@reactionary/source 0.3.18 → 0.6.2
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/README.md +28 -14
- package/core/src/client/client-builder.ts +54 -6
- package/core/src/factories/cart.factory.ts +40 -0
- package/core/src/factories/category.factory.ts +40 -0
- package/core/src/factories/checkout.factory.ts +59 -0
- package/core/src/factories/identity.factory.ts +26 -0
- package/core/src/factories/index.ts +15 -0
- package/core/src/factories/inventory.factory.ts +26 -0
- package/core/src/factories/order-search.factory.ts +33 -0
- package/core/src/factories/order.factory.ts +21 -0
- package/core/src/factories/price.factory.ts +29 -0
- package/core/src/factories/product-associations.factory.ts +30 -0
- package/core/src/factories/product-list.factory.ts +82 -0
- package/core/src/factories/product-reviews.factory.ts +58 -0
- package/core/src/factories/product-search.factory.ts +31 -0
- package/core/src/factories/product.factory.ts +21 -0
- package/core/src/factories/profile.factory.ts +23 -0
- package/core/src/factories/store.factory.ts +21 -0
- package/core/src/index.ts +3 -1
- package/core/src/providers/cart.provider.ts +12 -10
- package/core/src/providers/category.provider.ts +9 -7
- package/core/src/providers/checkout.provider.ts +14 -10
- package/core/src/providers/identity.provider.ts +7 -7
- package/core/src/providers/inventory.provider.ts +4 -4
- package/core/src/providers/order-search.provider.ts +4 -2
- package/core/src/providers/order.provider.ts +4 -4
- package/core/src/providers/price.provider.ts +5 -5
- package/core/src/providers/product-associations.provider.ts +6 -4
- package/core/src/providers/product-list.provider.ts +13 -8
- package/core/src/providers/product-reviews.provider.ts +8 -4
- package/core/src/providers/product-search.provider.ts +15 -28
- package/core/src/providers/product.provider.ts +6 -6
- package/core/src/providers/profile.provider.ts +8 -8
- package/core/src/providers/store.provider.ts +2 -2
- package/core/src/test/client-builder.spec.ts +81 -0
- package/examples/node/package.json +7 -7
- package/examples/node/src/basic/basic-node-provider-model-extension.spec.ts +10 -4
- package/examples/node/src/basic/basic-node-provider-query-extension.spec.ts +8 -2
- package/examples/node/src/basic/basic-node-setup.spec.ts +5 -1
- package/examples/node/src/basic/client-creation.spec.ts +3 -3
- package/examples/node/src/utils.ts +41 -41
- package/examples/node/tsconfig.lib.json +2 -1
- package/package.json +1 -1
- package/providers/algolia/src/core/initialize.ts +76 -21
- package/providers/algolia/src/core/initialize.types.ts +107 -0
- package/providers/algolia/src/factories/index.ts +1 -0
- package/providers/algolia/src/factories/product-search/product-search.factory.ts +182 -0
- package/providers/algolia/src/index.ts +2 -2
- package/providers/algolia/src/providers/analytics.provider.ts +4 -4
- package/providers/algolia/src/providers/product-search.provider.ts +67 -184
- package/providers/algolia/src/schema/capabilities.schema.ts +81 -7
- package/providers/algolia/src/test/analytics.spec.ts +9 -1
- package/providers/algolia/src/test/client-builder-product-search-extension.example.ts +85 -0
- package/providers/commercetools/src/core/capability-descriptors.ts +324 -0
- package/providers/commercetools/src/core/initialize.ts +35 -151
- package/providers/commercetools/src/core/initialize.types.ts +174 -0
- package/providers/commercetools/src/factories/cart/cart.factory.ts +142 -0
- package/providers/commercetools/src/factories/category/category.factory.ts +77 -0
- package/providers/commercetools/src/factories/checkout/checkout-initializer-overrides.example.ts +94 -0
- package/providers/commercetools/src/factories/checkout/checkout.factory.ts +338 -0
- package/providers/commercetools/src/factories/identity/identity.factory.ts +26 -0
- package/providers/commercetools/src/factories/inventory/inventory.factory.ts +49 -0
- package/providers/commercetools/src/factories/order/order.factory.ts +149 -0
- package/providers/commercetools/src/factories/order-search/order-search.factory.ts +108 -0
- package/providers/commercetools/src/factories/price/price.factory.ts +76 -0
- package/providers/commercetools/src/factories/product/product-factory-baseline.example.ts +14 -0
- package/providers/commercetools/src/factories/product/product-factory-schema-and-parse-extension.example.ts +35 -0
- package/providers/commercetools/src/factories/product/product-factory-schema-extension.example.ts +23 -0
- package/providers/commercetools/src/factories/product/product-initializer-factory-extension.example.ts +41 -0
- package/providers/commercetools/src/factories/product/product-provider-custom-method-only.example.ts +47 -0
- package/providers/commercetools/src/factories/product/product-provider-schema-signature-extension.example.ts +61 -0
- package/providers/commercetools/src/factories/product/product.factory.ts +220 -0
- package/providers/commercetools/src/factories/product/utils.example.ts +9 -0
- package/providers/commercetools/src/factories/product-associations/product-associations.factory.ts +103 -0
- package/providers/commercetools/src/factories/product-list/product-list.factory.ts +122 -0
- package/providers/commercetools/src/factories/product-reviews/product-reviews.factory.ts +81 -0
- package/providers/commercetools/src/factories/product-search/product-search.factory.ts +182 -0
- package/providers/commercetools/src/factories/profile/profile.factory.ts +94 -0
- package/providers/commercetools/src/factories/store/store.factory.ts +49 -0
- package/providers/commercetools/src/index.ts +15 -0
- package/providers/commercetools/src/providers/cart.provider.ts +67 -193
- package/providers/commercetools/src/providers/category.provider.ts +24 -64
- package/providers/commercetools/src/providers/checkout.provider.ts +50 -322
- package/providers/commercetools/src/providers/identity.provider.ts +35 -15
- package/providers/commercetools/src/providers/inventory.provider.ts +13 -31
- package/providers/commercetools/src/providers/order-search.provider.ts +16 -110
- package/providers/commercetools/src/providers/order.provider.ts +13 -144
- package/providers/commercetools/src/providers/price.provider.ts +37 -51
- package/providers/commercetools/src/providers/product-associations.provider.ts +39 -104
- package/providers/commercetools/src/providers/product-list.provider.ts +38 -23
- package/providers/commercetools/src/providers/product-reviews.provider.ts +34 -14
- package/providers/commercetools/src/providers/product-search.provider.ts +17 -170
- package/providers/commercetools/src/providers/product.provider.ts +20 -199
- package/providers/commercetools/src/providers/profile.provider.ts +27 -73
- package/providers/commercetools/src/providers/store.provider.ts +13 -31
- package/providers/commercetools/src/schema/capabilities.schema.ts +258 -20
- package/providers/commercetools/src/test/caching.spec.ts +18 -2
- package/providers/commercetools/src/test/client-builder-merge-extensions.example.ts +125 -0
- package/providers/fake/src/core/initialize.ts +213 -44
- package/providers/fake/src/core/initialize.types.ts +164 -0
- package/providers/fake/src/factories/cart/cart.factory.ts +34 -0
- package/providers/fake/src/factories/category/category.factory.ts +40 -0
- package/providers/fake/src/factories/checkout/checkout.factory.ts +53 -0
- package/providers/fake/src/factories/identity/identity.factory.ts +25 -0
- package/providers/fake/src/factories/index.ts +14 -0
- package/providers/fake/src/factories/inventory/inventory.factory.ts +25 -0
- package/providers/fake/src/factories/order/order.factory.ts +22 -0
- package/providers/fake/src/factories/order-search/order-search.factory.ts +27 -0
- package/providers/fake/src/factories/price/price.factory.ts +26 -0
- package/providers/fake/src/factories/product/product.factory.ts +22 -0
- package/providers/fake/src/factories/product-associations/product-associations.factory.ts +25 -0
- package/providers/fake/src/factories/product-reviews/product-reviews.factory.ts +53 -0
- package/providers/fake/src/factories/product-search/product-search.factory.ts +27 -0
- package/providers/fake/src/factories/profile/profile.factory.ts +22 -0
- package/providers/fake/src/factories/store/store.factory.ts +22 -0
- package/providers/fake/src/index.ts +2 -0
- package/providers/fake/src/providers/cart.provider.ts +23 -14
- package/providers/fake/src/providers/category.provider.ts +120 -105
- package/providers/fake/src/providers/checkout.provider.ts +39 -20
- package/providers/fake/src/providers/identity.provider.ts +40 -34
- package/providers/fake/src/providers/inventory.provider.ts +26 -24
- package/providers/fake/src/providers/order-search.provider.ts +38 -30
- package/providers/fake/src/providers/order.provider.ts +21 -37
- package/providers/fake/src/providers/price.provider.ts +42 -34
- package/providers/fake/src/providers/product-associations.provider.ts +23 -10
- package/providers/fake/src/providers/product-reviews.provider.ts +71 -69
- package/providers/fake/src/providers/product-search.provider.ts +43 -70
- package/providers/fake/src/providers/product.provider.ts +34 -32
- package/providers/fake/src/providers/profile.provider.ts +62 -55
- package/providers/fake/src/providers/store.provider.ts +38 -22
- package/providers/fake/src/schema/capabilities.schema.ts +175 -18
- package/providers/fake/src/test/cart.provider.spec.ts +20 -3
- package/providers/fake/src/test/category.provider.spec.ts +4 -1
- package/providers/fake/src/test/checkout.provider.spec.ts +12 -2
- package/providers/fake/src/test/client-builder-product-extension.example.ts +75 -0
- package/providers/fake/src/test/order-search.provider.spec.ts +4 -7
- package/providers/fake/src/test/order.provider.spec.ts +4 -6
- package/providers/fake/src/test/price.provider.spec.ts +3 -1
- package/providers/fake/src/test/product.provider.spec.ts +8 -2
- package/providers/fake/src/test/profile.provider.spec.ts +4 -2
- package/providers/google-analytics/src/core/initialize.ts +37 -12
- package/providers/google-analytics/src/core/initialize.types.ts +47 -0
- package/providers/google-analytics/src/index.ts +1 -0
- package/providers/google-analytics/src/schema/capabilities.schema.ts +31 -5
- package/providers/medusa/src/core/initialize.ts +324 -81
- package/providers/medusa/src/core/initialize.types.ts +184 -0
- package/providers/medusa/src/factories/cart/cart.factory.ts +34 -0
- package/providers/medusa/src/factories/category/category.factory.ts +37 -0
- package/providers/medusa/src/factories/checkout/checkout.factory.ts +50 -0
- package/providers/medusa/src/factories/identity/identity.factory.ts +22 -0
- package/providers/medusa/src/factories/index.ts +12 -0
- package/providers/medusa/src/factories/inventory/inventory.factory.ts +25 -0
- package/providers/medusa/src/factories/order/order.factory.ts +22 -0
- package/providers/medusa/src/factories/order-search/order-search.factory.ts +27 -0
- package/providers/medusa/src/factories/price/price.factory.ts +26 -0
- package/providers/medusa/src/factories/product/product.factory.ts +22 -0
- package/providers/medusa/src/factories/product-associations/product-associations.factory.ts +25 -0
- package/providers/medusa/src/factories/product-search/product-search.factory.ts +27 -0
- package/providers/medusa/src/factories/profile/profile.factory.ts +22 -0
- package/providers/medusa/src/index.ts +2 -0
- package/providers/medusa/src/providers/cart.provider.ts +33 -20
- package/providers/medusa/src/providers/category.provider.ts +30 -12
- package/providers/medusa/src/providers/checkout.provider.ts +42 -17
- package/providers/medusa/src/providers/identity.provider.ts +1 -1
- package/providers/medusa/src/providers/inventory.provider.ts +21 -7
- package/providers/medusa/src/providers/order-search.provider.ts +16 -5
- package/providers/medusa/src/providers/order.provider.ts +17 -5
- package/providers/medusa/src/providers/price.provider.ts +26 -7
- package/providers/medusa/src/providers/product-associations.provider.ts +19 -8
- package/providers/medusa/src/providers/product-search.provider.ts +19 -31
- package/providers/medusa/src/providers/product.provider.ts +47 -11
- package/providers/medusa/src/providers/profile.provider.ts +35 -11
- package/providers/medusa/src/schema/capabilities.schema.ts +229 -18
- package/providers/medusa/src/test/cart.provider.spec.ts +18 -2
- package/providers/medusa/src/test/category.provider.spec.ts +4 -1
- package/providers/medusa/src/test/checkout.spec.ts +9 -9
- package/providers/medusa/src/test/inventory.provider.spec.ts +3 -1
- package/providers/medusa/src/test/large-cart.provider.spec.ts +8 -2
- package/providers/medusa/src/test/price.provider.spec.ts +8 -1
- package/providers/medusa/src/test/product.provider.spec.ts +3 -1
- package/providers/medusa/src/test/search.provider.spec.ts +16 -3
- package/providers/meilisearch/src/core/initialize.ts +88 -21
- package/providers/meilisearch/src/core/initialize.types.ts +119 -0
- package/providers/meilisearch/src/factories/index.ts +2 -0
- package/providers/meilisearch/src/factories/order-search/order-search.factory.ts +27 -0
- package/providers/meilisearch/src/factories/product-search/product-search.factory.ts +27 -0
- package/providers/meilisearch/src/index.ts +2 -0
- package/providers/meilisearch/src/providers/index.ts +1 -0
- package/providers/meilisearch/src/providers/order-search.provider.ts +21 -6
- package/providers/meilisearch/src/providers/product-search.provider.ts +24 -8
- package/providers/meilisearch/src/schema/capabilities.schema.ts +95 -8
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
import 'dotenv/config';
|
|
2
2
|
import type { RequestContext } from '@reactionary/core';
|
|
3
3
|
import {
|
|
4
|
-
CartSchema,
|
|
5
|
-
IdentitySchema,
|
|
6
4
|
NoOpCache,
|
|
5
|
+
OrderSearchResultSchema,
|
|
7
6
|
createInitialRequestContext,
|
|
8
7
|
} from '@reactionary/core';
|
|
9
8
|
import { getFakerTestConfiguration } from './test-utils.js';
|
|
10
|
-
import { FakeCartProvider } from '../providers/cart.provider.js';
|
|
11
|
-
import { FakeIdentityProvider } from '../providers/index.js';
|
|
12
9
|
import { describe, expect, it, beforeAll, beforeEach, assert } from 'vitest';
|
|
13
|
-
import { FakeCheckoutProvider } from '../providers/checkout.provider.js';
|
|
14
|
-
import { FakeOrderProvider } from '../providers/order.provider.js';
|
|
15
10
|
import { FakeOrderSearchProvider } from '../providers/order-search.provider.js';
|
|
11
|
+
import { FakeOrderSearchFactory } from '../factories/index.js';
|
|
16
12
|
|
|
17
13
|
describe('Fake Order Search Provider', () => {
|
|
18
14
|
let provider: FakeOrderSearchProvider;
|
|
@@ -23,7 +19,8 @@ describe('Fake Order Search Provider', () => {
|
|
|
23
19
|
provider = new FakeOrderSearchProvider(
|
|
24
20
|
getFakerTestConfiguration(),
|
|
25
21
|
new NoOpCache(),
|
|
26
|
-
reqCtx
|
|
22
|
+
reqCtx,
|
|
23
|
+
new FakeOrderSearchFactory(OrderSearchResultSchema),
|
|
27
24
|
);
|
|
28
25
|
});
|
|
29
26
|
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import 'dotenv/config';
|
|
2
2
|
import type { RequestContext } from '@reactionary/core';
|
|
3
3
|
import {
|
|
4
|
-
CartSchema,
|
|
5
|
-
IdentitySchema,
|
|
6
4
|
NoOpCache,
|
|
5
|
+
OrderSchema,
|
|
7
6
|
createInitialRequestContext,
|
|
8
7
|
} from '@reactionary/core';
|
|
9
8
|
import { getFakerTestConfiguration } from './test-utils.js';
|
|
10
|
-
import { FakeCartProvider } from '../providers/cart.provider.js';
|
|
11
|
-
import { FakeIdentityProvider } from '../providers/index.js';
|
|
12
9
|
import { describe, expect, it, beforeAll, beforeEach, assert } from 'vitest';
|
|
13
|
-
import { FakeCheckoutProvider } from '../providers/checkout.provider.js';
|
|
14
10
|
import { FakeOrderProvider } from '../providers/order.provider.js';
|
|
11
|
+
import { FakeOrderFactory } from '../factories/index.js';
|
|
15
12
|
|
|
16
13
|
describe('Fake Order Provider', () => {
|
|
17
14
|
let provider: FakeOrderProvider;
|
|
@@ -22,7 +19,8 @@ describe('Fake Order Provider', () => {
|
|
|
22
19
|
provider = new FakeOrderProvider(
|
|
23
20
|
getFakerTestConfiguration(),
|
|
24
21
|
new NoOpCache(),
|
|
25
|
-
reqCtx
|
|
22
|
+
reqCtx,
|
|
23
|
+
new FakeOrderFactory(OrderSchema),
|
|
26
24
|
);
|
|
27
25
|
});
|
|
28
26
|
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
} from '@reactionary/core';
|
|
8
8
|
import { getFakerTestConfiguration } from './test-utils.js';
|
|
9
9
|
import { FakePriceProvider } from '../providers/price.provider.js';
|
|
10
|
+
import { FakePriceFactory } from '../factories/index.js';
|
|
10
11
|
import { describe, expect, it, beforeEach, assert } from 'vitest';
|
|
11
12
|
|
|
12
13
|
const testData = {
|
|
@@ -23,7 +24,8 @@ describe('Fake Price Provider', () => {
|
|
|
23
24
|
provider = new FakePriceProvider(
|
|
24
25
|
getFakerTestConfiguration(),
|
|
25
26
|
new NoOpCache(),
|
|
26
|
-
reqCtx
|
|
27
|
+
reqCtx,
|
|
28
|
+
new FakePriceFactory(PriceSchema),
|
|
27
29
|
);
|
|
28
30
|
});
|
|
29
31
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import 'dotenv/config';
|
|
2
2
|
|
|
3
3
|
import type { RequestContext } from '@reactionary/core';
|
|
4
|
-
import { createInitialRequestContext, MemoryCache } from '@reactionary/core';
|
|
4
|
+
import { createInitialRequestContext, MemoryCache, ProductSchema } from '@reactionary/core';
|
|
5
5
|
import { getFakerTestConfiguration } from './test-utils.js';
|
|
6
6
|
import { FakeProductProvider } from '../providers/index.js';
|
|
7
|
+
import { FakeProductFactory } from '../factories/index.js';
|
|
7
8
|
import { describe, expect, it, beforeEach, assert } from 'vitest';
|
|
8
9
|
|
|
9
10
|
describe('Fake Product Provider', () => {
|
|
@@ -12,7 +13,12 @@ describe('Fake Product Provider', () => {
|
|
|
12
13
|
|
|
13
14
|
beforeEach( () => {
|
|
14
15
|
reqCtx = createInitialRequestContext();
|
|
15
|
-
provider = new FakeProductProvider(
|
|
16
|
+
provider = new FakeProductProvider(
|
|
17
|
+
getFakerTestConfiguration(),
|
|
18
|
+
new MemoryCache(),
|
|
19
|
+
reqCtx,
|
|
20
|
+
new FakeProductFactory(ProductSchema),
|
|
21
|
+
);
|
|
16
22
|
})
|
|
17
23
|
|
|
18
24
|
it('should cache repeat product lookups by id', async () => {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import 'dotenv/config';
|
|
2
2
|
import type { RequestContext } from '@reactionary/core';
|
|
3
|
-
import { NoOpCache, createInitialRequestContext } from '@reactionary/core';
|
|
3
|
+
import { NoOpCache, ProfileSchema, createInitialRequestContext } from '@reactionary/core';
|
|
4
4
|
import { getFakerTestConfiguration } from './test-utils.js';
|
|
5
5
|
import { describe, expect, it, beforeEach, assert } from 'vitest';
|
|
6
6
|
import { FakeProfileProvider } from '../providers/profile.provider.js';
|
|
7
|
+
import { FakeProfileFactory } from '../factories/index.js';
|
|
7
8
|
|
|
8
9
|
describe('Fake Profile Provider', () => {
|
|
9
10
|
let provider: FakeProfileProvider;
|
|
@@ -14,7 +15,8 @@ describe('Fake Profile Provider', () => {
|
|
|
14
15
|
provider = new FakeProfileProvider(
|
|
15
16
|
getFakerTestConfiguration(),
|
|
16
17
|
new NoOpCache(),
|
|
17
|
-
reqCtx
|
|
18
|
+
reqCtx,
|
|
19
|
+
new FakeProfileFactory(ProfileSchema),
|
|
18
20
|
);
|
|
19
21
|
});
|
|
20
22
|
|
|
@@ -1,16 +1,41 @@
|
|
|
1
|
-
import type { Cache,
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type { Cache, RequestContext } from '@reactionary/core';
|
|
2
|
+
import {
|
|
3
|
+
GoogleAnalyticsCapabilitiesSchema,
|
|
4
|
+
type GoogleAnalyticsCapabilities,
|
|
5
|
+
} from '../schema/capabilities.schema.js';
|
|
6
|
+
import type { GoogleAnalyticsConfiguration } from '../schema/configuration.schema.js';
|
|
7
|
+
import { GoogleAnalyticsAnalyticsProvider } from '../providers/analytics.provider.js';
|
|
8
|
+
import {
|
|
9
|
+
type GoogleAnalyticsClientFromCapabilities,
|
|
10
|
+
resolveProviderOnlyCapability,
|
|
11
|
+
} from './initialize.types.js';
|
|
5
12
|
|
|
6
|
-
export function
|
|
7
|
-
|
|
8
|
-
|
|
13
|
+
export function withGoogleAnalyticsCapabilities<
|
|
14
|
+
T extends GoogleAnalyticsCapabilities,
|
|
15
|
+
>(configuration: GoogleAnalyticsConfiguration, capabilities: T) {
|
|
16
|
+
return (
|
|
17
|
+
cache: Cache,
|
|
18
|
+
context: RequestContext,
|
|
19
|
+
): GoogleAnalyticsClientFromCapabilities<T> => {
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
+
const client: any = {};
|
|
22
|
+
const caps = GoogleAnalyticsCapabilitiesSchema.parse(capabilities);
|
|
9
23
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
24
|
+
if (caps.analytics?.enabled) {
|
|
25
|
+
client.analytics = resolveProviderOnlyCapability(
|
|
26
|
+
capabilities.analytics,
|
|
27
|
+
(args) => new GoogleAnalyticsAnalyticsProvider(args.cache, args.context, args.config),
|
|
28
|
+
{
|
|
29
|
+
cache,
|
|
30
|
+
context,
|
|
31
|
+
config: configuration,
|
|
32
|
+
},
|
|
33
|
+
);
|
|
34
|
+
}
|
|
13
35
|
|
|
14
|
-
|
|
15
|
-
|
|
36
|
+
return client;
|
|
37
|
+
};
|
|
16
38
|
}
|
|
39
|
+
|
|
40
|
+
// Backward-compatibility alias.
|
|
41
|
+
export const googleAnalyticsCapabilities = withGoogleAnalyticsCapabilities;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ClientFromCapabilities } from '@reactionary/core';
|
|
2
|
+
import type { GoogleAnalyticsCapabilities } from '../schema/capabilities.schema.js';
|
|
3
|
+
import type { GoogleAnalyticsAnalyticsProvider } from '../providers/analytics.provider.js';
|
|
4
|
+
|
|
5
|
+
type EnabledCapability<TCapability> =
|
|
6
|
+
TCapability extends { enabled: true } ? true : false;
|
|
7
|
+
|
|
8
|
+
type NormalizeConfiguredCapabilities<T extends GoogleAnalyticsCapabilities> =
|
|
9
|
+
Omit<T, 'analytics'> & {
|
|
10
|
+
analytics?: EnabledCapability<T['analytics']>;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
type ExtractCapabilityProvider<TCapability, TDefaultProvider> =
|
|
14
|
+
TCapability extends { enabled: true; provider?: infer TProviderFactory }
|
|
15
|
+
? TProviderFactory extends (...args: unknown[]) => infer TProvider
|
|
16
|
+
? TProvider
|
|
17
|
+
: TDefaultProvider
|
|
18
|
+
: TDefaultProvider;
|
|
19
|
+
|
|
20
|
+
type CapabilityOverride<
|
|
21
|
+
TCapability,
|
|
22
|
+
TKey extends string,
|
|
23
|
+
TProvider,
|
|
24
|
+
> = TCapability extends { enabled: true }
|
|
25
|
+
? { [K in TKey]: TProvider }
|
|
26
|
+
: Record<never, never>;
|
|
27
|
+
|
|
28
|
+
type AnalyticsProviderFor<T extends GoogleAnalyticsCapabilities> =
|
|
29
|
+
ExtractCapabilityProvider<T['analytics'], GoogleAnalyticsAnalyticsProvider>;
|
|
30
|
+
|
|
31
|
+
export type GoogleAnalyticsClientFromCapabilities<
|
|
32
|
+
T extends GoogleAnalyticsCapabilities,
|
|
33
|
+
> = Omit<ClientFromCapabilities<NormalizeConfiguredCapabilities<T>>, 'analytics'> &
|
|
34
|
+
CapabilityOverride<T['analytics'], 'analytics', AnalyticsProviderFor<T>>;
|
|
35
|
+
|
|
36
|
+
export function resolveProviderOnlyCapability<TProvider, TProviderArgs>(
|
|
37
|
+
capability:
|
|
38
|
+
| {
|
|
39
|
+
provider?: (args: TProviderArgs) => TProvider;
|
|
40
|
+
}
|
|
41
|
+
| undefined,
|
|
42
|
+
defaultProvider: (args: TProviderArgs) => TProvider,
|
|
43
|
+
args: TProviderArgs,
|
|
44
|
+
): TProvider {
|
|
45
|
+
const provider = capability?.provider ?? defaultProvider;
|
|
46
|
+
return provider(args);
|
|
47
|
+
}
|
|
@@ -1,10 +1,36 @@
|
|
|
1
|
+
import type { AnalyticsProvider, Cache, RequestContext } from '@reactionary/core';
|
|
1
2
|
import { CapabilitiesSchema } from '@reactionary/core';
|
|
2
|
-
import type
|
|
3
|
+
import type { GoogleAnalyticsConfiguration } from './configuration.schema.js';
|
|
4
|
+
import * as z from 'zod';
|
|
5
|
+
|
|
6
|
+
const AnalyticsCapabilitySchema = z.looseObject({
|
|
7
|
+
enabled: z.boolean(),
|
|
8
|
+
provider: z.unknown().optional(),
|
|
9
|
+
});
|
|
3
10
|
|
|
4
11
|
export const GoogleAnalyticsCapabilitiesSchema = CapabilitiesSchema.pick({
|
|
5
12
|
analytics: true,
|
|
6
|
-
})
|
|
13
|
+
})
|
|
14
|
+
.extend({
|
|
15
|
+
analytics: AnalyticsCapabilitySchema.optional(),
|
|
16
|
+
})
|
|
17
|
+
.partial();
|
|
18
|
+
|
|
19
|
+
export interface GoogleAnalyticsProviderFactoryArgs {
|
|
20
|
+
cache: Cache;
|
|
21
|
+
context: RequestContext;
|
|
22
|
+
config: GoogleAnalyticsConfiguration;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface GoogleAnalyticsAnalyticsCapabilityConfig<
|
|
26
|
+
TProvider extends AnalyticsProvider = AnalyticsProvider,
|
|
27
|
+
> {
|
|
28
|
+
enabled: boolean;
|
|
29
|
+
provider?: (args: GoogleAnalyticsProviderFactoryArgs) => TProvider;
|
|
30
|
+
}
|
|
7
31
|
|
|
8
|
-
export type GoogleAnalyticsCapabilities
|
|
9
|
-
|
|
10
|
-
|
|
32
|
+
export type GoogleAnalyticsCapabilities<
|
|
33
|
+
TAnalyticsProvider extends AnalyticsProvider = AnalyticsProvider,
|
|
34
|
+
> = {
|
|
35
|
+
analytics?: GoogleAnalyticsAnalyticsCapabilityConfig<TAnalyticsProvider>;
|
|
36
|
+
};
|