@reactionary/provider-fake 0.3.14 → 0.3.15

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.
@@ -13,6 +13,7 @@ import { FakeOrderSearchProvider } from "../providers/order-search.provider.js";
13
13
  import { FakeOrderProvider } from "../providers/order.provider.js";
14
14
  import { FakeProfileProvider } from "../providers/profile.provider.js";
15
15
  import { FakeProductReviewsProvider } from "../providers/product-reviews.provider.js";
16
+ import { FakeProductAssociationsProvider } from "../providers/product-associations.provider.js";
16
17
  function withFakeCapabilities(configuration, capabilities) {
17
18
  return (cache, context) => {
18
19
  const client = {};
@@ -67,6 +68,9 @@ function withFakeCapabilities(configuration, capabilities) {
67
68
  if (capabilities.productReviews) {
68
69
  client.productReviews = new FakeProductReviewsProvider(configuration, cache, context);
69
70
  }
71
+ if (capabilities.productAssociations) {
72
+ client.productAssociations = new FakeProductAssociationsProvider(configuration, cache, context);
73
+ }
70
74
  return client;
71
75
  };
72
76
  }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@reactionary/provider-fake",
3
- "version": "0.3.14",
3
+ "version": "0.3.15",
4
4
  "main": "index.js",
5
5
  "types": "src/index.d.ts",
6
6
  "dependencies": {
7
- "@reactionary/core": "0.3.14",
7
+ "@reactionary/core": "0.3.15",
8
8
  "zod": "4.1.9",
9
9
  "@faker-js/faker": "^9.8.0"
10
10
  },
@@ -8,6 +8,7 @@ export * from "./order-search.provider.js";
8
8
  export * from "./order.provider.js";
9
9
  export * from "./price.provider.js";
10
10
  export * from "./product.provider.js";
11
+ export * from "./product-associations.provider.js";
11
12
  export * from "./product-reviews.provider.js";
12
13
  export * from "./product-search.provider.js";
13
14
  export * from "./profile.provider.js";
@@ -0,0 +1,117 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __decorateClass = (decorators, target, key, kind) => {
4
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
6
+ if (decorator = decorators[i])
7
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
+ if (kind && result)
9
+ __defProp(target, key, result);
10
+ return result;
11
+ };
12
+ import {
13
+ ProductAssociationsProvider,
14
+ Reactionary,
15
+ success
16
+ } from "@reactionary/core";
17
+ import { base, en, Faker } from "@faker-js/faker";
18
+ import { calcSeed } from "../utilities/seed.js";
19
+ class FakeProductAssociationsProvider extends ProductAssociationsProvider {
20
+ constructor(config, cache, context) {
21
+ super(cache, context);
22
+ this.config = config;
23
+ this.faker = new Faker({ locale: [en] });
24
+ }
25
+ async getAccessories(query) {
26
+ const associatedProducts = this.generateFakeAssociatedProducts(query.forProduct.key, query.numberOfAccessories || 4, "accessory");
27
+ const result = associatedProducts.map((product) => ({
28
+ associationIdentifier: {
29
+ key: `${query.forProduct.key}-accessory-${product.identifier.key}`
30
+ },
31
+ associationReturnType: "productSearchResultItem",
32
+ product
33
+ }));
34
+ return success(result);
35
+ }
36
+ async getSpareparts(query) {
37
+ const associatedProducts = this.generateFakeAssociatedProducts(query.forProduct.key, query.numberOfSpareparts || 4, "sparepart");
38
+ const result = associatedProducts.map((product) => ({
39
+ associationIdentifier: {
40
+ key: `${query.forProduct.key}-sparepart-${product.identifier.key}`
41
+ },
42
+ associationReturnType: "productSearchResultItem",
43
+ product
44
+ }));
45
+ return success(result);
46
+ }
47
+ async getReplacements(query) {
48
+ const associatedProducts = this.generateFakeAssociatedProducts(query.forProduct.key, query.numberOfReplacements || 4, "replacement");
49
+ const result = associatedProducts.map((product) => ({
50
+ associationIdentifier: {
51
+ key: `${query.forProduct.key}-replacement-${product.identifier.key}`
52
+ },
53
+ associationReturnType: "productSearchResultItem",
54
+ product
55
+ }));
56
+ return success(result);
57
+ }
58
+ generateFakeAssociatedProducts(baseProductKey, count, type) {
59
+ const products = [];
60
+ const seed = calcSeed(baseProductKey);
61
+ this.faker.seed(seed);
62
+ if (baseProductKey.includes("unknown")) {
63
+ return [];
64
+ }
65
+ if (baseProductKey === "product_100201") {
66
+ return [];
67
+ }
68
+ const hasAnyAssociations = this.faker.datatype.boolean({ probability: 0.5 });
69
+ if (!hasAnyAssociations) {
70
+ return [];
71
+ }
72
+ const numberOfAssociations = Math.min(count, this.faker.number.int({ min: 2, max: 12 }));
73
+ for (let i = 0; i < numberOfAssociations; i++) {
74
+ const key = `${baseProductKey}-${type}-${i + 1}`;
75
+ products.push({
76
+ identifier: { key },
77
+ name: `Fake ${type} ${i + 1} for ${baseProductKey}`,
78
+ slug: key,
79
+ variants: [{
80
+ variant: { sku: `${key}-variant` },
81
+ image: {
82
+ sourceUrl: `https://via.placeholder.com/300x300?text=${type}+${i + 1}`,
83
+ altText: `Image for ${type} ${i + 1}`
84
+ }
85
+ }]
86
+ });
87
+ }
88
+ return products;
89
+ }
90
+ }
91
+ __decorateClass([
92
+ Reactionary({
93
+ cache: true,
94
+ cacheTimeToLiveInSeconds: 300,
95
+ currencyDependentCaching: false,
96
+ localeDependentCaching: false
97
+ })
98
+ ], FakeProductAssociationsProvider.prototype, "getAccessories", 1);
99
+ __decorateClass([
100
+ Reactionary({
101
+ cache: true,
102
+ cacheTimeToLiveInSeconds: 300,
103
+ currencyDependentCaching: false,
104
+ localeDependentCaching: false
105
+ })
106
+ ], FakeProductAssociationsProvider.prototype, "getSpareparts", 1);
107
+ __decorateClass([
108
+ Reactionary({
109
+ cache: true,
110
+ cacheTimeToLiveInSeconds: 300,
111
+ currencyDependentCaching: false,
112
+ localeDependentCaching: false
113
+ })
114
+ ], FakeProductAssociationsProvider.prototype, "getReplacements", 1);
115
+ export {
116
+ FakeProductAssociationsProvider
117
+ };
@@ -12,7 +12,8 @@ const FakeCapabilitiesSchema = CapabilitiesSchema.pick({
12
12
  order: true,
13
13
  orderSearch: true,
14
14
  profile: true,
15
- productReviews: true
15
+ productReviews: true,
16
+ productAssociations: true
16
17
  }).partial();
17
18
  export {
18
19
  FakeCapabilitiesSchema
@@ -8,6 +8,7 @@ export * from './order-search.provider.js';
8
8
  export * from './order.provider.js';
9
9
  export * from './price.provider.js';
10
10
  export * from './product.provider.js';
11
+ export * from './product-associations.provider.js';
11
12
  export * from './product-reviews.provider.js';
12
13
  export * from './product-search.provider.js';
13
14
  export * from './profile.provider.js';
@@ -0,0 +1,12 @@
1
+ import { ProductAssociationsProvider, type ProductAssociationsGetAccessoriesQuery, type ProductAssociationsGetSparepartsQuery, type ProductAssociationsGetReplacementsQuery, type Result, type ProductAssociation } from '@reactionary/core';
2
+ import type { FakeConfiguration } from '../schema/configuration.schema.js';
3
+ import { Faker } from '@faker-js/faker';
4
+ export declare class FakeProductAssociationsProvider extends ProductAssociationsProvider {
5
+ protected config: FakeConfiguration;
6
+ protected faker: Faker;
7
+ constructor(config: FakeConfiguration, cache: any, context: any);
8
+ getAccessories(query: ProductAssociationsGetAccessoriesQuery): Promise<Result<ProductAssociation[]>>;
9
+ getSpareparts(query: ProductAssociationsGetSparepartsQuery): Promise<Result<ProductAssociation[]>>;
10
+ getReplacements(query: ProductAssociationsGetReplacementsQuery): Promise<Result<ProductAssociation[]>>;
11
+ private generateFakeAssociatedProducts;
12
+ }
@@ -11,6 +11,7 @@ export declare const FakeCapabilitiesSchema: z.ZodObject<{
11
11
  profile: z.ZodOptional<z.ZodBoolean>;
12
12
  store: z.ZodOptional<z.ZodBoolean>;
13
13
  productSearch: z.ZodOptional<z.ZodBoolean>;
14
+ productAssociations: z.ZodOptional<z.ZodBoolean>;
14
15
  productReviews: z.ZodOptional<z.ZodBoolean>;
15
16
  orderSearch: z.ZodOptional<z.ZodBoolean>;
16
17
  }, z.core.$loose>;