@velocity-astro/cms-plugins 0.0.0-stage → 0.1.0-beta.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Southwell Media
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,13 @@
1
- # Temporary Holding Version
1
+ # @velocity-astro/cms-plugins
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The plugins that come with Velocity CMS. Every site lists them under Plugins, switched off until an owner activates one.
4
+
5
+ Part of [Velocity CMS](https://github.com/Velocity-Astro/velocity-cms), a content management system for Astro sites. A site installs `@velocity-astro/cms-astro`, which brings the rest:
6
+
7
+ ```sh
8
+ npx velocity-cms init
9
+ ```
10
+
11
+ Docs: https://docs.deployvelocity.com/cms/
12
+
13
+ MIT
@@ -0,0 +1,10 @@
1
+ /** The one address this plugin sends to. Nothing an owner types can change it. */
2
+ export declare const HUBSPOT_UPSERT = "https://api.hubapi.com/crm/v3/objects/contacts/batch/upsert";
3
+ /**
4
+ * HubSpot: keeps a copy of the site's contacts in HubSpot. A contact made here, by a form or by
5
+ * hand, is made there, matched by email, and a change to the name or phone follows. It goes one
6
+ * way: nothing is read from HubSpot, and erasing a contact here does not erase it there. One
7
+ * that cannot be sent is tried again for about a day. Built on the plugin surface alone.
8
+ */
9
+ export declare const hubspot: import("@velocity-astro/cms-core").PluginDefinition;
10
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/hubspot/plugin.ts"],"names":[],"mappings":"AAKA,kFAAkF;AAClF,eAAO,MAAM,cAAc,gEAAgE,CAAC;AAsB5F;;;;;GAKG;AACH,eAAO,MAAM,OAAO,qDA8DlB,CAAC"}
@@ -0,0 +1,92 @@
1
+ import { definePlugin } from '@velocity-astro/cms-core';
2
+ /** How long HubSpot has to answer before a try counts as failed. */
3
+ const ANSWER_WITHIN_MS = 8000;
4
+ const UPSERT = 'upsert';
5
+ /** The one address this plugin sends to. Nothing an owner types can change it. */
6
+ export const HUBSPOT_UPSERT = 'https://api.hubapi.com/crm/v3/objects/contacts/batch/upsert';
7
+ /** The stages HubSpot has for a new person. Anything else typed into the setting is left out. */
8
+ const LIFECYCLE_STAGES = new Set(['subscriber', 'lead', 'marketingqualifiedlead', 'salesqualifiedlead', 'opportunity', 'customer', 'evangelist', 'other']);
9
+ const isRecord = (value) => typeof value === 'object' && value !== null;
10
+ const isPerson = (value) => isRecord(value) && typeof value['email'] === 'string';
11
+ const personOf = (contact) => ({
12
+ email: contact.email,
13
+ ...(contact.name !== undefined && { name: contact.name }),
14
+ ...(contact.phone !== undefined && { phone: contact.phone }),
15
+ isNew: contact.revision === 1,
16
+ });
17
+ /**
18
+ * HubSpot: keeps a copy of the site's contacts in HubSpot. A contact made here, by a form or by
19
+ * hand, is made there, matched by email, and a change to the name or phone follows. It goes one
20
+ * way: nothing is read from HubSpot, and erasing a contact here does not erase it there. One
21
+ * that cannot be sent is tried again for about a day. Built on the plugin surface alone.
22
+ */
23
+ export const hubspot = definePlugin({
24
+ name: 'hubspot',
25
+ apiVersion: 1,
26
+ label: { en: 'HubSpot' },
27
+ description: { en: 'Copy your contacts to HubSpot as they are made and changed, matched by email. Experimental: tested, but not yet tried against the real service.' },
28
+ version: '1.0.0',
29
+ permissions: ['contact:read'],
30
+ enabledByDefault: false,
31
+ settings: [
32
+ {
33
+ key: 'lifecycleStage',
34
+ type: 'text',
35
+ label: { en: 'Lifecycle stage for new contacts' },
36
+ help: { en: 'Optional. One of HubSpot\'s own, written as HubSpot names it: subscriber, lead, marketingqualifiedlead, salesqualifiedlead, opportunity, customer. Leave empty to let HubSpot decide.' },
37
+ },
38
+ { key: 'onlyNew', type: 'boolean', label: { en: 'Send new contacts only' }, help: { en: 'Left off, a change to a contact\'s name or phone here is sent to HubSpot too.' } },
39
+ ],
40
+ secrets: [
41
+ {
42
+ key: 'accessToken',
43
+ label: { en: 'Private app access token' },
44
+ help: { en: 'In HubSpot: Settings, Integrations, Private Apps. Create an app that may write contacts (crm.objects.contacts.write) and copy its token.' },
45
+ },
46
+ ],
47
+ setup(cms) {
48
+ cms.tasks.define(UPSERT, async (payload) => {
49
+ if (!isPerson(payload))
50
+ throw new Error('This piece of work was kept in a form this version cannot read.');
51
+ const token = await cms.secrets.get('accessToken');
52
+ if (token === undefined)
53
+ throw new Error('No access token is saved. Save one under Plugins, then try again.');
54
+ const settings = await cms.settings.get();
55
+ const stage = typeof settings['lifecycleStage'] === 'string' ? settings['lifecycleStage'].trim().toLowerCase() : '';
56
+ const [first, ...rest] = (payload.name ?? '').split(/\s+/).filter((part) => part !== '');
57
+ const properties = {
58
+ email: payload.email,
59
+ ...(first !== undefined && { firstname: first }),
60
+ ...(rest.length > 0 && { lastname: rest.join(' ') }),
61
+ ...(payload.phone !== undefined && { phone: payload.phone }),
62
+ ...(payload.isNew && LIFECYCLE_STAGES.has(stage) && { lifecyclestage: stage }),
63
+ };
64
+ let answer;
65
+ try {
66
+ answer = await fetch(HUBSPOT_UPSERT, {
67
+ method: 'POST',
68
+ headers: { 'content-type': 'application/json', 'user-agent': 'Velocity-CMS-HubSpot/1', authorization: `Bearer ${token.trim()}` },
69
+ body: JSON.stringify({ inputs: [{ id: payload.email, idProperty: 'email', properties }] }),
70
+ redirect: 'manual',
71
+ signal: AbortSignal.timeout(ANSWER_WITHIN_MS),
72
+ });
73
+ }
74
+ catch {
75
+ throw new Error(`HubSpot could not be reached within ${ANSWER_WITHIN_MS / 1000} seconds.`);
76
+ }
77
+ if (answer.status === 401)
78
+ throw new Error('HubSpot refused the access token. Save a working one under Plugins.');
79
+ if (answer.status === 403)
80
+ throw new Error('The access token may not write contacts. Give the private app crm.objects.contacts.write in HubSpot.');
81
+ // A 207 says some of what was sent was refused, and one person was sent. Why is not repeated: its words may name them.
82
+ if (!answer.ok || answer.status === 207)
83
+ throw new Error(`HubSpot answered ${answer.status} and did not take this contact.`);
84
+ });
85
+ cms.events.on('contact.saved', async ({ contact }) => {
86
+ if (contact.revision !== 1 && (await cms.settings.get())['onlyNew'] === true)
87
+ return;
88
+ await cms.tasks.add(UPSERT, personOf(contact), { label: contact.revision === 1 ? 'A new contact, to HubSpot' : 'A changed contact, to HubSpot' });
89
+ });
90
+ },
91
+ });
92
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/hubspot/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAgB,MAAM,0BAA0B,CAAC;AAEtE,oEAAoE;AACpE,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAC9B,MAAM,MAAM,GAAG,QAAQ,CAAC;AACxB,kFAAkF;AAClF,MAAM,CAAC,MAAM,cA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AC;YAClH,IAAI,MAAM,CAAC,MAAM,KAAK,GAAG;gBAAE,MAAM,IAAI,KAAK,CAAC,sGAAsG,CAAC,CAAC;YACnJ,uHAAuH;YACvH,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,MAAM,CAAC,MAAM,KAAK,GAAG;gBAAE,MAAM,IAAI,KAAK,CAAC,oBAAoB,MAAM,CAAC,MAAM,iCAAiC,CAAC,CAAC;QAC/H,CAAC,CAAC,CAAC;QAEH,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,eAAe,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;YACnD,IAAI,OAAO,CAAC,QAAQ,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,SAAS,CAAC,KAAK,IAAI;gBAAE,OAAO;YACrF,MAAM,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,2BAA2B,CAAC,CAAC,CAAC,+BAA+B,EAAE,CAAC,CAAC;QACpJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { PluginDefinition } from '@velocity-astro/cms-core';
2
+ import { hubspot } from './hubspot/plugin.js';
3
+ import { mailchimp, mailchimpHost } from './mailchimp/plugin.js';
4
+ import { slack, slackAddress } from './slack/plugin.js';
5
+ export { hubspot, mailchimp, mailchimpHost, slack, slackAddress };
6
+ export { seo } from './seo/plugin.js';
7
+ export { webhooks, deliveryAddress } from './webhooks/plugin.js';
8
+ export { analyse, type SeoAnalysis, type SeoConfig, type SeoProblem } from './seo/analyse.js';
9
+ /**
10
+ * The plugins that come with Velocity CMS. Every site loads them, each switched off until an
11
+ * owner activates it under Plugins, so nobody needs a developer to add one. A plugin joins this
12
+ * list when it is built on the plugin surface alone and says `enabledByDefault: false`.
13
+ */
14
+ export declare const catalogue: readonly PluginDefinition[];
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEjE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGxD,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC;AAClE,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9F;;;;GAIG;AACH,eAAO,MAAM,SAAS,EAAE,SAAS,gBAAgB,EAA+C,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ import { hubspot } from './hubspot/plugin.js';
2
+ import { mailchimp, mailchimpHost } from './mailchimp/plugin.js';
3
+ import { seo } from './seo/plugin.js';
4
+ import { slack, slackAddress } from './slack/plugin.js';
5
+ import { webhooks } from './webhooks/plugin.js';
6
+ export { hubspot, mailchimp, mailchimpHost, slack, slackAddress };
7
+ export { seo } from './seo/plugin.js';
8
+ export { webhooks, deliveryAddress } from './webhooks/plugin.js';
9
+ export { analyse } from './seo/analyse.js';
10
+ /**
11
+ * The plugins that come with Velocity CMS. Every site loads them, each switched off until an
12
+ * owner activates it under Plugins, so nobody needs a developer to add one. A plugin joins this
13
+ * list when it is built on the plugin surface alone and says `enabledByDefault: false`.
14
+ */
15
+ export const catalogue = [seo, webhooks, mailchimp, slack, hubspot];
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC;AAClE,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,OAAO,EAAqD,MAAM,kBAAkB,CAAC;AAE9F;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAgC,CAAC,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Where a key's account lives. A Mailchimp key ends in its data centre, such as `-us21`, and
3
+ * that is the only part of it that chooses a host: anything else in its place is refused, so a
4
+ * key can never send a request anywhere but Mailchimp.
5
+ */
6
+ export declare function mailchimpHost(key: string): string;
7
+ /**
8
+ * Mailchimp: adds the people who send a form to an audience. An owner saves an API key, names
9
+ * the audience, and may name the forms and a yes or no field that asks for consent. Each person
10
+ * is added once: someone already in the audience, or who unsubscribed, is left as they are. One
11
+ * that cannot be added is tried again for about a day. Built on the plugin surface alone.
12
+ */
13
+ export declare const mailchimp: import("@velocity-astro/cms-core").PluginDefinition;
14
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/mailchimp/plugin.ts"],"names":[],"mappings":"AAkBA;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIjD;AAWD;;;;;GAKG;AACH,eAAO,MAAM,SAAS,qDAiFpB,CAAC"}
@@ -0,0 +1,128 @@
1
+ import { definePlugin, liveFields } from '@velocity-astro/cms-core';
2
+ /** How long Mailchimp has to answer before a try counts as failed. */
3
+ const ANSWER_WITHIN_MS = 8000;
4
+ const SUBSCRIBE = 'subscribe';
5
+ const isRecord = (value) => typeof value === 'object' && value !== null;
6
+ const isSubscriber = (value) => isRecord(value) && typeof value['email'] === 'string';
7
+ const text = (value) => (typeof value === 'string' ? value.trim() : '');
8
+ const listOf = (value) => text(value).split(',').map((part) => part.trim()).filter((part) => part !== '');
9
+ /**
10
+ * Where a key's account lives. A Mailchimp key ends in its data centre, such as `-us21`, and
11
+ * that is the only part of it that chooses a host: anything else in its place is refused, so a
12
+ * key can never send a request anywhere but Mailchimp.
13
+ */
14
+ export function mailchimpHost(key) {
15
+ const centre = /-([a-z]{2}\d{1,3})$/.exec(key.trim())?.[1];
16
+ if (centre === undefined)
17
+ throw new Error('The API key does not look like a Mailchimp key. It ends in a dash and a data centre, such as -us21. Save it again under Plugins.');
18
+ return `${centre}.api.mailchimp.com`;
19
+ }
20
+ /** The sender as Mailchimp is told of them: the email, and the name and phone when the form marks the fields that hold them. */
21
+ function subscriberOf(form, submission) {
22
+ if (submission.email === undefined)
23
+ return undefined;
24
+ const held = (id) => (id === undefined ? '' : text(submission.data[id]));
25
+ const name = held(form.contact?.name);
26
+ const phone = held(form.contact?.phone);
27
+ return { email: submission.email, ...(name !== '' && { name }), ...(phone !== '' && { phone }) };
28
+ }
29
+ /**
30
+ * Mailchimp: adds the people who send a form to an audience. An owner saves an API key, names
31
+ * the audience, and may name the forms and a yes or no field that asks for consent. Each person
32
+ * is added once: someone already in the audience, or who unsubscribed, is left as they are. One
33
+ * that cannot be added is tried again for about a day. Built on the plugin surface alone.
34
+ */
35
+ export const mailchimp = definePlugin({
36
+ name: 'mailchimp',
37
+ apiVersion: 1,
38
+ label: { en: 'Mailchimp' },
39
+ description: { en: 'Add the people who send your forms to a Mailchimp audience, with a confirmation email first unless you say otherwise. Experimental: tested, but not yet tried against the real service.' },
40
+ version: '1.0.0',
41
+ permissions: ['submission:read'],
42
+ enabledByDefault: false,
43
+ settings: [
44
+ { key: 'audience', type: 'text', label: { en: 'Audience ID' }, help: { en: 'In Mailchimp: Audience, then Settings. It looks like a1b2c3d4e5.' } },
45
+ { key: 'forms', type: 'text', label: { en: 'Forms' }, help: { en: 'The keys of the forms whose senders are added, separated by commas, such as contact, newsletter. Leave empty for every form.' } },
46
+ {
47
+ key: 'consentField',
48
+ type: 'text',
49
+ label: { en: 'Consent field' },
50
+ help: { en: 'The key of a yes or no field on those forms, such as newsletter. With one named, only people who ticked it are added. Leave empty to add everyone who sends the form.' },
51
+ },
52
+ {
53
+ key: 'skipConfirmation',
54
+ type: 'boolean',
55
+ label: { en: 'Add people without a confirmation email' },
56
+ help: { en: 'Left off, Mailchimp emails each person a link to confirm before they join the audience.' },
57
+ },
58
+ { key: 'tags', type: 'text', label: { en: 'Tags' }, help: { en: 'Optional. Tags given to each person added, separated by commas.' } },
59
+ ],
60
+ secrets: [{ key: 'apiKey', label: { en: 'API key' }, help: { en: 'In Mailchimp: your profile, Extras, API keys. It ends in a dash and a data centre, such as -us21.' } }],
61
+ setup(cms) {
62
+ cms.tasks.define(SUBSCRIBE, async (payload) => {
63
+ if (!isSubscriber(payload))
64
+ throw new Error('This piece of work was kept in a form this version cannot read.');
65
+ const key = await cms.secrets.get('apiKey');
66
+ if (key === undefined)
67
+ throw new Error('No API key is saved. Save one under Plugins, then try again.');
68
+ const settings = await cms.settings.get();
69
+ const audience = text(settings['audience']);
70
+ if (!/^[a-z0-9]{4,40}$/i.test(audience))
71
+ throw new Error('The audience ID is missing or is not one. Find it in Mailchimp under Audience, Settings.');
72
+ const host = mailchimpHost(key);
73
+ const [first, ...rest] = (payload.name ?? '').split(/\s+/).filter((part) => part !== '');
74
+ const tags = listOf(settings['tags']);
75
+ const member = {
76
+ email_address: payload.email,
77
+ status: settings['skipConfirmation'] === true ? 'subscribed' : 'pending',
78
+ merge_fields: { ...(first !== undefined && { FNAME: first }), ...(rest.length > 0 && { LNAME: rest.join(' ') }), ...(payload.phone !== undefined && { PHONE: payload.phone }) },
79
+ ...(tags.length > 0 && { tags }),
80
+ };
81
+ let answer;
82
+ try {
83
+ // Existing members are not updated: someone who unsubscribed stays unsubscribed.
84
+ answer = await fetch(`https://${host}/3.0/lists/${audience}`, {
85
+ method: 'POST',
86
+ headers: { 'content-type': 'application/json', 'user-agent': 'Velocity-CMS-Mailchimp/1', authorization: `Basic ${btoa(`velocity:${key.trim()}`)}` },
87
+ body: JSON.stringify({ members: [member], update_existing: false }),
88
+ redirect: 'manual',
89
+ signal: AbortSignal.timeout(ANSWER_WITHIN_MS),
90
+ });
91
+ }
92
+ catch {
93
+ throw new Error(`Mailchimp could not be reached within ${ANSWER_WITHIN_MS / 1000} seconds.`);
94
+ }
95
+ if (answer.status === 401 || answer.status === 403)
96
+ throw new Error('Mailchimp refused the API key. Save a working one under Plugins.');
97
+ if (answer.status === 404)
98
+ throw new Error('Mailchimp has no audience with this ID. Check the audience ID in the settings.');
99
+ if (!answer.ok)
100
+ throw new Error(`Mailchimp answered ${answer.status}.`);
101
+ const result = await answer.json().catch(() => undefined);
102
+ const errors = isRecord(result) && Array.isArray(result['errors']) ? result['errors'].filter(isRecord) : [];
103
+ // Already there is what was asked for. Any other refusal is said by its code alone: its words may name the person.
104
+ const refused = errors.find((error) => error['error_code'] !== 'ERROR_CONTACT_EXISTS');
105
+ if (refused)
106
+ throw new Error(`Mailchimp did not take this address (${typeof refused['error_code'] === 'string' ? refused['error_code'] : 'no reason given'}).`);
107
+ });
108
+ // What looks like spam is kept in the inbox and never reaches a mailing list.
109
+ cms.events.on('submission.received', async ({ submission, form }) => {
110
+ if (submission.status === 'spam')
111
+ return;
112
+ const settings = await cms.settings.get();
113
+ const forms = listOf(settings['forms']);
114
+ if (forms.length > 0 && !forms.includes(form.key))
115
+ return;
116
+ const consent = text(settings['consentField']);
117
+ if (consent !== '') {
118
+ const field = liveFields(form.fields).find((candidate) => candidate.key === consent);
119
+ if (!field || submission.data[field.id] !== true)
120
+ return;
121
+ }
122
+ const subscriber = subscriberOf(form, submission);
123
+ if (subscriber)
124
+ await cms.tasks.add(SUBSCRIBE, subscriber, { label: `A sender of ${form.key} to Mailchimp` });
125
+ });
126
+ },
127
+ });
128
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/mailchimp/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAiC,MAAM,0BAA0B,CAAC;AAEnG,sEAAsE;AACtE,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAC9B,MAAM,SAAS,GAAG,WAAW,CAAC;AAS9B,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACnH,MAAM,YAAY,GAAG,CAAC,KAAc,EAAuB,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC;AACpH,MAAM,IAAI,GAAG,CAAC,KAAc,EAAU,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AACzF,MAAM,MAAM,GAAG,CAAC,KAAc,EAAY,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC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,cAAc,CAAC,CAAC,CAAC;YAC/C,IAAI,OAAO,KAAK,EAAE,EAAE,CAAC;gBACnB,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,KAAK,OAAO,CAAC,CAAC;gBACrF,IAAI,CAAC,KAAK,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,IAAI;oBAAE,OAAO;YAC3D,CAAC;YACD,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;YAClD,IAAI,UAAU;gBAAE,MAAM,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,eAAe,IAAI,CAAC,GAAG,eAAe,EAAE,CAAC,CAAC;QAChH,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,40 @@
1
+ import type { ContentTypeDef } from '@velocity-astro/cms-core';
2
+ /** What the SEO plugin goes by, from its settings. */
3
+ export interface SeoConfig {
4
+ /** Added to every page title, such as " | Lakeshore Realty". */
5
+ readonly titleSuffix: string;
6
+ /** The keys a description field may have, most wanted first. */
7
+ readonly descriptionKeys: readonly string[];
8
+ readonly maxTitle: number;
9
+ readonly maxDescription: number;
10
+ readonly requireDescription: boolean;
11
+ }
12
+ /** What an owner or editor wrote for search engines in place of an entry's own title and description. */
13
+ export interface SeoOverrides {
14
+ readonly title?: string;
15
+ readonly description?: string;
16
+ /** Asks search engines to leave the page out. */
17
+ readonly hidden?: boolean;
18
+ }
19
+ export type SeoProblem = 'no-title' | 'long-title' | 'no-description' | 'long-description';
20
+ export interface SeoAnalysis {
21
+ /** The title as a search engine would show it, ending included. Empty when the entry has none. */
22
+ readonly title: string;
23
+ readonly description: string;
24
+ /** The key of the field the description comes from, or `null` when the type has no such field. */
25
+ readonly descriptionKey: string | null;
26
+ /** The entry's own title and description, which show when nothing is written in their place. */
27
+ readonly ownTitle: string;
28
+ readonly ownDescription: string;
29
+ readonly problems: readonly SeoProblem[];
30
+ }
31
+ /**
32
+ * How one entry will read in search results. `data` is the entry's values by field id, as they
33
+ * are stored and as the editor's form holds them. `written` is what was written for search
34
+ * engines in their place, if anything.
35
+ *
36
+ * This function is also sent to the browser as text (see `plugin.ts`), so it must stand alone:
37
+ * it may use nothing but its arguments.
38
+ */
39
+ export declare function analyse(type: ContentTypeDef, data: Readonly<Record<string, unknown>>, config: SeoConfig, written?: SeoOverrides): SeoAnalysis;
40
+ //# sourceMappingURL=analyse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analyse.d.ts","sourceRoot":"","sources":["../../src/seo/analyse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE/D,sDAAsD;AACtD,MAAM,WAAW,SAAS;IACxB,gEAAgE;IAChE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,gEAAgE;IAChE,QAAQ,CAAC,eAAe,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,kBAAkB,EAAE,OAAO,CAAC;CACtC;AAED,yGAAyG;AACzG,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,iDAAiD;IACjD,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,YAAY,GAAG,gBAAgB,GAAG,kBAAkB,CAAC;AAE3F,MAAM,WAAW,WAAW;IAC1B,kGAAkG;IAClG,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,kGAAkG;IAClG,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IACvC,gGAAgG;IAChG,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,QAAQ,EAAE,SAAS,UAAU,EAAE,CAAC;CAC1C;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAE,YAAiB,GAAG,WAAW,CAqBjJ"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * How one entry will read in search results. `data` is the entry's values by field id, as they
3
+ * are stored and as the editor's form holds them. `written` is what was written for search
4
+ * engines in their place, if anything.
5
+ *
6
+ * This function is also sent to the browser as text (see `plugin.ts`), so it must stand alone:
7
+ * it may use nothing but its arguments.
8
+ */
9
+ export function analyse(type, data, config, written = {}) {
10
+ const fields = type.fields.filter((field) => field.deletedAt === undefined);
11
+ const text = (id) => {
12
+ const value = id === undefined ? undefined : data[id];
13
+ return typeof value === 'string' ? value.trim() : '';
14
+ };
15
+ const titleField = fields.find((field) => field.id === type.titlePath?.[0]) ?? fields.find((field) => field.type === 'text');
16
+ const descriptionField = config.descriptionKeys.map((key) => fields.find((field) => field.key === key && field.type === 'text')).find((field) => field !== undefined);
17
+ const ownTitle = text(titleField?.id);
18
+ const ownDescription = text(descriptionField?.id);
19
+ const own = (written.title ?? '').trim() || ownTitle;
20
+ const title = own === '' ? '' : `${own}${config.titleSuffix}`;
21
+ const description = (written.description ?? '').trim() || ownDescription;
22
+ const problems = [];
23
+ if (own === '')
24
+ problems.push('no-title');
25
+ else if (title.length > config.maxTitle)
26
+ problems.push('long-title');
27
+ // A type with no description field has nothing to fill in, so it is not counted against it.
28
+ if (description === '' && descriptionField)
29
+ problems.push('no-description');
30
+ else if (description.length > config.maxDescription)
31
+ problems.push('long-description');
32
+ return { title, description, descriptionKey: descriptionField?.key ?? null, ownTitle, ownDescription, problems };
33
+ }
34
+ //# sourceMappingURL=analyse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analyse.js","sourceRoot":"","sources":["../../src/seo/analyse.ts"],"names":[],"mappings":"AAmCA;;;;;;;GAOG;AACH,MAAM,UAAU,OAAO,CAAC,IAAoB,EAAE,IAAuC,EAAE,MAAiB,EAAE,UAAwB,EAAE;IAClI,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC;IAC5E,MAAM,IAAI,GAAG,CAAC,EAAsB,EAAE,EAAE;QACtC,MAAM,KAAK,GAAG,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACtD,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACvD,CAAC,CAAC;IACF,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC;IAC7H,MAAM,gBAAgB,GAAG,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,G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
+ import type { PluginEditorApi } from '@velocity-astro/cms-admin';
2
+ import type { analyse as Analyse, SeoProblem } from './analyse.js';
3
+ /** One entry with something to fix, as the server's review lists it. */
4
+ export interface SeoFinding {
5
+ readonly id: string;
6
+ readonly typeKey: string;
7
+ readonly typeLabel: string;
8
+ readonly name: string;
9
+ readonly status: string;
10
+ readonly problems: readonly SeoProblem[];
11
+ }
12
+ /**
13
+ * The SEO plugin's part of the editor: a search preview beside every entry, and a screen that
14
+ * lists what needs attention across the site.
15
+ *
16
+ * This function is sent to the browser as text (see `plugin.ts`), so it must stand alone: it may
17
+ * use nothing but its two arguments, and no helper from this file or any other.
18
+ */
19
+ export declare function seoEditor({ React, ui, client, links, register }: PluginEditorApi, analyse: typeof Analyse): void;
20
+ //# sourceMappingURL=editor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../../src/seo/editor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,KAAK,EAAE,OAAO,IAAI,OAAO,EAA2B,UAAU,EAAE,MAAM,cAAc,CAAC;AAE5F,wEAAwE;AACxE,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,SAAS,UAAU,EAAE,CAAC;CAC1C;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,OAAO,GAAG,IAAI,CAsMhH"}