@launchdarkly/js-client-sdk-common 1.19.1 → 1.21.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 (130) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/dist/cjs/api/datasource/DataSourceEntry.d.ts +45 -0
  3. package/dist/cjs/api/datasource/DataSourceEntry.d.ts.map +1 -0
  4. package/dist/cjs/api/datasource/FDv2ConnectionMode.d.ts +30 -0
  5. package/dist/cjs/api/datasource/FDv2ConnectionMode.d.ts.map +1 -0
  6. package/dist/cjs/api/datasource/LDClientDataSystemOptions.d.ts +75 -0
  7. package/dist/cjs/api/datasource/LDClientDataSystemOptions.d.ts.map +1 -0
  8. package/dist/cjs/api/datasource/ModeDefinition.d.ts +21 -0
  9. package/dist/cjs/api/datasource/ModeDefinition.d.ts.map +1 -0
  10. package/dist/cjs/api/datasource/index.d.ts +5 -0
  11. package/dist/cjs/api/datasource/index.d.ts.map +1 -0
  12. package/dist/cjs/api/index.d.ts +1 -0
  13. package/dist/cjs/api/index.d.ts.map +1 -1
  14. package/dist/cjs/configuration/Configuration.d.ts +0 -1
  15. package/dist/cjs/configuration/Configuration.d.ts.map +1 -1
  16. package/dist/cjs/configuration/validateOptions.d.ts +95 -0
  17. package/dist/cjs/configuration/validateOptions.d.ts.map +1 -0
  18. package/dist/cjs/datasource/ConnectionModeConfig.d.ts +19 -0
  19. package/dist/cjs/datasource/ConnectionModeConfig.d.ts.map +1 -0
  20. package/dist/cjs/datasource/DataSourceConfig.d.ts +1 -0
  21. package/dist/cjs/datasource/DataSourceConfig.d.ts.map +1 -1
  22. package/dist/cjs/datasource/Endpoints.d.ts +21 -0
  23. package/dist/cjs/datasource/Endpoints.d.ts.map +1 -0
  24. package/dist/cjs/datasource/LDClientDataSystemOptions.d.ts +20 -0
  25. package/dist/cjs/datasource/LDClientDataSystemOptions.d.ts.map +1 -0
  26. package/dist/cjs/datasource/StateDebounceManager.d.ts +92 -0
  27. package/dist/cjs/datasource/StateDebounceManager.d.ts.map +1 -0
  28. package/dist/cjs/datasource/fdv2/AsyncQueue.d.ts +2 -0
  29. package/dist/cjs/datasource/fdv2/AsyncQueue.d.ts.map +1 -0
  30. package/dist/cjs/datasource/fdv2/Conditions.d.ts +73 -0
  31. package/dist/cjs/datasource/fdv2/Conditions.d.ts.map +1 -0
  32. package/dist/cjs/datasource/fdv2/FDv2DataSource.d.ts +52 -0
  33. package/dist/cjs/datasource/fdv2/FDv2DataSource.d.ts.map +1 -0
  34. package/dist/cjs/datasource/fdv2/FDv2Requestor.d.ts +45 -0
  35. package/dist/cjs/datasource/fdv2/FDv2Requestor.d.ts.map +1 -0
  36. package/dist/cjs/datasource/fdv2/FDv2SourceResult.d.ts +82 -0
  37. package/dist/cjs/datasource/fdv2/FDv2SourceResult.d.ts.map +1 -0
  38. package/dist/cjs/datasource/fdv2/Initializer.d.ts +40 -0
  39. package/dist/cjs/datasource/fdv2/Initializer.d.ts.map +1 -0
  40. package/dist/cjs/datasource/fdv2/PollingBase.d.ts +2 -0
  41. package/dist/cjs/datasource/fdv2/PollingBase.d.ts.map +1 -0
  42. package/dist/cjs/datasource/fdv2/PollingInitializer.d.ts +2 -0
  43. package/dist/cjs/datasource/fdv2/PollingInitializer.d.ts.map +1 -0
  44. package/dist/cjs/datasource/fdv2/PollingSynchronizer.d.ts +2 -0
  45. package/dist/cjs/datasource/fdv2/PollingSynchronizer.d.ts.map +1 -0
  46. package/dist/cjs/datasource/fdv2/SourceManager.d.ts +88 -0
  47. package/dist/cjs/datasource/fdv2/SourceManager.d.ts.map +1 -0
  48. package/dist/cjs/datasource/fdv2/StreamingFDv2Base.d.ts +11 -0
  49. package/dist/cjs/datasource/fdv2/StreamingFDv2Base.d.ts.map +1 -0
  50. package/dist/cjs/datasource/fdv2/StreamingInitializerFDv2.d.ts +2 -0
  51. package/dist/cjs/datasource/fdv2/StreamingInitializerFDv2.d.ts.map +1 -0
  52. package/dist/cjs/datasource/fdv2/StreamingSynchronizerFDv2.d.ts +2 -0
  53. package/dist/cjs/datasource/fdv2/StreamingSynchronizerFDv2.d.ts.map +1 -0
  54. package/dist/cjs/datasource/fdv2/Synchronizer.d.ts +49 -0
  55. package/dist/cjs/datasource/fdv2/Synchronizer.d.ts.map +1 -0
  56. package/dist/cjs/datasource/fdv2/index.d.ts +16 -0
  57. package/dist/cjs/datasource/fdv2/index.d.ts.map +1 -0
  58. package/dist/cjs/datasource/flagEvalMapper.d.ts +31 -0
  59. package/dist/cjs/datasource/flagEvalMapper.d.ts.map +1 -0
  60. package/dist/cjs/index.cjs +187 -40
  61. package/dist/cjs/index.cjs.map +1 -1
  62. package/dist/cjs/index.d.ts +5 -0
  63. package/dist/cjs/index.d.ts.map +1 -1
  64. package/dist/cjs/types/index.d.ts +15 -0
  65. package/dist/cjs/types/index.d.ts.map +1 -1
  66. package/dist/esm/api/datasource/DataSourceEntry.d.ts +45 -0
  67. package/dist/esm/api/datasource/DataSourceEntry.d.ts.map +1 -0
  68. package/dist/esm/api/datasource/FDv2ConnectionMode.d.ts +30 -0
  69. package/dist/esm/api/datasource/FDv2ConnectionMode.d.ts.map +1 -0
  70. package/dist/esm/api/datasource/LDClientDataSystemOptions.d.ts +75 -0
  71. package/dist/esm/api/datasource/LDClientDataSystemOptions.d.ts.map +1 -0
  72. package/dist/esm/api/datasource/ModeDefinition.d.ts +21 -0
  73. package/dist/esm/api/datasource/ModeDefinition.d.ts.map +1 -0
  74. package/dist/esm/api/datasource/index.d.ts +5 -0
  75. package/dist/esm/api/datasource/index.d.ts.map +1 -0
  76. package/dist/esm/api/index.d.ts +1 -0
  77. package/dist/esm/api/index.d.ts.map +1 -1
  78. package/dist/esm/configuration/Configuration.d.ts +0 -1
  79. package/dist/esm/configuration/Configuration.d.ts.map +1 -1
  80. package/dist/esm/configuration/validateOptions.d.ts +95 -0
  81. package/dist/esm/configuration/validateOptions.d.ts.map +1 -0
  82. package/dist/esm/datasource/ConnectionModeConfig.d.ts +19 -0
  83. package/dist/esm/datasource/ConnectionModeConfig.d.ts.map +1 -0
  84. package/dist/esm/datasource/DataSourceConfig.d.ts +1 -0
  85. package/dist/esm/datasource/DataSourceConfig.d.ts.map +1 -1
  86. package/dist/esm/datasource/Endpoints.d.ts +21 -0
  87. package/dist/esm/datasource/Endpoints.d.ts.map +1 -0
  88. package/dist/esm/datasource/LDClientDataSystemOptions.d.ts +20 -0
  89. package/dist/esm/datasource/LDClientDataSystemOptions.d.ts.map +1 -0
  90. package/dist/esm/datasource/StateDebounceManager.d.ts +92 -0
  91. package/dist/esm/datasource/StateDebounceManager.d.ts.map +1 -0
  92. package/dist/esm/datasource/fdv2/AsyncQueue.d.ts +2 -0
  93. package/dist/esm/datasource/fdv2/AsyncQueue.d.ts.map +1 -0
  94. package/dist/esm/datasource/fdv2/Conditions.d.ts +73 -0
  95. package/dist/esm/datasource/fdv2/Conditions.d.ts.map +1 -0
  96. package/dist/esm/datasource/fdv2/FDv2DataSource.d.ts +52 -0
  97. package/dist/esm/datasource/fdv2/FDv2DataSource.d.ts.map +1 -0
  98. package/dist/esm/datasource/fdv2/FDv2Requestor.d.ts +45 -0
  99. package/dist/esm/datasource/fdv2/FDv2Requestor.d.ts.map +1 -0
  100. package/dist/esm/datasource/fdv2/FDv2SourceResult.d.ts +82 -0
  101. package/dist/esm/datasource/fdv2/FDv2SourceResult.d.ts.map +1 -0
  102. package/dist/esm/datasource/fdv2/Initializer.d.ts +40 -0
  103. package/dist/esm/datasource/fdv2/Initializer.d.ts.map +1 -0
  104. package/dist/esm/datasource/fdv2/PollingBase.d.ts +2 -0
  105. package/dist/esm/datasource/fdv2/PollingBase.d.ts.map +1 -0
  106. package/dist/esm/datasource/fdv2/PollingInitializer.d.ts +2 -0
  107. package/dist/esm/datasource/fdv2/PollingInitializer.d.ts.map +1 -0
  108. package/dist/esm/datasource/fdv2/PollingSynchronizer.d.ts +2 -0
  109. package/dist/esm/datasource/fdv2/PollingSynchronizer.d.ts.map +1 -0
  110. package/dist/esm/datasource/fdv2/SourceManager.d.ts +88 -0
  111. package/dist/esm/datasource/fdv2/SourceManager.d.ts.map +1 -0
  112. package/dist/esm/datasource/fdv2/StreamingFDv2Base.d.ts +11 -0
  113. package/dist/esm/datasource/fdv2/StreamingFDv2Base.d.ts.map +1 -0
  114. package/dist/esm/datasource/fdv2/StreamingInitializerFDv2.d.ts +2 -0
  115. package/dist/esm/datasource/fdv2/StreamingInitializerFDv2.d.ts.map +1 -0
  116. package/dist/esm/datasource/fdv2/StreamingSynchronizerFDv2.d.ts +2 -0
  117. package/dist/esm/datasource/fdv2/StreamingSynchronizerFDv2.d.ts.map +1 -0
  118. package/dist/esm/datasource/fdv2/Synchronizer.d.ts +49 -0
  119. package/dist/esm/datasource/fdv2/Synchronizer.d.ts.map +1 -0
  120. package/dist/esm/datasource/fdv2/index.d.ts +16 -0
  121. package/dist/esm/datasource/fdv2/index.d.ts.map +1 -0
  122. package/dist/esm/datasource/flagEvalMapper.d.ts +31 -0
  123. package/dist/esm/datasource/flagEvalMapper.d.ts.map +1 -0
  124. package/dist/esm/index.d.ts +5 -0
  125. package/dist/esm/index.d.ts.map +1 -1
  126. package/dist/esm/index.mjs +185 -42
  127. package/dist/esm/index.mjs.map +1 -1
  128. package/dist/esm/types/index.d.ts +15 -0
  129. package/dist/esm/types/index.d.ts.map +1 -1
  130. package/package.json +2 -2
