@aglyn/plugins-forms 1.0.0-beta.290 → 1.0.0-beta.292

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 (61) hide show
  1. package/README.md +11 -1
  2. package/package.json +14 -14
  3. package/src/lib/components/form-detail-card.js +122 -2
  4. package/src/lib/components/form-detail-card.js.map +1 -1
  5. package/src/lib/components/form-file-upload-body.d.ts +32 -0
  6. package/src/lib/components/form-file-upload-body.js +349 -0
  7. package/src/lib/components/form-file-upload-body.js.map +1 -0
  8. package/src/lib/components/form-file-upload.d.ts +39 -0
  9. package/src/lib/components/form-file-upload.js +175 -0
  10. package/src/lib/components/form-file-upload.js.map +1 -0
  11. package/src/lib/components/form-upload-context.d.ts +31 -0
  12. package/src/lib/components/form-upload-context.js +19 -0
  13. package/src/lib/components/form-upload-context.js.map +1 -0
  14. package/src/lib/components/form.js +48 -4
  15. package/src/lib/components/form.js.map +1 -1
  16. package/src/lib/declarations.console-server.js +14 -0
  17. package/src/lib/declarations.console-server.js.map +1 -1
  18. package/src/lib/declarations.server.js +18 -0
  19. package/src/lib/declarations.server.js.map +1 -1
  20. package/src/lib/model/form-request.d.ts +102 -0
  21. package/src/lib/model/form-request.js +187 -0
  22. package/src/lib/model/form-request.js.map +1 -0
  23. package/src/lib/server/form-confirmation-email.d.ts +70 -0
  24. package/src/lib/server/form-confirmation-email.js +194 -0
  25. package/src/lib/server/form-confirmation-email.js.map +1 -0
  26. package/src/lib/server/form-submit-files.d.ts +42 -0
  27. package/src/lib/server/form-submit-files.js +98 -0
  28. package/src/lib/server/form-submit-files.js.map +1 -0
  29. package/src/lib/server/form-submit.js +115 -7
  30. package/src/lib/server/form-submit.js.map +1 -1
  31. package/src/lib/server/form-upload-sweep.d.ts +30 -0
  32. package/src/lib/server/form-upload-sweep.js +83 -0
  33. package/src/lib/server/form-upload-sweep.js.map +1 -0
  34. package/src/lib/server/form-upload.d.ts +41 -0
  35. package/src/lib/server/form-upload.js +226 -0
  36. package/src/lib/server/form-upload.js.map +1 -0
  37. package/src/lib/server/form-uploads.d.ts +34 -0
  38. package/src/lib/server/form-uploads.js +29 -0
  39. package/src/lib/server/form-uploads.js.map +1 -0
  40. package/src/lib/server/submission-access.d.ts +38 -0
  41. package/src/lib/server/submission-access.js +37 -0
  42. package/src/lib/server/submission-access.js.map +1 -0
  43. package/src/lib/server/submission-facts.d.ts +37 -0
  44. package/src/lib/server/submission-facts.js +227 -0
  45. package/src/lib/server/submission-facts.js.map +1 -0
  46. package/src/lib/server/submission-files.d.ts +41 -0
  47. package/src/lib/server/submission-files.js +126 -0
  48. package/src/lib/server/submission-files.js.map +1 -0
  49. package/src/lib/server.js +22 -0
  50. package/src/lib/server.js.map +1 -1
  51. package/src/lib/site.js +8 -0
  52. package/src/lib/site.js.map +1 -1
  53. package/src/lib/tenant-emails.d.ts +29 -0
  54. package/src/lib/tenant-emails.js +125 -0
  55. package/src/lib/tenant-emails.js.map +1 -0
  56. package/src/lib/testing/stand-in-firestore.d.ts +27 -0
  57. package/src/lib/testing/stand-in-firestore.js +128 -0
  58. package/src/lib/testing/stand-in-firestore.js.map +1 -0
  59. package/src/lib/utils/form-confirmation-content.d.ts +47 -0
  60. package/src/lib/utils/form-confirmation-content.js +109 -0
  61. package/src/lib/utils/form-confirmation-content.js.map +1 -0
