@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,77 +1,99 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type {
|
|
2
|
+
Cache,
|
|
3
|
+
Category,
|
|
4
|
+
CategoryFactory,
|
|
5
|
+
CategoryFactoryCategoryOutput,
|
|
6
|
+
CategoryFactoryPaginatedOutput,
|
|
7
|
+
CategoryFactoryWithOutput,
|
|
8
|
+
CategoryPaginatedResult,
|
|
9
|
+
CategoryQueryById,
|
|
10
|
+
CategoryQueryBySlug,
|
|
11
|
+
CategoryQueryForBreadcrumb,
|
|
12
|
+
CategoryQueryForChildCategories,
|
|
13
|
+
CategoryQueryForTopCategories,
|
|
14
|
+
NotFoundError,
|
|
15
|
+
RequestContext,
|
|
16
|
+
Result,
|
|
17
|
+
} from '@reactionary/core';
|
|
18
|
+
import {
|
|
19
|
+
CategoryPaginatedResultSchema,
|
|
20
|
+
CategoryProvider,
|
|
21
|
+
CategoryQueryByIdSchema,
|
|
22
|
+
CategoryQueryBySlugSchema,
|
|
23
|
+
CategoryQueryForBreadcrumbSchema,
|
|
24
|
+
CategoryQueryForChildCategoriesSchema,
|
|
25
|
+
CategoryQueryForTopCategoriesSchema,
|
|
26
|
+
CategorySchema,
|
|
27
|
+
Reactionary,
|
|
28
|
+
error,
|
|
29
|
+
success,
|
|
30
|
+
} from '@reactionary/core';
|
|
31
|
+
import type { FakeConfiguration } from '../schema/configuration.schema.js';
|
|
32
|
+
import * as z from 'zod';
|
|
6
33
|
import { Faker, en, base } from '@faker-js/faker';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
34
|
+
import type { FakeCategoryFactory } from '../factories/category/category.factory.js';
|
|
35
|
+
|
|
36
|
+
export class FakeCategoryProvider<
|
|
37
|
+
TFactory extends CategoryFactory = FakeCategoryFactory,
|
|
38
|
+
> extends CategoryProvider<
|
|
39
|
+
CategoryFactoryCategoryOutput<TFactory>,
|
|
40
|
+
CategoryFactoryPaginatedOutput<TFactory>
|
|
41
|
+
> {
|
|
10
42
|
protected config: FakeConfiguration;
|
|
43
|
+
protected factory: CategoryFactoryWithOutput<TFactory>;
|
|
11
44
|
|
|
12
|
-
protected topCategories =
|
|
13
|
-
protected childCategories = new Map<string,
|
|
45
|
+
protected topCategories: Category[] = [];
|
|
46
|
+
protected childCategories = new Map<string, Category[]>();
|
|
14
47
|
protected allCategories = new Map<string, Category>();
|
|
15
48
|
|
|
16
49
|
protected categoryGenerator: Faker;
|
|
17
50
|
|
|
18
51
|
protected generateFakeCategory(parent: Category | undefined, index: number): Category {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} else {
|
|
23
|
-
name = `${parent.name}-${index}`;
|
|
24
|
-
}
|
|
52
|
+
const name = parent
|
|
53
|
+
? `${parent.name}-${index}`
|
|
54
|
+
: this.categoryGenerator.commerce.department();
|
|
25
55
|
|
|
26
56
|
const identifier = { key: name.toLowerCase().replace(/\s+/g, '-') };
|
|
27
|
-
const text = this.categoryGenerator.lorem.sentences(3);
|
|
28
|
-
const slug = identifier.key + '-slug';
|
|
29
|
-
|
|
30
|
-
let parentCategory;
|
|
31
|
-
if (parent) {
|
|
32
|
-
parentCategory = parent.identifier;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
57
|
const category = {
|
|
36
58
|
identifier,
|
|
37
59
|
images: [],
|
|
38
60
|
name,
|
|
39
|
-
slug
|
|
40
|
-
text,
|
|
41
|
-
parentCategory
|
|
61
|
+
slug: `${identifier.key}-slug`,
|
|
62
|
+
text: this.categoryGenerator.lorem.sentences(3),
|
|
63
|
+
parentCategory: parent?.identifier,
|
|
42
64
|
} satisfies Category;
|
|
43
65
|
|
|
44
66
|
this.allCategories.set(identifier.key, category);
|
|
45
67
|
return category;
|
|
46
68
|
}
|
|
47
69
|
|
|
48
|
-
|
|
49
|
-
|
|
70
|
+
constructor(
|
|
71
|
+
config: FakeConfiguration,
|
|
72
|
+
cache: Cache,
|
|
73
|
+
context: RequestContext,
|
|
74
|
+
factory: CategoryFactoryWithOutput<TFactory>,
|
|
75
|
+
) {
|
|
50
76
|
super(cache, context);
|
|
51
77
|
this.config = config;
|
|
78
|
+
this.factory = factory;
|
|
52
79
|
this.categoryGenerator = new Faker({
|
|
53
80
|
seed: this.config.seeds.category,
|
|
54
81
|
locale: [en, base],
|
|
55
82
|
});
|
|
56
83
|
|
|
57
|
-
// Generate some top-level categories
|
|
58
84
|
for (let i = 0; i < 6; i++) {
|
|
59
|
-
|
|
60
|
-
this.topCategories.push(category);
|
|
85
|
+
this.topCategories.push(this.generateFakeCategory(undefined, i));
|
|
61
86
|
}
|
|
62
87
|
|
|
63
|
-
// Generate two levels of child categories
|
|
64
88
|
this.topCategories.forEach((parentCategory) => {
|
|
65
|
-
const children =
|
|
89
|
+
const children: Category[] = [];
|
|
66
90
|
for (let j = 0; j < 5; j++) {
|
|
67
91
|
const childCategory = this.generateFakeCategory(parentCategory, j);
|
|
68
92
|
children.push(childCategory);
|
|
69
93
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const subChildCategory = this.generateFakeCategory(childCategory, k);
|
|
74
|
-
subCategoryChildren.push(subChildCategory);
|
|
94
|
+
const subCategoryChildren: Category[] = [];
|
|
95
|
+
for (let k = 0; k < 5; k++) {
|
|
96
|
+
subCategoryChildren.push(this.generateFakeCategory(childCategory, k));
|
|
75
97
|
}
|
|
76
98
|
this.childCategories.set(childCategory.identifier.key, subCategoryChildren);
|
|
77
99
|
}
|
|
@@ -81,104 +103,97 @@ export class FakeCategoryProvider extends CategoryProvider {
|
|
|
81
103
|
|
|
82
104
|
@Reactionary({
|
|
83
105
|
inputSchema: CategoryQueryByIdSchema,
|
|
84
|
-
outputSchema: CategorySchema
|
|
106
|
+
outputSchema: CategorySchema,
|
|
85
107
|
})
|
|
86
|
-
public override async getById(
|
|
108
|
+
public override async getById(
|
|
109
|
+
payload: CategoryQueryById,
|
|
110
|
+
): Promise<Result<CategoryFactoryCategoryOutput<TFactory>, NotFoundError>> {
|
|
87
111
|
const category = this.allCategories.get(payload.id.key);
|
|
88
112
|
|
|
89
|
-
if(!category) {
|
|
113
|
+
if (!category) {
|
|
90
114
|
return error<NotFoundError>({
|
|
91
115
|
type: 'NotFound',
|
|
92
|
-
identifier: payload
|
|
116
|
+
identifier: payload,
|
|
93
117
|
});
|
|
94
118
|
}
|
|
95
119
|
|
|
96
|
-
return success(category);
|
|
120
|
+
return success(this.factory.parseCategory(this.context, category));
|
|
97
121
|
}
|
|
98
122
|
|
|
99
123
|
@Reactionary({
|
|
100
124
|
inputSchema: CategoryQueryBySlugSchema,
|
|
101
|
-
outputSchema: CategorySchema
|
|
125
|
+
outputSchema: CategorySchema,
|
|
102
126
|
})
|
|
103
|
-
public override async getBySlug(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
127
|
+
public override async getBySlug(
|
|
128
|
+
payload: CategoryQueryBySlug,
|
|
129
|
+
): Promise<Result<CategoryFactoryCategoryOutput<TFactory>, NotFoundError>> {
|
|
130
|
+
for (const category of this.allCategories.values()) {
|
|
131
|
+
if (category.slug === payload.slug) {
|
|
132
|
+
return success(this.factory.parseCategory(this.context, category));
|
|
107
133
|
}
|
|
108
134
|
}
|
|
135
|
+
|
|
109
136
|
return error<NotFoundError>({
|
|
110
137
|
type: 'NotFound',
|
|
111
|
-
identifier: payload
|
|
138
|
+
identifier: payload,
|
|
112
139
|
});
|
|
113
140
|
}
|
|
114
141
|
|
|
115
142
|
@Reactionary({
|
|
116
143
|
inputSchema: CategoryQueryForBreadcrumbSchema,
|
|
117
|
-
outputSchema: z.array(CategorySchema)
|
|
144
|
+
outputSchema: z.array(CategorySchema),
|
|
118
145
|
})
|
|
119
|
-
public override async getBreadcrumbPathToCategory(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
path
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
146
|
+
public override async getBreadcrumbPathToCategory(
|
|
147
|
+
payload: CategoryQueryForBreadcrumb,
|
|
148
|
+
): Promise<Result<CategoryFactoryCategoryOutput<TFactory>[]>> {
|
|
149
|
+
const path: Category[] = [];
|
|
150
|
+
let next = this.allCategories.get(payload.id.key);
|
|
151
|
+
|
|
152
|
+
while (next) {
|
|
153
|
+
path.unshift(next);
|
|
154
|
+
if (!next.parentCategory) {
|
|
155
|
+
break;
|
|
127
156
|
}
|
|
157
|
+
next = this.allCategories.get(next.parentCategory.key);
|
|
128
158
|
}
|
|
129
|
-
|
|
159
|
+
|
|
160
|
+
return success(path.map((x) => this.factory.parseCategory(this.context, x)));
|
|
130
161
|
}
|
|
131
162
|
|
|
132
163
|
@Reactionary({
|
|
133
|
-
inputSchema:
|
|
134
|
-
outputSchema: CategoryPaginatedResultSchema
|
|
164
|
+
inputSchema: CategoryQueryForTopCategoriesSchema,
|
|
165
|
+
outputSchema: CategoryPaginatedResultSchema,
|
|
135
166
|
})
|
|
136
|
-
public override async
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
items: page ? page : [],
|
|
149
|
-
totalCount: children ? children.length : 0,
|
|
150
|
-
pageNumber: payload.paginationOptions.pageNumber,
|
|
151
|
-
pageSize: payload.paginationOptions.pageSize,
|
|
152
|
-
totalPages: children ? Math.ceil(children.length / payload.paginationOptions.pageSize) : 1,
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
return success(res);
|
|
167
|
+
public override async findTopCategories(
|
|
168
|
+
_payload: CategoryQueryForTopCategories,
|
|
169
|
+
): Promise<Result<CategoryFactoryPaginatedOutput<TFactory>>> {
|
|
170
|
+
const result = {
|
|
171
|
+
items: this.topCategories,
|
|
172
|
+
pageSize: this.topCategories.length,
|
|
173
|
+
pageNumber: 1,
|
|
174
|
+
totalCount: this.topCategories.length,
|
|
175
|
+
totalPages: 1,
|
|
176
|
+
} satisfies CategoryPaginatedResult;
|
|
177
|
+
|
|
178
|
+
return success(this.factory.parseCategoryPaginatedResult(this.context, result));
|
|
156
179
|
}
|
|
157
180
|
|
|
158
181
|
@Reactionary({
|
|
159
|
-
inputSchema:
|
|
160
|
-
outputSchema: CategoryPaginatedResultSchema
|
|
182
|
+
inputSchema: CategoryQueryForChildCategoriesSchema,
|
|
183
|
+
outputSchema: CategoryPaginatedResultSchema,
|
|
161
184
|
})
|
|
162
|
-
public override async
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
totalCount: children ? children.length : 0,
|
|
176
|
-
pageNumber: payload.paginationOptions.pageNumber,
|
|
177
|
-
pageSize: payload.paginationOptions.pageSize,
|
|
178
|
-
totalPages: children ? Math.ceil(children.length / payload.paginationOptions.pageSize) : 1,
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
return success(res);
|
|
185
|
+
public override async findChildCategories(
|
|
186
|
+
payload: CategoryQueryForChildCategories,
|
|
187
|
+
): Promise<Result<CategoryFactoryPaginatedOutput<TFactory>>> {
|
|
188
|
+
const items = this.childCategories.get(payload.parentId.key) || [];
|
|
189
|
+
const result = {
|
|
190
|
+
items,
|
|
191
|
+
pageSize: items.length,
|
|
192
|
+
pageNumber: 1,
|
|
193
|
+
totalCount: items.length,
|
|
194
|
+
totalPages: 1,
|
|
195
|
+
} satisfies CategoryPaginatedResult;
|
|
196
|
+
|
|
197
|
+
return success(this.factory.parseCategoryPaginatedResult(this.context, result));
|
|
182
198
|
}
|
|
183
|
-
|
|
184
199
|
}
|
|
@@ -29,21 +29,35 @@ import {
|
|
|
29
29
|
CheckoutMutationFinalizeCheckoutSchema,
|
|
30
30
|
success,
|
|
31
31
|
type CheckoutIdentifier,
|
|
32
|
+
type CheckoutFactory,
|
|
33
|
+
type CheckoutFactoryCheckoutOutput,
|
|
34
|
+
type CheckoutFactoryPaymentMethodOutput,
|
|
35
|
+
type CheckoutFactoryShippingMethodOutput,
|
|
36
|
+
type CheckoutFactoryWithOutput,
|
|
32
37
|
PaymentMethodSchema,
|
|
33
38
|
ShippingMethodSchema,
|
|
34
39
|
} from '@reactionary/core';
|
|
35
40
|
import type { FakeConfiguration } from '../schema/configuration.schema.js';
|
|
36
41
|
import { base, en, Faker } from '@faker-js/faker';
|
|
37
42
|
import * as z from 'zod';
|
|
43
|
+
import type { FakeCheckoutFactory } from '../factories/checkout/checkout.factory.js';
|
|
38
44
|
|
|
39
|
-
export class FakeCheckoutProvider
|
|
45
|
+
export class FakeCheckoutProvider<
|
|
46
|
+
TFactory extends CheckoutFactory = FakeCheckoutFactory,
|
|
47
|
+
> extends CheckoutProvider<
|
|
48
|
+
CheckoutFactoryCheckoutOutput<TFactory>,
|
|
49
|
+
CheckoutFactoryShippingMethodOutput<TFactory>,
|
|
50
|
+
CheckoutFactoryPaymentMethodOutput<TFactory>
|
|
51
|
+
> {
|
|
40
52
|
protected config: FakeConfiguration;
|
|
41
53
|
protected generator: Faker;
|
|
54
|
+
protected factory: CheckoutFactoryWithOutput<TFactory>;
|
|
42
55
|
|
|
43
56
|
constructor(
|
|
44
57
|
config: FakeConfiguration,
|
|
45
58
|
cache: Cache,
|
|
46
|
-
context: RequestContext
|
|
59
|
+
context: RequestContext,
|
|
60
|
+
factory: CheckoutFactoryWithOutput<TFactory>,
|
|
47
61
|
) {
|
|
48
62
|
super(cache, context);
|
|
49
63
|
|
|
@@ -53,6 +67,7 @@ export class FakeCheckoutProvider extends CheckoutProvider {
|
|
|
53
67
|
locale: [en, base],
|
|
54
68
|
seed: config.seeds.product,
|
|
55
69
|
});
|
|
70
|
+
this.factory = factory;
|
|
56
71
|
}
|
|
57
72
|
|
|
58
73
|
@Reactionary({
|
|
@@ -61,10 +76,10 @@ export class FakeCheckoutProvider extends CheckoutProvider {
|
|
|
61
76
|
})
|
|
62
77
|
public override async initiateCheckoutForCart(
|
|
63
78
|
payload: CheckoutMutationInitiateCheckout
|
|
64
|
-
): Promise<Result<
|
|
79
|
+
): Promise<Result<CheckoutFactoryCheckoutOutput<TFactory>>> {
|
|
65
80
|
const checkout = this.composeBaseCheckout(payload.cart.identifier);
|
|
66
81
|
|
|
67
|
-
return success(checkout);
|
|
82
|
+
return success(this.factory.parseCheckout(this.context, checkout));
|
|
68
83
|
}
|
|
69
84
|
|
|
70
85
|
@Reactionary({
|
|
@@ -73,10 +88,10 @@ export class FakeCheckoutProvider extends CheckoutProvider {
|
|
|
73
88
|
})
|
|
74
89
|
public override async getById(
|
|
75
90
|
payload: CheckoutQueryById
|
|
76
|
-
): Promise<Result<
|
|
91
|
+
): Promise<Result<CheckoutFactoryCheckoutOutput<TFactory>, NotFoundError>> {
|
|
77
92
|
const checkout = this.composeBaseCheckout(payload.identifier);
|
|
78
93
|
|
|
79
|
-
return success(checkout);
|
|
94
|
+
return success(this.factory.parseCheckout(this.context, checkout));
|
|
80
95
|
}
|
|
81
96
|
|
|
82
97
|
@Reactionary({
|
|
@@ -85,10 +100,10 @@ export class FakeCheckoutProvider extends CheckoutProvider {
|
|
|
85
100
|
})
|
|
86
101
|
public override async setShippingAddress(
|
|
87
102
|
payload: CheckoutMutationSetShippingAddress
|
|
88
|
-
): Promise<Result<
|
|
103
|
+
): Promise<Result<CheckoutFactoryCheckoutOutput<TFactory>>> {
|
|
89
104
|
const checkout = this.composeBaseCheckout(payload.checkout);
|
|
90
105
|
|
|
91
|
-
return success(checkout);
|
|
106
|
+
return success(this.factory.parseCheckout(this.context, checkout));
|
|
92
107
|
}
|
|
93
108
|
|
|
94
109
|
@Reactionary({
|
|
@@ -97,7 +112,7 @@ export class FakeCheckoutProvider extends CheckoutProvider {
|
|
|
97
112
|
})
|
|
98
113
|
public override async getAvailableShippingMethods(
|
|
99
114
|
payload: CheckoutQueryForAvailableShippingMethods
|
|
100
|
-
): Promise<Result<
|
|
115
|
+
): Promise<Result<CheckoutFactoryShippingMethodOutput<TFactory>[]>> {
|
|
101
116
|
const methods = [
|
|
102
117
|
{
|
|
103
118
|
name: 'Fake',
|
|
@@ -114,7 +129,9 @@ export class FakeCheckoutProvider extends CheckoutProvider {
|
|
|
114
129
|
},
|
|
115
130
|
] satisfies Array<ShippingMethod>;
|
|
116
131
|
|
|
117
|
-
return success(
|
|
132
|
+
return success(
|
|
133
|
+
methods.map((method) => this.factory.parseShippingMethod(this.context, method)),
|
|
134
|
+
);
|
|
118
135
|
}
|
|
119
136
|
|
|
120
137
|
@Reactionary({
|
|
@@ -123,7 +140,7 @@ export class FakeCheckoutProvider extends CheckoutProvider {
|
|
|
123
140
|
})
|
|
124
141
|
public override async getAvailablePaymentMethods(
|
|
125
142
|
payload: CheckoutQueryForAvailablePaymentMethods
|
|
126
|
-
): Promise<Result<
|
|
143
|
+
): Promise<Result<CheckoutFactoryPaymentMethodOutput<TFactory>[]>> {
|
|
127
144
|
const methods = [
|
|
128
145
|
{
|
|
129
146
|
description: 'A fake payment method for paying at some point',
|
|
@@ -136,7 +153,9 @@ export class FakeCheckoutProvider extends CheckoutProvider {
|
|
|
136
153
|
},
|
|
137
154
|
] satisfies Array<PaymentMethod>;
|
|
138
155
|
|
|
139
|
-
return success(
|
|
156
|
+
return success(
|
|
157
|
+
methods.map((method) => this.factory.parsePaymentMethod(this.context, method)),
|
|
158
|
+
);
|
|
140
159
|
}
|
|
141
160
|
|
|
142
161
|
@Reactionary({
|
|
@@ -145,10 +164,10 @@ export class FakeCheckoutProvider extends CheckoutProvider {
|
|
|
145
164
|
})
|
|
146
165
|
public override async addPaymentInstruction(
|
|
147
166
|
payload: CheckoutMutationAddPaymentInstruction
|
|
148
|
-
): Promise<Result<
|
|
167
|
+
): Promise<Result<CheckoutFactoryCheckoutOutput<TFactory>>> {
|
|
149
168
|
const checkout = this.composeBaseCheckout(payload.checkout);
|
|
150
169
|
|
|
151
|
-
return success(checkout);
|
|
170
|
+
return success(this.factory.parseCheckout(this.context, checkout));
|
|
152
171
|
}
|
|
153
172
|
|
|
154
173
|
@Reactionary({
|
|
@@ -157,10 +176,10 @@ export class FakeCheckoutProvider extends CheckoutProvider {
|
|
|
157
176
|
})
|
|
158
177
|
public override async removePaymentInstruction(
|
|
159
178
|
payload: CheckoutMutationRemovePaymentInstruction
|
|
160
|
-
): Promise<Result<
|
|
179
|
+
): Promise<Result<CheckoutFactoryCheckoutOutput<TFactory>>> {
|
|
161
180
|
const checkout = this.composeBaseCheckout(payload.checkout);
|
|
162
181
|
|
|
163
|
-
return success(checkout);
|
|
182
|
+
return success(this.factory.parseCheckout(this.context, checkout));
|
|
164
183
|
}
|
|
165
184
|
|
|
166
185
|
@Reactionary({
|
|
@@ -169,10 +188,10 @@ export class FakeCheckoutProvider extends CheckoutProvider {
|
|
|
169
188
|
})
|
|
170
189
|
public override async setShippingInstruction(
|
|
171
190
|
payload: CheckoutMutationSetShippingInstruction
|
|
172
|
-
): Promise<Result<
|
|
191
|
+
): Promise<Result<CheckoutFactoryCheckoutOutput<TFactory>>> {
|
|
173
192
|
const checkout = this.composeBaseCheckout(payload.checkout);
|
|
174
193
|
|
|
175
|
-
return success(checkout);
|
|
194
|
+
return success(this.factory.parseCheckout(this.context, checkout));
|
|
176
195
|
}
|
|
177
196
|
|
|
178
197
|
@Reactionary({
|
|
@@ -181,10 +200,10 @@ export class FakeCheckoutProvider extends CheckoutProvider {
|
|
|
181
200
|
})
|
|
182
201
|
public override async finalizeCheckout(
|
|
183
202
|
payload: CheckoutMutationFinalizeCheckout
|
|
184
|
-
): Promise<Result<
|
|
203
|
+
): Promise<Result<CheckoutFactoryCheckoutOutput<TFactory>>> {
|
|
185
204
|
const checkout = this.composeBaseCheckout(payload.checkout);
|
|
186
205
|
|
|
187
|
-
return success(checkout);
|
|
206
|
+
return success(this.factory.parseCheckout(this.context, checkout));
|
|
188
207
|
}
|
|
189
208
|
|
|
190
209
|
protected composeBaseCheckout(identifier?: CheckoutIdentifier) {
|
|
@@ -1,102 +1,108 @@
|
|
|
1
1
|
import {
|
|
2
|
+
type AnonymousIdentity,
|
|
3
|
+
type Cache,
|
|
2
4
|
type Identity,
|
|
3
|
-
type
|
|
5
|
+
type IdentityFactory,
|
|
6
|
+
type IdentityFactoryOutput,
|
|
7
|
+
type IdentityFactoryWithOutput,
|
|
4
8
|
type IdentityMutationLogin,
|
|
9
|
+
IdentityMutationLoginSchema,
|
|
5
10
|
type IdentityMutationLogout,
|
|
6
|
-
|
|
7
|
-
type Cache,
|
|
8
|
-
IdentityProvider,
|
|
11
|
+
IdentityMutationLogoutSchema,
|
|
9
12
|
type IdentityMutationRegister,
|
|
10
|
-
type AnonymousIdentity,
|
|
11
|
-
type RegisteredIdentity,
|
|
12
|
-
Reactionary,
|
|
13
13
|
IdentityMutationRegisterSchema,
|
|
14
|
-
|
|
15
|
-
IdentityMutationLogoutSchema,
|
|
16
|
-
IdentityMutationLoginSchema,
|
|
14
|
+
type IdentityQuerySelf,
|
|
17
15
|
IdentityQuerySelfSchema,
|
|
16
|
+
IdentityProvider,
|
|
17
|
+
IdentitySchema,
|
|
18
|
+
type RegisteredIdentity,
|
|
19
|
+
type RequestContext,
|
|
18
20
|
type Result,
|
|
21
|
+
Reactionary,
|
|
19
22
|
success,
|
|
20
23
|
} from '@reactionary/core';
|
|
21
24
|
import type { FakeConfiguration } from '../schema/configuration.schema.js';
|
|
22
25
|
import { base, en, Faker } from '@faker-js/faker';
|
|
26
|
+
import type { FakeIdentityFactory } from '../factories/identity/identity.factory.js';
|
|
23
27
|
|
|
24
|
-
export class FakeIdentityProvider
|
|
28
|
+
export class FakeIdentityProvider<
|
|
29
|
+
TFactory extends IdentityFactory = FakeIdentityFactory,
|
|
30
|
+
> extends IdentityProvider<IdentityFactoryOutput<TFactory>> {
|
|
25
31
|
protected config: FakeConfiguration;
|
|
32
|
+
protected factory: IdentityFactoryWithOutput<TFactory>;
|
|
26
33
|
private currentIdentity: Identity | null = null;
|
|
27
34
|
|
|
28
35
|
constructor(
|
|
29
36
|
config: FakeConfiguration,
|
|
30
37
|
cache: Cache,
|
|
31
|
-
context: RequestContext
|
|
38
|
+
context: RequestContext,
|
|
39
|
+
factory: IdentityFactoryWithOutput<TFactory>,
|
|
32
40
|
) {
|
|
33
41
|
super(cache, context);
|
|
34
42
|
|
|
35
43
|
this.config = config;
|
|
44
|
+
this.factory = factory;
|
|
36
45
|
}
|
|
37
46
|
|
|
38
47
|
@Reactionary({
|
|
39
48
|
inputSchema: IdentityQuerySelfSchema,
|
|
40
|
-
outputSchema: IdentitySchema
|
|
49
|
+
outputSchema: IdentitySchema,
|
|
41
50
|
})
|
|
42
51
|
public override async getSelf(
|
|
43
|
-
_payload: IdentityQuerySelf
|
|
44
|
-
): Promise<Result<
|
|
52
|
+
_payload: IdentityQuerySelf,
|
|
53
|
+
): Promise<Result<IdentityFactoryOutput<TFactory>>> {
|
|
45
54
|
if (!this.currentIdentity) {
|
|
46
|
-
|
|
55
|
+
this.currentIdentity = {
|
|
47
56
|
type: 'Anonymous',
|
|
48
57
|
} satisfies AnonymousIdentity;
|
|
49
|
-
|
|
50
|
-
this.currentIdentity = model;
|
|
51
58
|
}
|
|
52
59
|
|
|
53
|
-
return success(this.currentIdentity);
|
|
60
|
+
return success(this.factory.parseIdentity(this.context, this.currentIdentity));
|
|
54
61
|
}
|
|
55
62
|
|
|
56
63
|
@Reactionary({
|
|
57
64
|
inputSchema: IdentityMutationLoginSchema,
|
|
58
|
-
outputSchema: IdentitySchema
|
|
65
|
+
outputSchema: IdentitySchema,
|
|
59
66
|
})
|
|
60
67
|
public override async login(
|
|
61
|
-
|
|
62
|
-
): Promise<Result<
|
|
68
|
+
_payload: IdentityMutationLogin,
|
|
69
|
+
): Promise<Result<IdentityFactoryOutput<TFactory>>> {
|
|
63
70
|
const generator = new Faker({
|
|
64
71
|
seed: 42,
|
|
65
72
|
locale: [en, base],
|
|
66
73
|
});
|
|
67
74
|
|
|
68
|
-
|
|
75
|
+
this.currentIdentity = {
|
|
69
76
|
type: 'Registered',
|
|
70
77
|
id: {
|
|
71
78
|
userId: generator.string.alphanumeric(32),
|
|
72
79
|
},
|
|
73
80
|
} satisfies RegisteredIdentity;
|
|
74
81
|
|
|
75
|
-
this.currentIdentity
|
|
76
|
-
|
|
77
|
-
return success(this.currentIdentity);
|
|
82
|
+
return success(this.factory.parseIdentity(this.context, this.currentIdentity));
|
|
78
83
|
}
|
|
79
84
|
|
|
80
85
|
@Reactionary({
|
|
81
86
|
inputSchema: IdentityMutationLogoutSchema,
|
|
82
|
-
outputSchema: IdentitySchema
|
|
87
|
+
outputSchema: IdentitySchema,
|
|
83
88
|
})
|
|
84
89
|
public override async logout(
|
|
85
|
-
_payload: IdentityMutationLogout
|
|
86
|
-
): Promise<Result<
|
|
87
|
-
|
|
90
|
+
_payload: IdentityMutationLogout,
|
|
91
|
+
): Promise<Result<IdentityFactoryOutput<TFactory>>> {
|
|
92
|
+
this.currentIdentity = {
|
|
88
93
|
type: 'Anonymous',
|
|
89
94
|
} satisfies AnonymousIdentity;
|
|
90
95
|
|
|
91
|
-
this.currentIdentity
|
|
92
|
-
return success(this.currentIdentity);
|
|
96
|
+
return success(this.factory.parseIdentity(this.context, this.currentIdentity));
|
|
93
97
|
}
|
|
94
98
|
|
|
95
99
|
@Reactionary({
|
|
96
100
|
inputSchema: IdentityMutationRegisterSchema,
|
|
97
|
-
outputSchema: IdentitySchema
|
|
101
|
+
outputSchema: IdentitySchema,
|
|
98
102
|
})
|
|
99
|
-
public override register(
|
|
103
|
+
public override register(
|
|
104
|
+
_payload: IdentityMutationRegister,
|
|
105
|
+
): Promise<Result<IdentityFactoryOutput<TFactory>>> {
|
|
100
106
|
throw new Error('Method not implemented.');
|
|
101
107
|
}
|
|
102
108
|
}
|