@vertesia/client 1.6.0-dev.20261019.172735Z → 1.7.0-dev.20261120.100641Z
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/ApiKeysApi.d.ts +4 -7
- package/lib/ApiKeysApi.d.ts.map +1 -1
- package/lib/ApiKeysApi.js +5 -4
- package/lib/ApiKeysApi.js.map +1 -1
- 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/EnvironmentsApi.d.ts +2 -2
- package/lib/EnvironmentsApi.d.ts.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 +6 -13
- package/lib/InteractionsApi.d.ts.map +1 -1
- package/lib/InteractionsApi.js +4 -24
- 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/RemoteMcpConnectionsApi.d.ts +5 -1
- package/lib/RemoteMcpConnectionsApi.d.ts.map +1 -1
- package/lib/RemoteMcpConnectionsApi.js +6 -2
- package/lib/RemoteMcpConnectionsApi.js.map +1 -1
- package/lib/RunsApi.d.ts +3 -2
- package/lib/RunsApi.d.ts.map +1 -1
- package/lib/RunsApi.js +3 -2
- package/lib/RunsApi.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 +57 -8
- package/lib/client.js.map +1 -1
- package/lib/execute.d.ts +16 -2
- package/lib/execute.d.ts.map +1 -1
- package/lib/execute.js +16 -3
- 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/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/nodejs/NodeStreamSource.d.ts +11 -1
- package/lib/nodejs/NodeStreamSource.d.ts.map +1 -1
- package/lib/nodejs/NodeStreamSource.js +56 -16
- package/lib/nodejs/NodeStreamSource.js.map +1 -1
- package/lib/store/AgentsApi.d.ts +3 -0
- package/lib/store/AgentsApi.d.ts.map +1 -1
- package/lib/store/AgentsApi.js +10 -1
- package/lib/store/AgentsApi.js.map +1 -1
- package/lib/store/ContentSourcesApi.d.ts +57 -0
- package/lib/store/ContentSourcesApi.d.ts.map +1 -0
- package/lib/store/ContentSourcesApi.js +92 -0
- package/lib/store/ContentSourcesApi.js.map +1 -0
- package/lib/store/CostApi.d.ts +9 -1
- package/lib/store/CostApi.d.ts.map +1 -1
- package/lib/store/CostApi.js +16 -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 -69
- package/lib/store/FilesApi.js.map +1 -1
- package/lib/store/IndexingApi.d.ts +0 -6
- package/lib/store/IndexingApi.d.ts.map +1 -1
- package/lib/store/IndexingApi.js +3 -17
- package/lib/store/IndexingApi.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 -7
- package/lib/store/ObjectsApi.d.ts.map +1 -1
- package/lib/store/ObjectsApi.js +25 -46
- 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 +17 -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/stream-termination.d.ts.map +1 -1
- package/lib/store/stream-termination.js +17 -16
- package/lib/store/stream-termination.js.map +1 -1
- 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/store/zeno-bulk.d.ts +9 -0
- package/lib/store/zeno-bulk.d.ts.map +1 -0
- package/lib/store/zeno-bulk.js +26 -0
- package/lib/store/zeno-bulk.js.map +1 -0
- package/lib/user-agent.d.ts +11 -0
- package/lib/user-agent.d.ts.map +1 -0
- package/lib/user-agent.js +35 -0
- package/lib/user-agent.js.map +1 -0
- package/lib/vertesia-client.js +10 -9
- package/lib/vertesia-client.js.map +1 -1
- package/package.json +38 -9
- package/src/AccountApi.ts +3 -0
- package/src/AccountRolesApi.ts +29 -0
- package/src/ApiKeysApi.ts +4 -12
- package/src/AppsApi.ts +58 -4
- package/src/AuditTrailApi.ts +11 -0
- package/src/EnvironmentsApi.ts +2 -2
- package/src/IamApi.ts +1 -1
- package/src/InteractionCatalogApi.ts +44 -1
- package/src/InteractionsApi.ts +11 -33
- package/src/OAuthClientsApi.ts +6 -0
- package/src/OAuthProvidersApi.ts +7 -2
- package/src/RemoteMcpConnectionsApi.ts +7 -3
- package/src/RunsApi.ts +7 -2
- package/src/StreamSource.ts +29 -0
- package/src/UsersApi.ts +10 -1
- package/src/client.ts +74 -8
- package/src/execute.ts +33 -4
- package/src/idempotency-key.ts +34 -0
- package/src/index.ts +1 -0
- package/src/nodejs/NodeStreamSource.ts +63 -24
- package/src/store/AgentsApi.ts +13 -1
- package/src/store/ContentSourcesApi.ts +135 -0
- package/src/store/CostApi.ts +24 -0
- package/src/store/DashboardApi.ts +93 -18
- package/src/store/DataApi.ts +14 -10
- package/src/store/FilesApi.ts +84 -72
- package/src/store/IndexingApi.ts +3 -18
- package/src/store/NotificationsApi.ts +103 -0
- package/src/store/ObjectsApi.ts +32 -51
- 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 +23 -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/stream-termination.ts +24 -24
- package/src/store/upload-body.ts +37 -0
- package/src/store/upload-content.ts +129 -0
- package/src/store/upload-runtime.ts +42 -0
- package/src/store/zeno-bulk.ts +30 -0
- package/src/user-agent.ts +41 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { StreamSource } from '../StreamSource.js';
|
|
2
|
+
|
|
3
|
+
/** What to send to upload a source: the body, and the declared length of a stream body. */
|
|
4
|
+
export interface UploadBody {
|
|
5
|
+
body: Blob | ReadableStream;
|
|
6
|
+
/** Sent as `Content-Length` with a stream body whose length is known; a `Blob` carries its own. */
|
|
7
|
+
contentLength?: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The request body for uploading a source to a signed URL.
|
|
12
|
+
*
|
|
13
|
+
* A `File` is sent as it is. A stream source with a {@link StreamSource.replayableBody} (e.g. a local file) sends
|
|
14
|
+
* that instead, so a retry re-reads it rather than needing a buffered copy; its stream is cancelled, which releases
|
|
15
|
+
* what the stream holds, such as a file descriptor. Any other stream source sends its stream, with its
|
|
16
|
+
* {@link StreamSource.size} when known.
|
|
17
|
+
*/
|
|
18
|
+
export async function getUploadBody(source: StreamSource | File): Promise<UploadBody> {
|
|
19
|
+
if (!(source instanceof StreamSource)) return { body: source };
|
|
20
|
+
const body = await source.replayableBody();
|
|
21
|
+
if (!body) return { body: source.stream, contentLength: source.size };
|
|
22
|
+
await source.stream.cancel().catch(() => undefined);
|
|
23
|
+
return { body };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Headers for an upload: the content type, and `Content-Length` when the body declares one. */
|
|
27
|
+
export function uploadHeaders(upload: UploadBody, contentType: string | undefined): Record<string, string> | undefined {
|
|
28
|
+
const headers: Record<string, string> = {};
|
|
29
|
+
if (contentType) headers['Content-Type'] = contentType;
|
|
30
|
+
if (upload.contentLength !== undefined) headers['Content-Length'] = String(upload.contentLength);
|
|
31
|
+
return Object.keys(headers).length > 0 ? headers : undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** An ETag without the quotes HTTP puts around it (RFC 9110), as the upload methods return it. */
|
|
35
|
+
export function unquoteEtag(etag: string | undefined): string | undefined {
|
|
36
|
+
return etag?.replace(/^"(.*)"$/, '$1');
|
|
37
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
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 type { CreateUploadSessionPayload, GetFileUrlResponse } from '@vertesia/common';
|
|
6
|
+
import type { StreamSource } from '../StreamSource.js';
|
|
7
|
+
import { partsAsUploadBody, planUpload, type UploadPlan, uploadInParts } from './chunked-upload.js';
|
|
8
|
+
import type { FilesApi } from './FilesApi.js';
|
|
9
|
+
import { fetchSignedUrl } from './signed-url.js';
|
|
10
|
+
import { type UploadBody, unquoteEtag, uploadHeaders } from './upload-body.js';
|
|
11
|
+
import { UploadSessionUnavailableError } from './upload-runtime.js';
|
|
12
|
+
import { resolveUploadMimeType } from './uploadMimeType.js';
|
|
13
|
+
|
|
14
|
+
/** A location without its query string or fragment, which hold a signed URL's credentials. */
|
|
15
|
+
export function fileLocationForError(location: string): string {
|
|
16
|
+
try {
|
|
17
|
+
const url = new URL(location);
|
|
18
|
+
return `${url.protocol}//${url.host}${url.pathname}`;
|
|
19
|
+
} catch {
|
|
20
|
+
return location.split(/[?#]/, 1)[0] || 'unknown file';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** A copy of an error safe to log: every URL in its message is cut to its location. */
|
|
25
|
+
export function sanitizedErrorCause(error: unknown): Error | undefined {
|
|
26
|
+
if (!(error instanceof Error)) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
const message = error.message.replace(/https?:\/\/[^\s)\]}>"']+/g, (url) => fileLocationForError(url));
|
|
30
|
+
const cause = new Error(message);
|
|
31
|
+
cause.name = error.name;
|
|
32
|
+
return cause;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The statuses of a server without upload sessions (404, or 405 where another route matches the path), or whose
|
|
37
|
+
* storage has none (501).
|
|
38
|
+
*/
|
|
39
|
+
const NO_UPLOAD_SESSION_STATUSES: ReadonlySet<number> = new Set([404, 405, 501]);
|
|
40
|
+
|
|
41
|
+
/** The stream of a plan, which a failed upload must cancel to release what it holds (a socket, a file). */
|
|
42
|
+
function planStream(plan: UploadPlan): ReadableStream | undefined {
|
|
43
|
+
const body = plan.kind === 'parts' ? plan.parts.body : plan.upload.body;
|
|
44
|
+
return body instanceof ReadableStream ? body : undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Upload a source to the file `request` names: in one signed PUT, or, for a stream source longer than one part in
|
|
49
|
+
* Node.js, in parts through an upload session (see `chunked-upload.ts`). On failure the source's stream is cancelled.
|
|
50
|
+
*
|
|
51
|
+
* @param signUpload the signed PUT URL to use, when the caller already has one or signs it another way
|
|
52
|
+
* @param fallbackMimeType the content type when neither the source nor the server names one
|
|
53
|
+
*/
|
|
54
|
+
export async function uploadContent(
|
|
55
|
+
files: FilesApi,
|
|
56
|
+
source: StreamSource | File,
|
|
57
|
+
request: CreateUploadSessionPayload,
|
|
58
|
+
signUpload: () => Promise<GetFileUrlResponse> = () => files.getUploadUrl(request),
|
|
59
|
+
fallbackMimeType?: string,
|
|
60
|
+
): Promise<{ id: string; path: string; mime_type?: string; etag?: string }> {
|
|
61
|
+
const plan = await planUpload(source);
|
|
62
|
+
try {
|
|
63
|
+
return await sendPlan(files, source, request, plan, signUpload, fallbackMimeType);
|
|
64
|
+
} catch (err: unknown) {
|
|
65
|
+
// A stream already being sent is locked, and its sender cancels it; this one was never read whole.
|
|
66
|
+
await planStream(plan)
|
|
67
|
+
?.cancel(err)
|
|
68
|
+
.catch(() => undefined);
|
|
69
|
+
throw err;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function sendPlan(
|
|
74
|
+
files: FilesApi,
|
|
75
|
+
source: StreamSource | File,
|
|
76
|
+
request: CreateUploadSessionPayload,
|
|
77
|
+
plan: UploadPlan,
|
|
78
|
+
signUpload: () => Promise<GetFileUrlResponse>,
|
|
79
|
+
fallbackMimeType: string | undefined,
|
|
80
|
+
): Promise<{ id: string; path: string; mime_type?: string; etag?: string }> {
|
|
81
|
+
let upload: UploadBody;
|
|
82
|
+
if (plan.kind === 'parts') {
|
|
83
|
+
const session = await files.createUploadSession(request).catch((err: unknown) => {
|
|
84
|
+
if (err instanceof RequestError && NO_UPLOAD_SESSION_STATUSES.has(err.status)) return undefined;
|
|
85
|
+
throw err;
|
|
86
|
+
});
|
|
87
|
+
if (!session) {
|
|
88
|
+
console.warn(`Upload sessions are not available; uploading ${request.name} in a single request`);
|
|
89
|
+
upload = partsAsUploadBody(plan.parts);
|
|
90
|
+
} else {
|
|
91
|
+
try {
|
|
92
|
+
const etag = await uploadInParts(files, session, plan.parts);
|
|
93
|
+
const mime_type = resolveUploadMimeType(source.type, session.mime_type) || fallbackMimeType;
|
|
94
|
+
return { id: session.id, path: session.path, mime_type, etag };
|
|
95
|
+
} catch (err: unknown) {
|
|
96
|
+
if (!(err instanceof UploadSessionUnavailableError)) {
|
|
97
|
+
console.error('Failed to upload file', { err: sanitizedErrorCause(err), id: session.id });
|
|
98
|
+
throw err;
|
|
99
|
+
}
|
|
100
|
+
console.warn(`${err.message}; uploading ${session.path} in a single request instead`);
|
|
101
|
+
upload = partsAsUploadBody(plan.parts);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
upload = plan.upload;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const { url, id, path, mime_type } = await signUpload();
|
|
109
|
+
const sourceMimeType = resolveUploadMimeType(source.type, mime_type) || fallbackMimeType;
|
|
110
|
+
const res = await fetchSignedUrl(url, {
|
|
111
|
+
method: 'PUT',
|
|
112
|
+
body: upload.body,
|
|
113
|
+
headers: uploadHeaders(upload, sourceMimeType),
|
|
114
|
+
}).catch((err) => {
|
|
115
|
+
console.error('Failed to upload file', { err, location: fileLocationForError(url), id, path });
|
|
116
|
+
throw err;
|
|
117
|
+
});
|
|
118
|
+
if (!res.ok) {
|
|
119
|
+
console.error('Failed to upload file', {
|
|
120
|
+
status: res.status,
|
|
121
|
+
statusText: res.statusText,
|
|
122
|
+
location: fileLocationForError(url),
|
|
123
|
+
id,
|
|
124
|
+
path,
|
|
125
|
+
});
|
|
126
|
+
throw new Error(`Failed to upload file ${source.name}: ${res.statusText}`);
|
|
127
|
+
}
|
|
128
|
+
return { id, path, mime_type: sourceMimeType, etag: unquoteEtag(res.headers.get('etag') ?? undefined) };
|
|
129
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** Runtime checks and errors of the upload transports, safe to load in any runtime. */
|
|
2
|
+
|
|
3
|
+
/** Whether this runtime has Node's `http` client (Node.js, and runtimes compatible with it such as Bun). */
|
|
4
|
+
export function hasNodeHttp(): boolean {
|
|
5
|
+
return typeof process !== 'undefined' && typeof process.versions?.node === 'string';
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** The error for a body whose size differs from its declared `Content-Length`. */
|
|
9
|
+
export class ContentLengthMismatchError extends Error {
|
|
10
|
+
constructor(
|
|
11
|
+
readonly declared: number,
|
|
12
|
+
readonly actual: number,
|
|
13
|
+
readonly direction: 'short' | 'long',
|
|
14
|
+
) {
|
|
15
|
+
super(
|
|
16
|
+
direction === 'short'
|
|
17
|
+
? `Upload body ended after ${actual} bytes, short of its declared length of ${declared}`
|
|
18
|
+
: `Upload body ran past its declared length of ${declared} bytes`,
|
|
19
|
+
);
|
|
20
|
+
this.name = 'ContentLengthMismatchError';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** This client cannot use the upload session: an SDK it needs is not installed, or it does not know its protocol. */
|
|
25
|
+
export class UploadSessionUnavailableError extends Error {
|
|
26
|
+
constructor(
|
|
27
|
+
/** What is missing, such as `the optional package @azure/storage-blob`. */
|
|
28
|
+
readonly requirement: string,
|
|
29
|
+
cause?: unknown,
|
|
30
|
+
) {
|
|
31
|
+
super(`Uploading in parts needs ${requirement}`, { cause });
|
|
32
|
+
this.name = 'UploadSessionUnavailableError';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The `Content-Length` in `headers`, in any letter case; undefined when absent or not a whole byte count. */
|
|
37
|
+
export function contentLengthHeader(headers: Record<string, string> | undefined): number | undefined {
|
|
38
|
+
const entry = Object.entries(headers ?? {}).find(([name]) => name.toLowerCase() === 'content-length');
|
|
39
|
+
if (!entry || !/^\d+$/.test(entry[1].trim())) return undefined;
|
|
40
|
+
const length = Number(entry[1].trim());
|
|
41
|
+
return Number.isSafeInteger(length) ? length : undefined;
|
|
42
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
type RuntimeProcess = {
|
|
2
|
+
env?: Record<string, string | undefined>;
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
/** The ZENO_BULK_URL environment variable, in a runtime that has one. */
|
|
6
|
+
function getRuntimeZenoBulkUrl() {
|
|
7
|
+
const runtimeProcess = (globalThis as typeof globalThis & { process?: RuntimeProcess }).process;
|
|
8
|
+
return runtimeProcess?.env?.ZENO_BULK_URL || undefined;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The base URL of zeno-bulk, the service behind the bulk export and reindex endpoints, for a store base URL.
|
|
13
|
+
* - ZENO_BULK_URL, when the runtime sets it: a local stack that runs its own zeno-bulk, or none, points it there.
|
|
14
|
+
* - A store on localhost: the dev1 zeno-bulk, which serves the database a default local stack uses.
|
|
15
|
+
* - A dev-branch store, whose host names zeno-server: the matching zeno-bulk host.
|
|
16
|
+
* - Any other store: its own domain, whose load balancer routes the bulk paths to zeno-bulk.
|
|
17
|
+
*/
|
|
18
|
+
export function zenoBulkBaseUrl(storeBaseUrl: string): string {
|
|
19
|
+
const override = getRuntimeZenoBulkUrl();
|
|
20
|
+
if (override) {
|
|
21
|
+
return override.replace(/\/+$/, '');
|
|
22
|
+
}
|
|
23
|
+
if (storeBaseUrl.includes('localhost:') || storeBaseUrl.includes('127.0.0.1:')) {
|
|
24
|
+
return 'https://zeno-bulk-dev-main.api.dev1.vertesia.io';
|
|
25
|
+
}
|
|
26
|
+
if (storeBaseUrl.includes('zeno-server')) {
|
|
27
|
+
return storeBaseUrl.replace(/zeno-server/, 'zeno-bulk');
|
|
28
|
+
}
|
|
29
|
+
return storeBaseUrl;
|
|
30
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import packageMetadata from '../package.json' with { type: 'json' };
|
|
2
|
+
|
|
3
|
+
/** Product token every Vertesia SDK sends first in its User-Agent: `vertesia-client-<language>/<version>`. */
|
|
4
|
+
export const CLIENT_USER_AGENT_PRODUCT = `vertesia-client-ts/${packageMetadata.version}`;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The server-side JavaScript runtime, as `<name>/<version>`, or undefined in a browser.
|
|
8
|
+
*/
|
|
9
|
+
function serverRuntime(): string | undefined {
|
|
10
|
+
const runtime = globalThis as typeof globalThis & {
|
|
11
|
+
Deno?: { version?: { deno?: string } };
|
|
12
|
+
process?: { versions?: { bun?: string; node?: string } };
|
|
13
|
+
window?: unknown;
|
|
14
|
+
};
|
|
15
|
+
if (typeof runtime.window !== 'undefined') {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
const versions = runtime.process?.versions;
|
|
19
|
+
if (typeof versions?.bun === 'string') {
|
|
20
|
+
return `bun/${versions.bun}`;
|
|
21
|
+
}
|
|
22
|
+
if (typeof runtime.Deno?.version?.deno === 'string') {
|
|
23
|
+
return `deno/${runtime.Deno.version.deno}`;
|
|
24
|
+
}
|
|
25
|
+
if (typeof versions?.node === 'string') {
|
|
26
|
+
return `node/${versions.node}`;
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The User-Agent header identifying this SDK and its version, e.g.
|
|
33
|
+
* `vertesia-client-ts/1.7.0 node/22.11.0`.
|
|
34
|
+
*
|
|
35
|
+
* Empty in a browser: the browser owns its User-Agent, and any other custom header would add a
|
|
36
|
+
* CORS preflight requirement that servers on an older release do not allow.
|
|
37
|
+
*/
|
|
38
|
+
export function clientUserAgentHeaders(): Record<string, string> {
|
|
39
|
+
const runtime = serverRuntime();
|
|
40
|
+
return runtime ? { 'user-agent': `${CLIENT_USER_AGENT_PRODUCT} ${runtime}` } : {};
|
|
41
|
+
}
|