@palbase/backend 0.9.0 → 0.10.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.
@@ -106,16 +106,29 @@ interface TypedDB<S extends SchemaDef> {
106
106
  tables: {
107
107
  [K in keyof S["tables"]]: TypedTable<S["tables"][K]>;
108
108
  };
109
+ transaction<T>(fn: (tx: TypedTx<S>) => Promise<T>): Promise<T>;
110
+ }
111
+ /** Transaction-scoped typed facade: same typed tables, no nested transaction. */
112
+ interface TypedTx<S extends SchemaDef> {
113
+ tables: {
114
+ [K in keyof S["tables"]]: TypedTable<S["tables"][K]>;
115
+ };
109
116
  }
110
117
  /**
111
118
  * Wraps a raw `DBClient` with the type-safe `TypedDB<S>` facade derived from
112
119
  * the provided schema. No behavior change — all calls delegate to `raw` with
113
120
  * the table name as a plain string.
114
121
  *
115
- * The `satisfies` check verifies the built object is structurally compatible
116
- * before we present it as `TypedDB<S>`. The final `as TypedDB<S>` is a
117
- * single structural narrowing from the dynamically-built type to the precise
118
- * mapped type (TS cannot infer through `Object.keys` iteration).
122
+ * `buildTables` is the reusable factory that wraps any op-bearing client
123
+ * (`TxClient` the surface shared by `DBClient` and the transaction-scoped
124
+ * client) into the typed tables map. It is used both for the top-level db
125
+ * (wrapping `raw`) and inside `transaction`, where it wraps the raw `TxClient`
126
+ * the runtime yields so the callback sees the same typed `.tables` API.
127
+ *
128
+ * `transaction` delegates straight to `raw.transaction`; the two narrow
129
+ * `as TypedTx<S>` / `as TypedDB<S>` casts are single structural narrowings
130
+ * from the dynamically-built tables object to the precise mapped type (TS
131
+ * cannot infer through `Object.keys` iteration) — see module-level doc comment.
119
132
  */
120
133
  declare function makeTypedDB<S extends SchemaDef>(schema: S, raw: DBClient): TypedDB<S>;
121
134
 
