totalum-sdk 0.1.0-dev.10

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.
Files changed (53) hide show
  1. package/README.md +18 -0
  2. package/dist/_types/billing.d-BbSZh1wY.d.ts +38 -0
  3. package/dist/_types/coerce.d-C0KIW76L.d.ts +6 -0
  4. package/dist/_types/errors.d-Cu3q_E_r.d.ts +3093 -0
  5. package/dist/_types/integrations.d-BNGV70e3.d.ts +793 -0
  6. package/dist/_types/ops.d-C9375KIG.d.ts +117 -0
  7. package/dist/ai/index.d.ts +424 -0
  8. package/dist/ai/index.js +185 -0
  9. package/dist/analytics/index.d.ts +35 -0
  10. package/dist/analytics/index.js +15 -0
  11. package/dist/browser/index.d.ts +1595 -0
  12. package/dist/browser/index.js +168 -0
  13. package/dist/cron/index.d.ts +180 -0
  14. package/dist/cron/index.js +61 -0
  15. package/dist/d1/errors.js +31 -0
  16. package/dist/d1/https.js +103 -0
  17. package/dist/d1/index.d.ts +107 -0
  18. package/dist/d1/index.js +73 -0
  19. package/dist/d1/lazy.js +112 -0
  20. package/dist/d1/libsql.js +125 -0
  21. package/dist/d1/session.js +38 -0
  22. package/dist/d1/sql.js +87 -0
  23. package/dist/d1/types.js +1 -0
  24. package/dist/email/index.d.ts +31 -0
  25. package/dist/email/index.js +30 -0
  26. package/dist/errors.js +35 -0
  27. package/dist/files/index.d.ts +119 -0
  28. package/dist/files/index.js +63 -0
  29. package/dist/http.js +85 -0
  30. package/dist/index.d.ts +73 -0
  31. package/dist/index.js +68 -0
  32. package/dist/logs/index.d.ts +51 -0
  33. package/dist/logs/index.js +18 -0
  34. package/dist/payments/index.d.ts +47 -0
  35. package/dist/payments/index.js +20 -0
  36. package/dist/pdf/index.d.ts +42 -0
  37. package/dist/pdf/index.js +17 -0
  38. package/dist/react/index.d.ts +91 -0
  39. package/dist/react/index.js +178 -0
  40. package/dist/realtime/index.d.ts +103 -0
  41. package/dist/realtime/index.js +30 -0
  42. package/dist/scan/index.d.ts +46 -0
  43. package/dist/scan/index.js +12 -0
  44. package/dist/seo/index.d.ts +23 -0
  45. package/dist/seo/index.js +12 -0
  46. package/dist/speech/index.d.ts +41 -0
  47. package/dist/speech/index.js +22 -0
  48. package/dist/web/index.d.ts +170 -0
  49. package/dist/web/index.js +31 -0
  50. package/dist/webhooks/index.d.ts +48 -0
  51. package/dist/webhooks/index.js +61 -0
  52. package/package.json +146 -0
  53. package/totalum-sdk.md +1088 -0
