@gunsole/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +162 -0
- package/dist/index.cjs +477 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +227 -0
- package/dist/index.d.ts +227 -0
- package/dist/index.js +474 -0
- package/dist/index.js.map +1 -0
- package/package.json +65 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/buckets.ts","../src/config.ts","../src/utils/env.ts","../src/transport.ts","../src/client.ts","../src/factory.ts"],"names":[],"mappings":";;;AAsDA,IAAM,cAAA,uBAAkC,GAAA,CAAwB;AAAA,EAC9D,KAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA;AAAA,EACA,SAAA;AAAA,EACA,cAAA;AAAA,EACA,OAAA;AAAA,EACA,SAAA;AAAA,EACA,2BAAA;AAAA,EACA;AACF,CAAC,CAAA;AAKD,SAAS,kBAAA,CAEP,QAA6B,UAAA,EAAwC;AACrE,EAAA,MAAM,UAAA,GAAa,CACjB,KAAA,EACA,OAAA,EACA,OAAA,KACS;AACT,IAAA,MAAA,CAAO,IAAI,KAAA,EAAO;AAAA,MAChB,GAAG,OAAA;AAAA,MACH,OAAA;AAAA,MACA,MAAA,EAAQ;AAAA,KACW,CAAA;AAAA,EACvB,CAAA;AAEA,EAAA,MAAM,MAAA,IAAU,CAAC,OAAA,EAAiB,OAAA,KAA2C;AAC3E,IAAA,UAAA,CAAW,MAAA,EAAQ,SAAS,OAAO,CAAA;AAAA,EACrC,CAAA,CAAA;AAEA,EAAA,MAAA,CAAO,OAAO,CAAC,OAAA,EAAS,YAAa,UAAA,CAAW,MAAA,EAAQ,SAAS,OAAO,CAAA;AACxE,EAAA,MAAA,CAAO,QAAQ,CAAC,OAAA,EAAS,YAAa,UAAA,CAAW,OAAA,EAAS,SAAS,OAAO,CAA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AU,CAAA;AAC7B,MAAA,IAAA,CAAK,UAAA,GAAa,IAAA;AAAA,IACpB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,OAAA,GAAyB;AAC7B,IAAA,IAAA,CAAK,cAAA,EAAe;AACpB,IAAA,IAAA,CAAK,yBAAA,EAA0B;AAC/B,IAAA,MAAM,KAAK,KAAA,EAAM;AAAA,EACnB;AACF;;;AC9TO,SAAS,oBAOd,MAAA,EAC0D;AAC1D,EAAA,MAAM,MAAA,GAAS,IAAI,aAAA,CAAoB,MAAM,CAAA;AAC7C,EAAA,MAAM,OAAA,GAAU,MAAA,CAAO,OAAA,IAAW,EAAC;AACnC,EAAA,IAAI,OAAA,CAAQ,SAAS,CAAA,EAAG;AACtB,IAAA,OAAO,aAAA,CAAqC,QAAQ,OAAO,CAAA;AAAA,EAC7D;AACA,EAAA,OAAO,MAAA;AAET","file":"index.cjs","sourcesContent":["import type { GunsoleClient } from \"./client\";\nimport type { LogLevel, LogOptions } from \"./types\";\n\n/**\n * Log options for bucket methods (message is positional, bucket is implied)\n */\nexport type BucketLogOptions<\n Tags extends Record<string, string> = Record<string, string>,\n> = Omit<LogOptions<Tags>, \"bucket\" | \"message\">;\n\n/**\n * A callable bucket logger with level sub-methods\n */\nexport interface BucketLogger<\n Tags extends Record<string, string> = Record<string, string>,\n> {\n (message: string, options?: BucketLogOptions<Tags>): void;\n info(message: string, options?: BucketLogOptions<Tags>): void;\n debug(message: string, options?: BucketLogOptions<Tags>): void;\n warn(message: string, options?: BucketLogOptions<Tags>): void;\n error(message: string, options?: BucketLogOptions<Tags>): void;\n}\n\n/**\n * Mapped type that adds bucket accessors to a client\n */\nexport type WithBuckets<\n Tags extends Record<string, string> = Record<string, string>,\n Buckets extends string = string,\n> = { [K in Buckets]: BucketLogger<Tags> };\n\n/**\n * Bucket names that conflict with GunsoleClient methods\n */\nexport type ReservedBucketName =\n | \"log\"\n | \"info\"\n | \"debug\"\n | \"warn\"\n | \"error\"\n | \"setUser\"\n | \"setSessionId\"\n | \"flush\"\n | \"destroy\"\n | \"attachGlobalErrorHandlers\"\n | \"detachGlobalErrorHandlers\";\n\n/**\n * Validates a buckets tuple at the type level — reserved names become `never`\n */\nexport type ValidateBuckets<T extends readonly string[]> = {\n [K in keyof T]: T[K] extends ReservedBucketName ? never : T[K];\n};\n\nconst RESERVED_NAMES: Set<string> = new Set<ReservedBucketName>([\n \"log\",\n \"info\",\n \"debug\",\n \"warn\",\n \"error\",\n \"setUser\",\n \"setSessionId\",\n \"flush\",\n \"destroy\",\n \"attachGlobalErrorHandlers\",\n \"detachGlobalErrorHandlers\",\n]);\n\n/**\n * Create a BucketLogger for a specific bucket name\n */\nfunction createBucketLogger<\n Tags extends Record<string, string> = Record<string, string>,\n>(client: GunsoleClient<Tags>, bucketName: string): BucketLogger<Tags> {\n const logAtLevel = (\n level: LogLevel,\n message: string,\n options?: BucketLogOptions<Tags>\n ): void => {\n client.log(level, {\n ...options,\n message,\n bucket: bucketName,\n } as LogOptions<Tags>);\n };\n\n const logger = ((message: string, options?: BucketLogOptions<Tags>): void => {\n logAtLevel(\"info\", message, options);\n }) as BucketLogger<Tags>;\n\n logger.info = (message, options?) => logAtLevel(\"info\", message, options);\n logger.debug = (message, options?) => logAtLevel(\"debug\", message, options);\n logger.warn = (message, options?) => logAtLevel(\"warn\", message, options);\n logger.error = (message, options?) => logAtLevel(\"error\", message, options);\n\n return logger;\n}\n\n/**\n * Attach bucket accessors to a client instance\n */\nexport function attachBuckets<\n Tags extends Record<string, string> = Record<string, string>,\n Buckets extends string = string,\n>(\n client: GunsoleClient<Tags>,\n buckets: readonly string[]\n): GunsoleClient<Tags> & WithBuckets<Tags, Buckets> {\n for (const name of buckets) {\n if (RESERVED_NAMES.has(name)) {\n throw new Error(\n `Bucket name \"${name}\" conflicts with a reserved GunsoleClient method`\n );\n }\n (client as unknown as Record<string, unknown>)[name] =\n createBucketLogger(client, name);\n }\n return client as GunsoleClient<Tags> & WithBuckets<Tags, Buckets>;\n}\n","import type { ClientMode, GunsoleClientConfig } from \"./types\";\n\n/**\n * Default endpoints for each mode\n */\nconst DEFAULT_ENDPOINTS: Record<ClientMode, string> = {\n desktop: \"http://localhost:8787\",\n local: \"http://localhost:17655\",\n cloud: \"https://api.gunsole.com\",\n};\n\n/**\n * Default configuration values\n */\nconst DEFAULT_CONFIG = {\n batchSize: 10,\n flushInterval: 5000,\n};\n\n/**\n * Resolve the endpoint URL based on mode and custom endpoint\n */\nexport function resolveEndpoint(\n mode: ClientMode,\n customEndpoint?: string\n): string {\n if (customEndpoint) {\n return customEndpoint;\n }\n return DEFAULT_ENDPOINTS[mode];\n}\n\n/**\n * Normalize and validate client configuration\n */\nexport function normalizeConfig(config: GunsoleClientConfig): Omit<\n Required<GunsoleClientConfig>,\n \"fetch\"\n> & {\n endpoint: string;\n fetch?: GunsoleClientConfig[\"fetch\"];\n} {\n if (!config.projectId) {\n throw new Error(\"projectId is required\");\n }\n return {\n projectId: config.projectId,\n apiKey: config.apiKey ?? \"\",\n mode: config.mode,\n endpoint: resolveEndpoint(config.mode, config.endpoint),\n env: config.env ?? \"\",\n appName: config.appName ?? \"\",\n appVersion: config.appVersion ?? \"\",\n defaultTags: config.defaultTags ?? {},\n batchSize: config.batchSize ?? DEFAULT_CONFIG.batchSize,\n flushInterval: config.flushInterval ?? DEFAULT_CONFIG.flushInterval,\n fetch: config.fetch,\n isDebug: config.isDebug ?? false,\n isDisabled: config.isDisabled ?? false,\n buckets: config.buckets ?? [],\n };\n}\n","import type { FetchFunction } from \"../types\";\n\n/**\n * Check if running in a browser environment\n */\nexport function isBrowser(): boolean {\n return (\n typeof window !== \"undefined\" && typeof window.document !== \"undefined\"\n );\n}\n\n/**\n * Check if running in Node.js environment\n */\nexport function isNode(): boolean {\n return (\n typeof process !== \"undefined\" &&\n typeof process.versions !== \"undefined\" &&\n typeof process.versions.node !== \"undefined\"\n );\n}\n\n/**\n * Get fetch implementation (browser or Node.js)\n * If a custom fetch is provided, it will be used instead.\n */\nexport function getFetch(customFetch?: FetchFunction): FetchFunction {\n if (customFetch) {\n return customFetch;\n }\n\n if (isBrowser()) {\n return window.fetch.bind(window);\n }\n if (isNode()) {\n // In Node.js 18+, fetch is available globally\n if (typeof globalThis.fetch !== \"undefined\") {\n return globalThis.fetch;\n }\n // For older Node.js versions, user must provide their own fetch\n throw new Error(\n \"fetch is not available. Please use Node.js 18+ or provide a custom fetch implementation in the config\"\n );\n }\n throw new Error(\"Unsupported environment: neither browser nor Node.js\");\n}\n","import type { BatchPayload, FetchFunction, InternalLogEntry } from \"./types.js\";\nimport { getFetch } from \"./utils/env.js\";\n\n/**\n * Maximum number of retry attempts\n */\nconst MAX_RETRIES = 3;\n\n/**\n * Base delay for exponential backoff (milliseconds)\n */\nconst BASE_DELAY_MS = 1000;\n\n/**\n * Calculate exponential backoff delay\n */\nfunction calculateBackoffDelay(attempt: number): number {\n return BASE_DELAY_MS * 2 ** attempt;\n}\n\n/**\n * Sleep utility for retry delays\n */\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\n/**\n * Gzip compress a string using the native Compression Streams API\n */\nasync function gzipCompress(input: string): Promise<Uint8Array> {\n const encoder = new TextEncoder();\n const stream = new Blob([encoder.encode(input)])\n .stream()\n .pipeThrough(new CompressionStream(\"gzip\"));\n return new Uint8Array(await new Response(stream).arrayBuffer());\n}\n\n/**\n * Minify and optionally compress payload\n */\nasync function compressPayload(\n payload: BatchPayload,\n isDebug: boolean\n): Promise<string | Uint8Array> {\n const minified = JSON.stringify(payload);\n\n if (isDebug) {\n return minified;\n }\n\n return gzipCompress(minified);\n}\n\n/**\n * Transport layer for sending logs to the Gunsole API\n */\nexport class Transport {\n private endpoint: string;\n private apiKey: string;\n private projectId: string;\n private fetch: FetchFunction;\n private isDebug: boolean;\n\n constructor(\n endpoint: string,\n apiKey: string,\n projectId: string,\n fetch?: FetchFunction,\n isDebug = false\n ) {\n this.endpoint = endpoint;\n this.apiKey = apiKey;\n this.projectId = projectId;\n this.fetch = fetch ?? getFetch();\n this.isDebug = isDebug;\n }\n\n /**\n * Send a batch of logs to the API\n * Implements retry logic with exponential backoff\n */\n async sendBatch(logs: InternalLogEntry[]): Promise<void> {\n if (logs.length === 0) {\n return;\n }\n\n const payload: BatchPayload = {\n projectId: this.projectId,\n logs,\n };\n\n let lastError: Error | null = null;\n\n for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {\n try {\n const body = await compressPayload(payload, this.isDebug);\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n };\n\n if (this.apiKey) {\n headers[\"Authorization\"] = `Bearer ${this.apiKey}`;\n }\n\n // Only set Content-Encoding if not in debug mode\n if (!this.isDebug) {\n headers[\"Content-Encoding\"] = \"gzip\";\n }\n\n const response = await this.fetch(`${this.endpoint}/logs`, {\n method: \"POST\",\n headers,\n body: body as BodyInit,\n });\n\n if (response.ok) {\n return; // Success\n }\n\n // Non-2xx response\n const errorText = await response.text().catch(() => \"Unknown error\");\n lastError = new Error(`HTTP ${response.status}: ${errorText}`);\n\n // Don't retry client errors (4xx) except 429 (rate limited)\n if (response.status >= 400 && response.status < 500 && response.status !== 429) {\n break;\n }\n } catch (error) {\n lastError = error instanceof Error ? error : new Error(String(error));\n }\n\n // If not the last attempt, wait before retrying\n if (attempt < MAX_RETRIES - 1) {\n const delay = calculateBackoffDelay(attempt);\n await sleep(delay);\n }\n }\n\n // All retries failed - silently swallow the error\n // This ensures the SDK never crashes the host application\n // In production, you might want to log this to console in debug mode\n if (process.env.NODE_ENV === \"development\") {\n console.warn(\"[Gunsole] Failed to send logs after retries:\", lastError);\n }\n }\n}\n","import { normalizeConfig } from \"./config\";\nimport { Transport } from \"./transport\";\nimport type {\n GunsoleClientConfig,\n InternalLogEntry,\n LogLevel,\n LogOptions,\n UserInfo,\n ValidTagSchema,\n} from \"./types\";\n\n/**\n * Global error handler state\n */\ninterface GlobalErrorHandlers {\n unhandledRejection?: (event: PromiseRejectionEvent) => void;\n unhandledRejectionNode?: (reason: unknown, promise: Promise<unknown>) => void;\n error?: (event: ErrorEvent) => void;\n uncaughtException?: (error: Error) => void;\n attached: boolean;\n}\n\n/**\n * Gunsole client for sending logs and events\n */\nexport class GunsoleClient<\n Tags extends Record<string, string> & ValidTagSchema = Record<\n string,\n string\n >,\n> {\n private config: ReturnType<typeof normalizeConfig>;\n private transport: Transport;\n private batch: InternalLogEntry[] = [];\n private flushTimer: ReturnType<typeof setInterval> | null = null;\n private user: UserInfo | null = null;\n private sessionId: string | null = null;\n private globalHandlers: GlobalErrorHandlers = { attached: false };\n private readonly disabled: boolean;\n\n constructor(config: GunsoleClientConfig) {\n this.config = normalizeConfig(config);\n this.disabled = config.isDisabled ?? false;\n this.transport = new Transport(\n this.config.endpoint,\n this.config.apiKey,\n this.config.projectId,\n this.config.fetch,\n config.isDebug ?? false\n );\n\n if (this.disabled) {\n return;\n }\n\n this.startFlushTimer();\n }\n\n /**\n * Log a message. Defaults to info level.\n */\n log(options: LogOptions<Tags>): void;\n log(level: LogLevel, options: LogOptions<Tags>): void;\n log(\n levelOrOptions: LogLevel | LogOptions<Tags>,\n maybeOptions?: LogOptions<Tags>\n ): void {\n if (this.disabled) {\n return;\n }\n const level: LogLevel =\n typeof levelOrOptions === \"string\" ? levelOrOptions : \"info\";\n const options: LogOptions<Tags> =\n typeof levelOrOptions === \"string\" ? maybeOptions! : levelOrOptions;\n try {\n const internalEntry: InternalLogEntry = {\n level,\n bucket: options.bucket,\n message: options.message,\n context: options.context,\n timestamp: Date.now(),\n traceId: options.traceId,\n userId: this.user?.id,\n sessionId: this.sessionId ?? undefined,\n env: this.config.env || undefined,\n appName: this.config.appName || undefined,\n appVersion: this.config.appVersion || undefined,\n tags: {\n ...this.config.defaultTags,\n ...(Array.isArray(options.tags)\n ? Object.assign({}, ...options.tags)\n : options.tags),\n },\n };\n\n this.batch.push(internalEntry);\n\n // Flush if batch is full\n if (this.batch.length >= this.config.batchSize) {\n this.flush();\n }\n } catch (error) {\n // Silently swallow errors - never crash the host app\n if (process.env.NODE_ENV === \"development\") {\n console.warn(\"[Gunsole] Error in log():\", error);\n }\n }\n }\n\n /**\n * Log an info-level message\n */\n info(options: LogOptions<Tags>): void {\n this.log(\"info\", options);\n }\n\n debug(options: LogOptions<Tags>): void {\n this.log(\"debug\", options);\n }\n\n warn(options: LogOptions<Tags>): void {\n this.log(\"warn\", options);\n }\n\n error(options: LogOptions<Tags>): void {\n this.log(\"error\", options);\n }\n\n /**\n * Set user information\n */\n setUser(user: UserInfo): void {\n if (this.disabled) {\n return;\n }\n try {\n this.user = user;\n } catch (error) {\n if (process.env.NODE_ENV === \"development\") {\n console.warn(\"[Gunsole] Error in setUser():\", error);\n }\n }\n }\n\n /**\n * Set session ID\n */\n setSessionId(sessionId: string): void {\n if (this.disabled) {\n return;\n }\n try {\n this.sessionId = sessionId;\n } catch (error) {\n if (process.env.NODE_ENV === \"development\") {\n console.warn(\"[Gunsole] Error in setSessionId():\", error);\n }\n }\n }\n\n /**\n * Flush pending logs to the API\n */\n async flush(): Promise<void> {\n if (this.disabled) {\n return;\n }\n try {\n if (this.batch.length === 0) {\n return;\n }\n\n const logsToSend = [...this.batch];\n this.batch = [];\n\n await this.transport.sendBatch(logsToSend);\n } catch (error) {\n // Silently swallow errors\n if (process.env.NODE_ENV === \"development\") {\n console.warn(\"[Gunsole] Error in flush():\", error);\n }\n }\n }\n\n /**\n * Attach global error handlers\n */\n attachGlobalErrorHandlers(): void {\n if (this.disabled) {\n return;\n }\n try {\n if (this.globalHandlers.attached) {\n return;\n }\n\n // Unhandled promise rejections\n this.globalHandlers.unhandledRejection = (\n event: PromiseRejectionEvent\n ) => {\n this.error({\n message: \"Unhandled promise rejection\",\n bucket: \"unhandled_rejection\",\n context: {\n reason: String(event.reason),\n error:\n event.reason instanceof Error\n ? {\n name: event.reason.name,\n message: event.reason.message,\n stack: event.reason.stack,\n }\n : event.reason,\n },\n });\n };\n\n // Global errors\n this.globalHandlers.error = (event: ErrorEvent) => {\n this.error({\n message: event.message || \"Global error\",\n bucket: \"global_error\",\n context: {\n filename: event.filename,\n lineno: event.lineno,\n colno: event.colno,\n error: event.error\n ? {\n name: event.error.name,\n message: event.error.message,\n stack: event.error.stack,\n }\n : undefined,\n },\n });\n };\n\n if (typeof window !== \"undefined\") {\n window.addEventListener(\n \"unhandledrejection\",\n this.globalHandlers.unhandledRejection\n );\n window.addEventListener(\"error\", this.globalHandlers.error);\n }\n\n if (typeof process !== \"undefined\") {\n this.globalHandlers.unhandledRejectionNode = (\n reason: unknown,\n _promise: Promise<unknown>\n ) => {\n this.error({\n message: \"Unhandled promise rejection\",\n bucket: \"unhandled_rejection\",\n context: {\n reason: String(reason),\n error:\n reason instanceof Error\n ? {\n name: reason.name,\n message: reason.message,\n stack: reason.stack,\n }\n : reason,\n },\n });\n };\n\n this.globalHandlers.uncaughtException = (error: Error) => {\n this.error({\n message: error.message,\n bucket: \"uncaught_exception\",\n context: {\n name: error.name,\n stack: error.stack,\n },\n });\n };\n\n process.on(\n \"unhandledRejection\",\n this.globalHandlers.unhandledRejectionNode\n );\n process.on(\"uncaughtException\", this.globalHandlers.uncaughtException);\n }\n\n this.globalHandlers.attached = true;\n } catch (error) {\n if (process.env.NODE_ENV === \"development\") {\n console.warn(\"[Gunsole] Error in attachGlobalErrorHandlers():\", error);\n }\n }\n }\n\n /**\n * Detach global error handlers\n */\n detachGlobalErrorHandlers(): void {\n try {\n if (!this.globalHandlers.attached) {\n return;\n }\n\n if (typeof window !== \"undefined\") {\n if (this.globalHandlers.unhandledRejection) {\n window.removeEventListener(\n \"unhandledrejection\",\n this.globalHandlers.unhandledRejection\n );\n }\n if (this.globalHandlers.error) {\n window.removeEventListener(\"error\", this.globalHandlers.error);\n }\n }\n\n if (typeof process !== \"undefined\") {\n if (this.globalHandlers.unhandledRejectionNode) {\n process.removeListener(\n \"unhandledRejection\",\n this.globalHandlers.unhandledRejectionNode\n );\n }\n if (this.globalHandlers.uncaughtException) {\n process.removeListener(\n \"uncaughtException\",\n this.globalHandlers.uncaughtException\n );\n }\n }\n\n this.globalHandlers = { attached: false };\n } catch (error) {\n if (process.env.NODE_ENV === \"development\") {\n console.warn(\"[Gunsole] Error in detachGlobalErrorHandlers():\", error);\n }\n }\n }\n\n /**\n * Start the automatic flush timer\n */\n private startFlushTimer(): void {\n if (this.flushTimer) {\n return;\n }\n\n this.flushTimer = setInterval(() => {\n this.flush();\n }, this.config.flushInterval);\n }\n\n /**\n * Stop the automatic flush timer\n */\n private stopFlushTimer(): void {\n if (this.flushTimer) {\n clearInterval(this.flushTimer);\n this.flushTimer = null;\n }\n }\n\n /**\n * Cleanup resources. Awaiting ensures remaining logs are flushed.\n */\n async destroy(): Promise<void> {\n this.stopFlushTimer();\n this.detachGlobalErrorHandlers();\n await this.flush();\n }\n}\n","import {\n type ValidateBuckets,\n type WithBuckets,\n attachBuckets,\n} from \"./buckets\";\nimport { GunsoleClient } from \"./client\";\nimport type { GunsoleClientConfig, ValidTagSchema } from \"./types\";\n\n/**\n * Config without buckets — used for overload resolution so that\n * a config with `buckets` falls through to the validated overload.\n */\ntype BaseConfig = Omit<GunsoleClientConfig, \"buckets\">;\n\n/**\n * Create a new Gunsole client instance\n *\n * @param config - Client configuration\n * @returns Gunsole client instance\n *\n * @example\n * ```ts\n * const gunsole = createGunsoleClient({\n * projectId: \"my-project\",\n * apiKey: \"my-api-key\",\n * mode: \"cloud\",\n * buckets: [\"payment\", \"auth\"],\n * });\n *\n * gunsole.payment(\"User paid\");\n * gunsole.auth.error(\"Login failed\");\n * ```\n */\nexport function createGunsoleClient<\n Tags extends Record<string, string> & ValidTagSchema = Record<\n string,\n string\n >,\n>(config: BaseConfig): GunsoleClient<Tags>;\nexport function createGunsoleClient<\n Tags extends Record<string, string> & ValidTagSchema = Record<\n string,\n string\n >,\n const Buckets extends readonly string[] = readonly string[],\n>(\n config: BaseConfig & {\n buckets: Buckets & NoInfer<ValidateBuckets<Buckets>>;\n }\n): GunsoleClient<Tags> & WithBuckets<Tags, Buckets[number]>;\nexport function createGunsoleClient<\n Tags extends Record<string, string> & ValidTagSchema = Record<\n string,\n string\n >,\n const Buckets extends readonly string[] = readonly string[],\n>(\n config: GunsoleClientConfig & { buckets?: Buckets }\n): GunsoleClient<Tags> & WithBuckets<Tags, Buckets[number]> {\n const client = new GunsoleClient<Tags>(config);\n const buckets = config.buckets ?? [];\n if (buckets.length > 0) {\n return attachBuckets<Tags, Buckets[number]>(client, buckets);\n }\n return client as GunsoleClient<Tags> &\n WithBuckets<Tags, Buckets[number]>;\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetch function type
|
|
3
|
+
*/
|
|
4
|
+
type FetchFunction = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
5
|
+
/**
|
|
6
|
+
* Log level enumeration
|
|
7
|
+
*/
|
|
8
|
+
type LogLevel = "info" | "debug" | "warn" | "error";
|
|
9
|
+
/**
|
|
10
|
+
* Client mode determines the default endpoint
|
|
11
|
+
*/
|
|
12
|
+
type ClientMode = "desktop" | "local" | "cloud";
|
|
13
|
+
/** Single-key tag entry derived from a tag schema */
|
|
14
|
+
type TagEntry<T> = {
|
|
15
|
+
[K in keyof T]: Pick<T, K>;
|
|
16
|
+
}[keyof T];
|
|
17
|
+
/**
|
|
18
|
+
* Tag keys reserved by internal log entry fields.
|
|
19
|
+
* Using these as tag keys would shadow internal metadata.
|
|
20
|
+
*/
|
|
21
|
+
type ReservedTagKey = "bucket" | "message" | "level" | "timestamp" | "userId" | "sessionId" | "env" | "appName" | "appVersion";
|
|
22
|
+
/**
|
|
23
|
+
* Constrains a tag schema to exclude reserved internal field names.
|
|
24
|
+
* Each reserved key must be `never` (i.e. absent) in a valid tag type.
|
|
25
|
+
*/
|
|
26
|
+
type ValidTagSchema = {
|
|
27
|
+
[K in ReservedTagKey]?: never;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Options for logging methods (log, info, debug, warn, error)
|
|
31
|
+
*/
|
|
32
|
+
interface LogOptions<Tags extends Record<string, string> = Record<string, string>> {
|
|
33
|
+
/** Human-readable message */
|
|
34
|
+
message: string;
|
|
35
|
+
/** Bucket/category for the log */
|
|
36
|
+
bucket: string;
|
|
37
|
+
/** Additional context data */
|
|
38
|
+
context?: Record<string, unknown>;
|
|
39
|
+
/** Tags for filtering/grouping */
|
|
40
|
+
tags?: Partial<Tags> | TagEntry<Tags>[];
|
|
41
|
+
/** Trace ID for distributed tracing */
|
|
42
|
+
traceId?: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Log entry structure
|
|
46
|
+
*/
|
|
47
|
+
interface LogEntry {
|
|
48
|
+
/** Bucket/category for the log */
|
|
49
|
+
bucket: string;
|
|
50
|
+
/** Human-readable message */
|
|
51
|
+
message: string;
|
|
52
|
+
/** Additional context data */
|
|
53
|
+
context?: Record<string, unknown>;
|
|
54
|
+
/** Tags for filtering/grouping */
|
|
55
|
+
tags?: Record<string, string>;
|
|
56
|
+
/** Timestamp (Unix milliseconds, SDK fills if not provided) */
|
|
57
|
+
timestamp?: number;
|
|
58
|
+
/** Trace ID for distributed tracing */
|
|
59
|
+
traceId?: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* User information
|
|
63
|
+
*/
|
|
64
|
+
interface UserInfo {
|
|
65
|
+
/** Unique user identifier */
|
|
66
|
+
id: string;
|
|
67
|
+
/** User email address */
|
|
68
|
+
email?: string;
|
|
69
|
+
/** User display name */
|
|
70
|
+
name?: string;
|
|
71
|
+
/** Additional user traits */
|
|
72
|
+
traits?: Record<string, unknown>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Client configuration options
|
|
76
|
+
*/
|
|
77
|
+
interface GunsoleClientConfig {
|
|
78
|
+
/** Project identifier */
|
|
79
|
+
projectId: string;
|
|
80
|
+
/** API key (public or secret). Required for cloud mode. */
|
|
81
|
+
apiKey?: string;
|
|
82
|
+
/** Client mode (desktop/local/cloud) */
|
|
83
|
+
mode: ClientMode;
|
|
84
|
+
/** Custom endpoint URL (overrides mode default) */
|
|
85
|
+
endpoint?: string;
|
|
86
|
+
/** Environment name (e.g., "production", "staging") */
|
|
87
|
+
env?: string;
|
|
88
|
+
/** Application name */
|
|
89
|
+
appName?: string;
|
|
90
|
+
/** Application version */
|
|
91
|
+
appVersion?: string;
|
|
92
|
+
/** Default tags applied to all logs */
|
|
93
|
+
defaultTags?: Record<string, string>;
|
|
94
|
+
/** Batch size for log batching (default: 10) */
|
|
95
|
+
batchSize?: number;
|
|
96
|
+
/** Flush interval in milliseconds (default: 5000) */
|
|
97
|
+
flushInterval?: number;
|
|
98
|
+
/** Custom fetch implementation (default: uses global fetch or throws error) */
|
|
99
|
+
fetch?: FetchFunction;
|
|
100
|
+
/** Debug mode - when true, disables gzip compression for readable network payloads */
|
|
101
|
+
isDebug?: boolean;
|
|
102
|
+
/** When true, all SDK methods become no-ops. Useful for disabling in specific environments. */
|
|
103
|
+
isDisabled?: boolean;
|
|
104
|
+
/** Typed bucket names for bucket accessor methods */
|
|
105
|
+
buckets?: readonly string[];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Gunsole client for sending logs and events
|
|
110
|
+
*/
|
|
111
|
+
declare class GunsoleClient<Tags extends Record<string, string> & ValidTagSchema = Record<string, string>> {
|
|
112
|
+
private config;
|
|
113
|
+
private transport;
|
|
114
|
+
private batch;
|
|
115
|
+
private flushTimer;
|
|
116
|
+
private user;
|
|
117
|
+
private sessionId;
|
|
118
|
+
private globalHandlers;
|
|
119
|
+
private readonly disabled;
|
|
120
|
+
constructor(config: GunsoleClientConfig);
|
|
121
|
+
/**
|
|
122
|
+
* Log a message. Defaults to info level.
|
|
123
|
+
*/
|
|
124
|
+
log(options: LogOptions<Tags>): void;
|
|
125
|
+
log(level: LogLevel, options: LogOptions<Tags>): void;
|
|
126
|
+
/**
|
|
127
|
+
* Log an info-level message
|
|
128
|
+
*/
|
|
129
|
+
info(options: LogOptions<Tags>): void;
|
|
130
|
+
debug(options: LogOptions<Tags>): void;
|
|
131
|
+
warn(options: LogOptions<Tags>): void;
|
|
132
|
+
error(options: LogOptions<Tags>): void;
|
|
133
|
+
/**
|
|
134
|
+
* Set user information
|
|
135
|
+
*/
|
|
136
|
+
setUser(user: UserInfo): void;
|
|
137
|
+
/**
|
|
138
|
+
* Set session ID
|
|
139
|
+
*/
|
|
140
|
+
setSessionId(sessionId: string): void;
|
|
141
|
+
/**
|
|
142
|
+
* Flush pending logs to the API
|
|
143
|
+
*/
|
|
144
|
+
flush(): Promise<void>;
|
|
145
|
+
/**
|
|
146
|
+
* Attach global error handlers
|
|
147
|
+
*/
|
|
148
|
+
attachGlobalErrorHandlers(): void;
|
|
149
|
+
/**
|
|
150
|
+
* Detach global error handlers
|
|
151
|
+
*/
|
|
152
|
+
detachGlobalErrorHandlers(): void;
|
|
153
|
+
/**
|
|
154
|
+
* Start the automatic flush timer
|
|
155
|
+
*/
|
|
156
|
+
private startFlushTimer;
|
|
157
|
+
/**
|
|
158
|
+
* Stop the automatic flush timer
|
|
159
|
+
*/
|
|
160
|
+
private stopFlushTimer;
|
|
161
|
+
/**
|
|
162
|
+
* Cleanup resources. Awaiting ensures remaining logs are flushed.
|
|
163
|
+
*/
|
|
164
|
+
destroy(): Promise<void>;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Log options for bucket methods (message is positional, bucket is implied)
|
|
169
|
+
*/
|
|
170
|
+
type BucketLogOptions<Tags extends Record<string, string> = Record<string, string>> = Omit<LogOptions<Tags>, "bucket" | "message">;
|
|
171
|
+
/**
|
|
172
|
+
* A callable bucket logger with level sub-methods
|
|
173
|
+
*/
|
|
174
|
+
interface BucketLogger<Tags extends Record<string, string> = Record<string, string>> {
|
|
175
|
+
(message: string, options?: BucketLogOptions<Tags>): void;
|
|
176
|
+
info(message: string, options?: BucketLogOptions<Tags>): void;
|
|
177
|
+
debug(message: string, options?: BucketLogOptions<Tags>): void;
|
|
178
|
+
warn(message: string, options?: BucketLogOptions<Tags>): void;
|
|
179
|
+
error(message: string, options?: BucketLogOptions<Tags>): void;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Mapped type that adds bucket accessors to a client
|
|
183
|
+
*/
|
|
184
|
+
type WithBuckets<Tags extends Record<string, string> = Record<string, string>, Buckets extends string = string> = {
|
|
185
|
+
[K in Buckets]: BucketLogger<Tags>;
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* Bucket names that conflict with GunsoleClient methods
|
|
189
|
+
*/
|
|
190
|
+
type ReservedBucketName = "log" | "info" | "debug" | "warn" | "error" | "setUser" | "setSessionId" | "flush" | "destroy" | "attachGlobalErrorHandlers" | "detachGlobalErrorHandlers";
|
|
191
|
+
/**
|
|
192
|
+
* Validates a buckets tuple at the type level — reserved names become `never`
|
|
193
|
+
*/
|
|
194
|
+
type ValidateBuckets<T extends readonly string[]> = {
|
|
195
|
+
[K in keyof T]: T[K] extends ReservedBucketName ? never : T[K];
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Config without buckets — used for overload resolution so that
|
|
200
|
+
* a config with `buckets` falls through to the validated overload.
|
|
201
|
+
*/
|
|
202
|
+
type BaseConfig = Omit<GunsoleClientConfig, "buckets">;
|
|
203
|
+
/**
|
|
204
|
+
* Create a new Gunsole client instance
|
|
205
|
+
*
|
|
206
|
+
* @param config - Client configuration
|
|
207
|
+
* @returns Gunsole client instance
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```ts
|
|
211
|
+
* const gunsole = createGunsoleClient({
|
|
212
|
+
* projectId: "my-project",
|
|
213
|
+
* apiKey: "my-api-key",
|
|
214
|
+
* mode: "cloud",
|
|
215
|
+
* buckets: ["payment", "auth"],
|
|
216
|
+
* });
|
|
217
|
+
*
|
|
218
|
+
* gunsole.payment("User paid");
|
|
219
|
+
* gunsole.auth.error("Login failed");
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
declare function createGunsoleClient<Tags extends Record<string, string> & ValidTagSchema = Record<string, string>>(config: BaseConfig): GunsoleClient<Tags>;
|
|
223
|
+
declare function createGunsoleClient<Tags extends Record<string, string> & ValidTagSchema = Record<string, string>, const Buckets extends readonly string[] = readonly string[]>(config: BaseConfig & {
|
|
224
|
+
buckets: Buckets & NoInfer<ValidateBuckets<Buckets>>;
|
|
225
|
+
}): GunsoleClient<Tags> & WithBuckets<Tags, Buckets[number]>;
|
|
226
|
+
|
|
227
|
+
export { type BucketLogOptions, type BucketLogger, type ClientMode, type FetchFunction, GunsoleClient, type GunsoleClientConfig, type LogEntry, type LogLevel, type LogOptions, type ReservedBucketName, type ReservedTagKey, type TagEntry, type UserInfo, type ValidTagSchema, type ValidateBuckets, type WithBuckets, createGunsoleClient };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetch function type
|
|
3
|
+
*/
|
|
4
|
+
type FetchFunction = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
5
|
+
/**
|
|
6
|
+
* Log level enumeration
|
|
7
|
+
*/
|
|
8
|
+
type LogLevel = "info" | "debug" | "warn" | "error";
|
|
9
|
+
/**
|
|
10
|
+
* Client mode determines the default endpoint
|
|
11
|
+
*/
|
|
12
|
+
type ClientMode = "desktop" | "local" | "cloud";
|
|
13
|
+
/** Single-key tag entry derived from a tag schema */
|
|
14
|
+
type TagEntry<T> = {
|
|
15
|
+
[K in keyof T]: Pick<T, K>;
|
|
16
|
+
}[keyof T];
|
|
17
|
+
/**
|
|
18
|
+
* Tag keys reserved by internal log entry fields.
|
|
19
|
+
* Using these as tag keys would shadow internal metadata.
|
|
20
|
+
*/
|
|
21
|
+
type ReservedTagKey = "bucket" | "message" | "level" | "timestamp" | "userId" | "sessionId" | "env" | "appName" | "appVersion";
|
|
22
|
+
/**
|
|
23
|
+
* Constrains a tag schema to exclude reserved internal field names.
|
|
24
|
+
* Each reserved key must be `never` (i.e. absent) in a valid tag type.
|
|
25
|
+
*/
|
|
26
|
+
type ValidTagSchema = {
|
|
27
|
+
[K in ReservedTagKey]?: never;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Options for logging methods (log, info, debug, warn, error)
|
|
31
|
+
*/
|
|
32
|
+
interface LogOptions<Tags extends Record<string, string> = Record<string, string>> {
|
|
33
|
+
/** Human-readable message */
|
|
34
|
+
message: string;
|
|
35
|
+
/** Bucket/category for the log */
|
|
36
|
+
bucket: string;
|
|
37
|
+
/** Additional context data */
|
|
38
|
+
context?: Record<string, unknown>;
|
|
39
|
+
/** Tags for filtering/grouping */
|
|
40
|
+
tags?: Partial<Tags> | TagEntry<Tags>[];
|
|
41
|
+
/** Trace ID for distributed tracing */
|
|
42
|
+
traceId?: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Log entry structure
|
|
46
|
+
*/
|
|
47
|
+
interface LogEntry {
|
|
48
|
+
/** Bucket/category for the log */
|
|
49
|
+
bucket: string;
|
|
50
|
+
/** Human-readable message */
|
|
51
|
+
message: string;
|
|
52
|
+
/** Additional context data */
|
|
53
|
+
context?: Record<string, unknown>;
|
|
54
|
+
/** Tags for filtering/grouping */
|
|
55
|
+
tags?: Record<string, string>;
|
|
56
|
+
/** Timestamp (Unix milliseconds, SDK fills if not provided) */
|
|
57
|
+
timestamp?: number;
|
|
58
|
+
/** Trace ID for distributed tracing */
|
|
59
|
+
traceId?: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* User information
|
|
63
|
+
*/
|
|
64
|
+
interface UserInfo {
|
|
65
|
+
/** Unique user identifier */
|
|
66
|
+
id: string;
|
|
67
|
+
/** User email address */
|
|
68
|
+
email?: string;
|
|
69
|
+
/** User display name */
|
|
70
|
+
name?: string;
|
|
71
|
+
/** Additional user traits */
|
|
72
|
+
traits?: Record<string, unknown>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Client configuration options
|
|
76
|
+
*/
|
|
77
|
+
interface GunsoleClientConfig {
|
|
78
|
+
/** Project identifier */
|
|
79
|
+
projectId: string;
|
|
80
|
+
/** API key (public or secret). Required for cloud mode. */
|
|
81
|
+
apiKey?: string;
|
|
82
|
+
/** Client mode (desktop/local/cloud) */
|
|
83
|
+
mode: ClientMode;
|
|
84
|
+
/** Custom endpoint URL (overrides mode default) */
|
|
85
|
+
endpoint?: string;
|
|
86
|
+
/** Environment name (e.g., "production", "staging") */
|
|
87
|
+
env?: string;
|
|
88
|
+
/** Application name */
|
|
89
|
+
appName?: string;
|
|
90
|
+
/** Application version */
|
|
91
|
+
appVersion?: string;
|
|
92
|
+
/** Default tags applied to all logs */
|
|
93
|
+
defaultTags?: Record<string, string>;
|
|
94
|
+
/** Batch size for log batching (default: 10) */
|
|
95
|
+
batchSize?: number;
|
|
96
|
+
/** Flush interval in milliseconds (default: 5000) */
|
|
97
|
+
flushInterval?: number;
|
|
98
|
+
/** Custom fetch implementation (default: uses global fetch or throws error) */
|
|
99
|
+
fetch?: FetchFunction;
|
|
100
|
+
/** Debug mode - when true, disables gzip compression for readable network payloads */
|
|
101
|
+
isDebug?: boolean;
|
|
102
|
+
/** When true, all SDK methods become no-ops. Useful for disabling in specific environments. */
|
|
103
|
+
isDisabled?: boolean;
|
|
104
|
+
/** Typed bucket names for bucket accessor methods */
|
|
105
|
+
buckets?: readonly string[];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Gunsole client for sending logs and events
|
|
110
|
+
*/
|
|
111
|
+
declare class GunsoleClient<Tags extends Record<string, string> & ValidTagSchema = Record<string, string>> {
|
|
112
|
+
private config;
|
|
113
|
+
private transport;
|
|
114
|
+
private batch;
|
|
115
|
+
private flushTimer;
|
|
116
|
+
private user;
|
|
117
|
+
private sessionId;
|
|
118
|
+
private globalHandlers;
|
|
119
|
+
private readonly disabled;
|
|
120
|
+
constructor(config: GunsoleClientConfig);
|
|
121
|
+
/**
|
|
122
|
+
* Log a message. Defaults to info level.
|
|
123
|
+
*/
|
|
124
|
+
log(options: LogOptions<Tags>): void;
|
|
125
|
+
log(level: LogLevel, options: LogOptions<Tags>): void;
|
|
126
|
+
/**
|
|
127
|
+
* Log an info-level message
|
|
128
|
+
*/
|
|
129
|
+
info(options: LogOptions<Tags>): void;
|
|
130
|
+
debug(options: LogOptions<Tags>): void;
|
|
131
|
+
warn(options: LogOptions<Tags>): void;
|
|
132
|
+
error(options: LogOptions<Tags>): void;
|
|
133
|
+
/**
|
|
134
|
+
* Set user information
|
|
135
|
+
*/
|
|
136
|
+
setUser(user: UserInfo): void;
|
|
137
|
+
/**
|
|
138
|
+
* Set session ID
|
|
139
|
+
*/
|
|
140
|
+
setSessionId(sessionId: string): void;
|
|
141
|
+
/**
|
|
142
|
+
* Flush pending logs to the API
|
|
143
|
+
*/
|
|
144
|
+
flush(): Promise<void>;
|
|
145
|
+
/**
|
|
146
|
+
* Attach global error handlers
|
|
147
|
+
*/
|
|
148
|
+
attachGlobalErrorHandlers(): void;
|
|
149
|
+
/**
|
|
150
|
+
* Detach global error handlers
|
|
151
|
+
*/
|
|
152
|
+
detachGlobalErrorHandlers(): void;
|
|
153
|
+
/**
|
|
154
|
+
* Start the automatic flush timer
|
|
155
|
+
*/
|
|
156
|
+
private startFlushTimer;
|
|
157
|
+
/**
|
|
158
|
+
* Stop the automatic flush timer
|
|
159
|
+
*/
|
|
160
|
+
private stopFlushTimer;
|
|
161
|
+
/**
|
|
162
|
+
* Cleanup resources. Awaiting ensures remaining logs are flushed.
|
|
163
|
+
*/
|
|
164
|
+
destroy(): Promise<void>;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Log options for bucket methods (message is positional, bucket is implied)
|
|
169
|
+
*/
|
|
170
|
+
type BucketLogOptions<Tags extends Record<string, string> = Record<string, string>> = Omit<LogOptions<Tags>, "bucket" | "message">;
|
|
171
|
+
/**
|
|
172
|
+
* A callable bucket logger with level sub-methods
|
|
173
|
+
*/
|
|
174
|
+
interface BucketLogger<Tags extends Record<string, string> = Record<string, string>> {
|
|
175
|
+
(message: string, options?: BucketLogOptions<Tags>): void;
|
|
176
|
+
info(message: string, options?: BucketLogOptions<Tags>): void;
|
|
177
|
+
debug(message: string, options?: BucketLogOptions<Tags>): void;
|
|
178
|
+
warn(message: string, options?: BucketLogOptions<Tags>): void;
|
|
179
|
+
error(message: string, options?: BucketLogOptions<Tags>): void;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Mapped type that adds bucket accessors to a client
|
|
183
|
+
*/
|
|
184
|
+
type WithBuckets<Tags extends Record<string, string> = Record<string, string>, Buckets extends string = string> = {
|
|
185
|
+
[K in Buckets]: BucketLogger<Tags>;
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* Bucket names that conflict with GunsoleClient methods
|
|
189
|
+
*/
|
|
190
|
+
type ReservedBucketName = "log" | "info" | "debug" | "warn" | "error" | "setUser" | "setSessionId" | "flush" | "destroy" | "attachGlobalErrorHandlers" | "detachGlobalErrorHandlers";
|
|
191
|
+
/**
|
|
192
|
+
* Validates a buckets tuple at the type level — reserved names become `never`
|
|
193
|
+
*/
|
|
194
|
+
type ValidateBuckets<T extends readonly string[]> = {
|
|
195
|
+
[K in keyof T]: T[K] extends ReservedBucketName ? never : T[K];
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Config without buckets — used for overload resolution so that
|
|
200
|
+
* a config with `buckets` falls through to the validated overload.
|
|
201
|
+
*/
|
|
202
|
+
type BaseConfig = Omit<GunsoleClientConfig, "buckets">;
|
|
203
|
+
/**
|
|
204
|
+
* Create a new Gunsole client instance
|
|
205
|
+
*
|
|
206
|
+
* @param config - Client configuration
|
|
207
|
+
* @returns Gunsole client instance
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```ts
|
|
211
|
+
* const gunsole = createGunsoleClient({
|
|
212
|
+
* projectId: "my-project",
|
|
213
|
+
* apiKey: "my-api-key",
|
|
214
|
+
* mode: "cloud",
|
|
215
|
+
* buckets: ["payment", "auth"],
|
|
216
|
+
* });
|
|
217
|
+
*
|
|
218
|
+
* gunsole.payment("User paid");
|
|
219
|
+
* gunsole.auth.error("Login failed");
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
declare function createGunsoleClient<Tags extends Record<string, string> & ValidTagSchema = Record<string, string>>(config: BaseConfig): GunsoleClient<Tags>;
|
|
223
|
+
declare function createGunsoleClient<Tags extends Record<string, string> & ValidTagSchema = Record<string, string>, const Buckets extends readonly string[] = readonly string[]>(config: BaseConfig & {
|
|
224
|
+
buckets: Buckets & NoInfer<ValidateBuckets<Buckets>>;
|
|
225
|
+
}): GunsoleClient<Tags> & WithBuckets<Tags, Buckets[number]>;
|
|
226
|
+
|
|
227
|
+
export { type BucketLogOptions, type BucketLogger, type ClientMode, type FetchFunction, GunsoleClient, type GunsoleClientConfig, type LogEntry, type LogLevel, type LogOptions, type ReservedBucketName, type ReservedTagKey, type TagEntry, type UserInfo, type ValidTagSchema, type ValidateBuckets, type WithBuckets, createGunsoleClient };
|