@launchdarkly/js-sdk-common 2.8.0 → 2.10.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 (226) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/api/platform/Crypto.d.ts +17 -3
  3. package/dist/api/platform/Crypto.d.ts.map +1 -1
  4. package/dist/api/platform/EventSource.d.ts +3 -1
  5. package/dist/api/platform/EventSource.d.ts.map +1 -1
  6. package/dist/api/platform/Requests.d.ts +28 -0
  7. package/dist/api/platform/Requests.d.ts.map +1 -1
  8. package/dist/datasource/DataSourceErrorKinds.d.ts +7 -0
  9. package/dist/datasource/DataSourceErrorKinds.d.ts.map +1 -0
  10. package/dist/datasource/errors.d.ts +17 -0
  11. package/dist/datasource/errors.d.ts.map +1 -0
  12. package/dist/datasource/index.d.ts +4 -0
  13. package/dist/datasource/index.d.ts.map +1 -0
  14. package/dist/errors.d.ts +0 -11
  15. package/dist/errors.d.ts.map +1 -1
  16. package/dist/index.cjs +2477 -0
  17. package/dist/index.cjs.map +1 -0
  18. package/dist/index.d.ts +2 -1
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.mjs +2430 -0
  21. package/dist/index.mjs.map +1 -0
  22. package/dist/internal/events/EventProcessor.d.ts +2 -1
  23. package/dist/internal/events/EventProcessor.d.ts.map +1 -1
  24. package/dist/internal/events/EventSender.d.ts +2 -1
  25. package/dist/internal/events/EventSender.d.ts.map +1 -1
  26. package/dist/internal/events/InputClickEvent.d.ts +11 -0
  27. package/dist/internal/events/InputClickEvent.d.ts.map +1 -0
  28. package/dist/internal/events/InputCustomEvent.d.ts +2 -1
  29. package/dist/internal/events/InputCustomEvent.d.ts.map +1 -1
  30. package/dist/internal/events/InputEvent.d.ts +3 -1
  31. package/dist/internal/events/InputEvent.d.ts.map +1 -1
  32. package/dist/internal/events/InputPageViewEvent.d.ts +10 -0
  33. package/dist/internal/events/InputPageViewEvent.d.ts.map +1 -0
  34. package/dist/internal/events/LDInternalOptions.d.ts +1 -0
  35. package/dist/internal/events/LDInternalOptions.d.ts.map +1 -1
  36. package/dist/internal/index.d.ts +1 -1
  37. package/dist/internal/index.d.ts.map +1 -1
  38. package/dist/internal/stream/StreamingProcessor.d.ts +3 -2
  39. package/dist/internal/stream/StreamingProcessor.d.ts.map +1 -1
  40. package/dist/internal/stream/types.d.ts +1 -1
  41. package/dist/internal/stream/types.d.ts.map +1 -1
  42. package/dist/utils/http.d.ts +3 -2
  43. package/dist/utils/http.d.ts.map +1 -1
  44. package/package.json +18 -7
  45. package/dist/AttributeReference.js +0 -126
  46. package/dist/AttributeReference.js.map +0 -1
  47. package/dist/Context.js +0 -382
  48. package/dist/Context.js.map +0 -1
  49. package/dist/ContextFilter.js +0 -124
  50. package/dist/ContextFilter.js.map +0 -1
  51. package/dist/api/context/LDContext.js +0 -3
  52. package/dist/api/context/LDContext.js.map +0 -1
  53. package/dist/api/context/LDContextCommon.js +0 -3
  54. package/dist/api/context/LDContextCommon.js.map +0 -1
  55. package/dist/api/context/LDContextMeta.js +0 -3
  56. package/dist/api/context/LDContextMeta.js.map +0 -1
  57. package/dist/api/context/LDMultiKindContext.js +0 -3
  58. package/dist/api/context/LDMultiKindContext.js.map +0 -1
  59. package/dist/api/context/LDSingleKindContext.js +0 -3
  60. package/dist/api/context/LDSingleKindContext.js.map +0 -1
  61. package/dist/api/context/LDUser.js +0 -3
  62. package/dist/api/context/LDUser.js.map +0 -1
  63. package/dist/api/context/index.js +0 -23
  64. package/dist/api/context/index.js.map +0 -1
  65. package/dist/api/data/LDEvaluationDetail.js +0 -3
  66. package/dist/api/data/LDEvaluationDetail.js.map +0 -1
  67. package/dist/api/data/LDEvaluationReason.js +0 -3
  68. package/dist/api/data/LDEvaluationReason.js.map +0 -1
  69. package/dist/api/data/LDFlagSet.js +0 -3
  70. package/dist/api/data/LDFlagSet.js.map +0 -1
  71. package/dist/api/data/LDFlagValue.js +0 -3
  72. package/dist/api/data/LDFlagValue.js.map +0 -1
  73. package/dist/api/data/index.js +0 -21
  74. package/dist/api/data/index.js.map +0 -1
  75. package/dist/api/index.js +0 -24
  76. package/dist/api/index.js.map +0 -1
  77. package/dist/api/logging/BasicLoggerOptions.js +0 -3
  78. package/dist/api/logging/BasicLoggerOptions.js.map +0 -1
  79. package/dist/api/logging/LDLogLevel.js +0 -3
  80. package/dist/api/logging/LDLogLevel.js.map +0 -1
  81. package/dist/api/logging/LDLogger.js +0 -3
  82. package/dist/api/logging/LDLogger.js.map +0 -1
  83. package/dist/api/logging/index.js +0 -20
  84. package/dist/api/logging/index.js.map +0 -1
  85. package/dist/api/options/LDClientContext.js +0 -3
  86. package/dist/api/options/LDClientContext.js.map +0 -1
  87. package/dist/api/options/index.js +0 -4
  88. package/dist/api/options/index.js.map +0 -1
  89. package/dist/api/platform/AutoEnv.js +0 -20
  90. package/dist/api/platform/AutoEnv.js.map +0 -1
  91. package/dist/api/platform/Crypto.js +0 -3
  92. package/dist/api/platform/Crypto.js.map +0 -1
  93. package/dist/api/platform/Encoding.js +0 -3
  94. package/dist/api/platform/Encoding.js.map +0 -1
  95. package/dist/api/platform/EventSource.js +0 -3
  96. package/dist/api/platform/EventSource.js.map +0 -1
  97. package/dist/api/platform/Filesystem.js +0 -3
  98. package/dist/api/platform/Filesystem.js.map +0 -1
  99. package/dist/api/platform/Info.js +0 -3
  100. package/dist/api/platform/Info.js.map +0 -1
  101. package/dist/api/platform/Platform.js +0 -3
  102. package/dist/api/platform/Platform.js.map +0 -1
  103. package/dist/api/platform/Requests.js +0 -3
  104. package/dist/api/platform/Requests.js.map +0 -1
  105. package/dist/api/platform/Storage.js +0 -3
  106. package/dist/api/platform/Storage.js.map +0 -1
  107. package/dist/api/platform/index.js +0 -26
  108. package/dist/api/platform/index.js.map +0 -1
  109. package/dist/api/subsystem/LDContextDeduplicator.js +0 -3
  110. package/dist/api/subsystem/LDContextDeduplicator.js.map +0 -1
  111. package/dist/api/subsystem/LDEventProcessor.js +0 -3
  112. package/dist/api/subsystem/LDEventProcessor.js.map +0 -1
  113. package/dist/api/subsystem/LDEventSender.js +0 -15
  114. package/dist/api/subsystem/LDEventSender.js.map +0 -1
  115. package/dist/api/subsystem/LDStreamProcessor.js +0 -3
  116. package/dist/api/subsystem/LDStreamProcessor.js.map +0 -1
  117. package/dist/api/subsystem/index.js +0 -7
  118. package/dist/api/subsystem/index.js.map +0 -1
  119. package/dist/errors.js +0 -78
  120. package/dist/errors.js.map +0 -1
  121. package/dist/index.js +0 -31
  122. package/dist/index.js.map +0 -1
  123. package/dist/internal/context/index.js +0 -38
  124. package/dist/internal/context/index.js.map +0 -1
  125. package/dist/internal/diagnostics/DiagnosticsManager.js +0 -70
  126. package/dist/internal/diagnostics/DiagnosticsManager.js.map +0 -1
  127. package/dist/internal/diagnostics/index.js +0 -6
  128. package/dist/internal/diagnostics/index.js.map +0 -1
  129. package/dist/internal/diagnostics/types.js +0 -3
  130. package/dist/internal/diagnostics/types.js.map +0 -1
  131. package/dist/internal/evaluation/ErrorKinds.js +0 -15
  132. package/dist/internal/evaluation/ErrorKinds.js.map +0 -1
  133. package/dist/internal/evaluation/EventFactoryBase.js +0 -38
  134. package/dist/internal/evaluation/EventFactoryBase.js.map +0 -1
  135. package/dist/internal/evaluation/index.js +0 -8
  136. package/dist/internal/evaluation/index.js.map +0 -1
  137. package/dist/internal/events/ClientMessages.js +0 -14
  138. package/dist/internal/events/ClientMessages.js.map +0 -1
  139. package/dist/internal/events/EventProcessor.js +0 -239
  140. package/dist/internal/events/EventProcessor.js.map +0 -1
  141. package/dist/internal/events/EventSender.js +0 -77
  142. package/dist/internal/events/EventSender.js.map +0 -1
  143. package/dist/internal/events/EventSummarizer.js +0 -84
  144. package/dist/internal/events/EventSummarizer.js.map +0 -1
  145. package/dist/internal/events/InputCustomEvent.js +0 -19
  146. package/dist/internal/events/InputCustomEvent.js.map +0 -1
  147. package/dist/internal/events/InputEvalEvent.js +0 -38
  148. package/dist/internal/events/InputEvalEvent.js.map +0 -1
  149. package/dist/internal/events/InputEvent.js +0 -3
  150. package/dist/internal/events/InputEvent.js.map +0 -1
  151. package/dist/internal/events/InputEventBase.js +0 -11
  152. package/dist/internal/events/InputEventBase.js.map +0 -1
  153. package/dist/internal/events/InputIdentifyEvent.js +0 -12
  154. package/dist/internal/events/InputIdentifyEvent.js.map +0 -1
  155. package/dist/internal/events/InputMigrationEvent.js +0 -7
  156. package/dist/internal/events/InputMigrationEvent.js.map +0 -1
  157. package/dist/internal/events/LDInternalOptions.js +0 -3
  158. package/dist/internal/events/LDInternalOptions.js.map +0 -1
  159. package/dist/internal/events/LDInvalidSDKKeyError.js +0 -10
  160. package/dist/internal/events/LDInvalidSDKKeyError.js.map +0 -1
  161. package/dist/internal/events/NullEventProcessor.js +0 -11
  162. package/dist/internal/events/NullEventProcessor.js.map +0 -1
  163. package/dist/internal/events/SummaryCounter.js +0 -20
  164. package/dist/internal/events/SummaryCounter.js.map +0 -1
  165. package/dist/internal/events/guards.js +0 -20
  166. package/dist/internal/events/guards.js.map +0 -1
  167. package/dist/internal/events/index.js +0 -18
  168. package/dist/internal/events/index.js.map +0 -1
  169. package/dist/internal/events/sampling.js +0 -23
  170. package/dist/internal/events/sampling.js.map +0 -1
  171. package/dist/internal/index.js +0 -22
  172. package/dist/internal/index.js.map +0 -1
  173. package/dist/internal/stream/StreamingProcessor.js +0 -112
  174. package/dist/internal/stream/StreamingProcessor.js.map +0 -1
  175. package/dist/internal/stream/index.js +0 -6
  176. package/dist/internal/stream/index.js.map +0 -1
  177. package/dist/internal/stream/types.js +0 -3
  178. package/dist/internal/stream/types.js.map +0 -1
  179. package/dist/logging/BasicLogger.js +0 -97
  180. package/dist/logging/BasicLogger.js.map +0 -1
  181. package/dist/logging/SafeLogger.js +0 -63
  182. package/dist/logging/SafeLogger.js.map +0 -1
  183. package/dist/logging/createSafeLogger.js +0 -16
  184. package/dist/logging/createSafeLogger.js.map +0 -1
  185. package/dist/logging/format.js +0 -156
  186. package/dist/logging/format.js.map +0 -1
  187. package/dist/logging/index.js +0 -10
  188. package/dist/logging/index.js.map +0 -1
  189. package/dist/options/ApplicationTags.js +0 -55
  190. package/dist/options/ApplicationTags.js.map +0 -1
  191. package/dist/options/ClientContext.js +0 -20
  192. package/dist/options/ClientContext.js.map +0 -1
  193. package/dist/options/OptionMessages.js +0 -33
  194. package/dist/options/OptionMessages.js.map +0 -1
  195. package/dist/options/ServiceEndpoints.js +0 -77
  196. package/dist/options/ServiceEndpoints.js.map +0 -1
  197. package/dist/options/index.js +0 -15
  198. package/dist/options/index.js.map +0 -1
  199. package/dist/utils/VoidFunction.js +0 -3
  200. package/dist/utils/VoidFunction.js.map +0 -1
  201. package/dist/utils/cancelableTimedPromise.js +0 -30
  202. package/dist/utils/cancelableTimedPromise.js.map +0 -1
  203. package/dist/utils/clone.js +0 -10
  204. package/dist/utils/clone.js.map +0 -1
  205. package/dist/utils/date.js +0 -9
  206. package/dist/utils/date.js.map +0 -1
  207. package/dist/utils/debounce.js +0 -33
  208. package/dist/utils/debounce.js.map +0 -1
  209. package/dist/utils/deepCompact.js +0 -24
  210. package/dist/utils/deepCompact.js.map +0 -1
  211. package/dist/utils/fast-deep-equal/index.js +0 -90
  212. package/dist/utils/fast-deep-equal/index.js.map +0 -1
  213. package/dist/utils/http.js +0 -53
  214. package/dist/utils/http.js.map +0 -1
  215. package/dist/utils/index.js +0 -27
  216. package/dist/utils/index.js.map +0 -1
  217. package/dist/utils/isEmptyObject.js +0 -5
  218. package/dist/utils/isEmptyObject.js.map +0 -1
  219. package/dist/utils/noop.js +0 -4
  220. package/dist/utils/noop.js.map +0 -1
  221. package/dist/utils/sleep.js +0 -7
  222. package/dist/utils/sleep.js.map +0 -1
  223. package/dist/utils/timedPromise.js +0 -17
  224. package/dist/utils/timedPromise.js.map +0 -1
  225. package/dist/validators.js +0 -175
  226. package/dist/validators.js.map +0 -1
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class LDInvalidSDKKeyError extends Error {
4
- constructor(message) {
5
- super(message);
6
- this.name = 'LaunchDarklyInvalidSDKKeyError';
7
- }
8
- }
9
- exports.default = LDInvalidSDKKeyError;
10
- //# sourceMappingURL=LDInvalidSDKKeyError.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LDInvalidSDKKeyError.js","sourceRoot":"","sources":["../../../src/internal/events/LDInvalidSDKKeyError.ts"],"names":[],"mappings":";;AAAA,MAAqB,oBAAqB,SAAQ,KAAK;IACrD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gCAAgC,CAAC;IAC/C,CAAC;CACF;AALD,uCAKC"}
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class NullEventProcessor {
4
- close() { }
5
- async flush() {
6
- // empty comment to keep ts and eslint happy
7
- }
8
- sendEvent() { }
9
- }
10
- exports.default = NullEventProcessor;
11
- //# sourceMappingURL=NullEventProcessor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NullEventProcessor.js","sourceRoot":"","sources":["../../../src/internal/events/NullEventProcessor.ts"],"names":[],"mappings":";;AAEA,MAAqB,kBAAkB;IACrC,KAAK,KAAI,CAAC;IAEV,KAAK,CAAC,KAAK;QACT,4CAA4C;IAC9C,CAAC;IAED,SAAS,KAAI,CAAC;CACf;AARD,qCAQC"}
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /**
4
- * @internal
5
- */
6
- class SummaryCounter {
7
- constructor(count, key, value, defValue, version, variation) {
8
- this.count = count;
9
- this.key = key;
10
- this.value = value;
11
- this.version = version;
12
- this.variation = variation;
13
- this.default = defValue;
14
- }
15
- increment() {
16
- this.count += 1;
17
- }
18
- }
19
- exports.default = SummaryCounter;
20
- //# sourceMappingURL=SummaryCounter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SummaryCounter.js","sourceRoot":"","sources":["../../../src/internal/events/SummaryCounter.ts"],"names":[],"mappings":";;AAAA;;GAEG;AACH,MAAqB,cAAc;IAGjC,YACS,KAAa,EACb,GAAW,EACX,KAAU,EACjB,QAAa,EACN,OAAgB,EAChB,SAAkB;QALlB,UAAK,GAAL,KAAK,CAAQ;QACb,QAAG,GAAH,GAAG,CAAQ;QACX,UAAK,GAAL,KAAK,CAAK;QAEV,YAAO,GAAP,OAAO,CAAS;QAChB,cAAS,GAAT,SAAS,CAAS;QAEzB,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC;IAC1B,CAAC;IAED,SAAS;QACP,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC;IAClB,CAAC;CACF;AAjBD,iCAiBC"}
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isMigration = exports.isIdentify = exports.isCustom = exports.isFeature = void 0;
4
- function isFeature(u) {
5
- return u.kind === 'feature';
6
- }
7
- exports.isFeature = isFeature;
8
- function isCustom(u) {
9
- return u.kind === 'custom';
10
- }
11
- exports.isCustom = isCustom;
12
- function isIdentify(u) {
13
- return u.kind === 'identify';
14
- }
15
- exports.isIdentify = isIdentify;
16
- function isMigration(u) {
17
- return u.kind === 'migration_op';
18
- }
19
- exports.isMigration = isMigration;
20
- //# sourceMappingURL=guards.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"guards.js","sourceRoot":"","sources":["../../../src/internal/events/guards.ts"],"names":[],"mappings":";;;AAKA,SAAgB,SAAS,CAAC,CAAM;IAC9B,OAAO,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC;AAC9B,CAAC;AAFD,8BAEC;AAED,SAAgB,QAAQ,CAAC,CAAM;IAC7B,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC;AAC7B,CAAC;AAFD,4BAEC;AAED,SAAgB,UAAU,CAAC,CAAM;IAC/B,OAAO,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC;AAC/B,CAAC;AAFD,gCAEC;AAED,SAAgB,WAAW,CAAC,CAAM;IAChC,OAAO,CAAC,CAAC,IAAI,KAAK,cAAc,CAAC;AACnC,CAAC;AAFD,kCAEC"}
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NullEventProcessor = exports.shouldSample = exports.EventProcessor = exports.InputIdentifyEvent = exports.InputEvalEvent = exports.InputCustomEvent = exports.ClientMessages = void 0;
4
- const ClientMessages_1 = require("./ClientMessages");
5
- exports.ClientMessages = ClientMessages_1.default;
6
- const EventProcessor_1 = require("./EventProcessor");
7
- exports.EventProcessor = EventProcessor_1.default;
8
- const InputCustomEvent_1 = require("./InputCustomEvent");
9
- exports.InputCustomEvent = InputCustomEvent_1.default;
10
- const InputEvalEvent_1 = require("./InputEvalEvent");
11
- exports.InputEvalEvent = InputEvalEvent_1.default;
12
- const InputIdentifyEvent_1 = require("./InputIdentifyEvent");
13
- exports.InputIdentifyEvent = InputIdentifyEvent_1.default;
14
- const NullEventProcessor_1 = require("./NullEventProcessor");
15
- exports.NullEventProcessor = NullEventProcessor_1.default;
16
- const sampling_1 = require("./sampling");
17
- exports.shouldSample = sampling_1.default;
18
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/internal/events/index.ts"],"names":[],"mappings":";;;AAAA,qDAA8C;AAY5C,yBAZK,wBAAc,CAYL;AAXhB,qDAAyE;AAiBvE,yBAjBK,wBAAc,CAiBL;AAhBhB,yDAAkD;AAWhD,2BAXK,0BAAgB,CAWL;AAVlB,qDAA8C;AAW5C,yBAXK,wBAAc,CAWL;AAThB,6DAAsD;AAWpD,6BAXK,4BAAkB,CAWL;AARpB,6DAAsD;AAapD,6BAbK,4BAAkB,CAaL;AAZpB,yCAAsC;AAWpC,uBAXK,kBAAY,CAWL"}
@@ -1,23 +0,0 @@
1
- "use strict";
2
- /**
3
- * The contents of this file are for event sampling. They are not used for
4
- * any purpose requiring cryptographic security.
5
- * */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- function shouldSample(ratio) {
8
- const truncated = Math.trunc(ratio);
9
- // A radio of 1 means 1 in 1. So that will always sample. No need
10
- // to draw a random number.
11
- if (truncated === 1) {
12
- return true;
13
- }
14
- if (truncated === 0) {
15
- return false;
16
- }
17
- // Math.random() * truncated) would return 0, 1, ... (ratio - 1).
18
- // Checking for any number in the range will have approximately a 1 in X
19
- // chance. So we check for 0 as it is part of any range.
20
- return Math.floor(Math.random() * truncated) === 0;
21
- }
22
- exports.default = shouldSample;
23
- //# sourceMappingURL=sampling.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sampling.js","sourceRoot":"","sources":["../../../src/internal/events/sampling.ts"],"names":[],"mappings":";AAAA;;;KAGK;;AAEL,SAAwB,YAAY,CAAC,KAAa;IAChD,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACpC,iEAAiE;IACjE,2BAA2B;IAC3B,IAAI,SAAS,KAAK,CAAC,EAAE;QACnB,OAAO,IAAI,CAAC;KACb;IAED,IAAI,SAAS,KAAK,CAAC,EAAE;QACnB,OAAO,KAAK,CAAC;KACd;IAED,iEAAiE;IACjE,wEAAwE;IACxE,wDAAwD;IACxD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;AACrD,CAAC;AAhBD,+BAgBC"}
@@ -1,22 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./diagnostics"), exports);
18
- __exportStar(require("./evaluation"), exports);
19
- __exportStar(require("./events"), exports);
20
- __exportStar(require("./stream"), exports);
21
- __exportStar(require("./context"), exports);
22
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/internal/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,+CAA6B;AAC7B,2CAAyB;AACzB,2CAAyB;AACzB,4CAA0B"}
@@ -1,112 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const errors_1 = require("../../errors");
4
- const ServiceEndpoints_1 = require("../../options/ServiceEndpoints");
5
- const utils_1 = require("../../utils");
6
- const reportJsonError = (type, data, logger, errorHandler) => {
7
- logger === null || logger === void 0 ? void 0 : logger.error(`Stream received invalid data in "${type}" message`);
8
- logger === null || logger === void 0 ? void 0 : logger.debug(`Invalid JSON follows: ${data}`);
9
- errorHandler === null || errorHandler === void 0 ? void 0 : errorHandler(new errors_1.LDStreamingError('Malformed JSON data in event stream'));
10
- };
11
- class StreamingProcessor {
12
- constructor(sdkKey, clientContext, streamUriPath, parameters, listeners, diagnosticsManager, errorHandler, streamInitialReconnectDelay = 1) {
13
- this.listeners = listeners;
14
- this.diagnosticsManager = diagnosticsManager;
15
- this.errorHandler = errorHandler;
16
- this.streamInitialReconnectDelay = streamInitialReconnectDelay;
17
- const { basicConfiguration, platform } = clientContext;
18
- const { logger, tags } = basicConfiguration;
19
- const { info, requests } = platform;
20
- this.headers = (0, utils_1.defaultHeaders)(sdkKey, info, tags);
21
- this.logger = logger;
22
- this.requests = requests;
23
- this.streamUri = (0, ServiceEndpoints_1.getStreamingUri)(basicConfiguration.serviceEndpoints, streamUriPath, parameters);
24
- }
25
- logConnectionStarted() {
26
- this.connectionAttemptStartTime = Date.now();
27
- }
28
- logConnectionResult(success) {
29
- if (this.connectionAttemptStartTime && this.diagnosticsManager) {
30
- this.diagnosticsManager.recordStreamInit(this.connectionAttemptStartTime, !success, Date.now() - this.connectionAttemptStartTime);
31
- }
32
- this.connectionAttemptStartTime = undefined;
33
- }
34
- /**
35
- * This is a wrapper around the passed errorHandler which adds additional
36
- * diagnostics and logging logic.
37
- *
38
- * @param err The error to be logged and handled.
39
- * @return boolean whether to retry the connection.
40
- *
41
- * @private
42
- */
43
- retryAndHandleError(err) {
44
- var _a, _b, _c;
45
- if (!(0, utils_1.shouldRetry)(err)) {
46
- this.logConnectionResult(false);
47
- (_a = this.errorHandler) === null || _a === void 0 ? void 0 : _a.call(this, new errors_1.LDStreamingError(err.message, err.status));
48
- (_b = this.logger) === null || _b === void 0 ? void 0 : _b.error((0, utils_1.httpErrorMessage)(err, 'streaming request'));
49
- return false;
50
- }
51
- (_c = this.logger) === null || _c === void 0 ? void 0 : _c.warn((0, utils_1.httpErrorMessage)(err, 'streaming request', 'will retry'));
52
- this.logConnectionResult(false);
53
- this.logConnectionStarted();
54
- return true;
55
- }
56
- start() {
57
- this.logConnectionStarted();
58
- // TLS is handled by the platform implementation.
59
- const eventSource = this.requests.createEventSource(this.streamUri, {
60
- headers: this.headers,
61
- errorFilter: (error) => this.retryAndHandleError(error),
62
- initialRetryDelayMillis: 1000 * this.streamInitialReconnectDelay,
63
- readTimeoutMillis: 5 * 60 * 1000,
64
- retryResetIntervalMillis: 60 * 1000,
65
- });
66
- this.eventSource = eventSource;
67
- eventSource.onclose = () => {
68
- var _a;
69
- (_a = this.logger) === null || _a === void 0 ? void 0 : _a.info('Closed LaunchDarkly stream connection');
70
- };
71
- eventSource.onerror = () => {
72
- // The work is done by `errorFilter`.
73
- };
74
- eventSource.onopen = () => {
75
- var _a;
76
- (_a = this.logger) === null || _a === void 0 ? void 0 : _a.info('Opened LaunchDarkly stream connection');
77
- };
78
- eventSource.onretrying = (e) => {
79
- var _a;
80
- (_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`Will retry stream connection in ${e.delayMillis} milliseconds`);
81
- };
82
- this.listeners.forEach(({ deserializeData, processJson }, eventName) => {
83
- eventSource.addEventListener(eventName, (event) => {
84
- var _a, _b;
85
- (_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug(`Received ${eventName} event`);
86
- if (event === null || event === void 0 ? void 0 : event.data) {
87
- this.logConnectionResult(true);
88
- const { data } = event;
89
- const dataJson = deserializeData(data);
90
- if (!dataJson) {
91
- reportJsonError(eventName, data, this.logger, this.errorHandler);
92
- return;
93
- }
94
- processJson(dataJson);
95
- }
96
- else {
97
- (_b = this.errorHandler) === null || _b === void 0 ? void 0 : _b.call(this, new errors_1.LDStreamingError('Unexpected payload from event stream'));
98
- }
99
- });
100
- });
101
- }
102
- stop() {
103
- var _a;
104
- (_a = this.eventSource) === null || _a === void 0 ? void 0 : _a.close();
105
- this.eventSource = undefined;
106
- }
107
- close() {
108
- this.stop();
109
- }
110
- }
111
- exports.default = StreamingProcessor;
112
- //# sourceMappingURL=StreamingProcessor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StreamingProcessor.js","sourceRoot":"","sources":["../../../src/internal/stream/StreamingProcessor.ts"],"names":[],"mappings":";;AASA,yCAAgD;AAEhD,qEAAiE;AACjE,uCAA4E;AAI5E,MAAM,eAAe,GAAG,CACtB,IAAY,EACZ,IAAY,EACZ,MAAiB,EACjB,YAAoC,EACpC,EAAE;IACF,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,CAAC,oCAAoC,IAAI,WAAW,CAAC,CAAC;IACnE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,CAAC,yBAAyB,IAAI,EAAE,CAAC,CAAC;IAC/C,YAAY,aAAZ,YAAY,uBAAZ,YAAY,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;IACL,CAAC;IAED,IAAI;;QACF,MAAA,IAAI,CAAC,WAAW,0CAAE,KAAK,EAAE,CAAC;QAC1B,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC;IAC/B,CAAC;IAED,KAAK;QACH,IAAI,CAAC,IAAI,EAAE,CAAC;IACd,CAAC;CACF;AAED,kBAAe,kBAAkB,CAAC"}
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StreamingProcessor = void 0;
4
- const StreamingProcessor_1 = require("./StreamingProcessor");
5
- exports.StreamingProcessor = StreamingProcessor_1.default;
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/internal/stream/index.ts"],"names":[],"mappings":";;;AAAA,6DAAsD;AAG7C,6BAHF,4BAAkB,CAGE"}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/internal/stream/types.ts"],"names":[],"mappings":""}
@@ -1,97 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const format_1 = require("./format");
4
- const LogPriority = {
5
- debug: 0,
6
- info: 1,
7
- warn: 2,
8
- error: 3,
9
- none: 4,
10
- };
11
- const LevelNames = ['debug', 'info', 'warn', 'error', 'none'];
12
- /**
13
- * A basic logger which handles filtering by level.
14
- *
15
- * With the default options it will write to `console.error`
16
- * and it will use the formatting provided by `console.error`.
17
- * If the destination is overwritten, then it will use an included
18
- * formatter similar to `util.format`.
19
- *
20
- * If a formatter is available, then that should be overridden
21
- * as well for performance.
22
- */
23
- class BasicLogger {
24
- /**
25
- * This should only be used as a default fallback and not as a convenient
26
- * solution. In most cases you should construct a new instance with the
27
- * appropriate options for your specific needs.
28
- */
29
- static get() {
30
- return new BasicLogger({});
31
- }
32
- constructor(options) {
33
- var _a, _b, _c;
34
- this.logLevel = (_b = LogPriority[(_a = options.level) !== null && _a !== void 0 ? _a : 'info']) !== null && _b !== void 0 ? _b : LogPriority.info;
35
- this.name = (_c = options.name) !== null && _c !== void 0 ? _c : 'LaunchDarkly';
36
- // eslint-disable-next-line no-console
37
- this.destination = options.destination;
38
- this.formatter = options.formatter;
39
- }
40
- tryFormat(...args) {
41
- var _a;
42
- try {
43
- if (this.formatter) {
44
- // In case the provided formatter fails.
45
- return (_a = this.formatter) === null || _a === void 0 ? void 0 : _a.call(this, ...args);
46
- }
47
- return (0, format_1.default)(...args);
48
- }
49
- catch (_b) {
50
- return (0, format_1.default)(...args);
51
- }
52
- }
53
- tryWrite(msg) {
54
- try {
55
- this.destination(msg);
56
- }
57
- catch (_a) {
58
- // eslint-disable-next-line no-console
59
- console.error(msg);
60
- }
61
- }
62
- log(level, args) {
63
- if (level >= this.logLevel) {
64
- const prefix = `${LevelNames[level]}: [${this.name}]`;
65
- try {
66
- if (this.destination) {
67
- this.tryWrite(`${prefix} ${this.tryFormat(...args)}`);
68
- }
69
- else {
70
- // `console.error` has its own formatter.
71
- // So we don't need to do anything.
72
- // eslint-disable-next-line no-console
73
- console.error(...args);
74
- }
75
- }
76
- catch (_a) {
77
- // If all else fails do not break.
78
- // eslint-disable-next-line no-console
79
- console.error(...args);
80
- }
81
- }
82
- }
83
- error(...args) {
84
- this.log(LogPriority.error, args);
85
- }
86
- warn(...args) {
87
- this.log(LogPriority.warn, args);
88
- }
89
- info(...args) {
90
- this.log(LogPriority.info, args);
91
- }
92
- debug(...args) {
93
- this.log(LogPriority.debug, args);
94
- }
95
- }
96
- exports.default = BasicLogger;
97
- //# sourceMappingURL=BasicLogger.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BasicLogger.js","sourceRoot":"","sources":["../../src/logging/BasicLogger.ts"],"names":[],"mappings":";;AACA,qCAA8B;AAE9B,MAAM,WAAW,GAAG;IAClB,KAAK,EAAE,CAAC;I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I,KAAK,IAAI,IAAI,CAAC,QAAQ,EAAE;YAC1B,MAAM,MAAM,GAAG,GAAG,UAAU,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,IAAI,GAAG,CAAC;YACtD,IAAI;gBACF,IAAI,IAAI,CAAC,WAAW,EAAE;oBACpB,IAAI,CAAC,QAAQ,CAAC,GAAG,MAAM,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;iBACvD;qBAAM;oBACL,yCAAyC;oBACzC,mCAAmC;oBACnC,sCAAsC;oBACtC,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;iBACxB;aACF;YAAC,WAAM;gBACN,kCAAkC;gBAClC,sCAAsC;gBACtC,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;aACxB;SACF;IACH,CAAC;IAED,KAAK,CAAC,GAAG,IAAW;QAClB,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,IAAI,CAAC,GAAG,IAAW;QACjB,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,IAAI,CAAC,GAAG,IAAW;QACjB,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,GAAG,IAAW;QAClB,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACpC,CAAC;CACF;AAlFD,8BAkFC"}
@@ -1,63 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const validators_1 = require("../validators");
4
- const loggerRequirements = {
5
- error: validators_1.TypeValidators.Function,
6
- warn: validators_1.TypeValidators.Function,
7
- info: validators_1.TypeValidators.Function,
8
- debug: validators_1.TypeValidators.Function,
9
- };
10
- /**
11
- * The safeLogger logic exists because we allow the application to pass in a custom logger, but
12
- * there is no guarantee that the logger works correctly and if it ever throws exceptions there
13
- * could be serious consequences (e.g. an uncaught exception within an error event handler, due
14
- * to the SDK trying to log the error, can terminate the application). An exception could result
15
- * from faulty logic in the logger implementation, or it could be that this is not a logger at
16
- * all but some other kind of object; the former is handled by a catch block that logs an error
17
- * message to the SDK's default logger, and we can at least partly guard against the latter by
18
- * checking for the presence of required methods at configuration time.
19
- */
20
- class SafeLogger {
21
- /**
22
- * Construct a safe logger with the specified logger.
23
- * @param logger The logger to use.
24
- * @param fallback A fallback logger to use in case an issue is encountered using
25
- * the provided logger.
26
- */
27
- constructor(logger, fallback) {
28
- Object.entries(loggerRequirements).forEach(([level, validator]) => {
29
- if (!validator.is(logger[level])) {
30
- throw new Error(`Provided logger instance must support logger.${level}(...) method`);
31
- // Note that the SDK normally does not throw exceptions to the application, but that rule
32
- // does not apply to LDClient.init() which will throw an exception if the parameters are so
33
- // invalid that we cannot proceed with creating the client. An invalid logger meets those
34
- // criteria since the SDK calls the logger during nearly all of its operations.
35
- }
36
- });
37
- this.logger = logger;
38
- this.fallback = fallback;
39
- }
40
- log(level, args) {
41
- try {
42
- this.logger[level](...args);
43
- }
44
- catch (_a) {
45
- // If all else fails do not break.
46
- this.fallback[level](...args);
47
- }
48
- }
49
- error(...args) {
50
- this.log('error', args);
51
- }
52
- warn(...args) {
53
- this.log('warn', args);
54
- }
55
- info(...args) {
56
- this.log('info', args);
57
- }
58
- debug(...args) {
59
- this.log('debug', args);
60
- }
61
- }
62
- exports.default = SafeLogger;
63
- //# sourceMappingURL=SafeLogger.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SafeLogger.js","sourceRoot":"","sources":["../../src/logging/SafeLogger.ts"],"names":[],"mappings":";;AACA,8CAA+C;AAE/C,MAAM,kBAAkB,GAAG;IACzB,KAAK,EAAE,2BAAc,CAAC,QAAQ;IAC9B,IAAI,EAAE,2BAAc,CAAC,QAAQ;IAC7B,IA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AE,IAAI,CAAC,CAAC;IAC1B,CAAC;CACF;AAjDD,6BAiDC"}
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const BasicLogger_1 = require("./BasicLogger");
4
- const format_1 = require("./format");
5
- const SafeLogger_1 = require("./SafeLogger");
6
- const createSafeLogger = (logger) => {
7
- const basicLogger = new BasicLogger_1.default({
8
- level: 'info',
9
- // eslint-disable-next-line no-console
10
- destination: console.error,
11
- formatter: format_1.default,
12
- });
13
- return logger ? new SafeLogger_1.default(logger, basicLogger) : basicLogger;
14
- };
15
- exports.default = createSafeLogger;
16
- //# sourceMappingURL=createSafeLogger.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createSafeLogger.js","sourceRoot":"","sources":["../../src/logging/createSafeLogger.ts"],"names":[],"mappings":";;AACA,+CAAwC;AACxC,qCAA8B;AAC9B,6CAAsC;AAEtC,MAAM,gBAAgB,GAAG,CAAC,MAAiB,EAAE,EAAE;IAC7C,MAAM,WAAW,GAAG,IAAI,qBAAW,CAAC;QAClC,KAAK,EAAE,MAAM;QACb,sCAAsC;QACtC,WAAW,EAAE,OAAO,CAAC,KAAK;QAC1B,SAAS,EAAE,gBAAM;KAClB,CAAC,CAAC;IACH,OAAO,MAAM,CAAC,CAAC,CAAC,IAAI,oBAAU,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;AACpE,CAAC,CAAC;AAEF,kBAAe,gBAAgB,CAAC"}
@@ -1,156 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const validators_1 = require("../validators");
4
- /**
5
- * Attempt to produce a string representation of a value.
6
- * The format should be roughly comparable to `util.format`
7
- * aside from object which will be JSON versus the `util.inspect`
8
- * format.
9
- * @param val
10
- * @returns A string representation of the value if possible.
11
- */
12
- function tryStringify(val) {
13
- if (typeof val === 'string') {
14
- return val;
15
- }
16
- if (val === undefined) {
17
- return 'undefined';
18
- }
19
- if (val === null) {
20
- return 'null';
21
- }
22
- if (Object.prototype.hasOwnProperty.call(val, 'toString')) {
23
- try {
24
- return val.toString();
25
- }
26
- catch (_a) {
27
- /* Keep going */
28
- }
29
- }
30
- if (typeof val === 'bigint') {
31
- return `${val}n`;
32
- }
33
- try {
34
- return JSON.stringify(val);
35
- }
36
- catch (error) {
37
- if (error instanceof TypeError && error.message.indexOf('circular') >= 0) {
38
- return '[Circular]';
39
- }
40
- return '[Not Stringifiable]';
41
- }
42
- }
43
- /**
44
- * Attempt to produce a numeric representation.
45
- * BigInts have an `n` suffix.
46
- * @param val
47
- * @returns The numeric representation or 'NaN' if not numeric.
48
- */
49
- function toNumber(val) {
50
- // Symbol has to be treated special because it will
51
- // throw an exception if an attempt is made to convert it.
52
- if (typeof val === 'symbol') {
53
- return 'NaN';
54
- }
55
- if (typeof val === 'bigint') {
56
- return `${val}n`;
57
- }
58
- return String(Number(val));
59
- }
60
- /**
61
- * Attempt to produce an integer representation.
62
- * BigInts have an `n` suffix.
63
- * @param val
64
- * @returns The integer representation or 'NaN' if not numeric.
65
- */
66
- function toInt(val) {
67
- if (typeof val === 'symbol') {
68
- return 'NaN';
69
- }
70
- if (typeof val === 'bigint') {
71
- return `${val}n`;
72
- }
73
- return String(parseInt(val, 10));
74
- }
75
- /**
76
- * Attempt to produce a float representation.
77
- * BigInts have an `n` suffix.
78
- * @param val
79
- * @returns The integer representation or 'NaN' if not numeric.
80
- */
81
- function toFloat(val) {
82
- if (typeof val === 'symbol') {
83
- return 'NaN';
84
- }
85
- return String(parseFloat(val));
86
- }
87
- // Based on:
88
- // https://nodejs.org/api/util.html#utilformatformat-args
89
- // The result will not match node exactly, but it should get the
90
- // right information through.
91
- const escapes = {
92
- s: (val) => tryStringify(val),
93
- d: (val) => toNumber(val),
94
- i: (val) => toInt(val),
95
- f: (val) => toFloat(val),
96
- j: (val) => tryStringify(val),
97
- o: (val) => tryStringify(val),
98
- O: (val) => tryStringify(val),
99
- c: () => '',
100
- };
101
- /**
102
- * A basic formatted for use where `util.format` is not available.
103
- * This will not be as performant, but it will produce formatted
104
- * messages.
105
- *
106
- * @internal
107
- *
108
- * @param args
109
- * @returns Formatted string.
110
- */
111
- function format(...args) {
112
- var _a;
113
- const formatString = args.shift();
114
- if (validators_1.TypeValidators.String.is(formatString)) {
115
- let out = '';
116
- let i = 0;
117
- while (i < formatString.length) {
118
- const char = formatString.charAt(i);
119
- if (char === '%') {
120
- const nextIndex = i + 1;
121
- if (nextIndex < formatString.length) {
122
- const nextChar = formatString.charAt(i + 1);
123
- if (nextChar in escapes && args.length) {
124
- const value = args.shift();
125
- // This rule is for math.
126
- // eslint-disable-next-line no-unsafe-optional-chaining
127
- out += (_a = escapes[nextChar]) === null || _a === void 0 ? void 0 : _a.call(escapes, value);
128
- }
129
- else if (nextChar === '%') {
130
- out += '%';
131
- }
132
- else {
133
- out += `%${nextChar}`;
134
- }
135
- i += 2;
136
- }
137
- }
138
- else {
139
- out += char;
140
- i += 1;
141
- }
142
- }
143
- // If there are any args left after we exhaust the format string
144
- // then just stick those on the end.
145
- if (args.length) {
146
- if (out.length) {
147
- out += ' ';
148
- }
149
- out += args.map(tryStringify).join(' ');
150
- }
151
- return out;
152
- }
153
- return args.map(tryStringify).join(' ');
154
- }
155
- exports.default = format;
156
- //# sourceMappingURL=format.js.map