@reactionary/source 0.0.41 → 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/.env-template +8 -5
- package/.vscode/settings.json +5 -0
- package/README.md +41 -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 +11 -9
- package/core/src/decorators/reactionary.decorator.ts +80 -8
- package/core/src/index.ts +5 -29
- package/core/src/initialization.ts +43 -0
- 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 +57 -0
- package/core/src/providers/cart.provider.ts +131 -8
- package/core/src/providers/category.provider.ts +9 -9
- package/core/src/providers/identity.provider.ts +8 -7
- package/core/src/providers/index.ts +12 -0
- package/core/src/providers/inventory.provider.ts +4 -4
- package/core/src/providers/price.provider.ts +7 -7
- package/core/src/providers/product.provider.ts +17 -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 +3 -1
- package/core/src/schemas/models/analytics.model.ts +1 -1
- package/core/src/schemas/models/cart.model.ts +16 -3
- package/core/src/schemas/models/identifiers.model.ts +90 -22
- package/core/src/schemas/models/identity.model.ts +23 -7
- package/core/src/schemas/models/index.ts +15 -0
- package/core/src/schemas/models/payment.model.ts +41 -0
- package/core/src/schemas/models/profile.model.ts +35 -0
- package/core/src/schemas/models/shipping-method.model.ts +14 -0
- package/core/src/schemas/models/store.model.ts +11 -0
- package/core/src/schemas/mutations/cart-payment.mutation.ts +21 -0
- package/core/src/schemas/mutations/cart.mutation.ts +62 -3
- package/core/src/schemas/mutations/identity.mutation.ts +8 -1
- package/core/src/schemas/mutations/index.ts +10 -0
- package/core/src/schemas/mutations/profile.mutation.ts +9 -0
- package/core/src/schemas/queries/cart-payment.query.ts +12 -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 +3 -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 +9 -4
- package/providers/commercetools/README.md +27 -0
- package/providers/commercetools/src/core/client.ts +164 -117
- package/providers/commercetools/src/core/initialize.ts +24 -14
- package/providers/commercetools/src/providers/cart-payment.provider.ts +193 -0
- package/providers/commercetools/src/providers/cart.provider.ts +402 -125
- package/providers/commercetools/src/providers/category.provider.ts +35 -35
- package/providers/commercetools/src/providers/identity.provider.ts +23 -75
- package/providers/commercetools/src/providers/index.ts +2 -0
- package/providers/commercetools/src/providers/inventory.provider.ts +69 -40
- package/providers/commercetools/src/providers/price.provider.ts +79 -47
- package/providers/commercetools/src/providers/product.provider.ts +36 -30
- package/providers/commercetools/src/providers/profile.provider.ts +61 -0
- package/providers/commercetools/src/providers/search.provider.ts +16 -12
- package/providers/commercetools/src/providers/store.provider.ts +78 -0
- package/providers/commercetools/src/schema/capabilities.schema.ts +3 -1
- package/providers/commercetools/src/schema/commercetools.schema.ts +18 -0
- package/providers/commercetools/src/schema/configuration.schema.ts +2 -1
- package/providers/commercetools/src/test/cart-payment.provider.spec.ts +145 -0
- package/providers/commercetools/src/test/cart.provider.spec.ts +82 -22
- 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 +33 -5
- 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 +7 -31
- 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 +66 -19
- 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 +13 -10
- 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 -28
- 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 +9 -4
- package/trpc/src/types.ts +24 -22
- package/core/src/cache/cache-evaluation.interface.ts +0 -19
- package/examples/node/src/test-utils.ts +0 -26
|
@@ -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,35 +1,11 @@
|
|
|
1
|
-
import { Session } from "@reactionary/core";
|
|
2
|
-
|
|
3
1
|
export function getCommercetoolsTestConfiguration() {
|
|
4
2
|
return {
|
|
5
|
-
apiUrl: process.env['
|
|
6
|
-
authUrl: process.env['
|
|
7
|
-
clientId: process.env['
|
|
8
|
-
clientSecret: process.env['
|
|
9
|
-
projectKey: process.env['
|
|
3
|
+
apiUrl: process.env['CTP_API_URL'] || '',
|
|
4
|
+
authUrl: process.env['CTP_AUTH_URL'] || '',
|
|
5
|
+
clientId: process.env['CTP_CLIENT_ID'] || '',
|
|
6
|
+
clientSecret: process.env['CTP_CLIENT_SECRET'] || '',
|
|
7
|
+
projectKey: process.env['CTP_PROJECT_KEY'] || '',
|
|
8
|
+
scopes: (process.env['CTP_SCOPES'] || '').split(',').map(x => x.trim()).filter(x => x && x.length > 0),
|
|
10
9
|
}
|
|
11
10
|
}
|
|
12
|
-
|
|
13
|
-
return {
|
|
14
|
-
id: 'test-session-id',
|
|
15
|
-
identity: {
|
|
16
|
-
type: 'Anonymous',
|
|
17
|
-
meta: {
|
|
18
|
-
cache: { hit: false, key: '' },
|
|
19
|
-
placeholder: false,
|
|
20
|
-
},
|
|
21
|
-
id: '',
|
|
22
|
-
token: undefined,
|
|
23
|
-
issued: new Date(),
|
|
24
|
-
expiry: new Date(new Date().getTime() + 3600 * 1000), // 1 hour from now
|
|
25
|
-
},
|
|
26
|
-
languageContext: {
|
|
27
|
-
locale: 'en-US',
|
|
28
|
-
currencyCode: 'USD',
|
|
29
|
-
countryCode: 'US',
|
|
30
|
-
},
|
|
31
|
-
storeIdentifier: {
|
|
32
|
-
key: 'the-good-store',
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
}
|
|
11
|
+
|
|
@@ -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,15 +1,25 @@
|
|
|
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,
|
|
9
|
+
CartIdentifier,
|
|
10
|
+
CartMutationApplyCoupon,
|
|
11
|
+
CartMutationChangeCurrency,
|
|
12
|
+
CartMutationCheckout,
|
|
13
|
+
CartMutationDeleteCart,
|
|
14
|
+
CartMutationRemoveCoupon,
|
|
15
|
+
CartMutationSetBillingAddress,
|
|
16
|
+
CartMutationSetShippingInfo,
|
|
17
|
+
OrderIdentifier} from '@reactionary/core';
|
|
18
|
+
import {
|
|
19
|
+
CartProvider
|
|
10
20
|
} from '@reactionary/core';
|
|
11
|
-
import z from 'zod';
|
|
12
|
-
import { FakeConfiguration } from '../schema/configuration.schema';
|
|
21
|
+
import type z from 'zod';
|
|
22
|
+
import type { FakeConfiguration } from '../schema/configuration.schema';
|
|
13
23
|
import { Faker, en, base } from '@faker-js/faker';
|
|
14
24
|
|
|
15
25
|
export class FakeCartProvider<
|
|
@@ -31,7 +41,7 @@ export class FakeCartProvider<
|
|
|
31
41
|
|
|
32
42
|
public override async getById(
|
|
33
43
|
payload: CartQueryById,
|
|
34
|
-
|
|
44
|
+
_reqCtx: RequestContext
|
|
35
45
|
): Promise<T> {
|
|
36
46
|
const cartId = payload.cart.key;
|
|
37
47
|
|
|
@@ -69,14 +79,14 @@ export class FakeCartProvider<
|
|
|
69
79
|
|
|
70
80
|
public override async add(
|
|
71
81
|
payload: CartMutationItemAdd,
|
|
72
|
-
|
|
82
|
+
reqCtx: RequestContext
|
|
73
83
|
): Promise<T> {
|
|
74
84
|
|
|
75
85
|
const cartId = payload.cart.key || `cart-${this.generator.string.uuid()}`;
|
|
76
|
-
const cart = await this.getById({ cart: { key: cartId } },
|
|
86
|
+
const cart = await this.getById({ cart: { key: cartId } }, reqCtx);
|
|
77
87
|
|
|
78
88
|
const existingItemIndex = cart.items.findIndex(
|
|
79
|
-
item => item.
|
|
89
|
+
item => item.sku.key === payload.sku.key
|
|
80
90
|
);
|
|
81
91
|
|
|
82
92
|
if (existingItemIndex >= 0) {
|
|
@@ -86,26 +96,31 @@ export class FakeCartProvider<
|
|
|
86
96
|
|
|
87
97
|
cart.items.push({
|
|
88
98
|
identifier: { key: `item-${Date.now()}` },
|
|
89
|
-
|
|
99
|
+
sku: payload.sku,
|
|
90
100
|
quantity: payload.quantity,
|
|
91
101
|
price: {
|
|
92
102
|
unitPrice: {
|
|
93
103
|
value: price,
|
|
94
|
-
currency:
|
|
104
|
+
currency: reqCtx.languageContext.currencyCode,
|
|
95
105
|
},
|
|
96
106
|
totalPrice: {
|
|
97
107
|
value: 0, // Will be calculated below
|
|
98
|
-
currency:
|
|
108
|
+
currency: reqCtx.languageContext.currencyCode,
|
|
99
109
|
},
|
|
100
110
|
totalDiscount: {
|
|
101
111
|
value: 0,
|
|
102
|
-
currency:
|
|
112
|
+
currency: reqCtx.languageContext.currencyCode,
|
|
103
113
|
},
|
|
104
114
|
unitDiscount: {
|
|
105
115
|
value: 0,
|
|
106
|
-
currency:
|
|
116
|
+
currency: reqCtx.languageContext.currencyCode,
|
|
107
117
|
},
|
|
108
118
|
},
|
|
119
|
+
product: {
|
|
120
|
+
key: `product-for-${payload.sku.key}`,
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
|
|
109
124
|
});
|
|
110
125
|
}
|
|
111
126
|
|
|
@@ -116,10 +131,10 @@ export class FakeCartProvider<
|
|
|
116
131
|
|
|
117
132
|
public override async remove(
|
|
118
133
|
payload: CartMutationItemRemove,
|
|
119
|
-
|
|
134
|
+
reqCtx: RequestContext
|
|
120
135
|
): Promise<T> {
|
|
121
136
|
const cartId = payload.cart.key || `cart-${this.generator.string.uuid()}`;
|
|
122
|
-
const cart = await this.getById({ cart: { key: cartId } },
|
|
137
|
+
const cart = await this.getById({ cart: { key: cartId } }, reqCtx);
|
|
123
138
|
|
|
124
139
|
cart.items = cart.items.filter(
|
|
125
140
|
item => item.identifier.key !== payload.item.key
|
|
@@ -130,15 +145,17 @@ export class FakeCartProvider<
|
|
|
130
145
|
|
|
131
146
|
public override async changeQuantity(
|
|
132
147
|
payload: CartMutationItemQuantityChange,
|
|
133
|
-
|
|
148
|
+
reqCtx: RequestContext
|
|
134
149
|
): Promise<T> {
|
|
135
150
|
const cartId = payload.cart.key || `cart-${this.generator.string.uuid()}`;
|
|
136
|
-
const cart = await this.getById({ cart: { key: cartId } },
|
|
151
|
+
const cart = await this.getById({ cart: { key: cartId } }, reqCtx);
|
|
137
152
|
|
|
138
153
|
const item = cart.items.find(
|
|
139
154
|
item => item.identifier.key === payload.item.key
|
|
140
155
|
);
|
|
141
|
-
|
|
156
|
+
if (payload.quantity < 1) {
|
|
157
|
+
return cart;
|
|
158
|
+
}
|
|
142
159
|
if (item) {
|
|
143
160
|
item.quantity = payload.quantity;
|
|
144
161
|
}
|
|
@@ -147,6 +164,33 @@ export class FakeCartProvider<
|
|
|
147
164
|
}
|
|
148
165
|
|
|
149
166
|
|
|
167
|
+
public override getActiveCartId(reqCtx: RequestContext): Promise<CartIdentifier> {
|
|
168
|
+
throw new Error('Method not implemented.');
|
|
169
|
+
}
|
|
170
|
+
public override deleteCart(payload: CartMutationDeleteCart, reqCtx: RequestContext): Promise<T> {
|
|
171
|
+
throw new Error('Method not implemented.');
|
|
172
|
+
}
|
|
173
|
+
public override setShippingInfo(payload: CartMutationSetShippingInfo, reqCtx: RequestContext): Promise<T> {
|
|
174
|
+
throw new Error('Method not implemented.');
|
|
175
|
+
}
|
|
176
|
+
public override setBillingAddress(payload: CartMutationSetBillingAddress, reqCtx: RequestContext): Promise<T> {
|
|
177
|
+
throw new Error('Method not implemented.');
|
|
178
|
+
}
|
|
179
|
+
public override applyCouponCode(payload: CartMutationApplyCoupon, reqCtx: RequestContext): Promise<T> {
|
|
180
|
+
throw new Error('Method not implemented.');
|
|
181
|
+
}
|
|
182
|
+
public override removeCouponCode(payload: CartMutationRemoveCoupon, reqCtx: RequestContext): Promise<T> {
|
|
183
|
+
throw new Error('Method not implemented.');
|
|
184
|
+
}
|
|
185
|
+
public override checkout(payload: CartMutationCheckout, reqCtx: RequestContext): Promise<OrderIdentifier> {
|
|
186
|
+
throw new Error('Method not implemented.');
|
|
187
|
+
}
|
|
188
|
+
public override changeCurrency(payload: CartMutationChangeCurrency, reqCtx: RequestContext): Promise<T> {
|
|
189
|
+
throw new Error('Method not implemented.');
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
150
194
|
|
|
151
195
|
protected recalculateCart(cart: T) {
|
|
152
196
|
cart.items.forEach(item => {
|
|
@@ -163,4 +207,7 @@ export class FakeCartProvider<
|
|
|
163
207
|
currency: cart.items[0]?.price.unitPrice.currency || 'USD',
|
|
164
208
|
};
|
|
165
209
|
}
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
|
|
166
213
|
}
|
|
@@ -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.
|
|
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
|
];
|