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