@reactionary/source 0.0.42 → 0.0.48
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/.claude/settings.local.json +28 -0
- package/.vscode/settings.json +5 -0
- package/core/package.json +3 -1
- package/core/src/cache/cache.interface.ts +14 -18
- package/core/src/cache/memory-cache.ts +56 -0
- package/core/src/cache/noop-cache.ts +5 -23
- package/core/src/cache/redis-cache.ts +28 -38
- package/core/src/client/client-builder.ts +3 -3
- package/core/src/client/client.ts +10 -10
- package/core/src/decorators/reactionary.decorator.ts +80 -8
- package/core/src/index.ts +2 -1
- package/{examples/node/src/test-utils.ts → core/src/initialization.ts} +20 -10
- package/core/src/providers/analytics.provider.ts +1 -1
- package/core/src/providers/base.provider.ts +61 -25
- package/core/src/providers/cart-payment.provider.ts +7 -6
- package/core/src/providers/cart.provider.ts +17 -18
- package/core/src/providers/category.provider.ts +9 -9
- package/core/src/providers/identity.provider.ts +8 -7
- package/core/src/providers/index.ts +2 -0
- package/core/src/providers/inventory.provider.ts +4 -4
- package/core/src/providers/price.provider.ts +6 -6
- package/core/src/providers/product.provider.ts +5 -5
- package/core/src/providers/profile.provider.ts +22 -0
- package/core/src/providers/search.provider.ts +4 -4
- package/core/src/providers/store.provider.ts +14 -0
- package/core/src/schemas/capabilities.schema.ts +2 -1
- package/core/src/schemas/models/analytics.model.ts +1 -1
- package/core/src/schemas/models/identifiers.model.ts +66 -38
- package/core/src/schemas/models/identity.model.ts +16 -20
- package/core/src/schemas/models/index.ts +1 -0
- package/core/src/schemas/models/profile.model.ts +3 -2
- package/core/src/schemas/models/shipping-method.model.ts +2 -2
- package/core/src/schemas/models/store.model.ts +11 -0
- package/core/src/schemas/mutations/cart-payment.mutation.ts +1 -1
- package/core/src/schemas/mutations/cart.mutation.ts +2 -2
- package/core/src/schemas/mutations/identity.mutation.ts +6 -0
- package/core/src/schemas/mutations/index.ts +1 -0
- package/core/src/schemas/mutations/profile.mutation.ts +9 -0
- package/core/src/schemas/queries/cart.query.ts +1 -1
- package/core/src/schemas/queries/identity.query.ts +1 -1
- package/core/src/schemas/queries/index.ts +2 -0
- package/core/src/schemas/queries/inventory.query.ts +4 -12
- package/core/src/schemas/queries/price.query.ts +1 -1
- package/core/src/schemas/queries/profile.query.ts +7 -0
- package/core/src/schemas/queries/search.query.ts +1 -1
- package/core/src/schemas/queries/store.query.ts +11 -0
- package/core/src/schemas/session.schema.ts +31 -6
- package/eslint.config.mjs +7 -0
- package/examples/next/src/app/page.tsx +4 -12
- package/examples/node/package.json +1 -3
- package/examples/node/src/basic/basic-node-provider-model-extension.spec.ts +9 -8
- package/examples/node/src/basic/basic-node-provider-query-extension.spec.ts +4 -3
- package/examples/node/src/basic/basic-node-setup.spec.ts +4 -5
- package/nx.json +1 -0
- package/otel/src/metrics.ts +2 -1
- package/otel/src/provider-instrumentation.ts +2 -1
- package/otel/src/tracer.ts +7 -6
- package/otel/src/trpc-middleware.ts +3 -2
- package/package.json +2 -1
- package/providers/algolia/src/core/initialize.ts +4 -3
- package/providers/algolia/src/providers/product.provider.ts +15 -13
- package/providers/algolia/src/providers/search.provider.ts +9 -9
- package/providers/algolia/src/schema/capabilities.schema.ts +1 -1
- package/providers/algolia/src/test/search.provider.spec.ts +10 -10
- package/providers/algolia/src/test/test-utils.ts +1 -1
- package/providers/commercetools/README.md +11 -0
- package/providers/commercetools/src/core/client.ts +144 -88
- package/providers/commercetools/src/core/initialize.ts +14 -11
- package/providers/commercetools/src/providers/cart-payment.provider.ts +30 -29
- package/providers/commercetools/src/providers/cart.provider.ts +88 -116
- package/providers/commercetools/src/providers/category.provider.ts +34 -37
- package/providers/commercetools/src/providers/identity.provider.ts +22 -82
- package/providers/commercetools/src/providers/index.ts +2 -0
- package/providers/commercetools/src/providers/inventory.provider.ts +67 -48
- package/providers/commercetools/src/providers/price.provider.ts +76 -50
- package/providers/commercetools/src/providers/product.provider.ts +20 -23
- package/providers/commercetools/src/providers/profile.provider.ts +61 -0
- package/providers/commercetools/src/providers/search.provider.ts +12 -15
- package/providers/commercetools/src/providers/store.provider.ts +78 -0
- package/providers/commercetools/src/schema/capabilities.schema.ts +2 -1
- package/providers/commercetools/src/test/cart-payment.provider.spec.ts +13 -17
- package/providers/commercetools/src/test/cart.provider.spec.ts +18 -17
- package/providers/commercetools/src/test/category.provider.spec.ts +18 -17
- package/providers/commercetools/src/test/identity.provider.spec.ts +88 -0
- package/providers/commercetools/src/test/inventory.provider.spec.ts +41 -0
- package/providers/commercetools/src/test/price.provider.spec.ts +9 -8
- package/providers/commercetools/src/test/product.provider.spec.ts +9 -8
- package/providers/commercetools/src/test/profile.provider.spec.ts +49 -0
- package/providers/commercetools/src/test/search.provider.spec.ts +8 -7
- package/providers/commercetools/src/test/store.provider.spec.ts +37 -0
- package/providers/commercetools/src/test/test-utils.ts +0 -39
- package/providers/fake/src/core/initialize.ts +96 -38
- package/providers/fake/src/providers/analytics.provider.ts +6 -5
- package/providers/fake/src/providers/cart.provider.ts +30 -27
- package/providers/fake/src/providers/category.provider.ts +12 -12
- package/providers/fake/src/providers/identity.provider.ts +22 -14
- package/providers/fake/src/providers/index.ts +1 -0
- package/providers/fake/src/providers/inventory.provider.ts +13 -13
- package/providers/fake/src/providers/price.provider.ts +13 -13
- package/providers/fake/src/providers/product.provider.ts +11 -11
- package/providers/fake/src/providers/search.provider.ts +7 -5
- package/providers/fake/src/providers/store.provider.ts +47 -0
- package/providers/fake/src/schema/capabilities.schema.ts +4 -1
- package/providers/fake/src/test/cart.provider.spec.ts +18 -18
- package/providers/fake/src/test/category.provider.spec.ts +55 -37
- package/providers/fake/src/test/price.provider.spec.ts +9 -14
- package/providers/fake/src/test/product.provider.spec.ts +27 -0
- package/providers/fake/src/test/test-utils.ts +2 -33
- package/providers/posthog/src/core/initialize.ts +3 -3
- package/providers/posthog/src/schema/capabilities.schema.ts +1 -1
- package/trpc/src/client.ts +42 -41
- package/trpc/src/index.ts +4 -3
- package/trpc/src/integration.spec.ts +11 -11
- package/trpc/src/server.ts +26 -24
- package/trpc/src/test-utils.ts +1 -1
- package/trpc/src/types.ts +24 -22
- package/core/src/cache/cache-evaluation.interface.ts +0 -19
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Category,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
1
|
+
import type { Category, CategoryQueryById, CategoryQueryBySlug, CategoryQueryForBreadcrumb, CategoryQueryForChildCategories, CategoryQueryForTopCategories, RequestContext} from "@reactionary/core";
|
|
2
|
+
import { CategoryProvider, Session } from "@reactionary/core";
|
|
3
|
+
import type { FakeConfiguration } from "../schema/configuration.schema";
|
|
4
|
+
import type { Cache as ReactionaryCache } from "@reactionary/core";
|
|
5
|
+
import type z from "zod";
|
|
5
6
|
import { Faker, en, base } from '@faker-js/faker';
|
|
6
7
|
export class FakeCategoryProvider<
|
|
7
8
|
T extends Category = Category
|
|
@@ -70,19 +71,18 @@ export class FakeCategoryProvider<
|
|
|
70
71
|
});
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
public override async getById(payload: CategoryQueryById, session: Session): Promise<T> {
|
|
74
|
+
public override async getById(payload: CategoryQueryById, reqCtx: RequestContext): Promise<T> {
|
|
76
75
|
const category = this.allCategories.get(payload.id.key);
|
|
76
|
+
|
|
77
77
|
if(!category) {
|
|
78
78
|
const dummyCategory = this.newModel();
|
|
79
79
|
dummyCategory.meta.placeholder = true;
|
|
80
80
|
dummyCategory.identifier = { key: payload.id.key };
|
|
81
81
|
return dummyCategory;
|
|
82
82
|
}
|
|
83
|
-
return
|
|
83
|
+
return category;
|
|
84
84
|
}
|
|
85
|
-
public override getBySlug(payload: CategoryQueryBySlug,
|
|
85
|
+
public override getBySlug(payload: CategoryQueryBySlug, reqCtx: RequestContext): Promise<T | null> {
|
|
86
86
|
for(const p of this.allCategories.values()) {
|
|
87
87
|
if(p.slug === payload.slug) {
|
|
88
88
|
return Promise.resolve(p as T);
|
|
@@ -91,7 +91,7 @@ export class FakeCategoryProvider<
|
|
|
91
91
|
return Promise.resolve(null);
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
public override getBreadcrumbPathToCategory(payload: CategoryQueryForBreadcrumb,
|
|
94
|
+
public override getBreadcrumbPathToCategory(payload: CategoryQueryForBreadcrumb, reqCtx: RequestContext): Promise<T[]> {
|
|
95
95
|
const path = new Array<T>();
|
|
96
96
|
let category = this.allCategories.get(payload.id.key);
|
|
97
97
|
path.push(category as T);
|
|
@@ -104,7 +104,7 @@ export class FakeCategoryProvider<
|
|
|
104
104
|
return Promise.resolve(path);
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
public override async findChildCategories(payload: CategoryQueryForChildCategories,
|
|
107
|
+
public override async findChildCategories(payload: CategoryQueryForChildCategories, reqCtx: RequestContext): Promise<ReturnType<typeof this.parsePaginatedResult>> {
|
|
108
108
|
const children = this.childCategories.get(payload.parentId.key);
|
|
109
109
|
const page = children?.slice((payload.paginationOptions.pageNumber - 1) * payload.paginationOptions.pageSize, payload.paginationOptions.pageNumber * payload.paginationOptions.pageSize);
|
|
110
110
|
|
|
@@ -126,7 +126,7 @@ export class FakeCategoryProvider<
|
|
|
126
126
|
|
|
127
127
|
return Promise.resolve(res);
|
|
128
128
|
}
|
|
129
|
-
public override findTopCategories(payload: CategoryQueryForTopCategories,
|
|
129
|
+
public override findTopCategories(payload: CategoryQueryForTopCategories, reqCtx: RequestContext): Promise<ReturnType<typeof this.parsePaginatedResult>> {
|
|
130
130
|
const children = this.topCategories;
|
|
131
131
|
const page = children?.slice((payload.paginationOptions.pageNumber - 1) * payload.paginationOptions.pageSize, payload.paginationOptions.pageNumber * payload.paginationOptions.pageSize);
|
|
132
132
|
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Identity,
|
|
2
|
+
type Identity,
|
|
3
|
+
type IdentityQuerySelf,
|
|
4
|
+
type IdentityMutationLogin,
|
|
5
|
+
type IdentityMutationLogout,
|
|
6
|
+
type RequestContext,
|
|
7
|
+
type Cache,
|
|
3
8
|
IdentityProvider,
|
|
4
|
-
|
|
5
|
-
IdentityMutationLogin,
|
|
6
|
-
IdentityMutationLogout,
|
|
7
|
-
Session,
|
|
8
|
-
Cache,
|
|
9
|
+
type IdentityMutationRegister,
|
|
9
10
|
} from '@reactionary/core';
|
|
10
|
-
import z from 'zod';
|
|
11
|
-
import { FakeConfiguration } from '../schema/configuration.schema';
|
|
11
|
+
import type z from 'zod';
|
|
12
|
+
import type { FakeConfiguration } from '../schema/configuration.schema';
|
|
12
13
|
import { base, en, Faker } from '@faker-js/faker';
|
|
13
14
|
|
|
14
15
|
export class FakeIdentityProvider<
|
|
@@ -25,7 +26,7 @@ export class FakeIdentityProvider<
|
|
|
25
26
|
|
|
26
27
|
public override async getSelf(
|
|
27
28
|
_payload: IdentityQuerySelf,
|
|
28
|
-
|
|
29
|
+
_reqCtx: RequestContext
|
|
29
30
|
): Promise<T> {
|
|
30
31
|
if (!this.currentIdentity) {
|
|
31
32
|
const model = this.newModel();
|
|
@@ -50,7 +51,7 @@ export class FakeIdentityProvider<
|
|
|
50
51
|
|
|
51
52
|
public override async login(
|
|
52
53
|
payload: IdentityMutationLogin,
|
|
53
|
-
|
|
54
|
+
_reqCtx: RequestContext
|
|
54
55
|
): Promise<T> {
|
|
55
56
|
const generator = new Faker({
|
|
56
57
|
seed: 42,
|
|
@@ -72,14 +73,14 @@ export class FakeIdentityProvider<
|
|
|
72
73
|
placeholder: false,
|
|
73
74
|
},
|
|
74
75
|
});
|
|
75
|
-
|
|
76
|
+
|
|
76
77
|
this.currentIdentity = this.assert(model);
|
|
77
78
|
return this.currentIdentity;
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
public override async logout(
|
|
81
82
|
_payload: IdentityMutationLogout,
|
|
82
|
-
|
|
83
|
+
_reqCtx: RequestContext
|
|
83
84
|
): Promise<T> {
|
|
84
85
|
const model = this.newModel();
|
|
85
86
|
Object.assign(model, {
|
|
@@ -95,8 +96,15 @@ export class FakeIdentityProvider<
|
|
|
95
96
|
placeholder: false,
|
|
96
97
|
},
|
|
97
98
|
});
|
|
98
|
-
|
|
99
|
+
|
|
99
100
|
this.currentIdentity = this.assert(model);
|
|
100
101
|
return this.currentIdentity;
|
|
101
102
|
}
|
|
102
|
-
|
|
103
|
+
|
|
104
|
+
public override register(
|
|
105
|
+
payload: IdentityMutationRegister,
|
|
106
|
+
reqCtx: RequestContext
|
|
107
|
+
): Promise<T> {
|
|
108
|
+
throw new Error('Method not implemented.');
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
Inventory,
|
|
3
|
-
|
|
4
|
-
InventoryQuery,
|
|
5
|
-
Session,
|
|
3
|
+
RequestContext,
|
|
6
4
|
Cache,
|
|
5
|
+
InventoryQueryBySKU
|
|
6
|
+
} from '@reactionary/core';
|
|
7
|
+
import {
|
|
8
|
+
InventoryProvider
|
|
7
9
|
} from '@reactionary/core';
|
|
8
|
-
import z from 'zod';
|
|
9
|
-
import { FakeConfiguration } from '../schema/configuration.schema';
|
|
10
|
+
import type z from 'zod';
|
|
11
|
+
import type { FakeConfiguration } from '../schema/configuration.schema';
|
|
10
12
|
import { base, en, Faker } from '@faker-js/faker';
|
|
11
13
|
|
|
12
14
|
export class FakeInventoryProvider<
|
|
@@ -21,8 +23,8 @@ export class FakeInventoryProvider<
|
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
public override async getBySKU(
|
|
24
|
-
payload:
|
|
25
|
-
|
|
26
|
+
payload: InventoryQueryBySKU,
|
|
27
|
+
_reqCtx: RequestContext
|
|
26
28
|
): Promise<T> {
|
|
27
29
|
// Generate a simple hash from the SKU string for seeding
|
|
28
30
|
let hash = 0;
|
|
@@ -40,10 +42,8 @@ export class FakeInventoryProvider<
|
|
|
40
42
|
const model = this.newModel();
|
|
41
43
|
|
|
42
44
|
model.identifier = {
|
|
43
|
-
sku:
|
|
44
|
-
|
|
45
|
-
key: 'online'
|
|
46
|
-
},
|
|
45
|
+
sku: payload.sku,
|
|
46
|
+
fulfillmentCenter: payload.fulfilmentCenter
|
|
47
47
|
};
|
|
48
48
|
model.sku = skuString;
|
|
49
49
|
|
|
@@ -58,7 +58,7 @@ export class FakeInventoryProvider<
|
|
|
58
58
|
model.meta = {
|
|
59
59
|
cache: {
|
|
60
60
|
hit: false,
|
|
61
|
-
key: this.generateCacheKeySingle(model.identifier,
|
|
61
|
+
key: this.generateCacheKeySingle(model.identifier, _reqCtx)
|
|
62
62
|
},
|
|
63
63
|
placeholder: false,
|
|
64
64
|
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Price,
|
|
2
|
+
type Price,
|
|
3
|
+
type PriceQueryBySku,
|
|
4
|
+
type RequestContext,
|
|
5
|
+
type Cache,
|
|
3
6
|
PriceProvider,
|
|
4
|
-
PriceQueryBySku,
|
|
5
|
-
Session,
|
|
6
|
-
Cache,
|
|
7
7
|
} from '@reactionary/core';
|
|
8
|
-
import z from 'zod';
|
|
9
|
-
import { FakeConfiguration } from '../schema/configuration.schema';
|
|
8
|
+
import type z from 'zod';
|
|
9
|
+
import type { FakeConfiguration } from '../schema/configuration.schema';
|
|
10
10
|
import { base, en, Faker } from '@faker-js/faker';
|
|
11
11
|
|
|
12
12
|
export class FakePriceProvider<
|
|
@@ -20,20 +20,20 @@ export class FakePriceProvider<
|
|
|
20
20
|
this.config = config;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
public override async getBySKUs(payload: PriceQueryBySku[],
|
|
23
|
+
public override async getBySKUs(payload: PriceQueryBySku[], reqCtx: RequestContext): Promise<T[]> {
|
|
24
24
|
|
|
25
|
-
const promises = payload.map(p => this.getBySKU(p,
|
|
25
|
+
const promises = payload.map(p => this.getBySKU(p, reqCtx));
|
|
26
26
|
const result = await Promise.all(promises);
|
|
27
27
|
return result;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
public override async getBySKU(
|
|
31
31
|
payload: PriceQueryBySku,
|
|
32
|
-
|
|
32
|
+
_reqCtx: RequestContext
|
|
33
33
|
): Promise<T> {
|
|
34
34
|
|
|
35
35
|
if (payload.sku.key === 'unknown-sku') {
|
|
36
|
-
return this.createEmptyPriceResult(payload.sku.key,
|
|
36
|
+
return this.createEmptyPriceResult(payload.sku.key, _reqCtx.languageContext.currencyCode);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
// Generate a simple hash from the SKU key string for seeding
|
|
@@ -57,7 +57,7 @@ export class FakePriceProvider<
|
|
|
57
57
|
},
|
|
58
58
|
unitPrice: {
|
|
59
59
|
value: generator.number.int({ min: 300, max: 100000 }) / 100,
|
|
60
|
-
currency:
|
|
60
|
+
currency: _reqCtx.languageContext.currencyCode,
|
|
61
61
|
},
|
|
62
62
|
meta: {
|
|
63
63
|
cache: {
|
|
@@ -78,14 +78,14 @@ export class FakePriceProvider<
|
|
|
78
78
|
minimumQuantity: generator.number.int({ min: 2, max: 5 }),
|
|
79
79
|
price: {
|
|
80
80
|
value: tier1Price,
|
|
81
|
-
currency:
|
|
81
|
+
currency: _reqCtx.languageContext.currencyCode,
|
|
82
82
|
}
|
|
83
83
|
},
|
|
84
84
|
{
|
|
85
85
|
minimumQuantity: generator.number.int({ min: 6, max: 10 }),
|
|
86
86
|
price: {
|
|
87
87
|
value: tier2Price,
|
|
88
|
-
currency:
|
|
88
|
+
currency: _reqCtx.languageContext.currencyCode,
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
];
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Product,
|
|
2
|
+
type Product,
|
|
3
|
+
type ProductQueryById,
|
|
4
|
+
type ProductQueryBySlug,
|
|
5
|
+
type RequestContext,
|
|
6
|
+
type Cache as ReactinaryCache,
|
|
3
7
|
ProductProvider,
|
|
4
|
-
|
|
5
|
-
ProductQueryBySlug,
|
|
6
|
-
Session,
|
|
7
|
-
Cache as ReactinaryCache,
|
|
8
|
+
Reactionary,
|
|
8
9
|
} from '@reactionary/core';
|
|
9
|
-
import z from 'zod';
|
|
10
|
-
import { FakeConfiguration } from '../schema/configuration.schema';
|
|
10
|
+
import type z from 'zod';
|
|
11
|
+
import type { FakeConfiguration } from '../schema/configuration.schema';
|
|
11
12
|
import { base, en, Faker } from '@faker-js/faker';
|
|
12
|
-
import { traced } from '@reactionary/otel';
|
|
13
13
|
|
|
14
14
|
export class FakeProductProvider<
|
|
15
15
|
T extends Product = Product
|
|
@@ -22,19 +22,19 @@ export class FakeProductProvider<
|
|
|
22
22
|
this.config = config;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
@Reactionary({})
|
|
25
26
|
public override async getById(
|
|
26
27
|
payload: ProductQueryById,
|
|
27
|
-
|
|
28
|
+
_reqCtx: RequestContext
|
|
28
29
|
): Promise<T> {
|
|
29
30
|
return this.parseSingle(payload);
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
// FIXME: Should we have a get-by-sku here? Since thats whats coming back on cart items...
|
|
33
34
|
|
|
34
|
-
|
|
35
35
|
public override async getBySlug(
|
|
36
36
|
payload: ProductQueryBySlug,
|
|
37
|
-
|
|
37
|
+
_reqCtx: RequestContext
|
|
38
38
|
): Promise<T> {
|
|
39
39
|
return this.parseSingle(payload);
|
|
40
40
|
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
-
SearchProvider
|
|
2
|
+
SearchProvider
|
|
3
|
+
} from '@reactionary/core';
|
|
4
|
+
import type {
|
|
3
5
|
SearchResult,
|
|
4
6
|
SearchResultFacet,
|
|
5
7
|
SearchResultProduct,
|
|
6
8
|
Cache as ReactionaryCache,
|
|
7
9
|
} from '@reactionary/core';
|
|
8
|
-
import type {
|
|
9
|
-
import z from 'zod';
|
|
10
|
-
import { FakeConfiguration } from '../schema/configuration.schema';
|
|
10
|
+
import type { RequestContext, SearchQueryByTerm } from '@reactionary/core';
|
|
11
|
+
import type z from 'zod';
|
|
12
|
+
import type { FakeConfiguration } from '../schema/configuration.schema';
|
|
11
13
|
import { Faker, en, base } from '@faker-js/faker';
|
|
12
14
|
import { jitter } from '../utilities/jitter';
|
|
13
15
|
import { traced } from '@reactionary/otel';
|
|
@@ -26,7 +28,7 @@ export class FakeSearchProvider<
|
|
|
26
28
|
@traced()
|
|
27
29
|
public override async queryByTerm(
|
|
28
30
|
payload: SearchQueryByTerm,
|
|
29
|
-
|
|
31
|
+
_reqCtx: RequestContext
|
|
30
32
|
): Promise<SearchResult> {
|
|
31
33
|
await jitter(this.config.jitter.mean, this.config.jitter.deviation);
|
|
32
34
|
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Inventory,
|
|
3
|
+
Cache,
|
|
4
|
+
RequestContext,
|
|
5
|
+
StoreQueryByProximity,
|
|
6
|
+
Store,
|
|
7
|
+
} from '@reactionary/core';
|
|
8
|
+
import { InventoryProvider, StoreProvider } from '@reactionary/core';
|
|
9
|
+
import type z from 'zod';
|
|
10
|
+
import type { FakeConfiguration } from '../schema/configuration.schema';
|
|
11
|
+
import { base, en, Faker } from '@faker-js/faker';
|
|
12
|
+
|
|
13
|
+
export class FakeStoreProvider<
|
|
14
|
+
T extends Store = Store
|
|
15
|
+
> extends StoreProvider<T> {
|
|
16
|
+
protected config: FakeConfiguration;
|
|
17
|
+
|
|
18
|
+
constructor(config: FakeConfiguration, schema: z.ZodType<T>, cache: Cache) {
|
|
19
|
+
super(schema, cache);
|
|
20
|
+
|
|
21
|
+
this.config = config;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public override async queryByProximity(
|
|
25
|
+
payload: StoreQueryByProximity,
|
|
26
|
+
reqCtx: RequestContext
|
|
27
|
+
): Promise<T[]> {
|
|
28
|
+
const generator = new Faker({
|
|
29
|
+
seed: 42,
|
|
30
|
+
locale: [en, base],
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const results = [];
|
|
34
|
+
|
|
35
|
+
for (let i = 0; i < payload.limit; i++) {
|
|
36
|
+
const model = this.newModel();
|
|
37
|
+
|
|
38
|
+
model.name = generator.company.name();
|
|
39
|
+
model.identifier.key = '' + i;
|
|
40
|
+
model.fulfillmentCenter.key = '' + i;
|
|
41
|
+
|
|
42
|
+
results.push(model);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return results;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CapabilitiesSchema } from "@reactionary/core";
|
|
2
|
-
import { z } from 'zod';
|
|
2
|
+
import type { z } from 'zod';
|
|
3
3
|
|
|
4
4
|
export const FakeCapabilitiesSchema = CapabilitiesSchema.pick({
|
|
5
5
|
product: true,
|
|
@@ -7,6 +7,9 @@ export const FakeCapabilitiesSchema = CapabilitiesSchema.pick({
|
|
|
7
7
|
identity: true,
|
|
8
8
|
category: true,
|
|
9
9
|
cart: true,
|
|
10
|
+
inventory: true,
|
|
11
|
+
store: true,
|
|
12
|
+
price: true,
|
|
10
13
|
}).partial();
|
|
11
14
|
|
|
12
15
|
export type FakeCapabilities = z.infer<typeof FakeCapabilitiesSchema>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import 'dotenv/config';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import type { RequestContext} from '@reactionary/core';
|
|
3
|
+
import { CartSchema, IdentitySchema, NoOpCache, createInitialRequestContext } from '@reactionary/core';
|
|
4
|
+
import { getFakerTestConfiguration } from './test-utils';
|
|
4
5
|
import { FakeCartProvider } from '../providers/cart.provider';
|
|
5
6
|
import { FakeIdentityProvider } from '../providers';
|
|
6
7
|
|
|
@@ -13,7 +14,7 @@ const testData = {
|
|
|
13
14
|
describe('Fake Cart Provider', () => {
|
|
14
15
|
let provider: FakeCartProvider;
|
|
15
16
|
let identityProvider: FakeIdentityProvider;
|
|
16
|
-
let
|
|
17
|
+
let reqCtx: RequestContext;
|
|
17
18
|
|
|
18
19
|
beforeAll( () => {
|
|
19
20
|
provider = new FakeCartProvider(getFakerTestConfiguration(), CartSchema, new NoOpCache());
|
|
@@ -21,14 +22,14 @@ describe('Fake Cart Provider', () => {
|
|
|
21
22
|
});
|
|
22
23
|
|
|
23
24
|
beforeEach( () => {
|
|
24
|
-
|
|
25
|
+
reqCtx = createInitialRequestContext()
|
|
25
26
|
});
|
|
26
27
|
|
|
27
28
|
describe('anonymous sessions', () => {
|
|
28
29
|
it('should be able to get an empty cart', async () => {
|
|
29
30
|
const cart = await provider.getById({
|
|
30
31
|
cart: { key: '' },
|
|
31
|
-
},
|
|
32
|
+
}, reqCtx);
|
|
32
33
|
|
|
33
34
|
expect(cart.identifier.key).toBeFalsy();
|
|
34
35
|
expect(cart.items.length).toBe(0);
|
|
@@ -39,22 +40,22 @@ describe('Fake Cart Provider', () => {
|
|
|
39
40
|
it('should be able to add an item to a cart', async () => {
|
|
40
41
|
const cart = await provider.add({
|
|
41
42
|
cart: { key: '' },
|
|
42
|
-
|
|
43
|
+
sku: {
|
|
43
44
|
key: testData.skuWithoutTiers,
|
|
44
45
|
},
|
|
45
46
|
quantity: 1
|
|
46
|
-
},
|
|
47
|
+
}, reqCtx);
|
|
47
48
|
|
|
48
49
|
expect(cart.identifier.key).toBeDefined();
|
|
49
50
|
expect(cart.items.length).toBe(1);
|
|
50
|
-
expect(cart.items[0].
|
|
51
|
+
expect(cart.items[0].sku.key).toBe(testData.skuWithoutTiers);
|
|
51
52
|
expect(cart.items[0].quantity).toBe(1);
|
|
52
53
|
|
|
53
54
|
expect(cart.items[0].price.totalPrice.value).toBeGreaterThan(0);
|
|
54
|
-
expect(cart.items[0].price.totalPrice.currency).toBe(
|
|
55
|
+
expect(cart.items[0].price.totalPrice.currency).toBe(reqCtx.languageContext.currencyCode);
|
|
55
56
|
|
|
56
57
|
expect(cart.price.grandTotal.value).toBeGreaterThan(0);
|
|
57
|
-
expect(cart.price.grandTotal.currency).toBe(
|
|
58
|
+
expect(cart.price.grandTotal.currency).toBe(reqCtx.languageContext.currencyCode);
|
|
58
59
|
|
|
59
60
|
expect(cart.price.grandTotal.value).toBe(cart.items[0].price.totalPrice.value);
|
|
60
61
|
|
|
@@ -68,23 +69,22 @@ describe('Fake Cart Provider', () => {
|
|
|
68
69
|
|
|
69
70
|
const cart = await provider.add({
|
|
70
71
|
cart: { key: '' },
|
|
71
|
-
|
|
72
|
+
sku: {
|
|
72
73
|
key: testData.skuWithoutTiers,
|
|
73
74
|
},
|
|
74
75
|
quantity: 1
|
|
75
|
-
},
|
|
76
|
+
}, reqCtx);
|
|
76
77
|
|
|
77
78
|
const updatedCart = await provider.changeQuantity({
|
|
78
79
|
cart: cart.identifier,
|
|
79
80
|
item: cart.items[0].identifier,
|
|
80
81
|
quantity: 3
|
|
81
|
-
},
|
|
82
|
+
}, reqCtx);
|
|
82
83
|
|
|
83
84
|
expect(updatedCart.identifier.key).toBe(cart.identifier.key);
|
|
84
85
|
expect(updatedCart.items.length).toBe(1);
|
|
85
|
-
expect(updatedCart.items[0].
|
|
86
|
+
expect(updatedCart.items[0].sku.key).toBe(testData.skuWithoutTiers);
|
|
86
87
|
expect(updatedCart.items[0].quantity).toBe(3);
|
|
87
|
-
|
|
88
88
|
expect(updatedCart.items[0].price.totalPrice.value).toBe(cart.items[0].price.totalPrice.value * 3);
|
|
89
89
|
expect(updatedCart.items[0].price.unitPrice.value).toBe(cart.items[0].price.unitPrice.value);
|
|
90
90
|
|
|
@@ -95,16 +95,16 @@ describe('Fake Cart Provider', () => {
|
|
|
95
95
|
|
|
96
96
|
const cart = await provider.add({
|
|
97
97
|
cart: { key: '' },
|
|
98
|
-
|
|
98
|
+
sku: {
|
|
99
99
|
key: testData.skuWithoutTiers,
|
|
100
100
|
},
|
|
101
101
|
quantity: 1
|
|
102
|
-
},
|
|
102
|
+
}, reqCtx);
|
|
103
103
|
|
|
104
104
|
const updatedCart = await provider.remove({
|
|
105
105
|
cart: cart.identifier,
|
|
106
106
|
item: cart.items[0].identifier,
|
|
107
|
-
},
|
|
107
|
+
}, reqCtx);
|
|
108
108
|
expect(updatedCart.identifier.key).toBe(cart.identifier.key);
|
|
109
109
|
expect(updatedCart.items.length).toBe(0);
|
|
110
110
|
});
|