@actuate-media/cms-core 0.57.0 → 0.58.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.
Files changed (214) hide show
  1. package/dist/__tests__/api/stats-seo-cache.test.js +1 -1
  2. package/dist/__tests__/api/stats-seo-cache.test.js.map +1 -1
  3. package/dist/__tests__/auth/oauth.test.js +3 -1
  4. package/dist/__tests__/auth/oauth.test.js.map +1 -1
  5. package/dist/__tests__/auth/reset.test.js +1 -0
  6. package/dist/__tests__/auth/reset.test.js.map +1 -1
  7. package/dist/__tests__/auth/user-admin.test.js +14 -12
  8. package/dist/__tests__/auth/user-admin.test.js.map +1 -1
  9. package/dist/__tests__/db/model-types-freshness.test.d.ts +2 -0
  10. package/dist/__tests__/db/model-types-freshness.test.d.ts.map +1 -0
  11. package/dist/__tests__/db/model-types-freshness.test.js +46 -0
  12. package/dist/__tests__/db/model-types-freshness.test.js.map +1 -0
  13. package/dist/__tests__/scheduling/scheduling.test.js +8 -6
  14. package/dist/__tests__/scheduling/scheduling.test.js.map +1 -1
  15. package/dist/__tests__/server-site.test.js +3 -1
  16. package/dist/__tests__/server-site.test.js.map +1 -1
  17. package/dist/__tests__/setup/index.test.js +21 -10
  18. package/dist/__tests__/setup/index.test.js.map +1 -1
  19. package/dist/actions.d.ts +2 -1
  20. package/dist/actions.d.ts.map +1 -1
  21. package/dist/actions.js +15 -8
  22. package/dist/actions.js.map +1 -1
  23. package/dist/api/guarded-db.d.ts +14 -0
  24. package/dist/api/guarded-db.d.ts.map +1 -0
  25. package/dist/api/guarded-db.js +58 -0
  26. package/dist/api/guarded-db.js.map +1 -0
  27. package/dist/api/handler-factory.d.ts.map +1 -1
  28. package/dist/api/handler-factory.js +2 -1
  29. package/dist/api/handler-factory.js.map +1 -1
  30. package/dist/api/handlers.d.ts +5 -3
  31. package/dist/api/handlers.d.ts.map +1 -1
  32. package/dist/api/handlers.js +54 -13068
  33. package/dist/api/handlers.js.map +1 -1
  34. package/dist/api/route-helpers.d.ts +321 -0
  35. package/dist/api/route-helpers.d.ts.map +1 -0
  36. package/dist/api/route-helpers.js +1307 -0
  37. package/dist/api/route-helpers.js.map +1 -0
  38. package/dist/api/routes/ai-seo.d.ts +3 -0
  39. package/dist/api/routes/ai-seo.d.ts.map +1 -0
  40. package/dist/api/routes/ai-seo.js +377 -0
  41. package/dist/api/routes/ai-seo.js.map +1 -0
  42. package/dist/api/routes/ai-settings.d.ts +3 -0
  43. package/dist/api/routes/ai-settings.d.ts.map +1 -0
  44. package/dist/api/routes/ai-settings.js +764 -0
  45. package/dist/api/routes/ai-settings.js.map +1 -0
  46. package/dist/api/routes/auth.d.ts +3 -0
  47. package/dist/api/routes/auth.d.ts.map +1 -0
  48. package/dist/api/routes/auth.js +787 -0
  49. package/dist/api/routes/auth.js.map +1 -0
  50. package/dist/api/routes/collab.d.ts +3 -0
  51. package/dist/api/routes/collab.d.ts.map +1 -0
  52. package/dist/api/routes/collab.js +426 -0
  53. package/dist/api/routes/collab.js.map +1 -0
  54. package/dist/api/routes/dashboard.d.ts +7 -0
  55. package/dist/api/routes/dashboard.d.ts.map +1 -0
  56. package/dist/api/routes/dashboard.js +540 -0
  57. package/dist/api/routes/dashboard.js.map +1 -0
  58. package/dist/api/routes/documents.d.ts +3 -0
  59. package/dist/api/routes/documents.d.ts.map +1 -0
  60. package/dist/api/routes/documents.js +180 -0
  61. package/dist/api/routes/documents.js.map +1 -0
  62. package/dist/api/routes/folders.d.ts +3 -0
  63. package/dist/api/routes/folders.d.ts.map +1 -0
  64. package/dist/api/routes/folders.js +195 -0
  65. package/dist/api/routes/folders.js.map +1 -0
  66. package/dist/api/routes/forms.d.ts +3 -0
  67. package/dist/api/routes/forms.d.ts.map +1 -0
  68. package/dist/api/routes/forms.js +661 -0
  69. package/dist/api/routes/forms.js.map +1 -0
  70. package/dist/api/routes/globals.d.ts +3 -0
  71. package/dist/api/routes/globals.d.ts.map +1 -0
  72. package/dist/api/routes/globals.js +133 -0
  73. package/dist/api/routes/globals.js.map +1 -0
  74. package/dist/api/routes/media.d.ts +3 -0
  75. package/dist/api/routes/media.d.ts.map +1 -0
  76. package/dist/api/routes/media.js +521 -0
  77. package/dist/api/routes/media.js.map +1 -0
  78. package/dist/api/routes/meta.d.ts +3 -0
  79. package/dist/api/routes/meta.d.ts.map +1 -0
  80. package/dist/api/routes/meta.js +96 -0
  81. package/dist/api/routes/meta.js.map +1 -0
  82. package/dist/api/routes/page-templates.d.ts +3 -0
  83. package/dist/api/routes/page-templates.d.ts.map +1 -0
  84. package/dist/api/routes/page-templates.js +265 -0
  85. package/dist/api/routes/page-templates.js.map +1 -0
  86. package/dist/api/routes/presence.d.ts +3 -0
  87. package/dist/api/routes/presence.d.ts.map +1 -0
  88. package/dist/api/routes/presence.js +35 -0
  89. package/dist/api/routes/presence.js.map +1 -0
  90. package/dist/api/routes/preview.d.ts +3 -0
  91. package/dist/api/routes/preview.d.ts.map +1 -0
  92. package/dist/api/routes/preview.js +111 -0
  93. package/dist/api/routes/preview.js.map +1 -0
  94. package/dist/api/routes/redirects.d.ts +3 -0
  95. package/dist/api/routes/redirects.d.ts.map +1 -0
  96. package/dist/api/routes/redirects.js +790 -0
  97. package/dist/api/routes/redirects.js.map +1 -0
  98. package/dist/api/routes/saved-sections.d.ts +3 -0
  99. package/dist/api/routes/saved-sections.d.ts.map +1 -0
  100. package/dist/api/routes/saved-sections.js +1036 -0
  101. package/dist/api/routes/saved-sections.js.map +1 -0
  102. package/dist/api/routes/scheduling.d.ts +3 -0
  103. package/dist/api/routes/scheduling.d.ts.map +1 -0
  104. package/dist/api/routes/scheduling.js +373 -0
  105. package/dist/api/routes/scheduling.js.map +1 -0
  106. package/dist/api/routes/sections.d.ts +3 -0
  107. package/dist/api/routes/sections.d.ts.map +1 -0
  108. package/dist/api/routes/sections.js +500 -0
  109. package/dist/api/routes/sections.js.map +1 -0
  110. package/dist/api/routes/security-center.d.ts +3 -0
  111. package/dist/api/routes/security-center.d.ts.map +1 -0
  112. package/dist/api/routes/security-center.js +71 -0
  113. package/dist/api/routes/security-center.js.map +1 -0
  114. package/dist/api/routes/seo-public.d.ts +14 -0
  115. package/dist/api/routes/seo-public.d.ts.map +1 -0
  116. package/dist/api/routes/seo-public.js +930 -0
  117. package/dist/api/routes/seo-public.js.map +1 -0
  118. package/dist/api/routes/seo.d.ts +8 -0
  119. package/dist/api/routes/seo.d.ts.map +1 -0
  120. package/dist/api/routes/seo.js +848 -0
  121. package/dist/api/routes/seo.js.map +1 -0
  122. package/dist/api/routes/system.d.ts +3 -0
  123. package/dist/api/routes/system.d.ts.map +1 -0
  124. package/dist/api/routes/system.js +340 -0
  125. package/dist/api/routes/system.js.map +1 -0
  126. package/dist/api/routes/url-resolution.d.ts +3 -0
  127. package/dist/api/routes/url-resolution.d.ts.map +1 -0
  128. package/dist/api/routes/url-resolution.js +457 -0
  129. package/dist/api/routes/url-resolution.js.map +1 -0
  130. package/dist/api/routes/users.d.ts +3 -0
  131. package/dist/api/routes/users.d.ts.map +1 -0
  132. package/dist/api/routes/users.js +1162 -0
  133. package/dist/api/routes/users.js.map +1 -0
  134. package/dist/api/routes/webhooks.d.ts +3 -0
  135. package/dist/api/routes/webhooks.d.ts.map +1 -0
  136. package/dist/api/routes/webhooks.js +338 -0
  137. package/dist/api/routes/webhooks.js.map +1 -0
  138. package/dist/auth/invites.d.ts +9 -8
  139. package/dist/auth/invites.d.ts.map +1 -1
  140. package/dist/auth/invites.js.map +1 -1
  141. package/dist/auth/oauth.d.ts +2 -1
  142. package/dist/auth/oauth.d.ts.map +1 -1
  143. package/dist/auth/oauth.js.map +1 -1
  144. package/dist/auth/reset.d.ts +3 -2
  145. package/dist/auth/reset.d.ts.map +1 -1
  146. package/dist/auth/reset.js +5 -2
  147. package/dist/auth/reset.js.map +1 -1
  148. package/dist/auth/session.d.ts +3 -2
  149. package/dist/auth/session.d.ts.map +1 -1
  150. package/dist/auth/session.js.map +1 -1
  151. package/dist/auth/team.d.ts +4 -3
  152. package/dist/auth/team.d.ts.map +1 -1
  153. package/dist/auth/team.js.map +1 -1
  154. package/dist/auth/user-admin.d.ts +6 -5
  155. package/dist/auth/user-admin.d.ts.map +1 -1
  156. package/dist/auth/user-admin.js.map +1 -1
  157. package/dist/content-health/cron.d.ts +2 -1
  158. package/dist/content-health/cron.d.ts.map +1 -1
  159. package/dist/content-health/cron.js.map +1 -1
  160. package/dist/cron/index.d.ts +2 -1
  161. package/dist/cron/index.d.ts.map +1 -1
  162. package/dist/cron/index.js +2 -0
  163. package/dist/cron/index.js.map +1 -1
  164. package/dist/db/client-types.d.ts +75 -0
  165. package/dist/db/client-types.d.ts.map +1 -0
  166. package/dist/db/client-types.js +2 -0
  167. package/dist/db/client-types.js.map +1 -0
  168. package/dist/db/model-types.d.ts +564 -0
  169. package/dist/db/model-types.d.ts.map +1 -0
  170. package/dist/db/model-types.js +14 -0
  171. package/dist/db/model-types.js.map +1 -0
  172. package/dist/diagnostics/api-metrics.d.ts.map +1 -1
  173. package/dist/diagnostics/api-metrics.js.map +1 -1
  174. package/dist/forms/entries.d.ts.map +1 -1
  175. package/dist/forms/entries.js.map +1 -1
  176. package/dist/forms/files.d.ts.map +1 -1
  177. package/dist/forms/files.js.map +1 -1
  178. package/dist/forms/service.d.ts.map +1 -1
  179. package/dist/forms/service.js.map +1 -1
  180. package/dist/forms/submission.d.ts.map +1 -1
  181. package/dist/forms/submission.js.map +1 -1
  182. package/dist/forms/webhooks.d.ts.map +1 -1
  183. package/dist/forms/webhooks.js.map +1 -1
  184. package/dist/graphql/index.d.ts.map +1 -1
  185. package/dist/graphql/index.js.map +1 -1
  186. package/dist/index.d.ts +1 -0
  187. package/dist/index.d.ts.map +1 -1
  188. package/dist/index.js.map +1 -1
  189. package/dist/scheduling/index.d.ts +2 -1
  190. package/dist/scheduling/index.d.ts.map +1 -1
  191. package/dist/scheduling/index.js.map +1 -1
  192. package/dist/search/index.d.ts.map +1 -1
  193. package/dist/search/index.js.map +1 -1
  194. package/dist/security/audit.d.ts.map +1 -1
  195. package/dist/security/audit.js.map +1 -1
  196. package/dist/security/reauth.d.ts +2 -1
  197. package/dist/security/reauth.d.ts.map +1 -1
  198. package/dist/security/reauth.js.map +1 -1
  199. package/dist/seo/audit-runner.d.ts +3 -2
  200. package/dist/seo/audit-runner.d.ts.map +1 -1
  201. package/dist/seo/audit-runner.js.map +1 -1
  202. package/dist/server-site.d.ts +2 -1
  203. package/dist/server-site.d.ts.map +1 -1
  204. package/dist/server-site.js.map +1 -1
  205. package/dist/setup/index.d.ts +4 -3
  206. package/dist/setup/index.d.ts.map +1 -1
  207. package/dist/setup/index.js.map +1 -1
  208. package/dist/webhooks/index.d.ts +5 -5
  209. package/dist/webhooks/index.d.ts.map +1 -1
  210. package/dist/webhooks/index.js +8 -1
  211. package/dist/webhooks/index.js.map +1 -1
  212. package/dist/workflow/index.d.ts.map +1 -1
  213. package/dist/workflow/index.js.map +1 -1
  214. package/package.json +1 -1
