import * as fs from 'fs'; import * as path from 'path'; import Draft07Schema from '../../v1/Draft-07.json'; import UserApiManifestV1 from './UserApiManifestV1.json'; import { JSONSchemaService } from '../../../JsonSchemaService'; import { TypeResolverBuilder } from '../../../jsonTypeResolution/TypeResolverBuilder'; const pkgVersion = ((): string | undefined => { try { const pkgPath = path.join(__dirname, '..', '..', '..', '..', 'package.json'); const raw = fs.readFileSync(pkgPath, 'utf8'); return (JSON.parse(raw) as { version?: string }).version; } catch { return undefined; } })(); const draft07Remotes = { 'http://json-schema.org/draft-07/schema': Draft07Schema, 'http://json-schema.org/draft-07/schema#': Draft07Schema, } as const; const fullManifestMetaSchema = { root: UserApiManifestV1, remotes: draft07Remotes, } as const; const resolver = TypeResolverBuilder.new().build(); const fullManifestValidator = new JSONSchemaService(resolver, fullManifestMetaSchema); /** * Recommended `$schema` URL for the top-level DXP User API `manifest.json`. * * Published at {@link USER_API_FULL_MANIFEST_SCHEMA} under `lib/manifest/userApiManifest/UserApiManifestV1.json`. */ export const USER_API_MANIFEST_SCHEMA_URL = typeof pkgVersion === 'string' ? `https://unpkg.com/@squiz/dx-json-schema-lib@${pkgVersion}/lib/manifest/userApiManifest/UserApiManifestV1.json` : 'https://unpkg.com/@squiz/dx-json-schema-lib@latest/lib/manifest/userApiManifest/UserApiManifestV1.json'; /** * JSON Schema bundle validating the full on-disk manifest (CLI / zip upload). */ export { default as USER_API_FULL_MANIFEST_SCHEMA } from './UserApiManifestV1.json'; /** * Validate the User API manifest before upload. * * @throws {SchemaValidationError} when validation fails. */ export function validateUserApiFullManifest(input: unknown): true { return fullManifestValidator.validateInput(input); }