@configdirector/client-sdk 0.1.6 → 0.1.7

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.
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`eventsource-client`);var t=class{constructor(){this.handlerMap=new Map}on(e,t){let n=this.handlerMap.get(e);n?n.push(t):this.handlerMap.set(e,[t])}once(e,t){let n=this;function r(i){n.off(e,r),t.apply(n,i)}this.on(e,r)}off(e,t){let n=this.handlerMap.get(e);if(n)if(t){let e=n.indexOf(t);e>=0&&n.splice(e,1)}else this.handlerMap.set(e,[])}clear(){this.handlerMap.clear()}emit(e,t){let n=this.handlerMap.get(e);n&&n.slice().map(e=>e(t))}},n=class e extends Error{constructor(t,n){super(t),this.name=`ConfigDirectorConnectionError`,this.status=n,Object.setPrototypeOf(this,e.prototype)}},r=class e extends Error{constructor(t){super(t),this.name=`ConfigDirectorValidationError`,Object.setPrototypeOf(this,e.prototype)}};const i=e=>{if(e instanceof DOMException){if(e.name===`NotAllowedError`)return!0}else if(e instanceof TypeError)return!0;return!1};var a=class{constructor(e){this.options=e,this.eventEmitter=new t,this.options=e,this.logger=e.logger,this.url=new URL(`sse/v1`,e.baseUrl)}async connect(t,n){this.eventSource&&this.close();let r,i,a=async(e,t)=>{let n=await fetch(e,t);return r=n.status,n.ok||(i=await n.text()),n},o=new Promise((n,o)=>{this.eventSource=(0,e.createEventSource)({url:this.url,fetch:a,method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({givenContext:t,metaContext:this.options.metaContext,clientSdkKey:this.options.clientSdkKey}),onMessage:({data:e})=>{this.dispatchMessage(e)},onConnect:()=>{r&&this.isStatusFatal(r)?(this.close(),o(this.prepareFatalError(r,i))):(this.logger.debug(`[EventSourceTransport] Connected, status: %s`,r),n(this))},onScheduleReconnect:e=>{r&&this.isStatusFatal(r)?(this.close(),o(this.prepareFatalError(r,i))):this.logger.warn(`[EventSourceTransport] Scheduling reconnect in ${e.delay}. Response status: ${r}`)},onDisconnect:()=>{this.logger.debug(`[EventSourceTransport] Disconnected`)}})});return Promise.race([o,new Promise(e=>{setTimeout(()=>e(this),n)})])}dispatchMessage(e){try{let t=JSON.parse(e);this.eventEmitter.emit(`configSetReceived`,t)}catch(e){this.logger.error(`[EventSourceTransport] Error parsing and dispatching config data update: `,e)}}prepareFatalError(e,t){let r=e??0;return new n(`${`Connection failed with status: ${e??`unknown`}`}${(t?.trim()?.length??0)>0?` (${t})`:``}. This is an unrecoverable error, will not attempt to reconnect.`,r)}isStatusFatal(e){return!!e&&e>=400&&e<500}on(e,t){this.eventEmitter.on(e,t)}off(e,t){this.eventEmitter.off(e,t)}clear(){this.eventEmitter.clear()}close(){this.eventSource?.close()}dispose(){this.close(),this.clear()}};const o=e=>{let t=typeof e;if(t===`object`)try{return e.constructor?.name??t}catch{return t}else if(t===`function`)try{let n=e.name;return n?`function: ${n}`:t}catch{return t}return t},s=e=>e===`number`||e===`bigint`,c=(e,t)=>{let n=e.value,r=o(t);if(!n)return{parsedValue:t,requestedType:r,usedDefault:!0,reason:`value-missing`};if(typeof t==`string`)return{parsedValue:n,requestedType:r,usedDefault:!1,reason:`found-match`};if(typeof t==`boolean`&&e.type===`boolean`){let e=l(n),i=typeof e==`boolean`;return{parsedValue:i?e:t,requestedType:r,usedDefault:!i,reason:i?`found-match`:`invalid-boolean`}}if(s(typeof t)&&e.type===`integer`){let e=u(n),i=typeof e==`number`;return{parsedValue:i?e:t,requestedType:r,usedDefault:!i,reason:i?`found-match`:`invalid-number`}}if(s(typeof t)&&(e.type===`float`||e.type===`enum`)){let e=d(n),i=typeof e==`number`;return{parsedValue:i?e:t,requestedType:r,usedDefault:!i,reason:i?`found-match`:`invalid-number`}}return{parsedValue:n,requestedType:r,usedDefault:!1,reason:`found-match`}},l=e=>{if(!e)return;let t=e.toLowerCase();if(!(t!=`true`&&t!=`false`))return t===`true`},u=e=>{if(!e)return;let t=Number.parseInt(e);if(!(isNaN(t)||!isFinite(t)))return t},d=e=>{if(!e)return;let t=Number.parseFloat(e);if(!(isNaN(t)||!isFinite(t)))return t},f={off:-1,error:0,warn:1,info:2,debug:3},p=()=>{let e={year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,timeZoneName:`short`};try{return new Intl.DateTimeFormat(void 0,{...e,fractionalSecondDigits:3})}catch{return new Intl.DateTimeFormat(void 0,e)}};var m=class{constructor(e,t){this.level=e,this.decorator=t,this.level=e,this.decorator=t,this.dateFormatter=p()}debug(e,...t){this.log(console.debug,`debug`,e,...t)}info(e,...t){this.log(console.info,`info`,e,...t)}warn(e,...t){this.log(console.warn,`warn`,e,...t)}error(e,...t){this.log(console.error,`error`,e,...t)}log(e,t,n,...r){f[this.level]>=f[t]&&e(`[${this.dateFormatter.format(new Date)}] ${this.decorator?.decorateMessage(n)}`,...r)}},h=class{decorateMessage(e){return`[ConfigDirector:js-client-sdk] ${e}`}};const g=(e,t)=>new m(e??`warn`,t??new h);var _=class{aggregate(e){if(e.events.length==0)return[];let t=new Map;for(let n of e.events){let e=JSON.stringify(n),r=t.get(e)?.count||0;t.set(e,{event:n,count:r+1})}return Array.from(t).map(([,t])=>({startTime:e.startTime,endTime:e.endTime,count:t.count,event:t.event}))}},v=class{constructor(e){this._events=[],this._droppedEventCount=0,this.limit=e??1e3}get events(){return this._events}get reachedLimit(){return this._events.length>=this.limit}get droppedEventCount(){return this._droppedEventCount}push(...e){this.startTime||=new Date;let t=Math.max(0,e.length-this.limit),n=e.slice(t,e.length);if(this._droppedEventCount+=t,this._events.length+n.length>this.limit){let e=this._events.length+n.length-this.limit;this._events.splice(0,e),this._droppedEventCount+=e}return this._events.push(...n)}takeSnapshot(){let e=new Date,t=this.startTime??e,n=this._events.splice(0),r=this._droppedEventCount;return this.startTime=void 0,this._droppedEventCount=0,{startTime:t,endTime:e,events:n,droppedCount:r}}clear(){this._events=[],this.startTime=void 0,this._droppedEventCount=0}},y=class{constructor(e){this.executeRequests=!0,this.sdkKey=e.sdkKey,this.logger=e.logger,this.url=new URL(`telemetry/v1`,e.baseUrl)}report({discreteEvents:e,aggregatedEvents:t,droppedEvents:n}){if(!this.executeRequests)return{success:!1,fatalError:!0};let r={clientSdkKey:this.sdkKey,discreteEvents:e,aggregatedEvents:t,droppedEvents:n};if(this.isReportEmpty(r))return{success:!0,fatalError:!1};let i=this.sendReport(r);return i.fatalError&&(this.executeRequests=!1),i}isReportEmpty(e){return this.isEventListEmpty(e.discreteEvents)&&this.isEventListEmpty(e.aggregatedEvents)&&this.isDroppedEventsEmpty(e.droppedEvents)}isDroppedEventsEmpty(e){if(!e)return!0;let t=Object.keys(e);if(t.length==0)return!0;for(let n of t)if((e[n]??0)>0)return!1;return!0}isEventListEmpty(e){let t=Object.keys(e);if(t.length==0)return!0;for(let n of t)if((e[n]?.length??0)>0)return!1;return!0}sendReport(e){try{return{success:navigator.sendBeacon(this.url,JSON.stringify(e)),fatalError:!1}}catch(e){return this.logger.warn(`[EventReporter] Fatal error attempting to send telemetry data: ${e}. No more telemetry data will be sent.`),{success:!1,fatalError:!0}}}};const b=e=>x(new TextEncoder().encode(e)).toString(16).padStart(8,`0`),x=e=>{let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t+e[n],t>>>=0;return t};var S=class{constructor(e){this.evaluationEventQueue=new v,this.aggregator=new _,this.collectEvents=!0,this.logger=e.logger,this.reporter=new y(e),this.flushIntervalDelay=3e4,this.flushTimeout=setTimeout(()=>this.flushAndScheduleNext(),5e3);try{document.addEventListener(`visibilitychange`,()=>{document.visibilityState===`hidden`&&this.flush()})}catch(e){this.logger.warn(`[TelemetryEventCollector] Could not configure 'visibilitychange' listener: `,e)}}evaluatedConfig(e){this.collectEvents&&this.evaluationEventQueue.push(this.sanitizeEvaluatedConfigEvent(e))}sanitizeEvaluatedConfigEvent(e){return{key:e.key,type:e.type,defaultValue:this.sanitizeValue(e.defaultValue,e.type),requestedType:e.requestedType,evaluatedValue:this.sanitizeValue(e.evaluatedValue,e.type),usedDefault:e.usedDefault,evaluationReason:e.evaluationReason}}sanitizeValue(e,t){if(t===`json`)try{return b(JSON.stringify(e))}catch{return e.toString().slice(0,500)}return e.toString().slice(0,500)}flushAndScheduleNext(){this.flush().fatalError?(this.collectEvents=!1,this.close(),this.logger.warn(`[TelemetryEventCollector] Received a fatal error from telemetry collection. No longer collecting events.`)):this.flushTimeout=setTimeout(()=>this.flushAndScheduleNext(),this.flushIntervalDelay)}flush(){let e=this.evaluationEventQueue.takeSnapshot();return this.reporter.report({discreteEvents:{},aggregatedEvents:{evaluatedConfig:this.aggregator.aggregate(e)},droppedEvents:{evaluatedConfig:e.droppedCount}})}close(){this.collectEvents=!1,clearTimeout(this.flushTimeout),this.flush(),this.evaluationEventQueue.clear()}dispose(){this.close()}};const C=async(e,t,n,r)=>{let i=new AbortController,a=setTimeout(()=>{r.debug(`[fetchWithTimeout] Reached timeout, aborting request`),i.abort()},e);try{let e=await fetch(t,{...n,signal:i.signal});return clearTimeout(a),e}catch(e){throw r.warn(`[fetchWithTimeout] Fetch error: `,e),clearTimeout(a),e}};var w=class{constructor(e){this.options=e,this.eventEmitter=new t,this.fatalError=!1,this.options=e,this.logger=e.logger,this.url=new URL(`pull/v1`,e.baseUrl)}async connect(e,t){if(this.fatalError)return this.logger.warn(`[PullTransport] There was a prior unrecoverable error. Ignoring attempt to reconnect.`),this;try{let r=await C(t,this.url,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({givenContext:e,metaContext:this.options.metaContext,clientSdkKey:this.options.clientSdkKey})},this.logger);if(!r.ok)throw this.isStatusFatal(r.status)?(this.fatalError=!0,this.prepareFatalResponseStatusError(r.status,await r.text())):new n(`Connection failed with status: ${r.status}`,r.status);let i=JSON.parse(await r.text());return this.eventEmitter.emit(`configSetReceived`,i),this}catch(e){throw i(e)?(this.fatalError=!0,new n(`Connection failed with fatal error: ${e}. This is an unrecoverable error, retry attempts will be ignored.`)):e instanceof SyntaxError?new n(`Failed to parse the response from the server: ${e}`):new n(`Connection failed with error: ${e}.`)}}prepareFatalResponseStatusError(e,t){let r=e??0;return new n(`${`Connection failed with status: ${e??`unknown`}`}${(t?.trim()?.length??0)>0?` (${t})`:``}. This is an unrecoverable error, retry attempts will be ignored.`,r)}isStatusFatal(e){return!!e&&e>=400&&e<500}on(e,t){this.eventEmitter.on(e,t)}off(e,t){this.eventEmitter.off(e,t)}clear(){this.eventEmitter.clear()}close(){}dispose(){this.close(),this.clear()}};const T=new URL(`https://client-sdk-api.configdirector.com`);var E=class{constructor(e,n,r){this.handlersMap=new Map,this.eventEmitter=new t,this.ready=!1,this.logger=r?.logger??g(),this.timeout=r?.connection?.timeout??3e3;let i=this.parseUrl(r?.connection?.url)??T;this.streaming=r?.connection?.streaming!==!1;let o=this.streaming?a:w;this.usageEventCollector=new S({sdkKey:e,logger:this.logger,baseUrl:i}),this.transport=new o({clientSdkKey:e,baseUrl:i,metaContext:{...r?.metadata,sdkName:n.sdkName,sdkVersion:n.sdkVersion,userAgent:navigator?.userAgent},logger:this.logger}),this.transport.on(`configSetReceived`,e=>{this.readyResolve?.();let t=Object.keys(e.configs);!this.configSet||e.kind==`full`?(this.configSet=e,this.eventEmitter.emit(`configsUpdated`,{keys:t}),this.updateWatchers(e.configs)):(this.configSet.configs={...this.configSet.configs,...e.configs},this.eventEmitter.emit(`configsUpdated`,{keys:t}),this.updateWatchers(e.configs)),this.logger.debug(`[ConfigDirectorClient] ConfigSet updated from server:`,{keys:t})})}async initialize(e){await this.connectToTransport(e,`initialization`)}async updateContext(e){await this.connectToTransport(e,`context update`)}async connectToTransport(e,t){try{this.ready=!1,this.readyPromise=new Promise(e=>{this.readyResolve=e}).then(()=>{this.ready=!0,this.eventEmitter.emit(`clientReady`,{action:t}),this.logger.debug(`[ConfigDirectorClient] Received initial payload from the server, client is ready`)});let n=new Date().getTime();await this.transport.connect(e??{},this.timeout),this.currentContext=e;let r=new Date().getTime()-n,i=this.timeout-r;if(i>0&&await Promise.race([this.readyPromise,new Promise(e=>{setTimeout(()=>e(),i)})]),!this.ready){let e=this.streaming?`The client will continue to retry since there were no fatal errors detected. Configs will return the default value until the connection succeeds.`:`Since the client was configured without streaming, configs may not update and always return the default value.`;this.logger.warn(`[ConfigDirectorClient] Timed out waiting for ${t} after ${this.timeout}ms. ${e}`)}}catch(e){this.logger.error(`[ConfigDirectorClient] An error occurred during ${t}: `,e)}}updateWatchers(e){Object.values(e).forEach(e=>this.updateWatchersForConfig(e))}updateWatchersForConfig(e){this.handlersMap.get(e.key)?.forEach(t=>{let n=this.getValueFromConfigState(e.key,e,t.defaultValue);t.handler(n)})}watch(e,t,n){this.validateDefaultValue(t);let r=this.handlersMap.get(e),i={handler:n,defaultValue:t,requestedType:typeof t};return r?r.push(i):this.handlersMap.set(e,[i]),()=>this.unwatch(e,n)}unwatch(e,t){let n=this.handlersMap.get(e);if(n)if(t){let e=n.findIndex(e=>e.handler==t);e>=0&&n?.splice(e,1)}else n.splice(0)}getValue(e,t){this.validateDefaultValue(t);let n=this.configSet?.configs[e];return this.getValueFromConfigState(e,n,t)}getValueFromConfigState(e,t,n){if(!t)return this.logger.debug(`[ConfigDirectorClient] No config state found for '${e}', returning default value '${n}'`),this.usageEventCollector.evaluatedConfig({contextId:this.currentContext?.id,key:e,defaultValue:n,requestedType:o(n),evaluatedValue:n,usedDefault:!0,evaluationReason:`config-state-missing`}),n;let r=c(t,n);return this.usageEventCollector.evaluatedConfig({contextId:this.currentContext?.id,key:e,defaultValue:n,requestedType:r.requestedType,evaluatedValue:r.parsedValue,usedDefault:r.usedDefault,evaluationReason:r.reason}),this.logger.debug(`[ConfigDirectorClient] Evaluated '${e}' to '${r.parsedValue}'`),r.parsedValue}parseUrl(e){if(e)try{return new URL(e)}catch(t){throw new r(`Invalid base URL '${e}'. Parsing failed: ${t}`)}}validateDefaultValue(e){if(e==null)throw new r(`Invalid default value. The default value for a config must be defined and non-null.`);if(typeof e==`function`)throw new r(`Invalid default value. The default value for a config cannot be a function.`)}get isReady(){return this.ready}on(e,t){this.eventEmitter.on(e,t)}off(e,t){this.eventEmitter.off(e,t)}clear(){this.logger.debug(`[ConfigDirectorClient] clear() has been called, removing all observers`),this.eventEmitter.clear(),this.handlersMap.clear()}unwatchAll(){this.handlersMap.clear()}close(){this.logger.debug(`[ConfigDirectorClient] close() has been called, closing connection to server`),this.transport.close(),this.ready=!1}dispose(){this.clear(),this.close()}};const D=(e,t)=>new E(e,{sdkName:`js-client-sdk`,sdkVersion:`0.1.7`},t),O=(e,t)=>g(e,t);exports.createClient=D,exports.createConsoleLogger=O;
@@ -0,0 +1,242 @@
1
+ //#region ../js-client-core/src/Emitter.d.ts
2
+ type EventType = string | symbol;
3
+ type EventsRecord = Record<EventType, any>;
4
+ type Handler<TEventsRecord extends EventsRecord, TKey extends keyof TEventsRecord> = (payload: TEventsRecord[TKey]) => void;
5
+ interface EventProvider<TEventsRecord extends EventsRecord> {
6
+ on<TName extends keyof TEventsRecord>(name: TName, handler: Handler<TEventsRecord, TName>): void;
7
+ off<TName extends keyof TEventsRecord>(name: TName, handler?: Handler<TEventsRecord, TName>): void;
8
+ clear(): void;
9
+ }
10
+ //#endregion
11
+ //#region ../js-client-core/src/types.d.ts
12
+ type ConfigEnumLikeType = {
13
+ [key: string]: string | number;
14
+ };
15
+ type ConfigValueType = string | number | boolean | object | ConfigEnumLikeType;
16
+ type ConfigDirectorLoggingLevel = "debug" | "info" | "warn" | "error" | "off";
17
+ interface ConfigDirectorLogger {
18
+ debug(message: string, ...args: any): void;
19
+ info(message: string, ...args: any): void;
20
+ warn(message: string, ...args: any): void;
21
+ error(message: string, ...args: any): void;
22
+ }
23
+ interface ConfigDirectorLogMessageDecorator {
24
+ decorateMessage(message: string): string;
25
+ }
26
+ /**
27
+ * The user's context to be sent to ConfigDirector. This context will be used for targeting
28
+ * rules evaluation.
29
+ */
30
+ type ConfigDirectorContext = {
31
+ /**
32
+ * The user's identifier. This should be a value that uniquely identifies an application
33
+ * user.
34
+ * In the case of anonymous users, you could generate a UUID or alternatively not provide
35
+ * the {@link id} and the SDK will generate a random UUID. However, keep in mind that this
36
+ * value is used for segmenting users in percentage rollouts, and changes to the {@link id}
37
+ * could result in the user being assigned to a different percentile.
38
+ */
39
+ id?: string;
40
+ /**
41
+ * The user's display name. This will be shown in the ConfigDirector dashboard and may be
42
+ * used for targeting rules.
43
+ */
44
+ name?: string;
45
+ /**
46
+ * Any arbitrary traits for the current user. They will be shown in the ConfigDirector
47
+ * dashboard and may be used for targeting rules.
48
+ */
49
+ traits?: {
50
+ [key: string]: unknown;
51
+ };
52
+ };
53
+ /**
54
+ * Configuration options for the {@link ConfigDirectorClient}
55
+ */
56
+ type ConfigDirectorClientOptions = {
57
+ /**
58
+ * Application metadata that remains constant through the lifetime of the connection
59
+ */
60
+ metadata?: {
61
+ appVersion?: string;
62
+ appName?: string;
63
+ };
64
+ /**
65
+ * Connection options
66
+ */
67
+ connection?: {
68
+ /**
69
+ * Whether to open a streaming connection or use a one-time pull of configuration state.
70
+ * If set to true, the streaming connection will remain open and receive updates whenever
71
+ * config state is updated on the ConfigDirector dashboard.
72
+ * When set to false, there will be an initial request to retrieve config state during
73
+ * initialization, and an additional request whenever {@link ConfigDirectorClient.updateContext}
74
+ * is called. But not updates will be received after those requests.
75
+ *
76
+ * Defaults to true (streaming connection)
77
+ */
78
+ streaming?: boolean;
79
+ /**
80
+ * The timeout, in milliseconds, to be used in initialization and when updating the context.
81
+ * If streaming is enabled, the operation (initialization or context update) may still succeed
82
+ * after it times out if no unrecoverable errors are encountered (like an invalid SDK key).
83
+ * If streaming is disabled, if the operation times out, it will not be retried.
84
+ */
85
+ timeout?: number;
86
+ /**
87
+ * The base URL to the ConfigDirector SDK server. To be used only when needing to route through a
88
+ * proxy to connect to the ConfigDirector SDK server. Please refer to the docs on how to configure
89
+ * a proxy for the client SDK.
90
+ */
91
+ url?: string;
92
+ };
93
+ /**
94
+ * A logger that implements {@link ConfigDirectorLogger}. It defaults to the ConfigDirector console
95
+ * logger set to 'warn' level.
96
+ *
97
+ * The log level of the default logger can be adjusted by creating a default logger with the desired
98
+ * level and providing it in this property:
99
+ * @example
100
+ * import { createClient, createConsoleLogger } from "@configdirector/client-sdk";
101
+ * const client = createClient(
102
+ * "YOUR-SDK-KEY",
103
+ * { logger: createConsoleLogger("debug") },
104
+ * );
105
+ */
106
+ logger?: ConfigDirectorLogger;
107
+ };
108
+ type ClientConnectAction = "initialization" | "context update";
109
+ type ClientEvents = {
110
+ configsUpdated: {
111
+ keys: string[];
112
+ };
113
+ clientReady: {
114
+ action: ClientConnectAction;
115
+ };
116
+ };
117
+ type WatchHandler<T extends ConfigValueType> = (message: T) => void;
118
+ /**
119
+ * The ConfigDirector SDK client object.
120
+ *
121
+ * Applications should create a single instance of `ConfigDirectorClient`, and call
122
+ * {@link initialize} during application initialization.
123
+ *
124
+ * After initialization, to update the user's context, so that targeting rules are evaluated
125
+ * with the updated context, call {@link updateContext}.
126
+ */
127
+ interface ConfigDirectorClient extends EventProvider<ClientEvents> {
128
+ /**
129
+ * Initializes the connection to ConfigDirector to retrieve config evaluations. Until
130
+ * initialization is successful, all flags will return their default value provided to
131
+ * {@link watch} or {@link getValue}.
132
+ *
133
+ * If the connection fails or is interrupted with a transient error (network error,
134
+ * internal server error, etc) the client will continue to attempt to connect. However,
135
+ * if the connection fails with a persistent error, like an invalid SDK key, the client will
136
+ * not attempt to re-connect and an error will be logged to the console or the provided
137
+ * logger.
138
+ *
139
+ * @param context The current user's context to be used for evaluating targeting rules (optional).
140
+ */
141
+ initialize(context?: ConfigDirectorContext): Promise<void>;
142
+ /**
143
+ * Updates the user's context and re-evaluates all config and flag values based on the new context.
144
+ *
145
+ * @param context The current user's context to be used for evaluating targeting rules (required).
146
+ */
147
+ updateContext(context: ConfigDirectorContext): Promise<void>;
148
+ /**
149
+ * Returns whether or not the client is ready after calling {@link initialize} or {@link updateContext}
150
+ *
151
+ * The definition of ready is that the connection to the server was successful, and config state
152
+ * was received.
153
+ */
154
+ get isReady(): boolean;
155
+ /**
156
+ * Evaluates a config and returns its value based on the current context and targeting rules
157
+ *
158
+ * @returns The evaluated config value, or the `defaultValue` if the config state was unavailable
159
+ * @param configKey The config key to evaluate
160
+ * @param defaultValue The default value to be returned if the config state is unavailable. For
161
+ * example, if the client cannot connect to the server due to network conditions, or if getValue
162
+ * is called before initialization is done.
163
+ */
164
+ getValue<T extends ConfigValueType>(configKey: string, defaultValue: T): T;
165
+ /**
166
+ * Watches for changes to a a config evaluation value. Whenever the config value changes, the
167
+ * provided callback function will be called with the new value. Changes can happen due to updates
168
+ * to the config in the ConfigDirector dashboard, or if the context is updated via {@link updateContext}.
169
+ *
170
+ * @returns An 'unwatch' function that can be called to remove the subscriber
171
+ *
172
+ * @param configKey The config key to watch
173
+ * @param defaultValue The default value to be referenced if the config state is unavailable
174
+ * @param callback The callback function to be called whenever the config value is updated
175
+ */
176
+ watch<T extends ConfigValueType>(configKey: string, defaultValue: T, callback: WatchHandler<T>): () => void;
177
+ /**
178
+ * Removes a particular subscriber to the given `configKey`, or all subscribers if no callback
179
+ * is provided.
180
+ *
181
+ * @param configKey The config key to remove subscribers from
182
+ * @param callback The subscriber to be removed. If not provided, all subscribers are removed for
183
+ * the given `configKey`.
184
+ */
185
+ unwatch<T extends ConfigValueType>(configKey: string, callback?: WatchHandler<T>): void;
186
+ /**
187
+ * Removes all subscribers from all config keys
188
+ */
189
+ unwatchAll(): void;
190
+ /**
191
+ * Disposes of the client. All connections are closed, and all event and config key subscribers
192
+ * are removed.
193
+ *
194
+ * Intended to be called when your application shuts down
195
+ */
196
+ dispose(): void;
197
+ }
198
+ //#endregion
199
+ //#region ../js-client-core/src/logger.d.ts
200
+ declare class DefaultConsoleLogger implements ConfigDirectorLogger {
201
+ private readonly level;
202
+ private readonly decorator;
203
+ private readonly dateFormatter;
204
+ constructor(level: ConfigDirectorLoggingLevel, decorator: ConfigDirectorLogMessageDecorator);
205
+ debug(message: string, ...args: any): void;
206
+ info(message: string, ...args: any): void;
207
+ warn(message: string, ...args: any): void;
208
+ error(message: string, ...args: any): void;
209
+ private log;
210
+ }
211
+ //#endregion
212
+ //#region ../js-client-core/src/errors.d.ts
213
+ declare class ConfigDirectorConnectionError extends Error {
214
+ readonly name: string;
215
+ readonly status?: number;
216
+ constructor(message: string, status?: number);
217
+ }
218
+ declare class ConfigDirectorValidationError extends Error {
219
+ readonly name: string;
220
+ constructor(message: string);
221
+ }
222
+ //#endregion
223
+ //#region src/api.d.ts
224
+ /**
225
+ * Creates a `ConfigDirectorClient` object with the given `clientSdkKey` and optional
226
+ * `clientOptions`. The returned client needs to be initialized before it is ready to serve
227
+ * config values.
228
+ *
229
+ * @param clientSdkKey The client SDK key obtained from the ConfigDirector dashboard
230
+ * @param clientOptions {@link ConfigDirectorClientOptions} options for the client (optional)
231
+ * @returns A {@link ConfigDirectorClient} object
232
+ *
233
+ * @example
234
+ * import { createClient } from "@configdirector/client-sdk";
235
+ * const client = createClient("YOUR-SDK-KEY");
236
+ * await client.initialize();
237
+ */
238
+ declare const createClient: (clientSdkKey: string, clientOptions?: ConfigDirectorClientOptions) => ConfigDirectorClient;
239
+ declare const createConsoleLogger: (level: ConfigDirectorLoggingLevel, messageDecorator?: ConfigDirectorLogMessageDecorator) => DefaultConsoleLogger;
240
+ //#endregion
241
+ export { type ConfigDirectorClient, type ConfigDirectorClientOptions, type ConfigDirectorConnectionError, type ConfigDirectorContext, type ConfigDirectorLogMessageDecorator, type ConfigDirectorLogger, type ConfigDirectorLoggingLevel, type ConfigDirectorValidationError, type ConfigValueType, createClient, createConsoleLogger };
242
+ //# sourceMappingURL=configdirector-client.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configdirector-client.d.cts","names":[],"sources":["../../js-client-core/src/Emitter.ts","../../js-client-core/src/types.ts","../../js-client-core/src/logger.ts","../../js-client-core/src/errors.ts","../src/api.ts"],"mappings":";KAAK,SAAA;AAAA,KACA,YAAA,GAAe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,GAAmB,iCAAA,KAAiC,oBAAA"}
@@ -0,0 +1,242 @@
1
+ //#region ../js-client-core/src/Emitter.d.ts
2
+ type EventType = string | symbol;
3
+ type EventsRecord = Record<EventType, any>;
4
+ type Handler<TEventsRecord extends EventsRecord, TKey extends keyof TEventsRecord> = (payload: TEventsRecord[TKey]) => void;
5
+ interface EventProvider<TEventsRecord extends EventsRecord> {
6
+ on<TName extends keyof TEventsRecord>(name: TName, handler: Handler<TEventsRecord, TName>): void;
7
+ off<TName extends keyof TEventsRecord>(name: TName, handler?: Handler<TEventsRecord, TName>): void;
8
+ clear(): void;
9
+ }
10
+ //#endregion
11
+ //#region ../js-client-core/src/types.d.ts
12
+ type ConfigEnumLikeType = {
13
+ [key: string]: string | number;
14
+ };
15
+ type ConfigValueType = string | number | boolean | object | ConfigEnumLikeType;
16
+ type ConfigDirectorLoggingLevel = "debug" | "info" | "warn" | "error" | "off";
17
+ interface ConfigDirectorLogger {
18
+ debug(message: string, ...args: any): void;
19
+ info(message: string, ...args: any): void;
20
+ warn(message: string, ...args: any): void;
21
+ error(message: string, ...args: any): void;
22
+ }
23
+ interface ConfigDirectorLogMessageDecorator {
24
+ decorateMessage(message: string): string;
25
+ }
26
+ /**
27
+ * The user's context to be sent to ConfigDirector. This context will be used for targeting
28
+ * rules evaluation.
29
+ */
30
+ type ConfigDirectorContext = {
31
+ /**
32
+ * The user's identifier. This should be a value that uniquely identifies an application
33
+ * user.
34
+ * In the case of anonymous users, you could generate a UUID or alternatively not provide
35
+ * the {@link id} and the SDK will generate a random UUID. However, keep in mind that this
36
+ * value is used for segmenting users in percentage rollouts, and changes to the {@link id}
37
+ * could result in the user being assigned to a different percentile.
38
+ */
39
+ id?: string;
40
+ /**
41
+ * The user's display name. This will be shown in the ConfigDirector dashboard and may be
42
+ * used for targeting rules.
43
+ */
44
+ name?: string;
45
+ /**
46
+ * Any arbitrary traits for the current user. They will be shown in the ConfigDirector
47
+ * dashboard and may be used for targeting rules.
48
+ */
49
+ traits?: {
50
+ [key: string]: unknown;
51
+ };
52
+ };
53
+ /**
54
+ * Configuration options for the {@link ConfigDirectorClient}
55
+ */
56
+ type ConfigDirectorClientOptions = {
57
+ /**
58
+ * Application metadata that remains constant through the lifetime of the connection
59
+ */
60
+ metadata?: {
61
+ appVersion?: string;
62
+ appName?: string;
63
+ };
64
+ /**
65
+ * Connection options
66
+ */
67
+ connection?: {
68
+ /**
69
+ * Whether to open a streaming connection or use a one-time pull of configuration state.
70
+ * If set to true, the streaming connection will remain open and receive updates whenever
71
+ * config state is updated on the ConfigDirector dashboard.
72
+ * When set to false, there will be an initial request to retrieve config state during
73
+ * initialization, and an additional request whenever {@link ConfigDirectorClient.updateContext}
74
+ * is called. But not updates will be received after those requests.
75
+ *
76
+ * Defaults to true (streaming connection)
77
+ */
78
+ streaming?: boolean;
79
+ /**
80
+ * The timeout, in milliseconds, to be used in initialization and when updating the context.
81
+ * If streaming is enabled, the operation (initialization or context update) may still succeed
82
+ * after it times out if no unrecoverable errors are encountered (like an invalid SDK key).
83
+ * If streaming is disabled, if the operation times out, it will not be retried.
84
+ */
85
+ timeout?: number;
86
+ /**
87
+ * The base URL to the ConfigDirector SDK server. To be used only when needing to route through a
88
+ * proxy to connect to the ConfigDirector SDK server. Please refer to the docs on how to configure
89
+ * a proxy for the client SDK.
90
+ */
91
+ url?: string;
92
+ };
93
+ /**
94
+ * A logger that implements {@link ConfigDirectorLogger}. It defaults to the ConfigDirector console
95
+ * logger set to 'warn' level.
96
+ *
97
+ * The log level of the default logger can be adjusted by creating a default logger with the desired
98
+ * level and providing it in this property:
99
+ * @example
100
+ * import { createClient, createConsoleLogger } from "@configdirector/client-sdk";
101
+ * const client = createClient(
102
+ * "YOUR-SDK-KEY",
103
+ * { logger: createConsoleLogger("debug") },
104
+ * );
105
+ */
106
+ logger?: ConfigDirectorLogger;
107
+ };
108
+ type ClientConnectAction = "initialization" | "context update";
109
+ type ClientEvents = {
110
+ configsUpdated: {
111
+ keys: string[];
112
+ };
113
+ clientReady: {
114
+ action: ClientConnectAction;
115
+ };
116
+ };
117
+ type WatchHandler<T extends ConfigValueType> = (message: T) => void;
118
+ /**
119
+ * The ConfigDirector SDK client object.
120
+ *
121
+ * Applications should create a single instance of `ConfigDirectorClient`, and call
122
+ * {@link initialize} during application initialization.
123
+ *
124
+ * After initialization, to update the user's context, so that targeting rules are evaluated
125
+ * with the updated context, call {@link updateContext}.
126
+ */
127
+ interface ConfigDirectorClient extends EventProvider<ClientEvents> {
128
+ /**
129
+ * Initializes the connection to ConfigDirector to retrieve config evaluations. Until
130
+ * initialization is successful, all flags will return their default value provided to
131
+ * {@link watch} or {@link getValue}.
132
+ *
133
+ * If the connection fails or is interrupted with a transient error (network error,
134
+ * internal server error, etc) the client will continue to attempt to connect. However,
135
+ * if the connection fails with a persistent error, like an invalid SDK key, the client will
136
+ * not attempt to re-connect and an error will be logged to the console or the provided
137
+ * logger.
138
+ *
139
+ * @param context The current user's context to be used for evaluating targeting rules (optional).
140
+ */
141
+ initialize(context?: ConfigDirectorContext): Promise<void>;
142
+ /**
143
+ * Updates the user's context and re-evaluates all config and flag values based on the new context.
144
+ *
145
+ * @param context The current user's context to be used for evaluating targeting rules (required).
146
+ */
147
+ updateContext(context: ConfigDirectorContext): Promise<void>;
148
+ /**
149
+ * Returns whether or not the client is ready after calling {@link initialize} or {@link updateContext}
150
+ *
151
+ * The definition of ready is that the connection to the server was successful, and config state
152
+ * was received.
153
+ */
154
+ get isReady(): boolean;
155
+ /**
156
+ * Evaluates a config and returns its value based on the current context and targeting rules
157
+ *
158
+ * @returns The evaluated config value, or the `defaultValue` if the config state was unavailable
159
+ * @param configKey The config key to evaluate
160
+ * @param defaultValue The default value to be returned if the config state is unavailable. For
161
+ * example, if the client cannot connect to the server due to network conditions, or if getValue
162
+ * is called before initialization is done.
163
+ */
164
+ getValue<T extends ConfigValueType>(configKey: string, defaultValue: T): T;
165
+ /**
166
+ * Watches for changes to a a config evaluation value. Whenever the config value changes, the
167
+ * provided callback function will be called with the new value. Changes can happen due to updates
168
+ * to the config in the ConfigDirector dashboard, or if the context is updated via {@link updateContext}.
169
+ *
170
+ * @returns An 'unwatch' function that can be called to remove the subscriber
171
+ *
172
+ * @param configKey The config key to watch
173
+ * @param defaultValue The default value to be referenced if the config state is unavailable
174
+ * @param callback The callback function to be called whenever the config value is updated
175
+ */
176
+ watch<T extends ConfigValueType>(configKey: string, defaultValue: T, callback: WatchHandler<T>): () => void;
177
+ /**
178
+ * Removes a particular subscriber to the given `configKey`, or all subscribers if no callback
179
+ * is provided.
180
+ *
181
+ * @param configKey The config key to remove subscribers from
182
+ * @param callback The subscriber to be removed. If not provided, all subscribers are removed for
183
+ * the given `configKey`.
184
+ */
185
+ unwatch<T extends ConfigValueType>(configKey: string, callback?: WatchHandler<T>): void;
186
+ /**
187
+ * Removes all subscribers from all config keys
188
+ */
189
+ unwatchAll(): void;
190
+ /**
191
+ * Disposes of the client. All connections are closed, and all event and config key subscribers
192
+ * are removed.
193
+ *
194
+ * Intended to be called when your application shuts down
195
+ */
196
+ dispose(): void;
197
+ }
198
+ //#endregion
199
+ //#region ../js-client-core/src/logger.d.ts
200
+ declare class DefaultConsoleLogger implements ConfigDirectorLogger {
201
+ private readonly level;
202
+ private readonly decorator;
203
+ private readonly dateFormatter;
204
+ constructor(level: ConfigDirectorLoggingLevel, decorator: ConfigDirectorLogMessageDecorator);
205
+ debug(message: string, ...args: any): void;
206
+ info(message: string, ...args: any): void;
207
+ warn(message: string, ...args: any): void;
208
+ error(message: string, ...args: any): void;
209
+ private log;
210
+ }
211
+ //#endregion
212
+ //#region ../js-client-core/src/errors.d.ts
213
+ declare class ConfigDirectorConnectionError extends Error {
214
+ readonly name: string;
215
+ readonly status?: number;
216
+ constructor(message: string, status?: number);
217
+ }
218
+ declare class ConfigDirectorValidationError extends Error {
219
+ readonly name: string;
220
+ constructor(message: string);
221
+ }
222
+ //#endregion
223
+ //#region src/api.d.ts
224
+ /**
225
+ * Creates a `ConfigDirectorClient` object with the given `clientSdkKey` and optional
226
+ * `clientOptions`. The returned client needs to be initialized before it is ready to serve
227
+ * config values.
228
+ *
229
+ * @param clientSdkKey The client SDK key obtained from the ConfigDirector dashboard
230
+ * @param clientOptions {@link ConfigDirectorClientOptions} options for the client (optional)
231
+ * @returns A {@link ConfigDirectorClient} object
232
+ *
233
+ * @example
234
+ * import { createClient } from "@configdirector/client-sdk";
235
+ * const client = createClient("YOUR-SDK-KEY");
236
+ * await client.initialize();
237
+ */
238
+ declare const createClient: (clientSdkKey: string, clientOptions?: ConfigDirectorClientOptions) => ConfigDirectorClient;
239
+ declare const createConsoleLogger: (level: ConfigDirectorLoggingLevel, messageDecorator?: ConfigDirectorLogMessageDecorator) => DefaultConsoleLogger;
240
+ //#endregion
241
+ export { type ConfigDirectorClient, type ConfigDirectorClientOptions, type ConfigDirectorConnectionError, type ConfigDirectorContext, type ConfigDirectorLogMessageDecorator, type ConfigDirectorLogger, type ConfigDirectorLoggingLevel, type ConfigDirectorValidationError, type ConfigValueType, createClient, createConsoleLogger };
242
+ //# sourceMappingURL=configdirector-client.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configdirector-client.d.mts","names":[],"sources":["../../js-client-core/src/Emitter.ts","../../js-client-core/src/types.ts","../../js-client-core/src/logger.ts","../../js-client-core/src/errors.ts","../src/api.ts"],"mappings":";KAAK,SAAA;AAAA,KACA,YAAA,GAAe,MAAA,CAAO,SAAA;AAAA,KAEtB,OAAA,uBAA8B,YAAA,qBAAiC,aAAA,KAClE,OAAA,EAAS,aAAA,CAAc,IAAA;AAAA,UAGR,aAAA,uBAAoC,YAAA;EACnD,EAAA,qBAAuB,aAAA,EAAe,IAAA,EAAM,KAAA,EAAO,OAAA,EAAS,OAAA,CAAQ,aAAA,EAAe,KAAA;EACnF,GAAA,qBAAwB,aAAA,EAAe,IAAA,EAAM,KAAA,EAAO,OAAA,GAAU,OAAA,CAAQ,aAAA,EAAe,KAAA;EACrF,KAAA;AAAA;;;KCR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AAgB,eAAA,EAAiB,SAAA,UAAmB,YAAA,EAAc,CAAA,EAAG,QAAA,EAAU,YAAA,CAAa,CAAA;EAhC7C;;;;;;;;EA0C/C,OAAA,WAAkB,eAAA,EAAiB,SAAA,UAAmB,QAAA,GAAW,YAAA,CAAa,CAAA;EAV9E;;;EAeA,UAAA;EAfkE;;;;;;EAuBlE,OAAA;AAAA;;;cC/MW,oBAAA,YAAgC,oBAAA;EAAA,iBAGd,KAAA;EAAA,iBAAoD,SAAA;EAAA,iBAFhE,aAAA;cAEY,KAAA,EAAO,0BAAA,EAA6C,SAAA,EAAW,iCAAA;EAM5F,KAAA,CAAM,OAAA,aAAoB,IAAA;EAI1B,IAAA,CAAK,OAAA,aAAoB,IAAA;EAIzB,IAAA,CAAK,OAAA,aAAoB,IAAA;EAIzB,KAAA,CAAM,OAAA,aAAoB,IAAA;EAAA,QAIlB,GAAA;AAAA;;;cCxDG,6BAAA,SAAsC,KAAA;EAAA,SACxB,IAAA;EAAA,SACT,MAAA;cAEJ,OAAA,UAAiB,MAAA;AAAA;AAAA,cAQlB,6BAAA,SAAsC,KAAA;EAAA,SACxB,IAAA;cAEb,OAAA;AAAA;;;;;;;;AHfA;;;;;AACsB;;;;cIsBvB,YAAA,GACX,YAAA,UACA,aAAA,GAAgB,2BAAA,KACf,oBAAA;AAAA,cAQU,mBAAA,GACX,KAAA,EAAO,0BAAA,EACP,gBAAA,GAAmB,iCAAA,KAAiC,oBAAA"}
@@ -1,2 +1,2 @@
1
- import{createEventSource as e}from"eventsource-client";var t=class{constructor(){this.handlerMap=new Map}on(e,t){let n=this.handlerMap.get(e);n?n.push(t):this.handlerMap.set(e,[t])}once(e,t){let n=this;function r(i){n.off(e,r),t.apply(n,i)}this.on(e,r)}off(e,t){let n=this.handlerMap.get(e);if(n)if(t){let e=n.indexOf(t);e>=0&&n.splice(e,1)}else this.handlerMap.set(e,[])}clear(){this.handlerMap.clear()}emit(e,t){let n=this.handlerMap.get(e);n&&n.slice().map(e=>e(t))}},n=class e extends Error{constructor(t,n){super(t),this.name=`ConfigDirectorConnectionError`,this.status=n,Object.setPrototypeOf(this,e.prototype)}},r=class e extends Error{constructor(t){super(t),this.name=`ConfigDirectorValidationError`,Object.setPrototypeOf(this,e.prototype)}};const i=e=>{if(e instanceof DOMException){if(e.name===`NotAllowedError`)return!0}else if(e instanceof TypeError)return!0;return!1};var a=class{constructor(e){this.options=e,this.eventEmitter=new t,this.options=e,this.logger=e.logger,this.url=new URL(`sse/v1`,e.baseUrl)}async connect(t,n){this.eventSource&&this.close();let r,i,a=async(e,t)=>{let n=await fetch(e,t);return r=n.status,n.ok||(i=await n.text()),n},o=new Promise((n,o)=>{this.eventSource=e({url:this.url,fetch:a,method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({givenContext:t,metaContext:this.options.metaContext,clientSdkKey:this.options.clientSdkKey}),onMessage:({data:e})=>{this.dispatchMessage(e)},onConnect:()=>{r&&this.isStatusFatal(r)?(this.close(),o(this.prepareFatalError(r,i))):(this.logger.debug(`[EventSourceTransport] Connected, status: %s`,r),n(this))},onScheduleReconnect:e=>{r&&this.isStatusFatal(r)?(this.close(),o(this.prepareFatalError(r,i))):this.logger.warn(`[EventSourceTransport] Scheduling reconnect in ${e.delay}. Response status: ${r}`)},onDisconnect:()=>{this.logger.debug(`[EventSourceTransport] Disconnected`)}})});return Promise.race([o,new Promise(e=>{setTimeout(()=>e(this),n)})])}dispatchMessage(e){try{let t=JSON.parse(e);this.eventEmitter.emit(`configSetReceived`,t)}catch(e){this.logger.error(`[EventSourceTransport] Error parsing and dispatching config data update: `,e)}}prepareFatalError(e,t){let r=e??0;return new n(`${`Connection failed with status: ${e??`unknown`}`}${(t?.trim()?.length??0)>0?` (${t})`:``}. This is an unrecoverable error, will not attempt to reconnect.`,r)}isStatusFatal(e){return!!e&&e>=400&&e<500}on(e,t){this.eventEmitter.on(e,t)}off(e,t){this.eventEmitter.off(e,t)}clear(){this.eventEmitter.clear()}close(){this.eventSource?.close()}dispose(){this.close(),this.clear()}};const o=e=>{let t=typeof e;if(t===`object`)try{return e.constructor?.name??t}catch{return t}else if(t===`function`)try{let n=e.name;return n?`function: ${n}`:t}catch{return t}return t},s=e=>e===`number`||e===`bigint`,c=(e,t)=>{let n=e.value,r=o(t);if(!n)return{parsedValue:t,requestedType:r,usedDefault:!0,reason:`value-missing`};if(typeof t==`string`)return{parsedValue:n,requestedType:r,usedDefault:!1,reason:`found-match`};if(typeof t==`boolean`&&e.type===`boolean`){let e=l(n),i=typeof e==`boolean`;return{parsedValue:i?e:t,requestedType:r,usedDefault:!i,reason:i?`found-match`:`invalid-boolean`}}if(s(typeof t)&&e.type===`integer`){let e=u(n),i=typeof e==`number`;return{parsedValue:i?e:t,requestedType:r,usedDefault:!i,reason:i?`found-match`:`invalid-number`}}if(s(typeof t)&&(e.type===`float`||e.type===`enum`)){let e=d(n),i=typeof e==`number`;return{parsedValue:i?e:t,requestedType:r,usedDefault:!i,reason:i?`found-match`:`invalid-number`}}return{parsedValue:n,requestedType:r,usedDefault:!1,reason:`found-match`}},l=e=>{if(!e)return;let t=e.toLowerCase();if(!(t!=`true`&&t!=`false`))return t===`true`},u=e=>{if(!e)return;let t=Number.parseInt(e);if(!(isNaN(t)||!isFinite(t)))return t},d=e=>{if(!e)return;let t=Number.parseFloat(e);if(!(isNaN(t)||!isFinite(t)))return t},f={off:-1,error:0,warn:1,info:2,debug:3},p=()=>{let e={year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,timeZoneName:`short`};try{return new Intl.DateTimeFormat(void 0,{...e,fractionalSecondDigits:3})}catch{return new Intl.DateTimeFormat(void 0,e)}};var m=class{constructor(e,t){this.level=e,this.decorator=t,this.level=e,this.decorator=t,this.dateFormatter=p()}debug(e,...t){this.log(console.debug,`debug`,e,...t)}info(e,...t){this.log(console.info,`info`,e,...t)}warn(e,...t){this.log(console.warn,`warn`,e,...t)}error(e,...t){this.log(console.error,`error`,e,...t)}log(e,t,n,...r){f[this.level]>=f[t]&&e(`[${this.dateFormatter.format(new Date)}] ${this.decorator?.decorateMessage(n)}`,...r)}},h=class{decorateMessage(e){return`[ConfigDirector:js-client-sdk] ${e}`}};const g=(e,t)=>new m(e??`warn`,t??new h);var _=class{aggregate(e){if(e.events.length==0)return[];let t=new Map;for(let n of e.events){let e=JSON.stringify(n),r=t.get(e)?.count||0;t.set(e,{event:n,count:r+1})}return Array.from(t).map(([,t])=>({startTime:e.startTime,endTime:e.endTime,count:t.count,event:t.event}))}},v=class{constructor(e){this._events=[],this._droppedEventCount=0,this.limit=e??1e3}get events(){return this._events}get reachedLimit(){return this._events.length>=this.limit}get droppedEventCount(){return this._droppedEventCount}push(...e){this.startTime||=new Date;let t=Math.max(0,e.length-this.limit),n=e.slice(t,e.length);if(this._droppedEventCount+=t,this._events.length+n.length>this.limit){let e=this._events.length+n.length-this.limit;this._events.splice(0,e),this._droppedEventCount+=e}return this._events.push(...n)}takeSnapshot(){let e=new Date,t=this.startTime??e,n=this._events.splice(0),r=this._droppedEventCount;return this.startTime=void 0,this._droppedEventCount=0,{startTime:t,endTime:e,events:n,droppedCount:r}}clear(){this._events=[],this.startTime=void 0,this._droppedEventCount=0}},y=class{constructor(e){this.executeRequests=!0,this.sdkKey=e.sdkKey,this.logger=e.logger,this.url=new URL(`telemetry/v1`,e.baseUrl)}report({discreteEvents:e,aggregatedEvents:t,droppedEvents:n}){if(!this.executeRequests)return{success:!1,fatalError:!0};let r={clientSdkKey:this.sdkKey,discreteEvents:e,aggregatedEvents:t,droppedEvents:n};if(this.isReportEmpty(r))return{success:!0,fatalError:!1};let i=this.sendReport(r);return i.fatalError&&(this.executeRequests=!1),i}isReportEmpty(e){return this.isEventListEmpty(e.discreteEvents)&&this.isEventListEmpty(e.aggregatedEvents)&&this.isDroppedEventsEmpty(e.droppedEvents)}isDroppedEventsEmpty(e){if(!e)return!0;let t=Object.keys(e);if(t.length==0)return!0;for(let n of t)if((e[n]??0)>0)return!1;return!0}isEventListEmpty(e){let t=Object.keys(e);if(t.length==0)return!0;for(let n of t)if((e[n]?.length??0)>0)return!1;return!0}sendReport(e){try{return{success:navigator.sendBeacon(this.url,JSON.stringify(e)),fatalError:!1}}catch(e){return this.logger.warn(`[EventReporter] Fatal error attempting to send telemetry data: ${e}. No more telemetry data will be sent.`),{success:!1,fatalError:!0}}}};const b=e=>x(new TextEncoder().encode(e)).toString(16).padStart(8,`0`),x=e=>{let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t+e[n],t>>>=0;return t};var S=class{constructor(e){this.evaluationEventQueue=new v,this.aggregator=new _,this.collectEvents=!0,this.logger=e.logger,this.reporter=new y(e),this.flushIntervalDelay=3e4,this.flushTimeout=setTimeout(()=>this.flushAndScheduleNext(),5e3);try{document.addEventListener(`visibilitychange`,()=>{document.visibilityState===`hidden`&&this.flush()})}catch(e){this.logger.warn(`[TelemetryEventCollector] Could not configure 'visibilitychange' listener: `,e)}}evaluatedConfig(e){this.collectEvents&&this.evaluationEventQueue.push(this.sanitizeEvaluatedConfigEvent(e))}sanitizeEvaluatedConfigEvent(e){return{key:e.key,type:e.type,defaultValue:this.sanitizeValue(e.defaultValue,e.type),requestedType:e.requestedType,evaluatedValue:this.sanitizeValue(e.evaluatedValue,e.type),usedDefault:e.usedDefault,evaluationReason:e.evaluationReason}}sanitizeValue(e,t){if(t===`json`)try{return b(JSON.stringify(e))}catch{return e.toString().slice(0,500)}return e.toString().slice(0,500)}flushAndScheduleNext(){this.flush().fatalError?(this.collectEvents=!1,this.close(),this.logger.warn(`[TelemetryEventCollector] Received a fatal error from telemetry collection. No longer collecting events.`)):this.flushTimeout=setTimeout(()=>this.flushAndScheduleNext(),this.flushIntervalDelay)}flush(){let e=this.evaluationEventQueue.takeSnapshot();return this.reporter.report({discreteEvents:{},aggregatedEvents:{evaluatedConfig:this.aggregator.aggregate(e)},droppedEvents:{evaluatedConfig:e.droppedCount}})}close(){this.collectEvents=!1,clearTimeout(this.flushTimeout),this.flush(),this.evaluationEventQueue.clear()}dispose(){this.close()}};const C=async(e,t,n,r)=>{let i=new AbortController,a=setTimeout(()=>{r.debug(`[fetchWithTimeout] Reached timeout, aborting request`),i.abort()},e);try{let e=await fetch(t,{...n,signal:i.signal});return clearTimeout(a),e}catch(e){throw r.warn(`[fetchWithTimeout] Fetch error: `,e),clearTimeout(a),e}};var w=class{constructor(e){this.options=e,this.eventEmitter=new t,this.fatalError=!1,this.options=e,this.logger=e.logger,this.url=new URL(`pull/v1`,e.baseUrl)}async connect(e,t){if(this.fatalError)return this.logger.warn(`[PullTransport] There was a prior unrecoverable error. Ignoring attempt to reconnect.`),this;try{let r=await C(t,this.url,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({givenContext:e,metaContext:this.options.metaContext,clientSdkKey:this.options.clientSdkKey})},this.logger);if(!r.ok)throw this.isStatusFatal(r.status)?(this.fatalError=!0,this.prepareFatalResponseStatusError(r.status,await r.text())):new n(`Connection failed with status: ${r.status}`,r.status);let i=JSON.parse(await r.text());return this.eventEmitter.emit(`configSetReceived`,i),this}catch(e){throw i(e)?(this.fatalError=!0,new n(`Connection failed with fatal error: ${e}. This is an unrecoverable error, retry attempts will be ignored.`)):e instanceof SyntaxError?new n(`Failed to parse the response from the server: ${e}`):new n(`Connection failed with error: ${e}.`)}}prepareFatalResponseStatusError(e,t){let r=e??0;return new n(`${`Connection failed with status: ${e??`unknown`}`}${(t?.trim()?.length??0)>0?` (${t})`:``}. This is an unrecoverable error, retry attempts will be ignored.`,r)}isStatusFatal(e){return!!e&&e>=400&&e<500}on(e,t){this.eventEmitter.on(e,t)}off(e,t){this.eventEmitter.off(e,t)}clear(){this.eventEmitter.clear()}close(){}dispose(){this.close(),this.clear()}};const T=new URL(`https://client-sdk-api.configdirector.com`);var E=class{constructor(e,n,r){this.handlersMap=new Map,this.eventEmitter=new t,this.ready=!1,this.logger=r?.logger??g(),this.timeout=r?.connection?.timeout??3e3;let i=this.parseUrl(r?.connection?.url)??T;this.streaming=r?.connection?.streaming!==!1;let o=this.streaming?a:w;this.usageEventCollector=new S({sdkKey:e,logger:this.logger,baseUrl:i}),this.transport=new o({clientSdkKey:e,baseUrl:i,metaContext:{...r?.metadata,sdkName:n.sdkName,sdkVersion:n.sdkVersion,userAgent:navigator?.userAgent},logger:this.logger}),this.transport.on(`configSetReceived`,e=>{this.readyResolve?.();let t=Object.keys(e.configs);!this.configSet||e.kind==`full`?(this.configSet=e,this.eventEmitter.emit(`configsUpdated`,{keys:t}),this.updateWatchers(e.configs)):(this.configSet.configs={...this.configSet.configs,...e.configs},this.eventEmitter.emit(`configsUpdated`,{keys:t}),this.updateWatchers(e.configs)),this.logger.debug(`[ConfigDirectorClient] ConfigSet updated from server:`,{keys:t})})}async initialize(e){await this.connectToTransport(e,`initialization`)}async updateContext(e){await this.connectToTransport(e,`context update`)}async connectToTransport(e,t){try{this.ready=!1,this.readyPromise=new Promise(e=>{this.readyResolve=e}).then(()=>{this.ready=!0,this.eventEmitter.emit(`clientReady`,{action:t}),this.logger.debug(`[ConfigDirectorClient] Received initial payload from the server, client is ready`)});let n=new Date().getTime();await this.transport.connect(e??{},this.timeout),this.currentContext=e;let r=new Date().getTime()-n,i=this.timeout-r;if(i>0&&await Promise.race([this.readyPromise,new Promise(e=>{setTimeout(()=>e(),i)})]),!this.ready){let e=this.streaming?`The client will continue to retry since there were no fatal errors detected. Configs will return the default value until the connection succeeds.`:`Since the client was configured without streaming, configs may not update and always return the default value.`;this.logger.warn(`[ConfigDirectorClient] Timed out waiting for ${t} after ${this.timeout}ms. ${e}`)}}catch(e){this.logger.error(`[ConfigDirectorClient] An error occurred during ${t}: `,e)}}updateWatchers(e){Object.values(e).forEach(e=>this.updateWatchersForConfig(e))}updateWatchersForConfig(e){this.handlersMap.get(e.key)?.forEach(t=>{let n=this.getValueFromConfigState(e.key,e,t.defaultValue);t.handler(n)})}watch(e,t,n){this.validateDefaultValue(t);let r=this.handlersMap.get(e),i={handler:n,defaultValue:t,requestedType:typeof t};return r?r.push(i):this.handlersMap.set(e,[i]),()=>this.unwatch(e,n)}unwatch(e,t){let n=this.handlersMap.get(e);if(n)if(t){let e=n.findIndex(e=>e.handler==t);e>=0&&n?.splice(e,1)}else n.splice(0)}getValue(e,t){this.validateDefaultValue(t);let n=this.configSet?.configs[e];return this.getValueFromConfigState(e,n,t)}getValueFromConfigState(e,t,n){if(!t)return this.logger.debug(`[ConfigDirectorClient] No config state found for '${e}', returning default value '${n}'`),this.usageEventCollector.evaluatedConfig({contextId:this.currentContext?.id,key:e,defaultValue:n,requestedType:o(n),evaluatedValue:n,usedDefault:!0,evaluationReason:`config-state-missing`}),n;let r=c(t,n);return this.usageEventCollector.evaluatedConfig({contextId:this.currentContext?.id,key:e,defaultValue:n,requestedType:r.requestedType,evaluatedValue:r.parsedValue,usedDefault:r.usedDefault,evaluationReason:r.reason}),this.logger.debug(`[ConfigDirectorClient] Evaluated '${e}' to '${r.parsedValue}'`),r.parsedValue}parseUrl(e){if(e)try{return new URL(e)}catch(t){throw new r(`Invalid base URL '${e}'. Parsing failed: ${t}`)}}validateDefaultValue(e){if(e==null)throw new r(`Invalid default value. The default value for a config must be defined and non-null.`);if(typeof e==`function`)throw new r(`Invalid default value. The default value for a config cannot be a function.`)}get isReady(){return this.ready}on(e,t){this.eventEmitter.on(e,t)}off(e,t){this.eventEmitter.off(e,t)}clear(){this.logger.debug(`[ConfigDirectorClient] clear() has been called, removing all observers`),this.eventEmitter.clear(),this.handlersMap.clear()}unwatchAll(){this.handlersMap.clear()}close(){this.logger.debug(`[ConfigDirectorClient] close() has been called, closing connection to server`),this.transport.close(),this.ready=!1}dispose(){this.clear(),this.close()}};const D=(e,t)=>new E(e,{sdkName:`js-client-sdk`,sdkVersion:`0.1.6`},t),O=(e,t)=>g(e,t);export{D as createClient,O as createConsoleLogger};
1
+ import{createEventSource as e}from"eventsource-client";var t=class{constructor(){this.handlerMap=new Map}on(e,t){let n=this.handlerMap.get(e);n?n.push(t):this.handlerMap.set(e,[t])}once(e,t){let n=this;function r(i){n.off(e,r),t.apply(n,i)}this.on(e,r)}off(e,t){let n=this.handlerMap.get(e);if(n)if(t){let e=n.indexOf(t);e>=0&&n.splice(e,1)}else this.handlerMap.set(e,[])}clear(){this.handlerMap.clear()}emit(e,t){let n=this.handlerMap.get(e);n&&n.slice().map(e=>e(t))}},n=class e extends Error{constructor(t,n){super(t),this.name=`ConfigDirectorConnectionError`,this.status=n,Object.setPrototypeOf(this,e.prototype)}},r=class e extends Error{constructor(t){super(t),this.name=`ConfigDirectorValidationError`,Object.setPrototypeOf(this,e.prototype)}};const i=e=>{if(e instanceof DOMException){if(e.name===`NotAllowedError`)return!0}else if(e instanceof TypeError)return!0;return!1};var a=class{constructor(e){this.options=e,this.eventEmitter=new t,this.options=e,this.logger=e.logger,this.url=new URL(`sse/v1`,e.baseUrl)}async connect(t,n){this.eventSource&&this.close();let r,i,a=async(e,t)=>{let n=await fetch(e,t);return r=n.status,n.ok||(i=await n.text()),n},o=new Promise((n,o)=>{this.eventSource=e({url:this.url,fetch:a,method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({givenContext:t,metaContext:this.options.metaContext,clientSdkKey:this.options.clientSdkKey}),onMessage:({data:e})=>{this.dispatchMessage(e)},onConnect:()=>{r&&this.isStatusFatal(r)?(this.close(),o(this.prepareFatalError(r,i))):(this.logger.debug(`[EventSourceTransport] Connected, status: %s`,r),n(this))},onScheduleReconnect:e=>{r&&this.isStatusFatal(r)?(this.close(),o(this.prepareFatalError(r,i))):this.logger.warn(`[EventSourceTransport] Scheduling reconnect in ${e.delay}. Response status: ${r}`)},onDisconnect:()=>{this.logger.debug(`[EventSourceTransport] Disconnected`)}})});return Promise.race([o,new Promise(e=>{setTimeout(()=>e(this),n)})])}dispatchMessage(e){try{let t=JSON.parse(e);this.eventEmitter.emit(`configSetReceived`,t)}catch(e){this.logger.error(`[EventSourceTransport] Error parsing and dispatching config data update: `,e)}}prepareFatalError(e,t){let r=e??0;return new n(`${`Connection failed with status: ${e??`unknown`}`}${(t?.trim()?.length??0)>0?` (${t})`:``}. This is an unrecoverable error, will not attempt to reconnect.`,r)}isStatusFatal(e){return!!e&&e>=400&&e<500}on(e,t){this.eventEmitter.on(e,t)}off(e,t){this.eventEmitter.off(e,t)}clear(){this.eventEmitter.clear()}close(){this.eventSource?.close()}dispose(){this.close(),this.clear()}};const o=e=>{let t=typeof e;if(t===`object`)try{return e.constructor?.name??t}catch{return t}else if(t===`function`)try{let n=e.name;return n?`function: ${n}`:t}catch{return t}return t},s=e=>e===`number`||e===`bigint`,c=(e,t)=>{let n=e.value,r=o(t);if(!n)return{parsedValue:t,requestedType:r,usedDefault:!0,reason:`value-missing`};if(typeof t==`string`)return{parsedValue:n,requestedType:r,usedDefault:!1,reason:`found-match`};if(typeof t==`boolean`&&e.type===`boolean`){let e=l(n),i=typeof e==`boolean`;return{parsedValue:i?e:t,requestedType:r,usedDefault:!i,reason:i?`found-match`:`invalid-boolean`}}if(s(typeof t)&&e.type===`integer`){let e=u(n),i=typeof e==`number`;return{parsedValue:i?e:t,requestedType:r,usedDefault:!i,reason:i?`found-match`:`invalid-number`}}if(s(typeof t)&&(e.type===`float`||e.type===`enum`)){let e=d(n),i=typeof e==`number`;return{parsedValue:i?e:t,requestedType:r,usedDefault:!i,reason:i?`found-match`:`invalid-number`}}return{parsedValue:n,requestedType:r,usedDefault:!1,reason:`found-match`}},l=e=>{if(!e)return;let t=e.toLowerCase();if(!(t!=`true`&&t!=`false`))return t===`true`},u=e=>{if(!e)return;let t=Number.parseInt(e);if(!(isNaN(t)||!isFinite(t)))return t},d=e=>{if(!e)return;let t=Number.parseFloat(e);if(!(isNaN(t)||!isFinite(t)))return t},f={off:-1,error:0,warn:1,info:2,debug:3},p=()=>{let e={year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,timeZoneName:`short`};try{return new Intl.DateTimeFormat(void 0,{...e,fractionalSecondDigits:3})}catch{return new Intl.DateTimeFormat(void 0,e)}};var m=class{constructor(e,t){this.level=e,this.decorator=t,this.level=e,this.decorator=t,this.dateFormatter=p()}debug(e,...t){this.log(console.debug,`debug`,e,...t)}info(e,...t){this.log(console.info,`info`,e,...t)}warn(e,...t){this.log(console.warn,`warn`,e,...t)}error(e,...t){this.log(console.error,`error`,e,...t)}log(e,t,n,...r){f[this.level]>=f[t]&&e(`[${this.dateFormatter.format(new Date)}] ${this.decorator?.decorateMessage(n)}`,...r)}},h=class{decorateMessage(e){return`[ConfigDirector:js-client-sdk] ${e}`}};const g=(e,t)=>new m(e??`warn`,t??new h);var _=class{aggregate(e){if(e.events.length==0)return[];let t=new Map;for(let n of e.events){let e=JSON.stringify(n),r=t.get(e)?.count||0;t.set(e,{event:n,count:r+1})}return Array.from(t).map(([,t])=>({startTime:e.startTime,endTime:e.endTime,count:t.count,event:t.event}))}},v=class{constructor(e){this._events=[],this._droppedEventCount=0,this.limit=e??1e3}get events(){return this._events}get reachedLimit(){return this._events.length>=this.limit}get droppedEventCount(){return this._droppedEventCount}push(...e){this.startTime||=new Date;let t=Math.max(0,e.length-this.limit),n=e.slice(t,e.length);if(this._droppedEventCount+=t,this._events.length+n.length>this.limit){let e=this._events.length+n.length-this.limit;this._events.splice(0,e),this._droppedEventCount+=e}return this._events.push(...n)}takeSnapshot(){let e=new Date,t=this.startTime??e,n=this._events.splice(0),r=this._droppedEventCount;return this.startTime=void 0,this._droppedEventCount=0,{startTime:t,endTime:e,events:n,droppedCount:r}}clear(){this._events=[],this.startTime=void 0,this._droppedEventCount=0}},y=class{constructor(e){this.executeRequests=!0,this.sdkKey=e.sdkKey,this.logger=e.logger,this.url=new URL(`telemetry/v1`,e.baseUrl)}report({discreteEvents:e,aggregatedEvents:t,droppedEvents:n}){if(!this.executeRequests)return{success:!1,fatalError:!0};let r={clientSdkKey:this.sdkKey,discreteEvents:e,aggregatedEvents:t,droppedEvents:n};if(this.isReportEmpty(r))return{success:!0,fatalError:!1};let i=this.sendReport(r);return i.fatalError&&(this.executeRequests=!1),i}isReportEmpty(e){return this.isEventListEmpty(e.discreteEvents)&&this.isEventListEmpty(e.aggregatedEvents)&&this.isDroppedEventsEmpty(e.droppedEvents)}isDroppedEventsEmpty(e){if(!e)return!0;let t=Object.keys(e);if(t.length==0)return!0;for(let n of t)if((e[n]??0)>0)return!1;return!0}isEventListEmpty(e){let t=Object.keys(e);if(t.length==0)return!0;for(let n of t)if((e[n]?.length??0)>0)return!1;return!0}sendReport(e){try{return{success:navigator.sendBeacon(this.url,JSON.stringify(e)),fatalError:!1}}catch(e){return this.logger.warn(`[EventReporter] Fatal error attempting to send telemetry data: ${e}. No more telemetry data will be sent.`),{success:!1,fatalError:!0}}}};const b=e=>x(new TextEncoder().encode(e)).toString(16).padStart(8,`0`),x=e=>{let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t+e[n],t>>>=0;return t};var S=class{constructor(e){this.evaluationEventQueue=new v,this.aggregator=new _,this.collectEvents=!0,this.logger=e.logger,this.reporter=new y(e),this.flushIntervalDelay=3e4,this.flushTimeout=setTimeout(()=>this.flushAndScheduleNext(),5e3);try{document.addEventListener(`visibilitychange`,()=>{document.visibilityState===`hidden`&&this.flush()})}catch(e){this.logger.warn(`[TelemetryEventCollector] Could not configure 'visibilitychange' listener: `,e)}}evaluatedConfig(e){this.collectEvents&&this.evaluationEventQueue.push(this.sanitizeEvaluatedConfigEvent(e))}sanitizeEvaluatedConfigEvent(e){return{key:e.key,type:e.type,defaultValue:this.sanitizeValue(e.defaultValue,e.type),requestedType:e.requestedType,evaluatedValue:this.sanitizeValue(e.evaluatedValue,e.type),usedDefault:e.usedDefault,evaluationReason:e.evaluationReason}}sanitizeValue(e,t){if(t===`json`)try{return b(JSON.stringify(e))}catch{return e.toString().slice(0,500)}return e.toString().slice(0,500)}flushAndScheduleNext(){this.flush().fatalError?(this.collectEvents=!1,this.close(),this.logger.warn(`[TelemetryEventCollector] Received a fatal error from telemetry collection. No longer collecting events.`)):this.flushTimeout=setTimeout(()=>this.flushAndScheduleNext(),this.flushIntervalDelay)}flush(){let e=this.evaluationEventQueue.takeSnapshot();return this.reporter.report({discreteEvents:{},aggregatedEvents:{evaluatedConfig:this.aggregator.aggregate(e)},droppedEvents:{evaluatedConfig:e.droppedCount}})}close(){this.collectEvents=!1,clearTimeout(this.flushTimeout),this.flush(),this.evaluationEventQueue.clear()}dispose(){this.close()}};const C=async(e,t,n,r)=>{let i=new AbortController,a=setTimeout(()=>{r.debug(`[fetchWithTimeout] Reached timeout, aborting request`),i.abort()},e);try{let e=await fetch(t,{...n,signal:i.signal});return clearTimeout(a),e}catch(e){throw r.warn(`[fetchWithTimeout] Fetch error: `,e),clearTimeout(a),e}};var w=class{constructor(e){this.options=e,this.eventEmitter=new t,this.fatalError=!1,this.options=e,this.logger=e.logger,this.url=new URL(`pull/v1`,e.baseUrl)}async connect(e,t){if(this.fatalError)return this.logger.warn(`[PullTransport] There was a prior unrecoverable error. Ignoring attempt to reconnect.`),this;try{let r=await C(t,this.url,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({givenContext:e,metaContext:this.options.metaContext,clientSdkKey:this.options.clientSdkKey})},this.logger);if(!r.ok)throw this.isStatusFatal(r.status)?(this.fatalError=!0,this.prepareFatalResponseStatusError(r.status,await r.text())):new n(`Connection failed with status: ${r.status}`,r.status);let i=JSON.parse(await r.text());return this.eventEmitter.emit(`configSetReceived`,i),this}catch(e){throw i(e)?(this.fatalError=!0,new n(`Connection failed with fatal error: ${e}. This is an unrecoverable error, retry attempts will be ignored.`)):e instanceof SyntaxError?new n(`Failed to parse the response from the server: ${e}`):new n(`Connection failed with error: ${e}.`)}}prepareFatalResponseStatusError(e,t){let r=e??0;return new n(`${`Connection failed with status: ${e??`unknown`}`}${(t?.trim()?.length??0)>0?` (${t})`:``}. This is an unrecoverable error, retry attempts will be ignored.`,r)}isStatusFatal(e){return!!e&&e>=400&&e<500}on(e,t){this.eventEmitter.on(e,t)}off(e,t){this.eventEmitter.off(e,t)}clear(){this.eventEmitter.clear()}close(){}dispose(){this.close(),this.clear()}};const T=new URL(`https://client-sdk-api.configdirector.com`);var E=class{constructor(e,n,r){this.handlersMap=new Map,this.eventEmitter=new t,this.ready=!1,this.logger=r?.logger??g(),this.timeout=r?.connection?.timeout??3e3;let i=this.parseUrl(r?.connection?.url)??T;this.streaming=r?.connection?.streaming!==!1;let o=this.streaming?a:w;this.usageEventCollector=new S({sdkKey:e,logger:this.logger,baseUrl:i}),this.transport=new o({clientSdkKey:e,baseUrl:i,metaContext:{...r?.metadata,sdkName:n.sdkName,sdkVersion:n.sdkVersion,userAgent:navigator?.userAgent},logger:this.logger}),this.transport.on(`configSetReceived`,e=>{this.readyResolve?.();let t=Object.keys(e.configs);!this.configSet||e.kind==`full`?(this.configSet=e,this.eventEmitter.emit(`configsUpdated`,{keys:t}),this.updateWatchers(e.configs)):(this.configSet.configs={...this.configSet.configs,...e.configs},this.eventEmitter.emit(`configsUpdated`,{keys:t}),this.updateWatchers(e.configs)),this.logger.debug(`[ConfigDirectorClient] ConfigSet updated from server:`,{keys:t})})}async initialize(e){await this.connectToTransport(e,`initialization`)}async updateContext(e){await this.connectToTransport(e,`context update`)}async connectToTransport(e,t){try{this.ready=!1,this.readyPromise=new Promise(e=>{this.readyResolve=e}).then(()=>{this.ready=!0,this.eventEmitter.emit(`clientReady`,{action:t}),this.logger.debug(`[ConfigDirectorClient] Received initial payload from the server, client is ready`)});let n=new Date().getTime();await this.transport.connect(e??{},this.timeout),this.currentContext=e;let r=new Date().getTime()-n,i=this.timeout-r;if(i>0&&await Promise.race([this.readyPromise,new Promise(e=>{setTimeout(()=>e(),i)})]),!this.ready){let e=this.streaming?`The client will continue to retry since there were no fatal errors detected. Configs will return the default value until the connection succeeds.`:`Since the client was configured without streaming, configs may not update and always return the default value.`;this.logger.warn(`[ConfigDirectorClient] Timed out waiting for ${t} after ${this.timeout}ms. ${e}`)}}catch(e){this.logger.error(`[ConfigDirectorClient] An error occurred during ${t}: `,e)}}updateWatchers(e){Object.values(e).forEach(e=>this.updateWatchersForConfig(e))}updateWatchersForConfig(e){this.handlersMap.get(e.key)?.forEach(t=>{let n=this.getValueFromConfigState(e.key,e,t.defaultValue);t.handler(n)})}watch(e,t,n){this.validateDefaultValue(t);let r=this.handlersMap.get(e),i={handler:n,defaultValue:t,requestedType:typeof t};return r?r.push(i):this.handlersMap.set(e,[i]),()=>this.unwatch(e,n)}unwatch(e,t){let n=this.handlersMap.get(e);if(n)if(t){let e=n.findIndex(e=>e.handler==t);e>=0&&n?.splice(e,1)}else n.splice(0)}getValue(e,t){this.validateDefaultValue(t);let n=this.configSet?.configs[e];return this.getValueFromConfigState(e,n,t)}getValueFromConfigState(e,t,n){if(!t)return this.logger.debug(`[ConfigDirectorClient] No config state found for '${e}', returning default value '${n}'`),this.usageEventCollector.evaluatedConfig({contextId:this.currentContext?.id,key:e,defaultValue:n,requestedType:o(n),evaluatedValue:n,usedDefault:!0,evaluationReason:`config-state-missing`}),n;let r=c(t,n);return this.usageEventCollector.evaluatedConfig({contextId:this.currentContext?.id,key:e,defaultValue:n,requestedType:r.requestedType,evaluatedValue:r.parsedValue,usedDefault:r.usedDefault,evaluationReason:r.reason}),this.logger.debug(`[ConfigDirectorClient] Evaluated '${e}' to '${r.parsedValue}'`),r.parsedValue}parseUrl(e){if(e)try{return new URL(e)}catch(t){throw new r(`Invalid base URL '${e}'. Parsing failed: ${t}`)}}validateDefaultValue(e){if(e==null)throw new r(`Invalid default value. The default value for a config must be defined and non-null.`);if(typeof e==`function`)throw new r(`Invalid default value. The default value for a config cannot be a function.`)}get isReady(){return this.ready}on(e,t){this.eventEmitter.on(e,t)}off(e,t){this.eventEmitter.off(e,t)}clear(){this.logger.debug(`[ConfigDirectorClient] clear() has been called, removing all observers`),this.eventEmitter.clear(),this.handlersMap.clear()}unwatchAll(){this.handlersMap.clear()}close(){this.logger.debug(`[ConfigDirectorClient] close() has been called, closing connection to server`),this.transport.close(),this.ready=!1}dispose(){this.clear(),this.close()}};const D=(e,t)=>new E(e,{sdkName:`js-client-sdk`,sdkVersion:`0.1.7`},t),O=(e,t)=>g(e,t);export{D as createClient,O as createConsoleLogger};
2
2
  //# sourceMappingURL=configdirector-client.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configdirector-client.mjs","names":[],"sources":["../../js-client-core/src/Emitter.ts","../../js-client-core/src/errors.ts","../../js-client-core/src/StreamingTransport.ts","../../js-client-core/src/value-parser.ts","../../js-client-core/src/logger.ts","../../js-client-core/src/telemetry/EventAggregator.ts","../../js-client-core/src/telemetry/EventQueue.ts","../../js-client-core/src/telemetry/EventReporter.ts","../../js-client-core/src/telemetry/utils.ts","../../js-client-core/src/telemetry/TelemetryEventCollector.ts","../../js-client-core/src/fetchWithTimeout.ts","../../js-client-core/src/PullTransport.ts","../../js-client-core/src/DefaultConfigDirectorClient.ts","../src/api.ts"],"sourcesContent":["type EventType = string | symbol;\ntype EventsRecord = Record<EventType, any>;\n\ntype Handler<TEventsRecord extends EventsRecord, TKey extends keyof TEventsRecord> = (\n payload: TEventsRecord[TKey],\n) => void;\n\nexport interface EventProvider<TEventsRecord extends EventsRecord> {\n on<TName extends keyof TEventsRecord>(name: TName, handler: Handler<TEventsRecord, TName>): void;\n off<TName extends keyof TEventsRecord>(name: TName, handler?: Handler<TEventsRecord, TName>): void;\n clear(): void;\n}\n\nexport class Emitter<TEventsRecord extends EventsRecord> implements EventProvider<TEventsRecord> {\n private handlerMap: Map<keyof TEventsRecord, Array<(payload: any) => void>> = new Map();\n\n on<TName extends keyof TEventsRecord>(name: TName, handler: Handler<TEventsRecord, TName>) {\n const handlers = this.handlerMap.get(name);\n if (handlers) {\n handlers.push(handler);\n } else {\n this.handlerMap.set(name, [handler]);\n }\n }\n\n once<TName extends keyof TEventsRecord>(name: TName, handler: Handler<TEventsRecord, TName>) {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const self = this;\n function onceHandler(payload: TEventsRecord[keyof TEventsRecord]) {\n self.off(name, onceHandler);\n handler.apply(self, payload);\n }\n this.on(name, onceHandler);\n }\n\n off<TName extends keyof TEventsRecord>(name: TName, handler?: Handler<TEventsRecord, TName>) {\n const handlers = this.handlerMap.get(name);\n if (!handlers) {\n return;\n }\n\n if (handler) {\n const listenerIndex = handlers.indexOf(handler);\n if (listenerIndex >= 0) {\n handlers.splice(listenerIndex, 1);\n }\n } else {\n this.handlerMap.set(name, []);\n }\n }\n\n clear() {\n this.handlerMap.clear();\n }\n\n emit<TName extends keyof TEventsRecord>(name: TName, payload: TEventsRecord[TName]) {\n const handlers = this.handlerMap.get(name);\n if (!handlers) {\n return;\n }\n\n handlers.slice().map((h) => h(payload));\n }\n}\n","export class ConfigDirectorConnectionError extends Error {\n public override readonly name: string = \"ConfigDirectorConnectionError\";\n public readonly status?: number;\n\n constructor(message: string, status?: number) {\n super(message);\n this.status = status;\n\n Object.setPrototypeOf(this, ConfigDirectorConnectionError.prototype);\n }\n}\n\nexport class ConfigDirectorValidationError extends Error {\n public override readonly name: string = \"ConfigDirectorValidationError\";\n\n constructor(message: string) {\n super(message);\n\n Object.setPrototypeOf(this, ConfigDirectorValidationError.prototype);\n }\n}\n\nexport const isFetchErrorFatal = (fetchError: any): boolean => {\n if (fetchError instanceof DOMException) {\n const domError = fetchError as DOMException;\n if (domError.name === \"NotAllowedError\") {\n return true;\n }\n } else if (fetchError instanceof TypeError) {\n return true;\n }\n\n return false;\n};\n","import { createEventSource, type EventSourceClient } from \"eventsource-client\";\nimport type {\n ConfigDirectorContext,\n ConfigDirectorLogger,\n Transport,\n TransportEvents,\n TransportOptions,\n} from \"./types\";\nimport { Emitter } from \"./Emitter\";\nimport { ConfigDirectorConnectionError } from \"./errors\";\n\nexport class StreamingTransport implements Transport {\n private logger: ConfigDirectorLogger;\n private eventSource: EventSourceClient | undefined;\n private eventEmitter = new Emitter<TransportEvents>();\n private url: URL;\n\n constructor(private readonly options: TransportOptions) {\n this.options = options;\n this.logger = options.logger;\n this.url = new URL(\"sse/v1\", options.baseUrl);\n }\n\n public async connect(context: ConfigDirectorContext, timeout: number): Promise<this> {\n if (this.eventSource) {\n this.close();\n }\n\n let responseStatus: number | undefined = undefined;\n let errorBody: string | undefined = undefined;\n\n const customFetch = async (url: string | URL | Request, init?: RequestInit | undefined) => {\n const response = await fetch(url, init);\n responseStatus = response.status;\n if (!response.ok) {\n errorBody = await response.text();\n }\n return response;\n };\n\n const eventSourcePromise = new Promise<this>((resolve, reject) => {\n this.eventSource = createEventSource({\n url: this.url,\n fetch: customFetch,\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n givenContext: context,\n metaContext: this.options.metaContext,\n clientSdkKey: this.options.clientSdkKey,\n }),\n\n onMessage: ({ data }) => {\n this.dispatchMessage(data);\n },\n onConnect: () => {\n if (responseStatus && this.isStatusFatal(responseStatus)) {\n this.close();\n reject(this.prepareFatalError(responseStatus, errorBody));\n } else {\n this.logger.debug(\"[EventSourceTransport] Connected, status: %s\", responseStatus);\n resolve(this);\n }\n },\n onScheduleReconnect: (info: { delay: number }) => {\n if (responseStatus && this.isStatusFatal(responseStatus)) {\n this.close();\n reject(this.prepareFatalError(responseStatus, errorBody));\n } else {\n this.logger.warn(\n `[EventSourceTransport] Scheduling reconnect in ${info.delay}. Response status: ${responseStatus}`,\n );\n }\n },\n onDisconnect: () => {\n this.logger.debug(\"[EventSourceTransport] Disconnected\");\n },\n });\n });\n return Promise.race([\n eventSourcePromise,\n new Promise<this>((resolve) => {\n setTimeout(() => resolve(this), timeout);\n }),\n ]);\n }\n\n private dispatchMessage(data: string) {\n try {\n const json = JSON.parse(data);\n this.eventEmitter.emit(\"configSetReceived\", json);\n } catch (error) {\n this.logger.error(\"[EventSourceTransport] Error parsing and dispatching config data update: \", error);\n }\n }\n\n private prepareFatalError(\n responseStatus: number,\n errorBody: string | undefined,\n ): ConfigDirectorConnectionError {\n const status = responseStatus ?? 0;\n const headline = `Connection failed with status: ${responseStatus ?? \"unknown\"}`;\n const serverBody = (errorBody?.trim()?.length ?? 0) > 0 ? ` (${errorBody})` : \"\";\n const message = `${headline}${serverBody}. This is an unrecoverable error, will not attempt to reconnect.`;\n return new ConfigDirectorConnectionError(message, status);\n }\n\n private isStatusFatal(status: number | undefined): boolean {\n return !!status && status >= 400 && status < 500;\n }\n\n public on<TName extends keyof TransportEvents>(\n name: TName,\n handler: (payload: TransportEvents[TName]) => void,\n ): void {\n this.eventEmitter.on(name, handler);\n }\n\n public off<TName extends keyof TransportEvents>(\n name: TName,\n handler?: ((payload: TransportEvents[TName]) => void) | undefined,\n ): void {\n this.eventEmitter.off(name, handler);\n }\n\n public clear(): void {\n this.eventEmitter.clear();\n }\n\n public close() {\n this.eventSource?.close();\n }\n\n public dispose(): void {\n this.close();\n this.clear();\n }\n}\n","import type { ConfigState, ConfigValueType, EvaluationReason } from \"./types\";\n\ntype NativeType =\n | \"string\"\n | \"number\"\n | \"bigint\"\n | \"boolean\"\n | \"symbol\"\n | \"undefined\"\n | \"object\"\n | \"function\";\n\ntype ParseResult<T extends ConfigValueType> = {\n parsedValue: T;\n requestedType: NativeType | string;\n usedDefault: boolean;\n reason: EvaluationReason;\n};\n\nexport const getRequestedType = <T extends ConfigValueType>(defaultValue: T): string => {\n const baseType = typeof defaultValue;\n if (baseType === \"object\") {\n try {\n return (defaultValue as object).constructor?.name ?? baseType;\n } catch {\n return baseType;\n }\n } else if (baseType === \"function\") {\n try {\n const functionName = (defaultValue as any).name;\n return functionName ? `function: ${functionName}` : baseType;\n } catch {\n return baseType;\n }\n }\n return baseType;\n};\n\nconst isNumericNativeType = (requestedType: NativeType): boolean => {\n return requestedType === \"number\" || requestedType === \"bigint\";\n};\n\nexport const parseConfigValue = <T extends ConfigValueType>(\n configState: ConfigState,\n defaultValue: T,\n): ParseResult<T> => {\n const value = configState.value;\n const requestedType = getRequestedType(defaultValue);\n\n if (!value) {\n return {\n parsedValue: defaultValue as T,\n requestedType,\n usedDefault: true,\n reason: \"value-missing\",\n };\n }\n\n if (typeof defaultValue === \"string\") {\n return {\n parsedValue: value as T,\n requestedType,\n usedDefault: false,\n reason: \"found-match\",\n };\n }\n\n if (typeof defaultValue === \"boolean\" && configState.type === \"boolean\") {\n const boolValue = parseConfigBoolean(value);\n const hasBoolean = typeof boolValue === \"boolean\";\n return {\n parsedValue: (hasBoolean ? boolValue : defaultValue) as T,\n requestedType,\n usedDefault: !hasBoolean,\n reason: hasBoolean ? \"found-match\" : \"invalid-boolean\",\n };\n }\n\n if (isNumericNativeType(typeof defaultValue) && configState.type === \"integer\") {\n const numValue = parseConfigInteger(value);\n const hasNumber = typeof numValue === \"number\";\n return {\n parsedValue: (hasNumber ? numValue : defaultValue) as T,\n requestedType,\n usedDefault: !hasNumber,\n reason: hasNumber ? \"found-match\" : \"invalid-number\",\n };\n }\n if (isNumericNativeType(typeof defaultValue) && (configState.type === \"float\" || configState.type === \"enum\" )) {\n const numValue = parseConfigFloat(value);\n const hasNumber = typeof numValue === \"number\";\n return {\n parsedValue: (hasNumber ? numValue : defaultValue) as T,\n requestedType,\n usedDefault: !hasNumber,\n reason: hasNumber ? \"found-match\" : \"invalid-number\",\n };\n }\n\n return {\n parsedValue: value as T,\n requestedType,\n usedDefault: false,\n reason: \"found-match\",\n };\n};\n\nconst parseConfigBoolean = (value: string): boolean | undefined => {\n if (!value) {\n return;\n }\n const lowerValue = value.toLowerCase();\n if (lowerValue != \"true\" && lowerValue != \"false\") {\n return;\n }\n return lowerValue === \"true\";\n};\n\nconst parseConfigInteger = (value: string): number | undefined => {\n if (!value) {\n return;\n }\n const num = Number.parseInt(value);\n if (isNaN(num) || !isFinite(num)) {\n return;\n }\n return num;\n};\n\nconst parseConfigFloat = (value: string): number | undefined => {\n if (!value) {\n return;\n }\n const num = Number.parseFloat(value);\n if (isNaN(num) || !isFinite(num)) {\n return;\n }\n return num;\n};\n","import { ConfigDirectorLogger, ConfigDirectorLogMessageDecorator, ConfigDirectorLoggingLevel } from \"./types\";\n\nconst LEVELS: Record<ConfigDirectorLoggingLevel, number> = {\n off: -1,\n error: 0,\n warn: 1,\n info: 2,\n debug: 3,\n};\n\nconst buildDateFormatter = () => {\n const baseOptions: Intl.DateTimeFormatOptions = {\n year: \"numeric\",\n month: \"2-digit\",\n day: \"2-digit\",\n hour: \"2-digit\",\n minute: \"2-digit\",\n second: \"2-digit\",\n timeZoneName: \"short\",\n };\n\n try {\n return new Intl.DateTimeFormat(\n undefined,\n { ...baseOptions, fractionalSecondDigits: 3 } as Intl.DateTimeFormatOptions,\n );\n } catch {\n return new Intl.DateTimeFormat(undefined, baseOptions);\n }\n};\n\nexport class DefaultConsoleLogger implements ConfigDirectorLogger {\n private readonly dateFormatter;\n\n constructor(private readonly level: ConfigDirectorLoggingLevel, private readonly decorator: ConfigDirectorLogMessageDecorator) {\n this.level = level;\n this.decorator = decorator;\n this.dateFormatter = buildDateFormatter();\n }\n\n debug(message: string, ...args: any): void {\n this.log(console.debug, \"debug\", message, ...args);\n }\n\n info(message: string, ...args: any): void {\n this.log(console.info, \"info\", message, ...args);\n }\n\n warn(message: string, ...args: any): void {\n this.log(console.warn, \"warn\", message, ...args);\n }\n\n error(message: string, ...args: any): void {\n this.log(console.error, \"error\", message, ...args);\n }\n\n private log(loggerFunction: (...args: any) => void, level: ConfigDirectorLoggingLevel, message: string, ...args: any) {\n if (LEVELS[this.level] >= LEVELS[level]) {\n loggerFunction(`[${this.dateFormatter.format(new Date())}] ${this.decorator?.decorateMessage(message)}`, ...args);\n }\n }\n}\n\nclass LogMessageDecorator implements ConfigDirectorLogMessageDecorator {\n decorateMessage(message: string): string {\n return `[ConfigDirector:js-client-sdk] ${message}`;\n }\n}\n\nexport const createDefaultLogger = (\n level?: ConfigDirectorLoggingLevel,\n messageDecorator?: ConfigDirectorLogMessageDecorator,\n) => {\n return new DefaultConsoleLogger(level ?? \"warn\", messageDecorator ?? new LogMessageDecorator());\n};\n","import { AggregatedEvent, EventQueueSnapshot, ReportableEvent } from \"./types\";\n\nexport class EventAggregator {\n public aggregate<T extends ReportableEvent>(snapshot: EventQueueSnapshot<T>): AggregatedEvent<T>[] {\n if (snapshot.events.length == 0) {\n return [];\n }\n\n const map = new Map<string, { event: T; count: number }>();\n for (const event of snapshot.events) {\n const serializedEvent = JSON.stringify(event);\n const count = map.get(serializedEvent)?.count || 0;\n map.set(serializedEvent, { event, count: count + 1 });\n }\n return Array.from(map).map(([, v]) => {\n return {\n startTime: snapshot.startTime,\n endTime: snapshot.endTime,\n count: v.count,\n event: v.event,\n };\n });\n }\n}\n","import { EventQueueSnapshot, ReportableEvent } from \"./types\";\n\nexport class EventQueue<T extends ReportableEvent> {\n private readonly limit: number;\n private startTime?: Date;\n private _events: T[] = [];\n private _droppedEventCount = 0;\n\n constructor(limit?: number) {\n this.limit = limit ?? 1_000;\n }\n\n public get events(): T[] {\n return this._events;\n }\n\n public get reachedLimit(): boolean {\n return this._events.length >= this.limit;\n }\n\n public get droppedEventCount(): number {\n return this._droppedEventCount;\n }\n\n public push(...newEvents: T[]) {\n if (!this.startTime) {\n this.startTime = new Date();\n }\n\n const newEventsCountToDrop = Math.max(0, newEvents.length - this.limit);\n const eventsToPush = newEvents.slice(newEventsCountToDrop, newEvents.length);\n this._droppedEventCount += newEventsCountToDrop;\n if (this._events.length + eventsToPush.length > this.limit) {\n const eventCountToDrop = this._events.length + eventsToPush.length - this.limit;\n this._events.splice(0, eventCountToDrop);\n this._droppedEventCount += eventCountToDrop;\n }\n return this._events.push(...eventsToPush);\n }\n\n public takeSnapshot(): EventQueueSnapshot<T> {\n const endTime = new Date();\n const startTime = this.startTime ?? endTime;\n const eventsSnapshot = this._events.splice(0);\n const droppedCount = this._droppedEventCount;\n this.startTime = undefined;\n this._droppedEventCount = 0;\n return {\n startTime,\n endTime,\n events: eventsSnapshot,\n droppedCount,\n };\n }\n\n public clear() {\n this._events = [];\n this.startTime = undefined;\n this._droppedEventCount = 0;\n }\n}\n","import { ConfigDirectorLogger } from \"../types\";\nimport {\n AggregatedEventList,\n DiscreteEventList,\n DroppedEvents,\n EventReport,\n ReporterResponse,\n} from \"./types\";\n\nexport type EventReporterOptions = {\n sdkKey: string;\n logger: ConfigDirectorLogger;\n baseUrl: URL;\n};\n\nexport class EventReporter {\n private readonly sdkKey: string;\n private readonly logger: ConfigDirectorLogger;\n private readonly url: URL;\n private executeRequests = true;\n\n constructor(options: EventReporterOptions) {\n this.sdkKey = options.sdkKey;\n this.logger = options.logger;\n this.url = new URL(\"telemetry/v1\", options.baseUrl);\n }\n\n public report({\n discreteEvents,\n aggregatedEvents,\n droppedEvents,\n }: {\n discreteEvents: DiscreteEventList;\n aggregatedEvents: AggregatedEventList;\n droppedEvents?: DroppedEvents;\n }): ReporterResponse {\n if (!this.executeRequests) {\n return { success: false, fatalError: true };\n }\n\n const eventReport: EventReport = {\n clientSdkKey: this.sdkKey,\n discreteEvents,\n aggregatedEvents,\n droppedEvents,\n };\n if (this.isReportEmpty(eventReport)) {\n return { success: true, fatalError: false };\n }\n\n const response = this.sendReport(eventReport);\n if (response.fatalError) {\n this.executeRequests = false;\n }\n return response;\n }\n\n private isReportEmpty(eventReport: EventReport) {\n return (\n this.isEventListEmpty(eventReport.discreteEvents) &&\n this.isEventListEmpty(eventReport.aggregatedEvents) &&\n this.isDroppedEventsEmpty(eventReport.droppedEvents)\n );\n }\n\n private isDroppedEventsEmpty(droppedEvents?: DroppedEvents): boolean {\n if (!droppedEvents) {\n return true;\n }\n const keys = Object.keys(droppedEvents);\n if (keys.length == 0) {\n return true;\n }\n\n for (const key of keys) {\n if ((droppedEvents[key] ?? 0) > 0) {\n return false;\n }\n }\n\n return true;\n }\n\n private isEventListEmpty<T extends Record<string | symbol, any[]>>(eventList: T): boolean {\n const keys = Object.keys(eventList);\n if (keys.length == 0) {\n return true;\n }\n\n for (const key of keys) {\n if ((eventList[key]?.length ?? 0) > 0) {\n return false;\n }\n }\n\n return true;\n }\n\n private sendReport(eventReport: EventReport): ReporterResponse {\n try {\n const result = navigator.sendBeacon(this.url, JSON.stringify(eventReport));\n return { success: result, fatalError: false };\n } catch (beaconError) {\n this.logger.warn(\n `[EventReporter] Fatal error attempting to send telemetry data: ${beaconError}. No more telemetry data will be sent.`,\n );\n return { success: false, fatalError: true };\n }\n }\n}\n","export const djb2Hash = (data: string): string => {\n const hash = djb2(new TextEncoder().encode(data));\n\treturn hash.toString(16).padStart(8, \"0\");\n};\n\nconst djb2 = (bytes: Uint8Array): number => {\n let hash = 5381;\n\t\tfor (let i = 0; i < bytes.length; i++) {\n\t\t\thash = ((hash << 5) + hash) + bytes[i];\n\t\t\thash = hash >>> 0;\n\t\t}\n return hash;\n};\n","import { ConfigDirectorLogger, ConfigType, ConfigValueType } from \"../types\";\nimport { EventAggregator } from \"./EventAggregator\";\nimport { EventQueue } from \"./EventQueue\";\nimport { EventReporter } from \"./EventReporter\";\nimport { EvaluatedConfigEvent } from \"./telemetry-events\";\nimport { djb2Hash } from \"./utils\";\n\nconst CONFIG_VALUE_MAX_LENGTH = 500;\n\nexport type TelemetryEventCollectorOptions = {\n sdkKey: string;\n logger: ConfigDirectorLogger;\n baseUrl: URL;\n};\n\nexport class TelemetryEventCollector {\n private readonly logger: ConfigDirectorLogger;\n private readonly reporter: EventReporter;\n private evaluationEventQueue: EventQueue<EvaluatedConfigEvent<string>> = new EventQueue();\n private readonly aggregator: EventAggregator = new EventAggregator();\n private flushIntervalDelay: number;\n private flushTimeout: ReturnType<typeof setTimeout>;\n private collectEvents = true;\n\n constructor(options: TelemetryEventCollectorOptions) {\n this.logger = options.logger;\n this.reporter = new EventReporter(options);\n this.flushIntervalDelay = 30_000;\n const initialDelay = 5_000;\n this.flushTimeout = setTimeout(() => this.flushAndScheduleNext(), initialDelay);\n try {\n document.addEventListener(\"visibilitychange\", () => {\n if (document.visibilityState === \"hidden\") {\n this.flush();\n }\n });\n } catch (error) {\n this.logger.warn(\"[TelemetryEventCollector] Could not configure 'visibilitychange' listener: \", error);\n }\n }\n\n public evaluatedConfig<T extends ConfigValueType>(event: EvaluatedConfigEvent<T>): void {\n if (!this.collectEvents) {\n return;\n }\n\n this.evaluationEventQueue.push(this.sanitizeEvaluatedConfigEvent(event));\n }\n\n private sanitizeEvaluatedConfigEvent<T extends ConfigValueType>(\n event: EvaluatedConfigEvent<T>,\n ): EvaluatedConfigEvent<string> {\n return {\n key: event.key,\n type: event.type,\n defaultValue: this.sanitizeValue(event.defaultValue, event.type),\n requestedType: event.requestedType,\n evaluatedValue: this.sanitizeValue(event.evaluatedValue, event.type),\n usedDefault: event.usedDefault,\n evaluationReason: event.evaluationReason,\n };\n }\n\n private sanitizeValue<T extends ConfigValueType>(value: T, type?: ConfigType): string {\n if (type === \"json\") {\n try {\n const json = JSON.stringify(value);\n return djb2Hash(json);\n } catch {\n return value.toString().slice(0, CONFIG_VALUE_MAX_LENGTH);\n }\n }\n\n return value.toString().slice(0, CONFIG_VALUE_MAX_LENGTH);\n }\n\n private flushAndScheduleNext() {\n const response = this.flush();\n if (response.fatalError) {\n this.collectEvents = false;\n this.close();\n this.logger.warn(\n \"[TelemetryEventCollector] Received a fatal error from telemetry collection. No longer collecting events.\",\n );\n } else {\n this.flushTimeout = setTimeout(() => this.flushAndScheduleNext(), this.flushIntervalDelay);\n }\n }\n\n private flush() {\n const evaluationSnapshot = this.evaluationEventQueue.takeSnapshot();\n const response = this.reporter.report({\n discreteEvents: {},\n aggregatedEvents: {\n evaluatedConfig: this.aggregator.aggregate(evaluationSnapshot),\n },\n droppedEvents: {\n evaluatedConfig: evaluationSnapshot.droppedCount,\n },\n });\n return response;\n }\n\n public close() {\n this.collectEvents = false;\n clearTimeout(this.flushTimeout);\n this.flush();\n this.evaluationEventQueue.clear();\n }\n\n public dispose() {\n this.close();\n }\n}\n","import { ConfigDirectorLogger } from \"./types\";\n\nexport const fetchWithTimeout = async (\n timeout: number,\n resource: string | URL | Request,\n options: RequestInit | undefined,\n logger: ConfigDirectorLogger,\n) => {\n const abortController = new AbortController();\n const abortTimeoutId = setTimeout(() => {\n logger.debug(\"[fetchWithTimeout] Reached timeout, aborting request\");\n abortController.abort();\n }, timeout);\n\n try {\n const response = await fetch(resource, {\n ...options,\n signal: abortController.signal,\n });\n clearTimeout(abortTimeoutId);\n return response;\n } catch (error) {\n logger.warn(\"[fetchWithTimeout] Fetch error: \", error);\n clearTimeout(abortTimeoutId);\n throw error;\n }\n};\n","import type {\n ConfigDirectorContext,\n ConfigDirectorLogger,\n Transport,\n TransportEvents,\n TransportOptions,\n} from \"./types\";\nimport { Emitter } from \"./Emitter\";\nimport { ConfigDirectorConnectionError, isFetchErrorFatal } from \"./errors\";\nimport { fetchWithTimeout } from \"./fetchWithTimeout\";\n\nexport class PullTransport implements Transport {\n private logger: ConfigDirectorLogger;\n private eventEmitter = new Emitter<TransportEvents>();\n private url: URL;\n private fatalError = false;\n\n constructor(private readonly options: TransportOptions) {\n this.options = options;\n this.logger = options.logger;\n this.url = new URL(\"pull/v1\", options.baseUrl);\n }\n\n public async connect(context: ConfigDirectorContext, timeout: number): Promise<this> {\n if (this.fatalError) {\n this.logger.warn(\n \"[PullTransport] There was a prior unrecoverable error. Ignoring attempt to reconnect.\",\n );\n return this;\n }\n\n try {\n const response = await fetchWithTimeout(timeout, this.url, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n givenContext: context,\n metaContext: this.options.metaContext,\n clientSdkKey: this.options.clientSdkKey,\n }),\n }, this.logger);\n\n if (!response.ok) {\n if (this.isStatusFatal(response.status)) {\n this.fatalError = true;\n throw this.prepareFatalResponseStatusError(response.status, await response.text());\n } else {\n throw new ConfigDirectorConnectionError(\n `Connection failed with status: ${response.status}`,\n response.status,\n );\n }\n }\n\n const json = JSON.parse(await response.text());\n this.eventEmitter.emit(\"configSetReceived\", json);\n return this;\n } catch (fetchError) {\n if (isFetchErrorFatal(fetchError)) {\n this.fatalError = true;\n throw new ConfigDirectorConnectionError(\n `Connection failed with fatal error: ${fetchError}. This is an unrecoverable error, retry attempts will be ignored.`,\n );\n } else if (fetchError instanceof SyntaxError) {\n throw new ConfigDirectorConnectionError(\n `Failed to parse the response from the server: ${fetchError}`,\n );\n } else {\n throw new ConfigDirectorConnectionError(`Connection failed with error: ${fetchError}.`);\n }\n }\n }\n\n private prepareFatalResponseStatusError(\n responseStatus: number,\n errorBody: string | undefined,\n ): ConfigDirectorConnectionError {\n const status = responseStatus ?? 0;\n const headline = `Connection failed with status: ${responseStatus ?? \"unknown\"}`;\n const serverBody = (errorBody?.trim()?.length ?? 0) > 0 ? ` (${errorBody})` : \"\";\n const message = `${headline}${serverBody}. This is an unrecoverable error, retry attempts will be ignored.`;\n return new ConfigDirectorConnectionError(message, status);\n }\n\n private isStatusFatal(status: number | undefined): boolean {\n return !!status && status >= 400 && status < 500;\n }\n\n public on<TName extends keyof TransportEvents>(\n name: TName,\n handler: (payload: TransportEvents[TName]) => void,\n ): void {\n this.eventEmitter.on(name, handler);\n }\n\n public off<TName extends keyof TransportEvents>(\n name: TName,\n handler?: ((payload: TransportEvents[TName]) => void) | undefined,\n ): void {\n this.eventEmitter.off(name, handler);\n }\n\n public clear(): void {\n this.eventEmitter.clear();\n }\n\n public close() {}\n\n public dispose(): void {\n this.close();\n this.clear();\n }\n}\n","import { Emitter } from \"./Emitter\";\nimport { StreamingTransport } from \"./StreamingTransport\";\nimport { getRequestedType, parseConfigValue } from \"./value-parser\";\nimport {\n ConfigSet,\n ConfigState,\n ConfigStateMap,\n ConfigDirectorContext,\n ConfigDirectorClientOptions,\n ConfigDirectorClient,\n ClientEvents,\n WatchHandler,\n ConfigValueType,\n ConfigDirectorLogger,\n Transport,\n ClientConnectAction,\n IdentifyingSdkOptions,\n} from \"./types\";\nimport { createDefaultLogger } from \"./logger\";\nimport { TelemetryEventCollector } from \"./telemetry\";\nimport { ConfigDirectorValidationError } from \"./errors\";\nimport { PullTransport } from \"./PullTransport\";\n\nconst defaultBaseUrl = new URL(\"https://client-sdk-api.configdirector.com\");\n\ntype WatchHandlerWithOptions<T extends ConfigValueType> = {\n handler: WatchHandler<T>;\n defaultValue: T;\n requestedType: string;\n};\n\nexport class DefaultConfigDirectorClient implements ConfigDirectorClient {\n private logger: ConfigDirectorLogger;\n private usageEventCollector: TelemetryEventCollector;\n private configSet: ConfigSet | undefined;\n private handlersMap: Map<string, WatchHandlerWithOptions<any>[]> = new Map();\n private transport: Transport;\n private eventEmitter = new Emitter<ClientEvents>();\n private timeout: number;\n private ready = false;\n private readyPromise: Promise<void> | undefined;\n private readyResolve: (() => void) | undefined;\n private currentContext?: ConfigDirectorContext;\n private streaming: boolean;\n\n constructor(clientSdkKey: string, sdkOptions: IdentifyingSdkOptions, clientOptions?: ConfigDirectorClientOptions) {\n this.logger = clientOptions?.logger ?? createDefaultLogger();\n this.timeout = clientOptions?.connection?.timeout ?? 3_000;\n const baseUrl = this.parseUrl(clientOptions?.connection?.url) ?? defaultBaseUrl;\n this.streaming = clientOptions?.connection?.streaming === false ? false : true;\n const transportConstructor = this.streaming ? StreamingTransport : PullTransport;\n this.usageEventCollector = new TelemetryEventCollector({\n sdkKey: clientSdkKey,\n logger: this.logger,\n baseUrl,\n });\n this.transport = new transportConstructor({\n clientSdkKey,\n baseUrl,\n metaContext: {\n ...clientOptions?.metadata,\n sdkName: sdkOptions.sdkName,\n sdkVersion: sdkOptions.sdkVersion,\n userAgent: navigator?.userAgent,\n },\n logger: this.logger,\n });\n\n this.transport.on(\"configSetReceived\", (configSet: ConfigSet) => {\n this.readyResolve?.();\n const configKeys = Object.keys(configSet.configs);\n if (!this.configSet || configSet.kind == \"full\") {\n this.configSet = configSet;\n this.eventEmitter.emit(\"configsUpdated\", { keys: configKeys });\n this.updateWatchers(configSet.configs);\n } else {\n this.configSet.configs = {\n ...this.configSet.configs,\n ...configSet.configs,\n };\n this.eventEmitter.emit(\"configsUpdated\", { keys: configKeys });\n this.updateWatchers(configSet.configs);\n }\n this.logger.debug(\"[ConfigDirectorClient] ConfigSet updated from server:\", { keys: configKeys });\n });\n }\n\n public async initialize(context?: ConfigDirectorContext) {\n await this.connectToTransport(context, \"initialization\");\n }\n\n public async updateContext(context: ConfigDirectorContext) {\n await this.connectToTransport(context, \"context update\");\n }\n\n private async connectToTransport(context: ConfigDirectorContext | undefined, caller: ClientConnectAction) {\n try {\n this.ready = false;\n this.readyPromise = new Promise<void>((resolve) => {\n this.readyResolve = resolve;\n }).then(() => {\n this.ready = true;\n this.eventEmitter.emit(\"clientReady\", { action: caller });\n this.logger.debug(\"[ConfigDirectorClient] Received initial payload from the server, client is ready\");\n });\n const startTime = new Date().getTime();\n await this.transport.connect(context ?? {}, this.timeout);\n this.currentContext = context;\n const elapsedTime = (new Date().getTime() - startTime);\n const remainingTimeout = this.timeout - elapsedTime;\n if (remainingTimeout > 0) {\n await Promise.race([\n this.readyPromise,\n new Promise<void>((resolve) => {\n setTimeout(() => resolve(), remainingTimeout);\n }),\n ]);\n }\n if (!this.ready) {\n const warningDetails = this.streaming\n ? \"The client will continue to retry since there were no fatal errors detected. Configs will return the default value until the connection succeeds.\"\n : \"Since the client was configured without streaming, configs may not update and always return the default value.\";\n this.logger.warn(\n `[ConfigDirectorClient] Timed out waiting for ${caller} after ${this.timeout}ms. ${warningDetails}`,\n );\n }\n } catch (error) {\n this.logger.error(`[ConfigDirectorClient] An error occurred during ${caller}: `, error);\n }\n }\n\n private updateWatchers(configsMap: ConfigStateMap) {\n Object.values(configsMap).forEach((v) => this.updateWatchersForConfig(v));\n }\n\n private updateWatchersForConfig(configState: ConfigState) {\n this.handlersMap.get(configState.key)?.forEach((h) => {\n const value = this.getValueFromConfigState(configState.key, configState, h.defaultValue);\n h.handler(value);\n });\n }\n\n public watch<T extends ConfigValueType>(configKey: string, defaultValue: T, callback: WatchHandler<T>) {\n this.validateDefaultValue(defaultValue);\n\n const handlers = this.handlersMap.get(configKey);\n const handlerWithOptions = { handler: callback, defaultValue, requestedType: typeof defaultValue };\n if (handlers) {\n handlers.push(handlerWithOptions);\n } else {\n this.handlersMap.set(configKey, [handlerWithOptions]);\n }\n\n return () => this.unwatch(configKey, callback);\n }\n\n public unwatch<T extends ConfigValueType>(configKey: string, callback?: WatchHandler<T>) {\n const handlers = this.handlersMap.get(configKey);\n if (!handlers) {\n return;\n }\n\n if (callback) {\n const index = handlers.findIndex((h) => h.handler == callback);\n if (index >= 0) {\n handlers?.splice(index, 1);\n }\n } else {\n handlers.splice(0);\n }\n }\n\n public getValue<T extends ConfigValueType>(configKey: string, defaultValue: T): T {\n this.validateDefaultValue(defaultValue);\n\n const configState = this.configSet?.configs[configKey];\n return this.getValueFromConfigState(configKey, configState, defaultValue);\n }\n\n private getValueFromConfigState<T extends ConfigValueType>(\n configKey: string,\n configState: ConfigState | undefined,\n defaultValue: T,\n ): T {\n if (!configState) {\n this.logger.debug(\n `[ConfigDirectorClient] No config state found for '${configKey}', returning default value '${defaultValue}'`,\n );\n this.usageEventCollector.evaluatedConfig({\n contextId: this.currentContext?.id,\n key: configKey,\n defaultValue: defaultValue,\n requestedType: getRequestedType(defaultValue),\n evaluatedValue: defaultValue,\n usedDefault: true,\n evaluationReason: \"config-state-missing\",\n });\n return defaultValue;\n }\n\n const parseResult = parseConfigValue<T>(configState, defaultValue);\n this.usageEventCollector.evaluatedConfig({\n contextId: this.currentContext?.id,\n key: configKey,\n defaultValue: defaultValue,\n requestedType: parseResult.requestedType,\n evaluatedValue: parseResult.parsedValue,\n usedDefault: parseResult.usedDefault,\n evaluationReason: parseResult.reason,\n });\n this.logger.debug(`[ConfigDirectorClient] Evaluated '${configKey}' to '${parseResult.parsedValue}'`);\n return parseResult.parsedValue;\n }\n\n private parseUrl(url: string | undefined): URL | undefined {\n if (!url) {\n return;\n }\n\n try {\n return new URL(url);\n } catch (error) {\n throw new ConfigDirectorValidationError(`Invalid base URL '${url}'. Parsing failed: ${error}`);\n }\n }\n\n private validateDefaultValue<T extends ConfigValueType>(defaultValue: T) {\n if (defaultValue === undefined || defaultValue === null) {\n throw new ConfigDirectorValidationError(\n \"Invalid default value. The default value for a config must be defined and non-null.\",\n );\n }\n\n if (typeof defaultValue === \"function\") {\n throw new ConfigDirectorValidationError(\n \"Invalid default value. The default value for a config cannot be a function.\",\n );\n }\n }\n\n public get isReady(): boolean {\n return this.ready;\n }\n\n public on<T extends keyof ClientEvents>(eventName: T, handler: (event: ClientEvents[T]) => void): void {\n this.eventEmitter.on(eventName, handler);\n }\n\n public off<T extends keyof ClientEvents>(eventName: T, handler?: (payload: ClientEvents[T]) => void) {\n this.eventEmitter.off(eventName, handler);\n }\n\n public clear() {\n this.logger.debug(\"[ConfigDirectorClient] clear() has been called, removing all observers\");\n this.eventEmitter.clear();\n this.handlersMap.clear();\n }\n\n public unwatchAll() {\n this.handlersMap.clear();\n }\n\n public close() {\n this.logger.debug(\"[ConfigDirectorClient] close() has been called, closing connection to server\");\n this.transport.close();\n this.ready = false;\n }\n\n public dispose() {\n this.clear();\n this.close();\n }\n}\n","import {\n ConfigDirectorClient,\n ConfigDirectorClientOptions,\n ConfigDirectorLoggingLevel,\n ConfigDirectorLogMessageDecorator,\n createDefaultLogger,\n DefaultConfigDirectorClient\n} from \"@js-client-core/index\";\n\n/**\n * Creates a `ConfigDirectorClient` object with the given `clientSdkKey` and optional\n * `clientOptions`. The returned client needs to be initialized before it is ready to serve\n * config values.\n *\n * @param clientSdkKey The client SDK key obtained from the ConfigDirector dashboard\n * @param clientOptions {@link ConfigDirectorClientOptions} options for the client (optional)\n * @returns A {@link ConfigDirectorClient} object\n *\n * @example\n * import { createClient } from \"@configdirector/client-sdk\";\n * const client = createClient(\"YOUR-SDK-KEY\");\n * await client.initialize();\n */\nexport const createClient = (\n clientSdkKey: string,\n clientOptions?: ConfigDirectorClientOptions,\n): ConfigDirectorClient => {\n return new DefaultConfigDirectorClient(\n clientSdkKey,\n { sdkName: \"js-client-sdk\", sdkVersion: \"__VERSION__\" },\n clientOptions,\n );\n};\n\nexport const createConsoleLogger = (\n level: ConfigDirectorLoggingLevel,\n messageDecorator?: ConfigDirectorLogMessageDecorator,\n) => {\n return createDefaultLogger(level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1
1
  {
2
2
  "name": "@configdirector/client-sdk",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Javascript client SDK for ConfigDirector. ConfigDirector is a remote configuration and feature flag service.",
5
5
  "license": "MIT",
6
6
  "author": "ConfigDirector",
@@ -33,8 +33,7 @@
33
33
  }
34
34
  },
35
35
  "files": [
36
- "dist/*.js",
37
- "dist/*-client.d.ts"
36
+ "dist/*client.*"
38
37
  ],
39
38
  "types": "dist/configdirector-client.d.mts",
40
39
  "browser": "dist/configdirector-client.mjs",