@@ -1,4 +1,4 @@
1
- import { getPollingUri, TypeValidators, createSafeLogger, ServiceEndpoints, ApplicationTags, OptionMessages, NumberWithMinimum, SafeLogger, internal, deepCompact, clone, secondsToMillis, ClientContext, fastDeepEqual, defaultHeaders, Context, LDTimeoutError, AutoEnvAttributes, cancelableTimedPromise, LDClientError, isHttpRecoverable, httpErrorMessage, LDPollingError, DataSourceErrorKind, getStreamingUri, shouldRetry, LDStreamingError } from '@launchdarkly/js-sdk-common';
1
+ import { getPollingUri, isNullish, TypeValidators, OptionMessages, NumberWithMinimum, createSafeLogger, ServiceEndpoints, ApplicationTags, SafeLogger, internal, deepCompact, clone, secondsToMillis, ClientContext, fastDeepEqual, defaultHeaders, Context, LDTimeoutError, AutoEnvAttributes, cancelableTimedPromise, LDClientError, base64UrlEncode, isHttpRecoverable, httpErrorMessage, LDPollingError, DataSourceErrorKind, getStreamingUri, shouldRetry, LDStreamingError } from '@launchdarkly/js-sdk-common';
2
2
  export * from '@launchdarkly/js-sdk-common';
