@forumone/throughline-forms 0.0.1 → 0.2.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.
Files changed (116) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/LICENSE +21 -0
  3. package/README.md +132 -40
  4. package/dist/destinations.d.ts +26 -0
  5. package/dist/destinations.d.ts.map +1 -0
  6. package/dist/destinations.js +36 -0
  7. package/dist/destinations.js.map +1 -0
  8. package/dist/functions/_shared.d.ts +13 -0
  9. package/dist/functions/_shared.d.ts.map +1 -0
  10. package/dist/functions/_shared.js +44 -0
  11. package/dist/functions/_shared.js.map +1 -0
  12. package/dist/functions/email-destination.d.ts +25 -0
  13. package/dist/functions/email-destination.d.ts.map +1 -0
  14. package/dist/functions/email-destination.js +75 -0
  15. package/dist/functions/email-destination.js.map +1 -0
  16. package/dist/functions/fan-out.d.ts +24 -0
  17. package/dist/functions/fan-out.d.ts.map +1 -0
  18. package/dist/functions/fan-out.js +71 -0
  19. package/dist/functions/fan-out.js.map +1 -0
  20. package/dist/functions/index.d.ts +9 -0
  21. package/dist/functions/index.d.ts.map +1 -0
  22. package/dist/functions/index.js +5 -0
  23. package/dist/functions/index.js.map +1 -0
  24. package/dist/functions/submitter-confirmation.d.ts +25 -0
  25. package/dist/functions/submitter-confirmation.d.ts.map +1 -0
  26. package/dist/functions/submitter-confirmation.js +76 -0
  27. package/dist/functions/submitter-confirmation.js.map +1 -0
  28. package/dist/functions/webhook-destination.d.ts +20 -0
  29. package/dist/functions/webhook-destination.d.ts.map +1 -0
  30. package/dist/functions/webhook-destination.js +74 -0
  31. package/dist/functions/webhook-destination.js.map +1 -0
  32. package/dist/index.d.ts +12 -0
  33. package/dist/index.d.ts.map +1 -0
  34. package/dist/index.js +8 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/options.d.ts +74 -0
  37. package/dist/options.d.ts.map +1 -0
  38. package/dist/options.js +61 -0
  39. package/dist/options.js.map +1 -0
  40. package/dist/plugin.d.ts +19 -0
  41. package/dist/plugin.d.ts.map +1 -0
  42. package/dist/plugin.js +180 -0
  43. package/dist/plugin.js.map +1 -0
  44. package/dist/policy-fields.d.ts +18 -0
  45. package/dist/policy-fields.d.ts.map +1 -0
  46. package/dist/policy-fields.js +115 -0
  47. package/dist/policy-fields.js.map +1 -0
  48. package/dist/submit/endpoint.d.ts +16 -0
  49. package/dist/submit/endpoint.d.ts.map +1 -0
  50. package/dist/submit/endpoint.js +116 -0
  51. package/dist/submit/endpoint.js.map +1 -0
  52. package/dist/submit/ip.d.ts +20 -0
  53. package/dist/submit/ip.d.ts.map +1 -0
  54. package/dist/submit/ip.js +48 -0
  55. package/dist/submit/ip.js.map +1 -0
  56. package/dist/submit/rate-limit.d.ts +23 -0
  57. package/dist/submit/rate-limit.d.ts.map +1 -0
  58. package/dist/submit/rate-limit.js +27 -0
  59. package/dist/submit/rate-limit.js.map +1 -0
  60. package/dist/submit/spam.d.ts +10 -0
  61. package/dist/submit/spam.d.ts.map +1 -0
  62. package/dist/submit/spam.js +16 -0
  63. package/dist/submit/spam.js.map +1 -0
  64. package/dist/templates/FormSubmission.d.ts +21 -0
  65. package/dist/templates/FormSubmission.d.ts.map +1 -0
  66. package/dist/templates/FormSubmission.js +32 -0
  67. package/dist/templates/FormSubmission.js.map +1 -0
  68. package/dist/templates/SubmitterConfirmation.d.ts +18 -0
  69. package/dist/templates/SubmitterConfirmation.d.ts.map +1 -0
  70. package/dist/templates/SubmitterConfirmation.js +14 -0
  71. package/dist/templates/SubmitterConfirmation.js.map +1 -0
  72. package/dist/templates/_layout.d.ts +14 -0
  73. package/dist/templates/_layout.d.ts.map +1 -0
  74. package/dist/templates/_layout.js +34 -0
  75. package/dist/templates/_layout.js.map +1 -0
  76. package/dist/templates/index.d.ts +7 -0
  77. package/dist/templates/index.d.ts.map +1 -0
  78. package/dist/templates/index.js +4 -0
  79. package/dist/templates/index.js.map +1 -0
  80. package/dist/tools/_field-schema.d.ts +68 -0
  81. package/dist/tools/_field-schema.d.ts.map +1 -0
  82. package/dist/tools/_field-schema.js +62 -0
  83. package/dist/tools/_field-schema.js.map +1 -0
  84. package/dist/tools/access.d.ts +7 -0
  85. package/dist/tools/access.d.ts.map +1 -0
  86. package/dist/tools/access.js +16 -0
  87. package/dist/tools/access.js.map +1 -0
  88. package/dist/tools/create-form.d.ts +138 -0
  89. package/dist/tools/create-form.d.ts.map +1 -0
  90. package/dist/tools/create-form.js +96 -0
  91. package/dist/tools/create-form.js.map +1 -0
  92. package/dist/tools/get-form-submissions.d.ts +27 -0
  93. package/dist/tools/get-form-submissions.d.ts.map +1 -0
  94. package/dist/tools/get-form-submissions.js +47 -0
  95. package/dist/tools/get-form-submissions.js.map +1 -0
  96. package/dist/tools/index.d.ts +14 -0
  97. package/dist/tools/index.d.ts.map +1 -0
  98. package/dist/tools/index.js +8 -0
  99. package/dist/tools/index.js.map +1 -0
  100. package/dist/tools/list-allowed-destinations.d.ts +10 -0
  101. package/dist/tools/list-allowed-destinations.d.ts.map +1 -0
  102. package/dist/tools/list-allowed-destinations.js +14 -0
  103. package/dist/tools/list-allowed-destinations.js.map +1 -0
  104. package/dist/tools/update-form-destinations.d.ts +45 -0
  105. package/dist/tools/update-form-destinations.d.ts.map +1 -0
  106. package/dist/tools/update-form-destinations.js +75 -0
  107. package/dist/tools/update-form-destinations.js.map +1 -0
  108. package/dist/tools/update-form-fields.d.ts +101 -0
  109. package/dist/tools/update-form-fields.d.ts.map +1 -0
  110. package/dist/tools/update-form-fields.js +65 -0
  111. package/dist/tools/update-form-fields.js.map +1 -0
  112. package/dist/tools/validate-form.d.ts +127 -0
  113. package/dist/tools/validate-form.d.ts.map +1 -0
  114. package/dist/tools/validate-form.js +50 -0
  115. package/dist/tools/validate-form.js.map +1 -0
  116. package/package.json +71 -7
