qarpeo 0.2.0 → 0.3.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.
- package/dist/chunks/tools.mjs +993 -31
- package/dist/cli/index.mjs +1102 -31
- package/dist/fate/index.d.ts +9 -1
- package/dist/fate/index.mjs +20 -3
- package/dist/module.mjs +296 -753
- package/dist/runtime/browser.mjs +2 -2
- package/dist/runtime/comments-server.d.ts +3 -0
- package/dist/runtime/comments-server.mjs +2 -0
- package/dist/runtime/comments.d.ts +0 -2
- package/dist/runtime/comments.mjs +0 -2
- package/dist/runtime/db.d.ts +10 -9
- package/dist/runtime/db.mjs +79 -8
- package/dist/runtime/drizzle.mjs +21 -6
- package/dist/runtime/index.d.ts +4 -0
- package/dist/runtime/realtime-server.d.ts +4 -0
- package/dist/runtime/realtime-server.mjs +13 -0
- package/dist/runtime/realtime.d.ts +1 -4
- package/dist/runtime/realtime.mjs +0 -13
- package/dist/runtime/replica.d.ts +27 -0
- package/dist/runtime/replica.mjs +229 -0
- package/dist/runtime/server/durable-objects/agent.mjs +14 -2
- package/dist/runtime/server/durable-objects/room.d.ts +10 -0
- package/dist/runtime/server/durable-objects/room.mjs +119 -28
- package/dist/runtime/server/middleware/devtools.mjs +1 -1
- package/dist/runtime/server/middleware/tenancy.mjs +7 -4
- package/dist/runtime/server/plugins/store.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/mail/track/click/[id].get.mjs +57 -17
- package/dist/runtime/server/routes/agents/[agent]/chat.post.mjs +19 -12
- package/dist/runtime/server/routes/agents/[agent]/clear.post.mjs +8 -9
- package/dist/runtime/server/routes/agents/[agent]/history.get.mjs +8 -9
- package/dist/runtime/server/routes/analytics/events.get.mjs +12 -2
- package/dist/runtime/server/routes/analytics/pageviews.get.mjs +10 -1
- package/dist/runtime/server/routes/analytics/summary.get.mjs +10 -1
- package/dist/runtime/server/routes/auth/2fa/disable.post.mjs +11 -2
- package/dist/runtime/server/routes/auth/2fa/setup.post.mjs +7 -0
- package/dist/runtime/server/routes/auth/2fa/verify.post.mjs +11 -2
- package/dist/runtime/server/routes/auth/account.delete.mjs +7 -0
- package/dist/runtime/server/routes/auth/magic-link/verify.get.mjs +5 -3
- package/dist/runtime/server/routes/auth/organization/sso/index.post.mjs +10 -0
- package/dist/runtime/server/routes/auth/otp/verify.post.mjs +5 -3
- package/dist/runtime/server/routes/auth/sso/saml/acs.post.mjs +18 -0
- package/dist/runtime/server/routes/auth/webauthn/login/options.post.d.ts +1 -1
- package/dist/runtime/server/routes/auth/webauthn/login/options.post.mjs +11 -2
- package/dist/runtime/server/routes/auth/webauthn/login/verify.post.mjs +10 -1
- package/dist/runtime/server/routes/auth/webauthn/register/options.post.d.ts +1 -1
- package/dist/runtime/server/routes/auth/webauthn/register/options.post.mjs +10 -1
- package/dist/runtime/server/routes/auth/webauthn/register/verify.post.mjs +10 -1
- package/dist/runtime/server/routes/browser/crawl.post.mjs +13 -0
- package/dist/runtime/server/routes/browser/invoice.post.mjs +15 -1
- package/dist/runtime/server/routes/browser/og-image.post.mjs +13 -0
- package/dist/runtime/server/routes/browser/pdf.post.mjs +15 -1
- package/dist/runtime/server/routes/browser/screenshot.post.mjs +13 -0
- package/dist/runtime/server/routes/cms/[collection]/[id]/preview-token.post.mjs +23 -8
- package/dist/runtime/server/routes/cms/[collection]/[id]/publish.post.mjs +2 -1
- package/dist/runtime/server/routes/cms/[collection]/[id]/review.post.mjs +2 -1
- package/dist/runtime/server/routes/cms/[collection]/[id]/revisions/[revId]/restore.post.mjs +2 -1
- package/dist/runtime/server/routes/cms/[collection]/[id].delete.mjs +2 -1
- package/dist/runtime/server/routes/cms/[collection]/[id].put.mjs +2 -1
- package/dist/runtime/server/routes/cms/[collection]/index.post.mjs +2 -1
- package/dist/runtime/server/routes/cms/categories/[id].delete.mjs +2 -1
- package/dist/runtime/server/routes/cms/categories/[id].put.mjs +2 -1
- package/dist/runtime/server/routes/cms/categories.post.mjs +2 -1
- package/dist/runtime/server/routes/cms/collections/[id].delete.mjs +2 -1
- package/dist/runtime/server/routes/cms/collections/[id].put.mjs +2 -1
- package/dist/runtime/server/routes/cms/collections/index.post.mjs +2 -1
- package/dist/runtime/server/routes/cms/export.post.mjs +1 -1
- package/dist/runtime/server/routes/cms/subscribers/[id].delete.mjs +2 -1
- package/dist/runtime/server/routes/cms/subscribers/[id].patch.mjs +2 -1
- package/dist/runtime/server/routes/cms/tags/[id].delete.mjs +2 -1
- package/dist/runtime/server/routes/cms/tags.post.mjs +2 -1
- package/dist/runtime/server/routes/comments/[id]/react.post.mjs +7 -3
- package/dist/runtime/server/routes/comments/[id]/report.post.mjs +3 -0
- package/dist/runtime/server/routes/comments/[id].delete.mjs +1 -1
- package/dist/runtime/server/routes/comments/[id].get.mjs +13 -0
- package/dist/runtime/server/routes/comments/[id].patch.mjs +1 -1
- package/dist/runtime/server/routes/fate.d.ts +6 -0
- package/dist/runtime/server/routes/fate.mjs +32 -3
- package/dist/runtime/server/routes/mail/bounce.post.mjs +14 -2
- package/dist/runtime/server/routes/mail/unsubscribe.mjs +2 -1
- package/dist/runtime/server/routes/mail/webhooks.post.mjs +18 -4
- package/dist/runtime/server/routes/notifications/[id].get.mjs +3 -4
- package/dist/runtime/server/routes/notifications/index.get.mjs +4 -2
- package/dist/runtime/server/routes/notifications/push/subscribe.post.mjs +3 -1
- package/dist/runtime/server/routes/notifications/push/unsubscribe.post.mjs +5 -3
- package/dist/runtime/server/routes/notifications/read-all.post.mjs +6 -2
- package/dist/runtime/server/routes/notifications/send.post.mjs +13 -2
- package/dist/runtime/server/routes/payments/cancel.post.mjs +1 -1
- package/dist/runtime/server/routes/payments/change-plan.post.mjs +1 -1
- package/dist/runtime/server/routes/payments/checkout.post.mjs +1 -1
- package/dist/runtime/server/routes/payments/pause.post.mjs +1 -1
- package/dist/runtime/server/routes/payments/portal.post.mjs +1 -1
- package/dist/runtime/server/routes/payments/subscription.get.mjs +1 -1
- package/dist/runtime/server/routes/payments/usage.get.mjs +1 -1
- package/dist/runtime/server/routes/payments/usage.post.mjs +1 -1
- package/dist/runtime/server/routes/payments/webhook.post.mjs +8 -1
- package/dist/runtime/server/routes/realtime/broadcast.post.mjs +3 -2
- package/dist/runtime/server/routes/realtime/history.delete.mjs +2 -2
- package/dist/runtime/server/routes/realtime/history.get.mjs +2 -2
- package/dist/runtime/server/routes/realtime/presence.get.mjs +3 -3
- package/dist/runtime/server/routes/realtime/state.get.mjs +3 -3
- package/dist/runtime/server/routes/realtime/state.post.mjs +13 -4
- package/dist/runtime/server/routes/realtime/ws.get.mjs +2 -2
- package/dist/runtime/server/routes/storage/file/[...key].delete.mjs +1 -1
- package/dist/runtime/server/routes/storage/file/[...key].get.mjs +7 -0
- package/dist/runtime/server/routes/storage/files.get.d.ts +1 -1
- package/dist/runtime/server/routes/storage/files.get.mjs +24 -4
- package/dist/runtime/server/routes/storage/multipart/abort.post.mjs +16 -1
- package/dist/runtime/server/routes/storage/multipart/complete.post.d.ts +1 -1
- package/dist/runtime/server/routes/storage/multipart/complete.post.mjs +15 -1
- package/dist/runtime/server/routes/storage/multipart/create.post.mjs +7 -0
- package/dist/runtime/server/routes/storage/multipart/part.put.mjs +15 -1
- package/dist/runtime/server/routes/storage/presigned-r2.post.mjs +8 -1
- package/dist/runtime/server/routes/storage/presigned.post.d.ts +1 -1
- package/dist/runtime/server/routes/storage/presigned.post.mjs +8 -1
- package/dist/runtime/server/routes/storage/sign.post.mjs +7 -0
- package/dist/runtime/server/routes/storage/upload.post.d.ts +2 -2
- package/dist/runtime/server/routes/store/cart/index.delete.mjs +3 -4
- package/dist/runtime/server/routes/store/cart/index.get.mjs +3 -10
- package/dist/runtime/server/routes/store/cart/items/[id].delete.mjs +6 -4
- package/dist/runtime/server/routes/store/cart/items/[id].patch.mjs +12 -4
- package/dist/runtime/server/routes/store/cart/items.post.mjs +9 -10
- package/dist/runtime/server/routes/store/categories/index.get.mjs +4 -2
- package/dist/runtime/server/routes/store/checkout.post.mjs +13 -3
- package/dist/runtime/server/routes/store/coupons/apply.post.mjs +6 -5
- package/dist/runtime/server/routes/store/orders/[id].get.mjs +2 -2
- package/dist/runtime/server/routes/store/orders/download/[token].get.mjs +6 -3
- package/dist/runtime/server/routes/store/orders/index.get.mjs +1 -1
- package/dist/runtime/server/routes/store/products/[slug].get.mjs +2 -2
- package/dist/runtime/server/routes/store/products/index.get.mjs +1 -1
- package/dist/runtime/server/routes/store/tax/calculate.post.mjs +10 -0
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/index.delete.mjs +26 -25
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/verify.post.mjs +26 -25
- package/dist/runtime/server/utils/ai.d.ts +6 -0
- package/dist/runtime/server/utils/ai.mjs +12 -2
- package/dist/runtime/server/utils/analytics-query.mjs +8 -4
- package/dist/runtime/server/utils/browser-utils.d.ts +9 -0
- package/dist/runtime/server/utils/browser-utils.mjs +135 -0
- package/dist/runtime/server/utils/cms/cache.d.ts +13 -0
- package/dist/runtime/server/utils/cms/cache.mjs +95 -0
- package/dist/runtime/server/utils/cms/common.mjs +1 -1
- package/dist/runtime/server/utils/cms/markdown.mjs +38 -8
- package/dist/runtime/server/utils/cms/mutations.d.ts +26 -0
- package/dist/runtime/server/utils/cms/mutations.mjs +569 -0
- package/dist/runtime/server/utils/cms/path.d.ts +8 -0
- package/dist/runtime/server/utils/cms/path.mjs +23 -0
- package/dist/runtime/server/utils/cms/queries.d.ts +27 -0
- package/dist/runtime/server/utils/cms/queries.mjs +366 -0
- package/dist/runtime/server/utils/cms/references.d.ts +48 -0
- package/dist/runtime/server/utils/cms/references.mjs +309 -0
- package/dist/runtime/server/utils/cms/revisions.d.ts +7 -0
- package/dist/runtime/server/utils/cms/revisions.mjs +60 -0
- package/dist/runtime/server/utils/cms/sync.mjs +3 -3
- package/dist/runtime/server/utils/cms.d.ts +5 -82
- package/dist/runtime/server/utils/cms.mjs +28 -1367
- package/dist/runtime/server/utils/comments.d.ts +11 -0
- package/dist/runtime/server/utils/comments.mjs +65 -17
- package/dist/runtime/server/utils/crypto.mjs +1 -1
- package/dist/runtime/server/utils/domains.mjs +9 -0
- package/dist/runtime/server/utils/drizzle.d.ts +26 -1
- package/dist/runtime/server/utils/drizzle.mjs +78 -19
- package/dist/runtime/server/utils/email-inbound.mjs +9 -1
- package/dist/runtime/server/utils/impersonation.mjs +58 -1
- package/dist/runtime/server/utils/lock.d.ts +11 -0
- package/dist/runtime/server/utils/lock.mjs +4 -0
- package/dist/runtime/server/utils/mail-suppression.mjs +48 -13
- package/dist/runtime/server/utils/mail.d.ts +2 -1
- package/dist/runtime/server/utils/mail.mjs +17 -11
- package/dist/runtime/server/utils/notifications.d.ts +13 -4
- package/dist/runtime/server/utils/notifications.mjs +20 -4
- package/dist/runtime/server/utils/organization.mjs +36 -1
- package/dist/runtime/server/utils/passwordless.mjs +8 -0
- package/dist/runtime/server/utils/payments/checkout.d.ts +34 -0
- package/dist/runtime/server/utils/payments/checkout.mjs +158 -0
- package/dist/runtime/server/utils/payments/common.d.ts +45 -0
- package/dist/runtime/server/utils/payments/common.mjs +234 -0
- package/dist/runtime/server/utils/payments/index.d.ts +9 -0
- package/dist/runtime/server/utils/payments/index.mjs +21 -0
- package/dist/runtime/server/utils/payments/lemonsqueezy.d.ts +7 -0
- package/dist/runtime/server/utils/payments/lemonsqueezy.mjs +55 -0
- package/dist/runtime/server/utils/payments/paddle.d.ts +7 -0
- package/dist/runtime/server/utils/payments/paddle.mjs +92 -0
- package/dist/runtime/server/utils/payments/polar.d.ts +11 -0
- package/dist/runtime/server/utils/payments/polar.mjs +66 -0
- package/dist/runtime/server/utils/payments/stripe.d.ts +7 -0
- package/dist/runtime/server/utils/payments/stripe.mjs +159 -0
- package/dist/runtime/server/utils/payments/subscriptions.d.ts +89 -0
- package/dist/runtime/server/utils/payments/subscriptions.mjs +236 -0
- package/dist/runtime/server/utils/payments/usage.d.ts +12 -0
- package/dist/runtime/server/utils/payments/usage.mjs +143 -0
- package/dist/runtime/server/utils/payments/webhooks.d.ts +10 -0
- package/dist/runtime/server/utils/payments/webhooks.mjs +200 -0
- package/dist/runtime/server/utils/payments.d.ts +1 -158
- package/dist/runtime/server/utils/payments.mjs +1 -1289
- package/dist/runtime/server/utils/queue.d.ts +2 -0
- package/dist/runtime/server/utils/queue.mjs +34 -21
- package/dist/runtime/server/utils/rag.mjs +30 -17
- package/dist/runtime/server/utils/realtime.d.ts +5 -1
- package/dist/runtime/server/utils/realtime.mjs +43 -7
- package/dist/runtime/server/utils/session.mjs +16 -3
- package/dist/runtime/server/utils/sso.d.ts +3 -0
- package/dist/runtime/server/utils/sso.mjs +43 -0
- package/dist/runtime/server/utils/storage.mjs +12 -1
- package/dist/runtime/server/utils/store/cart.d.ts +63 -0
- package/dist/runtime/server/utils/store/cart.mjs +542 -0
- package/dist/runtime/server/utils/store/checkout.d.ts +14 -0
- package/dist/runtime/server/utils/store/checkout.mjs +118 -0
- package/dist/runtime/server/utils/store/common.d.ts +29 -0
- package/dist/runtime/server/utils/store/common.mjs +479 -0
- package/dist/runtime/server/utils/store/index.d.ts +7 -0
- package/dist/runtime/server/utils/store/index.mjs +30 -0
- package/dist/runtime/server/utils/store/inventory.d.ts +25 -0
- package/dist/runtime/server/utils/store/inventory.mjs +190 -0
- package/dist/runtime/server/utils/store/orders.d.ts +60 -0
- package/dist/runtime/server/utils/store/orders.mjs +590 -0
- package/dist/runtime/server/utils/store/products.d.ts +35 -0
- package/dist/runtime/server/utils/store/products.mjs +461 -0
- package/dist/runtime/server/utils/store/vendor.d.ts +18 -0
- package/dist/runtime/server/utils/store/vendor.mjs +68 -0
- package/dist/runtime/server/utils/store.d.ts +1 -207
- package/dist/runtime/server/utils/store.mjs +1 -2227
- package/dist/runtime/server/utils/string.d.ts +1 -1
- package/dist/runtime/server/utils/string.mjs +12 -4
- package/dist/runtime/server/utils/tenant.mjs +19 -5
- package/dist/runtime/server/utils/tracker.mjs +2 -0
- package/dist/runtime/server.d.ts +3 -3
- package/dist/runtime/server.mjs +4 -4
- package/dist/runtime/storage-server.d.ts +2 -0
- package/dist/runtime/storage-server.mjs +1 -0
- package/dist/runtime/storage.d.ts +1 -1
- package/dist/runtime/storage.mjs +0 -1
- package/dist/runtime/store.d.ts +0 -1
- package/dist/runtime/store.mjs +0 -1
- package/dist/runtime/test-utils.d.ts +4 -0
- package/dist/runtime/test-utils.mjs +54 -0
- package/dist/runtime/types/d1.d.ts +43 -0
- package/dist/runtime/types/drizzle.d.ts +6 -0
- package/dist/runtime/types/store.d.ts +1 -1
- package/dist/types/analytics.d.ts +80 -0
- package/dist/types/auth.d.ts +282 -0
- package/dist/types/cache.d.ts +55 -0
- package/dist/types/comments.d.ts +130 -0
- package/dist/types/db.d.ts +29 -0
- package/dist/types/email.d.ts +182 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/jobs.d.ts +58 -0
- package/dist/types/notifications.d.ts +77 -0
- package/dist/types/options.d.ts +363 -0
- package/dist/types/payments.d.ts +145 -0
- package/dist/types/ratelimit.d.ts +71 -0
- package/dist/types/realtime.d.ts +136 -0
- package/dist/types/site.d.ts +121 -0
- package/dist/types/storage.d.ts +164 -0
- package/dist/types/store-options.d.ts +199 -0
- package/dist/types/tenant.d.ts +100 -0
- package/dist/types.d.ts +1 -2174
- package/dist/utils/migration-lock.d.ts +139 -0
- package/dist/utils/pkg.d.ts +14 -1
- package/dist/utils/schema-diff.d.ts +39 -0
- package/package.json +55 -17
- 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 };
|