@reactionary/provider-fake 0.3.18 → 0.6.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 (69) hide show
  1. package/core/initialize.js +193 -37
  2. package/core/initialize.types.js +8 -0
  3. package/factories/cart/cart.factory.js +15 -0
  4. package/factories/category/category.factory.js +15 -0
  5. package/factories/checkout/checkout.factory.js +19 -0
  6. package/factories/identity/identity.factory.js +11 -0
  7. package/factories/index.js +14 -0
  8. package/factories/inventory/inventory.factory.js +11 -0
  9. package/factories/order/order.factory.js +11 -0
  10. package/factories/order-search/order-search.factory.js +11 -0
  11. package/factories/price/price.factory.js +11 -0
  12. package/factories/product/product.factory.js +11 -0
  13. package/factories/product-associations/product-associations.factory.js +11 -0
  14. package/factories/product-reviews/product-reviews.factory.js +19 -0
  15. package/factories/product-search/product-search.factory.js +11 -0
  16. package/factories/profile/profile.factory.js +11 -0
  17. package/factories/store/store.factory.js +11 -0
  18. package/index.js +2 -0
  19. package/package.json +2 -2
  20. package/providers/cart.provider.js +7 -6
  21. package/providers/category.provider.js +57 -74
  22. package/providers/checkout.provider.js +15 -10
  23. package/providers/identity.provider.js +15 -17
  24. package/providers/inventory.provider.js +11 -15
  25. package/providers/order-search.provider.js +4 -3
  26. package/providers/order.provider.js +9 -32
  27. package/providers/price.provider.js +9 -15
  28. package/providers/product-associations.provider.js +6 -5
  29. package/providers/product-reviews.provider.js +30 -29
  30. package/providers/product-search.provider.js +14 -29
  31. package/providers/product.provider.js +13 -14
  32. package/providers/profile.provider.js +37 -33
  33. package/providers/store.provider.js +21 -15
  34. package/schema/capabilities.schema.js +21 -0
  35. package/src/core/initialize.d.ts +3 -2
  36. package/src/core/initialize.types.d.ts +113 -0
  37. package/src/factories/cart/cart.factory.d.ts +9 -0
  38. package/src/factories/category/category.factory.d.ts +9 -0
  39. package/src/factories/checkout/checkout.factory.d.ts +11 -0
  40. package/src/factories/identity/identity.factory.d.ts +7 -0
  41. package/src/factories/index.d.ts +14 -0
  42. package/src/factories/inventory/inventory.factory.d.ts +7 -0
  43. package/src/factories/order/order.factory.d.ts +7 -0
  44. package/src/factories/order-search/order-search.factory.d.ts +7 -0
  45. package/src/factories/price/price.factory.d.ts +9 -0
  46. package/src/factories/product/product.factory.d.ts +7 -0
  47. package/src/factories/product-associations/product-associations.factory.d.ts +7 -0
  48. package/src/factories/product-reviews/product-reviews.factory.d.ts +11 -0
  49. package/src/factories/product-search/product-search.factory.d.ts +7 -0
  50. package/src/factories/profile/profile.factory.d.ts +7 -0
  51. package/src/factories/store/store.factory.d.ts +7 -0
  52. package/src/index.d.ts +2 -0
  53. package/src/providers/cart.provider.d.ts +12 -10
  54. package/src/providers/category.provider.d.ts +12 -11
  55. package/src/providers/checkout.provider.d.ts +14 -12
  56. package/src/providers/identity.provider.d.ts +9 -7
  57. package/src/providers/inventory.provider.d.ts +6 -4
  58. package/src/providers/order-search.provider.d.ts +6 -4
  59. package/src/providers/order.provider.d.ts +6 -4
  60. package/src/providers/price.provider.d.ts +7 -5
  61. package/src/providers/product-associations.provider.d.ts +9 -6
  62. package/src/providers/product-reviews.provider.d.ts +8 -7
  63. package/src/providers/product-search.provider.d.ts +6 -9
  64. package/src/providers/product.provider.d.ts +9 -7
  65. package/src/providers/profile.provider.d.ts +14 -20
  66. package/src/providers/store.provider.d.ts +6 -4
  67. package/src/schema/capabilities.schema.d.ts +115 -16
  68. package/src/test/client-builder-product-extension.example.d.ts +1 -0
  69. package/test/client-builder-product-extension.example.js +57 -0
@@ -10,37 +10,35 @@ var __decorateClass = (decorators, target, key, kind) => {
10
10
  return result;
11
11
  };
12
12
  import {
13
+ ProductRatingSummarySchema,
14
+ ProductReviewPaginatedResultSchema,
15
+ ProductReviewSchema,
13
16
  ProductReviewsProvider,
14
17
  Reactionary,
15
- success,
16
18
  error,
17
- ProductReviewSchema,
18
- ProductRatingSummarySchema,
19
- ProductReviewPaginatedResultSchema
19
+ success
20
20
  } from "@reactionary/core";
