@labdigital/commercetools-mock 2.17.0 → 2.18.0
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/dist/index.cjs +4219 -3989
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +268 -415
- package/dist/index.d.ts +268 -415
- package/dist/index.js +4219 -3989
- package/dist/index.js.map +1 -1
- package/package.json +44 -46
- package/src/constants.ts +2 -2
- package/src/ctMock.test.ts +11 -11
- package/src/ctMock.ts +141 -127
- package/src/deprecation.ts +8 -0
- package/src/exceptions.ts +17 -15
- package/src/helpers.ts +32 -32
- package/src/index.test.ts +128 -128
- package/src/index.ts +3 -3
- package/src/lib/expandParser.ts +13 -13
- package/src/lib/haversine.test.ts +9 -9
- package/src/lib/haversine.ts +11 -11
- package/src/lib/masking.ts +11 -11
- package/src/lib/parser.ts +2 -2
- package/src/lib/password.ts +23 -3
- package/src/lib/predicateParser.test.ts +185 -183
- package/src/lib/predicateParser.ts +234 -234
- package/src/lib/projectionSearchFilter.test.ts +103 -101
- package/src/lib/projectionSearchFilter.ts +152 -150
- package/src/lib/proxy.ts +5 -5
- package/src/oauth/errors.ts +4 -4
- package/src/oauth/helpers.ts +6 -6
- package/src/oauth/server.test.ts +110 -67
- package/src/oauth/server.ts +161 -141
- package/src/oauth/store.ts +49 -44
- package/src/priceSelector.test.ts +35 -35
- package/src/priceSelector.ts +30 -30
- package/src/product-projection-search.ts +136 -134
- package/src/projectAPI.test.ts +7 -7
- package/src/projectAPI.ts +24 -22
- package/src/repositories/abstract.ts +168 -116
- package/src/repositories/associate-role.ts +90 -77
- package/src/repositories/attribute-group.ts +51 -40
- package/src/repositories/business-unit.ts +168 -148
- package/src/repositories/cart/actions.ts +489 -0
- package/src/repositories/cart/helpers.ts +30 -0
- package/src/repositories/cart/index.ts +180 -0
- package/src/repositories/cart-discount/actions.ts +148 -0
- package/src/repositories/cart-discount/index.ts +86 -0
- package/src/repositories/category/actions.ts +231 -0
- package/src/repositories/category/index.ts +52 -0
- package/src/repositories/channel.ts +88 -90
- package/src/repositories/custom-object.ts +46 -45
- package/src/repositories/customer/actions.ts +165 -0
- package/src/repositories/customer/index.ts +79 -0
- package/src/repositories/customer-group.ts +66 -55
- package/src/repositories/discount-code/actions.ts +149 -0
- package/src/repositories/discount-code/index.ts +50 -0
- package/src/repositories/errors.ts +10 -10
- package/src/repositories/extension.ts +64 -62
- package/src/repositories/helpers.ts +117 -118
- package/src/repositories/index.ts +80 -79
- package/src/repositories/inventory-entry/actions.ts +84 -0
- package/src/repositories/inventory-entry/index.ts +44 -0
- package/src/repositories/my-customer.ts +114 -0
- package/src/repositories/my-order.ts +8 -8
- package/src/repositories/order/actions.ts +281 -0
- package/src/repositories/{order.test.ts → order/index.test.ts} +77 -77
- package/src/repositories/order/index.ts +260 -0
- package/src/repositories/order-edit.ts +10 -23
- package/src/repositories/payment/actions.ts +305 -0
- package/src/repositories/payment/helpers.ts +17 -0
- package/src/repositories/payment/index.ts +56 -0
- package/src/repositories/product/actions.ts +943 -0
- package/src/repositories/product/helpers.ts +98 -0
- package/src/repositories/product/index.ts +130 -0
- package/src/repositories/product-discount.ts +127 -117
- package/src/repositories/product-projection.ts +56 -62
- package/src/repositories/product-selection.ts +31 -28
- package/src/repositories/product-type.ts +136 -134
- package/src/repositories/project.ts +133 -118
- package/src/repositories/quote-request.ts +7 -19
- package/src/repositories/quote.ts +7 -22
- package/src/repositories/review.ts +13 -26
- package/src/repositories/shipping-method/actions.ts +198 -0
- package/src/repositories/shipping-method/helpers.ts +10 -0
- package/src/repositories/shipping-method/index.ts +138 -0
- package/src/repositories/shopping-list/actions.ts +295 -0
- package/src/repositories/shopping-list/index.ts +122 -0
- package/src/repositories/staged-quote.ts +7 -20
- package/src/repositories/standalone-price.ts +57 -44
- package/src/repositories/state.ts +113 -68
- package/src/repositories/store.ts +106 -94
- package/src/repositories/subscription.ts +46 -22
- package/src/repositories/tax-category/actions.ts +94 -0
- package/src/repositories/tax-category/helpers.ts +8 -0
- package/src/repositories/tax-category/index.ts +25 -0
- package/src/repositories/type/actions.ts +162 -0
- package/src/repositories/type/index.ts +24 -0
- package/src/repositories/zone.ts +62 -58
- package/src/server.ts +9 -9
- package/src/services/abstract.ts +75 -72
- package/src/services/associate-roles.test.ts +27 -27
- package/src/services/associate-roles.ts +7 -7
- package/src/services/attribute-group.ts +7 -7
- package/src/services/business-units.test.ts +28 -28
- package/src/services/business-units.ts +7 -7
- package/src/services/cart-discount.test.ts +199 -199
- package/src/services/cart-discount.ts +7 -7
- package/src/services/cart.test.ts +261 -261
- package/src/services/cart.ts +22 -21
- package/src/services/category.test.ts +121 -121
- package/src/services/category.ts +7 -7
- package/src/services/channel.ts +7 -7
- package/src/services/custom-object.test.ts +130 -130
- package/src/services/custom-object.ts +34 -31
- package/src/services/customer-group.ts +7 -7
- package/src/services/customer.test.ts +205 -205
- package/src/services/customer.ts +31 -29
- package/src/services/discount-code.ts +7 -7
- package/src/services/extension.ts +7 -7
- package/src/services/index.ts +85 -81
- package/src/services/inventory-entry.test.ts +106 -106
- package/src/services/inventory-entry.ts +7 -7
- package/src/services/my-cart.test.ts +56 -56
- package/src/services/my-cart.ts +20 -20
- package/src/services/my-customer.test.ts +155 -104
- package/src/services/my-customer.ts +61 -75
- package/src/services/my-order.ts +16 -16
- package/src/services/my-payment.test.ts +40 -40
- package/src/services/my-payment.ts +7 -7
- package/src/services/my-shopping-list.ts +7 -7
- package/src/services/order.test.ts +243 -243
- package/src/services/order.ts +23 -18
- package/src/services/payment.test.ts +40 -40
- package/src/services/payment.ts +7 -7
- package/src/services/product-discount.ts +7 -7
- package/src/services/product-projection.test.ts +190 -190
- package/src/services/product-projection.ts +34 -32
- package/src/services/product-selection.test.ts +19 -19
- package/src/services/product-selection.ts +7 -7
- package/src/services/product-type.test.ts +38 -38
- package/src/services/product-type.ts +7 -7
- package/src/services/product.test.ts +658 -656
- package/src/services/product.ts +7 -7
- package/src/services/project.test.ts +24 -24
- package/src/services/project.ts +17 -17
- package/src/services/reviews.ts +7 -7
- package/src/services/shipping-method.test.ts +78 -78
- package/src/services/shipping-method.ts +16 -16
- package/src/services/shopping-list.test.ts +170 -170
- package/src/services/shopping-list.ts +7 -7
- package/src/services/standalone-price.test.ts +112 -112
- package/src/services/standalone-price.ts +7 -7
- package/src/services/state.test.ts +30 -30
- package/src/services/state.ts +7 -7
- package/src/services/store.test.ts +40 -40
- package/src/services/store.ts +7 -7
- package/src/services/subscription.ts +7 -7
- package/src/services/tax-category.test.ts +43 -43
- package/src/services/tax-category.ts +7 -7
- package/src/services/type.ts +7 -7
- package/src/services/zone.ts +7 -7
- package/src/shippingCalculator.test.ts +43 -43
- package/src/shippingCalculator.ts +23 -23
- package/src/storage/abstract.ts +36 -34
- package/src/storage/in-memory.ts +237 -233
- package/src/storage/index.ts +2 -2
- package/src/types.ts +91 -91
- package/src/repositories/cart-discount.ts +0 -219
- package/src/repositories/cart.ts +0 -659
- package/src/repositories/category.ts +0 -256
- package/src/repositories/customer.ts +0 -228
- package/src/repositories/discount-code.ts +0 -181
- package/src/repositories/inventory-entry.ts +0 -109
- package/src/repositories/order.ts +0 -514
- package/src/repositories/payment.ts +0 -342
- package/src/repositories/product.ts +0 -1106
- package/src/repositories/shipping-method.ts +0 -312
- package/src/repositories/shopping-list.ts +0 -392
- package/src/repositories/tax-category.ts +0 -111
- package/src/repositories/type.ts +0 -172
|
@@ -3,47 +3,50 @@ import type {
|
|
|
3
3
|
ProductSelectionChangeNameAction,
|
|
4
4
|
ProductSelectionDraft,
|
|
5
5
|
ProductSelectionUpdateAction,
|
|
6
|
-
} from
|
|
7
|
-
import { getBaseResourceProperties } from
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
6
|
+
} from "@commercetools/platform-sdk";
|
|
7
|
+
import { getBaseResourceProperties } from "../helpers";
|
|
8
|
+
import { AbstractStorage } from "../storage/abstract";
|
|
9
|
+
import type { Writable } from "../types";
|
|
10
|
+
import {
|
|
11
|
+
AbstractResourceRepository,
|
|
12
|
+
AbstractUpdateHandler,
|
|
13
|
+
RepositoryContext,
|
|
14
|
+
UpdateHandlerInterface,
|
|
15
|
+
} from "./abstract";
|
|
10
16
|
|
|
11
|
-
export class ProductSelectionRepository extends AbstractResourceRepository<
|
|
12
|
-
|
|
13
|
-
|
|
17
|
+
export class ProductSelectionRepository extends AbstractResourceRepository<"product-selection"> {
|
|
18
|
+
constructor(storage: AbstractStorage) {
|
|
19
|
+
super("product-selection", storage);
|
|
20
|
+
this.actions = new ProductSelectionUpdateHandler(this._storage);
|
|
14
21
|
}
|
|
15
22
|
|
|
16
23
|
create(
|
|
17
24
|
context: RepositoryContext,
|
|
18
|
-
draft: ProductSelectionDraft
|
|
25
|
+
draft: ProductSelectionDraft,
|
|
19
26
|
): ProductSelection {
|
|
20
27
|
const resource: ProductSelection = {
|
|
21
28
|
...getBaseResourceProperties(),
|
|
22
29
|
productCount: 0,
|
|
23
30
|
key: draft.key,
|
|
24
31
|
name: draft.name,
|
|
25
|
-
mode:
|
|
26
|
-
}
|
|
27
|
-
this.saveNew(context, resource)
|
|
28
|
-
return resource
|
|
32
|
+
mode: "Individual",
|
|
33
|
+
};
|
|
34
|
+
return this.saveNew(context, resource);
|
|
29
35
|
}
|
|
36
|
+
}
|
|
30
37
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
resource: Writable<ProductSelection>,
|
|
37
|
-
action: any
|
|
38
|
-
) => void
|
|
38
|
+
class ProductSelectionUpdateHandler
|
|
39
|
+
extends AbstractUpdateHandler
|
|
40
|
+
implements
|
|
41
|
+
Partial<
|
|
42
|
+
UpdateHandlerInterface<ProductSelection, ProductSelectionUpdateAction>
|
|
39
43
|
>
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
},
|
|
44
|
+
{
|
|
45
|
+
changeName(
|
|
46
|
+
context: RepositoryContext,
|
|
47
|
+
resource: Writable<ProductSelection>,
|
|
48
|
+
{ name }: ProductSelectionChangeNameAction,
|
|
49
|
+
) {
|
|
50
|
+
resource.name = name;
|
|
48
51
|
}
|
|
49
52
|
}
|
|
@@ -11,14 +11,21 @@ import type {
|
|
|
11
11
|
ProductTypeRemoveAttributeDefinitionAction,
|
|
12
12
|
ProductTypeRemoveEnumValuesAction,
|
|
13
13
|
ProductTypeUpdateAction,
|
|
14
|
-
} from
|
|
15
|
-
import { getBaseResourceProperties } from
|
|
16
|
-
import
|
|
17
|
-
import {
|
|
14
|
+
} from "@commercetools/platform-sdk";
|
|
15
|
+
import { getBaseResourceProperties } from "../helpers";
|
|
16
|
+
import { AbstractStorage } from "../storage/abstract";
|
|
17
|
+
import type { Writable } from "../types";
|
|
18
|
+
import {
|
|
19
|
+
AbstractResourceRepository,
|
|
20
|
+
AbstractUpdateHandler,
|
|
21
|
+
RepositoryContext,
|
|
22
|
+
UpdateHandlerInterface,
|
|
23
|
+
} from "./abstract";
|
|
18
24
|
|
|
19
|
-
export class ProductTypeRepository extends AbstractResourceRepository<
|
|
20
|
-
|
|
21
|
-
|
|
25
|
+
export class ProductTypeRepository extends AbstractResourceRepository<"product-type"> {
|
|
26
|
+
constructor(storage: AbstractStorage) {
|
|
27
|
+
super("product-type", storage);
|
|
28
|
+
this.actions = new ProductTypeUpdateHandler(storage);
|
|
22
29
|
}
|
|
23
30
|
|
|
24
31
|
create(context: RepositoryContext, draft: ProductTypeDraft): ProductType {
|
|
@@ -28,146 +35,141 @@ export class ProductTypeRepository extends AbstractResourceRepository<'product-t
|
|
|
28
35
|
name: draft.name,
|
|
29
36
|
description: draft.description,
|
|
30
37
|
attributes: (draft.attributes ?? []).map((a) =>
|
|
31
|
-
|
|
38
|
+
attributeDefinitionFromAttributeDefinitionDraft(context, a),
|
|
32
39
|
),
|
|
33
|
-
}
|
|
40
|
+
};
|
|
34
41
|
|
|
35
|
-
this.saveNew(context, resource)
|
|
36
|
-
return resource
|
|
42
|
+
return this.saveNew(context, resource);
|
|
37
43
|
}
|
|
44
|
+
}
|
|
38
45
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
const attributeDefinitionFromAttributeDefinitionDraft = (
|
|
47
|
+
_context: RepositoryContext,
|
|
48
|
+
draft: AttributeDefinitionDraft,
|
|
49
|
+
): AttributeDefinition => ({
|
|
50
|
+
...draft,
|
|
51
|
+
attributeConstraint: draft.attributeConstraint ?? "None",
|
|
52
|
+
inputHint: draft.inputHint ?? "SingleLine",
|
|
53
|
+
inputTip:
|
|
54
|
+
draft.inputTip && Object.keys(draft.inputTip).length > 0
|
|
55
|
+
? draft.inputTip
|
|
56
|
+
: undefined,
|
|
57
|
+
isSearchable: draft.isSearchable ?? true,
|
|
58
|
+
});
|
|
52
59
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
context
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
attributeName,
|
|
68
|
-
newValue,
|
|
69
|
-
}: ProductTypeChangeLocalizedEnumValueLabelAction
|
|
70
|
-
) => {
|
|
71
|
-
const updateAttributeType = (type: Writable<AttributeType>) => {
|
|
72
|
-
switch (type.name) {
|
|
73
|
-
case 'lenum':
|
|
74
|
-
type.values.forEach((v) => {
|
|
75
|
-
if (v.key === newValue.key) {
|
|
76
|
-
v.label = newValue.label
|
|
77
|
-
}
|
|
78
|
-
})
|
|
79
|
-
return
|
|
80
|
-
case 'set':
|
|
81
|
-
updateAttributeType(type.elementType)
|
|
82
|
-
return
|
|
83
|
-
}
|
|
84
|
-
}
|
|
60
|
+
class ProductTypeUpdateHandler
|
|
61
|
+
extends AbstractUpdateHandler
|
|
62
|
+
implements
|
|
63
|
+
Partial<UpdateHandlerInterface<ProductType, ProductTypeUpdateAction>>
|
|
64
|
+
{
|
|
65
|
+
addAttributeDefinition(
|
|
66
|
+
context: RepositoryContext,
|
|
67
|
+
resource: Writable<ProductType>,
|
|
68
|
+
{ attribute }: ProductTypeAddAttributeDefinitionAction,
|
|
69
|
+
) {
|
|
70
|
+
resource.attributes?.push(
|
|
71
|
+
attributeDefinitionFromAttributeDefinitionDraft(context, attribute),
|
|
72
|
+
);
|
|
73
|
+
}
|
|
85
74
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
) => {
|
|
97
|
-
resource.attributes?.forEach((value) => {
|
|
98
|
-
if (value.name === attributeName) {
|
|
99
|
-
value.label = label
|
|
100
|
-
}
|
|
101
|
-
})
|
|
102
|
-
},
|
|
103
|
-
addAttributeDefinition: (
|
|
104
|
-
context: RepositoryContext,
|
|
105
|
-
resource: Writable<ProductType>,
|
|
106
|
-
{ attribute }: ProductTypeAddAttributeDefinitionAction
|
|
107
|
-
) => {
|
|
108
|
-
resource.attributes?.push(
|
|
109
|
-
this.attributeDefinitionFromAttributeDefinitionDraft(context, attribute)
|
|
110
|
-
)
|
|
111
|
-
},
|
|
112
|
-
changeAttributeOrderByName: (
|
|
113
|
-
context: RepositoryContext,
|
|
114
|
-
resource: Writable<ProductType>,
|
|
115
|
-
{ attributeNames }: ProductTypeChangeAttributeOrderByNameAction
|
|
116
|
-
) => {
|
|
117
|
-
const attrs = new Map(
|
|
118
|
-
resource.attributes?.map((item) => [item.name, item])
|
|
119
|
-
)
|
|
120
|
-
const result: AttributeDefinition[] = []
|
|
121
|
-
let current = resource.attributes
|
|
75
|
+
changeAttributeOrderByName(
|
|
76
|
+
context: RepositoryContext,
|
|
77
|
+
resource: Writable<ProductType>,
|
|
78
|
+
{ attributeNames }: ProductTypeChangeAttributeOrderByNameAction,
|
|
79
|
+
) {
|
|
80
|
+
const attrs = new Map(
|
|
81
|
+
resource.attributes?.map((item) => [item.name, item]),
|
|
82
|
+
);
|
|
83
|
+
const result: AttributeDefinition[] = [];
|
|
84
|
+
let current = resource.attributes;
|
|
122
85
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
86
|
+
attributeNames.forEach((attrName) => {
|
|
87
|
+
const attr = attrs.get(attrName);
|
|
88
|
+
if (attr === undefined) {
|
|
89
|
+
throw new Error("New attr");
|
|
90
|
+
}
|
|
91
|
+
result.push(attr);
|
|
129
92
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
93
|
+
// Remove from current items
|
|
94
|
+
current = current?.filter((f) => f.name !== attrName);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
resource.attributes = result;
|
|
98
|
+
// Add attrs which were not specified in the order as last items. Not
|
|
99
|
+
// sure if this follows commercetools
|
|
100
|
+
if (current) {
|
|
101
|
+
resource.attributes.push(...current);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
133
104
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
105
|
+
changeLabel(
|
|
106
|
+
context: RepositoryContext,
|
|
107
|
+
resource: Writable<ProductType>,
|
|
108
|
+
{ attributeName, label }: ProductTypeChangeLabelAction,
|
|
109
|
+
) {
|
|
110
|
+
resource.attributes?.forEach((value) => {
|
|
111
|
+
if (value.name === attributeName) {
|
|
112
|
+
value.label = label;
|
|
139
113
|
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
context: RepositoryContext,
|
|
143
|
-
resource: Writable<ProductType>,
|
|
144
|
-
{ name }: ProductTypeRemoveAttributeDefinitionAction
|
|
145
|
-
) => {
|
|
146
|
-
resource.attributes = resource.attributes?.filter((f) => f.name !== name)
|
|
147
|
-
},
|
|
148
|
-
removeEnumValues: (
|
|
149
|
-
context: RepositoryContext,
|
|
150
|
-
resource: Writable<ProductType>,
|
|
151
|
-
{ attributeName, keys }: ProductTypeRemoveEnumValuesAction
|
|
152
|
-
) => {
|
|
153
|
-
resource.attributes?.forEach((attr) => {
|
|
154
|
-
if (attr.name == attributeName) {
|
|
155
|
-
if (attr.type.name == 'enum') {
|
|
156
|
-
attr.type.values = attr.type.values.filter(
|
|
157
|
-
(v) => !keys.includes(v.key)
|
|
158
|
-
)
|
|
159
|
-
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
160
116
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
117
|
+
changeLocalizedEnumValueLabel(
|
|
118
|
+
context: RepositoryContext,
|
|
119
|
+
resource: Writable<ProductType>,
|
|
120
|
+
{ attributeName, newValue }: ProductTypeChangeLocalizedEnumValueLabelAction,
|
|
121
|
+
) {
|
|
122
|
+
const updateAttributeType = (type: Writable<AttributeType>) => {
|
|
123
|
+
switch (type.name) {
|
|
124
|
+
case "lenum":
|
|
125
|
+
type.values.forEach((v) => {
|
|
126
|
+
if (v.key === newValue.key) {
|
|
127
|
+
v.label = newValue.label;
|
|
167
128
|
}
|
|
129
|
+
});
|
|
130
|
+
return;
|
|
131
|
+
case "set":
|
|
132
|
+
updateAttributeType(type.elementType);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
resource.attributes?.forEach((value) => {
|
|
138
|
+
if (value.name === attributeName) {
|
|
139
|
+
updateAttributeType(value.type);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
removeAttributeDefinition(
|
|
145
|
+
context: RepositoryContext,
|
|
146
|
+
resource: Writable<ProductType>,
|
|
147
|
+
{ name }: ProductTypeRemoveAttributeDefinitionAction,
|
|
148
|
+
) {
|
|
149
|
+
resource.attributes = resource.attributes?.filter((f) => f.name !== name);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
removeEnumValues(
|
|
153
|
+
context: RepositoryContext,
|
|
154
|
+
resource: Writable<ProductType>,
|
|
155
|
+
{ attributeName, keys }: ProductTypeRemoveEnumValuesAction,
|
|
156
|
+
) {
|
|
157
|
+
resource.attributes?.forEach((attr) => {
|
|
158
|
+
if (attr.name == attributeName) {
|
|
159
|
+
if (attr.type.name == "enum") {
|
|
160
|
+
attr.type.values = attr.type.values.filter(
|
|
161
|
+
(v) => !keys.includes(v.key),
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (attr.type.name == "set") {
|
|
166
|
+
if (attr.type.elementType.name == "enum") {
|
|
167
|
+
attr.type.elementType.values = attr.type.elementType.values.filter(
|
|
168
|
+
(v) => !keys.includes(v.key),
|
|
169
|
+
);
|
|
168
170
|
}
|
|
169
171
|
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
+
}
|
|
173
|
+
});
|
|
172
174
|
}
|
|
173
175
|
}
|
|
@@ -12,137 +12,152 @@ import type {
|
|
|
12
12
|
ProjectSetExternalOAuthAction,
|
|
13
13
|
ProjectSetShippingRateInputTypeAction,
|
|
14
14
|
ProjectUpdateAction,
|
|
15
|
-
} from
|
|
16
|
-
import { maskSecretValue } from
|
|
17
|
-
import
|
|
18
|
-
import {
|
|
15
|
+
} from "@commercetools/platform-sdk";
|
|
16
|
+
import { maskSecretValue } from "../lib/masking";
|
|
17
|
+
import { AbstractStorage } from "../storage/abstract";
|
|
18
|
+
import type { Writable } from "../types";
|
|
19
|
+
import {
|
|
20
|
+
AbstractRepository,
|
|
21
|
+
AbstractUpdateHandler,
|
|
22
|
+
RepositoryContext,
|
|
23
|
+
UpdateHandlerInterface,
|
|
24
|
+
} from "./abstract";
|
|
19
25
|
|
|
20
26
|
export class ProjectRepository extends AbstractRepository<Project> {
|
|
27
|
+
constructor(storage: AbstractStorage) {
|
|
28
|
+
super(storage);
|
|
29
|
+
this.actions = new ProjectUpdateHandler(this._storage);
|
|
30
|
+
}
|
|
31
|
+
|
|
21
32
|
get(context: RepositoryContext): Project | null {
|
|
22
|
-
const resource = this._storage.getProject(context.projectKey)
|
|
23
|
-
return this.postProcessResource(resource)
|
|
33
|
+
const resource = this._storage.getProject(context.projectKey);
|
|
34
|
+
return this.postProcessResource(resource);
|
|
24
35
|
}
|
|
25
36
|
|
|
26
37
|
postProcessResource(resource: Project): Project {
|
|
27
38
|
if (resource) {
|
|
28
|
-
return maskSecretValue(resource,
|
|
39
|
+
return maskSecretValue(resource, "externalOAuth.authorizationHeader");
|
|
29
40
|
}
|
|
30
|
-
return resource
|
|
41
|
+
return resource;
|
|
31
42
|
}
|
|
32
43
|
|
|
33
44
|
saveNew(context: RepositoryContext, resource: Writable<Project>) {
|
|
34
|
-
resource.version = 1
|
|
35
|
-
this._storage.saveProject(resource)
|
|
45
|
+
resource.version = 1;
|
|
46
|
+
this._storage.saveProject(resource);
|
|
36
47
|
}
|
|
37
48
|
|
|
38
49
|
saveUpdate(context: RepositoryContext, version: number, resource: Project) {
|
|
39
|
-
this._storage.saveProject(resource)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
},
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
},
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
50
|
+
this._storage.saveProject(resource);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
class ProjectUpdateHandler
|
|
55
|
+
extends AbstractUpdateHandler
|
|
56
|
+
implements Partial<UpdateHandlerInterface<Project, ProjectUpdateAction>>
|
|
57
|
+
{
|
|
58
|
+
changeCartsConfiguration(
|
|
59
|
+
context: RepositoryContext,
|
|
60
|
+
resource: Writable<Project>,
|
|
61
|
+
{ cartsConfiguration }: ProjectChangeCartsConfigurationAction,
|
|
62
|
+
) {
|
|
63
|
+
resource.carts = cartsConfiguration || {
|
|
64
|
+
countryTaxRateFallbackEnabled: false,
|
|
65
|
+
deleteDaysAfterLastModification: 90,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
changeCountries(
|
|
70
|
+
context: RepositoryContext,
|
|
71
|
+
resource: Writable<Project>,
|
|
72
|
+
{ countries }: ProjectChangeCountriesAction,
|
|
73
|
+
) {
|
|
74
|
+
resource.countries = countries;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
changeCountryTaxRateFallbackEnabled(
|
|
78
|
+
context: RepositoryContext,
|
|
79
|
+
resource: Writable<Project>,
|
|
80
|
+
{
|
|
81
|
+
countryTaxRateFallbackEnabled,
|
|
82
|
+
}: ProjectChangeCountryTaxRateFallbackEnabledAction,
|
|
83
|
+
) {
|
|
84
|
+
resource.carts.countryTaxRateFallbackEnabled =
|
|
85
|
+
countryTaxRateFallbackEnabled;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
changeCurrencies(
|
|
89
|
+
context: RepositoryContext,
|
|
90
|
+
resource: Writable<Project>,
|
|
91
|
+
{ currencies }: ProjectChangeCurrenciesAction,
|
|
92
|
+
) {
|
|
93
|
+
resource.currencies = currencies;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
changeLanguages(
|
|
97
|
+
context: RepositoryContext,
|
|
98
|
+
resource: Writable<Project>,
|
|
99
|
+
{ languages }: ProjectChangeLanguagesAction,
|
|
100
|
+
) {
|
|
101
|
+
resource.languages = languages;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
changeMessagesConfiguration(
|
|
105
|
+
context: RepositoryContext,
|
|
106
|
+
resource: Writable<Project>,
|
|
107
|
+
{ messagesConfiguration }: ProjectChangeMessagesConfigurationAction,
|
|
108
|
+
) {
|
|
109
|
+
resource.messages.enabled = messagesConfiguration.enabled;
|
|
110
|
+
resource.messages.deleteDaysAfterCreation =
|
|
111
|
+
messagesConfiguration.deleteDaysAfterCreation;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
changeName(
|
|
115
|
+
context: RepositoryContext,
|
|
116
|
+
resource: Writable<Project>,
|
|
117
|
+
{ name }: ProjectChangeNameAction,
|
|
118
|
+
) {
|
|
119
|
+
resource.name = name;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
changeOrderSearchStatus(
|
|
123
|
+
context: RepositoryContext,
|
|
124
|
+
resource: Writable<Project>,
|
|
125
|
+
{ status }: ProjectChangeOrderSearchStatusAction,
|
|
126
|
+
) {
|
|
127
|
+
if (!resource.searchIndexing?.orders) {
|
|
128
|
+
throw new Error("Invalid project state");
|
|
129
|
+
}
|
|
130
|
+
resource.searchIndexing.orders.status = status;
|
|
131
|
+
resource.searchIndexing.orders.lastModifiedAt = new Date().toISOString();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
changeProductSearchIndexingEnabled(
|
|
135
|
+
context: RepositoryContext,
|
|
136
|
+
resource: Writable<Project>,
|
|
137
|
+
{ enabled }: ProjectChangeProductSearchIndexingEnabledAction,
|
|
138
|
+
) {
|
|
139
|
+
if (!resource.searchIndexing?.products) {
|
|
140
|
+
throw new Error("Invalid project state");
|
|
141
|
+
}
|
|
142
|
+
resource.searchIndexing.products.status = enabled
|
|
143
|
+
? "Activated"
|
|
144
|
+
: "Deactivated";
|
|
145
|
+
resource.searchIndexing.products.lastModifiedAt = new Date().toISOString();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
setExternalOAuth(
|
|
149
|
+
context: RepositoryContext,
|
|
150
|
+
resource: Writable<Project>,
|
|
151
|
+
{ externalOAuth }: ProjectSetExternalOAuthAction,
|
|
152
|
+
) {
|
|
153
|
+
resource.externalOAuth = externalOAuth;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
setShippingRateInputType(
|
|
157
|
+
context: RepositoryContext,
|
|
158
|
+
resource: Writable<Project>,
|
|
159
|
+
{ shippingRateInputType }: ProjectSetShippingRateInputTypeAction,
|
|
160
|
+
) {
|
|
161
|
+
resource.shippingRateInputType = shippingRateInputType;
|
|
147
162
|
}
|
|
148
163
|
}
|