@ductape/sdk 0.1.110 → 0.1.113
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/features/feature-executor.d.ts +9 -0
- package/dist/features/feature-executor.js +224 -70
- package/dist/features/feature-executor.js.map +1 -1
- package/dist/features/features.service.d.ts +5 -0
- package/dist/features/features.service.js +49 -7
- package/dist/features/features.service.js.map +1 -1
- package/dist/features/index.d.ts +2 -1
- package/dist/features/index.js +3 -1
- package/dist/features/index.js.map +1 -1
- package/dist/features/types/features.types.d.ts +9 -0
- package/dist/features/types/features.types.js.map +1 -1
- package/dist/functions/functions.runtime.d.ts +25 -0
- package/dist/functions/functions.runtime.js +254 -0
- package/dist/functions/functions.runtime.js.map +1 -0
- package/dist/functions/http-handler.d.ts +17 -0
- package/dist/functions/http-handler.js +51 -0
- package/dist/functions/http-handler.js.map +1 -0
- package/dist/functions/index.d.ts +3 -0
- package/dist/functions/index.js +20 -0
- package/dist/functions/index.js.map +1 -0
- package/dist/functions/types.d.ts +94 -0
- package/dist/functions/types.js +15 -0
- package/dist/functions/types.js.map +1 -0
- package/dist/graph/graphs.service.d.ts +1 -1
- package/dist/graph/graphs.service.js +73 -43
- package/dist/graph/graphs.service.js.map +1 -1
- package/dist/graph/types/traversal.interface.d.ts +2 -0
- package/dist/index.d.ts +16 -1
- package/dist/index.js +23 -3
- package/dist/index.js.map +1 -1
- package/dist/processor/services/processor.service.d.ts +6 -0
- package/dist/processor/services/processor.service.js +8 -13
- package/dist/processor/services/processor.service.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/productsBuilder.types.d.ts +3 -0
- package/dist/types/productsBuilder.types.js +2 -0
- package/dist/types/productsBuilder.types.js.map +1 -1
- package/dist/vector/vector-database.service.d.ts +2 -0
- package/dist/vector/vector-database.service.js +21 -12
- package/dist/vector/vector-database.service.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.portableFunctions = exports.PortableFunctionsRegistry = exports.PortableFunctionError = void 0;
|
|
4
|
+
exports.referenceFromContract = referenceFromContract;
|
|
5
|
+
exports.signInvocation = signInvocation;
|
|
6
|
+
exports.verifyInvocationSignature = verifyInvocationSignature;
|
|
7
|
+
exports.validatePortableValue = validatePortableValue;
|
|
8
|
+
const crypto_1 = require("crypto");
|
|
9
|
+
const contracts = new Map();
|
|
10
|
+
const keyFor = (namespace, version) => `${namespace}@${version}`;
|
|
11
|
+
class PortableFunctionError extends Error {
|
|
12
|
+
constructor(code, message, retryable = false, details) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.retryable = retryable;
|
|
16
|
+
this.details = details;
|
|
17
|
+
this.name = 'PortableFunctionError';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.PortableFunctionError = PortableFunctionError;
|
|
21
|
+
class PortableFunctionsRegistry {
|
|
22
|
+
registerEventsInvoker(invoker) {
|
|
23
|
+
this.eventsInvoker = invoker;
|
|
24
|
+
}
|
|
25
|
+
register(contract) {
|
|
26
|
+
assertIdentifier(contract.namespace, 'namespace');
|
|
27
|
+
assertIdentifier(contract.version, 'version');
|
|
28
|
+
if (!contract.operations || Object.keys(contract.operations).length === 0) {
|
|
29
|
+
throw new PortableFunctionError('FUNCTION_CONTRACT_INVALID', `Function contract ${contract.namespace}@${contract.version} has no operations.`);
|
|
30
|
+
}
|
|
31
|
+
for (const [operation, definition] of Object.entries(contract.operations)) {
|
|
32
|
+
assertIdentifier(operation, 'operation');
|
|
33
|
+
if (!definition.input || !definition.output) {
|
|
34
|
+
throw new PortableFunctionError('FUNCTION_CONTRACT_INVALID', `${contract.namespace}.${operation}@${contract.version} requires input and output schemas.`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
contracts.set(keyFor(contract.namespace, contract.version), contract);
|
|
38
|
+
return this.use(contract);
|
|
39
|
+
}
|
|
40
|
+
use(contract) {
|
|
41
|
+
return new Proxy({}, {
|
|
42
|
+
get: (_target, property) => {
|
|
43
|
+
if (typeof property !== 'string' || !(property in contract.operations))
|
|
44
|
+
return undefined;
|
|
45
|
+
return async (input) => this.invoke(referenceFromContract(contract, property), input, {
|
|
46
|
+
product: 'local', env: 'local', feature_id: (0, crypto_1.randomUUID)(), feature_tag: 'direct-function-invocation',
|
|
47
|
+
step_tag: property, invocation_id: (0, crypto_1.randomUUID)(),
|
|
48
|
+
}, '');
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
get(namespace, version) {
|
|
53
|
+
return contracts.get(keyFor(namespace, version));
|
|
54
|
+
}
|
|
55
|
+
list() {
|
|
56
|
+
return [...contracts.values()].map(contract => ({
|
|
57
|
+
namespace: contract.namespace, version: contract.version, operations: Object.keys(contract.operations),
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
async invoke(reference, input, context, accessKey) {
|
|
61
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
62
|
+
validatePortableValue(reference.input_schema, input, 'input');
|
|
63
|
+
const local = (_a = this.get(reference.namespace, reference.version)) === null || _a === void 0 ? void 0 : _a.operations[reference.operation];
|
|
64
|
+
let output;
|
|
65
|
+
if (local === null || local === void 0 ? void 0 : local.handler) {
|
|
66
|
+
output = await withDeadline(Promise.resolve(local.handler(input, context)), reference.timeout_ms, reference);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
const http = reference.transports.find(transport => transport.type === 'http');
|
|
70
|
+
const events = reference.transports.find(transport => transport.type === 'events');
|
|
71
|
+
if ((!http || http.type !== 'http') && (events === null || events === void 0 ? void 0 : events.type) === 'events' && this.eventsInvoker) {
|
|
72
|
+
const response = await withDeadline(this.eventsInvoker(events, {
|
|
73
|
+
function: { namespace: reference.namespace, operation: reference.operation, version: reference.version },
|
|
74
|
+
input: input, context,
|
|
75
|
+
}), (_b = events.timeout_ms) !== null && _b !== void 0 ? _b : reference.timeout_ms, reference);
|
|
76
|
+
if (response.invocation_id !== context.invocation_id)
|
|
77
|
+
throw new PortableFunctionError('FUNCTION_CORRELATION_MISMATCH', 'Function Event response invocation_id does not match the request.');
|
|
78
|
+
if (response.error)
|
|
79
|
+
throw new PortableFunctionError(response.error.code, response.error.message, response.error.retryable, response.error.details);
|
|
80
|
+
output = response.output;
|
|
81
|
+
}
|
|
82
|
+
else if (!http || http.type !== 'http') {
|
|
83
|
+
throw new PortableFunctionError('FUNCTION_UNAVAILABLE', `No local handler, configured Events invoker, or HTTP transport is available for ${reference.namespace}.${reference.operation}@${reference.version}.`, true);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
if (!accessKey)
|
|
87
|
+
throw new PortableFunctionError('FUNCTION_AUTH_UNAVAILABLE', 'An access key is required for signed HTTP function invocation.');
|
|
88
|
+
const invocation = {
|
|
89
|
+
function: { namespace: reference.namespace, operation: reference.operation, version: reference.version },
|
|
90
|
+
input: input, context,
|
|
91
|
+
};
|
|
92
|
+
const body = JSON.stringify(invocation);
|
|
93
|
+
const timestamp = Date.now().toString();
|
|
94
|
+
const signature = signInvocation(accessKey, timestamp, body);
|
|
95
|
+
const controller = new AbortController();
|
|
96
|
+
const timeout = setTimeout(() => controller.abort(), (_d = (_c = http.timeout_ms) !== null && _c !== void 0 ? _c : reference.timeout_ms) !== null && _d !== void 0 ? _d : 15000);
|
|
97
|
+
try {
|
|
98
|
+
const response = await fetch(http.url, {
|
|
99
|
+
method: 'POST', body, signal: controller.signal,
|
|
100
|
+
headers: {
|
|
101
|
+
'content-type': 'application/json',
|
|
102
|
+
'x-ductape-invocation-id': context.invocation_id,
|
|
103
|
+
'x-ductape-timestamp': timestamp,
|
|
104
|
+
'x-ductape-signature': signature,
|
|
105
|
+
'x-ductape-function': `${reference.namespace}.${reference.operation}@${reference.version}`,
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
const responseBody = await response.json();
|
|
109
|
+
if (!response.ok || responseBody.error) {
|
|
110
|
+
throw new PortableFunctionError((_f = (_e = responseBody.error) === null || _e === void 0 ? void 0 : _e.code) !== null && _f !== void 0 ? _f : 'FUNCTION_HTTP_ERROR', (_h = (_g = responseBody.error) === null || _g === void 0 ? void 0 : _g.message) !== null && _h !== void 0 ? _h : `Function endpoint returned HTTP ${response.status}.`, (_k = (_j = responseBody.error) === null || _j === void 0 ? void 0 : _j.retryable) !== null && _k !== void 0 ? _k : response.status >= 500, (_l = responseBody.error) === null || _l === void 0 ? void 0 : _l.details);
|
|
111
|
+
}
|
|
112
|
+
if (responseBody.invocation_id !== context.invocation_id) {
|
|
113
|
+
throw new PortableFunctionError('FUNCTION_CORRELATION_MISMATCH', 'Function response invocation_id does not match the request.');
|
|
114
|
+
}
|
|
115
|
+
output = responseBody.output;
|
|
116
|
+
}
|
|
117
|
+
finally {
|
|
118
|
+
clearTimeout(timeout);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
validatePortableValue(reference.output_schema, output, 'output');
|
|
123
|
+
return output;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.PortableFunctionsRegistry = PortableFunctionsRegistry;
|
|
127
|
+
exports.portableFunctions = new PortableFunctionsRegistry();
|
|
128
|
+
function referenceFromContract(contract, operation) {
|
|
129
|
+
var _a, _b, _c;
|
|
130
|
+
const definition = contract.operations[operation];
|
|
131
|
+
if (!definition)
|
|
132
|
+
throw new PortableFunctionError('FUNCTION_OPERATION_NOT_FOUND', `${contract.namespace}.${operation}@${contract.version} is not declared.`);
|
|
133
|
+
const declared = (_a = definition.transports) !== null && _a !== void 0 ? _a : [{ type: 'local' }];
|
|
134
|
+
const baseUrl = typeof process !== 'undefined' ? (_c = (_b = process.env) === null || _b === void 0 ? void 0 : _b.DUCTAPE_FUNCTION_BASE_URL) === null || _c === void 0 ? void 0 : _c.replace(/\/$/, '') : undefined;
|
|
135
|
+
const transports = [...declared];
|
|
136
|
+
if (baseUrl && !transports.some(transport => transport.type === 'http')) {
|
|
137
|
+
assertSecureFunctionUrl(baseUrl);
|
|
138
|
+
transports.push({
|
|
139
|
+
type: 'http',
|
|
140
|
+
url: `${baseUrl}/.well-known/ductape/functions/${encodeURIComponent(contract.namespace)}/${encodeURIComponent(contract.version)}/${encodeURIComponent(operation)}`,
|
|
141
|
+
timeout_ms: definition.timeout_ms,
|
|
142
|
+
authentication: 'ductape_hmac_sha256',
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
namespace: contract.namespace, operation, version: contract.version,
|
|
147
|
+
input_schema: definition.input, output_schema: definition.output,
|
|
148
|
+
transports,
|
|
149
|
+
timeout_ms: definition.timeout_ms, idempotent: definition.idempotent,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function assertSecureFunctionUrl(url) {
|
|
153
|
+
let parsed;
|
|
154
|
+
try {
|
|
155
|
+
parsed = new URL(url);
|
|
156
|
+
}
|
|
157
|
+
catch (_a) {
|
|
158
|
+
throw new PortableFunctionError('FUNCTION_CONTRACT_INVALID', `DUCTAPE_FUNCTION_BASE_URL is not a valid URL: ${JSON.stringify(url)}.`);
|
|
159
|
+
}
|
|
160
|
+
const local = parsed.hostname === 'localhost' || parsed.hostname === '127.0.0.1' || parsed.hostname === '::1';
|
|
161
|
+
if (parsed.protocol !== 'https:' && !(local && parsed.protocol === 'http:')) {
|
|
162
|
+
throw new PortableFunctionError('FUNCTION_INSECURE_TRANSPORT', 'Portable function HTTP endpoints must use HTTPS. HTTP is allowed only for localhost development.');
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function signInvocation(accessKey, timestamp, body) {
|
|
166
|
+
return (0, crypto_1.createHmac)('sha256', accessKey).update(`${timestamp}.${body}`).digest('hex');
|
|
167
|
+
}
|
|
168
|
+
function verifyInvocationSignature(accessKey, timestamp, body, signature, toleranceMs = 300000) {
|
|
169
|
+
const parsed = Number(timestamp);
|
|
170
|
+
if (!Number.isFinite(parsed) || Math.abs(Date.now() - parsed) > toleranceMs)
|
|
171
|
+
return false;
|
|
172
|
+
const expected = Buffer.from(signInvocation(accessKey, timestamp, body), 'hex');
|
|
173
|
+
const supplied = Buffer.from(signature, 'hex');
|
|
174
|
+
return expected.length === supplied.length && (0, crypto_1.timingSafeEqual)(expected, supplied);
|
|
175
|
+
}
|
|
176
|
+
function validatePortableValue(schema, value, path) {
|
|
177
|
+
var _a, _b, _c;
|
|
178
|
+
const fail = (message) => { throw new PortableFunctionError('FUNCTION_SCHEMA_VALIDATION_FAILED', `${path} ${message}`); };
|
|
179
|
+
if (schema.enum && !schema.enum.some(candidate => Object.is(candidate, value)))
|
|
180
|
+
fail(`must be one of ${JSON.stringify(schema.enum)}.`);
|
|
181
|
+
if (!schema.type)
|
|
182
|
+
return;
|
|
183
|
+
if (schema.type === 'null') {
|
|
184
|
+
if (value !== null)
|
|
185
|
+
fail('must be null.');
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (schema.type === 'array') {
|
|
189
|
+
if (!Array.isArray(value))
|
|
190
|
+
fail('must be an array.');
|
|
191
|
+
const arrayValue = value;
|
|
192
|
+
if (schema.items)
|
|
193
|
+
arrayValue.forEach((item, index) => validatePortableValue(schema.items, item, `${path}[${index}]`));
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
if (schema.type === 'object') {
|
|
197
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
198
|
+
fail('must be an object.');
|
|
199
|
+
const record = value;
|
|
200
|
+
for (const required of (_a = schema.required) !== null && _a !== void 0 ? _a : [])
|
|
201
|
+
if (!(required in record))
|
|
202
|
+
fail(`is missing required property "${required}".`);
|
|
203
|
+
for (const [key, nested] of Object.entries((_b = schema.properties) !== null && _b !== void 0 ? _b : {}))
|
|
204
|
+
if (key in record)
|
|
205
|
+
validatePortableValue(nested, record[key], `${path}.${key}`);
|
|
206
|
+
if (schema.additionalProperties === false) {
|
|
207
|
+
const known = new Set(Object.keys((_c = schema.properties) !== null && _c !== void 0 ? _c : {}));
|
|
208
|
+
for (const key of Object.keys(record))
|
|
209
|
+
if (!known.has(key))
|
|
210
|
+
fail(`contains unknown property "${key}".`);
|
|
211
|
+
}
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
const actual = typeof value;
|
|
215
|
+
if (schema.type === 'integer') {
|
|
216
|
+
if (actual !== 'number' || !Number.isInteger(value))
|
|
217
|
+
fail('must be an integer.');
|
|
218
|
+
}
|
|
219
|
+
else if (actual !== schema.type)
|
|
220
|
+
fail(`must be a ${schema.type}.`);
|
|
221
|
+
if (typeof value === 'string') {
|
|
222
|
+
if (schema.minLength != null && value.length < schema.minLength)
|
|
223
|
+
fail(`must contain at least ${schema.minLength} characters.`);
|
|
224
|
+
if (schema.maxLength != null && value.length > schema.maxLength)
|
|
225
|
+
fail(`must contain at most ${schema.maxLength} characters.`);
|
|
226
|
+
}
|
|
227
|
+
if (typeof value === 'number') {
|
|
228
|
+
if (schema.minimum != null && value < schema.minimum)
|
|
229
|
+
fail(`must be >= ${schema.minimum}.`);
|
|
230
|
+
if (schema.maximum != null && value > schema.maximum)
|
|
231
|
+
fail(`must be <= ${schema.maximum}.`);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
function assertIdentifier(value, label) {
|
|
235
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(value)) {
|
|
236
|
+
throw new PortableFunctionError('FUNCTION_CONTRACT_INVALID', `Invalid function ${label}: ${JSON.stringify(value)}.`);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
async function withDeadline(promise, timeoutMs, reference) {
|
|
240
|
+
if (!timeoutMs)
|
|
241
|
+
return promise;
|
|
242
|
+
let timer;
|
|
243
|
+
try {
|
|
244
|
+
return await Promise.race([
|
|
245
|
+
promise,
|
|
246
|
+
new Promise((_, reject) => { timer = setTimeout(() => reject(new PortableFunctionError('FUNCTION_TIMEOUT', `${reference.namespace}.${reference.operation}@${reference.version} exceeded ${timeoutMs}ms.`, true)), timeoutMs); }),
|
|
247
|
+
]);
|
|
248
|
+
}
|
|
249
|
+
finally {
|
|
250
|
+
if (timer)
|
|
251
|
+
clearTimeout(timer);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
//# sourceMappingURL=functions.runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"functions.runtime.js","sourceRoot":"","sources":["../../src/functions/functions.runtime.ts"],"names":[],"mappings":";;;AA+IA,sDAqBC;AAYD,wCAEC;AAED,8DAMC;AAED,sDAiCC;AA7ND,mCAAiE;AAajE,MAAM,SAAS,GAAG,IAAI,GAAG,EAAqC,CAAC;AAE/D,MAAM,MAAM,GAAG,CAAC,SAAiB,EAAE,OAAe,EAAE,EAAE,CAAC,GAAG,SAAS,IAAI,OAAO,EAAE,CAAC;AAEjF,MAAa,qBAAsB,SAAQ,KAAK;IAC9C,YAA4B,IAAY,EAAE,OAAe,EAAkB,YAAY,KAAK,EAAkB,OAAiB;QAC7H,KAAK,CAAC,OAAO,CAAC,CAAC;QADW,SAAI,GAAJ,IAAI,CAAQ;QAAmC,cAAS,GAAT,SAAS,CAAQ;QAAkB,YAAO,GAAP,OAAO,CAAU;QAE7H,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AALD,sDAKC;AAED,MAAa,yBAAyB;IAGpC,qBAAqB,CAAC,OAAsC;QAC1D,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC;IAC/B,CAAC;IACD,QAAQ,CAAsC,QAAW;QACvD,gBAAgB,CAAC,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QAClD,gBAAgB,CAAC,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAC9C,IAAI,CAAC,QAAQ,CAAC,UAAU,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,MA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OAAO,OAAO,CAAC;IAC/B,IAAI,KAAiC,CAAC;IACtC,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC;YACxB,OAAO;YACP,IAAI,OAAO,CAAI,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,qBAAqB,CAAC,kBAAkB,EAAE,GAAG,SAAS,CAAC,SAAS,IAAI,SAAS,CAAC,SAAS,IAAI,SAAS,CAAC,OAAO,aAAa,SAAS,KAAK,EAAE,IAAI,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;SACpO,CAAC,CAAC;IACL,CAAC;YAAS,CAAC;QACT,IAAI,KAAK;YAAE,YAAY,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IPortableFunctionInvocationResponse } from './types';
|
|
2
|
+
export interface IPortableFunctionHttpRequest {
|
|
3
|
+
headers: Record<string, string | string[] | undefined>;
|
|
4
|
+
body: string | Buffer | Record<string, unknown>;
|
|
5
|
+
params?: {
|
|
6
|
+
namespace?: string;
|
|
7
|
+
version?: string;
|
|
8
|
+
operation?: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export interface IPortableFunctionHttpResult {
|
|
12
|
+
status: number;
|
|
13
|
+
body: IPortableFunctionInvocationResponse;
|
|
14
|
+
}
|
|
15
|
+
export declare const PORTABLE_FUNCTION_HTTP_PATH = "/.well-known/ductape/functions/:namespace/:version/:operation";
|
|
16
|
+
/** Framework-neutral signed HTTP handler. Nest/Express adapters can pass raw request headers/body here. */
|
|
17
|
+
export declare function handlePortableFunctionHttpRequest(request: IPortableFunctionHttpRequest, accessKey: string): Promise<IPortableFunctionHttpResult>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PORTABLE_FUNCTION_HTTP_PATH = void 0;
|
|
4
|
+
exports.handlePortableFunctionHttpRequest = handlePortableFunctionHttpRequest;
|
|
5
|
+
const functions_runtime_1 = require("./functions.runtime");
|
|
6
|
+
exports.PORTABLE_FUNCTION_HTTP_PATH = '/.well-known/ductape/functions/:namespace/:version/:operation';
|
|
7
|
+
/** Framework-neutral signed HTTP handler. Nest/Express adapters can pass raw request headers/body here. */
|
|
8
|
+
async function handlePortableFunctionHttpRequest(request, accessKey) {
|
|
9
|
+
var _a, _b, _c;
|
|
10
|
+
const rawBody = typeof request.body === 'string' || Buffer.isBuffer(request.body)
|
|
11
|
+
? request.body.toString()
|
|
12
|
+
: JSON.stringify(request.body);
|
|
13
|
+
const timestamp = firstHeader(request.headers['x-ductape-timestamp']);
|
|
14
|
+
const signature = firstHeader(request.headers['x-ductape-signature']);
|
|
15
|
+
if (!timestamp || !signature || !(0, functions_runtime_1.verifyInvocationSignature)(accessKey, timestamp, rawBody, signature)) {
|
|
16
|
+
return { status: 401, body: { invocation_id: (_a = firstHeader(request.headers['x-ductape-invocation-id'])) !== null && _a !== void 0 ? _a : '', error: { code: 'FUNCTION_SIGNATURE_INVALID', message: 'Function invocation signature is invalid or expired.' } } };
|
|
17
|
+
}
|
|
18
|
+
let invocation;
|
|
19
|
+
try {
|
|
20
|
+
invocation = JSON.parse(rawBody);
|
|
21
|
+
}
|
|
22
|
+
catch (_d) {
|
|
23
|
+
return { status: 400, body: { invocation_id: '', error: { code: 'FUNCTION_REQUEST_INVALID', message: 'Function request body is not valid JSON.' } } };
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const route = request.params;
|
|
27
|
+
if (route && (route.namespace !== invocation.function.namespace || route.version !== invocation.function.version || route.operation !== invocation.function.operation)) {
|
|
28
|
+
throw new functions_runtime_1.PortableFunctionError('FUNCTION_ROUTE_MISMATCH', 'Function route parameters do not match the signed invocation body.');
|
|
29
|
+
}
|
|
30
|
+
const declaredHeader = firstHeader(request.headers['x-ductape-function']);
|
|
31
|
+
const expectedHeader = `${invocation.function.namespace}.${invocation.function.operation}@${invocation.function.version}`;
|
|
32
|
+
if (declaredHeader !== expectedHeader)
|
|
33
|
+
throw new functions_runtime_1.PortableFunctionError('FUNCTION_ROUTE_MISMATCH', 'X-Ductape-Function does not match the signed invocation body.');
|
|
34
|
+
const contract = functions_runtime_1.portableFunctions.get(invocation.function.namespace, invocation.function.version);
|
|
35
|
+
const operation = contract === null || contract === void 0 ? void 0 : contract.operations[invocation.function.operation];
|
|
36
|
+
if (!contract || !(operation === null || operation === void 0 ? void 0 : operation.handler))
|
|
37
|
+
throw new functions_runtime_1.PortableFunctionError('FUNCTION_UNAVAILABLE', `No local handler is registered for ${invocation.function.namespace}.${invocation.function.operation}@${invocation.function.version}.`, true);
|
|
38
|
+
const output = await functions_runtime_1.portableFunctions.invoke({
|
|
39
|
+
namespace: contract.namespace, operation: invocation.function.operation, version: contract.version,
|
|
40
|
+
input_schema: operation.input, output_schema: operation.output, transports: [{ type: 'local' }],
|
|
41
|
+
timeout_ms: operation.timeout_ms, idempotent: operation.idempotent,
|
|
42
|
+
}, invocation.input, invocation.context, accessKey);
|
|
43
|
+
return { status: 200, body: { invocation_id: invocation.context.invocation_id, output } };
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
const normalized = error instanceof functions_runtime_1.PortableFunctionError ? error : new functions_runtime_1.PortableFunctionError('FUNCTION_EXECUTION_FAILED', error instanceof Error ? error.message : String(error));
|
|
47
|
+
return { status: normalized.code === 'FUNCTION_UNAVAILABLE' ? 503 : 422, body: { invocation_id: (_c = (_b = invocation.context) === null || _b === void 0 ? void 0 : _b.invocation_id) !== null && _c !== void 0 ? _c : '', error: { code: normalized.code, message: normalized.message, retryable: normalized.retryable, details: normalized.details } } };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const firstHeader = (value) => Array.isArray(value) ? value[0] : value;
|
|
51
|
+
//#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E,aAAa,mCAAI,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,CAAC,OAAO,EAAE,SAAS,EAAE,UAAU,CAAC,SAAS,EAAE,OAAO,EAAE,UAAU,CAAC,OAAO,EAAE,EAAE,EAAE,CAAC;IAC3Q,CAAC;AACH,CAAC;AAED,MAAM,WAAW,GAAG,CAAC,KAAoC,EAAsB,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
__exportStar(require("./functions.runtime"), exports);
|
|
19
|
+
__exportStar(require("./http-handler"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,sDAAoC;AACpC,iDAA+B"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
export type PortableJsonSchema = {
|
|
2
|
+
type?: 'object' | 'array' | 'string' | 'number' | 'integer' | 'boolean' | 'null';
|
|
3
|
+
properties?: Record<string, PortableJsonSchema>;
|
|
4
|
+
required?: string[];
|
|
5
|
+
items?: PortableJsonSchema;
|
|
6
|
+
enum?: unknown[];
|
|
7
|
+
additionalProperties?: boolean | PortableJsonSchema;
|
|
8
|
+
minLength?: number;
|
|
9
|
+
maxLength?: number;
|
|
10
|
+
minimum?: number;
|
|
11
|
+
maximum?: number;
|
|
12
|
+
};
|
|
13
|
+
export interface IPortableFunctionContext {
|
|
14
|
+
product: string;
|
|
15
|
+
env: string;
|
|
16
|
+
workspace_id?: string;
|
|
17
|
+
feature_id: string;
|
|
18
|
+
feature_tag: string;
|
|
19
|
+
step_tag: string;
|
|
20
|
+
invocation_id: string;
|
|
21
|
+
trace_id?: string;
|
|
22
|
+
/** Inherited feature session. Kept outside business input. */
|
|
23
|
+
session?: string;
|
|
24
|
+
deadline_at?: number;
|
|
25
|
+
idempotency_key?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface IPortableFunctionHttpTransport {
|
|
28
|
+
type: 'http';
|
|
29
|
+
url: string;
|
|
30
|
+
timeout_ms?: number;
|
|
31
|
+
/** HMAC-SHA256 using the SDK access key. Unsigned HTTP invocation is intentionally unsupported. */
|
|
32
|
+
authentication: 'ductape_hmac_sha256';
|
|
33
|
+
}
|
|
34
|
+
export interface IPortableFunctionLocalTransport {
|
|
35
|
+
type: 'local';
|
|
36
|
+
}
|
|
37
|
+
export interface IPortableFunctionEventsTransport {
|
|
38
|
+
type: 'events';
|
|
39
|
+
/** Full broker/topic event names. */
|
|
40
|
+
request_event: string;
|
|
41
|
+
response_event: string;
|
|
42
|
+
timeout_ms?: number;
|
|
43
|
+
}
|
|
44
|
+
export type PortableFunctionTransport = IPortableFunctionLocalTransport | IPortableFunctionHttpTransport | IPortableFunctionEventsTransport;
|
|
45
|
+
export type PortableFunctionEventsInvoker = (transport: IPortableFunctionEventsTransport, invocation: IPortableFunctionInvocation) => Promise<IPortableFunctionInvocationResponse>;
|
|
46
|
+
export interface IPortableFunctionOperationContract<TInput = Record<string, unknown>, TOutput = unknown> {
|
|
47
|
+
input: PortableJsonSchema;
|
|
48
|
+
output: PortableJsonSchema;
|
|
49
|
+
description?: string;
|
|
50
|
+
timeout_ms?: number;
|
|
51
|
+
idempotent?: boolean;
|
|
52
|
+
transports?: PortableFunctionTransport[];
|
|
53
|
+
handler?: (input: TInput, context: IPortableFunctionContext) => Promise<TOutput> | TOutput;
|
|
54
|
+
}
|
|
55
|
+
export interface IPortableFunctionContract<TOperations extends Record<string, IPortableFunctionOperationContract<any, any>> = Record<string, IPortableFunctionOperationContract<any, any>>> {
|
|
56
|
+
namespace: string;
|
|
57
|
+
version: string;
|
|
58
|
+
description?: string;
|
|
59
|
+
operations: TOperations;
|
|
60
|
+
}
|
|
61
|
+
export interface IPortableFunctionReference {
|
|
62
|
+
namespace: string;
|
|
63
|
+
operation: string;
|
|
64
|
+
version: string;
|
|
65
|
+
input_schema: PortableJsonSchema;
|
|
66
|
+
output_schema: PortableJsonSchema;
|
|
67
|
+
transports: PortableFunctionTransport[];
|
|
68
|
+
timeout_ms?: number;
|
|
69
|
+
idempotent?: boolean;
|
|
70
|
+
}
|
|
71
|
+
export interface IPortableFunctionInvocation<TInput = Record<string, unknown>> {
|
|
72
|
+
function: Pick<IPortableFunctionReference, 'namespace' | 'operation' | 'version'>;
|
|
73
|
+
input: TInput;
|
|
74
|
+
context: IPortableFunctionContext;
|
|
75
|
+
}
|
|
76
|
+
export interface IPortableFunctionInvocationResponse<TOutput = unknown> {
|
|
77
|
+
invocation_id: string;
|
|
78
|
+
output?: TOutput;
|
|
79
|
+
error?: {
|
|
80
|
+
code: string;
|
|
81
|
+
message: string;
|
|
82
|
+
retryable?: boolean;
|
|
83
|
+
details?: unknown;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
export type PortableFunctionClient<TContract extends IPortableFunctionContract> = {
|
|
87
|
+
[K in keyof TContract['operations']]: TContract['operations'][K] extends IPortableFunctionOperationContract<infer TInput, infer TOutput> ? (input: TInput) => Promise<TOutput> : never;
|
|
88
|
+
};
|
|
89
|
+
export declare function defineFunctions<T extends IPortableFunctionContract>(contract: T): T;
|
|
90
|
+
/**
|
|
91
|
+
* Preserves an operation's application input/output types even when the portable
|
|
92
|
+
* contract intentionally contains no local handler.
|
|
93
|
+
*/
|
|
94
|
+
export declare function defineFunction<TInput, TOutput>(operation: IPortableFunctionOperationContract<TInput, TOutput>): IPortableFunctionOperationContract<TInput, TOutput>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defineFunctions = defineFunctions;
|
|
4
|
+
exports.defineFunction = defineFunction;
|
|
5
|
+
function defineFunctions(contract) {
|
|
6
|
+
return contract;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Preserves an operation's application input/output types even when the portable
|
|
10
|
+
* contract intentionally contains no local handler.
|
|
11
|
+
*/
|
|
12
|
+
function defineFunction(operation) {
|
|
13
|
+
return operation;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/functions/types.ts"],"names":[],"mappings":";;AAqGA,0CAEC;AAMD,wCAIC;AAZD,SAAgB,eAAe,CAAsC,QAAW;IAC9E,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;GAGG;AACH,SAAgB,cAAc,CAC5B,SAA8D;IAE9D,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -377,7 +377,7 @@ export declare class GraphService {
|
|
|
377
377
|
* );
|
|
378
378
|
* ```
|
|
379
379
|
*/
|
|
380
|
-
query<T = any>(queryString: string, params?: Record<string, any>, transaction?: IGraphTransaction): Promise<IRawQueryResult<T>>;
|
|
380
|
+
query<T = any>(queryString: string, params?: Record<string, any>, transaction?: IGraphTransaction, session?: string): Promise<IRawQueryResult<T>>;
|
|
381
381
|
/**
|
|
382
382
|
* Create a node index
|
|
383
383
|
* As documented in overview.md
|