@configdirector/nuxt-sdk 1.12.0 → 1.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json
CHANGED
|
@@ -8452,7 +8452,7 @@ var plugin_default = defineNitroPlugin((nitroApp) => {
|
|
|
8452
8452
|
logger.debug("Initializing ConfigDirector Nitro plugin");
|
|
8453
8453
|
const client = new DefaultConfigDirectorClient(serverSdkKey || void 0, {
|
|
8454
8454
|
sdkName: "nuxt-sdk",
|
|
8455
|
-
sdkVersion: "1.12.
|
|
8455
|
+
sdkVersion: "1.12.1"
|
|
8456
8456
|
}, {
|
|
8457
8457
|
logger,
|
|
8458
8458
|
connection: {
|
|
@@ -1584,7 +1584,8 @@ var DefaultConfigDirectorClient = class DefaultConfigDirectorClient {
|
|
|
1584
1584
|
clientSdkKey: plan.clientSdkKey,
|
|
1585
1585
|
baseUrl: plan.baseUrl,
|
|
1586
1586
|
logger: this.logger,
|
|
1587
|
-
metadata: clientOptions?.metadata
|
|
1587
|
+
metadata: clientOptions?.metadata,
|
|
1588
|
+
clientSession: this.clientSession
|
|
1588
1589
|
});
|
|
1589
1590
|
}
|
|
1590
1591
|
}
|
|
@@ -1931,6 +1932,7 @@ const DEFAULT_WORKER_CLOSE_TIMEOUT = 6e3;
|
|
|
1931
1932
|
var WebWorkerTelemetryClient = class {
|
|
1932
1933
|
logger;
|
|
1933
1934
|
initializeMessage;
|
|
1935
|
+
clientSession;
|
|
1934
1936
|
worker;
|
|
1935
1937
|
turnedOff = false;
|
|
1936
1938
|
pendingEvaluations = [];
|
|
@@ -1945,6 +1947,7 @@ var WebWorkerTelemetryClient = class {
|
|
|
1945
1947
|
this.logger = options.logger;
|
|
1946
1948
|
this.workerCloseTimeout = options.workerCloseTimeout ?? DEFAULT_WORKER_CLOSE_TIMEOUT;
|
|
1947
1949
|
this.pendingEvaluationLimit = options.evaluationQueueLimit ?? 1e3;
|
|
1950
|
+
this.clientSession = options.clientSession;
|
|
1948
1951
|
this.initializeMessage = {
|
|
1949
1952
|
type: "Initialize",
|
|
1950
1953
|
payload: {
|
|
@@ -1967,7 +1970,7 @@ var WebWorkerTelemetryClient = class {
|
|
|
1967
1970
|
return;
|
|
1968
1971
|
}
|
|
1969
1972
|
try {
|
|
1970
|
-
return new Worker(URL.createObjectURL(new Blob(["(function(){let e=async(e,t)=>e.valueId?{valueId:e.valueId}:e.value?e.value.length<=500&&e.type!=`json`?{value:e.value}:{valueId:await t(e.value)}:e,t=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},n=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},r=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(typeof t==`string`||t instanceof Request?t:t.toString(),{...n,signal:i.signal});return clearTimeout(a),e}catch(e){throw r.warn(`[fetchWithTimeout] Fetch error: `,e),clearTimeout(a),e}},i=e=>e?.name===`NotAllowedError`?!0:e instanceof TypeError;var a=class{constructor(e){this.executeRequests=!0,this.sdkKey=e.sdkKey,this.logger=e.logger,this.sdkIdentity=e.sdkIdentity,this.metaContext=e.metaContext,this.url=e.urlFactory(`client/telemetry/v1`,e.baseUrl)}async report({context:e,discreteEvents:t,aggregatedEvents:n,droppedEvents:r}){if(!this.executeRequests)return{success:!1,fatalError:!0};let
|
|
1973
|
+
return new Worker(URL.createObjectURL(new Blob(["(function(){let e=async(e,t)=>e.valueId?{valueId:e.valueId}:e.value?e.value.length<=500&&e.type!=`json`?{value:e.value}:{valueId:await t(e.value)}:e,t=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},n=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},r=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(typeof t==`string`||t instanceof Request?t:t.toString(),{...n,signal:i.signal});return clearTimeout(a),e}catch(e){throw r.warn(`[fetchWithTimeout] Fetch error: `,e),clearTimeout(a),e}},i=e=>e?.name===`NotAllowedError`?!0:e instanceof TypeError;var a=class{constructor(e){this.executeRequests=!0,this.sdkKey=e.sdkKey,this.logger=e.logger,this.sdkIdentity=e.sdkIdentity,this.metaContext=e.metaContext,this.url=e.urlFactory(`client/telemetry/v1`,e.baseUrl),this.clientSession=e.clientSession}async report({context:e,discreteEvents:t,aggregatedEvents:n,droppedEvents:r}){if(!this.executeRequests)return{success:!1,fatalError:!0};let{instanceId:i}=await this.clientSession,a={clientSdkKey:this.sdkKey,instanceId:i,metaContext:{sdkName:this.sdkIdentity.sdkName,sdkVersion:this.sdkIdentity.sdkVersion,appName:this.metaContext.appName,appVersion:this.metaContext.appVersion},context:e,discreteEvents:t,aggregatedEvents:n,droppedEvents:r};if(this.isReportEmpty(a))return{success:!0,fatalError:!1};let o=await this.sendReport(a);return o.fatalError&&(this.executeRequests=!1),o}isReportEmpty(e){return t(e.discreteEvents)&&t(e.aggregatedEvents)&&n(e.droppedEvents)}async sendReport(e){try{let t=await r(5e3,this.url,{method:`POST`,body:JSON.stringify(e),keepalive:!0},this.logger),n=this.isStatusFatal(t.status);return n&&this.logger.warn(`[EventReporter] Received a fatal status response (${t.status}) from the telemetry endpoint. No more telemetry data will be sent.`),{success:t.ok,fatalError:n}}catch(e){let t=i(e);return this.logger.warn(`[EventReporter] Error attempting to send telemetry data: ${e}`,{error:e}),{success:!1,fatalError:t}}}isStatusFatal(e){return!!e&&e>=400&&e<500&&e!=429}},o=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}))}},s=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}},c=class{constructor(e){this.aggregator=new o,this.collectEvents=!0,this.started=!1,this.logger=e.logger,this.evaluationEventQueue=new s(e.evaluationQueueLimit??1e3),this.flushIntervalDelay=e.flushIntervalDelay??3e4,this.initialFlushIntervalDelay=e.initialFlushIntervalDelay??5e3}start(){this.started||!this.collectEvents||(this.started=!0,this.flushTimeout=setTimeout(()=>this.flushAndScheduleNext(),this.initialFlushIntervalDelay))}async flushAndScheduleNext(){if(!this.collectEvents)return;let e;try{e=await this.flush()}catch(t){this.logger.warn(`[TelemetryEventCollector] Error flushing telemetry events: `,t),e={success:!1,fatalError:!1}}e.fatalError?(this.collectEvents=!1,this.close(),this.logger.warn(`[TelemetryEventCollector] Received a fatal error from telemetry collection. No longer collecting events.`)):this.collectEvents&&(this.cancelScheduledFlush(),this.flushTimeout=setTimeout(()=>this.flushAndScheduleNext(),this.flushIntervalDelay))}cancelScheduledFlush(){clearTimeout(this.flushTimeout)}async close(){this.collectEvents=!1,clearTimeout(this.flushTimeout);try{await this.flush()}catch(e){this.logger.warn(`[TelemetryEventCollector] Error flushing telemetry events during close: `,e)}this.evaluationEventQueue.clear()}dispose(){this.close()}},l=class{constructor(e){this.valueIdGenerator=e,this.valueIdGenerator=e}async process(t){let n=await Promise.all(t.events.map(async t=>({...t,defaultValue:await e(t.defaultValue,this.valueIdGenerator),evaluatedValue:await e(t.evaluatedValue,this.valueIdGenerator)})));return{...t,events:n}}},u=class{constructor(){this.countsByKindSample=new Map,this.countBeyondSampleLimit=0}record(e){return this.startTime??=new Date,this.add(e,1)}absorb(e){for(let t of e)(this.startTime===void 0||t.startTime<this.startTime)&&(this.startTime=t.startTime),this.add(t.event.kindSample,t.count)}add(e,t){if(e!==void 0){let n=this.countsByKindSample.get(e);if(n!==void 0)return this.countsByKindSample.set(e,n+t),`known-kind-sample`;if(this.countsByKindSample.size<20)return this.countsByKindSample.set(e,t),`new-kind-sample`}let n=this.countBeyondSampleLimit===0;return this.countBeyondSampleLimit+=t,n?`first-beyond-sample-limit`:`beyond-sample-limit`}takeSnapshot(){let e=new Date,t=this.startTime??e,n=(n,r)=>({startTime:t,endTime:e,count:n,event:{reason:`invalid-context-kind`,kindSample:r}}),r=Array.from(this.countsByKindSample,([e,t])=>n(t,e)),i=this.countBeyondSampleLimit>0?[...r,n(this.countBeyondSampleLimit)]:r;return this.clear(),i}clear(){this.countsByKindSample.clear(),this.countBeyondSampleLimit=0,this.startTime=void 0}},d=class extends c{constructor(e){super(e),this.invalidContextSubmissions=new u,this.reporter=new a(e),this.evaluationEventSnapshotPreprocessor=new l(e.valueIdGenerator)}async updateContext(e){this.cancelScheduledFlush(),await this.flush(),this._context=e,await this.flushAndScheduleNext()}evaluatedConfig(e){this.collectEvents&&this.evaluationEventQueue.push(e)}recordInvalidContext(e){this.invalidContextSubmissions.record(e)}absorbInvalidContextSubmissions(e){this.invalidContextSubmissions.absorb(e)}async forceFlush(){this.cancelScheduledFlush(),await this.flushAndScheduleNext()}async flush(){if(!this.reporter)return{success:!1,fatalError:!1};let e=await this.evaluationEventSnapshotPreprocessor.process(this.evaluationEventQueue.takeSnapshot());return await this.reporter?.report({context:this._context,discreteEvents:{},aggregatedEvents:{evaluatedConfig:this.aggregator.aggregate(e),invalidContext:this.invalidContextSubmissions.takeSnapshot()},droppedEvents:{evaluatedConfig:e.droppedCount}})}};let f=(e,t)=>new URL(e,t?.toString()),p=(e,t)=>{let n=BigInt(0),r=BigInt(62),i=Array.from(e).map(e=>e.toString(16).padStart(2,`0`)).join(``),a=BigInt(`0x`+i),o=``;for(;a>n;)o=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`[Number(a%r)]+o,a/=r;return o.padStart(t,`0`)},m=Math.ceil(128/Math.log2(62)),h=new TextEncoder,g=async e=>{if(typeof crypto>`u`||crypto.subtle==null)return;let t=await crypto.subtle.digest(`SHA-256`,h.encode(e?.toString()??``));return p(new Uint8Array(t,0,16),m)},_,v,y=new Promise(e=>{v=e}),b=(e,t,...n)=>({type:`Log`,payload:{level:e,message:t,args:n}}),x=e=>{try{self.postMessage(e)}catch{self.postMessage(b(e.payload.level,e.payload.message))}},S={debug:function(e,...t){x(b(`debug`,e,t))},info:function(e,...t){x(b(`info`,e,t))},warn:function(e,...t){x(b(`warn`,e,t))},error:function(e,...t){x(b(`error`,e,t))}};addEventListener(`message`,e=>{let t=e.data;if(t.type!=`Initialize`&&!_){S.info(`[TelemetryWorker] Ignoring ${t.type} because no collector is configured`);return}switch(S.debug(`[TelemetryWorker] Received '${t.type}' event:`,t),t.type){case`Initialize`:if(_){S.warn(`[TelemetryWorker] Received a duplicate Initialize event, ignoring it`);break}_=new d({...t.payload,baseUrl:f(t.payload.baseUrl),urlFactory:f,valueIdGenerator:g,logger:S,clientSession:y}),_.start();break;case`ClientSession`:v(t.payload);break;case`EvaluatedConfigEvent`:_?.evaluatedConfig(t.payload);break;case`InvalidContextSubmissions`:_?.absorbInvalidContextSubmissions(t.payload.entries);break;case`UpdateContext`:_?.updateContext(t.payload.context);break;case`Flush`:_?.forceFlush();break;case`Close`:(_?.close()??Promise.resolve()).then(()=>{self.postMessage({type:`Closed`}),self.close()});break}})})();"], { type: "application/javascript" })));
|
|
1971
1974
|
} catch (error) {
|
|
1972
1975
|
this.turnOff("[WebWorkerTelemetryClient] Telemetry is off because the telemetry Web Worker could not be created: ", error);
|
|
1973
1976
|
return;
|
|
@@ -1986,6 +1989,7 @@ var WebWorkerTelemetryClient = class {
|
|
|
1986
1989
|
this.handleWorkerEvent(message.data);
|
|
1987
1990
|
};
|
|
1988
1991
|
worker.postMessage(this.initializeMessage);
|
|
1992
|
+
this.forwardClientSession(worker);
|
|
1989
1993
|
this.worker = worker;
|
|
1990
1994
|
try {
|
|
1991
1995
|
document.addEventListener("visibilitychange", this.visibilityHandler);
|
|
@@ -1997,6 +2001,15 @@ var WebWorkerTelemetryClient = class {
|
|
|
1997
2001
|
this.forwardInvalidContextSubmissions(worker);
|
|
1998
2002
|
return worker;
|
|
1999
2003
|
}
|
|
2004
|
+
forwardClientSession(worker) {
|
|
2005
|
+
this.clientSession.then((clientSession) => {
|
|
2006
|
+
const clientSessionMessage = {
|
|
2007
|
+
type: "ClientSession",
|
|
2008
|
+
payload: clientSession
|
|
2009
|
+
};
|
|
2010
|
+
worker.postMessage(clientSessionMessage);
|
|
2011
|
+
});
|
|
2012
|
+
}
|
|
2000
2013
|
forwardInvalidContextSubmissions(worker) {
|
|
2001
2014
|
if (!worker) return;
|
|
2002
2015
|
const entries = this.pendingInvalidContextSubmissions.takeSnapshot();
|
|
@@ -2156,7 +2169,7 @@ const localStorageCachingProvider = (clientSdkKey) => {
|
|
|
2156
2169
|
* and fails like a missing key otherwise.
|
|
2157
2170
|
*/
|
|
2158
2171
|
const createBrowserClient = (clientSdkKeyOrOptions, sdkOptions, clientOptions) => {
|
|
2159
|
-
return DefaultConfigDirectorClient.from(({ clientSdkKey, baseUrl, logger, metadata }) => new WebWorkerTelemetryClient({
|
|
2172
|
+
return DefaultConfigDirectorClient.from(({ clientSdkKey, baseUrl, logger, metadata, clientSession }) => new WebWorkerTelemetryClient({
|
|
2160
2173
|
sdkKey: clientSdkKey,
|
|
2161
2174
|
sdkIdentity: {
|
|
2162
2175
|
sdkName: sdkOptions.sdkName,
|
|
@@ -2169,7 +2182,8 @@ const createBrowserClient = (clientSdkKeyOrOptions, sdkOptions, clientOptions) =
|
|
|
2169
2182
|
logger,
|
|
2170
2183
|
baseUrl,
|
|
2171
2184
|
urlFactory: defaultUrlFactory,
|
|
2172
|
-
valueIdGenerator: generateValueId
|
|
2185
|
+
valueIdGenerator: generateValueId,
|
|
2186
|
+
clientSession
|
|
2173
2187
|
}), clientSdkKeyOrOptions, sdkOptions, clientOptions, { platformCachingProvider: localStorageCachingProvider });
|
|
2174
2188
|
};
|
|
2175
2189
|
//#endregion
|
|
@@ -2337,7 +2351,7 @@ const buildClient = async (configdirector, logger) => {
|
|
|
2337
2351
|
return {
|
|
2338
2352
|
client: createBrowserClient(configdirector?.clientSdkKey || void 0, {
|
|
2339
2353
|
sdkName: "nuxt-sdk",
|
|
2340
|
-
sdkVersion: "1.12.
|
|
2354
|
+
sdkVersion: "1.12.1"
|
|
2341
2355
|
}, {
|
|
2342
2356
|
metadata: {
|
|
2343
2357
|
appName: configdirector?.appName,
|
package/dist/testing.mjs
CHANGED
|
@@ -1575,7 +1575,8 @@ var DefaultConfigDirectorClient = class DefaultConfigDirectorClient {
|
|
|
1575
1575
|
clientSdkKey: plan.clientSdkKey,
|
|
1576
1576
|
baseUrl: plan.baseUrl,
|
|
1577
1577
|
logger: this.logger,
|
|
1578
|
-
metadata: clientOptions?.metadata
|
|
1578
|
+
metadata: clientOptions?.metadata,
|
|
1579
|
+
clientSession: this.clientSession
|
|
1579
1580
|
});
|
|
1580
1581
|
}
|
|
1581
1582
|
}
|
|
@@ -2130,7 +2131,7 @@ const installTestClient = (testClient) => {
|
|
|
2130
2131
|
const createTestClient = (options) => {
|
|
2131
2132
|
return createTestClient$1({
|
|
2132
2133
|
sdkName: "nuxt-sdk",
|
|
2133
|
-
sdkVersion: "1.12.
|
|
2134
|
+
sdkVersion: "1.12.1"
|
|
2134
2135
|
}, options);
|
|
2135
2136
|
};
|
|
2136
2137
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@configdirector/nuxt-sdk",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.1",
|
|
4
4
|
"description": "Nuxt SDK for ConfigDirector. ConfigDirector is a remote configuration and feature flag service.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "ConfigDirector",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"eslint": "^10.7.0",
|
|
74
74
|
"jsdom": "^30.0.1",
|
|
75
75
|
"nuxt": "^4.5.2",
|
|
76
|
-
"playwright": "^1.
|
|
76
|
+
"playwright": "^1.64.1",
|
|
77
77
|
"rimraf": "^6.1.3",
|
|
78
78
|
"tsdown": "^0.21.7",
|
|
79
79
|
"tslib": "^2.8.1",
|