@stacksjs/types 0.70.44 → 0.70.53

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/src/dashboard.ts CHANGED
@@ -12,6 +12,14 @@
12
12
  * row when there's no newsletter without losing the model viewer.
13
13
  */
14
14
  export interface DashboardOptions {
15
+ /**
16
+ * Top-level feature gate. When `false`, the entire admin SPA + dashboard
17
+ * routes stay un-registered at boot. Missing or `true` keeps the dashboard
18
+ * on — the framework default, since every Stacks app wants it.
19
+ */
20
+ enabled?: boolean
21
+ /** Optional deploy-target gate, e.g. `['production']`. */
22
+ env?: string[]
15
23
  /** Per-section visibility toggles. Omit a section to leave it enabled. */
16
24
  sections?: {
17
25
  library?: { enabled?: boolean }
@@ -35,6 +43,176 @@ export interface DashboardOptions {
35
43
  allModels?: { enabled?: boolean }
36
44
  }
37
45
  }
46
+ /**
47
+ * CI tracking surface — GitHub Actions health across the configured orgs.
48
+ * Ports the standalone `repo-dashboard` app into the dashboard
49
+ * (stacksjs/stacks#1844). Defaults to off because most projects don't
50
+ * own multiple GitHub orgs; opt in by listing orgs and surfacing a
51
+ * `GITHUB_TOKEN` in the environment.
52
+ */
53
+ ci?: {
54
+ enabled?: boolean
55
+ /** Orgs whose repos appear as per-tab CI cards. */
56
+ orgs?: string[]
57
+ /** Self-hosted runner caps per org. Defaults to {@link runnerCapDefault}. */
58
+ runnerCaps?: Record<string, number>
59
+ /** Fallback cap for orgs missing from `runnerCaps`. Defaults to 20. */
60
+ runnerCapDefault?: number
61
+ /** Repo names to exclude from the CI feed. */
62
+ ignoreRepos?: string[]
63
+ /**
64
+ * Failing-CI notification fan-out (stacksjs/stacks#1849).
65
+ *
66
+ * When enabled, the dashboard fires a notification through the
67
+ * configured channels every time a repo's CI transitions from
68
+ * success → failure (or first-time-seen → failure). Sticky-red
69
+ * repos don't keep firing; same-run-id polls don't re-fire; a
70
+ * 5-minute cooldown silences flap-storms.
71
+ */
72
+ notifications?: {
73
+ enabled?: boolean
74
+ /**
75
+ * Channels to fan out through. Maps to the same values
76
+ * `notify()` from @stacksjs/notifications accepts. Defaults to
77
+ * `['chat']` — Slack via webhook — because that channel
78
+ * doesn't need a recipient list (it's already scoped to a
79
+ * Slack channel via env).
80
+ */
81
+ channels?: Array<'email' | 'sms' | 'chat' | 'database'>
82
+ /**
83
+ * Per-channel recipients for the channels that need one
84
+ * (email/sms/database). Skipped for `chat`. Each entry must
85
+ * carry the field the named channel requires (`email`,
86
+ * `phone`, `userId`).
87
+ */
88
+ recipients?: Array<{ email?: string, phone?: string, userId?: number }>
89
+ /**
90
+ * Minimum delay (minutes) between consecutive notifications for
91
+ * the same repo. Defaults to 5. Set to 0 to disable.
92
+ */
93
+ cooldownMinutes?: number
94
+ }
95
+ /**
96
+ * Runner-pressure alerts (stacksjs/stacks#1850).
97
+ *
98
+ * When an org's queued-job count stays at or above
99
+ * `queuedThreshold` for `windowMinutes`, the dashboard fires a
100
+ * notification through the configured channels. Hysteresis: an
101
+ * already-alerting org doesn't re-fire until the queue drops
102
+ * below threshold for a full window first.
103
+ */
104
+ alerts?: {
105
+ enabled?: boolean
106
+ /** Queue depth at or above counts as pressure. Defaults to 8. */
107
+ queuedThreshold?: number
108
+ /** Duration the threshold must hold in either direction before
109
+ * the alert fires / clears. Defaults to 10 minutes. */
110
+ windowMinutes?: number
111
+ /** Same channel options as {@link notifications.channels}. */
112
+ channels?: Array<'email' | 'sms' | 'chat' | 'database'>
113
+ /** Same recipient shape as {@link notifications.recipients}. */
114
+ recipients?: Array<{ email?: string, phone?: string, userId?: number }>
115
+ /**
116
+ * How long the runner-sample time-series is kept on disk.
117
+ * Older samples are pruned during each refresh to bound
118
+ * storage. Defaults to 24h.
119
+ */
120
+ retentionHours?: number
121
+ }
122
+ }
38
123
  }
