Open History to see the last commit
1// Re-derive a provider's schema content hashes from its upstream spec —
2// no service, no database: the exact fetchSpec → classify → bundle → hash
3// pipeline the sync engine runs (shared via `classifyAndBundle`), executed
4// locally. Compare the printed `contentHash` values against what
5// `GET /v1/schemas/{provider}/{activity}/{endpointId}` reports to verify
6// the service's stored schemas are honestly derived from their sources.
7//
8// bun scripts/rederive.ts <provider>
9//
10// Bun auto-loads `.env.local`, so keyed providers (FAL) pick up their
11// secret; the upstream spec may also have moved since the service last
12// synced — `provenance.sourceHash` tells you which document a stored
13// version came from.
14import { EXTRACTOR_VERSION } from '../src/server/ingest/bundle.ts'
15import { classifyAndBundle } from '../src/server/ingest/sync.ts'
16import { contentHash } from '../src/server/kv.ts'
17import { getProvider, providerRegistry } from '../src/server/providers/index.ts'
18
19const providerId = process.argv[2]
20const provider = providerId ? getProvider(providerId) : undefined
21if (!provider) {
22 console.error(
23 `usage: bun scripts/rederive.ts <provider>\n` +
24 `providers: ${providerRegistry.map((p) => p.id).join(', ')}`,
25 )
26 process.exit(1)
27}
28
29const fetched = await provider.fetchSpec(process.env)
30if (fetched.skipped) {
31 console.error(`skipped: ${fetched.skipped}`)
32 process.exit(1)
33}
34
35const { endpoints, warnings } = classifyAndBundle(provider, fetched)
36const rows: Array<{
37 endpointId: string
38 activity: string
39 kind: 'input' | 'output'
40 contentHash: string
41 sourceUrl: string | null
42 sourceHash: string | null
43}> = []
44for (const endpoint of endpoints) {
45 const endpointId = endpoint.dbId.slice(provider.id.length + 1)
46 for (const [kind, schema] of [
47 ['input', endpoint.input],
48 ['output', endpoint.output],
49 ] as const) {
50 if (!schema) continue
51 rows.push({
52 endpointId,
53 activity: endpoint.activity,
54 kind,
55 contentHash: await contentHash(schema),
56 sourceUrl: endpoint.source?.url ?? null,
57 sourceHash: endpoint.source?.hash ?? null,
58 })
59 }
60}
61
62console.log(
63 JSON.stringify(
64 {
65 provider: provider.id,
66 extractorVersion: EXTRACTOR_VERSION,
67 specRevision: fetched.specRevision ?? null,
68 schemas: rows,
69 warnings,
70 },
71 null,
72 2,
73 ),
74)