@uru-intelligence/app 2.1.6 → 2.2.4
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 +463 -14
- package/dist/background-jobs.d.ts +11 -0
- package/dist/background-jobs.js +571 -0
- package/dist/dampers.d.ts +24 -1
- package/dist/dampers.js +3 -0
- package/dist/dataset-boundary.js +38 -1
- package/dist/dataset-row.d.ts +9 -0
- package/dist/dataset-row.js +11 -0
- package/dist/datasets.d.ts +2 -1
- package/dist/datasets.js +82 -28
- package/dist/errors.js +5 -4
- package/dist/examples/customer-workflows/approved-external-write.d.ts +50 -0
- package/dist/examples/customer-workflows/approved-external-write.js +162 -0
- package/dist/examples/customer-workflows/file-processor.d.ts +46 -0
- package/dist/examples/customer-workflows/file-processor.js +53 -0
- package/dist/examples/customer-workflows/job-coordinator.d.ts +5 -0
- package/dist/examples/customer-workflows/job-coordinator.js +1 -0
- package/dist/examples/customer-workflows/review-only-draft.d.ts +38 -0
- package/dist/examples/customer-workflows/review-only-draft.js +48 -0
- package/dist/examples/customer-workflows/scheduled-collector.d.ts +46 -0
- package/dist/examples/customer-workflows/scheduled-collector.js +343 -0
- package/dist/files.js +4 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.js +20 -7
- package/dist/invocations.d.ts +11 -1
- package/dist/invocations.js +72 -4
- package/dist/job-run.d.ts +90 -0
- package/dist/job-run.js +229 -0
- package/dist/jobs.d.ts +3 -3
- package/dist/jobs.js +39 -11
- package/dist/runtime.d.ts +8 -4
- package/dist/runtime.js +27 -7
- package/dist/transport-deadline.d.ts +0 -1
- package/dist/transport-deadline.js +0 -27
- package/dist/transport-invocation.d.ts +23 -4
- package/dist/transport-invocation.js +114 -29
- package/dist/transport-retry.d.ts +68 -0
- package/dist/transport-retry.js +245 -0
- package/dist/transport.d.ts +5 -20
- package/dist/transport.js +54 -33
- package/dist/types.d.ts +203 -4
- package/dist/uploads.js +158 -19
- package/package.json +34 -9
package/dist/uploads.js
CHANGED
|
@@ -114,6 +114,8 @@ function grantFrom(value) {
|
|
|
114
114
|
for (const [name, headerValue] of Object.entries(headers)) {
|
|
115
115
|
requiredHeaders[name] = string(headerValue);
|
|
116
116
|
}
|
|
117
|
+
if (requiredHeaders['if-none-match'] !== '*')
|
|
118
|
+
invalid();
|
|
117
119
|
return {
|
|
118
120
|
uploadId,
|
|
119
121
|
uploadUrl,
|
|
@@ -148,6 +150,34 @@ function resultFrom(value) {
|
|
|
148
150
|
cleanupFailed: row['cleanupFailed'] === true,
|
|
149
151
|
};
|
|
150
152
|
}
|
|
153
|
+
function statusFrom(value) {
|
|
154
|
+
const row = object(value);
|
|
155
|
+
const state = string(row['state']);
|
|
156
|
+
const outcome = row['outcome'];
|
|
157
|
+
const sizeBytes = row['sizeBytes'];
|
|
158
|
+
if (!UUID.test(string(row['uploadId'])) ||
|
|
159
|
+
!['granted', 'verified', 'rejected', 'expired'].includes(state) ||
|
|
160
|
+
(outcome !== null && (typeof outcome !== 'string' || !OUTCOMES.includes(outcome))) ||
|
|
161
|
+
(sizeBytes !== null && (typeof sizeBytes !== 'number' || !Number.isSafeInteger(sizeBytes))) ||
|
|
162
|
+
typeof row['cleanupFailed'] !== 'boolean')
|
|
163
|
+
invalid();
|
|
164
|
+
return {
|
|
165
|
+
uploadId: string(row['uploadId']),
|
|
166
|
+
state: state,
|
|
167
|
+
outcome: outcome,
|
|
168
|
+
filename: string(row['filename']),
|
|
169
|
+
contentType: string(row['contentType']),
|
|
170
|
+
sizeBytes: sizeBytes,
|
|
171
|
+
expiresAt: string(row['expiresAt']),
|
|
172
|
+
cleanupFailed: row['cleanupFailed'],
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function requestKey(value) {
|
|
176
|
+
const key = value.trim();
|
|
177
|
+
if (key.trim().length < 1 || key.trim().length > 128)
|
|
178
|
+
invalid();
|
|
179
|
+
return key.trim();
|
|
180
|
+
}
|
|
151
181
|
/**
|
|
152
182
|
* Read the response body into a `Blob`, refusing anything above the platform's
|
|
153
183
|
* own per-file ceiling.
|
|
@@ -196,10 +226,48 @@ export function createUploadsContext(options) {
|
|
|
196
226
|
// costs nothing on a runtime whose `fetch` arrives later, and so the global
|
|
197
227
|
// is always called with the global as its receiver.
|
|
198
228
|
const doFetch = async (...args) => await resolveRuntimeFetch(options)(...args);
|
|
199
|
-
const
|
|
229
|
+
const generatedRequestKeys = new Map();
|
|
230
|
+
const generatedFileIds = new WeakMap();
|
|
231
|
+
const fileFingerprint = (file, contentType) => {
|
|
232
|
+
let fileId = generatedFileIds.get(file);
|
|
233
|
+
if (fileId === undefined) {
|
|
234
|
+
fileId = globalThis.crypto.randomUUID();
|
|
235
|
+
generatedFileIds.set(file, fileId);
|
|
236
|
+
}
|
|
237
|
+
return JSON.stringify([
|
|
238
|
+
fileId,
|
|
239
|
+
file.name,
|
|
240
|
+
contentType,
|
|
241
|
+
file.size,
|
|
242
|
+
typeof file.lastModified === 'number' ? file.lastModified : 0,
|
|
243
|
+
]);
|
|
244
|
+
};
|
|
245
|
+
const keyFor = (value, fingerprint) => {
|
|
246
|
+
if (value !== undefined)
|
|
247
|
+
return { key: requestKey(value), generated: false };
|
|
248
|
+
const existing = generatedRequestKeys.get(fingerprint);
|
|
249
|
+
if (existing !== undefined)
|
|
250
|
+
return { key: existing, generated: true };
|
|
251
|
+
const key = requestKey(globalThis.crypto.randomUUID());
|
|
252
|
+
if (generatedRequestKeys.size >= 128) {
|
|
253
|
+
const oldest = generatedRequestKeys.keys().next().value;
|
|
254
|
+
if (typeof oldest === 'string')
|
|
255
|
+
generatedRequestKeys.delete(oldest);
|
|
256
|
+
}
|
|
257
|
+
generatedRequestKeys.set(fingerprint, key);
|
|
258
|
+
return { key, generated: true };
|
|
259
|
+
};
|
|
260
|
+
const forgetGeneratedKey = (fingerprint, key) => {
|
|
261
|
+
if (generatedRequestKeys.get(fingerprint) === key) {
|
|
262
|
+
generatedRequestKeys.delete(fingerprint);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
const post = async (path, payload, signal, idempotencyKey) => {
|
|
200
266
|
const headers = new Headers(await resolveHeaders(options.headers));
|
|
201
267
|
if (payload !== undefined)
|
|
202
268
|
headers.set('content-type', 'application/json');
|
|
269
|
+
if (idempotencyKey !== undefined)
|
|
270
|
+
headers.set('Idempotency-Key', idempotencyKey);
|
|
203
271
|
const response = await doFetch(`${base}${path}`, {
|
|
204
272
|
method: 'POST',
|
|
205
273
|
headers,
|
|
@@ -217,7 +285,11 @@ export function createUploadsContext(options) {
|
|
|
217
285
|
}
|
|
218
286
|
return readJson(response);
|
|
219
287
|
};
|
|
220
|
-
const
|
|
288
|
+
const requestResponse = async (input, fingerprint = JSON.stringify([
|
|
289
|
+
input.filename,
|
|
290
|
+
input.contentType,
|
|
291
|
+
input.sizeBytes,
|
|
292
|
+
])) => {
|
|
221
293
|
if (typeof input.filename !== 'string' ||
|
|
222
294
|
input.filename.trim().length < 1 ||
|
|
223
295
|
input.filename.length > 255 ||
|
|
@@ -229,12 +301,29 @@ export function createUploadsContext(options) {
|
|
|
229
301
|
input.sizeBytes > URU_UPLOAD_MAX_BYTES) {
|
|
230
302
|
invalid();
|
|
231
303
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
304
|
+
const { key, generated } = keyFor(input.idempotencyKey, fingerprint);
|
|
305
|
+
return {
|
|
306
|
+
row: object(await post('', {
|
|
307
|
+
filename: input.filename,
|
|
308
|
+
contentType: input.contentType,
|
|
309
|
+
sizeBytes: input.sizeBytes,
|
|
310
|
+
}, input.signal, key)),
|
|
311
|
+
key,
|
|
312
|
+
generated,
|
|
313
|
+
fingerprint,
|
|
314
|
+
};
|
|
315
|
+
};
|
|
316
|
+
const request = async (input) => {
|
|
317
|
+
const response = await requestResponse(input);
|
|
318
|
+
if (response.row['state'] !== undefined && response.row['state'] !== 'granted') {
|
|
319
|
+
throw new UruAppRuntimeError('This upload request is finished. Read its saved status with the same request key.', { status: 409, body: null });
|
|
320
|
+
}
|
|
321
|
+
const grant = grantFrom(response.row);
|
|
322
|
+
if (response.generated)
|
|
323
|
+
forgetGeneratedKey(response.fingerprint, response.key);
|
|
324
|
+
return grant;
|
|
237
325
|
};
|
|
326
|
+
const status = async (idempotencyKey, options) => statusFrom(await post('/status', undefined, options?.signal, requestKey(idempotencyKey)));
|
|
238
327
|
const complete = async (uploadId, settings) => {
|
|
239
328
|
if (typeof uploadId !== 'string' || !UUID.test(uploadId))
|
|
240
329
|
invalid();
|
|
@@ -264,6 +353,7 @@ export function createUploadsContext(options) {
|
|
|
264
353
|
};
|
|
265
354
|
return {
|
|
266
355
|
request,
|
|
356
|
+
status,
|
|
267
357
|
complete,
|
|
268
358
|
read,
|
|
269
359
|
upload: async (file, settings) => {
|
|
@@ -275,30 +365,79 @@ export function createUploadsContext(options) {
|
|
|
275
365
|
const contentType = typeof file.type === 'string' && file.type.trim() !== ''
|
|
276
366
|
? file.type
|
|
277
367
|
: 'application/octet-stream';
|
|
278
|
-
const
|
|
368
|
+
const response = await requestResponse({
|
|
279
369
|
filename: file.name,
|
|
280
370
|
contentType,
|
|
281
371
|
sizeBytes: file.size,
|
|
372
|
+
...(settings?.idempotencyKey === undefined
|
|
373
|
+
? {}
|
|
374
|
+
: { idempotencyKey: settings.idempotencyKey }),
|
|
282
375
|
...(settings?.signal === undefined ? {} : { signal: settings.signal }),
|
|
283
|
-
});
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
//
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
376
|
+
}, fileFingerprint(file, contentType));
|
|
377
|
+
const row = response.row;
|
|
378
|
+
if (row['state'] === 'verified' ||
|
|
379
|
+
row['state'] === 'rejected' ||
|
|
380
|
+
row['state'] === 'expired') {
|
|
381
|
+
// A prior call may have finished after its response was lost. The
|
|
382
|
+
// completion read is idempotent and returns the stored verdict.
|
|
383
|
+
const result = await complete(string(row['uploadId']), settings);
|
|
384
|
+
if (response.generated)
|
|
385
|
+
forgetGeneratedKey(response.fingerprint, response.key);
|
|
386
|
+
return result;
|
|
387
|
+
}
|
|
388
|
+
const grant = grantFrom(row);
|
|
389
|
+
const completeIfStored = async () => {
|
|
390
|
+
if (settings?.signal?.aborted === true)
|
|
391
|
+
return null;
|
|
392
|
+
try {
|
|
393
|
+
const recovered = await complete(grant.uploadId, settings);
|
|
394
|
+
return recovered.state === 'granted' && recovered.outcome === 'pending'
|
|
395
|
+
? null
|
|
396
|
+
: recovered;
|
|
397
|
+
}
|
|
398
|
+
catch {
|
|
399
|
+
return null;
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
let put;
|
|
403
|
+
try {
|
|
404
|
+
put = await doFetch(grant.uploadUrl, {
|
|
405
|
+
method: 'PUT',
|
|
406
|
+
// Exactly the headers the grant was SIGNED with. Adding or altering one
|
|
407
|
+
// changes the canonical request the provider rebuilds, and the PUT is
|
|
408
|
+
// refused with a signature error that names nothing.
|
|
409
|
+
headers: new Headers(grant.requiredHeaders),
|
|
410
|
+
body: file,
|
|
411
|
+
...(settings?.signal === undefined ? {} : { signal: settings.signal }),
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
catch (error) {
|
|
415
|
+
const recovered = await completeIfStored();
|
|
416
|
+
if (recovered !== null) {
|
|
417
|
+
if (response.generated)
|
|
418
|
+
forgetGeneratedKey(response.fingerprint, response.key);
|
|
419
|
+
return recovered;
|
|
420
|
+
}
|
|
421
|
+
throw error;
|
|
422
|
+
}
|
|
293
423
|
if (!put.ok) {
|
|
294
424
|
await put.body?.cancel();
|
|
425
|
+
const recovered = await completeIfStored();
|
|
426
|
+
if (recovered !== null) {
|
|
427
|
+
if (response.generated)
|
|
428
|
+
forgetGeneratedKey(response.fingerprint, response.key);
|
|
429
|
+
return recovered;
|
|
430
|
+
}
|
|
295
431
|
throw new UruAppRuntimeError('Upload was refused by object storage.', {
|
|
296
432
|
status: put.status,
|
|
297
433
|
body: null,
|
|
298
434
|
});
|
|
299
435
|
}
|
|
300
436
|
await put.body?.cancel();
|
|
301
|
-
|
|
437
|
+
const result = await complete(grant.uploadId, settings?.signal === undefined ? undefined : { signal: settings.signal });
|
|
438
|
+
if (response.generated)
|
|
439
|
+
forgetGeneratedKey(response.fingerprint, response.key);
|
|
440
|
+
return result;
|
|
302
441
|
},
|
|
303
442
|
};
|
|
304
443
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uru-intelligence/app",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Runtime client for Uru Gems: capability calls, Datasets, jobs and secrets",
|
|
6
6
|
"keywords": [
|
|
@@ -28,11 +28,34 @@
|
|
|
28
28
|
"sideEffects": false,
|
|
29
29
|
"main": "./dist/index.js",
|
|
30
30
|
"types": "./dist/index.d.ts",
|
|
31
|
+
"typesVersions": {
|
|
32
|
+
"*": {
|
|
33
|
+
"examples/customer-workflows/*": [
|
|
34
|
+
"dist/examples/customer-workflows/*"
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
},
|
|
31
38
|
"exports": {
|
|
32
39
|
".": {
|
|
33
40
|
"types": "./dist/index.d.ts",
|
|
34
41
|
"default": "./dist/index.js"
|
|
35
42
|
},
|
|
43
|
+
"./examples/customer-workflows/scheduled-collector": {
|
|
44
|
+
"types": "./dist/examples/customer-workflows/scheduled-collector.d.ts",
|
|
45
|
+
"default": "./dist/examples/customer-workflows/scheduled-collector.js"
|
|
46
|
+
},
|
|
47
|
+
"./examples/customer-workflows/review-only-draft": {
|
|
48
|
+
"types": "./dist/examples/customer-workflows/review-only-draft.d.ts",
|
|
49
|
+
"default": "./dist/examples/customer-workflows/review-only-draft.js"
|
|
50
|
+
},
|
|
51
|
+
"./examples/customer-workflows/file-processor": {
|
|
52
|
+
"types": "./dist/examples/customer-workflows/file-processor.d.ts",
|
|
53
|
+
"default": "./dist/examples/customer-workflows/file-processor.js"
|
|
54
|
+
},
|
|
55
|
+
"./examples/customer-workflows/approved-external-write": {
|
|
56
|
+
"types": "./dist/examples/customer-workflows/approved-external-write.d.ts",
|
|
57
|
+
"default": "./dist/examples/customer-workflows/approved-external-write.js"
|
|
58
|
+
},
|
|
36
59
|
"./package.json": "./package.json"
|
|
37
60
|
},
|
|
38
61
|
"publishConfig": {
|
|
@@ -40,25 +63,27 @@
|
|
|
40
63
|
"provenance": false
|
|
41
64
|
},
|
|
42
65
|
"scripts": {
|
|
43
|
-
"build": "tsc -p tsconfig.build.json",
|
|
66
|
+
"build": "tsc -p tsconfig.build.json && tsc -p tsconfig.examples.build.json",
|
|
44
67
|
"clean": "rm -rf dist",
|
|
45
68
|
"prepack": "bun run clean && bun run build",
|
|
46
|
-
"type-check": "tsc --noEmit",
|
|
47
|
-
"lint": "node ../../scripts/run-with-repo-node.mjs oxlint --type-aware --deny-warnings -c ../../oxlint.config.mts .",
|
|
69
|
+
"type-check": "tsc --noEmit && tsc -p tsconfig.examples.json --noEmit",
|
|
70
|
+
"lint": "node ../../scripts/run-with-repo-node.mjs oxlint --type-aware --deny-warnings -c ../../oxlint.config.mts . && node ../../scripts/checks/check-bun-test-integrity.mjs",
|
|
48
71
|
"lint:fix": "node ../../scripts/run-with-repo-node.mjs oxlint --type-aware --deny-warnings -c ../../oxlint.config.mts --fix .",
|
|
49
|
-
"test": "bun test",
|
|
50
|
-
"test:unit": "bun test",
|
|
72
|
+
"test": "bun run test:safety",
|
|
73
|
+
"test:unit": "bun run test:safety",
|
|
74
|
+
"test:safety": "node ../../scripts/ci/run-named-test-files.mjs bun test --files-from test-lists/test-safety.txt",
|
|
51
75
|
"check:package": "node ../../scripts/checks/check-app-package-publishable.mjs",
|
|
52
|
-
"check:node-floor": "node ../../scripts/checks/check-app-package-node-floor.mjs"
|
|
76
|
+
"check:node-floor": "node ../../scripts/checks/check-app-package-node-floor.mjs",
|
|
77
|
+
"test:focused": "node ../../scripts/ci/run-named-test-files.mjs bun test --files"
|
|
53
78
|
},
|
|
54
79
|
"devDependencies": {
|
|
55
80
|
"@types/node": "24.13.3",
|
|
56
|
-
"bun-types": "1.3.
|
|
81
|
+
"bun-types": "1.3.14",
|
|
57
82
|
"publint": "0.3.24",
|
|
58
83
|
"typescript": "7.0.2"
|
|
59
84
|
},
|
|
60
85
|
"engines": {
|
|
61
86
|
"node": ">=22.12.0"
|
|
62
87
|
},
|
|
63
|
-
"packageManager": "bun@1.3.
|
|
88
|
+
"packageManager": "bun@1.3.14"
|
|
64
89
|
}
|