@@ -0,0 +1,321 @@
1
+ import type { ActionContext } from '../actions.js';
2
+ import { type TeamOptions } from '../auth/team.js';
3
+ import type { CollectionDefinition } from '../config/types.js';
4
+ import type { FetchFormEntriesParams, FetchFormsParams, FormDefinition } from '../forms/types.js';
5
+ import { type IncomingFile } from '../forms/files.js';
6
+ import { type ApiKeyScope } from '../security/api-key-enhanced.js';
7
+ import type { ActuateDB } from '../db/client-types.js';
8
+ export declare function importBlobStorage(): Promise<any>;
9
+ export declare function importAIPlugin(): Promise<any>;
10
+ /**
11
+ * Build the system/user prompt for an inline co-author action. Kept
12
+ * deterministic and small so the governed runtime can route it to any
13
+ * configured provider/model.
14
+ */
15
+ export declare function buildCoauthorPrompt(action: 'rewrite' | 'expand' | 'compress' | 'proofread', body: {
16
+ text?: string;
17
+ style?: string;
18
+ tone?: string;
19
+ instructions?: string;
20
+ targetLength?: number;
21
+ }): {
22
+ system: string;
23
+ user: string;
24
+ maxTokens: number;
25
+ };
26
+ /**
27
+ * Common helper for the read endpoints. Reads the `?populate=` query param,
28
+ * fetches the target collection's field schema, and expands every relation
29
+ * reference into a {@link RelationSummary}. When the caller didn't ask for
30
+ * population (or the doc has no `data` field) we short-circuit and return
31
+ * the doc untouched.
32
+ *
33
+ * Lives here (not in `actions.ts`) because the rest of the actions API
34
+ * stays purely DB-shaped — population is an HTTP concern.
35
+ */
36
+ export declare function maybePopulate(request: Request, collection: string, doc: Record<string, unknown> | null, dbInstance: ActuateDB): Promise<Record<string, unknown> | null>;
37
+ export declare const SECURITY_HEADERS: Record<string, string>;
38
+ export declare function json(data: unknown, status?: number): Response;
39
+ /**
40
+ * Variant of `json()` that emits the Phase-5.5 public-read
41
+ * `Cache-Control` header when the active CMS config opts in.
42
+ *
43
+ * - Session-cookie requests always get `private, no-store`.
44
+ * - API-key / unauthenticated requests get
45
+ * `public, s-maxage=N, stale-while-revalidate=M` when
46
+ * `cache.publicReads.enabled` is true.
47
+ * - Otherwise no `Cache-Control` header is set (i.e. the response is
48
+ * uncacheable downstream, matching the pre-5.5 behaviour).
49
+ *
50
+ * Use this for the public read endpoints (`/collections/:slug`,
51
+ * `/collections/:slug/:id`, `/globals/:slug`, `/resolve`). Mutating
52
+ * endpoints stay on the plain `json()` so the CDN never caches a write
53
+ * response by accident.
54
+ */
55
+ export declare function jsonWithCache(data: unknown, request: Request, status?: number): Response;
56
+ export declare function errorResponse(message: string, status: number): Response;
57
+ export declare function internalError(err: unknown, context?: string): Response;
58
+ export declare function clampPageSize(raw: number | string | null, max?: number, fallback?: number): number;
59
+ export declare function mediaUrl(storageKey: unknown): string;
60
+ export declare function normalizeMediaItem(media: any): any;
61
+ /**
62
+ * Build the admin editor route for a document that references a media asset.
63
+ * Pages own the `/pages/*` namespace; post-type collections use
64
+ * `/posts/:type/:id/edit`; everything else falls back to the generic
65
+ * collection editor. Kept in sync with the route table in `AdminRoot.tsx`.
66
+ */
67
+ export declare function mediaUsageEditPath(collection: string, id: string): string;
68
+ /**
69
+ * Map the `MediaUsage` join rows (with their related document) into the
70
+ * `{ page, path }[]` shape the admin drawer renders. Soft-deleted documents
71
+ * are excluded so trashed pages don't keep an asset looking "in use".
72
+ */
73
+ export declare function buildMediaUsedOn(mediaUsages: unknown): {
74
+ page: string;
75
+ path: string;
76
+ }[];
77
+ export declare const MEDIA_TITLE_STOPWORDS: Set<string>;
78
+ /**
79
+ * Derive a concise, Title-Cased title from AI-generated alt text. The alt
80
+ * text is already a model output describing the image, so the title stays
81
+ * grounded in real content rather than the filename.
82
+ */
83
+ export declare function deriveMediaTitleFromAlt(alt: string): string;
84
+ export declare function asRecord(value: unknown): Record<string, unknown>;
85
+ export declare function normalizeSubmission(submission: any): any;
86
+ /**
87
+ * Map a forms-service domain error to an HTTP response. Returns `null` for
88
+ * unrecognised errors so the caller can fall through to `internalError`.
89
+ */
90
+ export declare function mapFormError(err: unknown): Response | null;
91
+ export declare function parseFormsQuery(url: URL): FetchFormsParams;
92
+ export declare function parseEntriesQuery(url: URL): FetchFormEntriesParams;
93
+ /**
94
+ * Build CORS headers for the public form endpoints. When the form has no
95
+ * embed allowlist we reflect the requesting origin (open embedding). When an
96
+ * allowlist is set we only echo the origin if it matches, so a disallowed site
97
+ * cannot read the response. Browser-level CORS is complemented by a hard
98
+ * server-side origin check in the submit handler.
99
+ */
100
+ export declare function formCorsHeaders(request: Request, allowedDomains?: string[]): Record<string, string>;
101
+ export declare function normalizeAllowedHost(domain: string): string;
102
+ export declare function isOriginAllowed(origin: string, allowedDomains: string[]): boolean;
103
+ export declare function jsonWithHeaders(data: unknown, status: number, extra: Record<string, string>): Response;
104
+ /**
105
+ * Parse a public submission request into field values, files, and metadata.
106
+ * Supports both `application/json` (no files) and `multipart/form-data`
107
+ * (files + fields). Unknown/oversized bodies are rejected by the caller's
108
+ * Content-Length gate before this runs.
109
+ */
110
+ export declare function parseSubmissionRequest(request: Request): Promise<{
111
+ values: Record<string, unknown>;
112
+ files: IncomingFile[];
113
+ meta: {
114
+ attribution: Record<string, unknown> | null;
115
+ elapsedMs: number | null;
116
+ pageUrl: string | null;
117
+ captchaToken: string;
118
+ };
119
+ } | null>;
120
+ export declare function safeJsonObject(value: unknown): Record<string, unknown> | null;
121
+ /**
122
+ * Shared public-submission handler used by both the slug-based public route and
123
+ * the legacy by-id route. Enforces per-IP+form rate limiting, embed-origin
124
+ * allowlisting, optional CAPTCHA, file validation, then runs the core
125
+ * submission pipeline. Always responds with CORS headers so embedded forms can
126
+ * read the result.
127
+ */
128
+ export declare function submitToForm(request: Request, form: FormDefinition): Promise<Response>;
129
+ export declare function normalizeRedirect(redirect: any): any;
130
+ export declare function normalizeSeoPage(page: any): any;
131
+ export declare function hasModel(d: any, name: string): boolean;
132
+ /** Format a number compactly, e.g. 8400 -> "8.4K", 1_200_000 -> "1.2M". */
133
+ export declare function formatCompactNumber(n: number): string;
134
+ /** Minimal CSV line parser supporting double-quoted fields with escaped quotes. */
135
+ export declare function parseCsvLine(line: string): string[];
136
+ export declare function modelNotAvailable(name: string): Response;
137
+ /**
138
+ * XML-escape a value for safe inclusion in sitemap content. Sitemaps reject
139
+ * unescaped ampersands and angle brackets; URLs frequently contain `&` query
140
+ * separators, so this is non-optional.
141
+ */
142
+ export declare function escapeXml(value: string): string;
143
+ /**
144
+ * URLs per sitemap file. The sitemaps protocol caps a single file at 50,000
145
+ * URLs; we use a margin below that so the optional archive URL on page 0 can
146
+ * never push a file over the limit. Collections larger than this are split
147
+ * across multiple `?page=N` files referenced from the sitemap index.
148
+ */
149
+ export declare const SITEMAP_PAGE_SIZE = 45000;
150
+ /**
151
+ * Renders a 1200x630 SVG suitable for og:image. We don't pull in Satori/resvg
152
+ * because most integrators don't need PNG — major crawlers (Facebook, Twitter,
153
+ * LinkedIn, Slack, Discord) handle image/svg+xml correctly. Sites that
154
+ * specifically need PNG can override with their own /og endpoint via
155
+ * @vercel/og and point `seo.defaultOgImage` at it.
156
+ */
157
+ export declare function renderOgSvg(opts: {
158
+ title: string;
159
+ description?: string;
160
+ siteName?: string | null;
161
+ theme: 'light' | 'dark';
162
+ bg: string;
163
+ fg: string;
164
+ muted: string;
165
+ }): string;
166
+ /**
167
+ * Log unexpected query failures from the `safe*` wrappers.
168
+ *
169
+ * The wrappers exist so an optional Prisma model (e.g. a delegate
170
+ * that older schemas don't define) doesn't blow up the route — they
171
+ * return the empty value (`0` / `[]`) when the model isn't available.
172
+ * That defensive contract historically swallowed *every* error,
173
+ * including Prisma's "Unknown argument" rejections that flag a real
174
+ * application bug (see the `relationLoadStrategy` regression
175
+ * discovered while landing Phase 5.5 #5). Logging the underlying
176
+ * error preserves the defensive return semantics while making the
177
+ * actual class of bug visible in Vercel + Sentry logs.
178
+ *
179
+ * Kept private to this module — it's a logging contract, not a
180
+ * public API.
181
+ */
182
+ export declare function logSafeQueryFailure(scope: string, err: unknown): void;
183
+ export declare function safeCount(model: any, where?: Record<string, unknown>): Promise<number>;
184
+ export declare function safeFindMany<T>(model: any, args: Record<string, unknown>): Promise<T[]>;
185
+ export declare function isAllowedStorageUrl(url: string): boolean;
186
+ /** Max image size (bytes) we'll pull into memory for vision analysis. */
187
+ export declare const MAX_VISION_IMAGE_BYTES: number;
188
+ /**
189
+ * Fetch image bytes for multimodal (vision) analysis through {@link safeFetch}
190
+ * (SSRF-safe: re-validates the host, DNS-resolves to defeat rebinding, no
191
+ * redirects). Returns `null` on any failure (non-image, oversize, blocked,
192
+ * network) so the caller transparently falls back to a context-only heuristic.
193
+ */
194
+ export declare function fetchImageForVision(url: string, knownMimeType?: string): Promise<{
195
+ base64: string;
196
+ mimeType: string;
197
+ } | null>;
198
+ export declare const ALLOWED_SORT_FIELDS: Set<string>;
199
+ export declare function getSessionSecret(): string;
200
+ export declare function isSecretMissing(): boolean;
201
+ /**
202
+ * Authenticated request context. `apiKey` is set when the request was
203
+ * authenticated via an `act_sk_*` API key (rather than a user session) — in
204
+ * that case `sessionId` is the API key id and `role` reflects either the
205
+ * granted `admin` scope or `'API_KEY'` for scoped keys.
206
+ */
207
+ export type AuthSession = {
208
+ userId: string;
209
+ role: string;
210
+ sessionId: string;
211
+ apiKey?: {
212
+ id: string;
213
+ scopes: ApiKeyScope;
214
+ };
215
+ };
216
+ export declare function extractSession(request: Request): Promise<AuthSession | null>;
217
+ export declare function parseCookieHeader(cookieHeader: string): Record<string, string>;
218
+ /**
219
+ * Verify a password (or "current password") posted in the X-Reauth-Password
220
+ * header against the authenticated user. Returns an error Response when the
221
+ * header is missing or the password is wrong; returns null on success.
222
+ *
223
+ * Use this for high-impact account changes (TOTP enable/disable, role change,
224
+ * delete user, etc.) so a stolen session alone cannot perform them.
225
+ */
226
+ export declare function requirePasswordReauth(request: Request, userId: string): Promise<Response | null>;
227
+ export declare function requireAuth(request: Request): Promise<{
228
+ session: AuthSession;
229
+ error?: never;
230
+ } | {
231
+ session?: never;
232
+ error: Response;
233
+ }>;
234
+ /**
235
+ * Check that the request's auth context permits `action` on `collection`.
236
+ * - Session-authenticated requests fall through to `requireRole` semantics:
237
+ * write actions require WRITE_ROLES.
238
+ * - API-key-authenticated requests must have an explicit scope match.
239
+ */
240
+ export declare function requireCollectionScope(session: AuthSession, collection: string, action: 'read' | 'create' | 'update' | 'delete'): Response | null;
241
+ export declare function requireGlobalScope(session: AuthSession, slug: string): Response | null;
242
+ export declare function requireMediaScope(session: AuthSession): Response | null;
243
+ export declare function requirePageBuilderScope(session: AuthSession): Response | null;
244
+ export declare function requireAdminScope(session: AuthSession): Response | null;
245
+ export declare function buildActionContext(session: {
246
+ userId: string;
247
+ role: string;
248
+ }, db: ActuateDB, locale?: string): ActionContext;
249
+ export declare const WRITE_ROLES: Set<string>;
250
+ export declare const ADMIN_ROLES: Set<string>;
251
+ export declare function requireRole(role: string, allowedRoles: Set<string>): Response | null;
252
+ /**
253
+ * Build the shared {@link TeamOptions} for the Users endpoints from config +
254
+ * session: the workspace domain (for external-domain detection) and the seat
255
+ * cap (config-provided; null = unlimited until billing exists).
256
+ */
257
+ export declare function teamOptionsFor(session: AuthSession): TeamOptions;
258
+ /** Whether the configured email provider can actually send mail. */
259
+ export declare function isEmailConfigured(): boolean;
260
+ export declare const loginLimiter: import("../security/rate-limit.js").RateLimiter;
261
+ export declare const inviteLimiter: import("../security/rate-limit.js").RateLimiter;
262
+ export declare const totpLimiter: import("../security/rate-limit.js").RateLimiter;
263
+ export declare const formLimiterGlobal: import("../security/rate-limit.js").RateLimiter;
264
+ export declare const aiGenerateLimiter: import("../security/rate-limit.js").RateLimiter;
265
+ export declare const uploadLimiter: import("../security/rate-limit.js").RateLimiter;
266
+ export declare const aiAnalysisLimiter: import("../security/rate-limit.js").RateLimiter;
267
+ export declare const AI_ANALYSIS_MAX_CHARS = 50000;
268
+ export declare const linkHealthLimiter: import("../security/rate-limit.js").RateLimiter;
269
+ export declare const seoAuditLimiter: import("../security/rate-limit.js").RateLimiter;
270
+ export declare function checkRateLimitAsync(limiter: {
271
+ check: (key: string) => Promise<{
272
+ allowed: boolean;
273
+ }>;
274
+ }, key: string): Promise<boolean>;
275
+ /**
276
+ * Resolve the client IP from trusted-proxy headers (Vercel first, then x-real-ip,
277
+ * then x-forwarded-for only when ACTUATE_TRUST_PROXY=1). Returns 'unknown' when
278
+ * no trustworthy source is available — callers MUST treat that case as a hard
279
+ * failure for security-sensitive decisions like rate-limit keys and IP allowlists.
280
+ */
281
+ export declare function clientIp(request: Request): string;
282
+ /**
283
+ * Compute a before/after diff of top-level scalar (string/number/boolean) keys
284
+ * between a stored record and an incoming patch. Used to audit settings changes
285
+ * without ever logging nested objects (which may hold secret blobs).
286
+ */
287
+ export declare function diffScalarKeys(previous: Record<string, unknown>, next: Record<string, unknown>): Array<{
288
+ key: string;
289
+ from: unknown;
290
+ to: unknown;
291
+ }>;
292
+ export declare const MAX_CONCURRENT_SESSIONS = 5;
293
+ /**
294
+ * After a successful primary-credential check, prune the user's active sessions
295
+ * down to the configured concurrent maximum (default 5; configurable via
296
+ * `auth.maxConcurrentSessions`). Strategy is "revoke oldest" so a user can
297
+ * always sign in.
298
+ */
299
+ export declare function enforceSessionLimitsForUser(d: any, userId: string): Promise<void>;
300
+ export declare function getAdminPath(): string;
301
+ /**
302
+ * Resolve a collection definition from the runtime config, tolerating both
303
+ * the array and the record (keyed-by-slug) shapes consumers use.
304
+ */
305
+ export declare function findCollectionDef(slug: string): CollectionDefinition | undefined;
306
+ /**
307
+ * True when `collection` declares a `sections` JSON field — the storage
308
+ * contract the flat Page Editor + section endpoints rely on. Guards against
309
+ * silently dropping section writes on a collection that never declared the
310
+ * field (the field-access layer strips undeclared keys).
311
+ */
312
+ export declare function collectionSupportsSections(slug: string): boolean;
313
+ /**
314
+ * Gate a per-document read for endpoints (e.g. SEO analysis) that fetch a
315
+ * document directly rather than through the collection CRUD routes. Enforces
316
+ * both the API-key collection scope and the collection's `access.read` rule
317
+ * so an AUTHOR scoped to one collection cannot read another's content.
318
+ * Returns a `Response` to short-circuit with, or `null` when allowed.
319
+ */
320
+ export declare function enforceDocumentReadAccess(session: AuthSession, collection: string): Promise<Response | null>;
321
+ //# sourceMappingURL=route-helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route-helpers.d.ts","sourceRoot":"","sources":["../../src/api/route-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAKlD,OAAO,EAA0B,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAG1E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAS9D,OAAO,KAAK,EACV,sBAAsB,EACtB,gBAAgB,EAChB,cAAc,EAEf,MAAM,mBAAmB,CAAA;AAM1B,OAAO,EAIL,KAAK,YAAY,EAClB,MAAM,mBAAmB,CAAA;AAS1B,OAAO,EAQL,KAAK,WAAW,EACjB,MAAM,iCAAiC,CAAA;AAExC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAItD,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,GAAG,CAAC,CAGtD;AAED,wBAAsB,cAAc,IA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