@labdigital/commercetools-mock 1.1.3 → 1.3.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.d.mts +602 -0
- package/dist/index.d.ts +43 -26
- package/dist/index.global.js +6322 -6084
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +347 -163
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +343 -163
- package/dist/index.mjs.map +1 -1
- package/package.json +35 -41
- package/src/index.test.ts +2 -1
- package/src/lib/haversine.test.ts +1 -0
- package/src/lib/predicateParser.test.ts +2 -1
- package/src/lib/projectionSearchFilter.test.ts +2 -1
- package/src/lib/projectionSearchFilter.ts +2 -2
- package/src/oauth/server.ts +3 -4
- package/src/priceSelector.test.ts +2 -1
- package/src/priceSelector.ts +2 -2
- package/src/product-projection-search.ts +8 -8
- package/src/projectAPI.test.ts +1 -0
- package/src/repositories/abstract.ts +1 -1
- package/src/repositories/associate-role.ts +11 -0
- package/src/repositories/attribute-group.ts +11 -0
- package/src/repositories/business-unit.ts +11 -0
- package/src/repositories/cart-discount.ts +11 -4
- package/src/repositories/cart.ts +91 -9
- package/src/repositories/category.ts +3 -3
- package/src/repositories/channel.ts +3 -3
- package/src/repositories/custom-object.ts +3 -3
- package/src/repositories/customer-group.ts +3 -3
- package/src/repositories/customer.ts +4 -3
- package/src/repositories/discount-code.ts +3 -3
- package/src/repositories/errors.ts +1 -1
- package/src/repositories/extension.ts +3 -3
- package/src/repositories/helpers.ts +49 -6
- package/src/repositories/index.ts +6 -0
- package/src/repositories/inventory-entry.ts +4 -4
- package/src/repositories/my-order.ts +2 -2
- package/src/repositories/order-edit.ts +2 -2
- package/src/repositories/order.test.ts +10 -39
- package/src/repositories/order.ts +31 -16
- package/src/repositories/payment.ts +8 -7
- package/src/repositories/product-discount.ts +2 -2
- package/src/repositories/product-projection.ts +5 -5
- package/src/repositories/product-selection.ts +3 -2
- package/src/repositories/product-type.ts +2 -2
- package/src/repositories/product.ts +4 -9
- package/src/repositories/project.ts +2 -2
- package/src/repositories/quote-request.ts +2 -2
- package/src/repositories/quote.ts +2 -2
- package/src/repositories/review.ts +2 -2
- package/src/repositories/shipping-method.ts +10 -2
- package/src/repositories/shopping-list.ts +19 -13
- package/src/repositories/staged-quote.ts +2 -2
- package/src/repositories/standalone-price.ts +3 -3
- package/src/repositories/state.ts +2 -2
- package/src/repositories/store.ts +3 -2
- package/src/repositories/subscription.ts +1 -1
- package/src/repositories/tax-category.ts +2 -2
- package/src/repositories/type.ts +2 -2
- package/src/repositories/zone.ts +2 -2
- package/src/services/abstract.ts +2 -2
- package/src/services/cart.test.ts +2 -1
- package/src/services/cart.ts +4 -4
- package/src/services/category.test.ts +2 -1
- package/src/services/custom-object.test.ts +2 -1
- package/src/services/custom-object.ts +3 -3
- package/src/services/customer.test.ts +1 -0
- package/src/services/inventory-entry.test.ts +2 -1
- package/src/services/my-cart.test.ts +7 -3
- package/src/services/my-customer.test.ts +4 -2
- package/src/services/my-payment.test.ts +2 -1
- package/src/services/order.test.ts +2 -1
- package/src/services/payment.test.ts +2 -1
- package/src/services/product-projection.test.ts +3 -2
- package/src/services/product-type.test.ts +2 -1
- package/src/services/product.test.ts +2 -1
- package/src/services/project.ts +1 -1
- package/src/services/shipping-method.test.ts +2 -1
- package/src/services/standalone-price.test.ts +255 -244
- package/src/services/state.test.ts +2 -1
- package/src/services/store.test.ts +6 -1
- package/src/services/tax-category.test.ts +2 -1
- package/src/storage/abstract.ts +1 -1
- package/src/storage/in-memory.ts +7 -1
- package/src/types.ts +7 -1
package/dist/index.mjs
CHANGED
|
@@ -24,8 +24,8 @@ var CommercetoolsError = class extends Error {
|
|
|
24
24
|
import { v4 as uuidv4 } from "uuid";
|
|
25
25
|
var getBaseResourceProperties = () => ({
|
|
26
26
|
id: uuidv4(),
|
|
27
|
-
createdAt: new Date().toISOString(),
|
|
28
|
-
lastModifiedAt: new Date().toISOString(),
|
|
27
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
28
|
+
lastModifiedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
29
29
|
version: 0
|
|
30
30
|
});
|
|
31
31
|
var nestedLookup = (obj, path) => {
|
|
@@ -104,14 +104,13 @@ var parseQueryExpression = (predicate) => {
|
|
|
104
104
|
}
|
|
105
105
|
};
|
|
106
106
|
var validateSymbol = (val) => {
|
|
107
|
-
var _a, _b;
|
|
108
107
|
if (!val.type) {
|
|
109
108
|
throw new PredicateError("Internal error");
|
|
110
109
|
}
|
|
111
110
|
if (val.type === "identifier") {
|
|
112
111
|
const char = val.value.charAt(0);
|
|
113
|
-
const line =
|
|
114
|
-
const column =
|
|
112
|
+
const line = val.pos?.start.line;
|
|
113
|
+
const column = val.pos?.start.column;
|
|
115
114
|
throw new PredicateError(
|
|
116
115
|
`Invalid input '${char}', expected input parameter or primitive value (line ${line}, column ${column})`
|
|
117
116
|
);
|
|
@@ -162,6 +161,7 @@ var generateMatchFunc = (predicate) => {
|
|
|
162
161
|
100,
|
|
163
162
|
(t) => ({
|
|
164
163
|
type: "var",
|
|
164
|
+
// @ts-ignore
|
|
165
165
|
value: t.token.groups[1],
|
|
166
166
|
pos: t.token.strpos()
|
|
167
167
|
})
|
|
@@ -170,6 +170,7 @@ var generateMatchFunc = (predicate) => {
|
|
|
170
170
|
100,
|
|
171
171
|
(t) => ({
|
|
172
172
|
type: "string",
|
|
173
|
+
// @ts-ignore
|
|
173
174
|
value: t.token.groups[1],
|
|
174
175
|
pos: t.token.strpos()
|
|
175
176
|
})
|
|
@@ -412,6 +413,7 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
412
413
|
return project;
|
|
413
414
|
};
|
|
414
415
|
this.getProject = (projectKey) => this.addProject(projectKey);
|
|
416
|
+
// Expand resolves a nested reference and injects the object in the given obj
|
|
415
417
|
this.expand = (projectKey, obj, clause) => {
|
|
416
418
|
if (!clause)
|
|
417
419
|
return obj;
|
|
@@ -453,6 +455,9 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
453
455
|
let projectStorage = this.resources[projectKey];
|
|
454
456
|
if (!projectStorage) {
|
|
455
457
|
projectStorage = this.resources[projectKey] = {
|
|
458
|
+
"associate-role": /* @__PURE__ */ new Map(),
|
|
459
|
+
"attribute-group": /* @__PURE__ */ new Map(),
|
|
460
|
+
"business-unit": /* @__PURE__ */ new Map(),
|
|
456
461
|
cart: /* @__PURE__ */ new Map(),
|
|
457
462
|
"cart-discount": /* @__PURE__ */ new Map(),
|
|
458
463
|
category: /* @__PURE__ */ new Map(),
|
|
@@ -491,7 +496,7 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
491
496
|
clear() {
|
|
492
497
|
for (const [, projectStorage] of Object.entries(this.resources)) {
|
|
493
498
|
for (const [, value] of Object.entries(projectStorage)) {
|
|
494
|
-
value
|
|
499
|
+
value?.clear();
|
|
495
500
|
}
|
|
496
501
|
}
|
|
497
502
|
}
|
|
@@ -503,16 +508,14 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
503
508
|
return [];
|
|
504
509
|
}
|
|
505
510
|
add(projectKey, typeId, obj, params = {}) {
|
|
506
|
-
var _a;
|
|
507
511
|
const store = this.forProjectKey(projectKey);
|
|
508
|
-
|
|
512
|
+
store[typeId]?.set(obj.id, obj);
|
|
509
513
|
const resource = this.get(projectKey, typeId, obj.id, params);
|
|
510
514
|
assert(resource, `resource of type ${typeId} with id ${obj.id} not created`);
|
|
511
515
|
return cloneObject(resource);
|
|
512
516
|
}
|
|
513
517
|
get(projectKey, typeId, id, params = {}) {
|
|
514
|
-
|
|
515
|
-
const resource = (_a = this.forProjectKey(projectKey)[typeId]) == null ? void 0 : _a.get(id);
|
|
518
|
+
const resource = this.forProjectKey(projectKey)[typeId]?.get(id);
|
|
516
519
|
if (resource) {
|
|
517
520
|
const clone = cloneObject(resource);
|
|
518
521
|
return this.expand(projectKey, clone, params.expand);
|
|
@@ -534,10 +537,9 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
534
537
|
return null;
|
|
535
538
|
}
|
|
536
539
|
delete(projectKey, typeId, id, params = {}) {
|
|
537
|
-
var _a;
|
|
538
540
|
const resource = this.get(projectKey, typeId, id);
|
|
539
541
|
if (resource) {
|
|
540
|
-
|
|
542
|
+
this.forProjectKey(projectKey)[typeId]?.delete(id);
|
|
541
543
|
return this.expand(projectKey, resource, params.expand);
|
|
542
544
|
}
|
|
543
545
|
return resource;
|
|
@@ -627,6 +629,7 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
627
629
|
const store = this.forProjectKey(projectKey)[identifier.typeId];
|
|
628
630
|
if (store) {
|
|
629
631
|
const resource = Array.from(store.values()).find(
|
|
632
|
+
// @ts-ignore
|
|
630
633
|
(r) => r.key === identifier.key
|
|
631
634
|
);
|
|
632
635
|
if (resource) {
|
|
@@ -696,11 +699,10 @@ var OAuth2Store = class {
|
|
|
696
699
|
|
|
697
700
|
// src/oauth/helpers.ts
|
|
698
701
|
var getBearerToken = (request) => {
|
|
699
|
-
var _a;
|
|
700
702
|
const authHeader = request.header("Authorization");
|
|
701
|
-
const match = authHeader
|
|
703
|
+
const match = authHeader?.match(/^Bearer\s(?<token>[^\s]+)$/);
|
|
702
704
|
if (match) {
|
|
703
|
-
return
|
|
705
|
+
return match.groups?.token;
|
|
704
706
|
}
|
|
705
707
|
return void 0;
|
|
706
708
|
};
|
|
@@ -723,7 +725,7 @@ var OAuth2Server = class {
|
|
|
723
725
|
next(
|
|
724
726
|
new CommercetoolsError(
|
|
725
727
|
{
|
|
726
|
-
code: "
|
|
728
|
+
code: "invalid_token",
|
|
727
729
|
message: "This endpoint requires an access token. You can get one from the authorization server."
|
|
728
730
|
},
|
|
729
731
|
401
|
|
@@ -745,7 +747,6 @@ var OAuth2Server = class {
|
|
|
745
747
|
};
|
|
746
748
|
}
|
|
747
749
|
async tokenHandler(request, response, next) {
|
|
748
|
-
var _a;
|
|
749
750
|
const authHeader = request.header("Authorization");
|
|
750
751
|
if (!authHeader) {
|
|
751
752
|
return next(
|
|
@@ -786,7 +787,7 @@ var OAuth2Server = class {
|
|
|
786
787
|
const token = this.store.getClientToken(
|
|
787
788
|
credentials.name,
|
|
788
789
|
credentials.pass,
|
|
789
|
-
|
|
790
|
+
request.query.scope?.toString()
|
|
790
791
|
);
|
|
791
792
|
return response.status(200).send(token);
|
|
792
793
|
} else {
|
|
@@ -829,6 +830,7 @@ var ProjectAPI = class {
|
|
|
829
830
|
params
|
|
830
831
|
);
|
|
831
832
|
}
|
|
833
|
+
// TODO: Not sure if we want to expose this...
|
|
832
834
|
getRepository(typeId) {
|
|
833
835
|
const repository = this._repositories[typeId];
|
|
834
836
|
if (repository !== void 0) {
|
|
@@ -859,7 +861,7 @@ import { v4 as uuidv42 } from "uuid";
|
|
|
859
861
|
var createAddress = (base, projectKey, storage) => {
|
|
860
862
|
if (!base)
|
|
861
863
|
return void 0;
|
|
862
|
-
if (!
|
|
864
|
+
if (!base?.country) {
|
|
863
865
|
throw new Error("Country is required");
|
|
864
866
|
}
|
|
865
867
|
return {
|
|
@@ -896,7 +898,7 @@ var createPrice = (draft) => ({
|
|
|
896
898
|
id: uuidv42(),
|
|
897
899
|
value: createTypedMoney(draft.value)
|
|
898
900
|
});
|
|
899
|
-
var
|
|
901
|
+
var createCentPrecisionMoney = (value) => {
|
|
900
902
|
let fractionDigits = 2;
|
|
901
903
|
switch (value.currencyCode.toUpperCase()) {
|
|
902
904
|
case "BHD":
|
|
@@ -928,12 +930,22 @@ var createTypedMoney = (value) => {
|
|
|
928
930
|
default:
|
|
929
931
|
fractionDigits = 2;
|
|
930
932
|
}
|
|
933
|
+
if (value.preciseAmount) {
|
|
934
|
+
throw new Error("HighPrecisionMoney not supported");
|
|
935
|
+
}
|
|
931
936
|
return {
|
|
932
937
|
type: "centPrecision",
|
|
933
|
-
|
|
938
|
+
// centAmont is only optional on HighPrecisionMoney, so this should never
|
|
939
|
+
// fallback to 0
|
|
940
|
+
centAmount: value.centAmount ?? 0,
|
|
941
|
+
currencyCode: value.currencyCode,
|
|
934
942
|
fractionDigits
|
|
935
943
|
};
|
|
936
944
|
};
|
|
945
|
+
var createTypedMoney = (value) => {
|
|
946
|
+
const result = createCentPrecisionMoney(value);
|
|
947
|
+
return result;
|
|
948
|
+
};
|
|
937
949
|
var resolveStoreReference = (ref, projectKey, storage) => {
|
|
938
950
|
if (!ref)
|
|
939
951
|
return void 0;
|
|
@@ -952,7 +964,8 @@ var getReferenceFromResourceIdentifier = (resourceIdentifier, projectKey, storag
|
|
|
952
964
|
throw new CommercetoolsError(
|
|
953
965
|
{
|
|
954
966
|
code: "InvalidJsonInput",
|
|
955
|
-
message: `${resourceIdentifier.typeId}: ResourceIdentifier requires an 'id' xor a 'key'
|
|
967
|
+
message: `${resourceIdentifier.typeId}: ResourceIdentifier requires an 'id' xor a 'key'`,
|
|
968
|
+
detailedErrorMessage: `ResourceIdentifier requires an 'id' xor a 'key'`
|
|
956
969
|
},
|
|
957
970
|
400
|
|
958
971
|
);
|
|
@@ -966,6 +979,7 @@ var getReferenceFromResourceIdentifier = (resourceIdentifier, projectKey, storag
|
|
|
966
979
|
throw new CommercetoolsError(
|
|
967
980
|
{
|
|
968
981
|
code: "ReferencedResourceNotFound",
|
|
982
|
+
// @ts-ignore
|
|
969
983
|
typeId: resourceIdentifier.typeId,
|
|
970
984
|
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).`
|
|
971
985
|
},
|
|
@@ -974,7 +988,27 @@ var getReferenceFromResourceIdentifier = (resourceIdentifier, projectKey, storag
|
|
|
974
988
|
}
|
|
975
989
|
return {
|
|
976
990
|
typeId: resourceIdentifier.typeId,
|
|
977
|
-
id: resource
|
|
991
|
+
id: resource?.id
|
|
992
|
+
};
|
|
993
|
+
};
|
|
994
|
+
var getStoreKeyReference = (id, projectKey, storage) => {
|
|
995
|
+
if (id.key) {
|
|
996
|
+
return {
|
|
997
|
+
typeId: "store",
|
|
998
|
+
key: id.key
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
const value = getReferenceFromResourceIdentifier(
|
|
1002
|
+
id,
|
|
1003
|
+
projectKey,
|
|
1004
|
+
storage
|
|
1005
|
+
);
|
|
1006
|
+
if (!value.obj?.key) {
|
|
1007
|
+
throw new Error("No store found for reference");
|
|
1008
|
+
}
|
|
1009
|
+
return {
|
|
1010
|
+
typeId: "store",
|
|
1011
|
+
key: value.obj?.key
|
|
978
1012
|
};
|
|
979
1013
|
};
|
|
980
1014
|
var getRepositoryContext = (request) => ({
|
|
@@ -1012,9 +1046,6 @@ var ProjectService = class {
|
|
|
1012
1046
|
}
|
|
1013
1047
|
};
|
|
1014
1048
|
|
|
1015
|
-
// src/repositories/cart.ts
|
|
1016
|
-
import { v4 as uuidv43 } from "uuid";
|
|
1017
|
-
|
|
1018
1049
|
// src/repositories/abstract.ts
|
|
1019
1050
|
import deepEqual from "deep-equal";
|
|
1020
1051
|
|
|
@@ -1136,19 +1167,49 @@ var AbstractResourceRepository = class extends AbstractRepository {
|
|
|
1136
1167
|
if (current.version === resource.version) {
|
|
1137
1168
|
throw new Error("Internal error: no changes to save");
|
|
1138
1169
|
}
|
|
1139
|
-
resource.lastModifiedAt = new Date().toISOString();
|
|
1170
|
+
resource.lastModifiedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1140
1171
|
this._storage.add(context.projectKey, this.getTypeId(), resource);
|
|
1141
1172
|
return resource;
|
|
1142
1173
|
}
|
|
1143
1174
|
};
|
|
1144
1175
|
|
|
1176
|
+
// src/repositories/associate-role.ts
|
|
1177
|
+
var AssociateRoleRepository = class extends AbstractResourceRepository {
|
|
1178
|
+
getTypeId() {
|
|
1179
|
+
return "associate-role";
|
|
1180
|
+
}
|
|
1181
|
+
create(context, draft) {
|
|
1182
|
+
throw new Error("Method not implemented.");
|
|
1183
|
+
}
|
|
1184
|
+
};
|
|
1185
|
+
|
|
1186
|
+
// src/repositories/attribute-group.ts
|
|
1187
|
+
var AttributeGroupRepository = class extends AbstractResourceRepository {
|
|
1188
|
+
getTypeId() {
|
|
1189
|
+
return "attribute-group";
|
|
1190
|
+
}
|
|
1191
|
+
create(context, draft) {
|
|
1192
|
+
throw new Error("Method not implemented.");
|
|
1193
|
+
}
|
|
1194
|
+
};
|
|
1195
|
+
|
|
1196
|
+
// src/repositories/business-unit.ts
|
|
1197
|
+
var BusinessUnitRepository = class extends AbstractResourceRepository {
|
|
1198
|
+
getTypeId() {
|
|
1199
|
+
return "business-unit";
|
|
1200
|
+
}
|
|
1201
|
+
create(context, draft) {
|
|
1202
|
+
throw new Error("Method not implemented.");
|
|
1203
|
+
}
|
|
1204
|
+
};
|
|
1205
|
+
|
|
1145
1206
|
// src/repositories/cart.ts
|
|
1207
|
+
import { v4 as uuidv43 } from "uuid";
|
|
1146
1208
|
var CartRepository = class extends AbstractResourceRepository {
|
|
1147
1209
|
constructor() {
|
|
1148
1210
|
super(...arguments);
|
|
1149
1211
|
this.actions = {
|
|
1150
1212
|
addLineItem: (context, resource, { productId, variantId, sku, quantity = 1 }) => {
|
|
1151
|
-
var _a;
|
|
1152
1213
|
let product = null;
|
|
1153
1214
|
if (productId && variantId) {
|
|
1154
1215
|
product = this._storage.get(
|
|
@@ -1190,18 +1251,18 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1190
1251
|
});
|
|
1191
1252
|
}
|
|
1192
1253
|
const alreadyAdded = resource.lineItems.some(
|
|
1193
|
-
(x) => x.productId ===
|
|
1254
|
+
(x) => x.productId === product?.id && x.variant.id === variant?.id
|
|
1194
1255
|
);
|
|
1195
1256
|
if (alreadyAdded) {
|
|
1196
1257
|
resource.lineItems.map((x) => {
|
|
1197
|
-
if (x.productId ===
|
|
1258
|
+
if (x.productId === product?.id && x.variant.id === variant?.id) {
|
|
1198
1259
|
x.quantity += quantity;
|
|
1199
1260
|
x.totalPrice.centAmount = calculateLineItemTotalPrice(x);
|
|
1200
1261
|
}
|
|
1201
1262
|
return x;
|
|
1202
1263
|
});
|
|
1203
1264
|
} else {
|
|
1204
|
-
if (!
|
|
1265
|
+
if (!variant.prices?.length) {
|
|
1205
1266
|
throw new CommercetoolsError({
|
|
1206
1267
|
code: "General",
|
|
1207
1268
|
message: `A product with ID '${productId}' doesn't have any prices.`
|
|
@@ -1231,6 +1292,7 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1231
1292
|
perMethodTaxRate: [],
|
|
1232
1293
|
totalPrice: {
|
|
1233
1294
|
...price.value,
|
|
1295
|
+
type: "centPrecision",
|
|
1234
1296
|
centAmount: price.value.centAmount * quantity
|
|
1235
1297
|
},
|
|
1236
1298
|
quantity,
|
|
@@ -1242,6 +1304,46 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1242
1304
|
}
|
|
1243
1305
|
resource.totalPrice.centAmount = calculateCartTotalPrice(resource);
|
|
1244
1306
|
},
|
|
1307
|
+
changeLineItemQuantity: (context, resource, { lineItemId, lineItemKey, quantity }) => {
|
|
1308
|
+
let lineItem;
|
|
1309
|
+
if (lineItemId) {
|
|
1310
|
+
lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
1311
|
+
if (!lineItem) {
|
|
1312
|
+
throw new CommercetoolsError({
|
|
1313
|
+
code: "General",
|
|
1314
|
+
message: `A line item with ID '${lineItemId}' not found.`
|
|
1315
|
+
});
|
|
1316
|
+
}
|
|
1317
|
+
} else if (lineItemKey) {
|
|
1318
|
+
lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
1319
|
+
if (!lineItem) {
|
|
1320
|
+
throw new CommercetoolsError({
|
|
1321
|
+
code: "General",
|
|
1322
|
+
message: `A line item with Key '${lineItemKey}' not found.`
|
|
1323
|
+
});
|
|
1324
|
+
}
|
|
1325
|
+
} else {
|
|
1326
|
+
throw new CommercetoolsError({
|
|
1327
|
+
code: "General",
|
|
1328
|
+
message: `Either lineItemid or lineItemKey needs to be provided.`
|
|
1329
|
+
});
|
|
1330
|
+
}
|
|
1331
|
+
const shouldDelete = !quantity || quantity >= lineItem.quantity;
|
|
1332
|
+
if (shouldDelete) {
|
|
1333
|
+
resource.lineItems = resource.lineItems.filter(
|
|
1334
|
+
(x) => x.id !== lineItemId
|
|
1335
|
+
);
|
|
1336
|
+
} else {
|
|
1337
|
+
resource.lineItems.map((x) => {
|
|
1338
|
+
if (x.id === lineItemId && quantity) {
|
|
1339
|
+
x.quantity -= quantity;
|
|
1340
|
+
x.totalPrice.centAmount = calculateLineItemTotalPrice(x);
|
|
1341
|
+
}
|
|
1342
|
+
return x;
|
|
1343
|
+
});
|
|
1344
|
+
}
|
|
1345
|
+
resource.totalPrice.centAmount = calculateCartTotalPrice(resource);
|
|
1346
|
+
},
|
|
1245
1347
|
removeLineItem: (context, resource, { lineItemId, quantity }) => {
|
|
1246
1348
|
const lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
1247
1349
|
if (!lineItem) {
|
|
@@ -1267,7 +1369,11 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1267
1369
|
resource.totalPrice.centAmount = calculateCartTotalPrice(resource);
|
|
1268
1370
|
},
|
|
1269
1371
|
setBillingAddress: (context, resource, { address }) => {
|
|
1270
|
-
resource.billingAddress =
|
|
1372
|
+
resource.billingAddress = createAddress(
|
|
1373
|
+
address,
|
|
1374
|
+
context.projectKey,
|
|
1375
|
+
this._storage
|
|
1376
|
+
);
|
|
1271
1377
|
},
|
|
1272
1378
|
setShippingMethod: (context, resource, { shippingMethod }) => {
|
|
1273
1379
|
if (shippingMethod) {
|
|
@@ -1317,7 +1423,7 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1317
1423
|
typeId: "type",
|
|
1318
1424
|
id: resolvedType.id
|
|
1319
1425
|
},
|
|
1320
|
-
fields: fields ||
|
|
1426
|
+
fields: fields || {}
|
|
1321
1427
|
};
|
|
1322
1428
|
}
|
|
1323
1429
|
},
|
|
@@ -1325,7 +1431,22 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1325
1431
|
resource.locale = locale;
|
|
1326
1432
|
},
|
|
1327
1433
|
setShippingAddress: (context, resource, { address }) => {
|
|
1328
|
-
|
|
1434
|
+
if (!address) {
|
|
1435
|
+
resource.shippingAddress = void 0;
|
|
1436
|
+
return;
|
|
1437
|
+
}
|
|
1438
|
+
let custom = void 0;
|
|
1439
|
+
if (address.custom) {
|
|
1440
|
+
custom = createCustomFields(
|
|
1441
|
+
address.custom,
|
|
1442
|
+
context.projectKey,
|
|
1443
|
+
this._storage
|
|
1444
|
+
);
|
|
1445
|
+
}
|
|
1446
|
+
resource.shippingAddress = {
|
|
1447
|
+
...address,
|
|
1448
|
+
custom
|
|
1449
|
+
};
|
|
1329
1450
|
}
|
|
1330
1451
|
};
|
|
1331
1452
|
this.draftLineItemtoLineItem = (projectKey, draftLineItem, currency, country) => {
|
|
@@ -1381,7 +1502,9 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1381
1502
|
variant,
|
|
1382
1503
|
price,
|
|
1383
1504
|
totalPrice: {
|
|
1384
|
-
|
|
1505
|
+
type: "centPrecision",
|
|
1506
|
+
currencyCode: price.value.currencyCode,
|
|
1507
|
+
fractionDigits: price.value.fractionDigits,
|
|
1385
1508
|
centAmount: price.value.centAmount * quant
|
|
1386
1509
|
},
|
|
1387
1510
|
taxedPricePortions: [],
|
|
@@ -1398,20 +1521,23 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1398
1521
|
return "cart";
|
|
1399
1522
|
}
|
|
1400
1523
|
create(context, draft) {
|
|
1401
|
-
|
|
1402
|
-
const lineItems = ((_a = draft.lineItems) == null ? void 0 : _a.map(
|
|
1524
|
+
const lineItems = draft.lineItems?.map(
|
|
1403
1525
|
(draftLineItem) => this.draftLineItemtoLineItem(
|
|
1404
1526
|
context.projectKey,
|
|
1405
1527
|
draftLineItem,
|
|
1406
1528
|
draft.currency,
|
|
1407
1529
|
draft.country
|
|
1408
1530
|
)
|
|
1409
|
-
)
|
|
1531
|
+
) ?? [];
|
|
1410
1532
|
const resource = {
|
|
1411
1533
|
...getBaseResourceProperties(),
|
|
1412
1534
|
cartState: "Active",
|
|
1413
1535
|
country: draft.country,
|
|
1414
1536
|
customLineItems: [],
|
|
1537
|
+
directDiscounts: [],
|
|
1538
|
+
discountCodes: [],
|
|
1539
|
+
inventoryMode: "None",
|
|
1540
|
+
itemShippingAddresses: [],
|
|
1415
1541
|
lineItems,
|
|
1416
1542
|
locale: draft.locale,
|
|
1417
1543
|
taxCalculationMode: draft.taxCalculationMode ?? "LineItemLevel",
|
|
@@ -1504,6 +1630,9 @@ var CartDiscountRepository = class extends AbstractResourceRepository {
|
|
|
1504
1630
|
cartPredicate: draft.cartPredicate,
|
|
1505
1631
|
isActive: draft.isActive || false,
|
|
1506
1632
|
name: draft.name,
|
|
1633
|
+
stores: draft.stores?.map(
|
|
1634
|
+
(s) => getStoreKeyReference(s, context.projectKey, this._storage)
|
|
1635
|
+
) ?? [],
|
|
1507
1636
|
references: [],
|
|
1508
1637
|
target: draft.target,
|
|
1509
1638
|
requiresDiscountCode: draft.requiresDiscountCode || false,
|
|
@@ -1552,8 +1681,7 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
1552
1681
|
super(...arguments);
|
|
1553
1682
|
this.actions = {
|
|
1554
1683
|
changeAssetName: (context, resource, { assetId, assetKey, name }) => {
|
|
1555
|
-
|
|
1556
|
-
(_a = resource.assets) == null ? void 0 : _a.forEach((asset) => {
|
|
1684
|
+
resource.assets?.forEach((asset) => {
|
|
1557
1685
|
if (assetId && assetId === asset.id) {
|
|
1558
1686
|
asset.name = name;
|
|
1559
1687
|
}
|
|
@@ -1569,8 +1697,7 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
1569
1697
|
resource.key = key;
|
|
1570
1698
|
},
|
|
1571
1699
|
setAssetDescription: (context, resource, { assetId, assetKey, description }) => {
|
|
1572
|
-
|
|
1573
|
-
(_a = resource.assets) == null ? void 0 : _a.forEach((asset) => {
|
|
1700
|
+
resource.assets?.forEach((asset) => {
|
|
1574
1701
|
if (assetId && assetId === asset.id) {
|
|
1575
1702
|
asset.description = description;
|
|
1576
1703
|
}
|
|
@@ -1580,8 +1707,7 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
1580
1707
|
});
|
|
1581
1708
|
},
|
|
1582
1709
|
setAssetSources: (context, resource, { assetId, assetKey, sources }) => {
|
|
1583
|
-
|
|
1584
|
-
(_a = resource.assets) == null ? void 0 : _a.forEach((asset) => {
|
|
1710
|
+
resource.assets?.forEach((asset) => {
|
|
1585
1711
|
if (assetId && assetId === asset.id) {
|
|
1586
1712
|
asset.sources = sources;
|
|
1587
1713
|
}
|
|
@@ -1629,7 +1755,6 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
1629
1755
|
return "category";
|
|
1630
1756
|
}
|
|
1631
1757
|
create(context, draft) {
|
|
1632
|
-
var _a;
|
|
1633
1758
|
const resource = {
|
|
1634
1759
|
...getBaseResourceProperties(),
|
|
1635
1760
|
key: draft.key,
|
|
@@ -1639,7 +1764,8 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
1639
1764
|
externalId: draft.externalId || "",
|
|
1640
1765
|
parent: draft.parent ? { typeId: "category", id: draft.parent.id } : void 0,
|
|
1641
1766
|
ancestors: [],
|
|
1642
|
-
|
|
1767
|
+
// TODO
|
|
1768
|
+
assets: draft.assets?.map((d) => ({
|
|
1643
1769
|
id: uuidv44(),
|
|
1644
1770
|
name: d.name,
|
|
1645
1771
|
description: d.description,
|
|
@@ -1651,7 +1777,7 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
1651
1777
|
context.projectKey,
|
|
1652
1778
|
this._storage
|
|
1653
1779
|
)
|
|
1654
|
-
}))
|
|
1780
|
+
})) || [],
|
|
1655
1781
|
custom: createCustomFields(
|
|
1656
1782
|
draft.custom,
|
|
1657
1783
|
context.projectKey,
|
|
@@ -1831,6 +1957,7 @@ var CustomerRepository = class extends AbstractResourceRepository {
|
|
|
1831
1957
|
create(context, draft) {
|
|
1832
1958
|
const resource = {
|
|
1833
1959
|
...getBaseResourceProperties(),
|
|
1960
|
+
authenticationMode: draft.authenticationMode || "Password",
|
|
1834
1961
|
email: draft.email,
|
|
1835
1962
|
password: draft.password ? Buffer.from(draft.password).toString("base64") : void 0,
|
|
1836
1963
|
isEmailVerified: draft.isEmailVerified || false,
|
|
@@ -2048,10 +2175,9 @@ var ExtensionRepository = class extends AbstractResourceRepository {
|
|
|
2048
2175
|
return "extension";
|
|
2049
2176
|
}
|
|
2050
2177
|
postProcessResource(resource) {
|
|
2051
|
-
var _a;
|
|
2052
2178
|
if (resource) {
|
|
2053
2179
|
const extension = resource;
|
|
2054
|
-
if (extension.destination.type === "HTTP" &&
|
|
2180
|
+
if (extension.destination.type === "HTTP" && extension.destination.authentication?.type === "AuthorizationHeader") {
|
|
2055
2181
|
return maskSecretValue(
|
|
2056
2182
|
extension,
|
|
2057
2183
|
"destination.authentication.headerValue"
|
|
@@ -2109,7 +2235,7 @@ var InventoryEntryRepository = class extends AbstractResourceRepository {
|
|
|
2109
2235
|
typeId: "type",
|
|
2110
2236
|
id: resolvedType.id
|
|
2111
2237
|
},
|
|
2112
|
-
fields: fields ||
|
|
2238
|
+
fields: fields || {}
|
|
2113
2239
|
};
|
|
2114
2240
|
}
|
|
2115
2241
|
},
|
|
@@ -2122,7 +2248,6 @@ var InventoryEntryRepository = class extends AbstractResourceRepository {
|
|
|
2122
2248
|
return "inventory-entry";
|
|
2123
2249
|
}
|
|
2124
2250
|
create(context, draft) {
|
|
2125
|
-
var _a;
|
|
2126
2251
|
const resource = {
|
|
2127
2252
|
...getBaseResourceProperties(),
|
|
2128
2253
|
sku: draft.sku,
|
|
@@ -2133,7 +2258,7 @@ var InventoryEntryRepository = class extends AbstractResourceRepository {
|
|
|
2133
2258
|
supplyChannel: {
|
|
2134
2259
|
...draft.supplyChannel,
|
|
2135
2260
|
typeId: "channel",
|
|
2136
|
-
id:
|
|
2261
|
+
id: draft.supplyChannel?.id ?? ""
|
|
2137
2262
|
},
|
|
2138
2263
|
custom: createCustomFields(
|
|
2139
2264
|
draft.custom,
|
|
@@ -2192,7 +2317,11 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2192
2317
|
resource.state = { typeId: "state", id: resolvedType.id };
|
|
2193
2318
|
},
|
|
2194
2319
|
setBillingAddress: (context, resource, { address }) => {
|
|
2195
|
-
resource.billingAddress =
|
|
2320
|
+
resource.billingAddress = createAddress(
|
|
2321
|
+
address,
|
|
2322
|
+
context.projectKey,
|
|
2323
|
+
this._storage
|
|
2324
|
+
);
|
|
2196
2325
|
},
|
|
2197
2326
|
setCustomerEmail: (context, resource, { email }) => {
|
|
2198
2327
|
resource.customerEmail = email;
|
|
@@ -2219,7 +2348,7 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2219
2348
|
typeId: "type",
|
|
2220
2349
|
id: resolvedType.id
|
|
2221
2350
|
},
|
|
2222
|
-
fields: fields ||
|
|
2351
|
+
fields: fields || {}
|
|
2223
2352
|
};
|
|
2224
2353
|
}
|
|
2225
2354
|
},
|
|
@@ -2230,7 +2359,11 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2230
2359
|
resource.orderNumber = orderNumber;
|
|
2231
2360
|
},
|
|
2232
2361
|
setShippingAddress: (context, resource, { address }) => {
|
|
2233
|
-
resource.shippingAddress =
|
|
2362
|
+
resource.shippingAddress = createAddress(
|
|
2363
|
+
address,
|
|
2364
|
+
context.projectKey,
|
|
2365
|
+
this._storage
|
|
2366
|
+
);
|
|
2234
2367
|
},
|
|
2235
2368
|
setStore: (context, resource, { store }) => {
|
|
2236
2369
|
if (!store)
|
|
@@ -2295,12 +2428,19 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2295
2428
|
return resource;
|
|
2296
2429
|
}
|
|
2297
2430
|
import(context, draft) {
|
|
2298
|
-
var _a, _b;
|
|
2299
2431
|
assert2(this, "OrderRepository not valid");
|
|
2300
2432
|
const resource = {
|
|
2301
2433
|
...getBaseResourceProperties(),
|
|
2302
|
-
billingAddress:
|
|
2303
|
-
|
|
2434
|
+
billingAddress: createAddress(
|
|
2435
|
+
draft.billingAddress,
|
|
2436
|
+
context.projectKey,
|
|
2437
|
+
this._storage
|
|
2438
|
+
),
|
|
2439
|
+
shippingAddress: createAddress(
|
|
2440
|
+
draft.shippingAddress,
|
|
2441
|
+
context.projectKey,
|
|
2442
|
+
this._storage
|
|
2443
|
+
),
|
|
2304
2444
|
custom: createCustomFields(
|
|
2305
2445
|
draft.custom,
|
|
2306
2446
|
context.projectKey,
|
|
@@ -2321,17 +2461,13 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2321
2461
|
this._storage
|
|
2322
2462
|
),
|
|
2323
2463
|
syncInfo: [],
|
|
2324
|
-
lineItems:
|
|
2464
|
+
lineItems: draft.lineItems?.map(
|
|
2325
2465
|
(item) => this.lineItemFromImportDraft.bind(this)(context, item)
|
|
2326
|
-
)
|
|
2327
|
-
customLineItems:
|
|
2466
|
+
) || [],
|
|
2467
|
+
customLineItems: draft.customLineItems?.map(
|
|
2328
2468
|
(item) => this.customLineItemFromImportDraft.bind(this)(context, item)
|
|
2329
|
-
)
|
|
2330
|
-
totalPrice:
|
|
2331
|
-
type: "centPrecision",
|
|
2332
|
-
...draft.totalPrice,
|
|
2333
|
-
fractionDigits: 2
|
|
2334
|
-
}
|
|
2469
|
+
) || [],
|
|
2470
|
+
totalPrice: createCentPrecisionMoney(draft.totalPrice)
|
|
2335
2471
|
};
|
|
2336
2472
|
this.saveNew(context, resource);
|
|
2337
2473
|
return resource;
|
|
@@ -2388,7 +2524,7 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2388
2524
|
taxRate: draft.taxRate,
|
|
2389
2525
|
taxedPricePortions: [],
|
|
2390
2526
|
perMethodTaxRate: [],
|
|
2391
|
-
totalPrice:
|
|
2527
|
+
totalPrice: createCentPrecisionMoney(draft.price.value),
|
|
2392
2528
|
variant: {
|
|
2393
2529
|
id: variant.id,
|
|
2394
2530
|
sku: variant.sku,
|
|
@@ -2408,11 +2544,12 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2408
2544
|
discountedPricePerQuantity: [],
|
|
2409
2545
|
money: createTypedMoney(draft.money),
|
|
2410
2546
|
name: draft.name,
|
|
2411
|
-
quantity: draft.quantity,
|
|
2547
|
+
quantity: draft.quantity ?? 0,
|
|
2548
|
+
perMethodTaxRate: [],
|
|
2412
2549
|
priceMode: draft.priceMode,
|
|
2413
2550
|
slug: draft.slug,
|
|
2414
2551
|
state: [],
|
|
2415
|
-
totalPrice:
|
|
2552
|
+
totalPrice: createCentPrecisionMoney(draft.money)
|
|
2416
2553
|
};
|
|
2417
2554
|
return lineItem;
|
|
2418
2555
|
}
|
|
@@ -2474,8 +2611,10 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
2474
2611
|
this.transactionFromTransactionDraft = (draft, context) => ({
|
|
2475
2612
|
...draft,
|
|
2476
2613
|
id: uuidv45(),
|
|
2477
|
-
amount:
|
|
2478
|
-
custom: createCustomFields(draft.custom, context.projectKey, this._storage)
|
|
2614
|
+
amount: createCentPrecisionMoney(draft.amount),
|
|
2615
|
+
custom: createCustomFields(draft.custom, context.projectKey, this._storage),
|
|
2616
|
+
state: draft.state ?? "Initial"
|
|
2617
|
+
// Documented as default
|
|
2479
2618
|
});
|
|
2480
2619
|
this.actions = {
|
|
2481
2620
|
setCustomField: (context, resource, { name, value }) => {
|
|
@@ -2500,7 +2639,7 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
2500
2639
|
typeId: "type",
|
|
2501
2640
|
id: resolvedType.id
|
|
2502
2641
|
},
|
|
2503
|
-
fields: fields
|
|
2642
|
+
fields: fields ?? {}
|
|
2504
2643
|
};
|
|
2505
2644
|
}
|
|
2506
2645
|
},
|
|
@@ -2534,6 +2673,23 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
2534
2673
|
obj: stateObj
|
|
2535
2674
|
};
|
|
2536
2675
|
}
|
|
2676
|
+
// addInterfaceInteraction: () => {},
|
|
2677
|
+
// changeAmountPlanned: () => {},
|
|
2678
|
+
// changeTransactionInteractionId: () => {},
|
|
2679
|
+
// changeTransactionTimestamp: () => {},
|
|
2680
|
+
// setAmountPaid: () => {},
|
|
2681
|
+
// setAmountRefunded: () => {},
|
|
2682
|
+
// setAnonymousId: () => {},
|
|
2683
|
+
// setAuthorization: () => {},
|
|
2684
|
+
// setCustomer: () => {},
|
|
2685
|
+
// setExternalId: () => {},
|
|
2686
|
+
// setInterfaceId: () => {},
|
|
2687
|
+
// setKey: () => {},
|
|
2688
|
+
// setMethodInfoInterface: () => {},
|
|
2689
|
+
// setMethodInfoMethod: () => {},
|
|
2690
|
+
// setMethodInfoName: () => {},
|
|
2691
|
+
// setStatusInterfaceCode: () => {},
|
|
2692
|
+
// setStatusInterfaceText: () => {},
|
|
2537
2693
|
};
|
|
2538
2694
|
}
|
|
2539
2695
|
getTypeId() {
|
|
@@ -2542,7 +2698,7 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
2542
2698
|
create(context, draft) {
|
|
2543
2699
|
const resource = {
|
|
2544
2700
|
...getBaseResourceProperties(),
|
|
2545
|
-
amountPlanned:
|
|
2701
|
+
amountPlanned: createCentPrecisionMoney(draft.amountPlanned),
|
|
2546
2702
|
paymentMethodInfo: draft.paymentMethodInfo,
|
|
2547
2703
|
paymentStatus: draft.paymentStatus ? {
|
|
2548
2704
|
...draft.paymentStatus,
|
|
@@ -2788,13 +2944,9 @@ var ProductRepository = class extends AbstractResourceRepository {
|
|
|
2788
2944
|
},
|
|
2789
2945
|
changePrice: (context, resource, { priceId, price, staged }) => {
|
|
2790
2946
|
const changeVariantPrice = (data) => {
|
|
2791
|
-
var _a;
|
|
2792
2947
|
const allVariants = [data.masterVariant, ...data.variants ?? []];
|
|
2793
2948
|
const priceVariant = allVariants.find(
|
|
2794
|
-
(variant2) =>
|
|
2795
|
-
var _a2;
|
|
2796
|
-
return (_a2 = variant2.prices) == null ? void 0 : _a2.some((x) => x.id === priceId);
|
|
2797
|
-
}
|
|
2949
|
+
(variant2) => variant2.prices?.some((x) => x.id === priceId)
|
|
2798
2950
|
);
|
|
2799
2951
|
if (!priceVariant) {
|
|
2800
2952
|
throw new Error(
|
|
@@ -2811,7 +2963,7 @@ var ProductRepository = class extends AbstractResourceRepository {
|
|
|
2811
2963
|
`Variant with id ${priceVariant.id} or sku ${priceVariant.sku} not found on product ${resource.id}`
|
|
2812
2964
|
);
|
|
2813
2965
|
}
|
|
2814
|
-
variant.prices =
|
|
2966
|
+
variant.prices = variant.prices?.map((x) => {
|
|
2815
2967
|
if (x.id === priceId) {
|
|
2816
2968
|
return { ...x, ...price };
|
|
2817
2969
|
}
|
|
@@ -2833,13 +2985,9 @@ var ProductRepository = class extends AbstractResourceRepository {
|
|
|
2833
2985
|
},
|
|
2834
2986
|
removePrice: (context, resource, { priceId, staged }) => {
|
|
2835
2987
|
const removeVariantPrice = (data) => {
|
|
2836
|
-
var _a;
|
|
2837
2988
|
const allVariants = [data.masterVariant, ...data.variants ?? []];
|
|
2838
2989
|
const priceVariant = allVariants.find(
|
|
2839
|
-
(variant2) =>
|
|
2840
|
-
var _a2;
|
|
2841
|
-
return (_a2 = variant2.prices) == null ? void 0 : _a2.some((x) => x.id === priceId);
|
|
2842
|
-
}
|
|
2990
|
+
(variant2) => variant2.prices?.some((x) => x.id === priceId)
|
|
2843
2991
|
);
|
|
2844
2992
|
if (!priceVariant) {
|
|
2845
2993
|
throw new Error(
|
|
@@ -2856,7 +3004,7 @@ var ProductRepository = class extends AbstractResourceRepository {
|
|
|
2856
3004
|
`Variant with id ${priceVariant.id} or sku ${priceVariant.sku} not found on product ${resource.id}`
|
|
2857
3005
|
);
|
|
2858
3006
|
}
|
|
2859
|
-
variant.prices =
|
|
3007
|
+
variant.prices = variant.prices?.filter((x) => x.id !== priceId);
|
|
2860
3008
|
if (isMasterVariant) {
|
|
2861
3009
|
data.masterVariant = variant;
|
|
2862
3010
|
} else {
|
|
@@ -2871,13 +3019,46 @@ var ProductRepository = class extends AbstractResourceRepository {
|
|
|
2871
3019
|
checkForStagedChanges(resource);
|
|
2872
3020
|
return resource;
|
|
2873
3021
|
}
|
|
3022
|
+
// 'changeName': () => {},
|
|
3023
|
+
// 'changeSlug': () => {},
|
|
3024
|
+
// 'addVariant': () => {},
|
|
3025
|
+
// 'removeVariant': () => {},
|
|
3026
|
+
// 'changeMasterVariant': () => {},
|
|
3027
|
+
// 'setPrices': () => {},
|
|
3028
|
+
// 'setProductPriceCustomType': () => {},
|
|
3029
|
+
// 'setProductPriceCustomField': () => {},
|
|
3030
|
+
// 'setDiscountedPrice': () => {},
|
|
3031
|
+
// 'setAttributeInAllVariants': () => {},
|
|
3032
|
+
// 'addToCategory': () => {},
|
|
3033
|
+
// 'setCategoryOrderHint': () => {},
|
|
3034
|
+
// 'removeFromCategory': () => {},
|
|
3035
|
+
// 'setTaxCategory': () => {},
|
|
3036
|
+
// 'setSku': () => {},
|
|
3037
|
+
// 'setProductVariantKey': () => {},
|
|
3038
|
+
// 'setImageLabel': () => {},
|
|
3039
|
+
// 'addAsset': () => {},
|
|
3040
|
+
// 'removeAsset': () => {},
|
|
3041
|
+
// 'setAssetKey': () => {},
|
|
3042
|
+
// 'changeAssetOrder': () => {},
|
|
3043
|
+
// 'changeAssetName': () => {},
|
|
3044
|
+
// 'setAssetDescription': () => {},
|
|
3045
|
+
// 'setAssetTags': () => {},
|
|
3046
|
+
// 'setAssetSources': () => {},
|
|
3047
|
+
// 'setAssetCustomType': () => {},
|
|
3048
|
+
// 'setAssetCustomField': () => {},
|
|
3049
|
+
// 'setSearchKeywords': () => {},
|
|
3050
|
+
// 'setMetaTitle': () => {},
|
|
3051
|
+
// 'setMetaDescription': () => {},
|
|
3052
|
+
// 'setMetaKeywords': () => {},
|
|
3053
|
+
// 'revertStagedChanges': () => {},
|
|
3054
|
+
// 'revertStagedVariantChanges': () => {},
|
|
3055
|
+
// 'transitionState': () => {},
|
|
2874
3056
|
};
|
|
2875
3057
|
}
|
|
2876
3058
|
getTypeId() {
|
|
2877
3059
|
return "product";
|
|
2878
3060
|
}
|
|
2879
3061
|
create(context, draft) {
|
|
2880
|
-
var _a;
|
|
2881
3062
|
if (!draft.masterVariant) {
|
|
2882
3063
|
throw new Error("Missing master variant");
|
|
2883
3064
|
}
|
|
@@ -2902,9 +3083,9 @@ var ProductRepository = class extends AbstractResourceRepository {
|
|
|
2902
3083
|
slug: draft.slug,
|
|
2903
3084
|
categories: [],
|
|
2904
3085
|
masterVariant: variantFromDraft(1, draft.masterVariant),
|
|
2905
|
-
variants:
|
|
3086
|
+
variants: draft.variants?.map(
|
|
2906
3087
|
(variant, index) => variantFromDraft(index + 2, variant)
|
|
2907
|
-
)
|
|
3088
|
+
) ?? [],
|
|
2908
3089
|
searchKeywords: draft.searchKeywords ?? {}
|
|
2909
3090
|
};
|
|
2910
3091
|
const resource = {
|
|
@@ -2950,26 +3131,18 @@ var getVariant = (productData, variantId, sku) => {
|
|
|
2950
3131
|
variantIndex: !isMasterVariant && foundVariant ? productData.variants.indexOf(foundVariant) : -1
|
|
2951
3132
|
};
|
|
2952
3133
|
};
|
|
2953
|
-
var variantFromDraft = (variantId, variant) => {
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
images: []
|
|
2962
|
-
};
|
|
2963
|
-
};
|
|
3134
|
+
var variantFromDraft = (variantId, variant) => ({
|
|
3135
|
+
id: variantId,
|
|
3136
|
+
sku: variant?.sku,
|
|
3137
|
+
attributes: variant?.attributes ?? [],
|
|
3138
|
+
prices: variant?.prices?.map(priceFromDraft),
|
|
3139
|
+
assets: [],
|
|
3140
|
+
images: []
|
|
3141
|
+
});
|
|
2964
3142
|
var priceFromDraft = (draft) => ({
|
|
2965
3143
|
id: uuidv46(),
|
|
2966
3144
|
country: draft.country,
|
|
2967
|
-
value:
|
|
2968
|
-
currencyCode: draft.value.currencyCode,
|
|
2969
|
-
centAmount: draft.value.centAmount,
|
|
2970
|
-
fractionDigits: 2,
|
|
2971
|
-
type: "centPrecision"
|
|
2972
|
-
}
|
|
3145
|
+
value: createTypedMoney(draft.value)
|
|
2973
3146
|
});
|
|
2974
3147
|
|
|
2975
3148
|
// src/repositories/product-discount.ts
|
|
@@ -3103,6 +3276,7 @@ var parseFilter = (filter) => {
|
|
|
3103
3276
|
(t) => ({
|
|
3104
3277
|
type: "Symbol",
|
|
3105
3278
|
kind: "string",
|
|
3279
|
+
// @ts-ignore
|
|
3106
3280
|
value: t.token.groups[1]
|
|
3107
3281
|
})
|
|
3108
3282
|
).nud(
|
|
@@ -3247,7 +3421,6 @@ var getVariants = (p) => [
|
|
|
3247
3421
|
|
|
3248
3422
|
// src/priceSelector.ts
|
|
3249
3423
|
var applyPriceSelector = (products, selector) => {
|
|
3250
|
-
var _a;
|
|
3251
3424
|
validatePriceSelector(selector);
|
|
3252
3425
|
for (const product of products) {
|
|
3253
3426
|
const variants = [
|
|
@@ -3255,7 +3428,7 @@ var applyPriceSelector = (products, selector) => {
|
|
|
3255
3428
|
...product.variants ?? []
|
|
3256
3429
|
].filter((x) => x != void 0);
|
|
3257
3430
|
for (const variant of variants) {
|
|
3258
|
-
const scopedPrices =
|
|
3431
|
+
const scopedPrices = variant.prices?.filter((p) => priceSelectorFilter(p, selector)) ?? [];
|
|
3259
3432
|
if (scopedPrices.length > 0) {
|
|
3260
3433
|
const price = scopedPrices[0];
|
|
3261
3434
|
variant.scopedPriceDiscounted = false;
|
|
@@ -3279,17 +3452,16 @@ var validatePriceSelector = (selector) => {
|
|
|
3279
3452
|
}
|
|
3280
3453
|
};
|
|
3281
3454
|
var priceSelectorFilter = (price, selector) => {
|
|
3282
|
-
var _a, _b, _c, _d;
|
|
3283
3455
|
if ((selector.country || price.country) && selector.country !== price.country) {
|
|
3284
3456
|
return false;
|
|
3285
3457
|
}
|
|
3286
3458
|
if ((selector.currency || price.value.currencyCode) && selector.currency !== price.value.currencyCode) {
|
|
3287
3459
|
return false;
|
|
3288
3460
|
}
|
|
3289
|
-
if ((selector.channel ||
|
|
3461
|
+
if ((selector.channel || price.channel?.id) && selector.channel !== price.channel?.id) {
|
|
3290
3462
|
return false;
|
|
3291
3463
|
}
|
|
3292
|
-
if ((selector.customerGroup ||
|
|
3464
|
+
if ((selector.customerGroup || price.customerGroup?.id) && selector.customerGroup !== price.customerGroup?.id) {
|
|
3293
3465
|
return false;
|
|
3294
3466
|
}
|
|
3295
3467
|
return true;
|
|
@@ -3413,6 +3585,11 @@ var ProductProjectionSearch = class {
|
|
|
3413
3585
|
}
|
|
3414
3586
|
return result;
|
|
3415
3587
|
}
|
|
3588
|
+
/**
|
|
3589
|
+
* TODO: This implemention needs the following additional features:
|
|
3590
|
+
* - counting products
|
|
3591
|
+
* - correct dataType
|
|
3592
|
+
*/
|
|
3416
3593
|
termFacet(facet, products) {
|
|
3417
3594
|
const result = {
|
|
3418
3595
|
type: "terms",
|
|
@@ -3464,7 +3641,7 @@ var ProductProjectionSearch = class {
|
|
|
3464
3641
|
for (const p of products) {
|
|
3465
3642
|
for (const v of getVariants(p)) {
|
|
3466
3643
|
const val = resolveVariantValue(v, source);
|
|
3467
|
-
if (filters
|
|
3644
|
+
if (filters?.some((f) => f.match(val))) {
|
|
3468
3645
|
count++;
|
|
3469
3646
|
}
|
|
3470
3647
|
}
|
|
@@ -3478,7 +3655,7 @@ var ProductProjectionSearch = class {
|
|
|
3478
3655
|
};
|
|
3479
3656
|
}
|
|
3480
3657
|
rangeFacet(source, ranges, products) {
|
|
3481
|
-
const counts =
|
|
3658
|
+
const counts = ranges?.map((range) => {
|
|
3482
3659
|
if (source.startsWith("variants.")) {
|
|
3483
3660
|
const values = [];
|
|
3484
3661
|
for (const p of products) {
|
|
@@ -3500,6 +3677,7 @@ var ProductProjectionSearch = class {
|
|
|
3500
3677
|
to: range.stop || 0,
|
|
3501
3678
|
toStr: range.stop !== null ? Number(range.stop).toFixed(1) : "",
|
|
3502
3679
|
count: numValues,
|
|
3680
|
+
// totalCount: 0,
|
|
3503
3681
|
total: values.reduce((a, b) => a + b, 0),
|
|
3504
3682
|
min: numValues > 0 ? Math.min(...values) : 0,
|
|
3505
3683
|
max: numValues > 0 ? Math.max(...values) : 0,
|
|
@@ -3508,9 +3686,10 @@ var ProductProjectionSearch = class {
|
|
|
3508
3686
|
} else {
|
|
3509
3687
|
throw new Error("not supported");
|
|
3510
3688
|
}
|
|
3511
|
-
})
|
|
3689
|
+
}) || [];
|
|
3512
3690
|
const data = {
|
|
3513
3691
|
type: "range",
|
|
3692
|
+
// @ts-ignore
|
|
3514
3693
|
dataType: "number",
|
|
3515
3694
|
ranges: counts
|
|
3516
3695
|
};
|
|
@@ -3580,7 +3759,8 @@ var ProductSelectionRepository = class extends AbstractResourceRepository {
|
|
|
3580
3759
|
...getBaseResourceProperties(),
|
|
3581
3760
|
productCount: 0,
|
|
3582
3761
|
name: draft.name,
|
|
3583
|
-
type: "individual"
|
|
3762
|
+
type: "individual",
|
|
3763
|
+
mode: "Individual"
|
|
3584
3764
|
};
|
|
3585
3765
|
this.saveNew(context, resource);
|
|
3586
3766
|
return resource;
|
|
@@ -3603,7 +3783,6 @@ var ProductTypeRepository = class extends AbstractResourceRepository {
|
|
|
3603
3783
|
attributeName,
|
|
3604
3784
|
newValue
|
|
3605
3785
|
}) => {
|
|
3606
|
-
var _a;
|
|
3607
3786
|
const updateAttributeType = (type) => {
|
|
3608
3787
|
switch (type.name) {
|
|
3609
3788
|
case "lenum":
|
|
@@ -3618,30 +3797,27 @@ var ProductTypeRepository = class extends AbstractResourceRepository {
|
|
|
3618
3797
|
return;
|
|
3619
3798
|
}
|
|
3620
3799
|
};
|
|
3621
|
-
|
|
3800
|
+
resource.attributes?.forEach((value) => {
|
|
3622
3801
|
if (value.name === attributeName) {
|
|
3623
3802
|
updateAttributeType(value.type);
|
|
3624
3803
|
}
|
|
3625
3804
|
});
|
|
3626
3805
|
},
|
|
3627
3806
|
changeLabel: (context, resource, { attributeName, label }) => {
|
|
3628
|
-
|
|
3629
|
-
(_a = resource.attributes) == null ? void 0 : _a.forEach((value) => {
|
|
3807
|
+
resource.attributes?.forEach((value) => {
|
|
3630
3808
|
if (value.name === attributeName) {
|
|
3631
3809
|
value.label = label;
|
|
3632
3810
|
}
|
|
3633
3811
|
});
|
|
3634
3812
|
},
|
|
3635
3813
|
addAttributeDefinition: (context, resource, { attribute }) => {
|
|
3636
|
-
|
|
3637
|
-
(_a = resource.attributes) == null ? void 0 : _a.push(
|
|
3814
|
+
resource.attributes?.push(
|
|
3638
3815
|
this.attributeDefinitionFromAttributeDefinitionDraft(context, attribute)
|
|
3639
3816
|
);
|
|
3640
3817
|
},
|
|
3641
3818
|
changeAttributeOrderByName: (context, resource, { attributeNames }) => {
|
|
3642
|
-
var _a;
|
|
3643
3819
|
const attrs = new Map(
|
|
3644
|
-
|
|
3820
|
+
resource.attributes?.map((item) => [item.name, item])
|
|
3645
3821
|
);
|
|
3646
3822
|
const result = [];
|
|
3647
3823
|
let current = resource.attributes;
|
|
@@ -3651,7 +3827,7 @@ var ProductTypeRepository = class extends AbstractResourceRepository {
|
|
|
3651
3827
|
throw new Error("New attr");
|
|
3652
3828
|
}
|
|
3653
3829
|
result.push(attr);
|
|
3654
|
-
current = current
|
|
3830
|
+
current = current?.filter((f) => f.name !== attrName);
|
|
3655
3831
|
});
|
|
3656
3832
|
resource.attributes = result;
|
|
3657
3833
|
if (current) {
|
|
@@ -3659,12 +3835,10 @@ var ProductTypeRepository = class extends AbstractResourceRepository {
|
|
|
3659
3835
|
}
|
|
3660
3836
|
},
|
|
3661
3837
|
removeAttributeDefinition: (context, resource, { name }) => {
|
|
3662
|
-
|
|
3663
|
-
resource.attributes = (_a = resource.attributes) == null ? void 0 : _a.filter((f) => f.name !== name);
|
|
3838
|
+
resource.attributes = resource.attributes?.filter((f) => f.name !== name);
|
|
3664
3839
|
},
|
|
3665
3840
|
removeEnumValues: (context, resource, { attributeName, keys }) => {
|
|
3666
|
-
|
|
3667
|
-
(_a = resource.attributes) == null ? void 0 : _a.forEach((attr) => {
|
|
3841
|
+
resource.attributes?.forEach((attr) => {
|
|
3668
3842
|
if (attr.name == attributeName) {
|
|
3669
3843
|
if (attr.type.name == "enum") {
|
|
3670
3844
|
attr.type.values = attr.type.values.filter(
|
|
@@ -3723,20 +3897,18 @@ var ProjectRepository = class extends AbstractRepository {
|
|
|
3723
3897
|
resource.messages.deleteDaysAfterCreation = messagesConfiguration.deleteDaysAfterCreation;
|
|
3724
3898
|
},
|
|
3725
3899
|
changeProductSearchIndexingEnabled: (context, resource, { enabled }) => {
|
|
3726
|
-
|
|
3727
|
-
if (!((_a = resource.searchIndexing) == null ? void 0 : _a.products)) {
|
|
3900
|
+
if (!resource.searchIndexing?.products) {
|
|
3728
3901
|
throw new Error("Invalid project state");
|
|
3729
3902
|
}
|
|
3730
3903
|
resource.searchIndexing.products.status = enabled ? "Activated" : "Deactivated";
|
|
3731
|
-
resource.searchIndexing.products.lastModifiedAt = new Date().toISOString();
|
|
3904
|
+
resource.searchIndexing.products.lastModifiedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
3732
3905
|
},
|
|
3733
3906
|
changeOrderSearchStatus: (context, resource, { status }) => {
|
|
3734
|
-
|
|
3735
|
-
if (!((_a = resource.searchIndexing) == null ? void 0 : _a.orders)) {
|
|
3907
|
+
if (!resource.searchIndexing?.orders) {
|
|
3736
3908
|
throw new Error("Invalid project state");
|
|
3737
3909
|
}
|
|
3738
3910
|
resource.searchIndexing.orders.status = status;
|
|
3739
|
-
resource.searchIndexing.orders.lastModifiedAt = new Date().toISOString();
|
|
3911
|
+
resource.searchIndexing.orders.lastModifiedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
3740
3912
|
},
|
|
3741
3913
|
setShippingRateInputType: (context, resource, { shippingRateInputType }) => {
|
|
3742
3914
|
resource.shippingRateInputType = shippingRateInputType;
|
|
@@ -3828,18 +4000,15 @@ import deepEqual3 from "deep-equal";
|
|
|
3828
4000
|
var ShippingMethodRepository = class extends AbstractResourceRepository {
|
|
3829
4001
|
constructor() {
|
|
3830
4002
|
super(...arguments);
|
|
3831
|
-
this._transformZoneRateDraft = (context, draft) => {
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
shippingRates: (_a = draft.shippingRates) == null ? void 0 : _a.map(this._transformShippingRate)
|
|
3841
|
-
};
|
|
3842
|
-
};
|
|
4003
|
+
this._transformZoneRateDraft = (context, draft) => ({
|
|
4004
|
+
...draft,
|
|
4005
|
+
zone: getReferenceFromResourceIdentifier(
|
|
4006
|
+
draft.zone,
|
|
4007
|
+
context.projectKey,
|
|
4008
|
+
this._storage
|
|
4009
|
+
),
|
|
4010
|
+
shippingRates: draft.shippingRates?.map(this._transformShippingRate)
|
|
4011
|
+
});
|
|
3843
4012
|
this._transformShippingRate = (rate) => ({
|
|
3844
4013
|
price: createTypedMoney(rate.price),
|
|
3845
4014
|
freeAbove: rate.freeAbove && createTypedMoney(rate.freeAbove),
|
|
@@ -3900,6 +4069,9 @@ var ShippingMethodRepository = class extends AbstractResourceRepository {
|
|
|
3900
4069
|
setLocalizedDescription: (_context, resource, { localizedDescription }) => {
|
|
3901
4070
|
resource.localizedDescription = localizedDescription;
|
|
3902
4071
|
},
|
|
4072
|
+
setLocalizedName: (_context, resource, { localizedName }) => {
|
|
4073
|
+
resource.localizedName = localizedName;
|
|
4074
|
+
},
|
|
3903
4075
|
setPredicate: (_context, resource, { predicate }) => {
|
|
3904
4076
|
resource.predicate = predicate;
|
|
3905
4077
|
},
|
|
@@ -3936,7 +4108,6 @@ var ShippingMethodRepository = class extends AbstractResourceRepository {
|
|
|
3936
4108
|
return "shipping-method";
|
|
3937
4109
|
}
|
|
3938
4110
|
create(context, draft) {
|
|
3939
|
-
var _a;
|
|
3940
4111
|
const resource = {
|
|
3941
4112
|
...getBaseResourceProperties(),
|
|
3942
4113
|
...draft,
|
|
@@ -3945,7 +4116,7 @@ var ShippingMethodRepository = class extends AbstractResourceRepository {
|
|
|
3945
4116
|
context.projectKey,
|
|
3946
4117
|
this._storage
|
|
3947
4118
|
),
|
|
3948
|
-
zoneRates:
|
|
4119
|
+
zoneRates: draft.zoneRates?.map(
|
|
3949
4120
|
(z) => this._transformZoneRateDraft(context, z)
|
|
3950
4121
|
),
|
|
3951
4122
|
custom: createCustomFields(
|
|
@@ -3965,7 +4136,6 @@ var ShoppingListRepository = class extends AbstractResourceRepository {
|
|
|
3965
4136
|
return "shopping-list";
|
|
3966
4137
|
}
|
|
3967
4138
|
create(context, draft) {
|
|
3968
|
-
var _a, _b;
|
|
3969
4139
|
const resource = {
|
|
3970
4140
|
...getBaseResourceProperties(),
|
|
3971
4141
|
...draft,
|
|
@@ -3975,7 +4145,7 @@ var ShoppingListRepository = class extends AbstractResourceRepository {
|
|
|
3975
4145
|
this._storage
|
|
3976
4146
|
),
|
|
3977
4147
|
textLineItems: [],
|
|
3978
|
-
lineItems:
|
|
4148
|
+
lineItems: draft.lineItems?.map((e) => ({
|
|
3979
4149
|
...getBaseResourceProperties(),
|
|
3980
4150
|
...e,
|
|
3981
4151
|
addedAt: e.addedAt ?? "",
|
|
@@ -3983,14 +4153,18 @@ var ShoppingListRepository = class extends AbstractResourceRepository {
|
|
|
3983
4153
|
name: {},
|
|
3984
4154
|
quantity: e.quantity ?? 1,
|
|
3985
4155
|
productType: { typeId: "product-type", id: "" },
|
|
3986
|
-
custom: createCustomFields(
|
|
3987
|
-
|
|
4156
|
+
custom: createCustomFields(
|
|
4157
|
+
e.custom,
|
|
4158
|
+
context.projectKey,
|
|
4159
|
+
this._storage
|
|
4160
|
+
)
|
|
4161
|
+
})) ?? [],
|
|
3988
4162
|
customer: draft.customer ? getReferenceFromResourceIdentifier(
|
|
3989
4163
|
draft.customer,
|
|
3990
4164
|
context.projectKey,
|
|
3991
4165
|
this._storage
|
|
3992
4166
|
) : void 0,
|
|
3993
|
-
store:
|
|
4167
|
+
store: draft.store ? getStoreKeyReference(draft.store, context.projectKey, this._storage) : void 0
|
|
3994
4168
|
};
|
|
3995
4169
|
this.saveNew(context, resource);
|
|
3996
4170
|
return resource;
|
|
@@ -4031,7 +4205,6 @@ var StandAlonePriceRepository = class extends AbstractResourceRepository {
|
|
|
4031
4205
|
return "standalone-price";
|
|
4032
4206
|
}
|
|
4033
4207
|
create(context, draft) {
|
|
4034
|
-
var _a;
|
|
4035
4208
|
const resource = {
|
|
4036
4209
|
...getBaseResourceProperties(),
|
|
4037
4210
|
active: draft.active ? draft.active : false,
|
|
@@ -4039,7 +4212,7 @@ var StandAlonePriceRepository = class extends AbstractResourceRepository {
|
|
|
4039
4212
|
value: createTypedMoney(draft.value),
|
|
4040
4213
|
country: draft.country,
|
|
4041
4214
|
discounted: draft.discounted ? this.transformDiscountDraft(draft.discounted) : void 0,
|
|
4042
|
-
channel:
|
|
4215
|
+
channel: draft.channel?.id ? this.transformChannelReferenceDraft(draft.channel) : void 0,
|
|
4043
4216
|
validFrom: draft.validFrom,
|
|
4044
4217
|
validUntil: draft.validUntil
|
|
4045
4218
|
};
|
|
@@ -4081,7 +4254,7 @@ var StateRepository = class extends AbstractResourceRepository {
|
|
|
4081
4254
|
resource.roles = roles;
|
|
4082
4255
|
},
|
|
4083
4256
|
setTransitions: (context, resource, { transitions }) => {
|
|
4084
|
-
resource.transitions = transitions
|
|
4257
|
+
resource.transitions = transitions?.map(
|
|
4085
4258
|
(resourceId) => ({
|
|
4086
4259
|
id: resourceId.id || "",
|
|
4087
4260
|
typeId: "state"
|
|
@@ -4157,6 +4330,7 @@ var StoreRepository = class extends AbstractResourceRepository {
|
|
|
4157
4330
|
key: draft.key,
|
|
4158
4331
|
name: draft.name,
|
|
4159
4332
|
languages: draft.languages ?? [],
|
|
4333
|
+
countries: draft.countries ?? [],
|
|
4160
4334
|
distributionChannels: this.transformChannels(
|
|
4161
4335
|
context,
|
|
4162
4336
|
draft.distributionChannels
|
|
@@ -4273,11 +4447,10 @@ var TaxCategoryRepository = class extends AbstractResourceRepository {
|
|
|
4273
4447
|
return "tax-category";
|
|
4274
4448
|
}
|
|
4275
4449
|
create(context, draft) {
|
|
4276
|
-
var _a;
|
|
4277
4450
|
const resource = {
|
|
4278
4451
|
...getBaseResourceProperties(),
|
|
4279
4452
|
...draft,
|
|
4280
|
-
rates:
|
|
4453
|
+
rates: draft.rates?.map(this.taxRateFromTaxRateDraft) || []
|
|
4281
4454
|
};
|
|
4282
4455
|
this.saveNew(context, resource);
|
|
4283
4456
|
return resource;
|
|
@@ -4429,6 +4602,9 @@ var ZoneRepository = class extends AbstractResourceRepository {
|
|
|
4429
4602
|
|
|
4430
4603
|
// src/repositories/index.ts
|
|
4431
4604
|
var createRepositories = (storage) => ({
|
|
4605
|
+
"associate-role": new AssociateRoleRepository(storage),
|
|
4606
|
+
"attribute-group": new AttributeGroupRepository(storage),
|
|
4607
|
+
"business-unit": new BusinessUnitRepository(storage),
|
|
4432
4608
|
category: new CategoryRepository(storage),
|
|
4433
4609
|
cart: new CartRepository(storage),
|
|
4434
4610
|
"cart-discount": new CartDiscountRepository(storage),
|
|
@@ -4606,6 +4782,7 @@ var AbstractService = class {
|
|
|
4606
4782
|
);
|
|
4607
4783
|
return result;
|
|
4608
4784
|
}
|
|
4785
|
+
// No idea what i'm doing
|
|
4609
4786
|
_parseParam(value) {
|
|
4610
4787
|
if (Array.isArray(value)) {
|
|
4611
4788
|
return value;
|
|
@@ -4640,6 +4817,7 @@ var CartService = class extends AbstractService {
|
|
|
4640
4817
|
currency: cartOrOrder.totalPrice.currencyCode,
|
|
4641
4818
|
discountCodes: [],
|
|
4642
4819
|
shipping: [],
|
|
4820
|
+
// TODO: cartOrOrder.shipping,
|
|
4643
4821
|
lineItems: cartOrOrder.lineItems.map((lineItem) => ({
|
|
4644
4822
|
...lineItem,
|
|
4645
4823
|
variantId: lineItem.variant.id,
|
|
@@ -4750,7 +4928,10 @@ var CustomerService = class extends AbstractService {
|
|
|
4750
4928
|
const customer = this.repository.query(getRepositoryContext(request), {
|
|
4751
4929
|
where: [`email="${request.body.email}"`]
|
|
4752
4930
|
});
|
|
4753
|
-
const ttlMinutes = request.params.ttlMinutes ?
|
|
4931
|
+
const ttlMinutes = request.params.ttlMinutes ? (
|
|
4932
|
+
// @ts-ignore
|
|
4933
|
+
+request.params.ttlMinutes
|
|
4934
|
+
) : 34560;
|
|
4754
4935
|
const { version, ...rest } = getBaseResourceProperties();
|
|
4755
4936
|
return response.status(200).send({
|
|
4756
4937
|
...rest,
|
|
@@ -5205,10 +5386,9 @@ var CommercetoolsMock = class {
|
|
|
5205
5386
|
this.mockApiHost();
|
|
5206
5387
|
}
|
|
5207
5388
|
stop() {
|
|
5208
|
-
|
|
5209
|
-
(_a = this._nockScopes.auth) == null ? void 0 : _a.persist(false);
|
|
5389
|
+
this._nockScopes.auth?.persist(false);
|
|
5210
5390
|
this._nockScopes.auth = void 0;
|
|
5211
|
-
|
|
5391
|
+
this._nockScopes.api?.persist(false);
|
|
5212
5392
|
this._nockScopes.api = void 0;
|
|
5213
5393
|
}
|
|
5214
5394
|
clear() {
|
|
@@ -5238,7 +5418,7 @@ var CommercetoolsMock = class {
|
|
|
5238
5418
|
const app = express2();
|
|
5239
5419
|
const projectRouter = express2.Router({ mergeParams: true });
|
|
5240
5420
|
projectRouter.use(express2.json());
|
|
5241
|
-
if (!
|
|
5421
|
+
if (!options?.silent) {
|
|
5242
5422
|
app.use(morgan("tiny"));
|
|
5243
5423
|
}
|
|
5244
5424
|
app.use("/oauth", this._oauth2.createRouter());
|