@reactionary/core 0.0.42 → 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 (74) 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 +2 -1
  6. package/initialization.js +43 -0
  7. package/package.json +4 -2
  8. package/providers/base.provider.js +29 -12
  9. package/providers/index.js +2 -0
  10. package/providers/profile.provider.js +9 -0
  11. package/providers/store.provider.js +9 -0
  12. package/schemas/capabilities.schema.js +2 -1
  13. package/schemas/models/identifiers.model.js +12 -6
  14. package/schemas/models/identity.model.js +15 -16
  15. package/schemas/models/index.js +1 -0
  16. package/schemas/models/profile.model.js +3 -2
  17. package/schemas/models/shipping-method.model.js +2 -2
  18. package/schemas/models/store.model.js +11 -0
  19. package/schemas/mutations/cart.mutation.js +2 -2
  20. package/schemas/mutations/identity.mutation.js +6 -1
  21. package/schemas/mutations/index.js +1 -0
  22. package/schemas/mutations/profile.mutation.js +9 -0
  23. package/schemas/queries/index.js +2 -0
  24. package/schemas/queries/inventory.query.js +3 -5
  25. package/schemas/queries/profile.query.js +5 -0
  26. package/schemas/queries/store.query.js +11 -0
  27. package/schemas/session.schema.js +22 -8
  28. package/src/cache/cache.interface.d.ts +13 -20
  29. package/src/cache/memory-cache.d.ts +18 -0
  30. package/src/cache/noop-cache.d.ts +5 -11
  31. package/src/cache/redis-cache.d.ts +5 -11
  32. package/src/client/client-builder.d.ts +2 -2
  33. package/src/client/client.d.ts +10 -10
  34. package/src/decorators/reactionary.decorator.d.ts +34 -1
  35. package/src/index.d.ts +2 -1
  36. package/src/initialization.d.ts +2 -0
  37. package/src/providers/analytics.provider.d.ts +1 -1
  38. package/src/providers/base.provider.d.ts +12 -9
  39. package/src/providers/cart-payment.provider.d.ts +7 -7
  40. package/src/providers/cart.provider.d.ts +17 -17
  41. package/src/providers/category.provider.d.ts +9 -9
  42. package/src/providers/identity.provider.d.ts +8 -7
  43. package/src/providers/index.d.ts +2 -0
  44. package/src/providers/inventory.provider.d.ts +4 -4
  45. package/src/providers/price.provider.d.ts +6 -6
  46. package/src/providers/product.provider.d.ts +5 -5
  47. package/src/providers/profile.provider.d.ts +10 -0
  48. package/src/providers/search.provider.d.ts +4 -4
  49. package/src/providers/store.provider.d.ts +8 -0
  50. package/src/schemas/capabilities.schema.d.ts +1 -0
  51. package/src/schemas/models/analytics.model.d.ts +1 -1
  52. package/src/schemas/models/cart.model.d.ts +14 -0
  53. package/src/schemas/models/identifiers.model.d.ts +10 -6
  54. package/src/schemas/models/identity.model.d.ts +72 -27
  55. package/src/schemas/models/index.d.ts +1 -0
  56. package/src/schemas/models/inventory.model.d.ts +1 -1
  57. package/src/schemas/models/profile.model.d.ts +35 -0
  58. package/src/schemas/models/store.model.d.ts +18 -0
  59. package/src/schemas/mutations/cart-payment.mutation.d.ts +1 -1
  60. package/src/schemas/mutations/cart.mutation.d.ts +14 -0
  61. package/src/schemas/mutations/identity.mutation.d.ts +5 -0
  62. package/src/schemas/mutations/index.d.ts +1 -0
  63. package/src/schemas/mutations/profile.mutation.d.ts +6 -0
  64. package/src/schemas/queries/cart.query.d.ts +1 -1
  65. package/src/schemas/queries/identity.query.d.ts +1 -1
  66. package/src/schemas/queries/index.d.ts +2 -0
  67. package/src/schemas/queries/inventory.query.d.ts +6 -15
  68. package/src/schemas/queries/price.query.d.ts +1 -1
  69. package/src/schemas/queries/profile.query.d.ts +3 -0
  70. package/src/schemas/queries/search.query.d.ts +1 -1
  71. package/src/schemas/queries/store.query.d.ts +8 -0
  72. package/src/schemas/session.schema.d.ts +53 -21
  73. package/cache/cache-evaluation.interface.js +0 -0
  74. 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,6 +1,6 @@
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";
@@ -11,3 +11,4 @@ export * from "./schemas/session.schema";
11
11
  export * from "./schemas/models/";