3
3
  import * as jsSdkCommon from '@launchdarkly/js-sdk-common';
4
4
  export { jsSdkCommon as platform };
@@ -204,6 +204,74 @@ function createAsyncTaskQueue(logger) {
204
204
  };
205
205
  }
206
206
 
207
+ function isCompoundValidator(v) {
208
+ return 'validate' in v;
209
+ }
210
+ /**
211
+ * Validates an options object against a map of validators and defaults.
212
+ *
213
+ * If `input` is null, undefined, or not an object the defaults are returned
214
+ * (with a warning for non-nullish non-objects).
215
+ *
216
+ * Supports special validator types created by:
217
+ * - {@link validatorOf}: recursively validates nested objects
218
+ * - {@link arrayOf}: validates arrays with per-item validation
219
+ * - {@link anyOf}: accepts the first matching validator from a list
220
+ * - {@link recordOf}: validates objects with dynamic keys
221
+ */
222
+ function validateOptions(input, validatorMap, defaults, logger, prefix) {
223
+ const result = { ...defaults };
224
+ if (isNullish(input)) {
225
+ return result;
226
+ }
227
+ if (!TypeValidators.Object.is(input)) {
228
+ logger?.warn(OptionMessages.wrongOptionType(prefix ?? 'config', 'object', typeof input));
229
+ return result;
230
+ }
231
+ Object.entries(input).forEach(([key, value]) => {
232
+ const validator = validatorMap[key];
233
+ const name = prefix ? `${prefix}.${key}` : key;
234
+ if (!validator) {
235
+ logger?.warn(OptionMessages.unknownOption(name));
236
+ return;
237
+ }
238
+ if (isNullish(value)) {
239
+ return;
240
+ }
241
+ if (isCompoundValidator(validator)) {
242
+ const validated = validator.validate(value, name, logger, defaults[key]);
243
+ if (validated !== undefined) {
244
+ result[key] = validated.value;
245
+ }
246
+ return;
247
+ }
248
+ if (validator.is(value)) {
249
+ result[key] = value;
250
+ return;
251
+ }
252
+ // Validation failed — apply correction or fall back to default.
253
+ const validatorType = validator.getType();
254
+ if (validatorType === 'boolean') {
255
+ logger?.warn(OptionMessages.wrongOptionTypeBoolean(name, typeof value));
256
+ result[key] = !!value;
257
+ }
258
+ else if (validatorType === 'boolean | undefined | null') {
259
+ logger?.warn(OptionMessages.wrongOptionTypeBoolean(name, typeof value));
260
+ if (typeof value !== 'boolean' && typeof value !== 'undefined' && value !== null) {
261
+ result[key] = !!value;
262
+ }
263
+ }
264
+ else if (validator instanceof NumberWithMinimum && TypeValidators.Number.is(value)) {
265
+ logger?.warn(OptionMessages.optionBelowMinimum(name, value, validator.min));
266
+ result[key] = validator.min;
267
+ }
268
+ else {
269
+ logger?.warn(OptionMessages.wrongOptionType(name, validatorType, typeof value));
270
+ }
271
+ });
272
+ return result;
273
+ }
274
+
207
275
  // eslint-disable-next-line max-classes-per-file
