@labdigital/commercetools-mock 2.14.2 → 2.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +364 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -15
- package/dist/index.d.ts +19 -15
- package/dist/index.js +364 -34
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/repositories/customer.ts +13 -0
- package/src/repositories/payment.ts +148 -25
- package/src/repositories/shopping-list.ts +347 -16
- package/src/services/cart.test.ts +2 -2
- package/src/services/customer.test.ts +40 -0
- package/src/services/shopping-list.test.ts +352 -0
- package/src/storage/in-memory.ts +40 -2
package/dist/index.cjs
CHANGED
|
@@ -1238,6 +1238,16 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
1238
1238
|
};
|
|
1239
1239
|
_resolveResource = (projectKey, obj, expand) => {
|
|
1240
1240
|
const params = parseExpandClause(expand);
|
|
1241
|
+
if (params.index === "*") {
|
|
1242
|
+
const reference = obj[params.element];
|
|
1243
|
+
if (params.element === "lineItems" && params.rest?.startsWith("variant") && reference.every(
|
|
1244
|
+
(item) => item.variant === void 0 && item.variantId !== void 0
|
|
1245
|
+
)) {
|
|
1246
|
+
reference.forEach((item) => {
|
|
1247
|
+
this._resolveShoppingListLineItemVariant(projectKey, item);
|
|
1248
|
+
});
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1241
1251
|
if (!params.index) {
|
|
1242
1252
|
const reference = obj[params.element];
|
|
1243
1253
|
if (reference === void 0) {
|
|
@@ -1278,6 +1288,20 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
1278
1288
|
}
|
|
1279
1289
|
}
|
|
1280
1290
|
}
|
|
1291
|
+
_resolveShoppingListLineItemVariant(projectKey, lineItem) {
|
|
1292
|
+
const product = this.getByResourceIdentifier(projectKey, {
|
|
1293
|
+
typeId: "product",
|
|
1294
|
+
id: lineItem.productId
|
|
1295
|
+
});
|
|
1296
|
+
if (!product) {
|
|
1297
|
+
return;
|
|
1298
|
+
}
|
|
1299
|
+
const variant = [
|
|
1300
|
+
product.masterData.current.masterVariant,
|
|
1301
|
+
...product.masterData.current.variants
|
|
1302
|
+
].find((e) => e.id === lineItem.variantId);
|
|
1303
|
+
lineItem.variant = variant;
|
|
1304
|
+
}
|
|
1281
1305
|
};
|
|
1282
1306
|
|
|
1283
1307
|
// src/oauth/server.ts
|
|
@@ -3263,6 +3287,14 @@ var CustomerRepository = class extends AbstractResourceRepository {
|
|
|
3263
3287
|
throw new Error("Resource has no custom field");
|
|
3264
3288
|
}
|
|
3265
3289
|
resource.custom.fields[name] = value;
|
|
3290
|
+
},
|
|
3291
|
+
setCustomerNumber: (_context, resource, { customerNumber }) => {
|
|
3292
|
+
if (resource.customerNumber) {
|
|
3293
|
+
throw new Error(
|
|
3294
|
+
"A Customer number already exists and cannot be set again."
|
|
3295
|
+
);
|
|
3296
|
+
}
|
|
3297
|
+
resource.customerNumber = customerNumber;
|
|
3266
3298
|
}
|
|
3267
3299
|
};
|
|
3268
3300
|
};
|
|
@@ -3979,12 +4011,31 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
3979
4011
|
// Documented as default
|
|
3980
4012
|
});
|
|
3981
4013
|
actions = {
|
|
4014
|
+
addInterfaceInteraction: (context, resource, { type, fields }) => {
|
|
4015
|
+
resource.interfaceInteractions.push(
|
|
4016
|
+
createCustomFields({ type, fields }, context.projectKey, this._storage)
|
|
4017
|
+
);
|
|
4018
|
+
},
|
|
3982
4019
|
addTransaction: (context, resource, { transaction }) => {
|
|
3983
4020
|
resource.transactions = [
|
|
3984
4021
|
...resource.transactions,
|
|
3985
4022
|
this.transactionFromTransactionDraft(transaction, context)
|
|
3986
4023
|
];
|
|
3987
4024
|
},
|
|
4025
|
+
changeAmountPlanned: (_context, resource, { amount }) => {
|
|
4026
|
+
resource.amountPlanned = createCentPrecisionMoney(amount);
|
|
4027
|
+
},
|
|
4028
|
+
changeTransactionInteractionId: (_context, resource, {
|
|
4029
|
+
transactionId,
|
|
4030
|
+
interactionId
|
|
4031
|
+
}) => {
|
|
4032
|
+
const transaction = resource.transactions.find(
|
|
4033
|
+
(e) => e.id === transactionId
|
|
4034
|
+
);
|
|
4035
|
+
if (transaction) {
|
|
4036
|
+
transaction.interactionId = interactionId;
|
|
4037
|
+
}
|
|
4038
|
+
},
|
|
3988
4039
|
changeTransactionState: (_context, resource, { transactionId, state }) => {
|
|
3989
4040
|
const index = resource.transactions.findIndex(
|
|
3990
4041
|
(e) => e.id === transactionId
|
|
@@ -3995,6 +4046,14 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
3995
4046
|
};
|
|
3996
4047
|
resource.transactions[index] = updatedTransaction;
|
|
3997
4048
|
},
|
|
4049
|
+
changeTransactionTimestamp: (_context, resource, { transactionId, timestamp }) => {
|
|
4050
|
+
const transaction = resource.transactions.find(
|
|
4051
|
+
(e) => e.id === transactionId
|
|
4052
|
+
);
|
|
4053
|
+
if (transaction) {
|
|
4054
|
+
transaction.timestamp = timestamp;
|
|
4055
|
+
}
|
|
4056
|
+
},
|
|
3998
4057
|
transitionState: (context, resource, { state }) => {
|
|
3999
4058
|
const stateObj = this._storage.getByResourceIdentifier(
|
|
4000
4059
|
context.projectKey,
|
|
@@ -4009,6 +4068,21 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
4009
4068
|
obj: stateObj
|
|
4010
4069
|
};
|
|
4011
4070
|
},
|
|
4071
|
+
setAnonymousId: (_context, resource, { anonymousId }) => {
|
|
4072
|
+
resource.anonymousId = anonymousId;
|
|
4073
|
+
resource.customer = void 0;
|
|
4074
|
+
},
|
|
4075
|
+
setCustomer: (_context, resource, { customer }) => {
|
|
4076
|
+
if (customer) {
|
|
4077
|
+
const c = getReferenceFromResourceIdentifier(
|
|
4078
|
+
customer,
|
|
4079
|
+
_context.projectKey,
|
|
4080
|
+
this._storage
|
|
4081
|
+
);
|
|
4082
|
+
resource.customer = c;
|
|
4083
|
+
resource.anonymousId = void 0;
|
|
4084
|
+
}
|
|
4085
|
+
},
|
|
4012
4086
|
setCustomField: (context, resource, { name, value }) => {
|
|
4013
4087
|
if (!resource.custom) {
|
|
4014
4088
|
throw new Error("Resource has no custom field");
|
|
@@ -4035,33 +4109,63 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
4035
4109
|
};
|
|
4036
4110
|
}
|
|
4037
4111
|
},
|
|
4112
|
+
setInterfaceId: (_context, resource, { interfaceId }) => {
|
|
4113
|
+
resource.interfaceId = interfaceId;
|
|
4114
|
+
},
|
|
4038
4115
|
setKey: (_context, resource, { key }) => {
|
|
4039
4116
|
resource.key = key;
|
|
4040
4117
|
},
|
|
4041
|
-
|
|
4042
|
-
resource.
|
|
4043
|
-
},
|
|
4044
|
-
setStatusInterfaceText: (_context, resource, { interfaceText }) => {
|
|
4045
|
-
resource.paymentStatus.interfaceText = interfaceText;
|
|
4118
|
+
setMethodInfoMethod: (_context, resource, { method }) => {
|
|
4119
|
+
resource.paymentMethodInfo.method = method;
|
|
4046
4120
|
},
|
|
4047
4121
|
setMethodInfoName: (_context, resource, { name }) => {
|
|
4048
4122
|
resource.paymentMethodInfo.name = name;
|
|
4049
4123
|
},
|
|
4050
|
-
setMethodInfoMethod: (_context, resource, { method }) => {
|
|
4051
|
-
resource.paymentMethodInfo.method = method;
|
|
4052
|
-
},
|
|
4053
4124
|
setMethodInfoInterface: (_context, resource, args) => {
|
|
4054
4125
|
resource.paymentMethodInfo.paymentInterface = args.interface;
|
|
4055
4126
|
},
|
|
4056
|
-
|
|
4057
|
-
resource.
|
|
4127
|
+
setStatusInterfaceCode: (_context, resource, { interfaceCode }) => {
|
|
4128
|
+
resource.paymentStatus.interfaceCode = interfaceCode;
|
|
4129
|
+
},
|
|
4130
|
+
setStatusInterfaceText: (_context, resource, { interfaceText }) => {
|
|
4131
|
+
resource.paymentStatus.interfaceText = interfaceText;
|
|
4132
|
+
},
|
|
4133
|
+
setTransactionCustomField: (_context, resource, { transactionId, name, value }) => {
|
|
4134
|
+
const transaction = resource.transactions.find(
|
|
4135
|
+
(e) => e.id === transactionId
|
|
4136
|
+
);
|
|
4137
|
+
if (transaction) {
|
|
4138
|
+
if (!transaction.custom) {
|
|
4139
|
+
throw new Error("Transaction has no custom field");
|
|
4140
|
+
}
|
|
4141
|
+
transaction.custom.fields[name] = value;
|
|
4142
|
+
}
|
|
4143
|
+
},
|
|
4144
|
+
setTransactionCustomType: (context, resource, { transactionId, type, fields }) => {
|
|
4145
|
+
const transaction = resource.transactions.find(
|
|
4146
|
+
(e) => e.id === transactionId
|
|
4147
|
+
);
|
|
4148
|
+
if (transaction) {
|
|
4149
|
+
if (!type) {
|
|
4150
|
+
transaction.custom = void 0;
|
|
4151
|
+
} else {
|
|
4152
|
+
const resolvedType = this._storage.getByResourceIdentifier(
|
|
4153
|
+
context.projectKey,
|
|
4154
|
+
type
|
|
4155
|
+
);
|
|
4156
|
+
if (!resolvedType) {
|
|
4157
|
+
throw new Error(`Type ${type} not found`);
|
|
4158
|
+
}
|
|
4159
|
+
transaction.custom = {
|
|
4160
|
+
type: {
|
|
4161
|
+
typeId: "type",
|
|
4162
|
+
id: resolvedType.id
|
|
4163
|
+
},
|
|
4164
|
+
fields: fields ?? {}
|
|
4165
|
+
};
|
|
4166
|
+
}
|
|
4167
|
+
}
|
|
4058
4168
|
}
|
|
4059
|
-
// addInterfaceInteraction: () => {},
|
|
4060
|
-
// changeAmountPlanned: () => {},
|
|
4061
|
-
// changeTransactionInteractionId: () => {},
|
|
4062
|
-
// changeTransactionTimestamp: () => {},
|
|
4063
|
-
// setAnonymousId: () => {},
|
|
4064
|
-
// setCustomer: () => {},
|
|
4065
4169
|
};
|
|
4066
4170
|
};
|
|
4067
4171
|
|
|
@@ -5958,11 +6062,15 @@ var ShippingMethodRepository = class extends AbstractResourceRepository {
|
|
|
5958
6062
|
};
|
|
5959
6063
|
|
|
5960
6064
|
// src/repositories/shopping-list.ts
|
|
6065
|
+
var import_uuid8 = require("uuid");
|
|
5961
6066
|
var ShoppingListRepository = class extends AbstractResourceRepository {
|
|
5962
6067
|
getTypeId() {
|
|
5963
6068
|
return "shopping-list";
|
|
5964
6069
|
}
|
|
5965
6070
|
create(context, draft) {
|
|
6071
|
+
const lineItems = draft.lineItems?.map(
|
|
6072
|
+
(draftLineItem) => this.draftLineItemtoLineItem(context.projectKey, draftLineItem)
|
|
6073
|
+
) ?? [];
|
|
5966
6074
|
const resource = {
|
|
5967
6075
|
...getBaseResourceProperties(),
|
|
5968
6076
|
...draft,
|
|
@@ -5972,20 +6080,7 @@ var ShoppingListRepository = class extends AbstractResourceRepository {
|
|
|
5972
6080
|
this._storage
|
|
5973
6081
|
),
|
|
5974
6082
|
textLineItems: [],
|
|
5975
|
-
lineItems
|
|
5976
|
-
...getBaseResourceProperties(),
|
|
5977
|
-
...e,
|
|
5978
|
-
addedAt: e.addedAt ?? "",
|
|
5979
|
-
productId: e.productId ?? "",
|
|
5980
|
-
name: {},
|
|
5981
|
-
quantity: e.quantity ?? 1,
|
|
5982
|
-
productType: { typeId: "product-type", id: "" },
|
|
5983
|
-
custom: createCustomFields(
|
|
5984
|
-
e.custom,
|
|
5985
|
-
context.projectKey,
|
|
5986
|
-
this._storage
|
|
5987
|
-
)
|
|
5988
|
-
})) ?? [],
|
|
6083
|
+
lineItems,
|
|
5989
6084
|
customer: draft.customer ? getReferenceFromResourceIdentifier(
|
|
5990
6085
|
draft.customer,
|
|
5991
6086
|
context.projectKey,
|
|
@@ -5996,6 +6091,241 @@ var ShoppingListRepository = class extends AbstractResourceRepository {
|
|
|
5996
6091
|
this.saveNew(context, resource);
|
|
5997
6092
|
return resource;
|
|
5998
6093
|
}
|
|
6094
|
+
actions = {
|
|
6095
|
+
setKey: (context, resource, { key }) => {
|
|
6096
|
+
resource.key = key;
|
|
6097
|
+
},
|
|
6098
|
+
setSlug: (context, resource, { slug }) => {
|
|
6099
|
+
resource.slug = slug;
|
|
6100
|
+
},
|
|
6101
|
+
changeName: (context, resource, { name }) => {
|
|
6102
|
+
resource.name = name;
|
|
6103
|
+
},
|
|
6104
|
+
setDescription: (context, resource, { description }) => {
|
|
6105
|
+
resource.description = description;
|
|
6106
|
+
},
|
|
6107
|
+
setCustomer: (context, resource, { customer }) => {
|
|
6108
|
+
if (customer?.key) {
|
|
6109
|
+
throw new Error("set customer on shoppinglist by key not implemented");
|
|
6110
|
+
}
|
|
6111
|
+
if (customer?.id) {
|
|
6112
|
+
resource.customer = { typeId: "customer", id: customer.id };
|
|
6113
|
+
}
|
|
6114
|
+
},
|
|
6115
|
+
setStore: (context, resource, { store }) => {
|
|
6116
|
+
if (store?.key) {
|
|
6117
|
+
resource.store = { typeId: "store", key: store.key };
|
|
6118
|
+
}
|
|
6119
|
+
if (store?.id) {
|
|
6120
|
+
throw new Error("set store on shoppinglist by id not implemented");
|
|
6121
|
+
}
|
|
6122
|
+
},
|
|
6123
|
+
setAnonymousId: (context, resource, { anonymousId }) => {
|
|
6124
|
+
resource.anonymousId = anonymousId;
|
|
6125
|
+
},
|
|
6126
|
+
setCustomType: (context, resource, { type, fields }) => {
|
|
6127
|
+
if (!type) {
|
|
6128
|
+
resource.custom = void 0;
|
|
6129
|
+
} else {
|
|
6130
|
+
const resolvedType = this._storage.getByResourceIdentifier(
|
|
6131
|
+
context.projectKey,
|
|
6132
|
+
type
|
|
6133
|
+
);
|
|
6134
|
+
if (!resolvedType) {
|
|
6135
|
+
throw new Error(`Type ${type} not found`);
|
|
6136
|
+
}
|
|
6137
|
+
resource.custom = {
|
|
6138
|
+
type: {
|
|
6139
|
+
typeId: "type",
|
|
6140
|
+
id: resolvedType.id
|
|
6141
|
+
},
|
|
6142
|
+
fields: fields || {}
|
|
6143
|
+
};
|
|
6144
|
+
}
|
|
6145
|
+
},
|
|
6146
|
+
setCustomField: (context, resource, { name, value }) => {
|
|
6147
|
+
if (!resource.custom) {
|
|
6148
|
+
throw new Error("Resource has no custom field");
|
|
6149
|
+
}
|
|
6150
|
+
resource.custom.fields[name] = value;
|
|
6151
|
+
},
|
|
6152
|
+
setDeleteDaysAfterLastModification: (context, resource, {
|
|
6153
|
+
deleteDaysAfterLastModification
|
|
6154
|
+
}) => {
|
|
6155
|
+
resource.deleteDaysAfterLastModification = deleteDaysAfterLastModification;
|
|
6156
|
+
},
|
|
6157
|
+
addLineItem: (context, resource, { productId, variantId, sku, quantity = 1 }) => {
|
|
6158
|
+
let product = null;
|
|
6159
|
+
if (productId) {
|
|
6160
|
+
product = this._storage.get(
|
|
6161
|
+
context.projectKey,
|
|
6162
|
+
"product",
|
|
6163
|
+
productId,
|
|
6164
|
+
{}
|
|
6165
|
+
);
|
|
6166
|
+
} else if (sku) {
|
|
6167
|
+
const items = this._storage.query(context.projectKey, "product", {
|
|
6168
|
+
where: [
|
|
6169
|
+
`masterData(current(masterVariant(sku="${sku}"))) or masterData(current(variants(sku="${sku}")))`
|
|
6170
|
+
]
|
|
6171
|
+
});
|
|
6172
|
+
if (items.count === 1) {
|
|
6173
|
+
product = items.results[0];
|
|
6174
|
+
}
|
|
6175
|
+
}
|
|
6176
|
+
if (!product) {
|
|
6177
|
+
throw new CommercetoolsError({
|
|
6178
|
+
code: "General",
|
|
6179
|
+
message: sku ? `A product containing a variant with SKU '${sku}' not found.` : `A product with ID '${productId}' not found.`
|
|
6180
|
+
});
|
|
6181
|
+
}
|
|
6182
|
+
let varId = variantId;
|
|
6183
|
+
if (sku) {
|
|
6184
|
+
varId = [
|
|
6185
|
+
product.masterData.current.masterVariant,
|
|
6186
|
+
...product.masterData.current.variants
|
|
6187
|
+
].find((x) => x.sku === sku)?.id;
|
|
6188
|
+
}
|
|
6189
|
+
if (!varId) {
|
|
6190
|
+
varId = product.masterData.current.masterVariant.id;
|
|
6191
|
+
}
|
|
6192
|
+
const alreadyAdded = resource.lineItems.some(
|
|
6193
|
+
(x) => x.productId === product?.id && x.variantId === varId
|
|
6194
|
+
);
|
|
6195
|
+
if (alreadyAdded) {
|
|
6196
|
+
resource.lineItems.forEach((x) => {
|
|
6197
|
+
if (x.productId === product?.id && x.variantId === varId) {
|
|
6198
|
+
x.quantity += quantity;
|
|
6199
|
+
}
|
|
6200
|
+
});
|
|
6201
|
+
} else {
|
|
6202
|
+
resource.lineItems.push({
|
|
6203
|
+
addedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
6204
|
+
id: (0, import_uuid8.v4)(),
|
|
6205
|
+
productId: product.id,
|
|
6206
|
+
productSlug: product.masterData.current.slug,
|
|
6207
|
+
productType: product.productType,
|
|
6208
|
+
name: product.masterData.current.name,
|
|
6209
|
+
variantId: varId,
|
|
6210
|
+
quantity
|
|
6211
|
+
});
|
|
6212
|
+
}
|
|
6213
|
+
},
|
|
6214
|
+
removeLineItem: (context, resource, { lineItemId, quantity }) => {
|
|
6215
|
+
const lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
6216
|
+
if (!lineItem) {
|
|
6217
|
+
throw new CommercetoolsError({
|
|
6218
|
+
code: "General",
|
|
6219
|
+
message: `A line item with ID '${lineItemId}' not found.`
|
|
6220
|
+
});
|
|
6221
|
+
}
|
|
6222
|
+
const shouldDelete = !quantity || quantity >= lineItem.quantity;
|
|
6223
|
+
if (shouldDelete) {
|
|
6224
|
+
resource.lineItems = resource.lineItems.filter(
|
|
6225
|
+
(x) => x.id !== lineItemId
|
|
6226
|
+
);
|
|
6227
|
+
} else {
|
|
6228
|
+
resource.lineItems.forEach((x) => {
|
|
6229
|
+
if (x.id === lineItemId && quantity) {
|
|
6230
|
+
x.quantity -= quantity;
|
|
6231
|
+
}
|
|
6232
|
+
});
|
|
6233
|
+
}
|
|
6234
|
+
},
|
|
6235
|
+
changeLineItemQuantity: (context, resource, {
|
|
6236
|
+
lineItemId,
|
|
6237
|
+
lineItemKey,
|
|
6238
|
+
quantity
|
|
6239
|
+
}) => {
|
|
6240
|
+
let lineItem;
|
|
6241
|
+
if (lineItemId) {
|
|
6242
|
+
lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
6243
|
+
if (!lineItem) {
|
|
6244
|
+
throw new CommercetoolsError({
|
|
6245
|
+
code: "General",
|
|
6246
|
+
message: `A line item with ID '${lineItemId}' not found.`
|
|
6247
|
+
});
|
|
6248
|
+
}
|
|
6249
|
+
} else if (lineItemKey) {
|
|
6250
|
+
lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
6251
|
+
if (!lineItem) {
|
|
6252
|
+
throw new CommercetoolsError({
|
|
6253
|
+
code: "General",
|
|
6254
|
+
message: `A line item with Key '${lineItemKey}' not found.`
|
|
6255
|
+
});
|
|
6256
|
+
}
|
|
6257
|
+
} else {
|
|
6258
|
+
throw new CommercetoolsError({
|
|
6259
|
+
code: "General",
|
|
6260
|
+
message: `Either lineItemid or lineItemKey needs to be provided.`
|
|
6261
|
+
});
|
|
6262
|
+
}
|
|
6263
|
+
if (quantity === 0) {
|
|
6264
|
+
resource.lineItems = resource.lineItems.filter(
|
|
6265
|
+
(x) => x.id !== lineItemId
|
|
6266
|
+
);
|
|
6267
|
+
} else {
|
|
6268
|
+
resource.lineItems.forEach((x) => {
|
|
6269
|
+
if (x.id === lineItemId && quantity) {
|
|
6270
|
+
x.quantity = quantity;
|
|
6271
|
+
}
|
|
6272
|
+
});
|
|
6273
|
+
}
|
|
6274
|
+
}
|
|
6275
|
+
};
|
|
6276
|
+
draftLineItemtoLineItem = (projectKey, draftLineItem) => {
|
|
6277
|
+
const { sku, productId, variantId } = draftLineItem;
|
|
6278
|
+
const lineItem = {
|
|
6279
|
+
...getBaseResourceProperties(),
|
|
6280
|
+
...draftLineItem,
|
|
6281
|
+
addedAt: draftLineItem.addedAt ?? "",
|
|
6282
|
+
productId: draftLineItem.productId ?? "",
|
|
6283
|
+
name: {},
|
|
6284
|
+
variantId,
|
|
6285
|
+
quantity: draftLineItem.quantity ?? 1,
|
|
6286
|
+
productType: { typeId: "product-type", id: "" },
|
|
6287
|
+
custom: createCustomFields(
|
|
6288
|
+
draftLineItem.custom,
|
|
6289
|
+
projectKey,
|
|
6290
|
+
this._storage
|
|
6291
|
+
)
|
|
6292
|
+
};
|
|
6293
|
+
if (variantId) {
|
|
6294
|
+
return lineItem;
|
|
6295
|
+
}
|
|
6296
|
+
if (sku) {
|
|
6297
|
+
const items = this._storage.query(projectKey, "product", {
|
|
6298
|
+
where: [
|
|
6299
|
+
`masterData(current(masterVariant(sku="${sku}"))) or masterData(current(variants(sku="${sku}")))`
|
|
6300
|
+
]
|
|
6301
|
+
});
|
|
6302
|
+
if (items.count === 0) {
|
|
6303
|
+
throw new Error(`Product with sku ${sku} not found`);
|
|
6304
|
+
}
|
|
6305
|
+
const product = items.results[0];
|
|
6306
|
+
const allVariants = [
|
|
6307
|
+
product.masterData.current.masterVariant,
|
|
6308
|
+
...product.masterData.current.variants
|
|
6309
|
+
];
|
|
6310
|
+
const variantId2 = allVariants.find((e) => e.sku === sku)?.id;
|
|
6311
|
+
lineItem.variantId = variantId2;
|
|
6312
|
+
return lineItem;
|
|
6313
|
+
}
|
|
6314
|
+
if (productId) {
|
|
6315
|
+
const items = this._storage.query(projectKey, "product", {
|
|
6316
|
+
where: [`id="${productId}"`]
|
|
6317
|
+
});
|
|
6318
|
+
if (items.count === 0) {
|
|
6319
|
+
throw new Error(`Product with id ${productId} not found`);
|
|
6320
|
+
}
|
|
6321
|
+
const variantId2 = items.results[0].masterData.current.masterVariant.id;
|
|
6322
|
+
lineItem.variantId = variantId2;
|
|
6323
|
+
return lineItem;
|
|
6324
|
+
}
|
|
6325
|
+
throw new Error(
|
|
6326
|
+
`must provide either sku, productId or variantId for ShoppingListLineItem`
|
|
6327
|
+
);
|
|
6328
|
+
};
|
|
5999
6329
|
};
|
|
6000
6330
|
|
|
6001
6331
|
// src/repositories/staged-quote.ts
|
|
@@ -6214,7 +6544,7 @@ var SubscriptionRepository = class extends AbstractResourceRepository {
|
|
|
6214
6544
|
};
|
|
6215
6545
|
|
|
6216
6546
|
// src/repositories/tax-category.ts
|
|
6217
|
-
var
|
|
6547
|
+
var import_uuid9 = require("uuid");
|
|
6218
6548
|
var TaxCategoryRepository = class extends AbstractResourceRepository {
|
|
6219
6549
|
getTypeId() {
|
|
6220
6550
|
return "tax-category";
|
|
@@ -6230,7 +6560,7 @@ var TaxCategoryRepository = class extends AbstractResourceRepository {
|
|
|
6230
6560
|
}
|
|
6231
6561
|
taxRateFromTaxRateDraft = (draft) => ({
|
|
6232
6562
|
...draft,
|
|
6233
|
-
id: (0,
|
|
6563
|
+
id: (0, import_uuid9.v4)(),
|
|
6234
6564
|
amount: draft.amount || 0
|
|
6235
6565
|
});
|
|
6236
6566
|
actions = {
|
|
@@ -6789,7 +7119,7 @@ var CustomerGroupService = class extends AbstractService {
|
|
|
6789
7119
|
};
|
|
6790
7120
|
|
|
6791
7121
|
// src/services/customer.ts
|
|
6792
|
-
var
|
|
7122
|
+
var import_uuid10 = require("uuid");
|
|
6793
7123
|
var CustomerService = class extends AbstractService {
|
|
6794
7124
|
repository;
|
|
6795
7125
|
constructor(parent, repository) {
|
|
@@ -6813,7 +7143,7 @@ var CustomerService = class extends AbstractService {
|
|
|
6813
7143
|
...rest,
|
|
6814
7144
|
customerId: customer.results[0].id,
|
|
6815
7145
|
expiresAt: new Date(Date.now() + ttlMinutes * 60).toISOString(),
|
|
6816
|
-
value: (0,
|
|
7146
|
+
value: (0, import_uuid10.v4)()
|
|
6817
7147
|
});
|
|
6818
7148
|
});
|
|
6819
7149
|
}
|