@mitralab.io/sdk-core 0.2.14 → 0.2.15

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/dist/index.cjs CHANGED
@@ -120,6 +120,9 @@ function isObject(value) {
120
120
  function isNullableString(value) {
121
121
  return value === null || typeof value === "string";
122
122
  }
123
+ function isNonEmptyString(value) {
124
+ return typeof value === "string" && value.length > 0;
125
+ }
123
126
  function isNullableBoolean(value) {
124
127
  return value === null || typeof value === "boolean";
125
128
  }
@@ -753,6 +756,48 @@ function expectMessageAccepted(value, context, errors = defaultSdkCoreErrorFacto
753
756
  if (typeof response.messageId !== "string") invalidField(context, "messageId", errors);
754
757
  return response;
755
758
  }
759
+ function expectEmailTemplate(value, context, errors = defaultSdkCoreErrorFactory) {
760
+ const template = expectObject(value, context, errors);
761
+ if (typeof template.id !== "string") invalidField(context, "id", errors);
762
+ if (!isNonEmptyString(template.type)) invalidField(context, "type", errors);
763
+ if (!isNullableString(template.senderIdentityId)) {
764
+ invalidField(context, "senderIdentityId", errors);
765
+ }
766
+ if (typeof template.subject !== "string") invalidField(context, "subject", errors);
767
+ if (typeof template.htmlBody !== "string") invalidField(context, "htmlBody", errors);
768
+ if (!isNullableString(template.textBody)) invalidField(context, "textBody", errors);
769
+ if (typeof template.platformDefault !== "boolean") {
770
+ invalidField(context, "platformDefault", errors);
771
+ }
772
+ if (typeof template.createdAt !== "string") invalidField(context, "createdAt", errors);
773
+ if (typeof template.updatedAt !== "string") invalidField(context, "updatedAt", errors);
774
+ return template;
775
+ }
776
+ function expectEmailTemplateTypeCatalog(value, context, errors = defaultSdkCoreErrorFactory) {
777
+ const catalog = expectObject(value, context, errors);
778
+ if (!isNonEmptyString(catalog.type)) invalidField(context, "type", errors);
779
+ expectObjectArray(catalog.variables, `${context} variables`, errors).forEach(
780
+ (variable, position) => {
781
+ const variableContext = `${context} variable ${position}`;
782
+ if (typeof variable.name !== "string") invalidField(variableContext, "name", errors);
783
+ if (typeof variable.required !== "boolean") {
784
+ invalidField(variableContext, "required", errors);
785
+ }
786
+ if (!isNullableString(variable.description)) {
787
+ invalidField(variableContext, "description", errors);
788
+ }
789
+ if (!isNullableString(variable.preview)) invalidField(variableContext, "preview", errors);
790
+ }
791
+ );
792
+ return catalog;
793
+ }
794
+ function expectEmailTemplatePreview(value, context, errors = defaultSdkCoreErrorFactory) {
795
+ const preview = expectObject(value, context, errors);
796
+ if (typeof preview.subject !== "string") invalidField(context, "subject", errors);
797
+ if (typeof preview.htmlBody !== "string") invalidField(context, "htmlBody", errors);
798
+ if (!isNullableString(preview.textBody)) invalidField(context, "textBody", errors);
799
+ return preview;
800
+ }
756
801
  function expectAgentDefinition(value, context, errors = defaultSdkCoreErrorFactory) {
757
802
  const agent = expectObject(value, context, errors);
758
803
  if (typeof agent.id !== "string") invalidField(context, "id", errors);
@@ -2924,7 +2969,21 @@ function createMembersModule(transport, errors = defaultSdkCoreErrorFactory) {
2924
2969
  }
2925
2970
 
2926
2971
  // src/modules/messenger.ts
2927
- function createMessengerModule(transport, errors = defaultSdkCoreErrorFactory) {
2972
+ function createMessengerModule(transport, errors = defaultSdkCoreErrorFactory, getAppId) {
2973
+ const templatePath = (type) => `/api/v1/email/templates/${encodePathSegment(type, "email template type", errors)}`;
2974
+ const currentAppId = () => {
2975
+ const appId = getAppId?.();
2976
+ if (!appId) configurationError("An appId is required for email templates", errors);
2977
+ return appId;
2978
+ };
2979
+ const preview = async (type, appId) => expectEmailTemplatePreview(
2980
+ await transport.request(`${templatePath(type)}/preview`, {
2981
+ method: "GET",
2982
+ params: { appId }
2983
+ }),
2984
+ "Email template preview response",
2985
+ errors
2986
+ );
2928
2987
  return {
2929
2988
  async notify(content) {
2930
2989
  return expectMessageAccepted(
@@ -2945,6 +3004,66 @@ function createMessengerModule(transport, errors = defaultSdkCoreErrorFactory) {
2945
3004
  "Send email response",
2946
3005
  errors
2947
3006
  );
3007
+ },
3008
+ async listEmailTemplates() {
3009
+ return expectObjectArray(
3010
+ await transport.request("/api/v1/email/templates", {
3011
+ method: "GET",
3012
+ params: { appId: currentAppId() }
3013
+ }),
3014
+ "Email template list response",
3015
+ errors,
3016
+ expectEmailTemplate
3017
+ );
3018
+ },
3019
+ async getEmailTemplateType(type) {
3020
+ return expectEmailTemplateTypeCatalog(
3021
+ await transport.request(
3022
+ `/api/v1/email/template-types/${encodePathSegment(type, "email template type", errors)}`,
3023
+ { method: "GET" }
3024
+ ),
3025
+ "Email template type response",
3026
+ errors
3027
+ );
3028
+ },
3029
+ async getEmailTemplate(type) {
3030
+ return expectEmailTemplate(
3031
+ await transport.request(templatePath(type), {
3032
+ method: "GET",
3033
+ params: { appId: currentAppId() }
3034
+ }),
3035
+ "Email template response",
3036
+ errors
3037
+ );
3038
+ },
3039
+ async upsertEmailTemplate(type, input) {
3040
+ const appId = currentAppId();
3041
+ const template = expectEmailTemplate(
3042
+ await transport.request(templatePath(type), {
3043
+ method: "PUT",
3044
+ body: templateBody(appId, input)
3045
+ }),
3046
+ "Upsert email template response",
3047
+ errors
3048
+ );
3049
+ try {
3050
+ return { template, preview: await preview(type, appId) };
3051
+ } catch (previewError) {
3052
+ return { template, preview: null, previewError };
3053
+ }
3054
+ },
3055
+ async previewEmailTemplate(type) {
3056
+ return preview(type, currentAppId());
3057
+ },
3058
+ async deleteEmailTemplate(type) {
3059
+ expectEmpty(
3060
+ await transport.request(templatePath(type), {
3061
+ method: "DELETE",
3062
+ params: { appId: currentAppId() }
3063
+ }),
3064
+ "Delete email template response",
3065
+ errors
3066
+ );
2948
3067
  }
2949
3068
  };
2950
3069
  }
@@ -2960,6 +3079,14 @@ function rawEmailPayload(input) {
2960
3079
  ...input.text === void 0 ? {} : { text: input.text }
2961
3080
  };
2962
3081
  }
3082
+ function templateBody(appId, input) {
3083
+ return {
3084
+ appId,
3085
+ subject: input.subject,
3086
+ htmlBody: input.htmlBody,
3087
+ ...input.textBody === void 0 ? {} : { textBody: input.textBody }
3088
+ };
3089
+ }
2963
3090
 
2964
3091
  // src/modules/publicFunctions.ts
2965
3092
  function createPublicFunctionsModule(transport, errors = defaultSdkCoreErrorFactory) {
@@ -3277,7 +3404,7 @@ function createSdkCore(options) {
3277
3404
  integrationResources: createIntegrationResourcesModule(options.transports.integration, errors),
3278
3405
  integrationTemplates: createIntegrationTemplatesModule(options.transports.integration, errors),
3279
3406
  members,
3280
- messenger: createMessengerModule(messengerTransport, errors),
3407
+ messenger: createMessengerModule(messengerTransport, errors, options.getAppId),
3281
3408
  publicFunctions: createPublicFunctionsModule(options.transports.publicFunctions, errors),
3282
3409
  queries: createQueriesModule(options.transports.dataManager, errors),
3283
3410
  sql: createSqlModule(options.transports.dataManager, errors),
package/dist/index.d.cts CHANGED
@@ -1303,6 +1303,61 @@ interface SendEmailInput {
1303
1303
  /** Plain-text alternative for clients that do not render HTML. */
1304
1304
  text?: string;
1305
1305
  }
1306
+ /**
1307
+ * The account emails an app may rewrite with its own token. Messenger sends them from the app's
1308
+ * sender settings or the brand, so a template never picks its sender.
1309
+ */
1310
+ type EmailTemplateType = "SIGN_IN" | "SSO_GUIDANCE" | "APP_USER_INVITED" | "APP_ACCESS_REQUIRED";
1311
+ interface EmailTemplate {
1312
+ id: string;
1313
+ /**
1314
+ * An `EmailTemplateType` with an app token. Kept as a string because a console token also
1315
+ * lists the platform's other types, and a type Messenger opens later must not break the list.
1316
+ */
1317
+ type: string;
1318
+ /** Always null for these types: their sender comes from the app settings or the brand. */
1319
+ senderIdentityId: string | null;
1320
+ subject: string;
1321
+ htmlBody: string;
1322
+ textBody: string | null;
1323
+ /** True on a platform row. The list returns it next to the app's own row when the app rewrote the type. */
1324
+ platformDefault: boolean;
1325
+ createdAt: string;
1326
+ updatedAt: string;
1327
+ }
1328
+ interface EmailTemplateVariable {
1329
+ /** Referenced in a template as `$name`. */
1330
+ name: string;
1331
+ /** A required variable must appear in the subject or the HTML body. */
1332
+ required: boolean;
1333
+ description: string | null;
1334
+ /** Sample value used to render the preview. */
1335
+ preview: string | null;
1336
+ }
1337
+ interface EmailTemplateTypeCatalog {
1338
+ type: string;
1339
+ variables: EmailTemplateVariable[];
1340
+ }
1341
+ /** Replaces the app's version of the template as a whole. */
1342
+ interface EmailTemplateInput {
1343
+ subject: string;
1344
+ htmlBody: string;
1345
+ /** Left out, the plain-text version saved before is cleared. */
1346
+ textBody?: string;
1347
+ }
1348
+ /** The template rendered with the preview values of its variables. */
1349
+ interface EmailTemplatePreview {
1350
+ subject: string;
1351
+ htmlBody: string;
1352
+ textBody: string | null;
1353
+ }
1354
+ interface EmailTemplateUpsertResult {
1355
+ template: EmailTemplate;
1356
+ /** Null when only the preview failed; the template is saved all the same. */
1357
+ preview: EmailTemplatePreview | null;
1358
+ /** The transport or response error of the preview, unchanged, when `preview` is null. */
1359
+ previewError?: unknown;
1360
+ }
1306
1361
  interface AppContext {
1307
1362
  appId: string;
1308
1363
  app: AppDefinition;
@@ -1795,8 +1850,29 @@ interface MessengerModule {
1795
1850
  notify(content: string): Promise<MessageAccepted>;
1796
1851
  /** Sends an email from the app's sender; only the app's backend token may send. */
1797
1852
  sendEmail(input: SendEmailInput): Promise<MessageAccepted>;
1853
+ /**
1854
+ * Lists the current app's email templates: the platform row (`platformDefault: true`) of every
1855
+ * type and, beside it, the app's row for each type the app has rewritten.
1856
+ */
1857
+ listEmailTemplates(): Promise<EmailTemplate[]>;
1858
+ /** Gets the variables a type accepts, referenced as `$name` in the subject and HTML body. */
1859
+ getEmailTemplateType(type: EmailTemplateType): Promise<EmailTemplateTypeCatalog>;
1860
+ /** Gets the current app's version of a template, or the platform text when it has none. */
1861
+ getEmailTemplate(type: EmailTemplateType): Promise<EmailTemplate>;
1862
+ /**
1863
+ * Replaces the current app's version of a template and renders its preview. Every required
1864
+ * variable must appear in the subject or the HTML body.
1865
+ */
1866
+ upsertEmailTemplate(type: EmailTemplateType, input: EmailTemplateInput): Promise<EmailTemplateUpsertResult>;
1867
+ /**
1868
+ * Renders the app's saved template, or the platform one, with the catalog's sample values. It
1869
+ * does not prove which HTML goes out: the sender and the brand policy decide that at send time.
1870
+ */
1871
+ previewEmailTemplate(type: EmailTemplateType): Promise<EmailTemplatePreview>;
1872
+ /** Deletes the current app's version of a template, so the platform text applies again. */
1873
+ deleteEmailTemplate(type: EmailTemplateType): Promise<void>;
1798
1874
  }
1799
- declare function createMessengerModule(transport: Transport, errors?: SdkCoreErrorFactory): MessengerModule;
1875
+ declare function createMessengerModule(transport: Transport, errors?: SdkCoreErrorFactory, getAppId?: () => string | undefined): MessengerModule;
1800
1876
 
1801
1877
  interface PublicFunctionsModule {
1802
1878
  /**
@@ -1868,7 +1944,7 @@ interface SdkCoreTransports {
1868
1944
  codeStudio?: Transport;
1869
1945
  /** Copilot transport for tasks, credentials, models, and app connections. */
1870
1946
  copilot?: Transport;
1871
- /** Messenger transport for current-user notifications. */
1947
+ /** Messenger transport for current-user notifications, app emails, and their templates. */
1872
1948
  messenger?: Transport;
1873
1949
  /**
1874
1950
  * Anonymous Functions transport. It must not add Authorization or X-App-Id headers.
@@ -2188,4 +2264,4 @@ declare function expectPage<T extends object>(value: unknown, context: string, e
2188
2264
  declare function expectLegacyPage<T extends object>(value: unknown, context: string, errors?: SdkCoreErrorFactory, validateItem?: (value: unknown, context: string, errors: SdkCoreErrorFactory) => T): LegacyPage<T>;
2189
2265
  declare function expectEmpty(value: unknown, context: string, errors?: SdkCoreErrorFactory): void;
2190
2266
 
2191
- export { API_KEY_EXCHANGE_PATH, type AgentBulkDeleteResult, type AgentConnection, type AgentConnectionCreateInput, type AgentConnectionCustomProvider, type AgentConnectionCustomProviderInput, type AgentConnectionsModule, type AgentCredentialOptions, type AgentCredentialScope, type AgentCredentialsModule, type AgentDefinition, type AgentDirectChannelOptions, type AgentFetch, type AgentFetchResponse, type AgentInput, type AgentMessage, type AgentModel, type AgentProviderUsage, type AgentQueueItem, type AgentSendAndWaitOptions, type AgentSendOptions, type AgentSessionTransport, type AgentTask, type AgentTaskChannel, type AgentTaskCreateInput, type AgentTaskEvent, type AgentTaskEventConnection, type AgentTaskEventObserver, type AgentTaskEventSource, type AgentTaskInput, type AgentTaskListOptions, type AgentTaskRuntime, type AgentTaskSession, type AgentTaskSessionEventMap, type AgentTaskSessionManager, type AgentTaskSessionManagerOptions, type AgentTaskSessionOptions, type AgentTaskSessionStatus, AgentTaskTurnError, type AgentTasksModule, type AgentTasksWithSessions, type AgentTimelineItem, type AgentToolEvent, type AgentTurnResult, type AgentTurnUsage, type AgentTurnUsageRequest, type AgentUpdateItem, type AgentWebSocket, type AgentWebSocketConstructor, type AgentsModule, type ApiKeyExchangeCaller, type AppColor, type AppContext, type AppCreateInput, type AppDefinition, type AppDeploy, type AppDomain, type AppFiles, type AppGetOptions, type AppListOptions, type AppMember, type AppPublishOptions, type AppSummary, type AppUpdateInput, type AppVersion, type AppVersionStatus, type AppsModule, type AuthModule, type AuthenticationResult, type BatchExecution, type BatchStatementResult, type BulkUnsubscribeResult, type ColumnInput, type ConnectionConfig, type ConnectionConfigResponse, type ConnectionTestResult, type ContextModule, type ContextModuleDependencies, type CopilotProvider, type CredentialStatus, type CredentialUsage, type CredentialUsageWindow, type CustomQueriesModule, type CustomQueryDefinition, type CustomQueryInput, type CustomQuerySummary, type CustomQueryUpdateInput, type DataSourceBulkItemResult, type DataSourceBulkResult, type DataSourceCreateInput, type DataSourceDbType, type DataSourceDefinition, type DataSourceInstanceType, type DataSourceUpdateInput, type DataSourcesModule, type DdlStatement, type DeviceAuthorization, type DmlStatement, type EmptyFunctionInput, type EntitiesModule, type EntitiesProxy, type EntityListOptions, type EntityListResponse, type EntityTable, type ExistingAgentTaskSessionOptions, type FunctionBulkCreateInput, type FunctionBulkDeleteInput, type FunctionBulkDeleteResult, type FunctionBulkPatchInput, type FunctionBulkPatchItem, type FunctionBulkUpdateItem, type FunctionCreateInput, type FunctionDefinition, type FunctionExecution, type FunctionListOptions, type FunctionPatchInput, type FunctionRuntime, type FunctionSecrets, type FunctionSummary, type FunctionUpdateInput, type FunctionVersion, type FunctionVersionListOptions, type FunctionVisibility, type FunctionsAdminModule, type FunctionsModule, type FunctionsModuleOptions, type HttpMethod, type ImportColumnMapping, type ImportDefinition, type ImportExecution, type ImportExecutionListOptions, type ImportInput, type ImportProcessing, type ImportSchedule, type ImportSource, type ImportSourceResponse, type ImportTarget, type ImportsModule, type IntegrationAdminModule, type IntegrationConnectionStatus, type IntegrationCredentialRule, type IntegrationExecution, type IntegrationFieldSchema, type IntegrationFieldSchemaInput, type IntegrationLoginConfig, type IntegrationModule, type IntegrationProxyMode, type IntegrationRequestConfig, type IntegrationResource, type IntegrationResourceInput, type IntegrationResourceParam, type IntegrationResourceSummary, type IntegrationResourceUpdateInput, type IntegrationResourcesModule, type IntegrationTemplate, type IntegrationTemplateSummary, type IntegrationTemplateType, type IntegrationTemplatesModule, type IntegrationTokenExtraction, type InviteAppUserInput, type InvocationType, type JsonValue, type LegacyPage, type ListTablesOptions, type ListTemplateConfigsOptions, type MembersModule, type MessageAccepted, type MessengerModule, type NewAgentTaskSessionOptions, type OAuthExchangeInput, type OAuthStartResult, type Page, type PageOptions, type PlanPrice, type ProviderCredentialStatus, type ProxyInput, type ProxyResult, type PublicFunctionAsyncResult, type PublicFunctionResult, type PublicFunctionsModule, type QueriesModule, type QueryParamPrimitive, type QueryParamValue, type QueryResult, type SchemaModule, type SchemaScope, type SchemaTables, type SdkCore, SdkCoreConfigurationError, type SdkCoreErrorFactory, type SdkCoreOptions, SdkCoreResponseError, type SdkCoreTransports, type SendEmailInput, type SqlModule, type TableColumn, type TableDefinition, type TableForeignKey, type TemplateConfig, type TemplateConfigBulkItemResult, type TemplateConfigBulkResult, type TemplateConfigCreateInput, type TemplateConfigPage, type TemplateConfigSummary, type TemplateConfigUpdateInput, type Tenant, type TestCredentialsInput, type Transport, type TransportRequestOptions, type User, type UserPlan, type WorkflowDefinition, type WorkflowExecution, type WorkflowInput, type WorkflowSummary, type WorkflowsModule, appAccessTokenPath, createAgentConnectionsModule, createAgentCredentialsModule, createAgentTaskSessionManager, createAgentTasksModule, createAgentsModule, createAppsModule, createAuthModule, createContextModule, createCustomQueriesModule, createDataSourcesModule, createEntitiesModule, createFunctionsAdminModule, createFunctionsModule, createImportsModule, createIntegrationAdminModule, createIntegrationModule, createIntegrationResourcesModule, createIntegrationTemplatesModule, createMembersModule, createMessengerModule, createPublicFunctionsModule, createQueriesModule, createSchemaModule, createSdkCore, createSqlModule, createWorkflowsModule, defaultSdkCoreErrorFactory, encodePathSegment, expectEmpty, expectLegacyPage, expectNullableObject, expectObject, expectObjectArray, expectPage, expectStringArray, isWorkspaceSession, readTokenAppId, readTokenExpiry, resolveApiKeyToken, toAgentTimelineItem, tokenAuthorizesApp, withAgentTaskSessions };
2267
+ export { API_KEY_EXCHANGE_PATH, type AgentBulkDeleteResult, type AgentConnection, type AgentConnectionCreateInput, type AgentConnectionCustomProvider, type AgentConnectionCustomProviderInput, type AgentConnectionsModule, type AgentCredentialOptions, type AgentCredentialScope, type AgentCredentialsModule, type AgentDefinition, type AgentDirectChannelOptions, type AgentFetch, type AgentFetchResponse, type AgentInput, type AgentMessage, type AgentModel, type AgentProviderUsage, type AgentQueueItem, type AgentSendAndWaitOptions, type AgentSendOptions, type AgentSessionTransport, type AgentTask, type AgentTaskChannel, type AgentTaskCreateInput, type AgentTaskEvent, type AgentTaskEventConnection, type AgentTaskEventObserver, type AgentTaskEventSource, type AgentTaskInput, type AgentTaskListOptions, type AgentTaskRuntime, type AgentTaskSession, type AgentTaskSessionEventMap, type AgentTaskSessionManager, type AgentTaskSessionManagerOptions, type AgentTaskSessionOptions, type AgentTaskSessionStatus, AgentTaskTurnError, type AgentTasksModule, type AgentTasksWithSessions, type AgentTimelineItem, type AgentToolEvent, type AgentTurnResult, type AgentTurnUsage, type AgentTurnUsageRequest, type AgentUpdateItem, type AgentWebSocket, type AgentWebSocketConstructor, type AgentsModule, type ApiKeyExchangeCaller, type AppColor, type AppContext, type AppCreateInput, type AppDefinition, type AppDeploy, type AppDomain, type AppFiles, type AppGetOptions, type AppListOptions, type AppMember, type AppPublishOptions, type AppSummary, type AppUpdateInput, type AppVersion, type AppVersionStatus, type AppsModule, type AuthModule, type AuthenticationResult, type BatchExecution, type BatchStatementResult, type BulkUnsubscribeResult, type ColumnInput, type ConnectionConfig, type ConnectionConfigResponse, type ConnectionTestResult, type ContextModule, type ContextModuleDependencies, type CopilotProvider, type CredentialStatus, type CredentialUsage, type CredentialUsageWindow, type CustomQueriesModule, type CustomQueryDefinition, type CustomQueryInput, type CustomQuerySummary, type CustomQueryUpdateInput, type DataSourceBulkItemResult, type DataSourceBulkResult, type DataSourceCreateInput, type DataSourceDbType, type DataSourceDefinition, type DataSourceInstanceType, type DataSourceUpdateInput, type DataSourcesModule, type DdlStatement, type DeviceAuthorization, type DmlStatement, type EmailTemplate, type EmailTemplateInput, type EmailTemplatePreview, type EmailTemplateType, type EmailTemplateTypeCatalog, type EmailTemplateUpsertResult, type EmailTemplateVariable, type EmptyFunctionInput, type EntitiesModule, type EntitiesProxy, type EntityListOptions, type EntityListResponse, type EntityTable, type ExistingAgentTaskSessionOptions, type FunctionBulkCreateInput, type FunctionBulkDeleteInput, type FunctionBulkDeleteResult, type FunctionBulkPatchInput, type FunctionBulkPatchItem, type FunctionBulkUpdateItem, type FunctionCreateInput, type FunctionDefinition, type FunctionExecution, type FunctionListOptions, type FunctionPatchInput, type FunctionRuntime, type FunctionSecrets, type FunctionSummary, type FunctionUpdateInput, type FunctionVersion, type FunctionVersionListOptions, type FunctionVisibility, type FunctionsAdminModule, type FunctionsModule, type FunctionsModuleOptions, type HttpMethod, type ImportColumnMapping, type ImportDefinition, type ImportExecution, type ImportExecutionListOptions, type ImportInput, type ImportProcessing, type ImportSchedule, type ImportSource, type ImportSourceResponse, type ImportTarget, type ImportsModule, type IntegrationAdminModule, type IntegrationConnectionStatus, type IntegrationCredentialRule, type IntegrationExecution, type IntegrationFieldSchema, type IntegrationFieldSchemaInput, type IntegrationLoginConfig, type IntegrationModule, type IntegrationProxyMode, type IntegrationRequestConfig, type IntegrationResource, type IntegrationResourceInput, type IntegrationResourceParam, type IntegrationResourceSummary, type IntegrationResourceUpdateInput, type IntegrationResourcesModule, type IntegrationTemplate, type IntegrationTemplateSummary, type IntegrationTemplateType, type IntegrationTemplatesModule, type IntegrationTokenExtraction, type InviteAppUserInput, type InvocationType, type JsonValue, type LegacyPage, type ListTablesOptions, type ListTemplateConfigsOptions, type MembersModule, type MessageAccepted, type MessengerModule, type NewAgentTaskSessionOptions, type OAuthExchangeInput, type OAuthStartResult, type Page, type PageOptions, type PlanPrice, type ProviderCredentialStatus, type ProxyInput, type ProxyResult, type PublicFunctionAsyncResult, type PublicFunctionResult, type PublicFunctionsModule, type QueriesModule, type QueryParamPrimitive, type QueryParamValue, type QueryResult, type SchemaModule, type SchemaScope, type SchemaTables, type SdkCore, SdkCoreConfigurationError, type SdkCoreErrorFactory, type SdkCoreOptions, SdkCoreResponseError, type SdkCoreTransports, type SendEmailInput, type SqlModule, type TableColumn, type TableDefinition, type TableForeignKey, type TemplateConfig, type TemplateConfigBulkItemResult, type TemplateConfigBulkResult, type TemplateConfigCreateInput, type TemplateConfigPage, type TemplateConfigSummary, type TemplateConfigUpdateInput, type Tenant, type TestCredentialsInput, type Transport, type TransportRequestOptions, type User, type UserPlan, type WorkflowDefinition, type WorkflowExecution, type WorkflowInput, type WorkflowSummary, type WorkflowsModule, appAccessTokenPath, createAgentConnectionsModule, createAgentCredentialsModule, createAgentTaskSessionManager, createAgentTasksModule, createAgentsModule, createAppsModule, createAuthModule, createContextModule, createCustomQueriesModule, createDataSourcesModule, createEntitiesModule, createFunctionsAdminModule, createFunctionsModule, createImportsModule, createIntegrationAdminModule, createIntegrationModule, createIntegrationResourcesModule, createIntegrationTemplatesModule, createMembersModule, createMessengerModule, createPublicFunctionsModule, createQueriesModule, createSchemaModule, createSdkCore, createSqlModule, createWorkflowsModule, defaultSdkCoreErrorFactory, encodePathSegment, expectEmpty, expectLegacyPage, expectNullableObject, expectObject, expectObjectArray, expectPage, expectStringArray, isWorkspaceSession, readTokenAppId, readTokenExpiry, resolveApiKeyToken, toAgentTimelineItem, tokenAuthorizesApp, withAgentTaskSessions };
package/dist/index.d.ts CHANGED
@@ -1303,6 +1303,61 @@ interface SendEmailInput {
1303
1303
  /** Plain-text alternative for clients that do not render HTML. */
1304
1304
  text?: string;
1305
1305
  }
1306
+ /**
1307
+ * The account emails an app may rewrite with its own token. Messenger sends them from the app's
1308
+ * sender settings or the brand, so a template never picks its sender.
1309
+ */
1310
+ type EmailTemplateType = "SIGN_IN" | "SSO_GUIDANCE" | "APP_USER_INVITED" | "APP_ACCESS_REQUIRED";
1311
+ interface EmailTemplate {
1312
+ id: string;
1313
+ /**
1314
+ * An `EmailTemplateType` with an app token. Kept as a string because a console token also
1315
+ * lists the platform's other types, and a type Messenger opens later must not break the list.
1316
+ */
1317
+ type: string;
1318
+ /** Always null for these types: their sender comes from the app settings or the brand. */
1319
+ senderIdentityId: string | null;
1320
+ subject: string;
1321
+ htmlBody: string;
1322
+ textBody: string | null;
1323
+ /** True on a platform row. The list returns it next to the app's own row when the app rewrote the type. */
1324
+ platformDefault: boolean;
1325
+ createdAt: string;
1326
+ updatedAt: string;
1327
+ }
1328
+ interface EmailTemplateVariable {
1329
+ /** Referenced in a template as `$name`. */
1330
+ name: string;
1331
+ /** A required variable must appear in the subject or the HTML body. */
1332
+ required: boolean;
1333
+ description: string | null;
1334
+ /** Sample value used to render the preview. */
1335
+ preview: string | null;
1336
+ }
1337
+ interface EmailTemplateTypeCatalog {
1338
+ type: string;
1339
+ variables: EmailTemplateVariable[];
1340
+ }
1341
+ /** Replaces the app's version of the template as a whole. */
1342
+ interface EmailTemplateInput {
1343
+ subject: string;
1344
+ htmlBody: string;
1345
+ /** Left out, the plain-text version saved before is cleared. */
1346
+ textBody?: string;
1347
+ }
1348
+ /** The template rendered with the preview values of its variables. */
1349
+ interface EmailTemplatePreview {
1350
+ subject: string;
1351
+ htmlBody: string;
1352
+ textBody: string | null;
1353
+ }
1354
+ interface EmailTemplateUpsertResult {
1355
+ template: EmailTemplate;
1356
+ /** Null when only the preview failed; the template is saved all the same. */
1357
+ preview: EmailTemplatePreview | null;
1358
+ /** The transport or response error of the preview, unchanged, when `preview` is null. */
1359
+ previewError?: unknown;
1360
+ }
1306
1361
  interface AppContext {
1307
1362
  appId: string;
1308
1363
  app: AppDefinition;
@@ -1795,8 +1850,29 @@ interface MessengerModule {
1795
1850
  notify(content: string): Promise<MessageAccepted>;
1796
1851
  /** Sends an email from the app's sender; only the app's backend token may send. */
1797
1852
  sendEmail(input: SendEmailInput): Promise<MessageAccepted>;
1853
+ /**
1854
+ * Lists the current app's email templates: the platform row (`platformDefault: true`) of every
1855
+ * type and, beside it, the app's row for each type the app has rewritten.
1856
+ */
1857
+ listEmailTemplates(): Promise<EmailTemplate[]>;
1858
+ /** Gets the variables a type accepts, referenced as `$name` in the subject and HTML body. */
1859
+ getEmailTemplateType(type: EmailTemplateType): Promise<EmailTemplateTypeCatalog>;
1860
+ /** Gets the current app's version of a template, or the platform text when it has none. */
1861
+ getEmailTemplate(type: EmailTemplateType): Promise<EmailTemplate>;
1862
+ /**
1863
+ * Replaces the current app's version of a template and renders its preview. Every required
1864
+ * variable must appear in the subject or the HTML body.
1865
+ */
1866
+ upsertEmailTemplate(type: EmailTemplateType, input: EmailTemplateInput): Promise<EmailTemplateUpsertResult>;
1867
+ /**
1868
+ * Renders the app's saved template, or the platform one, with the catalog's sample values. It
1869
+ * does not prove which HTML goes out: the sender and the brand policy decide that at send time.
1870
+ */
1871
+ previewEmailTemplate(type: EmailTemplateType): Promise<EmailTemplatePreview>;
1872
+ /** Deletes the current app's version of a template, so the platform text applies again. */
1873
+ deleteEmailTemplate(type: EmailTemplateType): Promise<void>;
1798
1874
  }
1799
- declare function createMessengerModule(transport: Transport, errors?: SdkCoreErrorFactory): MessengerModule;
1875
+ declare function createMessengerModule(transport: Transport, errors?: SdkCoreErrorFactory, getAppId?: () => string | undefined): MessengerModule;
1800
1876
 
1801
1877
  interface PublicFunctionsModule {
1802
1878
  /**
@@ -1868,7 +1944,7 @@ interface SdkCoreTransports {
1868
1944
  codeStudio?: Transport;
1869
1945
  /** Copilot transport for tasks, credentials, models, and app connections. */
1870
1946
  copilot?: Transport;
1871
- /** Messenger transport for current-user notifications. */
1947
+ /** Messenger transport for current-user notifications, app emails, and their templates. */
1872
1948
  messenger?: Transport;
1873
1949
  /**
1874
1950
  * Anonymous Functions transport. It must not add Authorization or X-App-Id headers.
@@ -2188,4 +2264,4 @@ declare function expectPage<T extends object>(value: unknown, context: string, e
2188
2264
  declare function expectLegacyPage<T extends object>(value: unknown, context: string, errors?: SdkCoreErrorFactory, validateItem?: (value: unknown, context: string, errors: SdkCoreErrorFactory) => T): LegacyPage<T>;
2189
2265
  declare function expectEmpty(value: unknown, context: string, errors?: SdkCoreErrorFactory): void;
2190
2266
 
2191
- export { API_KEY_EXCHANGE_PATH, type AgentBulkDeleteResult, type AgentConnection, type AgentConnectionCreateInput, type AgentConnectionCustomProvider, type AgentConnectionCustomProviderInput, type AgentConnectionsModule, type AgentCredentialOptions, type AgentCredentialScope, type AgentCredentialsModule, type AgentDefinition, type AgentDirectChannelOptions, type AgentFetch, type AgentFetchResponse, type AgentInput, type AgentMessage, type AgentModel, type AgentProviderUsage, type AgentQueueItem, type AgentSendAndWaitOptions, type AgentSendOptions, type AgentSessionTransport, type AgentTask, type AgentTaskChannel, type AgentTaskCreateInput, type AgentTaskEvent, type AgentTaskEventConnection, type AgentTaskEventObserver, type AgentTaskEventSource, type AgentTaskInput, type AgentTaskListOptions, type AgentTaskRuntime, type AgentTaskSession, type AgentTaskSessionEventMap, type AgentTaskSessionManager, type AgentTaskSessionManagerOptions, type AgentTaskSessionOptions, type AgentTaskSessionStatus, AgentTaskTurnError, type AgentTasksModule, type AgentTasksWithSessions, type AgentTimelineItem, type AgentToolEvent, type AgentTurnResult, type AgentTurnUsage, type AgentTurnUsageRequest, type AgentUpdateItem, type AgentWebSocket, type AgentWebSocketConstructor, type AgentsModule, type ApiKeyExchangeCaller, type AppColor, type AppContext, type AppCreateInput, type AppDefinition, type AppDeploy, type AppDomain, type AppFiles, type AppGetOptions, type AppListOptions, type AppMember, type AppPublishOptions, type AppSummary, type AppUpdateInput, type AppVersion, type AppVersionStatus, type AppsModule, type AuthModule, type AuthenticationResult, type BatchExecution, type BatchStatementResult, type BulkUnsubscribeResult, type ColumnInput, type ConnectionConfig, type ConnectionConfigResponse, type ConnectionTestResult, type ContextModule, type ContextModuleDependencies, type CopilotProvider, type CredentialStatus, type CredentialUsage, type CredentialUsageWindow, type CustomQueriesModule, type CustomQueryDefinition, type CustomQueryInput, type CustomQuerySummary, type CustomQueryUpdateInput, type DataSourceBulkItemResult, type DataSourceBulkResult, type DataSourceCreateInput, type DataSourceDbType, type DataSourceDefinition, type DataSourceInstanceType, type DataSourceUpdateInput, type DataSourcesModule, type DdlStatement, type DeviceAuthorization, type DmlStatement, type EmptyFunctionInput, type EntitiesModule, type EntitiesProxy, type EntityListOptions, type EntityListResponse, type EntityTable, type ExistingAgentTaskSessionOptions, type FunctionBulkCreateInput, type FunctionBulkDeleteInput, type FunctionBulkDeleteResult, type FunctionBulkPatchInput, type FunctionBulkPatchItem, type FunctionBulkUpdateItem, type FunctionCreateInput, type FunctionDefinition, type FunctionExecution, type FunctionListOptions, type FunctionPatchInput, type FunctionRuntime, type FunctionSecrets, type FunctionSummary, type FunctionUpdateInput, type FunctionVersion, type FunctionVersionListOptions, type FunctionVisibility, type FunctionsAdminModule, type FunctionsModule, type FunctionsModuleOptions, type HttpMethod, type ImportColumnMapping, type ImportDefinition, type ImportExecution, type ImportExecutionListOptions, type ImportInput, type ImportProcessing, type ImportSchedule, type ImportSource, type ImportSourceResponse, type ImportTarget, type ImportsModule, type IntegrationAdminModule, type IntegrationConnectionStatus, type IntegrationCredentialRule, type IntegrationExecution, type IntegrationFieldSchema, type IntegrationFieldSchemaInput, type IntegrationLoginConfig, type IntegrationModule, type IntegrationProxyMode, type IntegrationRequestConfig, type IntegrationResource, type IntegrationResourceInput, type IntegrationResourceParam, type IntegrationResourceSummary, type IntegrationResourceUpdateInput, type IntegrationResourcesModule, type IntegrationTemplate, type IntegrationTemplateSummary, type IntegrationTemplateType, type IntegrationTemplatesModule, type IntegrationTokenExtraction, type InviteAppUserInput, type InvocationType, type JsonValue, type LegacyPage, type ListTablesOptions, type ListTemplateConfigsOptions, type MembersModule, type MessageAccepted, type MessengerModule, type NewAgentTaskSessionOptions, type OAuthExchangeInput, type OAuthStartResult, type Page, type PageOptions, type PlanPrice, type ProviderCredentialStatus, type ProxyInput, type ProxyResult, type PublicFunctionAsyncResult, type PublicFunctionResult, type PublicFunctionsModule, type QueriesModule, type QueryParamPrimitive, type QueryParamValue, type QueryResult, type SchemaModule, type SchemaScope, type SchemaTables, type SdkCore, SdkCoreConfigurationError, type SdkCoreErrorFactory, type SdkCoreOptions, SdkCoreResponseError, type SdkCoreTransports, type SendEmailInput, type SqlModule, type TableColumn, type TableDefinition, type TableForeignKey, type TemplateConfig, type TemplateConfigBulkItemResult, type TemplateConfigBulkResult, type TemplateConfigCreateInput, type TemplateConfigPage, type TemplateConfigSummary, type TemplateConfigUpdateInput, type Tenant, type TestCredentialsInput, type Transport, type TransportRequestOptions, type User, type UserPlan, type WorkflowDefinition, type WorkflowExecution, type WorkflowInput, type WorkflowSummary, type WorkflowsModule, appAccessTokenPath, createAgentConnectionsModule, createAgentCredentialsModule, createAgentTaskSessionManager, createAgentTasksModule, createAgentsModule, createAppsModule, createAuthModule, createContextModule, createCustomQueriesModule, createDataSourcesModule, createEntitiesModule, createFunctionsAdminModule, createFunctionsModule, createImportsModule, createIntegrationAdminModule, createIntegrationModule, createIntegrationResourcesModule, createIntegrationTemplatesModule, createMembersModule, createMessengerModule, createPublicFunctionsModule, createQueriesModule, createSchemaModule, createSdkCore, createSqlModule, createWorkflowsModule, defaultSdkCoreErrorFactory, encodePathSegment, expectEmpty, expectLegacyPage, expectNullableObject, expectObject, expectObjectArray, expectPage, expectStringArray, isWorkspaceSession, readTokenAppId, readTokenExpiry, resolveApiKeyToken, toAgentTimelineItem, tokenAuthorizesApp, withAgentTaskSessions };
2267
+ export { API_KEY_EXCHANGE_PATH, type AgentBulkDeleteResult, type AgentConnection, type AgentConnectionCreateInput, type AgentConnectionCustomProvider, type AgentConnectionCustomProviderInput, type AgentConnectionsModule, type AgentCredentialOptions, type AgentCredentialScope, type AgentCredentialsModule, type AgentDefinition, type AgentDirectChannelOptions, type AgentFetch, type AgentFetchResponse, type AgentInput, type AgentMessage, type AgentModel, type AgentProviderUsage, type AgentQueueItem, type AgentSendAndWaitOptions, type AgentSendOptions, type AgentSessionTransport, type AgentTask, type AgentTaskChannel, type AgentTaskCreateInput, type AgentTaskEvent, type AgentTaskEventConnection, type AgentTaskEventObserver, type AgentTaskEventSource, type AgentTaskInput, type AgentTaskListOptions, type AgentTaskRuntime, type AgentTaskSession, type AgentTaskSessionEventMap, type AgentTaskSessionManager, type AgentTaskSessionManagerOptions, type AgentTaskSessionOptions, type AgentTaskSessionStatus, AgentTaskTurnError, type AgentTasksModule, type AgentTasksWithSessions, type AgentTimelineItem, type AgentToolEvent, type AgentTurnResult, type AgentTurnUsage, type AgentTurnUsageRequest, type AgentUpdateItem, type AgentWebSocket, type AgentWebSocketConstructor, type AgentsModule, type ApiKeyExchangeCaller, type AppColor, type AppContext, type AppCreateInput, type AppDefinition, type AppDeploy, type AppDomain, type AppFiles, type AppGetOptions, type AppListOptions, type AppMember, type AppPublishOptions, type AppSummary, type AppUpdateInput, type AppVersion, type AppVersionStatus, type AppsModule, type AuthModule, type AuthenticationResult, type BatchExecution, type BatchStatementResult, type BulkUnsubscribeResult, type ColumnInput, type ConnectionConfig, type ConnectionConfigResponse, type ConnectionTestResult, type ContextModule, type ContextModuleDependencies, type CopilotProvider, type CredentialStatus, type CredentialUsage, type CredentialUsageWindow, type CustomQueriesModule, type CustomQueryDefinition, type CustomQueryInput, type CustomQuerySummary, type CustomQueryUpdateInput, type DataSourceBulkItemResult, type DataSourceBulkResult, type DataSourceCreateInput, type DataSourceDbType, type DataSourceDefinition, type DataSourceInstanceType, type DataSourceUpdateInput, type DataSourcesModule, type DdlStatement, type DeviceAuthorization, type DmlStatement, type EmailTemplate, type EmailTemplateInput, type EmailTemplatePreview, type EmailTemplateType, type EmailTemplateTypeCatalog, type EmailTemplateUpsertResult, type EmailTemplateVariable, type EmptyFunctionInput, type EntitiesModule, type EntitiesProxy, type EntityListOptions, type EntityListResponse, type EntityTable, type ExistingAgentTaskSessionOptions, type FunctionBulkCreateInput, type FunctionBulkDeleteInput, type FunctionBulkDeleteResult, type FunctionBulkPatchInput, type FunctionBulkPatchItem, type FunctionBulkUpdateItem, type FunctionCreateInput, type FunctionDefinition, type FunctionExecution, type FunctionListOptions, type FunctionPatchInput, type FunctionRuntime, type FunctionSecrets, type FunctionSummary, type FunctionUpdateInput, type FunctionVersion, type FunctionVersionListOptions, type FunctionVisibility, type FunctionsAdminModule, type FunctionsModule, type FunctionsModuleOptions, type HttpMethod, type ImportColumnMapping, type ImportDefinition, type ImportExecution, type ImportExecutionListOptions, type ImportInput, type ImportProcessing, type ImportSchedule, type ImportSource, type ImportSourceResponse, type ImportTarget, type ImportsModule, type IntegrationAdminModule, type IntegrationConnectionStatus, type IntegrationCredentialRule, type IntegrationExecution, type IntegrationFieldSchema, type IntegrationFieldSchemaInput, type IntegrationLoginConfig, type IntegrationModule, type IntegrationProxyMode, type IntegrationRequestConfig, type IntegrationResource, type IntegrationResourceInput, type IntegrationResourceParam, type IntegrationResourceSummary, type IntegrationResourceUpdateInput, type IntegrationResourcesModule, type IntegrationTemplate, type IntegrationTemplateSummary, type IntegrationTemplateType, type IntegrationTemplatesModule, type IntegrationTokenExtraction, type InviteAppUserInput, type InvocationType, type JsonValue, type LegacyPage, type ListTablesOptions, type ListTemplateConfigsOptions, type MembersModule, type MessageAccepted, type MessengerModule, type NewAgentTaskSessionOptions, type OAuthExchangeInput, type OAuthStartResult, type Page, type PageOptions, type PlanPrice, type ProviderCredentialStatus, type ProxyInput, type ProxyResult, type PublicFunctionAsyncResult, type PublicFunctionResult, type PublicFunctionsModule, type QueriesModule, type QueryParamPrimitive, type QueryParamValue, type QueryResult, type SchemaModule, type SchemaScope, type SchemaTables, type SdkCore, SdkCoreConfigurationError, type SdkCoreErrorFactory, type SdkCoreOptions, SdkCoreResponseError, type SdkCoreTransports, type SendEmailInput, type SqlModule, type TableColumn, type TableDefinition, type TableForeignKey, type TemplateConfig, type TemplateConfigBulkItemResult, type TemplateConfigBulkResult, type TemplateConfigCreateInput, type TemplateConfigPage, type TemplateConfigSummary, type TemplateConfigUpdateInput, type Tenant, type TestCredentialsInput, type Transport, type TransportRequestOptions, type User, type UserPlan, type WorkflowDefinition, type WorkflowExecution, type WorkflowInput, type WorkflowSummary, type WorkflowsModule, appAccessTokenPath, createAgentConnectionsModule, createAgentCredentialsModule, createAgentTaskSessionManager, createAgentTasksModule, createAgentsModule, createAppsModule, createAuthModule, createContextModule, createCustomQueriesModule, createDataSourcesModule, createEntitiesModule, createFunctionsAdminModule, createFunctionsModule, createImportsModule, createIntegrationAdminModule, createIntegrationModule, createIntegrationResourcesModule, createIntegrationTemplatesModule, createMembersModule, createMessengerModule, createPublicFunctionsModule, createQueriesModule, createSchemaModule, createSdkCore, createSqlModule, createWorkflowsModule, defaultSdkCoreErrorFactory, encodePathSegment, expectEmpty, expectLegacyPage, expectNullableObject, expectObject, expectObjectArray, expectPage, expectStringArray, isWorkspaceSession, readTokenAppId, readTokenExpiry, resolveApiKeyToken, toAgentTimelineItem, tokenAuthorizesApp, withAgentTaskSessions };
package/dist/index.js CHANGED
@@ -48,6 +48,9 @@ function isObject(value) {
48
48
  function isNullableString(value) {
49
49
  return value === null || typeof value === "string";
50
50
  }
51
+ function isNonEmptyString(value) {
52
+ return typeof value === "string" && value.length > 0;
53
+ }
51
54
  function isNullableBoolean(value) {
52
55
  return value === null || typeof value === "boolean";
53
56
  }
@@ -681,6 +684,48 @@ function expectMessageAccepted(value, context, errors = defaultSdkCoreErrorFacto
681
684
  if (typeof response.messageId !== "string") invalidField(context, "messageId", errors);
682
685
  return response;
683
686
  }
687
+ function expectEmailTemplate(value, context, errors = defaultSdkCoreErrorFactory) {
688
+ const template = expectObject(value, context, errors);
689
+ if (typeof template.id !== "string") invalidField(context, "id", errors);
690
+ if (!isNonEmptyString(template.type)) invalidField(context, "type", errors);
691
+ if (!isNullableString(template.senderIdentityId)) {
692
+ invalidField(context, "senderIdentityId", errors);
693
+ }
694
+ if (typeof template.subject !== "string") invalidField(context, "subject", errors);
695
+ if (typeof template.htmlBody !== "string") invalidField(context, "htmlBody", errors);
696
+ if (!isNullableString(template.textBody)) invalidField(context, "textBody", errors);
697
+ if (typeof template.platformDefault !== "boolean") {
698
+ invalidField(context, "platformDefault", errors);
699
+ }
700
+ if (typeof template.createdAt !== "string") invalidField(context, "createdAt", errors);
701
+ if (typeof template.updatedAt !== "string") invalidField(context, "updatedAt", errors);
702
+ return template;
703
+ }
704
+ function expectEmailTemplateTypeCatalog(value, context, errors = defaultSdkCoreErrorFactory) {
705
+ const catalog = expectObject(value, context, errors);
706
+ if (!isNonEmptyString(catalog.type)) invalidField(context, "type", errors);
707
+ expectObjectArray(catalog.variables, `${context} variables`, errors).forEach(
708
+ (variable, position) => {
709
+ const variableContext = `${context} variable ${position}`;
710
+ if (typeof variable.name !== "string") invalidField(variableContext, "name", errors);
711
+ if (typeof variable.required !== "boolean") {
712
+ invalidField(variableContext, "required", errors);
713
+ }
714
+ if (!isNullableString(variable.description)) {
715
+ invalidField(variableContext, "description", errors);
716
+ }
717
+ if (!isNullableString(variable.preview)) invalidField(variableContext, "preview", errors);
718
+ }
719
+ );
720
+ return catalog;
721
+ }
722
+ function expectEmailTemplatePreview(value, context, errors = defaultSdkCoreErrorFactory) {
723
+ const preview = expectObject(value, context, errors);
724
+ if (typeof preview.subject !== "string") invalidField(context, "subject", errors);
725
+ if (typeof preview.htmlBody !== "string") invalidField(context, "htmlBody", errors);
726
+ if (!isNullableString(preview.textBody)) invalidField(context, "textBody", errors);
727
+ return preview;
728
+ }
684
729
  function expectAgentDefinition(value, context, errors = defaultSdkCoreErrorFactory) {
685
730
  const agent = expectObject(value, context, errors);
686
731
  if (typeof agent.id !== "string") invalidField(context, "id", errors);
@@ -2852,7 +2897,21 @@ function createMembersModule(transport, errors = defaultSdkCoreErrorFactory) {
2852
2897
  }
2853
2898
 
2854
2899
  // src/modules/messenger.ts
2855
- function createMessengerModule(transport, errors = defaultSdkCoreErrorFactory) {
2900
+ function createMessengerModule(transport, errors = defaultSdkCoreErrorFactory, getAppId) {
2901
+ const templatePath = (type) => `/api/v1/email/templates/${encodePathSegment(type, "email template type", errors)}`;
2902
+ const currentAppId = () => {
2903
+ const appId = getAppId?.();
2904
+ if (!appId) configurationError("An appId is required for email templates", errors);
2905
+ return appId;
2906
+ };
2907
+ const preview = async (type, appId) => expectEmailTemplatePreview(
2908
+ await transport.request(`${templatePath(type)}/preview`, {
2909
+ method: "GET",
2910
+ params: { appId }
2911
+ }),
2912
+ "Email template preview response",
2913
+ errors
2914
+ );
2856
2915
  return {
2857
2916
  async notify(content) {
2858
2917
  return expectMessageAccepted(
@@ -2873,6 +2932,66 @@ function createMessengerModule(transport, errors = defaultSdkCoreErrorFactory) {
2873
2932
  "Send email response",
2874
2933
  errors
2875
2934
  );
2935
+ },
2936
+ async listEmailTemplates() {
2937
+ return expectObjectArray(
2938
+ await transport.request("/api/v1/email/templates", {
2939
+ method: "GET",
2940
+ params: { appId: currentAppId() }
2941
+ }),
2942
+ "Email template list response",
2943
+ errors,
2944
+ expectEmailTemplate
2945
+ );
2946
+ },
2947
+ async getEmailTemplateType(type) {
2948
+ return expectEmailTemplateTypeCatalog(
2949
+ await transport.request(
2950
+ `/api/v1/email/template-types/${encodePathSegment(type, "email template type", errors)}`,
2951
+ { method: "GET" }
2952
+ ),
2953
+ "Email template type response",
2954
+ errors
2955
+ );
2956
+ },
2957
+ async getEmailTemplate(type) {
2958
+ return expectEmailTemplate(
2959
+ await transport.request(templatePath(type), {
2960
+ method: "GET",
2961
+ params: { appId: currentAppId() }
2962
+ }),
2963
+ "Email template response",
2964
+ errors
2965
+ );
2966
+ },
2967
+ async upsertEmailTemplate(type, input) {
2968
+ const appId = currentAppId();
2969
+ const template = expectEmailTemplate(
2970
+ await transport.request(templatePath(type), {
2971
+ method: "PUT",
2972
+ body: templateBody(appId, input)
2973
+ }),
2974
+ "Upsert email template response",
2975
+ errors
2976
+ );
2977
+ try {
2978
+ return { template, preview: await preview(type, appId) };
2979
+ } catch (previewError) {
2980
+ return { template, preview: null, previewError };
2981
+ }
2982
+ },
2983
+ async previewEmailTemplate(type) {
2984
+ return preview(type, currentAppId());
2985
+ },
2986
+ async deleteEmailTemplate(type) {
2987
+ expectEmpty(
2988
+ await transport.request(templatePath(type), {
2989
+ method: "DELETE",
2990
+ params: { appId: currentAppId() }
2991
+ }),
2992
+ "Delete email template response",
2993
+ errors
2994
+ );
2876
2995
  }
2877
2996
  };
2878
2997
  }
@@ -2888,6 +3007,14 @@ function rawEmailPayload(input) {
2888
3007
  ...input.text === void 0 ? {} : { text: input.text }
2889
3008
  };
2890
3009
  }
3010
+ function templateBody(appId, input) {
3011
+ return {
3012
+ appId,
3013
+ subject: input.subject,
3014
+ htmlBody: input.htmlBody,
3015
+ ...input.textBody === void 0 ? {} : { textBody: input.textBody }
3016
+ };
3017
+ }
2891
3018
 
2892
3019
  // src/modules/publicFunctions.ts
2893
3020
  function createPublicFunctionsModule(transport, errors = defaultSdkCoreErrorFactory) {
@@ -3205,7 +3332,7 @@ function createSdkCore(options) {
3205
3332
  integrationResources: createIntegrationResourcesModule(options.transports.integration, errors),
3206
3333
  integrationTemplates: createIntegrationTemplatesModule(options.transports.integration, errors),
3207
3334
  members,
3208
- messenger: createMessengerModule(messengerTransport, errors),
3335
+ messenger: createMessengerModule(messengerTransport, errors, options.getAppId),
3209
3336
  publicFunctions: createPublicFunctionsModule(options.transports.publicFunctions, errors),
3210
3337
  queries: createQueriesModule(options.transports.dataManager, errors),
3211
3338
  sql: createSqlModule(options.transports.dataManager, errors),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mitralab.io/sdk-core",
3
- "version": "0.2.14",
3
+ "version": "0.2.15",
4
4
  "description": "Environment-neutral contracts and modules shared by Mitra JavaScript SDKs",
5
5
  "type": "module",
6
6
  "sideEffects": false,