@labdigital/commercetools-mock 2.9.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.d.cts CHANGED
@@ -81,6 +81,7 @@ declare class CartRepository extends AbstractResourceRepository<'cart'> {
81
81
  getActiveCart(projectKey: string): Cart | undefined;
82
82
  actions: {
83
83
  addLineItem: (context: RepositoryContext, resource: Writable<Cart>, { productId, variantId, sku, quantity }: CartAddLineItemAction) => void;
84
+ recalculate: () => void;
84
85
  addItemShippingAddress: (context: RepositoryContext, resource: Writable<Cart>, { action, address }: CartAddItemShippingAddressAction) => void;
85
86
  changeLineItemQuantity: (context: RepositoryContext, resource: Writable<Cart>, { lineItemId, lineItemKey, quantity }: CartChangeLineItemQuantityAction) => void;
86
87
  removeLineItem: (context: RepositoryContext, resource: Writable<Cart>, { lineItemId, quantity }: CartRemoveLineItemAction) => void;
package/dist/index.d.ts CHANGED
@@ -81,6 +81,7 @@ declare class CartRepository extends AbstractResourceRepository<'cart'> {
81
81
  getActiveCart(projectKey: string): Cart | undefined;
82
82
  actions: {
83
83
  addLineItem: (context: RepositoryContext, resource: Writable<Cart>, { productId, variantId, sku, quantity }: CartAddLineItemAction) => void;
84
+ recalculate: () => void;
84
85
  addItemShippingAddress: (context: RepositoryContext, resource: Writable<Cart>, { action, address }: CartAddItemShippingAddressAction) => void;
85
86
  changeLineItemQuantity: (context: RepositoryContext, resource: Writable<Cart>, { lineItemId, lineItemKey, quantity }: CartChangeLineItemQuantityAction) => void;
86
87
  removeLineItem: (context: RepositoryContext, resource: Writable<Cart>, { lineItemId, quantity }: CartRemoveLineItemAction) => void;
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,
@@ -2315,6 +2338,8 @@ var CartRepository = class extends AbstractResourceRepository {
2315
2338
  }
2316
2339
  resource.totalPrice.centAmount = calculateCartTotalPrice(resource);
2317
2340
  },
2341
+ recalculate: () => {
2342
+ },
2318
2343
  addItemShippingAddress: (context, resource, { action, address }) => {
2319
2344
  const newAddress = createAddress(
2320
2345
  address,
@@ -2560,7 +2585,7 @@ var CartRepository = class extends AbstractResourceRepository {
2560
2585
  );
2561
2586
  }
2562
2587
  return {
2563
- id: uuidv43(),
2588
+ id: uuidv44(),
2564
2589
  productId: product.id,
2565
2590
  productKey: product.key,
2566
2591
  productSlug: product.masterData.current.slug,
@@ -2731,14 +2756,14 @@ var CartDiscountRepository = class extends AbstractResourceRepository {
2731
2756
  };
2732
2757
 
2733
2758
  // src/repositories/category.ts
2734
- import { v4 as uuidv44 } from "uuid";
2759
+ import { v4 as uuidv45 } from "uuid";
2735
2760
  var CategoryRepository = class extends AbstractResourceRepository {
2736
2761
  getTypeId() {
2737
2762
  return "category";
2738
2763
  }
2739
2764
  assetFromAssetDraft = (draft, context) => ({
2740
2765
  ...draft,
2741
- id: uuidv44(),
2766
+ id: uuidv45(),
2742
2767
  custom: createCustomFields(draft.custom, context.projectKey, this._storage)
2743
2768
  });
2744
2769
  create(context, draft) {
@@ -2753,7 +2778,7 @@ var CategoryRepository = class extends AbstractResourceRepository {
2753
2778
  ancestors: [],
2754
2779
  // TODO
2755
2780
  assets: draft.assets?.map((d) => ({
2756
- id: uuidv44(),
2781
+ id: uuidv45(),
2757
2782
  name: d.name,
2758
2783
  description: d.description,
2759
2784
  sources: d.sources,
@@ -3749,7 +3774,7 @@ var OrderEditRepository = class extends AbstractResourceRepository {
3749
3774
  };
3750
3775
 
3751
3776
  // src/repositories/payment.ts
3752
- import { v4 as uuidv45 } from "uuid";
3777
+ import { v4 as uuidv46 } from "uuid";
3753
3778
  var PaymentRepository = class extends AbstractResourceRepository {
3754
3779
  getTypeId() {
3755
3780
  return "payment";
@@ -3784,7 +3809,7 @@ var PaymentRepository = class extends AbstractResourceRepository {
3784
3809
  }
3785
3810
  transactionFromTransactionDraft = (draft, context) => ({
3786
3811
  ...draft,
3787
- id: uuidv45(),
3812
+ id: uuidv46(),
3788
3813
  amount: createCentPrecisionMoney(draft.amount),
3789
3814
  custom: createCustomFields(draft.custom, context.projectKey, this._storage),
3790
3815
  state: draft.state ?? "Initial"
@@ -3868,7 +3893,7 @@ var PaymentRepository = class extends AbstractResourceRepository {
3868
3893
  };
3869
3894
 
3870
3895
  // src/repositories/product.ts
3871
- import { v4 as uuidv46 } from "uuid";
3896
+ import { v4 as uuidv47 } from "uuid";
3872
3897
  import deepEqual2 from "deep-equal";
3873
3898
  var ProductRepository = class extends AbstractResourceRepository {
3874
3899
  getTypeId() {
@@ -3974,7 +3999,7 @@ var ProductRepository = class extends AbstractResourceRepository {
3974
3999
  }
3975
4000
  priceFromDraft(context, draft) {
3976
4001
  return {
3977
- id: uuidv46(),
4002
+ id: uuidv47(),
3978
4003
  key: draft.key,
3979
4004
  country: draft.country,
3980
4005
  value: createTypedMoney(draft.value),
@@ -6016,7 +6041,7 @@ var SubscriptionRepository = class extends AbstractResourceRepository {
6016
6041
  };
6017
6042
 
6018
6043
  // src/repositories/tax-category.ts
6019
- import { v4 as uuidv47 } from "uuid";
6044
+ import { v4 as uuidv48 } from "uuid";
6020
6045
  var TaxCategoryRepository = class extends AbstractResourceRepository {
6021
6046
  getTypeId() {
6022
6047
  return "tax-category";
@@ -6032,7 +6057,7 @@ var TaxCategoryRepository = class extends AbstractResourceRepository {
6032
6057
  }
6033
6058
  taxRateFromTaxRateDraft = (draft) => ({
6034
6059
  ...draft,
6035
- id: uuidv47(),
6060
+ id: uuidv48(),
6036
6061
  amount: draft.amount || 0
6037
6062
  });
6038
6063
  actions = {
@@ -6591,7 +6616,7 @@ var CustomerGroupService = class extends AbstractService {
6591
6616
  };
6592
6617
 
6593
6618
  // src/services/customer.ts
6594
- import { v4 as uuidv48 } from "uuid";
6619
+ import { v4 as uuidv49 } from "uuid";
6595
6620
  var CustomerService = class extends AbstractService {
6596
6621
  repository;
6597
6622
  constructor(parent, repository) {
@@ -6615,7 +6640,7 @@ var CustomerService = class extends AbstractService {
6615
6640
  ...rest,
6616
6641
  customerId: customer.results[0].id,
6617
6642
  expiresAt: new Date(Date.now() + ttlMinutes * 60).toISOString(),
6618
- value: uuidv48()
6643
+ value: uuidv49()
6619
6644
  });
6620
6645
  });
6621
6646
  }