qarpeo 0.2.1 → 0.3.1

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 (260) hide show
  1. package/dist/chunks/tools.mjs +993 -31
  2. package/dist/cli/index.mjs +1071 -31
  3. package/dist/fate/index.d.ts +9 -1
  4. package/dist/fate/index.mjs +20 -3
  5. package/dist/module.mjs +296 -750
  6. package/dist/runtime/browser.mjs +2 -2
  7. package/dist/runtime/comments-server.d.ts +3 -0
  8. package/dist/runtime/comments-server.mjs +2 -0
  9. package/dist/runtime/comments.d.ts +0 -2
  10. package/dist/runtime/comments.mjs +0 -2
  11. package/dist/runtime/db.d.ts +10 -9
  12. package/dist/runtime/db.mjs +79 -8
  13. package/dist/runtime/drizzle.mjs +21 -6
  14. package/dist/runtime/index.d.ts +4 -0
  15. package/dist/runtime/realtime-server.d.ts +4 -0
  16. package/dist/runtime/realtime-server.mjs +13 -0
  17. package/dist/runtime/realtime.d.ts +1 -4
  18. package/dist/runtime/realtime.mjs +0 -13
  19. package/dist/runtime/replica.d.ts +27 -0
  20. package/dist/runtime/replica.mjs +229 -0
  21. package/dist/runtime/server/durable-objects/agent.mjs +14 -2
  22. package/dist/runtime/server/durable-objects/room.d.ts +10 -0
  23. package/dist/runtime/server/durable-objects/room.mjs +119 -28
  24. package/dist/runtime/server/middleware/devtools.mjs +1 -1
  25. package/dist/runtime/server/middleware/tenancy.mjs +7 -4
  26. package/dist/runtime/server/plugins/store.mjs +1 -1
  27. package/dist/runtime/server/routes/__qarpeo/mail/track/click/[id].get.mjs +57 -17
  28. package/dist/runtime/server/routes/agents/[agent]/chat.post.mjs +19 -12
  29. package/dist/runtime/server/routes/agents/[agent]/clear.post.mjs +8 -9
  30. package/dist/runtime/server/routes/agents/[agent]/history.get.mjs +8 -9
  31. package/dist/runtime/server/routes/analytics/events.get.mjs +12 -2
  32. package/dist/runtime/server/routes/analytics/pageviews.get.mjs +10 -1
  33. package/dist/runtime/server/routes/analytics/summary.get.mjs +10 -1
  34. package/dist/runtime/server/routes/auth/2fa/disable.post.mjs +11 -2
  35. package/dist/runtime/server/routes/auth/2fa/setup.post.mjs +7 -0
  36. package/dist/runtime/server/routes/auth/2fa/verify.post.mjs +11 -2
  37. package/dist/runtime/server/routes/auth/account.delete.mjs +7 -0
  38. package/dist/runtime/server/routes/auth/magic-link/verify.get.mjs +5 -3
  39. package/dist/runtime/server/routes/auth/organization/sso/index.post.mjs +10 -0
  40. package/dist/runtime/server/routes/auth/otp/verify.post.mjs +5 -3
  41. package/dist/runtime/server/routes/auth/sso/saml/acs.post.mjs +18 -0
  42. package/dist/runtime/server/routes/auth/webauthn/login/options.post.d.ts +1 -1
  43. package/dist/runtime/server/routes/auth/webauthn/login/options.post.mjs +11 -2
  44. package/dist/runtime/server/routes/auth/webauthn/login/verify.post.mjs +10 -1
  45. package/dist/runtime/server/routes/auth/webauthn/register/options.post.d.ts +1 -1
  46. package/dist/runtime/server/routes/auth/webauthn/register/options.post.mjs +10 -1
  47. package/dist/runtime/server/routes/auth/webauthn/register/verify.post.mjs +10 -1
  48. package/dist/runtime/server/routes/browser/crawl.post.mjs +13 -0
  49. package/dist/runtime/server/routes/browser/invoice.post.mjs +15 -1
  50. package/dist/runtime/server/routes/browser/og-image.post.mjs +13 -0
  51. package/dist/runtime/server/routes/browser/pdf.post.mjs +15 -1
  52. package/dist/runtime/server/routes/browser/screenshot.post.mjs +13 -0
  53. package/dist/runtime/server/routes/cms/[collection]/[id]/preview-token.post.mjs +23 -8
  54. package/dist/runtime/server/routes/cms/[collection]/[id]/publish.post.mjs +2 -1
  55. package/dist/runtime/server/routes/cms/[collection]/[id]/review.post.mjs +2 -1
  56. package/dist/runtime/server/routes/cms/[collection]/[id]/revisions/[revId]/restore.post.mjs +2 -1
  57. package/dist/runtime/server/routes/cms/[collection]/[id].delete.mjs +2 -1
  58. package/dist/runtime/server/routes/cms/[collection]/[id].put.mjs +2 -1
  59. package/dist/runtime/server/routes/cms/[collection]/index.post.mjs +2 -1
  60. package/dist/runtime/server/routes/cms/categories/[id].delete.mjs +2 -1
  61. package/dist/runtime/server/routes/cms/categories/[id].put.mjs +2 -1
  62. package/dist/runtime/server/routes/cms/categories.post.mjs +2 -1
  63. package/dist/runtime/server/routes/cms/collections/[id].delete.mjs +2 -1
  64. package/dist/runtime/server/routes/cms/collections/[id].put.mjs +2 -1
  65. package/dist/runtime/server/routes/cms/collections/index.post.mjs +2 -1
  66. package/dist/runtime/server/routes/cms/export.post.mjs +1 -1
  67. package/dist/runtime/server/routes/cms/subscribers/[id].delete.mjs +2 -1
  68. package/dist/runtime/server/routes/cms/subscribers/[id].patch.mjs +2 -1
  69. package/dist/runtime/server/routes/cms/tags/[id].delete.mjs +2 -1
  70. package/dist/runtime/server/routes/cms/tags.post.mjs +2 -1
  71. package/dist/runtime/server/routes/comments/[id]/react.post.mjs +7 -3
  72. package/dist/runtime/server/routes/comments/[id]/report.post.mjs +3 -0
  73. package/dist/runtime/server/routes/comments/[id].delete.mjs +1 -1
  74. package/dist/runtime/server/routes/comments/[id].get.mjs +13 -0
  75. package/dist/runtime/server/routes/comments/[id].patch.mjs +1 -1
  76. package/dist/runtime/server/routes/fate.d.ts +6 -0
  77. package/dist/runtime/server/routes/fate.mjs +32 -3
  78. package/dist/runtime/server/routes/mail/bounce.post.mjs +14 -2
  79. package/dist/runtime/server/routes/mail/unsubscribe.mjs +2 -1
  80. package/dist/runtime/server/routes/mail/webhooks.post.mjs +18 -4
  81. package/dist/runtime/server/routes/notifications/[id].get.mjs +3 -4
  82. package/dist/runtime/server/routes/notifications/index.get.mjs +4 -2
  83. package/dist/runtime/server/routes/notifications/push/subscribe.post.mjs +3 -1
  84. package/dist/runtime/server/routes/notifications/push/unsubscribe.post.mjs +5 -3
  85. package/dist/runtime/server/routes/notifications/read-all.post.mjs +6 -2
  86. package/dist/runtime/server/routes/notifications/send.post.mjs +13 -2
  87. package/dist/runtime/server/routes/payments/cancel.post.mjs +1 -1
  88. package/dist/runtime/server/routes/payments/change-plan.post.mjs +1 -1
  89. package/dist/runtime/server/routes/payments/checkout.post.mjs +1 -1
  90. package/dist/runtime/server/routes/payments/pause.post.mjs +1 -1
  91. package/dist/runtime/server/routes/payments/portal.post.mjs +1 -1
  92. package/dist/runtime/server/routes/payments/subscription.get.mjs +1 -1
  93. package/dist/runtime/server/routes/payments/usage.get.mjs +1 -1
  94. package/dist/runtime/server/routes/payments/usage.post.mjs +1 -1
  95. package/dist/runtime/server/routes/payments/webhook.post.mjs +8 -1
  96. package/dist/runtime/server/routes/realtime/broadcast.post.mjs +3 -2
  97. package/dist/runtime/server/routes/realtime/history.delete.mjs +2 -2
  98. package/dist/runtime/server/routes/realtime/history.get.mjs +2 -2
  99. package/dist/runtime/server/routes/realtime/presence.get.mjs +3 -3
  100. package/dist/runtime/server/routes/realtime/state.get.mjs +3 -3
  101. package/dist/runtime/server/routes/realtime/state.post.mjs +13 -4
  102. package/dist/runtime/server/routes/realtime/ws.get.mjs +2 -2
  103. package/dist/runtime/server/routes/storage/file/[...key].delete.mjs +1 -1
  104. package/dist/runtime/server/routes/storage/file/[...key].get.mjs +7 -0
  105. package/dist/runtime/server/routes/storage/files.get.d.ts +1 -1
  106. package/dist/runtime/server/routes/storage/files.get.mjs +24 -4
  107. package/dist/runtime/server/routes/storage/multipart/abort.post.mjs +16 -1
  108. package/dist/runtime/server/routes/storage/multipart/complete.post.d.ts +1 -1
  109. package/dist/runtime/server/routes/storage/multipart/complete.post.mjs +15 -1
  110. package/dist/runtime/server/routes/storage/multipart/create.post.mjs +7 -0
  111. package/dist/runtime/server/routes/storage/multipart/part.put.mjs +15 -1
  112. package/dist/runtime/server/routes/storage/presigned-r2.post.mjs +8 -1
  113. package/dist/runtime/server/routes/storage/presigned.post.d.ts +1 -1
  114. package/dist/runtime/server/routes/storage/presigned.post.mjs +8 -1
  115. package/dist/runtime/server/routes/storage/sign.post.mjs +7 -0
  116. package/dist/runtime/server/routes/storage/upload.post.d.ts +2 -2
  117. package/dist/runtime/server/routes/store/cart/index.delete.mjs +3 -4
  118. package/dist/runtime/server/routes/store/cart/index.get.mjs +3 -10
  119. package/dist/runtime/server/routes/store/cart/items/[id].delete.mjs +6 -4
  120. package/dist/runtime/server/routes/store/cart/items/[id].patch.mjs +12 -4
  121. package/dist/runtime/server/routes/store/cart/items.post.mjs +9 -10
  122. package/dist/runtime/server/routes/store/categories/index.get.mjs +4 -2
  123. package/dist/runtime/server/routes/store/checkout.post.mjs +13 -3
  124. package/dist/runtime/server/routes/store/coupons/apply.post.mjs +6 -5
  125. package/dist/runtime/server/routes/store/orders/[id].get.mjs +2 -2
  126. package/dist/runtime/server/routes/store/orders/download/[token].get.mjs +6 -3
  127. package/dist/runtime/server/routes/store/orders/index.get.mjs +1 -1
  128. package/dist/runtime/server/routes/store/products/[slug].get.mjs +2 -2
  129. package/dist/runtime/server/routes/store/products/index.get.mjs +1 -1
  130. package/dist/runtime/server/routes/store/tax/calculate.post.mjs +10 -0
  131. package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/index.delete.mjs +26 -25
  132. package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/verify.post.mjs +26 -25
  133. package/dist/runtime/server/utils/ai.d.ts +6 -0
  134. package/dist/runtime/server/utils/ai.mjs +12 -2
  135. package/dist/runtime/server/utils/analytics-query.mjs +8 -4
  136. package/dist/runtime/server/utils/browser-utils.d.ts +9 -0
  137. package/dist/runtime/server/utils/browser-utils.mjs +135 -0
  138. package/dist/runtime/server/utils/cms/cache.d.ts +13 -0
  139. package/dist/runtime/server/utils/cms/cache.mjs +95 -0
  140. package/dist/runtime/server/utils/cms/common.mjs +1 -1
  141. package/dist/runtime/server/utils/cms/markdown.mjs +38 -8
  142. package/dist/runtime/server/utils/cms/mutations.d.ts +26 -0
  143. package/dist/runtime/server/utils/cms/mutations.mjs +569 -0
  144. package/dist/runtime/server/utils/cms/path.d.ts +8 -0
  145. package/dist/runtime/server/utils/cms/path.mjs +23 -0
  146. package/dist/runtime/server/utils/cms/queries.d.ts +27 -0
  147. package/dist/runtime/server/utils/cms/queries.mjs +366 -0
  148. package/dist/runtime/server/utils/cms/references.d.ts +48 -0
  149. package/dist/runtime/server/utils/cms/references.mjs +309 -0
  150. package/dist/runtime/server/utils/cms/revisions.d.ts +7 -0
  151. package/dist/runtime/server/utils/cms/revisions.mjs +60 -0
  152. package/dist/runtime/server/utils/cms/sync.mjs +3 -3
  153. package/dist/runtime/server/utils/cms.d.ts +5 -82
  154. package/dist/runtime/server/utils/cms.mjs +28 -1367
  155. package/dist/runtime/server/utils/comments.d.ts +11 -0
  156. package/dist/runtime/server/utils/comments.mjs +65 -17
  157. package/dist/runtime/server/utils/crypto.mjs +1 -1
  158. package/dist/runtime/server/utils/domains.mjs +9 -0
  159. package/dist/runtime/server/utils/drizzle.d.ts +26 -1
  160. package/dist/runtime/server/utils/drizzle.mjs +78 -19
  161. package/dist/runtime/server/utils/email-inbound.mjs +9 -1
  162. package/dist/runtime/server/utils/impersonation.mjs +58 -1
  163. package/dist/runtime/server/utils/lock.d.ts +11 -0
  164. package/dist/runtime/server/utils/lock.mjs +4 -0
  165. package/dist/runtime/server/utils/mail-suppression.mjs +48 -13
  166. package/dist/runtime/server/utils/mail.d.ts +2 -1
  167. package/dist/runtime/server/utils/mail.mjs +17 -11
  168. package/dist/runtime/server/utils/notifications.d.ts +13 -4
  169. package/dist/runtime/server/utils/notifications.mjs +20 -4
  170. package/dist/runtime/server/utils/organization.mjs +36 -1
  171. package/dist/runtime/server/utils/passwordless.mjs +8 -0
  172. package/dist/runtime/server/utils/payments/checkout.d.ts +34 -0
  173. package/dist/runtime/server/utils/payments/checkout.mjs +158 -0
  174. package/dist/runtime/server/utils/payments/common.d.ts +45 -0
  175. package/dist/runtime/server/utils/payments/common.mjs +234 -0
  176. package/dist/runtime/server/utils/payments/index.d.ts +9 -0
  177. package/dist/runtime/server/utils/payments/index.mjs +21 -0
  178. package/dist/runtime/server/utils/payments/lemonsqueezy.d.ts +7 -0
  179. package/dist/runtime/server/utils/payments/lemonsqueezy.mjs +55 -0
  180. package/dist/runtime/server/utils/payments/paddle.d.ts +7 -0
  181. package/dist/runtime/server/utils/payments/paddle.mjs +92 -0
  182. package/dist/runtime/server/utils/payments/polar.d.ts +11 -0
  183. package/dist/runtime/server/utils/payments/polar.mjs +66 -0
  184. package/dist/runtime/server/utils/payments/stripe.d.ts +7 -0
  185. package/dist/runtime/server/utils/payments/stripe.mjs +159 -0
  186. package/dist/runtime/server/utils/payments/subscriptions.d.ts +89 -0
  187. package/dist/runtime/server/utils/payments/subscriptions.mjs +236 -0
  188. package/dist/runtime/server/utils/payments/usage.d.ts +12 -0
  189. package/dist/runtime/server/utils/payments/usage.mjs +143 -0
  190. package/dist/runtime/server/utils/payments/webhooks.d.ts +10 -0
  191. package/dist/runtime/server/utils/payments/webhooks.mjs +200 -0
  192. package/dist/runtime/server/utils/payments.d.ts +1 -158
  193. package/dist/runtime/server/utils/payments.mjs +1 -1289
  194. package/dist/runtime/server/utils/queue.d.ts +2 -0
  195. package/dist/runtime/server/utils/queue.mjs +34 -21
  196. package/dist/runtime/server/utils/rag.mjs +30 -17
  197. package/dist/runtime/server/utils/realtime.d.ts +5 -1
  198. package/dist/runtime/server/utils/realtime.mjs +43 -7
  199. package/dist/runtime/server/utils/session.mjs +16 -3
  200. package/dist/runtime/server/utils/sso.d.ts +3 -0
  201. package/dist/runtime/server/utils/sso.mjs +43 -0
  202. package/dist/runtime/server/utils/storage.mjs +12 -1
  203. package/dist/runtime/server/utils/store/cart.d.ts +63 -0
  204. package/dist/runtime/server/utils/store/cart.mjs +542 -0
  205. package/dist/runtime/server/utils/store/checkout.d.ts +14 -0
  206. package/dist/runtime/server/utils/store/checkout.mjs +118 -0
  207. package/dist/runtime/server/utils/store/common.d.ts +29 -0
  208. package/dist/runtime/server/utils/store/common.mjs +479 -0
  209. package/dist/runtime/server/utils/store/index.d.ts +7 -0
  210. package/dist/runtime/server/utils/store/index.mjs +30 -0
  211. package/dist/runtime/server/utils/store/inventory.d.ts +25 -0
  212. package/dist/runtime/server/utils/store/inventory.mjs +190 -0
  213. package/dist/runtime/server/utils/store/orders.d.ts +60 -0
  214. package/dist/runtime/server/utils/store/orders.mjs +590 -0
  215. package/dist/runtime/server/utils/store/products.d.ts +35 -0
  216. package/dist/runtime/server/utils/store/products.mjs +461 -0
  217. package/dist/runtime/server/utils/store/vendor.d.ts +18 -0
  218. package/dist/runtime/server/utils/store/vendor.mjs +68 -0
  219. package/dist/runtime/server/utils/store.d.ts +1 -207
  220. package/dist/runtime/server/utils/store.mjs +1 -2227
  221. package/dist/runtime/server/utils/string.d.ts +1 -1
  222. package/dist/runtime/server/utils/string.mjs +12 -4
  223. package/dist/runtime/server/utils/tenant.mjs +19 -5
  224. package/dist/runtime/server/utils/tracker.mjs +2 -0
  225. package/dist/runtime/server.d.ts +3 -3
  226. package/dist/runtime/server.mjs +4 -4
  227. package/dist/runtime/storage-server.d.ts +2 -0
  228. package/dist/runtime/storage-server.mjs +1 -0
  229. package/dist/runtime/storage.d.ts +1 -1
  230. package/dist/runtime/storage.mjs +0 -1
  231. package/dist/runtime/store.d.ts +0 -1
  232. package/dist/runtime/store.mjs +0 -1
  233. package/dist/runtime/test-utils.d.ts +4 -0
  234. package/dist/runtime/test-utils.mjs +54 -0
  235. package/dist/runtime/types/d1.d.ts +43 -0
  236. package/dist/runtime/types/drizzle.d.ts +6 -0
  237. package/dist/runtime/types/store.d.ts +1 -1
  238. package/dist/types/analytics.d.ts +80 -0
  239. package/dist/types/auth.d.ts +282 -0
  240. package/dist/types/cache.d.ts +55 -0
  241. package/dist/types/comments.d.ts +130 -0
  242. package/dist/types/db.d.ts +29 -0
  243. package/dist/types/email.d.ts +182 -0
  244. package/dist/types/index.d.ts +22 -0
  245. package/dist/types/jobs.d.ts +58 -0
  246. package/dist/types/notifications.d.ts +77 -0
  247. package/dist/types/options.d.ts +363 -0
  248. package/dist/types/payments.d.ts +145 -0
  249. package/dist/types/ratelimit.d.ts +71 -0
  250. package/dist/types/realtime.d.ts +136 -0
  251. package/dist/types/site.d.ts +121 -0
  252. package/dist/types/storage.d.ts +164 -0
  253. package/dist/types/store-options.d.ts +199 -0
  254. package/dist/types/tenant.d.ts +100 -0
  255. package/dist/types.d.ts +1 -2174
  256. package/dist/utils/migration-lock.d.ts +139 -0
  257. package/dist/utils/pkg.d.ts +14 -1
  258. package/dist/utils/schema-diff.d.ts +39 -0
  259. package/package.json +55 -17
  260. package/dist/chunks/auth-schema.mjs +0 -364
