@sequenceholdings/managed-functions 0.4.1 → 0.4.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/README.md +374 -2
- package/dist/abrigo-contract.d.ts +92 -0
- package/dist/abrigo-contract.js +55 -0
- package/dist/abrigo-response.d.ts +6 -0
- package/dist/abrigo-response.js +27 -0
- package/dist/abrigo.d.ts +14 -0
- package/dist/abrigo.js +150 -0
- package/dist/agent-evidence.d.ts +9 -0
- package/dist/agent-evidence.js +84 -0
- package/dist/agent-source-evidence-contract.d.ts +1197 -0
- package/dist/agent-source-evidence-contract.js +96 -0
- package/dist/agents-contract.d.ts +99 -0
- package/dist/agents-contract.js +69 -0
- package/dist/agents.d.ts +15 -0
- package/dist/agents.js +121 -0
- package/dist/capabilities.d.ts +150 -0
- package/dist/capabilities.js +58 -5
- package/dist/config.d.ts +17 -2
- package/dist/config.js +55 -1
- package/dist/deployed-policy.js +90 -2
- package/dist/directory-config.js +1 -1
- package/dist/directory-contract.d.ts +68 -0
- package/dist/directory-contract.js +57 -0
- package/dist/directory-manifest.d.ts +5 -0
- package/dist/directory-manifest.js +10 -0
- package/dist/http-tracing.js +3 -0
- package/dist/immutable-release-contract.d.ts +3 -0
- package/dist/immutable-release-contract.js +12 -0
- package/dist/index.d.ts +37 -1
- package/dist/index.js +72 -1
- package/dist/invocation-client.d.ts +8 -1
- package/dist/invocation-client.js +8 -3
- package/dist/invocation-contract.d.ts +36 -0
- package/dist/invocation-contract.js +48 -0
- package/dist/invocation.d.ts +8 -0
- package/dist/invocation.js +134 -0
- package/dist/lattice-capability.d.ts +5 -0
- package/dist/lattice-capability.js +16 -0
- package/dist/lattice-provenance-contract.d.ts +519 -0
- package/dist/lattice-provenance-contract.js +148 -0
- package/dist/lattice-provenance.d.ts +16 -0
- package/dist/lattice-provenance.js +167 -0
- package/dist/monitoring-annotations.d.ts +53 -0
- package/dist/monitoring-annotations.js +54 -0
- package/dist/monitoring-contract.d.ts +463 -0
- package/dist/monitoring-contract.js +89 -0
- package/dist/monitoring-events.d.ts +257 -0
- package/dist/monitoring-events.js +136 -0
- package/dist/monitoring.d.ts +14 -0
- package/dist/monitoring.js +78 -0
- package/dist/orm-contract.d.ts +1 -0
- package/dist/orm-contract.js +4 -0
- package/dist/orm.d.ts +19 -3
- package/dist/orm.js +93 -13
- package/dist/preflight-abrigo.d.ts +10 -0
- package/dist/preflight-abrigo.js +26 -0
- package/dist/preflight-agents.d.ts +10 -0
- package/dist/preflight-agents.js +51 -0
- package/dist/preflight-immutable-release.d.ts +10 -0
- package/dist/preflight-immutable-release.js +34 -0
- package/dist/preflight-invocation.d.ts +10 -0
- package/dist/preflight-invocation.js +40 -0
- package/dist/preflight-lattice.d.ts +10 -0
- package/dist/preflight-lattice.js +40 -0
- package/dist/preflight-monitoring.d.ts +10 -0
- package/dist/preflight-monitoring.js +46 -0
- package/dist/preflight-service-directory.d.ts +10 -0
- package/dist/preflight-service-directory.js +26 -0
- package/dist/preflight-workflows.d.ts +10 -0
- package/dist/preflight-workflows.js +38 -0
- package/dist/preflight.js +49 -5
- package/dist/processes-contract.d.ts +20 -0
- package/dist/processes-contract.js +8 -1
- package/dist/processes.d.ts +2 -1
- package/dist/processes.js +34 -0
- package/dist/runtime.cjs +3111 -214
- package/dist/sdk-range.d.ts +1 -0
- package/dist/sdk-range.js +25 -0
- package/dist/service-directory.d.ts +12 -0
- package/dist/service-directory.js +72 -0
- package/dist/workflow-scopes-contract.d.ts +8 -0
- package/dist/workflow-scopes-contract.js +29 -0
- package/dist/workflow-source-contract.d.ts +524 -0
- package/dist/workflow-source-contract.js +59 -0
- package/dist/workflow-source.d.ts +12 -0
- package/dist/workflow-source.js +93 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,13 +1,81 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.readCacheConfiguration = exports.cacheManifestSchema = exports.createCacheManager = exports.CacheError = exports.createFunctionStorageClient = exports.runWithFunctionTracing = exports.installFunctionTracing = exports.FunctionProcessReadError = exports.createFunctionServiceProcessesClient = exports.FunctionDirectoryReadError = exports.createFunctionDirectoryClient = void 0;
|
|
17
|
+
exports.createFunctionServiceDirectoryClient = exports.readCacheConfiguration = exports.cacheManifestSchema = exports.createCacheManager = exports.CacheError = exports.createFunctionStorageClient = exports.runWithFunctionTracing = exports.installFunctionTracing = exports.functionMonitoringAnnotationSchema = exports.monitoringPublishSchema = exports.monitoringEventsSchema = exports.monitoringPayloadHash = exports.FunctionMonitoringError = exports.createFunctionServiceMonitoringClient = exports.functionSourceJobAdmissionSchema = exports.functionAgentSourceExecutionSchema = exports.functionAgentConversationEvidenceRequestSchema = exports.functionAgentConversationEvidenceCaptureSchema = exports.functionAgentConversationEvidenceResponseSchema = exports.functionAgentSourceEvidenceCaptureSchema = exports.functionAgentSourceEvidenceRequestSchema = exports.functionAgentSourceResponseSchema = exports.createFunctionWorkflowEvidenceClient = exports.createFunctionServiceWorkflowsClient = exports.createFunctionAgentEvidenceClient = exports.FunctionAgentReadError = exports.createFunctionServiceAgentsClient = exports.FunctionProcessReadError = exports.createFunctionServiceProcessesClient = exports.functionLatticeHumanCompletionsPageSchema = exports.functionLatticeHumanCompletionsQuerySchema = exports.functionLatticeHumanCompletionSchema = exports.functionLatticeHumanCompletionQuerySchema = exports.functionLatticeExecutionContextSchema = exports.functionLatticeContextRequestSchema = exports.FunctionLatticeContextError = exports.FUNCTION_LATTICE_EXECUTION_TOKEN_HEADER = exports.FUNCTION_LATTICE_CONTEXT_PATH = exports.createFunctionInvocationClient = exports.functionLatticeStartProvenanceSchema = exports.functionLatticeParallelSnapshotQuerySchema = exports.functionLatticeParallelSnapshotSchema = exports.createFunctionLatticeClient = exports.readFunctionLatticeContextCapability = exports.functionLatticeContextCapabilitySchema = exports.FunctionDirectoryReadError = exports.createFunctionDirectoryClient = void 0;
|
|
4
18
|
exports.createManagedFunctionContext = createManagedFunctionContext;
|
|
5
19
|
var directory_1 = require("./directory");
|
|
6
20
|
Object.defineProperty(exports, "createFunctionDirectoryClient", { enumerable: true, get: function () { return directory_1.createFunctionDirectoryClient; } });
|
|
7
21
|
Object.defineProperty(exports, "FunctionDirectoryReadError", { enumerable: true, get: function () { return directory_1.FunctionDirectoryReadError; } });
|
|
22
|
+
var lattice_capability_1 = require("./lattice-capability");
|
|
23
|
+
Object.defineProperty(exports, "functionLatticeContextCapabilitySchema", { enumerable: true, get: function () { return lattice_capability_1.functionLatticeContextCapabilitySchema; } });
|
|
24
|
+
Object.defineProperty(exports, "readFunctionLatticeContextCapability", { enumerable: true, get: function () { return lattice_capability_1.readFunctionLatticeContextCapability; } });
|
|
25
|
+
var lattice_provenance_1 = require("./lattice-provenance");
|
|
26
|
+
Object.defineProperty(exports, "createFunctionLatticeClient", { enumerable: true, get: function () { return lattice_provenance_1.createFunctionLatticeClient; } });
|
|
27
|
+
var lattice_provenance_contract_1 = require("./lattice-provenance-contract");
|
|
28
|
+
Object.defineProperty(exports, "functionLatticeParallelSnapshotSchema", { enumerable: true, get: function () { return lattice_provenance_contract_1.functionLatticeParallelSnapshotSchema; } });
|
|
29
|
+
Object.defineProperty(exports, "functionLatticeParallelSnapshotQuerySchema", { enumerable: true, get: function () { return lattice_provenance_contract_1.functionLatticeParallelSnapshotQuerySchema; } });
|
|
30
|
+
var lattice_provenance_contract_2 = require("./lattice-provenance-contract");
|
|
31
|
+
Object.defineProperty(exports, "functionLatticeStartProvenanceSchema", { enumerable: true, get: function () { return lattice_provenance_contract_2.functionLatticeStartProvenanceSchema; } });
|
|
32
|
+
__exportStar(require("./invocation-contract"), exports);
|
|
33
|
+
__exportStar(require("./abrigo"), exports);
|
|
34
|
+
var invocation_1 = require("./invocation");
|
|
35
|
+
Object.defineProperty(exports, "createFunctionInvocationClient", { enumerable: true, get: function () { return invocation_1.createFunctionInvocationClient; } });
|
|
36
|
+
var lattice_provenance_contract_3 = require("./lattice-provenance-contract");
|
|
37
|
+
Object.defineProperty(exports, "FUNCTION_LATTICE_CONTEXT_PATH", { enumerable: true, get: function () { return lattice_provenance_contract_3.FUNCTION_LATTICE_CONTEXT_PATH; } });
|
|
38
|
+
Object.defineProperty(exports, "FUNCTION_LATTICE_EXECUTION_TOKEN_HEADER", { enumerable: true, get: function () { return lattice_provenance_contract_3.FUNCTION_LATTICE_EXECUTION_TOKEN_HEADER; } });
|
|
39
|
+
Object.defineProperty(exports, "FunctionLatticeContextError", { enumerable: true, get: function () { return lattice_provenance_contract_3.FunctionLatticeContextError; } });
|
|
40
|
+
Object.defineProperty(exports, "functionLatticeContextRequestSchema", { enumerable: true, get: function () { return lattice_provenance_contract_3.functionLatticeContextRequestSchema; } });
|
|
41
|
+
Object.defineProperty(exports, "functionLatticeExecutionContextSchema", { enumerable: true, get: function () { return lattice_provenance_contract_3.functionLatticeExecutionContextSchema; } });
|
|
42
|
+
Object.defineProperty(exports, "functionLatticeHumanCompletionQuerySchema", { enumerable: true, get: function () { return lattice_provenance_contract_3.functionLatticeHumanCompletionQuerySchema; } });
|
|
43
|
+
Object.defineProperty(exports, "functionLatticeHumanCompletionSchema", { enumerable: true, get: function () { return lattice_provenance_contract_3.functionLatticeHumanCompletionSchema; } });
|
|
44
|
+
var lattice_provenance_contract_4 = require("./lattice-provenance-contract");
|
|
45
|
+
Object.defineProperty(exports, "functionLatticeHumanCompletionsQuerySchema", { enumerable: true, get: function () { return lattice_provenance_contract_4.functionLatticeHumanCompletionsQuerySchema; } });
|
|
46
|
+
Object.defineProperty(exports, "functionLatticeHumanCompletionsPageSchema", { enumerable: true, get: function () { return lattice_provenance_contract_4.functionLatticeHumanCompletionsPageSchema; } });
|
|
8
47
|
var processes_1 = require("./processes");
|
|
9
48
|
Object.defineProperty(exports, "createFunctionServiceProcessesClient", { enumerable: true, get: function () { return processes_1.createFunctionServiceProcessesClient; } });
|
|
10
49
|
Object.defineProperty(exports, "FunctionProcessReadError", { enumerable: true, get: function () { return processes_1.FunctionProcessReadError; } });
|
|
50
|
+
var agents_1 = require("./agents");
|
|
51
|
+
Object.defineProperty(exports, "createFunctionServiceAgentsClient", { enumerable: true, get: function () { return agents_1.createFunctionServiceAgentsClient; } });
|
|
52
|
+
Object.defineProperty(exports, "FunctionAgentReadError", { enumerable: true, get: function () { return agents_1.FunctionAgentReadError; } });
|
|
53
|
+
var agent_evidence_1 = require("./agent-evidence");
|
|
54
|
+
Object.defineProperty(exports, "createFunctionAgentEvidenceClient", { enumerable: true, get: function () { return agent_evidence_1.createFunctionAgentEvidenceClient; } });
|
|
55
|
+
var workflow_source_1 = require("./workflow-source");
|
|
56
|
+
Object.defineProperty(exports, "createFunctionServiceWorkflowsClient", { enumerable: true, get: function () { return workflow_source_1.createFunctionServiceWorkflowsClient; } });
|
|
57
|
+
Object.defineProperty(exports, "createFunctionWorkflowEvidenceClient", { enumerable: true, get: function () { return workflow_source_1.createFunctionWorkflowEvidenceClient; } });
|
|
58
|
+
__exportStar(require("./workflow-source-contract"), exports);
|
|
59
|
+
var agent_source_evidence_contract_1 = require("./agent-source-evidence-contract");
|
|
60
|
+
Object.defineProperty(exports, "functionAgentSourceResponseSchema", { enumerable: true, get: function () { return agent_source_evidence_contract_1.functionAgentSourceResponseSchema; } });
|
|
61
|
+
Object.defineProperty(exports, "functionAgentSourceEvidenceRequestSchema", { enumerable: true, get: function () { return agent_source_evidence_contract_1.functionAgentSourceEvidenceRequestSchema; } });
|
|
62
|
+
Object.defineProperty(exports, "functionAgentSourceEvidenceCaptureSchema", { enumerable: true, get: function () { return agent_source_evidence_contract_1.functionAgentSourceEvidenceCaptureSchema; } });
|
|
63
|
+
Object.defineProperty(exports, "functionAgentConversationEvidenceResponseSchema", { enumerable: true, get: function () { return agent_source_evidence_contract_1.functionAgentConversationEvidenceResponseSchema; } });
|
|
64
|
+
Object.defineProperty(exports, "functionAgentConversationEvidenceCaptureSchema", { enumerable: true, get: function () { return agent_source_evidence_contract_1.functionAgentConversationEvidenceCaptureSchema; } });
|
|
65
|
+
Object.defineProperty(exports, "functionAgentConversationEvidenceRequestSchema", { enumerable: true, get: function () { return agent_source_evidence_contract_1.functionAgentConversationEvidenceRequestSchema; } });
|
|
66
|
+
Object.defineProperty(exports, "functionAgentSourceExecutionSchema", { enumerable: true, get: function () { return agent_source_evidence_contract_1.functionAgentSourceExecutionSchema; } });
|
|
67
|
+
var agent_source_evidence_contract_2 = require("./agent-source-evidence-contract");
|
|
68
|
+
Object.defineProperty(exports, "functionSourceJobAdmissionSchema", { enumerable: true, get: function () { return agent_source_evidence_contract_2.functionSourceJobAdmissionSchema; } });
|
|
69
|
+
var monitoring_1 = require("./monitoring");
|
|
70
|
+
Object.defineProperty(exports, "createFunctionServiceMonitoringClient", { enumerable: true, get: function () { return monitoring_1.createFunctionServiceMonitoringClient; } });
|
|
71
|
+
var monitoring_contract_1 = require("./monitoring-contract");
|
|
72
|
+
Object.defineProperty(exports, "FunctionMonitoringError", { enumerable: true, get: function () { return monitoring_contract_1.FunctionMonitoringError; } });
|
|
73
|
+
Object.defineProperty(exports, "monitoringPayloadHash", { enumerable: true, get: function () { return monitoring_contract_1.monitoringPayloadHash; } });
|
|
74
|
+
var monitoring_contract_2 = require("./monitoring-contract");
|
|
75
|
+
Object.defineProperty(exports, "monitoringEventsSchema", { enumerable: true, get: function () { return monitoring_contract_2.monitoringEventsSchema; } });
|
|
76
|
+
Object.defineProperty(exports, "monitoringPublishSchema", { enumerable: true, get: function () { return monitoring_contract_2.monitoringPublishSchema; } });
|
|
77
|
+
var monitoring_annotations_1 = require("./monitoring-annotations");
|
|
78
|
+
Object.defineProperty(exports, "functionMonitoringAnnotationSchema", { enumerable: true, get: function () { return monitoring_annotations_1.functionMonitoringAnnotationSchema; } });
|
|
11
79
|
var tracing_1 = require("./tracing");
|
|
12
80
|
Object.defineProperty(exports, "installFunctionTracing", { enumerable: true, get: function () { return tracing_1.installFunctionTracing; } });
|
|
13
81
|
Object.defineProperty(exports, "runWithFunctionTracing", { enumerable: true, get: function () { return tracing_1.runWithFunctionTracing; } });
|
|
@@ -68,3 +136,6 @@ function lazyValkeyStore(connection, local) {
|
|
|
68
136
|
delete: async (key) => (await client()).delete(key),
|
|
69
137
|
};
|
|
70
138
|
}
|
|
139
|
+
__exportStar(require("./directory-contract"), exports);
|
|
140
|
+
var service_directory_1 = require("./service-directory");
|
|
141
|
+
Object.defineProperty(exports, "createFunctionServiceDirectoryClient", { enumerable: true, get: function () { return service_directory_1.createFunctionServiceDirectoryClient; } });
|
|
@@ -18,13 +18,20 @@ export declare function readInvocationCredential<T extends {
|
|
|
18
18
|
token: string;
|
|
19
19
|
expiresAt: number;
|
|
20
20
|
};
|
|
21
|
-
export declare function createInvocationReadTransport({ baseUrl, fetchImpl, path, header, credential, timeoutMs, error, failure, }: Pick<FunctionInvocationClientOptions, 'baseUrl' | 'fetchImpl'> & {
|
|
21
|
+
export declare function createInvocationReadTransport({ baseUrl, fetchImpl, path, header, credential, additionalCredentials, timeoutMs, error, failure, }: Pick<FunctionInvocationClientOptions, 'baseUrl' | 'fetchImpl'> & {
|
|
22
22
|
path: string;
|
|
23
23
|
header: string;
|
|
24
24
|
credential: {
|
|
25
25
|
token: string;
|
|
26
26
|
expiresAt: number;
|
|
27
27
|
};
|
|
28
|
+
additionalCredentials?: readonly {
|
|
29
|
+
header: string;
|
|
30
|
+
credential: {
|
|
31
|
+
token: string;
|
|
32
|
+
expiresAt: number;
|
|
33
|
+
};
|
|
34
|
+
}[];
|
|
28
35
|
timeoutMs: number;
|
|
29
36
|
error: ClientErrorFactory;
|
|
30
37
|
failure: {
|
|
@@ -54,17 +54,22 @@ const errorResponseSchema = zod_1.z.object({
|
|
|
54
54
|
code: zod_1.z.string().max(128).optional(),
|
|
55
55
|
detail: zod_1.z.string().max(2000).optional(),
|
|
56
56
|
});
|
|
57
|
-
function createInvocationReadTransport({ baseUrl, fetchImpl = globalThis.fetch, path, header, credential, timeoutMs, error, failure, }) {
|
|
57
|
+
function createInvocationReadTransport({ baseUrl, fetchImpl = globalThis.fetch, path, header, credential, additionalCredentials = [], timeoutMs, error, failure, }) {
|
|
58
58
|
const url = `${trustedOrigin({ baseUrl, error })}${path}`;
|
|
59
|
+
const credentials = [{ header, credential }, ...additionalCredentials];
|
|
60
|
+
const names = credentials.map((value) => value.header.toLowerCase());
|
|
61
|
+
if (new Set(names).size !== names.length || names.includes('content-type')) {
|
|
62
|
+
throw error(400, 'invalid_configuration', 'Credential headers must be distinct');
|
|
63
|
+
}
|
|
59
64
|
return async function read({ body, schema, }) {
|
|
60
|
-
if (credential.expiresAt <= Date.now() / 1000) {
|
|
65
|
+
if (credentials.some((value) => value.credential.expiresAt <= Date.now() / 1000)) {
|
|
61
66
|
throw error(401, 'expired_context', 'The invocation credential expired; start a new invocation');
|
|
62
67
|
}
|
|
63
68
|
const response = await fetchImpl(url, {
|
|
64
69
|
method: 'POST',
|
|
65
70
|
headers: {
|
|
66
71
|
'content-type': 'application/json',
|
|
67
|
-
[header
|
|
72
|
+
...Object.fromEntries(credentials.map((value) => [value.header, value.credential.token])),
|
|
68
73
|
},
|
|
69
74
|
body: JSON.stringify(body),
|
|
70
75
|
redirect: 'error',
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const FUNCTION_INVOCATION_IDENTITY_TOKEN_HEADER = "x-sequence-invocation-identity-token";
|
|
3
|
+
export declare const FUNCTION_INVOCATION_CONTEXT_PATH = "/api/managed-functions/invocation/context";
|
|
4
|
+
export declare const functionInvocationIdentityCapabilitySchema: z.ZodObject<{
|
|
5
|
+
identity: z.ZodLiteral<true>;
|
|
6
|
+
}, z.core.$strict>;
|
|
7
|
+
export declare function readFunctionInvocationIdentityCapability(manifest: unknown): boolean;
|
|
8
|
+
export declare const functionInvocationContextRequestSchema: z.ZodObject<{
|
|
9
|
+
operation: z.ZodLiteral<"getInvocationContext">;
|
|
10
|
+
}, z.core.$strict>;
|
|
11
|
+
export type FunctionInvocationContextRequest = z.infer<typeof functionInvocationContextRequestSchema>;
|
|
12
|
+
export declare const functionInvocationContextSchema: z.ZodObject<{
|
|
13
|
+
receiver: z.ZodObject<{
|
|
14
|
+
functionId: z.ZodString;
|
|
15
|
+
versionId: z.ZodString;
|
|
16
|
+
invocationId: z.ZodString;
|
|
17
|
+
orgId: z.ZodString;
|
|
18
|
+
serviceAccountId: z.ZodString;
|
|
19
|
+
serviceAccountSub: z.ZodString;
|
|
20
|
+
}, z.core.$strict>;
|
|
21
|
+
caller: z.ZodObject<{
|
|
22
|
+
kind: z.ZodEnum<{
|
|
23
|
+
human: "human";
|
|
24
|
+
service_account: "service_account";
|
|
25
|
+
system: "system";
|
|
26
|
+
}>;
|
|
27
|
+
sub: z.ZodString;
|
|
28
|
+
}, z.core.$strict>;
|
|
29
|
+
}, z.core.$strict>;
|
|
30
|
+
export type FunctionInvocationContext = z.infer<typeof functionInvocationContextSchema>;
|
|
31
|
+
export declare class FunctionInvocationContextError extends Error {
|
|
32
|
+
readonly status: number;
|
|
33
|
+
readonly code: string;
|
|
34
|
+
readonly name = "FunctionInvocationContextError";
|
|
35
|
+
constructor(status: number, code: string, message: string);
|
|
36
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FunctionInvocationContextError = exports.functionInvocationContextSchema = exports.functionInvocationContextRequestSchema = exports.functionInvocationIdentityCapabilitySchema = exports.FUNCTION_INVOCATION_CONTEXT_PATH = exports.FUNCTION_INVOCATION_IDENTITY_TOKEN_HEADER = void 0;
|
|
4
|
+
exports.readFunctionInvocationIdentityCapability = readFunctionInvocationIdentityCapability;
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
exports.FUNCTION_INVOCATION_IDENTITY_TOKEN_HEADER = 'x-sequence-invocation-identity-token';
|
|
7
|
+
exports.FUNCTION_INVOCATION_CONTEXT_PATH = '/api/managed-functions/invocation/context';
|
|
8
|
+
const identifier = zod_1.z.string().min(1).max(255);
|
|
9
|
+
const principal = zod_1.z.string().min(1).max(512);
|
|
10
|
+
exports.functionInvocationIdentityCapabilitySchema = zod_1.z.strictObject({
|
|
11
|
+
identity: zod_1.z.literal(true),
|
|
12
|
+
});
|
|
13
|
+
function readFunctionInvocationIdentityCapability(manifest) {
|
|
14
|
+
if (typeof manifest !== 'object' || manifest === null)
|
|
15
|
+
return false;
|
|
16
|
+
const capabilities = Reflect.get(manifest, 'capabilities');
|
|
17
|
+
if (typeof capabilities !== 'object' || capabilities === null)
|
|
18
|
+
return false;
|
|
19
|
+
return exports.functionInvocationIdentityCapabilitySchema.safeParse(Reflect.get(capabilities, 'invocation')).success;
|
|
20
|
+
}
|
|
21
|
+
exports.functionInvocationContextRequestSchema = zod_1.z.strictObject({
|
|
22
|
+
operation: zod_1.z.literal('getInvocationContext'),
|
|
23
|
+
});
|
|
24
|
+
exports.functionInvocationContextSchema = zod_1.z.strictObject({
|
|
25
|
+
receiver: zod_1.z.strictObject({
|
|
26
|
+
functionId: identifier,
|
|
27
|
+
versionId: identifier,
|
|
28
|
+
invocationId: identifier,
|
|
29
|
+
orgId: identifier,
|
|
30
|
+
serviceAccountId: identifier,
|
|
31
|
+
serviceAccountSub: principal,
|
|
32
|
+
}).refine((value) => value.serviceAccountSub === `service-account|${value.serviceAccountId}`, 'The receiver subject must identify the attached service account'),
|
|
33
|
+
caller: zod_1.z.strictObject({
|
|
34
|
+
kind: zod_1.z.enum(['human', 'service_account', 'system']),
|
|
35
|
+
sub: principal,
|
|
36
|
+
}),
|
|
37
|
+
});
|
|
38
|
+
class FunctionInvocationContextError extends Error {
|
|
39
|
+
status;
|
|
40
|
+
code;
|
|
41
|
+
name = 'FunctionInvocationContextError';
|
|
42
|
+
constructor(status, code, message) {
|
|
43
|
+
super(message);
|
|
44
|
+
this.status = status;
|
|
45
|
+
this.code = code;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.FunctionInvocationContextError = FunctionInvocationContextError;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type FunctionInvocationContext } from './invocation-contract';
|
|
2
|
+
export * from './invocation-contract';
|
|
3
|
+
import type { FunctionInvocationClientOptions } from './invocation-client';
|
|
4
|
+
export type { FunctionInvocationClientOptions } from './invocation-client';
|
|
5
|
+
export interface FunctionInvocationClient {
|
|
6
|
+
getInvocationContext(): Promise<FunctionInvocationContext>;
|
|
7
|
+
}
|
|
8
|
+
export declare function createFunctionInvocationClient({ request, baseUrl, fetchImpl, }: FunctionInvocationClientOptions): FunctionInvocationClient;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.createFunctionInvocationClient = createFunctionInvocationClient;
|
|
18
|
+
const zod_1 = require("zod");
|
|
19
|
+
const invocation_contract_1 = require("./invocation-contract");
|
|
20
|
+
__exportStar(require("./invocation-contract"), exports);
|
|
21
|
+
const identifier = zod_1.z.string().min(1).max(255);
|
|
22
|
+
const principal = zod_1.z.string().min(1).max(512);
|
|
23
|
+
const tokenClaimsSchema = zod_1.z.strictObject({
|
|
24
|
+
audience: zod_1.z.literal('atlas-managed-function-invocation-identity'),
|
|
25
|
+
environment: zod_1.z.string().min(1).max(4096),
|
|
26
|
+
functionId: identifier,
|
|
27
|
+
versionId: identifier,
|
|
28
|
+
invocationId: identifier,
|
|
29
|
+
serviceAccountId: identifier,
|
|
30
|
+
org: identifier,
|
|
31
|
+
callerKind: zod_1.z.enum(['human', 'service_account', 'system']),
|
|
32
|
+
callerSub: principal,
|
|
33
|
+
callerAuthenticationMethod: identifier,
|
|
34
|
+
exp: zod_1.z.number().int().positive().max(Number.MAX_SAFE_INTEGER),
|
|
35
|
+
});
|
|
36
|
+
const errorSchema = zod_1.z.strictObject({
|
|
37
|
+
code: zod_1.z.string().min(1).max(128).regex(/^[a-z][a-z0-9_]*$/),
|
|
38
|
+
detail: zod_1.z.string().min(1).max(2000),
|
|
39
|
+
});
|
|
40
|
+
const invalidContext = () => new invocation_contract_1.FunctionInvocationContextError(401, 'invalid_context', 'This invocation has no valid identity credential');
|
|
41
|
+
function readCredential({ request }) {
|
|
42
|
+
const { headers } = request;
|
|
43
|
+
const matches = typeof headers.get === 'function'
|
|
44
|
+
? [headers.get(invocation_contract_1.FUNCTION_INVOCATION_IDENTITY_TOKEN_HEADER)]
|
|
45
|
+
: Object.entries(headers)
|
|
46
|
+
.filter(([name]) => name.toLowerCase() === invocation_contract_1.FUNCTION_INVOCATION_IDENTITY_TOKEN_HEADER)
|
|
47
|
+
.map(([, value]) => value);
|
|
48
|
+
const token = matches[0];
|
|
49
|
+
if (matches.length !== 1 || typeof token !== 'string' || token.length > 16_384)
|
|
50
|
+
throw invalidContext();
|
|
51
|
+
const envelope = /^([A-Za-z0-9_-]+)\.([A-Za-z0-9_-]{43})$/.exec(token);
|
|
52
|
+
if (!envelope?.[1])
|
|
53
|
+
throw invalidContext();
|
|
54
|
+
let value;
|
|
55
|
+
try {
|
|
56
|
+
const decoded = Buffer.from(envelope[1], 'base64url');
|
|
57
|
+
if (decoded.toString('base64url') !== envelope[1])
|
|
58
|
+
throw invalidContext();
|
|
59
|
+
value = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(decoded));
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
throw invalidContext();
|
|
63
|
+
}
|
|
64
|
+
const parsed = tokenClaimsSchema.safeParse(value);
|
|
65
|
+
if (!parsed.success)
|
|
66
|
+
throw invalidContext();
|
|
67
|
+
return { token, claims: parsed.data };
|
|
68
|
+
}
|
|
69
|
+
function trustedOrigin(baseUrl) {
|
|
70
|
+
const invalid = () => new invocation_contract_1.FunctionInvocationContextError(400, 'invalid_configuration', 'Configure a trusted HTTPS Atlas origin without credentials, path, query or fragment');
|
|
71
|
+
let url;
|
|
72
|
+
try {
|
|
73
|
+
url = new URL(baseUrl);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
throw invalid();
|
|
77
|
+
}
|
|
78
|
+
const loopback = url.protocol === 'http:' &&
|
|
79
|
+
['localhost', '127.0.0.1', '[::1]'].includes(url.hostname);
|
|
80
|
+
if ((!loopback && url.protocol !== 'https:') || url.username || url.password ||
|
|
81
|
+
url.pathname !== '/' || url.search || url.hash)
|
|
82
|
+
throw invalid();
|
|
83
|
+
return url.origin;
|
|
84
|
+
}
|
|
85
|
+
function requireFresh(claims) {
|
|
86
|
+
if (claims.exp <= Date.now() / 1000)
|
|
87
|
+
throw new invocation_contract_1.FunctionInvocationContextError(401, 'expired_context', 'The identity credential expired; start a new invocation');
|
|
88
|
+
}
|
|
89
|
+
function matchesInvocation({ context, claims, }) {
|
|
90
|
+
const { receiver, caller } = context;
|
|
91
|
+
return receiver.functionId === claims.functionId &&
|
|
92
|
+
receiver.versionId === claims.versionId &&
|
|
93
|
+
receiver.invocationId === claims.invocationId &&
|
|
94
|
+
receiver.orgId === claims.org &&
|
|
95
|
+
receiver.serviceAccountId === claims.serviceAccountId &&
|
|
96
|
+
caller.kind === claims.callerKind && caller.sub === claims.callerSub;
|
|
97
|
+
}
|
|
98
|
+
function createFunctionInvocationClient({ request, baseUrl, fetchImpl = globalThis.fetch, }) {
|
|
99
|
+
const url = `${trustedOrigin(baseUrl)}${invocation_contract_1.FUNCTION_INVOCATION_CONTEXT_PATH}`;
|
|
100
|
+
const { token, claims } = readCredential({ request });
|
|
101
|
+
return {
|
|
102
|
+
async getInvocationContext() {
|
|
103
|
+
requireFresh(claims);
|
|
104
|
+
let response;
|
|
105
|
+
try {
|
|
106
|
+
response = await fetchImpl(url, {
|
|
107
|
+
method: 'POST',
|
|
108
|
+
headers: {
|
|
109
|
+
'content-type': 'application/json',
|
|
110
|
+
[invocation_contract_1.FUNCTION_INVOCATION_IDENTITY_TOKEN_HEADER]: token,
|
|
111
|
+
},
|
|
112
|
+
body: JSON.stringify(invocation_contract_1.functionInvocationContextRequestSchema.parse({ operation: 'getInvocationContext' })),
|
|
113
|
+
redirect: 'error', signal: AbortSignal.timeout(30_000),
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
throw new invocation_contract_1.FunctionInvocationContextError(502, 'context_request_failed', 'The invocation context request failed');
|
|
118
|
+
}
|
|
119
|
+
if (response.redirected || (response.status >= 300 && response.status < 400))
|
|
120
|
+
throw new invocation_contract_1.FunctionInvocationContextError(502, 'redirect_refused', 'The invocation context request must not redirect');
|
|
121
|
+
const result = await response.json().catch(() => null);
|
|
122
|
+
if (!response.ok) {
|
|
123
|
+
const error = errorSchema.safeParse(result);
|
|
124
|
+
throw new invocation_contract_1.FunctionInvocationContextError(response.status, error.success ? error.data.code : 'context_read_failed', error.success && !error.data.detail.includes(token)
|
|
125
|
+
? error.data.detail : 'Invocation context read failed');
|
|
126
|
+
}
|
|
127
|
+
requireFresh(claims);
|
|
128
|
+
const parsed = invocation_contract_1.functionInvocationContextSchema.safeParse(result);
|
|
129
|
+
if (!parsed.success || !matchesInvocation({ context: parsed.data, claims }))
|
|
130
|
+
throw new invocation_contract_1.FunctionInvocationContextError(502, 'malformed_response', 'Atlas returned an invalid invocation context response');
|
|
131
|
+
return parsed.data;
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.functionLatticeContextCapabilitySchema = void 0;
|
|
4
|
+
exports.readFunctionLatticeContextCapability = readFunctionLatticeContextCapability;
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
exports.functionLatticeContextCapabilitySchema = zod_1.z.strictObject({
|
|
7
|
+
context: zod_1.z.literal(true),
|
|
8
|
+
});
|
|
9
|
+
function readFunctionLatticeContextCapability(manifest) {
|
|
10
|
+
if (typeof manifest !== 'object' || manifest === null)
|
|
11
|
+
return false;
|
|
12
|
+
const capabilities = Reflect.get(manifest, 'capabilities');
|
|
13
|
+
if (typeof capabilities !== 'object' || capabilities === null)
|
|
14
|
+
return false;
|
|
15
|
+
return exports.functionLatticeContextCapabilitySchema.safeParse(Reflect.get(capabilities, 'lattice')).success;
|
|
16
|
+
}
|