208
276
  const validators = {
209
277
  logger: TypeValidators.Object,
@@ -273,8 +341,12 @@ class ConfigurationImpl {
273
341
  this.hooks = [];
274
342
  this.inspectors = [];
275
343
  this.logger = ensureSafeLogger(pristineOptions.logger);
276
- const errors = this._validateTypesAndNames(pristineOptions);
277
- errors.forEach((e) => this.logger.warn(e));
344
+ const validated = validateOptions(pristineOptions, validators, {}, this.logger);
345
+ Object.entries(validated).forEach(([k, v]) => {
346
+ if (k !== 'logger') {
347
+ this[k] = v;
348
+ }
349
+ });
278
350
  this.serviceEndpoints = new ServiceEndpoints(this.streamUri, this.baseUri, this.eventsUri, internalOptions.analyticsEventPath, internalOptions.diagnosticEventPath, internalOptions.includeAuthorizationHeader, pristineOptions.payloadFilterKey);
279
351
  this.useReport = pristineOptions.useReport ?? false;
280
352
  this.tags = new ApplicationTags({ application: this.applicationInfo, logger: this.logger });
@@ -283,44 +355,6 @@ class ConfigurationImpl {
283
355
  this.credentialType = internalOptions.credentialType;
284
356
  this.getImplementationHooks = internalOptions.getImplementationHooks;
285
357
  }
286
- _validateTypesAndNames(pristineOptions) {
287
- const errors = [];
288
- Object.entries(pristineOptions).forEach(([k, v]) => {
289
- const validator = validators[k];
290
- if (validator) {
291
- if (!validator.is(v)) {
292
- const validatorType = validator.getType();
293
- if (validatorType === 'boolean') {
294
- errors.push(OptionMessages.wrongOptionTypeBoolean(k, typeof v));
295
- this[k] = !!v;
296
- }
297
- else if (validatorType === 'boolean | undefined | null') {
298
- errors.push(OptionMessages.wrongOptionTypeBoolean(k, typeof v));
299
- if (typeof v !== 'boolean' && typeof v !== 'undefined' && v !== null) {
300
- this[k] = !!v;
301
- }
302
- }
303
- else if (validator instanceof NumberWithMinimum && TypeValidators.Number.is(v)) {
304
- const { min } = validator;
305
- errors.push(OptionMessages.optionBelowMinimum(k, v, min));
306
- this[k] = min;
307
- }
308
- else {
309
- errors.push(OptionMessages.wrongOptionType(k, validator.getType(), typeof v));
310
- }
311
- }
312
- else if (k === 'logger') ;
313
- else {
314
- // if an option is explicitly null, coerce to undefined
315
- this[k] = v ?? undefined;
316
- }
317
- }
318
- else {
319
- errors.push(OptionMessages.unknownOption(k));
320
- }
321
- });
322
- return errors;
323
- }
324
358
  }
325
359
 
326
360
  async function digest(hasher, encoding) {
@@ -1962,6 +1996,115 @@ function readFlagsFromBootstrap(logger, data) {
1962
1996
  return ret;
1963
1997
  }
1964
1998
 
1999
+ /**
2000
+ * Creates endpoint paths for browser (client-side ID) FDv1 evaluation.
2001
+ *
2002
+ * @param clientSideId The client-side ID for this environment.
2003
+ */
2004
+ function browserFdv1Endpoints(clientSideId) {
2005
+ return {
2006
+ polling: () => ({
2007
+ pathGet(encoding, plainContextString) {
2008
+ return `/sdk/evalx/${clientSideId}/contexts/${base64UrlEncode(plainContextString, encoding)}`;
2009
+ },
2010
+ pathReport(_encoding, _plainContextString) {
2011
+ return `/sdk/evalx/${clientSideId}/context`;
2012
+ },
2013
+ pathPost(_encoding, _plainContextString) {
2014
+ throw new Error('Post for FDv1 unsupported.');
2015
+ },
2016
+ pathPing(_encoding, _plainContextString) {
2017
+ throw new Error('Ping for polling unsupported.');
2018
+ },
2019
+ }),
2020
+ streaming: () => ({
2021
+ pathGet(encoding, plainContextString) {
2022
+ return `/eval/${clientSideId}/${base64UrlEncode(plainContextString, encoding)}`;
2023
+ },
2024
+ pathReport(_encoding, _plainContextString) {
2025
+ return `/eval/${clientSideId}`;
2026
+ },
2027
+ pathPost(_encoding, _plainContextString) {
2028
+ throw new Error('Post for FDv1 unsupported.');
2029
+ },
2030
+ pathPing(_encoding, _plainContextString) {
2031
+ return `/ping/${clientSideId}`;
2032
+ },
2033
+ }),
2034
+ };
2035
+ }
2036
+ /**
2037
+ * Creates endpoint paths for mobile (mobile key) FDv1 evaluation.
2038
+ */
2039
+ function mobileFdv1Endpoints() {
2040
+ return {
2041
+ polling: () => ({
2042
+ pathGet(encoding, plainContextString) {
2043
+ return `/msdk/evalx/contexts/${base64UrlEncode(plainContextString, encoding)}`;
2044
+ },
2045
+ pathReport(_encoding, _plainContextString) {
2046
+ return `/msdk/evalx/context`;
2047
+ },
2048
+ pathPost(_encoding, _plainContextString) {
2049
+ throw new Error('Post for FDv1 unsupported.');
2050
+ },
2051
+ pathPing(_encoding, _plainContextString) {
2052
+ throw new Error('Ping for polling unsupported.');
2053
+ },
2054
+ }),
2055
+ streaming: () => ({
2056
+ pathGet(encoding, plainContextString) {
2057
+ return `/meval/${base64UrlEncode(plainContextString, encoding)}`;
2058
+ },
2059
+ pathReport(_encoding, _plainContextString) {
2060
+ return `/meval`;
2061
+ },
2062
+ pathPost(_encoding, _plainContextString) {
2063
+ throw new Error('Post for FDv1 unsupported.');
2064
+ },
2065
+ pathPing(_encoding, _plainContextString) {
2066
+ return `/mping`;
2067
+ },
2068
+ }),
2069
+ };
2070
+ }
2071
+ /**
2072
+ * Creates endpoint paths for FDv2 evaluation.
2073
+ * Unified for all client-side platforms per CSFDV2 Requirement 2.1.1.
2074
+ */
2075
+ function fdv2Endpoints() {
2076
+ return {
2077
+ polling: () => ({
2078
+ pathGet(encoding, plainContextString) {
2079
+ return `/sdk/poll/eval/${base64UrlEncode(plainContextString, encoding)}`;
2080
+ },
2081
+ pathReport(_encoding, _plainContextString) {
2082
+ throw new Error('Report for FDv2 unsupported.');
2083
+ },
2084
+ pathPost(_encoding, _plainContextString) {
2085
+ return `/sdk/poll/eval`;
2086
+ },
2087
+ pathPing(_encoding, _plainContextString) {
2088
+ throw new Error('Ping for polling unsupported.');
2089
+ },
2090
+ }),
2091
+ streaming: () => ({
2092
+ pathGet(encoding, plainContextString) {
2093
+ return `/sdk/stream/eval/${base64UrlEncode(plainContextString, encoding)}`;
2094
+ },
2095
+ pathReport(_encoding, _plainContextString) {
2096
+ throw new Error('Report for FDv2 unsupported.');
2097
+ },
2098
+ pathPost(_encoding, _plainContextString) {
2099
+ return `/sdk/stream/eval`;
2100
+ },
2101
+ pathPing(_encoding, _plainContextString) {
2102
+ throw new Error('Ping for streaming unsupported.');
2103
+ },
2104
+ }),
2105
+ };
2106
+ }
2107
+
1965
2108
  function createDataSourceEventHandler(flagManager, statusManager, logger) {
1966
2109
  return {
1967
2110
  async handlePut(context, flags) {
@@ -2415,5 +2558,5 @@ class BaseDataManager {
2415
2558
  }
2416
2559
  }
2417
2560
 
2418
- export { BaseDataManager, DataSourceState, LDClientImpl, makeRequestor, readFlagsFromBootstrap, safeRegisterDebugOverridePlugins };
2561
+ export { BaseDataManager, DataSourceState, LDClientImpl, browserFdv1Endpoints, fdv2Endpoints, makeRequestor, mobileFdv1Endpoints, readFlagsFromBootstrap, safeRegisterDebugOverridePlugins, validateOptions };
2419
2562
  //# sourceMappingURL=index.mjs.map