qarpeo 0.1.35 → 0.2.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/README.md +114 -26
- package/dist/apps/cms.d.ts +4 -0
- package/dist/apps/comments.d.ts +4 -0
- package/dist/apps/payments.d.ts +4 -0
- package/dist/apps/store.d.ts +4 -0
- package/dist/chunks/auth-schema.mjs +169 -30
- package/dist/chunks/tools.mjs +1680 -0
- package/dist/cli/index.mjs +1256 -221
- package/dist/core/aliases.d.ts +5 -0
- package/dist/core/context.d.ts +10 -0
- package/dist/core/cross-drive.d.ts +2 -0
- package/dist/core/d1-migrate.d.ts +4 -0
- package/dist/core/devtools.d.ts +4 -0
- package/dist/core/nitro.d.ts +4 -0
- package/dist/core/schema.d.ts +4 -0
- package/dist/core/server-utils.d.ts +4 -0
- package/dist/core/wrangler.d.ts +4 -0
- package/dist/dev/wrangler.d.ts +1 -0
- package/dist/fate/index.d.ts +8 -8
- package/dist/features/agents.d.ts +4 -0
- package/dist/features/auth.d.ts +4 -0
- package/dist/features/bots.d.ts +4 -0
- package/dist/features/fate.d.ts +4 -0
- package/dist/features/mail.d.ts +4 -0
- package/dist/features/mcp.d.ts +4 -0
- package/dist/features/multitenant.d.ts +4 -0
- package/dist/features/notifications.d.ts +4 -0
- package/dist/features/realtime.d.ts +4 -0
- package/dist/module.d.ts +10 -2
- package/dist/module.mjs +6313 -5118
- package/dist/primitives/ai.d.ts +4 -0
- package/dist/primitives/analytics.d.ts +4 -0
- package/dist/primitives/blob.d.ts +4 -0
- package/dist/primitives/browser.d.ts +4 -0
- package/dist/primitives/cache.d.ts +4 -0
- package/dist/primitives/d1.d.ts +4 -0
- package/dist/primitives/do.d.ts +4 -0
- package/dist/primitives/email.d.ts +4 -0
- package/dist/primitives/hyperdrive.d.ts +4 -0
- package/dist/primitives/kv.d.ts +4 -0
- package/dist/primitives/queue.d.ts +4 -0
- package/dist/primitives/ratelimit.d.ts +4 -0
- package/dist/primitives/vectorize.d.ts +4 -0
- package/dist/primitives/workflows.d.ts +4 -0
- package/dist/runtime/ai.d.ts +3 -3
- package/dist/runtime/ai.mjs +8 -1
- package/dist/runtime/app/components/RealtimeCursors.vue +2 -2
- package/dist/runtime/app/composables/ai.d.ts +56 -29
- package/dist/runtime/app/composables/analytics.d.ts +26 -106
- package/dist/runtime/app/composables/api-tokens.d.ts +31 -34
- package/dist/runtime/app/composables/auth.d.ts +147 -51
- package/dist/runtime/app/composables/auth.mjs +0 -7
- package/dist/runtime/app/composables/chat.d.ts +38 -35
- package/dist/runtime/app/composables/cms-preview.d.ts +30 -25
- package/dist/runtime/app/composables/cms.d.ts +57 -282
- package/dist/runtime/app/composables/cms.mjs +0 -35
- package/dist/runtime/app/composables/comments.d.ts +32 -5
- package/dist/runtime/app/composables/comments.mjs +29 -1
- package/dist/runtime/app/composables/docs-version.d.ts +25 -28
- package/dist/runtime/app/composables/impersonation.d.ts +22 -5
- package/dist/runtime/app/composables/organization.d.ts +38 -91
- package/dist/runtime/app/composables/passkey.d.ts +22 -6
- package/dist/runtime/app/composables/passwordless.d.ts +24 -7
- package/dist/runtime/app/composables/payments.d.ts +50 -34
- package/dist/runtime/app/composables/payments.mjs +1 -0
- package/dist/runtime/app/composables/sse.d.ts +76 -0
- package/dist/runtime/app/composables/sse.mjs +152 -0
- package/dist/runtime/app/composables/storage.d.ts +53 -65
- package/dist/runtime/app/composables/storage.mjs +17 -0
- package/dist/runtime/app/composables/store.d.ts +198 -0
- package/dist/runtime/app/composables/store.mjs +414 -0
- package/dist/runtime/app/composables/tenant.d.ts +31 -72
- package/dist/runtime/app/composables/turnstile.d.ts +16 -3
- package/dist/runtime/app/composables/two-factor.d.ts +23 -6
- package/dist/runtime/app/pages/devtools/notifications.vue +30 -27
- package/dist/runtime/app/pages/devtools/realtime.vue +19 -31
- package/dist/runtime/app/pages/devtools.vue +0 -7
- package/dist/runtime/auth.d.ts +9 -9
- package/dist/runtime/blob.d.ts +10 -1
- package/dist/runtime/blob.mjs +83 -0
- package/dist/runtime/cache.d.ts +48 -0
- package/dist/runtime/cache.mjs +92 -0
- package/dist/runtime/comments.d.ts +4 -0
- package/dist/runtime/comments.mjs +2 -0
- package/dist/runtime/db.d.ts +21 -1
- package/dist/runtime/db.mjs +54 -0
- package/dist/runtime/drizzle.d.ts +4 -2
- package/dist/runtime/drizzle.mjs +68 -1
- package/dist/runtime/durable-object.d.ts +2 -0
- package/dist/runtime/durable-object.mjs +2 -0
- package/dist/runtime/email.d.ts +1 -1
- package/dist/runtime/email.mjs +1 -1
- package/dist/runtime/kv.mjs +50 -1
- package/dist/runtime/mcp.d.ts +2 -0
- package/dist/runtime/mcp.mjs +2 -0
- package/dist/runtime/queue.d.ts +12 -2
- package/dist/runtime/queue.mjs +19 -1
- package/dist/runtime/ratelimit.d.ts +1 -0
- package/dist/runtime/ratelimit.mjs +7 -0
- package/dist/runtime/schema.d.ts +313 -0
- package/dist/runtime/schema.mjs +259 -0
- package/dist/runtime/server/db/cms-schema.d.ts +1225 -171
- package/dist/runtime/server/db/cms-schema.mjs +69 -70
- package/dist/runtime/server/db/store-schema.d.ts +4344 -0
- package/dist/runtime/server/db/store-schema.mjs +266 -0
- package/dist/runtime/server/durable-objects/agent.mjs +35 -0
- package/dist/runtime/server/durable-objects/room.mjs +0 -1
- package/dist/runtime/server/middleware/ratelimit.mjs +10 -8
- package/dist/runtime/server/plugins/comments.d.ts +7 -0
- package/dist/runtime/server/plugins/comments.mjs +7 -0
- package/dist/runtime/server/plugins/email-inbound.d.ts +5 -0
- package/dist/runtime/server/plugins/email-inbound.mjs +17 -0
- package/dist/runtime/server/plugins/store.d.ts +7 -0
- package/dist/runtime/server/plugins/store.mjs +7 -0
- package/dist/runtime/server/routes/__qarpeo/db/tables.get.mjs +2 -2
- package/dist/runtime/server/routes/atom.xml.get.mjs +3 -1
- package/dist/runtime/server/routes/auth/2fa/disable.post.mjs +13 -2
- package/dist/runtime/server/routes/auth/2fa/setup.post.mjs +9 -3
- package/dist/runtime/server/routes/auth/2fa/verify.post.mjs +11 -3
- package/dist/runtime/server/routes/auth/account.delete.mjs +2 -1
- package/dist/runtime/server/routes/auth/audit-logs.get.mjs +1 -1
- package/dist/runtime/server/routes/auth/magic-link/send.post.d.ts +1 -9
- package/dist/runtime/server/routes/auth/magic-link/send.post.mjs +8 -0
- package/dist/runtime/server/routes/auth/organization/sso/[id].delete.mjs +1 -1
- package/dist/runtime/server/routes/auth/organization/sso/index.get.mjs +1 -1
- package/dist/runtime/server/routes/auth/organization/sso/index.post.mjs +1 -1
- package/dist/runtime/server/routes/auth/otp/send.post.d.ts +1 -9
- package/dist/runtime/server/routes/auth/otp/send.post.mjs +8 -0
- package/dist/runtime/server/routes/auth/sso/login.get.mjs +3 -3
- package/dist/runtime/server/routes/auth/sso/oidc/callback.get.mjs +1 -1
- package/dist/runtime/server/routes/auth/sso/saml/acs.post.mjs +2 -2
- package/dist/runtime/server/routes/auth/webauthn/login/options.post.mjs +1 -1
- package/dist/runtime/server/routes/auth/webauthn/login/verify.post.mjs +1 -1
- package/dist/runtime/server/routes/auth/webauthn/register/options.post.mjs +2 -2
- package/dist/runtime/server/routes/auth/webauthn/register/verify.post.mjs +1 -1
- package/dist/runtime/server/routes/cms/[collection]/[id]/preview-token.post.mjs +1 -1
- package/dist/runtime/server/routes/cms/[collection]/atom.xml.get.mjs +3 -1
- package/dist/runtime/server/routes/cms/[collection]/feed.xml.get.mjs +3 -1
- package/dist/runtime/server/routes/cms/bookmarks/[id].delete.mjs +1 -1
- package/dist/runtime/server/routes/cms/bookmarks/check.post.mjs +1 -1
- package/dist/runtime/server/routes/cms/bookmarks/index.get.mjs +1 -1
- package/dist/runtime/server/routes/cms/bookmarks/index.post.mjs +1 -1
- package/dist/runtime/server/routes/cms/deploy.post.mjs +1 -1
- package/dist/runtime/server/routes/cms/export.post.mjs +4 -3
- package/dist/runtime/server/routes/cms/search.get.mjs +7 -5
- package/dist/runtime/server/routes/cms/sync.post.mjs +2 -1
- package/dist/runtime/server/routes/comments/[id]/react.post.mjs +1 -2
- package/dist/runtime/server/routes/comments/[id]/report.post.d.ts +1 -1
- package/dist/runtime/server/routes/comments/[id]/report.post.mjs +0 -2
- package/dist/runtime/server/routes/comments/[id].delete.mjs +8 -4
- package/dist/runtime/server/routes/comments/[id].get.d.ts +1 -1
- package/dist/runtime/server/routes/comments/[id].get.mjs +1 -2
- package/dist/runtime/server/routes/comments/[id].patch.d.ts +1 -1
- package/dist/runtime/server/routes/comments/[id].patch.mjs +6 -3
- package/dist/runtime/server/routes/comments/batch.post.d.ts +2 -0
- package/dist/runtime/server/routes/comments/batch.post.mjs +33 -0
- package/dist/runtime/server/routes/comments/index.get.d.ts +1 -1
- package/dist/runtime/server/routes/comments/index.get.mjs +6 -4
- package/dist/runtime/server/routes/comments/index.post.d.ts +1 -1
- package/dist/runtime/server/routes/comments/index.post.mjs +6 -2
- package/dist/runtime/server/routes/feed.xml.get.mjs +3 -1
- package/dist/runtime/server/routes/sitemap.xml.get.mjs +3 -1
- package/dist/runtime/server/routes/storage/presigned-r2.post.d.ts +17 -0
- package/dist/runtime/server/routes/storage/presigned-r2.post.mjs +29 -0
- package/dist/runtime/server/routes/store/cart/index.delete.d.ts +6 -0
- package/dist/runtime/server/routes/store/cart/index.delete.mjs +11 -0
- package/dist/runtime/server/routes/store/cart/index.get.d.ts +5 -0
- package/dist/runtime/server/routes/store/cart/index.get.mjs +14 -0
- package/dist/runtime/server/routes/store/cart/items/[id].delete.d.ts +6 -0
- package/dist/runtime/server/routes/store/cart/items/[id].delete.mjs +25 -0
- package/dist/runtime/server/routes/store/cart/items/[id].patch.d.ts +6 -0
- package/dist/runtime/server/routes/store/cart/items/[id].patch.mjs +29 -0
- package/dist/runtime/server/routes/store/cart/items.post.d.ts +6 -0
- package/dist/runtime/server/routes/store/cart/items.post.mjs +36 -0
- package/dist/runtime/server/routes/store/categories/index.get.d.ts +2 -0
- package/dist/runtime/server/routes/store/categories/index.get.mjs +8 -0
- package/dist/runtime/server/routes/store/checkout.post.d.ts +6 -0
- package/dist/runtime/server/routes/store/checkout.post.mjs +21 -0
- package/dist/runtime/server/routes/store/coupons/apply.post.d.ts +7 -0
- package/dist/runtime/server/routes/store/coupons/apply.post.mjs +18 -0
- package/dist/runtime/server/routes/store/currencies.get.d.ts +15 -0
- package/dist/runtime/server/routes/store/currencies.get.mjs +13 -0
- package/dist/runtime/server/routes/store/orders/[id].get.d.ts +2 -0
- package/dist/runtime/server/routes/store/orders/[id].get.mjs +26 -0
- package/dist/runtime/server/routes/store/orders/download/[token].get.d.ts +7 -0
- package/dist/runtime/server/routes/store/orders/download/[token].get.mjs +57 -0
- package/dist/runtime/server/routes/store/orders/index.get.d.ts +5 -0
- package/dist/runtime/server/routes/store/orders/index.get.mjs +30 -0
- package/dist/runtime/server/routes/store/products/[slug].get.d.ts +2 -0
- package/dist/runtime/server/routes/store/products/[slug].get.mjs +18 -0
- package/dist/runtime/server/routes/store/products/index.get.d.ts +5 -0
- package/dist/runtime/server/routes/store/products/index.get.mjs +33 -0
- package/dist/runtime/server/routes/store/tax/calculate.post.d.ts +9 -0
- package/dist/runtime/server/routes/store/tax/calculate.post.mjs +18 -0
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/index.delete.mjs +14 -1
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/verify.post.mjs +14 -1
- package/dist/runtime/server/routes/tenants/[tenant]/domains/index.get.mjs +24 -1
- package/dist/runtime/server/routes/tenants/[tenant]/domains/index.post.mjs +6 -0
- package/dist/runtime/server/utils/ai.d.ts +146 -21
- package/dist/runtime/server/utils/ai.mjs +406 -11
- package/dist/runtime/server/utils/analytics-query.d.ts +13 -58
- package/dist/runtime/server/utils/audit.d.ts +5 -4
- package/dist/runtime/server/utils/audit.mjs +25 -14
- package/dist/runtime/server/utils/auth.d.ts +29 -12
- package/dist/runtime/server/utils/auth.mjs +88 -70
- package/dist/runtime/server/utils/bots.d.ts +20 -4
- package/dist/runtime/server/utils/bots.mjs +7 -3
- package/dist/runtime/server/utils/browser-utils.d.ts +23 -23
- package/dist/runtime/server/utils/cache.d.ts +3 -3
- package/dist/runtime/server/utils/cms/collections.d.ts +23 -0
- package/dist/runtime/server/utils/cms/collections.mjs +143 -0
- package/dist/runtime/server/utils/cms/common.d.ts +9 -0
- package/dist/runtime/server/utils/cms/common.mjs +28 -0
- package/dist/runtime/server/utils/cms/git.mjs +2 -2
- package/dist/runtime/server/utils/cms/navigation.d.ts +46 -0
- package/dist/runtime/server/utils/cms/navigation.mjs +683 -0
- package/dist/runtime/server/utils/cms/preview.d.ts +11 -0
- package/dist/runtime/server/utils/cms/preview.mjs +50 -0
- package/dist/runtime/server/utils/cms/search.d.ts +1 -1
- package/dist/runtime/server/utils/cms/search.mjs +11 -7
- package/dist/runtime/server/utils/cms/sync.d.ts +34 -0
- package/dist/runtime/server/utils/cms/sync.mjs +1082 -0
- package/dist/runtime/server/utils/cms/taxonomy.d.ts +103 -0
- package/dist/runtime/server/utils/cms/taxonomy.mjs +348 -0
- package/dist/runtime/server/utils/cms.d.ts +13 -249
- package/dist/runtime/server/utils/cms.mjs +108 -2350
- package/dist/runtime/server/utils/comments-filter.d.ts +45 -0
- package/dist/runtime/server/utils/comments-filter.mjs +541 -0
- package/dist/runtime/server/utils/comments.d.ts +71 -0
- package/dist/runtime/server/utils/comments.mjs +137 -61
- package/dist/runtime/server/utils/config.d.ts +4 -3
- package/dist/runtime/server/utils/config.mjs +7 -6
- package/dist/runtime/server/utils/context.d.ts +14 -0
- package/dist/runtime/server/utils/context.mjs +2 -2
- package/dist/runtime/server/utils/crypto.d.ts +44 -5
- package/dist/runtime/server/utils/crypto.mjs +18 -0
- package/dist/runtime/server/utils/domains.mjs +9 -5
- package/dist/runtime/server/utils/drizzle.d.ts +35 -3
- package/dist/runtime/server/utils/drizzle.mjs +115 -6
- package/dist/runtime/server/utils/durable-object.d.ts +106 -0
- package/dist/runtime/server/utils/durable-object.mjs +628 -0
- package/dist/runtime/server/utils/email-inbound.d.ts +29 -0
- package/dist/runtime/server/utils/email-inbound.mjs +76 -0
- package/dist/runtime/server/utils/impersonation.d.ts +32 -2
- package/dist/runtime/server/utils/impersonation.mjs +16 -13
- package/dist/runtime/server/utils/lock.d.ts +71 -0
- package/dist/runtime/server/utils/lock.mjs +139 -0
- package/dist/runtime/server/utils/mail-suppression.mjs +7 -7
- package/dist/runtime/server/utils/mail.d.ts +30 -19
- package/dist/runtime/server/utils/mcp.d.ts +44 -0
- package/dist/runtime/server/utils/mcp.mjs +308 -0
- package/dist/runtime/server/utils/notifications.d.ts +72 -7
- package/dist/runtime/server/utils/notifications.mjs +67 -55
- package/dist/runtime/server/utils/oauth.d.ts +27 -4
- package/dist/runtime/server/utils/organization.d.ts +63 -7
- package/dist/runtime/server/utils/organization.mjs +26 -21
- package/dist/runtime/server/utils/passwordless.d.ts +62 -33
- package/dist/runtime/server/utils/payments.d.ts +51 -12
- package/dist/runtime/server/utils/payments.mjs +472 -282
- package/dist/runtime/server/utils/queue.d.ts +106 -13
- package/dist/runtime/server/utils/queue.mjs +313 -28
- package/dist/runtime/server/utils/rag.d.ts +42 -14
- package/dist/runtime/server/utils/rag.mjs +169 -4
- package/dist/runtime/server/utils/ratelimit.d.ts +34 -5
- package/dist/runtime/server/utils/ratelimit.mjs +95 -14
- package/dist/runtime/server/utils/realtime.d.ts +68 -52
- package/dist/runtime/server/utils/scheduled-task.d.ts +42 -1
- package/dist/runtime/server/utils/scheduled-task.mjs +29 -0
- package/dist/runtime/server/utils/schema-fallback.d.ts +1 -1
- package/dist/runtime/server/utils/schema-fallback.mjs +1 -1
- package/dist/runtime/server/utils/session.d.ts +84 -10
- package/dist/runtime/server/utils/session.mjs +12 -10
- package/dist/runtime/server/utils/sse.d.ts +75 -0
- package/dist/runtime/server/utils/sse.mjs +147 -0
- package/dist/runtime/server/utils/sso.d.ts +1 -1
- package/dist/runtime/server/utils/storage.d.ts +53 -4
- package/dist/runtime/server/utils/storage.mjs +15 -11
- package/dist/runtime/server/utils/store-localization.d.ts +51 -0
- package/dist/runtime/server/utils/store-localization.mjs +417 -0
- package/dist/runtime/server/utils/store.d.ts +207 -0
- package/dist/runtime/server/utils/store.mjs +2227 -0
- package/dist/runtime/server/utils/table-names.d.ts +51 -0
- package/dist/runtime/server/utils/table-names.mjs +69 -0
- package/dist/runtime/server/utils/tenant.d.ts +26 -2
- package/dist/runtime/server/utils/tenant.mjs +16 -12
- package/dist/runtime/server/utils/tools-registry-fallback.d.ts +1 -0
- package/dist/runtime/server/utils/tools-registry-fallback.mjs +1 -0
- package/dist/runtime/server/utils/totp.d.ts +45 -2
- package/dist/runtime/server/utils/tracker.d.ts +10 -11
- package/dist/runtime/server/utils/turnstile.d.ts +16 -1
- package/dist/runtime/server/utils/workflows.d.ts +92 -0
- package/dist/runtime/server/utils/workflows.mjs +299 -0
- package/dist/runtime/server.d.ts +8 -1
- package/dist/runtime/server.mjs +8 -5
- package/dist/runtime/service.d.ts +10 -10
- package/dist/runtime/storage.d.ts +1 -0
- package/dist/runtime/storage.mjs +1 -0
- package/dist/runtime/store.d.ts +4 -0
- package/dist/runtime/store.mjs +2 -0
- package/dist/runtime/test-utils.d.ts +11 -10
- package/dist/runtime/test-utils.mjs +64 -4
- package/dist/runtime/types/ai.d.ts +21 -2
- package/dist/runtime/types/d1.d.ts +17 -0
- package/dist/runtime/types/drizzle.d.ts +2 -2
- package/dist/runtime/types/durable-object.d.ts +62 -2
- package/dist/runtime/types/email.d.ts +46 -0
- package/dist/runtime/types/imports.d.ts +6 -1
- package/dist/runtime/types/index.d.ts +58 -0
- package/dist/runtime/types/index.mjs +3 -0
- package/dist/runtime/types/mcp.d.ts +83 -0
- package/dist/runtime/types/mcp.mjs +0 -0
- package/dist/runtime/types/queue.d.ts +36 -0
- package/dist/runtime/types/r2.d.ts +41 -0
- package/dist/runtime/types/store.d.ts +313 -0
- package/dist/runtime/types/store.mjs +0 -0
- package/dist/runtime/types/workflows.d.ts +98 -0
- package/dist/runtime/types/workflows.mjs +0 -0
- package/dist/runtime/workflows.d.ts +5 -0
- package/dist/runtime/workflows.mjs +2 -0
- package/dist/types/ai.d.ts +721 -0
- package/dist/types/cms.d.ts +710 -0
- package/dist/types.d.ts +406 -1288
- package/dist/utils/auth-schema.d.ts +3 -2
- package/dist/utils/bots.d.ts +20 -0
- package/dist/utils/comments-schema.d.ts +5 -4
- package/dist/utils/drizzle.d.ts +83 -3
- package/dist/utils/durable-objects.d.ts +10 -0
- package/dist/utils/email-inbound.d.ts +10 -0
- package/dist/utils/local-db.d.ts +1 -3
- package/dist/utils/mcp.d.ts +24 -0
- package/dist/utils/notifications-schema.d.ts +5 -4
- package/dist/utils/payments-schema.d.ts +4 -3
- package/dist/utils/store-schema.d.ts +14 -0
- package/dist/utils/table-names.d.ts +1 -0
- package/dist/utils/tenants-schema.d.ts +4 -3
- package/dist/utils/tools.d.ts +20 -0
- package/dist/utils/workflows.d.ts +8 -0
- package/package.json +34 -4
- package/dist/chunks/wrangler.mjs +0 -897
- package/dist/runtime/app/components/AuthRegister.vue +0 -306
- package/dist/runtime/app/components/AuthSessionsList.vue +0 -137
- package/dist/runtime/app/components/AuthSignIn.vue +0 -298
- package/dist/runtime/app/components/CMSBookmarkButton.vue +0 -59
- package/dist/runtime/app/components/CMSImage.vue +0 -47
- package/dist/runtime/app/components/CMSLocaleSwitcher.vue +0 -110
- package/dist/runtime/app/components/CMSNewsletter.vue +0 -81
- package/dist/runtime/app/components/CMSPreviewBanner.vue +0 -83
- package/dist/runtime/app/components/CMSTableOfContents.vue +0 -84
- package/dist/runtime/app/components/CMSVersionBanner.vue +0 -53
- package/dist/runtime/app/components/CMSVersionSwitcher.vue +0 -140
- package/dist/runtime/app/components/Comments.vue +0 -411
- package/dist/runtime/app/components/FileUpload.vue +0 -200
- package/dist/runtime/app/components/ImpersonationBanner.vue +0 -61
- package/dist/runtime/app/components/NotificationBell.vue +0 -263
- package/dist/runtime/app/components/NotificationList.vue +0 -205
- package/dist/runtime/app/components/NotificationPrompt.vue +0 -133
- package/dist/runtime/app/components/PricingGated.vue +0 -81
- package/dist/runtime/app/components/PricingTable.vue +0 -274
- package/dist/runtime/app/components/RealtimeChat.vue +0 -164
- package/dist/runtime/app/components/RealtimePresence.vue +0 -129
- package/dist/runtime/app/components/RealtimeStatus.vue +0 -79
- package/dist/runtime/app/components/SubscriptionCard.vue +0 -207
- package/dist/runtime/app/components/UserProfile.vue +0 -558
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getVectorizeBinding } from "../../vectorize.mjs";
|
|
2
|
+
import { getR2Binding } from "../../blob.mjs";
|
|
2
3
|
import { embedText, generateText, defineTool } from "./ai.mjs";
|
|
3
4
|
const GLOBAL_RAG_KEY = "__qarpeo_dev_mock_rag__";
|
|
4
5
|
function getDevMockRAGStore() {
|
|
@@ -77,6 +78,7 @@ export function splitTextIntoChunks(text, options) {
|
|
|
77
78
|
}
|
|
78
79
|
return splitRecursive(cleanText, 0).map((c) => c.trim()).filter((c) => c.length > 0);
|
|
79
80
|
}
|
|
81
|
+
const _docChunkCounts = /* @__PURE__ */ new Map();
|
|
80
82
|
export function createRAGPipeline(config) {
|
|
81
83
|
const bindingName = config?.binding || "VECTORIZE";
|
|
82
84
|
const aiBindingName = config?.aiBinding || "AI";
|
|
@@ -156,6 +158,7 @@ export function createRAGPipeline(config) {
|
|
|
156
158
|
}
|
|
157
159
|
mutationId = `mock_mut_${Date.now()}`;
|
|
158
160
|
}
|
|
161
|
+
_docChunkCounts.set(doc.id, vectors.length);
|
|
159
162
|
return { chunksIndexed: vectors.length, mutationId };
|
|
160
163
|
},
|
|
161
164
|
async indexDocuments(docs, options) {
|
|
@@ -173,11 +176,13 @@ export function createRAGPipeline(config) {
|
|
|
173
176
|
return { totalIndexed: docs.length, totalChunks };
|
|
174
177
|
},
|
|
175
178
|
async deleteDocument(documentId, options) {
|
|
176
|
-
const
|
|
179
|
+
const knownCount = _docChunkCounts.get(documentId);
|
|
180
|
+
const count = options?.chunksCount ?? options?.totalChunks ?? knownCount ?? options?.maxChunks ?? 100;
|
|
177
181
|
const idsToDelete = [];
|
|
178
|
-
for (let i = 0; i <
|
|
182
|
+
for (let i = 0; i < count; i++) {
|
|
179
183
|
idsToDelete.push(`${documentId}#chunk-${i}`);
|
|
180
184
|
}
|
|
185
|
+
_docChunkCounts.delete(documentId);
|
|
181
186
|
const vectorize = resolveVectorize(options?.event || config?.event);
|
|
182
187
|
if (vectorize) {
|
|
183
188
|
await vectorize.deleteByIds(idsToDelete);
|
|
@@ -238,8 +243,12 @@ export function createRAGPipeline(config) {
|
|
|
238
243
|
for (const item of store.values()) {
|
|
239
244
|
if (namespace && item.namespace !== namespace) continue;
|
|
240
245
|
const sim = cosineSimilarity(queryVector, item.vector);
|
|
241
|
-
const
|
|
242
|
-
const
|
|
246
|
+
const queryWords = queryText.toLowerCase().split(/\s+/).filter((w) => w.length > 2);
|
|
247
|
+
const matchCount = queryWords.filter(
|
|
248
|
+
(w) => item.text.toLowerCase().includes(w)
|
|
249
|
+
).length;
|
|
250
|
+
const keywordScore = queryWords.length > 0 ? matchCount / queryWords.length * 0.9 : 0;
|
|
251
|
+
const score = Math.max(sim, keywordScore);
|
|
243
252
|
if (score >= minScore) {
|
|
244
253
|
candidates.push({ item, score });
|
|
245
254
|
}
|
|
@@ -331,3 +340,159 @@ ${contextText}`;
|
|
|
331
340
|
};
|
|
332
341
|
return pipeline;
|
|
333
342
|
}
|
|
343
|
+
export function createAutoRag(config) {
|
|
344
|
+
const pipeline = createRAGPipeline(config);
|
|
345
|
+
const engine = {
|
|
346
|
+
async index(input, options) {
|
|
347
|
+
let docText = "";
|
|
348
|
+
let docId = options?.id;
|
|
349
|
+
let docMetadata = { ...options?.metadata };
|
|
350
|
+
let namespace = options?.namespace;
|
|
351
|
+
if (typeof input === "string") {
|
|
352
|
+
if (input.startsWith("r2://")) {
|
|
353
|
+
const raw = input.slice(5);
|
|
354
|
+
const slashIdx = raw.indexOf("/");
|
|
355
|
+
let bucketName = options?.bucket;
|
|
356
|
+
let key = raw;
|
|
357
|
+
if (!bucketName && slashIdx !== -1) {
|
|
358
|
+
const potentialBucket = raw.slice(0, slashIdx);
|
|
359
|
+
try {
|
|
360
|
+
const env = getR2Binding(potentialBucket, options?.event);
|
|
361
|
+
if (env) {
|
|
362
|
+
bucketName = potentialBucket;
|
|
363
|
+
key = raw.slice(slashIdx + 1);
|
|
364
|
+
}
|
|
365
|
+
} catch {
|
|
366
|
+
bucketName = "BUCKET";
|
|
367
|
+
key = raw;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
if (!bucketName) {
|
|
371
|
+
bucketName = "BUCKET";
|
|
372
|
+
}
|
|
373
|
+
const bucket = getR2Binding(bucketName, options?.event);
|
|
374
|
+
const obj = await bucket.get(key);
|
|
375
|
+
if (!obj) {
|
|
376
|
+
throw new Error(`AutoRAG: R2 object not found at key: ${key}`);
|
|
377
|
+
}
|
|
378
|
+
docText = await obj.text();
|
|
379
|
+
docId = docId || key;
|
|
380
|
+
docMetadata = { ...docMetadata, key, size: obj.size };
|
|
381
|
+
} else {
|
|
382
|
+
docText = input;
|
|
383
|
+
docId = docId || `doc_${Math.random().toString(36).slice(2, 10)}`;
|
|
384
|
+
}
|
|
385
|
+
} else if (input && typeof input === "object") {
|
|
386
|
+
if ("key" in input && (!("text" in input) || !input.text)) {
|
|
387
|
+
const bucketName = input.bucket || options?.bucket || "BUCKET";
|
|
388
|
+
const key = input.key;
|
|
389
|
+
const bucket = getR2Binding(bucketName, options?.event);
|
|
390
|
+
const obj = await bucket.get(key);
|
|
391
|
+
if (!obj) {
|
|
392
|
+
throw new Error(`AutoRAG: R2 object not found at key: ${key}`);
|
|
393
|
+
}
|
|
394
|
+
docText = await obj.text();
|
|
395
|
+
docId = docId || input.id || key;
|
|
396
|
+
docMetadata = { ...docMetadata, ...input.metadata, key, size: obj.size };
|
|
397
|
+
namespace = namespace || input.namespace;
|
|
398
|
+
} else {
|
|
399
|
+
docText = input.text || "";
|
|
400
|
+
docId = docId || input.id || `doc_${Math.random().toString(36).slice(2, 10)}`;
|
|
401
|
+
docMetadata = { ...docMetadata, ...input.metadata };
|
|
402
|
+
if (input.title) {
|
|
403
|
+
docMetadata.title = input.title;
|
|
404
|
+
}
|
|
405
|
+
namespace = namespace || input.namespace;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
if (!docText) {
|
|
409
|
+
return { documentId: docId || "", chunksIndexed: 0 };
|
|
410
|
+
}
|
|
411
|
+
const res = await pipeline.indexDocument(
|
|
412
|
+
{
|
|
413
|
+
id: docId,
|
|
414
|
+
text: docText,
|
|
415
|
+
metadata: docMetadata,
|
|
416
|
+
namespace
|
|
417
|
+
},
|
|
418
|
+
{
|
|
419
|
+
chunking: options?.chunking,
|
|
420
|
+
event: options?.event
|
|
421
|
+
}
|
|
422
|
+
);
|
|
423
|
+
return {
|
|
424
|
+
documentId: docId,
|
|
425
|
+
chunksIndexed: res.chunksIndexed,
|
|
426
|
+
mutationId: res.mutationId
|
|
427
|
+
};
|
|
428
|
+
},
|
|
429
|
+
async search(query, options) {
|
|
430
|
+
const { contextText, matches } = await pipeline.retrieveContext(query, options);
|
|
431
|
+
return {
|
|
432
|
+
matches,
|
|
433
|
+
contextText,
|
|
434
|
+
totalCount: matches.length
|
|
435
|
+
};
|
|
436
|
+
},
|
|
437
|
+
async answer(query, options) {
|
|
438
|
+
return await pipeline.answer(query, options);
|
|
439
|
+
},
|
|
440
|
+
async delete(documentId, options) {
|
|
441
|
+
await pipeline.deleteDocument(documentId, options);
|
|
442
|
+
},
|
|
443
|
+
async syncR2(options) {
|
|
444
|
+
const bucketName = options?.bucket || "BUCKET";
|
|
445
|
+
const prefix = options?.prefix;
|
|
446
|
+
const allowedExts = options?.extensions || [".md", ".txt", ".json", ".csv", ".html", ".markdown"];
|
|
447
|
+
const errors = [];
|
|
448
|
+
let indexedCount = 0;
|
|
449
|
+
let skippedCount = 0;
|
|
450
|
+
try {
|
|
451
|
+
const bucket = getR2Binding(bucketName, options?.event);
|
|
452
|
+
const listed = await bucket.list({ prefix });
|
|
453
|
+
const objects = listed?.objects || [];
|
|
454
|
+
for (const obj of objects) {
|
|
455
|
+
const key = obj.key;
|
|
456
|
+
const isText = allowedExts.some((ext) => key.toLowerCase().endsWith(ext));
|
|
457
|
+
if (!isText) {
|
|
458
|
+
skippedCount++;
|
|
459
|
+
continue;
|
|
460
|
+
}
|
|
461
|
+
try {
|
|
462
|
+
const item = await bucket.get(key);
|
|
463
|
+
if (!item) {
|
|
464
|
+
skippedCount++;
|
|
465
|
+
continue;
|
|
466
|
+
}
|
|
467
|
+
const text = await item.text();
|
|
468
|
+
await engine.index(
|
|
469
|
+
{
|
|
470
|
+
id: key,
|
|
471
|
+
text,
|
|
472
|
+
metadata: { key, size: obj.size, syncedAt: (/* @__PURE__ */ new Date()).toISOString() },
|
|
473
|
+
namespace: options?.namespace
|
|
474
|
+
},
|
|
475
|
+
{ event: options?.event }
|
|
476
|
+
);
|
|
477
|
+
indexedCount++;
|
|
478
|
+
} catch (err) {
|
|
479
|
+
errors.push(`Failed to index ${key}: ${err?.message || String(err)}`);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
} catch (err) {
|
|
483
|
+
errors.push(`Failed to access R2 bucket ${bucketName}: ${err?.message || String(err)}`);
|
|
484
|
+
}
|
|
485
|
+
return {
|
|
486
|
+
indexedCount,
|
|
487
|
+
skippedCount,
|
|
488
|
+
...errors.length > 0 ? { errors } : {}
|
|
489
|
+
};
|
|
490
|
+
},
|
|
491
|
+
asTool(options) {
|
|
492
|
+
return pipeline.asTool(options);
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
return engine;
|
|
496
|
+
}
|
|
497
|
+
export const autorag = createAutoRag();
|
|
498
|
+
export const useAutoRag = createAutoRag;
|
|
@@ -30,10 +30,12 @@ export declare function getClientIp(event: RequestEvent | any): string;
|
|
|
30
30
|
* Evaluates whether a request or key is within the allowed rate limit.
|
|
31
31
|
*
|
|
32
32
|
* @example
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* const res = await checkRateLimit(event, { max: 10, window: "1m" })
|
|
35
|
+
* if (!res.success) {
|
|
36
|
+
* // exceeded
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
37
39
|
*/
|
|
38
40
|
export declare function checkRateLimit(eventOrKey: RequestEvent | string | any, options?: CheckRateLimitOptions): Promise<RateLimitCheckResult>;
|
|
39
41
|
/**
|
|
@@ -41,6 +43,33 @@ export declare function checkRateLimit(eventOrKey: RequestEvent | string | any,
|
|
|
41
43
|
* rate limit headers and throws an HTTP 429 error.
|
|
42
44
|
*
|
|
43
45
|
* @example
|
|
44
|
-
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* await assertRateLimit(event, { max: 5, window: "1m" })
|
|
48
|
+
* ```
|
|
45
49
|
*/
|
|
46
50
|
export declare function assertRateLimit(eventOrKey: RequestEvent | string | any, options?: CheckRateLimitOptions): Promise<RateLimitCheckResult>;
|
|
51
|
+
export interface RateLimitHandlerOptions extends CheckRateLimitOptions {
|
|
52
|
+
/** Custom key extractor from request event (defaults to client IP + route path) */
|
|
53
|
+
getKey?: (event: RequestEvent) => string | Promise<string>;
|
|
54
|
+
/** Custom HTTP status code when rate limit is exceeded (defaults to 429) */
|
|
55
|
+
statusCode?: number;
|
|
56
|
+
/** Custom HTTP status message when rate limit is exceeded (defaults to 'Too Many Requests') */
|
|
57
|
+
statusMessage?: string;
|
|
58
|
+
/** Custom hook invoked when rate limit is exceeded before throwing */
|
|
59
|
+
onRateLimited?: (event: RequestEvent, result: RateLimitCheckResult) => any | Promise<any>;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Higher-order event handler for Nitro/Nuxt that automatically applies edge rate limiting.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* export default defineRateLimitedEventHandler({
|
|
67
|
+
* max: 5,
|
|
68
|
+
* window: "1m",
|
|
69
|
+
* message: "Slow down! Maximum 5 requests per minute allowed.",
|
|
70
|
+
* }, async (event) => {
|
|
71
|
+
* return { message: "Hello world" }
|
|
72
|
+
* })
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export declare function defineRateLimitedEventHandler<T = any>(optionsOrHandler: RateLimitHandlerOptions | ((event: RequestEvent) => Promise<T> | T), maybeHandler?: (event: RequestEvent) => Promise<T> | T): (event: RequestEvent) => Promise<T>;
|
|
@@ -65,23 +65,49 @@ export function parseRateLimitWindow(window, defaultSeconds = 60) {
|
|
|
65
65
|
return defaultSeconds;
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
+
function getHeaderSafe(event, name) {
|
|
69
|
+
if (!event) return void 0;
|
|
70
|
+
try {
|
|
71
|
+
const val = getRequestHeader(event, name);
|
|
72
|
+
if (val) return val;
|
|
73
|
+
} catch {
|
|
74
|
+
}
|
|
75
|
+
if (event.headers && typeof event.headers.get === "function") {
|
|
76
|
+
const val = event.headers.get(name);
|
|
77
|
+
if (val) return val;
|
|
78
|
+
}
|
|
79
|
+
const headers = event.node?.req?.headers || event.req?.headers || event.headers;
|
|
80
|
+
if (headers && typeof headers === "object") {
|
|
81
|
+
const val = headers[name.toLowerCase()] || headers[name];
|
|
82
|
+
if (typeof val === "string") return val;
|
|
83
|
+
if (Array.isArray(val) && val[0]) return val[0];
|
|
84
|
+
}
|
|
85
|
+
return void 0;
|
|
86
|
+
}
|
|
87
|
+
function sanitizeClientIp(ip) {
|
|
88
|
+
if (!ip || typeof ip !== "string") return null;
|
|
89
|
+
const trimmed = ip.trim();
|
|
90
|
+
if (!trimmed) return null;
|
|
91
|
+
const cleaned = trimmed.replace(/[\r\n\0\t\s]/g, "").slice(0, 64);
|
|
92
|
+
if (/^[a-fA-F0-9:.]+$/.test(cleaned)) {
|
|
93
|
+
return cleaned;
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
68
97
|
export function getClientIp(event) {
|
|
69
98
|
if (!event) return "127.0.0.1";
|
|
70
|
-
const cfIp =
|
|
71
|
-
if (cfIp
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
const xForwardedFor = getRequestHeader(event, "x-forwarded-for");
|
|
99
|
+
const cfIp = sanitizeClientIp(getHeaderSafe(event, "cf-connecting-ip"));
|
|
100
|
+
if (cfIp) return cfIp;
|
|
101
|
+
const xForwardedFor = getHeaderSafe(event, "x-forwarded-for");
|
|
75
102
|
if (xForwardedFor && typeof xForwardedFor === "string") {
|
|
76
|
-
const firstIp = xForwardedFor.split(",")[0]
|
|
103
|
+
const firstIp = sanitizeClientIp(xForwardedFor.split(",")[0]);
|
|
77
104
|
if (firstIp) return firstIp;
|
|
78
105
|
}
|
|
79
|
-
const xRealIp =
|
|
80
|
-
if (xRealIp
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return req.socket?.remoteAddress || "127.0.0.1";
|
|
106
|
+
const xRealIp = sanitizeClientIp(getHeaderSafe(event, "x-real-ip"));
|
|
107
|
+
if (xRealIp) return xRealIp;
|
|
108
|
+
const req = event.node?.req || event.req || event;
|
|
109
|
+
const socketIp = sanitizeClientIp(req.socket?.remoteAddress);
|
|
110
|
+
return socketIp || "127.0.0.1";
|
|
85
111
|
}
|
|
86
112
|
export async function checkRateLimit(eventOrKey, options) {
|
|
87
113
|
const isEvent = eventOrKey && typeof eventOrKey === "object" && ("node" in eventOrKey || "headers" in eventOrKey || "req" in eventOrKey);
|
|
@@ -129,10 +155,23 @@ export async function checkRateLimit(eventOrKey, options) {
|
|
|
129
155
|
const windowMs2 = windowSecs * 1e3;
|
|
130
156
|
const kvKey = `_rl:${limitKey}`;
|
|
131
157
|
const raw = await kv.get(kvKey);
|
|
132
|
-
let timestamps2 =
|
|
133
|
-
|
|
158
|
+
let timestamps2 = [];
|
|
159
|
+
if (raw) {
|
|
160
|
+
try {
|
|
161
|
+
const parsed = JSON.parse(raw);
|
|
162
|
+
if (Array.isArray(parsed)) timestamps2 = parsed;
|
|
163
|
+
} catch {
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
timestamps2 = timestamps2.filter((t) => typeof t === "number" && now2 - t < windowMs2);
|
|
134
167
|
const reset2 = timestamps2.length > 0 ? Math.ceil((timestamps2[0] + windowMs2 - now2) / 1e3) : windowSecs;
|
|
135
168
|
if (timestamps2.length >= max) {
|
|
169
|
+
if (timestamps2.length > max) {
|
|
170
|
+
timestamps2 = timestamps2.slice(-max);
|
|
171
|
+
await kv.put(kvKey, JSON.stringify(timestamps2), {
|
|
172
|
+
expirationTtl: Math.max(60, windowSecs + 10)
|
|
173
|
+
});
|
|
174
|
+
}
|
|
136
175
|
return {
|
|
137
176
|
success: false,
|
|
138
177
|
remaining: 0,
|
|
@@ -141,6 +180,9 @@ export async function checkRateLimit(eventOrKey, options) {
|
|
|
141
180
|
};
|
|
142
181
|
}
|
|
143
182
|
timestamps2.push(now2);
|
|
183
|
+
if (timestamps2.length > max) {
|
|
184
|
+
timestamps2 = timestamps2.slice(-max);
|
|
185
|
+
}
|
|
144
186
|
await kv.put(kvKey, JSON.stringify(timestamps2), {
|
|
145
187
|
expirationTtl: Math.max(60, windowSecs + 10)
|
|
146
188
|
});
|
|
@@ -203,3 +245,42 @@ export async function assertRateLimit(eventOrKey, options) {
|
|
|
203
245
|
}
|
|
204
246
|
return result;
|
|
205
247
|
}
|
|
248
|
+
export function defineRateLimitedEventHandler(optionsOrHandler, maybeHandler) {
|
|
249
|
+
let options = {};
|
|
250
|
+
let handler;
|
|
251
|
+
if (typeof optionsOrHandler === "function") {
|
|
252
|
+
handler = optionsOrHandler;
|
|
253
|
+
options = {};
|
|
254
|
+
} else {
|
|
255
|
+
options = optionsOrHandler || {};
|
|
256
|
+
handler = maybeHandler;
|
|
257
|
+
}
|
|
258
|
+
return async (event) => {
|
|
259
|
+
let key = options.key;
|
|
260
|
+
if (!key && typeof options.getKey === "function") {
|
|
261
|
+
key = await options.getKey(event);
|
|
262
|
+
}
|
|
263
|
+
const checkOpts = {
|
|
264
|
+
...options,
|
|
265
|
+
key,
|
|
266
|
+
event
|
|
267
|
+
};
|
|
268
|
+
const result = await checkRateLimit(event, checkOpts);
|
|
269
|
+
setResponseHeaderSafe(event, "X-RateLimit-Limit", String(result.limit));
|
|
270
|
+
setResponseHeaderSafe(event, "X-RateLimit-Remaining", String(result.remaining));
|
|
271
|
+
setResponseHeaderSafe(event, "X-RateLimit-Reset", String(result.reset));
|
|
272
|
+
if (!result.success) {
|
|
273
|
+
setResponseHeaderSafe(event, "Retry-After", String(result.reset));
|
|
274
|
+
if (typeof options.onRateLimited === "function") {
|
|
275
|
+
await options.onRateLimited(event, result);
|
|
276
|
+
}
|
|
277
|
+
throw createError({
|
|
278
|
+
statusCode: options.statusCode || 429,
|
|
279
|
+
statusMessage: options.statusMessage || "Too Many Requests",
|
|
280
|
+
message: options.message || "Rate limit exceeded. Please try again later.",
|
|
281
|
+
data: result
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
return await handler(event);
|
|
285
|
+
};
|
|
286
|
+
}
|
|
@@ -1,43 +1,52 @@
|
|
|
1
|
+
import type { RequestEvent } from "nuxt/server";
|
|
1
2
|
import type { DurableObjectStub, RealtimeMessage, RealtimeUser, RealtimePeer, RealtimeHandlerOptions, RealtimeHandlerRegistration, RoomStateSchema } from "../../../types";
|
|
2
3
|
export type { RealtimePeer, RealtimeHandlerOptions, RealtimeHandlerRegistration, RoomStateSchema };
|
|
3
4
|
/**
|
|
4
5
|
* Creates a type-safe room state schema definition helper.
|
|
5
6
|
*
|
|
6
7
|
* @example
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* interface ChatRoomState {
|
|
10
|
+
* topic: string
|
|
11
|
+
* isLocked: boolean
|
|
12
|
+
* }
|
|
13
|
+
* export const chatSchema = defineRoomState<ChatRoomState>({
|
|
14
|
+
* name: "chat",
|
|
15
|
+
* initialState: { topic: "General", isLocked: false },
|
|
16
|
+
* })
|
|
17
|
+
* ```
|
|
17
18
|
*/
|
|
18
19
|
export declare function defineRoomState<T extends Record<string, any>>(schema: RoomStateSchema<T>): RoomStateSchema<T>;
|
|
19
20
|
/**
|
|
20
21
|
* Defines a server-side message and lifecycle handler for a room pattern.
|
|
21
22
|
*
|
|
22
23
|
* @example
|
|
23
|
-
*
|
|
24
|
-
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* export default defineRealtimeHandler("chat:*", {
|
|
25
26
|
* async message(peer, event, payload) {
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
27
|
+
* await broadcastToRoom(peer.roomId, "message", {
|
|
28
|
+
* from: peer.ctx.user?.name ?? "Anonymous",
|
|
29
|
+
* text: payload.text,
|
|
30
|
+
* ts: Date.now(),
|
|
31
|
+
* })
|
|
31
32
|
* },
|
|
32
33
|
* connect(peer) {
|
|
33
|
-
*
|
|
34
|
+
* console.log(`User connected to ${peer.roomId}`)
|
|
34
35
|
* },
|
|
35
|
-
*
|
|
36
|
-
*
|
|
36
|
+
* })
|
|
37
|
+
* ```
|
|
37
38
|
*/
|
|
38
39
|
export declare function defineRealtimeHandler(roomPattern: string, handlers: RealtimeHandlerOptions): RealtimeHandlerRegistration;
|
|
39
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* Retrieves all registered realtime handlers matching a given room ID.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* const handlers = getRealtimeHandlersForRoom("chat:general")
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
40
48
|
export declare function getRealtimeHandlersForRoom(roomId: string): RealtimeHandlerOptions[];
|
|
49
|
+
export type EventOrRoom = RequestEvent | string;
|
|
41
50
|
/**
|
|
42
51
|
* Retrieves the Durable Object stub for a specific room name.
|
|
43
52
|
*
|
|
@@ -45,19 +54,19 @@ export declare function getRealtimeHandlersForRoom(roomId: string): RealtimeHand
|
|
|
45
54
|
* @param roomId Room identifier (e.g. "chat:support", "doc:123")
|
|
46
55
|
* @param bindingName Durable Object binding name (default "QARPEO_ROOM_DO")
|
|
47
56
|
*/
|
|
48
|
-
export declare function getRoomDurableObject(eventOrRoom
|
|
57
|
+
export declare function getRoomDurableObject(eventOrRoom?: EventOrRoom, maybeRoom?: string, bindingName?: string): DurableObjectStub;
|
|
49
58
|
/**
|
|
50
59
|
* Broadcasts an event and payload to all clients in a room from the server.
|
|
51
60
|
*
|
|
52
61
|
* @example
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
62
|
+
* ```ts
|
|
63
|
+
* await broadcastToRoom(event, "doc:456", "doc:updated", {
|
|
64
|
+
* title: "New Title",
|
|
65
|
+
* updatedBy: "Admin",
|
|
66
|
+
* })
|
|
67
|
+
* ```
|
|
59
68
|
*/
|
|
60
|
-
export declare function broadcastToRoom(eventOrRoom:
|
|
69
|
+
export declare function broadcastToRoom(eventOrRoom: EventOrRoom, roomOrEventName: string, eventNameOrPayload: unknown, payloadOrOptions?: unknown, options?: {
|
|
61
70
|
sender?: string;
|
|
62
71
|
excludePeerId?: string;
|
|
63
72
|
}): Promise<boolean>;
|
|
@@ -70,16 +79,16 @@ export declare function broadcastToRoom(eventOrRoom: any, roomOrEventName: strin
|
|
|
70
79
|
* console.log(`Online: ${onlineUsers.length}`)
|
|
71
80
|
* ```
|
|
72
81
|
*/
|
|
73
|
-
export declare function getRoomPresence(eventOrRoom:
|
|
82
|
+
export declare function getRoomPresence(eventOrRoom: EventOrRoom, maybeRoom?: string): Promise<RealtimeUser[]>;
|
|
74
83
|
/**
|
|
75
84
|
* Retrieves the message history replay buffer for a room from Durable Object storage.
|
|
76
85
|
*
|
|
77
86
|
* @example
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
87
|
+
* ```ts
|
|
88
|
+
* const messages = await getRoomHistory(event, "chat:support")
|
|
89
|
+
* ```
|
|
81
90
|
*/
|
|
82
|
-
export declare function getRoomHistory(eventOrRoom:
|
|
91
|
+
export declare function getRoomHistory(eventOrRoom: EventOrRoom, maybeRoom?: string, options?: {
|
|
83
92
|
limit?: number;
|
|
84
93
|
sinceSeq?: number;
|
|
85
94
|
since?: number;
|
|
@@ -88,37 +97,44 @@ export declare function getRoomHistory(eventOrRoom: any, maybeRoom?: string, opt
|
|
|
88
97
|
* Clears the persistent message history replay buffer for a room from Durable Object storage.
|
|
89
98
|
*
|
|
90
99
|
* @example
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
100
|
+
* ```ts
|
|
101
|
+
* await clearRoomHistory(event, "chat:support")
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export declare function clearRoomHistory(eventOrRoom: EventOrRoom, maybeRoom?: string): Promise<boolean>;
|
|
105
|
+
/**
|
|
106
|
+
* Disconnects a user from a room by their userId.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* const disconnectedCount = await disconnectRoomUser(event, "chat:general", "user_123")
|
|
111
|
+
* ```
|
|
94
112
|
*/
|
|
95
|
-
export declare function
|
|
96
|
-
/** Disconnects a user from a room by their userId. */
|
|
97
|
-
export declare function disconnectRoomUser(eventOrRoom: any, roomOrUserId: string, maybeUserId?: string): Promise<number>;
|
|
113
|
+
export declare function disconnectRoomUser(eventOrRoom: EventOrRoom, roomOrUserId: string, maybeUserId?: string): Promise<number>;
|
|
98
114
|
/**
|
|
99
115
|
* Retrieves the synchronized state of a room.
|
|
100
116
|
*
|
|
101
117
|
* @example
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
118
|
+
* ```ts
|
|
119
|
+
* const state = await getRoomState(event, "doc:456")
|
|
120
|
+
* ```
|
|
105
121
|
*/
|
|
106
|
-
export declare function getRoomState<T extends Record<string, any> = Record<string, any>>(eventOrRoom:
|
|
122
|
+
export declare function getRoomState<T extends Record<string, any> = Record<string, any>>(eventOrRoom: EventOrRoom, maybeRoom?: string): Promise<T>;
|
|
107
123
|
/**
|
|
108
124
|
* Replaces the entire synchronized state of a room and broadcasts to all connected clients.
|
|
109
125
|
*
|
|
110
126
|
* @example
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
127
|
+
* ```ts
|
|
128
|
+
* await setRoomState(event, "doc:456", { title: "New Document", locked: false })
|
|
129
|
+
* ```
|
|
114
130
|
*/
|
|
115
|
-
export declare function setRoomState<T extends Record<string, any> = Record<string, any>>(eventOrRoom:
|
|
131
|
+
export declare function setRoomState<T extends Record<string, any> = Record<string, any>>(eventOrRoom: EventOrRoom, roomOrState: string | T, maybeState?: T): Promise<T>;
|
|
116
132
|
/**
|
|
117
133
|
* Merges a partial patch into the synchronized state of a room and broadcasts the delta.
|
|
118
134
|
*
|
|
119
135
|
* @example
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
136
|
+
* ```ts
|
|
137
|
+
* await patchRoomState(event, "doc:456", { locked: true })
|
|
138
|
+
* ```
|
|
123
139
|
*/
|
|
124
|
-
export declare function patchRoomState<T extends Record<string, any> = Record<string, any>>(eventOrRoom:
|
|
140
|
+
export declare function patchRoomState<T extends Record<string, any> = Record<string, any>>(eventOrRoom: EventOrRoom, roomOrPatch: string | Partial<T>, maybePatch?: Partial<T>): Promise<T>;
|
|
@@ -1,4 +1,25 @@
|
|
|
1
1
|
import type { RequestEvent } from "nuxt/server";
|
|
2
|
+
export interface ScheduledTaskLockOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Time-to-live before the lock automatically expires, e.g. "5 minutes", "10 minutes", or ms.
|
|
5
|
+
* Prevents deadlocks if the isolate terminates unexpectedly.
|
|
6
|
+
*
|
|
7
|
+
* @default "10 minutes"
|
|
8
|
+
*/
|
|
9
|
+
ttl?: string | number;
|
|
10
|
+
/**
|
|
11
|
+
* Custom distributed lock key. Defaults to `cron:lock:<task_name>`.
|
|
12
|
+
*/
|
|
13
|
+
key?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Behavior when another execution holds the lock:
|
|
16
|
+
* - `"skip"` (default): gracefully skip execution and return `{ skipped: true, reason: "locked" }`.
|
|
17
|
+
* - `"throw"`: throw a lock conflict error.
|
|
18
|
+
*
|
|
19
|
+
* @default "skip"
|
|
20
|
+
*/
|
|
21
|
+
onConflict?: "skip" | "throw";
|
|
22
|
+
}
|
|
2
23
|
export interface ScheduledTaskContext {
|
|
3
24
|
event?: RequestEvent;
|
|
4
25
|
cron?: string;
|
|
@@ -17,11 +38,31 @@ export interface ScheduledTaskDefinition<TPayload = ScheduledTaskPayload, TResul
|
|
|
17
38
|
cron?: string;
|
|
18
39
|
/** Human-readable description */
|
|
19
40
|
description?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Enable distributed locking to prevent overlapping executions across edge isolates.
|
|
43
|
+
* Set to `true` (default: 10m TTL, skips on conflict) or configure custom options.
|
|
44
|
+
*/
|
|
45
|
+
lock?: boolean | ScheduledTaskLockOptions;
|
|
20
46
|
/** Task execution handler */
|
|
21
47
|
run(ctx: {
|
|
22
48
|
payload?: TPayload;
|
|
23
49
|
context?: ScheduledTaskContext;
|
|
24
50
|
}): Promise<TResult> | TResult;
|
|
25
51
|
}
|
|
26
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* Defines an edge-native scheduled task or cron job for Cloudflare Workers with optional
|
|
54
|
+
* distributed lock protection to prevent concurrent overlapping executions.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* export default defineScheduledTask({
|
|
59
|
+
* meta: { name: "cleanup", description: "Hourly cleanup of expired tokens" },
|
|
60
|
+
* cron: "0 * * * *",
|
|
61
|
+
* lock: true, // Distributed locking & overlap prevention
|
|
62
|
+
* async run({ context }) {
|
|
63
|
+
* console.log("Running scheduled cleanup at", context?.scheduledTime)
|
|
64
|
+
* },
|
|
65
|
+
* })
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
27
68
|
export declare function defineScheduledTask<TPayload = ScheduledTaskPayload, TResult = any>(def: ScheduledTaskDefinition<TPayload, TResult>): ScheduledTaskDefinition<TPayload, TResult>;
|
|
@@ -1,3 +1,32 @@
|
|
|
1
|
+
import { acquireLock, releaseLock } from "./lock.mjs";
|
|
1
2
|
export function defineScheduledTask(def) {
|
|
3
|
+
if (!def.lock) {
|
|
4
|
+
return def;
|
|
5
|
+
}
|
|
6
|
+
const originalRun = def.run;
|
|
7
|
+
const lockConfig = typeof def.lock === "object" ? def.lock : {};
|
|
8
|
+
const taskName = def.meta?.name || def.description || "unnamed_task";
|
|
9
|
+
const lockKey = lockConfig.key || `cron:lock:${taskName.toLowerCase().replace(/[^a-z0-9_-]/g, "_")}`;
|
|
10
|
+
const ttl = lockConfig.ttl || "10 minutes";
|
|
11
|
+
const onConflict = lockConfig.onConflict || "skip";
|
|
12
|
+
def.run = async (ctx) => {
|
|
13
|
+
const handle = await acquireLock(lockKey, {
|
|
14
|
+
ttl,
|
|
15
|
+
event: ctx.context?.event
|
|
16
|
+
});
|
|
17
|
+
if (!handle) {
|
|
18
|
+
if (onConflict === "throw") {
|
|
19
|
+
throw new Error(
|
|
20
|
+
`[qarpeo:cron] Scheduled task "${taskName}" is already running across edge isolates (lock key: ${lockKey}).`
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
return { skipped: true, reason: "locked", key: lockKey };
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
return await originalRun(ctx);
|
|
27
|
+
} finally {
|
|
28
|
+
await releaseLock(lockKey, handle.token, ctx.context?.event);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
2
31
|
return def;
|
|
3
32
|
}
|