@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.
- package/core/initialize.js +193 -37
- package/core/initialize.types.js +8 -0
- package/factories/cart/cart.factory.js +15 -0
- package/factories/category/category.factory.js +15 -0
- package/factories/checkout/checkout.factory.js +19 -0
- package/factories/identity/identity.factory.js +11 -0
- package/factories/index.js +14 -0
- package/factories/inventory/inventory.factory.js +11 -0
- package/factories/order/order.factory.js +11 -0
- package/factories/order-search/order-search.factory.js +11 -0
- package/factories/price/price.factory.js +11 -0
- package/factories/product/product.factory.js +11 -0
- package/factories/product-associations/product-associations.factory.js +11 -0
- package/factories/product-reviews/product-reviews.factory.js +19 -0
- package/factories/product-search/product-search.factory.js +11 -0
- package/factories/profile/profile.factory.js +11 -0
- package/factories/store/store.factory.js +11 -0
- package/index.js +2 -0
- package/package.json +2 -2
- package/providers/cart.provider.js +7 -6
- package/providers/category.provider.js +57 -74
- package/providers/checkout.provider.js +15 -10
- package/providers/identity.provider.js +15 -17
- package/providers/inventory.provider.js +11 -15
- package/providers/order-search.provider.js +4 -3
- package/providers/order.provider.js +9 -32
- package/providers/price.provider.js +9 -15
- package/providers/product-associations.provider.js +6 -5
- package/providers/product-reviews.provider.js +30 -29
- package/providers/product-search.provider.js +14 -29
- package/providers/product.provider.js +13 -14
- package/providers/profile.provider.js +37 -33
- package/providers/store.provider.js +21 -15
- package/schema/capabilities.schema.js +21 -0
- package/src/core/initialize.d.ts +3 -2
- 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 +2 -0
- package/src/providers/cart.provider.d.ts +12 -10
- package/src/providers/category.provider.d.ts +12 -11
- package/src/providers/checkout.provider.d.ts +14 -12
- package/src/providers/identity.provider.d.ts +9 -7
- package/src/providers/inventory.provider.d.ts +6 -4
- package/src/providers/order-search.provider.d.ts +6 -4
- package/src/providers/order.provider.d.ts +6 -4
- package/src/providers/price.provider.d.ts +7 -5
- package/src/providers/product-associations.provider.d.ts +9 -6
- package/src/providers/product-reviews.provider.d.ts +8 -7
- package/src/providers/product-search.provider.d.ts +6 -9
- package/src/providers/product.provider.d.ts +9 -7
- package/src/providers/profile.provider.d.ts +14 -20
- package/src/providers/store.provider.d.ts +6 -4
- package/src/schema/capabilities.schema.d.ts +115 -16
- package/src/test/client-builder-product-extension.example.d.ts +1 -0
- package/test/client-builder-product-extension.example.js +57 -0
|
@@ -9,33 +9,44 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
9
9
|
__defProp(target, key, result);
|
|
10
10
|
return result;
|
|
11
11
|
};
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
CategoryPaginatedResultSchema,
|
|
14
|
+
CategoryProvider,
|
|
15
|
+
CategoryQueryByIdSchema,
|
|
16
|
+
CategoryQueryBySlugSchema,
|
|
17
|
+
CategoryQueryForBreadcrumbSchema,
|
|
18
|
+
CategoryQueryForChildCategoriesSchema,
|
|
19
|
+
CategoryQueryForTopCategoriesSchema,
|
|
20
|
+
CategorySchema,
|
|
21
|
+
Reactionary,
|
|
22
|
+
error,
|
|
23
|
+
success
|
|
24
|
+
} from "@reactionary/core";
|
|
13
25
|
import * as z from "zod";
|
|
14
26
|
import { Faker, en, base } from "@faker-js/faker";
|
|
15
27
|
class FakeCategoryProvider extends CategoryProvider {
|
|
16
|
-
constructor(config, cache, context) {
|
|
28
|
+
constructor(config, cache, context, factory) {
|
|
17
29
|
super(cache, context);
|
|
18
|
-
this.topCategories =
|
|
30
|
+
this.topCategories = [];
|
|
19
31
|
this.childCategories = /* @__PURE__ */ new Map();
|
|
20
32
|
this.allCategories = /* @__PURE__ */ new Map();
|
|
21
33
|
this.config = config;
|
|
34
|
+
this.factory = factory;
|
|
22
35
|
this.categoryGenerator = new Faker({
|
|
23
36
|
seed: this.config.seeds.category,
|
|
24
37
|
locale: [en, base]
|
|
25
38
|
});
|
|
26
39
|
for (let i = 0; i < 6; i++) {
|
|
27
|
-
|
|
28
|
-
this.topCategories.push(category);
|
|
40
|
+
this.topCategories.push(this.generateFakeCategory(void 0, i));
|
|
29
41
|
}
|
|
30
42
|
this.topCategories.forEach((parentCategory) => {
|
|
31
|
-
const children =
|
|
43
|
+
const children = [];
|
|
32
44
|
for (let j = 0; j < 5; j++) {
|
|
33
45
|
const childCategory = this.generateFakeCategory(parentCategory, j);
|
|
34
46
|
children.push(childCategory);
|
|
35
|
-
const subCategoryChildren =
|
|
47
|
+
const subCategoryChildren = [];
|
|
36
48
|
for (let k = 0; k < 5; k++) {
|
|
37
|
-
|
|
38
|
-
subCategoryChildren.push(subChildCategory);
|
|
49
|
+
subCategoryChildren.push(this.generateFakeCategory(childCategory, k));
|
|
39
50
|
}
|
|
40
51
|
this.childCategories.set(childCategory.identifier.key, subCategoryChildren);
|
|
41
52
|
}
|
|
@@ -43,26 +54,15 @@ class FakeCategoryProvider extends CategoryProvider {
|
|
|
43
54
|
});
|
|
44
55
|
}
|
|
45
56
|
generateFakeCategory(parent, index) {
|
|
46
|
-
|
|
47
|
-
if (!parent) {
|
|
48
|
-
name = this.categoryGenerator.commerce.department();
|
|
49
|
-
} else {
|
|
50
|
-
name = `${parent.name}-${index}`;
|
|
51
|
-
}
|
|
57
|
+
const name = parent ? `${parent.name}-${index}` : this.categoryGenerator.commerce.department();
|
|
52
58
|
const identifier = { key: name.toLowerCase().replace(/\s+/g, "-") };
|
|
53
|
-
const text = this.categoryGenerator.lorem.sentences(3);
|
|
54
|
-
const slug = identifier.key + "-slug";
|
|
55
|
-
let parentCategory;
|
|
56
|
-
if (parent) {
|
|
57
|
-
parentCategory = parent.identifier;
|
|
58
|
-
}
|
|
59
59
|
const category = {
|
|
60
60
|
identifier,
|
|
61
61
|
images: [],
|
|
62
62
|
name,
|
|
63
|
-
slug
|
|
64
|
-
text,
|
|
65
|
-
parentCategory
|
|
63
|
+
slug: `${identifier.key}-slug`,
|
|
64
|
+
text: this.categoryGenerator.lorem.sentences(3),
|
|
65
|
+
parentCategory: parent?.identifier
|
|
66
66
|
};
|
|
67
67
|
this.allCategories.set(identifier.key, category);
|
|
68
68
|
return category;
|
|
@@ -75,12 +75,12 @@ class FakeCategoryProvider extends CategoryProvider {
|
|
|
75
75
|
identifier: payload
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
|
-
return success(category);
|
|
78
|
+
return success(this.factory.parseCategory(this.context, category));
|
|
79
79
|
}
|
|
80
80
|
async getBySlug(payload) {
|
|
81
|
-
for (const
|
|
82
|
-
if (
|
|
83
|
-
return success(
|
|
81
|
+
for (const category of this.allCategories.values()) {
|
|
82
|
+
if (category.slug === payload.slug) {
|
|
83
|
+
return success(this.factory.parseCategory(this.context, category));
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
return error({
|
|
@@ -89,54 +89,37 @@ class FakeCategoryProvider extends CategoryProvider {
|
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
91
|
async getBreadcrumbPathToCategory(payload) {
|
|
92
|
-
const path =
|
|
93
|
-
let
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
path.unshift(category);
|
|
92
|
+
const path = [];
|
|
93
|
+
let next = this.allCategories.get(payload.id.key);
|
|
94
|
+
while (next) {
|
|
95
|
+
path.unshift(next);
|
|
96
|
+
if (!next.parentCategory) {
|
|
97
|
+
break;
|
|
99
98
|
}
|
|
99
|
+
next = this.allCategories.get(next.parentCategory.key);
|
|
100
100
|
}
|
|
101
|
-
return success(path);
|
|
101
|
+
return success(path.map((x) => this.factory.parseCategory(this.context, x)));
|
|
102
102
|
}
|
|
103
|
-
async
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
hit: false,
|
|
111
|
-
key: "child-categories-" + payload.parentId.key + "-" + payload.paginationOptions.pageNumber + "-" + payload.paginationOptions.pageSize
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
items: page ? page : [],
|
|
115
|
-
totalCount: children ? children.length : 0,
|
|
116
|
-
pageNumber: payload.paginationOptions.pageNumber,
|
|
117
|
-
pageSize: payload.paginationOptions.pageSize,
|
|
118
|
-
totalPages: children ? Math.ceil(children.length / payload.paginationOptions.pageSize) : 1
|
|
103
|
+
async findTopCategories(_payload) {
|
|
104
|
+
const result = {
|
|
105
|
+
items: this.topCategories,
|
|
106
|
+
pageSize: this.topCategories.length,
|
|
107
|
+
pageNumber: 1,
|
|
108
|
+
totalCount: this.topCategories.length,
|
|
109
|
+
totalPages: 1
|
|
119
110
|
};
|
|
120
|
-
return success(
|
|
111
|
+
return success(this.factory.parseCategoryPaginatedResult(this.context, result));
|
|
121
112
|
}
|
|
122
|
-
async
|
|
123
|
-
const
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
key: "top-" + payload.paginationOptions.pageNumber + "-" + payload.paginationOptions.pageSize
|
|
131
|
-
}
|
|
132
|
-
},
|
|
133
|
-
items: page ? page : [],
|
|
134
|
-
totalCount: children ? children.length : 0,
|
|
135
|
-
pageNumber: payload.paginationOptions.pageNumber,
|
|
136
|
-
pageSize: payload.paginationOptions.pageSize,
|
|
137
|
-
totalPages: children ? Math.ceil(children.length / payload.paginationOptions.pageSize) : 1
|
|
113
|
+
async findChildCategories(payload) {
|
|
114
|
+
const items = this.childCategories.get(payload.parentId.key) || [];
|
|
115
|
+
const result = {
|
|
116
|
+
items,
|
|
117
|
+
pageSize: items.length,
|
|
118
|
+
pageNumber: 1,
|
|
119
|
+
totalCount: items.length,
|
|
120
|
+
totalPages: 1
|
|
138
121
|
};
|
|
139
|
-
return success(
|
|
122
|
+
return success(this.factory.parseCategoryPaginatedResult(this.context, result));
|
|
140
123
|
}
|
|
141
124
|
}
|
|
142
125
|
__decorateClass([
|
|
@@ -159,16 +142,16 @@ __decorateClass([
|
|
|
159
142
|
], FakeCategoryProvider.prototype, "getBreadcrumbPathToCategory", 1);
|
|
160
143
|
__decorateClass([
|
|
161
144
|
Reactionary({
|
|
162
|
-
inputSchema:
|
|
145
|
+
inputSchema: CategoryQueryForTopCategoriesSchema,
|
|
163
146
|
outputSchema: CategoryPaginatedResultSchema
|
|
164
147
|
})
|
|
165
|
-
], FakeCategoryProvider.prototype, "
|
|
148
|
+
], FakeCategoryProvider.prototype, "findTopCategories", 1);
|
|
166
149
|
__decorateClass([
|
|
167
150
|
Reactionary({
|
|
168
|
-
inputSchema:
|
|
151
|
+
inputSchema: CategoryQueryForChildCategoriesSchema,
|
|
169
152
|
outputSchema: CategoryPaginatedResultSchema
|
|
170
153
|
})
|
|
171
|
-
], FakeCategoryProvider.prototype, "
|
|
154
|
+
], FakeCategoryProvider.prototype, "findChildCategories", 1);
|
|
172
155
|
export {
|
|
173
156
|
FakeCategoryProvider
|
|
174
157
|
};
|
|
@@ -29,25 +29,26 @@ import {
|
|
|
29
29
|
import { base, en, Faker } from "@faker-js/faker";
|
|
30
30
|
import * as z from "zod";
|
|
31
31
|
class FakeCheckoutProvider extends CheckoutProvider {
|
|
32
|
-
constructor(config, cache, context) {
|
|
32
|
+
constructor(config, cache, context, factory) {
|
|
33
33
|
super(cache, context);
|
|
34
34
|
this.config = config;
|
|
35
35
|
this.generator = new Faker({
|
|
36
36
|
locale: [en, base],
|
|
37
37
|
seed: config.seeds.product
|
|
38
38
|
});
|
|
39
|
+
this.factory = factory;
|
|
39
40
|
}
|
|
40
41
|
async initiateCheckoutForCart(payload) {
|
|
41
42
|
const checkout = this.composeBaseCheckout(payload.cart.identifier);
|
|
42
|
-
return success(checkout);
|
|
43
|
+
return success(this.factory.parseCheckout(this.context, checkout));
|
|
43
44
|
}
|
|
44
45
|
async getById(payload) {
|
|
45
46
|
const checkout = this.composeBaseCheckout(payload.identifier);
|
|
46
|
-
return success(checkout);
|
|
47
|
+
return success(this.factory.parseCheckout(this.context, checkout));
|
|
47
48
|
}
|
|
48
49
|
async setShippingAddress(payload) {
|
|
49
50
|
const checkout = this.composeBaseCheckout(payload.checkout);
|
|
50
|
-
return success(checkout);
|
|
51
|
+
return success(this.factory.parseCheckout(this.context, checkout));
|
|
51
52
|
}
|
|
52
53
|
async getAvailableShippingMethods(payload) {
|
|
53
54
|
const methods = [
|
|
@@ -65,7 +66,9 @@ class FakeCheckoutProvider extends CheckoutProvider {
|
|
|
65
66
|
carrier: "Faker"
|
|
66
67
|
}
|
|
67
68
|
];
|
|
68
|
-
return success(
|
|
69
|
+
return success(
|
|
70
|
+
methods.map((method) => this.factory.parseShippingMethod(this.context, method))
|
|
71
|
+
);
|
|
69
72
|
}
|
|
70
73
|
async getAvailablePaymentMethods(payload) {
|
|
71
74
|
const methods = [
|
|
@@ -79,23 +82,25 @@ class FakeCheckoutProvider extends CheckoutProvider {
|
|
|
79
82
|
isPunchOut: false
|
|
80
83
|
}
|
|
81
84
|
];
|
|
82
|
-
return success(
|
|
85
|
+
return success(
|
|
86
|
+
methods.map((method) => this.factory.parsePaymentMethod(this.context, method))
|
|
87
|
+
);
|
|
83
88
|
}
|
|
84
89
|
async addPaymentInstruction(payload) {
|
|
85
90
|
const checkout = this.composeBaseCheckout(payload.checkout);
|
|
86
|
-
return success(checkout);
|
|
91
|
+
return success(this.factory.parseCheckout(this.context, checkout));
|
|
87
92
|
}
|
|
88
93
|
async removePaymentInstruction(payload) {
|
|
89
94
|
const checkout = this.composeBaseCheckout(payload.checkout);
|
|
90
|
-
return success(checkout);
|
|
95
|
+
return success(this.factory.parseCheckout(this.context, checkout));
|
|
91
96
|
}
|
|
92
97
|
async setShippingInstruction(payload) {
|
|
93
98
|
const checkout = this.composeBaseCheckout(payload.checkout);
|
|
94
|
-
return success(checkout);
|
|
99
|
+
return success(this.factory.parseCheckout(this.context, checkout));
|
|
95
100
|
}
|
|
96
101
|
async finalizeCheckout(payload) {
|
|
97
102
|
const checkout = this.composeBaseCheckout(payload.checkout);
|
|
98
|
-
return success(checkout);
|
|
103
|
+
return success(this.factory.parseCheckout(this.context, checkout));
|
|
99
104
|
}
|
|
100
105
|
composeBaseCheckout(identifier) {
|
|
101
106
|
const checkout = {
|
|
@@ -10,53 +10,51 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
10
10
|
return result;
|
|
11
11
|
};
|
|
12
12
|
import {
|
|
13
|
-
IdentityProvider,
|
|
14
|
-
Reactionary,
|
|
15
|
-
IdentityMutationRegisterSchema,
|
|
16
|
-
IdentitySchema,
|
|
17
|
-
IdentityMutationLogoutSchema,
|
|
18
13
|
IdentityMutationLoginSchema,
|
|
14
|
+
IdentityMutationLogoutSchema,
|
|
15
|
+
IdentityMutationRegisterSchema,
|
|
19
16
|
IdentityQuerySelfSchema,
|
|
17
|
+
IdentityProvider,
|
|
18
|
+
IdentitySchema,
|
|
19
|
+
Reactionary,
|
|
20
20
|
success
|
|
21
21
|
} from "@reactionary/core";
|
|
22
22
|
import { base, en, Faker } from "@faker-js/faker";
|
|
23
23
|
class FakeIdentityProvider extends IdentityProvider {
|
|
24
|
-
constructor(config, cache, context) {
|
|
24
|
+
constructor(config, cache, context, factory) {
|
|
25
25
|
super(cache, context);
|
|
26
26
|
this.currentIdentity = null;
|
|
27
27
|
this.config = config;
|
|
28
|
+
this.factory = factory;
|
|
28
29
|
}
|
|
29
30
|
async getSelf(_payload) {
|
|
30
31
|
if (!this.currentIdentity) {
|
|
31
|
-
|
|
32
|
+
this.currentIdentity = {
|
|
32
33
|
type: "Anonymous"
|
|
33
34
|
};
|
|
34
|
-
this.currentIdentity = model;
|
|
35
35
|
}
|
|
36
|
-
return success(this.currentIdentity);
|
|
36
|
+
return success(this.factory.parseIdentity(this.context, this.currentIdentity));
|
|
37
37
|
}
|
|
38
|
-
async login(
|
|
38
|
+
async login(_payload) {
|
|
39
39
|
const generator = new Faker({
|
|
40
40
|
seed: 42,
|
|
41
41
|
locale: [en, base]
|
|
42
42
|
});
|
|
43
|
-
|
|
43
|
+
this.currentIdentity = {
|
|
44
44
|
type: "Registered",
|
|
45
45
|
id: {
|
|
46
46
|
userId: generator.string.alphanumeric(32)
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
-
this.currentIdentity
|
|
50
|
-
return success(this.currentIdentity);
|
|
49
|
+
return success(this.factory.parseIdentity(this.context, this.currentIdentity));
|
|
51
50
|
}
|
|
52
51
|
async logout(_payload) {
|
|
53
|
-
|
|
52
|
+
this.currentIdentity = {
|
|
54
53
|
type: "Anonymous"
|
|
55
54
|
};
|
|
56
|
-
this.currentIdentity
|
|
57
|
-
return success(this.currentIdentity);
|
|
55
|
+
return success(this.factory.parseIdentity(this.context, this.currentIdentity));
|
|
58
56
|
}
|
|
59
|
-
register(
|
|
57
|
+
register(_payload) {
|
|
60
58
|
throw new Error("Method not implemented.");
|
|
61
59
|
}
|
|
62
60
|
}
|
|
@@ -18,36 +18,32 @@ import {
|
|
|
18
18
|
success
|
|
19
19
|
} from "@reactionary/core";
|
|
20
20
|
class FakeInventoryProvider extends InventoryProvider {
|
|
21
|
-
constructor(config, cache, context) {
|
|
21
|
+
constructor(config, cache, context, factory) {
|
|
22
22
|
super(cache, context);
|
|
23
23
|
this.config = config;
|
|
24
|
+
this.factory = factory;
|
|
24
25
|
}
|
|
25
26
|
async getBySKU(payload) {
|
|
26
27
|
let hash = 0;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
hash
|
|
30
|
-
hash = hash & hash;
|
|
28
|
+
for (let i = 0; i < payload.variant.sku.length; i++) {
|
|
29
|
+
hash = (hash << 5) - hash + payload.variant.sku.charCodeAt(i);
|
|
30
|
+
hash &= hash;
|
|
31
31
|
}
|
|
32
32
|
const generator = new Faker({
|
|
33
33
|
seed: hash || 42,
|
|
34
34
|
locale: [en, base]
|
|
35
35
|
});
|
|
36
|
-
const identifier = {
|
|
37
|
-
variant: payload.variant,
|
|
38
|
-
fulfillmentCenter: payload.fulfilmentCenter
|
|
39
|
-
};
|
|
40
36
|
const quantity = generator.number.int({ min: 0, max: 100 });
|
|
41
|
-
|
|
42
|
-
if (quantity > 0) {
|
|
43
|
-
status = "inStock";
|
|
44
|
-
}
|
|
37
|
+
const status = quantity > 0 ? "inStock" : "outOfStock";
|
|
45
38
|
const result = {
|
|
46
|
-
identifier
|
|
39
|
+
identifier: {
|
|
40
|
+
variant: payload.variant,
|
|
41
|
+
fulfillmentCenter: payload.fulfilmentCenter
|
|
42
|
+
},
|
|
47
43
|
quantity,
|
|
48
44
|
status
|
|
49
45
|
};
|
|
50
|
-
return success(result);
|
|
46
|
+
return success(this.factory.parseInventory(this.context, result));
|
|
51
47
|
}
|
|
52
48
|
}
|
|
53
49
|
__decorateClass([
|
|
@@ -18,16 +18,17 @@ import {
|
|
|
18
18
|
} from "@reactionary/core";
|
|
19
19
|
import { Faker, en, base } from "@faker-js/faker";
|
|
20
20
|
class FakeOrderSearchProvider extends OrderSearchProvider {
|
|
21
|
-
constructor(config, cache, context) {
|
|
21
|
+
constructor(config, cache, context, factory) {
|
|
22
22
|
super(cache, context);
|
|
23
23
|
this.config = config;
|
|
24
24
|
this.generator = new Faker({
|
|
25
25
|
locale: [en, base],
|
|
26
26
|
seed: config.seeds.product
|
|
27
27
|
});
|
|
28
|
+
this.factory = factory;
|
|
28
29
|
}
|
|
29
30
|
async queryByTerm(payload) {
|
|
30
|
-
const items =
|
|
31
|
+
const items = [];
|
|
31
32
|
for (let i = 0; i < payload.search.paginationOptions.pageSize; i++) {
|
|
32
33
|
items.push({
|
|
33
34
|
customerName: this.generator.company.name(),
|
|
@@ -56,7 +57,7 @@ class FakeOrderSearchProvider extends OrderSearchProvider {
|
|
|
56
57
|
totalCount,
|
|
57
58
|
totalPages
|
|
58
59
|
};
|
|
59
|
-
return success(result);
|
|
60
|
+
return success(this.factory.parseOrderSearchResult(this.context, result, payload));
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
__decorateClass([
|
|
@@ -18,13 +18,14 @@ import {
|
|
|
18
18
|
} from "@reactionary/core";
|
|
19
19
|
import { Faker, en, base } from "@faker-js/faker";
|
|
20
20
|
class FakeOrderProvider extends OrderProvider {
|
|
21
|
-
constructor(config, cache, context) {
|
|
21
|
+
constructor(config, cache, context, factory) {
|
|
22
22
|
super(cache, context);
|
|
23
23
|
this.config = config;
|
|
24
24
|
this.generator = new Faker({
|
|
25
25
|
locale: [en, base],
|
|
26
26
|
seed: config.seeds.product
|
|
27
27
|
});
|
|
28
|
+
this.factory = factory;
|
|
28
29
|
}
|
|
29
30
|
async getById(payload) {
|
|
30
31
|
const order = {
|
|
@@ -39,55 +40,31 @@ class FakeOrderProvider extends OrderProvider {
|
|
|
39
40
|
price: {
|
|
40
41
|
grandTotal: {
|
|
41
42
|
currency: "USD",
|
|
42
|
-
value: this.generator.number.float({
|
|
43
|
-
min: 100,
|
|
44
|
-
max: 1e4,
|
|
45
|
-
multipleOf: 25
|
|
46
|
-
})
|
|
43
|
+
value: this.generator.number.float({ min: 100, max: 1e4, multipleOf: 25 })
|
|
47
44
|
},
|
|
48
45
|
totalDiscount: {
|
|
49
46
|
currency: "USD",
|
|
50
|
-
value: this.generator.number.float({
|
|
51
|
-
min: 100,
|
|
52
|
-
max: 1e4,
|
|
53
|
-
multipleOf: 25
|
|
54
|
-
})
|
|
47
|
+
value: this.generator.number.float({ min: 100, max: 1e4, multipleOf: 25 })
|
|
55
48
|
},
|
|
56
49
|
totalProductPrice: {
|
|
57
50
|
currency: "USD",
|
|
58
|
-
value: this.generator.number.float({
|
|
59
|
-
min: 100,
|
|
60
|
-
max: 1e4,
|
|
61
|
-
multipleOf: 25
|
|
62
|
-
})
|
|
51
|
+
value: this.generator.number.float({ min: 100, max: 1e4, multipleOf: 25 })
|
|
63
52
|
},
|
|
64
53
|
totalShipping: {
|
|
65
54
|
currency: "USD",
|
|
66
|
-
value: this.generator.number.float({
|
|
67
|
-
min: 100,
|
|
68
|
-
max: 1e4,
|
|
69
|
-
multipleOf: 25
|
|
70
|
-
})
|
|
55
|
+
value: this.generator.number.float({ min: 100, max: 1e4, multipleOf: 25 })
|
|
71
56
|
},
|
|
72
57
|
totalSurcharge: {
|
|
73
58
|
currency: "USD",
|
|
74
|
-
value: this.generator.number.float({
|
|
75
|
-
min: 100,
|
|
76
|
-
max: 1e4,
|
|
77
|
-
multipleOf: 25
|
|
78
|
-
})
|
|
59
|
+
value: this.generator.number.float({ min: 100, max: 1e4, multipleOf: 25 })
|
|
79
60
|
},
|
|
80
61
|
totalTax: {
|
|
81
62
|
currency: "USD",
|
|
82
|
-
value: this.generator.number.float({
|
|
83
|
-
min: 100,
|
|
84
|
-
max: 1e4,
|
|
85
|
-
multipleOf: 25
|
|
86
|
-
})
|
|
63
|
+
value: this.generator.number.float({ min: 100, max: 1e4, multipleOf: 25 })
|
|
87
64
|
}
|
|
88
65
|
}
|
|
89
66
|
};
|
|
90
|
-
return success(order);
|
|
67
|
+
return success(this.factory.parseOrder(this.context, order));
|
|
91
68
|
}
|
|
92
69
|
}
|
|
93
70
|
__decorateClass([
|
|
@@ -10,23 +10,23 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
10
10
|
return result;
|
|
11
11
|
};
|
|
12
12
|
import {
|
|
13
|
-
PriceProvider,
|
|
14
|
-
Reactionary,
|
|
15
13
|
CustomerPriceQuerySchema,
|
|
16
|
-
PriceSchema,
|
|
17
14
|
ListPriceQuerySchema,
|
|
18
|
-
|
|
15
|
+
PriceProvider,
|
|
16
|
+
PriceSchema,
|
|
17
|
+
Reactionary,
|
|
19
18
|
success
|
|
20
19
|
} from "@reactionary/core";
|
|
21
20
|
import { base, en, Faker } from "@faker-js/faker";
|
|
22
21
|
import { calcSeed } from "../utilities/seed.js";
|
|
23
22
|
class FakePriceProvider extends PriceProvider {
|
|
24
|
-
constructor(config, cache, context) {
|
|
23
|
+
constructor(config, cache, context, factory) {
|
|
25
24
|
super(cache, context);
|
|
26
25
|
this.config = config;
|
|
27
26
|
this.faker = new Faker({
|
|
28
27
|
locale: [en, base]
|
|
29
28
|
});
|
|
29
|
+
this.factory = factory;
|
|
30
30
|
}
|
|
31
31
|
createPrice(variantSku, mode) {
|
|
32
32
|
const seed = calcSeed(variantSku);
|
|
@@ -45,7 +45,6 @@ class FakePriceProvider extends PriceProvider {
|
|
|
45
45
|
minimumQuantity: this.faker.number.int({ min: 2, max: 5 }),
|
|
46
46
|
price: {
|
|
47
47
|
value: price * 0.8,
|
|
48
|
-
// 20% discount for tier 1
|
|
49
48
|
currency: this.context.languageContext.currencyCode
|
|
50
49
|
}
|
|
51
50
|
});
|
|
@@ -53,7 +52,6 @@ class FakePriceProvider extends PriceProvider {
|
|
|
53
52
|
minimumQuantity: this.faker.number.int({ min: 6, max: 10 }),
|
|
54
53
|
price: {
|
|
55
54
|
value: price * 0.6,
|
|
56
|
-
// 40% discount for tier 2
|
|
57
55
|
currency: this.context.languageContext.currencyCode
|
|
58
56
|
}
|
|
59
57
|
});
|
|
@@ -73,16 +71,12 @@ class FakePriceProvider extends PriceProvider {
|
|
|
73
71
|
};
|
|
74
72
|
}
|
|
75
73
|
async getListPrice(payload) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
return success(this.createPrice(payload.variant.sku, "list"));
|
|
74
|
+
const base2 = payload.variant.sku === "unknown-sku" ? this.createEmptyPriceResult(payload.variant.sku) : this.createPrice(payload.variant.sku, "list");
|
|
75
|
+
return success(this.factory.parsePrice(this.context, base2));
|
|
80
76
|
}
|
|
81
77
|
async getCustomerPrice(payload) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
return success(this.createPrice(payload.variant.sku, "customer"));
|
|
78
|
+
const base2 = payload.variant.sku === "unknown-sku" ? this.createEmptyPriceResult(payload.variant.sku) : this.createPrice(payload.variant.sku, "customer");
|
|
79
|
+
return success(this.factory.parsePrice(this.context, base2));
|
|
86
80
|
}
|
|
87
81
|
}
|
|
88
82
|
__decorateClass([
|
|
@@ -14,12 +14,13 @@ import {
|
|
|
14
14
|
Reactionary,
|
|
15
15
|
success
|
|
16
16
|
} from "@reactionary/core";
|
|
17
|
-
import {
|
|
17
|
+
import { en, Faker } from "@faker-js/faker";
|
|
18
18
|
import { calcSeed } from "../utilities/seed.js";
|
|
19
19
|
class FakeProductAssociationsProvider extends ProductAssociationsProvider {
|
|
20
|
-
constructor(config, cache, context) {
|
|
20
|
+
constructor(config, cache, context, factory) {
|
|
21
21
|
super(cache, context);
|
|
22
22
|
this.config = config;
|
|
23
|
+
this.factory = factory;
|
|
23
24
|
this.faker = new Faker({ locale: [en] });
|
|
24
25
|
}
|
|
25
26
|
async getAccessories(query) {
|
|
@@ -31,7 +32,7 @@ class FakeProductAssociationsProvider extends ProductAssociationsProvider {
|
|
|
31
32
|
associationReturnType: "productSearchResultItem",
|
|
32
33
|
product
|
|
33
34
|
}));
|
|
34
|
-
return success(result);
|
|
35
|
+
return success(result.map((x) => this.factory.parseAssociation(this.context, x)));
|
|
35
36
|
}
|
|
36
37
|
async getSpareparts(query) {
|
|
37
38
|
const associatedProducts = this.generateFakeAssociatedProducts(query.forProduct.key, query.numberOfSpareparts || 4, "sparepart");
|
|
@@ -42,7 +43,7 @@ class FakeProductAssociationsProvider extends ProductAssociationsProvider {
|
|
|
42
43
|
associationReturnType: "productSearchResultItem",
|
|
43
44
|
product
|
|
44
45
|
}));
|
|
45
|
-
return success(result);
|
|
46
|
+
return success(result.map((x) => this.factory.parseAssociation(this.context, x)));
|
|
46
47
|
}
|
|
47
48
|
async getReplacements(query) {
|
|
48
49
|
const associatedProducts = this.generateFakeAssociatedProducts(query.forProduct.key, query.numberOfReplacements || 4, "replacement");
|
|
@@ -53,7 +54,7 @@ class FakeProductAssociationsProvider extends ProductAssociationsProvider {
|
|
|
53
54
|
associationReturnType: "productSearchResultItem",
|
|
54
55
|
product
|
|
55
56
|
}));
|
|
56
|
-
return success(result);
|
|
57
|
+
return success(result.map((x) => this.factory.parseAssociation(this.context, x)));
|
|
57
58
|
}
|
|
58
59
|
generateFakeAssociatedProducts(baseProductKey, count, type) {
|
|
59
60
|
const products = [];
|