@mondaydotcomorg/atp-client 0.23.0 → 0.23.2

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.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
- * Note: Even expired tokens can be refreshed as long as the server session
70
- * still exists. The server accepts expired JWTs for the refresh endpoint.
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/token/refresh") || url.includes("/api/init");
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) {
@@ -1436,24 +1421,10 @@ function createExploreApiTool(client) {
1436
1421
  const results = await Promise.all(pathsToExplore.map(async (path) => {
1437
1422
  try {
1438
1423
  const result = await client.exploreAPI(path);
1439
- if (result.type === "directory") {
1440
- return {
1441
- success: true,
1442
- type: "directory",
1443
- path: result.path,
1444
- items: result.items
1445
- };
1446
- } else {
1447
- return {
1448
- success: true,
1449
- type: "function",
1450
- name: result.name,
1451
- description: result.description,
1452
- definition: result.definition,
1453
- group: result.group,
1454
- path: result.path
1455
- };
1456
- }
1424
+ return {
1425
+ success: true,
1426
+ ...result
1427
+ };
1457
1428
  } catch (error) {
1458
1429
  const message = error instanceof Error ? error.message : String(error);
1459
1430
  return {