@vertesia/client 1.6.0-dev.20261022.120426Z → 1.6.0-dev.20261120.123957Z
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/lib/AccountApi.d.ts +2 -0
- package/lib/AccountApi.d.ts.map +1 -1
- package/lib/AccountApi.js +3 -0
- package/lib/AccountApi.js.map +1 -1
- package/lib/AccountRolesApi.d.ts +11 -0
- package/lib/AccountRolesApi.d.ts.map +1 -0
- package/lib/AccountRolesApi.js +22 -0
- package/lib/AccountRolesApi.js.map +1 -0
- package/lib/AppsApi.d.ts +18 -3
- package/lib/AppsApi.d.ts.map +1 -1
- package/lib/AppsApi.js +34 -4
- package/lib/AppsApi.js.map +1 -1
- package/lib/AuditTrailApi.d.ts +6 -1
- package/lib/AuditTrailApi.d.ts.map +1 -1
- package/lib/AuditTrailApi.js +8 -0
- package/lib/AuditTrailApi.js.map +1 -1
- package/lib/IamApi.d.ts +1 -1
- package/lib/IamApi.js +1 -1
- package/lib/InteractionCatalogApi.d.ts +19 -1
- package/lib/InteractionCatalogApi.d.ts.map +1 -1
- package/lib/InteractionCatalogApi.js +30 -0
- package/lib/InteractionCatalogApi.js.map +1 -1
- package/lib/InteractionsApi.d.ts +3 -12
- package/lib/InteractionsApi.d.ts.map +1 -1
- package/lib/InteractionsApi.js +2 -23
- package/lib/InteractionsApi.js.map +1 -1
- package/lib/OAuthClientsApi.d.ts +3 -1
- package/lib/OAuthClientsApi.d.ts.map +1 -1
- package/lib/OAuthClientsApi.js +4 -0
- package/lib/OAuthClientsApi.js.map +1 -1
- package/lib/OAuthProvidersApi.d.ts +6 -2
- package/lib/OAuthProvidersApi.d.ts.map +1 -1
- package/lib/OAuthProvidersApi.js +6 -2
- package/lib/OAuthProvidersApi.js.map +1 -1
- package/lib/StreamSource.d.ts +19 -1
- package/lib/StreamSource.d.ts.map +1 -1
- package/lib/StreamSource.js +31 -1
- package/lib/StreamSource.js.map +1 -1
- package/lib/UsersApi.d.ts +7 -1
- package/lib/UsersApi.d.ts.map +1 -1
- package/lib/UsersApi.js +8 -0
- package/lib/UsersApi.js.map +1 -1
- package/lib/client.d.ts +14 -2
- package/lib/client.d.ts.map +1 -1
- package/lib/client.js +55 -8
- package/lib/client.js.map +1 -1
- package/lib/execute.d.ts.map +1 -1
- package/lib/execute.js +4 -2
- package/lib/execute.js.map +1 -1
- package/lib/idempotency-key.d.ts +19 -0
- package/lib/idempotency-key.d.ts.map +1 -0
- package/lib/idempotency-key.js +34 -0
- package/lib/idempotency-key.js.map +1 -0
- package/lib/nodejs/NodeStreamSource.d.ts +10 -1
- package/lib/nodejs/NodeStreamSource.d.ts.map +1 -1
- package/lib/nodejs/NodeStreamSource.js +40 -2
- package/lib/nodejs/NodeStreamSource.js.map +1 -1
- package/lib/store/AgentsApi.d.ts.map +1 -1
- package/lib/store/AgentsApi.js +5 -2
- package/lib/store/AgentsApi.js.map +1 -1
- package/lib/store/ContentSourcesApi.d.ts +52 -0
- package/lib/store/ContentSourcesApi.d.ts.map +1 -0
- package/lib/store/ContentSourcesApi.js +85 -0
- package/lib/store/ContentSourcesApi.js.map +1 -0
- package/lib/store/CostApi.d.ts +6 -1
- package/lib/store/CostApi.d.ts.map +1 -1
- package/lib/store/CostApi.js +7 -0
- package/lib/store/CostApi.js.map +1 -1
- package/lib/store/DashboardApi.d.ts +61 -19
- package/lib/store/DashboardApi.d.ts.map +1 -1
- package/lib/store/DashboardApi.js +75 -19
- package/lib/store/DashboardApi.js.map +1 -1
- package/lib/store/DataApi.d.ts +9 -9
- package/lib/store/DataApi.d.ts.map +1 -1
- package/lib/store/DataApi.js +14 -10
- package/lib/store/DataApi.js.map +1 -1
- package/lib/store/FilesApi.d.ts +15 -1
- package/lib/store/FilesApi.d.ts.map +1 -1
- package/lib/store/FilesApi.js +54 -75
- package/lib/store/FilesApi.js.map +1 -1
- package/lib/store/NotificationsApi.d.ts +39 -0
- package/lib/store/NotificationsApi.d.ts.map +1 -0
- package/lib/store/NotificationsApi.js +68 -0
- package/lib/store/NotificationsApi.js.map +1 -0
- package/lib/store/ObjectsApi.d.ts +6 -1
- package/lib/store/ObjectsApi.d.ts.map +1 -1
- package/lib/store/ObjectsApi.js +23 -30
- package/lib/store/ObjectsApi.js.map +1 -1
- package/lib/store/RenderingApi.d.ts.map +1 -1
- package/lib/store/RenderingApi.js +1 -0
- package/lib/store/RenderingApi.js.map +1 -1
- package/lib/store/WorkflowsApi.d.ts +19 -1
- package/lib/store/WorkflowsApi.d.ts.map +1 -1
- package/lib/store/WorkflowsApi.js +21 -0
- package/lib/store/WorkflowsApi.js.map +1 -1
- package/lib/store/chunked-upload.d.ts +71 -0
- package/lib/store/chunked-upload.d.ts.map +1 -0
- package/lib/store/chunked-upload.js +206 -0
- package/lib/store/chunked-upload.js.map +1 -0
- package/lib/store/client.d.ts +9 -1
- package/lib/store/client.d.ts.map +1 -1
- package/lib/store/client.js +15 -1
- package/lib/store/client.js.map +1 -1
- package/lib/store/index.d.ts +3 -0
- package/lib/store/index.d.ts.map +1 -1
- package/lib/store/index.js +3 -0
- package/lib/store/index.js.map +1 -1
- package/lib/store/node-request.browser.d.ts +14 -0
- package/lib/store/node-request.browser.d.ts.map +1 -0
- package/lib/store/node-request.browser.js +20 -0
- package/lib/store/node-request.browser.js.map +1 -0
- package/lib/store/node-request.d.ts +20 -0
- package/lib/store/node-request.d.ts.map +1 -0
- package/lib/store/node-request.js +116 -0
- package/lib/store/node-request.js.map +1 -0
- package/lib/store/node-sessions.browser.d.ts +3 -0
- package/lib/store/node-sessions.browser.d.ts.map +1 -0
- package/lib/store/node-sessions.browser.js +15 -0
- package/lib/store/node-sessions.browser.js.map +1 -0
- package/lib/store/node-sessions.d.ts +14 -0
- package/lib/store/node-sessions.d.ts.map +1 -0
- package/lib/store/node-sessions.js +88 -0
- package/lib/store/node-sessions.js.map +1 -0
- package/lib/store/signed-url.d.ts +12 -16
- package/lib/store/signed-url.d.ts.map +1 -1
- package/lib/store/signed-url.js +111 -71
- package/lib/store/signed-url.js.map +1 -1
- package/lib/store/stream-bytes.d.ts +16 -0
- package/lib/store/stream-bytes.d.ts.map +1 -0
- package/lib/store/stream-bytes.js +70 -0
- package/lib/store/stream-bytes.js.map +1 -0
- package/lib/store/upload-body.d.ts +21 -0
- package/lib/store/upload-body.d.ts.map +1 -0
- package/lib/store/upload-body.js +32 -0
- package/lib/store/upload-body.js.map +1 -0
- package/lib/store/upload-content.d.ts +21 -0
- package/lib/store/upload-content.d.ts.map +1 -0
- package/lib/store/upload-content.js +113 -0
- package/lib/store/upload-content.js.map +1 -0
- package/lib/store/upload-runtime.d.ts +21 -0
- package/lib/store/upload-runtime.d.ts.map +1 -0
- package/lib/store/upload-runtime.js +40 -0
- package/lib/store/upload-runtime.js.map +1 -0
- package/lib/vertesia-client.js +10 -9
- package/lib/vertesia-client.js.map +1 -1
- package/package.json +35 -11
- package/src/AccountApi.ts +3 -0
- package/src/AccountRolesApi.ts +29 -0
- package/src/AppsApi.ts +58 -4
- package/src/AuditTrailApi.ts +11 -0
- package/src/IamApi.ts +1 -1
- package/src/InteractionCatalogApi.ts +44 -1
- package/src/InteractionsApi.ts +2 -31
- package/src/OAuthClientsApi.ts +6 -0
- package/src/OAuthProvidersApi.ts +7 -2
- package/src/StreamSource.ts +29 -0
- package/src/UsersApi.ts +10 -1
- package/src/client.ts +72 -8
- package/src/execute.ts +4 -2
- package/src/idempotency-key.ts +34 -0
- package/src/nodejs/NodeStreamSource.ts +37 -2
- package/src/store/AgentsApi.ts +5 -2
- package/src/store/ContentSourcesApi.ts +126 -0
- package/src/store/CostApi.ts +10 -0
- package/src/store/DashboardApi.ts +93 -18
- package/src/store/DataApi.ts +14 -10
- package/src/store/FilesApi.ts +84 -78
- package/src/store/NotificationsApi.ts +103 -0
- package/src/store/ObjectsApi.ts +30 -34
- package/src/store/RenderingApi.ts +1 -0
- package/src/store/WorkflowsApi.ts +25 -0
- package/src/store/chunked-upload.ts +272 -0
- package/src/store/client.ts +21 -1
- package/src/store/index.ts +3 -0
- package/src/store/node-request.browser.ts +22 -0
- package/src/store/node-request.ts +120 -0
- package/src/store/node-sessions.browser.ts +16 -0
- package/src/store/node-sessions.ts +109 -0
- package/src/store/signed-url.ts +126 -72
- package/src/store/stream-bytes.ts +79 -0
- package/src/store/upload-body.ts +37 -0
- package/src/store/upload-content.ts +129 -0
- package/src/store/upload-runtime.ts +42 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Byte handling for upload bodies read from a `ReadableStream`. Internal: not exported from the package. */
|
|
2
|
+
/**
|
|
3
|
+
* Normalize one `ReadableStream` chunk to a byte-backed `BlobPart`.
|
|
4
|
+
*
|
|
5
|
+
* A web stream produced from a Node `Readable.from(<string>)` (e.g. via
|
|
6
|
+
* `Readable.toWeb`, which `NodeStreamSource` uses) yields *string* chunks. Buffering
|
|
7
|
+
* such a stream with `new Response(stream).blob()` throws under undici with
|
|
8
|
+
* "TypeError: Received non-Uint8Array chunk", which breaks every signed-URL upload of
|
|
9
|
+
* a text/JSON body (extracted text previews, agent artifacts, tool storage). Encoding
|
|
10
|
+
* chunks ourselves keeps both string and binary bodies uploadable.
|
|
11
|
+
*/
|
|
12
|
+
export declare function chunkToBlobPart(chunk: unknown): BlobPart;
|
|
13
|
+
/** A byte stream of `head`, the parts already read, then what is left in `reader`. */
|
|
14
|
+
export declare function continueStream(head: BlobPart[], reader: ReadableStreamDefaultReader<unknown>): ReadableStream<Uint8Array>;
|
|
15
|
+
export declare function partToBytes(part: BlobPart): Promise<Uint8Array>;
|
|
16
|
+
//# sourceMappingURL=stream-bytes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-bytes.d.ts","sourceRoot":"","sources":["../../src/store/stream-bytes.ts"],"names":[],"mappings":"AAAA,6GAA6G;AAI7G;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,CAoBxD;AAED,sFAAsF;AACtF,wBAAgB,cAAc,CAC1B,IAAI,EAAE,QAAQ,EAAE,EAChB,MAAM,EAAE,2BAA2B,CAAC,OAAO,CAAC,GAC7C,cAAc,CAAC,UAAU,CAAC,CAkC5B;AAED,wBAAsB,WAAW,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAErE"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/** Byte handling for upload bodies read from a `ReadableStream`. Internal: not exported from the package. */
|
|
2
|
+
const textEncoder = new TextEncoder();
|
|
3
|
+
/**
|
|
4
|
+
* Normalize one `ReadableStream` chunk to a byte-backed `BlobPart`.
|
|
5
|
+
*
|
|
6
|
+
* A web stream produced from a Node `Readable.from(<string>)` (e.g. via
|
|
7
|
+
* `Readable.toWeb`, which `NodeStreamSource` uses) yields *string* chunks. Buffering
|
|
8
|
+
* such a stream with `new Response(stream).blob()` throws under undici with
|
|
9
|
+
* "TypeError: Received non-Uint8Array chunk", which breaks every signed-URL upload of
|
|
10
|
+
* a text/JSON body (extracted text previews, agent artifacts, tool storage). Encoding
|
|
11
|
+
* chunks ourselves keeps both string and binary bodies uploadable.
|
|
12
|
+
*/
|
|
13
|
+
export function chunkToBlobPart(chunk) {
|
|
14
|
+
if (typeof chunk === 'string') {
|
|
15
|
+
return textEncoder.encode(chunk);
|
|
16
|
+
}
|
|
17
|
+
if (chunk instanceof Blob) {
|
|
18
|
+
return chunk;
|
|
19
|
+
}
|
|
20
|
+
if (chunk instanceof ArrayBuffer) {
|
|
21
|
+
return new Uint8Array(chunk);
|
|
22
|
+
}
|
|
23
|
+
// Covers Uint8Array and every other typed-array / DataView view.
|
|
24
|
+
if (ArrayBuffer.isView(chunk)) {
|
|
25
|
+
return new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength);
|
|
26
|
+
}
|
|
27
|
+
// Fail loud rather than uploading e.g. "[object Object]" from an accidental
|
|
28
|
+
// object-mode stream — silently corrupting the stored content is worse than a clear error.
|
|
29
|
+
throw new TypeError(`Unsupported signed-URL upload chunk of type "${typeof chunk}"; ` +
|
|
30
|
+
`body streams must yield string or binary (Uint8Array/ArrayBuffer/DataView/Blob) chunks.`);
|
|
31
|
+
}
|
|
32
|
+
/** A byte stream of `head`, the parts already read, then what is left in `reader`. */
|
|
33
|
+
export function continueStream(head, reader) {
|
|
34
|
+
const pending = [...head];
|
|
35
|
+
return new ReadableStream({
|
|
36
|
+
async pull(controller) {
|
|
37
|
+
const next = pending.shift();
|
|
38
|
+
if (next !== undefined) {
|
|
39
|
+
controller.enqueue(await partToBytes(next));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
const { done, value } = await reader.read();
|
|
44
|
+
if (done) {
|
|
45
|
+
reader.releaseLock();
|
|
46
|
+
controller.close();
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
controller.enqueue(await partToBytes(chunkToBlobPart(value)));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
// An error in pull errors this stream without calling cancel, so the source is cancelled here.
|
|
54
|
+
pending.length = 0;
|
|
55
|
+
await reader.cancel(err).catch(() => undefined);
|
|
56
|
+
reader.releaseLock();
|
|
57
|
+
throw err;
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
async cancel(reason) {
|
|
61
|
+
pending.length = 0;
|
|
62
|
+
await reader.cancel(reason);
|
|
63
|
+
reader.releaseLock();
|
|
64
|
+
},
|
|
65
|
+
}, { highWaterMark: 0 });
|
|
66
|
+
}
|
|
67
|
+
export async function partToBytes(part) {
|
|
68
|
+
return part instanceof Blob ? new Uint8Array(await part.arrayBuffer()) : part;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=stream-bytes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-bytes.js","sourceRoot":"","sources":["../../src/store/stream-bytes.ts"],"names":[],"mappings":"AAAA,6GAA6G;AAE7G,MAAM,WAAW,GAAG,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,WAAW,EAAE,CAAC;oBACrB,UAAU,CAAC,KAAK,EAAE,CAAC;gBACvB,CAAC;qBAAM,CAAC;oBACJ,UAAU,CAAC,OAAO,CAAC,MAAM,WAAW,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBAClE,CAAC;YACL,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACX,+FAA+F;gBAC/F,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;gBACnB,MAAM,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;gBAChD,MAAM,CAAC,WAAW,EAAE,CAAC;gBACrB,MAAM,GAAG,CAAC;YACd,CAAC;QACL,CAAC;QACD,KAAK,CAAC,MAAM,CAAC,MAAM;YACf,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;YACnB,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC5B,MAAM,CAAC,WAAW,EAAE,CAAC;QACzB,CAAC;KACJ,EACD,EAAE,aAAa,EAAE,CAAC,EAAE,CACvB,CAAC;AACN,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IAAc;IAC5C,OAAO,IAAI,YAAY,IAAI,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAE,IAAmB,CAAC;AAClG,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { StreamSource } from '../StreamSource.js';
|
|
2
|
+
/** What to send to upload a source: the body, and the declared length of a stream body. */
|
|
3
|
+
export interface UploadBody {
|
|
4
|
+
body: Blob | ReadableStream;
|
|
5
|
+
/** Sent as `Content-Length` with a stream body whose length is known; a `Blob` carries its own. */
|
|
6
|
+
contentLength?: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The request body for uploading a source to a signed URL.
|
|
10
|
+
*
|
|
11
|
+
* A `File` is sent as it is. A stream source with a {@link StreamSource.replayableBody} (e.g. a local file) sends
|
|
12
|
+
* that instead, so a retry re-reads it rather than needing a buffered copy; its stream is cancelled, which releases
|
|
13
|
+
* what the stream holds, such as a file descriptor. Any other stream source sends its stream, with its
|
|
14
|
+
* {@link StreamSource.size} when known.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getUploadBody(source: StreamSource | File): Promise<UploadBody>;
|
|
17
|
+
/** Headers for an upload: the content type, and `Content-Length` when the body declares one. */
|
|
18
|
+
export declare function uploadHeaders(upload: UploadBody, contentType: string | undefined): Record<string, string> | undefined;
|
|
19
|
+
/** An ETag without the quotes HTTP puts around it (RFC 9110), as the upload methods return it. */
|
|
20
|
+
export declare function unquoteEtag(etag: string | undefined): string | undefined;
|
|
21
|
+
//# sourceMappingURL=upload-body.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload-body.d.ts","sourceRoot":"","sources":["../../src/store/upload-body.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,2FAA2F;AAC3F,MAAM,WAAW,UAAU;IACvB,IAAI,EAAE,IAAI,GAAG,cAAc,CAAC;IAC5B,mGAAmG;IACnG,aAAa,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;GAOG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,CAMpF;AAED,gGAAgG;AAChG,wBAAgB,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAKrH;AAED,kGAAkG;AAClG,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAExE"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { StreamSource } from '../StreamSource.js';
|
|
2
|
+
/**
|
|
3
|
+
* The request body for uploading a source to a signed URL.
|
|
4
|
+
*
|
|
5
|
+
* A `File` is sent as it is. A stream source with a {@link StreamSource.replayableBody} (e.g. a local file) sends
|
|
6
|
+
* that instead, so a retry re-reads it rather than needing a buffered copy; its stream is cancelled, which releases
|
|
7
|
+
* what the stream holds, such as a file descriptor. Any other stream source sends its stream, with its
|
|
8
|
+
* {@link StreamSource.size} when known.
|
|
9
|
+
*/
|
|
10
|
+
export async function getUploadBody(source) {
|
|
11
|
+
if (!(source instanceof StreamSource))
|
|
12
|
+
return { body: source };
|
|
13
|
+
const body = await source.replayableBody();
|
|
14
|
+
if (!body)
|
|
15
|
+
return { body: source.stream, contentLength: source.size };
|
|
16
|
+
await source.stream.cancel().catch(() => undefined);
|
|
17
|
+
return { body };
|
|
18
|
+
}
|
|
19
|
+
/** Headers for an upload: the content type, and `Content-Length` when the body declares one. */
|
|
20
|
+
export function uploadHeaders(upload, contentType) {
|
|
21
|
+
const headers = {};
|
|
22
|
+
if (contentType)
|
|
23
|
+
headers['Content-Type'] = contentType;
|
|
24
|
+
if (upload.contentLength !== undefined)
|
|
25
|
+
headers['Content-Length'] = String(upload.contentLength);
|
|
26
|
+
return Object.keys(headers).length > 0 ? headers : undefined;
|
|
27
|
+
}
|
|
28
|
+
/** An ETag without the quotes HTTP puts around it (RFC 9110), as the upload methods return it. */
|
|
29
|
+
export function unquoteEtag(etag) {
|
|
30
|
+
return etag?.replace(/^"(.*)"$/, '$1');
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=upload-body.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload-body.js","sourceRoot":"","sources":["../../src/store/upload-body.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AASlD;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MAA2B;IAC3D,IAAI,CAAC,CAAC,MAAM,YAAY,YAAY,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAC/D,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,cAAc,EAAE,CAAC;IAC3C,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;IACtE,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IACpD,OAAO,EAAE,IAAI,EAAE,CAAC;AACpB,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,aAAa,CAAC,MAAkB,EAAE,WAA+B;IAC7E,MAAM,OAAO,GAA2B,EAAE,CAAC;IAC3C,IAAI,WAAW;QAAE,OAAO,CAAC,cAAc,CAAC,GAAG,WAAW,CAAC;IACvD,IAAI,MAAM,CAAC,aAAa,KAAK,SAAS;QAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;IACjG,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;AACjE,CAAC;AAED,kGAAkG;AAClG,MAAM,UAAU,WAAW,CAAC,IAAwB;IAChD,OAAO,IAAI,EAAE,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { CreateUploadSessionPayload, GetFileUrlResponse } from '@vertesia/common';
|
|
2
|
+
import type { StreamSource } from '../StreamSource.js';
|
|
3
|
+
import type { FilesApi } from './FilesApi.js';
|
|
4
|
+
/** A location without its query string or fragment, which hold a signed URL's credentials. */
|
|
5
|
+
export declare function fileLocationForError(location: string): string;
|
|
6
|
+
/** A copy of an error safe to log: every URL in its message is cut to its location. */
|
|
7
|
+
export declare function sanitizedErrorCause(error: unknown): Error | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Upload a source to the file `request` names: in one signed PUT, or, for a stream source longer than one part in
|
|
10
|
+
* Node.js, in parts through an upload session (see `chunked-upload.ts`). On failure the source's stream is cancelled.
|
|
11
|
+
*
|
|
12
|
+
* @param signUpload the signed PUT URL to use, when the caller already has one or signs it another way
|
|
13
|
+
* @param fallbackMimeType the content type when neither the source nor the server names one
|
|
14
|
+
*/
|
|
15
|
+
export declare function uploadContent(files: FilesApi, source: StreamSource | File, request: CreateUploadSessionPayload, signUpload?: () => Promise<GetFileUrlResponse>, fallbackMimeType?: string): Promise<{
|
|
16
|
+
id: string;
|
|
17
|
+
path: string;
|
|
18
|
+
mime_type?: string;
|
|
19
|
+
etag?: string;
|
|
20
|
+
}>;
|
|
21
|
+
//# sourceMappingURL=upload-content.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload-content.d.ts","sourceRoot":"","sources":["../../src/store/upload-content.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACvF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAM9C,8FAA8F;AAC9F,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAO7D;AAED,uFAAuF;AACvF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,GAAG,SAAS,CAQrE;AAcD;;;;;;GAMG;AACH,wBAAsB,aAAa,CAC/B,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,YAAY,GAAG,IAAI,EAC3B,OAAO,EAAE,0BAA0B,EACnC,UAAU,GAAE,MAAM,OAAO,CAAC,kBAAkB,CAAqC,EACjF,gBAAgB,CAAC,EAAE,MAAM,GAC1B,OAAO,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAW1E"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The upload of a source to a file, shared by `FilesApi` and `ObjectsApi`. Internal: not exported from the package.
|
|
3
|
+
*/
|
|
4
|
+
import { RequestError } from '@vertesia/api-fetch-client';
|
|
5
|
+
import { partsAsUploadBody, planUpload, uploadInParts } from './chunked-upload.js';
|
|
6
|
+
import { fetchSignedUrl } from './signed-url.js';
|
|
7
|
+
import { unquoteEtag, uploadHeaders } from './upload-body.js';
|
|
8
|
+
import { UploadSessionUnavailableError } from './upload-runtime.js';
|
|
9
|
+
import { resolveUploadMimeType } from './uploadMimeType.js';
|
|
10
|
+
/** A location without its query string or fragment, which hold a signed URL's credentials. */
|
|
11
|
+
export function fileLocationForError(location) {
|
|
12
|
+
try {
|
|
13
|
+
const url = new URL(location);
|
|
14
|
+
return `${url.protocol}//${url.host}${url.pathname}`;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return location.split(/[?#]/, 1)[0] || 'unknown file';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/** A copy of an error safe to log: every URL in its message is cut to its location. */
|
|
21
|
+
export function sanitizedErrorCause(error) {
|
|
22
|
+
if (!(error instanceof Error)) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
const message = error.message.replace(/https?:\/\/[^\s)\]}>"']+/g, (url) => fileLocationForError(url));
|
|
26
|
+
const cause = new Error(message);
|
|
27
|
+
cause.name = error.name;
|
|
28
|
+
return cause;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The statuses of a server without upload sessions (404, or 405 where another route matches the path), or whose
|
|
32
|
+
* storage has none (501).
|
|
33
|
+
*/
|
|
34
|
+
const NO_UPLOAD_SESSION_STATUSES = new Set([404, 405, 501]);
|
|
35
|
+
/** The stream of a plan, which a failed upload must cancel to release what it holds (a socket, a file). */
|
|
36
|
+
function planStream(plan) {
|
|
37
|
+
const body = plan.kind === 'parts' ? plan.parts.body : plan.upload.body;
|
|
38
|
+
return body instanceof ReadableStream ? body : undefined;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Upload a source to the file `request` names: in one signed PUT, or, for a stream source longer than one part in
|
|
42
|
+
* Node.js, in parts through an upload session (see `chunked-upload.ts`). On failure the source's stream is cancelled.
|
|
43
|
+
*
|
|
44
|
+
* @param signUpload the signed PUT URL to use, when the caller already has one or signs it another way
|
|
45
|
+
* @param fallbackMimeType the content type when neither the source nor the server names one
|
|
46
|
+
*/
|
|
47
|
+
export async function uploadContent(files, source, request, signUpload = () => files.getUploadUrl(request), fallbackMimeType) {
|
|
48
|
+
const plan = await planUpload(source);
|
|
49
|
+
try {
|
|
50
|
+
return await sendPlan(files, source, request, plan, signUpload, fallbackMimeType);
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
// A stream already being sent is locked, and its sender cancels it; this one was never read whole.
|
|
54
|
+
await planStream(plan)
|
|
55
|
+
?.cancel(err)
|
|
56
|
+
.catch(() => undefined);
|
|
57
|
+
throw err;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async function sendPlan(files, source, request, plan, signUpload, fallbackMimeType) {
|
|
61
|
+
let upload;
|
|
62
|
+
if (plan.kind === 'parts') {
|
|
63
|
+
const session = await files.createUploadSession(request).catch((err) => {
|
|
64
|
+
if (err instanceof RequestError && NO_UPLOAD_SESSION_STATUSES.has(err.status))
|
|
65
|
+
return undefined;
|
|
66
|
+
throw err;
|
|
67
|
+
});
|
|
68
|
+
if (!session) {
|
|
69
|
+
console.warn(`Upload sessions are not available; uploading ${request.name} in a single request`);
|
|
70
|
+
upload = partsAsUploadBody(plan.parts);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
try {
|
|
74
|
+
const etag = await uploadInParts(files, session, plan.parts);
|
|
75
|
+
const mime_type = resolveUploadMimeType(source.type, session.mime_type) || fallbackMimeType;
|
|
76
|
+
return { id: session.id, path: session.path, mime_type, etag };
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
if (!(err instanceof UploadSessionUnavailableError)) {
|
|
80
|
+
console.error('Failed to upload file', { err: sanitizedErrorCause(err), id: session.id });
|
|
81
|
+
throw err;
|
|
82
|
+
}
|
|
83
|
+
console.warn(`${err.message}; uploading ${session.path} in a single request instead`);
|
|
84
|
+
upload = partsAsUploadBody(plan.parts);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
upload = plan.upload;
|
|
90
|
+
}
|
|
91
|
+
const { url, id, path, mime_type } = await signUpload();
|
|
92
|
+
const sourceMimeType = resolveUploadMimeType(source.type, mime_type) || fallbackMimeType;
|
|
93
|
+
const res = await fetchSignedUrl(url, {
|
|
94
|
+
method: 'PUT',
|
|
95
|
+
body: upload.body,
|
|
96
|
+
headers: uploadHeaders(upload, sourceMimeType),
|
|
97
|
+
}).catch((err) => {
|
|
98
|
+
console.error('Failed to upload file', { err, location: fileLocationForError(url), id, path });
|
|
99
|
+
throw err;
|
|
100
|
+
});
|
|
101
|
+
if (!res.ok) {
|
|
102
|
+
console.error('Failed to upload file', {
|
|
103
|
+
status: res.status,
|
|
104
|
+
statusText: res.statusText,
|
|
105
|
+
location: fileLocationForError(url),
|
|
106
|
+
id,
|
|
107
|
+
path,
|
|
108
|
+
});
|
|
109
|
+
throw new Error(`Failed to upload file ${source.name}: ${res.statusText}`);
|
|
110
|
+
}
|
|
111
|
+
return { id, path, mime_type: sourceMimeType, etag: unquoteEtag(res.headers.get('etag') ?? undefined) };
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=upload-content.js.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OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,SAAS,CAAC,EAAE,CAAC;AAC5G,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Runtime checks and errors of the upload transports, safe to load in any runtime. */
|
|
2
|
+
/** Whether this runtime has Node's `http` client (Node.js, and runtimes compatible with it such as Bun). */
|
|
3
|
+
export declare function hasNodeHttp(): boolean;
|
|
4
|
+
/** The error for a body whose size differs from its declared `Content-Length`. */
|
|
5
|
+
export declare class ContentLengthMismatchError extends Error {
|
|
6
|
+
readonly declared: number;
|
|
7
|
+
readonly actual: number;
|
|
8
|
+
readonly direction: 'short' | 'long';
|
|
9
|
+
constructor(declared: number, actual: number, direction: 'short' | 'long');
|
|
10
|
+
}
|
|
11
|
+
/** This client cannot use the upload session: an SDK it needs is not installed, or it does not know its protocol. */
|
|
12
|
+
export declare class UploadSessionUnavailableError extends Error {
|
|
13
|
+
/** What is missing, such as `the optional package @azure/storage-blob`. */
|
|
14
|
+
readonly requirement: string;
|
|
15
|
+
constructor(
|
|
16
|
+
/** What is missing, such as `the optional package @azure/storage-blob`. */
|
|
17
|
+
requirement: string, cause?: unknown);
|
|
18
|
+
}
|
|
19
|
+
/** The `Content-Length` in `headers`, in any letter case; undefined when absent or not a whole byte count. */
|
|
20
|
+
export declare function contentLengthHeader(headers: Record<string, string> | undefined): number | undefined;
|
|
21
|
+
//# sourceMappingURL=upload-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload-runtime.d.ts","sourceRoot":"","sources":["../../src/store/upload-runtime.ts"],"names":[],"mappings":"AAAA,uFAAuF;AAEvF,4GAA4G;AAC5G,wBAAgB,WAAW,IAAI,OAAO,CAErC;AAED,kFAAkF;AAClF,qBAAa,0BAA2B,SAAQ,KAAK;IAE7C,QAAQ,CAAC,QAAQ,EAAE,MAAM;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,SAAS,EAAE,OAAO,GAAG,MAAM;IAHxC,YACa,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,OAAO,GAAG,MAAM,EAQvC;CACJ;AAED,qHAAqH;AACrH,qBAAa,6BAA8B,SAAQ,KAAK;IAEhD,2EAA2E;IAC3E,QAAQ,CAAC,WAAW,EAAE,MAAM;IAFhC;IACI,2EAA2E;IAClE,WAAW,EAAE,MAAM,EAC5B,KAAK,CAAC,EAAE,OAAO,EAIlB;CACJ;AAED,8GAA8G;AAC9G,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAKnG"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Runtime checks and errors of the upload transports, safe to load in any runtime. */
|
|
2
|
+
/** Whether this runtime has Node's `http` client (Node.js, and runtimes compatible with it such as Bun). */
|
|
3
|
+
export function hasNodeHttp() {
|
|
4
|
+
return typeof process !== 'undefined' && typeof process.versions?.node === 'string';
|
|
5
|
+
}
|
|
6
|
+
/** The error for a body whose size differs from its declared `Content-Length`. */
|
|
7
|
+
export class ContentLengthMismatchError extends Error {
|
|
8
|
+
declared;
|
|
9
|
+
actual;
|
|
10
|
+
direction;
|
|
11
|
+
constructor(declared, actual, direction) {
|
|
12
|
+
super(direction === 'short'
|
|
13
|
+
? `Upload body ended after ${actual} bytes, short of its declared length of ${declared}`
|
|
14
|
+
: `Upload body ran past its declared length of ${declared} bytes`);
|
|
15
|
+
this.declared = declared;
|
|
16
|
+
this.actual = actual;
|
|
17
|
+
this.direction = direction;
|
|
18
|
+
this.name = 'ContentLengthMismatchError';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** This client cannot use the upload session: an SDK it needs is not installed, or it does not know its protocol. */
|
|
22
|
+
export class UploadSessionUnavailableError extends Error {
|
|
23
|
+
requirement;
|
|
24
|
+
constructor(
|
|
25
|
+
/** What is missing, such as `the optional package @azure/storage-blob`. */
|
|
26
|
+
requirement, cause) {
|
|
27
|
+
super(`Uploading in parts needs ${requirement}`, { cause });
|
|
28
|
+
this.requirement = requirement;
|
|
29
|
+
this.name = 'UploadSessionUnavailableError';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** The `Content-Length` in `headers`, in any letter case; undefined when absent or not a whole byte count. */
|
|
33
|
+
export function contentLengthHeader(headers) {
|
|
34
|
+
const entry = Object.entries(headers ?? {}).find(([name]) => name.toLowerCase() === 'content-length');
|
|
35
|
+
if (!entry || !/^\d+$/.test(entry[1].trim()))
|
|
36
|
+
return undefined;
|
|
37
|
+
const length = Number(entry[1].trim());
|
|
38
|
+
return Number.isSafeInteger(length) ? length : undefined;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=upload-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload-runtime.js","sourceRoot":"","sources":["../../src/store/upload-runtime.ts"],"names":[],"mappings":"AAAA,uFAAuF;AAEvF,4GAA4G;AAC5G,MAAM,UAAU,WAAW;IACvB,OAAO,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,OAAO,CAAC,QAAQ,EAAE,IAAI,KAAK,QAAQ,CAAC;AACxF,CAAC;AAED,kFAAkF;AAClF,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IAEpC,QAAQ;IACR,MAAM;IACN,SAAS;IAHtB,YACa,QAAgB,EAChB,MAAc,EACd,SAA2B;QAEpC,KAAK,CACD,SAAS,KAAK,OAAO;YACjB,CAAC,CAAC,2BAA2B,MAAM,2CAA2C,QAAQ,EAAE;YACxF,CAAC,CAAC,+CAA+C,QAAQ,QAAQ,CACxE,CAAC;wBARO,QAAQ;sBACR,MAAM;yBACN,SAAS;QAOlB,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC7C,CAAC;CACJ;AAED,qHAAqH;AACrH,MAAM,OAAO,6BAA8B,SAAQ,KAAK;IAGvC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