@labdigital/commercetools-mock 2.10.0 → 2.11.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
@@ -1250,6 +1250,7 @@ import express from "express";
1250
1250
 
1251
1251
  // src/oauth/store.ts
1252
1252
  import { randomBytes } from "crypto";
1253
+ import { v4 as uuidv42 } from "uuid";
1253
1254
  var OAuth2Store = class {
1254
1255
  tokens = [];
1255
1256
  validate = true;
@@ -1266,12 +1267,25 @@ var OAuth2Store = class {
1266
1267
  this.tokens.push(token);
1267
1268
  return token;
1268
1269
  }
1270
+ getAnonymousToken(scope, anonymousId) {
1271
+ if (!anonymousId) {
1272
+ anonymousId = uuidv42();
1273
+ }
1274
+ const token = {
1275
+ access_token: randomBytes(16).toString("base64"),
1276
+ token_type: "Bearer",
1277
+ expires_in: 172800,
1278
+ scope: scope ? `${scope} anonymous_id:${anonymousId}` : `anonymous_id:${anonymousId}`
1279
+ };
1280
+ this.tokens.push(token);
1281
+ return token;
1282
+ }
1269
1283
  getCustomerToken(scope, customerId) {
1270
1284
  const token = {
1271
1285
  access_token: randomBytes(16).toString("base64"),
1272
1286
  token_type: "Bearer",
1273
1287
  expires_in: 172800,
1274
- scope: scope ? `${scope} custome_id:${customerId}` : `customer_id: ${customerId}`
1288
+ scope: scope ? `${scope} customer_id:${customerId}` : `customer_id:${customerId}`
1275
1289
  };
1276
1290
  this.tokens.push(token);
1277
1291
  return token;
@@ -1486,15 +1500,24 @@ var OAuth2Server = class {
1486
1500
  );
1487
1501
  }
1488
1502
  async anonymousTokenHandler(request, response, next) {
1489
- return next(
1490
- new CommercetoolsError(
1491
- {
1492
- code: "invalid_client",
1493
- message: "Not implemented yet in commercetools-mock"
1494
- },
1495
- 401
1496
- )
1497
- );
1503
+ const grantType = request.query.grant_type || request.body.grant_type;
1504
+ if (!grantType) {
1505
+ return next(
1506
+ new CommercetoolsError(
1507
+ {
1508
+ code: "invalid_request",
1509
+ message: "Missing required parameter: grant_type."
1510
+ },
1511
+ 400
1512
+ )
1513
+ );
1514
+ }
1515
+ if (grantType === "client_credentials") {
1516
+ const scope = request.query.scope?.toString() || request.body.scope?.toString();
1517
+ const anonymous_id = void 0;
1518
+ const token = this.store.getAnonymousToken(scope, anonymous_id);
1519
+ return response.status(200).send(token);
1520
+ }
1498
1521
  }
1499
1522
  };
1500
1523
 
@@ -1554,7 +1577,7 @@ var DEFAULT_API_HOSTNAME = "https://api.*.commercetools.com";
1554
1577
  var DEFAULT_AUTH_HOSTNAME = "https://auth.*.commercetools.com";
1555
1578
 
1556
1579
  // src/repositories/helpers.ts
1557
- import { v4 as uuidv42 } from "uuid";
1580
+ import { v4 as uuidv43 } from "uuid";
1558
1581
  var createAddress = (base, projectKey, storage) => {
1559
1582
  if (!base)
1560
1583
  return void 0;
@@ -1592,7 +1615,7 @@ var createCustomFields = (draft, projectKey, storage) => {
1592
1615
  };
1593
1616
  };
1594
1617
  var createPrice = (draft) => ({
1595
- id: uuidv42(),
1618
+ id: uuidv43(),
1596
1619
  value: createTypedMoney(draft.value)
1597
1620
  });
