@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,82 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
2
|
+
import { assert, describe, expect, it } from 'vitest';
|
|
3
|
+
import { getCommercetoolsTestConfiguration } from './test-utils.js';
|
|
4
|
+
import {
|
|
5
|
+
createInitialRequestContext,
|
|
6
|
+
MemoryCache,
|
|
7
|
+
type ProductIdentifier,
|
|
8
|
+
type ProductSearchQueryByTerm,
|
|
9
|
+
} from '@reactionary/core';
|
|
10
|
+
import { CommercetoolsProductProvider } from '../providers/product.provider.js';
|
|
11
|
+
import { CommercetoolsClient } from '../core/client.js';
|
|
12
|
+
import { CommercetoolsSearchProvider } from '../providers/product-search.provider.js';
|
|
13
|
+
|
|
14
|
+
describe('Caching', () => {
|
|
15
|
+
it('should cache repeat look-ups for products', async () => {
|
|
16
|
+
const config = getCommercetoolsTestConfiguration();
|
|
17
|
+
const context = createInitialRequestContext();
|
|
18
|
+
const cache = new MemoryCache();
|
|
19
|
+
const client = new CommercetoolsClient(config, context);
|
|
20
|
+
const provider = new CommercetoolsProductProvider(config, cache, context, client);
|
|
21
|
+
|
|
22
|
+
const identifier = {
|
|
23
|
+
key: 'product_10959528'
|
|
24
|
+
} satisfies ProductIdentifier;
|
|
25
|
+
|
|
26
|
+
const uncached = await provider.getById({
|
|
27
|
+
identifier
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
if (!uncached.success) {
|
|
31
|
+
assert.fail();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
expect(uncached.meta.cache.hit).toBe(false);
|
|
35
|
+
|
|
36
|
+
const cached = await provider.getById({
|
|
37
|
+
identifier
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
if (!cached.success) {
|
|
41
|
+
assert.fail();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
expect(cached.meta.cache.hit).toBe(true);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('should cache repeat look-ups for product search', async () => {
|
|
48
|
+
const config = getCommercetoolsTestConfiguration();
|
|
49
|
+
const context = createInitialRequestContext();
|
|
50
|
+
const cache = new MemoryCache();
|
|
51
|
+
const client = new CommercetoolsClient(config, context);
|
|
52
|
+
const provider = new CommercetoolsSearchProvider(config, cache, context, client);
|
|
53
|
+
|
|
54
|
+
const query = {
|
|
55
|
+
search: {
|
|
56
|
+
facets: [],
|
|
57
|
+
filters: [],
|
|
58
|
+
paginationOptions: {
|
|
59
|
+
pageNumber: 1,
|
|
60
|
+
pageSize: 10
|
|
61
|
+
},
|
|
62
|
+
term: 'laptop'
|
|
63
|
+
}
|
|
64
|
+
} satisfies ProductSearchQueryByTerm;
|
|
65
|
+
|
|
66
|
+
const uncached = await provider.queryByTerm(query);
|
|
67
|
+
|
|
68
|
+
if (!uncached.success) {
|
|
69
|
+
assert.fail();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
expect(uncached.meta.cache.hit).toBe(false);
|
|
73
|
+
|
|
74
|
+
const cached = await provider.queryByTerm(query);
|
|
75
|
+
|
|
76
|
+
if (!cached.success) {
|
|
77
|
+
assert.fail();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
expect(cached.meta.cache.hit).toBe(true);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { CommercetoolsClient } from '../core/client.js';
|
|
4
|
+
import { getCommercetoolsTestConfiguration } from './test-utils.js';
|
|
5
|
+
import {
|
|
6
|
+
createInitialRequestContext,
|
|
7
|
+
type RequestContext,
|
|
8
|
+
} from '@reactionary/core';
|
|
9
|
+
import type { ApiRoot } from '@commercetools/platform-sdk';
|
|
10
|
+
import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
|
|
11
|
+
|
|
12
|
+
function setup() {
|
|
13
|
+
const config = getCommercetoolsTestConfiguration();
|
|
14
|
+
const context = createInitialRequestContext();
|
|
15
|
+
const root = new CommercetoolsClient(config, context);
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
config,
|
|
19
|
+
context,
|
|
20
|
+
root,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function createCart(
|
|
25
|
+
client: ApiRoot,
|
|
26
|
+
context: RequestContext,
|
|
27
|
+
config: CommercetoolsConfiguration
|
|
28
|
+
) {
|
|
29
|
+
const cart = await client
|
|
30
|
+
.withProjectKey({ projectKey: config.projectKey })
|
|
31
|
+
.me()
|
|
32
|
+
.carts()
|
|
33
|
+
.post({
|
|
34
|
+
body: {
|
|
35
|
+
currency: context.languageContext.currencyCode,
|
|
36
|
+
lineItems: [
|
|
37
|
+
{
|
|
38
|
+
sku: '0766623301831',
|
|
39
|
+
distributionChannel: {
|
|
40
|
+
typeId: 'channel',
|
|
41
|
+
key: 'OnlineFfmChannel',
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
.execute();
|
|
48
|
+
|
|
49
|
+
return cart;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
describe('Commercetools Identity', () => {
|
|
53
|
+
it('initially is considered anonymous', async () => {
|
|
54
|
+
const { root } = setup();
|
|
55
|
+
|
|
56
|
+
const initialSelf = await root.introspect();
|
|
57
|
+
expect(initialSelf.type).toBe('Anonymous');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('becomes a guest when acquiring a client for user operations', async () => {
|
|
61
|
+
const { root } = setup();
|
|
62
|
+
|
|
63
|
+
const client = await root.getClient();
|
|
64
|
+
const guestSelf = await root.introspect();
|
|
65
|
+
expect(guestSelf.type).toBe('Guest');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('can login from being anonymous', async () => {
|
|
69
|
+
const { config, context, root } = setup();
|
|
70
|
+
|
|
71
|
+
// After a login, we are expected to be Registered
|
|
72
|
+
const identity = await root.login('asger.jensen3@solteq.com', 'test12345');
|
|
73
|
+
expect(identity.type).toBe('Registered');
|
|
74
|
+
|
|
75
|
+
// And we expect the introspected result of what is in token-cache to match that...
|
|
76
|
+
const introspectedRegisteredIdentity = await root.introspect();
|
|
77
|
+
expect(introspectedRegisteredIdentity.type).toBe('Registered');
|
|
78
|
+
|
|
79
|
+
// Finally, we expect to be able to perform an add-to-cart (only acquiring client AFTER being logged in)
|
|
80
|
+
const client = await root.getClient();
|
|
81
|
+
const cart = await createCart(client, context, config);
|
|
82
|
+
|
|
83
|
+
expect(cart.body.id).toBeDefined();
|
|
84
|
+
expect(cart.body.lineItems.length).toBe(1);
|
|
85
|
+
expect(cart.body.customerId).toBe(identity.id.userId);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('can login from being guest', async () => {
|
|
89
|
+
const { config, context, root } = setup();
|
|
90
|
+
|
|
91
|
+
// Become guest by acquiring a client
|
|
92
|
+
const client = await root.getClient();
|
|
93
|
+
|
|
94
|
+
// After a login, we are expected to be Registered
|
|
95
|
+
const identity = await root.login('asger.jensen3@solteq.com', 'test12345');
|
|
96
|
+
expect(identity.type).toBe('Registered');
|
|
97
|
+
|
|
98
|
+
// And we expect the introspected result of what is in token-cache to match that...
|
|
99
|
+
const introspectedRegisteredIdentity = await root.introspect();
|
|
100
|
+
expect(introspectedRegisteredIdentity.type).toBe('Registered');
|
|
101
|
+
|
|
102
|
+
// Finally, we expect to be able to perform an add-to-cart
|
|
103
|
+
const cart = await createCart(client, context, config);
|
|
104
|
+
|
|
105
|
+
expect(cart.body.id).toBeDefined();
|
|
106
|
+
expect(cart.body.lineItems.length).toBe(1);
|
|
107
|
+
expect(cart.body.customerId).toBe(identity.id.userId);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -1,25 +1,27 @@
|
|
|
1
|
-
import { PaymentMethodSchema } from '@reactionary/core';
|
|
1
|
+
import { PaymentMethodSchema, type PaymentMethod, type PaymentMethodIdentifier } from '@reactionary/core';
|
|
2
2
|
import { PaymentMethodIdentifierSchema } from '@reactionary/core';
|
|
3
|
+
import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
|
|
3
4
|
|
|
4
5
|
export function getCommercetoolsTestConfiguration() {
|
|
5
6
|
return {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
apiUrl: process.env['CTP_API_URL'] || '',
|
|
8
|
+
authUrl: process.env['CTP_AUTH_URL'] || '',
|
|
9
|
+
clientId: process.env['CTP_CLIENT_ID'] || '',
|
|
10
|
+
clientSecret: process.env['CTP_CLIENT_SECRET'] || '',
|
|
11
|
+
projectKey: process.env['CTP_PROJECT_KEY'] || '',
|
|
12
|
+
scopes: (process.env['CTP_SCOPES'] || '').split(',').map(x => x.trim()).filter(x => x && x.length > 0),
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
paymentMethods: [
|
|
15
|
+
PaymentMethodSchema.parse({
|
|
16
|
+
identifier: PaymentMethodIdentifierSchema.parse({
|
|
17
|
+
paymentProcessor: 'stripe',
|
|
18
|
+
method: 'stripe',
|
|
19
|
+
name: 'Stripe',
|
|
20
|
+
} satisfies Partial<PaymentMethodIdentifier>),
|
|
21
|
+
description: 'Stripe payment gateway',
|
|
22
|
+
isPunchOut: true,
|
|
23
|
+
} satisfies Partial<PaymentMethod>),
|
|
24
|
+
],
|
|
25
|
+
facetFieldsForSearch: []
|
|
26
|
+
} satisfies CommercetoolsConfiguration
|
|
24
27
|
}
|
|
25
|
-
|
|
@@ -1,16 +1,4 @@
|
|
|
1
1
|
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"moduleResolution": "node",
|
|
6
|
-
"verbatimModuleSyntax": false,
|
|
7
|
-
"outDir": "../../dist/out-tsc",
|
|
8
|
-
"types": ["jest", "node"]
|
|
9
|
-
},
|
|
10
|
-
"include": [
|
|
11
|
-
"jest.config.cjs",
|
|
12
|
-
"src/**/*.test.ts",
|
|
13
|
-
"src/**/*.spec.ts",
|
|
14
|
-
"src/**/*.d.ts"
|
|
15
|
-
]
|
|
2
|
+
"extends": "./tsconfig.lib.json",
|
|
3
|
+
"exclude": []
|
|
16
4
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="vitest" />
|
|
2
|
+
import { defineConfig, defineProject } from 'vitest/config';
|
|
3
|
+
import tsconfigPaths from 'vite-tsconfig-paths';
|
|
4
|
+
import { resolve } from 'path';
|
|
5
|
+
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
|
|
6
|
+
|
|
7
|
+
export default defineProject({
|
|
8
|
+
plugins: [nxViteTsPaths()],
|
|
9
|
+
test: {
|
|
10
|
+
root: resolve(__dirname),
|
|
11
|
+
globals: true,
|
|
12
|
+
environment: 'node',
|
|
13
|
+
include: ['src/**/*.spec.{ts,js}', 'src/**/*.test.ts'],
|
|
14
|
+
},
|
|
15
|
+
});
|
package/providers/fake/README.md
CHANGED
|
@@ -1,7 +1,23 @@
|
|
|
1
|
-
# Fake
|
|
1
|
+
# Fake provider for Reactionary
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Supports
|
|
4
4
|
|
|
5
|
-
## Building
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
|
|
7
|
+
| Feature | Support | Notes |
|
|
8
|
+
| ----------- | ----------- | --------- |
|
|
9
|
+
| product | Full | |
|
|
10
|
+
| productSearch | Full | |
|
|
11
|
+
| identity | Full | |
|
|
12
|
+
| cart | Full | |
|
|
13
|
+
| checkout | Planned | |
|
|
14
|
+
| order | Planned | |
|
|
15
|
+
| inventory | Full | |
|
|
16
|
+
| price | Full | |
|
|
17
|
+
| category | Full | |
|
|
18
|
+
| store | Full | |
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## Notes
|
|
22
|
+
|
|
23
|
+
Not as many different product names as we would have liked. Maybe we need to create our own faker test data.
|
|
@@ -1,95 +1,93 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
Cache as ReactinaryCache,
|
|
3
|
-
|
|
4
|
-
|
|
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,
|
|
3
|
+
RequestContext,
|
|
4
|
+
ClientFromCapabilities,
|
|
20
5
|
} from '@reactionary/core';
|
|
21
6
|
import { FakeProductProvider } from '../providers/product.provider.js';
|
|
22
|
-
import { FakeSearchProvider } from '../providers/search.provider.js';
|
|
7
|
+
import { FakeSearchProvider } from '../providers/product-search.provider.js';
|
|
23
8
|
import type { FakeConfiguration } from '../schema/configuration.schema.js';
|
|
24
9
|
import type { FakeCapabilities } from '../schema/capabilities.schema.js';
|
|
25
10
|
import { FakeCategoryProvider } from '../providers/category.provider.js';
|
|
26
11
|
import {
|
|
27
12
|
FakeCartProvider,
|
|
13
|
+
FakeIdentityProvider,
|
|
28
14
|
FakeInventoryProvider,
|
|
29
15
|
FakePriceProvider,
|
|
30
16
|
FakeStoreProvider,
|
|
31
17
|
} from '../providers/index.js';
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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);
|
|
18
|
+
import { FakeCheckoutProvider } from '../providers/checkout.provider.js';
|
|
19
|
+
import { FakeOrderSearchProvider } from '../providers/order-search.provider.js';
|
|
20
|
+
import { FakeOrderProvider } from '../providers/order.provider.js';
|
|
21
|
+
import { FakeProfileProvider } from '../providers/profile.provider.js';
|
|
43
22
|
|
|
44
23
|
export function withFakeCapabilities<T extends FakeCapabilities>(
|
|
45
24
|
configuration: FakeConfiguration,
|
|
46
25
|
capabilities: T
|
|
47
26
|
) {
|
|
48
|
-
return (
|
|
27
|
+
return (
|
|
28
|
+
cache: ReactinaryCache,
|
|
29
|
+
context: RequestContext
|
|
30
|
+
): ClientFromCapabilities<T> => {
|
|
49
31
|
const client: any = {};
|
|
50
32
|
|
|
51
33
|
if (capabilities.product) {
|
|
52
|
-
client.product = new FakeProductProvider(
|
|
53
|
-
configuration,
|
|
54
|
-
ProductSchema,
|
|
55
|
-
cache
|
|
56
|
-
);
|
|
34
|
+
client.product = new FakeProductProvider(configuration, cache, context);
|
|
57
35
|
}
|
|
58
36
|
|
|
59
|
-
if (capabilities.
|
|
60
|
-
client.
|
|
37
|
+
if (capabilities.productSearch) {
|
|
38
|
+
client.productSearch = new FakeSearchProvider(
|
|
61
39
|
configuration,
|
|
62
|
-
|
|
63
|
-
|
|
40
|
+
cache,
|
|
41
|
+
context
|
|
64
42
|
);
|
|
65
43
|
}
|
|
66
44
|
|
|
67
45
|
if (capabilities.category) {
|
|
68
|
-
client.category = new FakeCategoryProvider(
|
|
69
|
-
configuration,
|
|
70
|
-
CategorySchema,
|
|
71
|
-
cache
|
|
72
|
-
);
|
|
46
|
+
client.category = new FakeCategoryProvider(configuration, cache, context);
|
|
73
47
|
}
|
|
74
48
|
|
|
75
49
|
if (capabilities.cart) {
|
|
76
|
-
client.cart = new FakeCartProvider(configuration,
|
|
50
|
+
client.cart = new FakeCartProvider(configuration, cache, context);
|
|
77
51
|
}
|
|
78
52
|
|
|
79
53
|
if (capabilities.inventory) {
|
|
80
54
|
client.inventory = new FakeInventoryProvider(
|
|
81
55
|
configuration,
|
|
82
|
-
|
|
83
|
-
|
|
56
|
+
cache,
|
|
57
|
+
context
|
|
84
58
|
);
|
|
85
59
|
}
|
|
86
60
|
|
|
87
61
|
if (capabilities.store) {
|
|
88
|
-
client.store = new FakeStoreProvider(configuration,
|
|
62
|
+
client.store = new FakeStoreProvider(configuration, cache, context);
|
|
89
63
|
}
|
|
90
64
|
|
|
91
65
|
if (capabilities.price) {
|
|
92
|
-
client.price = new FakePriceProvider(configuration,
|
|
66
|
+
client.price = new FakePriceProvider(configuration, cache, context);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (capabilities.identity) {
|
|
70
|
+
client.identity = new FakeIdentityProvider(configuration, cache, context);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (capabilities.checkout) {
|
|
74
|
+
client.checkout = new FakeCheckoutProvider(configuration, cache, context);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (capabilities.orderSearch) {
|
|
78
|
+
client.orderSearch = new FakeOrderSearchProvider(
|
|
79
|
+
configuration,
|
|
80
|
+
cache,
|
|
81
|
+
context
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (capabilities.order) {
|
|
86
|
+
client.order = new FakeOrderProvider(configuration, cache, context);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (capabilities.profile) {
|
|
90
|
+
client.profile = new FakeProfileProvider(configuration, cache, context);
|
|
93
91
|
}
|
|
94
92
|
|
|
95
93
|
return client;
|
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
Cache,
|
|
3
|
+
RequestContext} from '@reactionary/core';
|
|
4
4
|
import {
|
|
5
5
|
AnalyticsProvider
|
|
6
6
|
} from '@reactionary/core';
|
|
7
7
|
import type z from 'zod';
|
|
8
8
|
import type { FakeConfiguration } from '../schema/configuration.schema.js';
|
|
9
9
|
|
|
10
|
-
export class FakeAnalyticsProvider
|
|
11
|
-
T extends BaseModel = BaseModel
|
|
12
|
-
> extends AnalyticsProvider<T> {
|
|
10
|
+
export class FakeAnalyticsProvider extends AnalyticsProvider {
|
|
13
11
|
protected config: FakeConfiguration;
|
|
14
12
|
|
|
15
|
-
constructor(config: FakeConfiguration,
|
|
16
|
-
super(
|
|
13
|
+
constructor(config: FakeConfiguration, cache: Cache, context: RequestContext) {
|
|
14
|
+
super(cache, context);
|
|
17
15
|
|
|
18
16
|
this.config = config;
|
|
19
17
|
}
|