@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.js CHANGED
@@ -367,15 +367,47 @@ var OAuth2Server = class {
367
367
  }
368
368
  }
369
369
  async inStoreCustomerTokenHandler(request, response, next) {
370
- return next(
371
- new CommercetoolsError(
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
- code: "invalid_client",
374
- message: "Not implemented yet in commercetools-mock"
375
- },
376
- 401
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
@@ -6757,6 +6795,13 @@ var ProjectUpdateHandler = class extends AbstractUpdateHandler {
6757
6795
  changeCurrencies(context, resource, { currencies }) {
6758
6796
  resource.currencies = currencies;
6759
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
+ }
6760
6805
  changeLanguages(context, resource, { languages }) {
6761
6806
  resource.languages = languages;
6762
6807
  }
@@ -6782,7 +6827,15 @@ var ProjectUpdateHandler = class extends AbstractUpdateHandler {
6782
6827
  resource.searchIndexing.orders.status = status;
6783
6828
  resource.searchIndexing.orders.lastModifiedAt = (/* @__PURE__ */ new Date()).toISOString();
6784
6829
  }
6785
- 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
+ }
6786
6839
  if (!resource.searchIndexing?.products) {
6787
6840
  throw new Error("Invalid project state");
6788
6841
  }