diff --git a/components/import-export-sdk/package.json b/components/import-export-sdk/package.json index 6e770edd..5c386a85 100644 --- a/components/import-export-sdk/package.json +++ b/components/import-export-sdk/package.json @@ -30,7 +30,7 @@ }, "dependencies": { "@crystallize/js-api-client": "workspace:*", - "@crystallize/schema": "workspace:*", + "@crystallize/schema": "^2.0", "zod": "^3.23.8" } } diff --git a/components/schema/package.json b/components/schema/package.json index 9bc55c01..782e04ee 100644 --- a/components/schema/package.json +++ b/components/schema/package.json @@ -1,19 +1,21 @@ { "name": "@crystallize/schema", - "version": "2.0.0", + "version": "3.0.0", "license": "MIT", - "type": "module", - "main": "./dist/index.cjs", "exports": { - ".": { - "import": "./dist/index.js", - "require": "./dist/index.cjs", - "types": "./dist/index.d.ts" + "./pim": { + "types": "./dist/pim/index.d.ts", + "import": "./dist/pim/index.mjs", + "require": "./dist/pim/index.js" + }, + "./mass-operation": { + "types": "./dist/mass-operation/index.d.ts", + "import": "./dist/mass-operation/index.mjs", + "require": "./dist/mass-operation/index.js" } }, - "types": "./dist/index.d.ts", "scripts": { - "build": "rm -rf dist && tsup src/index.ts --format esm,cjs --dts", + "build": "rm -rf dist && tsup src/pim/index.ts --format esm,cjs --dts -d dist/pim && tsup src/mass-operation/index.ts --format esm,cjs --dts -d dist/mass-operation", "watch": "tsc -W", "test": "vitest run" }, diff --git a/components/schema/src/catalog/index.ts b/components/schema/src/catalog/index.ts new file mode 100644 index 00000000..e69de29b diff --git a/components/schema/src/discovery/index.ts b/components/schema/src/discovery/index.ts new file mode 100644 index 00000000..e69de29b diff --git a/components/schema/src/index.ts b/components/schema/src/index.ts deleted file mode 100644 index 81385d21..00000000 --- a/components/schema/src/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -export * from './item/index.js'; -export * from './shape/index.js'; -export * from './shared/index.js'; -export * from './tenant/index.js'; -export * from './topic/index.js'; -export * from './mass-operation/index.js'; diff --git a/components/schema/src/item/components/boolean/index.ts b/components/schema/src/item/components/boolean/index.ts deleted file mode 100644 index e81b7a9f..00000000 --- a/components/schema/src/item/components/boolean/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { z } from 'zod'; - -export const BooleanContentInputSchema = z.object({ - value: z.boolean(), -}); - -export type BooleanContentInput = z.infer; diff --git a/components/schema/src/item/components/contentChunk/index.ts b/components/schema/src/item/components/contentChunk/index.ts deleted file mode 100644 index d1896a77..00000000 --- a/components/schema/src/item/components/contentChunk/index.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { z } from 'zod'; -import { ComponentInput, ComponentInputSchema } from '../index.js'; - -export type ContentChunkContentInput = { - chunks: ComponentInput[][]; -}; - -export const ContentChunkContentInputSchema: z.ZodType = z.lazy(() => - z.object({ - chunks: z.array(z.array(ComponentInputSchema).min(1)).min(1), - }), -); diff --git a/components/schema/src/item/components/datetime/index.ts b/components/schema/src/item/components/datetime/index.ts deleted file mode 100644 index 583717c4..00000000 --- a/components/schema/src/item/components/datetime/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { z } from 'zod'; -import { DateTimeSchema } from '../../../shared/index.js'; - -export const DatetimeContentInputSchema = z.object({ - datetime: DateTimeSchema, -}); - -export type DatetimeContentInput = z.infer; diff --git a/components/schema/src/item/components/files/index.ts b/components/schema/src/item/components/files/index.ts deleted file mode 100644 index 9207ec67..00000000 --- a/components/schema/src/item/components/files/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { z } from 'zod'; - -export const FileInputSchema = z.object({ - key: z.string().min(1), - title: z.string().optional(), -}); - -export type FileInput = z.infer; diff --git a/components/schema/src/item/components/gridRelations/index.ts b/components/schema/src/item/components/gridRelations/index.ts deleted file mode 100644 index a6b0ab83..00000000 --- a/components/schema/src/item/components/gridRelations/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { z } from 'zod'; -import { IdSchema } from '../../../shared/index.js'; - -export const GridRelationsContentInputSchema = z.object({ - gridIds: z.array(IdSchema).optional(), -}); - -export type GridRelationsContentInput = z.infer; diff --git a/components/schema/src/item/components/images/index.ts b/components/schema/src/item/components/images/index.ts deleted file mode 100644 index c6f9d89e..00000000 --- a/components/schema/src/item/components/images/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { z } from 'zod'; -import { KeyValuePairInputSchema } from '../../../shared/index.js'; -import { RichTextContentInputSchema } from '../richText/index.js'; - -export const ImageInputSchema = z.object({ - key: z.string().min(1), - caption: RichTextContentInputSchema.optional(), - altText: z.string().optional(), - mimeType: z.string().optional(), - meta: z.array(KeyValuePairInputSchema).optional(), -}); - -export type ImageInput = z.infer; diff --git a/components/schema/src/item/components/index.ts b/components/schema/src/item/components/index.ts deleted file mode 100644 index 83d0d813..00000000 --- a/components/schema/src/item/components/index.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { z } from 'zod'; -import { BooleanContentInput, BooleanContentInputSchema } from './boolean/index.js'; -import { ContentChunkContentInput, ContentChunkContentInputSchema } from './contentChunk/index.js'; -import { DatetimeContentInput, DatetimeContentInputSchema } from './datetime/index.js'; -import { FileInput, FileInputSchema } from './files/index.js'; -import { GridRelationsContentInput, GridRelationsContentInputSchema } from './gridRelations/index.js'; -import { ImageInput, ImageInputSchema } from './images/index.js'; -import { ItemRelationsContentInput, ItemRelationsContentInputSchema } from './itemRelations/index.js'; -import { LocationContentInput, LocationContentInputSchema } from './location/index.js'; -import { NumericComponentContentInput, NumericComponentContentInputSchema } from './numeric/index.js'; -import { ParagraphCollectionContentInput, ParagraphCollectionContentInputSchema } from './paragraphCollection/index.js'; -import { PieceContentInput, PieceContentInputSchema } from './piece/index.js'; -import { PropertiesTableContentInput, PropertiesTableContentInputSchema } from './propertiesTable/index.js'; -import { RichTextContentInput, RichTextContentInputSchema } from './richText/index.js'; -import { SelectionComponentContentInput, SelectionComponentContentInputSchema } from './selection/index.js'; -import { SingleLineContentInput, SingleLineContentInputSchema } from './singleLine/index.js'; -import { VideoInput, VideoInputSchema } from './videos/index.js'; - -export type ComponentInput = { - componentId: string; - files?: FileInput[]; - images?: ImageInput[]; - videos?: VideoInput[]; - componentChoice?: ComponentInput; - componentMultipleChoice?: ComponentInput[]; - contentChunk?: ContentChunkContentInput; - boolean?: BooleanContentInput; - datetime?: DatetimeContentInput; - gridRelations?: GridRelationsContentInput; - itemRelations?: ItemRelationsContentInput; - location?: LocationContentInput; - numeric?: NumericComponentContentInput; - paragraphCollection?: ParagraphCollectionContentInput; - piece?: PieceContentInput; - propertiesTable?: PropertiesTableContentInput; - richText?: RichTextContentInput; - selection?: SelectionComponentContentInput; - singleLine?: SingleLineContentInput; -}; - -export const ComponentInputSchema: z.ZodType = z.lazy(() => - z.object({ - componentId: z.string().min(1), - files: z.array(FileInputSchema).optional(), - images: z.array(ImageInputSchema).optional(), - videos: z.array(VideoInputSchema).optional(), - componentChoice: ComponentInputSchema.optional(), - componentMultipleChoice: z.array(ComponentInputSchema).optional(), - contentChunk: ContentChunkContentInputSchema.optional(), - boolean: BooleanContentInputSchema.optional(), - datetime: DatetimeContentInputSchema.optional(), - gridRelations: GridRelationsContentInputSchema.optional(), - itemRelations: ItemRelationsContentInputSchema.optional(), - location: LocationContentInputSchema.optional(), - numeric: NumericComponentContentInputSchema.optional(), - paragraphCollection: ParagraphCollectionContentInputSchema.optional(), - piece: PieceContentInputSchema.optional(), - propertiesTable: PropertiesTableContentInputSchema.optional(), - richText: RichTextContentInputSchema.optional(), - selection: SelectionComponentContentInputSchema.optional(), - singleLine: SingleLineContentInputSchema.optional(), - }), -); diff --git a/components/schema/src/item/components/itemRelations/index.ts b/components/schema/src/item/components/itemRelations/index.ts deleted file mode 100644 index 213ffa7e..00000000 --- a/components/schema/src/item/components/itemRelations/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { z } from 'zod'; -import { IdSchema } from '../../../shared/index.js'; - -export const ItemRelationsContentInputSchema = z.object({ - itemIds: z.array(IdSchema).optional(), - skus: z.array(z.string()).optional(), -}); - -export type ItemRelationsContentInput = z.infer; diff --git a/components/schema/src/item/components/location/index.ts b/components/schema/src/item/components/location/index.ts deleted file mode 100644 index 3936ff9b..00000000 --- a/components/schema/src/item/components/location/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { z } from 'zod'; - -export const LocationContentInputSchema = z.object({ - lat: z.number().optional(), - long: z.number().optional(), -}); - -export type LocationContentInput = z.infer; diff --git a/components/schema/src/item/components/numeric/index.ts b/components/schema/src/item/components/numeric/index.ts deleted file mode 100644 index 58a17354..00000000 --- a/components/schema/src/item/components/numeric/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { z } from 'zod'; - -export const NumericComponentContentInputSchema = z.object({ - number: z.number(), - unit: z.string().optional(), -}); - -export type NumericComponentContentInput = z.infer; diff --git a/components/schema/src/item/components/paragraphCollection/index.ts b/components/schema/src/item/components/paragraphCollection/index.ts deleted file mode 100644 index d451f1ae..00000000 --- a/components/schema/src/item/components/paragraphCollection/index.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { z } from 'zod'; -import { ImageInputSchema } from '../images/index.js'; -import { RichTextContentInputSchema } from '../richText/index.js'; -import { SingleLineContentInputSchema } from '../singleLine/index.js'; -import { VideoInputSchema } from '../videos/index.js'; - -export const ParagraphInputSchema = z.object({ - body: RichTextContentInputSchema.optional(), - images: z.array(ImageInputSchema).optional(), - title: SingleLineContentInputSchema.optional(), - videos: z.array(VideoInputSchema).optional(), -}); - -export const ParagraphCollectionContentInputSchema = z.object({ - paragraphs: z.array(ParagraphInputSchema).optional(), -}); - -export type ParagraphInput = z.infer; -export type ParagraphCollectionContentInput = z.infer; diff --git a/components/schema/src/item/components/piece/index.ts b/components/schema/src/item/components/piece/index.ts deleted file mode 100644 index 822bf460..00000000 --- a/components/schema/src/item/components/piece/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { z } from 'zod'; -import { ComponentInputSchema } from '../index.js'; - -export const PieceContentInputSchema = z.object({ - identifier: z.string().min(1), - components: z.array(ComponentInputSchema).optional(), -}); - -export type PieceContentInput = z.infer; diff --git a/components/schema/src/item/components/propertiesTable/index.ts b/components/schema/src/item/components/propertiesTable/index.ts deleted file mode 100644 index b203c341..00000000 --- a/components/schema/src/item/components/propertiesTable/index.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { z } from 'zod'; -import { KeyValuePairInputSchema } from '../../../shared/index.js'; - -export const PropertiesTableComponentSectionInputSchema = z.object({ - properties: z.array(KeyValuePairInputSchema).optional(), - title: z.string().optional(), -}); - -export const PropertiesTableContentInputSchema = z.object({ - sections: z.array(PropertiesTableComponentSectionInputSchema).optional(), -}); - -export type PropertiesTableComponentSectionInput = z.infer; -export type PropertiesTableContentInput = z.infer; diff --git a/components/schema/src/item/components/richText/index.ts b/components/schema/src/item/components/richText/index.ts deleted file mode 100644 index 60daf0bd..00000000 --- a/components/schema/src/item/components/richText/index.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { z } from 'zod'; - -export const RichTextContentInputSchema = z - .object({ - html: z.array(z.string()).optional(), - json: z.array(z.string()).optional(), - }) - .refine( - ({ json }) => { - if (!json?.length) { - return true; - } - - try { - json?.map((str) => JSON.parse(str)); - return true; - } catch (err) { - return false; - } - }, - { - message: 'Invalid json provided to rich text content input', - }, - ); - -export type RichTextContentInput = z.infer; diff --git a/components/schema/src/item/components/selection/index.ts b/components/schema/src/item/components/selection/index.ts deleted file mode 100644 index c54d8573..00000000 --- a/components/schema/src/item/components/selection/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { z } from 'zod'; - -export const SelectionComponentContentInputSchema = z.object({ - keys: z.array(z.string()), -}); - -export type SelectionComponentContentInput = z.infer; diff --git a/components/schema/src/item/components/singleLine/index.ts b/components/schema/src/item/components/singleLine/index.ts deleted file mode 100644 index 5dc16f52..00000000 --- a/components/schema/src/item/components/singleLine/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { z } from 'zod'; - -export const SingleLineContentInputSchema = z.object({ - text: z.string().optional(), -}); - -export type SingleLineContentInput = z.infer; diff --git a/components/schema/src/item/components/videos/index.ts b/components/schema/src/item/components/videos/index.ts deleted file mode 100644 index 60095091..00000000 --- a/components/schema/src/item/components/videos/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { z } from 'zod'; -import { ImageInputSchema } from '../images/index.js'; - -export const VideoInputSchema = z.object({ - key: z.string().min(1), - thumbnails: z.array(ImageInputSchema).optional(), - title: z.string().optional(), -}); - -export type VideoInput = z.infer; diff --git a/components/schema/src/item/index.ts b/components/schema/src/item/index.ts deleted file mode 100644 index 11d55600..00000000 --- a/components/schema/src/item/index.ts +++ /dev/null @@ -1,164 +0,0 @@ -import { z } from 'zod'; -import { BasicShapeSchema } from '../shape/index.js'; -import { DateTimeSchema, Id, IdSchema, ItemType, ItemTypeEnum } from '../shared/index.js'; -import { Topic, TopicSchema } from '../topic/index.js'; -import { ComponentInputSchema } from './components/index.js'; -export * from './components/index.js'; - -export type Item = { - id: Id; - tenantId: Id; - language: string; - createdAt?: string; - updatedAt?: string; - type: ItemType; - name?: string; - externalReference?: string; - shape?: z.infer; - components?: any[]; - topics?: Topic[]; - relatingItems?: Item[]; - tree?: { - path?: string; - }; -}; - -export const ProductVariantAttributeSchema = z.object({ - attribute: z.string().min(1), - value: z.string().min(1), -}); - -export const ProductPriceVariantSchema = z.object({ - identifier: z.string().min(1), - currency: z.string().optional(), - name: z.string().optional(), - price: z.number().optional(), -}); - -export const ProductVariantSchema = z.object({ - isDefault: z.boolean().default(false), - sku: z.string().min(1), - name: z.string().min(1), - externalReference: z.string().optional(), - attributes: z.array(ProductVariantAttributeSchema).optional(), - price: z.number().optional(), - priceVariants: z.array(ProductPriceVariantSchema).optional(), - stock: z.number().optional(), - components: z.array(z.any()).optional(), -}); - -export const ItemSchema: z.ZodType = z.lazy(() => - z.object({ - id: IdSchema, - tenantId: IdSchema, - language: z.string().min(1), - createdAt: DateTimeSchema.optional(), - updatedAt: DateTimeSchema.optional(), - type: ItemTypeEnum, - name: z.string().optional(), - externalReference: z.string().optional(), - components: z.array(z.any()).optional(), - shape: BasicShapeSchema.optional(), - topics: z.array(TopicSchema).optional(), - relatingItems: z.array(ItemSchema).optional(), - tree: z - .object({ - path: z.string().optional(), - }) - .optional(), - }), -); - -export const ProductSchema = ItemSchema.and( - z.object({ - variants: z.array(ProductVariantSchema).optional(), - }), -); - -const createItemInputSchema = z.object({ - tenantId: IdSchema, - name: z.string().min(1), - shapeIdentifier: z.string().min(1), - createdAt: DateTimeSchema.optional(), - externalReference: z.string().optional(), - components: z.array(ComponentInputSchema).optional(), - topicIds: z.array(IdSchema).optional(), - tree: z.object({ - parentId: IdSchema, - position: z.number().positive().optional(), - }), -}); - -const updateItemInputSchema = z.object({ - name: z.string().optional(), - createdAt: DateTimeSchema.optional(), - externalReference: z.string().optional(), - components: z.array(ComponentInputSchema).optional(), - topicIds: z.array(IdSchema).optional(), -}); - -export const ProductVariantAttributeInputSchema = z.object({ - attribute: z.string().min(1), - value: z.string().min(1), -}); - -export const PriceVariantReferenceInputSchema = z.object({ - identifier: z.string().min(1), - price: z.number(), -}); - -export const CreateProductVariantInputSchema = z.object({ - isDefault: z.boolean(), - sku: z.string().min(1), - name: z.string().optional(), - price: z.number().optional(), - priceVariants: z.array(PriceVariantReferenceInputSchema).optional(), - stock: z.number().optional(), - attributes: z.array(ProductVariantAttributeInputSchema).optional(), - components: z.array(ComponentInputSchema).optional(), - externalReference: z.string().optional(), -}); - -export const UpdateProductVariantInputSchema = z.object({ - isDefault: z.boolean().optional(), - sku: z.string().optional(), - name: z.string().optional(), - price: z.number().optional(), - priceVariants: z.array(PriceVariantReferenceInputSchema).optional(), - stock: z.number().optional(), - attributes: z.array(ProductVariantAttributeInputSchema).optional(), - components: z.array(ComponentInputSchema).optional(), - externalReference: z.string().optional(), -}); - -export const CreateDocumentInputSchema = createItemInputSchema; -export const CreateFolderInputSchema = createItemInputSchema; -export const CreateProductInputSchema = createItemInputSchema.extend({ - variants: z.array(CreateProductVariantInputSchema).min(1), - vatTypeId: IdSchema, -}); -export const UpdateDocumentInputSchema = updateItemInputSchema; -export const UpdateFolderInputSchema = updateItemInputSchema; -export const UpdateProductInputSchema = updateItemInputSchema.extend({ - variants: z.array(UpdateProductVariantInputSchema).optional(), - vatTypeId: IdSchema.optional(), -}); - -export type Product = z.infer; -export type ProductVariant = z.infer; -export type ProductVariantAttribute = z.infer; -export type ProductPriceVariant = z.infer; - -export type ProductVariantAttributeInput = z.infer; -export type CreateProductVariantInput = z.infer; -export type UpdateProductVariantInput = z.infer; - -export type CreateDocumentInput = z.infer; -export type CreateFolderInput = z.infer; -export type CreateProductInput = z.infer; - -export type UpdateDocumentInput = z.infer; -export type UpdateFolderInput = z.infer; -export type UpdateProductInput = z.infer; - -export type { ComponentInput } from './components/index.js'; diff --git a/components/schema/src/mass-operation/index.ts b/components/schema/src/mass-operation/index.ts index 9296fc78..75091530 100644 --- a/components/schema/src/mass-operation/index.ts +++ b/components/schema/src/mass-operation/index.ts @@ -3,20 +3,29 @@ import { CreateItemOperationSchema, PublishItemOperationSchema, UnPublishItemOperationSchema, - UpdateComponentOperationSchema, + UpdateItemComponentOperationSchema, + UpdateSkuComponentOperationSchema, UpdateItemOperationSchema, UpsertItemOperationSchema, } from './item.js'; -import { CreateShapeOperationSchema, UpdateShapeOperationSchema } from './shape.js'; +import { + CreateProductShapeOperationSchema, + CreateFolderShapeOperationSchema, + CreateDocumentShapeOperationSchema, + UpdateShapeOperationSchema, +} from './shape.js'; -export const OperationSchema = z.union([ +export const OperationSchema = z.discriminatedUnion('intent', [ CreateItemOperationSchema, UpdateItemOperationSchema, UpsertItemOperationSchema, - UpdateComponentOperationSchema, PublishItemOperationSchema, UnPublishItemOperationSchema, - CreateShapeOperationSchema, + UpdateItemComponentOperationSchema, + UpdateSkuComponentOperationSchema, + CreateProductShapeOperationSchema, + CreateFolderShapeOperationSchema, + CreateDocumentShapeOperationSchema, UpdateShapeOperationSchema, ]); @@ -33,9 +42,15 @@ export type { CreateItemOperation, PublishItemOperation, UnPublishItemOperation, - UpdateComponentOperation, + UpdateItemComponentOperation, + UpdateSkuComponentOperation, UpdateItemOperation, UpsertItemOperation, } from './item.js'; -export type { CreateShapeOperation, UpdateShapeOperation } from './shape.js'; +export type { + CreateProductShapeOperation, + CreateDocumentShapeOperation, + CreateFolderShapeOperation, + UpdateShapeOperation, +} from './shape.js'; diff --git a/components/schema/src/mass-operation/item.ts b/components/schema/src/mass-operation/item.ts index 38ec8b9c..a563ffdd 100644 --- a/components/schema/src/mass-operation/item.ts +++ b/components/schema/src/mass-operation/item.ts @@ -1,77 +1,71 @@ import { z } from 'zod'; -import { ComponentInputSchema } from '../item/components/index.js'; import { IdSchema } from '../shared/index.js'; +import { ComponentContentInputSchema } from '../pim/components/component-content-input.js'; export const CreateItemOperationSchema = z.object({ - concern: z.literal('item'), - action: z.literal('create'), + intent: z.literal('item/create'), type: z.enum(['product', 'document', 'folder']), shape: z.string().min(1), language: z.string().min(1), topics: z.array(IdSchema).optional(), - components: z.array(ComponentInputSchema), + components: z.array(ComponentContentInputSchema), }); export const UpdateItemOperationSchema = CreateItemOperationSchema.omit({ - action: true, + intent: true, type: true, shape: true, }).merge( z.object({ - action: z.literal('update'), + intent: z.literal('item/update'), itemId: IdSchema, }), ); -export const UpsertItemOperationSchema = UpdateItemOperationSchema.omit({ action: true }).merge( +export const UpsertItemOperationSchema = UpdateItemOperationSchema.omit({ intent: true }).merge( z.object({ - action: z.literal('upsert'), + intent: z.literal('item/upsert'), }), ); -export const UpdateComponentOperationSchema = UpdateItemOperationSchema.omit({ - action: true, +export const UpdateItemComponentOperationSchema = UpdateItemOperationSchema.omit({ + intent: true, itemId: true, components: true, topics: true, -}) - .merge( - z.object({ - action: z.literal('updateComponent'), - component: ComponentInputSchema, - }), - ) - .and( - z - .object({ - sku: z.never().optional(), - itemId: IdSchema, - }) - .or( - z.object({ - sku: z.string(), - itemId: z.never().optional(), - }), - ), - ); +}).extend({ + intent: z.literal('item/updateComponent/item'), + component: ComponentContentInputSchema, + sku: z.never().optional(), + itemId: IdSchema, +}); +export const UpdateSkuComponentOperationSchema = UpdateItemComponentOperationSchema.omit({ + intent: true, + itemId: true, + sku: true, +}).extend({ + intent: z.literal('item/updateComponent/sku'), + sku: z.string(), + itemId: z.never().optional(), +}); export const PublishItemOperationSchema = z.object({ - concern: z.literal('item'), - action: z.literal('publish'), + intent: z.literal('item/publish'), itemId: IdSchema, language: z.string().min(1), includeDescendants: z.boolean().optional(), }); -export const UnPublishItemOperationSchema = PublishItemOperationSchema.omit({ action: true }).merge( +export const UnPublishItemOperationSchema = PublishItemOperationSchema.omit({ intent: true }).merge( z.object({ - action: z.literal('unpublish'), + intent: z.literal('item/unpublish'), }), ); export type CreateItemOperation = z.infer; export type UpdateItemOperation = z.infer; export type UpsertItemOperation = z.infer; -export type UpdateComponentOperation = z.infer; +export type UpdateItemComponentOperation = z.infer; +export type UpdateSkuComponentOperation = z.infer; export type PublishItemOperation = z.infer; export type UnPublishItemOperation = z.infer; diff --git a/components/schema/src/mass-operation/shape.ts b/components/schema/src/mass-operation/shape.ts index 84a2aef5..df2633da 100644 --- a/components/schema/src/mass-operation/shape.ts +++ b/components/schema/src/mass-operation/shape.ts @@ -1,19 +1,28 @@ import { z } from 'zod'; -import { NextPimCreateShapeInputSchema, UpdateShapeInputSchema } from '../shape/index.js'; +import { + CreateDocumentShapeInputSchema, + CreateFolderShapeInputSchema, + CreateProductShapeInputSchema, + UpdateShapeInputSchema, +} from '../pim/shape/index.js'; -export const CreateShapeOperationSchema = NextPimCreateShapeInputSchema.and( - z.object({ - concern: z.literal('shape'), - action: z.literal('create'), - }), -); -export type CreateShapeOperation = z.infer; +export const CreateDocumentShapeOperationSchema = CreateDocumentShapeInputSchema.extend({ + intent: z.literal('shape/create/document'), +}); +export type CreateDocumentShapeOperation = z.infer; -export const UpdateShapeOperationSchema = UpdateShapeInputSchema.and( - z.object({ - concern: z.literal('shape'), - action: z.literal('update'), - identifier: z.string().min(1), - }), -); +export const CreateFolderShapeOperationSchema = CreateFolderShapeInputSchema.extend({ + intent: z.literal('shape/create/folder'), +}); +export type CreateFolderShapeOperation = z.infer; + +export const CreateProductShapeOperationSchema = CreateProductShapeInputSchema.extend({ + intent: z.literal('shape/create/product'), +}); +export type CreateProductShapeOperation = z.infer; + +export const UpdateShapeOperationSchema = UpdateShapeInputSchema.extend({ + intent: z.literal('shape/update'), + identifier: z.string().min(1), +}); export type UpdateShapeOperation = z.infer; diff --git a/components/schema/src/orders/index.ts b/components/schema/src/orders/index.ts new file mode 100644 index 00000000..e69de29b diff --git a/components/schema/src/pim/components/component-config-input.ts b/components/schema/src/pim/components/component-config-input.ts new file mode 100644 index 00000000..50781d5d --- /dev/null +++ b/components/schema/src/pim/components/component-config-input.ts @@ -0,0 +1,99 @@ +import { z } from 'zod'; + +import { BooleanConfigInput, BooleanConfigInputSchema } from './types/boolean.js'; +import { DatetimeConfigInput, DatetimeConfigInputSchema } from './types/datetime.js'; +import { GridRelationsConfigInput, GridRelationsConfigInputSchema } from './types/grid-relations.js'; +import { ImagesConfigInput, ImagesConfigInputSchema } from './types/images.js'; +import { LocationConfigInput, LocationConfigInputSchema } from './types/location.js'; +import { ParagraphCollectionConfigInput, ParagraphCollectionConfigInputSchema } from './types/paragraph-collection.js'; +import { RichTextConfigInput, RichTextConfigInputSchema } from './types/rich-text.js'; +import { SingleLineConfigInput, SingleLineConfigInputSchema } from './types/single-line.js'; +import { VideosConfigInput, VideosConfigInputSchema } from './types/videos.js'; +import { NumericConfigInput, NumericConfigInputSchema } from './types/numeric.js'; +import { FilesConfigInput, FilesConfigInputSchema } from './types/files.js'; +import { ItemRelationsConfigInput, ItemRelationsConfigInputSchema } from './types/item-relations.js'; +import { PropertiesTableConfigInput, PropertiesTableConfigInputSchema } from './types/properties-table.js'; +import { SelectionConfigInput, SelectionConfigInputSchema } from './types/selection.js'; +import { GenericComponentConfigInputSchema } from './shared.js'; +import { ComponentDefinitionInputSchema } from './component-definition.js'; + +export type NestableComponentConfigInput = { + files?: FilesConfigInput; + images?: ImagesConfigInput; + videos?: VideosConfigInput; + boolean?: BooleanConfigInput; + datetime?: DatetimeConfigInput; + gridRelations?: GridRelationsConfigInput; + itemRelations?: ItemRelationsConfigInput; + location?: LocationConfigInput; + numeric?: NumericConfigInput; + paragraphCollection?: ParagraphCollectionConfigInput; + propertiesTable?: PropertiesTableConfigInput; + richText?: RichTextConfigInput; + selection?: SelectionConfigInput; + singleLine?: SingleLineConfigInput; + piece?: PieceConfigInput; +}; + +export const NestableComponentConfigInputSchema: z.ZodType = z.lazy(() => + z.object({ + files: FilesConfigInputSchema.optional(), + images: ImagesConfigInputSchema.optional(), + videos: VideosConfigInputSchema.optional(), + boolean: BooleanConfigInputSchema.optional(), + datetime: DatetimeConfigInputSchema.optional(), + gridRelations: GridRelationsConfigInputSchema.optional(), + itemRelations: ItemRelationsConfigInputSchema.optional(), + location: LocationConfigInputSchema.optional(), + numeric: NumericConfigInputSchema.optional(), + paragraphCollection: ParagraphCollectionConfigInputSchema.optional(), + propertiesTable: PropertiesTableConfigInputSchema.optional(), + richText: RichTextConfigInputSchema.optional(), + selection: SelectionConfigInputSchema.optional(), + singleLine: SingleLineConfigInputSchema.optional(), + piece: PieceConfigInputSchema.optional(), + }), +); + +export type ComponentConfigInput = NestableComponentConfigInput & { + componentChoice?: ChoiceConfigInput; + componentMultipleChoice?: MultipleChoicesConfigInput; + contentChunk?: ChunksConfigInput; +}; + +export const ComponentConfigInputSchema: z.ZodType = z.lazy(() => + NestableComponentConfigInputSchema.and( + z.object({ + componentChoice: ChoiceConfigInputSchema.optional(), + componentMultipleChoice: MultipleChoicesConfigInputSchema.optional(), + contentChunk: ChunksConfigInputSchema.optional(), + }), + ), +); + +/* + * Hoisting Nightmare debug prevention + * Do not try to put those files elsewhere, because base on how you transpile the code, it may not work + * as we have recursive imports here + */ +export const ChoiceConfigInputSchema = GenericComponentConfigInputSchema.extend({ + choices: z.array(ComponentDefinitionInputSchema), +}); +export type ChoiceConfigInput = z.infer; + +export const ChunksConfigInputSchema = GenericComponentConfigInputSchema.extend({ + components: z.array(ComponentDefinitionInputSchema), + repeatable: z.boolean().optional(), +}); +export type ChunksConfigInput = z.infer; + +export const MultipleChoicesConfigInputSchema = GenericComponentConfigInputSchema.extend({ + choices: z.array(ComponentDefinitionInputSchema), + allowDuplicates: z.boolean().optional(), +}); +export type MultipleChoicesConfigInput = z.infer; + +export const PieceConfigInputSchema = GenericComponentConfigInputSchema.extend({ + identifier: z.string().min(1), +}); +export type PieceConfigInput = z.infer; diff --git a/components/schema/src/pim/components/component-config.ts b/components/schema/src/pim/components/component-config.ts new file mode 100644 index 00000000..aea12fe3 --- /dev/null +++ b/components/schema/src/pim/components/component-config.ts @@ -0,0 +1,100 @@ +import { z } from 'zod'; + +import { BooleanConfig, BooleanConfigSchema } from './types/boolean.js'; +import { DatetimeConfig, DatetimeConfigSchema } from './types/datetime.js'; +import { GridRelationsConfig, GridRelationsConfigSchema } from './types/grid-relations.js'; +import { ImagesConfig, ImagesConfigSchema } from './types/images.js'; +import { LocationConfig, LocationConfigSchema } from './types/location.js'; +import { ParagraphCollectionConfig, ParagraphCollectionConfigSchema } from './types/paragraph-collection.js'; +import { RichTextConfig, RichTextConfigSchema } from './types/rich-text.js'; +import { SingleLineConfig, SingleLineConfigSchema } from './types/single-line.js'; +import { VideosConfig, VideosConfigSchema } from './types/videos.js'; +import { NumericConfig, NumericConfigSchema } from './types/numeric.js'; +import { FilesConfig, FilesConfigSchema } from './types/files.js'; +import { ItemRelationsConfig, ItemRelationsConfigSchema } from './types/item-relations.js'; +import { PropertiesTableConfig, PropertiesTableConfigSchema } from './types/properties-table.js'; +import { SelectionConfig, SelectionConfigSchema } from './types/selection.js'; +import { GenericComponentConfigSchema } from './shared.js'; +import { ComponentDefinitionInputSchema, ComponentDefinitionSchema } from './component-definition.js'; + +export type NestableComponentConfig = { + files?: FilesConfig; + images?: ImagesConfig; + videos?: VideosConfig; + boolean?: BooleanConfig; + datetime?: DatetimeConfig; + gridRelations?: GridRelationsConfig; + itemRelations?: ItemRelationsConfig; + location?: LocationConfig; + numeric?: NumericConfig; + paragraphCollection?: ParagraphCollectionConfig; + propertiesTable?: PropertiesTableConfig; + richText?: RichTextConfig; + selection?: SelectionConfig; + singleLine?: SingleLineConfig; + piece?: PieceConfig; +}; + +export const NestableComponentConfigSchema: z.ZodType = z.lazy(() => + z.object({ + files: FilesConfigSchema.optional(), + images: ImagesConfigSchema.optional(), + videos: VideosConfigSchema.optional(), + boolean: BooleanConfigSchema.optional(), + datetime: DatetimeConfigSchema.optional(), + gridRelations: GridRelationsConfigSchema.optional(), + itemRelations: ItemRelationsConfigSchema.optional(), + location: LocationConfigSchema.optional(), + numeric: NumericConfigSchema.optional(), + paragraphCollection: ParagraphCollectionConfigSchema.optional(), + propertiesTable: PropertiesTableConfigSchema.optional(), + richText: RichTextConfigSchema.optional(), + selection: SelectionConfigSchema.optional(), + singleLine: SingleLineConfigSchema.optional(), + piece: PieceConfigSchema.optional(), + }), +); + +export type ComponentConfig = NestableComponentConfig & { + componentChoice?: ChoiceConfig; + componentMultipleChoice?: MultipleChoicesConfig; + contentChunk?: ChunksConfig; +}; + +export const ComponentConfigSchema: z.ZodType = z.lazy(() => + NestableComponentConfigSchema.and( + z.object({ + componentChoice: ChoiceConfigSchema.optional(), + componentMultipleChoice: MultipleChoicesConfigSchema.optional(), + contentChunk: ChunksConfigSchema.optional(), + }), + ), +); + +/* + * Hoisting Nightmare debug prevention + * Do not try to put those files elsewhere, because base on how you transpile the code, it may not work + * as we have recursive imports here + */ +export const ChoiceConfigSchema = GenericComponentConfigSchema.extend({ + choices: z.array(ComponentDefinitionInputSchema), +}); +export type ChoiceConfig = z.infer; + +export const ChunksConfigSchema = GenericComponentConfigSchema.extend({ + components: z.array(ComponentDefinitionSchema), + repeatable: z.boolean(), +}); +export type ChunksConfig = z.infer; + +export const MultipleChoicesConfigSchema = GenericComponentConfigSchema.extend({ + choices: z.array(ComponentDefinitionSchema), + allowDuplicates: z.boolean().optional(), +}); +export type MultipleChoicesConfig = z.infer; + +export const PieceConfigSchema = GenericComponentConfigSchema.extend({ + identifier: z.string().min(1), + components: z.array(ComponentDefinitionSchema), +}); +export type PieceConfig = z.infer; diff --git a/components/schema/src/pim/components/component-content-input.ts b/components/schema/src/pim/components/component-content-input.ts new file mode 100644 index 00000000..1a3059f0 --- /dev/null +++ b/components/schema/src/pim/components/component-content-input.ts @@ -0,0 +1,95 @@ +import { z } from 'zod'; + +import { BooleanContentInput, BooleanContentInputSchema } from './types/boolean.js'; +import { DatetimeContentInput, DatetimeContentInputSchema } from './types/datetime.js'; +import { GridRelationsContentInput, GridRelationsContentInputSchema } from './types/grid-relations.js'; +import { ImagesContentInput, ImagesContentInputSchema } from './types/images.js'; +import { LocationContentInput, LocationContentInputSchema } from './types/location.js'; +import { + ParagraphCollectionContentInput, + ParagraphCollectionContentInputSchema, +} from './types/paragraph-collection.js'; +import { RichTextContentInput, RichTextContentInputSchema } from './types/rich-text.js'; +import { SingleLineContentInput, SingleLineContentInputSchema } from './types/single-line.js'; +import { VideosContentInput, VideosContentInputSchema } from './types/videos.js'; +import { NumericContentInput, NumericContentInputSchema } from './types/numeric.js'; +import { FilesContentInput, FilesContentInputSchema } from './types/files.js'; +import { ItemRelationsContentInput, ItemRelationsContentInputSchema } from './types/item-relations.js'; +import { PropertiesTableContentInput, PropertiesTableContentInputSchema } from './types/properties-table.js'; +import { SelectionContentInput, SelectionContentInputSchema } from './types/selection.js'; + +export type NestableComponentContentInput = { + componentId: string; + files?: FilesContentInput; + images?: ImagesContentInput; + videos?: VideosContentInput; + boolean?: BooleanContentInput; + datetime?: DatetimeContentInput; + gridRelations?: GridRelationsContentInput; + itemRelations?: ItemRelationsContentInput; + location?: LocationContentInput; + numeric?: NumericContentInput; + paragraphCollection?: ParagraphCollectionContentInput; + propertiesTable?: PropertiesTableContentInput; + richText?: RichTextContentInput; + selection?: SelectionContentInput; + singleLine?: SingleLineContentInput; + piece?: PieceContentInput; +}; + +export const NestableComponentContentInputSchema: z.ZodType = z.lazy(() => + z.object({ + componentId: z.string().min(1), + files: FilesContentInputSchema.optional(), + images: ImagesContentInputSchema.optional(), + videos: VideosContentInputSchema.optional(), + boolean: BooleanContentInputSchema.optional(), + datetime: DatetimeContentInputSchema.optional(), + gridRelations: GridRelationsContentInputSchema.optional(), + itemRelations: ItemRelationsContentInputSchema.optional(), + location: LocationContentInputSchema.optional(), + numeric: NumericContentInputSchema.optional(), + paragraphCollection: ParagraphCollectionContentInputSchema.optional(), + propertiesTable: PropertiesTableContentInputSchema.optional(), + richText: RichTextContentInputSchema.optional(), + selection: SelectionContentInputSchema.optional(), + singleLine: SingleLineContentInputSchema.optional(), + piece: PieceContentInputSchema.optional(), + }), +); + +export type ComponentContentInput = NestableComponentContentInput & { + componentChoice?: ChoiceContentInput; + componentMultipleChoice?: MultipleChoicesContentInput; + contentChunk?: ChunksContentInput; +}; + +export const ComponentContentInputSchema: z.ZodType = z.lazy(() => + NestableComponentContentInputSchema.and( + z.object({ + componentChoice: ChoiceContentInputSchema.optional(), + componentMultipleChoice: MultipleChoicesContentInputSchema.optional(), + contentChunk: ChunksContentInputSchema.optional(), + }), + ), +); + +/* + * Hoisting Nightmare debug prevention + * Do not try to put those files elsewhere, because base on how you transpile the code, it may not work + * as we have recursive imports here + */ +export const ChoiceContentInputSchema = NestableComponentContentInputSchema; +export type ChoiceContentInput = z.infer; +export const ChunksContentInputSchema = z.object({ + chunks: z.array(z.array(NestableComponentContentInputSchema)), +}); +export type ChunksContentInput = z.infer; +export const MultipleChoicesContentInputSchema = z.array(NestableComponentContentInputSchema); +export type MultipleChoicesContentInput = z.infer; + +export const PieceContentInputSchema = z.object({ + identifier: z.string(), + components: z.array(NestableComponentContentInputSchema), +}); +export type PieceContentInput = z.infer; diff --git a/components/schema/src/pim/components/component-content.ts b/components/schema/src/pim/components/component-content.ts new file mode 100644 index 00000000..c6b1cb3b --- /dev/null +++ b/components/schema/src/pim/components/component-content.ts @@ -0,0 +1,99 @@ +import { z } from 'zod'; + +import { BooleanContent, BooleanContentSchema } from './types/boolean.js'; +import { DatetimeContent, DatetimeContentSchema } from './types/datetime.js'; +import { GridRelationsContent, GridRelationsContentSchema } from './types/grid-relations.js'; +import { ImagesContent, ImagesContentSchema } from './types/images.js'; +import { LocationContent, LocationContentSchema } from './types/location.js'; +import { ParagraphCollectionContent, ParagraphCollectionContentSchema } from './types/paragraph-collection.js'; +import { RichTextContent, RichTextContentSchema } from './types/rich-text.js'; +import { SingleLineContent, SingleLineContentSchema } from './types/single-line.js'; +import { VideosContent, VideosContentSchema } from './types/videos.js'; +import { NumericContent, NumericContentSchema } from './types/numeric.js'; +import { FilesContent, FilesContentSchema } from './types/files.js'; +import { ItemRelationsContent, ItemRelationsContentSchema } from './types/item-relations.js'; +import { PropertiesTableContent, PropertiesTableContentSchema } from './types/properties-table.js'; +import { SelectionContent, SelectionContentSchema } from './types/selection.js'; +import { ComponentSchema } from './component.js'; + +export type NestableComponentContent = { + componentId: string; + files?: FilesContent; + images?: ImagesContent; + videos?: VideosContent; + boolean?: BooleanContent; + datetime?: DatetimeContent; + gridRelations?: GridRelationsContent; + itemRelations?: ItemRelationsContent; + location?: LocationContent; + numeric?: NumericContent; + paragraphCollection?: ParagraphCollectionContent; + propertiesTable?: PropertiesTableContent; + richText?: RichTextContent; + selection?: SelectionContent; + singleLine?: SingleLineContent; + piece?: PieceContent; +}; + +export const NestableComponentContentSchema: z.ZodType = z.lazy(() => + z.object({ + componentId: z.string().min(1), + files: FilesContentSchema.optional(), + images: ImagesContentSchema.optional(), + videos: VideosContentSchema.optional(), + boolean: BooleanContentSchema.optional(), + datetime: DatetimeContentSchema.optional(), + gridRelations: GridRelationsContentSchema.optional(), + itemRelations: ItemRelationsContentSchema.optional(), + location: LocationContentSchema.optional(), + numeric: NumericContentSchema.optional(), + paragraphCollection: ParagraphCollectionContentSchema.optional(), + propertiesTable: PropertiesTableContentSchema.optional(), + richText: RichTextContentSchema.optional(), + selection: SelectionContentSchema.optional(), + singleLine: SingleLineContentSchema.optional(), + piece: PieceContentSchema.optional(), + }), +); + +export type ComponentContent = NestableComponentContent & { + componentChoice?: ChoiceContent; + componentMultipleChoice?: MultipleChoicesContent; + contentChunk?: ChunksContent; +}; + +export const ComponentContentSchema: z.ZodType = z.lazy(() => + NestableComponentContentSchema.and( + z.object({ + componentChoice: ChoiceContentSchema.optional(), + componentMultipleChoice: MultipleChoicesContentSchema.optional(), + contentChunk: ChunksContentSchema.optional(), + }), + ), +); + +/* + * Hoisting Nightmare debug prevention + * Do not try to put those files elsewhere, because base on how you transpile the code, it may not work + * as we have recursive imports here + */ +export const ChoiceContentSchema = z.object({ + selectedComponent: ComponentSchema, +}); +export type ChoiceContent = z.infer; + +export const ChunksContentSchema = z.object({ + chunks: z.array(z.array(ComponentSchema)), +}); +export type ChunksContent = z.infer; + +export const MultipleChoicesContentSchema = z.object({ + selectedComponents: z.array(ComponentSchema), +}); +export type MultipleChoicesContent = z.infer; + +export const PieceContentSchema = z.object({ + identifier: z.string(), + components: z.array(ComponentSchema), +}); +export type PieceContent = z.infer; diff --git a/components/schema/src/pim/components/component-definition.ts b/components/schema/src/pim/components/component-definition.ts new file mode 100644 index 00000000..32863925 --- /dev/null +++ b/components/schema/src/pim/components/component-definition.ts @@ -0,0 +1,23 @@ +import { z } from 'zod'; +import { ComponentTypeEnum } from '../../shared/index.js'; +import { ComponentConfigInputSchema } from './component-config-input.js'; +import { ComponentConfigSchema } from './component-config.js'; + +export const ComponentDefinitionSchema = z.object({ + id: z.string().min(1), + type: ComponentTypeEnum, + name: z.string().min(1), + description: z.string(), + config: ComponentConfigSchema, +}); +export type ComponentDefinition = z.infer; + +export const ComponentDefinitionInputSchema = z.object({ + id: z.string().min(1), + type: ComponentTypeEnum, + name: z.string().min(1), + description: z.string(), + config: ComponentConfigInputSchema, +}); + +export type ComponentDefinitionInput = z.infer; diff --git a/components/schema/src/pim/components/component.ts b/components/schema/src/pim/components/component.ts new file mode 100644 index 00000000..473a2c3e --- /dev/null +++ b/components/schema/src/pim/components/component.ts @@ -0,0 +1,12 @@ +import { z } from 'zod'; +import { ComponentTypeEnum } from '../../shared/index.js'; +import { ComponentContentSchema } from './component-content.js'; + +export const ComponentSchema = z.object({ + componentId: z.string().min(1), + name: z.string().min(1), + type: ComponentTypeEnum, + content: ComponentContentSchema, +}); + +export type Component = z.infer; diff --git a/components/schema/src/pim/components/index.ts b/components/schema/src/pim/components/index.ts new file mode 100644 index 00000000..3b2f92e4 --- /dev/null +++ b/components/schema/src/pim/components/index.ts @@ -0,0 +1,24 @@ +// Others +export * from './component-config.js'; +export * from './component-config-input.js'; +export * from './component-content.js'; +export * from './component-content-input.js'; +export * from './component-definition.js'; +export * from './shared.js'; +export * from './component.js'; + +// Types +export * from './types/boolean.js'; +export * from './types/datetime.js'; +export * from './types/files.js'; +export * from './types/grid-relations.js'; +export * from './types/images.js'; +export * from './types/item-relations.js'; +export * from './types/location.js'; +export * from './types/numeric.js'; +export * from './types/paragraph-collection.js'; +export * from './types/properties-table.js'; +export * from './types/rich-text.js'; +export * from './types/selection.js'; +export * from './types/single-line.js'; +export * from './types/videos.js'; diff --git a/components/schema/src/pim/components/shared.ts b/components/schema/src/pim/components/shared.ts new file mode 100644 index 00000000..599077c1 --- /dev/null +++ b/components/schema/src/pim/components/shared.ts @@ -0,0 +1,37 @@ +import { z } from 'zod'; + +// Generic Stuff +export const GenericComponentConfigSchema = z.object({ + multilingual: z.boolean().optional(), + required: z.boolean().optional(), + discoverable: z.boolean().optional(), +}); +export type GenericComponentConfig = z.infer; +export const GenericComponentConfigInputSchema = GenericComponentConfigSchema; +export type GenericComponentConfigInput = z.infer; + +// Min Max Stuff +export const MinValueSchema = z.number().min(0).nullable().optional(); +export const MaxValueSchema = z.number().min(0).nullable().optional(); +export const MinMaxComponentConfigSchema = GenericComponentConfigSchema.extend({ + min: MinValueSchema, + max: MaxValueSchema, +}); +export type MinMaxComponentConfig = z.infer; + +export const MinMaxComponentConfigInputSchema = GenericComponentConfigInputSchema.extend({ + min: MinValueSchema, + max: MaxValueSchema, +}).refine( + ({ min, max }) => { + if (typeof min === 'number' && typeof max === 'number' && min > max) { + return false; + } + return true; + }, + { + message: 'Min cannot be greater than max', + path: ['min'], + }, +); +export type MinMaxComponentConfigInput = z.infer; diff --git a/components/schema/src/pim/components/types/boolean.ts b/components/schema/src/pim/components/types/boolean.ts new file mode 100644 index 00000000..fa6dfb5b --- /dev/null +++ b/components/schema/src/pim/components/types/boolean.ts @@ -0,0 +1,18 @@ +import { z } from 'zod'; +import { GenericComponentConfigInputSchema, GenericComponentConfigSchema } from '../shared.js'; + +export const BooleanConfigSchema = GenericComponentConfigSchema; +export const BooleanConfigInputSchema = GenericComponentConfigInputSchema; + +export type BooleanConfig = z.infer; +export type BooleanConfigInput = z.infer; + +export const BooleanContentSchema = z.object({ + value: z.boolean().optional(), +}); +export type BooleanContent = z.infer; + +export const BooleanContentInputSchema = z.object({ + value: z.boolean().optional(), +}); +export type BooleanContentInput = z.infer; diff --git a/components/schema/src/pim/components/types/datetime.ts b/components/schema/src/pim/components/types/datetime.ts new file mode 100644 index 00000000..11e1b050 --- /dev/null +++ b/components/schema/src/pim/components/types/datetime.ts @@ -0,0 +1,19 @@ +import { z } from 'zod'; +import { GenericComponentConfigInputSchema, GenericComponentConfigSchema } from '../shared.js'; +import { DateTimeSchema } from '../../../shared/index.js'; + +export const DatetimeConfigSchema = GenericComponentConfigSchema; +export const DatetimeConfigInputSchema = GenericComponentConfigInputSchema; + +export type DatetimeConfig = z.infer; +export type DatetimeConfigInput = z.infer; + +export const DatetimeContentSchema = z.object({ + datetime: DateTimeSchema.optional(), +}); +export type DatetimeContent = z.infer; + +export const DatetimeContentInputSchema = z.object({ + datetime: DateTimeSchema.optional(), +}); +export type DatetimeContentInput = z.infer; diff --git a/components/schema/src/pim/components/types/files.ts b/components/schema/src/pim/components/types/files.ts new file mode 100644 index 00000000..d12220f4 --- /dev/null +++ b/components/schema/src/pim/components/types/files.ts @@ -0,0 +1,56 @@ +import { z } from 'zod'; +import { MinMaxComponentConfigInputSchema, MinMaxComponentConfigSchema } from '../shared.js'; +import { + DateTimeSchema, + FileSizeUnitEnum, + KeyValuePairInputSchema, + KeyValuePairSchema, +} from '../../../shared/index.js'; + +// in the future that may be needed to split between config and input +const extraConfig = z.object({ + acceptedContentTypes: z + .array( + z.object({ + contentType: z.string(), + extensionLabel: z.string().optional(), + }), + ) + .optional(), + maxFileSize: z.object({ + size: z.number(), + unit: FileSizeUnitEnum, + }), +}); +export const FilesConfigSchema = MinMaxComponentConfigSchema.and(extraConfig); +export const FilesConfigInputSchema = MinMaxComponentConfigInputSchema.and(extraConfig); + +export type FilesConfig = z.infer; +export type FilesConfigInput = z.infer; + +export const FileContentSchema = z.object({ + key: z.string().min(1), + contentType: z.string().optional(), + title: z.string().optional(), + meta: z.array(KeyValuePairSchema).optional(), + size: z.number().optional(), + createdAt: DateTimeSchema.optional(), + updatedAt: DateTimeSchema.optional(), + url: z.string().min(1), +}); +export type FileContent = z.infer; + +export const FilesContentSchema = z.object({ + files: z.array(FileContentSchema).optional(), +}); +export type FilesContent = z.infer; + +export const FileInputSchema = z.object({ + key: z.string().min(1), + title: z.string().optional(), + meta: z.array(KeyValuePairInputSchema).optional(), +}); +export type FileInput = z.infer; + +export const FilesContentInputSchema = z.array(FileInputSchema); +export type FilesContentInput = z.infer; diff --git a/components/schema/src/pim/components/types/grid-relations.ts b/components/schema/src/pim/components/types/grid-relations.ts new file mode 100644 index 00000000..5da7f647 --- /dev/null +++ b/components/schema/src/pim/components/types/grid-relations.ts @@ -0,0 +1,65 @@ +import { z } from 'zod'; +import { MinMaxComponentConfigInputSchema, MinMaxComponentConfigSchema } from '../shared.js'; +import { + DateTimeSchema, + IdSchema, + ItemTypeEnum, + KeyValuePairSchema, + OwnerSchema, + VersionLabelEnum, +} from '../../../shared/index.js'; + +export const GridRelationsConfigSchema = MinMaxComponentConfigSchema; +export const GridRelationsConfigInputSchema = MinMaxComponentConfigInputSchema; + +export type GridRelationsConfig = z.infer; +export type GridRelationsConfigInput = z.infer; + +export const GridContentSchema = z.object({ + id: IdSchema, + language: z.string(), + name: z.string().optional(), + version: z + .object({ + id: IdSchema, + label: VersionLabelEnum, + createdAt: DateTimeSchema, + owner: OwnerSchema.optional(), + }) + .optional(), + meta: z.array(KeyValuePairSchema).optional(), + createdAt: DateTimeSchema, + updatedAt: DateTimeSchema.optional(), + rows: z + .array( + z.object({ + columns: z + .array( + z.object({ + itemId: IdSchema, + itemType: ItemTypeEnum, + meta: z.array(KeyValuePairSchema).optional(), + layout: z.object({ + rowspan: z.number(), + colspan: z.number(), + }), + }), + ) + .optional(), + meta: z.array(KeyValuePairSchema).optional(), + }), + ) + .optional(), +}); +export type GridContent = z.infer; + +export const GridRelationsContentSchema = z.object({ + gridIds: z.array(IdSchema).optional(), + grids: z.array(GridContentSchema).optional(), +}); +export type GridRelationsContent = z.infer; + +export const GridRelationsContentInputSchema = z.object({ + gridIds: z.array(IdSchema), +}); +export type GridRelationsContentInput = z.infer; diff --git a/components/schema/src/pim/components/types/images.ts b/components/schema/src/pim/components/types/images.ts new file mode 100644 index 00000000..2f6ba4e8 --- /dev/null +++ b/components/schema/src/pim/components/types/images.ts @@ -0,0 +1,70 @@ +import { z } from 'zod'; +import { MinMaxComponentConfigInputSchema, MinMaxComponentConfigSchema } from '../shared.js'; +import { RichTextContentInputSchema, RichTextContentSchema } from './rich-text.js'; +import { DateTimeSchema, IdSchema, KeyValuePairInputSchema, KeyValuePairSchema } from '../../../shared/index.js'; + +export const ImagesConfigSchema = MinMaxComponentConfigSchema; +export const ImagesConfigInputSchema = MinMaxComponentConfigInputSchema; + +export type ImagesConfig = z.infer; +export type ImagesConfigInput = z.infer; + +export const FocalPointSchema = z.object({ + x: z.number().min(0), + y: z.number().min(0), +}); +export type FocalPoint = z.infer; + +export const ShowcaseSchema = z.object({ + itemIds: z.array(IdSchema).optional(), + skus: z.array(z.string()).optional(), + hotpost: FocalPointSchema.optional(), + meta: z.array(KeyValuePairInputSchema).optional(), +}); +export type Showcase = z.infer; + +export const ImageVariantSchema = z.object({ + key: z.string().min(1), + width: z.number(), + height: z.number(), + size: z.number(), + url: z.string().min(1), +}); +export type ImageVariant = z.infer; + +export const ImageContentSchema = z.object({ + key: z.string().min(1), + mimeType: z.string().optional(), + altText: z.string().optional(), + caption: RichTextContentSchema.optional(), + meta: z.array(KeyValuePairSchema).optional(), + variants: z.array(ImageVariantSchema), + width: z.number(), + height: z.number(), + focalPoint: FocalPointSchema.optional(), + createdAt: DateTimeSchema.optional(), + updatedAt: DateTimeSchema.optional(), + url: z.string().min(1), + showcase: z.array(ShowcaseSchema).optional(), +}); +export type ImageContent = z.infer; + +export const ImagesContentSchema = z.object({ + imageIds: z.array(z.string()).optional(), + images: z.array(ImageContentSchema).optional(), +}); +export type ImagesContent = z.infer; + +export const ImageContentInputSchema = z.object({ + key: z.string().min(1), + mimeType: z.string().optional(), + altText: z.string().optional(), + caption: RichTextContentInputSchema.optional(), + meta: z.array(KeyValuePairInputSchema).optional(), + focalPoint: FocalPointSchema.optional(), + showcase: z.array(ShowcaseSchema).optional(), +}); +export type ImageContentInput = z.infer; + +export const ImagesContentInputSchema = z.array(ImageContentInputSchema); +export type ImagesContentInput = z.infer; diff --git a/components/schema/src/pim/components/types/item-relations.ts b/components/schema/src/pim/components/types/item-relations.ts new file mode 100644 index 00000000..86d4b854 --- /dev/null +++ b/components/schema/src/pim/components/types/item-relations.ts @@ -0,0 +1,83 @@ +import { z } from 'zod'; +import { + MaxValueSchema, + MinMaxComponentConfigInputSchema, + MinMaxComponentConfigSchema, + MinValueSchema, +} from '../shared.js'; +import { IdSchema } from '../../../shared/index.js'; + +// in the future that may be needed to split between config and input +const extraConfig = z.object({ + acceptedShapeIdentifiers: z.array(z.string()).optional(), + quickSelect: z + .object({ + folders: z.array(z.object({ folderId: IdSchema })).optional(), + }) + .optional(), +}); + +export const ItemRelationsConfigSchema = MinMaxComponentConfigSchema.omit({ + min: true, + max: true, +}).merge(extraConfig); + +export const ItemRelationsConfigInputSchema = MinMaxComponentConfigInputSchema.and( + z + .object({ + minItems: MinValueSchema, + maxItems: MaxValueSchema, + minSkus: MinValueSchema, + maxSkus: MaxValueSchema, + }) + .merge(extraConfig), +).refine( + ({ min, max, minItems, maxItems, minSkus, maxSkus }) => { + if (typeof min === 'number' && typeof max === 'number') { + if (min === max) { + return true; + } + if (min > max) { + return false; + } + } + if (typeof minItems === 'number' && typeof maxItems === 'number') { + if (minItems === maxItems) { + return true; + } + if (minItems > maxItems) { + return false; + } + } + if (typeof minSkus === 'number' && typeof maxSkus === 'number') { + if (minSkus === maxSkus) { + return true; + } + if (minSkus > maxSkus) { + return false; + } + } + return true; + }, + { + message: 'Min cannot be greater than max', + path: ['min'], + }, +); + +export type ItemRelationsConfig = z.infer; +export type ItemRelationsConfigInput = z.infer; + +export const ItemRelationsContentSchema = z.object({ + itemIds: z.array(IdSchema).optional(), + // skus: z.array(z.string()).optional() // @todo missing in Core Next + // items: @todo + // productVariants: @todo +}); +export type ItemRelationsContent = z.infer; + +export const ItemRelationsContentInputSchema = z.object({ + itemIds: z.array(IdSchema).optional(), + skus: z.array(z.string()).optional(), +}); +export type ItemRelationsContentInput = z.infer; diff --git a/components/schema/src/pim/components/types/location.ts b/components/schema/src/pim/components/types/location.ts new file mode 100644 index 00000000..d2b88865 --- /dev/null +++ b/components/schema/src/pim/components/types/location.ts @@ -0,0 +1,20 @@ +import { z } from 'zod'; +import { GenericComponentConfigInputSchema, GenericComponentConfigSchema } from '../shared.js'; + +export const LocationConfigSchema = GenericComponentConfigSchema; +export const LocationConfigInputSchema = GenericComponentConfigInputSchema; + +export type LocationConfig = z.infer; +export type LocationConfigInput = z.infer; + +export const LocationContentSchema = z.object({ + lat: z.number().optional(), + long: z.number().optional(), +}); +export type LocationContent = z.infer; + +export const LocationContentInputSchema = z.object({ + lat: z.number().optional(), + long: z.number().optional(), +}); +export type LocationContentInput = z.infer; diff --git a/components/schema/src/pim/components/types/numeric.ts b/components/schema/src/pim/components/types/numeric.ts new file mode 100644 index 00000000..fa3a6006 --- /dev/null +++ b/components/schema/src/pim/components/types/numeric.ts @@ -0,0 +1,26 @@ +import { z } from 'zod'; +import { GenericComponentConfigInputSchema, GenericComponentConfigSchema } from '../shared.js'; + +// in the future that may be needed to split between config and input +const extraConfig = z.object({ + decimalPlaces: z.number().positive().optional(), + units: z.array(z.string()).optional(), +}); + +export const NumericConfigSchema = GenericComponentConfigSchema.merge(extraConfig); +export const NumericConfigInputSchema = GenericComponentConfigInputSchema.merge(extraConfig); + +export type NumericConfig = z.infer; +export type NumericConfigInput = z.infer; + +export const NumericContentSchema = z.object({ + number: z.number(), + unit: z.string().optional(), +}); +export type NumericContent = z.infer; + +export const NumericContentInputSchema = z.object({ + number: z.number(), + unit: z.string().optional(), +}); +export type NumericContentInput = z.infer; diff --git a/components/schema/src/pim/components/types/paragraph-collection.ts b/components/schema/src/pim/components/types/paragraph-collection.ts new file mode 100644 index 00000000..337e7d3c --- /dev/null +++ b/components/schema/src/pim/components/types/paragraph-collection.ts @@ -0,0 +1,45 @@ +import { z } from 'zod'; +import { GenericComponentConfigInputSchema, GenericComponentConfigSchema } from '../shared.js'; +import { RichTextContentInputSchema, RichTextContentSchema } from './rich-text.js'; +import { ImageContentInputSchema, ImageContentSchema } from './images.js'; +import { SingleLineContentInputSchema, SingleLineContentSchema } from './single-line.js'; +import { VideoContentInputSchema, VideoContentSchema, VideosContentInputSchema } from './videos.js'; + +export const ParagraphCollectionConfigSchema = GenericComponentConfigSchema.omit({ + multilingual: true, +}).extend({ + multilingual: z.enum(['body', 'images', 'title', 'videos', 'structure']), +}); + +export const ParagraphCollectionConfigInputSchema = GenericComponentConfigInputSchema.omit({ + multilingual: true, +}).extend({ + multilingual: z.enum(['body', 'images', 'title', 'videos', 'structure']), +}); + +export type ParagraphCollectionConfig = z.infer; +export type ParagraphCollectionConfigInput = z.infer; + +export const ParagraphContentSchema = z.object({ + title: SingleLineContentSchema.optional(), + body: RichTextContentSchema.optional(), + images: z.array(ImageContentSchema).optional(), + videos: z.array(VideoContentSchema).optional(), +}); + +export const ParagraphContentInputSchema = z.object({ + body: RichTextContentInputSchema.optional(), + images: z.array(ImageContentInputSchema).optional(), + title: SingleLineContentInputSchema.optional(), + videos: z.array(VideoContentInputSchema).optional(), +}); + +export const ParagraphCollectionContentSchema = z.object({ + paragraphs: z.array(ParagraphContentSchema).optional(), +}); +export type ParagraphCollectionContent = z.infer; + +export const ParagraphCollectionContentInputSchema = z.object({ + paragraphs: z.array(ParagraphContentInputSchema).optional(), +}); +export type ParagraphCollectionContentInput = z.infer; diff --git a/components/schema/src/pim/components/types/properties-table.ts b/components/schema/src/pim/components/types/properties-table.ts new file mode 100644 index 00000000..89ac54b6 --- /dev/null +++ b/components/schema/src/pim/components/types/properties-table.ts @@ -0,0 +1,43 @@ +import { z } from 'zod'; +import { GenericComponentConfigInputSchema, GenericComponentConfigSchema } from '../shared.js'; +import { KeyValuePairInputSchema, KeyValuePairSchema } from '../../../shared/index.js'; + +// in the future that may be needed to split between config and input +const extraConfig = z.object({ + sections: z + .array( + z.object({ + title: z.string().optional(), + keys: z.array(z.string()), + }), + ) + .optional(), +}); +export const PropertiesTableConfigSchema = GenericComponentConfigSchema.merge(extraConfig); +export const PropertiesTableConfigInputSchema = GenericComponentConfigInputSchema.merge(extraConfig); + +export type PropertiesTableConfig = z.infer; +export type PropertiesTableConfigInput = z.infer; + +export const PropertiesTableContentSchema = z.object({ + sections: z + .array( + z.object({ + title: z.string().optional(), + properties: z.array(KeyValuePairSchema).optional(), + }), + ) + .optional(), +}); +export type PropertiesTableContent = z.infer; + +export const PropertiesTableSectionContentInputSchema = z.object({ + title: z.string().optional(), + properties: z.array(KeyValuePairInputSchema).optional(), +}); + +export type PropertiesTableSectionContentInput = z.infer; +export const PropertiesTableContentInputSchema = z.object({ + sections: z.array(PropertiesTableSectionContentInputSchema).optional(), +}); +export type PropertiesTableContentInput = z.infer; diff --git a/components/schema/src/pim/components/types/rich-text.ts b/components/schema/src/pim/components/types/rich-text.ts new file mode 100644 index 00000000..6a28875b --- /dev/null +++ b/components/schema/src/pim/components/types/rich-text.ts @@ -0,0 +1,37 @@ +import { z } from 'zod'; +import { MinMaxComponentConfigInputSchema, MinMaxComponentConfigSchema } from '../shared.js'; + +export const RichTextConfigSchema = MinMaxComponentConfigSchema; +export const RichTextConfigInputSchema = MinMaxComponentConfigInputSchema; + +export type RichTextConfig = z.infer; +export type RichTextConfigInput = z.infer; + +export const RichTextContentSchema = z.object({ + html: z.array(z.string()).optional(), + json: z.array(z.any()).optional(), + plainText: z.array(z.string()).optional(), +}); +export type RichTextContent = z.infer; + +export const RichTextContentInputSchema = z + .object({ + html: z.array(z.string()).optional(), + json: z.array(z.string()).optional(), + }) + .refine( + ({ json }) => { + if (json) { + try { + json.map((str) => JSON.parse(str)); + } catch (err) { + return false; + } + } + return true; + }, + { + message: 'Invalid json provided to rich text content input', + }, + ); +export type RichTextContentInput = z.infer; diff --git a/components/schema/src/pim/components/types/selection.ts b/components/schema/src/pim/components/types/selection.ts new file mode 100644 index 00000000..146ecdc9 --- /dev/null +++ b/components/schema/src/pim/components/types/selection.ts @@ -0,0 +1,30 @@ +import { z } from 'zod'; +import { MinMaxComponentConfigInputSchema, MinMaxComponentConfigSchema } from '../shared.js'; +import { KeyValuePairSchema } from '../../../shared/index.js'; + +// in the future that may be needed to split between config and input +const extraConfig = z.object({ + options: z.array( + z.object({ + key: z.string(), + value: z.string(), + isPreselected: z.boolean().optional(), + }), + ), +}); + +export const SelectionConfigSchema = MinMaxComponentConfigSchema.and(extraConfig); +export const SelectionConfigInputSchema = MinMaxComponentConfigInputSchema.and(extraConfig); + +export type SelectionConfig = z.infer; +export type SelectionConfigInput = z.infer; + +export const SelectionContentSchema = z.object({ + options: z.array(KeyValuePairSchema), +}); +export type SelectionContent = z.infer; + +export const SelectionContentInputSchema = z.object({ + keys: z.array(z.string()), +}); +export type SelectionContentInput = z.infer; diff --git a/components/schema/src/pim/components/types/single-line.ts b/components/schema/src/pim/components/types/single-line.ts new file mode 100644 index 00000000..71bb149d --- /dev/null +++ b/components/schema/src/pim/components/types/single-line.ts @@ -0,0 +1,23 @@ +import { z } from 'zod'; +import { MinMaxComponentConfigInputSchema, MinMaxComponentConfigSchema } from '../shared.js'; + +// in the future that may be needed to split between config and input +const extraConfig = z.object({ + pattern: z.string().optional(), +}); + +export const SingleLineConfigSchema = MinMaxComponentConfigSchema.and(extraConfig); +export const SingleLineConfigInputSchema = MinMaxComponentConfigInputSchema.and(extraConfig); + +export type SingleLineConfig = z.infer; +export type SingleLineConfigInput = z.infer; + +export const SingleLineContentSchema = z.object({ + text: z.string().optional(), +}); +export type SingleLineContent = z.infer; + +export const SingleLineContentInputSchema = z.object({ + text: z.string().optional(), +}); +export type SingleLineContentInput = z.infer; diff --git a/components/schema/src/pim/components/types/videos.ts b/components/schema/src/pim/components/types/videos.ts new file mode 100644 index 00000000..7a8c4191 --- /dev/null +++ b/components/schema/src/pim/components/types/videos.ts @@ -0,0 +1,31 @@ +import { z } from 'zod'; +import { MinMaxComponentConfigInputSchema, MinMaxComponentConfigSchema } from '../shared.js'; +import { ImageContentInputSchema, ImagesContentSchema } from './images.js'; + +export const VideosConfigSchema = MinMaxComponentConfigSchema; +export const VideosConfigInputSchema = MinMaxComponentConfigInputSchema; + +export type VideosConfig = z.infer; +export type VideosConfigInput = z.infer; + +export const VideoContentSchema = z.object({ + key: z.string().min(1), + thumbnails: z.array(ImagesContentSchema).optional(), + title: z.string().optional(), +}); +export type VideoContent = z.infer; + +export const VideosContentSchema = z.object({ + videos: z.array(VideoContentSchema).optional(), +}); +export type VideosContent = z.infer; + +export const VideoContentInputSchema = z.object({ + key: z.string().min(1), + thumbnails: z.array(ImageContentInputSchema).optional(), + title: z.string().optional(), +}); +export type VideoContentInput = z.infer; + +export const VideosContentInputSchema = z.array(VideoContentInputSchema); +export type VideosContentInput = z.infer; diff --git a/components/schema/src/pim/index.ts b/components/schema/src/pim/index.ts new file mode 100644 index 00000000..f16be068 --- /dev/null +++ b/components/schema/src/pim/index.ts @@ -0,0 +1,2 @@ +export * from './shape/index.js'; +export * from './components/index.js'; diff --git a/components/schema/src/pim/shape/index.ts b/components/schema/src/pim/shape/index.ts new file mode 100644 index 00000000..4e59d690 --- /dev/null +++ b/components/schema/src/pim/shape/index.ts @@ -0,0 +1,45 @@ +import { z } from 'zod'; +import { ItemTypeEnum, KeyValuePairInputSchema } from '../../shared/index.js'; +import { ComponentDefinitionInputSchema, ComponentDefinitionSchema } from '../components/component-definition.js'; + +const BaseShapeInputSchema = z.object({ + identifier: z.string().min(2).max(64), + name: z.string().min(1), + meta: KeyValuePairInputSchema.optional().nullable(), + components: z.array(ComponentDefinitionInputSchema).optional().nullable(), +}); + +export const CreateDocumentShapeInputSchema = BaseShapeInputSchema.extend({ + type: z.literal(ItemTypeEnum.Values.document), +}); + +export const CreateFolderShapeInputSchema = BaseShapeInputSchema.extend({ + type: z.literal(ItemTypeEnum.Values.folder), +}); + +export const CreateProductShapeInputSchema = BaseShapeInputSchema.extend({ + type: z.literal(ItemTypeEnum.Values.product), + variantComponents: z.array(ComponentDefinitionInputSchema).optional().nullable(), +}); + +export const UpdateShapeInputSchema = BaseShapeInputSchema.extend({ + components: z.array(ComponentDefinitionInputSchema).optional().nullable(), + variantComponents: z.array(ComponentDefinitionInputSchema).optional().nullable(), +}); + +export const BasicShapeSchema = z.object({ + identifier: z.string().min(2).max(64), + name: z.string().min(1), + type: ItemTypeEnum, +}); + +export const ShapeSchema = BasicShapeSchema.extend({ + components: z.array(ComponentDefinitionSchema).optional(), + variantComponents: z.array(ComponentDefinitionSchema).optional(), +}); + +export type CreateDocumentShapeInput = z.infer; +export type CreateFolderShapeInput = z.infer; +export type CreateProductShapeInput = z.infer; +export type UpdateShapeInput = z.infer; +export type Shape = z.infer; diff --git a/components/schema/src/shape/components.ts b/components/schema/src/shape/components.ts deleted file mode 100644 index 1db1efec..00000000 --- a/components/schema/src/shape/components.ts +++ /dev/null @@ -1,355 +0,0 @@ -import { z } from 'zod'; -import { IdSchema } from '../shared/index.js'; -import { ShapeComponentTypeEnum } from './enums.js'; - -const GenericComponentConfigSchema = z.object({ - multilingual: z.boolean().optional(), - required: z.boolean().optional(), - discoverable: z.boolean().optional(), -}); - -type GenericComponentConfig = z.infer; - -const minValueSchema = z.number().min(0).nullable().optional(); -const maxValueSchema = z.number().min(0).nullable().optional(); -const minMaxSchema = GenericComponentConfigSchema.extend({ min: minValueSchema, max: maxValueSchema }); -const minMaxItemRelationsSchema = z.object({ - min: minValueSchema, - max: maxValueSchema, - minItems: minValueSchema, - maxItems: maxValueSchema, - minSkus: minValueSchema, - maxSkus: maxValueSchema, -}); - -export const MinMaxComponentConfigSchema = minMaxSchema - .transform(({ min, max }) => { - // API throws an error of max being less than min if max is explicitly null. - // This transform can be removed if the API issue is resolved. - const result: z.infer = {}; - if (min !== null && min !== undefined) { - result.min = min; - } - if (max !== null && max !== undefined) { - result.max = max; - } - return result; - }) - .refine( - ({ min, max }) => { - if (typeof min === 'number' && typeof max === 'number') { - if (min === max) { - return true; - } - if (min > max) { - return false; - } - } - return true; - }, - { - message: 'Min cannot be greater than max', - path: ['min'], - }, - ); - -export const MinMaxItemRelationsComponentConfigSchema = minMaxItemRelationsSchema - .transform(({ min, max, minSkus, minItems, maxSkus, maxItems }) => { - // API throws an error of max being less than min if max is explicitly null. - // This transform can be removed if the API issue is resolved. - const result: z.infer = {}; - if (min !== null && min !== undefined) { - result.min = min; - } - if (minSkus !== null && minSkus !== undefined) { - result.minSkus = minSkus; - } - if (minItems !== null && minItems !== undefined) { - result.minItems = minItems; - } - if (max !== null && max !== undefined) { - result.max = max; - } - if (maxSkus !== null && maxSkus !== undefined) { - result.maxSkus = maxSkus; - } - if (maxItems !== null && maxItems !== undefined) { - result.maxItems = maxItems; - } - return result; - }) - .refine( - ({ min, max, minItems, maxItems, minSkus, maxSkus }) => { - if (typeof min === 'number' && typeof max === 'number') { - if (min === max) { - return true; - } - if (min > max) { - return false; - } - } - if (typeof minItems === 'number' && typeof maxItems === 'number') { - if (minItems === maxItems) { - return true; - } - if (minItems > maxItems) { - return false; - } - } - if (typeof minSkus === 'number' && typeof maxSkus === 'number') { - if (minSkus === maxSkus) { - return true; - } - if (minSkus > maxSkus) { - return false; - } - } - return true; - }, - { - message: 'Min cannot be greater than max', - path: ['min'], - }, - ); - -export type ComponentChoiceComponentConfig = GenericComponentConfig & { - choices: any[]; -}; -export type ComponentMultipleChoiceComponentConfig = GenericComponentConfig & { - choices: any[]; - allowDuplicates: boolean; -}; - -export const ComponentChoiceComponentConfigInputSchema: z.ZodType = z - .lazy(() => - GenericComponentConfigSchema.extend({ - choices: z.array(ShapeComponentInputSchema), - }), - ) - .refine(({ choices }) => !choices.find((cmp) => cmp.type === 'componentChoice' || cmp.type === 'contentChunk'), { - message: 'Nesting "componentChoice" or "contentChunk" structural components is not allowed', - }); - -export const ComponentMultipleChoiceComponentConfigInputSchema: z.ZodType = - z.lazy(() => - GenericComponentConfigSchema.extend({ - choices: z.array(ShapeComponentInputSchema), - allowDuplicates: z.coerce.boolean(), - }), - ); - -export type ContentChunkComponentConfig = GenericComponentConfig & { - components: any[]; - repeatable?: boolean; -}; - -export const ContentChunkComponentConfigInputSchema: z.ZodType = z - .lazy(() => - GenericComponentConfigSchema.extend({ - components: z.array(ShapeComponentInputSchema), - repeatable: z.coerce.boolean().default(false), - }), - ) - .refine( - ({ components }) => !components.find((cmp) => cmp.type === 'componentChoice' || cmp.type === 'contentChunk'), - { - message: 'Nesting "componentChoice" or "contentChunk" structural components is not allowed', - }, - ); - -export const FileComponentConfigSchema = MinMaxComponentConfigSchema.and( - z.object({ - acceptedContentTypes: z - .array( - z.object({ - contentType: z.string(), - extensionLabel: z.string().optional().nullable(), - }), - ) - .optional() - .nullable(), - maxFileSize: z.object({ - size: z.number(), - unit: z.enum(['Bytes', 'GiB', 'KiB', 'MiB']), - }), - }), -); - -export const ItemRelationsComponentConfigSchema = MinMaxItemRelationsComponentConfigSchema.and( - z.object({ - acceptedShapeIdentifiers: z.array(z.string()).optional().nullable(), - quickSelect: z - .object({ - folders: z - .array(z.object({ folderId: IdSchema })) - .optional() - .nullable(), - }) - - .optional() - .nullable(), - }), -).superRefine(({ max, maxItems, maxSkus }, ctx) => { - if (max && max > 50) { - ctx.addIssue({ - code: z.ZodIssueCode.too_big, - maximum: 50, - type: 'number', - inclusive: true, - message: 'Max cannot be greater than 50', - }); - } - if (maxItems && maxItems > 50) { - ctx.addIssue({ - code: z.ZodIssueCode.too_big, - maximum: 50, - type: 'number', - inclusive: true, - message: 'MaxItems cannot be greater than 50', - }); - } - if (maxSkus && maxSkus > 50) { - ctx.addIssue({ - code: z.ZodIssueCode.too_big, - maximum: 50, - type: 'number', - inclusive: true, - message: 'MaxSkus cannot be greater than 50', - }); - } -}); - -export const NumericComponentConfigSchema = GenericComponentConfigSchema.extend({ - decimalPlaces: z.number().min(0).optional(), - units: z.array(z.string()).optional(), -}); - -export type PieceComponentConfig = GenericComponentConfig & { - identifier: string; - components: any[]; -}; - -export const PieceComponentConfigInputSchema: z.ZodType = z.lazy(() => - GenericComponentConfigSchema.extend({ - identifier: z.string().min(1), - components: z.array(ShapeComponentInputSchema), - }), -); - -export const PropertiesTableComponentConfigSchema = GenericComponentConfigSchema.extend({ - sections: z.array( - z.object({ - title: z.string().optional().nullable(), - keys: z.array(z.string()), - }), - ), -}); - -export const SelectionComponentConfigInputSchema = MinMaxComponentConfigSchema.and( - z.object({ - options: z - .array( - z.object({ - key: z.string().min(1), - value: z.string().min(1), - isPreselected: z.coerce.boolean().default(false), - }), - ) - .optional() - .nullable(), - }), -); - -export const ShapeComponentConfigInputSchema = z.object({ - singleLine: MinMaxComponentConfigSchema.optional(), - boolean: GenericComponentConfigSchema.optional(), - datetime: GenericComponentConfigSchema.optional(), - gridRelations: GenericComponentConfigSchema.optional(), - location: GenericComponentConfigSchema.optional(), - paragraphCollection: GenericComponentConfigSchema.optional(), - richText: GenericComponentConfigSchema.optional(), - componentChoice: ComponentChoiceComponentConfigInputSchema.optional(), - componentMultipleChoice: ComponentMultipleChoiceComponentConfigInputSchema.optional(), - contentChunk: ContentChunkComponentConfigInputSchema.optional(), - files: FileComponentConfigSchema.optional(), - images: GenericComponentConfigSchema.optional(), //@todo: add ImageComponentConfigSchema - videos: GenericComponentConfigSchema.optional(), //@todo: add VideoComponentConfigSchema - itemRelations: ItemRelationsComponentConfigSchema.optional(), - numeric: NumericComponentConfigSchema.optional(), - piece: PieceComponentConfigInputSchema.optional(), - propertiesTable: PropertiesTableComponentConfigSchema.optional(), - selection: SelectionComponentConfigInputSchema.optional(), -}); - -export const ShapeComponentConfigSchema = ComponentChoiceComponentConfigInputSchema.or( - ContentChunkComponentConfigInputSchema, -) - .or(FileComponentConfigSchema) - .or(ItemRelationsComponentConfigSchema) - .or(NumericComponentConfigSchema) - .or(PieceComponentConfigInputSchema) - .or(ComponentMultipleChoiceComponentConfigInputSchema) - .or(PropertiesTableComponentConfigSchema) - .or(SelectionComponentConfigInputSchema); - -export const ShapeComponentInputSchema = z - .object({ - id: z.string().min(1), - name: z.string().min(1), - type: ShapeComponentTypeEnum, - description: z.string().optional().nullable(), - config: ShapeComponentConfigInputSchema.optional().nullable(), - }) - - .refine( - ({ type, config }) => { - if (!config) { - return true; - } - - // Check if there are any config options that don't match the type - // of the component. - return !Object.entries(config).find(([key, value]) => value && key !== type); - }, - { - message: 'Incorrect config type provided on shape component', - }, - ); - -export const ShapeComponentSchema = z - .object({ - id: z.string().min(1), - name: z.string().min(1), - type: ShapeComponentTypeEnum, - description: z.string().optional().nullable(), - config: ShapeComponentConfigSchema.optional().nullable(), - }) - - .refine( - ({ type, config }) => { - if (!config) { - return true; - } - - // Check if there are any config options that don't match the type - // of the component. - return !Object.entries(config).find(([key, value]) => value && key !== type); - }, - { - message: 'Incorrect config type provided on shape component', - }, - ); - -export type MinMaxComponentConfig = z.infer; -export type MinMaxItemRelationsComponentConfig = z.infer; -export type FileComponentConfig = z.infer; -export type ItemRelationsComponentConfig = z.infer; -export type NumericComponentConfig = z.infer; -export type PropertiesTableComponentConfig = z.infer; -export type SelectionComponentConfig = z.infer; - -export type ShapeComponentConfigInput = z.infer; -export type ShapeComponentInput = z.infer; - -export type ShapeComponentConfig = z.infer; -export type ShapeComponent = z.infer; diff --git a/components/schema/src/shape/enums.ts b/components/schema/src/shape/enums.ts deleted file mode 100644 index 118c4f21..00000000 --- a/components/schema/src/shape/enums.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { z } from 'zod'; - -export const ShapeComponentTypeEnum = z.enum([ - 'boolean', - 'componentChoice', - 'componentMultipleChoice', - 'contentChunk', - 'datetime', - 'gridRelations', - 'images', - 'itemRelations', - 'location', - 'numeric', - 'paragraphCollection', - 'piece', - 'propertiesTable', - 'richText', - 'selection', - 'singleLine', - 'videos', - 'files', -]); - -export type ShapeComponentType = z.infer; diff --git a/components/schema/src/shape/index.ts b/components/schema/src/shape/index.ts deleted file mode 100644 index 277b51a8..00000000 --- a/components/schema/src/shape/index.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { z } from 'zod'; -import { IdSchema, ItemTypeEnum, KeyValuePairSchema } from '../shared/index.js'; -import { ShapeComponentInputSchema, ShapeComponentSchema } from './components.js'; - -export * from './components.js'; -export * from './enums.js'; - -const TypedShapeSchema = z - .object({ - type: z.literal(ItemTypeEnum.Values.product), - variantComponents: z.array(ShapeComponentInputSchema).optional().nullable(), - }) - .or( - z.object({ - type: z.literal(ItemTypeEnum.Values.document).or(z.literal(ItemTypeEnum.Values.folder)), - variantComponents: z.never().optional(), - }), - ); - -const BaseShapeInputSchema = z.object({ - identifier: z.string().min(2).max(64), - name: z.string().min(1), - meta: KeyValuePairSchema.optional().nullable(), - components: z.array(ShapeComponentInputSchema).optional().nullable(), -}); -// @deprecated -export const CreateShapeInputSchema = BaseShapeInputSchema.extend({ - tenantId: IdSchema, -}).and(TypedShapeSchema); - -export const NextPimCreateShapeInputSchema = BaseShapeInputSchema.and(TypedShapeSchema); - -export const UpdateShapeInputSchema = BaseShapeInputSchema.omit({ - identifier: true, -}).extend({ - components: z.array(ShapeComponentInputSchema).optional().nullable(), - variantComponents: z.array(ShapeComponentInputSchema).optional().nullable(), -}); - -export const BasicShapeSchema = z.object({ - identifier: z.string().min(2).max(64), - name: z.string().min(1), - type: ItemTypeEnum, -}); - -export const ShapeSchema = BasicShapeSchema.extend({ - components: z.array(ShapeComponentSchema).optional(), - variantComponents: z.array(ShapeComponentSchema).optional(), -}); - -export type CreateShapeInput = z.infer; -export type NextPimCreateShapeInput = z.infer; -export type UpdateShapeInput = z.infer; -export type Shape = z.infer; diff --git a/components/schema/src/shared/index.ts b/components/schema/src/shared/index.ts index 827070c4..3072d1a7 100644 --- a/components/schema/src/shared/index.ts +++ b/components/schema/src/shared/index.ts @@ -1,19 +1,59 @@ import { z } from 'zod'; export const IdSchema = z.string().regex(/^[0-9a-f]{24}$/); +export type Id = z.infer; + export const ItemTypeEnum = z.enum(['product', 'document', 'folder']); -export const KeyValuePairSchema = z.record(z.string()); +export type ItemType = z.infer; + +export const VersionLabelEnum = z.enum(['current', 'draft', 'published']); +export type VersionLabel = z.infer; + +export const FileSizeUnitEnum = z.enum(['Bytes', 'GiB', 'KiB', 'MiB']); +export type FileSizeUnit = z.infer; + export const DateTimeSchema = z.string().refine( (str) => Number.isInteger(Date.parse(str)), (str) => ({ message: `${str} is not a valid date` }), ); +export const KeyValuePairSchema = z.record(z.string()); export const KeyValuePairInputSchema = z.object({ key: z.string().min(1), value: z.string().optional(), }); - -export type Id = z.infer; export type KeyValuePair = z.infer; export type KeyValuePairInput = z.infer; -export type ItemType = z.infer; + +// todo: maybe core next only +export const OwnerSchema = z.object({ + id: IdSchema, + firstName: z.string().optional(), + lastName: z.string().optional(), + email: z.string().optional(), + companyName: z.string().optional(), +}); +export type Owner = z.infer; + +export const ComponentTypeEnum = z.enum([ + 'boolean', + 'componentChoice', + 'componentMultipleChoice', + 'contentChunk', + 'datetime', + 'gridRelations', + 'images', + 'itemRelations', + 'location', + 'numeric', + 'paragraphCollection', + 'piece', + 'propertiesTable', + 'richText', + 'selection', + 'singleLine', + 'videos', + 'files', +]); + +export type ComponentType = z.infer; diff --git a/components/schema/src/subscriptions/index.ts b/components/schema/src/subscriptions/index.ts new file mode 100644 index 00000000..e69de29b diff --git a/components/schema/src/tenant/index.ts b/components/schema/src/tenant/index.ts deleted file mode 100644 index eb7d1419..00000000 --- a/components/schema/src/tenant/index.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { z } from 'zod'; -import { CreateShapeInputSchema, ShapeSchema } from '../shape/index.js'; -import { IdSchema } from '../shared/index.js'; - -export const TenantDefaultsInputSchema = z.object({ - currency: z.string().optional(), - language: z.string().optional(), -}); - -export const CreateTenantInputSchema = z.object({ - identifier: z.string().min(1), - name: z.string().min(1), - defaults: TenantDefaultsInputSchema.optional(), - shapes: z.array(CreateShapeInputSchema).optional(), -}); - -export const TenantDefaultsSchema = z.object({ - currency: z.string().min(1), - language: z.string().min(1), -}); - -export const TenantSchema = z.object({ - id: IdSchema, - identifier: z.string().min(1), - name: z.string().min(1), - defaults: TenantDefaultsSchema, - shapes: z.array(ShapeSchema).optional(), -}); - -export type TenantDefaultsInput = z.infer; -export type CreateTenantInput = z.infer; - -export type TenantDefaults = z.infer; -export type Tenant = z.infer; diff --git a/components/schema/src/topic/index.ts b/components/schema/src/topic/index.ts deleted file mode 100644 index 0cb3da5f..00000000 --- a/components/schema/src/topic/index.ts +++ /dev/null @@ -1,83 +0,0 @@ -import { z } from 'zod'; - -export const MAX_CHILD_COUNT = 100; - -export type CreateChildTopicInput = { - name: string; - children?: CreateChildTopicInput[]; - pathIdentifier?: string; -}; - -const validateChildren = (children?: CreateChildTopicInput[]): boolean => { - if (!children?.length) { - return true; - } - - const countChildren = (children: CreateChildTopicInput[]): number => - children.reduce( - (acc, child) => (child.children?.length ? acc + 1 + countChildren(child.children) : acc + 1), - 0, - ); - - return countChildren(children) <= MAX_CHILD_COUNT; -}; - -export const CreateChildTopicInputSchema: z.ZodType = z.lazy(() => - z.object({ - name: z.string().min(1), - children: z.array(CreateChildTopicInputSchema).optional(), - pathIdentifier: z.string().optional(), - }), -); - -const children = z.array(CreateChildTopicInputSchema).refine(validateChildren, { - params: { - code: 'MAX_CHILD_COUNT', - }, - message: `Cannot provide more than ${MAX_CHILD_COUNT} descendants in a topic mutation`, -}); - -export const BulkCreateTopicInputSchema = z.object({ - name: z.string().min(1), - children: children.optional(), - parentId: z.string().optional(), - pathIdentifier: z.string().optional(), -}); - -export const CreateTopicInputSchema = z.object({ - name: z.string().min(1), - children: children.optional(), - parentId: z.string().optional(), - pathIdentifier: z.string().optional(), - tenantId: z.string().min(1), -}); - -export const UpdateTopicInputSchema = z.object({ - name: z.string().optional(), - parentId: z.string().optional(), - pathIdentifier: z.string().optional(), -}); - -export type Topic = { - language?: string; - name: string; - id?: string; - parentId?: string; - pathIdentifier?: string; - children?: Topic[]; -}; - -export const TopicSchema: z.ZodType = z.lazy(() => - z.object({ - language: z.string().optional(), - id: z.string().optional(), - parentId: z.string().optional(), - name: z.string().min(1), - pathIdentifier: z.string().optional(), - children: z.array(TopicSchema).optional(), - }), -); - -export type BulkCreateTopicInput = z.infer; -export type CreateTopicInput = z.infer; -export type UpdateTopicInput = z.infer; diff --git a/components/schema/tests/shape/itemRelations.test.ts b/components/schema/tests/shape/itemRelations.test.ts deleted file mode 100644 index 3ba5fb36..00000000 --- a/components/schema/tests/shape/itemRelations.test.ts +++ /dev/null @@ -1,101 +0,0 @@ -import { ZodError } from 'zod'; -import { ItemRelationsComponentConfig, ItemRelationsComponentConfigSchema } from '../../src/shape/index.js'; -import { expect, test } from 'vitest'; - -interface testCase { - name: string; - min?: number | null; - max?: number | null; - minItems?: number | null; - maxItems?: number | null; - minSkus?: number | null; - maxSkus?: number | null; - error?: ZodError; - expected?: ItemRelationsComponentConfig; -} - -const testCases: testCase[] = [ - { - name: 'parses a valid max value', - max: 1, - expected: { - max: 1, - }, - }, - { - name: 'parses a valid min and max value', - min: 1, - max: 2, - expected: { - min: 1, - max: 2, - }, - }, - { - name: 'errors when max is greater than 50 (current hard limit)', - max: 51, - error: new ZodError([ - { - code: 'too_big', - maximum: 50, - type: 'number', - inclusive: true, - message: 'Max cannot be greater than 50', - path: [], - }, - ]), - }, - { - name: 'errors when max is greater than 50 (current hard limit)', - maxItems: 51, - error: new ZodError([ - { - code: 'too_big', - maximum: 50, - type: 'number', - inclusive: true, - message: 'MaxItems cannot be greater than 50', - path: [], - }, - ]), - }, - { - name: 'errors when max is greater than 50 (current hard limit)', - maxSkus: 51, - error: new ZodError([ - { - code: 'too_big', - maximum: 50, - type: 'number', - inclusive: true, - message: 'MaxSkus cannot be greater than 50', - path: [], - }, - ]), - }, -]; - -test('itemRelations.test', () => { - testCases.forEach((tc) => { - const shouldBeSuccess = tc.expected !== undefined; - const result: any = ItemRelationsComponentConfigSchema.safeParse({ - min: tc.min, - max: tc.max, - maxSkus: tc.maxSkus, - maxItems: tc.maxItems, - minSkus: tc.minSkus, - minItems: tc.minItems, - }); - - // if (!result.success) { - // console.log('result', result.error); - // } - expect(result.success).toBe(shouldBeSuccess); - - if (shouldBeSuccess) { - expect(result?.data).toStrictEqual(tc.expected); - } else { - expect(result?.error).toStrictEqual(tc.error); - } - }); -}); diff --git a/components/schema/tests/shape/minMaxValidation.test.ts b/components/schema/tests/shape/minMaxValidation.test.ts deleted file mode 100644 index 86fbbe2e..00000000 --- a/components/schema/tests/shape/minMaxValidation.test.ts +++ /dev/null @@ -1,182 +0,0 @@ -import { ZodError } from 'zod'; -import { MinMaxItemRelationsComponentConfig, MinMaxItemRelationsComponentConfigSchema } from '../../src/shape/index.js'; -import { expect, test } from 'vitest'; - -interface testCase { - name: string; - min?: number | null; - max?: number | null; - minItems?: number | null; - maxItems?: number | null; - minSkus?: number | null; - maxSkus?: number | null; - error?: ZodError; - expected?: MinMaxItemRelationsComponentConfig; -} - -const testCases: testCase[] = [ - { - name: 'parses empty config', - expected: {}, - }, - { - name: 'parses a valid min value', - min: 1, - expected: { - min: 1, - }, - }, - { - name: 'parses a valid minItems value', - minItems: 1, - expected: { - minItems: 1, - }, - }, - { - name: 'parses a valid max value', - max: 1, - expected: { - max: 1, - }, - }, - { - name: 'parses a valid maxItems value', - maxItems: 1, - expected: { - maxItems: 1, - }, - }, - { - name: 'parses a valid min and max value', - min: 1, - max: 2, - expected: { - min: 1, - max: 2, - }, - }, - { - name: 'parses when min and max are equal', - min: 1, - max: 1, - expected: { - min: 1, - max: 1, - }, - }, - { - name: 'parses when minSkus and maxSkus are equal', - minSkus: 1, - maxSkus: 1, - expected: { - minSkus: 1, - maxSkus: 1, - }, - }, - { - name: 'does not error when min is undefined', - min: undefined, - max: 1, - expected: { - max: 1, - }, - }, - { - name: 'does not error when max is undefined', - min: 1, - max: undefined, - expected: { - min: 1, - }, - }, - { - name: 'does not error when min is null', - min: null, - max: 1, - expected: { - max: 1, - }, - }, - { - name: 'does not error when max is null', - min: 1, - max: null, - expected: { - min: 1, - }, - }, - { - name: 'does not error when both min and max are null', - min: null, - max: null, - expected: {}, - }, - { - name: 'does not error when both min and max are 0', - min: 0, - max: 0, - expected: { - min: 0, - max: 0, - }, - }, - { - name: 'does not error when both min and max are 0', - minItems: 0, - maxItems: 0, - expected: { - minItems: 0, - maxItems: 0, - }, - }, - { - name: 'errors when min is negative', - min: -1, - error: new ZodError([ - { - code: 'too_small', - minimum: 0, - type: 'number', - inclusive: true, - exact: false, - message: 'Number must be greater than or equal to 0', - path: ['min'], - }, - ]), - }, - { - name: 'errors when min is greater than max', - min: 2, - max: 1, - error: new ZodError([ - { - code: 'custom', - message: 'Min cannot be greater than max', - path: ['min'], - }, - ]), - }, -]; - -test('minMaxValidation.test', () => { - testCases.forEach((tc) => { - const shouldBeSuccess = tc.expected !== undefined; - const result: any = MinMaxItemRelationsComponentConfigSchema.safeParse({ - min: tc.min, - max: tc.max, - minItems: tc.minItems, - maxItems: tc.maxItems, - minSkus: tc.minSkus, - maxSkus: tc.maxSkus, - }); - - expect(result.success).toBe(shouldBeSuccess); - - if (shouldBeSuccess) { - expect(result?.data).toStrictEqual(tc.expected); - } else { - expect(result?.error).toStrictEqual(tc.error); - } - }); -}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ee39d8be..9e015c47 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -118,8 +118,8 @@ importers: specifier: workspace:* version: link:../js-api-client '@crystallize/schema': - specifier: workspace:* - version: link:../schema + specifier: ^2.0 + version: 2.0.0 zod: specifier: ^3.23.8 version: 3.23.8 @@ -572,6 +572,12 @@ packages: integrity: sha512-UNtPCbrwrenpmrXuRwn9jYpPoweNXj8X5sMvYgsqYyaH8jQ6LfUJSk3dJLnBK+6sfYPrF4iAIo5sd5HQ+tg75A==, } + '@crystallize/schema@2.0.0': + resolution: + { + integrity: sha512-w6Mnz+31niFNPgnLNcmsB/07vM9Mn/Y41HSOahwE9TO2KMNl8b8RSrfvVE6i/8Siygyn2hVWpDNOEClO/WTDkw==, + } + '@esbuild/aix-ppc64@0.21.5': resolution: { @@ -5137,6 +5143,10 @@ snapshots: '@bufbuild/protobuf@2.2.2': {} + '@crystallize/schema@2.0.0': + dependencies: + zod: 3.23.8 + '@esbuild/aix-ppc64@0.21.5': optional: true