@devopness/sdk-js 3.5.0 → 3.5.1

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.
@@ -27,6 +27,11 @@ export declare class ApiBaseService {
27
27
  static set accessToken(value: string);
28
28
  static set onTokenExpired(callback: (accessToken: string) => void);
29
29
  protected isTokenExpired(response: AxiosResponse | undefined): boolean;
30
+ /**
31
+ * Decode the JWT payload so we can inspect the `exp` claim in both browser and Node runtimes.
32
+ * This avoids relying on a Node-only JWT helper while still tolerating malformed tokens safely.
33
+ */
34
+ private static decodeJwtPayload;
30
35
  baseURL(): string;
31
36
  protected post<T, B = undefined, R = AxiosResponse<T>>(endpoint: string, data?: B): Promise<R>;
32
37
  protected put<T, B = undefined, R = AxiosResponse<T>>(endpoint: string, data?: B): Promise<R>;
@@ -121,13 +121,44 @@ class ApiBaseService {
121
121
  ApiBaseService._onTokenExpired = callback;
122
122
  }
123
123
  isTokenExpired(response) {
124
- var _a, _b;
125
124
  if (!ApiBaseService.accessToken) {
126
125
  return false;
127
126
  }
128
- const decodedToken = JSON.parse(Buffer.from((_b = (_a = ApiBaseService.accessToken) === null || _a === void 0 ? void 0 : _a.split(".")) === null || _b === void 0 ? void 0 : _b[1], "base64").toString());
127
+ let decodedToken;
128
+ try {
129
+ decodedToken = JSON.parse(ApiBaseService.decodeJwtPayload(ApiBaseService.accessToken));
130
+ }
131
+ catch (_a) {
132
+ return false;
133
+ }
129
134
  return (response === null || response === void 0 ? void 0 : response.status) === 401 && decodedToken.exp < (new Date().getTime() / 1000);
130
135
  }
136
+ /**
137
+ * Decode the JWT payload so we can inspect the `exp` claim in both browser and Node runtimes.
138
+ * This avoids relying on a Node-only JWT helper while still tolerating malformed tokens safely.
139
+ */
140
+ static decodeJwtPayload(token) {
141
+ var _a;
142
+ try {
143
+ const payload = (_a = token.split(".")) === null || _a === void 0 ? void 0 : _a[1];
144
+ if (!payload) {
145
+ return "{}";
146
+ }
147
+ const base64 = payload.replace(/-/g, "+").replace(/_/g, "/");
148
+ const paddingLength = (4 - (base64.length % 4)) % 4;
149
+ const paddedBase64 = base64 + "=".repeat(paddingLength);
150
+ const binary = atob(paddedBase64);
151
+ return decodeURIComponent(Array.from(binary, (character) => {
152
+ const hex = character.charCodeAt(0).toString(16);
153
+ return `%${hex.length === 1 ? `0${hex}` : hex}`;
154
+ }).join(""));
155
+ }
156
+ catch (_b) {
157
+ // Malformed or legacy token payloads should not break the axios error path.
158
+ // Treat undecodable tokens as empty payloads and let the 401 handling continue.
159
+ return "{}";
160
+ }
161
+ }
131
162
  baseURL() {
132
163
  return this.api.defaults.baseURL ? this.api.defaults.baseURL : "";
133
164
  }
package/package.json CHANGED
@@ -1,13 +1,19 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@devopness/sdk-js",
4
- "version": "3.5.0",
4
+ "version": "3.5.1",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
8
  "description": "Devopness API JS/TS SDK - Painless essential DevOps to everyone",
9
9
  "main": "dist/index.js",
10
10
  "types": "dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.js"
15
+ }
16
+ },
11
17
  "files": [
12
18
  "dist"
13
19
  ],
@@ -19,6 +25,7 @@
19
25
  "docs-update-service-index": "npm run docs-remove-service-index && npm run docs-export-service-index",
20
26
  "docs": "npm run docs-update-service-index && typedoc",
21
27
  "lint": "eslint .",
28
+ "lint:fix": "eslint . --fix",
22
29
  "prepublishOnly": "npm run lint && npm test && npm run build",
23
30
  "test": "jest"
24
31
  },
@@ -50,23 +57,26 @@
50
57
  "url": "https://github.com/devopness/devopness/issues"
51
58
  },
52
59
  "homepage": "https://github.com/devopness/devopness#readme",
60
+ "engines": {
61
+ "node": ">=16"
62
+ },
53
63
  "devDependencies": {
54
64
  "@eslint/js": "^10.0.1",
55
- "@openapitools/openapi-generator-cli": "^2.39.0",
65
+ "@openapitools/openapi-generator-cli": "^2.39.1",
56
66
  "@types/jest": "^30.0.0",
57
- "@typescript-eslint/parser": "^8.61.1",
67
+ "@typescript-eslint/parser": "^8.62.1",
58
68
  "axios-mock-adapter": "^2.1.0",
59
- "eslint": "^10.5.0",
69
+ "eslint": "^10.6.0",
60
70
  "eslint-import-resolver-typescript": "^4.4.5",
61
71
  "eslint-plugin-import": "^2.32.0",
62
- "eslint-plugin-n": "^18.1.0",
72
+ "eslint-plugin-n": "^18.2.1",
63
73
  "eslint-plugin-promise": "^7.3.0",
64
74
  "husky": "9.1.7",
65
75
  "jest": "^30.4.2",
66
76
  "ts-jest": "^29.4.11",
67
77
  "typedoc": "^0.28.19",
68
- "typescript": "^5.9.3",
69
- "typescript-eslint": "^8.61.1"
78
+ "typescript": "^6.0.3",
79
+ "typescript-eslint": "^8.62.1"
70
80
  },
71
81
  "dependencies": {
72
82
  "@types/parse-link-header": "^2.0.3",