@configdirector/nextjs-sdk 1.13.0 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/client/index.cjs +1 -1
  2. package/dist/client/index.d.cts +2 -2
  3. package/dist/client/index.d.mts +2 -2
  4. package/dist/client/index.mjs +1 -1
  5. package/dist/client/index.mjs.map +1 -1
  6. package/dist/client/installedTestClient-Bam5r_HR.cjs +6 -0
  7. package/dist/client/installedTestClient-CL4AQC58.mjs +7 -0
  8. package/dist/client/installedTestClient-CL4AQC58.mjs.map +1 -0
  9. package/dist/client/testing.cjs +1 -1
  10. package/dist/client/testing.d.cts +12 -3
  11. package/dist/client/testing.d.cts.map +1 -1
  12. package/dist/client/testing.d.mts +12 -3
  13. package/dist/client/testing.d.mts.map +1 -1
  14. package/dist/client/testing.mjs +1 -1
  15. package/dist/client/testing.mjs.map +1 -1
  16. package/dist/client/{types-CRVL6Yi2.d.cts → types-CdyMdj5l.d.mts} +75 -7
  17. package/dist/client/types-CdyMdj5l.d.mts.map +1 -0
  18. package/dist/client/{types-B4kvU3bh.d.mts → types-P8frfCGH.d.cts} +75 -7
  19. package/dist/client/types-P8frfCGH.d.cts.map +1 -0
  20. package/dist/server/DefaultConfigDirectorClient-LQ79aY-g.mjs +6 -0
  21. package/dist/server/DefaultConfigDirectorClient-LQ79aY-g.mjs.map +1 -0
  22. package/dist/server/DefaultConfigDirectorClient-VHa0AfMj.cjs +5 -0
  23. package/dist/server/{errors-CxXHE84y.d.mts → errors-CkxBFyZy.d.cts} +76 -7
  24. package/dist/server/errors-CkxBFyZy.d.cts.map +1 -0
  25. package/dist/server/{errors-Do5xWGgb.d.cts → errors-CsEeGYMl.d.mts} +76 -7
  26. package/dist/server/errors-CsEeGYMl.d.mts.map +1 -0
  27. package/dist/server/index.cjs +1 -1
  28. package/dist/server/index.d.cts +2 -2
  29. package/dist/server/index.d.cts.map +1 -1
  30. package/dist/server/index.d.mts +2 -2
  31. package/dist/server/index.d.mts.map +1 -1
  32. package/dist/server/index.mjs +1 -1
  33. package/dist/server/testing.cjs +1 -1
  34. package/dist/server/testing.d.cts +12 -3
  35. package/dist/server/testing.d.cts.map +1 -1
  36. package/dist/server/testing.d.mts +12 -3
  37. package/dist/server/testing.d.mts.map +1 -1
  38. package/dist/server/testing.mjs +1 -1
  39. package/dist/server/testing.mjs.map +1 -1
  40. package/package.json +1 -1
  41. package/dist/client/installedTestClient-Byj9k8cX.cjs +0 -6
  42. package/dist/client/installedTestClient-DNVY-qrM.mjs +0 -7
  43. package/dist/client/installedTestClient-DNVY-qrM.mjs.map +0 -1
  44. package/dist/client/types-B4kvU3bh.d.mts.map +0 -1
  45. package/dist/client/types-CRVL6Yi2.d.cts.map +0 -1
  46. package/dist/server/DefaultConfigDirectorClient-BfpJX-Ni.mjs +0 -6
  47. package/dist/server/DefaultConfigDirectorClient-BfpJX-Ni.mjs.map +0 -1
  48. package/dist/server/DefaultConfigDirectorClient-C4cOinqO.cjs +0 -5
  49. package/dist/server/errors-CxXHE84y.d.mts.map +0 -1
  50. package/dist/server/errors-Do5xWGgb.d.cts.map +0 -1
@@ -1,5 +1,5 @@
1
1
 
2
- import { a as NativeJsonValue, c as ConfigDirectorContext, l as ConfigDirectorLogger, n as ConfigDirectorClient, o as NativeValue, s as NativeValues } from "./types-CRVL6Yi2.cjs";
2
+ import { _ as TrackedEvent, a as NativeJsonValue, c as ConfigDirectorContext, l as ConfigDirectorLogger, n as ConfigDirectorClient, o as NativeValue, s as NativeValues, v as TrackedEventDetailValue, y as TrackedEventDetails } from "./types-P8frfCGH.cjs";
3
3
 
4
4
  //#region ../shared/src/errors.d.ts
