@sequenceholdings/managed-functions 0.4.0 → 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 +444 -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 +165 -0
- package/dist/capabilities.js +61 -1
- package/dist/config.d.ts +18 -2
- package/dist/config.js +62 -1
- package/dist/deployed-policy.js +102 -0
- package/dist/directory-config.d.ts +23 -0
- package/dist/directory-config.js +22 -0
- 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/directory.d.ts +15 -0
- package/dist/directory.js +65 -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 +40 -1
- package/dist/index.js +75 -1
- package/dist/invocation-client.d.ts +45 -0
- package/dist/invocation-client.js +90 -0
- 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-directory.d.ts +10 -0
- package/dist/preflight-directory.js +36 -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 +50 -2
- package/dist/processes-contract.d.ts +20 -0
- package/dist/processes-contract.js +8 -1
- package/dist/processes.d.ts +4 -8
- package/dist/processes.js +52 -83
- package/dist/runtime.cjs +3387 -259
- 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
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createFunctionServiceWorkflowsClient = createFunctionServiceWorkflowsClient;
|
|
4
|
+
exports.createFunctionWorkflowEvidenceClient = createFunctionWorkflowEvidenceClient;
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const agent_source_evidence_contract_1 = require("./agent-source-evidence-contract");
|
|
7
|
+
const workflow_source_contract_1 = require("./workflow-source-contract");
|
|
8
|
+
function header(request, name) {
|
|
9
|
+
const { headers } = request;
|
|
10
|
+
const values = typeof headers.get === 'function' ? [headers.get(name)] : Object.entries(headers).filter(([key]) => key.toLowerCase() === name).map(([, value]) => value);
|
|
11
|
+
return values.length === 1 && typeof values[0] === 'string' ? values[0] : null;
|
|
12
|
+
}
|
|
13
|
+
const receiverSchema = zod_1.z.object({ sub: zod_1.z.string(), functionId: zod_1.z.uuid(), versionId: zod_1.z.uuid(), invocationId: zod_1.z.uuid(), serviceAccountId: zod_1.z.uuid(), org: zod_1.z.string().min(1), exp: zod_1.z.number().int() });
|
|
14
|
+
function credential({ request, evidence }) {
|
|
15
|
+
const refused = () => new workflow_source_contract_1.FunctionWorkflowReadError(401, 'invalid_context', 'This invocation has no valid workflow-source credential');
|
|
16
|
+
const token = header(request, evidence ? workflow_source_contract_1.FUNCTION_WORKFLOW_EVIDENCE_TOKEN_HEADER : workflow_source_contract_1.FUNCTION_WORKFLOW_TOKEN_HEADER);
|
|
17
|
+
const body = token && token.length <= 16_384 ? /^([A-Za-z0-9_-]+)\.[A-Za-z0-9_-]{43}$/.exec(token)?.[1] : null;
|
|
18
|
+
if (!body || !token)
|
|
19
|
+
throw refused();
|
|
20
|
+
let value;
|
|
21
|
+
try {
|
|
22
|
+
value = JSON.parse(Buffer.from(body, 'base64url').toString('utf8'));
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
throw refused();
|
|
26
|
+
}
|
|
27
|
+
const binding = receiverSchema.extend({ audience: zod_1.z.literal(evidence ? 'atlas-managed-function-workflow-evidence' : 'atlas-managed-function-workflow-read') }).safeParse(value);
|
|
28
|
+
if (!binding.success || binding.data.sub !== `service-account|${binding.data.serviceAccountId}`)
|
|
29
|
+
throw refused();
|
|
30
|
+
return { token, binding: binding.data };
|
|
31
|
+
}
|
|
32
|
+
function origin(baseUrl) {
|
|
33
|
+
let url;
|
|
34
|
+
try {
|
|
35
|
+
url = new URL(baseUrl);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
throw new workflow_source_contract_1.FunctionWorkflowReadError(400, 'invalid_configuration', 'Configure a trusted Atlas origin');
|
|
39
|
+
}
|
|
40
|
+
const loopback = url.protocol === 'http:' && ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname);
|
|
41
|
+
if ((!loopback && url.protocol !== 'https:') || url.username || url.password || url.pathname !== '/' || url.search || url.hash)
|
|
42
|
+
throw new workflow_source_contract_1.FunctionWorkflowReadError(400, 'invalid_configuration', 'Configure an HTTPS Atlas origin without credentials, path, query or fragment');
|
|
43
|
+
return url.origin;
|
|
44
|
+
}
|
|
45
|
+
function sameReceiver(left, right) {
|
|
46
|
+
return left.functionId === right.functionId && left.versionId === right.versionId && left.invocationId === right.invocationId && left.serviceAccountId === right.serviceAccountId && left.org === right.org && left.sub === right.sub;
|
|
47
|
+
}
|
|
48
|
+
async function post({ options, path, body, credentials }) {
|
|
49
|
+
const serialized = JSON.stringify(body);
|
|
50
|
+
if (Buffer.byteLength(serialized, 'utf8') > agent_source_evidence_contract_1.AGENT_SOURCE_VERIFY_MAX_BYTES)
|
|
51
|
+
throw new workflow_source_contract_1.FunctionWorkflowReadError(413, 'workflow_source_too_large', 'Workflow source verification exceeds 768 KiB; capture a smaller output before writing');
|
|
52
|
+
const lattice = header(options.request, 'x-sequence-lattice-execution-token');
|
|
53
|
+
const response = await (options.fetchImpl ?? globalThis.fetch)(`${origin(options.baseUrl)}${path}`, { method: 'POST', headers: { 'content-type': 'application/json', ...credentials, ...(lattice ? { 'x-sequence-lattice-execution-token': lattice } : {}) }, body: serialized, redirect: 'error', signal: AbortSignal.timeout(30_000) });
|
|
54
|
+
const result = await response.json().catch(() => null);
|
|
55
|
+
if (!response.ok) {
|
|
56
|
+
const error = zod_1.z.object({ detail: zod_1.z.string().max(2000).optional(), code: zod_1.z.string().max(128).optional() }).safeParse(result);
|
|
57
|
+
throw new workflow_source_contract_1.FunctionWorkflowReadError(response.status, error.success ? (error.data.code ?? 'workflow_source_failed') : 'workflow_source_failed', error.success ? (error.data.detail ?? 'Workflow source request failed') : 'Workflow source request failed');
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
function assertLive(binding) {
|
|
62
|
+
if (binding.exp <= Date.now() / 1000)
|
|
63
|
+
throw new workflow_source_contract_1.FunctionWorkflowReadError(401, 'expired_context', 'The workflow-source credential expired; start a new invocation');
|
|
64
|
+
}
|
|
65
|
+
function createFunctionServiceWorkflowsClient(options) {
|
|
66
|
+
origin(options.baseUrl);
|
|
67
|
+
const read = credential({ request: options.request, evidence: false });
|
|
68
|
+
const evidence = credential({ request: options.request, evidence: true });
|
|
69
|
+
if (!sameReceiver(read.binding, evidence.binding))
|
|
70
|
+
throw new workflow_source_contract_1.FunctionWorkflowReadError(401, 'invalid_context', 'Workflow capture credentials name different invocations');
|
|
71
|
+
return { async captureCompletedRun(query) {
|
|
72
|
+
assertLive(read.binding);
|
|
73
|
+
assertLive(evidence.binding);
|
|
74
|
+
const parsed = workflow_source_contract_1.functionWorkflowSourceCaptureSchema.safeParse(await post({ options, path: workflow_source_contract_1.FUNCTION_WORKFLOW_CAPTURE_PATH, body: { ...workflow_source_contract_1.functionWorkflowCompletedRunQuerySchema.parse(query), operation: 'captureCompletedRun' }, credentials: { [workflow_source_contract_1.FUNCTION_WORKFLOW_TOKEN_HEADER]: read.token, [workflow_source_contract_1.FUNCTION_WORKFLOW_EVIDENCE_TOKEN_HEADER]: evidence.token } }));
|
|
75
|
+
if (!parsed.success || parsed.data.response.workflow !== query.workflow || parsed.data.response.runId !== query.runId)
|
|
76
|
+
throw new workflow_source_contract_1.FunctionWorkflowReadError(502, 'malformed_response', 'Atlas returned a different completed workflow source');
|
|
77
|
+
return parsed.data;
|
|
78
|
+
} };
|
|
79
|
+
}
|
|
80
|
+
function createFunctionWorkflowEvidenceClient(options) {
|
|
81
|
+
origin(options.baseUrl);
|
|
82
|
+
const evidence = credential({ request: options.request, evidence: true });
|
|
83
|
+
return { async verifySourceEvidence(input) {
|
|
84
|
+
assertLive(evidence.binding);
|
|
85
|
+
const parsed = workflow_source_contract_1.functionWorkflowSourceVerificationSchema.safeParse(await post({ options, path: workflow_source_contract_1.FUNCTION_WORKFLOW_EVIDENCE_PATH, body: workflow_source_contract_1.functionWorkflowSourceEvidenceRequestSchema.parse({ ...input, operation: 'verifySourceEvidence' }), credentials: { [workflow_source_contract_1.FUNCTION_WORKFLOW_EVIDENCE_TOKEN_HEADER]: evidence.token } }));
|
|
86
|
+
if (!parsed.success)
|
|
87
|
+
throw new workflow_source_contract_1.FunctionWorkflowReadError(502, 'malformed_response', 'Atlas returned invalid workflow source verification');
|
|
88
|
+
const { source, receiver } = parsed.data;
|
|
89
|
+
if (source.workflowId !== input.workflow || source.runId !== input.runId || source.responseHash !== input.responseHash || receiver.functionId !== evidence.binding.functionId || receiver.versionId !== evidence.binding.versionId || receiver.invocationId !== evidence.binding.invocationId || receiver.serviceAccountId !== evidence.binding.serviceAccountId || receiver.org !== evidence.binding.org)
|
|
90
|
+
throw new workflow_source_contract_1.FunctionWorkflowReadError(502, 'malformed_response', 'Atlas returned workflow evidence for another request or invocation');
|
|
91
|
+
return parsed.data;
|
|
92
|
+
} };
|
|
93
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sequenceholdings/managed-functions",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Managed Function context and opt-in cache runtime",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"vitest": "^4.1.11",
|
|
49
49
|
"esbuild": "^0.25.0",
|
|
50
50
|
"tsup": "^8.3.0",
|
|
51
|
-
"@sequenceholdings/orm": "2.6.
|
|
51
|
+
"@sequenceholdings/orm": "2.6.2"
|
|
52
52
|
},
|
|
53
53
|
"engines": {
|
|
54
54
|
"node": ">=20"
|