@mondaydotcomorg/atp-server 0.24.0 → 0.24.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/client-sessions.d.ts +0 -13
- package/dist/client-sessions.d.ts.map +1 -1
- package/dist/client-sessions.js +1 -57
- package/dist/client-sessions.js.map +1 -1
- package/dist/create-server.d.ts +0 -1
- package/dist/create-server.d.ts.map +1 -1
- package/dist/create-server.js +1 -7
- package/dist/create-server.js.map +1 -1
- package/dist/graphql-loader.d.ts +27 -5
- package/dist/graphql-loader.d.ts.map +1 -1
- package/dist/graphql-loader.js +14 -11
- package/dist/graphql-loader.js.map +1 -1
- package/dist/http/router.d.ts.map +1 -1
- package/dist/http/router.js +0 -3
- package/dist/http/router.js.map +1 -1
- package/dist/index.cjs +29 -98
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +29 -98
- package/dist/index.js.map +1 -1
- package/dist/openapi-loader.d.ts +32 -7
- package/dist/openapi-loader.d.ts.map +1 -1
- package/dist/openapi-loader.js +11 -9
- package/dist/openapi-loader.js.map +1 -1
- package/package.json +6 -6
- package/src/client-sessions.ts +1 -64
- package/src/create-server.ts +1 -7
- package/src/graphql-loader.ts +43 -17
- package/src/http/router.ts +0 -2
- package/src/openapi-loader.ts +47 -17
- package/dist/handlers/token.handler.d.ts +0 -18
- package/dist/handlers/token.handler.d.ts.map +0 -1
- package/dist/handlers/token.handler.js +0 -36
- package/dist/handlers/token.handler.js.map +0 -1
- package/src/handlers/token.handler.ts +0 -59
package/dist/index.js
CHANGED
|
@@ -6179,7 +6179,7 @@ function isSwagger2(spec) {
|
|
|
6179
6179
|
return "swagger" in spec;
|
|
6180
6180
|
}
|
|
6181
6181
|
async function loadOpenAPI(source, options = {}) {
|
|
6182
|
-
const spec = await loadSpec(source);
|
|
6182
|
+
const spec = await loadSpec(source, options.fetcher);
|
|
6183
6183
|
const name = options.name || spec.info.title.toLowerCase().replace(/\s+/g, "-");
|
|
6184
6184
|
let baseURL = options.baseURL;
|
|
6185
6185
|
if (!baseURL) {
|
|
@@ -6223,11 +6223,14 @@ async function loadOpenAPI(source, options = {}) {
|
|
|
6223
6223
|
auth
|
|
6224
6224
|
};
|
|
6225
6225
|
}
|
|
6226
|
-
async function loadSpec(source) {
|
|
6226
|
+
async function loadSpec(source, fetcher) {
|
|
6227
6227
|
let content;
|
|
6228
6228
|
let isYaml = false;
|
|
6229
6229
|
if (source.startsWith("http://") || source.startsWith("https://")) {
|
|
6230
|
-
const
|
|
6230
|
+
const fetchFn = fetcher || fetch;
|
|
6231
|
+
const response = await fetchFn(source, {
|
|
6232
|
+
method: "GET"
|
|
6233
|
+
});
|
|
6231
6234
|
if (!response.ok) {
|
|
6232
6235
|
throw new Error(`Failed to load OpenAPI spec from ${source}: ${response.statusText}`);
|
|
6233
6236
|
}
|
|
@@ -6330,12 +6333,12 @@ function convertOperation(path, method, operation, spec, baseURL, options, pathP
|
|
|
6330
6333
|
const headers = {
|
|
6331
6334
|
"Content-Type": "application/json"
|
|
6332
6335
|
};
|
|
6333
|
-
let context;
|
|
6334
|
-
if (options.contextProvider) {
|
|
6335
|
-
context = await options.contextProvider(handlerContext?.requestContext);
|
|
6336
|
-
}
|
|
6337
6336
|
if (options.headerProvider) {
|
|
6338
|
-
|
|
6337
|
+
let requestContext = handlerContext?.requestContext;
|
|
6338
|
+
if (options.contextProvider) {
|
|
6339
|
+
requestContext = await options.contextProvider(requestContext);
|
|
6340
|
+
}
|
|
6341
|
+
const dynamicHeaders = await options.headerProvider(input, requestContext);
|
|
6339
6342
|
Object.assign(headers, dynamicHeaders);
|
|
6340
6343
|
log.debug("Added headers from headerProvider", {
|
|
6341
6344
|
keys: Object.keys(dynamicHeaders)
|
|
@@ -6459,7 +6462,8 @@ function convertOperation(path, method, operation, spec, baseURL, options, pathP
|
|
|
6459
6462
|
if (transformed.headers) finalHeaders = transformed.headers;
|
|
6460
6463
|
if (transformed.body !== void 0) finalBody = transformed.body;
|
|
6461
6464
|
}
|
|
6462
|
-
const
|
|
6465
|
+
const fetchFn = options.fetcher || fetch;
|
|
6466
|
+
const response = await fetchFn(finalUrl, {
|
|
6463
6467
|
method: finalMethod,
|
|
6464
6468
|
headers: finalHeaders,
|
|
6465
6469
|
body: finalBody
|
|
@@ -6792,12 +6796,11 @@ var ClientSessionManager = class {
|
|
|
6792
6796
|
this.jwtSecret = secret;
|
|
6793
6797
|
}
|
|
6794
6798
|
}
|
|
6795
|
-
ensureClientJWT(token, clientId
|
|
6799
|
+
ensureClientJWT(token, clientId) {
|
|
6796
6800
|
const decoded = jwt.verify(token, this.jwtSecret, {
|
|
6797
6801
|
algorithms: [
|
|
6798
6802
|
"HS256"
|
|
6799
|
-
]
|
|
6800
|
-
ignoreExpiration
|
|
6803
|
+
]
|
|
6801
6804
|
});
|
|
6802
6805
|
if (decoded.clientId !== clientId || decoded.type !== "client") {
|
|
6803
6806
|
return false;
|
|
@@ -6845,22 +6848,6 @@ var ClientSessionManager = class {
|
|
|
6845
6848
|
}
|
|
6846
6849
|
}
|
|
6847
6850
|
/**
|
|
6848
|
-
* Verify client token for refresh purposes - allows expired JWT tokens.
|
|
6849
|
-
* This is used during token refresh when the JWT may have expired but
|
|
6850
|
-
* the session still exists in cache.
|
|
6851
|
-
*/
|
|
6852
|
-
async verifyClientForRefresh(clientId, token) {
|
|
6853
|
-
try {
|
|
6854
|
-
if (!this.ensureClientJWT(token, clientId, true)) {
|
|
6855
|
-
return false;
|
|
6856
|
-
}
|
|
6857
|
-
const session = await this.cache.get(`session:${clientId}`);
|
|
6858
|
-
return session !== null;
|
|
6859
|
-
} catch {
|
|
6860
|
-
return false;
|
|
6861
|
-
}
|
|
6862
|
-
}
|
|
6863
|
-
/**
|
|
6864
6851
|
* Get client session
|
|
6865
6852
|
*/
|
|
6866
6853
|
async getSession(clientId) {
|
|
@@ -6900,36 +6887,6 @@ var ClientSessionManager = class {
|
|
|
6900
6887
|
});
|
|
6901
6888
|
}
|
|
6902
6889
|
/**
|
|
6903
|
-
* Refresh token for an existing client session.
|
|
6904
|
-
* Returns new token credentials if session exists in cache.
|
|
6905
|
-
* This works even if the session's expiresAt has passed - the refresh
|
|
6906
|
-
* will update expiresAt to extend the session.
|
|
6907
|
-
*/
|
|
6908
|
-
async refreshToken(clientId) {
|
|
6909
|
-
const session = await this.cache.get(`session:${clientId}`);
|
|
6910
|
-
if (!session) {
|
|
6911
|
-
return null;
|
|
6912
|
-
}
|
|
6913
|
-
await this.cache.delete(`session:${clientId}`);
|
|
6914
|
-
const newClientId = this.generateClientId();
|
|
6915
|
-
const now = Date.now();
|
|
6916
|
-
const newExpiresAt = now + this.tokenTTL;
|
|
6917
|
-
const newTokenRotateAt = now + this.tokenRotation;
|
|
6918
|
-
const updatedSession = {
|
|
6919
|
-
...session,
|
|
6920
|
-
clientId,
|
|
6921
|
-
expiresAt: newExpiresAt
|
|
6922
|
-
};
|
|
6923
|
-
await this.cache.set(`session:${newClientId}`, updatedSession);
|
|
6924
|
-
const newToken = this.generateToken(newClientId);
|
|
6925
|
-
return {
|
|
6926
|
-
clientId: newClientId,
|
|
6927
|
-
token: newToken,
|
|
6928
|
-
expiresAt: newExpiresAt,
|
|
6929
|
-
tokenRotateAt: newTokenRotateAt
|
|
6930
|
-
};
|
|
6931
|
-
}
|
|
6932
|
-
/**
|
|
6933
6890
|
* Get token TTL and rotation settings (useful for clients)
|
|
6934
6891
|
*/
|
|
6935
6892
|
getTokenSettings() {
|
|
@@ -11415,8 +11372,6 @@ async function handleRoute(ctx, server) {
|
|
|
11415
11372
|
} else if (ctx.path.startsWith("/api/resume/") && ctx.method === "POST") {
|
|
11416
11373
|
const executionId = ctx.path.substring("/api/resume/".length);
|
|
11417
11374
|
ctx.responseBody = await server.handleResume(ctx, executionId);
|
|
11418
|
-
} else if (ctx.path === "/api/token/refresh" && ctx.method === "POST") {
|
|
11419
|
-
ctx.responseBody = await server.handleTokenRefresh(ctx);
|
|
11420
11375
|
} else {
|
|
11421
11376
|
ctx.status = 404;
|
|
11422
11377
|
ctx.responseBody = {
|
|
@@ -12154,32 +12109,6 @@ async function handleResume(ctx, executionId, executor, stateManager, serverConf
|
|
|
12154
12109
|
return result;
|
|
12155
12110
|
}
|
|
12156
12111
|
__name(handleResume, "handleResume");
|
|
12157
|
-
async function handleTokenRefresh(ctx, sessionManager) {
|
|
12158
|
-
const clientId = ctx.clientId || ctx.body?.clientId;
|
|
12159
|
-
if (!clientId) {
|
|
12160
|
-
ctx.throw(400, "Client ID is required for token refresh");
|
|
12161
|
-
}
|
|
12162
|
-
const authHeader = ctx.headers["authorization"];
|
|
12163
|
-
if (!authHeader || !authHeader.startsWith("Bearer ")) {
|
|
12164
|
-
ctx.throw(401, "Bearer token required for refresh");
|
|
12165
|
-
}
|
|
12166
|
-
const currentToken = authHeader.substring(7);
|
|
12167
|
-
const isValid = await sessionManager.verifyClientForRefresh(clientId, currentToken);
|
|
12168
|
-
if (!isValid) {
|
|
12169
|
-
ctx.throw(401, "Invalid token or session expired");
|
|
12170
|
-
}
|
|
12171
|
-
const refreshResult = await sessionManager.refreshToken(clientId);
|
|
12172
|
-
if (!refreshResult) {
|
|
12173
|
-
ctx.throw(401, "Session not found or expired");
|
|
12174
|
-
}
|
|
12175
|
-
log.debug("Token refreshed", {
|
|
12176
|
-
clientId,
|
|
12177
|
-
newExpiresAt: refreshResult.expiresAt,
|
|
12178
|
-
newRotateAt: refreshResult.tokenRotateAt
|
|
12179
|
-
});
|
|
12180
|
-
return refreshResult;
|
|
12181
|
-
}
|
|
12182
|
-
__name(handleTokenRefresh, "handleTokenRefresh");
|
|
12183
12112
|
|
|
12184
12113
|
// src/handlers/definitions.handler.ts
|
|
12185
12114
|
async function getDefinitions(apiGroups) {
|
|
@@ -21327,7 +21256,7 @@ function buildSchema(source, options) {
|
|
|
21327
21256
|
});
|
|
21328
21257
|
}
|
|
21329
21258
|
__name(buildSchema, "buildSchema");
|
|
21330
|
-
async function resolveHeaders(options, params,
|
|
21259
|
+
async function resolveHeaders(options, params, requestContext) {
|
|
21331
21260
|
const headers = {};
|
|
21332
21261
|
if (options.headers) {
|
|
21333
21262
|
Object.assign(headers, options.headers);
|
|
@@ -21340,8 +21269,11 @@ async function resolveHeaders(options, params, executionContext) {
|
|
|
21340
21269
|
Object.assign(headers, authHeaders);
|
|
21341
21270
|
}
|
|
21342
21271
|
if (options.headerProvider) {
|
|
21343
|
-
|
|
21344
|
-
|
|
21272
|
+
let ctx = requestContext;
|
|
21273
|
+
if (options.contextProvider) {
|
|
21274
|
+
ctx = await options.contextProvider(requestContext);
|
|
21275
|
+
}
|
|
21276
|
+
const dynamicHeaders = await options.headerProvider(params, ctx);
|
|
21345
21277
|
Object.assign(headers, dynamicHeaders);
|
|
21346
21278
|
}
|
|
21347
21279
|
return headers;
|
|
@@ -21467,8 +21399,9 @@ async function loadGraphQL(source, options = {}) {
|
|
|
21467
21399
|
__name(loadGraphQL, "loadGraphQL");
|
|
21468
21400
|
async function loadSchema(source, options) {
|
|
21469
21401
|
if (source.startsWith("http://") || source.startsWith("https://")) {
|
|
21402
|
+
const fetchFn = options.fetcher || fetch;
|
|
21470
21403
|
const headers = await resolveHeaders(options);
|
|
21471
|
-
const response = await
|
|
21404
|
+
const response = await fetchFn(source, {
|
|
21472
21405
|
method: "POST",
|
|
21473
21406
|
headers: {
|
|
21474
21407
|
"Content-Type": "application/json",
|
|
@@ -21479,7 +21412,8 @@ async function loadSchema(source, options) {
|
|
|
21479
21412
|
})
|
|
21480
21413
|
});
|
|
21481
21414
|
if (!response.ok) {
|
|
21482
|
-
const getResponse = await
|
|
21415
|
+
const getResponse = await fetchFn(source, {
|
|
21416
|
+
method: "GET",
|
|
21483
21417
|
headers
|
|
21484
21418
|
});
|
|
21485
21419
|
if (getResponse.ok) {
|
|
@@ -21549,8 +21483,9 @@ function convertFieldToFunction(type, fieldName, field, url, options) {
|
|
|
21549
21483
|
context.metadata.graphql_query = query;
|
|
21550
21484
|
context.metadata.graphql_variables = variables;
|
|
21551
21485
|
}
|
|
21552
|
-
const headers = await resolveHeaders(options, paramsObj, context);
|
|
21553
|
-
const
|
|
21486
|
+
const headers = await resolveHeaders(options, paramsObj, context?.requestContext);
|
|
21487
|
+
const fetchFn = options.fetcher || fetch;
|
|
21488
|
+
const response = await fetchFn(url, {
|
|
21554
21489
|
method: "POST",
|
|
21555
21490
|
headers: {
|
|
21556
21491
|
"Content-Type": "application/json",
|
|
@@ -21868,7 +21803,7 @@ var AgentToolProtocolServer = class {
|
|
|
21868
21803
|
if (!this.cacheProvider) {
|
|
21869
21804
|
this.cacheProvider = new MemoryCache({
|
|
21870
21805
|
maxKeys: 1e3,
|
|
21871
|
-
defaultTTL: 3600
|
|
21806
|
+
defaultTTL: 24 * 3600
|
|
21872
21807
|
});
|
|
21873
21808
|
log.info("Cache provider configured (default)", {
|
|
21874
21809
|
provider: "memory"
|
|
@@ -22241,10 +22176,6 @@ var AgentToolProtocolServer = class {
|
|
|
22241
22176
|
}
|
|
22242
22177
|
return await handleResume(ctx, executionId, this.executor, this.stateManager, this.config, this.sessionManager);
|
|
22243
22178
|
}
|
|
22244
|
-
async handleTokenRefresh(ctx) {
|
|
22245
|
-
if (!this.sessionManager) ctx.throw(503, "Session manager not initialized");
|
|
22246
|
-
return await handleTokenRefresh(ctx, this.sessionManager);
|
|
22247
|
-
}
|
|
22248
22179
|
/**
|
|
22249
22180
|
* Update server components with new API groups (internal method)
|
|
22250
22181
|
* @private
|