@reactionary/fake 0.6.3
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.
- package/README.md +11 -0
- package/capabilities/analytics.capability.js +15 -0
- package/capabilities/cart.capability.js +261 -0
- package/capabilities/category.capability.js +160 -0
- package/capabilities/checkout.capability.js +231 -0
- package/capabilities/identity.capability.js +89 -0
- package/capabilities/index.js +15 -0
- package/capabilities/inventory.capability.js +59 -0
- package/capabilities/order-search.capability.js +74 -0
- package/capabilities/order.capability.js +81 -0
- package/capabilities/price.capability.js +99 -0
- package/capabilities/product-associations.capability.js +121 -0
- package/capabilities/product-reviews.capability.js +154 -0
- package/capabilities/product-search.capability.js +145 -0
- package/capabilities/product.capability.js +99 -0
- package/capabilities/profile.capability.js +130 -0
- package/capabilities/store.capability.js +59 -0
- package/core/initialize.js +235 -0
- package/core/initialize.types.js +8 -0
- package/factories/cart/cart.factory.js +17 -0
- package/factories/category/category.factory.js +17 -0
- package/factories/checkout/checkout.factory.js +22 -0
- package/factories/identity/identity.factory.js +12 -0
- package/factories/index.js +14 -0
- package/factories/inventory/inventory.factory.js +12 -0
- package/factories/order/order.factory.js +12 -0
- package/factories/order-search/order-search.factory.js +12 -0
- package/factories/price/price.factory.js +12 -0
- package/factories/product/product.factory.js +12 -0
- package/factories/product-associations/product-associations.factory.js +12 -0
- package/factories/product-reviews/product-reviews.factory.js +22 -0
- package/factories/product-search/product-search.factory.js +12 -0
- package/factories/profile/profile.factory.js +12 -0
- package/factories/store/store.factory.js +12 -0
- package/index.js +6 -0
- package/package.json +15 -0
- package/schema/capabilities.schema.js +41 -0
- package/schema/configuration.schema.js +18 -0
- package/src/capabilities/analytics.capability.d.ts +8 -0
- package/src/capabilities/cart.capability.d.ts +22 -0
- package/src/capabilities/category.capability.d.ts +20 -0
- package/src/capabilities/checkout.capability.d.ts +56 -0
- package/src/capabilities/identity.capability.d.ts +13 -0
- package/src/capabilities/index.d.ts +15 -0
- package/src/capabilities/inventory.capability.d.ts +10 -0
- package/src/capabilities/order-search.capability.d.ts +11 -0
- package/src/capabilities/order.capability.d.ts +11 -0
- package/src/capabilities/price.capability.d.ts +13 -0
- package/src/capabilities/product-associations.capability.d.ts +15 -0
- package/src/capabilities/product-reviews.capability.d.ts +13 -0
- package/src/capabilities/product-search.capability.d.ts +10 -0
- package/src/capabilities/product.capability.d.ts +12 -0
- package/src/capabilities/profile.capability.d.ts +18 -0
- package/src/capabilities/store.capability.d.ts +10 -0
- package/src/core/initialize.d.ts +5 -0
- package/src/core/initialize.types.d.ts +113 -0
- package/src/factories/cart/cart.factory.d.ts +9 -0
- package/src/factories/category/category.factory.d.ts +9 -0
- package/src/factories/checkout/checkout.factory.d.ts +11 -0
- package/src/factories/identity/identity.factory.d.ts +7 -0
- package/src/factories/index.d.ts +14 -0
- package/src/factories/inventory/inventory.factory.d.ts +7 -0
- package/src/factories/order/order.factory.d.ts +7 -0
- package/src/factories/order-search/order-search.factory.d.ts +7 -0
- package/src/factories/price/price.factory.d.ts +9 -0
- package/src/factories/product/product.factory.d.ts +7 -0
- package/src/factories/product-associations/product-associations.factory.d.ts +7 -0
- package/src/factories/product-reviews/product-reviews.factory.d.ts +11 -0
- package/src/factories/product-search/product-search.factory.d.ts +7 -0
- package/src/factories/profile/profile.factory.d.ts +7 -0
- package/src/factories/store/store.factory.d.ts +7 -0
- package/src/index.d.ts +6 -0
- package/src/schema/capabilities.schema.d.ts +117 -0
- package/src/schema/configuration.schema.d.ts +13 -0
- package/src/test/client-builder-product-extension.example.d.ts +1 -0
- package/src/test/test-utils.d.ts +2 -0
- package/src/utilities/jitter.d.ts +1 -0
- package/src/utilities/seed.d.ts +1 -0
- package/test/client-builder-product-extension.example.js +57 -0
- package/test/test-utils.js +16 -0
- package/utilities/jitter.js +13 -0
- package/utilities/seed.js +11 -0
|
@@ -0,0 +1,145 @@
|
|
|
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
|
+
ImageSchema,
|
|
14
|
+
ProductSearchCapability,
|
|
15
|
+
ProductSearchQueryByTermSchema,
|
|
16
|
+
ProductSearchResultItemSchema,
|
|
17
|
+
ProductSearchResultSchema,
|
|
18
|
+
Reactionary,
|
|
19
|
+
success
|
|
20
|
+
} from "@reactionary/core";
|
|
21
|
+
import { Faker, en, base } from "@faker-js/faker";
|
|
22
|
+
import { jitter } from "../utilities/jitter.js";
|
|
23
|
+
class FakeProductSearchCapability extends ProductSearchCapability {
|
|
24
|
+
config;
|
|
25
|
+
factory;
|
|
26
|
+
constructor(config, cache, context, factory) {
|
|
27
|
+
super(cache, context);
|
|
28
|
+
this.config = config;
|
|
29
|
+
this.factory = factory;
|
|
30
|
+
}
|
|
31
|
+
async queryByTerm(payload) {
|
|
32
|
+
await jitter(this.config.jitter.mean, this.config.jitter.deviation);
|
|
33
|
+
const query = payload.search;
|
|
34
|
+
const querySpecificity = 20 - query.term.length - query.paginationOptions.pageNumber - query.facets.length;
|
|
35
|
+
const totalProducts = 10 * querySpecificity;
|
|
36
|
+
const totalPages = Math.ceil(totalProducts / query.paginationOptions.pageSize);
|
|
37
|
+
const productsOnPage = Math.min(totalProducts, query.paginationOptions.pageSize);
|
|
38
|
+
const productGenerator = new Faker({
|
|
39
|
+
seed: querySpecificity,
|
|
40
|
+
locale: [en, base]
|
|
41
|
+
});
|
|
42
|
+
const facetGenerator = new Faker({
|
|
43
|
+
seed: 100,
|
|
44
|
+
locale: [en, base]
|
|
45
|
+
});
|
|
46
|
+
const products = [];
|
|
47
|
+
const facets = [];
|
|
48
|
+
for (let i = 0; i < productsOnPage; i++) {
|
|
49
|
+
const srcUrl = productGenerator.image.urlPicsumPhotos({
|
|
50
|
+
height: 300,
|
|
51
|
+
width: 300,
|
|
52
|
+
grayscale: true,
|
|
53
|
+
blur: 8
|
|
54
|
+
});
|
|
55
|
+
const img = ImageSchema.parse({
|
|
56
|
+
sourceUrl: srcUrl,
|
|
57
|
+
altText: "Fake product image",
|
|
58
|
+
height: 300,
|
|
59
|
+
width: 300
|
|
60
|
+
});
|
|
61
|
+
products.push(
|
|
62
|
+
ProductSearchResultItemSchema.parse({
|
|
63
|
+
identifier: {
|
|
64
|
+
key: `product_${productGenerator.commerce.isbn()}`
|
|
65
|
+
},
|
|
66
|
+
name: productGenerator.commerce.productName(),
|
|
67
|
+
slug: productGenerator.lorem.slug(),
|
|
68
|
+
variants: [
|
|
69
|
+
{
|
|
70
|
+
variant: {
|
|
71
|
+
sku: productGenerator.commerce.isbn()
|
|
72
|
+
},
|
|
73
|
+
image: img,
|
|
74
|
+
options: void 0
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
})
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
for (const baseFacet of ["color", "size"]) {
|
|
81
|
+
const facet = {
|
|
82
|
+
identifier: {
|
|
83
|
+
key: baseFacet
|
|
84
|
+
},
|
|
85
|
+
name: baseFacet,
|
|
86
|
+
values: []
|
|
87
|
+
};
|
|
88
|
+
for (let i = 0; i < 10; i++) {
|
|
89
|
+
const valueKey = i.toString();
|
|
90
|
+
const isActive = query.facets.find(
|
|
91
|
+
(x) => x.facet.key === facet.identifier.key && x.key === valueKey
|
|
92
|
+
) !== void 0;
|
|
93
|
+
facet.values.push({
|
|
94
|
+
active: isActive,
|
|
95
|
+
count: facetGenerator.number.int({ min: 1, max: 50 }),
|
|
96
|
+
identifier: {
|
|
97
|
+
facet: {
|
|
98
|
+
key: facet.identifier.key
|
|
99
|
+
},
|
|
100
|
+
key: valueKey
|
|
101
|
+
},
|
|
102
|
+
name: facetGenerator.color.human()
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
facets.push(facet);
|
|
106
|
+
}
|
|
107
|
+
const result = {
|
|
108
|
+
identifier: {
|
|
109
|
+
term: query.term,
|
|
110
|
+
paginationOptions: {
|
|
111
|
+
pageNumber: query.paginationOptions.pageNumber,
|
|
112
|
+
pageSize: query.paginationOptions.pageSize
|
|
113
|
+
},
|
|
114
|
+
facets: query.facets,
|
|
115
|
+
filters: []
|
|
116
|
+
},
|
|
117
|
+
facets,
|
|
118
|
+
items: products,
|
|
119
|
+
pageNumber: query.paginationOptions.pageNumber,
|
|
120
|
+
pageSize: query.paginationOptions.pageSize,
|
|
121
|
+
totalCount: totalProducts,
|
|
122
|
+
totalPages
|
|
123
|
+
};
|
|
124
|
+
return success(this.factory.parseSearchResult(this.context, result, payload));
|
|
125
|
+
}
|
|
126
|
+
async createCategoryNavigationFilter(payload) {
|
|
127
|
+
const facetIdentifier = {
|
|
128
|
+
key: "category"
|
|
129
|
+
};
|
|
130
|
+
const facetValueIdentifier = {
|
|
131
|
+
facet: facetIdentifier,
|
|
132
|
+
key: payload.categoryPath[payload.categoryPath.length - 1].identifier.key
|
|
133
|
+
};
|
|
134
|
+
return success(facetValueIdentifier);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
__decorateClass([
|
|
138
|
+
Reactionary({
|
|
139
|
+
inputSchema: ProductSearchQueryByTermSchema,
|
|
140
|
+
outputSchema: ProductSearchResultSchema
|
|
141
|
+
})
|
|
142
|
+
], FakeProductSearchCapability.prototype, "queryByTerm", 1);
|
|
143
|
+
export {
|
|
144
|
+
FakeProductSearchCapability
|
|
145
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
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
|
+
ProductQueryByIdSchema,
|
|
14
|
+
ProductQueryBySKUSchema,
|
|
15
|
+
ProductQueryBySlugSchema,
|
|
16
|
+
ProductCapability,
|
|
17
|
+
ProductSchema,
|
|
18
|
+
Reactionary,
|
|
19
|
+
success
|
|
20
|
+
} from "@reactionary/core";
|
|
21
|
+
import { base, en, Faker } from "@faker-js/faker";
|
|
22
|
+
class FakeProductCapability extends ProductCapability {
|
|
23
|
+
config;
|
|
24
|
+
factory;
|
|
25
|
+
constructor(config, cache, context, factory) {
|
|
26
|
+
super(cache, context);
|
|
27
|
+
this.config = config;
|
|
28
|
+
this.factory = factory;
|
|
29
|
+
}
|
|
30
|
+
async getById(payload) {
|
|
31
|
+
return success(this.composeSingle(payload.identifier.key));
|
|
32
|
+
}
|
|
33
|
+
async getBySlug(payload) {
|
|
34
|
+
return success(this.composeSingle(payload.slug));
|
|
35
|
+
}
|
|
36
|
+
async getBySKU(payload) {
|
|
37
|
+
return success(this.composeSingle(payload.variant.sku));
|
|
38
|
+
}
|
|
39
|
+
composeSingle(body) {
|
|
40
|
+
const generator = new Faker({
|
|
41
|
+
seed: 42,
|
|
42
|
+
locale: [en, base]
|
|
43
|
+
});
|
|
44
|
+
const result = {
|
|
45
|
+
identifier: {
|
|
46
|
+
key: body
|
|
47
|
+
},
|
|
48
|
+
name: generator.commerce.productName(),
|
|
49
|
+
slug: body,
|
|
50
|
+
brand: "",
|
|
51
|
+
longDescription: "",
|
|
52
|
+
mainVariant: {
|
|
53
|
+
barcode: "",
|
|
54
|
+
ean: "",
|
|
55
|
+
gtin: "",
|
|
56
|
+
identifier: {
|
|
57
|
+
sku: ""
|
|
58
|
+
},
|
|
59
|
+
images: [],
|
|
60
|
+
name: "",
|
|
61
|
+
options: [],
|
|
62
|
+
upc: ""
|
|
63
|
+
},
|
|
64
|
+
description: generator.commerce.productDescription(),
|
|
65
|
+
manufacturer: "",
|
|
66
|
+
options: [],
|
|
67
|
+
parentCategories: [],
|
|
68
|
+
published: true,
|
|
69
|
+
sharedAttributes: [],
|
|
70
|
+
variants: []
|
|
71
|
+
};
|
|
72
|
+
return this.factory.parseProduct(this.context, result);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
__decorateClass([
|
|
76
|
+
Reactionary({
|
|
77
|
+
inputSchema: ProductQueryByIdSchema,
|
|
78
|
+
outputSchema: ProductSchema,
|
|
79
|
+
cache: true,
|
|
80
|
+
cacheTimeToLiveInSeconds: 300,
|
|
81
|
+
currencyDependentCaching: false,
|
|
82
|
+
localeDependentCaching: true
|
|
83
|
+
})
|
|
84
|
+
], FakeProductCapability.prototype, "getById", 1);
|
|
85
|
+
__decorateClass([
|
|
86
|
+
Reactionary({
|
|
87
|
+
inputSchema: ProductQueryBySlugSchema,
|
|
88
|
+
outputSchema: ProductSchema
|
|
89
|
+
})
|
|
90
|
+
], FakeProductCapability.prototype, "getBySlug", 1);
|
|
91
|
+
__decorateClass([
|
|
92
|
+
Reactionary({
|
|
93
|
+
inputSchema: ProductQueryBySKUSchema,
|
|
94
|
+
outputSchema: ProductSchema
|
|
95
|
+
})
|
|
96
|
+
], FakeProductCapability.prototype, "getBySKU", 1);
|
|
97
|
+
export {
|
|
98
|
+
FakeProductCapability
|
|
99
|
+
};
|
|
@@ -0,0 +1,130 @@
|
|
|
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
|
+
AddressSchema,
|
|
14
|
+
ProfileMutationAddShippingAddressSchema,
|
|
15
|
+
ProfileMutationMakeShippingAddressDefaultSchema,
|
|
16
|
+
ProfileMutationRemoveShippingAddressSchema,
|
|
17
|
+
ProfileMutationSetBillingAddressSchema,
|
|
18
|
+
ProfileMutationUpdateSchema,
|
|
19
|
+
ProfileMutationUpdateShippingAddressSchema,
|
|
20
|
+
ProfileCapability,
|
|
21
|
+
ProfileQueryByIdSchema,
|
|
22
|
+
ProfileSchema,
|
|
23
|
+
Reactionary,
|
|
24
|
+
success
|
|
25
|
+
} from "@reactionary/core";
|
|
26
|
+
import { base, en, Faker } from "@faker-js/faker";
|
|
27
|
+
class FakeProfileCapability extends ProfileCapability {
|
|
28
|
+
config;
|
|
29
|
+
factory;
|
|
30
|
+
generator;
|
|
31
|
+
constructor(config, cache, context, factory) {
|
|
32
|
+
super(cache, context);
|
|
33
|
+
this.generator = new Faker({
|
|
34
|
+
locale: [en, base],
|
|
35
|
+
seed: config.seeds.product
|
|
36
|
+
});
|
|
37
|
+
this.config = config;
|
|
38
|
+
this.factory = factory;
|
|
39
|
+
}
|
|
40
|
+
async getById(payload) {
|
|
41
|
+
return success(this.composeProfile(payload.identifier));
|
|
42
|
+
}
|
|
43
|
+
async update(payload) {
|
|
44
|
+
return success(this.composeProfile(payload.identifier));
|
|
45
|
+
}
|
|
46
|
+
async addShippingAddress(payload) {
|
|
47
|
+
return success(this.composeProfile(payload.identifier));
|
|
48
|
+
}
|
|
49
|
+
async updateShippingAddress(payload) {
|
|
50
|
+
return success(this.composeProfile(payload.identifier));
|
|
51
|
+
}
|
|
52
|
+
async removeShippingAddress(payload) {
|
|
53
|
+
return success(this.composeProfile(payload.identifier));
|
|
54
|
+
}
|
|
55
|
+
async makeShippingAddressDefault(payload) {
|
|
56
|
+
return success(this.composeProfile(payload.identifier));
|
|
57
|
+
}
|
|
58
|
+
async setBillingAddress(payload) {
|
|
59
|
+
return success(this.composeProfile(payload.identifier));
|
|
60
|
+
}
|
|
61
|
+
composeProfile(identifier) {
|
|
62
|
+
const baseProfile = {
|
|
63
|
+
identifier,
|
|
64
|
+
email: this.generator.internet.email(),
|
|
65
|
+
phone: this.generator.phone.number(),
|
|
66
|
+
emailVerified: true,
|
|
67
|
+
phoneVerified: true,
|
|
68
|
+
createdAt: this.generator.date.past().toISOString(),
|
|
69
|
+
updatedAt: this.generator.date.recent().toISOString(),
|
|
70
|
+
billingAddress: this.createEmptyAddress(),
|
|
71
|
+
shippingAddress: this.createEmptyAddress(),
|
|
72
|
+
alternateShippingAddresses: []
|
|
73
|
+
};
|
|
74
|
+
return this.factory.parseProfile(this.context, baseProfile);
|
|
75
|
+
}
|
|
76
|
+
createEmptyAddress() {
|
|
77
|
+
return AddressSchema.parse({
|
|
78
|
+
identifier: {
|
|
79
|
+
nickName: this.generator.person.firstName().toLowerCase()
|
|
80
|
+
},
|
|
81
|
+
firstName: this.generator.person.firstName(),
|
|
82
|
+
lastName: this.generator.person.lastName(),
|
|
83
|
+
streetAddress: this.generator.location.street(),
|
|
84
|
+
streetNumber: this.generator.location.buildingNumber(),
|
|
85
|
+
city: this.generator.location.city(),
|
|
86
|
+
region: this.generator.location.state(),
|
|
87
|
+
postalCode: this.generator.location.zipCode(),
|
|
88
|
+
countryCode: this.generator.location.countryCode("alpha-2")
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
__decorateClass([
|
|
93
|
+
Reactionary({ inputSchema: ProfileQueryByIdSchema, outputSchema: ProfileSchema })
|
|
94
|
+
], FakeProfileCapability.prototype, "getById", 1);
|
|
95
|
+
__decorateClass([
|
|
96
|
+
Reactionary({ inputSchema: ProfileMutationUpdateSchema, outputSchema: ProfileSchema })
|
|
97
|
+
], FakeProfileCapability.prototype, "update", 1);
|
|
98
|
+
__decorateClass([
|
|
99
|
+
Reactionary({
|
|
100
|
+
inputSchema: ProfileMutationAddShippingAddressSchema,
|
|
101
|
+
outputSchema: ProfileSchema
|
|
102
|
+
})
|
|
103
|
+
], FakeProfileCapability.prototype, "addShippingAddress", 1);
|
|
104
|
+
__decorateClass([
|
|
105
|
+
Reactionary({
|
|
106
|
+
inputSchema: ProfileMutationUpdateShippingAddressSchema,
|
|
107
|
+
outputSchema: ProfileSchema
|
|
108
|
+
})
|
|
109
|
+
], FakeProfileCapability.prototype, "updateShippingAddress", 1);
|
|
110
|
+
__decorateClass([
|
|
111
|
+
Reactionary({
|
|
112
|
+
inputSchema: ProfileMutationRemoveShippingAddressSchema,
|
|
113
|
+
outputSchema: ProfileSchema
|
|
114
|
+
})
|
|
115
|
+
], FakeProfileCapability.prototype, "removeShippingAddress", 1);
|
|
116
|
+
__decorateClass([
|
|
117
|
+
Reactionary({
|
|
118
|
+
inputSchema: ProfileMutationMakeShippingAddressDefaultSchema,
|
|
119
|
+
outputSchema: ProfileSchema
|
|
120
|
+
})
|
|
121
|
+
], FakeProfileCapability.prototype, "makeShippingAddressDefault", 1);
|
|
122
|
+
__decorateClass([
|
|
123
|
+
Reactionary({
|
|
124
|
+
inputSchema: ProfileMutationSetBillingAddressSchema,
|
|
125
|
+
outputSchema: ProfileSchema
|
|
126
|
+
})
|
|
127
|
+
], FakeProfileCapability.prototype, "setBillingAddress", 1);
|
|
128
|
+
export {
|
|
129
|
+
FakeProfileCapability
|
|
130
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
Reactionary,
|
|
14
|
+
StoreCapability,
|
|
15
|
+
StoreQueryByProximitySchema,
|
|
16
|
+
StoreSchema,
|
|
17
|
+
success
|
|
18
|
+
} from "@reactionary/core";
|
|
19
|
+
import * as z from "zod";
|
|
20
|
+
import { base, en, Faker } from "@faker-js/faker";
|
|
21
|
+
class FakeStoreCapability extends StoreCapability {
|
|
22
|
+
config;
|
|
23
|
+
factory;
|
|
24
|
+
constructor(config, cache, context, factory) {
|
|
25
|
+
super(cache, context);
|
|
26
|
+
this.config = config;
|
|
27
|
+
this.factory = factory;
|
|
28
|
+
}
|
|
29
|
+
async queryByProximity(payload) {
|
|
30
|
+
const generator = new Faker({
|
|
31
|
+
seed: 42,
|
|
32
|
+
locale: [en, base]
|
|
33
|
+
});
|
|
34
|
+
const results = [];
|
|
35
|
+
for (let i = 0; i < payload.limit; i++) {
|
|
36
|
+
results.push(
|
|
37
|
+
this.factory.parseStore(this.context, {
|
|
38
|
+
identifier: {
|
|
39
|
+
key: `${i}`
|
|
40
|
+
},
|
|
41
|
+
fulfillmentCenter: {
|
|
42
|
+
key: `${i}`
|
|
43
|
+
},
|
|
44
|
+
name: generator.company.name()
|
|
45
|
+
})
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
return success(results);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
__decorateClass([
|
|
52
|
+
Reactionary({
|
|
53
|
+
inputSchema: StoreQueryByProximitySchema,
|
|
54
|
+
outputSchema: z.array(StoreSchema)
|
|
55
|
+
})
|
|
56
|
+
], FakeStoreCapability.prototype, "queryByProximity", 1);
|
|
57
|
+
export {
|
|
58
|
+
FakeStoreCapability
|
|
59
|
+
};
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CartIdentifierSchema as CoreCartIdentifierSchema,
|
|
3
|
+
CartSchema as CoreCartSchema,
|
|
4
|
+
CategoryPaginatedResultSchema as CoreCategoryPaginatedResultSchema,
|
|
5
|
+
CategorySchema as CoreCategorySchema,
|
|
6
|
+
CheckoutSchema as CoreCheckoutSchema,
|
|
7
|
+
IdentitySchema as CoreIdentitySchema,
|
|
8
|
+
InventorySchema as CoreInventorySchema,
|
|
9
|
+
OrderSchema as CoreOrderSchema,
|
|
10
|
+
OrderSearchResultSchema as CoreOrderSearchResultSchema,
|
|
11
|
+
PaymentMethodSchema as CorePaymentMethodSchema,
|
|
12
|
+
PriceSchema as CorePriceSchema,
|
|
13
|
+
ProductAssociationSchema as CoreProductAssociationSchema,
|
|
14
|
+
ProductRatingSummarySchema as CoreProductRatingSummarySchema,
|
|
15
|
+
ProductReviewPaginatedResultSchema as CoreProductReviewPaginatedResultSchema,
|
|
16
|
+
ProductReviewSchema as CoreProductReviewSchema,
|
|
17
|
+
ProductSchema as CoreProductSchema,
|
|
18
|
+
ProductSearchResultSchema as CoreProductSearchResultSchema,
|
|
19
|
+
ProfileSchema as CoreProfileSchema,
|
|
20
|
+
ShippingMethodSchema as CoreShippingMethodSchema,
|
|
21
|
+
StoreSchema as CoreStoreSchema
|
|
22
|
+
} from "@reactionary/core";
|
|
23
|
+
import { FakeProductCapability } from "../capabilities/product.capability.js";
|
|
24
|
+
import { FakeProductSearchCapability } from "../capabilities/product-search.capability.js";
|
|
25
|
+
import { FakeCapabilitiesSchema } from "../schema/capabilities.schema.js";
|
|
26
|
+
import { FakeCategoryCapability } from "../capabilities/category.capability.js";
|
|
27
|
+
import {
|
|
28
|
+
FakeCartCapability,
|
|
29
|
+
FakeIdentityCapability,
|
|
30
|
+
FakeInventoryCapability,
|
|
31
|
+
FakePriceCapability,
|
|
32
|
+
FakeStoreCapability
|
|
33
|
+
} from "../capabilities/index.js";
|
|
34
|
+
import { FakeCheckoutCapability } from "../capabilities/checkout.capability.js";
|
|
35
|
+
import { FakeOrderSearchCapability } from "../capabilities/order-search.capability.js";
|
|
36
|
+
import { FakeOrderCapability } from "../capabilities/order.capability.js";
|
|
37
|
+
import { FakeProfileCapability } from "../capabilities/profile.capability.js";
|
|
38
|
+
import { FakeProductReviewsCapability } from "../capabilities/product-reviews.capability.js";
|
|
39
|
+
import { FakeProductAssociationsCapability } from "../capabilities/product-associations.capability.js";
|
|
40
|
+
import {
|
|
41
|
+
FakeCartFactory,
|
|
42
|
+
FakeCategoryFactory,
|
|
43
|
+
FakeCheckoutFactory,
|
|
44
|
+
FakeIdentityFactory,
|
|
45
|
+
FakeInventoryFactory,
|
|
46
|
+
FakeOrderFactory,
|
|
47
|
+
FakeOrderSearchFactory,
|
|
48
|
+
FakePriceFactory,
|
|
49
|
+
FakeProductAssociationsFactory,
|
|
50
|
+
FakeProductFactory,
|
|
51
|
+
FakeProductReviewsFactory,
|
|
52
|
+
FakeProductSearchFactory,
|
|
53
|
+
FakeProfileFactory,
|
|
54
|
+
FakeStoreFactory
|
|
55
|
+
} from "../factories/index.js";
|
|
56
|
+
import {
|
|
57
|
+
resolveCapabilityWithFactory
|
|
58
|
+
} from "./initialize.types.js";
|
|
59
|
+
function withFakeCapabilities(configuration, capabilities) {
|
|
60
|
+
return (cache, context) => {
|
|
61
|
+
const client = {};
|
|
62
|
+
const caps = FakeCapabilitiesSchema.parse(capabilities);
|
|
63
|
+
const buildCapabilityArgs = (factory) => ({
|
|
64
|
+
cache,
|
|
65
|
+
context,
|
|
66
|
+
config: configuration,
|
|
67
|
+
factory
|
|
68
|
+
});
|
|
69
|
+
if (caps.product?.enabled) {
|
|
70
|
+
client.product = resolveCapabilityWithFactory(
|
|
71
|
+
capabilities.product,
|
|
72
|
+
{
|
|
73
|
+
factory: new FakeProductFactory(CoreProductSchema),
|
|
74
|
+
capability: (args) => new FakeProductCapability(args.config, args.cache, args.context, args.factory)
|
|
75
|
+
},
|
|
76
|
+
buildCapabilityArgs
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
if (caps.productSearch?.enabled) {
|
|
80
|
+
client.productSearch = resolveCapabilityWithFactory(
|
|
81
|
+
capabilities.productSearch,
|
|
82
|
+
{
|
|
83
|
+
factory: new FakeProductSearchFactory(CoreProductSearchResultSchema),
|
|
84
|
+
capability: (args) => new FakeProductSearchCapability(args.config, args.cache, args.context, args.factory)
|
|
85
|
+
},
|
|
86
|
+
buildCapabilityArgs
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
if (caps.category?.enabled) {
|
|
90
|
+
client.category = resolveCapabilityWithFactory(
|
|
91
|
+
capabilities.category,
|
|
92
|
+
{
|
|
93
|
+
factory: new FakeCategoryFactory(
|
|
94
|
+
CoreCategorySchema,
|
|
95
|
+
CoreCategoryPaginatedResultSchema
|
|
96
|
+
),
|
|
97
|
+
capability: (args) => new FakeCategoryCapability(args.config, args.cache, args.context, args.factory)
|
|
98
|
+
},
|
|
99
|
+
buildCapabilityArgs
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
if (caps.cart?.enabled) {
|
|
103
|
+
client.cart = resolveCapabilityWithFactory(
|
|
104
|
+
capabilities.cart,
|
|
105
|
+
{
|
|
106
|
+
factory: new FakeCartFactory(CoreCartSchema, CoreCartIdentifierSchema),
|
|
107
|
+
capability: (args) => new FakeCartCapability(args.config, args.cache, args.context, args.factory)
|
|
108
|
+
},
|
|
109
|
+
buildCapabilityArgs
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
if (caps.inventory?.enabled) {
|
|
113
|
+
client.inventory = resolveCapabilityWithFactory(
|
|
114
|
+
capabilities.inventory,
|
|
115
|
+
{
|
|
116
|
+
factory: new FakeInventoryFactory(CoreInventorySchema),
|
|
117
|
+
capability: (args) => new FakeInventoryCapability(args.config, args.cache, args.context, args.factory)
|
|
118
|
+
},
|
|
119
|
+
buildCapabilityArgs
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
if (caps.store?.enabled) {
|
|
123
|
+
client.store = resolveCapabilityWithFactory(
|
|
124
|
+
capabilities.store,
|
|
125
|
+
{
|
|
126
|
+
factory: new FakeStoreFactory(CoreStoreSchema),
|
|
127
|
+
capability: (args) => new FakeStoreCapability(args.config, args.cache, args.context, args.factory)
|
|
128
|
+
},
|
|
129
|
+
buildCapabilityArgs
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
if (caps.price?.enabled) {
|
|
133
|
+
client.price = resolveCapabilityWithFactory(
|
|
134
|
+
capabilities.price,
|
|
135
|
+
{
|
|
136
|
+
factory: new FakePriceFactory(CorePriceSchema),
|
|
137
|
+
capability: (args) => new FakePriceCapability(args.config, args.cache, args.context, args.factory)
|
|
138
|
+
},
|
|
139
|
+
buildCapabilityArgs
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
if (caps.identity?.enabled) {
|
|
143
|
+
client.identity = resolveCapabilityWithFactory(
|
|
144
|
+
capabilities.identity,
|
|
145
|
+
{
|
|
146
|
+
factory: new FakeIdentityFactory(CoreIdentitySchema),
|
|
147
|
+
capability: (args) => new FakeIdentityCapability(args.config, args.cache, args.context, args.factory)
|
|
148
|
+
},
|
|
149
|
+
buildCapabilityArgs
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
if (caps.checkout?.enabled) {
|
|
153
|
+
client.checkout = resolveCapabilityWithFactory(
|
|
154
|
+
capabilities.checkout,
|
|
155
|
+
{
|
|
156
|
+
factory: new FakeCheckoutFactory(
|
|
157
|
+
CoreCheckoutSchema,
|
|
158
|
+
CoreShippingMethodSchema,
|
|
159
|
+
CorePaymentMethodSchema
|
|
160
|
+
),
|
|
161
|
+
capability: (args) => new FakeCheckoutCapability(args.config, args.cache, args.context, args.factory)
|
|
162
|
+
},
|
|
163
|
+
buildCapabilityArgs
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
if (caps.orderSearch?.enabled) {
|
|
167
|
+
client.orderSearch = resolveCapabilityWithFactory(
|
|
168
|
+
capabilities.orderSearch,
|
|
169
|
+
{
|
|
170
|
+
factory: new FakeOrderSearchFactory(CoreOrderSearchResultSchema),
|
|
171
|
+
capability: (args) => new FakeOrderSearchCapability(args.config, args.cache, args.context, args.factory)
|
|
172
|
+
},
|
|
173
|
+
buildCapabilityArgs
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
if (caps.order?.enabled) {
|
|
177
|
+
client.order = resolveCapabilityWithFactory(
|
|
178
|
+
capabilities.order,
|
|
179
|
+
{
|
|
180
|
+
factory: new FakeOrderFactory(CoreOrderSchema),
|
|
181
|
+
capability: (args) => new FakeOrderCapability(args.config, args.cache, args.context, args.factory)
|
|
182
|
+
},
|
|
183
|
+
buildCapabilityArgs
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
if (caps.profile?.enabled) {
|
|
187
|
+
client.profile = resolveCapabilityWithFactory(
|
|
188
|
+
capabilities.profile,
|
|
189
|
+
{
|
|
190
|
+
factory: new FakeProfileFactory(CoreProfileSchema),
|
|
191
|
+
capability: (args) => new FakeProfileCapability(args.config, args.cache, args.context, args.factory)
|
|
192
|
+
},
|
|
193
|
+
buildCapabilityArgs
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
if (caps.productReviews?.enabled) {
|
|
197
|
+
client.productReviews = resolveCapabilityWithFactory(
|
|
198
|
+
capabilities.productReviews,
|
|
199
|
+
{
|
|
200
|
+
factory: new FakeProductReviewsFactory(
|
|
201
|
+
CoreProductRatingSummarySchema,
|
|
202
|
+
CoreProductReviewSchema,
|
|
203
|
+
CoreProductReviewPaginatedResultSchema
|
|
204
|
+
),
|
|
205
|
+
capability: (args) => new FakeProductReviewsCapability(
|
|
206
|
+
args.config,
|
|
207
|
+
args.cache,
|
|
208
|
+
args.context,
|
|
209
|
+
args.factory
|
|
210
|
+
)
|
|
211
|
+
},
|
|
212
|
+
buildCapabilityArgs
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
if (caps.productAssociations?.enabled) {
|
|
216
|
+
client.productAssociations = resolveCapabilityWithFactory(
|
|
217
|
+
capabilities.productAssociations,
|
|
218
|
+
{
|
|
219
|
+
factory: new FakeProductAssociationsFactory(CoreProductAssociationSchema),
|
|
220
|
+
capability: (args) => new FakeProductAssociationsCapability(
|
|
221
|
+
args.config,
|
|
222
|
+
args.cache,
|
|
223
|
+
args.context,
|
|
224
|
+
args.factory
|
|
225
|
+
)
|
|
226
|
+
},
|
|
227
|
+
buildCapabilityArgs
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
return client;
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
export {
|
|
234
|
+
withFakeCapabilities
|
|
235
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
function resolveCapabilityWithFactory(capability, defaults, buildCapabilityArgs) {
|
|
2
|
+
const factory = capability?.factory ?? defaults.factory;
|
|
3
|
+
const capabilityFactory = capability?.capability ?? defaults.capability;
|
|
4
|
+
return capabilityFactory(buildCapabilityArgs(factory));
|
|
5
|
+
}
|
|
6
|
+
export {
|
|
7
|
+
resolveCapabilityWithFactory
|
|
8
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
class FakeCartFactory {
|
|
2
|
+
cartSchema;
|
|
3
|
+
cartIdentifierSchema;
|
|
4
|
+
constructor(cartSchema, cartIdentifierSchema) {
|
|
5
|
+
this.cartSchema = cartSchema;
|
|
6
|
+
this.cartIdentifierSchema = cartIdentifierSchema;
|
|
7
|
+
}
|
|
8
|
+
parseCart(_context, data) {
|
|
9
|
+
return this.cartSchema.parse(data);
|
|
10
|
+
}
|
|
11
|
+
parseCartIdentifier(_context, data) {
|
|
12
|
+
return this.cartIdentifierSchema.parse(data);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
FakeCartFactory
|
|
17
|
+
};
|