@reactionary/core 0.0.41 → 0.0.48

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.
Files changed (85) hide show
  1. package/cache/memory-cache.js +39 -0
  2. package/cache/noop-cache.js +3 -13
  3. package/cache/redis-cache.js +16 -32
  4. package/decorators/reactionary.decorator.js +57 -4
  5. package/index.js +5 -27
  6. package/initialization.js +43 -0
  7. package/package.json +4 -2
  8. package/providers/base.provider.js +29 -12
  9. package/providers/cart-payment.provider.js +9 -0
  10. package/providers/cart.provider.js +6 -0
  11. package/providers/index.js +12 -0
  12. package/providers/price.provider.js +1 -1
  13. package/providers/product.provider.js +10 -0
  14. package/providers/profile.provider.js +9 -0
  15. package/providers/store.provider.js +9 -0
  16. package/schemas/capabilities.schema.js +3 -1
  17. package/schemas/models/cart.model.js +9 -2
  18. package/schemas/models/identifiers.model.js +40 -4
  19. package/schemas/models/identity.model.js +20 -6
  20. package/schemas/models/index.js +15 -0
  21. package/schemas/models/payment.model.js +37 -0
  22. package/schemas/models/profile.model.js +30 -0
  23. package/schemas/models/shipping-method.model.js +15 -0
  24. package/schemas/models/store.model.js +11 -0
  25. package/schemas/mutations/cart-payment.mutation.js +15 -0
  26. package/schemas/mutations/cart.mutation.js +52 -3
  27. package/schemas/mutations/identity.mutation.js +6 -1
  28. package/schemas/mutations/index.js +10 -0
  29. package/schemas/mutations/profile.mutation.js +9 -0
  30. package/schemas/queries/cart-payment.query.js +11 -0
  31. package/schemas/queries/index.js +3 -0
  32. package/schemas/queries/inventory.query.js +3 -5
  33. package/schemas/queries/profile.query.js +5 -0
  34. package/schemas/queries/store.query.js +11 -0
  35. package/schemas/session.schema.js +22 -8
  36. package/src/cache/cache.interface.d.ts +13 -20
  37. package/src/cache/memory-cache.d.ts +18 -0
  38. package/src/cache/noop-cache.d.ts +5 -11
  39. package/src/cache/redis-cache.d.ts +5 -11
  40. package/src/client/client-builder.d.ts +2 -2
  41. package/src/client/client.d.ts +11 -9
  42. package/src/decorators/reactionary.decorator.d.ts +34 -1
  43. package/src/index.d.ts +5 -27
  44. package/src/initialization.d.ts +2 -0
  45. package/src/providers/analytics.provider.d.ts +1 -1
  46. package/src/providers/base.provider.d.ts +12 -9
  47. package/src/providers/cart-payment.provider.d.ts +42 -0
  48. package/src/providers/cart.provider.d.ts +107 -8
  49. package/src/providers/category.provider.d.ts +9 -9
  50. package/src/providers/identity.provider.d.ts +8 -7
  51. package/src/providers/index.d.ts +12 -0
  52. package/src/providers/inventory.provider.d.ts +4 -4
  53. package/src/providers/price.provider.d.ts +7 -7
  54. package/src/providers/product.provider.d.ts +10 -5
  55. package/src/providers/profile.provider.d.ts +10 -0
  56. package/src/providers/search.provider.d.ts +4 -4
  57. package/src/providers/store.provider.d.ts +8 -0
  58. package/src/schemas/capabilities.schema.d.ts +2 -0
  59. package/src/schemas/models/analytics.model.d.ts +1 -1
  60. package/src/schemas/models/cart.model.d.ts +251 -2
  61. package/src/schemas/models/identifiers.model.d.ts +38 -4
  62. package/src/schemas/models/identity.model.d.ts +77 -14
  63. package/src/schemas/models/index.d.ts +15 -0
  64. package/src/schemas/models/inventory.model.d.ts +1 -1
  65. package/src/schemas/models/payment.model.d.ts +692 -0
  66. package/src/schemas/models/profile.model.d.ts +101 -0
  67. package/src/schemas/models/shipping-method.model.d.ts +201 -0
  68. package/src/schemas/models/store.model.d.ts +18 -0
  69. package/src/schemas/mutations/cart-payment.mutation.d.ts +213 -0
  70. package/src/schemas/mutations/cart.mutation.d.ts +477 -2
  71. package/src/schemas/mutations/identity.mutation.d.ts +5 -0
  72. package/src/schemas/mutations/index.d.ts +10 -0
  73. package/src/schemas/mutations/profile.mutation.d.ts +6 -0
  74. package/src/schemas/queries/cart-payment.query.d.ts +16 -0
  75. package/src/schemas/queries/cart.query.d.ts +1 -1
  76. package/src/schemas/queries/identity.query.d.ts +1 -1
  77. package/src/schemas/queries/index.d.ts +3 -0
  78. package/src/schemas/queries/inventory.query.d.ts +6 -15
  79. package/src/schemas/queries/price.query.d.ts +1 -1
  80. package/src/schemas/queries/profile.query.d.ts +3 -0
  81. package/src/schemas/queries/search.query.d.ts +1 -1
  82. package/src/schemas/queries/store.query.d.ts +8 -0
  83. package/src/schemas/session.schema.d.ts +57 -13
  84. package/cache/cache-evaluation.interface.js +0 -0
  85. package/src/cache/cache-evaluation.interface.d.ts +0 -17
