@softr/sdk 1.5.0 → 1.6.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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @softr/sdk
2
2
 
3
+ ## 1.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Add `defineEmailAction` to declare an email the app sends, and `email.send` and `EmailError` on `@softr/sdk/server` to send it.
8
+
9
+ ## 1.5.1
10
+
11
+ ### Patch Changes
12
+
13
+ - The `integrations` skill lists the base URLs of Microsoft Planner, Tally, Trello and Typeform.
14
+
3
15
  ## 1.5.0
4
16
 
5
17
  ### Minor Changes
package/dist/action.d.ts CHANGED
@@ -304,6 +304,50 @@ type IntegrationDefinition<TId extends string> = {
304
304
  * const res = await listEvents({ query: { timeMin: now, singleEvents: "true" } })
305
305
  */
306
306
  declare function defineIntegration<const TId extends string>(definition: IntegrationDefinition<TId>): IntegrationAction<TId>;
307
+ type EmailFields = {
308
+ senderId?: string;
309
+ to?: ReadonlyArray<string>;
310
+ cc?: ReadonlyArray<string>;
311
+ bcc?: ReadonlyArray<string>;
312
+ replyTo?: string;
313
+ };
314
+ type EmailResource = EmailFields & {
315
+ type: "SOFTR_EMAIL";
316
+ };
317
+ type EmailAction<TId extends string = string> = Action<EmailResource> & {
318
+ id: TId;
319
+ };
320
+ type EmailDefinition<TId extends string> = EmailFields & {
321
+ id: TId;
322
+ permissions: ActionPermissions;
323
+ };
324
+ /**
325
+ * Declares an email action: who may send it, and the fields every email it sends keeps whatever the
326
+ * call says. Softr sends it and bills the workspace's workflow credits.
327
+ *
328
+ * - `to`, `cc`, `bcc`: addresses. An element may be a whole `{LOGGED_IN_USER:EMAIL}` or
329
+ * `{LOGGED_IN_USER:<field>}` placeholder, filled in for the signed-in sender.
330
+ * - `replyTo`: an address or one such placeholder.
331
+ * - `senderId`: one of the workspace's email senders, for an email that must come from that address.
332
+ * Left out, the app's sender is used, else Softr's testing address. The call can never choose the sender.
333
+ *
334
+ * A field declared here wins over the call's, and declaring `to` also ignores the call's `cc` and
335
+ * `bcc`. Fix the recipients whenever the use case allows. An action that leaves `to` out lets the
336
+ * caller choose the recipients, so Softr stores it only for custom user groups:
337
+ * `{ userGroupTypes: ["LOGGED_IN_USERS"], customGroups: [...] }`.
338
+ *
339
+ * Pass the returned object to `email.send()` at runtime.
340
+ *
341
+ * @example
342
+ * const notifyOwner = defineEmailAction({
343
+ * id: "notifyOwner",
344
+ * to: ["owner@acme.com"],
345
+ * permissions: { userGroupTypes: ["NON_LOGGED_IN_USERS", "LOGGED_IN_USERS"] },
346
+ * })
347
+ *
348
+ * await email.send(notifyOwner, { subject: "New submission", body: html, replyTo: data.email })
349
+ */
350
+ declare function defineEmailAction<const TId extends string>(definition: EmailDefinition<TId>): EmailAction<TId>;
307
351
  type AiResource = {
308
352
  type: "SOFTR_AI";
309
353
  model: string;
@@ -338,4 +382,4 @@ type AiDefinition<TId extends string> = {
338
382
  */
339
383
  declare function defineAiAction<const TId extends string>(definition: AiDefinition<TId>): AiAction<TId>;
340
384
  //#endregion
341
- export { ActionData, ActionPermissions, ActionRecord, ActionShape, AiAction, DatasourceAction, FieldTypeOf, IntegrationAction, ReadOf, ReadShape, SoftrDatasources, WorkflowAction, defineAiAction, defineIntegration, defineMutation, defineQuery, defineWorkflow };
385
+ export { ActionData, ActionPermissions, ActionRecord, ActionShape, AiAction, DatasourceAction, EmailAction, FieldTypeOf, IntegrationAction, ReadOf, ReadShape, SoftrDatasources, WorkflowAction, defineAiAction, defineEmailAction, defineIntegration, defineMutation, defineQuery, defineWorkflow };
package/dist/action.js CHANGED
@@ -67,6 +67,43 @@ function defineIntegration(definition) {
67
67
  permissions
68
68
  };
69
69
  }
70
+ /**
71
+ * Declares an email action: who may send it, and the fields every email it sends keeps whatever the
72
+ * call says. Softr sends it and bills the workspace's workflow credits.
73
+ *
74
+ * - `to`, `cc`, `bcc`: addresses. An element may be a whole `{LOGGED_IN_USER:EMAIL}` or
75
+ * `{LOGGED_IN_USER:<field>}` placeholder, filled in for the signed-in sender.
76
+ * - `replyTo`: an address or one such placeholder.
77
+ * - `senderId`: one of the workspace's email senders, for an email that must come from that address.
78
+ * Left out, the app's sender is used, else Softr's testing address. The call can never choose the sender.
79
+ *
80
+ * A field declared here wins over the call's, and declaring `to` also ignores the call's `cc` and
81
+ * `bcc`. Fix the recipients whenever the use case allows. An action that leaves `to` out lets the
82
+ * caller choose the recipients, so Softr stores it only for custom user groups:
83
+ * `{ userGroupTypes: ["LOGGED_IN_USERS"], customGroups: [...] }`.
84
+ *
85
+ * Pass the returned object to `email.send()` at runtime.
86
+ *
87
+ * @example
88
+ * const notifyOwner = defineEmailAction({
89
+ * id: "notifyOwner",
90
+ * to: ["owner@acme.com"],
91
+ * permissions: { userGroupTypes: ["NON_LOGGED_IN_USERS", "LOGGED_IN_USERS"] },
92
+ * })
93
+ *
94
+ * await email.send(notifyOwner, { subject: "New submission", body: html, replyTo: data.email })
95
+ */
96
+ function defineEmailAction(definition) {
97
+ const { id, permissions,...fields } = definition;
98
+ return {
99
+ id,
100
+ resource: {
101
+ type: "SOFTR_EMAIL",
102
+ ...fields
103
+ },
104
+ permissions
105
+ };
106
+ }
70
107
  function isDatasourceAction(value) {
71
108
  if (typeof value !== "object" || value === null) return false;
72
109
  const candidate = value;
@@ -86,4 +123,4 @@ function defineAiAction(definition) {
86
123
  }
87
124
 
88
125
  //#endregion
89
- export { defineAiAction, defineIntegration, defineMutation, defineQuery, defineWorkflow, isDatasourceAction };
126
+ export { defineAiAction, defineEmailAction, defineIntegration, defineMutation, defineQuery, defineWorkflow, isDatasourceAction };
@@ -0,0 +1,47 @@
1
+ import { EmailAction } from "../action.js";
2
+
3
+ //#region src/core/email.d.ts
4
+ declare const EMAIL_ERROR_CODES: readonly ["NOT_FOUND", "INVALID_INPUT", "CREDITS_EXHAUSTED", "RATE_LIMITED", "DAILY_LIMIT_REACHED", "SENDER_UNAVAILABLE", "BLOCKED", "PROVIDER_REJECTED", "UNAVAILABLE"];
5
+ type EmailErrorCode = (typeof EMAIL_ERROR_CODES)[number];
6
+ interface EmailSendInit {
7
+ /** Ignored when the action declares its own. */
8
+ to?: ReadonlyArray<string>;
9
+ /** Ignored when the action declares its own `cc` or `to`. */
10
+ cc?: ReadonlyArray<string>;
11
+ /** Ignored when the action declares its own `bcc` or `to`. */
12
+ bcc?: ReadonlyArray<string>;
13
+ /** Ignored when the action declares its own. */
14
+ replyTo?: string;
15
+ subject: string;
16
+ /** Plain text or HTML. */
17
+ body: string;
18
+ }
19
+ interface EmailSent {
20
+ /** Null when the mail provider did not report one; the email was still sent. */
21
+ messageId: string | null;
22
+ }
23
+ /**
24
+ * Thrown when Softr did not send the email. `code` says why:
25
+ *
26
+ * - `NOT_FOUND`: no such action, or the caller is not in its audience.
27
+ * - `INVALID_INPUT`: the call's inputs were refused; the message says which.
28
+ * - `CREDITS_EXHAUSTED`: the workspace has no workflow credits left.
29
+ * - `RATE_LIMITED`: the caller or the app sent too many emails lately; try again later.
30
+ * - `DAILY_LIMIT_REACHED`: Softr's own address sent the app's emails for today.
31
+ * - `SENDER_UNAVAILABLE`: the chosen sender is missing or not confirmed, or the action leaves `to` open and would send from Softr's address.
32
+ * - `BLOCKED`: Softr paused the app's emails for a day because one looked like phishing.
33
+ * - `PROVIDER_REJECTED`: the mail provider refused the email.
34
+ * - `UNAVAILABLE`: Softr could not send it right now, or could not be reached.
35
+ */
36
+ declare class EmailError extends Error {
37
+ readonly status: number;
38
+ readonly code: EmailErrorCode;
39
+ constructor(status: number, code: EmailErrorCode, message: string);
40
+ }
41
+ /** Sends one email through the action. Never retries by itself. */
42
+ declare function sendEmail(action: EmailAction, init: EmailSendInit): Promise<EmailSent>;
43
+ declare const email: {
44
+ send: typeof sendEmail;
45
+ };
46
+ //#endregion
47
+ export { EmailError, EmailErrorCode, EmailSendInit, EmailSent, email };
@@ -0,0 +1,84 @@
1
+ import { softrApiUrl } from "../softr-api.js";
2
+ import { fetch } from "../fetch.js";
3
+ import { sessionConfig } from "../auth/config.js";
4
+ import { readSessionToken } from "../auth/session.js";
5
+
6
+ //#region src/core/email.ts
7
+ const EMAIL_ERROR_CODES = [
8
+ "NOT_FOUND",
9
+ "INVALID_INPUT",
10
+ "CREDITS_EXHAUSTED",
11
+ "RATE_LIMITED",
12
+ "DAILY_LIMIT_REACHED",
13
+ "SENDER_UNAVAILABLE",
14
+ "BLOCKED",
15
+ "PROVIDER_REJECTED",
16
+ "UNAVAILABLE"
17
+ ];
18
+ /** For an answer whose `code` is not an email code, such as Softr's generic error bodies. */
19
+ const CODE_OF_STATUS = {
20
+ 400: "INVALID_INPUT",
21
+ 404: "NOT_FOUND",
22
+ 429: "RATE_LIMITED"
23
+ };
24
+ /**
25
+ * Thrown when Softr did not send the email. `code` says why:
26
+ *
27
+ * - `NOT_FOUND`: no such action, or the caller is not in its audience.
28
+ * - `INVALID_INPUT`: the call's inputs were refused; the message says which.
29
+ * - `CREDITS_EXHAUSTED`: the workspace has no workflow credits left.
30
+ * - `RATE_LIMITED`: the caller or the app sent too many emails lately; try again later.
31
+ * - `DAILY_LIMIT_REACHED`: Softr's own address sent the app's emails for today.
32
+ * - `SENDER_UNAVAILABLE`: the chosen sender is missing or not confirmed, or the action leaves `to` open and would send from Softr's address.
33
+ * - `BLOCKED`: Softr paused the app's emails for a day because one looked like phishing.
34
+ * - `PROVIDER_REJECTED`: the mail provider refused the email.
35
+ * - `UNAVAILABLE`: Softr could not send it right now, or could not be reached.
36
+ */
37
+ var EmailError = class extends Error {
38
+ status;
39
+ code;
40
+ constructor(status, code, message) {
41
+ super(message);
42
+ this.name = "EmailError";
43
+ this.status = status;
44
+ this.code = code;
45
+ }
46
+ };
47
+ /** Sends one email through the action. Never retries by itself. */
48
+ async function sendEmail(action, init) {
49
+ const { to, cc, bcc, replyTo, subject, body } = init;
50
+ const sessionToken = readSessionToken();
51
+ let res;
52
+ try {
53
+ res = await fetch(`${softrApiUrl("SOFTR_PLATFORM_API_URL")}/v1/vibe/applications/${sessionConfig().applicationId}/actions/${action.id}/email`, {
54
+ method: "POST",
55
+ headers: {
56
+ ...sessionToken ? { Authorization: `Bearer ${sessionToken}` } : {},
57
+ "Content-Type": "application/json"
58
+ },
59
+ body: JSON.stringify({
60
+ to,
61
+ cc,
62
+ bcc,
63
+ replyTo,
64
+ subject,
65
+ body
66
+ })
67
+ });
68
+ } catch (error) {
69
+ throw new EmailError(502, "UNAVAILABLE", `Email "${action.id}" could not reach Softr: ${error instanceof Error ? error.message : String(error)}`);
70
+ }
71
+ if (res.ok) {
72
+ const sent = await res.json().catch(() => null);
73
+ return { messageId: typeof sent === "object" && sent !== null && "messageId" in sent && typeof sent.messageId === "string" ? sent.messageId : null };
74
+ }
75
+ const failure = await res.json().catch(() => null);
76
+ const known = typeof failure === "object" && failure !== null ? failure : {};
77
+ const sentCode = "code" in known ? EMAIL_ERROR_CODES.find((errorCode) => errorCode === known.code) : void 0;
78
+ const message = "message" in known && typeof known.message === "string" && known.message !== "" ? known.message : `Email "${action.id}" failed with HTTP ${res.status}`;
79
+ throw new EmailError(res.status, sentCode ?? CODE_OF_STATUS[res.status] ?? "UNAVAILABLE", message);
80
+ }
81
+ const email = { send: sendEmail };
82
+
83
+ //#endregion
84
+ export { EmailError, email };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { SoftrUserGroupId, SoftrUserGroups, SoftrUserProperties, User } from "./auth/user.js";
2
- import { ActionPermissions, SoftrDatasources, defineAiAction, defineIntegration, defineMutation, defineQuery, defineWorkflow } from "./action.js";
2
+ import { ActionPermissions, SoftrDatasources, defineAiAction, defineEmailAction, defineIntegration, defineMutation, defineQuery, defineWorkflow } from "./action.js";
3
3
  import { FileAttachment } from "./core/file-upload.js";
4
4
  import { FileItem, useFileUpload } from "./core/use-file-upload.js";
5
5
  import { AiAnswer, AiFile, AiGenerateInit, AiMessage, AiUsage } from "./core/ai.js";
6
+ import { EmailErrorCode, EmailSendInit, EmailSent } from "./core/email.js";
6
7
  import { DateOptions, DateParts, DateSeparator, DateValue, FixedDateFormat, FormattedDate, Formatting, FormattingScope, WeekDay, formatDate, formatDateTime, formatNumber, useFormatting } from "./formatting.js";
7
8
  import { SoftrContext } from "./auth/context.js";
8
9
  import { AuthSettings } from "./auth/platform.js";
@@ -21,4 +22,4 @@ import { PwaInstall, PwaPlatform, SoftrPwaHead, usePwaInstall } from "./pwa.js";
21
22
  import { PushNotifications, PushPrompt, usePushNotifications } from "./push.js";
22
23
  import { DefaultErrorOverlay } from "./default-error-overlay.js";
23
24
  import { Audience } from "./route/audience.js";
24
- export { type ActionPermissions, type AiAnswer, type AiFile, type AiGenerateInit, type AiMessage, type AiUsage, Audience, type AuthOptions, type AuthSettings, AuthSettingsProvider, type DateOptions, type DateParts, type DateSeparator, type DateValue, DefaultErrorOverlay, type FieldShape, type FileAttachment, type FileItem, type FixedDateFormat, FormattedDate, type Formatting, FormattingScope, type Page, type PageSettings, type PushNotifications, type PushPrompt, type PwaInstall, type PwaPlatform, type SoftrContext, type SoftrDatasources, type SoftrFieldRegistry, SoftrPwaHead, type SoftrUserGroupId, type SoftrUserGroups, type SoftrUserProperties, type SsoError, type User, type WeekDay, assertRouteAccess, checkAccess, defineAiAction, defineIntegration, defineMutation, definePage, defineQuery, defineVisibility, defineWorkflow, fieldShape, formatDate, formatDateTime, formatDuration, formatField, formatNumber, formatValue, getAuthSettings, getSoftrContext, guardRoute, initialSoftrContext, isAccessError, isAlreadyAuthenticatedError, isAuthorized, isForbiddenError, isUnauthenticatedError, pageHead, registerSoftrFields, softrAuthMiddleware, softrMcpMiddleware, ssoSignInHref, toReturnPath, useAuthSettings, useCurrentUser, useFileUpload, useFormatting, useIdleTimeout, useOverrides, usePushNotifications, usePwaInstall, useUserTimezone };
25
+ export { type ActionPermissions, type AiAnswer, type AiFile, type AiGenerateInit, type AiMessage, type AiUsage, Audience, type AuthOptions, type AuthSettings, AuthSettingsProvider, type DateOptions, type DateParts, type DateSeparator, type DateValue, DefaultErrorOverlay, type EmailErrorCode, type EmailSendInit, type EmailSent, type FieldShape, type FileAttachment, type FileItem, type FixedDateFormat, FormattedDate, type Formatting, FormattingScope, type Page, type PageSettings, type PushNotifications, type PushPrompt, type PwaInstall, type PwaPlatform, type SoftrContext, type SoftrDatasources, type SoftrFieldRegistry, SoftrPwaHead, type SoftrUserGroupId, type SoftrUserGroups, type SoftrUserProperties, type SsoError, type User, type WeekDay, assertRouteAccess, checkAccess, defineAiAction, defineEmailAction, defineIntegration, defineMutation, definePage, defineQuery, defineVisibility, defineWorkflow, fieldShape, formatDate, formatDateTime, formatDuration, formatField, formatNumber, formatValue, getAuthSettings, getSoftrContext, guardRoute, initialSoftrContext, isAccessError, isAlreadyAuthenticatedError, isAuthorized, isForbiddenError, isUnauthenticatedError, pageHead, registerSoftrFields, softrAuthMiddleware, softrMcpMiddleware, ssoSignInHref, toReturnPath, useAuthSettings, useCurrentUser, useFileUpload, useFormatting, useIdleTimeout, useOverrides, usePushNotifications, usePwaInstall, useUserTimezone };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { defineAiAction, defineIntegration, defineMutation, defineQuery, defineWorkflow } from "./action.js";
1
+ import { defineAiAction, defineEmailAction, defineIntegration, defineMutation, defineQuery, defineWorkflow } from "./action.js";
2
2
  import { useFileUpload } from "./core/use-file-upload.js";
3
3
  import { checkAccess, defineVisibility, isAuthorized } from "./route/visibility.js";
4
4
  import { assertRouteAccess, guardRoute, isAccessError, isAlreadyAuthenticatedError, isForbiddenError, isUnauthenticatedError } from "./route/route.js";
@@ -17,4 +17,4 @@ import { useUserTimezone } from "./timezone.js";
17
17
  import { DefaultErrorOverlay } from "./default-error-overlay.js";
18
18
  import { Audience } from "./route/audience.js";
19
19
 
20
- export { Audience, AuthSettingsProvider, DefaultErrorOverlay, FormattedDate, FormattingScope, SoftrPwaHead, assertRouteAccess, checkAccess, defineAiAction, defineIntegration, defineMutation, definePage, defineQuery, defineVisibility, defineWorkflow, fieldShape, formatDate, formatDateTime, formatDuration, formatField, formatNumber, formatValue, getAuthSettings, getSoftrContext, guardRoute, initialSoftrContext, isAccessError, isAlreadyAuthenticatedError, isAuthorized, isForbiddenError, isUnauthenticatedError, pageHead, registerSoftrFields, softrAuthMiddleware, softrMcpMiddleware, ssoSignInHref, toReturnPath, useAuthSettings, useCurrentUser, useFileUpload, useFormatting, useIdleTimeout, useOverrides, usePushNotifications, usePwaInstall, useUserTimezone };
20
+ export { Audience, AuthSettingsProvider, DefaultErrorOverlay, FormattedDate, FormattingScope, SoftrPwaHead, assertRouteAccess, checkAccess, defineAiAction, defineEmailAction, defineIntegration, defineMutation, definePage, defineQuery, defineVisibility, defineWorkflow, fieldShape, formatDate, formatDateTime, formatDuration, formatField, formatNumber, formatValue, getAuthSettings, getSoftrContext, guardRoute, initialSoftrContext, isAccessError, isAlreadyAuthenticatedError, isAuthorized, isForbiddenError, isUnauthenticatedError, pageHead, registerSoftrFields, softrAuthMiddleware, softrMcpMiddleware, ssoSignInHref, toReturnPath, useAuthSettings, useCurrentUser, useFileUpload, useFormatting, useIdleTimeout, useOverrides, usePushNotifications, usePwaInstall, useUserTimezone };
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "1.5.0";
2
+ var version = "1.6.0";
3
3
 
4
4
  //#endregion
5
5
  export { version };
package/dist/server.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import { upload } from "./core/file-upload.js";
2
2
  import { AiError, ai } from "./core/ai.js";
3
+ import { EmailError, email } from "./core/email.js";
3
4
  import { auth } from "./auth/server.js";
4
5
  import { FieldChoice, RecordOption, RecordOptions } from "./core/options.js";
5
6
  import { ds } from "./datasource/datasource.js";
6
7
  import { workflow } from "./core/workflow.js";
7
8
  import { integration } from "./core/integration.js";
8
9
  import "@tanstack/react-start/server-only";
9
- export { AiError, type FieldChoice, type RecordOption, type RecordOptions, ai, auth, ds, integration, upload, workflow };
10
+ export { AiError, EmailError, type FieldChoice, type RecordOption, type RecordOptions, ai, auth, ds, email, integration, upload, workflow };
package/dist/server.js CHANGED
@@ -4,6 +4,7 @@ import { auth } from "./auth/server.js";
4
4
  import { workflow } from "./core/workflow.js";
5
5
  import { integration } from "./core/integration.js";
6
6
  import { AiError, ai } from "./core/ai.js";
7
+ import { EmailError, email } from "./core/email.js";
7
8
  import "@tanstack/react-start/server-only";
8
9
 
9
- export { AiError, ai, auth, ds, integration, upload, workflow };
10
+ export { AiError, EmailError, ai, auth, ds, email, integration, upload, workflow };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softr/sdk",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
@@ -10,7 +10,7 @@ description: >-
10
10
  metadata:
11
11
  type: core
12
12
  library: softr-sdk
13
- library_version: 1.5.0
13
+ library_version: 1.6.0
14
14
  ---
15
15
 
16
16
  # Softr SDK core
@@ -13,7 +13,7 @@ description: >-
13
13
  metadata:
14
14
  type: sub-skill
15
15
  library: softr-sdk
16
- library_version: 1.5.0
16
+ library_version: 1.6.0
17
17
  ---
18
18
 
19
19
  **Boundary.** `ai` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineAiAction` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -10,7 +10,7 @@ description: >-
10
10
  metadata:
11
11
  type: sub-skill
12
12
  library: softr-sdk
13
- library_version: 1.5.0
13
+ library_version: 1.6.0
14
14
  ---
15
15
 
16
16
  **Boundary.** `auth` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build.
@@ -10,7 +10,7 @@ description: >-
10
10
  metadata:
11
11
  type: sub-skill
12
12
  library: softr-sdk
13
- library_version: 1.5.0
13
+ library_version: 1.6.0
14
14
  ---
15
15
 
16
16
  **Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler or a server-side route hook — importing it into a component fails the build. `defineQuery` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -11,7 +11,7 @@ description: >-
11
11
  metadata:
12
12
  type: sub-skill
13
13
  library: softr-sdk
14
- library_version: 1.5.0
14
+ library_version: 1.6.0
15
15
  ---
16
16
 
17
17
  # The current user
@@ -0,0 +1,148 @@
1
+ ---
2
+ name: email
3
+ description: >-
4
+ Send an email from the app itself, with nothing to connect and no workflow:
5
+ defineEmailAction from @softr/sdk declares who may send it and the fields it
6
+ fixes (to, cc, bcc, replyTo, and an optional senderId); email.send from
7
+ @softr/sdk/server sends one with a subject and a text or HTML body, and throws
8
+ an EmailError with a code when Softr does not send it. Load this for a contact
9
+ form that emails the owner, a confirmation to the signed-in user, staff
10
+ emailing a client, or any email the app sends while handling what a person
11
+ does in it.
12
+ metadata:
13
+ type: sub-skill
14
+ library: softr-sdk
15
+ library_version: 1.6.0
16
+ ---
17
+
18
+ **Boundary.** `email` and `EmailError` live on `@softr/sdk/server` and run only inside a `createServerFn` handler — importing them into a component fails the build. `defineEmailAction` and every type come from `@softr/sdk` and can be imported anywhere.
19
+
20
+ # Email
21
+
22
+ An app sends an email through an email action. Softr sends it and bills the workspace's **workflow credits**, so there is no mail service to connect and no workflow to build. Use it for every email the app sends while it handles something a person does in it: a form submitted, a button pressed, a record saved through the app.
23
+
24
+ A workflow is still the answer for an email on a schedule ("every Monday") or on a change made outside the app (a record edited in the table): load `automate-with-workflows` for those. A connected Gmail or Outlook is the answer only when the user wants the email to come from their own mailbox, through the `integrations` sub-skill.
25
+
26
+ `defineEmailAction` missing from `@softr/sdk`? The app was built on an older version. Upgrade `@softr/sdk` to the latest version first, then write the action.
27
+
28
+ ## Who can send it, and to whom
29
+
30
+ The action's `permissions` is its audience: everyone in it can send an email through it, directly, without the app's own code. The app's code is not a guard. Only what the declaration fixes holds whatever the caller sends.
31
+
32
+ - **Fix the recipients whenever the use case allows.** A contact form that emails the owner fixes `to` to the owner. "Email me this report" fixes `to` to `{LOGGED_IN_USER:EMAIL}`. Then nobody can send the app's email to anyone else.
33
+ - **When people pick the recipients, the audience is named groups only.** "Staff email a client" leaves `to` open and keeps the action to the staff group: `userGroupTypes: ["LOGGED_IN_USERS"]` with `customGroups`. An action that leaves `to` open for visitors or for every signed-in user would let anyone send any email to anyone from the app's address, so Softr refuses the app's actions until it fixes `to` or names groups. Never offer such people a choice of recipient, not even as one option of a question: offer a group to put them in, or keep the fixed recipient. Such an action also needs a sender of the workspace's own (see below).
34
+
35
+ ## The sender
36
+
37
+ An email comes from the first of these that is set:
38
+
39
+ 1. the action's `senderId`;
40
+ 2. the app's email sender, which also sends its sign-in emails (Users → Notifications in Studio);
41
+ 3. Softr's testing address, at most 30 emails a day per app. The next one fails with `DAILY_LIMIT_REACHED`. On a free or trial plan the app stops at 20 a day first, with `RATE_LIMITED`.
42
+
43
+ A chosen sender that is missing or not confirmed fails every send with `SENDER_UNAVAILABLE`: Softr never falls back. An action that leaves `to` open needs 1 or 2, and fails the same way from Softr's address.
44
+
45
+ **A page builder handed a brief** writes the action the brief describes, with no `senderId`: the sender is settled by whoever wrote the brief.
46
+
47
+ **Look before you write the action.** Call `application_get` for the app's sender and `workspace_list_email_senders` for the workspace's. Everything you say about the sender comes from those two answers.
48
+
49
+ **Ask, never pick.**
50
+
51
+ - The app has its own sender: the emails come from it. Say so.
52
+ - Otherwise, with confirmed senders in the workspace: name them and ask whether the emails should come from one, and if so for **the whole app** (sign-in emails too: `application_configure_email_sender` with the email only) or **only these emails** (the action's `senderId`, copied exactly; nothing else changes).
53
+ - With none: the emails come from Softr's testing address. Offer to send from the user's own address. Not every plan has custom senders: when adding one is refused, tell the user their plan does not include it.
54
+
55
+ **Adding a new sender.** `application_configure_email_sender` with an email and a name adds one, and also makes it the app's sender.
56
+
57
+ - For the whole app, call it once the user approves. Softr emails a confirmation link to that address; ask the user to click it, then check it with `workspace_list_email_senders`. Until then every email action fails with `SENDER_UNAVAILABLE`; only the app's sign-in emails keep the old sender. Give the user the DKIM and Return-Path records it returns: without them the emails are more likely to land in spam.
58
+ - For only these emails, the user adds and confirms it in Studio: Users → Notifications → Email sender → Manage email senders, leaving the app's sender as it is. Then set it as the action's `senderId`.
59
+
60
+ **In your closing message**, say where the emails come from: the sender's address, or "Softr's testing address, up to 30 emails a day" (20 on a free or trial plan). Never its raw address. For an action open to visitors, also say in one line that anyone can send it without the form, up to Softr's daily caps, and that each email costs the workspace's credits.
61
+
62
+ ## What it costs
63
+
64
+ Every email costs **5 workflow credits per recipient**, from the workspace's monthly workflow credits, which its workflows spend too. You do not know the workspace's plan, so never name one or count how many emails it covers. The plan and the closing message give the cost and where to watch it, for example: "Each submission emails you, at 5 workflow credits per email. Track them in Settings → Billing → Workflow usage, where this app has its own row."
65
+
66
+ Emails sent from the preview are real and charged, and the actions in the code reach the live app as soon as they are saved. Send at most one test email, and only when the user asks for one. Never send emails in a loop to try something out.
67
+
68
+ ## Declare the action
69
+
70
+ ```ts
71
+ const notifyOwner = defineEmailAction({
72
+ id: 'notifyOwner',
73
+ to: ['owner@acme.com'],
74
+ permissions: { userGroupTypes: ['NON_LOGGED_IN_USERS', 'LOGGED_IN_USERS'] },
75
+ })
76
+
77
+ const emailClient = defineEmailAction({
78
+ id: 'emailClient',
79
+ replyTo: '{LOGGED_IN_USER:EMAIL}',
80
+ permissions: { userGroupTypes: ['LOGGED_IN_USERS'], customGroups: ['<the staff group id>'] },
81
+ })
82
+ ```
83
+
84
+ - `id` is a name you choose, unique across the app.
85
+ - `to`, `cc`, `bcc`: arrays of addresses. Each one declared here replaces the call's, and declaring `to` also ignores the call's `cc` and `bcc`. An element may be a whole placeholder for the signed-in sender: `{LOGGED_IN_USER:EMAIL}`, or `{LOGGED_IN_USER:<field>}` for an email field of their user record. Never part of a string, never in the call.
86
+ - `replyTo`: an address or one such placeholder.
87
+ - `senderId`: one of the workspace's senders, as above. The call can never set the sender.
88
+ - `permissions`: who may send it, as for queries and mutations.
89
+
90
+ Write the object inline in `defineEmailAction`, every value a literal. A declaration that cannot be read is not stored, and the check reports it.
91
+
92
+ Declare one action per kind of email: the owner's notification and the client's confirmation are two actions, each with its own recipients and audience.
93
+
94
+ ## Core pattern
95
+
96
+ ```ts
97
+ const submit = createServerFn({ method: 'POST' })
98
+ .validator(contactSchema)
99
+ .handler(async ({ data }) => {
100
+ const saved = await ds.create(saveSubmission, { data })
101
+ try {
102
+ await email.send(notifyOwner, {
103
+ subject: `New message from ${data.name}`,
104
+ body: renderSubmission(data), // the app's own HTML, with what the visitor typed escaped
105
+ replyTo: data.email,
106
+ })
107
+ } catch (error) {
108
+ if (error instanceof EmailError) return { saved: true, emailed: false, reason: error.message }
109
+ throw error
110
+ }
111
+ return { saved: true, emailed: true }
112
+ })
113
+ ```
114
+
115
+ `email.send(action, init)` takes:
116
+
117
+ - `subject` and `body`. Required. `body` is plain text or HTML. Escape what visitors typed before you put it into HTML.
118
+ - `to`, `cc`, `bcc`, `replyTo`: each used only where the action does not fix it, and `cc` and `bcc` never when it fixes `to`. Each entry is one address. At most 50 recipients per email.
119
+
120
+ It answers `{ messageId }` once the email is sent. The answer never lists the recipients. An email carries no attachments: link to the file instead.
121
+
122
+ Every call is a new email. Disable the button while the request runs, so a double click does not send twice.
123
+
124
+ ## Failure modes
125
+
126
+ **Not handling `EmailError`.** `email.send` throws an `EmailError` from `@softr/sdk/server`, with `status`, `code` and `message` when the email was not sent, and never retries by itself. Catch it, keep what the request already saved, and show the person a line they can act on: "Saved, but the email could not be sent." The codes:
127
+
128
+ | `code` | Meaning |
129
+ | --- | --- |
130
+ | `NOT_FOUND` | No such action, or the caller is not in its audience |
131
+ | `INVALID_INPUT` | No subject or body, no recipient in `to`, an entry or placeholder that is not exactly one address, or more than 50 recipients |
132
+ | `CREDITS_EXHAUSTED` | The workspace has no workflow credits left |
133
+ | `RATE_LIMITED` | This person or the app sent too many emails lately; each has a daily cap, and a free or trial plan has a far lower one. Tell the person to try again later |
134
+ | `DAILY_LIMIT_REACHED` | Softr's own address sent the app's 30 emails for today. Tell the person the email could not be sent today; the owner fixes it by choosing their own sender |
135
+ | `BLOCKED` | Softr paused the app's emails for a day because one looked like phishing. Tell the person the email could not be sent; the owner contacts Softr support if it is a mistake |
136
+ | `SENDER_UNAVAILABLE` | The chosen sender is missing or not confirmed, or the action leaves `to` open and has no sender of the workspace's own. Tell the person the email could not be sent; the owner fixes the sender |
137
+ | `PROVIDER_REJECTED` | The mail provider refused the email |
138
+ | `UNAVAILABLE` | Softr could not send it right now or could not be reached |
139
+
140
+ **Letting a mistyped address reach Softr.** An address the person typed (the reply-to of a contact form, a client's email) that is not one address is refused with `INVALID_INPUT`, which reads as a vague failure. Check its format in the validator and tell them which field is wrong.
141
+
142
+ **Calling from client code.** `email` is server-only. Wrap the send in a `createServerFn` and call that from the form or the button.
143
+
144
+ **Taking recipients from the request when they could be fixed.** A `to` the browser sends is a `to` any caller can change. Fix it in the declaration, or read it on the server from the record the email is about.
145
+
146
+ **Placeholders in the call.** `{LOGGED_IN_USER:EMAIL}` is filled only in the declaration. In the call it is sent as written and fails.
147
+
148
+ **Building a workflow for an email the app sends itself.** A "Run custom workflow" trigger plus a "Send email" step does the same at more cost to the user: a workflow to keep published. Use the email action; keep workflows for schedules and table events.
@@ -7,7 +7,7 @@ description: >-
7
7
  metadata:
8
8
  type: sub-skill
9
9
  library: softr-sdk
10
- library_version: 1.5.0
10
+ library_version: 1.6.0
11
11
  ---
12
12
 
13
13
  **Boundary.** `upload` lives on `@softr/sdk/server` and runs inside server functions. `useFileUpload` and `FileItem` live on `@softr/sdk` and run in components. `FileAttachment` comes from `@softr/sdk` and can be imported anywhere.
@@ -8,7 +8,7 @@ description: >-
8
8
  metadata:
9
9
  type: sub-skill
10
10
  library: softr-sdk
11
- library_version: 1.5.0
11
+ library_version: 1.6.0
12
12
  ---
13
13
 
14
14
  # Dates, times and numbers
@@ -7,7 +7,7 @@ description: >-
7
7
  metadata:
8
8
  type: sub-skill
9
9
  library: softr-sdk
10
- library_version: 1.5.0
10
+ library_version: 1.6.0
11
11
  ---
12
12
 
13
13
  **Boundary.** `integration` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineIntegration` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -196,6 +196,7 @@ Match the `integrationType` from the attached integrations section to find the b
196
196
  | LINKUP | `https://api.linkup.so` |
197
197
  | LOOPS | `https://app.loops.so` |
198
198
  | MESSAGE_BIRD | `https://rest.messagebird.com` |
199
+ | MICROSOFT_PLANNER | `https://graph.microsoft.com` |
199
200
  | MISTRAL_AI | `https://api.mistral.ai` |
200
201
  | OPEN_AI | `https://api.openai.com` |
201
202
  | OUTLOOK | `https://graph.microsoft.com` |
@@ -208,9 +209,12 @@ Match the `integrationType` from the attached integrations section to find the b
208
209
  | SLACK | `https://slack.com/api` |
209
210
  | SMARTLEAD | `https://server.smartlead.ai` |
210
211
  | STRIPE | `https://api.stripe.com` |
212
+ | TALLY | `https://api.tally.so` |
211
213
  | TELEGRAM | `https://api.telegram.org` |
212
214
  | TINYURL | `https://api.tinyurl.com` |
215
+ | TRELLO | `https://api.trello.com` |
213
216
  | TWILIO | `https://api.twilio.com` |
217
+ | TYPEFORM | `https://api.typeform.com` |
214
218
  | XERO | `https://api.xero.com` |
215
219
  | ZOOM | `https://api.zoom.us` |
216
220
 
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.5.0
12
+ library_version: 1.6.0
13
13
  ---
14
14
 
15
15
  **Boundary.** `softrMcpMiddleware` lives on `@softr/sdk` and is registered once, in `src/start.ts`. The actions you hand it are the same `defineQuery` / `defineMutation` values the app's own pages use — declared wherever they already live, not duplicated for MCP.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.5.0
12
+ library_version: 1.6.0
13
13
  ---
14
14
 
15
15
  # Push notifications
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.5.0
12
+ library_version: 1.6.0
13
13
  ---
14
14
 
15
15
  # Installing the app
@@ -10,7 +10,7 @@ description: >-
10
10
  metadata:
11
11
  type: sub-skill
12
12
  library: softr-sdk
13
- library_version: 1.5.0
13
+ library_version: 1.6.0
14
14
  ---
15
15
 
16
16
  **Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineMutation` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -11,7 +11,7 @@ description: >-
11
11
  metadata:
12
12
  type: sub-skill
13
13
  library: softr-sdk
14
- library_version: 1.5.0
14
+ library_version: 1.6.0
15
15
  ---
16
16
 
17
17
  **Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler or a server-side route hook — importing it into a component fails the build. The same holds for any helper that calls `ds`: declare it inside the handler. A function at module level that calls `ds` keeps the server-only import in the browser bundle, and every page stops loading until it moves. `defineQuery` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.5.0
12
+ library_version: 1.6.0
13
13
  ---
14
14
 
15
15
  **Boundary.** `Audience` and `defineVisibility` come from `@softr/sdk` and work anywhere.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.5.0
12
+ library_version: 1.6.0
13
13
  ---
14
14
 
15
15
  **Boundary.** `definePage`, `pageHead`, the access functions and the error predicates come from `@softr/sdk` and work anywhere.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.5.0
12
+ library_version: 1.6.0
13
13
  ---
14
14
 
15
15
  **Boundary.** `workflow` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineWorkflow` and every type come from `@softr/sdk` and can be imported anywhere.