@mondaydotcomorg/atp-server 0.17.14
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/README.md +489 -0
- package/dist/aggregator/index.d.ts +59 -0
- package/dist/aggregator/index.d.ts.map +1 -0
- package/dist/aggregator/index.js +171 -0
- package/dist/aggregator/index.js.map +1 -0
- package/dist/callback/index.d.ts +98 -0
- package/dist/callback/index.d.ts.map +1 -0
- package/dist/callback/index.js +136 -0
- package/dist/callback/index.js.map +1 -0
- package/dist/client-sessions.d.ts +82 -0
- package/dist/client-sessions.d.ts.map +1 -0
- package/dist/client-sessions.js +174 -0
- package/dist/client-sessions.js.map +1 -0
- package/dist/controllers/definitions.controller.d.ts +4 -0
- package/dist/controllers/definitions.controller.d.ts.map +1 -0
- package/dist/controllers/definitions.controller.js +11 -0
- package/dist/controllers/definitions.controller.js.map +1 -0
- package/dist/controllers/execute.controller.d.ts +18 -0
- package/dist/controllers/execute.controller.d.ts.map +1 -0
- package/dist/controllers/execute.controller.js +122 -0
- package/dist/controllers/execute.controller.js.map +1 -0
- package/dist/controllers/info.controller.d.ts +3 -0
- package/dist/controllers/info.controller.d.ts.map +1 -0
- package/dist/controllers/info.controller.js +13 -0
- package/dist/controllers/info.controller.js.map +1 -0
- package/dist/controllers/resume.controller.d.ts +11 -0
- package/dist/controllers/resume.controller.d.ts.map +1 -0
- package/dist/controllers/resume.controller.js +61 -0
- package/dist/controllers/resume.controller.js.map +1 -0
- package/dist/controllers/search.controller.d.ts +4 -0
- package/dist/controllers/search.controller.d.ts.map +1 -0
- package/dist/controllers/search.controller.js +7 -0
- package/dist/controllers/search.controller.js.map +1 -0
- package/dist/controllers/stream.controller.d.ts +19 -0
- package/dist/controllers/stream.controller.d.ts.map +1 -0
- package/dist/controllers/stream.controller.js +141 -0
- package/dist/controllers/stream.controller.js.map +1 -0
- package/dist/core/config.d.ts +161 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +7 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/http.d.ts +4 -0
- package/dist/core/http.d.ts.map +1 -0
- package/dist/core/http.js +17 -0
- package/dist/core/http.js.map +1 -0
- package/dist/create-server.d.ts +120 -0
- package/dist/create-server.d.ts.map +1 -0
- package/dist/create-server.js +423 -0
- package/dist/create-server.js.map +1 -0
- package/dist/execution-state/index.d.ts +95 -0
- package/dist/execution-state/index.d.ts.map +1 -0
- package/dist/execution-state/index.js +128 -0
- package/dist/execution-state/index.js.map +1 -0
- package/dist/executor/ast-provenance-bridge.d.ts +12 -0
- package/dist/executor/ast-provenance-bridge.d.ts.map +1 -0
- package/dist/executor/ast-provenance-bridge.js +66 -0
- package/dist/executor/ast-provenance-bridge.js.map +1 -0
- package/dist/executor/ast-tracking-runtime.d.ts +7 -0
- package/dist/executor/ast-tracking-runtime.d.ts.map +1 -0
- package/dist/executor/ast-tracking-runtime.js +559 -0
- package/dist/executor/ast-tracking-runtime.js.map +1 -0
- package/dist/executor/bootstrap-generated.d.ts +32 -0
- package/dist/executor/bootstrap-generated.d.ts.map +1 -0
- package/dist/executor/bootstrap-generated.js +90 -0
- package/dist/executor/bootstrap-generated.js.map +1 -0
- package/dist/executor/compiler-config.d.ts +32 -0
- package/dist/executor/compiler-config.d.ts.map +1 -0
- package/dist/executor/compiler-config.js +99 -0
- package/dist/executor/compiler-config.js.map +1 -0
- package/dist/executor/constants.d.ts +4 -0
- package/dist/executor/constants.d.ts.map +1 -0
- package/dist/executor/constants.js +4 -0
- package/dist/executor/constants.js.map +1 -0
- package/dist/executor/error-handler.d.ts +9 -0
- package/dist/executor/error-handler.d.ts.map +1 -0
- package/dist/executor/error-handler.js +95 -0
- package/dist/executor/error-handler.js.map +1 -0
- package/dist/executor/execution-error-handler.d.ts +7 -0
- package/dist/executor/execution-error-handler.d.ts.map +1 -0
- package/dist/executor/execution-error-handler.js +136 -0
- package/dist/executor/execution-error-handler.js.map +1 -0
- package/dist/executor/executor.d.ts +20 -0
- package/dist/executor/executor.d.ts.map +1 -0
- package/dist/executor/executor.js +452 -0
- package/dist/executor/executor.js.map +1 -0
- package/dist/executor/index.d.ts +4 -0
- package/dist/executor/index.d.ts.map +1 -0
- package/dist/executor/index.js +3 -0
- package/dist/executor/index.js.map +1 -0
- package/dist/executor/resume-handler.d.ts +9 -0
- package/dist/executor/resume-handler.d.ts.map +1 -0
- package/dist/executor/resume-handler.js +22 -0
- package/dist/executor/resume-handler.js.map +1 -0
- package/dist/executor/sandbox-builder.d.ts +29 -0
- package/dist/executor/sandbox-builder.d.ts.map +1 -0
- package/dist/executor/sandbox-builder.js +538 -0
- package/dist/executor/sandbox-builder.js.map +1 -0
- package/dist/executor/sandbox-injector.d.ts +7 -0
- package/dist/executor/sandbox-injector.d.ts.map +1 -0
- package/dist/executor/sandbox-injector.js +293 -0
- package/dist/executor/sandbox-injector.js.map +1 -0
- package/dist/executor/types.d.ts +21 -0
- package/dist/executor/types.d.ts.map +1 -0
- package/dist/executor/types.js +2 -0
- package/dist/executor/types.js.map +1 -0
- package/dist/explorer/index.d.ts +69 -0
- package/dist/explorer/index.d.ts.map +1 -0
- package/dist/explorer/index.js +228 -0
- package/dist/explorer/index.js.map +1 -0
- package/dist/handlers/definitions.handler.d.ts +3 -0
- package/dist/handlers/definitions.handler.d.ts.map +1 -0
- package/dist/handlers/definitions.handler.js +11 -0
- package/dist/handlers/definitions.handler.js.map +1 -0
- package/dist/handlers/execute.handler.d.ts +7 -0
- package/dist/handlers/execute.handler.d.ts.map +1 -0
- package/dist/handlers/execute.handler.js +225 -0
- package/dist/handlers/execute.handler.js.map +1 -0
- package/dist/handlers/explorer.handler.d.ts +4 -0
- package/dist/handlers/explorer.handler.d.ts.map +1 -0
- package/dist/handlers/explorer.handler.js +10 -0
- package/dist/handlers/explorer.handler.js.map +1 -0
- package/dist/handlers/init.handler.d.ts +5 -0
- package/dist/handlers/init.handler.d.ts.map +1 -0
- package/dist/handlers/init.handler.js +41 -0
- package/dist/handlers/init.handler.js.map +1 -0
- package/dist/handlers/resume.handler.d.ts +6 -0
- package/dist/handlers/resume.handler.d.ts.map +1 -0
- package/dist/handlers/resume.handler.js +256 -0
- package/dist/handlers/resume.handler.js.map +1 -0
- package/dist/handlers/search.handler.d.ts +5 -0
- package/dist/handlers/search.handler.d.ts.map +1 -0
- package/dist/handlers/search.handler.js +11 -0
- package/dist/handlers/search.handler.js.map +1 -0
- package/dist/http/request-handler.d.ts +15 -0
- package/dist/http/request-handler.d.ts.map +1 -0
- package/dist/http/request-handler.js +94 -0
- package/dist/http/request-handler.js.map +1 -0
- package/dist/http/router.d.ts +4 -0
- package/dist/http/router.d.ts.map +1 -0
- package/dist/http/router.js +32 -0
- package/dist/http/router.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/instrumentation/index.d.ts +5 -0
- package/dist/instrumentation/index.d.ts.map +1 -0
- package/dist/instrumentation/index.js +5 -0
- package/dist/instrumentation/index.js.map +1 -0
- package/dist/instrumentation/serializer.d.ts +61 -0
- package/dist/instrumentation/serializer.d.ts.map +1 -0
- package/dist/instrumentation/serializer.js +334 -0
- package/dist/instrumentation/serializer.js.map +1 -0
- package/dist/instrumentation/state-manager.d.ts +61 -0
- package/dist/instrumentation/state-manager.d.ts.map +1 -0
- package/dist/instrumentation/state-manager.js +205 -0
- package/dist/instrumentation/state-manager.js.map +1 -0
- package/dist/instrumentation/transformer.d.ts +9 -0
- package/dist/instrumentation/transformer.d.ts.map +1 -0
- package/dist/instrumentation/transformer.js +70 -0
- package/dist/instrumentation/transformer.js.map +1 -0
- package/dist/instrumentation/types.d.ts +59 -0
- package/dist/instrumentation/types.d.ts.map +1 -0
- package/dist/instrumentation/types.js +5 -0
- package/dist/instrumentation/types.js.map +1 -0
- package/dist/middleware/audit.d.ts +18 -0
- package/dist/middleware/audit.d.ts.map +1 -0
- package/dist/middleware/audit.js +76 -0
- package/dist/middleware/audit.js.map +1 -0
- package/dist/openapi/index.d.ts +133 -0
- package/dist/openapi/index.d.ts.map +1 -0
- package/dist/openapi/index.js +235 -0
- package/dist/openapi/index.js.map +1 -0
- package/dist/openapi-loader.d.ts +87 -0
- package/dist/openapi-loader.d.ts.map +1 -0
- package/dist/openapi-loader.js +491 -0
- package/dist/openapi-loader.js.map +1 -0
- package/dist/routes/index.d.ts +21 -0
- package/dist/routes/index.d.ts.map +1 -0
- package/dist/routes/index.js +47 -0
- package/dist/routes/index.js.map +1 -0
- package/dist/search/index.d.ts +48 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +156 -0
- package/dist/search/index.js.map +1 -0
- package/dist/security/index.d.ts +2 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +2 -0
- package/dist/security/index.js.map +1 -0
- package/dist/shutdown.d.ts +19 -0
- package/dist/shutdown.d.ts.map +1 -0
- package/dist/shutdown.js +87 -0
- package/dist/shutdown.js.map +1 -0
- package/dist/utils/banner.d.ts +12 -0
- package/dist/utils/banner.d.ts.map +1 -0
- package/dist/utils/banner.js +18 -0
- package/dist/utils/banner.js.map +1 -0
- package/dist/utils/context.d.ts +16 -0
- package/dist/utils/context.d.ts.map +1 -0
- package/dist/utils/context.js +44 -0
- package/dist/utils/context.js.map +1 -0
- package/dist/utils/error.d.ts +8 -0
- package/dist/utils/error.d.ts.map +1 -0
- package/dist/utils/error.js +17 -0
- package/dist/utils/error.js.map +1 -0
- package/dist/utils/hint-based-instrumentation.d.ts +14 -0
- package/dist/utils/hint-based-instrumentation.d.ts.map +1 -0
- package/dist/utils/hint-based-instrumentation.js +84 -0
- package/dist/utils/hint-based-instrumentation.js.map +1 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/info.d.ts +20 -0
- package/dist/utils/info.d.ts.map +1 -0
- package/dist/utils/info.js +15 -0
- package/dist/utils/info.js.map +1 -0
- package/dist/utils/provenance-reattachment.d.ts +32 -0
- package/dist/utils/provenance-reattachment.d.ts.map +1 -0
- package/dist/utils/provenance-reattachment.js +115 -0
- package/dist/utils/provenance-reattachment.js.map +1 -0
- package/dist/utils/request.d.ts +21 -0
- package/dist/utils/request.d.ts.map +1 -0
- package/dist/utils/request.js +44 -0
- package/dist/utils/request.js.map +1 -0
- package/dist/utils/response.d.ts +30 -0
- package/dist/utils/response.d.ts.map +1 -0
- package/dist/utils/response.js +53 -0
- package/dist/utils/response.js.map +1 -0
- package/dist/utils/runtime-types.d.ts +6 -0
- package/dist/utils/runtime-types.d.ts.map +1 -0
- package/dist/utils/runtime-types.js +14 -0
- package/dist/utils/runtime-types.js.map +1 -0
- package/dist/utils/schema.d.ts +9 -0
- package/dist/utils/schema.d.ts.map +1 -0
- package/dist/utils/schema.js +13 -0
- package/dist/utils/schema.js.map +1 -0
- package/dist/utils/token-emitter.d.ts +21 -0
- package/dist/utils/token-emitter.d.ts.map +1 -0
- package/dist/utils/token-emitter.js +129 -0
- package/dist/utils/token-emitter.js.map +1 -0
- package/dist/validator/index.d.ts +36 -0
- package/dist/validator/index.d.ts.map +1 -0
- package/dist/validator/index.js +224 -0
- package/dist/validator/index.js.map +1 -0
- package/package.json +68 -0
- package/src/aggregator/index.ts +207 -0
- package/src/callback/index.ts +191 -0
- package/src/client-sessions.ts +234 -0
- package/src/controllers/definitions.controller.ts +19 -0
- package/src/controllers/execute.controller.ts +166 -0
- package/src/controllers/info.controller.ts +14 -0
- package/src/controllers/resume.controller.ts +92 -0
- package/src/controllers/search.controller.ts +16 -0
- package/src/controllers/stream.controller.ts +190 -0
- package/src/core/config.ts +180 -0
- package/src/core/http.ts +21 -0
- package/src/create-server.ts +536 -0
- package/src/execution-state/index.ts +204 -0
- package/src/executor/ast-provenance-bridge.ts +80 -0
- package/src/executor/ast-tracking-runtime.ts +558 -0
- package/src/executor/bootstrap-generated.ts +90 -0
- package/src/executor/compiler-config.ts +146 -0
- package/src/executor/constants.ts +5 -0
- package/src/executor/error-handler.ts +118 -0
- package/src/executor/execution-error-handler.ts +178 -0
- package/src/executor/executor.ts +631 -0
- package/src/executor/index.ts +3 -0
- package/src/executor/resume-handler.ts +39 -0
- package/src/executor/sandbox-builder.ts +684 -0
- package/src/executor/sandbox-injector.ts +345 -0
- package/src/executor/types.ts +22 -0
- package/src/explorer/index.ts +297 -0
- package/src/handlers/definitions.handler.ts +13 -0
- package/src/handlers/execute.handler.ts +286 -0
- package/src/handlers/explorer.handler.ts +18 -0
- package/src/handlers/init.handler.ts +53 -0
- package/src/handlers/resume.handler.ts +316 -0
- package/src/handlers/search.handler.ts +32 -0
- package/src/http/request-handler.ts +117 -0
- package/src/http/router.ts +29 -0
- package/src/index.ts +60 -0
- package/src/instrumentation/index.ts +4 -0
- package/src/instrumentation/serializer.ts +421 -0
- package/src/instrumentation/state-manager.ts +237 -0
- package/src/instrumentation/transformer.ts +84 -0
- package/src/instrumentation/types.ts +76 -0
- package/src/middleware/audit.ts +101 -0
- package/src/openapi/index.ts +378 -0
- package/src/openapi-loader.ts +744 -0
- package/src/routes/index.ts +93 -0
- package/src/search/index.ts +216 -0
- package/src/security/index.ts +1 -0
- package/src/shutdown.ts +108 -0
- package/src/utils/banner.ts +25 -0
- package/src/utils/context.ts +58 -0
- package/src/utils/error.ts +25 -0
- package/src/utils/hint-based-instrumentation.ts +99 -0
- package/src/utils/index.ts +15 -0
- package/src/utils/info.ts +31 -0
- package/src/utils/provenance-reattachment.ts +144 -0
- package/src/utils/request.ts +53 -0
- package/src/utils/response.ts +69 -0
- package/src/utils/runtime-types.ts +14 -0
- package/src/utils/schema.ts +18 -0
- package/src/utils/token-emitter.ts +182 -0
- package/src/validator/index.ts +253 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.handler.d.ts","sourceRoot":"","sources":["../../src/handlers/search.handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,wBAAsB,YAAY,CACjC,GAAG,EAAE,cAAc,EACnB,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,oBAAoB,GAC1B,OAAO,CAAC,OAAO,CAAC,CASlB;AAED,wBAAsB,iBAAiB,CACtC,GAAG,EAAE,cAAc,EACnB,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,oBAAoB,GAC1B,OAAO,CAAC,OAAO,CAAC,CASlB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export async function handleSearch(ctx, searchEngine, config) {
|
|
2
|
+
const searchOptions = ctx.body;
|
|
3
|
+
const results = await searchEngine.search(searchOptions, ctx.userId, ctx.auth, config.discovery.scopeFiltering);
|
|
4
|
+
return { results };
|
|
5
|
+
}
|
|
6
|
+
export async function handleSearchQuery(ctx, searchEngine, config) {
|
|
7
|
+
const query = ctx.query.query || ctx.query.keyword || '';
|
|
8
|
+
const results = await searchEngine.search({ query }, ctx.userId, ctx.auth, config.discovery.scopeFiltering);
|
|
9
|
+
return { results };
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=search.handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.handler.js","sourceRoot":"","sources":["../../src/handlers/search.handler.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,KAAK,UAAU,YAAY,CACjC,GAAmB,EACnB,YAA0B,EAC1B,MAA4B;IAE5B,MAAM,aAAa,GAAG,GAAG,CAAC,IAAW,CAAC;IACtC,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,MAAM,CACxC,aAAa,EACb,GAAG,CAAC,MAAM,EACV,GAAG,CAAC,IAAI,EACR,MAAM,CAAC,SAAS,CAAC,cAAc,CAC/B,CAAC;IACF,OAAO,EAAE,OAAO,EAAE,CAAC;AACpB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACtC,GAAmB,EACnB,YAA0B,EAC1B,MAA4B;IAE5B,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,KAAK,IAAI,GAAG,CAAC,KAAK,CAAC,OAAO,IAAI,EAAE,CAAC;IACzD,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,MAAM,CACxC,EAAE,KAAK,EAAE,EACT,GAAG,CAAC,MAAM,EACV,GAAG,CAAC,IAAI,EACR,MAAM,CAAC,SAAS,CAAC,cAAc,CAC/B,CAAC;IACF,OAAO,EAAE,OAAO,EAAE,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
import type { CacheProvider, AuthProvider, AuditSink } from '@mondaydotcomorg/atp-protocol';
|
|
3
|
+
import type { RequestContext, Middleware } from '../core/config.js';
|
|
4
|
+
import type { ClientSessionManager } from '../client-sessions.js';
|
|
5
|
+
export interface RequestHandlerDeps {
|
|
6
|
+
cacheProvider?: CacheProvider;
|
|
7
|
+
authProvider?: AuthProvider;
|
|
8
|
+
auditSink?: AuditSink;
|
|
9
|
+
customLogger?: any;
|
|
10
|
+
middleware: Middleware[];
|
|
11
|
+
routeHandler: (ctx: RequestContext) => Promise<void>;
|
|
12
|
+
sessionManager?: ClientSessionManager;
|
|
13
|
+
}
|
|
14
|
+
export declare function handleHTTPRequest(req: IncomingMessage, res: ServerResponse, deps: RequestHandlerDeps, responseHeaders: Map<IncomingMessage, Map<string, string>>): Promise<void>;
|
|
15
|
+
//# sourceMappingURL=request-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-handler.d.ts","sourceRoot":"","sources":["../../src/http/request-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAG5D,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAG5F,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAElE,MAAM,WAAW,kBAAkB;IAClC,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB,UAAU,EAAE,UAAU,EAAE,CAAC;IACzB,YAAY,EAAE,CAAC,GAAG,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,cAAc,CAAC,EAAE,oBAAoB,CAAC;CACtC;AAED,wBAAsB,iBAAiB,CACtC,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,IAAI,EAAE,kBAAkB,EACxB,eAAe,EAAE,GAAG,CAAC,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GACxD,OAAO,CAAC,IAAI,CAAC,CA2Ef"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { nanoid } from 'nanoid';
|
|
2
|
+
import { log } from '@mondaydotcomorg/atp-runtime';
|
|
3
|
+
import { parseBody } from '../core/http.js';
|
|
4
|
+
import { handleError, createContext } from '../utils/index.js';
|
|
5
|
+
export async function handleHTTPRequest(req, res, deps, responseHeaders) {
|
|
6
|
+
const ctx = createContext({
|
|
7
|
+
req,
|
|
8
|
+
cacheProvider: deps.cacheProvider,
|
|
9
|
+
authProvider: deps.authProvider,
|
|
10
|
+
auditSink: deps.auditSink,
|
|
11
|
+
customLogger: deps.customLogger,
|
|
12
|
+
responseHeaders,
|
|
13
|
+
});
|
|
14
|
+
const headers = new Map();
|
|
15
|
+
responseHeaders.set(req, headers);
|
|
16
|
+
try {
|
|
17
|
+
if (req.method === 'POST' || req.method === 'PUT') {
|
|
18
|
+
ctx.body = await parseBody(req);
|
|
19
|
+
}
|
|
20
|
+
await runMiddleware(ctx, deps.middleware, deps.routeHandler);
|
|
21
|
+
try {
|
|
22
|
+
if (ctx.clientId && deps.sessionManager && ctx.path !== '/api/init') {
|
|
23
|
+
try {
|
|
24
|
+
const newToken = deps.sessionManager.generateToken(ctx.clientId);
|
|
25
|
+
const expiresAt = Date.now() + 60 * 60 * 1000;
|
|
26
|
+
headers.set('X-ATP-Token', newToken);
|
|
27
|
+
headers.set('X-ATP-Token-Expires', expiresAt.toString());
|
|
28
|
+
}
|
|
29
|
+
catch (error) { }
|
|
30
|
+
}
|
|
31
|
+
res.writeHead(ctx.status, {
|
|
32
|
+
'Content-Type': 'application/json',
|
|
33
|
+
...Object.fromEntries(headers),
|
|
34
|
+
});
|
|
35
|
+
res.end(JSON.stringify(ctx.responseBody));
|
|
36
|
+
}
|
|
37
|
+
catch (writeError) { }
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
try {
|
|
41
|
+
if (ctx.clientId && deps.sessionManager && ctx.path !== '/api/init') {
|
|
42
|
+
try {
|
|
43
|
+
const newToken = deps.sessionManager.generateToken(ctx.clientId);
|
|
44
|
+
const expiresAt = Date.now() + 60 * 60 * 1000;
|
|
45
|
+
headers.set('X-ATP-Token', newToken);
|
|
46
|
+
headers.set('X-ATP-Token-Expires', expiresAt.toString());
|
|
47
|
+
log.debug('Token refresh headers set on error', {
|
|
48
|
+
clientId: ctx.clientId,
|
|
49
|
+
path: ctx.path,
|
|
50
|
+
hasSessionManager: !!deps.sessionManager,
|
|
51
|
+
headerCount: headers.size,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
catch (tokenError) {
|
|
55
|
+
log.warn('Token refresh failed on error', { error: tokenError });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
log.debug('Token refresh skipped on error', {
|
|
60
|
+
hasClientId: !!ctx.clientId,
|
|
61
|
+
hasSessionManager: !!deps.sessionManager,
|
|
62
|
+
path: ctx.path,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
handleError(res, error, nanoid(), headers);
|
|
66
|
+
}
|
|
67
|
+
catch (handlerError) {
|
|
68
|
+
try {
|
|
69
|
+
if (!res.headersSent) {
|
|
70
|
+
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
71
|
+
res.end(JSON.stringify({ error: 'Internal server error' }));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch { }
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
finally {
|
|
78
|
+
responseHeaders.delete(req);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async function runMiddleware(ctx, middleware, routeHandler) {
|
|
82
|
+
let index = 0;
|
|
83
|
+
const next = async () => {
|
|
84
|
+
const mw = middleware[index++];
|
|
85
|
+
if (mw) {
|
|
86
|
+
await mw(ctx, next);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
await routeHandler(ctx);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
await next();
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=request-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-handler.js","sourceRoot":"","sources":["../../src/http/request-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,GAAG,EAAE,MAAM,8BAA8B,CAAC;AAEnD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAc/D,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACtC,GAAoB,EACpB,GAAmB,EACnB,IAAwB,EACxB,eAA0D;IAE1D,MAAM,GAAG,GAAG,aAAa,CAAC;QACzB,GAAG;QACH,aAAa,EAAE,IAAI,CAAC,aAAa;QACjC,YAAY,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,EAAE,cAAc,EACnB,MAAM,EAAE,uBAAuB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAsBf"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export async function handleRoute(ctx, server) {
|
|
2
|
+
if (ctx.path === '/api/info' && ctx.method === 'GET') {
|
|
3
|
+
ctx.responseBody = server.getInfo();
|
|
4
|
+
}
|
|
5
|
+
else if (ctx.path === '/api/definitions' && ctx.method === 'GET') {
|
|
6
|
+
ctx.responseBody = await server.getDefinitions(ctx);
|
|
7
|
+
}
|
|
8
|
+
else if (ctx.path === '/api/init' && ctx.method === 'POST') {
|
|
9
|
+
ctx.responseBody = await server.handleInit(ctx);
|
|
10
|
+
}
|
|
11
|
+
else if (ctx.path === '/api/search' && ctx.method === 'POST') {
|
|
12
|
+
ctx.responseBody = await server.handleSearch(ctx);
|
|
13
|
+
}
|
|
14
|
+
else if (ctx.path.startsWith('/api/search') && ctx.method === 'GET') {
|
|
15
|
+
ctx.responseBody = await server.handleSearchQuery(ctx);
|
|
16
|
+
}
|
|
17
|
+
else if (ctx.path === '/api/explore' && ctx.method === 'POST') {
|
|
18
|
+
ctx.responseBody = await server.handleExplore(ctx);
|
|
19
|
+
}
|
|
20
|
+
else if (ctx.path === '/api/execute' && ctx.method === 'POST') {
|
|
21
|
+
ctx.responseBody = await server.handleExecute(ctx);
|
|
22
|
+
}
|
|
23
|
+
else if (ctx.path.startsWith('/api/resume/') && ctx.method === 'POST') {
|
|
24
|
+
const executionId = ctx.path.substring('/api/resume/'.length);
|
|
25
|
+
ctx.responseBody = await server.handleResume(ctx, executionId);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
ctx.status = 404;
|
|
29
|
+
ctx.responseBody = { error: 'Not found' };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/http/router.ts"],"names":[],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MAAM,EAAE,CAAC;QACjE,GAAG,CAAC,YAAY,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IACpD,CAAC;SAAM,IAAI,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;QACzE,MAAM,WAAW,GAAG,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QAC9D,GAAG,CAAC,YAAY,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;IAChE,CAAC;SAAM,CAAC;QACP,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC;QACjB,GAAG,CAAC,YAAY,GAAG,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC;IAC3C,CAAC;AACF,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { AgentToolProtocolServer, createServer } from './create-server.js';
|
|
2
|
+
export { loadOpenAPI } from './openapi-loader.js';
|
|
3
|
+
export { APIAggregator } from './aggregator/index.js';
|
|
4
|
+
export { SearchEngine } from './search/index.js';
|
|
5
|
+
export { SandboxExecutor } from './executor/index.js';
|
|
6
|
+
export type { ServerConfig, AuditConfig, Logger, Middleware, RequestContext, } from './core/config.js';
|
|
7
|
+
export { MB, GB, SECOND, MINUTE, HOUR, DAY } from './core/config.js';
|
|
8
|
+
export type { ProvenanceMetadata, SourceMetadata, ToolSource, LLMSource, UserSource, SystemSource, ReaderPermissions, ProvenanceState, PolicyAction, PolicyResult, SecurityPolicy, } from '@mondaydotcomorg/atp-provenance';
|
|
9
|
+
export { ProvenanceMode, ProvenanceSource, ProvenanceSecurityError, createProvenanceProxy, getProvenance, hasProvenance, getAllProvenance, canRead, getProvenanceForPrimitive, markPrimitiveTainted, isPrimitiveTainted, setProvenanceExecutionId, clearProvenanceExecutionId, cleanupProvenanceForExecution, captureProvenanceState, restoreProvenanceState, SecurityPolicyEngine, type Logger as ProvenanceLogger, preventDataExfiltration, preventDataExfiltrationWithApproval, requireUserOrigin, requireUserOriginWithApproval, blockLLMRecipients, blockLLMRecipientsWithApproval, auditSensitiveAccess, getBuiltInPolicies, getBuiltInPoliciesWithApproval, createCustomPolicy, instrumentCode, createTrackingRuntime, } from '@mondaydotcomorg/atp-provenance';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,YAAY,EACX,YAAY,EACZ,WAAW,EACX,MAAM,EACN,UAAU,EACV,cAAc,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAErE,YAAY,EACX,kBAAkB,EAClB,cAAc,EACd,UAAU,EACV,SAAS,EACT,UAAU,EACV,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,cAAc,GACd,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EACN,cAAc,EACd,gBAAgB,EAChB,uBAAuB,EACvB,qBAAqB,EACrB,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,OAAO,EACP,yBAAyB,EACzB,oBAAoB,EACpB,kBAAkB,EAClB,wBAAwB,EACxB,0BAA0B,EAC1B,6BAA6B,EAC7B,sBAAsB,EACtB,sBAAsB,EACtB,oBAAoB,EACpB,KAAK,MAAM,IAAI,gBAAgB,EAC/B,uBAAuB,EACvB,mCAAmC,EACnC,iBAAiB,EACjB,6BAA6B,EAC7B,kBAAkB,EAClB,8BAA8B,EAC9B,oBAAoB,EACpB,kBAAkB,EAClB,8BAA8B,EAC9B,kBAAkB,EAClB,cAAc,EACd,qBAAqB,GACrB,MAAM,iCAAiC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { AgentToolProtocolServer, createServer } from './create-server.js';
|
|
2
|
+
export { loadOpenAPI } from './openapi-loader.js';
|
|
3
|
+
export { APIAggregator } from './aggregator/index.js';
|
|
4
|
+
export { SearchEngine } from './search/index.js';
|
|
5
|
+
export { SandboxExecutor } from './executor/index.js';
|
|
6
|
+
export { MB, GB, SECOND, MINUTE, HOUR, DAY } from './core/config.js';
|
|
7
|
+
export { ProvenanceMode, ProvenanceSource, ProvenanceSecurityError, createProvenanceProxy, getProvenance, hasProvenance, getAllProvenance, canRead, getProvenanceForPrimitive, markPrimitiveTainted, isPrimitiveTainted, setProvenanceExecutionId, clearProvenanceExecutionId, cleanupProvenanceForExecution, captureProvenanceState, restoreProvenanceState, SecurityPolicyEngine, preventDataExfiltration, preventDataExfiltrationWithApproval, requireUserOrigin, requireUserOriginWithApproval, blockLLMRecipients, blockLLMRecipientsWithApproval, auditSensitiveAccess, getBuiltInPolicies, getBuiltInPoliciesWithApproval, createCustomPolicy, instrumentCode, createTrackingRuntime, } from '@mondaydotcomorg/atp-provenance';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAQtD,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAgBrE,OAAO,EACN,cAAc,EACd,gBAAgB,EAChB,uBAAuB,EACvB,qBAAqB,EACrB,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,OAAO,EACP,yBAAyB,EACzB,oBAAoB,EACpB,kBAAkB,EAClB,wBAAwB,EACxB,0BAA0B,EAC1B,6BAA6B,EAC7B,sBAAsB,EACtB,sBAAsB,EACtB,oBAAoB,EAEpB,uBAAuB,EACvB,mCAAmC,EACnC,iBAAiB,EACjB,6BAA6B,EAC7B,kBAAkB,EAClB,8BAA8B,EAC9B,oBAAoB,EACpB,kBAAkB,EAClB,8BAA8B,EAC9B,kBAAkB,EAClB,cAAc,EACd,qBAAqB,GACrB,MAAM,iCAAiC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/instrumentation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/instrumentation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*/
|
|
3
|
+
import type { SerializedValue } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Configuration options for the Serializer
|
|
6
|
+
*/
|
|
7
|
+
export interface SerializerOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Additional global built-ins to skip during variable extraction
|
|
10
|
+
* (beyond the standard JavaScript built-ins that are detected automatically)
|
|
11
|
+
*/
|
|
12
|
+
customGlobalBuiltIns?: string[];
|
|
13
|
+
/**
|
|
14
|
+
* Whether to use caching for keyword/built-in detection
|
|
15
|
+
* Default: true (recommended for performance)
|
|
16
|
+
*/
|
|
17
|
+
enableCaching?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare class Serializer {
|
|
20
|
+
private refCounter;
|
|
21
|
+
private refMap;
|
|
22
|
+
private customGlobalBuiltIns;
|
|
23
|
+
private keywordCache;
|
|
24
|
+
private globalCache;
|
|
25
|
+
private enableCaching;
|
|
26
|
+
constructor(options?: SerializerOptions);
|
|
27
|
+
/**
|
|
28
|
+
* Deep serialize a value with circular reference detection
|
|
29
|
+
*/
|
|
30
|
+
serialize(value: unknown, scope?: Record<string, unknown>): SerializedValue;
|
|
31
|
+
/**
|
|
32
|
+
* Deserialize a value back to its original form
|
|
33
|
+
*/
|
|
34
|
+
deserialize(serialized: SerializedValue, refRegistry?: Map<string, unknown>): unknown;
|
|
35
|
+
private deepSerialize;
|
|
36
|
+
private serializeFunction;
|
|
37
|
+
private extractReferencedVars;
|
|
38
|
+
/**
|
|
39
|
+
* Check if a name is a reserved JavaScript keyword
|
|
40
|
+
* Uses caching for performance when enabled
|
|
41
|
+
*/
|
|
42
|
+
private isReservedKeyword;
|
|
43
|
+
/**
|
|
44
|
+
* Check if a name is a global built-in
|
|
45
|
+
* Dynamically detects built-ins at runtime with caching for performance
|
|
46
|
+
*/
|
|
47
|
+
private isGlobalBuiltIn;
|
|
48
|
+
/**
|
|
49
|
+
* Detect all global built-ins at runtime
|
|
50
|
+
* This is called once and cached for performance
|
|
51
|
+
*/
|
|
52
|
+
private detectGlobalBuiltIns;
|
|
53
|
+
/**
|
|
54
|
+
* Check if a name is a property of the global object
|
|
55
|
+
* Used when caching is disabled
|
|
56
|
+
*/
|
|
57
|
+
private isGlobalProperty;
|
|
58
|
+
private deepDeserialize;
|
|
59
|
+
private deserializeFunction;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=serializer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializer.d.ts","sourceRoot":"","sources":["../../src/instrumentation/serializer.ts"],"names":[],"mappings":"AAAA;GACG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IACjC;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAEhC;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACxB;AAOD,qBAAa,UAAU;IACtB,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,MAAM,CAAiC;IAC/C,OAAO,CAAC,oBAAoB,CAAc;IAC1C,OAAO,CAAC,YAAY,CAA8B;IAClD,OAAO,CAAC,WAAW,CAA4B;IAC/C,OAAO,CAAC,aAAa,CAAU;gBAEnB,OAAO,GAAE,iBAAsB;IAK3C;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,eAAe;IAK/E;;OAEG;IACH,WAAW,CAAC,UAAU,EAAE,eAAe,EAAE,WAAW,GAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAa,GAAG,OAAO;IAIhG,OAAO,CAAC,aAAa;IAsGrB,OAAO,CAAC,iBAAiB;IAsCzB,OAAO,CAAC,qBAAqB;IAyB7B;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAoBzB;;;OAGG;IACH,OAAO,CAAC,eAAe;IAgBvB;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IA2D5B;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAUxB,OAAO,CAAC,eAAe;IA0DvB,OAAO,CAAC,mBAAmB;CAsB3B"}
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime-detected global built-ins (cached for performance)
|
|
3
|
+
*/
|
|
4
|
+
let cachedGlobals = null;
|
|
5
|
+
export class Serializer {
|
|
6
|
+
refCounter = 0;
|
|
7
|
+
refMap = new WeakMap();
|
|
8
|
+
customGlobalBuiltIns;
|
|
9
|
+
keywordCache = new Map();
|
|
10
|
+
globalCache = null;
|
|
11
|
+
enableCaching;
|
|
12
|
+
constructor(options = {}) {
|
|
13
|
+
this.customGlobalBuiltIns = new Set(options.customGlobalBuiltIns || []);
|
|
14
|
+
this.enableCaching = options.enableCaching !== false;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Deep serialize a value with circular reference detection
|
|
18
|
+
*/
|
|
19
|
+
serialize(value, scope = {}) {
|
|
20
|
+
const visited = new WeakSet();
|
|
21
|
+
return this.deepSerialize(value, scope, visited);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Deserialize a value back to its original form
|
|
25
|
+
*/
|
|
26
|
+
deserialize(serialized, refRegistry = new Map()) {
|
|
27
|
+
return this.deepDeserialize(serialized, refRegistry);
|
|
28
|
+
}
|
|
29
|
+
deepSerialize(value, scope, visited) {
|
|
30
|
+
if (value === null || value === undefined) {
|
|
31
|
+
return { type: 'primitive', value };
|
|
32
|
+
}
|
|
33
|
+
const type = typeof value;
|
|
34
|
+
if (type === 'string' ||
|
|
35
|
+
type === 'number' ||
|
|
36
|
+
type === 'boolean' ||
|
|
37
|
+
type === 'bigint' ||
|
|
38
|
+
type === 'symbol') {
|
|
39
|
+
if (type === 'bigint') {
|
|
40
|
+
return { type: 'primitive', value: value.toString() + 'n' };
|
|
41
|
+
}
|
|
42
|
+
if (type === 'symbol') {
|
|
43
|
+
return { type: 'primitive', value: value.toString() };
|
|
44
|
+
}
|
|
45
|
+
return { type: 'primitive', value };
|
|
46
|
+
}
|
|
47
|
+
if (type === 'function') {
|
|
48
|
+
return this.serializeFunction(value, scope, visited);
|
|
49
|
+
}
|
|
50
|
+
if (type === 'object' && value !== null) {
|
|
51
|
+
if (visited.has(value)) {
|
|
52
|
+
let refId = this.refMap.get(value);
|
|
53
|
+
if (!refId) {
|
|
54
|
+
refId = `ref_${this.refCounter++}`;
|
|
55
|
+
this.refMap.set(value, refId);
|
|
56
|
+
}
|
|
57
|
+
return { type: 'circular', refId };
|
|
58
|
+
}
|
|
59
|
+
visited.add(value);
|
|
60
|
+
if (value instanceof Date) {
|
|
61
|
+
return {
|
|
62
|
+
type: 'date',
|
|
63
|
+
value: value.toISOString(),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (value instanceof RegExp) {
|
|
67
|
+
return {
|
|
68
|
+
type: 'regexp',
|
|
69
|
+
pattern: value.source,
|
|
70
|
+
flags: value.flags,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (Array.isArray(value)) {
|
|
74
|
+
return {
|
|
75
|
+
type: 'array',
|
|
76
|
+
value: value.map((item) => this.deepSerialize(item, scope, visited)),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
if (value instanceof Map) {
|
|
80
|
+
const entries = [];
|
|
81
|
+
for (const [k, v] of value.entries()) {
|
|
82
|
+
entries.push([
|
|
83
|
+
this.deepSerialize(k, scope, visited),
|
|
84
|
+
this.deepSerialize(v, scope, visited),
|
|
85
|
+
]);
|
|
86
|
+
}
|
|
87
|
+
return { type: 'map', entries };
|
|
88
|
+
}
|
|
89
|
+
if (value instanceof Set) {
|
|
90
|
+
const items = [];
|
|
91
|
+
for (const item of value.values()) {
|
|
92
|
+
items.push(this.deepSerialize(item, scope, visited));
|
|
93
|
+
}
|
|
94
|
+
return { type: 'set', items };
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
const properties = {};
|
|
98
|
+
for (const [k, v] of Object.entries(value)) {
|
|
99
|
+
properties[k] = this.deepSerialize(v, scope, visited);
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
type: 'object',
|
|
103
|
+
className: value.constructor?.name,
|
|
104
|
+
properties,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
return { type: 'nonserializable' };
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return { type: 'nonserializable' };
|
|
112
|
+
}
|
|
113
|
+
serializeFunction(fn, scope, visited) {
|
|
114
|
+
try {
|
|
115
|
+
const source = fn.toString();
|
|
116
|
+
if (source.includes('[native code]')) {
|
|
117
|
+
return {
|
|
118
|
+
type: 'function',
|
|
119
|
+
source: 'native',
|
|
120
|
+
className: fn.name,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
const referencedVars = this.extractReferencedVars(source);
|
|
124
|
+
const closure = {};
|
|
125
|
+
for (const varName of referencedVars) {
|
|
126
|
+
if (varName in scope) {
|
|
127
|
+
closure[varName] = this.deepSerialize(scope[varName], scope, visited);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
type: 'function',
|
|
132
|
+
source,
|
|
133
|
+
closure,
|
|
134
|
+
isAsync: source.startsWith('async'),
|
|
135
|
+
isGenerator: fn.constructor.name === 'GeneratorFunction',
|
|
136
|
+
isArrow: source.includes('=>'),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
catch (e) {
|
|
140
|
+
return { type: 'nonserializable' };
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
extractReferencedVars(source) {
|
|
144
|
+
const vars = new Set();
|
|
145
|
+
const identifierRegex = /\b([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g;
|
|
146
|
+
let match;
|
|
147
|
+
while ((match = identifierRegex.exec(source)) !== null) {
|
|
148
|
+
const name = match[1];
|
|
149
|
+
if (!name)
|
|
150
|
+
continue;
|
|
151
|
+
if (this.isReservedKeyword(name)) {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (this.isGlobalBuiltIn(name)) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
vars.add(name);
|
|
158
|
+
}
|
|
159
|
+
return vars;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Check if a name is a reserved JavaScript keyword
|
|
163
|
+
* Uses caching for performance when enabled
|
|
164
|
+
*/
|
|
165
|
+
isReservedKeyword(name) {
|
|
166
|
+
if (this.enableCaching && this.keywordCache.has(name)) {
|
|
167
|
+
return this.keywordCache.get(name);
|
|
168
|
+
}
|
|
169
|
+
let isKeyword = false;
|
|
170
|
+
try {
|
|
171
|
+
new Function(`var ${name};`);
|
|
172
|
+
isKeyword = false;
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
isKeyword = true;
|
|
176
|
+
}
|
|
177
|
+
if (this.enableCaching) {
|
|
178
|
+
this.keywordCache.set(name, isKeyword);
|
|
179
|
+
}
|
|
180
|
+
return isKeyword;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Check if a name is a global built-in
|
|
184
|
+
* Dynamically detects built-ins at runtime with caching for performance
|
|
185
|
+
*/
|
|
186
|
+
isGlobalBuiltIn(name) {
|
|
187
|
+
if (this.customGlobalBuiltIns.has(name)) {
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
if (this.enableCaching && !this.globalCache) {
|
|
191
|
+
this.globalCache = this.detectGlobalBuiltIns();
|
|
192
|
+
}
|
|
193
|
+
if (this.enableCaching && this.globalCache) {
|
|
194
|
+
return this.globalCache.has(name);
|
|
195
|
+
}
|
|
196
|
+
return this.isGlobalProperty(name);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Detect all global built-ins at runtime
|
|
200
|
+
* This is called once and cached for performance
|
|
201
|
+
*/
|
|
202
|
+
detectGlobalBuiltIns() {
|
|
203
|
+
const globals = new Set();
|
|
204
|
+
const globalObj = typeof globalThis !== 'undefined' ? globalThis : global;
|
|
205
|
+
try {
|
|
206
|
+
const ownProps = Object.getOwnPropertyNames(globalObj);
|
|
207
|
+
for (const prop of ownProps) {
|
|
208
|
+
globals.add(prop);
|
|
209
|
+
}
|
|
210
|
+
let proto = Object.getPrototypeOf(globalObj);
|
|
211
|
+
while (proto) {
|
|
212
|
+
const protoProps = Object.getOwnPropertyNames(proto);
|
|
213
|
+
for (const prop of protoProps) {
|
|
214
|
+
globals.add(prop);
|
|
215
|
+
}
|
|
216
|
+
proto = Object.getPrototypeOf(proto);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
catch (e) {
|
|
220
|
+
const fallbackGlobals = [
|
|
221
|
+
'undefined',
|
|
222
|
+
'null',
|
|
223
|
+
'true',
|
|
224
|
+
'false',
|
|
225
|
+
'Math',
|
|
226
|
+
'Date',
|
|
227
|
+
'Array',
|
|
228
|
+
'Object',
|
|
229
|
+
'String',
|
|
230
|
+
'Number',
|
|
231
|
+
'Boolean',
|
|
232
|
+
'Promise',
|
|
233
|
+
'Set',
|
|
234
|
+
'Map',
|
|
235
|
+
'WeakMap',
|
|
236
|
+
'WeakSet',
|
|
237
|
+
'JSON',
|
|
238
|
+
'Error',
|
|
239
|
+
'TypeError',
|
|
240
|
+
'RegExp',
|
|
241
|
+
'parseInt',
|
|
242
|
+
'parseFloat',
|
|
243
|
+
'isNaN',
|
|
244
|
+
'isFinite',
|
|
245
|
+
'console',
|
|
246
|
+
'process',
|
|
247
|
+
'Buffer',
|
|
248
|
+
'global',
|
|
249
|
+
'globalThis',
|
|
250
|
+
];
|
|
251
|
+
for (const g of fallbackGlobals) {
|
|
252
|
+
globals.add(g);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return globals;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Check if a name is a property of the global object
|
|
259
|
+
* Used when caching is disabled
|
|
260
|
+
*/
|
|
261
|
+
isGlobalProperty(name) {
|
|
262
|
+
const globalObj = typeof globalThis !== 'undefined' ? globalThis : global;
|
|
263
|
+
try {
|
|
264
|
+
return name in globalObj;
|
|
265
|
+
}
|
|
266
|
+
catch {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
deepDeserialize(serialized, refRegistry) {
|
|
271
|
+
switch (serialized.type) {
|
|
272
|
+
case 'primitive':
|
|
273
|
+
return serialized.value;
|
|
274
|
+
case 'date':
|
|
275
|
+
return new Date(serialized.value);
|
|
276
|
+
case 'regexp':
|
|
277
|
+
return new RegExp(serialized.pattern || '', serialized.flags || '');
|
|
278
|
+
case 'array':
|
|
279
|
+
return serialized.value.map((item) => this.deepDeserialize(item, refRegistry));
|
|
280
|
+
case 'map': {
|
|
281
|
+
const map = new Map();
|
|
282
|
+
if (serialized.entries) {
|
|
283
|
+
for (const [k, v] of serialized.entries) {
|
|
284
|
+
map.set(this.deepDeserialize(k, refRegistry), this.deepDeserialize(v, refRegistry));
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return map;
|
|
288
|
+
}
|
|
289
|
+
case 'set': {
|
|
290
|
+
const set = new Set();
|
|
291
|
+
if (serialized.items) {
|
|
292
|
+
for (const item of serialized.items) {
|
|
293
|
+
set.add(this.deepDeserialize(item, refRegistry));
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return set;
|
|
297
|
+
}
|
|
298
|
+
case 'object': {
|
|
299
|
+
const obj = {};
|
|
300
|
+
if (serialized.properties) {
|
|
301
|
+
for (const [k, v] of Object.entries(serialized.properties)) {
|
|
302
|
+
obj[k] = this.deepDeserialize(v, refRegistry);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return obj;
|
|
306
|
+
}
|
|
307
|
+
case 'function':
|
|
308
|
+
return this.deserializeFunction(serialized, refRegistry);
|
|
309
|
+
case 'circular':
|
|
310
|
+
return refRegistry.get(serialized.refId) || null;
|
|
311
|
+
case 'nonserializable':
|
|
312
|
+
default:
|
|
313
|
+
return undefined;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
deserializeFunction(serialized, refRegistry) {
|
|
317
|
+
try {
|
|
318
|
+
if (serialized.source === 'native' || !serialized.source) {
|
|
319
|
+
return undefined;
|
|
320
|
+
}
|
|
321
|
+
const closureNames = Object.keys(serialized.closure || {});
|
|
322
|
+
const closureValues = closureNames.map((name) => {
|
|
323
|
+
const closureValue = serialized.closure?.[name];
|
|
324
|
+
return closureValue ? this.deepDeserialize(closureValue, refRegistry) : undefined;
|
|
325
|
+
});
|
|
326
|
+
const fnFactory = new Function(...closureNames, `return ${serialized.source}`);
|
|
327
|
+
return fnFactory(...closureValues);
|
|
328
|
+
}
|
|
329
|
+
catch (e) {
|
|
330
|
+
return undefined;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
//# sourceMappingURL=serializer.js.map
|