@reactionary/source 0.0.48 → 0.0.52
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/core/package.json +4 -3
- package/core/src/cache/cache.interface.ts +1 -1
- package/core/src/cache/memory-cache.ts +2 -2
- package/core/src/cache/noop-cache.ts +1 -1
- package/core/src/cache/redis-cache.ts +1 -1
- package/core/src/client/client-builder.ts +4 -4
- package/core/src/client/client.ts +12 -12
- package/core/src/decorators/reactionary.decorator.ts +22 -2
- package/core/src/index.ts +14 -14
- package/core/src/initialization.ts +1 -1
- package/core/src/providers/analytics.provider.ts +2 -2
- package/core/src/providers/base.provider.ts +5 -5
- package/core/src/providers/cart.provider.ts +6 -6
- package/core/src/providers/category.provider.ts +4 -9
- package/core/src/providers/checkout.provider.ts +156 -0
- package/core/src/providers/identity.provider.ts +5 -5
- package/core/src/providers/index.ts +13 -12
- package/core/src/providers/inventory.provider.ts +4 -4
- package/core/src/providers/order.provider.ts +31 -0
- package/core/src/providers/price.provider.ts +5 -5
- package/core/src/providers/product.provider.ts +5 -5
- package/core/src/providers/profile.provider.ts +5 -5
- package/core/src/providers/search.provider.ts +4 -4
- package/core/src/providers/store.provider.ts +4 -4
- package/core/src/schemas/capabilities.schema.ts +2 -1
- package/core/src/schemas/models/analytics.model.ts +1 -1
- package/core/src/schemas/models/cart.model.ts +3 -28
- package/core/src/schemas/models/category.model.ts +2 -2
- package/core/src/schemas/models/checkout.model.ts +66 -0
- package/core/src/schemas/models/cost.model.ts +21 -0
- package/core/src/schemas/models/identifiers.model.ts +23 -2
- package/core/src/schemas/models/identity.model.ts +8 -5
- package/core/src/schemas/models/index.ts +19 -15
- package/core/src/schemas/models/inventory.model.ts +2 -2
- package/core/src/schemas/models/order.model.ts +46 -0
- package/core/src/schemas/models/payment.model.ts +5 -12
- package/core/src/schemas/models/price.model.ts +3 -3
- package/core/src/schemas/models/product.model.ts +6 -3
- package/core/src/schemas/models/profile.model.ts +2 -2
- package/core/src/schemas/models/search.model.ts +2 -3
- package/core/src/schemas/models/shipping-method.model.ts +34 -3
- package/core/src/schemas/models/store.model.ts +2 -2
- package/core/src/schemas/mutations/analytics.mutation.ts +2 -2
- package/core/src/schemas/mutations/cart.mutation.ts +5 -5
- package/core/src/schemas/mutations/checkout.mutation.ts +50 -0
- package/core/src/schemas/mutations/identity.mutation.ts +1 -1
- package/core/src/schemas/mutations/index.ts +10 -10
- package/core/src/schemas/mutations/profile.mutation.ts +1 -1
- package/core/src/schemas/queries/cart.query.ts +2 -2
- package/core/src/schemas/queries/category.query.ts +3 -3
- package/core/src/schemas/queries/checkout.query.ts +22 -0
- package/core/src/schemas/queries/identity.query.ts +1 -1
- package/core/src/schemas/queries/index.ts +13 -12
- package/core/src/schemas/queries/inventory.query.ts +2 -2
- package/core/src/schemas/queries/order.query.ts +9 -0
- package/core/src/schemas/queries/price.query.ts +2 -2
- package/core/src/schemas/queries/product.query.ts +9 -2
- package/core/src/schemas/queries/profile.query.ts +1 -1
- package/core/src/schemas/queries/search.query.ts +2 -2
- package/core/src/schemas/queries/store.query.ts +1 -1
- package/core/src/schemas/session.schema.ts +3 -3
- package/core/tsconfig.json +3 -2
- package/examples/next/next.config.js +17 -6
- package/examples/next/src/app/page.tsx +1 -2
- package/examples/node/package.json +2 -1
- package/examples/node/src/basic/basic-node-setup.spec.ts +1 -1
- package/examples/node/tsconfig.json +2 -1
- package/examples/node/tsconfig.spec.json +3 -2
- package/package.json +3 -1
- package/providers/algolia/package.json +2 -1
- package/providers/algolia/src/core/initialize.ts +5 -5
- package/providers/algolia/src/index.ts +5 -5
- package/providers/algolia/src/providers/product.provider.ts +8 -2
- package/providers/algolia/src/providers/search.provider.ts +1 -1
- package/providers/algolia/src/test/search.provider.spec.ts +1 -1
- package/providers/algolia/tsconfig.json +2 -1
- package/providers/algolia/tsconfig.spec.json +3 -2
- package/providers/commercetools/{jest.config.ts → jest.config.cjs} +1 -1
- package/providers/commercetools/package.json +3 -2
- package/providers/commercetools/src/core/client.ts +63 -32
- package/providers/commercetools/src/core/initialize.ts +20 -16
- package/providers/commercetools/src/index.ts +10 -10
- package/providers/commercetools/src/providers/cart.provider.ts +14 -19
- package/providers/commercetools/src/providers/category.provider.ts +3 -12
- package/providers/commercetools/src/providers/checkout.provider.ts +644 -0
- package/providers/commercetools/src/providers/identity.provider.ts +8 -8
- package/providers/commercetools/src/providers/index.ts +12 -9
- package/providers/commercetools/src/providers/inventory.provider.ts +2 -4
- package/providers/commercetools/src/providers/order.provider.ts +163 -0
- package/providers/commercetools/src/providers/price.provider.ts +3 -3
- package/providers/commercetools/src/providers/product.provider.ts +24 -6
- package/providers/commercetools/src/providers/profile.provider.ts +2 -2
- package/providers/commercetools/src/providers/search.provider.ts +3 -5
- package/providers/commercetools/src/providers/store.provider.ts +3 -3
- package/providers/commercetools/src/schema/capabilities.schema.ts +2 -1
- package/providers/commercetools/src/schema/commercetools.schema.ts +7 -5
- package/providers/commercetools/src/schema/configuration.schema.ts +2 -0
- package/providers/commercetools/src/test/cart.provider.spec.ts +24 -4
- package/providers/commercetools/src/test/category.provider.spec.ts +3 -3
- package/providers/commercetools/src/test/checkout.provider.spec.ts +312 -0
- package/providers/commercetools/src/test/identity.provider.spec.ts +3 -3
- package/providers/commercetools/src/test/inventory.provider.spec.ts +2 -2
- package/providers/commercetools/src/test/price.provider.spec.ts +4 -4
- package/providers/commercetools/src/test/product.provider.spec.ts +22 -5
- package/providers/commercetools/src/test/profile.provider.spec.ts +3 -3
- package/providers/commercetools/src/test/search.provider.spec.ts +2 -2
- package/providers/commercetools/src/test/store.provider.spec.ts +2 -2
- package/providers/commercetools/src/test/test-utils.ts +14 -0
- package/providers/commercetools/tsconfig.json +2 -1
- package/providers/commercetools/tsconfig.spec.json +4 -3
- package/providers/fake/{jest.config.ts → jest.config.cjs} +1 -1
- package/providers/fake/package.json +2 -2
- package/providers/fake/src/core/initialize.ts +6 -6
- package/providers/fake/src/index.ts +4 -4
- package/providers/fake/src/providers/analytics.provider.ts +1 -1
- package/providers/fake/src/providers/cart.provider.ts +2 -2
- package/providers/fake/src/providers/category.provider.ts +7 -3
- package/providers/fake/src/providers/identity.provider.ts +1 -1
- package/providers/fake/src/providers/index.ts +9 -9
- package/providers/fake/src/providers/inventory.provider.ts +1 -1
- package/providers/fake/src/providers/price.provider.ts +1 -1
- package/providers/fake/src/providers/product.provider.ts +10 -4
- package/providers/fake/src/providers/search.provider.ts +2 -5
- package/providers/fake/src/providers/store.provider.ts +2 -3
- package/providers/fake/src/test/cart.provider.spec.ts +3 -3
- package/providers/fake/src/test/category.provider.spec.ts +2 -2
- package/providers/fake/src/test/price.provider.spec.ts +2 -2
- package/providers/fake/src/test/product.provider.spec.ts +8 -8
- package/providers/fake/src/test/test-utils.ts +1 -1
- package/providers/fake/tsconfig.json +2 -1
- package/providers/fake/tsconfig.spec.json +1 -3
- package/providers/posthog/package.json +4 -4
- package/providers/posthog/project.json +2 -2
- package/providers/posthog/src/core/initialize.ts +2 -2
- package/providers/posthog/src/index.ts +3 -3
- package/providers/posthog/tsconfig.json +2 -1
- package/tsconfig.base.json +3 -4
- package/.claude/settings.local.json +0 -28
- package/core/src/providers/cart-payment.provider.ts +0 -57
- package/core/src/schemas/mutations/cart-payment.mutation.ts +0 -21
- package/core/src/schemas/queries/cart-payment.query.ts +0 -12
- package/otel/README.md +0 -227
- package/otel/eslint.config.mjs +0 -23
- package/otel/package.json +0 -11
- package/otel/pnpm-lock.yaml +0 -805
- package/otel/project.json +0 -33
- package/otel/src/index.ts +0 -22
- package/otel/src/metrics.ts +0 -76
- package/otel/src/provider-instrumentation.ts +0 -108
- package/otel/src/test/otel.spec.ts +0 -8
- package/otel/src/trace-decorator.ts +0 -226
- package/otel/src/tracer.ts +0 -83
- package/otel/src/trpc-middleware.ts +0 -128
- package/otel/tsconfig.json +0 -23
- package/otel/tsconfig.lib.json +0 -23
- package/otel/tsconfig.spec.json +0 -28
- package/otel/vite.config.ts +0 -24
- package/providers/commercetools/src/providers/cart-payment.provider.ts +0 -193
- package/providers/commercetools/src/test/cart-payment.provider.spec.ts +0 -145
- package/trpc/README.md +0 -7
- package/trpc/__mocks__/superjson.js +0 -25
- package/trpc/eslint.config.mjs +0 -19
- package/trpc/jest.config.ts +0 -14
- package/trpc/package.json +0 -14
- package/trpc/project.json +0 -31
- package/trpc/src/client.ts +0 -175
- package/trpc/src/index.ts +0 -44
- package/trpc/src/integration.spec.ts +0 -223
- package/trpc/src/server.ts +0 -125
- package/trpc/src/test-utils.ts +0 -31
- package/trpc/src/transparent-client.spec.ts +0 -162
- package/trpc/src/types.ts +0 -144
- package/trpc/tsconfig.json +0 -16
- package/trpc/tsconfig.lib.json +0 -10
- package/trpc/tsconfig.spec.json +0 -15
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
2
|
+
import type { Cart, Checkout, RequestContext } from '@reactionary/core';
|
|
3
|
+
import {
|
|
4
|
+
CartSchema,
|
|
5
|
+
CheckoutSchema,
|
|
6
|
+
IdentitySchema,
|
|
7
|
+
NoOpCache,
|
|
8
|
+
PaymentInstructionSchema,
|
|
9
|
+
ShippingInstructionSchema,
|
|
10
|
+
createInitialRequestContext,
|
|
11
|
+
} from '@reactionary/core';
|
|
12
|
+
import { getCommercetoolsTestConfiguration } from './test-utils.js';
|
|
13
|
+
import { CommercetoolsCartProvider } from '../providers/cart.provider.js';
|
|
14
|
+
import { CommercetoolsIdentityProvider } from '../providers/identity.provider.js';
|
|
15
|
+
import { CommercetoolsCheckoutProvider } from '../providers/checkout.provider.js';
|
|
16
|
+
|
|
17
|
+
const testData = {
|
|
18
|
+
skuWithoutTiers: 'SGB-01',
|
|
19
|
+
skuWithTiers: 'GMCT-01',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
describe('Commercetools Checkout Provider', () => {
|
|
23
|
+
let provider: CommercetoolsCheckoutProvider;
|
|
24
|
+
let cartProvider: CommercetoolsCartProvider;
|
|
25
|
+
let identityProvider: CommercetoolsIdentityProvider;
|
|
26
|
+
let reqCtx: RequestContext;
|
|
27
|
+
|
|
28
|
+
beforeAll(() => {
|
|
29
|
+
provider = new CommercetoolsCheckoutProvider(
|
|
30
|
+
getCommercetoolsTestConfiguration(),
|
|
31
|
+
CheckoutSchema,
|
|
32
|
+
new NoOpCache()
|
|
33
|
+
);
|
|
34
|
+
cartProvider = new CommercetoolsCartProvider(
|
|
35
|
+
getCommercetoolsTestConfiguration(),
|
|
36
|
+
CartSchema,
|
|
37
|
+
new NoOpCache()
|
|
38
|
+
);
|
|
39
|
+
identityProvider = new CommercetoolsIdentityProvider(
|
|
40
|
+
getCommercetoolsTestConfiguration(),
|
|
41
|
+
IdentitySchema,
|
|
42
|
+
new NoOpCache()
|
|
43
|
+
);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
reqCtx = createInitialRequestContext();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('anonymous sessions', () => {
|
|
51
|
+
let cart: Cart;
|
|
52
|
+
|
|
53
|
+
beforeEach(async () => {
|
|
54
|
+
cart = await cartProvider.add(
|
|
55
|
+
{
|
|
56
|
+
cart: { key: '', version: 0 },
|
|
57
|
+
sku: {
|
|
58
|
+
key: testData.skuWithoutTiers,
|
|
59
|
+
},
|
|
60
|
+
quantity: 1,
|
|
61
|
+
},
|
|
62
|
+
reqCtx
|
|
63
|
+
);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('can create a checkout session from a cart', async () => {
|
|
67
|
+
// we have either an anonymous user, or an authenticated user.
|
|
68
|
+
// if it is anonymous, we assume you will have collected some basic info by now ?
|
|
69
|
+
|
|
70
|
+
const checkout = await provider.initiateCheckoutForCart(
|
|
71
|
+
{
|
|
72
|
+
cart: cart.identifier,
|
|
73
|
+
billingAddress: {
|
|
74
|
+
countryCode: 'US',
|
|
75
|
+
firstName: 'John',
|
|
76
|
+
lastName: 'Doe',
|
|
77
|
+
streetAddress: '123 Main St',
|
|
78
|
+
streetNumber: '1A',
|
|
79
|
+
postalCode: '12345',
|
|
80
|
+
city: 'Anytown',
|
|
81
|
+
region: '',
|
|
82
|
+
},
|
|
83
|
+
notificationEmail: 'sample@example.com',
|
|
84
|
+
notificationPhone: '+4512345678',
|
|
85
|
+
},
|
|
86
|
+
reqCtx
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
expect(checkout.identifier.key).toBeDefined();
|
|
90
|
+
expect(checkout.originalCartReference.key).toBe(cart.identifier.key);
|
|
91
|
+
expect(checkout.billingAddress?.firstName).toBe('John');
|
|
92
|
+
expect(checkout.items.length).toBe(1);
|
|
93
|
+
expect(checkout.items[0].sku.key).toBe(testData.skuWithoutTiers);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
describe('checkout actions', () => {
|
|
97
|
+
let checkout: Checkout;
|
|
98
|
+
beforeEach(async () => {
|
|
99
|
+
checkout = await provider.initiateCheckoutForCart(
|
|
100
|
+
{
|
|
101
|
+
cart: cart.identifier,
|
|
102
|
+
billingAddress: {
|
|
103
|
+
countryCode: 'US',
|
|
104
|
+
firstName: 'John',
|
|
105
|
+
lastName: 'Doe',
|
|
106
|
+
streetAddress: '123 Main St',
|
|
107
|
+
streetNumber: '1A',
|
|
108
|
+
postalCode: '12345',
|
|
109
|
+
city: 'Anytown',
|
|
110
|
+
region: '',
|
|
111
|
+
},
|
|
112
|
+
notificationEmail: 'sample@example.com',
|
|
113
|
+
notificationPhone: '+4512345678',
|
|
114
|
+
},
|
|
115
|
+
reqCtx
|
|
116
|
+
);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('can list payment methods', async () => {
|
|
120
|
+
const paymentMethods = await provider.getAvailablePaymentMethods(
|
|
121
|
+
{
|
|
122
|
+
checkout: checkout.identifier,
|
|
123
|
+
},
|
|
124
|
+
reqCtx
|
|
125
|
+
);
|
|
126
|
+
expect(paymentMethods.length).toBeGreaterThan(0);
|
|
127
|
+
expect(
|
|
128
|
+
paymentMethods.find((x) => x.identifier.method === 'stripe')
|
|
129
|
+
).toBeDefined();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('can list shipping methods', async () => {
|
|
133
|
+
const shippingMethods = await provider.getAvailableShippingMethods(
|
|
134
|
+
{
|
|
135
|
+
checkout: checkout.identifier,
|
|
136
|
+
},
|
|
137
|
+
reqCtx
|
|
138
|
+
);
|
|
139
|
+
expect(shippingMethods.length).toBeGreaterThan(0);
|
|
140
|
+
expect(
|
|
141
|
+
shippingMethods.find((x) => x.identifier.key === 'us-delivery')
|
|
142
|
+
).toBeDefined();
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('can add a payment instruction', async () => {
|
|
146
|
+
const paymentMethods = await provider.getAvailablePaymentMethods(
|
|
147
|
+
{
|
|
148
|
+
checkout: checkout.identifier,
|
|
149
|
+
},
|
|
150
|
+
reqCtx
|
|
151
|
+
);
|
|
152
|
+
const pm = paymentMethods.find((x) => x.identifier.method === 'stripe');
|
|
153
|
+
expect(pm).toBeDefined();
|
|
154
|
+
|
|
155
|
+
const checkoutWithPi = await provider.addPaymentInstruction(
|
|
156
|
+
{
|
|
157
|
+
checkout: checkout.identifier,
|
|
158
|
+
paymentInstruction: PaymentInstructionSchema.parse({
|
|
159
|
+
paymentMethod: pm?.identifier,
|
|
160
|
+
amount: checkout.price.grandTotal,
|
|
161
|
+
protocolData: [{ key: 'test-key', value: 'test-value' }],
|
|
162
|
+
}),
|
|
163
|
+
},
|
|
164
|
+
reqCtx
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
expect(checkoutWithPi.paymentInstructions.length).toBe(1);
|
|
168
|
+
expect(checkoutWithPi.paymentInstructions[0].paymentMethod.method).toBe(
|
|
169
|
+
'stripe'
|
|
170
|
+
);
|
|
171
|
+
expect(checkoutWithPi.paymentInstructions[0].protocolData.find(x => x.key === 'stripe_clientSecret')?.value).toBeDefined();
|
|
172
|
+
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
xit('can cancel an in-progress payment', async () => {
|
|
176
|
+
const paymentMethods = await provider.getAvailablePaymentMethods(
|
|
177
|
+
{
|
|
178
|
+
checkout: checkout.identifier,
|
|
179
|
+
},
|
|
180
|
+
reqCtx
|
|
181
|
+
);
|
|
182
|
+
const pm = paymentMethods.find((x) => x.identifier.method === 'stripe');
|
|
183
|
+
expect(pm).toBeDefined();
|
|
184
|
+
|
|
185
|
+
const checkoutWithPi = await provider.addPaymentInstruction(
|
|
186
|
+
{
|
|
187
|
+
checkout: checkout.identifier,
|
|
188
|
+
paymentInstruction: PaymentInstructionSchema.parse({
|
|
189
|
+
paymentMethod: pm?.identifier,
|
|
190
|
+
amount: checkout.price.grandTotal,
|
|
191
|
+
protocolData: [{ key: 'test-key', value: 'test-value' }],
|
|
192
|
+
}),
|
|
193
|
+
},
|
|
194
|
+
reqCtx
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
expect(checkoutWithPi.paymentInstructions.length).toBe(1);
|
|
198
|
+
|
|
199
|
+
const checkoutAfterCancel = await provider.removePaymentInstruction(
|
|
200
|
+
{
|
|
201
|
+
checkout: checkout.identifier,
|
|
202
|
+
paymentInstruction:
|
|
203
|
+
checkoutWithPi.paymentInstructions[0].identifier,
|
|
204
|
+
},
|
|
205
|
+
reqCtx
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
expect(checkoutAfterCancel.paymentInstructions.length).toBe(0);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('can set shipping address', async () => {
|
|
212
|
+
const checkoutWithShipping = await provider.setShippingAddress(
|
|
213
|
+
{
|
|
214
|
+
checkout: checkout.identifier,
|
|
215
|
+
shippingAddress: {
|
|
216
|
+
countryCode: 'US',
|
|
217
|
+
firstName: 'Jane',
|
|
218
|
+
lastName: 'Doe',
|
|
219
|
+
streetAddress: '456 Other St',
|
|
220
|
+
streetNumber: '2B',
|
|
221
|
+
postalCode: '54321',
|
|
222
|
+
city: 'Othertown',
|
|
223
|
+
region: '',
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
reqCtx
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
expect(checkoutWithShipping.shippingAddress).toBeDefined();
|
|
230
|
+
expect(checkoutWithShipping.shippingAddress?.firstName).toBe('Jane');
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it('can set shipping instructions', async () => {
|
|
234
|
+
const shippingMethods = await provider.getAvailableShippingMethods(
|
|
235
|
+
{
|
|
236
|
+
checkout: checkout.identifier,
|
|
237
|
+
},
|
|
238
|
+
reqCtx
|
|
239
|
+
);
|
|
240
|
+
const sm = shippingMethods.find((x) => x.identifier.key === 'us-delivery');
|
|
241
|
+
expect(sm).toBeDefined();
|
|
242
|
+
|
|
243
|
+
const shippingInstruction = ShippingInstructionSchema.parse({
|
|
244
|
+
shippingMethod: sm?.identifier || { key: '' },
|
|
245
|
+
amount: checkout.price.totalShipping,
|
|
246
|
+
instructions: 'Leave at front door if not home',
|
|
247
|
+
consentForUnattendedDelivery: true,
|
|
248
|
+
pickupPoint: '4190asx141', // this would be a real pickup point ID in a real scenario
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
const checkoutWithShipping = await provider.setShippingInstruction(
|
|
252
|
+
{
|
|
253
|
+
checkout: checkout.identifier,
|
|
254
|
+
shippingInstruction,
|
|
255
|
+
},
|
|
256
|
+
reqCtx
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
expect(checkout.price.totalShipping.value).toBe(0);
|
|
260
|
+
expect(checkoutWithShipping.price.totalShipping.value).toBeGreaterThan(0);
|
|
261
|
+
expect(checkoutWithShipping.shippingInstruction).toBeDefined();
|
|
262
|
+
expect(
|
|
263
|
+
checkoutWithShipping.shippingInstruction?.shippingMethod.key
|
|
264
|
+
).toBe('us-delivery');
|
|
265
|
+
expect(checkoutWithShipping.shippingInstruction?.instructions).toBe(
|
|
266
|
+
'Leave at front door if not home'
|
|
267
|
+
);
|
|
268
|
+
expect(checkoutWithShipping.shippingInstruction?.pickupPoint).toBe(
|
|
269
|
+
'4190asx141'
|
|
270
|
+
);
|
|
271
|
+
expect(
|
|
272
|
+
checkoutWithShipping.shippingInstruction?.consentForUnattendedDelivery
|
|
273
|
+
).toBe(true);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
xit('wont report it finalizable until everything is paid/authorized', async () => {
|
|
277
|
+
expect(checkout.readyForFinalization).toBe(false);
|
|
278
|
+
const pm = (
|
|
279
|
+
await provider.getAvailablePaymentMethods(
|
|
280
|
+
{
|
|
281
|
+
checkout: checkout.identifier,
|
|
282
|
+
},
|
|
283
|
+
reqCtx
|
|
284
|
+
)
|
|
285
|
+
).find((x) => x.identifier.method === 'stripe');
|
|
286
|
+
expect(pm).toBeDefined();
|
|
287
|
+
|
|
288
|
+
const checkoutWithPi = await provider.addPaymentInstruction(
|
|
289
|
+
{
|
|
290
|
+
checkout: checkout.identifier,
|
|
291
|
+
paymentInstruction: PaymentInstructionSchema.parse({
|
|
292
|
+
paymentMethod: pm?.identifier,
|
|
293
|
+
amount: checkout.price.grandTotal,
|
|
294
|
+
protocolData: [{ key: 'test-key', value: 'test-value' }],
|
|
295
|
+
}),
|
|
296
|
+
},
|
|
297
|
+
reqCtx
|
|
298
|
+
);
|
|
299
|
+
|
|
300
|
+
// do something to simulate payment authorization ?
|
|
301
|
+
const checkoutReady = await provider.getById(
|
|
302
|
+
{ identifier: checkoutWithPi.identifier },
|
|
303
|
+
reqCtx
|
|
304
|
+
);
|
|
305
|
+
if (!checkoutReady) {
|
|
306
|
+
fail('checkout not found');
|
|
307
|
+
}
|
|
308
|
+
expect(checkoutReady.readyForFinalization).toBe(true);
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
});
|
|
@@ -6,9 +6,9 @@ import {
|
|
|
6
6
|
NoOpCache,
|
|
7
7
|
createInitialRequestContext,
|
|
8
8
|
} from '@reactionary/core';
|
|
9
|
-
import { getCommercetoolsTestConfiguration } from './test-utils';
|
|
10
|
-
import { CommercetoolsIdentityProvider } from '../providers/identity.provider';
|
|
11
|
-
import { CommercetoolsCartProvider } from '../providers/cart.provider';
|
|
9
|
+
import { getCommercetoolsTestConfiguration } from './test-utils.js';
|
|
10
|
+
import { CommercetoolsIdentityProvider } from '../providers/identity.provider.js';
|
|
11
|
+
import { CommercetoolsCartProvider } from '../providers/cart.provider.js';
|
|
12
12
|
|
|
13
13
|
describe('Commercetools Identity Provider', () => {
|
|
14
14
|
let provider: CommercetoolsIdentityProvider;
|
|
@@ -5,8 +5,8 @@ import {
|
|
|
5
5
|
NoOpCache,
|
|
6
6
|
createInitialRequestContext,
|
|
7
7
|
} from '@reactionary/core';
|
|
8
|
-
import { getCommercetoolsTestConfiguration } from './test-utils';
|
|
9
|
-
import { CommercetoolsInventoryProvider } from '../providers/inventory.provider';
|
|
8
|
+
import { getCommercetoolsTestConfiguration } from './test-utils.js';
|
|
9
|
+
import { CommercetoolsInventoryProvider } from '../providers/inventory.provider.js';
|
|
10
10
|
|
|
11
11
|
describe('Commercetools Inventory Provider', () => {
|
|
12
12
|
let provider: CommercetoolsInventoryProvider;
|
|
@@ -2,10 +2,10 @@ import 'dotenv/config';
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
import type { RequestContext} from '@reactionary/core';
|
|
5
|
-
import { NoOpCache, PriceSchema,
|
|
6
|
-
import { getCommercetoolsTestConfiguration } from './test-utils';
|
|
5
|
+
import { NoOpCache, PriceSchema, createInitialRequestContext,} from '@reactionary/core';
|
|
6
|
+
import { getCommercetoolsTestConfiguration } from './test-utils.js';
|
|
7
7
|
|
|
8
|
-
import { CommercetoolsPriceProvider } from '../providers/price.provider';
|
|
8
|
+
import { CommercetoolsPriceProvider } from '../providers/price.provider.js';
|
|
9
9
|
|
|
10
10
|
const testData = {
|
|
11
11
|
skuWithoutTiers: 'SGB-01',
|
|
@@ -39,7 +39,7 @@ describe('Commercetools Price Provider', () => {
|
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
xit('should be able to get prices for a product with tiers', async () => {
|
|
43
43
|
const result = await provider.getBySKU({ sku: { key: testData.skuWithTiers }}, reqCtx);
|
|
44
44
|
|
|
45
45
|
expect(result).toBeTruthy();
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import 'dotenv/config';
|
|
2
2
|
import type { RequestContext} from '@reactionary/core';
|
|
3
|
-
import { NoOpCache, ProductSchema,
|
|
4
|
-
import { CommercetoolsProductProvider } from '../providers/product.provider';
|
|
5
|
-
import { getCommercetoolsTestConfiguration } from './test-utils';
|
|
3
|
+
import { NoOpCache, ProductSchema, createInitialRequestContext } from '@reactionary/core';
|
|
4
|
+
import { CommercetoolsProductProvider } from '../providers/product.provider.js';
|
|
5
|
+
import { getCommercetoolsTestConfiguration } from './test-utils.js';
|
|
6
6
|
|
|
7
7
|
const testData = {
|
|
8
8
|
product : {
|
|
9
9
|
id: '4d28f98d-c446-446e-b59a-d9f718e5b98a',
|
|
10
10
|
name: 'Sunnai Glass Bowl',
|
|
11
|
-
image: 'https://storage.googleapis.com/merchant-center-europe/sample-data/goodstore/Sunnai_Glass_Bowl-1.1.jpeg'
|
|
12
|
-
|
|
11
|
+
image: 'https://storage.googleapis.com/merchant-center-europe/sample-data/goodstore/Sunnai_Glass_Bowl-1.1.jpeg',
|
|
12
|
+
sku: 'SGB-01',
|
|
13
|
+
|
|
14
|
+
},
|
|
15
|
+
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
describe('Commercetools Product Provider', () => {
|
|
@@ -48,12 +51,26 @@ describe('Commercetools Product Provider', () => {
|
|
|
48
51
|
}
|
|
49
52
|
});
|
|
50
53
|
|
|
54
|
+
it('should be able to get a product by sku', async () => {
|
|
55
|
+
const result = await provider.getBySKU( { sku: { key: testData.product.sku } }, reqCtx);
|
|
56
|
+
|
|
57
|
+
expect(result).toBeTruthy();
|
|
58
|
+
if (result) {
|
|
59
|
+
expect(result.meta.placeholder).toBe(false);
|
|
60
|
+
expect(result.identifier.key).toBe(testData.product.id);
|
|
61
|
+
expect(result.name).toBe(testData.product.name);
|
|
62
|
+
expect(result.image).toBe(testData.product.image);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
51
66
|
it('should return null for unknown slug', async () => {
|
|
52
67
|
const result = await provider.getBySlug( { slug: 'unknown-slug' }, reqCtx);
|
|
53
68
|
|
|
54
69
|
expect(result).toBeNull();
|
|
55
70
|
});
|
|
56
71
|
|
|
72
|
+
|
|
73
|
+
|
|
57
74
|
it('should return a placeholder product for unknown id', async () => {
|
|
58
75
|
const result = await provider.getById( { id: 'unknown-id' }, reqCtx);
|
|
59
76
|
|
|
@@ -6,9 +6,9 @@ import {
|
|
|
6
6
|
ProfileSchema,
|
|
7
7
|
createInitialRequestContext,
|
|
8
8
|
} from '@reactionary/core';
|
|
9
|
-
import { getCommercetoolsTestConfiguration } from './test-utils';
|
|
10
|
-
import { CommercetoolsProfileProvider } from '../providers/profile.provider';
|
|
11
|
-
import { CommercetoolsIdentityProvider } from '../providers/identity.provider';
|
|
9
|
+
import { getCommercetoolsTestConfiguration } from './test-utils.js';
|
|
10
|
+
import { CommercetoolsProfileProvider } from '../providers/profile.provider.js';
|
|
11
|
+
import { CommercetoolsIdentityProvider } from '../providers/identity.provider.js';
|
|
12
12
|
|
|
13
13
|
describe('Commercetools Profile Provider', () => {
|
|
14
14
|
let provider: CommercetoolsProfileProvider;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import 'dotenv/config';
|
|
2
2
|
import type { RequestContext} from '@reactionary/core';
|
|
3
3
|
import { NoOpCache, SearchResultSchema, createInitialRequestContext } from '@reactionary/core';
|
|
4
|
-
import { CommercetoolsSearchProvider } from '../providers/search.provider';
|
|
5
|
-
import { getCommercetoolsTestConfiguration } from './test-utils';
|
|
4
|
+
import { CommercetoolsSearchProvider } from '../providers/search.provider.js';
|
|
5
|
+
import { getCommercetoolsTestConfiguration } from './test-utils.js';
|
|
6
6
|
|
|
7
7
|
const testData = {
|
|
8
8
|
searchTerm: 'bowl'
|
|
@@ -5,8 +5,8 @@ import {
|
|
|
5
5
|
StoreSchema,
|
|
6
6
|
createInitialRequestContext,
|
|
7
7
|
} from '@reactionary/core';
|
|
8
|
-
import { getCommercetoolsTestConfiguration } from './test-utils';
|
|
9
|
-
import { CommercetoolsStoreProvider } from '../providers/store.provider';
|
|
8
|
+
import { getCommercetoolsTestConfiguration } from './test-utils.js';
|
|
9
|
+
import { CommercetoolsStoreProvider } from '../providers/store.provider.js';
|
|
10
10
|
|
|
11
11
|
describe('Commercetools Store Provider', () => {
|
|
12
12
|
let provider: CommercetoolsStoreProvider;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { PaymentMethodSchema } from '@reactionary/core';
|
|
2
|
+
import { PaymentMethodIdentifierSchema } from '@reactionary/core';
|
|
3
|
+
|
|
1
4
|
export function getCommercetoolsTestConfiguration() {
|
|
2
5
|
return {
|
|
3
6
|
apiUrl: process.env['CTP_API_URL'] || '',
|
|
@@ -6,6 +9,17 @@ export function getCommercetoolsTestConfiguration() {
|
|
|
6
9
|
clientSecret: process.env['CTP_CLIENT_SECRET'] || '',
|
|
7
10
|
projectKey: process.env['CTP_PROJECT_KEY'] || '',
|
|
8
11
|
scopes: (process.env['CTP_SCOPES'] || '').split(',').map(x => x.trim()).filter(x => x && x.length > 0),
|
|
12
|
+
|
|
13
|
+
paymentMethods: [
|
|
14
|
+
PaymentMethodSchema.parse({
|
|
15
|
+
identifier: PaymentMethodIdentifierSchema.parse({
|
|
16
|
+
paymentProvider: 'stripe',
|
|
17
|
+
method: 'stripe',
|
|
18
|
+
name: 'Stripe',
|
|
19
|
+
}),
|
|
20
|
+
description: 'Stripe payment gateway'
|
|
21
|
+
})
|
|
22
|
+
]
|
|
9
23
|
}
|
|
10
24
|
}
|
|
11
25
|
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": "./tsconfig.json",
|
|
3
3
|
"compilerOptions": {
|
|
4
|
-
"outDir": "../../dist/out-tsc",
|
|
5
4
|
"module": "commonjs",
|
|
6
|
-
"moduleResolution": "
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"verbatimModuleSyntax": false,
|
|
7
|
+
"outDir": "../../dist/out-tsc",
|
|
7
8
|
"types": ["jest", "node"]
|
|
8
9
|
},
|
|
9
10
|
"include": [
|
|
10
|
-
"jest.config.
|
|
11
|
+
"jest.config.cjs",
|
|
11
12
|
"src/**/*.test.ts",
|
|
12
13
|
"src/**/*.spec.ts",
|
|
13
14
|
"src/**/*.d.ts"
|
|
@@ -18,17 +18,17 @@ import {
|
|
|
18
18
|
StoreSchema,
|
|
19
19
|
PriceSchema,
|
|
20
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';
|
|
21
|
+
import { FakeProductProvider } from '../providers/product.provider.js';
|
|
22
|
+
import { FakeSearchProvider } from '../providers/search.provider.js';
|
|
23
|
+
import type { FakeConfiguration } from '../schema/configuration.schema.js';
|
|
24
|
+
import type { FakeCapabilities } from '../schema/capabilities.schema.js';
|
|
25
|
+
import { FakeCategoryProvider } from '../providers/category.provider.js';
|
|
26
26
|
import {
|
|
27
27
|
FakeCartProvider,
|
|
28
28
|
FakeInventoryProvider,
|
|
29
29
|
FakePriceProvider,
|
|
30
30
|
FakeStoreProvider,
|
|
31
|
-
} from '../providers';
|
|
31
|
+
} from '../providers/index.js';
|
|
32
32
|
|
|
33
33
|
type FakeClient<T extends FakeCapabilities> = (T['cart'] extends true
|
|
34
34
|
? { cart: CartProvider }
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './core/initialize';
|
|
1
|
+
export * from './core/initialize.js';
|
|
2
2
|
|
|
3
|
-
export * from './providers/'
|
|
4
|
-
export * from './schema/capabilities.schema';
|
|
5
|
-
export * from './schema/configuration.schema';
|
|
3
|
+
export * from './providers/index.js'
|
|
4
|
+
export * from './schema/capabilities.schema.js';
|
|
5
|
+
export * from './schema/configuration.schema.js';
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
AnalyticsProvider
|
|
6
6
|
} from '@reactionary/core';
|
|
7
7
|
import type z from 'zod';
|
|
8
|
-
import type { FakeConfiguration } from '../schema/configuration.schema';
|
|
8
|
+
import type { FakeConfiguration } from '../schema/configuration.schema.js';
|
|
9
9
|
|
|
10
10
|
export class FakeAnalyticsProvider<
|
|
11
11
|
T extends BaseModel = BaseModel
|
|
@@ -4,7 +4,7 @@ import type {
|
|
|
4
4
|
CartMutationItemAdd,
|
|
5
5
|
CartMutationItemRemove,
|
|
6
6
|
CartMutationItemQuantityChange,
|
|
7
|
-
|
|
7
|
+
RequestContext,
|
|
8
8
|
Cache,
|
|
9
9
|
CartIdentifier,
|
|
10
10
|
CartMutationApplyCoupon,
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
CartProvider
|
|
20
20
|
} from '@reactionary/core';
|
|
21
21
|
import type z from 'zod';
|
|
22
|
-
import type { FakeConfiguration } from '../schema/configuration.schema';
|
|
22
|
+
import type { FakeConfiguration } from '../schema/configuration.schema.js';
|
|
23
23
|
import { Faker, en, base } from '@faker-js/faker';
|
|
24
24
|
|
|
25
25
|
export class FakeCartProvider<
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Category, CategoryQueryById, CategoryQueryBySlug, CategoryQueryForBreadcrumb, CategoryQueryForChildCategories, CategoryQueryForTopCategories, RequestContext} from "@reactionary/core";
|
|
2
|
-
import { CategoryProvider,
|
|
3
|
-
import type { FakeConfiguration } from "../schema/configuration.schema";
|
|
2
|
+
import { CategoryProvider, Reactionary } from "@reactionary/core";
|
|
3
|
+
import type { FakeConfiguration } from "../schema/configuration.schema.js";
|
|
4
4
|
import type { Cache as ReactionaryCache } from "@reactionary/core";
|
|
5
5
|
import type z from "zod";
|
|
6
6
|
import { Faker, en, base } from '@faker-js/faker';
|
|
@@ -71,9 +71,10 @@ export class FakeCategoryProvider<
|
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
@Reactionary({})
|
|
74
75
|
public override async getById(payload: CategoryQueryById, reqCtx: RequestContext): Promise<T> {
|
|
75
76
|
const category = this.allCategories.get(payload.id.key);
|
|
76
|
-
|
|
77
|
+
|
|
77
78
|
if(!category) {
|
|
78
79
|
const dummyCategory = this.newModel();
|
|
79
80
|
dummyCategory.meta.placeholder = true;
|
|
@@ -82,6 +83,8 @@ export class FakeCategoryProvider<
|
|
|
82
83
|
}
|
|
83
84
|
return category;
|
|
84
85
|
}
|
|
86
|
+
|
|
87
|
+
@Reactionary({})
|
|
85
88
|
public override getBySlug(payload: CategoryQueryBySlug, reqCtx: RequestContext): Promise<T | null> {
|
|
86
89
|
for(const p of this.allCategories.values()) {
|
|
87
90
|
if(p.slug === payload.slug) {
|
|
@@ -91,6 +94,7 @@ export class FakeCategoryProvider<
|
|
|
91
94
|
return Promise.resolve(null);
|
|
92
95
|
}
|
|
93
96
|
|
|
97
|
+
@Reactionary({})
|
|
94
98
|
public override getBreadcrumbPathToCategory(payload: CategoryQueryForBreadcrumb, reqCtx: RequestContext): Promise<T[]> {
|
|
95
99
|
const path = new Array<T>();
|
|
96
100
|
let category = this.allCategories.get(payload.id.key);
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
type IdentityMutationRegister,
|
|
10
10
|
} from '@reactionary/core';
|
|
11
11
|
import type z from 'zod';
|
|
12
|
-
import type { FakeConfiguration } from '../schema/configuration.schema';
|
|
12
|
+
import type { FakeConfiguration } from '../schema/configuration.schema.js';
|
|
13
13
|
import { base, en, Faker } from '@faker-js/faker';
|
|
14
14
|
|
|
15
15
|
export class FakeIdentityProvider<
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export * from './analytics.provider';
|
|
2
|
-
export * from './cart.provider';
|
|
3
|
-
export * from './category.provider';
|
|
4
|
-
export * from './identity.provider';
|
|
5
|
-
export * from './inventory.provider';
|
|
6
|
-
export * from './price.provider';
|
|
7
|
-
export * from './product.provider';
|
|
8
|
-
export * from './search.provider';
|
|
9
|
-
export * from './store.provider';
|
|
1
|
+
export * from './analytics.provider.js';
|
|
2
|
+
export * from './cart.provider.js';
|
|
3
|
+
export * from './category.provider.js';
|
|
4
|
+
export * from './identity.provider.js';
|
|
5
|
+
export * from './inventory.provider.js';
|
|
6
|
+
export * from './price.provider.js';
|
|
7
|
+
export * from './product.provider.js';
|
|
8
|
+
export * from './search.provider.js';
|
|
9
|
+
export * from './store.provider.js';
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
InventoryProvider
|
|
9
9
|
} from '@reactionary/core';
|
|
10
10
|
import type z from 'zod';
|
|
11
|
-
import type { FakeConfiguration } from '../schema/configuration.schema';
|
|
11
|
+
import type { FakeConfiguration } from '../schema/configuration.schema.js';
|
|
12
12
|
import { base, en, Faker } from '@faker-js/faker';
|
|
13
13
|
|
|
14
14
|
export class FakeInventoryProvider<
|