|
| 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>; |
0 commit comments