qarpeo 0.1.34 → 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 -5114
- 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 +31 -10
- package/dist/runtime/server/utils/cache.mjs +130 -53
- 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 +430 -1292
- 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
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { sendEmail } from "../../email.mjs";
|
|
2
|
+
export function defineEmailHandler(handler) {
|
|
3
|
+
return handler;
|
|
4
|
+
}
|
|
5
|
+
export function createInboundEmailContext(rawMessage, env, ctx) {
|
|
6
|
+
const from = rawMessage.from || "";
|
|
7
|
+
const to = rawMessage.to || "";
|
|
8
|
+
const headers = rawMessage.headers instanceof Headers ? rawMessage.headers : new Headers(rawMessage.headers || {});
|
|
9
|
+
let cachedText = null;
|
|
10
|
+
const readStreamAsText = async (stream) => {
|
|
11
|
+
const reader = stream.getReader();
|
|
12
|
+
const decoder = new TextDecoder();
|
|
13
|
+
let result = "";
|
|
14
|
+
while (true) {
|
|
15
|
+
const { done, value } = await reader.read();
|
|
16
|
+
if (done) break;
|
|
17
|
+
result += decoder.decode(value, { stream: true });
|
|
18
|
+
}
|
|
19
|
+
result += decoder.decode();
|
|
20
|
+
return result;
|
|
21
|
+
};
|
|
22
|
+
const message = {
|
|
23
|
+
from,
|
|
24
|
+
to,
|
|
25
|
+
headers,
|
|
26
|
+
raw: rawMessage.raw,
|
|
27
|
+
rawSize: rawMessage.rawSize ?? 0,
|
|
28
|
+
setReject(reason) {
|
|
29
|
+
if (typeof rawMessage.setReject === "function") {
|
|
30
|
+
rawMessage.setReject(reason);
|
|
31
|
+
} else {
|
|
32
|
+
console.warn(`[qarpeo:email:inbound] Email rejected: ${reason}`);
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
async forward(rcptTo, extraHeaders) {
|
|
36
|
+
if (typeof rawMessage.forward === "function") {
|
|
37
|
+
await rawMessage.forward(rcptTo, extraHeaders);
|
|
38
|
+
} else {
|
|
39
|
+
console.log(`[qarpeo:email:inbound] Forwarding email to ${rcptTo}`);
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
async reply(options) {
|
|
43
|
+
const subject = options.subject || (headers.get("subject") ? `Re: ${headers.get("subject")}` : "Re: Your message");
|
|
44
|
+
return sendEmail({
|
|
45
|
+
...options,
|
|
46
|
+
to: options.to || from,
|
|
47
|
+
subject
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
async text() {
|
|
51
|
+
if (cachedText !== null) return cachedText;
|
|
52
|
+
if (typeof rawMessage.text === "string") {
|
|
53
|
+
cachedText = rawMessage.text;
|
|
54
|
+
return rawMessage.text;
|
|
55
|
+
}
|
|
56
|
+
if (rawMessage.raw && typeof rawMessage.raw.getReader === "function") {
|
|
57
|
+
const text = await readStreamAsText(rawMessage.raw);
|
|
58
|
+
cachedText = text;
|
|
59
|
+
return text;
|
|
60
|
+
}
|
|
61
|
+
return "";
|
|
62
|
+
},
|
|
63
|
+
async json() {
|
|
64
|
+
const content = await this.text();
|
|
65
|
+
return JSON.parse(content);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
return {
|
|
69
|
+
message,
|
|
70
|
+
forward: (rcptTo, extraHeaders) => message.forward(rcptTo, extraHeaders),
|
|
71
|
+
reply: (options) => message.reply(options),
|
|
72
|
+
reject: (reason) => message.setReject(reason),
|
|
73
|
+
env,
|
|
74
|
+
context: ctx
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
import { type RequestEvent } from "nuxt/server";
|
|
2
2
|
import type { QarpeoUser } from "../../types/auth";
|
|
3
3
|
/**
|
|
4
|
-
* Admin impersonates a target user by stacking
|
|
4
|
+
* Admin impersonates a target user by stacking an "impersonator" context into the sealed session.
|
|
5
5
|
* The admin's original identity is preserved in `session.impersonator`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const { user } = await startImpersonation(event, targetUserId)
|
|
10
|
+
* ```
|
|
6
11
|
*/
|
|
7
12
|
export declare function startImpersonation(event: RequestEvent, targetUserId: string): Promise<{
|
|
8
13
|
success: boolean;
|
|
9
14
|
user: QarpeoUser;
|
|
10
15
|
}>;
|
|
11
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Stops impersonation and restores the admin's original identity.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const { user } = await stopImpersonation(event)
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
12
24
|
export declare function stopImpersonation(event: RequestEvent): Promise<{
|
|
13
25
|
success: boolean;
|
|
14
26
|
user: QarpeoUser;
|
|
@@ -16,6 +28,14 @@ export declare function stopImpersonation(event: RequestEvent): Promise<{
|
|
|
16
28
|
/**
|
|
17
29
|
* Creates a new Personal Access Token (PAT) for the current user. Returns the raw token ONCE — only
|
|
18
30
|
* the SHA-256 hash is stored.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* const { token, id } = await createApiToken(event, {
|
|
35
|
+
* name: "CLI Token",
|
|
36
|
+
* scopes: ["read", "write"],
|
|
37
|
+
* })
|
|
38
|
+
* ```
|
|
19
39
|
*/
|
|
20
40
|
export declare function createApiToken(event: RequestEvent, input: {
|
|
21
41
|
name: string;
|
|
@@ -45,6 +65,11 @@ export declare function revokeApiToken(event: RequestEvent, tokenId: string): Pr
|
|
|
45
65
|
/**
|
|
46
66
|
* Verifies a raw PAT token from `Authorization: Bearer qp_live_...` header. Returns the user and
|
|
47
67
|
* token metadata if valid; throws 401 if invalid/expired.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* const { user, scopes } = await verifyApiToken(event, rawToken)
|
|
72
|
+
* ```
|
|
48
73
|
*/
|
|
49
74
|
export declare function verifyApiToken(event: RequestEvent, rawToken: string): Promise<{
|
|
50
75
|
user: QarpeoUser;
|
|
@@ -57,6 +82,11 @@ export declare function hasApiTokenScope(scopes: string[], required: string): bo
|
|
|
57
82
|
/**
|
|
58
83
|
* Middleware helper: requires a valid Bearer PAT from Authorization header. Throws 401 if
|
|
59
84
|
* no/invalid token. Returns the verified token context.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* const { user, scopes } = await requireApiToken(event, { scope: "read:files" })
|
|
89
|
+
* ```
|
|
60
90
|
*/
|
|
61
91
|
export declare function requireApiToken(event: RequestEvent, options?: {
|
|
62
92
|
scope?: string;
|
|
@@ -2,6 +2,9 @@ import { createError } from "nuxt/server";
|
|
|
2
2
|
import { getD1Binding } from "../../db.mjs";
|
|
3
3
|
import { ensureAuthTables } from "./auth.mjs";
|
|
4
4
|
import { hashSessionToken, getAuthSession, setAuthSession } from "./session.mjs";
|
|
5
|
+
import { resolveTableName } from "./table-names.mjs";
|
|
6
|
+
const userTbl = (e) => resolveTableName("user", e);
|
|
7
|
+
const apiTokenTbl = (e) => resolveTableName("api_token", e);
|
|
5
8
|
function getD1(event) {
|
|
6
9
|
const bindingName = globalThis.process?.env?.QARPEO_DEFAULT_DB_BINDING || "DB";
|
|
7
10
|
return getD1Binding(bindingName, event);
|
|
@@ -13,7 +16,7 @@ export async function startImpersonation(event, targetUserId) {
|
|
|
13
16
|
if (!adminUser?.id) {
|
|
14
17
|
throw createError({ statusCode: 401, statusMessage: "Unauthorized" });
|
|
15
18
|
}
|
|
16
|
-
if (adminUser.role !== "admin" && adminUser.role !== "
|
|
19
|
+
if (adminUser.role !== "admin" && adminUser.role !== "super") {
|
|
17
20
|
throw createError({
|
|
18
21
|
statusCode: 403,
|
|
19
22
|
statusMessage: "Forbidden",
|
|
@@ -37,7 +40,7 @@ export async function startImpersonation(event, targetUserId) {
|
|
|
37
40
|
const d1 = getD1(event);
|
|
38
41
|
await ensureAuthTables(d1);
|
|
39
42
|
const dbTarget = await d1.prepare(
|
|
40
|
-
|
|
43
|
+
`SELECT id, email, name, image as avatar_url, role, email_verified FROM ${userTbl(event)} WHERE id = ? LIMIT 1`
|
|
41
44
|
).bind(targetUserId).first();
|
|
42
45
|
if (!dbTarget) {
|
|
43
46
|
throw createError({
|
|
@@ -46,7 +49,7 @@ export async function startImpersonation(event, targetUserId) {
|
|
|
46
49
|
message: "Target user not found"
|
|
47
50
|
});
|
|
48
51
|
}
|
|
49
|
-
if (dbTarget.role === "admin" || dbTarget.role === "
|
|
52
|
+
if (dbTarget.role === "admin" || dbTarget.role === "super") {
|
|
50
53
|
throw createError({
|
|
51
54
|
statusCode: 403,
|
|
52
55
|
statusMessage: "Forbidden",
|
|
@@ -154,7 +157,7 @@ export async function createApiToken(event, input) {
|
|
|
154
157
|
const expiresAt = input.expiresInDays ? now + input.expiresInDays * 24 * 60 * 60 * 1e3 : null;
|
|
155
158
|
const id = crypto.randomUUID();
|
|
156
159
|
await d1.prepare(`
|
|
157
|
-
INSERT INTO
|
|
160
|
+
INSERT INTO ${apiTokenTbl(event)} (id, user_id, name, token_hash, scopes, expires_at, created_at)
|
|
158
161
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
159
162
|
`).bind(id, user.id, name, tokenHash, JSON.stringify(scopes), expiresAt, now).run();
|
|
160
163
|
return { id, token: rawToken, name, scopes, expiresAt, createdAt: now };
|
|
@@ -169,7 +172,7 @@ export async function listApiTokens(event) {
|
|
|
169
172
|
await ensureAuthTables(d1);
|
|
170
173
|
const results = await d1.prepare(`
|
|
171
174
|
SELECT id, name, scopes, last_used_at as lastUsedAt, expires_at as expiresAt, created_at as createdAt
|
|
172
|
-
FROM
|
|
175
|
+
FROM ${apiTokenTbl(event)}
|
|
173
176
|
WHERE user_id = ?
|
|
174
177
|
ORDER BY created_at DESC
|
|
175
178
|
`).bind(user.id).all();
|
|
@@ -190,16 +193,16 @@ export async function revokeApiToken(event, tokenId) {
|
|
|
190
193
|
}
|
|
191
194
|
const d1 = getD1(event);
|
|
192
195
|
await ensureAuthTables(d1);
|
|
193
|
-
const existing = await d1.prepare(
|
|
196
|
+
const existing = await d1.prepare(`SELECT user_id FROM ${apiTokenTbl(event)} WHERE id = ? LIMIT 1`).bind(tokenId).first();
|
|
194
197
|
if (!existing) {
|
|
195
198
|
throw createError({ statusCode: 404, statusMessage: "Not Found", message: "Token not found" });
|
|
196
199
|
}
|
|
197
200
|
const isOwner = existing.user_id === user.id;
|
|
198
|
-
const isAdmin = user.role === "admin" || user.role === "
|
|
201
|
+
const isAdmin = user.role === "admin" || user.role === "super";
|
|
199
202
|
if (!isOwner && !isAdmin) {
|
|
200
203
|
throw createError({ statusCode: 403, statusMessage: "Forbidden", message: "Permission denied" });
|
|
201
204
|
}
|
|
202
|
-
await d1.prepare(
|
|
205
|
+
await d1.prepare(`DELETE FROM ${apiTokenTbl(event)} WHERE id = ?`).bind(tokenId).run();
|
|
203
206
|
return { success: true };
|
|
204
207
|
}
|
|
205
208
|
export async function verifyApiToken(event, rawToken) {
|
|
@@ -222,7 +225,7 @@ export async function verifyApiToken(event, rawToken) {
|
|
|
222
225
|
}
|
|
223
226
|
const tokenHash = await hashSessionToken(rawToken);
|
|
224
227
|
const tokenRecord = await d1.prepare(
|
|
225
|
-
|
|
228
|
+
`SELECT id, user_id, scopes, expires_at FROM ${apiTokenTbl(event)} WHERE token_hash = ? LIMIT 1`
|
|
226
229
|
).bind(tokenHash).first();
|
|
227
230
|
if (!tokenRecord) {
|
|
228
231
|
throw createError({
|
|
@@ -232,7 +235,7 @@ export async function verifyApiToken(event, rawToken) {
|
|
|
232
235
|
});
|
|
233
236
|
}
|
|
234
237
|
if (tokenRecord.expires_at && Date.now() > tokenRecord.expires_at) {
|
|
235
|
-
await d1.prepare(
|
|
238
|
+
await d1.prepare(`DELETE FROM ${apiTokenTbl(event)} WHERE id = ?`).bind(tokenRecord.id).run();
|
|
236
239
|
throw createError({
|
|
237
240
|
statusCode: 401,
|
|
238
241
|
statusMessage: "Unauthorized",
|
|
@@ -243,15 +246,15 @@ export async function verifyApiToken(event, rawToken) {
|
|
|
243
246
|
const ctx = event.context?.cloudflare?.ctx;
|
|
244
247
|
if (ctx?.waitUntil) {
|
|
245
248
|
ctx.waitUntil(
|
|
246
|
-
d1.prepare(
|
|
249
|
+
d1.prepare(`UPDATE ${apiTokenTbl(event)} SET last_used_at = ? WHERE id = ?`).bind(Date.now(), tokenRecord.id).run()
|
|
247
250
|
);
|
|
248
251
|
} else {
|
|
249
|
-
await d1.prepare(
|
|
252
|
+
await d1.prepare(`UPDATE ${apiTokenTbl(event)} SET last_used_at = ? WHERE id = ?`).bind(Date.now(), tokenRecord.id).run();
|
|
250
253
|
}
|
|
251
254
|
} catch {
|
|
252
255
|
}
|
|
253
256
|
const dbUser = await d1.prepare(
|
|
254
|
-
|
|
257
|
+
`SELECT id, email, name, image as avatar_url, role, email_verified FROM ${userTbl(event)} WHERE id = ? LIMIT 1`
|
|
255
258
|
).bind(tokenRecord.user_id).first();
|
|
256
259
|
if (!dbUser) {
|
|
257
260
|
throw createError({
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { CFEvent } from "../../types/index";
|
|
2
|
+
export interface LockOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Time-to-live for the lock, e.g. "5 minutes", "30 seconds", or milliseconds.
|
|
5
|
+
* Prevents deadlocks if the isolate or worker terminates unexpectedly.
|
|
6
|
+
*
|
|
7
|
+
* @default "5 minutes" (300,000ms)
|
|
8
|
+
*/
|
|
9
|
+
ttl?: string | number;
|
|
10
|
+
/**
|
|
11
|
+
* Optional event context for resolving Cloudflare bindings.
|
|
12
|
+
*/
|
|
13
|
+
event?: CFEvent;
|
|
14
|
+
/**
|
|
15
|
+
* Custom lock token (identifier of the lock holder). Defaults to random UUID.
|
|
16
|
+
*/
|
|
17
|
+
token?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Behavior when the lock cannot be acquired:
|
|
20
|
+
* - `"return"` (default): return null / false
|
|
21
|
+
* - `"throw"`: throw a LockConflictError
|
|
22
|
+
*/
|
|
23
|
+
onConflict?: "return" | "throw";
|
|
24
|
+
}
|
|
25
|
+
export interface LockHandle {
|
|
26
|
+
key: string;
|
|
27
|
+
token: string;
|
|
28
|
+
expiresAt: number;
|
|
29
|
+
}
|
|
30
|
+
/** Error thrown when a lock cannot be acquired and `onConflict: "throw"` is specified. */
|
|
31
|
+
export declare class LockConflictError extends Error {
|
|
32
|
+
readonly key: string;
|
|
33
|
+
constructor(key: string);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Tries to acquire a distributed lock on the specified resource key.
|
|
37
|
+
*
|
|
38
|
+
* @param key Unique resource key to lock (e.g. `cron:cleanup`, `inventory:sync`)
|
|
39
|
+
* @param options Lock configuration (ttl, token, event)
|
|
40
|
+
* @returns `LockHandle` if successfully acquired, or `null` if the lock is held
|
|
41
|
+
*/
|
|
42
|
+
export declare function acquireLock(key: string, options?: LockOptions): Promise<LockHandle | null>;
|
|
43
|
+
/**
|
|
44
|
+
* Releases a distributed lock using the handle token.
|
|
45
|
+
*
|
|
46
|
+
* @param key Unique resource key
|
|
47
|
+
* @param token The token returned when the lock was acquired
|
|
48
|
+
* @param event Optional event context
|
|
49
|
+
* @returns `true` if released, `false` if lock was not held or token mismatched
|
|
50
|
+
*/
|
|
51
|
+
export declare function releaseLock(key: string, token: string, event?: CFEvent): Promise<boolean>;
|
|
52
|
+
/**
|
|
53
|
+
* Runs an asynchronous callback within a distributed lock.
|
|
54
|
+
* Automatically acquires the lock before running and releases it afterwards,
|
|
55
|
+
* ensuring proper cleanup even if the callback throws an error.
|
|
56
|
+
*
|
|
57
|
+
* @param key Unique lock resource key
|
|
58
|
+
* @param optionsOrCallback LockOptions or callback function
|
|
59
|
+
* @param maybeCallback Callback function when options are provided as second argument
|
|
60
|
+
* @returns Result of callback, or `null` if the lock could not be acquired
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* const result = await withLock("sync-inventory", { ttl: "2 minutes" }, async () => {
|
|
65
|
+
* return await syncProductsFromShopify()
|
|
66
|
+
* })
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare function withLock<T>(key: string, optionsOrCallback: LockOptions | (() => Promise<T> | T), maybeCallback?: () => Promise<T> | T): Promise<T | null>;
|
|
70
|
+
/** Clears all in-memory locks (used during test teardown). */
|
|
71
|
+
export declare function clearLockStore(): void;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { getCloudflareEnv } from "../../bindings.mjs";
|
|
2
|
+
const memoryLocks = /* @__PURE__ */ new Map();
|
|
3
|
+
function parseLockDuration(duration) {
|
|
4
|
+
if (typeof duration === "number") return Math.max(1, duration);
|
|
5
|
+
if (!duration || typeof duration !== "string") return 3e5;
|
|
6
|
+
const str = duration.trim().toLowerCase();
|
|
7
|
+
const match = str.match(/^([\d.]+)\s*([a-z]+)$/);
|
|
8
|
+
if (!match) {
|
|
9
|
+
const num = Number(str);
|
|
10
|
+
return isNaN(num) ? 3e5 : Math.max(1e3, num);
|
|
11
|
+
}
|
|
12
|
+
const val = parseFloat(match[1]);
|
|
13
|
+
const unit = match[2];
|
|
14
|
+
switch (unit) {
|
|
15
|
+
case "ms":
|
|
16
|
+
case "millisecond":
|
|
17
|
+
case "milliseconds":
|
|
18
|
+
return Math.round(val);
|
|
19
|
+
case "s":
|
|
20
|
+
case "sec":
|
|
21
|
+
case "secs":
|
|
22
|
+
case "second":
|
|
23
|
+
case "seconds":
|
|
24
|
+
return Math.round(val * 1e3);
|
|
25
|
+
case "m":
|
|
26
|
+
case "min":
|
|
27
|
+
case "mins":
|
|
28
|
+
case "minute":
|
|
29
|
+
case "minutes":
|
|
30
|
+
return Math.round(val * 60 * 1e3);
|
|
31
|
+
case "h":
|
|
32
|
+
case "hr":
|
|
33
|
+
case "hrs":
|
|
34
|
+
case "hour":
|
|
35
|
+
case "hours":
|
|
36
|
+
return Math.round(val * 3600 * 1e3);
|
|
37
|
+
case "d":
|
|
38
|
+
case "day":
|
|
39
|
+
case "days":
|
|
40
|
+
return Math.round(val * 86400 * 1e3);
|
|
41
|
+
default:
|
|
42
|
+
return Math.max(1e3, Math.round(val));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export class LockConflictError extends Error {
|
|
46
|
+
constructor(key) {
|
|
47
|
+
super(`[qarpeo:lock] Lock on resource "${key}" is already held.`);
|
|
48
|
+
this.key = key;
|
|
49
|
+
this.name = "LockConflictError";
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export async function acquireLock(key, options) {
|
|
53
|
+
const ttlMs = parseLockDuration(options?.ttl);
|
|
54
|
+
const token = options?.token || crypto.randomUUID();
|
|
55
|
+
const now = Date.now();
|
|
56
|
+
const expiresAt = now + ttlMs;
|
|
57
|
+
const existing = memoryLocks.get(key);
|
|
58
|
+
if (existing && existing.expiresAt > now) {
|
|
59
|
+
if (options?.onConflict === "throw") {
|
|
60
|
+
throw new LockConflictError(key);
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
let env = {};
|
|
65
|
+
try {
|
|
66
|
+
env = getCloudflareEnv(options?.event);
|
|
67
|
+
} catch {
|
|
68
|
+
}
|
|
69
|
+
const kv = env["KV"] || env["QARPEO_KV"];
|
|
70
|
+
if (kv && typeof kv.get === "function" && typeof kv.put === "function") {
|
|
71
|
+
try {
|
|
72
|
+
const kvKey = `__qarpeo_lock:${key}`;
|
|
73
|
+
const remoteVal = await kv.get(kvKey);
|
|
74
|
+
if (remoteVal && remoteVal !== token) {
|
|
75
|
+
if (options?.onConflict === "throw") {
|
|
76
|
+
throw new LockConflictError(key);
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
const ttlSec = Math.max(60, Math.ceil(ttlMs / 1e3));
|
|
81
|
+
await kv.put(kvKey, token, { expirationTtl: ttlSec });
|
|
82
|
+
} catch {
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
memoryLocks.set(key, { token, expiresAt });
|
|
86
|
+
return {
|
|
87
|
+
key,
|
|
88
|
+
token,
|
|
89
|
+
expiresAt
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
export async function releaseLock(key, token, event) {
|
|
93
|
+
let released = false;
|
|
94
|
+
const existing = memoryLocks.get(key);
|
|
95
|
+
if (existing && existing.token === token) {
|
|
96
|
+
memoryLocks.delete(key);
|
|
97
|
+
released = true;
|
|
98
|
+
}
|
|
99
|
+
let env = {};
|
|
100
|
+
try {
|
|
101
|
+
env = getCloudflareEnv(event);
|
|
102
|
+
} catch {
|
|
103
|
+
}
|
|
104
|
+
const kv = env["KV"] || env["QARPEO_KV"];
|
|
105
|
+
if (kv && typeof kv.get === "function" && typeof kv.delete === "function") {
|
|
106
|
+
try {
|
|
107
|
+
const kvKey = `__qarpeo_lock:${key}`;
|
|
108
|
+
const remoteToken = await kv.get(kvKey);
|
|
109
|
+
if (remoteToken === token) {
|
|
110
|
+
await kv.delete(kvKey);
|
|
111
|
+
released = true;
|
|
112
|
+
}
|
|
113
|
+
} catch {
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return released;
|
|
117
|
+
}
|
|
118
|
+
export async function withLock(key, optionsOrCallback, maybeCallback) {
|
|
119
|
+
let options = {};
|
|
120
|
+
let callback;
|
|
121
|
+
if (typeof optionsOrCallback === "function") {
|
|
122
|
+
callback = optionsOrCallback;
|
|
123
|
+
} else {
|
|
124
|
+
options = optionsOrCallback || {};
|
|
125
|
+
callback = maybeCallback;
|
|
126
|
+
}
|
|
127
|
+
const handle = await acquireLock(key, options);
|
|
128
|
+
if (!handle) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
return await callback();
|
|
133
|
+
} finally {
|
|
134
|
+
await releaseLock(key, handle.token, options.event);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
export function clearLockStore() {
|
|
138
|
+
memoryLocks.clear();
|
|
139
|
+
}
|
|
@@ -11,7 +11,7 @@ export async function ensureMailSuppressionsTable(db) {
|
|
|
11
11
|
if (_tableEnsured || !db) return;
|
|
12
12
|
try {
|
|
13
13
|
await db.prepare(
|
|
14
|
-
`CREATE TABLE IF NOT EXISTS
|
|
14
|
+
`CREATE TABLE IF NOT EXISTS mail_suppression (
|
|
15
15
|
id TEXT PRIMARY KEY,
|
|
16
16
|
email TEXT NOT NULL UNIQUE,
|
|
17
17
|
reason TEXT NOT NULL,
|
|
@@ -31,7 +31,7 @@ import { getSessionSecret } from "./config.mjs";
|
|
|
31
31
|
function resolveUnsubscribeSecret(secret) {
|
|
32
32
|
const procEnv = globalThis.process?.env || {};
|
|
33
33
|
const runtimeConfig = globalThis.__NUXT_RUNTIME_CONFIG__ || {};
|
|
34
|
-
const explicit = secret || runtimeConfig.qarpeo?.mail?.unsubscribe?.secret || runtimeConfig.qarpeo?.auth?.secret || procEnv.AUTH_SECRET || procEnv.
|
|
34
|
+
const explicit = secret || runtimeConfig.qarpeo?.mail?.unsubscribe?.secret || runtimeConfig.qarpeo?.auth?.secret || procEnv.AUTH_SECRET || procEnv.NUXT_APP_SECRET;
|
|
35
35
|
if (explicit) return explicit;
|
|
36
36
|
return getSessionSecret(void 0, "qarpeo-dev-unsubscribe-salt");
|
|
37
37
|
}
|
|
@@ -136,7 +136,7 @@ export async function suppressEmail(event, options) {
|
|
|
136
136
|
if (db && typeof db.prepare === "function") {
|
|
137
137
|
await ensureMailSuppressionsTable(db);
|
|
138
138
|
await db.prepare(
|
|
139
|
-
`INSERT INTO
|
|
139
|
+
`INSERT INTO mail_suppression (id, email, reason, type, source, metadata_json, created_at, updated_at)
|
|
140
140
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
141
141
|
ON CONFLICT(email) DO UPDATE SET
|
|
142
142
|
reason = excluded.reason,
|
|
@@ -200,7 +200,7 @@ export async function isEmailSuppressed(event, email) {
|
|
|
200
200
|
await ensureMailSuppressionsTable(db);
|
|
201
201
|
const row = await db.prepare(
|
|
202
202
|
`SELECT id, email, reason, type, source, metadata_json, created_at, updated_at
|
|
203
|
-
FROM
|
|
203
|
+
FROM mail_suppression
|
|
204
204
|
WHERE email = ? LIMIT 1`
|
|
205
205
|
).bind(cleanEmail).first();
|
|
206
206
|
if (row) {
|
|
@@ -242,7 +242,7 @@ export async function unsuppressEmail(event, email) {
|
|
|
242
242
|
const db = getD1Binding("DB", event);
|
|
243
243
|
if (db && typeof db.prepare === "function") {
|
|
244
244
|
await ensureMailSuppressionsTable(db);
|
|
245
|
-
const res = await db.prepare(`DELETE FROM
|
|
245
|
+
const res = await db.prepare(`DELETE FROM mail_suppression WHERE email = ?`).bind(cleanEmail).run();
|
|
246
246
|
if (res && Number(res?.meta?.changes || 0) > 0) removed = true;
|
|
247
247
|
}
|
|
248
248
|
} catch {
|
|
@@ -277,11 +277,11 @@ export async function listSuppressedEmails(event, options = {}) {
|
|
|
277
277
|
whereClause += " AND reason = ?";
|
|
278
278
|
params.push(options.reason);
|
|
279
279
|
}
|
|
280
|
-
const countRow = await db.prepare(`SELECT COUNT(*) as count FROM
|
|
280
|
+
const countRow = await db.prepare(`SELECT COUNT(*) as count FROM mail_suppression ${whereClause}`).bind(...params).first();
|
|
281
281
|
const total2 = Number(countRow?.count || 0);
|
|
282
282
|
const rows = await db.prepare(
|
|
283
283
|
`SELECT id, email, reason, type, source, metadata_json, created_at, updated_at
|
|
284
|
-
FROM
|
|
284
|
+
FROM mail_suppression
|
|
285
285
|
${whereClause}
|
|
286
286
|
ORDER BY created_at DESC
|
|
287
287
|
LIMIT ? OFFSET ?`
|
|
@@ -64,27 +64,38 @@ export declare function deliverMailDirect(options: {
|
|
|
64
64
|
* tracking, queue-backed delivery, and dev mailbox capture.
|
|
65
65
|
*
|
|
66
66
|
* @example
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
67
|
+
* ```ts
|
|
68
|
+
* // Markdown content:
|
|
69
|
+
* await sendMail({
|
|
70
|
+
* to: "user@example.com",
|
|
71
|
+
* subject: "Welcome to Acme",
|
|
72
|
+
* markdown:
|
|
73
|
+
* "# Welcome!\nWe are glad you joined us.\n\n[btn: Go to Dashboard](https://myapp.com)",
|
|
74
|
+
* })
|
|
74
75
|
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
76
|
+
* // Template:
|
|
77
|
+
* await sendMail({
|
|
78
|
+
* to: "user@example.com",
|
|
79
|
+
* template: "welcome",
|
|
80
|
+
* data: { name: "Alice", actionUrl: "https://myapp.com/dashboard" },
|
|
81
|
+
* })
|
|
82
|
+
* ```
|
|
81
83
|
*/
|
|
82
84
|
export declare function sendMail(request: SendMailRequest, event?: RequestEvent): Promise<MailResult>;
|
|
83
|
-
|
|
84
|
-
export declare function useMail(event?: RequestEvent): {
|
|
85
|
+
export interface UseMailReturn {
|
|
85
86
|
send: (request: SendMailRequest) => Promise<MailResult>;
|
|
86
|
-
getMailbox:
|
|
87
|
-
getEmail:
|
|
88
|
-
clearMailbox:
|
|
89
|
-
}
|
|
87
|
+
getMailbox: () => DevEmailRecord[];
|
|
88
|
+
getEmail: (id: string) => DevEmailRecord | undefined;
|
|
89
|
+
clearMailbox: () => void;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Access the Qarpeo Transactional Mail client.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* const mail = useMail(event)
|
|
97
|
+
* await mail.send({ to: "user@example.com", subject: "Hello", text: "Welcome" })
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export declare function useMail(event?: RequestEvent): UseMailReturn;
|
|
90
101
|
export { suppressEmail, isEmailSuppressed, unsuppressEmail, listSuppressedEmails, recordSoftBounce, generateUnsubscribeToken, verifyUnsubscribeToken, buildListUnsubscribeHeaders, } from "./mail-suppression";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { AgentTool } from "../../../types";
|
|
2
|
+
import type { McpServerDefinition, McpTool, McpClient, McpClientOptions } from "../../types/mcp";
|
|
3
|
+
/**
|
|
4
|
+
* Converts Qarpeo AgentTool array or record to MCP tool descriptors.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* const mcpTools = agentToolsToMcpTools({ search: defineTool({ ... }) })
|
|
8
|
+
*/
|
|
9
|
+
export declare function agentToolsToMcpTools(tools: Record<string, AgentTool> | AgentTool[] | undefined): McpTool[];
|
|
10
|
+
/**
|
|
11
|
+
* Creates an edge MCP (Model Context Protocol) server as an H3/Nuxt event handler.
|
|
12
|
+
*
|
|
13
|
+
* The returned handler can be used directly in a Nuxt server route:
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* // server/routes/mcp.post.ts
|
|
18
|
+
* export default defineMcpServer({
|
|
19
|
+
* name: "my-mcp",
|
|
20
|
+
* version: "1.0.0",
|
|
21
|
+
* tools: {
|
|
22
|
+
* search: defineTool({
|
|
23
|
+
* description: "Search the database",
|
|
24
|
+
* parameters: { type: "object", properties: { q: { type: "string" } } },
|
|
25
|
+
* execute: async ({ q }) => db.search(q),
|
|
26
|
+
* }),
|
|
27
|
+
* },
|
|
28
|
+
* })
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function defineMcpServer(definition: McpServerDefinition): (event: any) => Promise<Response>;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a typed MCP client that sends JSON-RPC 2.0 requests to a remote MCP server.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* const client = createMcpClient("https://mcp.example.com/api/mcp")
|
|
38
|
+
* const tools = await client.getTools()
|
|
39
|
+
* const result = await client.callTool("search", { q: "hello" })
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function createMcpClient(url: string, options?: McpClientOptions): McpClient;
|
|
43
|
+
/** Alias for {@link createMcpClient}. */
|
|
44
|
+
export declare const useMcpClient: typeof createMcpClient;
|