@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,8 +1,9 @@
|
|
|
1
1
|
import 'dotenv/config';
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import type { RequestContext} from '@reactionary/core';
|
|
5
|
+
import { NoOpCache, PriceSchema, Session, createInitialRequestContext,} from '@reactionary/core';
|
|
6
|
+
import { getCommercetoolsTestConfiguration } from './test-utils';
|
|
6
7
|
|
|
7
8
|
import { CommercetoolsPriceProvider } from '../providers/price.provider';
|
|
8
9
|
|
|
@@ -14,7 +15,7 @@ const testData = {
|
|
|
14
15
|
|
|
15
16
|
describe('Commercetools Price Provider', () => {
|
|
16
17
|
let provider: CommercetoolsPriceProvider;
|
|
17
|
-
let
|
|
18
|
+
let reqCtx: RequestContext;
|
|
18
19
|
|
|
19
20
|
|
|
20
21
|
|
|
@@ -23,11 +24,11 @@ describe('Commercetools Price Provider', () => {
|
|
|
23
24
|
});
|
|
24
25
|
|
|
25
26
|
beforeEach( () => {
|
|
26
|
-
|
|
27
|
+
reqCtx = createInitialRequestContext()
|
|
27
28
|
})
|
|
28
29
|
|
|
29
30
|
it('should be able to get prices for a product without tiers', async () => {
|
|
30
|
-
const result = await provider.getBySKU({ sku: { key: testData.skuWithoutTiers }},
|
|
31
|
+
const result = await provider.getBySKU({ sku: { key: testData.skuWithoutTiers }}, reqCtx);
|
|
31
32
|
|
|
32
33
|
expect(result).toBeTruthy();
|
|
33
34
|
if (result) {
|
|
@@ -39,7 +40,7 @@ describe('Commercetools Price Provider', () => {
|
|
|
39
40
|
});
|
|
40
41
|
|
|
41
42
|
it('should be able to get prices for a product with tiers', async () => {
|
|
42
|
-
const result = await provider.getBySKU({ sku: { key: testData.skuWithTiers }},
|
|
43
|
+
const result = await provider.getBySKU({ sku: { key: testData.skuWithTiers }}, reqCtx);
|
|
43
44
|
|
|
44
45
|
expect(result).toBeTruthy();
|
|
45
46
|
if (result) {
|
|
@@ -56,7 +57,7 @@ describe('Commercetools Price Provider', () => {
|
|
|
56
57
|
});
|
|
57
58
|
|
|
58
59
|
it('should return a placeholder price for an unknown SKU', async () => {
|
|
59
|
-
const result = await provider.getBySKU({ sku: { key: 'unknown-sku' }},
|
|
60
|
+
const result = await provider.getBySKU({ sku: { key: 'unknown-sku' }}, reqCtx);
|
|
60
61
|
|
|
61
62
|
expect(result).toBeTruthy();
|
|
62
63
|
if (result) {
|
|
@@ -70,7 +71,7 @@ describe('Commercetools Price Provider', () => {
|
|
|
70
71
|
|
|
71
72
|
it('can look up multiple prices at once', async () => {
|
|
72
73
|
const skus = [testData.skuWithTiers, testData.skuWithoutTiers, 'unknown-sku'];
|
|
73
|
-
const results = await Promise.all(skus.map( sku => provider.getBySKU({ sku: { key: sku }},
|
|
74
|
+
const results = await Promise.all(skus.map( sku => provider.getBySKU({ sku: { key: sku }}, reqCtx)));
|
|
74
75
|
|
|
75
76
|
expect(results).toHaveLength(skus.length);
|
|
76
77
|
expect(results[0].identifier.sku.key).toBe(testData.skuWithTiers);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import 'dotenv/config';
|
|
2
|
-
import {
|
|
2
|
+
import type { RequestContext} from '@reactionary/core';
|
|
3
|
+
import { NoOpCache, ProductSchema, Session, createInitialRequestContext } from '@reactionary/core';
|
|
3
4
|
import { CommercetoolsProductProvider } from '../providers/product.provider';
|
|
4
|
-
import {
|
|
5
|
+
import { getCommercetoolsTestConfiguration } from './test-utils';
|
|
5
6
|
|
|
6
7
|
const testData = {
|
|
7
8
|
product : {
|
|
@@ -14,19 +15,19 @@ const testData = {
|
|
|
14
15
|
describe('Commercetools Product Provider', () => {
|
|
15
16
|
|
|
16
17
|
let provider: CommercetoolsProductProvider;
|
|
17
|
-
let
|
|
18
|
+
let reqCtx: RequestContext;
|
|
18
19
|
|
|
19
20
|
beforeAll( () => {
|
|
20
21
|
provider = new CommercetoolsProductProvider(getCommercetoolsTestConfiguration(), ProductSchema, new NoOpCache());
|
|
21
22
|
});
|
|
22
23
|
|
|
23
24
|
beforeEach( () => {
|
|
24
|
-
|
|
25
|
+
reqCtx = createInitialRequestContext()
|
|
25
26
|
})
|
|
26
27
|
|
|
27
28
|
|
|
28
29
|
it('should be able to get a product by id', async () => {
|
|
29
|
-
const result = await provider.getById( { id: testData.product.id },
|
|
30
|
+
const result = await provider.getById( { id: testData.product.id }, reqCtx);
|
|
30
31
|
|
|
31
32
|
expect(result).toBeTruthy();
|
|
32
33
|
expect(result.identifier.key).toBe(testData.product.id);
|
|
@@ -36,7 +37,7 @@ describe('Commercetools Product Provider', () => {
|
|
|
36
37
|
});
|
|
37
38
|
|
|
38
39
|
it('should be able to get a product by slug', async () => {
|
|
39
|
-
const result = await provider.getBySlug( { slug: 'sunnai-glass-bowl' },
|
|
40
|
+
const result = await provider.getBySlug( { slug: 'sunnai-glass-bowl' }, reqCtx);
|
|
40
41
|
|
|
41
42
|
expect(result).toBeTruthy();
|
|
42
43
|
if (result) {
|
|
@@ -48,13 +49,13 @@ describe('Commercetools Product Provider', () => {
|
|
|
48
49
|
});
|
|
49
50
|
|
|
50
51
|
it('should return null for unknown slug', async () => {
|
|
51
|
-
const result = await provider.getBySlug( { slug: 'unknown-slug' },
|
|
52
|
+
const result = await provider.getBySlug( { slug: 'unknown-slug' }, reqCtx);
|
|
52
53
|
|
|
53
54
|
expect(result).toBeNull();
|
|
54
55
|
});
|
|
55
56
|
|
|
56
57
|
it('should return a placeholder product for unknown id', async () => {
|
|
57
|
-
const result = await provider.getById( { id: 'unknown-id' },
|
|
58
|
+
const result = await provider.getById( { id: 'unknown-id' }, reqCtx);
|
|
58
59
|
|
|
59
60
|
expect(result).toBeTruthy();
|
|
60
61
|
expect(result.meta.placeholder).toBe(true);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
2
|
+
import type { RequestContext } from '@reactionary/core';
|
|
3
|
+
import {
|
|
4
|
+
IdentitySchema,
|
|
5
|
+
NoOpCache,
|
|
6
|
+
ProfileSchema,
|
|
7
|
+
createInitialRequestContext,
|
|
8
|
+
} from '@reactionary/core';
|
|
9
|
+
import { getCommercetoolsTestConfiguration } from './test-utils';
|
|
10
|
+
import { CommercetoolsProfileProvider } from '../providers/profile.provider';
|
|
11
|
+
import { CommercetoolsIdentityProvider } from '../providers/identity.provider';
|
|
12
|
+
|
|
13
|
+
describe('Commercetools Profile Provider', () => {
|
|
14
|
+
let provider: CommercetoolsProfileProvider;
|
|
15
|
+
let identityProvider: CommercetoolsIdentityProvider;
|
|
16
|
+
let reqCtx: RequestContext;
|
|
17
|
+
|
|
18
|
+
beforeAll(() => {
|
|
19
|
+
provider = new CommercetoolsProfileProvider(
|
|
20
|
+
getCommercetoolsTestConfiguration(),
|
|
21
|
+
ProfileSchema,
|
|
22
|
+
new NoOpCache()
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
identityProvider = new CommercetoolsIdentityProvider(
|
|
26
|
+
getCommercetoolsTestConfiguration(),
|
|
27
|
+
IdentitySchema,
|
|
28
|
+
new NoOpCache()
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
beforeEach(async () => {
|
|
33
|
+
reqCtx = createInitialRequestContext();
|
|
34
|
+
|
|
35
|
+
const time = new Date().getTime();
|
|
36
|
+
|
|
37
|
+
await identityProvider.register({
|
|
38
|
+
username: `martin.rogne+test-${ time }@solteq.com`,
|
|
39
|
+
password: 'love2test'
|
|
40
|
+
}, reqCtx);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should be able to fetch the profile for the current user', async () => {
|
|
44
|
+
const profile = await provider.getSelf({}, reqCtx);
|
|
45
|
+
|
|
46
|
+
expect(profile).toBeDefined();
|
|
47
|
+
expect(profile.email).toContain('martin.rogne');
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import 'dotenv/config';
|
|
2
|
-
import {
|
|
2
|
+
import type { RequestContext} from '@reactionary/core';
|
|
3
|
+
import { NoOpCache, SearchResultSchema, createInitialRequestContext } from '@reactionary/core';
|
|
3
4
|
import { CommercetoolsSearchProvider } from '../providers/search.provider';
|
|
4
|
-
import { getCommercetoolsTestConfiguration
|
|
5
|
+
import { getCommercetoolsTestConfiguration } from './test-utils';
|
|
5
6
|
|
|
6
7
|
const testData = {
|
|
7
8
|
searchTerm: 'bowl'
|
|
@@ -10,14 +11,14 @@ const testData = {
|
|
|
10
11
|
describe('Commercetools Search Provider', () => {
|
|
11
12
|
|
|
12
13
|
let provider: CommercetoolsSearchProvider;
|
|
13
|
-
let
|
|
14
|
+
let reqCtx: RequestContext;
|
|
14
15
|
|
|
15
16
|
beforeAll( () => {
|
|
16
17
|
provider = new CommercetoolsSearchProvider(getCommercetoolsTestConfiguration(), SearchResultSchema, new NoOpCache());
|
|
17
18
|
});
|
|
18
19
|
|
|
19
20
|
beforeEach( () => {
|
|
20
|
-
|
|
21
|
+
reqCtx = createInitialRequestContext()
|
|
21
22
|
})
|
|
22
23
|
|
|
23
24
|
it('should be able to get a result by term', async () => {
|
|
@@ -27,7 +28,7 @@ describe('Commercetools Search Provider', () => {
|
|
|
27
28
|
facets: [],
|
|
28
29
|
page: 1,
|
|
29
30
|
pageSize: 10,
|
|
30
|
-
}},
|
|
31
|
+
}}, reqCtx);
|
|
31
32
|
|
|
32
33
|
expect(result.products.length).toBeGreaterThan(0);
|
|
33
34
|
});
|
|
@@ -40,7 +41,7 @@ describe('Commercetools Search Provider', () => {
|
|
|
40
41
|
facets: [],
|
|
41
42
|
page: 1,
|
|
42
43
|
pageSize: 1,
|
|
43
|
-
}},
|
|
44
|
+
}}, reqCtx);
|
|
44
45
|
|
|
45
46
|
expect(result.products.length).toBeGreaterThan(0);
|
|
46
47
|
expect(result.pages).toBeGreaterThan(1);
|
|
@@ -51,7 +52,7 @@ describe('Commercetools Search Provider', () => {
|
|
|
51
52
|
facets: [],
|
|
52
53
|
page: 2,
|
|
53
54
|
pageSize: 1,
|
|
54
|
-
}},
|
|
55
|
+
}}, reqCtx);
|
|
55
56
|
|
|
56
57
|
expect(result2.products.length).toBeGreaterThan(0);
|
|
57
58
|
expect(result2.pages).toBeGreaterThan(2);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
2
|
+
import type { RequestContext } from '@reactionary/core';
|
|
3
|
+
import {
|
|
4
|
+
NoOpCache,
|
|
5
|
+
StoreSchema,
|
|
6
|
+
createInitialRequestContext,
|
|
7
|
+
} from '@reactionary/core';
|
|
8
|
+
import { getCommercetoolsTestConfiguration } from './test-utils';
|
|
9
|
+
import { CommercetoolsStoreProvider } from '../providers/store.provider';
|
|
10
|
+
|
|
11
|
+
describe('Commercetools Store Provider', () => {
|
|
12
|
+
let provider: CommercetoolsStoreProvider;
|
|
13
|
+
let reqCtx: RequestContext;
|
|
14
|
+
|
|
15
|
+
beforeAll(() => {
|
|
16
|
+
provider = new CommercetoolsStoreProvider(
|
|
17
|
+
getCommercetoolsTestConfiguration(),
|
|
18
|
+
StoreSchema,
|
|
19
|
+
new NoOpCache()
|
|
20
|
+
);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
reqCtx = createInitialRequestContext();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should be able to query stores by longitude and latitude', async () => {
|
|
28
|
+
const stores = await provider.queryByProximity({
|
|
29
|
+
distance: 1000,
|
|
30
|
+
latitude: 15,
|
|
31
|
+
longitude: 15,
|
|
32
|
+
limit: 10
|
|
33
|
+
}, reqCtx);
|
|
34
|
+
|
|
35
|
+
expect(stores.length).toBe(2);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Session } from "@reactionary/core";
|
|
2
|
-
|
|
3
1
|
export function getCommercetoolsTestConfiguration() {
|
|
4
2
|
return {
|
|
5
3
|
apiUrl: process.env['CTP_API_URL'] || '',
|
|
@@ -10,41 +8,4 @@ export function getCommercetoolsTestConfiguration() {
|
|
|
10
8
|
scopes: (process.env['CTP_SCOPES'] || '').split(',').map(x => x.trim()).filter(x => x && x.length > 0),
|
|
11
9
|
}
|
|
12
10
|
}
|
|
13
|
-
export function createGuestTestSession(): Session {
|
|
14
|
-
const session = createAnonymousTestSession();
|
|
15
|
-
session.identity.type = 'Guest';
|
|
16
|
-
session.identity.id.userId = 'guest-user-id';
|
|
17
|
-
// HOW do i get to call .guest() on the client?
|
|
18
|
-
|
|
19
|
-
return session;
|
|
20
|
-
}
|
|
21
11
|
|
|
22
|
-
export function createAnonymousTestSession(): Session {
|
|
23
|
-
return {
|
|
24
|
-
id: 'test-session-id',
|
|
25
|
-
identity: {
|
|
26
|
-
type: 'Anonymous',
|
|
27
|
-
meta: {
|
|
28
|
-
cache: { hit: false, key: '' },
|
|
29
|
-
placeholder: false,
|
|
30
|
-
},
|
|
31
|
-
id: { userId: 'anonymous' },
|
|
32
|
-
token: undefined,
|
|
33
|
-
issued: new Date(),
|
|
34
|
-
expiry: new Date(new Date().getTime() + 3600 * 1000),
|
|
35
|
-
logonId: "",
|
|
36
|
-
createdAt: "",
|
|
37
|
-
updatedAt: "",
|
|
38
|
-
keyring: [],
|
|
39
|
-
currentService: undefined
|
|
40
|
-
},
|
|
41
|
-
languageContext: {
|
|
42
|
-
locale: 'en-US',
|
|
43
|
-
currencyCode: 'USD',
|
|
44
|
-
countryCode: 'US',
|
|
45
|
-
},
|
|
46
|
-
storeIdentifier: {
|
|
47
|
-
key: 'the-good-store',
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
}
|
|
@@ -1,39 +1,97 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
1
|
+
import type {
|
|
2
|
+
Cache as ReactinaryCache,
|
|
3
|
+
ProductProvider,
|
|
4
|
+
SearchProvider,
|
|
5
|
+
IdentityProvider,
|
|
6
|
+
CategoryProvider,
|
|
7
|
+
CartProvider,
|
|
8
|
+
InventoryProvider,
|
|
9
|
+
StoreProvider,
|
|
10
|
+
PriceProvider,
|
|
11
|
+
} from '@reactionary/core';
|
|
12
|
+
import {
|
|
13
|
+
ProductSchema,
|
|
14
|
+
SearchResultSchema,
|
|
15
|
+
CategorySchema,
|
|
16
|
+
CartSchema,
|
|
17
|
+
InventorySchema,
|
|
18
|
+
StoreSchema,
|
|
19
|
+
PriceSchema,
|
|
20
|
+
} from '@reactionary/core';
|
|
21
|
+
import { FakeProductProvider } from '../providers/product.provider';
|
|
22
|
+
import { FakeSearchProvider } from '../providers/search.provider';
|
|
23
|
+
import type { FakeConfiguration } from '../schema/configuration.schema';
|
|
24
|
+
import type { FakeCapabilities } from '../schema/capabilities.schema';
|
|
25
|
+
import { FakeCategoryProvider } from '../providers/category.provider';
|
|
26
|
+
import {
|
|
27
|
+
FakeCartProvider,
|
|
28
|
+
FakeInventoryProvider,
|
|
29
|
+
FakePriceProvider,
|
|
30
|
+
FakeStoreProvider,
|
|
31
|
+
} from '../providers';
|
|
32
|
+
|
|
33
|
+
type FakeClient<T extends FakeCapabilities> = (T['cart'] extends true
|
|
34
|
+
? { cart: CartProvider }
|
|
35
|
+
: object) &
|
|
36
|
+
(T['product'] extends true ? { product: ProductProvider } : object) &
|
|
37
|
+
(T['search'] extends true ? { search: SearchProvider } : object) &
|
|
38
|
+
(T['identity'] extends true ? { identity: IdentityProvider } : object) &
|
|
39
|
+
(T['category'] extends true ? { category: CategoryProvider } : object) &
|
|
40
|
+
(T['inventory'] extends true ? { inventory: InventoryProvider } : object) &
|
|
41
|
+
(T['store'] extends true ? { store: StoreProvider } : object) &
|
|
42
|
+
(T['price'] extends true ? { price: PriceProvider } : object);
|
|
43
|
+
|
|
44
|
+
export function withFakeCapabilities<T extends FakeCapabilities>(
|
|
45
|
+
configuration: FakeConfiguration,
|
|
46
|
+
capabilities: T
|
|
47
|
+
) {
|
|
48
|
+
return (cache: ReactinaryCache): FakeClient<T> => {
|
|
49
|
+
const client: any = {};
|
|
50
|
+
|
|
51
|
+
if (capabilities.product) {
|
|
52
|
+
client.product = new FakeProductProvider(
|
|
53
|
+
configuration,
|
|
54
|
+
ProductSchema,
|
|
55
|
+
cache
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (capabilities.search) {
|
|
60
|
+
client.search = new FakeSearchProvider(
|
|
61
|
+
configuration,
|
|
62
|
+
SearchResultSchema,
|
|
63
|
+
cache
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (capabilities.category) {
|
|
68
|
+
client.category = new FakeCategoryProvider(
|
|
69
|
+
configuration,
|
|
70
|
+
CategorySchema,
|
|
71
|
+
cache
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (capabilities.cart) {
|
|
76
|
+
client.cart = new FakeCartProvider(configuration, CartSchema, cache);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (capabilities.inventory) {
|
|
80
|
+
client.inventory = new FakeInventoryProvider(
|
|
81
|
+
configuration,
|
|
82
|
+
InventorySchema,
|
|
83
|
+
cache
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (capabilities.store) {
|
|
88
|
+
client.store = new FakeStoreProvider(configuration, StoreSchema, cache);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (capabilities.price) {
|
|
92
|
+
client.price = new FakePriceProvider(configuration, PriceSchema, cache);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return client;
|
|
96
|
+
};
|
|
39
97
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AnalyticsProvider,
|
|
1
|
+
import type {
|
|
3
2
|
BaseModel,
|
|
4
|
-
Cache
|
|
3
|
+
Cache} from '@reactionary/core';
|
|
4
|
+
import {
|
|
5
|
+
AnalyticsProvider
|
|
5
6
|
} from '@reactionary/core';
|
|
6
|
-
import z from 'zod';
|
|
7
|
-
import { FakeConfiguration } from '../schema/configuration.schema';
|
|
7
|
+
import type z from 'zod';
|
|
8
|
+
import type { FakeConfiguration } from '../schema/configuration.schema';
|
|
8
9
|
|
|
9
10
|
export class FakeAnalyticsProvider<
|
|
10
11
|
T extends BaseModel = BaseModel
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
Cart,
|
|
3
|
-
CartProvider,
|
|
4
3
|
CartQueryById,
|
|
5
4
|
CartMutationItemAdd,
|
|
6
5
|
CartMutationItemRemove,
|
|
7
6
|
CartMutationItemQuantityChange,
|
|
8
|
-
Session,
|
|
7
|
+
Session, RequestContext,
|
|
9
8
|
Cache,
|
|
10
9
|
CartIdentifier,
|
|
11
10
|
CartMutationApplyCoupon,
|
|
@@ -15,10 +14,12 @@ import {
|
|
|
15
14
|
CartMutationRemoveCoupon,
|
|
16
15
|
CartMutationSetBillingAddress,
|
|
17
16
|
CartMutationSetShippingInfo,
|
|
18
|
-
OrderIdentifier
|
|
17
|
+
OrderIdentifier} from '@reactionary/core';
|
|
18
|
+
import {
|
|
19
|
+
CartProvider
|
|
19
20
|
} from '@reactionary/core';
|
|
20
|
-
import z from 'zod';
|
|
21
|
-
import { FakeConfiguration } from '../schema/configuration.schema';
|
|
21
|
+
import type z from 'zod';
|
|
22
|
+
import type { FakeConfiguration } from '../schema/configuration.schema';
|
|
22
23
|
import { Faker, en, base } from '@faker-js/faker';
|
|
23
24
|
|
|
24
25
|
export class FakeCartProvider<
|
|
@@ -40,7 +41,7 @@ export class FakeCartProvider<
|
|
|
40
41
|
|
|
41
42
|
public override async getById(
|
|
42
43
|
payload: CartQueryById,
|
|
43
|
-
|
|
44
|
+
_reqCtx: RequestContext
|
|
44
45
|
): Promise<T> {
|
|
45
46
|
const cartId = payload.cart.key;
|
|
46
47
|
|
|
@@ -78,11 +79,11 @@ export class FakeCartProvider<
|
|
|
78
79
|
|
|
79
80
|
public override async add(
|
|
80
81
|
payload: CartMutationItemAdd,
|
|
81
|
-
|
|
82
|
+
reqCtx: RequestContext
|
|
82
83
|
): Promise<T> {
|
|
83
84
|
|
|
84
85
|
const cartId = payload.cart.key || `cart-${this.generator.string.uuid()}`;
|
|
85
|
-
const cart = await this.getById({ cart: { key: cartId } },
|
|
86
|
+
const cart = await this.getById({ cart: { key: cartId } }, reqCtx);
|
|
86
87
|
|
|
87
88
|
const existingItemIndex = cart.items.findIndex(
|
|
88
89
|
item => item.sku.key === payload.sku.key
|
|
@@ -95,29 +96,31 @@ export class FakeCartProvider<
|
|
|
95
96
|
|
|
96
97
|
cart.items.push({
|
|
97
98
|
identifier: { key: `item-${Date.now()}` },
|
|
98
|
-
sku:
|
|
99
|
+
sku: payload.sku,
|
|
99
100
|
quantity: payload.quantity,
|
|
100
101
|
price: {
|
|
101
102
|
unitPrice: {
|
|
102
103
|
value: price,
|
|
103
|
-
currency:
|
|
104
|
+
currency: reqCtx.languageContext.currencyCode,
|
|
104
105
|
},
|
|
105
106
|
totalPrice: {
|
|
106
107
|
value: 0, // Will be calculated below
|
|
107
|
-
currency:
|
|
108
|
+
currency: reqCtx.languageContext.currencyCode,
|
|
108
109
|
},
|
|
109
110
|
totalDiscount: {
|
|
110
111
|
value: 0,
|
|
111
|
-
currency:
|
|
112
|
+
currency: reqCtx.languageContext.currencyCode,
|
|
112
113
|
},
|
|
113
114
|
unitDiscount: {
|
|
114
115
|
value: 0,
|
|
115
|
-
currency:
|
|
116
|
+
currency: reqCtx.languageContext.currencyCode,
|
|
116
117
|
},
|
|
117
118
|
},
|
|
118
119
|
product: {
|
|
119
120
|
key: `product-for-${payload.sku.key}`,
|
|
120
|
-
}
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
|
|
121
124
|
});
|
|
122
125
|
}
|
|
123
126
|
|
|
@@ -128,10 +131,10 @@ export class FakeCartProvider<
|
|
|
128
131
|
|
|
129
132
|
public override async remove(
|
|
130
133
|
payload: CartMutationItemRemove,
|
|
131
|
-
|
|
134
|
+
reqCtx: RequestContext
|
|
132
135
|
): Promise<T> {
|
|
133
136
|
const cartId = payload.cart.key || `cart-${this.generator.string.uuid()}`;
|
|
134
|
-
const cart = await this.getById({ cart: { key: cartId } },
|
|
137
|
+
const cart = await this.getById({ cart: { key: cartId } }, reqCtx);
|
|
135
138
|
|
|
136
139
|
cart.items = cart.items.filter(
|
|
137
140
|
item => item.identifier.key !== payload.item.key
|
|
@@ -142,10 +145,10 @@ export class FakeCartProvider<
|
|
|
142
145
|
|
|
143
146
|
public override async changeQuantity(
|
|
144
147
|
payload: CartMutationItemQuantityChange,
|
|
145
|
-
|
|
148
|
+
reqCtx: RequestContext
|
|
146
149
|
): Promise<T> {
|
|
147
150
|
const cartId = payload.cart.key || `cart-${this.generator.string.uuid()}`;
|
|
148
|
-
const cart = await this.getById({ cart: { key: cartId } },
|
|
151
|
+
const cart = await this.getById({ cart: { key: cartId } }, reqCtx);
|
|
149
152
|
|
|
150
153
|
const item = cart.items.find(
|
|
151
154
|
item => item.identifier.key === payload.item.key
|
|
@@ -161,28 +164,28 @@ export class FakeCartProvider<
|
|
|
161
164
|
}
|
|
162
165
|
|
|
163
166
|
|
|
164
|
-
public override getActiveCartId(
|
|
167
|
+
public override getActiveCartId(reqCtx: RequestContext): Promise<CartIdentifier> {
|
|
165
168
|
throw new Error('Method not implemented.');
|
|
166
169
|
}
|
|
167
|
-
public override deleteCart(payload: CartMutationDeleteCart,
|
|
170
|
+
public override deleteCart(payload: CartMutationDeleteCart, reqCtx: RequestContext): Promise<T> {
|
|
168
171
|
throw new Error('Method not implemented.');
|
|
169
172
|
}
|
|
170
|
-
public override setShippingInfo(payload: CartMutationSetShippingInfo,
|
|
173
|
+
public override setShippingInfo(payload: CartMutationSetShippingInfo, reqCtx: RequestContext): Promise<T> {
|
|
171
174
|
throw new Error('Method not implemented.');
|
|
172
175
|
}
|
|
173
|
-
public override setBillingAddress(payload: CartMutationSetBillingAddress,
|
|
176
|
+
public override setBillingAddress(payload: CartMutationSetBillingAddress, reqCtx: RequestContext): Promise<T> {
|
|
174
177
|
throw new Error('Method not implemented.');
|
|
175
178
|
}
|
|
176
|
-
public override applyCouponCode(payload: CartMutationApplyCoupon,
|
|
179
|
+
public override applyCouponCode(payload: CartMutationApplyCoupon, reqCtx: RequestContext): Promise<T> {
|
|
177
180
|
throw new Error('Method not implemented.');
|
|
178
181
|
}
|
|
179
|
-
public override removeCouponCode(payload: CartMutationRemoveCoupon,
|
|
182
|
+
public override removeCouponCode(payload: CartMutationRemoveCoupon, reqCtx: RequestContext): Promise<T> {
|
|
180
183
|
throw new Error('Method not implemented.');
|
|
181
184
|
}
|
|
182
|
-
public override checkout(payload: CartMutationCheckout,
|
|
185
|
+
public override checkout(payload: CartMutationCheckout, reqCtx: RequestContext): Promise<OrderIdentifier> {
|
|
183
186
|
throw new Error('Method not implemented.');
|
|
184
187
|
}
|
|
185
|
-
public override changeCurrency(payload: CartMutationChangeCurrency,
|
|
188
|
+
public override changeCurrency(payload: CartMutationChangeCurrency, reqCtx: RequestContext): Promise<T> {
|
|
186
189
|
throw new Error('Method not implemented.');
|
|
187
190
|
}
|
|
188
191
|
|