@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
|
@@ -1,23 +1,33 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
State,
|
|
3
|
+
StateAddRolesAction,
|
|
3
4
|
StateChangeInitialAction,
|
|
4
5
|
StateChangeKeyAction,
|
|
6
|
+
StateChangeTypeAction,
|
|
5
7
|
StateDraft,
|
|
6
8
|
StateReference,
|
|
9
|
+
StateRemoveRolesAction,
|
|
7
10
|
StateSetDescriptionAction,
|
|
8
11
|
StateSetNameAction,
|
|
9
12
|
StateSetRolesAction,
|
|
10
13
|
StateSetTransitionsAction,
|
|
11
14
|
StateUpdateAction,
|
|
12
|
-
} from
|
|
13
|
-
import { getBaseResourceProperties } from
|
|
14
|
-
import
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
15
|
+
} from "@commercetools/platform-sdk";
|
|
16
|
+
import { getBaseResourceProperties } from "../helpers";
|
|
17
|
+
import { AbstractStorage } from "../storage/abstract";
|
|
18
|
+
import type { Writable } from "../types";
|
|
19
|
+
import {
|
|
20
|
+
AbstractResourceRepository,
|
|
21
|
+
AbstractUpdateHandler,
|
|
22
|
+
RepositoryContext,
|
|
23
|
+
UpdateHandlerInterface,
|
|
24
|
+
} from "./abstract";
|
|
25
|
+
import { getReferenceFromResourceIdentifier } from "./helpers";
|
|
17
26
|
|
|
18
|
-
export class StateRepository extends AbstractResourceRepository<
|
|
19
|
-
|
|
20
|
-
|
|
27
|
+
export class StateRepository extends AbstractResourceRepository<"state"> {
|
|
28
|
+
constructor(storage: AbstractStorage) {
|
|
29
|
+
super("state", storage);
|
|
30
|
+
this.actions = new StateUpdateHandler(storage);
|
|
21
31
|
}
|
|
22
32
|
|
|
23
33
|
create(context: RepositoryContext, draft: StateDraft): State {
|
|
@@ -27,70 +37,105 @@ export class StateRepository extends AbstractResourceRepository<'state'> {
|
|
|
27
37
|
builtIn: false,
|
|
28
38
|
initial: draft.initial || false,
|
|
29
39
|
transitions: (draft.transitions || []).map((t) =>
|
|
30
|
-
getReferenceFromResourceIdentifier(
|
|
40
|
+
getReferenceFromResourceIdentifier(
|
|
41
|
+
t,
|
|
42
|
+
context.projectKey,
|
|
43
|
+
this._storage,
|
|
44
|
+
),
|
|
31
45
|
),
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
return this.saveNew(context, resource);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
class StateUpdateHandler
|
|
53
|
+
extends AbstractUpdateHandler
|
|
54
|
+
implements UpdateHandlerInterface<State, StateUpdateAction>
|
|
55
|
+
{
|
|
56
|
+
addRoles(
|
|
57
|
+
context: RepositoryContext,
|
|
58
|
+
resource: Writable<State>,
|
|
59
|
+
action: StateAddRolesAction,
|
|
60
|
+
) {
|
|
61
|
+
if (!resource.roles) {
|
|
62
|
+
resource.roles = [];
|
|
63
|
+
}
|
|
64
|
+
for (const role of action.roles) {
|
|
65
|
+
if (!resource.roles.includes(role)) {
|
|
66
|
+
resource.roles.push(role);
|
|
67
|
+
}
|
|
32
68
|
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
changeInitial(
|
|
72
|
+
context: RepositoryContext,
|
|
73
|
+
resource: Writable<State>,
|
|
74
|
+
{ initial }: StateChangeInitialAction,
|
|
75
|
+
) {
|
|
76
|
+
resource.initial = initial;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
changeKey(
|
|
80
|
+
context: RepositoryContext,
|
|
81
|
+
resource: Writable<State>,
|
|
82
|
+
{ key }: StateChangeKeyAction,
|
|
83
|
+
) {
|
|
84
|
+
resource.key = key;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
changeType(
|
|
88
|
+
context: RepositoryContext,
|
|
89
|
+
resource: Writable<State>,
|
|
90
|
+
action: StateChangeTypeAction,
|
|
91
|
+
) {
|
|
92
|
+
resource.type = action.type;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
removeRoles(
|
|
96
|
+
context: RepositoryContext,
|
|
97
|
+
resource: Writable<State>,
|
|
98
|
+
action: StateRemoveRolesAction,
|
|
99
|
+
) {
|
|
100
|
+
resource.roles = resource.roles?.filter(
|
|
101
|
+
(role) => !action.roles.includes(role),
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
setDescription(
|
|
106
|
+
context: RepositoryContext,
|
|
107
|
+
resource: Writable<State>,
|
|
108
|
+
{ description }: StateSetDescriptionAction,
|
|
109
|
+
) {
|
|
110
|
+
resource.description = description;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
setName(
|
|
114
|
+
context: RepositoryContext,
|
|
115
|
+
resource: Writable<State>,
|
|
116
|
+
{ name }: StateSetNameAction,
|
|
117
|
+
) {
|
|
118
|
+
resource.name = name;
|
|
119
|
+
}
|
|
33
120
|
|
|
34
|
-
|
|
35
|
-
|
|
121
|
+
setRoles(
|
|
122
|
+
context: RepositoryContext,
|
|
123
|
+
resource: Writable<State>,
|
|
124
|
+
{ roles }: StateSetRolesAction,
|
|
125
|
+
) {
|
|
126
|
+
resource.roles = roles;
|
|
36
127
|
}
|
|
37
128
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
context: RepositoryContext,
|
|
50
|
-
resource: Writable<State>,
|
|
51
|
-
{ key }: StateChangeKeyAction
|
|
52
|
-
) => {
|
|
53
|
-
resource.key = key
|
|
54
|
-
},
|
|
55
|
-
changeInitial: (
|
|
56
|
-
context: RepositoryContext,
|
|
57
|
-
resource: Writable<State>,
|
|
58
|
-
{ initial }: StateChangeInitialAction
|
|
59
|
-
) => {
|
|
60
|
-
resource.initial = initial
|
|
61
|
-
},
|
|
62
|
-
setDescription: (
|
|
63
|
-
context: RepositoryContext,
|
|
64
|
-
resource: Writable<State>,
|
|
65
|
-
{ description }: StateSetDescriptionAction
|
|
66
|
-
) => {
|
|
67
|
-
resource.description = description
|
|
68
|
-
},
|
|
69
|
-
setName: (
|
|
70
|
-
context: RepositoryContext,
|
|
71
|
-
resource: Writable<State>,
|
|
72
|
-
{ name }: StateSetNameAction
|
|
73
|
-
) => {
|
|
74
|
-
resource.name = name
|
|
75
|
-
},
|
|
76
|
-
setRoles: (
|
|
77
|
-
context: RepositoryContext,
|
|
78
|
-
resource: Writable<State>,
|
|
79
|
-
{ roles }: StateSetRolesAction
|
|
80
|
-
) => {
|
|
81
|
-
resource.roles = roles
|
|
82
|
-
},
|
|
83
|
-
setTransitions: (
|
|
84
|
-
context: RepositoryContext,
|
|
85
|
-
resource: Writable<State>,
|
|
86
|
-
{ transitions }: StateSetTransitionsAction
|
|
87
|
-
) => {
|
|
88
|
-
resource.transitions = transitions?.map(
|
|
89
|
-
(resourceId): StateReference => ({
|
|
90
|
-
id: resourceId.id || '',
|
|
91
|
-
typeId: 'state',
|
|
92
|
-
})
|
|
93
|
-
)
|
|
94
|
-
},
|
|
129
|
+
setTransitions(
|
|
130
|
+
context: RepositoryContext,
|
|
131
|
+
resource: Writable<State>,
|
|
132
|
+
{ transitions }: StateSetTransitionsAction,
|
|
133
|
+
) {
|
|
134
|
+
resource.transitions = transitions?.map(
|
|
135
|
+
(resourceId): StateReference => ({
|
|
136
|
+
id: resourceId.id || "",
|
|
137
|
+
typeId: "state",
|
|
138
|
+
}),
|
|
139
|
+
);
|
|
95
140
|
}
|
|
96
141
|
}
|
|
@@ -10,18 +10,25 @@ import type {
|
|
|
10
10
|
StoreSetLanguagesAction,
|
|
11
11
|
StoreSetNameAction,
|
|
12
12
|
StoreUpdateAction,
|
|
13
|
-
} from
|
|
14
|
-
import { getBaseResourceProperties } from
|
|
15
|
-
import
|
|
16
|
-
import {
|
|
13
|
+
} from "@commercetools/platform-sdk";
|
|
14
|
+
import { getBaseResourceProperties } from "../helpers";
|
|
15
|
+
import { AbstractStorage } from "../storage/abstract";
|
|
16
|
+
import type { Writable } from "../types";
|
|
17
|
+
import {
|
|
18
|
+
AbstractResourceRepository,
|
|
19
|
+
AbstractUpdateHandler,
|
|
20
|
+
RepositoryContext,
|
|
21
|
+
UpdateHandlerInterface,
|
|
22
|
+
} from "./abstract";
|
|
17
23
|
import {
|
|
18
24
|
createCustomFields,
|
|
19
25
|
getReferenceFromResourceIdentifier,
|
|
20
|
-
} from
|
|
26
|
+
} from "./helpers";
|
|
21
27
|
|
|
22
|
-
export class StoreRepository extends AbstractResourceRepository<
|
|
23
|
-
|
|
24
|
-
|
|
28
|
+
export class StoreRepository extends AbstractResourceRepository<"store"> {
|
|
29
|
+
constructor(storage: AbstractStorage) {
|
|
30
|
+
super("store", storage);
|
|
31
|
+
this.actions = new StoreUpdateHandler(this._storage);
|
|
25
32
|
}
|
|
26
33
|
|
|
27
34
|
create(context: RepositoryContext, draft: StoreDraft): Store {
|
|
@@ -31,106 +38,111 @@ export class StoreRepository extends AbstractResourceRepository<'store'> {
|
|
|
31
38
|
name: draft.name,
|
|
32
39
|
languages: draft.languages ?? [],
|
|
33
40
|
countries: draft.countries ?? [],
|
|
34
|
-
distributionChannels:
|
|
41
|
+
distributionChannels: transformChannels(
|
|
42
|
+
context,
|
|
43
|
+
this._storage,
|
|
44
|
+
draft.distributionChannels,
|
|
45
|
+
),
|
|
46
|
+
supplyChannels: transformChannels(
|
|
35
47
|
context,
|
|
36
|
-
|
|
48
|
+
this._storage,
|
|
49
|
+
draft.supplyChannels,
|
|
37
50
|
),
|
|
38
|
-
supplyChannels: this.transformChannels(context, draft.supplyChannels),
|
|
39
51
|
productSelections: [],
|
|
40
52
|
custom: createCustomFields(
|
|
41
53
|
draft.custom,
|
|
42
54
|
context.projectKey,
|
|
43
|
-
this._storage
|
|
55
|
+
this._storage,
|
|
44
56
|
),
|
|
45
|
-
}
|
|
46
|
-
this.saveNew(context, resource)
|
|
47
|
-
|
|
57
|
+
};
|
|
58
|
+
return this.saveNew(context, resource);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const transformChannels = (
|
|
63
|
+
context: RepositoryContext,
|
|
64
|
+
storage: AbstractStorage,
|
|
65
|
+
channels?: ChannelResourceIdentifier[],
|
|
66
|
+
) => {
|
|
67
|
+
if (!channels) return [];
|
|
68
|
+
|
|
69
|
+
return channels.map((ref) =>
|
|
70
|
+
getReferenceFromResourceIdentifier<ChannelReference>(
|
|
71
|
+
ref,
|
|
72
|
+
context.projectKey,
|
|
73
|
+
storage,
|
|
74
|
+
),
|
|
75
|
+
);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
class StoreUpdateHandler
|
|
79
|
+
extends AbstractUpdateHandler
|
|
80
|
+
implements Partial<UpdateHandlerInterface<Store, StoreUpdateAction>>
|
|
81
|
+
{
|
|
82
|
+
setCountries(
|
|
83
|
+
context: RepositoryContext,
|
|
84
|
+
resource: Writable<Store>,
|
|
85
|
+
{ countries }: StoreSetCountriesAction,
|
|
86
|
+
) {
|
|
87
|
+
resource.countries = countries ?? [];
|
|
48
88
|
}
|
|
49
89
|
|
|
50
|
-
|
|
90
|
+
setCustomField(
|
|
51
91
|
context: RepositoryContext,
|
|
52
|
-
|
|
92
|
+
resource: Writable<Store>,
|
|
93
|
+
{ name, value }: StoreSetCustomFieldAction,
|
|
53
94
|
) {
|
|
54
|
-
if (!
|
|
95
|
+
if (!resource.custom) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (value === null) {
|
|
99
|
+
delete resource.custom.fields[name];
|
|
100
|
+
} else {
|
|
101
|
+
resource.custom.fields[name] = value;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
55
104
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
105
|
+
setCustomType(
|
|
106
|
+
context: RepositoryContext,
|
|
107
|
+
resource: Writable<Store>,
|
|
108
|
+
{ type, fields }: StoreSetCustomTypeAction,
|
|
109
|
+
) {
|
|
110
|
+
if (type) {
|
|
111
|
+
resource.custom = createCustomFields(
|
|
112
|
+
{ type, fields },
|
|
59
113
|
context.projectKey,
|
|
60
|
-
this._storage
|
|
61
|
-
)
|
|
62
|
-
|
|
114
|
+
this._storage,
|
|
115
|
+
);
|
|
116
|
+
} else {
|
|
117
|
+
resource.custom = undefined;
|
|
118
|
+
}
|
|
63
119
|
}
|
|
64
120
|
|
|
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
|
-
setLanguages: (
|
|
93
|
-
context: RepositoryContext,
|
|
94
|
-
resource: Writable<Store>,
|
|
95
|
-
{ languages }: StoreSetLanguagesAction
|
|
96
|
-
) => {
|
|
97
|
-
resource.languages = languages ?? []
|
|
98
|
-
},
|
|
99
|
-
setCustomType: (
|
|
100
|
-
context: RepositoryContext,
|
|
101
|
-
resource: Writable<Store>,
|
|
102
|
-
{ type, fields }: StoreSetCustomTypeAction
|
|
103
|
-
) => {
|
|
104
|
-
if (type) {
|
|
105
|
-
resource.custom = createCustomFields(
|
|
106
|
-
{ type, fields },
|
|
107
|
-
context.projectKey,
|
|
108
|
-
this._storage
|
|
109
|
-
)
|
|
110
|
-
} else {
|
|
111
|
-
resource.custom = undefined
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
setCustomField: (
|
|
115
|
-
context: RepositoryContext,
|
|
116
|
-
resource: Writable<Store>,
|
|
117
|
-
{ name, value }: StoreSetCustomFieldAction
|
|
118
|
-
) => {
|
|
119
|
-
if (!resource.custom) {
|
|
120
|
-
return
|
|
121
|
-
}
|
|
122
|
-
if (value === null) {
|
|
123
|
-
delete resource.custom.fields[name]
|
|
124
|
-
} else {
|
|
125
|
-
resource.custom.fields[name] = value
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
setCountries: (
|
|
129
|
-
context: RepositoryContext,
|
|
130
|
-
resource: Writable<Store>,
|
|
131
|
-
{ countries }: StoreSetCountriesAction
|
|
132
|
-
) => {
|
|
133
|
-
resource.countries = countries ?? []
|
|
134
|
-
},
|
|
121
|
+
setDistributionChannels(
|
|
122
|
+
context: RepositoryContext,
|
|
123
|
+
resource: Writable<Store>,
|
|
124
|
+
{ distributionChannels }: StoreSetDistributionChannelsAction,
|
|
125
|
+
) {
|
|
126
|
+
resource.distributionChannels = transformChannels(
|
|
127
|
+
context,
|
|
128
|
+
this._storage,
|
|
129
|
+
distributionChannels,
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
setLanguages(
|
|
134
|
+
context: RepositoryContext,
|
|
135
|
+
resource: Writable<Store>,
|
|
136
|
+
{ languages }: StoreSetLanguagesAction,
|
|
137
|
+
) {
|
|
138
|
+
resource.languages = languages ?? [];
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
setName(
|
|
142
|
+
context: RepositoryContext,
|
|
143
|
+
resource: Writable<Store>,
|
|
144
|
+
{ name }: StoreSetNameAction,
|
|
145
|
+
) {
|
|
146
|
+
resource.name = name;
|
|
135
147
|
}
|
|
136
148
|
}
|
|
@@ -2,33 +2,44 @@ import type {
|
|
|
2
2
|
InvalidInputError,
|
|
3
3
|
Subscription,
|
|
4
4
|
SubscriptionDraft,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import {
|
|
5
|
+
SubscriptionSetKeyAction,
|
|
6
|
+
SubscriptionUpdateAction,
|
|
7
|
+
} from "@commercetools/platform-sdk";
|
|
8
|
+
import { CommercetoolsError } from "~src/exceptions";
|
|
9
|
+
import { getBaseResourceProperties } from "../helpers";
|
|
10
|
+
import { AbstractStorage } from "../storage/abstract";
|
|
11
|
+
import { Writable } from "../types";
|
|
12
|
+
import {
|
|
13
|
+
AbstractResourceRepository,
|
|
14
|
+
AbstractUpdateHandler,
|
|
15
|
+
RepositoryContext,
|
|
16
|
+
UpdateHandlerInterface,
|
|
17
|
+
} from "./abstract";
|
|
9
18
|
|
|
10
|
-
export class SubscriptionRepository extends AbstractResourceRepository<
|
|
11
|
-
|
|
12
|
-
|
|
19
|
+
export class SubscriptionRepository extends AbstractResourceRepository<"subscription"> {
|
|
20
|
+
constructor(storage: AbstractStorage) {
|
|
21
|
+
super("subscription", storage);
|
|
22
|
+
this.actions = new SubscriptionUpdateHandler(storage);
|
|
13
23
|
}
|
|
24
|
+
|
|
14
25
|
create(context: RepositoryContext, draft: SubscriptionDraft): Subscription {
|
|
15
26
|
// TODO: We could actually test this here by using the aws sdk. For now
|
|
16
27
|
// hardcode a failed check when account id is 0000000000
|
|
17
|
-
if (draft.destination.type ===
|
|
18
|
-
const queueURL = new URL(draft.destination.queueUrl)
|
|
19
|
-
const accountId = queueURL.pathname.split(
|
|
20
|
-
if (accountId ===
|
|
21
|
-
const dest = draft.destination
|
|
28
|
+
if (draft.destination.type === "SQS") {
|
|
29
|
+
const queueURL = new URL(draft.destination.queueUrl);
|
|
30
|
+
const accountId = queueURL.pathname.split("/")[1];
|
|
31
|
+
if (accountId === "0000000000") {
|
|
32
|
+
const dest = draft.destination;
|
|
22
33
|
throw new CommercetoolsError<InvalidInputError>(
|
|
23
34
|
{
|
|
24
|
-
code:
|
|
35
|
+
code: "InvalidInput",
|
|
25
36
|
message:
|
|
26
|
-
|
|
37
|
+
"A test message could not be delivered to this destination: " +
|
|
27
38
|
`SQS ${dest.queueUrl} in ${dest.region} for ${dest.accessKey}. ` +
|
|
28
|
-
|
|
39
|
+
"Please make sure your destination is correctly configured.",
|
|
29
40
|
},
|
|
30
|
-
400
|
|
31
|
-
)
|
|
41
|
+
400,
|
|
42
|
+
);
|
|
32
43
|
}
|
|
33
44
|
}
|
|
34
45
|
|
|
@@ -37,13 +48,26 @@ export class SubscriptionRepository extends AbstractResourceRepository<'subscrip
|
|
|
37
48
|
changes: draft.changes || [],
|
|
38
49
|
destination: draft.destination,
|
|
39
50
|
format: draft.format || {
|
|
40
|
-
type:
|
|
51
|
+
type: "Platform",
|
|
41
52
|
},
|
|
42
53
|
key: draft.key,
|
|
43
54
|
messages: draft.messages || [],
|
|
44
|
-
status:
|
|
45
|
-
}
|
|
46
|
-
this.saveNew(context, resource)
|
|
47
|
-
|
|
55
|
+
status: "Healthy",
|
|
56
|
+
};
|
|
57
|
+
return this.saveNew(context, resource);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
class SubscriptionUpdateHandler
|
|
62
|
+
extends AbstractUpdateHandler
|
|
63
|
+
implements
|
|
64
|
+
Partial<UpdateHandlerInterface<Subscription, SubscriptionUpdateAction>>
|
|
65
|
+
{
|
|
66
|
+
setKey(
|
|
67
|
+
_context: RepositoryContext,
|
|
68
|
+
resource: Writable<Subscription>,
|
|
69
|
+
{ key }: SubscriptionSetKeyAction,
|
|
70
|
+
) {
|
|
71
|
+
resource.key = key;
|
|
48
72
|
}
|
|
49
73
|
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
TaxCategory,
|
|
3
|
+
TaxCategoryAddTaxRateAction,
|
|
4
|
+
TaxCategoryChangeNameAction,
|
|
5
|
+
TaxCategoryRemoveTaxRateAction,
|
|
6
|
+
TaxCategoryReplaceTaxRateAction,
|
|
7
|
+
TaxCategorySetDescriptionAction,
|
|
8
|
+
TaxCategorySetKeyAction,
|
|
9
|
+
TaxCategoryUpdateAction,
|
|
10
|
+
} from "@commercetools/platform-sdk";
|
|
11
|
+
import type { Writable } from "~src/types";
|
|
12
|
+
import { AbstractUpdateHandler, RepositoryContext } from "../abstract";
|
|
13
|
+
import { taxRateFromTaxRateDraft } from "./helpers";
|
|
14
|
+
|
|
15
|
+
type TaxCategoryUpdateHandlerMethod<T> = (
|
|
16
|
+
context: RepositoryContext,
|
|
17
|
+
resource: Writable<TaxCategory>,
|
|
18
|
+
action: T,
|
|
19
|
+
) => void;
|
|
20
|
+
|
|
21
|
+
type TaxCategoryUpdateActions = {
|
|
22
|
+
[P in TaxCategoryUpdateAction as P["action"]]: TaxCategoryUpdateHandlerMethod<P>;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export class TaxCategoryUpdateHandler
|
|
26
|
+
extends AbstractUpdateHandler
|
|
27
|
+
implements TaxCategoryUpdateActions
|
|
28
|
+
{
|
|
29
|
+
addTaxRate(
|
|
30
|
+
context: RepositoryContext,
|
|
31
|
+
resource: Writable<TaxCategory>,
|
|
32
|
+
{ taxRate }: TaxCategoryAddTaxRateAction,
|
|
33
|
+
) {
|
|
34
|
+
if (resource.rates === undefined) {
|
|
35
|
+
resource.rates = [];
|
|
36
|
+
}
|
|
37
|
+
resource.rates.push(taxRateFromTaxRateDraft(taxRate));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
changeName(
|
|
41
|
+
context: RepositoryContext,
|
|
42
|
+
resource: Writable<TaxCategory>,
|
|
43
|
+
{ name }: TaxCategoryChangeNameAction,
|
|
44
|
+
) {
|
|
45
|
+
resource.name = name;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
removeTaxRate(
|
|
49
|
+
context: RepositoryContext,
|
|
50
|
+
resource: Writable<TaxCategory>,
|
|
51
|
+
{ taxRateId }: TaxCategoryRemoveTaxRateAction,
|
|
52
|
+
) {
|
|
53
|
+
if (resource.rates === undefined) {
|
|
54
|
+
resource.rates = [];
|
|
55
|
+
}
|
|
56
|
+
resource.rates = resource.rates.filter(
|
|
57
|
+
(taxRate) => taxRate.id !== taxRateId,
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
replaceTaxRate(
|
|
62
|
+
context: RepositoryContext,
|
|
63
|
+
resource: Writable<TaxCategory>,
|
|
64
|
+
{ taxRateId, taxRate }: TaxCategoryReplaceTaxRateAction,
|
|
65
|
+
) {
|
|
66
|
+
if (resource.rates === undefined) {
|
|
67
|
+
resource.rates = [];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const taxRateObj = taxRateFromTaxRateDraft(taxRate);
|
|
71
|
+
for (let i = 0; i < resource.rates.length; i++) {
|
|
72
|
+
const rate = resource.rates[i];
|
|
73
|
+
if (rate.id === taxRateId) {
|
|
74
|
+
resource.rates[i] = taxRateObj;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
setDescription(
|
|
80
|
+
context: RepositoryContext,
|
|
81
|
+
resource: Writable<TaxCategory>,
|
|
82
|
+
{ description }: TaxCategorySetDescriptionAction,
|
|
83
|
+
) {
|
|
84
|
+
resource.description = description;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
setKey(
|
|
88
|
+
context: RepositoryContext,
|
|
89
|
+
resource: Writable<TaxCategory>,
|
|
90
|
+
{ key }: TaxCategorySetKeyAction,
|
|
91
|
+
) {
|
|
92
|
+
resource.key = key;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
TaxCategory,
|
|
3
|
+
TaxCategoryDraft,
|
|
4
|
+
} from "@commercetools/platform-sdk";
|
|
5
|
+
import { getBaseResourceProperties } from "~src/helpers";
|
|
6
|
+
import { AbstractStorage } from "~src/storage/abstract";
|
|
7
|
+
import { AbstractResourceRepository, RepositoryContext } from "../abstract";
|
|
8
|
+
import { TaxCategoryUpdateHandler } from "./actions";
|
|
9
|
+
import { taxRateFromTaxRateDraft } from "./helpers";
|
|
10
|
+
|
|
11
|
+
export class TaxCategoryRepository extends AbstractResourceRepository<"tax-category"> {
|
|
12
|
+
constructor(storage: AbstractStorage) {
|
|
13
|
+
super("tax-category", storage);
|
|
14
|
+
this.actions = new TaxCategoryUpdateHandler(this._storage);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
create(context: RepositoryContext, draft: TaxCategoryDraft): TaxCategory {
|
|
18
|
+
const resource: TaxCategory = {
|
|
19
|
+
...getBaseResourceProperties(),
|
|
20
|
+
...draft,
|
|
21
|
+
rates: draft.rates?.map(taxRateFromTaxRateDraft) || [],
|
|
22
|
+
};
|
|
23
|
+
return this.saveNew(context, resource);
|
|
24
|
+
}
|
|
25
|
+
}
|