qarpeo 0.0.0-alpha.10
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/LICENSE +21 -0
- package/README.md +102 -0
- package/dist/chunks/auth-schema.mjs +219 -0
- package/dist/chunks/wrangler.mjs +783 -0
- package/dist/cli/index.mjs +1085 -0
- package/dist/dev/env.d.ts +12 -0
- package/dist/dev/wrangler.d.ts +18 -0
- package/dist/module.d.ts +16 -0
- package/dist/module.mjs +4436 -0
- package/dist/runtime/ai.d.ts +25 -0
- package/dist/runtime/ai.mjs +106 -0
- package/dist/runtime/analytics.d.ts +24 -0
- package/dist/runtime/analytics.mjs +38 -0
- package/dist/runtime/app/components/BlobImage.vue +100 -0
- package/dist/runtime/app/components/CMSBlocks.vue +93 -0
- package/dist/runtime/app/components/CMSContent.vue +23 -0
- package/dist/runtime/app/components/CMSImage.vue +49 -0
- package/dist/runtime/app/components/CMSLocaleSwitcher.vue +110 -0
- package/dist/runtime/app/components/CMSPreviewBanner.vue +79 -0
- package/dist/runtime/app/components/CMSVersionBanner.vue +49 -0
- package/dist/runtime/app/components/CMSVersionSwitcher.vue +126 -0
- package/dist/runtime/app/components/ContentRenderer.vue +80 -0
- package/dist/runtime/app/components/FileUpload.vue +196 -0
- package/dist/runtime/app/components/ImpersonationBanner.vue +57 -0
- package/dist/runtime/app/components/SignedIn.vue +13 -0
- package/dist/runtime/app/components/SignedOut.vue +13 -0
- package/dist/runtime/app/components/shiki.css +34 -0
- package/dist/runtime/app/composables/analytics.d.ts +125 -0
- package/dist/runtime/app/composables/analytics.mjs +81 -0
- package/dist/runtime/app/composables/api-tokens.d.ts +49 -0
- package/dist/runtime/app/composables/api-tokens.mjs +61 -0
- package/dist/runtime/app/composables/auth.d.ts +50 -0
- package/dist/runtime/app/composables/auth.mjs +101 -0
- package/dist/runtime/app/composables/chat.d.ts +69 -0
- package/dist/runtime/app/composables/chat.mjs +159 -0
- package/dist/runtime/app/composables/cms-preview.d.ts +33 -0
- package/dist/runtime/app/composables/cms-preview.mjs +83 -0
- package/dist/runtime/app/composables/cms.d.ts +307 -0
- package/dist/runtime/app/composables/cms.mjs +355 -0
- package/dist/runtime/app/composables/docs-version.d.ts +35 -0
- package/dist/runtime/app/composables/docs-version.mjs +70 -0
- package/dist/runtime/app/composables/impersonation.d.ts +14 -0
- package/dist/runtime/app/composables/impersonation.mjs +44 -0
- package/dist/runtime/app/composables/notifications.d.ts +35 -0
- package/dist/runtime/app/composables/notifications.mjs +139 -0
- package/dist/runtime/app/composables/organization.d.ts +127 -0
- package/dist/runtime/app/composables/organization.mjs +138 -0
- package/dist/runtime/app/composables/passkey.d.ts +6 -0
- package/dist/runtime/app/composables/passkey.mjs +105 -0
- package/dist/runtime/app/composables/passwordless.d.ts +7 -0
- package/dist/runtime/app/composables/passwordless.mjs +67 -0
- package/dist/runtime/app/composables/payments.d.ts +43 -0
- package/dist/runtime/app/composables/payments.mjs +74 -0
- package/dist/runtime/app/composables/realtime.d.ts +96 -0
- package/dist/runtime/app/composables/realtime.mjs +432 -0
- package/dist/runtime/app/composables/site.d.ts +35 -0
- package/dist/runtime/app/composables/site.mjs +36 -0
- package/dist/runtime/app/composables/storage.d.ts +60 -0
- package/dist/runtime/app/composables/storage.mjs +294 -0
- package/dist/runtime/app/composables/tenant.d.ts +82 -0
- package/dist/runtime/app/composables/tenant.mjs +120 -0
- package/dist/runtime/app/composables/turnstile.d.ts +3 -0
- package/dist/runtime/app/composables/turnstile.mjs +10 -0
- package/dist/runtime/app/composables/two-factor.d.ts +12 -0
- package/dist/runtime/app/composables/two-factor.mjs +65 -0
- package/dist/runtime/app/middleware/auth.global.d.ts +2 -0
- package/dist/runtime/app/middleware/auth.global.mjs +44 -0
- package/dist/runtime/app/pages/cms.vue +2249 -0
- package/dist/runtime/app/pages/devtools/agents.vue +717 -0
- package/dist/runtime/app/pages/devtools/analytics.vue +618 -0
- package/dist/runtime/app/pages/devtools/auth.vue +351 -0
- package/dist/runtime/app/pages/devtools/blob.vue +745 -0
- package/dist/runtime/app/pages/devtools/db.vue +546 -0
- package/dist/runtime/app/pages/devtools/domains.vue +772 -0
- package/dist/runtime/app/pages/devtools/kv.vue +829 -0
- package/dist/runtime/app/pages/devtools/logs.vue +655 -0
- package/dist/runtime/app/pages/devtools/mail.vue +389 -0
- package/dist/runtime/app/pages/devtools/overview.vue +390 -0
- package/dist/runtime/app/pages/devtools/settings.vue +560 -0
- package/dist/runtime/app/pages/devtools.vue +165 -0
- package/dist/runtime/app/plugins/seo.d.ts +2 -0
- package/dist/runtime/app/plugins/seo.mjs +105 -0
- package/dist/runtime/app/plugins/shortcuts.client.d.ts +6 -0
- package/dist/runtime/app/plugins/shortcuts.client.mjs +19 -0
- package/dist/runtime/app/public/sw-notifications.mjs +52 -0
- package/dist/runtime/auth.d.ts +25 -0
- package/dist/runtime/auth.mjs +11 -0
- package/dist/runtime/bindings.d.ts +27 -0
- package/dist/runtime/bindings.mjs +38 -0
- package/dist/runtime/blob.d.ts +26 -0
- package/dist/runtime/blob.mjs +334 -0
- package/dist/runtime/bots.d.ts +1 -0
- package/dist/runtime/bots.mjs +1 -0
- package/dist/runtime/browser.d.ts +21 -0
- package/dist/runtime/browser.mjs +64 -0
- package/dist/runtime/cache.d.ts +19 -0
- package/dist/runtime/cache.mjs +12 -0
- package/dist/runtime/cms.d.ts +2 -0
- package/dist/runtime/cms.mjs +0 -0
- package/dist/runtime/db.d.ts +21 -0
- package/dist/runtime/db.mjs +36 -0
- package/dist/runtime/drizzle.d.ts +11 -0
- package/dist/runtime/drizzle.mjs +18 -0
- package/dist/runtime/email.d.ts +51 -0
- package/dist/runtime/email.mjs +245 -0
- package/dist/runtime/hyperdrive.d.ts +21 -0
- package/dist/runtime/hyperdrive.mjs +49 -0
- package/dist/runtime/index.d.ts +23 -0
- package/dist/runtime/index.mjs +23 -0
- package/dist/runtime/kv.d.ts +16 -0
- package/dist/runtime/kv.mjs +126 -0
- package/dist/runtime/payments.d.ts +2 -0
- package/dist/runtime/payments.mjs +0 -0
- package/dist/runtime/queue.d.ts +21 -0
- package/dist/runtime/queue.mjs +41 -0
- package/dist/runtime/rag.d.ts +1 -0
- package/dist/runtime/rag.mjs +1 -0
- package/dist/runtime/ratelimit.d.ts +21 -0
- package/dist/runtime/ratelimit.mjs +38 -0
- package/dist/runtime/realtime.d.ts +6 -0
- package/dist/runtime/realtime.mjs +13 -0
- package/dist/runtime/server/db/cms-schema.d.ts +651 -0
- package/dist/runtime/server/db/cms-schema.mjs +74 -0
- package/dist/runtime/server/durable-objects/agent.d.ts +14 -0
- package/dist/runtime/server/durable-objects/agent.mjs +571 -0
- package/dist/runtime/server/durable-objects/room.d.ts +34 -0
- package/dist/runtime/server/durable-objects/room.mjs +514 -0
- package/dist/runtime/server/middleware/auth.d.ts +2 -0
- package/dist/runtime/server/middleware/auth.mjs +108 -0
- package/dist/runtime/server/middleware/devtools.d.ts +2 -0
- package/dist/runtime/server/middleware/devtools.mjs +61 -0
- package/dist/runtime/server/middleware/ratelimit.d.ts +2 -0
- package/dist/runtime/server/middleware/ratelimit.mjs +49 -0
- package/dist/runtime/server/middleware/tenancy.d.ts +6 -0
- package/dist/runtime/server/middleware/tenancy.mjs +15 -0
- package/dist/runtime/server/middleware/tracker.d.ts +7 -0
- package/dist/runtime/server/middleware/tracker.mjs +9 -0
- package/dist/runtime/server/plugins/agents.d.ts +7 -0
- package/dist/runtime/server/plugins/agents.mjs +3 -0
- package/dist/runtime/server/plugins/cms.d.ts +7 -0
- package/dist/runtime/server/plugins/cms.mjs +16 -0
- package/dist/runtime/server/plugins/dev-logs.d.ts +1 -0
- package/dist/runtime/server/plugins/dev-logs.mjs +58 -0
- package/dist/runtime/server/plugins/dev-proxy.d.ts +3 -0
- package/dist/runtime/server/plugins/dev-proxy.mjs +21 -0
- package/dist/runtime/server/plugins/env.d.ts +6 -0
- package/dist/runtime/server/plugins/env.mjs +17 -0
- package/dist/runtime/server/plugins/queue.d.ts +6 -0
- package/dist/runtime/server/plugins/queue.mjs +8 -0
- package/dist/runtime/server/routes/__qarpeo/agents/chat.post.d.ts +20 -0
- package/dist/runtime/server/routes/__qarpeo/agents/chat.post.mjs +110 -0
- package/dist/runtime/server/routes/__qarpeo/agents/clear.post.d.ts +7 -0
- package/dist/runtime/server/routes/__qarpeo/agents/clear.post.mjs +15 -0
- package/dist/runtime/server/routes/__qarpeo/agents/create.post.d.ts +17 -0
- package/dist/runtime/server/routes/__qarpeo/agents/create.post.mjs +47 -0
- package/dist/runtime/server/routes/__qarpeo/agents/history.get.d.ts +15 -0
- package/dist/runtime/server/routes/__qarpeo/agents/history.get.mjs +24 -0
- package/dist/runtime/server/routes/__qarpeo/agents/list.get.d.ts +5 -0
- package/dist/runtime/server/routes/__qarpeo/agents/list.get.mjs +63 -0
- package/dist/runtime/server/routes/__qarpeo/analytics/events.get.d.ts +64 -0
- package/dist/runtime/server/routes/__qarpeo/analytics/events.get.mjs +55 -0
- package/dist/runtime/server/routes/__qarpeo/analytics/summary.get.d.ts +30 -0
- package/dist/runtime/server/routes/__qarpeo/analytics/summary.get.mjs +73 -0
- package/dist/runtime/server/routes/__qarpeo/auth/revoke-session.post.d.ts +6 -0
- package/dist/runtime/server/routes/__qarpeo/auth/revoke-session.post.mjs +26 -0
- package/dist/runtime/server/routes/__qarpeo/auth/sessions.get.d.ts +6 -0
- package/dist/runtime/server/routes/__qarpeo/auth/sessions.get.mjs +46 -0
- package/dist/runtime/server/routes/__qarpeo/auth/users.get.d.ts +7 -0
- package/dist/runtime/server/routes/__qarpeo/auth/users.get.mjs +65 -0
- package/dist/runtime/server/routes/__qarpeo/blob/files.get.d.ts +22 -0
- package/dist/runtime/server/routes/__qarpeo/blob/files.get.mjs +36 -0
- package/dist/runtime/server/routes/__qarpeo/db/query.post.d.ts +23 -0
- package/dist/runtime/server/routes/__qarpeo/db/query.post.mjs +34 -0
- package/dist/runtime/server/routes/__qarpeo/db/tables.get.d.ts +31 -0
- package/dist/runtime/server/routes/__qarpeo/db/tables.get.mjs +81 -0
- package/dist/runtime/server/routes/__qarpeo/kv/delete.post.d.ts +11 -0
- package/dist/runtime/server/routes/__qarpeo/kv/delete.post.mjs +18 -0
- package/dist/runtime/server/routes/__qarpeo/kv/get.get.d.ts +11 -0
- package/dist/runtime/server/routes/__qarpeo/kv/get.get.mjs +20 -0
- package/dist/runtime/server/routes/__qarpeo/kv/keys.get.d.ts +8 -0
- package/dist/runtime/server/routes/__qarpeo/kv/keys.get.mjs +27 -0
- package/dist/runtime/server/routes/__qarpeo/kv/set.post.d.ts +14 -0
- package/dist/runtime/server/routes/__qarpeo/kv/set.post.mjs +24 -0
- package/dist/runtime/server/routes/__qarpeo/logs.delete.d.ts +5 -0
- package/dist/runtime/server/routes/__qarpeo/logs.delete.mjs +6 -0
- package/dist/runtime/server/routes/__qarpeo/logs.get.d.ts +5 -0
- package/dist/runtime/server/routes/__qarpeo/logs.get.mjs +26 -0
- package/dist/runtime/server/routes/__qarpeo/logs.post.d.ts +6 -0
- package/dist/runtime/server/routes/__qarpeo/logs.post.mjs +17 -0
- package/dist/runtime/server/routes/__qarpeo/mail/bounce.post.d.ts +5 -0
- package/dist/runtime/server/routes/__qarpeo/mail/bounce.post.mjs +37 -0
- package/dist/runtime/server/routes/__qarpeo/mail/clear.post.d.ts +4 -0
- package/dist/runtime/server/routes/__qarpeo/mail/clear.post.mjs +6 -0
- package/dist/runtime/server/routes/__qarpeo/mail/inbox.get.d.ts +5 -0
- package/dist/runtime/server/routes/__qarpeo/mail/inbox.get.mjs +7 -0
- package/dist/runtime/server/routes/__qarpeo/mail/send-test.post.d.ts +4 -0
- package/dist/runtime/server/routes/__qarpeo/mail/send-test.post.mjs +29 -0
- package/dist/runtime/server/routes/__qarpeo/mail/track/click/[id].get.d.ts +2 -0
- package/dist/runtime/server/routes/__qarpeo/mail/track/click/[id].get.mjs +23 -0
- package/dist/runtime/server/routes/__qarpeo/mail/track/open/[id].get.d.ts +2 -0
- package/dist/runtime/server/routes/__qarpeo/mail/track/open/[id].get.mjs +31 -0
- package/dist/runtime/server/routes/__qarpeo/overview/health.get.d.ts +8 -0
- package/dist/runtime/server/routes/__qarpeo/overview/health.get.mjs +46 -0
- package/dist/runtime/server/routes/__qarpeo/overview.get.d.ts +32 -0
- package/dist/runtime/server/routes/__qarpeo/overview.get.mjs +38 -0
- package/dist/runtime/server/routes/__qarpeo/settings/reset-dev-data.post.d.ts +11 -0
- package/dist/runtime/server/routes/__qarpeo/settings/reset-dev-data.post.mjs +84 -0
- package/dist/runtime/server/routes/__qarpeo/settings.get.d.ts +124 -0
- package/dist/runtime/server/routes/__qarpeo/settings.get.mjs +145 -0
- package/dist/runtime/server/routes/__qarpeo/tenants/create.post.d.ts +7 -0
- package/dist/runtime/server/routes/__qarpeo/tenants/create.post.mjs +26 -0
- package/dist/runtime/server/routes/__qarpeo/tenants/domain-add.post.d.ts +6 -0
- package/dist/runtime/server/routes/__qarpeo/tenants/domain-add.post.mjs +29 -0
- package/dist/runtime/server/routes/__qarpeo/tenants/domain-delete.post.d.ts +7 -0
- package/dist/runtime/server/routes/__qarpeo/tenants/domain-delete.post.mjs +21 -0
- package/dist/runtime/server/routes/__qarpeo/tenants/domain-verify.post.d.ts +9 -0
- package/dist/runtime/server/routes/__qarpeo/tenants/domain-verify.post.mjs +21 -0
- package/dist/runtime/server/routes/__qarpeo/tenants/list.get.d.ts +15 -0
- package/dist/runtime/server/routes/__qarpeo/tenants/list.get.mjs +22 -0
- package/dist/runtime/server/routes/agents/[agent]/chat.post.d.ts +2 -0
- package/dist/runtime/server/routes/agents/[agent]/chat.post.mjs +35 -0
- package/dist/runtime/server/routes/agents/[agent]/clear.post.d.ts +4 -0
- package/dist/runtime/server/routes/agents/[agent]/clear.post.mjs +27 -0
- package/dist/runtime/server/routes/agents/[agent]/history.get.d.ts +4 -0
- package/dist/runtime/server/routes/agents/[agent]/history.get.mjs +27 -0
- package/dist/runtime/server/routes/analytics/events.get.d.ts +3 -0
- package/dist/runtime/server/routes/analytics/events.get.mjs +17 -0
- package/dist/runtime/server/routes/analytics/pageviews.get.d.ts +3 -0
- package/dist/runtime/server/routes/analytics/pageviews.get.mjs +15 -0
- package/dist/runtime/server/routes/analytics/summary.get.d.ts +6 -0
- package/dist/runtime/server/routes/analytics/summary.get.mjs +15 -0
- package/dist/runtime/server/routes/atom.xml.get.d.ts +2 -0
- package/dist/runtime/server/routes/atom.xml.get.mjs +76 -0
- package/dist/runtime/server/routes/auth/2fa/disable.post.d.ts +4 -0
- package/dist/runtime/server/routes/auth/2fa/disable.post.mjs +44 -0
- package/dist/runtime/server/routes/auth/2fa/setup.post.d.ts +6 -0
- package/dist/runtime/server/routes/auth/2fa/setup.post.mjs +32 -0
- package/dist/runtime/server/routes/auth/2fa/verify.post.d.ts +6 -0
- package/dist/runtime/server/routes/auth/2fa/verify.post.mjs +92 -0
- package/dist/runtime/server/routes/auth/[provider]/callback.d.ts +1 -0
- package/dist/runtime/server/routes/auth/[provider]/callback.mjs +1 -0
- package/dist/runtime/server/routes/auth/[provider].d.ts +3 -0
- package/dist/runtime/server/routes/auth/[provider].mjs +95 -0
- package/dist/runtime/server/routes/auth/account.delete.d.ts +5 -0
- package/dist/runtime/server/routes/auth/account.delete.mjs +52 -0
- package/dist/runtime/server/routes/auth/impersonate/start.post.d.ts +5 -0
- package/dist/runtime/server/routes/auth/impersonate/start.post.mjs +14 -0
- package/dist/runtime/server/routes/auth/impersonate/stop.post.d.ts +5 -0
- package/dist/runtime/server/routes/auth/impersonate/stop.post.mjs +5 -0
- package/dist/runtime/server/routes/auth/logout-all.post.d.ts +4 -0
- package/dist/runtime/server/routes/auth/logout-all.post.mjs +16 -0
- package/dist/runtime/server/routes/auth/logout-others.post.d.ts +4 -0
- package/dist/runtime/server/routes/auth/logout-others.post.mjs +11 -0
- package/dist/runtime/server/routes/auth/logout.post.d.ts +4 -0
- package/dist/runtime/server/routes/auth/logout.post.mjs +17 -0
- package/dist/runtime/server/routes/auth/magic-link/send.post.d.ts +10 -0
- package/dist/runtime/server/routes/auth/magic-link/send.post.mjs +29 -0
- package/dist/runtime/server/routes/auth/magic-link/verify.get.d.ts +2 -0
- package/dist/runtime/server/routes/auth/magic-link/verify.get.mjs +81 -0
- package/dist/runtime/server/routes/auth/organization/create.post.d.ts +5 -0
- package/dist/runtime/server/routes/auth/organization/create.post.mjs +10 -0
- package/dist/runtime/server/routes/auth/organization/invite.post.d.ts +9 -0
- package/dist/runtime/server/routes/auth/organization/invite.post.mjs +27 -0
- package/dist/runtime/server/routes/auth/organization/join.post.d.ts +6 -0
- package/dist/runtime/server/routes/auth/organization/join.post.mjs +15 -0
- package/dist/runtime/server/routes/auth/organization/list.get.d.ts +5 -0
- package/dist/runtime/server/routes/auth/organization/list.get.mjs +7 -0
- package/dist/runtime/server/routes/auth/organization/members/[id].delete.d.ts +4 -0
- package/dist/runtime/server/routes/auth/organization/members/[id].delete.mjs +33 -0
- package/dist/runtime/server/routes/auth/organization/members/index.get.d.ts +6 -0
- package/dist/runtime/server/routes/auth/organization/members/index.get.mjs +18 -0
- package/dist/runtime/server/routes/auth/organization/mfa.post.d.ts +6 -0
- package/dist/runtime/server/routes/auth/organization/mfa.post.mjs +33 -0
- package/dist/runtime/server/routes/auth/organization/sso/[id].delete.d.ts +4 -0
- package/dist/runtime/server/routes/auth/organization/sso/[id].delete.mjs +28 -0
- package/dist/runtime/server/routes/auth/organization/sso/index.get.d.ts +2 -0
- package/dist/runtime/server/routes/auth/organization/sso/index.get.mjs +23 -0
- package/dist/runtime/server/routes/auth/organization/sso/index.post.d.ts +5 -0
- package/dist/runtime/server/routes/auth/organization/sso/index.post.mjs +84 -0
- package/dist/runtime/server/routes/auth/organization/switch.post.d.ts +6 -0
- package/dist/runtime/server/routes/auth/organization/switch.post.mjs +14 -0
- package/dist/runtime/server/routes/auth/otp/send.post.d.ts +10 -0
- package/dist/runtime/server/routes/auth/otp/send.post.mjs +29 -0
- package/dist/runtime/server/routes/auth/otp/verify.post.d.ts +6 -0
- package/dist/runtime/server/routes/auth/otp/verify.post.mjs +95 -0
- package/dist/runtime/server/routes/auth/sessions/[id].delete.d.ts +5 -0
- package/dist/runtime/server/routes/auth/sessions/[id].delete.mjs +24 -0
- package/dist/runtime/server/routes/auth/sessions.get.d.ts +2 -0
- package/dist/runtime/server/routes/auth/sessions.get.mjs +11 -0
- package/dist/runtime/server/routes/auth/sso/login.get.d.ts +2 -0
- package/dist/runtime/server/routes/auth/sso/login.get.mjs +94 -0
- package/dist/runtime/server/routes/auth/sso/oidc/callback.get.d.ts +2 -0
- package/dist/runtime/server/routes/auth/sso/oidc/callback.get.mjs +113 -0
- package/dist/runtime/server/routes/auth/sso/saml/acs.post.d.ts +2 -0
- package/dist/runtime/server/routes/auth/sso/saml/acs.post.mjs +95 -0
- package/dist/runtime/server/routes/auth/tokens/[id].delete.d.ts +4 -0
- package/dist/runtime/server/routes/auth/tokens/[id].delete.mjs +13 -0
- package/dist/runtime/server/routes/auth/tokens/create.post.d.ts +9 -0
- package/dist/runtime/server/routes/auth/tokens/create.post.mjs +17 -0
- package/dist/runtime/server/routes/auth/tokens/index.get.d.ts +9 -0
- package/dist/runtime/server/routes/auth/tokens/index.get.mjs +5 -0
- package/dist/runtime/server/routes/auth/turnstile/verify.post.d.ts +2 -0
- package/dist/runtime/server/routes/auth/turnstile/verify.post.mjs +15 -0
- package/dist/runtime/server/routes/auth/user.get.d.ts +2 -0
- package/dist/runtime/server/routes/auth/user.get.mjs +6 -0
- package/dist/runtime/server/routes/auth/webauthn/login/options.post.d.ts +2 -0
- package/dist/runtime/server/routes/auth/webauthn/login/options.post.mjs +17 -0
- package/dist/runtime/server/routes/auth/webauthn/login/verify.post.d.ts +6 -0
- package/dist/runtime/server/routes/auth/webauthn/login/verify.post.mjs +127 -0
- package/dist/runtime/server/routes/auth/webauthn/register/options.post.d.ts +2 -0
- package/dist/runtime/server/routes/auth/webauthn/register/options.post.mjs +47 -0
- package/dist/runtime/server/routes/auth/webauthn/register/verify.post.d.ts +5 -0
- package/dist/runtime/server/routes/auth/webauthn/register/verify.post.mjs +88 -0
- package/dist/runtime/server/routes/cms/[collection]/[id]/preview-token.post.d.ts +8 -0
- package/dist/runtime/server/routes/cms/[collection]/[id]/preview-token.post.mjs +27 -0
- package/dist/runtime/server/routes/cms/[collection]/[id]/publish.post.d.ts +6 -0
- package/dist/runtime/server/routes/cms/[collection]/[id]/publish.post.mjs +19 -0
- package/dist/runtime/server/routes/cms/[collection]/[id]/review.post.d.ts +6 -0
- package/dist/runtime/server/routes/cms/[collection]/[id]/review.post.mjs +33 -0
- package/dist/runtime/server/routes/cms/[collection]/[id].delete.d.ts +4 -0
- package/dist/runtime/server/routes/cms/[collection]/[id].delete.mjs +17 -0
- package/dist/runtime/server/routes/cms/[collection]/[id].put.d.ts +4 -0
- package/dist/runtime/server/routes/cms/[collection]/[id].put.mjs +18 -0
- package/dist/runtime/server/routes/cms/[collection]/[slug].get.d.ts +4 -0
- package/dist/runtime/server/routes/cms/[collection]/[slug].get.mjs +19 -0
- package/dist/runtime/server/routes/cms/[collection]/atom.xml.get.d.ts +2 -0
- package/dist/runtime/server/routes/cms/[collection]/atom.xml.get.mjs +69 -0
- package/dist/runtime/server/routes/cms/[collection]/by-path.get.d.ts +8 -0
- package/dist/runtime/server/routes/cms/[collection]/by-path.get.mjs +23 -0
- package/dist/runtime/server/routes/cms/[collection]/feed.xml.get.d.ts +2 -0
- package/dist/runtime/server/routes/cms/[collection]/feed.xml.get.mjs +65 -0
- package/dist/runtime/server/routes/cms/[collection]/index.get.d.ts +7 -0
- package/dist/runtime/server/routes/cms/[collection]/index.get.mjs +15 -0
- package/dist/runtime/server/routes/cms/[collection]/index.post.d.ts +4 -0
- package/dist/runtime/server/routes/cms/[collection]/index.post.mjs +23 -0
- package/dist/runtime/server/routes/cms/[collection]/references.get.d.ts +19 -0
- package/dist/runtime/server/routes/cms/[collection]/references.get.mjs +47 -0
- package/dist/runtime/server/routes/cms/[collection]/surroundings.get.d.ts +10 -0
- package/dist/runtime/server/routes/cms/[collection]/surroundings.get.mjs +12 -0
- package/dist/runtime/server/routes/cms/collections/[id].delete.d.ts +4 -0
- package/dist/runtime/server/routes/cms/collections/[id].delete.mjs +10 -0
- package/dist/runtime/server/routes/cms/collections/[id].put.d.ts +4 -0
- package/dist/runtime/server/routes/cms/collections/[id].put.mjs +11 -0
- package/dist/runtime/server/routes/cms/collections/index.get.d.ts +4 -0
- package/dist/runtime/server/routes/cms/collections/index.get.mjs +6 -0
- package/dist/runtime/server/routes/cms/collections/index.post.d.ts +4 -0
- package/dist/runtime/server/routes/cms/collections/index.post.mjs +19 -0
- package/dist/runtime/server/routes/cms/components/index.get.d.ts +17 -0
- package/dist/runtime/server/routes/cms/components/index.get.mjs +16 -0
- package/dist/runtime/server/routes/cms/deploy.post.d.ts +4 -0
- package/dist/runtime/server/routes/cms/deploy.post.mjs +46 -0
- package/dist/runtime/server/routes/cms/export.post.d.ts +10 -0
- package/dist/runtime/server/routes/cms/export.post.mjs +55 -0
- package/dist/runtime/server/routes/cms/navigation.get.d.ts +8 -0
- package/dist/runtime/server/routes/cms/navigation.get.mjs +36 -0
- package/dist/runtime/server/routes/cms/preview/disable.get.d.ts +9 -0
- package/dist/runtime/server/routes/cms/preview/disable.get.mjs +9 -0
- package/dist/runtime/server/routes/cms/preview/enable.get.d.ts +14 -0
- package/dist/runtime/server/routes/cms/preview/enable.get.mjs +42 -0
- package/dist/runtime/server/routes/cms/publish-scheduled.post.d.ts +11 -0
- package/dist/runtime/server/routes/cms/publish-scheduled.post.mjs +35 -0
- package/dist/runtime/server/routes/cms/search.get.d.ts +13 -0
- package/dist/runtime/server/routes/cms/search.get.mjs +137 -0
- package/dist/runtime/server/routes/cms/sync.post.d.ts +7 -0
- package/dist/runtime/server/routes/cms/sync.post.mjs +18 -0
- package/dist/runtime/server/routes/cms/webhooks/[provider].post.d.ts +150 -0
- package/dist/runtime/server/routes/cms/webhooks/[provider].post.mjs +213 -0
- package/dist/runtime/server/routes/docs/search.get.d.ts +15 -0
- package/dist/runtime/server/routes/docs/search.get.mjs +20 -0
- package/dist/runtime/server/routes/feed.xml.get.d.ts +2 -0
- package/dist/runtime/server/routes/feed.xml.get.mjs +73 -0
- package/dist/runtime/server/routes/mail/bounce.post.d.ts +14 -0
- package/dist/runtime/server/routes/mail/bounce.post.mjs +56 -0
- package/dist/runtime/server/routes/mail/inbox/[id].get.d.ts +2 -0
- package/dist/runtime/server/routes/mail/inbox/[id].get.mjs +9 -0
- package/dist/runtime/server/routes/mail/inbox.get.d.ts +4 -0
- package/dist/runtime/server/routes/mail/inbox.get.mjs +7 -0
- package/dist/runtime/server/routes/mail/suppressions/[email].delete.d.ts +11 -0
- package/dist/runtime/server/routes/mail/suppressions/[email].delete.mjs +18 -0
- package/dist/runtime/server/routes/mail/suppressions/index.get.d.ts +12 -0
- package/dist/runtime/server/routes/mail/suppressions/index.get.mjs +23 -0
- package/dist/runtime/server/routes/mail/suppressions/index.post.d.ts +10 -0
- package/dist/runtime/server/routes/mail/suppressions/index.post.mjs +23 -0
- package/dist/runtime/server/routes/mail/unsubscribe.d.ts +13 -0
- package/dist/runtime/server/routes/mail/unsubscribe.mjs +91 -0
- package/dist/runtime/server/routes/mail/webhooks.post.d.ts +12 -0
- package/dist/runtime/server/routes/mail/webhooks.post.mjs +71 -0
- package/dist/runtime/server/routes/notifications/[id]/read.post.d.ts +4 -0
- package/dist/runtime/server/routes/notifications/[id]/read.post.mjs +13 -0
- package/dist/runtime/server/routes/notifications/[id].delete.d.ts +4 -0
- package/dist/runtime/server/routes/notifications/[id].delete.mjs +13 -0
- package/dist/runtime/server/routes/notifications/[id].get.d.ts +2 -0
- package/dist/runtime/server/routes/notifications/[id].get.mjs +15 -0
- package/dist/runtime/server/routes/notifications/index.get.d.ts +6 -0
- package/dist/runtime/server/routes/notifications/index.get.mjs +18 -0
- package/dist/runtime/server/routes/notifications/push/subscribe.post.d.ts +4 -0
- package/dist/runtime/server/routes/notifications/push/subscribe.post.mjs +20 -0
- package/dist/runtime/server/routes/notifications/push/unsubscribe.post.d.ts +4 -0
- package/dist/runtime/server/routes/notifications/push/unsubscribe.post.mjs +15 -0
- package/dist/runtime/server/routes/notifications/read-all.post.d.ts +4 -0
- package/dist/runtime/server/routes/notifications/read-all.post.mjs +11 -0
- package/dist/runtime/server/routes/payments/cancel.post.d.ts +7 -0
- package/dist/runtime/server/routes/payments/cancel.post.mjs +9 -0
- package/dist/runtime/server/routes/payments/change-plan.post.d.ts +7 -0
- package/dist/runtime/server/routes/payments/change-plan.post.mjs +12 -0
- package/dist/runtime/server/routes/payments/checkout.post.d.ts +9 -0
- package/dist/runtime/server/routes/payments/checkout.post.mjs +16 -0
- package/dist/runtime/server/routes/payments/pause.post.d.ts +7 -0
- package/dist/runtime/server/routes/payments/pause.post.mjs +9 -0
- package/dist/runtime/server/routes/payments/portal.post.d.ts +5 -0
- package/dist/runtime/server/routes/payments/portal.post.mjs +9 -0
- package/dist/runtime/server/routes/payments/subscription.get.d.ts +6 -0
- package/dist/runtime/server/routes/payments/subscription.get.mjs +9 -0
- package/dist/runtime/server/routes/payments/usage.get.d.ts +12 -0
- package/dist/runtime/server/routes/payments/usage.get.mjs +18 -0
- package/dist/runtime/server/routes/payments/usage.post.d.ts +6 -0
- package/dist/runtime/server/routes/payments/usage.post.mjs +24 -0
- package/dist/runtime/server/routes/payments/webhook.post.d.ts +14 -0
- package/dist/runtime/server/routes/payments/webhook.post.mjs +21 -0
- package/dist/runtime/server/routes/realtime/broadcast.post.d.ts +4 -0
- package/dist/runtime/server/routes/realtime/broadcast.post.mjs +26 -0
- package/dist/runtime/server/routes/realtime/history.delete.d.ts +13 -0
- package/dist/runtime/server/routes/realtime/history.delete.mjs +12 -0
- package/dist/runtime/server/routes/realtime/history.get.d.ts +16 -0
- package/dist/runtime/server/routes/realtime/history.get.mjs +15 -0
- package/dist/runtime/server/routes/realtime/presence.get.d.ts +6 -0
- package/dist/runtime/server/routes/realtime/presence.get.mjs +27 -0
- package/dist/runtime/server/routes/realtime/state.get.d.ts +5 -0
- package/dist/runtime/server/routes/realtime/state.get.mjs +26 -0
- package/dist/runtime/server/routes/realtime/state.post.d.ts +6 -0
- package/dist/runtime/server/routes/realtime/state.post.mjs +37 -0
- package/dist/runtime/server/routes/realtime/ws.get.d.ts +2 -0
- package/dist/runtime/server/routes/realtime/ws.get.mjs +73 -0
- package/dist/runtime/server/routes/robots.txt.get.d.ts +2 -0
- package/dist/runtime/server/routes/robots.txt.get.mjs +41 -0
- package/dist/runtime/server/routes/rss.xml.get.d.ts +2 -0
- package/dist/runtime/server/routes/rss.xml.get.mjs +2 -0
- package/dist/runtime/server/routes/sitemap.xml.get.d.ts +2 -0
- package/dist/runtime/server/routes/sitemap.xml.get.mjs +84 -0
- package/dist/runtime/server/routes/storage/file/[...key].delete.d.ts +4 -0
- package/dist/runtime/server/routes/storage/file/[...key].delete.mjs +23 -0
- package/dist/runtime/server/routes/storage/file/[...key].get.d.ts +2 -0
- package/dist/runtime/server/routes/storage/file/[...key].get.mjs +23 -0
- package/dist/runtime/server/routes/storage/files.get.d.ts +14 -0
- package/dist/runtime/server/routes/storage/files.get.mjs +11 -0
- package/dist/runtime/server/routes/storage/presigned.post.d.ts +8 -0
- package/dist/runtime/server/routes/storage/presigned.post.mjs +39 -0
- package/dist/runtime/server/routes/storage/sign.post.d.ts +6 -0
- package/dist/runtime/server/routes/storage/sign.post.mjs +24 -0
- package/dist/runtime/server/routes/storage/upload.post.d.ts +22 -0
- package/dist/runtime/server/routes/storage/upload.post.mjs +96 -0
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/index.delete.d.ts +8 -0
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/index.delete.mjs +39 -0
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/verify.post.d.ts +8 -0
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/verify.post.mjs +39 -0
- package/dist/runtime/server/routes/tenants/[tenant]/domains/index.get.d.ts +8 -0
- package/dist/runtime/server/routes/tenants/[tenant]/domains/index.get.mjs +20 -0
- package/dist/runtime/server/routes/tenants/[tenant]/domains/index.post.d.ts +8 -0
- package/dist/runtime/server/routes/tenants/[tenant]/domains/index.post.mjs +44 -0
- package/dist/runtime/server/routes/tenants/current.get.d.ts +8 -0
- package/dist/runtime/server/routes/tenants/current.get.mjs +6 -0
- package/dist/runtime/server/tasks/cms/publish.d.ts +4 -0
- package/dist/runtime/server/tasks/cms/publish.mjs +18 -0
- package/dist/runtime/server/utils/agent-store.d.ts +24 -0
- package/dist/runtime/server/utils/agent-store.mjs +53 -0
- package/dist/runtime/server/utils/agents-registry-fallback.d.ts +1 -0
- package/dist/runtime/server/utils/agents-registry-fallback.mjs +1 -0
- package/dist/runtime/server/utils/ai.d.ts +119 -0
- package/dist/runtime/server/utils/ai.mjs +607 -0
- package/dist/runtime/server/utils/analytics-query.d.ts +109 -0
- package/dist/runtime/server/utils/analytics-query.mjs +234 -0
- package/dist/runtime/server/utils/auth.d.ts +60 -0
- package/dist/runtime/server/utils/auth.mjs +361 -0
- package/dist/runtime/server/utils/blob-store.d.ts +13 -0
- package/dist/runtime/server/utils/blob-store.mjs +60 -0
- package/dist/runtime/server/utils/bots.d.ts +21 -0
- package/dist/runtime/server/utils/bots.mjs +491 -0
- package/dist/runtime/server/utils/cache.d.ts +33 -0
- package/dist/runtime/server/utils/cache.mjs +128 -0
- package/dist/runtime/server/utils/cms-events.d.ts +17 -0
- package/dist/runtime/server/utils/cms-events.mjs +80 -0
- package/dist/runtime/server/utils/cms-filter.d.ts +3 -0
- package/dist/runtime/server/utils/cms-filter.mjs +34 -0
- package/dist/runtime/server/utils/cms.d.ts +278 -0
- package/dist/runtime/server/utils/cms.mjs +3268 -0
- package/dist/runtime/server/utils/config.d.ts +27 -0
- package/dist/runtime/server/utils/config.mjs +38 -0
- package/dist/runtime/server/utils/context.d.ts +13 -0
- package/dist/runtime/server/utils/context.mjs +98 -0
- package/dist/runtime/server/utils/crypto.d.ts +16 -0
- package/dist/runtime/server/utils/crypto.mjs +56 -0
- package/dist/runtime/server/utils/dev-logs.d.ts +21 -0
- package/dist/runtime/server/utils/dev-logs.mjs +41 -0
- package/dist/runtime/server/utils/dev-proxy.d.ts +1 -0
- package/dist/runtime/server/utils/dev-proxy.mjs +69 -0
- package/dist/runtime/server/utils/domains.d.ts +46 -0
- package/dist/runtime/server/utils/domains.mjs +318 -0
- package/dist/runtime/server/utils/drizzle.d.ts +10 -0
- package/dist/runtime/server/utils/drizzle.mjs +36 -0
- package/dist/runtime/server/utils/email-templates.d.ts +44 -0
- package/dist/runtime/server/utils/email-templates.mjs +373 -0
- package/dist/runtime/server/utils/feed.d.ts +42 -0
- package/dist/runtime/server/utils/feed.mjs +161 -0
- package/dist/runtime/server/utils/impersonation.d.ts +67 -0
- package/dist/runtime/server/utils/impersonation.mjs +298 -0
- package/dist/runtime/server/utils/jobs.d.ts +70 -0
- package/dist/runtime/server/utils/jobs.mjs +125 -0
- package/dist/runtime/server/utils/kv-store.d.ts +9 -0
- package/dist/runtime/server/utils/kv-store.mjs +32 -0
- package/dist/runtime/server/utils/mail-suppression.d.ts +62 -0
- package/dist/runtime/server/utils/mail-suppression.mjs +328 -0
- package/dist/runtime/server/utils/mail.d.ts +90 -0
- package/dist/runtime/server/utils/mail.mjs +366 -0
- package/dist/runtime/server/utils/notifications.d.ts +51 -0
- package/dist/runtime/server/utils/notifications.mjs +215 -0
- package/dist/runtime/server/utils/organization.d.ts +54 -0
- package/dist/runtime/server/utils/organization.mjs +354 -0
- package/dist/runtime/server/utils/passwordless.d.ts +48 -0
- package/dist/runtime/server/utils/passwordless.mjs +179 -0
- package/dist/runtime/server/utils/payments.d.ts +121 -0
- package/dist/runtime/server/utils/payments.mjs +1067 -0
- package/dist/runtime/server/utils/queue-fallback.d.ts +2 -0
- package/dist/runtime/server/utils/queue-fallback.mjs +2 -0
- package/dist/runtime/server/utils/queue.d.ts +4 -0
- package/dist/runtime/server/utils/queue.mjs +3 -0
- package/dist/runtime/server/utils/rag.d.ts +25 -0
- package/dist/runtime/server/utils/rag.mjs +333 -0
- package/dist/runtime/server/utils/ratelimit.d.ts +45 -0
- package/dist/runtime/server/utils/ratelimit.mjs +182 -0
- package/dist/runtime/server/utils/realtime.d.ts +110 -0
- package/dist/runtime/server/utils/realtime.mjs +197 -0
- package/dist/runtime/server/utils/schema-fallback.d.ts +3 -0
- package/dist/runtime/server/utils/schema-fallback.mjs +2 -0
- package/dist/runtime/server/utils/session.d.ts +72 -0
- package/dist/runtime/server/utils/session.mjs +287 -0
- package/dist/runtime/server/utils/sso.d.ts +49 -0
- package/dist/runtime/server/utils/sso.mjs +131 -0
- package/dist/runtime/server/utils/storage.d.ts +111 -0
- package/dist/runtime/server/utils/storage.mjs +654 -0
- package/dist/runtime/server/utils/tenant.d.ts +44 -0
- package/dist/runtime/server/utils/tenant.mjs +285 -0
- package/dist/runtime/server/utils/totp.d.ts +33 -0
- package/dist/runtime/server/utils/totp.mjs +112 -0
- package/dist/runtime/server/utils/tracker.d.ts +72 -0
- package/dist/runtime/server/utils/tracker.mjs +139 -0
- package/dist/runtime/server/utils/turnstile.d.ts +17 -0
- package/dist/runtime/server/utils/turnstile.mjs +68 -0
- package/dist/runtime/server/utils/vapid.d.ts +35 -0
- package/dist/runtime/server/utils/vapid.mjs +211 -0
- package/dist/runtime/storage.d.ts +1 -0
- package/dist/runtime/storage.mjs +0 -0
- package/dist/runtime/types/ai.d.ts +68 -0
- package/dist/runtime/types/ai.mjs +0 -0
- package/dist/runtime/types/analytics.d.ts +30 -0
- package/dist/runtime/types/analytics.mjs +0 -0
- package/dist/runtime/types/auth-globals.d.ts +14 -0
- package/dist/runtime/types/auth.d.ts +153 -0
- package/dist/runtime/types/auth.mjs +0 -0
- package/dist/runtime/types/browser.d.ts +29 -0
- package/dist/runtime/types/browser.mjs +0 -0
- package/dist/runtime/types/d1.d.ts +44 -0
- package/dist/runtime/types/d1.mjs +0 -0
- package/dist/runtime/types/drizzle.d.ts +13 -0
- package/dist/runtime/types/drizzle.mjs +0 -0
- package/dist/runtime/types/durable-object.d.ts +51 -0
- package/dist/runtime/types/durable-object.mjs +0 -0
- package/dist/runtime/types/email.d.ts +66 -0
- package/dist/runtime/types/email.mjs +0 -0
- package/dist/runtime/types/hyperdrive.d.ts +18 -0
- package/dist/runtime/types/hyperdrive.mjs +0 -0
- package/dist/runtime/types/imports.d.ts +58 -0
- package/dist/runtime/types/index.d.ts +156 -0
- package/dist/runtime/types/index.mjs +13 -0
- package/dist/runtime/types/queue.d.ts +67 -0
- package/dist/runtime/types/queue.mjs +0 -0
- package/dist/runtime/types/r2.d.ts +108 -0
- package/dist/runtime/types/r2.mjs +0 -0
- package/dist/runtime/types/ratelimit.d.ts +21 -0
- package/dist/runtime/types/ratelimit.mjs +0 -0
- package/dist/runtime/types/vectorize.d.ts +74 -0
- package/dist/runtime/types/vectorize.mjs +0 -0
- package/dist/runtime/vectorize.d.ts +21 -0
- package/dist/runtime/vectorize.mjs +53 -0
- package/dist/types.d.ts +2750 -0
- package/dist/types.mjs +1 -0
- package/dist/utils/agents.d.ts +8 -0
- package/dist/utils/auth-schema.d.ts +11 -0
- package/dist/utils/bindings.d.ts +16 -0
- package/dist/utils/cms-schema.d.ts +1 -0
- package/dist/utils/cms-sources.d.ts +62 -0
- package/dist/utils/drizzle.d.ts +42 -0
- package/dist/utils/jobs.d.ts +8 -0
- package/dist/utils/local-db.d.ts +28 -0
- package/dist/utils/notifications-schema.d.ts +15 -0
- package/dist/utils/payments-schema.d.ts +11 -0
- package/dist/utils/pkg.d.ts +15 -0
- package/dist/utils/queue.d.ts +8 -0
- package/dist/utils/tenants-schema.d.ts +11 -0
- package/package.json +104 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { DurableObjectStub, RealtimeMessage, RealtimeUser, RealtimePeer, RealtimeHandlerOptions, RealtimeHandlerRegistration } from "../../../types";
|
|
2
|
+
export type { RealtimePeer, RealtimeHandlerOptions, RealtimeHandlerRegistration };
|
|
3
|
+
/**
|
|
4
|
+
* Defines a server-side message and lifecycle handler for a room pattern.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* export default defineRealtimeHandler("chat:*", {
|
|
9
|
+
* async message(peer, event, payload) {
|
|
10
|
+
* await broadcastToRoom(peer.roomId, "message", {
|
|
11
|
+
* from: peer.ctx.user?.name ?? "Anonymous",
|
|
12
|
+
* text: payload.text,
|
|
13
|
+
* ts: Date.now(),
|
|
14
|
+
* })
|
|
15
|
+
* },
|
|
16
|
+
* connect(peer) {
|
|
17
|
+
* console.log(`User connected to ${peer.roomId}`)
|
|
18
|
+
* },
|
|
19
|
+
* })
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function defineRealtimeHandler(roomPattern: string, handlers: RealtimeHandlerOptions): RealtimeHandlerRegistration;
|
|
23
|
+
/**
|
|
24
|
+
* Retrieves all registered realtime handlers matching a given room ID.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getRealtimeHandlersForRoom(roomId: string): RealtimeHandlerOptions[];
|
|
27
|
+
/**
|
|
28
|
+
* Retrieves the Durable Object stub for a specific room name.
|
|
29
|
+
*
|
|
30
|
+
* @param event Universal server event context (optional if in global context)
|
|
31
|
+
* @param roomId Room identifier (e.g. "chat:support", "doc:123")
|
|
32
|
+
* @param bindingName Durable Object binding name (default "QARPEO_ROOM_DO")
|
|
33
|
+
*/
|
|
34
|
+
export declare function getRoomDurableObject(eventOrRoom: any, maybeRoom?: string, bindingName?: string): DurableObjectStub;
|
|
35
|
+
/**
|
|
36
|
+
* Broadcasts an event and payload to all clients in a room from the server.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ;```ts
|
|
40
|
+
* await broadcastToRoom(event, "doc:456", "doc:updated", {
|
|
41
|
+
* title: "New Title",
|
|
42
|
+
* updatedBy: "Admin",
|
|
43
|
+
* })
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function broadcastToRoom(eventOrRoom: any, roomOrEventName: string, eventNameOrPayload: any, payloadOrOptions?: any, options?: {
|
|
47
|
+
sender?: string;
|
|
48
|
+
excludePeerId?: string;
|
|
49
|
+
}): Promise<boolean>;
|
|
50
|
+
/**
|
|
51
|
+
* Retrieves the active presence roster for a room.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const onlineUsers = await getRoomPresence(event, "doc:456")
|
|
56
|
+
* console.log(`Online: ${onlineUsers.length}`)
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function getRoomPresence(eventOrRoom: any, maybeRoom?: string): Promise<RealtimeUser[]>;
|
|
60
|
+
/**
|
|
61
|
+
* Retrieves the message history replay buffer for a room from Durable Object storage.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* const messages = await getRoomHistory(event, "chat:support")
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare function getRoomHistory(eventOrRoom: any, maybeRoom?: string, options?: {
|
|
69
|
+
limit?: number;
|
|
70
|
+
sinceSeq?: number;
|
|
71
|
+
since?: number;
|
|
72
|
+
}): Promise<RealtimeMessage[]>;
|
|
73
|
+
/**
|
|
74
|
+
* Clears the persistent message history replay buffer for a room from Durable Object storage.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* await clearRoomHistory(event, "chat:support")
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare function clearRoomHistory(eventOrRoom: any, maybeRoom?: string): Promise<boolean>;
|
|
82
|
+
/** Disconnects a user from a room by their userId. */
|
|
83
|
+
export declare function disconnectRoomUser(eventOrRoom: any, roomOrUserId: string, maybeUserId?: string): Promise<number>;
|
|
84
|
+
/**
|
|
85
|
+
* Retrieves the synchronized state of a room.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* const state = await getRoomState(event, "doc:456")
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export declare function getRoomState<T extends Record<string, any> = Record<string, any>>(eventOrRoom: any, maybeRoom?: string): Promise<T>;
|
|
93
|
+
/**
|
|
94
|
+
* Replaces the entire synchronized state of a room and broadcasts to all connected clients.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* await setRoomState(event, "doc:456", { title: "New Document", locked: false })
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export declare function setRoomState<T extends Record<string, any> = Record<string, any>>(eventOrRoom: any, roomOrState: string | T, maybeState?: T): Promise<T>;
|
|
102
|
+
/**
|
|
103
|
+
* Merges a partial patch into the synchronized state of a room and broadcasts the delta.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* await patchRoomState(event, "doc:456", { locked: true })
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export declare function patchRoomState<T extends Record<string, any> = Record<string, any>>(eventOrRoom: any, roomOrPatch: string | Partial<T>, maybePatch?: Partial<T>): Promise<T>;
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { getCloudflareEnv } from "../../bindings.mjs";
|
|
2
|
+
const registeredRealtimeHandlers = [];
|
|
3
|
+
export function defineRealtimeHandler(roomPattern, handlers) {
|
|
4
|
+
const reg = {
|
|
5
|
+
pattern: roomPattern,
|
|
6
|
+
handlers
|
|
7
|
+
};
|
|
8
|
+
registeredRealtimeHandlers.push(reg);
|
|
9
|
+
return reg;
|
|
10
|
+
}
|
|
11
|
+
export function getRealtimeHandlersForRoom(roomId) {
|
|
12
|
+
return registeredRealtimeHandlers.filter((reg) => {
|
|
13
|
+
if (reg.pattern === "*" || reg.pattern === roomId) return true;
|
|
14
|
+
if (reg.pattern.endsWith("*")) {
|
|
15
|
+
const prefix = reg.pattern.slice(0, -1);
|
|
16
|
+
return roomId.startsWith(prefix);
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
}).map((reg) => reg.handlers);
|
|
20
|
+
}
|
|
21
|
+
function resolveRoomAndEvent(arg1, arg2) {
|
|
22
|
+
if (typeof arg1 === "string") {
|
|
23
|
+
return { event: void 0, roomId: arg1 };
|
|
24
|
+
}
|
|
25
|
+
return { event: arg1, roomId: arg2 || "general" };
|
|
26
|
+
}
|
|
27
|
+
export function getRoomDurableObject(eventOrRoom, maybeRoom, bindingName = "QARPEO_ROOM_DO") {
|
|
28
|
+
const { event, roomId } = resolveRoomAndEvent(eventOrRoom, maybeRoom);
|
|
29
|
+
const env = getCloudflareEnv(event);
|
|
30
|
+
const binding = env[bindingName];
|
|
31
|
+
if (!binding || typeof binding.idFromName !== "function") {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`[qarpeo.realtime] Durable Object binding "${bindingName}" is not available in the current environment. Ensure "qarpeo.realtime: true" or "qarpeo.do: true" is configured.`
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
const id = binding.idFromName(roomId);
|
|
37
|
+
return binding.get(id);
|
|
38
|
+
}
|
|
39
|
+
export async function broadcastToRoom(eventOrRoom, roomOrEventName, eventNameOrPayload, payloadOrOptions, options) {
|
|
40
|
+
let event;
|
|
41
|
+
let roomId;
|
|
42
|
+
let eventName;
|
|
43
|
+
let payload;
|
|
44
|
+
let opts;
|
|
45
|
+
if (typeof eventOrRoom === "string") {
|
|
46
|
+
event = void 0;
|
|
47
|
+
roomId = eventOrRoom;
|
|
48
|
+
eventName = roomOrEventName;
|
|
49
|
+
payload = eventNameOrPayload;
|
|
50
|
+
opts = payloadOrOptions;
|
|
51
|
+
} else {
|
|
52
|
+
event = eventOrRoom;
|
|
53
|
+
roomId = roomOrEventName;
|
|
54
|
+
eventName = eventNameOrPayload;
|
|
55
|
+
payload = payloadOrOptions;
|
|
56
|
+
opts = options;
|
|
57
|
+
}
|
|
58
|
+
const stub = getRoomDurableObject(event, roomId);
|
|
59
|
+
const res = await stub.fetch("http://internal/broadcast", {
|
|
60
|
+
method: "POST",
|
|
61
|
+
headers: { "Content-Type": "application/json" },
|
|
62
|
+
body: JSON.stringify({
|
|
63
|
+
event: eventName,
|
|
64
|
+
payload,
|
|
65
|
+
sender: opts?.sender || "server",
|
|
66
|
+
excludePeerId: opts?.excludePeerId
|
|
67
|
+
})
|
|
68
|
+
});
|
|
69
|
+
if (!res.ok) {
|
|
70
|
+
const errorText = await res.text().catch(() => "Unknown error");
|
|
71
|
+
throw new Error(`[qarpeo.realtime] broadcastToRoom failed: ${errorText}`);
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
export async function getRoomPresence(eventOrRoom, maybeRoom) {
|
|
76
|
+
const { event, roomId } = resolveRoomAndEvent(eventOrRoom, maybeRoom);
|
|
77
|
+
const stub = getRoomDurableObject(event, roomId);
|
|
78
|
+
const res = await stub.fetch("http://internal/presence", {
|
|
79
|
+
method: "GET"
|
|
80
|
+
});
|
|
81
|
+
if (!res.ok) {
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
const data = await res.json().catch(() => ({ presence: [] }));
|
|
85
|
+
return data.presence || [];
|
|
86
|
+
}
|
|
87
|
+
export async function getRoomHistory(eventOrRoom, maybeRoom, options) {
|
|
88
|
+
let opts = options;
|
|
89
|
+
let finalRoom = maybeRoom;
|
|
90
|
+
if (typeof maybeRoom === "object" && maybeRoom !== null && !options) {
|
|
91
|
+
opts = maybeRoom;
|
|
92
|
+
finalRoom = void 0;
|
|
93
|
+
}
|
|
94
|
+
const { event, roomId } = resolveRoomAndEvent(eventOrRoom, finalRoom);
|
|
95
|
+
const stub = getRoomDurableObject(event, roomId);
|
|
96
|
+
let url = "http://internal/history";
|
|
97
|
+
const params = [];
|
|
98
|
+
if (opts?.limit) params.push(`limit=${opts.limit}`);
|
|
99
|
+
if (opts?.sinceSeq != null) params.push(`sinceSeq=${opts.sinceSeq}`);
|
|
100
|
+
if (opts?.since != null) params.push(`since=${opts.since}`);
|
|
101
|
+
if (params.length > 0) url += `?${params.join("&")}`;
|
|
102
|
+
const res = await stub.fetch(url, {
|
|
103
|
+
method: "GET"
|
|
104
|
+
});
|
|
105
|
+
if (!res.ok) {
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
const data = await res.json().catch(() => ({ history: [] }));
|
|
109
|
+
return data.history || [];
|
|
110
|
+
}
|
|
111
|
+
export async function clearRoomHistory(eventOrRoom, maybeRoom) {
|
|
112
|
+
const { event, roomId } = resolveRoomAndEvent(eventOrRoom, maybeRoom);
|
|
113
|
+
const stub = getRoomDurableObject(event, roomId);
|
|
114
|
+
const res = await stub.fetch("http://internal/history", {
|
|
115
|
+
method: "DELETE"
|
|
116
|
+
});
|
|
117
|
+
return res.ok;
|
|
118
|
+
}
|
|
119
|
+
export async function disconnectRoomUser(eventOrRoom, roomOrUserId, maybeUserId) {
|
|
120
|
+
let event;
|
|
121
|
+
let roomId;
|
|
122
|
+
let userId;
|
|
123
|
+
if (typeof eventOrRoom === "string") {
|
|
124
|
+
event = void 0;
|
|
125
|
+
roomId = eventOrRoom;
|
|
126
|
+
userId = roomOrUserId;
|
|
127
|
+
} else {
|
|
128
|
+
event = eventOrRoom;
|
|
129
|
+
roomId = roomOrUserId;
|
|
130
|
+
userId = maybeUserId || "";
|
|
131
|
+
}
|
|
132
|
+
const stub = getRoomDurableObject(event, roomId);
|
|
133
|
+
const res = await stub.fetch("http://internal/disconnect", {
|
|
134
|
+
method: "POST",
|
|
135
|
+
headers: { "Content-Type": "application/json" },
|
|
136
|
+
body: JSON.stringify({ userId })
|
|
137
|
+
});
|
|
138
|
+
if (!res.ok) {
|
|
139
|
+
return 0;
|
|
140
|
+
}
|
|
141
|
+
const data = await res.json().catch(() => ({ disconnected: 0 }));
|
|
142
|
+
return data.disconnected || 0;
|
|
143
|
+
}
|
|
144
|
+
export async function getRoomState(eventOrRoom, maybeRoom) {
|
|
145
|
+
const { event, roomId } = resolveRoomAndEvent(eventOrRoom, maybeRoom);
|
|
146
|
+
const stub = getRoomDurableObject(event, roomId);
|
|
147
|
+
const res = await stub.fetch("http://internal/state", { method: "GET" });
|
|
148
|
+
if (!res.ok) return {};
|
|
149
|
+
const data = await res.json().catch(() => ({ state: {} }));
|
|
150
|
+
return data.state || {};
|
|
151
|
+
}
|
|
152
|
+
export async function setRoomState(eventOrRoom, roomOrState, maybeState) {
|
|
153
|
+
let event;
|
|
154
|
+
let roomId;
|
|
155
|
+
let state;
|
|
156
|
+
if (typeof eventOrRoom === "string") {
|
|
157
|
+
event = void 0;
|
|
158
|
+
roomId = eventOrRoom;
|
|
159
|
+
state = roomOrState;
|
|
160
|
+
} else {
|
|
161
|
+
event = eventOrRoom;
|
|
162
|
+
roomId = roomOrState;
|
|
163
|
+
state = maybeState;
|
|
164
|
+
}
|
|
165
|
+
const stub = getRoomDurableObject(event, roomId);
|
|
166
|
+
const res = await stub.fetch("http://internal/state", {
|
|
167
|
+
method: "POST",
|
|
168
|
+
headers: { "Content-Type": "application/json" },
|
|
169
|
+
body: JSON.stringify({ state })
|
|
170
|
+
});
|
|
171
|
+
if (!res.ok) throw new Error("[qarpeo.realtime] setRoomState failed");
|
|
172
|
+
const data = await res.json().catch(() => ({ state }));
|
|
173
|
+
return data.state;
|
|
174
|
+
}
|
|
175
|
+
export async function patchRoomState(eventOrRoom, roomOrPatch, maybePatch) {
|
|
176
|
+
let event;
|
|
177
|
+
let roomId;
|
|
178
|
+
let patch;
|
|
179
|
+
if (typeof eventOrRoom === "string") {
|
|
180
|
+
event = void 0;
|
|
181
|
+
roomId = eventOrRoom;
|
|
182
|
+
patch = roomOrPatch;
|
|
183
|
+
} else {
|
|
184
|
+
event = eventOrRoom;
|
|
185
|
+
roomId = roomOrPatch;
|
|
186
|
+
patch = maybePatch;
|
|
187
|
+
}
|
|
188
|
+
const stub = getRoomDurableObject(event, roomId);
|
|
189
|
+
const res = await stub.fetch("http://internal/state", {
|
|
190
|
+
method: "POST",
|
|
191
|
+
headers: { "Content-Type": "application/json" },
|
|
192
|
+
body: JSON.stringify({ patch })
|
|
193
|
+
});
|
|
194
|
+
if (!res.ok) throw new Error("[qarpeo.realtime] patchRoomState failed");
|
|
195
|
+
const data = await res.json().catch(() => ({ state: patch }));
|
|
196
|
+
return data.state;
|
|
197
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { useSession } from "nuxt/server";
|
|
2
|
+
import type { QarpeoUser } from "../../types/auth";
|
|
3
|
+
/**
|
|
4
|
+
* Returns the current authenticated user session data from sealed cookie.
|
|
5
|
+
* Powered by Nuxt 4.6+ native session, with fallback to global session helpers.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getAuthSession<T = any>(event: any): Promise<T>;
|
|
8
|
+
/**
|
|
9
|
+
* Updates the sealed session cookie with user session data.
|
|
10
|
+
* Powered by Nuxt 4.6+ native session, and syncs with global session helpers if present.
|
|
11
|
+
*/
|
|
12
|
+
export declare function setAuthSession(event: any, sessionData: any, config?: any): Promise<any>;
|
|
13
|
+
/**
|
|
14
|
+
* Clears the session cookie.
|
|
15
|
+
* Powered by Nuxt 4.6+ native session, and syncs with global session helpers if present.
|
|
16
|
+
*/
|
|
17
|
+
export declare function clearAuthSession(event: any, config?: any): Promise<boolean>;
|
|
18
|
+
/**
|
|
19
|
+
* Requires an active user session, throwing 401 Unauthorized if not authenticated.
|
|
20
|
+
*/
|
|
21
|
+
export declare function requireAuthSession<T = any>(event: any, opts?: any): Promise<T>;
|
|
22
|
+
export declare const getUserSession: typeof getAuthSession;
|
|
23
|
+
export declare const setUserSession: typeof setAuthSession;
|
|
24
|
+
export declare const clearUserSession: typeof clearAuthSession;
|
|
25
|
+
export declare const requireUserSession: typeof requireAuthSession;
|
|
26
|
+
export { useSession };
|
|
27
|
+
export declare function hashSessionToken(secret: string): Promise<string>;
|
|
28
|
+
export interface CreateDeviceSessionOptions {
|
|
29
|
+
provider?: string;
|
|
30
|
+
maxAge?: number;
|
|
31
|
+
maxSessionsPerUser?: number;
|
|
32
|
+
backend?: "cookie" | "kv";
|
|
33
|
+
}
|
|
34
|
+
export interface DeviceSessionRecord {
|
|
35
|
+
sessionId: string;
|
|
36
|
+
tokenSecret: string;
|
|
37
|
+
tokenHash: string;
|
|
38
|
+
clientType: string;
|
|
39
|
+
userAgent: string | null;
|
|
40
|
+
ipAddress: string | null;
|
|
41
|
+
loggedInAt: number;
|
|
42
|
+
expiresAt: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Creates a new multi-device session, handles LRU eviction if limits are exceeded, and saves into
|
|
46
|
+
* D1 (and KV if backend="kv").
|
|
47
|
+
*/
|
|
48
|
+
export declare function createDeviceSession(event: any, user: QarpeoUser, options?: CreateDeviceSessionOptions): Promise<DeviceSessionRecord>;
|
|
49
|
+
/**
|
|
50
|
+
* Throttled sliding-window update of last_active. Runs at most once every 15 minutes
|
|
51
|
+
* to preserve D1 write quotas.
|
|
52
|
+
*/
|
|
53
|
+
export declare function touchDeviceSession(event: any, session: any): Promise<void>;
|
|
54
|
+
export interface SessionListItem {
|
|
55
|
+
id: string;
|
|
56
|
+
clientType: string;
|
|
57
|
+
userAgent: string | null;
|
|
58
|
+
ipAddress: string | null;
|
|
59
|
+
lastActive: number;
|
|
60
|
+
expiresAt: number;
|
|
61
|
+
isCurrent: boolean;
|
|
62
|
+
}
|
|
63
|
+
/** Lists all active device sessions for a user, sorted by last_active descending. */
|
|
64
|
+
export declare function listDeviceSessions(event: any, userId: string, currentSessionId?: string): Promise<SessionListItem[]>;
|
|
65
|
+
/** Revokes a single session belonging to the user. */
|
|
66
|
+
export declare function revokeDeviceSession(event: any, userId: string, sessionIdToRevoke: string): Promise<boolean>;
|
|
67
|
+
/** Revokes all sessions for the given user. */
|
|
68
|
+
export declare function revokeAllDeviceSessions(event: any, userId: string): Promise<boolean>;
|
|
69
|
+
/** Revokes all sessions for the given user EXCEPT the current active session. */
|
|
70
|
+
export declare function revokeOtherDeviceSessions(event: any, userId: string, currentSessionId?: string): Promise<boolean>;
|
|
71
|
+
/** Validates whether a session ID is still valid in KV (sub-millisecond remote revocation check). */
|
|
72
|
+
export declare function verifyKVSession(event: any, sessionId: string): Promise<boolean>;
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getRequestHeader,
|
|
3
|
+
getSession,
|
|
4
|
+
updateSession,
|
|
5
|
+
clearSession,
|
|
6
|
+
useSession,
|
|
7
|
+
createError
|
|
8
|
+
} from "nuxt/server";
|
|
9
|
+
import { getD1Binding } from "../../db.mjs";
|
|
10
|
+
import { getKVBinding } from "../../kv.mjs";
|
|
11
|
+
export async function getAuthSession(event) {
|
|
12
|
+
try {
|
|
13
|
+
const s = await getSession(event);
|
|
14
|
+
if (s?.data && Object.keys(s.data).length > 0) {
|
|
15
|
+
return s.data;
|
|
16
|
+
}
|
|
17
|
+
} catch {
|
|
18
|
+
}
|
|
19
|
+
if (typeof globalThis.getAuthSession === "function") {
|
|
20
|
+
try {
|
|
21
|
+
return await globalThis.getAuthSession(event);
|
|
22
|
+
} catch {
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (typeof globalThis.getUserSession === "function") {
|
|
26
|
+
try {
|
|
27
|
+
return await globalThis.getUserSession(event);
|
|
28
|
+
} catch {
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
33
|
+
export async function setAuthSession(event, sessionData, config) {
|
|
34
|
+
try {
|
|
35
|
+
await updateSession(event, config, sessionData);
|
|
36
|
+
} catch {
|
|
37
|
+
}
|
|
38
|
+
if (typeof globalThis.setAuthSession === "function") {
|
|
39
|
+
try {
|
|
40
|
+
await globalThis.setAuthSession(event, sessionData, config);
|
|
41
|
+
} catch {
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (typeof globalThis.setUserSession === "function") {
|
|
45
|
+
try {
|
|
46
|
+
await globalThis.setUserSession(event, sessionData, config);
|
|
47
|
+
} catch {
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return sessionData;
|
|
51
|
+
}
|
|
52
|
+
export async function clearAuthSession(event, config) {
|
|
53
|
+
try {
|
|
54
|
+
await clearSession(event, config);
|
|
55
|
+
} catch {
|
|
56
|
+
}
|
|
57
|
+
if (typeof globalThis.clearAuthSession === "function") {
|
|
58
|
+
try {
|
|
59
|
+
await globalThis.clearAuthSession(event, config);
|
|
60
|
+
} catch {
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (typeof globalThis.clearUserSession === "function") {
|
|
64
|
+
try {
|
|
65
|
+
await globalThis.clearUserSession(event, config);
|
|
66
|
+
} catch {
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
export async function requireAuthSession(event, opts) {
|
|
72
|
+
const session = await getAuthSession(event);
|
|
73
|
+
if (!session?.user?.id) {
|
|
74
|
+
if (typeof globalThis.requireAuthSession === "function") {
|
|
75
|
+
return globalThis.requireAuthSession(event, opts);
|
|
76
|
+
}
|
|
77
|
+
if (typeof globalThis.requireUserSession === "function") {
|
|
78
|
+
return globalThis.requireUserSession(event, opts);
|
|
79
|
+
}
|
|
80
|
+
throw createError({
|
|
81
|
+
statusCode: 401,
|
|
82
|
+
statusMessage: "Unauthorized",
|
|
83
|
+
message: "Authentication required"
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return session;
|
|
87
|
+
}
|
|
88
|
+
export const getUserSession = getAuthSession;
|
|
89
|
+
export const setUserSession = setAuthSession;
|
|
90
|
+
export const clearUserSession = clearAuthSession;
|
|
91
|
+
export const requireUserSession = requireAuthSession;
|
|
92
|
+
export { useSession };
|
|
93
|
+
export async function hashSessionToken(secret) {
|
|
94
|
+
const encoder = new TextEncoder();
|
|
95
|
+
const data = encoder.encode(secret);
|
|
96
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
|
97
|
+
return Array.from(new Uint8Array(hashBuffer)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
98
|
+
}
|
|
99
|
+
export async function createDeviceSession(event, user, options = {}) {
|
|
100
|
+
const sessionId = crypto.randomUUID();
|
|
101
|
+
const tokenSecret = crypto.randomUUID();
|
|
102
|
+
const tokenHash = await hashSessionToken(tokenSecret);
|
|
103
|
+
const clientType = getRequestHeader(event, "x-client-type") || "web";
|
|
104
|
+
const userAgent = getRequestHeader(event, "user-agent") || null;
|
|
105
|
+
const ipAddress = getRequestHeader(event, "cf-connecting-ip") || getRequestHeader(event, "x-forwarded-for")?.split(",")[0]?.trim() || null;
|
|
106
|
+
const now = Date.now();
|
|
107
|
+
const maxAge = options.maxAge || 604800;
|
|
108
|
+
const expiresAt = now + maxAge * 1e3;
|
|
109
|
+
const maxSessions = options.maxSessionsPerUser ?? 5;
|
|
110
|
+
let d1;
|
|
111
|
+
try {
|
|
112
|
+
const bindingName = globalThis.process?.env?.QARPEO_DEFAULT_DB_BINDING || "DB";
|
|
113
|
+
d1 = getD1Binding(bindingName, event);
|
|
114
|
+
} catch {
|
|
115
|
+
d1 = null;
|
|
116
|
+
}
|
|
117
|
+
if (d1) {
|
|
118
|
+
await d1.prepare(`
|
|
119
|
+
INSERT INTO _qarpeo_sessions (id, user_id, token_hash, client_type, user_agent, ip_address, last_active, expires_at)
|
|
120
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
121
|
+
`).bind(sessionId, user.id, tokenHash, clientType, userAgent, ipAddress, now, expiresAt).run();
|
|
122
|
+
if (maxSessions > 0) {
|
|
123
|
+
const activeSessions = await d1.prepare("SELECT id FROM _qarpeo_sessions WHERE user_id = ? ORDER BY last_active ASC").bind(user.id).all();
|
|
124
|
+
const results = activeSessions.results || [];
|
|
125
|
+
if (results.length > maxSessions) {
|
|
126
|
+
const excessCount = results.length - maxSessions;
|
|
127
|
+
const toEvict = results.slice(0, excessCount).map((r) => r.id);
|
|
128
|
+
for (const evictId of toEvict) {
|
|
129
|
+
await d1.prepare("DELETE FROM _qarpeo_sessions WHERE id = ?").bind(evictId).run();
|
|
130
|
+
if (options.backend === "kv") {
|
|
131
|
+
try {
|
|
132
|
+
const kv = getKVBinding("KV", event);
|
|
133
|
+
await kv.delete(`session:${evictId}`);
|
|
134
|
+
} catch {
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (options.backend === "kv") {
|
|
142
|
+
try {
|
|
143
|
+
const kv = getKVBinding("KV", event);
|
|
144
|
+
const kvPayload = {
|
|
145
|
+
sessionId,
|
|
146
|
+
tokenHash,
|
|
147
|
+
userId: user.id,
|
|
148
|
+
user,
|
|
149
|
+
clientType,
|
|
150
|
+
ipAddress,
|
|
151
|
+
userAgent,
|
|
152
|
+
expiresAt,
|
|
153
|
+
loggedInAt: now,
|
|
154
|
+
tenantId: event?.context?.tenant?.id ?? null
|
|
155
|
+
};
|
|
156
|
+
await kv.put(`session:${sessionId}`, JSON.stringify(kvPayload), {
|
|
157
|
+
expirationTtl: maxAge
|
|
158
|
+
});
|
|
159
|
+
} catch (err) {
|
|
160
|
+
console.warn("[qarpeo] Failed to store session in KV:", err.message);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
sessionId,
|
|
165
|
+
tokenSecret,
|
|
166
|
+
tokenHash,
|
|
167
|
+
clientType,
|
|
168
|
+
userAgent,
|
|
169
|
+
ipAddress,
|
|
170
|
+
loggedInAt: now,
|
|
171
|
+
expiresAt
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
export async function touchDeviceSession(event, session) {
|
|
175
|
+
if (!session?.sessionId) return;
|
|
176
|
+
const now = Date.now();
|
|
177
|
+
const fifteenMinutes = 15 * 60 * 1e3;
|
|
178
|
+
if (session.lastActiveUpdated && now - session.lastActiveUpdated < fifteenMinutes) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
session.lastActiveUpdated = now;
|
|
182
|
+
const updateTask = async () => {
|
|
183
|
+
try {
|
|
184
|
+
const bindingName = globalThis.process?.env?.QARPEO_DEFAULT_DB_BINDING || "DB";
|
|
185
|
+
const d1 = getD1Binding(bindingName, event);
|
|
186
|
+
await d1.prepare("UPDATE _qarpeo_sessions SET last_active = ? WHERE id = ?").bind(now, session.sessionId).run();
|
|
187
|
+
} catch {
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
const ctx = event.context?.cloudflare?.context;
|
|
191
|
+
if (ctx && typeof ctx.waitUntil === "function") {
|
|
192
|
+
ctx.waitUntil(updateTask());
|
|
193
|
+
} else {
|
|
194
|
+
updateTask().catch(() => {
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
export async function listDeviceSessions(event, userId, currentSessionId) {
|
|
199
|
+
try {
|
|
200
|
+
const bindingName = globalThis.process?.env?.QARPEO_DEFAULT_DB_BINDING || "DB";
|
|
201
|
+
const d1 = getD1Binding(bindingName, event);
|
|
202
|
+
const res = await d1.prepare(
|
|
203
|
+
"SELECT id, client_type, user_agent, ip_address, last_active, expires_at FROM _qarpeo_sessions WHERE user_id = ? ORDER BY last_active DESC"
|
|
204
|
+
).bind(userId).all();
|
|
205
|
+
const rows = res.results || [];
|
|
206
|
+
return rows.map((r) => ({
|
|
207
|
+
id: r.id,
|
|
208
|
+
clientType: r.client_type || "web",
|
|
209
|
+
userAgent: r.user_agent || null,
|
|
210
|
+
ipAddress: r.ip_address || null,
|
|
211
|
+
lastActive: r.last_active,
|
|
212
|
+
expiresAt: r.expires_at,
|
|
213
|
+
isCurrent: r.id === currentSessionId
|
|
214
|
+
}));
|
|
215
|
+
} catch {
|
|
216
|
+
return [];
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
export async function revokeDeviceSession(event, userId, sessionIdToRevoke) {
|
|
220
|
+
try {
|
|
221
|
+
const bindingName = globalThis.process?.env?.QARPEO_DEFAULT_DB_BINDING || "DB";
|
|
222
|
+
const d1 = getD1Binding(bindingName, event);
|
|
223
|
+
await d1.prepare("DELETE FROM _qarpeo_sessions WHERE id = ? AND user_id = ?").bind(sessionIdToRevoke, userId).run();
|
|
224
|
+
try {
|
|
225
|
+
const kv = getKVBinding("KV", event);
|
|
226
|
+
await kv.delete(`session:${sessionIdToRevoke}`);
|
|
227
|
+
} catch {
|
|
228
|
+
}
|
|
229
|
+
return true;
|
|
230
|
+
} catch {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
export async function revokeAllDeviceSessions(event, userId) {
|
|
235
|
+
try {
|
|
236
|
+
const bindingName = globalThis.process?.env?.QARPEO_DEFAULT_DB_BINDING || "DB";
|
|
237
|
+
const d1 = getD1Binding(bindingName, event);
|
|
238
|
+
const res = await d1.prepare("SELECT id FROM _qarpeo_sessions WHERE user_id = ?").bind(userId).all();
|
|
239
|
+
const sessionIds = (res.results || []).map((r) => r.id);
|
|
240
|
+
await d1.prepare("DELETE FROM _qarpeo_sessions WHERE user_id = ?").bind(userId).run();
|
|
241
|
+
try {
|
|
242
|
+
const kv = getKVBinding("KV", event);
|
|
243
|
+
for (const id of sessionIds) {
|
|
244
|
+
await kv.delete(`session:${id}`);
|
|
245
|
+
}
|
|
246
|
+
} catch {
|
|
247
|
+
}
|
|
248
|
+
return true;
|
|
249
|
+
} catch {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
export async function revokeOtherDeviceSessions(event, userId, currentSessionId) {
|
|
254
|
+
if (!currentSessionId) return false;
|
|
255
|
+
try {
|
|
256
|
+
const bindingName = globalThis.process?.env?.QARPEO_DEFAULT_DB_BINDING || "DB";
|
|
257
|
+
const d1 = getD1Binding(bindingName, event);
|
|
258
|
+
const res = await d1.prepare("SELECT id FROM _qarpeo_sessions WHERE user_id = ? AND id != ?").bind(userId, currentSessionId).all();
|
|
259
|
+
const sessionIds = (res.results || []).map((r) => r.id);
|
|
260
|
+
await d1.prepare("DELETE FROM _qarpeo_sessions WHERE user_id = ? AND id != ?").bind(userId, currentSessionId).run();
|
|
261
|
+
try {
|
|
262
|
+
const kv = getKVBinding("KV", event);
|
|
263
|
+
for (const id of sessionIds) {
|
|
264
|
+
await kv.delete(`session:${id}`);
|
|
265
|
+
}
|
|
266
|
+
} catch {
|
|
267
|
+
}
|
|
268
|
+
return true;
|
|
269
|
+
} catch {
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
export async function verifyKVSession(event, sessionId) {
|
|
274
|
+
try {
|
|
275
|
+
const kv = getKVBinding("KV", event);
|
|
276
|
+
const data = await kv.get(`session:${sessionId}`, { type: "json" });
|
|
277
|
+
if (!data) return false;
|
|
278
|
+
const sessionTenantId = data.tenantId ?? null;
|
|
279
|
+
const requestTenantId = event?.context?.tenant?.id ?? null;
|
|
280
|
+
if (sessionTenantId && requestTenantId && sessionTenantId !== requestTenantId) {
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
return true;
|
|
284
|
+
} catch {
|
|
285
|
+
return true;
|
|
286
|
+
}
|
|
287
|
+
}
|