12
12
  export * from "./schemas/mutations/";
13
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.42",
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
  }
@@ -7,4 +7,6 @@ export * from "./identity.provider";
7
7
  export * from "./inventory.provider";
8
8
  export * from "./price.provider";
9
9
  export * from "./product.provider";
10
+ export * from "./profile.provider";
10
11
  export * from "./search.provider";
12
+ export * from "./store.provider";
@@ -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
+ };
@@ -8,7 +8,8 @@ const CapabilitiesSchema = z.looseObject({
8
8
  cartPayment: z.boolean(),
9
9
  inventory: z.boolean(),
10
10
  price: z.boolean(),
11
- category: z.boolean()
11
+ category: z.boolean(),
12
+ store: z.boolean()
12
13
  });
13
14
  export {
14
15
  CapabilitiesSchema
@@ -30,6 +30,9 @@ 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
+ });
33
36
  const OrderIdentifierSchema = z.looseObject({
34
37
  key: z.string().default("").nonoptional()
35
38
  });
@@ -39,17 +42,19 @@ const OrderItemIdentifierSchema = z.looseObject({
39
42
  const WebStoreIdentifierSchema = z.looseObject({
40
43
  key: z.string().default("").nonoptional()
41
44
  });
42
- const InventoryChannelIdentifierSchema = z.looseObject({
43
- key: z.string().default("online").nonoptional()
45
+ const FulfillmentCenterIdentifierSchema = z.looseObject({
46
+ key: z.string().default("").nonoptional()
44
47
  });
45
48
  const InventoryIdentifierSchema = z.looseObject({
46
49
  sku: SKUIdentifierSchema.default(() => SKUIdentifierSchema.parse({})),
47
- channelId: InventoryChannelIdentifierSchema.default(() => InventoryChannelIdentifierSchema.parse({}))
50
+ fulfillmentCenter: FulfillmentCenterIdentifierSchema.default(
51
+ () => FulfillmentCenterIdentifierSchema.parse({})
52
+ )
48
53
  });
49
54
  const IdentityIdentifierSchema = z.looseObject({
50
55
  userId: z.string().default("").nonoptional()
51
56
  });
52
- const ShippingMethodIdentifier = z.looseObject({
57
+ const ShippingMethodIdentifierSchema = z.looseObject({
53
58
  key: z.string().default("").nonoptional()
54
59
  });
55
60
  const PaymentMethodIdentifierSchema = z.looseObject({
@@ -70,8 +75,8 @@ export {
70
75
  CategoryIdentifierSchema,
71
76
  FacetIdentifierSchema,
72
77
  FacetValueIdentifierSchema,
78
+ FulfillmentCenterIdentifierSchema,
73
79
  IdentityIdentifierSchema,
74
- InventoryChannelIdentifierSchema,
75
80
  InventoryIdentifierSchema,
76
81
  OrderIdentifierSchema,
77
82
  OrderItemIdentifierSchema,
@@ -81,6 +86,7 @@ export {
81
86
  ProductIdentifierSchema,
82
87
  SKUIdentifierSchema,
83
88
  SearchIdentifierSchema,
84
- ShippingMethodIdentifier,
89
+ ShippingMethodIdentifierSchema,
90
+ StoreIdentifierSchema,
85
91
  WebStoreIdentifierSchema
86
92
  };
@@ -1,29 +1,28 @@
1
1
  import { z } from "zod";
2
2
  import { BaseModelSchema } from "./base.model";
3
3
  import { IdentityIdentifierSchema } from "./identifiers.model";
4
- const IdentityTypeSchema = z.enum(["Anonymous", "Guest", "Registered"]);
5
- const ServiceTokenSchema = z.object({
6
- service: z.string().default(""),
7
- token: z.string().default(""),
8
- issued: z.coerce.date().default(/* @__PURE__ */ new Date()),
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(),
9
12
  expiry: z.coerce.date().default(/* @__PURE__ */ new Date())
10
13
  });
11
- const IdentitySchema = BaseModelSchema.extend({
14
+ const RegisteredIdentitySchema = BaseModelSchema.extend({
12
15
  id: IdentityIdentifierSchema.default(() => IdentityIdentifierSchema.parse({})),
13
- type: IdentityTypeSchema.default("Anonymous"),
16
+ type: z.literal("Registered"),
14
17
  logonId: z.string().default(""),
15
- createdAt: z.string().default(() => (/* @__PURE__ */ new Date()).toISOString()),
16
- updatedAt: z.string().default(() => (/* @__PURE__ */ new Date()).toISOString()),
17
- // Tokens for various services
18
- keyring: z.array(ServiceTokenSchema).default(() => []),
19
- // Deprecated - use serviceTokens map instead
20
- currentService: z.string().optional(),
21
18
  token: z.string().optional(),
22
- issued: z.coerce.date().default(/* @__PURE__ */ new Date()),
19
+ refresh_token: z.string().optional(),
23
20
  expiry: z.coerce.date().default(/* @__PURE__ */ new Date())
24
21
  });
22
+ const IdentitySchema = z.discriminatedUnion("type", [AnonymousIdentitySchema, GuestIdentitySchema, RegisteredIdentitySchema]);
25
23
  export {
24
+ AnonymousIdentitySchema,
25
+ GuestIdentitySchema,
26
26
  IdentitySchema,
27
- IdentityTypeSchema,
28
- ServiceTokenSchema
27
+ RegisteredIdentitySchema
29
28
  };
@@ -12,3 +12,4 @@ export * from "./product.model";
12
12
  export * from "./profile.model";
13
13
  export * from "./search.model";
14
14
  export * from "./shipping-method.model";
15
+ export * from "./store.model";
@@ -1,6 +1,7 @@
1
1
  import z from "zod";
2
2
  import { AddressIdentifierSchema, IdentityIdentifierSchema } from "./identifiers.model";
3
- const AddressSchema = z.looseObject({
3
+ import { BaseModelSchema } from "./base.model";
4
+ const AddressSchema = BaseModelSchema.extend({
4
5
  identifier: AddressIdentifierSchema.default(() => AddressIdentifierSchema.parse({})),
5
6
  firstName: z.string().default(""),
6
7
  lastName: z.string().default(""),
@@ -11,7 +12,7 @@ const AddressSchema = z.looseObject({
11
12
  postalCode: z.string().default(""),
12
13
  countryCode: z.string().default("US")
13
14
  });
14
- const ProfileSchema = z.looseObject({
15
+ const ProfileSchema = BaseModelSchema.extend({
15
16
  identifier: IdentityIdentifierSchema.default(() => IdentityIdentifierSchema.parse({})),
16
17
  email: z.string().email().default(""),
17
18
  phone: z.string().default(""),
@@ -1,9 +1,9 @@
1
1
  import z from "zod";
2
- import { ShippingMethodIdentifier } from "./identifiers.model";
2
+ import { ShippingMethodIdentifierSchema } from "./identifiers.model";
3
3
  import { MonetaryAmountSchema } from "./price.model";
4
4
  import { ImageSchema } from "./base.model";
5
5
  const ShippingMethodSchema = z.looseObject({
6
- identifier: ShippingMethodIdentifier.default(() => ShippingMethodIdentifier.parse({})),
6
+ identifier: ShippingMethodIdentifierSchema.default(() => ShippingMethodIdentifierSchema.parse({})),
7
7
  name: z.string().default(""),
8
8
  description: z.string().default(""),
9
9
  logo: ImageSchema.optional(),
@@ -0,0 +1,11 @@
1
+ import { z } from "zod";
2
+ import { BaseModelSchema } from "./base.model";
3
+ import { FulfillmentCenterIdentifierSchema, StoreIdentifierSchema } from "./identifiers.model";
4
+ const StoreSchema = BaseModelSchema.extend({
5
+ identifier: StoreIdentifierSchema.default(() => StoreIdentifierSchema.parse({})),
6
+ name: z.string().default(""),
7
+ fulfillmentCenter: FulfillmentCenterIdentifierSchema.default(() => FulfillmentCenterIdentifierSchema.parse({}))
8
+ });
9
+ export {
10
+ StoreSchema
11
+ };
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { BaseMutationSchema } from "./base.mutation";
3
- import { CartIdentifierSchema, CartItemIdentifierSchema, PaymentMethodIdentifierSchema, ShippingMethodIdentifier, SKUIdentifierSchema } from "../models/identifiers.model";
3
+ import { CartIdentifierSchema, CartItemIdentifierSchema, PaymentMethodIdentifierSchema, ShippingMethodIdentifierSchema, SKUIdentifierSchema } from "../models/identifiers.model";
4
4
  import { AddressSchema } from "../models/profile.model";
5
5
  import { CurrencySchema } from "../models/currency.model";
6
6
  import { MonetaryAmountSchema } from "../models/price.model";
@@ -23,7 +23,7 @@ const CartMutationDeleteCartSchema = BaseMutationSchema.extend({
23
23
  });
24
24
  const CartMutationSetShippingInfoSchema = BaseMutationSchema.extend({
25
25
  cart: CartIdentifierSchema.required(),
26
- shippingMethod: ShippingMethodIdentifier.optional(),
26
+ shippingMethod: ShippingMethodIdentifierSchema.optional(),
27
27
  shippingAddress: AddressSchema.optional()
28
28
  });
29
29
  const CartMutationSetBillingAddressSchema = BaseMutationSchema.extend({
@@ -5,7 +5,12 @@ const IdentityMutationLoginSchema = BaseMutationSchema.extend({
5
5
  password: z.string()
6
6
  });
7
7
  const IdentityMutationLogoutSchema = BaseMutationSchema.extend({});
8
+ const IdentityMutationRegisterSchema = BaseMutationSchema.extend({
9
+ username: z.string(),
10
+ password: z.string()
11
+ });
8
12
  export {
9
13
  IdentityMutationLoginSchema,
10
- IdentityMutationLogoutSchema
14
+ IdentityMutationLogoutSchema,
15
+ IdentityMutationRegisterSchema
11
16
  };
@@ -6,4 +6,5 @@ export * from "./identity.mutation";
6
6
  export * from "./inventory.mutation";
7
7
  export * from "./price.mutation";
8
8
  export * from "./product.mutation";
9
+ export * from "./profile.mutation";
9
10
  export * from "./search.mutation";
@@ -0,0 +1,9 @@
1
+ import { z } from "zod";
2
+ import { BaseMutationSchema } from "./base.mutation";
3
+ const ProfileMutationUpdateSchema = BaseMutationSchema.extend({
4
+ email: z.email().default("base@example.com"),
5
+ phone: z.string().default("")
6
+ });
7
+ export {
8
+ ProfileMutationUpdateSchema
9
+ };
@@ -7,4 +7,6 @@ export * from "./identity.query";
7
7
  export * from "./inventory.query";
8
8
  export * from "./price.query";
9
9
  export * from "./product.query";
10
+ export * from "./profile.query";
10
11
  export * from "./search.query";
12
+ export * from "./store.query";
@@ -1,11 +1,9 @@
1
- import { z } from "zod";
2
1
  import { BaseQuerySchema } from "./base.query";
3
- import { ProductIdentifierSchema } from "../models/identifiers.model";
2
+ import { FulfillmentCenterIdentifierSchema, ProductIdentifierSchema } from "../models/identifiers.model";
4
3
  const InventoryQueryBySKUSchema = BaseQuerySchema.extend({
5
- query: z.literal("sku"),
6
- sku: ProductIdentifierSchema.default(() => ProductIdentifierSchema.parse({}))
4
+ sku: ProductIdentifierSchema.default(() => ProductIdentifierSchema.parse({})).nonoptional(),
5
+ fulfilmentCenter: FulfillmentCenterIdentifierSchema.default(() => FulfillmentCenterIdentifierSchema.parse({})).nonoptional()
7
6
  });
8
- ;
9
7
  export {
10
8
  InventoryQueryBySKUSchema
11
9
  };
@@ -0,0 +1,5 @@
1
+ import { BaseQuerySchema } from "./base.query";
2
+ const ProfileQuerySelfSchema = BaseQuerySchema.extend({});
3
+ export {
4
+ ProfileQuerySelfSchema
5
+ };
@@ -0,0 +1,11 @@
1
+ import { z } from "zod";
2
+ import { BaseQuerySchema } from "./base.query";
3
+ const StoreQueryByProximitySchema = BaseQuerySchema.extend({
4
+ longitude: z.number().default(0),
5
+ latitude: z.number().default(0),
6
+ distance: z.number().default(0),
7
+ limit: z.number().default(10)
8
+ });
9
+ export {
10
+ StoreQueryByProximitySchema
11
+ };