39
124
 
40
125
  export type DashboardConfig = Partial<DashboardOptions>
126
+
127
+ /**
128
+ * Per-model dashboard configuration (stacksjs/stacks#1843).
129
+ *
130
+ * Attach to a model definition to influence how the model surfaces in the
131
+ * dashboard sidebar without touching the framework's dashboard internals:
132
+ *
133
+ * ```ts
134
+ * defineModel({
135
+ * name: 'AuditLog',
136
+ * table: 'audit_logs',
137
+ * dashboard: {
138
+ * section: 'management',
139
+ * icon: 'shield',
140
+ * roles: ['admin'],
141
+ * description: 'Append-only audit trail (admin-only)',
142
+ * },
143
+ * attributes: { … },
144
+ * })
145
+ * ```
146
+ *
147
+ * Resolution chain (most specific → fallback):
148
+ *
149
+ * 1. `dashboard.enabled === false` → model is hidden from the sidebar
150
+ * entirely. The dynamic ORM viewer (`/models/<id>`) still works for
151
+ * direct navigation, but the row is suppressed.
152
+ * 2. `dashboard.section` → pins the model to that section, overriding
153
+ * the path-based auto-categorisation (commerce/, Content/, etc.).
154
+ * 3. `dashboard.label` / `dashboard.icon` → display overrides; fall back
155
+ * to the model name and `iconMap` lookup.
156
+ * 4. `dashboard.roles` → role-gates the sidebar row. The server-side
157
+ * sidebar builder emits the row with role metadata; the client filters
158
+ * it out for users who lack a matching role. Permissive default
159
+ * (unauthenticated viewers see everything — see `useRole.ts`).
160
+ */
161
+ export interface DashboardModelOptions {
162
+ /**
163
+ * Hide this model from the dashboard sidebar entirely. Direct
164
+ * navigation to `/models/<id>` still works — this only suppresses the
165
+ * sidebar row.
166
+ *
167
+ * Defaults to `true` (model is shown).
168
+ */
169
+ enabled?: boolean
170
+
171
+ /**
172
+ * Override the display name in the sidebar. Defaults to the model name.
173
+ */
174
+ label?: string
175
+
176
+ /**
177
+ * Override the icon. Defaults to the auto-derived one in `iconMap`.
178
+ * The string is whatever the active sidebar icon set expects
179
+ * (e.g., SF Symbol name for the native sidebar; Lucide-style name for
180
+ * the web sidebar).
181
+ */
182
+ icon?: string
183
+
184
+ /**
185
+ * Pin this model to a specific sidebar section instead of the
186
+ * auto-derived category. Useful when a "logs" model lives under
187
+ * `app/Models/` (userland) but should appear under Management rather
188
+ * than Data.
189
+ */
190
+ section?:
191
+ | 'home'
192
+ | 'library'
193
+ | 'content'
194
+ | 'commerce'
195
+ | 'marketing'
196
+ | 'analytics'
197
+ | 'management'
198
+ | 'utilities'
199
+ | 'data'
200
+ | 'app'
201
+
202
+ /**
203
+ * Role-gate the sidebar row. The row is rendered server-side with
204
+ * `data-required-roles="…"`; the client filters it out via
205
+ * `useRole()` if the viewer doesn't hold any of the listed roles.
206
+ *
207
+ * The dev-mode default in `useRole()` means unauthenticated viewers
208
+ * (e.g., the local dev dashboard) see role-gated rows as if they
209
+ * were a dev — see `composables/useRole.ts` for the full chain.
210
+ */
211
+ roles?: string[]
212
+
213
+ /**
214
+ * Short tooltip / hover description for the sidebar row. Optional —
215
+ * sidebars that don't support tooltips ignore it.
216
+ */
217
+ description?: string
218
+ }
package/src/database.ts CHANGED
@@ -13,6 +13,20 @@ export interface DatabaseOptions {
13
13
  prefix?: string
14
14
  }