@@ -1,364 +0,0 @@
1
- import { useRuntimeConfig } from 'nuxt/server';
2
-
3
- function getQarpeoConfig(event) {
4
- let rc;
5
- try {
6
- rc = useRuntimeConfig(event);
7
- } catch {
8
- rc = void 0;
9
- }
10
- if (!rc || !rc.qarpeo) {
11
- rc = globalThis.__NUXT_RUNTIME_CONFIG__ || rc || {};
12
- }
13
- const q = event?.context?.qarpeo || rc?.qarpeo || {};
14
- return {
15
- auth: q.auth || {},
16
- blob: q.blob || q.storage || {},
17
- storage: q.storage || q.blob || {},
18
- cms: q.cms || {},
19
- comments: q.comments || {},
20
- payments: q.payments || {},
21
- ratelimit: q.ratelimit || {},
22
- realtime: q.realtime || {},
23
- mail: q.mail || {},
24
- analytics: q.analytics || {},
25
- multitenant: q.multitenant || {},
26
- store: q.store || {},
27
- agents: q.agents || {},
28
- jobs: q.jobs || {},
29
- ...q
30
- };
31
- }
32
-
33
- function getTablePrefix(event, explicitPrefix) {
34
- let prefix = explicitPrefix;
35
- if (prefix === void 0) {
36
- try {
37
- const cfg = getQarpeoConfig(event);
38
- if (cfg) {
39
- prefix = cfg.tablePrefix ?? cfg.prefix;
40
- }
41
- } catch {
42
- }
43
- }
44
- if (prefix === void 0 && typeof process !== "undefined" && process?.env) {
45
- const envVal = process.env.QARPEO_TABLE_PREFIX;
46
- if (envVal === "1" || envVal === "true") {
47
- prefix = true;
48
- } else if (envVal && envVal !== "0" && envVal !== "false") {
49
- prefix = envVal;
50
- }
51
- }
52
- if (!prefix || prefix === false) return "";
53
- if (prefix === true) return "qarpeo_";
54
- return typeof prefix === "string" && prefix.endsWith("_") ? prefix : `${prefix}_`;
55
- }
56
- function getTableOverrides(event) {
57
- try {
58
- const cfg = getQarpeoConfig(event);
59
- if (cfg?.tables && typeof cfg.tables === "object") {
60
- return cfg.tables;
61
- }
62
- } catch {
63
- }
64
- if (typeof process !== "undefined" && process?.env?.QARPEO_TABLES) {
65
- try {
66
- return JSON.parse(process.env.QARPEO_TABLES);
67
- } catch {
68
- }
69
- }
70
- return {};
71
- }
72
- function toCamelCase(str) {
73
- return str.replace(/_([a-z0-9])/g, (_, letter) => letter.toUpperCase());
74
- }
75
- function resolveTableName(baseName, prefixOrEventOrOptions, event) {
76
- let explicitPrefix;
77
- let tablesMap;
78
- let effectiveEvent = event;
79
- if (typeof prefixOrEventOrOptions === "object" && prefixOrEventOrOptions !== null && !("req" in prefixOrEventOrOptions && "res" in prefixOrEventOrOptions)) {
80
- const opts = prefixOrEventOrOptions;
81
- explicitPrefix = opts.tablePrefix ?? opts.prefix;
82
- tablesMap = opts.tables;
83
- } else if (typeof prefixOrEventOrOptions === "boolean" || typeof prefixOrEventOrOptions === "string") {
84
- explicitPrefix = prefixOrEventOrOptions;
85
- } else if (prefixOrEventOrOptions) {
86
- effectiveEvent = prefixOrEventOrOptions;
87
- }
88
- const runtimeOverrides = getTableOverrides(effectiveEvent);
89
- const mergedTables = { ...runtimeOverrides, ...tablesMap || {} };
90
- const camelKey = toCamelCase(baseName);
91
- const override = mergedTables[baseName] || mergedTables[camelKey];
92
- if (override) {
93
- return override;
94
- }
95
- const p = getTablePrefix(effectiveEvent, explicitPrefix);
96
- return `${p}${baseName}`;
97
- }
98
- function resolveIndexName(tableName, suffix) {
99
- return `idx_${tableName}_${suffix}`;
100
- }
101
-
102
- const ALL_AUTH_TABLE_NAMES = [
103
- "user",
104
- "account",
105
- "session",
106
- "verification",
107
- "twoFactor",
108
- "passkey",
109
- "organization",
110
- "member",
111
- "invitation",
112
- "auditLogs"
113
- ];
114
- function getActiveAuthTableNames(auth, prefixOrOptions) {
115
- if (!auth) return [];
116
- const opts = typeof auth === "object" ? auth : {};
117
- const tables = [
118
- resolveTableName("user", prefixOrOptions),
119
- resolveTableName("account", prefixOrOptions),
120
- resolveTableName("session", prefixOrOptions),
121
- resolveTableName("verification", prefixOrOptions),
122
- resolveTableName("audit_log", prefixOrOptions)
123
- ];
124
- if (opts.twoFactor) tables.push(resolveTableName("two_factor", prefixOrOptions));
125
- if (opts.webauthn || opts.webAuthn) tables.push(resolveTableName("passkey", prefixOrOptions));
126
- if (opts.organizations) {
127
- tables.push(
128
- resolveTableName("organization", prefixOrOptions),
129
- resolveTableName("member", prefixOrOptions),
130
- resolveTableName("invitation", prefixOrOptions)
131
- );
132
- }
133
- return tables;
134
- }
135
- function compileExtendedField(key, def) {
136
- switch (def.type) {
137
- case "string": {
138
- let chain = `text("${key}")`;
139
- if (def.default !== void 0) chain += `.default(${JSON.stringify(def.default)})`;
140
- if (def.nullable === false) chain += `.notNull()`;
141
- return ` ${key}: ${chain},`;
142
- }
143
- case "number": {
144
- let chain = `integer("${key}")`;
145
- if (def.default !== void 0) chain += `.default(${Number(def.default)})`;
146
- if (def.nullable === false) chain += `.notNull()`;
147
- return ` ${key}: ${chain},`;
148
- }
149
- case "boolean": {
150
- let chain = `integer("${key}", { mode: "boolean" })`;
151
- if (def.default !== void 0) chain += `.default(${def.default ? 1 : 0})`;
152
- return ` ${key}: ${chain},`;
153
- }
154
- case "json": {
155
- return ` ${key}: text("${key}", { mode: "json" }),`;
156
- }
157
- default:
158
- return ` ${key}: text("${key}"),`;
159
- }
160
- }
161
- function generateAuthSchema(auth, prefixOrOptions) {
162
- const opts = typeof auth === "object" ? auth : {};
163
- const extendsFields = opts.fields?.extends || {};
164
- const userTbl = resolveTableName("user", prefixOrOptions);
165
- const sessionTbl = resolveTableName("session", prefixOrOptions);
166
- const accountTbl = resolveTableName("account", prefixOrOptions);
167
- const verificationTbl = resolveTableName("verification", prefixOrOptions);
168
- const auditLogTbl = resolveTableName("audit_log", prefixOrOptions);
169
- const twoFactorTbl = resolveTableName("two_factor", prefixOrOptions);
170
- const passkeyTbl = resolveTableName("passkey", prefixOrOptions);
171
- const organizationTbl = resolveTableName("organization", prefixOrOptions);
172
- const memberTbl = resolveTableName("member", prefixOrOptions);
173
- const invitationTbl = resolveTableName("invitation", prefixOrOptions);
174
- const lines = [
175
- `// Auto-generated by Qarpeo for Better Auth on Cloudflare D1`,
176
- `// snakeCase.table maps camelCase property names \u2192 snake_case column names automatically`,
177
- `import { sql } from "drizzle-orm";
178
- import { snakeCase, text, integer, blob, index } from "drizzle-orm/sqlite-core";`,
179
- ``,
180
- `// \u2500\u2500\u2500 1. User Table \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
181
- `export const user = snakeCase.table("${userTbl}", {`,
182
- ` id: text("id").primaryKey(),`,
183
- ` name: text("name").notNull(),`,
184
- ` email: text("email").notNull().unique(),`,
185
- ` emailVerified: integer("email_verified", { mode: "boolean" }).notNull().default(false),`,
186
- ` image: text("image"),`
187
- ];
188
- if (!extendsFields.role) {
189
- lines.push(` role: text("role").default("user"),`);
190
- }
191
- for (const [key, fieldDef] of Object.entries(extendsFields)) {
192
- lines.push(compileExtendedField(key, fieldDef));
193
- }
194
- lines.push(
195
- ` createdAt: integer("created_at", { mode: "timestamp_ms" }).notNull().default(sql\`(cast(unixepoch('subsecond') * 1000 as integer))\`),`,
196
- ` updatedAt: integer("updated_at", { mode: "timestamp_ms" }).notNull().default(sql\`(cast(unixepoch('subsecond') * 1000 as integer))\`).$onUpdate(() => new Date()),`,
197
- `});`,
198
- `export const users = user;`,
199
- ``,
200
- `// \u2500\u2500\u2500 2. Session Table \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
201
- `export const session = snakeCase.table("${sessionTbl}", {`,
202
- ` id: text("id").primaryKey(),`,
203
- ` expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),`,
204
- ` token: text("token").notNull().unique(),`,
205
- ` createdAt: integer("created_at", { mode: "timestamp_ms" }).notNull().default(sql\`(cast(unixepoch('subsecond') * 1000 as integer))\`),`,
206
- ` updatedAt: integer("updated_at", { mode: "timestamp_ms" }).notNull().default(sql\`(cast(unixepoch('subsecond') * 1000 as integer))\`).$onUpdate(() => new Date()),`,
207
- ` ipAddress: text("ip_address"),`,
208
- ` userAgent: text("user_agent"),`,
209
- ` userId: text("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),`,
210
- `}, (table) => [`,
211
- ` index("${resolveIndexName(sessionTbl, "user_id")}").on(table.userId),`,
212
- ` index("${resolveIndexName(sessionTbl, "token")}").on(table.token),`,
213
- `]);`,
214
- `export const sessions = session;`,
215
- ``,
216
- `// \u2500\u2500\u2500 3. Account Table (OAuth & Passwords) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
217
- `export const account = snakeCase.table("${accountTbl}", {`,
218
- ` id: text("id").primaryKey(),`,
219
- ` accountId: text("account_id").notNull(),`,
220
- ` providerId: text("provider_id").notNull(),`,
221
- ` userId: text("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),`,
222
- ` accessToken: text("access_token"),`,
223
- ` refreshToken: text("refresh_token"),`,
224
- ` idToken: text("id_token"),`,
225
- ` accessTokenExpiresAt: integer("access_token_expires_at", { mode: "timestamp_ms" }),`,
226
- ` refreshTokenExpiresAt: integer("refresh_token_expires_at", { mode: "timestamp_ms" }),`,
227
- ` scope: text("scope"),`,
228
- ` password: text("password"),`,
229
- ` createdAt: integer("created_at", { mode: "timestamp_ms" }).notNull().default(sql\`(cast(unixepoch('subsecond') * 1000 as integer))\`),`,
230
- ` updatedAt: integer("updated_at", { mode: "timestamp_ms" }).notNull().default(sql\`(cast(unixepoch('subsecond') * 1000 as integer))\`).$onUpdate(() => new Date()),`,
231
- `}, (table) => [`,
232
- ` index("${resolveIndexName(accountTbl, "user_id")}").on(table.userId),`,
233
- `]);`,
234
- `export const accounts = account;`,
235
- ``,
236
- `// \u2500\u2500\u2500 4. Verification Table (Tokens & OTP) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
237
- `export const verification = snakeCase.table("${verificationTbl}", {`,
238
- ` id: text("id").primaryKey(),`,
239
- ` identifier: text("identifier").notNull(),`,
240
- ` value: text("value").notNull(),`,
241
- ` expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),`,
242
- ` createdAt: integer("created_at", { mode: "timestamp_ms" }),`,
243
- ` updatedAt: integer("updated_at", { mode: "timestamp_ms" }),`,
244
- `});`,
245
- `export const verifications = verification;`,
246
- ``,
247
- `// \u2500\u2500\u2500 5. Audit Logs Table \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
248
- `export const auditLogs = snakeCase.table("${auditLogTbl}", {`,
249
- ` id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()),`,
250
- ` userId: text("user_id"),`,
251
- ` action: text("action").notNull(),`,
252
- ` targetType: text("target_type"),`,
253
- ` targetId: text("target_id"),`,
254
- ` details: text("details", { mode: "json" }),`,
255
- ` ipAddress: text("ip_address"),`,
256
- ` userAgent: text("user_agent"),`,
257
- ` createdAt: integer("created_at", { mode: "timestamp_ms" })`,
258
- ` .notNull()`,
259
- ` .$defaultFn(() => new Date()),`,
260
- ` updatedAt: integer("updated_at", { mode: "timestamp_ms" })`,
261
- ` .notNull()`,
262
- ` .$defaultFn(() => new Date()),`,
263
- `}, (table) => [`,
264
- ` index("${resolveIndexName(auditLogTbl, "user_id")}").on(table.userId),`,
265
- ` index("${resolveIndexName(auditLogTbl, "action")}").on(table.action),`,
266
- ` index("${resolveIndexName(auditLogTbl, "target")}").on(table.targetType, table.targetId),`,
267
- ` index("${resolveIndexName(auditLogTbl, "created_at")}").on(table.createdAt),`,
268
- `]);`,
269
- `export const auditLog = auditLogs;`,
270
- `export { auditLogs as audit_logs };`
271
- );
272
- if (opts.twoFactor) {
273
- lines.push(
274
- ``,
275
- `// \u2500\u2500\u2500 6. Two-Factor Authentication Table (TOTP) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
276
- `export const twoFactor = snakeCase.table("${twoFactorTbl}", {`,
277
- ` id: text("id").primaryKey(),`,
278
- ` userId: text("user_id").notNull().unique().references(() => user.id, { onDelete: "cascade" }),`,
279
- ` secret: text("secret").notNull(),`,
280
- ` backupCodes: text("backup_codes").notNull(),`,
281
- ` createdAt: integer("created_at", { mode: "timestamp_ms" }).notNull().default(sql\`(cast(unixepoch('subsecond') * 1000 as integer))\`),`,
282
- `});`
283
- );
284
- }
285
- if (opts.webauthn || opts.webAuthn) {
286
- lines.push(
287
- ``,
288
- `// \u2500\u2500\u2500 7. Passkeys Table \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
289
- `export const passkey = snakeCase.table("${passkeyTbl}", {`,
290
- ` id: text("id").primaryKey(),`,
291
- ` name: text("name"),`,
292
- ` publicKey: text("public_key").notNull(),`,
293
- ` userId: text("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),`,
294
- ` credentialId: text("credential_id").notNull().unique(),`,
295
- ` counter: integer("counter").notNull().default(0),`,
296
- ` deviceType: text("device_type").notNull(),`,
297
- ` backedUp: integer("backed_up", { mode: "boolean" }).notNull().default(false),`,
298
- ` transports: text("transports"),`,
299
- ` createdAt: integer("created_at", { mode: "timestamp_ms" }).notNull().default(sql\`(cast(unixepoch('subsecond') * 1000 as integer))\`),`,
300
- `});`
301
- );
302
- }
303
- if (opts.organizations) {
304
- lines.push(
305
- ``,
306
- `// \u2500\u2500\u2500 8. Organizations & Members Tables \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
307
- `export const organization = snakeCase.table("${organizationTbl}", {`,
308
- ` id: text("id").primaryKey(),`,
309
- ` name: text("name").notNull(),`,
310
- ` slug: text("slug").notNull().unique(),`,
311
- ` logo: text("logo"),`,
312
- ` metadata: text("metadata"),`,
313
- ` createdAt: integer("created_at", { mode: "timestamp_ms" }).notNull().default(sql\`(cast(unixepoch('subsecond') * 1000 as integer))\`),`,
314
- `});`,
315
- `export const organizations = organization;`,
316
- ``,
317
- `export const member = snakeCase.table("${memberTbl}", {`,
318
- ` id: text("id").primaryKey(),`,
319
- ` organizationId: text("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),`,
320
- ` userId: text("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),`,
321
- ` role: text("role").notNull().default("member"),`,
322
- ` createdAt: integer("created_at", { mode: "timestamp_ms" }).notNull().default(sql\`(cast(unixepoch('subsecond') * 1000 as integer))\`),`,
323
- `});`,
324
- `export const members = member;`,
325
- ``,
326
- `export const invitation = snakeCase.table("${invitationTbl}", {`,
327
- ` id: text("id").primaryKey(),`,
328
- ` organizationId: text("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),`,
329
- ` email: text("email").notNull(),`,
330
- ` role: text("role").notNull().default("member"),`,
331
- ` status: text("status").notNull().default("pending"),`,
332
- ` expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),`,
333
- ` inviterId: text("inviter_id").notNull().references(() => user.id, { onDelete: "cascade" }),`,
334
- `});`,
335
- `export const invitations = invitation;`
336
- );
337
- }
338
- if (!opts.twoFactor) {
339
- lines.push(`export const twoFactor = undefined;`);
340
- }
341
- if (!opts.webauthn && !opts.webAuthn) {
342
- lines.push(`export const passkey = undefined;`);
343
- lines.push(`export const authenticators = undefined;`);
344
- } else {
345
- lines.push(`export { passkey as authenticators };`);
346
- }
347
- if (!opts.organizations) {
348
- lines.push(
349
- `export const organization = undefined;`,
350
- `export const member = undefined;`,
351
- `export const invitation = undefined;`
352
- );
353
- }
354
- return lines.join("\n") + "\n";
355
- }
356
-
357
- const authSchema = {
358
- __proto__: null,
359
- ALL_AUTH_TABLE_NAMES: ALL_AUTH_TABLE_NAMES,
360
- generateAuthSchema: generateAuthSchema,
361
- getActiveAuthTableNames: getActiveAuthTableNames
362
- };
363
-
364
- export { resolveIndexName as a, getActiveAuthTableNames as b, authSchema as c, generateAuthSchema as g, resolveTableName as r };