@reactionary/provider-fake 0.0.36 → 0.0.38
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 +9 -1
- package/index.js +1 -7
- package/package.json +3 -3
- package/providers/cart.provider.js +56 -4
- package/providers/category.provider.js +122 -0
- package/providers/index.js +8 -0
- package/providers/inventory.provider.js +20 -10
- package/providers/price.provider.js +35 -4
- package/providers/product.provider.js +0 -2
- package/schema/capabilities.schema.js +3 -1
- package/schema/configuration.schema.js +5 -0
- package/src/core/initialize.d.ts +3 -1
- package/src/index.d.ts +1 -7
- package/src/providers/cart.provider.d.ts +2 -0
- package/src/providers/category.provider.d.ts +19 -0
- package/src/providers/index.d.ts +8 -0
- package/src/providers/price.provider.d.ts +1 -0
- package/src/providers/search.provider.d.ts +2 -2
- package/src/schema/capabilities.schema.d.ts +4 -2
- package/src/schema/configuration.schema.d.ts +9 -0
package/core/initialize.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { ProductSchema, SearchResultSchema } from "@reactionary/core";
|
|
1
|
+
import { ProductSchema, SearchResultSchema, CategorySchema, CartSchema } from "@reactionary/core";
|
|
2
2
|
import { FakeProductProvider } from "../providers/product.provider";
|
|
3
3
|
import { FakeSearchProvider } from "../providers/search.provider";
|
|
4
|
+
import { FakeCategoryProvider } from "../providers/category.provider";
|
|
5
|
+
import { FakeCartProvider } from "../providers";
|
|
4
6
|
function withFakeCapabilities(configuration, capabilities) {
|
|
5
7
|
return (cache) => {
|
|
6
8
|
const client = {};
|
|
@@ -10,6 +12,12 @@ function withFakeCapabilities(configuration, capabilities) {
|
|
|
10
12
|
if (capabilities.search) {
|
|
11
13
|
client.search = new FakeSearchProvider(configuration, SearchResultSchema, cache);
|
|
12
14
|
}
|
|
15
|
+
if (capabilities.category) {
|
|
16
|
+
client.category = new FakeCategoryProvider(configuration, CategorySchema, cache);
|
|
17
|
+
}
|
|
18
|
+
if (capabilities.cart) {
|
|
19
|
+
client.cart = new FakeCartProvider(configuration, CartSchema, cache);
|
|
20
|
+
}
|
|
13
21
|
return client;
|
|
14
22
|
};
|
|
15
23
|
}
|
package/index.js
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
export * from "./core/initialize";
|
|
2
|
-
export * from "./providers/
|
|
3
|
-
export * from "./providers/cart.provider";
|
|
4
|
-
export * from "./providers/identity.provider";
|
|
5
|
-
export * from "./providers/inventory.provider";
|
|
6
|
-
export * from "./providers/price.provider";
|
|
7
|
-
export * from "./providers/product.provider";
|
|
8
|
-
export * from "./providers/search.provider";
|
|
2
|
+
export * from "./providers/";
|
|
9
3
|
export * from "./schema/capabilities.schema";
|
|
10
4
|
export * from "./schema/configuration.schema";
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactionary/provider-fake",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.38",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "src/index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@reactionary/core": "0.0.
|
|
8
|
-
"@reactionary/otel": "0.0.
|
|
7
|
+
"@reactionary/core": "0.0.38",
|
|
8
|
+
"@reactionary/otel": "0.0.38",
|
|
9
9
|
"zod": "4.0.0-beta.20250430T185432",
|
|
10
10
|
"@faker-js/faker": "^9.8.0"
|
|
11
11
|
}
|
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CartProvider
|
|
3
3
|
} from "@reactionary/core";
|
|
4
|
+
import { Faker, en, base } from "@faker-js/faker/.";
|
|
4
5
|
class FakeCartProvider extends CartProvider {
|
|
5
6
|
constructor(config, schema, cache) {
|
|
6
7
|
super(schema, cache);
|
|
7
8
|
this.carts = /* @__PURE__ */ new Map();
|
|
9
|
+
this.generator = new Faker({
|
|
10
|
+
locale: [en, base],
|
|
11
|
+
seed: config.seeds.product
|
|
12
|
+
});
|
|
8
13
|
this.config = config;
|
|
9
14
|
}
|
|
10
15
|
async getById(payload, _session) {
|
|
11
16
|
const cartId = payload.cart.key;
|
|
17
|
+
if (payload.cart.key === "") {
|
|
18
|
+
const result = this.newModel();
|
|
19
|
+
result.meta = {
|
|
20
|
+
cache: { hit: false, key: "empty" },
|
|
21
|
+
placeholder: true
|
|
22
|
+
};
|
|
23
|
+
return this.assert(result);
|
|
24
|
+
}
|
|
12
25
|
if (!this.carts.has(cartId)) {
|
|
13
26
|
const model = this.newModel();
|
|
14
27
|
Object.assign(model, {
|
|
@@ -31,38 +44,77 @@ class FakeCartProvider extends CartProvider {
|
|
|
31
44
|
return cart;
|
|
32
45
|
}
|
|
33
46
|
async add(payload, session) {
|
|
34
|
-
const
|
|
47
|
+
const cartId = payload.cart.key || `cart-${this.generator.string.uuid()}`;
|
|
48
|
+
const cart = await this.getById({ cart: { key: cartId } }, session);
|
|
35
49
|
const existingItemIndex = cart.items.findIndex(
|
|
36
50
|
(item) => item.product.key === payload.product.key
|
|
37
51
|
);
|
|
38
52
|
if (existingItemIndex >= 0) {
|
|
39
53
|
cart.items[existingItemIndex].quantity += payload.quantity;
|
|
40
54
|
} else {
|
|
55
|
+
const price = this.generator.number.int({ min: 100, max: 1e5 }) / 100;
|
|
41
56
|
cart.items.push({
|
|
42
57
|
identifier: { key: `item-${Date.now()}` },
|
|
43
58
|
product: payload.product,
|
|
44
|
-
quantity: payload.quantity
|
|
59
|
+
quantity: payload.quantity,
|
|
60
|
+
price: {
|
|
61
|
+
unitPrice: {
|
|
62
|
+
value: price,
|
|
63
|
+
currency: session.languageContext.currencyCode
|
|
64
|
+
},
|
|
65
|
+
totalPrice: {
|
|
66
|
+
value: 0,
|
|
67
|
+
// Will be calculated below
|
|
68
|
+
currency: session.languageContext.currencyCode
|
|
69
|
+
},
|
|
70
|
+
totalDiscount: {
|
|
71
|
+
value: 0,
|
|
72
|
+
currency: session.languageContext.currencyCode
|
|
73
|
+
},
|
|
74
|
+
unitDiscount: {
|
|
75
|
+
value: 0,
|
|
76
|
+
currency: session.languageContext.currencyCode
|
|
77
|
+
}
|
|
78
|
+
}
|
|
45
79
|
});
|
|
46
80
|
}
|
|
81
|
+
this.recalculateCart(cart);
|
|
47
82
|
return this.assert(cart);
|
|
48
83
|
}
|
|
49
84
|
async remove(payload, session) {
|
|
50
|
-
const
|
|
85
|
+
const cartId = payload.cart.key || `cart-${this.generator.string.uuid()}`;
|
|
86
|
+
const cart = await this.getById({ cart: { key: cartId } }, session);
|
|
51
87
|
cart.items = cart.items.filter(
|
|
52
88
|
(item) => item.identifier.key !== payload.item.key
|
|
53
89
|
);
|
|
90
|
+
this.recalculateCart(cart);
|
|
54
91
|
return this.assert(cart);
|
|
55
92
|
}
|
|
56
93
|
async changeQuantity(payload, session) {
|
|
57
|
-
const
|
|
94
|
+
const cartId = payload.cart.key || `cart-${this.generator.string.uuid()}`;
|
|
95
|
+
const cart = await this.getById({ cart: { key: cartId } }, session);
|
|
58
96
|
const item = cart.items.find(
|
|
59
97
|
(item2) => item2.identifier.key === payload.item.key
|
|
60
98
|
);
|
|
61
99
|
if (item) {
|
|
62
100
|
item.quantity = payload.quantity;
|
|
63
101
|
}
|
|
102
|
+
this.recalculateCart(cart);
|
|
64
103
|
return this.assert(cart);
|
|
65
104
|
}
|
|
105
|
+
recalculateCart(cart) {
|
|
106
|
+
cart.items.forEach((item) => {
|
|
107
|
+
item.price.totalPrice.value = item.price.unitPrice.value * item.quantity;
|
|
108
|
+
});
|
|
109
|
+
cart.price.totalProductPrice = {
|
|
110
|
+
value: cart.items.reduce((sum, item) => sum + item.price.totalPrice.value, 0),
|
|
111
|
+
currency: cart.items[0]?.price.unitPrice.currency || "USD"
|
|
112
|
+
};
|
|
113
|
+
cart.price.grandTotal = {
|
|
114
|
+
value: cart.items.reduce((sum, item) => sum + item.price.totalPrice.value, 0),
|
|
115
|
+
currency: cart.items[0]?.price.unitPrice.currency || "USD"
|
|
116
|
+
};
|
|
117
|
+
}
|
|
66
118
|
}
|
|
67
119
|
export {
|
|
68
120
|
FakeCartProvider
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { CategoryProvider } from "@reactionary/core";
|
|
2
|
+
import { Faker, en, base } from "@faker-js/faker";
|
|
3
|
+
class FakeCategoryProvider extends CategoryProvider {
|
|
4
|
+
constructor(config, schema, cache) {
|
|
5
|
+
super(schema, cache);
|
|
6
|
+
this.topCategories = new Array();
|
|
7
|
+
this.childCategories = /* @__PURE__ */ new Map();
|
|
8
|
+
this.allCategories = /* @__PURE__ */ new Map();
|
|
9
|
+
this.config = config;
|
|
10
|
+
this.categoryGenerator = new Faker({
|
|
11
|
+
seed: this.config.seeds.category,
|
|
12
|
+
locale: [en, base]
|
|
13
|
+
});
|
|
14
|
+
for (let i = 0; i < 6; i++) {
|
|
15
|
+
const category = this.generateFakeCategory(void 0, i);
|
|
16
|
+
this.topCategories.push(category);
|
|
17
|
+
}
|
|
18
|
+
this.topCategories.forEach((parentCategory) => {
|
|
19
|
+
const children = new Array();
|
|
20
|
+
for (let j = 0; j < 5; j++) {
|
|
21
|
+
const childCategory = this.generateFakeCategory(parentCategory, j);
|
|
22
|
+
children.push(childCategory);
|
|
23
|
+
const subCategoryChildren = new Array();
|
|
24
|
+
for (let k = 0; k < 5; k++) {
|
|
25
|
+
const subChildCategory = this.generateFakeCategory(childCategory, k);
|
|
26
|
+
subCategoryChildren.push(subChildCategory);
|
|
27
|
+
}
|
|
28
|
+
this.childCategories.set(childCategory.identifier.key, subCategoryChildren);
|
|
29
|
+
}
|
|
30
|
+
this.childCategories.set(parentCategory.identifier.key, children);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
generateFakeCategory(parent, index) {
|
|
34
|
+
let name;
|
|
35
|
+
if (!parent) {
|
|
36
|
+
name = this.categoryGenerator.commerce.department();
|
|
37
|
+
} else {
|
|
38
|
+
name = `${parent.name}-${index}`;
|
|
39
|
+
}
|
|
40
|
+
const category = this.newModel();
|
|
41
|
+
category.identifier = { key: name.toLowerCase().replace(/\s+/g, "-") };
|
|
42
|
+
category.name = name;
|
|
43
|
+
category.text = this.categoryGenerator.lorem.sentences(3);
|
|
44
|
+
category.slug = category.identifier.key + "-slug";
|
|
45
|
+
if (parent) {
|
|
46
|
+
category.parentCategory = parent.identifier;
|
|
47
|
+
}
|
|
48
|
+
this.allCategories.set(category.identifier.key, category);
|
|
49
|
+
return category;
|
|
50
|
+
}
|
|
51
|
+
async getById(payload, session) {
|
|
52
|
+
const category = this.allCategories.get(payload.id.key);
|
|
53
|
+
if (!category) {
|
|
54
|
+
const dummyCategory = this.newModel();
|
|
55
|
+
dummyCategory.meta.placeholder = true;
|
|
56
|
+
dummyCategory.identifier = { key: payload.id.key };
|
|
57
|
+
return dummyCategory;
|
|
58
|
+
}
|
|
59
|
+
return category;
|
|
60
|
+
}
|
|
61
|
+
getBySlug(payload, session) {
|
|
62
|
+
for (const p of this.allCategories.values()) {
|
|
63
|
+
if (p.slug === payload.slug) {
|
|
64
|
+
return Promise.resolve(p);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return Promise.resolve(null);
|
|
68
|
+
}
|
|
69
|
+
getBreadcrumbPathToCategory(payload, session) {
|
|
70
|
+
const path = new Array();
|
|
71
|
+
let category = this.allCategories.get(payload.id.key);
|
|
72
|
+
path.push(category);
|
|
73
|
+
while (category?.parentCategory) {
|
|
74
|
+
category = this.allCategories.get(category.parentCategory.key);
|
|
75
|
+
if (category) {
|
|
76
|
+
path.unshift(category);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return Promise.resolve(path);
|
|
80
|
+
}
|
|
81
|
+
async findChildCategories(payload, session) {
|
|
82
|
+
const children = this.childCategories.get(payload.parentId.key);
|
|
83
|
+
const page = children?.slice((payload.paginationOptions.pageNumber - 1) * payload.paginationOptions.pageSize, payload.paginationOptions.pageNumber * payload.paginationOptions.pageSize);
|
|
84
|
+
const res = {
|
|
85
|
+
meta: {
|
|
86
|
+
placeholder: false,
|
|
87
|
+
cache: {
|
|
88
|
+
hit: false,
|
|
89
|
+
key: "child-categories-" + payload.parentId.key + "-" + payload.paginationOptions.pageNumber + "-" + payload.paginationOptions.pageSize
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
items: page ? page : [],
|
|
93
|
+
totalCount: children ? children.length : 0,
|
|
94
|
+
pageNumber: payload.paginationOptions.pageNumber,
|
|
95
|
+
pageSize: payload.paginationOptions.pageSize,
|
|
96
|
+
totalPages: children ? Math.ceil(children.length / payload.paginationOptions.pageSize) : 1
|
|
97
|
+
};
|
|
98
|
+
return Promise.resolve(res);
|
|
99
|
+
}
|
|
100
|
+
findTopCategories(payload, session) {
|
|
101
|
+
const children = this.topCategories;
|
|
102
|
+
const page = children?.slice((payload.paginationOptions.pageNumber - 1) * payload.paginationOptions.pageSize, payload.paginationOptions.pageNumber * payload.paginationOptions.pageSize);
|
|
103
|
+
const res = {
|
|
104
|
+
meta: {
|
|
105
|
+
placeholder: false,
|
|
106
|
+
cache: {
|
|
107
|
+
hit: false,
|
|
108
|
+
key: "top-" + payload.paginationOptions.pageNumber + "-" + payload.paginationOptions.pageSize
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
items: page ? page : [],
|
|
112
|
+
totalCount: children ? children.length : 0,
|
|
113
|
+
pageNumber: payload.paginationOptions.pageNumber,
|
|
114
|
+
pageSize: payload.paginationOptions.pageSize,
|
|
115
|
+
totalPages: children ? Math.ceil(children.length / payload.paginationOptions.pageSize) : 1
|
|
116
|
+
};
|
|
117
|
+
return Promise.resolve(res);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
export {
|
|
121
|
+
FakeCategoryProvider
|
|
122
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./analytics.provider";
|
|
2
|
+
export * from "./cart.provider";
|
|
3
|
+
export * from "./category.provider";
|
|
4
|
+
export * from "./identity.provider";
|
|
5
|
+
export * from "./inventory.provider";
|
|
6
|
+
export * from "./price.provider";
|
|
7
|
+
export * from "./product.provider";
|
|
8
|
+
export * from "./search.provider";
|
|
@@ -9,7 +9,7 @@ class FakeInventoryProvider extends InventoryProvider {
|
|
|
9
9
|
}
|
|
10
10
|
async getBySKU(payload, _session) {
|
|
11
11
|
let hash = 0;
|
|
12
|
-
const skuString = payload.sku;
|
|
12
|
+
const skuString = payload.sku.key;
|
|
13
13
|
for (let i = 0; i < skuString.length; i++) {
|
|
14
14
|
hash = (hash << 5) - hash + skuString.charCodeAt(i);
|
|
15
15
|
hash = hash & hash;
|
|
@@ -19,16 +19,26 @@ class FakeInventoryProvider extends InventoryProvider {
|
|
|
19
19
|
locale: [en, base]
|
|
20
20
|
});
|
|
21
21
|
const model = this.newModel();
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
hit: false,
|
|
27
|
-
key: payload.sku
|
|
28
|
-
},
|
|
29
|
-
placeholder: false
|
|
22
|
+
model.identifier = {
|
|
23
|
+
sku: { key: skuString },
|
|
24
|
+
channelId: {
|
|
25
|
+
key: "online"
|
|
30
26
|
}
|
|
31
|
-
}
|
|
27
|
+
};
|
|
28
|
+
model.sku = skuString;
|
|
29
|
+
model.quantity = generator.number.int({ min: 0, max: 100 });
|
|
30
|
+
if (model.quantity > 0) {
|
|
31
|
+
model.status = "inStock";
|
|
32
|
+
} else {
|
|
33
|
+
model.status = "outOfStock";
|
|
34
|
+
}
|
|
35
|
+
model.meta = {
|
|
36
|
+
cache: {
|
|
37
|
+
hit: false,
|
|
38
|
+
key: this.generateCacheKeySingle(model.identifier, _session)
|
|
39
|
+
},
|
|
40
|
+
placeholder: false
|
|
41
|
+
};
|
|
32
42
|
return this.assert(model);
|
|
33
43
|
}
|
|
34
44
|
}
|
|
@@ -7,7 +7,15 @@ class FakePriceProvider extends PriceProvider {
|
|
|
7
7
|
super(schema, cache);
|
|
8
8
|
this.config = config;
|
|
9
9
|
}
|
|
10
|
+
async getBySKUs(payload, session) {
|
|
11
|
+
const promises = payload.map((p) => this.getBySKU(p, session));
|
|
12
|
+
const result = await Promise.all(promises);
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
10
15
|
async getBySKU(payload, _session) {
|
|
16
|
+
if (payload.sku.key === "unknown-sku") {
|
|
17
|
+
return this.getEmptyPriceResult(payload.sku.key, _session.languageContext.currencyCode);
|
|
18
|
+
}
|
|
11
19
|
let hash = 0;
|
|
12
20
|
const skuString = payload.sku.key;
|
|
13
21
|
for (let i = 0; i < skuString.length; i++) {
|
|
@@ -23,18 +31,41 @@ class FakePriceProvider extends PriceProvider {
|
|
|
23
31
|
identifier: {
|
|
24
32
|
sku: payload.sku
|
|
25
33
|
},
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
currency:
|
|
34
|
+
unitPrice: {
|
|
35
|
+
value: generator.number.int({ min: 300, max: 1e5 }) / 100,
|
|
36
|
+
currency: _session.languageContext.currencyCode
|
|
29
37
|
},
|
|
30
38
|
meta: {
|
|
31
39
|
cache: {
|
|
32
40
|
hit: false,
|
|
33
|
-
key: payload.sku
|
|
41
|
+
key: payload.sku.key
|
|
34
42
|
},
|
|
35
43
|
placeholder: false
|
|
36
44
|
}
|
|
37
45
|
});
|
|
46
|
+
if (skuString.includes("with-tiers")) {
|
|
47
|
+
const unitPrice = model.unitPrice?.value || 0;
|
|
48
|
+
const tier1Price = unitPrice * 0.8;
|
|
49
|
+
const tier2Price = tier1Price * 0.8;
|
|
50
|
+
model.tieredPrices = [
|
|
51
|
+
{
|
|
52
|
+
minimumQuantity: generator.number.int({ min: 2, max: 5 }),
|
|
53
|
+
price: {
|
|
54
|
+
value: tier1Price,
|
|
55
|
+
currency: _session.languageContext.currencyCode
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
minimumQuantity: generator.number.int({ min: 6, max: 10 }),
|
|
60
|
+
price: {
|
|
61
|
+
value: tier2Price,
|
|
62
|
+
currency: _session.languageContext.currencyCode
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
];
|
|
66
|
+
} else {
|
|
67
|
+
model.tieredPrices = [];
|
|
68
|
+
}
|
|
38
69
|
return this.assert(model);
|
|
39
70
|
}
|
|
40
71
|
}
|
|
@@ -2,13 +2,11 @@ import {
|
|
|
2
2
|
ProductProvider
|
|
3
3
|
} from "@reactionary/core";
|
|
4
4
|
import { base, en, Faker } from "@faker-js/faker";
|
|
5
|
-
import { traced } from "@reactionary/otel";
|
|
6
5
|
class FakeProductProvider extends ProductProvider {
|
|
7
6
|
constructor(config, schema, cache) {
|
|
8
7
|
super(schema, cache);
|
|
9
8
|
this.config = config;
|
|
10
9
|
}
|
|
11
|
-
@traced()
|
|
12
10
|
async getById(payload, _session) {
|
|
13
11
|
return this.parseSingle(payload);
|
|
14
12
|
}
|
|
@@ -2,7 +2,9 @@ import { CapabilitiesSchema } from "@reactionary/core";
|
|
|
2
2
|
const FakeCapabilitiesSchema = CapabilitiesSchema.pick({
|
|
3
3
|
product: true,
|
|
4
4
|
search: true,
|
|
5
|
-
identity: true
|
|
5
|
+
identity: true,
|
|
6
|
+
category: true,
|
|
7
|
+
cart: true
|
|
6
8
|
}).partial();
|
|
7
9
|
export {
|
|
8
10
|
FakeCapabilitiesSchema
|
|
@@ -6,6 +6,11 @@ const FakeConfigurationSchema = z.looseInterface({
|
|
|
6
6
|
}).default({
|
|
7
7
|
mean: 0,
|
|
8
8
|
deviation: 0
|
|
9
|
+
}),
|
|
10
|
+
seeds: z.looseInterface({
|
|
11
|
+
product: z.number().min(0).max(1e4).default(1),
|
|
12
|
+
search: z.number().min(0).max(1e4).default(1),
|
|
13
|
+
category: z.number().min(0).max(1e4).default(1)
|
|
9
14
|
})
|
|
10
15
|
});
|
|
11
16
|
export {
|
package/src/core/initialize.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { Cache as ReactinaryCache, ProductProvider, SearchProvider, IdentityProvider } from "@reactionary/core";
|
|
1
|
+
import { Cache as ReactinaryCache, ProductProvider, SearchProvider, IdentityProvider, CategoryProvider, CartProvider } from "@reactionary/core";
|
|
2
2
|
import { FakeConfiguration } from "../schema/configuration.schema";
|
|
3
3
|
import { FakeCapabilities } from "../schema/capabilities.schema";
|
|
4
4
|
type FakeClient<T extends FakeCapabilities> = Partial<{
|
|
5
|
+
cart: T['cart'] extends true ? CartProvider : never;
|
|
5
6
|
product: T['product'] extends true ? ProductProvider : never;
|
|
6
7
|
search: T['search'] extends true ? SearchProvider : never;
|
|
7
8
|
identity: T['identity'] extends true ? IdentityProvider : never;
|
|
9
|
+
category: T['category'] extends true ? CategoryProvider : never;
|
|
8
10
|
}>;
|
|
9
11
|
export declare function withFakeCapabilities<T extends FakeCapabilities>(configuration: FakeConfiguration, capabilities: T): (cache: ReactinaryCache) => FakeClient<T>;
|
|
10
12
|
export {};
|
package/src/index.d.ts
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
export * from './core/initialize';
|
|
2
|
-
export * from './providers/
|
|
3
|
-
export * from './providers/cart.provider';
|
|
4
|
-
export * from './providers/identity.provider';
|
|
5
|
-
export * from './providers/inventory.provider';
|
|
6
|
-
export * from './providers/price.provider';
|
|
7
|
-
export * from './providers/product.provider';
|
|
8
|
-
export * from './providers/search.provider';
|
|
2
|
+
export * from './providers/';
|
|
9
3
|
export * from './schema/capabilities.schema';
|
|
10
4
|
export * from './schema/configuration.schema';
|
|
@@ -4,9 +4,11 @@ import { FakeConfiguration } from '../schema/configuration.schema';
|
|
|
4
4
|
export declare class FakeCartProvider<T extends Cart = Cart> extends CartProvider<T> {
|
|
5
5
|
protected config: FakeConfiguration;
|
|
6
6
|
private carts;
|
|
7
|
+
private generator;
|
|
7
8
|
constructor(config: FakeConfiguration, schema: z.ZodType<T>, cache: Cache);
|
|
8
9
|
getById(payload: CartQueryById, _session: Session): Promise<T>;
|
|
9
10
|
add(payload: CartMutationItemAdd, session: Session): Promise<T>;
|
|
10
11
|
remove(payload: CartMutationItemRemove, session: Session): Promise<T>;
|
|
11
12
|
changeQuantity(payload: CartMutationItemQuantityChange, session: Session): Promise<T>;
|
|
13
|
+
protected recalculateCart(cart: T): void;
|
|
12
14
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Category, CategoryProvider, CategoryQueryById, CategoryQueryBySlug, CategoryQueryForBreadcrumb, CategoryQueryForChildCategories, CategoryQueryForTopCategories, Session } from "@reactionary/core";
|
|
2
|
+
import { FakeConfiguration } from "../schema/configuration.schema";
|
|
3
|
+
import { Cache as ReactionaryCache } from "@reactionary/core";
|
|
4
|
+
import z from "zod";
|
|
5
|
+
import { Faker } from '@faker-js/faker';
|
|
6
|
+
export declare class FakeCategoryProvider<T extends Category = Category> extends CategoryProvider<T> {
|
|
7
|
+
protected config: FakeConfiguration;
|
|
8
|
+
protected topCategories: T[];
|
|
9
|
+
protected childCategories: Map<string, T[]>;
|
|
10
|
+
protected allCategories: Map<string, T>;
|
|
11
|
+
protected categoryGenerator: Faker;
|
|
12
|
+
protected generateFakeCategory(parent: Category | undefined, index: number): T;
|
|
13
|
+
constructor(config: FakeConfiguration, schema: z.ZodType<T>, cache: ReactionaryCache);
|
|
14
|
+
getById(payload: CategoryQueryById, session: Session): Promise<T>;
|
|
15
|
+
getBySlug(payload: CategoryQueryBySlug, session: Session): Promise<T | null>;
|
|
16
|
+
getBreadcrumbPathToCategory(payload: CategoryQueryForBreadcrumb, session: Session): Promise<T[]>;
|
|
17
|
+
findChildCategories(payload: CategoryQueryForChildCategories, session: Session): Promise<ReturnType<typeof this.parsePaginatedResult>>;
|
|
18
|
+
findTopCategories(payload: CategoryQueryForTopCategories, session: Session): Promise<ReturnType<typeof this.parsePaginatedResult>>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './analytics.provider';
|
|
2
|
+
export * from './cart.provider';
|
|
3
|
+
export * from './category.provider';
|
|
4
|
+
export * from './identity.provider';
|
|
5
|
+
export * from './inventory.provider';
|
|
6
|
+
export * from './price.provider';
|
|
7
|
+
export * from './product.provider';
|
|
8
|
+
export * from './search.provider';
|
|
@@ -4,5 +4,6 @@ import { FakeConfiguration } from '../schema/configuration.schema';
|
|
|
4
4
|
export declare class FakePriceProvider<T extends Price = Price> extends PriceProvider<T> {
|
|
5
5
|
protected config: FakeConfiguration;
|
|
6
6
|
constructor(config: FakeConfiguration, schema: z.ZodType<T>, cache: Cache);
|
|
7
|
+
getBySKUs(payload: PriceQueryBySku[], session: Session): Promise<T[]>;
|
|
7
8
|
getBySKU(payload: PriceQueryBySku, _session: Session): Promise<T>;
|
|
8
9
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { SearchProvider, SearchQueryByTerm, SearchResult, Session, Cache as
|
|
1
|
+
import { SearchProvider, SearchQueryByTerm, SearchResult, Session, Cache as ReactionaryCache } from '@reactionary/core';
|
|
2
2
|
import z from 'zod';
|
|
3
3
|
import { FakeConfiguration } from '../schema/configuration.schema';
|
|
4
4
|
export declare class FakeSearchProvider<T extends SearchResult = SearchResult> extends SearchProvider<T> {
|
|
5
5
|
protected config: FakeConfiguration;
|
|
6
|
-
constructor(config: FakeConfiguration, schema: z.ZodType<T>, cache:
|
|
6
|
+
constructor(config: FakeConfiguration, schema: z.ZodType<T>, cache: ReactionaryCache);
|
|
7
7
|
queryByTerm(payload: SearchQueryByTerm, _session: Session): Promise<SearchResult>;
|
|
8
8
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
export declare const FakeCapabilitiesSchema: z.ZodInterface<{
|
|
3
3
|
identity: z.ZodOptional<z.ZodBoolean>;
|
|
4
|
-
search: z.ZodOptional<z.ZodBoolean>;
|
|
5
4
|
product: z.ZodOptional<z.ZodBoolean>;
|
|
5
|
+
search: z.ZodOptional<z.ZodBoolean>;
|
|
6
|
+
cart: z.ZodOptional<z.ZodBoolean>;
|
|
7
|
+
category: z.ZodOptional<z.ZodBoolean>;
|
|
6
8
|
}, {
|
|
7
|
-
optional: "identity" | "search" | "
|
|
9
|
+
optional: "identity" | "product" | "search" | "cart" | "category";
|
|
8
10
|
defaulted: never;
|
|
9
11
|
extra: Record<string, unknown>;
|
|
10
12
|
}>;
|
|
@@ -8,6 +8,15 @@ export declare const FakeConfigurationSchema: z.ZodInterface<{
|
|
|
8
8
|
defaulted: never;
|
|
9
9
|
extra: Record<string, unknown>;
|
|
10
10
|
}>>;
|
|
11
|
+
seeds: z.ZodInterface<{
|
|
12
|
+
product: z.ZodDefault<z.ZodNumber>;
|
|
13
|
+
search: z.ZodDefault<z.ZodNumber>;
|
|
14
|
+
category: z.ZodDefault<z.ZodNumber>;
|
|
15
|
+
}, {
|
|
16
|
+
optional: never;
|
|
17
|
+
defaulted: never;
|
|
18
|
+
extra: Record<string, unknown>;
|
|
19
|
+
}>;
|
|
11
20
|
}, {
|
|
12
21
|
optional: never;
|
|
13
22
|
defaulted: never;
|