domma-cms 1.44.1 → 1.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/CLAUDE.md +5 -2
- package/admin/js/api.js +1 -1
- package/admin/js/lib/plugins-arrange.js +2 -2
- package/admin/js/templates/plugins.html +6 -0
- package/admin/js/views/plugins.js +20 -10
- package/docs/plugin-development.md +1 -0
- package/package.json +1 -1
- package/public/css/site.css +1 -1
- package/server/routes/api/plugin-marketplace.js +43 -4
- package/server/server.js +4 -0
- package/server/services/notification-sources.js +5 -2
- package/server/services/pluginEntitlement.js +46 -2
- package/server/services/pluginInstaller.js +50 -0
- package/server/services/plugins.js +9 -0
- package/server/services/request-log.js +3 -1
- package/server/services/storeClient.js +65 -5
- package/server/templates/page.html +2 -2
|
@@ -35,6 +35,8 @@ import path from 'node:path';
|
|
|
35
35
|
const SLUG = /^[a-z0-9][a-z0-9-_]{0,63}$/;
|
|
36
36
|
/** Entitlement states a plugin runs under (pluginEntitlement.mayLoad). */
|
|
37
37
|
const LOADS = new Set(['valid', 'grace', 'support-ended']);
|
|
38
|
+
/** The store sells the Pro bundle under this name; it is a licence for its Tools, never a plugin of its own. */
|
|
39
|
+
const BUNDLE_SLUG = 'bundle-pro';
|
|
38
40
|
|
|
39
41
|
/** Messages the installer raises deliberately - things an admin can act on. Anything else stays vague (it can carry a path). */
|
|
40
42
|
function installError(err) {
|
|
@@ -222,7 +224,38 @@ export async function pluginMarketplaceRoutes(fastify) {
|
|
|
222
224
|
pending: pending.find(p => p.slug === e.slug)?.id ?? null
|
|
223
225
|
};
|
|
224
226
|
});
|
|
225
|
-
|
|
227
|
+
// EU VAT: when the store asks, the buy form asks for a country and an optional VAT number.
|
|
228
|
+
const vat = answer.vat && Array.isArray(answer.vat.countries)
|
|
229
|
+
? { countryRequired: answer.vat.countryRequired === true, countries: answer.vat.countries.filter(c => /^[A-Z]{2}$/.test(c?.code || '')).map(c => ({ code: c.code, name: String(c.name || c.code).slice(0, 60) })) }
|
|
230
|
+
: null;
|
|
231
|
+
const bundles = await storeBundles(answer, installed, pending);
|
|
232
|
+
return { available: true, mode: 'store', site: answer.site || null, siteError: answer.siteError || null, cmsVersion, catalogue, bundles, pending, connection: storeClient.connectionView(), ...(vat && { vat }) };
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* The store's bundles (the Pro bundle) for the screen: price, what it holds and what of that is here. A bundle
|
|
237
|
+
* this site holds also hands over the keys of Tools added to it since - kept, so Install works for them.
|
|
238
|
+
*/
|
|
239
|
+
async function storeBundles(answer, installed, pending) {
|
|
240
|
+
const rows = (Array.isArray(answer.bundles) ? answer.bundles : []).filter(b => SLUG.test(b?.slug || ''));
|
|
241
|
+
const fresh = {};
|
|
242
|
+
for (const b of rows) {
|
|
243
|
+
for (const [slug, key] of Object.entries(b.owned && b.keys && typeof b.keys === 'object' ? b.keys : {})) {
|
|
244
|
+
if (SLUG.test(slug) && storeClient.KEY_FORMAT.test(String(key))) fresh[slug] = String(key);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
const held = storeClient.readState().keys;
|
|
248
|
+
if (Object.entries(fresh).some(([slug, key]) => held[slug] !== key)) {
|
|
249
|
+
await storeClient.changeState(s => { Object.assign(s.keys, fresh); }).catch(() => {});
|
|
250
|
+
}
|
|
251
|
+
return rows.map(b => ({
|
|
252
|
+
slug: b.slug, bundle: b.bundle || null, displayName: String(b.displayName || b.slug).slice(0, 80), description: String(b.description || '').slice(0, 300),
|
|
253
|
+
forSale: b.forSale === true, price: b.price, renewal: b.renewal, currency: b.currency, supportMonths: b.supportMonths, renewalPeriodMonths: b.renewalPeriodMonths,
|
|
254
|
+
owned: b.owned === true, supportEnds: b.supportEnds || null, updates: b.updates === true, canRenew: b.canRenew === true, renewFrom: b.renewFrom || null,
|
|
255
|
+
contents: (Array.isArray(b.contents) ? b.contents : []).filter(c => SLUG.test(c?.slug || ''))
|
|
256
|
+
.map(c => ({ slug: c.slug, displayName: String(c.displayName || c.slug).slice(0, 80), owned: c.owned === true, installed: installed.has(c.slug) })),
|
|
257
|
+
pending: pending.find(p => p.slug === b.slug)?.id ?? null
|
|
258
|
+
}));
|
|
226
259
|
}
|
|
227
260
|
|
|
228
261
|
// POST /plugins/marketplace/buy {slug} -> {id, checkoutUrl}
|
|
@@ -233,7 +266,9 @@ export async function pluginMarketplaceRoutes(fastify) {
|
|
|
233
266
|
const user = await getUserById(request.user?.id);
|
|
234
267
|
if (!user?.email) return reply.code(400).send({ error: 'Your account has no email address for the receipt and licence key - add one under My profile.' });
|
|
235
268
|
try {
|
|
236
|
-
const
|
|
269
|
+
const b = request.body || {};
|
|
270
|
+
const out = await storeClient.startPurchase({ site: await siteAddress(request), slug, email: user.email, name: user.name || user.displayName || '',
|
|
271
|
+
country: String(b.country || '').toUpperCase().slice(0, 2), vatNumber: typeof b.vatNumber === 'string' ? b.vatNumber.trim() : '', buyerIp: request.ip || '' });
|
|
237
272
|
return reply.send(out);
|
|
238
273
|
} catch (err) {
|
|
239
274
|
return reply.code(err instanceof storeClient.StoreError ? err.status : 500).send({ error: err instanceof storeClient.StoreError ? err.message : 'The purchase could not be started.' });
|
|
@@ -261,12 +296,16 @@ export async function pluginMarketplaceRoutes(fastify) {
|
|
|
261
296
|
return { code: err instanceof storeClient.StoreError ? err.status : 500, body: { error: err instanceof storeClient.StoreError ? err.message : 'The purchase could not be checked.' } };
|
|
262
297
|
}
|
|
263
298
|
if (out.status !== 'paid') return { body: out };
|
|
264
|
-
|
|
299
|
+
// A bundle is a licence, not a plugin: nothing to install for it - its Tools come in as `included`.
|
|
300
|
+
const bundle = out.slug === BUNDLE_SLUG;
|
|
301
|
+
const main = bundle ? { body: { ...out, bundle: true, installed: true } } : await installClaimed(out);
|
|
265
302
|
// What came free with it (the MongoDB Adapter with Email): installed beside it, the same way.
|
|
266
303
|
const included = [];
|
|
267
304
|
for (const slug of out.included || []) {
|
|
268
305
|
const r = await installClaimed({ ...out, slug, kind: out.kind, included: [] });
|
|
269
|
-
included.push({ slug, installed: r.body.installed === true, installError: r.body.installError || null
|
|
306
|
+
included.push({ slug, installed: r.body.installed === true, installError: r.body.installError || null,
|
|
307
|
+
// Already on this site before (bought singly, or a copy from earlier): its licence now covers it.
|
|
308
|
+
...(bundle && { alreadyHere: r.body.restartRequired !== true && r.body.installed === true }) });
|
|
270
309
|
}
|
|
271
310
|
return { code: main.code, body: { ...main.body, included } };
|
|
272
311
|
}
|
package/server/server.js
CHANGED
|
@@ -802,6 +802,10 @@ await app.register(callPublicRoutes);
|
|
|
802
802
|
// into a Tool switched off with `staff: true`. A ticket only works on a site its Manager started.
|
|
803
803
|
const { staffAccessRoutes } = await import('./services/staffAccess.js');
|
|
804
804
|
await app.register(staffAccessRoutes);
|
|
805
|
+
// The Domma store's check that this self-hosted site is the address it buys for
|
|
806
|
+
// (/.well-known/domma-store/<token>, services/storeClient.js) - before the catch-all.
|
|
807
|
+
const { storeProofRoutes } = await import('./services/storeClient.js');
|
|
808
|
+
await app.register(storeProofRoutes);
|
|
805
809
|
|
|
806
810
|
// The outreach unsubscribe link (/campaign-unsubscribe) - core's, so it outlives the Tool that
|
|
807
811
|
// sent the email. After the plugins: an older Campaigns Pro that registers it itself wins.
|
|
@@ -51,6 +51,9 @@ export function licenceNotice(name, label, verdict, now = new Date()) {
|
|
|
51
51
|
return {severity: 'warning', title: `${label} licence has expired`,
|
|
52
52
|
body: `The ${label} licence ended on ${ends(e.expiresAt)}. It keeps working until ${fmtDate(graceEnd, {utc: true})}, then stops. Renew it before then.`};
|
|
53
53
|
}
|
|
54
|
+
case 'not-covered':
|
|
55
|
+
return {severity: 'critical', title: `${label} is not running: this version needs a renewal`,
|
|
56
|
+
body: `This copy of ${label} is newer than your licence covers (${String(e.versions || '').replace(/^<=/, 'up to ')}), and its updates ended on ${ends(e.supportExpiresAt)}. Renew it in the Marketplace, or install the version your licence covers - its data is kept.`};
|
|
54
57
|
case 'support-ended':
|
|
55
58
|
return {severity: 'info', title: `${label}: support and updates have ended`,
|
|
56
59
|
body: `Your ${label} licence is permanent and keeps working, but updates stopped on ${ends(e.supportExpiresAt)}.`};
|
|
@@ -183,7 +186,7 @@ export async function todoChanged(userId, todos, today) {
|
|
|
183
186
|
|
|
184
187
|
export async function registerCoreSources() {
|
|
185
188
|
const plugins = await import('./plugins.js');
|
|
186
|
-
const {classifyEntitlement} = await import('./pluginEntitlement.js');
|
|
189
|
+
const {classifyEntitlement, coveredVerdict} = await import('./pluginEntitlement.js');
|
|
187
190
|
|
|
188
191
|
registerNotificationSource({
|
|
189
192
|
id: 'core:plugin-load', label: 'Plugin failed to start', severity: 'critical', every: 'boot',
|
|
@@ -227,7 +230,7 @@ export async function registerCoreSources() {
|
|
|
227
230
|
if (m.closedSource !== true) continue;
|
|
228
231
|
const key = `licence:${m.name}`;
|
|
229
232
|
if (!states[m.name]?.enabled) { await resolve(key); continue; }
|
|
230
|
-
const notice = licenceNotice(m.name, m.displayName || m.name, classifyEntitlement(m.name), now);
|
|
233
|
+
const notice = licenceNotice(m.name, m.displayName || m.name, coveredVerdict(classifyEntitlement(m.name), m.version), now);
|
|
231
234
|
if (notice) await raise({...notice, dedupeKey: key, link: '#/plugins'});
|
|
232
235
|
else await resolve(key);
|
|
233
236
|
}
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
import {createPublicKey, verify as cryptoVerify} from 'node:crypto';
|
|
25
25
|
import fs from 'node:fs';
|
|
26
26
|
import path from 'node:path';
|
|
27
|
-
import {trustedKey} from './pluginInstaller.js';
|
|
27
|
+
import {compareVersions, trustedKey} from './pluginInstaller.js';
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Canonical JSON: keys sorted at every depth, no whitespace, undefined dropped.
|
|
@@ -101,6 +101,7 @@ export function readEntitlement(slug) {
|
|
|
101
101
|
* 'valid' load it
|
|
102
102
|
* 'grace' load it, and say so - a rental just past its term
|
|
103
103
|
* 'support-ended' load it - a perpetual licence whose updates have stopped
|
|
104
|
+
* (mayLoad() refuses a version newer than it covers: 'not-covered')
|
|
104
105
|
* 'expired' do NOT load - a rental past its grace period
|
|
105
106
|
* 'unlicensed' do NOT load - absent, malformed, or not signed by us
|
|
106
107
|
*
|
|
@@ -153,6 +154,49 @@ export function classifyEntitlement(slug, entitlement = readEntitlement(slug), n
|
|
|
153
154
|
return {state: 'valid', reason: '', entitlement};
|
|
154
155
|
}
|
|
155
156
|
|
|
157
|
+
/**
|
|
158
|
+
* Does an entitlement's `versions` cover this version? The store mints a bought
|
|
159
|
+
* licence's entitlement as `<=X.Y.Z` - the version that download was - and '*'
|
|
160
|
+
* (or no field) for everything else. Comparisons are joined by spaces
|
|
161
|
+
* (`>=1.0.0 <=1.4.2`); a bare version means exactly that one. Anything else
|
|
162
|
+
* covers nothing: a ceiling read wrongly must never mean "no ceiling".
|
|
163
|
+
*
|
|
164
|
+
* @param {string|undefined} versions
|
|
165
|
+
* @param {string} version
|
|
166
|
+
* @returns {boolean}
|
|
167
|
+
*/
|
|
168
|
+
export function versionsCover(versions, version) {
|
|
169
|
+
const spec = versions === undefined || versions === null ? '*' : String(versions).trim();
|
|
170
|
+
if (spec === '*' || spec === '') return true;
|
|
171
|
+
if (!/^\d+(?:\.\d+)*$/.test(String(version ?? ''))) return false;
|
|
172
|
+
return spec.split(/\s+/).every((part) => {
|
|
173
|
+
const m = /^(<=|>=|<|>|=)?(\d+(?:\.\d+)*)$/.exec(part);
|
|
174
|
+
if (!m) return false;
|
|
175
|
+
const c = compareVersions(version, m[2]);
|
|
176
|
+
switch (m[1]) {
|
|
177
|
+
case '<=': return c <= 0;
|
|
178
|
+
case '>=': return c >= 0;
|
|
179
|
+
case '<': return c < 0;
|
|
180
|
+
case '>': return c > 0;
|
|
181
|
+
default: return c === 0;
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* A perpetual licence whose support has ended covers only the versions it was
|
|
188
|
+
* given: dropping a newer copy in by hand (a .dcmsplugin from elsewhere) must
|
|
189
|
+
* not get round the renewal. While support runs, any version loads - an update
|
|
190
|
+
* from the store brings its own, wider entitlement with it.
|
|
191
|
+
*/
|
|
192
|
+
export function coveredVerdict(verdict, version) {
|
|
193
|
+
if (verdict.state !== 'support-ended' || verdict.entitlement?.model !== 'perpetual') return verdict;
|
|
194
|
+
const versions = verdict.entitlement.versions;
|
|
195
|
+
if (versionsCover(versions, version)) return verdict;
|
|
196
|
+
return {...verdict, state: 'not-covered',
|
|
197
|
+
reason: `version ${version} is newer than this licence covers (${versions}) and its updates have ended`};
|
|
198
|
+
}
|
|
199
|
+
|
|
156
200
|
/** The states that let a plugin load. */
|
|
157
201
|
const LOADABLE = new Set(['valid', 'grace', 'support-ended']);
|
|
158
202
|
|
|
@@ -166,6 +210,6 @@ export function mayLoad(manifest) {
|
|
|
166
210
|
if (manifest?.closedSource !== true) {
|
|
167
211
|
return {allowed: true, state: 'not-required', reason: ''};
|
|
168
212
|
}
|
|
169
|
-
const {state, reason} = classifyEntitlement(manifest.name);
|
|
213
|
+
const {state, reason} = coveredVerdict(classifyEntitlement(manifest.name), manifest.version);
|
|
170
214
|
return {allowed: LOADABLE.has(state), state, reason};
|
|
171
215
|
}
|
|
@@ -132,6 +132,32 @@ export function trustedKeyIds(use) {
|
|
|
132
132
|
* @param {string} b
|
|
133
133
|
* @returns {number}
|
|
134
134
|
*/
|
|
135
|
+
/** The refusal for installing a `hostedOnly` plugin where Domma does not host the site, or null. */
|
|
136
|
+
async function hostedOnlyRefusal(manifest) {
|
|
137
|
+
if (manifest?.hostedOnly !== true) return null;
|
|
138
|
+
const {hostedHere} = await import('./storeClient.js');
|
|
139
|
+
if (hostedHere()) return null;
|
|
140
|
+
return Object.assign(new Error(`${manifest.displayName || manifest.name} runs only on sites Domma hosts, so it cannot be installed here.`),
|
|
141
|
+
{statusCode: 403, code: 'hosted-only', expose: true});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* The refusal for installing a version a bought licence no longer covers, or
|
|
146
|
+
* null. Checked before anything on disk changes, so the working copy stays.
|
|
147
|
+
* The entitlement is the incoming one, else the one the installation carries.
|
|
148
|
+
*/
|
|
149
|
+
async function licenceShortfall(slug, manifest, entitlement) {
|
|
150
|
+
if (manifest?.closedSource !== true || !entitlement) return null;
|
|
151
|
+
const {classifyEntitlement, coveredVerdict} = await import('./pluginEntitlement.js');
|
|
152
|
+
const verdict = coveredVerdict(classifyEntitlement(slug, entitlement), manifest.version);
|
|
153
|
+
if (verdict.state !== 'not-covered') return null;
|
|
154
|
+
const ended = String(entitlement.supportExpiresAt || '').slice(0, 10);
|
|
155
|
+
const name = manifest.displayName || slug;
|
|
156
|
+
return Object.assign(new Error(`${name} ${manifest.version} came out after your updates ended${ended ? ` on ${ended}` : ''}. `
|
|
157
|
+
+ `Your licence covers ${String(entitlement.versions).replace(/^<=/, 'up to ')}. Renew it in the Marketplace to install this version - the one you have keeps working.`),
|
|
158
|
+
{statusCode: 403, code: 'licence-versions', expose: true});
|
|
159
|
+
}
|
|
160
|
+
|
|
135
161
|
export function compareVersions(a, b) {
|
|
136
162
|
const parse = v => String(v ?? '').split('.').map(x => parseInt(x, 10) || 0);
|
|
137
163
|
const av = parse(a);
|
|
@@ -411,6 +437,16 @@ export async function installPlugin(slug, { tarball, signature, publicKeyId, all
|
|
|
411
437
|
await fs.rm(destDir, { recursive: true, force: true });
|
|
412
438
|
throw cmsTooOldError(tooNew);
|
|
413
439
|
}
|
|
440
|
+
const notCovered = await licenceShortfall(slug, manifest, entitlement);
|
|
441
|
+
if (notCovered) {
|
|
442
|
+
await fs.rm(destDir, { recursive: true, force: true });
|
|
443
|
+
throw notCovered;
|
|
444
|
+
}
|
|
445
|
+
const notHosted = await hostedOnlyRefusal(manifest);
|
|
446
|
+
if (notHosted) {
|
|
447
|
+
await fs.rm(destDir, { recursive: true, force: true });
|
|
448
|
+
throw notHosted;
|
|
449
|
+
}
|
|
414
450
|
|
|
415
451
|
// Step 5 - Update config/plugins.json
|
|
416
452
|
const cfg = await readPluginsConfig();
|
|
@@ -498,6 +534,20 @@ async function upgradePlugin(slug, {tarball, unsigned, entitlement, allowDowngra
|
|
|
498
534
|
await fs.rm(incoming, {recursive: true, force: true});
|
|
499
535
|
throw new Error(`Refusing to downgrade ${slug} from ${from} to ${to}.`);
|
|
500
536
|
}
|
|
537
|
+
let heldEntitlement = entitlement;
|
|
538
|
+
if (!heldEntitlement) {
|
|
539
|
+
try { heldEntitlement = JSON.parse(await fs.readFile(path.join(destDir, '.entitlement.json'), 'utf8')); } catch { /* none */ }
|
|
540
|
+
}
|
|
541
|
+
const notCovered = await licenceShortfall(slug, next.manifest, heldEntitlement);
|
|
542
|
+
if (notCovered) {
|
|
543
|
+
await fs.rm(incoming, {recursive: true, force: true});
|
|
544
|
+
throw notCovered;
|
|
545
|
+
}
|
|
546
|
+
const notHosted = await hostedOnlyRefusal(next.manifest);
|
|
547
|
+
if (notHosted) {
|
|
548
|
+
await fs.rm(incoming, {recursive: true, force: true});
|
|
549
|
+
throw notHosted;
|
|
550
|
+
}
|
|
501
551
|
|
|
502
552
|
// 3. Carry the site's data across.
|
|
503
553
|
const dataDir = path.join(destDir, 'data');
|
|
@@ -466,7 +466,16 @@ export async function registerPlugins(fastify) {
|
|
|
466
466
|
// email-pro still counted as active it would displace mail-reader and then
|
|
467
467
|
// fail to load itself, leaving a customer whose licence lapsed with NEITHER -
|
|
468
468
|
// worse off than someone who never paid at all.
|
|
469
|
+
// A plugin whose manifest says `hostedOnly: true` (Site Builder, Tool Builder) runs only where Domma
|
|
470
|
+
// hosts the site - a managed site, or the manager itself. Elsewhere it does not load, whatever it carries.
|
|
471
|
+
const {hostedHere} = await import('./storeClient.js');
|
|
472
|
+
const hosted = hostedHere();
|
|
469
473
|
for (const manifest of manifests) {
|
|
474
|
+
if (manifest.hostedOnly === true && !hosted) {
|
|
475
|
+
_entitlementStates[manifest.name] = 'hosted-only';
|
|
476
|
+
fastify.log.warn(`[plugins] "${manifest.name}" not loaded: it runs only on sites Domma hosts`);
|
|
477
|
+
continue;
|
|
478
|
+
}
|
|
470
479
|
if (manifest.closedSource !== true) continue;
|
|
471
480
|
const verdict = mayLoad(manifest);
|
|
472
481
|
_entitlementStates[manifest.name] = verdict.state;
|
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
/** Parameter names redacted whatever their case. */
|
|
15
15
|
// `code` and `state`: an OAuth2 callback (the mail sign-in) carries a live
|
|
16
16
|
// authorisation code and its one-time ticket in the query string.
|
|
17
|
-
|
|
17
|
+
// `hub.verify_token`: a Meta (WhatsApp, Facebook) webhook subscription check sends
|
|
18
|
+
// the site's verify token in the query string (?hub.mode=subscribe&hub.verify_token=...).
|
|
19
|
+
const SENSITIVE = new Set(['token', 't', 'key', 'hostkey', 'invitekey', 'code', 'state', 'hub.verify_token']);
|
|
18
20
|
|
|
19
21
|
/** Anything with secret or password in the name is redacted too. */
|
|
20
22
|
const SENSITIVE_PATTERN = /secret|password|passwd/i;
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
*
|
|
30
30
|
* @module server/services/storeClient
|
|
31
31
|
*/
|
|
32
|
+
import {randomBytes} from 'node:crypto';
|
|
32
33
|
import fs from 'node:fs';
|
|
33
34
|
import path from 'node:path';
|
|
34
35
|
import {getConfig} from '../config.js';
|
|
@@ -74,6 +75,11 @@ export function isOwnerInstance() {
|
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
|
|
78
|
+
/** Does Domma host this site - a managed site, or the manager itself? (`hostedOnly` plugins run only here.) */
|
|
79
|
+
export function hostedHere() {
|
|
80
|
+
return isManaged() || isOwnerInstance();
|
|
81
|
+
}
|
|
82
|
+
|
|
77
83
|
/** Was a store named on purpose (server.json `storeUrl` or `DOMMA_STORE_URL`), rather than the default? */
|
|
78
84
|
export function storeNamed() {
|
|
79
85
|
if (process.env.DOMMA_STORE_URL) return true;
|
|
@@ -153,6 +159,53 @@ export function pendingPurchases(now = Date.now()) {
|
|
|
153
159
|
// Talking to the store
|
|
154
160
|
// ---------------------------------------------------------------------------
|
|
155
161
|
|
|
162
|
+
// ---------------------------------------------------------------------------
|
|
163
|
+
// Proving this site is the address it buys for
|
|
164
|
+
// ---------------------------------------------------------------------------
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* A licence is for one site address, and the store checks the asker really is
|
|
168
|
+
* that site: each checkout, claim and paid download carries a fresh proof token,
|
|
169
|
+
* and the store fetches https://<site>/.well-known/domma-store/<token> back. Only
|
|
170
|
+
* the server answering at that address knows the token, so a key bought for an
|
|
171
|
+
* address nobody controls (or copied to another site) cannot be used.
|
|
172
|
+
*/
|
|
173
|
+
const PROOF_MS = 10 * 60_000;
|
|
174
|
+
export const PROOF_FORMAT = /^[A-Za-z0-9_-]{32,64}$/;
|
|
175
|
+
const proofs = new Map();
|
|
176
|
+
|
|
177
|
+
function purgeProofs(now) {
|
|
178
|
+
for (const [token, until] of proofs) if (until <= now) proofs.delete(token);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** A new proof token, live for ten minutes. */
|
|
182
|
+
export function newProof(now = Date.now()) {
|
|
183
|
+
purgeProofs(now);
|
|
184
|
+
const token = randomBytes(24).toString('base64url');
|
|
185
|
+
proofs.set(token, now + PROOF_MS);
|
|
186
|
+
return token;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Is this a proof token this site handed out, still live? */
|
|
190
|
+
export function proofLive(token, now = Date.now()) {
|
|
191
|
+
if (typeof token !== 'string' || !PROOF_FORMAT.test(token)) return false;
|
|
192
|
+
purgeProofs(now);
|
|
193
|
+
return proofs.has(token);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** Test-only: forget every proof. */
|
|
197
|
+
export function _resetProofs() { proofs.clear(); }
|
|
198
|
+
|
|
199
|
+
/** GET /.well-known/domma-store/:token - the store's check that this site is the address it says. No auth. */
|
|
200
|
+
export async function storeProofRoutes(fastify) {
|
|
201
|
+
fastify.get('/.well-known/domma-store/:token', {config: {rateLimit: {max: 60, timeWindow: '1 minute'}}}, async (request, reply) => {
|
|
202
|
+
reply.header('Cache-Control', 'no-store').header('X-Robots-Tag', 'noindex');
|
|
203
|
+
const token = String(request.params?.token || '');
|
|
204
|
+
if (!storeOpen() || !proofLive(token)) return reply.code(404).type('text/plain; charset=utf-8').send('Not found');
|
|
205
|
+
return reply.type('text/plain; charset=utf-8').send(token);
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
|
|
156
209
|
/** A refusal from the store, carried to the admin as its own words. */
|
|
157
210
|
export class StoreError extends Error {
|
|
158
211
|
constructor(message, status = 502, code = null) {
|
|
@@ -197,9 +250,14 @@ export function fetchStoreCatalogue(site, keys) {
|
|
|
197
250
|
*
|
|
198
251
|
* @returns {Promise<{id: string, checkoutUrl: string, kind: string, price: number, currency: string}>}
|
|
199
252
|
*/
|
|
200
|
-
export async function startPurchase({site, slug, email, name}) {
|
|
253
|
+
export async function startPurchase({site, slug, email, name, country = '', vatNumber = '', buyerIp = ''}) {
|
|
201
254
|
const key = readState().keys[slug] || heldKeys([slug])[slug] || '';
|
|
202
|
-
|
|
255
|
+
// EU VAT (when the store asks for it, catalogue `vat`): the buyer's country, an optional EU VAT number, and the
|
|
256
|
+
// address they bought from - the store keeps them as the evidence the tax return needs.
|
|
257
|
+
const vat = {...(/^[A-Z]{2}$/.test(country) && {country}), ...(vatNumber && {vatNumber: String(vatNumber).slice(0, 40)}),
|
|
258
|
+
// The buyer's address goes only with a VAT declaration: while the store asks nothing, it learns nothing new.
|
|
259
|
+
...(buyerIp && /^[A-Z]{2}$/.test(country) && {buyerIp: String(buyerIp).slice(0, 45)})};
|
|
260
|
+
const out = await call('/checkout', {site, slug, email, name, ...(key && {key}), ...vat, proof: newProof()});
|
|
203
261
|
if (typeof out.id !== 'string' || typeof out.claim !== 'string' || typeof out.checkoutUrl !== 'string' || !/^https:\/\//i.test(out.checkoutUrl)) {
|
|
204
262
|
throw new StoreError('The store gave an answer this site does not understand.', 502);
|
|
205
263
|
}
|
|
@@ -208,7 +266,8 @@ export async function startPurchase({site, slug, email, name}) {
|
|
|
208
266
|
// (the store refunds a second payment for a site that already has it, and hands either claim the key).
|
|
209
267
|
s.pending.push({id: out.id, claim: out.claim, slug, kind: out.kind, startedAt: new Date().toISOString()});
|
|
210
268
|
});
|
|
211
|
-
return {id: out.id, checkoutUrl: out.checkoutUrl, kind: out.kind, price: out.price, currency: out.currency
|
|
269
|
+
return {id: out.id, checkoutUrl: out.checkoutUrl, kind: out.kind, price: out.price, currency: out.currency,
|
|
270
|
+
...(out.vat && typeof out.vat === 'object' && {vat: out.vat}), ...(typeof out.vatNote === 'string' && {vatNote: out.vatNote.slice(0, 300)})};
|
|
212
271
|
}
|
|
213
272
|
|
|
214
273
|
/**
|
|
@@ -220,7 +279,7 @@ export async function startPurchase({site, slug, email, name}) {
|
|
|
220
279
|
export async function claimPurchase(id) {
|
|
221
280
|
const p = readState().pending.find((x) => x.id === id);
|
|
222
281
|
if (!p) return {status: 'unknown'};
|
|
223
|
-
const out = await call('/claim', {id: p.id, claim: p.claim});
|
|
282
|
+
const out = await call('/claim', {id: p.id, claim: p.claim, proof: newProof()});
|
|
224
283
|
if (out.status === 'paid' && typeof out.licenceKey === 'string') {
|
|
225
284
|
await changeState((s) => {
|
|
226
285
|
s.keys[p.slug] = out.licenceKey;
|
|
@@ -314,7 +373,8 @@ export async function downloadPlugin(slug) {
|
|
|
314
373
|
const base = storeUrl();
|
|
315
374
|
if (!base) throw new StoreError('The store is switched off on this site.', 503);
|
|
316
375
|
const key = heldKeys([slug])[slug] || '';
|
|
317
|
-
|
|
376
|
+
// A paid download carries a proof: the store checks this site is the address the licence is for.
|
|
377
|
+
const url = `${base.replace(/\/store$/, '')}/plugins/${encodeURIComponent(slug)}/download${key ? `?licence=${encodeURIComponent(key)}&proof=${newProof()}` : ''}`;
|
|
318
378
|
let res;
|
|
319
379
|
try {
|
|
320
380
|
res = await fetch(url, {signal: AbortSignal.timeout(60_000)});
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
<link rel="stylesheet" href="/dist/domma/themes/domma-themes.css">
|
|
26
26
|
|
|
27
27
|
<!-- Site CSS -->
|
|
28
|
-
<link rel="stylesheet" href="/public/css/site.css?v=
|
|
28
|
+
<link rel="stylesheet" href="/public/css/site.css?v=20261108-hero-outline">
|
|
29
29
|
<link rel="stylesheet" href="/public/css/forms.css?v=20261031-forms-reduce-motion">
|
|
30
30
|
<!-- Menu item hover / current-page effects. Loaded after site.css so a
|
|
31
31
|
menu's own highlight wins over the blanket link styling there. -->
|
|
@@ -183,7 +183,7 @@
|
|
|
183
183
|
searchable / filterable / sortable / paginate attributes) -->
|
|
184
184
|
<!-- Its range-filter arithmetic; a module that runs first and sets window.DommaCollectionRange -->
|
|
185
185
|
<script src="/public/js/collection-range.mjs?v=20261025-range-slider" type="module"></script>
|
|
186
|
-
<script src="/public/js/collection-browser.js?v=
|
|
186
|
+
<script src="/public/js/collection-browser.js?v=20261108-hero-outline" defer></script>
|
|
187
187
|
<!-- Core Forms logic engine (must run before forms.js and site.js) -->
|
|
188
188
|
<script src="/public/js/form-logic-engine.js?v=20261031-forms-reduce-motion" defer></script>
|
|
189
189
|
|