- Hub client: register and heartbeat on protocol v2 with the site's Ed25519 key (sent on the heartbeat until the Hub has it); falls back to v1 for a day if the Hub refuses v2, so the licence always refreshes. - crosscode.link/1 Connect / Disconnect, both directions, trusted through the Hub's cached linkedProducts (ProductLink, LinkNonce). - GET /api/feed/v1/events from FeedEntry (go-live, closing and selling out are changes; deactivated events go in deleted), event.changed to connected products, and showing their events (ImportedEvent). - /api/v2/linked-products, /api/v2/linked-events; /events/:id/full gains crosscodeEvent and priceRangeCents for the JSON-LD. - Contracts: FEED_PATHS, typesVersions for @crosscode/contracts/signing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
45 lines
1.9 KiB
TypeScript
45 lines
1.9 KiB
TypeScript
/**
|
|
* What every part of the feed and of Linked products needs to know about this site: its Hub id,
|
|
* its address, its timezone and whether campuses and publishing are on.
|
|
*/
|
|
import type { FeedContext } from './build';
|
|
|
|
/* eslint-disable @typescript-eslint/no-require-imports -- CommonJS */
|
|
const prisma = require('../config/db');
|
|
const { getSetting } = require('../utils/settingsCache') as { getSetting(key: string, fallback?: string): Promise<string> };
|
|
const { campusesEnabled } = require('../utils/campuses') as { campusesEnabled(): Promise<boolean> };
|
|
/* eslint-enable @typescript-eslint/no-require-imports */
|
|
|
|
/** Setting: "Publish my events" (on unless set to "false"). */
|
|
export const PUBLISH_KEY = 'feed_publish';
|
|
|
|
export async function publishOn(): Promise<boolean> {
|
|
return String(await getSetting(PUBLISH_KEY, 'true')).toLowerCase() !== 'false';
|
|
}
|
|
|
|
/** The site's address, as it tells the Hub (hub/report.js installInfo). */
|
|
export async function siteUrl(): Promise<string> {
|
|
const url = await getSetting('app_base_url', process.env.FRONTEND_URL || '');
|
|
return String(url || process.env.FRONTEND_URL || '').split(',')[0]!.trim().replace(/\/+$/, '');
|
|
}
|
|
|
|
export async function hubInstallId(): Promise<string | null> {
|
|
const row = await prisma.appSetting.findUnique({ where: { key: 'hub_install_id' } });
|
|
return row?.value || null;
|
|
}
|
|
|
|
/** Placeholder id for a site not connected to the Hub (its JSON-LD still works; it has no feed). */
|
|
export const NO_INSTALL_ID = '00000000-0000-4000-8000-000000000000';
|
|
|
|
export async function feedContext(now = new Date()): Promise<FeedContext & { connected: boolean }> {
|
|
const [installId, baseUrl, campusesOn] = await Promise.all([hubInstallId(), siteUrl(), campusesEnabled().catch(() => false)]);
|
|
return {
|
|
installId: installId || NO_INSTALL_ID,
|
|
connected: !!installId,
|
|
baseUrl,
|
|
timezone: process.env.APP_TIMEZONE || 'Africa/Johannesburg',
|
|
campusesOn,
|
|
now,
|
|
};
|
|
}
|