totalum-sdk 1.10.5 → 1.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/_types/{coerce.d-Dgx5wOUv.d.ts → coerce.d-D_rylvPs.d.ts} +1 -1
  3. package/dist/_types/{errors.d-CIkIZmY-.d.ts → errors.d-BPpY5QKu.d.ts} +32 -2
  4. package/dist/_types/{integrations.d-B3Ea8Iuc.d.ts → integrations.d-BTZHy48D.d.ts} +2 -2
  5. package/dist/_types/{ops.d-G13QAhKA.d.ts → ops.d-Ce5zJyX0.d.ts} +2 -2
  6. package/dist/ai/index.d.ts +275 -23
  7. package/dist/ai/index.js +305 -24
  8. package/dist/analytics/index.d.ts +58 -12
  9. package/dist/analytics/index.js +46 -3
  10. package/dist/browser/index.d.ts +228 -20
  11. package/dist/browser/index.js +122 -13
  12. package/dist/connections/index.d.ts +601 -0
  13. package/dist/connections/index.js +353 -0
  14. package/dist/cron/index.d.ts +147 -20
  15. package/dist/cron/index.js +157 -15
  16. package/dist/d1/errors.js +15 -0
  17. package/dist/d1/index.d.ts +254 -10
  18. package/dist/d1/index.js +24 -4
  19. package/dist/d1/session.js +26 -2
  20. package/dist/email/index.d.ts +65 -10
  21. package/dist/email/index.js +60 -5
  22. package/dist/errors.js +17 -0
  23. package/dist/files/index.d.ts +243 -20
  24. package/dist/files/index.js +247 -14
  25. package/dist/index.d.ts +28 -10
  26. package/dist/index.js +22 -5
  27. package/dist/logs/index.d.ts +48 -10
  28. package/dist/logs/index.js +39 -4
  29. package/dist/payments/index.d.ts +221 -23
  30. package/dist/payments/index.js +216 -18
  31. package/dist/pdf/index.d.ts +59 -9
  32. package/dist/pdf/index.js +54 -4
  33. package/dist/react/index.d.ts +78 -6
  34. package/dist/react/index.js +51 -5
  35. package/dist/realtime/index.d.ts +55 -8
  36. package/dist/realtime/index.js +53 -6
  37. package/dist/scan/index.d.ts +78 -10
  38. package/dist/scan/index.js +63 -3
  39. package/dist/seo/index.d.ts +43 -7
  40. package/dist/seo/index.js +39 -3
  41. package/dist/speech/index.d.ts +34 -10
  42. package/dist/speech/index.js +25 -5
  43. package/dist/vectors/index.d.ts +96 -9
  44. package/dist/vectors/index.js +93 -7
  45. package/dist/web/index.d.ts +168 -15
  46. package/dist/web/index.js +163 -10
  47. package/dist/webhooks/index.d.ts +122 -15
  48. package/dist/webhooks/index.js +119 -13
  49. package/package.json +6 -1
  50. package/totalum-sdk.md +8900 -664
  51. package/totalum-sdk.signatures.json +61 -1
