totalum-sdk 0.1.0-dev.8 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/dist/_types/{billing.d-C1exPLN6.d.ts → billing.d-BcRcDH4Y.d.ts} +1 -1
  3. package/dist/_types/{coerce.d-RtY2zQyw.d.ts → coerce.d-BXj_o-j6.d.ts} +1 -1
  4. package/dist/_types/{errors.d-yrue1e9O.d.ts → errors.d-Dtt-BIwJ.d.ts} +62 -2
  5. package/dist/_types/{integrations.d-BKPWost0.d.ts → integrations.d-DjOeFaYn.d.ts} +2 -2
  6. package/dist/_types/{ops.d-BOMT9yln.d.ts → ops.d-BKBWL6Qf.d.ts} +2 -2
  7. package/dist/ai/index.d.ts +42 -26
  8. package/dist/ai/index.js +13 -9
  9. package/dist/analytics/index.d.ts +4 -4
  10. package/dist/browser/index.d.ts +114 -5
  11. package/dist/browser/index.js +22 -5
  12. package/dist/cron/index.d.ts +5 -5
  13. package/dist/cron/index.js +2 -10
  14. package/dist/d1/index.d.ts +6 -4
  15. package/dist/d1/lazy.js +21 -3
  16. package/dist/d1/session.js +83 -15
  17. package/dist/deprecate.js +16 -0
  18. package/dist/email/index.d.ts +12 -6
  19. package/dist/email/index.js +4 -3
  20. package/dist/files/index.d.ts +11 -9
  21. package/dist/files/index.js +10 -5
  22. package/dist/index.d.ts +11 -8
  23. package/dist/index.js +3 -0
  24. package/dist/logs/index.d.ts +5 -5
  25. package/dist/payments/index.d.ts +5 -5
  26. package/dist/pdf/index.d.ts +5 -5
  27. package/dist/react/index.d.ts +91 -0
  28. package/dist/react/index.js +178 -0
  29. package/dist/realtime/index.d.ts +2 -2
  30. package/dist/scan/index.d.ts +14 -6
  31. package/dist/scan/index.js +5 -1
  32. package/dist/seo/index.d.ts +4 -4
  33. package/dist/speech/index.d.ts +26 -13
  34. package/dist/speech/index.js +24 -12
  35. package/dist/vectors/index.d.ts +167 -0
  36. package/dist/vectors/index.js +28 -0
  37. package/dist/web/index.d.ts +6 -6
  38. package/dist/web/index.js +1 -1
  39. package/dist/webhooks/index.d.ts +4 -4
  40. package/package.json +24 -4
  41. package/totalum-sdk.md +152 -24
  42. package/totalum-sdk.signatures.json +313 -0
@@ -3,11 +3,21 @@ export const READ_YOUR_WRITES_COOKIE = '__tlm_d1_w';
3
3
  /** Replicas lag the primary by 30–75 ms (Cloudflare); 10 s leaves a wide margin (research 46 §6.3). */
4
4
  const WINDOW_SECONDS = 10;
5
5
  const READS = new Set(['GET', 'HEAD']);
6
+ /**
7
+ * A replica read slower than this is re-run on the primary, and the rest of the request reads the primary. Replicas
8
+ * answer in tens of ms; measured stalls last 10 s or more while the primary stays fast (ui-evidence/preview-hang).
9
+ * D1's Sessions API documents no timeout or fallback of its own.
10
+ */
11
+ export const REPLICA_READ_TIMEOUT_MS = 2000;
12
+ /** Only a `SELECT` is re-run: a write that stalled may still land, and running it twice would duplicate it. */
13
+ const PURE_READ = /^\s*select\b/i;
14
+ const LATE = Symbol('late');
6
15
  /**
7
16
  * Runs one request of a Worker with a replicated D1 (A3.23, research 46 §6.3): a `GET`/`HEAD` reads through a
8
17
  * `first-unconstrained` session — the nearest replica — unless the browser wrote in the last 10 s; any other method
9
18
  * uses the plain binding (writes go to the primary; measured faster than any session) and its response sets the short
10
- * cookie that sends that browser's next reads to the primary. `run` receives the env to hand to the app, whose
19
+ * cookie that sends that browser's next reads to the primary. A replica read that takes over `REPLICA_READ_TIMEOUT_MS`
20
+ * is answered by the primary instead, and the rest of that request reads the primary. `run` receives the env to hand to the app, whose
11
21
  * `totalumD1()` reads `TOTALUM_DB` from it on every statement. No D1 binding (Turso, a laptop): `run(env)` unchanged.
12
22
  */
