qarpeo 0.1.18 → 0.1.21

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 (237) hide show
  1. package/README.md +96 -96
  2. package/dist/chunks/auth-schema.mjs +3 -1
  3. package/dist/chunks/wrangler.mjs +22 -3
  4. package/dist/cli/index.mjs +448 -221
  5. package/dist/fate/index.d.ts +29 -22
  6. package/dist/fate/index.mjs +1 -3
  7. package/dist/module.d.ts +1 -1
  8. package/dist/module.mjs +103 -82
  9. package/dist/runtime/ai.d.ts +2 -2
  10. package/dist/runtime/app/components/BlobImage.vue +119 -107
  11. package/dist/runtime/app/components/CMSBlocks.vue +104 -93
  12. package/dist/runtime/app/components/CMSContent.vue +24 -23
  13. package/dist/runtime/app/components/CMSImage.vue +49 -49
  14. package/dist/runtime/app/components/CMSLocaleSwitcher.vue +110 -110
  15. package/dist/runtime/app/components/CMSPreviewBanner.vue +83 -79
  16. package/dist/runtime/app/components/CMSVersionBanner.vue +53 -49
  17. package/dist/runtime/app/components/CMSVersionSwitcher.vue +140 -140
  18. package/dist/runtime/app/components/ContentRenderer.vue +83 -80
  19. package/dist/runtime/app/components/FileUpload.vue +200 -196
  20. package/dist/runtime/app/components/ImpersonationBanner.vue +61 -57
  21. package/dist/runtime/app/components/QarpeoWelcome.vue +84 -84
  22. package/dist/runtime/app/components/SignedIn.vue +13 -13
  23. package/dist/runtime/app/components/SignedOut.vue +13 -13
  24. package/dist/runtime/app/components/shiki.css +34 -34
  25. package/dist/runtime/app/composables/ai.d.ts +22 -22
  26. package/dist/runtime/app/composables/ai.mjs +3 -7
  27. package/dist/runtime/app/composables/analytics.mjs +1 -1
  28. package/dist/runtime/app/composables/api-tokens.mjs +1 -1
  29. package/dist/runtime/app/composables/auth.d.ts +6 -7
  30. package/dist/runtime/app/composables/auth.mjs +6 -3
  31. package/dist/runtime/app/composables/chat.mjs +3 -7
  32. package/dist/runtime/app/composables/cms-preview.d.ts +3 -3
  33. package/dist/runtime/app/composables/cms-preview.mjs +1 -1
  34. package/dist/runtime/app/composables/cms.d.ts +3 -5
  35. package/dist/runtime/app/composables/cms.mjs +2 -2
  36. package/dist/runtime/app/composables/docs-version.d.ts +8 -7
  37. package/dist/runtime/app/composables/docs-version.mjs +3 -3
  38. package/dist/runtime/app/composables/impersonation.mjs +1 -1
  39. package/dist/runtime/app/composables/notifications.d.ts +5 -5
  40. package/dist/runtime/app/composables/notifications.mjs +4 -5
  41. package/dist/runtime/app/composables/organization.mjs +1 -1
  42. package/dist/runtime/app/composables/passkey.mjs +1 -1
  43. package/dist/runtime/app/composables/passwordless.mjs +1 -1
  44. package/dist/runtime/app/composables/payments.d.ts +2 -1
  45. package/dist/runtime/app/composables/payments.mjs +1 -1
  46. package/dist/runtime/app/composables/realtime.d.ts +13 -13
  47. package/dist/runtime/app/composables/realtime.mjs +2 -2
  48. package/dist/runtime/app/composables/resumable-upload.d.ts +11 -11
  49. package/dist/runtime/app/composables/resumable-upload.mjs +1 -1
  50. package/dist/runtime/app/composables/site.mjs +1 -1
  51. package/dist/runtime/app/composables/storage.d.ts +151 -11
  52. package/dist/runtime/app/composables/storage.mjs +291 -33
  53. package/dist/runtime/app/composables/turnstile.mjs +1 -1
  54. package/dist/runtime/app/composables/two-factor.mjs +1 -1
  55. package/dist/runtime/app/pages/devtools/agents.vue +716 -716
  56. package/dist/runtime/app/pages/devtools/analytics.vue +616 -616
  57. package/dist/runtime/app/pages/devtools/auth.vue +381 -350
  58. package/dist/runtime/app/pages/devtools/blob.vue +743 -744
  59. package/dist/runtime/app/pages/devtools/db.vue +545 -545
  60. package/dist/runtime/app/pages/devtools/domains.vue +771 -771
  61. package/dist/runtime/app/pages/devtools/kv.vue +827 -828
  62. package/dist/runtime/app/pages/devtools/logs.vue +649 -653
  63. package/dist/runtime/app/pages/devtools/mail.vue +388 -388
  64. package/dist/runtime/app/pages/devtools/overview.vue +391 -389
  65. package/dist/runtime/app/pages/devtools/realtime.vue +89 -27
  66. package/dist/runtime/app/pages/devtools/security.vue +20 -5
  67. package/dist/runtime/app/pages/devtools/settings.vue +559 -559
  68. package/dist/runtime/app/pages/devtools/tasks.vue +26 -10
  69. package/dist/runtime/app/pages/devtools.vue +176 -176
  70. package/dist/runtime/app/plugins/seo.mjs +1 -1
  71. package/dist/runtime/app/plugins/shortcuts.client.d.ts +1 -4
  72. package/dist/runtime/app/public/sw-notifications.mjs +47 -52
  73. package/dist/runtime/blob.mjs +11 -4
  74. package/dist/runtime/browser.d.ts +1 -1
  75. package/dist/runtime/browser.mjs +12 -2
  76. package/dist/runtime/cache.d.ts +2 -1
  77. package/dist/runtime/kv.mjs +4 -1
  78. package/dist/runtime/providers/qarpeo.d.ts +3 -3
  79. package/dist/runtime/server/durable-objects/agent.mjs +1 -1
  80. package/dist/runtime/server/durable-objects/room.d.ts +2 -2
  81. package/dist/runtime/server/durable-objects/room.mjs +5 -5
  82. package/dist/runtime/server/middleware/devtools.mjs +6 -2
  83. package/dist/runtime/server/plugins/cms.d.ts +4 -2
  84. package/dist/runtime/server/plugins/dev-proxy.mjs +1 -1
  85. package/dist/runtime/server/routes/__qarpeo/agents/chat.post.d.ts +2 -2
  86. package/dist/runtime/server/routes/__qarpeo/agents/chat.post.mjs +4 -1
  87. package/dist/runtime/server/routes/__qarpeo/analytics/events.get.d.ts +1 -4
  88. package/dist/runtime/server/routes/__qarpeo/analytics/summary.get.d.ts +2 -2
  89. package/dist/runtime/server/routes/__qarpeo/analytics/summary.get.mjs +5 -1
  90. package/dist/runtime/server/routes/__qarpeo/db/tables.get.d.ts +2 -2
  91. package/dist/runtime/server/routes/__qarpeo/db/tables.get.mjs +1 -1
  92. package/dist/runtime/server/routes/__qarpeo/logs.get.d.ts +4 -1
  93. package/dist/runtime/server/routes/__qarpeo/mail/track/click/[id].get.mjs +1 -1
  94. package/dist/runtime/server/routes/__qarpeo/mail/track/open/[id].get.mjs +2 -2
  95. package/dist/runtime/server/routes/__qarpeo/overview.get.d.ts +2 -2
  96. package/dist/runtime/server/routes/__qarpeo/realtime/broadcast.post.d.ts +2 -2
  97. package/dist/runtime/server/routes/__qarpeo/realtime/broadcast.post.mjs +1 -1
  98. package/dist/runtime/server/routes/__qarpeo/realtime/clear.post.d.ts +1 -4
  99. package/dist/runtime/server/routes/__qarpeo/realtime/clear.post.mjs +1 -1
  100. package/dist/runtime/server/routes/__qarpeo/realtime/disconnect.post.d.ts +1 -4
  101. package/dist/runtime/server/routes/__qarpeo/realtime/disconnect.post.mjs +1 -1
  102. package/dist/runtime/server/routes/__qarpeo/realtime/room.get.d.ts +2 -2
  103. package/dist/runtime/server/routes/__qarpeo/realtime/rooms.get.d.ts +2 -2
  104. package/dist/runtime/server/routes/__qarpeo/security/analytics.get.d.ts +2 -2
  105. package/dist/runtime/server/routes/__qarpeo/security/ban.post.d.ts +1 -4
  106. package/dist/runtime/server/routes/__qarpeo/security/clear.post.d.ts +1 -4
  107. package/dist/runtime/server/routes/__qarpeo/security/unban.post.d.ts +1 -4
  108. package/dist/runtime/server/routes/__qarpeo/settings.get.mjs +1 -1
  109. package/dist/runtime/server/routes/__qarpeo/tasks/run.post.mjs +3 -1
  110. package/dist/runtime/server/routes/agents/[agent]/chat.post.mjs +8 -2
  111. package/dist/runtime/server/routes/agents/[agent]/clear.post.mjs +8 -2
  112. package/dist/runtime/server/routes/agents/[agent]/history.get.mjs +8 -2
  113. package/dist/runtime/server/routes/ai/embed.post.d.ts +1 -4
  114. package/dist/runtime/server/routes/ai/search.post.d.ts +2 -2
  115. package/dist/runtime/server/routes/auth/account.delete.mjs +1 -1
  116. package/dist/runtime/server/routes/auth/handler.mjs +6 -1
  117. package/dist/runtime/server/routes/auth/magic-link/verify.get.mjs +1 -1
  118. package/dist/runtime/server/routes/auth/organization/members/[id].delete.mjs +7 -1
  119. package/dist/runtime/server/routes/auth/otp/verify.post.mjs +1 -1
  120. package/dist/runtime/server/routes/auth/sso/login.get.mjs +7 -1
  121. package/dist/runtime/server/routes/auth/sso/oidc/callback.get.mjs +8 -2
  122. package/dist/runtime/server/routes/auth/sso/saml/acs.post.mjs +7 -2
  123. package/dist/runtime/server/routes/auth/webauthn/login/options.post.mjs +1 -1
  124. package/dist/runtime/server/routes/auth/webauthn/login/verify.post.mjs +7 -2
  125. package/dist/runtime/server/routes/auth/webauthn/register/options.post.mjs +6 -1
  126. package/dist/runtime/server/routes/auth/webauthn/register/verify.post.mjs +6 -1
  127. package/dist/runtime/server/routes/browser/crawl.post.d.ts +1 -2
  128. package/dist/runtime/server/routes/browser/invoice.post.d.ts +1 -2
  129. package/dist/runtime/server/routes/browser/og-image.post.d.ts +2 -2
  130. package/dist/runtime/server/routes/browser/pdf.post.d.ts +1 -2
  131. package/dist/runtime/server/routes/browser/pdf.post.mjs +6 -1
  132. package/dist/runtime/server/routes/browser/screenshot.post.d.ts +2 -2
  133. package/dist/runtime/server/routes/browser/screenshot.post.mjs +5 -1
  134. package/dist/runtime/server/routes/cms/components/index.get.d.ts +2 -2
  135. package/dist/runtime/server/routes/cms/preview/disable.get.d.ts +4 -3
  136. package/dist/runtime/server/routes/cms/preview/enable.get.d.ts +8 -8
  137. package/dist/runtime/server/routes/cms/search.get.mjs +1 -1
  138. package/dist/runtime/server/routes/cms/webhooks/[provider].post.d.ts +7 -7
  139. package/dist/runtime/server/routes/cms/webhooks/[provider].post.mjs +9 -2
  140. package/dist/runtime/server/routes/docs/search.get.d.ts +9 -9
  141. package/dist/runtime/server/routes/fate.mjs +5 -8
  142. package/dist/runtime/server/routes/mail/bounce.post.d.ts +2 -2
  143. package/dist/runtime/server/routes/mail/unsubscribe.d.ts +2 -2
  144. package/dist/runtime/server/routes/mail/webhooks.post.d.ts +2 -2
  145. package/dist/runtime/server/routes/mail/webhooks.post.mjs +7 -1
  146. package/dist/runtime/server/routes/payments/usage.get.d.ts +8 -8
  147. package/dist/runtime/server/routes/payments/usage.post.d.ts +2 -2
  148. package/dist/runtime/server/routes/realtime/history.delete.d.ts +4 -3
  149. package/dist/runtime/server/routes/realtime/history.get.d.ts +7 -6
  150. package/dist/runtime/server/routes/realtime/ws.get.mjs +6 -1
  151. package/dist/runtime/server/routes/robots.txt.get.mjs +1 -1
  152. package/dist/runtime/server/routes/sitemap.xml.get.mjs +2 -1
  153. package/dist/runtime/server/routes/storage/multipart/abort.post.d.ts +2 -2
  154. package/dist/runtime/server/routes/storage/multipart/complete.post.d.ts +2 -2
  155. package/dist/runtime/server/routes/storage/multipart/complete.post.mjs +2 -2
  156. package/dist/runtime/server/routes/storage/multipart/create.post.d.ts +2 -2
  157. package/dist/runtime/server/routes/storage/multipart/create.post.mjs +7 -3
  158. package/dist/runtime/server/routes/storage/multipart/part.put.d.ts +2 -2
  159. package/dist/runtime/server/routes/storage/multipart/part.put.mjs +1 -1
  160. package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/index.delete.mjs +2 -4
  161. package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/verify.post.mjs +2 -4
  162. package/dist/runtime/server/routes/tenants/[tenant]/domains/index.get.mjs +1 -1
  163. package/dist/runtime/server/routes/tenants/[tenant]/domains/index.post.mjs +2 -4
  164. package/dist/runtime/server/tasks/cms/publish.mjs +1 -1
  165. package/dist/runtime/server/utils/ai.d.ts +9 -9
  166. package/dist/runtime/server/utils/ai.mjs +3 -3
  167. package/dist/runtime/server/utils/auth.d.ts +12 -16
  168. package/dist/runtime/server/utils/auth.mjs +15 -9
  169. package/dist/runtime/server/utils/bots.mjs +21 -7
  170. package/dist/runtime/server/utils/browser-utils.d.ts +44 -41
  171. package/dist/runtime/server/utils/browser-utils.mjs +14 -4
  172. package/dist/runtime/server/utils/cache.d.ts +5 -5
  173. package/dist/runtime/server/utils/cms/common.d.ts +26 -0
  174. package/dist/runtime/server/utils/cms/common.mjs +68 -0
  175. package/dist/runtime/server/utils/cms/git.d.ts +24 -0
  176. package/dist/runtime/server/utils/cms/git.mjs +240 -0
  177. package/dist/runtime/server/utils/cms/markdown.d.ts +22 -0
  178. package/dist/runtime/server/utils/cms/markdown.mjs +92 -0
  179. package/dist/runtime/server/utils/cms/path.d.ts +51 -0
  180. package/dist/runtime/server/utils/cms/path.mjs +127 -0
  181. package/dist/runtime/server/utils/cms/search.d.ts +22 -0
  182. package/dist/runtime/server/utils/cms/search.mjs +221 -0
  183. package/dist/runtime/server/utils/cms-events.d.ts +1 -1
  184. package/dist/runtime/server/utils/cms-events.mjs +2 -2
  185. package/dist/runtime/server/utils/cms-filter.mjs +2 -2
  186. package/dist/runtime/server/utils/cms.d.ts +17 -149
  187. package/dist/runtime/server/utils/cms.mjs +52 -761
  188. package/dist/runtime/server/utils/config.d.ts +5 -4
  189. package/dist/runtime/server/utils/domains.mjs +7 -4
  190. package/dist/runtime/server/utils/email-templates.d.ts +10 -7
  191. package/dist/runtime/server/utils/email-templates.mjs +20 -5
  192. package/dist/runtime/server/utils/feed.d.ts +2 -2
  193. package/dist/runtime/server/utils/feed.mjs +3 -1
  194. package/dist/runtime/server/utils/mail-suppression.d.ts +8 -24
  195. package/dist/runtime/server/utils/mail-suppression.mjs +2 -2
  196. package/dist/runtime/server/utils/mail.d.ts +7 -8
  197. package/dist/runtime/server/utils/mail.mjs +17 -12
  198. package/dist/runtime/server/utils/multipart-store.d.ts +2 -2
  199. package/dist/runtime/server/utils/notifications.d.ts +9 -23
  200. package/dist/runtime/server/utils/organization.mjs +4 -12
  201. package/dist/runtime/server/utils/passwordless.mjs +1 -1
  202. package/dist/runtime/server/utils/payments.d.ts +2 -6
  203. package/dist/runtime/server/utils/payments.mjs +1 -1
  204. package/dist/runtime/server/utils/queue.d.ts +21 -31
  205. package/dist/runtime/server/utils/rag.d.ts +4 -4
  206. package/dist/runtime/server/utils/rag.mjs +8 -8
  207. package/dist/runtime/server/utils/realtime-store.d.ts +2 -2
  208. package/dist/runtime/server/utils/realtime.d.ts +26 -28
  209. package/dist/runtime/server/utils/scheduled-task.d.ts +1 -3
  210. package/dist/runtime/server/utils/security-store.d.ts +2 -2
  211. package/dist/runtime/server/utils/session.d.ts +9 -11
  212. package/dist/runtime/server/utils/sso.d.ts +9 -15
  213. package/dist/runtime/server/utils/sso.mjs +4 -8
  214. package/dist/runtime/server/utils/storage.d.ts +19 -2
  215. package/dist/runtime/server/utils/storage.mjs +36 -7
  216. package/dist/runtime/server/utils/tenant.mjs +3 -1
  217. package/dist/runtime/server/utils/turnstile.d.ts +3 -5
  218. package/dist/runtime/server/utils/vapid.d.ts +5 -8
  219. package/dist/runtime/server/utils/vapid.mjs +26 -13
  220. package/dist/runtime/service.d.ts +13 -13
  221. package/dist/runtime/service.mjs +4 -2
  222. package/dist/runtime/test-utils.d.ts +20 -30
  223. package/dist/runtime/test-utils.mjs +5 -4
  224. package/dist/runtime/types/auth-globals.d.ts +14 -14
  225. package/dist/runtime/types/imports.d.ts +82 -82
  226. package/dist/runtime/types/index.d.ts +2 -2
  227. package/dist/runtime/types/r2.d.ts +5 -0
  228. package/dist/runtime/types/service.d.ts +11 -18
  229. package/dist/types.d.ts +100 -107
  230. package/dist/utils/auth-schema.d.ts +2 -2
  231. package/dist/utils/cms-sources.d.ts +3 -3
  232. package/dist/utils/local-db.d.ts +3 -3
  233. package/dist/utils/notifications-schema.d.ts +1 -3
  234. package/dist/utils/pkg.d.ts +7 -0
  235. package/dist/utils/queue.d.ts +3 -3
  236. package/dist/utils/tasks.d.ts +3 -2
  237. package/package.json +11 -8