@@ -0,0 +1,39 @@
1
+ class MemoryCache {
2
+ constructor() {
3
+ this.entries = new Array();
4
+ }
5
+ async get(key, schema) {
6
+ const c = this.entries.find((x) => x.key === key);
7
+ if (!c) {
8
+ return null;
9
+ }
10
+ const parsed = schema.parse(c.value);
11
+ parsed.meta.cache.hit = true;
12
+ return parsed;
13
+ }
14
+ async put(key, value, options) {
15
+ this.entries.push({
16
+ key,
17
+ value,
18
+ options
19
+ });
20
+ return;
21
+ }
22
+ async invalidate(dependencyIds) {
23
+ let index = 0;
24
+ for (const entry of this.entries) {
25
+ for (const entryDependency of entry.options.dependencyIds) {
26
+ if (dependencyIds.indexOf(entryDependency) > -1) {
27
+ this.entries.splice(index, 1);
28
+ }
29
+ }
30
+ index++;
31
+ }
32
+ }
33
+ async clear() {
34
+ this.entries = [];
35
+ }
36
+ }
37
+ export {
38
+ MemoryCache
39
+ };
@@ -2,25 +2,15 @@ class NoOpCache {
2
2
  async get(_key, _schema) {
3
3
  return null;
4
4
  }
5
- async put(_key, _value, _ttlSeconds) {
5
+ async put(_key, _value, options) {
6
6
  return;
7
7
  }
8
- async del(_keys) {
8
+ async invalidate(dependencyIds) {
9
9
  return;
10
10
  }
11
- async keys(_pattern) {
12
- return [];
13
- }
14
- async clear(_pattern) {
11
+ async clear() {
15
12
  return;
16
13
  }
17
- async getStats() {
18
- return {
19
- hits: 0,
20
- misses: 0,
21
- size: 0
22
- };
23
- }
24
14
  }
25
15
  export {
26
16
  NoOpCache
@@ -14,45 +14,29 @@ class RedisCache {
14
14
  }
15
15
  return null;
16
16
  }
17
- async put(key, value, ttlSeconds) {
17
+ async put(key, value, options) {
18
18
  if (!key) {
19
19
  return;
20
20
  }
21
- const options = ttlSeconds ? { ex: ttlSeconds } : void 0;
22
- await this.redis.set(key, value, options);
23
- }
24
- async del(keys) {
25
- const keyArray = Array.isArray(keys) ? keys : [keys];
26
- for (const key of keyArray) {
27
- if (key.includes("*")) {
28
- const matchingKeys = await this.redis.keys(key);
29
- if (matchingKeys.length > 0) {
30
- await this.redis.del(...matchingKeys);
31
- }
32
- } else {
33
- await this.redis.del(key);
34
- }
21
+ const serialized = JSON.stringify(value);
22
+ const multi = this.redis.multi();
23
+ multi.set(key, serialized, { ex: options.ttlSeconds });
24
+ for (const depId of options.dependencyIds) {
25
+ multi.sadd(`dep:${depId}`, key);
35
26
  }
27
+ await multi.exec();
36
28
  }
37
- async keys(pattern) {
38
- return await this.redis.keys(pattern);
39
- }
40
- async clear(pattern) {
41
- const searchPattern = pattern || "*";
42
- const keys = await this.redis.keys(searchPattern);
43
- if (keys.length > 0) {
44
- await this.redis.del(...keys);
29
+ async invalidate(dependencyIds) {
30
+ for (const id of dependencyIds) {
31
+ const depKey = `dep:${id}`;
32
+ const keys = await this.redis.smembers(depKey);
33
+ if (keys.length > 0) {
34
+ await this.redis.del(...keys);
35
+ }
36
+ await this.redis.del(depKey);
45
37
  }
46
38
  }
47
- async getStats() {
48
- const keys = await this.redis.keys("*");
49
- return {
50
- hits: 0,
51
- // Would need to track this separately
52
- misses: 0,
53
- // Would need to track this separately
54
- size: keys.length
55
- };
39
+ async clear() {
56
40
  }
57
41
  }
58
42
  export {
@@ -1,13 +1,66 @@
1
+ import { getTracer, SpanKind } from "@reactionary/otel";
2
+ class ReactionaryDecoratorOptions {
3
+ constructor() {
4
+ /**
5
+ * Whether or not the query is eligible for caching. Queries that depend
6
+ * heavily on personalization, for example, are likely to be a poor fit
7
+ * for caching.
8
+ */
9
+ this.cache = false;
10
+ /**
11
+ * Whether or not the cache entry should be variable based on the locale
12
+ * of the context in which it is querried.
13
+ */
14
+ this.localeDependentCaching = false;
15
+ /**
16
+ * Whether or not the cache entry should be variable based on the currency
17
+ * of the context in which it is querried.
18
+ */
19
+ this.currencyDependentCaching = false;
20
+ /**
21
+ * The number of seconds which a cache entry should be considered valid for the
22
+ * given query.
23
+ */
24
+ this.cacheTimeToLiveInSeconds = 60;
25
+ }
26
+ }
27
+ ;
1
28
  function Reactionary(options) {
2
29
  return function(target, propertyKey, descriptor) {
3
30
  const original = descriptor.value;
4
- descriptor.value = function(...args) {
5
- console.log("calling through reactionary decoration!");
6
- return original.apply(this, args);
31
+ const scope = `${target.constructor.name}.${propertyKey.toString()}`;
32
+ const configuration = { ...new ReactionaryDecoratorOptions(), ...options };
33
+ if (!original) {
34
+ throw new Error(
35
+ "@Reactionary decorator may only be applied to methods on classes extending BaseProvider."
36
+ );
37
+ }
38
+ descriptor.value = async function(...args) {
39
+ const tracer = getTracer();
40
+ return tracer.startActiveSpan(
41
+ propertyKey.toString(),
42
+ { kind: SpanKind.SERVER },
43
+ async (span) => {
44
+ const cacheKey = this.generateCacheKeyForQuery(scope, args[0]);
45
+ const fromCache = await this.cache.get(cacheKey, this.schema);
46
+ let result = fromCache;
47
+ if (!result) {
48
+ result = await original.apply(this, args);
49
+ const dependencyIds = this.generateDependencyIdsForModel(result);
50
+ this.cache.put(cacheKey, result, {
51
+ ttlSeconds: configuration.cacheTimeToLiveInSeconds,
52
+ dependencyIds
53
+ });
54
+ }
55
+ span.end();
56
+ return this.assert(result);
57
+ }
58
+ );
7
59
  };
8
60
  return descriptor;
9
61
  };
10
62
  }
11
63
  export {
12
- Reactionary
64
+ Reactionary,
65
+ ReactionaryDecoratorOptions
13
66
  };
package/index.js CHANGED
@@ -1,36 +1,14 @@
1
1
  export * from "./cache/cache.interface";
2
- export * from "./cache/cache-evaluation.interface";
3
2
  export * from "./cache/redis-cache";
3
+ export * from "./cache/memory-cache";
4
4
  export * from "./cache/noop-cache";
5
5
  export * from "./client/client";
6
6
  export * from "./client/client-builder";
7
7
  export * from "./decorators/reactionary.decorator";
8
- export * from "./providers/analytics.provider";
9
- export * from "./providers/base.provider";
10
- export * from "./providers/cart.provider";
11
- export * from "./providers/identity.provider";
12
- export * from "./providers/inventory.provider";
13
- export * from "./providers/price.provider";
14
- export * from "./providers/product.provider";
15
- export * from "./providers/search.provider";
16
- export * from "./providers/category.provider";
8
+ export * from "./providers/";
17
9
  export * from "./schemas/capabilities.schema";
18
10
  export * from "./schemas/session.schema";
19
- export * from "./schemas/models/base.model";
20
- export * from "./schemas/models/cart.model";
21
- export * from "./schemas/models/currency.model";
22
- export * from "./schemas/models/identifiers.model";
23
- export * from "./schemas/models/identity.model";
24
- export * from "./schemas/models/inventory.model";
25
- export * from "./schemas/models/price.model";
26
- export * from "./schemas/models/product.model";
27
- export * from "./schemas/models/search.model";
28
- export * from "./schemas/models/category.model";
29
- export * from "./schemas/mutations/base.mutation";
30
- export * from "./schemas/mutations/cart.mutation";
31
- export * from "./schemas/mutations/identity.mutation";
32
- export * from "./schemas/mutations/inventory.mutation";
33
- export * from "./schemas/mutations/price.mutation";
34
- export * from "./schemas/mutations/product.mutation";
35
- export * from "./schemas/mutations/search.mutation";
11
+ export * from "./schemas/models/";
12
+ export * from "./schemas/mutations/";
36
13
  export * from "./schemas/queries";
14
+ export * from "./initialization";
@@ -0,0 +1,43 @@
1
+ function createInitialRequestContext() {
2
+ return {
3
+ id: "",
4
+ identity: {
5
+ type: "Anonymous",
6
+ meta: {
7
+ cache: { hit: false, key: "" },
8
+ placeholder: false
9
+ },
10
+ id: { userId: "anonymous" },
11
+ token: void 0,
12
+ issued: /* @__PURE__ */ new Date(),
13
+ expiry: new Date((/* @__PURE__ */ new Date()).getTime() + 3600 * 1e3),
14
+ logonId: "",
15
+ createdAt: "",
16
+ updatedAt: "",
17
+ keyring: [],
18
+ currentService: void 0
19
+ },
20
+ languageContext: {
21
+ locale: "en-US",
22
+ currencyCode: "USD"
23
+ },
24
+ storeIdentifier: {
25
+ key: "the-good-store"
26
+ },
27
+ taxJurisdiction: {
28
+ countryCode: "US",
29
+ stateCode: "",
30
+ countyCode: "",
31
+ cityCode: ""
32
+ },
33
+ session: {},
34
+ correlationId: "",
35
+ isBot: false,
36
+ clientIp: "",
37
+ userAgent: "",
38
+ referrer: ""
39
+ };
40
+ }
41
+ export {
42
+ createInitialRequestContext
43
+ };
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "@reactionary/core",
3
- "version": "0.0.41",
3
+ "version": "0.0.48",
4
4
  "main": "index.js",
5
5
  "types": "src/index.d.ts",
6
6
  "dependencies": {
7
7
  "zod": "4.1.9",
8
- "@upstash/redis": "^1.34.9"
8
+ "@upstash/redis": "^1.34.9",
9
+ "@reactionary/otel": "0.0.48",
10
+ "node-object-hash": "^3.1.1"
9
11
  }
10
12
  }
@@ -1,4 +1,7 @@
1
- import { createPaginatedResponseSchema } from "../schemas/models/base.model";
1
+ import {
2
+ createPaginatedResponseSchema
3
+ } from "../schemas/models/base.model";
4
+ import { hasher } from "node-object-hash";
2
5
  class BaseProvider {
3
6
  constructor(schema, cache) {
4
7
  this.schema = schema;
@@ -21,26 +24,40 @@ class BaseProvider {
21
24
  * Handler for parsing a response from a remote provider and converting it
22
25
  * into the typed domain model.
23
26
  */
24
- parseSingle(_body, session) {
27
+ parseSingle(_body, reqCtx) {
25
28
  const model = this.newModel();
26
29
  return this.assert(model);
27
30
  }
28
- parsePaginatedResult(_body, session) {
31
+ parsePaginatedResult(_body, reqCtx) {
29
32
  return createPaginatedResponseSchema(this.schema).parse({});
30
33
  }
31
- generateCacheKeyPaginatedResult(resultSetName, res, session) {
34
+ generateDependencyIdsForModel(model) {
35
+ const identifier = model?.identifier;
36
+ if (!identifier) {
37
+ return [];
38
+ }
39
+ const h = hasher({ sort: true, coerce: false });
40
+ const hash = h.hash(identifier);
41
+ return [hash];
42
+ }
43
+ generateCacheKeyForQuery(scope, query) {
44
+ const h = hasher({ sort: true, coerce: false });
45
+ const queryHash = h.hash(query);
46
+ return `${scope}:${queryHash}`;
47
+ }
48
+ generateCacheKeyPaginatedResult(resultSetName, res, reqCtx) {
32
49
  const type = this.getResourceName();
33
- const langPart = session.languageContext.locale;
34
- const currencyPart = session.languageContext.currencyCode || "default";
35
- const storePart = session.storeIdentifier?.key || "default";
50
+ const langPart = reqCtx.languageContext.locale;
51
+ const currencyPart = reqCtx.languageContext.currencyCode || "default";
52
+ const storePart = reqCtx.storeIdentifier?.key || "default";
36
53
  return `${type}-${resultSetName}-paginated|pageNumber:${res.pageNumber}|pageSize:${res.pageSize}|store:${storePart}|lang:${langPart}|currency:${currencyPart}`;
37
54
  }
38
- generateCacheKeySingle(identifier, session) {
55
+ generateCacheKeySingle(identifier, reqCtx) {
39
56
  const type = this.getResourceName();
40
- const idPart = Object.entries(identifier).map(([k, v]) => `${k}:${v.key}`).join("#");
41
- const langPart = session.languageContext.locale;
42
- const currencyPart = session.languageContext.currencyCode || "default";
43
- const storePart = session.storeIdentifier?.key || "default";
57
+ const idPart = Object.entries(identifier).map(([k, v]) => `${k}:${v}`).join("#");
58
+ const langPart = reqCtx.languageContext.locale;
59
+ const currencyPart = reqCtx.languageContext.currencyCode || "default";
60
+ const storePart = reqCtx.storeIdentifier?.key || "default";
44
61
  return `${type}-${idPart}|store:${storePart}|lang:${langPart}|currency:${currencyPart}`;
45
62
  }
46
63
  }
@@ -0,0 +1,9 @@
1
+ import { BaseProvider } from "./base.provider";
2
+ class CartPaymentProvider extends BaseProvider {
3
+ getResourceName() {
4
+ return "cart-payment-instruction";
5
+ }
6
+ }
7
+ export {
8
+ CartPaymentProvider
9
+ };
@@ -1,5 +1,11 @@
1
1
  import { BaseProvider } from "./base.provider";
2
2
  class CartProvider extends BaseProvider {
3
+ createEmptyCart() {
4
+ const cart = this.newModel();
5
+ cart.meta = { placeholder: true, cache: { hit: true, key: "empty-cart" } };
6
+ cart.identifier = { key: "" };
7
+ return cart;
8
+ }
3
9
  getResourceName() {
4
10
  return "cart";
5
11
  }
@@ -0,0 +1,12 @@
1
+ export * from "./analytics.provider";
2
+ export * from "./base.provider";
3
+ export * from "./cart-payment.provider";
4
+ export * from "./cart.provider";
5
+ export * from "./category.provider";
6
+ export * from "./identity.provider";
7
+ export * from "./inventory.provider";
8
+ export * from "./price.provider";
9
+ export * from "./product.provider";
10
+ export * from "./profile.provider";
11
+ export * from "./search.provider";
12
+ export * from "./store.provider";
@@ -8,7 +8,7 @@ class PriceProvider extends BaseProvider {
8
8
  * @param currency
9
9
  * @returns
10
10
  */
11
- getEmptyPriceResult(sku, currency) {
11
+ createEmptyPriceResult(sku, currency) {
12
12
  const base = this.newModel();
13
13
  base.identifier = {
14
14
  sku: { key: sku }
@@ -1,5 +1,15 @@
1
1
  import { BaseProvider } from "./base.provider";
2
2
  class ProductProvider extends BaseProvider {
3
+ createEmptyProduct(id) {
4
+ const product = this.newModel();
5
+ product.identifier = { key: id };
6
+ product.meta.placeholder = true;
7
+ return product;
8
+ }
9
+ /**
10
+ * The resource name, used for caching and logging.
11
+ * @returns
12
+ */
3
13
  getResourceName() {
4
14
  return "product";
5
15
  }
@@ -0,0 +1,9 @@
1
+ import { BaseProvider } from "./base.provider";
2
+ class ProfileProvider extends BaseProvider {
3
+ getResourceName() {
4
+ return "profile";
5
+ }
6
+ }
7
+ export {
8
+ ProfileProvider
9
+ };
@@ -0,0 +1,9 @@
1
+ import { BaseProvider } from "./base.provider";
2
+ class StoreProvider extends BaseProvider {
3
+ getResourceName() {
4
+ return "store";
5
+ }
6
+ }
7
+ export {
8
+ StoreProvider
9
+ };
@@ -5,9 +5,11 @@ const CapabilitiesSchema = z.looseObject({
5
5
  analytics: z.boolean(),
6
6
  identity: z.boolean(),
7
7
  cart: z.boolean(),
8
+ cartPayment: z.boolean(),
8
9
  inventory: z.boolean(),
9
10
  price: z.boolean(),
10
- category: z.boolean()
11
+ category: z.boolean(),
12
+ store: z.boolean()
11
13
  });
12
14
  export {
13
15
  CapabilitiesSchema
@@ -1,7 +1,9 @@
1
1
  import { z } from "zod";
2
- import { CartIdentifierSchema, CartItemIdentifierSchema, ProductIdentifierSchema } from "../models/identifiers.model";
2
+ import { CartIdentifierSchema, CartItemIdentifierSchema, IdentityIdentifierSchema, ProductIdentifierSchema, SKUIdentifierSchema } from "../models/identifiers.model";
3
3
  import { BaseModelSchema } from "./base.model";
4
4
  import { MonetaryAmountSchema } from "./price.model";
5
+ import { AddressSchema } from "./profile.model";
6
+ import { ShippingMethodSchema } from "./shipping-method.model";
5
7
  const CostBreakDownSchema = z.looseObject({
6
8
  totalTax: MonetaryAmountSchema.default(() => MonetaryAmountSchema.parse({})).describe("The amount of tax paid on the cart. This may include VAT, GST, sales tax, etc."),
7
9
  totalDiscount: MonetaryAmountSchema.default(() => MonetaryAmountSchema.parse({})).describe("The amount of discount applied to the cart."),
@@ -19,15 +21,20 @@ const ItemCostBreakdownSchema = z.looseObject({
19
21
  const CartItemSchema = z.looseObject({
20
22
  identifier: CartItemIdentifierSchema.default(() => CartItemIdentifierSchema.parse({})),
21
23
  product: ProductIdentifierSchema.default(() => ProductIdentifierSchema.parse({})),
24
+ sku: SKUIdentifierSchema.default(() => SKUIdentifierSchema.parse({})),
22
25
  quantity: z.number().default(0),
23
26
  price: ItemCostBreakdownSchema.default(() => ItemCostBreakdownSchema.parse({}))
24
27
  });
25
28
  const CartSchema = BaseModelSchema.extend({
26
29
  identifier: CartIdentifierSchema.default(() => CartIdentifierSchema.parse({})),
30
+ userId: IdentityIdentifierSchema.default(() => IdentityIdentifierSchema.parse({})),
27
31
  items: z.array(CartItemSchema).default(() => []),
28
32
  price: CostBreakDownSchema.default(() => CostBreakDownSchema.parse({})),
29
33
  name: z.string().default(""),
30
- description: z.string().default("")
34
+ description: z.string().default(""),
35
+ shippingAddress: AddressSchema.optional(),
36
+ billingAddress: AddressSchema.optional(),
37
+ shippingMethod: ShippingMethodSchema.optional()
31
38
  });
32
39
  export {
33
40
  CartItemSchema,
@@ -30,27 +30,63 @@ const PriceIdentifierSchema = z.looseObject({
30
30
  const CategoryIdentifierSchema = z.looseObject({
31
31
  key: z.string().default("").nonoptional()
32
32
  });
33
+ const StoreIdentifierSchema = z.looseObject({
34
+ key: z.string().default("").optional()
35
+ });
36
+ const OrderIdentifierSchema = z.looseObject({
37
+ key: z.string().default("").nonoptional()
38
+ });
39
+ const OrderItemIdentifierSchema = z.looseObject({
40
+ key: z.string().default("").nonoptional()
41
+ });
33
42
  const WebStoreIdentifierSchema = z.looseObject({
34
43
  key: z.string().default("").nonoptional()
35
44
  });
36
- const InventoryChannelIdentifierSchema = z.looseObject({
37
- key: z.string().default("online").nonoptional()
45
+ const FulfillmentCenterIdentifierSchema = z.looseObject({
46
+ key: z.string().default("").nonoptional()
38
47
  });
39
48
  const InventoryIdentifierSchema = z.looseObject({
40
49
  sku: SKUIdentifierSchema.default(() => SKUIdentifierSchema.parse({})),
41
- channelId: InventoryChannelIdentifierSchema.default(() => InventoryChannelIdentifierSchema.parse({}))
50
+ fulfillmentCenter: FulfillmentCenterIdentifierSchema.default(
51
+ () => FulfillmentCenterIdentifierSchema.parse({})
52
+ )
53
+ });
54
+ const IdentityIdentifierSchema = z.looseObject({
55
+ userId: z.string().default("").nonoptional()
56
+ });
57
+ const ShippingMethodIdentifierSchema = z.looseObject({
58
+ key: z.string().default("").nonoptional()
59
+ });
60
+ const PaymentMethodIdentifierSchema = z.looseObject({
61
+ method: z.string().default("").nonoptional(),
62
+ name: z.string().default("").nonoptional(),
63
+ paymentProcessor: z.string().default("").nonoptional()
64
+ });
65
+ const AddressIdentifierSchema = z.looseObject({
66
+ nickName: z.string().default("").nonoptional()
67
+ });
68
+ const PaymentInstructionIdentifierSchema = z.looseObject({
69
+ key: z.string().default("").nonoptional()
42
70
  });
43
71
  export {
72
+ AddressIdentifierSchema,
44
73
  CartIdentifierSchema,
45
74
  CartItemIdentifierSchema,
46
75
  CategoryIdentifierSchema,
47
76
  FacetIdentifierSchema,
48
77
  FacetValueIdentifierSchema,
49
- InventoryChannelIdentifierSchema,
78
+ FulfillmentCenterIdentifierSchema,
79
+ IdentityIdentifierSchema,
50
80
  InventoryIdentifierSchema,
81
+ OrderIdentifierSchema,
82
+ OrderItemIdentifierSchema,
83
+ PaymentInstructionIdentifierSchema,
84
+ PaymentMethodIdentifierSchema,
51
85
  PriceIdentifierSchema,
52
86
  ProductIdentifierSchema,
53
87
  SKUIdentifierSchema,
54
88
  SearchIdentifierSchema,
89
+ ShippingMethodIdentifierSchema,
90
+ StoreIdentifierSchema,
55
91
  WebStoreIdentifierSchema
56
92
  };
@@ -1,14 +1,28 @@
1
1
  import { z } from "zod";
2
2
  import { BaseModelSchema } from "./base.model";
3
- const IdentityTypeSchema = z.enum(["Anonymous", "Guest", "Registered"]);
4
- const IdentitySchema = BaseModelSchema.extend({
5
- id: z.string().default(""),
6
- type: IdentityTypeSchema.default("Anonymous"),
3
+ import { IdentityIdentifierSchema } from "./identifiers.model";
4
+ const AnonymousIdentitySchema = BaseModelSchema.extend({
5
+ type: z.literal("Anonymous")
6
+ });
7
+ const GuestIdentitySchema = BaseModelSchema.extend({
8
+ id: IdentityIdentifierSchema.default(() => IdentityIdentifierSchema.parse({})),
9
+ type: z.literal("Guest"),
10
+ token: z.string().optional(),
11
+ refresh_token: z.string().optional(),
12
+ expiry: z.coerce.date().default(/* @__PURE__ */ new Date())
13
+ });
14
+ const RegisteredIdentitySchema = BaseModelSchema.extend({
15
+ id: IdentityIdentifierSchema.default(() => IdentityIdentifierSchema.parse({})),
16
+ type: z.literal("Registered"),
17
+ logonId: z.string().default(""),
7
18
  token: z.string().optional(),
8
- issued: z.coerce.date().default(/* @__PURE__ */ new Date()),
19
+ refresh_token: z.string().optional(),
9
20
  expiry: z.coerce.date().default(/* @__PURE__ */ new Date())
10
21
  });
22
+ const IdentitySchema = z.discriminatedUnion("type", [AnonymousIdentitySchema, GuestIdentitySchema, RegisteredIdentitySchema]);
11
23
  export {
24
+ AnonymousIdentitySchema,
25
+ GuestIdentitySchema,
12
26
  IdentitySchema,
13
- IdentityTypeSchema
27
+ RegisteredIdentitySchema
14
28
  };
@@ -0,0 +1,15 @@
1
+ export * from "./analytics.model";
2
+ export * from "./base.model";
3
+ export * from "./cart.model";
4
+ export * from "./category.model";
5
+ export * from "./currency.model";
6
+ export * from "./identifiers.model";
7
+ export * from "./identity.model";
8
+ export * from "./inventory.model";
9
+ export * from "./payment.model";
10
+ export * from "./price.model";
11
+ export * from "./product.model";
12
+ export * from "./profile.model";
13
+ export * from "./search.model";
14
+ export * from "./shipping-method.model";
15
+ export * from "./store.model";
@@ -0,0 +1,37 @@
1
+ import { z } from "zod";
2
+ import { BaseModelSchema, ImageSchema } from "./base.model";
3
+ import { CartIdentifierSchema, PaymentInstructionIdentifierSchema, PaymentMethodIdentifierSchema } from "./identifiers.model";
4
+ import { MonetaryAmountSchema } from "./price.model";
5
+ const PaymentStatusSchema = z.enum(["pending", "authorized", "canceled", "capture", "partial_capture", "refunded", "partial_refund"]);
6
+ const PaymentProtocolDataSchema = z.looseObject({
7
+ key: z.string().default(""),
8
+ value: z.string().default("")
9
+ });
10
+ const PaymentMethodSchema = BaseModelSchema.extend({
11
+ identifier: PaymentMethodIdentifierSchema.default(() => PaymentMethodIdentifierSchema.parse({})),
12
+ logo: ImageSchema.optional(),
13
+ description: z.string().default(""),
14
+ isPunchOut: z.boolean().default(true)
15
+ });
16
+ const PaymentInstructionSchema = BaseModelSchema.extend({
17
+ identifier: PaymentInstructionIdentifierSchema.default(() => PaymentInstructionIdentifierSchema.parse({})),
18
+ amount: MonetaryAmountSchema.default(() => MonetaryAmountSchema.parse({})),
19
+ paymentMethod: PaymentMethodIdentifierSchema.default(() => PaymentMethodIdentifierSchema.parse({})),
20
+ protocolData: z.array(PaymentProtocolDataSchema).default(() => []).describe("Additional protocol-specific data for processing the payment."),
21
+ status: PaymentStatusSchema.default("pending")
22
+ });
23
+ const CartPaymentInstructionSchema = PaymentInstructionSchema.extend({
24
+ cart: CartIdentifierSchema.default(() => CartIdentifierSchema.parse({}))
25
+ });
26
+ const OrderPaymentInstructionSchema = PaymentInstructionSchema.extend({
27
+ order: z.string().default("")
28
+ // OrderIdentifierSchema
29
+ });
30
+ export {
31
+ CartPaymentInstructionSchema,
32
+ OrderPaymentInstructionSchema,
33
+ PaymentInstructionSchema,
34
+ PaymentMethodSchema,
35
+ PaymentProtocolDataSchema,
36
+ PaymentStatusSchema
37
+ };