@reactionary/source 0.0.52 → 0.2.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env-template +19 -0
- package/.github/workflows/pull-request.yml +3 -1
- package/.github/workflows/release.yml +9 -0
- package/.vscode/extensions.json +0 -2
- package/LICENSE +21 -0
- package/README.md +175 -23
- package/core/package.json +6 -3
- package/core/src/cache/cache.interface.ts +1 -0
- package/core/src/cache/index.ts +4 -0
- package/core/src/cache/memory-cache.ts +30 -2
- package/core/src/cache/noop-cache.ts +15 -1
- package/core/src/cache/redis-cache.ts +20 -0
- package/core/src/client/client-builder.ts +71 -54
- package/core/src/client/client.ts +9 -47
- package/core/src/client/index.ts +2 -0
- package/core/src/decorators/index.ts +1 -0
- package/core/src/decorators/reactionary.decorator.ts +203 -34
- package/core/src/index.ts +6 -19
- package/core/src/initialization.ts +1 -18
- package/core/src/metrics/metrics.ts +67 -0
- package/core/src/providers/analytics.provider.ts +1 -6
- package/core/src/providers/base.provider.ts +5 -69
- package/core/src/providers/cart.provider.ts +15 -55
- package/core/src/providers/category.provider.ts +7 -11
- package/core/src/providers/checkout.provider.ts +17 -15
- package/core/src/providers/identity.provider.ts +6 -8
- package/core/src/providers/index.ts +2 -1
- package/core/src/providers/inventory.provider.ts +15 -5
- package/core/src/providers/order-search.provider.ts +29 -0
- package/core/src/providers/order.provider.ts +47 -15
- package/core/src/providers/price.provider.ts +30 -36
- package/core/src/providers/product-search.provider.ts +61 -0
- package/core/src/providers/product.provider.ts +71 -12
- package/core/src/providers/profile.provider.ts +74 -14
- package/core/src/providers/store.provider.ts +3 -5
- package/core/src/schemas/capabilities.schema.ts +10 -3
- package/core/src/schemas/errors/generic.error.ts +9 -0
- package/core/src/schemas/errors/index.ts +4 -0
- package/core/src/schemas/errors/invalid-input.error.ts +9 -0
- package/core/src/schemas/errors/invalid-output.error.ts +9 -0
- package/core/src/schemas/errors/not-found.error.ts +9 -0
- package/core/src/schemas/index.ts +7 -0
- package/core/src/schemas/models/analytics.model.ts +2 -1
- package/core/src/schemas/models/base.model.ts +6 -24
- package/core/src/schemas/models/cart.model.ts +5 -8
- package/core/src/schemas/models/category.model.ts +4 -9
- package/core/src/schemas/models/checkout.model.ts +6 -7
- package/core/src/schemas/models/cost.model.ts +4 -3
- package/core/src/schemas/models/currency.model.ts +2 -1
- package/core/src/schemas/models/identifiers.model.ts +106 -62
- package/core/src/schemas/models/identity.model.ts +10 -19
- package/core/src/schemas/models/index.ts +2 -1
- package/core/src/schemas/models/inventory.model.ts +8 -5
- package/core/src/schemas/models/order-search.model.ts +28 -0
- package/core/src/schemas/models/order.model.ts +20 -26
- package/core/src/schemas/models/payment.model.ts +14 -17
- package/core/src/schemas/models/price.model.ts +11 -11
- package/core/src/schemas/models/product-search.model.ts +42 -0
- package/core/src/schemas/models/product.model.ts +64 -22
- package/core/src/schemas/models/profile.model.ts +19 -22
- package/core/src/schemas/models/shipping-method.model.ts +24 -29
- package/core/src/schemas/models/store.model.ts +9 -5
- package/core/src/schemas/mutations/analytics.mutation.ts +8 -7
- package/core/src/schemas/mutations/base.mutation.ts +2 -1
- package/core/src/schemas/mutations/cart.mutation.ts +33 -33
- package/core/src/schemas/mutations/checkout.mutation.ts +23 -30
- package/core/src/schemas/mutations/identity.mutation.ts +4 -3
- package/core/src/schemas/mutations/profile.mutation.ts +38 -3
- package/core/src/schemas/queries/base.query.ts +2 -1
- package/core/src/schemas/queries/cart.query.ts +3 -3
- package/core/src/schemas/queries/category.query.ts +18 -18
- package/core/src/schemas/queries/checkout.query.ts +7 -9
- package/core/src/schemas/queries/identity.query.ts +2 -1
- package/core/src/schemas/queries/index.ts +2 -1
- package/core/src/schemas/queries/inventory.query.ts +5 -5
- package/core/src/schemas/queries/order-search.query.ts +10 -0
- package/core/src/schemas/queries/order.query.ts +3 -2
- package/core/src/schemas/queries/price.query.ts +10 -4
- package/core/src/schemas/queries/product-search.query.ts +16 -0
- package/core/src/schemas/queries/product.query.ts +13 -6
- package/core/src/schemas/queries/profile.query.ts +5 -2
- package/core/src/schemas/queries/store.query.ts +6 -5
- package/core/src/schemas/result.ts +107 -0
- package/core/src/schemas/session.schema.ts +4 -4
- package/core/src/test/reactionary.decorator.spec.ts +249 -0
- package/core/src/zod-utils.ts +19 -0
- package/core/tsconfig.json +1 -1
- package/core/tsconfig.spec.json +2 -26
- package/core/vitest.config.ts +14 -0
- package/documentation/1-purpose.md +114 -0
- package/documentation/2-getting-started.md +229 -0
- package/documentation/3-querying-and-changing-data.md +74 -0
- package/documentation/4-product-data.md +107 -0
- package/documentation/5-cart-and-checkout.md +211 -0
- package/documentation/6-product-search.md +143 -0
- package/documentation/7-marketing.md +3 -0
- package/eslint.config.mjs +1 -0
- package/examples/node/eslint.config.mjs +1 -4
- package/examples/node/package.json +10 -3
- package/examples/node/project.json +4 -1
- package/examples/node/src/basic/basic-node-provider-model-extension.spec.ts +22 -23
- package/examples/node/src/basic/basic-node-provider-query-extension.spec.ts +15 -11
- package/examples/node/src/basic/basic-node-setup.spec.ts +44 -28
- package/examples/node/src/basic/client-creation.spec.ts +53 -0
- package/examples/node/src/capabilities/cart.spec.ts +255 -0
- package/examples/node/src/capabilities/category.spec.ts +193 -0
- package/examples/node/src/capabilities/checkout.spec.ts +341 -0
- package/examples/node/src/capabilities/identity.spec.ts +93 -0
- package/examples/node/src/capabilities/inventory.spec.ts +66 -0
- package/examples/node/src/capabilities/order-search.spec.ts +265 -0
- package/examples/node/src/capabilities/order.spec.ts +91 -0
- package/examples/node/src/capabilities/price.spec.ts +51 -0
- package/examples/node/src/capabilities/product-search.spec.ts +293 -0
- package/examples/node/src/capabilities/product.spec.ts +122 -0
- package/examples/node/src/capabilities/profile.spec.ts +316 -0
- package/examples/node/src/capabilities/store.spec.ts +26 -0
- package/examples/node/src/utils.ts +147 -0
- package/examples/node/tsconfig.json +9 -12
- package/examples/node/tsconfig.lib.json +1 -2
- package/examples/node/tsconfig.spec.json +2 -14
- package/examples/node/vitest.config.ts +14 -0
- package/migrations.json +22 -5
- package/nx.json +8 -47
- package/package.json +24 -96
- package/providers/algolia/README.md +39 -2
- package/providers/algolia/package.json +2 -1
- package/providers/algolia/src/core/initialize.ts +7 -14
- package/providers/algolia/src/index.ts +2 -4
- package/providers/algolia/src/providers/index.ts +1 -0
- package/providers/algolia/src/providers/product-search.provider.ts +241 -0
- package/providers/algolia/src/schema/capabilities.schema.ts +2 -3
- package/providers/algolia/src/schema/index.ts +3 -0
- package/providers/algolia/src/schema/search.schema.ts +8 -8
- package/providers/algolia/tsconfig.json +1 -1
- package/providers/algolia/tsconfig.lib.json +1 -1
- package/providers/algolia/tsconfig.spec.json +2 -14
- package/providers/algolia/vitest.config.ts +14 -0
- package/providers/commercetools/README.md +30 -3
- package/providers/commercetools/package.json +2 -1
- package/providers/commercetools/src/core/client.ts +178 -99
- package/providers/commercetools/src/core/initialize.ts +130 -74
- package/providers/commercetools/src/core/token-cache.ts +45 -0
- package/providers/commercetools/src/index.ts +3 -2
- package/providers/commercetools/src/providers/cart.provider.ts +281 -341
- package/providers/commercetools/src/providers/category.provider.ts +223 -138
- package/providers/commercetools/src/providers/checkout.provider.ts +631 -449
- package/providers/commercetools/src/providers/identity.provider.ts +50 -29
- package/providers/commercetools/src/providers/index.ts +2 -2
- package/providers/commercetools/src/providers/inventory.provider.ts +76 -74
- package/providers/commercetools/src/providers/order-search.provider.ts +220 -0
- package/providers/commercetools/src/providers/order.provider.ts +96 -61
- package/providers/commercetools/src/providers/price.provider.ts +147 -117
- package/providers/commercetools/src/providers/product-search.provider.ts +528 -0
- package/providers/commercetools/src/providers/product.provider.ts +249 -74
- package/providers/commercetools/src/providers/profile.provider.ts +445 -28
- package/providers/commercetools/src/providers/store.provider.ts +54 -40
- package/providers/commercetools/src/schema/capabilities.schema.ts +3 -1
- package/providers/commercetools/src/schema/commercetools.schema.ts +17 -3
- package/providers/commercetools/src/schema/configuration.schema.ts +1 -0
- package/providers/commercetools/src/schema/session.schema.ts +7 -0
- package/providers/commercetools/src/test/caching.spec.ts +82 -0
- package/providers/commercetools/src/test/identity.spec.ts +109 -0
- package/providers/commercetools/src/test/test-utils.ts +21 -19
- package/providers/commercetools/tsconfig.json +1 -1
- package/providers/commercetools/tsconfig.lib.json +1 -1
- package/providers/commercetools/tsconfig.spec.json +2 -14
- package/providers/commercetools/vitest.config.ts +15 -0
- package/providers/fake/README.md +20 -4
- package/providers/fake/package.json +2 -1
- package/providers/fake/src/core/initialize.ts +47 -49
- package/providers/fake/src/providers/analytics.provider.ts +5 -7
- package/providers/fake/src/providers/cart.provider.ts +163 -92
- package/providers/fake/src/providers/category.provider.ts +78 -50
- package/providers/fake/src/providers/checkout.provider.ts +254 -0
- package/providers/fake/src/providers/identity.provider.ts +57 -65
- package/providers/fake/src/providers/index.ts +6 -2
- package/providers/fake/src/providers/inventory.provider.ts +40 -36
- package/providers/fake/src/providers/order-search.provider.ts +78 -0
- package/providers/fake/src/providers/order.provider.ts +106 -0
- package/providers/fake/src/providers/price.provider.ts +93 -41
- package/providers/fake/src/providers/product-search.provider.ts +206 -0
- package/providers/fake/src/providers/product.provider.ts +56 -41
- package/providers/fake/src/providers/profile.provider.ts +147 -0
- package/providers/fake/src/providers/store.provider.ts +30 -20
- package/providers/fake/src/schema/capabilities.schema.ts +5 -1
- package/providers/fake/src/test/cart.provider.spec.ts +59 -80
- package/providers/fake/src/test/category.provider.spec.ts +145 -87
- package/providers/fake/src/test/checkout.provider.spec.ts +222 -0
- package/providers/fake/src/test/order-search.provider.spec.ts +50 -0
- package/providers/fake/src/test/order.provider.spec.ts +44 -0
- package/providers/fake/src/test/price.provider.spec.ts +50 -45
- package/providers/fake/src/test/product.provider.spec.ts +15 -7
- package/providers/fake/src/test/profile.provider.spec.ts +167 -0
- package/providers/fake/tsconfig.json +1 -1
- package/providers/fake/tsconfig.lib.json +1 -1
- package/providers/fake/tsconfig.spec.json +2 -12
- package/providers/fake/vitest.config.ts +14 -0
- package/providers/medusa/README.md +30 -0
- package/providers/medusa/TESTING.md +98 -0
- package/providers/medusa/eslint.config.mjs +19 -0
- package/providers/medusa/package.json +22 -0
- package/providers/medusa/project.json +34 -0
- package/providers/medusa/src/core/client.ts +370 -0
- package/providers/medusa/src/core/initialize.ts +78 -0
- package/providers/medusa/src/index.ts +13 -0
- package/providers/medusa/src/providers/cart.provider.ts +575 -0
- package/providers/medusa/src/providers/category.provider.ts +247 -0
- package/providers/medusa/src/providers/checkout.provider.ts +636 -0
- package/providers/medusa/src/providers/identity.provider.ts +137 -0
- package/providers/medusa/src/providers/inventory.provider.ts +173 -0
- package/providers/medusa/src/providers/order-search.provider.ts +202 -0
- package/providers/medusa/src/providers/order.provider.ts +226 -0
- package/providers/medusa/src/providers/price.provider.ts +140 -0
- package/providers/medusa/src/providers/product-search.provider.ts +243 -0
- package/providers/medusa/src/providers/product.provider.ts +261 -0
- package/providers/medusa/src/providers/profile.provider.ts +392 -0
- package/providers/medusa/src/schema/capabilities.schema.ts +18 -0
- package/providers/medusa/src/schema/configuration.schema.ts +11 -0
- package/providers/medusa/src/schema/medusa.schema.ts +31 -0
- package/providers/medusa/src/test/cart.provider.spec.ts +240 -0
- package/providers/medusa/src/test/category.provider.spec.ts +231 -0
- package/providers/medusa/src/test/checkout.spec.ts +349 -0
- package/providers/medusa/src/test/identity.provider.spec.ts +122 -0
- package/providers/medusa/src/test/inventory.provider.spec.ts +88 -0
- package/providers/medusa/src/test/large-cart.provider.spec.ts +103 -0
- package/providers/medusa/src/test/price.provider.spec.ts +104 -0
- package/providers/medusa/src/test/product.provider.spec.ts +146 -0
- package/providers/medusa/src/test/search.provider.spec.ts +203 -0
- package/providers/medusa/src/test/test-utils.ts +13 -0
- package/providers/medusa/src/utils/medusa-helpers.ts +89 -0
- package/providers/medusa/tsconfig.json +21 -0
- package/providers/medusa/tsconfig.lib.json +9 -0
- package/providers/medusa/tsconfig.spec.json +4 -0
- package/providers/medusa/vitest.config.ts +15 -0
- package/providers/meilisearch/README.md +48 -0
- package/providers/meilisearch/eslint.config.mjs +22 -0
- package/providers/meilisearch/package.json +13 -0
- package/providers/meilisearch/project.json +34 -0
- package/providers/meilisearch/src/core/initialize.ts +21 -0
- package/providers/meilisearch/src/index.ts +6 -0
- package/providers/meilisearch/src/providers/index.ts +1 -0
- package/providers/meilisearch/src/providers/order-search.provider.ts +222 -0
- package/providers/meilisearch/src/providers/product-search.provider.ts +251 -0
- package/providers/meilisearch/src/schema/capabilities.schema.ts +10 -0
- package/providers/meilisearch/src/schema/configuration.schema.ts +11 -0
- package/providers/meilisearch/src/schema/index.ts +3 -0
- package/providers/meilisearch/src/schema/search.schema.ts +14 -0
- package/providers/meilisearch/tsconfig.json +24 -0
- package/providers/meilisearch/tsconfig.lib.json +10 -0
- package/providers/meilisearch/tsconfig.spec.json +4 -0
- package/providers/meilisearch/vitest.config.ts +14 -0
- package/providers/posthog/package.json +2 -1
- package/providers/posthog/tsconfig.json +1 -1
- package/tsconfig.base.json +5 -0
- package/vitest.config.ts +10 -0
- package/core/src/providers/search.provider.ts +0 -18
- package/core/src/schemas/models/search.model.ts +0 -36
- package/core/src/schemas/queries/search.query.ts +0 -9
- package/examples/next/.swcrc +0 -30
- package/examples/next/eslint.config.mjs +0 -21
- package/examples/next/index.d.ts +0 -6
- package/examples/next/next-env.d.ts +0 -5
- package/examples/next/next.config.js +0 -31
- package/examples/next/project.json +0 -9
- package/examples/next/public/.gitkeep +0 -0
- package/examples/next/public/favicon.ico +0 -0
- package/examples/next/src/app/global.css +0 -0
- package/examples/next/src/app/layout.tsx +0 -18
- package/examples/next/src/app/page.module.scss +0 -2
- package/examples/next/src/app/page.tsx +0 -47
- package/examples/next/src/instrumentation.ts +0 -9
- package/examples/next/tsconfig.json +0 -44
- package/examples/node/jest.config.ts +0 -10
- package/jest.config.ts +0 -6
- package/jest.preset.js +0 -3
- package/providers/algolia/jest.config.ts +0 -10
- package/providers/algolia/src/providers/product.provider.ts +0 -66
- package/providers/algolia/src/providers/search.provider.ts +0 -106
- package/providers/algolia/src/test/search.provider.spec.ts +0 -91
- package/providers/commercetools/jest.config.cjs +0 -10
- package/providers/commercetools/src/providers/search.provider.ts +0 -96
- package/providers/commercetools/src/test/cart.provider.spec.ts +0 -199
- package/providers/commercetools/src/test/category.provider.spec.ts +0 -168
- package/providers/commercetools/src/test/checkout.provider.spec.ts +0 -312
- package/providers/commercetools/src/test/identity.provider.spec.ts +0 -88
- package/providers/commercetools/src/test/inventory.provider.spec.ts +0 -41
- package/providers/commercetools/src/test/price.provider.spec.ts +0 -81
- package/providers/commercetools/src/test/product.provider.spec.ts +0 -80
- package/providers/commercetools/src/test/profile.provider.spec.ts +0 -49
- package/providers/commercetools/src/test/search.provider.spec.ts +0 -61
- package/providers/commercetools/src/test/store.provider.spec.ts +0 -37
- package/providers/fake/jest.config.cjs +0 -10
- package/providers/fake/src/providers/search.provider.ts +0 -132
|
@@ -1,144 +1,184 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { PaginationOptionsSchema } from './base.model.js';
|
|
3
|
+
import type { InferType } from '../../zod-utils.js';
|
|
4
|
+
export const OrderStatusSchema = z.enum(['AwaitingPayment', 'ReleasedToFulfillment', 'Shipped', 'Cancelled']).describe('The current status of the order.');
|
|
5
|
+
export const OrderInventoryStatusSchema = z.enum(['NotAllocated', 'Allocated', 'Backordered', 'Preordered']).describe('The inventory release status of the order.');
|
|
2
6
|
|
|
3
7
|
export const FacetIdentifierSchema = z.looseObject({
|
|
4
|
-
key: z.string()
|
|
8
|
+
key: z.string(),
|
|
5
9
|
});
|
|
6
10
|
|
|
7
|
-
export const FacetValueIdentifierSchema = z.
|
|
8
|
-
facet: FacetIdentifierSchema
|
|
9
|
-
key: z.string()
|
|
11
|
+
export const FacetValueIdentifierSchema = z.object({
|
|
12
|
+
facet: FacetIdentifierSchema,
|
|
13
|
+
key: z.string(),
|
|
10
14
|
});
|
|
11
15
|
|
|
12
|
-
export const
|
|
13
|
-
|
|
16
|
+
export const ProductVariantIdentifierSchema = z.looseObject({
|
|
17
|
+
sku: z.string(),
|
|
14
18
|
});
|
|
15
19
|
|
|
16
|
-
export const
|
|
17
|
-
key: z.string().
|
|
20
|
+
export const ProductAttributeIdentifierSchema = z.looseObject({
|
|
21
|
+
key: z.string().describe('The unique identifier for the product attribute.'),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export const ProductAttributeValueIdentifierSchema = z.looseObject({
|
|
25
|
+
key: z.string().describe('The unique identifier for the product attribute value.'),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export const ProductOptionIdentifierSchema = z.looseObject({
|
|
29
|
+
key: z.string().describe('The unique identifier for the product option.'),
|
|
18
30
|
});
|
|
19
31
|
|
|
20
|
-
export const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
pageSize: z.number().default(20),
|
|
24
|
-
facets: z.array(FacetValueIdentifierSchema.required()).default(() => []),
|
|
32
|
+
export const ProductOptionValueIdentifierSchema = z.looseObject({
|
|
33
|
+
option: ProductOptionIdentifierSchema,
|
|
34
|
+
key: z.string().describe('The value of the product option, e.g., "Red" or "Large".'),
|
|
25
35
|
});
|
|
26
36
|
|
|
37
|
+
export const ProductIdentifierSchema = z.looseObject({
|
|
38
|
+
key: z.string()
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
|
|
27
42
|
export const CartIdentifierSchema = z.looseObject({
|
|
28
|
-
key: z.string()
|
|
43
|
+
key: z.string(),
|
|
29
44
|
});
|
|
30
45
|
|
|
31
46
|
export const CartItemIdentifierSchema = z.looseObject({
|
|
32
|
-
key: z.string()
|
|
47
|
+
key: z.string(),
|
|
33
48
|
});
|
|
34
49
|
|
|
35
50
|
export const PriceIdentifierSchema = z.looseObject({
|
|
36
|
-
|
|
51
|
+
variant: ProductVariantIdentifierSchema,
|
|
37
52
|
});
|
|
38
53
|
|
|
39
54
|
export const CategoryIdentifierSchema = z.looseObject({
|
|
40
|
-
key: z.string()
|
|
55
|
+
key: z.string(),
|
|
41
56
|
});
|
|
42
57
|
|
|
43
58
|
export const StoreIdentifierSchema = z.looseObject({
|
|
44
|
-
key: z.string()
|
|
59
|
+
key: z.string(),
|
|
45
60
|
});
|
|
46
61
|
|
|
47
62
|
export const OrderIdentifierSchema = z.looseObject({
|
|
48
|
-
key: z.string()
|
|
63
|
+
key: z.string(),
|
|
49
64
|
});
|
|
50
65
|
|
|
51
66
|
export const OrderItemIdentifierSchema = z.looseObject({
|
|
52
|
-
key: z.string()
|
|
67
|
+
key: z.string(),
|
|
53
68
|
});
|
|
54
69
|
|
|
55
70
|
|
|
56
71
|
export const CheckoutIdentifierSchema = z.looseObject({
|
|
57
|
-
key: z.string()
|
|
72
|
+
key: z.string(),
|
|
58
73
|
});
|
|
59
74
|
|
|
60
75
|
export const CheckoutItemIdentifierSchema = z.looseObject({
|
|
61
|
-
key: z.string()
|
|
76
|
+
key: z.string(),
|
|
62
77
|
});
|
|
63
78
|
|
|
64
79
|
/**
|
|
65
80
|
* The target store the user is interacting with. Can change over time, and is not necessarily the same as the default store.
|
|
66
81
|
*/
|
|
67
82
|
export const WebStoreIdentifierSchema = z.looseObject({
|
|
68
|
-
key: z.string()
|
|
83
|
+
key: z.string(),
|
|
69
84
|
});
|
|
70
85
|
|
|
71
86
|
export const FulfillmentCenterIdentifierSchema = z.looseObject({
|
|
72
|
-
key: z.string()
|
|
87
|
+
key: z.string(),
|
|
73
88
|
});
|
|
74
89
|
|
|
75
90
|
export const InventoryIdentifierSchema = z.looseObject({
|
|
76
|
-
|
|
77
|
-
fulfillmentCenter: FulfillmentCenterIdentifierSchema
|
|
78
|
-
FulfillmentCenterIdentifierSchema.parse({})
|
|
79
|
-
),
|
|
91
|
+
variant: ProductVariantIdentifierSchema,
|
|
92
|
+
fulfillmentCenter: FulfillmentCenterIdentifierSchema,
|
|
80
93
|
});
|
|
81
94
|
|
|
82
95
|
export const IdentityIdentifierSchema = z.looseObject({
|
|
83
|
-
userId: z.string()
|
|
96
|
+
userId: z.string(),
|
|
84
97
|
});
|
|
85
98
|
|
|
86
99
|
export const ShippingMethodIdentifierSchema = z.looseObject({
|
|
87
|
-
key: z.string()
|
|
100
|
+
key: z.string(),
|
|
88
101
|
});
|
|
89
102
|
|
|
90
103
|
export const PaymentMethodIdentifierSchema = z.looseObject({
|
|
91
|
-
method: z.string()
|
|
92
|
-
name: z.string()
|
|
93
|
-
paymentProcessor: z.string()
|
|
104
|
+
method: z.string(),
|
|
105
|
+
name: z.string(),
|
|
106
|
+
paymentProcessor: z.string(),
|
|
94
107
|
});
|
|
95
108
|
|
|
96
109
|
export const AddressIdentifierSchema = z.looseObject({
|
|
97
|
-
nickName: z.string()
|
|
110
|
+
nickName: z.string(),
|
|
98
111
|
});
|
|
99
112
|
|
|
100
113
|
export const PaymentInstructionIdentifierSchema = z.looseObject({
|
|
101
|
-
key: z.string()
|
|
114
|
+
key: z.string(),
|
|
102
115
|
});
|
|
103
116
|
|
|
104
117
|
export const PickupPointIdentifierSchema = z.looseObject({
|
|
105
|
-
key: z.string()
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
export
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
export
|
|
118
|
-
|
|
118
|
+
key: z.string(),
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
export const ProductSearchIdentifierSchema = z.looseObject({
|
|
123
|
+
term: z.string().describe('The search term used to find products.'),
|
|
124
|
+
facets: z.array(FacetValueIdentifierSchema).describe('The facets applied to filter the search results.'),
|
|
125
|
+
filters: z.array(z.string()).describe('Additional filters applied to the search results.'),
|
|
126
|
+
paginationOptions: PaginationOptionsSchema.describe('Pagination options for the search results.'),
|
|
127
|
+
categoryFilter: FacetValueIdentifierSchema.optional().describe('An optional category filter applied to the search results.'),
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
export const OrderSearchIdentifierSchema = z.looseObject({
|
|
131
|
+
term: z.string().describe('The search term used to find orders. Not all providers may support term-based search for orders.'),
|
|
132
|
+
partNumber: z.array(z.string()).optional().describe('An optional list part number to filter orders by specific products. Will be ANDed together.'),
|
|
133
|
+
orderStatus: z.array(OrderStatusSchema).optional().describe('An optional list of order statuses to filter the search results.'),
|
|
134
|
+
user: IdentityIdentifierSchema.optional().describe('An optional user ID to filter orders by specific users. Mostly for b2b usecases with hierachial order access.'),
|
|
135
|
+
startDate: z.string().optional().describe('An optional start date to filter orders from a specific date onwards. ISO8601'),
|
|
136
|
+
endDate: z.string().optional().describe('An optional end date to filter orders up to a specific date. ISO8601'),
|
|
137
|
+
filters: z.array(z.string()).describe('Additional filters applied to the search results.'),
|
|
138
|
+
paginationOptions: PaginationOptionsSchema.describe('Pagination options for the search results.'),
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
export type OrderSearchIdentifier = InferType<typeof OrderSearchIdentifierSchema>;
|
|
142
|
+
export type ProductIdentifier = InferType<typeof ProductIdentifierSchema>;
|
|
143
|
+
export type ProductVariantIdentifier = InferType<typeof ProductVariantIdentifierSchema>;
|
|
144
|
+
export type SearchIdentifier = InferType<typeof ProductSearchIdentifierSchema>;
|
|
145
|
+
export type FacetIdentifier = InferType<typeof FacetIdentifierSchema>;
|
|
146
|
+
export type FacetValueIdentifier = InferType<typeof FacetValueIdentifierSchema>;
|
|
147
|
+
export type CartIdentifier = InferType<typeof CartIdentifierSchema>;
|
|
148
|
+
export type CartItemIdentifier = InferType<typeof CartItemIdentifierSchema>;
|
|
149
|
+
export type PriceIdentifier = InferType<typeof PriceIdentifierSchema>;
|
|
150
|
+
export type CategoryIdentifier = InferType<typeof CategoryIdentifierSchema>;
|
|
151
|
+
export type WebStoreIdentifier = InferType<typeof WebStoreIdentifierSchema>;
|
|
152
|
+
export type InventoryIdentifier = InferType<typeof InventoryIdentifierSchema>;
|
|
153
|
+
export type FulfillmentCenterIdentifier = InferType<
|
|
119
154
|
typeof FulfillmentCenterIdentifierSchema
|
|
120
155
|
>;
|
|
121
|
-
export type IdentityIdentifier =
|
|
122
|
-
export type ShippingMethodIdentifier =
|
|
156
|
+
export type IdentityIdentifier = InferType<typeof IdentityIdentifierSchema>;
|
|
157
|
+
export type ShippingMethodIdentifier = InferType<
|
|
123
158
|
typeof ShippingMethodIdentifierSchema
|
|
124
159
|
>;
|
|
125
|
-
export type PaymentMethodIdentifier =
|
|
160
|
+
export type PaymentMethodIdentifier = InferType<
|
|
126
161
|
typeof PaymentMethodIdentifierSchema
|
|
127
162
|
>;
|
|
128
|
-
export type AddressIdentifier =
|
|
129
|
-
export type PaymentInstructionIdentifier =
|
|
163
|
+
export type AddressIdentifier = InferType<typeof AddressIdentifierSchema>;
|
|
164
|
+
export type PaymentInstructionIdentifier = InferType<
|
|
130
165
|
typeof PaymentInstructionIdentifierSchema
|
|
131
166
|
>;
|
|
132
|
-
export type OrderIdentifier =
|
|
133
|
-
export type OrderItemIdentifier =
|
|
134
|
-
|
|
135
|
-
export type CheckoutIdentifier =
|
|
136
|
-
export type CheckoutItemIdentifier =
|
|
137
|
-
export type PickupPointIdentifier =
|
|
138
|
-
export type StoreIdentifier =
|
|
167
|
+
export type OrderIdentifier = InferType<typeof OrderIdentifierSchema>;
|
|
168
|
+
export type OrderItemIdentifier = InferType<typeof OrderItemIdentifierSchema>;
|
|
169
|
+
|
|
170
|
+
export type CheckoutIdentifier = InferType<typeof CheckoutIdentifierSchema>;
|
|
171
|
+
export type CheckoutItemIdentifier = InferType<typeof CheckoutItemIdentifierSchema>;
|
|
172
|
+
export type PickupPointIdentifier = InferType<typeof PickupPointIdentifierSchema>;
|
|
173
|
+
export type StoreIdentifier = InferType<typeof StoreIdentifierSchema>;
|
|
174
|
+
export type ProductOptionIdentifier = InferType<typeof ProductOptionIdentifierSchema>;
|
|
175
|
+
export type ProductOptionValueIdentifier = InferType<typeof ProductOptionValueIdentifierSchema>;
|
|
176
|
+
export type ProductAttributeIdentifier = InferType<typeof ProductAttributeIdentifierSchema>;
|
|
177
|
+
export type ProductAttributeValueIdentifier = InferType<typeof ProductAttributeValueIdentifierSchema>;
|
|
139
178
|
|
|
140
179
|
export type IdentifierType =
|
|
141
180
|
| ProductIdentifier
|
|
181
|
+
| ProductVariantIdentifier
|
|
142
182
|
| SearchIdentifier
|
|
143
183
|
| FacetIdentifier
|
|
144
184
|
| FacetValueIdentifier
|
|
@@ -159,4 +199,8 @@ export type IdentifierType =
|
|
|
159
199
|
| CheckoutIdentifier
|
|
160
200
|
| CheckoutItemIdentifier
|
|
161
201
|
| StoreIdentifier
|
|
162
|
-
|
|
|
202
|
+
| ProductOptionIdentifier
|
|
203
|
+
| ProductOptionValueIdentifier
|
|
204
|
+
| PickupPointIdentifier
|
|
205
|
+
| ProductAttributeIdentifier
|
|
206
|
+
| ProductAttributeValueIdentifier;
|
|
@@ -1,34 +1,25 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { BaseModelSchema } from './base.model.js';
|
|
3
3
|
import { IdentityIdentifierSchema } from './identifiers.model.js';
|
|
4
|
+
import type { InferType } from '../../zod-utils.js';
|
|
4
5
|
|
|
5
6
|
export const AnonymousIdentitySchema = BaseModelSchema.extend({
|
|
6
|
-
type: z.literal('Anonymous')
|
|
7
|
-
token: z.string().optional(),
|
|
8
|
-
refresh_token: z.string().optional(),
|
|
9
|
-
expiry: z.coerce.date().default(new Date())
|
|
7
|
+
type: z.literal('Anonymous'),
|
|
10
8
|
});
|
|
11
9
|
|
|
12
10
|
export const GuestIdentitySchema = BaseModelSchema.extend({
|
|
13
|
-
id: IdentityIdentifierSchema
|
|
14
|
-
type: z.literal('Guest')
|
|
15
|
-
token: z.string().optional(),
|
|
16
|
-
refresh_token: z.string().optional(),
|
|
17
|
-
expiry: z.coerce.date().default(new Date())
|
|
11
|
+
id: IdentityIdentifierSchema,
|
|
12
|
+
type: z.literal('Guest')
|
|
18
13
|
});
|
|
19
14
|
|
|
20
15
|
export const RegisteredIdentitySchema = BaseModelSchema.extend({
|
|
21
|
-
id: IdentityIdentifierSchema
|
|
22
|
-
type: z.literal('Registered')
|
|
23
|
-
logonId: z.string().default(''),
|
|
24
|
-
token: z.string().optional(),
|
|
25
|
-
refresh_token: z.string().optional(),
|
|
26
|
-
expiry: z.coerce.date().default(new Date())
|
|
16
|
+
id: IdentityIdentifierSchema,
|
|
17
|
+
type: z.literal('Registered'),
|
|
27
18
|
});
|
|
28
19
|
|
|
29
20
|
export const IdentitySchema = z.discriminatedUnion('type', [ AnonymousIdentitySchema, GuestIdentitySchema, RegisteredIdentitySchema]);
|
|
30
21
|
|
|
31
|
-
export type AnonymousIdentity =
|
|
32
|
-
export type GuestIdentity =
|
|
33
|
-
export type RegisteredIdentity =
|
|
34
|
-
export type Identity =
|
|
22
|
+
export type AnonymousIdentity = InferType<typeof AnonymousIdentitySchema>;
|
|
23
|
+
export type GuestIdentity = InferType<typeof GuestIdentitySchema>;
|
|
24
|
+
export type RegisteredIdentity = InferType<typeof RegisteredIdentitySchema>;
|
|
25
|
+
export type Identity = InferType<typeof IdentitySchema>;
|
|
@@ -9,11 +9,12 @@ export * from './inventory.model.js';
|
|
|
9
9
|
export * from './payment.model.js';
|
|
10
10
|
export * from './price.model.js';
|
|
11
11
|
export * from './product.model.js';
|
|
12
|
+
export * from './product-search.model.js';
|
|
12
13
|
export * from './profile.model.js';
|
|
13
|
-
export * from './search.model.js';
|
|
14
14
|
export * from './shipping-method.model.js';
|
|
15
15
|
export * from './store.model.js';
|
|
16
16
|
export * from './order.model.js';
|
|
17
17
|
export * from './cost.model.js';
|
|
18
18
|
export * from './checkout.model.js';
|
|
19
19
|
export * from './payment.model.js';
|
|
20
|
+
export * from './order-search.model.js'
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { BaseModelSchema } from './base.model.js';
|
|
3
3
|
import { InventoryIdentifierSchema } from './identifiers.model.js';
|
|
4
|
+
import type { InferType } from '../../zod-utils.js';
|
|
5
|
+
|
|
6
|
+
export const InventoryStatusSchema = z.enum(['inStock', 'outOfStock', 'onBackOrder', 'preOrder', 'discontinued']);
|
|
4
7
|
|
|
5
8
|
export const InventorySchema = BaseModelSchema.extend({
|
|
6
|
-
identifier: InventoryIdentifierSchema
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
status: z.enum(['inStock', 'outOfStock', 'onBackOrder', 'preOrder', 'discontinued']).default('inStock'),
|
|
9
|
+
identifier: InventoryIdentifierSchema,
|
|
10
|
+
quantity: z.number(),
|
|
11
|
+
status: InventoryStatusSchema,
|
|
10
12
|
});
|
|
11
13
|
|
|
12
|
-
export type
|
|
14
|
+
export type InventoryStatus = InferType<typeof InventoryStatusSchema>;
|
|
15
|
+
export type Inventory = InferType<typeof InventorySchema>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
import { BaseModelSchema, createPaginatedResponseSchema } from "./base.model.js";
|
|
3
|
+
import { IdentityIdentifierSchema, OrderIdentifierSchema, OrderInventoryStatusSchema, OrderSearchIdentifierSchema, OrderStatusSchema } from "./identifiers.model.js";
|
|
4
|
+
import type { InferType } from "../../zod-utils.js";
|
|
5
|
+
import { MonetaryAmountSchema } from "./price.model.js";
|
|
6
|
+
import { AddressSchema } from "./profile.model.js";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export const OrderSearchResultItemSchema = BaseModelSchema.extend({
|
|
10
|
+
identifier: OrderIdentifierSchema,
|
|
11
|
+
userId: IdentityIdentifierSchema,
|
|
12
|
+
customerName: z.string(),
|
|
13
|
+
shippingAddress: AddressSchema.optional(),
|
|
14
|
+
orderDate: z.string(),
|
|
15
|
+
orderStatus: OrderStatusSchema,
|
|
16
|
+
inventoryStatus: OrderInventoryStatusSchema,
|
|
17
|
+
totalAmount: MonetaryAmountSchema
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
export const OrderSearchResultSchema = createPaginatedResponseSchema(OrderSearchResultItemSchema).extend({
|
|
23
|
+
identifier: OrderSearchIdentifierSchema,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
export type OrderSearchResult = InferType<typeof OrderSearchResultSchema>;
|
|
28
|
+
export type OrderSearchResultItem = InferType<typeof OrderSearchResultItemSchema>;
|
|
@@ -1,46 +1,40 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { CartIdentifierSchema, CartItemIdentifierSchema, IdentityIdentifierSchema,
|
|
2
|
+
import { CartIdentifierSchema, CartItemIdentifierSchema, IdentityIdentifierSchema, OrderIdentifierSchema, OrderInventoryStatusSchema, OrderItemIdentifierSchema, OrderStatusSchema, ProductVariantIdentifierSchema } from '../models/identifiers.model.js';
|
|
3
3
|
import { BaseModelSchema } from './base.model.js';
|
|
4
4
|
import { AddressSchema } from './profile.model.js';
|
|
5
5
|
import { ShippingMethodSchema } from './shipping-method.model.js';
|
|
6
6
|
import { CostBreakDownSchema, ItemCostBreakdownSchema } from './cost.model.js';
|
|
7
7
|
import { PaymentInstructionSchema } from './payment.model.js';
|
|
8
|
+
import type { InferType } from '../../zod-utils.js';
|
|
8
9
|
|
|
9
|
-
export const OrderStatusSchema = z.enum(['AwaitingPayment', 'ReleasedToFulfillment', 'Shipped', 'Cancelled']).default('AwaitingPayment').describe('The current status of the order.');
|
|
10
|
-
export const OrderInventoryStatusSchema = z.enum(['NotAllocated', 'Allocated', 'Backordered', 'Preordered']).default('Allocated').describe('The inventory release status of the order.');
|
|
11
10
|
|
|
12
11
|
|
|
13
12
|
export const OrderItemSchema = z.looseObject({
|
|
14
|
-
identifier:
|
|
15
|
-
|
|
16
|
-
quantity: z.number()
|
|
17
|
-
price: ItemCostBreakdownSchema
|
|
18
|
-
|
|
19
|
-
inventoryStatus: OrderInventoryStatusSchema.default('Allocated').describe('The inventory release status of the order item.'),
|
|
13
|
+
identifier: OrderItemIdentifierSchema,
|
|
14
|
+
variant: ProductVariantIdentifierSchema,
|
|
15
|
+
quantity: z.number(),
|
|
16
|
+
price: ItemCostBreakdownSchema,
|
|
17
|
+
inventoryStatus: OrderInventoryStatusSchema.describe('The inventory release status of the order item.'),
|
|
20
18
|
});
|
|
21
19
|
|
|
22
20
|
export const OrderSchema = BaseModelSchema.extend({
|
|
23
|
-
identifier:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
name: z.string().default(''),
|
|
30
|
-
description: z.string().default(''),
|
|
31
|
-
|
|
21
|
+
identifier: OrderIdentifierSchema,
|
|
22
|
+
userId: IdentityIdentifierSchema,
|
|
23
|
+
items: z.array(OrderItemSchema),
|
|
24
|
+
price: CostBreakDownSchema,
|
|
25
|
+
name: z.string().optional(),
|
|
26
|
+
description: z.string().optional(),
|
|
32
27
|
shippingAddress: AddressSchema.optional(),
|
|
33
28
|
billingAddress: AddressSchema.optional(),
|
|
34
29
|
shippingMethod: ShippingMethodSchema.optional(),
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
paymentInstructions: z.array(PaymentInstructionSchema).default(() => []),
|
|
30
|
+
orderStatus: OrderStatusSchema,
|
|
31
|
+
inventoryStatus: OrderInventoryStatusSchema,
|
|
32
|
+
paymentInstructions: z.array(PaymentInstructionSchema),
|
|
40
33
|
cartReference: CartIdentifierSchema.optional().describe('Reference to the cart from which this order was created.'),
|
|
41
34
|
});
|
|
42
35
|
|
|
43
36
|
|
|
44
|
-
|
|
45
|
-
export type
|
|
46
|
-
export type
|
|
37
|
+
export type OrderStatus = InferType<typeof OrderStatusSchema>;
|
|
38
|
+
export type OrderInventoryStatus = InferType<typeof OrderInventoryStatusSchema>;
|
|
39
|
+
export type OrderItem = InferType<typeof OrderItemSchema>;
|
|
40
|
+
export type Order = InferType<typeof OrderSchema>;
|
|
@@ -2,33 +2,30 @@ import { z } from 'zod';
|
|
|
2
2
|
import { BaseModelSchema, ImageSchema } from './base.model.js';
|
|
3
3
|
import { PaymentInstructionIdentifierSchema, PaymentMethodIdentifierSchema } from './identifiers.model.js';
|
|
4
4
|
import { MonetaryAmountSchema } from './price.model.js';
|
|
5
|
+
import type { InferType } from '../../zod-utils.js';
|
|
5
6
|
|
|
6
7
|
export const PaymentStatusSchema = z.enum(['pending', 'authorized', 'canceled', 'capture', 'partial_capture', 'refunded', 'partial_refund']);
|
|
7
8
|
|
|
8
9
|
export const PaymentProtocolDataSchema = z.looseObject({
|
|
9
|
-
key: z.string()
|
|
10
|
-
value: z.string()
|
|
10
|
+
key: z.string(),
|
|
11
|
+
value: z.string(),
|
|
11
12
|
});
|
|
12
13
|
|
|
13
|
-
|
|
14
14
|
export const PaymentMethodSchema = BaseModelSchema.extend({
|
|
15
|
-
identifier: PaymentMethodIdentifierSchema
|
|
15
|
+
identifier: PaymentMethodIdentifierSchema,
|
|
16
16
|
logo: ImageSchema.optional(),
|
|
17
|
-
description: z.string()
|
|
18
|
-
isPunchOut: z.boolean()
|
|
17
|
+
description: z.string(),
|
|
18
|
+
isPunchOut: z.boolean()
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
export const PaymentInstructionSchema = BaseModelSchema.extend({
|
|
22
|
-
identifier: PaymentInstructionIdentifierSchema
|
|
23
|
-
amount: MonetaryAmountSchema
|
|
24
|
-
paymentMethod: PaymentMethodIdentifierSchema
|
|
25
|
-
protocolData: z.array(PaymentProtocolDataSchema).
|
|
26
|
-
status: PaymentStatusSchema
|
|
22
|
+
identifier: PaymentInstructionIdentifierSchema,
|
|
23
|
+
amount: MonetaryAmountSchema,
|
|
24
|
+
paymentMethod: PaymentMethodIdentifierSchema,
|
|
25
|
+
protocolData: z.array(PaymentProtocolDataSchema).describe('Additional protocol-specific data for processing the payment.'),
|
|
26
|
+
status: PaymentStatusSchema,
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
export type PaymentInstruction = z.infer<typeof PaymentInstructionSchema>;
|
|
33
|
-
export type PaymentStatus = z.infer<typeof PaymentStatusSchema>;
|
|
34
|
-
export type PaymentMethod = z.infer<typeof PaymentMethodSchema>;
|
|
29
|
+
export type PaymentInstruction = InferType<typeof PaymentInstructionSchema>;
|
|
30
|
+
export type PaymentStatus = InferType<typeof PaymentStatusSchema>;
|
|
31
|
+
export type PaymentMethod = InferType<typeof PaymentMethodSchema>;
|
|
@@ -2,24 +2,24 @@ import { z } from 'zod';
|
|
|
2
2
|
import { BaseModelSchema } from './base.model.js';
|
|
3
3
|
import { PriceIdentifierSchema } from './identifiers.model.js';
|
|
4
4
|
import { CurrencySchema } from './currency.model.js';
|
|
5
|
+
import type { InferType } from '../../zod-utils.js';
|
|
5
6
|
|
|
6
7
|
export const MonetaryAmountSchema = z.looseObject({
|
|
7
|
-
value: z.number().
|
|
8
|
-
currency: CurrencySchema.
|
|
8
|
+
value: z.number().describe('The monetary amount in decimal-precision.'),
|
|
9
|
+
currency: CurrencySchema.describe('The currency associated with the amount, as a ISO 4217 standardized code.')
|
|
9
10
|
});
|
|
10
11
|
|
|
11
12
|
export const TieredPriceSchema = z.looseObject({
|
|
12
|
-
minimumQuantity: z.number().
|
|
13
|
-
price: MonetaryAmountSchema.
|
|
13
|
+
minimumQuantity: z.number().describe('The minimum quantity required to be eligible for the tiered price.'),
|
|
14
|
+
price: MonetaryAmountSchema.describe('The monetary amount for the tiered price.'),
|
|
14
15
|
});
|
|
15
16
|
|
|
16
|
-
|
|
17
17
|
export const PriceSchema = BaseModelSchema.extend({
|
|
18
|
-
identifier: PriceIdentifierSchema
|
|
19
|
-
unitPrice: MonetaryAmountSchema
|
|
20
|
-
tieredPrices: z.array(TieredPriceSchema)
|
|
18
|
+
identifier: PriceIdentifierSchema,
|
|
19
|
+
unitPrice: MonetaryAmountSchema,
|
|
20
|
+
tieredPrices: z.array(TieredPriceSchema)
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
export type MonetaryAmount =
|
|
24
|
-
export type Price =
|
|
25
|
-
export type TieredPrice =
|
|
23
|
+
export type MonetaryAmount = InferType<typeof MonetaryAmountSchema>;
|
|
24
|
+
export type Price = InferType<typeof PriceSchema>;
|
|
25
|
+
export type TieredPrice = InferType<typeof TieredPriceSchema>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ProductIdentifierSchema, FacetValueIdentifierSchema, FacetIdentifierSchema, ProductSearchIdentifierSchema, ProductVariantIdentifierSchema } from './identifiers.model.js';
|
|
3
|
+
import { BaseModelSchema, createPaginatedResponseSchema, ImageSchema } from './base.model.js';
|
|
4
|
+
import { ProductVariantOptionSchema } from './product.model.js';
|
|
5
|
+
import type { InferType } from '../../zod-utils.js';
|
|
6
|
+
|
|
7
|
+
export const ProductSearchResultItemVariantSchema = z.looseObject({
|
|
8
|
+
variant: ProductVariantIdentifierSchema.describe('The specific variant of the product'),
|
|
9
|
+
image: ImageSchema.describe('The image representing this variant in the search results'),
|
|
10
|
+
options: ProductVariantOptionSchema.optional().describe('The subset of options that can reasonably be applied on a PLP'),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export const ProductSearchResultItemSchema = BaseModelSchema.extend({
|
|
14
|
+
identifier: ProductIdentifierSchema,
|
|
15
|
+
name: z.string(),
|
|
16
|
+
slug: z.string(),
|
|
17
|
+
variants: z.array(ProductSearchResultItemVariantSchema).describe('A list of variants associated with the product in the search results. If exactly one is present, you can use add-to-cart directly from PLP. If none are present, you must direct to PDP. If mulitple are present, and no options are set, you must direct to PDP. If multiple are present, and they have options, you can render swatches on PLP and allow customer to flip between variants.'),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export const ProductSearchResultFacetValueSchema = z.looseObject({
|
|
21
|
+
identifier: FacetValueIdentifierSchema,
|
|
22
|
+
name: z.string(),
|
|
23
|
+
count: z.number(),
|
|
24
|
+
active: z.boolean(),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export const ProductSearchResultFacetSchema = z.looseObject({
|
|
28
|
+
identifier: FacetIdentifierSchema,
|
|
29
|
+
name: z.string(),
|
|
30
|
+
values: z.array(ProductSearchResultFacetValueSchema),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export const ProductSearchResultSchema = createPaginatedResponseSchema(ProductSearchResultItemSchema).extend({
|
|
34
|
+
identifier: ProductSearchIdentifierSchema,
|
|
35
|
+
facets: z.array(ProductSearchResultFacetSchema),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export type ProductSearchResultItemVariant = InferType<typeof ProductSearchResultItemVariantSchema>;
|
|
39
|
+
export type ProductSearchResultItem = InferType<typeof ProductSearchResultItemSchema>;
|
|
40
|
+
export type ProductSearchResult = InferType<typeof ProductSearchResultSchema>;
|
|
41
|
+
export type ProductSearchResultFacet = InferType<typeof ProductSearchResultFacetSchema>;
|
|
42
|
+
export type ProductSearchResultFacetValue = InferType<typeof ProductSearchResultFacetValueSchema>;
|