@@ -1,22 +1,18 @@
1
1
  import { type RequestEvent } from "nuxt/server";
2
2
  /**
3
- * Returns a memoized Better Auth instance connected to Cloudflare D1 via Drizzle.
4
- * The instance is cached by secret value within the isolate lifetime to avoid
5
- * re-initialising plugins, adapters and crypto material on every request.
3
+ * Returns a memoized Better Auth instance connected to Cloudflare D1 via Drizzle. The instance is
4
+ * cached by secret value within the isolate lifetime to avoid re-initialising plugins, adapters and
5
+ * crypto material on every request.
6
6
  *
7
- * In production, if no auth secret is configured the server will refuse to start
8
- * rather than silently falling back to a publicly-known placeholder value.
7
+ * In production, if no auth secret is configured the server will refuse to start rather than
8
+ * silently falling back to a publicly-known placeholder value.
9
9
  */
10
10
  export declare function serverAuth(event?: RequestEvent): any;
11
11
  export declare const createAuth: typeof serverAuth;
12
12
  export declare const useServerAuth: typeof serverAuth;
13
- /**
14
- * Fetches the current session from Better Auth on the server.
15
- */
13
+ /** Fetches the current session from Better Auth on the server. */
16
14
  export declare function getServerSession(event: RequestEvent): Promise<any>;
