@aglyn/plugins-forms 1.0.0-beta.290 → 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
|
@@ -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
|
+
*/
|
|
17
|
+
import type { TenantEmailEntry } from '@aglyn/shared-util-email';
|
|
18
|
+
/** The catalog key a form's confirmation is sent and designed under (AGL-4098). */
|
|
19
|
+
export declare const FORM_CONFIRMATION_EMAIL_KEY = "form-confirmation";
|
|
20
|
+
/**
|
|
21
|
+
* The emails a site sends through Forms (AGL-4098).
|
|
22
|
+
*
|
|
23
|
+
* Declared here, by the plugin that sends them, and compiled into the
|
|
24
|
+
* platform's tenant email catalog (`TENANT_EMAILS` in
|
|
25
|
+
* `@aglyn/shared-util-email`) by `tools/scripts/generate-plugin-manifests.mjs`:
|
|
26
|
+
* the catalog's readers include the send path, which loads no plugin code.
|
|
27
|
+
* Regenerate after changing an entry; `--check` refuses a stale catalog.
|
|
28
|
+
*/
|
|
29
|
+
export declare function formsTenantEmails(): readonly TenantEmailEntry[];
|
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
*/ /** The catalog key a form's confirmation is sent and designed under (AGL-4098). */ export const FORM_CONFIRMATION_EMAIL_KEY = 'form-confirmation';
|
|
17
|
+
/**
|
|
18
|
+
* The emails a site sends through Forms (AGL-4098).
|
|
19
|
+
*
|
|
20
|
+
* Declared here, by the plugin that sends them, and compiled into the
|
|
21
|
+
* platform's tenant email catalog (`TENANT_EMAILS` in
|
|
22
|
+
* `@aglyn/shared-util-email`) by `tools/scripts/generate-plugin-manifests.mjs`:
|
|
23
|
+
* the catalog's readers include the send path, which loads no plugin code.
|
|
24
|
+
* Regenerate after changing an entry; `--check` refuses a stale catalog.
|
|
25
|
+
*/ export function formsTenantEmails() {
|
|
26
|
+
return [
|
|
27
|
+
{
|
|
28
|
+
// The person who sent a form, told it arrived: what they sent, what
|
|
29
|
+
// happens next and how to reach the business. Sent only for a form set
|
|
30
|
+
// to "Email the person a confirmation" (on by default for a request).
|
|
31
|
+
// It starts the email conversation the business's answer — a quote
|
|
32
|
+
// started from the request — later replies into. Every token is
|
|
33
|
+
// composed per send by `utils/form-confirmation-content.ts`.
|
|
34
|
+
key: FORM_CONFIRMATION_EMAIL_KEY,
|
|
35
|
+
name: 'Form confirmation',
|
|
36
|
+
description: 'Sent to the person who filled in a form, when the form is set to email ' + 'them a confirmation: what they sent, the files they attached, what ' + 'happens next and how to reach you. Your reply, such as a quote, ' + 'arrives in the same conversation.',
|
|
37
|
+
pluginId: 'forms',
|
|
38
|
+
plugin: 'Forms',
|
|
39
|
+
control: 'besigner',
|
|
40
|
+
defaultSubject: '{{form.subject}}',
|
|
41
|
+
mergeTokens: [
|
|
42
|
+
{
|
|
43
|
+
name: 'form.subject',
|
|
44
|
+
description: 'The subject: what they sent, to whom',
|
|
45
|
+
sample: 'We got your quote request — Northwind Signs'
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: 'form.name',
|
|
49
|
+
description: 'The form’s name',
|
|
50
|
+
sample: 'Request a quote'
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'form.heading',
|
|
54
|
+
description: '“We got your request” for a request, else “Thanks, we got your message”',
|
|
55
|
+
sample: 'We got your request'
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: 'form.intro',
|
|
59
|
+
description: 'One sentence on what this email is',
|
|
60
|
+
sample: 'Thanks for asking Northwind Signs for a quote. Here is a copy of what you sent.'
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: 'form.answers',
|
|
64
|
+
description: 'Their answers, one per line, under the form’s own labels',
|
|
65
|
+
sample: 'Name: Jane Doe\nProduct: Vinyl banner — 3 × 6 ft / Matte\nDetails: Two banners for the spring fair.'
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: 'form.files',
|
|
69
|
+
description: 'The files they attached, by name; empty when there were none',
|
|
70
|
+
sample: 'Files you sent: logo.ai, banner-sketch.pdf'
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: 'form.nextStep',
|
|
74
|
+
description: 'What happens next',
|
|
75
|
+
sample: 'Northwind Signs will look over your request and email you a quote. Reply to this email if anything changes.'
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: 'business.contact',
|
|
79
|
+
description: 'How to reach the business beyond a reply: its contact email, and its phone when it lists one',
|
|
80
|
+
sample: 'You can also reach Northwind Signs at hello@northwind.example or 555-0100.'
|
|
81
|
+
}
|
|
82
|
+
],
|
|
83
|
+
defaultBody: [
|
|
84
|
+
{
|
|
85
|
+
block: 'text',
|
|
86
|
+
text: '{{host.businessName}} · {{form.name}}',
|
|
87
|
+
variant: 'eyebrow'
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
block: 'text',
|
|
91
|
+
text: '{{form.heading}}',
|
|
92
|
+
variant: 'heading'
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
block: 'text',
|
|
96
|
+
text: '{{form.intro}}',
|
|
97
|
+
variant: 'body'
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
block: 'text',
|
|
101
|
+
text: '{{form.answers}}',
|
|
102
|
+
variant: 'details'
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
block: 'text',
|
|
106
|
+
text: '{{form.files}}',
|
|
107
|
+
variant: 'caption'
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
block: 'text',
|
|
111
|
+
text: '{{form.nextStep}}',
|
|
112
|
+
variant: 'body'
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
block: 'text',
|
|
116
|
+
text: '{{business.contact}}',
|
|
117
|
+
variant: 'caption'
|
|
118
|
+
}
|
|
119
|
+
],
|
|
120
|
+
footerReason: 'You’re receiving this because you sent a form on the {{host.businessName}} website.'
|
|
121
|
+
}
|
|
122
|
+
];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
//# sourceMappingURL=tenant-emails.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../libs/plugins/forms/src/lib/tenant-emails.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 { TenantEmailEntry } from '@aglyn/shared-util-email'\n\n/** The catalog key a form's confirmation is sent and designed under (AGL-4098). */\nexport const FORM_CONFIRMATION_EMAIL_KEY = 'form-confirmation'\n\n/**\n * The emails a site sends through Forms (AGL-4098).\n *\n * Declared here, by the plugin that sends them, and compiled into the\n * platform's tenant email catalog (`TENANT_EMAILS` in\n * `@aglyn/shared-util-email`) by `tools/scripts/generate-plugin-manifests.mjs`:\n * the catalog's readers include the send path, which loads no plugin code.\n * Regenerate after changing an entry; `--check` refuses a stale catalog.\n */\nexport function formsTenantEmails(): readonly TenantEmailEntry[] {\n return [\n {\n // The person who sent a form, told it arrived: what they sent, what\n // happens next and how to reach the business. Sent only for a form set\n // to \"Email the person a confirmation\" (on by default for a request).\n // It starts the email conversation the business's answer — a quote\n // started from the request — later replies into. Every token is\n // composed per send by `utils/form-confirmation-content.ts`.\n key: FORM_CONFIRMATION_EMAIL_KEY,\n name: 'Form confirmation',\n description:\n 'Sent to the person who filled in a form, when the form is set to email ' +\n 'them a confirmation: what they sent, the files they attached, what ' +\n 'happens next and how to reach you. Your reply, such as a quote, ' +\n 'arrives in the same conversation.',\n pluginId: 'forms',\n plugin: 'Forms',\n control: 'besigner',\n defaultSubject: '{{form.subject}}',\n mergeTokens: [\n {\n name: 'form.subject',\n description: 'The subject: what they sent, to whom',\n sample: 'We got your quote request — Northwind Signs',\n },\n { name: 'form.name', description: 'The form’s name', sample: 'Request a quote' },\n {\n name: 'form.heading',\n description: '“We got your request” for a request, else “Thanks, we got your message”',\n sample: 'We got your request',\n },\n {\n name: 'form.intro',\n description: 'One sentence on what this email is',\n sample: 'Thanks for asking Northwind Signs for a quote. Here is a copy of what you sent.',\n },\n {\n name: 'form.answers',\n description: 'Their answers, one per line, under the form’s own labels',\n sample: 'Name: Jane Doe\\nProduct: Vinyl banner — 3 × 6 ft / Matte\\nDetails: Two banners for the spring fair.',\n },\n {\n name: 'form.files',\n description: 'The files they attached, by name; empty when there were none',\n sample: 'Files you sent: logo.ai, banner-sketch.pdf',\n },\n {\n name: 'form.nextStep',\n description: 'What happens next',\n sample: 'Northwind Signs will look over your request and email you a quote. Reply to this email if anything changes.',\n },\n {\n name: 'business.contact',\n description: 'How to reach the business beyond a reply: its contact email, and its phone when it lists one',\n sample: 'You can also reach Northwind Signs at hello@northwind.example or 555-0100.',\n },\n ],\n defaultBody: [\n { block: 'text', text: '{{host.businessName}} · {{form.name}}', variant: 'eyebrow' },\n { block: 'text', text: '{{form.heading}}', variant: 'heading' },\n { block: 'text', text: '{{form.intro}}', variant: 'body' },\n { block: 'text', text: '{{form.answers}}', variant: 'details' },\n { block: 'text', text: '{{form.files}}', variant: 'caption' },\n { block: 'text', text: '{{form.nextStep}}', variant: 'body' },\n { block: 'text', text: '{{business.contact}}', variant: 'caption' },\n ],\n footerReason: 'You’re receiving this because you sent a form on the {{host.businessName}} website.',\n },\n ]\n}\n"],"names":["FORM_CONFIRMATION_EMAIL_KEY","formsTenantEmails","key","name","description","pluginId","plugin","control","defaultSubject","mergeTokens","sample","defaultBody","block","text","variant","footerReason"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAID,iFAAiF,GACjF,OAAO,MAAMA,8BAA8B,oBAAmB;AAE9D;;;;;;;;CAQC,GACD,OAAO,SAASC;IACd,OAAO;QACL;YACE,oEAAoE;YACpE,uEAAuE;YACvE,sEAAsE;YACtE,mEAAmE;YACnE,gEAAgE;YAChE,6DAA6D;YAC7DC,KAAKF;YACLG,MAAM;YACNC,aACE,4EACA,wEACA,qEACA;YACFC,UAAU;YACVC,QAAQ;YACRC,SAAS;YACTC,gBAAgB;YAChBC,aAAa;gBACX;oBACEN,MAAM;oBACNC,aAAa;oBACbM,QAAQ;gBACV;gBACA;oBAAEP,MAAM;oBAAaC,aAAa;oBAAmBM,QAAQ;gBAAkB;gBAC/E;oBACEP,MAAM;oBACNC,aAAa;oBACbM,QAAQ;gBACV;gBACA;oBACEP,MAAM;oBACNC,aAAa;oBACbM,QAAQ;gBACV;gBACA;oBACEP,MAAM;oBACNC,aAAa;oBACbM,QAAQ;gBACV;gBACA;oBACEP,MAAM;oBACNC,aAAa;oBACbM,QAAQ;gBACV;gBACA;oBACEP,MAAM;oBACNC,aAAa;oBACbM,QAAQ;gBACV;gBACA;oBACEP,MAAM;oBACNC,aAAa;oBACbM,QAAQ;gBACV;aACD;YACDC,aAAa;gBACX;oBAAEC,OAAO;oBAAQC,MAAM;oBAAyCC,SAAS;gBAAU;gBACnF;oBAAEF,OAAO;oBAAQC,MAAM;oBAAoBC,SAAS;gBAAU;gBAC9D;oBAAEF,OAAO;oBAAQC,MAAM;oBAAkBC,SAAS;gBAAO;gBACzD;oBAAEF,OAAO;oBAAQC,MAAM;oBAAoBC,SAAS;gBAAU;gBAC9D;oBAAEF,OAAO;oBAAQC,MAAM;oBAAkBC,SAAS;gBAAU;gBAC5D;oBAAEF,OAAO;oBAAQC,MAAM;oBAAqBC,SAAS;gBAAO;gBAC5D;oBAAEF,OAAO;oBAAQC,MAAM;oBAAwBC,SAAS;gBAAU;aACnE;YACDC,cAAc;QAChB;KACD;AACH"}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
* A Firestore stand-in for this plugin's specs (AGL-4098): documents by full
|
|
19
|
+
* path in one map, the reads and writes the request routes make, a
|
|
20
|
+
* transaction that applies its writes when its body resolves, and a
|
|
21
|
+
* collection-group query on one field. Test-only.
|
|
22
|
+
*/
|
|
23
|
+
export interface StandInFirestore {
|
|
24
|
+
docs: Map<string, Record<string, any>>;
|
|
25
|
+
firestore: FirebaseFirestore.Firestore;
|
|
26
|
+
}
|
|
27
|
+
export declare function standInFirestore(seed?: Record<string, Record<string, any>>): StandInFirestore;
|
|
@@ -0,0 +1,128 @@
|
|
|
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
|
+
* A Firestore stand-in for this plugin's specs (AGL-4098): documents by full
|
|
18
|
+
* path in one map, the reads and writes the request routes make, a
|
|
19
|
+
* transaction that applies its writes when its body resolves, and a
|
|
20
|
+
* collection-group query on one field. Test-only.
|
|
21
|
+
*/ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
22
|
+
const merge = (base, patch)=>{
|
|
23
|
+
const next = _extends({}, base != null ? base : {});
|
|
24
|
+
for (const [key, value] of Object.entries(patch)){
|
|
25
|
+
next[key] = value && typeof value === 'object' && !Array.isArray(value) && next[key] && typeof next[key] === 'object' ? merge(next[key], value) : value;
|
|
26
|
+
}
|
|
27
|
+
return next;
|
|
28
|
+
};
|
|
29
|
+
export function standInFirestore(seed = {}) {
|
|
30
|
+
const docs = new Map(Object.entries(seed));
|
|
31
|
+
const snapshot = (path)=>{
|
|
32
|
+
const data = docs.get(path);
|
|
33
|
+
return {
|
|
34
|
+
id: path.split('/').pop(),
|
|
35
|
+
exists: data !== undefined,
|
|
36
|
+
ref: doc(path),
|
|
37
|
+
data: ()=>data ? _extends({}, data) : undefined,
|
|
38
|
+
get: (field)=>data == null ? void 0 : data[field]
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
function doc(path) {
|
|
42
|
+
return {
|
|
43
|
+
id: path.split('/').pop(),
|
|
44
|
+
path,
|
|
45
|
+
get: async ()=>snapshot(path),
|
|
46
|
+
set: async (data, options)=>{
|
|
47
|
+
docs.set(path, (options == null ? void 0 : options.merge) ? merge(docs.get(path), data) : _extends({}, data));
|
|
48
|
+
},
|
|
49
|
+
create: async (data)=>{
|
|
50
|
+
if (docs.has(path)) throw Object.assign(new Error('ALREADY_EXISTS'), {
|
|
51
|
+
code: 6
|
|
52
|
+
});
|
|
53
|
+
docs.set(path, _extends({}, data));
|
|
54
|
+
},
|
|
55
|
+
update: async (data)=>{
|
|
56
|
+
if (!docs.has(path)) throw Object.assign(new Error('NOT_FOUND'), {
|
|
57
|
+
code: 5
|
|
58
|
+
});
|
|
59
|
+
docs.set(path, _extends({}, docs.get(path), data));
|
|
60
|
+
},
|
|
61
|
+
delete: async ()=>void docs.delete(path),
|
|
62
|
+
collection: (name)=>collection(`${path}/${name}`)
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
let auto = 0;
|
|
66
|
+
function collection(path) {
|
|
67
|
+
return {
|
|
68
|
+
doc: (id)=>doc(`${path}/${id != null ? id : `auto-${++auto}`}`),
|
|
69
|
+
add: async (data)=>{
|
|
70
|
+
const ref = doc(`${path}/auto-${++auto}`);
|
|
71
|
+
docs.set(ref.path, _extends({}, data));
|
|
72
|
+
return ref;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const firestore = {
|
|
77
|
+
collection: (name)=>collection(name),
|
|
78
|
+
collectionGroup: (name)=>{
|
|
79
|
+
const filters = [];
|
|
80
|
+
let max = Infinity;
|
|
81
|
+
let order = null;
|
|
82
|
+
const query = {
|
|
83
|
+
where: (field, op, value)=>{
|
|
84
|
+
filters.push((data)=>op === '<=' ? data[field] <= value : op === '==' ? data[field] === value : false);
|
|
85
|
+
return query;
|
|
86
|
+
},
|
|
87
|
+
orderBy: (field)=>{
|
|
88
|
+
order = field;
|
|
89
|
+
return query;
|
|
90
|
+
},
|
|
91
|
+
limit: (count)=>{
|
|
92
|
+
max = count;
|
|
93
|
+
return query;
|
|
94
|
+
},
|
|
95
|
+
get: async ()=>{
|
|
96
|
+
const matches = [
|
|
97
|
+
...docs.keys()
|
|
98
|
+
].filter((path)=>path.split('/').slice(-2, -1)[0] === name).filter((path)=>filters.every((filter)=>filter(docs.get(path)))).sort((a, b)=>{
|
|
99
|
+
var _ref, _ref1;
|
|
100
|
+
var _docs_get, _docs_get1;
|
|
101
|
+
return order ? Number((_ref = (_docs_get = docs.get(a)) == null ? void 0 : _docs_get[order]) != null ? _ref : 0) - Number((_ref1 = (_docs_get1 = docs.get(b)) == null ? void 0 : _docs_get1[order]) != null ? _ref1 : 0) : 0;
|
|
102
|
+
}).slice(0, max);
|
|
103
|
+
return {
|
|
104
|
+
empty: matches.length === 0,
|
|
105
|
+
size: matches.length,
|
|
106
|
+
docs: matches.map(snapshot)
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
return query;
|
|
111
|
+
},
|
|
112
|
+
runTransaction: async (body)=>{
|
|
113
|
+
const writes = [];
|
|
114
|
+
const answer = await body({
|
|
115
|
+
get: async (ref)=>snapshot(ref.path),
|
|
116
|
+
set: (ref, data, options)=>writes.push(()=>docs.set(ref.path, (options == null ? void 0 : options.merge) ? merge(docs.get(ref.path), data) : _extends({}, data)))
|
|
117
|
+
});
|
|
118
|
+
writes.forEach((write)=>write());
|
|
119
|
+
return answer;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
return {
|
|
123
|
+
docs,
|
|
124
|
+
firestore: firestore
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
//# sourceMappingURL=stand-in-firestore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/forms/src/lib/testing/stand-in-firestore.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/**\n * A Firestore stand-in for this plugin's specs (AGL-4098): documents by full\n * path in one map, the reads and writes the request routes make, a\n * transaction that applies its writes when its body resolves, and a\n * collection-group query on one field. Test-only.\n */\nexport interface StandInFirestore {\n docs: Map<string, Record<string, any>>\n firestore: FirebaseFirestore.Firestore\n}\n\nconst merge = (base: Record<string, any> | undefined, patch: Record<string, any>) => {\n const next: Record<string, any> = { ...(base ?? {}) }\n for (const [key, value] of Object.entries(patch)) {\n next[key] =\n value && typeof value === 'object' && !Array.isArray(value) && next[key] && typeof next[key] === 'object'\n ? merge(next[key], value)\n : value\n }\n return next\n}\n\nexport function standInFirestore(seed: Record<string, Record<string, any>> = {}): StandInFirestore {\n const docs = new Map<string, Record<string, any>>(Object.entries(seed))\n const snapshot = (path: string) => {\n const data = docs.get(path)\n return {\n id: path.split('/').pop() as string,\n exists: data !== undefined,\n ref: doc(path),\n data: () => (data ? { ...data } : undefined),\n get: (field: string) => data?.[field],\n }\n }\n function doc(path: string): any {\n return {\n id: path.split('/').pop(),\n path,\n get: async () => snapshot(path),\n set: async (data: Record<string, any>, options?: { merge?: boolean }) => {\n docs.set(path, options?.merge ? merge(docs.get(path), data) : { ...data })\n },\n create: async (data: Record<string, any>) => {\n if (docs.has(path)) throw Object.assign(new Error('ALREADY_EXISTS'), { code: 6 })\n docs.set(path, { ...data })\n },\n update: async (data: Record<string, any>) => {\n if (!docs.has(path)) throw Object.assign(new Error('NOT_FOUND'), { code: 5 })\n docs.set(path, { ...docs.get(path), ...data })\n },\n delete: async () => void docs.delete(path),\n collection: (name: string) => collection(`${path}/${name}`),\n }\n }\n let auto = 0\n function collection(path: string): any {\n return {\n doc: (id?: string) => doc(`${path}/${id ?? `auto-${++auto}`}`),\n add: async (data: Record<string, any>) => {\n const ref = doc(`${path}/auto-${++auto}`)\n docs.set(ref.path, { ...data })\n return ref\n },\n }\n }\n const firestore = {\n collection: (name: string) => collection(name),\n collectionGroup: (name: string) => {\n const filters: Array<(data: Record<string, any>) => boolean> = []\n let max = Infinity\n let order: string | null = null\n const query: any = {\n where: (field: string, op: string, value: any) => {\n filters.push((data) => (op === '<=' ? data[field] <= value : op === '==' ? data[field] === value : false))\n return query\n },\n orderBy: (field: string) => {\n order = field\n return query\n },\n limit: (count: number) => {\n max = count\n return query\n },\n get: async () => {\n const matches = [...docs.keys()]\n .filter((path) => path.split('/').slice(-2, -1)[0] === name)\n .filter((path) => filters.every((filter) => filter(docs.get(path) as Record<string, any>)))\n .sort((a, b) => (order ? Number(docs.get(a)?.[order] ?? 0) - Number(docs.get(b)?.[order] ?? 0) : 0))\n .slice(0, max)\n return { empty: matches.length === 0, size: matches.length, docs: matches.map(snapshot) }\n },\n }\n return query\n },\n runTransaction: async <T>(body: (transaction: any) => Promise<T>): Promise<T> => {\n const writes: Array<() => void> = []\n const answer = await body({\n get: async (ref: any) => snapshot(ref.path),\n set: (ref: any, data: Record<string, any>, options?: { merge?: boolean }) =>\n writes.push(() => docs.set(ref.path, options?.merge ? merge(docs.get(ref.path), data) : { ...data })),\n })\n writes.forEach((write) => write())\n return answer\n },\n }\n return { docs, firestore: firestore as unknown as FirebaseFirestore.Firestore }\n}\n"],"names":["merge","base","patch","next","key","value","Object","entries","Array","isArray","standInFirestore","seed","docs","Map","snapshot","path","data","get","id","split","pop","exists","undefined","ref","doc","field","set","options","create","has","assign","Error","code","update","delete","collection","name","auto","add","firestore","collectionGroup","filters","max","Infinity","order","query","where","op","push","orderBy","limit","count","matches","keys","filter","slice","every","sort","a","b","Number","empty","length","size","map","runTransaction","body","writes","answer","forEach","write"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;CAKC;AAMD,MAAMA,QAAQ,CAACC,MAAuCC;IACpD,MAAMC,OAA4B,aAAMF,eAAAA,OAAQ,CAAC;IACjD,KAAK,MAAM,CAACG,KAAKC,MAAM,IAAIC,OAAOC,OAAO,CAACL,OAAQ;QAChDC,IAAI,CAACC,IAAI,GACPC,SAAS,OAAOA,UAAU,YAAY,CAACG,MAAMC,OAAO,CAACJ,UAAUF,IAAI,CAAC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AOhD,YAAAA,KAAKK,GAAG,CAACyC,uBAAT9C,SAAa,CAACgC,MAAM,mBAAI,KAAKgB,iBAAOhD,aAAAA,KAAKK,GAAG,CAAC0C,uBAAT/C,UAAa,CAACgC,MAAM,oBAAI,KAAK;uBAChGW,KAAK,CAAC,GAAGb;oBACZ,OAAO;wBAAEmB,OAAOT,QAAQU,MAAM,KAAK;wBAAGC,MAAMX,QAAQU,MAAM;wBAAElD,MAAMwC,QAAQY,GAAG,CAAClD;oBAAU;gBAC1F;YACF;YACA,OAAO+B;QACT;QACAoB,gBAAgB,OAAUC;YACxB,MAAMC,SAA4B,EAAE;YACpC,MAAMC,SAAS,MAAMF,KAAK;gBACxBjD,KAAK,OAAOM,MAAaT,SAASS,IAAIR,IAAI;gBAC1CW,KAAK,CAACH,KAAUP,MAA2BW,UACzCwC,OAAOnB,IAAI,CAAC,IAAMpC,KAAKc,GAAG,CAACH,IAAIR,IAAI,EAAEY,CAAAA,2BAAAA,QAAS3B,KAAK,IAAGA,MAAMY,KAAKK,GAAG,CAACM,IAAIR,IAAI,GAAGC,QAAQ,aAAKA;YACjG;YACAmD,OAAOE,OAAO,CAAC,CAACC,QAAUA;YAC1B,OAAOF;QACT;IACF;IACA,OAAO;QAAExD;QAAM2B,WAAWA;IAAoD;AAChF"}
|
|
@@ -0,0 +1,48 @@
|
|
|
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, type FormRequest } from '@aglyn/aglyn/app-utils/forms';
|
|
18
|
+
/** The most answers copied into the email; a long survey keeps its first ones. */
|
|
19
|
+
export declare const FORM_CONFIRMATION_MAX_ANSWERS = 12;
|
|
20
|
+
/** The most characters of one answer the email repeats. */
|
|
21
|
+
export declare const FORM_CONFIRMATION_MAX_ANSWER_CHARS = 300;
|
|
22
|
+
export interface FormConfirmationInput {
|
|
23
|
+
businessName: string;
|
|
24
|
+
formName: string;
|
|
25
|
+
request: FormRequest | null;
|
|
26
|
+
/** The answers as stored, in the order the form posted them. */
|
|
27
|
+
answers: Readonly<Record<string, string>>;
|
|
28
|
+
/** The form's declared fields, for their labels and types. */
|
|
29
|
+
decls: readonly FormFieldDecl[];
|
|
30
|
+
/** The field the form names as its opt-in, when it names one. */
|
|
31
|
+
consentFieldName?: string | null;
|
|
32
|
+
/** The names of the files they attached, in order. */
|
|
33
|
+
fileNames: readonly string[];
|
|
34
|
+
/** The site's contact email (its listing's, else its support address). */
|
|
35
|
+
contactEmail: string | null;
|
|
36
|
+
/** The phone the site's listing gives, when it gives one. */
|
|
37
|
+
contactPhone: string | null;
|
|
38
|
+
}
|
|
39
|
+
export interface FormConfirmationContent {
|
|
40
|
+
subject: string;
|
|
41
|
+
tokens: Record<string, string>;
|
|
42
|
+
/** The plain-text twin, for a send with no design to render. */
|
|
43
|
+
text: string;
|
|
44
|
+
}
|
|
45
|
+
/** The answers worth a copy, under the form's labels. */
|
|
46
|
+
export declare function formConfirmationAnswers(input: Pick<FormConfirmationInput, 'answers' | 'decls' | 'consentFieldName'>): string[];
|
|
47
|
+
/** The confirmation's tokens and its plain-text twin. */
|
|
48
|
+
export declare function formConfirmationContent(input: FormConfirmationInput): FormConfirmationContent;
|
|
@@ -0,0 +1,100 @@
|
|
|
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 { isMarketingConsentFieldName } from "@aglyn/aglyn/app-utils/forms";
|
|
17
|
+
/*==========================================
|
|
18
|
+
* WHAT A FORM'S CONFIRMATION SAYS (AGL-4098).
|
|
19
|
+
*
|
|
20
|
+
* The `form-confirmation` catalog email's tokens, composed per send: a
|
|
21
|
+
* heading and a sentence on what this is (a request, or a message), a copy of
|
|
22
|
+
* the answers under the form's own labels, the files by name, what happens
|
|
23
|
+
* next, and how to reach the business beyond a reply. The opt-in box and the
|
|
24
|
+
* file fields' own lines are left out of the answers: a tick says nothing
|
|
25
|
+
* worth a copy, and the files are named on their own line. Links typed into
|
|
26
|
+
* an answer are left out too ({@link TYPED_LINK}).
|
|
27
|
+
*
|
|
28
|
+
* Pure: the submit route and the sample renders call the same function.
|
|
29
|
+
*=========================================*/ /** The most answers copied into the email; a long survey keeps its first ones. */ export const FORM_CONFIRMATION_MAX_ANSWERS = 12;
|
|
30
|
+
/** The most characters of one answer the email repeats. */ export const FORM_CONFIRMATION_MAX_ANSWER_CHARS = 300;
|
|
31
|
+
/** The most file names listed before "and N more". */ const MAX_NAMED_FILES = 6;
|
|
32
|
+
/**
|
|
33
|
+
* Links typed into a form, as the confirmation leaves them out. Whoever sends
|
|
34
|
+
* a form chooses the address it goes to, so a copy that kept a link would let
|
|
35
|
+
* a stranger mail anybody a link of their choosing from the site's domain.
|
|
36
|
+
*/ const TYPED_LINK = /\b(?:https?:\/\/|www\.)\S+/gi;
|
|
37
|
+
/** One answer as a line of the details panel: on one line, links out, and not too long. */ function answerLine(label, value) {
|
|
38
|
+
const flat = value.replace(TYPED_LINK, '[link]').replace(/\s+/g, ' ').trim();
|
|
39
|
+
const shown = flat.length > FORM_CONFIRMATION_MAX_ANSWER_CHARS ? `${flat.slice(0, FORM_CONFIRMATION_MAX_ANSWER_CHARS - 1).trimEnd()}…` : flat;
|
|
40
|
+
return `${label}: ${shown}`;
|
|
41
|
+
}
|
|
42
|
+
/** The answers worth a copy, under the form's labels. */ export function formConfirmationAnswers(input) {
|
|
43
|
+
const lines = [];
|
|
44
|
+
for (const [key, value] of Object.entries(input.answers)){
|
|
45
|
+
if (lines.length >= FORM_CONFIRMATION_MAX_ANSWERS) break;
|
|
46
|
+
if (key === 'formId' || !String(value != null ? value : '').trim()) continue;
|
|
47
|
+
const decl = input.decls.find((entry)=>(entry == null ? void 0 : entry.fieldName) === key);
|
|
48
|
+
if ((decl == null ? void 0 : decl.fieldType) === 'file') continue;
|
|
49
|
+
if (key === input.consentFieldName || (decl == null ? void 0 : decl.role) === 'consent' || isMarketingConsentFieldName(key)) continue;
|
|
50
|
+
const label = typeof (decl == null ? void 0 : decl.label) === 'string' && decl.label.trim() || key;
|
|
51
|
+
lines.push(answerLine(label, String(value)));
|
|
52
|
+
}
|
|
53
|
+
return lines;
|
|
54
|
+
}
|
|
55
|
+
/** `logo.ai, sketch.pdf and 2 more`. */ function namedFiles(names) {
|
|
56
|
+
const shown = names.slice(0, MAX_NAMED_FILES);
|
|
57
|
+
const more = names.length - shown.length;
|
|
58
|
+
return more > 0 ? `${shown.join(', ')} and ${more} more` : shown.join(', ');
|
|
59
|
+
}
|
|
60
|
+
/** The confirmation's tokens and its plain-text twin. */ export function formConfirmationContent(input) {
|
|
61
|
+
var _input_request;
|
|
62
|
+
const business = input.businessName.trim() || 'the business';
|
|
63
|
+
const quote = ((_input_request = input.request) == null ? void 0 : _input_request.kind) === 'quote';
|
|
64
|
+
const subject = (quote ? `We got your quote request — ${business}` : `We got your message — ${business}`).slice(0, 200);
|
|
65
|
+
const heading = quote ? 'We got your request' : 'Thanks, we got your message';
|
|
66
|
+
const intro = quote ? `Thanks for asking ${business} for a quote. Here is a copy of what you sent.` : `Thanks for getting in touch with ${business}. Here is a copy of what you sent.`;
|
|
67
|
+
const answers = formConfirmationAnswers(input);
|
|
68
|
+
const files = input.fileNames.length ? `${input.fileNames.length === 1 ? 'The file you sent' : 'Files you sent'}: ${namedFiles(input.fileNames)}` : '';
|
|
69
|
+
const nextStep = quote ? `${business} will look over your request and email you a quote. Reply to this email if anything changes or you want to add something.` : `${business} will get back to you soon. Reply to this email if you want to add anything.`;
|
|
70
|
+
const ways = [
|
|
71
|
+
input.contactEmail,
|
|
72
|
+
input.contactPhone
|
|
73
|
+
].map((entry)=>String(entry != null ? entry : '').trim()).filter(Boolean);
|
|
74
|
+
const contact = ways.length ? `You can also reach ${business} at ${ways.join(' or ')}.` : '';
|
|
75
|
+
const tokens = {
|
|
76
|
+
'form.subject': subject,
|
|
77
|
+
'form.name': input.formName.trim() || 'Form',
|
|
78
|
+
'form.heading': heading,
|
|
79
|
+
'form.intro': intro,
|
|
80
|
+
'form.answers': answers.join('\n'),
|
|
81
|
+
'form.files': files,
|
|
82
|
+
'form.nextStep': nextStep,
|
|
83
|
+
'business.contact': contact
|
|
84
|
+
};
|
|
85
|
+
const text = [
|
|
86
|
+
heading,
|
|
87
|
+
intro,
|
|
88
|
+
answers.join('\n'),
|
|
89
|
+
files,
|
|
90
|
+
nextStep,
|
|
91
|
+
contact
|
|
92
|
+
].filter(Boolean).join('\n\n');
|
|
93
|
+
return {
|
|
94
|
+
subject,
|
|
95
|
+
tokens,
|
|
96
|
+
text
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
//# sourceMappingURL=form-confirmation-content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/forms/src/lib/utils/form-confirmation-content.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 isMarketingConsentFieldName,\n type FormFieldDecl,\n type FormRequest,\n} from '@aglyn/aglyn/app-utils/forms'\n\n/*==========================================\n * WHAT A FORM'S CONFIRMATION SAYS (AGL-4098).\n *\n * The `form-confirmation` catalog email's tokens, composed per send: a\n * heading and a sentence on what this is (a request, or a message), a copy of\n * the answers under the form's own labels, the files by name, what happens\n * next, and how to reach the business beyond a reply. The opt-in box and the\n * file fields' own lines are left out of the answers: a tick says nothing\n * worth a copy, and the files are named on their own line. Links typed into\n * an answer are left out too ({@link TYPED_LINK}).\n *\n * Pure: the submit route and the sample renders call the same function.\n *=========================================*/\n\n/** The most answers copied into the email; a long survey keeps its first ones. */\nexport const FORM_CONFIRMATION_MAX_ANSWERS = 12\n\n/** The most characters of one answer the email repeats. */\nexport const FORM_CONFIRMATION_MAX_ANSWER_CHARS = 300\n\n/** The most file names listed before \"and N more\". */\nconst MAX_NAMED_FILES = 6\n\nexport interface FormConfirmationInput {\n businessName: string\n formName: string\n request: FormRequest | null\n /** The answers as stored, in the order the form posted them. */\n answers: Readonly<Record<string, string>>\n /** The form's declared fields, for their labels and types. */\n decls: readonly FormFieldDecl[]\n /** The field the form names as its opt-in, when it names one. */\n consentFieldName?: string | null\n /** The names of the files they attached, in order. */\n fileNames: readonly string[]\n /** The site's contact email (its listing's, else its support address). */\n contactEmail: string | null\n /** The phone the site's listing gives, when it gives one. */\n contactPhone: string | null\n}\n\nexport interface FormConfirmationContent {\n subject: string\n tokens: Record<string, string>\n /** The plain-text twin, for a send with no design to render. */\n text: string\n}\n\n/**\n * Links typed into a form, as the confirmation leaves them out. Whoever sends\n * a form chooses the address it goes to, so a copy that kept a link would let\n * a stranger mail anybody a link of their choosing from the site's domain.\n */\nconst TYPED_LINK = /\\b(?:https?:\\/\\/|www\\.)\\S+/gi\n\n/** One answer as a line of the details panel: on one line, links out, and not too long. */\nfunction answerLine(label: string, value: string): string {\n const flat = value.replace(TYPED_LINK, '[link]').replace(/\\s+/g, ' ').trim()\n const shown =\n flat.length > FORM_CONFIRMATION_MAX_ANSWER_CHARS\n ? `${flat.slice(0, FORM_CONFIRMATION_MAX_ANSWER_CHARS - 1).trimEnd()}…`\n : flat\n return `${label}: ${shown}`\n}\n\n/** The answers worth a copy, under the form's labels. */\nexport function formConfirmationAnswers(input: Pick<FormConfirmationInput, 'answers' | 'decls' | 'consentFieldName'>): string[] {\n const lines: string[] = []\n for (const [key, value] of Object.entries(input.answers)) {\n if (lines.length >= FORM_CONFIRMATION_MAX_ANSWERS) break\n if (key === 'formId' || !String(value ?? '').trim()) continue\n const decl = input.decls.find((entry) => entry?.fieldName === key)\n if (decl?.fieldType === 'file') continue\n if (key === input.consentFieldName || decl?.role === 'consent' || isMarketingConsentFieldName(key)) continue\n const label = (typeof decl?.label === 'string' && decl.label.trim()) || key\n lines.push(answerLine(label, String(value)))\n }\n return lines\n}\n\n/** `logo.ai, sketch.pdf and 2 more`. */\nfunction namedFiles(names: readonly string[]): string {\n const shown = names.slice(0, MAX_NAMED_FILES)\n const more = names.length - shown.length\n return more > 0 ? `${shown.join(', ')} and ${more} more` : shown.join(', ')\n}\n\n/** The confirmation's tokens and its plain-text twin. */\nexport function formConfirmationContent(input: FormConfirmationInput): FormConfirmationContent {\n const business = input.businessName.trim() || 'the business'\n const quote = input.request?.kind === 'quote'\n const subject = (quote ? `We got your quote request — ${business}` : `We got your message — ${business}`).slice(0, 200)\n const heading = quote ? 'We got your request' : 'Thanks, we got your message'\n const intro = quote\n ? `Thanks for asking ${business} for a quote. Here is a copy of what you sent.`\n : `Thanks for getting in touch with ${business}. Here is a copy of what you sent.`\n const answers = formConfirmationAnswers(input)\n const files = input.fileNames.length\n ? `${input.fileNames.length === 1 ? 'The file you sent' : 'Files you sent'}: ${namedFiles(input.fileNames)}`\n : ''\n const nextStep = quote\n ? `${business} will look over your request and email you a quote. Reply to this email if anything changes or you want to add something.`\n : `${business} will get back to you soon. Reply to this email if you want to add anything.`\n const ways = [input.contactEmail, input.contactPhone].map((entry) => String(entry ?? '').trim()).filter(Boolean)\n const contact = ways.length ? `You can also reach ${business} at ${ways.join(' or ')}.` : ''\n const tokens: Record<string, string> = {\n 'form.subject': subject,\n 'form.name': input.formName.trim() || 'Form',\n 'form.heading': heading,\n 'form.intro': intro,\n 'form.answers': answers.join('\\n'),\n 'form.files': files,\n 'form.nextStep': nextStep,\n 'business.contact': contact,\n }\n const text = [heading, intro, answers.join('\\n'), files, nextStep, contact].filter(Boolean).join('\\n\\n')\n return { subject, tokens, text }\n}\n"],"names":["isMarketingConsentFieldName","FORM_CONFIRMATION_MAX_ANSWERS","FORM_CONFIRMATION_MAX_ANSWER_CHARS","MAX_NAMED_FILES","TYPED_LINK","answerLine","label","value","flat","replace","trim","shown","length","slice","trimEnd","formConfirmationAnswers","input","lines","key","Object","entries","answers","String","decl","decls","find","entry","fieldName","fieldType","consentFieldName","role","push","namedFiles","names","more","join","formConfirmationContent","business","businessName","quote","request","kind","subject","heading","intro","files","fileNames","nextStep","ways","contactEmail","contactPhone","map","filter","Boolean","contact","tokens","formName","text"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,2BAA2B,QAGtB,+BAA8B;AAErC;;;;;;;;;;;;2CAY2C,GAE3C,gFAAgF,GAChF,OAAO,MAAMC,gCAAgC,GAAE;AAE/C,yDAAyD,GACzD,OAAO,MAAMC,qCAAqC,IAAG;AAEr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