5
5
  declare class ConfigDirectorConnectionError extends Error {
@@ -29,7 +29,9 @@ type TestClientOptions = {
29
29
  */
30
30
  timeout?: number;
31
31
  /**
32
- * The logger the SDK client uses. Defaults to the SDK's console logger at `warn` level.
32
+ * The logger the SDK client uses. Defaults to the SDK's console logger at `warn` level. Since the
33
+ * test client sends no telemetry, every tracked event that is not recorded as it was tracked logs
34
+ * a warning, rather than each cause once per telemetry batch.
33
35
  */
34
36
  logger?: ConfigDirectorLogger;
35
37
  };
@@ -98,6 +100,13 @@ interface TestClient {
98
100
  * the client connects without it. Resumes are not recorded.
99
101
  */
100
102
  readonly contextUpdates: ConfigDirectorContext[];
103
+ /**
104
+ * Every event the code under test tracked through the client, in call order, with the context
105
+ * the client had at that moment, as the SDK would report it: an event whose name does not have
106
+ * 1 to 150 characters is not recorded, and a value or details the SDK would leave out are missing
107
+ * from the record. The limit of 1,000 events per telemetry batch does not apply.
108
+ */
109
+ readonly trackedEvents: TrackedEvent[];
101
110
  }
102
111
  //#endregion
103
112
  //#region ../js-client-core/src/testing/installTestClient.d.ts
@@ -147,5 +156,5 @@ declare const installTestClient: (testClient: TestClient) => (() => void);
147
156
  */
148
157
  declare const createTestClient: (options?: TestClientOptions) => TestClient;
149
158
  //#endregion
150
- export { ConfigDirectorConnectionError, ConfigDirectorValidationError, type TestClient, type TestClientOptions, type NativeJsonValue as TestJsonValue, type NativeValue as TestValue, type NativeValues as TestValues, createTestClient, installTestClient };
159
+ export { ConfigDirectorConnectionError, ConfigDirectorValidationError, type TestClient, type TestClientOptions, type NativeJsonValue as TestJsonValue, type NativeValue as TestValue, type NativeValues as TestValues, type TrackedEvent, type TrackedEventDetailValue, type TrackedEventDetails, createTestClient, installTestClient };
151
160
  //# sourceMappingURL=testing.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"testing.d.cts","names":[],"sources":["../../../shared/src/errors.ts","../../../js-client-core/src/testing/TestClient.ts","../../../js-client-core/src/testing/installTestClient.ts","../../src/client/testing.ts"],"mappings":";;;;cAAa,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;;;;AAfd;;KCYY,iBAAA;EDZ4C;;;;;ECkBtD,MAAA,GAAS,YAAA;EDdoB;;;AAQ/B;ECWE,OAAA;;;;EAIA,MAAA,GAAS,oBAAA;AAAA;;;;;;;AAfX;;UA0BiB,UAAA;EAXc;;;;EAAA,SAgBpB,MAAA,EAAQ,oBAAA;EAhBR;;;AAWX;EAWE,QAAA,CAAS,GAAA,UAAa,KAAA,EAAO,WAAA;;;;;EAM7B,WAAA,CAAY,GAAA;EAiDkC;;;;EA3C9C,aAAA,CAAc,MAAA,EAAQ,YAAA;EAZb;;;;EAkBT,kBAAA;EANA;;;;EAYA,sBAAA;EAMA;;;;EAAA,kBAAA;EAyByB;;;;EAnBzB,iBAAA;;AC7DF;;;EDmEE,qBAAA;ECnEsD;;;;EDyEtD,iBAAA;EElED;;;;;EAAA,SFyEU,cAAA,EAAgB,qBAAA;AAAA;;;;;ADxG3B;;;;;;;;;;;;AAYA;;;;;;;cEYa,iBAAA,GAAqB,UAAA,EAAY,UAAA;;;;;;;;;;;;;;AFZ9C;;;;;;;;;cGiBa,gBAAA,GAAoB,OAAA,GAAU,iBAAA,KAAoB,UAAA"}
1
+ {"version":3,"file":"testing.d.cts","names":[],"sources":["../../../shared/src/errors.ts","../../../js-client-core/src/testing/TestClient.ts","../../../js-client-core/src/testing/installTestClient.ts","../../src/client/testing.ts"],"mappings":";;;;cAAa,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;;;;AAfd;;KCmBY,iBAAA;EDnB4C;;;;;ECyBtD,MAAA,GAAS,YAAA;EDrBoB;;;AAQ/B;ECkBE,OAAA;;;;;;EAMA,MAAA,GAAS,oBAAA;AAAA;;;;;AAjBX;;;;UA4BiB,UAAA;EAtBN;;;;EAAA,SA2BA,MAAA,EAAQ,oBAAA;EAhBY;AAW/B;;;EAWE,QAAA,CAAS,GAAA,UAAa,KAAA,EAAO,WAAA;EAAA;;;;EAM7B,WAAA,CAAY,GAAA;EAyDwB;;;;EAnDpC,aAAA,CAAc,MAAA,EAAQ,YAAA;EAZO;;;;EAkB7B,kBAAA;EANsB;;;;EAYtB,sBAAA;EAYA;;;;EANA,kBAAA;EAiCS;;;;EA3BT,iBAAA;;;ACtEF;;ED4EE,qBAAA;EC5E4C;;;;EDkF5C,iBAAA;EE5EW;;;;;EAAA,SFmFF,cAAA,EAAgB,qBAAA;EEnFoC;;;;;;EAAA,SF2FpD,aAAA,EAAe,YAAA;AAAA;;;;;ADzH1B;;;;;;;;;;;;AAYA;;;;;;;cEYa,iBAAA,GAAqB,UAAA,EAAY,UAAA;;;;;;;;;;;;;AFZ9C;;;;;;;;;;cGkBa,gBAAA,GAAoB,OAAA,GAAU,iBAAA,KAAoB,UAAA"}
@@ -1,5 +1,5 @@
1
1
 
2
- import { a as NativeJsonValue, c as ConfigDirectorContext, l as ConfigDirectorLogger, n as ConfigDirectorClient, o as NativeValue, s as NativeValues } from "./types-B4kvU3bh.mjs";
2
+ import { _ as TrackedEvent, a as NativeJsonValue, c as ConfigDirectorContext, l as ConfigDirectorLogger, n as ConfigDirectorClient, o as NativeValue, s as NativeValues, v as TrackedEventDetailValue, y as TrackedEventDetails } from "./types-CdyMdj5l.mjs";
3
3
 
4
4
  //#region ../shared/src/errors.d.ts
5
5
  declare class ConfigDirectorConnectionError extends Error {
@@ -29,7 +29,9 @@ type TestClientOptions = {
29
29
  */
30
30
  timeout?: number;
31
31
  /**
32
- * The logger the SDK client uses. Defaults to the SDK's console logger at `warn` level.
32
+ * The logger the SDK client uses. Defaults to the SDK's console logger at `warn` level. Since the
33
+ * test client sends no telemetry, every tracked event that is not recorded as it was tracked logs
34
+ * a warning, rather than each cause once per telemetry batch.
33
35
  */
34
36
  logger?: ConfigDirectorLogger;
35
37
  };
@@ -98,6 +100,13 @@ interface TestClient {
98
100
  * the client connects without it. Resumes are not recorded.
99
101
  */
100
102
  readonly contextUpdates: ConfigDirectorContext[];
103
+ /**
104
+ * Every event the code under test tracked through the client, in call order, with the context
105
+ * the client had at that moment, as the SDK would report it: an event whose name does not have
106
+ * 1 to 150 characters is not recorded, and a value or details the SDK would leave out are missing
107
+ * from the record. The limit of 1,000 events per telemetry batch does not apply.
108
+ */
109
+ readonly trackedEvents: TrackedEvent[];
101
110
  }
102
111
  //#endregion
103
112
  //#region ../js-client-core/src/testing/installTestClient.d.ts
@@ -147,5 +156,5 @@ declare const installTestClient: (testClient: TestClient) => (() => void);
147
156
  */
148
157
  declare const createTestClient: (options?: TestClientOptions) => TestClient;
149
158
  //#endregion
150
- export { ConfigDirectorConnectionError, ConfigDirectorValidationError, type TestClient, type TestClientOptions, type NativeJsonValue as TestJsonValue, type NativeValue as TestValue, type NativeValues as TestValues, createTestClient, installTestClient };
159
+ export { ConfigDirectorConnectionError, ConfigDirectorValidationError, type TestClient, type TestClientOptions, type NativeJsonValue as TestJsonValue, type NativeValue as TestValue, type NativeValues as TestValues, type TrackedEvent, type TrackedEventDetailValue, type TrackedEventDetails, createTestClient, installTestClient };
151
160
  //# sourceMappingURL=testing.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"testing.d.mts","names":[],"sources":["../../../shared/src/errors.ts","../../../js-client-core/src/testing/TestClient.ts","../../../js-client-core/src/testing/installTestClient.ts","../../src/client/testing.ts"],"mappings":";;;;cAAa,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;;;;AAfd;;KCYY,iBAAA;EDZ4C;;;;;ECkBtD,MAAA,GAAS,YAAA;EDdoB;;;AAQ/B;ECWE,OAAA;;;;EAIA,MAAA,GAAS,oBAAA;AAAA;;;;;;;AAfX;;UA0BiB,UAAA;EAXc;;;;EAAA,SAgBpB,MAAA,EAAQ,oBAAA;EAhBR;;;AAWX;EAWE,QAAA,CAAS,GAAA,UAAa,KAAA,EAAO,WAAA;;;;;EAM7B,WAAA,CAAY,GAAA;EAiDkC;;;;EA3C9C,aAAA,CAAc,MAAA,EAAQ,YAAA;EAZb;;;;EAkBT,kBAAA;EANA;;;;EAYA,sBAAA;EAMA;;;;EAAA,kBAAA;EAyByB;;;;EAnBzB,iBAAA;;AC7DF;;;EDmEE,qBAAA;ECnEsD;;;;EDyEtD,iBAAA;EElED;;;;;EAAA,SFyEU,cAAA,EAAgB,qBAAA;AAAA;;;;;ADxG3B;;;;;;;;;;;;AAYA;;;;;;;cEYa,iBAAA,GAAqB,UAAA,EAAY,UAAA;;;;;;;;;;;;;;AFZ9C;;;;;;;;;cGiBa,gBAAA,GAAoB,OAAA,GAAU,iBAAA,KAAoB,UAAA"}
1
+ {"version":3,"file":"testing.d.mts","names":[],"sources":["../../../shared/src/errors.ts","../../../js-client-core/src/testing/TestClient.ts","../../../js-client-core/src/testing/installTestClient.ts","../../src/client/testing.ts"],"mappings":";;;;cAAa,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;;;;AAfd;;KCmBY,iBAAA;EDnB4C;;;;;ECyBtD,MAAA,GAAS,YAAA;EDrBoB;;;AAQ/B;ECkBE,OAAA;;;;;;EAMA,MAAA,GAAS,oBAAA;AAAA;;;;;AAjBX;;;;UA4BiB,UAAA;EAtBN;;;;EAAA,SA2BA,MAAA,EAAQ,oBAAA;EAhBY;AAW/B;;;EAWE,QAAA,CAAS,GAAA,UAAa,KAAA,EAAO,WAAA;EAAA;;;;EAM7B,WAAA,CAAY,GAAA;EAyDwB;;;;EAnDpC,aAAA,CAAc,MAAA,EAAQ,YAAA;EAZO;;;;EAkB7B,kBAAA;EANsB;;;;EAYtB,sBAAA;EAYA;;;;EANA,kBAAA;EAiCS;;;;EA3BT,iBAAA;;;ACtEF;;ED4EE,qBAAA;EC5E4C;;;;EDkF5C,iBAAA;EE5EW;;;;;EAAA,SFmFF,cAAA,EAAgB,qBAAA;EEnFoC;;;;;;EAAA,SF2FpD,aAAA,EAAe,YAAA;AAAA;;;;;ADzH1B;;;;;;;;;;;;AAYA;;;;;;;cEYa,iBAAA,GAAqB,UAAA,EAAY,UAAA;;;;;;;;;;;;;AFZ9C;;;;;;;;;;cGkBa,gBAAA,GAAoB,OAAA,GAAU,iBAAA,KAAoB,UAAA"}
@@ -1,3 +1,3 @@
1
1
  "use client";
2
- "use client";import{c as e,d as t,f as n,h as r,l as i,m as a,p as o,r as s,t as c}from"./installedTestClient-DNVY-qrM.mjs";const l={environmentId:`test-environment`,projectId:`test-project`},u=e=>{switch(e){case`initialization`:return`initialize`;case`context update`:return`updateContext`;default:return}};var d=class{constructor(e,t){this.logger=e,this.emitter=new a,this.configs=new Map,this.recordedContexts=[],this.pendingDeliveries=[],this.armed={initialize:`nothing`,updateContext:`nothing`},this.connected=!1,this.delivering=!1,this.revision=0,this.attemptGeneration=0,this.on=(e,t)=>this.emitter.on(e,t),this.off=(e,t)=>this.emitter.off(e,t),this.store(t)}get contextUpdates(){return[...this.recordedContexts]}setValue(e,t){let n=this.encode(e,t);this.configs.set(e,n),this.deliverIfConnected(r(r({},l),{},{kind:`delta`,configs:{[e]:n}}))}removeValue(e){this.configs.delete(e),this.deliverIfConnected(this.fullUpdate())}replaceValues(e){let t=this.encodeAll(e);this.configs.clear(),t.forEach((e,t)=>this.configs.set(t,e)),this.armed.initialize=`nothing`,this.armed.updateContext=`nothing`,this.deliverIfConnected(this.fullUpdate())}hold(e){this.armed[e]=`hold`}complete(e){var t;((t=this.pendingHold)==null?void 0:t.attempt)===e?this.pendingHold.complete():this.armed[e]===`hold`&&(this.armed[e]=`nothing`)}fail(e){var t;((t=this.pendingHold)==null?void 0:t.attempt)===e?this.pendingHold.fail():this.armed[e]=`failure`}connect(e,t,n){this.endAttempt();let r=u(n);if(!r)return this.connectNow();this.recordedContexts.push(e);let i=this.armed[r];switch(this.armed[r]=`nothing`,i){case`failure`:return this.failNow(n);case`hold`:return this.holdNow(r,n,t);default:return this.connectNow()}}clear(){this.emitter.clear()}close(){this.endAttempt()}dispose(){this.close(),this.clear()}endAttempt(){var e;this.attemptGeneration++,this.connected=!1,(e=this.pendingHold)==null||e.end()}connectNow(){let e=Promise.resolve(this);return this.scheduleFirstDelivery(),e}holdNow(e,t,n){return new Promise((r,i)=>{let a=setTimeout(()=>{var e;return(e=this.pendingHold)==null?void 0:e.end()},n),o=()=>{clearTimeout(a),this.pendingHold=void 0};this.pendingHold={attempt:e,end:()=>{o(),r(this)},complete:()=>{o(),r(this),this.scheduleFirstDelivery()},fail:()=>{o();let e=this.fatalError(t);this.emitter.emit(`connectionError`,e),i(e)}}})}failNow(e){let t=this.fatalError(e);return this.emitter.emit(`connectionError`,t),Promise.reject(t)}fatalError(e){return new n(`Connection failed with status: 401. Error: the test client failed this ${e}. This is an unrecoverable error, will not attempt to reconnect.`,401)}scheduleFirstDelivery(){let e=this.attemptGeneration;Promise.resolve().then(()=>{}).then(()=>{e===this.attemptGeneration&&(this.connected=!0,this.deliver(this.fullUpdate()))})}deliverIfConnected(e){this.connected&&this.deliver(e)}deliver(e){if(this.pendingDeliveries.push(e),!this.delivering){this.delivering=!0;try{let e=this.pendingDeliveries.shift();for(;e;)this.emitCaught(e),e=this.pendingDeliveries.shift()}finally{this.delivering=!1}}}emitCaught(e){try{this.emitter.emit(`configSetReceived`,e)}catch(e){this.logger.error(`[InMemoryConnection] Error dispatching a config update from the test client: `,e)}}fullUpdate(){return r(r({},l),{},{kind:`full`,configs:Object.fromEntries(this.configs)})}store(e){this.encodeAll(e).forEach((e,t)=>this.configs.set(t,e))}encodeAll(e){let t=new Map;for(let[n,r]of Object.entries(e))t.set(n,this.encode(n,r));return t}encode(e,n){return t(`test-config:${e}`,e,n,`test-value:${e}:${++this.revision}`)}},f=class{constructor(e,t){this.client=e,this.connection=t}setValue(e,t){this.connection.setValue(e,t)}removeValue(e){this.connection.removeValue(e)}replaceValues(e){this.connection.replaceValues(e)}holdInitialization(){this.connection.hold(`initialize`)}completeInitialization(){this.connection.complete(`initialize`)}failInitialization(){this.connection.fail(`initialize`)}holdContextUpdate(){this.connection.hold(`updateContext`)}completeContextUpdate(){this.connection.complete(`updateContext`)}failContextUpdate(){this.connection.fail(`updateContext`)}get contextUpdates(){return this.connection.contextUpdates}};const p=(t,n)=>{var r,a;let o=(r=n==null?void 0:n.logger)==null?i():r,c=new d(o,(a=n==null?void 0:n.values)==null?{}:a);return new f(new s(()=>e,`test-client`,t,{logger:o,connection:{timeout:n==null?void 0:n.timeout}},{transport:c}),c)},m=e=>{let t=globalThis,n=t[c];return t[c]=e.client,()=>{t[c]=n}},h=e=>p({sdkName:`nextjs-sdk`,sdkVersion:`1.13.0`},e);export{n as ConfigDirectorConnectionError,o as ConfigDirectorValidationError,h as createTestClient,m as installTestClient};
2
+ "use client";import{_ as e,c as t,d as n,f as r,l as i,m as a,p as o,r as s,t as c,v as l}from"./installedTestClient-CL4AQC58.mjs";const u=(e,t)=>l(l(l({name:e.name},t===void 0?{}:{context:t}),e.value===void 0?{}:{value:e.value}),e.details===void 0?{}:{details:e.details});var d=class{constructor(e){this.logger=e,this.events=[]}record(t,n){switch(t.warnings.forEach(t=>this.logger.warn(e[t])),t.outcome){case`dropped`:return;case`admitted`:this.events.push(u(t.entry,n));return}}};const f={environmentId:`test-environment`,projectId:`test-project`},p=e=>{switch(e){case`initialization`:return`initialize`;case`context update`:return`updateContext`;default:return}};var m=class{constructor(e,t){this.logger=e,this.emitter=new a,this.configs=new Map,this.recordedContexts=[],this.pendingDeliveries=[],this.armed={initialize:`nothing`,updateContext:`nothing`},this.connected=!1,this.delivering=!1,this.revision=0,this.attemptGeneration=0,this.on=(e,t)=>this.emitter.on(e,t),this.off=(e,t)=>this.emitter.off(e,t),this.store(t)}get contextUpdates(){return[...this.recordedContexts]}setValue(e,t){let n=this.encode(e,t);this.configs.set(e,n),this.deliverIfConnected(l(l({},f),{},{kind:`delta`,configs:{[e]:n}}))}removeValue(e){this.configs.delete(e),this.deliverIfConnected(this.fullUpdate())}replaceValues(e){let t=this.encodeAll(e);this.configs.clear(),t.forEach((e,t)=>this.configs.set(t,e)),this.armed.initialize=`nothing`,this.armed.updateContext=`nothing`,this.deliverIfConnected(this.fullUpdate())}hold(e){this.armed[e]=`hold`}complete(e){var t;((t=this.pendingHold)==null?void 0:t.attempt)===e?this.pendingHold.complete():this.armed[e]===`hold`&&(this.armed[e]=`nothing`)}fail(e){var t;((t=this.pendingHold)==null?void 0:t.attempt)===e?this.pendingHold.fail():this.armed[e]=`failure`}connect(e,t,n){this.endAttempt();let r=p(n);if(!r)return this.connectNow();this.recordedContexts.push(e);let i=this.armed[r];switch(this.armed[r]=`nothing`,i){case`failure`:return this.failNow(n);case`hold`:return this.holdNow(r,n,t);default:return this.connectNow()}}clear(){this.emitter.clear()}close(){this.endAttempt()}dispose(){this.close(),this.clear()}endAttempt(){var e;this.attemptGeneration++,this.connected=!1,(e=this.pendingHold)==null||e.end()}connectNow(){let e=Promise.resolve(this);return this.scheduleFirstDelivery(),e}holdNow(e,t,n){return new Promise((r,i)=>{let a=setTimeout(()=>{var e;return(e=this.pendingHold)==null?void 0:e.end()},n),o=()=>{clearTimeout(a),this.pendingHold=void 0};this.pendingHold={attempt:e,end:()=>{o(),r(this)},complete:()=>{o(),r(this),this.scheduleFirstDelivery()},fail:()=>{o();let e=this.fatalError(t);this.emitter.emit(`connectionError`,e),i(e)}}})}failNow(e){let t=this.fatalError(e);return this.emitter.emit(`connectionError`,t),Promise.reject(t)}fatalError(e){return new r(`Connection failed with status: 401. Error: the test client failed this ${e}. This is an unrecoverable error, will not attempt to reconnect.`,401)}scheduleFirstDelivery(){let e=this.attemptGeneration;Promise.resolve().then(()=>{}).then(()=>{e===this.attemptGeneration&&(this.connected=!0,this.deliver(this.fullUpdate()))})}deliverIfConnected(e){this.connected&&this.deliver(e)}deliver(e){if(this.pendingDeliveries.push(e),!this.delivering){this.delivering=!0;try{let e=this.pendingDeliveries.shift();for(;e;)this.emitCaught(e),e=this.pendingDeliveries.shift()}finally{this.delivering=!1}}}emitCaught(e){try{this.emitter.emit(`configSetReceived`,e)}catch(e){this.logger.error(`[InMemoryConnection] Error dispatching a config update from the test client: `,e)}}fullUpdate(){return l(l({},f),{},{kind:`full`,configs:Object.fromEntries(this.configs)})}store(e){this.encodeAll(e).forEach((e,t)=>this.configs.set(t,e))}encodeAll(e){let t=new Map;for(let[n,r]of Object.entries(e))t.set(n,this.encode(n,r));return t}encode(e,t){return n(`test-config:${e}`,e,t,`test-value:${e}:${++this.revision}`)}},h=class{constructor(e,t,n){this.client=e,this.connection=t,this.trackedEvents=n}setValue(e,t){this.connection.setValue(e,t)}removeValue(e){this.connection.removeValue(e)}replaceValues(e){this.connection.replaceValues(e)}holdInitialization(){this.connection.hold(`initialize`)}completeInitialization(){this.connection.complete(`initialize`)}failInitialization(){this.connection.fail(`initialize`)}holdContextUpdate(){this.connection.hold(`updateContext`)}completeContextUpdate(){this.connection.complete(`updateContext`)}failContextUpdate(){this.connection.fail(`updateContext`)}get contextUpdates(){return this.connection.contextUpdates}};const g=(e,n)=>{var r,a;let o=(r=n==null?void 0:n.logger)==null?i():r,c=new m(o,(a=n==null?void 0:n.values)==null?{}:a),u=new d(o);return new h(new s(()=>l(l({},t),{},{trackedEvent:(e,t)=>u.record(e,t)}),`test-client`,e,{logger:o,connection:{timeout:n==null?void 0:n.timeout}},{transport:c}),c,u.events)},_=e=>{let t=globalThis,n=t[c];return t[c]=e.client,()=>{t[c]=n}},v=e=>g({sdkName:`nextjs-sdk`,sdkVersion:`1.14.0`},e);export{r as ConfigDirectorConnectionError,o as ConfigDirectorValidationError,v as createTestClient,_ as installTestClient};
3
3
  //# sourceMappingURL=testing.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"testing.mjs","names":["createTestClient"],"sources":["../../../js-client-core/src/testing/InMemoryConnection.ts","../../../js-client-core/src/testing/TestClient.ts","../../../js-client-core/src/testing/installTestClient.ts","../../src/client/testing.ts"],"sourcesContent":["import type {\n ClientConnectAction,\n ConfigDirectorContext,\n ConfigDirectorLogger,\n ConfigSet,\n ConfigState,\n Transport,\n TransportEvents,\n} from \"../types\";\nimport { Emitter } from \"../Emitter\";\nimport { ConfigDirectorConnectionError } from \"../errors\";\nimport type { TestValue, TestValues } from \"./values\";\nimport { nativeValueConfigState } from \"../native-values\";\n\ntype ControlledAttempt = \"initialize\" | \"updateContext\";\n\ntype Armed = \"nothing\" | \"hold\" | \"failure\";\n\ntype PendingHold = {\n attempt: ControlledAttempt;\n end: () => void;\n complete: () => void;\n fail: () => void;\n};\n\nconst TEST_ENVIRONMENT = { environmentId: \"test-environment\", projectId: \"test-project\" };\n\nconst controlledAttemptFor = (reason: ClientConnectAction): ControlledAttempt | undefined => {\n switch (reason) {\n case \"initialization\":\n return \"initialize\";\n case \"context update\":\n return \"updateContext\";\n default:\n return undefined;\n }\n};\n\nexport class InMemoryConnection implements Transport {\n private readonly emitter = new Emitter<TransportEvents>();\n private readonly configs = new Map<string, ConfigState>();\n private readonly recordedContexts: ConfigDirectorContext[] = [];\n private readonly pendingDeliveries: ConfigSet[] = [];\n private readonly armed: Record<ControlledAttempt, Armed> = { initialize: \"nothing\", updateContext: \"nothing\" };\n private pendingHold: PendingHold | undefined;\n private connected = false;\n private delivering = false;\n private revision = 0;\n private attemptGeneration = 0;\n\n constructor(\n private readonly logger: ConfigDirectorLogger,\n values: TestValues,\n ) {\n this.store(values);\n }\n\n public get contextUpdates(): ConfigDirectorContext[] {\n return [...this.recordedContexts];\n }\n\n public setValue(key: string, value: TestValue) {\n const configState = this.encode(key, value);\n this.configs.set(key, configState);\n this.deliverIfConnected({ ...TEST_ENVIRONMENT, kind: \"delta\", configs: { [key]: configState } });\n }\n\n public removeValue(key: string) {\n this.configs.delete(key);\n this.deliverIfConnected(this.fullUpdate());\n }\n\n public replaceValues(values: TestValues) {\n const encoded = this.encodeAll(values);\n this.configs.clear();\n encoded.forEach((configState, key) => this.configs.set(key, configState));\n this.armed.initialize = \"nothing\";\n this.armed.updateContext = \"nothing\";\n this.deliverIfConnected(this.fullUpdate());\n }\n\n public hold(attempt: ControlledAttempt) {\n this.armed[attempt] = \"hold\";\n }\n\n public complete(attempt: ControlledAttempt) {\n if (this.pendingHold?.attempt === attempt) {\n this.pendingHold.complete();\n } else if (this.armed[attempt] === \"hold\") {\n this.armed[attempt] = \"nothing\";\n }\n }\n\n public fail(attempt: ControlledAttempt) {\n if (this.pendingHold?.attempt === attempt) {\n this.pendingHold.fail();\n } else {\n this.armed[attempt] = \"failure\";\n }\n }\n\n public connect(context: ConfigDirectorContext, timeout: number, reason: ClientConnectAction): Promise<this> {\n this.endAttempt();\n const attempt = controlledAttemptFor(reason);\n if (!attempt) {\n return this.connectNow();\n }\n this.recordedContexts.push(context);\n const armed = this.armed[attempt];\n this.armed[attempt] = \"nothing\";\n switch (armed) {\n case \"failure\":\n return this.failNow(reason);\n case \"hold\":\n return this.holdNow(attempt, reason, timeout);\n default:\n return this.connectNow();\n }\n }\n\n public on: Transport[\"on\"] = (name, handler) => this.emitter.on(name, handler);\n\n public off: Transport[\"off\"] = (name, handler) => this.emitter.off(name, handler);\n\n public clear() {\n this.emitter.clear();\n }\n\n public close() {\n this.endAttempt();\n }\n\n public dispose() {\n this.close();\n this.clear();\n }\n\n private endAttempt() {\n this.attemptGeneration++;\n this.connected = false;\n this.pendingHold?.end();\n }\n\n private connectNow(): Promise<this> {\n const connected = Promise.resolve(this);\n this.scheduleFirstDelivery();\n return connected;\n }\n\n private holdNow(attempt: ControlledAttempt, reason: ClientConnectAction, timeout: number): Promise<this> {\n return new Promise<this>((resolve, reject) => {\n const timer = setTimeout(() => this.pendingHold?.end(), timeout);\n const release = () => {\n clearTimeout(timer);\n this.pendingHold = undefined;\n };\n this.pendingHold = {\n attempt,\n end: () => {\n release();\n resolve(this);\n },\n complete: () => {\n release();\n resolve(this);\n this.scheduleFirstDelivery();\n },\n fail: () => {\n release();\n const error = this.fatalError(reason);\n this.emitter.emit(\"connectionError\", error);\n reject(error);\n },\n };\n });\n }\n\n private failNow(reason: ClientConnectAction): Promise<this> {\n const error = this.fatalError(reason);\n this.emitter.emit(\"connectionError\", error);\n return Promise.reject(error);\n }\n\n private fatalError(reason: ClientConnectAction) {\n return new ConfigDirectorConnectionError(\n `Connection failed with status: 401. Error: the test client failed this ${reason}. This is an unrecoverable error, will not attempt to reconnect.`,\n 401,\n );\n }\n\n private scheduleFirstDelivery() {\n const generation = this.attemptGeneration;\n void Promise.resolve()\n .then(() => {})\n .then(() => {\n if (generation !== this.attemptGeneration) {\n return;\n }\n this.connected = true;\n this.deliver(this.fullUpdate());\n });\n }\n\n private deliverIfConnected(configSet: ConfigSet) {\n if (this.connected) {\n this.deliver(configSet);\n }\n }\n\n private deliver(configSet: ConfigSet) {\n this.pendingDeliveries.push(configSet);\n if (this.delivering) {\n return;\n }\n this.delivering = true;\n try {\n let next = this.pendingDeliveries.shift();\n while (next) {\n this.emitCaught(next);\n next = this.pendingDeliveries.shift();\n }\n } finally {\n this.delivering = false;\n }\n }\n\n private emitCaught(configSet: ConfigSet) {\n try {\n this.emitter.emit(\"configSetReceived\", configSet);\n } catch (error) {\n this.logger.error(\"[InMemoryConnection] Error dispatching a config update from the test client: \", error);\n }\n }\n\n private fullUpdate(): ConfigSet {\n return { ...TEST_ENVIRONMENT, kind: \"full\", configs: Object.fromEntries(this.configs) };\n }\n\n private store(values: TestValues) {\n this.encodeAll(values).forEach((configState, key) => this.configs.set(key, configState));\n }\n\n private encodeAll(values: TestValues): Map<string, ConfigState> {\n const encoded = new Map<string, ConfigState>();\n for (const [key, value] of Object.entries(values)) {\n encoded.set(key, this.encode(key, value));\n }\n return encoded;\n }\n\n private encode(key: string, value: TestValue): ConfigState {\n return nativeValueConfigState(`test-config:${key}`, key, value, `test-value:${key}:${++this.revision}`);\n }\n}\n","import { DefaultConfigDirectorClient } from \"../DefaultConfigDirectorClient\";\nimport { createDefaultLogger } from \"../logger\";\nimport type { ConfigDirectorClient, ConfigDirectorContext, ConfigDirectorLogger, IdentifyingSdkOptions } from \"../types\";\nimport { discardingTelemetryClient } from \"../telemetry/discarding\";\nimport { InMemoryConnection } from \"./InMemoryConnection\";\nimport type { TestValue, TestValues } from \"./values\";\n\nconst TEST_CLIENT_SDK_KEY = \"test-client\";\n\n/**\n * Options for {@link createTestClient}. Every option is optional.\n */\nexport type TestClientOptions = {\n /**\n * The config values the test client serves once its client connects, keyed by config key. The\n * config type follows from each value: a boolean, an integral number (`integer`), any other\n * number (`float`), a string, or a plain object or array (`json`).\n */\n values?: TestValues;\n /**\n * The connection timeout of the SDK client, in milliseconds. It bounds how long a held\n * `initialize` or `updateContext` waits. Defaults to the SDK's production timeout.\n */\n timeout?: number;\n /**\n * The logger the SDK client uses. Defaults to the SDK's console logger at `warn` level.\n */\n logger?: ConfigDirectorLogger;\n};\n\n/**\n * A real ConfigDirector client connected to an in-memory server that the test controls.\n *\n * The client under {@link TestClient.client} is the SDK's production client: value parsing, watchers,\n * events, and readiness behave as they do against ConfigDirector. Only the network connection and\n * telemetry are replaced, so no request is ever made and nothing is left running after the client is\n * disposed.\n */\nexport interface TestClient {\n /**\n * The SDK client to hand to the code under test. It starts uninitialized, like a production\n * client; `initialize` completes at once with the seeded values unless initialization is held.\n */\n readonly client: ConfigDirectorClient;\n\n /**\n * Stores `value` under `key` and, when the client is connected, delivers it as an update, so\n * reads, watchers, and `configsUpdated` handlers see it.\n */\n setValue(key: string, value: TestValue): void;\n\n /**\n * Removes `key` and, when the client is connected, delivers a full update without it, so reads\n * fall back to the in-code default value and watchers of `key` receive that default.\n */\n removeValue(key: string): void;\n\n /**\n * Replaces every stored value with `values`, disarms any armed hold or failure, and, when the\n * client is connected, delivers the new values as a full update.\n */\n replaceValues(values: TestValues): void;\n\n /**\n * Makes the next `initialize` wait until {@link completeInitialization} or\n * {@link failInitialization} is called, or until the client's timeout elapses.\n */\n holdInitialization(): void;\n\n /**\n * Delivers the stored values to a held `initialize`, so it completes with the client ready. When\n * a hold is armed but no `initialize` has started, it disarms the hold instead.\n */\n completeInitialization(): void;\n\n /**\n * Fails a held `initialize` with an unrecoverable connection error, or arms the next `initialize`\n * to fail. `initialize` completes promptly with the client not ready and `connectionError` fires.\n */\n failInitialization(): void;\n\n /**\n * Makes the next `updateContext` wait until {@link completeContextUpdate} or\n * {@link failContextUpdate} is called, or until the client's timeout elapses.\n */\n holdContextUpdate(): void;\n\n /**\n * Delivers the stored values to a held `updateContext`, or disarms an armed hold that no\n * `updateContext` has picked up.\n */\n completeContextUpdate(): void;\n\n /**\n * Fails a held `updateContext` with an unrecoverable connection error, or arms the next\n * `updateContext` to fail.\n */\n failContextUpdate(): void;\n\n /**\n * The context of every `initialize` and `updateContext` call, in call order. `initialize` without\n * a context records an empty context, and so does a call whose context has an invalid kind, since\n * the client connects without it. Resumes are not recorded.\n */\n readonly contextUpdates: ConfigDirectorContext[];\n}\n\nclass InMemoryTestClient implements TestClient {\n constructor(\n public readonly client: ConfigDirectorClient,\n private readonly connection: InMemoryConnection,\n ) {}\n\n public setValue(key: string, value: TestValue) {\n this.connection.setValue(key, value);\n }\n\n public removeValue(key: string) {\n this.connection.removeValue(key);\n }\n\n public replaceValues(values: TestValues) {\n this.connection.replaceValues(values);\n }\n\n public holdInitialization() {\n this.connection.hold(\"initialize\");\n }\n\n public completeInitialization() {\n this.connection.complete(\"initialize\");\n }\n\n public failInitialization() {\n this.connection.fail(\"initialize\");\n }\n\n public holdContextUpdate() {\n this.connection.hold(\"updateContext\");\n }\n\n public completeContextUpdate() {\n this.connection.complete(\"updateContext\");\n }\n\n public failContextUpdate() {\n this.connection.fail(\"updateContext\");\n }\n\n public get contextUpdates(): ConfigDirectorContext[] {\n return this.connection.contextUpdates;\n }\n}\n\nexport const createTestClient = (sdkOptions: IdentifyingSdkOptions, options?: TestClientOptions): TestClient => {\n const logger = options?.logger ?? createDefaultLogger();\n const connection = new InMemoryConnection(logger, options?.values ?? {});\n const client = new DefaultConfigDirectorClient(\n () => discardingTelemetryClient,\n TEST_CLIENT_SDK_KEY,\n sdkOptions,\n { logger, connection: { timeout: options?.timeout } },\n { transport: connection },\n );\n return new InMemoryTestClient(client, connection);\n};\n","import { INSTALLED_TEST_CLIENT_SLOT, type InstalledTestClientSlot } from \"../installedTestClient\";\nimport type { TestClient } from \"./TestClient\";\n\n/**\n * Makes every `ConfigDirectorProvider` mounted without a `client` prop, and every client\n * `withProvider` would build, use `testClient.client` instead of building a client, until the\n * returned function uninstalls it. Construction props such as `sdkKey` are ignored while installed;\n * `context` and `hooks` apply to the installed client as they do for a `client` prop. A provider\n * reads the installed client when it is constructed, so install before rendering.\n *\n * Installing again replaces the installed test client. Each uninstall function restores the test\n * client that was installed when it was created, so nested installs are uninstalled in reverse order.\n *\n * @param testClient The test client whose `client` providers should use\n * @returns A function that uninstalls it\n *\n * @example\n * let uninstallTestClient: () => void;\n * beforeEach(() => {\n * testClient = createTestClient({ values: { \"new-checkout\": true } });\n * uninstallTestClient = installTestClient(testClient);\n * });\n * afterEach(() => uninstallTestClient());\n */\nexport const installTestClient = (testClient: TestClient): (() => void) => {\n const slot = globalThis as InstalledTestClientSlot;\n const previous = slot[INSTALLED_TEST_CLIENT_SLOT];\n slot[INSTALLED_TEST_CLIENT_SLOT] = testClient.client;\n return () => {\n slot[INSTALLED_TEST_CLIENT_SLOT] = previous;\n };\n};\n","\"use client\";\n\nimport { createTestClient as createCoreTestClient } from \"@js-client-core/testing/index\";\nimport type { TestClient, TestClientOptions } from \"@js-client-core/testing/index\";\n\nexport { installTestClient } from \"@js-client-core/testing/index\";\nexport type { TestClient, TestClientOptions, TestValue, TestValues, TestJsonValue } from \"@js-client-core/testing/index\";\nexport { ConfigDirectorConnectionError, ConfigDirectorValidationError } from \"@shared/errors\";\n\n/**\n * Creates a {@link TestClient}: a real browser `ConfigDirectorClient` connected to an in-memory\n * server that the test controls. No network connection is opened and no telemetry is sent. Render\n * the client `ConfigDirectorProvider` with `client={testClient.client}`, or install it with\n * `installTestClient` for components that render their own provider.\n *\n * @param options {@link TestClientOptions}: the initial values, the client's timeout, and its logger\n * @returns A {@link TestClient} whose `client` is passed to the code under test\n *\n * @example\n * import { createTestClient } from \"@configdirector/nextjs-sdk/client/testing\";\n *\n * const testClient = createTestClient({ values: { \"new-checkout\": true } });\n * render(\n * <ConfigDirectorProvider client={testClient.client}>\n * <Checkout />\n * </ConfigDirectorProvider>,\n * );\n * act(() => testClient.setValue(\"new-checkout\", false));\n */\nexport const createTestClient = (options?: TestClientOptions): TestClient => {\n return createCoreTestClient({ sdkName: \"nextjs-sdk\", sdkVersion: \"__VERSION__\" }, options);\n};\n"],"mappings":";4HAyBA,MAAM,EAAmB,CAAE,cAAe,mBAAoB,UAAW,eAAgB,CAEnF,EAAwB,GAA+D,CAC3F,OAAQ,EAAR,CACE,IAAK,iBACH,MAAO,aACT,IAAK,iBACH,MAAO,gBACT,QACE,SAIN,IAAa,EAAb,KAAqD,CAYnD,YACE,EACA,EACA,CAFiB,KAAA,OAAA,EAZnB,KAAiB,QAAU,IAAI,EAC/B,KAAiB,QAAU,IAAI,IAC/B,KAAiB,iBAA4C,EAAE,CAC/D,KAAiB,kBAAiC,EAAE,CACpD,KAAiB,MAA0C,CAAE,WAAY,UAAW,cAAe,UAAW,CAE9G,KAAQ,UAAY,GACpB,KAAQ,WAAa,GACrB,KAAQ,SAAW,EACnB,KAAQ,kBAAoB,EAwE5B,KAAO,IAAuB,EAAM,IAAY,KAAK,QAAQ,GAAG,EAAM,EAAQ,CAE9E,KAAO,KAAyB,EAAM,IAAY,KAAK,QAAQ,IAAI,EAAM,EAAQ,CApE/E,KAAK,MAAM,EAAO,CAGpB,IAAW,gBAA0C,CACnD,MAAO,CAAC,GAAG,KAAK,iBAAiB,CAGnC,SAAgB,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AAK,WAAW,KAAK,gBAAgB,CAGvC,uBAA+B,CAC7B,KAAK,WAAW,SAAS,gBAAgB,CAG3C,mBAA2B,CACzB,KAAK,WAAW,KAAK,gBAAgB,CAGvC,IAAW,gBAA0C,CACnD,OAAO,KAAK,WAAW,iBAI3B,MAAaA,GAAoB,EAAmC,IAA4C,SAC9G,IAAM,GAAA,EAAA,GAAA,KAAA,IAAA,GAAS,EAAS,SAAA,KAAU,GAAqB,CAA/B,EAClB,EAAa,IAAI,EAAmB,GAAA,EAAA,GAAA,KAAA,IAAA,GAAQ,EAAS,SAAA,KAAU,EAAE,CAAZ,EAAa,CAQxE,OAAO,IAAI,EAPI,IAAI,MACX,EACN,cACA,EACA,CAAE,SAAQ,WAAY,CAAE,QAAA,GAAA,KAAA,IAAA,GAAS,EAAS,QAAS,CAAE,CACrD,CAAE,UAAW,EAAY,CAC1B,CACqC,EAAW,EC5ItC,EAAqB,GAAyC,CACzE,IAAM,EAAO,WACP,EAAW,EAAK,GAEtB,MADA,GAAK,GAA8B,EAAW,WACjC,CACX,EAAK,GAA8B,ICA1B,EAAoB,GACxB,EAAqB,CAAE,QAAS,aAAc,WAAY,SAAe,CAAE,EAAQ"}
1
+ {"version":3,"file":"testing.mjs","names":["createTestClient"],"sources":["../../../shared/src/telemetry/RecordedTrackedEvents.ts","../../../js-client-core/src/testing/InMemoryConnection.ts","../../../js-client-core/src/testing/TestClient.ts","../../../js-client-core/src/testing/installTestClient.ts","../../src/client/testing.ts"],"sourcesContent":["import type { ConfigDirectorContext, ConfigDirectorLogger, TrackedEvent } from \"../types\";\nimport { trackedEventWarningMessages } from \"./tracked-events\";\nimport type { TrackedEventAdmission, TrackedEventEntry } from \"./tracked-events\";\n\nconst recordedEventOf = (entry: TrackedEventEntry, context: ConfigDirectorContext | undefined): TrackedEvent => ({\n name: entry.name,\n ...(context === undefined ? {} : { context }),\n ...(entry.value === undefined ? {} : { value: entry.value }),\n ...(entry.details === undefined ? {} : { details: entry.details }),\n});\n\nexport class RecordedTrackedEvents {\n public readonly events: TrackedEvent[] = [];\n\n constructor(private readonly logger: ConfigDirectorLogger) {}\n\n public record(admission: TrackedEventAdmission, context: ConfigDirectorContext | undefined): void {\n admission.warnings.forEach((warning) => this.logger.warn(trackedEventWarningMessages[warning]));\n switch (admission.outcome) {\n case \"dropped\":\n return;\n case \"admitted\":\n this.events.push(recordedEventOf(admission.entry, context));\n return;\n }\n }\n}\n","import type {\n ClientConnectAction,\n ConfigDirectorContext,\n ConfigDirectorLogger,\n ConfigSet,\n ConfigState,\n Transport,\n TransportEvents,\n} from \"../types\";\nimport { Emitter } from \"../Emitter\";\nimport { ConfigDirectorConnectionError } from \"../errors\";\nimport type { TestValue, TestValues } from \"./values\";\nimport { nativeValueConfigState } from \"../native-values\";\n\ntype ControlledAttempt = \"initialize\" | \"updateContext\";\n\ntype Armed = \"nothing\" | \"hold\" | \"failure\";\n\ntype PendingHold = {\n attempt: ControlledAttempt;\n end: () => void;\n complete: () => void;\n fail: () => void;\n};\n\nconst TEST_ENVIRONMENT = { environmentId: \"test-environment\", projectId: \"test-project\" };\n\nconst controlledAttemptFor = (reason: ClientConnectAction): ControlledAttempt | undefined => {\n switch (reason) {\n case \"initialization\":\n return \"initialize\";\n case \"context update\":\n return \"updateContext\";\n default:\n return undefined;\n }\n};\n\nexport class InMemoryConnection implements Transport {\n private readonly emitter = new Emitter<TransportEvents>();\n private readonly configs = new Map<string, ConfigState>();\n private readonly recordedContexts: ConfigDirectorContext[] = [];\n private readonly pendingDeliveries: ConfigSet[] = [];\n private readonly armed: Record<ControlledAttempt, Armed> = { initialize: \"nothing\", updateContext: \"nothing\" };\n private pendingHold: PendingHold | undefined;\n private connected = false;\n private delivering = false;\n private revision = 0;\n private attemptGeneration = 0;\n\n constructor(\n private readonly logger: ConfigDirectorLogger,\n values: TestValues,\n ) {\n this.store(values);\n }\n\n public get contextUpdates(): ConfigDirectorContext[] {\n return [...this.recordedContexts];\n }\n\n public setValue(key: string, value: TestValue) {\n const configState = this.encode(key, value);\n this.configs.set(key, configState);\n this.deliverIfConnected({ ...TEST_ENVIRONMENT, kind: \"delta\", configs: { [key]: configState } });\n }\n\n public removeValue(key: string) {\n this.configs.delete(key);\n this.deliverIfConnected(this.fullUpdate());\n }\n\n public replaceValues(values: TestValues) {\n const encoded = this.encodeAll(values);\n this.configs.clear();\n encoded.forEach((configState, key) => this.configs.set(key, configState));\n this.armed.initialize = \"nothing\";\n this.armed.updateContext = \"nothing\";\n this.deliverIfConnected(this.fullUpdate());\n }\n\n public hold(attempt: ControlledAttempt) {\n this.armed[attempt] = \"hold\";\n }\n\n public complete(attempt: ControlledAttempt) {\n if (this.pendingHold?.attempt === attempt) {\n this.pendingHold.complete();\n } else if (this.armed[attempt] === \"hold\") {\n this.armed[attempt] = \"nothing\";\n }\n }\n\n public fail(attempt: ControlledAttempt) {\n if (this.pendingHold?.attempt === attempt) {\n this.pendingHold.fail();\n } else {\n this.armed[attempt] = \"failure\";\n }\n }\n\n public connect(context: ConfigDirectorContext, timeout: number, reason: ClientConnectAction): Promise<this> {\n this.endAttempt();\n const attempt = controlledAttemptFor(reason);\n if (!attempt) {\n return this.connectNow();\n }\n this.recordedContexts.push(context);\n const armed = this.armed[attempt];\n this.armed[attempt] = \"nothing\";\n switch (armed) {\n case \"failure\":\n return this.failNow(reason);\n case \"hold\":\n return this.holdNow(attempt, reason, timeout);\n default:\n return this.connectNow();\n }\n }\n\n public on: Transport[\"on\"] = (name, handler) => this.emitter.on(name, handler);\n\n public off: Transport[\"off\"] = (name, handler) => this.emitter.off(name, handler);\n\n public clear() {\n this.emitter.clear();\n }\n\n public close() {\n this.endAttempt();\n }\n\n public dispose() {\n this.close();\n this.clear();\n }\n\n private endAttempt() {\n this.attemptGeneration++;\n this.connected = false;\n this.pendingHold?.end();\n }\n\n private connectNow(): Promise<this> {\n const connected = Promise.resolve(this);\n this.scheduleFirstDelivery();\n return connected;\n }\n\n private holdNow(attempt: ControlledAttempt, reason: ClientConnectAction, timeout: number): Promise<this> {\n return new Promise<this>((resolve, reject) => {\n const timer = setTimeout(() => this.pendingHold?.end(), timeout);\n const release = () => {\n clearTimeout(timer);\n this.pendingHold = undefined;\n };\n this.pendingHold = {\n attempt,\n end: () => {\n release();\n resolve(this);\n },\n complete: () => {\n release();\n resolve(this);\n this.scheduleFirstDelivery();\n },\n fail: () => {\n release();\n const error = this.fatalError(reason);\n this.emitter.emit(\"connectionError\", error);\n reject(error);\n },\n };\n });\n }\n\n private failNow(reason: ClientConnectAction): Promise<this> {\n const error = this.fatalError(reason);\n this.emitter.emit(\"connectionError\", error);\n return Promise.reject(error);\n }\n\n private fatalError(reason: ClientConnectAction) {\n return new ConfigDirectorConnectionError(\n `Connection failed with status: 401. Error: the test client failed this ${reason}. This is an unrecoverable error, will not attempt to reconnect.`,\n 401,\n );\n }\n\n private scheduleFirstDelivery() {\n const generation = this.attemptGeneration;\n void Promise.resolve()\n .then(() => {})\n .then(() => {\n if (generation !== this.attemptGeneration) {\n return;\n }\n this.connected = true;\n this.deliver(this.fullUpdate());\n });\n }\n\n private deliverIfConnected(configSet: ConfigSet) {\n if (this.connected) {\n this.deliver(configSet);\n }\n }\n\n private deliver(configSet: ConfigSet) {\n this.pendingDeliveries.push(configSet);\n if (this.delivering) {\n return;\n }\n this.delivering = true;\n try {\n let next = this.pendingDeliveries.shift();\n while (next) {\n this.emitCaught(next);\n next = this.pendingDeliveries.shift();\n }\n } finally {\n this.delivering = false;\n }\n }\n\n private emitCaught(configSet: ConfigSet) {\n try {\n this.emitter.emit(\"configSetReceived\", configSet);\n } catch (error) {\n this.logger.error(\"[InMemoryConnection] Error dispatching a config update from the test client: \", error);\n }\n }\n\n private fullUpdate(): ConfigSet {\n return { ...TEST_ENVIRONMENT, kind: \"full\", configs: Object.fromEntries(this.configs) };\n }\n\n private store(values: TestValues) {\n this.encodeAll(values).forEach((configState, key) => this.configs.set(key, configState));\n }\n\n private encodeAll(values: TestValues): Map<string, ConfigState> {\n const encoded = new Map<string, ConfigState>();\n for (const [key, value] of Object.entries(values)) {\n encoded.set(key, this.encode(key, value));\n }\n return encoded;\n }\n\n private encode(key: string, value: TestValue): ConfigState {\n return nativeValueConfigState(`test-config:${key}`, key, value, `test-value:${key}:${++this.revision}`);\n }\n}\n","import { DefaultConfigDirectorClient } from \"../DefaultConfigDirectorClient\";\nimport { createDefaultLogger } from \"../logger\";\nimport type {\n ConfigDirectorClient,\n ConfigDirectorContext,\n ConfigDirectorLogger,\n IdentifyingSdkOptions,\n TrackedEvent,\n} from \"../types\";\nimport { RecordedTrackedEvents } from \"@shared/telemetry/RecordedTrackedEvents\";\nimport { discardingTelemetryClient } from \"../telemetry/discarding\";\nimport { InMemoryConnection } from \"./InMemoryConnection\";\nimport type { TestValue, TestValues } from \"./values\";\n\nconst TEST_CLIENT_SDK_KEY = \"test-client\";\n\n/**\n * Options for {@link createTestClient}. Every option is optional.\n */\nexport type TestClientOptions = {\n /**\n * The config values the test client serves once its client connects, keyed by config key. The\n * config type follows from each value: a boolean, an integral number (`integer`), any other\n * number (`float`), a string, or a plain object or array (`json`).\n */\n values?: TestValues;\n /**\n * The connection timeout of the SDK client, in milliseconds. It bounds how long a held\n * `initialize` or `updateContext` waits. Defaults to the SDK's production timeout.\n */\n timeout?: number;\n /**\n * The logger the SDK client uses. Defaults to the SDK's console logger at `warn` level. Since the\n * test client sends no telemetry, every tracked event that is not recorded as it was tracked logs\n * a warning, rather than each cause once per telemetry batch.\n */\n logger?: ConfigDirectorLogger;\n};\n\n/**\n * A real ConfigDirector client connected to an in-memory server that the test controls.\n *\n * The client under {@link TestClient.client} is the SDK's production client: value parsing, watchers,\n * events, and readiness behave as they do against ConfigDirector. Only the network connection and\n * telemetry are replaced, so no request is ever made and nothing is left running after the client is\n * disposed.\n */\nexport interface TestClient {\n /**\n * The SDK client to hand to the code under test. It starts uninitialized, like a production\n * client; `initialize` completes at once with the seeded values unless initialization is held.\n */\n readonly client: ConfigDirectorClient;\n\n /**\n * Stores `value` under `key` and, when the client is connected, delivers it as an update, so\n * reads, watchers, and `configsUpdated` handlers see it.\n */\n setValue(key: string, value: TestValue): void;\n\n /**\n * Removes `key` and, when the client is connected, delivers a full update without it, so reads\n * fall back to the in-code default value and watchers of `key` receive that default.\n */\n removeValue(key: string): void;\n\n /**\n * Replaces every stored value with `values`, disarms any armed hold or failure, and, when the\n * client is connected, delivers the new values as a full update.\n */\n replaceValues(values: TestValues): void;\n\n /**\n * Makes the next `initialize` wait until {@link completeInitialization} or\n * {@link failInitialization} is called, or until the client's timeout elapses.\n */\n holdInitialization(): void;\n\n /**\n * Delivers the stored values to a held `initialize`, so it completes with the client ready. When\n * a hold is armed but no `initialize` has started, it disarms the hold instead.\n */\n completeInitialization(): void;\n\n /**\n * Fails a held `initialize` with an unrecoverable connection error, or arms the next `initialize`\n * to fail. `initialize` completes promptly with the client not ready and `connectionError` fires.\n */\n failInitialization(): void;\n\n /**\n * Makes the next `updateContext` wait until {@link completeContextUpdate} or\n * {@link failContextUpdate} is called, or until the client's timeout elapses.\n */\n holdContextUpdate(): void;\n\n /**\n * Delivers the stored values to a held `updateContext`, or disarms an armed hold that no\n * `updateContext` has picked up.\n */\n completeContextUpdate(): void;\n\n /**\n * Fails a held `updateContext` with an unrecoverable connection error, or arms the next\n * `updateContext` to fail.\n */\n failContextUpdate(): void;\n\n /**\n * The context of every `initialize` and `updateContext` call, in call order. `initialize` without\n * a context records an empty context, and so does a call whose context has an invalid kind, since\n * the client connects without it. Resumes are not recorded.\n */\n readonly contextUpdates: ConfigDirectorContext[];\n\n /**\n * Every event the code under test tracked through the client, in call order, with the context\n * the client had at that moment, as the SDK would report it: an event whose name does not have\n * 1 to 150 characters is not recorded, and a value or details the SDK would leave out are missing\n * from the record. The limit of 1,000 events per telemetry batch does not apply.\n */\n readonly trackedEvents: TrackedEvent[];\n}\n\nclass InMemoryTestClient implements TestClient {\n constructor(\n public readonly client: ConfigDirectorClient,\n private readonly connection: InMemoryConnection,\n public readonly trackedEvents: TrackedEvent[],\n ) {}\n\n public setValue(key: string, value: TestValue) {\n this.connection.setValue(key, value);\n }\n\n public removeValue(key: string) {\n this.connection.removeValue(key);\n }\n\n public replaceValues(values: TestValues) {\n this.connection.replaceValues(values);\n }\n\n public holdInitialization() {\n this.connection.hold(\"initialize\");\n }\n\n public completeInitialization() {\n this.connection.complete(\"initialize\");\n }\n\n public failInitialization() {\n this.connection.fail(\"initialize\");\n }\n\n public holdContextUpdate() {\n this.connection.hold(\"updateContext\");\n }\n\n public completeContextUpdate() {\n this.connection.complete(\"updateContext\");\n }\n\n public failContextUpdate() {\n this.connection.fail(\"updateContext\");\n }\n\n public get contextUpdates(): ConfigDirectorContext[] {\n return this.connection.contextUpdates;\n }\n}\n\nexport const createTestClient = (sdkOptions: IdentifyingSdkOptions, options?: TestClientOptions): TestClient => {\n const logger = options?.logger ?? createDefaultLogger();\n const connection = new InMemoryConnection(logger, options?.values ?? {});\n const recordedTrackedEvents = new RecordedTrackedEvents(logger);\n const client = new DefaultConfigDirectorClient(\n () => ({\n ...discardingTelemetryClient,\n trackedEvent: (admission, context) => recordedTrackedEvents.record(admission, context),\n }),\n TEST_CLIENT_SDK_KEY,\n sdkOptions,\n { logger, connection: { timeout: options?.timeout } },\n { transport: connection },\n );\n return new InMemoryTestClient(client, connection, recordedTrackedEvents.events);\n};\n","import { INSTALLED_TEST_CLIENT_SLOT, type InstalledTestClientSlot } from \"../installedTestClient\";\nimport type { TestClient } from \"./TestClient\";\n\n/**\n * Makes every `ConfigDirectorProvider` mounted without a `client` prop, and every client\n * `withProvider` would build, use `testClient.client` instead of building a client, until the\n * returned function uninstalls it. Construction props such as `sdkKey` are ignored while installed;\n * `context` and `hooks` apply to the installed client as they do for a `client` prop. A provider\n * reads the installed client when it is constructed, so install before rendering.\n *\n * Installing again replaces the installed test client. Each uninstall function restores the test\n * client that was installed when it was created, so nested installs are uninstalled in reverse order.\n *\n * @param testClient The test client whose `client` providers should use\n * @returns A function that uninstalls it\n *\n * @example\n * let uninstallTestClient: () => void;\n * beforeEach(() => {\n * testClient = createTestClient({ values: { \"new-checkout\": true } });\n * uninstallTestClient = installTestClient(testClient);\n * });\n * afterEach(() => uninstallTestClient());\n */\nexport const installTestClient = (testClient: TestClient): (() => void) => {\n const slot = globalThis as InstalledTestClientSlot;\n const previous = slot[INSTALLED_TEST_CLIENT_SLOT];\n slot[INSTALLED_TEST_CLIENT_SLOT] = testClient.client;\n return () => {\n slot[INSTALLED_TEST_CLIENT_SLOT] = previous;\n };\n};\n","\"use client\";\n\nimport { createTestClient as createCoreTestClient } from \"@js-client-core/testing/index\";\nimport type { TestClient, TestClientOptions } from \"@js-client-core/testing/index\";\n\nexport { installTestClient } from \"@js-client-core/testing/index\";\nexport type { TestClient, TestClientOptions, TestValue, TestValues, TestJsonValue } from \"@js-client-core/testing/index\";\nexport type { TrackedEvent, TrackedEventDetails, TrackedEventDetailValue } from \"@shared/types\";\nexport { ConfigDirectorConnectionError, ConfigDirectorValidationError } from \"@shared/errors\";\n\n/**\n * Creates a {@link TestClient}: a real browser `ConfigDirectorClient` connected to an in-memory\n * server that the test controls. No network connection is opened and no telemetry is sent. Render\n * the client `ConfigDirectorProvider` with `client={testClient.client}`, or install it with\n * `installTestClient` for components that render their own provider.\n *\n * @param options {@link TestClientOptions}: the initial values, the client's timeout, and its logger\n * @returns A {@link TestClient} whose `client` is passed to the code under test\n *\n * @example\n * import { createTestClient } from \"@configdirector/nextjs-sdk/client/testing\";\n *\n * const testClient = createTestClient({ values: { \"new-checkout\": true } });\n * render(\n * <ConfigDirectorProvider client={testClient.client}>\n * <Checkout />\n * </ConfigDirectorProvider>,\n * );\n * act(() => testClient.setValue(\"new-checkout\", false));\n */\nexport const createTestClient = (options?: TestClientOptions): TestClient => {\n return createCoreTestClient({ sdkName: \"nextjs-sdk\", sdkVersion: \"__VERSION__\" }, options);\n};\n"],"mappings":";mIAIA,MAAM,GAAmB,EAA0B,IAAA,EAAA,EAAA,EAAA,CACjD,KAAM,EAAM,KAAA,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gB,CAGvC,uBAA+B,CAC7B,KAAK,WAAW,SAAS,gBAAgB,CAG3C,mBAA2B,CACzB,KAAK,WAAW,KAAK,gBAAgB,CAGvC,IAAW,gBAA0C,CACnD,OAAO,KAAK,WAAW,iBAI3B,MAAaA,GAAoB,EAAmC,IAA4C,SAC9G,IAAM,GAAA,EAAA,GAAA,KAAA,IAAA,GAAS,EAAS,SAAA,KAAU,GAAqB,CAA/B,EAClB,EAAa,IAAI,EAAmB,GAAA,EAAA,GAAA,KAAA,IAAA,GAAQ,EAAS,SAAA,KAAU,EAAE,CAAZ,EAAa,CAClE,EAAwB,IAAI,EAAsB,EAAO,CAW/D,OAAO,IAAI,EAVI,IAAI,MAAA,EAAA,EAAA,EAAA,CAEZ,EAAA,CAAA,EAAA,CAAA,CACH,cAAe,EAAW,IAAY,EAAsB,OAAO,EAAW,EAAQ,CAAA,CACvF,CACD,cACA,EACA,CAAE,SAAQ,WAAY,CAAE,QAAA,GAAA,KAAA,IAAA,GAAS,EAAS,QAAS,CAAE,CACrD,CAAE,UAAW,EAAY,CAC1B,CACqC,EAAY,EAAsB,OAAO,EClKpE,EAAqB,GAAyC,CACzE,IAAM,EAAO,WACP,EAAW,EAAK,GAEtB,MADA,GAAK,GAA8B,EAAW,WACjC,CACX,EAAK,GAA8B,ICC1B,EAAoB,GACxB,EAAqB,CAAE,QAAS,aAAc,WAAY,SAAe,CAAE,EAAQ"}
@@ -22,6 +22,12 @@ type ConfigState = {
22
22
  type: ConfigType;
23
23
  value: string | undefined | null;
24
24
  valueId?: string | undefined | null;
25
+ variation?: {
26
+ id: string;
27
+ name?: string | undefined | null;
28
+ } | undefined | null;
29
+ ruleId?: string | undefined | null;
30
+ shareId?: string | undefined | null;
25
31
  };
26
32
  type ConfigDirectorLoggingLevel = "debug" | "info" | "warn" | "error" | "off";
27
33
  interface ConfigDirectorLogger {
@@ -32,24 +38,72 @@ interface ConfigDirectorLogger {
32
38
  }
33
39
  /**
34
40
  * Why an evaluation returned the value it did. `found-match` returns a value from ConfigDirector,
35
- * and `cached` a value kept on the device while a client SDK waits for live values. `value-missing`
41
+ * and `cached` a value kept on the device while a client SDK waits for live values.
42
+ * `rollout-skipped-no-identifier` returns the default targeting rule value: a server SDK skipped a
43
+ * percentage rollout because the context has no `id` to place it in a share. `value-missing`
36
44
  * returns the in-code default value because the config has no value. Every other reason returns the
37
45
  * in-code default value because of an error: the config does not exist (`config-state-missing`), no
38
46
  * values have arrived yet (`client-not-ready`), or the value cannot be read as the type of the in-code
39
47
  * default value.
40
48
  */
41
- type EvaluationReason = "found-match" | "config-state-missing" | "client-not-ready" | "type-mismatch" | "value-missing" | "invalid-number" | "invalid-json" | "invalid-boolean" | "cached";
49
+ type EvaluationReason = "found-match" | "rollout-skipped-no-identifier" | "config-state-missing" | "client-not-ready" | "type-mismatch" | "value-missing" | "invalid-number" | "invalid-json" | "invalid-boolean" | "cached";
50
+ /**
51
+ * One of the values a config can serve, such as the control or a treatment of an experiment.
52
+ */
53
+ type Variation = {
54
+ /** The ID ConfigDirector assigned to the variation, which stays the same when it is renamed. */id: string; /** The variation's name, when it has one. */
55
+ name?: string;
56
+ };
42
57
  /**
43
58
  * One evaluation of a config: the value it returned, why, and the context it was evaluated for.
44
59
  */
45
60
  type ConfigEvaluation<T extends ConfigValueType = ConfigValueType> = {
46
61
  /** The config key that was evaluated. */key: string; /** The value returned, which is the in-code default value when {@link isDefaultValue} is `true`. */
47
62
  value: T; /** The ID ConfigDirector assigned to the value returned, when ConfigDirector sent one with it. */
48
- valueId?: string; /** Whether the evaluation returned the in-code default value. */
63
+ valueId?: string;
64
+ /**
65
+ * The variation that was served. It is `undefined` when the config has no variations or the
66
+ * in-code default value is returned.
67
+ */
68
+ variation?: Variation; /** Whether the evaluation returned the in-code default value. */
49
69
  isDefaultValue: boolean; /** Why the evaluation returned this value. */
50
70
  reason: EvaluationReason; /** The context the config was evaluated for, if any. */
51
71
  context?: ConfigDirectorContext;
52
72
  };
73
+ /**
74
+ * A value in the details of a tracked event: a string, a number, a boolean, or an array or object
75
+ * of such values.
76
+ */
77
+ type TrackedEventDetailValue = string | number | boolean | TrackedEventDetailValue[] | {
78
+ [key: string]: TrackedEventDetailValue;
79
+ };
80
+ /**
81
+ * Details of a tracked event, such as the plan a customer chose. Details with more than 20
82
+ * top-level keys, or larger than 1 KB as JSON, are left out and the event is still reported.
83
+ */
84
+ type TrackedEventDetails = {
85
+ [key: string]: TrackedEventDetailValue;
86
+ };
87
+ /**
88
+ * What a tracked event carries besides its name.
89
+ */
90
+ type TrackOptions = {
91
+ /**
92
+ * A number the event measures, such as an amount of money, a count or a duration. A value that
93
+ * is not a finite number is left out and the event is still reported.
94
+ */
95
+ value?: number; /** Details of the event. */
96
+ details?: TrackedEventDetails;
97
+ };
98
+ /**
99
+ * An event the code under test tracked, as a test client recorded it.
100
+ */
101
+ type TrackedEvent = {
102
+ /** The name the event was tracked with. */name: string; /** The context the event was tracked for, if any. */
103
+ context?: ConfigDirectorContext; /** The value the event was tracked with, when it is a finite number. */
104
+ value?: number; /** The details the event was tracked with, when they are within the limits. */
105
+ details?: TrackedEventDetails;
106
+ };
53
107
  /**
54
108
  * The context to be sent to ConfigDirector: the user or other entity, such as a device or an
55
109
  * organization, that configs are evaluated for. This context will be used for targeting rules
@@ -227,8 +281,8 @@ interface ConfigDirectorClient extends EventProvider<ClientEvents> {
227
281
  getValue<T extends ConfigValueType>(configKey: string, defaultValue: T): T;
228
282
  /**
229
283
  * Evaluates a config as {@link getValue} does and returns the evaluation: the value, the reason it
230
- * was served and its value ID. Like every read, it fires `configEvaluated` and is counted in
231
- * telemetry.
284
+ * was served, its value ID and its variation. Like every read, it fires `configEvaluated` and is
285
+ * counted in telemetry.
232
286
  *
233
287
  * @returns The evaluation, whose `value` is what {@link getValue} returns
234
288
  * @param configKey The config key to evaluate
@@ -260,6 +314,20 @@ interface ConfigDirectorClient extends EventProvider<ClientEvents> {
260
314
  * Removes all subscribers from all config keys
261
315
  */
262
316
  unwatchAll(): void;
317
+ /**
318
+ * Reports to ConfigDirector that something happened for the current context, such as a completed
319
+ * checkout, so it can be counted. The event is sent with the next telemetry batch. `track` never
320
+ * throws, and does nothing in `offline` mode.
321
+ *
322
+ * An event counts for an experiment only when the current context has an `id`, the one the
323
+ * experiment's config was evaluated for. Before the client has a context, or for a context
324
+ * without an `id`, the event is still reported.
325
+ *
326
+ * @param eventName The name of the event, 1 to 150 characters. An event with any other name is
327
+ * not reported and a warning is logged.
328
+ * @param options The event's {@link TrackOptions.value} and {@link TrackOptions.details} (optional)
329
+ */
330
+ track(eventName: string, options?: TrackOptions): void;
263
331
  /**
264
332
  * Pauses the network connection without clearing event handlers, watch handlers, or config
265
333
  * state. Intended for mobile environments where the OS may kill background connections (e.g.
@@ -282,5 +350,5 @@ interface ConfigDirectorClient extends EventProvider<ClientEvents> {
282
350
  dispose(): void;
283
351
  }
284
352
  //#endregion
285
- export { NativeJsonValue as a, ConfigDirectorContext as c, ConfigEvaluation as d, ConfigState as f, EvaluationReason as h, OfflineValues as i, ConfigDirectorLogger as l, ConnectionMode as m, ConfigDirectorClient as n, NativeValue as o, ConfigValueType as p, OfflineValue as r, NativeValues as s, ClientHooks as t, ConfigDirectorLoggingLevel as u };
286
- //# sourceMappingURL=types-CRVL6Yi2.d.cts.map
353
+ export { TrackedEvent as _, NativeJsonValue as a, Variation as b, ConfigDirectorContext as c, ConfigEvaluation as d, ConfigState as f, TrackOptions as g, EvaluationReason as h, OfflineValues as i, ConfigDirectorLogger as l, ConnectionMode as m, ConfigDirectorClient as n, NativeValue as o, ConfigValueType as p, OfflineValue as r, NativeValues as s, ClientHooks as t, ConfigDirectorLoggingLevel as u, TrackedEventDetailValue as v, TrackedEventDetails as y };
354
+ //# sourceMappingURL=types-CdyMdj5l.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-CdyMdj5l.d.mts","names":[],"sources":["../../../js-client-core/src/Emitter.ts","../../../shared/src/types.ts","../../../shared/src/native-values.ts","../../../js-client-core/src/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AAA;AAAA"}
@@ -22,6 +22,12 @@ type ConfigState = {
22
22
  type: ConfigType;
23
23
  value: string | undefined | null;
24
24
  valueId?: string | undefined | null;
25
+ variation?: {
26
+ id: string;
27
+ name?: string | undefined | null;
28
+ } | undefined | null;
29
+ ruleId?: string | undefined | null;
30
+ shareId?: string | undefined | null;
25
31
  };
26
32
  type ConfigDirectorLoggingLevel = "debug" | "info" | "warn" | "error" | "off";
27
33
  interface ConfigDirectorLogger {
@@ -32,24 +38,72 @@ interface ConfigDirectorLogger {
32
38
  }
33
39
  /**
34
40
  * Why an evaluation returned the value it did. `found-match` returns a value from ConfigDirector,
35
- * and `cached` a value kept on the device while a client SDK waits for live values. `value-missing`
41
+ * and `cached` a value kept on the device while a client SDK waits for live values.
42
+ * `rollout-skipped-no-identifier` returns the default targeting rule value: a server SDK skipped a
43
+ * percentage rollout because the context has no `id` to place it in a share. `value-missing`
36
44
  * returns the in-code default value because the config has no value. Every other reason returns the
37
45
  * in-code default value because of an error: the config does not exist (`config-state-missing`), no
38
46
  * values have arrived yet (`client-not-ready`), or the value cannot be read as the type of the in-code
39
47
  * default value.
40
48
  */
41
- type EvaluationReason = "found-match" | "config-state-missing" | "client-not-ready" | "type-mismatch" | "value-missing" | "invalid-number" | "invalid-json" | "invalid-boolean" | "cached";
49
+ type EvaluationReason = "found-match" | "rollout-skipped-no-identifier" | "config-state-missing" | "client-not-ready" | "type-mismatch" | "value-missing" | "invalid-number" | "invalid-json" | "invalid-boolean" | "cached";
50
+ /**
51
+ * One of the values a config can serve, such as the control or a treatment of an experiment.
52
+ */
53
+ type Variation = {
54
+ /** The ID ConfigDirector assigned to the variation, which stays the same when it is renamed. */id: string; /** The variation's name, when it has one. */
55
+ name?: string;
56
+ };
42
57
  /**
43
58
  * One evaluation of a config: the value it returned, why, and the context it was evaluated for.
44
59
  */
45
60
  type ConfigEvaluation<T extends ConfigValueType = ConfigValueType> = {
46
61
  /** The config key that was evaluated. */key: string; /** The value returned, which is the in-code default value when {@link isDefaultValue} is `true`. */
47
62
  value: T; /** The ID ConfigDirector assigned to the value returned, when ConfigDirector sent one with it. */
48
- valueId?: string; /** Whether the evaluation returned the in-code default value. */
63
+ valueId?: string;
64
+ /**
65
+ * The variation that was served. It is `undefined` when the config has no variations or the
66
+ * in-code default value is returned.
67
+ */
68
+ variation?: Variation; /** Whether the evaluation returned the in-code default value. */
49
69
  isDefaultValue: boolean; /** Why the evaluation returned this value. */
50
70
  reason: EvaluationReason; /** The context the config was evaluated for, if any. */
51
71
  context?: ConfigDirectorContext;
52
72
  };
73
+ /**
74
+ * A value in the details of a tracked event: a string, a number, a boolean, or an array or object
75
+ * of such values.
76
+ */
77
+ type TrackedEventDetailValue = string | number | boolean | TrackedEventDetailValue[] | {
78
+ [key: string]: TrackedEventDetailValue;
79
+ };
80
+ /**
81
+ * Details of a tracked event, such as the plan a customer chose. Details with more than 20
82
+ * top-level keys, or larger than 1 KB as JSON, are left out and the event is still reported.
83
+ */
84
+ type TrackedEventDetails = {
85
+ [key: string]: TrackedEventDetailValue;
86
+ };
87
+ /**
88
+ * What a tracked event carries besides its name.
89
+ */
90
+ type TrackOptions = {
91
+ /**
92
+ * A number the event measures, such as an amount of money, a count or a duration. A value that
93
+ * is not a finite number is left out and the event is still reported.
94
+ */
95
+ value?: number; /** Details of the event. */
96
+ details?: TrackedEventDetails;
97
+ };
98
+ /**
99
+ * An event the code under test tracked, as a test client recorded it.
100
+ */
101
+ type TrackedEvent = {
102
+ /** The name the event was tracked with. */name: string; /** The context the event was tracked for, if any. */
103
+ context?: ConfigDirectorContext; /** The value the event was tracked with, when it is a finite number. */
104
+ value?: number; /** The details the event was tracked with, when they are within the limits. */
105
+ details?: TrackedEventDetails;
106
+ };
53
107
  /**
54
108
  * The context to be sent to ConfigDirector: the user or other entity, such as a device or an
55
109
  * organization, that configs are evaluated for. This context will be used for targeting rules
@@ -227,8 +281,8 @@ interface ConfigDirectorClient extends EventProvider<ClientEvents> {
227
281
  getValue<T extends ConfigValueType>(configKey: string, defaultValue: T): T;
228
282
  /**
229
283
  * Evaluates a config as {@link getValue} does and returns the evaluation: the value, the reason it
230
- * was served and its value ID. Like every read, it fires `configEvaluated` and is counted in
231
- * telemetry.
284
+ * was served, its value ID and its variation. Like every read, it fires `configEvaluated` and is
285
+ * counted in telemetry.
232
286
  *
233
287
  * @returns The evaluation, whose `value` is what {@link getValue} returns
234
288
  * @param configKey The config key to evaluate
@@ -260,6 +314,20 @@ interface ConfigDirectorClient extends EventProvider<ClientEvents> {
260
314
  * Removes all subscribers from all config keys
261
315
  */
262
316
  unwatchAll(): void;
317
+ /**
318
+ * Reports to ConfigDirector that something happened for the current context, such as a completed
319
+ * checkout, so it can be counted. The event is sent with the next telemetry batch. `track` never
320
+ * throws, and does nothing in `offline` mode.
321
+ *
322
+ * An event counts for an experiment only when the current context has an `id`, the one the
323
+ * experiment's config was evaluated for. Before the client has a context, or for a context
324
+ * without an `id`, the event is still reported.
325
+ *
326
+ * @param eventName The name of the event, 1 to 150 characters. An event with any other name is
327
+ * not reported and a warning is logged.
328
+ * @param options The event's {@link TrackOptions.value} and {@link TrackOptions.details} (optional)
329
+ */
330
+ track(eventName: string, options?: TrackOptions): void;
263
331
  /**
264
332
  * Pauses the network connection without clearing event handlers, watch handlers, or config
265
333
  * state. Intended for mobile environments where the OS may kill background connections (e.g.
@@ -282,5 +350,5 @@ interface ConfigDirectorClient extends EventProvider<ClientEvents> {
282
350
  dispose(): void;
283
351
  }
284
352
  //#endregion
285
- export { NativeJsonValue as a, ConfigDirectorContext as c, ConfigEvaluation as d, ConfigState as f, EvaluationReason as h, OfflineValues as i, ConfigDirectorLogger as l, ConnectionMode as m, ConfigDirectorClient as n, NativeValue as o, ConfigValueType as p, OfflineValue as r, NativeValues as s, ClientHooks as t, ConfigDirectorLoggingLevel as u };
286
- //# sourceMappingURL=types-B4kvU3bh.d.mts.map
353
+ export { TrackedEvent as _, NativeJsonValue as a, Variation as b, ConfigDirectorContext as c, ConfigEvaluation as d, ConfigState as f, TrackOptions as g, EvaluationReason as h, OfflineValues as i, ConfigDirectorLogger as l, ConnectionMode as m, ConfigDirectorClient as n, NativeValue as o, ConfigValueType as p, OfflineValue as r, NativeValues as s, ClientHooks as t, ConfigDirectorLoggingLevel as u, TrackedEventDetailValue as v, TrackedEventDetails as y };
354
+ //# sourceMappingURL=types-P8frfCGH.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-P8frfCGH.d.cts","names":[],"sources":["../../../js-client-core/src/Emitter.ts","../../../shared/src/types.ts","../../../shared/src/native-values.ts","../../../js-client-core/src/types.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;;;cCVW,cAAA;AAAA,KAUD,UAAA,WAAqB,cAAA;AAAA,KAErB,kBAAA;EAAA,CAAwB,GAAA;AAAA;AAAA,KAExB,eAAA,wCAAuD,kBAAA;AAAA,KAEvD,WAAA;EACV,EAAA;EACA,GAAA;EACA,IAAA,EAAM,UAAA;EACN,KAAA;EACA,OAAA;EACA,SAAA;IAAc,EAAA;IAAY,IAAA;EAAA;EAC1B,MAAA;EACA,OAAA;AAAA;AAAA,KAQU,0BAAA;AAAA,UAEK,oBAAA;EACf,KAAA,CAAM,OAAA,aAAoB,IAAA;EAE1B,IAAA,CAAK,OAAA,aAAoB,IAAA;EAEzB,IAAA,CAAK,OAAA,aAAoB,IAAA;EAEzB,KAAA,CAAM,OAAA,aAAoB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