@reactionary/core 0.1.13 → 0.2.2

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 (63) hide show
  1. package/cache/memory-cache.js +1 -1
  2. package/decorators/reactionary.decorator.js +50 -16
  3. package/package.json +1 -1
  4. package/providers/base.provider.js +0 -15
  5. package/providers/cart.provider.js +0 -39
  6. package/providers/inventory.provider.js +1 -8
  7. package/providers/order.provider.js +0 -1
  8. package/providers/price.provider.js +0 -7
  9. package/providers/product.provider.js +0 -7
  10. package/schemas/errors/generic.error.js +8 -0
  11. package/schemas/errors/index.js +4 -0
  12. package/schemas/errors/invalid-input.error.js +8 -0
  13. package/schemas/errors/invalid-output.error.js +8 -0
  14. package/schemas/errors/not-found.error.js +8 -0
  15. package/schemas/index.js +2 -0
  16. package/schemas/models/base.model.js +1 -14
  17. package/schemas/models/profile.model.js +1 -1
  18. package/schemas/mutations/cart.mutation.js +1 -1
  19. package/schemas/mutations/checkout.mutation.js +4 -4
  20. package/schemas/mutations/profile.mutation.js +31 -3
  21. package/schemas/queries/profile.query.js +5 -2
  22. package/schemas/result.js +51 -0
  23. package/src/cache/memory-cache.d.ts +2 -1
  24. package/src/decorators/reactionary.decorator.d.ts +3 -2
  25. package/src/providers/base.provider.d.ts +0 -3
  26. package/src/providers/cart.provider.d.ts +11 -10
  27. package/src/providers/category.provider.d.ts +6 -6
  28. package/src/providers/checkout.provider.d.ts +11 -9
  29. package/src/providers/identity.provider.d.ts +5 -4
  30. package/src/providers/inventory.provider.d.ts +3 -1
  31. package/src/providers/order.provider.d.ts +3 -1
  32. package/src/providers/price.provider.d.ts +3 -3
  33. package/src/providers/product-search.provider.d.ts +3 -3
  34. package/src/providers/product.provider.d.ts +5 -3
  35. package/src/providers/profile.provider.d.ts +66 -4
  36. package/src/providers/store.provider.d.ts +2 -1
  37. package/src/schemas/errors/generic.error.d.ts +7 -0
  38. package/src/schemas/errors/index.d.ts +4 -0
  39. package/src/schemas/errors/invalid-input.error.d.ts +7 -0
  40. package/src/schemas/errors/invalid-output.error.d.ts +7 -0
  41. package/src/schemas/errors/not-found.error.d.ts +7 -0
  42. package/src/schemas/index.d.ts +2 -0
  43. package/src/schemas/models/analytics.model.d.ts +1 -9
  44. package/src/schemas/models/base.model.d.ts +1 -29
  45. package/src/schemas/models/cart.model.d.ts +0 -7
  46. package/src/schemas/models/category.model.d.ts +0 -21
  47. package/src/schemas/models/checkout.model.d.ts +0 -35
  48. package/src/schemas/models/identity.model.d.ts +0 -42
  49. package/src/schemas/models/inventory.model.d.ts +0 -7
  50. package/src/schemas/models/order.model.d.ts +0 -28
  51. package/src/schemas/models/payment.model.d.ts +0 -14
  52. package/src/schemas/models/price.model.d.ts +0 -7
  53. package/src/schemas/models/product-search.model.d.ts +0 -21
  54. package/src/schemas/models/product.model.d.ts +0 -7
  55. package/src/schemas/models/profile.model.d.ts +2 -37
  56. package/src/schemas/models/shipping-method.model.d.ts +0 -14
  57. package/src/schemas/models/store.model.d.ts +0 -7
  58. package/src/schemas/mutations/cart.mutation.d.ts +2 -16
  59. package/src/schemas/mutations/checkout.mutation.d.ts +1 -8
  60. package/src/schemas/mutations/profile.mutation.d.ts +78 -0
  61. package/src/schemas/queries/product-search.query.d.ts +0 -7
  62. package/src/schemas/queries/profile.query.d.ts +6 -2
  63. package/src/schemas/result.d.ts +55 -0