15
15
 
16
+ // SingleStore is MySQL wire-compatible (port 3306); it shares MySQL's
17
+ // connection shape and adds an optional `ssl` flag for managed (Helios)
18
+ // endpoints, which require TLS.
19
+ singlestore?: {
20
+ url?: string
21
+ host?: string
22
+ port?: number
23
+ name?: string
24
+ username?: string
25
+ password?: string
26
+ prefix?: string
27
+ ssl?: boolean
28
+ }
29
+
16
30
  sqlite: {
17
31
  url?: string
18
32
  database?: string
package/src/email.ts CHANGED
@@ -277,6 +277,23 @@ export interface EmailOptions {
277
277
  }
278
278
 
279
279
  mailboxes: string[] | MailboxConfig[]
280
+
281
+ /**
282
+ * Auto-forwarding rules for received mail, provisioned to the mail server's
283
+ * readable `forwards.json` (re-read on every message — edits take effect
284
+ * with no restart).
285
+ *
286
+ * Key = the delivered mailbox: the full address for a per-domain isolated
287
+ * mailbox (e.g. `'no-reply@acme.com'`), or a bare local-part for a
288
+ * legacy role mailbox (e.g. `'postmaster'`).
289
+ * Value = destination addresses. Targets on a local domain are written
290
+ * straight to that mailbox's Maildir; external targets are relayed.
291
+ * A copy also stays in the source mailbox.
292
+ *
293
+ * @example { 'no-reply@acme.com': ['chris@acme.com'] }
294
+ */
295
+ forwards?: Record<string, string[]>
296
+
280
297
  domain?: string
281
298
 
282
299
  url: string
@@ -286,6 +303,30 @@ export interface EmailOptions {
286
303
  notifications?: EmailNotificationsConfig
287
304
 
288
305
  default: 'log' | 'ses' | 'sendgrid' | 'mailgun' | 'mailtrap' | 'smtp'
306
+
307
+ /**
308
+ * Suppression-list enforcement policy (stacksjs/stacks#1880).
309
+ *
310
+ * - `'strict'` — block all sends to suppressed
311
+ * recipients (default)
312
+ * - `'transactional-allowed'` — block broadcasts; allow messages
313
+ * with `tag: 'transactional'`
314
+ * - `'off'` — never block; the suppression
315
+ * table is just a tracking record
316
+ *
317
+ * The check is opt-in at the table level — apps that haven't
318
+ * created the `email_suppressions` table see "always allowed"
319
+ * with a one-shot warn.
320
+ */
321
+ suppressionPolicy?: 'strict' | 'transactional-allowed' | 'off'
322
+
323
+ /**
324
+ * URL prefix the framework's default unsubscribe route mounts
325
+ * under (stacksjs/stacks#1880). Defaults to
326
+ * `/_stacks/email/unsubscribe`. The full link is built as
327
+ * `${app.url}${unsubscribeRoute}/${signed-token}`.
328
+ */
329
+ unsubscribeRoute?: string
289
330
  }
290
331
 
291
332
  export type EmailConfig = Partial<EmailOptions>
@@ -340,6 +381,17 @@ export interface EmailMessage {
340
381
  cc?: string | string[] | EmailAddress[]
341
382
  /** Blind carbon copy recipient(s) */
342
383
  bcc?: string | string[] | EmailAddress[]
384
+ /**
385
+ * Reply-To address(es) for the outgoing message.
386
+ *
387
+ * Drivers must propagate this to the provider's equivalent field
388
+ * (`ReplyToAddresses` on SES, `h:Reply-To` on Mailgun, `reply_to` on
389
+ * SendGrid, a `Reply-To:` header for SMTP). Previously the field
390
+ * lived as an `as any` stash on the message (stacksjs/stacks#1871 M-4)
391
+ * — promoting it to a first-class slot means drivers can be
392
+ * checked at compile time for coverage.
393
+ */
394
+ replyTo?: EmailAddress | EmailAddress[] | string | string[]
343
395
  /** Email subject line */
344
396
  subject: string
345
397
  /** Path to email template (Vue component) */
@@ -364,6 +416,48 @@ export interface EmailMessage {
364
416
  onError?: (error: Error) => Promise<{ message: string }> | { message: string }
365
417
  /** Optional custom handler */
366
418
  handle?: () => Promise<{ message: string }> | { message: string }
419
+ /**
420
+ * Caller-supplied idempotency key (stacksjs/stacks#1871 M-8).
421
+ *
422
+ * When set, `mail.send()` consults an `email_idempotency` dedup
423
+ * table before dispatching to the driver:
424
+ * - hit: returns the cached EmailResult from the first send
425
+ * - miss: dispatches, then records the result under the key
426
+ *
427
+ * Why it matters: queued send retries (the framework retries 3×
428
+ * with backoff) and external retry loops (webhook handlers that
429
+ * re-fire on transient failures, request POSTs that the user
430
+ * double-clicks) can otherwise deliver the same email multiple
431
+ * times. The key turns those retries into safe no-ops.
432
+ *
433
+ * Construction guidance: derive the key from the business event
434
+ * the email represents — e.g. `welcome:${userId}`,
435
+ * `order-confirmation:${orderId}:${attempt}`, not from message
436
+ * content (which would collide across unrelated sends).
437
+ *
438
+ * The dedup table is opt-in. When the migration hasn't been run
439
+ * yet, the framework warns once and falls back to "send every
440
+ * time" so unrelated apps aren't broken by the new behavior.
441
+ */
442
+ idempotencyKey?: string
443
+ /**
444
+ * Classification used by the suppression-policy check
445
+ * (stacksjs/stacks#1880). Set to `'transactional'` for messages
446
+ * that should bypass suppression when
447
+ * `email.suppressionPolicy: 'transactional-allowed'` is
448
+ * configured — password resets, billing receipts, magic-link
449
+ * sign-ins.
450
+ *
451
+ * Set to `'broadcast'` (or omit) for marketing / newsletter
452
+ * sends; those get blocked when the recipient is suppressed.
453
+ *
454
+ * Under the default `'strict'` policy this field has no effect
455
+ * — both transactional and broadcast sends get blocked. Apps
456
+ * that need to send password-reset emails to bounced addresses
457
+ * (rare, but legitimate) opt into `'transactional-allowed'` AND
458
+ * tag the message.
459
+ */
460
+ tag?: 'transactional' | 'broadcast'
367
461
  }
368
462
 
369
463
  // Email interfaces
package/src/index.ts CHANGED
@@ -15,10 +15,17 @@ export * from './cdn'
15
15
  export * from './chat'
16
16
  export * from './cli'
17
17
  export * from './cloud'
18
+ export * from './cms'
19
+ export * from './commerce'
18
20
  export * from './components'
19
21
  export * from './configure'
22
+ export * from './cors'
20
23
  export * from './cron-jobs'
21
24
  export * from './dashboard'
25
+ // Module-augments bun-query-builder's BrowserModelDefinition with the
26
+ // stacks `dashboard` slot. Importing this file (transitively via the
27
+ // barrel) is what makes `defineModel({ dashboard: {...} })` typecheck.
28
+ export * from './model-dashboard-augmentation'
22
29
  export * from './database'
23
30
  export * from './dependencies'
24
31
  export * from './deploy'
@@ -37,8 +44,10 @@ export * from './i18n'
37
44
  export * from './library'
38
45
  export * from './logging'
39
46
  export * from './manifest'
47
+ export * from './marketing'
40
48
  export * from './model'
41
49
  export * from './model-names'
50
+ export * from './monitoring'
42
51
  export * from './notifications'
43
52
  export * from './pages'
44
53
  export * from './payments'
package/src/logging.ts CHANGED
@@ -25,6 +25,38 @@ export interface LoggingOptions {
25
25
  * @default 'storage/logs/deployments.log'
26
26
  */
27
27
  deploymentsPath: string
28
+
29
+ /**
30
+ * **Minimum Log Level**
31
+ *
32
+ * Messages below this level are suppressed. The `LOG_LEVEL` env var
33
+ * overrides this when set (stacksjs/stacks#1935).
34
+ *
35
+ * @default 'info'
36
+ */
37
+ level?: 'debug' | 'info' | 'success' | 'warning' | 'error'
38
+
39
+ /**
40
+ * **Output Format**
41
+ *
42
+ * `'json'` for structured output (production), `'text'` for the
43
+ * human-readable dev view. The `LOG_FORMAT` env var overrides this;
44
+ * default is `'json'` in production, `'text'` otherwise.
45
+ *
46
+ * @default 'text'
47
+ */
48
+ format?: 'json' | 'text'
49
+
50
+ /**
51
+ * **Write To File**
52
+ *
53
+ * Whether logs are persisted to `logsPath`'s directory as daily
54
+ * files. Set `false` for console-only output (e.g. when the platform
55
+ * captures stdout).
56
+ *
57
+ * @default true
58
+ */
59
+ writeToFile?: boolean
28
60
  }
29
61
 
30
62
  export type LoggingConfig = Partial<LoggingOptions>
@@ -0,0 +1,14 @@
1
+ /**
2
+ * **Marketing Options**
3
+ *
4
+ * Top-level feature gate for the marketing bundle (`/api/email/subscribe`,
5
+ * `/api/contact`, Campaign / EmailList / SocialPost). Stays inert at boot
6
+ * when `enabled` is `false`.
7
+ */
8
+ export interface MarketingOptions {
9
+ enabled?: boolean
10
+ /** Optional deploy-target gate, e.g. `['production']`. */
11
+ env?: string[]
12
+ }
13
+
14
+ export type MarketingConfig = Partial<MarketingOptions>
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Module augmentation that adds the Stacks-specific `dashboard` slot to
3
+ * bun-query-builder's `BrowserModelDefinition`.
4
+ *
5
+ * Why this lives here (Stacks, not bqb):
6
+ *
7
+ * The `dashboard` config is a Stacks framework concept — it influences
8
+ * how the model appears in `buddy dev --dashboard`'s sidebar. It has no
9
+ * meaning outside the dashboard surface, so adding it to bqb's core
10
+ * types would force every bqb consumer to carry weight they don't need.
11
+ *
12
+ * Declaration merging keeps the typing clean at every call site:
13
+ *
14
+ * ```ts
15
+ * import { defineModel } from '@stacksjs/orm'
16
+ *
17
+ * defineModel({
18
+ * name: 'AuditLog',
19
+ * dashboard: { section: 'management', roles: ['admin'] }, // ← typed
20
+ * attributes: { … },
21
+ * })
22
+ * ```
23
+ *
24
+ * Without this augmentation, the `dashboard` property would still pass
25
+ * (because bqb's `defineModel<TDef extends BrowserModelDefinition>` uses
26
+ * `extends`, which permits excess properties), but with no autocomplete
27
+ * and no shape validation. The augmentation gives both.
28
+ *
29
+ * Loading note: this file only declares types — no runtime effects. It
30
+ * must be reachable via `@stacksjs/types`' barrel so any package that
31
+ * already imports from `@stacksjs/types` picks up the augmentation in
32
+ * the same compilation. Re-exported from `index.ts`.
33
+ */
34
+
35
+ import type { DashboardModelOptions } from './dashboard'
36
+
37
+ declare module 'bun-query-builder' {
38
+ interface BrowserModelDefinition {
39
+ /**
40
+ * Stacks dashboard sidebar configuration for this model.
41
+ * See {@link DashboardModelOptions} for the full shape.
42
+ *
43
+ * Omit to use defaults (model is shown under its auto-categorised
44
+ * section using `iconMap` + the model name).
45
+ */
46
+ readonly dashboard?: DashboardModelOptions
47
+ }
48
+ }
49
+
50
+ // Re-export for `import type { DashboardModelOptions } from '@stacksjs/types'`.
51
+ export type { DashboardModelOptions }
package/src/model.ts CHANGED
@@ -103,10 +103,15 @@ type Action = ActionPath | ActionName | undefined
103
103
 
104
104
  export type ApiRoutes = 'index' | 'show' | 'store' | 'update' | 'destroy'
105
105
 
106
- export type SocialProviders = 'google' | 'github' | 'twitter' | 'facebook'
106
+ export type SocialProviders = 'google' | 'github' | 'apple' | 'twitter' | 'facebook'
107
107
 
108
108
  export interface SeedOptions {
109
109
  count: number
110
+ /**
111
+ * Fixed rows merged over factory output for the first N entries (N = fixtures.length).
112
+ * Keys use model attribute names (camelCase); stored as snake_case columns.
113
+ */
114
+ fixtures?: Array<Record<string, unknown>>
110
115
  }
111
116
 
112
117
  type LogAttribute = string
@@ -185,7 +190,17 @@ export interface ModelOptions extends Base {
185
190
  commentables?: boolean // defaults to false
186
191
  useAuth?: boolean | UserAuthOptions // defaults to false
187
192
  authenticatable?: boolean | UserAuthOptions // useAuth alias
193
+ /**
194
+ * @deprecated stacksjs/stacks#1929 — the `useSeeder` trait only
195
+ * existed to drive the auto-walker, which is removed from
196
+ * `./buddy seed` (stacksjs/stacks#1919). Seeding is now owned by
197
+ * class seeders: a `database/seeders/<Model>Seeder.ts` file calling
198
+ * `factory.generate(Model, { count })`. Run `./buddy seed:scaffold`
199
+ * to codemod existing traits into seeder files (and strip the
200
+ * trait). This field is scheduled for removal in the next major.
201
+ */
188
202
  useSeeder?: boolean | SeedOptions // defaults to a count of 10
203
+ /** @deprecated alias of {@link useSeeder} — see stacksjs/stacks#1929. */
189
204
  seedable?: boolean | SeedOptions // useSeeder alias
190
205
  useSearch?: boolean | SearchOptions // defaults to false
191
206
  useSocials?: SocialOptions // defaults to false
@@ -253,6 +268,23 @@ export interface Attribute {
253
268
  export interface CompositeIndex {
254
269
  name: string
255
270
  columns: string[]
271
+ /**
272
+ * Emit `UNIQUE` on the index — turns a multi-column index into a
273
+ * multi-column unique constraint. Combine with `where:` for a
274
+ * partial unique index (stacksjs/stacks#1943).
275
+ *
276
+ * @default false
277
+ */
278
+ unique?: boolean
279
+ /**
280
+ * Partial-index `WHERE` clause as a raw SQL expression — e.g.
281
+ * `'user_id IS NOT NULL'`. Lets the constraint apply to a subset of
282
+ * rows; the canonical case is "prevent a logged-in user from flagging
283
+ * the same review twice, but allow anonymous flags (user_id NULL) to
284
+ * repeat" (stacksjs/stacks#1943). Emitted verbatim, so don't
285
+ * interpolate untrusted input.
286
+ */
287
+ where?: string
256
288
  }
257
289
 
258
290
  export interface AttributesElements {
@@ -0,0 +1,14 @@
1
+ /**
2
+ * **Monitoring Options**
3
+ *
4
+ * Top-level feature gate for the monitoring bundle (Error model +
5
+ * error-tracking views and actions). Stays inert at boot when `enabled`
6
+ * is `false`.
7
+ */
8
+ export interface MonitoringOptions {
9
+ enabled?: boolean
10
+ /** Optional deploy-target gate, e.g. `['production']`. */
11
+ env?: string[]
12
+ }
13
+
14
+ export type MonitoringConfig = Partial<MonitoringOptions>
package/src/queue.ts CHANGED
@@ -250,6 +250,14 @@ export interface Dispatchable {
250
250
  }
251
251
 
252
252
  export interface QueueOptions {
253
+ /**
254
+ * Top-level feature gate. When `false`, the queue runtime is skipped at
255
+ * boot (no Job/FailedJob model load, no queue worker startup). Missing or
256
+ * `true` means the queue feature is on.
257
+ */
258
+ enabled?: boolean
259
+ /** Optional deploy-target gate, e.g. `['production']`. */
260
+ env?: string[]
253
261
  /** Default queue driver */
254
262
  default: QueueDriver
255
263
  /** Queue connections */