@@ -331,7 +344,18 @@ interface PalbasePushSendResponse {
331
344
  interface PalbaseEmailSendParams {
332
345
  to: string | string[];
333
346
  subject?: string;
347
+ /**
348
+ * @deprecated The server reads `template_slug`, not `template` — this
349
+ * field is forwarded as-is and ignored by palnotify. Use `templateSlug`
350
+ * instead. Retained for source-compat with older callers.
351
+ */
334
352
  template?: string;
353
+ /**
354
+ * Server email-template slug. The notifications client maps this to the
355
+ * wire field `template_slug` (mutually exclusive with `subject` + body
356
+ * fields when not overriding template output).
357
+ */
358
+ templateSlug?: string;
335
359
  variables?: Record<string, unknown>;
336
360
  html?: string;
337
361
  text?: string;
@@ -350,7 +374,18 @@ interface PalbaseEmailSendResponse {
350
374
  /** SMS send params. */
351
375
  interface PalbaseSmsSendParams {
352
376
  to: string | string[];
353
- body: string;
377
+ /**
378
+ * SMS body text. Either `body` OR `templateSlug` must be supplied —
379
+ * the two are mutually exclusive at the server.
380
+ */
381
+ body?: string;
382
+ /**
383
+ * Server SMS-template slug. The notifications client maps this to the
384
+ * wire field `template_slug`. When provided, palnotify renders the
385
+ * template with `variables` and uses the result as the SMS body.
386
+ */
387
+ templateSlug?: string;
388
+ variables?: Record<string, unknown>;
354
389
  category?: string;
355
390
  }
356
391
  /** SMS send response. */
@@ -422,6 +457,56 @@ interface PalbaseRegisterDeviceParams {
422
457
  app_version?: string;
423
458
  locale?: string;
424
459
  }
460
+ /** Email template view (camelCase). */
461
+ interface PalbaseEmailTemplate {
462
+ id: string;
463
+ projectId: string;
464
+ slug: string;
465
+ subject: string;
466
+ htmlBody: string;
467
+ textBody?: string;
468
+ variables: string[];
469
+ isDefault: boolean;
470
+ createdAt: string;
471
+ updatedAt: string;
472
+ }
473
+ /** Payload for templates.email.create. */
474
+ interface PalbaseCreateEmailTemplateInput {
475
+ slug: string;
476
+ subject: string;
477
+ htmlBody: string;
478
+ textBody?: string;
479
+ variables?: string[];
480
+ }
481
+ /** Payload for templates.email.update — patch semantics. */
482
+ interface PalbaseUpdateEmailTemplateInput {
483
+ subject?: string;
484
+ htmlBody?: string;
485
+ textBody?: string;
486
+ variables?: string[];
487
+ }
488
+ /** SMS template view (camelCase). No subject / html / text distinction. */
489
+ interface PalbaseSMSTemplate {
490
+ id: string;
491
+ projectId: string;
492
+ slug: string;
493
+ body: string;
494
+ variables: string[];
495
+ isDefault: boolean;
496
+ createdAt: string;
497
+ updatedAt: string;
498
+ }
499
+ /** Payload for templates.sms.create. */
500
+ interface PalbaseCreateSMSTemplateInput {
501
+ slug: string;
502
+ body: string;
503
+ variables?: string[];
504
+ }
505
+ /** Payload for templates.sms.update — patch semantics. */
506
+ interface PalbaseUpdateSMSTemplateInput {
507
+ body?: string;
508
+ variables?: string[];
509
+ }
425
510
  /** Analytics event properties. */
426
511
  type PalbaseAnalyticsProperties = Record<string, unknown>;
427
512
  /** Analytics identify traits. */
@@ -952,6 +1037,47 @@ interface PalbasePreferencesClient {
952
1037
  /** Update notification preferences. */
953
1038
  update(params: PalbasePreferences): Promise<PalbaseResult<PalbasePreferences>>;
954
1039
  }
1040
+ /**
1041
+ * Email-template CRUD sub-client (service-role gated server-side).
1042
+ */
1043
+ interface PalbaseEmailTemplatesClient {
1044
+ /** List all email templates. */
1045
+ list(): Promise<PalbaseResult<PalbaseEmailTemplate[]>>;
1046
+ /** Get one email template by ID. */
1047
+ get(id: string): Promise<PalbaseResult<PalbaseEmailTemplate>>;
1048
+ /** Create an email template. */
1049
+ create(input: PalbaseCreateEmailTemplateInput): Promise<PalbaseResult<PalbaseEmailTemplate>>;
1050
+ /** Update an email template (patch semantics). */
1051
+ update(id: string, input: PalbaseUpdateEmailTemplateInput): Promise<PalbaseResult<PalbaseEmailTemplate>>;
1052
+ /** Delete an email template. */
1053
+ delete(id: string): Promise<PalbaseResult<void>>;
1054
+ }
1055
+ /**
1056
+ * SMS-template CRUD sub-client (service-role gated server-side).
1057
+ */
1058
+ interface PalbaseSMSTemplatesClient {
1059
+ /** List all SMS templates. */
1060
+ list(): Promise<PalbaseResult<PalbaseSMSTemplate[]>>;
1061
+ /** Get one SMS template by ID. */
1062
+ get(id: string): Promise<PalbaseResult<PalbaseSMSTemplate>>;
1063
+ /** Create an SMS template. */
1064
+ create(input: PalbaseCreateSMSTemplateInput): Promise<PalbaseResult<PalbaseSMSTemplate>>;
1065
+ /** Update an SMS template (patch semantics). */
1066
+ update(id: string, input: PalbaseUpdateSMSTemplateInput): Promise<PalbaseResult<PalbaseSMSTemplate>>;
1067
+ /** Delete an SMS template. */
1068
+ delete(id: string): Promise<PalbaseResult<void>>;
1069
+ }
1070
+ /**
1071
+ * Templates sub-client — parallel CRUD for email and SMS templates.
1072
+ * Service-role gated server-side; both surfaces map TS camelCase to
1073
+ * wire snake_case in the runtime client.
1074
+ */
1075
+ interface PalbaseTemplatesClient {
1076
+ /** Email template CRUD. */
1077
+ email: PalbaseEmailTemplatesClient;
1078
+ /** SMS template CRUD. */
1079
+ sms: PalbaseSMSTemplatesClient;
1080
+ }
955
1081
  /**
956
1082
  * Notifications client available on `ctx.notifications`.
957
1083
  * Service-role: all send operations require privileged access.
@@ -968,6 +1094,8 @@ interface PalbaseNotificationsClient {
968
1094
  inbox: PalbaseInboxClient;
969
1095
  /** Notification preferences manager. */
970
1096
  preferences: PalbasePreferencesClient;
1097
+ /** Email + SMS template CRUD (service-role). */
1098
+ templates: PalbaseTemplatesClient;
971
1099
  /** Register a device for push notifications. */
972
1100
  registerDevice(params: PalbaseRegisterDeviceParams): Promise<PalbaseResult<PalbaseDeviceTokenView>>;
973
1101
  /** Remove a device registration. */
@@ -1080,6 +1208,8 @@ interface RateLimitConfig {
1080
1208
  /** Window duration in seconds. */
1081
1209
  window: number;
1082
1210
  }
1211
+ /** The transaction-scoped client passed to `db.transaction(fn)` — same DB ops, no nested transaction. */
1212
+ type TxClient = Omit<DBClient, "transaction">;
1083
1213
  /** Database client interface injected into endpoint context. */
1084
1214
  interface DBClient {
1085
1215
  /** Run a read-only SQL query (executes in a READ ONLY transaction). */
@@ -1089,6 +1219,12 @@ interface DBClient {
1089
1219
  delete(table: string, id: string): Promise<void>;
1090
1220
  findById(table: string, id: string): Promise<Record<string, unknown> | null>;
1091
1221
  findMany(table: string, query?: Record<string, unknown>): Promise<Record<string, unknown>[]>;
1222
+ /**
1223
+ * Run an interactive transaction. The callback receives a `tx` with the same
1224
+ * DB ops as this client; returning normally commits, throwing rolls back.
1225
+ * Nested transactions are not supported.
1226
+ */
1227
+ transaction<T>(fn: (tx: TxClient) => Promise<T>): Promise<T>;
1092
1228
  }
1093
1229
  /** Logger interface injected into endpoint context. */
1094
1230
  interface Logger {
@@ -1296,4 +1432,4 @@ interface EndpointConfig<TInputSchema extends ZodSchema = ZodSchema, TOutputSche
1296
1432
  */
1297
1433
  declare function defineEndpoint<TInputSchema extends ZodSchema, TOutputSchema extends ZodSchema, TSchema extends SchemaDef | undefined = undefined, const TAuth extends AuthSpec | undefined = undefined>(config: EndpointConfig<TInputSchema, TOutputSchema, TSchema, TAuth>): EndpointConfig<TInputSchema, TOutputSchema, TSchema, TAuth>;
1298
1434
 
1299
- export { type PalbaseIdentifyTraits as $, type AuthConfig as A, type PalbaseDocumentRef as B, type CacheClient as C, type DBClient as D, type EndpointContext as E, type FileContext as F, type PalbaseDocumentSnapshot as G, type HttpMethod as H, type InsertShape as I, type PalbaseEmailClient as J, type PalbaseEmailSendParams as K, type Logger as L, type Middleware as M, type PalbaseEmailSendResponse as N, type PalbaseEventNamesResult as O, type PalbaseModuleClients as P, type QueueClient as Q, type PalbaseEventsQueryInput as R, type PalbaseEventsResult as S, type PalbaseFileObject as T, type PalbaseFlag as U, type PalbaseFlagContext as V, type PalbaseFlagVariant as W, type PalbaseFlagsClient as X, type PalbaseFunctionsClient as Y, type PalbaseFunnelQueryInput as Z, type PalbaseFunnelResult as _, type EndpointConfig as a, type PalbaseInboxClient as a0, type PalbaseInboxListOptions as a1, type PalbaseInboxListResult as a2, type PalbaseInboxMessage as a3, type PalbaseInboxSendParams as a4, type PalbaseInboxSendResponse as a5, type PalbaseInitialLink as a6, type PalbaseInvokeOptions as a7, type PalbaseLink as a8, type PalbaseLinkAnalytics as a9, type PalbaseSmsClient as aA, type PalbaseSmsSendParams as aB, type PalbaseSmsSendResponse as aC, type PalbaseStorageClient as aD, type PalbaseTransformOptions as aE, type PalbaseUpdateLinkParams as aF, type PalbaseUploadOptions as aG, type PalbaseUser as aH, type PalbaseUserDetailResult as aI, type PalbaseUsersQueryInput as aJ, type PalbaseUsersResult as aK, type PalbaseVerifyRequestSignatureParams as aL, type PalbaseWhereOperator as aM, type RateLimitConfig as aN, type RowShape as aO, type TypedDB as aP, type TypedTable as aQ, type User as aR, defineEndpoint as aS, defineMiddleware as aT, makeTypedDB as aU, type PalbaseLinkDetails as aa, type PalbaseLinksClient as ab, type PalbaseListLinksOptions as ac, type PalbaseListLinksResult as ad, type PalbaseListOptions as ae, type PalbaseMatchParams as af, type PalbaseMultiChannelResponse as ag, type PalbaseNotificationsClient as ah, type PalbaseOverviewResult as ai, type PalbasePreferences as aj, type PalbasePreferencesClient as ak, type PalbasePublicUrlResponse as al, type PalbasePushClient as am, type PalbasePushSendParams as an, type PalbasePushSendResponse as ao, type PalbaseQrCodeOptions as ap, type PalbaseQuerySnapshot as aq, type PalbaseRealtimeChannel as ar, type PalbaseRealtimeClient as as, type PalbaseRealtimeMessage as at, type PalbaseRegisterDeviceParams as au, type PalbaseResult as av, type PalbaseRetentionQueryInput as aw, type PalbaseRetentionResult as ax, type PalbaseSession as ay, type PalbaseSignedUrlResponse as az, type MiddlewareContext as b, type MiddlewareHandler as c, type PalbaseAnalyticsClient as d, type PalbaseAnalyticsManagementNamespace as e, type PalbaseAnalyticsProperties as f, type PalbaseAnalyticsQueryNamespace as g, type PalbaseAttestAndroidParams as h, type PalbaseAttestAndroidResult as i, type PalbaseAttestiOSParams as j, type PalbaseAttestiOSResult as k, type PalbaseAuthClient as l, type PalbaseBindDeviceParams as m, type PalbaseBucketClient as n, type PalbaseCmsClient as o, type PalbaseCmsFindOneOptions as p, type PalbaseCmsFindOptions as q, type PalbaseCohortQueryInput as r, type PalbaseCohortResult as s, type PalbaseCollectionRef as t, type PalbaseCountQueryInput as u, type PalbaseCountResult as v, type PalbaseCreateLinkParams as w, type PalbaseDeviceInfo as x, type PalbaseDeviceTokenView as y, type PalbaseDocsClient as z };
1435
+ export { type PalbaseIdentifyTraits as $, type AuthConfig as A, type PalbaseDocumentRef as B, type CacheClient as C, type DBClient as D, type EndpointContext as E, type FileContext as F, type PalbaseDocumentSnapshot as G, type HttpMethod as H, type InsertShape as I, type PalbaseEmailClient as J, type PalbaseEmailSendParams as K, type Logger as L, type Middleware as M, type PalbaseEmailSendResponse as N, type PalbaseEventNamesResult as O, type PalbaseModuleClients as P, type QueueClient as Q, type PalbaseEventsQueryInput as R, type PalbaseEventsResult as S, type PalbaseFileObject as T, type PalbaseFlag as U, type PalbaseFlagContext as V, type PalbaseFlagVariant as W, type PalbaseFlagsClient as X, type PalbaseFunctionsClient as Y, type PalbaseFunnelQueryInput as Z, type PalbaseFunnelResult as _, type EndpointConfig as a, type PalbaseInboxClient as a0, type PalbaseInboxListOptions as a1, type PalbaseInboxListResult as a2, type PalbaseInboxMessage as a3, type PalbaseInboxSendParams as a4, type PalbaseInboxSendResponse as a5, type PalbaseInitialLink as a6, type PalbaseInvokeOptions as a7, type PalbaseLink as a8, type PalbaseLinkAnalytics as a9, type PalbaseSmsClient as aA, type PalbaseSmsSendParams as aB, type PalbaseSmsSendResponse as aC, type PalbaseStorageClient as aD, type PalbaseTransformOptions as aE, type PalbaseUpdateLinkParams as aF, type PalbaseUploadOptions as aG, type PalbaseUser as aH, type PalbaseUserDetailResult as aI, type PalbaseUsersQueryInput as aJ, type PalbaseUsersResult as aK, type PalbaseVerifyRequestSignatureParams as aL, type PalbaseWhereOperator as aM, type RateLimitConfig as aN, type RowShape as aO, type TxClient as aP, type TypedDB as aQ, type TypedTable as aR, type TypedTx as aS, type User as aT, defineEndpoint as aU, defineMiddleware as aV, makeTypedDB as aW, type PalbaseLinkDetails as aa, type PalbaseLinksClient as ab, type PalbaseListLinksOptions as ac, type PalbaseListLinksResult as ad, type PalbaseListOptions as ae, type PalbaseMatchParams as af, type PalbaseMultiChannelResponse as ag, type PalbaseNotificationsClient as ah, type PalbaseOverviewResult as ai, type PalbasePreferences as aj, type PalbasePreferencesClient as ak, type PalbasePublicUrlResponse as al, type PalbasePushClient as am, type PalbasePushSendParams as an, type PalbasePushSendResponse as ao, type PalbaseQrCodeOptions as ap, type PalbaseQuerySnapshot as aq, type PalbaseRealtimeChannel as ar, type PalbaseRealtimeClient as as, type PalbaseRealtimeMessage as at, type PalbaseRegisterDeviceParams as au, type PalbaseResult as av, type PalbaseRetentionQueryInput as aw, type PalbaseRetentionResult as ax, type PalbaseSession as ay, type PalbaseSignedUrlResponse as az, type MiddlewareContext as b, type MiddlewareHandler as c, type PalbaseAnalyticsClient as d, type PalbaseAnalyticsManagementNamespace as e, type PalbaseAnalyticsProperties as f, type PalbaseAnalyticsQueryNamespace as g, type PalbaseAttestAndroidParams as h, type PalbaseAttestAndroidResult as i, type PalbaseAttestiOSParams as j, type PalbaseAttestiOSResult as k, type PalbaseAuthClient as l, type PalbaseBindDeviceParams as m, type PalbaseBucketClient as n, type PalbaseCmsClient as o, type PalbaseCmsFindOneOptions as p, type PalbaseCmsFindOptions as q, type PalbaseCohortQueryInput as r, type PalbaseCohortResult as s, type PalbaseCollectionRef as t, type PalbaseCountQueryInput as u, type PalbaseCountResult as v, type PalbaseCreateLinkParams as w, type PalbaseDeviceInfo as x, type PalbaseDeviceTokenView as y, type PalbaseDocsClient as z };
@@ -106,16 +106,29 @@ interface TypedDB<S extends SchemaDef> {
106
106
  tables: {
107
107
  [K in keyof S["tables"]]: TypedTable<S["tables"][K]>;
108
108
  };
109
+ transaction<T>(fn: (tx: TypedTx<S>) => Promise<T>): Promise<T>;
110
+ }
111
+ /** Transaction-scoped typed facade: same typed tables, no nested transaction. */
112
+ interface TypedTx<S extends SchemaDef> {
113
+ tables: {
114
+ [K in keyof S["tables"]]: TypedTable<S["tables"][K]>;
115
+ };
109
116
  }
110
117
  /**
111
118
  * Wraps a raw `DBClient` with the type-safe `TypedDB<S>` facade derived from
112
119
  * the provided schema. No behavior change — all calls delegate to `raw` with
113
120
  * the table name as a plain string.
114
121
  *
115
- * The `satisfies` check verifies the built object is structurally compatible
116
- * before we present it as `TypedDB<S>`. The final `as TypedDB<S>` is a
117
- * single structural narrowing from the dynamically-built type to the precise
118
- * mapped type (TS cannot infer through `Object.keys` iteration).
122
+ * `buildTables` is the reusable factory that wraps any op-bearing client
123
+ * (`TxClient` the surface shared by `DBClient` and the transaction-scoped
124
+ * client) into the typed tables map. It is used both for the top-level db
125
+ * (wrapping `raw`) and inside `transaction`, where it wraps the raw `TxClient`
126
+ * the runtime yields so the callback sees the same typed `.tables` API.
127
+ *
128
+ * `transaction` delegates straight to `raw.transaction`; the two narrow
129
+ * `as TypedTx<S>` / `as TypedDB<S>` casts are single structural narrowings
130
+ * from the dynamically-built tables object to the precise mapped type (TS
131
+ * cannot infer through `Object.keys` iteration) — see module-level doc comment.
119
132
  */
120
133
  declare function makeTypedDB<S extends SchemaDef>(schema: S, raw: DBClient): TypedDB<S>;
121
134
 
@@ -331,7 +344,18 @@ interface PalbasePushSendResponse {
331
344
  interface PalbaseEmailSendParams {
332
345
  to: string | string[];
333
346
  subject?: string;
347
+ /**
348
+ * @deprecated The server reads `template_slug`, not `template` — this
349
+ * field is forwarded as-is and ignored by palnotify. Use `templateSlug`
350
+ * instead. Retained for source-compat with older callers.
351
+ */
334
352
  template?: string;
353
+ /**
354
+ * Server email-template slug. The notifications client maps this to the
355
+ * wire field `template_slug` (mutually exclusive with `subject` + body
356
+ * fields when not overriding template output).
357
+ */
358
+ templateSlug?: string;
335
359
  variables?: Record<string, unknown>;
336
360
  html?: string;
337
361
  text?: string;
@@ -350,7 +374,18 @@ interface PalbaseEmailSendResponse {
350
374
  /** SMS send params. */
351
375
  interface PalbaseSmsSendParams {
352
376
  to: string | string[];
353
- body: string;
377
+ /**
378
+ * SMS body text. Either `body` OR `templateSlug` must be supplied —
379
+ * the two are mutually exclusive at the server.
380
+ */
381
+ body?: string;
382
+ /**
383
+ * Server SMS-template slug. The notifications client maps this to the
384
+ * wire field `template_slug`. When provided, palnotify renders the
385
+ * template with `variables` and uses the result as the SMS body.
386
+ */
387
+ templateSlug?: string;
388
+ variables?: Record<string, unknown>;
354
389
  category?: string;
355
390
  }
356
391
  /** SMS send response. */
@@ -422,6 +457,56 @@ interface PalbaseRegisterDeviceParams {
422
457
  app_version?: string;
423
458
  locale?: string;
424
459
  }
460
+ /** Email template view (camelCase). */
461
+ interface PalbaseEmailTemplate {
462
+ id: string;
463
+ projectId: string;
464
+ slug: string;
465
+ subject: string;
466
+ htmlBody: string;
467
+ textBody?: string;
468
+ variables: string[];
469
+ isDefault: boolean;
470
+ createdAt: string;
471
+ updatedAt: string;
472
+ }
473
+ /** Payload for templates.email.create. */
474
+ interface PalbaseCreateEmailTemplateInput {
475
+ slug: string;
476
+ subject: string;
477
+ htmlBody: string;
478
+ textBody?: string;
479
+ variables?: string[];
480
+ }
481
+ /** Payload for templates.email.update — patch semantics. */
482
+ interface PalbaseUpdateEmailTemplateInput {
483
+ subject?: string;
484
+ htmlBody?: string;
485
+ textBody?: string;
486
+ variables?: string[];
487
+ }
488
+ /** SMS template view (camelCase). No subject / html / text distinction. */
489
+ interface PalbaseSMSTemplate {
490
+ id: string;
491
+ projectId: string;
492
+ slug: string;
493
+ body: string;
494
+ variables: string[];
495
+ isDefault: boolean;
496
+ createdAt: string;
497
+ updatedAt: string;
498
+ }
499
+ /** Payload for templates.sms.create. */
500
+ interface PalbaseCreateSMSTemplateInput {
501
+ slug: string;
502
+ body: string;
503
+ variables?: string[];
504
+ }
505
+ /** Payload for templates.sms.update — patch semantics. */
506
+ interface PalbaseUpdateSMSTemplateInput {
507
+ body?: string;
508
+ variables?: string[];
509
+ }
425
510
  /** Analytics event properties. */
426
511
  type PalbaseAnalyticsProperties = Record<string, unknown>;
427
512
  /** Analytics identify traits. */
@@ -952,6 +1037,47 @@ interface PalbasePreferencesClient {
952
1037
  /** Update notification preferences. */
953
1038
  update(params: PalbasePreferences): Promise<PalbaseResult<PalbasePreferences>>;
954
1039
  }
1040
+ /**
1041
+ * Email-template CRUD sub-client (service-role gated server-side).
1042
+ */
1043
+ interface PalbaseEmailTemplatesClient {
1044
+ /** List all email templates. */
1045
+ list(): Promise<PalbaseResult<PalbaseEmailTemplate[]>>;
1046
+ /** Get one email template by ID. */
1047
+ get(id: string): Promise<PalbaseResult<PalbaseEmailTemplate>>;
1048
+ /** Create an email template. */
1049
+ create(input: PalbaseCreateEmailTemplateInput): Promise<PalbaseResult<PalbaseEmailTemplate>>;
1050
+ /** Update an email template (patch semantics). */
1051
+ update(id: string, input: PalbaseUpdateEmailTemplateInput): Promise<PalbaseResult<PalbaseEmailTemplate>>;
1052
+ /** Delete an email template. */
1053
+ delete(id: string): Promise<PalbaseResult<void>>;
1054
+ }
1055
+ /**
1056
+ * SMS-template CRUD sub-client (service-role gated server-side).
1057
+ */
1058
+ interface PalbaseSMSTemplatesClient {
1059
+ /** List all SMS templates. */
1060
+ list(): Promise<PalbaseResult<PalbaseSMSTemplate[]>>;
1061
+ /** Get one SMS template by ID. */
1062
+ get(id: string): Promise<PalbaseResult<PalbaseSMSTemplate>>;
1063
+ /** Create an SMS template. */
1064
+ create(input: PalbaseCreateSMSTemplateInput): Promise<PalbaseResult<PalbaseSMSTemplate>>;
1065
+ /** Update an SMS template (patch semantics). */
1066
+ update(id: string, input: PalbaseUpdateSMSTemplateInput): Promise<PalbaseResult<PalbaseSMSTemplate>>;
1067
+ /** Delete an SMS template. */
1068
+ delete(id: string): Promise<PalbaseResult<void>>;
1069
+ }
1070
+ /**
1071
+ * Templates sub-client — parallel CRUD for email and SMS templates.
1072
+ * Service-role gated server-side; both surfaces map TS camelCase to
1073
+ * wire snake_case in the runtime client.
1074
+ */
1075
+ interface PalbaseTemplatesClient {
1076
+ /** Email template CRUD. */
1077
+ email: PalbaseEmailTemplatesClient;
1078
+ /** SMS template CRUD. */
1079
+ sms: PalbaseSMSTemplatesClient;
1080
+ }
955
1081
  /**
956
1082
  * Notifications client available on `ctx.notifications`.
957
1083
  * Service-role: all send operations require privileged access.
@@ -968,6 +1094,8 @@ interface PalbaseNotificationsClient {
968
1094
  inbox: PalbaseInboxClient;
969
1095
  /** Notification preferences manager. */
970
1096
  preferences: PalbasePreferencesClient;
1097
+ /** Email + SMS template CRUD (service-role). */
1098
+ templates: PalbaseTemplatesClient;
971
1099
  /** Register a device for push notifications. */
972
1100
  registerDevice(params: PalbaseRegisterDeviceParams): Promise<PalbaseResult<PalbaseDeviceTokenView>>;
973
1101
  /** Remove a device registration. */
@@ -1080,6 +1208,8 @@ interface RateLimitConfig {
1080
1208
  /** Window duration in seconds. */
1081
1209
  window: number;
1082
1210
  }
1211
+ /** The transaction-scoped client passed to `db.transaction(fn)` — same DB ops, no nested transaction. */
1212
+ type TxClient = Omit<DBClient, "transaction">;
1083
1213
  /** Database client interface injected into endpoint context. */
1084
1214
  interface DBClient {
1085
1215
  /** Run a read-only SQL query (executes in a READ ONLY transaction). */
@@ -1089,6 +1219,12 @@ interface DBClient {
1089
1219
  delete(table: string, id: string): Promise<void>;
1090
1220
  findById(table: string, id: string): Promise<Record<string, unknown> | null>;
1091
1221
  findMany(table: string, query?: Record<string, unknown>): Promise<Record<string, unknown>[]>;
1222
+ /**
1223
+ * Run an interactive transaction. The callback receives a `tx` with the same
1224
+ * DB ops as this client; returning normally commits, throwing rolls back.
1225
+ * Nested transactions are not supported.
1226
+ */
1227
+ transaction<T>(fn: (tx: TxClient) => Promise<T>): Promise<T>;
1092
1228
  }
1093
1229
  /** Logger interface injected into endpoint context. */
1094
1230
  interface Logger {
@@ -1296,4 +1432,4 @@ interface EndpointConfig<TInputSchema extends ZodSchema = ZodSchema, TOutputSche
1296
1432
  */
1297
1433
  declare function defineEndpoint<TInputSchema extends ZodSchema, TOutputSchema extends ZodSchema, TSchema extends SchemaDef | undefined = undefined, const TAuth extends AuthSpec | undefined = undefined>(config: EndpointConfig<TInputSchema, TOutputSchema, TSchema, TAuth>): EndpointConfig<TInputSchema, TOutputSchema, TSchema, TAuth>;
1298
1434
 
1299
- export { type PalbaseIdentifyTraits as $, type AuthConfig as A, type PalbaseDocumentRef as B, type CacheClient as C, type DBClient as D, type EndpointContext as E, type FileContext as F, type PalbaseDocumentSnapshot as G, type HttpMethod as H, type InsertShape as I, type PalbaseEmailClient as J, type PalbaseEmailSendParams as K, type Logger as L, type Middleware as M, type PalbaseEmailSendResponse as N, type PalbaseEventNamesResult as O, type PalbaseModuleClients as P, type QueueClient as Q, type PalbaseEventsQueryInput as R, type PalbaseEventsResult as S, type PalbaseFileObject as T, type PalbaseFlag as U, type PalbaseFlagContext as V, type PalbaseFlagVariant as W, type PalbaseFlagsClient as X, type PalbaseFunctionsClient as Y, type PalbaseFunnelQueryInput as Z, type PalbaseFunnelResult as _, type EndpointConfig as a, type PalbaseInboxClient as a0, type PalbaseInboxListOptions as a1, type PalbaseInboxListResult as a2, type PalbaseInboxMessage as a3, type PalbaseInboxSendParams as a4, type PalbaseInboxSendResponse as a5, type PalbaseInitialLink as a6, type PalbaseInvokeOptions as a7, type PalbaseLink as a8, type PalbaseLinkAnalytics as a9, type PalbaseSmsClient as aA, type PalbaseSmsSendParams as aB, type PalbaseSmsSendResponse as aC, type PalbaseStorageClient as aD, type PalbaseTransformOptions as aE, type PalbaseUpdateLinkParams as aF, type PalbaseUploadOptions as aG, type PalbaseUser as aH, type PalbaseUserDetailResult as aI, type PalbaseUsersQueryInput as aJ, type PalbaseUsersResult as aK, type PalbaseVerifyRequestSignatureParams as aL, type PalbaseWhereOperator as aM, type RateLimitConfig as aN, type RowShape as aO, type TypedDB as aP, type TypedTable as aQ, type User as aR, defineEndpoint as aS, defineMiddleware as aT, makeTypedDB as aU, type PalbaseLinkDetails as aa, type PalbaseLinksClient as ab, type PalbaseListLinksOptions as ac, type PalbaseListLinksResult as ad, type PalbaseListOptions as ae, type PalbaseMatchParams as af, type PalbaseMultiChannelResponse as ag, type PalbaseNotificationsClient as ah, type PalbaseOverviewResult as ai, type PalbasePreferences as aj, type PalbasePreferencesClient as ak, type PalbasePublicUrlResponse as al, type PalbasePushClient as am, type PalbasePushSendParams as an, type PalbasePushSendResponse as ao, type PalbaseQrCodeOptions as ap, type PalbaseQuerySnapshot as aq, type PalbaseRealtimeChannel as ar, type PalbaseRealtimeClient as as, type PalbaseRealtimeMessage as at, type PalbaseRegisterDeviceParams as au, type PalbaseResult as av, type PalbaseRetentionQueryInput as aw, type PalbaseRetentionResult as ax, type PalbaseSession as ay, type PalbaseSignedUrlResponse as az, type MiddlewareContext as b, type MiddlewareHandler as c, type PalbaseAnalyticsClient as d, type PalbaseAnalyticsManagementNamespace as e, type PalbaseAnalyticsProperties as f, type PalbaseAnalyticsQueryNamespace as g, type PalbaseAttestAndroidParams as h, type PalbaseAttestAndroidResult as i, type PalbaseAttestiOSParams as j, type PalbaseAttestiOSResult as k, type PalbaseAuthClient as l, type PalbaseBindDeviceParams as m, type PalbaseBucketClient as n, type PalbaseCmsClient as o, type PalbaseCmsFindOneOptions as p, type PalbaseCmsFindOptions as q, type PalbaseCohortQueryInput as r, type PalbaseCohortResult as s, type PalbaseCollectionRef as t, type PalbaseCountQueryInput as u, type PalbaseCountResult as v, type PalbaseCreateLinkParams as w, type PalbaseDeviceInfo as x, type PalbaseDeviceTokenView as y, type PalbaseDocsClient as z };
1435
+ export { type PalbaseIdentifyTraits as $, type AuthConfig as A, type PalbaseDocumentRef as B, type CacheClient as C, type DBClient as D, type EndpointContext as E, type FileContext as F, type PalbaseDocumentSnapshot as G, type HttpMethod as H, type InsertShape as I, type PalbaseEmailClient as J, type PalbaseEmailSendParams as K, type Logger as L, type Middleware as M, type PalbaseEmailSendResponse as N, type PalbaseEventNamesResult as O, type PalbaseModuleClients as P, type QueueClient as Q, type PalbaseEventsQueryInput as R, type PalbaseEventsResult as S, type PalbaseFileObject as T, type PalbaseFlag as U, type PalbaseFlagContext as V, type PalbaseFlagVariant as W, type PalbaseFlagsClient as X, type PalbaseFunctionsClient as Y, type PalbaseFunnelQueryInput as Z, type PalbaseFunnelResult as _, type EndpointConfig as a, type PalbaseInboxClient as a0, type PalbaseInboxListOptions as a1, type PalbaseInboxListResult as a2, type PalbaseInboxMessage as a3, type PalbaseInboxSendParams as a4, type PalbaseInboxSendResponse as a5, type PalbaseInitialLink as a6, type PalbaseInvokeOptions as a7, type PalbaseLink as a8, type PalbaseLinkAnalytics as a9, type PalbaseSmsClient as aA, type PalbaseSmsSendParams as aB, type PalbaseSmsSendResponse as aC, type PalbaseStorageClient as aD, type PalbaseTransformOptions as aE, type PalbaseUpdateLinkParams as aF, type PalbaseUploadOptions as aG, type PalbaseUser as aH, type PalbaseUserDetailResult as aI, type PalbaseUsersQueryInput as aJ, type PalbaseUsersResult as aK, type PalbaseVerifyRequestSignatureParams as aL, type PalbaseWhereOperator as aM, type RateLimitConfig as aN, type RowShape as aO, type TxClient as aP, type TypedDB as aQ, type TypedTable as aR, type TypedTx as aS, type User as aT, defineEndpoint as aU, defineMiddleware as aV, makeTypedDB as aW, type PalbaseLinkDetails as aa, type PalbaseLinksClient as ab, type PalbaseListLinksOptions as ac, type PalbaseListLinksResult as ad, type PalbaseListOptions as ae, type PalbaseMatchParams as af, type PalbaseMultiChannelResponse as ag, type PalbaseNotificationsClient as ah, type PalbaseOverviewResult as ai, type PalbasePreferences as aj, type PalbasePreferencesClient as ak, type PalbasePublicUrlResponse as al, type PalbasePushClient as am, type PalbasePushSendParams as an, type PalbasePushSendResponse as ao, type PalbaseQrCodeOptions as ap, type PalbaseQuerySnapshot as aq, type PalbaseRealtimeChannel as ar, type PalbaseRealtimeClient as as, type PalbaseRealtimeMessage as at, type PalbaseRegisterDeviceParams as au, type PalbaseResult as av, type PalbaseRetentionQueryInput as aw, type PalbaseRetentionResult as ax, type PalbaseSession as ay, type PalbaseSignedUrlResponse as az, type MiddlewareContext as b, type MiddlewareHandler as c, type PalbaseAnalyticsClient as d, type PalbaseAnalyticsManagementNamespace as e, type PalbaseAnalyticsProperties as f, type PalbaseAnalyticsQueryNamespace as g, type PalbaseAttestAndroidParams as h, type PalbaseAttestAndroidResult as i, type PalbaseAttestiOSParams as j, type PalbaseAttestiOSResult as k, type PalbaseAuthClient as l, type PalbaseBindDeviceParams as m, type PalbaseBucketClient as n, type PalbaseCmsClient as o, type PalbaseCmsFindOneOptions as p, type PalbaseCmsFindOptions as q, type PalbaseCohortQueryInput as r, type PalbaseCohortResult as s, type PalbaseCollectionRef as t, type PalbaseCountQueryInput as u, type PalbaseCountResult as v, type PalbaseCreateLinkParams as w, type PalbaseDeviceInfo as x, type PalbaseDeviceTokenView as y, type PalbaseDocsClient as z };
package/dist/index.cjs CHANGED
@@ -143,14 +143,21 @@ function makeTypedTable(name, raw) {
143
143
  };
144
144
  }
145
145
  function makeTypedDB(schema, raw) {
146
- const tables = {};
147
- for (const key of Object.keys(schema.tables)) {
148
- const tableDef = schema.tables[key];
149
- if (tableDef !== void 0) {
150
- tables[key] = makeTypedTable(tableDef.name, raw);
146
+ function buildTables(client) {
147
+ const tables = {};
148
+ for (const key of Object.keys(schema.tables)) {
149
+ const tableDef = schema.tables[key];
150
+ if (tableDef !== void 0) {
151
+ tables[key] = makeTypedTable(tableDef.name, client);
152
+ }
151
153
  }
154
+ return tables;
152
155
  }
153
- return { tables };
156
+ const result = {
157
+ tables: buildTables(raw),
158
+ transaction: (fn) => raw.transaction((rawTx) => fn({ tables: buildTables(rawTx) }))
159
+ };
160
+ return result;
154
161
  }
155
162
 
156
163
  // src/middleware.ts