@oddington/sdk 0.1.25 → 0.1.27
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 +5 -3
- package/dist/browser.js +131 -110
- package/dist/index.js +4 -4
- package/dist/types/packages/sdk/src/routine-definition-types.d.ts +1 -0
- package/dist/types/shared/app-routine-contract.d.ts +1 -0
- package/dist/types/shared/files-contract.d.ts +1 -0
- package/dist/types/shared/inbox-contract.d.ts +4 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ import { defineRoutine, file, schema } from '@oddington/sdk';
|
|
|
40
40
|
|
|
41
41
|
export default defineRoutine({
|
|
42
42
|
id: 'invoice-import',
|
|
43
|
-
input: schema.object({ document: file() }),
|
|
43
|
+
input: schema.object({ document: file({ storage: 'local', path: 'Statements' }) }),
|
|
44
44
|
access: { files: 'read' },
|
|
45
45
|
steps: {
|
|
46
46
|
read: {
|
|
@@ -67,8 +67,10 @@ skipped. Omitted input normalizes to `{}`. A top-level schema can supply a valid
|
|
|
67
67
|
immutable default with `.default(value)`, such as
|
|
68
68
|
`schema.object({ files: schema.array(file(), { maxItems: 32 }) }).default({ files: [] })`.
|
|
69
69
|
Nested defaults are unsupported and rejected. Omitted steps permit no step call;
|
|
70
|
-
omitted result permits no returned value. `file()` declares a complete OS File descriptor
|
|
71
|
-
|
|
70
|
+
omitted result permits no returned value. `file()` declares a complete OS File descriptor.
|
|
71
|
+
Its optional `storage` selects local or remote placement and its optional `path`
|
|
72
|
+
selects a managed OS parent such as `Statements`; it is never a machine or provider
|
|
73
|
+
path. The trusted launcher separately verifies current File-use authority. The supplied
|
|
72
74
|
runtime contains `run.id`, `data`, `files`, `connections`, `inbox`, and `step`.
|
|
73
75
|
Accepted input and saved values are immutable snapshots. Access declarations set
|
|
74
76
|
maximum named capabilities and grant no authority; the trusted host checks current
|
package/dist/browser.js
CHANGED
|
@@ -1,3 +1,108 @@
|
|
|
1
|
+
var FileOperationError = class extends Error {
|
|
2
|
+
constructor(code, status, retryable = !1) {
|
|
3
|
+
super(code);
|
|
4
|
+
this.code = code;
|
|
5
|
+
this.status = status;
|
|
6
|
+
this.retryable = retryable;
|
|
7
|
+
}
|
|
8
|
+
code;
|
|
9
|
+
status;
|
|
10
|
+
retryable;
|
|
11
|
+
}, FILE_ID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/, FILE_ORIGINAL_MAX_BYTES = 5 * 1024 ** 3;
|
|
12
|
+
function parseFileDescriptor(value) {
|
|
13
|
+
let invalid8 = () => {
|
|
14
|
+
throw new FileOperationError("unavailable", 503, !0);
|
|
15
|
+
};
|
|
16
|
+
if (!value || typeof value != "object" || Array.isArray(value)) return invalid8();
|
|
17
|
+
let f = value;
|
|
18
|
+
if (Object.keys(f).sort().join(",") !== "details,enrichments,id,mediaType,name,path,sha256,size" || typeof f.id != "string" || !FILE_ID_PATTERN.test(f.id) || !safeFileName(f.name) || !safeFilePath(f.path) || !Number.isSafeInteger(f.size) || f.size < 0 || f.size > FILE_ORIGINAL_MAX_BYTES || typeof f.sha256 != "string" || !/^[0-9a-f]{64}$/.test(f.sha256) || !f.enrichments || typeof f.enrichments != "object" || Array.isArray(f.enrichments) || !f.details || typeof f.details != "object" || Array.isArray(f.details)) return invalid8();
|
|
19
|
+
let d = f.details;
|
|
20
|
+
if (d.kind === "other") {
|
|
21
|
+
if (Object.keys(d).length !== 1 || ![
|
|
22
|
+
"application/octet-stream",
|
|
23
|
+
"text/plain",
|
|
24
|
+
"text/markdown",
|
|
25
|
+
"application/json",
|
|
26
|
+
"image/png",
|
|
27
|
+
"image/jpeg"
|
|
28
|
+
].includes(f.mediaType)) return invalid8();
|
|
29
|
+
} else if (d.kind === "csv") {
|
|
30
|
+
if (Object.keys(d).sort().join(",") !== "dataRows,delimiter,encoding,headerRow,kind" || f.mediaType !== "text/csv" || !["utf-8", "windows-1252"].includes(d.encoding) || ![",", ";", " "].includes(d.delimiter) || !Number.isSafeInteger(d.headerRow) || d.headerRow < 1 || !Number.isSafeInteger(d.dataRows) || d.dataRows < 0) return invalid8();
|
|
31
|
+
} else if (d.kind === "pdf") {
|
|
32
|
+
if (f.mediaType !== "application/pdf" || Object.keys(d).some((key) => !["kind", "pages"].includes(key)) || "pages" in d && (!Number.isSafeInteger(d.pages) || d.pages < 1)) return invalid8();
|
|
33
|
+
} else return invalid8();
|
|
34
|
+
for (let [name, descriptor] of Object.entries(f.enrichments)) {
|
|
35
|
+
if (!safeEnrichmentName(name)) return invalid8();
|
|
36
|
+
parseEnrichmentDescriptor(descriptor);
|
|
37
|
+
}
|
|
38
|
+
return new TextEncoder().encode(JSON.stringify(f)).byteLength > 16 * 1024 ? invalid8() : f;
|
|
39
|
+
}
|
|
40
|
+
function parseEnrichmentDescriptor(value) {
|
|
41
|
+
let invalid8 = () => {
|
|
42
|
+
throw new FileOperationError("unavailable", 503, !0);
|
|
43
|
+
};
|
|
44
|
+
if (!value || typeof value != "object" || Array.isArray(value)) return invalid8();
|
|
45
|
+
let d = value;
|
|
46
|
+
return Object.keys(d).sort().join(",") !== "mediaType,sha256,size" || !["application/octet-stream", "text/plain", "text/markdown", "application/json"].includes(d.mediaType) || !Number.isSafeInteger(d.size) || d.size < 0 || d.size > 16 * 1024 * 1024 || typeof d.sha256 != "string" || !/^[0-9a-f]{64}$/.test(d.sha256) ? invalid8() : d;
|
|
47
|
+
}
|
|
48
|
+
function safeEnrichmentName(value) {
|
|
49
|
+
return safeFileName(value) && !/^original(?:\.|$)/i.test(value);
|
|
50
|
+
}
|
|
51
|
+
function parseFileEnrichMetadata(value, maxBytes) {
|
|
52
|
+
let invalid8 = () => {
|
|
53
|
+
throw new FileOperationError("invalid_input", 400);
|
|
54
|
+
};
|
|
55
|
+
if (!value || typeof value != "object" || Array.isArray(value)) return invalid8();
|
|
56
|
+
let d = value;
|
|
57
|
+
if (Object.keys(d).some((key) => !["name", "size", "mediaType", "replace"].includes(key)) || !safeEnrichmentName(d.name) || !Number.isSafeInteger(d.size) || d.size < 0 || d.mediaType !== void 0 && (typeof d.mediaType != "string" || d.mediaType.length > 255 || /[\u0000-\u001f\u007f]/.test(d.mediaType)) || d.replace !== void 0 && (typeof d.replace != "string" || !/^[0-9a-f]{64}$/.test(d.replace))) return invalid8();
|
|
58
|
+
if (d.size > maxBytes) throw new FileOperationError("request_too_large", 413);
|
|
59
|
+
return d;
|
|
60
|
+
}
|
|
61
|
+
function safeFileName(value) {
|
|
62
|
+
return typeof value == "string" && value.length > 0 && value.length <= 255 && value === value.trim() && value !== "." && value !== ".." && !/[\u0000-\u001f\u007f-\u009f/\\:*?"<>|]/u.test(value) && !/[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/.test(value) && !/[. ]$/.test(value) && !/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(value);
|
|
63
|
+
}
|
|
64
|
+
function safeFilePath(value) {
|
|
65
|
+
return typeof value == "string" && value.length <= 1024 && value.split("/").every(safeFileName);
|
|
66
|
+
}
|
|
67
|
+
function safeManagedFilePath(value) {
|
|
68
|
+
return safeFilePath(value) && value.split("/")[0].toLowerCase() !== ".os";
|
|
69
|
+
}
|
|
70
|
+
var ORIGINAL_MEDIA_TYPES = ["application/pdf", "text/plain", "text/markdown", "application/json", "image/png", "image/jpeg"];
|
|
71
|
+
function declaredOriginalMediaType(value) {
|
|
72
|
+
let normalized = value.split(";", 1)[0].trim().toLowerCase();
|
|
73
|
+
return ORIGINAL_MEDIA_TYPES.includes(normalized) ? normalized : void 0;
|
|
74
|
+
}
|
|
75
|
+
function parseFileCreateMetadata(value, maxBytes) {
|
|
76
|
+
let invalid8 = () => {
|
|
77
|
+
throw new FileOperationError("invalid_input", 400);
|
|
78
|
+
};
|
|
79
|
+
if (!value || typeof value != "object" || Array.isArray(value)) return invalid8();
|
|
80
|
+
let input = value;
|
|
81
|
+
if (Object.keys(input).some((key) => !["name", "path", "storage", "csv", "inputMediaType", "size", "requestKey"].includes(key))) return invalid8();
|
|
82
|
+
let path = input.path === void 0 ? "Files" : input.path;
|
|
83
|
+
if (!safeFileName(input.name) || !safeManagedFilePath(path) || input.storage !== void 0 && input.storage !== "remote" && input.storage !== "local" || input.inputMediaType !== void 0 && (typeof input.inputMediaType != "string" || !ORIGINAL_MEDIA_TYPES.includes(input.inputMediaType)) || !Number.isSafeInteger(input.size) || input.size < 0) return invalid8();
|
|
84
|
+
if (input.size > maxBytes) throw new FileOperationError("request_too_large", 413);
|
|
85
|
+
if (typeof input.requestKey != "string" || input.requestKey.length < 1 || input.requestKey.length > 256 || input.requestKey !== input.requestKey.trim() || /[\u0000-\u001f\u007f]/.test(input.requestKey)) return invalid8();
|
|
86
|
+
let csv;
|
|
87
|
+
if (input.csv !== void 0) {
|
|
88
|
+
if (!input.csv || typeof input.csv != "object" || Array.isArray(input.csv)) return invalid8();
|
|
89
|
+
let hints = input.csv;
|
|
90
|
+
if (Object.keys(hints).some((key) => !["encoding", "delimiter", "headerRow"].includes(key))) return invalid8();
|
|
91
|
+
let encoding = hints.encoding === void 0 ? "utf-8" : hints.encoding, delimiter = hints.delimiter === void 0 ? "," : hints.delimiter, headerRow = hints.headerRow === void 0 ? 1 : hints.headerRow;
|
|
92
|
+
if (encoding !== "utf-8" && encoding !== "windows-1252" || ![",", ";", " "].includes(delimiter) || !Number.isSafeInteger(headerRow) || headerRow < 1 || headerRow > 1e5) return invalid8();
|
|
93
|
+
csv = { encoding, delimiter, headerRow };
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
name: input.name,
|
|
97
|
+
path,
|
|
98
|
+
...input.storage ? { storage: input.storage } : {},
|
|
99
|
+
...input.inputMediaType === void 0 ? {} : { inputMediaType: input.inputMediaType },
|
|
100
|
+
...csv ? { csv } : {},
|
|
101
|
+
size: input.size,
|
|
102
|
+
requestKey: input.requestKey
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
1
106
|
var InboxContractError = class extends Error {
|
|
2
107
|
constructor(message2) {
|
|
3
108
|
super(message2), this.name = "InboxContractError";
|
|
@@ -65,7 +170,7 @@ function validateInboxFile(value) {
|
|
|
65
170
|
let fileId = id(v.id, "Inbox file ID"), name = id(v.name, "filename"), mediaType = id(v.mediaType, "media type");
|
|
66
171
|
(!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(fileId) || /[\x00-\x1f\x7f/\\]/.test(name) || !/^[a-z0-9!#$&^_.+-]+\/[a-z0-9!#$&^_.+-]+$/.test(mediaType) || typeof v.sha256 != "string" || !/^[0-9a-f]{64}$/.test(v.sha256)) && fail("Invalid Inbox file identity or metadata");
|
|
67
172
|
let size = natural(v.size, "file size");
|
|
68
|
-
size >
|
|
173
|
+
size > FILE_ORIGINAL_MAX_BYTES && fail("File exceeds supported size");
|
|
69
174
|
let d = object(v.details, "file details"), details;
|
|
70
175
|
switch (d.kind) {
|
|
71
176
|
case "csv":
|
|
@@ -144,7 +249,19 @@ function recordsBlock(value) {
|
|
|
144
249
|
return validateBlock({ ...value, kind: "records" });
|
|
145
250
|
}
|
|
146
251
|
function fileBlock(value) {
|
|
147
|
-
|
|
252
|
+
let input = object(serializable(value), "Files Block"), files3 = array(input.files, "files").map((entry) => {
|
|
253
|
+
let descriptor = object(entry, "File");
|
|
254
|
+
if (!("path" in descriptor || "enrichments" in descriptor)) return validateInboxFile(descriptor);
|
|
255
|
+
let file2;
|
|
256
|
+
try {
|
|
257
|
+
file2 = parseFileDescriptor(descriptor);
|
|
258
|
+
} catch {
|
|
259
|
+
return fail("Invalid shared File descriptor");
|
|
260
|
+
}
|
|
261
|
+
let { id: id3, name, mediaType, size, sha256, details } = file2;
|
|
262
|
+
return { id: id3, name, mediaType, size, sha256, details };
|
|
263
|
+
});
|
|
264
|
+
return validateBlock({ ...input, kind: "files", files: files3 });
|
|
148
265
|
}
|
|
149
266
|
function asksBlock(value) {
|
|
150
267
|
return validateBlock({ ...value, kind: "asks" });
|
|
@@ -393,108 +510,6 @@ function validateRecordRead(value) {
|
|
|
393
510
|
};
|
|
394
511
|
}
|
|
395
512
|
|
|
396
|
-
var FileOperationError = class extends Error {
|
|
397
|
-
constructor(code, status, retryable = !1) {
|
|
398
|
-
super(code);
|
|
399
|
-
this.code = code;
|
|
400
|
-
this.status = status;
|
|
401
|
-
this.retryable = retryable;
|
|
402
|
-
}
|
|
403
|
-
code;
|
|
404
|
-
status;
|
|
405
|
-
retryable;
|
|
406
|
-
}, FILE_ID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/, FILE_ORIGINAL_MAX_BYTES = 5 * 1024 ** 3;
|
|
407
|
-
function parseFileDescriptor(value) {
|
|
408
|
-
let invalid8 = () => {
|
|
409
|
-
throw new FileOperationError("unavailable", 503, !0);
|
|
410
|
-
};
|
|
411
|
-
if (!value || typeof value != "object" || Array.isArray(value)) return invalid8();
|
|
412
|
-
let f = value;
|
|
413
|
-
if (Object.keys(f).sort().join(",") !== "details,enrichments,id,mediaType,name,path,sha256,size" || typeof f.id != "string" || !FILE_ID_PATTERN.test(f.id) || !safeFileName(f.name) || !safeFilePath(f.path) || !Number.isSafeInteger(f.size) || f.size < 0 || f.size > FILE_ORIGINAL_MAX_BYTES || typeof f.sha256 != "string" || !/^[0-9a-f]{64}$/.test(f.sha256) || !f.enrichments || typeof f.enrichments != "object" || Array.isArray(f.enrichments) || !f.details || typeof f.details != "object" || Array.isArray(f.details)) return invalid8();
|
|
414
|
-
let d = f.details;
|
|
415
|
-
if (d.kind === "other") {
|
|
416
|
-
if (Object.keys(d).length !== 1 || ![
|
|
417
|
-
"application/octet-stream",
|
|
418
|
-
"text/plain",
|
|
419
|
-
"text/markdown",
|
|
420
|
-
"application/json",
|
|
421
|
-
"image/png",
|
|
422
|
-
"image/jpeg"
|
|
423
|
-
].includes(f.mediaType)) return invalid8();
|
|
424
|
-
} else if (d.kind === "csv") {
|
|
425
|
-
if (Object.keys(d).sort().join(",") !== "dataRows,delimiter,encoding,headerRow,kind" || f.mediaType !== "text/csv" || !["utf-8", "windows-1252"].includes(d.encoding) || ![",", ";", " "].includes(d.delimiter) || !Number.isSafeInteger(d.headerRow) || d.headerRow < 1 || !Number.isSafeInteger(d.dataRows) || d.dataRows < 0) return invalid8();
|
|
426
|
-
} else if (d.kind === "pdf") {
|
|
427
|
-
if (f.mediaType !== "application/pdf" || Object.keys(d).some((key) => !["kind", "pages"].includes(key)) || "pages" in d && (!Number.isSafeInteger(d.pages) || d.pages < 1)) return invalid8();
|
|
428
|
-
} else return invalid8();
|
|
429
|
-
for (let [name, descriptor] of Object.entries(f.enrichments)) {
|
|
430
|
-
if (!safeEnrichmentName(name)) return invalid8();
|
|
431
|
-
parseEnrichmentDescriptor(descriptor);
|
|
432
|
-
}
|
|
433
|
-
return new TextEncoder().encode(JSON.stringify(f)).byteLength > 16 * 1024 ? invalid8() : f;
|
|
434
|
-
}
|
|
435
|
-
function parseEnrichmentDescriptor(value) {
|
|
436
|
-
let invalid8 = () => {
|
|
437
|
-
throw new FileOperationError("unavailable", 503, !0);
|
|
438
|
-
};
|
|
439
|
-
if (!value || typeof value != "object" || Array.isArray(value)) return invalid8();
|
|
440
|
-
let d = value;
|
|
441
|
-
return Object.keys(d).sort().join(",") !== "mediaType,sha256,size" || !["application/octet-stream", "text/plain", "text/markdown", "application/json"].includes(d.mediaType) || !Number.isSafeInteger(d.size) || d.size < 0 || d.size > 16 * 1024 * 1024 || typeof d.sha256 != "string" || !/^[0-9a-f]{64}$/.test(d.sha256) ? invalid8() : d;
|
|
442
|
-
}
|
|
443
|
-
function safeEnrichmentName(value) {
|
|
444
|
-
return safeFileName(value) && !/^original(?:\.|$)/i.test(value);
|
|
445
|
-
}
|
|
446
|
-
function parseFileEnrichMetadata(value, maxBytes) {
|
|
447
|
-
let invalid8 = () => {
|
|
448
|
-
throw new FileOperationError("invalid_input", 400);
|
|
449
|
-
};
|
|
450
|
-
if (!value || typeof value != "object" || Array.isArray(value)) return invalid8();
|
|
451
|
-
let d = value;
|
|
452
|
-
if (Object.keys(d).some((key) => !["name", "size", "mediaType", "replace"].includes(key)) || !safeEnrichmentName(d.name) || !Number.isSafeInteger(d.size) || d.size < 0 || d.mediaType !== void 0 && (typeof d.mediaType != "string" || d.mediaType.length > 255 || /[\u0000-\u001f\u007f]/.test(d.mediaType)) || d.replace !== void 0 && (typeof d.replace != "string" || !/^[0-9a-f]{64}$/.test(d.replace))) return invalid8();
|
|
453
|
-
if (d.size > maxBytes) throw new FileOperationError("request_too_large", 413);
|
|
454
|
-
return d;
|
|
455
|
-
}
|
|
456
|
-
function safeFileName(value) {
|
|
457
|
-
return typeof value == "string" && value.length > 0 && value.length <= 255 && value === value.trim() && value !== "." && value !== ".." && !/[\u0000-\u001f\u007f-\u009f/\\:*?"<>|]/u.test(value) && !/[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/.test(value) && !/[. ]$/.test(value) && !/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(value);
|
|
458
|
-
}
|
|
459
|
-
function safeFilePath(value) {
|
|
460
|
-
return typeof value == "string" && value.length <= 1024 && value.split("/").every(safeFileName);
|
|
461
|
-
}
|
|
462
|
-
var ORIGINAL_MEDIA_TYPES = ["application/pdf", "text/plain", "text/markdown", "application/json", "image/png", "image/jpeg"];
|
|
463
|
-
function declaredOriginalMediaType(value) {
|
|
464
|
-
let normalized = value.split(";", 1)[0].trim().toLowerCase();
|
|
465
|
-
return ORIGINAL_MEDIA_TYPES.includes(normalized) ? normalized : void 0;
|
|
466
|
-
}
|
|
467
|
-
function parseFileCreateMetadata(value, maxBytes) {
|
|
468
|
-
let invalid8 = () => {
|
|
469
|
-
throw new FileOperationError("invalid_input", 400);
|
|
470
|
-
};
|
|
471
|
-
if (!value || typeof value != "object" || Array.isArray(value)) return invalid8();
|
|
472
|
-
let input = value;
|
|
473
|
-
if (Object.keys(input).some((key) => !["name", "path", "storage", "csv", "inputMediaType", "size", "requestKey"].includes(key))) return invalid8();
|
|
474
|
-
let path = input.path === void 0 ? "Files" : input.path;
|
|
475
|
-
if (!safeFileName(input.name) || !safeFilePath(path) || path.split("/")[0].toLowerCase() === ".os" || input.storage !== void 0 && input.storage !== "remote" && input.storage !== "local" || input.inputMediaType !== void 0 && (typeof input.inputMediaType != "string" || !ORIGINAL_MEDIA_TYPES.includes(input.inputMediaType)) || !Number.isSafeInteger(input.size) || input.size < 0) return invalid8();
|
|
476
|
-
if (input.size > maxBytes) throw new FileOperationError("request_too_large", 413);
|
|
477
|
-
if (typeof input.requestKey != "string" || input.requestKey.length < 1 || input.requestKey.length > 256 || input.requestKey !== input.requestKey.trim() || /[\u0000-\u001f\u007f]/.test(input.requestKey)) return invalid8();
|
|
478
|
-
let csv;
|
|
479
|
-
if (input.csv !== void 0) {
|
|
480
|
-
if (!input.csv || typeof input.csv != "object" || Array.isArray(input.csv)) return invalid8();
|
|
481
|
-
let hints = input.csv;
|
|
482
|
-
if (Object.keys(hints).some((key) => !["encoding", "delimiter", "headerRow"].includes(key))) return invalid8();
|
|
483
|
-
let encoding = hints.encoding === void 0 ? "utf-8" : hints.encoding, delimiter = hints.delimiter === void 0 ? "," : hints.delimiter, headerRow = hints.headerRow === void 0 ? 1 : hints.headerRow;
|
|
484
|
-
if (encoding !== "utf-8" && encoding !== "windows-1252" || ![",", ";", " "].includes(delimiter) || !Number.isSafeInteger(headerRow) || headerRow < 1 || headerRow > 1e5) return invalid8();
|
|
485
|
-
csv = { encoding, delimiter, headerRow };
|
|
486
|
-
}
|
|
487
|
-
return {
|
|
488
|
-
name: input.name,
|
|
489
|
-
path,
|
|
490
|
-
...input.storage ? { storage: input.storage } : {},
|
|
491
|
-
...input.inputMediaType === void 0 ? {} : { inputMediaType: input.inputMediaType },
|
|
492
|
-
...csv ? { csv } : {},
|
|
493
|
-
size: input.size,
|
|
494
|
-
requestKey: input.requestKey
|
|
495
|
-
};
|
|
496
|
-
}
|
|
497
|
-
|
|
498
513
|
var AppRoutineContractError = class extends Error {
|
|
499
514
|
constructor(code) {
|
|
500
515
|
super(code);
|
|
@@ -545,7 +560,11 @@ function parseAppRoutineContract(value) {
|
|
|
545
560
|
case "boolean":
|
|
546
561
|
return fields2(value2, ["type"]) ? { type: value2.type } : invalidContract();
|
|
547
562
|
case "file":
|
|
548
|
-
return !fields2(value2, ["type"], ["storage"]) || owns(value2, "storage") && value2.storage !== "local" && value2.storage !== "remote"
|
|
563
|
+
return !fields2(value2, ["type"], ["storage", "path"]) || owns(value2, "storage") && value2.storage !== "local" && value2.storage !== "remote" || owns(value2, "path") && !safeManagedFilePath(value2.path) ? invalidContract() : {
|
|
564
|
+
type: "file",
|
|
565
|
+
...owns(value2, "storage") ? { storage: value2.storage } : {},
|
|
566
|
+
...owns(value2, "path") ? { path: value2.path } : {}
|
|
567
|
+
};
|
|
549
568
|
case "string":
|
|
550
569
|
return !fields2(value2, ["type"], ["maxLength"]) || owns(value2, "maxLength") && (!Number.isSafeInteger(value2.maxLength) || value2.maxLength < 0 || value2.maxLength > 4096) ? invalidContract() : { type: "string", ...owns(value2, "maxLength") ? { maxLength: value2.maxLength } : {} };
|
|
551
570
|
case "integer":
|
|
@@ -592,7 +611,9 @@ function validateRoutineSchemaValue(schema2, value) {
|
|
|
592
611
|
return typeof value != "number" || !(schema2.type === "integer" ? Number.isSafeInteger(value) : Number.isFinite(value)) || schema2.minimum !== void 0 && value < schema2.minimum || schema2.maximum !== void 0 && value > schema2.maximum ? invalidValue() : void 0;
|
|
593
612
|
case "file":
|
|
594
613
|
try {
|
|
595
|
-
jsonData(value)
|
|
614
|
+
jsonData(value);
|
|
615
|
+
let file2 = parseFileDescriptor(value);
|
|
616
|
+
if (schema2.path !== void 0 && file2.path !== schema2.path) return invalidValue();
|
|
596
617
|
} catch {
|
|
597
618
|
return invalidValue();
|
|
598
619
|
}
|
|
@@ -791,7 +812,7 @@ var schema = {
|
|
|
791
812
|
boolean() {
|
|
792
813
|
return declaration({ type: "boolean" });
|
|
793
814
|
}
|
|
794
|
-
}, file = (options = {}) => (assertRoutineFields(options, ["storage"]), declaration({ type: "file", ...options })), definitions = /* @__PURE__ */ new WeakMap(), defineRoutine = (definition) => {
|
|
815
|
+
}, file = (options = {}) => (assertRoutineFields(options, ["storage", "path"]), declaration({ type: "file", ...options })), definitions = /* @__PURE__ */ new WeakMap(), defineRoutine = (definition) => {
|
|
795
816
|
if (assertRoutineFields(definition, ["id", "title", "input", "steps", "result", "access", "responses", "run"]), !isAppRoutineName(definition.id) || definition.title !== void 0 && !routineTitle(definition.title) || typeof definition.run != "function") return invalidContract3();
|
|
796
817
|
let input = definition.input === void 0 ? { schema: empty, default: {} } : schemaMetadata(definition.input), result2 = definition.result === void 0 ? void 0 : schemaMetadata(definition.result).schema, access = parseRoutineAccess(definition.access);
|
|
797
818
|
assertRoutineFields(definition.steps ?? {});
|
|
@@ -2957,10 +2978,10 @@ var unavailable3 = () => new InboxOperationError(503, "unavailable"), stale = ()
|
|
|
2957
2978
|
function hostFailure(error, context2) {
|
|
2958
2979
|
return !context2.isCurrent() || context2.expiresAt <= Date.now() || error instanceof InboxContextError && error.status === 401 ? stale() : error instanceof InboxContextError && error.status === 403 ? new InboxOperationError(403, "access_denied") : unavailable3();
|
|
2959
2980
|
}
|
|
2960
|
-
async function send2(operation2, input) {
|
|
2981
|
+
async function send2(operation2, input, admitted) {
|
|
2961
2982
|
let envelope = parseInboxRequest({ operation: operation2, input }), context2;
|
|
2962
2983
|
try {
|
|
2963
|
-
context2 = await resolveAppContext();
|
|
2984
|
+
context2 = admitted ?? await resolveAppContext();
|
|
2964
2985
|
} catch {
|
|
2965
2986
|
throw stale();
|
|
2966
2987
|
}
|
|
@@ -3120,7 +3141,7 @@ var inbox = {
|
|
|
3120
3141
|
let page = await send2("questions.list", {
|
|
3121
3142
|
routines,
|
|
3122
3143
|
...beforeNumber === void 0 ? {} : { beforeNumber }
|
|
3123
|
-
});
|
|
3144
|
+
}, initial);
|
|
3124
3145
|
if (check(), page.questions.some((question2) => question2.inboxUrl !== `https://${initial.workspace}.oddington.ai/inbox/${question2.itemId}` || !routines.includes(question2.routine)) || beforeNumber !== void 0 && page.nextBeforeNumber !== null && page.nextBeforeNumber >= beforeNumber) throw unavailable3();
|
|
3125
3146
|
if (questions.push(...page.questions), page.nextBeforeNumber === null) return questions;
|
|
3126
3147
|
beforeNumber = page.nextBeforeNumber;
|