@reactionary/provider-fake 0.0.71 → 0.0.72
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/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactionary/provider-fake",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.72",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "src/index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@reactionary/core": "0.0.
|
|
7
|
+
"@reactionary/core": "0.0.72",
|
|
8
8
|
"zod": "4.1.9",
|
|
9
9
|
"@faker-js/faker": "^9.8.0"
|
|
10
10
|
},
|
|
@@ -7,12 +7,63 @@ class FakePriceProvider extends PriceProvider {
|
|
|
7
7
|
super(schema, cache, context);
|
|
8
8
|
this.config = config;
|
|
9
9
|
}
|
|
10
|
-
async
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
async getListPrice(payload) {
|
|
11
|
+
if (payload.variant.sku === "unknown-sku") {
|
|
12
|
+
return this.createEmptyPriceResult(payload.variant.sku);
|
|
13
|
+
}
|
|
14
|
+
let hash = 0;
|
|
15
|
+
const skuString = payload.variant.sku;
|
|
16
|
+
for (let i = 0; i < skuString.length; i++) {
|
|
17
|
+
hash = (hash << 5) - hash + skuString.charCodeAt(i);
|
|
18
|
+
hash = hash & hash;
|
|
19
|
+
}
|
|
20
|
+
const generator = new Faker({
|
|
21
|
+
seed: hash || 42,
|
|
22
|
+
locale: [en, base]
|
|
23
|
+
});
|
|
24
|
+
const model = this.newModel();
|
|
25
|
+
Object.assign(model, {
|
|
26
|
+
identifier: {
|
|
27
|
+
variant: payload.variant
|
|
28
|
+
},
|
|
29
|
+
unitPrice: {
|
|
30
|
+
value: generator.number.int({ min: 300, max: 1e5 }) / 100,
|
|
31
|
+
currency: this.context.languageContext.currencyCode
|
|
32
|
+
},
|
|
33
|
+
meta: {
|
|
34
|
+
cache: {
|
|
35
|
+
hit: false,
|
|
36
|
+
key: payload.variant.sku
|
|
37
|
+
},
|
|
38
|
+
placeholder: false
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
if (skuString.includes("with-tiers")) {
|
|
42
|
+
const unitPrice = model.unitPrice?.value || 0;
|
|
43
|
+
const tier1Price = unitPrice * 0.8;
|
|
44
|
+
const tier2Price = tier1Price * 0.8;
|
|
45
|
+
model.tieredPrices = [
|
|
46
|
+
{
|
|
47
|
+
minimumQuantity: generator.number.int({ min: 2, max: 5 }),
|
|
48
|
+
price: {
|
|
49
|
+
value: tier1Price,
|
|
50
|
+
currency: this.context.languageContext.currencyCode
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
minimumQuantity: generator.number.int({ min: 6, max: 10 }),
|
|
55
|
+
price: {
|
|
56
|
+
value: tier2Price,
|
|
57
|
+
currency: this.context.languageContext.currencyCode
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
];
|
|
61
|
+
} else {
|
|
62
|
+
model.tieredPrices = [];
|
|
63
|
+
}
|
|
64
|
+
return this.assert(model);
|
|
14
65
|
}
|
|
15
|
-
async
|
|
66
|
+
async getCustomerPrice(payload) {
|
|
16
67
|
if (payload.variant.sku === "unknown-sku") {
|
|
17
68
|
return this.createEmptyPriceResult(payload.variant.sku);
|
|
18
69
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { type Price, type
|
|
1
|
+
import { type Price, type RequestContext, type Cache, PriceProvider, type CustomerPriceQuery, type ListPriceQuery } from '@reactionary/core';
|
|
2
2
|
import type z from 'zod';
|
|
3
3
|
import type { FakeConfiguration } from '../schema/configuration.schema.js';
|
|
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, context: RequestContext);
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
getListPrice(payload: ListPriceQuery): Promise<T>;
|
|
8
|
+
getCustomerPrice(payload: CustomerPriceQuery): Promise<T>;
|
|
9
9
|
}
|