@aglyn/plugins-forms 1.0.0-beta.289 → 1.0.0-beta.291
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -1
- package/package.json +14 -14
- package/src/lib/components/form-detail-card.js +122 -2
- package/src/lib/components/form-detail-card.js.map +1 -1
- package/src/lib/components/form-file-upload-body.d.ts +32 -0
- package/src/lib/components/form-file-upload-body.js +349 -0
- package/src/lib/components/form-file-upload-body.js.map +1 -0
- package/src/lib/components/form-file-upload.d.ts +39 -0
- package/src/lib/components/form-file-upload.js +175 -0
- package/src/lib/components/form-file-upload.js.map +1 -0
- package/src/lib/components/form-upload-context.d.ts +31 -0
- package/src/lib/components/form-upload-context.js +19 -0
- package/src/lib/components/form-upload-context.js.map +1 -0
- package/src/lib/components/form.js +48 -4
- package/src/lib/components/form.js.map +1 -1
- package/src/lib/declarations.console-server.js +14 -0
- package/src/lib/declarations.console-server.js.map +1 -1
- package/src/lib/declarations.server.js +18 -0
- package/src/lib/declarations.server.js.map +1 -1
- package/src/lib/model/form-request.d.ts +102 -0
- package/src/lib/model/form-request.js +187 -0
- package/src/lib/model/form-request.js.map +1 -0
- package/src/lib/server/form-confirmation-email.d.ts +71 -0
- package/src/lib/server/form-confirmation-email.js +195 -0
- package/src/lib/server/form-confirmation-email.js.map +1 -0
- package/src/lib/server/form-submit-files.d.ts +42 -0
- package/src/lib/server/form-submit-files.js +98 -0
- package/src/lib/server/form-submit-files.js.map +1 -0
- package/src/lib/server/form-submit.js +116 -7
- package/src/lib/server/form-submit.js.map +1 -1
- package/src/lib/server/form-upload-sweep.d.ts +30 -0
- package/src/lib/server/form-upload-sweep.js +83 -0
- package/src/lib/server/form-upload-sweep.js.map +1 -0
- package/src/lib/server/form-upload.d.ts +41 -0
- package/src/lib/server/form-upload.js +226 -0
- package/src/lib/server/form-upload.js.map +1 -0
- package/src/lib/server/form-uploads.d.ts +34 -0
- package/src/lib/server/form-uploads.js +29 -0
- package/src/lib/server/form-uploads.js.map +1 -0
- package/src/lib/server/submission-access.d.ts +38 -0
- package/src/lib/server/submission-access.js +37 -0
- package/src/lib/server/submission-access.js.map +1 -0
- package/src/lib/server/submission-facts.d.ts +37 -0
- package/src/lib/server/submission-facts.js +227 -0
- package/src/lib/server/submission-facts.js.map +1 -0
- package/src/lib/server/submission-files.d.ts +41 -0
- package/src/lib/server/submission-files.js +126 -0
- package/src/lib/server/submission-files.js.map +1 -0
- package/src/lib/server.js +22 -0
- package/src/lib/server.js.map +1 -1
- package/src/lib/site.js +8 -0
- package/src/lib/site.js.map +1 -1
- package/src/lib/tenant-emails.d.ts +29 -0
- package/src/lib/tenant-emails.js +125 -0
- package/src/lib/tenant-emails.js.map +1 -0
- package/src/lib/testing/stand-in-firestore.d.ts +27 -0
- package/src/lib/testing/stand-in-firestore.js +128 -0
- package/src/lib/testing/stand-in-firestore.js.map +1 -0
- package/src/lib/utils/form-confirmation-content.d.ts +48 -0
- package/src/lib/utils/form-confirmation-content.js +100 -0
- package/src/lib/utils/form-confirmation-content.js.map +1 -0
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
// registry, not the whole server surface.
|
|
18
18
|
import { registerApiV1SiteResource } from "@aglyn/tenant-data-admin/server/api-v1-resources";
|
|
19
19
|
import { registerPluginTransferResource } from "@aglyn/aglyn/plugin-manager/plugin-transfer-resources";
|
|
20
|
+
import { registerPluginConsoleCron } from "@aglyn/aglyn/plugin-manager/plugin-console-crons";
|
|
20
21
|
import { BUNDLE_ID } from "./constants/bundle-common.js";
|
|
21
22
|
import { registerFormsRecordRoutes } from "./model/forms-record-routes.js";
|
|
22
23
|
import { FORM_SUBMISSIONS_MATCH_KEYS, FORM_SUBMISSIONS_TRANSFER_KEY } from "./transfer/form-submissions-transfer-key.js";
|
|
@@ -49,6 +50,19 @@ import { FORM_SUBMISSIONS_MATCH_KEYS, FORM_SUBMISSIONS_TRANSFER_KEY } from "./tr
|
|
|
49
50
|
* with the first export; only its match keys are read at registration.
|
|
50
51
|
* Registering again replaces this plugin's own entries.
|
|
51
52
|
*/ export function registerFormsConsoleServerDeclarations() {
|
|
53
|
+
// Files attached to a form that was never sent (AGL-4098): deleted a day
|
|
54
|
+
// after their latest upload, with the key's record.
|
|
55
|
+
registerPluginConsoleCron({
|
|
56
|
+
id: 'forms-upload-sweep',
|
|
57
|
+
label: 'Unsent form files',
|
|
58
|
+
drives: 'Deletes the files a visitor attached to a form and never sent, a day after the last one went up. If it stops, those files stay in the site’s private storage.',
|
|
59
|
+
run: async (context)=>{
|
|
60
|
+
const { defaultFormUploadSweepDeps, sweepFormUploads } = await import("./server/form-upload-sweep.js");
|
|
61
|
+
return sweepFormUploads(defaultFormUploadSweepDeps(), context);
|
|
62
|
+
}
|
|
63
|
+
}, {
|
|
64
|
+
pluginId: BUNDLE_ID
|
|
65
|
+
});
|
|
52
66
|
// A form's console address on the server too, so a server route that names a
|
|
53
67
|
// form someone else made (an AI job's draft, AGL-3854) links it through the
|
|
54
68
|
// record-route seam rather than spelling this plugin's path.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../libs/plugins/forms/src/lib/declarations.console-server.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// The registry's own module, not the data layer's barrel: boot needs the\n// registry, not the whole server surface.\nimport { registerApiV1SiteResource } from '@aglyn/tenant-data-admin/server/api-v1-resources'\nimport { registerPluginTransferResource } from '@aglyn/aglyn/plugin-manager/plugin-transfer-resources'\nimport { BUNDLE_ID } from './constants/bundle-common'\nimport { registerFormsRecordRoutes } from './model/forms-record-routes'\nimport {\n FORM_SUBMISSIONS_MATCH_KEYS,\n FORM_SUBMISSIONS_TRANSFER_KEY,\n} from './transfer/form-submissions-transfer-key'\nimport type { FormSubmissionsTransferResource } from './transfer/form-submissions-transfer'\n\n/**\n * The submissions resource over the console's Admin SDK, built with the first\n * export that asks — the resource, `firebase-admin` and the Admin app load\n * then, never at boot.\n */\nasync function formSubmissionsTransfer(): Promise<FormSubmissionsTransferResource> {\n return (await import('./transfer/form-submissions-transfer.server')).adminFormSubmissionsTransferResource()\n}\n\n/**\n * The forms plugin's CONSOLE-ONLY server declarations, named under\n * `consoleServerDeclarations` in `plugins.config.json` and run at the\n * console's boot. The tenant runtime registers none of it.\n *\n * It serves a site's form submissions on the customer REST API,\n * `/v1/sites/{siteId}/form-submissions/…`: the console's router owns the\n * pipeline in front — the key, the plan's API access, the quota, the rate\n * limit, the error envelope — and the site's ownership, and hands every\n * request under the resource here. No plan feature is named: submissions are\n * read and marked on every plan, as they always were. The resource brings its\n * description for the API's OpenAPI document.\n *\n * It also answers the export of a site's submissions (`forms.submissions`,\n * export only — see `transfer/form-submissions-transfer.ts`): the console's\n * transfer routes gate the reader on the site and read through these hooks.\n *\n * Light at boot: the handler is imported with its first request and the\n * description when the document is first built, and the transfer resource\n * with the first export; only its match keys are read at registration.\n * Registering again replaces this plugin's own entries.\n */\nexport function registerFormsConsoleServerDeclarations(): void {\n // A form's console address on the server too, so a server route that names a\n // form someone else made (an AI job's draft, AGL-3854) links it through the\n // record-route seam rather than spelling this plugin's path.\n registerFormsRecordRoutes()\n registerApiV1SiteResource(\n 'form-submissions',\n {\n handle: async (...args) =>\n (await import('./server/api-v1/form-submissions')).handleFormSubmissions(...args),\n describe: async () =>\n (await import('./server/api-v1/openapi')).FORM_SUBMISSIONS_API_V1_DESCRIPTION,\n },\n { pluginId: BUNDLE_ID },\n )\n registerPluginTransferResource(\n FORM_SUBMISSIONS_TRANSFER_KEY,\n {\n matchKeys: FORM_SUBMISSIONS_MATCH_KEYS,\n fields: async (ctx) => (await formSubmissionsTransfer()).fields(ctx),\n count: async (ctx, options) => (await formSubmissionsTransfer()).count(ctx, options),\n readPage: async (ctx, cursor, fieldIds, options) =>\n (await formSubmissionsTransfer()).readPage(ctx, cursor, fieldIds, options),\n lookup: async (ctx, requests) => (await formSubmissionsTransfer()).lookup(ctx, requests),\n },\n { pluginId: BUNDLE_ID },\n )\n}\n"],"names":["registerApiV1SiteResource","registerPluginTransferResource","BUNDLE_ID","registerFormsRecordRoutes","FORM_SUBMISSIONS_MATCH_KEYS","FORM_SUBMISSIONS_TRANSFER_KEY","formSubmissionsTransfer","adminFormSubmissionsTransferResource","registerFormsConsoleServerDeclarations","handle","args","handleFormSubmissions","describe","FORM_SUBMISSIONS_API_V1_DESCRIPTION","
|
|
1
|
+
{"version":3,"sources":["../../../../../../libs/plugins/forms/src/lib/declarations.console-server.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// The registry's own module, not the data layer's barrel: boot needs the\n// registry, not the whole server surface.\nimport { registerApiV1SiteResource } from '@aglyn/tenant-data-admin/server/api-v1-resources'\nimport { registerPluginTransferResource } from '@aglyn/aglyn/plugin-manager/plugin-transfer-resources'\nimport { registerPluginConsoleCron } from '@aglyn/aglyn/plugin-manager/plugin-console-crons'\nimport { BUNDLE_ID } from './constants/bundle-common'\nimport { registerFormsRecordRoutes } from './model/forms-record-routes'\nimport {\n FORM_SUBMISSIONS_MATCH_KEYS,\n FORM_SUBMISSIONS_TRANSFER_KEY,\n} from './transfer/form-submissions-transfer-key'\nimport type { FormSubmissionsTransferResource } from './transfer/form-submissions-transfer'\n\n/**\n * The submissions resource over the console's Admin SDK, built with the first\n * export that asks — the resource, `firebase-admin` and the Admin app load\n * then, never at boot.\n */\nasync function formSubmissionsTransfer(): Promise<FormSubmissionsTransferResource> {\n return (await import('./transfer/form-submissions-transfer.server')).adminFormSubmissionsTransferResource()\n}\n\n/**\n * The forms plugin's CONSOLE-ONLY server declarations, named under\n * `consoleServerDeclarations` in `plugins.config.json` and run at the\n * console's boot. The tenant runtime registers none of it.\n *\n * It serves a site's form submissions on the customer REST API,\n * `/v1/sites/{siteId}/form-submissions/…`: the console's router owns the\n * pipeline in front — the key, the plan's API access, the quota, the rate\n * limit, the error envelope — and the site's ownership, and hands every\n * request under the resource here. No plan feature is named: submissions are\n * read and marked on every plan, as they always were. The resource brings its\n * description for the API's OpenAPI document.\n *\n * It also answers the export of a site's submissions (`forms.submissions`,\n * export only — see `transfer/form-submissions-transfer.ts`): the console's\n * transfer routes gate the reader on the site and read through these hooks.\n *\n * Light at boot: the handler is imported with its first request and the\n * description when the document is first built, and the transfer resource\n * with the first export; only its match keys are read at registration.\n * Registering again replaces this plugin's own entries.\n */\nexport function registerFormsConsoleServerDeclarations(): void {\n // Files attached to a form that was never sent (AGL-4098): deleted a day\n // after their latest upload, with the key's record.\n registerPluginConsoleCron(\n {\n id: 'forms-upload-sweep',\n label: 'Unsent form files',\n drives:\n 'Deletes the files a visitor attached to a form and never sent, a day after the last one went up. If it stops, those files stay in the site’s private storage.',\n run: async (context) => {\n const { defaultFormUploadSweepDeps, sweepFormUploads } = await import('./server/form-upload-sweep')\n return sweepFormUploads(defaultFormUploadSweepDeps(), context)\n },\n },\n { pluginId: BUNDLE_ID },\n )\n // A form's console address on the server too, so a server route that names a\n // form someone else made (an AI job's draft, AGL-3854) links it through the\n // record-route seam rather than spelling this plugin's path.\n registerFormsRecordRoutes()\n registerApiV1SiteResource(\n 'form-submissions',\n {\n handle: async (...args) =>\n (await import('./server/api-v1/form-submissions')).handleFormSubmissions(...args),\n describe: async () =>\n (await import('./server/api-v1/openapi')).FORM_SUBMISSIONS_API_V1_DESCRIPTION,\n },\n { pluginId: BUNDLE_ID },\n )\n registerPluginTransferResource(\n FORM_SUBMISSIONS_TRANSFER_KEY,\n {\n matchKeys: FORM_SUBMISSIONS_MATCH_KEYS,\n fields: async (ctx) => (await formSubmissionsTransfer()).fields(ctx),\n count: async (ctx, options) => (await formSubmissionsTransfer()).count(ctx, options),\n readPage: async (ctx, cursor, fieldIds, options) =>\n (await formSubmissionsTransfer()).readPage(ctx, cursor, fieldIds, options),\n lookup: async (ctx, requests) => (await formSubmissionsTransfer()).lookup(ctx, requests),\n },\n { pluginId: BUNDLE_ID },\n )\n}\n"],"names":["registerApiV1SiteResource","registerPluginTransferResource","registerPluginConsoleCron","BUNDLE_ID","registerFormsRecordRoutes","FORM_SUBMISSIONS_MATCH_KEYS","FORM_SUBMISSIONS_TRANSFER_KEY","formSubmissionsTransfer","adminFormSubmissionsTransferResource","registerFormsConsoleServerDeclarations","id","label","drives","run","context","defaultFormUploadSweepDeps","sweepFormUploads","pluginId","handle","args","handleFormSubmissions","describe","FORM_SUBMISSIONS_API_V1_DESCRIPTION","matchKeys","fields","ctx","count","options","readPage","cursor","fieldIds","lookup","requests"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,yEAAyE;AACzE,0CAA0C;AAC1C,SAASA,yBAAyB,QAAQ,mDAAkD;AAC5F,SAASC,8BAA8B,QAAQ,wDAAuD;AACtG,SAASC,yBAAyB,QAAQ,mDAAkD;AAC5F,SAASC,SAAS,QAAQ,+BAA2B;AACrD,SAASC,yBAAyB,QAAQ,iCAA6B;AACvE,SACEC,2BAA2B,EAC3BC,6BAA6B,QACxB,8CAA0C;AAGjD;;;;CAIC,GACD,eAAeC;IACb,OAAO,AAAC,CAAA,MAAM,MAAM,CAAC,iDAA6C,EAAGC,oCAAoC;AAC3G;AAEA;;;;;;;;;;;;;;;;;;;;;CAqBC,GACD,OAAO,SAASC;IACd,yEAAyE;IACzE,oDAAoD;IACpDP,0BACE;QACEQ,IAAI;QACJC,OAAO;QACPC,QACE;QACFC,KAAK,OAAOC;YACV,MAAM,EAAEC,0BAA0B,EAAEC,gBAAgB,EAAE,GAAG,MAAM,MAAM,CAAC;YACtE,OAAOA,iBAAiBD,8BAA8BD;QACxD;IACF,GACA;QAAEG,UAAUd;IAAU;IAExB,6EAA6E;IAC7E,4EAA4E;IAC5E,6DAA6D;IAC7DC;IACAJ,0BACE,oBACA;QACEkB,QAAQ,OAAO,GAAGC,OAChB,AAAC,CAAA,MAAM,MAAM,CAAC,sCAAkC,EAAGC,qBAAqB,IAAID;QAC9EE,UAAU,UACR,AAAC,CAAA,MAAM,MAAM,CAAC,6BAAyB,EAAGC,mCAAmC;IACjF,GACA;QAAEL,UAAUd;IAAU;IAExBF,+BACEK,+BACA;QACEiB,WAAWlB;QACXmB,QAAQ,OAAOC,MAAQ,AAAC,CAAA,MAAMlB,yBAAwB,EAAGiB,MAAM,CAACC;QAChEC,OAAO,OAAOD,KAAKE,UAAY,AAAC,CAAA,MAAMpB,yBAAwB,EAAGmB,KAAK,CAACD,KAAKE;QAC5EC,UAAU,OAAOH,KAAKI,QAAQC,UAAUH,UACtC,AAAC,CAAA,MAAMpB,yBAAwB,EAAGqB,QAAQ,CAACH,KAAKI,QAAQC,UAAUH;QACpEI,QAAQ,OAAON,KAAKO,WAAa,AAAC,CAAA,MAAMzB,yBAAwB,EAAGwB,MAAM,CAACN,KAAKO;IACjF,GACA;QAAEf,UAAUd;IAAU;AAE1B"}
|
|
@@ -78,6 +78,24 @@ import { BUNDLE_ID } from "./constants/bundle-common.js";
|
|
|
78
78
|
pluginId: BUNDLE_ID
|
|
79
79
|
});
|
|
80
80
|
registerPluginEventHandler('host.records.removed', async (payload)=>{
|
|
81
|
+
// A removed submission's files go with it (AGL-4098): the API's delete
|
|
82
|
+
// and a person's erasure both say so here. Its files are kept under
|
|
83
|
+
// its own id; the upload pipeline loads only for one that had files.
|
|
84
|
+
if (payload.collection === 'formSubmissions') {
|
|
85
|
+
const withFiles = payload.records.filter((record)=>Array.isArray(record.data['files']) && record.data['files'].length > 0);
|
|
86
|
+
if (withFiles.length) {
|
|
87
|
+
const [{ formUploadCalls }, { formFileScope }] = await Promise.all([
|
|
88
|
+
import("./server/form-uploads.js"),
|
|
89
|
+
import("./model/form-request.js")
|
|
90
|
+
]);
|
|
91
|
+
const uploads = formUploadCalls();
|
|
92
|
+
for (const record of withFiles){
|
|
93
|
+
const hostId = typeof record.data['hostId'] === 'string' ? record.data['hostId'] : payload.hostIds[0];
|
|
94
|
+
if (!hostId) continue;
|
|
95
|
+
await uploads.removeAll(formFileScope(hostId, record.id)).catch((error)=>console.error(`[forms] files of ${hostId}/${record.id} were not deleted`, error));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
81
99
|
const targets = formsCountingRemovedRecords(payload);
|
|
82
100
|
if (!targets.length) return;
|
|
83
101
|
const { recountFormStats } = await import("./server/form-stats.js");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../libs/plugins/forms/src/lib/declarations.server.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// The seam from its own module, not the plugin-manager barrel: boot needs the\n// registry and nothing else, and the barrel reaches the client contexts.\nimport { formIdsOfLeadSources } from '@aglyn/aglyn/app-utils/forms'\nimport {\n registerPluginEventHandler,\n type PluginEventPayloads,\n} from '@aglyn/aglyn/plugin-manager/plugin-events'\nimport {\n registerPluginRecordIndex,\n type PluginRecordIndex,\n} from '@aglyn/aglyn/plugin-manager/plugin-record-index'\nimport { registerPluginIntakeGate } from '@aglyn/aglyn/plugin-manager/plugin-intake-gates'\nimport { BUNDLE_ID } from './constants/bundle-common'\n\n/**\n * The forms each removed record was counted by, per site (AGL-3330): a\n * submission names its form by `formId` on its own site, and a lead names\n * the forms that filed it by `form:{formId}` in `sources`, on any of the\n * organization's sites.\n */\nexport function formsCountingRemovedRecords(\n payload: PluginEventPayloads['host.records.removed'],\n): Array<{ hostId: string; formIds: string[] }> {\n const byHost = new Map<string, Set<string>>()\n const add = (hostId: string, formId: string) => {\n if (!hostId || !formId) return\n const ids = byHost.get(hostId) ?? new Set<string>()\n ids.add(formId)\n byHost.set(hostId, ids)\n }\n for (const { data } of payload.records) {\n if (payload.collection === 'formSubmissions') {\n const formId = typeof data['formId'] === 'string' ? data['formId'] : ''\n const hostId = typeof data['hostId'] === 'string' ? data['hostId'] : payload.hostIds[0]\n add(hostId ?? '', formId)\n } else if (payload.collection === 'leads') {\n for (const formId of formIdsOfLeadSources(data['sources'])) {\n for (const hostId of payload.hostIds) add(hostId, formId)\n }\n }\n }\n return [...byHost].map(([hostId, formIds]) => ({ hostId, formIds: [...formIds] }))\n}\n\n/**\n * The forms plugin's server declarations: the light registrations core reads\n * at boot, before any surface loads.\n *\n * A form's counters are this plugin's to keep (AGL-3330), and a row they\n * counted can be removed by a path that is not the plugin's — the public\n * API's delete, a person's erasure. Core says so through\n * `host.records.removed`, and this recounts each form the removed rows fed.\n * The recount module (and the Admin SDK with it) loads on the first such\n * event, not at boot. A site that does not hold a named form answers nothing\n * for one document read, so a lead's forms are looked for on each site the\n * event names.\n */\nexport function registerFormsServerDeclarations(): void {\n // The form door's own gates, for a monitor that must not write to ask them\n // (the funnel probe, AGL-2586): loaded with the first question.\n registerPluginIntakeGate(\n 'form',\n async (request) => (await import('./server/form-intake-gate')).formIntakeGate(request),\n { pluginId: BUNDLE_ID },\n )\n // Submissions are this plugin's records (AGL-3080): the Inbox reads, marks\n // and threads them through this index rather than through the collection.\n registerPluginRecordIndex('formSubmission', lazyFormSubmissionIndex, { pluginId: BUNDLE_ID })\n registerPluginEventHandler(\n 'host.records.removed',\n async (payload) => {\n const targets = formsCountingRemovedRecords(payload)\n if (!targets.length) return\n const { recountFormStats } = await import('./server/form-stats')\n for (const { hostId, formIds } of targets) {\n for (const formId of formIds) {\n try {\n await recountFormStats({ hostId, formId })\n } catch (error) {\n console.error(`[forms] recount after a removal failed for ${hostId}/${formId}`, error)\n }\n }\n }\n },\n { pluginId: BUNDLE_ID },\n )\n}\n\nconst loadFormSubmissionIndex = async () =>\n (await import('./server/form-submission-index')).formSubmissionRecordIndex\n\n/** The index, its module (and the Admin SDK with it) loaded on its first read. */\nconst lazyFormSubmissionIndex: PluginRecordIndex = {\n list: async (request) => (await loadFormSubmissionIndex()).list(request),\n get: async (request) => (await loadFormSubmissionIndex()).get(request),\n ref: async (request) => (await loadFormSubmissionIndex()).ref?.(request) ?? null,\n}\n"],"names":["formIdsOfLeadSources","registerPluginEventHandler","registerPluginRecordIndex","registerPluginIntakeGate","BUNDLE_ID","formsCountingRemovedRecords","payload","byHost","Map","add","hostId","formId","ids","get","Set","set","data","records","collection","hostIds","map","formIds","registerFormsServerDeclarations","request","formIntakeGate","pluginId","lazyFormSubmissionIndex","
|
|
1
|
+
{"version":3,"sources":["../../../../../../libs/plugins/forms/src/lib/declarations.server.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// The seam from its own module, not the plugin-manager barrel: boot needs the\n// registry and nothing else, and the barrel reaches the client contexts.\nimport { formIdsOfLeadSources } from '@aglyn/aglyn/app-utils/forms'\nimport {\n registerPluginEventHandler,\n type PluginEventPayloads,\n} from '@aglyn/aglyn/plugin-manager/plugin-events'\nimport {\n registerPluginRecordIndex,\n type PluginRecordIndex,\n} from '@aglyn/aglyn/plugin-manager/plugin-record-index'\nimport { registerPluginIntakeGate } from '@aglyn/aglyn/plugin-manager/plugin-intake-gates'\nimport { BUNDLE_ID } from './constants/bundle-common'\n\n/**\n * The forms each removed record was counted by, per site (AGL-3330): a\n * submission names its form by `formId` on its own site, and a lead names\n * the forms that filed it by `form:{formId}` in `sources`, on any of the\n * organization's sites.\n */\nexport function formsCountingRemovedRecords(\n payload: PluginEventPayloads['host.records.removed'],\n): Array<{ hostId: string; formIds: string[] }> {\n const byHost = new Map<string, Set<string>>()\n const add = (hostId: string, formId: string) => {\n if (!hostId || !formId) return\n const ids = byHost.get(hostId) ?? new Set<string>()\n ids.add(formId)\n byHost.set(hostId, ids)\n }\n for (const { data } of payload.records) {\n if (payload.collection === 'formSubmissions') {\n const formId = typeof data['formId'] === 'string' ? data['formId'] : ''\n const hostId = typeof data['hostId'] === 'string' ? data['hostId'] : payload.hostIds[0]\n add(hostId ?? '', formId)\n } else if (payload.collection === 'leads') {\n for (const formId of formIdsOfLeadSources(data['sources'])) {\n for (const hostId of payload.hostIds) add(hostId, formId)\n }\n }\n }\n return [...byHost].map(([hostId, formIds]) => ({ hostId, formIds: [...formIds] }))\n}\n\n/**\n * The forms plugin's server declarations: the light registrations core reads\n * at boot, before any surface loads.\n *\n * A form's counters are this plugin's to keep (AGL-3330), and a row they\n * counted can be removed by a path that is not the plugin's — the public\n * API's delete, a person's erasure. Core says so through\n * `host.records.removed`, and this recounts each form the removed rows fed.\n * The recount module (and the Admin SDK with it) loads on the first such\n * event, not at boot. A site that does not hold a named form answers nothing\n * for one document read, so a lead's forms are looked for on each site the\n * event names.\n */\nexport function registerFormsServerDeclarations(): void {\n // The form door's own gates, for a monitor that must not write to ask them\n // (the funnel probe, AGL-2586): loaded with the first question.\n registerPluginIntakeGate(\n 'form',\n async (request) => (await import('./server/form-intake-gate')).formIntakeGate(request),\n { pluginId: BUNDLE_ID },\n )\n // Submissions are this plugin's records (AGL-3080): the Inbox reads, marks\n // and threads them through this index rather than through the collection.\n registerPluginRecordIndex('formSubmission', lazyFormSubmissionIndex, { pluginId: BUNDLE_ID })\n registerPluginEventHandler(\n 'host.records.removed',\n async (payload) => {\n // A removed submission's files go with it (AGL-4098): the API's delete\n // and a person's erasure both say so here. Its files are kept under\n // its own id; the upload pipeline loads only for one that had files.\n if (payload.collection === 'formSubmissions') {\n const withFiles = payload.records.filter(\n (record) => Array.isArray(record.data['files']) && (record.data['files'] as unknown[]).length > 0,\n )\n if (withFiles.length) {\n const [{ formUploadCalls }, { formFileScope }] = await Promise.all([\n import('./server/form-uploads'),\n import('./model/form-request'),\n ])\n const uploads = formUploadCalls()\n for (const record of withFiles) {\n const hostId = typeof record.data['hostId'] === 'string' ? record.data['hostId'] : payload.hostIds[0]\n if (!hostId) continue\n await uploads\n .removeAll(formFileScope(hostId, record.id))\n .catch((error) => console.error(`[forms] files of ${hostId}/${record.id} were not deleted`, error))\n }\n }\n }\n const targets = formsCountingRemovedRecords(payload)\n if (!targets.length) return\n const { recountFormStats } = await import('./server/form-stats')\n for (const { hostId, formIds } of targets) {\n for (const formId of formIds) {\n try {\n await recountFormStats({ hostId, formId })\n } catch (error) {\n console.error(`[forms] recount after a removal failed for ${hostId}/${formId}`, error)\n }\n }\n }\n },\n { pluginId: BUNDLE_ID },\n )\n}\n\nconst loadFormSubmissionIndex = async () =>\n (await import('./server/form-submission-index')).formSubmissionRecordIndex\n\n/** The index, its module (and the Admin SDK with it) loaded on its first read. */\nconst lazyFormSubmissionIndex: PluginRecordIndex = {\n list: async (request) => (await loadFormSubmissionIndex()).list(request),\n get: async (request) => (await loadFormSubmissionIndex()).get(request),\n ref: async (request) => (await loadFormSubmissionIndex()).ref?.(request) ?? null,\n}\n"],"names":["formIdsOfLeadSources","registerPluginEventHandler","registerPluginRecordIndex","registerPluginIntakeGate","BUNDLE_ID","formsCountingRemovedRecords","payload","byHost","Map","add","hostId","formId","ids","get","Set","set","data","records","collection","hostIds","map","formIds","registerFormsServerDeclarations","request","formIntakeGate","pluginId","lazyFormSubmissionIndex","withFiles","filter","record","Array","isArray","length","formUploadCalls","formFileScope","Promise","all","uploads","removeAll","id","catch","error","console","targets","recountFormStats","loadFormSubmissionIndex","formSubmissionRecordIndex","list","ref"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,8EAA8E;AAC9E,yEAAyE;AACzE,SAASA,oBAAoB,QAAQ,+BAA8B;AACnE,SACEC,0BAA0B,QAErB,4CAA2C;AAClD,SACEC,yBAAyB,QAEpB,kDAAiD;AACxD,SAASC,wBAAwB,QAAQ,kDAAiD;AAC1F,SAASC,SAAS,QAAQ,+BAA2B;AAErD;;;;;CAKC,GACD,OAAO,SAASC,4BACdC,OAAoD;IAEpD,MAAMC,SAAS,IAAIC;IACnB,MAAMC,MAAM,CAACC,QAAgBC;YAEfJ;QADZ,IAAI,CAACG,UAAU,CAACC,QAAQ;QACxB,MAAMC,OAAML,cAAAA,OAAOM,GAAG,CAACH,mBAAXH,cAAsB,IAAIO;QACtCF,IAAIH,GAAG,CAACE;QACRJ,OAAOQ,GAAG,CAACL,QAAQE;IACrB;IACA,KAAK,MAAM,EAAEI,IAAI,EAAE,IAAIV,QAAQW,OAAO,CAAE;QACtC,IAAIX,QAAQY,UAAU,KAAK,mBAAmB;YAC5C,MAAMP,SAAS,OAAOK,IAAI,CAAC,SAAS,KAAK,WAAWA,IAAI,CAAC,SAAS,GAAG;YACrE,MAAMN,SAAS,OAAOM,IAAI,CAAC,SAAS,KAAK,WAAWA,IAAI,CAAC,SAAS,GAAGV,QAAQa,OAAO,CAAC,EAAE;YACvFV,IAAIC,iBAAAA,SAAU,IAAIC;QACpB,OAAO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the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { type FormFieldDecl, type FormRequest } from '@aglyn/aglyn/app-utils/forms';
|
|
18
|
+
import { type VisitorUploadFile, type VisitorUploadScope } from '@aglyn/aglyn/app-utils/visitor-upload';
|
|
19
|
+
import { type EmailThread } from '@aglyn/shared-util-email/email-thread';
|
|
20
|
+
/** The resource another plugin reads a submission's facts under, on the core's record-facts seam. */
|
|
21
|
+
export declare const FORM_SUBMISSION_FACTS_RESOURCE = "forms.submission";
|
|
22
|
+
/** The visitor-upload purpose a form's files are kept under. */
|
|
23
|
+
export declare const FORM_FILE_PURPOSE = "form-file";
|
|
24
|
+
/** A pending submission key: letters and digits, long enough that nobody guesses one. */
|
|
25
|
+
export declare const FORM_UPLOAD_KEY_PATTERN: RegExp;
|
|
26
|
+
/**
|
|
27
|
+
* The hidden input a File upload field posts each kept file under, as
|
|
28
|
+
* `{fieldName}:{fileId}`. `__`-prefixed, so it is never an answer: the Form
|
|
29
|
+
* lifts these into the request's `files`.
|
|
30
|
+
*/
|
|
31
|
+
export declare const FORM_FILE_INPUT = "__formFile";
|
|
32
|
+
/** The request body's key for the files a submission names. */
|
|
33
|
+
export declare const FORM_FILES_BODY_KEY = "files";
|
|
34
|
+
/** The `code` a submit refusal about its files carries, so the form shows its sentence. */
|
|
35
|
+
export declare const FORM_FILES_REFUSAL_CODE = "files";
|
|
36
|
+
/** How long an upload key that was never sent keeps its files: a day after its latest file. */
|
|
37
|
+
export declare const FORM_UPLOAD_KEY_TTL_MS: number;
|
|
38
|
+
/** Where the upload route keeps what it knows of a pending key, under the form it is for. */
|
|
39
|
+
export declare const FORM_UPLOAD_KEYS_COLLECTION = "formUploadKeys";
|
|
40
|
+
/** A fresh pending submission key, from the browser's random source. */
|
|
41
|
+
export declare function mintFormUploadKey(random?: (bytes: Uint8Array) => Uint8Array): string;
|
|
42
|
+
/** Whether a value can be a pending submission key. */
|
|
43
|
+
export declare function isFormUploadKey(value: unknown): value is string;
|
|
44
|
+
/** The upload scope of one pending key, which is also the submission it becomes. */
|
|
45
|
+
export declare function formFileScope(hostId: string, key: string): VisitorUploadScope;
|
|
46
|
+
/** One file a submission names: which field it answers, and its id under the key. */
|
|
47
|
+
export interface FormFileRef {
|
|
48
|
+
field: string;
|
|
49
|
+
id: string;
|
|
50
|
+
}
|
|
51
|
+
/** The files a form sends: its key, and each file by field and id. */
|
|
52
|
+
export interface FormFileRefs {
|
|
53
|
+
key: string;
|
|
54
|
+
refs: FormFileRef[];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The files a request body names, checked for shape only: a key, and at most
|
|
58
|
+
* {@link VISITOR_UPLOAD_MAX_FILES} distinct `{ field, id }` pairs. `null` when
|
|
59
|
+
* the body names none; an `error` for anything malformed.
|
|
60
|
+
*/
|
|
61
|
+
export declare function parseFormFileRefs(raw: unknown): FormFileRefs | null | {
|
|
62
|
+
error: string;
|
|
63
|
+
};
|
|
64
|
+
/** The `{field}:{id}` value a File upload field posts per kept file. */
|
|
65
|
+
export declare function formFileInputValue(field: string, id: string): string;
|
|
66
|
+
/** The refs a form's hidden file inputs posted, in order. */
|
|
67
|
+
export declare function formFileRefsFromInputs(values: readonly string[]): FormFileRef[];
|
|
68
|
+
/** A file on a stored submission: which field it answers, and its record without the storage path. */
|
|
69
|
+
export interface FormSubmissionFile {
|
|
70
|
+
id: string;
|
|
71
|
+
field: string;
|
|
72
|
+
name: string;
|
|
73
|
+
contentType: string;
|
|
74
|
+
size: number;
|
|
75
|
+
uploadedAtMs: number;
|
|
76
|
+
}
|
|
77
|
+
/** A kept upload as the submission records it. */
|
|
78
|
+
export declare function formSubmissionFileOf(field: string, file: VisitorUploadFile): FormSubmissionFile;
|
|
79
|
+
/** The files a stored submission names, read defensively. */
|
|
80
|
+
export declare function readFormSubmissionFiles(raw: unknown): FormSubmissionFile[];
|
|
81
|
+
/** What a file field answers with, as the Inbox and the emails read it: the names, in order. */
|
|
82
|
+
export declare function formFileFieldAnswer(files: ReadonlyArray<{
|
|
83
|
+
name: string;
|
|
84
|
+
}>): string;
|
|
85
|
+
/** The declared `file` fields of a form, by name. */
|
|
86
|
+
export declare function formFileFields(decls: readonly FormFieldDecl[]): Map<string, FormFieldDecl>;
|
|
87
|
+
/**
|
|
88
|
+
* Splits a form's posted fields into the answers a person reads and the
|
|
89
|
+
* machine values beside them (`product__data`, see `FORM_FIELD_DATA_SUFFIX`):
|
|
90
|
+
* the answers keep their order; each machine value is kept under the field it
|
|
91
|
+
* belongs to, so `fieldData.product` is what `product__data` posted.
|
|
92
|
+
*/
|
|
93
|
+
export declare function splitFormFieldData(fields: Readonly<Record<string, string>>): {
|
|
94
|
+
answers: Record<string, string>;
|
|
95
|
+
fieldData: Record<string, string>;
|
|
96
|
+
};
|
|
97
|
+
/** The key a machine value is posted under, for the field it belongs to. */
|
|
98
|
+
export declare function formFieldDataKey(field: string): string;
|
|
99
|
+
/** What a stored submission asks for, or null for an ordinary message. */
|
|
100
|
+
export declare function readSubmissionRequest(raw: unknown): FormRequest | null;
|
|
101
|
+
/** The conversation a submission's confirmation started, or null. */
|
|
102
|
+
export declare function readSubmissionThread(raw: unknown): EmailThread | null;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/ import { FORM_FIELD_DATA_SUFFIX, formFieldDataOwner, readFormRequest } from "@aglyn/aglyn/app-utils/forms";
|
|
17
|
+
import { isVisitorUploadSegment, VISITOR_UPLOAD_MAX_FILES } from "@aglyn/aglyn/app-utils/visitor-upload";
|
|
18
|
+
import { readEmailThread } from "@aglyn/shared-util-email/email-thread";
|
|
19
|
+
/*==========================================
|
|
20
|
+
* A REQUEST SENT THROUGH A FORM (AGL-4098): its files, what it asks for, and
|
|
21
|
+
* the conversation its confirmation starts.
|
|
22
|
+
*
|
|
23
|
+
* Pure, shared by the browser and the server.
|
|
24
|
+
*
|
|
25
|
+
* FILES. A form with a File upload field sends its files BEFORE the form: the
|
|
26
|
+
* Form mints a pending submission key when it opens ({@link mintFormUploadKey}),
|
|
27
|
+
* each file goes up through the shared visitor upload under the purpose
|
|
28
|
+
* `form-file` and that key (`POST /api/forms/upload`), and the form then sends
|
|
29
|
+
* the kept files by id ({@link FormFileRefs}). The submit route reads each id
|
|
30
|
+
* back from that scope and refuses one it cannot find, so a submission only
|
|
31
|
+
* ever names files that arrived, under its own key. The key becomes the
|
|
32
|
+
* submission's id, so a submission's files are always at
|
|
33
|
+
* `hosts/{hostId}/private/uploads/form-file/{submissionId}/`.
|
|
34
|
+
*
|
|
35
|
+
* A REQUEST is what a form marked "This form asks for a quote" sends: the
|
|
36
|
+
* submission carries `request: { kind: 'quote' }`, read off the verified form,
|
|
37
|
+
* never the request body.
|
|
38
|
+
*
|
|
39
|
+
* THE CONVERSATION. A form that emails the person a confirmation starts an
|
|
40
|
+
* email thread with it and keeps it on the submission (`emailThread`), so the
|
|
41
|
+
* business's answer — a quote started from the request — replies into the
|
|
42
|
+
* same conversation.
|
|
43
|
+
*=========================================*/ /** The resource another plugin reads a submission's facts under, on the core's record-facts seam. */ export const FORM_SUBMISSION_FACTS_RESOURCE = 'forms.submission';
|
|
44
|
+
/** The visitor-upload purpose a form's files are kept under. */ export const FORM_FILE_PURPOSE = 'form-file';
|
|
45
|
+
/** A pending submission key: letters and digits, long enough that nobody guesses one. */ export const FORM_UPLOAD_KEY_PATTERN = /^[A-Za-z0-9]{24,64}$/;
|
|
46
|
+
/**
|
|
47
|
+
* The hidden input a File upload field posts each kept file under, as
|
|
48
|
+
* `{fieldName}:{fileId}`. `__`-prefixed, so it is never an answer: the Form
|
|
49
|
+
* lifts these into the request's `files`.
|
|
50
|
+
*/ export const FORM_FILE_INPUT = '__formFile';
|
|
51
|
+
/** The request body's key for the files a submission names. */ export const FORM_FILES_BODY_KEY = 'files';
|
|
52
|
+
/** The `code` a submit refusal about its files carries, so the form shows its sentence. */ export const FORM_FILES_REFUSAL_CODE = 'files';
|
|
53
|
+
/** How long an upload key that was never sent keeps its files: a day after its latest file. */ export const FORM_UPLOAD_KEY_TTL_MS = 24 * 60 * 60 * 1000;
|
|
54
|
+
/** Where the upload route keeps what it knows of a pending key, under the form it is for. */ export const FORM_UPLOAD_KEYS_COLLECTION = 'formUploadKeys';
|
|
55
|
+
/** A fresh pending submission key, from the browser's random source. */ export function mintFormUploadKey(random = (bytes)=>globalThis.crypto.getRandomValues(bytes)) {
|
|
56
|
+
return Array.from(random(new Uint8Array(16)), (byte)=>byte.toString(16).padStart(2, '0')).join('');
|
|
57
|
+
}
|
|
58
|
+
/** Whether a value can be a pending submission key. */ export function isFormUploadKey(value) {
|
|
59
|
+
return typeof value === 'string' && FORM_UPLOAD_KEY_PATTERN.test(value);
|
|
60
|
+
}
|
|
61
|
+
/** The upload scope of one pending key, which is also the submission it becomes. */ export function formFileScope(hostId, key) {
|
|
62
|
+
return {
|
|
63
|
+
hostId,
|
|
64
|
+
purpose: FORM_FILE_PURPOSE,
|
|
65
|
+
purposeId: key
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The files a request body names, checked for shape only: a key, and at most
|
|
70
|
+
* {@link VISITOR_UPLOAD_MAX_FILES} distinct `{ field, id }` pairs. `null` when
|
|
71
|
+
* the body names none; an `error` for anything malformed.
|
|
72
|
+
*/ export function parseFormFileRefs(raw) {
|
|
73
|
+
if (raw === undefined || raw === null) return null;
|
|
74
|
+
const source = typeof raw === 'object' ? raw : {};
|
|
75
|
+
const list = Array.isArray(source['refs']) ? source['refs'] : null;
|
|
76
|
+
if (!isFormUploadKey(source['key']) || !list) return {
|
|
77
|
+
error: 'The files sent with this form could not be read.'
|
|
78
|
+
};
|
|
79
|
+
if (list.length === 0) return null;
|
|
80
|
+
if (list.length > VISITOR_UPLOAD_MAX_FILES) {
|
|
81
|
+
return {
|
|
82
|
+
error: `A form can send up to ${VISITOR_UPLOAD_MAX_FILES} files.`
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
const seen = new Set();
|
|
86
|
+
const refs = [];
|
|
87
|
+
for (const entry of list){
|
|
88
|
+
const ref = entry && typeof entry === 'object' ? entry : {};
|
|
89
|
+
const field = typeof ref['field'] === 'string' ? ref['field'].trim().slice(0, 64) : '';
|
|
90
|
+
const id = ref['id'];
|
|
91
|
+
if (!field || !isVisitorUploadSegment(id)) return {
|
|
92
|
+
error: 'The files sent with this form could not be read.'
|
|
93
|
+
};
|
|
94
|
+
if (seen.has(id)) continue;
|
|
95
|
+
seen.add(id);
|
|
96
|
+
refs.push({
|
|
97
|
+
field,
|
|
98
|
+
id
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
key: source['key'],
|
|
103
|
+
refs
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/** The `{field}:{id}` value a File upload field posts per kept file. */ export function formFileInputValue(field, id) {
|
|
107
|
+
return `${field}:${id}`;
|
|
108
|
+
}
|
|
109
|
+
/** The refs a form's hidden file inputs posted, in order. */ export function formFileRefsFromInputs(values) {
|
|
110
|
+
const refs = [];
|
|
111
|
+
for (const value of values){
|
|
112
|
+
const at = value.lastIndexOf(':');
|
|
113
|
+
if (at <= 0) continue;
|
|
114
|
+
refs.push({
|
|
115
|
+
field: value.slice(0, at),
|
|
116
|
+
id: value.slice(at + 1)
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
return refs;
|
|
120
|
+
}
|
|
121
|
+
/** A kept upload as the submission records it. */ export function formSubmissionFileOf(field, file) {
|
|
122
|
+
return {
|
|
123
|
+
id: file.id,
|
|
124
|
+
field,
|
|
125
|
+
name: file.name,
|
|
126
|
+
contentType: file.contentType,
|
|
127
|
+
size: file.size,
|
|
128
|
+
uploadedAtMs: file.uploadedAtMs
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/** The files a stored submission names, read defensively. */ export function readFormSubmissionFiles(raw) {
|
|
132
|
+
if (!Array.isArray(raw)) return [];
|
|
133
|
+
const files = [];
|
|
134
|
+
for (const entry of raw.slice(0, VISITOR_UPLOAD_MAX_FILES)){
|
|
135
|
+
const file = entry && typeof entry === 'object' ? entry : {};
|
|
136
|
+
if (!isVisitorUploadSegment(file['id']) || typeof file['name'] !== 'string') continue;
|
|
137
|
+
files.push({
|
|
138
|
+
id: file['id'],
|
|
139
|
+
field: typeof file['field'] === 'string' ? file['field'] : '',
|
|
140
|
+
name: file['name'],
|
|
141
|
+
contentType: typeof file['contentType'] === 'string' ? file['contentType'] : '',
|
|
142
|
+
size: Number(file['size']) || 0,
|
|
143
|
+
uploadedAtMs: Number(file['uploadedAtMs']) || 0
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
return files;
|
|
147
|
+
}
|
|
148
|
+
/** What a file field answers with, as the Inbox and the emails read it: the names, in order. */ export function formFileFieldAnswer(files) {
|
|
149
|
+
return files.map((file)=>file.name).join(', ').slice(0, 2000);
|
|
150
|
+
}
|
|
151
|
+
/** The declared `file` fields of a form, by name. */ export function formFileFields(decls) {
|
|
152
|
+
return new Map(decls.filter((decl)=>(decl == null ? void 0 : decl.fieldType) === 'file').map((decl)=>[
|
|
153
|
+
decl.fieldName,
|
|
154
|
+
decl
|
|
155
|
+
]));
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Splits a form's posted fields into the answers a person reads and the
|
|
159
|
+
* machine values beside them (`product__data`, see `FORM_FIELD_DATA_SUFFIX`):
|
|
160
|
+
* the answers keep their order; each machine value is kept under the field it
|
|
161
|
+
* belongs to, so `fieldData.product` is what `product__data` posted.
|
|
162
|
+
*/ export function splitFormFieldData(fields) {
|
|
163
|
+
const answers = {};
|
|
164
|
+
const fieldData = {};
|
|
165
|
+
for (const [key, value] of Object.entries(fields)){
|
|
166
|
+
const owner = formFieldDataOwner(key);
|
|
167
|
+
if (owner) fieldData[owner] = value;
|
|
168
|
+
else answers[key] = value;
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
answers,
|
|
172
|
+
fieldData
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/** The key a machine value is posted under, for the field it belongs to. */ export function formFieldDataKey(field) {
|
|
176
|
+
return `${field}${FORM_FIELD_DATA_SUFFIX}`;
|
|
177
|
+
}
|
|
178
|
+
/** What a stored submission asks for, or null for an ordinary message. */ export function readSubmissionRequest(raw) {
|
|
179
|
+
return readFormRequest({
|
|
180
|
+
request: raw
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
/** The conversation a submission's confirmation started, or null. */ export function readSubmissionThread(raw) {
|
|
184
|
+
return readEmailThread(raw);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
//# sourceMappingURL=form-request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/forms/src/lib/model/form-request.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n FORM_FIELD_DATA_SUFFIX,\n formFieldDataOwner,\n readFormRequest,\n type FormFieldDecl,\n type FormRequest,\n} from '@aglyn/aglyn/app-utils/forms'\nimport {\n isVisitorUploadSegment,\n VISITOR_UPLOAD_MAX_FILES,\n type VisitorUploadFile,\n type VisitorUploadScope,\n} from '@aglyn/aglyn/app-utils/visitor-upload'\nimport { readEmailThread, type EmailThread } from '@aglyn/shared-util-email/email-thread'\n\n/*==========================================\n * A REQUEST SENT THROUGH A FORM (AGL-4098): its files, what it asks for, and\n * the conversation its confirmation starts.\n *\n * Pure, shared by the browser and the server.\n *\n * FILES. A form with a File upload field sends its files BEFORE the form: the\n * Form mints a pending submission key when it opens ({@link mintFormUploadKey}),\n * each file goes up through the shared visitor upload under the purpose\n * `form-file` and that key (`POST /api/forms/upload`), and the form then sends\n * the kept files by id ({@link FormFileRefs}). The submit route reads each id\n * back from that scope and refuses one it cannot find, so a submission only\n * ever names files that arrived, under its own key. The key becomes the\n * submission's id, so a submission's files are always at\n * `hosts/{hostId}/private/uploads/form-file/{submissionId}/`.\n *\n * A REQUEST is what a form marked \"This form asks for a quote\" sends: the\n * submission carries `request: { kind: 'quote' }`, read off the verified form,\n * never the request body.\n *\n * THE CONVERSATION. A form that emails the person a confirmation starts an\n * email thread with it and keeps it on the submission (`emailThread`), so the\n * business's answer — a quote started from the request — replies into the\n * same conversation.\n *=========================================*/\n\n/** The resource another plugin reads a submission's facts under, on the core's record-facts seam. */\nexport const FORM_SUBMISSION_FACTS_RESOURCE = 'forms.submission'\n\n/** The visitor-upload purpose a form's files are kept under. */\nexport const FORM_FILE_PURPOSE = 'form-file'\n\n/** A pending submission key: letters and digits, long enough that nobody guesses one. */\nexport const FORM_UPLOAD_KEY_PATTERN = /^[A-Za-z0-9]{24,64}$/\n\n/**\n * The hidden input a File upload field posts each kept file under, as\n * `{fieldName}:{fileId}`. `__`-prefixed, so it is never an answer: the Form\n * lifts these into the request's `files`.\n */\nexport const FORM_FILE_INPUT = '__formFile'\n\n/** The request body's key for the files a submission names. */\nexport const FORM_FILES_BODY_KEY = 'files'\n\n/** The `code` a submit refusal about its files carries, so the form shows its sentence. */\nexport const FORM_FILES_REFUSAL_CODE = 'files'\n\n/** How long an upload key that was never sent keeps its files: a day after its latest file. */\nexport const FORM_UPLOAD_KEY_TTL_MS = 24 * 60 * 60 * 1000\n\n/** Where the upload route keeps what it knows of a pending key, under the form it is for. */\nexport const FORM_UPLOAD_KEYS_COLLECTION = 'formUploadKeys'\n\n/** A fresh pending submission key, from the browser's random source. */\nexport function mintFormUploadKey(random: (bytes: Uint8Array) => Uint8Array = (bytes) => globalThis.crypto.getRandomValues(bytes)): string {\n return Array.from(random(new Uint8Array(16)), (byte) => byte.toString(16).padStart(2, '0')).join('')\n}\n\n/** Whether a value can be a pending submission key. */\nexport function isFormUploadKey(value: unknown): value is string {\n return typeof value === 'string' && FORM_UPLOAD_KEY_PATTERN.test(value)\n}\n\n/** The upload scope of one pending key, which is also the submission it becomes. */\nexport function formFileScope(hostId: string, key: string): VisitorUploadScope {\n return { hostId, purpose: FORM_FILE_PURPOSE, purposeId: key }\n}\n\n/** One file a submission names: which field it answers, and its id under the key. */\nexport interface FormFileRef {\n field: string\n id: string\n}\n\n/** The files a form sends: its key, and each file by field and id. */\nexport interface FormFileRefs {\n key: string\n refs: FormFileRef[]\n}\n\n/**\n * The files a request body names, checked for shape only: a key, and at most\n * {@link VISITOR_UPLOAD_MAX_FILES} distinct `{ field, id }` pairs. `null` when\n * the body names none; an `error` for anything malformed.\n */\nexport function parseFormFileRefs(raw: unknown): FormFileRefs | null | { error: string } {\n if (raw === undefined || raw === null) return null\n const source = (typeof raw === 'object' ? raw : {}) as Record<string, unknown>\n const list = Array.isArray(source['refs']) ? (source['refs'] as unknown[]) : null\n if (!isFormUploadKey(source['key']) || !list) return { error: 'The files sent with this form could not be read.' }\n if (list.length === 0) return null\n if (list.length > VISITOR_UPLOAD_MAX_FILES) {\n return { error: `A form can send up to ${VISITOR_UPLOAD_MAX_FILES} files.` }\n }\n const seen = new Set<string>()\n const refs: FormFileRef[] = []\n for (const entry of list) {\n const ref = (entry && typeof entry === 'object' ? entry : {}) as Record<string, unknown>\n const field = typeof ref['field'] === 'string' ? ref['field'].trim().slice(0, 64) : ''\n const id = ref['id']\n if (!field || !isVisitorUploadSegment(id)) return { error: 'The files sent with this form could not be read.' }\n if (seen.has(id)) continue\n seen.add(id)\n refs.push({ field, id })\n }\n return { key: source['key'] as string, refs }\n}\n\n/** The `{field}:{id}` value a File upload field posts per kept file. */\nexport function formFileInputValue(field: string, id: string): string {\n return `${field}:${id}`\n}\n\n/** The refs a form's hidden file inputs posted, in order. */\nexport function formFileRefsFromInputs(values: readonly string[]): FormFileRef[] {\n const refs: FormFileRef[] = []\n for (const value of values) {\n const at = value.lastIndexOf(':')\n if (at <= 0) continue\n refs.push({ field: value.slice(0, at), id: value.slice(at + 1) })\n }\n return refs\n}\n\n/** A file on a stored submission: which field it answers, and its record without the storage path. */\nexport interface FormSubmissionFile {\n id: string\n field: string\n name: string\n contentType: string\n size: number\n uploadedAtMs: number\n}\n\n/** A kept upload as the submission records it. */\nexport function formSubmissionFileOf(field: string, file: VisitorUploadFile): FormSubmissionFile {\n return {\n id: file.id,\n field,\n name: file.name,\n contentType: file.contentType,\n size: file.size,\n uploadedAtMs: file.uploadedAtMs,\n }\n}\n\n/** The files a stored submission names, read defensively. */\nexport function readFormSubmissionFiles(raw: unknown): FormSubmissionFile[] {\n if (!Array.isArray(raw)) return []\n const files: FormSubmissionFile[] = []\n for (const entry of raw.slice(0, VISITOR_UPLOAD_MAX_FILES)) {\n const file = (entry && typeof entry === 'object' ? entry : {}) as Record<string, unknown>\n if (!isVisitorUploadSegment(file['id']) || typeof file['name'] !== 'string') continue\n files.push({\n id: file['id'] as string,\n field: typeof file['field'] === 'string' ? file['field'] : '',\n name: file['name'],\n contentType: typeof file['contentType'] === 'string' ? file['contentType'] : '',\n size: Number(file['size']) || 0,\n uploadedAtMs: Number(file['uploadedAtMs']) || 0,\n })\n }\n return files\n}\n\n/** What a file field answers with, as the Inbox and the emails read it: the names, in order. */\nexport function formFileFieldAnswer(files: ReadonlyArray<{ name: string }>): string {\n return files.map((file) => file.name).join(', ').slice(0, 2000)\n}\n\n/** The declared `file` fields of a form, by name. */\nexport function formFileFields(decls: readonly FormFieldDecl[]): Map<string, FormFieldDecl> {\n return new Map(decls.filter((decl) => decl?.fieldType === 'file').map((decl) => [decl.fieldName, decl]))\n}\n\n/**\n * Splits a form's posted fields into the answers a person reads and the\n * machine values beside them (`product__data`, see `FORM_FIELD_DATA_SUFFIX`):\n * the answers keep their order; each machine value is kept under the field it\n * belongs to, so `fieldData.product` is what `product__data` posted.\n */\nexport function splitFormFieldData(fields: Readonly<Record<string, string>>): {\n answers: Record<string, string>\n fieldData: Record<string, string>\n} {\n const answers: Record<string, string> = {}\n const fieldData: Record<string, string> = {}\n for (const [key, value] of Object.entries(fields)) {\n const owner = formFieldDataOwner(key)\n if (owner) fieldData[owner] = value\n else answers[key] = value\n }\n return { answers, fieldData }\n}\n\n/** The key a machine value is posted under, for the field it belongs to. */\nexport function formFieldDataKey(field: string): string {\n return `${field}${FORM_FIELD_DATA_SUFFIX}`\n}\n\n/** What a stored submission asks for, or null for an ordinary message. */\nexport function readSubmissionRequest(raw: unknown): FormRequest | null {\n return readFormRequest({ request: raw })\n}\n\n/** The conversation a submission's confirmation started, or null. */\nexport function readSubmissionThread(raw: unknown): EmailThread | null {\n return readEmailThread(raw)\n}\n"],"names":["FORM_FIELD_DATA_SUFFIX","formFieldDataOwner","readFormRequest","isVisitorUploadSegment","VISITOR_UPLOAD_MAX_FILES","readEmailThread","FORM_SUBMISSION_FACTS_RESOURCE","FORM_FILE_PURPOSE","FORM_UPLOAD_KEY_PATTERN","FORM_FILE_INPUT","FORM_FILES_BODY_KEY","FORM_FILES_REFUSAL_CODE","FORM_UPLOAD_KEY_TTL_MS","FORM_UPLOAD_KEYS_COLLECTION","mintFormUploadKey","random","bytes","globalThis","crypto","getRandomValues","Array","from","Uint8Array","byte","toString","padStart","join","isFormUploadKey","value","test","formFileScope","hostId","key","purpose","purposeId","parseFormFileRefs","raw","undefined","source","list","isArray","error","length","seen","Set","refs","entry","ref","field","trim","slice","id","has","add","push","formFileInputValue","formFileRefsFromInputs","values","at","lastIndexOf","formSubmissionFileOf","file","name","contentType","size","uploadedAtMs","readFormSubmissionFiles","files","Number","formFileFieldAnswer","map","formFileFields","decls","Map","filter","decl","fieldType","fieldName","splitFormFieldData","fields","answers","fieldData","Object","entries","owner","formFieldDataKey","readSubmissionRequest","request","readSubmissionThread"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,sBAAsB,EACtBC,kBAAkB,EAClBC,eAAe,QAGV,+BAA8B;AACrC,SACEC,sBAAsB,EACtBC,wBAAwB,QAGnB,wCAAuC;AAC9C,SAASC,eAAe,QAA0B,wCAAuC;AAEzF;;;;;;;;;;;;;;;;;;;;;;;;2CAwB2C,GAE3C,mGAAmG,GACnG,OAAO,MAAMC,iCAAiC,mBAAkB;AAEhE,8DAA8D,GAC9D,OAAO,MAAMC,oBAAoB,YAAW;AAE5C,uFAAuF,GACvF,OAAO,MAAMC,0BAA0B,uBAAsB;AAE7D;;;;CAIC,GACD,OAAO,MAAMC,kBAAkB,aAAY;AAE3C,6DAA6D,GAC7D,OAAO,MAAMC,sBAAsB,QAAO;AAE1C,yFAAyF,GACzF,OAAO,MAAMC,0BAA0B,QAAO;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D;aACzBoD,OAAO,CAAChD,IAAI,GAAGJ;IACtB;IACA,OAAO;QAAEoD;QAASC;IAAU;AAC9B;AAEA,0EAA0E,GAC1E,OAAO,SAASI,iBAAiBrC,KAAa;IAC5C,OAAO,GAAGA,QAAQhD,wBAAwB;AAC5C;AAEA,wEAAwE,GACxE,OAAO,SAASsF,sBAAsBlD,GAAY;IAChD,OAAOlC,gBAAgB;QAAEqF,SAASnD;IAAI;AACxC;AAEA,mEAAmE,GACnE,OAAO,SAASoD,qBAAqBpD,GAAY;IAC/C,OAAO/B,gBAAgB+B;AACzB"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import type { FormFieldDecl, FormRequest } from '@aglyn/aglyn/app-utils/forms';
|
|
18
|
+
import { type EmailThread, type RenderedHostEmail, type SendEmailOptions, type SendEmailResult, type SendingIdentityVerdict } from '@aglyn/shared-util-email';
|
|
19
|
+
/** Confirmations one address may be sent by one site, per hour. */
|
|
20
|
+
export declare const FORM_CONFIRMATIONS_PER_ADDRESS: {
|
|
21
|
+
limit: number;
|
|
22
|
+
windowMs: number;
|
|
23
|
+
};
|
|
24
|
+
/** Confirmations one site may send, per hour. */
|
|
25
|
+
export declare const FORM_CONFIRMATIONS_PER_SITE: {
|
|
26
|
+
limit: number;
|
|
27
|
+
windowMs: number;
|
|
28
|
+
};
|
|
29
|
+
export interface FormConfirmationInput {
|
|
30
|
+
hostId: string;
|
|
31
|
+
host: Record<string, unknown>;
|
|
32
|
+
org: unknown;
|
|
33
|
+
to: string;
|
|
34
|
+
formName: string;
|
|
35
|
+
request: FormRequest | null;
|
|
36
|
+
answers: Readonly<Record<string, string>>;
|
|
37
|
+
decls: readonly FormFieldDecl[];
|
|
38
|
+
consentFieldName: string | null;
|
|
39
|
+
fileNames: readonly string[];
|
|
40
|
+
atMs: number;
|
|
41
|
+
}
|
|
42
|
+
export type FormConfirmationResult = {
|
|
43
|
+
sent: true;
|
|
44
|
+
messageId: string;
|
|
45
|
+
providerId: string | null;
|
|
46
|
+
subject: string;
|
|
47
|
+
thread: EmailThread;
|
|
48
|
+
} | {
|
|
49
|
+
sent: false;
|
|
50
|
+
reason: string;
|
|
51
|
+
};
|
|
52
|
+
export interface FormConfirmationDeps {
|
|
53
|
+
configured(): boolean;
|
|
54
|
+
sendingIdentity(hostId: string): Promise<SendingIdentityVerdict>;
|
|
55
|
+
render(hostId: string, key: string, tokens: Record<string, string>): Promise<RenderedHostEmail | null>;
|
|
56
|
+
send(options: SendEmailOptions): Promise<SendEmailResult>;
|
|
57
|
+
meter(hostId: string): Promise<void>;
|
|
58
|
+
/** The bounce and complaint list only: the person asked for this email. */
|
|
59
|
+
suppression(email: string): Promise<'suppressed-platform' | null>;
|
|
60
|
+
consumeRateLimit(key: string, options: {
|
|
61
|
+
limit: number;
|
|
62
|
+
windowMs: number;
|
|
63
|
+
}): Promise<{
|
|
64
|
+
allowed: boolean;
|
|
65
|
+
}>;
|
|
66
|
+
}
|
|
67
|
+
export declare function defaultFormConfirmationDeps(): FormConfirmationDeps;
|
|
68
|
+
/** The business's name as its emails print it. */
|
|
69
|
+
export declare function formBusinessName(host: Record<string, unknown>): string;
|
|
70
|
+
/** Sends one form's confirmation; never throws. */
|
|
71
|
+
export declare function sendFormConfirmation(input: FormConfirmationInput, deps?: FormConfirmationDeps): Promise<FormConfirmationResult>;
|