@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/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -43,7 +43,6 @@ interface InProcessServer {
|
|
|
43
43
|
handleExplore(ctx: unknown): Promise<unknown>;
|
|
44
44
|
handleExecute(ctx: unknown): Promise<unknown>;
|
|
45
45
|
handleResume(ctx: unknown, executionId: string): Promise<unknown>;
|
|
46
|
-
handleTokenRefresh(ctx: unknown): Promise<unknown>;
|
|
47
46
|
}
|
|
48
47
|
|
|
49
48
|
/**
|
package/src/core/base-session.ts
CHANGED
|
@@ -29,6 +29,15 @@ export interface ISession {
|
|
|
29
29
|
setTokenRefreshConfig(config: Partial<TokenRefreshConfig>): void;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Stored init parameters for re-initialization during token refresh.
|
|
34
|
+
*/
|
|
35
|
+
export interface StoredInitParams {
|
|
36
|
+
clientInfo?: { name?: string; version?: string; [key: string]: unknown };
|
|
37
|
+
tools?: ClientToolDefinition[];
|
|
38
|
+
services?: { hasLLM: boolean; hasApproval: boolean; hasEmbedding: boolean; hasTools: boolean };
|
|
39
|
+
}
|
|
40
|
+
|
|
32
41
|
/**
|
|
33
42
|
* Base session class with shared token management logic.
|
|
34
43
|
* Subclasses implement the transport-specific operations (HTTP vs in-process).
|
|
@@ -40,12 +49,13 @@ export abstract class BaseSession implements ISession {
|
|
|
40
49
|
protected tokenRotateAt?: number;
|
|
41
50
|
protected initPromise?: Promise<void>;
|
|
42
51
|
protected refreshPromise?: Promise<void>;
|
|
52
|
+
protected storedInitParams?: StoredInitParams;
|
|
43
53
|
protected tokenRefreshConfig: TokenRefreshConfig = {
|
|
44
54
|
enabled: true,
|
|
45
55
|
bufferMs: 1000,
|
|
46
56
|
};
|
|
47
57
|
|
|
48
|
-
constructor(tokenRefreshConfig?: Partial<TokenRefreshConfig>) {
|
|
58
|
+
protected constructor(tokenRefreshConfig?: Partial<TokenRefreshConfig>) {
|
|
49
59
|
if (tokenRefreshConfig) {
|
|
50
60
|
this.tokenRefreshConfig = { ...this.tokenRefreshConfig, ...tokenRefreshConfig };
|
|
51
61
|
}
|
|
@@ -81,9 +91,25 @@ export abstract class BaseSession implements ISession {
|
|
|
81
91
|
abstract prepareHeaders(method: string, url: string, body?: unknown): Promise<Record<string, string>>;
|
|
82
92
|
|
|
83
93
|
/**
|
|
84
|
-
* Perform
|
|
94
|
+
* Perform token refresh by re-initializing the session.
|
|
95
|
+
* Resets the init guard and calls init() again with the stored params,
|
|
96
|
+
* effectively creating a fresh session without depending on the old
|
|
97
|
+
* session still existing in the server's cache.
|
|
85
98
|
*/
|
|
86
|
-
protected
|
|
99
|
+
protected async doRefreshToken(): Promise<void> {
|
|
100
|
+
if (!this.storedInitParams) {
|
|
101
|
+
throw new Error('Cannot refresh token: init params not stored. Was init() called?');
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Reset the init guard so init() runs a fresh handshake
|
|
105
|
+
this.initPromise = undefined;
|
|
106
|
+
|
|
107
|
+
await this.init(
|
|
108
|
+
this.storedInitParams.clientInfo,
|
|
109
|
+
this.storedInitParams.tools,
|
|
110
|
+
this.storedInitParams.services,
|
|
111
|
+
);
|
|
112
|
+
}
|
|
87
113
|
|
|
88
114
|
/**
|
|
89
115
|
* Gets the unique client ID.
|
|
@@ -118,8 +144,8 @@ export abstract class BaseSession implements ISession {
|
|
|
118
144
|
* This is called automatically before requests when autoRefresh is enabled.
|
|
119
145
|
* Uses a shared promise to prevent concurrent refresh requests.
|
|
120
146
|
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
147
|
+
* Refresh works by re-initializing the session (calling init() again),
|
|
148
|
+
* so it does not depend on the old session still existing in the server's cache.
|
|
123
149
|
*/
|
|
124
150
|
async refreshTokenIfNeeded(): Promise<void> {
|
|
125
151
|
// Skip if auto-refresh is disabled
|
|
@@ -163,9 +189,10 @@ export abstract class BaseSession implements ISession {
|
|
|
163
189
|
}
|
|
164
190
|
|
|
165
191
|
/**
|
|
166
|
-
* Check if URL should skip token refresh (to avoid infinite recursion)
|
|
192
|
+
* Check if URL should skip token refresh (to avoid infinite recursion).
|
|
193
|
+
* Since refresh now calls init(), we only need to guard the init path.
|
|
167
194
|
*/
|
|
168
195
|
protected shouldSkipRefreshForUrl(url: string): boolean {
|
|
169
|
-
return url.includes('/api/
|
|
196
|
+
return url.includes('/api/init');
|
|
170
197
|
}
|
|
171
198
|
}
|
|
@@ -15,7 +15,6 @@ export interface InProcessServer {
|
|
|
15
15
|
handleExplore(ctx: InProcessRequestContext): Promise<unknown>;
|
|
16
16
|
handleExecute(ctx: InProcessRequestContext): Promise<unknown>;
|
|
17
17
|
handleResume(ctx: InProcessRequestContext, executionId: string): Promise<unknown>;
|
|
18
|
-
handleTokenRefresh(ctx: InProcessRequestContext): Promise<unknown>;
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
/**
|
|
@@ -65,6 +64,9 @@ export class InProcessSession extends BaseSession {
|
|
|
65
64
|
tools?: ClientToolDefinition[],
|
|
66
65
|
services?: { hasLLM: boolean; hasApproval: boolean; hasEmbedding: boolean; hasTools: boolean }
|
|
67
66
|
): Promise<TokenCredentials> {
|
|
67
|
+
// Store init params so doRefreshToken() can re-init with the same data
|
|
68
|
+
this.storedInitParams = { clientInfo, tools, services };
|
|
69
|
+
|
|
68
70
|
if (this.initPromise) {
|
|
69
71
|
await this.initPromise;
|
|
70
72
|
return {
|
|
@@ -133,20 +135,6 @@ export class InProcessSession extends BaseSession {
|
|
|
133
135
|
return '';
|
|
134
136
|
}
|
|
135
137
|
|
|
136
|
-
/**
|
|
137
|
-
* Perform the actual token refresh via in-process server call
|
|
138
|
-
*/
|
|
139
|
-
protected async doRefreshToken(): Promise<void> {
|
|
140
|
-
const ctx = await this.createContext({
|
|
141
|
-
method: 'POST',
|
|
142
|
-
path: '/api/token/refresh',
|
|
143
|
-
body: { clientId: this.clientId },
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
const result = (await this.server.handleTokenRefresh(ctx)) as TokenCredentials;
|
|
147
|
-
this.updateTokenState(result);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
138
|
/**
|
|
151
139
|
* Prepares headers for a request, refreshing token if needed
|
|
152
140
|
*/
|
package/src/core/session.ts
CHANGED
|
@@ -32,6 +32,9 @@ export class ClientSession extends BaseSession {
|
|
|
32
32
|
tools?: ClientToolDefinition[],
|
|
33
33
|
services?: { hasLLM: boolean; hasApproval: boolean; hasEmbedding: boolean; hasTools: boolean }
|
|
34
34
|
): Promise<TokenCredentials> {
|
|
35
|
+
// Store init params so doRefreshToken() can re-init with the same data
|
|
36
|
+
this.storedInitParams = { clientInfo, tools, services };
|
|
37
|
+
|
|
35
38
|
if (this.initPromise) {
|
|
36
39
|
await this.initPromise;
|
|
37
40
|
return {
|
|
@@ -107,36 +110,6 @@ export class ClientSession extends BaseSession {
|
|
|
107
110
|
return this.baseUrl;
|
|
108
111
|
}
|
|
109
112
|
|
|
110
|
-
/**
|
|
111
|
-
* Perform the actual token refresh via HTTP
|
|
112
|
-
*/
|
|
113
|
-
protected async doRefreshToken(): Promise<void> {
|
|
114
|
-
const url = `${this.baseUrl}/api/token/refresh`;
|
|
115
|
-
const body = JSON.stringify({ clientId: this.clientId });
|
|
116
|
-
|
|
117
|
-
// Use current token for auth, but don't recursively try to refresh
|
|
118
|
-
const headers: Record<string, string> = {
|
|
119
|
-
'Content-Type': 'application/json',
|
|
120
|
-
...this.customHeaders,
|
|
121
|
-
'X-Client-ID': this.clientId!,
|
|
122
|
-
Authorization: `Bearer ${this.clientToken}`,
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
const response = await fetch(url, {
|
|
126
|
-
method: 'POST',
|
|
127
|
-
headers,
|
|
128
|
-
body,
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
if (!response.ok) {
|
|
132
|
-
const errorText = await response.text();
|
|
133
|
-
throw new Error(`Token refresh failed: ${response.status} ${response.statusText} - ${errorText}`);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const data = (await response.json()) as TokenCredentials;
|
|
137
|
-
this.updateTokenState(data);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
113
|
/**
|
|
141
114
|
* Prepares headers for a request, refreshing token if needed and calling preRequest hook if configured
|
|
142
115
|
*/
|