@labdigital/commercetools-mock 2.17.1 → 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 +4186 -3974
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +266 -413
- package/dist/index.d.ts +266 -413
- package/dist/index.js +4186 -3974
- 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 +86 -86
- package/src/oauth/server.ts +158 -144
- package/src/oauth/store.ts +44 -43
- 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 +23 -36
- 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,5 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AssociateRoleReference,
|
|
3
|
+
BusinessUnitKeyReference,
|
|
4
|
+
BusinessUnitReference,
|
|
5
|
+
BusinessUnitResourceIdentifier,
|
|
3
6
|
type Address,
|
|
4
7
|
type Associate,
|
|
5
8
|
type AssociateDraft,
|
|
@@ -26,50 +29,47 @@ import {
|
|
|
26
29
|
type Type,
|
|
27
30
|
type TypedMoney,
|
|
28
31
|
type _Money,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
} from
|
|
33
|
-
import
|
|
34
|
-
import {
|
|
35
|
-
import { CommercetoolsError } from '../exceptions.js'
|
|
36
|
-
import { AbstractStorage } from '../storage/index.js'
|
|
37
|
-
import { type RepositoryContext } from './abstract.js'
|
|
32
|
+
} from "@commercetools/platform-sdk";
|
|
33
|
+
import type { Request } from "express";
|
|
34
|
+
import { v4 as uuidv4 } from "uuid";
|
|
35
|
+
import { CommercetoolsError } from "~src/exceptions";
|
|
36
|
+
import { AbstractStorage } from "../storage";
|
|
37
|
+
import { type RepositoryContext } from "./abstract";
|
|
38
38
|
|
|
39
39
|
export const createAddress = (
|
|
40
40
|
base: BaseAddress | undefined,
|
|
41
41
|
projectKey: string,
|
|
42
|
-
storage: AbstractStorage
|
|
42
|
+
storage: AbstractStorage,
|
|
43
43
|
): Address | undefined => {
|
|
44
|
-
if (!base) return undefined
|
|
44
|
+
if (!base) return undefined;
|
|
45
45
|
|
|
46
46
|
if (!base?.country) {
|
|
47
|
-
throw new Error(
|
|
47
|
+
throw new Error("Country is required");
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
return {
|
|
51
51
|
...base,
|
|
52
|
-
}
|
|
53
|
-
}
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
54
|
|
|
55
55
|
export const createCustomFields = (
|
|
56
56
|
draft: CustomFieldsDraft | undefined,
|
|
57
57
|
projectKey: string,
|
|
58
|
-
storage: AbstractStorage
|
|
58
|
+
storage: AbstractStorage,
|
|
59
59
|
): CustomFields | undefined => {
|
|
60
|
-
if (!draft) return undefined
|
|
61
|
-
if (!draft.type) return undefined
|
|
62
|
-
if (!draft.type.typeId) return undefined
|
|
63
|
-
if (!draft.fields) return undefined
|
|
60
|
+
if (!draft) return undefined;
|
|
61
|
+
if (!draft.type) return undefined;
|
|
62
|
+
if (!draft.type.typeId) return undefined;
|
|
63
|
+
if (!draft.fields) return undefined;
|
|
64
64
|
const typeResource = storage.getByResourceIdentifier(
|
|
65
65
|
projectKey,
|
|
66
|
-
draft.type
|
|
67
|
-
) as Type
|
|
66
|
+
draft.type,
|
|
67
|
+
) as Type;
|
|
68
68
|
|
|
69
69
|
if (!typeResource) {
|
|
70
70
|
throw new Error(
|
|
71
|
-
`No type '${draft.type.typeId}' with id=${draft.type.id} or key=${draft.type.key}
|
|
72
|
-
)
|
|
71
|
+
`No type '${draft.type.typeId}' with id=${draft.type.id} or key=${draft.type.key}`,
|
|
72
|
+
);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
return {
|
|
@@ -78,241 +78,240 @@ export const createCustomFields = (
|
|
|
78
78
|
id: typeResource.id,
|
|
79
79
|
},
|
|
80
80
|
fields: draft.fields,
|
|
81
|
-
}
|
|
82
|
-
}
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
83
|
|
|
84
84
|
export const createPrice = (draft: PriceDraft): Price => ({
|
|
85
85
|
id: uuidv4(),
|
|
86
86
|
value: createTypedMoney(draft.value),
|
|
87
|
-
})
|
|
87
|
+
});
|
|
88
88
|
|
|
89
89
|
export const createCentPrecisionMoney = (value: _Money): CentPrecisionMoney => {
|
|
90
90
|
// Taken from https://docs.adyen.com/development-resources/currency-codes
|
|
91
|
-
let fractionDigits = 2
|
|
91
|
+
let fractionDigits = 2;
|
|
92
92
|
switch (value.currencyCode.toUpperCase()) {
|
|
93
|
-
case
|
|
94
|
-
case
|
|
95
|
-
case
|
|
96
|
-
case
|
|
97
|
-
case
|
|
98
|
-
case
|
|
99
|
-
case
|
|
100
|
-
fractionDigits = 3
|
|
101
|
-
break
|
|
102
|
-
case
|
|
103
|
-
case
|
|
104
|
-
case
|
|
105
|
-
case
|
|
106
|
-
case
|
|
107
|
-
case
|
|
108
|
-
case
|
|
109
|
-
case
|
|
110
|
-
case
|
|
111
|
-
case
|
|
112
|
-
case
|
|
113
|
-
case
|
|
114
|
-
case
|
|
115
|
-
case
|
|
116
|
-
case
|
|
117
|
-
fractionDigits = 0
|
|
118
|
-
break
|
|
93
|
+
case "BHD":
|
|
94
|
+
case "IQD":
|
|
95
|
+
case "JOD":
|
|
96
|
+
case "KWD":
|
|
97
|
+
case "LYD":
|
|
98
|
+
case "OMR":
|
|
99
|
+
case "TND":
|
|
100
|
+
fractionDigits = 3;
|
|
101
|
+
break;
|
|
102
|
+
case "CVE":
|
|
103
|
+
case "DJF":
|
|
104
|
+
case "GNF":
|
|
105
|
+
case "IDR":
|
|
106
|
+
case "JPY":
|
|
107
|
+
case "KMF":
|
|
108
|
+
case "KRW":
|
|
109
|
+
case "PYG":
|
|
110
|
+
case "RWF":
|
|
111
|
+
case "UGX":
|
|
112
|
+
case "VND":
|
|
113
|
+
case "VUV":
|
|
114
|
+
case "XAF":
|
|
115
|
+
case "XOF":
|
|
116
|
+
case "XPF":
|
|
117
|
+
fractionDigits = 0;
|
|
118
|
+
break;
|
|
119
119
|
default:
|
|
120
|
-
fractionDigits = 2
|
|
120
|
+
fractionDigits = 2;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
if ((value as HighPrecisionMoney & HighPrecisionMoneyDraft).preciseAmount) {
|
|
124
|
-
throw new Error(
|
|
124
|
+
throw new Error("HighPrecisionMoney not supported");
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
return {
|
|
128
|
-
type:
|
|
128
|
+
type: "centPrecision",
|
|
129
129
|
// centAmont is only optional on HighPrecisionMoney, so this should never
|
|
130
130
|
// fallback to 0
|
|
131
131
|
centAmount: value.centAmount ?? 0,
|
|
132
132
|
currencyCode: value.currencyCode,
|
|
133
133
|
fractionDigits: fractionDigits,
|
|
134
|
-
}
|
|
135
|
-
}
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
136
|
|
|
137
137
|
export const createTypedMoney = (value: _Money): TypedMoney => {
|
|
138
|
-
const result = createCentPrecisionMoney(value)
|
|
139
|
-
return result
|
|
140
|
-
}
|
|
138
|
+
const result = createCentPrecisionMoney(value);
|
|
139
|
+
return result;
|
|
140
|
+
};
|
|
141
141
|
|
|
142
142
|
export const resolveStoreReference = (
|
|
143
143
|
ref: StoreResourceIdentifier | undefined,
|
|
144
144
|
projectKey: string,
|
|
145
|
-
storage: AbstractStorage
|
|
145
|
+
storage: AbstractStorage,
|
|
146
146
|
): StoreKeyReference | undefined => {
|
|
147
|
-
if (!ref) return undefined
|
|
148
|
-
const resource = storage.getByResourceIdentifier(projectKey, ref)
|
|
147
|
+
if (!ref) return undefined;
|
|
148
|
+
const resource = storage.getByResourceIdentifier(projectKey, ref);
|
|
149
149
|
if (!resource) {
|
|
150
|
-
throw new Error(
|
|
150
|
+
throw new Error("No such store");
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
const store = resource as Store
|
|
153
|
+
const store = resource as Store;
|
|
154
154
|
return {
|
|
155
|
-
typeId:
|
|
155
|
+
typeId: "store",
|
|
156
156
|
key: store.key,
|
|
157
|
-
}
|
|
158
|
-
}
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
159
|
|
|
160
160
|
export const getReferenceFromResourceIdentifier = <T extends Reference>(
|
|
161
161
|
resourceIdentifier: ResourceIdentifier,
|
|
162
162
|
projectKey: string,
|
|
163
|
-
storage: AbstractStorage
|
|
163
|
+
storage: AbstractStorage,
|
|
164
164
|
): T => {
|
|
165
165
|
if (!resourceIdentifier.id && !resourceIdentifier.key) {
|
|
166
166
|
throw new CommercetoolsError<InvalidJsonInputError>(
|
|
167
167
|
{
|
|
168
|
-
code:
|
|
168
|
+
code: "InvalidJsonInput",
|
|
169
169
|
message: `${resourceIdentifier.typeId}: ResourceIdentifier requires an 'id' xor a 'key'`,
|
|
170
170
|
detailedErrorMessage: `ResourceIdentifier requires an 'id' xor a 'key'`,
|
|
171
171
|
},
|
|
172
|
-
400
|
|
173
|
-
)
|
|
172
|
+
400,
|
|
173
|
+
);
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
const resource = storage.getByResourceIdentifier(
|
|
177
177
|
projectKey,
|
|
178
|
-
resourceIdentifier
|
|
179
|
-
)
|
|
178
|
+
resourceIdentifier,
|
|
179
|
+
);
|
|
180
180
|
if (!resource) {
|
|
181
181
|
const errIdentifier = resourceIdentifier.key
|
|
182
182
|
? `key '${resourceIdentifier.key}'`
|
|
183
|
-
: `identifier '${resourceIdentifier.id}'
|
|
183
|
+
: `identifier '${resourceIdentifier.id}'`;
|
|
184
184
|
|
|
185
185
|
throw new CommercetoolsError<ReferencedResourceNotFoundError>(
|
|
186
186
|
{
|
|
187
|
-
code:
|
|
187
|
+
code: "ReferencedResourceNotFound",
|
|
188
188
|
// @ts-ignore
|
|
189
189
|
typeId: resourceIdentifier.typeId,
|
|
190
190
|
message: `The referenced object of type '${resourceIdentifier.typeId}' with '${errIdentifier}' was not found. It either doesn't exist, or it can't be accessed from this endpoint (e.g., if the endpoint filters by store or customer account).`,
|
|
191
191
|
},
|
|
192
|
-
400
|
|
193
|
-
)
|
|
192
|
+
400,
|
|
193
|
+
);
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
return {
|
|
197
197
|
typeId: resourceIdentifier.typeId,
|
|
198
198
|
id: resource?.id,
|
|
199
|
-
} as unknown as T
|
|
200
|
-
}
|
|
199
|
+
} as unknown as T;
|
|
200
|
+
};
|
|
201
201
|
|
|
202
202
|
export const getStoreKeyReference = (
|
|
203
203
|
id: StoreResourceIdentifier,
|
|
204
204
|
projectKey: string,
|
|
205
|
-
storage: AbstractStorage
|
|
205
|
+
storage: AbstractStorage,
|
|
206
206
|
): StoreKeyReference => {
|
|
207
207
|
if (id.key) {
|
|
208
208
|
return {
|
|
209
|
-
typeId:
|
|
209
|
+
typeId: "store",
|
|
210
210
|
key: id.key,
|
|
211
|
-
}
|
|
211
|
+
};
|
|
212
212
|
}
|
|
213
213
|
const value = getReferenceFromResourceIdentifier<StoreReference>(
|
|
214
214
|
id,
|
|
215
215
|
projectKey,
|
|
216
|
-
storage
|
|
217
|
-
)
|
|
216
|
+
storage,
|
|
217
|
+
);
|
|
218
218
|
|
|
219
219
|
if (!value.obj?.key) {
|
|
220
|
-
throw new Error(
|
|
220
|
+
throw new Error("No store found for reference");
|
|
221
221
|
}
|
|
222
222
|
return {
|
|
223
|
-
typeId:
|
|
223
|
+
typeId: "store",
|
|
224
224
|
key: value.obj?.key,
|
|
225
|
-
}
|
|
226
|
-
}
|
|
225
|
+
};
|
|
226
|
+
};
|
|
227
227
|
|
|
228
228
|
export const getRepositoryContext = (request: Request): RepositoryContext => ({
|
|
229
229
|
projectKey: request.params.projectKey,
|
|
230
230
|
storeKey: request.params.storeKey,
|
|
231
|
-
})
|
|
231
|
+
});
|
|
232
232
|
|
|
233
233
|
export const createAssociate = (
|
|
234
234
|
a: AssociateDraft,
|
|
235
235
|
projectKey: string,
|
|
236
|
-
storage: AbstractStorage
|
|
236
|
+
storage: AbstractStorage,
|
|
237
237
|
): Associate | undefined => {
|
|
238
|
-
if (!a) return undefined
|
|
238
|
+
if (!a) return undefined;
|
|
239
239
|
|
|
240
240
|
if (!a.associateRoleAssignments) {
|
|
241
|
-
throw new Error(
|
|
241
|
+
throw new Error("AssociateRoleAssignments is required");
|
|
242
242
|
}
|
|
243
243
|
|
|
244
244
|
return {
|
|
245
245
|
customer: getReferenceFromResourceIdentifier(
|
|
246
246
|
a.customer,
|
|
247
247
|
projectKey,
|
|
248
|
-
storage
|
|
248
|
+
storage,
|
|
249
249
|
),
|
|
250
250
|
associateRoleAssignments: a.associateRoleAssignments?.map(
|
|
251
251
|
(a: AssociateRoleAssignmentDraft): AssociateRoleAssignment => ({
|
|
252
252
|
associateRole: getAssociateRoleKeyReference(
|
|
253
253
|
a.associateRole,
|
|
254
254
|
projectKey,
|
|
255
|
-
storage
|
|
255
|
+
storage,
|
|
256
256
|
),
|
|
257
257
|
inheritance: a.inheritance as string,
|
|
258
|
-
})
|
|
258
|
+
}),
|
|
259
259
|
),
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
}
|
|
260
|
+
};
|
|
261
|
+
};
|
|
263
262
|
|
|
264
263
|
export const getAssociateRoleKeyReference = (
|
|
265
264
|
id: AssociateRoleResourceIdentifier,
|
|
266
265
|
projectKey: string,
|
|
267
|
-
storage: AbstractStorage
|
|
266
|
+
storage: AbstractStorage,
|
|
268
267
|
): AssociateRoleKeyReference => {
|
|
269
268
|
if (id.key) {
|
|
270
269
|
return {
|
|
271
|
-
typeId:
|
|
270
|
+
typeId: "associate-role",
|
|
272
271
|
key: id.key,
|
|
273
|
-
}
|
|
272
|
+
};
|
|
274
273
|
}
|
|
275
274
|
|
|
276
275
|
const value = getReferenceFromResourceIdentifier<AssociateRoleReference>(
|
|
277
276
|
id,
|
|
278
277
|
projectKey,
|
|
279
|
-
storage
|
|
280
|
-
)
|
|
278
|
+
storage,
|
|
279
|
+
);
|
|
281
280
|
|
|
282
281
|
if (!value.obj?.key) {
|
|
283
|
-
throw new Error(
|
|
282
|
+
throw new Error("No associate-role found for reference");
|
|
284
283
|
}
|
|
285
284
|
|
|
286
285
|
return {
|
|
287
|
-
typeId:
|
|
286
|
+
typeId: "associate-role",
|
|
288
287
|
key: value.obj?.key,
|
|
289
|
-
}
|
|
290
|
-
}
|
|
288
|
+
};
|
|
289
|
+
};
|
|
291
290
|
|
|
292
291
|
export const getBusinessUnitKeyReference = (
|
|
293
292
|
id: BusinessUnitResourceIdentifier,
|
|
294
293
|
projectKey: string,
|
|
295
|
-
storage: AbstractStorage
|
|
294
|
+
storage: AbstractStorage,
|
|
296
295
|
): BusinessUnitKeyReference => {
|
|
297
296
|
if (id.key) {
|
|
298
297
|
return {
|
|
299
|
-
typeId:
|
|
298
|
+
typeId: "business-unit",
|
|
300
299
|
key: id.key,
|
|
301
|
-
}
|
|
300
|
+
};
|
|
302
301
|
}
|
|
303
302
|
|
|
304
303
|
const value = getReferenceFromResourceIdentifier<BusinessUnitReference>(
|
|
305
304
|
id,
|
|
306
305
|
projectKey,
|
|
307
|
-
storage
|
|
308
|
-
)
|
|
306
|
+
storage,
|
|
307
|
+
);
|
|
309
308
|
|
|
310
309
|
if (!value.obj?.key) {
|
|
311
|
-
throw new Error(
|
|
310
|
+
throw new Error("No business-unit found for reference");
|
|
312
311
|
}
|
|
313
312
|
|
|
314
313
|
return {
|
|
315
|
-
typeId:
|
|
314
|
+
typeId: "business-unit",
|
|
316
315
|
key: value.obj?.key,
|
|
317
|
-
}
|
|
318
|
-
}
|
|
316
|
+
};
|
|
317
|
+
};
|
|
@@ -1,82 +1,83 @@
|
|
|
1
|
-
import { AbstractStorage } from
|
|
2
|
-
import { AssociateRoleRepository } from
|
|
3
|
-
import { AttributeGroupRepository } from
|
|
4
|
-
import { BusinessUnitRepository } from
|
|
5
|
-
import { CartRepository } from
|
|
6
|
-
import { CartDiscountRepository } from
|
|
7
|
-
import { CategoryRepository } from
|
|
8
|
-
import { ChannelRepository } from
|
|
9
|
-
import { CustomObjectRepository } from
|
|
10
|
-
import { CustomerRepository } from
|
|
11
|
-
import { CustomerGroupRepository } from
|
|
12
|
-
import { DiscountCodeRepository } from
|
|
13
|
-
import { ExtensionRepository } from
|
|
14
|
-
import { InventoryEntryRepository } from
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
37
|
-
import {
|
|
1
|
+
import { AbstractStorage } from "../storage";
|
|
2
|
+
import { AssociateRoleRepository } from "./associate-role";
|
|
3
|
+
import { AttributeGroupRepository } from "./attribute-group";
|
|
4
|
+
import { BusinessUnitRepository } from "./business-unit";
|
|
5
|
+
import { CartRepository } from "./cart";
|
|
6
|
+
import { CartDiscountRepository } from "./cart-discount";
|
|
7
|
+
import { CategoryRepository } from "./category";
|
|
8
|
+
import { ChannelRepository } from "./channel";
|
|
9
|
+
import { CustomObjectRepository } from "./custom-object";
|
|
10
|
+
import { CustomerRepository } from "./customer";
|
|
11
|
+
import { CustomerGroupRepository } from "./customer-group";
|
|
12
|
+
import { DiscountCodeRepository } from "./discount-code";
|
|
13
|
+
import { ExtensionRepository } from "./extension";
|
|
14
|
+
import { InventoryEntryRepository } from "./inventory-entry";
|
|
15
|
+
import { MyCustomerRepository } from "./my-customer";
|
|
16
|
+
import { MyOrderRepository } from "./my-order";
|
|
17
|
+
import { OrderRepository } from "./order";
|
|
18
|
+
import { OrderEditRepository } from "./order-edit";
|
|
19
|
+
import { PaymentRepository } from "./payment";
|
|
20
|
+
import { ProductRepository } from "./product";
|
|
21
|
+
import { ProductDiscountRepository } from "./product-discount";
|
|
22
|
+
import { ProductProjectionRepository } from "./product-projection";
|
|
23
|
+
import { ProductSelectionRepository } from "./product-selection";
|
|
24
|
+
import { ProductTypeRepository } from "./product-type";
|
|
25
|
+
import { ProjectRepository } from "./project";
|
|
26
|
+
import { QuoteRepository } from "./quote";
|
|
27
|
+
import { QuoteRequestRepository } from "./quote-request";
|
|
28
|
+
import { ReviewRepository } from "./review";
|
|
29
|
+
import { ShippingMethodRepository } from "./shipping-method";
|
|
30
|
+
import { ShoppingListRepository } from "./shopping-list";
|
|
31
|
+
import { StagedQuoteRepository } from "./staged-quote";
|
|
32
|
+
import { StandAlonePriceRepository } from "./standalone-price";
|
|
33
|
+
import { StateRepository } from "./state";
|
|
34
|
+
import { StoreRepository } from "./store";
|
|
35
|
+
import { SubscriptionRepository } from "./subscription";
|
|
36
|
+
import { TaxCategoryRepository } from "./tax-category";
|
|
37
|
+
import { TypeRepository } from "./type";
|
|
38
|
+
import { ZoneRepository } from "./zone";
|
|
38
39
|
|
|
39
|
-
export type RepositoryMap = ReturnType<typeof createRepositories
|
|
40
|
+
export type RepositoryMap = ReturnType<typeof createRepositories>;
|
|
40
41
|
|
|
41
42
|
export const createRepositories = (storage: AbstractStorage) => ({
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
category: new CategoryRepository(storage),
|
|
46
|
-
cart: new CartRepository(storage),
|
|
47
|
-
|
|
48
|
-
customer: new CustomerRepository(storage),
|
|
49
|
-
channel: new ChannelRepository(storage),
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
extension: new ExtensionRepository(storage),
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
order: new OrderRepository(storage),
|
|
56
|
-
|
|
57
|
-
payment: new PaymentRepository(storage),
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
product: new ProductRepository(storage),
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
project: new ProjectRepository(storage),
|
|
69
|
-
review: new ReviewRepository(storage),
|
|
70
|
-
quote: new QuoteRepository(storage),
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
state: new StateRepository(storage),
|
|
77
|
-
store: new StoreRepository(storage),
|
|
78
|
-
subscription: new SubscriptionRepository(storage),
|
|
79
|
-
|
|
80
|
-
type: new TypeRepository(storage),
|
|
81
|
-
zone: new ZoneRepository(storage),
|
|
82
|
-
})
|
|
43
|
+
"associate-role": new AssociateRoleRepository(storage),
|
|
44
|
+
"attribute-group": new AttributeGroupRepository(storage),
|
|
45
|
+
"business-unit": new BusinessUnitRepository(storage),
|
|
46
|
+
"category": new CategoryRepository(storage),
|
|
47
|
+
"cart": new CartRepository(storage),
|
|
48
|
+
"cart-discount": new CartDiscountRepository(storage),
|
|
49
|
+
"customer": new CustomerRepository(storage),
|
|
50
|
+
"channel": new ChannelRepository(storage),
|
|
51
|
+
"customer-group": new CustomerGroupRepository(storage),
|
|
52
|
+
"discount-code": new DiscountCodeRepository(storage),
|
|
53
|
+
"extension": new ExtensionRepository(storage),
|
|
54
|
+
"inventory-entry": new InventoryEntryRepository(storage),
|
|
55
|
+
"key-value-document": new CustomObjectRepository(storage),
|
|
56
|
+
"order": new OrderRepository(storage),
|
|
57
|
+
"order-edit": new OrderEditRepository(storage),
|
|
58
|
+
"payment": new PaymentRepository(storage),
|
|
59
|
+
"my-cart": new CartRepository(storage),
|
|
60
|
+
"my-order": new MyOrderRepository(storage),
|
|
61
|
+
"my-customer": new MyCustomerRepository(storage),
|
|
62
|
+
"my-payment": new PaymentRepository(storage),
|
|
63
|
+
"my-shopping-list": new ShoppingListRepository(storage),
|
|
64
|
+
"product": new ProductRepository(storage),
|
|
65
|
+
"product-type": new ProductTypeRepository(storage),
|
|
66
|
+
"product-discount": new ProductDiscountRepository(storage),
|
|
67
|
+
"product-projection": new ProductProjectionRepository(storage),
|
|
68
|
+
"product-selection": new ProductSelectionRepository(storage),
|
|
69
|
+
"project": new ProjectRepository(storage),
|
|
70
|
+
"review": new ReviewRepository(storage),
|
|
71
|
+
"quote": new QuoteRepository(storage),
|
|
72
|
+
"quote-request": new QuoteRequestRepository(storage),
|
|
73
|
+
"shipping-method": new ShippingMethodRepository(storage),
|
|
74
|
+
"shopping-list": new ShoppingListRepository(storage),
|
|
75
|
+
"staged-quote": new StagedQuoteRepository(storage),
|
|
76
|
+
"standalone-price": new StandAlonePriceRepository(storage),
|
|
77
|
+
"state": new StateRepository(storage),
|
|
78
|
+
"store": new StoreRepository(storage),
|
|
79
|
+
"subscription": new SubscriptionRepository(storage),
|
|
80
|
+
"tax-category": new TaxCategoryRepository(storage),
|
|
81
|
+
"type": new TypeRepository(storage),
|
|
82
|
+
"zone": new ZoneRepository(storage),
|
|
83
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
InventoryEntry,
|
|
3
|
+
InventoryEntryChangeQuantityAction,
|
|
4
|
+
InventoryEntrySetCustomFieldAction,
|
|
5
|
+
InventoryEntrySetCustomTypeAction,
|
|
6
|
+
InventoryEntrySetExpectedDeliveryAction,
|
|
7
|
+
InventoryEntrySetRestockableInDaysAction,
|
|
8
|
+
InventoryEntryUpdateAction,
|
|
9
|
+
} from "@commercetools/platform-sdk";
|
|
10
|
+
import type { Writable } from "~src/types";
|
|
11
|
+
import {
|
|
12
|
+
AbstractUpdateHandler,
|
|
13
|
+
UpdateHandlerInterface,
|
|
14
|
+
type RepositoryContext,
|
|
15
|
+
} from "../abstract";
|
|
16
|
+
|
|
17
|
+
export class InventoryEntryUpdateHandler
|
|
18
|
+
extends AbstractUpdateHandler
|
|
19
|
+
implements
|
|
20
|
+
Partial<UpdateHandlerInterface<InventoryEntry, InventoryEntryUpdateAction>>
|
|
21
|
+
{
|
|
22
|
+
changeQuantity(
|
|
23
|
+
context: RepositoryContext,
|
|
24
|
+
resource: Writable<InventoryEntry>,
|
|
25
|
+
{ quantity }: InventoryEntryChangeQuantityAction,
|
|
26
|
+
) {
|
|
27
|
+
resource.quantityOnStock = quantity;
|
|
28
|
+
// don't know active reservations so just set to same value
|
|
29
|
+
resource.availableQuantity = quantity;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
setCustomField(
|
|
33
|
+
context: RepositoryContext,
|
|
34
|
+
resource: InventoryEntry,
|
|
35
|
+
{ name, value }: InventoryEntrySetCustomFieldAction,
|
|
36
|
+
) {
|
|
37
|
+
if (!resource.custom) {
|
|
38
|
+
throw new Error("Resource has no custom field");
|
|
39
|
+
}
|
|
40
|
+
resource.custom.fields[name] = value;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
setCustomType(
|
|
44
|
+
context: RepositoryContext,
|
|
45
|
+
resource: Writable<InventoryEntry>,
|
|
46
|
+
{ type, fields }: InventoryEntrySetCustomTypeAction,
|
|
47
|
+
) {
|
|
48
|
+
if (!type) {
|
|
49
|
+
resource.custom = undefined;
|
|
50
|
+
} else {
|
|
51
|
+
const resolvedType = this._storage.getByResourceIdentifier(
|
|
52
|
+
context.projectKey,
|
|
53
|
+
type,
|
|
54
|
+
);
|
|
55
|
+
if (!resolvedType) {
|
|
56
|
+
throw new Error(`Type ${type} not found`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
resource.custom = {
|
|
60
|
+
type: {
|
|
61
|
+
typeId: "type",
|
|
62
|
+
id: resolvedType.id,
|
|
63
|
+
},
|
|
64
|
+
fields: fields || {},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
setExpectedDelivery(
|
|
70
|
+
context: RepositoryContext,
|
|
71
|
+
resource: Writable<InventoryEntry>,
|
|
72
|
+
{ expectedDelivery }: InventoryEntrySetExpectedDeliveryAction,
|
|
73
|
+
) {
|
|
74
|
+
resource.expectedDelivery = new Date(expectedDelivery!).toISOString();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
setRestockableInDays(
|
|
78
|
+
context: RepositoryContext,
|
|
79
|
+
resource: Writable<InventoryEntry>,
|
|
80
|
+
{ restockableInDays }: InventoryEntrySetRestockableInDaysAction,
|
|
81
|
+
) {
|
|
82
|
+
resource.restockableInDays = restockableInDays;
|
|
83
|
+
}
|
|
84
|
+
}
|