@aglyn/aglyn 1.4.0 → 1.6.0
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/package.json +11 -11
- package/src/lib/app-utils/business-details.d.ts +93 -0
- package/src/lib/app-utils/business-details.js +145 -0
- package/src/lib/app-utils/business-details.js.map +1 -0
- package/src/lib/app-utils/business-profile.d.ts +20 -3
- package/src/lib/app-utils/business-profile.js +31 -7
- package/src/lib/app-utils/business-profile.js.map +1 -1
- package/src/lib/app-utils/content-authors.d.ts +2 -0
- package/src/lib/app-utils/content-authors.js.map +1 -1
- package/src/lib/app-utils/docs-help-sections.generated.js +0 -1
- package/src/lib/app-utils/docs-help-sections.generated.js.map +1 -1
- package/src/lib/app-utils/docs-help.generated.js +0 -1
- package/src/lib/app-utils/docs-help.generated.js.map +1 -1
- package/src/lib/app-utils/docs-index.generated.js +15 -15
- package/src/lib/app-utils/docs-index.generated.js.map +1 -1
- package/src/lib/app-utils/health-report.d.ts +39 -0
- package/src/lib/app-utils/health-report.js +41 -0
- package/src/lib/app-utils/health-report.js.map +1 -1
- package/src/lib/app-utils/host-tokens.d.ts +53 -11
- package/src/lib/app-utils/host-tokens.js +173 -18
- package/src/lib/app-utils/host-tokens.js.map +1 -1
- package/src/lib/app-utils/site-email-chrome.js +3 -0
- package/src/lib/app-utils/site-email-chrome.js.map +1 -1
- package/src/lib/app-utils/site-entity-json-ld.js +17 -2
- package/src/lib/app-utils/site-entity-json-ld.js.map +1 -1
- package/src/lib/app-utils/weekly-summary.d.ts +15 -4
- package/src/lib/app-utils/weekly-summary.js +76 -21
- package/src/lib/app-utils/weekly-summary.js.map +1 -1
- package/src/lib/plugin-manager/plugin-figures.d.ts +22 -2
- package/src/lib/plugin-manager/plugin-figures.js +5 -0
- package/src/lib/plugin-manager/plugin-figures.js.map +1 -1
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
+
import { type HostSeoEntity } from './content-authors';
|
|
17
18
|
/**
|
|
18
19
|
* Host variables — publisher templates that fill themselves in (AGL-1022).
|
|
19
20
|
*
|
|
@@ -80,7 +81,12 @@ export interface HostTokenSource {
|
|
|
80
81
|
logoDarkUrl?: string;
|
|
81
82
|
subdomain?: string;
|
|
82
83
|
cname?: string;
|
|
83
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* The one-block copies of the email and address, and the social links
|
|
86
|
+
* (AGL-1022). Setup → Business profile writes the email and address to `seo.entity`
|
|
87
|
+
* and mirrors them here (AGL-4136), so these are what a token reads when
|
|
88
|
+
* the entity has none: a site saved before that, or by the native apps.
|
|
89
|
+
*/
|
|
84
90
|
business?: {
|
|
85
91
|
supportEmail?: string;
|
|
86
92
|
address?: string;
|
|
@@ -89,11 +95,13 @@ export interface HostTokenSource {
|
|
|
89
95
|
url?: string;
|
|
90
96
|
}>;
|
|
91
97
|
};
|
|
98
|
+
/**
|
|
99
|
+
* The business's facts as Setup → Business profile and SEO → Local business store
|
|
100
|
+
* them (AGL-4136): the name, slogan, phone, email, structured address, the
|
|
101
|
+
* profiles it claims and the areas it serves.
|
|
102
|
+
*/
|
|
92
103
|
seo?: {
|
|
93
|
-
entity?:
|
|
94
|
-
name?: string;
|
|
95
|
-
logo?: string;
|
|
96
|
-
};
|
|
104
|
+
entity?: Pick<HostSeoEntity, 'name' | 'logo' | 'slogan' | 'email' | 'telephone' | 'address' | 'sameAs' | 'areaServed'>;
|
|
97
105
|
};
|
|
98
106
|
}
|
|
99
107
|
export interface HostTokenDefinition {
|
|
@@ -114,6 +122,37 @@ export interface HostTokenDefinition {
|
|
|
114
122
|
fallback?: (host: HostTokenSource) => string | undefined;
|
|
115
123
|
whenEmpty: HostTokenEmptyBehaviour;
|
|
116
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* A phone number as a `tel:` link (AGL-4136): everything but its digits and
|
|
127
|
+
* a leading `+` removed, so `+1 (512) 555-0100` dials `tel:+15125550100`.
|
|
128
|
+
* Nothing when the number holds no digit, so a Call button never links to a
|
|
129
|
+
* bare `tel:`.
|
|
130
|
+
*/
|
|
131
|
+
export declare function telephoneHref(phone: unknown): string | undefined;
|
|
132
|
+
/**
|
|
133
|
+
* The social networks a page can link by name (AGL-4136), each with the
|
|
134
|
+
* hostnames its profile addresses are served from. A hostname matches itself
|
|
135
|
+
* and any subdomain of itself, so `www.` and `m.` addresses are the same
|
|
136
|
+
* profile. X keeps `twitter.com`, because a link saved before the rename is
|
|
137
|
+
* still the same account.
|
|
138
|
+
*/
|
|
139
|
+
declare const SOCIAL_NETWORK_HOSTS: {
|
|
140
|
+
readonly facebook: readonly ["facebook.com", "fb.com"];
|
|
141
|
+
readonly instagram: readonly ["instagram.com"];
|
|
142
|
+
readonly x: readonly ["x.com", "twitter.com"];
|
|
143
|
+
readonly linkedin: readonly ["linkedin.com"];
|
|
144
|
+
readonly youtube: readonly ["youtube.com", "youtu.be"];
|
|
145
|
+
readonly tiktok: readonly ["tiktok.com"];
|
|
146
|
+
};
|
|
147
|
+
export type HostSocialNetwork = keyof typeof SOCIAL_NETWORK_HOSTS;
|
|
148
|
+
/**
|
|
149
|
+
* The site's profile on one network: the first of the profiles it claims
|
|
150
|
+
* (`siteProfileUrls`, the entity's `sameAs` and then Setup → Business profile's
|
|
151
|
+
* social links, https only) served from that network's hostname. Matched by
|
|
152
|
+
* HOSTNAME rather than by the link's label, because the label is free text
|
|
153
|
+
* and the address is what a visitor is sent to.
|
|
154
|
+
*/
|
|
155
|
+
export declare function siteSocialProfileUrl(host: HostTokenSource | null | undefined, network: HostSocialNetwork): string | undefined;
|
|
117
156
|
/**
|
|
118
157
|
* The closed registry.
|
|
119
158
|
*
|
|
@@ -221,12 +260,14 @@ export declare function describeHostTokens(host: HostTokenSource | null | undefi
|
|
|
221
260
|
*/
|
|
222
261
|
export declare function hostTokenMerge(host: HostTokenSource | null | undefined): Record<string, string>;
|
|
223
262
|
/**
|
|
224
|
-
* The email address a visitor writes to the business at: the one
|
|
225
|
-
*
|
|
226
|
-
* when the site has neither. One
|
|
227
|
-
*
|
|
228
|
-
* email
|
|
229
|
-
*
|
|
263
|
+
* The email address a visitor writes to the business at: the one Setup →
|
|
264
|
+
* Business saves (`seo.entity.email`), else the one-block copy a site saved
|
|
265
|
+
* before that (`business.supportEmail`). Null when the site has neither. One
|
|
266
|
+
* answer for every place that names it: the `{{host.supportEmail}}` token
|
|
267
|
+
* and so the email footer, the waiver consent, the quote and invoice PDFs,
|
|
268
|
+
* the Reply-To of the quote email (AGL-4097), and the address a refused form
|
|
269
|
+
* or sign-up offers instead (AGL-4136). Trimmed, not validated; a caller
|
|
270
|
+
* putting it in a header checks it is an address.
|
|
230
271
|
*/
|
|
231
272
|
export declare function siteContactEmail(host: {
|
|
232
273
|
seo?: {
|
|
@@ -251,3 +292,4 @@ export declare function siteContactEmail(host: {
|
|
|
251
292
|
* binding-free tree costs one `Object.entries`.
|
|
252
293
|
*/
|
|
253
294
|
export declare function resolveNodesHostTokens<T extends Record<string, any>>(nodes: T, host: HostTokenSource | null | undefined): T;
|
|
295
|
+
export {};
|
|
@@ -14,7 +14,10 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
|
14
14
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
15
|
* See the License for the specific language governing permissions and
|
|
16
16
|
* limitations under the License.
|
|
17
|
-
*/ import {
|
|
17
|
+
*/ import { structuredAddressLine } from "./business-profile.js";
|
|
18
|
+
import { siteProfileUrls } from "./content-authors.js";
|
|
19
|
+
import { hostPublicOrigin } from "./host-naming.js";
|
|
20
|
+
import { normalizeAreaServed } from "./local-business.js";
|
|
18
21
|
const trimmed = (value)=>{
|
|
19
22
|
const text = typeof value === 'string' ? value.trim() : '';
|
|
20
23
|
return text || undefined;
|
|
@@ -47,6 +50,82 @@ function logo(host) {
|
|
|
47
50
|
var _host_seo_entity, _host_seo;
|
|
48
51
|
return (_trimmed = trimmed(host.logoUrl)) != null ? _trimmed : trimmed((_host_seo = host.seo) == null ? void 0 : (_host_seo_entity = _host_seo.entity) == null ? void 0 : _host_seo_entity.logo);
|
|
49
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* A phone number as a `tel:` link (AGL-4136): everything but its digits and
|
|
55
|
+
* a leading `+` removed, so `+1 (512) 555-0100` dials `tel:+15125550100`.
|
|
56
|
+
* Nothing when the number holds no digit, so a Call button never links to a
|
|
57
|
+
* bare `tel:`.
|
|
58
|
+
*/ export function telephoneHref(phone) {
|
|
59
|
+
const text = trimmed(phone);
|
|
60
|
+
if (!text) return undefined;
|
|
61
|
+
const digits = text.replace(/\D+/g, '');
|
|
62
|
+
if (!digits) return undefined;
|
|
63
|
+
return `tel:${text.startsWith('+') ? '+' : ''}${digits}`;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The social networks a page can link by name (AGL-4136), each with the
|
|
67
|
+
* hostnames its profile addresses are served from. A hostname matches itself
|
|
68
|
+
* and any subdomain of itself, so `www.` and `m.` addresses are the same
|
|
69
|
+
* profile. X keeps `twitter.com`, because a link saved before the rename is
|
|
70
|
+
* still the same account.
|
|
71
|
+
*/ const SOCIAL_NETWORK_HOSTS = {
|
|
72
|
+
facebook: [
|
|
73
|
+
'facebook.com',
|
|
74
|
+
'fb.com'
|
|
75
|
+
],
|
|
76
|
+
instagram: [
|
|
77
|
+
'instagram.com'
|
|
78
|
+
],
|
|
79
|
+
x: [
|
|
80
|
+
'x.com',
|
|
81
|
+
'twitter.com'
|
|
82
|
+
],
|
|
83
|
+
linkedin: [
|
|
84
|
+
'linkedin.com'
|
|
85
|
+
],
|
|
86
|
+
youtube: [
|
|
87
|
+
'youtube.com',
|
|
88
|
+
'youtu.be'
|
|
89
|
+
],
|
|
90
|
+
tiktok: [
|
|
91
|
+
'tiktok.com'
|
|
92
|
+
]
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* The site's profile on one network: the first of the profiles it claims
|
|
96
|
+
* (`siteProfileUrls`, the entity's `sameAs` and then Setup → Business profile's
|
|
97
|
+
* social links, https only) served from that network's hostname. Matched by
|
|
98
|
+
* HOSTNAME rather than by the link's label, because the label is free text
|
|
99
|
+
* and the address is what a visitor is sent to.
|
|
100
|
+
*/ export function siteSocialProfileUrl(host, network) {
|
|
101
|
+
const hosts = SOCIAL_NETWORK_HOSTS[network];
|
|
102
|
+
for (const value of siteProfileUrls(host)){
|
|
103
|
+
let hostname;
|
|
104
|
+
try {
|
|
105
|
+
hostname = new URL(value).hostname.toLowerCase();
|
|
106
|
+
} catch (unused) {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (hosts.some((name)=>hostname === name || hostname.endsWith(`.${name}`))) {
|
|
110
|
+
return value;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
/** The areas served, as SEO → Local business stores and the structured data publishes them. */ function areasServed(host) {
|
|
116
|
+
var _host_seo_entity, _host_seo;
|
|
117
|
+
return normalizeAreaServed((_host_seo = host.seo) == null ? void 0 : (_host_seo_entity = _host_seo.entity) == null ? void 0 : _host_seo_entity.areaServed);
|
|
118
|
+
}
|
|
119
|
+
/** One social network's profile link as a token: a URL, dropped where the site has none. */ function socialToken(network, key, name) {
|
|
120
|
+
return {
|
|
121
|
+
key,
|
|
122
|
+
type: 'url',
|
|
123
|
+
label: `${name} link`,
|
|
124
|
+
description: `The address of the site’s ${name} profile, from Setup → Business profile.`,
|
|
125
|
+
resolve: (host)=>siteSocialProfileUrl(host, network),
|
|
126
|
+
whenEmpty: 'omit-block'
|
|
127
|
+
};
|
|
128
|
+
}
|
|
50
129
|
/**
|
|
51
130
|
* The closed registry.
|
|
52
131
|
*
|
|
@@ -58,10 +137,21 @@ function logo(host) {
|
|
|
58
137
|
key: 'businessName',
|
|
59
138
|
type: 'text',
|
|
60
139
|
label: 'Business name',
|
|
61
|
-
description: 'The site’s
|
|
140
|
+
description: 'The business name from Setup → Business profile, or the site’s name when none is set.',
|
|
62
141
|
resolve: businessName,
|
|
63
142
|
whenEmpty: 'blank'
|
|
64
143
|
},
|
|
144
|
+
slogan: {
|
|
145
|
+
key: 'slogan',
|
|
146
|
+
type: 'text',
|
|
147
|
+
label: 'Slogan',
|
|
148
|
+
description: 'A short line about the business, from Setup → Business profile.',
|
|
149
|
+
resolve: (host)=>{
|
|
150
|
+
var _host_seo_entity, _host_seo;
|
|
151
|
+
return trimmed((_host_seo = host.seo) == null ? void 0 : (_host_seo_entity = _host_seo.entity) == null ? void 0 : _host_seo_entity.slogan);
|
|
152
|
+
},
|
|
153
|
+
whenEmpty: 'blank'
|
|
154
|
+
},
|
|
65
155
|
logo: {
|
|
66
156
|
key: 'logo',
|
|
67
157
|
type: 'image',
|
|
@@ -93,14 +183,41 @@ function logo(host) {
|
|
|
93
183
|
resolve: siteUrl,
|
|
94
184
|
whenEmpty: 'blank'
|
|
95
185
|
},
|
|
96
|
-
|
|
186
|
+
phone: {
|
|
187
|
+
key: 'phone',
|
|
188
|
+
type: 'text',
|
|
189
|
+
label: 'Phone',
|
|
190
|
+
description: 'The business’s phone number, as entered on Setup → Business profile.',
|
|
191
|
+
resolve: (host)=>{
|
|
192
|
+
var _host_seo_entity, _host_seo;
|
|
193
|
+
return trimmed((_host_seo = host.seo) == null ? void 0 : (_host_seo_entity = _host_seo.entity) == null ? void 0 : _host_seo_entity.telephone);
|
|
194
|
+
},
|
|
195
|
+
whenEmpty: 'omit-block'
|
|
196
|
+
},
|
|
197
|
+
phoneLink: {
|
|
198
|
+
key: 'phoneLink',
|
|
199
|
+
type: 'url',
|
|
200
|
+
label: 'Phone link',
|
|
201
|
+
description: 'The phone number as a tel: link, for a Call button’s link. Dropped when the site has no phone.',
|
|
202
|
+
resolve: (host)=>{
|
|
203
|
+
var _host_seo_entity, _host_seo;
|
|
204
|
+
return telephoneHref((_host_seo = host.seo) == null ? void 0 : (_host_seo_entity = _host_seo.entity) == null ? void 0 : _host_seo_entity.telephone);
|
|
205
|
+
},
|
|
206
|
+
whenEmpty: 'omit-block'
|
|
207
|
+
},
|
|
208
|
+
/*
|
|
209
|
+
The key keeps its old name, because pages and emails already say
|
|
210
|
+
`{{host.supportEmail}}`. What it reads is the site's one email (AGL-4136):
|
|
211
|
+
the one Setup → Business profile saves to the entity, else the one-block copy a
|
|
212
|
+
site saved before that.
|
|
213
|
+
*/ supportEmail: {
|
|
97
214
|
key: 'supportEmail',
|
|
98
215
|
type: 'email',
|
|
99
|
-
label: '
|
|
100
|
-
description: '
|
|
216
|
+
label: 'Email',
|
|
217
|
+
description: 'The email address visitors write to, from Setup → Business profile.',
|
|
101
218
|
resolve: (host)=>{
|
|
102
|
-
var
|
|
103
|
-
return
|
|
219
|
+
var _siteContactEmail;
|
|
220
|
+
return (_siteContactEmail = siteContactEmail(host)) != null ? _siteContactEmail : undefined;
|
|
104
221
|
},
|
|
105
222
|
whenEmpty: 'omit-block'
|
|
106
223
|
},
|
|
@@ -108,20 +225,46 @@ function logo(host) {
|
|
|
108
225
|
key: 'address',
|
|
109
226
|
type: 'address',
|
|
110
227
|
label: 'Postal address',
|
|
111
|
-
description: 'The business’s postal address, as one block of text.',
|
|
228
|
+
description: 'The business’s postal address from Setup → Business profile, as one block of text.',
|
|
229
|
+
// The structured address, formatted the one way it is formatted
|
|
230
|
+
// everywhere (AGL-4136), else the one-block copy as it was typed —
|
|
231
|
+
// line breaks kept, because a document prints it a line per line.
|
|
112
232
|
resolve: (host)=>{
|
|
113
|
-
var
|
|
114
|
-
|
|
233
|
+
var _trimmed;
|
|
234
|
+
var _host_seo_entity, _host_seo, _host_business;
|
|
235
|
+
return (_trimmed = trimmed(structuredAddressLine((_host_seo = host.seo) == null ? void 0 : (_host_seo_entity = _host_seo.entity) == null ? void 0 : _host_seo_entity.address))) != null ? _trimmed : trimmed((_host_business = host.business) == null ? void 0 : _host_business.address);
|
|
115
236
|
},
|
|
116
237
|
whenEmpty: 'omit-block'
|
|
117
238
|
},
|
|
239
|
+
mainArea: {
|
|
240
|
+
key: 'mainArea',
|
|
241
|
+
type: 'text',
|
|
242
|
+
label: 'Main area',
|
|
243
|
+
description: 'The first area served, by its place name: San Antonio, for “San Antonio, TX”. From SEO → Local business.',
|
|
244
|
+
// The text before the first comma, so the token reads in a sentence —
|
|
245
|
+
// "across San Antonio and surrounding areas" — and a page that already
|
|
246
|
+
// says the place name can switch to it without a visible change.
|
|
247
|
+
resolve: (host)=>{
|
|
248
|
+
var _areasServed_;
|
|
249
|
+
return trimmed((_areasServed_ = areasServed(host)[0]) == null ? void 0 : _areasServed_.split(',')[0]);
|
|
250
|
+
},
|
|
251
|
+
whenEmpty: 'blank'
|
|
252
|
+
},
|
|
253
|
+
areasServed: {
|
|
254
|
+
key: 'areasServed',
|
|
255
|
+
type: 'text',
|
|
256
|
+
label: 'Areas served',
|
|
257
|
+
description: 'Every area served, in order, separated by commas. From SEO → Local business.',
|
|
258
|
+
resolve: (host)=>trimmed(areasServed(host).join(', ')),
|
|
259
|
+
whenEmpty: 'blank'
|
|
260
|
+
},
|
|
118
261
|
socialLinks: {
|
|
119
262
|
key: 'socialLinks',
|
|
120
263
|
type: 'text',
|
|
121
264
|
label: 'Social links',
|
|
122
265
|
description: 'The site’s social profiles, as a list of labeled links.',
|
|
123
266
|
// Rendered as text here so a token in copy degrades to something readable;
|
|
124
|
-
// a
|
|
267
|
+
// a link to one profile is that network's own token below (AGL-4136).
|
|
125
268
|
resolve: (host)=>{
|
|
126
269
|
var _ref;
|
|
127
270
|
var _host_business;
|
|
@@ -133,7 +276,17 @@ function logo(host) {
|
|
|
133
276
|
return labels.length ? labels.join(' · ') : undefined;
|
|
134
277
|
},
|
|
135
278
|
whenEmpty: 'omit-block'
|
|
136
|
-
}
|
|
279
|
+
},
|
|
280
|
+
/*
|
|
281
|
+
One link per common network (AGL-4136), so a page's social icons link
|
|
282
|
+
the site's own profiles from Setup → Business profile instead of a hand-made
|
|
283
|
+
variable per network.
|
|
284
|
+
*/ facebookUrl: socialToken('facebook', 'facebookUrl', 'Facebook'),
|
|
285
|
+
instagramUrl: socialToken('instagram', 'instagramUrl', 'Instagram'),
|
|
286
|
+
xUrl: socialToken('x', 'xUrl', 'X'),
|
|
287
|
+
linkedinUrl: socialToken('linkedin', 'linkedinUrl', 'LinkedIn'),
|
|
288
|
+
youtubeUrl: socialToken('youtube', 'youtubeUrl', 'YouTube'),
|
|
289
|
+
tiktokUrl: socialToken('tiktok', 'tiktokUrl', 'TikTok')
|
|
137
290
|
};
|
|
138
291
|
/**
|
|
139
292
|
* The registry's entry for `key`, or undefined when it declares none.
|
|
@@ -285,12 +438,14 @@ function logo(host) {
|
|
|
285
438
|
return merge;
|
|
286
439
|
}
|
|
287
440
|
/**
|
|
288
|
-
* The email address a visitor writes to the business at: the one
|
|
289
|
-
*
|
|
290
|
-
* when the site has neither. One
|
|
291
|
-
*
|
|
292
|
-
* email
|
|
293
|
-
*
|
|
441
|
+
* The email address a visitor writes to the business at: the one Setup →
|
|
442
|
+
* Business saves (`seo.entity.email`), else the one-block copy a site saved
|
|
443
|
+
* before that (`business.supportEmail`). Null when the site has neither. One
|
|
444
|
+
* answer for every place that names it: the `{{host.supportEmail}}` token
|
|
445
|
+
* and so the email footer, the waiver consent, the quote and invoice PDFs,
|
|
446
|
+
* the Reply-To of the quote email (AGL-4097), and the address a refused form
|
|
447
|
+
* or sign-up offers instead (AGL-4136). Trimmed, not validated; a caller
|
|
448
|
+
* putting it in a header checks it is an address.
|
|
294
449
|
*/ export function siteContactEmail(host) {
|
|
295
450
|
var _host_seo_entity, _host_seo, _host_business;
|
|
296
451
|
const text = (value)=>typeof value === 'string' ? value.trim().slice(0, 320) : '';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/host-tokens.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 { hostPublicOrigin } from './host-naming'\n\n/**\n * Host variables — publisher templates that fill themselves in (AGL-1022).\n *\n * A publisher writing an email template cannot reference the installing site,\n * so every install begins with the same chore: swap the placeholder logo, fix\n * the business name, correct the links. Miss one and the site sends an email\n * carrying someone else's branding.\n *\n * `host.*` gives artifacts a way to NAME the host instead of hard-coding it.\n * The author writes `{{host.businessName}}`; the installing site fills it in,\n * and it stays filled in when that site rebrands.\n *\n * ## The namespace IS the security boundary\n *\n * This is publisher-authored content resolving against tenant data, so the\n * registry is CLOSED and each token reads through a hand-written function\n * rather than a path into the document. That is the whole design: a token\n * cannot address `stripeAccountId`, or `memberRoles`, or anything else, because\n * there is no path syntax to express it — `host.` is followed by a key that\n * either appears in {@link HOST_TOKENS} or resolves to nothing at all. Adding a\n * token is a deliberate edit here, reviewable as a diff.\n *\n * A path-based registry (\"allow `host.seo.title`\") would have been shorter and\n * is the version to refuse: allowlisting prefixes is how a namespace grows a\n * hole, and the first `host.orgId` would be a data leak with a plausible commit\n * message.\n *\n * ## Resolve LATE\n *\n * At render and at send, never at install. Freezing values into the artifact\n * would make a rebrand stop propagating silently — the site would keep sending\n * last year's business name from a template nobody remembers is a template.\n *\n * ## Every token defines what \"empty\" does\n *\n * A site with no logo must produce something deliberate. Never an empty image,\n * and never the literal `{{host.logo}}` reaching a visitor — a leaked token is\n * the most embarrassing possible failure for a feature whose entire purpose is\n * to stop templates looking unfinished.\n */\n\n/**\n * What a token yields, so a renderer knows how to place it and the authoring\n * surface can refuse it in the wrong slot.\n *\n * `text` is the only type safe to drop into arbitrary copy. The others carry a\n * shape a slot has to understand — an `image` in a paragraph is a URL sitting\n * in the middle of a sentence, which is exactly the \"fails in a sent email\"\n * outcome this typing exists to move to authoring time.\n */\nexport type HostTokenType = 'text' | 'url' | 'email' | 'image' | 'address'\n\n/** What a renderer should do when a token resolves to nothing. */\nexport type HostTokenEmptyBehaviour =\n /** Render nothing in its place; the surrounding copy still makes sense. */\n | 'blank'\n /**\n * The block holding it should be dropped entirely. An `<img src=\"\">` is a\n * broken-image icon in every mail client, which is worse than no logo.\n */\n | 'omit-block'\n\n/** The site fields a token may read. A closed, explicit surface. */\nexport interface HostTokenSource {\n displayName?: string\n logoUrl?: string\n logoDarkUrl?: string\n subdomain?: string\n cname?: string\n /** Contact details a publisher template can reference (AGL-1022). */\n business?: {\n supportEmail?: string\n address?: string\n socialLinks?: Array<{ label?: string; url?: string }>\n }\n seo?: { entity?: { name?: string; logo?: string } }\n}\n\nexport interface HostTokenDefinition {\n /** The key after `host.` */\n key: string\n type: HostTokenType\n label: string\n description: string\n /** Reads the value. Hand-written per token — never a path into the document. */\n resolve: (host: HostTokenSource) => string | undefined\n /**\n * A deliberate second choice when `resolve` finds nothing.\n *\n * Not a nicety: \"fall back to the business name\" is what turns a missing logo\n * from a hole in the page into a wordmark, which is what a careful designer\n * would have done by hand.\n */\n fallback?: (host: HostTokenSource) => string | undefined\n whenEmpty: HostTokenEmptyBehaviour\n}\n\nconst trimmed = (value: unknown): string | undefined => {\n const text = typeof value === 'string' ? value.trim() : ''\n return text || undefined\n}\n\n/**\n * The site's public URL.\n *\n * A custom domain wins when connected, because that is the address the site is\n * actually known by — a template linking to the aglyn.app subdomain of a site\n * with its own domain is technically correct and reads as a mistake.\n */\nfunction siteUrl(host: HostTokenSource): string | undefined {\n const custom = trimmed(host.cname)\n if (custom) return `https://${custom.replace(/^https?:\\/\\//, '')}`\n // `hostPublicOrigin`, not a fourth hand-rolled apex (AGL-2195). The cname\n // branch stays here because this one strips a scheme the token source may\n // carry; the subdomain branch has no such difference and had none — it was\n // the same two lines with `aglyn.app` written in, so an operator's own apex\n // was honoured everywhere except in the tokens a template renders.\n return hostPublicOrigin({ subdomain: trimmed(host.subdomain) })\n}\n\nfunction businessName(host: HostTokenSource): string | undefined {\n return trimmed(host.seo?.entity?.name) ?? trimmed(host.displayName)\n}\n\nfunction logo(host: HostTokenSource): string | undefined {\n return trimmed(host.logoUrl) ?? trimmed(host.seo?.entity?.logo)\n}\n\n/**\n * The closed registry.\n *\n * Ordered as an author would look for them. Every entry is reachable from a\n * field a site can actually set — a token that can never resolve is worse than\n * an absent one, because it teaches people the feature does not work.\n */\nexport const HOST_TOKENS: Record<string, HostTokenDefinition> = {\n businessName: {\n key: 'businessName',\n type: 'text',\n label: 'Business name',\n description: 'The site’s business or brand name.',\n resolve: businessName,\n whenEmpty: 'blank',\n },\n logo: {\n key: 'logo',\n type: 'image',\n label: 'Logo',\n description: 'The site’s logo image.',\n resolve: logo,\n // No image: the block is dropped and the business name carries the brand\n // instead, which is what the block was for.\n whenEmpty: 'omit-block',\n },\n logoDark: {\n key: 'logoDark',\n type: 'image',\n label: 'Logo for dark backgrounds',\n description:\n 'The logo to show on a dark background. The site’s logo when it has no dark one.',\n // The pair a header toggles by color scheme (AGL-4119): a site with one\n // logo shows it in both schemes, and one with none shows neither.\n resolve: (host) => trimmed(host.logoDarkUrl) ?? logo(host),\n whenEmpty: 'omit-block',\n },\n url: {\n key: 'url',\n type: 'url',\n label: 'Site address',\n description: 'The site’s public URL — its custom domain when connected.',\n resolve: siteUrl,\n whenEmpty: 'blank',\n },\n supportEmail: {\n key: 'supportEmail',\n type: 'email',\n label: 'Support email',\n description: 'Where visitors should write for help.',\n resolve: (host) => trimmed(host.business?.supportEmail),\n whenEmpty: 'omit-block',\n },\n address: {\n key: 'address',\n type: 'address',\n label: 'Postal address',\n description: 'The business’s postal address, as one block of text.',\n resolve: (host) => trimmed(host.business?.address),\n whenEmpty: 'omit-block',\n },\n socialLinks: {\n key: 'socialLinks',\n type: 'text',\n label: 'Social links',\n description: 'The site’s social profiles, as a list of labeled links.',\n // Rendered as text here so a token in copy degrades to something readable;\n // a renderer wanting real links reads `host.business.socialLinks` itself.\n resolve: (host) => {\n const links = host.business?.socialLinks ?? []\n const labels = links\n .map((link) => trimmed(link?.label) ?? trimmed(link?.url))\n .filter((label): label is string => Boolean(label))\n return labels.length ? labels.join(' · ') : undefined\n },\n whenEmpty: 'omit-block',\n },\n}\n\n/**\n * The registry's entry for `key`, or undefined when it declares none.\n *\n * An OWN entry only. `HOST_TOKENS` is an object literal, so a bare index also\n * finds the `Object.prototype` members — `constructor`, `toString`, `valueOf` —\n * and every one of those names matches {@link HOST_TOKEN_PATTERN}. Read that\n * way, `{{host.constructor}}` answers the `Object` function where a definition\n * belongs, and calling its `resolve` throws in the middle of a render. A name\n * the registry does not declare resolves to nothing, whatever the name is.\n */\nexport function hostTokenDefinition(\n key: string,\n): HostTokenDefinition | undefined {\n return Object.prototype.hasOwnProperty.call(HOST_TOKENS, key)\n ? HOST_TOKENS[key]\n : undefined\n}\n\n/**\n * `{{host.key}}` — whitespace-tolerant, and deliberately NOT dotted beyond one\n * segment. `host.a.b` does not match, so there is no path syntax to abuse.\n */\nexport const HOST_TOKEN_PATTERN = /\\{\\{\\s*host\\.([a-zA-Z][a-zA-Z0-9_]*)\\s*\\}\\}/g\n\n/**\n * Whether a value is exactly one image token, like `{{host.logo}}`: what a\n * picture's `src` may be when it is the installing site's own logo. It becomes\n * that site's stored value at render, so it names nothing of the publisher's.\n */\nexport function isHostImageToken(value: string): boolean {\n const keys = hostTokensIn(value)\n return (\n keys.length === 1 &&\n value.replace(HOST_TOKEN_PATTERN, '').trim() === '' &&\n hostTokenDefinition(keys[0])?.type === 'image'\n )\n}\n\n/** Every `host.*` token in a string, in order, including unknown ones. */\nexport function hostTokensIn(text: string): string[] {\n if (typeof text !== 'string' || !text.includes('{{')) return []\n const keys: string[] = []\n for (const match of text.matchAll(HOST_TOKEN_PATTERN)) keys.push(match[1])\n return keys\n}\n\n/** The resolved value of one token, or undefined when the site has none. */\nexport function resolveHostToken(\n key: string,\n host: HostTokenSource | null | undefined,\n): string | undefined {\n const definition = hostTokenDefinition(key)\n if (!definition || !host) return undefined\n return definition.resolve(host) ?? definition.fallback?.(host)\n}\n\n/**\n * Replaces every `host.*` token with the installing site's value.\n *\n * An unresolved token — unknown key, or a site that has not set the field —\n * renders EMPTY, never the literal. Leaking `{{host.logo}}` into a sent email\n * is the failure this feature exists to prevent, so it cannot be the fallback\n * for the feature's own gaps. The authoring-time check\n * ({@link validateHostTokens}) is where a typo is meant to be caught, while the\n * writer can still fix it.\n */\nexport function resolveHostTokens(\n text: string,\n host: HostTokenSource | null | undefined,\n): string {\n if (typeof text !== 'string' || !text.includes('{{')) return text\n return text.replace(HOST_TOKEN_PATTERN, (_token, key) =>\n resolveHostToken(String(key), host) ?? '',\n )\n}\n\nexport interface HostTokenIssue {\n key: string\n /**\n * `unknown` — no such token; it will render empty.\n * `wrong-slot` — the token's type cannot be placed here.\n */\n kind: 'unknown' | 'wrong-slot'\n message: string\n}\n\n/**\n * Authoring-time check: catch a token before it reaches a visitor.\n *\n * The two things worth failing on are a typo (which would silently render\n * nothing) and a type mismatch (an image URL dropped into a sentence). Both are\n * invisible at authoring time without this and obvious afterwards, which is the\n * wrong way round for something that ends up in a sent email.\n *\n * `allow` names the types this slot can take. Omit it for free text, where only\n * `text` and the string-ish types make sense.\n */\nexport function validateHostTokens(\n text: string,\n options?: { allow?: readonly HostTokenType[] },\n): HostTokenIssue[] {\n const allow = options?.allow ?? ['text', 'url', 'email', 'address']\n const issues: HostTokenIssue[] = []\n const seen = new Set<string>()\n for (const key of hostTokensIn(text)) {\n if (seen.has(key)) continue\n seen.add(key)\n const definition = hostTokenDefinition(key)\n if (!definition) {\n issues.push({\n key,\n kind: 'unknown',\n message:\n `There is no host variable called \"${key}\". It will render as ` +\n 'nothing. Available: ' +\n Object.keys(HOST_TOKENS).join(', ') +\n '.',\n })\n continue\n }\n if (!allow.includes(definition.type)) {\n issues.push({\n key,\n kind: 'wrong-slot',\n message:\n `\"${definition.label}\" is ${\n definition.type === 'image' ? 'an image' : `a ${definition.type}`\n }, so it cannot go here. Put it in a slot that takes ` +\n `${definition.type === 'image' ? 'an image' : `a ${definition.type}`}.`,\n })\n }\n }\n return issues\n}\n\n/**\n * Whether a block containing these tokens should be dropped for this site.\n *\n * The other half of \"every token needs a defined empty behaviour\": a logo block\n * on a site with no logo should not render an empty image, and the renderer\n * cannot know that from the resolved string alone — `''` is both \"no value\" and\n * \"a value that happens to be empty\". Asking here keeps the rule with the\n * token definition rather than spread across the surfaces that render it.\n */\nexport function shouldOmitBlock(\n text: string,\n host: HostTokenSource | null | undefined,\n): boolean {\n for (const key of hostTokensIn(text)) {\n const definition = hostTokenDefinition(key)\n if (!definition || definition.whenEmpty !== 'omit-block') continue\n if (!resolveHostToken(key, host)) return true\n }\n return false\n}\n\n/**\n * Every token with its resolved value for one site, for an authoring picker\n * that shows what each will actually produce here.\n *\n * A picker listing token names alone makes the author guess; showing the value\n * this site would render is what turns \"is it businessName or business_name\"\n * into a question nobody has to ask.\n */\nexport function describeHostTokens(\n host: HostTokenSource | null | undefined,\n): Array<HostTokenDefinition & { token: string; value?: string; set: boolean }> {\n return Object.values(HOST_TOKENS).map((definition) => {\n const value = resolveHostToken(definition.key, host)\n return {\n ...definition,\n token: `{{host.${definition.key}}}`,\n value,\n set: Boolean(value),\n }\n })\n}\n\n/**\n * The `host.*` values as a merge-token map, for surfaces that already have a\n * token substituter of their own.\n *\n * This is how EMAIL gets host variables without the email library depending on\n * this one: `substituteMergeTokens` already matches `{{a.b}}`, so a caller\n * spreads this into the merge map it was passing anyway. One registry, two\n * surfaces, no second substitution engine to drift.\n *\n * Every registered token appears, INCLUDING the ones this site has not set —\n * as `''`. Omitting them would leave `{{host.supportEmail}}` for the generic\n * catch-all to blank, which works today and works by accident: the moment a\n * surface without that catch-all uses this map, the literal token ships.\n */\nexport function hostTokenMerge(\n host: HostTokenSource | null | undefined,\n): Record<string, string> {\n const merge: Record<string, string> = {}\n for (const key of Object.keys(HOST_TOKENS)) {\n merge[`host.${key}`] = resolveHostToken(key, host) ?? ''\n }\n return merge\n}\n\n/**\n * The email address a visitor writes to the business at: the one its\n * business listing shows (`seo.entity.email`), else its support email. Null\n * when the site has neither. One answer for every place that names it: the\n * waiver consent, the quote and invoice PDFs, and the Reply-To of the quote\n * email (AGL-4097). Trimmed, not validated; a caller putting it in a header\n * checks it is an address.\n */\nexport function siteContactEmail(\n host:\n | {\n seo?: { entity?: { email?: unknown } | null } | null\n business?: { supportEmail?: unknown } | null\n }\n | null\n | undefined,\n): string | null {\n const text = (value: unknown) => (typeof value === 'string' ? value.trim().slice(0, 320) : '')\n return text(host?.seo?.entity?.email) || text(host?.business?.supportEmail) || null\n}\n\n/**\n * Resolves `host.*` tokens across every string prop of a normalized node map.\n *\n * Mirrors `resolveNodesBindings` deliberately — same shallow-copy discipline,\n * same string-props-only rule — so a screen and an email resolve the same token\n * to the same value. The issue's warning is the reason: two resolvers drift,\n * and then the same token means different things depending on where an author\n * typed it.\n *\n * Returns the input untouched when the site has nothing to substitute, so a\n * binding-free tree costs one `Object.entries`.\n */\nexport function resolveNodesHostTokens<T extends Record<string, any>>(\n nodes: T,\n host: HostTokenSource | null | undefined,\n): T {\n if (!nodes) return nodes\n let changed = false\n const next: Record<string, any> = {}\n for (const [id, node] of Object.entries(nodes)) {\n const props = node?.props\n if (!props) {\n next[id] = node\n continue\n }\n let nodeChanged = false\n const nextProps: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(props)) {\n if (typeof value === 'string' && value.includes('{{')) {\n const resolved = resolveHostTokens(value, host)\n nextProps[key] = resolved\n if (resolved !== value) nodeChanged = true\n } else {\n nextProps[key] = value\n }\n }\n next[id] = nodeChanged ? { ...node, props: nextProps } : node\n changed = changed || nodeChanged\n }\n return (changed ? next : nodes) as T\n}\n"],"names":["hostPublicOrigin","trimmed","value","text","trim","undefined","siteUrl","host","custom","cname","replace","subdomain","businessName","seo","entity","name","displayName","logo","logoUrl","HOST_TOKENS","key","type","label","description","resolve","whenEmpty","logoDark","logoDarkUrl","url","supportEmail","business","address","socialLinks","links","labels","map","link","filter","Boolean","length","join","hostTokenDefinition","Object","prototype","hasOwnProperty","call","HOST_TOKEN_PATTERN","isHostImageToken","keys","hostTokensIn","includes","match","matchAll","push","resolveHostToken","definition","fallback","resolveHostTokens","_token","String","validateHostTokens","options","allow","issues","seen","Set","has","add","kind","message","shouldOmitBlock","describeHostTokens","values","token","set","hostTokenMerge","merge","siteContactEmail","slice","email","resolveNodesHostTokens","nodes","changed","next","id","node","entries","props","nodeChanged","nextProps","resolved"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,gBAAgB,QAAQ,mBAAe;AAmGhD,MAAMC,UAAU,CAACC;IACf,MAAMC,OAAO,OAAOD,UAAU,WAAWA,MAAME,IAAI,KAAK;IACxD,OAAOD,QAAQE;AACjB;AAEA;;;;;;CAMC,GACD,SAASC,QAAQC,IAAqB;IACpC,MAAMC,SAASP,QAAQM,KAAKE,KAAK;IACjC,IAAID,QAAQ,OAAO,CAAC,QAAQ,EAAEA,OAAOE,OAAO,CAAC,gBAAgB,KAAK;IAClE,0EAA0E;IAC1E,0EAA0E;IAC1E,2EAA2E;IAC3E,4EAA4E;IAC5E,mEAAmE;IACnE,OAAOV,iBAAiB;QAAEW,WAAWV,QAAQM,KAAKI,SAAS;IAAE;AAC/D;AAEA,SAASC,aAAaL,IAAqB;QAClCN;QAAQM,kBAAAA;IAAf,QAAON,WAAAA,SAAQM,YAAAA,KAAKM,GAAG,sBAARN,mBAAAA,UAAUO,MAAM,qBAAhBP,iBAAkBQ,IAAI,aAA9Bd,WAAmCA,QAAQM,KAAKS,WAAW;AACpE;AAEA,SAASC,KAAKV,IAAqB;QAC1BN;QAAiCM,kBAAAA;IAAxC,QAAON,WAAAA,QAAQM,KAAKW,OAAO,aAApBjB,WAAyBA,SAAQM,YAAAA,KAAKM,GAAG,sBAARN,mBAAAA,UAAUO,MAA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ACD,OAAO,SAASmD,uBACdC,KAAQ,EACR1E,IAAwC;IAExC,IAAI,CAAC0E,OAAO,OAAOA;IACnB,IAAIC,UAAU;IACd,MAAMC,OAA4B,CAAC;IACnC,KAAK,MAAM,CAACC,IAAIC,KAAK,IAAI3C,OAAO4C,OAAO,CAACL,OAAQ;QAC9C,MAAMM,QAAQF,wBAAAA,KAAME,KAAK;QACzB,IAAI,CAACA,OAAO;YACVJ,IAAI,CAACC,GAAG,GAAGC;YACX;QACF;QACA,IAAIG,cAAc;QAClB,MAAMC,YAAqC,CAAC;QAC5C,KAAK,MAAM,CAACrE,KAAKlB,MAAM,IAAIwC,OAAO4C,OAAO,CAACC,OAAQ;YAChD,IAAI,OAAOrF,UAAU,YAAYA,MAAMgD,QAAQ,CAAC,OAAO;gBACrD,MAAMwC,WAAWjC,kBAAkBvD,OAAOK;gBAC1CkF,SAAS,CAACrE,IAAI,GAAGsE;gBACjB,IAAIA,aAAaxF,OAAOsF,cAAc;YACxC,OAAO;gBACLC,SAAS,CAACrE,IAAI,GAAGlB;YACnB;QACF;QACAiF,IAAI,CAACC,GAAG,GAAGI,cAAc,aAAKH;YAAME,OAAOE;aAAcJ;QACzDH,UAAUA,WAAWM;IACvB;IACA,OAAQN,UAAUC,OAAOF;AAC3B"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/host-tokens.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 { structuredAddressLine } from './business-profile'\nimport { siteProfileUrls, type HostSeoEntity } from './content-authors'\nimport { hostPublicOrigin } from './host-naming'\nimport { normalizeAreaServed } from './local-business'\n\n/**\n * Host variables — publisher templates that fill themselves in (AGL-1022).\n *\n * A publisher writing an email template cannot reference the installing site,\n * so every install begins with the same chore: swap the placeholder logo, fix\n * the business name, correct the links. Miss one and the site sends an email\n * carrying someone else's branding.\n *\n * `host.*` gives artifacts a way to NAME the host instead of hard-coding it.\n * The author writes `{{host.businessName}}`; the installing site fills it in,\n * and it stays filled in when that site rebrands.\n *\n * ## The namespace IS the security boundary\n *\n * This is publisher-authored content resolving against tenant data, so the\n * registry is CLOSED and each token reads through a hand-written function\n * rather than a path into the document. That is the whole design: a token\n * cannot address `stripeAccountId`, or `memberRoles`, or anything else, because\n * there is no path syntax to express it — `host.` is followed by a key that\n * either appears in {@link HOST_TOKENS} or resolves to nothing at all. Adding a\n * token is a deliberate edit here, reviewable as a diff.\n *\n * A path-based registry (\"allow `host.seo.title`\") would have been shorter and\n * is the version to refuse: allowlisting prefixes is how a namespace grows a\n * hole, and the first `host.orgId` would be a data leak with a plausible commit\n * message.\n *\n * ## Resolve LATE\n *\n * At render and at send, never at install. Freezing values into the artifact\n * would make a rebrand stop propagating silently — the site would keep sending\n * last year's business name from a template nobody remembers is a template.\n *\n * ## Every token defines what \"empty\" does\n *\n * A site with no logo must produce something deliberate. Never an empty image,\n * and never the literal `{{host.logo}}` reaching a visitor — a leaked token is\n * the most embarrassing possible failure for a feature whose entire purpose is\n * to stop templates looking unfinished.\n */\n\n/**\n * What a token yields, so a renderer knows how to place it and the authoring\n * surface can refuse it in the wrong slot.\n *\n * `text` is the only type safe to drop into arbitrary copy. The others carry a\n * shape a slot has to understand — an `image` in a paragraph is a URL sitting\n * in the middle of a sentence, which is exactly the \"fails in a sent email\"\n * outcome this typing exists to move to authoring time.\n */\nexport type HostTokenType = 'text' | 'url' | 'email' | 'image' | 'address'\n\n/** What a renderer should do when a token resolves to nothing. */\nexport type HostTokenEmptyBehaviour =\n /** Render nothing in its place; the surrounding copy still makes sense. */\n | 'blank'\n /**\n * The block holding it should be dropped entirely. An `<img src=\"\">` is a\n * broken-image icon in every mail client, which is worse than no logo.\n */\n | 'omit-block'\n\n/** The site fields a token may read. A closed, explicit surface. */\nexport interface HostTokenSource {\n displayName?: string\n logoUrl?: string\n logoDarkUrl?: string\n subdomain?: string\n cname?: string\n /**\n * The one-block copies of the email and address, and the social links\n * (AGL-1022). Setup → Business profile writes the email and address to `seo.entity`\n * and mirrors them here (AGL-4136), so these are what a token reads when\n * the entity has none: a site saved before that, or by the native apps.\n */\n business?: {\n supportEmail?: string\n address?: string\n socialLinks?: Array<{ label?: string; url?: string }>\n }\n /**\n * The business's facts as Setup → Business profile and SEO → Local business store\n * them (AGL-4136): the name, slogan, phone, email, structured address, the\n * profiles it claims and the areas it serves.\n */\n seo?: {\n entity?: Pick<\n HostSeoEntity,\n | 'name'\n | 'logo'\n | 'slogan'\n | 'email'\n | 'telephone'\n | 'address'\n | 'sameAs'\n | 'areaServed'\n >\n }\n}\n\nexport interface HostTokenDefinition {\n /** The key after `host.` */\n key: string\n type: HostTokenType\n label: string\n description: string\n /** Reads the value. Hand-written per token — never a path into the document. */\n resolve: (host: HostTokenSource) => string | undefined\n /**\n * A deliberate second choice when `resolve` finds nothing.\n *\n * Not a nicety: \"fall back to the business name\" is what turns a missing logo\n * from a hole in the page into a wordmark, which is what a careful designer\n * would have done by hand.\n */\n fallback?: (host: HostTokenSource) => string | undefined\n whenEmpty: HostTokenEmptyBehaviour\n}\n\nconst trimmed = (value: unknown): string | undefined => {\n const text = typeof value === 'string' ? value.trim() : ''\n return text || undefined\n}\n\n/**\n * The site's public URL.\n *\n * A custom domain wins when connected, because that is the address the site is\n * actually known by — a template linking to the aglyn.app subdomain of a site\n * with its own domain is technically correct and reads as a mistake.\n */\nfunction siteUrl(host: HostTokenSource): string | undefined {\n const custom = trimmed(host.cname)\n if (custom) return `https://${custom.replace(/^https?:\\/\\//, '')}`\n // `hostPublicOrigin`, not a fourth hand-rolled apex (AGL-2195). The cname\n // branch stays here because this one strips a scheme the token source may\n // carry; the subdomain branch has no such difference and had none — it was\n // the same two lines with `aglyn.app` written in, so an operator's own apex\n // was honoured everywhere except in the tokens a template renders.\n return hostPublicOrigin({ subdomain: trimmed(host.subdomain) })\n}\n\nfunction businessName(host: HostTokenSource): string | undefined {\n return trimmed(host.seo?.entity?.name) ?? trimmed(host.displayName)\n}\n\nfunction logo(host: HostTokenSource): string | undefined {\n return trimmed(host.logoUrl) ?? trimmed(host.seo?.entity?.logo)\n}\n\n/**\n * A phone number as a `tel:` link (AGL-4136): everything but its digits and\n * a leading `+` removed, so `+1 (512) 555-0100` dials `tel:+15125550100`.\n * Nothing when the number holds no digit, so a Call button never links to a\n * bare `tel:`.\n */\nexport function telephoneHref(phone: unknown): string | undefined {\n const text = trimmed(phone)\n if (!text) return undefined\n const digits = text.replace(/\\D+/g, '')\n if (!digits) return undefined\n return `tel:${text.startsWith('+') ? '+' : ''}${digits}`\n}\n\n/**\n * The social networks a page can link by name (AGL-4136), each with the\n * hostnames its profile addresses are served from. A hostname matches itself\n * and any subdomain of itself, so `www.` and `m.` addresses are the same\n * profile. X keeps `twitter.com`, because a link saved before the rename is\n * still the same account.\n */\nconst SOCIAL_NETWORK_HOSTS = {\n facebook: ['facebook.com', 'fb.com'],\n instagram: ['instagram.com'],\n x: ['x.com', 'twitter.com'],\n linkedin: ['linkedin.com'],\n youtube: ['youtube.com', 'youtu.be'],\n tiktok: ['tiktok.com'],\n} as const\n\nexport type HostSocialNetwork = keyof typeof SOCIAL_NETWORK_HOSTS\n\n/**\n * The site's profile on one network: the first of the profiles it claims\n * (`siteProfileUrls`, the entity's `sameAs` and then Setup → Business profile's\n * social links, https only) served from that network's hostname. Matched by\n * HOSTNAME rather than by the link's label, because the label is free text\n * and the address is what a visitor is sent to.\n */\nexport function siteSocialProfileUrl(\n host: HostTokenSource | null | undefined,\n network: HostSocialNetwork,\n): string | undefined {\n const hosts: readonly string[] = SOCIAL_NETWORK_HOSTS[network]\n for (const value of siteProfileUrls(host)) {\n let hostname: string\n try {\n hostname = new URL(value).hostname.toLowerCase()\n } catch {\n continue\n }\n if (hosts.some((name) => hostname === name || hostname.endsWith(`.${name}`))) {\n return value\n }\n }\n return undefined\n}\n\n/** The areas served, as SEO → Local business stores and the structured data publishes them. */\nfunction areasServed(host: HostTokenSource): string[] {\n return normalizeAreaServed(host.seo?.entity?.areaServed)\n}\n\n/** One social network's profile link as a token: a URL, dropped where the site has none. */\nfunction socialToken(\n network: HostSocialNetwork,\n key: string,\n name: string,\n): HostTokenDefinition {\n return {\n key,\n type: 'url',\n label: `${name} link`,\n description: `The address of the site’s ${name} profile, from Setup → Business profile.`,\n resolve: (host) => siteSocialProfileUrl(host, network),\n whenEmpty: 'omit-block',\n }\n}\n\n/**\n * The closed registry.\n *\n * Ordered as an author would look for them. Every entry is reachable from a\n * field a site can actually set — a token that can never resolve is worse than\n * an absent one, because it teaches people the feature does not work.\n */\nexport const HOST_TOKENS: Record<string, HostTokenDefinition> = {\n businessName: {\n key: 'businessName',\n type: 'text',\n label: 'Business name',\n description:\n 'The business name from Setup → Business profile, or the site’s name when none is set.',\n resolve: businessName,\n whenEmpty: 'blank',\n },\n slogan: {\n key: 'slogan',\n type: 'text',\n label: 'Slogan',\n description: 'A short line about the business, from Setup → Business profile.',\n resolve: (host) => trimmed(host.seo?.entity?.slogan),\n whenEmpty: 'blank',\n },\n logo: {\n key: 'logo',\n type: 'image',\n label: 'Logo',\n description: 'The site’s logo image.',\n resolve: logo,\n // No image: the block is dropped and the business name carries the brand\n // instead, which is what the block was for.\n whenEmpty: 'omit-block',\n },\n logoDark: {\n key: 'logoDark',\n type: 'image',\n label: 'Logo for dark backgrounds',\n description:\n 'The logo to show on a dark background. The site’s logo when it has no dark one.',\n // The pair a header toggles by color scheme (AGL-4119): a site with one\n // logo shows it in both schemes, and one with none shows neither.\n resolve: (host) => trimmed(host.logoDarkUrl) ?? logo(host),\n whenEmpty: 'omit-block',\n },\n url: {\n key: 'url',\n type: 'url',\n label: 'Site address',\n description: 'The site’s public URL — its custom domain when connected.',\n resolve: siteUrl,\n whenEmpty: 'blank',\n },\n phone: {\n key: 'phone',\n type: 'text',\n label: 'Phone',\n description: 'The business’s phone number, as entered on Setup → Business profile.',\n resolve: (host) => trimmed(host.seo?.entity?.telephone),\n whenEmpty: 'omit-block',\n },\n phoneLink: {\n key: 'phoneLink',\n type: 'url',\n label: 'Phone link',\n description:\n 'The phone number as a tel: link, for a Call button’s link. Dropped when the site has no phone.',\n resolve: (host) => telephoneHref(host.seo?.entity?.telephone),\n whenEmpty: 'omit-block',\n },\n /*\n The key keeps its old name, because pages and emails already say\n `{{host.supportEmail}}`. What it reads is the site's one email (AGL-4136):\n the one Setup → Business profile saves to the entity, else the one-block copy a\n site saved before that.\n */\n supportEmail: {\n key: 'supportEmail',\n type: 'email',\n label: 'Email',\n description: 'The email address visitors write to, from Setup → Business profile.',\n resolve: (host) => siteContactEmail(host) ?? undefined,\n whenEmpty: 'omit-block',\n },\n address: {\n key: 'address',\n type: 'address',\n label: 'Postal address',\n description:\n 'The business’s postal address from Setup → Business profile, as one block of text.',\n // The structured address, formatted the one way it is formatted\n // everywhere (AGL-4136), else the one-block copy as it was typed —\n // line breaks kept, because a document prints it a line per line.\n resolve: (host) =>\n trimmed(structuredAddressLine(host.seo?.entity?.address)) ??\n trimmed(host.business?.address),\n whenEmpty: 'omit-block',\n },\n mainArea: {\n key: 'mainArea',\n type: 'text',\n label: 'Main area',\n description:\n 'The first area served, by its place name: San Antonio, for “San Antonio, TX”. From SEO → Local business.',\n // The text before the first comma, so the token reads in a sentence —\n // \"across San Antonio and surrounding areas\" — and a page that already\n // says the place name can switch to it without a visible change.\n resolve: (host) => trimmed(areasServed(host)[0]?.split(',')[0]),\n whenEmpty: 'blank',\n },\n areasServed: {\n key: 'areasServed',\n type: 'text',\n label: 'Areas served',\n description:\n 'Every area served, in order, separated by commas. From SEO → Local business.',\n resolve: (host) => trimmed(areasServed(host).join(', ')),\n whenEmpty: 'blank',\n },\n socialLinks: {\n key: 'socialLinks',\n type: 'text',\n label: 'Social links',\n description: 'The site’s social profiles, as a list of labeled links.',\n // Rendered as text here so a token in copy degrades to something readable;\n // a link to one profile is that network's own token below (AGL-4136).\n resolve: (host) => {\n const links = host.business?.socialLinks ?? []\n const labels = links\n .map((link) => trimmed(link?.label) ?? trimmed(link?.url))\n .filter((label): label is string => Boolean(label))\n return labels.length ? labels.join(' · ') : undefined\n },\n whenEmpty: 'omit-block',\n },\n /*\n One link per common network (AGL-4136), so a page's social icons link\n the site's own profiles from Setup → Business profile instead of a hand-made\n variable per network.\n */\n facebookUrl: socialToken('facebook', 'facebookUrl', 'Facebook'),\n instagramUrl: socialToken('instagram', 'instagramUrl', 'Instagram'),\n xUrl: socialToken('x', 'xUrl', 'X'),\n linkedinUrl: socialToken('linkedin', 'linkedinUrl', 'LinkedIn'),\n youtubeUrl: socialToken('youtube', 'youtubeUrl', 'YouTube'),\n tiktokUrl: socialToken('tiktok', 'tiktokUrl', 'TikTok'),\n}\n\n/**\n * The registry's entry for `key`, or undefined when it declares none.\n *\n * An OWN entry only. `HOST_TOKENS` is an object literal, so a bare index also\n * finds the `Object.prototype` members — `constructor`, `toString`, `valueOf` —\n * and every one of those names matches {@link HOST_TOKEN_PATTERN}. Read that\n * way, `{{host.constructor}}` answers the `Object` function where a definition\n * belongs, and calling its `resolve` throws in the middle of a render. A name\n * the registry does not declare resolves to nothing, whatever the name is.\n */\nexport function hostTokenDefinition(\n key: string,\n): HostTokenDefinition | undefined {\n return Object.prototype.hasOwnProperty.call(HOST_TOKENS, key)\n ? HOST_TOKENS[key]\n : undefined\n}\n\n/**\n * `{{host.key}}` — whitespace-tolerant, and deliberately NOT dotted beyond one\n * segment. `host.a.b` does not match, so there is no path syntax to abuse.\n */\nexport const HOST_TOKEN_PATTERN = /\\{\\{\\s*host\\.([a-zA-Z][a-zA-Z0-9_]*)\\s*\\}\\}/g\n\n/**\n * Whether a value is exactly one image token, like `{{host.logo}}`: what a\n * picture's `src` may be when it is the installing site's own logo. It becomes\n * that site's stored value at render, so it names nothing of the publisher's.\n */\nexport function isHostImageToken(value: string): boolean {\n const keys = hostTokensIn(value)\n return (\n keys.length === 1 &&\n value.replace(HOST_TOKEN_PATTERN, '').trim() === '' &&\n hostTokenDefinition(keys[0])?.type === 'image'\n )\n}\n\n/** Every `host.*` token in a string, in order, including unknown ones. */\nexport function hostTokensIn(text: string): string[] {\n if (typeof text !== 'string' || !text.includes('{{')) return []\n const keys: string[] = []\n for (const match of text.matchAll(HOST_TOKEN_PATTERN)) keys.push(match[1])\n return keys\n}\n\n/** The resolved value of one token, or undefined when the site has none. */\nexport function resolveHostToken(\n key: string,\n host: HostTokenSource | null | undefined,\n): string | undefined {\n const definition = hostTokenDefinition(key)\n if (!definition || !host) return undefined\n return definition.resolve(host) ?? definition.fallback?.(host)\n}\n\n/**\n * Replaces every `host.*` token with the installing site's value.\n *\n * An unresolved token — unknown key, or a site that has not set the field —\n * renders EMPTY, never the literal. Leaking `{{host.logo}}` into a sent email\n * is the failure this feature exists to prevent, so it cannot be the fallback\n * for the feature's own gaps. The authoring-time check\n * ({@link validateHostTokens}) is where a typo is meant to be caught, while the\n * writer can still fix it.\n */\nexport function resolveHostTokens(\n text: string,\n host: HostTokenSource | null | undefined,\n): string {\n if (typeof text !== 'string' || !text.includes('{{')) return text\n return text.replace(HOST_TOKEN_PATTERN, (_token, key) =>\n resolveHostToken(String(key), host) ?? '',\n )\n}\n\nexport interface HostTokenIssue {\n key: string\n /**\n * `unknown` — no such token; it will render empty.\n * `wrong-slot` — the token's type cannot be placed here.\n */\n kind: 'unknown' | 'wrong-slot'\n message: string\n}\n\n/**\n * Authoring-time check: catch a token before it reaches a visitor.\n *\n * The two things worth failing on are a typo (which would silently render\n * nothing) and a type mismatch (an image URL dropped into a sentence). Both are\n * invisible at authoring time without this and obvious afterwards, which is the\n * wrong way round for something that ends up in a sent email.\n *\n * `allow` names the types this slot can take. Omit it for free text, where only\n * `text` and the string-ish types make sense.\n */\nexport function validateHostTokens(\n text: string,\n options?: { allow?: readonly HostTokenType[] },\n): HostTokenIssue[] {\n const allow = options?.allow ?? ['text', 'url', 'email', 'address']\n const issues: HostTokenIssue[] = []\n const seen = new Set<string>()\n for (const key of hostTokensIn(text)) {\n if (seen.has(key)) continue\n seen.add(key)\n const definition = hostTokenDefinition(key)\n if (!definition) {\n issues.push({\n key,\n kind: 'unknown',\n message:\n `There is no host variable called \"${key}\". It will render as ` +\n 'nothing. Available: ' +\n Object.keys(HOST_TOKENS).join(', ') +\n '.',\n })\n continue\n }\n if (!allow.includes(definition.type)) {\n issues.push({\n key,\n kind: 'wrong-slot',\n message:\n `\"${definition.label}\" is ${\n definition.type === 'image' ? 'an image' : `a ${definition.type}`\n }, so it cannot go here. Put it in a slot that takes ` +\n `${definition.type === 'image' ? 'an image' : `a ${definition.type}`}.`,\n })\n }\n }\n return issues\n}\n\n/**\n * Whether a block containing these tokens should be dropped for this site.\n *\n * The other half of \"every token needs a defined empty behaviour\": a logo block\n * on a site with no logo should not render an empty image, and the renderer\n * cannot know that from the resolved string alone — `''` is both \"no value\" and\n * \"a value that happens to be empty\". Asking here keeps the rule with the\n * token definition rather than spread across the surfaces that render it.\n */\nexport function shouldOmitBlock(\n text: string,\n host: HostTokenSource | null | undefined,\n): boolean {\n for (const key of hostTokensIn(text)) {\n const definition = hostTokenDefinition(key)\n if (!definition || definition.whenEmpty !== 'omit-block') continue\n if (!resolveHostToken(key, host)) return true\n }\n return false\n}\n\n/**\n * Every token with its resolved value for one site, for an authoring picker\n * that shows what each will actually produce here.\n *\n * A picker listing token names alone makes the author guess; showing the value\n * this site would render is what turns \"is it businessName or business_name\"\n * into a question nobody has to ask.\n */\nexport function describeHostTokens(\n host: HostTokenSource | null | undefined,\n): Array<HostTokenDefinition & { token: string; value?: string; set: boolean }> {\n return Object.values(HOST_TOKENS).map((definition) => {\n const value = resolveHostToken(definition.key, host)\n return {\n ...definition,\n token: `{{host.${definition.key}}}`,\n value,\n set: Boolean(value),\n }\n })\n}\n\n/**\n * The `host.*` values as a merge-token map, for surfaces that already have a\n * token substituter of their own.\n *\n * This is how EMAIL gets host variables without the email library depending on\n * this one: `substituteMergeTokens` already matches `{{a.b}}`, so a caller\n * spreads this into the merge map it was passing anyway. One registry, two\n * surfaces, no second substitution engine to drift.\n *\n * Every registered token appears, INCLUDING the ones this site has not set —\n * as `''`. Omitting them would leave `{{host.supportEmail}}` for the generic\n * catch-all to blank, which works today and works by accident: the moment a\n * surface without that catch-all uses this map, the literal token ships.\n */\nexport function hostTokenMerge(\n host: HostTokenSource | null | undefined,\n): Record<string, string> {\n const merge: Record<string, string> = {}\n for (const key of Object.keys(HOST_TOKENS)) {\n merge[`host.${key}`] = resolveHostToken(key, host) ?? ''\n }\n return merge\n}\n\n/**\n * The email address a visitor writes to the business at: the one Setup →\n * Business saves (`seo.entity.email`), else the one-block copy a site saved\n * before that (`business.supportEmail`). Null when the site has neither. One\n * answer for every place that names it: the `{{host.supportEmail}}` token\n * and so the email footer, the waiver consent, the quote and invoice PDFs,\n * the Reply-To of the quote email (AGL-4097), and the address a refused form\n * or sign-up offers instead (AGL-4136). Trimmed, not validated; a caller\n * putting it in a header checks it is an address.\n */\nexport function siteContactEmail(\n host:\n | {\n seo?: { entity?: { email?: unknown } | null } | null\n business?: { supportEmail?: unknown } | null\n }\n | null\n | undefined,\n): string | null {\n const text = (value: unknown) => (typeof value === 'string' ? value.trim().slice(0, 320) : '')\n return text(host?.seo?.entity?.email) || text(host?.business?.supportEmail) || null\n}\n\n/**\n * Resolves `host.*` tokens across every string prop of a normalized node map.\n *\n * Mirrors `resolveNodesBindings` deliberately — same shallow-copy discipline,\n * same string-props-only rule — so a screen and an email resolve the same token\n * to the same value. The issue's warning is the reason: two resolvers drift,\n * and then the same token means different things depending on where an author\n * typed it.\n *\n * Returns the input untouched when the site has nothing to substitute, so a\n * binding-free tree costs one `Object.entries`.\n */\nexport function resolveNodesHostTokens<T extends Record<string, any>>(\n nodes: T,\n host: HostTokenSource | null | undefined,\n): T {\n if (!nodes) return nodes\n let changed = false\n const next: Record<string, any> = {}\n for (const [id, node] of Object.entries(nodes)) {\n const props = node?.props\n if (!props) {\n next[id] = node\n continue\n }\n let nodeChanged = false\n const nextProps: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(props)) {\n if (typeof value === 'string' && value.includes('{{')) {\n const resolved = resolveHostTokens(value, host)\n nextProps[key] = resolved\n if (resolved !== value) nodeChanged = true\n } else {\n nextProps[key] = value\n }\n }\n next[id] = nodeChanged ? { ...node, props: nextProps } : node\n changed = changed || nodeChanged\n }\n return (changed ? next : nodes) as T\n}\n"],"names":["structuredAddressLine","siteProfileUrls","hostPublicOrigin","normalizeAreaServed","trimmed","value","text","trim","undefined","siteUrl","host","custom","cname","replace","subdomain","businessName","seo","entity","name","displayName","logo","logoUrl","telephoneHref","phone","digits","startsWith","SOCIAL_NETWORK_HOSTS","facebook","instagram","x","linkedin","youtube","tiktok","siteSocialProfileUrl","network","hosts","hostname","URL","toLowerCase","some","endsWith","areasServed","areaServed","socialToken","key","type","label","description","resolve","whenEmpty","HOST_TOKENS","slogan","logoDark","logoDarkUrl","url","telephone","phoneLink","supportEmail","siteContactEmail","address","business","mainArea","split","join","socialLinks","links","labels","map","link","filter","Boolean","length","facebookUrl","instagramUrl","xUrl","linkedinUrl","youtubeUrl","tiktokUrl","hostTokenDefinition","Object","prototype","hasOwnProperty","call","HOST_TOKEN_PATTERN","isHostImageToken","keys","hostTokensIn","includes","match","matchAll","push","resolveHostToken","definition","fallback","resolveHostTokens","_token","String","validateHostTokens","options","allow","issues","seen","Set","has","add","kind","message","shouldOmitBlock","describeHostTokens","values","token","set","hostTokenMerge","merge","slice","email","resolveNodesHostTokens","nodes","changed","next","id","node","entries","props","nodeChanged","nextProps","resolved"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,qBAAqB,QAAQ,wBAAoB;AAC1D,SAASC,eAA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,EACR3G,IAAwC;IAExC,IAAI,CAAC2G,OAAO,OAAOA;IACnB,IAAIC,UAAU;IACd,MAAMC,OAA4B,CAAC;IACnC,KAAK,MAAM,CAACC,IAAIC,KAAK,IAAI1C,OAAO2C,OAAO,CAACL,OAAQ;QAC9C,MAAMM,QAAQF,wBAAAA,KAAME,KAAK;QACzB,IAAI,CAACA,OAAO;YACVJ,IAAI,CAACC,GAAG,GAAGC;YACX;QACF;QACA,IAAIG,cAAc;QAClB,MAAMC,YAAqC,CAAC;QAC5C,KAAK,MAAM,CAACjF,KAAKvC,MAAM,IAAI0E,OAAO2C,OAAO,CAACC,OAAQ;YAChD,IAAI,OAAOtH,UAAU,YAAYA,MAAMkF,QAAQ,CAAC,OAAO;gBACrD,MAAMuC,WAAWhC,kBAAkBzF,OAAOK;gBAC1CmH,SAAS,CAACjF,IAAI,GAAGkF;gBACjB,IAAIA,aAAazH,OAAOuH,cAAc;YACxC,OAAO;gBACLC,SAAS,CAACjF,IAAI,GAAGvC;YACnB;QACF;QACAkH,IAAI,CAACC,GAAG,GAAGI,cAAc,aAAKH;YAAME,OAAOE;aAAcJ;QACzDH,UAAUA,WAAWM;IACvB;IACA,OAAQN,UAAUC,OAAOF;AAC3B"}
|
|
@@ -51,6 +51,9 @@ import { resolveHostToken } from "./host-tokens.js";
|
|
|
51
51
|
const name = (_resolveHostToken = resolveHostToken('businessName', host)) != null ? _resolveHostToken : '';
|
|
52
52
|
const logo = inboxLogo(resolveHostToken('logo', host));
|
|
53
53
|
const url = resolveHostToken('url', host);
|
|
54
|
+
// The site's one email and its one address (AGL-4136): what Setup →
|
|
55
|
+
// Business saves, else the one-block copies a site saved before that —
|
|
56
|
+
// the tokens decide, so the footer says what the pages say.
|
|
54
57
|
const supportEmail = resolveHostToken('supportEmail', host);
|
|
55
58
|
const address = resolveHostToken('address', host);
|
|
56
59
|
// The site's name is resolved here rather than left to the merge, so a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/site-email-chrome.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 * The header and footer a SITE's email is drawn inside (AGL-3370).\n *\n * The site-side twin of `system-email-chrome.ts`. A site's mail to its own\n * customers (an order receipt, a member's password reset, a newsletter\n * confirmation) is the site's, so everything in the chrome is read off the\n * site: its logo or its name in bold, linked to its address; a footer of why\n * the reader is getting the mail, the site's support address, and a\n * `© {year} {business name} · {postal address}` line.\n *\n * Nothing here names the platform. A site's customer bought from the site,\n * not from Aglyn, and a vendor's name at the foot of a receipt is the same\n * leak white-label exists to close, on every plan.\n *\n * Which emails wear it is the caller's decision: the built-in copy and the\n * text-only messages do; a design the site owner published is theirs, placed\n * header and footer included, and is sent as they built it.\n *\n * Pure: no reads, and a clock a test can replace.\n */\n\nimport type {\n EmailChrome,\n EmailChromeFooter,\n} from '@aglyn/shared-util-email/email-render'\n\nimport { resolveHostToken, type HostTokenSource } from './host-tokens'\n\nexport interface SiteEmailChromeInput {\n /** The site's host document, or the fields of it the tokens read. */\n host: HostTokenSource | null | undefined\n /**\n * Why the recipient is getting this email, as a template: the renderer\n * substitutes `{{host.businessName}}` and the email's own tokens in it, as\n * it does in the body.\n */\n reason?: string\n /** The clock the copyright year is read from. */\n now?: () => Date\n}\n\n/**\n * A logo an inbox can draw, or undefined.\n *\n * An SVG is refused: Gmail and Outlook draw no SVG in mail, so a site whose\n * logo is one would open every email with an empty box where its name\n * belongs. The business name in bold is the header instead.\n */\nfunction inboxLogo(url: string | undefined): string | undefined {\n if (!url) return undefined\n return /\\.svg(?:[?#]|$)/i.test(url) || /^data:image\\/svg/i.test(url)\n ? undefined\n : url\n}\n\n/** See the module note. */\nexport function buildSiteEmailChrome(input: SiteEmailChromeInput): EmailChrome {\n const { host } = input\n const now = input.now ?? (() => new Date())\n const name = resolveHostToken('businessName', host) ?? ''\n const logo = inboxLogo(resolveHostToken('logo', host))\n const url = resolveHostToken('url', host)\n const supportEmail = resolveHostToken('supportEmail', host)\n const address = resolveHostToken('address', host)\n\n // The site's name is resolved here rather than left to the merge, so a\n // site that has not set one reads \"this site\" where a merge would leave a\n // hole in the sentence (\"you placed an order with .\").\n const reason = String(input.reason ?? '')\n .replace(/\\{\\{\\s*host\\.businessName\\s*\\}\\}/g, name || 'this site')\n .trim()\n const footer: EmailChromeFooter = {\n ...(reason ? { reason } : {}),\n ...(supportEmail\n ? { support: { label: supportEmail, href: `mailto:${supportEmail}` } }\n : {}),\n ...(name\n ? {\n legal:\n `© ${now().getUTCFullYear()} ${name}` +\n (address ? ` · ${address.replace(/\\s*\\n\\s*/g, ', ')}` : ''),\n }\n : {}),\n }\n\n return {\n header: {\n ...(logo ? { logoUrl: logo } : {}),\n logoAlt: name,\n ...(url ? { href: url } : {}),\n },\n footer,\n }\n}\n"],"names":["resolveHostToken","inboxLogo","url","undefined","test","buildSiteEmailChrome","input","host","now","Date","name","logo","supportEmail","address","reason","String","replace","trim","footer","support","label","href","legal","getUTCFullYear","header","logoUrl","logoAlt"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;CAmBC;AAOD,SAASA,gBAAgB,QAA8B,mBAAe;AAetE;;;;;;CAMC,GACD,SAASC,UAAUC,GAAuB;IACxC,IAAI,CAACA,KAAK,OAAOC;IACjB,OAAO,mBAAmBC,IAAI,CAACF,QAAQ,oBAAoBE,IAAI,CAACF,OAC5DC,YACAD;AACN;AAEA,yBAAyB,GACzB,OAAO,SAASG,qBAAqBC,KAA2B;QAElDA,YACCN,
|
|
1
|
+
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/site-email-chrome.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 * The header and footer a SITE's email is drawn inside (AGL-3370).\n *\n * The site-side twin of `system-email-chrome.ts`. A site's mail to its own\n * customers (an order receipt, a member's password reset, a newsletter\n * confirmation) is the site's, so everything in the chrome is read off the\n * site: its logo or its name in bold, linked to its address; a footer of why\n * the reader is getting the mail, the site's support address, and a\n * `© {year} {business name} · {postal address}` line.\n *\n * Nothing here names the platform. A site's customer bought from the site,\n * not from Aglyn, and a vendor's name at the foot of a receipt is the same\n * leak white-label exists to close, on every plan.\n *\n * Which emails wear it is the caller's decision: the built-in copy and the\n * text-only messages do; a design the site owner published is theirs, placed\n * header and footer included, and is sent as they built it.\n *\n * Pure: no reads, and a clock a test can replace.\n */\n\nimport type {\n EmailChrome,\n EmailChromeFooter,\n} from '@aglyn/shared-util-email/email-render'\n\nimport { resolveHostToken, type HostTokenSource } from './host-tokens'\n\nexport interface SiteEmailChromeInput {\n /** The site's host document, or the fields of it the tokens read. */\n host: HostTokenSource | null | undefined\n /**\n * Why the recipient is getting this email, as a template: the renderer\n * substitutes `{{host.businessName}}` and the email's own tokens in it, as\n * it does in the body.\n */\n reason?: string\n /** The clock the copyright year is read from. */\n now?: () => Date\n}\n\n/**\n * A logo an inbox can draw, or undefined.\n *\n * An SVG is refused: Gmail and Outlook draw no SVG in mail, so a site whose\n * logo is one would open every email with an empty box where its name\n * belongs. The business name in bold is the header instead.\n */\nfunction inboxLogo(url: string | undefined): string | undefined {\n if (!url) return undefined\n return /\\.svg(?:[?#]|$)/i.test(url) || /^data:image\\/svg/i.test(url)\n ? undefined\n : url\n}\n\n/** See the module note. */\nexport function buildSiteEmailChrome(input: SiteEmailChromeInput): EmailChrome {\n const { host } = input\n const now = input.now ?? (() => new Date())\n const name = resolveHostToken('businessName', host) ?? ''\n const logo = inboxLogo(resolveHostToken('logo', host))\n const url = resolveHostToken('url', host)\n // The site's one email and its one address (AGL-4136): what Setup →\n // Business saves, else the one-block copies a site saved before that —\n // the tokens decide, so the footer says what the pages say.\n const supportEmail = resolveHostToken('supportEmail', host)\n const address = resolveHostToken('address', host)\n\n // The site's name is resolved here rather than left to the merge, so a\n // site that has not set one reads \"this site\" where a merge would leave a\n // hole in the sentence (\"you placed an order with .\").\n const reason = String(input.reason ?? '')\n .replace(/\\{\\{\\s*host\\.businessName\\s*\\}\\}/g, name || 'this site')\n .trim()\n const footer: EmailChromeFooter = {\n ...(reason ? { reason } : {}),\n ...(supportEmail\n ? { support: { label: supportEmail, href: `mailto:${supportEmail}` } }\n : {}),\n ...(name\n ? {\n legal:\n `© ${now().getUTCFullYear()} ${name}` +\n (address ? ` · ${address.replace(/\\s*\\n\\s*/g, ', ')}` : ''),\n }\n : {}),\n }\n\n return {\n header: {\n ...(logo ? { logoUrl: logo } : {}),\n logoAlt: name,\n ...(url ? { href: url } : {}),\n },\n footer,\n }\n}\n"],"names":["resolveHostToken","inboxLogo","url","undefined","test","buildSiteEmailChrome","input","host","now","Date","name","logo","supportEmail","address","reason","String","replace","trim","footer","support","label","href","legal","getUTCFullYear","header","logoUrl","logoAlt"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;CAmBC;AAOD,SAASA,gBAAgB,QAA8B,mBAAe;AAetE;;;;;;CAMC,GACD,SAASC,UAAUC,GAAuB;IACxC,IAAI,CAACA,KAAK,OAAOC;IACjB,OAAO,mBAAmBC,IAAI,CAACF,QAAQ,oBAAoBE,IAAI,CAACF,OAC5DC,YACAD;AACN;AAEA,yBAAyB,GACzB,OAAO,SAASG,qBAAqBC,KAA2B;QAElDA,YACCN,mBAYSM;IAdtB,MAAM,EAAEC,IAAI,EAAE,GAAGD;IACjB,MAAME,OAAMF,aAAAA,MAAME,GAAG,YAATF,aAAc,IAAM,IAAIG;IACpC,MAAMC,QAAOV,oBAAAA,iBAAiB,gBAAgBO,iBAAjCP,oBAA0C;IACvD,MAAMW,OAAOV,UAAUD,iBAAiB,QAAQO;IAChD,MAAML,MAAMF,iBAAiB,OAAOO;IACpC,oEAAoE;IACpE,uEAAuE;IACvE,4DAA4D;IAC5D,MAAMK,eAAeZ,iBAAiB,gBAAgBO;IACtD,MAAMM,UAAUb,iBAAiB,WAAWO;IAE5C,uEAAuE;IACvE,0EAA0E;IAC1E,uDAAuD;IACvD,MAAMO,SAASC,QAAOT,gBAAAA,MAAMQ,MAAM,YAAZR,gBAAgB,IACnCU,OAAO,CAAC,qCAAqCN,QAAQ,aACrDO,IAAI;IACP,MAAMC,SAA4B,aAC5BJ,SAAS;QAAEA;IAAO,IAAI,CAAC,GACvBF,eACA;QAAEO,SAAS;YAAEC,OAAOR;YAAcS,MAAM,CAAC,OAAO,EAAET,cAAc;QAAC;IAAE,IACnE,CAAC,GACDF,OACA;QACEY,OACE,CAAC,EAAE,EAAEd,MAAMe,cAAc,GAAG,CAAC,EAAEb,MAAM,GACpCG,CAAAA,UAAU,CAAC,GAAG,EAAEA,QAAQG,OAAO,CAAC,aAAa,OAAO,GAAG,EAAC;IAC7D,IACA,CAAC;IAGP,OAAO;QACLQ,QAAQ,aACFb,OAAO;YAAEc,SAASd;QAAK,IAAI,CAAC;YAChCe,SAAShB;WACLR,MAAM;YAAEmB,MAAMnB;QAAI,IAAI,CAAC;QAE7BgB;IACF;AACF"}
|
|
@@ -15,6 +15,8 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
|
15
15
|
* See the License for the specific language governing permissions and
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/ import { AUTHOR_NAME_MAX_LENGTH, SITE_ENTITY_FRAGMENT, contentAuthorSchemaType, hostSeoEntityImageJsonLd, siteProfileUrls } from "./content-authors.js";
|
|
18
|
+
import { SITE_SLOGAN_MAX_LENGTH } from "./business-details.js";
|
|
19
|
+
import { siteContactEmail } from "./host-tokens.js";
|
|
18
20
|
import { PAYMENT_ACCEPTED_MAX_LENGTH, PRICE_RANGE_MAX_LENGTH, localBusinessType, normalizeAreaServed, parseOpeningHours } from "./local-business.js";
|
|
19
21
|
/*
|
|
20
22
|
* The SITE entity's JSON-LD: the nested `publisher` and the standalone node.
|
|
@@ -125,7 +127,7 @@ import { PAYMENT_ACCEPTED_MAX_LENGTH, PRICE_RANGE_MAX_LENGTH, localBusinessType,
|
|
|
125
127
|
* Returns `undefined` only when there is no name to be had from anywhere —
|
|
126
128
|
* a host document with no entity, no display name and no SEO title.
|
|
127
129
|
*/ export function siteEntityJsonLd(host, context) {
|
|
128
|
-
var _ref, _ref1;
|
|
130
|
+
var _ref, _ref1, _siteContactEmail;
|
|
129
131
|
var _host_seo, _host_seo1, _context_origin, _host_seo2, _entity_address, _entity_address1, _entity_address2, _entity_address3, _entity_address4;
|
|
130
132
|
const entity = (_ref = host == null ? void 0 : (_host_seo = host.seo) == null ? void 0 : _host_seo.entity) != null ? _ref : undefined;
|
|
131
133
|
const name = text(entity == null ? void 0 : entity.name, 400) || text(host == null ? void 0 : host.displayName, 400) || text(host == null ? void 0 : (_host_seo1 = host.seo) == null ? void 0 : _host_seo1.title, 400);
|
|
@@ -148,7 +150,13 @@ import { PAYMENT_ACCEPTED_MAX_LENGTH, PRICE_RANGE_MAX_LENGTH, localBusinessType,
|
|
|
148
150
|
present — `schema.org` requires neither, and a consumer that finds a
|
|
149
151
|
ContactPoint with no channel has been told less than it would learn from
|
|
150
152
|
its absence.
|
|
151
|
-
|
|
153
|
+
|
|
154
|
+
The email is the site's one email (AGL-4136): what Setup → Business
|
|
155
|
+
profile saves to the entity, else the older one-block copy, so a site
|
|
156
|
+
whose email lives only there still says how to reach it.
|
|
157
|
+
*/ // `SiteEntityHost` names only the social links under `business`; the host
|
|
158
|
+
// document handed here is the whole document, older email copy included.
|
|
159
|
+
const email = text((_siteContactEmail = siteContactEmail(host)) != null ? _siteContactEmail : '', 320);
|
|
152
160
|
const telephone = text(entity == null ? void 0 : entity.telephone, 64);
|
|
153
161
|
const contactType = text(entity == null ? void 0 : entity.contactType, 120) || 'customer support';
|
|
154
162
|
const contactPoint = email || telephone ? _extends({
|
|
@@ -169,6 +177,11 @@ import { PAYMENT_ACCEPTED_MAX_LENGTH, PRICE_RANGE_MAX_LENGTH, localBusinessType,
|
|
|
169
177
|
const address = Object.entries(addressFields).filter(([, value])=>value);
|
|
170
178
|
const schemaType = siteEntitySchemaType(entity);
|
|
171
179
|
const picture = hostSeoEntityImageJsonLd(entity, context);
|
|
180
|
+
/*
|
|
181
|
+
The business's slogan from Setup → Business profile (AGL-4136). `slogan` is an
|
|
182
|
+
Organization property, which every LocalBusiness type inherits; a Person
|
|
183
|
+
has none, so a site published by a person never carries it.
|
|
184
|
+
*/ const slogan = schemaType === 'Person' ? '' : text(entity == null ? void 0 : entity.slogan, SITE_SLOGAN_MAX_LENGTH);
|
|
172
185
|
const business = schemaType !== 'Person' && schemaType !== 'Organization' ? localBusinessJsonLd(entity, telephone, picture.logo) : {};
|
|
173
186
|
return _extends({
|
|
174
187
|
'@context': 'https://schema.org',
|
|
@@ -179,6 +192,8 @@ import { PAYMENT_ACCEPTED_MAX_LENGTH, PRICE_RANGE_MAX_LENGTH, localBusinessType,
|
|
|
179
192
|
name
|
|
180
193
|
}, description ? {
|
|
181
194
|
description
|
|
195
|
+
} : {}, slogan ? {
|
|
196
|
+
slogan
|
|
182
197
|
} : {}, url ? {
|
|
183
198
|
url
|
|
184
199
|
} : {}, picture, sameAs.length ? {
|