@nodaro/sdk 2.75.0 → 2.76.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-3WQ4UW3C.js +3 -0
- package/dist/chunk-3WQ4UW3C.js.map +1 -0
- package/dist/{chunk-IJAJTVEW.js → chunk-4Q3XZE5O.js} +17 -3
- package/dist/chunk-4Q3XZE5O.js.map +1 -0
- package/dist/{chunk-MQQA2E6J.cjs → chunk-6NIKAVI3.cjs} +2 -2
- package/dist/chunk-6NIKAVI3.cjs.map +1 -0
- package/dist/{chunk-YE6X5BQ2.js → chunk-6TR7QXSX.js} +3 -3
- package/dist/{chunk-YE6X5BQ2.js.map → chunk-6TR7QXSX.js.map} +1 -1
- package/dist/chunk-6YWXKDAY.cjs +190 -0
- package/dist/chunk-6YWXKDAY.cjs.map +1 -0
- package/dist/chunk-7NTMMIPC.cjs +4 -0
- package/dist/chunk-7NTMMIPC.cjs.map +1 -0
- package/dist/{chunk-CLBLAWH3.cjs → chunk-7PMOXQEO.cjs} +9 -9
- package/dist/{chunk-CLBLAWH3.cjs.map → chunk-7PMOXQEO.cjs.map} +1 -1
- package/dist/{chunk-BETFYVOR.cjs → chunk-7XKVBFKM.cjs} +5 -5
- package/dist/{chunk-BETFYVOR.cjs.map → chunk-7XKVBFKM.cjs.map} +1 -1
- package/dist/{chunk-HNUCPUIX.js → chunk-AOHDYZSZ.js} +3 -3
- package/dist/{chunk-HNUCPUIX.js.map → chunk-AOHDYZSZ.js.map} +1 -1
- package/dist/{chunk-TKSQCF2X.js → chunk-CSNYBGHP.js} +2 -2
- package/dist/chunk-CSNYBGHP.js.map +1 -0
- package/dist/{chunk-4AD3CBDK.cjs → chunk-E2NMFQNY.cjs} +18 -2
- package/dist/chunk-E2NMFQNY.cjs.map +1 -0
- package/dist/{chunk-O6YXG4BM.js → chunk-FOC4VPGK.js} +4 -4
- package/dist/{chunk-O6YXG4BM.js.map → chunk-FOC4VPGK.js.map} +1 -1
- package/dist/{chunk-DNONFO6S.js → chunk-GWL4O3J2.js} +3 -3
- package/dist/{chunk-DNONFO6S.js.map → chunk-GWL4O3J2.js.map} +1 -1
- package/dist/{chunk-GU3YOOCK.cjs → chunk-IO7NEEZZ.cjs} +20 -18
- package/dist/chunk-IO7NEEZZ.cjs.map +1 -0
- package/dist/chunk-K53JD2ZC.js +187 -0
- package/dist/chunk-K53JD2ZC.js.map +1 -0
- package/dist/{chunk-4GSUIOTT.cjs → chunk-KNBZFWVO.cjs} +22 -22
- package/dist/{chunk-4GSUIOTT.cjs.map → chunk-KNBZFWVO.cjs.map} +1 -1
- package/dist/{chunk-VGY3WBNY.js → chunk-OO4AKYUN.js} +3 -3
- package/dist/{chunk-VGY3WBNY.js.map → chunk-OO4AKYUN.js.map} +1 -1
- package/dist/{chunk-CCXY4ZJM.js → chunk-SA7VTT7C.js} +3 -3
- package/dist/{chunk-CCXY4ZJM.js.map → chunk-SA7VTT7C.js.map} +1 -1
- package/dist/{chunk-R427LDUV.cjs → chunk-SGVJUVFD.cjs} +5 -5
- package/dist/{chunk-R427LDUV.cjs.map → chunk-SGVJUVFD.cjs.map} +1 -1
- package/dist/{chunk-QSPTSAEI.cjs → chunk-SGVTZ2J5.cjs} +27 -24
- package/dist/chunk-SGVTZ2J5.cjs.map +1 -0
- package/dist/{chunk-YUY56PT7.js → chunk-TZFZDEWI.js} +20 -19
- package/dist/chunk-TZFZDEWI.js.map +1 -0
- package/dist/{chunk-UX5SMJEI.js → chunk-U2F6IHHY.js} +18 -15
- package/dist/chunk-U2F6IHHY.js.map +1 -0
- package/dist/{chunk-C5GFDCK2.cjs → chunk-UKITRPXF.cjs} +2 -2
- package/dist/{chunk-C5GFDCK2.cjs.map → chunk-UKITRPXF.cjs.map} +1 -1
- package/dist/{chunk-VTHHSO2K.cjs → chunk-UPWAODYT.cjs} +4 -4
- package/dist/{chunk-VTHHSO2K.cjs.map → chunk-UPWAODYT.cjs.map} +1 -1
- package/dist/{chunk-R5DTFY73.js → chunk-WY5QIOO4.js} +2 -2
- package/dist/{chunk-R5DTFY73.js.map → chunk-WY5QIOO4.js.map} +1 -1
- package/dist/{chunk-EJJIA765.cjs → chunk-XWPYN2VX.cjs} +5 -5
- package/dist/{chunk-EJJIA765.cjs.map → chunk-XWPYN2VX.cjs.map} +1 -1
- package/dist/{chunk-SZ67PDKE.js → chunk-YQ2Q4OM3.js} +3 -3
- package/dist/{chunk-SZ67PDKE.js.map → chunk-YQ2Q4OM3.js.map} +1 -1
- package/dist/{chunk-TQLOD7OL.cjs → chunk-ZJM5YBXY.cjs} +4 -4
- package/dist/{chunk-TQLOD7OL.cjs.map → chunk-ZJM5YBXY.cjs.map} +1 -1
- package/dist/entries/cast-swap.cjs +2 -2
- package/dist/entries/cast-swap.d.cts +2 -623
- package/dist/entries/cast-swap.d.ts +2 -623
- package/dist/entries/cast-swap.js +1 -1
- package/dist/entries/characters.d.cts +1 -1
- package/dist/entries/characters.d.ts +1 -1
- package/dist/entries/client.cjs +18 -18
- package/dist/entries/client.d.cts +7 -5
- package/dist/entries/client.d.ts +7 -5
- package/dist/entries/client.js +13 -13
- package/dist/entries/copilot.cjs +4 -4
- package/dist/entries/copilot.js +3 -3
- package/dist/entries/core.cjs +6 -6
- package/dist/entries/core.js +2 -2
- package/dist/entries/creatures.d.cts +1 -1
- package/dist/entries/creatures.d.ts +1 -1
- package/dist/entries/edit.cjs +7 -7
- package/dist/entries/edit.js +2 -2
- package/dist/entries/errors.cjs +36 -28
- package/dist/entries/errors.d.cts +24 -1
- package/dist/entries/errors.d.ts +24 -1
- package/dist/entries/errors.js +1 -1
- package/dist/entries/jobs.cjs +2 -2
- package/dist/entries/jobs.d.cts +4 -4
- package/dist/entries/jobs.d.ts +4 -4
- package/dist/entries/jobs.js +1 -1
- package/dist/entries/locations.d.cts +1 -1
- package/dist/entries/locations.d.ts +1 -1
- package/dist/entries/media.cjs +4 -4
- package/dist/entries/media.d.cts +1 -1
- package/dist/entries/media.d.ts +1 -1
- package/dist/entries/media.js +3 -3
- package/dist/entries/nodes.cjs +3 -3
- package/dist/entries/nodes.d.cts +1 -1
- package/dist/entries/nodes.d.ts +1 -1
- package/dist/entries/nodes.js +2 -2
- package/dist/entries/objects.d.cts +1 -1
- package/dist/entries/objects.d.ts +1 -1
- package/dist/entries/scene3d.d.cts +2 -2
- package/dist/entries/scene3d.d.ts +2 -2
- package/dist/entries/studio.cjs +5 -5
- package/dist/entries/studio.js +2 -2
- package/dist/entries/trends.cjs +2 -2
- package/dist/entries/trends.d.cts +26 -18
- package/dist/entries/trends.d.ts +26 -18
- package/dist/entries/trends.js +1 -1
- package/dist/entries/uploads.cjs +7 -2
- package/dist/entries/uploads.d.cts +60 -1
- package/dist/entries/uploads.d.ts +60 -1
- package/dist/entries/uploads.js +2 -1
- package/dist/entries/video-remake.cjs +13 -0
- package/dist/entries/video-remake.cjs.map +1 -0
- package/dist/entries/video-remake.d.cts +4 -0
- package/dist/entries/video-remake.d.ts +4 -0
- package/dist/entries/video-remake.js +4 -0
- package/dist/entries/video-remake.js.map +1 -0
- package/dist/index.cjs +78 -61
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +14 -13
- package/dist/{nodes-DtSP2yna.d.cts → nodes-BHtjh6gl.d.cts} +2 -2
- package/dist/{nodes-HKVmoCnt.d.ts → nodes-BaRqRB2Z.d.ts} +2 -2
- package/dist/video-remake-C-KR7YtT.d.ts +676 -0
- package/dist/video-remake-DTuCyhd9.d.cts +676 -0
- package/package.json +7 -2
- package/dist/chunk-4AD3CBDK.cjs.map +0 -1
- package/dist/chunk-F6KAMECM.cjs +0 -72
- package/dist/chunk-F6KAMECM.cjs.map +0 -1
- package/dist/chunk-GU3YOOCK.cjs.map +0 -1
- package/dist/chunk-IJAJTVEW.js.map +0 -1
- package/dist/chunk-MQQA2E6J.cjs.map +0 -1
- package/dist/chunk-QSPTSAEI.cjs.map +0 -1
- package/dist/chunk-TKSQCF2X.js.map +0 -1
- package/dist/chunk-UX5SMJEI.js.map +0 -1
- package/dist/chunk-YEOK5A5H.js +0 -70
- package/dist/chunk-YEOK5A5H.js.map +0 -1
- package/dist/chunk-YUY56PT7.js.map +0 -1
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { NodaroError, LargeUploadUnavailableError } from './chunk-4Q3XZE5O.js';
|
|
2
|
+
|
|
3
|
+
// src/resources/uploads.ts
|
|
4
|
+
var UPLOAD_MAX_BYTES = 500 * 1024 * 1024;
|
|
5
|
+
var PART_ATTEMPTS = 3;
|
|
6
|
+
var COMPLETE_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
7
|
+
var UploadsResource = class {
|
|
8
|
+
constructor(client) {
|
|
9
|
+
this.client = client;
|
|
10
|
+
}
|
|
11
|
+
client;
|
|
12
|
+
/**
|
|
13
|
+
* Upload one file (`POST /v1/upload`, multipart — the file rides the `file`
|
|
14
|
+
* field). The SDK's `request` detects the `FormData` body and lets the
|
|
15
|
+
* runtime set the multipart boundary. Returns the persisted asset's public
|
|
16
|
+
* URL + storage metadata (unwraps the `{ data }` envelope). Throws
|
|
17
|
+
* `StorageExceededError` (413) over the storage cap and the SDK's other typed
|
|
18
|
+
* errors on the usual statuses.
|
|
19
|
+
*/
|
|
20
|
+
async upload(file) {
|
|
21
|
+
return this.uploadMultipart(file);
|
|
22
|
+
}
|
|
23
|
+
async uploadMultipart(file, filename, signal) {
|
|
24
|
+
const form = new FormData();
|
|
25
|
+
if (filename !== void 0) form.append("file", file, filename);
|
|
26
|
+
else form.append("file", file);
|
|
27
|
+
const res = await this.client.request(
|
|
28
|
+
"POST",
|
|
29
|
+
"/v1/upload",
|
|
30
|
+
{ body: form, ...signal ? { signal } : {} }
|
|
31
|
+
);
|
|
32
|
+
return res.data;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Upload a file of any size, choosing the lane by size:
|
|
36
|
+
*
|
|
37
|
+
* - **{@link UPLOAD_MAX_BYTES} (500 MB) or less:** exactly {@link upload}
|
|
38
|
+
* (`POST /v1/upload`) — the path every file of that size takes today, with
|
|
39
|
+
* everything it does on the server (faststart, HEIC conversion, upload
|
|
40
|
+
* policies, thumbnails). The large-upload lane is never touched.
|
|
41
|
+
* - **Bigger (video or audio only):** the bytes go straight from here to the
|
|
42
|
+
* platform's object storage in parts (`POST /v1/uploads/large/start` → one
|
|
43
|
+
* `PUT` per part → `POST /v1/uploads/large/complete`), never through the
|
|
44
|
+
* API server. What limits such a file is length: one longer than 30
|
|
45
|
+
* minutes is refused once it has arrived, with `MediaTooLongError` (the
|
|
46
|
+
* stored copy is removed and nothing counts against storage).
|
|
47
|
+
*
|
|
48
|
+
* Returns the same result as {@link upload}. Parts are sent `concurrency` at
|
|
49
|
+
* a time (default 3); a part that fails is tried twice more before the
|
|
50
|
+
* upload fails. `onProgress(sentBytes, totalBytes)` is called as parts
|
|
51
|
+
* finish (once at the end on the small path). Aborting `signal`, or any
|
|
52
|
+
* failure, aborts the upload on the server (best-effort).
|
|
53
|
+
*
|
|
54
|
+
* A file over 500 MB on a deployment without the lane — one that checks every
|
|
55
|
+
* upload's bytes (409 `large_upload_unavailable`), or an older server (404) —
|
|
56
|
+
* throws `LargeUploadUnavailableError`: `POST /v1/upload` would refuse it
|
|
57
|
+
* anyway. Throws `StorageExceededError` (413) when the file does not fit in
|
|
58
|
+
* the account's storage, and the SDK's other typed errors on the usual
|
|
59
|
+
* statuses.
|
|
60
|
+
*
|
|
61
|
+
* In a browser, storage must allow cross-origin `PUT` from the page's origin
|
|
62
|
+
* for the large lane (the platform's own deployments do).
|
|
63
|
+
*/
|
|
64
|
+
async uploadLarge(file, options = {}) {
|
|
65
|
+
const filename = options.filename ?? (file.name && file.name.length > 0 ? file.name : "upload");
|
|
66
|
+
const signal = options.signal;
|
|
67
|
+
if (file.size <= UPLOAD_MAX_BYTES) {
|
|
68
|
+
const result = await this.uploadMultipart(file, filename, signal);
|
|
69
|
+
options.onProgress?.(file.size, file.size);
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
let started;
|
|
73
|
+
try {
|
|
74
|
+
started = await this.client.request("POST", "/v1/uploads/large/start", {
|
|
75
|
+
body: { filename, mimeType: file.type || "application/octet-stream", sizeBytes: file.size },
|
|
76
|
+
...signal ? { signal } : {}
|
|
77
|
+
});
|
|
78
|
+
} catch (err) {
|
|
79
|
+
if (err instanceof NodaroError && err.status === 404) throw new LargeUploadUnavailableError(void 0, 404);
|
|
80
|
+
throw err;
|
|
81
|
+
}
|
|
82
|
+
const { token, partSize, partUrls } = started;
|
|
83
|
+
try {
|
|
84
|
+
await this.sendParts(file, partSize, partUrls, options);
|
|
85
|
+
const res = await this.client.request("POST", "/v1/uploads/large/complete", {
|
|
86
|
+
body: { token },
|
|
87
|
+
timeoutMs: COMPLETE_TIMEOUT_MS,
|
|
88
|
+
...signal ? { signal } : {}
|
|
89
|
+
});
|
|
90
|
+
return res.data;
|
|
91
|
+
} catch (err) {
|
|
92
|
+
await this.client.request("POST", "/v1/uploads/large/abort", { body: { token } }).catch(() => void 0);
|
|
93
|
+
throw err;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* PUT every part, `concurrency` at a time, each tried up to
|
|
98
|
+
* {@link PART_ATTEMPTS} times. Each part is EXACTLY `partSize` bytes (the
|
|
99
|
+
* last one the remainder): its URL has that length signed in, so storage
|
|
100
|
+
* refuses any other. The runtime sets Content-Length from the slice itself.
|
|
101
|
+
*/
|
|
102
|
+
async sendParts(file, partSize, partUrls, options) {
|
|
103
|
+
const total = file.size;
|
|
104
|
+
const concurrency = Math.max(1, Math.floor(options.concurrency ?? 3));
|
|
105
|
+
let next = 0;
|
|
106
|
+
let sent = 0;
|
|
107
|
+
let failed;
|
|
108
|
+
const worker = async () => {
|
|
109
|
+
while (failed === void 0 && next < partUrls.length) {
|
|
110
|
+
const index = next++;
|
|
111
|
+
const start = index * partSize;
|
|
112
|
+
const part = file.slice(start, Math.min(start + partSize, total));
|
|
113
|
+
try {
|
|
114
|
+
await this.putPart(partUrls[index], part, index + 1, options.signal);
|
|
115
|
+
} catch (err) {
|
|
116
|
+
failed ??= err;
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
sent += part.size;
|
|
120
|
+
options.onProgress?.(sent, total);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, partUrls.length) }, () => worker()));
|
|
124
|
+
if (failed !== void 0) throw failed;
|
|
125
|
+
}
|
|
126
|
+
async putPart(url, part, partNumber, signal) {
|
|
127
|
+
let lastStatus = 0;
|
|
128
|
+
for (let attempt = 1; attempt <= PART_ATTEMPTS; attempt++) {
|
|
129
|
+
signal?.throwIfAborted();
|
|
130
|
+
try {
|
|
131
|
+
const res = await this.client.fetch(url, { method: "PUT", body: part, ...signal ? { signal } : {} });
|
|
132
|
+
if (res.ok) return;
|
|
133
|
+
lastStatus = res.status;
|
|
134
|
+
if (res.status >= 400 && res.status < 500 && res.status !== 408 && res.status !== 429) break;
|
|
135
|
+
} catch (err) {
|
|
136
|
+
if (signal?.aborted) throw err;
|
|
137
|
+
lastStatus = 0;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
throw new NodaroError(`Uploading part ${partNumber} failed${lastStatus ? ` (HTTP ${lastStatus})` : ""}`, "upload_part_failed", lastStatus);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Copy a picture from a web address into your storage
|
|
144
|
+
* (`POST /v1/media/import-url`, body `{ url }`). The platform fetches it
|
|
145
|
+
* (http(s) only, never a private address, up to 20 MB), keeps it only if it
|
|
146
|
+
* decodes as an image (JPEG, PNG, WebP, GIF; HEIC/HEIF and AVIF are
|
|
147
|
+
* converted to JPEG or PNG), and stores it as an upload of yours, so its address serves
|
|
148
|
+
* the pixels to the browser (a canvas can read it). Returns the stored
|
|
149
|
+
* picture (unwraps the `{ data }` envelope).
|
|
150
|
+
*
|
|
151
|
+
* Throws `StorageExceededError` on a 413, its `reason` telling the two
|
|
152
|
+
* apart: `storage_limit_exceeded` is a full storage (the quota is in
|
|
153
|
+
* `details` — `usedBytes`, `quotaBytes`, `remainingBytes`, `tier`), and
|
|
154
|
+
* `file_too_large` a picture over 20 MB. Throws a `NodaroError` with `code`
|
|
155
|
+
* `validation_error` (400: not an http(s) address, or not an image) or
|
|
156
|
+
* `fetch_failed` (422: the address could not be reached or answered with an
|
|
157
|
+
* error).
|
|
158
|
+
*
|
|
159
|
+
* An import of a link runs the platform's content rights check: pass the
|
|
160
|
+
* `confirmationId` from `contentRights.confirm({ url })` when the deployment
|
|
161
|
+
* requires one (`403 rights_confirmation_required` otherwise). A site an
|
|
162
|
+
* administrator disabled answers `403 import_source_disabled`, and a
|
|
163
|
+
* deployment that turned link imports off answers `403 link_imports_disabled`
|
|
164
|
+
* for a link to another site (a file of the deployment's own storage is still
|
|
165
|
+
* imported as before).
|
|
166
|
+
*/
|
|
167
|
+
async importUrl(url, options = {}) {
|
|
168
|
+
const res = await this.client.request("POST", "/v1/media/import-url", {
|
|
169
|
+
body: { url, ...options.confirmationId ? { confirmationId: options.confirmationId } : {} }
|
|
170
|
+
});
|
|
171
|
+
return res.data;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Store a JSON document (`POST /v1/upload-json`, up to 25 MB) and get its
|
|
175
|
+
* public URL — e.g. an image editor's design state, passed to
|
|
176
|
+
* `client.jobs.fromUpload` as `editStateUrl` so the edit can be reopened.
|
|
177
|
+
* The URL is unguessable but public: never store a secret in it. Creates no
|
|
178
|
+
* library item.
|
|
179
|
+
*/
|
|
180
|
+
uploadJson(json) {
|
|
181
|
+
return this.client.request("POST", "/v1/upload-json", { body: json });
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
export { UPLOAD_MAX_BYTES, UploadsResource };
|
|
186
|
+
//# sourceMappingURL=chunk-K53JD2ZC.js.map
|
|
187
|
+
//# sourceMappingURL=chunk-K53JD2ZC.js.map
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AC3B,QAAA,UAAA,GAAa,CAAA;AAAA,MACf;AAAA,IACF;AACA,IAAA,MAAM,IAAI,WAAA,CAAY,CAAA,eAAA,EAAkB,UAAU,CAAA,OAAA,EAAU,UAAA,GAAa,CAAA,OAAA,EAAU,UAAU,CAAA,CAAA,CAAA,GAAM,EAAE,CAAA,CAAA,EAAI,oBAAA,EAAsB,UAAU,CAAA;AAAA,EAC3I;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA2BA,MAAM,SAAA,CAAU,GAAA,EAAa,OAAA,GAAuC,EAAC,EAA6B;AAChG,IAAA,MAAM,MAAM,MAAM,IAAA,CAAK,MAAA,CAAO,OAAA,CAAmC,QAAQ,sBAAA,EAAwB;AAAA,MAC/F,IAAA,EAAM,EAAE,GAAA,EAAK,GAAI,OAAA,CAAQ,cAAA,GAAiB,EAAE,cAAA,EAAgB,OAAA,CAAQ,cAAA,EAAe,GAAI,EAAC;AAAG,KAC5F,CAAA;AACD,IAAA,OAAO,GAAA,CAAI,IAAA;AAAA,EACb;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,WAAW,IAAA,EAA+E;AACxF,IAAA,OAAO,IAAA,CAAK,OAAO,OAAA,CAA0B,MAAA,EAAQ,mBAAmB,EAAE,IAAA,EAAM,MAAM,CAAA;AAAA,EACxF;AACF","file":"chunk-K53JD2ZC.js","sourcesContent":["import type { NodaroClientCore } from \"../core.js\"\nimport { LargeUploadUnavailableError, NodaroError } from \"../errors.js\"\n\n/**\n * The most `POST /v1/upload` ({@link UploadsResource.upload}) takes: 500 MB.\n * {@link UploadsResource.uploadLarge} sends a file of this size or less through\n * that same route, and only a bigger one through the large-upload lane.\n */\nexport const UPLOAD_MAX_BYTES = 500 * 1024 * 1024\n/** Tries per part: the first, and two retries. */\nconst PART_ATTEMPTS = 3\n/** `/complete` reads the stored file's length and makes its poster before it answers. */\nconst COMPLETE_TIMEOUT_MS = 5 * 60 * 1000\n\n/** Options of {@link UploadsResource.uploadLarge}. */\nexport interface UploadLargeOptions {\n /** The name to store the file under; defaults to the file's own name, else `upload`. */\n readonly filename?: string\n /** Called as parts finish, with the bytes sent so far and the file's size. */\n readonly onProgress?: (sentBytes: number, totalBytes: number) => void\n /** Cancels the upload; the server's copy of the parts is aborted. */\n readonly signal?: AbortSignal\n /** Parts sent at once (default 3). */\n readonly concurrency?: number\n}\n\n/** `POST /v1/uploads/large/start`'s answer. */\ninterface LargeUploadStart {\n readonly token: string\n readonly partSize: number\n readonly partUrls: readonly string[]\n}\n\n/**\n * Result of a successful `POST /v1/upload`. Mirrors the route's `data` envelope\n * (`backend/src/routes/upload.ts`), the source of truth — keep in sync if that\n * response changes. The route also returns loosely-typed extracted `metadata`;\n * it is omitted here until a consumer needs a typed shape (add it shaped to\n * that need rather than inventing `Record<string, unknown>` surface now).\n */\nexport interface UploadResult {\n /** Public R2 URL of the stored asset (always present on success). */\n readonly url: string\n /** Storage row id; `null` when no asset row was written (e.g. unauthenticated). */\n readonly assetId: string | null\n /** Generated thumbnail URL (images/video); `null` for audio or on failure. */\n readonly thumbnailUrl: string | null\n /** Server-classified asset category (e.g. \"image\" | \"video\" | \"audio\"). */\n readonly category: string\n /** Display filename (server override or the original). */\n readonly filename: string\n /** Final MIME type after server normalization. */\n readonly mimeType: string\n /** Stored byte size. */\n readonly sizeBytes: number\n /** R2 object key. */\n readonly r2Key: string\n}\n\nexport class UploadsResource {\n constructor(private client: NodaroClientCore) {}\n\n /**\n * Upload one file (`POST /v1/upload`, multipart — the file rides the `file`\n * field). The SDK's `request` detects the `FormData` body and lets the\n * runtime set the multipart boundary. Returns the persisted asset's public\n * URL + storage metadata (unwraps the `{ data }` envelope). Throws\n * `StorageExceededError` (413) over the storage cap and the SDK's other typed\n * errors on the usual statuses.\n */\n async upload(file: File): Promise<UploadResult> {\n return this.uploadMultipart(file)\n }\n\n private async uploadMultipart(file: Blob, filename?: string, signal?: AbortSignal): Promise<UploadResult> {\n const form = new FormData()\n if (filename !== undefined) form.append(\"file\", file, filename)\n else form.append(\"file\", file)\n const res = await this.client.request<{ data: UploadResult }>(\n \"POST\",\n \"/v1/upload\",\n { body: form, ...(signal ? { signal } : {}) },\n )\n return res.data\n }\n\n /**\n * Upload a file of any size, choosing the lane by size:\n *\n * - **{@link UPLOAD_MAX_BYTES} (500 MB) or less:** exactly {@link upload}\n * (`POST /v1/upload`) — the path every file of that size takes today, with\n * everything it does on the server (faststart, HEIC conversion, upload\n * policies, thumbnails). The large-upload lane is never touched.\n * - **Bigger (video or audio only):** the bytes go straight from here to the\n * platform's object storage in parts (`POST /v1/uploads/large/start` → one\n * `PUT` per part → `POST /v1/uploads/large/complete`), never through the\n * API server. What limits such a file is length: one longer than 30\n * minutes is refused once it has arrived, with `MediaTooLongError` (the\n * stored copy is removed and nothing counts against storage).\n *\n * Returns the same result as {@link upload}. Parts are sent `concurrency` at\n * a time (default 3); a part that fails is tried twice more before the\n * upload fails. `onProgress(sentBytes, totalBytes)` is called as parts\n * finish (once at the end on the small path). Aborting `signal`, or any\n * failure, aborts the upload on the server (best-effort).\n *\n * A file over 500 MB on a deployment without the lane — one that checks every\n * upload's bytes (409 `large_upload_unavailable`), or an older server (404) —\n * throws `LargeUploadUnavailableError`: `POST /v1/upload` would refuse it\n * anyway. Throws `StorageExceededError` (413) when the file does not fit in\n * the account's storage, and the SDK's other typed errors on the usual\n * statuses.\n *\n * In a browser, storage must allow cross-origin `PUT` from the page's origin\n * for the large lane (the platform's own deployments do).\n */\n async uploadLarge(file: Blob & { readonly name?: string }, options: UploadLargeOptions = {}): Promise<UploadResult> {\n const filename = options.filename ?? (file.name && file.name.length > 0 ? file.name : \"upload\")\n const signal = options.signal\n if (file.size <= UPLOAD_MAX_BYTES) {\n const result = await this.uploadMultipart(file, filename, signal)\n options.onProgress?.(file.size, file.size)\n return result\n }\n let started: LargeUploadStart\n try {\n started = await this.client.request<LargeUploadStart>(\"POST\", \"/v1/uploads/large/start\", {\n body: { filename, mimeType: file.type || \"application/octet-stream\", sizeBytes: file.size },\n ...(signal ? { signal } : {}),\n })\n } catch (err) {\n if (err instanceof NodaroError && err.status === 404) throw new LargeUploadUnavailableError(undefined, 404)\n throw err\n }\n\n const { token, partSize, partUrls } = started\n try {\n await this.sendParts(file, partSize, partUrls, options)\n const res = await this.client.request<{ data: UploadResult }>(\"POST\", \"/v1/uploads/large/complete\", {\n body: { token },\n timeoutMs: COMPLETE_TIMEOUT_MS,\n ...(signal ? { signal } : {}),\n })\n return res.data\n } catch (err) {\n // Best-effort, and never under the caller's (possibly aborted) signal.\n await this.client.request(\"POST\", \"/v1/uploads/large/abort\", { body: { token } }).catch(() => undefined)\n throw err\n }\n }\n\n /**\n * PUT every part, `concurrency` at a time, each tried up to\n * {@link PART_ATTEMPTS} times. Each part is EXACTLY `partSize` bytes (the\n * last one the remainder): its URL has that length signed in, so storage\n * refuses any other. The runtime sets Content-Length from the slice itself.\n */\n private async sendParts(file: Blob, partSize: number, partUrls: readonly string[], options: UploadLargeOptions): Promise<void> {\n const total = file.size\n const concurrency = Math.max(1, Math.floor(options.concurrency ?? 3))\n let next = 0\n let sent = 0\n let failed: unknown\n const worker = async (): Promise<void> => {\n while (failed === undefined && next < partUrls.length) {\n const index = next++\n const start = index * partSize\n const part = file.slice(start, Math.min(start + partSize, total))\n try {\n await this.putPart(partUrls[index]!, part, index + 1, options.signal)\n } catch (err) {\n failed ??= err\n return\n }\n sent += part.size\n options.onProgress?.(sent, total)\n }\n }\n await Promise.all(Array.from({ length: Math.min(concurrency, partUrls.length) }, () => worker()))\n if (failed !== undefined) throw failed\n }\n\n private async putPart(url: string, part: Blob, partNumber: number, signal: AbortSignal | undefined): Promise<void> {\n let lastStatus = 0\n for (let attempt = 1; attempt <= PART_ATTEMPTS; attempt++) {\n signal?.throwIfAborted()\n try {\n const res = await this.client.fetch(url, { method: \"PUT\", body: part, ...(signal ? { signal } : {}) })\n if (res.ok) return\n lastStatus = res.status\n // A refusal (expired link, wrong signature) will not change on a retry.\n if (res.status >= 400 && res.status < 500 && res.status !== 408 && res.status !== 429) break\n } catch (err) {\n if (signal?.aborted) throw err\n lastStatus = 0\n }\n }\n throw new NodaroError(`Uploading part ${partNumber} failed${lastStatus ? ` (HTTP ${lastStatus})` : \"\"}`, \"upload_part_failed\", lastStatus)\n }\n\n /**\n * Copy a picture from a web address into your storage\n * (`POST /v1/media/import-url`, body `{ url }`). The platform fetches it\n * (http(s) only, never a private address, up to 20 MB), keeps it only if it\n * decodes as an image (JPEG, PNG, WebP, GIF; HEIC/HEIF and AVIF are\n * converted to JPEG or PNG), and stores it as an upload of yours, so its address serves\n * the pixels to the browser (a canvas can read it). Returns the stored\n * picture (unwraps the `{ data }` envelope).\n *\n * Throws `StorageExceededError` on a 413, its `reason` telling the two\n * apart: `storage_limit_exceeded` is a full storage (the quota is in\n * `details` — `usedBytes`, `quotaBytes`, `remainingBytes`, `tier`), and\n * `file_too_large` a picture over 20 MB. Throws a `NodaroError` with `code`\n * `validation_error` (400: not an http(s) address, or not an image) or\n * `fetch_failed` (422: the address could not be reached or answered with an\n * error).\n *\n * An import of a link runs the platform's content rights check: pass the\n * `confirmationId` from `contentRights.confirm({ url })` when the deployment\n * requires one (`403 rights_confirmation_required` otherwise). A site an\n * administrator disabled answers `403 import_source_disabled`, and a\n * deployment that turned link imports off answers `403 link_imports_disabled`\n * for a link to another site (a file of the deployment's own storage is still\n * imported as before).\n */\n async importUrl(url: string, options: { confirmationId?: string } = {}): Promise<ImportUrlResult> {\n const res = await this.client.request<{ data: ImportUrlResult }>(\"POST\", \"/v1/media/import-url\", {\n body: { url, ...(options.confirmationId ? { confirmationId: options.confirmationId } : {}) },\n })\n return res.data\n }\n\n /**\n * Store a JSON document (`POST /v1/upload-json`, up to 25 MB) and get its\n * public URL — e.g. an image editor's design state, passed to\n * `client.jobs.fromUpload` as `editStateUrl` so the edit can be reopened.\n * The URL is unguessable but public: never store a secret in it. Creates no\n * library item.\n */\n uploadJson(json: Record<string, unknown> | readonly unknown[]): Promise<UploadJsonResult> {\n return this.client.request<UploadJsonResult>(\"POST\", \"/v1/upload-json\", { body: json })\n }\n}\n\n/** Result of {@link UploadsResource.uploadJson}. */\nexport interface UploadJsonResult {\n /** Public URL of the stored JSON document. */\n readonly url: string\n}\n\n/**\n * Result of {@link UploadsResource.importUrl}. Mirrors the route's `data`:\n * the fields of {@link UploadResult} it shares, plus the picture's size.\n */\nexport interface ImportUrlResult {\n /** Public URL of the stored picture. */\n readonly url: string\n /** Generated thumbnail URL; `null` when it could not be made. */\n readonly thumbnailUrl: string | null\n /** Storage row id; `null` when no asset row was written. */\n readonly assetId: string | null\n /** Final MIME type (a HEIC/HEIF or AVIF source is stored as JPEG or PNG). */\n readonly mimeType: string\n /** Stored byte size. */\n readonly sizeBytes: number\n /** Display filename: the address's last path segment, else `imported-<id>.<ext>`. */\n readonly filename: string\n /** Width in pixels; 0 when it could not be read. */\n readonly width: number\n /** Height in pixels; 0 when it could not be read. */\n readonly height: number\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkE2NMFQNY_cjs = require('./chunk-E2NMFQNY.cjs');
|
|
4
4
|
var nodes = require('@nodaro/shared/nodes');
|
|
5
5
|
var social = require('@nodaro/shared/social');
|
|
6
6
|
|
|
@@ -9,7 +9,7 @@ var DEFAULT_MAX_MS = 15 * 60 * 1e3;
|
|
|
9
9
|
var MAX_QUEUED_CREDIT_MS = (24 * 60 + 30) * 60 * 1e3;
|
|
10
10
|
var sleep = (ms, signal) => new Promise((resolve, reject) => {
|
|
11
11
|
if (signal?.aborted) {
|
|
12
|
-
reject(new
|
|
12
|
+
reject(new chunkE2NMFQNY_cjs.JobAbortedError());
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
15
|
const timer = setTimeout(() => {
|
|
@@ -18,20 +18,20 @@ var sleep = (ms, signal) => new Promise((resolve, reject) => {
|
|
|
18
18
|
}, ms);
|
|
19
19
|
function onAbort() {
|
|
20
20
|
clearTimeout(timer);
|
|
21
|
-
reject(new
|
|
21
|
+
reject(new chunkE2NMFQNY_cjs.JobAbortedError());
|
|
22
22
|
}
|
|
23
23
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
24
24
|
});
|
|
25
25
|
function notRunnable(type, why) {
|
|
26
|
-
return new
|
|
26
|
+
return new chunkE2NMFQNY_cjs.NodaroError(`Node type "${type}" has no route of its own to run it directly: ${why}.`, "node_not_runnable", 0);
|
|
27
27
|
}
|
|
28
|
-
var isRouteNotFound = (err) => err instanceof
|
|
28
|
+
var isRouteNotFound = (err) => err instanceof chunkE2NMFQNY_cjs.NotFoundError && /^Route\b.*\bnot found\b/i.test(err.message);
|
|
29
29
|
function extractJobId(result, label) {
|
|
30
30
|
if (result && typeof result === "object" && "jobId" in result) {
|
|
31
31
|
const jobId = result.jobId;
|
|
32
32
|
if (typeof jobId === "string") return jobId;
|
|
33
33
|
}
|
|
34
|
-
throw new
|
|
34
|
+
throw new chunkE2NMFQNY_cjs.JobFailedError(`${label} did not return a jobId`, "");
|
|
35
35
|
}
|
|
36
36
|
function isImageBatchRequest(type, params) {
|
|
37
37
|
if (type !== "generate-image") return false;
|
|
@@ -42,7 +42,7 @@ function batchJobIds(result) {
|
|
|
42
42
|
return Array.isArray(ids) && ids.every((id) => typeof id === "string") ? ids : null;
|
|
43
43
|
}
|
|
44
44
|
function batchRefusal(detail) {
|
|
45
|
-
return new
|
|
45
|
+
return new chunkE2NMFQNY_cjs.NodaroError(
|
|
46
46
|
`${detail}: this waits for one job \u2014 use nodes.runBatchAndWait() for a batch (count above 1, or models).`,
|
|
47
47
|
"batch_requires_run_batch_and_wait",
|
|
48
48
|
0
|
|
@@ -89,7 +89,7 @@ var NodesResource = class {
|
|
|
89
89
|
return res.data;
|
|
90
90
|
}
|
|
91
91
|
async runAndWait(type, params = {}, opts = {}) {
|
|
92
|
-
if (opts.signal?.aborted) throw new
|
|
92
|
+
if (opts.signal?.aborted) throw new chunkE2NMFQNY_cjs.JobAbortedError();
|
|
93
93
|
if (isImageBatchRequest(type, params)) throw batchRefusal(`${type} with count above 1 or models makes several jobs`);
|
|
94
94
|
const result = await this.run(type, params, { idempotencyKey: opts.idempotencyKey });
|
|
95
95
|
const ids = batchJobIds(result);
|
|
@@ -114,9 +114,9 @@ var NodesResource = class {
|
|
|
114
114
|
* `not_a_batch`) — wait for it with {@link runAndWait}.
|
|
115
115
|
*/
|
|
116
116
|
async runBatchAndWait(type, params, opts = {}) {
|
|
117
|
-
if (opts.signal?.aborted) throw new
|
|
117
|
+
if (opts.signal?.aborted) throw new chunkE2NMFQNY_cjs.JobAbortedError();
|
|
118
118
|
if (!isImageBatchRequest(type, params)) {
|
|
119
|
-
throw new
|
|
119
|
+
throw new chunkE2NMFQNY_cjs.NodaroError(
|
|
120
120
|
"runBatchAndWait waits for a batch \u2014 count above 1, or models; wait for one image with nodes.runAndWait().",
|
|
121
121
|
"not_a_batch",
|
|
122
122
|
0
|
|
@@ -124,7 +124,7 @@ var NodesResource = class {
|
|
|
124
124
|
}
|
|
125
125
|
const result = await this.run(type, params, { idempotencyKey: opts.idempotencyKey });
|
|
126
126
|
const batch = batchResultOf(result);
|
|
127
|
-
if (!batch) throw new
|
|
127
|
+
if (!batch) throw new chunkE2NMFQNY_cjs.JobFailedError(`${type} did not answer with a batch`, "");
|
|
128
128
|
const modelOf = new Map(batch.groups.flatMap((group) => group.jobIds.map((id) => [id, group.model])));
|
|
129
129
|
const results = await Promise.all(
|
|
130
130
|
batch.jobIds.map(async (jobId) => {
|
|
@@ -132,7 +132,7 @@ var NodesResource = class {
|
|
|
132
132
|
try {
|
|
133
133
|
return { jobId, model, status: "completed", output: await this.pollJob(jobId, type, opts) };
|
|
134
134
|
} catch (err) {
|
|
135
|
-
if (err instanceof
|
|
135
|
+
if (err instanceof chunkE2NMFQNY_cjs.JobAbortedError || !(err instanceof chunkE2NMFQNY_cjs.NodaroError)) throw err;
|
|
136
136
|
return { jobId, model, status: "error", error: err };
|
|
137
137
|
}
|
|
138
138
|
})
|
|
@@ -153,13 +153,13 @@ var NodesResource = class {
|
|
|
153
153
|
* @param opts Shared `signal` / `cancelOnAbort` / `onProgress` / `pollMs` / `maxMs`.
|
|
154
154
|
*/
|
|
155
155
|
async runMany(type, paramsList, opts = {}) {
|
|
156
|
-
if (opts.signal?.aborted) throw new
|
|
156
|
+
if (opts.signal?.aborted) throw new chunkE2NMFQNY_cjs.JobAbortedError();
|
|
157
157
|
if (paramsList.some((params) => isImageBatchRequest(type, params))) {
|
|
158
158
|
throw batchRefusal(`a ${type} entry with count above 1 or models makes several jobs`);
|
|
159
159
|
}
|
|
160
160
|
return Promise.all(
|
|
161
161
|
paramsList.map(async (params) => {
|
|
162
|
-
if (opts.signal?.aborted) throw new
|
|
162
|
+
if (opts.signal?.aborted) throw new chunkE2NMFQNY_cjs.JobAbortedError();
|
|
163
163
|
const result = await this.run(type, params);
|
|
164
164
|
const jobId = extractJobId(result, type);
|
|
165
165
|
const output = await this.pollJob(jobId, type, opts);
|
|
@@ -174,9 +174,9 @@ var NodesResource = class {
|
|
|
174
174
|
try {
|
|
175
175
|
return await this.pollUntilSettled(jobId, label, opts);
|
|
176
176
|
} catch (err) {
|
|
177
|
-
if (!(err instanceof
|
|
177
|
+
if (!(err instanceof chunkE2NMFQNY_cjs.JobAbortedError)) throw err;
|
|
178
178
|
if (opts.cancelOnAbort) await this.client.jobs.cancel(jobId).catch(() => void 0);
|
|
179
|
-
throw err.jobId ? err : new
|
|
179
|
+
throw err.jobId ? err : new chunkE2NMFQNY_cjs.JobAbortedError(err.message, jobId);
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
182
|
/** Poll an already-kicked job id until it stops moving; resolve output_data
|
|
@@ -193,7 +193,7 @@ var NodesResource = class {
|
|
|
193
193
|
let lastReadAt = startedAt;
|
|
194
194
|
let queuedMs = 0;
|
|
195
195
|
for (; ; ) {
|
|
196
|
-
if (opts.signal?.aborted) throw new
|
|
196
|
+
if (opts.signal?.aborted) throw new chunkE2NMFQNY_cjs.JobAbortedError(void 0, jobId);
|
|
197
197
|
const { data } = await this.client.jobs.getStatus(jobId);
|
|
198
198
|
const readAt = Date.now();
|
|
199
199
|
if (data.status === "queued") {
|
|
@@ -205,17 +205,17 @@ var NodesResource = class {
|
|
|
205
205
|
return data.output_data ?? {};
|
|
206
206
|
}
|
|
207
207
|
if (data.status === "failed" || data.status === "cancelled") {
|
|
208
|
-
throw new
|
|
208
|
+
throw new chunkE2NMFQNY_cjs.JobFailedError(
|
|
209
209
|
data.error_message ?? `${label} ${data.status}`,
|
|
210
210
|
jobId,
|
|
211
211
|
data.status
|
|
212
212
|
);
|
|
213
213
|
}
|
|
214
214
|
if (data.status === "pending_review") {
|
|
215
|
-
throw new
|
|
215
|
+
throw new chunkE2NMFQNY_cjs.JobHeldError(`${label} is awaiting review`, jobId);
|
|
216
216
|
}
|
|
217
217
|
if (Date.now() > startedAt + maxMs + queuedMs) {
|
|
218
|
-
throw new
|
|
218
|
+
throw new chunkE2NMFQNY_cjs.JobTimeoutError(`${label} timed out`, jobId, maxMs);
|
|
219
219
|
}
|
|
220
220
|
await sleep(pollMs, opts.signal);
|
|
221
221
|
}
|
|
@@ -223,5 +223,5 @@ var NodesResource = class {
|
|
|
223
223
|
};
|
|
224
224
|
|
|
225
225
|
exports.NodesResource = NodesResource;
|
|
226
|
-
//# sourceMappingURL=chunk-
|
|
227
|
-
//# sourceMappingURL=chunk-
|
|
226
|
+
//# sourceMappingURL=chunk-KNBZFWVO.cjs.map
|
|
227
|
+
//# sourceMappingURL=chunk-KNBZFWVO.cjs.map
|