@labdigital/commercetools-mock 2.11.0 → 2.12.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
@@ -1299,7 +1299,8 @@ var OAuth2Store = class {
1299
1299
  access_token: (0, import_crypto.randomBytes)(16).toString("base64"),
1300
1300
  token_type: "Bearer",
1301
1301
  expires_in: 172800,
1302
- scope: scope || "todo"
1302
+ scope: scope || "todo",
1303
+ refresh_token: `my-project-${(0, import_crypto.randomBytes)(16).toString("base64")}`
1303
1304
  };
1304
1305
  this.tokens.push(token);
1305
1306
  return token;
@@ -1312,7 +1313,8 @@ var OAuth2Store = class {
1312
1313
  access_token: (0, import_crypto.randomBytes)(16).toString("base64"),
1313
1314
  token_type: "Bearer",
1314
1315
  expires_in: 172800,
1315
- scope: scope ? `${scope} anonymous_id:${anonymousId}` : `anonymous_id:${anonymousId}`
1316
+ scope: scope ? `${scope} anonymous_id:${anonymousId}` : `anonymous_id:${anonymousId}`,
1317
+ refresh_token: `my-project-${(0, import_crypto.randomBytes)(16).toString("base64")}`
1316
1318
  };
1317
1319
  this.tokens.push(token);
1318
1320
  return token;
@@ -1322,11 +1324,29 @@ var OAuth2Store = class {
1322
1324
  access_token: (0, import_crypto.randomBytes)(16).toString("base64"),
1323
1325
  token_type: "Bearer",
1324
1326
  expires_in: 172800,
1325
- scope: scope ? `${scope} customer_id:${customerId}` : `customer_id:${customerId}`
1327
+ scope: scope ? `${scope} customer_id:${customerId}` : `customer_id:${customerId}`,
1328
+ refresh_token: `my-project-${(0, import_crypto.randomBytes)(16).toString("base64")}`
1326
1329
  };
1327
1330
  this.tokens.push(token);
1328
1331
  return token;
1329
1332
  }
1333
+ refreshToken(clientId, clientSecret, refreshToken) {
1334
+ const existing = this.tokens.find((t) => t.refresh_token === refreshToken);
1335
+ if (!existing) {
1336
+ return void 0;
1337
+ }
1338
+ const token = {
1339
+ ...existing,
1340
+ access_token: (0, import_crypto.randomBytes)(16).toString("base64")
1341
+ };
1342
+ this.tokens.push(token);
1343
+ return {
1344
+ access_token: token.access_token,
1345
+ token_type: token.token_type,
1346
+ expires_in: token.expires_in,
1347
+ scope: token.scope
1348
+ };
1349
+ }
1330
1350
  validateToken(token) {
1331
1351
  if (!this.validate)
1332
1352
  return true;
@@ -1466,11 +1486,36 @@ var OAuth2Server = class {
1466
1486
  );
1467
1487
  return response.status(200).send(token);
1468
1488
  } else if (grantType === "refresh_token") {
1469
- const token = this.store.getClientToken(
1489
+ const refreshToken = request.query.refresh_token?.toString();
1490
+ if (!refreshToken) {
1491
+ return next(
1492
+ new CommercetoolsError(
1493
+ {
1494
+ code: "invalid_request",
1495
+ message: "Missing required parameter: refresh_token."
1496
+ },
1497
+ 400
1498
+ )
1499
+ );
1500
+ }
1501
+ const token = this.store.refreshToken(
1470
1502
  request.credentials.clientId,
1471
1503
  request.credentials.clientSecret,
1472
- request.query.scope?.toString()
1504
+ refreshToken
1473
1505
  );
1506
+ if (!token) {
1507
+ return next(
1508
+ new CommercetoolsError(
1509
+ {
1510
+ statusCode: 400,
1511
+ message: "The refresh token was not found. It may have expired.",
1512
+ error: "invalid_grant",
1513
+ error_description: "The refresh token was not found. It may have expired."
1514
+ },
1515
+ 400
1516
+ )
1517
+ );
1518
+ }
1474
1519
  return response.status(200).send(token);
1475
1520
  } else {
1476
1521
  return next(