@labdigital/commercetools-mock 1.2.0 → 1.3.1
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 +5827 -5596
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +344 -167
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +344 -171
- package/dist/index.mjs.map +1 -1
- package/package.json +33 -39
- 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/predicateParser.ts +2 -2
- package/src/lib/projectionSearchFilter.test.ts +2 -1
- package/src/lib/projectionSearchFilter.ts +4 -4
- 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 +90 -13
- 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 +2 -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.js
CHANGED
|
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
20
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
25
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
26
|
mod
|
|
23
27
|
));
|
|
@@ -57,8 +61,8 @@ var CommercetoolsError = class extends Error {
|
|
|
57
61
|
var import_uuid = require("uuid");
|
|
58
62
|
var getBaseResourceProperties = () => ({
|
|
59
63
|
id: (0, import_uuid.v4)(),
|
|
60
|
-
createdAt: new Date().toISOString(),
|
|
61
|
-
lastModifiedAt: new Date().toISOString(),
|
|
64
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
65
|
+
lastModifiedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
62
66
|
version: 0
|
|
63
67
|
});
|
|
64
68
|
var nestedLookup = (obj, path) => {
|
|
@@ -137,14 +141,13 @@ var parseQueryExpression = (predicate) => {
|
|
|
137
141
|
}
|
|
138
142
|
};
|
|
139
143
|
var validateSymbol = (val) => {
|
|
140
|
-
var _a, _b;
|
|
141
144
|
if (!val.type) {
|
|
142
145
|
throw new PredicateError("Internal error");
|
|
143
146
|
}
|
|
144
147
|
if (val.type === "identifier") {
|
|
145
148
|
const char = val.value.charAt(0);
|
|
146
|
-
const line =
|
|
147
|
-
const column =
|
|
149
|
+
const line = val.pos?.start.line;
|
|
150
|
+
const column = val.pos?.start.column;
|
|
148
151
|
throw new PredicateError(
|
|
149
152
|
`Invalid input '${char}', expected input parameter or primitive value (line ${line}, column ${column})`
|
|
150
153
|
);
|
|
@@ -195,6 +198,7 @@ var generateMatchFunc = (predicate) => {
|
|
|
195
198
|
100,
|
|
196
199
|
(t) => ({
|
|
197
200
|
type: "var",
|
|
201
|
+
// @ts-ignore
|
|
198
202
|
value: t.token.groups[1],
|
|
199
203
|
pos: t.token.strpos()
|
|
200
204
|
})
|
|
@@ -203,6 +207,7 @@ var generateMatchFunc = (predicate) => {
|
|
|
203
207
|
100,
|
|
204
208
|
(t) => ({
|
|
205
209
|
type: "string",
|
|
210
|
+
// @ts-ignore
|
|
206
211
|
value: t.token.groups[1],
|
|
207
212
|
pos: t.token.strpos()
|
|
208
213
|
})
|
|
@@ -445,6 +450,7 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
445
450
|
return project;
|
|
446
451
|
};
|
|
447
452
|
this.getProject = (projectKey) => this.addProject(projectKey);
|
|
453
|
+
// Expand resolves a nested reference and injects the object in the given obj
|
|
448
454
|
this.expand = (projectKey, obj, clause) => {
|
|
449
455
|
if (!clause)
|
|
450
456
|
return obj;
|
|
@@ -486,6 +492,9 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
486
492
|
let projectStorage = this.resources[projectKey];
|
|
487
493
|
if (!projectStorage) {
|
|
488
494
|
projectStorage = this.resources[projectKey] = {
|
|
495
|
+
"associate-role": /* @__PURE__ */ new Map(),
|
|
496
|
+
"attribute-group": /* @__PURE__ */ new Map(),
|
|
497
|
+
"business-unit": /* @__PURE__ */ new Map(),
|
|
489
498
|
cart: /* @__PURE__ */ new Map(),
|
|
490
499
|
"cart-discount": /* @__PURE__ */ new Map(),
|
|
491
500
|
category: /* @__PURE__ */ new Map(),
|
|
@@ -524,7 +533,7 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
524
533
|
clear() {
|
|
525
534
|
for (const [, projectStorage] of Object.entries(this.resources)) {
|
|
526
535
|
for (const [, value] of Object.entries(projectStorage)) {
|
|
527
|
-
value
|
|
536
|
+
value?.clear();
|
|
528
537
|
}
|
|
529
538
|
}
|
|
530
539
|
}
|
|
@@ -536,16 +545,14 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
536
545
|
return [];
|
|
537
546
|
}
|
|
538
547
|
add(projectKey, typeId, obj, params = {}) {
|
|
539
|
-
var _a;
|
|
540
548
|
const store = this.forProjectKey(projectKey);
|
|
541
|
-
|
|
549
|
+
store[typeId]?.set(obj.id, obj);
|
|
542
550
|
const resource = this.get(projectKey, typeId, obj.id, params);
|
|
543
551
|
(0, import_assert.default)(resource, `resource of type ${typeId} with id ${obj.id} not created`);
|
|
544
552
|
return cloneObject(resource);
|
|
545
553
|
}
|
|
546
554
|
get(projectKey, typeId, id, params = {}) {
|
|
547
|
-
|
|
548
|
-
const resource = (_a = this.forProjectKey(projectKey)[typeId]) == null ? void 0 : _a.get(id);
|
|
555
|
+
const resource = this.forProjectKey(projectKey)[typeId]?.get(id);
|
|
549
556
|
if (resource) {
|
|
550
557
|
const clone = cloneObject(resource);
|
|
551
558
|
return this.expand(projectKey, clone, params.expand);
|
|
@@ -567,10 +574,9 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
567
574
|
return null;
|
|
568
575
|
}
|
|
569
576
|
delete(projectKey, typeId, id, params = {}) {
|
|
570
|
-
var _a;
|
|
571
577
|
const resource = this.get(projectKey, typeId, id);
|
|
572
578
|
if (resource) {
|
|
573
|
-
|
|
579
|
+
this.forProjectKey(projectKey)[typeId]?.delete(id);
|
|
574
580
|
return this.expand(projectKey, resource, params.expand);
|
|
575
581
|
}
|
|
576
582
|
return resource;
|
|
@@ -660,6 +666,7 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
660
666
|
const store = this.forProjectKey(projectKey)[identifier.typeId];
|
|
661
667
|
if (store) {
|
|
662
668
|
const resource = Array.from(store.values()).find(
|
|
669
|
+
// @ts-ignore
|
|
663
670
|
(r) => r.key === identifier.key
|
|
664
671
|
);
|
|
665
672
|
if (resource) {
|
|
@@ -729,11 +736,10 @@ var OAuth2Store = class {
|
|
|
729
736
|
|
|
730
737
|
// src/oauth/helpers.ts
|
|
731
738
|
var getBearerToken = (request) => {
|
|
732
|
-
var _a;
|
|
733
739
|
const authHeader = request.header("Authorization");
|
|
734
|
-
const match = authHeader
|
|
740
|
+
const match = authHeader?.match(/^Bearer\s(?<token>[^\s]+)$/);
|
|
735
741
|
if (match) {
|
|
736
|
-
return
|
|
742
|
+
return match.groups?.token;
|
|
737
743
|
}
|
|
738
744
|
return void 0;
|
|
739
745
|
};
|
|
@@ -756,7 +762,7 @@ var OAuth2Server = class {
|
|
|
756
762
|
next(
|
|
757
763
|
new CommercetoolsError(
|
|
758
764
|
{
|
|
759
|
-
code: "
|
|
765
|
+
code: "invalid_token",
|
|
760
766
|
message: "This endpoint requires an access token. You can get one from the authorization server."
|
|
761
767
|
},
|
|
762
768
|
401
|
|
@@ -778,7 +784,6 @@ var OAuth2Server = class {
|
|
|
778
784
|
};
|
|
779
785
|
}
|
|
780
786
|
async tokenHandler(request, response, next) {
|
|
781
|
-
var _a;
|
|
782
787
|
const authHeader = request.header("Authorization");
|
|
783
788
|
if (!authHeader) {
|
|
784
789
|
return next(
|
|
@@ -819,7 +824,7 @@ var OAuth2Server = class {
|
|
|
819
824
|
const token = this.store.getClientToken(
|
|
820
825
|
credentials.name,
|
|
821
826
|
credentials.pass,
|
|
822
|
-
|
|
827
|
+
request.query.scope?.toString()
|
|
823
828
|
);
|
|
824
829
|
return response.status(200).send(token);
|
|
825
830
|
} else {
|
|
@@ -862,6 +867,7 @@ var ProjectAPI = class {
|
|
|
862
867
|
params
|
|
863
868
|
);
|
|
864
869
|
}
|
|
870
|
+
// TODO: Not sure if we want to expose this...
|
|
865
871
|
getRepository(typeId) {
|
|
866
872
|
const repository = this._repositories[typeId];
|
|
867
873
|
if (repository !== void 0) {
|
|
@@ -892,7 +898,7 @@ var import_uuid2 = require("uuid");
|
|
|
892
898
|
var createAddress = (base, projectKey, storage) => {
|
|
893
899
|
if (!base)
|
|
894
900
|
return void 0;
|
|
895
|
-
if (!
|
|
901
|
+
if (!base?.country) {
|
|
896
902
|
throw new Error("Country is required");
|
|
897
903
|
}
|
|
898
904
|
return {
|
|
@@ -929,7 +935,7 @@ var createPrice = (draft) => ({
|
|
|
929
935
|
id: (0, import_uuid2.v4)(),
|
|
930
936
|
value: createTypedMoney(draft.value)
|
|
931
937
|
});
|
|
932
|
-
var
|
|
938
|
+
var createCentPrecisionMoney = (value) => {
|
|
933
939
|
let fractionDigits = 2;
|
|
934
940
|
switch (value.currencyCode.toUpperCase()) {
|
|
935
941
|
case "BHD":
|
|
@@ -961,12 +967,22 @@ var createTypedMoney = (value) => {
|
|
|
961
967
|
default:
|
|
962
968
|
fractionDigits = 2;
|
|
963
969
|
}
|
|
970
|
+
if (value.preciseAmount) {
|
|
971
|
+
throw new Error("HighPrecisionMoney not supported");
|
|
972
|
+
}
|
|
964
973
|
return {
|
|
965
974
|
type: "centPrecision",
|
|
966
|
-
|
|
975
|
+
// centAmont is only optional on HighPrecisionMoney, so this should never
|
|
976
|
+
// fallback to 0
|
|
977
|
+
centAmount: value.centAmount ?? 0,
|
|
978
|
+
currencyCode: value.currencyCode,
|
|
967
979
|
fractionDigits
|
|
968
980
|
};
|
|
969
981
|
};
|
|
982
|
+
var createTypedMoney = (value) => {
|
|
983
|
+
const result = createCentPrecisionMoney(value);
|
|
984
|
+
return result;
|
|
985
|
+
};
|
|
970
986
|
var resolveStoreReference = (ref, projectKey, storage) => {
|
|
971
987
|
if (!ref)
|
|
972
988
|
return void 0;
|
|
@@ -985,7 +1001,8 @@ var getReferenceFromResourceIdentifier = (resourceIdentifier, projectKey, storag
|
|
|
985
1001
|
throw new CommercetoolsError(
|
|
986
1002
|
{
|
|
987
1003
|
code: "InvalidJsonInput",
|
|
988
|
-
message: `${resourceIdentifier.typeId}: ResourceIdentifier requires an 'id' xor a 'key'
|
|
1004
|
+
message: `${resourceIdentifier.typeId}: ResourceIdentifier requires an 'id' xor a 'key'`,
|
|
1005
|
+
detailedErrorMessage: `ResourceIdentifier requires an 'id' xor a 'key'`
|
|
989
1006
|
},
|
|
990
1007
|
400
|
|
991
1008
|
);
|
|
@@ -999,6 +1016,7 @@ var getReferenceFromResourceIdentifier = (resourceIdentifier, projectKey, storag
|
|
|
999
1016
|
throw new CommercetoolsError(
|
|
1000
1017
|
{
|
|
1001
1018
|
code: "ReferencedResourceNotFound",
|
|
1019
|
+
// @ts-ignore
|
|
1002
1020
|
typeId: resourceIdentifier.typeId,
|
|
1003
1021
|
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).`
|
|
1004
1022
|
},
|
|
@@ -1007,7 +1025,27 @@ var getReferenceFromResourceIdentifier = (resourceIdentifier, projectKey, storag
|
|
|
1007
1025
|
}
|
|
1008
1026
|
return {
|
|
1009
1027
|
typeId: resourceIdentifier.typeId,
|
|
1010
|
-
id: resource
|
|
1028
|
+
id: resource?.id
|
|
1029
|
+
};
|
|
1030
|
+
};
|
|
1031
|
+
var getStoreKeyReference = (id, projectKey, storage) => {
|
|
1032
|
+
if (id.key) {
|
|
1033
|
+
return {
|
|
1034
|
+
typeId: "store",
|
|
1035
|
+
key: id.key
|
|
1036
|
+
};
|
|
1037
|
+
}
|
|
1038
|
+
const value = getReferenceFromResourceIdentifier(
|
|
1039
|
+
id,
|
|
1040
|
+
projectKey,
|
|
1041
|
+
storage
|
|
1042
|
+
);
|
|
1043
|
+
if (!value.obj?.key) {
|
|
1044
|
+
throw new Error("No store found for reference");
|
|
1045
|
+
}
|
|
1046
|
+
return {
|
|
1047
|
+
typeId: "store",
|
|
1048
|
+
key: value.obj?.key
|
|
1011
1049
|
};
|
|
1012
1050
|
};
|
|
1013
1051
|
var getRepositoryContext = (request) => ({
|
|
@@ -1045,9 +1083,6 @@ var ProjectService = class {
|
|
|
1045
1083
|
}
|
|
1046
1084
|
};
|
|
1047
1085
|
|
|
1048
|
-
// src/repositories/cart.ts
|
|
1049
|
-
var import_uuid3 = require("uuid");
|
|
1050
|
-
|
|
1051
1086
|
// src/repositories/abstract.ts
|
|
1052
1087
|
var import_deep_equal = __toESM(require("deep-equal"));
|
|
1053
1088
|
|
|
@@ -1169,19 +1204,49 @@ var AbstractResourceRepository = class extends AbstractRepository {
|
|
|
1169
1204
|
if (current.version === resource.version) {
|
|
1170
1205
|
throw new Error("Internal error: no changes to save");
|
|
1171
1206
|
}
|
|
1172
|
-
resource.lastModifiedAt = new Date().toISOString();
|
|
1207
|
+
resource.lastModifiedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1173
1208
|
this._storage.add(context.projectKey, this.getTypeId(), resource);
|
|
1174
1209
|
return resource;
|
|
1175
1210
|
}
|
|
1176
1211
|
};
|
|
1177
1212
|
|
|
1213
|
+
// src/repositories/associate-role.ts
|
|
1214
|
+
var AssociateRoleRepository = class extends AbstractResourceRepository {
|
|
1215
|
+
getTypeId() {
|
|
1216
|
+
return "associate-role";
|
|
1217
|
+
}
|
|
1218
|
+
create(context, draft) {
|
|
1219
|
+
throw new Error("Method not implemented.");
|
|
1220
|
+
}
|
|
1221
|
+
};
|
|
1222
|
+
|
|
1223
|
+
// src/repositories/attribute-group.ts
|
|
1224
|
+
var AttributeGroupRepository = class extends AbstractResourceRepository {
|
|
1225
|
+
getTypeId() {
|
|
1226
|
+
return "attribute-group";
|
|
1227
|
+
}
|
|
1228
|
+
create(context, draft) {
|
|
1229
|
+
throw new Error("Method not implemented.");
|
|
1230
|
+
}
|
|
1231
|
+
};
|
|
1232
|
+
|
|
1233
|
+
// src/repositories/business-unit.ts
|
|
1234
|
+
var BusinessUnitRepository = class extends AbstractResourceRepository {
|
|
1235
|
+
getTypeId() {
|
|
1236
|
+
return "business-unit";
|
|
1237
|
+
}
|
|
1238
|
+
create(context, draft) {
|
|
1239
|
+
throw new Error("Method not implemented.");
|
|
1240
|
+
}
|
|
1241
|
+
};
|
|
1242
|
+
|
|
1178
1243
|
// src/repositories/cart.ts
|
|
1244
|
+
var import_uuid3 = require("uuid");
|
|
1179
1245
|
var CartRepository = class extends AbstractResourceRepository {
|
|
1180
1246
|
constructor() {
|
|
1181
1247
|
super(...arguments);
|
|
1182
1248
|
this.actions = {
|
|
1183
1249
|
addLineItem: (context, resource, { productId, variantId, sku, quantity = 1 }) => {
|
|
1184
|
-
var _a;
|
|
1185
1250
|
let product = null;
|
|
1186
1251
|
if (productId && variantId) {
|
|
1187
1252
|
product = this._storage.get(
|
|
@@ -1223,18 +1288,17 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1223
1288
|
});
|
|
1224
1289
|
}
|
|
1225
1290
|
const alreadyAdded = resource.lineItems.some(
|
|
1226
|
-
(x) => x.productId ===
|
|
1291
|
+
(x) => x.productId === product?.id && x.variant.id === variant?.id
|
|
1227
1292
|
);
|
|
1228
1293
|
if (alreadyAdded) {
|
|
1229
|
-
resource.lineItems.
|
|
1230
|
-
if (x.productId ===
|
|
1294
|
+
resource.lineItems.forEach((x) => {
|
|
1295
|
+
if (x.productId === product?.id && x.variant.id === variant?.id) {
|
|
1231
1296
|
x.quantity += quantity;
|
|
1232
1297
|
x.totalPrice.centAmount = calculateLineItemTotalPrice(x);
|
|
1233
1298
|
}
|
|
1234
|
-
return x;
|
|
1235
1299
|
});
|
|
1236
1300
|
} else {
|
|
1237
|
-
if (!
|
|
1301
|
+
if (!variant.prices?.length) {
|
|
1238
1302
|
throw new CommercetoolsError({
|
|
1239
1303
|
code: "General",
|
|
1240
1304
|
message: `A product with ID '${productId}' doesn't have any prices.`
|
|
@@ -1264,6 +1328,7 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1264
1328
|
perMethodTaxRate: [],
|
|
1265
1329
|
totalPrice: {
|
|
1266
1330
|
...price.value,
|
|
1331
|
+
type: "centPrecision",
|
|
1267
1332
|
centAmount: price.value.centAmount * quantity
|
|
1268
1333
|
},
|
|
1269
1334
|
quantity,
|
|
@@ -1275,6 +1340,44 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1275
1340
|
}
|
|
1276
1341
|
resource.totalPrice.centAmount = calculateCartTotalPrice(resource);
|
|
1277
1342
|
},
|
|
1343
|
+
changeLineItemQuantity: (context, resource, { lineItemId, lineItemKey, quantity }) => {
|
|
1344
|
+
let lineItem;
|
|
1345
|
+
if (lineItemId) {
|
|
1346
|
+
lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
1347
|
+
if (!lineItem) {
|
|
1348
|
+
throw new CommercetoolsError({
|
|
1349
|
+
code: "General",
|
|
1350
|
+
message: `A line item with ID '${lineItemId}' not found.`
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1353
|
+
} else if (lineItemKey) {
|
|
1354
|
+
lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
1355
|
+
if (!lineItem) {
|
|
1356
|
+
throw new CommercetoolsError({
|
|
1357
|
+
code: "General",
|
|
1358
|
+
message: `A line item with Key '${lineItemKey}' not found.`
|
|
1359
|
+
});
|
|
1360
|
+
}
|
|
1361
|
+
} else {
|
|
1362
|
+
throw new CommercetoolsError({
|
|
1363
|
+
code: "General",
|
|
1364
|
+
message: `Either lineItemid or lineItemKey needs to be provided.`
|
|
1365
|
+
});
|
|
1366
|
+
}
|
|
1367
|
+
if (quantity === 0) {
|
|
1368
|
+
resource.lineItems = resource.lineItems.filter(
|
|
1369
|
+
(x) => x.id !== lineItemId
|
|
1370
|
+
);
|
|
1371
|
+
} else {
|
|
1372
|
+
resource.lineItems.forEach((x) => {
|
|
1373
|
+
if (x.id === lineItemId && quantity) {
|
|
1374
|
+
x.quantity = quantity;
|
|
1375
|
+
x.totalPrice.centAmount = calculateLineItemTotalPrice(x);
|
|
1376
|
+
}
|
|
1377
|
+
});
|
|
1378
|
+
}
|
|
1379
|
+
resource.totalPrice.centAmount = calculateCartTotalPrice(resource);
|
|
1380
|
+
},
|
|
1278
1381
|
removeLineItem: (context, resource, { lineItemId, quantity }) => {
|
|
1279
1382
|
const lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
1280
1383
|
if (!lineItem) {
|
|
@@ -1289,18 +1392,21 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1289
1392
|
(x) => x.id !== lineItemId
|
|
1290
1393
|
);
|
|
1291
1394
|
} else {
|
|
1292
|
-
resource.lineItems.
|
|
1395
|
+
resource.lineItems.forEach((x) => {
|
|
1293
1396
|
if (x.id === lineItemId && quantity) {
|
|
1294
1397
|
x.quantity -= quantity;
|
|
1295
1398
|
x.totalPrice.centAmount = calculateLineItemTotalPrice(x);
|
|
1296
1399
|
}
|
|
1297
|
-
return x;
|
|
1298
1400
|
});
|
|
1299
1401
|
}
|
|
1300
1402
|
resource.totalPrice.centAmount = calculateCartTotalPrice(resource);
|
|
1301
1403
|
},
|
|
1302
1404
|
setBillingAddress: (context, resource, { address }) => {
|
|
1303
|
-
resource.billingAddress =
|
|
1405
|
+
resource.billingAddress = createAddress(
|
|
1406
|
+
address,
|
|
1407
|
+
context.projectKey,
|
|
1408
|
+
this._storage
|
|
1409
|
+
);
|
|
1304
1410
|
},
|
|
1305
1411
|
setShippingMethod: (context, resource, { shippingMethod }) => {
|
|
1306
1412
|
if (shippingMethod) {
|
|
@@ -1350,7 +1456,7 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1350
1456
|
typeId: "type",
|
|
1351
1457
|
id: resolvedType.id
|
|
1352
1458
|
},
|
|
1353
|
-
fields: fields ||
|
|
1459
|
+
fields: fields || {}
|
|
1354
1460
|
};
|
|
1355
1461
|
}
|
|
1356
1462
|
},
|
|
@@ -1358,7 +1464,22 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1358
1464
|
resource.locale = locale;
|
|
1359
1465
|
},
|
|
1360
1466
|
setShippingAddress: (context, resource, { address }) => {
|
|
1361
|
-
|
|
1467
|
+
if (!address) {
|
|
1468
|
+
resource.shippingAddress = void 0;
|
|
1469
|
+
return;
|
|
1470
|
+
}
|
|
1471
|
+
let custom = void 0;
|
|
1472
|
+
if (address.custom) {
|
|
1473
|
+
custom = createCustomFields(
|
|
1474
|
+
address.custom,
|
|
1475
|
+
context.projectKey,
|
|
1476
|
+
this._storage
|
|
1477
|
+
);
|
|
1478
|
+
}
|
|
1479
|
+
resource.shippingAddress = {
|
|
1480
|
+
...address,
|
|
1481
|
+
custom
|
|
1482
|
+
};
|
|
1362
1483
|
}
|
|
1363
1484
|
};
|
|
1364
1485
|
this.draftLineItemtoLineItem = (projectKey, draftLineItem, currency, country) => {
|
|
@@ -1414,7 +1535,9 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1414
1535
|
variant,
|
|
1415
1536
|
price,
|
|
1416
1537
|
totalPrice: {
|
|
1417
|
-
|
|
1538
|
+
type: "centPrecision",
|
|
1539
|
+
currencyCode: price.value.currencyCode,
|
|
1540
|
+
fractionDigits: price.value.fractionDigits,
|
|
1418
1541
|
centAmount: price.value.centAmount * quant
|
|
1419
1542
|
},
|
|
1420
1543
|
taxedPricePortions: [],
|
|
@@ -1431,20 +1554,23 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1431
1554
|
return "cart";
|
|
1432
1555
|
}
|
|
1433
1556
|
create(context, draft) {
|
|
1434
|
-
|
|
1435
|
-
const lineItems = ((_a = draft.lineItems) == null ? void 0 : _a.map(
|
|
1557
|
+
const lineItems = draft.lineItems?.map(
|
|
1436
1558
|
(draftLineItem) => this.draftLineItemtoLineItem(
|
|
1437
1559
|
context.projectKey,
|
|
1438
1560
|
draftLineItem,
|
|
1439
1561
|
draft.currency,
|
|
1440
1562
|
draft.country
|
|
1441
1563
|
)
|
|
1442
|
-
)
|
|
1564
|
+
) ?? [];
|
|
1443
1565
|
const resource = {
|
|
1444
1566
|
...getBaseResourceProperties(),
|
|
1445
1567
|
cartState: "Active",
|
|
1446
1568
|
country: draft.country,
|
|
1447
1569
|
customLineItems: [],
|
|
1570
|
+
directDiscounts: [],
|
|
1571
|
+
discountCodes: [],
|
|
1572
|
+
inventoryMode: "None",
|
|
1573
|
+
itemShippingAddresses: [],
|
|
1448
1574
|
lineItems,
|
|
1449
1575
|
locale: draft.locale,
|
|
1450
1576
|
taxCalculationMode: draft.taxCalculationMode ?? "LineItemLevel",
|
|
@@ -1537,6 +1663,9 @@ var CartDiscountRepository = class extends AbstractResourceRepository {
|
|
|
1537
1663
|
cartPredicate: draft.cartPredicate,
|
|
1538
1664
|
isActive: draft.isActive || false,
|
|
1539
1665
|
name: draft.name,
|
|
1666
|
+
stores: draft.stores?.map(
|
|
1667
|
+
(s) => getStoreKeyReference(s, context.projectKey, this._storage)
|
|
1668
|
+
) ?? [],
|
|
1540
1669
|
references: [],
|
|
1541
1670
|
target: draft.target,
|
|
1542
1671
|
requiresDiscountCode: draft.requiresDiscountCode || false,
|
|
@@ -1585,8 +1714,7 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
1585
1714
|
super(...arguments);
|
|
1586
1715
|
this.actions = {
|
|
1587
1716
|
changeAssetName: (context, resource, { assetId, assetKey, name }) => {
|
|
1588
|
-
|
|
1589
|
-
(_a = resource.assets) == null ? void 0 : _a.forEach((asset) => {
|
|
1717
|
+
resource.assets?.forEach((asset) => {
|
|
1590
1718
|
if (assetId && assetId === asset.id) {
|
|
1591
1719
|
asset.name = name;
|
|
1592
1720
|
}
|
|
@@ -1602,8 +1730,7 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
1602
1730
|
resource.key = key;
|
|
1603
1731
|
},
|
|
1604
1732
|
setAssetDescription: (context, resource, { assetId, assetKey, description }) => {
|
|
1605
|
-
|
|
1606
|
-
(_a = resource.assets) == null ? void 0 : _a.forEach((asset) => {
|
|
1733
|
+
resource.assets?.forEach((asset) => {
|
|
1607
1734
|
if (assetId && assetId === asset.id) {
|
|
1608
1735
|
asset.description = description;
|
|
1609
1736
|
}
|
|
@@ -1613,8 +1740,7 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
1613
1740
|
});
|
|
1614
1741
|
},
|
|
1615
1742
|
setAssetSources: (context, resource, { assetId, assetKey, sources }) => {
|
|
1616
|
-
|
|
1617
|
-
(_a = resource.assets) == null ? void 0 : _a.forEach((asset) => {
|
|
1743
|
+
resource.assets?.forEach((asset) => {
|
|
1618
1744
|
if (assetId && assetId === asset.id) {
|
|
1619
1745
|
asset.sources = sources;
|
|
1620
1746
|
}
|
|
@@ -1662,7 +1788,6 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
1662
1788
|
return "category";
|
|
1663
1789
|
}
|
|
1664
1790
|
create(context, draft) {
|
|
1665
|
-
var _a;
|
|
1666
1791
|
const resource = {
|
|
1667
1792
|
...getBaseResourceProperties(),
|
|
1668
1793
|
key: draft.key,
|
|
@@ -1672,7 +1797,8 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
1672
1797
|
externalId: draft.externalId || "",
|
|
1673
1798
|
parent: draft.parent ? { typeId: "category", id: draft.parent.id } : void 0,
|
|
1674
1799
|
ancestors: [],
|
|
1675
|
-
|
|
1800
|
+
// TODO
|
|
1801
|
+
assets: draft.assets?.map((d) => ({
|
|
1676
1802
|
id: (0, import_uuid4.v4)(),
|
|
1677
1803
|
name: d.name,
|
|
1678
1804
|
description: d.description,
|
|
@@ -1684,7 +1810,7 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
1684
1810
|
context.projectKey,
|
|
1685
1811
|
this._storage
|
|
1686
1812
|
)
|
|
1687
|
-
}))
|
|
1813
|
+
})) || [],
|
|
1688
1814
|
custom: createCustomFields(
|
|
1689
1815
|
draft.custom,
|
|
1690
1816
|
context.projectKey,
|
|
@@ -1864,6 +1990,7 @@ var CustomerRepository = class extends AbstractResourceRepository {
|
|
|
1864
1990
|
create(context, draft) {
|
|
1865
1991
|
const resource = {
|
|
1866
1992
|
...getBaseResourceProperties(),
|
|
1993
|
+
authenticationMode: draft.authenticationMode || "Password",
|
|
1867
1994
|
email: draft.email,
|
|
1868
1995
|
password: draft.password ? Buffer.from(draft.password).toString("base64") : void 0,
|
|
1869
1996
|
isEmailVerified: draft.isEmailVerified || false,
|
|
@@ -2081,10 +2208,9 @@ var ExtensionRepository = class extends AbstractResourceRepository {
|
|
|
2081
2208
|
return "extension";
|
|
2082
2209
|
}
|
|
2083
2210
|
postProcessResource(resource) {
|
|
2084
|
-
var _a;
|
|
2085
2211
|
if (resource) {
|
|
2086
2212
|
const extension = resource;
|
|
2087
|
-
if (extension.destination.type === "HTTP" &&
|
|
2213
|
+
if (extension.destination.type === "HTTP" && extension.destination.authentication?.type === "AuthorizationHeader") {
|
|
2088
2214
|
return maskSecretValue(
|
|
2089
2215
|
extension,
|
|
2090
2216
|
"destination.authentication.headerValue"
|
|
@@ -2142,7 +2268,7 @@ var InventoryEntryRepository = class extends AbstractResourceRepository {
|
|
|
2142
2268
|
typeId: "type",
|
|
2143
2269
|
id: resolvedType.id
|
|
2144
2270
|
},
|
|
2145
|
-
fields: fields ||
|
|
2271
|
+
fields: fields || {}
|
|
2146
2272
|
};
|
|
2147
2273
|
}
|
|
2148
2274
|
},
|
|
@@ -2155,7 +2281,6 @@ var InventoryEntryRepository = class extends AbstractResourceRepository {
|
|
|
2155
2281
|
return "inventory-entry";
|
|
2156
2282
|
}
|
|
2157
2283
|
create(context, draft) {
|
|
2158
|
-
var _a;
|
|
2159
2284
|
const resource = {
|
|
2160
2285
|
...getBaseResourceProperties(),
|
|
2161
2286
|
sku: draft.sku,
|
|
@@ -2166,7 +2291,7 @@ var InventoryEntryRepository = class extends AbstractResourceRepository {
|
|
|
2166
2291
|
supplyChannel: {
|
|
2167
2292
|
...draft.supplyChannel,
|
|
2168
2293
|
typeId: "channel",
|
|
2169
|
-
id:
|
|
2294
|
+
id: draft.supplyChannel?.id ?? ""
|
|
2170
2295
|
},
|
|
2171
2296
|
custom: createCustomFields(
|
|
2172
2297
|
draft.custom,
|
|
@@ -2225,7 +2350,11 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2225
2350
|
resource.state = { typeId: "state", id: resolvedType.id };
|
|
2226
2351
|
},
|
|
2227
2352
|
setBillingAddress: (context, resource, { address }) => {
|
|
2228
|
-
resource.billingAddress =
|
|
2353
|
+
resource.billingAddress = createAddress(
|
|
2354
|
+
address,
|
|
2355
|
+
context.projectKey,
|
|
2356
|
+
this._storage
|
|
2357
|
+
);
|
|
2229
2358
|
},
|
|
2230
2359
|
setCustomerEmail: (context, resource, { email }) => {
|
|
2231
2360
|
resource.customerEmail = email;
|
|
@@ -2252,7 +2381,7 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2252
2381
|
typeId: "type",
|
|
2253
2382
|
id: resolvedType.id
|
|
2254
2383
|
},
|
|
2255
|
-
fields: fields ||
|
|
2384
|
+
fields: fields || {}
|
|
2256
2385
|
};
|
|
2257
2386
|
}
|
|
2258
2387
|
},
|
|
@@ -2263,7 +2392,11 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2263
2392
|
resource.orderNumber = orderNumber;
|
|
2264
2393
|
},
|
|
2265
2394
|
setShippingAddress: (context, resource, { address }) => {
|
|
2266
|
-
resource.shippingAddress =
|
|
2395
|
+
resource.shippingAddress = createAddress(
|
|
2396
|
+
address,
|
|
2397
|
+
context.projectKey,
|
|
2398
|
+
this._storage
|
|
2399
|
+
);
|
|
2267
2400
|
},
|
|
2268
2401
|
setStore: (context, resource, { store }) => {
|
|
2269
2402
|
if (!store)
|
|
@@ -2328,12 +2461,19 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2328
2461
|
return resource;
|
|
2329
2462
|
}
|
|
2330
2463
|
import(context, draft) {
|
|
2331
|
-
var _a, _b;
|
|
2332
2464
|
(0, import_assert2.default)(this, "OrderRepository not valid");
|
|
2333
2465
|
const resource = {
|
|
2334
2466
|
...getBaseResourceProperties(),
|
|
2335
|
-
billingAddress:
|
|
2336
|
-
|
|
2467
|
+
billingAddress: createAddress(
|
|
2468
|
+
draft.billingAddress,
|
|
2469
|
+
context.projectKey,
|
|
2470
|
+
this._storage
|
|
2471
|
+
),
|
|
2472
|
+
shippingAddress: createAddress(
|
|
2473
|
+
draft.shippingAddress,
|
|
2474
|
+
context.projectKey,
|
|
2475
|
+
this._storage
|
|
2476
|
+
),
|
|
2337
2477
|
custom: createCustomFields(
|
|
2338
2478
|
draft.custom,
|
|
2339
2479
|
context.projectKey,
|
|
@@ -2354,17 +2494,13 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2354
2494
|
this._storage
|
|
2355
2495
|
),
|
|
2356
2496
|
syncInfo: [],
|
|
2357
|
-
lineItems:
|
|
2497
|
+
lineItems: draft.lineItems?.map(
|
|
2358
2498
|
(item) => this.lineItemFromImportDraft.bind(this)(context, item)
|
|
2359
|
-
)
|
|
2360
|
-
customLineItems:
|
|
2499
|
+
) || [],
|
|
2500
|
+
customLineItems: draft.customLineItems?.map(
|
|
2361
2501
|
(item) => this.customLineItemFromImportDraft.bind(this)(context, item)
|
|
2362
|
-
)
|
|
2363
|
-
totalPrice:
|
|
2364
|
-
type: "centPrecision",
|
|
2365
|
-
...draft.totalPrice,
|
|
2366
|
-
fractionDigits: 2
|
|
2367
|
-
}
|
|
2502
|
+
) || [],
|
|
2503
|
+
totalPrice: createCentPrecisionMoney(draft.totalPrice)
|
|
2368
2504
|
};
|
|
2369
2505
|
this.saveNew(context, resource);
|
|
2370
2506
|
return resource;
|
|
@@ -2421,7 +2557,7 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2421
2557
|
taxRate: draft.taxRate,
|
|
2422
2558
|
taxedPricePortions: [],
|
|
2423
2559
|
perMethodTaxRate: [],
|
|
2424
|
-
totalPrice:
|
|
2560
|
+
totalPrice: createCentPrecisionMoney(draft.price.value),
|
|
2425
2561
|
variant: {
|
|
2426
2562
|
id: variant.id,
|
|
2427
2563
|
sku: variant.sku,
|
|
@@ -2441,11 +2577,12 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2441
2577
|
discountedPricePerQuantity: [],
|
|
2442
2578
|
money: createTypedMoney(draft.money),
|
|
2443
2579
|
name: draft.name,
|
|
2444
|
-
quantity: draft.quantity,
|
|
2580
|
+
quantity: draft.quantity ?? 0,
|
|
2581
|
+
perMethodTaxRate: [],
|
|
2445
2582
|
priceMode: draft.priceMode,
|
|
2446
2583
|
slug: draft.slug,
|
|
2447
2584
|
state: [],
|
|
2448
|
-
totalPrice:
|
|
2585
|
+
totalPrice: createCentPrecisionMoney(draft.money)
|
|
2449
2586
|
};
|
|
2450
2587
|
return lineItem;
|
|
2451
2588
|
}
|
|
@@ -2507,8 +2644,10 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
2507
2644
|
this.transactionFromTransactionDraft = (draft, context) => ({
|
|
2508
2645
|
...draft,
|
|
2509
2646
|
id: (0, import_uuid5.v4)(),
|
|
2510
|
-
amount:
|
|
2511
|
-
custom: createCustomFields(draft.custom, context.projectKey, this._storage)
|
|
2647
|
+
amount: createCentPrecisionMoney(draft.amount),
|
|
2648
|
+
custom: createCustomFields(draft.custom, context.projectKey, this._storage),
|
|
2649
|
+
state: draft.state ?? "Initial"
|
|
2650
|
+
// Documented as default
|
|
2512
2651
|
});
|
|
2513
2652
|
this.actions = {
|
|
2514
2653
|
setCustomField: (context, resource, { name, value }) => {
|
|
@@ -2533,7 +2672,7 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
2533
2672
|
typeId: "type",
|
|
2534
2673
|
id: resolvedType.id
|
|
2535
2674
|
},
|
|
2536
|
-
fields: fields
|
|
2675
|
+
fields: fields ?? {}
|
|
2537
2676
|
};
|
|
2538
2677
|
}
|
|
2539
2678
|
},
|
|
@@ -2567,6 +2706,23 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
2567
2706
|
obj: stateObj
|
|
2568
2707
|
};
|
|
2569
2708
|
}
|
|
2709
|
+
// addInterfaceInteraction: () => {},
|
|
2710
|
+
// changeAmountPlanned: () => {},
|
|
2711
|
+
// changeTransactionInteractionId: () => {},
|
|
2712
|
+
// changeTransactionTimestamp: () => {},
|
|
2713
|
+
// setAmountPaid: () => {},
|
|
2714
|
+
// setAmountRefunded: () => {},
|
|
2715
|
+
// setAnonymousId: () => {},
|
|
2716
|
+
// setAuthorization: () => {},
|
|
2717
|
+
// setCustomer: () => {},
|
|
2718
|
+
// setExternalId: () => {},
|
|
2719
|
+
// setInterfaceId: () => {},
|
|
2720
|
+
// setKey: () => {},
|
|
2721
|
+
// setMethodInfoInterface: () => {},
|
|
2722
|
+
// setMethodInfoMethod: () => {},
|
|
2723
|
+
// setMethodInfoName: () => {},
|
|
2724
|
+
// setStatusInterfaceCode: () => {},
|
|
2725
|
+
// setStatusInterfaceText: () => {},
|
|
2570
2726
|
};
|
|
2571
2727
|
}
|
|
2572
2728
|
getTypeId() {
|
|
@@ -2575,7 +2731,7 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
2575
2731
|
create(context, draft) {
|
|
2576
2732
|
const resource = {
|
|
2577
2733
|
...getBaseResourceProperties(),
|
|
2578
|
-
amountPlanned:
|
|
2734
|
+
amountPlanned: createCentPrecisionMoney(draft.amountPlanned),
|
|
2579
2735
|
paymentMethodInfo: draft.paymentMethodInfo,
|
|
2580
2736
|
paymentStatus: draft.paymentStatus ? {
|
|
2581
2737
|
...draft.paymentStatus,
|
|
@@ -2821,13 +2977,9 @@ var ProductRepository = class extends AbstractResourceRepository {
|
|
|
2821
2977
|
},
|
|
2822
2978
|
changePrice: (context, resource, { priceId, price, staged }) => {
|
|
2823
2979
|
const changeVariantPrice = (data) => {
|
|
2824
|
-
var _a;
|
|
2825
2980
|
const allVariants = [data.masterVariant, ...data.variants ?? []];
|
|
2826
2981
|
const priceVariant = allVariants.find(
|
|
2827
|
-
(variant2) =>
|
|
2828
|
-
var _a2;
|
|
2829
|
-
return (_a2 = variant2.prices) == null ? void 0 : _a2.some((x) => x.id === priceId);
|
|
2830
|
-
}
|
|
2982
|
+
(variant2) => variant2.prices?.some((x) => x.id === priceId)
|
|
2831
2983
|
);
|
|
2832
2984
|
if (!priceVariant) {
|
|
2833
2985
|
throw new Error(
|
|
@@ -2844,7 +2996,7 @@ var ProductRepository = class extends AbstractResourceRepository {
|
|
|
2844
2996
|
`Variant with id ${priceVariant.id} or sku ${priceVariant.sku} not found on product ${resource.id}`
|
|
2845
2997
|
);
|
|
2846
2998
|
}
|
|
2847
|
-
variant.prices =
|
|
2999
|
+
variant.prices = variant.prices?.map((x) => {
|
|
2848
3000
|
if (x.id === priceId) {
|
|
2849
3001
|
return { ...x, ...price };
|
|
2850
3002
|
}
|
|
@@ -2866,13 +3018,9 @@ var ProductRepository = class extends AbstractResourceRepository {
|
|
|
2866
3018
|
},
|
|
2867
3019
|
removePrice: (context, resource, { priceId, staged }) => {
|
|
2868
3020
|
const removeVariantPrice = (data) => {
|
|
2869
|
-
var _a;
|
|
2870
3021
|
const allVariants = [data.masterVariant, ...data.variants ?? []];
|
|
2871
3022
|
const priceVariant = allVariants.find(
|
|
2872
|
-
(variant2) =>
|
|
2873
|
-
var _a2;
|
|
2874
|
-
return (_a2 = variant2.prices) == null ? void 0 : _a2.some((x) => x.id === priceId);
|
|
2875
|
-
}
|
|
3023
|
+
(variant2) => variant2.prices?.some((x) => x.id === priceId)
|
|
2876
3024
|
);
|
|
2877
3025
|
if (!priceVariant) {
|
|
2878
3026
|
throw new Error(
|
|
@@ -2889,7 +3037,7 @@ var ProductRepository = class extends AbstractResourceRepository {
|
|
|
2889
3037
|
`Variant with id ${priceVariant.id} or sku ${priceVariant.sku} not found on product ${resource.id}`
|
|
2890
3038
|
);
|
|
2891
3039
|
}
|
|
2892
|
-
variant.prices =
|
|
3040
|
+
variant.prices = variant.prices?.filter((x) => x.id !== priceId);
|
|
2893
3041
|
if (isMasterVariant) {
|
|
2894
3042
|
data.masterVariant = variant;
|
|
2895
3043
|
} else {
|
|
@@ -2904,13 +3052,46 @@ var ProductRepository = class extends AbstractResourceRepository {
|
|
|
2904
3052
|
checkForStagedChanges(resource);
|
|
2905
3053
|
return resource;
|
|
2906
3054
|
}
|
|
3055
|
+
// 'changeName': () => {},
|
|
3056
|
+
// 'changeSlug': () => {},
|
|
3057
|
+
// 'addVariant': () => {},
|
|
3058
|
+
// 'removeVariant': () => {},
|
|
3059
|
+
// 'changeMasterVariant': () => {},
|
|
3060
|
+
// 'setPrices': () => {},
|
|
3061
|
+
// 'setProductPriceCustomType': () => {},
|
|
3062
|
+
// 'setProductPriceCustomField': () => {},
|
|
3063
|
+
// 'setDiscountedPrice': () => {},
|
|
3064
|
+
// 'setAttributeInAllVariants': () => {},
|
|
3065
|
+
// 'addToCategory': () => {},
|
|
3066
|
+
// 'setCategoryOrderHint': () => {},
|
|
3067
|
+
// 'removeFromCategory': () => {},
|
|
3068
|
+
// 'setTaxCategory': () => {},
|
|
3069
|
+
// 'setSku': () => {},
|
|
3070
|
+
// 'setProductVariantKey': () => {},
|
|
3071
|
+
// 'setImageLabel': () => {},
|
|
3072
|
+
// 'addAsset': () => {},
|
|
3073
|
+
// 'removeAsset': () => {},
|
|
3074
|
+
// 'setAssetKey': () => {},
|
|
3075
|
+
// 'changeAssetOrder': () => {},
|
|
3076
|
+
// 'changeAssetName': () => {},
|
|
3077
|
+
// 'setAssetDescription': () => {},
|
|
3078
|
+
// 'setAssetTags': () => {},
|
|
3079
|
+
// 'setAssetSources': () => {},
|
|
3080
|
+
// 'setAssetCustomType': () => {},
|
|
3081
|
+
// 'setAssetCustomField': () => {},
|
|
3082
|
+
// 'setSearchKeywords': () => {},
|
|
3083
|
+
// 'setMetaTitle': () => {},
|
|
3084
|
+
// 'setMetaDescription': () => {},
|
|
3085
|
+
// 'setMetaKeywords': () => {},
|
|
3086
|
+
// 'revertStagedChanges': () => {},
|
|
3087
|
+
// 'revertStagedVariantChanges': () => {},
|
|
3088
|
+
// 'transitionState': () => {},
|
|
2907
3089
|
};
|
|
2908
3090
|
}
|
|
2909
3091
|
getTypeId() {
|
|
2910
3092
|
return "product";
|
|
2911
3093
|
}
|
|
2912
3094
|
create(context, draft) {
|
|
2913
|
-
var _a;
|
|
2914
3095
|
if (!draft.masterVariant) {
|
|
2915
3096
|
throw new Error("Missing master variant");
|
|
2916
3097
|
}
|
|
@@ -2935,9 +3116,9 @@ var ProductRepository = class extends AbstractResourceRepository {
|
|
|
2935
3116
|
slug: draft.slug,
|
|
2936
3117
|
categories: [],
|
|
2937
3118
|
masterVariant: variantFromDraft(1, draft.masterVariant),
|
|
2938
|
-
variants:
|
|
3119
|
+
variants: draft.variants?.map(
|
|
2939
3120
|
(variant, index) => variantFromDraft(index + 2, variant)
|
|
2940
|
-
)
|
|
3121
|
+
) ?? [],
|
|
2941
3122
|
searchKeywords: draft.searchKeywords ?? {}
|
|
2942
3123
|
};
|
|
2943
3124
|
const resource = {
|
|
@@ -2983,26 +3164,18 @@ var getVariant = (productData, variantId, sku) => {
|
|
|
2983
3164
|
variantIndex: !isMasterVariant && foundVariant ? productData.variants.indexOf(foundVariant) : -1
|
|
2984
3165
|
};
|
|
2985
3166
|
};
|
|
2986
|
-
var variantFromDraft = (variantId, variant) => {
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
images: []
|
|
2995
|
-
};
|
|
2996
|
-
};
|
|
3167
|
+
var variantFromDraft = (variantId, variant) => ({
|
|
3168
|
+
id: variantId,
|
|
3169
|
+
sku: variant?.sku,
|
|
3170
|
+
attributes: variant?.attributes ?? [],
|
|
3171
|
+
prices: variant?.prices?.map(priceFromDraft),
|
|
3172
|
+
assets: [],
|
|
3173
|
+
images: []
|
|
3174
|
+
});
|
|
2997
3175
|
var priceFromDraft = (draft) => ({
|
|
2998
3176
|
id: (0, import_uuid6.v4)(),
|
|
2999
3177
|
country: draft.country,
|
|
3000
|
-
value:
|
|
3001
|
-
currencyCode: draft.value.currencyCode,
|
|
3002
|
-
centAmount: draft.value.centAmount,
|
|
3003
|
-
fractionDigits: 2,
|
|
3004
|
-
type: "centPrecision"
|
|
3005
|
-
}
|
|
3178
|
+
value: createTypedMoney(draft.value)
|
|
3006
3179
|
});
|
|
3007
3180
|
|
|
3008
3181
|
// src/repositories/product-discount.ts
|
|
@@ -3136,6 +3309,7 @@ var parseFilter = (filter) => {
|
|
|
3136
3309
|
(t) => ({
|
|
3137
3310
|
type: "Symbol",
|
|
3138
3311
|
kind: "string",
|
|
3312
|
+
// @ts-ignore
|
|
3139
3313
|
value: t.token.groups[1]
|
|
3140
3314
|
})
|
|
3141
3315
|
).nud(
|
|
@@ -3280,7 +3454,6 @@ var getVariants = (p) => [
|
|
|
3280
3454
|
|
|
3281
3455
|
// src/priceSelector.ts
|
|
3282
3456
|
var applyPriceSelector = (products, selector) => {
|
|
3283
|
-
var _a;
|
|
3284
3457
|
validatePriceSelector(selector);
|
|
3285
3458
|
for (const product of products) {
|
|
3286
3459
|
const variants = [
|
|
@@ -3288,7 +3461,7 @@ var applyPriceSelector = (products, selector) => {
|
|
|
3288
3461
|
...product.variants ?? []
|
|
3289
3462
|
].filter((x) => x != void 0);
|
|
3290
3463
|
for (const variant of variants) {
|
|
3291
|
-
const scopedPrices =
|
|
3464
|
+
const scopedPrices = variant.prices?.filter((p) => priceSelectorFilter(p, selector)) ?? [];
|
|
3292
3465
|
if (scopedPrices.length > 0) {
|
|
3293
3466
|
const price = scopedPrices[0];
|
|
3294
3467
|
variant.scopedPriceDiscounted = false;
|
|
@@ -3312,17 +3485,16 @@ var validatePriceSelector = (selector) => {
|
|
|
3312
3485
|
}
|
|
3313
3486
|
};
|
|
3314
3487
|
var priceSelectorFilter = (price, selector) => {
|
|
3315
|
-
var _a, _b, _c, _d;
|
|
3316
3488
|
if ((selector.country || price.country) && selector.country !== price.country) {
|
|
3317
3489
|
return false;
|
|
3318
3490
|
}
|
|
3319
3491
|
if ((selector.currency || price.value.currencyCode) && selector.currency !== price.value.currencyCode) {
|
|
3320
3492
|
return false;
|
|
3321
3493
|
}
|
|
3322
|
-
if ((selector.channel ||
|
|
3494
|
+
if ((selector.channel || price.channel?.id) && selector.channel !== price.channel?.id) {
|
|
3323
3495
|
return false;
|
|
3324
3496
|
}
|
|
3325
|
-
if ((selector.customerGroup ||
|
|
3497
|
+
if ((selector.customerGroup || price.customerGroup?.id) && selector.customerGroup !== price.customerGroup?.id) {
|
|
3326
3498
|
return false;
|
|
3327
3499
|
}
|
|
3328
3500
|
return true;
|
|
@@ -3446,6 +3618,11 @@ var ProductProjectionSearch = class {
|
|
|
3446
3618
|
}
|
|
3447
3619
|
return result;
|
|
3448
3620
|
}
|
|
3621
|
+
/**
|
|
3622
|
+
* TODO: This implemention needs the following additional features:
|
|
3623
|
+
* - counting products
|
|
3624
|
+
* - correct dataType
|
|
3625
|
+
*/
|
|
3449
3626
|
termFacet(facet, products) {
|
|
3450
3627
|
const result = {
|
|
3451
3628
|
type: "terms",
|
|
@@ -3497,7 +3674,7 @@ var ProductProjectionSearch = class {
|
|
|
3497
3674
|
for (const p of products) {
|
|
3498
3675
|
for (const v of getVariants(p)) {
|
|
3499
3676
|
const val = resolveVariantValue(v, source);
|
|
3500
|
-
if (filters
|
|
3677
|
+
if (filters?.some((f) => f.match(val))) {
|
|
3501
3678
|
count++;
|
|
3502
3679
|
}
|
|
3503
3680
|
}
|
|
@@ -3511,7 +3688,7 @@ var ProductProjectionSearch = class {
|
|
|
3511
3688
|
};
|
|
3512
3689
|
}
|
|
3513
3690
|
rangeFacet(source, ranges, products) {
|
|
3514
|
-
const counts =
|
|
3691
|
+
const counts = ranges?.map((range) => {
|
|
3515
3692
|
if (source.startsWith("variants.")) {
|
|
3516
3693
|
const values = [];
|
|
3517
3694
|
for (const p of products) {
|
|
@@ -3533,6 +3710,7 @@ var ProductProjectionSearch = class {
|
|
|
3533
3710
|
to: range.stop || 0,
|
|
3534
3711
|
toStr: range.stop !== null ? Number(range.stop).toFixed(1) : "",
|
|
3535
3712
|
count: numValues,
|
|
3713
|
+
// totalCount: 0,
|
|
3536
3714
|
total: values.reduce((a, b) => a + b, 0),
|
|
3537
3715
|
min: numValues > 0 ? Math.min(...values) : 0,
|
|
3538
3716
|
max: numValues > 0 ? Math.max(...values) : 0,
|
|
@@ -3541,9 +3719,10 @@ var ProductProjectionSearch = class {
|
|
|
3541
3719
|
} else {
|
|
3542
3720
|
throw new Error("not supported");
|
|
3543
3721
|
}
|
|
3544
|
-
})
|
|
3722
|
+
}) || [];
|
|
3545
3723
|
const data = {
|
|
3546
3724
|
type: "range",
|
|
3725
|
+
// @ts-ignore
|
|
3547
3726
|
dataType: "number",
|
|
3548
3727
|
ranges: counts
|
|
3549
3728
|
};
|
|
@@ -3613,7 +3792,8 @@ var ProductSelectionRepository = class extends AbstractResourceRepository {
|
|
|
3613
3792
|
...getBaseResourceProperties(),
|
|
3614
3793
|
productCount: 0,
|
|
3615
3794
|
name: draft.name,
|
|
3616
|
-
type: "individual"
|
|
3795
|
+
type: "individual",
|
|
3796
|
+
mode: "Individual"
|
|
3617
3797
|
};
|
|
3618
3798
|
this.saveNew(context, resource);
|
|
3619
3799
|
return resource;
|
|
@@ -3636,7 +3816,6 @@ var ProductTypeRepository = class extends AbstractResourceRepository {
|
|
|
3636
3816
|
attributeName,
|
|
3637
3817
|
newValue
|
|
3638
3818
|
}) => {
|
|
3639
|
-
var _a;
|
|
3640
3819
|
const updateAttributeType = (type) => {
|
|
3641
3820
|
switch (type.name) {
|
|
3642
3821
|
case "lenum":
|
|
@@ -3651,30 +3830,27 @@ var ProductTypeRepository = class extends AbstractResourceRepository {
|
|
|
3651
3830
|
return;
|
|
3652
3831
|
}
|
|
3653
3832
|
};
|
|
3654
|
-
|
|
3833
|
+
resource.attributes?.forEach((value) => {
|
|
3655
3834
|
if (value.name === attributeName) {
|
|
3656
3835
|
updateAttributeType(value.type);
|
|
3657
3836
|
}
|
|
3658
3837
|
});
|
|
3659
3838
|
},
|
|
3660
3839
|
changeLabel: (context, resource, { attributeName, label }) => {
|
|
3661
|
-
|
|
3662
|
-
(_a = resource.attributes) == null ? void 0 : _a.forEach((value) => {
|
|
3840
|
+
resource.attributes?.forEach((value) => {
|
|
3663
3841
|
if (value.name === attributeName) {
|
|
3664
3842
|
value.label = label;
|
|
3665
3843
|
}
|
|
3666
3844
|
});
|
|
3667
3845
|
},
|
|
3668
3846
|
addAttributeDefinition: (context, resource, { attribute }) => {
|
|
3669
|
-
|
|
3670
|
-
(_a = resource.attributes) == null ? void 0 : _a.push(
|
|
3847
|
+
resource.attributes?.push(
|
|
3671
3848
|
this.attributeDefinitionFromAttributeDefinitionDraft(context, attribute)
|
|
3672
3849
|
);
|
|
3673
3850
|
},
|
|
3674
3851
|
changeAttributeOrderByName: (context, resource, { attributeNames }) => {
|
|
3675
|
-
var _a;
|
|
3676
3852
|
const attrs = new Map(
|
|
3677
|
-
|
|
3853
|
+
resource.attributes?.map((item) => [item.name, item])
|
|
3678
3854
|
);
|
|
3679
3855
|
const result = [];
|
|
3680
3856
|
let current = resource.attributes;
|
|
@@ -3684,7 +3860,7 @@ var ProductTypeRepository = class extends AbstractResourceRepository {
|
|
|
3684
3860
|
throw new Error("New attr");
|
|
3685
3861
|
}
|
|
3686
3862
|
result.push(attr);
|
|
3687
|
-
current = current
|
|
3863
|
+
current = current?.filter((f) => f.name !== attrName);
|
|
3688
3864
|
});
|
|
3689
3865
|
resource.attributes = result;
|
|
3690
3866
|
if (current) {
|
|
@@ -3692,12 +3868,10 @@ var ProductTypeRepository = class extends AbstractResourceRepository {
|
|
|
3692
3868
|
}
|
|
3693
3869
|
},
|
|
3694
3870
|
removeAttributeDefinition: (context, resource, { name }) => {
|
|
3695
|
-
|
|
3696
|
-
resource.attributes = (_a = resource.attributes) == null ? void 0 : _a.filter((f) => f.name !== name);
|
|
3871
|
+
resource.attributes = resource.attributes?.filter((f) => f.name !== name);
|
|
3697
3872
|
},
|
|
3698
3873
|
removeEnumValues: (context, resource, { attributeName, keys }) => {
|
|
3699
|
-
|
|
3700
|
-
(_a = resource.attributes) == null ? void 0 : _a.forEach((attr) => {
|
|
3874
|
+
resource.attributes?.forEach((attr) => {
|
|
3701
3875
|
if (attr.name == attributeName) {
|
|
3702
3876
|
if (attr.type.name == "enum") {
|
|
3703
3877
|
attr.type.values = attr.type.values.filter(
|
|
@@ -3756,20 +3930,18 @@ var ProjectRepository = class extends AbstractRepository {
|
|
|
3756
3930
|
resource.messages.deleteDaysAfterCreation = messagesConfiguration.deleteDaysAfterCreation;
|
|
3757
3931
|
},
|
|
3758
3932
|
changeProductSearchIndexingEnabled: (context, resource, { enabled }) => {
|
|
3759
|
-
|
|
3760
|
-
if (!((_a = resource.searchIndexing) == null ? void 0 : _a.products)) {
|
|
3933
|
+
if (!resource.searchIndexing?.products) {
|
|
3761
3934
|
throw new Error("Invalid project state");
|
|
3762
3935
|
}
|
|
3763
3936
|
resource.searchIndexing.products.status = enabled ? "Activated" : "Deactivated";
|
|
3764
|
-
resource.searchIndexing.products.lastModifiedAt = new Date().toISOString();
|
|
3937
|
+
resource.searchIndexing.products.lastModifiedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
3765
3938
|
},
|
|
3766
3939
|
changeOrderSearchStatus: (context, resource, { status }) => {
|
|
3767
|
-
|
|
3768
|
-
if (!((_a = resource.searchIndexing) == null ? void 0 : _a.orders)) {
|
|
3940
|
+
if (!resource.searchIndexing?.orders) {
|
|
3769
3941
|
throw new Error("Invalid project state");
|
|
3770
3942
|
}
|
|
3771
3943
|
resource.searchIndexing.orders.status = status;
|
|
3772
|
-
resource.searchIndexing.orders.lastModifiedAt = new Date().toISOString();
|
|
3944
|
+
resource.searchIndexing.orders.lastModifiedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
3773
3945
|
},
|
|
3774
3946
|
setShippingRateInputType: (context, resource, { shippingRateInputType }) => {
|
|
3775
3947
|
resource.shippingRateInputType = shippingRateInputType;
|
|
@@ -3861,18 +4033,15 @@ var import_deep_equal3 = __toESM(require("deep-equal"));
|
|
|
3861
4033
|
var ShippingMethodRepository = class extends AbstractResourceRepository {
|
|
3862
4034
|
constructor() {
|
|
3863
4035
|
super(...arguments);
|
|
3864
|
-
this._transformZoneRateDraft = (context, draft) => {
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
shippingRates: (_a = draft.shippingRates) == null ? void 0 : _a.map(this._transformShippingRate)
|
|
3874
|
-
};
|
|
3875
|
-
};
|
|
4036
|
+
this._transformZoneRateDraft = (context, draft) => ({
|
|
4037
|
+
...draft,
|
|
4038
|
+
zone: getReferenceFromResourceIdentifier(
|
|
4039
|
+
draft.zone,
|
|
4040
|
+
context.projectKey,
|
|
4041
|
+
this._storage
|
|
4042
|
+
),
|
|
4043
|
+
shippingRates: draft.shippingRates?.map(this._transformShippingRate)
|
|
4044
|
+
});
|
|
3876
4045
|
this._transformShippingRate = (rate) => ({
|
|
3877
4046
|
price: createTypedMoney(rate.price),
|
|
3878
4047
|
freeAbove: rate.freeAbove && createTypedMoney(rate.freeAbove),
|
|
@@ -3972,7 +4141,6 @@ var ShippingMethodRepository = class extends AbstractResourceRepository {
|
|
|
3972
4141
|
return "shipping-method";
|
|
3973
4142
|
}
|
|
3974
4143
|
create(context, draft) {
|
|
3975
|
-
var _a;
|
|
3976
4144
|
const resource = {
|
|
3977
4145
|
...getBaseResourceProperties(),
|
|
3978
4146
|
...draft,
|
|
@@ -3981,7 +4149,7 @@ var ShippingMethodRepository = class extends AbstractResourceRepository {
|
|
|
3981
4149
|
context.projectKey,
|
|
3982
4150
|
this._storage
|
|
3983
4151
|
),
|
|
3984
|
-
zoneRates:
|
|
4152
|
+
zoneRates: draft.zoneRates?.map(
|
|
3985
4153
|
(z) => this._transformZoneRateDraft(context, z)
|
|
3986
4154
|
),
|
|
3987
4155
|
custom: createCustomFields(
|
|
@@ -4001,7 +4169,6 @@ var ShoppingListRepository = class extends AbstractResourceRepository {
|
|
|
4001
4169
|
return "shopping-list";
|
|
4002
4170
|
}
|
|
4003
4171
|
create(context, draft) {
|
|
4004
|
-
var _a, _b;
|
|
4005
4172
|
const resource = {
|
|
4006
4173
|
...getBaseResourceProperties(),
|
|
4007
4174
|
...draft,
|
|
@@ -4011,7 +4178,7 @@ var ShoppingListRepository = class extends AbstractResourceRepository {
|
|
|
4011
4178
|
this._storage
|
|
4012
4179
|
),
|
|
4013
4180
|
textLineItems: [],
|
|
4014
|
-
lineItems:
|
|
4181
|
+
lineItems: draft.lineItems?.map((e) => ({
|
|
4015
4182
|
...getBaseResourceProperties(),
|
|
4016
4183
|
...e,
|
|
4017
4184
|
addedAt: e.addedAt ?? "",
|
|
@@ -4019,14 +4186,18 @@ var ShoppingListRepository = class extends AbstractResourceRepository {
|
|
|
4019
4186
|
name: {},
|
|
4020
4187
|
quantity: e.quantity ?? 1,
|
|
4021
4188
|
productType: { typeId: "product-type", id: "" },
|
|
4022
|
-
custom: createCustomFields(
|
|
4023
|
-
|
|
4189
|
+
custom: createCustomFields(
|
|
4190
|
+
e.custom,
|
|
4191
|
+
context.projectKey,
|
|
4192
|
+
this._storage
|
|
4193
|
+
)
|
|
4194
|
+
})) ?? [],
|
|
4024
4195
|
customer: draft.customer ? getReferenceFromResourceIdentifier(
|
|
4025
4196
|
draft.customer,
|
|
4026
4197
|
context.projectKey,
|
|
4027
4198
|
this._storage
|
|
4028
4199
|
) : void 0,
|
|
4029
|
-
store:
|
|
4200
|
+
store: draft.store ? getStoreKeyReference(draft.store, context.projectKey, this._storage) : void 0
|
|
4030
4201
|
};
|
|
4031
4202
|
this.saveNew(context, resource);
|
|
4032
4203
|
return resource;
|
|
@@ -4067,7 +4238,6 @@ var StandAlonePriceRepository = class extends AbstractResourceRepository {
|
|
|
4067
4238
|
return "standalone-price";
|
|
4068
4239
|
}
|
|
4069
4240
|
create(context, draft) {
|
|
4070
|
-
var _a;
|
|
4071
4241
|
const resource = {
|
|
4072
4242
|
...getBaseResourceProperties(),
|
|
4073
4243
|
active: draft.active ? draft.active : false,
|
|
@@ -4075,7 +4245,7 @@ var StandAlonePriceRepository = class extends AbstractResourceRepository {
|
|
|
4075
4245
|
value: createTypedMoney(draft.value),
|
|
4076
4246
|
country: draft.country,
|
|
4077
4247
|
discounted: draft.discounted ? this.transformDiscountDraft(draft.discounted) : void 0,
|
|
4078
|
-
channel:
|
|
4248
|
+
channel: draft.channel?.id ? this.transformChannelReferenceDraft(draft.channel) : void 0,
|
|
4079
4249
|
validFrom: draft.validFrom,
|
|
4080
4250
|
validUntil: draft.validUntil
|
|
4081
4251
|
};
|
|
@@ -4117,7 +4287,7 @@ var StateRepository = class extends AbstractResourceRepository {
|
|
|
4117
4287
|
resource.roles = roles;
|
|
4118
4288
|
},
|
|
4119
4289
|
setTransitions: (context, resource, { transitions }) => {
|
|
4120
|
-
resource.transitions = transitions
|
|
4290
|
+
resource.transitions = transitions?.map(
|
|
4121
4291
|
(resourceId) => ({
|
|
4122
4292
|
id: resourceId.id || "",
|
|
4123
4293
|
typeId: "state"
|
|
@@ -4193,6 +4363,7 @@ var StoreRepository = class extends AbstractResourceRepository {
|
|
|
4193
4363
|
key: draft.key,
|
|
4194
4364
|
name: draft.name,
|
|
4195
4365
|
languages: draft.languages ?? [],
|
|
4366
|
+
countries: draft.countries ?? [],
|
|
4196
4367
|
distributionChannels: this.transformChannels(
|
|
4197
4368
|
context,
|
|
4198
4369
|
draft.distributionChannels
|
|
@@ -4309,11 +4480,10 @@ var TaxCategoryRepository = class extends AbstractResourceRepository {
|
|
|
4309
4480
|
return "tax-category";
|
|
4310
4481
|
}
|
|
4311
4482
|
create(context, draft) {
|
|
4312
|
-
var _a;
|
|
4313
4483
|
const resource = {
|
|
4314
4484
|
...getBaseResourceProperties(),
|
|
4315
4485
|
...draft,
|
|
4316
|
-
rates:
|
|
4486
|
+
rates: draft.rates?.map(this.taxRateFromTaxRateDraft) || []
|
|
4317
4487
|
};
|
|
4318
4488
|
this.saveNew(context, resource);
|
|
4319
4489
|
return resource;
|
|
@@ -4465,6 +4635,9 @@ var ZoneRepository = class extends AbstractResourceRepository {
|
|
|
4465
4635
|
|
|
4466
4636
|
// src/repositories/index.ts
|
|
4467
4637
|
var createRepositories = (storage) => ({
|
|
4638
|
+
"associate-role": new AssociateRoleRepository(storage),
|
|
4639
|
+
"attribute-group": new AttributeGroupRepository(storage),
|
|
4640
|
+
"business-unit": new BusinessUnitRepository(storage),
|
|
4468
4641
|
category: new CategoryRepository(storage),
|
|
4469
4642
|
cart: new CartRepository(storage),
|
|
4470
4643
|
"cart-discount": new CartDiscountRepository(storage),
|
|
@@ -4642,6 +4815,7 @@ var AbstractService = class {
|
|
|
4642
4815
|
);
|
|
4643
4816
|
return result;
|
|
4644
4817
|
}
|
|
4818
|
+
// No idea what i'm doing
|
|
4645
4819
|
_parseParam(value) {
|
|
4646
4820
|
if (Array.isArray(value)) {
|
|
4647
4821
|
return value;
|
|
@@ -4676,6 +4850,7 @@ var CartService = class extends AbstractService {
|
|
|
4676
4850
|
currency: cartOrOrder.totalPrice.currencyCode,
|
|
4677
4851
|
discountCodes: [],
|
|
4678
4852
|
shipping: [],
|
|
4853
|
+
// TODO: cartOrOrder.shipping,
|
|
4679
4854
|
lineItems: cartOrOrder.lineItems.map((lineItem) => ({
|
|
4680
4855
|
...lineItem,
|
|
4681
4856
|
variantId: lineItem.variant.id,
|
|
@@ -4786,7 +4961,10 @@ var CustomerService = class extends AbstractService {
|
|
|
4786
4961
|
const customer = this.repository.query(getRepositoryContext(request), {
|
|
4787
4962
|
where: [`email="${request.body.email}"`]
|
|
4788
4963
|
});
|
|
4789
|
-
const ttlMinutes = request.params.ttlMinutes ?
|
|
4964
|
+
const ttlMinutes = request.params.ttlMinutes ? (
|
|
4965
|
+
// @ts-ignore
|
|
4966
|
+
+request.params.ttlMinutes
|
|
4967
|
+
) : 34560;
|
|
4790
4968
|
const { version, ...rest } = getBaseResourceProperties();
|
|
4791
4969
|
return response.status(200).send({
|
|
4792
4970
|
...rest,
|
|
@@ -5241,10 +5419,9 @@ var CommercetoolsMock = class {
|
|
|
5241
5419
|
this.mockApiHost();
|
|
5242
5420
|
}
|
|
5243
5421
|
stop() {
|
|
5244
|
-
|
|
5245
|
-
(_a = this._nockScopes.auth) == null ? void 0 : _a.persist(false);
|
|
5422
|
+
this._nockScopes.auth?.persist(false);
|
|
5246
5423
|
this._nockScopes.auth = void 0;
|
|
5247
|
-
|
|
5424
|
+
this._nockScopes.api?.persist(false);
|
|
5248
5425
|
this._nockScopes.api = void 0;
|
|
5249
5426
|
}
|
|
5250
5427
|
clear() {
|
|
@@ -5274,7 +5451,7 @@ var CommercetoolsMock = class {
|
|
|
5274
5451
|
const app = (0, import_express6.default)();
|
|
5275
5452
|
const projectRouter = import_express6.default.Router({ mergeParams: true });
|
|
5276
5453
|
projectRouter.use(import_express6.default.json());
|
|
5277
|
-
if (!
|
|
5454
|
+
if (!options?.silent) {
|
|
5278
5455
|
app.use((0, import_morgan.default)("tiny"));
|
|
5279
5456
|
}
|
|
5280
5457
|
app.use("/oauth", this._oauth2.createRouter());
|