@shoper/cli 0.2.1-3 → 0.2.1-4

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.
@@ -1,4 +1,5 @@
1
1
  import jwt from 'jsonwebtoken';
2
+ import differenceBy from 'lodash/differenceBy.js';
2
3
  export class CLiAuthTokensUtils {
3
4
  static getTokenPayload(token) {
4
5
  try {
@@ -33,13 +34,15 @@ export class CLiAuthTokensUtils {
33
34
  if (!decoded) {
34
35
  return { isValid: false, message: 'Failed to decode token.' };
35
36
  }
36
- const { header } = decoded;
37
37
  const payload = decoded.payload;
38
- const expectedPayloadKeys = ['sub', 'exp', 'iat', 'iss', 'nbf', 'scope', 'id', 'name', 'key'];
39
- for (const key of Object.keys(payload)) {
40
- if (!expectedPayloadKeys.includes(key)) {
41
- return { isValid: false, message: `Unexpected key in payload: ${key}` };
42
- }
38
+ const expectedPayloadKeys = ['exp', 'iat', 'iss', 'nbf', 'scope', 'id', 'name', 'key'];
39
+ const missingKeys = differenceBy(expectedPayloadKeys, Object.keys(payload));
40
+ if (missingKeys.length > 0) {
41
+ return { isValid: false, message: `Missing keys in payload: ${missingKeys.join(', ')}` };
42
+ }
43
+ const unexpectedKeys = differenceBy(Object.keys(payload), expectedPayloadKeys);
44
+ if (unexpectedKeys.length > 0) {
45
+ return { isValid: false, message: `Unexpected keys in payload: ${unexpectedKeys.join(', ')}` };
43
46
  }
44
47
  // Check if the token has expired
45
48
  const now = Math.floor(Date.now() / 1000); // Current time in seconds
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@shoper/cli",
3
3
  "packageManager": "yarn@3.2.0",
4
4
  "sideEffects": false,
5
- "version": "0.2.1-3",
5
+ "version": "0.2.1-4",
6
6
  "description": "CLI tool for Shoper",
7
7
  "author": "Joanna Firek",
8
8
  "license": "MIT",