@aglyn/aglyn 1.0.0-beta.253 → 1.0.0-beta.255
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-profile-values.d.ts +83 -0
- package/src/lib/app-utils/business-profile-values.js +160 -0
- package/src/lib/app-utils/business-profile-values.js.map +1 -0
- package/src/lib/app-utils/business-profile.d.ts +7 -60
- package/src/lib/app-utils/business-profile.js +2 -172
- package/src/lib/app-utils/business-profile.js.map +1 -1
- package/src/lib/app-utils/docs-help-sections.generated.js +8 -5
- package/src/lib/app-utils/docs-help-sections.generated.js.map +1 -1
- package/src/lib/app-utils/docs-help.generated.d.ts +13 -7
- package/src/lib/app-utils/docs-help.generated.js +53 -16
- package/src/lib/app-utils/docs-help.generated.js.map +1 -1
- package/src/lib/app-utils/docs-index.generated.js +237 -6
- package/src/lib/app-utils/docs-index.generated.js.map +1 -1
- package/src/lib/app-utils/lockdown.d.ts +6 -0
- package/src/lib/app-utils/lockdown.js +20 -0
- package/src/lib/app-utils/lockdown.js.map +1 -1
- package/src/lib/app-utils/native-app-association.d.ts +129 -0
- package/src/lib/app-utils/native-app-association.js +248 -0
- package/src/lib/app-utils/native-app-association.js.map +1 -0
- package/src/lib/app-utils/sso-enforcement.d.ts +69 -0
- package/src/lib/app-utils/sso-enforcement.js +66 -0
- package/src/lib/app-utils/sso-enforcement.js.map +1 -0
- package/src/lib/app-utils/time-zone-choices.d.ts +46 -0
- package/src/lib/app-utils/time-zone-choices.js +469 -0
- package/src/lib/app-utils/time-zone-choices.js.map +1 -0
- package/src/lib/data-transfer/site-package-diff.d.ts +108 -0
- package/src/lib/data-transfer/site-package-diff.js +268 -0
- package/src/lib/data-transfer/site-package-diff.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aglyn/aglyn",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.255",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"homepage": "https://aglyn.com",
|
|
6
6
|
"repository": {
|
|
@@ -37,16 +37,16 @@
|
|
|
37
37
|
"./package.json": "./package.json"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@aglyn/shared-data-enums": "1.0.0-beta.
|
|
41
|
-
"@aglyn/shared-data-mdi": "1.0.0-beta.
|
|
42
|
-
"@aglyn/shared-data-types": "1.0.0-beta.
|
|
43
|
-
"@aglyn/shared-util-email": "1.0.0-beta.
|
|
44
|
-
"@aglyn/shared-util-first-touch": "1.0.0-beta.
|
|
45
|
-
"@aglyn/shared-util-http": "1.0.0-beta.
|
|
46
|
-
"@aglyn/shared-util-logger": "1.0.0-beta.
|
|
47
|
-
"@aglyn/shared-util-timestamp": "1.0.0-beta.
|
|
48
|
-
"@aglyn/shared-util-tools": "1.0.0-beta.
|
|
49
|
-
"@aglyn/shared-util-vendor": "1.0.0-beta.
|
|
40
|
+
"@aglyn/shared-data-enums": "1.0.0-beta.255",
|
|
41
|
+
"@aglyn/shared-data-mdi": "1.0.0-beta.255",
|
|
42
|
+
"@aglyn/shared-data-types": "1.0.0-beta.255",
|
|
43
|
+
"@aglyn/shared-util-email": "1.0.0-beta.255",
|
|
44
|
+
"@aglyn/shared-util-first-touch": "1.0.0-beta.255",
|
|
45
|
+
"@aglyn/shared-util-http": "1.0.0-beta.255",
|
|
46
|
+
"@aglyn/shared-util-logger": "1.0.0-beta.255",
|
|
47
|
+
"@aglyn/shared-util-timestamp": "1.0.0-beta.255",
|
|
48
|
+
"@aglyn/shared-util-tools": "1.0.0-beta.255",
|
|
49
|
+
"@aglyn/shared-util-vendor": "1.0.0-beta.255",
|
|
50
50
|
"@data-driven-forms/react-form-renderer": "^4.2.0",
|
|
51
51
|
"@msgpack/msgpack": "^3.1.3",
|
|
52
52
|
"@types/unist": "^3.0.3",
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
* The pure part of the business profile: its fields, limits, sources and the
|
|
19
|
+
* write rules (what the owner typed is theirs; a changed field becomes the
|
|
20
|
+
* owner's). It imports nothing, so the native apps replay it from
|
|
21
|
+
* `function-cases.generated.json` (AGL-3671); `business-profile.ts` re-exports
|
|
22
|
+
* all of it, so every existing import is unchanged.
|
|
23
|
+
*/
|
|
24
|
+
/** The collection a profile document lives in, under a host or an org. */
|
|
25
|
+
export declare const BUSINESS_PROFILE_SUBCOLLECTION = "businessProfile";
|
|
26
|
+
/** The site's profile document id. */
|
|
27
|
+
export declare const BUSINESS_PROFILE_SITE_DOC = "profile";
|
|
28
|
+
/** The workspace defaults document id. */
|
|
29
|
+
export declare const BUSINESS_PROFILE_WORKSPACE_DOC = "defaults";
|
|
30
|
+
/** Who wrote a stored value: the owner, the guided start's answers, or a generator. */
|
|
31
|
+
export type BusinessProfileSource = 'owner' | 'start' | 'ai';
|
|
32
|
+
/**
|
|
33
|
+
* Where a RESOLVED value came from: a stored source, the site's own settings
|
|
34
|
+
* (`seo.entity`, `business`, the display name), or the workspace defaults.
|
|
35
|
+
*/
|
|
36
|
+
export type BusinessProfileOrigin = BusinessProfileSource | 'site' | 'workspace';
|
|
37
|
+
export declare const BUSINESS_TONES: readonly ["friendly", "professional", "playful", "premium", "plain"];
|
|
38
|
+
export type BusinessTone = (typeof BUSINESS_TONES)[number];
|
|
39
|
+
/** Each tone as the owner picks it and as a writer is told it. */
|
|
40
|
+
export declare const BUSINESS_TONE_LABELS: Readonly<Record<BusinessTone, string>>;
|
|
41
|
+
/** The fields the profile document stores itself. */
|
|
42
|
+
export declare const BUSINESS_PROFILE_FIELDS: readonly ["whatYouDo", "services", "serviceArea", "audience", "tone", "toneNotes"];
|
|
43
|
+
export type BusinessProfileField = (typeof BUSINESS_PROFILE_FIELDS)[number];
|
|
44
|
+
/** Each field's ceiling, in characters; `services` is per item. */
|
|
45
|
+
export declare const BUSINESS_PROFILE_MAX_CHARS: Readonly<Record<Exclude<BusinessProfileField, 'tone'>, number>>;
|
|
46
|
+
/** At most this many services are kept. */
|
|
47
|
+
export declare const BUSINESS_PROFILE_MAX_SERVICES = 12;
|
|
48
|
+
/** The stored document, at either level. */
|
|
49
|
+
export interface BusinessProfileDoc {
|
|
50
|
+
whatYouDo?: string;
|
|
51
|
+
services?: string[];
|
|
52
|
+
serviceArea?: string;
|
|
53
|
+
audience?: string;
|
|
54
|
+
tone?: BusinessTone | null;
|
|
55
|
+
toneNotes?: string;
|
|
56
|
+
/** Who wrote each stored value; a value without one is the owner's. */
|
|
57
|
+
sources?: Partial<Record<BusinessProfileField, BusinessProfileSource>>;
|
|
58
|
+
updatedAt?: unknown;
|
|
59
|
+
updatedBy?: string | null;
|
|
60
|
+
}
|
|
61
|
+
/** The values a write carries, before they are sanitized. */
|
|
62
|
+
export type BusinessProfileValues = Partial<Pick<BusinessProfileDoc, 'whatYouDo' | 'services' | 'serviceArea' | 'audience' | 'tone' | 'toneNotes'>>;
|
|
63
|
+
export declare const text: (value: unknown, max: number) => string;
|
|
64
|
+
/** One field's stored value, sanitized; empty is `''`, `[]` or `null`. */
|
|
65
|
+
export declare function fieldValue(doc: BusinessProfileValues | null | undefined, field: BusinessProfileField): unknown;
|
|
66
|
+
export declare const isEmpty: (value: unknown) => boolean;
|
|
67
|
+
/** The source a stored, non-empty value carries; the owner's when none is recorded. */
|
|
68
|
+
export declare function businessProfileSourceOf(doc: BusinessProfileDoc | null | undefined, field: BusinessProfileField): BusinessProfileSource | null;
|
|
69
|
+
/** Every value a write may carry, sanitized; an absent field stays absent. */
|
|
70
|
+
export declare function sanitizeBusinessProfileValues(values: BusinessProfileValues): BusinessProfileValues;
|
|
71
|
+
/**
|
|
72
|
+
* The document a generator's or the guided start's values make of the stored
|
|
73
|
+
* one: each value fills a field that is empty or was written by a source that
|
|
74
|
+
* weighs less, and nothing else. `null` when nothing would change, so a caller
|
|
75
|
+
* writes only when there is something to write.
|
|
76
|
+
*/
|
|
77
|
+
export declare function mergeBusinessProfilePrefill(current: BusinessProfileDoc | null | undefined, values: BusinessProfileValues, source: Exclude<BusinessProfileSource, 'owner'>): BusinessProfileDoc | null;
|
|
78
|
+
/**
|
|
79
|
+
* The document the owner's save makes: every field they changed becomes
|
|
80
|
+
* theirs, and a field they left as it was keeps the source it had — so saving
|
|
81
|
+
* the form after correcting one line does not claim every suggestion on it.
|
|
82
|
+
*/
|
|
83
|
+
export declare function businessProfileOwnerWrite(current: BusinessProfileDoc | null | undefined, edited: BusinessProfileValues): Pick<BusinessProfileDoc, BusinessProfileField | 'sources'>;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2026 Aglyn LLC
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/ /**
|
|
18
|
+
* The pure part of the business profile: its fields, limits, sources and the
|
|
19
|
+
* write rules (what the owner typed is theirs; a changed field becomes the
|
|
20
|
+
* owner's). It imports nothing, so the native apps replay it from
|
|
21
|
+
* `function-cases.generated.json` (AGL-3671); `business-profile.ts` re-exports
|
|
22
|
+
* all of it, so every existing import is unchanged.
|
|
23
|
+
*/ /** The collection a profile document lives in, under a host or an org. */ export const BUSINESS_PROFILE_SUBCOLLECTION = 'businessProfile';
|
|
24
|
+
/** The site's profile document id. */ export const BUSINESS_PROFILE_SITE_DOC = 'profile';
|
|
25
|
+
/** The workspace defaults document id. */ export const BUSINESS_PROFILE_WORKSPACE_DOC = 'defaults';
|
|
26
|
+
/** How much a source's words weigh: a higher rank is never replaced by a lower one. */ const SOURCE_RANK = {
|
|
27
|
+
ai: 1,
|
|
28
|
+
start: 2,
|
|
29
|
+
owner: 3
|
|
30
|
+
};
|
|
31
|
+
export const BUSINESS_TONES = [
|
|
32
|
+
'friendly',
|
|
33
|
+
'professional',
|
|
34
|
+
'playful',
|
|
35
|
+
'premium',
|
|
36
|
+
'plain'
|
|
37
|
+
];
|
|
38
|
+
/** Each tone as the owner picks it and as a writer is told it. */ export const BUSINESS_TONE_LABELS = {
|
|
39
|
+
friendly: 'Friendly and warm',
|
|
40
|
+
professional: 'Professional and clear',
|
|
41
|
+
playful: 'Playful and upbeat',
|
|
42
|
+
premium: 'Premium and refined',
|
|
43
|
+
plain: 'Plain and direct'
|
|
44
|
+
};
|
|
45
|
+
/** The fields the profile document stores itself. */ export const BUSINESS_PROFILE_FIELDS = [
|
|
46
|
+
'whatYouDo',
|
|
47
|
+
'services',
|
|
48
|
+
'serviceArea',
|
|
49
|
+
'audience',
|
|
50
|
+
'tone',
|
|
51
|
+
'toneNotes'
|
|
52
|
+
];
|
|
53
|
+
/** Each field's ceiling, in characters; `services` is per item. */ export const BUSINESS_PROFILE_MAX_CHARS = {
|
|
54
|
+
whatYouDo: 200,
|
|
55
|
+
services: 60,
|
|
56
|
+
serviceArea: 120,
|
|
57
|
+
audience: 160,
|
|
58
|
+
toneNotes: 200
|
|
59
|
+
};
|
|
60
|
+
/** At most this many services are kept. */ export const BUSINESS_PROFILE_MAX_SERVICES = 12;
|
|
61
|
+
export const text = (value, max)=>typeof value === 'string' ? value.replace(/\s+/g, ' ').trim().slice(0, max) : '';
|
|
62
|
+
const tone = (value)=>BUSINESS_TONES.includes(value) ? value : null;
|
|
63
|
+
const services = (value)=>{
|
|
64
|
+
const items = Array.isArray(value) ? value : typeof value === 'string' ? value.split(/[,\n]/) : [];
|
|
65
|
+
const seen = new Set();
|
|
66
|
+
const kept = [];
|
|
67
|
+
for (const item of items){
|
|
68
|
+
const name = text(item, BUSINESS_PROFILE_MAX_CHARS.services);
|
|
69
|
+
const key = name.toLowerCase();
|
|
70
|
+
if (!name || seen.has(key)) continue;
|
|
71
|
+
seen.add(key);
|
|
72
|
+
kept.push(name);
|
|
73
|
+
if (kept.length >= BUSINESS_PROFILE_MAX_SERVICES) break;
|
|
74
|
+
}
|
|
75
|
+
return kept;
|
|
76
|
+
};
|
|
77
|
+
/** One field's stored value, sanitized; empty is `''`, `[]` or `null`. */ export function fieldValue(doc, field) {
|
|
78
|
+
switch(field){
|
|
79
|
+
case 'services':
|
|
80
|
+
return services(doc == null ? void 0 : doc.services);
|
|
81
|
+
case 'tone':
|
|
82
|
+
return tone(doc == null ? void 0 : doc.tone);
|
|
83
|
+
default:
|
|
84
|
+
return text(doc == null ? void 0 : doc[field], BUSINESS_PROFILE_MAX_CHARS[field]);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
export const isEmpty = (value)=>value === null || value === '' || Array.isArray(value) && value.length === 0;
|
|
88
|
+
/** The source a stored, non-empty value carries; the owner's when none is recorded. */ export function businessProfileSourceOf(doc, field) {
|
|
89
|
+
var _doc_sources;
|
|
90
|
+
if (isEmpty(fieldValue(doc, field))) return null;
|
|
91
|
+
const source = doc == null ? void 0 : (_doc_sources = doc.sources) == null ? void 0 : _doc_sources[field];
|
|
92
|
+
return source && source in SOURCE_RANK ? source : 'owner';
|
|
93
|
+
}
|
|
94
|
+
/** Every value a write may carry, sanitized; an absent field stays absent. */ export function sanitizeBusinessProfileValues(values) {
|
|
95
|
+
const clean = {};
|
|
96
|
+
for (const field of BUSINESS_PROFILE_FIELDS){
|
|
97
|
+
if (!(field in values)) continue;
|
|
98
|
+
clean[field] = fieldValue(values, field);
|
|
99
|
+
}
|
|
100
|
+
return clean;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The document a generator's or the guided start's values make of the stored
|
|
104
|
+
* one: each value fills a field that is empty or was written by a source that
|
|
105
|
+
* weighs less, and nothing else. `null` when nothing would change, so a caller
|
|
106
|
+
* writes only when there is something to write.
|
|
107
|
+
*/ export function mergeBusinessProfilePrefill(current, values, source) {
|
|
108
|
+
var _ref;
|
|
109
|
+
const clean = sanitizeBusinessProfileValues(values);
|
|
110
|
+
const next = _extends({}, current != null ? current : {}, {
|
|
111
|
+
sources: _extends({}, (_ref = current == null ? void 0 : current.sources) != null ? _ref : {})
|
|
112
|
+
});
|
|
113
|
+
let changed = false;
|
|
114
|
+
for (const field of BUSINESS_PROFILE_FIELDS){
|
|
115
|
+
var _current_sources;
|
|
116
|
+
if (!(field in clean)) continue;
|
|
117
|
+
const value = clean[field];
|
|
118
|
+
if (isEmpty(value)) continue;
|
|
119
|
+
// An explicit source counts even on an empty value: a field the owner
|
|
120
|
+
// cleared stays cleared rather than being refilled behind them.
|
|
121
|
+
const recorded = current == null ? void 0 : (_current_sources = current.sources) == null ? void 0 : _current_sources[field];
|
|
122
|
+
const held = recorded && recorded in SOURCE_RANK ? recorded : businessProfileSourceOf(current, field);
|
|
123
|
+
if (held && SOURCE_RANK[held] >= SOURCE_RANK[source]) continue;
|
|
124
|
+
if (JSON.stringify(fieldValue(current, field)) === JSON.stringify(value)) continue;
|
|
125
|
+
next[field] = value;
|
|
126
|
+
next.sources[field] = source;
|
|
127
|
+
changed = true;
|
|
128
|
+
}
|
|
129
|
+
return changed ? next : null;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The document the owner's save makes: every field they changed becomes
|
|
133
|
+
* theirs, and a field they left as it was keeps the source it had — so saving
|
|
134
|
+
* the form after correcting one line does not claim every suggestion on it.
|
|
135
|
+
*/ export function businessProfileOwnerWrite(current, edited) {
|
|
136
|
+
const clean = sanitizeBusinessProfileValues(edited);
|
|
137
|
+
const next = {};
|
|
138
|
+
const sources = {};
|
|
139
|
+
for (const field of BUSINESS_PROFILE_FIELDS){
|
|
140
|
+
var _businessProfileSourceOf;
|
|
141
|
+
const before = fieldValue(current, field);
|
|
142
|
+
const after = field in clean ? clean[field] : before;
|
|
143
|
+
next[field] = after;
|
|
144
|
+
const same = JSON.stringify(before) === JSON.stringify(after);
|
|
145
|
+
if (isEmpty(after)) {
|
|
146
|
+
var _current_sources;
|
|
147
|
+
// A suggestion the owner deleted is their decision, and recorded as
|
|
148
|
+
// one, so the next prefill does not put it back.
|
|
149
|
+
if (!same) sources[field] = 'owner';
|
|
150
|
+
else if ((current == null ? void 0 : (_current_sources = current.sources) == null ? void 0 : _current_sources[field]) === 'owner') sources[field] = 'owner';
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
sources[field] = same ? (_businessProfileSourceOf = businessProfileSourceOf(current, field)) != null ? _businessProfileSourceOf : 'owner' : 'owner';
|
|
154
|
+
}
|
|
155
|
+
return _extends({}, next, {
|
|
156
|
+
sources
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
//# sourceMappingURL=business-profile-values.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/business-profile-values.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 pure part of the business profile: its fields, limits, sources and the\n * write rules (what the owner typed is theirs; a changed field becomes the\n * owner's). It imports nothing, so the native apps replay it from\n * `function-cases.generated.json` (AGL-3671); `business-profile.ts` re-exports\n * all of it, so every existing import is unchanged.\n */\n\n/** The collection a profile document lives in, under a host or an org. */\nexport const BUSINESS_PROFILE_SUBCOLLECTION = 'businessProfile'\n/** The site's profile document id. */\nexport const BUSINESS_PROFILE_SITE_DOC = 'profile'\n/** The workspace defaults document id. */\nexport const BUSINESS_PROFILE_WORKSPACE_DOC = 'defaults'\n\n/** Who wrote a stored value: the owner, the guided start's answers, or a generator. */\nexport type BusinessProfileSource = 'owner' | 'start' | 'ai'\n\n/**\n * Where a RESOLVED value came from: a stored source, the site's own settings\n * (`seo.entity`, `business`, the display name), or the workspace defaults.\n */\nexport type BusinessProfileOrigin = BusinessProfileSource | 'site' | 'workspace'\n\n/** How much a source's words weigh: a higher rank is never replaced by a lower one. */\nconst SOURCE_RANK: Readonly<Record<BusinessProfileSource, number>> = {\n ai: 1,\n start: 2,\n owner: 3,\n}\n\nexport const BUSINESS_TONES = ['friendly', 'professional', 'playful', 'premium', 'plain'] as const\nexport type BusinessTone = (typeof BUSINESS_TONES)[number]\n\n/** Each tone as the owner picks it and as a writer is told it. */\nexport const BUSINESS_TONE_LABELS: Readonly<Record<BusinessTone, string>> = {\n friendly: 'Friendly and warm',\n professional: 'Professional and clear',\n playful: 'Playful and upbeat',\n premium: 'Premium and refined',\n plain: 'Plain and direct',\n}\n\n/** The fields the profile document stores itself. */\nexport const BUSINESS_PROFILE_FIELDS = [\n 'whatYouDo',\n 'services',\n 'serviceArea',\n 'audience',\n 'tone',\n 'toneNotes',\n] as const\nexport type BusinessProfileField = (typeof BUSINESS_PROFILE_FIELDS)[number]\n\n/** Each field's ceiling, in characters; `services` is per item. */\nexport const BUSINESS_PROFILE_MAX_CHARS: Readonly<Record<Exclude<BusinessProfileField, 'tone'>, number>> = {\n whatYouDo: 200,\n services: 60,\n serviceArea: 120,\n audience: 160,\n toneNotes: 200,\n}\n\n/** At most this many services are kept. */\nexport const BUSINESS_PROFILE_MAX_SERVICES = 12\n\n/** The stored document, at either level. */\nexport interface BusinessProfileDoc {\n whatYouDo?: string\n services?: string[]\n serviceArea?: string\n audience?: string\n tone?: BusinessTone | null\n toneNotes?: string\n /** Who wrote each stored value; a value without one is the owner's. */\n sources?: Partial<Record<BusinessProfileField, BusinessProfileSource>>\n updatedAt?: unknown\n updatedBy?: string | null\n}\n\n/** The values a write carries, before they are sanitized. */\nexport type BusinessProfileValues = Partial<\n Pick<BusinessProfileDoc, 'whatYouDo' | 'services' | 'serviceArea' | 'audience' | 'tone' | 'toneNotes'>\n>\n\nexport const text = (value: unknown, max: number): string =>\n typeof value === 'string' ? value.replace(/\\s+/g, ' ').trim().slice(0, max) : ''\n\nconst tone = (value: unknown): BusinessTone | null =>\n (BUSINESS_TONES as readonly unknown[]).includes(value) ? (value as BusinessTone) : null\n\nconst services = (value: unknown): string[] => {\n const items = Array.isArray(value) ? value : typeof value === 'string' ? value.split(/[,\\n]/) : []\n const seen = new Set<string>()\n const kept: string[] = []\n for (const item of items) {\n const name = text(item, BUSINESS_PROFILE_MAX_CHARS.services)\n const key = name.toLowerCase()\n if (!name || seen.has(key)) continue\n seen.add(key)\n kept.push(name)\n if (kept.length >= BUSINESS_PROFILE_MAX_SERVICES) break\n }\n return kept\n}\n\n/** One field's stored value, sanitized; empty is `''`, `[]` or `null`. */\nexport function fieldValue(doc: BusinessProfileValues | null | undefined, field: BusinessProfileField): unknown {\n switch (field) {\n case 'services':\n return services(doc?.services)\n case 'tone':\n return tone(doc?.tone)\n default:\n return text(doc?.[field], BUSINESS_PROFILE_MAX_CHARS[field])\n }\n}\n\nexport const isEmpty = (value: unknown): boolean =>\n value === null || value === '' || (Array.isArray(value) && value.length === 0)\n\n/** The source a stored, non-empty value carries; the owner's when none is recorded. */\nexport function businessProfileSourceOf(\n doc: BusinessProfileDoc | null | undefined,\n field: BusinessProfileField,\n): BusinessProfileSource | null {\n if (isEmpty(fieldValue(doc, field))) return null\n const source = doc?.sources?.[field]\n return source && source in SOURCE_RANK ? source : 'owner'\n}\n\n/** Every value a write may carry, sanitized; an absent field stays absent. */\nexport function sanitizeBusinessProfileValues(values: BusinessProfileValues): BusinessProfileValues {\n const clean: BusinessProfileValues = {}\n for (const field of BUSINESS_PROFILE_FIELDS) {\n if (!(field in values)) continue\n ;(clean as Record<string, unknown>)[field] = fieldValue(values, field)\n }\n return clean\n}\n\n/**\n * The document a generator's or the guided start's values make of the stored\n * one: each value fills a field that is empty or was written by a source that\n * weighs less, and nothing else. `null` when nothing would change, so a caller\n * writes only when there is something to write.\n */\nexport function mergeBusinessProfilePrefill(\n current: BusinessProfileDoc | null | undefined,\n values: BusinessProfileValues,\n source: Exclude<BusinessProfileSource, 'owner'>,\n): BusinessProfileDoc | null {\n const clean = sanitizeBusinessProfileValues(values)\n const next: BusinessProfileDoc = { ...(current ?? {}), sources: { ...(current?.sources ?? {}) } }\n let changed = false\n for (const field of BUSINESS_PROFILE_FIELDS) {\n if (!(field in clean)) continue\n const value = (clean as Record<string, unknown>)[field]\n if (isEmpty(value)) continue\n // An explicit source counts even on an empty value: a field the owner\n // cleared stays cleared rather than being refilled behind them.\n const recorded = current?.sources?.[field]\n const held = recorded && recorded in SOURCE_RANK ? recorded : businessProfileSourceOf(current, field)\n if (held && SOURCE_RANK[held] >= SOURCE_RANK[source]) continue\n if (JSON.stringify(fieldValue(current, field)) === JSON.stringify(value)) continue\n ;(next as Record<string, unknown>)[field] = value\n next.sources![field] = source\n changed = true\n }\n return changed ? next : null\n}\n\n/**\n * The document the owner's save makes: every field they changed becomes\n * theirs, and a field they left as it was keeps the source it had — so saving\n * the form after correcting one line does not claim every suggestion on it.\n */\nexport function businessProfileOwnerWrite(\n current: BusinessProfileDoc | null | undefined,\n edited: BusinessProfileValues,\n): Pick<BusinessProfileDoc, BusinessProfileField | 'sources'> {\n const clean = sanitizeBusinessProfileValues(edited)\n const next: Record<string, unknown> = {}\n const sources: Partial<Record<BusinessProfileField, BusinessProfileSource>> = {}\n for (const field of BUSINESS_PROFILE_FIELDS) {\n const before = fieldValue(current, field)\n const after = field in clean ? (clean as Record<string, unknown>)[field] : before\n next[field] = after\n const same = JSON.stringify(before) === JSON.stringify(after)\n if (isEmpty(after)) {\n // A suggestion the owner deleted is their decision, and recorded as\n // one, so the next prefill does not put it back.\n if (!same) sources[field] = 'owner'\n else if (current?.sources?.[field] === 'owner') sources[field] = 'owner'\n continue\n }\n sources[field] = same ? (businessProfileSourceOf(current, field) ?? 'owner') : 'owner'\n }\n return { ...(next as Pick<BusinessProfileDoc, BusinessProfileField>), sources }\n}\n"],"names":["BUSINESS_PROFILE_SUBCOLLECTION","BUSINESS_PROFILE_SITE_DOC","BUSINESS_PROFILE_WORKSPACE_DOC","SOURCE_RANK","ai","start","owner","BUSINESS_TONES","BUSINESS_TONE_LABELS","friendly","professional","playful","premium","plain","BUSINESS_PROFILE_FIELDS","BUSINESS_PROFILE_MAX_CHARS","whatYouDo","services","serviceArea","audience","toneNotes","BUSINESS_PROFILE_MAX_SERVICES","text","value","max","replace","trim","slice","tone","includes","items","Array","isArray","split","seen","Set","kept","item","name","key","toLowerCase","has","add","push","length","fieldValue","doc","field","isEmpty","businessProfileSourceOf","source","sources","sanitizeBusinessProfileValues","values","clean","mergeBusinessProfilePrefill","current","next","changed","recorded","held","JSON","stringify","businessProfileOwnerWrite","edited","before","after","same"],"mappings":";AAAA;;;;;;;;;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AAA,QAASL,OAAO,qBAAhBK,gBAAkB,CAACT,MAAM,MAAK,SAASI,OAAO,CAACJ,MAAM,GAAG;YACjE;QACF;QACAI,OAAO,CAACJ,MAAM,GAAGoB,QAAQlB,2BAAAA,wBAAwBO,SAAST,kBAAjCE,2BAA2C,UAAW;IACjF;IACA,OAAO,aAAMQ;QAAyDN;;AACxE"}
|
|
@@ -15,6 +15,13 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
import { type HostSeoEntity } from './content-authors';
|
|
18
|
+
import { type BusinessProfileDoc, type BusinessProfileOrigin, type BusinessTone } from './business-profile-values';
|
|
19
|
+
export { BUSINESS_PROFILE_FIELDS, BUSINESS_PROFILE_MAX_CHARS, BUSINESS_PROFILE_MAX_SERVICES, BUSINESS_PROFILE_SITE_DOC, BUSINESS_PROFILE_SUBCOLLECTION, BUSINESS_PROFILE_WORKSPACE_DOC, BUSINESS_TONE_LABELS, BUSINESS_TONES, businessProfileOwnerWrite, businessProfileSourceOf, mergeBusinessProfilePrefill, sanitizeBusinessProfileValues, } from './business-profile-values';
|
|
20
|
+
export type { BusinessProfileDoc, BusinessProfileField, BusinessProfileOrigin, BusinessProfileSource, BusinessProfileValues, BusinessTone, } from './business-profile-values';
|
|
21
|
+
/** The tones as a plain list, in the order the owner picks them, for the native apps' pickers. */
|
|
22
|
+
export declare const BUSINESS_TONE_ORDER: readonly string[];
|
|
23
|
+
/** The stored fields as a plain list, for the native apps' writers. */
|
|
24
|
+
export declare const BUSINESS_PROFILE_FIELD_ORDER: readonly string[];
|
|
18
25
|
/**
|
|
19
26
|
* A site's BUSINESS PROFILE (AGL-3661): what the business is, as everything
|
|
20
27
|
* that writes about it needs to know — the site's own pages, the structured
|
|
@@ -51,49 +58,6 @@ import { type HostSeoEntity } from './content-authors';
|
|
|
51
58
|
* what a generator guessed; and a generator's guess fills only what is empty.
|
|
52
59
|
* {@link mergeBusinessProfilePrefill} is the one place that rule is applied.
|
|
53
60
|
*/
|
|
54
|
-
/** The collection a profile document lives in, under a host or an org. */
|
|
55
|
-
export declare const BUSINESS_PROFILE_SUBCOLLECTION = "businessProfile";
|
|
56
|
-
/** The site's profile document id. */
|
|
57
|
-
export declare const BUSINESS_PROFILE_SITE_DOC = "profile";
|
|
58
|
-
/** The workspace defaults document id. */
|
|
59
|
-
export declare const BUSINESS_PROFILE_WORKSPACE_DOC = "defaults";
|
|
60
|
-
/** Who wrote a stored value: the owner, the guided start's answers, or a generator. */
|
|
61
|
-
export type BusinessProfileSource = 'owner' | 'start' | 'ai';
|
|
62
|
-
/**
|
|
63
|
-
* Where a RESOLVED value came from: a stored source, the site's own settings
|
|
64
|
-
* (`seo.entity`, `business`, the display name), or the workspace defaults.
|
|
65
|
-
*/
|
|
66
|
-
export type BusinessProfileOrigin = BusinessProfileSource | 'site' | 'workspace';
|
|
67
|
-
export declare const BUSINESS_TONES: readonly ["friendly", "professional", "playful", "premium", "plain"];
|
|
68
|
-
export type BusinessTone = (typeof BUSINESS_TONES)[number];
|
|
69
|
-
/** The tones as a plain list, in the order the owner picks them, for the native apps' pickers. */
|
|
70
|
-
export declare const BUSINESS_TONE_ORDER: readonly string[];
|
|
71
|
-
/** Each tone as the owner picks it and as a writer is told it. */
|
|
72
|
-
export declare const BUSINESS_TONE_LABELS: Readonly<Record<BusinessTone, string>>;
|
|
73
|
-
/** The fields the profile document stores itself. */
|
|
74
|
-
export declare const BUSINESS_PROFILE_FIELDS: readonly ["whatYouDo", "services", "serviceArea", "audience", "tone", "toneNotes"];
|
|
75
|
-
export type BusinessProfileField = (typeof BUSINESS_PROFILE_FIELDS)[number];
|
|
76
|
-
/** The stored fields as a plain list, for the native apps' writers. */
|
|
77
|
-
export declare const BUSINESS_PROFILE_FIELD_ORDER: readonly string[];
|
|
78
|
-
/** Each field's ceiling, in characters; `services` is per item. */
|
|
79
|
-
export declare const BUSINESS_PROFILE_MAX_CHARS: Readonly<Record<Exclude<BusinessProfileField, 'tone'>, number>>;
|
|
80
|
-
/** At most this many services are kept. */
|
|
81
|
-
export declare const BUSINESS_PROFILE_MAX_SERVICES = 12;
|
|
82
|
-
/** The stored document, at either level. */
|
|
83
|
-
export interface BusinessProfileDoc {
|
|
84
|
-
whatYouDo?: string;
|
|
85
|
-
services?: string[];
|
|
86
|
-
serviceArea?: string;
|
|
87
|
-
audience?: string;
|
|
88
|
-
tone?: BusinessTone | null;
|
|
89
|
-
toneNotes?: string;
|
|
90
|
-
/** Who wrote each stored value; a value without one is the owner's. */
|
|
91
|
-
sources?: Partial<Record<BusinessProfileField, BusinessProfileSource>>;
|
|
92
|
-
updatedAt?: unknown;
|
|
93
|
-
updatedBy?: string | null;
|
|
94
|
-
}
|
|
95
|
-
/** The values a write carries, before they are sanitized. */
|
|
96
|
-
export type BusinessProfileValues = Partial<Pick<BusinessProfileDoc, 'whatYouDo' | 'services' | 'serviceArea' | 'audience' | 'tone' | 'toneNotes'>>;
|
|
97
61
|
/** The host fields the profile reads. A closed surface, as the host tokens' is. */
|
|
98
62
|
export interface BusinessProfileHost {
|
|
99
63
|
displayName?: string;
|
|
@@ -137,23 +101,6 @@ export interface ResolvedBusinessProfile {
|
|
|
137
101
|
profiles: string[];
|
|
138
102
|
logo: string | null;
|
|
139
103
|
}
|
|
140
|
-
/** The source a stored, non-empty value carries; the owner's when none is recorded. */
|
|
141
|
-
export declare function businessProfileSourceOf(doc: BusinessProfileDoc | null | undefined, field: BusinessProfileField): BusinessProfileSource | null;
|
|
142
|
-
/** Every value a write may carry, sanitized; an absent field stays absent. */
|
|
143
|
-
export declare function sanitizeBusinessProfileValues(values: BusinessProfileValues): BusinessProfileValues;
|
|
144
|
-
/**
|
|
145
|
-
* The document a generator's or the guided start's values make of the stored
|
|
146
|
-
* one: each value fills a field that is empty or was written by a source that
|
|
147
|
-
* weighs less, and nothing else. `null` when nothing would change, so a caller
|
|
148
|
-
* writes only when there is something to write.
|
|
149
|
-
*/
|
|
150
|
-
export declare function mergeBusinessProfilePrefill(current: BusinessProfileDoc | null | undefined, values: BusinessProfileValues, source: Exclude<BusinessProfileSource, 'owner'>): BusinessProfileDoc | null;
|
|
151
|
-
/**
|
|
152
|
-
* The document the owner's save makes: every field they changed becomes
|
|
153
|
-
* theirs, and a field they left as it was keeps the source it had — so saving
|
|
154
|
-
* the form after correcting one line does not claim every suggestion on it.
|
|
155
|
-
*/
|
|
156
|
-
export declare function businessProfileOwnerWrite(current: BusinessProfileDoc | null | undefined, edited: BusinessProfileValues): Pick<BusinessProfileDoc, BusinessProfileField | 'sources'>;
|
|
157
104
|
/**
|
|
158
105
|
* The profile as every reader sees it, field by field (AGL-3661):
|
|
159
106
|
*
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
1
|
/**
|
|
3
2
|
* @license
|
|
4
3
|
* Copyright 2026 Aglyn LLC
|
|
@@ -17,179 +16,10 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
|
17
16
|
*/ import { siteProfileUrls } from "./content-authors.js";
|
|
18
17
|
import { normalizeAreaServed } from "./local-business.js";
|
|
19
18
|
import { PLATFORM_BRAND_NAME } from "./platform-brand.js";
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* that writes about it needs to know — the site's own pages, the structured
|
|
23
|
-
* data, and any generator a plugin brings.
|
|
24
|
-
*
|
|
25
|
-
* ── Most of it is already stored, so this stores only the rest ─────────────
|
|
26
|
-
*
|
|
27
|
-
* The site's name, its one-line description, its contact details, its hours,
|
|
28
|
-
* the areas it serves and its social profiles all have a home on the host
|
|
29
|
-
* document already: `seo.entity` (the publisher entity the JSON-LD is built
|
|
30
|
-
* from, edited in Setup → SEO) and `business` (the contact card the `host.*`
|
|
31
|
-
* tokens and the footer read, edited in Setup → Basic details). Copying them
|
|
32
|
-
* here would make two places to keep in step, and the copy would drift.
|
|
33
|
-
*
|
|
34
|
-
* So the profile document holds only what has no home yet — the services, the
|
|
35
|
-
* audience, the tone of voice — plus a line about the business and the area it
|
|
36
|
-
* serves for a site whose SEO entity does not say. {@link resolveBusinessProfile}
|
|
37
|
-
* reads the two together into one picture, field by field, and says where
|
|
38
|
-
* each value came from.
|
|
39
|
-
*
|
|
40
|
-
* ── Where it is stored ────────────────────────────────────────────────────
|
|
41
|
-
*
|
|
42
|
-
* `hosts/{hostId}/businessProfile/profile` for a site and
|
|
43
|
-
* `orgs/{orgId}/businessProfile/defaults` for the workspace, whose values a
|
|
44
|
-
* site inherits where it has none of its own. A subcollection document rather
|
|
45
|
-
* than a key on the host: the host document's `business` map is replaced
|
|
46
|
-
* whole by the contact card's save, and a key beside it would be one more
|
|
47
|
-
* thing a partial write could blank.
|
|
48
|
-
*
|
|
49
|
-
* ── Whose words win ───────────────────────────────────────────────────────
|
|
50
|
-
*
|
|
51
|
-
* Every stored value carries its source. What the owner typed is never
|
|
52
|
-
* replaced by anything else; what the guided start was told replaces only
|
|
53
|
-
* what a generator guessed; and a generator's guess fills only what is empty.
|
|
54
|
-
* {@link mergeBusinessProfilePrefill} is the one place that rule is applied.
|
|
55
|
-
*/ /** The collection a profile document lives in, under a host or an org. */ export const BUSINESS_PROFILE_SUBCOLLECTION = 'businessProfile';
|
|
56
|
-
/** The site's profile document id. */ export const BUSINESS_PROFILE_SITE_DOC = 'profile';
|
|
57
|
-
/** The workspace defaults document id. */ export const BUSINESS_PROFILE_WORKSPACE_DOC = 'defaults';
|
|
58
|
-
/** How much a source's words weigh: a higher rank is never replaced by a lower one. */ const SOURCE_RANK = {
|
|
59
|
-
ai: 1,
|
|
60
|
-
start: 2,
|
|
61
|
-
owner: 3
|
|
62
|
-
};
|
|
63
|
-
export const BUSINESS_TONES = [
|
|
64
|
-
'friendly',
|
|
65
|
-
'professional',
|
|
66
|
-
'playful',
|
|
67
|
-
'premium',
|
|
68
|
-
'plain'
|
|
69
|
-
];
|
|
19
|
+
import { BUSINESS_PROFILE_FIELDS, BUSINESS_PROFILE_MAX_CHARS, BUSINESS_TONES, businessProfileSourceOf, fieldValue, isEmpty, text } from "./business-profile-values.js";
|
|
20
|
+
export { BUSINESS_PROFILE_FIELDS, BUSINESS_PROFILE_MAX_CHARS, BUSINESS_PROFILE_MAX_SERVICES, BUSINESS_PROFILE_SITE_DOC, BUSINESS_PROFILE_SUBCOLLECTION, BUSINESS_PROFILE_WORKSPACE_DOC, BUSINESS_TONE_LABELS, BUSINESS_TONES, businessProfileOwnerWrite, businessProfileSourceOf, mergeBusinessProfilePrefill, sanitizeBusinessProfileValues } from "./business-profile-values.js";
|
|
70
21
|
/** The tones as a plain list, in the order the owner picks them, for the native apps' pickers. */ export const BUSINESS_TONE_ORDER = BUSINESS_TONES;
|
|
71
|
-
/** Each tone as the owner picks it and as a writer is told it. */ export const BUSINESS_TONE_LABELS = {
|
|
72
|
-
friendly: 'Friendly and warm',
|
|
73
|
-
professional: 'Professional and clear',
|
|
74
|
-
playful: 'Playful and upbeat',
|
|
75
|
-
premium: 'Premium and refined',
|
|
76
|
-
plain: 'Plain and direct'
|
|
77
|
-
};
|
|
78
|
-
/** The fields the profile document stores itself. */ export const BUSINESS_PROFILE_FIELDS = [
|
|
79
|
-
'whatYouDo',
|
|
80
|
-
'services',
|
|
81
|
-
'serviceArea',
|
|
82
|
-
'audience',
|
|
83
|
-
'tone',
|
|
84
|
-
'toneNotes'
|
|
85
|
-
];
|
|
86
22
|
/** The stored fields as a plain list, for the native apps' writers. */ export const BUSINESS_PROFILE_FIELD_ORDER = BUSINESS_PROFILE_FIELDS;
|
|
87
|
-
/** Each field's ceiling, in characters; `services` is per item. */ export const BUSINESS_PROFILE_MAX_CHARS = {
|
|
88
|
-
whatYouDo: 200,
|
|
89
|
-
services: 60,
|
|
90
|
-
serviceArea: 120,
|
|
91
|
-
audience: 160,
|
|
92
|
-
toneNotes: 200
|
|
93
|
-
};
|
|
94
|
-
/** At most this many services are kept. */ export const BUSINESS_PROFILE_MAX_SERVICES = 12;
|
|
95
|
-
const text = (value, max)=>typeof value === 'string' ? value.replace(/\s+/g, ' ').trim().slice(0, max) : '';
|
|
96
|
-
const tone = (value)=>BUSINESS_TONES.includes(value) ? value : null;
|
|
97
|
-
const services = (value)=>{
|
|
98
|
-
const items = Array.isArray(value) ? value : typeof value === 'string' ? value.split(/[,\n]/) : [];
|
|
99
|
-
const seen = new Set();
|
|
100
|
-
const kept = [];
|
|
101
|
-
for (const item of items){
|
|
102
|
-
const name = text(item, BUSINESS_PROFILE_MAX_CHARS.services);
|
|
103
|
-
const key = name.toLowerCase();
|
|
104
|
-
if (!name || seen.has(key)) continue;
|
|
105
|
-
seen.add(key);
|
|
106
|
-
kept.push(name);
|
|
107
|
-
if (kept.length >= BUSINESS_PROFILE_MAX_SERVICES) break;
|
|
108
|
-
}
|
|
109
|
-
return kept;
|
|
110
|
-
};
|
|
111
|
-
/** One field's stored value, sanitized; empty is `''`, `[]` or `null`. */ function fieldValue(doc, field) {
|
|
112
|
-
switch(field){
|
|
113
|
-
case 'services':
|
|
114
|
-
return services(doc == null ? void 0 : doc.services);
|
|
115
|
-
case 'tone':
|
|
116
|
-
return tone(doc == null ? void 0 : doc.tone);
|
|
117
|
-
default:
|
|
118
|
-
return text(doc == null ? void 0 : doc[field], BUSINESS_PROFILE_MAX_CHARS[field]);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
const isEmpty = (value)=>value === null || value === '' || Array.isArray(value) && value.length === 0;
|
|
122
|
-
/** The source a stored, non-empty value carries; the owner's when none is recorded. */ export function businessProfileSourceOf(doc, field) {
|
|
123
|
-
var _doc_sources;
|
|
124
|
-
if (isEmpty(fieldValue(doc, field))) return null;
|
|
125
|
-
const source = doc == null ? void 0 : (_doc_sources = doc.sources) == null ? void 0 : _doc_sources[field];
|
|
126
|
-
return source && source in SOURCE_RANK ? source : 'owner';
|
|
127
|
-
}
|
|
128
|
-
/** Every value a write may carry, sanitized; an absent field stays absent. */ export function sanitizeBusinessProfileValues(values) {
|
|
129
|
-
const clean = {};
|
|
130
|
-
for (const field of BUSINESS_PROFILE_FIELDS){
|
|
131
|
-
if (!(field in values)) continue;
|
|
132
|
-
clean[field] = fieldValue(values, field);
|
|
133
|
-
}
|
|
134
|
-
return clean;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* The document a generator's or the guided start's values make of the stored
|
|
138
|
-
* one: each value fills a field that is empty or was written by a source that
|
|
139
|
-
* weighs less, and nothing else. `null` when nothing would change, so a caller
|
|
140
|
-
* writes only when there is something to write.
|
|
141
|
-
*/ export function mergeBusinessProfilePrefill(current, values, source) {
|
|
142
|
-
var _ref;
|
|
143
|
-
const clean = sanitizeBusinessProfileValues(values);
|
|
144
|
-
const next = _extends({}, current != null ? current : {}, {
|
|
145
|
-
sources: _extends({}, (_ref = current == null ? void 0 : current.sources) != null ? _ref : {})
|
|
146
|
-
});
|
|
147
|
-
let changed = false;
|
|
148
|
-
for (const field of BUSINESS_PROFILE_FIELDS){
|
|
149
|
-
var _current_sources;
|
|
150
|
-
if (!(field in clean)) continue;
|
|
151
|
-
const value = clean[field];
|
|
152
|
-
if (isEmpty(value)) continue;
|
|
153
|
-
// An explicit source counts even on an empty value: a field the owner
|
|
154
|
-
// cleared stays cleared rather than being refilled behind them.
|
|
155
|
-
const recorded = current == null ? void 0 : (_current_sources = current.sources) == null ? void 0 : _current_sources[field];
|
|
156
|
-
const held = recorded && recorded in SOURCE_RANK ? recorded : businessProfileSourceOf(current, field);
|
|
157
|
-
if (held && SOURCE_RANK[held] >= SOURCE_RANK[source]) continue;
|
|
158
|
-
if (JSON.stringify(fieldValue(current, field)) === JSON.stringify(value)) continue;
|
|
159
|
-
next[field] = value;
|
|
160
|
-
next.sources[field] = source;
|
|
161
|
-
changed = true;
|
|
162
|
-
}
|
|
163
|
-
return changed ? next : null;
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* The document the owner's save makes: every field they changed becomes
|
|
167
|
-
* theirs, and a field they left as it was keeps the source it had — so saving
|
|
168
|
-
* the form after correcting one line does not claim every suggestion on it.
|
|
169
|
-
*/ export function businessProfileOwnerWrite(current, edited) {
|
|
170
|
-
const clean = sanitizeBusinessProfileValues(edited);
|
|
171
|
-
const next = {};
|
|
172
|
-
const sources = {};
|
|
173
|
-
for (const field of BUSINESS_PROFILE_FIELDS){
|
|
174
|
-
var _businessProfileSourceOf;
|
|
175
|
-
const before = fieldValue(current, field);
|
|
176
|
-
const after = field in clean ? clean[field] : before;
|
|
177
|
-
next[field] = after;
|
|
178
|
-
const same = JSON.stringify(before) === JSON.stringify(after);
|
|
179
|
-
if (isEmpty(after)) {
|
|
180
|
-
var _current_sources;
|
|
181
|
-
// A suggestion the owner deleted is their decision, and recorded as
|
|
182
|
-
// one, so the next prefill does not put it back.
|
|
183
|
-
if (!same) sources[field] = 'owner';
|
|
184
|
-
else if ((current == null ? void 0 : (_current_sources = current.sources) == null ? void 0 : _current_sources[field]) === 'owner') sources[field] = 'owner';
|
|
185
|
-
continue;
|
|
186
|
-
}
|
|
187
|
-
sources[field] = same ? (_businessProfileSourceOf = businessProfileSourceOf(current, field)) != null ? _businessProfileSourceOf : 'owner' : 'owner';
|
|
188
|
-
}
|
|
189
|
-
return _extends({}, next, {
|
|
190
|
-
sources
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
23
|
/** The postal address as one line: the SEO entity's parts, else the contact card's block. */ function addressLine(host) {
|
|
194
24
|
var _host_seo_entity, _host_seo, _host_business;
|
|
195
25
|
const parts = host == null ? void 0 : (_host_seo = host.seo) == null ? void 0 : (_host_seo_entity = _host_seo.entity) == null ? void 0 : _host_seo_entity.address;
|