@reactionary/source 0.0.52 → 0.2.16
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/.env-template +19 -0
- package/.github/workflows/pull-request.yml +3 -1
- package/.github/workflows/release.yml +9 -0
- package/.vscode/extensions.json +0 -2
- package/LICENSE +21 -0
- package/README.md +175 -23
- package/core/package.json +6 -3
- package/core/src/cache/cache.interface.ts +1 -0
- package/core/src/cache/index.ts +4 -0
- package/core/src/cache/memory-cache.ts +30 -2
- package/core/src/cache/noop-cache.ts +15 -1
- package/core/src/cache/redis-cache.ts +20 -0
- package/core/src/client/client-builder.ts +71 -54
- package/core/src/client/client.ts +9 -47
- package/core/src/client/index.ts +2 -0
- package/core/src/decorators/index.ts +1 -0
- package/core/src/decorators/reactionary.decorator.ts +203 -34
- package/core/src/index.ts +6 -19
- package/core/src/initialization.ts +1 -18
- package/core/src/metrics/metrics.ts +67 -0
- package/core/src/providers/analytics.provider.ts +1 -6
- package/core/src/providers/base.provider.ts +5 -69
- package/core/src/providers/cart.provider.ts +15 -55
- package/core/src/providers/category.provider.ts +7 -11
- package/core/src/providers/checkout.provider.ts +17 -15
- package/core/src/providers/identity.provider.ts +6 -8
- package/core/src/providers/index.ts +2 -1
- package/core/src/providers/inventory.provider.ts +15 -5
- package/core/src/providers/order-search.provider.ts +29 -0
- package/core/src/providers/order.provider.ts +47 -15
- package/core/src/providers/price.provider.ts +30 -36
- package/core/src/providers/product-search.provider.ts +61 -0
- package/core/src/providers/product.provider.ts +71 -12
- package/core/src/providers/profile.provider.ts +74 -14
- package/core/src/providers/store.provider.ts +3 -5
- package/core/src/schemas/capabilities.schema.ts +10 -3
- package/core/src/schemas/errors/generic.error.ts +9 -0
- package/core/src/schemas/errors/index.ts +4 -0
- package/core/src/schemas/errors/invalid-input.error.ts +9 -0
- package/core/src/schemas/errors/invalid-output.error.ts +9 -0
- package/core/src/schemas/errors/not-found.error.ts +9 -0
- package/core/src/schemas/index.ts +7 -0
- package/core/src/schemas/models/analytics.model.ts +2 -1
- package/core/src/schemas/models/base.model.ts +6 -24
- package/core/src/schemas/models/cart.model.ts +5 -8
- package/core/src/schemas/models/category.model.ts +4 -9
- package/core/src/schemas/models/checkout.model.ts +6 -7
- package/core/src/schemas/models/cost.model.ts +4 -3
- package/core/src/schemas/models/currency.model.ts +2 -1
- package/core/src/schemas/models/identifiers.model.ts +106 -62
- package/core/src/schemas/models/identity.model.ts +10 -19
- package/core/src/schemas/models/index.ts +2 -1
- package/core/src/schemas/models/inventory.model.ts +8 -5
- package/core/src/schemas/models/order-search.model.ts +28 -0
- package/core/src/schemas/models/order.model.ts +20 -26
- package/core/src/schemas/models/payment.model.ts +14 -17
- package/core/src/schemas/models/price.model.ts +11 -11
- package/core/src/schemas/models/product-search.model.ts +42 -0
- package/core/src/schemas/models/product.model.ts +64 -22
- package/core/src/schemas/models/profile.model.ts +19 -22
- package/core/src/schemas/models/shipping-method.model.ts +24 -29
- package/core/src/schemas/models/store.model.ts +9 -5
- package/core/src/schemas/mutations/analytics.mutation.ts +8 -7
- package/core/src/schemas/mutations/base.mutation.ts +2 -1
- package/core/src/schemas/mutations/cart.mutation.ts +33 -33
- package/core/src/schemas/mutations/checkout.mutation.ts +23 -30
- package/core/src/schemas/mutations/identity.mutation.ts +4 -3
- package/core/src/schemas/mutations/profile.mutation.ts +38 -3
- package/core/src/schemas/queries/base.query.ts +2 -1
- package/core/src/schemas/queries/cart.query.ts +3 -3
- package/core/src/schemas/queries/category.query.ts +18 -18
- package/core/src/schemas/queries/checkout.query.ts +7 -9
- package/core/src/schemas/queries/identity.query.ts +2 -1
- package/core/src/schemas/queries/index.ts +2 -1
- package/core/src/schemas/queries/inventory.query.ts +5 -5
- package/core/src/schemas/queries/order-search.query.ts +10 -0
- package/core/src/schemas/queries/order.query.ts +3 -2
- package/core/src/schemas/queries/price.query.ts +10 -4
- package/core/src/schemas/queries/product-search.query.ts +16 -0
- package/core/src/schemas/queries/product.query.ts +13 -6
- package/core/src/schemas/queries/profile.query.ts +5 -2
- package/core/src/schemas/queries/store.query.ts +6 -5
- package/core/src/schemas/result.ts +107 -0
- package/core/src/schemas/session.schema.ts +4 -4
- package/core/src/test/reactionary.decorator.spec.ts +249 -0
- package/core/src/zod-utils.ts +19 -0
- package/core/tsconfig.json +1 -1
- package/core/tsconfig.spec.json +2 -26
- package/core/vitest.config.ts +14 -0
- package/documentation/1-purpose.md +114 -0
- package/documentation/2-getting-started.md +229 -0
- package/documentation/3-querying-and-changing-data.md +74 -0
- package/documentation/4-product-data.md +107 -0
- package/documentation/5-cart-and-checkout.md +211 -0
- package/documentation/6-product-search.md +143 -0
- package/documentation/7-marketing.md +3 -0
- package/eslint.config.mjs +1 -0
- package/examples/node/eslint.config.mjs +1 -4
- package/examples/node/package.json +10 -3
- package/examples/node/project.json +4 -1
- package/examples/node/src/basic/basic-node-provider-model-extension.spec.ts +22 -23
- package/examples/node/src/basic/basic-node-provider-query-extension.spec.ts +15 -11
- package/examples/node/src/basic/basic-node-setup.spec.ts +44 -28
- package/examples/node/src/basic/client-creation.spec.ts +53 -0
- package/examples/node/src/capabilities/cart.spec.ts +255 -0
- package/examples/node/src/capabilities/category.spec.ts +193 -0
- package/examples/node/src/capabilities/checkout.spec.ts +341 -0
- package/examples/node/src/capabilities/identity.spec.ts +93 -0
- package/examples/node/src/capabilities/inventory.spec.ts +66 -0
- package/examples/node/src/capabilities/order-search.spec.ts +265 -0
- package/examples/node/src/capabilities/order.spec.ts +91 -0
- package/examples/node/src/capabilities/price.spec.ts +51 -0
- package/examples/node/src/capabilities/product-search.spec.ts +293 -0
- package/examples/node/src/capabilities/product.spec.ts +122 -0
- package/examples/node/src/capabilities/profile.spec.ts +316 -0
- package/examples/node/src/capabilities/store.spec.ts +26 -0
- package/examples/node/src/utils.ts +147 -0
- package/examples/node/tsconfig.json +9 -12
- package/examples/node/tsconfig.lib.json +1 -2
- package/examples/node/tsconfig.spec.json +2 -14
- package/examples/node/vitest.config.ts +14 -0
- package/migrations.json +22 -5
- package/nx.json +8 -47
- package/package.json +24 -96
- package/providers/algolia/README.md +39 -2
- package/providers/algolia/package.json +2 -1
- package/providers/algolia/src/core/initialize.ts +7 -14
- package/providers/algolia/src/index.ts +2 -4
- package/providers/algolia/src/providers/index.ts +1 -0
- package/providers/algolia/src/providers/product-search.provider.ts +241 -0
- package/providers/algolia/src/schema/capabilities.schema.ts +2 -3
- package/providers/algolia/src/schema/index.ts +3 -0
- package/providers/algolia/src/schema/search.schema.ts +8 -8
- package/providers/algolia/tsconfig.json +1 -1
- package/providers/algolia/tsconfig.lib.json +1 -1
- package/providers/algolia/tsconfig.spec.json +2 -14
- package/providers/algolia/vitest.config.ts +14 -0
- package/providers/commercetools/README.md +30 -3
- package/providers/commercetools/package.json +2 -1
- package/providers/commercetools/src/core/client.ts +178 -99
- package/providers/commercetools/src/core/initialize.ts +130 -74
- package/providers/commercetools/src/core/token-cache.ts +45 -0
- package/providers/commercetools/src/index.ts +3 -2
- package/providers/commercetools/src/providers/cart.provider.ts +281 -341
- package/providers/commercetools/src/providers/category.provider.ts +223 -138
- package/providers/commercetools/src/providers/checkout.provider.ts +631 -449
- package/providers/commercetools/src/providers/identity.provider.ts +50 -29
- package/providers/commercetools/src/providers/index.ts +2 -2
- package/providers/commercetools/src/providers/inventory.provider.ts +76 -74
- package/providers/commercetools/src/providers/order-search.provider.ts +220 -0
- package/providers/commercetools/src/providers/order.provider.ts +96 -61
- package/providers/commercetools/src/providers/price.provider.ts +147 -117
- package/providers/commercetools/src/providers/product-search.provider.ts +528 -0
- package/providers/commercetools/src/providers/product.provider.ts +249 -74
- package/providers/commercetools/src/providers/profile.provider.ts +445 -28
- package/providers/commercetools/src/providers/store.provider.ts +54 -40
- package/providers/commercetools/src/schema/capabilities.schema.ts +3 -1
- package/providers/commercetools/src/schema/commercetools.schema.ts +17 -3
- package/providers/commercetools/src/schema/configuration.schema.ts +1 -0
- package/providers/commercetools/src/schema/session.schema.ts +7 -0
- package/providers/commercetools/src/test/caching.spec.ts +82 -0
- package/providers/commercetools/src/test/identity.spec.ts +109 -0
- package/providers/commercetools/src/test/test-utils.ts +21 -19
- package/providers/commercetools/tsconfig.json +1 -1
- package/providers/commercetools/tsconfig.lib.json +1 -1
- package/providers/commercetools/tsconfig.spec.json +2 -14
- package/providers/commercetools/vitest.config.ts +15 -0
- package/providers/fake/README.md +20 -4
- package/providers/fake/package.json +2 -1
- package/providers/fake/src/core/initialize.ts +47 -49
- package/providers/fake/src/providers/analytics.provider.ts +5 -7
- package/providers/fake/src/providers/cart.provider.ts +163 -92
- package/providers/fake/src/providers/category.provider.ts +78 -50
- package/providers/fake/src/providers/checkout.provider.ts +254 -0
- package/providers/fake/src/providers/identity.provider.ts +57 -65
- package/providers/fake/src/providers/index.ts +6 -2
- package/providers/fake/src/providers/inventory.provider.ts +40 -36
- package/providers/fake/src/providers/order-search.provider.ts +78 -0
- package/providers/fake/src/providers/order.provider.ts +106 -0
- package/providers/fake/src/providers/price.provider.ts +93 -41
- package/providers/fake/src/providers/product-search.provider.ts +206 -0
- package/providers/fake/src/providers/product.provider.ts +56 -41
- package/providers/fake/src/providers/profile.provider.ts +147 -0
- package/providers/fake/src/providers/store.provider.ts +30 -20
- package/providers/fake/src/schema/capabilities.schema.ts +5 -1
- package/providers/fake/src/test/cart.provider.spec.ts +59 -80
- package/providers/fake/src/test/category.provider.spec.ts +145 -87
- package/providers/fake/src/test/checkout.provider.spec.ts +222 -0
- package/providers/fake/src/test/order-search.provider.spec.ts +50 -0
- package/providers/fake/src/test/order.provider.spec.ts +44 -0
- package/providers/fake/src/test/price.provider.spec.ts +50 -45
- package/providers/fake/src/test/product.provider.spec.ts +15 -7
- package/providers/fake/src/test/profile.provider.spec.ts +167 -0
- package/providers/fake/tsconfig.json +1 -1
- package/providers/fake/tsconfig.lib.json +1 -1
- package/providers/fake/tsconfig.spec.json +2 -12
- package/providers/fake/vitest.config.ts +14 -0
- package/providers/medusa/README.md +30 -0
- package/providers/medusa/TESTING.md +98 -0
- package/providers/medusa/eslint.config.mjs +19 -0
- package/providers/medusa/package.json +22 -0
- package/providers/medusa/project.json +34 -0
- package/providers/medusa/src/core/client.ts +370 -0
- package/providers/medusa/src/core/initialize.ts +78 -0
- package/providers/medusa/src/index.ts +13 -0
- package/providers/medusa/src/providers/cart.provider.ts +575 -0
- package/providers/medusa/src/providers/category.provider.ts +247 -0
- package/providers/medusa/src/providers/checkout.provider.ts +636 -0
- package/providers/medusa/src/providers/identity.provider.ts +137 -0
- package/providers/medusa/src/providers/inventory.provider.ts +173 -0
- package/providers/medusa/src/providers/order-search.provider.ts +202 -0
- package/providers/medusa/src/providers/order.provider.ts +226 -0
- package/providers/medusa/src/providers/price.provider.ts +140 -0
- package/providers/medusa/src/providers/product-search.provider.ts +243 -0
- package/providers/medusa/src/providers/product.provider.ts +261 -0
- package/providers/medusa/src/providers/profile.provider.ts +392 -0
- package/providers/medusa/src/schema/capabilities.schema.ts +18 -0
- package/providers/medusa/src/schema/configuration.schema.ts +11 -0
- package/providers/medusa/src/schema/medusa.schema.ts +31 -0
- package/providers/medusa/src/test/cart.provider.spec.ts +240 -0
- package/providers/medusa/src/test/category.provider.spec.ts +231 -0
- package/providers/medusa/src/test/checkout.spec.ts +349 -0
- package/providers/medusa/src/test/identity.provider.spec.ts +122 -0
- package/providers/medusa/src/test/inventory.provider.spec.ts +88 -0
- package/providers/medusa/src/test/large-cart.provider.spec.ts +103 -0
- package/providers/medusa/src/test/price.provider.spec.ts +104 -0
- package/providers/medusa/src/test/product.provider.spec.ts +146 -0
- package/providers/medusa/src/test/search.provider.spec.ts +203 -0
- package/providers/medusa/src/test/test-utils.ts +13 -0
- package/providers/medusa/src/utils/medusa-helpers.ts +89 -0
- package/providers/medusa/tsconfig.json +21 -0
- package/providers/medusa/tsconfig.lib.json +9 -0
- package/providers/medusa/tsconfig.spec.json +4 -0
- package/providers/medusa/vitest.config.ts +15 -0
- package/providers/meilisearch/README.md +48 -0
- package/providers/meilisearch/eslint.config.mjs +22 -0
- package/providers/meilisearch/package.json +13 -0
- package/providers/meilisearch/project.json +34 -0
- package/providers/meilisearch/src/core/initialize.ts +21 -0
- package/providers/meilisearch/src/index.ts +6 -0
- package/providers/meilisearch/src/providers/index.ts +1 -0
- package/providers/meilisearch/src/providers/order-search.provider.ts +222 -0
- package/providers/meilisearch/src/providers/product-search.provider.ts +251 -0
- package/providers/meilisearch/src/schema/capabilities.schema.ts +10 -0
- package/providers/meilisearch/src/schema/configuration.schema.ts +11 -0
- package/providers/meilisearch/src/schema/index.ts +3 -0
- package/providers/meilisearch/src/schema/search.schema.ts +14 -0
- package/providers/meilisearch/tsconfig.json +24 -0
- package/providers/meilisearch/tsconfig.lib.json +10 -0
- package/providers/meilisearch/tsconfig.spec.json +4 -0
- package/providers/meilisearch/vitest.config.ts +14 -0
- package/providers/posthog/package.json +2 -1
- package/providers/posthog/tsconfig.json +1 -1
- package/tsconfig.base.json +5 -0
- package/vitest.config.ts +10 -0
- package/core/src/providers/search.provider.ts +0 -18
- package/core/src/schemas/models/search.model.ts +0 -36
- package/core/src/schemas/queries/search.query.ts +0 -9
- package/examples/next/.swcrc +0 -30
- package/examples/next/eslint.config.mjs +0 -21
- package/examples/next/index.d.ts +0 -6
- package/examples/next/next-env.d.ts +0 -5
- package/examples/next/next.config.js +0 -31
- package/examples/next/project.json +0 -9
- package/examples/next/public/.gitkeep +0 -0
- package/examples/next/public/favicon.ico +0 -0
- package/examples/next/src/app/global.css +0 -0
- package/examples/next/src/app/layout.tsx +0 -18
- package/examples/next/src/app/page.module.scss +0 -2
- package/examples/next/src/app/page.tsx +0 -47
- package/examples/next/src/instrumentation.ts +0 -9
- package/examples/next/tsconfig.json +0 -44
- package/examples/node/jest.config.ts +0 -10
- package/jest.config.ts +0 -6
- package/jest.preset.js +0 -3
- package/providers/algolia/jest.config.ts +0 -10
- package/providers/algolia/src/providers/product.provider.ts +0 -66
- package/providers/algolia/src/providers/search.provider.ts +0 -106
- package/providers/algolia/src/test/search.provider.spec.ts +0 -91
- package/providers/commercetools/jest.config.cjs +0 -10
- package/providers/commercetools/src/providers/search.provider.ts +0 -96
- package/providers/commercetools/src/test/cart.provider.spec.ts +0 -199
- package/providers/commercetools/src/test/category.provider.spec.ts +0 -168
- package/providers/commercetools/src/test/checkout.provider.spec.ts +0 -312
- package/providers/commercetools/src/test/identity.provider.spec.ts +0 -88
- package/providers/commercetools/src/test/inventory.provider.spec.ts +0 -41
- package/providers/commercetools/src/test/price.provider.spec.ts +0 -81
- package/providers/commercetools/src/test/product.provider.spec.ts +0 -80
- package/providers/commercetools/src/test/profile.provider.spec.ts +0 -49
- package/providers/commercetools/src/test/search.provider.spec.ts +0 -61
- package/providers/commercetools/src/test/store.provider.spec.ts +0 -37
- package/providers/fake/jest.config.cjs +0 -10
- package/providers/fake/src/providers/search.provider.ts +0 -132
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CheckoutProvider,
|
|
3
|
+
type Checkout,
|
|
4
|
+
type CheckoutMutationAddPaymentInstruction,
|
|
5
|
+
type CheckoutMutationFinalizeCheckout,
|
|
6
|
+
type CheckoutMutationInitiateCheckout,
|
|
7
|
+
type CheckoutMutationRemovePaymentInstruction,
|
|
8
|
+
type CheckoutMutationSetShippingAddress,
|
|
9
|
+
type CheckoutMutationSetShippingInstruction,
|
|
10
|
+
type CheckoutQueryById,
|
|
11
|
+
type CheckoutQueryForAvailablePaymentMethods,
|
|
12
|
+
type CheckoutQueryForAvailableShippingMethods,
|
|
13
|
+
type NotFoundError,
|
|
14
|
+
type PaymentMethod,
|
|
15
|
+
type RequestContext,
|
|
16
|
+
type Result,
|
|
17
|
+
type ShippingMethod,
|
|
18
|
+
type Cache,
|
|
19
|
+
Reactionary,
|
|
20
|
+
CheckoutMutationInitiateCheckoutSchema,
|
|
21
|
+
CheckoutSchema,
|
|
22
|
+
CheckoutQueryByIdSchema,
|
|
23
|
+
CheckoutMutationSetShippingAddressSchema,
|
|
24
|
+
CheckoutQueryForAvailableShippingMethodsSchema,
|
|
25
|
+
CheckoutQueryForAvailablePaymentMethodsSchema,
|
|
26
|
+
CheckoutMutationAddPaymentInstructionSchema,
|
|
27
|
+
CheckoutMutationRemovePaymentInstructionSchema,
|
|
28
|
+
CheckoutMutationSetShippingInstructionSchema,
|
|
29
|
+
CheckoutMutationFinalizeCheckoutSchema,
|
|
30
|
+
success,
|
|
31
|
+
type CheckoutIdentifier,
|
|
32
|
+
} from '@reactionary/core';
|
|
33
|
+
import type { FakeConfiguration } from '../schema/configuration.schema.js';
|
|
34
|
+
import { base, en, Faker } from '@faker-js/faker';
|
|
35
|
+
|
|
36
|
+
export class FakeCheckoutProvider extends CheckoutProvider {
|
|
37
|
+
protected config: FakeConfiguration;
|
|
38
|
+
protected generator: Faker;
|
|
39
|
+
|
|
40
|
+
constructor(
|
|
41
|
+
config: FakeConfiguration,
|
|
42
|
+
cache: Cache,
|
|
43
|
+
context: RequestContext
|
|
44
|
+
) {
|
|
45
|
+
super(cache, context);
|
|
46
|
+
|
|
47
|
+
this.config = config;
|
|
48
|
+
|
|
49
|
+
this.generator = new Faker({
|
|
50
|
+
locale: [en, base],
|
|
51
|
+
seed: config.seeds.product,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@Reactionary({
|
|
56
|
+
inputSchema: CheckoutMutationInitiateCheckoutSchema,
|
|
57
|
+
outputSchema: CheckoutSchema,
|
|
58
|
+
})
|
|
59
|
+
public override async initiateCheckoutForCart(
|
|
60
|
+
payload: CheckoutMutationInitiateCheckout
|
|
61
|
+
): Promise<Result<Checkout>> {
|
|
62
|
+
const checkout = this.composeBaseCheckout(payload.cart.identifier);
|
|
63
|
+
|
|
64
|
+
return success(checkout);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@Reactionary({
|
|
68
|
+
inputSchema: CheckoutQueryByIdSchema,
|
|
69
|
+
outputSchema: CheckoutSchema,
|
|
70
|
+
})
|
|
71
|
+
public override async getById(
|
|
72
|
+
payload: CheckoutQueryById
|
|
73
|
+
): Promise<Result<Checkout, NotFoundError>> {
|
|
74
|
+
const checkout = this.composeBaseCheckout(payload.identifier);
|
|
75
|
+
|
|
76
|
+
return success(checkout);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@Reactionary({
|
|
80
|
+
inputSchema: CheckoutMutationSetShippingAddressSchema,
|
|
81
|
+
outputSchema: CheckoutSchema,
|
|
82
|
+
})
|
|
83
|
+
public override async setShippingAddress(
|
|
84
|
+
payload: CheckoutMutationSetShippingAddress
|
|
85
|
+
): Promise<Result<Checkout>> {
|
|
86
|
+
const checkout = this.composeBaseCheckout(payload.checkout);
|
|
87
|
+
|
|
88
|
+
return success(checkout);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@Reactionary({
|
|
92
|
+
inputSchema: CheckoutQueryForAvailableShippingMethodsSchema,
|
|
93
|
+
outputSchema: CheckoutSchema,
|
|
94
|
+
})
|
|
95
|
+
public override async getAvailableShippingMethods(
|
|
96
|
+
payload: CheckoutQueryForAvailableShippingMethods
|
|
97
|
+
): Promise<Result<ShippingMethod[]>> {
|
|
98
|
+
const methods = [
|
|
99
|
+
{
|
|
100
|
+
name: 'Fake',
|
|
101
|
+
deliveryTime: '3 days',
|
|
102
|
+
description: 'A fake delivery by fake mail',
|
|
103
|
+
identifier: {
|
|
104
|
+
key: 'fake-001',
|
|
105
|
+
},
|
|
106
|
+
price: {
|
|
107
|
+
currency: 'USD',
|
|
108
|
+
value: 500,
|
|
109
|
+
},
|
|
110
|
+
carrier: 'Faker',
|
|
111
|
+
},
|
|
112
|
+
] satisfies Array<ShippingMethod>;
|
|
113
|
+
|
|
114
|
+
return success(methods);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
@Reactionary({
|
|
118
|
+
inputSchema: CheckoutQueryForAvailablePaymentMethodsSchema,
|
|
119
|
+
outputSchema: CheckoutSchema,
|
|
120
|
+
})
|
|
121
|
+
public override async getAvailablePaymentMethods(
|
|
122
|
+
payload: CheckoutQueryForAvailablePaymentMethods
|
|
123
|
+
): Promise<Result<PaymentMethod[]>> {
|
|
124
|
+
const methods = [
|
|
125
|
+
{
|
|
126
|
+
description: 'A fake payment method for paying at some point',
|
|
127
|
+
identifier: {
|
|
128
|
+
method: 'PayLater',
|
|
129
|
+
name: 'Pay Later',
|
|
130
|
+
paymentProcessor: 'Faker',
|
|
131
|
+
},
|
|
132
|
+
isPunchOut: false,
|
|
133
|
+
},
|
|
134
|
+
] satisfies Array<PaymentMethod>;
|
|
135
|
+
|
|
136
|
+
return success(methods);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
@Reactionary({
|
|
140
|
+
inputSchema: CheckoutMutationAddPaymentInstructionSchema,
|
|
141
|
+
outputSchema: CheckoutSchema,
|
|
142
|
+
})
|
|
143
|
+
public override async addPaymentInstruction(
|
|
144
|
+
payload: CheckoutMutationAddPaymentInstruction
|
|
145
|
+
): Promise<Result<Checkout>> {
|
|
146
|
+
const checkout = this.composeBaseCheckout(payload.checkout);
|
|
147
|
+
|
|
148
|
+
return success(checkout);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
@Reactionary({
|
|
152
|
+
inputSchema: CheckoutMutationRemovePaymentInstructionSchema,
|
|
153
|
+
outputSchema: CheckoutSchema,
|
|
154
|
+
})
|
|
155
|
+
public override async removePaymentInstruction(
|
|
156
|
+
payload: CheckoutMutationRemovePaymentInstruction
|
|
157
|
+
): Promise<Result<Checkout>> {
|
|
158
|
+
const checkout = this.composeBaseCheckout(payload.checkout);
|
|
159
|
+
|
|
160
|
+
return success(checkout);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
@Reactionary({
|
|
164
|
+
inputSchema: CheckoutMutationSetShippingInstructionSchema,
|
|
165
|
+
outputSchema: CheckoutSchema,
|
|
166
|
+
})
|
|
167
|
+
public override async setShippingInstruction(
|
|
168
|
+
payload: CheckoutMutationSetShippingInstruction
|
|
169
|
+
): Promise<Result<Checkout>> {
|
|
170
|
+
const checkout = this.composeBaseCheckout(payload.checkout);
|
|
171
|
+
|
|
172
|
+
return success(checkout);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
@Reactionary({
|
|
176
|
+
inputSchema: CheckoutMutationFinalizeCheckoutSchema,
|
|
177
|
+
outputSchema: CheckoutSchema,
|
|
178
|
+
})
|
|
179
|
+
public override async finalizeCheckout(
|
|
180
|
+
payload: CheckoutMutationFinalizeCheckout
|
|
181
|
+
): Promise<Result<Checkout>> {
|
|
182
|
+
const checkout = this.composeBaseCheckout(payload.checkout);
|
|
183
|
+
|
|
184
|
+
return success(checkout);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
protected composeBaseCheckout(identifier?: CheckoutIdentifier) {
|
|
188
|
+
const checkout = {
|
|
189
|
+
description: 'Fake Checkout',
|
|
190
|
+
identifier: identifier || {
|
|
191
|
+
key: this.generator.string.uuid(),
|
|
192
|
+
},
|
|
193
|
+
items: [],
|
|
194
|
+
name: 'Fake Checkout',
|
|
195
|
+
originalCartReference: {
|
|
196
|
+
key: this.generator.string.uuid(),
|
|
197
|
+
},
|
|
198
|
+
paymentInstructions: [],
|
|
199
|
+
price: {
|
|
200
|
+
grandTotal: {
|
|
201
|
+
currency: 'USD',
|
|
202
|
+
value: this.generator.number.float({
|
|
203
|
+
min: 100,
|
|
204
|
+
max: 10000,
|
|
205
|
+
multipleOf: 25
|
|
206
|
+
}),
|
|
207
|
+
},
|
|
208
|
+
totalDiscount: {
|
|
209
|
+
currency: 'USD',
|
|
210
|
+
value: this.generator.number.float({
|
|
211
|
+
min: 100,
|
|
212
|
+
max: 10000,
|
|
213
|
+
multipleOf: 25,
|
|
214
|
+
}),
|
|
215
|
+
},
|
|
216
|
+
totalProductPrice: {
|
|
217
|
+
currency: 'USD',
|
|
218
|
+
value: this.generator.number.float({
|
|
219
|
+
min: 100,
|
|
220
|
+
max: 10000,
|
|
221
|
+
multipleOf: 25
|
|
222
|
+
}),
|
|
223
|
+
},
|
|
224
|
+
totalShipping: {
|
|
225
|
+
currency: 'USD',
|
|
226
|
+
value: this.generator.number.float({
|
|
227
|
+
min: 100,
|
|
228
|
+
max: 10000,
|
|
229
|
+
multipleOf: 25
|
|
230
|
+
}),
|
|
231
|
+
},
|
|
232
|
+
totalSurcharge: {
|
|
233
|
+
currency: 'USD',
|
|
234
|
+
value: this.generator.number.float({
|
|
235
|
+
min: 100,
|
|
236
|
+
max: 10000,
|
|
237
|
+
multipleOf: 25
|
|
238
|
+
}),
|
|
239
|
+
},
|
|
240
|
+
totalTax: {
|
|
241
|
+
currency: 'USD',
|
|
242
|
+
value: this.generator.number.float({
|
|
243
|
+
min: 100,
|
|
244
|
+
max: 10000,
|
|
245
|
+
multipleOf: 25
|
|
246
|
+
}),
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
readyForFinalization: false,
|
|
250
|
+
} satisfies Checkout;
|
|
251
|
+
|
|
252
|
+
return checkout;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
@@ -7,104 +7,96 @@ import {
|
|
|
7
7
|
type Cache,
|
|
8
8
|
IdentityProvider,
|
|
9
9
|
type IdentityMutationRegister,
|
|
10
|
+
type AnonymousIdentity,
|
|
11
|
+
type RegisteredIdentity,
|
|
12
|
+
Reactionary,
|
|
13
|
+
IdentityMutationRegisterSchema,
|
|
14
|
+
IdentitySchema,
|
|
15
|
+
IdentityMutationLogoutSchema,
|
|
16
|
+
IdentityMutationLoginSchema,
|
|
17
|
+
IdentityQuerySelfSchema,
|
|
18
|
+
type Result,
|
|
19
|
+
success,
|
|
10
20
|
} from '@reactionary/core';
|
|
11
|
-
import type z from 'zod';
|
|
12
21
|
import type { FakeConfiguration } from '../schema/configuration.schema.js';
|
|
13
22
|
import { base, en, Faker } from '@faker-js/faker';
|
|
14
23
|
|
|
15
|
-
export class FakeIdentityProvider
|
|
16
|
-
T extends Identity = Identity
|
|
17
|
-
> extends IdentityProvider<T> {
|
|
24
|
+
export class FakeIdentityProvider extends IdentityProvider {
|
|
18
25
|
protected config: FakeConfiguration;
|
|
19
|
-
private currentIdentity:
|
|
26
|
+
private currentIdentity: Identity | null = null;
|
|
20
27
|
|
|
21
|
-
constructor(
|
|
22
|
-
|
|
28
|
+
constructor(
|
|
29
|
+
config: FakeConfiguration,
|
|
30
|
+
cache: Cache,
|
|
31
|
+
context: RequestContext
|
|
32
|
+
) {
|
|
33
|
+
super(cache, context);
|
|
23
34
|
|
|
24
35
|
this.config = config;
|
|
25
36
|
}
|
|
26
37
|
|
|
38
|
+
@Reactionary({
|
|
39
|
+
inputSchema: IdentityQuerySelfSchema,
|
|
40
|
+
outputSchema: IdentitySchema
|
|
41
|
+
})
|
|
27
42
|
public override async getSelf(
|
|
28
|
-
_payload: IdentityQuerySelf
|
|
29
|
-
|
|
30
|
-
): Promise<T> {
|
|
43
|
+
_payload: IdentityQuerySelf
|
|
44
|
+
): Promise<Result<Identity>> {
|
|
31
45
|
if (!this.currentIdentity) {
|
|
32
|
-
const model =
|
|
33
|
-
Object.assign(model, {
|
|
34
|
-
id: 'anonymous',
|
|
46
|
+
const model = {
|
|
35
47
|
type: 'Anonymous',
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
cache: {
|
|
40
|
-
hit: false,
|
|
41
|
-
key: 'anonymous',
|
|
42
|
-
},
|
|
43
|
-
placeholder: false,
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
this.currentIdentity = this.assert(model);
|
|
48
|
+
} satisfies AnonymousIdentity;
|
|
49
|
+
|
|
50
|
+
this.currentIdentity = model;
|
|
47
51
|
}
|
|
48
52
|
|
|
49
|
-
return this.currentIdentity;
|
|
53
|
+
return success(this.currentIdentity);
|
|
50
54
|
}
|
|
51
55
|
|
|
56
|
+
@Reactionary({
|
|
57
|
+
inputSchema: IdentityMutationLoginSchema,
|
|
58
|
+
outputSchema: IdentitySchema
|
|
59
|
+
})
|
|
52
60
|
public override async login(
|
|
53
|
-
payload: IdentityMutationLogin
|
|
54
|
-
|
|
55
|
-
): Promise<T> {
|
|
61
|
+
payload: IdentityMutationLogin
|
|
62
|
+
): Promise<Result<Identity>> {
|
|
56
63
|
const generator = new Faker({
|
|
57
64
|
seed: 42,
|
|
58
65
|
locale: [en, base],
|
|
59
66
|
});
|
|
60
67
|
|
|
61
|
-
const model =
|
|
62
|
-
Object.assign(model, {
|
|
63
|
-
id: generator.string.uuid(),
|
|
68
|
+
const model = {
|
|
64
69
|
type: 'Registered',
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
expiry: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000), // 7 days from now
|
|
68
|
-
meta: {
|
|
69
|
-
cache: {
|
|
70
|
-
hit: false,
|
|
71
|
-
key: payload.username,
|
|
72
|
-
},
|
|
73
|
-
placeholder: false,
|
|
70
|
+
id: {
|
|
71
|
+
userId: generator.string.alphanumeric(32),
|
|
74
72
|
},
|
|
75
|
-
}
|
|
73
|
+
} satisfies RegisteredIdentity;
|
|
74
|
+
|
|
75
|
+
this.currentIdentity = model;
|
|
76
76
|
|
|
77
|
-
this.currentIdentity
|
|
78
|
-
return this.currentIdentity;
|
|
77
|
+
return success(this.currentIdentity);
|
|
79
78
|
}
|
|
80
79
|
|
|
80
|
+
@Reactionary({
|
|
81
|
+
inputSchema: IdentityMutationLogoutSchema,
|
|
82
|
+
outputSchema: IdentitySchema
|
|
83
|
+
})
|
|
81
84
|
public override async logout(
|
|
82
|
-
_payload: IdentityMutationLogout
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const model = this.newModel();
|
|
86
|
-
Object.assign(model, {
|
|
87
|
-
id: 'anonymous',
|
|
85
|
+
_payload: IdentityMutationLogout
|
|
86
|
+
): Promise<Result<Identity>> {
|
|
87
|
+
const model = {
|
|
88
88
|
type: 'Anonymous',
|
|
89
|
-
|
|
90
|
-
expiry: new Date(Date.now() + 24 * 60 * 60 * 1000), // 24 hours from now
|
|
91
|
-
meta: {
|
|
92
|
-
cache: {
|
|
93
|
-
hit: false,
|
|
94
|
-
key: 'anonymous',
|
|
95
|
-
},
|
|
96
|
-
placeholder: false,
|
|
97
|
-
},
|
|
98
|
-
});
|
|
89
|
+
} satisfies AnonymousIdentity;
|
|
99
90
|
|
|
100
|
-
this.currentIdentity =
|
|
101
|
-
return this.currentIdentity;
|
|
91
|
+
this.currentIdentity = model;
|
|
92
|
+
return success(this.currentIdentity);
|
|
102
93
|
}
|
|
103
94
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
)
|
|
95
|
+
@Reactionary({
|
|
96
|
+
inputSchema: IdentityMutationRegisterSchema,
|
|
97
|
+
outputSchema: IdentitySchema
|
|
98
|
+
})
|
|
99
|
+
public override register(payload: IdentityMutationRegister): Promise<Result<Identity>> {
|
|
108
100
|
throw new Error('Method not implemented.');
|
|
109
101
|
}
|
|
110
102
|
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
export * from './analytics.provider.js';
|
|
2
2
|
export * from './cart.provider.js';
|
|
3
3
|
export * from './category.provider.js';
|
|
4
|
+
export * from './checkout.provider.js';
|
|
4
5
|
export * from './identity.provider.js';
|
|
5
6
|
export * from './inventory.provider.js';
|
|
7
|
+
export * from './order-search.provider.js';
|
|
8
|
+
export * from './order.provider.js';
|
|
6
9
|
export * from './price.provider.js';
|
|
7
10
|
export * from './product.provider.js';
|
|
8
|
-
export * from './search.provider.js';
|
|
9
|
-
export * from './
|
|
11
|
+
export * from './product-search.provider.js';
|
|
12
|
+
export * from './profile.provider.js';
|
|
13
|
+
export * from './store.provider.js';
|
|
@@ -1,36 +1,46 @@
|
|
|
1
|
+
import { base, en, Faker } from '@faker-js/faker';
|
|
1
2
|
import type {
|
|
3
|
+
Cache,
|
|
2
4
|
Inventory,
|
|
5
|
+
InventoryIdentifier,
|
|
6
|
+
InventoryQueryBySKU,
|
|
7
|
+
InventoryStatus,
|
|
8
|
+
NotFoundError,
|
|
3
9
|
RequestContext,
|
|
4
|
-
|
|
5
|
-
InventoryQueryBySKU
|
|
10
|
+
Result,
|
|
6
11
|
} from '@reactionary/core';
|
|
7
12
|
import {
|
|
8
|
-
InventoryProvider
|
|
13
|
+
InventoryProvider,
|
|
14
|
+
InventoryQueryBySKUSchema,
|
|
15
|
+
InventorySchema,
|
|
16
|
+
Reactionary,
|
|
17
|
+
success,
|
|
9
18
|
} from '@reactionary/core';
|
|
10
|
-
import type z from 'zod';
|
|
11
19
|
import type { FakeConfiguration } from '../schema/configuration.schema.js';
|
|
12
|
-
import { base, en, Faker } from '@faker-js/faker';
|
|
13
20
|
|
|
14
|
-
export class FakeInventoryProvider
|
|
15
|
-
T extends Inventory = Inventory
|
|
16
|
-
> extends InventoryProvider<T> {
|
|
21
|
+
export class FakeInventoryProvider extends InventoryProvider {
|
|
17
22
|
protected config: FakeConfiguration;
|
|
18
23
|
|
|
19
|
-
constructor(
|
|
20
|
-
|
|
24
|
+
constructor(
|
|
25
|
+
config: FakeConfiguration,
|
|
26
|
+
cache: Cache,
|
|
27
|
+
context: RequestContext
|
|
28
|
+
) {
|
|
29
|
+
super(cache, context);
|
|
21
30
|
|
|
22
31
|
this.config = config;
|
|
23
32
|
}
|
|
24
33
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
)
|
|
34
|
+
@Reactionary({
|
|
35
|
+
inputSchema: InventoryQueryBySKUSchema,
|
|
36
|
+
outputSchema: InventorySchema
|
|
37
|
+
})
|
|
38
|
+
public override async getBySKU(payload: InventoryQueryBySKU): Promise<Result<Inventory, NotFoundError>> {
|
|
29
39
|
// Generate a simple hash from the SKU string for seeding
|
|
30
40
|
let hash = 0;
|
|
31
|
-
const skuString = payload.sku
|
|
41
|
+
const skuString = payload.variant.sku;
|
|
32
42
|
for (let i = 0; i < skuString.length; i++) {
|
|
33
|
-
hash = (
|
|
43
|
+
hash = (hash << 5) - hash + skuString.charCodeAt(i);
|
|
34
44
|
hash = hash & hash; // Convert to 32bit integer
|
|
35
45
|
}
|
|
36
46
|
|
|
@@ -39,30 +49,24 @@ export class FakeInventoryProvider<
|
|
|
39
49
|
locale: [en, base],
|
|
40
50
|
});
|
|
41
51
|
|
|
42
|
-
const
|
|
52
|
+
const identifier = {
|
|
53
|
+
variant: payload.variant,
|
|
54
|
+
fulfillmentCenter: payload.fulfilmentCenter,
|
|
55
|
+
} satisfies InventoryIdentifier;
|
|
43
56
|
|
|
44
|
-
|
|
45
|
-
sku: payload.sku,
|
|
46
|
-
fulfillmentCenter: payload.fulfilmentCenter
|
|
47
|
-
};
|
|
48
|
-
model.sku = skuString;
|
|
57
|
+
const quantity = generator.number.int({ min: 0, max: 100 });
|
|
49
58
|
|
|
50
|
-
|
|
51
|
-
if (
|
|
52
|
-
|
|
53
|
-
} else {
|
|
54
|
-
model.status = 'outOfStock';
|
|
59
|
+
let status: InventoryStatus = 'outOfStock';
|
|
60
|
+
if (quantity > 0) {
|
|
61
|
+
status = 'inStock';
|
|
55
62
|
}
|
|
56
63
|
|
|
64
|
+
const result = {
|
|
65
|
+
identifier,
|
|
66
|
+
quantity,
|
|
67
|
+
status
|
|
68
|
+
} satisfies Inventory;
|
|
57
69
|
|
|
58
|
-
|
|
59
|
-
cache: {
|
|
60
|
-
hit: false,
|
|
61
|
-
key: this.generateCacheKeySingle(model.identifier, _reqCtx)
|
|
62
|
-
},
|
|
63
|
-
placeholder: false,
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
return this.assert(model);
|
|
70
|
+
return success(result);
|
|
67
71
|
}
|
|
68
72
|
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OrderSearchProvider,
|
|
3
|
+
OrderSearchQueryByTermSchema,
|
|
4
|
+
OrderSearchResultSchema,
|
|
5
|
+
Reactionary,
|
|
6
|
+
type Cache,
|
|
7
|
+
type OrderSearchQueryByTerm,
|
|
8
|
+
type OrderSearchResult,
|
|
9
|
+
type RequestContext,
|
|
10
|
+
type Result,
|
|
11
|
+
success,
|
|
12
|
+
type OrderSearchResultItem,
|
|
13
|
+
} from '@reactionary/core';
|
|
14
|
+
import type { FakeConfiguration } from '../schema/configuration.schema.js';
|
|
15
|
+
import { Faker, en, base } from '@faker-js/faker';
|
|
16
|
+
|
|
17
|
+
export class FakeOrderSearchProvider extends OrderSearchProvider {
|
|
18
|
+
protected config: FakeConfiguration;
|
|
19
|
+
protected generator: Faker;
|
|
20
|
+
|
|
21
|
+
constructor(
|
|
22
|
+
config: FakeConfiguration,
|
|
23
|
+
cache: Cache,
|
|
24
|
+
context: RequestContext
|
|
25
|
+
) {
|
|
26
|
+
super(cache, context);
|
|
27
|
+
|
|
28
|
+
this.config = config;
|
|
29
|
+
|
|
30
|
+
this.generator = new Faker({
|
|
31
|
+
locale: [en, base],
|
|
32
|
+
seed: config.seeds.product,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@Reactionary({
|
|
37
|
+
inputSchema: OrderSearchQueryByTermSchema,
|
|
38
|
+
outputSchema: OrderSearchResultSchema,
|
|
39
|
+
})
|
|
40
|
+
public override async queryByTerm(
|
|
41
|
+
payload: OrderSearchQueryByTerm
|
|
42
|
+
): Promise<Result<OrderSearchResult>> {
|
|
43
|
+
const items = new Array<OrderSearchResultItem>();
|
|
44
|
+
|
|
45
|
+
for (let i = 0; i < payload.search.paginationOptions.pageSize; i++) {
|
|
46
|
+
items.push({
|
|
47
|
+
customerName: this.generator.company.name(),
|
|
48
|
+
identifier: {
|
|
49
|
+
key: this.generator.string.uuid()
|
|
50
|
+
},
|
|
51
|
+
inventoryStatus: 'Allocated',
|
|
52
|
+
orderDate: this.generator.date.past().toString(),
|
|
53
|
+
orderStatus: 'Shipped',
|
|
54
|
+
totalAmount: {
|
|
55
|
+
currency: 'USD',
|
|
56
|
+
value: this.generator.number.int({ multipleOf: 100 })
|
|
57
|
+
},
|
|
58
|
+
userId: {
|
|
59
|
+
userId: '1234'
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const totalCount = this.generator.number.int({ min: items.length, max: 200 });
|
|
65
|
+
const totalPages = Math.ceil(totalCount / payload.search.paginationOptions.pageSize);
|
|
66
|
+
|
|
67
|
+
const result = {
|
|
68
|
+
identifier: payload.search,
|
|
69
|
+
items,
|
|
70
|
+
pageNumber: payload.search.paginationOptions.pageNumber,
|
|
71
|
+
pageSize: payload.search.paginationOptions.pageSize,
|
|
72
|
+
totalCount,
|
|
73
|
+
totalPages
|
|
74
|
+
} satisfies OrderSearchResult;
|
|
75
|
+
|
|
76
|
+
return success(result);
|
|
77
|
+
}
|
|
78
|
+
}
|