@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,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
AddressSchema,
|
|
2
3
|
ProfileMutationAddShippingAddressSchema,
|
|
3
4
|
ProfileMutationMakeShippingAddressDefaultSchema,
|
|
4
5
|
ProfileMutationRemoveShippingAddressSchema,
|
|
@@ -10,9 +11,13 @@ import {
|
|
|
10
11
|
ProfileSchema,
|
|
11
12
|
Reactionary,
|
|
12
13
|
type Cache,
|
|
14
|
+
type Address,
|
|
13
15
|
type IdentityIdentifier,
|
|
14
16
|
type NotFoundError,
|
|
15
17
|
type Profile,
|
|
18
|
+
type ProfileFactory,
|
|
19
|
+
type ProfileFactoryOutput,
|
|
20
|
+
type ProfileFactoryWithOutput,
|
|
16
21
|
type ProfileMutationAddShippingAddress,
|
|
17
22
|
type ProfileMutationMakeShippingAddressDefault,
|
|
18
23
|
type ProfileMutationRemoveShippingAddress,
|
|
@@ -26,15 +31,20 @@ import {
|
|
|
26
31
|
} from '@reactionary/core';
|
|
27
32
|
import type { FakeConfiguration } from '../schema/configuration.schema.js';
|
|
28
33
|
import { base, en, Faker } from '@faker-js/faker';
|
|
34
|
+
import type { FakeProfileFactory } from '../factories/profile/profile.factory.js';
|
|
29
35
|
|
|
30
|
-
export class FakeProfileProvider
|
|
36
|
+
export class FakeProfileProvider<
|
|
37
|
+
TFactory extends ProfileFactory = FakeProfileFactory,
|
|
38
|
+
> extends ProfileProvider<ProfileFactoryOutput<TFactory>> {
|
|
31
39
|
protected config: FakeConfiguration;
|
|
40
|
+
protected factory: ProfileFactoryWithOutput<TFactory>;
|
|
32
41
|
private generator: Faker;
|
|
33
42
|
|
|
34
43
|
constructor(
|
|
35
44
|
config: FakeConfiguration,
|
|
36
45
|
cache: Cache,
|
|
37
|
-
context: RequestContext
|
|
46
|
+
context: RequestContext,
|
|
47
|
+
factory: ProfileFactoryWithOutput<TFactory>,
|
|
38
48
|
) {
|
|
39
49
|
super(cache, context);
|
|
40
50
|
this.generator = new Faker({
|
|
@@ -42,30 +52,21 @@ export class FakeProfileProvider extends ProfileProvider {
|
|
|
42
52
|
seed: config.seeds.product,
|
|
43
53
|
});
|
|
44
54
|
this.config = config;
|
|
55
|
+
this.factory = factory;
|
|
45
56
|
}
|
|
46
57
|
|
|
47
|
-
@Reactionary({
|
|
48
|
-
inputSchema: ProfileQueryByIdSchema,
|
|
49
|
-
outputSchema: ProfileSchema,
|
|
50
|
-
})
|
|
58
|
+
@Reactionary({ inputSchema: ProfileQueryByIdSchema, outputSchema: ProfileSchema })
|
|
51
59
|
public override async getById(
|
|
52
|
-
payload: ProfileQuerySelf
|
|
53
|
-
): Promise<Result<
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return success(profile);
|
|
60
|
+
payload: ProfileQuerySelf,
|
|
61
|
+
): Promise<Result<ProfileFactoryOutput<TFactory>, NotFoundError>> {
|
|
62
|
+
return success(this.composeProfile(payload.identifier));
|
|
57
63
|
}
|
|
58
64
|
|
|
59
|
-
@Reactionary({
|
|
60
|
-
inputSchema: ProfileMutationUpdateSchema,
|
|
61
|
-
outputSchema: ProfileSchema,
|
|
62
|
-
})
|
|
65
|
+
@Reactionary({ inputSchema: ProfileMutationUpdateSchema, outputSchema: ProfileSchema })
|
|
63
66
|
public override async update(
|
|
64
|
-
payload: ProfileMutationUpdate
|
|
65
|
-
): Promise<Result<
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return success(profile);
|
|
67
|
+
payload: ProfileMutationUpdate,
|
|
68
|
+
): Promise<Result<ProfileFactoryOutput<TFactory>, NotFoundError>> {
|
|
69
|
+
return success(this.composeProfile(payload.identifier));
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
@Reactionary({
|
|
@@ -73,11 +74,9 @@ export class FakeProfileProvider extends ProfileProvider {
|
|
|
73
74
|
outputSchema: ProfileSchema,
|
|
74
75
|
})
|
|
75
76
|
public override async addShippingAddress(
|
|
76
|
-
payload: ProfileMutationAddShippingAddress
|
|
77
|
-
): Promise<Result<
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return success(profile);
|
|
77
|
+
payload: ProfileMutationAddShippingAddress,
|
|
78
|
+
): Promise<Result<ProfileFactoryOutput<TFactory>, NotFoundError>> {
|
|
79
|
+
return success(this.composeProfile(payload.identifier));
|
|
81
80
|
}
|
|
82
81
|
|
|
83
82
|
@Reactionary({
|
|
@@ -85,11 +84,9 @@ export class FakeProfileProvider extends ProfileProvider {
|
|
|
85
84
|
outputSchema: ProfileSchema,
|
|
86
85
|
})
|
|
87
86
|
public override async updateShippingAddress(
|
|
88
|
-
payload: ProfileMutationUpdateShippingAddress
|
|
89
|
-
): Promise<Result<
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return success(profile);
|
|
87
|
+
payload: ProfileMutationUpdateShippingAddress,
|
|
88
|
+
): Promise<Result<ProfileFactoryOutput<TFactory>, NotFoundError>> {
|
|
89
|
+
return success(this.composeProfile(payload.identifier));
|
|
93
90
|
}
|
|
94
91
|
|
|
95
92
|
@Reactionary({
|
|
@@ -97,11 +94,9 @@ export class FakeProfileProvider extends ProfileProvider {
|
|
|
97
94
|
outputSchema: ProfileSchema,
|
|
98
95
|
})
|
|
99
96
|
public override async removeShippingAddress(
|
|
100
|
-
payload: ProfileMutationRemoveShippingAddress
|
|
101
|
-
): Promise<Result<
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return success(profile);
|
|
97
|
+
payload: ProfileMutationRemoveShippingAddress,
|
|
98
|
+
): Promise<Result<ProfileFactoryOutput<TFactory>, NotFoundError>> {
|
|
99
|
+
return success(this.composeProfile(payload.identifier));
|
|
105
100
|
}
|
|
106
101
|
|
|
107
102
|
@Reactionary({
|
|
@@ -109,11 +104,9 @@ export class FakeProfileProvider extends ProfileProvider {
|
|
|
109
104
|
outputSchema: ProfileSchema,
|
|
110
105
|
})
|
|
111
106
|
public override async makeShippingAddressDefault(
|
|
112
|
-
payload: ProfileMutationMakeShippingAddressDefault
|
|
113
|
-
): Promise<Result<
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return success(profile);
|
|
107
|
+
payload: ProfileMutationMakeShippingAddressDefault,
|
|
108
|
+
): Promise<Result<ProfileFactoryOutput<TFactory>, NotFoundError>> {
|
|
109
|
+
return success(this.composeProfile(payload.identifier));
|
|
117
110
|
}
|
|
118
111
|
|
|
119
112
|
@Reactionary({
|
|
@@ -121,27 +114,41 @@ export class FakeProfileProvider extends ProfileProvider {
|
|
|
121
114
|
outputSchema: ProfileSchema,
|
|
122
115
|
})
|
|
123
116
|
public override async setBillingAddress(
|
|
124
|
-
payload: ProfileMutationSetBillingAddress
|
|
125
|
-
): Promise<Result<
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
return success(profile);
|
|
117
|
+
payload: ProfileMutationSetBillingAddress,
|
|
118
|
+
): Promise<Result<ProfileFactoryOutput<TFactory>, NotFoundError>> {
|
|
119
|
+
return success(this.composeProfile(payload.identifier));
|
|
129
120
|
}
|
|
130
121
|
|
|
131
|
-
protected
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
createdAt: this.generator.date.past().toISOString(),
|
|
122
|
+
protected composeProfile(identifier: IdentityIdentifier): ProfileFactoryOutput<TFactory> {
|
|
123
|
+
const baseProfile = {
|
|
124
|
+
identifier,
|
|
135
125
|
email: this.generator.internet.email(),
|
|
136
|
-
emailVerified: true,
|
|
137
|
-
identifier: identifier || {
|
|
138
|
-
userId: this.generator.string.uuid(),
|
|
139
|
-
},
|
|
140
126
|
phone: this.generator.phone.number(),
|
|
127
|
+
emailVerified: true,
|
|
141
128
|
phoneVerified: true,
|
|
142
|
-
|
|
129
|
+
createdAt: this.generator.date.past().toISOString(),
|
|
130
|
+
updatedAt: this.generator.date.recent().toISOString(),
|
|
131
|
+
billingAddress: this.createEmptyAddress(),
|
|
132
|
+
shippingAddress: this.createEmptyAddress(),
|
|
133
|
+
alternateShippingAddresses: [],
|
|
143
134
|
} satisfies Profile;
|
|
144
135
|
|
|
145
|
-
return
|
|
136
|
+
return this.factory.parseProfile(this.context, baseProfile);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
protected createEmptyAddress(): Address {
|
|
140
|
+
return AddressSchema.parse({
|
|
141
|
+
identifier: {
|
|
142
|
+
nickName: this.generator.person.firstName().toLowerCase(),
|
|
143
|
+
},
|
|
144
|
+
firstName: this.generator.person.firstName(),
|
|
145
|
+
lastName: this.generator.person.lastName(),
|
|
146
|
+
streetAddress: this.generator.location.street(),
|
|
147
|
+
streetNumber: this.generator.location.buildingNumber(),
|
|
148
|
+
city: this.generator.location.city(),
|
|
149
|
+
region: this.generator.location.state(),
|
|
150
|
+
postalCode: this.generator.location.zipCode(),
|
|
151
|
+
countryCode: this.generator.location.countryCode('alpha-2'),
|
|
152
|
+
});
|
|
146
153
|
}
|
|
147
154
|
}
|
|
@@ -2,53 +2,69 @@ import type {
|
|
|
2
2
|
Cache,
|
|
3
3
|
FulfillmentCenterIdentifier,
|
|
4
4
|
RequestContext,
|
|
5
|
-
|
|
5
|
+
Result,
|
|
6
|
+
StoreFactory,
|
|
7
|
+
StoreFactoryOutput,
|
|
8
|
+
StoreFactoryWithOutput,
|
|
6
9
|
StoreIdentifier,
|
|
7
10
|
StoreQueryByProximity,
|
|
8
|
-
Result
|
|
9
11
|
} from '@reactionary/core';
|
|
10
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
Reactionary,
|
|
14
|
+
StoreProvider,
|
|
15
|
+
StoreQueryByProximitySchema,
|
|
16
|
+
StoreSchema,
|
|
17
|
+
success,
|
|
18
|
+
} from '@reactionary/core';
|
|
11
19
|
import * as z from 'zod';
|
|
12
20
|
import type { FakeConfiguration } from '../schema/configuration.schema.js';
|
|
13
21
|
import { base, en, Faker } from '@faker-js/faker';
|
|
22
|
+
import type { FakeStoreFactory } from '../factories/store/store.factory.js';
|
|
14
23
|
|
|
15
|
-
export class FakeStoreProvider
|
|
24
|
+
export class FakeStoreProvider<
|
|
25
|
+
TFactory extends StoreFactory = FakeStoreFactory,
|
|
26
|
+
> extends StoreProvider<StoreFactoryOutput<TFactory>> {
|
|
16
27
|
protected config: FakeConfiguration;
|
|
28
|
+
protected factory: StoreFactoryWithOutput<TFactory>;
|
|
17
29
|
|
|
18
|
-
constructor(
|
|
30
|
+
constructor(
|
|
31
|
+
config: FakeConfiguration,
|
|
32
|
+
cache: Cache,
|
|
33
|
+
context: RequestContext,
|
|
34
|
+
factory: StoreFactoryWithOutput<TFactory>,
|
|
35
|
+
) {
|
|
19
36
|
super(cache, context);
|
|
20
37
|
|
|
21
38
|
this.config = config;
|
|
39
|
+
this.factory = factory;
|
|
22
40
|
}
|
|
23
41
|
|
|
24
42
|
@Reactionary({
|
|
25
43
|
inputSchema: StoreQueryByProximitySchema,
|
|
26
|
-
outputSchema: z.array(StoreSchema)
|
|
44
|
+
outputSchema: z.array(StoreSchema),
|
|
27
45
|
})
|
|
28
46
|
public override async queryByProximity(
|
|
29
|
-
payload: StoreQueryByProximity
|
|
30
|
-
): Promise<Result<
|
|
47
|
+
payload: StoreQueryByProximity,
|
|
48
|
+
): Promise<Result<StoreFactoryOutput<TFactory>[]>> {
|
|
31
49
|
const generator = new Faker({
|
|
32
50
|
seed: 42,
|
|
33
51
|
locale: [en, base],
|
|
34
52
|
});
|
|
35
53
|
|
|
36
|
-
const results =
|
|
54
|
+
const results: StoreFactoryOutput<TFactory>[] = [];
|
|
37
55
|
|
|
38
56
|
for (let i = 0; i < payload.limit; i++) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
name
|
|
51
|
-
});
|
|
57
|
+
results.push(
|
|
58
|
+
this.factory.parseStore(this.context, {
|
|
59
|
+
identifier: {
|
|
60
|
+
key: `${i}`,
|
|
61
|
+
} satisfies StoreIdentifier,
|
|
62
|
+
fulfillmentCenter: {
|
|
63
|
+
key: `${i}`,
|
|
64
|
+
} satisfies FulfillmentCenterIdentifier,
|
|
65
|
+
name: generator.company.name(),
|
|
66
|
+
}),
|
|
67
|
+
);
|
|
52
68
|
}
|
|
53
69
|
|
|
54
70
|
return success(results);
|
|
@@ -1,21 +1,178 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type {
|
|
2
|
+
Cache,
|
|
3
|
+
CartFactory,
|
|
4
|
+
CartFactoryWithOutput,
|
|
5
|
+
CartProvider,
|
|
6
|
+
CategoryFactory,
|
|
7
|
+
CategoryFactoryWithOutput,
|
|
8
|
+
CategoryProvider,
|
|
9
|
+
CheckoutFactory,
|
|
10
|
+
CheckoutFactoryWithOutput,
|
|
11
|
+
CheckoutProvider,
|
|
12
|
+
IdentityFactory,
|
|
13
|
+
IdentityFactoryWithOutput,
|
|
14
|
+
IdentityProvider,
|
|
15
|
+
InventoryFactory,
|
|
16
|
+
InventoryFactoryWithOutput,
|
|
17
|
+
InventoryProvider,
|
|
18
|
+
OrderFactory,
|
|
19
|
+
OrderFactoryWithOutput,
|
|
20
|
+
OrderProvider,
|
|
21
|
+
OrderSearchFactory,
|
|
22
|
+
OrderSearchFactoryWithOutput,
|
|
23
|
+
OrderSearchProvider,
|
|
24
|
+
PriceFactory,
|
|
25
|
+
PriceFactoryWithOutput,
|
|
26
|
+
PriceProvider,
|
|
27
|
+
ProductAssociationsFactory,
|
|
28
|
+
ProductAssociationsFactoryWithOutput,
|
|
29
|
+
ProductAssociationsProvider,
|
|
30
|
+
ProductFactory,
|
|
31
|
+
ProductFactoryWithOutput,
|
|
32
|
+
ProductProvider,
|
|
33
|
+
ProductReviewsFactory,
|
|
34
|
+
ProductReviewsFactoryWithOutput,
|
|
35
|
+
ProductReviewsProvider,
|
|
36
|
+
ProductSearchFactory,
|
|
37
|
+
ProductSearchFactoryWithOutput,
|
|
38
|
+
ProductSearchProvider,
|
|
39
|
+
ProfileFactory,
|
|
40
|
+
ProfileFactoryWithOutput,
|
|
41
|
+
ProfileProvider,
|
|
42
|
+
RequestContext,
|
|
43
|
+
StoreFactory,
|
|
44
|
+
StoreFactoryWithOutput,
|
|
45
|
+
StoreProvider,
|
|
46
|
+
} from '@reactionary/core';
|
|
47
|
+
import { CapabilitiesSchema } from '@reactionary/core';
|
|
48
|
+
import type { FakeConfiguration } from './configuration.schema.js';
|
|
49
|
+
import * as z from 'zod';
|
|
50
|
+
|
|
51
|
+
const OverridableCapabilitySchema = z.looseObject({
|
|
52
|
+
enabled: z.boolean(),
|
|
53
|
+
factory: z.unknown().optional(),
|
|
54
|
+
provider: z.unknown().optional(),
|
|
55
|
+
});
|
|
3
56
|
|
|
4
57
|
export const FakeCapabilitiesSchema = CapabilitiesSchema.pick({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
})
|
|
58
|
+
product: true,
|
|
59
|
+
productSearch: true,
|
|
60
|
+
identity: true,
|
|
61
|
+
category: true,
|
|
62
|
+
cart: true,
|
|
63
|
+
inventory: true,
|
|
64
|
+
store: true,
|
|
65
|
+
price: true,
|
|
66
|
+
checkout: true,
|
|
67
|
+
order: true,
|
|
68
|
+
orderSearch: true,
|
|
69
|
+
profile: true,
|
|
70
|
+
productReviews: true,
|
|
71
|
+
productAssociations: true,
|
|
72
|
+
})
|
|
73
|
+
.extend({
|
|
74
|
+
product: OverridableCapabilitySchema.optional(),
|
|
75
|
+
productSearch: OverridableCapabilitySchema.optional(),
|
|
76
|
+
identity: OverridableCapabilitySchema.optional(),
|
|
77
|
+
category: OverridableCapabilitySchema.optional(),
|
|
78
|
+
cart: OverridableCapabilitySchema.optional(),
|
|
79
|
+
inventory: OverridableCapabilitySchema.optional(),
|
|
80
|
+
store: OverridableCapabilitySchema.optional(),
|
|
81
|
+
price: OverridableCapabilitySchema.optional(),
|
|
82
|
+
checkout: OverridableCapabilitySchema.optional(),
|
|
83
|
+
order: OverridableCapabilitySchema.optional(),
|
|
84
|
+
orderSearch: OverridableCapabilitySchema.optional(),
|
|
85
|
+
profile: OverridableCapabilitySchema.optional(),
|
|
86
|
+
productReviews: OverridableCapabilitySchema.optional(),
|
|
87
|
+
productAssociations: OverridableCapabilitySchema.optional(),
|
|
88
|
+
})
|
|
89
|
+
.partial();
|
|
90
|
+
|
|
91
|
+
export interface FakeCapabilityProviderFactoryArgs<TFactory> {
|
|
92
|
+
cache: Cache;
|
|
93
|
+
context: RequestContext;
|
|
94
|
+
config: FakeConfiguration;
|
|
95
|
+
factory: TFactory;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface FakeCapabilityConfig<TFactory, TProvider> {
|
|
99
|
+
enabled: boolean;
|
|
100
|
+
factory?: TFactory;
|
|
101
|
+
provider?: (args: FakeCapabilityProviderFactoryArgs<TFactory>) => TProvider;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export type FakeProductCapabilityConfig = FakeCapabilityConfig<
|
|
105
|
+
ProductFactoryWithOutput<ProductFactory>,
|
|
106
|
+
ProductProvider
|
|
107
|
+
>;
|
|
108
|
+
export type FakeProductSearchCapabilityConfig = FakeCapabilityConfig<
|
|
109
|
+
ProductSearchFactoryWithOutput<ProductSearchFactory>,
|
|
110
|
+
ProductSearchProvider
|
|
111
|
+
>;
|
|
112
|
+
export type FakeIdentityCapabilityConfig = FakeCapabilityConfig<
|
|
113
|
+
IdentityFactoryWithOutput<IdentityFactory>,
|
|
114
|
+
IdentityProvider
|
|
115
|
+
>;
|
|
116
|
+
export type FakeCategoryCapabilityConfig = FakeCapabilityConfig<
|
|
117
|
+
CategoryFactoryWithOutput<CategoryFactory>,
|
|
118
|
+
CategoryProvider
|
|
119
|
+
>;
|
|
120
|
+
export type FakeCartCapabilityConfig = FakeCapabilityConfig<
|
|
121
|
+
CartFactoryWithOutput<CartFactory>,
|
|
122
|
+
CartProvider
|
|
123
|
+
>;
|
|
124
|
+
export type FakeInventoryCapabilityConfig = FakeCapabilityConfig<
|
|
125
|
+
InventoryFactoryWithOutput<InventoryFactory>,
|
|
126
|
+
InventoryProvider
|
|
127
|
+
>;
|
|
128
|
+
export type FakeStoreCapabilityConfig = FakeCapabilityConfig<
|
|
129
|
+
StoreFactoryWithOutput<StoreFactory>,
|
|
130
|
+
StoreProvider
|
|
131
|
+
>;
|
|
132
|
+
export type FakePriceCapabilityConfig = FakeCapabilityConfig<
|
|
133
|
+
PriceFactoryWithOutput<PriceFactory>,
|
|
134
|
+
PriceProvider
|
|
135
|
+
>;
|
|
136
|
+
export type FakeCheckoutCapabilityConfig = FakeCapabilityConfig<
|
|
137
|
+
CheckoutFactoryWithOutput<CheckoutFactory>,
|
|
138
|
+
CheckoutProvider
|
|
139
|
+
>;
|
|
140
|
+
export type FakeOrderCapabilityConfig = FakeCapabilityConfig<
|
|
141
|
+
OrderFactoryWithOutput<OrderFactory>,
|
|
142
|
+
OrderProvider
|
|
143
|
+
>;
|
|
144
|
+
export type FakeOrderSearchCapabilityConfig = FakeCapabilityConfig<
|
|
145
|
+
OrderSearchFactoryWithOutput<OrderSearchFactory>,
|
|
146
|
+
OrderSearchProvider
|
|
147
|
+
>;
|
|
148
|
+
export type FakeProfileCapabilityConfig = FakeCapabilityConfig<
|
|
149
|
+
ProfileFactoryWithOutput<ProfileFactory>,
|
|
150
|
+
ProfileProvider
|
|
151
|
+
>;
|
|
152
|
+
export type FakeProductReviewsCapabilityConfig = FakeCapabilityConfig<
|
|
153
|
+
ProductReviewsFactoryWithOutput<ProductReviewsFactory>,
|
|
154
|
+
ProductReviewsProvider
|
|
155
|
+
>;
|
|
156
|
+
export type FakeProductAssociationsCapabilityConfig = FakeCapabilityConfig<
|
|
157
|
+
ProductAssociationsFactoryWithOutput<ProductAssociationsFactory>,
|
|
158
|
+
ProductAssociationsProvider
|
|
159
|
+
>;
|
|
160
|
+
|
|
161
|
+
export type FakeCapabilities = {
|
|
162
|
+
product?: FakeProductCapabilityConfig;
|
|
163
|
+
productSearch?: FakeProductSearchCapabilityConfig;
|
|
164
|
+
identity?: FakeIdentityCapabilityConfig;
|
|
165
|
+
category?: FakeCategoryCapabilityConfig;
|
|
166
|
+
cart?: FakeCartCapabilityConfig;
|
|
167
|
+
inventory?: FakeInventoryCapabilityConfig;
|
|
168
|
+
store?: FakeStoreCapabilityConfig;
|
|
169
|
+
price?: FakePriceCapabilityConfig;
|
|
170
|
+
checkout?: FakeCheckoutCapabilityConfig;
|
|
171
|
+
order?: FakeOrderCapabilityConfig;
|
|
172
|
+
orderSearch?: FakeOrderSearchCapabilityConfig;
|
|
173
|
+
profile?: FakeProfileCapabilityConfig;
|
|
174
|
+
productReviews?: FakeProductReviewsCapabilityConfig;
|
|
175
|
+
productAssociations?: FakeProductAssociationsCapabilityConfig;
|
|
176
|
+
};
|
|
20
177
|
|
|
21
|
-
export type
|
|
178
|
+
export type ParsedFakeCapabilities = z.infer<typeof FakeCapabilitiesSchema>;
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import 'dotenv/config';
|
|
2
2
|
import type { RequestContext} from '@reactionary/core';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
CartIdentifierSchema,
|
|
5
|
+
CartSchema,
|
|
6
|
+
IdentitySchema,
|
|
7
|
+
NoOpCache,
|
|
8
|
+
createInitialRequestContext,
|
|
9
|
+
} from '@reactionary/core';
|
|
4
10
|
import { getFakerTestConfiguration } from './test-utils.js';
|
|
5
11
|
import { FakeCartProvider } from '../providers/cart.provider.js';
|
|
6
12
|
import { FakeIdentityProvider } from '../providers/index.js';
|
|
13
|
+
import { FakeCartFactory, FakeIdentityFactory } from '../factories/index.js';
|
|
7
14
|
import { describe, expect, it, beforeAll, beforeEach, assert } from 'vitest';
|
|
8
15
|
|
|
9
16
|
const testData = {
|
|
@@ -18,8 +25,18 @@ describe('Fake Cart Provider', () => {
|
|
|
18
25
|
|
|
19
26
|
beforeEach( () => {
|
|
20
27
|
reqCtx = createInitialRequestContext();
|
|
21
|
-
provider = new FakeCartProvider(
|
|
22
|
-
|
|
28
|
+
provider = new FakeCartProvider(
|
|
29
|
+
getFakerTestConfiguration(),
|
|
30
|
+
new NoOpCache(),
|
|
31
|
+
reqCtx,
|
|
32
|
+
new FakeCartFactory(CartSchema, CartIdentifierSchema),
|
|
33
|
+
);
|
|
34
|
+
identityProvider = new FakeIdentityProvider(
|
|
35
|
+
getFakerTestConfiguration(),
|
|
36
|
+
new NoOpCache(),
|
|
37
|
+
reqCtx,
|
|
38
|
+
new FakeIdentityFactory(IdentitySchema),
|
|
39
|
+
);
|
|
23
40
|
});
|
|
24
41
|
|
|
25
42
|
describe('anonymous sessions', () => {
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import 'dotenv/config';
|
|
2
2
|
import type { RequestContext } from '@reactionary/core';
|
|
3
3
|
import {
|
|
4
|
+
CategoryPaginatedResultSchema,
|
|
4
5
|
CategorySchema,
|
|
5
6
|
MemoryCache,
|
|
6
7
|
createInitialRequestContext,
|
|
7
8
|
} from '@reactionary/core';
|
|
8
9
|
import { FakeCategoryProvider } from '../providers/index.js';
|
|
10
|
+
import { FakeCategoryFactory } from '../factories/index.js';
|
|
9
11
|
import { getFakerTestConfiguration } from './test-utils.js';
|
|
10
12
|
import { describe, expect, it, beforeAll, beforeEach, assert } from 'vitest';
|
|
11
13
|
|
|
@@ -21,7 +23,8 @@ describe('Faker Category Provider', () => {
|
|
|
21
23
|
provider = new FakeCategoryProvider(
|
|
22
24
|
getFakerTestConfiguration(),
|
|
23
25
|
cache,
|
|
24
|
-
reqCtx
|
|
26
|
+
reqCtx,
|
|
27
|
+
new FakeCategoryFactory(CategorySchema, CategoryPaginatedResultSchema),
|
|
25
28
|
);
|
|
26
29
|
});
|
|
27
30
|
|
|
@@ -2,11 +2,15 @@ import 'dotenv/config';
|
|
|
2
2
|
import type { RequestContext } from '@reactionary/core';
|
|
3
3
|
import {
|
|
4
4
|
NoOpCache,
|
|
5
|
+
CheckoutSchema,
|
|
6
|
+
ShippingMethodSchema,
|
|
7
|
+
PaymentMethodSchema,
|
|
5
8
|
createInitialRequestContext,
|
|
6
9
|
} from '@reactionary/core';
|
|
7
10
|
import { getFakerTestConfiguration } from './test-utils.js';
|
|
8
11
|
import { describe, expect, it, beforeEach, assert } from 'vitest';
|
|
9
12
|
import { FakeCheckoutProvider } from '../providers/checkout.provider.js';
|
|
13
|
+
import { FakeCheckoutFactory } from '../factories/index.js';
|
|
10
14
|
|
|
11
15
|
describe('Fake Checkout Provider', () => {
|
|
12
16
|
let provider: FakeCheckoutProvider;
|
|
@@ -17,7 +21,12 @@ describe('Fake Checkout Provider', () => {
|
|
|
17
21
|
provider = new FakeCheckoutProvider(
|
|
18
22
|
getFakerTestConfiguration(),
|
|
19
23
|
new NoOpCache(),
|
|
20
|
-
reqCtx
|
|
24
|
+
reqCtx,
|
|
25
|
+
new FakeCheckoutFactory(
|
|
26
|
+
CheckoutSchema,
|
|
27
|
+
ShippingMethodSchema,
|
|
28
|
+
PaymentMethodSchema,
|
|
29
|
+
),
|
|
21
30
|
);
|
|
22
31
|
});
|
|
23
32
|
|
|
@@ -177,7 +186,8 @@ describe('Fake Checkout Provider', () => {
|
|
|
177
186
|
},
|
|
178
187
|
userId: {
|
|
179
188
|
userId: 'Fake'
|
|
180
|
-
}
|
|
189
|
+
},
|
|
190
|
+
appliedPromotions: [],
|
|
181
191
|
},
|
|
182
192
|
});
|
|
183
193
|
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ClientBuilder,
|
|
3
|
+
NoOpCache,
|
|
4
|
+
ProductSchema,
|
|
5
|
+
createInitialRequestContext,
|
|
6
|
+
type RequestContext,
|
|
7
|
+
} from '@reactionary/core';
|
|
8
|
+
import * as z from 'zod';
|
|
9
|
+
import { withFakeCapabilities } from '../core/initialize.js';
|
|
10
|
+
import type { FakeConfiguration } from '../schema/configuration.schema.js';
|
|
11
|
+
import { FakeProductFactory } from '../factories/product/product.factory.js';
|
|
12
|
+
|
|
13
|
+
const assertType = <T>(_value: T) => {
|
|
14
|
+
void _value;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type IsAny<T> = 0 extends (1 & T) ? true : false;
|
|
18
|
+
const assertNotAny = <T>(_value: IsAny<T> extends true ? never : T) => {
|
|
19
|
+
void _value;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const ExtendedProductSchema = ProductSchema.safeExtend({
|
|
23
|
+
extendedValue: z.string(),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
class ExtendedFakeProductFactory extends FakeProductFactory<typeof ExtendedProductSchema> {
|
|
27
|
+
constructor() {
|
|
28
|
+
super(ExtendedProductSchema);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public override parseProduct(context: RequestContext, data: unknown) {
|
|
32
|
+
const base = super.parseProduct(context, data);
|
|
33
|
+
return this.productSchema.parse({
|
|
34
|
+
...base,
|
|
35
|
+
extendedValue: 'from-fake-factory',
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const config = {
|
|
41
|
+
jitter: {
|
|
42
|
+
mean: 0,
|
|
43
|
+
deviation: 0,
|
|
44
|
+
},
|
|
45
|
+
seeds: {
|
|
46
|
+
product: 1,
|
|
47
|
+
search: 1,
|
|
48
|
+
category: 1,
|
|
49
|
+
},
|
|
50
|
+
} satisfies FakeConfiguration;
|
|
51
|
+
|
|
52
|
+
const client = new ClientBuilder(createInitialRequestContext())
|
|
53
|
+
.withCache(new NoOpCache())
|
|
54
|
+
.withCapability(
|
|
55
|
+
withFakeCapabilities(config, {
|
|
56
|
+
product: {
|
|
57
|
+
enabled: true,
|
|
58
|
+
factory: new ExtendedFakeProductFactory(),
|
|
59
|
+
},
|
|
60
|
+
}),
|
|
61
|
+
)
|
|
62
|
+
.build();
|
|
63
|
+
|
|
64
|
+
client.product
|
|
65
|
+
.getById({
|
|
66
|
+
identifier: { key: 'example-product-id' },
|
|
67
|
+
})
|
|
68
|
+
.then((result) => {
|
|
69
|
+
assertNotAny(result);
|
|
70
|
+
if (result.success) {
|
|
71
|
+
assertNotAny(result.value);
|
|
72
|
+
assertNotAny(result.value.extendedValue);
|
|
73
|
+
assertType<string>(result.value.extendedValue);
|
|
74
|
+
}
|
|
75
|
+
});
|