launchdarkly-js-sdk-common 3.4.0 → 3.6.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "launchdarkly-js-sdk-common",
3
- "version": "3.4.0",
3
+ "version": "3.6.0",
4
4
  "description": "LaunchDarkly SDK for JavaScript - common code",
5
5
  "author": "LaunchDarkly <team@launchdarkly.com>",
6
6
  "license": "Apache-2.0",
@@ -68,7 +68,7 @@
68
68
  "rollup-plugin-uglify": "6.0.4",
69
69
  "semver": "^5.5.0",
70
70
  "semver-compare": "^1.0.0",
71
- "typescript": "^3.7.5"
71
+ "typescript": "~4.4.4"
72
72
  },
73
73
  "dependencies": {
74
74
  "base64-js": "^1.3.0",
package/typings.d.ts CHANGED
@@ -53,6 +53,8 @@ declare module 'launchdarkly-js-sdk-common' {
53
53
  * respectively.
54
54
  *
55
55
  * To make LDClient use this logger, put it in the `logger` property of [[LDOptions]].
56
+ *
57
+ * @deprecated Please use `basicLogger` instead.
56
58
  */
57
59
  export function createConsoleLogger(minimumLevel: string): LDLogger;
58
60
 
@@ -66,8 +68,7 @@ declare module 'launchdarkly-js-sdk-common' {
66
68
  /**
67
69
  * An object that will perform logging for the client.
68
70
  *
69
- * If not specified, the default is [[createConsoleLogger]] in the browser SDK, or a logger
70
- * from the `winston` package in Electron.
71
+ * If not specified, the default is to use `basicLogger`.
71
72
  */
72
73
  logger?: LDLogger;
73
74
 
@@ -132,10 +133,14 @@ declare module 'launchdarkly-js-sdk-common' {
132
133
  /**
133
134
  * Whether or not to include custom HTTP headers when requesting flags from LaunchDarkly.
134
135
  *
135
- * Currently these are used to track what version of the SDK is active. This defaults to true
136
- * (custom headers will be sent). One reason you might want to set it to false is that the presence
137
- * of custom headers causes browsers to make an extra OPTIONS request (a CORS preflight check)
138
- * before each flag request, which could affect performance.
136
+ * These are used to send metadata about the SDK (such as the version). They
137
+ * are also used to send the application.id and application.version set in
138
+ * the options.
139
+ *
140
+ * This defaults to true (custom headers will be sent). One reason you might
141
+ * want to set it to false is that the presence of custom headers causes
142
+ * browsers to make an extra OPTIONS request (a CORS preflight check) before
143
+ * each flag request, which could affect performance.
139
144
  */
140
145
  sendLDHeaders?: boolean;
141
146
 
@@ -283,6 +288,31 @@ declare module 'launchdarkly-js-sdk-common' {
283
288
  * The default value is `false`.
284
289
  */
285
290
  autoAliasingOptOut?: boolean;
291
+
292
+ /**
293
+ * Information about the application where the LaunchDarkly SDK is running.
294
+ */
295
+ application?: {
296
+ /**
297
+ * A unique identifier representing the application where the LaunchDarkly SDK is running.
298
+ *
299
+ * This can be specified as any string value as long as it only uses the following characters: ASCII letters,
300
+ * ASCII digits, period, hyphen, underscore. A string containing any other characters will be ignored.
301
+ *
302
+ * Example: `authentication-service`
303
+ */
304
+ id?: string;
305
+
306
+ /**
307
+ * A unique identifier representing the version of the application where the LaunchDarkly SDK is running.
308
+ *
309
+ * This can be specified as any string value as long as it only uses the following characters: ASCII letters,
310
+ * ASCII digits, period, hyphen, underscore. A string containing any other characters will be ignored.
311
+ *
312
+ * Example: `1.0.0` (standard version string) or `abcdef` (sha prefix)
313
+ */
314
+ version?: string;
315
+ }
286
316
  }
287
317
 
288
318
  /**
@@ -450,8 +480,7 @@ declare module 'launchdarkly-js-sdk-common' {
450
480
  }
451
481
 
452
482
  /**
453
- * The basic interface for the LaunchDarkly client. The browser SDK and the Electron SDK both
454
- * use this, but may add some methods of their own.
483
+ * The basic interface for the LaunchDarkly client. Platform-specific SDKs may add some methods of their own.
455
484
  *
456
485
  * @see https://docs.launchdarkly.com/sdk/client-side/javascript
457
486
  *
@@ -735,4 +764,96 @@ declare module 'launchdarkly-js-sdk-common' {
735
764
  */
736
765
  close(onDone?: () => void): Promise<void>;
737
766
  }
767
+
768
+ /**
769
+ * Provides a simple [[LDLogger]] implementation.
770
+ *
771
+ * This logging implementation uses a simple format that includes only the log level
772
+ * and the message text. Output is written to the console unless otherwise specified.
773
+ * You can filter by log level as described in [[BasicLoggerOptions.level]].
774
+ *
775
+ * To use the logger created by this function, put it into [[LDOptions.logger]]. If
776
+ * you do not set [[LDOptions.logger]] to anything, the SDK uses a default logger
777
+ * that is equivalent to `ld.basicLogger({ level: 'info' })`.
778
+ *
779
+ * @param options Configuration for the logger. If no options are specified, the
780
+ * logger uses `{ level: 'info' }`.
781
+ *
782
+ * @param formatter An optional function equivalent to Node's util.format, allowing
783
+ * for parameter substitution in log messages. If this is omitted, parameter
784
+ * substitution is not available.
785
+ *
786
+ * @example
787
+ * This example shows how to use `basicLogger` in your SDK options to enable console
788
+ * logging only at `warn` and `error` levels.
789
+ * ```javascript
790
+ * const ldOptions = {
791
+ * logger: ld.basicLogger({ level: 'warn' }),
792
+ * };
793
+ * ```
794
+ *
795
+ * @example
796
+ * This example shows how to use `basicLogger` in your SDK options to cause log
797
+ * output to always go to `console.error` instead of `console.log`.
798
+ * ```javascript
799
+ * const ldOptions = {
800
+ * logger: ld.basicLogger({ destination: console.error }),
801
+ * };
802
+ * ```
803
+ *
804
+ * @ignore (don't need to show this separately in TypeDoc output; each SDK should provide its own
805
+ * basicLogger function that delegates to this and sets the formatter parameter)
806
+ */
807
+ export function commonBasicLogger(
808
+ options?: BasicLoggerOptions,
809
+ formatter?: (format: string, ...args: any[]) => void
810
+ ): LDLogger;
811
+
812
+ /**
813
+ * Configuration for [[basicLogger]].
814
+ */
815
+ export interface BasicLoggerOptions {
816
+ /**
817
+ * The lowest level of log message to enable.
818
+ *
819
+ * See [[LDLogLevel]] for a list of possible levels. Setting a level here causes
820
+ * all lower-importance levels to be disabled: for instance, if you specify
821
+ * `'warn'`, then `'debug'` and `'info'` are disabled.
822
+ *
823
+ * If not specified, the default is `'info'` (meaning that `'debug'` is disabled).
824
+ */
825
+ level?: LDLogLevel;
826
+
827
+ /**
828
+ * A string to prepend to all log output. If not specified, the default is
829
+ * "[LaunchDarkly] ".
830
+ */
831
+ prefix?: string;
832
+
833
+ /**
834
+ * An optional function to use to print each log line.
835
+ *
836
+ * If this is specified, `basicLogger` calls it to write each line of output. The
837
+ * argument is a fully formatted log line, not including a linefeed. The function
838
+ * is only called for log levels that are enabled.
839
+ *
840
+ * If not specified, the default in browsers is to use `console.log`, `console.info`,
841
+ * `console.warn`, or `console.error` according to the level; the default in
842
+ * Node.js and Electron is to always use `console.log`.
843
+ *
844
+ * Setting this property to anything other than a function will cause SDK
845
+ * initialization to fail.
846
+ */
847
+ destination?: (line: string) => void,
848
+ }
849
+
850
+ /**
851
+ * Logging levels that can be used with [[basicLogger]].
852
+ *
853
+ * Set [[BasicLoggerOptions.level]] to one of these values to control what levels
854
+ * of log messages are enabled. Going from lowest importance (and most verbose)
855
+ * to most importance, the levels are `'debug'`, `'info'`, `'warn'`, and `'error'`.
856
+ * You can also specify `'none'` instead to disable all logging.
857
+ */
858
+ export type LDLogLevel = 'debug' | 'info' | 'warn' | 'error' | 'none';
738
859
  }