import { DID_KEY_ASSOCIATOR_OAUTH_SCOPE, OAUTH_SCOPE_LOCALHOST } from "@publicdomainrelay/oauth-scope"; export const GENERATED_OAUTH_SCOPE_PATH = "generated/oauth-scope.js"; export function renderOauthScopeModule( full: readonly string[] = DID_KEY_ASSOCIATOR_OAUTH_SCOPE, localhost: string = OAUTH_SCOPE_LOCALHOST, ): string { return [ "// AUTO-GENERATED by build.ts from @publicdomainrelay/oauth-scope \u2014 DO NOT EDIT.", "// Single source: typescript-helpers/lib/oauth-scope/mod.ts. Regenerated on every build.", `export const OAUTH_SCOPE_FULL = ${JSON.stringify(full.join(" "))};`, `export const OAUTH_SCOPE_LOCALHOST = ${JSON.stringify(localhost)};`, "", ].join("\n"); } export interface OauthScopeDrift { missing: string[]; extra: string[]; } export function parseOauthScopeFull(moduleText: string): string[] { const m = /export const OAUTH_SCOPE_FULL = ("(?:[^"\\]|\\.)*");/.exec(moduleText); if (!m) return []; return (JSON.parse(m[1]) as string).split(" ").filter(Boolean); } export function oauthScopeDrift( moduleText: string, full: readonly string[] = DID_KEY_ASSOCIATOR_OAUTH_SCOPE, ): OauthScopeDrift { const have = new Set(parseOauthScopeFull(moduleText)); const want = new Set(full); return { missing: [...want].filter((t) => !have.has(t)), extra: [...have].filter((t) => !want.has(t)), }; }