17
- /**
18
- * Throws 401 if user is unauthenticated.
19
- */
15
+ /** Throws 401 if user is unauthenticated. */
20
16
  export declare function requireServerSession(event: RequestEvent): Promise<any>;
21
17
  import type { QarpeoSession } from "../../types/auth";
22
18
  /** Ensures Better Auth core tables (user, account, session, verification, etc.) exist in D1. */
@@ -58,17 +54,17 @@ export interface DeleteAccountOptions {
58
54
  cascadeOrg?: boolean;
59
55
  }
60
56
  /**
61
- * Permanently deletes a user account and purges all related sessions, OAuth accounts,
62
- * 2FA credentials, WebAuthn authenticators, API tokens, and notification records.
63
- * Throws 400 if user is sole owner of an organization and cascadeOrg is not specified.
57
+ * Permanently deletes a user account and purges all related sessions, OAuth accounts, 2FA
58
+ * credentials, WebAuthn authenticators, API tokens, and notification records. Throws 400 if user is
59
+ * sole owner of an organization and cascadeOrg is not specified.
64
60
  */
65
61
  export declare function deleteUserAccount(event: RequestEvent, userId: string, options?: DeleteAccountOptions): Promise<{
66
62
  success: boolean;
67
63
  userId: string;
68
64
  }>;