1598
1621
  var createCentPrecisionMoney = (value) => {
@@ -2158,7 +2181,7 @@ var BusinessUnitRepository = class extends AbstractResourceRepository {
2158
2181
  };
2159
2182
 
2160
2183
  // src/repositories/cart.ts
2161
- import { v4 as uuidv43 } from "uuid";
2184
+ import { v4 as uuidv44 } from "uuid";
2162
2185
  var CartRepository = class extends AbstractResourceRepository {
2163
2186
  getTypeId() {
2164
2187
  return "cart";
@@ -2291,7 +2314,7 @@ var CartRepository = class extends AbstractResourceRepository {
2291
2314
  );
2292
2315
  }
2293
2316
  resource.lineItems.push({
2294
- id: uuidv43(),
2317
+ id: uuidv44(),
2295
2318
  productId: product.id,
2296
2319
  productKey: product.key,
2297
2320
  productSlug: product.masterData.current.slug,
@@ -2562,7 +2585,7 @@ var CartRepository = class extends AbstractResourceRepository {
2562
2585
  );
2563
2586
  }
2564
2587
  return {
2565
- id: uuidv43(),
2588
+ id: uuidv44(),
2566
2589
  productId: product.id,
2567
2590
  productKey: product.key,
2568
2591
  productSlug: product.masterData.current.slug,
@@ -2733,14 +2756,14 @@ var CartDiscountRepository = class extends AbstractResourceRepository {
2733
2756
  };
2734
2757
 
2735
2758
  // src/repositories/category.ts
2736
- import { v4 as uuidv44 } from "uuid";
2759
+ import { v4 as uuidv45 } from "uuid";
2737
2760
  var CategoryRepository = class extends AbstractResourceRepository {
2738
2761
  getTypeId() {
2739
2762
  return "category";
2740
2763
  }
2741
2764
  assetFromAssetDraft = (draft, context) => ({
2742
2765
  ...draft,
2743
- id: uuidv44(),
2766
+ id: uuidv45(),
2744
2767
  custom: createCustomFields(draft.custom, context.projectKey, this._storage)
2745
2768
  });
2746
2769
  create(context, draft) {
@@ -2755,7 +2778,7 @@ var CategoryRepository = class extends AbstractResourceRepository {
2755
2778
  ancestors: [],
2756
2779
  // TODO
2757
2780
  assets: draft.assets?.map((d) => ({
2758
- id: uuidv44(),
2781
+ id: uuidv45(),
2759
2782
  name: d.name,
2760
2783
  description: d.description,
2761
2784
  sources: d.sources,
@@ -3751,7 +3774,7 @@ var OrderEditRepository = class extends AbstractResourceRepository {
3751
3774
  };
3752
3775
 
3753
3776
  // src/repositories/payment.ts
3754
- import { v4 as uuidv45 } from "uuid";
3777
+ import { v4 as uuidv46 } from "uuid";
3755
3778
  var PaymentRepository = class extends AbstractResourceRepository {
3756
3779
  getTypeId() {
3757
3780
  return "payment";
@@ -3786,7 +3809,7 @@ var PaymentRepository = class extends AbstractResourceRepository {
3786
3809
  }
3787
3810
  transactionFromTransactionDraft = (draft, context) => ({
3788
3811
  ...draft,
3789
- id: uuidv45(),
3812
+ id: uuidv46(),
3790
3813
  amount: createCentPrecisionMoney(draft.amount),
3791
3814
  custom: createCustomFields(draft.custom, context.projectKey, this._storage),
3792
3815
  state: draft.state ?? "Initial"
@@ -3870,7 +3893,7 @@ var PaymentRepository = class extends AbstractResourceRepository {
3870
3893
  };
3871
3894
 
3872
3895
  // src/repositories/product.ts
3873
- import { v4 as uuidv46 } from "uuid";
3896
+ import { v4 as uuidv47 } from "uuid";
3874
3897
  import deepEqual2 from "deep-equal";
3875
3898
  var ProductRepository = class extends AbstractResourceRepository {
3876
3899
  getTypeId() {
@@ -3976,7 +3999,7 @@ var ProductRepository = class extends AbstractResourceRepository {
3976
3999
  }
3977
4000
  priceFromDraft(context, draft) {
3978
4001
  return {
3979
- id: uuidv46(),
4002
+ id: uuidv47(),
3980
4003
  key: draft.key,
3981
4004
  country: draft.country,
3982
4005
  value: createTypedMoney(draft.value),
@@ -6018,7 +6041,7 @@ var SubscriptionRepository = class extends AbstractResourceRepository {
6018
6041
  };
6019
6042
 
6020
6043
  // src/repositories/tax-category.ts
6021
- import { v4 as uuidv47 } from "uuid";
6044
+ import { v4 as uuidv48 } from "uuid";
6022
6045
  var TaxCategoryRepository = class extends AbstractResourceRepository {
6023
6046
  getTypeId() {
6024
6047
  return "tax-category";
@@ -6034,7 +6057,7 @@ var TaxCategoryRepository = class extends AbstractResourceRepository {
6034
6057
  }
6035
6058
  taxRateFromTaxRateDraft = (draft) => ({
6036
6059
  ...draft,
6037
- id: uuidv47(),
6060
+ id: uuidv48(),
6038
6061
  amount: draft.amount || 0
6039
6062
  });
6040
6063
  actions = {
@@ -6593,7 +6616,7 @@ var CustomerGroupService = class extends AbstractService {
6593
6616
  };
6594
6617
 
6595
6618
  // src/services/customer.ts
6596
- import { v4 as uuidv48 } from "uuid";
6619
+ import { v4 as uuidv49 } from "uuid";
6597
6620
  var CustomerService = class extends AbstractService {
6598
6621
  repository;
6599
6622
  constructor(parent, repository) {
@@ -6617,7 +6640,7 @@ var CustomerService = class extends AbstractService {
6617
6640
  ...rest,
6618
6641
  customerId: customer.results[0].id,
6619
6642
  expiresAt: new Date(Date.now() + ttlMinutes * 60).toISOString(),
6620
- value: uuidv48()
6643
+ value: uuidv49()
6621
6644
  });
6622
6645
  });
6623
6646
  }