@labdigital/commercetools-mock 2.12.0 → 2.12.2

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
@@ -1294,6 +1294,9 @@ var OAuth2Store = class {
1294
1294
  constructor(validate = true) {
1295
1295
  this.validate = validate;
1296
1296
  }
1297
+ addToken(token) {
1298
+ this.tokens.push(token);
1299
+ }
1297
1300
  getClientToken(clientId, clientSecret, scope) {
1298
1301
  const token = {
1299
1302
  access_token: (0, import_crypto.randomBytes)(16).toString("base64"),
@@ -1302,7 +1305,7 @@ var OAuth2Store = class {
1302
1305
  scope: scope || "todo",
1303
1306
  refresh_token: `my-project-${(0, import_crypto.randomBytes)(16).toString("base64")}`
1304
1307
  };
1305
- this.tokens.push(token);
1308
+ this.addToken(token);
1306
1309
  return token;
1307
1310
  }
1308
1311
  getAnonymousToken(scope, anonymousId) {
@@ -1316,7 +1319,7 @@ var OAuth2Store = class {
1316
1319
  scope: scope ? `${scope} anonymous_id:${anonymousId}` : `anonymous_id:${anonymousId}`,
1317
1320
  refresh_token: `my-project-${(0, import_crypto.randomBytes)(16).toString("base64")}`
1318
1321
  };
1319
- this.tokens.push(token);
1322
+ this.addToken(token);
1320
1323
  return token;
1321
1324
  }
1322
1325
  getCustomerToken(scope, customerId) {
@@ -1327,7 +1330,7 @@ var OAuth2Store = class {
1327
1330
  scope: scope ? `${scope} customer_id:${customerId}` : `customer_id:${customerId}`,
1328
1331
  refresh_token: `my-project-${(0, import_crypto.randomBytes)(16).toString("base64")}`
1329
1332
  };
1330
- this.tokens.push(token);
1333
+ this.addToken(token);
1331
1334
  return token;
1332
1335
  }
1333
1336
  refreshToken(clientId, clientSecret, refreshToken) {
@@ -1339,7 +1342,7 @@ var OAuth2Store = class {
1339
1342
  ...existing,
1340
1343
  access_token: (0, import_crypto.randomBytes)(16).toString("base64")
1341
1344
  };
1342
- this.tokens.push(token);
1345
+ this.addToken(token);
1343
1346
  return {
1344
1347
  access_token: token.access_token,
1345
1348
  token_type: token.token_type,
@@ -1486,7 +1489,7 @@ var OAuth2Server = class {
1486
1489
  );
1487
1490
  return response.status(200).send(token);
1488
1491
  } else if (grantType === "refresh_token") {
1489
- const refreshToken = request.query.refresh_token?.toString();
1492
+ const refreshToken = request.query.refresh_token?.toString() || request.body.refresh_token;
1490
1493
  if (!refreshToken) {
1491
1494
  return next(
1492
1495
  new CommercetoolsError(
@@ -7321,6 +7324,9 @@ var CommercetoolsMock = class {
7321
7324
  this._storage
7322
7325
  );
7323
7326
  }
7327
+ authStore() {
7328
+ return this._oauth2.store;
7329
+ }
7324
7330
  runServer(port = 3e3, options) {
7325
7331
  const server = this.app.listen(port, () => {
7326
7332
  console.info(`Mock server listening at http://localhost:${port}`);