@labdigital/commercetools-mock 2.36.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 CHANGED
@@ -404,15 +404,47 @@ var OAuth2Server = class {
404
404
  }
405
405
  }
406
406
  async inStoreCustomerTokenHandler(request, response, next) {
407
- return next(
408
- new CommercetoolsError(
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
- code: "invalid_client",
411
- message: "Not implemented yet in commercetools-mock"
412
- },
413
- 401
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
@@ -6794,6 +6832,13 @@ var ProjectUpdateHandler = class extends AbstractUpdateHandler {
6794
6832
  changeCurrencies(context, resource, { currencies }) {
6795
6833
  resource.currencies = currencies;
6796
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
+ }
6797
6842
  changeLanguages(context, resource, { languages }) {
6798
6843
  resource.languages = languages;
6799
6844
  }
@@ -6819,7 +6864,15 @@ var ProjectUpdateHandler = class extends AbstractUpdateHandler {
6819
6864
  resource.searchIndexing.orders.status = status;
6820
6865
  resource.searchIndexing.orders.lastModifiedAt = (/* @__PURE__ */ new Date()).toISOString();
6821
6866
  }
6822
- 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
+ }
6823
6876
  if (!resource.searchIndexing?.products) {
6824
6877
  throw new Error("Invalid project state");
6825
6878
  }