@schemacompany/core
v0.1.1
Published
Core utilities for The Schema Company SDKs
Readme
@schemacompany/core
Core utilities for The Schema Company SDKs. This package provides the base client, types, and error handling used by all other SDK packages.
Installation
npm install @schemacompany/coreUsage
import { SchemaClient } from "@schemacompany/core";
const client = new SchemaClient();
// Fetch a schema by hash
const schema = await client.fetchSchema("a1b2c3d4...");
console.log(schema);
// { "@context": "https://schema.org", "@type": "WebPage", ... }
// Fetch as raw JSON string
const raw = await client.fetchSchemaRaw("a1b2c3d4...");
console.log(raw);
// '{"@context":"https://schema.org",...}'
// Validate a hash format
const isValid = client.validateHash("a1b2c3d4...");API
SchemaClient
class SchemaClient {
constructor(config?: SchemaCompanyConfig);
fetchSchema(hash: string): Promise<Schema>;
fetchSchemaRaw(hash: string): Promise<string>;
validateHash(hash: string): boolean;
}SchemaCompanyConfig
interface SchemaCompanyConfig {
baseUrl?: string; // Default: https://assets.theschemacompany.com
timeout?: number; // Default: 5000ms
}Error Classes
SchemaCompanyError- Base error classSchemaNotFoundError- Thrown when schema hash is not found (404)SchemaFetchError- Thrown on network or parse errorsInvalidHashError- Thrown when hash format is invalid
Constants
import { DEFAULT_BASE_URL, HASH_REGEX } from "@schemacompany/core";
// DEFAULT_BASE_URL: "https://assets.theschemacompany.com"
// HASH_REGEX: /^[a-f0-9]{64}$/iLicense
MIT