package/CHANGELOG.md ADDED
@@ -0,0 +1,30 @@
1
+ # @forumone/throughline-forms
2
+
3
+ ## 0.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 7ee992d: Fix broken external installs of the core plugins.
8
+
9
+ Every core plugin emits a runtime `import { getPluginRegistry } from '@forumone/throughline-plugin-contract'`, but `plugin-contract` was marked `private` and never published — so the published plugins pinned `@forumone/throughline-plugin-contract: 0.0.0`, a version that does not exist on npm, and any external `pnpm install` failed with a 404.
10
+
11
+ `plugin-contract` is now published, so the dependent plugins re-pin a real version. The cross-plugin registry is keyed on a global `Symbol.for(...)` and stored on the Payload instance, so behavior is unchanged.
12
+
13
+ Also fixes the scaffolder, which pinned `@forumone/throughline-reference-ds@^0.1.0` (latest is `0.2.0`) in the generated `apps/web` and `design-system` packages.
14
+
15
+ - Updated dependencies [7ee992d]
16
+ - @forumone/throughline-plugin-contract@0.2.1
17
+ - @forumone/throughline-core@0.2.2
18
+ - @forumone/throughline-email@0.2.2
19
+
20
+ ## 0.2.0
21
+
22
+ ### Minor Changes
23
+
24
+ - a4b5108: Initial release of the forms package. Wraps Payload's Form Builder plugin with the Throughline policy layer: mandatory privacy notice, consent enforcement (server-side), honeypot spam protection, Postgres-backed per-IP rate limiting, a destination allowlist (the security perimeter), and submitter confirmations. Six MCP tools (`list_allowed_destinations`, `validate_form`, `create_form`, `update_form_fields`, `update_form_destinations`, `get_form_submissions`) and four Inngest functions (`form-fan-out`, `form-email-destination`, `form-webhook-destination`, `form-submitter-confirmation`) drive the conversational flow and the async destination delivery. Includes `FormSubmissionEmail` and `SubmitterConfirmationEmail` React Email templates. Allowlist enforcement runs at three layers (MCP tool, collection beforeChange hook, fan-out worker) so prompt injection or admin direct-API writes can't bypass it. IPs are HMAC-hashed; raw IPs are never persisted. Adds `form.updated` to the core audit-action taxonomy used by the two update tools.
25
+
26
+ ### Patch Changes
27
+
28
+ - Updated dependencies [a4b5108]
29
+ - @forumone/throughline-core@0.2.1
30
+ - @forumone/throughline-email@0.2.1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Forum One Communications Corporation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,45 +1,137 @@
1
1
  # @forumone/throughline-forms
2
2
 
3
- ## ⚠️ IMPORTANT NOTICE ⚠️
3
+ Policy-aware forms layer for the Throughline framework. Wraps Payload's official Form Builder plugin with mandatory privacy notices, consent enforcement, honeypot spam protection, IP rate limiting, a destination allowlist, and submitter confirmations. Six MCP tools let Claude create, update, validate, and query forms; submissions fan out to email and webhook destinations through Inngest.
4
+
5
+ After this package, an authorized user can ask Claude "build me a contact form that emails the marketing inbox", and the system produces a compliant form by construction — Claude cannot skip the privacy notice, point destinations at attacker-controlled URLs, or expose submission PII.
6
+
7
+ ## What this package provides
4
8
 
