@labdigital/commercetools-mock 2.27.0 → 2.28.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.cjs +72 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +72 -16
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/oauth/server.test.ts +1 -0
- package/src/repositories/business-unit.ts +40 -8
- package/src/repositories/cart/actions.ts +8 -4
- package/src/repositories/customer/index.ts +1 -0
- package/src/repositories/helpers.ts +1 -2
- package/src/repositories/index.ts +2 -0
- package/src/repositories/order/actions.ts +22 -0
- package/src/repositories/product-tailoring.ts +34 -0
- package/src/repositories/shipping-method/actions.ts +10 -1
- package/src/repositories/shipping-method/index.ts +1 -0
- package/src/services/customer.test.ts +2 -0
- package/src/services/my-customer.test.ts +11 -3
- package/src/services/order.test.ts +161 -0
- package/src/services/shipping-method.test.ts +1 -0
- package/src/storage/in-memory.ts +2 -0
- package/src/types.ts +2 -0
package/dist/index.cjs
CHANGED
|
@@ -1540,6 +1540,7 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
1540
1540
|
"product-selection": /* @__PURE__ */ new Map(),
|
|
1541
1541
|
"product-type": /* @__PURE__ */ new Map(),
|
|
1542
1542
|
"product-projection": /* @__PURE__ */ new Map(),
|
|
1543
|
+
"product-tailoring": /* @__PURE__ */ new Map(),
|
|
1543
1544
|
"review": /* @__PURE__ */ new Map(),
|
|
1544
1545
|
"shipping-method": /* @__PURE__ */ new Map(),
|
|
1545
1546
|
"staged-quote": /* @__PURE__ */ new Map(),
|
|
@@ -1924,6 +1925,22 @@ var AbstractUpdateHandler = class {
|
|
|
1924
1925
|
}
|
|
1925
1926
|
};
|
|
1926
1927
|
|
|
1928
|
+
// src/repositories/product-tailoring.ts
|
|
1929
|
+
var ProductTailoringRepository = class extends AbstractResourceRepository {
|
|
1930
|
+
constructor(storage) {
|
|
1931
|
+
super("product-tailoring", storage);
|
|
1932
|
+
this.actions = new ProductTailoringUpdateHandler(this._storage);
|
|
1933
|
+
}
|
|
1934
|
+
create(context, draft) {
|
|
1935
|
+
throw new Error("Create method for product-tailoring not implemented.");
|
|
1936
|
+
}
|
|
1937
|
+
};
|
|
1938
|
+
var ProductTailoringUpdateHandler = class extends AbstractUpdateHandler {
|
|
1939
|
+
setSlug() {
|
|
1940
|
+
throw new Error("SetSlug method for product-tailoring not implemented.");
|
|
1941
|
+
}
|
|
1942
|
+
};
|
|
1943
|
+
|
|
1927
1944
|
// src/repositories/helpers.ts
|
|
1928
1945
|
var import_uuid4 = require("uuid");
|
|
1929
1946
|
var createAddress = (base, projectKey, storage) => {
|
|
@@ -2247,6 +2264,18 @@ var BusinessUnitRepository = class extends AbstractResourceRepository {
|
|
|
2247
2264
|
this.actions = new BusinessUnitUpdateHandler(this._storage);
|
|
2248
2265
|
}
|
|
2249
2266
|
create(context, draft) {
|
|
2267
|
+
const addresses = draft.addresses?.map((address) => ({
|
|
2268
|
+
...address,
|
|
2269
|
+
id: generateRandomString(5)
|
|
2270
|
+
})) ?? [];
|
|
2271
|
+
const defaultBillingAddressId = addresses.length > 0 && draft.defaultBillingAddress !== void 0 ? addresses[draft.defaultBillingAddress].id : void 0;
|
|
2272
|
+
const defaultShippingAddressId = addresses.length > 0 && draft.defaultShippingAddress !== void 0 ? addresses[draft.defaultShippingAddress].id : void 0;
|
|
2273
|
+
const shippingAddressIds = draft.shippingAddresses?.map(
|
|
2274
|
+
(i) => addresses[i].id
|
|
2275
|
+
);
|
|
2276
|
+
const billingAddressIds = draft.billingAddresses?.map(
|
|
2277
|
+
(i) => addresses[i].id
|
|
2278
|
+
);
|
|
2250
2279
|
const resource = {
|
|
2251
2280
|
...getBaseResourceProperties(),
|
|
2252
2281
|
key: draft.key,
|
|
@@ -2257,18 +2286,18 @@ var BusinessUnitRepository = class extends AbstractResourceRepository {
|
|
|
2257
2286
|
storeMode: draft.storeMode,
|
|
2258
2287
|
name: draft.name,
|
|
2259
2288
|
contactEmail: draft.contactEmail,
|
|
2260
|
-
addresses
|
|
2261
|
-
(a) => createAddress(a, context.projectKey, this._storage)
|
|
2262
|
-
),
|
|
2289
|
+
addresses,
|
|
2263
2290
|
custom: createCustomFields(
|
|
2264
2291
|
draft.custom,
|
|
2265
2292
|
context.projectKey,
|
|
2266
2293
|
this._storage
|
|
2267
2294
|
),
|
|
2268
|
-
shippingAddressIds
|
|
2269
|
-
|
|
2270
|
-
|
|
2295
|
+
shippingAddressIds,
|
|
2296
|
+
billingAddressIds,
|
|
2297
|
+
defaultShippingAddressId,
|
|
2298
|
+
defaultBillingAddressId,
|
|
2271
2299
|
associateMode: draft.associateMode,
|
|
2300
|
+
approvalRuleMode: draft.approvalRuleMode,
|
|
2272
2301
|
associates: draft.associates?.map(
|
|
2273
2302
|
(a) => createAssociate(a, context.projectKey, this._storage)
|
|
2274
2303
|
)
|
|
@@ -2342,6 +2371,9 @@ var BusinessUnitUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
2342
2371
|
resource.addresses.push(newAddress);
|
|
2343
2372
|
}
|
|
2344
2373
|
}
|
|
2374
|
+
changeApprovalRuleMode(context, resource, { approvalRuleMode }) {
|
|
2375
|
+
resource.approvalRuleMode = approvalRuleMode;
|
|
2376
|
+
}
|
|
2345
2377
|
changeAssociateMode(context, resource, { associateMode }) {
|
|
2346
2378
|
resource.associateMode = associateMode;
|
|
2347
2379
|
}
|
|
@@ -2641,10 +2673,12 @@ var CartUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
2641
2673
|
}
|
|
2642
2674
|
}
|
|
2643
2675
|
setDirectDiscounts(context, resource, { discounts }) {
|
|
2644
|
-
resource.directDiscounts = discounts.map(
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2676
|
+
resource.directDiscounts = discounts.map(
|
|
2677
|
+
(discount) => ({
|
|
2678
|
+
...discount,
|
|
2679
|
+
id: (0, import_uuid5.v4)()
|
|
2680
|
+
})
|
|
2681
|
+
);
|
|
2648
2682
|
}
|
|
2649
2683
|
setLineItemShippingDetails(context, resource, {
|
|
2650
2684
|
action,
|
|
@@ -3454,7 +3488,8 @@ var CustomerRepository = class extends AbstractResourceRepository {
|
|
|
3454
3488
|
draft.custom,
|
|
3455
3489
|
context.projectKey,
|
|
3456
3490
|
this._storage
|
|
3457
|
-
)
|
|
3491
|
+
),
|
|
3492
|
+
stores: []
|
|
3458
3493
|
};
|
|
3459
3494
|
return this.saveNew(context, resource);
|
|
3460
3495
|
}
|
|
@@ -3892,12 +3927,13 @@ var MyCustomerRepository = class extends CustomerRepository {
|
|
|
3892
3927
|
};
|
|
3893
3928
|
|
|
3894
3929
|
// src/repositories/my-order.ts
|
|
3895
|
-
var
|
|
3930
|
+
var import_assert4 = __toESM(require("assert"), 1);
|
|
3896
3931
|
|
|
3897
3932
|
// src/repositories/order/index.ts
|
|
3898
|
-
var
|
|
3933
|
+
var import_assert3 = __toESM(require("assert"), 1);
|
|
3899
3934
|
|
|
3900
3935
|
// src/repositories/order/actions.ts
|
|
3936
|
+
var import_assert2 = __toESM(require("assert"), 1);
|
|
3901
3937
|
var OrderUpdateHandler = class extends AbstractUpdateHandler {
|
|
3902
3938
|
addPayment(context, resource, { payment }) {
|
|
3903
3939
|
const resolvedPayment = this._storage.getByResourceIdentifier(
|
|
@@ -3993,6 +4029,21 @@ var OrderUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
3993
4029
|
};
|
|
3994
4030
|
}
|
|
3995
4031
|
}
|
|
4032
|
+
setDeliveryCustomField(context, resource, { deliveryId, name, value }) {
|
|
4033
|
+
(0, import_assert2.default)(resource.shippingInfo, "shippingInfo is not defined");
|
|
4034
|
+
if (Array.isArray(resource.shippingInfo.deliveries)) {
|
|
4035
|
+
resource.shippingInfo.deliveries.map((delivery) => {
|
|
4036
|
+
if (delivery.id !== deliveryId)
|
|
4037
|
+
throw "No matching delivery id found";
|
|
4038
|
+
if (delivery.custom) {
|
|
4039
|
+
const update = delivery.custom.fields;
|
|
4040
|
+
update[name] = value;
|
|
4041
|
+
Object.assign(delivery.custom.fields, update);
|
|
4042
|
+
}
|
|
4043
|
+
return delivery;
|
|
4044
|
+
});
|
|
4045
|
+
}
|
|
4046
|
+
}
|
|
3996
4047
|
setLocale(context, resource, { locale }) {
|
|
3997
4048
|
resource.locale = locale;
|
|
3998
4049
|
}
|
|
@@ -4074,7 +4125,7 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
4074
4125
|
this.actions = new OrderUpdateHandler(storage);
|
|
4075
4126
|
}
|
|
4076
4127
|
create(context, draft) {
|
|
4077
|
-
(0,
|
|
4128
|
+
(0, import_assert3.default)(draft.cart, "draft.cart is missing");
|
|
4078
4129
|
return this.createFromCart(
|
|
4079
4130
|
context,
|
|
4080
4131
|
{
|
|
@@ -4115,7 +4166,7 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
4115
4166
|
return this.saveNew(context, resource);
|
|
4116
4167
|
}
|
|
4117
4168
|
import(context, draft) {
|
|
4118
|
-
(0,
|
|
4169
|
+
(0, import_assert3.default)(this, "OrderRepository not valid");
|
|
4119
4170
|
const resource = {
|
|
4120
4171
|
...getBaseResourceProperties(),
|
|
4121
4172
|
billingAddress: createAddress(
|
|
@@ -4258,7 +4309,7 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
4258
4309
|
// src/repositories/my-order.ts
|
|
4259
4310
|
var MyOrderRepository = class extends OrderRepository {
|
|
4260
4311
|
create(context, draft) {
|
|
4261
|
-
(0,
|
|
4312
|
+
(0, import_assert4.default)(draft.id, "draft.id is missing");
|
|
4262
4313
|
const cartIdentifier = {
|
|
4263
4314
|
id: draft.id,
|
|
4264
4315
|
typeId: "cart"
|
|
@@ -6249,6 +6300,9 @@ var ShippingMethodUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
6249
6300
|
shippingRates: []
|
|
6250
6301
|
});
|
|
6251
6302
|
}
|
|
6303
|
+
changeActive(_context, resource, { active }) {
|
|
6304
|
+
resource.active = active;
|
|
6305
|
+
}
|
|
6252
6306
|
changeIsDefault(_context, resource, { isDefault }) {
|
|
6253
6307
|
resource.isDefault = isDefault;
|
|
6254
6308
|
}
|
|
@@ -6318,6 +6372,7 @@ var ShippingMethodRepository = class extends AbstractResourceRepository {
|
|
|
6318
6372
|
const resource = {
|
|
6319
6373
|
...getBaseResourceProperties(),
|
|
6320
6374
|
...draft,
|
|
6375
|
+
active: draft.active ?? true,
|
|
6321
6376
|
taxCategory: getReferenceFromResourceIdentifier(
|
|
6322
6377
|
draft.taxCategory,
|
|
6323
6378
|
context.projectKey,
|
|
@@ -7134,6 +7189,7 @@ var createRepositories = (storage) => ({
|
|
|
7134
7189
|
"product-discount": new ProductDiscountRepository(storage),
|
|
7135
7190
|
"product-projection": new ProductProjectionRepository(storage),
|
|
7136
7191
|
"product-selection": new ProductSelectionRepository(storage),
|
|
7192
|
+
"product-tailoring": new ProductTailoringRepository(storage),
|
|
7137
7193
|
"project": new ProjectRepository(storage),
|
|
7138
7194
|
"review": new ReviewRepository(storage),
|
|
7139
7195
|
"quote": new QuoteRepository(storage),
|