@@ -0,0 +1,601 @@
1
+ import { Z as ZodObject, d as ZodString, f as ZodEnum, u as ZodISODateTime, m as $strip, o as output, c as ZodOptional, h as ZodRecord, g as ZodUnknown, j as ZodBoolean, r as ZodLiteral, e as ZodArray, k as ZodNumber, p as ZodURL, T as TotalumClientOptions, U as Usage } from '../_types/errors.d-BPpY5QKu.js';
2
+ export { a as TotalumError, b as TotalumErrorCode, i as isTotalumError } from '../_types/errors.d-BPpY5QKu.js';
3
+
4
+ /** `POST /v1/connections/link`: the URL the user is sent to; it comes back to `returnUrl?connection=success|failed&toolkit=…`. */
5
+ declare const ConnectionLinkInput: ZodObject<{
6
+ userId: ZodString;
7
+ toolkit: ZodString;
8
+ returnUrl: ZodURL;
9
+ }, $strip>;
10
+ type ConnectionLinkInput = output<typeof ConnectionLinkInput>;
11
+ declare const ConnectionStatus: ZodEnum<{
12
+ active: "active";
13
+ disabled: "disabled";
14
+ failed: "failed";
15
+ expired: "expired";
16
+ pending: "pending";
17
+ }>;
18
+ type ConnectionStatus = output<typeof ConnectionStatus>;
19
+ /** One connected account of the user (never a token). */
20
+ declare const Connection: ZodObject<{
21
+ id: ZodString;
22
+ toolkit: ZodString;
23
+ status: ZodEnum<{
24
+ active: "active";
25
+ disabled: "disabled";
26
+ failed: "failed";
27
+ expired: "expired";
28
+ pending: "pending";
29
+ }>;
30
+ createdAt: ZodISODateTime;
31
+ }, $strip>;
32
+ type Connection = output<typeof Connection>;
33
+ /**
34
+ * `POST /v1/connections/execute`: runs `action` with the user's active connection of the action's toolkit
35
+ * (`connectionId` picks one of the user's own when there are several). None → `409 CONNECTION_REQUIRED`.
36
+ */
37
+ declare const ConnectionExecuteInput: ZodObject<{
38
+ userId: ZodString;
39
+ action: ZodString;
40
+ input: ZodOptional<ZodRecord<ZodString, ZodUnknown>>;
41
+ connectionId: ZodOptional<ZodString>;
42
+ }, $strip>;
43
+ type ConnectionExecuteInput = output<typeof ConnectionExecuteInput>;
44
+ /** `GET /v1/connections/actions?toolkit=…&search=…` and `GET /v1/connections/actions/:action`. */
45
+ declare const ConnectionAction: ZodObject<{
46
+ slug: ZodString;
47
+ toolkit: ZodString;
48
+ name: ZodString;
49
+ description: ZodString;
50
+ inputSchema: ZodOptional<ZodRecord<ZodString, ZodUnknown>>;
51
+ }, $strip>;
52
+ type ConnectionAction = output<typeof ConnectionAction>;
53
+ /** `GET /v1/connections/toolkits?search=&category=&cursor=&limit=`: one row of the catalogue. */
54
+ declare const ConnectionToolkit: ZodObject<{
55
+ slug: ZodString;
56
+ name: ZodString;
57
+ description: ZodString;
58
+ categories: ZodArray<ZodString>;
59
+ authSchemes: ZodArray<ZodString>;
60
+ connect: ZodEnum<{
61
+ none: "none";
62
+ credentials: "credentials";
63
+ oauth: "oauth";
64
+ unavailable: "unavailable";
65
+ }>;
66
+ actionsCount: ZodNumber;
67
+ triggersCount: ZodNumber;
68
+ }, $strip>;
69
+ type ConnectionToolkit = output<typeof ConnectionToolkit>;
70
+ /** `GET /v1/connections/toolkits/:slug`: the exact `connect` mode and what the user types on the hosted page. */
71
+ declare const ConnectionToolkitDetail: ZodObject<{
72
+ slug: ZodString;
73
+ name: ZodString;
74
+ description: ZodString;
75
+ categories: ZodArray<ZodString>;
76
+ authSchemes: ZodArray<ZodString>;
77
+ connect: ZodEnum<{
78
+ none: "none";
79
+ credentials: "credentials";
80
+ oauth: "oauth";
81
+ unavailable: "unavailable";
82
+ }>;
83
+ actionsCount: ZodNumber;
84
+ triggersCount: ZodNumber;
85
+ credentialFields: ZodArray<ZodObject<{
86
+ name: ZodString;
87
+ label: ZodString;
88
+ description: ZodString;
89
+ }, $strip>>;
90
+ }, $strip>;
91
+ type ConnectionToolkitDetail = output<typeof ConnectionToolkitDetail>;
92
+ /** `GET /v1/connections/triggers?toolkit=…` and `GET /v1/connections/triggers/:trigger` (with the schemas). */
93
+ declare const ConnectionTrigger: ZodObject<{
94
+ slug: ZodString;
95
+ toolkit: ZodString;
96
+ name: ZodString;
97
+ description: ZodString;
98
+ type: ZodString;
99
+ instructions: ZodOptional<ZodString>;
100
+ configSchema: ZodOptional<ZodRecord<ZodString, ZodUnknown>>;
101
+ payloadSchema: ZodOptional<ZodRecord<ZodString, ZodUnknown>>;
102
+ }, $strip>;
103
+ type ConnectionTrigger = output<typeof ConnectionTrigger>;
104
+ /**
105
+ * `POST /v1/connections/subscriptions`: watch `trigger` on the user's connection of its toolkit; each event is POSTed
106
+ * to `deliverTo` (a path of the app's own preview or published site, default `CONNECTIONS_EVENTS_PATH`), signed with
107
+ * the project's webhook secret (`Totalum-Signature`).
108
+ */
109
+ declare const ConnectionSubscribeInput: ZodObject<{
110
+ userId: ZodString;
111
+ trigger: ZodString;
112
+ config: ZodOptional<ZodRecord<ZodString, ZodUnknown>>;
113
+ connectionId: ZodOptional<ZodString>;
114
+ deliverTo: ZodOptional<ZodString>;
115
+ }, $strip>;
116
+ type ConnectionSubscribeInput = output<typeof ConnectionSubscribeInput>;
117
+ declare const ConnectionSubscription: ZodObject<{
118
+ id: ZodString;
119
+ trigger: ZodString;
120
+ connectionId: ZodString;
121
+ config: ZodRecord<ZodString, ZodUnknown>;
122
+ enabled: ZodBoolean;
123
+ }, $strip>;
124
+ type ConnectionSubscription = output<typeof ConnectionSubscription>;
125
+ /** One delivered event: the body POSTed to the app's `deliverTo` route (verify it with `totalum.webhooks.verify`). */
126
+ declare const ConnectionEvent: ZodObject<{
127
+ id: ZodString;
128
+ createdAt: ZodISODateTime;
129
+ projectId: ZodString;
130
+ env: ZodEnum<{
131
+ dev: "dev";
132
+ live: "live";
133
+ }>;
134
+ livemode: ZodOptional<ZodBoolean>;
135
+ type: ZodLiteral<"connections.event">;
136
+ data: ZodObject<{
137
+ subscriptionId: ZodString;
138
+ trigger: ZodString;
139
+ userId: ZodString;
140
+ connectionId: ZodString;
141
+ payload: ZodRecord<ZodString, ZodUnknown>;
142
+ }, $strip>;
143
+ }, $strip>;
144
+ type ConnectionEvent = output<typeof ConnectionEvent>;
145
+
146
+ /**
147
+ * Creates the `connections` namespace (the same object as `totalum.connections`; scope `connections`; server-side code
148
+ * only: it needs the project key). Your app's users connect their own accounts of ~1,500 apps — Google Calendar, Gmail, Google Drive, Outlook,
149
+ * OneDrive, Slack, Dropbox, Notion, HubSpot, GitHub, Stripe, Airtable, … — on a hosted page (they sign in at the
150
+ * provider, or type their own API key there), with no OAuth app of yours; then your server runs actions on them
151
+ * (`GOOGLECALENDAR_CREATE_EVENT`, `GMAIL_SEND_EMAIL`, …) and receives their events (`subscribe`). The tokens never
152
+ * reach your app. `userId` is always **your signed-in user's id** (the one in your database), taken from the session
153
+ * on the server — never from the request: each user, project and environment (dev/live) only ever sees its own
154
+ * connections.
155
+ *
156
+ * @param options - The project key, API URL and environment; each falls back to its environment variable.
157
+ * @returns The `connections` namespace: the methods below.
158
+ * @example
159
+ * import { totalumConnections } from 'totalum-sdk/connections';
160
+ *
161
+ * const connections = totalumConnections();
162
+ * const list = await connections.list({ userId: user.id });
163
+ */
164
+ declare function totalumConnections(options?: TotalumClientOptions): {
165
+ /**
166
+ * The URL to send the user to so they connect `toolkit` (e.g. `'googlecalendar'`); valid about 10 minutes, so
167
+ * make it when the user clicks "Connect" and redirect at once. They sign in at the provider (or type their own key
168
+ * on the hosted page) and come back to `returnUrl` with `?connection=success|failed&toolkit=<toolkit>` added. A new
169
+ * connection through Totalum's sign-in is billed once in credits when it becomes active.
170
+ *
171
+ * @param input - Your user, the app to connect and where to come back.
172
+ * @returns The hosted sign-in URL to redirect the user to.
173
+ * @throws VALIDATION_ERROR (400) `returnUrl` is not `https://` (only `localhost` may be `http`).
174
+ * @throws RECORD_NOT_FOUND (404) No app with this slug: look it up with `toolkits({ search })`.
175
+ * @throws TOOLKIT_NOT_AVAILABLE (400) This app cannot be connected.
176
+ * @throws TOOLKIT_NEEDS_OWN_APP (400) This app only signs in through an OAuth app registered by the developer, which is
177
+ * not available.
178
+ * @example
179
+ * // src/app/api/connect/google-calendar/route.ts
180
+ * const user = await requireUser(); // your own session
181
+ * const url = await totalum.connections.connectUrl({
182
+ * userId: user.id,
183
+ * toolkit: 'googlecalendar',
184
+ * returnUrl: 'https://acme.totalum.app/settings/integrations',
185
+ * });
186
+ * return Response.redirect(url, 302);
187
+ * //=>
188
+ * "https://connect.<sign-in host>/link/lk_Iem_dXdIv3-i"
189
+ */
190
+ connectUrl: (input: ConnectionLinkInput) => Promise<string>;
191
+ /**
192
+ * The user's connected accounts (newest first), optionally of one app: show them on a settings page with a
193
+ * "Disconnect" button. `status` is `active` when usable. Free.
194
+ *
195
+ * @param input - Your user, and optionally one app.
196
+ * @param input.userId - Your signed-in user's id, from the session.
197
+ * @param input.toolkit - Only connections of this app (`googlecalendar`).
198
+ * @returns The connections.
199
+ * @throws VALIDATION_ERROR (400) `userId` is empty or over 200 characters.
200
+ * @example
201
+ * const list = await totalum.connections.list({ userId: 'user_42' });
202
+ * //=>
203
+ * [
204
+ * { "id": "ca_8Qw2nZ4kLp", "toolkit": "googlecalendar", "status": "active", "createdAt": "2026-10-02T09:14:00.000Z" },
205
+ * { "id": "ca_3Hy7tR1mXc", "toolkit": "gmail", "status": "expired", "createdAt": "2026-08-21T16:40:00.000Z" }
206
+ * ]
207
+ */
208
+ list: (input: {
209
+ userId: string;
210
+ toolkit?: string;
211
+ }) => Promise<{
212
+ id: string;
213
+ toolkit: string;
214
+ status: "failed" | "expired" | "pending" | "active" | "disabled";
215
+ createdAt: string;
216
+ }[]>;
217
+ /**
218
+ * Whether the user has an active connection of an app: show "Connect" or the feature that needs it. Free.
219
+ *
220
+ * @param input - Your user and the app.
221
+ * @param input.userId - Your signed-in user's id, from the session.
222
+ * @param input.toolkit - The app's slug (`googlecalendar`).
223
+ * @returns `true` when the user has an active connection of `toolkit`.
224
+ * @throws VALIDATION_ERROR (400) `userId` is empty or over 200 characters.
225
+ * @example
226
+ * const connected = await totalum.connections.isConnected({ userId: 'user_42', toolkit: 'googlecalendar' });
227
+ * //=>
228
+ * false
229
+ */
230
+ isConnected: (input: {
231
+ userId: string;
232
+ toolkit: string;
233
+ }) => Promise<boolean>;
234
+ /**
235
+ * Disconnects one of the user's connected accounts (the provider's access is revoked). Free.
236
+ *
237
+ * @param input - Your user and the connection.
238
+ * @param input.userId - Your signed-in user's id, from the session.
239
+ * @param input.id - The connection's `id`, from `list()`.
240
+ * @returns `{ deleted: true }`.
241
+ * @throws RECORD_NOT_FOUND (404) The user has no connection with this id.
242
+ * @example
243
+ * await totalum.connections.disconnect({ userId: 'user_42', id: 'ca_8Qw2nZ4kLp' });
244
+ * //=>
245
+ * { "deleted": true }
246
+ */
247
+ disconnect: (input: {
248
+ userId: string;
249
+ id: string;
250
+ }) => Promise<{
251
+ deleted: true;
252
+ }>;
253
+ /**
254
+ * Runs `action` (e.g. `GOOGLECALENDAR_CREATE_EVENT`) with the user's active connection of its toolkit and
255
+ * returns the provider's answer in `data`. Read the action's `inputSchema` with `action(slug)` to build `input`.
256
+ * Billed in credits per action.
257
+ *
258
+ * @param input - Your user, the action and its input.
259
+ * @returns The provider's answer and what the action cost.
260
+ * @throws CONNECTION_REQUIRED (409) The user has not connected this app yet: send them to `connectUrl()`;
261
+ * `details.action` names the action.
262
+ * @throws CONNECTION_ACTION_FAILED (422) The provider refused the action (a bad input, a missing permission); the
263
+ * message says why.
264
+ * @throws RECORD_NOT_FOUND (404) No action with this slug.
265
+ * @throws PROVIDER_TIMEOUT (504) The provider did not answer in time.
266
+ * @example
267
+ * const { data } = await totalum.connections.execute({
268
+ * userId: 'user_42',
269
+ * action: 'GOOGLECALENDAR_CREATE_EVENT',
270
+ * input: {
271
+ * summary: 'Demo with Acme',
272
+ * start_datetime: '2026-10-14T10:00:00',
273
+ * timezone: 'Europe/Madrid',
274
+ * event_duration_minutes: 30,
275
+ * attendees: ['ana@example.com'],
276
+ * },
277
+ * });
278
+ * //=>
279
+ * {
280
+ * "data": { "id": "5r1q8m2v6k0c4n9b", "status": "confirmed", "htmlLink": "https://www.google.com/calendar/event?eid=NXIxcThtMnY2azBj…", … },
281
+ * "usage": { "credits": 0.0028 }
282
+ * }
283
+ */
284
+ execute: (input: ConnectionExecuteInput) => Promise<Omit<{
285
+ /** The provider's answer, as the action's documentation describes (the created event, the sent message, …). */
286
+ data: unknown;
287
+ }, "usage"> & {
288
+ usage: Usage;
289
+ }>;
290
+ /**
291
+ * The actions an app offers (slug, name, description), optionally filtered by words — to find the slug to pass to
292
+ * `execute()`. Free.
293
+ *
294
+ * @param input - The app and an optional search.
295
+ * @param input.toolkit - The app's slug (`googlecalendar`).
296
+ * @param input.search - Only actions matching these words (`create event`).
297
+ * @returns The matching actions, without their input schemas (read one with `action(slug)`).
298
+ * @throws RECORD_NOT_FOUND (404) No app with this slug.
299
+ * @example
300
+ * const actions = await totalum.connections.actions({ toolkit: 'googlecalendar', search: 'create event' });
301
+ * //=>
302
+ * [
303
+ * { "slug": "GOOGLECALENDAR_CREATE_EVENT", "toolkit": "googlecalendar", "name": "Create Event", "description": "Creates a timed event using start_datetime and either end_datetime or duration fields, or an all-day event…" },
304
+ * { "slug": "GOOGLECALENDAR_QUICK_ADD", "toolkit": "googlecalendar", "name": "Quick Add Event", "description": "Creates an event from a text string such as 'Lunch with Ana tomorrow at 1pm'…" }
305
+ * ]
306
+ */
307
+ actions: (input: {
308
+ toolkit: string;
309
+ search?: string;
310
+ }) => Promise<{
311
+ slug: string;
312
+ toolkit: string;
313
+ name: string;
314
+ description: string;
315
+ inputSchema?: Record<string, unknown> | undefined;
316
+ }[]>;
317
+ /**
318
+ * One action with its `inputSchema`: the JSON Schema of what `execute()` takes as `input`. Free.
319
+ *
320
+ * @param slug - The action's slug (`GOOGLECALENDAR_CREATE_EVENT`).
321
+ * @returns The action and its input schema.
322
+ * @throws RECORD_NOT_FOUND (404) No action with this slug.
323
+ * @example
324
+ * const action = await totalum.connections.action('GOOGLECALENDAR_CREATE_EVENT');
325
+ * //=>
326
+ * {
327
+ * "slug": "GOOGLECALENDAR_CREATE_EVENT",
328
+ * "toolkit": "googlecalendar",
329
+ * "name": "Create Event",
330
+ * "description": "Creates a timed event using start_datetime and either end_datetime or duration fields…",
331
+ * "inputSchema": {
332
+ * "type": "object",
333
+ * "properties": {
334
+ * "summary": { "type": "string", "description": "Summary (title) of the event." },
335
+ * "start_datetime": { "type": "string", "description": "Event start time…" },
336
+ * …
337
+ * }
338
+ * }
339
+ * }
340
+ */
341
+ action: (slug: string) => Promise<{
342
+ slug: string;
343
+ toolkit: string;
344
+ name: string;
345
+ description: string;
346
+ inputSchema?: Record<string, unknown> | undefined;
347
+ }>;
348
+ /**
349
+ * Searches the catalogue of apps (`search` matches names and descriptions, `category` e.g. `crm`); `connect`
350
+ * says how a user connects it: `oauth` (signs in at the provider), `credentials` (types their own key on the
351
+ * hosted page), `none` (no connection: run its actions directly), `unavailable` (cannot be connected). Pages
352
+ * with `cursor` = the previous `nextCursor`. Free.
353
+ *
354
+ * @param input - The search, category and paging; all optional.
355
+ * @param input.search - Words to match in app names and descriptions (`calendar`).
356
+ * @param input.category - Only apps of this category (`crm`, `email`, `calendar`).
357
+ * @param input.cursor - The previous page's `nextCursor`.
358
+ * @param input.limit - Apps per page.
359
+ * @returns One page of apps, the cursor of the next and the total.
360
+ * @throws PROVIDER_UNAVAILABLE (503) The catalogue is not available right now; retry later.
361
+ * @example
362
+ * const page = await totalum.connections.toolkits({ search: 'calendar', limit: 2 });
363
+ * //=>
364
+ * {
365
+ * "toolkits": [
366
+ * { "slug": "googlecalendar", "name": "Google Calendar", "description": "Google Calendar is a time management tool…", "categories": ["scheduling-&-booking"], "authSchemes": ["OAUTH2"], "connect": "oauth", "actionsCount": 47, "triggersCount": 7 },
367
+ * { "slug": "outlook", "name": "Outlook", "description": "Outlook is Microsoft's email and calendaring platform…", "categories": ["email", "calendar"], "authSchemes": ["OAUTH2", "S2S_OAUTH2"], "connect": "oauth", "actionsCount": 297, "triggersCount": 5 }
368
+ * ],
369
+ * "nextCursor": "Mi0y",
370
+ * "total": 18
371
+ * }
372
+ */
373
+ toolkits: (input?: {
374
+ search?: string;
375
+ category?: string;
376
+ cursor?: string;
377
+ limit?: number;
378
+ }) => Promise<{
379
+ toolkits: {
380
+ slug: string;
381
+ name: string;
382
+ description: string;
383
+ categories: string[];
384
+ authSchemes: string[];
385
+ connect: "none" | "credentials" | "oauth" | "unavailable";
386
+ actionsCount: number;
387
+ triggersCount: number;
388
+ }[];
389
+ nextCursor: string | null;
390
+ total: number;
391
+ }>;
392
+ /**
393
+ * One app, exactly: how it connects and, for `credentials`, the fields the user types on the hosted page. Free.
394
+ *
395
+ * @param slug - The app's slug (`googlecalendar`).
396
+ * @returns The app's details.
397
+ * @throws RECORD_NOT_FOUND (404) No app with this slug.
398
+ * @example
399
+ * const app = await totalum.connections.toolkit('googlecalendar');
400
+ * //=>
401
+ * {
402
+ * "slug": "googlecalendar",
403
+ * "name": "Google Calendar",
404
+ * "description": "Google Calendar is a time management tool providing scheduling features…",
405
+ * "categories": ["scheduling-&-booking"],
406
+ * "authSchemes": ["OAUTH2"],
407
+ * "connect": "oauth",
408
+ * "actionsCount": 47,
409
+ * "triggersCount": 7,
410
+ * "credentialFields": []
411
+ * }
412
+ */
413
+ toolkit: (slug: string) => Promise<{
414
+ slug: string;
415
+ name: string;
416
+ description: string;
417
+ categories: string[];
418
+ authSchemes: string[];
419
+ connect: "none" | "credentials" | "oauth" | "unavailable";
420
+ actionsCount: number;
421
+ triggersCount: number;
422
+ credentialFields: {
423
+ name: string;
424
+ label: string;
425
+ description: string;
426
+ }[];
427
+ }>;
428
+ /**
429
+ * The events (triggers) an app can send, such as `GMAIL_NEW_GMAIL_MESSAGE` — to find the slug to pass to
430
+ * `subscribe()`. Free.
431
+ *
432
+ * @param input - The app.
433
+ * @param input.toolkit - The app's slug (`gmail`).
434
+ * @returns The app's triggers, without their schemas (read one with `trigger(slug)`).
435
+ * @throws RECORD_NOT_FOUND (404) No app with this slug.
436
+ * @example
437
+ * const triggers = await totalum.connections.triggers({ toolkit: 'gmail' });
438
+ * //=>
439
+ * [
440
+ * { "slug": "GMAIL_EMAIL_SENT_TRIGGER", "toolkit": "gmail", "name": "Email Sent", "description": "Triggers when a Gmail message is sent by the authenticated user…", "type": "poll" },
441
+ * { "slug": "GMAIL_NEW_GMAIL_MESSAGE", "toolkit": "gmail", "name": "New Gmail Message Received Trigger", "description": "Triggers when a new message is received in Gmail.", "type": "poll" }
442
+ * ]
443
+ */
444
+ triggers: (input: {
445
+ toolkit: string;
446
+ }) => Promise<{
447
+ slug: string;
448
+ toolkit: string;
449
+ name: string;
450
+ description: string;
451
+ type: string;
452
+ instructions?: string | undefined;
453
+ configSchema?: Record<string, unknown> | undefined;
454
+ payloadSchema?: Record<string, unknown> | undefined;
455
+ }[]>;
456
+ /**
457
+ * One trigger with `configSchema` (what `subscribe`'s `config` takes) and `payloadSchema` (the event's shape).
458
+ * Free.
459
+ *
460
+ * @param slug - The trigger's slug (`GMAIL_NEW_GMAIL_MESSAGE`).
461
+ * @returns The trigger and its schemas.
462
+ * @throws RECORD_NOT_FOUND (404) No trigger with this slug.
463
+ * @example
464
+ * const trigger = await totalum.connections.trigger('GMAIL_NEW_GMAIL_MESSAGE');
465
+ * //=>
466
+ * {
467
+ * "slug": "GMAIL_NEW_GMAIL_MESSAGE",
468
+ * "toolkit": "gmail",
469
+ * "name": "New Gmail Message Received Trigger",
470
+ * "description": "Triggers when a new message is received in Gmail.",
471
+ * "type": "poll",
472
+ * "instructions": "Provide the user ID (usually 'me')…",
473
+ * "configSchema": {
474
+ * "properties": {
475
+ * "interval": { "type": "number", "default": 2, "description": "Periodic Interval to Check for Updates & Send a Trigger in Minutes" },
476
+ * "labelIds": { "type": "string", "default": "INBOX", "description": "Filter messages by a single label ID…" }
477
+ * }
478
+ * },
479
+ * "payloadSchema": { "properties": { "message_id": { "type": "string" }, "sender": { "type": "string" }, "subject": { "type": "string" }, … } }
480
+ * }
481
+ */
482
+ trigger: (slug: string) => Promise<{
483
+ slug: string;
484
+ toolkit: string;
485
+ name: string;
486
+ description: string;
487
+ type: string;
488
+ instructions?: string | undefined;
489
+ configSchema?: Record<string, unknown> | undefined;
490
+ payloadSchema?: Record<string, unknown> | undefined;
491
+ }>;
492
+ /**
493
+ * Watches `trigger` on the user's active connection of its toolkit: each event is POSTed to `deliverTo` (a path
494
+ * of your own app, default `/api/webhooks/connections`) on the preview (dev users) or the published site (live
495
+ * users), signed with your project's webhook secret — read it with `verifyEvent`. Each delivered event is billed in
496
+ * credits.
497
+ *
498
+ * @param input - Your user, the trigger, its configuration and where to deliver.
499
+ * @returns The subscription; keep its `id` to `unsubscribe()` later.
500
+ * @throws CONNECTION_REQUIRED (409) The user has not connected this app yet: send them to `connectUrl()`.
501
+ * @throws RECORD_NOT_FOUND (404) No trigger with this slug.
502
+ * @throws VALIDATION_ERROR (400) `config` does not match the trigger's `configSchema`, or `deliverTo` is not a path.
503
+ * @example
504
+ * const sub = await totalum.connections.subscribe({
505
+ * userId: 'user_42',
506
+ * trigger: 'GMAIL_NEW_GMAIL_MESSAGE',
507
+ * config: { labelIds: 'INBOX', interval: 1 },
508
+ * });
509
+ * //=>
510
+ * { "id": "ti_Zp4Lm8Qw2nXc", "trigger": "GMAIL_NEW_GMAIL_MESSAGE", "connectionId": "ca_3Hy7tR1mXc", "config": { "labelIds": "INBOX", "interval": 1 }, "enabled": true }
511
+ */
512
+ subscribe: (input: ConnectionSubscribeInput) => Promise<{
513
+ id: string;
514
+ trigger: string;
515
+ connectionId: string;
516
+ config: Record<string, unknown>;
517
+ enabled: boolean;
518
+ }>;
519
+ /**
520
+ * The user's event subscriptions. Free.
521
+ *
522
+ * @param input - Your user.
523
+ * @param input.userId - Your signed-in user's id, from the session.
524
+ * @returns The subscriptions.
525
+ * @throws VALIDATION_ERROR (400) `userId` is empty or over 200 characters.
526
+ * @example
527
+ * const subs = await totalum.connections.subscriptions({ userId: 'user_42' });
528
+ * //=>
529
+ * [
530
+ * { "id": "ti_Zp4Lm8Qw2nXc", "trigger": "GMAIL_NEW_GMAIL_MESSAGE", "connectionId": "ca_3Hy7tR1mXc", "config": { "labelIds": "INBOX", "interval": 1 }, "enabled": true }
531
+ * ]
532
+ */
533
+ subscriptions: (input: {
534
+ userId: string;
535
+ }) => Promise<{
536
+ id: string;
537
+ trigger: string;
538
+ connectionId: string;
539
+ config: Record<string, unknown>;
540
+ enabled: boolean;
541
+ }[]>;
542
+ /**
543
+ * Stops one of the user's subscriptions: no more events are delivered. Free.
544
+ *
545
+ * @param input - Your user and the subscription.
546
+ * @param input.userId - Your signed-in user's id, from the session.
547
+ * @param input.id - The subscription's `id`, from `subscribe()` or `subscriptions()`.
548
+ * @returns `{ deleted: true }`.
549
+ * @throws RECORD_NOT_FOUND (404) The user has no subscription with this id.
550
+ * @example
551
+ * await totalum.connections.unsubscribe({ userId: 'user_42', id: 'ti_Zp4Lm8Qw2nXc' });
552
+ * //=>
553
+ * { "deleted": true }
554
+ */
555
+ unsubscribe: (input: {
556
+ userId: string;
557
+ id: string;
558
+ }) => Promise<{
559
+ deleted: true;
560
+ }>;
561
+ /**
562
+ * Verifies one delivered event (the raw body text and the request headers of your `deliverTo` route) with
563
+ * `TOTALUM_WEBHOOK_SECRET` and returns it typed: `data.userId` is your user, `data.payload` the event. Answer 2xx
564
+ * quickly; a failed delivery is retried.
565
+ *
566
+ * @param rawBody - The request body as text, untouched (`await request.text()`).
567
+ * @param headers - The request's headers.
568
+ * @param secret - The signing secret. Default: `TOTALUM_WEBHOOK_SECRET`.
569
+ * @returns The verified event.
570
+ * @throws WEBHOOK_SIGNATURE_INVALID (401) Not signed by Totalum (or the body was changed): answer 401.
571
+ * @throws WEBHOOK_TIMESTAMP_EXPIRED (401) A replayed delivery: answer 401.
572
+ * @throws WEBHOOK_SECRET_MISSING No secret is set or passed.
573
+ * @example
574
+ * // src/app/api/webhooks/connections/route.ts
575
+ * export async function POST(request: Request) {
576
+ * const event = await totalum.connections.verifyEvent(await request.text(), request.headers);
577
+ * if (event.data.trigger === 'GMAIL_NEW_GMAIL_MESSAGE') await saveInboxItem(event.data.userId, event.data.payload);
578
+ * return new Response('ok');
579
+ * }
580
+ * //=>
581
+ * {
582
+ * "id": "evt_01M4P2A9K3J7H5G1F8D6S4A2Q0",
583
+ * "type": "connections.event",
584
+ * "createdAt": "2026-10-11T18:20:31.000Z",
585
+ * "projectId": "acme-crm",
586
+ * "env": "live",
587
+ * "data": {
588
+ * "subscriptionId": "ti_Zp4Lm8Qw2nXc",
589
+ * "trigger": "GMAIL_NEW_GMAIL_MESSAGE",
590
+ * "userId": "user_42",
591
+ * "connectionId": "ca_3Hy7tR1mXc",
592
+ * "payload": { "message_id": "19a2c4e6f8b0d1e3", "sender": "Ana <ana@example.com>", "subject": "Quote for October", … }
593
+ * }
594
+ * }
595
+ */
596
+ verifyEvent: (rawBody: string, headers: Headers | Record<string, string | undefined>, secret?: string) => Promise<ConnectionEvent>;
597
+ };
598
+ type TotalumConnections = ReturnType<typeof totalumConnections>;
599
+
600
+ export { Connection, ConnectionAction, ConnectionEvent, ConnectionStatus, ConnectionSubscription, ConnectionToolkit, ConnectionToolkitDetail, ConnectionTrigger, TotalumClientOptions, totalumConnections };
601
+ export type { TotalumConnections };