Something went wrong. Try again.
Stable episode delivery and analytics on pod.place
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970import { RegistryApi } from "../api";import { createApplication } from "../app";import { PlatformAuth } from "../auth";import { RecordNotFound } from "../errors";import { SqliteStore } from "../store";import { resolverId, resolverUrl } from "../validation";import type { AnalyticsEvent, EpisodeRecord, RecordEnvelope, RecordReader, ShowRecord } from "../types";
export const DID = "did:plc:djyfh7w2dpxt7w7cpagfeyie";export const SHOW_URI = `at://${DID}/place.pod.show/self`;export const EPISODE_URI = `at://${DID}/place.pod.episode/episode1`;export const CID1 = "bafyreiganpcunm7x2n3e7orysnwswxda5jyqdllforhnaumqvtymhh7boi";export const CID2 = "bafyreidc6sydkkbchcyg62v77wbhzvb2mvytlmsychqgwf2xojjtirmzj4";export const TOKEN = "maincasts-test-credential-" + "a".repeat(32);export const NEW_HOST_TOKEN = "new-host-test-credential-" + "b".repeat(32);export const NOW = Date.UTC(2026, 0, 1);export const BASE_URL = "https://pod.place";
export function showRecord(): ShowRecord { return { $type: "place.pod.show", title: "Test show", description: "Test description", createdAt: new Date(NOW).toISOString(), feedUrl: "https://example.com/rss", website: "https://example.com", language: "en", categories: ["Technology"], explicit: false, coverImageUrl: "https://example.com/cover.jpg" };}export function episodeRecord(): EpisodeRecord { const guid = "episode-42-open-standards"; const url = resolverUrl(BASE_URL, resolverId(SHOW_URI, guid)); return { $type: "place.pod.episode", showUri: SHOW_URI, title: "Test episode", guid, createdAt: new Date(NOW).toISOString(), audioUrl: url, audioMimeType: "audio/mpeg", audioSizeBytes: 1234, media: { url, type: "audio/mpeg", length: 1234, primary: { url: "https://cdn.example.com/final-v1.mp3", type: "audio/mpeg", length: 1234 } } };}export function fixture() { const store = new SqliteStore(":memory:"); const records = new Map<string, RecordEnvelope>([ [SHOW_URI, { uri: SHOW_URI, cid: CID1, value: showRecord() }], [EPISODE_URI, { uri: EPISODE_URI, cid: CID1, value: episodeRecord() }], ]); let time = NOW; let reads = 0; const reader: RecordReader = { async get(uri) { reads++; const record = records.get(uri); if (!record) throw new RecordNotFound(); return structuredClone(record); } }; const policy = { baseUrl: BASE_URL, lookupHost: async () => ["8.8.8.8"] }; const auth = new PlatformAuth([ { platform: "maincasts.com", token: TOKEN }, { platform: "another-host.example", token: NEW_HOST_TOKEN }, ]); const api = new RegistryApi(store, reader, auth, policy, () => time); const events: AnalyticsEvent[] = []; const app = createApplication(api, { store, originPolicy: policy, maxAgeMs: 21_600_000, now: () => time, analyticsSecret: "secret".repeat(8), analytics: { async record(event) { events.push(event); } } }); function request(path: string, method = "GET", body?: unknown, token = TOKEN) { return app(new Request(BASE_URL + path, { method, headers: { authorization: `Bearer ${token}`, "content-type": "application/json" }, ...(body !== undefined && { body: JSON.stringify(body) }), }), "8.8.4.4"); } async function register() { return request("/v1/resolvers", "POST", { episodeUri: EPISODE_URI, expectedCid: CID1 }); } return { store, records, reader, policy, api, app, events, request, register, id: resolverId(SHOW_URI, episodeRecord().guid), reads: () => reads, setTime: (value: number) => { time = value; } };}