@labdigital/commercetools-mock 2.61.2 → 2.62.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +9 -7
- package/dist/index.mjs +278 -205
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/repositories/as-associate.test.ts +25 -0
- package/src/repositories/as-associate.ts +2 -0
- package/src/repositories/business-unit.ts +119 -42
- package/src/repositories/customer/actions.ts +18 -0
- package/src/repositories/index.ts +2 -0
- package/src/services/as-associate-shopping-list.test.ts +58 -0
- package/src/services/as-associate-shopping-list.ts +33 -0
- package/src/services/as-associate.ts +8 -0
package/dist/index.d.mts
CHANGED
|
@@ -113,10 +113,18 @@ declare class QuoteRequestRepository extends AbstractResourceRepository<"quote-r
|
|
|
113
113
|
createFromCart(context: RepositoryContext, cartReference: CartReference): QuoteRequest;
|
|
114
114
|
}
|
|
115
115
|
//#endregion
|
|
116
|
+
//#region src/repositories/shopping-list/index.d.ts
|
|
117
|
+
declare class ShoppingListRepository extends AbstractResourceRepository<"shopping-list"> {
|
|
118
|
+
constructor(config: Config);
|
|
119
|
+
create(context: RepositoryContext, draft: ShoppingListDraft): ShoppingList;
|
|
120
|
+
draftLineItemtoLineItem: (projectKey: string, draftLineItem: LineItemDraft) => ShoppingListLineItem;
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
116
123
|
//#region src/repositories/as-associate.d.ts
|
|
117
124
|
declare class AsAssociateOrderRepository extends OrderRepository {}
|
|
118
125
|
declare class AsAssociateCartRepository extends CartRepository {}
|
|
119
126
|
declare class AsAssociateQuoteRequestRepository extends QuoteRequestRepository {}
|
|
127
|
+
declare class AsAssociateShoppingListRepository extends ShoppingListRepository {}
|
|
120
128
|
//#endregion
|
|
121
129
|
//#region src/repositories/associate-role.d.ts
|
|
122
130
|
declare class AssociateRoleRepository extends AbstractResourceRepository<"associate-role"> {
|
|
@@ -1159,13 +1167,6 @@ declare class ShippingMethodRepository extends AbstractResourceRepository<"shipp
|
|
|
1159
1167
|
private _transformZoneRateDraft;
|
|
1160
1168
|
}
|
|
1161
1169
|
//#endregion
|
|
1162
|
-
//#region src/repositories/shopping-list/index.d.ts
|
|
1163
|
-
declare class ShoppingListRepository extends AbstractResourceRepository<"shopping-list"> {
|
|
1164
|
-
constructor(config: Config);
|
|
1165
|
-
create(context: RepositoryContext, draft: ShoppingListDraft): ShoppingList;
|
|
1166
|
-
draftLineItemtoLineItem: (projectKey: string, draftLineItem: LineItemDraft) => ShoppingListLineItem;
|
|
1167
|
-
}
|
|
1168
|
-
//#endregion
|
|
1169
1170
|
//#region src/repositories/standalone-price.d.ts
|
|
1170
1171
|
declare class StandAlonePriceRepository extends AbstractResourceRepository<"standalone-price"> {
|
|
1171
1172
|
constructor(config: Config);
|
|
@@ -1216,6 +1217,7 @@ declare const createRepositories: (config: Config) => {
|
|
|
1216
1217
|
cart: AsAssociateCartRepository;
|
|
1217
1218
|
order: AsAssociateOrderRepository;
|
|
1218
1219
|
"quote-request": AsAssociateQuoteRequestRepository;
|
|
1220
|
+
"shopping-list": AsAssociateShoppingListRepository;
|
|
1219
1221
|
};
|
|
1220
1222
|
"associate-role": AssociateRoleRepository;
|
|
1221
1223
|
"attribute-group": AttributeGroupRepository;
|
package/dist/index.mjs
CHANGED
|
@@ -1969,11 +1969,188 @@ var QuoteRequestRepository = class extends AbstractResourceRepository {
|
|
|
1969
1969
|
}
|
|
1970
1970
|
};
|
|
1971
1971
|
|
|
1972
|
+
//#endregion
|
|
1973
|
+
//#region src/repositories/shopping-list/actions.ts
|
|
1974
|
+
var ShoppingListUpdateHandler = class extends AbstractUpdateHandler {
|
|
1975
|
+
addLineItem(context, resource, { productId, variantId, sku, quantity = 1, addedAt, key }) {
|
|
1976
|
+
let product = null;
|
|
1977
|
+
if (productId) product = this._storage.get(context.projectKey, "product", productId, {});
|
|
1978
|
+
else if (sku) {
|
|
1979
|
+
const items = this._storage.query(context.projectKey, "product", { where: [`masterData(current(masterVariant(sku="${sku}"))) or masterData(current(variants(sku="${sku}")))`] });
|
|
1980
|
+
if (items.count === 1) product = items.results[0];
|
|
1981
|
+
}
|
|
1982
|
+
if (!product) throw new CommercetoolsError({
|
|
1983
|
+
code: "General",
|
|
1984
|
+
message: sku ? `A product containing a variant with SKU '${sku}' not found.` : `A product with ID '${productId}' not found.`
|
|
1985
|
+
});
|
|
1986
|
+
let varId = variantId;
|
|
1987
|
+
if (sku) varId = [product.masterData.current.masterVariant, ...product.masterData.current.variants].find((x) => x.sku === sku)?.id;
|
|
1988
|
+
if (!varId) varId = product.masterData.current.masterVariant.id;
|
|
1989
|
+
if (resource.lineItems.some((x) => x.productId === product?.id && x.variantId === varId)) resource.lineItems.forEach((x) => {
|
|
1990
|
+
if (x.productId === product?.id && x.variantId === varId) x.quantity += quantity;
|
|
1991
|
+
});
|
|
1992
|
+
else resource.lineItems.push({
|
|
1993
|
+
addedAt: addedAt ? addedAt : (/* @__PURE__ */ new Date()).toISOString(),
|
|
1994
|
+
id: v4(),
|
|
1995
|
+
key,
|
|
1996
|
+
productId: product.id,
|
|
1997
|
+
productSlug: product.masterData.current.slug,
|
|
1998
|
+
productType: product.productType,
|
|
1999
|
+
name: product.masterData.current.name,
|
|
2000
|
+
variantId: varId,
|
|
2001
|
+
quantity,
|
|
2002
|
+
published: Boolean(product.masterData.current)
|
|
2003
|
+
});
|
|
2004
|
+
}
|
|
2005
|
+
changeLineItemQuantity(context, resource, { lineItemId, lineItemKey, quantity }) {
|
|
2006
|
+
let lineItem;
|
|
2007
|
+
if (lineItemId) {
|
|
2008
|
+
lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
2009
|
+
if (!lineItem) throw new CommercetoolsError({
|
|
2010
|
+
code: "General",
|
|
2011
|
+
message: `A line item with ID '${lineItemId}' not found.`
|
|
2012
|
+
});
|
|
2013
|
+
} else if (lineItemKey) {
|
|
2014
|
+
lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
2015
|
+
if (!lineItem) throw new CommercetoolsError({
|
|
2016
|
+
code: "General",
|
|
2017
|
+
message: `A line item with Key '${lineItemKey}' not found.`
|
|
2018
|
+
});
|
|
2019
|
+
} else throw new CommercetoolsError({
|
|
2020
|
+
code: "General",
|
|
2021
|
+
message: "Either lineItemid or lineItemKey needs to be provided."
|
|
2022
|
+
});
|
|
2023
|
+
if (quantity === 0) resource.lineItems = resource.lineItems.filter((x) => x.id !== lineItemId);
|
|
2024
|
+
else resource.lineItems.forEach((x) => {
|
|
2025
|
+
if (x.id === lineItemId && quantity) x.quantity = quantity;
|
|
2026
|
+
});
|
|
2027
|
+
}
|
|
2028
|
+
changeName(context, resource, { name }) {
|
|
2029
|
+
resource.name = name;
|
|
2030
|
+
}
|
|
2031
|
+
removeLineItem(context, resource, { lineItemId, quantity }) {
|
|
2032
|
+
const lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
2033
|
+
if (!lineItem) throw new CommercetoolsError({
|
|
2034
|
+
code: "General",
|
|
2035
|
+
message: `A line item with ID '${lineItemId}' not found.`
|
|
2036
|
+
});
|
|
2037
|
+
if (!quantity || quantity >= lineItem.quantity) resource.lineItems = resource.lineItems.filter((x) => x.id !== lineItemId);
|
|
2038
|
+
else resource.lineItems.forEach((x) => {
|
|
2039
|
+
if (x.id === lineItemId && quantity) x.quantity -= quantity;
|
|
2040
|
+
});
|
|
2041
|
+
}
|
|
2042
|
+
setAnonymousId(context, resource, { anonymousId }) {
|
|
2043
|
+
resource.anonymousId = anonymousId;
|
|
2044
|
+
}
|
|
2045
|
+
setCustomer(context, resource, { customer }) {
|
|
2046
|
+
if (customer?.key) throw new Error("set customer on shoppinglist by key not implemented");
|
|
2047
|
+
if (customer?.id) resource.customer = {
|
|
2048
|
+
typeId: "customer",
|
|
2049
|
+
id: customer.id
|
|
2050
|
+
};
|
|
2051
|
+
}
|
|
2052
|
+
setCustomField(context, resource, { name, value }) {
|
|
2053
|
+
if (!resource.custom) throw new Error("Resource has no custom field");
|
|
2054
|
+
resource.custom.fields[name] = value;
|
|
2055
|
+
}
|
|
2056
|
+
setCustomType(context, resource, { type, fields }) {
|
|
2057
|
+
if (!type) resource.custom = void 0;
|
|
2058
|
+
else {
|
|
2059
|
+
const resolvedType = this._storage.getByResourceIdentifier(context.projectKey, type);
|
|
2060
|
+
if (!resolvedType) throw new Error(`Type ${type} not found`);
|
|
2061
|
+
resource.custom = {
|
|
2062
|
+
type: {
|
|
2063
|
+
typeId: "type",
|
|
2064
|
+
id: resolvedType.id
|
|
2065
|
+
},
|
|
2066
|
+
fields: fields || {}
|
|
2067
|
+
};
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
setDeleteDaysAfterLastModification(context, resource, { deleteDaysAfterLastModification }) {
|
|
2071
|
+
resource.deleteDaysAfterLastModification = deleteDaysAfterLastModification;
|
|
2072
|
+
}
|
|
2073
|
+
setDescription(context, resource, { description }) {
|
|
2074
|
+
resource.description = description;
|
|
2075
|
+
}
|
|
2076
|
+
setKey(context, resource, { key }) {
|
|
2077
|
+
resource.key = key;
|
|
2078
|
+
}
|
|
2079
|
+
setSlug(context, resource, { slug }) {
|
|
2080
|
+
resource.slug = slug;
|
|
2081
|
+
}
|
|
2082
|
+
setStore(context, resource, { store }) {
|
|
2083
|
+
if (store?.key) resource.store = {
|
|
2084
|
+
typeId: "store",
|
|
2085
|
+
key: store.key
|
|
2086
|
+
};
|
|
2087
|
+
if (store?.id) throw new Error("set store on shoppinglist by id not implemented");
|
|
2088
|
+
}
|
|
2089
|
+
};
|
|
2090
|
+
|
|
2091
|
+
//#endregion
|
|
2092
|
+
//#region src/repositories/shopping-list/index.ts
|
|
2093
|
+
var ShoppingListRepository = class extends AbstractResourceRepository {
|
|
2094
|
+
constructor(config) {
|
|
2095
|
+
super("shopping-list", config);
|
|
2096
|
+
this.actions = new ShoppingListUpdateHandler(config.storage);
|
|
2097
|
+
}
|
|
2098
|
+
create(context, draft) {
|
|
2099
|
+
const lineItems = draft.lineItems?.map((draftLineItem) => this.draftLineItemtoLineItem(context.projectKey, draftLineItem)) ?? [];
|
|
2100
|
+
const resource = {
|
|
2101
|
+
...getBaseResourceProperties(),
|
|
2102
|
+
...draft,
|
|
2103
|
+
custom: createCustomFields(draft.custom, context.projectKey, this._storage),
|
|
2104
|
+
textLineItems: [],
|
|
2105
|
+
lineItems,
|
|
2106
|
+
customer: draft.customer ? getReferenceFromResourceIdentifier(draft.customer, context.projectKey, this._storage) : void 0,
|
|
2107
|
+
store: draft.store ? getStoreKeyReference(draft.store, context.projectKey, this._storage) : void 0,
|
|
2108
|
+
businessUnit: draft.businessUnit ? getBusinessUnitKeyReference(draft.businessUnit, context.projectKey, this._storage) : void 0
|
|
2109
|
+
};
|
|
2110
|
+
return this.saveNew(context, resource);
|
|
2111
|
+
}
|
|
2112
|
+
draftLineItemtoLineItem = (projectKey, draftLineItem) => {
|
|
2113
|
+
const { sku, productId, variantId } = draftLineItem;
|
|
2114
|
+
const lineItem = {
|
|
2115
|
+
...getBaseResourceProperties(),
|
|
2116
|
+
...draftLineItem,
|
|
2117
|
+
addedAt: draftLineItem.addedAt ?? "",
|
|
2118
|
+
productId: draftLineItem.productId ?? "",
|
|
2119
|
+
name: {},
|
|
2120
|
+
variantId,
|
|
2121
|
+
published: true,
|
|
2122
|
+
quantity: draftLineItem.quantity ?? 1,
|
|
2123
|
+
productType: {
|
|
2124
|
+
typeId: "product-type",
|
|
2125
|
+
id: ""
|
|
2126
|
+
},
|
|
2127
|
+
custom: createCustomFields(draftLineItem.custom, projectKey, this._storage)
|
|
2128
|
+
};
|
|
2129
|
+
if (productId && variantId) return lineItem;
|
|
2130
|
+
if (sku) {
|
|
2131
|
+
const items = this._storage.query(projectKey, "product", { where: [`masterData(current(masterVariant(sku="${sku}"))) or masterData(current(variants(sku="${sku}")))`] });
|
|
2132
|
+
if (items.count === 0) throw new Error(`Product with sku ${sku} not found`);
|
|
2133
|
+
const product = items.results[0];
|
|
2134
|
+
lineItem.variantId = [product.masterData.current.masterVariant, ...product.masterData.current.variants].find((e) => e.sku === sku)?.id;
|
|
2135
|
+
lineItem.productId = product.id;
|
|
2136
|
+
return lineItem;
|
|
2137
|
+
}
|
|
2138
|
+
if (productId) {
|
|
2139
|
+
const items = this._storage.query(projectKey, "product", { where: [`id="${productId}"`] });
|
|
2140
|
+
if (items.count === 0) throw new Error(`Product with id ${productId} not found`);
|
|
2141
|
+
lineItem.variantId = items.results[0].masterData.current.masterVariant.id;
|
|
2142
|
+
return lineItem;
|
|
2143
|
+
}
|
|
2144
|
+
throw new Error("must provide either sku, productId or variantId for ShoppingListLineItem");
|
|
2145
|
+
};
|
|
2146
|
+
};
|
|
2147
|
+
|
|
1972
2148
|
//#endregion
|
|
1973
2149
|
//#region src/repositories/as-associate.ts
|
|
1974
2150
|
var AsAssociateOrderRepository = class extends OrderRepository {};
|
|
1975
2151
|
var AsAssociateCartRepository = class extends CartRepository {};
|
|
1976
2152
|
var AsAssociateQuoteRequestRepository = class extends QuoteRequestRepository {};
|
|
2153
|
+
var AsAssociateShoppingListRepository = class extends ShoppingListRepository {};
|
|
1977
2154
|
|
|
1978
2155
|
//#endregion
|
|
1979
2156
|
//#region src/repositories/associate-role.ts
|
|
@@ -2138,14 +2315,15 @@ var BusinessUnitUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
2138
2315
|
resource.stores.push(newStore);
|
|
2139
2316
|
}
|
|
2140
2317
|
}
|
|
2141
|
-
changeAddress(context, resource, { addressId, address }) {
|
|
2142
|
-
const
|
|
2143
|
-
|
|
2318
|
+
changeAddress(context, resource, { addressId, addressKey, address }) {
|
|
2319
|
+
const current = this._findAddress(resource, addressId, addressKey, true);
|
|
2320
|
+
assert(current?.id);
|
|
2321
|
+
const oldAddressIndex = resource.addresses.findIndex((a) => a.id === current.id);
|
|
2144
2322
|
const newAddress = createAddress({
|
|
2145
2323
|
...address,
|
|
2146
|
-
id:
|
|
2324
|
+
id: current.id
|
|
2147
2325
|
}, context.projectKey, this._storage);
|
|
2148
|
-
if (newAddress) resource.addresses[
|
|
2326
|
+
if (newAddress) resource.addresses[oldAddressIndex] = newAddress;
|
|
2149
2327
|
}
|
|
2150
2328
|
changeApprovalRuleMode(context, resource, { approvalRuleMode }) {
|
|
2151
2329
|
resource.approvalRuleMode = approvalRuleMode;
|
|
@@ -2187,27 +2365,44 @@ var BusinessUnitUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
2187
2365
|
setStoreMode(context, resource, { storeMode }) {
|
|
2188
2366
|
resource.storeMode = storeMode;
|
|
2189
2367
|
}
|
|
2190
|
-
setDefaultShippingAddress(context, resource, { addressId }) {
|
|
2191
|
-
|
|
2368
|
+
setDefaultShippingAddress(context, resource, { addressId, addressKey }) {
|
|
2369
|
+
const address = this._findAddress(resource, addressId, addressKey, true);
|
|
2370
|
+
assert(address?.id);
|
|
2371
|
+
resource.defaultShippingAddressId = address.id;
|
|
2372
|
+
if (resource.shippingAddressIds === void 0) resource.shippingAddressIds = [];
|
|
2373
|
+
if (!resource.shippingAddressIds.includes(address.id)) resource.shippingAddressIds.push(address.id);
|
|
2192
2374
|
}
|
|
2193
|
-
addShippingAddressId(context, resource, { addressId }) {
|
|
2194
|
-
|
|
2195
|
-
|
|
2375
|
+
addShippingAddressId(context, resource, { addressId, addressKey }) {
|
|
2376
|
+
const address = this._findAddress(resource, addressId, addressKey, true);
|
|
2377
|
+
assert(address?.id);
|
|
2378
|
+
if (resource.shippingAddressIds === void 0) resource.shippingAddressIds = [];
|
|
2379
|
+
if (!resource.shippingAddressIds.includes(address.id)) resource.shippingAddressIds.push(address.id);
|
|
2380
|
+
return resource;
|
|
2196
2381
|
}
|
|
2197
|
-
removeShippingAddressId(context, resource, { addressId }) {
|
|
2198
|
-
|
|
2199
|
-
|
|
2382
|
+
removeShippingAddressId(context, resource, { addressId, addressKey }) {
|
|
2383
|
+
const address = this._findAddress(resource, addressId, addressKey, true);
|
|
2384
|
+
assert(address?.id);
|
|
2385
|
+
resource.shippingAddressIds = resource.shippingAddressIds?.filter((id) => id !== address.id);
|
|
2386
|
+
if (resource.defaultShippingAddressId === address.id) resource.defaultShippingAddressId = void 0;
|
|
2200
2387
|
}
|
|
2201
|
-
addBillingAddressId(context, resource, { addressId }) {
|
|
2202
|
-
|
|
2203
|
-
|
|
2388
|
+
addBillingAddressId(context, resource, { addressId, addressKey }) {
|
|
2389
|
+
const address = this._findAddress(resource, addressId, addressKey, true);
|
|
2390
|
+
assert(address?.id);
|
|
2391
|
+
if (resource.billingAddressIds === void 0) resource.billingAddressIds = [];
|
|
2392
|
+
if (!resource.billingAddressIds.includes(address.id)) resource.billingAddressIds.push(address.id);
|
|
2204
2393
|
}
|
|
2205
|
-
removeBillingAddressId(context, resource, { addressId }) {
|
|
2206
|
-
|
|
2207
|
-
|
|
2394
|
+
removeBillingAddressId(context, resource, { addressId, addressKey }) {
|
|
2395
|
+
const address = this._findAddress(resource, addressId, addressKey, true);
|
|
2396
|
+
assert(address?.id);
|
|
2397
|
+
resource.billingAddressIds = resource.billingAddressIds?.filter((id) => id !== address.id);
|
|
2398
|
+
if (resource.defaultBillingAddressId === address.id) resource.defaultBillingAddressId = void 0;
|
|
2208
2399
|
}
|
|
2209
|
-
setDefaultBillingAddress(context, resource, { addressId }) {
|
|
2210
|
-
|
|
2400
|
+
setDefaultBillingAddress(context, resource, { addressId, addressKey }) {
|
|
2401
|
+
const address = this._findAddress(resource, addressId, addressKey, true);
|
|
2402
|
+
assert(address?.id);
|
|
2403
|
+
resource.defaultBillingAddressId = address.id;
|
|
2404
|
+
if (resource.billingAddressIds === void 0) resource.billingAddressIds = [];
|
|
2405
|
+
if (!resource.billingAddressIds.includes(address.id)) resource.billingAddressIds.push(address.id);
|
|
2211
2406
|
}
|
|
2212
2407
|
setCustomField(context, resource, { name, value }) {
|
|
2213
2408
|
if (!resource.custom) throw new Error("Resource has no custom type");
|
|
@@ -2228,12 +2423,36 @@ var BusinessUnitUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
2228
2423
|
fields
|
|
2229
2424
|
}, context.projectKey, this._storage);
|
|
2230
2425
|
}
|
|
2231
|
-
removeAddress(context, resource, { addressId }) {
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
if (resource.
|
|
2236
|
-
if (resource.
|
|
2426
|
+
removeAddress(context, resource, { addressId, addressKey }) {
|
|
2427
|
+
const address = this._findAddress(resource, addressId, addressKey, true);
|
|
2428
|
+
assert(address?.id);
|
|
2429
|
+
resource.addresses = resource.addresses.filter((a) => a.id !== address.id);
|
|
2430
|
+
if (resource.shippingAddressIds) resource.shippingAddressIds = resource.shippingAddressIds.filter((id) => id !== address.id);
|
|
2431
|
+
if (resource.billingAddressIds) resource.billingAddressIds = resource.billingAddressIds.filter((id) => id !== address.id);
|
|
2432
|
+
if (resource.defaultShippingAddressId === address.id) resource.defaultShippingAddressId = void 0;
|
|
2433
|
+
if (resource.defaultBillingAddressId === address.id) resource.defaultBillingAddressId = void 0;
|
|
2434
|
+
}
|
|
2435
|
+
_findAddress(resource, addressId, addressKey, required = false) {
|
|
2436
|
+
if (addressKey) {
|
|
2437
|
+
const address = resource.addresses.find((a) => a.key === addressKey);
|
|
2438
|
+
if (!address) throw new CommercetoolsError({
|
|
2439
|
+
code: "InvalidOperation",
|
|
2440
|
+
message: `Business Unit does not contain an address with the key ${addressKey}.`
|
|
2441
|
+
}, 400);
|
|
2442
|
+
return address;
|
|
2443
|
+
}
|
|
2444
|
+
if (addressId) {
|
|
2445
|
+
const address = resource.addresses.find((a) => a.id === addressId);
|
|
2446
|
+
if (!address) throw new CommercetoolsError({
|
|
2447
|
+
code: "InvalidOperation",
|
|
2448
|
+
message: `Business Unit does not contain an address with the id ${addressId}.`
|
|
2449
|
+
}, 400);
|
|
2450
|
+
return address;
|
|
2451
|
+
}
|
|
2452
|
+
if (required) throw new CommercetoolsError({
|
|
2453
|
+
code: "InvalidOperation",
|
|
2454
|
+
message: "One of address 'addressId' or 'addressKey' is required."
|
|
2455
|
+
}, 400);
|
|
2237
2456
|
}
|
|
2238
2457
|
};
|
|
2239
2458
|
|
|
@@ -2636,6 +2855,10 @@ var CustomerUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
2636
2855
|
const address = this._findAddress(resource, action.addressId, action.addressKey, true);
|
|
2637
2856
|
assert(address?.id);
|
|
2638
2857
|
resource.addresses = resource.addresses.filter((a) => a.id !== address.id);
|
|
2858
|
+
if (resource.shippingAddressIds) resource.shippingAddressIds = resource.shippingAddressIds.filter((id) => id !== address.id);
|
|
2859
|
+
if (resource.billingAddressIds) resource.billingAddressIds = resource.billingAddressIds.filter((id) => id !== address.id);
|
|
2860
|
+
if (resource.defaultShippingAddressId === address.id) resource.defaultShippingAddressId = void 0;
|
|
2861
|
+
if (resource.defaultBillingAddressId === address.id) resource.defaultBillingAddressId = void 0;
|
|
2639
2862
|
}
|
|
2640
2863
|
removeBillingAddressId(context, resource, action) {
|
|
2641
2864
|
const address = this._findAddress(resource, action.addressId, action.addressKey, true);
|
|
@@ -6197,182 +6420,6 @@ var ShippingMethodRepository = class extends AbstractResourceRepository {
|
|
|
6197
6420
|
}
|
|
6198
6421
|
};
|
|
6199
6422
|
|
|
6200
|
-
//#endregion
|
|
6201
|
-
//#region src/repositories/shopping-list/actions.ts
|
|
6202
|
-
var ShoppingListUpdateHandler = class extends AbstractUpdateHandler {
|
|
6203
|
-
addLineItem(context, resource, { productId, variantId, sku, quantity = 1, addedAt, key }) {
|
|
6204
|
-
let product = null;
|
|
6205
|
-
if (productId) product = this._storage.get(context.projectKey, "product", productId, {});
|
|
6206
|
-
else if (sku) {
|
|
6207
|
-
const items = this._storage.query(context.projectKey, "product", { where: [`masterData(current(masterVariant(sku="${sku}"))) or masterData(current(variants(sku="${sku}")))`] });
|
|
6208
|
-
if (items.count === 1) product = items.results[0];
|
|
6209
|
-
}
|
|
6210
|
-
if (!product) throw new CommercetoolsError({
|
|
6211
|
-
code: "General",
|
|
6212
|
-
message: sku ? `A product containing a variant with SKU '${sku}' not found.` : `A product with ID '${productId}' not found.`
|
|
6213
|
-
});
|
|
6214
|
-
let varId = variantId;
|
|
6215
|
-
if (sku) varId = [product.masterData.current.masterVariant, ...product.masterData.current.variants].find((x) => x.sku === sku)?.id;
|
|
6216
|
-
if (!varId) varId = product.masterData.current.masterVariant.id;
|
|
6217
|
-
if (resource.lineItems.some((x) => x.productId === product?.id && x.variantId === varId)) resource.lineItems.forEach((x) => {
|
|
6218
|
-
if (x.productId === product?.id && x.variantId === varId) x.quantity += quantity;
|
|
6219
|
-
});
|
|
6220
|
-
else resource.lineItems.push({
|
|
6221
|
-
addedAt: addedAt ? addedAt : (/* @__PURE__ */ new Date()).toISOString(),
|
|
6222
|
-
id: v4(),
|
|
6223
|
-
key,
|
|
6224
|
-
productId: product.id,
|
|
6225
|
-
productSlug: product.masterData.current.slug,
|
|
6226
|
-
productType: product.productType,
|
|
6227
|
-
name: product.masterData.current.name,
|
|
6228
|
-
variantId: varId,
|
|
6229
|
-
quantity,
|
|
6230
|
-
published: Boolean(product.masterData.current)
|
|
6231
|
-
});
|
|
6232
|
-
}
|
|
6233
|
-
changeLineItemQuantity(context, resource, { lineItemId, lineItemKey, quantity }) {
|
|
6234
|
-
let lineItem;
|
|
6235
|
-
if (lineItemId) {
|
|
6236
|
-
lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
6237
|
-
if (!lineItem) throw new CommercetoolsError({
|
|
6238
|
-
code: "General",
|
|
6239
|
-
message: `A line item with ID '${lineItemId}' not found.`
|
|
6240
|
-
});
|
|
6241
|
-
} else if (lineItemKey) {
|
|
6242
|
-
lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
6243
|
-
if (!lineItem) throw new CommercetoolsError({
|
|
6244
|
-
code: "General",
|
|
6245
|
-
message: `A line item with Key '${lineItemKey}' not found.`
|
|
6246
|
-
});
|
|
6247
|
-
} else throw new CommercetoolsError({
|
|
6248
|
-
code: "General",
|
|
6249
|
-
message: "Either lineItemid or lineItemKey needs to be provided."
|
|
6250
|
-
});
|
|
6251
|
-
if (quantity === 0) resource.lineItems = resource.lineItems.filter((x) => x.id !== lineItemId);
|
|
6252
|
-
else resource.lineItems.forEach((x) => {
|
|
6253
|
-
if (x.id === lineItemId && quantity) x.quantity = quantity;
|
|
6254
|
-
});
|
|
6255
|
-
}
|
|
6256
|
-
changeName(context, resource, { name }) {
|
|
6257
|
-
resource.name = name;
|
|
6258
|
-
}
|
|
6259
|
-
removeLineItem(context, resource, { lineItemId, quantity }) {
|
|
6260
|
-
const lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
6261
|
-
if (!lineItem) throw new CommercetoolsError({
|
|
6262
|
-
code: "General",
|
|
6263
|
-
message: `A line item with ID '${lineItemId}' not found.`
|
|
6264
|
-
});
|
|
6265
|
-
if (!quantity || quantity >= lineItem.quantity) resource.lineItems = resource.lineItems.filter((x) => x.id !== lineItemId);
|
|
6266
|
-
else resource.lineItems.forEach((x) => {
|
|
6267
|
-
if (x.id === lineItemId && quantity) x.quantity -= quantity;
|
|
6268
|
-
});
|
|
6269
|
-
}
|
|
6270
|
-
setAnonymousId(context, resource, { anonymousId }) {
|
|
6271
|
-
resource.anonymousId = anonymousId;
|
|
6272
|
-
}
|
|
6273
|
-
setCustomer(context, resource, { customer }) {
|
|
6274
|
-
if (customer?.key) throw new Error("set customer on shoppinglist by key not implemented");
|
|
6275
|
-
if (customer?.id) resource.customer = {
|
|
6276
|
-
typeId: "customer",
|
|
6277
|
-
id: customer.id
|
|
6278
|
-
};
|
|
6279
|
-
}
|
|
6280
|
-
setCustomField(context, resource, { name, value }) {
|
|
6281
|
-
if (!resource.custom) throw new Error("Resource has no custom field");
|
|
6282
|
-
resource.custom.fields[name] = value;
|
|
6283
|
-
}
|
|
6284
|
-
setCustomType(context, resource, { type, fields }) {
|
|
6285
|
-
if (!type) resource.custom = void 0;
|
|
6286
|
-
else {
|
|
6287
|
-
const resolvedType = this._storage.getByResourceIdentifier(context.projectKey, type);
|
|
6288
|
-
if (!resolvedType) throw new Error(`Type ${type} not found`);
|
|
6289
|
-
resource.custom = {
|
|
6290
|
-
type: {
|
|
6291
|
-
typeId: "type",
|
|
6292
|
-
id: resolvedType.id
|
|
6293
|
-
},
|
|
6294
|
-
fields: fields || {}
|
|
6295
|
-
};
|
|
6296
|
-
}
|
|
6297
|
-
}
|
|
6298
|
-
setDeleteDaysAfterLastModification(context, resource, { deleteDaysAfterLastModification }) {
|
|
6299
|
-
resource.deleteDaysAfterLastModification = deleteDaysAfterLastModification;
|
|
6300
|
-
}
|
|
6301
|
-
setDescription(context, resource, { description }) {
|
|
6302
|
-
resource.description = description;
|
|
6303
|
-
}
|
|
6304
|
-
setKey(context, resource, { key }) {
|
|
6305
|
-
resource.key = key;
|
|
6306
|
-
}
|
|
6307
|
-
setSlug(context, resource, { slug }) {
|
|
6308
|
-
resource.slug = slug;
|
|
6309
|
-
}
|
|
6310
|
-
setStore(context, resource, { store }) {
|
|
6311
|
-
if (store?.key) resource.store = {
|
|
6312
|
-
typeId: "store",
|
|
6313
|
-
key: store.key
|
|
6314
|
-
};
|
|
6315
|
-
if (store?.id) throw new Error("set store on shoppinglist by id not implemented");
|
|
6316
|
-
}
|
|
6317
|
-
};
|
|
6318
|
-
|
|
6319
|
-
//#endregion
|
|
6320
|
-
//#region src/repositories/shopping-list/index.ts
|
|
6321
|
-
var ShoppingListRepository = class extends AbstractResourceRepository {
|
|
6322
|
-
constructor(config) {
|
|
6323
|
-
super("shopping-list", config);
|
|
6324
|
-
this.actions = new ShoppingListUpdateHandler(config.storage);
|
|
6325
|
-
}
|
|
6326
|
-
create(context, draft) {
|
|
6327
|
-
const lineItems = draft.lineItems?.map((draftLineItem) => this.draftLineItemtoLineItem(context.projectKey, draftLineItem)) ?? [];
|
|
6328
|
-
const resource = {
|
|
6329
|
-
...getBaseResourceProperties(),
|
|
6330
|
-
...draft,
|
|
6331
|
-
custom: createCustomFields(draft.custom, context.projectKey, this._storage),
|
|
6332
|
-
textLineItems: [],
|
|
6333
|
-
lineItems,
|
|
6334
|
-
customer: draft.customer ? getReferenceFromResourceIdentifier(draft.customer, context.projectKey, this._storage) : void 0,
|
|
6335
|
-
store: draft.store ? getStoreKeyReference(draft.store, context.projectKey, this._storage) : void 0,
|
|
6336
|
-
businessUnit: draft.businessUnit ? getBusinessUnitKeyReference(draft.businessUnit, context.projectKey, this._storage) : void 0
|
|
6337
|
-
};
|
|
6338
|
-
return this.saveNew(context, resource);
|
|
6339
|
-
}
|
|
6340
|
-
draftLineItemtoLineItem = (projectKey, draftLineItem) => {
|
|
6341
|
-
const { sku, productId, variantId } = draftLineItem;
|
|
6342
|
-
const lineItem = {
|
|
6343
|
-
...getBaseResourceProperties(),
|
|
6344
|
-
...draftLineItem,
|
|
6345
|
-
addedAt: draftLineItem.addedAt ?? "",
|
|
6346
|
-
productId: draftLineItem.productId ?? "",
|
|
6347
|
-
name: {},
|
|
6348
|
-
variantId,
|
|
6349
|
-
published: true,
|
|
6350
|
-
quantity: draftLineItem.quantity ?? 1,
|
|
6351
|
-
productType: {
|
|
6352
|
-
typeId: "product-type",
|
|
6353
|
-
id: ""
|
|
6354
|
-
},
|
|
6355
|
-
custom: createCustomFields(draftLineItem.custom, projectKey, this._storage)
|
|
6356
|
-
};
|
|
6357
|
-
if (productId && variantId) return lineItem;
|
|
6358
|
-
if (sku) {
|
|
6359
|
-
const items = this._storage.query(projectKey, "product", { where: [`masterData(current(masterVariant(sku="${sku}"))) or masterData(current(variants(sku="${sku}")))`] });
|
|
6360
|
-
if (items.count === 0) throw new Error(`Product with sku ${sku} not found`);
|
|
6361
|
-
const product = items.results[0];
|
|
6362
|
-
lineItem.variantId = [product.masterData.current.masterVariant, ...product.masterData.current.variants].find((e) => e.sku === sku)?.id;
|
|
6363
|
-
lineItem.productId = product.id;
|
|
6364
|
-
return lineItem;
|
|
6365
|
-
}
|
|
6366
|
-
if (productId) {
|
|
6367
|
-
const items = this._storage.query(projectKey, "product", { where: [`id="${productId}"`] });
|
|
6368
|
-
if (items.count === 0) throw new Error(`Product with id ${productId} not found`);
|
|
6369
|
-
lineItem.variantId = items.results[0].masterData.current.masterVariant.id;
|
|
6370
|
-
return lineItem;
|
|
6371
|
-
}
|
|
6372
|
-
throw new Error("must provide either sku, productId or variantId for ShoppingListLineItem");
|
|
6373
|
-
};
|
|
6374
|
-
};
|
|
6375
|
-
|
|
6376
6423
|
//#endregion
|
|
6377
6424
|
//#region src/repositories/standalone-price.ts
|
|
6378
6425
|
var StandAlonePriceRepository = class extends AbstractResourceRepository {
|
|
@@ -6728,7 +6775,8 @@ const createRepositories = (config) => ({
|
|
|
6728
6775
|
"as-associate": {
|
|
6729
6776
|
cart: new AsAssociateCartRepository(config),
|
|
6730
6777
|
order: new AsAssociateOrderRepository(config),
|
|
6731
|
-
"quote-request": new AsAssociateQuoteRequestRepository(config)
|
|
6778
|
+
"quote-request": new AsAssociateQuoteRequestRepository(config),
|
|
6779
|
+
"shopping-list": new AsAssociateShoppingListRepository(config)
|
|
6732
6780
|
},
|
|
6733
6781
|
"associate-role": new AssociateRoleRepository(config),
|
|
6734
6782
|
"attribute-group": new AttributeGroupRepository(config),
|
|
@@ -6996,6 +7044,30 @@ var AsAssociateQuoteRequestService = class extends AbstractService {
|
|
|
6996
7044
|
}
|
|
6997
7045
|
};
|
|
6998
7046
|
|
|
7047
|
+
//#endregion
|
|
7048
|
+
//#region src/services/as-associate-shopping-list.ts
|
|
7049
|
+
var AsAssociateShoppingListService = class extends AbstractService {
|
|
7050
|
+
repository;
|
|
7051
|
+
constructor(parent, repository) {
|
|
7052
|
+
super(parent);
|
|
7053
|
+
this.repository = repository;
|
|
7054
|
+
}
|
|
7055
|
+
getBasePath() {
|
|
7056
|
+
return "shopping-lists";
|
|
7057
|
+
}
|
|
7058
|
+
registerRoutes(parent) {
|
|
7059
|
+
const basePath = this.getBasePath();
|
|
7060
|
+
const router = Router({ mergeParams: true });
|
|
7061
|
+
this.extraRoutes(router);
|
|
7062
|
+
router.get("/", this.get.bind(this));
|
|
7063
|
+
router.get("/:id", this.getWithId.bind(this));
|
|
7064
|
+
router.delete("/:id", this.deleteWithId.bind(this));
|
|
7065
|
+
router.post("/", this.post.bind(this));
|
|
7066
|
+
router.post("/:id", this.postWithId.bind(this));
|
|
7067
|
+
parent.use(`/${basePath}`, router);
|
|
7068
|
+
}
|
|
7069
|
+
};
|
|
7070
|
+
|
|
6999
7071
|
//#endregion
|
|
7000
7072
|
//#region src/services/as-associate.ts
|
|
7001
7073
|
var AsAssociateService = class {
|
|
@@ -7006,7 +7078,8 @@ var AsAssociateService = class {
|
|
|
7006
7078
|
this.subServices = {
|
|
7007
7079
|
order: new AsAssociateOrderService(this.router, repositories.order),
|
|
7008
7080
|
cart: new AsAssociateCartService(this.router, repositories.cart),
|
|
7009
|
-
"quote-request": new AsAssociateQuoteRequestService(this.router, repositories["quote-request"])
|
|
7081
|
+
"quote-request": new AsAssociateQuoteRequestService(this.router, repositories["quote-request"]),
|
|
7082
|
+
"shopping-list": new AsAssociateShoppingListService(this.router, repositories["shopping-list"])
|
|
7010
7083
|
};
|
|
7011
7084
|
parent.use("/as-associate/:associateId/in-business-unit/key=:businessUnitId", this.router);
|
|
7012
7085
|
}
|