@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.mjs
CHANGED
|
@@ -24,8 +24,8 @@ var CommercetoolsError = class extends Error {
|
|
|
24
24
|
import { v4 as uuidv4 } from "uuid";
|
|
25
25
|
var getBaseResourceProperties = () => ({
|
|
26
26
|
id: uuidv4(),
|
|
27
|
-
createdAt: new Date().toISOString(),
|
|
28
|
-
lastModifiedAt: new Date().toISOString(),
|
|
27
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
28
|
+
lastModifiedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
29
29
|
version: 0
|
|
30
30
|
});
|
|
31
31
|
var nestedLookup = (obj, path) => {
|
|
@@ -75,7 +75,7 @@ var parseExpandClause = (clause) => {
|
|
|
75
75
|
};
|
|
76
76
|
|
|
77
77
|
// src/lib/predicateParser.ts
|
|
78
|
-
import
|
|
78
|
+
import Lexer from "perplex";
|
|
79
79
|
import { Parser } from "pratt";
|
|
80
80
|
|
|
81
81
|
// src/lib/haversine.ts
|
|
@@ -104,14 +104,13 @@ var parseQueryExpression = (predicate) => {
|
|
|
104
104
|
}
|
|
105
105
|
};
|
|
106
106
|
var validateSymbol = (val) => {
|
|
107
|
-
var _a, _b;
|
|
108
107
|
if (!val.type) {
|
|
109
108
|
throw new PredicateError("Internal error");
|
|
110
109
|
}
|
|
111
110
|
if (val.type === "identifier") {
|
|
112
111
|
const char = val.value.charAt(0);
|
|
113
|
-
const line =
|
|
114
|
-
const column =
|
|
112
|
+
const line = val.pos?.start.line;
|
|
113
|
+
const column = val.pos?.start.column;
|
|
115
114
|
throw new PredicateError(
|
|
116
115
|
`Invalid input '${char}', expected input parameter or primitive value (line ${line}, column ${column})`
|
|
117
116
|
);
|
|
@@ -138,7 +137,7 @@ var resolveValue = (obj, val) => {
|
|
|
138
137
|
}
|
|
139
138
|
return obj[val.value];
|
|
140
139
|
};
|
|
141
|
-
var getLexer = (value) => new
|
|
140
|
+
var getLexer = (value) => new Lexer(value).token("AND", /and(?![-_a-z0-9]+)/i).token("OR", /or(?![-_a-z0-9]+)/i).token("NOT", /not(?![-_a-z0-9]+)/i).token("WITHIN", /within(?![-_a-z0-9]+)/i).token("IN", /in(?![-_a-z0-9]+)/i).token("MATCHES_IGNORE_CASE", /matches\s+ignore\s+case(?![-_a-z0-9]+)/i).token("CONTAINS", /contains(?![-_a-z0-9]+)/i).token("ALL", /all(?![-_a-z0-9]+)/i).token("ANY", /any(?![-_a-z0-9]+)/i).token("EMPTY", /empty(?![-_a-z0-9]+)/i).token("IS", /is(?![-_a-z0-9]+)/i).token("DEFINED", /defined(?![-_a-z0-9]+)/i).token("FLOAT", /\d+\.\d+/).token("INT", /\d+/).token("VARIABLE", /:([-_A-Za-z0-9]+)/).token("BOOLEAN", /(true|false)/).token("IDENTIFIER", /[-_A-Za-z0-9]+/).token("STRING", /"((?:\\.|[^"\\])*)"/).token("STRING", /'((?:\\.|[^'\\])*)'/).token("COMMA", ",").token("(", "(").token(")", ")").token(">=", ">=").token("<=", "<=").token(">", ">").token("<", "<").token("!=", "!=").token("=", "=").token('"', '"').token("WS", /\s+/, true);
|
|
142
141
|
var generateMatchFunc = (predicate) => {
|
|
143
142
|
const lexer = getLexer(predicate);
|
|
144
143
|
const parser = new Parser(lexer).builder().nud(
|
|
@@ -162,6 +161,7 @@ var generateMatchFunc = (predicate) => {
|
|
|
162
161
|
100,
|
|
163
162
|
(t) => ({
|
|
164
163
|
type: "var",
|
|
164
|
+
// @ts-ignore
|
|
165
165
|
value: t.token.groups[1],
|
|
166
166
|
pos: t.token.strpos()
|
|
167
167
|
})
|
|
@@ -170,6 +170,7 @@ var generateMatchFunc = (predicate) => {
|
|
|
170
170
|
100,
|
|
171
171
|
(t) => ({
|
|
172
172
|
type: "string",
|
|
173
|
+
// @ts-ignore
|
|
173
174
|
value: t.token.groups[1],
|
|
174
175
|
pos: t.token.strpos()
|
|
175
176
|
})
|
|
@@ -412,6 +413,7 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
412
413
|
return project;
|
|
413
414
|
};
|
|
414
415
|
this.getProject = (projectKey) => this.addProject(projectKey);
|
|
416
|
+
// Expand resolves a nested reference and injects the object in the given obj
|
|
415
417
|
this.expand = (projectKey, obj, clause) => {
|
|
416
418
|
if (!clause)
|
|
417
419
|
return obj;
|
|
@@ -453,6 +455,9 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
453
455
|
let projectStorage = this.resources[projectKey];
|
|
454
456
|
if (!projectStorage) {
|
|
455
457
|
projectStorage = this.resources[projectKey] = {
|
|
458
|
+
"associate-role": /* @__PURE__ */ new Map(),
|
|
459
|
+
"attribute-group": /* @__PURE__ */ new Map(),
|
|
460
|
+
"business-unit": /* @__PURE__ */ new Map(),
|
|
456
461
|
cart: /* @__PURE__ */ new Map(),
|
|
457
462
|
"cart-discount": /* @__PURE__ */ new Map(),
|
|
458
463
|
category: /* @__PURE__ */ new Map(),
|
|
@@ -491,7 +496,7 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
491
496
|
clear() {
|
|
492
497
|
for (const [, projectStorage] of Object.entries(this.resources)) {
|
|
493
498
|
for (const [, value] of Object.entries(projectStorage)) {
|
|
494
|
-
value
|
|
499
|
+
value?.clear();
|
|
495
500
|
}
|
|
496
501
|
}
|
|
497
502
|
}
|
|
@@ -503,16 +508,14 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
503
508
|
return [];
|
|
504
509
|
}
|
|
505
510
|
add(projectKey, typeId, obj, params = {}) {
|
|
506
|
-
var _a;
|
|
507
511
|
const store = this.forProjectKey(projectKey);
|
|
508
|
-
|
|
512
|
+
store[typeId]?.set(obj.id, obj);
|
|
509
513
|
const resource = this.get(projectKey, typeId, obj.id, params);
|
|
510
514
|
assert(resource, `resource of type ${typeId} with id ${obj.id} not created`);
|
|
511
515
|
return cloneObject(resource);
|
|
512
516
|
}
|
|
513
517
|
get(projectKey, typeId, id, params = {}) {
|
|
514
|
-
|
|
515
|
-
const resource = (_a = this.forProjectKey(projectKey)[typeId]) == null ? void 0 : _a.get(id);
|
|
518
|
+
const resource = this.forProjectKey(projectKey)[typeId]?.get(id);
|
|
516
519
|
if (resource) {
|
|
517
520
|
const clone = cloneObject(resource);
|
|
518
521
|
return this.expand(projectKey, clone, params.expand);
|
|
@@ -534,10 +537,9 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
534
537
|
return null;
|
|
535
538
|
}
|
|
536
539
|
delete(projectKey, typeId, id, params = {}) {
|
|
537
|
-
var _a;
|
|
538
540
|
const resource = this.get(projectKey, typeId, id);
|
|
539
541
|
if (resource) {
|
|
540
|
-
|
|
542
|
+
this.forProjectKey(projectKey)[typeId]?.delete(id);
|
|
541
543
|
return this.expand(projectKey, resource, params.expand);
|
|
542
544
|
}
|
|
543
545
|
return resource;
|
|
@@ -627,6 +629,7 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
627
629
|
const store = this.forProjectKey(projectKey)[identifier.typeId];
|
|
628
630
|
if (store) {
|
|
629
631
|
const resource = Array.from(store.values()).find(
|
|
632
|
+
// @ts-ignore
|
|
630
633
|
(r) => r.key === identifier.key
|
|
631
634
|
);
|
|
632
635
|
if (resource) {
|
|
@@ -696,11 +699,10 @@ var OAuth2Store = class {
|
|
|
696
699
|
|
|
697
700
|
// src/oauth/helpers.ts
|
|
698
701
|
var getBearerToken = (request) => {
|
|
699
|
-
var _a;
|
|
700
702
|
const authHeader = request.header("Authorization");
|
|
701
|
-
const match = authHeader
|
|
703
|
+
const match = authHeader?.match(/^Bearer\s(?<token>[^\s]+)$/);
|
|
702
704
|
if (match) {
|
|
703
|
-
return
|
|
705
|
+
return match.groups?.token;
|
|
704
706
|
}
|
|
705
707
|
return void 0;
|
|
706
708
|
};
|
|
@@ -723,7 +725,7 @@ var OAuth2Server = class {
|
|
|
723
725
|
next(
|
|
724
726
|
new CommercetoolsError(
|
|
725
727
|
{
|
|
726
|
-
code: "
|
|
728
|
+
code: "invalid_token",
|
|
727
729
|
message: "This endpoint requires an access token. You can get one from the authorization server."
|
|
728
730
|
},
|
|
729
731
|
401
|
|
@@ -745,7 +747,6 @@ var OAuth2Server = class {
|
|
|
745
747
|
};
|
|
746
748
|
}
|
|
747
749
|
async tokenHandler(request, response, next) {
|
|
748
|
-
var _a;
|
|
749
750
|
const authHeader = request.header("Authorization");
|
|
750
751
|
if (!authHeader) {
|
|
751
752
|
return next(
|
|
@@ -786,7 +787,7 @@ var OAuth2Server = class {
|
|
|
786
787
|
const token = this.store.getClientToken(
|
|
787
788
|
credentials.name,
|
|
788
789
|
credentials.pass,
|
|
789
|
-
|
|
790
|
+
request.query.scope?.toString()
|
|
790
791
|
);
|
|
791
792
|
return response.status(200).send(token);
|
|
792
793
|
} else {
|
|
@@ -829,6 +830,7 @@ var ProjectAPI = class {
|
|
|
829
830
|
params
|
|
830
831
|
);
|
|
831
832
|
}
|
|
833
|
+
// TODO: Not sure if we want to expose this...
|
|
832
834
|
getRepository(typeId) {
|
|
833
835
|
const repository = this._repositories[typeId];
|
|
834
836
|
if (repository !== void 0) {
|
|
@@ -859,7 +861,7 @@ import { v4 as uuidv42 } from "uuid";
|
|
|
859
861
|
var createAddress = (base, projectKey, storage) => {
|
|
860
862
|
if (!base)
|
|
861
863
|
return void 0;
|
|
862
|
-
if (!
|
|
864
|
+
if (!base?.country) {
|
|
863
865
|
throw new Error("Country is required");
|
|
864
866
|
}
|
|
865
867
|
return {
|
|
@@ -896,7 +898,7 @@ var createPrice = (draft) => ({
|
|
|
896
898
|
id: uuidv42(),
|
|
897
899
|
value: createTypedMoney(draft.value)
|
|
898
900
|
});
|
|
899
|
-
var
|
|
901
|
+
var createCentPrecisionMoney = (value) => {
|
|
900
902
|
let fractionDigits = 2;
|
|
901
903
|
switch (value.currencyCode.toUpperCase()) {
|
|
902
904
|
case "BHD":
|
|
@@ -928,12 +930,22 @@ var createTypedMoney = (value) => {
|
|
|
928
930
|
default:
|
|
929
931
|
fractionDigits = 2;
|
|
930
932
|
}
|
|
933
|
+
if (value.preciseAmount) {
|
|
934
|
+
throw new Error("HighPrecisionMoney not supported");
|
|
935
|
+
}
|
|
931
936
|
return {
|
|
932
937
|
type: "centPrecision",
|
|
933
|
-
|
|
938
|
+
// centAmont is only optional on HighPrecisionMoney, so this should never
|
|
939
|
+
// fallback to 0
|
|
940
|
+
centAmount: value.centAmount ?? 0,
|
|
941
|
+
currencyCode: value.currencyCode,
|
|
934
942
|
fractionDigits
|
|
935
943
|
};
|
|
936
944
|
};
|
|
945
|
+
var createTypedMoney = (value) => {
|
|
946
|
+
const result = createCentPrecisionMoney(value);
|
|
947
|
+
return result;
|
|
948
|
+
};
|
|
937
949
|
var resolveStoreReference = (ref, projectKey, storage) => {
|
|
938
950
|
if (!ref)
|
|
939
951
|
return void 0;
|
|
@@ -952,7 +964,8 @@ var getReferenceFromResourceIdentifier = (resourceIdentifier, projectKey, storag
|
|
|
952
964
|
throw new CommercetoolsError(
|
|
953
965
|
{
|
|
954
966
|
code: "InvalidJsonInput",
|
|
955
|
-
message: `${resourceIdentifier.typeId}: ResourceIdentifier requires an 'id' xor a 'key'
|
|
967
|
+
message: `${resourceIdentifier.typeId}: ResourceIdentifier requires an 'id' xor a 'key'`,
|
|
968
|
+
detailedErrorMessage: `ResourceIdentifier requires an 'id' xor a 'key'`
|
|
956
969
|
},
|
|
957
970
|
400
|
|
958
971
|
);
|
|
@@ -966,6 +979,7 @@ var getReferenceFromResourceIdentifier = (resourceIdentifier, projectKey, storag
|
|
|
966
979
|
throw new CommercetoolsError(
|
|
967
980
|
{
|
|
968
981
|
code: "ReferencedResourceNotFound",
|
|
982
|
+
// @ts-ignore
|
|
969
983
|
typeId: resourceIdentifier.typeId,
|
|
970
984
|
message: `The referenced object of type '${resourceIdentifier.typeId}' with '${errIdentifier}' was not found. It either doesn't exist, or it can't be accessed from this endpoint (e.g., if the endpoint filters by store or customer account).`
|
|
971
985
|
},
|
|
@@ -974,7 +988,27 @@ var getReferenceFromResourceIdentifier = (resourceIdentifier, projectKey, storag
|
|
|
974
988
|
}
|
|
975
989
|
return {
|
|
976
990
|
typeId: resourceIdentifier.typeId,
|
|
977
|
-
id: resource
|
|
991
|
+
id: resource?.id
|
|
992
|
+
};
|
|
993
|
+
};
|
|
994
|
+
var getStoreKeyReference = (id, projectKey, storage) => {
|
|
995
|
+
if (id.key) {
|
|
996
|
+
return {
|
|
997
|
+
typeId: "store",
|
|
998
|
+
key: id.key
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
const value = getReferenceFromResourceIdentifier(
|
|
1002
|
+
id,
|
|
1003
|
+
projectKey,
|
|
1004
|
+
storage
|
|
1005
|
+
);
|
|
1006
|
+
if (!value.obj?.key) {
|
|
1007
|
+
throw new Error("No store found for reference");
|
|
1008
|
+
}
|
|
1009
|
+
return {
|
|
1010
|
+
typeId: "store",
|
|
1011
|
+
key: value.obj?.key
|
|
978
1012
|
};
|
|
979
1013
|
};
|
|
980
1014
|
var getRepositoryContext = (request) => ({
|
|
@@ -1012,9 +1046,6 @@ var ProjectService = class {
|
|
|
1012
1046
|
}
|
|
1013
1047
|
};
|
|
1014
1048
|
|
|
1015
|
-
// src/repositories/cart.ts
|
|
1016
|
-
import { v4 as uuidv43 } from "uuid";
|
|
1017
|
-
|
|
1018
1049
|
// src/repositories/abstract.ts
|
|
1019
1050
|
import deepEqual from "deep-equal";
|
|
1020
1051
|
|
|
@@ -1136,19 +1167,49 @@ var AbstractResourceRepository = class extends AbstractRepository {
|
|
|
1136
1167
|
if (current.version === resource.version) {
|
|
1137
1168
|
throw new Error("Internal error: no changes to save");
|
|
1138
1169
|
}
|
|
1139
|
-
resource.lastModifiedAt = new Date().toISOString();
|
|
1170
|
+
resource.lastModifiedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1140
1171
|
this._storage.add(context.projectKey, this.getTypeId(), resource);
|
|
1141
1172
|
return resource;
|
|
1142
1173
|
}
|
|
1143
1174
|
};
|
|
1144
1175
|
|
|
1176
|
+
// src/repositories/associate-role.ts
|
|
1177
|
+
var AssociateRoleRepository = class extends AbstractResourceRepository {
|
|
1178
|
+
getTypeId() {
|
|
1179
|
+
return "associate-role";
|
|
1180
|
+
}
|
|
1181
|
+
create(context, draft) {
|
|
1182
|
+
throw new Error("Method not implemented.");
|
|
1183
|
+
}
|
|
1184
|
+
};
|
|
1185
|
+
|
|
1186
|
+
// src/repositories/attribute-group.ts
|
|
1187
|
+
var AttributeGroupRepository = class extends AbstractResourceRepository {
|
|
1188
|
+
getTypeId() {
|
|
1189
|
+
return "attribute-group";
|
|
1190
|
+
}
|
|
1191
|
+
create(context, draft) {
|
|
1192
|
+
throw new Error("Method not implemented.");
|
|
1193
|
+
}
|
|
1194
|
+
};
|
|
1195
|
+
|
|
1196
|
+
// src/repositories/business-unit.ts
|
|
1197
|
+
var BusinessUnitRepository = class extends AbstractResourceRepository {
|
|
1198
|
+
getTypeId() {
|
|
1199
|
+
return "business-unit";
|
|
1200
|
+
}
|
|
1201
|
+
create(context, draft) {
|
|
1202
|
+
throw new Error("Method not implemented.");
|
|
1203
|
+
}
|
|
1204
|
+
};
|
|
1205
|
+
|
|
1145
1206
|
// src/repositories/cart.ts
|
|
1207
|
+
import { v4 as uuidv43 } from "uuid";
|
|
1146
1208
|
var CartRepository = class extends AbstractResourceRepository {
|
|
1147
1209
|
constructor() {
|
|
1148
1210
|
super(...arguments);
|
|
1149
1211
|
this.actions = {
|
|
1150
1212
|
addLineItem: (context, resource, { productId, variantId, sku, quantity = 1 }) => {
|
|
1151
|
-
var _a;
|
|
1152
1213
|
let product = null;
|
|
1153
1214
|
if (productId && variantId) {
|
|
1154
1215
|
product = this._storage.get(
|
|
@@ -1190,18 +1251,17 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1190
1251
|
});
|
|
1191
1252
|
}
|
|
1192
1253
|
const alreadyAdded = resource.lineItems.some(
|
|
1193
|
-
(x) => x.productId ===
|
|
1254
|
+
(x) => x.productId === product?.id && x.variant.id === variant?.id
|
|
1194
1255
|
);
|
|
1195
1256
|
if (alreadyAdded) {
|
|
1196
|
-
resource.lineItems.
|
|
1197
|
-
if (x.productId ===
|
|
1257
|
+
resource.lineItems.forEach((x) => {
|
|
1258
|
+
if (x.productId === product?.id && x.variant.id === variant?.id) {
|
|
1198
1259
|
x.quantity += quantity;
|
|
1199
1260
|
x.totalPrice.centAmount = calculateLineItemTotalPrice(x);
|
|
1200
1261
|
}
|
|
1201
|
-
return x;
|
|
1202
1262
|
});
|
|
1203
1263
|
} else {
|
|
1204
|
-
if (!
|
|
1264
|
+
if (!variant.prices?.length) {
|
|
1205
1265
|
throw new CommercetoolsError({
|
|
1206
1266
|
code: "General",
|
|
1207
1267
|
message: `A product with ID '${productId}' doesn't have any prices.`
|
|
@@ -1231,6 +1291,7 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1231
1291
|
perMethodTaxRate: [],
|
|
1232
1292
|
totalPrice: {
|
|
1233
1293
|
...price.value,
|
|
1294
|
+
type: "centPrecision",
|
|
1234
1295
|
centAmount: price.value.centAmount * quantity
|
|
1235
1296
|
},
|
|
1236
1297
|
quantity,
|
|
@@ -1242,6 +1303,44 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1242
1303
|
}
|
|
1243
1304
|
resource.totalPrice.centAmount = calculateCartTotalPrice(resource);
|
|
1244
1305
|
},
|
|
1306
|
+
changeLineItemQuantity: (context, resource, { lineItemId, lineItemKey, quantity }) => {
|
|
1307
|
+
let lineItem;
|
|
1308
|
+
if (lineItemId) {
|
|
1309
|
+
lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
1310
|
+
if (!lineItem) {
|
|
1311
|
+
throw new CommercetoolsError({
|
|
1312
|
+
code: "General",
|
|
1313
|
+
message: `A line item with ID '${lineItemId}' not found.`
|
|
1314
|
+
});
|
|
1315
|
+
}
|
|
1316
|
+
} else if (lineItemKey) {
|
|
1317
|
+
lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
1318
|
+
if (!lineItem) {
|
|
1319
|
+
throw new CommercetoolsError({
|
|
1320
|
+
code: "General",
|
|
1321
|
+
message: `A line item with Key '${lineItemKey}' not found.`
|
|
1322
|
+
});
|
|
1323
|
+
}
|
|
1324
|
+
} else {
|
|
1325
|
+
throw new CommercetoolsError({
|
|
1326
|
+
code: "General",
|
|
1327
|
+
message: `Either lineItemid or lineItemKey needs to be provided.`
|
|
1328
|
+
});
|
|
1329
|
+
}
|
|
1330
|
+
if (quantity === 0) {
|
|
1331
|
+
resource.lineItems = resource.lineItems.filter(
|
|
1332
|
+
(x) => x.id !== lineItemId
|
|
1333
|
+
);
|
|
1334
|
+
} else {
|
|
1335
|
+
resource.lineItems.forEach((x) => {
|
|
1336
|
+
if (x.id === lineItemId && quantity) {
|
|
1337
|
+
x.quantity = quantity;
|
|
1338
|
+
x.totalPrice.centAmount = calculateLineItemTotalPrice(x);
|
|
1339
|
+
}
|
|
1340
|
+
});
|
|
1341
|
+
}
|
|
1342
|
+
resource.totalPrice.centAmount = calculateCartTotalPrice(resource);
|
|
1343
|
+
},
|
|
1245
1344
|
removeLineItem: (context, resource, { lineItemId, quantity }) => {
|
|
1246
1345
|
const lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
1247
1346
|
if (!lineItem) {
|
|
@@ -1256,18 +1355,21 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1256
1355
|
(x) => x.id !== lineItemId
|
|
1257
1356
|
);
|
|
1258
1357
|
} else {
|
|
1259
|
-
resource.lineItems.
|
|
1358
|
+
resource.lineItems.forEach((x) => {
|
|
1260
1359
|
if (x.id === lineItemId && quantity) {
|
|
1261
1360
|
x.quantity -= quantity;
|
|
1262
1361
|
x.totalPrice.centAmount = calculateLineItemTotalPrice(x);
|
|
1263
1362
|
}
|
|
1264
|
-
return x;
|
|
1265
1363
|
});
|
|
1266
1364
|
}
|
|
1267
1365
|
resource.totalPrice.centAmount = calculateCartTotalPrice(resource);
|
|
1268
1366
|
},
|
|
1269
1367
|
setBillingAddress: (context, resource, { address }) => {
|
|
1270
|
-
resource.billingAddress =
|
|
1368
|
+
resource.billingAddress = createAddress(
|
|
1369
|
+
address,
|
|
1370
|
+
context.projectKey,
|
|
1371
|
+
this._storage
|
|
1372
|
+
);
|
|
1271
1373
|
},
|
|
1272
1374
|
setShippingMethod: (context, resource, { shippingMethod }) => {
|
|
1273
1375
|
if (shippingMethod) {
|
|
@@ -1317,7 +1419,7 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1317
1419
|
typeId: "type",
|
|
1318
1420
|
id: resolvedType.id
|
|
1319
1421
|
},
|
|
1320
|
-
fields: fields ||
|
|
1422
|
+
fields: fields || {}
|
|
1321
1423
|
};
|
|
1322
1424
|
}
|
|
1323
1425
|
},
|
|
@@ -1325,7 +1427,22 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1325
1427
|
resource.locale = locale;
|
|
1326
1428
|
},
|
|
1327
1429
|
setShippingAddress: (context, resource, { address }) => {
|
|
1328
|
-
|
|
1430
|
+
if (!address) {
|
|
1431
|
+
resource.shippingAddress = void 0;
|
|
1432
|
+
return;
|
|
1433
|
+
}
|
|
1434
|
+
let custom = void 0;
|
|
1435
|
+
if (address.custom) {
|
|
1436
|
+
custom = createCustomFields(
|
|
1437
|
+
address.custom,
|
|
1438
|
+
context.projectKey,
|
|
1439
|
+
this._storage
|
|
1440
|
+
);
|
|
1441
|
+
}
|
|
1442
|
+
resource.shippingAddress = {
|
|
1443
|
+
...address,
|
|
1444
|
+
custom
|
|
1445
|
+
};
|
|
1329
1446
|
}
|
|
1330
1447
|
};
|
|
1331
1448
|
this.draftLineItemtoLineItem = (projectKey, draftLineItem, currency, country) => {
|
|
@@ -1381,7 +1498,9 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1381
1498
|
variant,
|
|
1382
1499
|
price,
|
|
1383
1500
|
totalPrice: {
|
|
1384
|
-
|
|
1501
|
+
type: "centPrecision",
|
|
1502
|
+
currencyCode: price.value.currencyCode,
|
|
1503
|
+
fractionDigits: price.value.fractionDigits,
|
|
1385
1504
|
centAmount: price.value.centAmount * quant
|
|
1386
1505
|
},
|
|
1387
1506
|
taxedPricePortions: [],
|
|
@@ -1398,20 +1517,23 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1398
1517
|
return "cart";
|
|
1399
1518
|
}
|
|
1400
1519
|
create(context, draft) {
|
|
1401
|
-
|
|
1402
|
-
const lineItems = ((_a = draft.lineItems) == null ? void 0 : _a.map(
|
|
1520
|
+
const lineItems = draft.lineItems?.map(
|
|
1403
1521
|
(draftLineItem) => this.draftLineItemtoLineItem(
|
|
1404
1522
|
context.projectKey,
|
|
1405
1523
|
draftLineItem,
|
|
1406
1524
|
draft.currency,
|
|
1407
1525
|
draft.country
|
|
1408
1526
|
)
|
|
1409
|
-
)
|
|
1527
|
+
) ?? [];
|
|
1410
1528
|
const resource = {
|
|
1411
1529
|
...getBaseResourceProperties(),
|
|
1412
1530
|
cartState: "Active",
|
|
1413
1531
|
country: draft.country,
|
|
1414
1532
|
customLineItems: [],
|
|
1533
|
+
directDiscounts: [],
|
|
1534
|
+
discountCodes: [],
|
|
1535
|
+
inventoryMode: "None",
|
|
1536
|
+
itemShippingAddresses: [],
|
|
1415
1537
|
lineItems,
|
|
1416
1538
|
locale: draft.locale,
|
|
1417
1539
|
taxCalculationMode: draft.taxCalculationMode ?? "LineItemLevel",
|
|
@@ -1504,6 +1626,9 @@ var CartDiscountRepository = class extends AbstractResourceRepository {
|
|
|
1504
1626
|
cartPredicate: draft.cartPredicate,
|
|
1505
1627
|
isActive: draft.isActive || false,
|
|
1506
1628
|
name: draft.name,
|
|
1629
|
+
stores: draft.stores?.map(
|
|
1630
|
+
(s) => getStoreKeyReference(s, context.projectKey, this._storage)
|
|
1631
|
+
) ?? [],
|
|
1507
1632
|
references: [],
|
|
1508
1633
|
target: draft.target,
|
|
1509
1634
|
requiresDiscountCode: draft.requiresDiscountCode || false,
|
|
@@ -1552,8 +1677,7 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
1552
1677
|
super(...arguments);
|
|
1553
1678
|
this.actions = {
|
|
1554
1679
|
changeAssetName: (context, resource, { assetId, assetKey, name }) => {
|
|
1555
|
-
|
|
1556
|
-
(_a = resource.assets) == null ? void 0 : _a.forEach((asset) => {
|
|
1680
|
+
resource.assets?.forEach((asset) => {
|
|
1557
1681
|
if (assetId && assetId === asset.id) {
|
|
1558
1682
|
asset.name = name;
|
|
1559
1683
|
}
|
|
@@ -1569,8 +1693,7 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
1569
1693
|
resource.key = key;
|
|
1570
1694
|
},
|
|
1571
1695
|
setAssetDescription: (context, resource, { assetId, assetKey, description }) => {
|
|
1572
|
-
|
|
1573
|
-
(_a = resource.assets) == null ? void 0 : _a.forEach((asset) => {
|
|
1696
|
+
resource.assets?.forEach((asset) => {
|
|
1574
1697
|
if (assetId && assetId === asset.id) {
|
|
1575
1698
|
asset.description = description;
|
|
1576
1699
|
}
|
|
@@ -1580,8 +1703,7 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
1580
1703
|
});
|
|
1581
1704
|
},
|
|
1582
1705
|
setAssetSources: (context, resource, { assetId, assetKey, sources }) => {
|
|
1583
|
-
|
|
1584
|
-
(_a = resource.assets) == null ? void 0 : _a.forEach((asset) => {
|
|
1706
|
+
resource.assets?.forEach((asset) => {
|
|
1585
1707
|
if (assetId && assetId === asset.id) {
|
|
1586
1708
|
asset.sources = sources;
|
|
1587
1709
|
}
|
|
@@ -1629,7 +1751,6 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
1629
1751
|
return "category";
|
|
1630
1752
|
}
|
|
1631
1753
|
create(context, draft) {
|
|
1632
|
-
var _a;
|
|
1633
1754
|
const resource = {
|
|
1634
1755
|
...getBaseResourceProperties(),
|
|
1635
1756
|
key: draft.key,
|
|
@@ -1639,7 +1760,8 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
1639
1760
|
externalId: draft.externalId || "",
|
|
1640
1761
|
parent: draft.parent ? { typeId: "category", id: draft.parent.id } : void 0,
|
|
1641
1762
|
ancestors: [],
|
|
1642
|
-
|
|
1763
|
+
// TODO
|
|
1764
|
+
assets: draft.assets?.map((d) => ({
|
|
1643
1765
|
id: uuidv44(),
|
|
1644
1766
|
name: d.name,
|
|
1645
1767
|
description: d.description,
|
|
@@ -1651,7 +1773,7 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
1651
1773
|
context.projectKey,
|
|
1652
1774
|
this._storage
|
|
1653
1775
|
)
|
|
1654
|
-
}))
|
|
1776
|
+
})) || [],
|
|
1655
1777
|
custom: createCustomFields(
|
|
1656
1778
|
draft.custom,
|
|
1657
1779
|
context.projectKey,
|
|
@@ -1831,6 +1953,7 @@ var CustomerRepository = class extends AbstractResourceRepository {
|
|
|
1831
1953
|
create(context, draft) {
|
|
1832
1954
|
const resource = {
|
|
1833
1955
|
...getBaseResourceProperties(),
|
|
1956
|
+
authenticationMode: draft.authenticationMode || "Password",
|
|
1834
1957
|
email: draft.email,
|
|
1835
1958
|
password: draft.password ? Buffer.from(draft.password).toString("base64") : void 0,
|
|
1836
1959
|
isEmailVerified: draft.isEmailVerified || false,
|
|
@@ -2048,10 +2171,9 @@ var ExtensionRepository = class extends AbstractResourceRepository {
|
|
|
2048
2171
|
return "extension";
|
|
2049
2172
|
}
|
|
2050
2173
|
postProcessResource(resource) {
|
|
2051
|
-
var _a;
|
|
2052
2174
|
if (resource) {
|
|
2053
2175
|
const extension = resource;
|
|
2054
|
-
if (extension.destination.type === "HTTP" &&
|
|
2176
|
+
if (extension.destination.type === "HTTP" && extension.destination.authentication?.type === "AuthorizationHeader") {
|
|
2055
2177
|
return maskSecretValue(
|
|
2056
2178
|
extension,
|
|
2057
2179
|
"destination.authentication.headerValue"
|
|
@@ -2109,7 +2231,7 @@ var InventoryEntryRepository = class extends AbstractResourceRepository {
|
|
|
2109
2231
|
typeId: "type",
|
|
2110
2232
|
id: resolvedType.id
|
|
2111
2233
|
},
|
|
2112
|
-
fields: fields ||
|
|
2234
|
+
fields: fields || {}
|
|
2113
2235
|
};
|
|
2114
2236
|
}
|
|
2115
2237
|
},
|
|
@@ -2122,7 +2244,6 @@ var InventoryEntryRepository = class extends AbstractResourceRepository {
|
|
|
2122
2244
|
return "inventory-entry";
|
|
2123
2245
|
}
|
|
2124
2246
|
create(context, draft) {
|
|
2125
|
-
var _a;
|
|
2126
2247
|
const resource = {
|
|
2127
2248
|
...getBaseResourceProperties(),
|
|
2128
2249
|
sku: draft.sku,
|
|
@@ -2133,7 +2254,7 @@ var InventoryEntryRepository = class extends AbstractResourceRepository {
|
|
|
2133
2254
|
supplyChannel: {
|
|
2134
2255
|
...draft.supplyChannel,
|
|
2135
2256
|
typeId: "channel",
|
|
2136
|
-
id:
|
|
2257
|
+
id: draft.supplyChannel?.id ?? ""
|
|
2137
2258
|
},
|
|
2138
2259
|
custom: createCustomFields(
|
|
2139
2260
|
draft.custom,
|
|
@@ -2192,7 +2313,11 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2192
2313
|
resource.state = { typeId: "state", id: resolvedType.id };
|
|
2193
2314
|
},
|
|
2194
2315
|
setBillingAddress: (context, resource, { address }) => {
|
|
2195
|
-
resource.billingAddress =
|
|
2316
|
+
resource.billingAddress = createAddress(
|
|
2317
|
+
address,
|
|
2318
|
+
context.projectKey,
|
|
2319
|
+
this._storage
|
|
2320
|
+
);
|
|
2196
2321
|
},
|
|
2197
2322
|
setCustomerEmail: (context, resource, { email }) => {
|
|
2198
2323
|
resource.customerEmail = email;
|
|
@@ -2219,7 +2344,7 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2219
2344
|
typeId: "type",
|
|
2220
2345
|
id: resolvedType.id
|
|
2221
2346
|
},
|
|
2222
|
-
fields: fields ||
|
|
2347
|
+
fields: fields || {}
|
|
2223
2348
|
};
|
|
2224
2349
|
}
|
|
2225
2350
|
},
|
|
@@ -2230,7 +2355,11 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2230
2355
|
resource.orderNumber = orderNumber;
|
|
2231
2356
|
},
|
|
2232
2357
|
setShippingAddress: (context, resource, { address }) => {
|
|
2233
|
-
resource.shippingAddress =
|
|
2358
|
+
resource.shippingAddress = createAddress(
|
|
2359
|
+
address,
|
|
2360
|
+
context.projectKey,
|
|
2361
|
+
this._storage
|
|
2362
|
+
);
|
|
2234
2363
|
},
|
|
2235
2364
|
setStore: (context, resource, { store }) => {
|
|
2236
2365
|
if (!store)
|
|
@@ -2295,12 +2424,19 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2295
2424
|
return resource;
|
|
2296
2425
|
}
|
|
2297
2426
|
import(context, draft) {
|
|
2298
|
-
var _a, _b;
|
|
2299
2427
|
assert2(this, "OrderRepository not valid");
|
|
2300
2428
|
const resource = {
|
|
2301
2429
|
...getBaseResourceProperties(),
|
|
2302
|
-
billingAddress:
|
|
2303
|
-
|
|
2430
|
+
billingAddress: createAddress(
|
|
2431
|
+
draft.billingAddress,
|
|
2432
|
+
context.projectKey,
|
|
2433
|
+
this._storage
|
|
2434
|
+
),
|
|
2435
|
+
shippingAddress: createAddress(
|
|
2436
|
+
draft.shippingAddress,
|
|
2437
|
+
context.projectKey,
|
|
2438
|
+
this._storage
|
|
2439
|
+
),
|
|
2304
2440
|
custom: createCustomFields(
|
|
2305
2441
|
draft.custom,
|
|
2306
2442
|
context.projectKey,
|
|
@@ -2321,17 +2457,13 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2321
2457
|
this._storage
|
|
2322
2458
|
),
|
|
2323
2459
|
syncInfo: [],
|
|
2324
|
-
lineItems:
|
|
2460
|
+
lineItems: draft.lineItems?.map(
|
|
2325
2461
|
(item) => this.lineItemFromImportDraft.bind(this)(context, item)
|
|
2326
|
-
)
|
|
2327
|
-
customLineItems:
|
|
2462
|
+
) || [],
|
|
2463
|
+
customLineItems: draft.customLineItems?.map(
|
|
2328
2464
|
(item) => this.customLineItemFromImportDraft.bind(this)(context, item)
|
|
2329
|
-
)
|
|
2330
|
-
totalPrice:
|
|
2331
|
-
type: "centPrecision",
|
|
2332
|
-
...draft.totalPrice,
|
|
2333
|
-
fractionDigits: 2
|
|
2334
|
-
}
|
|
2465
|
+
) || [],
|
|
2466
|
+
totalPrice: createCentPrecisionMoney(draft.totalPrice)
|
|
2335
2467
|
};
|
|
2336
2468
|
this.saveNew(context, resource);
|
|
2337
2469
|
return resource;
|
|
@@ -2388,7 +2520,7 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2388
2520
|
taxRate: draft.taxRate,
|
|
2389
2521
|
taxedPricePortions: [],
|
|
2390
2522
|
perMethodTaxRate: [],
|
|
2391
|
-
totalPrice:
|
|
2523
|
+
totalPrice: createCentPrecisionMoney(draft.price.value),
|
|
2392
2524
|
variant: {
|
|
2393
2525
|
id: variant.id,
|
|
2394
2526
|
sku: variant.sku,
|
|
@@ -2408,11 +2540,12 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2408
2540
|
discountedPricePerQuantity: [],
|
|
2409
2541
|
money: createTypedMoney(draft.money),
|
|
2410
2542
|
name: draft.name,
|
|
2411
|
-
quantity: draft.quantity,
|
|
2543
|
+
quantity: draft.quantity ?? 0,
|
|
2544
|
+
perMethodTaxRate: [],
|
|
2412
2545
|
priceMode: draft.priceMode,
|
|
2413
2546
|
slug: draft.slug,
|
|
2414
2547
|
state: [],
|
|
2415
|
-
totalPrice:
|
|
2548
|
+
totalPrice: createCentPrecisionMoney(draft.money)
|
|
2416
2549
|
};
|
|
2417
2550
|
return lineItem;
|
|
2418
2551
|
}
|
|
@@ -2474,8 +2607,10 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
2474
2607
|
this.transactionFromTransactionDraft = (draft, context) => ({
|
|
2475
2608
|
...draft,
|
|
2476
2609
|
id: uuidv45(),
|
|
2477
|
-
amount:
|
|
2478
|
-
custom: createCustomFields(draft.custom, context.projectKey, this._storage)
|
|
2610
|
+
amount: createCentPrecisionMoney(draft.amount),
|
|
2611
|
+
custom: createCustomFields(draft.custom, context.projectKey, this._storage),
|
|
2612
|
+
state: draft.state ?? "Initial"
|
|
2613
|
+
// Documented as default
|
|
2479
2614
|
});
|
|
2480
2615
|
this.actions = {
|
|
2481
2616
|
setCustomField: (context, resource, { name, value }) => {
|
|
@@ -2500,7 +2635,7 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
2500
2635
|
typeId: "type",
|
|
2501
2636
|
id: resolvedType.id
|
|
2502
2637
|
},
|
|
2503
|
-
fields: fields
|
|
2638
|
+
fields: fields ?? {}
|
|
2504
2639
|
};
|
|
2505
2640
|
}
|
|
2506
2641
|
},
|
|
@@ -2534,6 +2669,23 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
2534
2669
|
obj: stateObj
|
|
2535
2670
|
};
|
|
2536
2671
|
}
|
|
2672
|
+
// addInterfaceInteraction: () => {},
|
|
2673
|
+
// changeAmountPlanned: () => {},
|
|
2674
|
+
// changeTransactionInteractionId: () => {},
|
|
2675
|
+
// changeTransactionTimestamp: () => {},
|
|
2676
|
+
// setAmountPaid: () => {},
|
|
2677
|
+
// setAmountRefunded: () => {},
|
|
2678
|
+
// setAnonymousId: () => {},
|
|
2679
|
+
// setAuthorization: () => {},
|
|
2680
|
+
// setCustomer: () => {},
|
|
2681
|
+
// setExternalId: () => {},
|
|
2682
|
+
// setInterfaceId: () => {},
|
|
2683
|
+
// setKey: () => {},
|
|
2684
|
+
// setMethodInfoInterface: () => {},
|
|
2685
|
+
// setMethodInfoMethod: () => {},
|
|
2686
|
+
// setMethodInfoName: () => {},
|
|
2687
|
+
// setStatusInterfaceCode: () => {},
|
|
2688
|
+
// setStatusInterfaceText: () => {},
|
|
2537
2689
|
};
|
|
2538
2690
|
}
|
|
2539
2691
|
getTypeId() {
|
|
@@ -2542,7 +2694,7 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
2542
2694
|
create(context, draft) {
|
|
2543
2695
|
const resource = {
|
|
2544
2696
|
...getBaseResourceProperties(),
|
|
2545
|
-
amountPlanned:
|
|
2697
|
+
amountPlanned: createCentPrecisionMoney(draft.amountPlanned),
|
|
2546
2698
|
paymentMethodInfo: draft.paymentMethodInfo,
|
|
2547
2699
|
paymentStatus: draft.paymentStatus ? {
|
|
2548
2700
|
...draft.paymentStatus,
|
|
@@ -2788,13 +2940,9 @@ var ProductRepository = class extends AbstractResourceRepository {
|
|
|
2788
2940
|
},
|
|
2789
2941
|
changePrice: (context, resource, { priceId, price, staged }) => {
|
|
2790
2942
|
const changeVariantPrice = (data) => {
|
|
2791
|
-
var _a;
|
|
2792
2943
|
const allVariants = [data.masterVariant, ...data.variants ?? []];
|
|
2793
2944
|
const priceVariant = allVariants.find(
|
|
2794
|
-
(variant2) =>
|
|
2795
|
-
var _a2;
|
|
2796
|
-
return (_a2 = variant2.prices) == null ? void 0 : _a2.some((x) => x.id === priceId);
|
|
2797
|
-
}
|
|
2945
|
+
(variant2) => variant2.prices?.some((x) => x.id === priceId)
|
|
2798
2946
|
);
|
|
2799
2947
|
if (!priceVariant) {
|
|
2800
2948
|
throw new Error(
|
|
@@ -2811,7 +2959,7 @@ var ProductRepository = class extends AbstractResourceRepository {
|
|
|
2811
2959
|
`Variant with id ${priceVariant.id} or sku ${priceVariant.sku} not found on product ${resource.id}`
|
|
2812
2960
|
);
|
|
2813
2961
|
}
|
|
2814
|
-
variant.prices =
|
|
2962
|
+
variant.prices = variant.prices?.map((x) => {
|
|
2815
2963
|
if (x.id === priceId) {
|
|
2816
2964
|
return { ...x, ...price };
|
|
2817
2965
|
}
|
|
@@ -2833,13 +2981,9 @@ var ProductRepository = class extends AbstractResourceRepository {
|
|
|
2833
2981
|
},
|
|
2834
2982
|
removePrice: (context, resource, { priceId, staged }) => {
|
|
2835
2983
|
const removeVariantPrice = (data) => {
|
|
2836
|
-
var _a;
|
|
2837
2984
|
const allVariants = [data.masterVariant, ...data.variants ?? []];
|
|
2838
2985
|
const priceVariant = allVariants.find(
|
|
2839
|
-
(variant2) =>
|
|
2840
|
-
var _a2;
|
|
2841
|
-
return (_a2 = variant2.prices) == null ? void 0 : _a2.some((x) => x.id === priceId);
|
|
2842
|
-
}
|
|
2986
|
+
(variant2) => variant2.prices?.some((x) => x.id === priceId)
|
|
2843
2987
|
);
|
|
2844
2988
|
if (!priceVariant) {
|
|
2845
2989
|
throw new Error(
|
|
@@ -2856,7 +3000,7 @@ var ProductRepository = class extends AbstractResourceRepository {
|
|
|
2856
3000
|
`Variant with id ${priceVariant.id} or sku ${priceVariant.sku} not found on product ${resource.id}`
|
|
2857
3001
|
);
|
|
2858
3002
|
}
|
|
2859
|
-
variant.prices =
|
|
3003
|
+
variant.prices = variant.prices?.filter((x) => x.id !== priceId);
|
|
2860
3004
|
if (isMasterVariant) {
|
|
2861
3005
|
data.masterVariant = variant;
|
|
2862
3006
|
} else {
|
|
@@ -2871,13 +3015,46 @@ var ProductRepository = class extends AbstractResourceRepository {
|
|
|
2871
3015
|
checkForStagedChanges(resource);
|
|
2872
3016
|
return resource;
|
|
2873
3017
|
}
|
|
3018
|
+
// 'changeName': () => {},
|
|
3019
|
+
// 'changeSlug': () => {},
|
|
3020
|
+
// 'addVariant': () => {},
|
|
3021
|
+
// 'removeVariant': () => {},
|
|
3022
|
+
// 'changeMasterVariant': () => {},
|
|
3023
|
+
// 'setPrices': () => {},
|
|
3024
|
+
// 'setProductPriceCustomType': () => {},
|
|
3025
|
+
// 'setProductPriceCustomField': () => {},
|
|
3026
|
+
// 'setDiscountedPrice': () => {},
|
|
3027
|
+
// 'setAttributeInAllVariants': () => {},
|
|
3028
|
+
// 'addToCategory': () => {},
|
|
3029
|
+
// 'setCategoryOrderHint': () => {},
|
|
3030
|
+
// 'removeFromCategory': () => {},
|
|
3031
|
+
// 'setTaxCategory': () => {},
|
|
3032
|
+
// 'setSku': () => {},
|
|
3033
|
+
// 'setProductVariantKey': () => {},
|
|
3034
|
+
// 'setImageLabel': () => {},
|
|
3035
|
+
// 'addAsset': () => {},
|
|
3036
|
+
// 'removeAsset': () => {},
|
|
3037
|
+
// 'setAssetKey': () => {},
|
|
3038
|
+
// 'changeAssetOrder': () => {},
|
|
3039
|
+
// 'changeAssetName': () => {},
|
|
3040
|
+
// 'setAssetDescription': () => {},
|
|
3041
|
+
// 'setAssetTags': () => {},
|
|
3042
|
+
// 'setAssetSources': () => {},
|
|
3043
|
+
// 'setAssetCustomType': () => {},
|
|
3044
|
+
// 'setAssetCustomField': () => {},
|
|
3045
|
+
// 'setSearchKeywords': () => {},
|
|
3046
|
+
// 'setMetaTitle': () => {},
|
|
3047
|
+
// 'setMetaDescription': () => {},
|
|
3048
|
+
// 'setMetaKeywords': () => {},
|
|
3049
|
+
// 'revertStagedChanges': () => {},
|
|
3050
|
+
// 'revertStagedVariantChanges': () => {},
|
|
3051
|
+
// 'transitionState': () => {},
|
|
2874
3052
|
};
|
|
2875
3053
|
}
|
|
2876
3054
|
getTypeId() {
|
|
2877
3055
|
return "product";
|
|
2878
3056
|
}
|
|
2879
3057
|
create(context, draft) {
|
|
2880
|
-
var _a;
|
|
2881
3058
|
if (!draft.masterVariant) {
|
|
2882
3059
|
throw new Error("Missing master variant");
|
|
2883
3060
|
}
|
|
@@ -2902,9 +3079,9 @@ var ProductRepository = class extends AbstractResourceRepository {
|
|
|
2902
3079
|
slug: draft.slug,
|
|
2903
3080
|
categories: [],
|
|
2904
3081
|
masterVariant: variantFromDraft(1, draft.masterVariant),
|
|
2905
|
-
variants:
|
|
3082
|
+
variants: draft.variants?.map(
|
|
2906
3083
|
(variant, index) => variantFromDraft(index + 2, variant)
|
|
2907
|
-
)
|
|
3084
|
+
) ?? [],
|
|
2908
3085
|
searchKeywords: draft.searchKeywords ?? {}
|
|
2909
3086
|
};
|
|
2910
3087
|
const resource = {
|
|
@@ -2950,26 +3127,18 @@ var getVariant = (productData, variantId, sku) => {
|
|
|
2950
3127
|
variantIndex: !isMasterVariant && foundVariant ? productData.variants.indexOf(foundVariant) : -1
|
|
2951
3128
|
};
|
|
2952
3129
|
};
|
|
2953
|
-
var variantFromDraft = (variantId, variant) => {
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
images: []
|
|
2962
|
-
};
|
|
2963
|
-
};
|
|
3130
|
+
var variantFromDraft = (variantId, variant) => ({
|
|
3131
|
+
id: variantId,
|
|
3132
|
+
sku: variant?.sku,
|
|
3133
|
+
attributes: variant?.attributes ?? [],
|
|
3134
|
+
prices: variant?.prices?.map(priceFromDraft),
|
|
3135
|
+
assets: [],
|
|
3136
|
+
images: []
|
|
3137
|
+
});
|
|
2964
3138
|
var priceFromDraft = (draft) => ({
|
|
2965
3139
|
id: uuidv46(),
|
|
2966
3140
|
country: draft.country,
|
|
2967
|
-
value:
|
|
2968
|
-
currencyCode: draft.value.currencyCode,
|
|
2969
|
-
centAmount: draft.value.centAmount,
|
|
2970
|
-
fractionDigits: 2,
|
|
2971
|
-
type: "centPrecision"
|
|
2972
|
-
}
|
|
3141
|
+
value: createTypedMoney(draft.value)
|
|
2973
3142
|
});
|
|
2974
3143
|
|
|
2975
3144
|
// src/repositories/product-discount.ts
|
|
@@ -3057,7 +3226,7 @@ var ProductDiscountRepository = class extends AbstractResourceRepository {
|
|
|
3057
3226
|
};
|
|
3058
3227
|
|
|
3059
3228
|
// src/lib/projectionSearchFilter.ts
|
|
3060
|
-
import
|
|
3229
|
+
import Lexer2 from "perplex";
|
|
3061
3230
|
import Parser2 from "pratt";
|
|
3062
3231
|
var parseFilterExpression = (filter) => {
|
|
3063
3232
|
const exprFunc = generateMatchFunc2(filter);
|
|
@@ -3067,7 +3236,7 @@ var parseFilterExpression = (filter) => {
|
|
|
3067
3236
|
}
|
|
3068
3237
|
return filterProduct(source, exprFunc);
|
|
3069
3238
|
};
|
|
3070
|
-
var getLexer2 = (value) => new
|
|
3239
|
+
var getLexer2 = (value) => new Lexer2(value).token("MISSING", /missing(?![-_a-z0-9]+)/i).token("EXISTS", /exists(?![-_a-z0-9]+)/i).token("RANGE", /range(?![-_a-z0-9]+)/i).token("TO", /to(?![-_a-z0-9]+)/i).token("IDENTIFIER", /[-_.a-z]+/i).token("FLOAT", /\d+\.\d+/).token("INT", /\d+/).token("STRING", /"((?:\\.|[^"\\])*)"/).token("STRING", /'((?:\\.|[^'\\])*)'/).token("COMMA", ",").token("STAR", "*").token("(", "(").token(":", ":").token(")", ")").token('"', '"').token("WS", /\s+/, true);
|
|
3071
3240
|
var parseFilter = (filter) => {
|
|
3072
3241
|
const lexer = getLexer2(filter);
|
|
3073
3242
|
const parser = new Parser2(lexer).builder().nud("IDENTIFIER", 100, (t) => t.token.match).led(":", 100, ({ left, bp }) => {
|
|
@@ -3103,6 +3272,7 @@ var parseFilter = (filter) => {
|
|
|
3103
3272
|
(t) => ({
|
|
3104
3273
|
type: "Symbol",
|
|
3105
3274
|
kind: "string",
|
|
3275
|
+
// @ts-ignore
|
|
3106
3276
|
value: t.token.groups[1]
|
|
3107
3277
|
})
|
|
3108
3278
|
).nud(
|
|
@@ -3247,7 +3417,6 @@ var getVariants = (p) => [
|
|
|
3247
3417
|
|
|
3248
3418
|
// src/priceSelector.ts
|
|
3249
3419
|
var applyPriceSelector = (products, selector) => {
|
|
3250
|
-
var _a;
|
|
3251
3420
|
validatePriceSelector(selector);
|
|
3252
3421
|
for (const product of products) {
|
|
3253
3422
|
const variants = [
|
|
@@ -3255,7 +3424,7 @@ var applyPriceSelector = (products, selector) => {
|
|
|
3255
3424
|
...product.variants ?? []
|
|
3256
3425
|
].filter((x) => x != void 0);
|
|
3257
3426
|
for (const variant of variants) {
|
|
3258
|
-
const scopedPrices =
|
|
3427
|
+
const scopedPrices = variant.prices?.filter((p) => priceSelectorFilter(p, selector)) ?? [];
|
|
3259
3428
|
if (scopedPrices.length > 0) {
|
|
3260
3429
|
const price = scopedPrices[0];
|
|
3261
3430
|
variant.scopedPriceDiscounted = false;
|
|
@@ -3279,17 +3448,16 @@ var validatePriceSelector = (selector) => {
|
|
|
3279
3448
|
}
|
|
3280
3449
|
};
|
|
3281
3450
|
var priceSelectorFilter = (price, selector) => {
|
|
3282
|
-
var _a, _b, _c, _d;
|
|
3283
3451
|
if ((selector.country || price.country) && selector.country !== price.country) {
|
|
3284
3452
|
return false;
|
|
3285
3453
|
}
|
|
3286
3454
|
if ((selector.currency || price.value.currencyCode) && selector.currency !== price.value.currencyCode) {
|
|
3287
3455
|
return false;
|
|
3288
3456
|
}
|
|
3289
|
-
if ((selector.channel ||
|
|
3457
|
+
if ((selector.channel || price.channel?.id) && selector.channel !== price.channel?.id) {
|
|
3290
3458
|
return false;
|
|
3291
3459
|
}
|
|
3292
|
-
if ((selector.customerGroup ||
|
|
3460
|
+
if ((selector.customerGroup || price.customerGroup?.id) && selector.customerGroup !== price.customerGroup?.id) {
|
|
3293
3461
|
return false;
|
|
3294
3462
|
}
|
|
3295
3463
|
return true;
|
|
@@ -3413,6 +3581,11 @@ var ProductProjectionSearch = class {
|
|
|
3413
3581
|
}
|
|
3414
3582
|
return result;
|
|
3415
3583
|
}
|
|
3584
|
+
/**
|
|
3585
|
+
* TODO: This implemention needs the following additional features:
|
|
3586
|
+
* - counting products
|
|
3587
|
+
* - correct dataType
|
|
3588
|
+
*/
|
|
3416
3589
|
termFacet(facet, products) {
|
|
3417
3590
|
const result = {
|
|
3418
3591
|
type: "terms",
|
|
@@ -3464,7 +3637,7 @@ var ProductProjectionSearch = class {
|
|
|
3464
3637
|
for (const p of products) {
|
|
3465
3638
|
for (const v of getVariants(p)) {
|
|
3466
3639
|
const val = resolveVariantValue(v, source);
|
|
3467
|
-
if (filters
|
|
3640
|
+
if (filters?.some((f) => f.match(val))) {
|
|
3468
3641
|
count++;
|
|
3469
3642
|
}
|
|
3470
3643
|
}
|
|
@@ -3478,7 +3651,7 @@ var ProductProjectionSearch = class {
|
|
|
3478
3651
|
};
|
|
3479
3652
|
}
|
|
3480
3653
|
rangeFacet(source, ranges, products) {
|
|
3481
|
-
const counts =
|
|
3654
|
+
const counts = ranges?.map((range) => {
|
|
3482
3655
|
if (source.startsWith("variants.")) {
|
|
3483
3656
|
const values = [];
|
|
3484
3657
|
for (const p of products) {
|
|
@@ -3500,6 +3673,7 @@ var ProductProjectionSearch = class {
|
|
|
3500
3673
|
to: range.stop || 0,
|
|
3501
3674
|
toStr: range.stop !== null ? Number(range.stop).toFixed(1) : "",
|
|
3502
3675
|
count: numValues,
|
|
3676
|
+
// totalCount: 0,
|
|
3503
3677
|
total: values.reduce((a, b) => a + b, 0),
|
|
3504
3678
|
min: numValues > 0 ? Math.min(...values) : 0,
|
|
3505
3679
|
max: numValues > 0 ? Math.max(...values) : 0,
|
|
@@ -3508,9 +3682,10 @@ var ProductProjectionSearch = class {
|
|
|
3508
3682
|
} else {
|
|
3509
3683
|
throw new Error("not supported");
|
|
3510
3684
|
}
|
|
3511
|
-
})
|
|
3685
|
+
}) || [];
|
|
3512
3686
|
const data = {
|
|
3513
3687
|
type: "range",
|
|
3688
|
+
// @ts-ignore
|
|
3514
3689
|
dataType: "number",
|
|
3515
3690
|
ranges: counts
|
|
3516
3691
|
};
|
|
@@ -3580,7 +3755,8 @@ var ProductSelectionRepository = class extends AbstractResourceRepository {
|
|
|
3580
3755
|
...getBaseResourceProperties(),
|
|
3581
3756
|
productCount: 0,
|
|
3582
3757
|
name: draft.name,
|
|
3583
|
-
type: "individual"
|
|
3758
|
+
type: "individual",
|
|
3759
|
+
mode: "Individual"
|
|
3584
3760
|
};
|
|
3585
3761
|
this.saveNew(context, resource);
|
|
3586
3762
|
return resource;
|
|
@@ -3603,7 +3779,6 @@ var ProductTypeRepository = class extends AbstractResourceRepository {
|
|
|
3603
3779
|
attributeName,
|
|
3604
3780
|
newValue
|
|
3605
3781
|
}) => {
|
|
3606
|
-
var _a;
|
|
3607
3782
|
const updateAttributeType = (type) => {
|
|
3608
3783
|
switch (type.name) {
|
|
3609
3784
|
case "lenum":
|
|
@@ -3618,30 +3793,27 @@ var ProductTypeRepository = class extends AbstractResourceRepository {
|
|
|
3618
3793
|
return;
|
|
3619
3794
|
}
|
|
3620
3795
|
};
|
|
3621
|
-
|
|
3796
|
+
resource.attributes?.forEach((value) => {
|
|
3622
3797
|
if (value.name === attributeName) {
|
|
3623
3798
|
updateAttributeType(value.type);
|
|
3624
3799
|
}
|
|
3625
3800
|
});
|
|
3626
3801
|
},
|
|
3627
3802
|
changeLabel: (context, resource, { attributeName, label }) => {
|
|
3628
|
-
|
|
3629
|
-
(_a = resource.attributes) == null ? void 0 : _a.forEach((value) => {
|
|
3803
|
+
resource.attributes?.forEach((value) => {
|
|
3630
3804
|
if (value.name === attributeName) {
|
|
3631
3805
|
value.label = label;
|
|
3632
3806
|
}
|
|
3633
3807
|
});
|
|
3634
3808
|
},
|
|
3635
3809
|
addAttributeDefinition: (context, resource, { attribute }) => {
|
|
3636
|
-
|
|
3637
|
-
(_a = resource.attributes) == null ? void 0 : _a.push(
|
|
3810
|
+
resource.attributes?.push(
|
|
3638
3811
|
this.attributeDefinitionFromAttributeDefinitionDraft(context, attribute)
|
|
3639
3812
|
);
|
|
3640
3813
|
},
|
|
3641
3814
|
changeAttributeOrderByName: (context, resource, { attributeNames }) => {
|
|
3642
|
-
var _a;
|
|
3643
3815
|
const attrs = new Map(
|
|
3644
|
-
|
|
3816
|
+
resource.attributes?.map((item) => [item.name, item])
|
|
3645
3817
|
);
|
|
3646
3818
|
const result = [];
|
|
3647
3819
|
let current = resource.attributes;
|
|
@@ -3651,7 +3823,7 @@ var ProductTypeRepository = class extends AbstractResourceRepository {
|
|
|
3651
3823
|
throw new Error("New attr");
|
|
3652
3824
|
}
|
|
3653
3825
|
result.push(attr);
|
|
3654
|
-
current = current
|
|
3826
|
+
current = current?.filter((f) => f.name !== attrName);
|
|
3655
3827
|
});
|
|
3656
3828
|
resource.attributes = result;
|
|
3657
3829
|
if (current) {
|
|
@@ -3659,12 +3831,10 @@ var ProductTypeRepository = class extends AbstractResourceRepository {
|
|
|
3659
3831
|
}
|
|
3660
3832
|
},
|
|
3661
3833
|
removeAttributeDefinition: (context, resource, { name }) => {
|
|
3662
|
-
|
|
3663
|
-
resource.attributes = (_a = resource.attributes) == null ? void 0 : _a.filter((f) => f.name !== name);
|
|
3834
|
+
resource.attributes = resource.attributes?.filter((f) => f.name !== name);
|
|
3664
3835
|
},
|
|
3665
3836
|
removeEnumValues: (context, resource, { attributeName, keys }) => {
|
|
3666
|
-
|
|
3667
|
-
(_a = resource.attributes) == null ? void 0 : _a.forEach((attr) => {
|
|
3837
|
+
resource.attributes?.forEach((attr) => {
|
|
3668
3838
|
if (attr.name == attributeName) {
|
|
3669
3839
|
if (attr.type.name == "enum") {
|
|
3670
3840
|
attr.type.values = attr.type.values.filter(
|
|
@@ -3723,20 +3893,18 @@ var ProjectRepository = class extends AbstractRepository {
|
|
|
3723
3893
|
resource.messages.deleteDaysAfterCreation = messagesConfiguration.deleteDaysAfterCreation;
|
|
3724
3894
|
},
|
|
3725
3895
|
changeProductSearchIndexingEnabled: (context, resource, { enabled }) => {
|
|
3726
|
-
|
|
3727
|
-
if (!((_a = resource.searchIndexing) == null ? void 0 : _a.products)) {
|
|
3896
|
+
if (!resource.searchIndexing?.products) {
|
|
3728
3897
|
throw new Error("Invalid project state");
|
|
3729
3898
|
}
|
|
3730
3899
|
resource.searchIndexing.products.status = enabled ? "Activated" : "Deactivated";
|
|
3731
|
-
resource.searchIndexing.products.lastModifiedAt = new Date().toISOString();
|
|
3900
|
+
resource.searchIndexing.products.lastModifiedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
3732
3901
|
},
|
|
3733
3902
|
changeOrderSearchStatus: (context, resource, { status }) => {
|
|
3734
|
-
|
|
3735
|
-
if (!((_a = resource.searchIndexing) == null ? void 0 : _a.orders)) {
|
|
3903
|
+
if (!resource.searchIndexing?.orders) {
|
|
3736
3904
|
throw new Error("Invalid project state");
|
|
3737
3905
|
}
|
|
3738
3906
|
resource.searchIndexing.orders.status = status;
|
|
3739
|
-
resource.searchIndexing.orders.lastModifiedAt = new Date().toISOString();
|
|
3907
|
+
resource.searchIndexing.orders.lastModifiedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
3740
3908
|
},
|
|
3741
3909
|
setShippingRateInputType: (context, resource, { shippingRateInputType }) => {
|
|
3742
3910
|
resource.shippingRateInputType = shippingRateInputType;
|
|
@@ -3828,18 +3996,15 @@ import deepEqual3 from "deep-equal";
|
|
|
3828
3996
|
var ShippingMethodRepository = class extends AbstractResourceRepository {
|
|
3829
3997
|
constructor() {
|
|
3830
3998
|
super(...arguments);
|
|
3831
|
-
this._transformZoneRateDraft = (context, draft) => {
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
shippingRates: (_a = draft.shippingRates) == null ? void 0 : _a.map(this._transformShippingRate)
|
|
3841
|
-
};
|
|
3842
|
-
};
|
|
3999
|
+
this._transformZoneRateDraft = (context, draft) => ({
|
|
4000
|
+
...draft,
|
|
4001
|
+
zone: getReferenceFromResourceIdentifier(
|
|
4002
|
+
draft.zone,
|
|
4003
|
+
context.projectKey,
|
|
4004
|
+
this._storage
|
|
4005
|
+
),
|
|
4006
|
+
shippingRates: draft.shippingRates?.map(this._transformShippingRate)
|
|
4007
|
+
});
|
|
3843
4008
|
this._transformShippingRate = (rate) => ({
|
|
3844
4009
|
price: createTypedMoney(rate.price),
|
|
3845
4010
|
freeAbove: rate.freeAbove && createTypedMoney(rate.freeAbove),
|
|
@@ -3939,7 +4104,6 @@ var ShippingMethodRepository = class extends AbstractResourceRepository {
|
|
|
3939
4104
|
return "shipping-method";
|
|
3940
4105
|
}
|
|
3941
4106
|
create(context, draft) {
|
|
3942
|
-
var _a;
|
|
3943
4107
|
const resource = {
|
|
3944
4108
|
...getBaseResourceProperties(),
|
|
3945
4109
|
...draft,
|
|
@@ -3948,7 +4112,7 @@ var ShippingMethodRepository = class extends AbstractResourceRepository {
|
|
|
3948
4112
|
context.projectKey,
|
|
3949
4113
|
this._storage
|
|
3950
4114
|
),
|
|
3951
|
-
zoneRates:
|
|
4115
|
+
zoneRates: draft.zoneRates?.map(
|
|
3952
4116
|
(z) => this._transformZoneRateDraft(context, z)
|
|
3953
4117
|
),
|
|
3954
4118
|
custom: createCustomFields(
|
|
@@ -3968,7 +4132,6 @@ var ShoppingListRepository = class extends AbstractResourceRepository {
|
|
|
3968
4132
|
return "shopping-list";
|
|
3969
4133
|
}
|
|
3970
4134
|
create(context, draft) {
|
|
3971
|
-
var _a, _b;
|
|
3972
4135
|
const resource = {
|
|
3973
4136
|
...getBaseResourceProperties(),
|
|
3974
4137
|
...draft,
|
|
@@ -3978,7 +4141,7 @@ var ShoppingListRepository = class extends AbstractResourceRepository {
|
|
|
3978
4141
|
this._storage
|
|
3979
4142
|
),
|
|
3980
4143
|
textLineItems: [],
|
|
3981
|
-
lineItems:
|
|
4144
|
+
lineItems: draft.lineItems?.map((e) => ({
|
|
3982
4145
|
...getBaseResourceProperties(),
|
|
3983
4146
|
...e,
|
|
3984
4147
|
addedAt: e.addedAt ?? "",
|
|
@@ -3986,14 +4149,18 @@ var ShoppingListRepository = class extends AbstractResourceRepository {
|
|
|
3986
4149
|
name: {},
|
|
3987
4150
|
quantity: e.quantity ?? 1,
|
|
3988
4151
|
productType: { typeId: "product-type", id: "" },
|
|
3989
|
-
custom: createCustomFields(
|
|
3990
|
-
|
|
4152
|
+
custom: createCustomFields(
|
|
4153
|
+
e.custom,
|
|
4154
|
+
context.projectKey,
|
|
4155
|
+
this._storage
|
|
4156
|
+
)
|
|
4157
|
+
})) ?? [],
|
|
3991
4158
|
customer: draft.customer ? getReferenceFromResourceIdentifier(
|
|
3992
4159
|
draft.customer,
|
|
3993
4160
|
context.projectKey,
|
|
3994
4161
|
this._storage
|
|
3995
4162
|
) : void 0,
|
|
3996
|
-
store:
|
|
4163
|
+
store: draft.store ? getStoreKeyReference(draft.store, context.projectKey, this._storage) : void 0
|
|
3997
4164
|
};
|
|
3998
4165
|
this.saveNew(context, resource);
|
|
3999
4166
|
return resource;
|
|
@@ -4034,7 +4201,6 @@ var StandAlonePriceRepository = class extends AbstractResourceRepository {
|
|
|
4034
4201
|
return "standalone-price";
|
|
4035
4202
|
}
|
|
4036
4203
|
create(context, draft) {
|
|
4037
|
-
var _a;
|
|
4038
4204
|
const resource = {
|
|
4039
4205
|
...getBaseResourceProperties(),
|
|
4040
4206
|
active: draft.active ? draft.active : false,
|
|
@@ -4042,7 +4208,7 @@ var StandAlonePriceRepository = class extends AbstractResourceRepository {
|
|
|
4042
4208
|
value: createTypedMoney(draft.value),
|
|
4043
4209
|
country: draft.country,
|
|
4044
4210
|
discounted: draft.discounted ? this.transformDiscountDraft(draft.discounted) : void 0,
|
|
4045
|
-
channel:
|
|
4211
|
+
channel: draft.channel?.id ? this.transformChannelReferenceDraft(draft.channel) : void 0,
|
|
4046
4212
|
validFrom: draft.validFrom,
|
|
4047
4213
|
validUntil: draft.validUntil
|
|
4048
4214
|
};
|
|
@@ -4084,7 +4250,7 @@ var StateRepository = class extends AbstractResourceRepository {
|
|
|
4084
4250
|
resource.roles = roles;
|
|
4085
4251
|
},
|
|
4086
4252
|
setTransitions: (context, resource, { transitions }) => {
|
|
4087
|
-
resource.transitions = transitions
|
|
4253
|
+
resource.transitions = transitions?.map(
|
|
4088
4254
|
(resourceId) => ({
|
|
4089
4255
|
id: resourceId.id || "",
|
|
4090
4256
|
typeId: "state"
|
|
@@ -4160,6 +4326,7 @@ var StoreRepository = class extends AbstractResourceRepository {
|
|
|
4160
4326
|
key: draft.key,
|
|
4161
4327
|
name: draft.name,
|
|
4162
4328
|
languages: draft.languages ?? [],
|
|
4329
|
+
countries: draft.countries ?? [],
|
|
4163
4330
|
distributionChannels: this.transformChannels(
|
|
4164
4331
|
context,
|
|
4165
4332
|
draft.distributionChannels
|
|
@@ -4276,11 +4443,10 @@ var TaxCategoryRepository = class extends AbstractResourceRepository {
|
|
|
4276
4443
|
return "tax-category";
|
|
4277
4444
|
}
|
|
4278
4445
|
create(context, draft) {
|
|
4279
|
-
var _a;
|
|
4280
4446
|
const resource = {
|
|
4281
4447
|
...getBaseResourceProperties(),
|
|
4282
4448
|
...draft,
|
|
4283
|
-
rates:
|
|
4449
|
+
rates: draft.rates?.map(this.taxRateFromTaxRateDraft) || []
|
|
4284
4450
|
};
|
|
4285
4451
|
this.saveNew(context, resource);
|
|
4286
4452
|
return resource;
|
|
@@ -4432,6 +4598,9 @@ var ZoneRepository = class extends AbstractResourceRepository {
|
|
|
4432
4598
|
|
|
4433
4599
|
// src/repositories/index.ts
|
|
4434
4600
|
var createRepositories = (storage) => ({
|
|
4601
|
+
"associate-role": new AssociateRoleRepository(storage),
|
|
4602
|
+
"attribute-group": new AttributeGroupRepository(storage),
|
|
4603
|
+
"business-unit": new BusinessUnitRepository(storage),
|
|
4435
4604
|
category: new CategoryRepository(storage),
|
|
4436
4605
|
cart: new CartRepository(storage),
|
|
4437
4606
|
"cart-discount": new CartDiscountRepository(storage),
|
|
@@ -4609,6 +4778,7 @@ var AbstractService = class {
|
|
|
4609
4778
|
);
|
|
4610
4779
|
return result;
|
|
4611
4780
|
}
|
|
4781
|
+
// No idea what i'm doing
|
|
4612
4782
|
_parseParam(value) {
|
|
4613
4783
|
if (Array.isArray(value)) {
|
|
4614
4784
|
return value;
|
|
@@ -4643,6 +4813,7 @@ var CartService = class extends AbstractService {
|
|
|
4643
4813
|
currency: cartOrOrder.totalPrice.currencyCode,
|
|
4644
4814
|
discountCodes: [],
|
|
4645
4815
|
shipping: [],
|
|
4816
|
+
// TODO: cartOrOrder.shipping,
|
|
4646
4817
|
lineItems: cartOrOrder.lineItems.map((lineItem) => ({
|
|
4647
4818
|
...lineItem,
|
|
4648
4819
|
variantId: lineItem.variant.id,
|
|
@@ -4753,7 +4924,10 @@ var CustomerService = class extends AbstractService {
|
|
|
4753
4924
|
const customer = this.repository.query(getRepositoryContext(request), {
|
|
4754
4925
|
where: [`email="${request.body.email}"`]
|
|
4755
4926
|
});
|
|
4756
|
-
const ttlMinutes = request.params.ttlMinutes ?
|
|
4927
|
+
const ttlMinutes = request.params.ttlMinutes ? (
|
|
4928
|
+
// @ts-ignore
|
|
4929
|
+
+request.params.ttlMinutes
|
|
4930
|
+
) : 34560;
|
|
4757
4931
|
const { version, ...rest } = getBaseResourceProperties();
|
|
4758
4932
|
return response.status(200).send({
|
|
4759
4933
|
...rest,
|
|
@@ -5208,10 +5382,9 @@ var CommercetoolsMock = class {
|
|
|
5208
5382
|
this.mockApiHost();
|
|
5209
5383
|
}
|
|
5210
5384
|
stop() {
|
|
5211
|
-
|
|
5212
|
-
(_a = this._nockScopes.auth) == null ? void 0 : _a.persist(false);
|
|
5385
|
+
this._nockScopes.auth?.persist(false);
|
|
5213
5386
|
this._nockScopes.auth = void 0;
|
|
5214
|
-
|
|
5387
|
+
this._nockScopes.api?.persist(false);
|
|
5215
5388
|
this._nockScopes.api = void 0;
|
|
5216
5389
|
}
|
|
5217
5390
|
clear() {
|
|
@@ -5241,7 +5414,7 @@ var CommercetoolsMock = class {
|
|
|
5241
5414
|
const app = express2();
|
|
5242
5415
|
const projectRouter = express2.Router({ mergeParams: true });
|
|
5243
5416
|
projectRouter.use(express2.json());
|
|
5244
|
-
if (!
|
|
5417
|
+
if (!options?.silent) {
|
|
5245
5418
|
app.use(morgan("tiny"));
|
|
5246
5419
|
}
|
|
5247
5420
|
app.use("/oauth", this._oauth2.createRouter());
|