@labdigital/commercetools-mock 2.35.0 → 2.37.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 +123 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +119 -17
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/oauth/server.test.ts +42 -0
- package/src/oauth/server.ts +44 -7
- package/src/repositories/customer/index.ts +43 -9
- package/src/repositories/project.ts +26 -1
- package/src/services/customer.test.ts +45 -5
- package/src/services/index.ts +2 -0
- package/src/services/my-business-unit.ts +28 -0
- package/src/services/my-customer.test.ts +2 -0
- package/src/services/project.test.ts +6 -0
- package/src/storage/in-memory.ts +6 -0
- package/src/types.ts +2 -1
package/dist/index.cjs
CHANGED
|
@@ -36,7 +36,7 @@ __export(src_exports, {
|
|
|
36
36
|
module.exports = __toCommonJS(src_exports);
|
|
37
37
|
|
|
38
38
|
// src/ctMock.ts
|
|
39
|
-
var
|
|
39
|
+
var import_express7 = __toESM(require("express"), 1);
|
|
40
40
|
var import_light_my_request = __toESM(require("light-my-request"), 1);
|
|
41
41
|
var import_morgan = __toESM(require("morgan"), 1);
|
|
42
42
|
var import_msw = require("msw");
|
|
@@ -404,15 +404,47 @@ var OAuth2Server = class {
|
|
|
404
404
|
}
|
|
405
405
|
}
|
|
406
406
|
async inStoreCustomerTokenHandler(request, response, next) {
|
|
407
|
-
|
|
408
|
-
|
|
407
|
+
const projectKey = request.params.projectKey;
|
|
408
|
+
const storeKey = request.params.storeKey;
|
|
409
|
+
const grantType = request.query.grant_type || request.body.grant_type;
|
|
410
|
+
if (!grantType) {
|
|
411
|
+
return next(
|
|
412
|
+
new CommercetoolsError(
|
|
413
|
+
{
|
|
414
|
+
code: "invalid_request",
|
|
415
|
+
message: "Missing required parameter: grant_type."
|
|
416
|
+
},
|
|
417
|
+
400
|
|
418
|
+
)
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
if (grantType === "password") {
|
|
422
|
+
const username = request.query.username || request.body.username;
|
|
423
|
+
const password = hashPassword(
|
|
424
|
+
request.query.password || request.body.password
|
|
425
|
+
);
|
|
426
|
+
const scope = request.query.scope?.toString() || request.body.scope?.toString();
|
|
427
|
+
const result = this.customerRepository.query(
|
|
428
|
+
{ projectKey, storeKey },
|
|
409
429
|
{
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
430
|
+
where: [`email = "${username}"`, `password = "${password}"`]
|
|
431
|
+
}
|
|
432
|
+
);
|
|
433
|
+
if (result.count === 0) {
|
|
434
|
+
return next(
|
|
435
|
+
new CommercetoolsError(
|
|
436
|
+
{
|
|
437
|
+
code: "invalid_customer_account_credentials",
|
|
438
|
+
message: "Customer account with the given credentials not found."
|
|
439
|
+
},
|
|
440
|
+
400
|
|
441
|
+
)
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
const customer = result.results[0];
|
|
445
|
+
const token = this.store.getCustomerToken(projectKey, customer.id, scope);
|
|
446
|
+
return response.status(200).send(token);
|
|
447
|
+
}
|
|
416
448
|
}
|
|
417
449
|
async anonymousTokenHandler(request, response, next) {
|
|
418
450
|
const projectKey = request.params.projectKey;
|
|
@@ -1437,8 +1469,14 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
1437
1469
|
products: {
|
|
1438
1470
|
status: "Deactivated"
|
|
1439
1471
|
},
|
|
1472
|
+
productsSearch: {
|
|
1473
|
+
status: "Deactivated"
|
|
1474
|
+
},
|
|
1440
1475
|
orders: {
|
|
1441
1476
|
status: "Deactivated"
|
|
1477
|
+
},
|
|
1478
|
+
customers: {
|
|
1479
|
+
status: "Deactivated"
|
|
1442
1480
|
}
|
|
1443
1481
|
},
|
|
1444
1482
|
version: 1
|
|
@@ -3745,8 +3783,34 @@ var CustomerRepository = class extends AbstractResourceRepository {
|
|
|
3745
3783
|
...address,
|
|
3746
3784
|
id: generateRandomString(5)
|
|
3747
3785
|
})) ?? [];
|
|
3748
|
-
const
|
|
3749
|
-
|
|
3786
|
+
const lookupAdressId = (addresses2, addressId) => {
|
|
3787
|
+
if (addressId < addresses2.length) {
|
|
3788
|
+
const id = addresses2[addressId].id;
|
|
3789
|
+
if (!id) {
|
|
3790
|
+
throw new Error("Address ID is missing");
|
|
3791
|
+
}
|
|
3792
|
+
return id;
|
|
3793
|
+
}
|
|
3794
|
+
throw new CommercetoolsError({
|
|
3795
|
+
code: "InvalidInput",
|
|
3796
|
+
message: `Address with ID '${addressId}' not found.`,
|
|
3797
|
+
errors: [
|
|
3798
|
+
{
|
|
3799
|
+
code: "InvalidInput",
|
|
3800
|
+
message: `Address with ID '${addressId}' not found.`,
|
|
3801
|
+
field: "addressId"
|
|
3802
|
+
}
|
|
3803
|
+
]
|
|
3804
|
+
});
|
|
3805
|
+
};
|
|
3806
|
+
const defaultBillingAddressId = draft.defaultBillingAddress ? lookupAdressId(addresses, draft.defaultBillingAddress) : void 0;
|
|
3807
|
+
const defaultShippingAddressId = draft.defaultShippingAddress ? lookupAdressId(addresses, draft.defaultShippingAddress) : void 0;
|
|
3808
|
+
const shippingAddressIds = draft.shippingAddresses?.map(
|
|
3809
|
+
(addressId) => lookupAdressId(addresses, addressId)
|
|
3810
|
+
) ?? [];
|
|
3811
|
+
const billingAddressIds = draft.billingAddresses?.map(
|
|
3812
|
+
(addressId) => lookupAdressId(addresses, addressId)
|
|
3813
|
+
) ?? [];
|
|
3750
3814
|
const resource = {
|
|
3751
3815
|
...getBaseResourceProperties(),
|
|
3752
3816
|
key: draft.key,
|
|
@@ -3765,6 +3829,8 @@ var CustomerRepository = class extends AbstractResourceRepository {
|
|
|
3765
3829
|
externalId: draft.externalId,
|
|
3766
3830
|
defaultBillingAddressId,
|
|
3767
3831
|
defaultShippingAddressId,
|
|
3832
|
+
shippingAddressIds,
|
|
3833
|
+
billingAddressIds,
|
|
3768
3834
|
custom: createCustomFields(
|
|
3769
3835
|
draft.custom,
|
|
3770
3836
|
context.projectKey,
|
|
@@ -6766,6 +6832,13 @@ var ProjectUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
6766
6832
|
changeCurrencies(context, resource, { currencies }) {
|
|
6767
6833
|
resource.currencies = currencies;
|
|
6768
6834
|
}
|
|
6835
|
+
changeCustomerSearchStatus(context, resource, { status }) {
|
|
6836
|
+
if (!resource.searchIndexing?.customers) {
|
|
6837
|
+
throw new Error("Invalid project state");
|
|
6838
|
+
}
|
|
6839
|
+
resource.searchIndexing.customers.status = status;
|
|
6840
|
+
resource.searchIndexing.customers.lastModifiedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
6841
|
+
}
|
|
6769
6842
|
changeLanguages(context, resource, { languages }) {
|
|
6770
6843
|
resource.languages = languages;
|
|
6771
6844
|
}
|
|
@@ -6791,7 +6864,15 @@ var ProjectUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
6791
6864
|
resource.searchIndexing.orders.status = status;
|
|
6792
6865
|
resource.searchIndexing.orders.lastModifiedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
6793
6866
|
}
|
|
6794
|
-
changeProductSearchIndexingEnabled(context, resource, { enabled }) {
|
|
6867
|
+
changeProductSearchIndexingEnabled(context, resource, { enabled, mode }) {
|
|
6868
|
+
if (mode === "ProductsSearch") {
|
|
6869
|
+
if (!resource.searchIndexing?.productsSearch) {
|
|
6870
|
+
throw new Error("Invalid project state");
|
|
6871
|
+
}
|
|
6872
|
+
resource.searchIndexing.productsSearch.status = enabled ? "Activated" : "Deactivated";
|
|
6873
|
+
resource.searchIndexing.productsSearch.lastModifiedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
6874
|
+
return;
|
|
6875
|
+
}
|
|
6795
6876
|
if (!resource.searchIndexing?.products) {
|
|
6796
6877
|
throw new Error("Invalid project state");
|
|
6797
6878
|
}
|
|
@@ -8259,9 +8340,9 @@ var InventoryEntryService = class extends AbstractService {
|
|
|
8259
8340
|
}
|
|
8260
8341
|
};
|
|
8261
8342
|
|
|
8262
|
-
// src/services/my-
|
|
8343
|
+
// src/services/my-business-unit.ts
|
|
8263
8344
|
var import_express3 = require("express");
|
|
8264
|
-
var
|
|
8345
|
+
var MyBusinessUnitService = class extends AbstractService {
|
|
8265
8346
|
repository;
|
|
8266
8347
|
constructor(parent, repository) {
|
|
8267
8348
|
super(parent);
|
|
@@ -8274,6 +8355,26 @@ var MyCartService = class extends AbstractService {
|
|
|
8274
8355
|
const basePath = this.getBasePath();
|
|
8275
8356
|
const router = (0, import_express3.Router)({ mergeParams: true });
|
|
8276
8357
|
this.extraRoutes(router);
|
|
8358
|
+
router.get("/business-units/", this.get.bind(this));
|
|
8359
|
+
parent.use(`/${basePath}`, router);
|
|
8360
|
+
}
|
|
8361
|
+
};
|
|
8362
|
+
|
|
8363
|
+
// src/services/my-cart.ts
|
|
8364
|
+
var import_express4 = require("express");
|
|
8365
|
+
var MyCartService = class extends AbstractService {
|
|
8366
|
+
repository;
|
|
8367
|
+
constructor(parent, repository) {
|
|
8368
|
+
super(parent);
|
|
8369
|
+
this.repository = repository;
|
|
8370
|
+
}
|
|
8371
|
+
getBasePath() {
|
|
8372
|
+
return "me";
|
|
8373
|
+
}
|
|
8374
|
+
registerRoutes(parent) {
|
|
8375
|
+
const basePath = this.getBasePath();
|
|
8376
|
+
const router = (0, import_express4.Router)({ mergeParams: true });
|
|
8377
|
+
this.extraRoutes(router);
|
|
8277
8378
|
router.get("/active-cart", this.activeCart.bind(this));
|
|
8278
8379
|
router.get("/carts/", this.get.bind(this));
|
|
8279
8380
|
router.get("/carts/:id", this.getWithId.bind(this));
|
|
@@ -8292,7 +8393,7 @@ var MyCartService = class extends AbstractService {
|
|
|
8292
8393
|
};
|
|
8293
8394
|
|
|
8294
8395
|
// src/services/my-customer.ts
|
|
8295
|
-
var
|
|
8396
|
+
var import_express5 = require("express");
|
|
8296
8397
|
var MyCustomerService = class extends AbstractService {
|
|
8297
8398
|
repository;
|
|
8298
8399
|
constructor(parent, repository) {
|
|
@@ -8304,7 +8405,7 @@ var MyCustomerService = class extends AbstractService {
|
|
|
8304
8405
|
}
|
|
8305
8406
|
registerRoutes(parent) {
|
|
8306
8407
|
const basePath = this.getBasePath();
|
|
8307
|
-
const router = (0,
|
|
8408
|
+
const router = (0, import_express5.Router)({ mergeParams: true });
|
|
8308
8409
|
this.extraRoutes(router);
|
|
8309
8410
|
router.get("", this.getMe.bind(this));
|
|
8310
8411
|
router.post("", this.updateMe.bind(this));
|
|
@@ -8400,7 +8501,7 @@ var MyCustomerService = class extends AbstractService {
|
|
|
8400
8501
|
};
|
|
8401
8502
|
|
|
8402
8503
|
// src/services/my-order.ts
|
|
8403
|
-
var
|
|
8504
|
+
var import_express6 = require("express");
|
|
8404
8505
|
var MyOrderService = class extends AbstractService {
|
|
8405
8506
|
repository;
|
|
8406
8507
|
constructor(parent, repository) {
|
|
@@ -8412,7 +8513,7 @@ var MyOrderService = class extends AbstractService {
|
|
|
8412
8513
|
}
|
|
8413
8514
|
registerRoutes(parent) {
|
|
8414
8515
|
const basePath = this.getBasePath();
|
|
8415
|
-
const router = (0,
|
|
8516
|
+
const router = (0, import_express6.Router)({ mergeParams: true });
|
|
8416
8517
|
this.extraRoutes(router);
|
|
8417
8518
|
router.get("/orders/", this.get.bind(this));
|
|
8418
8519
|
router.get("/orders/:id", this.getWithId.bind(this));
|
|
@@ -8774,6 +8875,7 @@ var createServices = (router, repos) => ({
|
|
|
8774
8875
|
"my-cart": new MyCartService(router, repos["my-cart"]),
|
|
8775
8876
|
"my-order": new MyOrderService(router, repos["my-order"]),
|
|
8776
8877
|
"my-customer": new MyCustomerService(router, repos["my-customer"]),
|
|
8878
|
+
"my-business-unit": new MyBusinessUnitService(router, repos["business-unit"]),
|
|
8777
8879
|
"my-payment": new MyPaymentService(router, repos["my-payment"]),
|
|
8778
8880
|
"my-shopping-list": new MyShoppingListService(
|
|
8779
8881
|
router,
|
|
@@ -8918,9 +9020,9 @@ var CommercetoolsMock = class {
|
|
|
8918
9020
|
createApp(options) {
|
|
8919
9021
|
this._repositories = createRepositories(this._storage);
|
|
8920
9022
|
this._oauth2.setCustomerRepository(this._repositories.customer);
|
|
8921
|
-
const app = (0,
|
|
8922
|
-
const projectRouter =
|
|
8923
|
-
projectRouter.use(
|
|
9023
|
+
const app = (0, import_express7.default)();
|
|
9024
|
+
const projectRouter = import_express7.default.Router({ mergeParams: true });
|
|
9025
|
+
projectRouter.use(import_express7.default.json());
|
|
8924
9026
|
if (!options?.silent) {
|
|
8925
9027
|
app.use((0, import_morgan.default)("tiny"));
|
|
8926
9028
|
}
|