interface SdkUserContext { key: string; attributes?: object; } interface VariantDto { variantId: number; dataTypeCode: 'BOOL' | 'STR' | 'NUM' | 'JSON'; name: string; description: string; createdAt: string; updatedAt: string; jsonValue: object; numberValue: number; stringValue: string; booleanValue: boolean; } interface FeatureFlagDto { featureFlagId: number; name: string; key: string; description: string; createdAt: string; updatedAt: string; variants: VariantDto[]; } interface PercentageRolloutEntryDto { variantId: number; percentage: number; } interface TargetingRuleClauseAttributeCustomDto { attributeId: number; name: string; } interface TargetingRuleClauseValueDto { targetingRuleClauseValueId: number; value: string; } interface TargetingRuleClauseDto { targetingRuleClauseId: number; order: number; operator: 'IOO' | 'INOO' | 'EW' | 'DNEW' | 'SW' | 'DNSW' | 'MR' | 'DNMR' | 'LT' | 'LTE' | 'GT' | 'GTE' | 'SVLT' | 'SVLTE' | 'SVGT' | 'SVGTE'; attribute: 'EMAIL' | 'KEY' | 'IP' | 'COUNTRY' | 'CUSTOM'; customAttribute: TargetingRuleClauseAttributeCustomDto; values: TargetingRuleClauseValueDto[]; createdAt: string; updatedAt: string; } interface VariantEnvironmentTargetingRuleDto { variantEnvironmentTargetingRuleId: number; variantId: number; name: string; order: number; createdAt: string; updatedAt: string; clauses: TargetingRuleClauseDto[]; } interface FeatureFlagStateDto { featureFlagEnvironmentStateId: number; environmentId: number; isEnabled: boolean; createdAt: string; updatedAt: string; enabledSingleVariantId: number; disabledSingleVariantId: number; seed: string; percentageRollout: PercentageRolloutEntryDto[]; targetingRules: VariantEnvironmentTargetingRuleDto[]; } interface FeatureFlagEnvironmentDetailDto { organizationId: number; workspaceId: number; environmentId: number; featureFlag: FeatureFlagDto; state: FeatureFlagStateDto; } type LogLevel = 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'NONE'; interface ILogger { setLogLevel(logLevel: LogLevel): void; debug(message: any, ...optionalParams: [...any, string?, string?]): void; info(message: any, ...optionalParams: [...any, string?, string?]): void; log(message: any, ...optionalParams: [...any, string?, string?]): void; warn(message: any, ...optionalParams: [...any, string?, string?]): void; error(message: any, ...optionalParams: [...any, string?, string?]): void; } type FsFlagSet = Record; type CustomAttributeValue = any; type CustomAttributes = Record; type FsUserContext = { key: string; attributes?: CustomAttributes; }; declare const SyncType: { readonly Sse: "sse"; readonly Ws: "ws"; readonly Poll: "poll"; readonly Off: "off"; }; declare const Platform: { readonly Node: "node"; }; type PollingSync = { type: typeof SyncType.Poll; pollRateInSec: number; }; type NonPollingSync = { type?: Exclude<(typeof SyncType)[keyof typeof SyncType], typeof SyncType.Poll>; pollRateInSec?: never; }; interface FsConfig { readonly sdkKey: string; readonly sync?: PollingSync | NonPollingSync; readonly tracking?: { impressions?: { maxQueueSize: number; pushRateInSec: number; }; events?: { maxQueueSize: number; pushRateInSec: number; }; }; readonly urls?: { ws?: string; sse?: string; flags?: string; events?: string; }; logger?: Partial; readonly logLevel?: LogLevel; readonly metadata?: Record; } type EventCallback = (payload: FsEventTypePayload[T]) => void; declare const FsEvent: { readonly SDK_READY: "init::ready"; readonly SDK_READY_FROM_STORE: "init::ready-store"; readonly ERROR: "sdk::error"; readonly SDK_UPDATE: "state::update"; }; type FsEventType = (typeof FsEvent)[keyof typeof FsEvent]; type EventVoidPayload = void; type EventErrorPayload = FsErrorEvent; interface FsEventTypePayload { [FsEvent.SDK_READY]: EventVoidPayload; [FsEvent.ERROR]: EventErrorPayload; [FsEvent.SDK_UPDATE]: EventVoidPayload; [FsEvent.SDK_READY_FROM_STORE]: EventVoidPayload; } interface FeatureFlags { } type IsFeatureFlagsEmpty = keyof T extends never ? true : false; declare const NoExplicitReturn: unique symbol; type NoExplicitReturnType = typeof NoExplicitReturn; type FlagReturnType = IsFeatureFlagsEmpty extends true ? TReturn extends NoExplicitReturnType ? unknown : TReturn : TKey extends keyof TFeatureFlags ? TFeatureFlags[TKey] : never; declare class FsClient { private readonly container; private initialized; constructor(config: FsConfig); private registerServices; /** * Evaluates a feature flag for a given user context with full type-safety. * * This function is designed to work with or without `FlagSync CLI` generated * TypeScript types, providing robust type inference, validation, and autocompletion. * * @example With FlagSync CLI generated types (recommended for full type-safety and DX): * ```ts * declare module '@flagsync/node-sdk' { * interface FeatureFlags { * 'price-discount': 0.1 | 0.2; * 'layout': 'v1' | 'v2' | 'v3'; * 'killswitch': boolean; * } * } * * const ctx = { key: 'user123' }; * * const discount = client.flag(ctx, 'price-discount'); // Type: 0.1 | 0.2 * const layout = client.flag(ctx, 'layout', 'v1'); // Type: 'v1' | 'v2' | 'v3' (defaultValue must be 'v1' | 'v2' | 'v3') * const isEnabled = client.flag(ctx, 'killswitch'); // Type: boolean * const value = client.flag(ctx, 'not-a-real-flag'); // ❌ TS Error: Argument is not a key of FeatureFlags * const badDefault = client.flag(ctx, 'price-discount', 0.5); // ❌ TS Error: Default value type mismatch * ``` * * When not using FlagSync CLI, you must manually type the flag value, or * it will be inferred as "unknown" * * @example Without FlagSync CLI generated types (manual type specification or inference as `unknown`): * ```ts * const ctx = { userId: 'user456' }; * * const layout = client.flag<'v1' | 'v2'>(ctx, 'layout'); // Type: 'v1' | 'v2' * const discount = client.flag(ctx, 'price-discount'); // Type: number * const enabled = client.flag(ctx, 'enable-feature', false); // Type: boolean (defaultValue must be true or false) * * // Without an explicit generic (and no generated types), the return type is `unknown`: * const someDynamicKey = client.flag(ctx, 'some-dynamic-key'); // Type: unknown * ``` */ flag(context: FsUserContext, flagKey: IsFeatureFlagsEmpty extends true ? TKey : (TKey extends keyof FeatureFlags ? TKey : never) | (keyof FeatureFlags extends never ? never : keyof FeatureFlags), defaultValue?: FlagReturnType): FlagReturnType; destroy(): Promise; on(event: T, callback: EventCallback): void; once(event: T, callback: EventCallback): void; off(event: T, callback?: EventCallback): void; track(context: SdkUserContext, eventKey: string, value?: number | null | undefined, properties?: Record): void; waitForReady(): Promise; waitForReadyCanThrow(): Promise; } declare enum ServiceErrorCode { InvalidSdkKey = "INVALID_SDK_KEY", InvalidConfiguration = "INVALID_CONFIGURATION", UnknownError = "UNKNOWN_ERROR", InvalidSdkDefinition = "INVALID_SDK_DEFINITION", UserContextNotFound = "USER_CONTEXT_NOT_FOUND" } interface ServiceErrorInput { errorCode?: ServiceErrorCode; statusCode?: number; message?: string; path?: string; } declare class FsServiceError extends Error { errorCode: ServiceErrorCode; statusCode: number; message: string; path: string; constructor({ errorCode, statusCode, path, message, }?: ServiceErrorInput); } declare class ServiceErrorFactory { /** * Creates a ServiceError from a thrown object. * * @param e The thrown error object, which could be an Error or a Response. */ static create(e: unknown): Promise; /** * Creates a ServiceError from a Response object with structured error data. * @param status The HTTP status code. * @param res The parsed JSON body of the error response. */ private static createFromResponse; /** * Creates a generic ServiceError from an unknown or Error object. * @param e The error object. */ private static createGeneric; } type FsErrorSource = 'api' | 'sdk'; type FsErrorEvent = { type: FsErrorSource; error: Error | FsServiceError; }; declare function FlagSyncFactory(config: FsConfig): { client: () => FsClient; }; export { type CustomAttributeValue, type CustomAttributes, type EventCallback, type FeatureFlags, type FlagReturnType, FlagSyncFactory, FsClient, type FsConfig, type FsErrorEvent, type FsErrorSource, FsEvent, type FsEventType, type FsEventTypePayload, type FsFlagSet, FsServiceError, type FsUserContext, type IsFeatureFlagsEmpty, type LogLevel, NoExplicitReturn, type NoExplicitReturnType, Platform, ServiceErrorFactory, SyncType };