@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.cjs
CHANGED
|
@@ -6211,7 +6211,7 @@ function isSwagger2(spec) {
|
|
|
6211
6211
|
return "swagger" in spec;
|
|
6212
6212
|
}
|
|
6213
6213
|
async function loadOpenAPI(source, options = {}) {
|
|
6214
|
-
const spec = await loadSpec(source);
|
|
6214
|
+
const spec = await loadSpec(source, options.fetcher);
|
|
6215
6215
|
const name = options.name || spec.info.title.toLowerCase().replace(/\s+/g, "-");
|
|
6216
6216
|
let baseURL = options.baseURL;
|
|
6217
6217
|
if (!baseURL) {
|
|
@@ -6255,11 +6255,14 @@ async function loadOpenAPI(source, options = {}) {
|
|
|
6255
6255
|
auth
|
|
6256
6256
|
};
|
|
6257
6257
|
}
|
|
6258
|
-
async function loadSpec(source) {
|
|
6258
|
+
async function loadSpec(source, fetcher) {
|
|
6259
6259
|
let content;
|
|
6260
6260
|
let isYaml = false;
|
|
6261
6261
|
if (source.startsWith("http://") || source.startsWith("https://")) {
|
|
6262
|
-
const
|
|
6262
|
+
const fetchFn = fetcher || fetch;
|
|
6263
|
+
const response = await fetchFn(source, {
|
|
6264
|
+
method: "GET"
|
|
6265
|
+
});
|
|
6263
6266
|
if (!response.ok) {
|
|
6264
6267
|
throw new Error(`Failed to load OpenAPI spec from ${source}: ${response.statusText}`);
|
|
6265
6268
|
}
|
|
@@ -6362,12 +6365,12 @@ function convertOperation(path, method, operation, spec, baseURL, options, pathP
|
|
|
6362
6365
|
const headers = {
|
|
6363
6366
|
"Content-Type": "application/json"
|
|
6364
6367
|
};
|
|
6365
|
-
let context;
|
|
6366
|
-
if (options.contextProvider) {
|
|
6367
|
-
context = await options.contextProvider(handlerContext?.requestContext);
|
|
6368
|
-
}
|
|
6369
6368
|
if (options.headerProvider) {
|
|
6370
|
-
|
|
6369
|
+
let requestContext = handlerContext?.requestContext;
|
|
6370
|
+
if (options.contextProvider) {
|
|
6371
|
+
requestContext = await options.contextProvider(requestContext);
|
|
6372
|
+
}
|
|
6373
|
+
const dynamicHeaders = await options.headerProvider(input, requestContext);
|
|
6371
6374
|
Object.assign(headers, dynamicHeaders);
|
|
6372
6375
|
atpRuntime.log.debug("Added headers from headerProvider", {
|
|
6373
6376
|
keys: Object.keys(dynamicHeaders)
|
|
@@ -6491,7 +6494,8 @@ function convertOperation(path, method, operation, spec, baseURL, options, pathP
|
|
|
6491
6494
|
if (transformed.headers) finalHeaders = transformed.headers;
|
|
6492
6495
|
if (transformed.body !== void 0) finalBody = transformed.body;
|
|
6493
6496
|
}
|
|
6494
|
-
const
|
|
6497
|
+
const fetchFn = options.fetcher || fetch;
|
|
6498
|
+
const response = await fetchFn(finalUrl, {
|
|
6495
6499
|
method: finalMethod,
|
|
6496
6500
|
headers: finalHeaders,
|
|
6497
6501
|
body: finalBody
|
|
@@ -6824,12 +6828,11 @@ var ClientSessionManager = class {
|
|
|
6824
6828
|
this.jwtSecret = secret;
|
|
6825
6829
|
}
|
|
6826
6830
|
}
|
|
6827
|
-
ensureClientJWT(token, clientId
|
|
6831
|
+
ensureClientJWT(token, clientId) {
|
|
6828
6832
|
const decoded = jwt__default.default.verify(token, this.jwtSecret, {
|
|
6829
6833
|
algorithms: [
|
|
6830
6834
|
"HS256"
|
|
6831
|
-
]
|
|
6832
|
-
ignoreExpiration
|
|
6835
|
+
]
|
|
6833
6836
|
});
|
|
6834
6837
|
if (decoded.clientId !== clientId || decoded.type !== "client") {
|
|
6835
6838
|
return false;
|
|
@@ -6877,22 +6880,6 @@ var ClientSessionManager = class {
|
|
|
6877
6880
|
}
|
|
6878
6881
|
}
|
|
6879
6882
|
/**
|
|
6880
|
-
* Verify client token for refresh purposes - allows expired JWT tokens.
|
|
6881
|
-
* This is used during token refresh when the JWT may have expired but
|
|
6882
|
-
* the session still exists in cache.
|
|
6883
|
-
*/
|
|
6884
|
-
async verifyClientForRefresh(clientId, token) {
|
|
6885
|
-
try {
|
|
6886
|
-
if (!this.ensureClientJWT(token, clientId, true)) {
|
|
6887
|
-
return false;
|
|
6888
|
-
}
|
|
6889
|
-
const session = await this.cache.get(`session:${clientId}`);
|
|
6890
|
-
return session !== null;
|
|
6891
|
-
} catch {
|
|
6892
|
-
return false;
|
|
6893
|
-
}
|
|
6894
|
-
}
|
|
6895
|
-
/**
|
|
6896
6883
|
* Get client session
|
|
6897
6884
|
*/
|
|
6898
6885
|
async getSession(clientId) {
|
|
@@ -6932,36 +6919,6 @@ var ClientSessionManager = class {
|
|
|
6932
6919
|
});
|
|
6933
6920
|
}
|
|
6934
6921
|
/**
|
|
6935
|
-
* Refresh token for an existing client session.
|
|
6936
|
-
* Returns new token credentials if session exists in cache.
|
|
6937
|
-
* This works even if the session's expiresAt has passed - the refresh
|
|
6938
|
-
* will update expiresAt to extend the session.
|
|
6939
|
-
*/
|
|
6940
|
-
async refreshToken(clientId) {
|
|
6941
|
-
const session = await this.cache.get(`session:${clientId}`);
|
|
6942
|
-
if (!session) {
|
|
6943
|
-
return null;
|
|
6944
|
-
}
|
|
6945
|
-
await this.cache.delete(`session:${clientId}`);
|
|
6946
|
-
const newClientId = this.generateClientId();
|
|
6947
|
-
const now = Date.now();
|
|
6948
|
-
const newExpiresAt = now + this.tokenTTL;
|
|
6949
|
-
const newTokenRotateAt = now + this.tokenRotation;
|
|
6950
|
-
const updatedSession = {
|
|
6951
|
-
...session,
|
|
6952
|
-
clientId,
|
|
6953
|
-
expiresAt: newExpiresAt
|
|
6954
|
-
};
|
|
6955
|
-
await this.cache.set(`session:${newClientId}`, updatedSession);
|
|
6956
|
-
const newToken = this.generateToken(newClientId);
|
|
6957
|
-
return {
|
|
6958
|
-
clientId: newClientId,
|
|
6959
|
-
token: newToken,
|
|
6960
|
-
expiresAt: newExpiresAt,
|
|
6961
|
-
tokenRotateAt: newTokenRotateAt
|
|
6962
|
-
};
|
|
6963
|
-
}
|
|
6964
|
-
/**
|
|
6965
6922
|
* Get token TTL and rotation settings (useful for clients)
|
|
6966
6923
|
*/
|
|
6967
6924
|
getTokenSettings() {
|
|
@@ -11447,8 +11404,6 @@ async function handleRoute(ctx, server) {
|
|
|
11447
11404
|
} else if (ctx.path.startsWith("/api/resume/") && ctx.method === "POST") {
|
|
11448
11405
|
const executionId = ctx.path.substring("/api/resume/".length);
|
|
11449
11406
|
ctx.responseBody = await server.handleResume(ctx, executionId);
|
|
11450
|
-
} else if (ctx.path === "/api/token/refresh" && ctx.method === "POST") {
|
|
11451
|
-
ctx.responseBody = await server.handleTokenRefresh(ctx);
|
|
11452
11407
|
} else {
|
|
11453
11408
|
ctx.status = 404;
|
|
11454
11409
|
ctx.responseBody = {
|
|
@@ -12186,32 +12141,6 @@ async function handleResume(ctx, executionId, executor, stateManager, serverConf
|
|
|
12186
12141
|
return result;
|
|
12187
12142
|
}
|
|
12188
12143
|
__name(handleResume, "handleResume");
|
|
12189
|
-
async function handleTokenRefresh(ctx, sessionManager) {
|
|
12190
|
-
const clientId = ctx.clientId || ctx.body?.clientId;
|
|
12191
|
-
if (!clientId) {
|
|
12192
|
-
ctx.throw(400, "Client ID is required for token refresh");
|
|
12193
|
-
}
|
|
12194
|
-
const authHeader = ctx.headers["authorization"];
|
|
12195
|
-
if (!authHeader || !authHeader.startsWith("Bearer ")) {
|
|
12196
|
-
ctx.throw(401, "Bearer token required for refresh");
|
|
12197
|
-
}
|
|
12198
|
-
const currentToken = authHeader.substring(7);
|
|
12199
|
-
const isValid = await sessionManager.verifyClientForRefresh(clientId, currentToken);
|
|
12200
|
-
if (!isValid) {
|
|
12201
|
-
ctx.throw(401, "Invalid token or session expired");
|
|
12202
|
-
}
|
|
12203
|
-
const refreshResult = await sessionManager.refreshToken(clientId);
|
|
12204
|
-
if (!refreshResult) {
|
|
12205
|
-
ctx.throw(401, "Session not found or expired");
|
|
12206
|
-
}
|
|
12207
|
-
atpRuntime.log.debug("Token refreshed", {
|
|
12208
|
-
clientId,
|
|
12209
|
-
newExpiresAt: refreshResult.expiresAt,
|
|
12210
|
-
newRotateAt: refreshResult.tokenRotateAt
|
|
12211
|
-
});
|
|
12212
|
-
return refreshResult;
|
|
12213
|
-
}
|
|
12214
|
-
__name(handleTokenRefresh, "handleTokenRefresh");
|
|
12215
12144
|
|
|
12216
12145
|
// src/handlers/definitions.handler.ts
|
|
12217
12146
|
async function getDefinitions(apiGroups) {
|
|
@@ -21359,7 +21288,7 @@ function buildSchema(source, options) {
|
|
|
21359
21288
|
});
|
|
21360
21289
|
}
|
|
21361
21290
|
__name(buildSchema, "buildSchema");
|
|
21362
|
-
async function resolveHeaders(options, params,
|
|
21291
|
+
async function resolveHeaders(options, params, requestContext) {
|
|
21363
21292
|
const headers = {};
|
|
21364
21293
|
if (options.headers) {
|
|
21365
21294
|
Object.assign(headers, options.headers);
|
|
@@ -21372,8 +21301,11 @@ async function resolveHeaders(options, params, executionContext) {
|
|
|
21372
21301
|
Object.assign(headers, authHeaders);
|
|
21373
21302
|
}
|
|
21374
21303
|
if (options.headerProvider) {
|
|
21375
|
-
|
|
21376
|
-
|
|
21304
|
+
let ctx = requestContext;
|
|
21305
|
+
if (options.contextProvider) {
|
|
21306
|
+
ctx = await options.contextProvider(requestContext);
|
|
21307
|
+
}
|
|
21308
|
+
const dynamicHeaders = await options.headerProvider(params, ctx);
|
|
21377
21309
|
Object.assign(headers, dynamicHeaders);
|
|
21378
21310
|
}
|
|
21379
21311
|
return headers;
|
|
@@ -21499,8 +21431,9 @@ async function loadGraphQL(source, options = {}) {
|
|
|
21499
21431
|
__name(loadGraphQL, "loadGraphQL");
|
|
21500
21432
|
async function loadSchema(source, options) {
|
|
21501
21433
|
if (source.startsWith("http://") || source.startsWith("https://")) {
|
|
21434
|
+
const fetchFn = options.fetcher || fetch;
|
|
21502
21435
|
const headers = await resolveHeaders(options);
|
|
21503
|
-
const response = await
|
|
21436
|
+
const response = await fetchFn(source, {
|
|
21504
21437
|
method: "POST",
|
|
21505
21438
|
headers: {
|
|
21506
21439
|
"Content-Type": "application/json",
|
|
@@ -21511,7 +21444,8 @@ async function loadSchema(source, options) {
|
|
|
21511
21444
|
})
|
|
21512
21445
|
});
|
|
21513
21446
|
if (!response.ok) {
|
|
21514
|
-
const getResponse = await
|
|
21447
|
+
const getResponse = await fetchFn(source, {
|
|
21448
|
+
method: "GET",
|
|
21515
21449
|
headers
|
|
21516
21450
|
});
|
|
21517
21451
|
if (getResponse.ok) {
|
|
@@ -21581,8 +21515,9 @@ function convertFieldToFunction(type, fieldName, field, url, options) {
|
|
|
21581
21515
|
context.metadata.graphql_query = query;
|
|
21582
21516
|
context.metadata.graphql_variables = variables;
|
|
21583
21517
|
}
|
|
21584
|
-
const headers = await resolveHeaders(options, paramsObj, context);
|
|
21585
|
-
const
|
|
21518
|
+
const headers = await resolveHeaders(options, paramsObj, context?.requestContext);
|
|
21519
|
+
const fetchFn = options.fetcher || fetch;
|
|
21520
|
+
const response = await fetchFn(url, {
|
|
21586
21521
|
method: "POST",
|
|
21587
21522
|
headers: {
|
|
21588
21523
|
"Content-Type": "application/json",
|
|
@@ -21900,7 +21835,7 @@ var AgentToolProtocolServer = class {
|
|
|
21900
21835
|
if (!this.cacheProvider) {
|
|
21901
21836
|
this.cacheProvider = new atpProviders.MemoryCache({
|
|
21902
21837
|
maxKeys: 1e3,
|
|
21903
|
-
defaultTTL: 3600
|
|
21838
|
+
defaultTTL: 24 * 3600
|
|
21904
21839
|
});
|
|
21905
21840
|
atpRuntime.log.info("Cache provider configured (default)", {
|
|
21906
21841
|
provider: "memory"
|
|
@@ -22273,10 +22208,6 @@ var AgentToolProtocolServer = class {
|
|
|
22273
22208
|
}
|
|
22274
22209
|
return await handleResume(ctx, executionId, this.executor, this.stateManager, this.config, this.sessionManager);
|
|
22275
22210
|
}
|
|
22276
|
-
async handleTokenRefresh(ctx) {
|
|
22277
|
-
if (!this.sessionManager) ctx.throw(503, "Session manager not initialized");
|
|
22278
|
-
return await handleTokenRefresh(ctx, this.sessionManager);
|
|
22279
|
-
}
|
|
22280
22211
|
/**
|
|
22281
22212
|
* Update server components with new API groups (internal method)
|
|
22282
22213
|
* @private
|