imap-wizard 0.0.0-stage → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/COPYING +674 -0
- package/LICENSE +155 -0
- package/README.md +498 -2
- package/dist/app.d.ts +61 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +201 -0
- package/dist/app.js.map +1 -0
- package/dist/cache/body-cache.d.ts +29 -0
- package/dist/cache/body-cache.d.ts.map +1 -0
- package/dist/cache/body-cache.js +95 -0
- package/dist/cache/body-cache.js.map +1 -0
- package/dist/cache/schema.d.ts +40 -0
- package/dist/cache/schema.d.ts.map +1 -0
- package/dist/cache/schema.js +160 -0
- package/dist/cache/schema.js.map +1 -0
- package/dist/cache/store.d.ts +233 -0
- package/dist/cache/store.d.ts.map +1 -0
- package/dist/cache/store.js +556 -0
- package/dist/cache/store.js.map +1 -0
- package/dist/cache/sync-engine.d.ts +140 -0
- package/dist/cache/sync-engine.d.ts.map +1 -0
- package/dist/cache/sync-engine.js +477 -0
- package/dist/cache/sync-engine.js.map +1 -0
- package/dist/cli/account-commands.d.ts +51 -0
- package/dist/cli/account-commands.d.ts.map +1 -0
- package/dist/cli/account-commands.js +767 -0
- package/dist/cli/account-commands.js.map +1 -0
- package/dist/cli/config-commands.d.ts +9 -0
- package/dist/cli/config-commands.d.ts.map +1 -0
- package/dist/cli/config-commands.js +293 -0
- package/dist/cli/config-commands.js.map +1 -0
- package/dist/cli/email-commands.d.ts +18 -0
- package/dist/cli/email-commands.d.ts.map +1 -0
- package/dist/cli/email-commands.js +447 -0
- package/dist/cli/email-commands.js.map +1 -0
- package/dist/cli/guard.d.ts +11 -0
- package/dist/cli/guard.d.ts.map +1 -0
- package/dist/cli/guard.js +18 -0
- package/dist/cli/guard.js.map +1 -0
- package/dist/cli/http.d.ts +15 -0
- package/dist/cli/http.d.ts.map +1 -0
- package/dist/cli/http.js +263 -0
- package/dist/cli/http.js.map +1 -0
- package/dist/cli/install-commands.d.ts +18 -0
- package/dist/cli/install-commands.d.ts.map +1 -0
- package/dist/cli/install-commands.js +323 -0
- package/dist/cli/install-commands.js.map +1 -0
- package/dist/cli/keychain-commands.d.ts +9 -0
- package/dist/cli/keychain-commands.d.ts.map +1 -0
- package/dist/cli/keychain-commands.js +243 -0
- package/dist/cli/keychain-commands.js.map +1 -0
- package/dist/cli/notify.d.ts +8 -0
- package/dist/cli/notify.d.ts.map +1 -0
- package/dist/cli/notify.js +143 -0
- package/dist/cli/notify.js.map +1 -0
- package/dist/cli/providers.d.ts +13 -0
- package/dist/cli/providers.d.ts.map +1 -0
- package/dist/cli/providers.js +180 -0
- package/dist/cli/providers.js.map +1 -0
- package/dist/cli/scheduler.d.ts +8 -0
- package/dist/cli/scheduler.d.ts.map +1 -0
- package/dist/cli/scheduler.js +268 -0
- package/dist/cli/scheduler.js.map +1 -0
- package/dist/cli/setup.d.ts +12 -0
- package/dist/cli/setup.d.ts.map +1 -0
- package/dist/cli/setup.js +15 -0
- package/dist/cli/setup.js.map +1 -0
- package/dist/cli/test.d.ts +7 -0
- package/dist/cli/test.d.ts.map +1 -0
- package/dist/cli/test.js +67 -0
- package/dist/cli/test.js.map +1 -0
- package/dist/config/loader.d.ts +45 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +487 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/password-command.d.ts +14 -0
- package/dist/config/password-command.d.ts.map +1 -0
- package/dist/config/password-command.js +74 -0
- package/dist/config/password-command.js.map +1 -0
- package/dist/config/schema.d.ts +416 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/config/schema.js +260 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/config/send-limit.d.ts +18 -0
- package/dist/config/send-limit.d.ts.map +1 -0
- package/dist/config/send-limit.js +64 -0
- package/dist/config/send-limit.js.map +1 -0
- package/dist/config/validate.d.ts +30 -0
- package/dist/config/validate.d.ts.map +1 -0
- package/dist/config/validate.js +120 -0
- package/dist/config/validate.js.map +1 -0
- package/dist/config/xdg.d.ts +44 -0
- package/dist/config/xdg.d.ts.map +1 -0
- package/dist/config/xdg.js +49 -0
- package/dist/config/xdg.js.map +1 -0
- package/dist/connections/manager.d.ts +53 -0
- package/dist/connections/manager.d.ts.map +1 -0
- package/dist/connections/manager.js +376 -0
- package/dist/connections/manager.js.map +1 -0
- package/dist/connections/types.d.ts +15 -0
- package/dist/connections/types.d.ts.map +1 -0
- package/dist/connections/types.js +2 -0
- package/dist/connections/types.js.map +1 -0
- package/dist/logging.d.ts +22 -0
- package/dist/logging.d.ts.map +1 -0
- package/dist/logging.js +33 -0
- package/dist/logging.js.map +1 -0
- package/dist/main.d.ts +15 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +276 -0
- package/dist/main.js.map +1 -0
- package/dist/prompts/actions.prompt.d.ts +9 -0
- package/dist/prompts/actions.prompt.d.ts.map +1 -0
- package/dist/prompts/actions.prompt.js +70 -0
- package/dist/prompts/actions.prompt.js.map +1 -0
- package/dist/prompts/calendar.prompt.d.ts +9 -0
- package/dist/prompts/calendar.prompt.d.ts.map +1 -0
- package/dist/prompts/calendar.prompt.js +59 -0
- package/dist/prompts/calendar.prompt.js.map +1 -0
- package/dist/prompts/cleanup.prompt.d.ts +9 -0
- package/dist/prompts/cleanup.prompt.d.ts.map +1 -0
- package/dist/prompts/cleanup.prompt.js +82 -0
- package/dist/prompts/cleanup.prompt.js.map +1 -0
- package/dist/prompts/compose.prompt.d.ts +8 -0
- package/dist/prompts/compose.prompt.d.ts.map +1 -0
- package/dist/prompts/compose.prompt.js +124 -0
- package/dist/prompts/compose.prompt.js.map +1 -0
- package/dist/prompts/register.d.ts +8 -0
- package/dist/prompts/register.d.ts.map +1 -0
- package/dist/prompts/register.js +20 -0
- package/dist/prompts/register.js.map +1 -0
- package/dist/prompts/thread.prompt.d.ts +9 -0
- package/dist/prompts/thread.prompt.d.ts.map +1 -0
- package/dist/prompts/thread.prompt.js +62 -0
- package/dist/prompts/thread.prompt.js.map +1 -0
- package/dist/prompts/triage.prompt.d.ts +9 -0
- package/dist/prompts/triage.prompt.d.ts.map +1 -0
- package/dist/prompts/triage.prompt.js +71 -0
- package/dist/prompts/triage.prompt.js.map +1 -0
- package/dist/resources/accounts.resource.d.ts +9 -0
- package/dist/resources/accounts.resource.d.ts.map +1 -0
- package/dist/resources/accounts.resource.js +26 -0
- package/dist/resources/accounts.resource.js.map +1 -0
- package/dist/resources/mailboxes.resource.d.ts +10 -0
- package/dist/resources/mailboxes.resource.d.ts.map +1 -0
- package/dist/resources/mailboxes.resource.js +33 -0
- package/dist/resources/mailboxes.resource.js.map +1 -0
- package/dist/resources/register.d.ts +12 -0
- package/dist/resources/register.d.ts.map +1 -0
- package/dist/resources/register.js +20 -0
- package/dist/resources/register.js.map +1 -0
- package/dist/resources/scheduled.resource.d.ts +9 -0
- package/dist/resources/scheduled.resource.d.ts.map +1 -0
- package/dist/resources/scheduled.resource.js +31 -0
- package/dist/resources/scheduled.resource.js.map +1 -0
- package/dist/resources/stats.resource.d.ts +10 -0
- package/dist/resources/stats.resource.d.ts.map +1 -0
- package/dist/resources/stats.resource.js +50 -0
- package/dist/resources/stats.resource.js.map +1 -0
- package/dist/resources/templates.resource.d.ts +9 -0
- package/dist/resources/templates.resource.d.ts.map +1 -0
- package/dist/resources/templates.resource.js +34 -0
- package/dist/resources/templates.resource.js.map +1 -0
- package/dist/resources/unread.resource.d.ts +11 -0
- package/dist/resources/unread.resource.d.ts.map +1 -0
- package/dist/resources/unread.resource.js +53 -0
- package/dist/resources/unread.resource.js.map +1 -0
- package/dist/safety/audit.d.ts +17 -0
- package/dist/safety/audit.d.ts.map +1 -0
- package/dist/safety/audit.js +50 -0
- package/dist/safety/audit.js.map +1 -0
- package/dist/safety/rate-limiter.d.ts +22 -0
- package/dist/safety/rate-limiter.d.ts.map +1 -0
- package/dist/safety/rate-limiter.js +52 -0
- package/dist/safety/rate-limiter.js.map +1 -0
- package/dist/safety/validation.d.ts +46 -0
- package/dist/safety/validation.d.ts.map +1 -0
- package/dist/safety/validation.js +114 -0
- package/dist/safety/validation.js.map +1 -0
- package/dist/safety/webhook-guard.d.ts +33 -0
- package/dist/safety/webhook-guard.d.ts.map +1 -0
- package/dist/safety/webhook-guard.js +154 -0
- package/dist/safety/webhook-guard.js.map +1 -0
- package/dist/security/keychain.d.ts +31 -0
- package/dist/security/keychain.d.ts.map +1 -0
- package/dist/security/keychain.js +217 -0
- package/dist/security/keychain.js.map +1 -0
- package/dist/server.d.ts +13 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +35 -0
- package/dist/server.js.map +1 -0
- package/dist/services/calendar.service.d.ts +22 -0
- package/dist/services/calendar.service.d.ts.map +1 -0
- package/dist/services/calendar.service.js +115 -0
- package/dist/services/calendar.service.js.map +1 -0
- package/dist/services/clipboard.service.d.ts +16 -0
- package/dist/services/clipboard.service.d.ts.map +1 -0
- package/dist/services/clipboard.service.js +92 -0
- package/dist/services/clipboard.service.js.map +1 -0
- package/dist/services/event-bus.d.ts +62 -0
- package/dist/services/event-bus.d.ts.map +1 -0
- package/dist/services/event-bus.js +16 -0
- package/dist/services/event-bus.js.map +1 -0
- package/dist/services/hooks.service.d.ts +88 -0
- package/dist/services/hooks.service.d.ts.map +1 -0
- package/dist/services/hooks.service.js +539 -0
- package/dist/services/hooks.service.js.map +1 -0
- package/dist/services/imap.service.d.ts +301 -0
- package/dist/services/imap.service.d.ts.map +1 -0
- package/dist/services/imap.service.js +2135 -0
- package/dist/services/imap.service.js.map +1 -0
- package/dist/services/label-strategy.d.ts +20 -0
- package/dist/services/label-strategy.d.ts.map +1 -0
- package/dist/services/label-strategy.js +247 -0
- package/dist/services/label-strategy.js.map +1 -0
- package/dist/services/local-calendar.service.d.ts +127 -0
- package/dist/services/local-calendar.service.d.ts.map +1 -0
- package/dist/services/local-calendar.service.js +537 -0
- package/dist/services/local-calendar.service.js.map +1 -0
- package/dist/services/notifier.service.d.ts +91 -0
- package/dist/services/notifier.service.d.ts.map +1 -0
- package/dist/services/notifier.service.js +381 -0
- package/dist/services/notifier.service.js.map +1 -0
- package/dist/services/oauth.service.d.ts +47 -0
- package/dist/services/oauth.service.d.ts.map +1 -0
- package/dist/services/oauth.service.js +140 -0
- package/dist/services/oauth.service.js.map +1 -0
- package/dist/services/presets.d.ts +36 -0
- package/dist/services/presets.d.ts.map +1 -0
- package/dist/services/presets.js +175 -0
- package/dist/services/presets.js.map +1 -0
- package/dist/services/reminders.service.d.ts +63 -0
- package/dist/services/reminders.service.d.ts.map +1 -0
- package/dist/services/reminders.service.js +305 -0
- package/dist/services/reminders.service.js.map +1 -0
- package/dist/services/scheduler.service.d.ts +42 -0
- package/dist/services/scheduler.service.d.ts.map +1 -0
- package/dist/services/scheduler.service.js +294 -0
- package/dist/services/scheduler.service.js.map +1 -0
- package/dist/services/smtp.service.d.ts +97 -0
- package/dist/services/smtp.service.d.ts.map +1 -0
- package/dist/services/smtp.service.js +339 -0
- package/dist/services/smtp.service.js.map +1 -0
- package/dist/services/template.service.d.ts +33 -0
- package/dist/services/template.service.d.ts.map +1 -0
- package/dist/services/template.service.js +123 -0
- package/dist/services/template.service.js.map +1 -0
- package/dist/services/verification.service.d.ts +26 -0
- package/dist/services/verification.service.d.ts.map +1 -0
- package/dist/services/verification.service.js +94 -0
- package/dist/services/verification.service.js.map +1 -0
- package/dist/services/watcher.service.d.ts +36 -0
- package/dist/services/watcher.service.d.ts.map +1 -0
- package/dist/services/watcher.service.js +238 -0
- package/dist/services/watcher.service.js.map +1 -0
- package/dist/tools/accounts.tool.d.ts +7 -0
- package/dist/tools/accounts.tool.d.ts.map +1 -0
- package/dist/tools/accounts.tool.js +33 -0
- package/dist/tools/accounts.tool.js.map +1 -0
- package/dist/tools/analytics.tool.d.ts +9 -0
- package/dist/tools/analytics.tool.d.ts.map +1 -0
- package/dist/tools/analytics.tool.js +32 -0
- package/dist/tools/analytics.tool.js.map +1 -0
- package/dist/tools/attachments.tool.d.ts +7 -0
- package/dist/tools/attachments.tool.d.ts.map +1 -0
- package/dist/tools/attachments.tool.js +93 -0
- package/dist/tools/attachments.tool.js.map +1 -0
- package/dist/tools/bulk.tool.d.ts +7 -0
- package/dist/tools/bulk.tool.d.ts.map +1 -0
- package/dist/tools/bulk.tool.js +80 -0
- package/dist/tools/bulk.tool.js.map +1 -0
- package/dist/tools/calendar.tool.d.ts +19 -0
- package/dist/tools/calendar.tool.d.ts.map +1 -0
- package/dist/tools/calendar.tool.js +576 -0
- package/dist/tools/calendar.tool.js.map +1 -0
- package/dist/tools/contacts.tool.d.ts +7 -0
- package/dist/tools/contacts.tool.d.ts.map +1 -0
- package/dist/tools/contacts.tool.js +49 -0
- package/dist/tools/contacts.tool.js.map +1 -0
- package/dist/tools/drafts.tool.d.ts +8 -0
- package/dist/tools/drafts.tool.d.ts.map +1 -0
- package/dist/tools/drafts.tool.js +110 -0
- package/dist/tools/drafts.tool.js.map +1 -0
- package/dist/tools/emails.tool.d.ts +17 -0
- package/dist/tools/emails.tool.d.ts.map +1 -0
- package/dist/tools/emails.tool.js +508 -0
- package/dist/tools/emails.tool.js.map +1 -0
- package/dist/tools/folders.tool.d.ts +7 -0
- package/dist/tools/folders.tool.d.ts.map +1 -0
- package/dist/tools/folders.tool.js +129 -0
- package/dist/tools/folders.tool.js.map +1 -0
- package/dist/tools/health.tool.d.ts +10 -0
- package/dist/tools/health.tool.d.ts.map +1 -0
- package/dist/tools/health.tool.js +106 -0
- package/dist/tools/health.tool.js.map +1 -0
- package/dist/tools/label.tool.d.ts +11 -0
- package/dist/tools/label.tool.d.ts.map +1 -0
- package/dist/tools/label.tool.js +190 -0
- package/dist/tools/label.tool.js.map +1 -0
- package/dist/tools/locate.tool.d.ts +11 -0
- package/dist/tools/locate.tool.d.ts.map +1 -0
- package/dist/tools/locate.tool.js +65 -0
- package/dist/tools/locate.tool.js.map +1 -0
- package/dist/tools/mailboxes.tool.d.ts +7 -0
- package/dist/tools/mailboxes.tool.d.ts.map +1 -0
- package/dist/tools/mailboxes.tool.js +49 -0
- package/dist/tools/mailboxes.tool.js.map +1 -0
- package/dist/tools/manage.tool.d.ts +7 -0
- package/dist/tools/manage.tool.d.ts.map +1 -0
- package/dist/tools/manage.tool.js +140 -0
- package/dist/tools/manage.tool.js.map +1 -0
- package/dist/tools/register.d.ts +20 -0
- package/dist/tools/register.d.ts.map +1 -0
- package/dist/tools/register.js +60 -0
- package/dist/tools/register.js.map +1 -0
- package/dist/tools/scheduler.tool.d.ts +9 -0
- package/dist/tools/scheduler.tool.d.ts.map +1 -0
- package/dist/tools/scheduler.tool.js +130 -0
- package/dist/tools/scheduler.tool.js.map +1 -0
- package/dist/tools/schemas.d.ts +146 -0
- package/dist/tools/schemas.d.ts.map +1 -0
- package/dist/tools/schemas.js +89 -0
- package/dist/tools/schemas.js.map +1 -0
- package/dist/tools/security.tool.d.ts +11 -0
- package/dist/tools/security.tool.d.ts.map +1 -0
- package/dist/tools/security.tool.js +49 -0
- package/dist/tools/security.tool.js.map +1 -0
- package/dist/tools/send.tool.d.ts +7 -0
- package/dist/tools/send.tool.d.ts.map +1 -0
- package/dist/tools/send.tool.js +196 -0
- package/dist/tools/send.tool.js.map +1 -0
- package/dist/tools/templates.tool.d.ts +12 -0
- package/dist/tools/templates.tool.d.ts.map +1 -0
- package/dist/tools/templates.tool.js +149 -0
- package/dist/tools/templates.tool.js.map +1 -0
- package/dist/tools/thread.tool.d.ts +10 -0
- package/dist/tools/thread.tool.d.ts.map +1 -0
- package/dist/tools/thread.tool.js +140 -0
- package/dist/tools/thread.tool.js.map +1 -0
- package/dist/tools/verification.tool.d.ts +5 -0
- package/dist/tools/verification.tool.d.ts.map +1 -0
- package/dist/tools/verification.tool.js +125 -0
- package/dist/tools/verification.tool.js.map +1 -0
- package/dist/tools/watcher.tool.d.ts +19 -0
- package/dist/tools/watcher.tool.d.ts.map +1 -0
- package/dist/tools/watcher.tool.js +319 -0
- package/dist/tools/watcher.tool.js.map +1 -0
- package/dist/types/index.d.ts +329 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +5 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/auth-results.d.ts +24 -0
- package/dist/utils/auth-results.d.ts.map +1 -0
- package/dist/utils/auth-results.js +71 -0
- package/dist/utils/auth-results.js.map +1 -0
- package/dist/utils/bulk-headers.d.ts +34 -0
- package/dist/utils/bulk-headers.d.ts.map +1 -0
- package/dist/utils/bulk-headers.js +112 -0
- package/dist/utils/bulk-headers.js.map +1 -0
- package/dist/utils/calendar-notes.d.ts +31 -0
- package/dist/utils/calendar-notes.d.ts.map +1 -0
- package/dist/utils/calendar-notes.js +83 -0
- package/dist/utils/calendar-notes.js.map +1 -0
- package/dist/utils/calendar-state.d.ts +27 -0
- package/dist/utils/calendar-state.d.ts.map +1 -0
- package/dist/utils/calendar-state.js +85 -0
- package/dist/utils/calendar-state.js.map +1 -0
- package/dist/utils/conference-details.d.ts +12 -0
- package/dist/utils/conference-details.d.ts.map +1 -0
- package/dist/utils/conference-details.js +71 -0
- package/dist/utils/conference-details.js.map +1 -0
- package/dist/utils/html.d.ts +24 -0
- package/dist/utils/html.d.ts.map +1 -0
- package/dist/utils/html.js +162 -0
- package/dist/utils/html.js.map +1 -0
- package/dist/utils/imap-client.d.ts +22 -0
- package/dist/utils/imap-client.d.ts.map +1 -0
- package/dist/utils/imap-client.js +26 -0
- package/dist/utils/imap-client.js.map +1 -0
- package/dist/utils/imap-error.d.ts +28 -0
- package/dist/utils/imap-error.d.ts.map +1 -0
- package/dist/utils/imap-error.js +82 -0
- package/dist/utils/imap-error.js.map +1 -0
- package/dist/utils/meeting-url.d.ts +10 -0
- package/dist/utils/meeting-url.d.ts.map +1 -0
- package/dist/utils/meeting-url.js +30 -0
- package/dist/utils/meeting-url.js.map +1 -0
- package/dist/utils/offline-notice.d.ts +10 -0
- package/dist/utils/offline-notice.d.ts.map +1 -0
- package/dist/utils/offline-notice.js +10 -0
- package/dist/utils/offline-notice.js.map +1 -0
- package/dist/utils/reply-chain.d.ts +6 -0
- package/dist/utils/reply-chain.d.ts.map +1 -0
- package/dist/utils/reply-chain.js +15 -0
- package/dist/utils/reply-chain.js.map +1 -0
- package/dist/utils/verification-code.d.ts +29 -0
- package/dist/utils/verification-code.d.ts.map +1 -0
- package/dist/utils/verification-code.js +305 -0
- package/dist/utils/verification-code.js.map +1 -0
- package/dist/utils/verification-link.d.ts +26 -0
- package/dist/utils/verification-link.d.ts.map +1 -0
- package/dist/utils/verification-link.js +197 -0
- package/dist/utils/verification-link.js.map +1 -0
- package/package.json +106 -4
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Resource: email://templates/{name}
|
|
3
|
+
*
|
|
4
|
+
* Dynamic resource exposing user-defined email templates.
|
|
5
|
+
*/
|
|
6
|
+
import { ResourceTemplate } from '@modelcontextprotocol/server';
|
|
7
|
+
export default function registerTemplatesResource(server, templateService) {
|
|
8
|
+
server.registerResource('templates', new ResourceTemplate('email://templates/{name}', {
|
|
9
|
+
list: async () => {
|
|
10
|
+
const templates = await templateService.listTemplates();
|
|
11
|
+
return {
|
|
12
|
+
resources: templates.map((t) => ({
|
|
13
|
+
uri: `email://templates/${t.name}`,
|
|
14
|
+
name: `Template: ${t.name}`,
|
|
15
|
+
description: t.description ?? `Email template "${t.name}"`,
|
|
16
|
+
mimeType: 'application/json',
|
|
17
|
+
})),
|
|
18
|
+
};
|
|
19
|
+
},
|
|
20
|
+
}), { description: 'User-defined email template with variable placeholders' }, async (uri, { name }) => {
|
|
21
|
+
const templateName = name;
|
|
22
|
+
const template = await templateService.getTemplate(templateName);
|
|
23
|
+
return {
|
|
24
|
+
contents: [
|
|
25
|
+
{
|
|
26
|
+
uri: uri.href,
|
|
27
|
+
mimeType: 'application/json',
|
|
28
|
+
text: JSON.stringify(template, null, 2),
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=templates.resource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates.resource.js","sourceRoot":"","sources":["../../src/resources/templates.resource.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAIhE,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAC/C,MAAiB,EACjB,eAAgC;IAEhC,MAAM,CAAC,gBAAgB,CACrB,WAAW,EACX,IAAI,gBAAgB,CAAC,0BAA0B,EAAE;QAC/C,IAAI,EAAE,KAAK,IAAI,EAAE;YACf,MAAM,SAAS,GAAG,MAAM,eAAe,CAAC,aAAa,EAAE,CAAC;YACxD,OAAO;gBACL,SAAS,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;oBAC/B,GAAG,EAAE,qBAAqB,CAAC,CAAC,IAAI,EAAE;oBAClC,IAAI,EAAE,aAAa,CAAC,CAAC,IAAI,EAAE;oBAC3B,WAAW,EAAE,CAAC,CAAC,WAAW,IAAI,mBAAmB,CAAC,CAAC,IAAI,GAAG;oBAC1D,QAAQ,EAAE,kBAAkB;iBAC7B,CAAC,CAAC;aACJ,CAAC;QACJ,CAAC;KACF,CAAC,EACF,EAAE,WAAW,EAAE,wDAAwD,EAAE,EACzE,KAAK,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;QACtB,MAAM,YAAY,GAAG,IAAc,CAAC;QACpC,MAAM,QAAQ,GAAG,MAAM,eAAe,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;QAEjE,OAAO;YACL,QAAQ,EAAE;gBACR;oBACE,GAAG,EAAE,GAAG,CAAC,IAAI;oBACb,QAAQ,EAAE,kBAAkB;oBAC5B,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;iBACxC;aACF;SACF,CAAC;IACJ,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Resource: email://{account}/unread
|
|
3
|
+
*
|
|
4
|
+
* Dynamic resource providing an unread email summary per folder.
|
|
5
|
+
* Only includes folders with unread messages.
|
|
6
|
+
*/
|
|
7
|
+
import type { McpServer } from '@modelcontextprotocol/server';
|
|
8
|
+
import type ConnectionManager from '../connections/manager.js';
|
|
9
|
+
import type ImapService from '../services/imap.service.js';
|
|
10
|
+
export default function registerUnreadResource(server: McpServer, connections: ConnectionManager, imapService: ImapService): void;
|
|
11
|
+
//# sourceMappingURL=unread.resource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unread.resource.d.ts","sourceRoot":"","sources":["../../src/resources/unread.resource.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAG9D,OAAO,KAAK,iBAAiB,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,WAAW,MAAM,6BAA6B,CAAC;AAE3D,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,MAAM,EAAE,SAAS,EACjB,WAAW,EAAE,iBAAiB,EAC9B,WAAW,EAAE,WAAW,GACvB,IAAI,CAuDN"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Resource: email://{account}/unread
|
|
3
|
+
*
|
|
4
|
+
* Dynamic resource providing an unread email summary per folder.
|
|
5
|
+
* Only includes folders with unread messages.
|
|
6
|
+
*/
|
|
7
|
+
import { ResourceTemplate } from '@modelcontextprotocol/server';
|
|
8
|
+
export default function registerUnreadResource(server, connections, imapService) {
|
|
9
|
+
const names = connections.getAccountNames();
|
|
10
|
+
const accounts = names.map((name) => connections.getAccount(name));
|
|
11
|
+
server.registerResource('unread', new ResourceTemplate('email://{account}/unread', {
|
|
12
|
+
list: async () => ({
|
|
13
|
+
resources: accounts.map((a) => ({
|
|
14
|
+
uri: `email://${a.name}/unread`,
|
|
15
|
+
name: `${a.name} — Unread summary`,
|
|
16
|
+
description: `Unread email counts by folder for ${a.email}`,
|
|
17
|
+
mimeType: 'application/json',
|
|
18
|
+
})),
|
|
19
|
+
}),
|
|
20
|
+
}), { description: 'Unread email count summary by folder for an account' }, async (uri, { account }) => {
|
|
21
|
+
const accountName = account;
|
|
22
|
+
const mailboxes = await imapService.listMailboxes(accountName);
|
|
23
|
+
const unreadFolders = mailboxes
|
|
24
|
+
.filter((mb) => mb.unseenMessages !== undefined && mb.unseenMessages > 0)
|
|
25
|
+
.map((mb) => ({
|
|
26
|
+
path: mb.path,
|
|
27
|
+
unread: mb.unseenMessages,
|
|
28
|
+
}));
|
|
29
|
+
// Folders whose STATUS call failed have an unknown unread count, so
|
|
30
|
+
// totalUnread is a lower bound rather than a fact. Say so instead of
|
|
31
|
+
// letting the consumer read an incomplete total as complete.
|
|
32
|
+
const incompleteFolders = mailboxes
|
|
33
|
+
.filter((mb) => mb.unseenMessages === undefined)
|
|
34
|
+
.map((mb) => mb.path);
|
|
35
|
+
const totalUnread = unreadFolders.reduce((sum, f) => sum + f.unread, 0);
|
|
36
|
+
const summary = {
|
|
37
|
+
account: accountName,
|
|
38
|
+
totalUnread,
|
|
39
|
+
folders: unreadFolders,
|
|
40
|
+
...(incompleteFolders.length > 0 ? { incompleteFolders } : {}),
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
contents: [
|
|
44
|
+
{
|
|
45
|
+
uri: uri.href,
|
|
46
|
+
mimeType: 'application/json',
|
|
47
|
+
text: JSON.stringify(summary, null, 2),
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=unread.resource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unread.resource.js","sourceRoot":"","sources":["../../src/resources/unread.resource.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAKhE,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,MAAiB,EACjB,WAA8B,EAC9B,WAAwB;IAExB,MAAM,KAAK,GAAG,WAAW,CAAC,eAAe,EAAE,CAAC;IAC5C,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;IAEnE,MAAM,CAAC,gBAAgB,CACrB,QAAQ,EACR,IAAI,gBAAgB,CAAC,0BAA0B,EAAE;QAC/C,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;YACjB,SAAS,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;gBAC9B,GAAG,EAAE,WAAW,CAAC,CAAC,IAAI,SAAS;gBAC/B,IAAI,EAAE,GAAG,CAAC,CAAC,IAAI,mBAAmB;gBAClC,WAAW,EAAE,qCAAqC,CAAC,CAAC,KAAK,EAAE;gBAC3D,QAAQ,EAAE,kBAAkB;aAC7B,CAAC,CAAC;SACJ,CAAC;KACH,CAAC,EACF,EAAE,WAAW,EAAE,qDAAqD,EAAE,EACtE,KAAK,EAAE,GAAG,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;QACzB,MAAM,WAAW,GAAG,OAAiB,CAAC;QACtC,MAAM,SAAS,GAAG,MAAM,WAAW,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;QAE/D,MAAM,aAAa,GAAG,SAAS;aAC5B,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,cAAc,KAAK,SAAS,IAAI,EAAE,CAAC,cAAc,GAAG,CAAC,CAAC;aACxE,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;YACZ,IAAI,EAAE,EAAE,CAAC,IAAI;YACb,MAAM,EAAE,EAAE,CAAC,cAAwB;SACpC,CAAC,CAAC,CAAC;QAEN,oEAAoE;QACpE,qEAAqE;QACrE,6DAA6D;QAC7D,MAAM,iBAAiB,GAAG,SAAS;aAChC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,cAAc,KAAK,SAAS,CAAC;aAC/C,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;QAExB,MAAM,WAAW,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAExE,MAAM,OAAO,GAAG;YACd,OAAO,EAAE,WAAW;YACpB,WAAW;YACX,OAAO,EAAE,aAAa;YACtB,GAAG,CAAC,iBAAiB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC/D,CAAC;QAEF,OAAO;YACL,QAAQ,EAAE;gBACR;oBACE,GAAG,EAAE,GAAG,CAAC,IAAI;oBACb,QAAQ,EAAE,kBAAkB;oBAC5B,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;iBACvC;aACF;SACF,CAAC;IACJ,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Audit logger — append-only JSON Lines log for all write operations.
|
|
3
|
+
*
|
|
4
|
+
* Logs are stored at the XDG data directory:
|
|
5
|
+
* ~/.local/share/email-mcp/audit.log
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Append a single audit entry to the log file.
|
|
9
|
+
* Creates the directory and file if they don't exist.
|
|
10
|
+
*/
|
|
11
|
+
declare function log(tool: string, account: string, params: Record<string, unknown>, result: 'ok' | 'error', error?: string): Promise<void>;
|
|
12
|
+
declare const audit: {
|
|
13
|
+
readonly log: typeof log;
|
|
14
|
+
readonly AUDIT_LOG_PATH: string;
|
|
15
|
+
};
|
|
16
|
+
export default audit;
|
|
17
|
+
//# sourceMappingURL=audit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../../src/safety/audit.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgCH;;;GAGG;AACH,iBAAe,GAAG,CAChB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,MAAM,EAAE,IAAI,GAAG,OAAO,EACtB,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAcf;AAED,QAAA,MAAM,KAAK;;;CAAmC,CAAC;eAEhC,KAAK"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Audit logger — append-only JSON Lines log for all write operations.
|
|
3
|
+
*
|
|
4
|
+
* Logs are stored at the XDG data directory:
|
|
5
|
+
* ~/.local/share/email-mcp/audit.log
|
|
6
|
+
*/
|
|
7
|
+
import fs from 'node:fs/promises';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { xdg } from '../config/xdg.js';
|
|
10
|
+
const AUDIT_LOG_PATH = path.join(xdg.data, 'audit.log');
|
|
11
|
+
/** Fields redacted from audit params to protect sensitive data. */
|
|
12
|
+
const REDACTED_FIELDS = new Set(['password', 'body', 'bodyText', 'bodyHtml', 'content_base64']);
|
|
13
|
+
function redactParams(params) {
|
|
14
|
+
const cleaned = {};
|
|
15
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
16
|
+
if (REDACTED_FIELDS.has(key)) {
|
|
17
|
+
cleaned[key] = '[REDACTED]';
|
|
18
|
+
}
|
|
19
|
+
else if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
20
|
+
cleaned[key] = redactParams(value);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
cleaned[key] = value;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return cleaned;
|
|
27
|
+
}
|
|
28
|
+
async function ensureLogDir() {
|
|
29
|
+
await fs.mkdir(path.dirname(AUDIT_LOG_PATH), { recursive: true });
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Append a single audit entry to the log file.
|
|
33
|
+
* Creates the directory and file if they don't exist.
|
|
34
|
+
*/
|
|
35
|
+
async function log(tool, account, params, result, error) {
|
|
36
|
+
await ensureLogDir();
|
|
37
|
+
const entry = {
|
|
38
|
+
ts: new Date().toISOString(),
|
|
39
|
+
tool,
|
|
40
|
+
account,
|
|
41
|
+
params: redactParams(params),
|
|
42
|
+
result,
|
|
43
|
+
...(error ? { error } : {}),
|
|
44
|
+
};
|
|
45
|
+
const line = `${JSON.stringify(entry)}\n`;
|
|
46
|
+
await fs.appendFile(AUDIT_LOG_PATH, line, 'utf-8');
|
|
47
|
+
}
|
|
48
|
+
const audit = { log, AUDIT_LOG_PATH };
|
|
49
|
+
export default audit;
|
|
50
|
+
//# sourceMappingURL=audit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit.js","sourceRoot":"","sources":["../../src/safety/audit.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAIvC,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;AAExD,mEAAmE;AACnE,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAAC,CAAC;AAEhG,SAAS,YAAY,CAAC,MAA+B;IACnD,MAAM,OAAO,GAA4B,EAAE,CAAC;IAC5C,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QAC9C,IAAI,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAC7B,OAAO,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC;QAC9B,CAAC;aAAM,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACvE,OAAO,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,KAAgC,CAAC,CAAC;QAChE,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACvB,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,KAAK,UAAU,YAAY;IACzB,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AACpE,CAAC;AAED;;;GAGG;AACH,KAAK,UAAU,GAAG,CAChB,IAAY,EACZ,OAAe,EACf,MAA+B,EAC/B,MAAsB,EACtB,KAAc;IAEd,MAAM,YAAY,EAAE,CAAC;IAErB,MAAM,KAAK,GAAe;QACxB,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QAC5B,IAAI;QACJ,OAAO;QACP,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC;QAC5B,MAAM;QACN,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC5B,CAAC;IAEF,MAAM,IAAI,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC;IAC1C,MAAM,EAAE,CAAC,UAAU,CAAC,cAAc,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AACrD,CAAC;AAED,MAAM,KAAK,GAAG,EAAE,GAAG,EAAE,cAAc,EAAW,CAAC;AAE/C,eAAe,KAAK,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token-bucket rate limiter.
|
|
3
|
+
*
|
|
4
|
+
* Limits the number of send operations per account within a time window.
|
|
5
|
+
* Defaults to 10 sends per 60-second window.
|
|
6
|
+
*/
|
|
7
|
+
export default class RateLimiter {
|
|
8
|
+
private buckets;
|
|
9
|
+
private readonly maxTokens;
|
|
10
|
+
private readonly windowMs;
|
|
11
|
+
constructor(maxPerMinute?: number);
|
|
12
|
+
/**
|
|
13
|
+
* Try to consume a token for the given account.
|
|
14
|
+
* @returns `true` if allowed, `false` if rate-limited.
|
|
15
|
+
*/
|
|
16
|
+
tryConsume(accountName: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Get remaining tokens for an account.
|
|
19
|
+
*/
|
|
20
|
+
remaining(accountName: string): number;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=rate-limiter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limiter.d.ts","sourceRoot":"","sources":["../../src/safety/rate-limiter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,OAAO,OAAO,WAAW;IAC9B,OAAO,CAAC,OAAO,CAA6D;IAE5E,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IAEnC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAElC,YAAY,YAAY,SAAK,EAG5B;IAED;;;OAGG;IACH,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAuBvC;IAED;;OAEG;IACH,SAAS,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAQrC;CACF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token-bucket rate limiter.
|
|
3
|
+
*
|
|
4
|
+
* Limits the number of send operations per account within a time window.
|
|
5
|
+
* Defaults to 10 sends per 60-second window.
|
|
6
|
+
*/
|
|
7
|
+
export default class RateLimiter {
|
|
8
|
+
buckets = new Map();
|
|
9
|
+
maxTokens;
|
|
10
|
+
windowMs;
|
|
11
|
+
constructor(maxPerMinute = 10) {
|
|
12
|
+
this.maxTokens = maxPerMinute;
|
|
13
|
+
this.windowMs = 60_000;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Try to consume a token for the given account.
|
|
17
|
+
* @returns `true` if allowed, `false` if rate-limited.
|
|
18
|
+
*/
|
|
19
|
+
tryConsume(accountName) {
|
|
20
|
+
const now = Date.now();
|
|
21
|
+
let bucket = this.buckets.get(accountName);
|
|
22
|
+
if (!bucket) {
|
|
23
|
+
bucket = { tokens: this.maxTokens, lastRefill: now };
|
|
24
|
+
this.buckets.set(accountName, bucket);
|
|
25
|
+
}
|
|
26
|
+
// Refill tokens based on elapsed time
|
|
27
|
+
const elapsed = now - bucket.lastRefill;
|
|
28
|
+
const refill = Math.floor((elapsed / this.windowMs) * this.maxTokens);
|
|
29
|
+
if (refill > 0) {
|
|
30
|
+
bucket.tokens = Math.min(this.maxTokens, bucket.tokens + refill);
|
|
31
|
+
bucket.lastRefill = now;
|
|
32
|
+
}
|
|
33
|
+
if (bucket.tokens > 0) {
|
|
34
|
+
bucket.tokens -= 1;
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get remaining tokens for an account.
|
|
41
|
+
*/
|
|
42
|
+
remaining(accountName) {
|
|
43
|
+
const bucket = this.buckets.get(accountName);
|
|
44
|
+
if (!bucket)
|
|
45
|
+
return this.maxTokens;
|
|
46
|
+
// Calculate refill
|
|
47
|
+
const elapsed = Date.now() - bucket.lastRefill;
|
|
48
|
+
const refill = Math.floor((elapsed / this.windowMs) * this.maxTokens);
|
|
49
|
+
return Math.min(this.maxTokens, bucket.tokens + refill);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=rate-limiter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limiter.js","sourceRoot":"","sources":["../../src/safety/rate-limiter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,OAAO,OAAO,WAAW;IACtB,OAAO,GAAG,IAAI,GAAG,EAAkD,CAAC;IAE3D,SAAS,CAAS;IAElB,QAAQ,CAAS;IAElC,YAAY,YAAY,GAAG,EAAE;QAC3B,IAAI,CAAC,SAAS,GAAG,YAAY,CAAC;QAC9B,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC;IACzB,CAAC;IAED;;;OAGG;IACH,UAAU,CAAC,WAAmB;QAC5B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,IAAI,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QAE3C,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC;YACrD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;QACxC,CAAC;QAED,sCAAsC;QACtC,MAAM,OAAO,GAAG,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC;QACxC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC;QACtE,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;YACf,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;YACjE,MAAM,CAAC,UAAU,GAAG,GAAG,CAAC;QAC1B,CAAC;QAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,MAAM,CAAC,MAAM,IAAI,CAAC,CAAC;YACnB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACH,SAAS,CAAC,WAAmB;QAC3B,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QAC7C,IAAI,CAAC,MAAM;YAAE,OAAO,IAAI,CAAC,SAAS,CAAC;QAEnC,mBAAmB;QACnB,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,UAAU,CAAC;QAC/C,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC;QACtE,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;IAC1D,CAAC;CACF"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** Input validation and sanitization utilities. */
|
|
2
|
+
/**
|
|
3
|
+
* Validate and sanitize an IMAP mailbox name.
|
|
4
|
+
* Rejects names containing IMAP wildcard characters (`*`, `%`) or empty strings.
|
|
5
|
+
* @param name - The mailbox name to validate.
|
|
6
|
+
* @returns The trimmed mailbox name.
|
|
7
|
+
*/
|
|
8
|
+
export declare function sanitizeMailboxName(name: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Strip control characters from an IMAP search query.
|
|
11
|
+
* Removes ASCII 0-31 except tab (0x09) and newline (0x0A).
|
|
12
|
+
* @param query - The raw search query.
|
|
13
|
+
* @returns The sanitized query string.
|
|
14
|
+
*/
|
|
15
|
+
export declare function sanitizeSearchQuery(query: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Validate a webhook URL.
|
|
18
|
+
* Ensures the URL uses http(s) and does not point to a private or loopback address.
|
|
19
|
+
* @param url - The webhook URL to validate.
|
|
20
|
+
*/
|
|
21
|
+
export declare function validateWebhookUrl(url: string): void;
|
|
22
|
+
/**
|
|
23
|
+
* Sanitize a value for use in a template.
|
|
24
|
+
* When `html` is true, HTML-special characters are escaped.
|
|
25
|
+
* @param value - The template variable value.
|
|
26
|
+
* @param html - Whether to apply HTML escaping.
|
|
27
|
+
* @returns The sanitized value.
|
|
28
|
+
*/
|
|
29
|
+
export declare function sanitizeTemplateVariable(value: string, html: boolean): string;
|
|
30
|
+
/**
|
|
31
|
+
* Validate an email label name.
|
|
32
|
+
* Rejects labels with control characters or that exceed 200 characters.
|
|
33
|
+
* @param name - The label name to validate.
|
|
34
|
+
* @returns The trimmed label name.
|
|
35
|
+
*/
|
|
36
|
+
export declare function validateLabelName(name: string): string;
|
|
37
|
+
/** Maximum allowed length for email bodies (shared across send/reply/forward/draft). */
|
|
38
|
+
export declare const MAX_EMAIL_BODY_LENGTH = 5000000;
|
|
39
|
+
/**
|
|
40
|
+
* Validate that an input string does not exceed a maximum length.
|
|
41
|
+
* @param input - The input string to check.
|
|
42
|
+
* @param maxLength - The maximum allowed length.
|
|
43
|
+
* @param fieldName - The field name for the error message.
|
|
44
|
+
*/
|
|
45
|
+
export declare function validateInputLength(input: string, maxLength: number, fieldName: string): void;
|
|
46
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/safety/validation.ts"],"names":[],"mappings":"AAIA,mDAAmD;AAEnD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CASxD;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOzD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAwBpD;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,CAU7E;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAetD;AAED,wFAAwF;AACxF,eAAO,MAAM,qBAAqB,UAAY,CAAC;AAE/C;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAI7F"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import net from 'node:net';
|
|
2
|
+
import { isForbiddenAddress } from './webhook-guard.js';
|
|
3
|
+
/** Input validation and sanitization utilities. */
|
|
4
|
+
/**
|
|
5
|
+
* Validate and sanitize an IMAP mailbox name.
|
|
6
|
+
* Rejects names containing IMAP wildcard characters (`*`, `%`) or empty strings.
|
|
7
|
+
* @param name - The mailbox name to validate.
|
|
8
|
+
* @returns The trimmed mailbox name.
|
|
9
|
+
*/
|
|
10
|
+
export function sanitizeMailboxName(name) {
|
|
11
|
+
const trimmed = name.trim();
|
|
12
|
+
if (trimmed.length === 0) {
|
|
13
|
+
throw new Error('Mailbox name must not be empty');
|
|
14
|
+
}
|
|
15
|
+
if (trimmed.includes('*') || trimmed.includes('%')) {
|
|
16
|
+
throw new Error('Mailbox name must not contain IMAP wildcard characters (* or %)');
|
|
17
|
+
}
|
|
18
|
+
return trimmed;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Strip control characters from an IMAP search query.
|
|
22
|
+
* Removes ASCII 0-31 except tab (0x09) and newline (0x0A).
|
|
23
|
+
* @param query - The raw search query.
|
|
24
|
+
* @returns The sanitized query string.
|
|
25
|
+
*/
|
|
26
|
+
export function sanitizeSearchQuery(query) {
|
|
27
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: intentional — sanitize control chars from user input
|
|
28
|
+
const cleaned = query.replace(/[\x00-\x08\x0B-\x1F]/g, '').trim(); // eslint-disable-line no-control-regex
|
|
29
|
+
if (cleaned.length === 0) {
|
|
30
|
+
throw new Error('Search query must not be empty after sanitization');
|
|
31
|
+
}
|
|
32
|
+
return cleaned;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Validate a webhook URL.
|
|
36
|
+
* Ensures the URL uses http(s) and does not point to a private or loopback address.
|
|
37
|
+
* @param url - The webhook URL to validate.
|
|
38
|
+
*/
|
|
39
|
+
export function validateWebhookUrl(url) {
|
|
40
|
+
let parsed;
|
|
41
|
+
try {
|
|
42
|
+
parsed = new URL(url);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
throw new Error(`Invalid webhook URL: ${url}`);
|
|
46
|
+
}
|
|
47
|
+
if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') {
|
|
48
|
+
throw new Error(`Webhook URL must use http or https protocol, got ${parsed.protocol}`);
|
|
49
|
+
}
|
|
50
|
+
const hostname = parsed.hostname.toLowerCase();
|
|
51
|
+
// new URL('https://[::1]') stores hostname as '[::1]'
|
|
52
|
+
const bare = hostname.replace(/^\[|\]$/g, '').replace(/\.$/, '');
|
|
53
|
+
if (bare === 'localhost') {
|
|
54
|
+
throw new Error(`Webhook URL must not point to a loopback or private address: ${bare}`);
|
|
55
|
+
}
|
|
56
|
+
// Any literal IP — use the authoritative range check.
|
|
57
|
+
if (net.isIP(bare) !== 0 && isForbiddenAddress(bare)) {
|
|
58
|
+
throw new Error(`Webhook URL must not point to a loopback or private address: ${bare}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Sanitize a value for use in a template.
|
|
63
|
+
* When `html` is true, HTML-special characters are escaped.
|
|
64
|
+
* @param value - The template variable value.
|
|
65
|
+
* @param html - Whether to apply HTML escaping.
|
|
66
|
+
* @returns The sanitized value.
|
|
67
|
+
*/
|
|
68
|
+
export function sanitizeTemplateVariable(value, html) {
|
|
69
|
+
if (!html) {
|
|
70
|
+
return value;
|
|
71
|
+
}
|
|
72
|
+
return value
|
|
73
|
+
.replace(/&/g, '&')
|
|
74
|
+
.replace(/</g, '<')
|
|
75
|
+
.replace(/>/g, '>')
|
|
76
|
+
.replace(/"/g, '"')
|
|
77
|
+
.replace(/'/g, ''');
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Validate an email label name.
|
|
81
|
+
* Rejects labels with control characters or that exceed 200 characters.
|
|
82
|
+
* @param name - The label name to validate.
|
|
83
|
+
* @returns The trimmed label name.
|
|
84
|
+
*/
|
|
85
|
+
export function validateLabelName(name) {
|
|
86
|
+
const trimmed = name.trim();
|
|
87
|
+
if (trimmed.length === 0) {
|
|
88
|
+
throw new Error('Label name must not be empty');
|
|
89
|
+
}
|
|
90
|
+
if (trimmed.length > 200) {
|
|
91
|
+
throw new Error('Label name must not exceed 200 characters');
|
|
92
|
+
}
|
|
93
|
+
/* eslint-disable no-control-regex */
|
|
94
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: intentional — reject control chars in label names
|
|
95
|
+
if (/[\x00-\x1F]/.test(trimmed)) {
|
|
96
|
+
throw new Error('Label name must not contain control characters');
|
|
97
|
+
}
|
|
98
|
+
/* eslint-enable no-control-regex */
|
|
99
|
+
return trimmed;
|
|
100
|
+
}
|
|
101
|
+
/** Maximum allowed length for email bodies (shared across send/reply/forward/draft). */
|
|
102
|
+
export const MAX_EMAIL_BODY_LENGTH = 5_000_000;
|
|
103
|
+
/**
|
|
104
|
+
* Validate that an input string does not exceed a maximum length.
|
|
105
|
+
* @param input - The input string to check.
|
|
106
|
+
* @param maxLength - The maximum allowed length.
|
|
107
|
+
* @param fieldName - The field name for the error message.
|
|
108
|
+
*/
|
|
109
|
+
export function validateInputLength(input, maxLength, fieldName) {
|
|
110
|
+
if (input.length > maxLength) {
|
|
111
|
+
throw new Error(`${fieldName} exceeds maximum length of ${maxLength} characters`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/safety/validation.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Webhook destination guard.
|
|
3
|
+
*
|
|
4
|
+
* A webhook URL decides where notification payloads go. The synchronous
|
|
5
|
+
* string checks in validation.ts catch obvious literals, but they inspect
|
|
6
|
+
* the hostname as text: they never resolve it, so a name that resolves into
|
|
7
|
+
* private address space passes, and they never see where a redirect lands.
|
|
8
|
+
*
|
|
9
|
+
* This module is the authoritative gate. It resolves every hostname and
|
|
10
|
+
* range-checks every resolved address before a request may go out, and
|
|
11
|
+
* treats any address inside private, loopback, link-local, or otherwise
|
|
12
|
+
* non-routable space as refused. Resolution failure refuses too: an
|
|
13
|
+
* unresolvable destination is not a destination.
|
|
14
|
+
*/
|
|
15
|
+
export type Lookup = (hostname: string) => Promise<{
|
|
16
|
+
address: string;
|
|
17
|
+
family: number;
|
|
18
|
+
}[]>;
|
|
19
|
+
/** True when the address is inside a range that must never receive webhooks. */
|
|
20
|
+
export declare function isForbiddenAddress(address: string): boolean;
|
|
21
|
+
export interface ValidatedTarget {
|
|
22
|
+
hostname: string;
|
|
23
|
+
address: string;
|
|
24
|
+
family: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Refuses a webhook URL unless every address its hostname resolves to is
|
|
28
|
+
* public. Returns the validated target pinned to the address that was checked,
|
|
29
|
+
* so dispatch can connect to that address rather than resolving again.
|
|
30
|
+
* Throws with an operator-actionable message when refused.
|
|
31
|
+
*/
|
|
32
|
+
export declare function assertWebhookTargetAllowed(url: string, lookup?: Lookup): Promise<ValidatedTarget>;
|
|
33
|
+
//# sourceMappingURL=webhook-guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook-guard.d.ts","sourceRoot":"","sources":["../../src/safety/webhook-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAKH,MAAM,MAAM,MAAM,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAAE,CAAC,CAAC;AAK1F,gFAAgF;AAChF,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAa3D;AA4ED,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;GAKG;AACH,wBAAsB,0BAA0B,CAC9C,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,MAAuB,GAC9B,OAAO,CAAC,eAAe,CAAC,CAgD1B"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Webhook destination guard.
|
|
3
|
+
*
|
|
4
|
+
* A webhook URL decides where notification payloads go. The synchronous
|
|
5
|
+
* string checks in validation.ts catch obvious literals, but they inspect
|
|
6
|
+
* the hostname as text: they never resolve it, so a name that resolves into
|
|
7
|
+
* private address space passes, and they never see where a redirect lands.
|
|
8
|
+
*
|
|
9
|
+
* This module is the authoritative gate. It resolves every hostname and
|
|
10
|
+
* range-checks every resolved address before a request may go out, and
|
|
11
|
+
* treats any address inside private, loopback, link-local, or otherwise
|
|
12
|
+
* non-routable space as refused. Resolution failure refuses too: an
|
|
13
|
+
* unresolvable destination is not a destination.
|
|
14
|
+
*/
|
|
15
|
+
import { promises as dnsPromises } from 'node:dns';
|
|
16
|
+
import net from 'node:net';
|
|
17
|
+
const DEFAULT_LOOKUP = async (hostname) => dnsPromises.lookup(hostname, { all: true, verbatim: true });
|
|
18
|
+
/** True when the address is inside a range that must never receive webhooks. */
|
|
19
|
+
export function isForbiddenAddress(address) {
|
|
20
|
+
const family = net.isIP(address);
|
|
21
|
+
if (family === 4) {
|
|
22
|
+
return isForbiddenIPv4(address);
|
|
23
|
+
}
|
|
24
|
+
if (family === 6) {
|
|
25
|
+
return isForbiddenIPv6(address);
|
|
26
|
+
}
|
|
27
|
+
// Not an IP literal the parser recognises — refuse rather than guess.
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
function isForbiddenIPv4(address) {
|
|
31
|
+
const octets = address.split('.').map(Number);
|
|
32
|
+
const [a, b] = octets;
|
|
33
|
+
// Loopback and this-host ranges.
|
|
34
|
+
if (a === 0 || a === 10 || a === 127)
|
|
35
|
+
return true;
|
|
36
|
+
// Link-local, which includes cloud metadata services.
|
|
37
|
+
if (a === 169 && b === 254)
|
|
38
|
+
return true;
|
|
39
|
+
// Carrier-grade NAT.
|
|
40
|
+
if (a === 100 && b >= 64 && b <= 127)
|
|
41
|
+
return true;
|
|
42
|
+
// RFC 1918 private space.
|
|
43
|
+
if (a === 172 && b >= 16 && b <= 31)
|
|
44
|
+
return true;
|
|
45
|
+
if (a === 192 && b === 168)
|
|
46
|
+
return true;
|
|
47
|
+
// IETF protocol assignments and benchmarking ranges.
|
|
48
|
+
if (a === 192 && b === 0)
|
|
49
|
+
return true;
|
|
50
|
+
if (a === 198 && (b === 18 || b === 19))
|
|
51
|
+
return true;
|
|
52
|
+
// Multicast and reserved.
|
|
53
|
+
if (a >= 224)
|
|
54
|
+
return true;
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
function isForbiddenIPv6(address) {
|
|
58
|
+
const lower = address.toLowerCase();
|
|
59
|
+
// IPv4-mapped addresses arrive in either textual form depending on how the
|
|
60
|
+
// URL was written ('::ffff:127.0.0.1' stays dotted, '::ffff:7f00:1' stays
|
|
61
|
+
// hex). Unwrap both and re-check the embedded v4.
|
|
62
|
+
const mappedDotted = /^::ffff:(\d+\.\d+\.\d+\.\d+)$/.exec(lower);
|
|
63
|
+
if (mappedDotted)
|
|
64
|
+
return isForbiddenIPv4(mappedDotted[1]);
|
|
65
|
+
const mappedHex = /^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/.exec(lower);
|
|
66
|
+
if (mappedHex) {
|
|
67
|
+
const hi = parseInt(mappedHex[1], 16);
|
|
68
|
+
const lo = parseInt(mappedHex[2], 16);
|
|
69
|
+
return isForbiddenIPv4(`${(hi >> 8) & 0xff}.${hi & 0xff}.${(lo >> 8) & 0xff}.${lo & 0xff}`);
|
|
70
|
+
}
|
|
71
|
+
const expanded = expandIPv6(lower);
|
|
72
|
+
if (expanded === null)
|
|
73
|
+
return true;
|
|
74
|
+
// :: (unspecified) and ::1 (loopback).
|
|
75
|
+
if (expanded === '0'.repeat(32) || expanded === `${'0'.repeat(31)}1`)
|
|
76
|
+
return true;
|
|
77
|
+
// fc00::/7 unique-local.
|
|
78
|
+
if (expanded.startsWith('fc') || expanded.startsWith('fd'))
|
|
79
|
+
return true;
|
|
80
|
+
// fe80::/10 link-local.
|
|
81
|
+
if (/^fe[89ab]/.test(expanded))
|
|
82
|
+
return true;
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
/** Expands an IPv6 address to 32 lowercase hex chars, or null when invalid. */
|
|
86
|
+
function expandIPv6(address) {
|
|
87
|
+
if (!net.isIPv6(address))
|
|
88
|
+
return null;
|
|
89
|
+
const [headRaw, ...tailParts] = address.split('::');
|
|
90
|
+
const tail = tailParts.length > 0 ? tailParts.join('::').split('::')[0] : '';
|
|
91
|
+
const headGroups = headRaw ? headRaw.split(':') : [];
|
|
92
|
+
const tailGroups = tail ? tail.split(':') : [];
|
|
93
|
+
const missing = 8 - headGroups.length - tailGroups.length;
|
|
94
|
+
if (tailParts.length > 0 && missing < 0)
|
|
95
|
+
return null;
|
|
96
|
+
const zeros = Array.from({ length: Math.max(missing, 0) }, () => '0000');
|
|
97
|
+
const groups = [...headGroups, ...zeros, ...tailGroups];
|
|
98
|
+
if (groups.length !== 8)
|
|
99
|
+
return null;
|
|
100
|
+
for (const group of groups) {
|
|
101
|
+
if (!/^[0-9a-f]{1,4}$/.test(group))
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
return groups.map((g) => g.padStart(4, '0')).join('');
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Refuses a webhook URL unless every address its hostname resolves to is
|
|
108
|
+
* public. Returns the validated target pinned to the address that was checked,
|
|
109
|
+
* so dispatch can connect to that address rather than resolving again.
|
|
110
|
+
* Throws with an operator-actionable message when refused.
|
|
111
|
+
*/
|
|
112
|
+
export async function assertWebhookTargetAllowed(url, lookup = DEFAULT_LOOKUP) {
|
|
113
|
+
let parsed;
|
|
114
|
+
try {
|
|
115
|
+
parsed = new URL(url);
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
throw new Error(`Invalid webhook URL: ${url}`);
|
|
119
|
+
}
|
|
120
|
+
if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') {
|
|
121
|
+
throw new Error(`Webhook URL must use http or https protocol, got ${parsed.protocol}`);
|
|
122
|
+
}
|
|
123
|
+
// The FQDN form of a name carries a trailing dot ('localhost.'), which
|
|
124
|
+
// resolves identically but compares differently as text. Normalise first.
|
|
125
|
+
const hostname = parsed.hostname.replace(/^\[|\]$/g, '').replace(/\.$/, '');
|
|
126
|
+
// Literal addresses need no resolution — pin to the literal itself.
|
|
127
|
+
if (net.isIP(hostname) !== 0) {
|
|
128
|
+
if (isForbiddenAddress(hostname)) {
|
|
129
|
+
throw new Error(`Webhook URL must point to a public address: ${hostname} is not routable`);
|
|
130
|
+
}
|
|
131
|
+
return { hostname, address: hostname, family: net.isIP(hostname) };
|
|
132
|
+
}
|
|
133
|
+
let resolved;
|
|
134
|
+
try {
|
|
135
|
+
resolved = await lookup(hostname);
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
throw new Error(`Webhook URL hostname does not resolve: ${hostname}`);
|
|
139
|
+
}
|
|
140
|
+
if (resolved.length === 0) {
|
|
141
|
+
throw new Error(`Webhook URL hostname does not resolve: ${hostname}`);
|
|
142
|
+
}
|
|
143
|
+
for (const { address } of resolved) {
|
|
144
|
+
if (isForbiddenAddress(address)) {
|
|
145
|
+
throw new Error(`Webhook URL must point to a public address: ${hostname} resolves to ${address}, ` +
|
|
146
|
+
`which is not routable`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// Pin to the first validated address — all were checked, so any is safe.
|
|
150
|
+
// The caller must use this address for the connection, not resolve again.
|
|
151
|
+
const first = resolved[0];
|
|
152
|
+
return { hostname, address: first.address, family: first.family };
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=webhook-guard.js.map
|