13
23
  export async function withTotalumSession(request, env, run) {
@@ -15,24 +25,82 @@ export async function withTotalumSession(request, env, run) {
15
25
  if (typeof db?.withSession !== 'function')
16
26
  return run(env);
17
27
  const binding = db;
18
- if (!READS.has(request.method)) {
19
- const res = await run(env);
20
- if (res.status === 101)
21
- return res; // a WebSocket upgrade cannot be re-wrapped
22
- const out = new Response(res.body, res);
23
- out.headers.append('set-cookie', `${READ_YOUR_WRITES_COOKIE}=1; Max-Age=${String(WINDOW_SECONDS)}; Path=/; HttpOnly; Secure; SameSite=None; Partitioned`);
24
- return out;
25
- }
28
+ if (!READS.has(request.method))
29
+ return withCookie(await run(env));
26
30
  const cookies = request.headers.get('cookie') ?? '';
27
31
  if (new RegExp(`(?:^|;\\s*)${READ_YOUR_WRITES_COOKIE}=`).test(cookies))
28
32
  return run(env);
29
- const session = binding.withSession('first-unconstrained');
30
- const replicaDb = {
31
- prepare: (sql) => session.prepare(sql),
32
- batch: (statements) => session.batch(statements),
33
- exec: (sql) => binding.exec(sql),
33
+ const replica = boundedReplica(binding, binding.withSession('first-unconstrained'));
34
+ const res = await run({ ...env, TOTALUM_DB: replica.db });
35
+ // a GET that wrote (a first visit creating its row, an OAuth callback) sends the browser's next reads to the primary too
36
+ return replica.wrote() ? withCookie(res) : res;
37
+ }
38
+ function withCookie(res) {
39
+ if (res.status === 101)
40
+ return res; // a WebSocket upgrade cannot be re-wrapped
41
+ const out = new Response(res.body, res);
42
+ out.headers.append('set-cookie', `${READ_YOUR_WRITES_COOKIE}=1; Max-Age=${String(WINDOW_SECONDS)}; Path=/; HttpOnly; Secure; SameSite=None; Partitioned`);
43
+ return out;
44
+ }
45
+ /**
46
+ * The request's database on the nearest replica, each pure read bounded by `REPLICA_READ_TIMEOUT_MS`: past it, the read
47
+ * runs on the primary (the stalled replica call is abandoned) and so does every later statement of this request. Any
48
+ * other statement (a write, even one that fails) runs on the primary and so does the rest of the request: a lost-race
49
+ * re-read (better-auth's rate limiter: insert → UNIQUE → read again) must see the row the replica has not received yet.
50
+ */
51
+ function boundedReplica(binding, session) {
52
+ let primary = false;
53
+ let wrote = false;
54
+ async function read(sqls, call) {
55
+ if (!sqls.every((sql) => PURE_READ.test(sql))) {
56
+ primary = wrote = true;
57
+ return call(binding);
58
+ }
59
+ if (primary)
60
+ return call(binding);
61
+ let timer;
62
+ const late = new Promise((resolve) => {
63
+ timer = setTimeout(() => {
64
+ resolve(LATE);
65
+ }, REPLICA_READ_TIMEOUT_MS);
66
+ });
67
+ try {
68
+ const out = await Promise.race([call(session), late]);
69
+ if (out !== LATE)
70
+ return out;
71
+ }
72
+ finally {
73
+ clearTimeout(timer);
74
+ }
75
+ primary = true;
76
+ console.warn(JSON.stringify({ event: 'd1_replica_read_timeout', ms: REPLICA_READ_TIMEOUT_MS }));
77
+ return call(binding);
78
+ }
79
+ const statement = (sql, params = []) => {
80
+ const real = (db) => db.prepare(sql).bind(...params);
81
+ const bounded = (method) => (...args) => read([sql], (db) => real(db)[method](...args));
82
+ return {
83
+ sql,
84
+ real,
85
+ bind: (...values) => statement(sql, values),
86
+ first: bounded('first'),
87
+ run: bounded('run'),
88
+ all: bounded('all'),
89
+ raw: bounded('raw'),
90
+ };
91
+ };
92
+ const db = {
93
+ prepare: (sql) => statement(sql),
94
+ batch: (statements) => {
95
+ const mine = statements;
96
+ return read(mine.map((s) => s.sql), (d) => d.batch(mine.map((s) => s.real(d))));
97
+ },
98
+ exec: (sql) => {
99
+ primary = wrote = true;
100
+ return binding.exec(sql);
101
+ },
34
102
  dump: () => binding.dump(),
35
103
  withSession: (c) => binding.withSession(c),
36
104
  };
37
- return run({ ...env, TOTALUM_DB: replicaDb });
105
+ return { db, wrote: () => wrote };
38
106
  }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The deprecation policy (CHANGELOG.md): a deprecated name keeps working for at least one major version and warns
3
+ * once per process (per isolate in a Worker) with `console.warn`, naming its replacement.
4
+ */
5
+ const warned = new Set();
6
+ export function deprecated(name, replacement) {
7
+ if (warned.has(name))
8
+ return;
9
+ warned.add(name);
10
+ console.warn(`[totalum-sdk] ${name} is deprecated and will be removed in totalum-sdk 2.0.0; use ${replacement}.`);
11
+ }
12
+ /** `fn` under an old name: same behaviour and type (overloads included), plus the one-time warning. */
13
+ export const alias = (fn, name, replacement) => ((...args) => {
14
+ deprecated(name, replacement);
15
+ return fn(...args);
16
+ });
@@ -1,8 +1,8 @@
1
- import { E as EmailSendInput, j as EmailView } from '../_types/integrations.d-BKPWost0.js';
2
- export { i as EmailSendOutput } 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';
1
+ import { E as EmailSendInput, j as EmailView } from '../_types/integrations.d-DjOeFaYn.js';
2
+ export { i as EmailSendOutput } from '../_types/integrations.d-DjOeFaYn.js';
3
+ import { T as TotalumClientOptions } from '../_types/errors.d-Dtt-BIwJ.js';
4
+ export { a as TotalumError, b as TotalumErrorCode, i as isTotalumError } from '../_types/errors.d-Dtt-BIwJ.js';
5
+ import '../_types/coerce.d-BXj_o-j6.js';
6
6
 
7
7
  /**
8
8
  * `totalum.email` (plan 05 §6.4) over SDK-API `/v1/email/*` (scope `email`): Resend, HTML sent byte for byte, charged
@@ -10,7 +10,7 @@ import '../_types/coerce.d-RtY2zQyw.js';
10
10
  */
11
11
  declare function totalumEmail(options?: TotalumClientOptions): {
12
12
  /**
13
- * Sends one e-mail (HTML byte for byte); charged per recipient.
13
+ * Sends one e-mail (HTML byte for byte); charged per recipient (`usage.credits`).
14
14
  *
15
15
  * @example
16
16
  * await email.send({ to: 'ana@example.com', subject: 'Welcome', html: '<p>Hi Ana</p>' });
@@ -21,6 +21,12 @@ declare function totalumEmail(options?: TotalumClientOptions): {
21
21
  messageId: string;
22
22
  id: string;
23
23
  status: "queued" | "sent";
24
+ } & {
25
+ usage: {
26
+ vendor?: string | undefined;
27
+ units?: number | undefined;
28
+ credits: number;
29
+ };
24
30
  }>;
25
31
  /** `null` when the e-mail is not this project's. */
26
32
  get: (id: string) => Promise<EmailView | null>;
@@ -1,5 +1,5 @@
1
1
  import { isTotalumError } from '../errors.js';
2
- import { jsonClient } from '../http.js';
2
+ import { envelopeClient, jsonClient, withUsage } from '../http.js';
3
3
  export { TotalumError, isTotalumError } from '../errors.js';
4
4
  /**
5
5
  * `totalum.email` (plan 05 §6.4) over SDK-API `/v1/email/*` (scope `email`): Resend, HTML sent byte for byte, charged
@@ -7,14 +7,15 @@ export { TotalumError, isTotalumError } from '../errors.js';
7
7
  */
8
8
  export function totalumEmail(options = {}) {
9
9
  const call = jsonClient(options);
10
+ const envelope = envelopeClient(options);
10
11
  return {
11
12
  /**
12
- * Sends one e-mail (HTML byte for byte); charged per recipient.
13
+ * Sends one e-mail (HTML byte for byte); charged per recipient (`usage.credits`).
13
14
  *
14
15
  * @example
15
16
  * await email.send({ to: 'ana@example.com', subject: 'Welcome', html: '<p>Hi Ana</p>' });
16
17
  */
17
- send: (msg) => call('POST', '/v1/email/send', msg),
18
+ send: async (msg) => withUsage(await envelope('POST', '/v1/email/send', msg)),
18
19
  /** `null` when the e-mail is not this project's. */
19
20
  get: async (id) => {
20
21
  try {
@@ -1,8 +1,8 @@
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';
1
+ import { F as FileDescriptor, k as FileUploadUrlInput, m as FilesListQuery } from '../_types/integrations.d-DjOeFaYn.js';
2
+ export { l as FileUploadUrlOutput, n as FilesPage } from '../_types/integrations.d-DjOeFaYn.js';
3
+ import { T as TotalumClientOptions } from '../_types/errors.d-Dtt-BIwJ.js';
4
+ export { a as TotalumError, b as TotalumErrorCode, i as isTotalumError } from '../_types/errors.d-Dtt-BIwJ.js';
5
+ import '../_types/coerce.d-BXj_o-j6.js';
6
6
 
7
7
  interface TotalumFilesOptions extends TotalumClientOptions {
8
8
  /** The public files host; default `TOTALUM_FILES_URL`, else `https://files.totalum-project.com` (A10.1). */
@@ -94,15 +94,17 @@ declare function totalumFiles(options?: TotalumFilesOptions): {
94
94
  expiresInSeconds?: number;
95
95
  download?: boolean;
96
96
  }) => Promise<string>;
97
- /** Same as `getSignedUrl`. */
97
+ /** @deprecated Since 1.0.0: use `getSignedUrl` (the same call). */
98
98
  getDownloadUrl: (key: string, opts?: {
99
99
  expiresInSeconds?: number;
100
100
  download?: boolean;
101
101
  }) => Promise<string>;
102
- /** Signed GET URLs for many keys at once (`ttl` in seconds, ≤ 7 days). */
102
+ /** Signed GET URLs for many keys at once (`expiresInSeconds` ≤ 7 days, default 15 min), keyed by file key. */
103
103
  presign(keys: string[], opts?: {
104
- ttl?: number;
104
+ expiresInSeconds?: number;
105
105
  download?: boolean;
106
+ /** @deprecated Since 1.0.0: use `expiresInSeconds`. */
107
+ ttl?: number;
106
108
  }): Promise<Record<string, string>>;
107
109
  /** Deletes one key, or up to 1000 keys at once. */
108
110
  delete(keys: string | string[]): Promise<void>;
@@ -115,5 +117,5 @@ declare function totalumFiles(options?: TotalumFilesOptions): {
115
117
  };
116
118
  type TotalumFiles = ReturnType<typeof totalumFiles>;
117
119
 
118
- export { FileDescriptor, FileUploadUrlInput, FilesListQuery, totalumFiles };
120
+ export { FileDescriptor, FileUploadUrlInput, FilesListQuery, TotalumClientOptions, totalumFiles };
119
121
  export type { TotalumFiles, TotalumFilesOptions, UploadOptions };
@@ -1,3 +1,4 @@
1
+ import { alias, deprecated } from '../deprecate.js';
1
2
  import { apiUrlOf, jsonClient, query, rawClient, readEnv } from '../http.js';
2
3
  export { TotalumError, isTotalumError } from '../errors.js';
3
4
  const DEFAULT_FILES_URL = 'https://files.totalum-project.com';
@@ -42,12 +43,16 @@ export function totalumFiles(options = {}) {
42
43
  get: (key) => call('GET', `${path(key)}/meta`),
43
44
  /** 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
45
  getSignedUrl,
45
- /** Same as `getSignedUrl`. */
46
- getDownloadUrl: getSignedUrl,
47
- /** Signed GET URLs for many keys at once (`ttl` in seconds, ≤ 7 days). */
46
+ /** @deprecated Since 1.0.0: use `getSignedUrl` (the same call). */
47
+ getDownloadUrl: alias(getSignedUrl, 'files.getDownloadUrl()', 'files.getSignedUrl()'),
48
+ /** Signed GET URLs for many keys at once (`expiresInSeconds` ≤ 7 days, default 15 min), keyed by file key. */
48
49
  async presign(keys, opts = {}) {
49
- return (await call('POST', '/v1/files/presign', { keys, ...opts }))
50
- .urls;
50
+ // eslint-disable-next-line @typescript-eslint/no-deprecated -- the old name still works until 2.0.0
51
+ const { expiresInSeconds, ttl, download } = opts;
52
+ if (ttl !== undefined)
53
+ deprecated('files.presign({ ttl })', 'files.presign({ expiresInSeconds })');
54
+ const body = { keys, ttl: expiresInSeconds ?? ttl, download };
55
+ return (await call('POST', '/v1/files/presign', body)).urls;
51
56
  },
52
57
  /** Deletes one key, or up to 1000 keys at once. */
53
58
  async delete(keys) {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
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';
2
+ export { AiChatInput, AiEmbedInput, AiEmbedOutput, AiImageEditInput, AiImageInput, AiImageOutput, AiModelsOutput, AiPresetName, AiTextOutput, AiVideoCreated, AiVideoInput, AiVideoJob, AiVisionDescribeInput, ChatResult, ChatStream, ChatUsage, TotalumAi } from './ai/index.js';
3
3
  import { totalumAnalytics } from './analytics/index.js';
4
4
  export { SiteAnalyticsQuery, TotalumAnalytics } from './analytics/index.js';
5
5
  import { totalumBrowser } from './browser/index.js';
@@ -23,17 +23,19 @@ export { ScanDocumentResult, TotalumScan } from './scan/index.js';
23
23
  import { totalumSeo } from './seo/index.js';
24
24
  export { TotalumSeo } from './seo/index.js';
25
25
  import { totalumSpeech } from './speech/index.js';
26
- export { TotalumSpeech } from './speech/index.js';
26
+ export { SpeechAudio, TotalumSpeech } from './speech/index.js';
27
+ import { totalumVectors } from './vectors/index.js';
28
+ export { TotalumVectors, VectorFilter, VectorMatch, VectorMetadata, VectorRecord, VectorSpace, VectorUpsertItem, VectorsQueryInput } from './vectors/index.js';
27
29
  import { totalumWeb } from './web/index.js';
28
30
  export { TotalumWeb } from './web/index.js';
29
31
  import { totalumWebhooks } from './webhooks/index.js';
30
32
  export { TotalumWebhookError, TotalumWebhooks, verifyWebhook } from './webhooks/index.js';
31
33
  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-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';
34
+ export { T as TotalumClientOptions, a as TotalumError, b as TotalumErrorCode, i as isTotalumError } from './_types/errors.d-Dtt-BIwJ.js';
35
+ 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-DjOeFaYn.js';
36
+ export { L as LogsPage, S as SiteAnalyticsOutput, a as SiteDimension, b as SiteMetric } from './_types/ops.d-BKBWL6Qf.js';
37
+ export { W as WebhookConfig, a as WebhookEvent, b as WebhookSecretOutput } from './_types/billing.d-BcRcDH4Y.js';
38
+ import './_types/coerce.d-BXj_o-j6.js';
37
39
 
38
40
  /** The options of `createTotalum()`: every namespace's options in one object (each falls back to its env var). */
39
41
  type TotalumOptions = TotalumAiOptions & TotalumFilesOptions;
@@ -51,6 +53,7 @@ declare const namespaces: {
51
53
  scan: typeof totalumScan;
52
54
  seo: typeof totalumSeo;
53
55
  speech: typeof totalumSpeech;
56
+ vectors: typeof totalumVectors;
54
57
  web: typeof totalumWeb;
55
58
  webhooks: typeof totalumWebhooks;
56
59
  };
@@ -69,5 +72,5 @@ declare function createTotalum(options?: TotalumOptions): Totalum;
69
72
  /** The default instance, configured from the environment (`TOTALUM_PROJECT_KEY`, `TOTALUM_SDK_API_URL`, `TOTALUM_ENV`). */
70
73
  declare const totalum: Totalum;
71
74
 
72
- export { TotalumAiOptions, TotalumFilesOptions, createTotalum, totalum, totalumAi, totalumAnalytics, totalumBrowser, totalumCron, totalumEmail, totalumFiles, totalumLogs, totalumPayments, totalumPdf, totalumRealtime, totalumScan, totalumSeo, totalumSpeech, totalumWeb, totalumWebhooks };
75
+ export { TotalumAiOptions, TotalumFilesOptions, createTotalum, totalum, totalumAi, totalumAnalytics, totalumBrowser, totalumCron, totalumEmail, totalumFiles, totalumLogs, totalumPayments, totalumPdf, totalumRealtime, totalumScan, totalumSeo, totalumSpeech, totalumVectors, totalumWeb, totalumWebhooks };
73
76
  export type { Totalum, TotalumOptions };
package/dist/index.js CHANGED
@@ -11,6 +11,7 @@ import { totalumRealtime } from './realtime/index.js';
11
11
  import { totalumScan } from './scan/index.js';
12
12
  import { totalumSeo } from './seo/index.js';
13
13
  import { totalumSpeech } from './speech/index.js';
14
+ import { totalumVectors } from './vectors/index.js';
14
15
  import { totalumWeb } from './web/index.js';
15
16
  import { totalumWebhooks } from './webhooks/index.js';
16
17
  export * from './ai/index.js';
@@ -27,6 +28,7 @@ export * from './realtime/index.js';
27
28
  export * from './scan/index.js';
28
29
  export * from './seo/index.js';
29
30
  export * from './speech/index.js';
31
+ export * from './vectors/index.js';
30
32
  export * from './web/index.js';
31
33
  export * from './webhooks/index.js';
32
34
  const namespaces = {
@@ -43,6 +45,7 @@ const namespaces = {
43
45
  scan: totalumScan,
44
46
  seo: totalumSeo,
45
47
  speech: totalumSpeech,
48
+ vectors: totalumVectors,
46
49
  web: totalumWeb,
47
50
  webhooks: totalumWebhooks,
48
51
  };
@@ -1,8 +1,8 @@
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';
1
+ import { c as LogsQueryInput } from '../_types/ops.d-BKBWL6Qf.js';
2
+ export { L as LogsPage } from '../_types/ops.d-BKBWL6Qf.js';
3
+ import { T as TotalumClientOptions } from '../_types/errors.d-Dtt-BIwJ.js';
4
+ export { a as TotalumError, b as TotalumErrorCode, i as isTotalumError } from '../_types/errors.d-Dtt-BIwJ.js';
5
+ import '../_types/coerce.d-BXj_o-j6.js';
6
6
 
7
7
  /** A `logs.query` filter: the window (default the last hour), level, substring, status class, path, request id, env. */
8
8
  type LogsQuery = Omit<LogsQueryInput, 'caller' | 'runId'>;
@@ -1,8 +1,8 @@
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';
1
+ import { O as OnboardingLinkInput, C as CheckoutInput, g as CustomerPortalLinkInput } from '../_types/integrations.d-DjOeFaYn.js';
2
+ export { a as CheckoutOutput, h as CustomerPortalLinkOutput, o as OnboardingLinkOutput, P as PaymentsStatus } from '../_types/integrations.d-DjOeFaYn.js';
3
+ import { T as TotalumClientOptions } from '../_types/errors.d-Dtt-BIwJ.js';
4
+ export { a as TotalumError, b as TotalumErrorCode, i as isTotalumError } from '../_types/errors.d-Dtt-BIwJ.js';
5
+ import '../_types/coerce.d-BXj_o-j6.js';
6
6
 
7
7
  /**
8
8
  * `totalum.payments` (plan 05, plan 11 §9.5) over SDK-API `/v1/payments/*` with a project key (scope `payments`): Stripe
@@ -1,8 +1,8 @@
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';
1
+ import { p as PdfFromHtmlInput, q as PdfFromUrlInput } from '../_types/integrations.d-DjOeFaYn.js';
2
+ export { r as PdfOutput } from '../_types/integrations.d-DjOeFaYn.js';
3
+ import { T as TotalumClientOptions } from '../_types/errors.d-Dtt-BIwJ.js';
4
+ export { a as TotalumError, b as TotalumErrorCode, i as isTotalumError } from '../_types/errors.d-Dtt-BIwJ.js';
5
+ import '../_types/coerce.d-BXj_o-j6.js';
6
6
 
7
7
  /** `totalum.pdf` (plan 04 §5.5) over `/v1/pdf/*` (scope `files:write`): a new file in the project's storage each time. */
8
8
  declare function totalumPdf(options?: TotalumClientOptions): {
@@ -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 };