totalum-sdk 0.1.0-dev.4 → 0.1.0-dev.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -3
- package/dist/_types/billing.d-C1exPLN6.d.ts +38 -0
- package/dist/_types/coerce.d-RtY2zQyw.d.ts +6 -0
- package/dist/_types/errors.d-yrue1e9O.d.ts +3057 -0
- package/dist/_types/integrations.d-BKPWost0.d.ts +793 -0
- package/dist/_types/ops.d-BOMT9yln.d.ts +117 -0
- package/dist/ai/index.d.ts +424 -0
- package/dist/ai/index.js +185 -0
- package/dist/analytics/index.d.ts +35 -0
- package/dist/analytics/index.js +15 -0
- package/dist/browser/index.d.ts +1541 -0
- package/dist/browser/index.js +168 -0
- package/dist/cron/index.d.ts +180 -0
- package/dist/cron/index.js +61 -0
- package/dist/d1/errors.js +5 -13
- package/dist/d1/index.d.ts +90 -5
- package/dist/d1/index.js +6 -10
- package/dist/email/index.d.ts +31 -0
- package/dist/email/index.js +30 -0
- package/dist/errors.js +35 -0
- package/dist/files/index.d.ts +119 -0
- package/dist/files/index.js +63 -0
- package/dist/http.js +85 -0
- package/dist/index.d.ts +73 -0
- package/dist/index.js +68 -0
- package/dist/logs/index.d.ts +51 -0
- package/dist/logs/index.js +18 -0
- package/dist/payments/index.d.ts +47 -0
- package/dist/payments/index.js +20 -0
- package/dist/pdf/index.d.ts +42 -0
- package/dist/pdf/index.js +17 -0
- package/dist/realtime/index.d.ts +103 -0
- package/dist/realtime/index.js +30 -0
- package/dist/scan/index.d.ts +46 -0
- package/dist/scan/index.js +12 -0
- package/dist/seo/index.d.ts +23 -0
- package/dist/seo/index.js +12 -0
- package/dist/speech/index.d.ts +41 -0
- package/dist/speech/index.js +22 -0
- package/dist/web/index.d.ts +170 -0
- package/dist/web/index.js +31 -0
- package/dist/webhooks/index.d.ts +48 -0
- package/dist/webhooks/index.js +61 -0
- package/package.json +77 -5
- package/totalum-sdk.md +1055 -0
- package/dist/d1/errors.d.ts +0 -27
- package/dist/d1/https.d.ts +0 -10
- package/dist/d1/lazy.d.ts +0 -7
- package/dist/d1/libsql.d.ts +0 -23
- package/dist/d1/sql.d.ts +0 -9
- package/dist/d1/types.d.ts +0 -72
package/dist/errors.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one error every `totalum-sdk` call throws (plan 05 §7.1): the SDK-API envelope's frozen `errorCode`, the HTTP
|
|
3
|
+
* status and `details`. `TotalumD1Error` (`totalum-sdk/d1`) and `TotalumWebhookError` (`totalum-sdk/webhooks`)
|
|
4
|
+
* extend it, so one `isTotalumError(e)` check covers the whole package.
|
|
5
|
+
*/
|
|
6
|
+
export class TotalumError extends Error {
|
|
7
|
+
name = 'TotalumError';
|
|
8
|
+
errorCode;
|
|
9
|
+
/** HTTP status; 0 for network errors, 500 for client-side refusals. */
|
|
10
|
+
status;
|
|
11
|
+
details;
|
|
12
|
+
/** SDK-API's request id, for support and the logs explorer. */
|
|
13
|
+
requestId;
|
|
14
|
+
constructor(errorCode, message, status = 500, details, requestId) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.errorCode = errorCode;
|
|
17
|
+
this.status = status;
|
|
18
|
+
this.details = details;
|
|
19
|
+
this.requestId = requestId;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export function isTotalumError(e) {
|
|
23
|
+
return e instanceof TotalumError;
|
|
24
|
+
}
|
|
25
|
+
/** Inside workerd: the preview and the published app (A7.14). */
|
|
26
|
+
export const inWorker = () => typeof navigator !== 'undefined' && navigator.userAgent === 'Cloudflare-Workers';
|
|
27
|
+
/**
|
|
28
|
+
* Refuses a Node-only method inside a Worker (plan 05 §7.2b): the message says where the app runs, what was called and
|
|
29
|
+
* the HTTPS replacement; `details {method, replacement, docsUrl}` lets a caller render the hint.
|
|
30
|
+
*/
|
|
31
|
+
export function assertNode(method, replacement, docsUrl) {
|
|
32
|
+
if (!inWorker())
|
|
33
|
+
return;
|
|
34
|
+
throw new TotalumError('NODE_ONLY', `NODE_ONLY: ${method} needs a Node runtime, and your preview and published app both run on Cloudflare Workers. ${replacement} See ${docsUrl}`, 500, { method, replacement, docsUrl });
|
|
35
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { F as FileDescriptor, k as FileUploadUrlInput, m as FilesListQuery } from '../_types/integrations.d-BKPWost0.js';
|
|
2
|
+
export { l as FileUploadUrlOutput, n as FilesPage } from '../_types/integrations.d-BKPWost0.js';
|
|
3
|
+
import { TotalumClientOptions } from '../ai/index.js';
|
|
4
|
+
export { a as TotalumError, b as TotalumErrorCode, i as isTotalumError } from '../_types/errors.d-yrue1e9O.js';
|
|
5
|
+
import '../_types/coerce.d-RtY2zQyw.js';
|
|
6
|
+
|
|
7
|
+
interface TotalumFilesOptions extends TotalumClientOptions {
|
|
8
|
+
/** The public files host; default `TOTALUM_FILES_URL`, else `https://files.totalum-project.com` (A10.1). */
|
|
9
|
+
filesUrl?: string;
|
|
10
|
+
}
|
|
11
|
+
interface UploadOptions {
|
|
12
|
+
name?: string;
|
|
13
|
+
contentType?: string;
|
|
14
|
+
/** `true` stores the file under the private prefix: no public URL, read it through `getSignedUrl` (A10.1). */
|
|
15
|
+
private?: boolean;
|
|
16
|
+
folder?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* `totalum.files` (plan 05 §5; SDK-API plan 04 §5.4) over HTTPS with the project key. Every call returns the file
|
|
20
|
+
* descriptor `{key, fileName, fileSize, contentType, fileUrl, visibility, createdAt}` meant to be stored as-is in the
|
|
21
|
+
* row's file column; failures throw `TotalumError` with SDK-API's frozen code.
|
|
22
|
+
*/
|
|
23
|
+
declare function totalumFiles(options?: TotalumFilesOptions): {
|
|
24
|
+
/** Up to 25 MB through SDK-API; larger files go through `getUploadUrl` + `complete`. */
|
|
25
|
+
upload(input: Blob | ArrayBuffer | Uint8Array | string, opts?: UploadOptions): Promise<FileDescriptor>;
|
|
26
|
+
/** A presigned PUT (15 min, bound to this type and size) for a direct browser/Node upload; then `complete(key)`. */
|
|
27
|
+
getUploadUrl: (input: FileUploadUrlInput) => Promise<{
|
|
28
|
+
uploadUrl: string;
|
|
29
|
+
key: string;
|
|
30
|
+
headers: Record<string, string>;
|
|
31
|
+
expiresAt: string;
|
|
32
|
+
}>;
|
|
33
|
+
/** Registers a file uploaded with `getUploadUrl` and returns its descriptor. */
|
|
34
|
+
complete: (key: string) => Promise<{
|
|
35
|
+
key: string;
|
|
36
|
+
fileName: string;
|
|
37
|
+
fileSize: number;
|
|
38
|
+
contentType: string;
|
|
39
|
+
fileUrl: string | null;
|
|
40
|
+
visibility: "public-by-link" | "private";
|
|
41
|
+
createdAt: string;
|
|
42
|
+
etag?: string | undefined;
|
|
43
|
+
storageClass?: "Standard" | "InfrequentAccess" | undefined;
|
|
44
|
+
name?: string | undefined;
|
|
45
|
+
url?: string | null | undefined;
|
|
46
|
+
size?: number | undefined;
|
|
47
|
+
id?: string | undefined;
|
|
48
|
+
fileNameId?: string | undefined;
|
|
49
|
+
}>;
|
|
50
|
+
/**
|
|
51
|
+
* One page of the project's files, newest first: filter by `folder`, `name`, `type`, created and size ranges; `cursor`
|
|
52
|
+
* from the previous page's `nextCursor`.
|
|
53
|
+
*/
|
|
54
|
+
list: (q?: Partial<Record<keyof FilesListQuery, string | number>>) => Promise<{
|
|
55
|
+
items: {
|
|
56
|
+
key: string;
|
|
57
|
+
fileName: string;
|
|
58
|
+
fileSize: number;
|
|
59
|
+
contentType: string;
|
|
60
|
+
fileUrl: string | null;
|
|
61
|
+
visibility: "public-by-link" | "private";
|
|
62
|
+
createdAt: string;
|
|
63
|
+
etag?: string | undefined;
|
|
64
|
+
storageClass?: "Standard" | "InfrequentAccess" | undefined;
|
|
65
|
+
name?: string | undefined;
|
|
66
|
+
url?: string | null | undefined;
|
|
67
|
+
size?: number | undefined;
|
|
68
|
+
id?: string | undefined;
|
|
69
|
+
fileNameId?: string | undefined;
|
|
70
|
+
}[];
|
|
71
|
+
nextCursor: string | null;
|
|
72
|
+
totalBytes: number;
|
|
73
|
+
fileCount: number;
|
|
74
|
+
}>;
|
|
75
|
+
/** The descriptor of one file; `FILE_NOT_FOUND` (404) when it does not exist. */
|
|
76
|
+
get: (key: string) => Promise<{
|
|
77
|
+
key: string;
|
|
78
|
+
fileName: string;
|
|
79
|
+
fileSize: number;
|
|
80
|
+
contentType: string;
|
|
81
|
+
fileUrl: string | null;
|
|
82
|
+
visibility: "public-by-link" | "private";
|
|
83
|
+
createdAt: string;
|
|
84
|
+
etag?: string | undefined;
|
|
85
|
+
storageClass?: "Standard" | "InfrequentAccess" | undefined;
|
|
86
|
+
name?: string | undefined;
|
|
87
|
+
url?: string | null | undefined;
|
|
88
|
+
size?: number | undefined;
|
|
89
|
+
id?: string | undefined;
|
|
90
|
+
fileNameId?: string | undefined;
|
|
91
|
+
}>;
|
|
92
|
+
/** A presigned GET that R2 verifies: 15 min by default, at most 7 days — the way to hand a private file to a browser. */
|
|
93
|
+
getSignedUrl: (key: string, opts?: {
|
|
94
|
+
expiresInSeconds?: number;
|
|
95
|
+
download?: boolean;
|
|
96
|
+
}) => Promise<string>;
|
|
97
|
+
/** Same as `getSignedUrl`. */
|
|
98
|
+
getDownloadUrl: (key: string, opts?: {
|
|
99
|
+
expiresInSeconds?: number;
|
|
100
|
+
download?: boolean;
|
|
101
|
+
}) => Promise<string>;
|
|
102
|
+
/** Signed GET URLs for many keys at once (`ttl` in seconds, ≤ 7 days). */
|
|
103
|
+
presign(keys: string[], opts?: {
|
|
104
|
+
ttl?: number;
|
|
105
|
+
download?: boolean;
|
|
106
|
+
}): Promise<Record<string, string>>;
|
|
107
|
+
/** Deletes one key, or up to 1000 keys at once. */
|
|
108
|
+
delete(keys: string | string[]): Promise<void>;
|
|
109
|
+
/** The object itself (private files included), with `Range` support; errors throw like every other call. */
|
|
110
|
+
stream: (key: string, opts?: {
|
|
111
|
+
range?: string;
|
|
112
|
+
}) => Promise<Response>;
|
|
113
|
+
/** Sync, no I/O: the public URL of a `p/` key, or the authenticated SDK-API URL of a private `pv/` key. */
|
|
114
|
+
url(key: string): string;
|
|
115
|
+
};
|
|
116
|
+
type TotalumFiles = ReturnType<typeof totalumFiles>;
|
|
117
|
+
|
|
118
|
+
export { FileDescriptor, FileUploadUrlInput, FilesListQuery, totalumFiles };
|
|
119
|
+
export type { TotalumFiles, TotalumFilesOptions, UploadOptions };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { apiUrlOf, jsonClient, query, rawClient, readEnv } from '../http.js';
|
|
2
|
+
export { TotalumError, isTotalumError } from '../errors.js';
|
|
3
|
+
const DEFAULT_FILES_URL = 'https://files.totalum-project.com';
|
|
4
|
+
/**
|
|
5
|
+
* `totalum.files` (plan 05 §5; SDK-API plan 04 §5.4) over HTTPS with the project key. Every call returns the file
|
|
6
|
+
* descriptor `{key, fileName, fileSize, contentType, fileUrl, visibility, createdAt}` meant to be stored as-is in the
|
|
7
|
+
* row's file column; failures throw `TotalumError` with SDK-API's frozen code.
|
|
8
|
+
*/
|
|
9
|
+
export function totalumFiles(options = {}) {
|
|
10
|
+
const call = jsonClient(options);
|
|
11
|
+
const raw = rawClient(options);
|
|
12
|
+
const filesUrl = () => options.filesUrl ?? readEnv('TOTALUM_FILES_URL') ?? DEFAULT_FILES_URL;
|
|
13
|
+
const path = (key) => `/v1/files/${key.split('/').map(encodeURIComponent).join('/')}`;
|
|
14
|
+
const getSignedUrl = async (key, opts = {}) => {
|
|
15
|
+
const q = query({ expiresInSeconds: opts.expiresInSeconds, download: opts.download || undefined });
|
|
16
|
+
return (await call('GET', `${path(key)}/download-url${q}`)).url;
|
|
17
|
+
};
|
|
18
|
+
return {
|
|
19
|
+
/** Up to 25 MB through SDK-API; larger files go through `getUploadUrl` + `complete`. */
|
|
20
|
+
upload(input, opts = {}) {
|
|
21
|
+
const type = opts.contentType ?? (input instanceof Blob ? input.type : '');
|
|
22
|
+
const name = opts.name ?? (input instanceof File ? input.name : 'file');
|
|
23
|
+
const form = new FormData();
|
|
24
|
+
form.set('file', new Blob([input], { type: type || 'application/octet-stream' }), name);
|
|
25
|
+
form.set('name', name);
|
|
26
|
+
if (opts.private)
|
|
27
|
+
form.set('private', 'true');
|
|
28
|
+
if (opts.folder)
|
|
29
|
+
form.set('folder', opts.folder);
|
|
30
|
+
return call('POST', '/v1/files', form);
|
|
31
|
+
},
|
|
32
|
+
/** A presigned PUT (15 min, bound to this type and size) for a direct browser/Node upload; then `complete(key)`. */
|
|
33
|
+
getUploadUrl: (input) => call('POST', '/v1/files/upload-url', input),
|
|
34
|
+
/** Registers a file uploaded with `getUploadUrl` and returns its descriptor. */
|
|
35
|
+
complete: (key) => call('POST', '/v1/files/complete', { key }),
|
|
36
|
+
/**
|
|
37
|
+
* One page of the project's files, newest first: filter by `folder`, `name`, `type`, created and size ranges; `cursor`
|
|
38
|
+
* from the previous page's `nextCursor`.
|
|
39
|
+
*/
|
|
40
|
+
list: (q = {}) => call('GET', `/v1/files${query(q)}`),
|
|
41
|
+
/** The descriptor of one file; `FILE_NOT_FOUND` (404) when it does not exist. */
|
|
42
|
+
get: (key) => call('GET', `${path(key)}/meta`),
|
|
43
|
+
/** A presigned GET that R2 verifies: 15 min by default, at most 7 days — the way to hand a private file to a browser. */
|
|
44
|
+
getSignedUrl,
|
|
45
|
+
/** Same as `getSignedUrl`. */
|
|
46
|
+
getDownloadUrl: getSignedUrl,
|
|
47
|
+
/** Signed GET URLs for many keys at once (`ttl` in seconds, ≤ 7 days). */
|
|
48
|
+
async presign(keys, opts = {}) {
|
|
49
|
+
return (await call('POST', '/v1/files/presign', { keys, ...opts }))
|
|
50
|
+
.urls;
|
|
51
|
+
},
|
|
52
|
+
/** Deletes one key, or up to 1000 keys at once. */
|
|
53
|
+
async delete(keys) {
|
|
54
|
+
await (Array.isArray(keys) ? call('POST', '/v1/files/delete', { keys }) : call('DELETE', path(keys)));
|
|
55
|
+
},
|
|
56
|
+
/** The object itself (private files included), with `Range` support; errors throw like every other call. */
|
|
57
|
+
stream: (key, opts = {}) => raw(path(key), undefined, 'GET', opts.range ? { range: opts.range } : {}),
|
|
58
|
+
/** Sync, no I/O: the public URL of a `p/` key, or the authenticated SDK-API URL of a private `pv/` key. */
|
|
59
|
+
url(key) {
|
|
60
|
+
return key.startsWith('pv/') ? apiUrlOf(options) + path(key) : `${filesUrl()}/${key}`;
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { TotalumError } from './errors.js';
|
|
2
|
+
export const DEFAULT_API_URL = 'https://sdk-api.totalum.app';
|
|
3
|
+
const MISSING_KEY = 'Set TOTALUM_PROJECT_KEY (server-side) or pass { key }.';
|
|
4
|
+
/** `process.env` (Node; workerd with `nodejs_compat`, where OpenNext and Miniflare populate it from bindings); `''` = unset. */
|
|
5
|
+
export function readEnv(name) {
|
|
6
|
+
const value = typeof process === 'undefined' ? undefined : process.env[name];
|
|
7
|
+
return value === '' ? undefined : value;
|
|
8
|
+
}
|
|
9
|
+
/** The project key: the option, else `TOTALUM_PROJECT_KEY`, else `SDK_NOT_CONFIGURED`. Read at call time, never at import. */
|
|
10
|
+
export function projectKey(options) {
|
|
11
|
+
const key = options.key ?? readEnv('TOTALUM_PROJECT_KEY');
|
|
12
|
+
if (key === undefined)
|
|
13
|
+
throw new TotalumError('SDK_NOT_CONFIGURED', MISSING_KEY);
|
|
14
|
+
return key;
|
|
15
|
+
}
|
|
16
|
+
export const apiUrlOf = (options) => options.apiUrl ?? readEnv('TOTALUM_SDK_API_URL') ?? DEFAULT_API_URL;
|
|
17
|
+
export const envOf = (options) => options.env ?? (readEnv('TOTALUM_ENV') === 'dev' ? 'dev' : 'live');
|
|
18
|
+
/** One HTTPS call to SDK-API with the project key; a transport failure is `NETWORK_ERROR`. */
|
|
19
|
+
export async function send(options, method, route, body, extra = {}) {
|
|
20
|
+
const headers = {
|
|
21
|
+
...extra,
|
|
22
|
+
authorization: `Bearer ${projectKey(options)}`,
|
|
23
|
+
'x-totalum-env': envOf(options),
|
|
24
|
+
};
|
|
25
|
+
const form = body instanceof FormData;
|
|
26
|
+
if (body !== undefined && !form)
|
|
27
|
+
headers['content-type'] = 'application/json';
|
|
28
|
+
try {
|
|
29
|
+
return await fetch(apiUrlOf(options) + route, {
|
|
30
|
+
method,
|
|
31
|
+
headers,
|
|
32
|
+
...(body === undefined ? {} : { body: form ? body : JSON.stringify(body) }),
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
throw new TotalumError('NETWORK_ERROR', e instanceof Error ? e.message : String(e), 0);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** The envelope of a response, or the typed error its `errors` carry. */
|
|
40
|
+
export async function envelopeOf(res) {
|
|
41
|
+
let envelope;
|
|
42
|
+
try {
|
|
43
|
+
const parsed = await res.json();
|
|
44
|
+
envelope = parsed;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
throw new TotalumError('RESPONSE_PARSE_ERROR', `HTTP ${String(res.status)} without a JSON envelope`, res.status);
|
|
48
|
+
}
|
|
49
|
+
if (envelope.errors) {
|
|
50
|
+
const details = envelope.errors.errorDetails;
|
|
51
|
+
throw new TotalumError(envelope.errors.errorCode, envelope.errors.errorMessage, res.status, typeof details === 'object' && details !== null ? details : undefined, envelope.metadata?.requestId);
|
|
52
|
+
}
|
|
53
|
+
return envelope;
|
|
54
|
+
}
|
|
55
|
+
/** JSON calls to SDK-API with the project key: the whole envelope, or `TotalumError` with the frozen code. */
|
|
56
|
+
export function envelopeClient(options) {
|
|
57
|
+
return async (method, route, body) => envelopeOf(await send(options, method, route, body));
|
|
58
|
+
}
|
|
59
|
+
/** JSON calls to SDK-API with the project key: the envelope's `data`, or `TotalumError` with the frozen code. */
|
|
60
|
+
export function jsonClient(options) {
|
|
61
|
+
const call = envelopeClient(options);
|
|
62
|
+
return async (method, route, body) => (await call(method, route, body)).data;
|
|
63
|
+
}
|
|
64
|
+
/** A call whose success is not JSON (audio, a stream, a file): the raw `Response`, or the envelope's refusal thrown. */
|
|
65
|
+
export function rawClient(options) {
|
|
66
|
+
return async (route, body, method = 'POST', extra) => {
|
|
67
|
+
const res = await send(options, method, route, body, extra);
|
|
68
|
+
if (!res.ok)
|
|
69
|
+
await envelopeOf(res);
|
|
70
|
+
return res;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** `?a=1&b=2` from the defined entries (arrays joined with commas), or `''`. */
|
|
74
|
+
export function query(params) {
|
|
75
|
+
const q = new URLSearchParams();
|
|
76
|
+
for (const [k, v] of Object.entries(params))
|
|
77
|
+
if (v !== undefined)
|
|
78
|
+
q.set(k, Array.isArray(v) ? v.join(',') : String(v));
|
|
79
|
+
return q.size ? `?${q.toString()}` : '';
|
|
80
|
+
}
|
|
81
|
+
/** `data` + `usage {credits, vendor?, units?}` from `metadata` (plan 11 §0.8: every integration result shows its price). */
|
|
82
|
+
export const withUsage = ({ data, metadata }) => ({
|
|
83
|
+
...data,
|
|
84
|
+
usage: { credits: metadata?.credits ?? 0, ...metadata?.usage },
|
|
85
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { totalumAi, TotalumAiOptions } from './ai/index.js';
|
|
2
|
+
export { AiChatInput, AiEmbedInput, AiEmbedOutput, AiImageEditInput, AiImageInput, AiImageOutput, AiModelsOutput, AiTextOutput, AiVideoCreated, AiVideoInput, AiVideoJob, AiVisionDescribeInput, ChatResult, ChatStream, ChatUsage, TotalumAi } from './ai/index.js';
|
|
3
|
+
import { totalumAnalytics } from './analytics/index.js';
|
|
4
|
+
export { SiteAnalyticsQuery, TotalumAnalytics } from './analytics/index.js';
|
|
5
|
+
import { totalumBrowser } from './browser/index.js';
|
|
6
|
+
export { BrowserActionsOutput, BrowserCommand, BrowserCommandResult, BrowserCommands, BrowserProgram, BrowserProgramStatus, BrowserSession, BrowserSessionCreated, BrowserSessionInput, BrowserSessionStatus, TotalumBrowser } from './browser/index.js';
|
|
7
|
+
import { totalumCron } from './cron/index.js';
|
|
8
|
+
export { TotalumCron } from './cron/index.js';
|
|
9
|
+
import { totalumEmail } from './email/index.js';
|
|
10
|
+
export { TotalumEmail } from './email/index.js';
|
|
11
|
+
import { totalumFiles, TotalumFilesOptions } from './files/index.js';
|
|
12
|
+
export { TotalumFiles, UploadOptions } from './files/index.js';
|
|
13
|
+
import { totalumLogs } from './logs/index.js';
|
|
14
|
+
export { LogsQuery, TotalumLogs } from './logs/index.js';
|
|
15
|
+
import { totalumPayments } from './payments/index.js';
|
|
16
|
+
export { TotalumPayments } from './payments/index.js';
|
|
17
|
+
import { totalumPdf } from './pdf/index.js';
|
|
18
|
+
export { TotalumPdf } from './pdf/index.js';
|
|
19
|
+
import { totalumRealtime } from './realtime/index.js';
|
|
20
|
+
export { RealtimePublishInput, RealtimePublishOutput, RealtimeTicketInput, RealtimeTicketOutput, TotalumRealtime } from './realtime/index.js';
|
|
21
|
+
import { totalumScan } from './scan/index.js';
|
|
22
|
+
export { ScanDocumentResult, TotalumScan } from './scan/index.js';
|
|
23
|
+
import { totalumSeo } from './seo/index.js';
|
|
24
|
+
export { TotalumSeo } from './seo/index.js';
|
|
25
|
+
import { totalumSpeech } from './speech/index.js';
|
|
26
|
+
export { TotalumSpeech } from './speech/index.js';
|
|
27
|
+
import { totalumWeb } from './web/index.js';
|
|
28
|
+
export { TotalumWeb } from './web/index.js';
|
|
29
|
+
import { totalumWebhooks } from './webhooks/index.js';
|
|
30
|
+
export { TotalumWebhookError, TotalumWebhooks, verifyWebhook } from './webhooks/index.js';
|
|
31
|
+
export { D1Database, D1DatabaseSession, D1ExecResult, D1PreparedStatement, D1Result, TotalumD1ClientCode, TotalumD1Error, TotalumD1ErrorCode, TotalumD1Options, isTotalumD1Error, totalumD1 } from './d1/index.js';
|
|
32
|
+
export { T as TotalumClientOptions, a as TotalumError, b as TotalumErrorCode, i as isTotalumError } from './_types/errors.d-yrue1e9O.js';
|
|
33
|
+
export { C as CheckoutInput, a as CheckoutOutput, b as CronJob, c as CronJobInput, d as CronJobPatch, e as CronRun, f as CronRunsPage, g as CustomerPortalLinkInput, h as CustomerPortalLinkOutput, E as EmailSendInput, i as EmailSendOutput, j as EmailView, F as FileDescriptor, k as FileUploadUrlInput, l as FileUploadUrlOutput, m as FilesListQuery, n as FilesPage, J as JobCreated, O as OnboardingLinkInput, o as OnboardingLinkOutput, P as PaymentsStatus, p as PdfFromHtmlInput, q as PdfFromUrlInput, r as PdfOutput, S as ScanDocumentInput, s as ScanOcrInput, t as ScanOcrOutput, u as ScreenshotInput, v as ScreenshotOutput, w as SeoIndexNowKey, x as SeoNotifyOutput, y as SpeakInput, z as StoredMedia, T as TranscribeInput, A as TranscribeOutput, W as WebJob, B as WebScrapeOutput, D as WebSearchOutput } from './_types/integrations.d-BKPWost0.js';
|
|
34
|
+
export { L as LogsPage, S as SiteAnalyticsOutput, a as SiteDimension, b as SiteMetric } from './_types/ops.d-BOMT9yln.js';
|
|
35
|
+
export { W as WebhookConfig, a as WebhookEvent, b as WebhookSecretOutput } from './_types/billing.d-C1exPLN6.js';
|
|
36
|
+
import './_types/coerce.d-RtY2zQyw.js';
|
|
37
|
+
|
|
38
|
+
/** The options of `createTotalum()`: every namespace's options in one object (each falls back to its env var). */
|
|
39
|
+
type TotalumOptions = TotalumAiOptions & TotalumFilesOptions;
|
|
40
|
+
declare const namespaces: {
|
|
41
|
+
ai: typeof totalumAi;
|
|
42
|
+
analytics: typeof totalumAnalytics;
|
|
43
|
+
browser: typeof totalumBrowser;
|
|
44
|
+
cron: typeof totalumCron;
|
|
45
|
+
email: typeof totalumEmail;
|
|
46
|
+
files: typeof totalumFiles;
|
|
47
|
+
logs: typeof totalumLogs;
|
|
48
|
+
payments: typeof totalumPayments;
|
|
49
|
+
pdf: typeof totalumPdf;
|
|
50
|
+
realtime: typeof totalumRealtime;
|
|
51
|
+
scan: typeof totalumScan;
|
|
52
|
+
seo: typeof totalumSeo;
|
|
53
|
+
speech: typeof totalumSpeech;
|
|
54
|
+
web: typeof totalumWeb;
|
|
55
|
+
webhooks: typeof totalumWebhooks;
|
|
56
|
+
};
|
|
57
|
+
type Totalum = {
|
|
58
|
+
readonly [K in keyof typeof namespaces]: ReturnType<(typeof namespaces)[K]>;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Every integration namespace on one object (plan 05 §2.1), each built on first access with the same options — no I/O
|
|
62
|
+
* and no env read until a method is called. The database is `totalumD1()` from `totalum-sdk/d1`, not a namespace.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* const totalum = createTotalum({ env: 'dev' });
|
|
66
|
+
* await totalum.email.send({ to: 'a@b.c', subject: 'Hi', html: '<p>Hi</p>' });
|
|
67
|
+
*/
|
|
68
|
+
declare function createTotalum(options?: TotalumOptions): Totalum;
|
|
69
|
+
/** The default instance, configured from the environment (`TOTALUM_PROJECT_KEY`, `TOTALUM_SDK_API_URL`, `TOTALUM_ENV`). */
|
|
70
|
+
declare const totalum: Totalum;
|
|
71
|
+
|
|
72
|
+
export { TotalumAiOptions, TotalumFilesOptions, createTotalum, totalum, totalumAi, totalumAnalytics, totalumBrowser, totalumCron, totalumEmail, totalumFiles, totalumLogs, totalumPayments, totalumPdf, totalumRealtime, totalumScan, totalumSeo, totalumSpeech, totalumWeb, totalumWebhooks };
|
|
73
|
+
export type { Totalum, TotalumOptions };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { totalumAi } from './ai/index.js';
|
|
2
|
+
import { totalumAnalytics } from './analytics/index.js';
|
|
3
|
+
import { totalumBrowser } from './browser/index.js';
|
|
4
|
+
import { totalumCron } from './cron/index.js';
|
|
5
|
+
import { totalumEmail } from './email/index.js';
|
|
6
|
+
import { totalumFiles } from './files/index.js';
|
|
7
|
+
import { totalumLogs } from './logs/index.js';
|
|
8
|
+
import { totalumPayments } from './payments/index.js';
|
|
9
|
+
import { totalumPdf } from './pdf/index.js';
|
|
10
|
+
import { totalumRealtime } from './realtime/index.js';
|
|
11
|
+
import { totalumScan } from './scan/index.js';
|
|
12
|
+
import { totalumSeo } from './seo/index.js';
|
|
13
|
+
import { totalumSpeech } from './speech/index.js';
|
|
14
|
+
import { totalumWeb } from './web/index.js';
|
|
15
|
+
import { totalumWebhooks } from './webhooks/index.js';
|
|
16
|
+
export * from './ai/index.js';
|
|
17
|
+
export * from './analytics/index.js';
|
|
18
|
+
export * from './browser/index.js';
|
|
19
|
+
export * from './cron/index.js';
|
|
20
|
+
export * from './d1/index.js';
|
|
21
|
+
export * from './email/index.js';
|
|
22
|
+
export * from './files/index.js';
|
|
23
|
+
export * from './logs/index.js';
|
|
24
|
+
export * from './payments/index.js';
|
|
25
|
+
export * from './pdf/index.js';
|
|
26
|
+
export * from './realtime/index.js';
|
|
27
|
+
export * from './scan/index.js';
|
|
28
|
+
export * from './seo/index.js';
|
|
29
|
+
export * from './speech/index.js';
|
|
30
|
+
export * from './web/index.js';
|
|
31
|
+
export * from './webhooks/index.js';
|
|
32
|
+
const namespaces = {
|
|
33
|
+
ai: totalumAi,
|
|
34
|
+
analytics: totalumAnalytics,
|
|
35
|
+
browser: totalumBrowser,
|
|
36
|
+
cron: totalumCron,
|
|
37
|
+
email: totalumEmail,
|
|
38
|
+
files: totalumFiles,
|
|
39
|
+
logs: totalumLogs,
|
|
40
|
+
payments: totalumPayments,
|
|
41
|
+
pdf: totalumPdf,
|
|
42
|
+
realtime: totalumRealtime,
|
|
43
|
+
scan: totalumScan,
|
|
44
|
+
seo: totalumSeo,
|
|
45
|
+
speech: totalumSpeech,
|
|
46
|
+
web: totalumWeb,
|
|
47
|
+
webhooks: totalumWebhooks,
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Every integration namespace on one object (plan 05 §2.1), each built on first access with the same options — no I/O
|
|
51
|
+
* and no env read until a method is called. The database is `totalumD1()` from `totalum-sdk/d1`, not a namespace.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* const totalum = createTotalum({ env: 'dev' });
|
|
55
|
+
* await totalum.email.send({ to: 'a@b.c', subject: 'Hi', html: '<p>Hi</p>' });
|
|
56
|
+
*/
|
|
57
|
+
export function createTotalum(options = {}) {
|
|
58
|
+
const built = {};
|
|
59
|
+
const totalum = {};
|
|
60
|
+
for (const name of Object.keys(namespaces))
|
|
61
|
+
Object.defineProperty(totalum, name, {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
get: () => (built[name] ??= namespaces[name](options)),
|
|
64
|
+
});
|
|
65
|
+
return totalum;
|
|
66
|
+
}
|
|
67
|
+
/** The default instance, configured from the environment (`TOTALUM_PROJECT_KEY`, `TOTALUM_SDK_API_URL`, `TOTALUM_ENV`). */
|
|
68
|
+
export const totalum = /* @__PURE__ */ createTotalum();
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { c as LogsQueryInput } from '../_types/ops.d-BOMT9yln.js';
|
|
2
|
+
export { L as LogsPage } from '../_types/ops.d-BOMT9yln.js';
|
|
3
|
+
import { T as TotalumClientOptions } from '../_types/errors.d-yrue1e9O.js';
|
|
4
|
+
export { a as TotalumError, i as isTotalumError } from '../_types/errors.d-yrue1e9O.js';
|
|
5
|
+
import '../_types/coerce.d-RtY2zQyw.js';
|
|
6
|
+
|
|
7
|
+
/** A `logs.query` filter: the window (default the last hour), level, substring, status class, path, request id, env. */
|
|
8
|
+
type LogsQuery = Omit<LogsQueryInput, 'caller' | 'runId'>;
|
|
9
|
+
/**
|
|
10
|
+
* `totalum.logs` (plan 05 §6.11) over SDK-API `/v1/logs` (scope `logs:read`; the agent's sandbox key reads its dev
|
|
11
|
+
* preview for free): the Worker invocations of the published app (`env: 'live'`) or the preview (`'dev'`). Free.
|
|
12
|
+
*/
|
|
13
|
+
declare function totalumLogs(options?: TotalumClientOptions): {
|
|
14
|
+
/**
|
|
15
|
+
* Up to `limit` (≤ 500) log lines, newest first; `window` is always the window actually searched.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* const { items } = await logs.query({ level: 'error', env: 'live' });
|
|
19
|
+
*/
|
|
20
|
+
query: (q?: LogsQuery) => Promise<{
|
|
21
|
+
items: {
|
|
22
|
+
ts: string;
|
|
23
|
+
level: "error" | "log" | "debug" | "info" | "warn";
|
|
24
|
+
message: string;
|
|
25
|
+
requestId: string | null;
|
|
26
|
+
method: string | null;
|
|
27
|
+
path: string | null;
|
|
28
|
+
status: number | null;
|
|
29
|
+
cpuMs: number | null;
|
|
30
|
+
wallMs: number | null;
|
|
31
|
+
outcome: string;
|
|
32
|
+
exception?: {
|
|
33
|
+
name: string;
|
|
34
|
+
message: string;
|
|
35
|
+
stack?: string | undefined;
|
|
36
|
+
} | undefined;
|
|
37
|
+
}[];
|
|
38
|
+
window: {
|
|
39
|
+
from: string;
|
|
40
|
+
to: string;
|
|
41
|
+
source: "live" | "buffer";
|
|
42
|
+
};
|
|
43
|
+
nextCursor: string | null;
|
|
44
|
+
sampled: boolean;
|
|
45
|
+
hint?: string | undefined;
|
|
46
|
+
}>;
|
|
47
|
+
};
|
|
48
|
+
type TotalumLogs = ReturnType<typeof totalumLogs>;
|
|
49
|
+
|
|
50
|
+
export { TotalumClientOptions, totalumLogs };
|
|
51
|
+
export type { LogsQuery, TotalumLogs };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsonClient } from '../http.js';
|
|
2
|
+
export { TotalumError, isTotalumError } from '../errors.js';
|
|
3
|
+
/**
|
|
4
|
+
* `totalum.logs` (plan 05 §6.11) over SDK-API `/v1/logs` (scope `logs:read`; the agent's sandbox key reads its dev
|
|
5
|
+
* preview for free): the Worker invocations of the published app (`env: 'live'`) or the preview (`'dev'`). Free.
|
|
6
|
+
*/
|
|
7
|
+
export function totalumLogs(options = {}) {
|
|
8
|
+
const call = jsonClient(options);
|
|
9
|
+
return {
|
|
10
|
+
/**
|
|
11
|
+
* Up to `limit` (≤ 500) log lines, newest first; `window` is always the window actually searched.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const { items } = await logs.query({ level: 'error', env: 'live' });
|
|
15
|
+
*/
|
|
16
|
+
query: (q = {}) => call('POST', '/v1/logs/query', q),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { O as OnboardingLinkInput, C as CheckoutInput, g as CustomerPortalLinkInput } from '../_types/integrations.d-BKPWost0.js';
|
|
2
|
+
export { a as CheckoutOutput, h as CustomerPortalLinkOutput, o as OnboardingLinkOutput, P as PaymentsStatus } from '../_types/integrations.d-BKPWost0.js';
|
|
3
|
+
import { T as TotalumClientOptions } from '../_types/errors.d-yrue1e9O.js';
|
|
4
|
+
export { a as TotalumError, i as isTotalumError } from '../_types/errors.d-yrue1e9O.js';
|
|
5
|
+
import '../_types/coerce.d-RtY2zQyw.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* `totalum.payments` (plan 05, plan 11 §9.5) over SDK-API `/v1/payments/*` with a project key (scope `payments`): Stripe
|
|
9
|
+
* Connect direct charges on the project's own connected account. Card data never passes through here — send buyers to
|
|
10
|
+
* the hosted Checkout `url` (SAQ-A); SDK-API refuses card fields with `CARD_DATA_NOT_ACCEPTED`.
|
|
11
|
+
*/
|
|
12
|
+
declare function totalumPayments(options?: TotalumClientOptions): {
|
|
13
|
+
/** Whether the project's Stripe account can take payments (charges, payouts, pending requirements). */
|
|
14
|
+
getStatus: () => Promise<{
|
|
15
|
+
enabled: boolean;
|
|
16
|
+
mode: "connect" | "own_key";
|
|
17
|
+
accountId: string | null;
|
|
18
|
+
livemode: boolean;
|
|
19
|
+
chargesEnabled: boolean;
|
|
20
|
+
payoutsEnabled: boolean;
|
|
21
|
+
detailsSubmitted: boolean;
|
|
22
|
+
requirements: {
|
|
23
|
+
currentlyDue: string[];
|
|
24
|
+
pastDue: string[];
|
|
25
|
+
eventuallyDue: string[];
|
|
26
|
+
};
|
|
27
|
+
applicationFeeBps: number;
|
|
28
|
+
}>;
|
|
29
|
+
/** Stripe's hosted onboarding for the project owner (single use; never for the agent's sandbox key). */
|
|
30
|
+
onboardingLink: (input: OnboardingLinkInput) => Promise<{
|
|
31
|
+
url: string;
|
|
32
|
+
expiresAt: string;
|
|
33
|
+
}>;
|
|
34
|
+
/** A hosted Checkout Session: `payment`, `subscription`, or `setup` (save a card for later). Redirect to `url`. */
|
|
35
|
+
createCheckout: (input: CheckoutInput) => Promise<{
|
|
36
|
+
id: string;
|
|
37
|
+
url: string;
|
|
38
|
+
}>;
|
|
39
|
+
/** Stripe's hosted portal where a customer manages their subscriptions and saved cards. */
|
|
40
|
+
customerPortalLink: (input: CustomerPortalLinkInput) => Promise<{
|
|
41
|
+
url: string;
|
|
42
|
+
}>;
|
|
43
|
+
};
|
|
44
|
+
type TotalumPayments = ReturnType<typeof totalumPayments>;
|
|
45
|
+
|
|
46
|
+
export { CheckoutInput, CustomerPortalLinkInput, OnboardingLinkInput, TotalumClientOptions, totalumPayments };
|
|
47
|
+
export type { TotalumPayments };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsonClient } from '../http.js';
|
|
2
|
+
export { TotalumError, isTotalumError } from '../errors.js';
|
|
3
|
+
/**
|
|
4
|
+
* `totalum.payments` (plan 05, plan 11 §9.5) over SDK-API `/v1/payments/*` with a project key (scope `payments`): Stripe
|
|
5
|
+
* Connect direct charges on the project's own connected account. Card data never passes through here — send buyers to
|
|
6
|
+
* the hosted Checkout `url` (SAQ-A); SDK-API refuses card fields with `CARD_DATA_NOT_ACCEPTED`.
|
|
7
|
+
*/
|
|
8
|
+
export function totalumPayments(options = {}) {
|
|
9
|
+
const call = jsonClient(options);
|
|
10
|
+
return {
|
|
11
|
+
/** Whether the project's Stripe account can take payments (charges, payouts, pending requirements). */
|
|
12
|
+
getStatus: () => call('GET', '/v1/payments/status'),
|
|
13
|
+
/** Stripe's hosted onboarding for the project owner (single use; never for the agent's sandbox key). */
|
|
14
|
+
onboardingLink: (input) => call('POST', '/v1/payments/onboarding-link', input),
|
|
15
|
+
/** A hosted Checkout Session: `payment`, `subscription`, or `setup` (save a card for later). Redirect to `url`. */
|
|
16
|
+
createCheckout: (input) => call('POST', '/v1/payments/checkout', input),
|
|
17
|
+
/** Stripe's hosted portal where a customer manages their subscriptions and saved cards. */
|
|
18
|
+
customerPortalLink: (input) => call('POST', '/v1/payments/customer-portal-link', input),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { p as PdfFromHtmlInput, q as PdfFromUrlInput } from '../_types/integrations.d-BKPWost0.js';
|
|
2
|
+
export { r as PdfOutput } from '../_types/integrations.d-BKPWost0.js';
|
|
3
|
+
import { T as TotalumClientOptions } from '../_types/errors.d-yrue1e9O.js';
|
|
4
|
+
export { a as TotalumError, i as isTotalumError } from '../_types/errors.d-yrue1e9O.js';
|
|
5
|
+
import '../_types/coerce.d-RtY2zQyw.js';
|
|
6
|
+
|
|
7
|
+
/** `totalum.pdf` (plan 04 §5.5) over `/v1/pdf/*` (scope `files:write`): a new file in the project's storage each time. */
|
|
8
|
+
declare function totalumPdf(options?: TotalumClientOptions): {
|
|
9
|
+
/**
|
|
10
|
+
* A PDF rendered from HTML, stored as a project file (`key`, `url`).
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const { url } = await pdf.fromHtml({ html: '<h1>Invoice 12</h1>', name: 'invoice-12' });
|
|
14
|
+
*/
|
|
15
|
+
fromHtml: (input: PdfFromHtmlInput) => Promise<{
|
|
16
|
+
url: string;
|
|
17
|
+
fileName: string;
|
|
18
|
+
key: string;
|
|
19
|
+
} & {
|
|
20
|
+
usage: {
|
|
21
|
+
vendor?: string | undefined;
|
|
22
|
+
units?: number | undefined;
|
|
23
|
+
credits: number;
|
|
24
|
+
};
|
|
25
|
+
}>;
|
|
26
|
+
/** A PDF of a web page, stored as a project file. */
|
|
27
|
+
fromUrl: (input: PdfFromUrlInput) => Promise<{
|
|
28
|
+
url: string;
|
|
29
|
+
fileName: string;
|
|
30
|
+
key: string;
|
|
31
|
+
} & {
|
|
32
|
+
usage: {
|
|
33
|
+
vendor?: string | undefined;
|
|
34
|
+
units?: number | undefined;
|
|
35
|
+
credits: number;
|
|
36
|
+
};
|
|
37
|
+
}>;
|
|
38
|
+
};
|
|
39
|
+
type TotalumPdf = ReturnType<typeof totalumPdf>;
|
|
40
|
+
|
|
41
|
+
export { PdfFromHtmlInput, PdfFromUrlInput, TotalumClientOptions, totalumPdf };
|
|
42
|
+
export type { TotalumPdf };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { envelopeClient, withUsage } from '../http.js';
|
|
2
|
+
export { TotalumError, isTotalumError } from '../errors.js';
|
|
3
|
+
/** `totalum.pdf` (plan 04 §5.5) over `/v1/pdf/*` (scope `files:write`): a new file in the project's storage each time. */
|
|
4
|
+
export function totalumPdf(options = {}) {
|
|
5
|
+
const call = envelopeClient(options);
|
|
6
|
+
return {
|
|
7
|
+
/**
|
|
8
|
+
* A PDF rendered from HTML, stored as a project file (`key`, `url`).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const { url } = await pdf.fromHtml({ html: '<h1>Invoice 12</h1>', name: 'invoice-12' });
|
|
12
|
+
*/
|
|
13
|
+
fromHtml: async (input) => withUsage(await call('POST', '/v1/pdf/from-html', input)),
|
|
14
|
+
/** A PDF of a web page, stored as a project file. */
|
|
15
|
+
fromUrl: async (input) => withUsage(await call('POST', '/v1/pdf/from-url', input)),
|
|
16
|
+
};
|
|
17
|
+
}
|