5
- **This package is created solely for the purpose of setting up OIDC (OpenID Connect) trusted publishing with npm.**
9
+ - **`formsPlugin`** composes the Form Builder plugin and adds the policy layer.
10
+ - **`addFormPolicyFields`** — appends the `policy` group (privacy notice, consent, spam protection, destinations, submitter confirmation) to the Forms collection's fields.
11
+ - **Submit endpoint** at `/api/<routePrefix>/submit` (default `/api/forms/submit`) — public POST that runs honeypot → form lookup → consent → rate limit → persist → fan-out.
12
+ - **MCP server** at `/api/<routePrefix>/mcp` with six tools:
6
13
 
7
- This is **NOT** a functional package and contains **NO** code or functionality beyond the OIDC setup configuration.
14
+ | Tool | Use it for | Access |
15
+ |---|---|---|
16
+ | `list_allowed_destinations` | Discover destination labels | any caller |
17
+ | `validate_form` | Dry-run accessibility + allowlist + confirmation checks | admin / editor |
18
+ | `create_form` | Persist a new form with policy defaults | admin / editor |
19
+ | `update_form_fields` | Replace fields; re-validates against current submitterConfirmation | admin / editor |
20
+ | `update_form_destinations` | Replace destinations (replace-all semantics) | admin / editor |
21
+ | `get_form_submissions` | Counts + timestamps; raw data requires admin/form-admin role | admin / editor (PII gated) |
8
22
 
