@aglyn/plugins-ai 1.0.0-beta.244 → 1.0.0-beta.247
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 +17 -17
- package/src/lib/activity/ai-activity-actions.js +7 -1
- package/src/lib/activity/ai-activity-actions.js.map +1 -1
- package/src/lib/components/ai-job-links.js +21 -0
- package/src/lib/components/ai-job-links.js.map +1 -1
- package/src/lib/components/ai-product-zones.d.ts +3 -1
- package/src/lib/components/ai-product-zones.js.map +1 -1
- package/src/lib/components/ai-products-hub-card.component.js +1 -1
- package/src/lib/components/ai-products-hub-card.component.js.map +1 -1
- package/src/lib/components/ai-products-proposals.component.js +17 -9
- package/src/lib/components/ai-products-proposals.component.js.map +1 -1
- package/src/lib/components/ai-site-start-card.component.d.ts +1 -1
- package/src/lib/components/ai-site-start-card.component.js +98 -23
- package/src/lib/components/ai-site-start-card.component.js.map +1 -1
- package/src/lib/components/ai-upsell-dialog.component.js +1 -1
- package/src/lib/components/ai-upsell-dialog.component.js.map +1 -1
- package/src/lib/declarations.server.js +12 -0
- package/src/lib/declarations.server.js.map +1 -1
- package/src/lib/jobs/ai-build-capabilities.js +216 -2
- package/src/lib/jobs/ai-build-capabilities.js.map +1 -1
- package/src/lib/jobs/ai-job-build-step.d.ts +3 -1
- package/src/lib/jobs/ai-job-build-step.js +124 -18
- package/src/lib/jobs/ai-job-build-step.js.map +1 -1
- package/src/lib/jobs/ai-job-duplicate-step.d.ts +123 -0
- package/src/lib/jobs/ai-job-duplicate-step.js +269 -0
- package/src/lib/jobs/ai-job-duplicate-step.js.map +1 -0
- package/src/lib/jobs/ai-job-form-dataset.d.ts +8 -5
- package/src/lib/jobs/ai-job-form-dataset.js +28 -10
- package/src/lib/jobs/ai-job-form-dataset.js.map +1 -1
- package/src/lib/jobs/ai-job-form-step.d.ts +20 -4
- package/src/lib/jobs/ai-job-form-step.js +98 -28
- package/src/lib/jobs/ai-job-form-step.js.map +1 -1
- package/src/lib/jobs/ai-job-layout-language.d.ts +6 -2
- package/src/lib/jobs/ai-job-layout-language.js +29 -5
- package/src/lib/jobs/ai-job-layout-language.js.map +1 -1
- package/src/lib/jobs/ai-job-layout-step.js +4 -1
- package/src/lib/jobs/ai-job-layout-step.js.map +1 -1
- package/src/lib/jobs/ai-job-media-step.d.ts +239 -0
- package/src/lib/jobs/ai-job-media-step.js +610 -0
- package/src/lib/jobs/ai-job-media-step.js.map +1 -0
- package/src/lib/jobs/ai-job-navigation-step.d.ts +157 -0
- package/src/lib/jobs/ai-job-navigation-step.js +439 -0
- package/src/lib/jobs/ai-job-navigation-step.js.map +1 -0
- package/src/lib/jobs/ai-job-page-language.d.ts +4 -1
- package/src/lib/jobs/ai-job-page-language.js +30 -5
- package/src/lib/jobs/ai-job-page-language.js.map +1 -1
- package/src/lib/jobs/ai-job-page-sections.js +5 -4
- package/src/lib/jobs/ai-job-page-sections.js.map +1 -1
- package/src/lib/jobs/ai-job-page-step.js +3 -2
- package/src/lib/jobs/ai-job-page-step.js.map +1 -1
- package/src/lib/jobs/ai-job-plan-step.d.ts +14 -3
- package/src/lib/jobs/ai-job-plan-step.js +87 -20
- package/src/lib/jobs/ai-job-plan-step.js.map +1 -1
- package/src/lib/jobs/ai-job-products-step.d.ts +2 -2
- package/src/lib/jobs/ai-job-products-step.js +2 -2
- package/src/lib/jobs/ai-job-products-step.js.map +1 -1
- package/src/lib/jobs/ai-job-settings-step.d.ts +268 -0
- package/src/lib/jobs/ai-job-settings-step.js +690 -0
- package/src/lib/jobs/ai-job-settings-step.js.map +1 -0
- package/src/lib/jobs/ai-job-site-content.d.ts +22 -8
- package/src/lib/jobs/ai-job-site-content.js +33 -15
- package/src/lib/jobs/ai-job-site-content.js.map +1 -1
- package/src/lib/jobs/ai-job-site-datasets.d.ts +3 -1
- package/src/lib/jobs/ai-job-site-datasets.js +13 -5
- package/src/lib/jobs/ai-job-site-datasets.js.map +1 -1
- package/src/lib/jobs/ai-job-site-events.d.ts +148 -0
- package/src/lib/jobs/ai-job-site-events.js +313 -0
- package/src/lib/jobs/ai-job-site-events.js.map +1 -0
- package/src/lib/jobs/ai-job-site-step.d.ts +12 -4
- package/src/lib/jobs/ai-job-site-step.js +132 -26
- package/src/lib/jobs/ai-job-site-step.js.map +1 -1
- package/src/lib/jobs/ai-job-tracking-step.d.ts +184 -0
- package/src/lib/jobs/ai-job-tracking-step.js +501 -0
- package/src/lib/jobs/ai-job-tracking-step.js.map +1 -0
- package/src/lib/jobs/ai-layout-stock-photos.d.ts +21 -0
- package/src/lib/jobs/ai-layout-stock-photos.js +41 -4
- package/src/lib/jobs/ai-layout-stock-photos.js.map +1 -1
- package/src/lib/jobs/ai-site-publish.d.ts +62 -4
- package/src/lib/jobs/ai-site-publish.js +202 -56
- package/src/lib/jobs/ai-site-publish.js.map +1 -1
- package/src/lib/jobs/ai-stock-photo-picker.d.ts +24 -0
- package/src/lib/jobs/ai-stock-photo-picker.js +108 -0
- package/src/lib/jobs/ai-stock-photo-picker.js.map +1 -0
- package/src/lib/jobs/fixtures/ai-jazz-events-build-plan-recording.d.ts +37 -0
- package/src/lib/jobs/fixtures/ai-jazz-events-build-plan-recording.js +47 -0
- package/src/lib/jobs/fixtures/ai-jazz-events-build-plan-recording.js.map +1 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-agl3760-recordings.d.ts +21 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-agl3760-recordings.js +128 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-agl3760-recordings.js.map +1 -0
- package/src/lib/layout-language/ai-layout-compiler.d.ts +16 -7
- package/src/lib/layout-language/ai-layout-compiler.js +62 -42
- package/src/lib/layout-language/ai-layout-compiler.js.map +1 -1
- package/src/lib/layout-language/ai-layout-frame-hollows.d.ts +41 -0
- package/src/lib/layout-language/ai-layout-frame-hollows.js +330 -0
- package/src/lib/layout-language/ai-layout-frame-hollows.js.map +1 -0
- package/src/lib/layout-language/ai-layout-frame.d.ts +24 -5
- package/src/lib/layout-language/ai-layout-frame.js +93 -20
- package/src/lib/layout-language/ai-layout-frame.js.map +1 -1
- package/src/lib/layout-language/ai-layout-gaps.js +3 -1
- package/src/lib/layout-language/ai-layout-gaps.js.map +1 -1
- package/src/lib/layout-language/ai-layout-labels.d.ts +70 -0
- package/src/lib/layout-language/ai-layout-labels.js +162 -0
- package/src/lib/layout-language/ai-layout-labels.js.map +1 -0
- package/src/lib/layout-language/ai-layout-links.js +5 -2
- package/src/lib/layout-language/ai-layout-links.js.map +1 -1
- package/src/lib/layout-language/ai-layout-listings.d.ts +49 -1
- package/src/lib/layout-language/ai-layout-listings.js +66 -5
- package/src/lib/layout-language/ai-layout-listings.js.map +1 -1
- package/src/lib/layout-language/ai-layout-tree.d.ts +2 -0
- package/src/lib/layout-language/ai-layout-tree.js +17 -0
- package/src/lib/layout-language/ai-layout-tree.js.map +1 -1
- package/src/lib/model/ai-build-event-page.d.ts +70 -0
- package/src/lib/model/ai-build-event-page.js +145 -0
- package/src/lib/model/ai-build-event-page.js.map +1 -0
- package/src/lib/model/ai-build-job.d.ts +44 -0
- package/src/lib/model/ai-build-job.js +141 -13
- package/src/lib/model/ai-build-job.js.map +1 -1
- package/src/lib/model/ai-build-plan.d.ts +39 -3
- package/src/lib/model/ai-build-plan.js +59 -5
- package/src/lib/model/ai-build-plan.js.map +1 -1
- package/src/lib/model/ai-credit-estimate.d.ts +52 -0
- package/src/lib/model/ai-credit-estimate.js +51 -0
- package/src/lib/model/ai-credit-estimate.js.map +1 -1
- package/src/lib/model/ai-job-activity.js +6 -1
- package/src/lib/model/ai-job-activity.js.map +1 -1
- package/src/lib/model/ai-jobs.types.d.ts +18 -2
- package/src/lib/model/ai-jobs.types.js +6 -1
- package/src/lib/model/ai-jobs.types.js.map +1 -1
- package/src/lib/model/ai-layout-menus.d.ts +104 -0
- package/src/lib/model/ai-layout-menus.js +518 -0
- package/src/lib/model/ai-layout-menus.js.map +1 -0
- package/src/lib/model/ai-plan-capabilities.d.ts +8 -0
- package/src/lib/model/ai-plan-capabilities.js.map +1 -1
- package/src/lib/model/ai-products.d.ts +31 -1
- package/src/lib/model/ai-products.js +34 -1
- package/src/lib/model/ai-products.js.map +1 -1
- package/src/lib/model/ai-site-inventory.d.ts +17 -0
- package/src/lib/model/ai-site-inventory.js +5 -0
- package/src/lib/model/ai-site-inventory.js.map +1 -1
- package/src/lib/model/ai-site-job.d.ts +12 -2
- package/src/lib/model/ai-site-job.js +39 -12
- package/src/lib/model/ai-site-job.js.map +1 -1
- package/src/lib/model/ai-site-store-pages.js +1 -1
- package/src/lib/model/ai-site-store-pages.js.map +1 -1
- package/src/lib/runtime/ai-doctrine-validators.d.ts +78 -3
- package/src/lib/runtime/ai-doctrine-validators.js +219 -31
- package/src/lib/runtime/ai-doctrine-validators.js.map +1 -1
- package/src/lib/runtime/ai-doctrine.d.ts +6 -1
- package/src/lib/runtime/ai-doctrine.js +16 -7
- package/src/lib/runtime/ai-doctrine.js.map +1 -1
- package/src/lib/runtime/ai-eval-live.d.ts +1 -1
- package/src/lib/runtime/ai-eval-live.js +1 -1
- package/src/lib/runtime/ai-eval-live.js.map +1 -1
- package/src/lib/runtime/ai-palette.d.ts +3 -1
- package/src/lib/runtime/ai-palette.generated.js +499 -11
- package/src/lib/runtime/ai-palette.generated.js.map +1 -1
- package/src/lib/runtime/ai-palette.js +5 -3
- package/src/lib/runtime/ai-palette.js.map +1 -1
- package/src/lib/runtime/ai-products-generation.d.ts +4 -2
- package/src/lib/runtime/ai-products-generation.js +12 -6
- package/src/lib/runtime/ai-products-generation.js.map +1 -1
- package/src/lib/runtime/ai-template-examples.js +8 -2
- package/src/lib/runtime/ai-template-examples.js.map +1 -1
- package/src/lib/runtime/site-inventory.d.ts +12 -0
- package/src/lib/runtime/site-inventory.js +29 -1
- package/src/lib/runtime/site-inventory.js.map +1 -1
- package/src/lib/server.js +20 -0
- package/src/lib/server.js.map +1 -1
- package/src/lib/testing/stand-in-dataset-index.js +37 -3
- package/src/lib/testing/stand-in-dataset-index.js.map +1 -1
- package/src/lib/tools/ai-products-tool.d.ts +3 -1
- package/src/lib/tools/ai-products-tool.js +15 -5
- package/src/lib/tools/ai-products-tool.js.map +1 -1
|
@@ -0,0 +1,690 @@
|
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2026 Aglyn LLC
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/ import { supportedTimeZones } from "@aglyn/aglyn/app-utils/collection-entry-date";
|
|
18
|
+
import { createResourceUid } from "@aglyn/aglyn/app-utils/create-resource-uid";
|
|
19
|
+
import { inheritedMediaAlt } from "@aglyn/aglyn/app-utils/media-metadata";
|
|
20
|
+
import { mediaNodeSrc } from "@aglyn/aglyn/app-utils/media-ref";
|
|
21
|
+
import { hostRoleCanWrite } from "@aglyn/aglyn/app-utils/organizations";
|
|
22
|
+
import { visibleToHost } from "@aglyn/aglyn/app-utils/scope-tokens";
|
|
23
|
+
import { SCREEN_ROOT_PATH } from "@aglyn/aglyn/app-utils/screen-route";
|
|
24
|
+
import { siteLanguageCode } from "@aglyn/aglyn/app-utils/seo-locale";
|
|
25
|
+
import { isSeoTitleVariable } from "@aglyn/aglyn/app-utils/seo-title-variables";
|
|
26
|
+
import { dropPluginSiteCache } from "@aglyn/aglyn/plugin-manager/plugin-site-cache";
|
|
27
|
+
import { syncHostProjectionForMembers } from "@aglyn/tenant-data-admin/server/host-memberships";
|
|
28
|
+
import { getLockdownVerdict } from "@aglyn/tenant-data-admin/server/lockdown";
|
|
29
|
+
import { resolveOrgIdForHost } from "@aglyn/tenant-data-admin/server/organizations";
|
|
30
|
+
import { FieldValue } from "firebase-admin/firestore";
|
|
31
|
+
import { registerAiJobAdmission } from "./ai-job-admission.js";
|
|
32
|
+
import { aiJobEditModel } from "./ai-job-edit-step.js";
|
|
33
|
+
import { aiLimitReview, aiUnspentOutcome } from "./ai-job-generation.js";
|
|
34
|
+
import { registerAiJobStep } from "./ai-jobs.js";
|
|
35
|
+
/**
|
|
36
|
+
* The `settings` step (AGL-3748): a change to what a member can change in the
|
|
37
|
+
* site's settings — its name, its search defaults, its favicon, logo and
|
|
38
|
+
* social image from the media library, its language, its time zone, its
|
|
39
|
+
* contact details and its consent banner's mode — as a first-class build
|
|
40
|
+
* operation, so "rename my site to Juniper Clay Studio", "make the site
|
|
41
|
+
* Spanish" or "set the SEO description" is one item on Assist's plan card.
|
|
42
|
+
*
|
|
43
|
+
* NO MODEL. The planner already wrote the values as the item's arguments;
|
|
44
|
+
* this checks each against the rule the console's own control holds it to
|
|
45
|
+
* and writes it, so it costs no credits.
|
|
46
|
+
*
|
|
47
|
+
* ── Only the console's own fields ────────────────────────────────────────
|
|
48
|
+
*
|
|
49
|
+
* Every field written is one a settings card or form writes, under the same
|
|
50
|
+
* name and to the same limit: `displayName` (Admin → General, 30), `seo.title`
|
|
51
|
+
* (60), `seo.description` (155), `seo.separator` (3), `seo.titlePattern`
|
|
52
|
+
* (120, its own variables only), `seo.entity.name`, `seo.entity.description`
|
|
53
|
+
* (300), `seo.entity.telephone`, `business.supportEmail` and
|
|
54
|
+
* `business.address` (the Business details card), `locales`/`defaultLocale`
|
|
55
|
+
* (the Languages card), `timeZone` (one of the zones the console offers),
|
|
56
|
+
* `consent.mode` (the consent banner card), and `seo.favicon`, `logoUrl` and
|
|
57
|
+
* `seo.image` (with its size and alt) written as the media pickers write
|
|
58
|
+
* them, through `mediaNodeSrc`.
|
|
59
|
+
*
|
|
60
|
+
* NEVER: the address (subdomain, domains), plugins, members and roles,
|
|
61
|
+
* billing, lockdown, deletion, search engine indexing, analytics and
|
|
62
|
+
* advertising ids, verification tokens, or turning the consent banner off.
|
|
63
|
+
* Those are not arguments, so the planner cannot ask for them.
|
|
64
|
+
*
|
|
65
|
+
* ── Live on confirm ──────────────────────────────────────────────────────
|
|
66
|
+
*
|
|
67
|
+
* A setting has no draft: the console saves it straight to the host
|
|
68
|
+
* document, and the tenant renders it from there. So does this, once the
|
|
69
|
+
* person confirms the plan (Zach, 2026-10-12: live on confirm). The write
|
|
70
|
+
* drops the site's cached pages as the console's door does
|
|
71
|
+
* (`host-document-writes.ts`), with a site-wide publish outbox entry in the
|
|
72
|
+
* same transaction for the drain to fire if the drop does not land.
|
|
73
|
+
*
|
|
74
|
+
* ── Who may ──────────────────────────────────────────────────────────────
|
|
75
|
+
*
|
|
76
|
+
* The Firestore rules' own for these keys (`canWriteHostContent` and
|
|
77
|
+
* `hostWritesFrozen`): a member with a write role on the site (admin, editor
|
|
78
|
+
* or author), while no lockdown freezes the site, its org or the platform.
|
|
79
|
+
* Asked at the door, again before the write, and the role once more inside
|
|
80
|
+
* the transaction that writes.
|
|
81
|
+
*
|
|
82
|
+
* ── Idempotent ───────────────────────────────────────────────────────────
|
|
83
|
+
*
|
|
84
|
+
* The transaction compares each value with what is stored and writes only
|
|
85
|
+
* what differs, so a pass asked again writes nothing and announces nothing.
|
|
86
|
+
*/ export const AI_SETTINGS_KIND = 'settings';
|
|
87
|
+
/**
|
|
88
|
+
* ASSUMED: the least time the step needs — the site, the org, up to three
|
|
89
|
+
* media lookups in two libraries, and the one transaction that writes. No
|
|
90
|
+
* model, so it fits an inline door.
|
|
91
|
+
*/ export const AI_JOB_SETTINGS_STEP_MINIMUM_MS = 5000;
|
|
92
|
+
export const AI_SETTINGS_NO_SITE_COPY = 'Open the site whose settings should change.';
|
|
93
|
+
export const AI_SETTINGS_ROLE_COPY = 'Changing the site’s settings needs the admin, editor or author role on this site.';
|
|
94
|
+
export const AI_SETTINGS_LOCKED_COPY = 'This site is not accepting changes right now.';
|
|
95
|
+
export const AI_SETTINGS_NOTHING_COPY = 'The request named no site setting this could change.';
|
|
96
|
+
/** Where a person finds what the op changed, as the build's notes name it. */ export const AI_SETTINGS_WHERE = 'the site’s Settings';
|
|
97
|
+
/** The output's fixed id: one site's settings, whatever changed. */ export const AI_SETTINGS_OUTPUT_ID = 'site';
|
|
98
|
+
/** The console's own limits, each from the control that edits the field. */ export const AI_SETTINGS_LIMITS = {
|
|
99
|
+
/** Admin → General, Display name. */ name: 30,
|
|
100
|
+
/** Setup → SEO, Title. */ seoTitle: 60,
|
|
101
|
+
/** Setup → SEO, Description. */ seoDescription: 155,
|
|
102
|
+
/** Setup → SEO, Separator. */ separator: 3,
|
|
103
|
+
/** Setup → SEO, Title pattern. */ titlePattern: 120,
|
|
104
|
+
/** Setup → SEO, the publisher's description. */ businessDescription: 300,
|
|
105
|
+
businessName: 100,
|
|
106
|
+
telephone: 40,
|
|
107
|
+
supportEmail: 254,
|
|
108
|
+
address: 200
|
|
109
|
+
};
|
|
110
|
+
/** The consent banner card's two modes; turning the banner off is not offered. */ export const AI_SETTINGS_CONSENT_MODES = [
|
|
111
|
+
'geo',
|
|
112
|
+
'strict'
|
|
113
|
+
];
|
|
114
|
+
/** The media a setting may name, and the field each is written to. */ export const AI_SETTINGS_MEDIA_ARGS = [
|
|
115
|
+
'favicon',
|
|
116
|
+
'logo',
|
|
117
|
+
'socialImage'
|
|
118
|
+
];
|
|
119
|
+
const MEDIA_ARG_NOUNS = {
|
|
120
|
+
favicon: 'favicon',
|
|
121
|
+
logo: 'logo',
|
|
122
|
+
socialImage: 'social image'
|
|
123
|
+
};
|
|
124
|
+
/** The item's arguments, as the planner fills them in. Every one optional. */ export const AI_SETTINGS_ARGS_SCHEMA = {
|
|
125
|
+
type: 'object',
|
|
126
|
+
properties: {
|
|
127
|
+
name: {
|
|
128
|
+
type: 'string',
|
|
129
|
+
description: 'The site’s name as the console lists it. Visitors see the search title, not this.',
|
|
130
|
+
maxLength: AI_SETTINGS_LIMITS.name
|
|
131
|
+
},
|
|
132
|
+
seoTitle: {
|
|
133
|
+
type: 'string',
|
|
134
|
+
description: 'The search title pages fall back to, usually the business’s name.',
|
|
135
|
+
maxLength: AI_SETTINGS_LIMITS.seoTitle
|
|
136
|
+
},
|
|
137
|
+
seoDescription: {
|
|
138
|
+
type: 'string',
|
|
139
|
+
description: 'The search description pages fall back to: one or two plain sentences.',
|
|
140
|
+
maxLength: AI_SETTINGS_LIMITS.seoDescription
|
|
141
|
+
},
|
|
142
|
+
separator: {
|
|
143
|
+
type: 'string',
|
|
144
|
+
description: 'The character between a page’s name and the site title, such as | or ·.',
|
|
145
|
+
maxLength: AI_SETTINGS_LIMITS.separator
|
|
146
|
+
},
|
|
147
|
+
titlePattern: {
|
|
148
|
+
type: 'string',
|
|
149
|
+
description: 'How an untitled page is titled, using only {{page.name}}, {{site.separator}} and {{site.name}}.',
|
|
150
|
+
maxLength: AI_SETTINGS_LIMITS.titlePattern
|
|
151
|
+
},
|
|
152
|
+
businessName: {
|
|
153
|
+
type: 'string',
|
|
154
|
+
description: 'The business’s name as search engines and AI assistants are told it.',
|
|
155
|
+
maxLength: AI_SETTINGS_LIMITS.businessName
|
|
156
|
+
},
|
|
157
|
+
businessDescription: {
|
|
158
|
+
type: 'string',
|
|
159
|
+
description: 'What the business is, in one sentence (its tagline), as search engines and AI assistants are told it.',
|
|
160
|
+
maxLength: AI_SETTINGS_LIMITS.businessDescription
|
|
161
|
+
},
|
|
162
|
+
telephone: {
|
|
163
|
+
type: 'string',
|
|
164
|
+
description: 'The business’s phone number, exactly as the person gave it.',
|
|
165
|
+
maxLength: AI_SETTINGS_LIMITS.telephone
|
|
166
|
+
},
|
|
167
|
+
supportEmail: {
|
|
168
|
+
type: 'string',
|
|
169
|
+
description: 'The contact email pages and emails show, exactly as the person gave it.',
|
|
170
|
+
maxLength: AI_SETTINGS_LIMITS.supportEmail
|
|
171
|
+
},
|
|
172
|
+
address: {
|
|
173
|
+
type: 'string',
|
|
174
|
+
description: 'The business’s address on one line, exactly as the person gave it.',
|
|
175
|
+
maxLength: AI_SETTINGS_LIMITS.address
|
|
176
|
+
},
|
|
177
|
+
language: {
|
|
178
|
+
type: 'string',
|
|
179
|
+
description: 'The language the site is in, as a code such as en, es, fr or pt-BR. It does not translate the pages.',
|
|
180
|
+
maxLength: 10
|
|
181
|
+
},
|
|
182
|
+
timeZone: {
|
|
183
|
+
type: 'string',
|
|
184
|
+
description: 'The site’s time zone as an IANA name, such as America/Chicago.',
|
|
185
|
+
maxLength: 64
|
|
186
|
+
},
|
|
187
|
+
consentMode: {
|
|
188
|
+
type: 'string',
|
|
189
|
+
description: 'The cookie banner’s mode: geo (asks only where the law requires) or strict (asks every visitor).',
|
|
190
|
+
enum: AI_SETTINGS_CONSENT_MODES
|
|
191
|
+
},
|
|
192
|
+
favicon: {
|
|
193
|
+
type: 'string',
|
|
194
|
+
description: 'An image already in the media library, by its id or exact file name, for the browser tab icon.',
|
|
195
|
+
maxLength: 200
|
|
196
|
+
},
|
|
197
|
+
logo: {
|
|
198
|
+
type: 'string',
|
|
199
|
+
description: 'An image already in the media library, by its id or exact file name, for the site’s logo.',
|
|
200
|
+
maxLength: 200
|
|
201
|
+
},
|
|
202
|
+
socialImage: {
|
|
203
|
+
type: 'string',
|
|
204
|
+
description: 'An image already in the media library, by its id or exact file name, for the card shown when a page is shared.',
|
|
205
|
+
maxLength: 200
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
additionalProperties: false
|
|
209
|
+
};
|
|
210
|
+
const text = (value)=>typeof value === 'string' ? value.replace(/\s+/g, ' ').trim() : '';
|
|
211
|
+
const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
212
|
+
const TELEPHONE = /^[+()0-9][0-9 ()+.\-/]{4,38}[0-9)]$/;
|
|
213
|
+
const PATTERN_VARIABLE = /\{\{\s*([^}]*?)\s*\}\}/g;
|
|
214
|
+
/** Whether a title pattern names only the variables the renderer knows. */ export function aiSettingsTitlePatternOk(pattern) {
|
|
215
|
+
if (/[{}]/.test(pattern.replace(PATTERN_VARIABLE, ''))) return false;
|
|
216
|
+
return [
|
|
217
|
+
...pattern.matchAll(PATTERN_VARIABLE)
|
|
218
|
+
].every((match)=>isSeoTitleVariable(match[1]));
|
|
219
|
+
}
|
|
220
|
+
/** The item's arguments read: what may be written, and a sentence for each that may not. */ export function aiSettingsRequestOf(inputs) {
|
|
221
|
+
const request = {};
|
|
222
|
+
const problems = [];
|
|
223
|
+
const bounded = (key, noun)=>{
|
|
224
|
+
const value = text(inputs == null ? void 0 : inputs[key]);
|
|
225
|
+
if (!value) return;
|
|
226
|
+
if (value.length > AI_SETTINGS_LIMITS[key]) {
|
|
227
|
+
problems.push(`The ${noun} is longer than ${AI_SETTINGS_LIMITS[key]} characters.`);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
request[key] = value;
|
|
231
|
+
};
|
|
232
|
+
bounded('name', 'site name');
|
|
233
|
+
bounded('seoTitle', 'search title');
|
|
234
|
+
bounded('seoDescription', 'search description');
|
|
235
|
+
bounded('separator', 'title separator');
|
|
236
|
+
bounded('businessName', 'business name');
|
|
237
|
+
bounded('businessDescription', 'business description');
|
|
238
|
+
bounded('address', 'address');
|
|
239
|
+
bounded('titlePattern', 'title pattern');
|
|
240
|
+
if (request.titlePattern && !aiSettingsTitlePatternOk(request.titlePattern)) {
|
|
241
|
+
problems.push('The title pattern may use only {{page.name}}, {{site.separator}} and {{site.name}}.');
|
|
242
|
+
delete request.titlePattern;
|
|
243
|
+
}
|
|
244
|
+
bounded('telephone', 'phone number');
|
|
245
|
+
if (request.telephone && !TELEPHONE.test(request.telephone)) {
|
|
246
|
+
problems.push(`“${request.telephone}” is not a phone number.`);
|
|
247
|
+
delete request.telephone;
|
|
248
|
+
}
|
|
249
|
+
bounded('supportEmail', 'contact email');
|
|
250
|
+
if (request.supportEmail && !EMAIL.test(request.supportEmail)) {
|
|
251
|
+
problems.push(`“${request.supportEmail}” is not an email address.`);
|
|
252
|
+
delete request.supportEmail;
|
|
253
|
+
}
|
|
254
|
+
const language = text(inputs == null ? void 0 : inputs['language']);
|
|
255
|
+
if (language) {
|
|
256
|
+
const locale = siteLanguageCode(language);
|
|
257
|
+
if (locale) request.language = locale;
|
|
258
|
+
else problems.push(`“${language}” is not a language code such as es or pt-BR.`);
|
|
259
|
+
}
|
|
260
|
+
const timeZone = text(inputs == null ? void 0 : inputs['timeZone']);
|
|
261
|
+
if (timeZone) {
|
|
262
|
+
if (supportedTimeZones().includes(timeZone)) request.timeZone = timeZone;
|
|
263
|
+
else problems.push(`“${timeZone}” is not a time zone the site settings offer.`);
|
|
264
|
+
}
|
|
265
|
+
const consentMode = text(inputs == null ? void 0 : inputs['consentMode']);
|
|
266
|
+
if (consentMode) {
|
|
267
|
+
if (AI_SETTINGS_CONSENT_MODES.includes(consentMode)) {
|
|
268
|
+
request.consentMode = consentMode;
|
|
269
|
+
} else problems.push('The cookie banner’s mode is geo or strict.');
|
|
270
|
+
}
|
|
271
|
+
for (const key of AI_SETTINGS_MEDIA_ARGS){
|
|
272
|
+
const value = text(inputs == null ? void 0 : inputs[key]);
|
|
273
|
+
if (value) request[key] = value.slice(0, 200);
|
|
274
|
+
}
|
|
275
|
+
return {
|
|
276
|
+
request,
|
|
277
|
+
problems
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
/** Whether a read request asks for anything at all. */ export function aiSettingsRequestEmpty(request) {
|
|
281
|
+
return Object.keys(request).length === 0;
|
|
282
|
+
}
|
|
283
|
+
function mediaRowOf(doc, org) {
|
|
284
|
+
var _doc_data, _data_fileName, _data_contentType;
|
|
285
|
+
const data = (_doc_data = doc.data()) != null ? _doc_data : {};
|
|
286
|
+
const number = (value)=>typeof value === 'number' && value > 0 ? value : null;
|
|
287
|
+
return _extends({
|
|
288
|
+
id: doc.id,
|
|
289
|
+
fileName: String((_data_fileName = data['fileName']) != null ? _data_fileName : ''),
|
|
290
|
+
contentType: String((_data_contentType = data['contentType']) != null ? _data_contentType : ''),
|
|
291
|
+
url: typeof data['url'] === 'string' ? data['url'] : null,
|
|
292
|
+
cdnPath: typeof data['cdnPath'] === 'string' ? data['cdnPath'] : null,
|
|
293
|
+
contentHash: typeof data['contentHash'] === 'string' ? data['contentHash'] : null,
|
|
294
|
+
private: data['private'] === true,
|
|
295
|
+
deleted: data['deletedAt'] != null
|
|
296
|
+
}, org ? {
|
|
297
|
+
visibleTo: Array.isArray(data['visibleTo']) ? data['visibleTo'] : null
|
|
298
|
+
} : {}, {
|
|
299
|
+
width: number(data['width']),
|
|
300
|
+
height: number(data['height']),
|
|
301
|
+
alt: typeof data['alt'] === 'string' ? data['alt'] : ''
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* The rows a media name could be, from the site's own library and then its
|
|
306
|
+
* org's: the one whose id it is, else those whose file name it is.
|
|
307
|
+
*/ export async function readAiSettingsMediaRows(firestore, input) {
|
|
308
|
+
const libraries = [
|
|
309
|
+
{
|
|
310
|
+
ref: firestore.collection('hosts').doc(input.hostId).collection('media'),
|
|
311
|
+
org: false
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
ref: firestore.collection('orgs').doc(input.orgId).collection('media'),
|
|
315
|
+
org: true
|
|
316
|
+
}
|
|
317
|
+
];
|
|
318
|
+
const rows = [];
|
|
319
|
+
for (const library of libraries){
|
|
320
|
+
if (/^[A-Za-z0-9_-]{1,128}$/.test(input.source)) {
|
|
321
|
+
const byId = await library.ref.doc(input.source).get();
|
|
322
|
+
if (byId.exists) rows.push(mediaRowOf(byId, library.org));
|
|
323
|
+
}
|
|
324
|
+
const byName = await library.ref.where('fileName', '==', input.source).limit(5).get();
|
|
325
|
+
for (const doc of byName.docs)if (!rows.some((row)=>row.id === doc.id)) rows.push(mediaRowOf(doc, library.org));
|
|
326
|
+
}
|
|
327
|
+
return rows;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* The image a setting names, chosen from the rows read: a public image of
|
|
331
|
+
* this site's library, or of its org's that this site may use, never deleted.
|
|
332
|
+
* Its id wins over a file name; two images of one name are refused in words.
|
|
333
|
+
*/ export function aiSettingsMediaOf(arg, source, rows, hostId) {
|
|
334
|
+
const noun = MEDIA_ARG_NOUNS[arg];
|
|
335
|
+
const usable = rows.filter((row)=>!row.deleted && !row.private && row.contentType.startsWith('image/') && (row.visibleTo === undefined || visibleToHost(row.visibleTo, hostId)));
|
|
336
|
+
const byId = usable.find((row)=>row.id === source);
|
|
337
|
+
const named = usable.filter((row)=>row.fileName === source);
|
|
338
|
+
if (!byId && named.length > 1) return {
|
|
339
|
+
error: `The media library has more than one image called “${source}”; name the one for the ${noun}.`
|
|
340
|
+
};
|
|
341
|
+
const row = byId != null ? byId : named[0];
|
|
342
|
+
if (!row) return {
|
|
343
|
+
error: `The media library has no image “${source}” this site can use for the ${noun}.`
|
|
344
|
+
};
|
|
345
|
+
const src = mediaNodeSrc({
|
|
346
|
+
url: row.url,
|
|
347
|
+
cdnPath: row.cdnPath,
|
|
348
|
+
contentHash: row.contentHash,
|
|
349
|
+
private: row.private
|
|
350
|
+
});
|
|
351
|
+
if (!src) return {
|
|
352
|
+
error: `The image “${source}” has no address the site can show.`
|
|
353
|
+
};
|
|
354
|
+
return {
|
|
355
|
+
src,
|
|
356
|
+
width: row.width,
|
|
357
|
+
height: row.height,
|
|
358
|
+
alt: row.alt,
|
|
359
|
+
fileName: row.fileName || row.id
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
const getPath = (data, path)=>path.split('.').reduce((at, key)=>at && typeof at === 'object' ? at[key] : undefined, data);
|
|
363
|
+
const sameValue = (a, b)=>JSON.stringify(a != null ? a : null) === JSON.stringify(b != null ? b : null);
|
|
364
|
+
/**
|
|
365
|
+
* The language change, as the Languages card would save it: a site with no
|
|
366
|
+
* languages, or one, now publishes in this one; a multilingual site that
|
|
367
|
+
* lists it makes it the default. A multilingual site that does not list it
|
|
368
|
+
* is refused, because adding a language is the Languages card's decision.
|
|
369
|
+
*/ export function aiSettingsLanguageChanges(host, language) {
|
|
370
|
+
const locales = Array.isArray(host.locales) ? host.locales.filter((one)=>typeof one === 'string') : [];
|
|
371
|
+
const said = `The site’s language is now ${language}.`;
|
|
372
|
+
if (locales.length > 1) {
|
|
373
|
+
if (!locales.includes(language)) {
|
|
374
|
+
return {
|
|
375
|
+
error: `This site publishes in ${locales.join(', ')}; add ${language} in Settings → Details → Languages first.`
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
return [
|
|
379
|
+
{
|
|
380
|
+
path: 'defaultLocale',
|
|
381
|
+
value: language,
|
|
382
|
+
said
|
|
383
|
+
}
|
|
384
|
+
];
|
|
385
|
+
}
|
|
386
|
+
return [
|
|
387
|
+
{
|
|
388
|
+
path: 'locales',
|
|
389
|
+
value: [
|
|
390
|
+
language
|
|
391
|
+
],
|
|
392
|
+
said
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
path: 'defaultLocale',
|
|
396
|
+
value: language,
|
|
397
|
+
said
|
|
398
|
+
}
|
|
399
|
+
];
|
|
400
|
+
}
|
|
401
|
+
/** Every change the request asks of this host, before comparing with what is stored. */ export function aiSettingsChanges(host, request, media) {
|
|
402
|
+
const changes = [];
|
|
403
|
+
const problems = [];
|
|
404
|
+
const set = (path, value, said)=>changes.push({
|
|
405
|
+
path,
|
|
406
|
+
value,
|
|
407
|
+
said
|
|
408
|
+
});
|
|
409
|
+
if (request.name) set('displayName', request.name, `The site is now called “${request.name}”.`);
|
|
410
|
+
if (request.seoTitle) set('seo.title', request.seoTitle, `The search title is now “${request.seoTitle}”.`);
|
|
411
|
+
if (request.seoDescription) set('seo.description', request.seoDescription, 'The search description is set.');
|
|
412
|
+
if (request.separator) set('seo.separator', request.separator, `The title separator is now “${request.separator}”.`);
|
|
413
|
+
if (request.titlePattern) set('seo.titlePattern', request.titlePattern, `Untitled pages are now titled “${request.titlePattern}”.`);
|
|
414
|
+
if (request.businessName) set('seo.entity.name', request.businessName, `The business name is now “${request.businessName}”.`);
|
|
415
|
+
if (request.businessDescription) set('seo.entity.description', request.businessDescription, 'The business description is set.');
|
|
416
|
+
if (request.telephone) set('seo.entity.telephone', request.telephone, `The phone number is now ${request.telephone}.`);
|
|
417
|
+
if (request.supportEmail) set('business.supportEmail', request.supportEmail, `The contact email is now ${request.supportEmail}.`);
|
|
418
|
+
if (request.address) set('business.address', request.address, 'The address is set.');
|
|
419
|
+
if (request.timeZone) set('timeZone', request.timeZone, `The site’s time zone is now ${request.timeZone}.`);
|
|
420
|
+
if (request.consentMode) {
|
|
421
|
+
set('consent.mode', request.consentMode, request.consentMode === 'strict' ? 'The cookie banner now asks every visitor.' : 'The cookie banner now asks where the law requires.');
|
|
422
|
+
}
|
|
423
|
+
if (request.language) {
|
|
424
|
+
const language = aiSettingsLanguageChanges(host, request.language);
|
|
425
|
+
if ('error' in language) problems.push(language.error);
|
|
426
|
+
else changes.push(...language);
|
|
427
|
+
}
|
|
428
|
+
if (media.favicon) set('seo.favicon', media.favicon.src, `The favicon is now “${media.favicon.fileName}”.`);
|
|
429
|
+
if (media.logo) set('logoUrl', media.logo.src, `The logo is now “${media.logo.fileName}”.`);
|
|
430
|
+
if (media.socialImage) {
|
|
431
|
+
var _image_width, _image_height, _inheritedMediaAlt;
|
|
432
|
+
const image = media.socialImage;
|
|
433
|
+
const said = `The social image is now “${image.fileName}”.`;
|
|
434
|
+
set('seo.image', image.src, said);
|
|
435
|
+
// Its size and alt, as the Social image card copies them at pick time.
|
|
436
|
+
set('seo.imageWidth', (_image_width = image.width) != null ? _image_width : 0, said);
|
|
437
|
+
set('seo.imageHeight', (_image_height = image.height) != null ? _image_height : 0, said);
|
|
438
|
+
const savedAlt = getPath(host, 'seo.imageAlt');
|
|
439
|
+
set('seo.imageAlt', (_inheritedMediaAlt = inheritedMediaAlt({
|
|
440
|
+
placementAlt: savedAlt,
|
|
441
|
+
assetAlt: image.alt
|
|
442
|
+
})) != null ? _inheritedMediaAlt : typeof savedAlt === 'string' ? savedAlt : '', said);
|
|
443
|
+
}
|
|
444
|
+
return {
|
|
445
|
+
changes,
|
|
446
|
+
problems
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* The settings written, in one transaction that reads the host as it is
|
|
451
|
+
* stored NOW: the member still holds a write role, and only the values that
|
|
452
|
+
* differ from what is stored are written, with a site-wide publish outbox
|
|
453
|
+
* entry beside them so the live site's cached pages are dropped.
|
|
454
|
+
*/ export async function writeAiSiteSettings(firestore, input) {
|
|
455
|
+
const hostRef = firestore.collection('hosts').doc(input.hostId);
|
|
456
|
+
return firestore.runTransaction(async (tx)=>{
|
|
457
|
+
var _host_get, _host_data;
|
|
458
|
+
const host = await tx.get(hostRef);
|
|
459
|
+
if (!host.exists) return {
|
|
460
|
+
ok: false,
|
|
461
|
+
error: 'Unknown site'
|
|
462
|
+
};
|
|
463
|
+
const roles = (_host_get = host.get('memberRoles')) != null ? _host_get : {};
|
|
464
|
+
if (!hostRoleCanWrite(roles[input.uid])) return {
|
|
465
|
+
ok: false,
|
|
466
|
+
error: AI_SETTINGS_ROLE_COPY
|
|
467
|
+
};
|
|
468
|
+
const data = (_host_data = host.data()) != null ? _host_data : {};
|
|
469
|
+
const { changes, problems } = aiSettingsChanges(data, input.request, input.media);
|
|
470
|
+
const changed = changes.filter((change)=>!sameValue(getPath(data, change.path), change.value));
|
|
471
|
+
const done = [
|
|
472
|
+
...new Set(changes.map((change)=>change.said))
|
|
473
|
+
];
|
|
474
|
+
if (!changed.length) return {
|
|
475
|
+
ok: true,
|
|
476
|
+
done,
|
|
477
|
+
notDone: problems,
|
|
478
|
+
changed: [],
|
|
479
|
+
outboxId: null
|
|
480
|
+
};
|
|
481
|
+
const updates = {
|
|
482
|
+
updatedAt: input.now
|
|
483
|
+
};
|
|
484
|
+
for (const change of changed)updates[change.path] = change.value;
|
|
485
|
+
tx.update(hostRef, updates);
|
|
486
|
+
// The announce, written down in the save's own transaction: a setting
|
|
487
|
+
// has no address, so it asks for the whole site, as the console's does.
|
|
488
|
+
const outboxRef = firestore.collection('publishOutbox').doc(createResourceUid());
|
|
489
|
+
tx.set(outboxRef, {
|
|
490
|
+
hostId: input.hostId,
|
|
491
|
+
paths: [
|
|
492
|
+
SCREEN_ROOT_PATH
|
|
493
|
+
],
|
|
494
|
+
entireHost: true,
|
|
495
|
+
createdAt: FieldValue.serverTimestamp(),
|
|
496
|
+
attempts: 0
|
|
497
|
+
});
|
|
498
|
+
return {
|
|
499
|
+
ok: true,
|
|
500
|
+
done,
|
|
501
|
+
notDone: problems,
|
|
502
|
+
changed: changed.map((change)=>change.path),
|
|
503
|
+
outboxId: outboxRef.id
|
|
504
|
+
};
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
// ── The step ──────────────────────────────────────────────────────────────
|
|
508
|
+
/** Why this member may not change this site's settings now, or `null`. */ export async function aiSettingsAccessRefusal(input, deps = {}) {
|
|
509
|
+
var _input_host_get, _deps_lockdown;
|
|
510
|
+
if (!input.host.exists) return 'Unknown site';
|
|
511
|
+
const roles = (_input_host_get = input.host.get('memberRoles')) != null ? _input_host_get : {};
|
|
512
|
+
if (!hostRoleCanWrite(roles[input.uid])) return AI_SETTINGS_ROLE_COPY;
|
|
513
|
+
const locked = await ((_deps_lockdown = deps.lockdown) != null ? _deps_lockdown : getLockdownVerdict)({
|
|
514
|
+
staff: false,
|
|
515
|
+
uid: input.uid,
|
|
516
|
+
org: input.org,
|
|
517
|
+
host: input.host.data(),
|
|
518
|
+
intent: 'write'
|
|
519
|
+
});
|
|
520
|
+
return locked ? AI_SETTINGS_LOCKED_COPY : null;
|
|
521
|
+
}
|
|
522
|
+
/** The output's note: what changed, that it is live, and what was not done. */ export function aiSettingsOutputNote(done, notDone, language) {
|
|
523
|
+
// The build's own wording for an item with no draft state (AGL-3745).
|
|
524
|
+
const did = done.length ? `${done.join(' ')} Live now, in ${AI_SETTINGS_WHERE}.` : 'Nothing needed changing.';
|
|
525
|
+
const translate = language ? ' The pages keep the words they have: changing the language does not translate them.' : '';
|
|
526
|
+
const not = notDone.length ? ` Not done: ${notDone.join(' ')}` : '';
|
|
527
|
+
return `${did}${translate}${not}`.slice(0, 1000);
|
|
528
|
+
}
|
|
529
|
+
/** Each media argument resolved to its image, or a sentence for each that cannot be. */ async function mediaOf(firestore, input, readMedia) {
|
|
530
|
+
const media = {};
|
|
531
|
+
const problems = [];
|
|
532
|
+
for (const arg of AI_SETTINGS_MEDIA_ARGS){
|
|
533
|
+
const source = input.request[arg];
|
|
534
|
+
if (!source) continue;
|
|
535
|
+
const rows = await readMedia(firestore, {
|
|
536
|
+
hostId: input.hostId,
|
|
537
|
+
orgId: input.orgId,
|
|
538
|
+
source
|
|
539
|
+
});
|
|
540
|
+
const found = aiSettingsMediaOf(arg, source, rows, input.hostId);
|
|
541
|
+
if ('error' in found) problems.push(found.error);
|
|
542
|
+
else media[arg] = found;
|
|
543
|
+
}
|
|
544
|
+
return {
|
|
545
|
+
media,
|
|
546
|
+
problems
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
export function createAiJobSettingsStep(deps = {}) {
|
|
550
|
+
var _deps_readMedia, _deps_write, _deps_dropCache, _deps_syncMemberships;
|
|
551
|
+
const readMedia = (_deps_readMedia = deps.readMedia) != null ? _deps_readMedia : readAiSettingsMediaRows;
|
|
552
|
+
const write = (_deps_write = deps.write) != null ? _deps_write : writeAiSiteSettings;
|
|
553
|
+
const dropCache = (_deps_dropCache = deps.dropCache) != null ? _deps_dropCache : dropPluginSiteCache;
|
|
554
|
+
const syncMemberships = (_deps_syncMemberships = deps.syncMemberships) != null ? _deps_syncMemberships : syncHostProjectionForMembers;
|
|
555
|
+
return async ({ job, now, firestore, org, modelFor })=>{
|
|
556
|
+
var _ref, _data;
|
|
557
|
+
// No model is asked: the outcome records the edit step's at no cost.
|
|
558
|
+
const model = (_ref = modelFor == null ? void 0 : modelFor('job.edit')) != null ? _ref : aiJobEditModel();
|
|
559
|
+
const unspent = (failure)=>_extends({}, aiUnspentOutcome(model), {
|
|
560
|
+
failure
|
|
561
|
+
});
|
|
562
|
+
const hostId = job.hostId;
|
|
563
|
+
if (!hostId) return unspent(AI_SETTINGS_NO_SITE_COPY);
|
|
564
|
+
const read = aiSettingsRequestOf(job.inputs);
|
|
565
|
+
if (aiSettingsRequestEmpty(read.request)) return unspent([
|
|
566
|
+
AI_SETTINGS_NOTHING_COPY,
|
|
567
|
+
...read.problems
|
|
568
|
+
].join(' '));
|
|
569
|
+
const orgData = org != null ? org : (_data = (await firestore.collection('orgs').doc(job.orgId).get()).data()) != null ? _data : null;
|
|
570
|
+
const host = await firestore.collection('hosts').doc(hostId).get();
|
|
571
|
+
const refused = await aiSettingsAccessRefusal({
|
|
572
|
+
host,
|
|
573
|
+
uid: job.createdBy,
|
|
574
|
+
org: orgData
|
|
575
|
+
}, {
|
|
576
|
+
lockdown: deps.lockdown
|
|
577
|
+
});
|
|
578
|
+
if (refused) return aiUnspentOutcome(model, {
|
|
579
|
+
review: aiLimitReview(refused)
|
|
580
|
+
});
|
|
581
|
+
const found = await mediaOf(firestore, {
|
|
582
|
+
hostId,
|
|
583
|
+
orgId: job.orgId,
|
|
584
|
+
request: read.request
|
|
585
|
+
}, readMedia);
|
|
586
|
+
const written = await write(firestore, {
|
|
587
|
+
hostId,
|
|
588
|
+
uid: job.createdBy,
|
|
589
|
+
request: read.request,
|
|
590
|
+
media: found.media,
|
|
591
|
+
now
|
|
592
|
+
});
|
|
593
|
+
if (written.ok === false) return unspent(written.error);
|
|
594
|
+
const notDone = [
|
|
595
|
+
...read.problems,
|
|
596
|
+
...found.problems,
|
|
597
|
+
...written.notDone
|
|
598
|
+
];
|
|
599
|
+
if (!written.done.length) return unspent([
|
|
600
|
+
AI_SETTINGS_NOTHING_COPY,
|
|
601
|
+
...notDone
|
|
602
|
+
].join(' '));
|
|
603
|
+
if (written.outboxId) {
|
|
604
|
+
// The live site's cached pages go now; the outbox entry stays for the
|
|
605
|
+
// drain unless the drop certainly happened.
|
|
606
|
+
const dropped = await dropCache({
|
|
607
|
+
hostIds: [
|
|
608
|
+
hostId
|
|
609
|
+
],
|
|
610
|
+
reason: 'AI build changed site settings'
|
|
611
|
+
}).catch(()=>({
|
|
612
|
+
complete: false
|
|
613
|
+
}));
|
|
614
|
+
if (dropped.complete) await firestore.collection('publishOutbox').doc(written.outboxId).delete().catch(()=>undefined);
|
|
615
|
+
}
|
|
616
|
+
if (written.changed.includes('displayName')) {
|
|
617
|
+
// The site switcher lists sites by the name members' projections carry.
|
|
618
|
+
await syncMemberships(job.orgId, hostId).catch((error)=>{
|
|
619
|
+
console.error('ai settings: membership projection not synced', {
|
|
620
|
+
hostId,
|
|
621
|
+
jobId: job.$id,
|
|
622
|
+
error
|
|
623
|
+
});
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
const output = {
|
|
627
|
+
resource: 'settings',
|
|
628
|
+
id: AI_SETTINGS_OUTPUT_ID,
|
|
629
|
+
hostId,
|
|
630
|
+
hostSubdomain: typeof host.get('subdomain') === 'string' && host.get('subdomain') || null,
|
|
631
|
+
label: 'Site settings',
|
|
632
|
+
note: aiSettingsOutputNote(written.done, notDone, Boolean(read.request.language))
|
|
633
|
+
};
|
|
634
|
+
return aiUnspentOutcome(model, {
|
|
635
|
+
outputs: [
|
|
636
|
+
output
|
|
637
|
+
]
|
|
638
|
+
});
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
export const runAiJobSettingsStep = createAiJobSettingsStep();
|
|
642
|
+
/**
|
|
643
|
+
* A settings change is admitted on a site of the job's own org, for a member
|
|
644
|
+
* who may write its settings now, where the request names at least one
|
|
645
|
+
* setting this can change. Refused in those words before anything is written.
|
|
646
|
+
*/ export function createAiSettingsJobAdmission(deps = {}) {
|
|
647
|
+
var _deps_ownerOf;
|
|
648
|
+
const ownerOf = (_deps_ownerOf = deps.ownerOf) != null ? _deps_ownerOf : resolveOrgIdForHost;
|
|
649
|
+
return async (context)=>{
|
|
650
|
+
var _context_uid;
|
|
651
|
+
if (!context.hostId) return {
|
|
652
|
+
status: 400,
|
|
653
|
+
error: AI_SETTINGS_NO_SITE_COPY
|
|
654
|
+
};
|
|
655
|
+
const owner = await ownerOf(context.hostId);
|
|
656
|
+
if (!owner || owner !== context.orgId) return {
|
|
657
|
+
status: 404,
|
|
658
|
+
error: 'Unknown site'
|
|
659
|
+
};
|
|
660
|
+
const host = await context.firestore.collection('hosts').doc(context.hostId).get();
|
|
661
|
+
const refused = await aiSettingsAccessRefusal({
|
|
662
|
+
host,
|
|
663
|
+
uid: (_context_uid = context.uid) != null ? _context_uid : '',
|
|
664
|
+
org: context.org
|
|
665
|
+
}, {
|
|
666
|
+
lockdown: deps.lockdown
|
|
667
|
+
});
|
|
668
|
+
if (refused) return {
|
|
669
|
+
status: 403,
|
|
670
|
+
error: refused
|
|
671
|
+
};
|
|
672
|
+
const read = aiSettingsRequestOf(context.inputs);
|
|
673
|
+
return aiSettingsRequestEmpty(read.request) ? {
|
|
674
|
+
status: 400,
|
|
675
|
+
error: [
|
|
676
|
+
AI_SETTINGS_NOTHING_COPY,
|
|
677
|
+
...read.problems
|
|
678
|
+
].join(' ')
|
|
679
|
+
} : null;
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
export const aiSettingsJobAdmission = createAiSettingsJobAdmission();
|
|
683
|
+
/** Registers the settings step and its door (AGL-3748). */ export function registerAiSettingsJob() {
|
|
684
|
+
registerAiJobStep(AI_SETTINGS_KIND, runAiJobSettingsStep, {
|
|
685
|
+
minimumMs: AI_JOB_SETTINGS_STEP_MINIMUM_MS
|
|
686
|
+
});
|
|
687
|
+
registerAiJobAdmission(AI_SETTINGS_KIND, aiSettingsJobAdmission);
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
//# sourceMappingURL=ai-job-settings-step.js.map
|