totalum-sdk 1.11.0 → 1.11.1
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/CHANGELOG.md +9 -0
- package/dist/_types/{coerce.d-BKhuaDya.d.ts → coerce.d-D_rylvPs.d.ts} +1 -1
- package/dist/_types/{errors.d-RTRkidv5.d.ts → errors.d-BPpY5QKu.d.ts} +20 -2
- package/dist/_types/{integrations.d-CzTa9T-L.d.ts → integrations.d-BTZHy48D.d.ts} +2 -2
- package/dist/_types/{ops.d-CNsrT4Ma.d.ts → ops.d-Ce5zJyX0.d.ts} +2 -2
- package/dist/ai/index.d.ts +275 -23
- package/dist/ai/index.js +305 -24
- package/dist/analytics/index.d.ts +58 -12
- package/dist/analytics/index.js +46 -3
- package/dist/browser/index.d.ts +208 -18
- package/dist/browser/index.js +122 -13
- package/dist/connections/index.d.ts +305 -23
- package/dist/connections/index.js +302 -21
- package/dist/cron/index.d.ts +147 -20
- package/dist/cron/index.js +157 -15
- package/dist/d1/errors.js +15 -0
- package/dist/d1/index.d.ts +254 -10
- package/dist/d1/index.js +24 -4
- package/dist/d1/session.js +26 -2
- package/dist/email/index.d.ts +65 -10
- package/dist/email/index.js +60 -5
- package/dist/errors.js +17 -0
- package/dist/files/index.d.ts +243 -20
- package/dist/files/index.js +247 -14
- package/dist/index.d.ts +24 -9
- package/dist/index.js +19 -5
- package/dist/logs/index.d.ts +48 -10
- package/dist/logs/index.js +39 -4
- package/dist/payments/index.d.ts +221 -23
- package/dist/payments/index.js +216 -18
- package/dist/pdf/index.d.ts +59 -9
- package/dist/pdf/index.js +54 -4
- package/dist/react/index.d.ts +78 -6
- package/dist/react/index.js +51 -5
- package/dist/realtime/index.d.ts +55 -8
- package/dist/realtime/index.js +53 -6
- package/dist/scan/index.d.ts +78 -10
- package/dist/scan/index.js +63 -3
- package/dist/seo/index.d.ts +43 -7
- package/dist/seo/index.js +39 -3
- package/dist/speech/index.d.ts +34 -10
- package/dist/speech/index.js +25 -5
- package/dist/vectors/index.d.ts +96 -9
- package/dist/vectors/index.js +93 -7
- package/dist/web/index.d.ts +168 -15
- package/dist/web/index.js +163 -10
- package/dist/webhooks/index.d.ts +122 -15
- package/dist/webhooks/index.js +119 -13
- package/package.json +2 -1
- package/totalum-sdk.md +8841 -754
- package/totalum-sdk.signatures.json +1 -1
package/dist/files/index.js
CHANGED
|
@@ -3,21 +3,99 @@ import { apiUrlOf, jsonClient, query, rawClient, readEnv } from '../http.js';
|
|
|
3
3
|
export { TotalumError, isTotalumError } from '../errors.js';
|
|
4
4
|
const DEFAULT_FILES_URL = 'https://files.totalum-project.com';
|
|
5
5
|
/**
|
|
6
|
-
* `
|
|
6
|
+
* Creates the `files` namespace (the same object as `totalum.files`) with its own options. Every call returns the file
|
|
7
7
|
* descriptor `{key, fileName, fileSize, contentType, fileUrl, visibility, createdAt}` meant to be stored as-is in the
|
|
8
8
|
* row's file column; failures throw `TotalumError` with the Totalum API's frozen code.
|
|
9
|
+
*
|
|
10
|
+
* @param options - The project key, API URL, environment and public files host; each falls back to its environment
|
|
11
|
+
* variable.
|
|
12
|
+
* @returns The `files` namespace: the methods below.
|
|
13
|
+
* @example
|
|
14
|
+
* import { totalumFiles } from 'totalum-sdk/files';
|
|
15
|
+
*
|
|
16
|
+
* const files = totalumFiles({ env: 'dev' });
|
|
17
|
+
* const page = await files.list({ limit: 10 });
|
|
9
18
|
*/
|
|
10
19
|
export function totalumFiles(options = {}) {
|
|
11
20
|
const call = jsonClient(options);
|
|
12
21
|
const raw = rawClient(options);
|
|
13
22
|
const filesUrl = () => options.filesUrl ?? readEnv('TOTALUM_FILES_URL') ?? DEFAULT_FILES_URL;
|
|
14
23
|
const path = (key) => `/v1/files/${key.split('/').map(encodeURIComponent).join('/')}`;
|
|
24
|
+
/**
|
|
25
|
+
* A temporary link to one file — the way to show or download a private file in the browser. The link works for 15
|
|
26
|
+
* minutes by default and at most 7 days; anyone holding it can read the file until then, so make it when the page
|
|
27
|
+
* needs it rather than storing it.
|
|
28
|
+
*
|
|
29
|
+
* @param key - The file's `key` (private `pv/…` or public `p/…`).
|
|
30
|
+
* @param opts - How long the link works and whether the browser downloads the file.
|
|
31
|
+
* @param opts.expiresInSeconds - Seconds the link works, 1–604800 (7 days). Default 900 (15 minutes).
|
|
32
|
+
* @param opts.download - `true` makes the browser download the file under its name instead of showing it.
|
|
33
|
+
* @returns The signed `https://` URL.
|
|
34
|
+
* @throws FILE_NOT_FOUND (404) No such file.
|
|
35
|
+
* @throws FILE_KEY_FORBIDDEN (403) The key belongs to another project.
|
|
36
|
+
* @throws VALIDATION_ERROR (400) `expiresInSeconds` is out of range.
|
|
37
|
+
* @example
|
|
38
|
+
* const url = await totalum.files.getSignedUrl(contract.key, { expiresInSeconds: 3600, download: true });
|
|
39
|
+
* //=>
|
|
40
|
+
* "https://2e99a1160c18f1f4e0d589ff6105397e.r2.cloudflarestorage.com/project-files/pv/acme-crm/01M4P0Q0X79QHFPBKBK2XHFTDG.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Expires=3600&…"
|
|
41
|
+
*/
|
|
15
42
|
const getSignedUrl = async (key, opts = {}) => {
|
|
16
43
|
const q = query({ expiresInSeconds: opts.expiresInSeconds, download: opts.download || undefined });
|
|
17
44
|
return (await call('GET', `${path(key)}/download-url${q}`)).url;
|
|
18
45
|
};
|
|
19
46
|
return {
|
|
20
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* Stores a file of up to 25 MB and returns its descriptor. Call it from a route handler or server action with the
|
|
49
|
+
* `File` from a form, a `Blob`, bytes or a string; larger files go through `getUploadUrl` + `complete`. Public files
|
|
50
|
+
* (the default) get a permanent, unguessable `fileUrl`; private ones only signed URLs. Each upload gets a new key:
|
|
51
|
+
* uploading the same name again never overwrites a file.
|
|
52
|
+
*
|
|
53
|
+
* @param input - The content: a `File`/`Blob` (its name and type are used), an `ArrayBuffer`/`Uint8Array`, or a
|
|
54
|
+
* string (stored as UTF-8 text).
|
|
55
|
+
* @param opts - The name, type, visibility and folder.
|
|
56
|
+
* @returns The stored file's descriptor: save it as-is in the row's file column.
|
|
57
|
+
* @throws FILE_TOO_LARGE (413) Over 25 MB (use `getUploadUrl`), or over the plan's largest file; `details.maxBytes`.
|
|
58
|
+
* @throws UNSUPPORTED_FILE_TYPE (415) HTML and executable files are never stored.
|
|
59
|
+
* @throws STORAGE_LIMIT_EXCEEDED (429) The plan's storage is full; `details.capBytes`.
|
|
60
|
+
* @throws RATE_LIMIT_EXCEEDED (429) The plan's uploads per minute or per month are used up; `details.period`.
|
|
61
|
+
* @throws FILE_UPLOAD_ERROR (502) The file could not be stored; retry.
|
|
62
|
+
* @example
|
|
63
|
+
* // src/app/api/avatar/route.ts
|
|
64
|
+
* import { totalum } from 'totalum-sdk';
|
|
65
|
+
*
|
|
66
|
+
* export async function POST(request: Request) {
|
|
67
|
+
* const form = await request.formData();
|
|
68
|
+
* const file = form.get('file') as File;
|
|
69
|
+
* const stored = await totalum.files.upload(file, { folder: 'avatars' });
|
|
70
|
+
* // save `stored` in the user's avatar column, then show stored.fileUrl
|
|
71
|
+
* return Response.json(stored);
|
|
72
|
+
* }
|
|
73
|
+
* //=>
|
|
74
|
+
* {
|
|
75
|
+
* "key": "p/acme-crm/01M4P0PZXJ0DPQM7R20QVZ0EKC.png",
|
|
76
|
+
* "fileName": "ana.png",
|
|
77
|
+
* "fileSize": 48213,
|
|
78
|
+
* "contentType": "image/png",
|
|
79
|
+
* "fileUrl": "https://files.totalum-project.com/p/acme-crm/01M4P0PZXJ0DPQM7R20QVZ0EKC.png",
|
|
80
|
+
* "visibility": "public-by-link",
|
|
81
|
+
* "createdAt": "2026-10-11T17:38:33.872Z",
|
|
82
|
+
* "etag": "\"8e72fb50886ffd6a1cdef31c54e3596b\"",
|
|
83
|
+
* "name": "ana.png",
|
|
84
|
+
* "url": "https://files.totalum-project.com/p/acme-crm/01M4P0PZXJ0DPQM7R20QVZ0EKC.png",
|
|
85
|
+
* "size": 48213,
|
|
86
|
+
* "id": "p/acme-crm/01M4P0PZXJ0DPQM7R20QVZ0EKC.png",
|
|
87
|
+
* "fileNameId": "p/acme-crm/01M4P0PZXJ0DPQM7R20QVZ0EKC.png"
|
|
88
|
+
* }
|
|
89
|
+
* @example
|
|
90
|
+
* // a private file: no fileUrl, read it with getSignedUrl
|
|
91
|
+
* const contract = await totalum.files.upload(pdfBytes, {
|
|
92
|
+
* name: 'contract-ana.pdf',
|
|
93
|
+
* contentType: 'application/pdf',
|
|
94
|
+
* private: true,
|
|
95
|
+
* });
|
|
96
|
+
* //=>
|
|
97
|
+
* { "key": "pv/acme-crm/01M4P0Q0X79QHFPBKBK2XHFTDG.pdf", "fileName": "contract-ana.pdf", "fileUrl": null, "visibility": "private", … }
|
|
98
|
+
*/
|
|
21
99
|
upload(input, opts = {}) {
|
|
22
100
|
const type = opts.contentType ?? (input instanceof Blob ? input.type : '');
|
|
23
101
|
const name = opts.name ?? (input instanceof File ? input.name : 'file');
|
|
@@ -31,25 +109,137 @@ export function totalumFiles(options = {}) {
|
|
|
31
109
|
return call('POST', '/v1/files', form);
|
|
32
110
|
},
|
|
33
111
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
112
|
+
* Starts a direct upload for a large file (over 25 MB, or any file you want the browser to send straight to
|
|
113
|
+
* storage): your server asks for an upload URL, the browser `PUT`s the bytes to it with the returned `headers`,
|
|
114
|
+
* then your server calls `complete(key)`. The URL lasts 15 minutes and only accepts exactly this type and size.
|
|
115
|
+
* The largest file is 50 MB on the Free plan, 500 MB on Starter, Builder and Professional, and 1 GB on Enterprise.
|
|
116
|
+
*
|
|
117
|
+
* @param input - The file's name, type and exact size in bytes, plus its folder and visibility.
|
|
118
|
+
* @returns Where and how to `PUT` the bytes, and the key to pass to `complete()`.
|
|
119
|
+
* @throws FILE_TOO_LARGE (413) Over the plan's largest file; `details.maxBytes`.
|
|
120
|
+
* @throws UNSUPPORTED_FILE_TYPE (415) HTML and executable files are never stored.
|
|
121
|
+
* @throws STORAGE_LIMIT_EXCEEDED (429) The plan's storage is full.
|
|
122
|
+
* @example
|
|
123
|
+
* // server: hand the browser an upload URL
|
|
124
|
+
* const upload = await totalum.files.getUploadUrl({ name: 'demo.mp4', contentType: 'video/mp4', size: 73400320 });
|
|
125
|
+
* // browser: await fetch(upload.uploadUrl, { method: 'PUT', headers: upload.headers, body: file });
|
|
126
|
+
* // server, afterwards:
|
|
127
|
+
* const stored = await totalum.files.complete(upload.key);
|
|
128
|
+
* //=>
|
|
129
|
+
* {
|
|
130
|
+
* "uploadUrl": "https://2e99a1160c18f1f4e0d589ff6105397e.r2.cloudflarestorage.com/project-files/p/acme-crm/01M4P0Q21EK7JVGY3MXK224DAH.mp4?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Expires=900&…",
|
|
131
|
+
* "key": "p/acme-crm/01M4P0Q21EK7JVGY3MXK224DAH.mp4",
|
|
132
|
+
* "headers": { "content-type": "video/mp4", "content-length": "73400320" },
|
|
133
|
+
* "expiresAt": "2026-10-11T17:53:35.830Z"
|
|
134
|
+
* }
|
|
37
135
|
*/
|
|
38
136
|
getUploadUrl: (input) => call('POST', '/v1/files/upload-url', input),
|
|
39
|
-
/**
|
|
137
|
+
/**
|
|
138
|
+
* Finishes a direct upload started with `getUploadUrl`: checks the bytes arrived with the declared size and type and
|
|
139
|
+
* returns the file's descriptor. Calling it again for a finished file returns the same descriptor.
|
|
140
|
+
*
|
|
141
|
+
* @param key - The `key` `getUploadUrl` returned.
|
|
142
|
+
* @returns The stored file's descriptor, the same shape `upload()` returns.
|
|
143
|
+
* @throws UPLOAD_NOT_COMPLETED (409) Nothing was uploaded to the URL yet, or the bytes did not match the declared size
|
|
144
|
+
* or type (the object is then deleted: start again).
|
|
145
|
+
* @throws FILE_NOT_FOUND (404) No upload was started for this key.
|
|
146
|
+
* @throws FILE_KEY_FORBIDDEN (403) The key belongs to another project.
|
|
147
|
+
* @example
|
|
148
|
+
* const stored = await totalum.files.complete('p/acme-crm/01M4P0Q21EK7JVGY3MXK224DAH.mp4');
|
|
149
|
+
* //=>
|
|
150
|
+
* {
|
|
151
|
+
* "key": "p/acme-crm/01M4P0Q21EK7JVGY3MXK224DAH.mp4",
|
|
152
|
+
* "fileName": "demo.mp4",
|
|
153
|
+
* "fileSize": 73400320,
|
|
154
|
+
* "contentType": "video/mp4",
|
|
155
|
+
* "fileUrl": "https://files.totalum-project.com/p/acme-crm/01M4P0Q21EK7JVGY3MXK224DAH.mp4",
|
|
156
|
+
* "visibility": "public-by-link",
|
|
157
|
+
* "createdAt": "2026-10-11T17:38:35.830Z",
|
|
158
|
+
* …
|
|
159
|
+
* }
|
|
160
|
+
*/
|
|
40
161
|
complete: (key) => call('POST', '/v1/files/complete', { key }),
|
|
41
162
|
/**
|
|
42
|
-
* One page of the project's files, newest first
|
|
43
|
-
*
|
|
163
|
+
* One page of the project's files, newest first, with the project's total storage. Filter by folder, name, type,
|
|
164
|
+
* creation date and size; fetch the next page with `cursor` set to the previous page's `nextCursor`.
|
|
165
|
+
*
|
|
166
|
+
* @param q - The filters and paging; every field is optional.
|
|
167
|
+
* @param q.folder - Only files in this folder (as given to `upload`).
|
|
168
|
+
* @param q.name - Only files whose name contains this text.
|
|
169
|
+
* @param q.type - Only files whose content type starts with this (`image/`, `application/pdf`).
|
|
170
|
+
* @param q.createdFrom - Only files created at or after this ISO date-time.
|
|
171
|
+
* @param q.createdTo - Only files created at or before this ISO date-time.
|
|
172
|
+
* @param q.sizeFrom - Only files of at least this many bytes.
|
|
173
|
+
* @param q.sizeTo - Only files of at most this many bytes.
|
|
174
|
+
* @param q.cursor - The previous page's `nextCursor`, for the next page.
|
|
175
|
+
* @param q.limit - Files per page, 1–100. Default 100.
|
|
176
|
+
* @returns The page of files and the project's totals.
|
|
177
|
+
* @throws VALIDATION_ERROR (400) A filter has the wrong format (a date that is not ISO, a limit over 100).
|
|
178
|
+
* @example
|
|
179
|
+
* const page = await totalum.files.list({ folder: 'invoices', limit: 2 });
|
|
180
|
+
* //=>
|
|
181
|
+
* {
|
|
182
|
+
* "items": [
|
|
183
|
+
* {
|
|
184
|
+
* "key": "p/acme-crm/01M4P0PZXJ0DPQM7R20QVZ0EKC.pdf",
|
|
185
|
+
* "fileName": "invoice-12.pdf",
|
|
186
|
+
* "fileSize": 18233,
|
|
187
|
+
* "contentType": "application/pdf",
|
|
188
|
+
* "fileUrl": "https://files.totalum-project.com/p/acme-crm/01M4P0PZXJ0DPQM7R20QVZ0EKC.pdf",
|
|
189
|
+
* "visibility": "public-by-link",
|
|
190
|
+
* "createdAt": "2026-10-11T17:38:33.872Z",
|
|
191
|
+
* …
|
|
192
|
+
* }
|
|
193
|
+
* ],
|
|
194
|
+
* "nextCursor": null,
|
|
195
|
+
* "totalBytes": 2445409,
|
|
196
|
+
* "fileCount": 11
|
|
197
|
+
* }
|
|
44
198
|
*/
|
|
45
199
|
list: (q = {}) => call('GET', `/v1/files${query(q)}`),
|
|
46
|
-
/**
|
|
200
|
+
/**
|
|
201
|
+
* The descriptor of one file: check that a stored key still exists, or read its name, size and type.
|
|
202
|
+
*
|
|
203
|
+
* @param key - The file's `key`.
|
|
204
|
+
* @returns The file's descriptor.
|
|
205
|
+
* @throws FILE_NOT_FOUND (404) No such file (or it was deleted).
|
|
206
|
+
* @throws FILE_KEY_FORBIDDEN (403) The key belongs to another project.
|
|
207
|
+
* @example
|
|
208
|
+
* const file = await totalum.files.get('p/acme-crm/01M4P0PZXJ0DPQM7R20QVZ0EKC.txt');
|
|
209
|
+
* //=>
|
|
210
|
+
* {
|
|
211
|
+
* "key": "p/acme-crm/01M4P0PZXJ0DPQM7R20QVZ0EKC.txt",
|
|
212
|
+
* "fileName": "hello.txt",
|
|
213
|
+
* "fileSize": 19,
|
|
214
|
+
* "contentType": "text/plain",
|
|
215
|
+
* "fileUrl": "https://files.totalum-project.com/p/acme-crm/01M4P0PZXJ0DPQM7R20QVZ0EKC.txt",
|
|
216
|
+
* "visibility": "public-by-link",
|
|
217
|
+
* "createdAt": "2026-10-11T17:38:33.872Z",
|
|
218
|
+
* …
|
|
219
|
+
* }
|
|
220
|
+
*/
|
|
47
221
|
get: (key) => call('GET', `${path(key)}/meta`),
|
|
48
|
-
/** A presigned GET that R2 verifies: 15 min by default, at most 7 days — the way to hand a private file to a browser. */
|
|
49
222
|
getSignedUrl,
|
|
50
223
|
/** @deprecated Since 1.0.0: use `getSignedUrl` (the same call). */
|
|
51
224
|
getDownloadUrl: alias(getSignedUrl, 'files.getDownloadUrl()', 'files.getSignedUrl()'),
|
|
52
|
-
/**
|
|
225
|
+
/**
|
|
226
|
+
* Signed links for many files in one call — for a gallery or a table of private files.
|
|
227
|
+
*
|
|
228
|
+
* @param keys - The files' keys.
|
|
229
|
+
* @param opts - How long the links work and whether browsers download the files.
|
|
230
|
+
* @param opts.expiresInSeconds - Seconds the links work, at most 604800 (7 days). Default 900 (15 minutes).
|
|
231
|
+
* @param opts.download - `true` makes browsers download the files instead of showing them.
|
|
232
|
+
* @returns An object from each key to its signed URL.
|
|
233
|
+
* @throws FILE_NOT_FOUND (404) One of the keys does not exist; `details.key` names it.
|
|
234
|
+
* @throws FILE_KEY_FORBIDDEN (403) A key belongs to another project.
|
|
235
|
+
* @example
|
|
236
|
+
* const urls = await totalum.files.presign(photos.map((p) => p.key), { expiresInSeconds: 600 });
|
|
237
|
+
* //=>
|
|
238
|
+
* {
|
|
239
|
+
* "pv/acme-crm/01M4P0PZXJ0DPQM7R20QVZ0EKC.jpg": "https://2e99a1160c18f1f4e0d589ff6105397e.r2.cloudflarestorage.com/project-files/pv/acme-crm/01M4P0PZXJ0DPQM7R20QVZ0EKC.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Expires=600&…",
|
|
240
|
+
* "pv/acme-crm/01M4P0Q0X79QHFPBKBK2XHFTDG.jpg": "https://2e99a1160c18f1f4e0d589ff6105397e.r2.cloudflarestorage.com/project-files/pv/acme-crm/01M4P0Q0X79QHFPBKBK2XHFTDG.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Expires=600&…"
|
|
241
|
+
* }
|
|
242
|
+
*/
|
|
53
243
|
async presign(keys, opts = {}) {
|
|
54
244
|
// eslint-disable-next-line @typescript-eslint/no-deprecated -- the old name still works until 2.0.0
|
|
55
245
|
const { expiresInSeconds, ttl, download } = opts;
|
|
@@ -58,13 +248,56 @@ export function totalumFiles(options = {}) {
|
|
|
58
248
|
const body = { keys, ttl: expiresInSeconds ?? ttl, download };
|
|
59
249
|
return (await call('POST', '/v1/files/presign', body)).urls;
|
|
60
250
|
},
|
|
61
|
-
/**
|
|
251
|
+
/**
|
|
252
|
+
* Deletes one file, or up to 1,000 at once. The public URL stops working within the hour (edge caches expire).
|
|
253
|
+
* Deleting a list skips keys that are already gone; deleting a single key that does not exist throws.
|
|
254
|
+
*
|
|
255
|
+
* @param keys - One key, or an array of up to 1,000 keys.
|
|
256
|
+
* @returns Nothing once the files are deleted.
|
|
257
|
+
* @throws FILE_NOT_FOUND (404) The single key does not exist.
|
|
258
|
+
* @throws FILE_KEY_FORBIDDEN (403) A key belongs to another project.
|
|
259
|
+
* @throws VALIDATION_ERROR (400) More than 1,000 keys, or an empty list.
|
|
260
|
+
* @example
|
|
261
|
+
* await totalum.files.delete(user.avatar.key);
|
|
262
|
+
* await totalum.files.delete(oldInvoices.map((f) => f.key));
|
|
263
|
+
*/
|
|
62
264
|
async delete(keys) {
|
|
63
265
|
await (Array.isArray(keys) ? call('POST', '/v1/files/delete', { keys }) : call('DELETE', path(keys)));
|
|
64
266
|
},
|
|
65
|
-
/**
|
|
267
|
+
/**
|
|
268
|
+
* The file's bytes as a `Response` (private files included), to read on the server or to return from a route that
|
|
269
|
+
* serves the file after your own permission check. Supports HTTP ranges for partial reads (video seeking).
|
|
270
|
+
*
|
|
271
|
+
* @param key - The file's `key`.
|
|
272
|
+
* @param opts - A byte range to read.
|
|
273
|
+
* @param opts.range - An HTTP `Range` header value, such as `bytes=0-1023`; the answer is then `206` with those bytes.
|
|
274
|
+
* @returns The fetch `Response` with the file's bytes, `content-type` and length.
|
|
275
|
+
* @throws FILE_NOT_FOUND (404) No such file.
|
|
276
|
+
* @throws FILE_KEY_FORBIDDEN (403) The key belongs to another project.
|
|
277
|
+
* @example
|
|
278
|
+
* // src/app/api/contracts/[id]/route.ts — serve a private file to its owner only
|
|
279
|
+
* const contract = await getContractForCurrentUser(params.id); // your own permission check
|
|
280
|
+
* const res = await totalum.files.stream(contract.fileKey);
|
|
281
|
+
* return new Response(res.body, { headers: { 'content-type': res.headers.get('content-type') ?? 'application/pdf' } });
|
|
282
|
+
* @example
|
|
283
|
+
* const res = await totalum.files.stream('p/acme-crm/01M4P0PZXJ0DPQM7R20QVZ0EKC.txt', { range: 'bytes=0-4' });
|
|
284
|
+
* console.log(res.status, await res.text());
|
|
285
|
+
* //=>
|
|
286
|
+
* 206 Hello
|
|
287
|
+
*/
|
|
66
288
|
stream: (key, opts = {}) => raw(path(key), undefined, 'GET', opts.range ? { range: opts.range } : {}),
|
|
67
|
-
/**
|
|
289
|
+
/**
|
|
290
|
+
* The URL of a file, computed locally (no request): the public URL of a public `p/…` key, or for a private `pv/…`
|
|
291
|
+
* key the Totalum API URL that serves it only with the project key (a server-side fetch). To show a private file in
|
|
292
|
+
* a browser use `getSignedUrl` instead.
|
|
293
|
+
*
|
|
294
|
+
* @param key - The file's `key`.
|
|
295
|
+
* @returns The file's URL.
|
|
296
|
+
* @example
|
|
297
|
+
* totalum.files.url('p/acme-crm/01M4P0PZXJ0DPQM7R20QVZ0EKC.png');
|
|
298
|
+
* //=>
|
|
299
|
+
* "https://files.totalum-project.com/p/acme-crm/01M4P0PZXJ0DPQM7R20QVZ0EKC.png"
|
|
300
|
+
*/
|
|
68
301
|
url(key) {
|
|
69
302
|
return key.startsWith('pv/') ? apiUrlOf(options) + path(key) : `${filesUrl()}/${key}`;
|
|
70
303
|
},
|
package/dist/index.d.ts
CHANGED
|
@@ -33,10 +33,10 @@ export { TotalumWeb } from './web/index.js';
|
|
|
33
33
|
import { totalumWebhooks } from './webhooks/index.js';
|
|
34
34
|
export { TotalumWebhookError, TotalumWebhooks, WebhookConfig, WebhookEvent, WebhookSecretOutput, verifyWebhook } from './webhooks/index.js';
|
|
35
35
|
export { D1Database, D1DatabaseSession, D1ExecResult, D1PreparedStatement, D1Result, READ_YOUR_WRITES_COOKIE, TotalumD1ClientCode, TotalumD1Error, TotalumD1ErrorCode, TotalumD1Options, isTotalumD1Error, totalumD1, withTotalumSession } from './d1/index.js';
|
|
36
|
-
export { T as TotalumClientOptions, a as TotalumError, b as TotalumErrorCode, i as isTotalumError } from './_types/errors.d-
|
|
37
|
-
export { C as CheckoutInput, a as CheckoutOutput, b as CheckoutSession, c as CronJob, d as CronJobInput, e as CronJobPatch, f as CronRun, g as CronRunsPage, h as CustomerPortalLinkInput, i as CustomerPortalLinkOutput, E as EmailSendInput, j as EmailSendOutput, k as EmailView, F as FileDescriptor, l as FileUploadUrlInput, m as FileUploadUrlOutput, n as FilesListQuery, o as FilesPage, J as JobCreated, O as OnboardingLinkInput, p as OnboardingLinkOutput, P as PaymentsStatus, q as PdfFromHtmlInput, r as PdfFromUrlInput, s as PdfOutput, R as RefundInput, t as RefundOutput, S as ScanDocumentInput, u as ScanOcrInput, v as ScanOcrOutput, w as ScreenshotInput, x as ScreenshotOutput, y as SeoIndexNowKey, z as SeoNotifyOutput, A as SpeakInput, B as StoredMedia, D as Subscription, G as SubscriptionUpdateInput, T as TranscribeInput, H as TranscribeOutput, W as WebJob, I as WebScrapeOutput, K as WebSearchOutput } from './_types/integrations.d-
|
|
38
|
-
export { L as LogsPage, S as SiteAnalyticsOutput, a as SiteDimension, b as SiteMetric } from './_types/ops.d-
|
|
39
|
-
import './_types/coerce.d-
|
|
36
|
+
export { T as TotalumClientOptions, a as TotalumError, b as TotalumErrorCode, i as isTotalumError } from './_types/errors.d-BPpY5QKu.js';
|
|
37
|
+
export { C as CheckoutInput, a as CheckoutOutput, b as CheckoutSession, c as CronJob, d as CronJobInput, e as CronJobPatch, f as CronRun, g as CronRunsPage, h as CustomerPortalLinkInput, i as CustomerPortalLinkOutput, E as EmailSendInput, j as EmailSendOutput, k as EmailView, F as FileDescriptor, l as FileUploadUrlInput, m as FileUploadUrlOutput, n as FilesListQuery, o as FilesPage, J as JobCreated, O as OnboardingLinkInput, p as OnboardingLinkOutput, P as PaymentsStatus, q as PdfFromHtmlInput, r as PdfFromUrlInput, s as PdfOutput, R as RefundInput, t as RefundOutput, S as ScanDocumentInput, u as ScanOcrInput, v as ScanOcrOutput, w as ScreenshotInput, x as ScreenshotOutput, y as SeoIndexNowKey, z as SeoNotifyOutput, A as SpeakInput, B as StoredMedia, D as Subscription, G as SubscriptionUpdateInput, T as TranscribeInput, H as TranscribeOutput, W as WebJob, I as WebScrapeOutput, K as WebSearchOutput } from './_types/integrations.d-BTZHy48D.js';
|
|
38
|
+
export { L as LogsPage, S as SiteAnalyticsOutput, a as SiteDimension, b as SiteMetric } from './_types/ops.d-Ce5zJyX0.js';
|
|
39
|
+
import './_types/coerce.d-D_rylvPs.js';
|
|
40
40
|
|
|
41
41
|
/** The options of `createTotalum()`: every namespace's options in one object (each falls back to its env var). */
|
|
42
42
|
type TotalumOptions = TotalumAiOptions & TotalumFilesOptions;
|
|
@@ -59,19 +59,34 @@ declare const namespaces: {
|
|
|
59
59
|
web: typeof totalumWeb;
|
|
60
60
|
webhooks: typeof totalumWebhooks;
|
|
61
61
|
};
|
|
62
|
+
/** The type of `totalum` and of `createTotalum()`'s result: one property per namespace. */
|
|
62
63
|
type Totalum = {
|
|
63
64
|
readonly [K in keyof typeof namespaces]: ReturnType<(typeof namespaces)[K]>;
|
|
64
65
|
};
|
|
65
66
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
67
|
+
* Creates a `totalum` object with your own options — another project key, the `dev` environment, a test API URL.
|
|
68
|
+
* Every integration namespace is on it, each built on first access with the same options — no I/O and no env read
|
|
69
|
+
* until a method is called. The database is `totalumD1()` from `totalum-sdk/d1`, not a namespace.
|
|
68
70
|
*
|
|
71
|
+
* @param options - Every namespace's options: `key`, `apiUrl`, `env`, `filesUrl`, `aiBaseUrl`; each falls back to its
|
|
72
|
+
* environment variable.
|
|
73
|
+
* @returns An object with every namespace (`files`, `ai`, `email`, …), like `totalum`.
|
|
69
74
|
* @example
|
|
70
|
-
*
|
|
71
|
-
*
|
|
75
|
+
* import { createTotalum } from 'totalum-sdk';
|
|
76
|
+
*
|
|
77
|
+
* const devTotalum = createTotalum({ env: 'dev' });
|
|
78
|
+
* await devTotalum.email.send({ to: 'ana@example.com', subject: 'Test', html: '<p>Test</p>' });
|
|
72
79
|
*/
|
|
73
80
|
declare function createTotalum(options?: TotalumOptions): Totalum;
|
|
74
|
-
/**
|
|
81
|
+
/**
|
|
82
|
+
* The default instance, configured from the environment (`TOTALUM_PROJECT_KEY`, `TOTALUM_SDK_API_URL`, `TOTALUM_ENV`):
|
|
83
|
+
* import it and call any namespace. Use it in server code only.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* import { totalum } from 'totalum-sdk';
|
|
87
|
+
*
|
|
88
|
+
* const page = await totalum.files.list({ limit: 10 });
|
|
89
|
+
*/
|
|
75
90
|
declare const totalum: Totalum;
|
|
76
91
|
|
|
77
92
|
export { TotalumAiOptions, TotalumFilesOptions, createTotalum, totalum, totalumAi, totalumAnalytics, totalumBrowser, totalumConnections, totalumCron, totalumEmail, totalumFiles, totalumLogs, totalumPayments, totalumPdf, totalumRealtime, totalumScan, totalumSeo, totalumSpeech, totalumVectors, totalumWeb, totalumWebhooks };
|
package/dist/index.js
CHANGED
|
@@ -53,12 +53,18 @@ const namespaces = {
|
|
|
53
53
|
webhooks: totalumWebhooks,
|
|
54
54
|
};
|
|
55
55
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
56
|
+
* Creates a `totalum` object with your own options — another project key, the `dev` environment, a test API URL.
|
|
57
|
+
* Every integration namespace is on it, each built on first access with the same options — no I/O and no env read
|
|
58
|
+
* until a method is called. The database is `totalumD1()` from `totalum-sdk/d1`, not a namespace.
|
|
58
59
|
*
|
|
60
|
+
* @param options - Every namespace's options: `key`, `apiUrl`, `env`, `filesUrl`, `aiBaseUrl`; each falls back to its
|
|
61
|
+
* environment variable.
|
|
62
|
+
* @returns An object with every namespace (`files`, `ai`, `email`, …), like `totalum`.
|
|
59
63
|
* @example
|
|
60
|
-
*
|
|
61
|
-
*
|
|
64
|
+
* import { createTotalum } from 'totalum-sdk';
|
|
65
|
+
*
|
|
66
|
+
* const devTotalum = createTotalum({ env: 'dev' });
|
|
67
|
+
* await devTotalum.email.send({ to: 'ana@example.com', subject: 'Test', html: '<p>Test</p>' });
|
|
62
68
|
*/
|
|
63
69
|
export function createTotalum(options = {}) {
|
|
64
70
|
const built = {};
|
|
@@ -70,5 +76,13 @@ export function createTotalum(options = {}) {
|
|
|
70
76
|
});
|
|
71
77
|
return totalum;
|
|
72
78
|
}
|
|
73
|
-
/**
|
|
79
|
+
/**
|
|
80
|
+
* The default instance, configured from the environment (`TOTALUM_PROJECT_KEY`, `TOTALUM_SDK_API_URL`, `TOTALUM_ENV`):
|
|
81
|
+
* import it and call any namespace. Use it in server code only.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* import { totalum } from 'totalum-sdk';
|
|
85
|
+
*
|
|
86
|
+
* const page = await totalum.files.list({ limit: 10 });
|
|
87
|
+
*/
|
|
74
88
|
export const totalum = /* @__PURE__ */ createTotalum();
|
package/dist/logs/index.d.ts
CHANGED
|
@@ -1,21 +1,59 @@
|
|
|
1
|
-
import { c as LogsQueryInput } from '../_types/ops.d-
|
|
2
|
-
export { L as LogsPage } from '../_types/ops.d-
|
|
3
|
-
import { T as TotalumClientOptions } from '../_types/errors.d-
|
|
4
|
-
export { a as TotalumError, b as TotalumErrorCode, i as isTotalumError } from '../_types/errors.d-
|
|
5
|
-
import '../_types/coerce.d-
|
|
1
|
+
import { c as LogsQueryInput } from '../_types/ops.d-Ce5zJyX0.js';
|
|
2
|
+
export { L as LogsPage } from '../_types/ops.d-Ce5zJyX0.js';
|
|
3
|
+
import { T as TotalumClientOptions } from '../_types/errors.d-BPpY5QKu.js';
|
|
4
|
+
export { a as TotalumError, b as TotalumErrorCode, i as isTotalumError } from '../_types/errors.d-BPpY5QKu.js';
|
|
5
|
+
import '../_types/coerce.d-D_rylvPs.js';
|
|
6
6
|
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* A `logs.query` filter: the time window (default the last hour), level, text, status, path, request id and
|
|
9
|
+
* environment; every field is optional.
|
|
10
|
+
*/
|
|
8
11
|
type LogsQuery = Omit<LogsQueryInput, 'caller' | 'runId'>;
|
|
9
12
|
/**
|
|
10
|
-
* `
|
|
11
|
-
*
|
|
13
|
+
* Creates the `logs` namespace (the same object as `totalum.logs`, scope `logs:read`): the requests the published app
|
|
14
|
+
* (`env: 'live'`) or the preview (`'dev'`) handled, with their `console` lines and errors. Free.
|
|
15
|
+
*
|
|
16
|
+
* @param options - The project key, API URL and environment; each falls back to its environment variable.
|
|
17
|
+
* @returns The `logs` namespace: the method below.
|
|
18
|
+
* @example
|
|
19
|
+
* import { totalumLogs } from 'totalum-sdk/logs';
|
|
20
|
+
*
|
|
21
|
+
* const logs = totalumLogs();
|
|
22
|
+
* const { items } = await logs.query({ level: 'error' });
|
|
12
23
|
*/
|
|
13
24
|
declare function totalumLogs(options?: TotalumClientOptions): {
|
|
14
25
|
/**
|
|
15
|
-
*
|
|
26
|
+
* Reads the app's server logs, newest first: one item per request (or per `console` line), with its level,
|
|
27
|
+
* message, path, status and timings. Use it for an admin "recent errors" page or to debug. `window` in the answer
|
|
28
|
+
* is the window actually searched. Free.
|
|
16
29
|
*
|
|
30
|
+
* @param q - The filters; all optional.
|
|
31
|
+
* @returns Up to `limit` (≤ 500) log items and the window searched.
|
|
32
|
+
* @throws VALIDATION_ERROR (400) A filter has the wrong format (`status` must look like `500` or `5xx`).
|
|
33
|
+
* @throws LOGS_UPSTREAM_ERROR (502) Logs are unavailable; retry shortly.
|
|
17
34
|
* @example
|
|
18
|
-
* const { items } = await logs.query({ level: 'error', env: 'live' });
|
|
35
|
+
* const { items } = await totalum.logs.query({ level: 'error', env: 'live', limit: 2 });
|
|
36
|
+
* //=>
|
|
37
|
+
* {
|
|
38
|
+
* "items": [
|
|
39
|
+
* {
|
|
40
|
+
* "ts": "2026-10-11T17:20:41.118Z",
|
|
41
|
+
* "level": "error",
|
|
42
|
+
* "message": "TypeError: Cannot read properties of undefined (reading 'id')",
|
|
43
|
+
* "requestId": "8f1c2a9e4b7d3c6a",
|
|
44
|
+
* "method": "POST",
|
|
45
|
+
* "path": "/api/orders",
|
|
46
|
+
* "status": 500,
|
|
47
|
+
* "cpuMs": 4.1,
|
|
48
|
+
* "wallMs": 37.9,
|
|
49
|
+
* "outcome": "ok",
|
|
50
|
+
* "exception": { "name": "TypeError", "message": "Cannot read properties of undefined (reading 'id')" }
|
|
51
|
+
* }
|
|
52
|
+
* ],
|
|
53
|
+
* "window": { "from": "2026-10-11T16:38:39.984Z", "to": "2026-10-11T17:38:39.984Z", "source": "live" },
|
|
54
|
+
* "nextCursor": null,
|
|
55
|
+
* "sampled": false
|
|
56
|
+
* }
|
|
19
57
|
*/
|
|
20
58
|
query: (q?: LogsQuery) => Promise<{
|
|
21
59
|
items: {
|
package/dist/logs/index.js
CHANGED
|
@@ -1,17 +1,52 @@
|
|
|
1
1
|
import { jsonClient } from '../http.js';
|
|
2
2
|
export { TotalumError, isTotalumError } from '../errors.js';
|
|
3
3
|
/**
|
|
4
|
-
* `
|
|
5
|
-
*
|
|
4
|
+
* Creates the `logs` namespace (the same object as `totalum.logs`, scope `logs:read`): the requests the published app
|
|
5
|
+
* (`env: 'live'`) or the preview (`'dev'`) handled, with their `console` lines and errors. Free.
|
|
6
|
+
*
|
|
7
|
+
* @param options - The project key, API URL and environment; each falls back to its environment variable.
|
|
8
|
+
* @returns The `logs` namespace: the method below.
|
|
9
|
+
* @example
|
|
10
|
+
* import { totalumLogs } from 'totalum-sdk/logs';
|
|
11
|
+
*
|
|
12
|
+
* const logs = totalumLogs();
|
|
13
|
+
* const { items } = await logs.query({ level: 'error' });
|
|
6
14
|
*/
|
|
7
15
|
export function totalumLogs(options = {}) {
|
|
8
16
|
const call = jsonClient(options);
|
|
9
17
|
return {
|
|
10
18
|
/**
|
|
11
|
-
*
|
|
19
|
+
* Reads the app's server logs, newest first: one item per request (or per `console` line), with its level,
|
|
20
|
+
* message, path, status and timings. Use it for an admin "recent errors" page or to debug. `window` in the answer
|
|
21
|
+
* is the window actually searched. Free.
|
|
12
22
|
*
|
|
23
|
+
* @param q - The filters; all optional.
|
|
24
|
+
* @returns Up to `limit` (≤ 500) log items and the window searched.
|
|
25
|
+
* @throws VALIDATION_ERROR (400) A filter has the wrong format (`status` must look like `500` or `5xx`).
|
|
26
|
+
* @throws LOGS_UPSTREAM_ERROR (502) Logs are unavailable; retry shortly.
|
|
13
27
|
* @example
|
|
14
|
-
* const { items } = await logs.query({ level: 'error', env: 'live' });
|
|
28
|
+
* const { items } = await totalum.logs.query({ level: 'error', env: 'live', limit: 2 });
|
|
29
|
+
* //=>
|
|
30
|
+
* {
|
|
31
|
+
* "items": [
|
|
32
|
+
* {
|
|
33
|
+
* "ts": "2026-10-11T17:20:41.118Z",
|
|
34
|
+
* "level": "error",
|
|
35
|
+
* "message": "TypeError: Cannot read properties of undefined (reading 'id')",
|
|
36
|
+
* "requestId": "8f1c2a9e4b7d3c6a",
|
|
37
|
+
* "method": "POST",
|
|
38
|
+
* "path": "/api/orders",
|
|
39
|
+
* "status": 500,
|
|
40
|
+
* "cpuMs": 4.1,
|
|
41
|
+
* "wallMs": 37.9,
|
|
42
|
+
* "outcome": "ok",
|
|
43
|
+
* "exception": { "name": "TypeError", "message": "Cannot read properties of undefined (reading 'id')" }
|
|
44
|
+
* }
|
|
45
|
+
* ],
|
|
46
|
+
* "window": { "from": "2026-10-11T16:38:39.984Z", "to": "2026-10-11T17:38:39.984Z", "source": "live" },
|
|
47
|
+
* "nextCursor": null,
|
|
48
|
+
* "sampled": false
|
|
49
|
+
* }
|
|
15
50
|
*/
|
|
16
51
|
query: (q = {}) => call('POST', '/v1/logs/query', q),
|
|
17
52
|
};
|