69
65
  /**
70
- * Evaluates whether Multi-Factor Authentication is required for a user
71
- * based on user 2FA enrollment and global/organization MFA policies.
66
+ * Evaluates whether Multi-Factor Authentication is required for a user based on user 2FA enrollment
67
+ * and global/organization MFA policies.
72
68
  */
73
69
  export declare function resolveMfaStatus(d1: any, user: {
74
70
  id: string;
@@ -1,8 +1,8 @@
1
- import { betterAuth } from "better-auth";
2
1
  import { drizzleAdapter } from "@better-auth/drizzle-adapter";
2
+ import { betterAuth } from "better-auth";
3
3
  import { createError } from "nuxt/server";
4
- import { useDrizzle } from "./drizzle.mjs";
5
4
  import * as authSchema from "#qarpeo/auth/schema";
5
+ import { useDrizzle } from "./drizzle.mjs";
6
6
  const _authCache = /* @__PURE__ */ new Map();
7
7
  export function serverAuth(event) {
8
8
  const cfEnv = event?.context?.cloudflare?.env;
@@ -232,7 +232,9 @@ export async function ensureAuthTables(d1) {
232
232
  d1.prepare(`CREATE INDEX IF NOT EXISTS account_user_id_idx ON account(user_id)`),
233
233
  d1.prepare(`CREATE INDEX IF NOT EXISTS member_user_id_idx ON member(user_id)`),
234
234
  d1.prepare(`CREATE INDEX IF NOT EXISTS member_org_id_idx ON member(organization_id)`),
235
- d1.prepare(`CREATE INDEX IF NOT EXISTS _qarpeo_api_tokens_user_id_idx ON _qarpeo_api_tokens(user_id)`)
235
+ d1.prepare(
236
+ `CREATE INDEX IF NOT EXISTS _qarpeo_api_tokens_user_id_idx ON _qarpeo_api_tokens(user_id)`
237
+ )
236
238
  ]);
237
239
  try {
238
240
  await d1.prepare(`
@@ -289,15 +291,15 @@ export async function handleOAuthSuccess({
289
291
  let dbUser = null;
290
292
  let isNew = false;
291
293
  if (d1 && profile.providerAccountId) {
292
- const existingAccount = await d1.prepare(
293
- "SELECT * FROM account WHERE provider_id = ? AND account_id = ? LIMIT 1"
294
- ).bind(provider, profile.providerAccountId).first();
294
+ const existingAccount = await d1.prepare("SELECT * FROM account WHERE provider_id = ? AND account_id = ? LIMIT 1").bind(provider, profile.providerAccountId).first();
295
295
  const encryptedAccessToken = tokens?.access_token ? await encryptToken(tokens.access_token, event) : null;
296
296
  const encryptedRefreshToken = tokens?.refresh_token ? await encryptToken(tokens.refresh_token, event) : null;
297
297
  if (existingAccount) {
298
298
  dbUser = await d1.prepare("SELECT * FROM user WHERE id = ? LIMIT 1").bind(existingAccount.user_id).first();
299
299
  if (dbUser) {
300
- await d1.prepare("UPDATE account SET access_token = ?, refresh_token = ?, updated_at = ? WHERE id = ?").bind(encryptedAccessToken, encryptedRefreshToken, now, existingAccount.id).run();
300
+ await d1.prepare(
301
+ "UPDATE account SET access_token = ?, refresh_token = ?, updated_at = ? WHERE id = ?"
302
+ ).bind(encryptedAccessToken, encryptedRefreshToken, now, existingAccount.id).run();
301
303
  await d1.prepare("UPDATE user SET updated_at = ? WHERE id = ?").bind(now, dbUser.id).run();
302
304
  }
303
305
  }
@@ -421,10 +423,14 @@ export async function deleteUserAccount(event, userId, options = {}) {
421
423
  d1 = null;
422
424
  }
423
425
  if (d1) {
424
- const memberships = await d1.prepare("SELECT m.organization_id, m.role, o.name as org_name FROM member m LEFT JOIN organization o ON m.organization_id = o.id WHERE m.user_id = ? AND m.role = 'owner'").bind(userId).all();
426
+ const memberships = await d1.prepare(
427
+ "SELECT m.organization_id, m.role, o.name as org_name FROM member m LEFT JOIN organization o ON m.organization_id = o.id WHERE m.user_id = ? AND m.role = 'owner'"
428
+ ).bind(userId).all();
425
429
  const ownedOrgs = memberships.results || [];
426
430
  for (const org of ownedOrgs) {
427
- const otherOwners = await d1.prepare("SELECT COUNT(*) as count FROM member WHERE organization_id = ? AND role = 'owner' AND user_id != ?").bind(org.organization_id, userId).first();
431
+ const otherOwners = await d1.prepare(
432
+ "SELECT COUNT(*) as count FROM member WHERE organization_id = ? AND role = 'owner' AND user_id != ?"
433
+ ).bind(org.organization_id, userId).first();
428
434
  const otherOwnerCount = Number(otherOwners?.count || 0);
429
435
  if (otherOwnerCount === 0) {
430
436
  if (options.cascadeOrg) {
@@ -5,8 +5,8 @@ import {
5
5
  createError
6
6
  } from "nuxt/server";
7
7
  import { getCloudflareEnv } from "../../bindings.mjs";
8
- import { timingSafeEqualString } from "./crypto.mjs";
9
8
  import { useAgent } from "./ai.mjs";
9
+ import { timingSafeEqualString } from "./crypto.mjs";
10
10
  async function computeHmacSha256Hex(secret, data) {
11
11
  const encoder = new TextEncoder();
12
12
  const key = await crypto.subtle.importKey(
@@ -51,7 +51,9 @@ export async function verifyDiscordSignature(publicKeyHex, timestamp, body, sign
51
51
  const dataBytes = new TextEncoder().encode(timestamp + body);
52
52
  let key;
53
53
  try {
54
- key = await crypto.subtle.importKey("raw", keyBytes, { name: "Ed25519" }, false, ["verify"]);
54
+ key = await crypto.subtle.importKey("raw", keyBytes, { name: "Ed25519" }, false, [
55
+ "verify"
56
+ ]);
55
57
  } catch {
56
58
  key = await crypto.subtle.importKey(
57
59
  "raw",
@@ -61,7 +63,12 @@ export async function verifyDiscordSignature(publicKeyHex, timestamp, body, sign
61
63
  ["verify"]
62
64
  );
63
65
  }
64
- return await crypto.subtle.verify({ name: key.algorithm.name }, key, sigBytes, dataBytes);
66
+ return await crypto.subtle.verify(
67
+ { name: key.algorithm.name },
68
+ key,
69
+ sigBytes,
70
+ dataBytes
71
+ );
65
72
  } catch {
66
73
  return false;
67
74
  }
@@ -399,9 +406,11 @@ export function defineBotHandler(config) {
399
406
  switch (config.provider) {
400
407
  case "telegram": {
401
408
  const token = config.botToken || env.TELEGRAM_BOT_TOKEN || globalThis.process?.env?.TELEGRAM_BOT_TOKEN;
402
- if (!token) throw new Error("[defineBotHandler] TELEGRAM_BOT_TOKEN is required to send replies");
409
+ if (!token)
410
+ throw new Error("[defineBotHandler] TELEGRAM_BOT_TOKEN is required to send replies");
403
411
  const targetChatId = message?.chatId || payload.chat_id || payload.chat?.id;
404
- if (!targetChatId) throw new Error("[defineBotHandler] Chat ID not found for Telegram reply");
412
+ if (!targetChatId)
413
+ throw new Error("[defineBotHandler] Chat ID not found for Telegram reply");
405
414
  return await sendTelegramMessage(token, targetChatId, text, opts);
406
415
  }
407
416
  case "slack": {
@@ -419,10 +428,15 @@ export function defineBotHandler(config) {
419
428
  const token = config.botToken || env.WHATSAPP_ACCESS_TOKEN || globalThis.process?.env?.WHATSAPP_ACCESS_TOKEN;
420
429
  const phoneId = config.phoneNumberId || env.WHATSAPP_PHONE_NUMBER_ID || globalThis.process?.env?.WHATSAPP_PHONE_NUMBER_ID;
421
430
  if (!token || !phoneId) {
422
- throw new Error("[defineBotHandler] WHATSAPP_ACCESS_TOKEN and WHATSAPP_PHONE_NUMBER_ID are required to send replies");
431
+ throw new Error(
432
+ "[defineBotHandler] WHATSAPP_ACCESS_TOKEN and WHATSAPP_PHONE_NUMBER_ID are required to send replies"
433
+ );
423
434
  }
424
435
  const to = message?.chatId;
425
- if (!to) throw new Error("[defineBotHandler] Recipient phone number not found for WhatsApp reply");
436
+ if (!to)
437
+ throw new Error(
438
+ "[defineBotHandler] Recipient phone number not found for WhatsApp reply"
439
+ );
426
440
  return await sendWhatsAppMessage(token, phoneId, to, text);
427
441
  }
428
442
  case "discord": {
@@ -1,10 +1,9 @@
1
1
  /**
2
2
  * Cloudflare Browser Rendering High-Level Utilities
3
3
  *
4
- * Provides ergonomic wrappers around the Cloudflare Browser Rendering binding
5
- * for the most common headless-browser operations: screenshot, PDF generation,
6
- * and page crawling. Each function gracefully falls back to a minimal dev-mode
7
- * stub when the BROWSER binding is not available.
4
+ * Provides ergonomic wrappers around the Cloudflare Browser Rendering binding for the most common
5
+ * headless-browser operations: screenshot, PDF generation, and page crawling. Each function
6
+ * gracefully falls back to a minimal dev-mode stub when the BROWSER binding is not available.
8
7
  */
9
8
  export type ImageFormat = "png" | "jpeg" | "webp";
10
9
  export interface ScreenshotOptions {
@@ -162,9 +161,9 @@ export interface PdfResult {
162
161
  * Falls back to a minimal mock PNG in development when the BROWSER binding is unavailable.
163
162
  *
164
163
  * @example
165
- * // In a server route
166
- * const { data, contentType } = await captureScreenshot("https://example.com")
167
- * return new Response(data, { headers: { "Content-Type": contentType } })
164
+ * // In a server route
165
+ * const { data, contentType } = await captureScreenshot("https://example.com")
166
+ * return new Response(data, { headers: { "Content-Type": contentType } })
168
167
  */
169
168
  export declare function captureScreenshot(urlOrHtml: string, options?: ScreenshotOptions): Promise<ScreenshotResult>;
170
169
  /**
@@ -173,56 +172,60 @@ export declare function captureScreenshot(urlOrHtml: string, options?: Screensho
173
172
  * Falls back to a minimal valid mock PDF in development when the BROWSER binding is unavailable.
174
173
  *
175
174
  * @example
176
- * const { data } = await generatePdf("https://example.com/invoice/123")
177
- * return new Response(data, {
178
- * headers: { "Content-Type": "application/pdf", "Content-Disposition": 'attachment; filename="invoice.pdf"' }
179
- * })
175
+ * const { data } = await generatePdf("https://example.com/invoice/123")
176
+ * return new Response(data, {
177
+ * headers: {
178
+ * "Content-Type": "application/pdf",
179
+ * "Content-Disposition": 'attachment; filename="invoice.pdf"',
180
+ * },
181
+ * })
180
182
  */
181
183
  export declare function generatePdf(urlOrHtml: string, options?: PdfOptions): Promise<PdfResult>;
182
184
  /**
183
- * Recursively crawls a website starting from `startUrl`, extracting text content
184
- * and links from each visited page.
185
+ * Recursively crawls a website starting from `startUrl`, extracting text content and links from
186
+ * each visited page.
185
187
  *
186
188
  * Falls back to a single mock page result in development when the BROWSER binding is unavailable.
187
189
  *
188
190
  * @example
189
- * const { pages } = await crawlPage("https://docs.example.com", { maxPages: 20 })
190
- * const corpus = pages.map(p => p.text).join("\n\n")
191
+ * const { pages } = await crawlPage("https://docs.example.com", { maxPages: 20 })
192
+ * const corpus = pages.map((p) => p.text).join("\n\n")
191
193
  */
192
194
  export declare function crawlPage(startUrl: string, options?: CrawlOptions): Promise<CrawlResult>;
193
195
  /**
194
- * Generates an on-demand dynamic OpenGraph (OG) social card image (1200×630)
195
- * on Cloudflare Edge using headless browser rendering.
196
+ * Generates an on-demand dynamic OpenGraph (OG) social card image (1200×630) on Cloudflare Edge
197
+ * using headless browser rendering.
196
198
  *
197
199
  * @example
198
- * ```ts
199
- * const { data, contentType } = await renderOgSocialCard({
200
- * title: "Building Microservices on Cloudflare",
201
- * description: "Fast RPC, Durable Objects, and Vectorize on the Edge",
202
- * siteName: "Qarpeo",
203
- * theme: "dark",
204
- * })
205
- * return new Response(data, { headers: { "Content-Type": contentType } })
206
- * ```
200
+ * ;```ts
201
+ * const { data, contentType } = await renderOgSocialCard({
202
+ * title: "Building Microservices on Cloudflare",
203
+ * description: "Fast RPC, Durable Objects, and Vectorize on the Edge",
204
+ * siteName: "Qarpeo",
205
+ * theme: "dark",
206
+ * })
207
+ * return new Response(data, { headers: { "Content-Type": contentType } })
208
+ * ```
207
209
  */
208
210
  export declare function renderOgSocialCard(options: OgSocialCardOptions): Promise<ScreenshotResult>;
209
211
  /**
210
- * Generates a clean, professional PDF invoice on-demand on the edge using Cloudflare Browser Rendering.
212
+ * Generates a clean, professional PDF invoice on-demand on the edge using Cloudflare Browser
213
+ * Rendering.
211
214
  *
212
215
  * @example
213
- * ```ts
214
- * const { data } = await generateInvoicePdf({
215
- * invoiceNumber: "INV-2026-0042",
216
- * issueDate: "2026-11-11",
217
- * seller: { name: "Acme Cloud Corp", email: "billing@acme.com" },
218
- * customer: { name: "Client Studios", email: "finance@client.com" },
219
- * items: [
220
- * { description: "Edge Compute (Million Requests)", quantity: 50, unitPrice: 0.5 },
221
- * { description: "Vectorize Storage (GB/mo)", quantity: 10, unitPrice: 5 },
222
- * ],
223
- * currency: "$",
224
- * taxPercent: 10,
225
- * })
226
- * ```
216
+ * ;```ts
217
+ * const { data } = await generateInvoicePdf({
218
+ * invoiceNumber: "INV-2026-0042",
219
+ * issueDate: "2026-11-11",
220
+ * seller: { name: "Acme Cloud Corp", email: "billing@acme.com" },
221
+ * customer: { name: "Client Studios", email: "finance@client.com" },
222
+ * items: [
223
+ * { description: "Edge Compute (Million Requests)", quantity: 50, unitPrice: 0.5 },
224
+ * { description: "Vectorize Storage (GB/mo)", quantity: 10, unitPrice: 5 },
225
+ * ],
226
+ * currency: "$",
227
+ * taxPercent: 10,
228
+ * })
229
+ * ```
227
230
  */
228
231
  export declare function generateInvoicePdf(options: GenerateInvoiceOptions): Promise<PdfResult>;
@@ -13,7 +13,11 @@ function getBrowserBinding(name = "BROWSER") {
13
13
  }
14
14
  async function loadPuppeteer() {
15
15
  try {
16
- const mod = await import("@cloudflare/puppeteer");
16
+ const modName = "@cloudflare/puppeteer";
17
+ const mod = await import(
18
+ /* @vite-ignore */
19
+ modName
20
+ );
17
21
  return mod.default || mod;
18
22
  } catch {
19
23
  return null;
@@ -247,7 +251,10 @@ export async function renderOgSocialCard(options) {
247
251
  const bgStyle = theme === "light" ? "background: #ffffff; color: #0f172a;" : theme === "gradient" ? `background: linear-gradient(135deg, #090d16 0%, #1e1b4b 50%, #0f172a 100%); color: #f8fafc;` : "background: #090d16; color: #f8fafc;";
248
252
  const borderStyle = theme === "light" ? "border-color: #e2e8f0;" : "border-color: rgba(255,255,255,0.1);";
249
253
  const descColor = theme === "light" ? "color: #64748b;" : "color: #94a3b8;";
250
- const escapeHtml = (str) => str.replace(/[&<>'"]/g, (tag) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", "'": "&#39;", '"': "&quot;" })[tag] || tag);
254
+ const escapeHtml = (str) => str.replace(
255
+ /[&<>'"]/g,
256
+ (tag) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", "'": "&#39;", '"': "&quot;" })[tag] || tag
257
+ );
251
258
  const html = `<!DOCTYPE html>
252
259
  <html>
253
260
  <head>
@@ -366,13 +373,16 @@ export async function generateInvoicePdf(options) {
366
373
  dueDate,
367
374
  seller,
368
375
  customer,
369
- items = [],
376
+ items,
370
377
  currency = "$",
371
378
  taxPercent = 0,
372
379
  notes,
373
380
  ...pdfOpts
374
381
  } = options;
375
- const escapeHtml = (str) => str.replace(/[&<>'"]/g, (tag) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", "'": "&#39;", '"': "&quot;" })[tag] || tag);
382
+ const escapeHtml = (str) => str.replace(
383
+ /[&<>'"]/g,
384
+ (tag) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", "'": "&#39;", '"': "&quot;" })[tag] || tag
385
+ );
376
386
  const subtotal = items.reduce((acc, item) => acc + item.quantity * item.unitPrice, 0);
377
387
  const taxAmount = subtotal * taxPercent / 100;
378
388
  const grandTotal = subtotal + taxAmount;
@@ -24,14 +24,14 @@ export declare function purgeCache(pattern?: string): Promise<string[]>;
24
24
  * Purge all cache items associated with one or more semantic cache tags.
25
25
  *
26
26
  * @example
27
- * ```ts
28
- * await purgeCacheTag("posts", "author:123")
29
- * ```
27
+ * ;```ts
28
+ * await purgeCacheTag("posts", "author:123")
29
+ * ```
30
30
  */
31
31
  export declare function purgeCacheTag(...tags: string[]): Promise<string[]>;
32
32
  /**
33
- * Remember and cache the result of an async computation or database query.
34
- * Supports Time-To-Live (TTL), Stale-While-Revalidate (SWR), and semantic Cache Tags.
33
+ * Remember and cache the result of an async computation or database query. Supports Time-To-Live
34
+ * (TTL), Stale-While-Revalidate (SWR), and semantic Cache Tags.
35
35
  *
36
36
  * @param key Unique cache key (e.g. 'dashboard:stats')
37
37
  * @param ttlOrOptions Duration (number | string) or options object { ttl, swr, tags }
@@ -0,0 +1,26 @@
1
+ import { type RequestEvent } from "nuxt/server";
2
+ import type { CMSOptions, CMSCollectionConfig, CMSGitHubConfig, CMSDeployTriggerConfig, CMSApprovalConfig } from "../../../../types";
3
+ export declare function getCMSDb(event?: RequestEvent): any;
4
+ export declare function nanoid(size?: number): string;
5
+ export declare function getCMSConfig(event?: RequestEvent): Omit<Required<CMSOptions>, "github" | "deploy" | "approval" | "exclude" | "webhookSecret"> & {
6
+ collections: Record<string, CMSCollectionConfig>;
7
+ github?: CMSGitHubConfig;
8
+ deploy?: CMSDeployTriggerConfig;
9
+ approval?: boolean | CMSApprovalConfig;
10
+ exclude?: string | string[];
11
+ webhookSecret?: string;
12
+ };
13
+ /**
14
+ * Resolves the effective approval workflow configuration for a collection. Returns null if approval
15
+ * is disabled for the collection.
16
+ */
17
+ export declare function resolveCollectionApproval(collectionConfig?: CMSCollectionConfig, globalApproval?: boolean | CMSApprovalConfig): CMSApprovalConfig | null;
18
+ /**
19
+ * Computes a hex SHA-256 digest of the given text using Web Crypto. Used for deterministic change
20
+ * detection in the hybrid sync engine.
21
+ */
22
+ export declare function computeContentHash(text: string): Promise<string>;
23
+ /** Resolves the active tenant ID for CMS scoping from the current event context. */
24
+ export declare function getCMSTenantId(event: RequestEvent): string | null;
25
+ /** Returns the tenant key prefix (e.g. 'tenant_123:') for namespacing KV caches. */
26
+ export declare function getCMSTenantPrefix(event: RequestEvent): string;
@@ -0,0 +1,68 @@
1
+ import { useRuntimeConfig } from "nuxt/server";
2
+ import { getD1Binding } from "../../../db.mjs";
3
+ export function getCMSDb(event) {
4
+ try {
5
+ return getD1Binding("DB", event);
6
+ } catch {
7
+ return null;
8
+ }
9
+ }
10
+ export function nanoid(size = 21) {
11
+ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
12
+ const bytes = crypto.getRandomValues(new Uint8Array(size));
13
+ return Array.from(bytes, (b) => chars[b % chars.length]).join("");
14
+ }
15
+ export function getCMSConfig(event) {
16
+ const rc = useRuntimeConfig(event);
17
+ const cfg = rc?.qarpeo?.cms || {};
18
+ return {
19
+ api: cfg.api === true,
20
+ apiPath: cfg.apiPath || "/api/cms",
21
+ contentDir: cfg.contentDir || "content",
22
+ hybrid: cfg.hybrid !== false,
23
+ roles: cfg.roles || ["admin", "editor"],
24
+ revisions: cfg.revisions || { max: 10 },
25
+ cache: cfg.cache !== false,
26
+ collections: cfg.collections || {},
27
+ components: cfg.components || {},
28
+ sources: cfg.sources || [],
29
+ exclude: cfg.exclude || void 0,
30
+ github: cfg.github || void 0,
31
+ deploy: cfg.deploy || void 0,
32
+ webhooks: cfg.webhooks || [],
33
+ webhookSecret: cfg.webhookSecret || void 0,
34
+ approval: cfg.approval || void 0,
35
+ scheduledPublish: cfg.scheduledPublish ?? false,
36
+ shiki: cfg.shiki !== void 0 ? cfg.shiki : true,
37
+ plugins: cfg.plugins || {},
38
+ locales: cfg.locales || ["en"],
39
+ defaultLocale: cfg.defaultLocale || "en"
40
+ };
41
+ }
42
+ export function resolveCollectionApproval(collectionConfig, globalApproval) {
43
+ const raw = collectionConfig?.approval ?? globalApproval;
44
+ if (!raw) return null;
45
+ if (typeof raw === "object") {
46
+ return {
47
+ roles: raw.roles && raw.roles.length > 0 ? raw.roles : ["admin"],
48
+ allowSelfApproval: raw.allowSelfApproval ?? false
49
+ };
50
+ }
51
+ return {
52
+ roles: ["admin"],
53
+ allowSelfApproval: false
54
+ };
55
+ }
56
+ export async function computeContentHash(text) {
57
+ const enc = new TextEncoder();
58
+ const buf = await crypto.subtle.digest("SHA-256", enc.encode(text));
59
+ return Array.from(new Uint8Array(buf)).map((b) => b.toString(16).padStart(2, "0")).join("");
60
+ }
61
+ export function getCMSTenantId(event) {
62
+ const tenantId = event?.context?.tenant?.id || event?.context?.tenantId || event?.context?.organizationId || event?.context?.orgId || null;
63
+ return tenantId ? String(tenantId) : null;
64
+ }
65
+ export function getCMSTenantPrefix(event) {
66
+ const tenantId = getCMSTenantId(event);
67
+ return tenantId ? `${tenantId}:` : "";
68
+ }
@@ -0,0 +1,24 @@
1
+ import type { RequestEvent } from "nuxt/server";
2
+ import type { CMSEntry } from "../../../../types";
3
+ export interface GitSyncResult {
4
+ filePath?: string;
5
+ contentHash?: string;
6
+ localFs?: boolean;
7
+ github?: {
8
+ ok: boolean;
9
+ commitSha?: string;
10
+ prUrl?: string;
11
+ error?: string;
12
+ };
13
+ }
14
+ export declare function registerEntryFormatter(fn: (entry: CMSEntry | Record<string, any>) => string): void;
15
+ /**
16
+ * Synchronizes a CMS entry modification back to Git / filesystem when mode is 'git-sync'.
17
+ *
18
+ * - In local dev (Node.js): Writes or deletes the markdown file on local disk and updates D1
19
+ * content_hash.
20
+ * - In production (or when GitHub repo is configured): Commits directly or opens a PR via GitHub API.
21
+ */
22
+ export declare function syncEntryToGit(event: RequestEvent, collectionId: string, entry: CMSEntry | Record<string, any>, action: "create" | "update" | "delete" | "publish"): Promise<GitSyncResult | null>;
23
+ /** Validates a GitHub webhook signature against a known secret. */
24
+ export declare function verifyGitHubSignature(rawBody: string, signatureHeader: string | null | undefined, secret: string): Promise<boolean>;