@@ -0,0 +1,226 @@
1
+ import { _ as _extends } from "@swc/helpers/_/_extends";
2
+ /**
3
+ * @license
4
+ * Copyright 2026 Aglyn LLC
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */ import { isFormArchived } from "@aglyn/aglyn/app-utils/forms";
18
+ import { NO_CLIENT_ADDRESS_BUCKET, readClientIp } from "@aglyn/aglyn/app-utils/request-ip";
19
+ import { isVisitorUploadSegment, visitorUploadFileView, visitorUploadFinalPath, visitorUploadTypeInKinds, VISITOR_UPLOAD_HONEYPOT_FIELD, VISITOR_UPLOAD_MAX_FILES } from "@aglyn/aglyn/app-utils/visitor-upload";
20
+ import { firebaseAdmin } from "@aglyn/tenant-data-admin/server/firebase-admin";
21
+ import { formFileFields, formFileScope, FORM_UPLOAD_KEYS_COLLECTION, FORM_UPLOAD_KEY_TTL_MS, isFormUploadKey } from "../model/form-request.js";
22
+ export function defaultFormUploadDeps() {
23
+ return {
24
+ firestore: ()=>firebaseAdmin.app().firestore(),
25
+ uploads: async ()=>(await import("./form-uploads.js")).formUploadCalls(),
26
+ now: ()=>Date.now()
27
+ };
28
+ }
29
+ const DOC_ID = /^(?!__.*__$)[^/]{1,128}$/;
30
+ const json = (body, status = 200, headers)=>Response.json(body, _extends({
31
+ status
32
+ }, headers ? {
33
+ headers
34
+ } : {}));
35
+ /** The marker of a key, under the form it was minted for. */ export function formUploadKeyRef(firestore, hostId, formId, key) {
36
+ return firestore.collection('hosts').doc(hostId).collection('forms').doc(formId).collection(FORM_UPLOAD_KEYS_COLLECTION).doc(key);
37
+ }
38
+ /** The files a key's record holds, read defensively. */ export function formUploadKeyFiles(data) {
39
+ var _ref;
40
+ const files = (_ref = data == null ? void 0 : data['files']) != null ? _ref : {};
41
+ return Object.fromEntries(Object.entries(files).filter((entry)=>isVisitorUploadSegment(entry[0]) && typeof entry[1] === 'string'));
42
+ }
43
+ /** How many of a key's files answer one field. */ const countFor = (files, field)=>Object.values(files).filter((owner)=>owner === field).length;
44
+ /** The refusal when a field holds all it takes. */ function fullMessage(decl) {
45
+ var _decl_maxFiles;
46
+ const max = (_decl_maxFiles = decl.maxFiles) != null ? _decl_maxFiles : VISITOR_UPLOAD_MAX_FILES;
47
+ return max === 1 ? 'This field takes one file. Remove it to send another.' : `This field takes up to ${max} files.`;
48
+ }
49
+ export async function handleFormUpload(deps, request) {
50
+ var _body_action, _body_hostId, _body_formId, _readClientIp, _body_field;
51
+ if (request.method !== 'POST') return new Response(null, {
52
+ status: 405,
53
+ headers: {
54
+ Allow: 'POST'
55
+ }
56
+ });
57
+ const body = await request.json().catch(()=>({}));
58
+ // A person never fills the honeypot; a bot that did learns nothing.
59
+ const honeypot = body[VISITOR_UPLOAD_HONEYPOT_FIELD];
60
+ if (typeof honeypot === 'string' && honeypot.trim()) return json({
61
+ received: true
62
+ });
63
+ const action = String((_body_action = body['action']) != null ? _body_action : '');
64
+ const hostId = String((_body_hostId = body['hostId']) != null ? _body_hostId : '');
65
+ const formId = String((_body_formId = body['formId']) != null ? _body_formId : '');
66
+ const key = body['key'];
67
+ if (!DOC_ID.test(hostId) || !DOC_ID.test(formId) || !isFormUploadKey(key)) {
68
+ return json({
69
+ error: 'This form can’t take files right now. Reload the page and try again.'
70
+ }, 400);
71
+ }
72
+ const firestore = deps.firestore();
73
+ const formSnapshot = await firestore.collection('hosts').doc(hostId).collection('forms').doc(formId).get();
74
+ if (!formSnapshot.exists || isFormArchived(formSnapshot.data())) {
75
+ return json({
76
+ error: 'This form is no longer accepting submissions.'
77
+ }, 404);
78
+ }
79
+ const decls = Array.isArray(formSnapshot.get('fields')) ? formSnapshot.get('fields') : [];
80
+ const fileFields = formFileFields(decls);
81
+ const scope = formFileScope(hostId, key);
82
+ const markerRef = formUploadKeyRef(firestore, hostId, formId, key);
83
+ const caller = {
84
+ ip: (_readClientIp = readClientIp(request.headers)) != null ? _readClientIp : NO_CLIENT_ADDRESS_BUCKET
85
+ };
86
+ if (action === 'remove') {
87
+ const fileId = body['fileId'];
88
+ if (!isVisitorUploadSegment(fileId)) return json({
89
+ error: 'Unknown file'
90
+ }, 400);
91
+ const marker = await markerRef.get();
92
+ const files = formUploadKeyFiles(marker.data());
93
+ // Only a file this key holds; a stranger's key holds nothing of theirs.
94
+ if (!marker.exists || !(fileId in files)) return json({
95
+ removed: true
96
+ });
97
+ const uploads = await deps.uploads();
98
+ await uploads.remove(visitorUploadFinalPath(scope, fileId));
99
+ const rest = _extends({}, files);
100
+ delete rest[fileId];
101
+ // `update` writes the map whole, so the removed file leaves it.
102
+ await markerRef.update({
103
+ files: rest
104
+ });
105
+ return json({
106
+ removed: true
107
+ });
108
+ }
109
+ const field = String((_body_field = body['field']) != null ? _body_field : '').trim();
110
+ const decl = fileFields.get(field);
111
+ if (!decl) return json({
112
+ error: 'This form doesn’t take files here.'
113
+ }, 404);
114
+ if (action === 'ticket') {
115
+ var _decl_maxFiles;
116
+ const marker = await markerRef.get();
117
+ const files = formUploadKeyFiles(marker.data());
118
+ if (countFor(files, field) >= ((_decl_maxFiles = decl.maxFiles) != null ? _decl_maxFiles : VISITOR_UPLOAD_MAX_FILES)) {
119
+ return json({
120
+ error: fullMessage(decl)
121
+ }, 409);
122
+ }
123
+ if (Object.keys(files).length >= VISITOR_UPLOAD_MAX_FILES) {
124
+ return json({
125
+ error: `A form can send up to ${VISITOR_UPLOAD_MAX_FILES} files.`
126
+ }, 409);
127
+ }
128
+ const uploads = await deps.uploads();
129
+ const minted = await uploads.mint({
130
+ scope,
131
+ request: body['file'],
132
+ caller,
133
+ kinds: decl.fileKinds
134
+ });
135
+ if ('error' in minted) {
136
+ return json({
137
+ error: minted.error,
138
+ code: minted.code
139
+ }, minted.status, minted.retryAfterSeconds ? {
140
+ 'Retry-After': String(minted.retryAfterSeconds)
141
+ } : undefined);
142
+ }
143
+ const now = deps.now();
144
+ await markerRef.set(_extends({
145
+ hostId,
146
+ formId,
147
+ key
148
+ }, marker.exists ? {} : {
149
+ createdAtMs: now,
150
+ files: {}
151
+ }, {
152
+ sweepAtMs: now + FORM_UPLOAD_KEY_TTL_MS
153
+ }), {
154
+ merge: true
155
+ });
156
+ return json({
157
+ ticket: minted.ticket,
158
+ upload: minted.upload,
159
+ file: minted.file
160
+ });
161
+ }
162
+ if (action === 'finalize') {
163
+ const uploads = await deps.uploads();
164
+ const kept = await uploads.finalize({
165
+ scope,
166
+ ticket: body['ticket'],
167
+ caller
168
+ });
169
+ if ('error' in kept) return json({
170
+ error: kept.error,
171
+ code: kept.code
172
+ }, kept.status);
173
+ // The ticket held the kinds; the bytes are held to them again here.
174
+ if (!visitorUploadTypeInKinds(kept.file.contentType, decl.fileKinds)) {
175
+ await uploads.remove(kept.file.path).catch(()=>undefined);
176
+ return json({
177
+ error: `${kept.file.name} isn’t a kind of file this field takes.`
178
+ }, 415);
179
+ }
180
+ const now = deps.now();
181
+ const answer = await firestore.runTransaction(async (transaction)=>{
182
+ var _decl_maxFiles;
183
+ const marker = await transaction.get(markerRef);
184
+ // Swept, or never ticketed here: the file has no key to belong to.
185
+ if (!marker.exists) return 'gone';
186
+ const files = formUploadKeyFiles(marker.data());
187
+ if (files[kept.file.id] === field) return 'kept';
188
+ if (countFor(files, field) >= ((_decl_maxFiles = decl.maxFiles) != null ? _decl_maxFiles : VISITOR_UPLOAD_MAX_FILES)) return 'full';
189
+ transaction.set(markerRef, {
190
+ files: _extends({}, files, {
191
+ [kept.file.id]: field
192
+ }),
193
+ sweepAtMs: now + FORM_UPLOAD_KEY_TTL_MS
194
+ }, {
195
+ merge: true
196
+ });
197
+ return 'kept';
198
+ });
199
+ if (answer !== 'kept') {
200
+ await uploads.remove(kept.file.path).catch(()=>undefined);
201
+ return answer === 'full' ? json({
202
+ error: fullMessage(decl)
203
+ }, 409) : json({
204
+ error: 'This upload took too long. Reload the page and attach the file again.'
205
+ }, 410);
206
+ }
207
+ return json({
208
+ file: visitorUploadFileView(kept.file)
209
+ });
210
+ }
211
+ return json({
212
+ error: 'Unknown action'
213
+ }, 400);
214
+ }
215
+ /** `POST /api/forms/upload`. */ export async function POST(request) {
216
+ try {
217
+ return await handleFormUpload(defaultFormUploadDeps(), request);
218
+ } catch (error) {
219
+ console.error('[forms] upload failed', error);
220
+ return json({
221
+ error: 'The file could not be sent. Try again.'
222
+ }, 500);
223
+ }
224
+ }
225
+
226
+ //# sourceMappingURL=form-upload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/forms/src/lib/server/form-upload.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 { isFormArchived, type FormFieldDecl } from '@aglyn/aglyn/app-utils/forms'\nimport { NO_CLIENT_ADDRESS_BUCKET, readClientIp } from '@aglyn/aglyn/app-utils/request-ip'\nimport {\n isVisitorUploadSegment,\n visitorUploadFileView,\n visitorUploadFinalPath,\n visitorUploadTypeInKinds,\n VISITOR_UPLOAD_HONEYPOT_FIELD,\n VISITOR_UPLOAD_MAX_FILES,\n} from '@aglyn/aglyn/app-utils/visitor-upload'\nimport { firebaseAdmin } from '@aglyn/tenant-data-admin/server/firebase-admin'\nimport {\n formFileFields,\n formFileScope,\n FORM_UPLOAD_KEYS_COLLECTION,\n FORM_UPLOAD_KEY_TTL_MS,\n isFormUploadKey,\n} from '../model/form-request'\nimport type { FormUploadCalls } from './form-uploads'\n\n/*==========================================\n * A FORM'S FILES, SENT BEFORE THE FORM (AGL-4098): `POST /api/forms/upload`.\n *\n * { action: 'ticket', hostId, formId, key, field, file: { name, contentType, size } }\n * → { ticket, upload: { url, fields }, file }\n * { action: 'finalize', hostId, formId, key, field, ticket }\n * → { file: { id, name, contentType, size, uploadedAtMs } }\n * { action: 'remove', hostId, formId, key, fileId }\n * → { removed: true }\n *\n * The shared visitor upload (`@aglyn/tenant-data-admin/server/visitor-upload`)\n * moves and checks the bytes; this route decides who may upload for what. A\n * file is taken only for a form that exists on the site, is in use, and\n * DECLARES a File upload field of that name — and only of the kinds, and up\n * to the number, the author set on that field. Everything is scoped to the\n * pending submission key the Form minted (`form-file/{key}`), which the\n * submission takes as its id when it is sent.\n *\n * What the route knows of a key is kept under the form,\n * `hosts/{hostId}/forms/{formId}/formUploadKeys/{key}`: which files it holds\n * and for which field, and when it may be swept. The submit route reads it to\n * check a submission's files and deletes it once they are the submission's;\n * the console's sweep (`form-upload-sweep.ts`) deletes the files of a key\n * that was never sent, a day after its latest file.\n *\n * A visitor door like the submit route, but one that keeps the tenant\n * dispatcher's gates: its cross-origin check, the site's Forms switch,\n * lockdown and the visitor-write limit stand in front of it, and the upload's\n * own limits (tickets per address and per site, the `uploads` pause) behind.\n * The honeypot is answered quietly, as the submit route answers it.\n *=========================================*/\n\nexport interface FormUploadDeps {\n firestore(): FirebaseFirestore.Firestore\n uploads(): Promise<FormUploadCalls>\n now(): number\n}\n\nexport function defaultFormUploadDeps(): FormUploadDeps {\n return {\n firestore: () => firebaseAdmin.app().firestore(),\n uploads: async () => (await import('./form-uploads')).formUploadCalls(),\n now: () => Date.now(),\n }\n}\n\n/** What the upload route knows of one pending key. */\nexport interface FormUploadKeyRecord {\n hostId: string\n formId: string\n key: string\n /** Each kept file's id, and the field it was sent for. */\n files: Record<string, string>\n createdAtMs: number\n /** When the console's sweep may delete the key's files, if it was never sent. */\n sweepAtMs: number\n}\n\nconst DOC_ID = /^(?!__.*__$)[^/]{1,128}$/\n\nconst json = (body: unknown, status = 200, headers?: Record<string, string>) =>\n Response.json(body, { status, ...(headers ? { headers } : {}) })\n\n/** The marker of a key, under the form it was minted for. */\nexport function formUploadKeyRef(\n firestore: FirebaseFirestore.Firestore,\n hostId: string,\n formId: string,\n key: string,\n): FirebaseFirestore.DocumentReference {\n return firestore\n .collection('hosts')\n .doc(hostId)\n .collection('forms')\n .doc(formId)\n .collection(FORM_UPLOAD_KEYS_COLLECTION)\n .doc(key)\n}\n\n/** The files a key's record holds, read defensively. */\nexport function formUploadKeyFiles(data: Record<string, unknown> | undefined): Record<string, string> {\n const files = (data?.['files'] ?? {}) as Record<string, unknown>\n return Object.fromEntries(\n Object.entries(files).filter(\n (entry): entry is [string, string] => isVisitorUploadSegment(entry[0]) && typeof entry[1] === 'string',\n ),\n )\n}\n\n/** How many of a key's files answer one field. */\nconst countFor = (files: Record<string, string>, field: string) =>\n Object.values(files).filter((owner) => owner === field).length\n\n/** The refusal when a field holds all it takes. */\nfunction fullMessage(decl: FormFieldDecl): string {\n const max = decl.maxFiles ?? VISITOR_UPLOAD_MAX_FILES\n return max === 1 ? 'This field takes one file. Remove it to send another.' : `This field takes up to ${max} files.`\n}\n\nexport async function handleFormUpload(deps: FormUploadDeps, request: Request): Promise<Response> {\n if (request.method !== 'POST') return new Response(null, { status: 405, headers: { Allow: 'POST' } })\n const body = (await request.json().catch(() => ({}))) as Record<string, unknown>\n // A person never fills the honeypot; a bot that did learns nothing.\n const honeypot = body[VISITOR_UPLOAD_HONEYPOT_FIELD]\n if (typeof honeypot === 'string' && honeypot.trim()) return json({ received: true })\n\n const action = String(body['action'] ?? '')\n const hostId = String(body['hostId'] ?? '')\n const formId = String(body['formId'] ?? '')\n const key = body['key']\n if (!DOC_ID.test(hostId) || !DOC_ID.test(formId) || !isFormUploadKey(key)) {\n return json({ error: 'This form can’t take files right now. Reload the page and try again.' }, 400)\n }\n\n const firestore = deps.firestore()\n const formSnapshot = await firestore.collection('hosts').doc(hostId).collection('forms').doc(formId).get()\n if (!formSnapshot.exists || isFormArchived(formSnapshot.data() as never)) {\n return json({ error: 'This form is no longer accepting submissions.' }, 404)\n }\n const decls = Array.isArray(formSnapshot.get('fields')) ? (formSnapshot.get('fields') as FormFieldDecl[]) : []\n const fileFields = formFileFields(decls)\n const scope = formFileScope(hostId, key)\n const markerRef = formUploadKeyRef(firestore, hostId, formId, key)\n const caller = { ip: readClientIp(request.headers) ?? NO_CLIENT_ADDRESS_BUCKET }\n\n if (action === 'remove') {\n const fileId = body['fileId']\n if (!isVisitorUploadSegment(fileId)) return json({ error: 'Unknown file' }, 400)\n const marker = await markerRef.get()\n const files = formUploadKeyFiles(marker.data())\n // Only a file this key holds; a stranger's key holds nothing of theirs.\n if (!marker.exists || !(fileId in files)) return json({ removed: true })\n const uploads = await deps.uploads()\n await uploads.remove(visitorUploadFinalPath(scope, fileId))\n const rest = { ...files }\n delete rest[fileId]\n // `update` writes the map whole, so the removed file leaves it.\n await markerRef.update({ files: rest })\n return json({ removed: true })\n }\n\n const field = String(body['field'] ?? '').trim()\n const decl = fileFields.get(field)\n if (!decl) return json({ error: 'This form doesn’t take files here.' }, 404)\n\n if (action === 'ticket') {\n const marker = await markerRef.get()\n const files = formUploadKeyFiles(marker.data())\n if (countFor(files, field) >= (decl.maxFiles ?? VISITOR_UPLOAD_MAX_FILES)) {\n return json({ error: fullMessage(decl) }, 409)\n }\n if (Object.keys(files).length >= VISITOR_UPLOAD_MAX_FILES) {\n return json({ error: `A form can send up to ${VISITOR_UPLOAD_MAX_FILES} files.` }, 409)\n }\n const uploads = await deps.uploads()\n const minted = await uploads.mint({ scope, request: body['file'], caller, kinds: decl.fileKinds })\n if ('error' in minted) {\n return json(\n { error: minted.error, code: minted.code },\n minted.status,\n minted.retryAfterSeconds ? { 'Retry-After': String(minted.retryAfterSeconds) } : undefined,\n )\n }\n const now = deps.now()\n await markerRef.set(\n {\n hostId,\n formId,\n key,\n ...(marker.exists ? {} : { createdAtMs: now, files: {} }),\n sweepAtMs: now + FORM_UPLOAD_KEY_TTL_MS,\n },\n { merge: true },\n )\n return json({ ticket: minted.ticket, upload: minted.upload, file: minted.file })\n }\n\n if (action === 'finalize') {\n const uploads = await deps.uploads()\n const kept = await uploads.finalize({ scope, ticket: body['ticket'], caller })\n if ('error' in kept) return json({ error: kept.error, code: kept.code }, kept.status)\n // The ticket held the kinds; the bytes are held to them again here.\n if (!visitorUploadTypeInKinds(kept.file.contentType, decl.fileKinds)) {\n await uploads.remove(kept.file.path).catch(() => undefined)\n return json({ error: `${kept.file.name} isn’t a kind of file this field takes.` }, 415)\n }\n const now = deps.now()\n const answer = await firestore.runTransaction(async (transaction) => {\n const marker = await transaction.get(markerRef)\n // Swept, or never ticketed here: the file has no key to belong to.\n if (!marker.exists) return 'gone' as const\n const files = formUploadKeyFiles(marker.data())\n if (files[kept.file.id] === field) return 'kept' as const\n if (countFor(files, field) >= (decl.maxFiles ?? VISITOR_UPLOAD_MAX_FILES)) return 'full' as const\n transaction.set(\n markerRef,\n { files: { ...files, [kept.file.id]: field }, sweepAtMs: now + FORM_UPLOAD_KEY_TTL_MS },\n { merge: true },\n )\n return 'kept' as const\n })\n if (answer !== 'kept') {\n await uploads.remove(kept.file.path).catch(() => undefined)\n return answer === 'full'\n ? json({ error: fullMessage(decl) }, 409)\n : json({ error: 'This upload took too long. Reload the page and attach the file again.' }, 410)\n }\n return json({ file: visitorUploadFileView(kept.file) })\n }\n\n return json({ error: 'Unknown action' }, 400)\n}\n\n/** `POST /api/forms/upload`. */\nexport async function POST(request: Request): Promise<Response> {\n try {\n return await handleFormUpload(defaultFormUploadDeps(), request)\n } catch (error) {\n console.error('[forms] upload failed', error)\n return json({ error: 'The file could not be sent. Try again.' }, 500)\n }\n}\n"],"names":["isFormArchived","NO_CLIENT_ADDRESS_BUCKET","readClientIp","isVisitorUploadSegment","visitorUploadFileView","visitorUploadFinalPath","visitorUploadTypeInKinds","VISITOR_UPLOAD_HONEYPOT_FIELD","VISITOR_UPLOAD_MAX_FILES","firebaseAdmin","formFileFields","formFileScope","FORM_UPLOAD_KEYS_COLLECTION","FORM_UPLOAD_KEY_TTL_MS","isFormUploadKey","defaultFormUploadDeps","firestore","app","uploads","formUploadCalls","now","Date","DOC_ID","json","body","status","headers","Response","formUploadKeyRef","hostId","formId","key","collection","doc","formUploadKeyFiles","data","files","Object","fromEntries","entries","filter","entry","countFor","field","values","owner","length","fullMessage","decl","max","maxFiles","handleFormUpload","deps","request","method","Allow","catch","honeypot","trim","received","action","String","test","error","formSnapshot","get","exists","decls","Array","isArray","fileFields","scope","markerRef","caller","ip","fileId","marker","removed","remove","rest","update","keys","minted","mint","kinds","fileKinds","code","retryAfterSeconds","undefined","set","createdAtMs","sweepAtMs","merge","ticket","upload","file","kept","finalize","contentType","path","name","answer","runTransaction","transaction","id","POST","console"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,cAAc,QAA4B,+BAA8B;AACjF,SAASC,wBAAwB,EAAEC,YAAY,QAAQ,oCAAmC;AAC1F,SACEC,sBAAsB,EACtBC,qBAAqB,EACrBC,sBAAsB,EACtBC,wBAAwB,EACxBC,6BAA6B,EAC7BC,wBAAwB,QACnB,wCAAuC;AAC9C,SAASC,aAAa,QAAQ,iDAAgD;AAC9E,SACEC,cAAc,EACdC,aAAa,EACbC,2BAA2B,EAC3BC,sBAAsB,EACtBC,eAAe,QACV,2BAAuB;AAyC9B,OAAO,SAASC;IACd,OAAO;QACLC,WAAW,IAAMP,cAAcQ,GAAG,GAAGD,SAAS;QAC9CE,SAAS,UAAY,AAAC,CAAA,MAAM,MAAM,CAAC,oBAAgB,EAAGC,eAAe;QACrEC,KAAK,IAAMC,KAAKD,GAAG;IACrB;AACF;AAcA,MAAME,SAAS;AAEf,MAAMC,OAAO,CAACC,MAAeC,SAAS,GAAG,EAAEC,UACzCC,SAASJ,IAAI,CAACC,MAAM;QAAEC;OAAYC,UAAU;QAAEA;IAAQ,IAAI,CAAC;AAE7D,2DAA2D,GAC3D,OAAO,SAASE,iBACdZ,SAAsC,EACtCa,MAAc,EACdC,MAAc,EACdC,GAAW;IAEX,OAAOf,UACJgB,UAAU,CAAC,SACXC,GAAG,CAACJ,QACJG,UAAU,CAAC,SACXC,GAAG,CAACH,QACJE,UAAU,CAACpB,6BACXqB,GAAG,CAACF;AACT;AAEA,sDAAsD,GACtD,OAAO,SAASG,mBAAmBC,IAAyC;;IAC1E,MAAMC,gBAASD,wBAAAA,IAAM,CAAC,QAAQ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AOO,YAAWK,iBAAAA,KAAKE,QAAQ,YAAbF,iBAAiBxC,2BAA2B,OAAO;YAClF+F,YAAYd,GAAG,CACbjB,WACA;gBAAEpC,OAAO,aAAKA;oBAAO,CAAC4D,KAAKD,IAAI,CAACS,EAAE,CAAC,EAAE7D;;gBAASgD,WAAWvE,MAAMP;YAAuB,GACtF;gBAAE+E,OAAO;YAAK;YAEhB,OAAO;QACT;QACA,IAAIS,WAAW,QAAQ;YACrB,MAAMnF,QAAQ4D,MAAM,CAACkB,KAAKD,IAAI,CAACI,IAAI,EAAE3C,KAAK,CAAC,IAAMgC;YACjD,OAAOa,WAAW,SACd9E,KAAK;gBAAEwC,OAAOhB,YAAYC;YAAM,GAAG,OACnCzB,KAAK;gBAAEwC,OAAO;YAAwE,GAAG;QAC/F;QACA,OAAOxC,KAAK;YAAEwE,MAAM3F,sBAAsB4F,KAAKD,IAAI;QAAE;IACvD;IAEA,OAAOxE,KAAK;QAAEwC,OAAO;IAAiB,GAAG;AAC3C;AAEA,8BAA8B,GAC9B,OAAO,eAAe0C,KAAKpD,OAAgB;IACzC,IAAI;QACF,OAAO,MAAMF,iBAAiBpC,yBAAyBsC;IACzD,EAAE,OAAOU,OAAO;QACd2C,QAAQ3C,KAAK,CAAC,yBAAyBA;QACvC,OAAOxC,KAAK;YAAEwC,OAAO;QAAyC,GAAG;IACnE;AACF"}
@@ -0,0 +1,34 @@
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 { VisitorUploadFile, VisitorUploadScope } from '@aglyn/aglyn/app-utils/visitor-upload';
18
+ import { finalizeVisitorUpload, mintVisitorUploadTicket, type VisitorUploadResponse } from '@aglyn/tenant-data-admin/server/visitor-upload';
19
+ /**
20
+ * The shared visitor upload's calls, as a form's routes make them (AGL-4098):
21
+ * the upload route, the submit route, the Inbox's download, a deleted
22
+ * submission's clean-up and the sweep of keys never sent. Reached by dynamic
23
+ * import, so the upload pipeline, the bucket and the SVG sanitizer load only
24
+ * when a file is actually sent, read or removed.
25
+ */
26
+ export interface FormUploadCalls {
27
+ mint(input: Parameters<typeof mintVisitorUploadTicket>[1]): ReturnType<typeof mintVisitorUploadTicket>;
28
+ finalize(input: Parameters<typeof finalizeVisitorUpload>[1]): ReturnType<typeof finalizeVisitorUpload>;
29
+ read(scope: VisitorUploadScope, id: string): Promise<VisitorUploadFile | null>;
30
+ remove(path: string): Promise<void>;
31
+ removeAll(scope: VisitorUploadScope): Promise<void>;
32
+ send(res: VisitorUploadResponse, file: Pick<VisitorUploadFile, 'path' | 'name' | 'contentType'>): Promise<void>;
33
+ }
34
+ export declare function formUploadCalls(): FormUploadCalls;
@@ -0,0 +1,29 @@
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 { defaultVisitorUploadDeps, deleteVisitorUpload, deleteVisitorUploads, finalizeVisitorUpload, mintVisitorUploadTicket, readVisitorUpload, sendVisitorUploadFile } from "@aglyn/tenant-data-admin/server/visitor-upload";
17
+ export function formUploadCalls() {
18
+ const deps = defaultVisitorUploadDeps();
19
+ return {
20
+ mint: (input)=>mintVisitorUploadTicket(deps, input),
21
+ finalize: (input)=>finalizeVisitorUpload(deps, input),
22
+ read: (scope, id)=>readVisitorUpload(deps, scope, id),
23
+ remove: (path)=>deleteVisitorUpload(deps, path),
24
+ removeAll: (scope)=>deleteVisitorUploads(deps, scope),
25
+ send: (res, file)=>sendVisitorUploadFile(deps, res, file)
26
+ };
27
+ }
28
+
29
+ //# sourceMappingURL=form-uploads.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/forms/src/lib/server/form-uploads.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 type { VisitorUploadFile, VisitorUploadScope } from '@aglyn/aglyn/app-utils/visitor-upload'\nimport {\n defaultVisitorUploadDeps,\n deleteVisitorUpload,\n deleteVisitorUploads,\n finalizeVisitorUpload,\n mintVisitorUploadTicket,\n readVisitorUpload,\n sendVisitorUploadFile,\n type VisitorUploadResponse,\n} from '@aglyn/tenant-data-admin/server/visitor-upload'\n\n/**\n * The shared visitor upload's calls, as a form's routes make them (AGL-4098):\n * the upload route, the submit route, the Inbox's download, a deleted\n * submission's clean-up and the sweep of keys never sent. Reached by dynamic\n * import, so the upload pipeline, the bucket and the SVG sanitizer load only\n * when a file is actually sent, read or removed.\n */\nexport interface FormUploadCalls {\n mint(input: Parameters<typeof mintVisitorUploadTicket>[1]): ReturnType<typeof mintVisitorUploadTicket>\n finalize(input: Parameters<typeof finalizeVisitorUpload>[1]): ReturnType<typeof finalizeVisitorUpload>\n read(scope: VisitorUploadScope, id: string): Promise<VisitorUploadFile | null>\n remove(path: string): Promise<void>\n removeAll(scope: VisitorUploadScope): Promise<void>\n send(res: VisitorUploadResponse, file: Pick<VisitorUploadFile, 'path' | 'name' | 'contentType'>): Promise<void>\n}\n\nexport function formUploadCalls(): FormUploadCalls {\n const deps = defaultVisitorUploadDeps()\n return {\n mint: (input) => mintVisitorUploadTicket(deps, input),\n finalize: (input) => finalizeVisitorUpload(deps, input),\n read: (scope, id) => readVisitorUpload(deps, scope, id),\n remove: (path) => deleteVisitorUpload(deps, path),\n removeAll: (scope) => deleteVisitorUploads(deps, scope),\n send: (res, file) => sendVisitorUploadFile(deps, res, file),\n }\n}\n"],"names":["defaultVisitorUploadDeps","deleteVisitorUpload","deleteVisitorUploads","finalizeVisitorUpload","mintVisitorUploadTicket","readVisitorUpload","sendVisitorUploadFile","formUploadCalls","deps","mint","input","finalize","read","scope","id","remove","path","removeAll","send","res","file"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAGD,SACEA,wBAAwB,EACxBC,mBAAmB,EACnBC,oBAAoB,EACpBC,qBAAqB,EACrBC,uBAAuB,EACvBC,iBAAiB,EACjBC,qBAAqB,QAEhB,iDAAgD;AAkBvD,OAAO,SAASC;IACd,MAAMC,OAAOR;IACb,OAAO;QACLS,MAAM,CAACC,QAAUN,wBAAwBI,MAAME;QAC/CC,UAAU,CAACD,QAAUP,sBAAsBK,MAAME;QACjDE,MAAM,CAACC,OAAOC,KAAOT,kBAAkBG,MAAMK,OAAOC;QACpDC,QAAQ,CAACC,OAASf,oBAAoBO,MAAMQ;QAC5CC,WAAW,CAACJ,QAAUX,qBAAqBM,MAAMK;QACjDK,MAAM,CAACC,KAAKC,OAASd,sBAAsBE,MAAMW,KAAKC;IACxD;AACF"}
@@ -0,0 +1,38 @@
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
+ /**
18
+ * Whether a member may read a site's form submissions on the server, asked
19
+ * the way the security rules ask it of the Inbox's own reads (AGL-4098): a
20
+ * verified staff caller; a member of the site (`memberRoles`, the rules'
21
+ * `isHostMember`); or, for a submission filed under an organization, a
22
+ * member of that whole organization (the org Inbox's collection-group read,
23
+ * `isOrgWideMemberOf(resource.data.orgId)`).
24
+ *
25
+ * Reading is all it grants: the Inbox's own reads are site membership, so a
26
+ * submission's files are downloaded on the same terms as its fields are read.
27
+ */
28
+ export declare function memberMayReadSubmissions(input: {
29
+ uid: string;
30
+ staff: boolean;
31
+ host: {
32
+ get(field: string): unknown;
33
+ };
34
+ /** The organization the submission is filed under, when it names one. */
35
+ orgId: string | null;
36
+ /** The member's record in that organization, read only when site membership does not answer. */
37
+ orgMember: (orgId: string, uid: string) => Promise<Record<string, unknown> | null>;
38
+ }): Promise<boolean>;
@@ -0,0 +1,37 @@
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 { isOrgWideMember } from "@aglyn/aglyn/app-utils/organizations";
17
+ /**
18
+ * Whether a member may read a site's form submissions on the server, asked
19
+ * the way the security rules ask it of the Inbox's own reads (AGL-4098): a
20
+ * verified staff caller; a member of the site (`memberRoles`, the rules'
21
+ * `isHostMember`); or, for a submission filed under an organization, a
22
+ * member of that whole organization (the org Inbox's collection-group read,
23
+ * `isOrgWideMemberOf(resource.data.orgId)`).
24
+ *
25
+ * Reading is all it grants: the Inbox's own reads are site membership, so a
26
+ * submission's files are downloaded on the same terms as its fields are read.
27
+ */ export async function memberMayReadSubmissions(input) {
28
+ var _input_host_get;
29
+ if (input.staff) return true;
30
+ const roles = (_input_host_get = input.host.get('memberRoles')) != null ? _input_host_get : {};
31
+ if (roles[input.uid]) return true;
32
+ if (!input.orgId) return false;
33
+ const member = await input.orgMember(input.orgId, input.uid).catch(()=>null);
34
+ return isOrgWideMember(member);
35
+ }
36
+
37
+ //# sourceMappingURL=submission-access.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/forms/src/lib/server/submission-access.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 { isOrgWideMember } from '@aglyn/aglyn/app-utils/organizations'\n\n/**\n * Whether a member may read a site's form submissions on the server, asked\n * the way the security rules ask it of the Inbox's own reads (AGL-4098): a\n * verified staff caller; a member of the site (`memberRoles`, the rules'\n * `isHostMember`); or, for a submission filed under an organization, a\n * member of that whole organization (the org Inbox's collection-group read,\n * `isOrgWideMemberOf(resource.data.orgId)`).\n *\n * Reading is all it grants: the Inbox's own reads are site membership, so a\n * submission's files are downloaded on the same terms as its fields are read.\n */\nexport async function memberMayReadSubmissions(input: {\n uid: string\n staff: boolean\n host: { get(field: string): unknown }\n /** The organization the submission is filed under, when it names one. */\n orgId: string | null\n /** The member's record in that organization, read only when site membership does not answer. */\n orgMember: (orgId: string, uid: string) => Promise<Record<string, unknown> | null>\n}): Promise<boolean> {\n if (input.staff) return true\n const roles = (input.host.get('memberRoles') ?? {}) as Record<string, unknown>\n if (roles[input.uid]) return true\n if (!input.orgId) return false\n const member = await input.orgMember(input.orgId, input.uid).catch(() => null)\n return isOrgWideMember(member as never)\n}\n"],"names":["isOrgWideMember","memberMayReadSubmissions","input","staff","roles","host","get","uid","orgId","member","orgMember","catch"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,eAAe,QAAQ,uCAAsC;AAEtE;;;;;;;;;;CAUC,GACD,OAAO,eAAeC,yBAAyBC,KAQ9C;QAEgBA;IADf,IAAIA,MAAMC,KAAK,EAAE,OAAO;IACxB,MAAMC,SAASF,kBAAAA,MAAMG,IAAI,CAACC,GAAG,CAAC,0BAAfJ,kBAAiC,CAAC;IACjD,IAAIE,KAAK,CAACF,MAAMK,GAAG,CAAC,EAAE,OAAO;IAC7B,IAAI,CAACL,MAAMM,KAAK,EAAE,OAAO;IACzB,MAAMC,SAAS,MAAMP,MAAMQ,SAAS,CAACR,MAAMM,KAAK,EAAEN,MAAMK,GAAG,EAAEI,KAAK,CAAC,IAAM;IACzE,OAAOX,gBAAgBS;AACzB"}
@@ -0,0 +1,37 @@
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 } from '@aglyn/aglyn/app-utils/forms';
18
+ import type { PluginRecordFactsRead, PluginRecordFactsReader, PluginRecordFactsRequest } from '@aglyn/aglyn/plugin-manager/plugin-record-facts';
19
+ import { FORM_SUBMISSION_FACTS_RESOURCE } from '../model/form-request';
20
+ export { FORM_SUBMISSION_FACTS_RESOURCE };
21
+ export interface SubmissionFactsDeps {
22
+ firestore(): FirebaseFirestore.Firestore;
23
+ orgMember(orgId: string, uid: string): Promise<Record<string, unknown> | null>;
24
+ }
25
+ export declare function defaultSubmissionFactsDeps(): SubmissionFactsDeps;
26
+ /** Who sent it, as far as the answers say. */
27
+ export declare function submissionPerson(fields: Record<string, string>): {
28
+ name: string;
29
+ email: string;
30
+ phone: string;
31
+ company: string;
32
+ };
33
+ /** The request's own words: a message field, else the form's first multi-line field. */
34
+ export declare function submissionMessage(fields: Record<string, string>, decls: readonly FormFieldDecl[]): string;
35
+ export declare function readSubmissionFacts(deps: SubmissionFactsDeps, request: PluginRecordFactsRequest): Promise<PluginRecordFactsRead>;
36
+ /** The reader as the seam registers it; its module loads with the first read. */
37
+ export declare const formSubmissionFactsReader: PluginRecordFactsReader;