Skip to content

Commit

Permalink
Add TSDoc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bpapillon committed Jan 24, 2025
1 parent 6dda6e3 commit fd03c99
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>[];
};
/** 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<string, string>;
/** Custom logger implementation */
logger?: Logger;
/** Enable offline mode to prevent network activity */
offline?: boolean;
}

Expand All @@ -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 = "",
Expand Down Expand Up @@ -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<boolean> {
if (this.offline) {
return this.getFlagDefault(key);
Expand Down Expand Up @@ -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<void> {
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<void> {
if (this.offline) return;

Expand All @@ -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<void> {
if (this.offline) return;

Expand All @@ -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);
}
Expand Down

0 comments on commit fd03c99

Please sign in to comment.