@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
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AnalyticsCapability
|
|
3
|
+
} from "@reactionary/core";
|
|
4
|
+
class FakeAnalyticsCapability extends AnalyticsCapability {
|
|
5
|
+
config;
|
|
6
|
+
constructor(config, cache, context) {
|
|
7
|
+
super(cache, context);
|
|
8
|
+
this.config = config;
|
|
9
|
+
}
|
|
10
|
+
async track(event) {
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
FakeAnalyticsCapability
|
|
15
|
+
};
|
|
@@ -0,0 +1,261 @@
|
|
|
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
|
+
CartIdentifierSchema,
|
|
14
|
+
CartMutationApplyCouponSchema,
|
|
15
|
+
CartMutationChangeCurrencySchema,
|
|
16
|
+
CartMutationDeleteCartSchema,
|
|
17
|
+
CartMutationItemAddSchema,
|
|
18
|
+
CartMutationItemQuantityChangeSchema,
|
|
19
|
+
CartMutationItemRemoveSchema,
|
|
20
|
+
CartMutationRemoveCouponSchema,
|
|
21
|
+
CartCapability,
|
|
22
|
+
CartQueryByIdSchema,
|
|
23
|
+
CartSchema,
|
|
24
|
+
Reactionary,
|
|
25
|
+
error,
|
|
26
|
+
success,
|
|
27
|
+
unwrapValue
|
|
28
|
+
} from "@reactionary/core";
|
|
29
|
+
import { Faker, en, base } from "@faker-js/faker";
|
|
30
|
+
class FakeCartCapability extends CartCapability {
|
|
31
|
+
config;
|
|
32
|
+
factory;
|
|
33
|
+
carts = /* @__PURE__ */ new Map();
|
|
34
|
+
generator;
|
|
35
|
+
constructor(config, cache, context, factory) {
|
|
36
|
+
super(cache, context);
|
|
37
|
+
this.generator = new Faker({
|
|
38
|
+
locale: [en, base],
|
|
39
|
+
seed: config.seeds.product
|
|
40
|
+
});
|
|
41
|
+
this.config = config;
|
|
42
|
+
this.factory = factory;
|
|
43
|
+
}
|
|
44
|
+
async getById(payload) {
|
|
45
|
+
const cartId = payload.cart.key;
|
|
46
|
+
if (payload.cart.key === "") {
|
|
47
|
+
return error({
|
|
48
|
+
type: "NotFound",
|
|
49
|
+
identifier: cartId
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (!this.carts.has(cartId)) {
|
|
53
|
+
const cart2 = this.createEmptyCart();
|
|
54
|
+
cart2.identifier.key = cartId;
|
|
55
|
+
this.carts.set(cartId, cart2);
|
|
56
|
+
}
|
|
57
|
+
const cart = this.carts.get(cartId);
|
|
58
|
+
if (!cart) {
|
|
59
|
+
throw new Error(`Cart with id ${cartId} not found`);
|
|
60
|
+
}
|
|
61
|
+
return success(this.factory.parseCart(this.context, cart));
|
|
62
|
+
}
|
|
63
|
+
async add(payload) {
|
|
64
|
+
const cartId = payload?.cart?.key || `cart-${this.generator.string.uuid()}`;
|
|
65
|
+
const cart = unwrapValue(await this.getById({ cart: { key: cartId } }));
|
|
66
|
+
if (cart.identifier.key === "") {
|
|
67
|
+
cart.identifier.key = cartId;
|
|
68
|
+
this.carts.set(cartId, cart);
|
|
69
|
+
}
|
|
70
|
+
const existingItemIndex = cart.items.findIndex(
|
|
71
|
+
(item) => item.variant.sku === payload.variant.sku
|
|
72
|
+
);
|
|
73
|
+
if (existingItemIndex >= 0) {
|
|
74
|
+
cart.items[existingItemIndex].quantity += payload.quantity;
|
|
75
|
+
} else {
|
|
76
|
+
const price = this.generator.number.int({ min: 100, max: 1e5 }) / 100;
|
|
77
|
+
cart.items.push({
|
|
78
|
+
identifier: { key: `item-${Date.now()}` },
|
|
79
|
+
variant: payload.variant,
|
|
80
|
+
quantity: payload.quantity,
|
|
81
|
+
price: {
|
|
82
|
+
unitPrice: {
|
|
83
|
+
value: price,
|
|
84
|
+
currency: this.context.languageContext.currencyCode
|
|
85
|
+
},
|
|
86
|
+
totalPrice: {
|
|
87
|
+
value: 0,
|
|
88
|
+
// Will be calculated below
|
|
89
|
+
currency: this.context.languageContext.currencyCode
|
|
90
|
+
},
|
|
91
|
+
totalDiscount: {
|
|
92
|
+
value: 0,
|
|
93
|
+
currency: this.context.languageContext.currencyCode
|
|
94
|
+
},
|
|
95
|
+
unitDiscount: {
|
|
96
|
+
value: 0,
|
|
97
|
+
currency: this.context.languageContext.currencyCode
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
product: {
|
|
101
|
+
key: `product-for-${payload.variant.sku}`
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
this.recalculateCart(cart);
|
|
106
|
+
return success(this.factory.parseCart(this.context, cart));
|
|
107
|
+
}
|
|
108
|
+
async remove(payload) {
|
|
109
|
+
const cartId = payload.cart.key || `cart-${this.generator.string.uuid()}`;
|
|
110
|
+
const cart = unwrapValue(await this.getById({ cart: { key: cartId } }));
|
|
111
|
+
cart.items = cart.items.filter(
|
|
112
|
+
(item) => item.identifier.key !== payload.item.key
|
|
113
|
+
);
|
|
114
|
+
this.recalculateCart(cart);
|
|
115
|
+
return success(this.factory.parseCart(this.context, cart));
|
|
116
|
+
}
|
|
117
|
+
async changeQuantity(payload) {
|
|
118
|
+
const cartId = payload.cart.key || `cart-${this.generator.string.uuid()}`;
|
|
119
|
+
const cart = unwrapValue(await this.getById({ cart: { key: cartId } }));
|
|
120
|
+
const item = cart.items.find(
|
|
121
|
+
(item2) => item2.identifier.key === payload.item.key
|
|
122
|
+
);
|
|
123
|
+
if (payload.quantity < 1) {
|
|
124
|
+
return success(this.factory.parseCart(this.context, cart));
|
|
125
|
+
}
|
|
126
|
+
if (item) {
|
|
127
|
+
item.quantity = payload.quantity;
|
|
128
|
+
}
|
|
129
|
+
this.recalculateCart(cart);
|
|
130
|
+
return success(this.factory.parseCart(this.context, cart));
|
|
131
|
+
}
|
|
132
|
+
getActiveCartId() {
|
|
133
|
+
throw new Error("Method not implemented.");
|
|
134
|
+
}
|
|
135
|
+
deleteCart(payload) {
|
|
136
|
+
throw new Error("Method not implemented.");
|
|
137
|
+
}
|
|
138
|
+
applyCouponCode(payload) {
|
|
139
|
+
throw new Error("Method not implemented.");
|
|
140
|
+
}
|
|
141
|
+
removeCouponCode(payload) {
|
|
142
|
+
throw new Error("Method not implemented.");
|
|
143
|
+
}
|
|
144
|
+
changeCurrency(payload) {
|
|
145
|
+
throw new Error("Method not implemented.");
|
|
146
|
+
}
|
|
147
|
+
recalculateCart(cart) {
|
|
148
|
+
cart.items.forEach((item) => {
|
|
149
|
+
item.price.totalPrice.value = item.price.unitPrice.value * item.quantity;
|
|
150
|
+
});
|
|
151
|
+
cart.price.totalProductPrice = {
|
|
152
|
+
value: cart.items.reduce(
|
|
153
|
+
(sum, item) => sum + item.price.totalPrice.value,
|
|
154
|
+
0
|
|
155
|
+
),
|
|
156
|
+
currency: cart.items[0]?.price.unitPrice.currency || "USD"
|
|
157
|
+
};
|
|
158
|
+
cart.price.grandTotal = {
|
|
159
|
+
value: cart.items.reduce(
|
|
160
|
+
(sum, item) => sum + item.price.totalPrice.value,
|
|
161
|
+
0
|
|
162
|
+
),
|
|
163
|
+
currency: cart.items[0]?.price.unitPrice.currency || "USD"
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
createEmptyCart() {
|
|
167
|
+
const cart = {
|
|
168
|
+
identifier: { key: "" },
|
|
169
|
+
description: "",
|
|
170
|
+
items: [],
|
|
171
|
+
name: "",
|
|
172
|
+
price: {
|
|
173
|
+
grandTotal: {
|
|
174
|
+
value: 0,
|
|
175
|
+
currency: "XXX"
|
|
176
|
+
},
|
|
177
|
+
totalDiscount: {
|
|
178
|
+
value: 0,
|
|
179
|
+
currency: "XXX"
|
|
180
|
+
},
|
|
181
|
+
totalProductPrice: {
|
|
182
|
+
value: 0,
|
|
183
|
+
currency: "XXX"
|
|
184
|
+
},
|
|
185
|
+
totalShipping: {
|
|
186
|
+
value: 0,
|
|
187
|
+
currency: "XXX"
|
|
188
|
+
},
|
|
189
|
+
totalSurcharge: {
|
|
190
|
+
value: 0,
|
|
191
|
+
currency: "XXX"
|
|
192
|
+
},
|
|
193
|
+
totalTax: {
|
|
194
|
+
value: 0,
|
|
195
|
+
currency: "XXX"
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
appliedPromotions: [],
|
|
199
|
+
userId: {
|
|
200
|
+
userId: ""
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
return cart;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
__decorateClass([
|
|
207
|
+
Reactionary({
|
|
208
|
+
inputSchema: CartQueryByIdSchema,
|
|
209
|
+
outputSchema: CartSchema
|
|
210
|
+
})
|
|
211
|
+
], FakeCartCapability.prototype, "getById", 1);
|
|
212
|
+
__decorateClass([
|
|
213
|
+
Reactionary({
|
|
214
|
+
inputSchema: CartMutationItemAddSchema,
|
|
215
|
+
outputSchema: CartSchema
|
|
216
|
+
})
|
|
217
|
+
], FakeCartCapability.prototype, "add", 1);
|
|
218
|
+
__decorateClass([
|
|
219
|
+
Reactionary({
|
|
220
|
+
inputSchema: CartMutationItemRemoveSchema,
|
|
221
|
+
outputSchema: CartSchema
|
|
222
|
+
})
|
|
223
|
+
], FakeCartCapability.prototype, "remove", 1);
|
|
224
|
+
__decorateClass([
|
|
225
|
+
Reactionary({
|
|
226
|
+
inputSchema: CartMutationItemQuantityChangeSchema,
|
|
227
|
+
outputSchema: CartSchema
|
|
228
|
+
})
|
|
229
|
+
], FakeCartCapability.prototype, "changeQuantity", 1);
|
|
230
|
+
__decorateClass([
|
|
231
|
+
Reactionary({
|
|
232
|
+
outputSchema: CartIdentifierSchema
|
|
233
|
+
})
|
|
234
|
+
], FakeCartCapability.prototype, "getActiveCartId", 1);
|
|
235
|
+
__decorateClass([
|
|
236
|
+
Reactionary({
|
|
237
|
+
inputSchema: CartMutationDeleteCartSchema,
|
|
238
|
+
outputSchema: CartSchema
|
|
239
|
+
})
|
|
240
|
+
], FakeCartCapability.prototype, "deleteCart", 1);
|
|
241
|
+
__decorateClass([
|
|
242
|
+
Reactionary({
|
|
243
|
+
inputSchema: CartMutationApplyCouponSchema,
|
|
244
|
+
outputSchema: CartSchema
|
|
245
|
+
})
|
|
246
|
+
], FakeCartCapability.prototype, "applyCouponCode", 1);
|
|
247
|
+
__decorateClass([
|
|
248
|
+
Reactionary({
|
|
249
|
+
inputSchema: CartMutationRemoveCouponSchema,
|
|
250
|
+
outputSchema: CartSchema
|
|
251
|
+
})
|
|
252
|
+
], FakeCartCapability.prototype, "removeCouponCode", 1);
|
|
253
|
+
__decorateClass([
|
|
254
|
+
Reactionary({
|
|
255
|
+
inputSchema: CartMutationChangeCurrencySchema,
|
|
256
|
+
outputSchema: CartSchema
|
|
257
|
+
})
|
|
258
|
+
], FakeCartCapability.prototype, "changeCurrency", 1);
|
|
259
|
+
export {
|
|
260
|
+
FakeCartCapability
|
|
261
|
+
};
|
|
@@ -0,0 +1,160 @@
|
|
|
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
|
+
CategoryPaginatedResultSchema,
|
|
14
|
+
CategoryCapability,
|
|
15
|
+
CategoryQueryByIdSchema,
|
|
16
|
+
CategoryQueryBySlugSchema,
|
|
17
|
+
CategoryQueryForBreadcrumbSchema,
|
|
18
|
+
CategoryQueryForChildCategoriesSchema,
|
|
19
|
+
CategoryQueryForTopCategoriesSchema,
|
|
20
|
+
CategorySchema,
|
|
21
|
+
Reactionary,
|
|
22
|
+
error,
|
|
23
|
+
success
|
|
24
|
+
} from "@reactionary/core";
|
|
25
|
+
import * as z from "zod";
|
|
26
|
+
import { Faker, en, base } from "@faker-js/faker";
|
|
27
|
+
class FakeCategoryCapability extends CategoryCapability {
|
|
28
|
+
config;
|
|
29
|
+
factory;
|
|
30
|
+
topCategories = [];
|
|
31
|
+
childCategories = /* @__PURE__ */ new Map();
|
|
32
|
+
allCategories = /* @__PURE__ */ new Map();
|
|
33
|
+
categoryGenerator;
|
|
34
|
+
generateFakeCategory(parent, index) {
|
|
35
|
+
const name = parent ? `${parent.name}-${index}` : this.categoryGenerator.commerce.department();
|
|
36
|
+
const identifier = { key: name.toLowerCase().replace(/\s+/g, "-") };
|
|
37
|
+
const category = {
|
|
38
|
+
identifier,
|
|
39
|
+
images: [],
|
|
40
|
+
name,
|
|
41
|
+
slug: `${identifier.key}-slug`,
|
|
42
|
+
text: this.categoryGenerator.lorem.sentences(3),
|
|
43
|
+
parentCategory: parent?.identifier
|
|
44
|
+
};
|
|
45
|
+
this.allCategories.set(identifier.key, category);
|
|
46
|
+
return category;
|
|
47
|
+
}
|
|
48
|
+
constructor(config, cache, context, factory) {
|
|
49
|
+
super(cache, context);
|
|
50
|
+
this.config = config;
|
|
51
|
+
this.factory = factory;
|
|
52
|
+
this.categoryGenerator = new Faker({
|
|
53
|
+
seed: this.config.seeds.category,
|
|
54
|
+
locale: [en, base]
|
|
55
|
+
});
|
|
56
|
+
for (let i = 0; i < 6; i++) {
|
|
57
|
+
this.topCategories.push(this.generateFakeCategory(void 0, i));
|
|
58
|
+
}
|
|
59
|
+
this.topCategories.forEach((parentCategory) => {
|
|
60
|
+
const children = [];
|
|
61
|
+
for (let j = 0; j < 5; j++) {
|
|
62
|
+
const childCategory = this.generateFakeCategory(parentCategory, j);
|
|
63
|
+
children.push(childCategory);
|
|
64
|
+
const subCategoryChildren = [];
|
|
65
|
+
for (let k = 0; k < 5; k++) {
|
|
66
|
+
subCategoryChildren.push(this.generateFakeCategory(childCategory, k));
|
|
67
|
+
}
|
|
68
|
+
this.childCategories.set(childCategory.identifier.key, subCategoryChildren);
|
|
69
|
+
}
|
|
70
|
+
this.childCategories.set(parentCategory.identifier.key, children);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
async getById(payload) {
|
|
74
|
+
const category = this.allCategories.get(payload.id.key);
|
|
75
|
+
if (!category) {
|
|
76
|
+
return error({
|
|
77
|
+
type: "NotFound",
|
|
78
|
+
identifier: payload
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return success(this.factory.parseCategory(this.context, category));
|
|
82
|
+
}
|
|
83
|
+
async getBySlug(payload) {
|
|
84
|
+
for (const category of this.allCategories.values()) {
|
|
85
|
+
if (category.slug === payload.slug) {
|
|
86
|
+
return success(this.factory.parseCategory(this.context, category));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return error({
|
|
90
|
+
type: "NotFound",
|
|
91
|
+
identifier: payload
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async getBreadcrumbPathToCategory(payload) {
|
|
95
|
+
const path = [];
|
|
96
|
+
let next = this.allCategories.get(payload.id.key);
|
|
97
|
+
while (next) {
|
|
98
|
+
path.unshift(next);
|
|
99
|
+
if (!next.parentCategory) {
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
next = this.allCategories.get(next.parentCategory.key);
|
|
103
|
+
}
|
|
104
|
+
return success(path.map((x) => this.factory.parseCategory(this.context, x)));
|
|
105
|
+
}
|
|
106
|
+
async findTopCategories(_payload) {
|
|
107
|
+
const result = {
|
|
108
|
+
items: this.topCategories,
|
|
109
|
+
pageSize: this.topCategories.length,
|
|
110
|
+
pageNumber: 1,
|
|
111
|
+
totalCount: this.topCategories.length,
|
|
112
|
+
totalPages: 1
|
|
113
|
+
};
|
|
114
|
+
return success(this.factory.parseCategoryPaginatedResult(this.context, result));
|
|
115
|
+
}
|
|
116
|
+
async findChildCategories(payload) {
|
|
117
|
+
const items = this.childCategories.get(payload.parentId.key) || [];
|
|
118
|
+
const result = {
|
|
119
|
+
items,
|
|
120
|
+
pageSize: items.length,
|
|
121
|
+
pageNumber: 1,
|
|
122
|
+
totalCount: items.length,
|
|
123
|
+
totalPages: 1
|
|
124
|
+
};
|
|
125
|
+
return success(this.factory.parseCategoryPaginatedResult(this.context, result));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
__decorateClass([
|
|
129
|
+
Reactionary({
|
|
130
|
+
inputSchema: CategoryQueryByIdSchema,
|
|
131
|
+
outputSchema: CategorySchema
|
|
132
|
+
})
|
|
133
|
+
], FakeCategoryCapability.prototype, "getById", 1);
|
|
134
|
+
__decorateClass([
|
|
135
|
+
Reactionary({
|
|
136
|
+
inputSchema: CategoryQueryBySlugSchema,
|
|
137
|
+
outputSchema: CategorySchema
|
|
138
|
+
})
|
|
139
|
+
], FakeCategoryCapability.prototype, "getBySlug", 1);
|
|
140
|
+
__decorateClass([
|
|
141
|
+
Reactionary({
|
|
142
|
+
inputSchema: CategoryQueryForBreadcrumbSchema,
|
|
143
|
+
outputSchema: z.array(CategorySchema)
|
|
144
|
+
})
|
|
145
|
+
], FakeCategoryCapability.prototype, "getBreadcrumbPathToCategory", 1);
|
|
146
|
+
__decorateClass([
|
|
147
|
+
Reactionary({
|
|
148
|
+
inputSchema: CategoryQueryForTopCategoriesSchema,
|
|
149
|
+
outputSchema: CategoryPaginatedResultSchema
|
|
150
|
+
})
|
|
151
|
+
], FakeCategoryCapability.prototype, "findTopCategories", 1);
|
|
152
|
+
__decorateClass([
|
|
153
|
+
Reactionary({
|
|
154
|
+
inputSchema: CategoryQueryForChildCategoriesSchema,
|
|
155
|
+
outputSchema: CategoryPaginatedResultSchema
|
|
156
|
+
})
|
|
157
|
+
], FakeCategoryCapability.prototype, "findChildCategories", 1);
|
|
158
|
+
export {
|
|
159
|
+
FakeCategoryCapability
|
|
160
|
+
};
|
|
@@ -0,0 +1,231 @@
|
|
|
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
|
+
CheckoutCapability,
|
|
14
|
+
Reactionary,
|
|
15
|
+
CheckoutMutationInitiateCheckoutSchema,
|
|
16
|
+
CheckoutSchema,
|
|
17
|
+
CheckoutQueryByIdSchema,
|
|
18
|
+
CheckoutMutationSetShippingAddressSchema,
|
|
19
|
+
CheckoutQueryForAvailableShippingMethodsSchema,
|
|
20
|
+
CheckoutQueryForAvailablePaymentMethodsSchema,
|
|
21
|
+
CheckoutMutationAddPaymentInstructionSchema,
|
|
22
|
+
CheckoutMutationRemovePaymentInstructionSchema,
|
|
23
|
+
CheckoutMutationSetShippingInstructionSchema,
|
|
24
|
+
CheckoutMutationFinalizeCheckoutSchema,
|
|
25
|
+
success,
|
|
26
|
+
PaymentMethodSchema,
|
|
27
|
+
ShippingMethodSchema
|
|
28
|
+
} from "@reactionary/core";
|
|
29
|
+
import { base, en, Faker } from "@faker-js/faker";
|
|
30
|
+
import * as z from "zod";
|
|
31
|
+
class FakeCheckoutCapability extends CheckoutCapability {
|
|
32
|
+
config;
|
|
33
|
+
generator;
|
|
34
|
+
factory;
|
|
35
|
+
constructor(config, cache, context, factory) {
|
|
36
|
+
super(cache, context);
|
|
37
|
+
this.config = config;
|
|
38
|
+
this.generator = new Faker({
|
|
39
|
+
locale: [en, base],
|
|
40
|
+
seed: config.seeds.product
|
|
41
|
+
});
|
|
42
|
+
this.factory = factory;
|
|
43
|
+
}
|
|
44
|
+
async initiateCheckoutForCart(payload) {
|
|
45
|
+
const checkout = this.composeBaseCheckout(payload.cart.identifier);
|
|
46
|
+
return success(this.factory.parseCheckout(this.context, checkout));
|
|
47
|
+
}
|
|
48
|
+
async getById(payload) {
|
|
49
|
+
const checkout = this.composeBaseCheckout(payload.identifier);
|
|
50
|
+
return success(this.factory.parseCheckout(this.context, checkout));
|
|
51
|
+
}
|
|
52
|
+
async setShippingAddress(payload) {
|
|
53
|
+
const checkout = this.composeBaseCheckout(payload.checkout);
|
|
54
|
+
return success(this.factory.parseCheckout(this.context, checkout));
|
|
55
|
+
}
|
|
56
|
+
async getAvailableShippingMethods(payload) {
|
|
57
|
+
const methods = [
|
|
58
|
+
{
|
|
59
|
+
name: "Fake",
|
|
60
|
+
deliveryTime: "3 days",
|
|
61
|
+
description: "A fake delivery by fake mail",
|
|
62
|
+
identifier: {
|
|
63
|
+
key: "fake-001"
|
|
64
|
+
},
|
|
65
|
+
price: {
|
|
66
|
+
currency: "USD",
|
|
67
|
+
value: 500
|
|
68
|
+
},
|
|
69
|
+
carrier: "Faker"
|
|
70
|
+
}
|
|
71
|
+
];
|
|
72
|
+
return success(
|
|
73
|
+
methods.map((method) => this.factory.parseShippingMethod(this.context, method))
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
async getAvailablePaymentMethods(payload) {
|
|
77
|
+
const methods = [
|
|
78
|
+
{
|
|
79
|
+
description: "A fake payment method for paying at some point",
|
|
80
|
+
identifier: {
|
|
81
|
+
method: "PayLater",
|
|
82
|
+
name: "Pay Later",
|
|
83
|
+
paymentProcessor: "Faker"
|
|
84
|
+
},
|
|
85
|
+
isPunchOut: false
|
|
86
|
+
}
|
|
87
|
+
];
|
|
88
|
+
return success(
|
|
89
|
+
methods.map((method) => this.factory.parsePaymentMethod(this.context, method))
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
async addPaymentInstruction(payload) {
|
|
93
|
+
const checkout = this.composeBaseCheckout(payload.checkout);
|
|
94
|
+
return success(this.factory.parseCheckout(this.context, checkout));
|
|
95
|
+
}
|
|
96
|
+
async removePaymentInstruction(payload) {
|
|
97
|
+
const checkout = this.composeBaseCheckout(payload.checkout);
|
|
98
|
+
return success(this.factory.parseCheckout(this.context, checkout));
|
|
99
|
+
}
|
|
100
|
+
async setShippingInstruction(payload) {
|
|
101
|
+
const checkout = this.composeBaseCheckout(payload.checkout);
|
|
102
|
+
return success(this.factory.parseCheckout(this.context, checkout));
|
|
103
|
+
}
|
|
104
|
+
async finalizeCheckout(payload) {
|
|
105
|
+
const checkout = this.composeBaseCheckout(payload.checkout);
|
|
106
|
+
return success(this.factory.parseCheckout(this.context, checkout));
|
|
107
|
+
}
|
|
108
|
+
composeBaseCheckout(identifier) {
|
|
109
|
+
const checkout = {
|
|
110
|
+
description: "Fake Checkout",
|
|
111
|
+
identifier: identifier || {
|
|
112
|
+
key: this.generator.string.uuid()
|
|
113
|
+
},
|
|
114
|
+
items: [],
|
|
115
|
+
name: "Fake Checkout",
|
|
116
|
+
originalCartReference: {
|
|
117
|
+
key: this.generator.string.uuid()
|
|
118
|
+
},
|
|
119
|
+
paymentInstructions: [],
|
|
120
|
+
price: {
|
|
121
|
+
grandTotal: {
|
|
122
|
+
currency: "USD",
|
|
123
|
+
value: this.generator.number.float({
|
|
124
|
+
min: 100,
|
|
125
|
+
max: 1e4,
|
|
126
|
+
multipleOf: 25
|
|
127
|
+
})
|
|
128
|
+
},
|
|
129
|
+
totalDiscount: {
|
|
130
|
+
currency: "USD",
|
|
131
|
+
value: this.generator.number.float({
|
|
132
|
+
min: 100,
|
|
133
|
+
max: 1e4,
|
|
134
|
+
multipleOf: 25
|
|
135
|
+
})
|
|
136
|
+
},
|
|
137
|
+
totalProductPrice: {
|
|
138
|
+
currency: "USD",
|
|
139
|
+
value: this.generator.number.float({
|
|
140
|
+
min: 100,
|
|
141
|
+
max: 1e4,
|
|
142
|
+
multipleOf: 25
|
|
143
|
+
})
|
|
144
|
+
},
|
|
145
|
+
totalShipping: {
|
|
146
|
+
currency: "USD",
|
|
147
|
+
value: this.generator.number.float({
|
|
148
|
+
min: 100,
|
|
149
|
+
max: 1e4,
|
|
150
|
+
multipleOf: 25
|
|
151
|
+
})
|
|
152
|
+
},
|
|
153
|
+
totalSurcharge: {
|
|
154
|
+
currency: "USD",
|
|
155
|
+
value: this.generator.number.float({
|
|
156
|
+
min: 100,
|
|
157
|
+
max: 1e4,
|
|
158
|
+
multipleOf: 25
|
|
159
|
+
})
|
|
160
|
+
},
|
|
161
|
+
totalTax: {
|
|
162
|
+
currency: "USD",
|
|
163
|
+
value: this.generator.number.float({
|
|
164
|
+
min: 100,
|
|
165
|
+
max: 1e4,
|
|
166
|
+
multipleOf: 25
|
|
167
|
+
})
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
readyForFinalization: false
|
|
171
|
+
};
|
|
172
|
+
return checkout;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
__decorateClass([
|
|
176
|
+
Reactionary({
|
|
177
|
+
inputSchema: CheckoutMutationInitiateCheckoutSchema,
|
|
178
|
+
outputSchema: CheckoutSchema
|
|
179
|
+
})
|
|
180
|
+
], FakeCheckoutCapability.prototype, "initiateCheckoutForCart", 1);
|
|
181
|
+
__decorateClass([
|
|
182
|
+
Reactionary({
|
|
183
|
+
inputSchema: CheckoutQueryByIdSchema,
|
|
184
|
+
outputSchema: CheckoutSchema
|
|
185
|
+
})
|
|
186
|
+
], FakeCheckoutCapability.prototype, "getById", 1);
|
|
187
|
+
__decorateClass([
|
|
188
|
+
Reactionary({
|
|
189
|
+
inputSchema: CheckoutMutationSetShippingAddressSchema,
|
|
190
|
+
outputSchema: CheckoutSchema
|
|
191
|
+
})
|
|
192
|
+
], FakeCheckoutCapability.prototype, "setShippingAddress", 1);
|
|
193
|
+
__decorateClass([
|
|
194
|
+
Reactionary({
|
|
195
|
+
inputSchema: CheckoutQueryForAvailableShippingMethodsSchema,
|
|
196
|
+
outputSchema: z.array(ShippingMethodSchema)
|
|
197
|
+
})
|
|
198
|
+
], FakeCheckoutCapability.prototype, "getAvailableShippingMethods", 1);
|
|
199
|
+
__decorateClass([
|
|
200
|
+
Reactionary({
|
|
201
|
+
inputSchema: CheckoutQueryForAvailablePaymentMethodsSchema,
|
|
202
|
+
outputSchema: z.array(PaymentMethodSchema)
|
|
203
|
+
})
|
|
204
|
+
], FakeCheckoutCapability.prototype, "getAvailablePaymentMethods", 1);
|
|
205
|
+
__decorateClass([
|
|
206
|
+
Reactionary({
|
|
207
|
+
inputSchema: CheckoutMutationAddPaymentInstructionSchema,
|
|
208
|
+
outputSchema: CheckoutSchema
|
|
209
|
+
})
|
|
210
|
+
], FakeCheckoutCapability.prototype, "addPaymentInstruction", 1);
|
|
211
|
+
__decorateClass([
|
|
212
|
+
Reactionary({
|
|
213
|
+
inputSchema: CheckoutMutationRemovePaymentInstructionSchema,
|
|
214
|
+
outputSchema: CheckoutSchema
|
|
215
|
+
})
|
|
216
|
+
], FakeCheckoutCapability.prototype, "removePaymentInstruction", 1);
|
|
217
|
+
__decorateClass([
|
|
218
|
+
Reactionary({
|
|
219
|
+
inputSchema: CheckoutMutationSetShippingInstructionSchema,
|
|
220
|
+
outputSchema: CheckoutSchema
|
|
221
|
+
})
|
|
222
|
+
], FakeCheckoutCapability.prototype, "setShippingInstruction", 1);
|
|
223
|
+
__decorateClass([
|
|
224
|
+
Reactionary({
|
|
225
|
+
inputSchema: CheckoutMutationFinalizeCheckoutSchema,
|
|
226
|
+
outputSchema: CheckoutSchema
|
|
227
|
+
})
|
|
228
|
+
], FakeCheckoutCapability.prototype, "finalizeCheckout", 1);
|
|
229
|
+
export {
|
|
230
|
+
FakeCheckoutCapability
|
|
231
|
+
};
|