@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.js
CHANGED
|
@@ -367,15 +367,47 @@ var OAuth2Server = class {
|
|
|
367
367
|
}
|
|
368
368
|
}
|
|
369
369
|
async inStoreCustomerTokenHandler(request, response, next) {
|
|
370
|
-
|
|
371
|
-
|
|
370
|
+
const projectKey = request.params.projectKey;
|
|
371
|
+
const storeKey = request.params.storeKey;
|
|
372
|
+
const grantType = request.query.grant_type || request.body.grant_type;
|
|
373
|
+
if (!grantType) {
|
|
374
|
+
return next(
|
|
375
|
+
new CommercetoolsError(
|
|
376
|
+
{
|
|
377
|
+
code: "invalid_request",
|
|
378
|
+
message: "Missing required parameter: grant_type."
|
|
379
|
+
},
|
|
380
|
+
400
|
|
381
|
+
)
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
if (grantType === "password") {
|
|
385
|
+
const username = request.query.username || request.body.username;
|
|
386
|
+
const password = hashPassword(
|
|
387
|
+
request.query.password || request.body.password
|
|
388
|
+
);
|
|
389
|
+
const scope = request.query.scope?.toString() || request.body.scope?.toString();
|
|
390
|
+
const result = this.customerRepository.query(
|
|
391
|
+
{ projectKey, storeKey },
|
|
372
392
|
{
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
393
|
+
where: [`email = "${username}"`, `password = "${password}"`]
|
|
394
|
+
}
|
|
395
|
+
);
|
|
396
|
+
if (result.count === 0) {
|
|
397
|
+
return next(
|
|
398
|
+
new CommercetoolsError(
|
|
399
|
+
{
|
|
400
|
+
code: "invalid_customer_account_credentials",
|
|
401
|
+
message: "Customer account with the given credentials not found."
|
|
402
|
+
},
|
|
403
|
+
400
|
|
404
|
+
)
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
const customer = result.results[0];
|
|
408
|
+
const token = this.store.getCustomerToken(projectKey, customer.id, scope);
|
|
409
|
+
return response.status(200).send(token);
|
|
410
|
+
}
|
|
379
411
|
}
|
|
380
412
|
async anonymousTokenHandler(request, response, next) {
|
|
381
413
|
const projectKey = request.params.projectKey;
|
|
@@ -1400,8 +1432,14 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
1400
1432
|
products: {
|
|
1401
1433
|
status: "Deactivated"
|
|
1402
1434
|
},
|
|
1435
|
+
productsSearch: {
|
|
1436
|
+
status: "Deactivated"
|
|
1437
|
+
},
|
|
1403
1438
|
orders: {
|
|
1404
1439
|
status: "Deactivated"
|
|
1440
|
+
},
|
|
1441
|
+
customers: {
|
|
1442
|
+
status: "Deactivated"
|
|
1405
1443
|
}
|
|
1406
1444
|
},
|
|
1407
1445
|
version: 1
|
|
@@ -3708,8 +3746,34 @@ var CustomerRepository = class extends AbstractResourceRepository {
|
|
|
3708
3746
|
...address,
|
|
3709
3747
|
id: generateRandomString(5)
|
|
3710
3748
|
})) ?? [];
|
|
3711
|
-
const
|
|
3712
|
-
|
|
3749
|
+
const lookupAdressId = (addresses2, addressId) => {
|
|
3750
|
+
if (addressId < addresses2.length) {
|
|
3751
|
+
const id = addresses2[addressId].id;
|
|
3752
|
+
if (!id) {
|
|
3753
|
+
throw new Error("Address ID is missing");
|
|
3754
|
+
}
|
|
3755
|
+
return id;
|
|
3756
|
+
}
|
|
3757
|
+
throw new CommercetoolsError({
|
|
3758
|
+
code: "InvalidInput",
|
|
3759
|
+
message: `Address with ID '${addressId}' not found.`,
|
|
3760
|
+
errors: [
|
|
3761
|
+
{
|
|
3762
|
+
code: "InvalidInput",
|
|
3763
|
+
message: `Address with ID '${addressId}' not found.`,
|
|
3764
|
+
field: "addressId"
|
|
3765
|
+
}
|
|
3766
|
+
]
|
|
3767
|
+
});
|
|
3768
|
+
};
|
|
3769
|
+
const defaultBillingAddressId = draft.defaultBillingAddress ? lookupAdressId(addresses, draft.defaultBillingAddress) : void 0;
|
|
3770
|
+
const defaultShippingAddressId = draft.defaultShippingAddress ? lookupAdressId(addresses, draft.defaultShippingAddress) : void 0;
|
|
3771
|
+
const shippingAddressIds = draft.shippingAddresses?.map(
|
|
3772
|
+
(addressId) => lookupAdressId(addresses, addressId)
|
|
3773
|
+
) ?? [];
|
|
3774
|
+
const billingAddressIds = draft.billingAddresses?.map(
|
|
3775
|
+
(addressId) => lookupAdressId(addresses, addressId)
|
|
3776
|
+
) ?? [];
|
|
3713
3777
|
const resource = {
|
|
3714
3778
|
...getBaseResourceProperties(),
|
|
3715
3779
|
key: draft.key,
|
|
@@ -3728,6 +3792,8 @@ var CustomerRepository = class extends AbstractResourceRepository {
|
|
|
3728
3792
|
externalId: draft.externalId,
|
|
3729
3793
|
defaultBillingAddressId,
|
|
3730
3794
|
defaultShippingAddressId,
|
|
3795
|
+
shippingAddressIds,
|
|
3796
|
+
billingAddressIds,
|
|
3731
3797
|
custom: createCustomFields(
|
|
3732
3798
|
draft.custom,
|
|
3733
3799
|
context.projectKey,
|
|
@@ -6729,6 +6795,13 @@ var ProjectUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
6729
6795
|
changeCurrencies(context, resource, { currencies }) {
|
|
6730
6796
|
resource.currencies = currencies;
|
|
6731
6797
|
}
|
|
6798
|
+
changeCustomerSearchStatus(context, resource, { status }) {
|
|
6799
|
+
if (!resource.searchIndexing?.customers) {
|
|
6800
|
+
throw new Error("Invalid project state");
|
|
6801
|
+
}
|
|
6802
|
+
resource.searchIndexing.customers.status = status;
|
|
6803
|
+
resource.searchIndexing.customers.lastModifiedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
6804
|
+
}
|
|
6732
6805
|
changeLanguages(context, resource, { languages }) {
|
|
6733
6806
|
resource.languages = languages;
|
|
6734
6807
|
}
|
|
@@ -6754,7 +6827,15 @@ var ProjectUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
6754
6827
|
resource.searchIndexing.orders.status = status;
|
|
6755
6828
|
resource.searchIndexing.orders.lastModifiedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
6756
6829
|
}
|
|
6757
|
-
changeProductSearchIndexingEnabled(context, resource, { enabled }) {
|
|
6830
|
+
changeProductSearchIndexingEnabled(context, resource, { enabled, mode }) {
|
|
6831
|
+
if (mode === "ProductsSearch") {
|
|
6832
|
+
if (!resource.searchIndexing?.productsSearch) {
|
|
6833
|
+
throw new Error("Invalid project state");
|
|
6834
|
+
}
|
|
6835
|
+
resource.searchIndexing.productsSearch.status = enabled ? "Activated" : "Deactivated";
|
|
6836
|
+
resource.searchIndexing.productsSearch.lastModifiedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
6837
|
+
return;
|
|
6838
|
+
}
|
|
6758
6839
|
if (!resource.searchIndexing?.products) {
|
|
6759
6840
|
throw new Error("Invalid project state");
|
|
6760
6841
|
}
|
|
@@ -8222,9 +8303,9 @@ var InventoryEntryService = class extends AbstractService {
|
|
|
8222
8303
|
}
|
|
8223
8304
|
};
|
|
8224
8305
|
|
|
8225
|
-
// src/services/my-
|
|
8306
|
+
// src/services/my-business-unit.ts
|
|
8226
8307
|
import { Router as Router2 } from "express";
|
|
8227
|
-
var
|
|
8308
|
+
var MyBusinessUnitService = class extends AbstractService {
|
|
8228
8309
|
repository;
|
|
8229
8310
|
constructor(parent, repository) {
|
|
8230
8311
|
super(parent);
|
|
@@ -8237,6 +8318,26 @@ var MyCartService = class extends AbstractService {
|
|
|
8237
8318
|
const basePath = this.getBasePath();
|
|
8238
8319
|
const router = Router2({ mergeParams: true });
|
|
8239
8320
|
this.extraRoutes(router);
|
|
8321
|
+
router.get("/business-units/", this.get.bind(this));
|
|
8322
|
+
parent.use(`/${basePath}`, router);
|
|
8323
|
+
}
|
|
8324
|
+
};
|
|
8325
|
+
|
|
8326
|
+
// src/services/my-cart.ts
|
|
8327
|
+
import { Router as Router3 } from "express";
|
|
8328
|
+
var MyCartService = class extends AbstractService {
|
|
8329
|
+
repository;
|
|
8330
|
+
constructor(parent, repository) {
|
|
8331
|
+
super(parent);
|
|
8332
|
+
this.repository = repository;
|
|
8333
|
+
}
|
|
8334
|
+
getBasePath() {
|
|
8335
|
+
return "me";
|
|
8336
|
+
}
|
|
8337
|
+
registerRoutes(parent) {
|
|
8338
|
+
const basePath = this.getBasePath();
|
|
8339
|
+
const router = Router3({ mergeParams: true });
|
|
8340
|
+
this.extraRoutes(router);
|
|
8240
8341
|
router.get("/active-cart", this.activeCart.bind(this));
|
|
8241
8342
|
router.get("/carts/", this.get.bind(this));
|
|
8242
8343
|
router.get("/carts/:id", this.getWithId.bind(this));
|
|
@@ -8255,7 +8356,7 @@ var MyCartService = class extends AbstractService {
|
|
|
8255
8356
|
};
|
|
8256
8357
|
|
|
8257
8358
|
// src/services/my-customer.ts
|
|
8258
|
-
import { Router as
|
|
8359
|
+
import { Router as Router4 } from "express";
|
|
8259
8360
|
var MyCustomerService = class extends AbstractService {
|
|
8260
8361
|
repository;
|
|
8261
8362
|
constructor(parent, repository) {
|
|
@@ -8267,7 +8368,7 @@ var MyCustomerService = class extends AbstractService {
|
|
|
8267
8368
|
}
|
|
8268
8369
|
registerRoutes(parent) {
|
|
8269
8370
|
const basePath = this.getBasePath();
|
|
8270
|
-
const router =
|
|
8371
|
+
const router = Router4({ mergeParams: true });
|
|
8271
8372
|
this.extraRoutes(router);
|
|
8272
8373
|
router.get("", this.getMe.bind(this));
|
|
8273
8374
|
router.post("", this.updateMe.bind(this));
|
|
@@ -8363,7 +8464,7 @@ var MyCustomerService = class extends AbstractService {
|
|
|
8363
8464
|
};
|
|
8364
8465
|
|
|
8365
8466
|
// src/services/my-order.ts
|
|
8366
|
-
import { Router as
|
|
8467
|
+
import { Router as Router5 } from "express";
|
|
8367
8468
|
var MyOrderService = class extends AbstractService {
|
|
8368
8469
|
repository;
|
|
8369
8470
|
constructor(parent, repository) {
|
|
@@ -8375,7 +8476,7 @@ var MyOrderService = class extends AbstractService {
|
|
|
8375
8476
|
}
|
|
8376
8477
|
registerRoutes(parent) {
|
|
8377
8478
|
const basePath = this.getBasePath();
|
|
8378
|
-
const router =
|
|
8479
|
+
const router = Router5({ mergeParams: true });
|
|
8379
8480
|
this.extraRoutes(router);
|
|
8380
8481
|
router.get("/orders/", this.get.bind(this));
|
|
8381
8482
|
router.get("/orders/:id", this.getWithId.bind(this));
|
|
@@ -8737,6 +8838,7 @@ var createServices = (router, repos) => ({
|
|
|
8737
8838
|
"my-cart": new MyCartService(router, repos["my-cart"]),
|
|
8738
8839
|
"my-order": new MyOrderService(router, repos["my-order"]),
|
|
8739
8840
|
"my-customer": new MyCustomerService(router, repos["my-customer"]),
|
|
8841
|
+
"my-business-unit": new MyBusinessUnitService(router, repos["business-unit"]),
|
|
8740
8842
|
"my-payment": new MyPaymentService(router, repos["my-payment"]),
|
|
8741
8843
|
"my-shopping-list": new MyShoppingListService(
|
|
8742
8844
|
router,
|