@mondaydotcomorg/atp-client 0.23.0 → 0.23.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.
- package/dist/client.d.ts +0 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js.map +1 -1
- package/dist/core/base-session.d.ts +28 -6
- package/dist/core/base-session.d.ts.map +1 -1
- package/dist/core/base-session.js +20 -4
- package/dist/core/base-session.js.map +1 -1
- package/dist/core/in-process-session.d.ts +0 -5
- package/dist/core/in-process-session.d.ts.map +1 -1
- package/dist/core/in-process-session.js +2 -12
- package/dist/core/in-process-session.js.map +1 -1
- package/dist/core/index.cjs +29 -44
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.js +29 -44
- package/dist/core/index.js.map +1 -1
- package/dist/core/session.d.ts +0 -4
- package/dist/core/session.d.ts.map +1 -1
- package/dist/core/session.js +2 -25
- package/dist/core/session.js.map +1 -1
- package/dist/index.cjs +29 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +29 -44
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +0 -1
- package/src/core/base-session.ts +34 -7
- package/src/core/in-process-session.ts +3 -15
- package/src/core/session.ts +3 -30
package/dist/index.js
CHANGED
|
@@ -24,6 +24,7 @@ var BaseSession = class {
|
|
|
24
24
|
tokenRotateAt;
|
|
25
25
|
initPromise;
|
|
26
26
|
refreshPromise;
|
|
27
|
+
storedInitParams;
|
|
27
28
|
tokenRefreshConfig = {
|
|
28
29
|
enabled: true,
|
|
29
30
|
bufferMs: 1e3
|
|
@@ -37,6 +38,19 @@ var BaseSession = class {
|
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
/**
|
|
41
|
+
* Perform token refresh by re-initializing the session.
|
|
42
|
+
* Resets the init guard and calls init() again with the stored params,
|
|
43
|
+
* effectively creating a fresh session without depending on the old
|
|
44
|
+
* session still existing in the server's cache.
|
|
45
|
+
*/
|
|
46
|
+
async doRefreshToken() {
|
|
47
|
+
if (!this.storedInitParams) {
|
|
48
|
+
throw new Error("Cannot refresh token: init params not stored. Was init() called?");
|
|
49
|
+
}
|
|
50
|
+
this.initPromise = void 0;
|
|
51
|
+
await this.init(this.storedInitParams.clientInfo, this.storedInitParams.tools, this.storedInitParams.services);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
40
54
|
* Gets the unique client ID.
|
|
41
55
|
*/
|
|
42
56
|
getClientId() {
|
|
@@ -66,8 +80,8 @@ var BaseSession = class {
|
|
|
66
80
|
* This is called automatically before requests when autoRefresh is enabled.
|
|
67
81
|
* Uses a shared promise to prevent concurrent refresh requests.
|
|
68
82
|
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
83
|
+
* Refresh works by re-initializing the session (calling init() again),
|
|
84
|
+
* so it does not depend on the old session still existing in the server's cache.
|
|
71
85
|
*/
|
|
72
86
|
async refreshTokenIfNeeded() {
|
|
73
87
|
if (!this.tokenRefreshConfig.enabled) {
|
|
@@ -100,10 +114,11 @@ var BaseSession = class {
|
|
|
100
114
|
this.tokenRotateAt = credentials.tokenRotateAt;
|
|
101
115
|
}
|
|
102
116
|
/**
|
|
103
|
-
* Check if URL should skip token refresh (to avoid infinite recursion)
|
|
117
|
+
* Check if URL should skip token refresh (to avoid infinite recursion).
|
|
118
|
+
* Since refresh now calls init(), we only need to guard the init path.
|
|
104
119
|
*/
|
|
105
120
|
shouldSkipRefreshForUrl(url) {
|
|
106
|
-
return url.includes("/api/
|
|
121
|
+
return url.includes("/api/init");
|
|
107
122
|
}
|
|
108
123
|
};
|
|
109
124
|
|
|
@@ -127,6 +142,11 @@ var ClientSession = class extends BaseSession {
|
|
|
127
142
|
* The server generates and returns a unique client ID and token.
|
|
128
143
|
*/
|
|
129
144
|
async init(clientInfo, tools, services) {
|
|
145
|
+
this.storedInitParams = {
|
|
146
|
+
clientInfo,
|
|
147
|
+
tools,
|
|
148
|
+
services
|
|
149
|
+
};
|
|
130
150
|
if (this.initPromise) {
|
|
131
151
|
await this.initPromise;
|
|
132
152
|
return {
|
|
@@ -188,32 +208,6 @@ var ClientSession = class extends BaseSession {
|
|
|
188
208
|
return this.baseUrl;
|
|
189
209
|
}
|
|
190
210
|
/**
|
|
191
|
-
* Perform the actual token refresh via HTTP
|
|
192
|
-
*/
|
|
193
|
-
async doRefreshToken() {
|
|
194
|
-
const url = `${this.baseUrl}/api/token/refresh`;
|
|
195
|
-
const body = JSON.stringify({
|
|
196
|
-
clientId: this.clientId
|
|
197
|
-
});
|
|
198
|
-
const headers = {
|
|
199
|
-
"Content-Type": "application/json",
|
|
200
|
-
...this.customHeaders,
|
|
201
|
-
"X-Client-ID": this.clientId,
|
|
202
|
-
Authorization: `Bearer ${this.clientToken}`
|
|
203
|
-
};
|
|
204
|
-
const response = await fetch(url, {
|
|
205
|
-
method: "POST",
|
|
206
|
-
headers,
|
|
207
|
-
body
|
|
208
|
-
});
|
|
209
|
-
if (!response.ok) {
|
|
210
|
-
const errorText = await response.text();
|
|
211
|
-
throw new Error(`Token refresh failed: ${response.status} ${response.statusText} - ${errorText}`);
|
|
212
|
-
}
|
|
213
|
-
const data = await response.json();
|
|
214
|
-
this.updateTokenState(data);
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
211
|
* Prepares headers for a request, refreshing token if needed and calling preRequest hook if configured
|
|
218
212
|
*/
|
|
219
213
|
async prepareHeaders(method, url, body) {
|
|
@@ -254,6 +248,11 @@ var InProcessSession = class extends BaseSession {
|
|
|
254
248
|
* Initializes the client session with the in-process server.
|
|
255
249
|
*/
|
|
256
250
|
async init(clientInfo, tools, services) {
|
|
251
|
+
this.storedInitParams = {
|
|
252
|
+
clientInfo,
|
|
253
|
+
tools,
|
|
254
|
+
services
|
|
255
|
+
};
|
|
257
256
|
if (this.initPromise) {
|
|
258
257
|
await this.initPromise;
|
|
259
258
|
return {
|
|
@@ -310,20 +309,6 @@ var InProcessSession = class extends BaseSession {
|
|
|
310
309
|
return "";
|
|
311
310
|
}
|
|
312
311
|
/**
|
|
313
|
-
* Perform the actual token refresh via in-process server call
|
|
314
|
-
*/
|
|
315
|
-
async doRefreshToken() {
|
|
316
|
-
const ctx = await this.createContext({
|
|
317
|
-
method: "POST",
|
|
318
|
-
path: "/api/token/refresh",
|
|
319
|
-
body: {
|
|
320
|
-
clientId: this.clientId
|
|
321
|
-
}
|
|
322
|
-
});
|
|
323
|
-
const result = await this.server.handleTokenRefresh(ctx);
|
|
324
|
-
this.updateTokenState(result);
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
312
|
* Prepares headers for a request, refreshing token if needed
|
|
328
313
|
*/
|
|
329
314
|
async prepareHeaders(_method, url, _body) {
|