@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,89 @@
|
|
|
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
|
+
IdentityMutationLoginSchema,
|
|
14
|
+
IdentityMutationLogoutSchema,
|
|
15
|
+
IdentityMutationRegisterSchema,
|
|
16
|
+
IdentityQuerySelfSchema,
|
|
17
|
+
IdentityCapability,
|
|
18
|
+
IdentitySchema,
|
|
19
|
+
Reactionary,
|
|
20
|
+
success
|
|
21
|
+
} from "@reactionary/core";
|
|
22
|
+
import { base, en, Faker } from "@faker-js/faker";
|
|
23
|
+
class FakeIdentityCapability extends IdentityCapability {
|
|
24
|
+
config;
|
|
25
|
+
factory;
|
|
26
|
+
currentIdentity = null;
|
|
27
|
+
constructor(config, cache, context, factory) {
|
|
28
|
+
super(cache, context);
|
|
29
|
+
this.config = config;
|
|
30
|
+
this.factory = factory;
|
|
31
|
+
}
|
|
32
|
+
async getSelf(_payload) {
|
|
33
|
+
if (!this.currentIdentity) {
|
|
34
|
+
this.currentIdentity = {
|
|
35
|
+
type: "Anonymous"
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return success(this.factory.parseIdentity(this.context, this.currentIdentity));
|
|
39
|
+
}
|
|
40
|
+
async login(_payload) {
|
|
41
|
+
const generator = new Faker({
|
|
42
|
+
seed: 42,
|
|
43
|
+
locale: [en, base]
|
|
44
|
+
});
|
|
45
|
+
this.currentIdentity = {
|
|
46
|
+
type: "Registered",
|
|
47
|
+
id: {
|
|
48
|
+
userId: generator.string.alphanumeric(32)
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
return success(this.factory.parseIdentity(this.context, this.currentIdentity));
|
|
52
|
+
}
|
|
53
|
+
async logout(_payload) {
|
|
54
|
+
this.currentIdentity = {
|
|
55
|
+
type: "Anonymous"
|
|
56
|
+
};
|
|
57
|
+
return success(this.factory.parseIdentity(this.context, this.currentIdentity));
|
|
58
|
+
}
|
|
59
|
+
register(_payload) {
|
|
60
|
+
throw new Error("Method not implemented.");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
__decorateClass([
|
|
64
|
+
Reactionary({
|
|
65
|
+
inputSchema: IdentityQuerySelfSchema,
|
|
66
|
+
outputSchema: IdentitySchema
|
|
67
|
+
})
|
|
68
|
+
], FakeIdentityCapability.prototype, "getSelf", 1);
|
|
69
|
+
__decorateClass([
|
|
70
|
+
Reactionary({
|
|
71
|
+
inputSchema: IdentityMutationLoginSchema,
|
|
72
|
+
outputSchema: IdentitySchema
|
|
73
|
+
})
|
|
74
|
+
], FakeIdentityCapability.prototype, "login", 1);
|
|
75
|
+
__decorateClass([
|
|
76
|
+
Reactionary({
|
|
77
|
+
inputSchema: IdentityMutationLogoutSchema,
|
|
78
|
+
outputSchema: IdentitySchema
|
|
79
|
+
})
|
|
80
|
+
], FakeIdentityCapability.prototype, "logout", 1);
|
|
81
|
+
__decorateClass([
|
|
82
|
+
Reactionary({
|
|
83
|
+
inputSchema: IdentityMutationRegisterSchema,
|
|
84
|
+
outputSchema: IdentitySchema
|
|
85
|
+
})
|
|
86
|
+
], FakeIdentityCapability.prototype, "register", 1);
|
|
87
|
+
export {
|
|
88
|
+
FakeIdentityCapability
|
|
89
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from "./analytics.capability.js";
|
|
2
|
+
export * from "./cart.capability.js";
|
|
3
|
+
export * from "./category.capability.js";
|
|
4
|
+
export * from "./checkout.capability.js";
|
|
5
|
+
export * from "./identity.capability.js";
|
|
6
|
+
export * from "./inventory.capability.js";
|
|
7
|
+
export * from "./order-search.capability.js";
|
|
8
|
+
export * from "./order.capability.js";
|
|
9
|
+
export * from "./price.capability.js";
|
|
10
|
+
export * from "./product.capability.js";
|
|
11
|
+
export * from "./product-associations.capability.js";
|
|
12
|
+
export * from "./product-reviews.capability.js";
|
|
13
|
+
export * from "./product-search.capability.js";
|
|
14
|
+
export * from "./profile.capability.js";
|
|
15
|
+
export * from "./store.capability.js";
|
|
@@ -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 { base, en, Faker } from "@faker-js/faker";
|
|
13
|
+
import {
|
|
14
|
+
InventoryCapability,
|
|
15
|
+
InventoryQueryBySKUSchema,
|
|
16
|
+
InventorySchema,
|
|
17
|
+
Reactionary,
|
|
18
|
+
success
|
|
19
|
+
} from "@reactionary/core";
|
|
20
|
+
class FakeInventoryCapability extends InventoryCapability {
|
|
21
|
+
config;
|
|
22
|
+
factory;
|
|
23
|
+
constructor(config, cache, context, factory) {
|
|
24
|
+
super(cache, context);
|
|
25
|
+
this.config = config;
|
|
26
|
+
this.factory = factory;
|
|
27
|
+
}
|
|
28
|
+
async getBySKU(payload) {
|
|
29
|
+
let hash = 0;
|
|
30
|
+
for (let i = 0; i < payload.variant.sku.length; i++) {
|
|
31
|
+
hash = (hash << 5) - hash + payload.variant.sku.charCodeAt(i);
|
|
32
|
+
hash &= hash;
|
|
33
|
+
}
|
|
34
|
+
const generator = new Faker({
|
|
35
|
+
seed: hash || 42,
|
|
36
|
+
locale: [en, base]
|
|
37
|
+
});
|
|
38
|
+
const quantity = generator.number.int({ min: 0, max: 100 });
|
|
39
|
+
const status = quantity > 0 ? "inStock" : "outOfStock";
|
|
40
|
+
const result = {
|
|
41
|
+
identifier: {
|
|
42
|
+
variant: payload.variant,
|
|
43
|
+
fulfillmentCenter: payload.fulfilmentCenter
|
|
44
|
+
},
|
|
45
|
+
quantity,
|
|
46
|
+
status
|
|
47
|
+
};
|
|
48
|
+
return success(this.factory.parseInventory(this.context, result));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
__decorateClass([
|
|
52
|
+
Reactionary({
|
|
53
|
+
inputSchema: InventoryQueryBySKUSchema,
|
|
54
|
+
outputSchema: InventorySchema
|
|
55
|
+
})
|
|
56
|
+
], FakeInventoryCapability.prototype, "getBySKU", 1);
|
|
57
|
+
export {
|
|
58
|
+
FakeInventoryCapability
|
|
59
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
OrderSearchCapability,
|
|
14
|
+
OrderSearchQueryByTermSchema,
|
|
15
|
+
OrderSearchResultSchema,
|
|
16
|
+
Reactionary,
|
|
17
|
+
success
|
|
18
|
+
} from "@reactionary/core";
|
|
19
|
+
import { Faker, en, base } from "@faker-js/faker";
|
|
20
|
+
class FakeOrderSearchCapability extends OrderSearchCapability {
|
|
21
|
+
config;
|
|
22
|
+
generator;
|
|
23
|
+
factory;
|
|
24
|
+
constructor(config, cache, context, factory) {
|
|
25
|
+
super(cache, context);
|
|
26
|
+
this.config = config;
|
|
27
|
+
this.generator = new Faker({
|
|
28
|
+
locale: [en, base],
|
|
29
|
+
seed: config.seeds.product
|
|
30
|
+
});
|
|
31
|
+
this.factory = factory;
|
|
32
|
+
}
|
|
33
|
+
async queryByTerm(payload) {
|
|
34
|
+
const items = [];
|
|
35
|
+
for (let i = 0; i < payload.search.paginationOptions.pageSize; i++) {
|
|
36
|
+
items.push({
|
|
37
|
+
customerName: this.generator.company.name(),
|
|
38
|
+
identifier: {
|
|
39
|
+
key: this.generator.string.uuid()
|
|
40
|
+
},
|
|
41
|
+
inventoryStatus: "Allocated",
|
|
42
|
+
orderDate: this.generator.date.past().toString(),
|
|
43
|
+
orderStatus: "Shipped",
|
|
44
|
+
totalAmount: {
|
|
45
|
+
currency: "USD",
|
|
46
|
+
value: this.generator.number.int({ multipleOf: 100 })
|
|
47
|
+
},
|
|
48
|
+
userId: {
|
|
49
|
+
userId: "1234"
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
const totalCount = this.generator.number.int({ min: items.length, max: 200 });
|
|
54
|
+
const totalPages = Math.ceil(totalCount / payload.search.paginationOptions.pageSize);
|
|
55
|
+
const result = {
|
|
56
|
+
identifier: payload.search,
|
|
57
|
+
items,
|
|
58
|
+
pageNumber: payload.search.paginationOptions.pageNumber,
|
|
59
|
+
pageSize: payload.search.paginationOptions.pageSize,
|
|
60
|
+
totalCount,
|
|
61
|
+
totalPages
|
|
62
|
+
};
|
|
63
|
+
return success(this.factory.parseOrderSearchResult(this.context, result, payload));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
__decorateClass([
|
|
67
|
+
Reactionary({
|
|
68
|
+
inputSchema: OrderSearchQueryByTermSchema,
|
|
69
|
+
outputSchema: OrderSearchResultSchema
|
|
70
|
+
})
|
|
71
|
+
], FakeOrderSearchCapability.prototype, "queryByTerm", 1);
|
|
72
|
+
export {
|
|
73
|
+
FakeOrderSearchCapability
|
|
74
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
OrderCapability,
|
|
14
|
+
OrderQueryByIdSchema,
|
|
15
|
+
OrderSchema,
|
|
16
|
+
Reactionary,
|
|
17
|
+
success
|
|
18
|
+
} from "@reactionary/core";
|
|
19
|
+
import { Faker, en, base } from "@faker-js/faker";
|
|
20
|
+
class FakeOrderCapability extends OrderCapability {
|
|
21
|
+
config;
|
|
22
|
+
generator;
|
|
23
|
+
factory;
|
|
24
|
+
constructor(config, cache, context, factory) {
|
|
25
|
+
super(cache, context);
|
|
26
|
+
this.config = config;
|
|
27
|
+
this.generator = new Faker({
|
|
28
|
+
locale: [en, base],
|
|
29
|
+
seed: config.seeds.product
|
|
30
|
+
});
|
|
31
|
+
this.factory = factory;
|
|
32
|
+
}
|
|
33
|
+
async getById(payload) {
|
|
34
|
+
const order = {
|
|
35
|
+
identifier: payload.order,
|
|
36
|
+
inventoryStatus: "Allocated",
|
|
37
|
+
items: [],
|
|
38
|
+
orderStatus: "Shipped",
|
|
39
|
+
paymentInstructions: [],
|
|
40
|
+
userId: {
|
|
41
|
+
userId: "1234"
|
|
42
|
+
},
|
|
43
|
+
price: {
|
|
44
|
+
grandTotal: {
|
|
45
|
+
currency: "USD",
|
|
46
|
+
value: this.generator.number.float({ min: 100, max: 1e4, multipleOf: 25 })
|
|
47
|
+
},
|
|
48
|
+
totalDiscount: {
|
|
49
|
+
currency: "USD",
|
|
50
|
+
value: this.generator.number.float({ min: 100, max: 1e4, multipleOf: 25 })
|
|
51
|
+
},
|
|
52
|
+
totalProductPrice: {
|
|
53
|
+
currency: "USD",
|
|
54
|
+
value: this.generator.number.float({ min: 100, max: 1e4, multipleOf: 25 })
|
|
55
|
+
},
|
|
56
|
+
totalShipping: {
|
|
57
|
+
currency: "USD",
|
|
58
|
+
value: this.generator.number.float({ min: 100, max: 1e4, multipleOf: 25 })
|
|
59
|
+
},
|
|
60
|
+
totalSurcharge: {
|
|
61
|
+
currency: "USD",
|
|
62
|
+
value: this.generator.number.float({ min: 100, max: 1e4, multipleOf: 25 })
|
|
63
|
+
},
|
|
64
|
+
totalTax: {
|
|
65
|
+
currency: "USD",
|
|
66
|
+
value: this.generator.number.float({ min: 100, max: 1e4, multipleOf: 25 })
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
return success(this.factory.parseOrder(this.context, order));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
__decorateClass([
|
|
74
|
+
Reactionary({
|
|
75
|
+
inputSchema: OrderQueryByIdSchema,
|
|
76
|
+
outputSchema: OrderSchema
|
|
77
|
+
})
|
|
78
|
+
], FakeOrderCapability.prototype, "getById", 1);
|
|
79
|
+
export {
|
|
80
|
+
FakeOrderCapability
|
|
81
|
+
};
|
|
@@ -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
|
+
CustomerPriceQuerySchema,
|
|
14
|
+
ListPriceQuerySchema,
|
|
15
|
+
PriceCapability,
|
|
16
|
+
PriceSchema,
|
|
17
|
+
Reactionary,
|
|
18
|
+
success
|
|
19
|
+
} from "@reactionary/core";
|
|
20
|
+
import { base, en, Faker } from "@faker-js/faker";
|
|
21
|
+
import { calcSeed } from "../utilities/seed.js";
|
|
22
|
+
class FakePriceCapability extends PriceCapability {
|
|
23
|
+
config;
|
|
24
|
+
faker;
|
|
25
|
+
factory;
|
|
26
|
+
constructor(config, cache, context, factory) {
|
|
27
|
+
super(cache, context);
|
|
28
|
+
this.config = config;
|
|
29
|
+
this.faker = new Faker({
|
|
30
|
+
locale: [en, base]
|
|
31
|
+
});
|
|
32
|
+
this.factory = factory;
|
|
33
|
+
}
|
|
34
|
+
createPrice(variantSku, mode) {
|
|
35
|
+
const seed = calcSeed(variantSku);
|
|
36
|
+
this.faker.seed(seed);
|
|
37
|
+
let price = this.faker.number.int({ min: 300, max: 1e5 }) / 100;
|
|
38
|
+
let onSale = false;
|
|
39
|
+
if (mode === "customer") {
|
|
40
|
+
onSale = this.faker.datatype.boolean({ probability: 0.1 });
|
|
41
|
+
if (onSale) {
|
|
42
|
+
price = price * this.faker.number.float({ min: 0.5, max: 0.9 });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const tiers = [];
|
|
46
|
+
if (variantSku.includes("with-tiers")) {
|
|
47
|
+
tiers.push({
|
|
48
|
+
minimumQuantity: this.faker.number.int({ min: 2, max: 5 }),
|
|
49
|
+
price: {
|
|
50
|
+
value: price * 0.8,
|
|
51
|
+
currency: this.context.languageContext.currencyCode
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
tiers.push({
|
|
55
|
+
minimumQuantity: this.faker.number.int({ min: 6, max: 10 }),
|
|
56
|
+
price: {
|
|
57
|
+
value: price * 0.6,
|
|
58
|
+
currency: this.context.languageContext.currencyCode
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
identifier: {
|
|
64
|
+
variant: {
|
|
65
|
+
sku: variantSku
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
unitPrice: {
|
|
69
|
+
value: price,
|
|
70
|
+
currency: this.context.languageContext.currencyCode
|
|
71
|
+
},
|
|
72
|
+
onSale,
|
|
73
|
+
tieredPrices: tiers
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
async getListPrice(payload) {
|
|
77
|
+
const base2 = payload.variant.sku === "unknown-sku" ? this.createEmptyPriceResult(payload.variant.sku) : this.createPrice(payload.variant.sku, "list");
|
|
78
|
+
return success(this.factory.parsePrice(this.context, base2));
|
|
79
|
+
}
|
|
80
|
+
async getCustomerPrice(payload) {
|
|
81
|
+
const base2 = payload.variant.sku === "unknown-sku" ? this.createEmptyPriceResult(payload.variant.sku) : this.createPrice(payload.variant.sku, "customer");
|
|
82
|
+
return success(this.factory.parsePrice(this.context, base2));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
__decorateClass([
|
|
86
|
+
Reactionary({
|
|
87
|
+
inputSchema: ListPriceQuerySchema,
|
|
88
|
+
outputSchema: PriceSchema
|
|
89
|
+
})
|
|
90
|
+
], FakePriceCapability.prototype, "getListPrice", 1);
|
|
91
|
+
__decorateClass([
|
|
92
|
+
Reactionary({
|
|
93
|
+
inputSchema: CustomerPriceQuerySchema,
|
|
94
|
+
outputSchema: PriceSchema
|
|
95
|
+
})
|
|
96
|
+
], FakePriceCapability.prototype, "getCustomerPrice", 1);
|
|
97
|
+
export {
|
|
98
|
+
FakePriceCapability
|
|
99
|
+
};
|
|
@@ -0,0 +1,121 @@
|
|
|
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
|
+
ProductAssociationsCapability,
|
|
14
|
+
Reactionary,
|
|
15
|
+
success
|
|
16
|
+
} from "@reactionary/core";
|
|
17
|
+
import { en, Faker } from "@faker-js/faker";
|
|
18
|
+
import { calcSeed } from "../utilities/seed.js";
|
|
19
|
+
class FakeProductAssociationsCapability extends ProductAssociationsCapability {
|
|
20
|
+
config;
|
|
21
|
+
factory;
|
|
22
|
+
faker;
|
|
23
|
+
constructor(config, cache, context, factory) {
|
|
24
|
+
super(cache, context);
|
|
25
|
+
this.config = config;
|
|
26
|
+
this.factory = factory;
|
|
27
|
+
this.faker = new Faker({ locale: [en] });
|
|
28
|
+
}
|
|
29
|
+
async getAccessories(query) {
|
|
30
|
+
const associatedProducts = this.generateFakeAssociatedProducts(query.forProduct.key, query.numberOfAccessories || 4, "accessory");
|
|
31
|
+
const result = associatedProducts.map((product) => ({
|
|
32
|
+
associationIdentifier: {
|
|
33
|
+
key: `${query.forProduct.key}-accessory-${product.identifier.key}`
|
|
34
|
+
},
|
|
35
|
+
associationReturnType: "productSearchResultItem",
|
|
36
|
+
product
|
|
37
|
+
}));
|
|
38
|
+
return success(result.map((x) => this.factory.parseAssociation(this.context, x)));
|
|
39
|
+
}
|
|
40
|
+
async getSpareparts(query) {
|
|
41
|
+
const associatedProducts = this.generateFakeAssociatedProducts(query.forProduct.key, query.numberOfSpareparts || 4, "sparepart");
|
|
42
|
+
const result = associatedProducts.map((product) => ({
|
|
43
|
+
associationIdentifier: {
|
|
44
|
+
key: `${query.forProduct.key}-sparepart-${product.identifier.key}`
|
|
45
|
+
},
|
|
46
|
+
associationReturnType: "productSearchResultItem",
|
|
47
|
+
product
|
|
48
|
+
}));
|
|
49
|
+
return success(result.map((x) => this.factory.parseAssociation(this.context, x)));
|
|
50
|
+
}
|
|
51
|
+
async getReplacements(query) {
|
|
52
|
+
const associatedProducts = this.generateFakeAssociatedProducts(query.forProduct.key, query.numberOfReplacements || 4, "replacement");
|
|
53
|
+
const result = associatedProducts.map((product) => ({
|
|
54
|
+
associationIdentifier: {
|
|
55
|
+
key: `${query.forProduct.key}-replacement-${product.identifier.key}`
|
|
56
|
+
},
|
|
57
|
+
associationReturnType: "productSearchResultItem",
|
|
58
|
+
product
|
|
59
|
+
}));
|
|
60
|
+
return success(result.map((x) => this.factory.parseAssociation(this.context, x)));
|
|
61
|
+
}
|
|
62
|
+
generateFakeAssociatedProducts(baseProductKey, count, type) {
|
|
63
|
+
const products = [];
|
|
64
|
+
const seed = calcSeed(baseProductKey);
|
|
65
|
+
this.faker.seed(seed);
|
|
66
|
+
if (baseProductKey.includes("unknown")) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
if (baseProductKey === "product_100201") {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
const hasAnyAssociations = this.faker.datatype.boolean({ probability: 0.5 });
|
|
73
|
+
if (!hasAnyAssociations) {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
const numberOfAssociations = Math.min(count, this.faker.number.int({ min: 2, max: 12 }));
|
|
77
|
+
for (let i = 0; i < numberOfAssociations; i++) {
|
|
78
|
+
const key = `${baseProductKey}-${type}-${i + 1}`;
|
|
79
|
+
products.push({
|
|
80
|
+
identifier: { key },
|
|
81
|
+
name: `Fake ${type} ${i + 1} for ${baseProductKey}`,
|
|
82
|
+
slug: key,
|
|
83
|
+
variants: [{
|
|
84
|
+
variant: { sku: `${key}-variant` },
|
|
85
|
+
image: {
|
|
86
|
+
sourceUrl: `https://via.placeholder.com/300x300?text=${type}+${i + 1}`,
|
|
87
|
+
altText: `Image for ${type} ${i + 1}`
|
|
88
|
+
}
|
|
89
|
+
}]
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return products;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
__decorateClass([
|
|
96
|
+
Reactionary({
|
|
97
|
+
cache: true,
|
|
98
|
+
cacheTimeToLiveInSeconds: 300,
|
|
99
|
+
currencyDependentCaching: false,
|
|
100
|
+
localeDependentCaching: false
|
|
101
|
+
})
|
|
102
|
+
], FakeProductAssociationsCapability.prototype, "getAccessories", 1);
|
|
103
|
+
__decorateClass([
|
|
104
|
+
Reactionary({
|
|
105
|
+
cache: true,
|
|
106
|
+
cacheTimeToLiveInSeconds: 300,
|
|
107
|
+
currencyDependentCaching: false,
|
|
108
|
+
localeDependentCaching: false
|
|
109
|
+
})
|
|
110
|
+
], FakeProductAssociationsCapability.prototype, "getSpareparts", 1);
|
|
111
|
+
__decorateClass([
|
|
112
|
+
Reactionary({
|
|
113
|
+
cache: true,
|
|
114
|
+
cacheTimeToLiveInSeconds: 300,
|
|
115
|
+
currencyDependentCaching: false,
|
|
116
|
+
localeDependentCaching: false
|
|
117
|
+
})
|
|
118
|
+
], FakeProductAssociationsCapability.prototype, "getReplacements", 1);
|
|
119
|
+
export {
|
|
120
|
+
FakeProductAssociationsCapability
|
|
121
|
+
};
|
|
@@ -0,0 +1,154 @@
|
|
|
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
|
+
ProductRatingSummarySchema,
|
|
14
|
+
ProductReviewPaginatedResultSchema,
|
|
15
|
+
ProductReviewSchema,
|
|
16
|
+
ProductReviewsCapability,
|
|
17
|
+
Reactionary,
|
|
18
|
+
error,
|
|
19
|
+
success
|
|
20
|
+
} from "@reactionary/core";
|
|
21
|
+
import { base, en, Faker } from "@faker-js/faker";
|
|
22
|
+
import { calcSeed } from "../utilities/seed.js";
|
|
23
|
+
class FakeProductReviewsCapability extends ProductReviewsCapability {
|
|
24
|
+
config;
|
|
25
|
+
factory;
|
|
26
|
+
faker;
|
|
27
|
+
constructor(config, cache, context, factory) {
|
|
28
|
+
super(cache, context);
|
|
29
|
+
this.config = config;
|
|
30
|
+
this.factory = factory;
|
|
31
|
+
this.faker = new Faker({ locale: [en, base] });
|
|
32
|
+
}
|
|
33
|
+
createReviewsForProduct(productIdentifier) {
|
|
34
|
+
const seed = calcSeed(productIdentifier.key);
|
|
35
|
+
this.faker.seed(seed);
|
|
36
|
+
const hasAnyReviews = this.faker.datatype.boolean({ probability: 0.5 });
|
|
37
|
+
if (!hasAnyReviews || productIdentifier.key === "unknown-product-id") {
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
const reviews = [];
|
|
41
|
+
const totalReviews = this.faker.number.int({ min: 1, max: 20 });
|
|
42
|
+
for (let i = 0; i < totalReviews; i++) {
|
|
43
|
+
const hasReply = this.faker.datatype.boolean({ probability: 0.3 });
|
|
44
|
+
reviews.push({
|
|
45
|
+
identifier: {
|
|
46
|
+
key: `fake-review-${productIdentifier.key}-${i}`
|
|
47
|
+
},
|
|
48
|
+
product: productIdentifier,
|
|
49
|
+
authorName: this.faker.person.fullName(),
|
|
50
|
+
authorId: this.faker.string.uuid(),
|
|
51
|
+
rating: this.faker.number.int({ min: 1, max: 5 }),
|
|
52
|
+
title: this.faker.lorem.sentence(),
|
|
53
|
+
content: this.faker.lorem.paragraphs({ min: 1, max: 5 }),
|
|
54
|
+
createdAt: this.faker.date.past({ years: 1 }).toISOString(),
|
|
55
|
+
updatedAt: this.faker.datatype.boolean() ? this.faker.date.recent({ days: 30 }).toISOString() : void 0,
|
|
56
|
+
verified: this.faker.datatype.boolean(),
|
|
57
|
+
reply: hasReply ? this.faker.lorem.sentences(2) : void 0,
|
|
58
|
+
repliedAt: hasReply ? this.faker.date.recent({ days: 7 }).toISOString() : void 0
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return reviews.sort(
|
|
62
|
+
(a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
async getRatingSummary(query) {
|
|
66
|
+
const reviews = this.createReviewsForProduct(query.product);
|
|
67
|
+
if (reviews.length === 0) {
|
|
68
|
+
const emptySummary = this.createEmptyProductRatingSummary({ product: query.product });
|
|
69
|
+
return success(this.factory.parseRatingSummary(this.context, emptySummary));
|
|
70
|
+
}
|
|
71
|
+
const totalRatings = reviews.length;
|
|
72
|
+
const averageRating = reviews.reduce((sum, review) => sum + review.rating, 0) / totalRatings;
|
|
73
|
+
const summary = {
|
|
74
|
+
identifier: {
|
|
75
|
+
product: query.product
|
|
76
|
+
},
|
|
77
|
+
averageRating,
|
|
78
|
+
totalRatings,
|
|
79
|
+
ratingDistribution: {
|
|
80
|
+
"1": reviews.filter((x) => x.rating === 1).length,
|
|
81
|
+
"2": reviews.filter((x) => x.rating === 2).length,
|
|
82
|
+
"3": reviews.filter((x) => x.rating === 3).length,
|
|
83
|
+
"4": reviews.filter((x) => x.rating === 4).length,
|
|
84
|
+
"5": reviews.filter((x) => x.rating === 5).length
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
return success(this.factory.parseRatingSummary(this.context, summary));
|
|
88
|
+
}
|
|
89
|
+
async findReviews(query) {
|
|
90
|
+
const pageSize = query.paginationOptions?.pageSize ?? 20;
|
|
91
|
+
const pageNumber = query.paginationOptions?.pageNumber ?? 1;
|
|
92
|
+
const reviews = this.createReviewsForProduct(query.product);
|
|
93
|
+
const returnedReviews = reviews.slice((pageNumber - 1) * pageSize, pageNumber * pageSize);
|
|
94
|
+
const result = {
|
|
95
|
+
items: returnedReviews,
|
|
96
|
+
totalCount: reviews.length,
|
|
97
|
+
pageSize,
|
|
98
|
+
pageNumber,
|
|
99
|
+
totalPages: Math.ceil(reviews.length / Math.max(pageSize, 1))
|
|
100
|
+
};
|
|
101
|
+
return success(this.factory.parseReviewPaginatedResult(this.context, result));
|
|
102
|
+
}
|
|
103
|
+
async submitReview(mutation) {
|
|
104
|
+
if (this.context.session.identityContext.identity.type !== "Registered") {
|
|
105
|
+
return error({
|
|
106
|
+
type: "InvalidInput",
|
|
107
|
+
error: "Only registered users can submit reviews."
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
const review = {
|
|
111
|
+
identifier: {
|
|
112
|
+
key: this.faker.string.uuid()
|
|
113
|
+
},
|
|
114
|
+
product: mutation.product,
|
|
115
|
+
authorName: mutation.authorName,
|
|
116
|
+
rating: mutation.rating,
|
|
117
|
+
title: mutation.title,
|
|
118
|
+
content: mutation.content,
|
|
119
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
120
|
+
verified: this.faker.datatype.boolean()
|
|
121
|
+
};
|
|
122
|
+
return success(this.factory.parseReview(this.context, review));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
__decorateClass([
|
|
126
|
+
Reactionary({
|
|
127
|
+
outputSchema: ProductRatingSummarySchema,
|
|
128
|
+
cache: true,
|
|
129
|
+
cacheTimeToLiveInSeconds: 300,
|
|
130
|
+
currencyDependentCaching: false,
|
|
131
|
+
localeDependentCaching: false
|
|
132
|
+
})
|
|
133
|
+
], FakeProductReviewsCapability.prototype, "getRatingSummary", 1);
|
|
134
|
+
__decorateClass([
|
|
135
|
+
Reactionary({
|
|
136
|
+
outputSchema: ProductReviewPaginatedResultSchema,
|
|
137
|
+
cache: true,
|
|
138
|
+
cacheTimeToLiveInSeconds: 60,
|
|
139
|
+
currencyDependentCaching: false,
|
|
140
|
+
localeDependentCaching: true
|
|
141
|
+
})
|
|
142
|
+
], FakeProductReviewsCapability.prototype, "findReviews", 1);
|
|
143
|
+
__decorateClass([
|
|
144
|
+
Reactionary({
|
|
145
|
+
outputSchema: ProductReviewSchema,
|
|
146
|
+
cache: false,
|
|
147
|
+
cacheTimeToLiveInSeconds: 0,
|
|
148
|
+
currencyDependentCaching: false,
|
|
149
|
+
localeDependentCaching: false
|
|
150
|
+
})
|
|
151
|
+
], FakeProductReviewsCapability.prototype, "submitReview", 1);
|
|
152
|
+
export {
|
|
153
|
+
FakeProductReviewsCapability
|
|
154
|
+
};
|