21
21
  import { base, en, Faker } from "@faker-js/faker";
22
22
  import { calcSeed } from "../utilities/seed.js";
23
23
  class FakeProductReviewsProvider extends ProductReviewsProvider {
24
- constructor(config, cache, context) {
24
+ constructor(config, cache, context, factory) {
25
25
  super(cache, context);
26
26
  this.config = config;
27
- this.faker = new Faker({ locale: [en] });
27
+ this.factory = factory;
28
+ this.faker = new Faker({ locale: [en, base] });
28
29
  }
29
30
  createReviewsForProduct(productIdentifier) {
30
31
  const seed = calcSeed(productIdentifier.key);
31
32
  this.faker.seed(seed);
32
33
  const hasAnyReviews = this.faker.datatype.boolean({ probability: 0.5 });
33
- if (!hasAnyReviews) {
34
- return [];
35
- }
36
- if (productIdentifier.key === "unknown-product-id") {
34
+ if (!hasAnyReviews || productIdentifier.key === "unknown-product-id") {
37
35
  return [];
38
36
  }
39
37
  const reviews = [];
40
38
  const totalReviews = this.faker.number.int({ min: 1, max: 20 });
41
39
  for (let i = 0; i < totalReviews; i++) {
42
40
  const hasReply = this.faker.datatype.boolean({ probability: 0.3 });
43
- const review = {
41
+ reviews.push({
44
42
  identifier: {
45
43
  key: `fake-review-${productIdentifier.key}-${i}`
46
44
  },
@@ -55,53 +53,56 @@ class FakeProductReviewsProvider extends ProductReviewsProvider {
55
53
  verified: this.faker.datatype.boolean(),
56
54
  reply: hasReply ? this.faker.lorem.sentences(2) : void 0,
57
55
  repliedAt: hasReply ? this.faker.date.recent({ days: 7 }).toISOString() : void 0
58
- };
59
- reviews.push(review);
56
+ });
60
57
  }
61
- return reviews.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
58
+ return reviews.sort(
59
+ (a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
60
+ );
62
61
  }
63
62
  async getRatingSummary(query) {
64
63
  const reviews = this.createReviewsForProduct(query.product);
65
64
  if (reviews.length === 0) {
66
65
  const emptySummary = this.createEmptyProductRatingSummary({ product: query.product });
67
- return success(emptySummary);
66
+ return success(this.factory.parseRatingSummary(this.context, emptySummary));
68
67
  }
69
68
  const totalRatings = reviews.length;
70
- const averageRating = reviews.reduce((sum, review) => sum + review.rating, 0) / (totalRatings || 1);
71
- const ratingDistribution = {
72
- "1": reviews.filter((x) => x.rating === 1).length,
73
- "2": reviews.filter((x) => x.rating === 2).length,
74
- "3": reviews.filter((x) => x.rating === 3).length,
75
- "4": reviews.filter((x) => x.rating === 4).length,
76
- "5": reviews.filter((x) => x.rating === 5).length
77
- };
69
+ const averageRating = reviews.reduce((sum, review) => sum + review.rating, 0) / totalRatings;
78
70
  const summary = {
79
71
  identifier: {
80
72
  product: query.product
81
73
  },
82
74
  averageRating,
83
75
  totalRatings,
84
- ratingDistribution
76
+ ratingDistribution: {
77
+ "1": reviews.filter((x) => x.rating === 1).length,
78
+ "2": reviews.filter((x) => x.rating === 2).length,
79
+ "3": reviews.filter((x) => x.rating === 3).length,
80
+ "4": reviews.filter((x) => x.rating === 4).length,
81
+ "5": reviews.filter((x) => x.rating === 5).length
82
+ }
85
83
  };
86
- return success(summary);
84
+ return success(this.factory.parseRatingSummary(this.context, summary));
87
85
  }
88
86
  async findReviews(query) {
89
87
  const pageSize = query.paginationOptions?.pageSize ?? 20;
90
88
  const pageNumber = query.paginationOptions?.pageNumber ?? 1;
91
89
  const reviews = this.createReviewsForProduct(query.product);
92
90
  const returnedReviews = reviews.slice((pageNumber - 1) * pageSize, pageNumber * pageSize);
93
- const paginatedResult = {
91
+ const result = {
94
92
  items: returnedReviews,
95
93
  totalCount: reviews.length,
96
94
  pageSize,
97
95
  pageNumber,
98
96
  totalPages: Math.ceil(reviews.length / Math.max(pageSize, 1))
99
97
  };
100
- return success(paginatedResult);
98
+ return success(this.factory.parseReviewPaginatedResult(this.context, result));
101
99
  }
102
100
  async submitReview(mutation) {
103
101
  if (this.context.session.identityContext.identity.type !== "Registered") {
104
- return error({ type: "InvalidInput", error: "Only registered users can submit reviews." });
102
+ return error({
103
+ type: "InvalidInput",
104
+ error: "Only registered users can submit reviews."
105
+ });
105
106
  }
106
107
  const review = {
107
108
  identifier: {
@@ -115,7 +116,7 @@ class FakeProductReviewsProvider extends ProductReviewsProvider {
115
116
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
116
117
  verified: this.faker.datatype.boolean()
117
118
  };
118
- return success(review);
119
+ return success(this.factory.parseReview(this.context, review));
119
120
  }
120
121
  }
121
122
  __decorateClass([
@@ -16,28 +16,23 @@ import {
16
16
  ProductSearchResultItemSchema,
17
17
  ProductSearchResultSchema,
18
18
  Reactionary,
19
- success,
20
- error
19
+ success
21
20
  } from "@reactionary/core";
22
21
  import { Faker, en, base } from "@faker-js/faker";
23
22
  import { jitter } from "../utilities/jitter.js";
24
23
  class FakeSearchProvider extends ProductSearchProvider {
25
- constructor(config, cache, context) {
24
+ constructor(config, cache, context, factory) {
26
25
  super(cache, context);
27
26
  this.config = config;
27
+ this.factory = factory;
28
28
  }
29
29
  async queryByTerm(payload) {
30
30
  await jitter(this.config.jitter.mean, this.config.jitter.deviation);
31
31
  const query = payload.search;
32
32
  const querySpecificity = 20 - query.term.length - query.paginationOptions.pageNumber - query.facets.length;
33
33
  const totalProducts = 10 * querySpecificity;
34
- const totalPages = Math.ceil(
35
- totalProducts / query.paginationOptions.pageSize
36
- );
37
- const productsOnPage = Math.min(
38
- totalProducts,
39
- query.paginationOptions.pageSize
40
- );
34
+ const totalPages = Math.ceil(totalProducts / query.paginationOptions.pageSize);
35
+ const productsOnPage = Math.min(totalProducts, query.paginationOptions.pageSize);
41
36
  const productGenerator = new Faker({
42
37
  seed: querySpecificity,
43
38
  locale: [en, base]
@@ -46,8 +41,8 @@ class FakeSearchProvider extends ProductSearchProvider {
46
41
  seed: 100,
47
42
  locale: [en, base]
48
43
  });
49
- const products = new Array();
50
- const facets = new Array();
44
+ const products = [];
45
+ const facets = [];
51
46
  for (let i = 0; i < productsOnPage; i++) {
52
47
  const srcUrl = productGenerator.image.urlPicsumPhotos({
53
48
  height: 300,
@@ -64,7 +59,7 @@ class FakeSearchProvider extends ProductSearchProvider {
64
59
  products.push(
65
60
  ProductSearchResultItemSchema.parse({
66
61
  identifier: {
67
- key: "product_" + productGenerator.commerce.isbn()
62
+ key: `product_${productGenerator.commerce.isbn()}`
68
63
  },
69
64
  name: productGenerator.commerce.productName(),
70
65
  slug: productGenerator.lorem.slug(),
@@ -80,13 +75,12 @@ class FakeSearchProvider extends ProductSearchProvider {
80
75
  })
81
76
  );
82
77
  }
83
- const facetBase = ["color", "size"];
84
- for (const base2 of facetBase) {
78
+ for (const baseFacet of ["color", "size"]) {
85
79
  const facet = {
86
80
  identifier: {
87
- key: base2
81
+ key: baseFacet
88
82
  },
89
- name: base2,
83
+ name: baseFacet,
90
84
  values: []
91
85
  };
92
86
  for (let i = 0; i < 10; i++) {
@@ -108,7 +102,7 @@ class FakeSearchProvider extends ProductSearchProvider {
108
102
  }
109
103
  facets.push(facet);
110
104
  }
111
- const result = ProductSearchResultSchema.parse({
105
+ const result = {
112
106
  identifier: {
113
107
  term: query.term,
114
108
  paginationOptions: {
@@ -124,8 +118,8 @@ class FakeSearchProvider extends ProductSearchProvider {
124
118
  pageSize: query.paginationOptions.pageSize,
125
119
  totalCount: totalProducts,
126
120
  totalPages
127
- });
128
- return success(result);
121
+ };
122
+ return success(this.factory.parseSearchResult(this.context, result, payload));
129
123
  }
130
124
  async createCategoryNavigationFilter(payload) {
131
125
  const facetIdentifier = {
@@ -137,15 +131,6 @@ class FakeSearchProvider extends ProductSearchProvider {
137
131
  };
138
132
  return success(facetValueIdentifier);
139
133
  }
140
- parseFacetValue(facetValueIdentifier, label, count) {
141
- throw new Error("Method not implemented.");
142
- }
143
- parseFacet(facetIdentifier, facetValue) {
144
- throw new Error("Method not implemented.");
145
- }
146
- parseVariant(variant, product) {
147
- throw new Error("Method not implemented.");
148
- }
149
134
  }
150
135
  __decorateClass([
151
136
  Reactionary({
@@ -10,42 +10,41 @@ var __decorateClass = (decorators, target, key, kind) => {
10
10
  return result;
11
11
  };
12
12
  import {
13
- ProductProvider,
14
- Reactionary,
15
13
  ProductQueryByIdSchema,
16
- ProductSchema,
17
- ProductQueryBySlugSchema,
18
14
  ProductQueryBySKUSchema,
19
- error,
15
+ ProductQueryBySlugSchema,
16
+ ProductProvider,
17
+ ProductSchema,
18
+ Reactionary,
20
19
  success
21
20
  } from "@reactionary/core";
22
21
  import { base, en, Faker } from "@faker-js/faker";
23
22
  class FakeProductProvider extends ProductProvider {
24
- constructor(config, cache, context) {
23
+ constructor(config, cache, context, factory) {
25
24
  super(cache, context);
26
25
  this.config = config;
26
+ this.factory = factory;
27
27
  }
28
28
  async getById(payload) {
29
- return success(this.parseSingle(payload.identifier.key));
29
+ return success(this.composeSingle(payload.identifier.key));
30
30
  }
31
31
  async getBySlug(payload) {
32
- return success(this.parseSingle(payload.slug));
32
+ return success(this.composeSingle(payload.slug));
33
33
  }
34
34
  async getBySKU(payload) {
35
- return success(this.parseSingle(payload.variant.sku));
35
+ return success(this.composeSingle(payload.variant.sku));
36
36
  }
37
- parseSingle(body) {
37
+ composeSingle(body) {
38
38
  const generator = new Faker({
39
39
  seed: 42,
40
40
  locale: [en, base]
41
41
  });
42
- const key = body;
43
42
  const result = {
44
43
  identifier: {
45
- key
44
+ key: body
46
45
  },
47
46
  name: generator.commerce.productName(),
48
- slug: key,
47
+ slug: body,
49
48
  brand: "",
50
49
  longDescription: "",
51
50
  mainVariant: {
@@ -68,7 +67,7 @@ class FakeProductProvider extends ProductProvider {
68
67
  sharedAttributes: [],
69
68
  variants: []
70
69
  };
71
- return result;
70
+ return this.factory.parseProduct(this.context, result);
72
71
  }
73
72
  }
74
73
  __decorateClass([
@@ -10,6 +10,7 @@ var __decorateClass = (decorators, target, key, kind) => {
10
10
  return result;
11
11
  };
12
12
  import {
13
+ AddressSchema,
13
14
  ProfileMutationAddShippingAddressSchema,
14
15
  ProfileMutationMakeShippingAddressDefaultSchema,
15
16
  ProfileMutationRemoveShippingAddressSchema,
@@ -24,69 +25,72 @@ import {
24
25
  } from "@reactionary/core";
25
26
  import { base, en, Faker } from "@faker-js/faker";
26
27
  class FakeProfileProvider extends ProfileProvider {
27
- constructor(config, cache, context) {
28
+ constructor(config, cache, context, factory) {
28
29
  super(cache, context);
29
30
  this.generator = new Faker({
30
31
  locale: [en, base],
31
32
  seed: config.seeds.product
32
33
  });
33
34
  this.config = config;
35
+ this.factory = factory;
34
36
  }
35
37
  async getById(payload) {
36
- const profile = this.composeBaseProfile(payload.identifier);
37
- return success(profile);
38
+ return success(this.composeProfile(payload.identifier));
38
39
  }
39
40
  async update(payload) {
40
- const profile = this.composeBaseProfile(payload.identifier);
41
- return success(profile);
41
+ return success(this.composeProfile(payload.identifier));
42
42
  }
43
43
  async addShippingAddress(payload) {
44
- const profile = this.composeBaseProfile(payload.identifier);
45
- return success(profile);
44
+ return success(this.composeProfile(payload.identifier));
46
45
  }
47
46
  async updateShippingAddress(payload) {
48
- const profile = this.composeBaseProfile(payload.identifier);
49
- return success(profile);
47
+ return success(this.composeProfile(payload.identifier));
50
48
  }
51
49
  async removeShippingAddress(payload) {
52
- const profile = this.composeBaseProfile(payload.identifier);
53
- return success(profile);
50
+ return success(this.composeProfile(payload.identifier));
54
51
  }
55
52
  async makeShippingAddressDefault(payload) {
56
- const profile = this.composeBaseProfile(payload.identifier);
57
- return success(profile);
53
+ return success(this.composeProfile(payload.identifier));
58
54
  }
59
55
  async setBillingAddress(payload) {
60
- const profile = this.composeBaseProfile(payload.identifier);
61
- return success(profile);
56
+ return success(this.composeProfile(payload.identifier));
62
57
  }
63
- composeBaseProfile(identifier) {
64
- const profile = {
65
- alternateShippingAddresses: [],
66
- createdAt: this.generator.date.past().toISOString(),
58
+ composeProfile(identifier) {
59
+ const baseProfile = {
60
+ identifier,
67
61
  email: this.generator.internet.email(),
68
- emailVerified: true,
69
- identifier: identifier || {
70
- userId: this.generator.string.uuid()
71
- },
72
62
  phone: this.generator.phone.number(),
63
+ emailVerified: true,
73
64
  phoneVerified: true,
74
- updatedAt: this.generator.date.past().toISOString()
65
+ createdAt: this.generator.date.past().toISOString(),
66
+ updatedAt: this.generator.date.recent().toISOString(),
67
+ billingAddress: this.createEmptyAddress(),
68
+ shippingAddress: this.createEmptyAddress(),
69
+ alternateShippingAddresses: []
75
70
  };
76
- return profile;
71
+ return this.factory.parseProfile(this.context, baseProfile);
72
+ }
73
+ createEmptyAddress() {
74
+ return AddressSchema.parse({
75
+ identifier: {
76
+ nickName: this.generator.person.firstName().toLowerCase()
77
+ },
78
+ firstName: this.generator.person.firstName(),
79
+ lastName: this.generator.person.lastName(),
80
+ streetAddress: this.generator.location.street(),
81
+ streetNumber: this.generator.location.buildingNumber(),
82
+ city: this.generator.location.city(),
83
+ region: this.generator.location.state(),
84
+ postalCode: this.generator.location.zipCode(),
85
+ countryCode: this.generator.location.countryCode("alpha-2")
86
+ });
77
87
  }
78
88
  }
79
89
  __decorateClass([
80
- Reactionary({
81
- inputSchema: ProfileQueryByIdSchema,
82
- outputSchema: ProfileSchema
83
- })
90
+ Reactionary({ inputSchema: ProfileQueryByIdSchema, outputSchema: ProfileSchema })
84
91
  ], FakeProfileProvider.prototype, "getById", 1);
85
92
  __decorateClass([
86
- Reactionary({
87
- inputSchema: ProfileMutationUpdateSchema,
88
- outputSchema: ProfileSchema
89
- })
93
+ Reactionary({ inputSchema: ProfileMutationUpdateSchema, outputSchema: ProfileSchema })
90
94
  ], FakeProfileProvider.prototype, "update", 1);
91
95
  __decorateClass([
92
96
  Reactionary({
@@ -9,33 +9,39 @@ var __decorateClass = (decorators, target, key, kind) => {
9
9
  __defProp(target, key, result);
10
10
  return result;
11
11
  };
12
- import { Reactionary, StoreProvider, StoreQueryByProximitySchema, StoreSchema, success } from "@reactionary/core";
12
+ import {
13
+ Reactionary,
14
+ StoreProvider,
15
+ StoreQueryByProximitySchema,
16
+ StoreSchema,
17
+ success
18
+ } from "@reactionary/core";
13
19
  import * as z from "zod";
14
20
  import { base, en, Faker } from "@faker-js/faker";
15
21
  class FakeStoreProvider extends StoreProvider {
16
- constructor(config, cache, context) {
22
+ constructor(config, cache, context, factory) {
17
23
  super(cache, context);
18
24
  this.config = config;
25
+ this.factory = factory;
19
26
  }
20
27
  async queryByProximity(payload) {
21
28
  const generator = new Faker({
22
29
  seed: 42,
23
30
  locale: [en, base]
24
31
  });
25
- const results = new Array();
32
+ const results = [];
26
33
  for (let i = 0; i < payload.limit; i++) {
27
- const name = generator.company.name();
28
- const identifier = {
29
- key: "" + i
30
- };
31
- const fulfillmentCenter = {
32
- key: "" + i
33
- };
34
- results.push({
35
- fulfillmentCenter,
36
- identifier,
37
- name
38
- });
34
+ results.push(
35
+ this.factory.parseStore(this.context, {
36
+ identifier: {
37
+ key: `${i}`
38
+ },
39
+ fulfillmentCenter: {
40
+ key: `${i}`
41
+ },
42
+ name: generator.company.name()
43
+ })
44
+ );
39
45
  }
40
46
  return success(results);
41
47
  }
@@ -1,4 +1,10 @@
1
1
  import { CapabilitiesSchema } from "@reactionary/core";
2
+ import * as z from "zod";
3
+ const OverridableCapabilitySchema = z.looseObject({
4
+ enabled: z.boolean(),
5
+ factory: z.unknown().optional(),
6
+ provider: z.unknown().optional()
7
+ });
2
8
  const FakeCapabilitiesSchema = CapabilitiesSchema.pick({
3
9
  product: true,
4
10
  productSearch: true,
@@ -14,6 +20,21 @@ const FakeCapabilitiesSchema = CapabilitiesSchema.pick({
14
20
  profile: true,
15
21
  productReviews: true,
16
22
  productAssociations: true
23
+ }).extend({
24
+ product: OverridableCapabilitySchema.optional(),
25
+ productSearch: OverridableCapabilitySchema.optional(),
26
+ identity: OverridableCapabilitySchema.optional(),
27
+ category: OverridableCapabilitySchema.optional(),
28
+ cart: OverridableCapabilitySchema.optional(),
29
+ inventory: OverridableCapabilitySchema.optional(),
30
+ store: OverridableCapabilitySchema.optional(),
31
+ price: OverridableCapabilitySchema.optional(),
32
+ checkout: OverridableCapabilitySchema.optional(),
33
+ order: OverridableCapabilitySchema.optional(),
34
+ orderSearch: OverridableCapabilitySchema.optional(),
35
+ profile: OverridableCapabilitySchema.optional(),
36
+ productReviews: OverridableCapabilitySchema.optional(),
37
+ productAssociations: OverridableCapabilitySchema.optional()
17
38
  }).partial();
18
39
  export {
19
40
  FakeCapabilitiesSchema
@@ -1,4 +1,5 @@
1
- import type { Cache as ReactinaryCache, RequestContext, ClientFromCapabilities } from '@reactionary/core';
1
+ import type { Cache as ReactinaryCache, RequestContext } from '@reactionary/core';
2
2
  import type { FakeConfiguration } from '../schema/configuration.schema.js';
3
3
  import type { FakeCapabilities } from '../schema/capabilities.schema.js';
4
- export declare function withFakeCapabilities<T extends FakeCapabilities>(configuration: FakeConfiguration, capabilities: T): (cache: ReactinaryCache, context: RequestContext) => ClientFromCapabilities<T>;
4
+ import { type FakeClientFromCapabilities } from './initialize.types.js';
5
+ export declare function withFakeCapabilities<T extends FakeCapabilities>(configuration: FakeConfiguration, capabilities: T): (cache: ReactinaryCache, context: RequestContext) => FakeClientFromCapabilities<T>;
@@ -0,0 +1,113 @@
1
+ import type { CartFactory, CategoryFactory, CheckoutFactory, ClientFromCapabilities, IdentityFactory, InventoryFactory, OrderFactory, OrderSearchFactory, PriceFactory, ProductAssociationsFactory, ProductFactory, ProductReviewsFactory, ProductSearchFactory, ProfileFactory, StoreFactory } from '@reactionary/core';
2
+ import type { FakeCapabilities } from '../schema/capabilities.schema.js';
3
+ import type { FakeCartFactory } from '../factories/cart/cart.factory.js';
4
+ import type { FakeCategoryFactory } from '../factories/category/category.factory.js';
5
+ import type { FakeCheckoutFactory } from '../factories/checkout/checkout.factory.js';
6
+ import type { FakeIdentityFactory } from '../factories/identity/identity.factory.js';
7
+ import type { FakeInventoryFactory } from '../factories/inventory/inventory.factory.js';
8
+ import type { FakeOrderFactory } from '../factories/order/order.factory.js';
9
+ import type { FakeOrderSearchFactory } from '../factories/order-search/order-search.factory.js';
10
+ import type { FakePriceFactory } from '../factories/price/price.factory.js';
11
+ import type { FakeProductAssociationsFactory } from '../factories/product-associations/product-associations.factory.js';
12
+ import type { FakeProductFactory } from '../factories/product/product.factory.js';
13
+ import type { FakeProductReviewsFactory } from '../factories/product-reviews/product-reviews.factory.js';
14
+ import type { FakeProductSearchFactory } from '../factories/product-search/product-search.factory.js';
15
+ import type { FakeProfileFactory } from '../factories/profile/profile.factory.js';
16
+ import type { FakeStoreFactory } from '../factories/store/store.factory.js';
17
+ import type { FakeCartProvider } from '../providers/cart.provider.js';
18
+ import type { FakeCategoryProvider } from '../providers/category.provider.js';
19
+ import type { FakeCheckoutProvider } from '../providers/checkout.provider.js';
20
+ import type { FakeIdentityProvider } from '../providers/identity.provider.js';
21
+ import type { FakeInventoryProvider } from '../providers/inventory.provider.js';
22
+ import type { FakeOrderProvider } from '../providers/order.provider.js';
23
+ import type { FakeOrderSearchProvider } from '../providers/order-search.provider.js';
24
+ import type { FakePriceProvider } from '../providers/price.provider.js';
25
+ import type { FakeProductAssociationsProvider } from '../providers/product-associations.provider.js';
26
+ import type { FakeProductProvider } from '../providers/product.provider.js';
27
+ import type { FakeProductReviewsProvider } from '../providers/product-reviews.provider.js';
28
+ import type { FakeSearchProvider } from '../providers/product-search.provider.js';
29
+ import type { FakeProfileProvider } from '../providers/profile.provider.js';
30
+ import type { FakeStoreProvider } from '../providers/store.provider.js';
31
+ type FakeCapabilityKey = keyof FakeCapabilities;
32
+ type EnabledCapability<TCapability> = TCapability extends {
33
+ enabled: true;
34
+ } ? true : false;
35
+ type NormalizeConfiguredCapabilities<T extends FakeCapabilities> = {
36
+ [K in FakeCapabilityKey]?: EnabledCapability<T[K]>;
37
+ };
38
+ type ExtractCapabilityFactory<TCapability, TContract, TDefaultFactory> = TCapability extends {
39
+ enabled: true;
40
+ factory?: infer TFactory;
41
+ } ? TFactory extends TContract ? TFactory : TDefaultFactory : TDefaultFactory;
42
+ type ExtractCapabilityProvider<TCapability, TDefaultProvider> = TCapability extends {
43
+ enabled: true;
44
+ provider?: infer TProviderFactory;
45
+ } ? TProviderFactory extends (...args: unknown[]) => infer TProvider ? TProvider : TDefaultProvider : TDefaultProvider;
46
+ type FactoryContractMap = {
47
+ product: ProductFactory;
48
+ productSearch: ProductSearchFactory;
49
+ identity: IdentityFactory;
50
+ category: CategoryFactory;
51
+ cart: CartFactory;
52
+ inventory: InventoryFactory;
53
+ store: StoreFactory;
54
+ price: PriceFactory;
55
+ checkout: CheckoutFactory;
56
+ order: OrderFactory;
57
+ orderSearch: OrderSearchFactory;
58
+ profile: ProfileFactory;
59
+ productReviews: ProductReviewsFactory;
60
+ productAssociations: ProductAssociationsFactory;
61
+ };
62
+ type DefaultFactoryMap = {
63
+ product: FakeProductFactory;
64
+ productSearch: FakeProductSearchFactory;
65
+ identity: FakeIdentityFactory;
66
+ category: FakeCategoryFactory;
67
+ cart: FakeCartFactory;
68
+ inventory: FakeInventoryFactory;
69
+ store: FakeStoreFactory;
70
+ price: FakePriceFactory;
71
+ checkout: FakeCheckoutFactory;
72
+ order: FakeOrderFactory;
73
+ orderSearch: FakeOrderSearchFactory;
74
+ profile: FakeProfileFactory;
75
+ productReviews: FakeProductReviewsFactory;
76
+ productAssociations: FakeProductAssociationsFactory;
77
+ };
78
+ type ResolvedFactoryMap<T extends FakeCapabilities> = {
79
+ [K in FakeCapabilityKey]: ExtractCapabilityFactory<T[K], FactoryContractMap[K], DefaultFactoryMap[K]>;
80
+ };
81
+ type DefaultProviderMap<T extends FakeCapabilities> = {
82
+ product: FakeProductProvider<ResolvedFactoryMap<T>['product']>;
83
+ productSearch: FakeSearchProvider<ResolvedFactoryMap<T>['productSearch']>;
84
+ identity: FakeIdentityProvider<ResolvedFactoryMap<T>['identity']>;
85
+ category: FakeCategoryProvider<ResolvedFactoryMap<T>['category']>;
86
+ cart: FakeCartProvider<ResolvedFactoryMap<T>['cart']>;
87
+ inventory: FakeInventoryProvider<ResolvedFactoryMap<T>['inventory']>;
88
+ store: FakeStoreProvider<ResolvedFactoryMap<T>['store']>;
89
+ price: FakePriceProvider<ResolvedFactoryMap<T>['price']>;
90
+ checkout: FakeCheckoutProvider<ResolvedFactoryMap<T>['checkout']>;
91
+ order: FakeOrderProvider<ResolvedFactoryMap<T>['order']>;
92
+ orderSearch: FakeOrderSearchProvider<ResolvedFactoryMap<T>['orderSearch']>;
93
+ profile: FakeProfileProvider<ResolvedFactoryMap<T>['profile']>;
94
+ productReviews: FakeProductReviewsProvider<ResolvedFactoryMap<T>['productReviews']>;
95
+ productAssociations: FakeProductAssociationsProvider<ResolvedFactoryMap<T>['productAssociations']>;
96
+ };
97
+ type CapabilityProviderTypeMap<T extends FakeCapabilities> = {
98
+ [K in FakeCapabilityKey]: ExtractCapabilityProvider<T[K], DefaultProviderMap<T>[K]>;
99
+ };
100
+ type EnabledCapabilityOverrideMap<T extends FakeCapabilities> = {
101
+ [K in FakeCapabilityKey as T[K] extends {
102
+ enabled: true;
103
+ } ? K : never]: CapabilityProviderTypeMap<T>[K];
104
+ };
105
+ export type FakeClientFromCapabilities<T extends FakeCapabilities> = Omit<ClientFromCapabilities<NormalizeConfiguredCapabilities<T>>, FakeCapabilityKey> & EnabledCapabilityOverrideMap<T>;
106
+ export declare function resolveCapabilityProvider<TFactory, TProvider, TProviderArgs>(capability: {
107
+ factory?: TFactory;
108
+ provider?: (args: TProviderArgs) => TProvider;
109
+ } | undefined, defaults: {
110
+ factory: TFactory;
111
+ provider: (args: TProviderArgs) => TProvider;
112
+ }, buildProviderArgs: (factory: TFactory) => TProviderArgs): TProvider;
113
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { AnyCartIdentifierSchema, AnyCartSchema, CartFactory, CartIdentifierSchema, CartSchema, RequestContext } from '@reactionary/core';
2
+ import type * as z from 'zod';
3
+ export declare class FakeCartFactory<TCartSchema extends AnyCartSchema = typeof CartSchema, TCartIdentifierSchema extends AnyCartIdentifierSchema = typeof CartIdentifierSchema> implements CartFactory<TCartSchema, TCartIdentifierSchema> {
4
+ readonly cartSchema: TCartSchema;
5
+ readonly cartIdentifierSchema: TCartIdentifierSchema;
6
+ constructor(cartSchema: TCartSchema, cartIdentifierSchema: TCartIdentifierSchema);
7
+ parseCart(_context: RequestContext, data: unknown): z.output<TCartSchema>;
8
+ parseCartIdentifier(_context: RequestContext, data: unknown): z.output<TCartIdentifierSchema>;
9
+ }
@@ -0,0 +1,9 @@
1
+ import type { AnyCategoryPaginatedResultSchema, AnyCategorySchema, CategoryFactory, CategoryPaginatedResultSchema, CategorySchema, RequestContext } from '@reactionary/core';
2
+ import type * as z from 'zod';
3
+ export declare class FakeCategoryFactory<TCategorySchema extends AnyCategorySchema = typeof CategorySchema, TCategoryPaginatedSchema extends AnyCategoryPaginatedResultSchema = typeof CategoryPaginatedResultSchema> implements CategoryFactory<TCategorySchema, TCategoryPaginatedSchema> {
4
+ readonly categorySchema: TCategorySchema;
5
+ readonly categoryPaginatedResultSchema: TCategoryPaginatedSchema;
6
+ constructor(categorySchema: TCategorySchema, categoryPaginatedResultSchema: TCategoryPaginatedSchema);
7
+ parseCategory(_context: RequestContext, data: unknown): z.output<TCategorySchema>;
8
+ parseCategoryPaginatedResult(_context: RequestContext, data: unknown): z.output<TCategoryPaginatedSchema>;
9
+ }
@@ -0,0 +1,11 @@
1
+ import type { AnyCheckoutSchema, AnyPaymentMethodSchema, AnyShippingMethodSchema, CheckoutFactory, CheckoutSchema, PaymentMethodSchema, RequestContext, ShippingMethodSchema } from '@reactionary/core';
2
+ import type * as z from 'zod';
3
+ export declare class FakeCheckoutFactory<TCheckoutSchema extends AnyCheckoutSchema = typeof CheckoutSchema, TShippingMethodSchema extends AnyShippingMethodSchema = typeof ShippingMethodSchema, TPaymentMethodSchema extends AnyPaymentMethodSchema = typeof PaymentMethodSchema> implements CheckoutFactory<TCheckoutSchema, TShippingMethodSchema, TPaymentMethodSchema> {
4
+ readonly checkoutSchema: TCheckoutSchema;
5
+ readonly shippingMethodSchema: TShippingMethodSchema;
6
+ readonly paymentMethodSchema: TPaymentMethodSchema;
7
+ constructor(checkoutSchema: TCheckoutSchema, shippingMethodSchema: TShippingMethodSchema, paymentMethodSchema: TPaymentMethodSchema);
8
+ parseCheckout(_context: RequestContext, data: unknown): z.output<TCheckoutSchema>;
9
+ parseShippingMethod(_context: RequestContext, data: unknown): z.output<TShippingMethodSchema>;
10
+ parsePaymentMethod(_context: RequestContext, data: unknown): z.output<TPaymentMethodSchema>;
11
+ }
@@ -0,0 +1,7 @@
1
+ import type { AnyIdentitySchema, IdentityFactory, IdentitySchema, RequestContext } from '@reactionary/core';
2
+ import type * as z from 'zod';
3
+ export declare class FakeIdentityFactory<TIdentitySchema extends AnyIdentitySchema = typeof IdentitySchema> implements IdentityFactory<TIdentitySchema> {
4
+ readonly identitySchema: TIdentitySchema;
5
+ constructor(identitySchema: TIdentitySchema);
6
+ parseIdentity(_context: RequestContext, data: unknown): z.output<TIdentitySchema>;
7
+ }