diff --git a/src/wrapper.ts b/src/wrapper.ts index 7acbf73..6726174 100644 --- a/src/wrapper.ts +++ b/src/wrapper.ts @@ -6,17 +6,30 @@ import { ConsoleLogger, Logger } from "./logger"; import { EventBuffer } from "./events"; import { offlineFetcher, provideFetcher } from "./core/fetcher/custom"; +/** + * Configuration options for the SchematicClient + */ export interface SchematicOptions { + /** API key for authentication */ apiKey?: string; + /** Custom base URL for API endpoints */ basePath?: string; + /** Cache provider configuration */ cacheProviders?: { + /** Providers for caching flag check results */ flagChecks?: CacheProvider[]; }; + /** If using an API key that is not environment-specific, use this option to specify the environment */ environmentId?: string; + /** Interval in milliseconds for flushing event buffer */ eventBufferInterval?: number; + /** Default values for feature flags */ flagDefaults?: { [key: string]: boolean }; + /** Additional HTTP headers for API requests */ headers?: Record; + /** Custom logger implementation */ logger?: Logger; + /** Enable offline mode to prevent network activity */ offline?: boolean; } @@ -27,6 +40,10 @@ export class SchematicClient extends BaseClient { private logger: Logger; private offline: boolean; + /** + * Creates a new instance of the SchematicClient + * @param opts - Configuration options for the client + */ constructor(opts?: SchematicOptions) { const { apiKey = "", @@ -74,6 +91,13 @@ export class SchematicClient extends BaseClient { this.offline = offline; } + /** + * Checks the value of a feature flag for the given evaluation context + * @param evalCtx - The context (company and/or user) for evaluating the feature flag + * @param key - The unique identifier of the feature flag + * @returns Promise resolving to the flag's boolean value, falling back to default if unavailable + * @throws Will log error and return flag default if check fails + */ async checkFlag(evalCtx: api.CheckFlagRequestBody, key: string): Promise { if (this.offline) { return this.getFlagDefault(key); @@ -104,10 +128,20 @@ export class SchematicClient extends BaseClient { } } + /** + * Gracefully shuts down the client by stopping the event buffer + * @returns Promise that resolves when the event buffer has been stopped + */ async close(): Promise { return this.eventBuffer.stop(); } + /** + * Send a non-blocking event to create or update companies and users + * @param body - The identify event payload containing user properties + * @returns Promise that resolves when the event has been enqueued + * @throws Will log error if event enqueueing fails + */ async identify(body: api.EventBodyIdentify): Promise { if (this.offline) return; @@ -118,6 +152,12 @@ export class SchematicClient extends BaseClient { } } + /** + * Send a non-blocking event to track usage + * @param body - The track event payload containing event details + * @returns Promise that resolves when the event has been enqueued + * @throws Will log error if event enqueueing fails + */ async track(body: api.EventBodyTrack): Promise { if (this.offline) return; @@ -128,10 +168,19 @@ export class SchematicClient extends BaseClient { } } + /** + * Sets the default value for a specific feature flag + * @param flag - The feature flag identifier + * @param value - The default boolean value to set + */ setFlagDefault(flag: string, value: boolean): void { this.flagDefaults[flag] = value; } + /** + * Sets default values for multiple feature flags at once + * @param values - Object mapping flag identifiers to their default boolean values + */ setFlagDefaults(values: { [key: string]: boolean }): void { Object.assign(this.flagDefaults, values); }