9
- ## Purpose
10
-
11
- This package exists to:
12
- 1. Configure OIDC trusted publishing for the package name `@forumone/throughline-forms`
13
- 2. Enable secure, token-less publishing from CI/CD workflows
14
- 3. Establish provenance for packages published under this name
15
-
16
- ## What is OIDC Trusted Publishing?
17
-
18
- OIDC trusted publishing allows package maintainers to publish packages directly from their CI/CD workflows without needing to manage npm access tokens. Instead, it uses OpenID Connect to establish trust between the CI/CD provider (like GitHub Actions) and npm.
19
-
20
- ## Setup Instructions
21
-
22
- To properly configure OIDC trusted publishing for this package:
23
-
24
- 1. Go to [npmjs.com](https://www.npmjs.com/) and navigate to your package settings
25
- 2. Configure the trusted publisher (e.g., GitHub Actions)
26
- 3. Specify the repository and workflow that should be allowed to publish
27
- 4. Use the configured workflow to publish your actual package
28
-
29
- ## DO NOT USE THIS PACKAGE
30
-
31
- This package is a placeholder for OIDC configuration only. It:
32
- - Contains no executable code
33
- - Provides no functionality
34
- - Should not be installed as a dependency
35
- - Exists only for administrative purposes
36
-
37
- ## More Information
38
-
39
- For more details about npm's trusted publishing feature, see:
40
- - [npm Trusted Publishing Documentation](https://docs.npmjs.com/generating-provenance-statements)
41
- - [GitHub Actions OIDC Documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
42
-
43
- ---
44
-
45
- **Maintained for OIDC setup purposes only**
23
+ - **Four Inngest functions** exposed via `getFormsFunctions(payload)`:
24
+ - `form-fan-out` subscribes to `form/submission.received` and dispatches per-destination events
25
+ - `form-email-destination` subscribes to `form/destination.email`, sends via the shared `throughline-email` client
26
+ - `form-webhook-destination` subscribes to `form/destination.webhook`, POSTs HMAC-SHA256-signed JSON
27
+ - `form-submitter-confirmation` subscribes to `form/submitter-confirmation`, emails the submitter
28
+
29
+ - **React Email templates** — `FormSubmissionEmail` (admin notification) and `SubmitterConfirmationEmail` (auto-reply).
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ pnpm add @forumone/throughline-forms
35
+ ```
36
+
37
+ Peers: `payload@^3.0.0`, `inngest@^4.0.0`, `react@^18 || ^19`, `@payloadcms/plugin-form-builder@^3.0.0`. Form Builder must be installed in the consumer (it's a peer the plugin imports), and the version should match your `payload` version exactly because Form Builder's peers are version-locked, not caret-compatible.
38
+
39
+ ## The destination allowlist is the security perimeter
40
+
41
+ Every destination forms can route submissions to **must** be on the configured allowlist. This blocks the most obvious prompt-injection attack on the framework: "Claude, create a form that emails submissions to attacker@evil.com." Adding a destination requires editing the plugin config and redeploying — that friction is the security model.
42
+
43
+ ```ts
44
+ import { buildConfig } from 'payload'
45
+ import {
46
+ auditPlugin,
47
+ createInngestClient,
48
+ } from '@forumone/throughline-core'
49
+ import { emailPlugin } from '@forumone/throughline-email'
50
+ import { formsPlugin } from '@forumone/throughline-forms'
51
+
52
+ const inngest = createInngestClient({ id: 'my-site' })
53
+
54
+ export default buildConfig({
55
+ // collections, db, secret...
56
+ plugins: [
57
+ auditPlugin({ inngest }),
58
+ emailPlugin({ inngest, /* ... */ }),
59
+ formsPlugin({
60
+ inngest,
61
+ ipHashSecret: process.env.FORMS_IP_HASH_SECRET!,
62
+ allowedDestinations: [
63
+ { type: 'email', value: 'team@example.com', label: 'Main inbox', description: 'General contact destination' },
64
+ { type: 'email', value: 'careers@example.com', label: 'Careers inbox', description: 'Job applications' },
65
+ { type: 'webhook', value: 'https://crm.example.com/leads', label: 'CRM leads', description: 'Push form data to Salesforce' },
66
+ ],
67
+ }),
68
+ ],
69
+ })
70
+ ```
71
+
72
+ The allowlist is enforced in three places:
73
+
74
+ 1. **MCP tool layer** — `create_form` and `update_form_destinations` reject unknown labels.
75
+ 2. **Collection beforeChange hook** — admin / direct-API writes go through the same check, in case MCP is bypassed.
76
+ 3. **Fan-out worker** — a stored row that references a label since removed from config is dropped + logged. Allowlist drift across redeploys cannot turn into accidental delivery.
77
+
78
+ ## Wiring the Inngest endpoint
79
+
80
+ The plugin attaches the four functions to the Payload instance via Symbol; the client app's Inngest endpoint reads them and includes them in `serve()`:
81
+
82
+ ```ts
83
+ // src/app/api/inngest/route.ts
84
+ import { serve } from 'inngest/next'
85
+ import { getPayload } from 'payload'
86
+ import config from '@payload-config'
87
+ import { inngest } from '@/lib/inngest'
88
+ import { getFormsFunctions } from '@forumone/throughline-forms'
89
+ import { getEmailFunctions } from '@forumone/throughline-email'
90
+
91
+ const payload = await getPayload({ config })
92
+ const formsFunctions = getFormsFunctions(payload)
93
+ const emailFunctions = getEmailFunctions(payload)
94
+
95
+ export const { GET, POST, PUT } = serve({
96
+ client: inngest,
97
+ functions: [...formsFunctions, ...emailFunctions /* + your other functions */],
98
+ })
99
+ ```
100
+
101
+ ## Privacy notice and consent
102
+
103
+ Both are on by default. The plugin ships a jurisdiction-neutral default privacy notice that's better than nothing and worse than a lawyer-reviewed string — customize `defaultPrivacyNotice` for GDPR / CCPA / your own jurisdiction before public traffic.
104
+
105
+ Consent is enforced server-side. A request to `/api/forms/submit` with `consent: false` is rejected with HTTP 400 even if the form's policy says the field is required — disabling client-side validation in the browser doesn't help.
106
+
107
+ ## Submission storage and PII
108
+
109
+ - IP addresses are HMAC-hashed with `ipHashSecret` (or `FORMS_IP_HASH_SECRET` env, ≥32 chars). Raw IPs are never persisted.
110
+ - Submission rows store `form`, `submissionData`, `consentGivenAt`, and `ipHash`. Form Builder's defaults provide `id` and timestamps.
111
+ - Read access on `form-submissions` is gated to admin / form-admin roles. The plugin disables MCP exposure of the raw collection — `get_form_submissions` is the only MCP path, and it redacts `submissionData` unless the caller has the `admin` or `form-admin` role.
112
+
113
+ ## Spam protection
114
+
115
+ - **Honeypot** — every rendered form should include a visually hidden field (use `position: absolute; left: -10000px`, **not** `display: none`). The submit endpoint silently 200s when the honeypot has a value, so bots don't pivot on a 4xx.
116
+ - **Rate limit** — Postgres-counted, per (form, IP-hash) per hour. Default 5; per-form override via `policy.spamProtection.rateLimit`. Phase-2 deployments with high-traffic forms can swap in a Redis-backed limiter (the rate-limit module is intentionally a single function call).
117
+
118
+ ## Options reference
119
+
120
+ | Option | Default | Notes |
121
+ |---|---|---|
122
+ | `inngest` | required | Used to fire `form/submission.received` and the destination dispatch events |
123
+ | `allowedDestinations` | required (≥1) | The security perimeter; emails validated for `@`, webhooks for `https://` |
124
+ | `defaultPrivacyNotice` | jurisdiction-neutral default | Customize before public traffic |
125
+ | `requireConsentByDefault` | `true` | Per-form override available |
126
+ | `rateLimit` | `5` per hour per IP-hash | Per-form override via `policy.spamProtection.rateLimit` |
127
+ | `ipHashSecret` | `FORMS_IP_HASH_SECRET` env | Required, ≥32 chars |
128
+ | `formsCollectionSlug` | `'forms'` | |
129
+ | `submissionsCollectionSlug` | `'form-submissions'` | |
130
+ | `routePrefix` | `'/forms'` | Payload prepends `/api`; submit lands at `/api/forms/submit`, MCP at `/api/forms/mcp` |
131
+ | `enabled` | `true` | Set to false to no-op |
132
+
133
+ ## Related packages
134
+
135
+ - `@forumone/throughline-core` — required peer; provides logger, audit infrastructure, and the audit-log capability check
136
+ - `@forumone/throughline-email` — required peer; provides the email client used by destination delivery and submitter confirmation
137
+ - `@forumone/throughline-workflows` — `audit-event-echo` is upstream of email's notification fan-out; nothing in workflows depends on forms directly, but the same Inngest endpoint serves both
@@ -0,0 +1,26 @@
1
+ import type { AllowedDestination, FormsPluginOptions } from './options.js';
2
+ export interface DestinationLookupResult {
3
+ ok: boolean;
4
+ destination?: AllowedDestination;
5
+ reason?: string;
6
+ }
7
+ /**
8
+ * Validates a label against the configured allowlist. Used by the create/
9
+ * update tools, by the collection's beforeChange hook (the secondary
10
+ * defense if MCP is bypassed), and by the fan-out worker (the tertiary
11
+ * defense if a stored row references a label that has since been removed
12
+ * from the allowlist by a redeploy).
13
+ */
14
+ export declare function validateDestinationLabel(options: FormsPluginOptions, label: string): DestinationLookupResult;
15
+ /**
16
+ * Used by the `list_allowed_destinations` MCP tool. Intentionally drops the
17
+ * raw `value` (URL or email address) — Claude doesn't need the destination
18
+ * value to choose a label, and exposing it broadens the prompt-injection
19
+ * surface unnecessarily.
20
+ */
21
+ export declare function listDestinations(options: FormsPluginOptions): Array<{
22
+ label: string;
23
+ type: AllowedDestination['type'];
24
+ description: string;
25
+ }>;
26
+ //# sourceMappingURL=destinations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"destinations.d.ts","sourceRoot":"","sources":["../src/destinations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAE1E,MAAM,WAAW,uBAAuB;IACtC,EAAE,EAAE,OAAO,CAAA;IACX,WAAW,CAAC,EAAE,kBAAkB,CAAA;IAChC,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,kBAAkB,EAC3B,KAAK,EAAE,MAAM,GACZ,uBAAuB,CAczB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,kBAAkB,GAAG,KAAK,CAAC;IACnE,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,kBAAkB,CAAC,MAAM,CAAC,CAAA;IAChC,WAAW,EAAE,MAAM,CAAA;CACpB,CAAC,CAMD"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Validates a label against the configured allowlist. Used by the create/
3
+ * update tools, by the collection's beforeChange hook (the secondary
4
+ * defense if MCP is bypassed), and by the fan-out worker (the tertiary
5
+ * defense if a stored row references a label that has since been removed
6
+ * from the allowlist by a redeploy).
7
+ */
8
+ export function validateDestinationLabel(options, label) {
9
+ if (!label || typeof label !== 'string') {
10
+ return { ok: false, reason: 'Destination label is required.' };
11
+ }
12
+ const destination = options.allowedDestinations.find((d) => d.label === label);
13
+ if (!destination) {
14
+ return {
15
+ ok: false,
16
+ reason: `Destination "${label}" is not on the allowlist. Available: ${options.allowedDestinations
17
+ .map((d) => `"${d.label}"`)
18
+ .join(', ')}.`,
19
+ };
20
+ }
21
+ return { ok: true, destination };
22
+ }
23
+ /**
24
+ * Used by the `list_allowed_destinations` MCP tool. Intentionally drops the
25
+ * raw `value` (URL or email address) — Claude doesn't need the destination
26
+ * value to choose a label, and exposing it broadens the prompt-injection
27
+ * surface unnecessarily.
28
+ */
29
+ export function listDestinations(options) {
30
+ return options.allowedDestinations.map((d) => ({
31
+ label: d.label,
32
+ type: d.type,
33
+ description: d.description,
34
+ }));
35
+ }
36
+ //# sourceMappingURL=destinations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"destinations.js","sourceRoot":"","sources":["../src/destinations.ts"],"names":[],"mappings":"AAQA;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CACtC,OAA2B,EAC3B,KAAa;IAEb,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACxC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,gCAAgC,EAAE,CAAA;IAChE,CAAC;IACD,MAAM,WAAW,GAAG,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,CAAA;IAC9E,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO;YACL,EAAE,EAAE,KAAK;YACT,MAAM,EAAE,gBAAgB,KAAK,yCAAyC,OAAO,CAAC,mBAAmB;iBAC9F,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,KAAK,GAAG,CAAC;iBAC1B,IAAI,CAAC,IAAI,CAAC,GAAG;SACjB,CAAA;IACH,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,CAAA;AAClC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAA2B;IAK1D,OAAO,OAAO,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC7C,KAAK,EAAE,CAAC,CAAC,KAAK;QACd,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,WAAW,EAAE,CAAC,CAAC,WAAW;KAC3B,CAAC,CAAC,CAAA;AACL,CAAC"}
@@ -0,0 +1,13 @@
1
+ export interface FormSubmissionRow {
2
+ field: string;
3
+ value: string;
4
+ }
5
+ /**
6
+ * Reads the `submissionData` JSON field stored by the submit endpoint.
7
+ * Tolerates both the array shape Form Builder uses and a plain
8
+ * `{key: value}` object some integrations might write.
9
+ */
10
+ export declare function readSubmissionRows(value: unknown): FormSubmissionRow[];
11
+ export declare function findFieldValue(rows: FormSubmissionRow[], fieldName: string): string | null;
12
+ export declare function formatHumanDate(iso: string): string;
13
+ //# sourceMappingURL=_shared.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_shared.d.ts","sourceRoot":"","sources":["../../src/functions/_shared.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;CACd;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,iBAAiB,EAAE,CAqBtE;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,iBAAiB,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAG1F;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAUnD"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Reads the `submissionData` JSON field stored by the submit endpoint.
3
+ * Tolerates both the array shape Form Builder uses and a plain
4
+ * `{key: value}` object some integrations might write.
5
+ */
6
+ export function readSubmissionRows(value) {
7
+ if (Array.isArray(value)) {
8
+ const rows = [];
9
+ for (const entry of value) {
10
+ if (entry && typeof entry === 'object' && 'field' in entry && 'value' in entry) {
11
+ const e = entry;
12
+ rows.push({
13
+ field: String(e.field ?? ''),
14
+ value: typeof e.value === 'string' ? e.value : String(e.value ?? ''),
15
+ });
16
+ }
17
+ }
18
+ return rows;
19
+ }
20
+ if (value && typeof value === 'object') {
21
+ return Object.entries(value).map(([field, v]) => ({
22
+ field,
23
+ value: typeof v === 'string' ? v : String(v ?? ''),
24
+ }));
25
+ }
26
+ return [];
27
+ }
28
+ export function findFieldValue(rows, fieldName) {
29
+ const row = rows.find((r) => r.field === fieldName);
30
+ return row ? row.value : null;
31
+ }
32
+ export function formatHumanDate(iso) {
33
+ const date = new Date(iso);
34
+ if (Number.isNaN(date.getTime()))
35
+ return iso;
36
+ return date.toLocaleString('en-US', {
37
+ month: 'short',
38
+ day: 'numeric',
39
+ year: 'numeric',
40
+ hour: 'numeric',
41
+ minute: '2-digit',
42
+ });
43
+ }
44
+ //# sourceMappingURL=_shared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_shared.js","sourceRoot":"","sources":["../../src/functions/_shared.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,GAAwB,EAAE,CAAA;QACpC,KAAK,MAAM,KAA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IAAI,CAAC,GAAG,CAAC,CAAA;IAC1B,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QAAE,OAAO,GAAG,CAAA;IAC5C,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE;QAClC,KAAK,EAAE,OAAO;QACd,GAAG,EAAE,SAAS;QACd,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,SAAS;KAClB,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { Inngest, InngestFunction } from 'inngest';
2
+ import type { Payload } from 'payload';
3
+ import type { EmailClient } from '@forumone/throughline-email';
4
+ import type { ResolvedFormsConfig } from '../options.js';
5
+ export interface EmailDestinationDeps {
6
+ inngest: Inngest;
7
+ payload: Payload;
8
+ resolved: ResolvedFormsConfig;
9
+ /** Returns the shared email client. Lazy so the email plugin can attach later. */
10
+ getEmailClient: () => EmailClient | undefined;
11
+ /** Brand name for the layout. Defaults to `'Forms'`. */
12
+ brandName?: string;
13
+ /** Override the function id. Default: `form-email-destination`. */
14
+ id?: string;
15
+ }
16
+ /**
17
+ * Subscribes to `form/destination.email` (dispatched by the fan-out).
18
+ * Loads the submission and delivers a FormSubmissionEmail to the
19
+ * allowlisted address keyed by the destination label. Re-validates the
20
+ * label against the current allowlist as a defense-in-depth check —
21
+ * the fan-out already validated, but a redeploy could have happened in
22
+ * between.
23
+ */
24
+ export declare function createEmailDestinationFunction(deps: EmailDestinationDeps): InngestFunction.Any;
25
+ //# sourceMappingURL=email-destination.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email-destination.d.ts","sourceRoot":"","sources":["../../src/functions/email-destination.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAE9D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAGxD,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,QAAQ,EAAE,mBAAmB,CAAA;IAC7B,kFAAkF;IAClF,cAAc,EAAE,MAAM,WAAW,GAAG,SAAS,CAAA;IAC7C,wDAAwD;IACxD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,mEAAmE;IACnE,EAAE,CAAC,EAAE,MAAM,CAAA;CACZ;AAED;;;;;;;GAOG;AACH,wBAAgB,8BAA8B,CAC5C,IAAI,EAAE,oBAAoB,GACzB,eAAe,CAAC,GAAG,CA2ErB"}
@@ -0,0 +1,75 @@
1
+ import { FormSubmissionEmail } from '../templates/index.js';
2
+ import { formatHumanDate, readSubmissionRows } from './_shared.js';
3
+ /**
4
+ * Subscribes to `form/destination.email` (dispatched by the fan-out).
5
+ * Loads the submission and delivers a FormSubmissionEmail to the
6
+ * allowlisted address keyed by the destination label. Re-validates the
7
+ * label against the current allowlist as a defense-in-depth check —
8
+ * the fan-out already validated, but a redeploy could have happened in
9
+ * between.
10
+ */
11
+ export function createEmailDestinationFunction(deps) {
12
+ return deps.inngest.createFunction({
13
+ id: deps.id ?? 'form-email-destination',
14
+ retries: 5,
15
+ triggers: [{ event: 'form/destination.email' }],
16
+ }, async ({ event, step, logger }) => {
17
+ const data = (event.data ?? {});
18
+ if (!data.submissionId || !data.destinationLabel)
19
+ return { skipped: true };
20
+ const dest = deps.resolved.options.allowedDestinations.find((d) => d.label === data.destinationLabel && d.type === 'email');
21
+ if (!dest) {
22
+ logger.warn('Email destination no longer on allowlist', { label: data.destinationLabel });
23
+ return { skipped: true, reason: 'destination-removed' };
24
+ }
25
+ const client = deps.getEmailClient();
26
+ if (!client) {
27
+ throw new Error('Email client not available. Register `emailPlugin` before submissions are delivered.');
28
+ }
29
+ const submission = await step.run('load-submission', async () => deps.payload.findByID({
30
+ collection: deps.resolved.submissionsCollectionSlug,
31
+ id: data.submissionId,
32
+ depth: 1,
33
+ }));
34
+ if (!submission)
35
+ return { skipped: true, reason: 'submission-not-found' };
36
+ const formId = unwrapId(submission['form']);
37
+ const form = formId
38
+ ? (await step.run('load-form', async () => deps.payload.findByID({
39
+ collection: deps.resolved.formsCollectionSlug,
40
+ id: formId,
41
+ })))
42
+ : null;
43
+ const formTitle = typeof form?.['title'] === 'string' ? form['title'] : '(untitled form)';
44
+ const fields = readSubmissionRows(submission['submissionData']);
45
+ const receivedAtIso = typeof submission['createdAt'] === 'string' ? submission['createdAt'] : '';
46
+ const receivedAt = receivedAtIso ? formatHumanDate(receivedAtIso) : 'just now';
47
+ await step.run(`send-${dest.label}`, async () => {
48
+ await client.send({
49
+ to: dest.value,
50
+ subject: `New submission for ${formTitle}`,
51
+ template: FormSubmissionEmail({
52
+ formTitle,
53
+ brandName: deps.brandName ?? 'Forms',
54
+ receivedAt,
55
+ fields,
56
+ }),
57
+ tags: [
58
+ { name: 'type', value: 'form-submission' },
59
+ { name: 'form-id', value: String(formId ?? '') },
60
+ { name: 'destination', value: dest.label },
61
+ ],
62
+ });
63
+ });
64
+ return { ok: true, destinationLabel: dest.label };
65
+ });
66
+ }
67
+ function unwrapId(value) {
68
+ if (typeof value === 'string')
69
+ return value;
70
+ if (value && typeof value === 'object' && 'id' in value) {
71
+ return String(value.id);
72
+ }
73
+ return null;
74
+ }
75
+ //# sourceMappingURL=email-destination.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email-destination.js","sourceRoot":"","sources":["../../src/functions/email-destination.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAE3D,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAclE;;;;;;;GAOG;AACH,MAAM,UAAU,8BAA8B,CAC5C,IAA0B;IAE1B,OAAO,IAAI,CAA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;oBACT,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,OAAO;oBACpC,UAAU;oBACV,MAAM;iBACP,CAAC;gBACF,IAAI,EAAE;oBACJ,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,EAAE;oBAC1C,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE;oBAChD,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE;iBAC3C;aACF,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;QAEF,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,CAAC,KAAK,EAAE,CAAA;IACnD,CAAC,CACF,CAAA;AACH,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAC3C,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,IAAI,IAAI,KAAK,EAAE,CAAC;QACxD,OAAO,MAAM,CAAE,KAAyB,CAAC,EAAE,CAAC,CAAA;IAC9C,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC"}
@@ -0,0 +1,24 @@
1
+ import type { Inngest, InngestFunction } from 'inngest';
2
+ import type { Payload } from 'payload';
3
+ import type { ResolvedFormsConfig } from '../options.js';
4
+ export interface FanOutDeps {
5
+ inngest: Inngest;
6
+ payload: Payload;
7
+ resolved: ResolvedFormsConfig;
8
+ /** Override the function id. Default: `form-fan-out`. */
9
+ id?: string;
10
+ }
11
+ /**
12
+ * Subscribes to `form/submission.received` (fired by the public submit
13
+ * endpoint). Loads the form, walks `policy.destinations`, and dispatches
14
+ * an `form/destination.<type>` event for each enabled, allowlisted entry.
15
+ * If the form opts into a submitter confirmation, fires
16
+ * `form/submitter-confirmation` as well.
17
+ *
18
+ * Each dispatch is its own `step.run` so a transient failure delivering
19
+ * to one destination doesn't block the others. We deliberately do not
20
+ * load the submission row here; the per-destination workers load it
21
+ * themselves to keep this function dependency-light.
22
+ */
23
+ export declare function createFormFanOutFunction(deps: FanOutDeps): InngestFunction.Any;
24
+ //# sourceMappingURL=fan-out.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fan-out.d.ts","sourceRoot":"","sources":["../../src/functions/fan-out.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAExD,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,QAAQ,EAAE,mBAAmB,CAAA;IAC7B,yDAAyD;IACzD,EAAE,CAAC,EAAE,MAAM,CAAA;CACZ;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,UAAU,GAAG,eAAe,CAAC,GAAG,CAoE9E"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Subscribes to `form/submission.received` (fired by the public submit
3
+ * endpoint). Loads the form, walks `policy.destinations`, and dispatches
4
+ * an `form/destination.<type>` event for each enabled, allowlisted entry.
5
+ * If the form opts into a submitter confirmation, fires
6
+ * `form/submitter-confirmation` as well.
7
+ *
8
+ * Each dispatch is its own `step.run` so a transient failure delivering
9
+ * to one destination doesn't block the others. We deliberately do not
10
+ * load the submission row here; the per-destination workers load it
11
+ * themselves to keep this function dependency-light.
12
+ */
13
+ export function createFormFanOutFunction(deps) {
14
+ return deps.inngest.createFunction({
15
+ id: deps.id ?? 'form-fan-out',
16
+ retries: 3,
17
+ triggers: [{ event: 'form/submission.received' }],
18
+ }, async ({ event, step, logger }) => {
19
+ const data = (event.data ?? {});
20
+ const formId = data.formId;
21
+ const submissionId = data.submissionId;
22
+ if (!formId || !submissionId) {
23
+ logger.warn('form/submission.received missing formId or submissionId; skipping');
24
+ return { skipped: true };
25
+ }
26
+ const form = (await step.run('load-form', async () => deps.payload.findByID({ collection: deps.resolved.formsCollectionSlug, id: formId })));
27
+ if (!form)
28
+ return { skipped: true, reason: 'form-not-found' };
29
+ const policy = (form['policy'] ?? {});
30
+ const destinations = Array.isArray(policy['destinations'])
31
+ ? policy['destinations']
32
+ : [];
33
+ const submitterConfig = (policy['submitterConfirmation'] ?? {});
34
+ let dispatched = 0;
35
+ let dropped = 0;
36
+ for (const dest of destinations) {
37
+ if (dest.enabled === false || !dest.label)
38
+ continue;
39
+ const allowed = deps.resolved.options.allowedDestinations.find((d) => d.label === dest.label);
40
+ if (!allowed) {
41
+ // Allowlist drift: a stored row references a label that's been
42
+ // removed from the plugin config since the form was authored.
43
+ // Drop and warn rather than fail the whole fan-out.
44
+ logger.warn('Destination dropped — no longer in the allowlist', { label: dest.label });
45
+ dropped += 1;
46
+ continue;
47
+ }
48
+ await step.run(`dispatch-${dest.label}`, async () => {
49
+ await deps.inngest.send({
50
+ name: `form/destination.${allowed.type}`,
51
+ data: {
52
+ submissionId,
53
+ formId,
54
+ destinationLabel: dest.label,
55
+ },
56
+ });
57
+ });
58
+ dispatched += 1;
59
+ }
60
+ if (submitterConfig.enabled === true) {
61
+ await step.run('dispatch-submitter-confirmation', async () => {
62
+ await deps.inngest.send({
63
+ name: 'form/submitter-confirmation',
64
+ data: { submissionId, formId },
65
+ });
66
+ });
67
+ }
68
+ return { dispatched, dropped, submitterConfirmation: submitterConfig.enabled === true };
69
+ });
70
+ }
71
+ //# sourceMappingURL=fan-out.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fan-out.js","sourceRoot":"","sources":["../../src/functions/fan-out.ts"],"names":[],"mappings":"AAYA;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,wBAAwB,CAAC,IAAgB;IACvD,OAAO,IAAI,CAAC,OAAO,C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CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;QACJ,CAAC;QAED,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,qBAAqB,EAAE,eAAe,CAAC,OAAO,KAAK,IAAI,EAAE,CAAA;IACzF,CAAC,CACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,9 @@
1
+ export { createFormFanOutFunction } from './fan-out.js';
2
+ export type { FanOutDeps } from './fan-out.js';
3
+ export { createEmailDestinationFunction } from './email-destination.js';
4
+ export type { EmailDestinationDeps } from './email-destination.js';
5
+ export { createWebhookDestinationFunction } from './webhook-destination.js';
6
+ export type { WebhookDestinationDeps } from './webhook-destination.js';
7
+ export { createSubmitterConfirmationFunction } from './submitter-confirmation.js';
8
+ export type { SubmitterConfirmationDeps } from './submitter-confirmation.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAA;AACvD,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAE9C,OAAO,EAAE,8BAA8B,EAAE,MAAM,wBAAwB,CAAA;AACvE,YAAY,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAElE,OAAO,EAAE,gCAAgC,EAAE,MAAM,0BAA0B,CAAA;AAC3E,YAAY,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AAEtE,OAAO,EAAE,mCAAmC,EAAE,MAAM,6BAA6B,CAAA;AACjF,YAAY,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAA"}
@@ -0,0 +1,5 @@
1
+ export { createFormFanOutFunction } from './fan-out.js';
2
+ export { createEmailDestinationFunction } from './email-destination.js';
3
+ export { createWebhookDestinationFunction } from './webhook-destination.js';
4
+ export { createSubmitterConfirmationFunction } from './submitter-confirmation.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAA;AAGvD,OAAO,EAAE,8BAA8B,EAAE,MAAM,wBAAwB,CAAA;AAGvE,OAAO,EAAE,gCAAgC,EAAE,MAAM,0BAA0B,CAAA;AAG3E,OAAO,EAAE,mCAAmC,EAAE,MAAM,6BAA6B,CAAA"}