totalum-sdk 1.11.0 → 1.12.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.
- package/CHANGELOG.md +20 -0
- package/dist/_types/{coerce.d-BKhuaDya.d.ts → coerce.d-Cp5NZQN-.d.ts} +1 -1
- package/dist/_types/{errors.d-RTRkidv5.d.ts → errors.d-ve4rY-Hx.d.ts} +37 -5
- package/dist/_types/{integrations.d-CzTa9T-L.d.ts → integrations.d-BRhNKT7K.d.ts} +2 -2
- package/dist/_types/{ops.d-CNsrT4Ma.d.ts → ops.d-DIC4u0go.d.ts} +2 -2
- package/dist/ai/index.d.ts +275 -23
- package/dist/ai/index.js +305 -24
- package/dist/analytics/index.d.ts +58 -12
- package/dist/analytics/index.js +46 -3
- package/dist/browser/index.d.ts +228 -20
- package/dist/browser/index.js +122 -13
- package/dist/connections/index.d.ts +305 -23
- package/dist/connections/index.js +302 -21
- package/dist/cron/index.d.ts +147 -20
- package/dist/cron/index.js +157 -15
- package/dist/d1/errors.js +15 -0
- package/dist/d1/index.d.ts +254 -10
- package/dist/d1/index.js +24 -4
- package/dist/d1/session.js +26 -2
- package/dist/email/index.d.ts +65 -10
- package/dist/email/index.js +60 -5
- package/dist/errors.js +17 -0
- package/dist/files/index.d.ts +243 -20
- package/dist/files/index.js +247 -14
- package/dist/index.d.ts +25 -10
- package/dist/index.js +19 -5
- package/dist/logs/index.d.ts +48 -10
- package/dist/logs/index.js +39 -4
- package/dist/payments/index.d.ts +221 -23
- package/dist/payments/index.js +216 -18
- package/dist/pdf/index.d.ts +59 -9
- package/dist/pdf/index.js +54 -4
- package/dist/react/index.d.ts +78 -6
- package/dist/react/index.js +51 -5
- package/dist/realtime/index.d.ts +55 -8
- package/dist/realtime/index.js +53 -6
- package/dist/scan/index.d.ts +78 -10
- package/dist/scan/index.js +63 -3
- package/dist/seo/index.d.ts +1118 -8
- package/dist/seo/index.js +325 -4
- package/dist/speech/index.d.ts +34 -10
- package/dist/speech/index.js +25 -5
- package/dist/vectors/index.d.ts +96 -9
- package/dist/vectors/index.js +93 -7
- package/dist/web/index.d.ts +168 -15
- package/dist/web/index.js +163 -10
- package/dist/webhooks/index.d.ts +122 -15
- package/dist/webhooks/index.js +119 -13
- package/package.json +2 -1
- package/totalum-sdk.md +10336 -754
- package/totalum-sdk.signatures.json +69 -1
|
@@ -2,14 +2,22 @@ import { envelopeClient, jsonClient, query, withUsage } from '../http.js';
|
|
|
2
2
|
import { verifyWebhook } from '../webhooks/index.js';
|
|
3
3
|
export { TotalumError, isTotalumError } from '../errors.js';
|
|
4
4
|
/**
|
|
5
|
-
* `
|
|
6
|
-
* key). Your app's users connect their own accounts of ~1,500 apps — Google Calendar, Gmail, Google Drive, Outlook,
|
|
5
|
+
* Creates the `connections` namespace (the same object as `totalum.connections`; scope `connections`; server-side code
|
|
6
|
+
* only: it needs the project key). Your app's users connect their own accounts of ~1,500 apps — Google Calendar, Gmail, Google Drive, Outlook,
|
|
7
7
|
* OneDrive, Slack, Dropbox, Notion, HubSpot, GitHub, Stripe, Airtable, … — on a hosted page (they sign in at the
|
|
8
8
|
* provider, or type their own API key there), with no OAuth app of yours; then your server runs actions on them
|
|
9
9
|
* (`GOOGLECALENDAR_CREATE_EVENT`, `GMAIL_SEND_EMAIL`, …) and receives their events (`subscribe`). The tokens never
|
|
10
10
|
* reach your app. `userId` is always **your signed-in user's id** (the one in your database), taken from the session
|
|
11
11
|
* on the server — never from the request: each user, project and environment (dev/live) only ever sees its own
|
|
12
12
|
* connections.
|
|
13
|
+
*
|
|
14
|
+
* @param options - The project key, API URL and environment; each falls back to its environment variable.
|
|
15
|
+
* @returns The `connections` namespace: the methods below.
|
|
16
|
+
* @example
|
|
17
|
+
* import { totalumConnections } from 'totalum-sdk/connections';
|
|
18
|
+
*
|
|
19
|
+
* const connections = totalumConnections();
|
|
20
|
+
* const list = await connections.list({ userId: user.id });
|
|
13
21
|
*/
|
|
14
22
|
export function totalumConnections(options = {}) {
|
|
15
23
|
const call = envelopeClient(options);
|
|
@@ -17,55 +25,328 @@ export function totalumConnections(options = {}) {
|
|
|
17
25
|
return {
|
|
18
26
|
/**
|
|
19
27
|
* The URL to send the user to so they connect `toolkit` (e.g. `'googlecalendar'`); valid about 10 minutes, so
|
|
20
|
-
* make it when the user clicks "Connect" and redirect at once. They
|
|
21
|
-
* `?connection=success|failed&toolkit=<toolkit>` added.
|
|
28
|
+
* make it when the user clicks "Connect" and redirect at once. They sign in at the provider (or type their own key
|
|
29
|
+
* on the hosted page) and come back to `returnUrl` with `?connection=success|failed&toolkit=<toolkit>` added. A new
|
|
30
|
+
* connection through Totalum's sign-in is billed once in credits when it becomes active.
|
|
31
|
+
*
|
|
32
|
+
* @param input - Your user, the app to connect and where to come back.
|
|
33
|
+
* @returns The hosted sign-in URL to redirect the user to.
|
|
34
|
+
* @throws VALIDATION_ERROR (400) `returnUrl` is not `https://` (only `localhost` may be `http`).
|
|
35
|
+
* @throws RECORD_NOT_FOUND (404) No app with this slug: look it up with `toolkits({ search })`.
|
|
36
|
+
* @throws TOOLKIT_NOT_AVAILABLE (400) This app cannot be connected.
|
|
37
|
+
* @throws TOOLKIT_NEEDS_OWN_APP (400) This app only signs in through an OAuth app registered by the developer, which is
|
|
38
|
+
* not available.
|
|
39
|
+
* @example
|
|
40
|
+
* // src/app/api/connect/google-calendar/route.ts
|
|
41
|
+
* const user = await requireUser(); // your own session
|
|
42
|
+
* const url = await totalum.connections.connectUrl({
|
|
43
|
+
* userId: user.id,
|
|
44
|
+
* toolkit: 'googlecalendar',
|
|
45
|
+
* returnUrl: 'https://acme.totalum.app/settings/integrations',
|
|
46
|
+
* });
|
|
47
|
+
* return Response.redirect(url, 302);
|
|
48
|
+
* //=>
|
|
49
|
+
* "https://connect.<sign-in host>/link/lk_Iem_dXdIv3-i"
|
|
22
50
|
*/
|
|
23
51
|
connectUrl: async (input) => (await data('POST', '/v1/connections/link', input)).url,
|
|
24
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* The user's connected accounts (newest first), optionally of one app: show them on a settings page with a
|
|
54
|
+
* "Disconnect" button. `status` is `active` when usable. Free.
|
|
55
|
+
*
|
|
56
|
+
* @param input - Your user, and optionally one app.
|
|
57
|
+
* @param input.userId - Your signed-in user's id, from the session.
|
|
58
|
+
* @param input.toolkit - Only connections of this app (`googlecalendar`).
|
|
59
|
+
* @returns The connections.
|
|
60
|
+
* @throws VALIDATION_ERROR (400) `userId` is empty or over 200 characters.
|
|
61
|
+
* @example
|
|
62
|
+
* const list = await totalum.connections.list({ userId: 'user_42' });
|
|
63
|
+
* //=>
|
|
64
|
+
* [
|
|
65
|
+
* { "id": "ca_8Qw2nZ4kLp", "toolkit": "googlecalendar", "status": "active", "createdAt": "2026-10-02T09:14:00.000Z" },
|
|
66
|
+
* { "id": "ca_3Hy7tR1mXc", "toolkit": "gmail", "status": "expired", "createdAt": "2026-08-21T16:40:00.000Z" }
|
|
67
|
+
* ]
|
|
68
|
+
*/
|
|
25
69
|
list: async (input) => (await data('GET', `/v1/connections${query(input)}`)).connections,
|
|
26
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* Whether the user has an active connection of an app: show "Connect" or the feature that needs it. Free.
|
|
72
|
+
*
|
|
73
|
+
* @param input - Your user and the app.
|
|
74
|
+
* @param input.userId - Your signed-in user's id, from the session.
|
|
75
|
+
* @param input.toolkit - The app's slug (`googlecalendar`).
|
|
76
|
+
* @returns `true` when the user has an active connection of `toolkit`.
|
|
77
|
+
* @throws VALIDATION_ERROR (400) `userId` is empty or over 200 characters.
|
|
78
|
+
* @example
|
|
79
|
+
* const connected = await totalum.connections.isConnected({ userId: 'user_42', toolkit: 'googlecalendar' });
|
|
80
|
+
* //=>
|
|
81
|
+
* false
|
|
82
|
+
*/
|
|
27
83
|
isConnected: async (input) => (await data('GET', `/v1/connections${query(input)}`)).connections.some((c) => c.status === 'active'),
|
|
28
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* Disconnects one of the user's connected accounts (the provider's access is revoked). Free.
|
|
86
|
+
*
|
|
87
|
+
* @param input - Your user and the connection.
|
|
88
|
+
* @param input.userId - Your signed-in user's id, from the session.
|
|
89
|
+
* @param input.id - The connection's `id`, from `list()`.
|
|
90
|
+
* @returns `{ deleted: true }`.
|
|
91
|
+
* @throws RECORD_NOT_FOUND (404) The user has no connection with this id.
|
|
92
|
+
* @example
|
|
93
|
+
* await totalum.connections.disconnect({ userId: 'user_42', id: 'ca_8Qw2nZ4kLp' });
|
|
94
|
+
* //=>
|
|
95
|
+
* { "deleted": true }
|
|
96
|
+
*/
|
|
29
97
|
disconnect: async (input) => data('DELETE', `/v1/connections/${encodeURIComponent(input.id)}${query({ userId: input.userId })}`),
|
|
30
98
|
/**
|
|
31
99
|
* Runs `action` (e.g. `GOOGLECALENDAR_CREATE_EVENT`) with the user's active connection of its toolkit and
|
|
32
|
-
* returns the provider's answer in `data`.
|
|
33
|
-
*
|
|
100
|
+
* returns the provider's answer in `data`. Read the action's `inputSchema` with `action(slug)` to build `input`.
|
|
101
|
+
* Billed in credits per action.
|
|
102
|
+
*
|
|
103
|
+
* @param input - Your user, the action and its input.
|
|
104
|
+
* @returns The provider's answer and what the action cost.
|
|
105
|
+
* @throws CONNECTION_REQUIRED (409) The user has not connected this app yet: send them to `connectUrl()`;
|
|
106
|
+
* `details.action` names the action.
|
|
107
|
+
* @throws CONNECTION_ACTION_FAILED (422) The provider refused the action (a bad input, a missing permission); the
|
|
108
|
+
* message says why.
|
|
109
|
+
* @throws RECORD_NOT_FOUND (404) No action with this slug.
|
|
110
|
+
* @throws PROVIDER_TIMEOUT (504) The provider did not answer in time.
|
|
111
|
+
* @example
|
|
112
|
+
* const { data } = await totalum.connections.execute({
|
|
113
|
+
* userId: 'user_42',
|
|
114
|
+
* action: 'GOOGLECALENDAR_CREATE_EVENT',
|
|
115
|
+
* input: {
|
|
116
|
+
* summary: 'Demo with Acme',
|
|
117
|
+
* start_datetime: '2026-10-14T10:00:00',
|
|
118
|
+
* timezone: 'Europe/Madrid',
|
|
119
|
+
* event_duration_minutes: 30,
|
|
120
|
+
* attendees: ['ana@example.com'],
|
|
121
|
+
* },
|
|
122
|
+
* });
|
|
123
|
+
* //=>
|
|
124
|
+
* {
|
|
125
|
+
* "data": { "id": "5r1q8m2v6k0c4n9b", "status": "confirmed", "htmlLink": "https://www.google.com/calendar/event?eid=NXIxcThtMnY2azBj…", … },
|
|
126
|
+
* "usage": { "credits": 0.0028 }
|
|
127
|
+
* }
|
|
34
128
|
*/
|
|
35
129
|
execute: async (input) => withUsage(await call('POST', '/v1/connections/execute', input)),
|
|
36
|
-
/**
|
|
130
|
+
/**
|
|
131
|
+
* The actions an app offers (slug, name, description), optionally filtered by words — to find the slug to pass to
|
|
132
|
+
* `execute()`. Free.
|
|
133
|
+
*
|
|
134
|
+
* @param input - The app and an optional search.
|
|
135
|
+
* @param input.toolkit - The app's slug (`googlecalendar`).
|
|
136
|
+
* @param input.search - Only actions matching these words (`create event`).
|
|
137
|
+
* @returns The matching actions, without their input schemas (read one with `action(slug)`).
|
|
138
|
+
* @throws RECORD_NOT_FOUND (404) No app with this slug.
|
|
139
|
+
* @example
|
|
140
|
+
* const actions = await totalum.connections.actions({ toolkit: 'googlecalendar', search: 'create event' });
|
|
141
|
+
* //=>
|
|
142
|
+
* [
|
|
143
|
+
* { "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…" },
|
|
144
|
+
* { "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'…" }
|
|
145
|
+
* ]
|
|
146
|
+
*/
|
|
37
147
|
actions: async (input) => (await data('GET', `/v1/connections/actions${query(input)}`)).actions,
|
|
38
|
-
/**
|
|
148
|
+
/**
|
|
149
|
+
* One action with its `inputSchema`: the JSON Schema of what `execute()` takes as `input`. Free.
|
|
150
|
+
*
|
|
151
|
+
* @param slug - The action's slug (`GOOGLECALENDAR_CREATE_EVENT`).
|
|
152
|
+
* @returns The action and its input schema.
|
|
153
|
+
* @throws RECORD_NOT_FOUND (404) No action with this slug.
|
|
154
|
+
* @example
|
|
155
|
+
* const action = await totalum.connections.action('GOOGLECALENDAR_CREATE_EVENT');
|
|
156
|
+
* //=>
|
|
157
|
+
* {
|
|
158
|
+
* "slug": "GOOGLECALENDAR_CREATE_EVENT",
|
|
159
|
+
* "toolkit": "googlecalendar",
|
|
160
|
+
* "name": "Create Event",
|
|
161
|
+
* "description": "Creates a timed event using start_datetime and either end_datetime or duration fields…",
|
|
162
|
+
* "inputSchema": {
|
|
163
|
+
* "type": "object",
|
|
164
|
+
* "properties": {
|
|
165
|
+
* "summary": { "type": "string", "description": "Summary (title) of the event." },
|
|
166
|
+
* "start_datetime": { "type": "string", "description": "Event start time…" },
|
|
167
|
+
* …
|
|
168
|
+
* }
|
|
169
|
+
* }
|
|
170
|
+
* }
|
|
171
|
+
*/
|
|
39
172
|
action: (slug) => data('GET', `/v1/connections/actions/${encodeURIComponent(slug)}`),
|
|
40
173
|
/**
|
|
41
174
|
* Searches the catalogue of apps (`search` matches names and descriptions, `category` e.g. `crm`); `connect`
|
|
42
175
|
* says how a user connects it: `oauth` (signs in at the provider), `credentials` (types their own key on the
|
|
43
176
|
* hosted page), `none` (no connection: run its actions directly), `unavailable` (cannot be connected). Pages
|
|
44
|
-
* with `cursor` = the previous `nextCursor`.
|
|
177
|
+
* with `cursor` = the previous `nextCursor`. Free.
|
|
178
|
+
*
|
|
179
|
+
* @param input - The search, category and paging; all optional.
|
|
180
|
+
* @param input.search - Words to match in app names and descriptions (`calendar`).
|
|
181
|
+
* @param input.category - Only apps of this category (`crm`, `email`, `calendar`).
|
|
182
|
+
* @param input.cursor - The previous page's `nextCursor`.
|
|
183
|
+
* @param input.limit - Apps per page.
|
|
184
|
+
* @returns One page of apps, the cursor of the next and the total.
|
|
185
|
+
* @throws PROVIDER_UNAVAILABLE (503) The catalogue is not available right now; retry later.
|
|
186
|
+
* @example
|
|
187
|
+
* const page = await totalum.connections.toolkits({ search: 'calendar', limit: 2 });
|
|
188
|
+
* //=>
|
|
189
|
+
* {
|
|
190
|
+
* "toolkits": [
|
|
191
|
+
* { "slug": "googlecalendar", "name": "Google Calendar", "description": "Google Calendar is a time management tool…", "categories": ["scheduling-&-booking"], "authSchemes": ["OAUTH2"], "connect": "oauth", "actionsCount": 47, "triggersCount": 7 },
|
|
192
|
+
* { "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 }
|
|
193
|
+
* ],
|
|
194
|
+
* "nextCursor": "Mi0y",
|
|
195
|
+
* "total": 18
|
|
196
|
+
* }
|
|
45
197
|
*/
|
|
46
198
|
toolkits: (input = {}) => data('GET', `/v1/connections/toolkits${query(input)}`),
|
|
47
|
-
/**
|
|
199
|
+
/**
|
|
200
|
+
* One app, exactly: how it connects and, for `credentials`, the fields the user types on the hosted page. Free.
|
|
201
|
+
*
|
|
202
|
+
* @param slug - The app's slug (`googlecalendar`).
|
|
203
|
+
* @returns The app's details.
|
|
204
|
+
* @throws RECORD_NOT_FOUND (404) No app with this slug.
|
|
205
|
+
* @example
|
|
206
|
+
* const app = await totalum.connections.toolkit('googlecalendar');
|
|
207
|
+
* //=>
|
|
208
|
+
* {
|
|
209
|
+
* "slug": "googlecalendar",
|
|
210
|
+
* "name": "Google Calendar",
|
|
211
|
+
* "description": "Google Calendar is a time management tool providing scheduling features…",
|
|
212
|
+
* "categories": ["scheduling-&-booking"],
|
|
213
|
+
* "authSchemes": ["OAUTH2"],
|
|
214
|
+
* "connect": "oauth",
|
|
215
|
+
* "actionsCount": 47,
|
|
216
|
+
* "triggersCount": 7,
|
|
217
|
+
* "credentialFields": []
|
|
218
|
+
* }
|
|
219
|
+
*/
|
|
48
220
|
toolkit: (slug) => data('GET', `/v1/connections/toolkits/${encodeURIComponent(slug)}`),
|
|
49
|
-
/**
|
|
221
|
+
/**
|
|
222
|
+
* The events (triggers) an app can send, such as `GMAIL_NEW_GMAIL_MESSAGE` — to find the slug to pass to
|
|
223
|
+
* `subscribe()`. Free.
|
|
224
|
+
*
|
|
225
|
+
* @param input - The app.
|
|
226
|
+
* @param input.toolkit - The app's slug (`gmail`).
|
|
227
|
+
* @returns The app's triggers, without their schemas (read one with `trigger(slug)`).
|
|
228
|
+
* @throws RECORD_NOT_FOUND (404) No app with this slug.
|
|
229
|
+
* @example
|
|
230
|
+
* const triggers = await totalum.connections.triggers({ toolkit: 'gmail' });
|
|
231
|
+
* //=>
|
|
232
|
+
* [
|
|
233
|
+
* { "slug": "GMAIL_EMAIL_SENT_TRIGGER", "toolkit": "gmail", "name": "Email Sent", "description": "Triggers when a Gmail message is sent by the authenticated user…", "type": "poll" },
|
|
234
|
+
* { "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" }
|
|
235
|
+
* ]
|
|
236
|
+
*/
|
|
50
237
|
triggers: async (input) => (await data('GET', `/v1/connections/triggers${query(input)}`)).triggers,
|
|
51
|
-
/**
|
|
238
|
+
/**
|
|
239
|
+
* One trigger with `configSchema` (what `subscribe`'s `config` takes) and `payloadSchema` (the event's shape).
|
|
240
|
+
* Free.
|
|
241
|
+
*
|
|
242
|
+
* @param slug - The trigger's slug (`GMAIL_NEW_GMAIL_MESSAGE`).
|
|
243
|
+
* @returns The trigger and its schemas.
|
|
244
|
+
* @throws RECORD_NOT_FOUND (404) No trigger with this slug.
|
|
245
|
+
* @example
|
|
246
|
+
* const trigger = await totalum.connections.trigger('GMAIL_NEW_GMAIL_MESSAGE');
|
|
247
|
+
* //=>
|
|
248
|
+
* {
|
|
249
|
+
* "slug": "GMAIL_NEW_GMAIL_MESSAGE",
|
|
250
|
+
* "toolkit": "gmail",
|
|
251
|
+
* "name": "New Gmail Message Received Trigger",
|
|
252
|
+
* "description": "Triggers when a new message is received in Gmail.",
|
|
253
|
+
* "type": "poll",
|
|
254
|
+
* "instructions": "Provide the user ID (usually 'me')…",
|
|
255
|
+
* "configSchema": {
|
|
256
|
+
* "properties": {
|
|
257
|
+
* "interval": { "type": "number", "default": 2, "description": "Periodic Interval to Check for Updates & Send a Trigger in Minutes" },
|
|
258
|
+
* "labelIds": { "type": "string", "default": "INBOX", "description": "Filter messages by a single label ID…" }
|
|
259
|
+
* }
|
|
260
|
+
* },
|
|
261
|
+
* "payloadSchema": { "properties": { "message_id": { "type": "string" }, "sender": { "type": "string" }, "subject": { "type": "string" }, … } }
|
|
262
|
+
* }
|
|
263
|
+
*/
|
|
52
264
|
trigger: (slug) => data('GET', `/v1/connections/triggers/${encodeURIComponent(slug)}`),
|
|
53
265
|
/**
|
|
54
266
|
* Watches `trigger` on the user's active connection of its toolkit: each event is POSTed to `deliverTo` (a path
|
|
55
267
|
* of your own app, default `/api/webhooks/connections`) on the preview (dev users) or the published site (live
|
|
56
|
-
* users), signed with your project's webhook secret — read it with `verifyEvent`.
|
|
57
|
-
*
|
|
268
|
+
* users), signed with your project's webhook secret — read it with `verifyEvent`. Each delivered event is billed in
|
|
269
|
+
* credits.
|
|
270
|
+
*
|
|
271
|
+
* @param input - Your user, the trigger, its configuration and where to deliver.
|
|
272
|
+
* @returns The subscription; keep its `id` to `unsubscribe()` later.
|
|
273
|
+
* @throws CONNECTION_REQUIRED (409) The user has not connected this app yet: send them to `connectUrl()`.
|
|
274
|
+
* @throws RECORD_NOT_FOUND (404) No trigger with this slug.
|
|
275
|
+
* @throws VALIDATION_ERROR (400) `config` does not match the trigger's `configSchema`, or `deliverTo` is not a path.
|
|
276
|
+
* @example
|
|
277
|
+
* const sub = await totalum.connections.subscribe({
|
|
278
|
+
* userId: 'user_42',
|
|
279
|
+
* trigger: 'GMAIL_NEW_GMAIL_MESSAGE',
|
|
280
|
+
* config: { labelIds: 'INBOX', interval: 1 },
|
|
281
|
+
* });
|
|
282
|
+
* //=>
|
|
283
|
+
* { "id": "ti_Zp4Lm8Qw2nXc", "trigger": "GMAIL_NEW_GMAIL_MESSAGE", "connectionId": "ca_3Hy7tR1mXc", "config": { "labelIds": "INBOX", "interval": 1 }, "enabled": true }
|
|
58
284
|
*/
|
|
59
285
|
subscribe: (input) => data('POST', '/v1/connections/subscriptions', input),
|
|
60
|
-
/**
|
|
286
|
+
/**
|
|
287
|
+
* The user's event subscriptions. Free.
|
|
288
|
+
*
|
|
289
|
+
* @param input - Your user.
|
|
290
|
+
* @param input.userId - Your signed-in user's id, from the session.
|
|
291
|
+
* @returns The subscriptions.
|
|
292
|
+
* @throws VALIDATION_ERROR (400) `userId` is empty or over 200 characters.
|
|
293
|
+
* @example
|
|
294
|
+
* const subs = await totalum.connections.subscriptions({ userId: 'user_42' });
|
|
295
|
+
* //=>
|
|
296
|
+
* [
|
|
297
|
+
* { "id": "ti_Zp4Lm8Qw2nXc", "trigger": "GMAIL_NEW_GMAIL_MESSAGE", "connectionId": "ca_3Hy7tR1mXc", "config": { "labelIds": "INBOX", "interval": 1 }, "enabled": true }
|
|
298
|
+
* ]
|
|
299
|
+
*/
|
|
61
300
|
subscriptions: async (input) => (await data('GET', `/v1/connections/subscriptions${query(input)}`))
|
|
62
301
|
.subscriptions,
|
|
63
|
-
/**
|
|
302
|
+
/**
|
|
303
|
+
* Stops one of the user's subscriptions: no more events are delivered. Free.
|
|
304
|
+
*
|
|
305
|
+
* @param input - Your user and the subscription.
|
|
306
|
+
* @param input.userId - Your signed-in user's id, from the session.
|
|
307
|
+
* @param input.id - The subscription's `id`, from `subscribe()` or `subscriptions()`.
|
|
308
|
+
* @returns `{ deleted: true }`.
|
|
309
|
+
* @throws RECORD_NOT_FOUND (404) The user has no subscription with this id.
|
|
310
|
+
* @example
|
|
311
|
+
* await totalum.connections.unsubscribe({ userId: 'user_42', id: 'ti_Zp4Lm8Qw2nXc' });
|
|
312
|
+
* //=>
|
|
313
|
+
* { "deleted": true }
|
|
314
|
+
*/
|
|
64
315
|
unsubscribe: (input) => data('DELETE', `/v1/connections/subscriptions/${encodeURIComponent(input.id)}${query({ userId: input.userId })}`),
|
|
65
316
|
/**
|
|
66
317
|
* Verifies one delivered event (the raw body text and the request headers of your `deliverTo` route) with
|
|
67
|
-
* `TOTALUM_WEBHOOK_SECRET` and returns it typed: `data.userId` is your user, `data.payload` the event.
|
|
68
|
-
*
|
|
318
|
+
* `TOTALUM_WEBHOOK_SECRET` and returns it typed: `data.userId` is your user, `data.payload` the event. Answer 2xx
|
|
319
|
+
* quickly; a failed delivery is retried.
|
|
320
|
+
*
|
|
321
|
+
* @param rawBody - The request body as text, untouched (`await request.text()`).
|
|
322
|
+
* @param headers - The request's headers.
|
|
323
|
+
* @param secret - The signing secret. Default: `TOTALUM_WEBHOOK_SECRET`.
|
|
324
|
+
* @returns The verified event.
|
|
325
|
+
* @throws WEBHOOK_SIGNATURE_INVALID (401) Not signed by Totalum (or the body was changed): answer 401.
|
|
326
|
+
* @throws WEBHOOK_TIMESTAMP_EXPIRED (401) A replayed delivery: answer 401.
|
|
327
|
+
* @throws WEBHOOK_SECRET_MISSING No secret is set or passed.
|
|
328
|
+
* @example
|
|
329
|
+
* // src/app/api/webhooks/connections/route.ts
|
|
330
|
+
* export async function POST(request: Request) {
|
|
331
|
+
* const event = await totalum.connections.verifyEvent(await request.text(), request.headers);
|
|
332
|
+
* if (event.data.trigger === 'GMAIL_NEW_GMAIL_MESSAGE') await saveInboxItem(event.data.userId, event.data.payload);
|
|
333
|
+
* return new Response('ok');
|
|
334
|
+
* }
|
|
335
|
+
* //=>
|
|
336
|
+
* {
|
|
337
|
+
* "id": "evt_01M4P2A9K3J7H5G1F8D6S4A2Q0",
|
|
338
|
+
* "type": "connections.event",
|
|
339
|
+
* "createdAt": "2026-10-11T18:20:31.000Z",
|
|
340
|
+
* "projectId": "acme-crm",
|
|
341
|
+
* "env": "live",
|
|
342
|
+
* "data": {
|
|
343
|
+
* "subscriptionId": "ti_Zp4Lm8Qw2nXc",
|
|
344
|
+
* "trigger": "GMAIL_NEW_GMAIL_MESSAGE",
|
|
345
|
+
* "userId": "user_42",
|
|
346
|
+
* "connectionId": "ca_3Hy7tR1mXc",
|
|
347
|
+
* "payload": { "message_id": "19a2c4e6f8b0d1e3", "sender": "Ana <ana@example.com>", "subject": "Quote for October", … }
|
|
348
|
+
* }
|
|
349
|
+
* }
|
|
69
350
|
*/
|
|
70
351
|
verifyEvent: async (rawBody, headers, secret) => (await verifyWebhook(rawBody, headers, secret)),
|
|
71
352
|
};
|
package/dist/cron/index.d.ts
CHANGED
|
@@ -1,26 +1,60 @@
|
|
|
1
|
-
import { d as CronJobInput, c as CronJob, e as CronJobPatch } from '../_types/integrations.d-
|
|
2
|
-
export { f as CronRun, g as CronRunsPage } from '../_types/integrations.d-
|
|
3
|
-
import { T as TotalumClientOptions } from '../_types/errors.d-
|
|
4
|
-
export { a as TotalumError, b as TotalumErrorCode, i as isTotalumError } from '../_types/errors.d-
|
|
5
|
-
import '../_types/coerce.d-
|
|
1
|
+
import { d as CronJobInput, c as CronJob, e as CronJobPatch } from '../_types/integrations.d-BRhNKT7K.js';
|
|
2
|
+
export { f as CronRun, g as CronRunsPage } from '../_types/integrations.d-BRhNKT7K.js';
|
|
3
|
+
import { T as TotalumClientOptions } from '../_types/errors.d-ve4rY-Hx.js';
|
|
4
|
+
export { a as TotalumError, b as TotalumErrorCode, i as isTotalumError } from '../_types/errors.d-ve4rY-Hx.js';
|
|
5
|
+
import '../_types/coerce.d-Cp5NZQN-.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* `
|
|
8
|
+
* Creates the `cron` namespace (the same object as `totalum.cron`, scope `cron`): HTTP jobs against the project's own host,
|
|
9
9
|
* fired by Totalum's Scheduler; limits per plan (`429 CRON_LIMIT_REACHED {limit, plan}`, `400 INVALID_SCHEDULE
|
|
10
10
|
* {minIntervalSeconds}`). Each run costs a small fraction of a credit. `timezone` (IANA) reads the schedule on that zone's clock, daylight
|
|
11
11
|
* saving included; `pauseAfterFailures` (1–100, default 3; `null` = never) sets how many failed runs in a row pause it.
|
|
12
|
+
*
|
|
13
|
+
* @param options - The project key, API URL and environment; each falls back to its environment variable.
|
|
14
|
+
* @returns The `cron` namespace: the methods below.
|
|
15
|
+
* @example
|
|
16
|
+
* import { totalumCron } from 'totalum-sdk/cron';
|
|
17
|
+
*
|
|
18
|
+
* const cron = totalumCron();
|
|
19
|
+
* const jobs = await cron.list();
|
|
12
20
|
*/
|
|
13
21
|
declare function totalumCron(options?: TotalumClientOptions): {
|
|
14
22
|
/**
|
|
15
|
-
*
|
|
23
|
+
* Creates a job that calls a route of your own app on a schedule — a cron expression (`'0 8 * * *'`) or
|
|
24
|
+
* `{ everyMinutes: 15 }`. The URL must be the project's own `https://` host: the published site for a `live` job,
|
|
25
|
+
* the preview for a `dev` one (without `env`, the URL decides). Each call is signed by Totalum (the template's cron
|
|
26
|
+
* routes check it) and recorded in `runs()`.
|
|
16
27
|
*
|
|
28
|
+
* @param input - The name, schedule, request and options.
|
|
29
|
+
* @returns The new job.
|
|
30
|
+
* @throws INVALID_SCHEDULE (400) Not a valid schedule, or it fires more often than the plan allows;
|
|
31
|
+
* `details.minIntervalSeconds`.
|
|
32
|
+
* @throws CRON_URL_NOT_ALLOWED (403) The URL is not the project's own `https://` host for that environment;
|
|
33
|
+
* `details.allowedHost`.
|
|
34
|
+
* @throws CRON_REQUIRES_PUBLISHED_PROJECT (403) A `live` job, but the project is not published yet.
|
|
35
|
+
* @throws CRON_LIMIT_REACHED (429) The plan's number of jobs per environment is reached; `details.limit`.
|
|
36
|
+
* @throws ENGINE_UNAVAILABLE (502) The scheduler is unavailable; retry shortly.
|
|
17
37
|
* @example
|
|
18
|
-
* await cron.create({
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
38
|
+
* const job = await totalum.cron.create({
|
|
39
|
+
* name: 'daily-report',
|
|
40
|
+
* schedule: '0 8 * * *', // 08:00 in Madrid all year
|
|
41
|
+
* timezone: 'Europe/Madrid',
|
|
42
|
+
* request: { method: 'POST', url: 'https://acme.totalum.app/api/cron/report' },
|
|
23
43
|
* });
|
|
44
|
+
* //=>
|
|
45
|
+
* {
|
|
46
|
+
* "id": "cj_01M4P1F0R7T2Y9U4I6O3P8A5SD",
|
|
47
|
+
* "name": "daily-report",
|
|
48
|
+
* "schedule": "0 8 * * *",
|
|
49
|
+
* "request": { "method": "POST", "url": "https://acme.totalum.app/api/cron/report" },
|
|
50
|
+
* "enabled": true,
|
|
51
|
+
* "status": "active",
|
|
52
|
+
* "nextRunAt": "2026-10-12T06:00:00.000Z",
|
|
53
|
+
* "createdAt": "2026-10-11T18:30:00.000Z",
|
|
54
|
+
* "env": "live",
|
|
55
|
+
* "timezone": "Europe/Madrid",
|
|
56
|
+
* "pauseAfterFailures": 3
|
|
57
|
+
* }
|
|
24
58
|
*/
|
|
25
59
|
create: (input: CronJobInput) => Promise<{
|
|
26
60
|
id: string;
|
|
@@ -49,7 +83,31 @@ declare function totalumCron(options?: TotalumClientOptions): {
|
|
|
49
83
|
description?: string | undefined;
|
|
50
84
|
timezone?: string | undefined;
|
|
51
85
|
}>;
|
|
52
|
-
/**
|
|
86
|
+
/**
|
|
87
|
+
* Every job of the project, both environments. Free.
|
|
88
|
+
*
|
|
89
|
+
* @returns The jobs.
|
|
90
|
+
* @throws ENGINE_UNAVAILABLE (502) The scheduler is unavailable; retry shortly.
|
|
91
|
+
* @example
|
|
92
|
+
* const jobs = await totalum.cron.list();
|
|
93
|
+
* //=>
|
|
94
|
+
* [
|
|
95
|
+
* {
|
|
96
|
+
* "id": "cj_01M4P1F0R7T2Y9U4I6O3P8A5SD",
|
|
97
|
+
* "name": "daily-report",
|
|
98
|
+
* "schedule": "0 8 * * *",
|
|
99
|
+
* "request": { "method": "POST", "url": "https://acme.totalum.app/api/cron/report" },
|
|
100
|
+
* "enabled": true,
|
|
101
|
+
* "status": "active",
|
|
102
|
+
* "nextRunAt": "2026-10-12T06:00:00.000Z",
|
|
103
|
+
* "lastRun": { "at": "2026-10-11T06:00:00.412Z", "status": 200, "latencyMs": 812 },
|
|
104
|
+
* "createdAt": "2026-10-01T18:30:00.000Z",
|
|
105
|
+
* "env": "live",
|
|
106
|
+
* "timezone": "Europe/Madrid",
|
|
107
|
+
* "pauseAfterFailures": 3
|
|
108
|
+
* }
|
|
109
|
+
* ]
|
|
110
|
+
*/
|
|
53
111
|
list: () => Promise<{
|
|
54
112
|
id: string;
|
|
55
113
|
name: string;
|
|
@@ -77,9 +135,18 @@ declare function totalumCron(options?: TotalumClientOptions): {
|
|
|
77
135
|
description?: string | undefined;
|
|
78
136
|
timezone?: string | undefined;
|
|
79
137
|
}[]>;
|
|
80
|
-
/**
|
|
138
|
+
/**
|
|
139
|
+
* One job, or `null` when the project has no job with this id. Free.
|
|
140
|
+
*
|
|
141
|
+
* @param id - The job's `id` (`cj_…`).
|
|
142
|
+
* @returns The job, or `null`.
|
|
143
|
+
* @throws ENGINE_UNAVAILABLE (502) The scheduler is unavailable; retry shortly.
|
|
144
|
+
* @example
|
|
145
|
+
* const job = await totalum.cron.get('cj_01M4P1F0R7T2Y9U4I6O3P8A5SD');
|
|
146
|
+
* //=>
|
|
147
|
+
* { "id": "cj_01M4P1F0R7T2Y9U4I6O3P8A5SD", "name": "daily-report", "status": "active", "nextRunAt": "2026-10-12T06:00:00.000Z", … }
|
|
148
|
+
*/
|
|
81
149
|
get: (id: string) => Promise<CronJob | null>;
|
|
82
|
-
/** Changes any field of a job (`schedule`, `request`, `enabled`, …). */
|
|
83
150
|
update: (id: string, patch: CronJobPatch) => Promise<{
|
|
84
151
|
id: string;
|
|
85
152
|
name: string;
|
|
@@ -107,9 +174,27 @@ declare function totalumCron(options?: TotalumClientOptions): {
|
|
|
107
174
|
description?: string | undefined;
|
|
108
175
|
timezone?: string | undefined;
|
|
109
176
|
}>;
|
|
110
|
-
/**
|
|
177
|
+
/**
|
|
178
|
+
* Deletes a job and its run history.
|
|
179
|
+
*
|
|
180
|
+
* @param id - The job's `id`.
|
|
181
|
+
* @returns Nothing once deleted.
|
|
182
|
+
* @throws CRON_JOB_NOT_FOUND (404) No job with this id.
|
|
183
|
+
* @example
|
|
184
|
+
* await totalum.cron.delete('cj_01M4P1F0R7T2Y9U4I6O3P8A5SD');
|
|
185
|
+
*/
|
|
111
186
|
delete: (id: string) => Promise<void>;
|
|
112
|
-
/**
|
|
187
|
+
/**
|
|
188
|
+
* Stops a job from firing until `resume` (the same as `update(id, { enabled: false })`).
|
|
189
|
+
*
|
|
190
|
+
* @param id - The job's `id`.
|
|
191
|
+
* @returns The job, now `paused`.
|
|
192
|
+
* @throws CRON_JOB_NOT_FOUND (404) No job with this id.
|
|
193
|
+
* @example
|
|
194
|
+
* const job = await totalum.cron.pause('cj_01M4P1F0R7T2Y9U4I6O3P8A5SD');
|
|
195
|
+
* //=>
|
|
196
|
+
* { "id": "cj_01M4P1F0R7T2Y9U4I6O3P8A5SD", "enabled": false, "status": "paused", "nextRunAt": null, … }
|
|
197
|
+
*/
|
|
113
198
|
pause: (id: string) => Promise<{
|
|
114
199
|
id: string;
|
|
115
200
|
name: string;
|
|
@@ -137,7 +222,17 @@ declare function totalumCron(options?: TotalumClientOptions): {
|
|
|
137
222
|
description?: string | undefined;
|
|
138
223
|
timezone?: string | undefined;
|
|
139
224
|
}>;
|
|
140
|
-
/**
|
|
225
|
+
/**
|
|
226
|
+
* Lets a paused job fire again — also one paused after failing runs (`paused_failures`) once its route is fixed.
|
|
227
|
+
*
|
|
228
|
+
* @param id - The job's `id`.
|
|
229
|
+
* @returns The job, now `active`.
|
|
230
|
+
* @throws CRON_JOB_NOT_FOUND (404) No job with this id.
|
|
231
|
+
* @example
|
|
232
|
+
* const job = await totalum.cron.resume('cj_01M4P1F0R7T2Y9U4I6O3P8A5SD');
|
|
233
|
+
* //=>
|
|
234
|
+
* { "id": "cj_01M4P1F0R7T2Y9U4I6O3P8A5SD", "enabled": true, "status": "active", "nextRunAt": "2026-10-12T06:00:00.000Z", … }
|
|
235
|
+
*/
|
|
141
236
|
resume: (id: string) => Promise<{
|
|
142
237
|
id: string;
|
|
143
238
|
name: string;
|
|
@@ -165,7 +260,27 @@ declare function totalumCron(options?: TotalumClientOptions): {
|
|
|
165
260
|
description?: string | undefined;
|
|
166
261
|
timezone?: string | undefined;
|
|
167
262
|
}>;
|
|
168
|
-
/**
|
|
263
|
+
/**
|
|
264
|
+
* A job's executions of the last 30 days, newest first: when each ran, the HTTP status your route answered and how
|
|
265
|
+
* long it took. Free.
|
|
266
|
+
*
|
|
267
|
+
* @param id - The job's `id`.
|
|
268
|
+
* @param opts - Paging.
|
|
269
|
+
* @param opts.limit - Runs per page.
|
|
270
|
+
* @param opts.cursor - The previous page's `nextCursor`.
|
|
271
|
+
* @returns One page of runs.
|
|
272
|
+
* @throws CRON_JOB_NOT_FOUND (404) No job with this id.
|
|
273
|
+
* @example
|
|
274
|
+
* const page = await totalum.cron.runs('cj_01M4P1F0R7T2Y9U4I6O3P8A5SD', { limit: 2 });
|
|
275
|
+
* //=>
|
|
276
|
+
* {
|
|
277
|
+
* "items": [
|
|
278
|
+
* { "id": "cr_01M4P1G2H3J4K5L6M7N8P9Q0RS", "scheduledFor": "2026-10-11T06:00:00.000Z", "startedAt": "2026-10-11T06:00:00.412Z", "status": 200, "latencyMs": 812, "responseSnippet": "{\"ok\":true}" },
|
|
279
|
+
* { "id": "cr_01M4MZ8B7V6C5X4Z3A2S1D0F9G", "scheduledFor": "2026-10-10T06:00:00.000Z", "startedAt": "2026-10-10T06:00:00.388Z", "status": "timeout", "latencyMs": 30000, "error": "The request timed out" }
|
|
280
|
+
* ],
|
|
281
|
+
* "nextCursor": "MjAyNi0xMC0xMFQwNjowMDowMC4wMDBa"
|
|
282
|
+
* }
|
|
283
|
+
*/
|
|
169
284
|
runs: (id: string, opts?: {
|
|
170
285
|
limit?: number;
|
|
171
286
|
cursor?: string;
|
|
@@ -181,7 +296,19 @@ declare function totalumCron(options?: TotalumClientOptions): {
|
|
|
181
296
|
}[];
|
|
182
297
|
nextCursor: string | null;
|
|
183
298
|
}>;
|
|
184
|
-
/**
|
|
299
|
+
/**
|
|
300
|
+
* Fires a job now, outside its schedule — a "Run now" button, or to test a new job. At most 10 manual runs a
|
|
301
|
+
* minute per project.
|
|
302
|
+
*
|
|
303
|
+
* @param id - The job's `id`.
|
|
304
|
+
* @returns The id of the run it started (it shows in `runs()` once done).
|
|
305
|
+
* @throws CRON_JOB_NOT_FOUND (404) No job with this id.
|
|
306
|
+
* @throws RATE_LIMITED (429) More than 10 manual runs in a minute; `details.retryAfterSeconds`.
|
|
307
|
+
* @example
|
|
308
|
+
* const { runId } = await totalum.cron.trigger('cj_01M4P1F0R7T2Y9U4I6O3P8A5SD');
|
|
309
|
+
* //=>
|
|
310
|
+
* { "runId": "cr_01M4P1H5J6K7L8M9N0P1Q2R3ST" }
|
|
311
|
+
*/
|
|
185
312
|
trigger: (id: string) => Promise<{
|
|
186
313
|
runId: string;
|
|
187
314
|
}>;
|