Hub 2.21.0: install the Church Website; Website storage bought in steps

- New install offers the Church Website: Accounts first when the church has
  none, at accounts.<its address> (www. dropped); the FastPanel email sends a
  www. site's bare domain to www. with a 301.
- Licence.extraStorageSteps (migration): the token sends a Website its limit
  (5 GB + steps, limits.storageBytes, contracts 1.17.0); invoices bill the
  steps bought instead of the storage reported. Edit popup field 0-99.
- A Website/App licence starts on its plan however it's made (New install too).
- Vendored @crosscode/contracts 1.17.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 00:03:21 +02:00
co-authored by Claude Opus 5.5
parent 6f8242064f
commit c6f734ab20
21 changed files with 235 additions and 36 deletions
+59 -2
View File
@@ -8,7 +8,7 @@ jest.mock('../src/utils/mail', () => ({ sendMail: jest.fn(async m => { mockMails
process.env.HUB_ENCRYPTION_KEY = 'test-encryption-key-test-encryption-key';
process.env.FRONTEND_URL = 'https://hub.test';
const { agent } = require('@crosscode/contracts');
const { agent, hub } = require('@crosscode/contracts');
const signing = require('@crosscode/contracts/signing');
const db = require('../src/config/db');
const servers = require('../src/utils/servers');
@@ -473,7 +473,7 @@ describe('Accounts from the Hub (2.3.0)', () => {
await jobs.newInstall({ customerId: 'cust-1', serverId: server.id, shortName: 'hope', domain: 'events.hope.co.za' }, admin, NOW);
await expect(jobs.newInstall({ product: 'accounts', customerId: 'cust-1', serverId: server.id, shortName: 'hope', domain: 'accounts.hope.co.za' }, admin, NOW)).rejects.toMatchObject({ code: 'BUSY' });
await expect(jobs.newInstall({ product: 'accounts', customerId: 'cust-1', serverId: other.id, shortName: 'hope', domain: 'accounts.hope.co.za' }, admin, NOW)).rejects.toMatchObject({ code: 'OTHER_SERVER' });
await expect(jobs.newInstall({ product: 'website', customerId: 'cust-1', serverId: server.id, shortName: 'hope', domain: 'www.hope.co.za' }, admin, NOW)).rejects.toMatchObject({ code: 'BAD_REQUEST' });
await expect(jobs.newInstall({ product: 'app', customerId: 'cust-1', serverId: server.id, shortName: 'hope', domain: 'app.hope.co.za' }, admin, NOW)).rejects.toMatchObject({ code: 'BAD_REQUEST' });
});
});
@@ -539,6 +539,63 @@ describe('Cross Events 3.0 brings its Accounts (2.5.0)', () => {
});
});
describe('the Church Website from the Hub (2.21.0)', () => {
const poll = (server) => jobs.poll(server, { agentApiVersion: 1, agentVersion: '1.1.0', mode: 'church', runningJobId: null }, NOW);
beforeEach(async () => {
await db.release.create({ data: { id: 'rw1', product: 'website', version: '1.0.0', notes: '- First release', requires: [{ product: 'accounts', version: '1.7.0' }], releasedAt: NOW } });
await db.release.create({ data: { id: 'ra7', product: 'accounts', version: '1.7.0', notes: '- Brand style', releasedAt: NOW } });
});
test('a new church: Accounts first at accounts.<its domain>, then the Website on www., with a CCW- licence on the Website plan', async () => {
const { server } = await joinServer();
await servers.setServerConfig(server.id, { TRUST_PROXY: 'loopback' });
const out = await jobs.newInstall({ product: 'website', customerId: 'cust-1', serverId: server.id, shortName: 'grace', domain: 'www.grace.co.za' }, admin, NOW);
expect(out.alsoInstalling).toEqual({ product: 'accounts', domain: 'accounts.grace.co.za', version: '1.7.0' });
const [first] = (await poll(server)).jobs;
expect(first).toMatchObject({ type: 'install', args: { products: ['accounts'] } });
await jobs.receiveReport(server, signedReport(first, 'succeeded', { result: { versions: { accounts: 'accounts@1.7.0' } } }), NOW);
const [second] = (await poll(server)).jobs;
expect(second).toMatchObject({ type: 'add-product', args: { church: 'grace', product: 'website', version: 'website@1.0.0', domain: 'www.grace.co.za' } });
expect(agent.agentJobSchema.safeParse(second).success).toBe(true);
const key = signing.openConfig(second.config, keys.x.privateKeyPem).install.website.HUB_LICENCE_KEY;
expect(key).toMatch(/^CCW-/);
expect(await db.licence.findFirst({ where: { key } })).toMatchObject({ product: 'website', plan: 'Website' });
});
test('on a Cross Code address, Accounts goes in front of it', async () => {
const { server } = await joinServer();
await servers.setServerConfig(server.id, { TRUST_PROXY: 'loopback' });
const out = await jobs.newInstall({ product: 'website', customerId: 'cust-1', serverId: server.id, shortName: 'hope', domain: 'hope.crosscode.co.za' }, admin, NOW);
expect(out.alsoInstalling.domain).toBe('accounts.hope.crosscode.co.za');
});
test("the FastPanel steps send the bare domain to www. with a 301; a Cross Code address has no such step", async () => {
const own = await jobs.fastPanelText({ id: 'd1', product: 'website', shortName: 'grace', domain: 'www.grace.co.za', webPort: 20010, apiPort: 20011, customer: { name: 'Grace' } });
expect(own).toContain('Add grace.co.za as an alias');
expect(own).toContain('return 301 https://www.grace.co.za$request_uri;');
expect(own).toContain('DNS: www.grace.co.za and grace.co.za');
expect(own).toContain('location ^~ /api/ {');
const crosscode = await jobs.fastPanelText({ id: 'd2', product: 'website', shortName: 'hope', domain: 'hope.crosscode.co.za', webPort: 20012, apiPort: 20013, customer: { name: 'Hope' } });
expect(crosscode).not.toContain('301');
const events = await jobs.fastPanelText({ id: 'd3', product: 'events', shortName: 'hope', domain: 'www.hope.co.za', webPort: 20014, apiPort: 20015, customer: { name: 'Hope' } });
expect(events).not.toContain('301');
});
});
describe("a Website licence carries its storage limit (2.21.0)", () => {
const GB = 1024 ** 3;
const licenceToken = require('../src/utils/licenceToken');
const base = { id: '0b6f2c1e-8a3d-4f5b-9c7e-1d2e3f4a5b6c', customerId: '1c7a3d2f-9b4e-4a6c-8d8f-2e3f4a5b6c7d', plan: 'Website', status: 'active', expiresAt: null, graceDays: 14 };
test('5 GB plus the steps bought, valid for contracts 1.17.0; other products have none', () => {
const p = licenceToken.buildPayload({ ...base, product: 'website', extraStorageSteps: 2 }, { id: '2d8b4e3a-0c5f-4b7d-9e9a-3f4a5b6c7d8e' }, 'Grace', NOW);
expect(p.limits.storageBytes).toBe(15 * GB);
expect(hub.licencePayloadSchema.safeParse(p).success).toBe(true);
expect(licenceToken.buildPayload({ ...base, product: 'website' }, { id: '2d8b4e3a-0c5f-4b7d-9e9a-3f4a5b6c7d8e' }, 'Grace', NOW).limits.storageBytes).toBe(5 * GB);
expect(licenceToken.buildPayload({ ...base, product: 'events', plan: 'Seed', extraStorageSteps: 3 }, { id: '2d8b4e3a-0c5f-4b7d-9e9a-3f4a5b6c7d8e' }, 'Grace', NOW).limits).not.toHaveProperty('storageBytes');
});
});
describe('settings for servers (found in the VM test)', () => {
test('install defaults, the port range and the central IP are saved', async () => {