@@ -1,4 +1,5 @@
1
1
  import { getReactionaryCacheMeter } from "../metrics/metrics.js";
2
+ import { error, NotFoundErrorSchema, success } from "../schemas/index.js";
2
3
  class MemoryCache {
3
4
  constructor() {
4
5
  this.entries = new Array();
@@ -13,7 +14,6 @@ class MemoryCache {
13
14
  return null;
14
15
  }
15
16
  const parsed = schema.parse(c.value);
16
- parsed.meta.cache.hit = true;
17
17
  this.meter.hits.add(1, {
18
18
  "labels.cache_type": "memory"
19
19
  });
@@ -1,5 +1,6 @@
1
1
  import { trace } from "@opentelemetry/api";
2
2
  import { getReactionaryMeter } from "../metrics/metrics.js";
3
+ import { error, success } from "../schemas/result.js";
3
4
  const TRACER_NAME = "@reactionary";
4
5
  const TRACER_VERSION = "0.0.1";
5
6
  let globalTracer = null;
@@ -56,26 +57,43 @@ function Reactionary(options) {
56
57
  meter.requestInProgress.add(1, attributes);
57
58
  try {
58
59
  const input = validateInput(args[0], configuration.inputSchema);
59
- const cacheKey = this.generateCacheKeyForQuery(scope, input);
60
+ if (!input.success) {
61
+ return input;
62
+ }
63
+ const cacheKey = this.generateCacheKeyForQuery(scope, input.value);
60
64
  const fromCache = await this.cache.get(
61
65
  cacheKey,
62
66
  options.inputSchema
63
67
  );
64
- let result = fromCache;
65
- if (!result) {
66
- result = await original.apply(this, [input]);
67
- const dependencyIds = this.generateDependencyIdsForModel(result);
68
- this.cache.put(cacheKey, result, {
69
- ttlSeconds: configuration.cacheTimeToLiveInSeconds,
70
- dependencyIds
71
- });
68
+ let result;
69
+ if (!fromCache) {
70
+ result = await original.apply(this, [input.value]);
71
+ const r = result;
72
+ if (r.success) {
73
+ const dependencyIds = this.generateDependencyIdsForModel(r.value);
74
+ this.cache.put(cacheKey, r.value, {
75
+ ttlSeconds: configuration.cacheTimeToLiveInSeconds,
76
+ dependencyIds
77
+ });
78
+ }
72
79
  } else {
80
+ result = success(fromCache);
73
81
  cacheStatus = "hit";
74
82
  }
75
- return validateOutput(result, configuration.outputSchema);
83
+ const validatedResult = validateOutput(result, configuration.outputSchema);
84
+ if (validatedResult.success) {
85
+ validatedResult.meta.cache.hit = !!fromCache;
86
+ validatedResult.meta.cache.key = cacheKey;
87
+ }
88
+ return result;
76
89
  } catch (err) {
90
+ console.error(err);
77
91
  status = "error";
78
- throw err;
92
+ const result = error({
93
+ type: "Generic",
94
+ message: "REDACTED"
95
+ });
96
+ return result;
79
97
  } finally {
80
98
  const duration = performance.now() - startTime;
81
99
  const finalAttributes = {
@@ -94,17 +112,33 @@ function Reactionary(options) {
94
112
  }
95
113
  function validateInput(input, schema) {
96
114
  if (!schema) {
97
- return input;
115
+ return success(input);
116
+ }
117
+ let validated = success(input);
118
+ const parse = schema.safeParse(input);
119
+ if (!parse.success) {
120
+ validated = error({
121
+ type: "InvalidInput",
122
+ error: parse.error
123
+ });
98
124
  }
99
- const parsed = schema.parse(input);
100
- return parsed;
125
+ return validated;
101
126
  }
102
127
  function validateOutput(output, schema) {
103
128
  if (!schema) {
104
129
  return output;
105
130
  }
106
- const parsed = schema.parse(output);
107
- return parsed;
131
+ let validated = output;
132
+ if (output.success) {
133
+ const parse = schema.safeParse(output.value);
134
+ if (!parse.success) {
135
+ validated = error({
136
+ type: "InvalidOutput",
137
+ error: parse.error
138
+ });
139
+ }
140
+ }
141
+ return validated;
108
142
  }
109
143
  async function traceSpan(name, fn) {
110
144
  const tracer = getTracer();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactionary/core",
3
- "version": "0.1.13",
3
+ "version": "0.2.2",
4
4
  "main": "index.js",
5
5
  "types": "src/index.d.ts",
6
6
  "dependencies": {
@@ -19,21 +19,6 @@ class BaseProvider {
19
19
  const queryHash = h.hash(query);
20
20
  return `${scope}:${queryHash}`;
21
21
  }
22
- generateCacheKeyPaginatedResult(resultSetName, res) {
23
- const type = this.getResourceName();
24
- const langPart = this.context.languageContext.locale;
25
- const currencyPart = this.context.languageContext.currencyCode || "default";
26
- const storePart = this.context.storeIdentifier?.key || "default";
27
- return `${type}-${resultSetName}-paginated|pageNumber:${res.pageNumber}|pageSize:${res.pageSize}|store:${storePart}|lang:${langPart}|currency:${currencyPart}`;
28
- }
29
- generateCacheKeySingle(identifier) {
30
- const type = this.getResourceName();
31
- const idPart = Object.entries(identifier).map(([k, v]) => `${k}:${v}`).join("#");
32
- const langPart = this.context.languageContext.locale;
33
- const currencyPart = this.context.languageContext.currencyCode || "default";
34
- const storePart = this.context.storeIdentifier?.key || "default";
35
- return `${type}-${idPart}|store:${storePart}|lang:${langPart}|currency:${currencyPart}`;
36
- }
37
22
  }
38
23
  export {
39
24
  BaseProvider
@@ -1,44 +1,5 @@
1
1
  import { BaseProvider } from "./base.provider.js";
2
2
  class CartProvider extends BaseProvider {
3
- createEmptyCart() {
4
- const cart = {
5
- identifier: { key: "" },
6
- meta: { placeholder: true, cache: { hit: true, key: "empty-cart" } },
7
- description: "",
8
- items: [],
9
- name: "",
10
- price: {
11
- grandTotal: {
12
- value: 0,
13
- currency: "XXX"
14
- },
15
- totalDiscount: {
16
- value: 0,
17
- currency: "XXX"
18
- },
19
- totalProductPrice: {
20
- value: 0,
21
- currency: "XXX"
22
- },
23
- totalShipping: {
24
- value: 0,
25
- currency: "XXX"
26
- },
27
- totalSurcharge: {
28
- value: 0,
29
- currency: "XXX"
30
- },
31
- totalTax: {
32
- value: 0,
33
- currency: "XXX"
34
- }
35
- },
36
- userId: {
37
- userId: ""
38
- }
39
- };
40
- return cart;
41
- }
42
3
  getResourceName() {
43
4
  return "cart";
44
5
  }
@@ -7,14 +7,7 @@ class InventoryProvider extends BaseProvider {
7
7
  const inventory = {
8
8
  identifier: key,
9
9
  quantity: 0,
10
- status: "outOfStock",
11
- meta: {
12
- cache: {
13
- hit: false,
14
- key: this.generateCacheKeySingle(key)
15
- },
16
- placeholder: true
17
- }
10
+ status: "outOfStock"
18
11
  };
19
12
  return inventory;
20
13
  }
@@ -2,7 +2,6 @@ import { BaseProvider } from "./base.provider.js";
2
2
  class OrderProvider extends BaseProvider {
3
3
  createEmptyOrder() {
4
4
  const order = {
5
- meta: { placeholder: true, cache: { hit: true, key: "empty-order" } },
6
5
  identifier: {
7
6
  key: ""
8
7
  },
@@ -19,13 +19,6 @@ class PriceProvider extends BaseProvider {
19
19
  unitPrice: {
20
20
  value: -1,
21
21
  currency: this.context.languageContext.currencyCode
22
- },
23
- meta: {
24
- cache: {
25
- hit: false,
26
- key: `price-${sku}-${this.context.languageContext.currencyCode}`
27
- },
28
- placeholder: true
29
22
  }
30
23
  };
31
24
  return price;
@@ -21,13 +21,6 @@ class ProductProvider extends BaseProvider {
21
21
  upc: ""
22
22
  },
23
23
  manufacturer: "",
24
- meta: {
25
- cache: {
26
- hit: false,
27
- key: ""
28
- },
29
- placeholder: true
30
- },
31
24
  name: "",
32
25
  options: [],
33
26
  parentCategories: [],
@@ -0,0 +1,8 @@
1
+ import { z } from "zod";
2
+ const GenericErrorSchema = z.looseObject({
3
+ type: z.literal("Generic"),
4
+ message: z.string().nonempty()
5
+ });
6
+ export {
7
+ GenericErrorSchema
8
+ };
@@ -0,0 +1,4 @@
1
+ export * from "./generic.error.js";
2
+ export * from "./invalid-input.error.js";
3
+ export * from "./invalid-output.error.js";
4
+ export * from "./not-found.error.js";
@@ -0,0 +1,8 @@
1
+ import { z } from "zod";
2
+ const InvalidInputErrorSchema = z.looseObject({
3
+ type: z.literal("InvalidInput"),
4
+ error: z.ZodError
5
+ });
6
+ export {
7
+ InvalidInputErrorSchema
8
+ };
@@ -0,0 +1,8 @@
1
+ import { z } from "zod";
2
+ const InvalidOutputErrorSchema = z.looseObject({
3
+ type: z.literal("InvalidOutput"),
4
+ error: z.ZodError
5
+ });
6
+ export {
7
+ InvalidOutputErrorSchema
8
+ };
@@ -0,0 +1,8 @@
1
+ import { z } from "zod";
2
+ const NotFoundErrorSchema = z.looseObject({
3
+ type: z.literal("NotFound"),
4
+ identifier: z.unknown()
5
+ });
6
+ export {
7
+ NotFoundErrorSchema
8
+ };
package/schemas/index.js CHANGED
@@ -1,5 +1,7 @@
1
+ export * from "./errors/index.js";
1
2
  export * from "./models/index.js";
2
3
  export * from "./mutations/index.js";
3
4
  export * from "./queries/index.js";
4
5
  export * from "./capabilities.schema.js";
5
6
  export * from "./session.schema.js";
7
+ export * from "./result.js";
@@ -1,22 +1,11 @@
1
1
  import { z } from "zod";
2
- const CacheInformationSchema = z.looseObject({
3
- hit: z.boolean().default(false),
4
- key: z.string().default("")
5
- });
6
- const MetaSchema = z.looseObject({
7
- cache: CacheInformationSchema.default(() => CacheInformationSchema.parse({})),
8
- placeholder: z.boolean().default(false).describe("Whether or not the entity exists in a remote system, or is a default placeholder.")
9
- });
10
- const BaseModelSchema = z.looseObject({
11
- meta: MetaSchema.default(() => MetaSchema.parse({}))
12
- });
2
+ const BaseModelSchema = z.looseObject({});
13
3
  const PaginationOptionsSchema = z.looseObject({
14
4
  pageNumber: z.number().default(1).describe("Current page number, starting from 1"),
15
5
  pageSize: z.number().min(1).max(50).default(20).describe("Number of items per page")
16
6
  });
17
7
  function createPaginatedResponseSchema(itemSchema) {
18
8
  return z.object({
19
- meta: MetaSchema.default(() => MetaSchema.parse({})),
20
9
  pageNumber: z.number().min(1).describe("Current page number, starting from 1"),
21
10
  pageSize: z.number().min(1).describe("Number of items per page"),
22
11
  totalCount: z.number().min(0).describe("Total number of items available"),
@@ -32,9 +21,7 @@ const ImageSchema = z.looseObject({
32
21
  });
33
22
  export {
34
23
  BaseModelSchema,
35
- CacheInformationSchema,
36
24
  ImageSchema,
37
- MetaSchema,
38
25
  PaginationOptionsSchema,
39
26
  createPaginatedResponseSchema
40
27
  };
@@ -22,7 +22,7 @@ const ProfileSchema = BaseModelSchema.extend({
22
22
  updatedAt: z.string(),
23
23
  shippingAddress: AddressSchema.optional(),
24
24
  billingAddress: AddressSchema.optional(),
25
- alternateShippingAddresses: z.array(AddressSchema)
25
+ alternateShippingAddresses: z.array(AddressSchema).default(() => [])
26
26
  });
27
27
  export {
28
28
  AddressSchema,
@@ -5,7 +5,7 @@ import { AddressSchema } from "../models/profile.model.js";
5
5
  import { CurrencySchema } from "../models/currency.model.js";
6
6
  import { MonetaryAmountSchema } from "../models/price.model.js";
7
7
  const CartMutationItemAddSchema = BaseMutationSchema.extend({
8
- cart: CartIdentifierSchema,
8
+ cart: CartIdentifierSchema.optional(),
9
9
  variant: ProductVariantIdentifierSchema,
10
10
  quantity: z.number()
11
11
  });
@@ -3,19 +3,19 @@ import { CartIdentifierSchema, AddressSchema, PaymentInstructionIdentifierSchema
3
3
  import { BaseMutationSchema } from "./base.mutation.js";
4
4
  const CheckoutMutationInitiateCheckoutSchema = BaseMutationSchema.extend({
5
5
  cart: CartSchema,
6
- billingAddress: AddressSchema.omit({ identifier: true, meta: true }).optional(),
6
+ billingAddress: AddressSchema.omit({ identifier: true }).optional(),
7
7
  notificationEmail: z.string().optional(),
8
8
  notificationPhone: z.string().optional()
9
9
  });
10
10
  const CheckoutMutationSetShippingAddressSchema = BaseMutationSchema.extend({
11
11
  checkout: CartIdentifierSchema,
12
- shippingAddress: AddressSchema.omit({ identifier: true, meta: true })
12
+ shippingAddress: AddressSchema.omit({ identifier: true })
13
13
  });
14
14
  const CheckoutMutationFinalizeCheckoutSchema = BaseMutationSchema.extend({
15
15
  checkout: CartIdentifierSchema
16
16
  });
17
17
  const CheckoutMutationAddPaymentInstructionSchema = BaseMutationSchema.extend({
18
- paymentInstruction: PaymentInstructionSchema.omit({ meta: true, status: true, identifier: true }),
18
+ paymentInstruction: PaymentInstructionSchema.omit({ status: true, identifier: true }),
19
19
  checkout: CartIdentifierSchema
20
20
  });
21
21
  const CheckoutMutationRemovePaymentInstructionSchema = BaseMutationSchema.extend({
@@ -23,7 +23,7 @@ const CheckoutMutationRemovePaymentInstructionSchema = BaseMutationSchema.extend
23
23
  checkout: CartIdentifierSchema
24
24
  });
25
25
  const CheckoutMutationSetShippingInstructionSchema = BaseMutationSchema.extend({
26
- shippingInstruction: ShippingInstructionSchema.omit({ meta: true }),
26
+ shippingInstruction: ShippingInstructionSchema,
27
27
  checkout: CartIdentifierSchema
28
28
  });
29
29
  export {
@@ -1,9 +1,37 @@
1
1
  import { z } from "zod";
2
2
  import { BaseMutationSchema } from "./base.mutation.js";
3
+ import { AddressIdentifierSchema, IdentityIdentifierSchema } from "../models/identifiers.model.js";
4
+ import { AddressSchema } from "../models/profile.model.js";
3
5
  const ProfileMutationUpdateSchema = BaseMutationSchema.extend({
4
- email: z.email(),
5
- phone: z.string()
6
+ identifier: IdentityIdentifierSchema,
7
+ email: z.email().describe("The main contact email of the profile"),
8
+ phone: z.string().describe("The main phone number of the profile")
9
+ });
10
+ const ProfileMutationAddShippingAddressSchema = BaseMutationSchema.extend({
11
+ identifier: IdentityIdentifierSchema,
12
+ address: AddressSchema
13
+ });
14
+ const ProfileMutationRemoveShippingAddressSchema = BaseMutationSchema.extend({
15
+ identifier: IdentityIdentifierSchema,
16
+ addressIdentifier: AddressIdentifierSchema
17
+ });
18
+ const ProfileMutationUpdateShippingAddressSchema = BaseMutationSchema.extend({
19
+ identifier: IdentityIdentifierSchema,
20
+ address: AddressSchema
21
+ });
22
+ const ProfileMutationMakeShippingAddressDefaultSchema = BaseMutationSchema.extend({
23
+ identifier: IdentityIdentifierSchema,
24
+ addressIdentifier: AddressIdentifierSchema
25
+ });
26
+ const ProfileMutationSetBillingAddressSchema = BaseMutationSchema.extend({
27
+ identifier: IdentityIdentifierSchema,
28
+ address: AddressSchema
6
29
  });
7
30
  export {
8
- ProfileMutationUpdateSchema
31
+ ProfileMutationAddShippingAddressSchema,
32
+ ProfileMutationMakeShippingAddressDefaultSchema,
33
+ ProfileMutationRemoveShippingAddressSchema,
34
+ ProfileMutationSetBillingAddressSchema,
35
+ ProfileMutationUpdateSchema,
36
+ ProfileMutationUpdateShippingAddressSchema
9
37
  };
@@ -1,5 +1,8 @@
1
1
  import { BaseQuerySchema } from "./base.query.js";
2
- const ProfileQuerySelfSchema = BaseQuerySchema.extend({});
2
+ import { IdentityIdentifierSchema } from "../models/identifiers.model.js";
3
+ const ProfileQueryByIdSchema = BaseQuerySchema.extend({
4
+ identifier: IdentityIdentifierSchema
5
+ });
3
6
  export {
4
- ProfileQuerySelfSchema
7
+ ProfileQueryByIdSchema
5
8
  };
@@ -0,0 +1,51 @@
1
+ import { trace } from "@opentelemetry/api";
2
+ function assertSuccess(result) {
3
+ if (!result.success) {
4
+ throw new Error(
5
+ `Expected Result.success = true, but got false. Error: ${result.error}`
6
+ );
7
+ }
8
+ }
9
+ function assertError(result) {
10
+ if (result.success) {
11
+ throw new Error(`Expected failure but got success: ${result.value}`);
12
+ }
13
+ }
14
+ function unwrapValue(result) {
15
+ assertSuccess(result);
16
+ return result.value;
17
+ }
18
+ function unwrapError(result) {
19
+ assertError(result);
20
+ return result.error;
21
+ }
22
+ function success(value) {
23
+ return {
24
+ success: true,
25
+ value,
26
+ meta: {
27
+ trace: trace.getActiveSpan()?.spanContext().traceId || "",
28
+ cache: {
29
+ hit: false,
30
+ key: ""
31
+ }
32
+ }
33
+ };
34
+ }
35
+ function error(error2) {
36
+ return {
37
+ success: false,
38
+ error: error2,
39
+ meta: {
40
+ trace: trace.getActiveSpan()?.spanContext().traceId || ""
41
+ }
42
+ };
43
+ }
44
+ export {
45
+ assertError,
46
+ assertSuccess,
47
+ error,
48
+ success,
49
+ unwrapError,
50
+ unwrapValue
51
+ };
@@ -1,4 +1,5 @@
1
1
  import type { BaseModel } from '../schemas/models/index.js';
2
+ import type { Result } from '../schemas/result.js';
2
3
  import type { Cache, CacheEntryOptions } from './cache.interface.js';
3
4
  import type z from 'zod';
4
5
  /**
@@ -13,7 +14,7 @@ export declare class MemoryCache implements Cache {
13
14
  }[];
14
15
  protected meter: import("../metrics/metrics.js").ReactionaryCacheMetrics;
15
16
  get<T extends BaseModel>(key: string, schema: z.ZodType<T>): Promise<T | null>;
16
- put(key: string, value: unknown, options: CacheEntryOptions): Promise<void>;
17
+ put(key: string, value: Result<unknown>, options: CacheEntryOptions): Promise<void>;
17
18
  invalidate(dependencyIds: Array<string>): Promise<void>;
18
19
  clear(): Promise<void>;
19
20
  }
@@ -1,6 +1,7 @@
1
1
  import type { Tracer } from '@opentelemetry/api';
2
2
  import type { z } from 'zod';
3
3
  import type { BaseProvider } from '../providers/index.js';
4
+ import { type Result } from '../schemas/result.js';
4
5
  export declare function getTracer(): Tracer;
5
6
  /**
6
7
  * The options associated with annotating a provider function and marking
@@ -46,11 +47,11 @@ export declare function Reactionary(options: Partial<ReactionaryDecoratorOptions
46
47
  /**
47
48
  * Utility function to handle input validation.
48
49
  */
49
- export declare function validateInput(input: any, schema: z.ZodType | undefined): any;
50
+ export declare function validateInput<T>(input: T, schema: z.ZodType | undefined): Result<T>;
50
51
  /**
51
52
  * Utility function to handle output validation.
52
53
  */
53
- export declare function validateOutput(output: any, schema: z.ZodType | undefined): any;
54
+ export declare function validateOutput(output: Result<unknown>, schema: z.ZodType | undefined): Result<unknown>;
54
55
  /**
55
56
  * Utility function to wrap entry / exit into decorated functions in a
56
57
  * traced span for OTEL handling.
@@ -1,6 +1,5 @@
1
1
  import type { Cache } from '../cache/cache.interface.js';
2
2
  import { type RequestContext } from '../schemas/session.schema.js';
3
- import type { IdentifierType } from '../schemas/models/identifiers.model.js';
4
3
  /**
5
4
  * Base capability provider, responsible for mutations (changes) and queries (fetches)
6
5
  * for a given business object domain.
@@ -11,8 +10,6 @@ export declare abstract class BaseProvider {
11
10
  constructor(cache: Cache, context: RequestContext);
12
11
  generateDependencyIdsForModel(model: unknown): Array<string>;
13
12
  protected generateCacheKeyForQuery(scope: string, query: object): string;
14
- protected generateCacheKeyPaginatedResult(resultSetName: string, res: any): string;
15
- protected generateCacheKeySingle(identifier: IdentifierType): string;
16
13
  /**
17
14
  * Returns the abstract resource name provided by the remote system.
18
15
  */
@@ -1,7 +1,9 @@
1
+ import type { NotFoundError } from "../schemas/index.js";
1
2
  import type { Cart } from "../schemas/models/cart.model.js";
2
3
  import type { CartIdentifier } from "../schemas/models/identifiers.model.js";
3
4
  import type { CartMutationApplyCoupon, CartMutationChangeCurrency, CartMutationDeleteCart, CartMutationItemAdd, CartMutationItemQuantityChange, CartMutationItemRemove, CartMutationRemoveCoupon } from "../schemas/mutations/cart.mutation.js";
4
5
  import type { CartQueryById } from "../schemas/queries/cart.query.js";
6
+ import type { Result } from "../schemas/result.js";
5
7
  import { BaseProvider } from "./base.provider.js";
6
8
  export declare abstract class CartProvider extends BaseProvider {
7
9
  /**
@@ -11,14 +13,14 @@ export declare abstract class CartProvider extends BaseProvider {
11
13
  * @param payload
12
14
  * @param session
13
15
  */
14
- abstract getById(payload: CartQueryById): Promise<Cart>;
16
+ abstract getById(payload: CartQueryById): Promise<Result<Cart, NotFoundError>>;
15
17
  /**
16
18
  * Get the active cart id for the user.
17
19
  *
18
20
  * Usecase: Most common usecase during site load, or after login. You want to get the active cart for the user, so you can display it in the minicart.
19
21
  * @param session
20
22
  */
21
- abstract getActiveCartId(): Promise<CartIdentifier>;
23
+ abstract getActiveCartId(): Promise<Result<CartIdentifier, NotFoundError>>;
22
24
  /**
23
25
  * Add item to cart. If no cart exists, create a new one. Returns the updated and recalculated cart.
24
26
  * Does not automatically consolidate items, so if you want to have second add of same item to increase quantity,
@@ -28,7 +30,7 @@ export declare abstract class CartProvider extends BaseProvider {
28
30
  * @param payload
29
31
  * @param session
30
32
  */
31
- abstract add(payload: CartMutationItemAdd): Promise<Cart>;
33
+ abstract add(payload: CartMutationItemAdd): Promise<Result<Cart>>;
32
34
  /**
33
35
  * Remove item from cart. If the cart is empty after removal, delete the cart. Returns the updated and recalculated cart.
34
36
  *
@@ -36,7 +38,7 @@ export declare abstract class CartProvider extends BaseProvider {
36
38
  * @param payload
37
39
  * @param session
38
40
  */
39
- abstract remove(payload: CartMutationItemRemove): Promise<Cart>;
41
+ abstract remove(payload: CartMutationItemRemove): Promise<Result<Cart>>;
40
42
  /**
41
43
  * Change quantity of item in cart. If the cart is empty after change, delete the cart. Returns the updated and recalculated cart.
42
44
  * Changing quantity to 0 is not allowed. Use the remove call instead. This is done to avoid accidental removal of item.
@@ -46,7 +48,7 @@ export declare abstract class CartProvider extends BaseProvider {
46
48
  * @param payload
47
49
  * @param session
48
50
  */
49
- abstract changeQuantity(payload: CartMutationItemQuantityChange): Promise<Cart>;
51
+ abstract changeQuantity(payload: CartMutationItemQuantityChange): Promise<Result<Cart>>;
50
52
  /**
51
53
  * Deletes the entire cart.
52
54
  *
@@ -54,7 +56,7 @@ export declare abstract class CartProvider extends BaseProvider {
54
56
  * @param payload
55
57
  * @param session
56
58
  */
57
- abstract deleteCart(payload: CartMutationDeleteCart): Promise<Cart>;
59
+ abstract deleteCart(payload: CartMutationDeleteCart): Promise<Result<void>>;
58
60
  /**
59
61
  * Applies a coupon code to the cart. Returns the updated and recalculated cart.
60
62
  *
@@ -62,7 +64,7 @@ export declare abstract class CartProvider extends BaseProvider {
62
64
  * @param payload
63
65
  * @param session
64
66
  */
65
- abstract applyCouponCode(payload: CartMutationApplyCoupon): Promise<Cart>;
67
+ abstract applyCouponCode(payload: CartMutationApplyCoupon): Promise<Result<Cart>>;
66
68
  /**
67
69
  * Removes a coupon code from the cart. Returns the updated and recalculated cart.
68
70
  *
@@ -70,7 +72,7 @@ export declare abstract class CartProvider extends BaseProvider {
70
72
  * @param payload
71
73
  * @param session
72
74
  */
73
- abstract removeCouponCode(payload: CartMutationRemoveCoupon): Promise<Cart>;
75
+ abstract removeCouponCode(payload: CartMutationRemoveCoupon): Promise<Result<Cart>>;
74
76
  /**
75
77
  * Changes the currency of the cart.
76
78
  *
@@ -78,7 +80,6 @@ export declare abstract class CartProvider extends BaseProvider {
78
80
  * @param newCurrency
79
81
  * @param session
80
82
  */
81
- abstract changeCurrency(payload: CartMutationChangeCurrency): Promise<Cart>;
82
- protected createEmptyCart(): Cart;
83
+ abstract changeCurrency(payload: CartMutationChangeCurrency): Promise<Result<Cart>>;
83
84
  protected getResourceName(): string;
84
85
  }