@labdigital/commercetools-mock 1.2.0 → 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 +6319 -6084
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +344 -163
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +340 -163
- 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/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 +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,18 @@ 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
1294
|
resource.lineItems.map((x) => {
|
|
1230
|
-
if (x.productId ===
|
|
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
1299
|
return x;
|
|
1235
1300
|
});
|
|
1236
1301
|
} else {
|
|
1237
|
-
if (!
|
|
1302
|
+
if (!variant.prices?.length) {
|
|
1238
1303
|
throw new CommercetoolsError({
|
|
1239
1304
|
code: "General",
|
|
1240
1305
|
message: `A product with ID '${productId}' doesn't have any prices.`
|
|
@@ -1264,6 +1329,7 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1264
1329
|
perMethodTaxRate: [],
|
|
1265
1330
|
totalPrice: {
|
|
1266
1331
|
...price.value,
|
|
1332
|
+
type: "centPrecision",
|
|
1267
1333
|
centAmount: price.value.centAmount * quantity
|
|
1268
1334
|
},
|
|
1269
1335
|
quantity,
|
|
@@ -1275,6 +1341,46 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1275
1341
|
}
|
|
1276
1342
|
resource.totalPrice.centAmount = calculateCartTotalPrice(resource);
|
|
1277
1343
|
},
|
|
1344
|
+
changeLineItemQuantity: (context, resource, { lineItemId, lineItemKey, quantity }) => {
|
|
1345
|
+
let lineItem;
|
|
1346
|
+
if (lineItemId) {
|
|
1347
|
+
lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
1348
|
+
if (!lineItem) {
|
|
1349
|
+
throw new CommercetoolsError({
|
|
1350
|
+
code: "General",
|
|
1351
|
+
message: `A line item with ID '${lineItemId}' not found.`
|
|
1352
|
+
});
|
|
1353
|
+
}
|
|
1354
|
+
} else if (lineItemKey) {
|
|
1355
|
+
lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
1356
|
+
if (!lineItem) {
|
|
1357
|
+
throw new CommercetoolsError({
|
|
1358
|
+
code: "General",
|
|
1359
|
+
message: `A line item with Key '${lineItemKey}' not found.`
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1362
|
+
} else {
|
|
1363
|
+
throw new CommercetoolsError({
|
|
1364
|
+
code: "General",
|
|
1365
|
+
message: `Either lineItemid or lineItemKey needs to be provided.`
|
|
1366
|
+
});
|
|
1367
|
+
}
|
|
1368
|
+
const shouldDelete = !quantity || quantity >= lineItem.quantity;
|
|
1369
|
+
if (shouldDelete) {
|
|
1370
|
+
resource.lineItems = resource.lineItems.filter(
|
|
1371
|
+
(x) => x.id !== lineItemId
|
|
1372
|
+
);
|
|
1373
|
+
} else {
|
|
1374
|
+
resource.lineItems.map((x) => {
|
|
1375
|
+
if (x.id === lineItemId && quantity) {
|
|
1376
|
+
x.quantity -= quantity;
|
|
1377
|
+
x.totalPrice.centAmount = calculateLineItemTotalPrice(x);
|
|
1378
|
+
}
|
|
1379
|
+
return x;
|
|
1380
|
+
});
|
|
1381
|
+
}
|
|
1382
|
+
resource.totalPrice.centAmount = calculateCartTotalPrice(resource);
|
|
1383
|
+
},
|
|
1278
1384
|
removeLineItem: (context, resource, { lineItemId, quantity }) => {
|
|
1279
1385
|
const lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
1280
1386
|
if (!lineItem) {
|
|
@@ -1300,7 +1406,11 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1300
1406
|
resource.totalPrice.centAmount = calculateCartTotalPrice(resource);
|
|
1301
1407
|
},
|
|
1302
1408
|
setBillingAddress: (context, resource, { address }) => {
|
|
1303
|
-
resource.billingAddress =
|
|
1409
|
+
resource.billingAddress = createAddress(
|
|
1410
|
+
address,
|
|
1411
|
+
context.projectKey,
|
|
1412
|
+
this._storage
|
|
1413
|
+
);
|
|
1304
1414
|
},
|
|
1305
1415
|
setShippingMethod: (context, resource, { shippingMethod }) => {
|
|
1306
1416
|
if (shippingMethod) {
|
|
@@ -1350,7 +1460,7 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1350
1460
|
typeId: "type",
|
|
1351
1461
|
id: resolvedType.id
|
|
1352
1462
|
},
|
|
1353
|
-
fields: fields ||
|
|
1463
|
+
fields: fields || {}
|
|
1354
1464
|
};
|
|
1355
1465
|
}
|
|
1356
1466
|
},
|
|
@@ -1358,7 +1468,22 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1358
1468
|
resource.locale = locale;
|
|
1359
1469
|
},
|
|
1360
1470
|
setShippingAddress: (context, resource, { address }) => {
|
|
1361
|
-
|
|
1471
|
+
if (!address) {
|
|
1472
|
+
resource.shippingAddress = void 0;
|
|
1473
|
+
return;
|
|
1474
|
+
}
|
|
1475
|
+
let custom = void 0;
|
|
1476
|
+
if (address.custom) {
|
|
1477
|
+
custom = createCustomFields(
|
|
1478
|
+
address.custom,
|
|
1479
|
+
context.projectKey,
|
|
1480
|
+
this._storage
|
|
1481
|
+
);
|
|
1482
|
+
}
|
|
1483
|
+
resource.shippingAddress = {
|
|
1484
|
+
...address,
|
|
1485
|
+
custom
|
|
1486
|
+
};
|
|
1362
1487
|
}
|
|
1363
1488
|
};
|
|
1364
1489
|
this.draftLineItemtoLineItem = (projectKey, draftLineItem, currency, country) => {
|
|
@@ -1414,7 +1539,9 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1414
1539
|
variant,
|
|
1415
1540
|
price,
|
|
1416
1541
|
totalPrice: {
|
|
1417
|
-
|
|
1542
|
+
type: "centPrecision",
|
|
1543
|
+
currencyCode: price.value.currencyCode,
|
|
1544
|
+
fractionDigits: price.value.fractionDigits,
|
|
1418
1545
|
centAmount: price.value.centAmount * quant
|
|
1419
1546
|
},
|
|
1420
1547
|
taxedPricePortions: [],
|
|
@@ -1431,20 +1558,23 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1431
1558
|
return "cart";
|
|
1432
1559
|
}
|
|
1433
1560
|
create(context, draft) {
|
|
1434
|
-
|
|
1435
|
-
const lineItems = ((_a = draft.lineItems) == null ? void 0 : _a.map(
|
|
1561
|
+
const lineItems = draft.lineItems?.map(
|
|
1436
1562
|
(draftLineItem) => this.draftLineItemtoLineItem(
|
|
1437
1563
|
context.projectKey,
|
|
1438
1564
|
draftLineItem,
|
|
1439
1565
|
draft.currency,
|
|
1440
1566
|
draft.country
|
|
1441
1567
|
)
|
|
1442
|
-
)
|
|
1568
|
+
) ?? [];
|
|
1443
1569
|
const resource = {
|
|
1444
1570
|
...getBaseResourceProperties(),
|
|
1445
1571
|
cartState: "Active",
|
|
1446
1572
|
country: draft.country,
|
|
1447
1573
|
customLineItems: [],
|
|
1574
|
+
directDiscounts: [],
|
|
1575
|
+
discountCodes: [],
|
|
1576
|
+
inventoryMode: "None",
|
|
1577
|
+
itemShippingAddresses: [],
|
|
1448
1578
|
lineItems,
|
|
1449
1579
|
locale: draft.locale,
|
|
1450
1580
|
taxCalculationMode: draft.taxCalculationMode ?? "LineItemLevel",
|
|
@@ -1537,6 +1667,9 @@ var CartDiscountRepository = class extends AbstractResourceRepository {
|
|
|
1537
1667
|
cartPredicate: draft.cartPredicate,
|
|
1538
1668
|
isActive: draft.isActive || false,
|
|
1539
1669
|
name: draft.name,
|
|
1670
|
+
stores: draft.stores?.map(
|
|
1671
|
+
(s) => getStoreKeyReference(s, context.projectKey, this._storage)
|
|
1672
|
+
) ?? [],
|
|
1540
1673
|
references: [],
|
|
1541
1674
|
target: draft.target,
|
|
1542
1675
|
requiresDiscountCode: draft.requiresDiscountCode || false,
|
|
@@ -1585,8 +1718,7 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
1585
1718
|
super(...arguments);
|
|
1586
1719
|
this.actions = {
|
|
1587
1720
|
changeAssetName: (context, resource, { assetId, assetKey, name }) => {
|
|
1588
|
-
|
|
1589
|
-
(_a = resource.assets) == null ? void 0 : _a.forEach((asset) => {
|
|
1721
|
+
resource.assets?.forEach((asset) => {
|
|
1590
1722
|
if (assetId && assetId === asset.id) {
|
|
1591
1723
|
asset.name = name;
|
|
1592
1724
|
}
|
|
@@ -1602,8 +1734,7 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
1602
1734
|
resource.key = key;
|
|
1603
1735
|
},
|
|
1604
1736
|
setAssetDescription: (context, resource, { assetId, assetKey, description }) => {
|
|
1605
|
-
|
|
1606
|
-
(_a = resource.assets) == null ? void 0 : _a.forEach((asset) => {
|
|
1737
|
+
resource.assets?.forEach((asset) => {
|
|
1607
1738
|
if (assetId && assetId === asset.id) {
|
|
1608
1739
|
asset.description = description;
|
|
1609
1740
|
}
|
|
@@ -1613,8 +1744,7 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
1613
1744
|
});
|
|
1614
1745
|
},
|
|
1615
1746
|
setAssetSources: (context, resource, { assetId, assetKey, sources }) => {
|
|
1616
|
-
|
|
1617
|
-
(_a = resource.assets) == null ? void 0 : _a.forEach((asset) => {
|
|
1747
|
+
resource.assets?.forEach((asset) => {
|
|
1618
1748
|
if (assetId && assetId === asset.id) {
|
|
1619
1749
|
asset.sources = sources;
|
|
1620
1750
|
}
|
|
@@ -1662,7 +1792,6 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
1662
1792
|
return "category";
|
|
1663
1793
|
}
|
|
1664
1794
|
create(context, draft) {
|
|
1665
|
-
var _a;
|
|
1666
1795
|
const resource = {
|
|
1667
1796
|
...getBaseResourceProperties(),
|
|
1668
1797
|
key: draft.key,
|
|
@@ -1672,7 +1801,8 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
1672
1801
|
externalId: draft.externalId || "",
|
|
1673
1802
|
parent: draft.parent ? { typeId: "category", id: draft.parent.id } : void 0,
|
|
1674
1803
|
ancestors: [],
|
|
1675
|
-
|
|
1804
|
+
// TODO
|
|
1805
|
+
assets: draft.assets?.map((d) => ({
|
|
1676
1806
|
id: (0, import_uuid4.v4)(),
|
|
1677
1807
|
name: d.name,
|
|
1678
1808
|
description: d.description,
|
|
@@ -1684,7 +1814,7 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
1684
1814
|
context.projectKey,
|
|
1685
1815
|
this._storage
|
|
1686
1816
|
)
|
|
1687
|
-
}))
|
|
1817
|
+
})) || [],
|
|
1688
1818
|
custom: createCustomFields(
|
|
1689
1819
|
draft.custom,
|
|
1690
1820
|
context.projectKey,
|
|
@@ -1864,6 +1994,7 @@ var CustomerRepository = class extends AbstractResourceRepository {
|
|
|
1864
1994
|
create(context, draft) {
|
|
1865
1995
|
const resource = {
|
|
1866
1996
|
...getBaseResourceProperties(),
|
|
1997
|
+
authenticationMode: draft.authenticationMode || "Password",
|
|
1867
1998
|
email: draft.email,
|
|
1868
1999
|
password: draft.password ? Buffer.from(draft.password).toString("base64") : void 0,
|
|
1869
2000
|
isEmailVerified: draft.isEmailVerified || false,
|
|
@@ -2081,10 +2212,9 @@ var ExtensionRepository = class extends AbstractResourceRepository {
|
|
|
2081
2212
|
return "extension";
|
|
2082
2213
|
}
|
|
2083
2214
|
postProcessResource(resource) {
|
|
2084
|
-
var _a;
|
|
2085
2215
|
if (resource) {
|
|
2086
2216
|
const extension = resource;
|
|
2087
|
-
if (extension.destination.type === "HTTP" &&
|
|
2217
|
+
if (extension.destination.type === "HTTP" && extension.destination.authentication?.type === "AuthorizationHeader") {
|
|
2088
2218
|
return maskSecretValue(
|
|
2089
2219
|
extension,
|
|
2090
2220
|
"destination.authentication.headerValue"
|
|
@@ -2142,7 +2272,7 @@ var InventoryEntryRepository = class extends AbstractResourceRepository {
|
|
|
2142
2272
|
typeId: "type",
|
|
2143
2273
|
id: resolvedType.id
|
|
2144
2274
|
},
|
|
2145
|
-
fields: fields ||
|
|
2275
|
+
fields: fields || {}
|
|
2146
2276
|
};
|
|
2147
2277
|
}
|
|
2148
2278
|
},
|
|
@@ -2155,7 +2285,6 @@ var InventoryEntryRepository = class extends AbstractResourceRepository {
|
|
|
2155
2285
|
return "inventory-entry";
|
|
2156
2286
|
}
|
|
2157
2287
|
create(context, draft) {
|
|
2158
|
-
var _a;
|
|
2159
2288
|
const resource = {
|
|
2160
2289
|
...getBaseResourceProperties(),
|
|
2161
2290
|
sku: draft.sku,
|
|
@@ -2166,7 +2295,7 @@ var InventoryEntryRepository = class extends AbstractResourceRepository {
|
|
|
2166
2295
|
supplyChannel: {
|
|
2167
2296
|
...draft.supplyChannel,
|
|
2168
2297
|
typeId: "channel",
|
|
2169
|
-
id:
|
|
2298
|
+
id: draft.supplyChannel?.id ?? ""
|
|
2170
2299
|
},
|
|
2171
2300
|
custom: createCustomFields(
|
|
2172
2301
|
draft.custom,
|
|
@@ -2225,7 +2354,11 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2225
2354
|
resource.state = { typeId: "state", id: resolvedType.id };
|
|
2226
2355
|
},
|
|
2227
2356
|
setBillingAddress: (context, resource, { address }) => {
|
|
2228
|
-
resource.billingAddress =
|
|
2357
|
+
resource.billingAddress = createAddress(
|
|
2358
|
+
address,
|
|
2359
|
+
context.projectKey,
|
|
2360
|
+
this._storage
|
|
2361
|
+
);
|
|
2229
2362
|
},
|
|
2230
2363
|
setCustomerEmail: (context, resource, { email }) => {
|
|
2231
2364
|
resource.customerEmail = email;
|
|
@@ -2252,7 +2385,7 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2252
2385
|
typeId: "type",
|
|
2253
2386
|
id: resolvedType.id
|
|
2254
2387
|
},
|
|
2255
|
-
fields: fields ||
|
|
2388
|
+
fields: fields || {}
|
|
2256
2389
|
};
|
|
2257
2390
|
}
|
|
2258
2391
|
},
|
|
@@ -2263,7 +2396,11 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2263
2396
|
resource.orderNumber = orderNumber;
|
|
2264
2397
|
},
|
|
2265
2398
|
setShippingAddress: (context, resource, { address }) => {
|
|
2266
|
-
resource.shippingAddress =
|
|
2399
|
+
resource.shippingAddress = createAddress(
|
|
2400
|
+
address,
|
|
2401
|
+
context.projectKey,
|
|
2402
|
+
this._storage
|
|
2403
|
+
);
|
|
2267
2404
|
},
|
|
2268
2405
|
setStore: (context, resource, { store }) => {
|
|
2269
2406
|
if (!store)
|
|
@@ -2328,12 +2465,19 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2328
2465
|
return resource;
|
|
2329
2466
|
}
|
|
2330
2467
|
import(context, draft) {
|
|
2331
|
-
var _a, _b;
|
|
2332
2468
|
(0, import_assert2.default)(this, "OrderRepository not valid");
|
|
2333
2469
|
const resource = {
|
|
2334
2470
|
...getBaseResourceProperties(),
|
|
2335
|
-
billingAddress:
|
|
2336
|
-
|
|
2471
|
+
billingAddress: createAddress(
|
|
2472
|
+
draft.billingAddress,
|
|
2473
|
+
context.projectKey,
|
|
2474
|
+
this._storage
|
|
2475
|
+
),
|
|
2476
|
+
shippingAddress: createAddress(
|
|
2477
|
+
draft.shippingAddress,
|
|
2478
|
+
context.projectKey,
|
|
2479
|
+
this._storage
|
|
2480
|
+
),
|
|
2337
2481
|
custom: createCustomFields(
|
|
2338
2482
|
draft.custom,
|
|
2339
2483
|
context.projectKey,
|
|
@@ -2354,17 +2498,13 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2354
2498
|
this._storage
|
|
2355
2499
|
),
|
|
2356
2500
|
syncInfo: [],
|
|
2357
|
-
lineItems:
|
|
2501
|
+
lineItems: draft.lineItems?.map(
|
|
2358
2502
|
(item) => this.lineItemFromImportDraft.bind(this)(context, item)
|
|
2359
|
-
)
|
|
2360
|
-
customLineItems:
|
|
2503
|
+
) || [],
|
|
2504
|
+
customLineItems: draft.customLineItems?.map(
|
|
2361
2505
|
(item) => this.customLineItemFromImportDraft.bind(this)(context, item)
|
|
2362
|
-
)
|
|
2363
|
-
totalPrice:
|
|
2364
|
-
type: "centPrecision",
|
|
2365
|
-
...draft.totalPrice,
|
|
2366
|
-
fractionDigits: 2
|
|
2367
|
-
}
|
|
2506
|
+
) || [],
|
|
2507
|
+
totalPrice: createCentPrecisionMoney(draft.totalPrice)
|
|
2368
2508
|
};
|
|
2369
2509
|
this.saveNew(context, resource);
|
|
2370
2510
|
return resource;
|
|
@@ -2421,7 +2561,7 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2421
2561
|
taxRate: draft.taxRate,
|
|
2422
2562
|
taxedPricePortions: [],
|
|
2423
2563
|
perMethodTaxRate: [],
|
|
2424
|
-
totalPrice:
|
|
2564
|
+
totalPrice: createCentPrecisionMoney(draft.price.value),
|
|
2425
2565
|
variant: {
|
|
2426
2566
|
id: variant.id,
|
|
2427
2567
|
sku: variant.sku,
|
|
@@ -2441,11 +2581,12 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2441
2581
|
discountedPricePerQuantity: [],
|
|
2442
2582
|
money: createTypedMoney(draft.money),
|
|
2443
2583
|
name: draft.name,
|
|
2444
|
-
quantity: draft.quantity,
|
|
2584
|
+
quantity: draft.quantity ?? 0,
|
|
2585
|
+
perMethodTaxRate: [],
|
|
2445
2586
|
priceMode: draft.priceMode,
|
|
2446
2587
|
slug: draft.slug,
|
|
2447
2588
|
state: [],
|
|
2448
|
-
totalPrice:
|
|
2589
|
+
totalPrice: createCentPrecisionMoney(draft.money)
|
|
2449
2590
|
};
|
|
2450
2591
|
return lineItem;
|
|
2451
2592
|
}
|
|
@@ -2507,8 +2648,10 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
2507
2648
|
this.transactionFromTransactionDraft = (draft, context) => ({
|
|
2508
2649
|
...draft,
|
|
2509
2650
|
id: (0, import_uuid5.v4)(),
|
|
2510
|
-
amount:
|
|
2511
|
-
custom: createCustomFields(draft.custom, context.projectKey, this._storage)
|
|
2651
|
+
amount: createCentPrecisionMoney(draft.amount),
|
|
2652
|
+
custom: createCustomFields(draft.custom, context.projectKey, this._storage),
|
|
2653
|
+
state: draft.state ?? "Initial"
|
|
2654
|
+
// Documented as default
|
|
2512
2655
|
});
|
|
2513
2656
|
this.actions = {
|
|
2514
2657
|
setCustomField: (context, resource, { name, value }) => {
|
|
@@ -2533,7 +2676,7 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
2533
2676
|
typeId: "type",
|
|
2534
2677
|
id: resolvedType.id
|
|
2535
2678
|
},
|
|
2536
|
-
fields: fields
|
|
2679
|
+
fields: fields ?? {}
|
|
2537
2680
|
};
|
|
2538
2681
|
}
|
|
2539
2682
|
},
|
|
@@ -2567,6 +2710,23 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
2567
2710
|
obj: stateObj
|
|
2568
2711
|
};
|
|
2569
2712
|
}
|
|
2713
|
+
// addInterfaceInteraction: () => {},
|
|
2714
|
+
// changeAmountPlanned: () => {},
|
|
2715
|
+
// changeTransactionInteractionId: () => {},
|
|
2716
|
+
// changeTransactionTimestamp: () => {},
|
|
2717
|
+
// setAmountPaid: () => {},
|
|
2718
|
+
// setAmountRefunded: () => {},
|
|
2719
|
+
// setAnonymousId: () => {},
|
|
2720
|
+
// setAuthorization: () => {},
|
|
2721
|
+
// setCustomer: () => {},
|
|
2722
|
+
// setExternalId: () => {},
|
|
2723
|
+
// setInterfaceId: () => {},
|
|
2724
|
+
// setKey: () => {},
|
|
2725
|
+
// setMethodInfoInterface: () => {},
|
|
2726
|
+
// setMethodInfoMethod: () => {},
|
|
2727
|
+
// setMethodInfoName: () => {},
|
|
2728
|
+
// setStatusInterfaceCode: () => {},
|
|
2729
|
+
// setStatusInterfaceText: () => {},
|
|
2570
2730
|
};
|
|
2571
2731
|
}
|
|
2572
2732
|
getTypeId() {
|
|
@@ -2575,7 +2735,7 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
2575
2735
|
create(context, draft) {
|
|
2576
2736
|
const resource = {
|
|
2577
2737
|
...getBaseResourceProperties(),
|
|
2578
|
-
amountPlanned:
|
|
2738
|
+
amountPlanned: createCentPrecisionMoney(draft.amountPlanned),
|
|
2579
2739
|
paymentMethodInfo: draft.paymentMethodInfo,
|
|
2580
2740
|
paymentStatus: draft.paymentStatus ? {
|
|
2581
2741
|
...draft.paymentStatus,
|
|
@@ -2821,13 +2981,9 @@ var ProductRepository = class extends AbstractResourceRepository {
|
|
|
2821
2981
|
},
|
|
2822
2982
|
changePrice: (context, resource, { priceId, price, staged }) => {
|
|
2823
2983
|
const changeVariantPrice = (data) => {
|
|
2824
|
-
var _a;
|
|
2825
2984
|
const allVariants = [data.masterVariant, ...data.variants ?? []];
|
|
2826
2985
|
const priceVariant = allVariants.find(
|
|
2827
|
-
(variant2) =>
|
|
2828
|
-
var _a2;
|
|
2829
|
-
return (_a2 = variant2.prices) == null ? void 0 : _a2.some((x) => x.id === priceId);
|
|
2830
|
-
}
|
|
2986
|
+
(variant2) => variant2.prices?.some((x) => x.id === priceId)
|
|
2831
2987
|
);
|
|
2832
2988
|
if (!priceVariant) {
|
|
2833
2989
|
throw new Error(
|
|
@@ -2844,7 +3000,7 @@ var ProductRepository = class extends AbstractResourceRepository {
|
|
|
2844
3000
|
`Variant with id ${priceVariant.id} or sku ${priceVariant.sku} not found on product ${resource.id}`
|
|
2845
3001
|
);
|
|
2846
3002
|
}
|
|
2847
|
-
variant.prices =
|
|
3003
|
+
variant.prices = variant.prices?.map((x) => {
|
|
2848
3004
|
if (x.id === priceId) {
|
|
2849
3005
|
return { ...x, ...price };
|
|
2850
3006
|
}
|
|
@@ -2866,13 +3022,9 @@ var ProductRepository = class extends AbstractResourceRepository {
|
|
|
2866
3022
|
},
|
|
2867
3023
|
removePrice: (context, resource, { priceId, staged }) => {
|
|
2868
3024
|
const removeVariantPrice = (data) => {
|
|
2869
|
-
var _a;
|
|
2870
3025
|
const allVariants = [data.masterVariant, ...data.variants ?? []];
|
|
2871
3026
|
const priceVariant = allVariants.find(
|
|
2872
|
-
(variant2) =>
|
|
2873
|
-
var _a2;
|
|
2874
|
-
return (_a2 = variant2.prices) == null ? void 0 : _a2.some((x) => x.id === priceId);
|
|
2875
|
-
}
|
|
3027
|
+
(variant2) => variant2.prices?.some((x) => x.id === priceId)
|
|
2876
3028
|
);
|
|
2877
3029
|
if (!priceVariant) {
|
|
2878
3030
|
throw new Error(
|
|
@@ -2889,7 +3041,7 @@ var ProductRepository = class extends AbstractResourceRepository {
|
|
|
2889
3041
|
`Variant with id ${priceVariant.id} or sku ${priceVariant.sku} not found on product ${resource.id}`
|
|
2890
3042
|
);
|
|
2891
3043
|
}
|
|
2892
|
-
variant.prices =
|
|
3044
|
+
variant.prices = variant.prices?.filter((x) => x.id !== priceId);
|
|
2893
3045
|
if (isMasterVariant) {
|
|
2894
3046
|
data.masterVariant = variant;
|
|
2895
3047
|
} else {
|
|
@@ -2904,13 +3056,46 @@ var ProductRepository = class extends AbstractResourceRepository {
|
|
|
2904
3056
|
checkForStagedChanges(resource);
|
|
2905
3057
|
return resource;
|
|
2906
3058
|
}
|
|
3059
|
+
// 'changeName': () => {},
|
|
3060
|
+
// 'changeSlug': () => {},
|
|
3061
|
+
// 'addVariant': () => {},
|
|
3062
|
+
// 'removeVariant': () => {},
|
|
3063
|
+
// 'changeMasterVariant': () => {},
|
|
3064
|
+
// 'setPrices': () => {},
|
|
3065
|
+
// 'setProductPriceCustomType': () => {},
|
|
3066
|
+
// 'setProductPriceCustomField': () => {},
|
|
3067
|
+
// 'setDiscountedPrice': () => {},
|
|
3068
|
+
// 'setAttributeInAllVariants': () => {},
|
|
3069
|
+
// 'addToCategory': () => {},
|
|
3070
|
+
// 'setCategoryOrderHint': () => {},
|
|
3071
|
+
// 'removeFromCategory': () => {},
|
|
3072
|
+
// 'setTaxCategory': () => {},
|
|
3073
|
+
// 'setSku': () => {},
|
|
3074
|
+
// 'setProductVariantKey': () => {},
|
|
3075
|
+
// 'setImageLabel': () => {},
|
|
3076
|
+
// 'addAsset': () => {},
|
|
3077
|
+
// 'removeAsset': () => {},
|
|
3078
|
+
// 'setAssetKey': () => {},
|
|
3079
|
+
// 'changeAssetOrder': () => {},
|
|
3080
|
+
// 'changeAssetName': () => {},
|
|
3081
|
+
// 'setAssetDescription': () => {},
|
|
3082
|
+
// 'setAssetTags': () => {},
|
|
3083
|
+
// 'setAssetSources': () => {},
|
|
3084
|
+
// 'setAssetCustomType': () => {},
|
|
3085
|
+
// 'setAssetCustomField': () => {},
|
|
3086
|
+
// 'setSearchKeywords': () => {},
|
|
3087
|
+
// 'setMetaTitle': () => {},
|
|
3088
|
+
// 'setMetaDescription': () => {},
|
|
3089
|
+
// 'setMetaKeywords': () => {},
|
|
3090
|
+
// 'revertStagedChanges': () => {},
|
|
3091
|
+
// 'revertStagedVariantChanges': () => {},
|
|
3092
|
+
// 'transitionState': () => {},
|
|
2907
3093
|
};
|
|
2908
3094
|
}
|
|
2909
3095
|
getTypeId() {
|
|
2910
3096
|
return "product";
|
|
2911
3097
|
}
|
|
2912
3098
|
create(context, draft) {
|
|
2913
|
-
var _a;
|
|
2914
3099
|
if (!draft.masterVariant) {
|
|
2915
3100
|
throw new Error("Missing master variant");
|
|
2916
3101
|
}
|
|
@@ -2935,9 +3120,9 @@ var ProductRepository = class extends AbstractResourceRepository {
|
|
|
2935
3120
|
slug: draft.slug,
|
|
2936
3121
|
categories: [],
|
|
2937
3122
|
masterVariant: variantFromDraft(1, draft.masterVariant),
|
|
2938
|
-
variants:
|
|
3123
|
+
variants: draft.variants?.map(
|
|
2939
3124
|
(variant, index) => variantFromDraft(index + 2, variant)
|
|
2940
|
-
)
|
|
3125
|
+
) ?? [],
|
|
2941
3126
|
searchKeywords: draft.searchKeywords ?? {}
|
|
2942
3127
|
};
|
|
2943
3128
|
const resource = {
|
|
@@ -2983,26 +3168,18 @@ var getVariant = (productData, variantId, sku) => {
|
|
|
2983
3168
|
variantIndex: !isMasterVariant && foundVariant ? productData.variants.indexOf(foundVariant) : -1
|
|
2984
3169
|
};
|
|
2985
3170
|
};
|
|
2986
|
-
var variantFromDraft = (variantId, variant) => {
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
images: []
|
|
2995
|
-
};
|
|
2996
|
-
};
|
|
3171
|
+
var variantFromDraft = (variantId, variant) => ({
|
|
3172
|
+
id: variantId,
|
|
3173
|
+
sku: variant?.sku,
|
|
3174
|
+
attributes: variant?.attributes ?? [],
|
|
3175
|
+
prices: variant?.prices?.map(priceFromDraft),
|
|
3176
|
+
assets: [],
|
|
3177
|
+
images: []
|
|
3178
|
+
});
|
|
2997
3179
|
var priceFromDraft = (draft) => ({
|
|
2998
3180
|
id: (0, import_uuid6.v4)(),
|
|
2999
3181
|
country: draft.country,
|
|
3000
|
-
value:
|
|
3001
|
-
currencyCode: draft.value.currencyCode,
|
|
3002
|
-
centAmount: draft.value.centAmount,
|
|
3003
|
-
fractionDigits: 2,
|
|
3004
|
-
type: "centPrecision"
|
|
3005
|
-
}
|
|
3182
|
+
value: createTypedMoney(draft.value)
|
|
3006
3183
|
});
|
|
3007
3184
|
|
|
3008
3185
|
// src/repositories/product-discount.ts
|
|
@@ -3136,6 +3313,7 @@ var parseFilter = (filter) => {
|
|
|
3136
3313
|
(t) => ({
|
|
3137
3314
|
type: "Symbol",
|
|
3138
3315
|
kind: "string",
|
|
3316
|
+
// @ts-ignore
|
|
3139
3317
|
value: t.token.groups[1]
|
|
3140
3318
|
})
|
|
3141
3319
|
).nud(
|
|
@@ -3280,7 +3458,6 @@ var getVariants = (p) => [
|
|
|
3280
3458
|
|
|
3281
3459
|
// src/priceSelector.ts
|
|
3282
3460
|
var applyPriceSelector = (products, selector) => {
|
|
3283
|
-
var _a;
|
|
3284
3461
|
validatePriceSelector(selector);
|
|
3285
3462
|
for (const product of products) {
|
|
3286
3463
|
const variants = [
|
|
@@ -3288,7 +3465,7 @@ var applyPriceSelector = (products, selector) => {
|
|
|
3288
3465
|
...product.variants ?? []
|
|
3289
3466
|
].filter((x) => x != void 0);
|
|
3290
3467
|
for (const variant of variants) {
|
|
3291
|
-
const scopedPrices =
|
|
3468
|
+
const scopedPrices = variant.prices?.filter((p) => priceSelectorFilter(p, selector)) ?? [];
|
|
3292
3469
|
if (scopedPrices.length > 0) {
|
|
3293
3470
|
const price = scopedPrices[0];
|
|
3294
3471
|
variant.scopedPriceDiscounted = false;
|
|
@@ -3312,17 +3489,16 @@ var validatePriceSelector = (selector) => {
|
|
|
3312
3489
|
}
|
|
3313
3490
|
};
|
|
3314
3491
|
var priceSelectorFilter = (price, selector) => {
|
|
3315
|
-
var _a, _b, _c, _d;
|
|
3316
3492
|
if ((selector.country || price.country) && selector.country !== price.country) {
|
|
3317
3493
|
return false;
|
|
3318
3494
|
}
|
|
3319
3495
|
if ((selector.currency || price.value.currencyCode) && selector.currency !== price.value.currencyCode) {
|
|
3320
3496
|
return false;
|
|
3321
3497
|
}
|
|
3322
|
-
if ((selector.channel ||
|
|
3498
|
+
if ((selector.channel || price.channel?.id) && selector.channel !== price.channel?.id) {
|
|
3323
3499
|
return false;
|
|
3324
3500
|
}
|
|
3325
|
-
if ((selector.customerGroup ||
|
|
3501
|
+
if ((selector.customerGroup || price.customerGroup?.id) && selector.customerGroup !== price.customerGroup?.id) {
|
|
3326
3502
|
return false;
|
|
3327
3503
|
}
|
|
3328
3504
|
return true;
|
|
@@ -3446,6 +3622,11 @@ var ProductProjectionSearch = class {
|
|
|
3446
3622
|
}
|
|
3447
3623
|
return result;
|
|
3448
3624
|
}
|
|
3625
|
+
/**
|
|
3626
|
+
* TODO: This implemention needs the following additional features:
|
|
3627
|
+
* - counting products
|
|
3628
|
+
* - correct dataType
|
|
3629
|
+
*/
|
|
3449
3630
|
termFacet(facet, products) {
|
|
3450
3631
|
const result = {
|
|
3451
3632
|
type: "terms",
|
|
@@ -3497,7 +3678,7 @@ var ProductProjectionSearch = class {
|
|
|
3497
3678
|
for (const p of products) {
|
|
3498
3679
|
for (const v of getVariants(p)) {
|
|
3499
3680
|
const val = resolveVariantValue(v, source);
|
|
3500
|
-
if (filters
|
|
3681
|
+
if (filters?.some((f) => f.match(val))) {
|
|
3501
3682
|
count++;
|
|
3502
3683
|
}
|
|
3503
3684
|
}
|
|
@@ -3511,7 +3692,7 @@ var ProductProjectionSearch = class {
|
|
|
3511
3692
|
};
|
|
3512
3693
|
}
|
|
3513
3694
|
rangeFacet(source, ranges, products) {
|
|
3514
|
-
const counts =
|
|
3695
|
+
const counts = ranges?.map((range) => {
|
|
3515
3696
|
if (source.startsWith("variants.")) {
|
|
3516
3697
|
const values = [];
|
|
3517
3698
|
for (const p of products) {
|
|
@@ -3533,6 +3714,7 @@ var ProductProjectionSearch = class {
|
|
|
3533
3714
|
to: range.stop || 0,
|
|
3534
3715
|
toStr: range.stop !== null ? Number(range.stop).toFixed(1) : "",
|
|
3535
3716
|
count: numValues,
|
|
3717
|
+
// totalCount: 0,
|
|
3536
3718
|
total: values.reduce((a, b) => a + b, 0),
|
|
3537
3719
|
min: numValues > 0 ? Math.min(...values) : 0,
|
|
3538
3720
|
max: numValues > 0 ? Math.max(...values) : 0,
|
|
@@ -3541,9 +3723,10 @@ var ProductProjectionSearch = class {
|
|
|
3541
3723
|
} else {
|
|
3542
3724
|
throw new Error("not supported");
|
|
3543
3725
|
}
|
|
3544
|
-
})
|
|
3726
|
+
}) || [];
|
|
3545
3727
|
const data = {
|
|
3546
3728
|
type: "range",
|
|
3729
|
+
// @ts-ignore
|
|
3547
3730
|
dataType: "number",
|
|
3548
3731
|
ranges: counts
|
|
3549
3732
|
};
|
|
@@ -3613,7 +3796,8 @@ var ProductSelectionRepository = class extends AbstractResourceRepository {
|
|
|
3613
3796
|
...getBaseResourceProperties(),
|
|
3614
3797
|
productCount: 0,
|
|
3615
3798
|
name: draft.name,
|
|
3616
|
-
type: "individual"
|
|
3799
|
+
type: "individual",
|
|
3800
|
+
mode: "Individual"
|
|
3617
3801
|
};
|
|
3618
3802
|
this.saveNew(context, resource);
|
|
3619
3803
|
return resource;
|
|
@@ -3636,7 +3820,6 @@ var ProductTypeRepository = class extends AbstractResourceRepository {
|
|
|
3636
3820
|
attributeName,
|
|
3637
3821
|
newValue
|
|
3638
3822
|
}) => {
|
|
3639
|
-
var _a;
|
|
3640
3823
|
const updateAttributeType = (type) => {
|
|
3641
3824
|
switch (type.name) {
|
|
3642
3825
|
case "lenum":
|
|
@@ -3651,30 +3834,27 @@ var ProductTypeRepository = class extends AbstractResourceRepository {
|
|
|
3651
3834
|
return;
|
|
3652
3835
|
}
|
|
3653
3836
|
};
|
|
3654
|
-
|
|
3837
|
+
resource.attributes?.forEach((value) => {
|
|
3655
3838
|
if (value.name === attributeName) {
|
|
3656
3839
|
updateAttributeType(value.type);
|
|
3657
3840
|
}
|
|
3658
3841
|
});
|
|
3659
3842
|
},
|
|
3660
3843
|
changeLabel: (context, resource, { attributeName, label }) => {
|
|
3661
|
-
|
|
3662
|
-
(_a = resource.attributes) == null ? void 0 : _a.forEach((value) => {
|
|
3844
|
+
resource.attributes?.forEach((value) => {
|
|
3663
3845
|
if (value.name === attributeName) {
|
|
3664
3846
|
value.label = label;
|
|
3665
3847
|
}
|
|
3666
3848
|
});
|
|
3667
3849
|
},
|
|
3668
3850
|
addAttributeDefinition: (context, resource, { attribute }) => {
|
|
3669
|
-
|
|
3670
|
-
(_a = resource.attributes) == null ? void 0 : _a.push(
|
|
3851
|
+
resource.attributes?.push(
|
|
3671
3852
|
this.attributeDefinitionFromAttributeDefinitionDraft(context, attribute)
|
|
3672
3853
|
);
|
|
3673
3854
|
},
|
|
3674
3855
|
changeAttributeOrderByName: (context, resource, { attributeNames }) => {
|
|
3675
|
-
var _a;
|
|
3676
3856
|
const attrs = new Map(
|
|
3677
|
-
|
|
3857
|
+
resource.attributes?.map((item) => [item.name, item])
|
|
3678
3858
|
);
|
|
3679
3859
|
const result = [];
|
|
3680
3860
|
let current = resource.attributes;
|
|
@@ -3684,7 +3864,7 @@ var ProductTypeRepository = class extends AbstractResourceRepository {
|
|
|
3684
3864
|
throw new Error("New attr");
|
|
3685
3865
|
}
|
|
3686
3866
|
result.push(attr);
|
|
3687
|
-
current = current
|
|
3867
|
+
current = current?.filter((f) => f.name !== attrName);
|
|
3688
3868
|
});
|
|
3689
3869
|
resource.attributes = result;
|
|
3690
3870
|
if (current) {
|
|
@@ -3692,12 +3872,10 @@ var ProductTypeRepository = class extends AbstractResourceRepository {
|
|
|
3692
3872
|
}
|
|
3693
3873
|
},
|
|
3694
3874
|
removeAttributeDefinition: (context, resource, { name }) => {
|
|
3695
|
-
|
|
3696
|
-
resource.attributes = (_a = resource.attributes) == null ? void 0 : _a.filter((f) => f.name !== name);
|
|
3875
|
+
resource.attributes = resource.attributes?.filter((f) => f.name !== name);
|
|
3697
3876
|
},
|
|
3698
3877
|
removeEnumValues: (context, resource, { attributeName, keys }) => {
|
|
3699
|
-
|
|
3700
|
-
(_a = resource.attributes) == null ? void 0 : _a.forEach((attr) => {
|
|
3878
|
+
resource.attributes?.forEach((attr) => {
|
|
3701
3879
|
if (attr.name == attributeName) {
|
|
3702
3880
|
if (attr.type.name == "enum") {
|
|
3703
3881
|
attr.type.values = attr.type.values.filter(
|
|
@@ -3756,20 +3934,18 @@ var ProjectRepository = class extends AbstractRepository {
|
|
|
3756
3934
|
resource.messages.deleteDaysAfterCreation = messagesConfiguration.deleteDaysAfterCreation;
|
|
3757
3935
|
},
|
|
3758
3936
|
changeProductSearchIndexingEnabled: (context, resource, { enabled }) => {
|
|
3759
|
-
|
|
3760
|
-
if (!((_a = resource.searchIndexing) == null ? void 0 : _a.products)) {
|
|
3937
|
+
if (!resource.searchIndexing?.products) {
|
|
3761
3938
|
throw new Error("Invalid project state");
|
|
3762
3939
|
}
|
|
3763
3940
|
resource.searchIndexing.products.status = enabled ? "Activated" : "Deactivated";
|
|
3764
|
-
resource.searchIndexing.products.lastModifiedAt = new Date().toISOString();
|
|
3941
|
+
resource.searchIndexing.products.lastModifiedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
3765
3942
|
},
|
|
3766
3943
|
changeOrderSearchStatus: (context, resource, { status }) => {
|
|
3767
|
-
|
|
3768
|
-
if (!((_a = resource.searchIndexing) == null ? void 0 : _a.orders)) {
|
|
3944
|
+
if (!resource.searchIndexing?.orders) {
|
|
3769
3945
|
throw new Error("Invalid project state");
|
|
3770
3946
|
}
|
|
3771
3947
|
resource.searchIndexing.orders.status = status;
|
|
3772
|
-
resource.searchIndexing.orders.lastModifiedAt = new Date().toISOString();
|
|
3948
|
+
resource.searchIndexing.orders.lastModifiedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
3773
3949
|
},
|
|
3774
3950
|
setShippingRateInputType: (context, resource, { shippingRateInputType }) => {
|
|
3775
3951
|
resource.shippingRateInputType = shippingRateInputType;
|
|
@@ -3861,18 +4037,15 @@ var import_deep_equal3 = __toESM(require("deep-equal"));
|
|
|
3861
4037
|
var ShippingMethodRepository = class extends AbstractResourceRepository {
|
|
3862
4038
|
constructor() {
|
|
3863
4039
|
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
|
-
};
|
|
4040
|
+
this._transformZoneRateDraft = (context, draft) => ({
|
|
4041
|
+
...draft,
|
|
4042
|
+
zone: getReferenceFromResourceIdentifier(
|
|
4043
|
+
draft.zone,
|
|
4044
|
+
context.projectKey,
|
|
4045
|
+
this._storage
|
|
4046
|
+
),
|
|
4047
|
+
shippingRates: draft.shippingRates?.map(this._transformShippingRate)
|
|
4048
|
+
});
|
|
3876
4049
|
this._transformShippingRate = (rate) => ({
|
|
3877
4050
|
price: createTypedMoney(rate.price),
|
|
3878
4051
|
freeAbove: rate.freeAbove && createTypedMoney(rate.freeAbove),
|
|
@@ -3972,7 +4145,6 @@ var ShippingMethodRepository = class extends AbstractResourceRepository {
|
|
|
3972
4145
|
return "shipping-method";
|
|
3973
4146
|
}
|
|
3974
4147
|
create(context, draft) {
|
|
3975
|
-
var _a;
|
|
3976
4148
|
const resource = {
|
|
3977
4149
|
...getBaseResourceProperties(),
|
|
3978
4150
|
...draft,
|
|
@@ -3981,7 +4153,7 @@ var ShippingMethodRepository = class extends AbstractResourceRepository {
|
|
|
3981
4153
|
context.projectKey,
|
|
3982
4154
|
this._storage
|
|
3983
4155
|
),
|
|
3984
|
-
zoneRates:
|
|
4156
|
+
zoneRates: draft.zoneRates?.map(
|
|
3985
4157
|
(z) => this._transformZoneRateDraft(context, z)
|
|
3986
4158
|
),
|
|
3987
4159
|
custom: createCustomFields(
|
|
@@ -4001,7 +4173,6 @@ var ShoppingListRepository = class extends AbstractResourceRepository {
|
|
|
4001
4173
|
return "shopping-list";
|
|
4002
4174
|
}
|
|
4003
4175
|
create(context, draft) {
|
|
4004
|
-
var _a, _b;
|
|
4005
4176
|
const resource = {
|
|
4006
4177
|
...getBaseResourceProperties(),
|
|
4007
4178
|
...draft,
|
|
@@ -4011,7 +4182,7 @@ var ShoppingListRepository = class extends AbstractResourceRepository {
|
|
|
4011
4182
|
this._storage
|
|
4012
4183
|
),
|
|
4013
4184
|
textLineItems: [],
|
|
4014
|
-
lineItems:
|
|
4185
|
+
lineItems: draft.lineItems?.map((e) => ({
|
|
4015
4186
|
...getBaseResourceProperties(),
|
|
4016
4187
|
...e,
|
|
4017
4188
|
addedAt: e.addedAt ?? "",
|
|
@@ -4019,14 +4190,18 @@ var ShoppingListRepository = class extends AbstractResourceRepository {
|
|
|
4019
4190
|
name: {},
|
|
4020
4191
|
quantity: e.quantity ?? 1,
|
|
4021
4192
|
productType: { typeId: "product-type", id: "" },
|
|
4022
|
-
custom: createCustomFields(
|
|
4023
|
-
|
|
4193
|
+
custom: createCustomFields(
|
|
4194
|
+
e.custom,
|
|
4195
|
+
context.projectKey,
|
|
4196
|
+
this._storage
|
|
4197
|
+
)
|
|
4198
|
+
})) ?? [],
|
|
4024
4199
|
customer: draft.customer ? getReferenceFromResourceIdentifier(
|
|
4025
4200
|
draft.customer,
|
|
4026
4201
|
context.projectKey,
|
|
4027
4202
|
this._storage
|
|
4028
4203
|
) : void 0,
|
|
4029
|
-
store:
|
|
4204
|
+
store: draft.store ? getStoreKeyReference(draft.store, context.projectKey, this._storage) : void 0
|
|
4030
4205
|
};
|
|
4031
4206
|
this.saveNew(context, resource);
|
|
4032
4207
|
return resource;
|
|
@@ -4067,7 +4242,6 @@ var StandAlonePriceRepository = class extends AbstractResourceRepository {
|
|
|
4067
4242
|
return "standalone-price";
|
|
4068
4243
|
}
|
|
4069
4244
|
create(context, draft) {
|
|
4070
|
-
var _a;
|
|
4071
4245
|
const resource = {
|
|
4072
4246
|
...getBaseResourceProperties(),
|
|
4073
4247
|
active: draft.active ? draft.active : false,
|
|
@@ -4075,7 +4249,7 @@ var StandAlonePriceRepository = class extends AbstractResourceRepository {
|
|
|
4075
4249
|
value: createTypedMoney(draft.value),
|
|
4076
4250
|
country: draft.country,
|
|
4077
4251
|
discounted: draft.discounted ? this.transformDiscountDraft(draft.discounted) : void 0,
|
|
4078
|
-
channel:
|
|
4252
|
+
channel: draft.channel?.id ? this.transformChannelReferenceDraft(draft.channel) : void 0,
|
|
4079
4253
|
validFrom: draft.validFrom,
|
|
4080
4254
|
validUntil: draft.validUntil
|
|
4081
4255
|
};
|
|
@@ -4117,7 +4291,7 @@ var StateRepository = class extends AbstractResourceRepository {
|
|
|
4117
4291
|
resource.roles = roles;
|
|
4118
4292
|
},
|
|
4119
4293
|
setTransitions: (context, resource, { transitions }) => {
|
|
4120
|
-
resource.transitions = transitions
|
|
4294
|
+
resource.transitions = transitions?.map(
|
|
4121
4295
|
(resourceId) => ({
|
|
4122
4296
|
id: resourceId.id || "",
|
|
4123
4297
|
typeId: "state"
|
|
@@ -4193,6 +4367,7 @@ var StoreRepository = class extends AbstractResourceRepository {
|
|
|
4193
4367
|
key: draft.key,
|
|
4194
4368
|
name: draft.name,
|
|
4195
4369
|
languages: draft.languages ?? [],
|
|
4370
|
+
countries: draft.countries ?? [],
|
|
4196
4371
|
distributionChannels: this.transformChannels(
|
|
4197
4372
|
context,
|
|
4198
4373
|
draft.distributionChannels
|
|
@@ -4309,11 +4484,10 @@ var TaxCategoryRepository = class extends AbstractResourceRepository {
|
|
|
4309
4484
|
return "tax-category";
|
|
4310
4485
|
}
|
|
4311
4486
|
create(context, draft) {
|
|
4312
|
-
var _a;
|
|
4313
4487
|
const resource = {
|
|
4314
4488
|
...getBaseResourceProperties(),
|
|
4315
4489
|
...draft,
|
|
4316
|
-
rates:
|
|
4490
|
+
rates: draft.rates?.map(this.taxRateFromTaxRateDraft) || []
|
|
4317
4491
|
};
|
|
4318
4492
|
this.saveNew(context, resource);
|
|
4319
4493
|
return resource;
|
|
@@ -4465,6 +4639,9 @@ var ZoneRepository = class extends AbstractResourceRepository {
|
|
|
4465
4639
|
|
|
4466
4640
|
// src/repositories/index.ts
|
|
4467
4641
|
var createRepositories = (storage) => ({
|
|
4642
|
+
"associate-role": new AssociateRoleRepository(storage),
|
|
4643
|
+
"attribute-group": new AttributeGroupRepository(storage),
|
|
4644
|
+
"business-unit": new BusinessUnitRepository(storage),
|
|
4468
4645
|
category: new CategoryRepository(storage),
|
|
4469
4646
|
cart: new CartRepository(storage),
|
|
4470
4647
|
"cart-discount": new CartDiscountRepository(storage),
|
|
@@ -4642,6 +4819,7 @@ var AbstractService = class {
|
|
|
4642
4819
|
);
|
|
4643
4820
|
return result;
|
|
4644
4821
|
}
|
|
4822
|
+
// No idea what i'm doing
|
|
4645
4823
|
_parseParam(value) {
|
|
4646
4824
|
if (Array.isArray(value)) {
|
|
4647
4825
|
return value;
|
|
@@ -4676,6 +4854,7 @@ var CartService = class extends AbstractService {
|
|
|
4676
4854
|
currency: cartOrOrder.totalPrice.currencyCode,
|
|
4677
4855
|
discountCodes: [],
|
|
4678
4856
|
shipping: [],
|
|
4857
|
+
// TODO: cartOrOrder.shipping,
|
|
4679
4858
|
lineItems: cartOrOrder.lineItems.map((lineItem) => ({
|
|
4680
4859
|
...lineItem,
|
|
4681
4860
|
variantId: lineItem.variant.id,
|
|
@@ -4786,7 +4965,10 @@ var CustomerService = class extends AbstractService {
|
|
|
4786
4965
|
const customer = this.repository.query(getRepositoryContext(request), {
|
|
4787
4966
|
where: [`email="${request.body.email}"`]
|
|
4788
4967
|
});
|
|
4789
|
-
const ttlMinutes = request.params.ttlMinutes ?
|
|
4968
|
+
const ttlMinutes = request.params.ttlMinutes ? (
|
|
4969
|
+
// @ts-ignore
|
|
4970
|
+
+request.params.ttlMinutes
|
|
4971
|
+
) : 34560;
|
|
4790
4972
|
const { version, ...rest } = getBaseResourceProperties();
|
|
4791
4973
|
return response.status(200).send({
|
|
4792
4974
|
...rest,
|
|
@@ -5241,10 +5423,9 @@ var CommercetoolsMock = class {
|
|
|
5241
5423
|
this.mockApiHost();
|
|
5242
5424
|
}
|
|
5243
5425
|
stop() {
|
|
5244
|
-
|
|
5245
|
-
(_a = this._nockScopes.auth) == null ? void 0 : _a.persist(false);
|
|
5426
|
+
this._nockScopes.auth?.persist(false);
|
|
5246
5427
|
this._nockScopes.auth = void 0;
|
|
5247
|
-
|
|
5428
|
+
this._nockScopes.api?.persist(false);
|
|
5248
5429
|
this._nockScopes.api = void 0;
|
|
5249
5430
|
}
|
|
5250
5431
|
clear() {
|
|
@@ -5274,7 +5455,7 @@ var CommercetoolsMock = class {
|
|
|
5274
5455
|
const app = (0, import_express6.default)();
|
|
5275
5456
|
const projectRouter = import_express6.default.Router({ mergeParams: true });
|
|
5276
5457
|
projectRouter.use(import_express6.default.json());
|
|
5277
|
-
if (!
|
|
5458
|
+
if (!options?.silent) {
|
|
5278
5459
|
app.use((0, import_morgan.default)("tiny"));
|
|
5279
5460
|
}
|
|
5280
5461
|
app.use("/oauth", this._oauth2.createRouter());
|