Skip to content

Commit dd4d84e

Browse files
committed
feat(schema): add flows
1 parent d87d094 commit dd4d84e

10 files changed

Lines changed: 399 additions & 2 deletions

File tree

components/schema/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@crystallize/schema",
3-
"version": "6.7.0",
3+
"version": "6.8.0",
44
"license": "MIT",
55
"repository": {
66
"type": "git",
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { z } from 'zod';
2+
import { UpdateFlowInputSchema, CreateFlowInputSchema } from '../pim';
3+
import { RefSchema } from '../shared';
4+
5+
export const CreateFlowOperationSchema = CreateFlowInputSchema.extend({
6+
_ref: RefSchema.optional(),
7+
intent: z.literal('flow/create'),
8+
identifier: z.string().min(1),
9+
});
10+
export type CreateFlowOperation = z.infer<typeof CreateFlowOperationSchema>;
11+
12+
export const UpdateFlowOperationSchema = UpdateFlowInputSchema.extend({
13+
_ref: RefSchema.optional(),
14+
intent: z.literal('flow/update'),
15+
identifier: z.string().min(1),
16+
})
17+
export type UpdateFlowOperation = z.infer<typeof UpdateFlowOperationSchema>;
18+
19+
export const UpsertFlowOperationSchema = CreateFlowInputSchema.extend({
20+
_ref: RefSchema.optional(),
21+
intent: z.literal('flow/upsert'),
22+
identifier: z.string().min(1),
23+
});
24+
25+
export type UpsertFlowOperation = z.infer<typeof UpsertFlowOperationSchema>;

components/schema/src/mass-operation/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
AddItemTreeNodeAliasesOperationSchema,
1919
AddItemTreeNodeShortcutsOperationSchema,
2020
AddItemTreeNodeHistoryOperationSchema,
21+
AddItemsToFlowStageOperationSchema,
2122
} from './item';
2223
import {
2324
CreatePieceOperationSchema,
@@ -27,6 +28,7 @@ import {
2728
UpsertPieceOperationSchema,
2829
UpsertShapeOperationSchema,
2930
} from './shape';
31+
3032
import { ModifyProductVariantStockOperationSchema } from './product-variant';
3133
import {
3234
CreateCustomerGroupOperationSchema,
@@ -52,6 +54,7 @@ import {
5254
} from './pricelist';
5355
import { CreateTopicOperationSchema, UpdateTopicOperationSchema, UpsertTopicOperationSchema } from './topic';
5456
import { ModifyProductVariantPriceOperationSchema } from './product-variant';
57+
import { CreateFlowOperationSchema, UpdateFlowOperationSchema, UpsertFlowOperationSchema } from './flow';
5558

5659
export const OperationSchema = z.discriminatedUnion('intent', [
5760
DeleteItemOperationSchema,
@@ -113,6 +116,11 @@ export const OperationSchema = z.discriminatedUnion('intent', [
113116
AddItemTreeNodeAliasesOperationSchema,
114117
AddItemTreeNodeShortcutsOperationSchema,
115118
AddItemTreeNodeHistoryOperationSchema,
119+
120+
CreateFlowOperationSchema,
121+
UpdateFlowOperationSchema,
122+
UpsertFlowOperationSchema,
123+
AddItemsToFlowStageOperationSchema,
116124
]);
117125

118126
export const OperationsSchema = z.object({
@@ -142,8 +150,15 @@ export type {
142150
AddItemTreeNodeAliasesOperation,
143151
AddItemTreeNodeShortcutsOperation,
144152
AddItemTreeNodeHistoryOperation,
153+
AddItemsToFlowStageOperation,
145154
} from './item';
146155

156+
export type {
157+
CreateFlowOperation,
158+
UpdateFlowOperation,
159+
UpsertFlowOperation,
160+
} from './flow';
161+
147162
export type {
148163
CreateShapeOperation,
149164
UpdateShapeOperation,

components/schema/src/mass-operation/item.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ import {
88
UpdateFolderInputSchema,
99
UpdateProductInputSchema,
1010
} from '../pim/index';
11-
import { checkResourceIdentifierOrId, IdSchema, RefSchema, ResourceIdentifierSchema } from '../shared';
11+
import {
12+
checkResourceIdentifierOrId,
13+
IdSchema,
14+
RefSchema,
15+
ResourceIdentifierSchema
16+
} from '../shared';
17+
import { FlowContentActionConfigInputSchema, ItemFlowStageAssociationInputSchema } from '../pim/flow/flow-input';
1218

1319
export const CreateDocumentOperationSchema = CreateDocumentInputSchema.extend({
1420
_ref: RefSchema.optional(),
@@ -157,6 +163,16 @@ export const AddItemTreeNodeHistoryOperationSchema = z
157163
})
158164
.superRefine(checkResourceIdentifierOrId);
159165

166+
167+
export const AddItemsToFlowStageOperationSchema = z.object({
168+
_ref: RefSchema.optional(),
169+
intent: z.literal('item/flow/stage/addItems'),
170+
actionConfig: z.array(FlowContentActionConfigInputSchema).optional(),
171+
items: z.array(ItemFlowStageAssociationInputSchema).min(1),
172+
moveFromFlowIdentifier: z.string().min(1).optional(),
173+
stageIdentifier: z.string().min(1),
174+
});
175+
160176
export type UpdateItemComponentOperation = z.infer<typeof UpdateItemComponentOperationSchema>;
161177
export type UpdateSkuComponentOperation = z.infer<typeof UpdateSkuComponentOperationSchema>;
162178
export type PublishItemOperation = z.infer<typeof PublishItemOperationSchema>;
@@ -178,3 +194,4 @@ export type UpsertProductOperation = z.infer<typeof UpsertProductOperationSchema
178194
export type AddItemTreeNodeShortcutsOperation = z.infer<typeof AddItemTreeNodeShortcutsOperationSchema>;
179195
export type AddItemTreeNodeAliasesOperation = z.infer<typeof AddItemTreeNodeAliasesOperationSchema>;
180196
export type AddItemTreeNodeHistoryOperation = z.infer<typeof AddItemTreeNodeHistoryOperationSchema>;
197+
export type AddItemsToFlowStageOperation = z.infer<typeof AddItemsToFlowStageOperationSchema>;
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import { z } from 'zod';
2+
import { DateTimeSchema, IdSchema, KeyValuePairInputSchema, VersionLabelSchema } from '../../shared';
3+
import { FlowStageActionNotProcessedBehaviorSchema, FlowStageActionTypeSchema, FlowTypeSchema } from './flow';
4+
5+
export const FlowStageMoveActionTypeSchema = z.enum(['advance', 'move', 'removeFromFlow']);
6+
export type FlowStageMoveActionType = z.infer<typeof FlowStageMoveActionTypeSchema>;
7+
8+
export const FlowStageActionMoveInputSchema = z.object({
9+
targetStageIdentifier: z.string().min(1),
10+
});
11+
export type FlowStageActionMoveInput = z.infer<typeof FlowStageActionMoveInputSchema>;
12+
13+
export const FlowStageMoveActionInputSchema = z.object({
14+
action: FlowStageMoveActionTypeSchema,
15+
move: FlowStageActionMoveInputSchema.nullish(),
16+
});
17+
export type FlowStageMoveActionInput = z.infer<typeof FlowStageMoveActionInputSchema>;
18+
19+
export const FlowStageActionPublishInputSchema = z.object({
20+
onFailure: FlowStageMoveActionInputSchema.nullish(),
21+
});
22+
export type FlowStageActionPublishInput = z.infer<typeof FlowStageActionPublishInputSchema>;
23+
24+
export const FlowStageActionUnpublishInputSchema = z.object({
25+
onFailure: FlowStageMoveActionInputSchema.nullish(),
26+
});
27+
export type FlowStageActionUnpublishInput = z.infer<typeof FlowStageActionUnpublishInputSchema>;
28+
29+
export const FlowStageActionWaitAbsoluteInputSchema = z.object({
30+
until: DateTimeSchema,
31+
});
32+
export type FlowStageActionWaitAbsoluteInput = z.infer<typeof FlowStageActionWaitAbsoluteInputSchema>;
33+
34+
export const FlowStageActionWaitIndividualInputSchema = z.object({
35+
onExpiredDatetime: FlowStageActionNotProcessedBehaviorSchema.nullish(),
36+
onMissingDatetime: FlowStageActionNotProcessedBehaviorSchema.nullish(),
37+
});
38+
export type FlowStageActionWaitIndividualInput = z.infer<typeof FlowStageActionWaitIndividualInputSchema>;
39+
40+
export const FlowStageActionWaitRelativeInputSchema = z.object({
41+
days: z.int().nullish(),
42+
hours: z.int().nullish(),
43+
minutes: z.int().nullish(),
44+
});
45+
export type FlowStageActionWaitRelativeInput = z.infer<typeof FlowStageActionWaitRelativeInputSchema>;
46+
47+
export const FlowStageActionInputSchema = z.object({
48+
action: FlowStageActionTypeSchema,
49+
move: FlowStageActionMoveInputSchema.nullish(),
50+
publish: FlowStageActionPublishInputSchema.nullish(),
51+
unpublish: FlowStageActionUnpublishInputSchema.nullish(),
52+
waitAbsolute: FlowStageActionWaitAbsoluteInputSchema.nullish(),
53+
waitIndividual: FlowStageActionWaitIndividualInputSchema.nullish(),
54+
waitRelative: FlowStageActionWaitRelativeInputSchema.nullish(),
55+
});
56+
export type FlowStageActionInput = z.infer<typeof FlowStageActionInputSchema>;
57+
58+
export const ItemFlowRestrictionsInputSchema = z.object({
59+
acceptedShapeIdentifiers: z.array(z.string().min(1)).nullish(),
60+
});
61+
export type ItemFlowRestrictionsInput = z.infer<typeof ItemFlowRestrictionsInputSchema>;
62+
63+
export const FlowRestrictionsInputSchema = z.object({
64+
item: ItemFlowRestrictionsInputSchema.nullish(),
65+
});
66+
export type FlowRestrictionsInput = z.infer<typeof FlowRestrictionsInputSchema>;
67+
68+
export const EmbeddedFlowStageInputSchema = z.object({
69+
actions: z.array(FlowStageActionInputSchema).nullish(),
70+
identifier: z.string().min(1),
71+
meta: z.array(KeyValuePairInputSchema).nullish(),
72+
name: z.string().min(1),
73+
});
74+
export type EmbeddedFlowStageInput = z.infer<typeof EmbeddedFlowStageInputSchema>;
75+
76+
export const CreateFlowInputSchema = z.object({
77+
meta: z.array(KeyValuePairInputSchema).nullish(),
78+
name: z.string().min(1),
79+
restrictions: FlowRestrictionsInputSchema.nullish(),
80+
stages: z.array(EmbeddedFlowStageInputSchema),
81+
type: FlowTypeSchema,
82+
});
83+
export type CreateFlowInput = z.infer<typeof CreateFlowInputSchema>;
84+
85+
export const UpdateFlowInputSchema = z.object({
86+
meta: z.array(KeyValuePairInputSchema).nullish(),
87+
name: z.string().min(1).nullish(),
88+
restrictions: FlowRestrictionsInputSchema.nullish(),
89+
stages: z.array(EmbeddedFlowStageInputSchema).nullish(),
90+
});
91+
export type UpdateFlowInput = z.infer<typeof UpdateFlowInputSchema>;
92+
93+
export const FlowContentActionConfigWaitIndividualInputSchema = z.object({
94+
until: DateTimeSchema,
95+
});
96+
export type FlowContentActionConfigWaitIndividualInput = z.infer<typeof FlowContentActionConfigWaitIndividualInputSchema>;
97+
98+
export const FlowContentActionConfigInputSchema = z.object({
99+
stageIdentifier: z.string().min(1).optional(),
100+
waitIndividual: FlowContentActionConfigWaitIndividualInputSchema.optional(),
101+
});
102+
export type FlowContentActionConfigInput = z.infer<typeof FlowContentActionConfigInputSchema>;
103+
104+
export const ItemFlowStageAssociationInputSchema = z.object({
105+
id: IdSchema,
106+
language: z.string().min(1).optional(),
107+
version: VersionLabelSchema.optional(),
108+
});
109+
export type ItemFlowStageAssociationInput = z.infer<typeof ItemFlowStageAssociationInputSchema>;
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import { z } from 'zod';
2+
import { DateTimeSchema, KeyValuePairSchema } from '../../shared';
3+
4+
export const FlowStageActionTypeSchema = z.enum([
5+
'advance',
6+
'move',
7+
'publish',
8+
'removeFromFlow',
9+
'unpublish',
10+
'waitAbsolute',
11+
'waitIndividual',
12+
'waitRelative',
13+
]);
14+
export type FlowStageActionType = z.infer<typeof FlowStageActionTypeSchema>;
15+
16+
export const FlowTypeSchema = z.enum(['item']);
17+
export type FlowType = z.infer<typeof FlowTypeSchema>;
18+
19+
export const FlowStageActionNotProcessedBehaviorSchema = z.enum(['skip', 'stall']);
20+
export type FlowStageActionNotProcessedBehavior = z.infer<typeof FlowStageActionNotProcessedBehaviorSchema>;
21+
22+
export const FlowStageActionAdvanceSchema = z.object({
23+
action: z.literal('advance'),
24+
});
25+
export type FlowStageActionAdvance = z.infer<typeof FlowStageActionAdvanceSchema>;
26+
27+
export const FlowStageActionMoveSchema = z.object({
28+
action: z.literal('move'),
29+
targetStageIdentifier: z.string().min(1),
30+
});
31+
export type FlowStageActionMove = z.infer<typeof FlowStageActionMoveSchema>;
32+
33+
export const FlowStageActionPublishSchema = z.object({
34+
action: z.literal('publish'),
35+
onFailure: FlowStageActionMoveSchema.nullish(),
36+
});
37+
export type FlowStageActionPublish = z.infer<typeof FlowStageActionPublishSchema>;
38+
39+
export const FlowStageActionRemoveFromFlowSchema = z.object({
40+
action: z.literal('removeFromFlow'),
41+
});
42+
export type FlowStageActionRemoveFromFlow = z.infer<typeof FlowStageActionRemoveFromFlowSchema>;
43+
44+
export const FlowStageActionUnpublishSchema = z.object({
45+
action: z.literal('unpublish'),
46+
onFailure: FlowStageActionMoveSchema.nullish(),
47+
});
48+
export type FlowStageActionUnpublish = z.infer<typeof FlowStageActionUnpublishSchema>;
49+
50+
export const FlowStageActionWaitAbsoluteSchema = z.object({
51+
action: z.literal('waitAbsolute'),
52+
until: DateTimeSchema,
53+
});
54+
export type FlowStageActionWaitAbsolute = z.infer<typeof FlowStageActionWaitAbsoluteSchema>;
55+
56+
export const FlowStageActionWaitIndividualSchema = z.object({
57+
action: z.literal('waitIndividual'),
58+
onExpiredDatetime: FlowStageActionNotProcessedBehaviorSchema.nullish(),
59+
onMissingDatetime: FlowStageActionNotProcessedBehaviorSchema.nullish(),
60+
});
61+
export type FlowStageActionWaitIndividual = z.infer<typeof FlowStageActionWaitIndividualSchema>;
62+
63+
export const FlowStageActionWaitRelativeSchema = z.object({
64+
action: z.literal('waitRelative'),
65+
minutes: z.int().min(1),
66+
});
67+
export type FlowStageActionWaitRelative = z.infer<typeof FlowStageActionWaitRelativeSchema>;
68+
69+
export const FlowStageActionSchema = z.discriminatedUnion('action', [
70+
FlowStageActionAdvanceSchema,
71+
FlowStageActionMoveSchema,
72+
FlowStageActionPublishSchema,
73+
FlowStageActionRemoveFromFlowSchema,
74+
FlowStageActionUnpublishSchema,
75+
FlowStageActionWaitAbsoluteSchema,
76+
FlowStageActionWaitIndividualSchema,
77+
FlowStageActionWaitRelativeSchema,
78+
]);
79+
export type FlowStageAction = z.infer<typeof FlowStageActionSchema>;
80+
81+
export const ItemFlowRestrictionsSchema = z.object({
82+
acceptedShapeIdentifiers: z.array(z.string().min(1)).nullish(),
83+
});
84+
export type ItemFlowRestrictions = z.infer<typeof ItemFlowRestrictionsSchema>;
85+
86+
export const FlowRestrictionsSchema = ItemFlowRestrictionsSchema;
87+
export type FlowRestrictions = z.infer<typeof FlowRestrictionsSchema>;
88+
89+
const BaseFlowSchema = z.object({
90+
createdAt: DateTimeSchema,
91+
identifier: z.string().min(1),
92+
meta: z.array(KeyValuePairSchema).nullish(),
93+
metaProperty: z.string().nullish(),
94+
name: z.string().min(1),
95+
restrictions: FlowRestrictionsSchema.nullish(),
96+
stageIdentifiers: z.array(z.string().min(1)),
97+
type: FlowTypeSchema,
98+
updatedAt: DateTimeSchema.nullish(),
99+
});
100+
101+
export const FlowStageSchema = z.object({
102+
actions: z.array(FlowStageActionSchema).nullish(),
103+
createdAt: DateTimeSchema,
104+
flow: BaseFlowSchema,
105+
flowIdentifier: z.string().min(1),
106+
identifier: z.string().min(1),
107+
meta: z.array(KeyValuePairSchema).nullish(),
108+
metaProperty: z.string().nullish(),
109+
name: z.string().min(1),
110+
updatedAt: DateTimeSchema.nullish(),
111+
});
112+
export type FlowStage = z.infer<typeof FlowStageSchema>;
113+
114+
export const FlowSchema = BaseFlowSchema.extend({
115+
stages: z.array(FlowStageSchema),
116+
});
117+
export type Flow = z.infer<typeof FlowSchema>;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './flow-input';
2+
export * from './flow';

components/schema/src/pim/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export * from './subscription-contracts/index';
99
export * from './payment/index';
1010
export * from './assets/index';
1111
export * from './pricelists/index';
12+
export * from './flow/index';
1213
export * from './topics/index';

0 commit comments

Comments
 (0)