@@ -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
+ });
@@ -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, READ_YOUR_WRITES_COOKIE, TotalumD1ClientCode, TotalumD1Error, TotalumD1ErrorCode, TotalumD1Options, isTotalumD1Error, totalumD1, withTotalumSession } from './d1/index.js';
32
+ export { T as TotalumClientOptions, a as TotalumError, b as TotalumErrorCode, i as isTotalumError } from './_types/errors.d-Cu3q_E_r.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-BNGV70e3.js';
34
+ export { L as LogsPage, S as SiteAnalyticsOutput, a as SiteDimension, b as SiteMetric } from './_types/ops.d-C9375KIG.js';
35
+ export { W as WebhookConfig, a as WebhookEvent, b as WebhookSecretOutput } from './_types/billing.d-BbSZh1wY.js';
36
+ import './_types/coerce.d-C0KIW76L.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-C9375KIG.js';
2
+ export { L as LogsPage } from '../_types/ops.d-C9375KIG.js';
3
+ import { T as TotalumClientOptions } from '../_types/errors.d-Cu3q_E_r.js';
4
+ export { a as TotalumError, i as isTotalumError } from '../_types/errors.d-Cu3q_E_r.js';
5
+ import '../_types/coerce.d-C0KIW76L.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-BNGV70e3.js';
2
+ export { a as CheckoutOutput, h as CustomerPortalLinkOutput, o as OnboardingLinkOutput, P as PaymentsStatus } from '../_types/integrations.d-BNGV70e3.js';
3
+ import { T as TotalumClientOptions } from '../_types/errors.d-Cu3q_E_r.js';
4
+ export { a as TotalumError, i as isTotalumError } from '../_types/errors.d-Cu3q_E_r.js';
5
+ import '../_types/coerce.d-C0KIW76L.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-BNGV70e3.js';
2
+ export { r as PdfOutput } from '../_types/integrations.d-BNGV70e3.js';
3
+ import { T as TotalumClientOptions } from '../_types/errors.d-Cu3q_E_r.js';
4
+ export { a as TotalumError, i as isTotalumError } from '../_types/errors.d-Cu3q_E_r.js';
5
+ import '../_types/coerce.d-C0KIW76L.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
+ }
@@ -0,0 +1,91 @@
1
+ /**
2
+ * `totalum-sdk/react` (plan 06 §12.5, A6.33): the browser side of `totalum.realtime`. The page never holds a key: it
3
+ * asks the app's own server for a ticket (`POST ticketUrl {room}`, default `/api/realtime/ticket`), opens the room's
4
+ * socket, and on every drop — a Totalum deploy drops them all — re-tickets and reconnects with backoff. Presence is
5
+ * built on the same socket: `presence:*` messages plus a 30 s heartbeat (a room with present users stays awake).
6
+ */
7
+ type RealtimeStatus = 'connecting' | 'open' | 'reconnecting' | 'closed';
8
+ interface RealtimeMessage<T = unknown> {
9
+ id: string;
10
+ event: string;
11
+ identity: {
12
+ id: string;
13
+ name?: string;
14
+ };
15
+ data: T;
16
+ ts: string;
17
+ }
18
+ interface RealtimePeer<M = Record<string, unknown>> {
19
+ /** One per open socket: the same user in two tabs is two peers with the same `identity`. */
20
+ connectionId: string;
21
+ identity: {
22
+ id: string;
23
+ name?: string;
24
+ };
25
+ meta: M;
26
+ }
27
+ interface RealtimeChannelOptions<M = Record<string, unknown>> {
28
+ /** The app's route that mints the ticket; it receives `{ room }` and answers `{ url }` or `{ data: { url } }`. */
29
+ ticketUrl?: string;
30
+ /** Or mint the ticket yourself. */
31
+ getTicket?: (room: string) => Promise<{
32
+ url: string;
33
+ }>;
34
+ /** Announce this connection's presence with this metadata (name, colour…); `others` lists everyone else's. */
35
+ presence?: M;
36
+ /** Messages kept in memory, newest last (default 100). */
37
+ keep?: number;
38
+ /** Tests only. */
39
+ WebSocket?: typeof WebSocket;
40
+ }
41
+ interface RealtimeSnapshot<M = Record<string, unknown>> {
42
+ status: RealtimeStatus;
43
+ messages: RealtimeMessage[];
44
+ others: RealtimePeer<M>[];
45
+ }
46
+ /** One room, one socket; framework-free (the hook below is a thin wrapper). */
47
+ declare class RealtimeChannel<M = Record<string, unknown>> {
48
+ readonly room: string;
49
+ private readonly options;
50
+ private ws;
51
+ private stopped;
52
+ private attempt;
53
+ private timer;
54
+ private heartbeat;
55
+ private readonly peers;
56
+ private readonly listeners;
57
+ private readonly connectionId;
58
+ private snapshot;
59
+ constructor(room: string, options?: RealtimeChannelOptions<M>);
60
+ subscribe: (listener: () => void) => (() => void);
61
+ getSnapshot: () => RealtimeSnapshot<M>;
62
+ connect(): void;
63
+ /** Sends `data` to everyone in the room (you included); `false` when the socket is not open. */
64
+ publish: (data: unknown, event?: string) => boolean;
65
+ close(): void;
66
+ private open;
67
+ private ticket;
68
+ /** A drop is normal (every deploy drops every socket): re-ticket and reconnect, 0.5 s … 30 s apart. */
69
+ private retry;
70
+ private send;
71
+ private receive;
72
+ /** Peers whose socket dropped without a goodbye disappear after 75 s of silence. */
73
+ private expire;
74
+ private set;
75
+ }
76
+ /**
77
+ * A room in a client component: `status`, the `messages` received since it opened, `others` (with `presence`), and
78
+ * `publish(data, event?)`. Render `status === 'reconnecting'` as an ordinary state, not an error.
79
+ *
80
+ * @example
81
+ * const { messages, others, publish, status } = useRealtimeChannel(`chat:${roomId}`, { presence: { name } });
82
+ */
83
+ declare function useRealtimeChannel<M = Record<string, unknown>>(room: string, options?: RealtimeChannelOptions<M>): {
84
+ publish: (data: unknown, event?: string) => boolean;
85
+ status: RealtimeStatus;
86
+ messages: RealtimeMessage[];
87
+ others: RealtimePeer<M>[];
88
+ };
89
+
90
+ export { RealtimeChannel, useRealtimeChannel };
91
+ export type { RealtimeChannelOptions, RealtimeMessage, RealtimePeer, RealtimeSnapshot, RealtimeStatus };