@labdigital/commercetools-mock 2.14.2 → 2.15.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 +356 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -15
- package/dist/index.d.ts +18 -15
- package/dist/index.js +356 -34
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- 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/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
|
|
@@ -3979,12 +4003,31 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
3979
4003
|
// Documented as default
|
|
3980
4004
|
});
|
|
3981
4005
|
actions = {
|
|
4006
|
+
addInterfaceInteraction: (context, resource, { type, fields }) => {
|
|
4007
|
+
resource.interfaceInteractions.push(
|
|
4008
|
+
createCustomFields({ type, fields }, context.projectKey, this._storage)
|
|
4009
|
+
);
|
|
4010
|
+
},
|
|
3982
4011
|
addTransaction: (context, resource, { transaction }) => {
|
|
3983
4012
|
resource.transactions = [
|
|
3984
4013
|
...resource.transactions,
|
|
3985
4014
|
this.transactionFromTransactionDraft(transaction, context)
|
|
3986
4015
|
];
|
|
3987
4016
|
},
|
|
4017
|
+
changeAmountPlanned: (_context, resource, { amount }) => {
|
|
4018
|
+
resource.amountPlanned = createCentPrecisionMoney(amount);
|
|
4019
|
+
},
|
|
4020
|
+
changeTransactionInteractionId: (_context, resource, {
|
|
4021
|
+
transactionId,
|
|
4022
|
+
interactionId
|
|
4023
|
+
}) => {
|
|
4024
|
+
const transaction = resource.transactions.find(
|
|
4025
|
+
(e) => e.id === transactionId
|
|
4026
|
+
);
|
|
4027
|
+
if (transaction) {
|
|
4028
|
+
transaction.interactionId = interactionId;
|
|
4029
|
+
}
|
|
4030
|
+
},
|
|
3988
4031
|
changeTransactionState: (_context, resource, { transactionId, state }) => {
|
|
3989
4032
|
const index = resource.transactions.findIndex(
|
|
3990
4033
|
(e) => e.id === transactionId
|
|
@@ -3995,6 +4038,14 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
3995
4038
|
};
|
|
3996
4039
|
resource.transactions[index] = updatedTransaction;
|
|
3997
4040
|
},
|
|
4041
|
+
changeTransactionTimestamp: (_context, resource, { transactionId, timestamp }) => {
|
|
4042
|
+
const transaction = resource.transactions.find(
|
|
4043
|
+
(e) => e.id === transactionId
|
|
4044
|
+
);
|
|
4045
|
+
if (transaction) {
|
|
4046
|
+
transaction.timestamp = timestamp;
|
|
4047
|
+
}
|
|
4048
|
+
},
|
|
3998
4049
|
transitionState: (context, resource, { state }) => {
|
|
3999
4050
|
const stateObj = this._storage.getByResourceIdentifier(
|
|
4000
4051
|
context.projectKey,
|
|
@@ -4009,6 +4060,21 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
4009
4060
|
obj: stateObj
|
|
4010
4061
|
};
|
|
4011
4062
|
},
|
|
4063
|
+
setAnonymousId: (_context, resource, { anonymousId }) => {
|
|
4064
|
+
resource.anonymousId = anonymousId;
|
|
4065
|
+
resource.customer = void 0;
|
|
4066
|
+
},
|
|
4067
|
+
setCustomer: (_context, resource, { customer }) => {
|
|
4068
|
+
if (customer) {
|
|
4069
|
+
const c = getReferenceFromResourceIdentifier(
|
|
4070
|
+
customer,
|
|
4071
|
+
_context.projectKey,
|
|
4072
|
+
this._storage
|
|
4073
|
+
);
|
|
4074
|
+
resource.customer = c;
|
|
4075
|
+
resource.anonymousId = void 0;
|
|
4076
|
+
}
|
|
4077
|
+
},
|
|
4012
4078
|
setCustomField: (context, resource, { name, value }) => {
|
|
4013
4079
|
if (!resource.custom) {
|
|
4014
4080
|
throw new Error("Resource has no custom field");
|
|
@@ -4035,33 +4101,63 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
4035
4101
|
};
|
|
4036
4102
|
}
|
|
4037
4103
|
},
|
|
4104
|
+
setInterfaceId: (_context, resource, { interfaceId }) => {
|
|
4105
|
+
resource.interfaceId = interfaceId;
|
|
4106
|
+
},
|
|
4038
4107
|
setKey: (_context, resource, { key }) => {
|
|
4039
4108
|
resource.key = key;
|
|
4040
4109
|
},
|
|
4041
|
-
|
|
4042
|
-
resource.
|
|
4043
|
-
},
|
|
4044
|
-
setStatusInterfaceText: (_context, resource, { interfaceText }) => {
|
|
4045
|
-
resource.paymentStatus.interfaceText = interfaceText;
|
|
4110
|
+
setMethodInfoMethod: (_context, resource, { method }) => {
|
|
4111
|
+
resource.paymentMethodInfo.method = method;
|
|
4046
4112
|
},
|
|
4047
4113
|
setMethodInfoName: (_context, resource, { name }) => {
|
|
4048
4114
|
resource.paymentMethodInfo.name = name;
|
|
4049
4115
|
},
|
|
4050
|
-
setMethodInfoMethod: (_context, resource, { method }) => {
|
|
4051
|
-
resource.paymentMethodInfo.method = method;
|
|
4052
|
-
},
|
|
4053
4116
|
setMethodInfoInterface: (_context, resource, args) => {
|
|
4054
4117
|
resource.paymentMethodInfo.paymentInterface = args.interface;
|
|
4055
4118
|
},
|
|
4056
|
-
|
|
4057
|
-
resource.
|
|
4119
|
+
setStatusInterfaceCode: (_context, resource, { interfaceCode }) => {
|
|
4120
|
+
resource.paymentStatus.interfaceCode = interfaceCode;
|
|
4121
|
+
},
|
|
4122
|
+
setStatusInterfaceText: (_context, resource, { interfaceText }) => {
|
|
4123
|
+
resource.paymentStatus.interfaceText = interfaceText;
|
|
4124
|
+
},
|
|
4125
|
+
setTransactionCustomField: (_context, resource, { transactionId, name, value }) => {
|
|
4126
|
+
const transaction = resource.transactions.find(
|
|
4127
|
+
(e) => e.id === transactionId
|
|
4128
|
+
);
|
|
4129
|
+
if (transaction) {
|
|
4130
|
+
if (!transaction.custom) {
|
|
4131
|
+
throw new Error("Transaction has no custom field");
|
|
4132
|
+
}
|
|
4133
|
+
transaction.custom.fields[name] = value;
|
|
4134
|
+
}
|
|
4135
|
+
},
|
|
4136
|
+
setTransactionCustomType: (context, resource, { transactionId, type, fields }) => {
|
|
4137
|
+
const transaction = resource.transactions.find(
|
|
4138
|
+
(e) => e.id === transactionId
|
|
4139
|
+
);
|
|
4140
|
+
if (transaction) {
|
|
4141
|
+
if (!type) {
|
|
4142
|
+
transaction.custom = void 0;
|
|
4143
|
+
} else {
|
|
4144
|
+
const resolvedType = this._storage.getByResourceIdentifier(
|
|
4145
|
+
context.projectKey,
|
|
4146
|
+
type
|
|
4147
|
+
);
|
|
4148
|
+
if (!resolvedType) {
|
|
4149
|
+
throw new Error(`Type ${type} not found`);
|
|
4150
|
+
}
|
|
4151
|
+
transaction.custom = {
|
|
4152
|
+
type: {
|
|
4153
|
+
typeId: "type",
|
|
4154
|
+
id: resolvedType.id
|
|
4155
|
+
},
|
|
4156
|
+
fields: fields ?? {}
|
|
4157
|
+
};
|
|
4158
|
+
}
|
|
4159
|
+
}
|
|
4058
4160
|
}
|
|
4059
|
-
// addInterfaceInteraction: () => {},
|
|
4060
|
-
// changeAmountPlanned: () => {},
|
|
4061
|
-
// changeTransactionInteractionId: () => {},
|
|
4062
|
-
// changeTransactionTimestamp: () => {},
|
|
4063
|
-
// setAnonymousId: () => {},
|
|
4064
|
-
// setCustomer: () => {},
|
|
4065
4161
|
};
|
|
4066
4162
|
};
|
|
4067
4163
|
|
|
@@ -5958,11 +6054,15 @@ var ShippingMethodRepository = class extends AbstractResourceRepository {
|
|
|
5958
6054
|
};
|
|
5959
6055
|
|
|
5960
6056
|
// src/repositories/shopping-list.ts
|
|
6057
|
+
var import_uuid8 = require("uuid");
|
|
5961
6058
|
var ShoppingListRepository = class extends AbstractResourceRepository {
|
|
5962
6059
|
getTypeId() {
|
|
5963
6060
|
return "shopping-list";
|
|
5964
6061
|
}
|
|
5965
6062
|
create(context, draft) {
|
|
6063
|
+
const lineItems = draft.lineItems?.map(
|
|
6064
|
+
(draftLineItem) => this.draftLineItemtoLineItem(context.projectKey, draftLineItem)
|
|
6065
|
+
) ?? [];
|
|
5966
6066
|
const resource = {
|
|
5967
6067
|
...getBaseResourceProperties(),
|
|
5968
6068
|
...draft,
|
|
@@ -5972,20 +6072,7 @@ var ShoppingListRepository = class extends AbstractResourceRepository {
|
|
|
5972
6072
|
this._storage
|
|
5973
6073
|
),
|
|
5974
6074
|
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
|
-
})) ?? [],
|
|
6075
|
+
lineItems,
|
|
5989
6076
|
customer: draft.customer ? getReferenceFromResourceIdentifier(
|
|
5990
6077
|
draft.customer,
|
|
5991
6078
|
context.projectKey,
|
|
@@ -5996,6 +6083,241 @@ var ShoppingListRepository = class extends AbstractResourceRepository {
|
|
|
5996
6083
|
this.saveNew(context, resource);
|
|
5997
6084
|
return resource;
|
|
5998
6085
|
}
|
|
6086
|
+
actions = {
|
|
6087
|
+
setKey: (context, resource, { key }) => {
|
|
6088
|
+
resource.key = key;
|
|
6089
|
+
},
|
|
6090
|
+
setSlug: (context, resource, { slug }) => {
|
|
6091
|
+
resource.slug = slug;
|
|
6092
|
+
},
|
|
6093
|
+
changeName: (context, resource, { name }) => {
|
|
6094
|
+
resource.name = name;
|
|
6095
|
+
},
|
|
6096
|
+
setDescription: (context, resource, { description }) => {
|
|
6097
|
+
resource.description = description;
|
|
6098
|
+
},
|
|
6099
|
+
setCustomer: (context, resource, { customer }) => {
|
|
6100
|
+
if (customer?.key) {
|
|
6101
|
+
throw new Error("set customer on shoppinglist by key not implemented");
|
|
6102
|
+
}
|
|
6103
|
+
if (customer?.id) {
|
|
6104
|
+
resource.customer = { typeId: "customer", id: customer.id };
|
|
6105
|
+
}
|
|
6106
|
+
},
|
|
6107
|
+
setStore: (context, resource, { store }) => {
|
|
6108
|
+
if (store?.key) {
|
|
6109
|
+
resource.store = { typeId: "store", key: store.key };
|
|
6110
|
+
}
|
|
6111
|
+
if (store?.id) {
|
|
6112
|
+
throw new Error("set store on shoppinglist by id not implemented");
|
|
6113
|
+
}
|
|
6114
|
+
},
|
|
6115
|
+
setAnonymousId: (context, resource, { anonymousId }) => {
|
|
6116
|
+
resource.anonymousId = anonymousId;
|
|
6117
|
+
},
|
|
6118
|
+
setCustomType: (context, resource, { type, fields }) => {
|
|
6119
|
+
if (!type) {
|
|
6120
|
+
resource.custom = void 0;
|
|
6121
|
+
} else {
|
|
6122
|
+
const resolvedType = this._storage.getByResourceIdentifier(
|
|
6123
|
+
context.projectKey,
|
|
6124
|
+
type
|
|
6125
|
+
);
|
|
6126
|
+
if (!resolvedType) {
|
|
6127
|
+
throw new Error(`Type ${type} not found`);
|
|
6128
|
+
}
|
|
6129
|
+
resource.custom = {
|
|
6130
|
+
type: {
|
|
6131
|
+
typeId: "type",
|
|
6132
|
+
id: resolvedType.id
|
|
6133
|
+
},
|
|
6134
|
+
fields: fields || {}
|
|
6135
|
+
};
|
|
6136
|
+
}
|
|
6137
|
+
},
|
|
6138
|
+
setCustomField: (context, resource, { name, value }) => {
|
|
6139
|
+
if (!resource.custom) {
|
|
6140
|
+
throw new Error("Resource has no custom field");
|
|
6141
|
+
}
|
|
6142
|
+
resource.custom.fields[name] = value;
|
|
6143
|
+
},
|
|
6144
|
+
setDeleteDaysAfterLastModification: (context, resource, {
|
|
6145
|
+
deleteDaysAfterLastModification
|
|
6146
|
+
}) => {
|
|
6147
|
+
resource.deleteDaysAfterLastModification = deleteDaysAfterLastModification;
|
|
6148
|
+
},
|
|
6149
|
+
addLineItem: (context, resource, { productId, variantId, sku, quantity = 1 }) => {
|
|
6150
|
+
let product = null;
|
|
6151
|
+
if (productId) {
|
|
6152
|
+
product = this._storage.get(
|
|
6153
|
+
context.projectKey,
|
|
6154
|
+
"product",
|
|
6155
|
+
productId,
|
|
6156
|
+
{}
|
|
6157
|
+
);
|
|
6158
|
+
} else if (sku) {
|
|
6159
|
+
const items = this._storage.query(context.projectKey, "product", {
|
|
6160
|
+
where: [
|
|
6161
|
+
`masterData(current(masterVariant(sku="${sku}"))) or masterData(current(variants(sku="${sku}")))`
|
|
6162
|
+
]
|
|
6163
|
+
});
|
|
6164
|
+
if (items.count === 1) {
|
|
6165
|
+
product = items.results[0];
|
|
6166
|
+
}
|
|
6167
|
+
}
|
|
6168
|
+
if (!product) {
|
|
6169
|
+
throw new CommercetoolsError({
|
|
6170
|
+
code: "General",
|
|
6171
|
+
message: sku ? `A product containing a variant with SKU '${sku}' not found.` : `A product with ID '${productId}' not found.`
|
|
6172
|
+
});
|
|
6173
|
+
}
|
|
6174
|
+
let varId = variantId;
|
|
6175
|
+
if (sku) {
|
|
6176
|
+
varId = [
|
|
6177
|
+
product.masterData.current.masterVariant,
|
|
6178
|
+
...product.masterData.current.variants
|
|
6179
|
+
].find((x) => x.sku === sku)?.id;
|
|
6180
|
+
}
|
|
6181
|
+
if (!varId) {
|
|
6182
|
+
varId = product.masterData.current.masterVariant.id;
|
|
6183
|
+
}
|
|
6184
|
+
const alreadyAdded = resource.lineItems.some(
|
|
6185
|
+
(x) => x.productId === product?.id && x.variantId === varId
|
|
6186
|
+
);
|
|
6187
|
+
if (alreadyAdded) {
|
|
6188
|
+
resource.lineItems.forEach((x) => {
|
|
6189
|
+
if (x.productId === product?.id && x.variantId === varId) {
|
|
6190
|
+
x.quantity += quantity;
|
|
6191
|
+
}
|
|
6192
|
+
});
|
|
6193
|
+
} else {
|
|
6194
|
+
resource.lineItems.push({
|
|
6195
|
+
addedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
6196
|
+
id: (0, import_uuid8.v4)(),
|
|
6197
|
+
productId: product.id,
|
|
6198
|
+
productSlug: product.masterData.current.slug,
|
|
6199
|
+
productType: product.productType,
|
|
6200
|
+
name: product.masterData.current.name,
|
|
6201
|
+
variantId: varId,
|
|
6202
|
+
quantity
|
|
6203
|
+
});
|
|
6204
|
+
}
|
|
6205
|
+
},
|
|
6206
|
+
removeLineItem: (context, resource, { lineItemId, quantity }) => {
|
|
6207
|
+
const lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
6208
|
+
if (!lineItem) {
|
|
6209
|
+
throw new CommercetoolsError({
|
|
6210
|
+
code: "General",
|
|
6211
|
+
message: `A line item with ID '${lineItemId}' not found.`
|
|
6212
|
+
});
|
|
6213
|
+
}
|
|
6214
|
+
const shouldDelete = !quantity || quantity >= lineItem.quantity;
|
|
6215
|
+
if (shouldDelete) {
|
|
6216
|
+
resource.lineItems = resource.lineItems.filter(
|
|
6217
|
+
(x) => x.id !== lineItemId
|
|
6218
|
+
);
|
|
6219
|
+
} else {
|
|
6220
|
+
resource.lineItems.forEach((x) => {
|
|
6221
|
+
if (x.id === lineItemId && quantity) {
|
|
6222
|
+
x.quantity -= quantity;
|
|
6223
|
+
}
|
|
6224
|
+
});
|
|
6225
|
+
}
|
|
6226
|
+
},
|
|
6227
|
+
changeLineItemQuantity: (context, resource, {
|
|
6228
|
+
lineItemId,
|
|
6229
|
+
lineItemKey,
|
|
6230
|
+
quantity
|
|
6231
|
+
}) => {
|
|
6232
|
+
let lineItem;
|
|
6233
|
+
if (lineItemId) {
|
|
6234
|
+
lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
6235
|
+
if (!lineItem) {
|
|
6236
|
+
throw new CommercetoolsError({
|
|
6237
|
+
code: "General",
|
|
6238
|
+
message: `A line item with ID '${lineItemId}' not found.`
|
|
6239
|
+
});
|
|
6240
|
+
}
|
|
6241
|
+
} else if (lineItemKey) {
|
|
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 Key '${lineItemKey}' not found.`
|
|
6247
|
+
});
|
|
6248
|
+
}
|
|
6249
|
+
} else {
|
|
6250
|
+
throw new CommercetoolsError({
|
|
6251
|
+
code: "General",
|
|
6252
|
+
message: `Either lineItemid or lineItemKey needs to be provided.`
|
|
6253
|
+
});
|
|
6254
|
+
}
|
|
6255
|
+
if (quantity === 0) {
|
|
6256
|
+
resource.lineItems = resource.lineItems.filter(
|
|
6257
|
+
(x) => x.id !== lineItemId
|
|
6258
|
+
);
|
|
6259
|
+
} else {
|
|
6260
|
+
resource.lineItems.forEach((x) => {
|
|
6261
|
+
if (x.id === lineItemId && quantity) {
|
|
6262
|
+
x.quantity = quantity;
|
|
6263
|
+
}
|
|
6264
|
+
});
|
|
6265
|
+
}
|
|
6266
|
+
}
|
|
6267
|
+
};
|
|
6268
|
+
draftLineItemtoLineItem = (projectKey, draftLineItem) => {
|
|
6269
|
+
const { sku, productId, variantId } = draftLineItem;
|
|
6270
|
+
const lineItem = {
|
|
6271
|
+
...getBaseResourceProperties(),
|
|
6272
|
+
...draftLineItem,
|
|
6273
|
+
addedAt: draftLineItem.addedAt ?? "",
|
|
6274
|
+
productId: draftLineItem.productId ?? "",
|
|
6275
|
+
name: {},
|
|
6276
|
+
variantId,
|
|
6277
|
+
quantity: draftLineItem.quantity ?? 1,
|
|
6278
|
+
productType: { typeId: "product-type", id: "" },
|
|
6279
|
+
custom: createCustomFields(
|
|
6280
|
+
draftLineItem.custom,
|
|
6281
|
+
projectKey,
|
|
6282
|
+
this._storage
|
|
6283
|
+
)
|
|
6284
|
+
};
|
|
6285
|
+
if (variantId) {
|
|
6286
|
+
return lineItem;
|
|
6287
|
+
}
|
|
6288
|
+
if (sku) {
|
|
6289
|
+
const items = this._storage.query(projectKey, "product", {
|
|
6290
|
+
where: [
|
|
6291
|
+
`masterData(current(masterVariant(sku="${sku}"))) or masterData(current(variants(sku="${sku}")))`
|
|
6292
|
+
]
|
|
6293
|
+
});
|
|
6294
|
+
if (items.count === 0) {
|
|
6295
|
+
throw new Error(`Product with sku ${sku} not found`);
|
|
6296
|
+
}
|
|
6297
|
+
const product = items.results[0];
|
|
6298
|
+
const allVariants = [
|
|
6299
|
+
product.masterData.current.masterVariant,
|
|
6300
|
+
...product.masterData.current.variants
|
|
6301
|
+
];
|
|
6302
|
+
const variantId2 = allVariants.find((e) => e.sku === sku)?.id;
|
|
6303
|
+
lineItem.variantId = variantId2;
|
|
6304
|
+
return lineItem;
|
|
6305
|
+
}
|
|
6306
|
+
if (productId) {
|
|
6307
|
+
const items = this._storage.query(projectKey, "product", {
|
|
6308
|
+
where: [`id="${productId}"`]
|
|
6309
|
+
});
|
|
6310
|
+
if (items.count === 0) {
|
|
6311
|
+
throw new Error(`Product with id ${productId} not found`);
|
|
6312
|
+
}
|
|
6313
|
+
const variantId2 = items.results[0].masterData.current.masterVariant.id;
|
|
6314
|
+
lineItem.variantId = variantId2;
|
|
6315
|
+
return lineItem;
|
|
6316
|
+
}
|
|
6317
|
+
throw new Error(
|
|
6318
|
+
`must provide either sku, productId or variantId for ShoppingListLineItem`
|
|
6319
|
+
);
|
|
6320
|
+
};
|
|
5999
6321
|
};
|
|
6000
6322
|
|
|
6001
6323
|
// src/repositories/staged-quote.ts
|
|
@@ -6214,7 +6536,7 @@ var SubscriptionRepository = class extends AbstractResourceRepository {
|
|
|
6214
6536
|
};
|
|
6215
6537
|
|
|
6216
6538
|
// src/repositories/tax-category.ts
|
|
6217
|
-
var
|
|
6539
|
+
var import_uuid9 = require("uuid");
|
|
6218
6540
|
var TaxCategoryRepository = class extends AbstractResourceRepository {
|
|
6219
6541
|
getTypeId() {
|
|
6220
6542
|
return "tax-category";
|
|
@@ -6230,7 +6552,7 @@ var TaxCategoryRepository = class extends AbstractResourceRepository {
|
|
|
6230
6552
|
}
|
|
6231
6553
|
taxRateFromTaxRateDraft = (draft) => ({
|
|
6232
6554
|
...draft,
|
|
6233
|
-
id: (0,
|
|
6555
|
+
id: (0, import_uuid9.v4)(),
|
|
6234
6556
|
amount: draft.amount || 0
|
|
6235
6557
|
});
|
|
6236
6558
|
actions = {
|
|
@@ -6789,7 +7111,7 @@ var CustomerGroupService = class extends AbstractService {
|
|
|
6789
7111
|
};
|
|
6790
7112
|
|
|
6791
7113
|
// src/services/customer.ts
|
|
6792
|
-
var
|
|
7114
|
+
var import_uuid10 = require("uuid");
|
|
6793
7115
|
var CustomerService = class extends AbstractService {
|
|
6794
7116
|
repository;
|
|
6795
7117
|
constructor(parent, repository) {
|
|
@@ -6813,7 +7135,7 @@ var CustomerService = class extends AbstractService {
|
|
|
6813
7135
|
...rest,
|
|
6814
7136
|
customerId: customer.results[0].id,
|
|
6815
7137
|
expiresAt: new Date(Date.now() + ttlMinutes * 60).toISOString(),
|
|
6816
|
-
value: (0,
|
|
7138
|
+
value: (0, import_uuid10.v4)()
|
|
6817
7139
|
});
|
|
6818
7140
|
});
|
|
6819
7141
|
}
|