@configdirector/react-native-sdk 1.4.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,36 @@
1
1
  # ConfigDirector React Native SDK
2
2
 
3
- This is the React Native SDK for [ConfigDirector](https://www.configdirector.com).
3
+ [![npm][npm-badge]][npm]
4
+
5
+ React Native SDK for [ConfigDirector](https://www.configdirector.com), remote config and feature flags with typed values, JSON Schema validation, and safe renames of live flags. Start free, no card required.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install --save @configdirector/react-native-sdk
11
+ ```
12
+
13
+ ## Retrieve a value
14
+
15
+ ```tsx
16
+ import { Text } from "react-native";
17
+ import { ConfigDirectorProvider, useConfigValue } from "@configdirector/react-native-sdk";
18
+
19
+ export default function App() {
20
+ return (
21
+ <ConfigDirectorProvider sdkKey="YOUR-CLIENT-SDK-KEY" appName="MyApp" appVersion="1.0.0">
22
+ <Home />
23
+ </ConfigDirectorProvider>
24
+ );
25
+ }
26
+
27
+ function Home() {
28
+ const { value: darkMode } = useConfigValue("dark-mode", false);
29
+ return <Text>dark-mode: {String(darkMode)}</Text>;
30
+ }
31
+ ```
32
+
33
+ Full details are in the [official documentation](https://docs.configdirector.com/sdks/mobile/react-native).
4
34
 
5
35
  ## Documentation
6
36
 
@@ -10,4 +40,9 @@ There is also [a quickstart guide for ConfigDirector and any of our SDKs](https:
10
40
 
11
41
  ## Getting Help
12
42
 
13
- Reach out to us via https://www.configdirector.com/support
43
+ - [Ask a question in Discussions](https://github.com/orgs/ConfigDirector/discussions)
44
+ - [Contact support](https://www.configdirector.com/support)
45
+
46
+ [//]: # "links"
47
+ [npm-badge]: https://img.shields.io/npm/v/@configdirector/react-native-sdk.svg
48
+ [npm]: https://www.npmjs.com/package/@configdirector/react-native-sdk
@@ -553,6 +553,11 @@ const getRequestedType = (defaultValue) => {
553
553
  const isNumericNativeType = (requestedType) => {
554
554
  return requestedType === "number" || requestedType === "bigint";
555
555
  };
556
+ const configTypesNotReadableAsString = new Set([
557
+ "boolean",
558
+ "integer",
559
+ "float"
560
+ ]);
556
561
  const parseConfigValue = (configState, defaultValue) => {
557
562
  const value = configState.value;
558
563
  const requestedType = getRequestedType(defaultValue);
@@ -564,13 +569,22 @@ const parseConfigValue = (configState, defaultValue) => {
564
569
  reason: "value-missing"
565
570
  };
566
571
  if (configState.type === "json") return parseJson(value, defaultValue, requestedType, configState.valueId);
567
- if (typeof defaultValue === "string") return {
568
- parsedValue: value,
569
- parsedValueId: configState.valueId,
570
- requestedType,
571
- usedDefault: false,
572
- reason: "found-match"
573
- };
572
+ if (typeof defaultValue === "string") {
573
+ if (configTypesNotReadableAsString.has(configState.type)) return {
574
+ parsedValue: defaultValue,
575
+ parsedValueId: void 0,
576
+ requestedType,
577
+ usedDefault: true,
578
+ reason: "type-mismatch"
579
+ };
580
+ return {
581
+ parsedValue: value,
582
+ parsedValueId: configState.valueId,
583
+ requestedType,
584
+ usedDefault: false,
585
+ reason: "found-match"
586
+ };
587
+ }
574
588
  if (typeof defaultValue === "boolean" && (configState.type === "boolean" || configState.type === "string" || configState.type === "enum")) {
575
589
  const boolValue = parseConfigBoolean(value);
576
590
  const hasBoolean = typeof boolValue === "boolean";
@@ -1346,12 +1360,14 @@ var ClientEventReporter = class {
1346
1360
  constructor(options) {
1347
1361
  _defineProperty(this, "sdkKey", void 0);
1348
1362
  _defineProperty(this, "sdkIdentity", void 0);
1363
+ _defineProperty(this, "metaContext", void 0);
1349
1364
  _defineProperty(this, "logger", void 0);
1350
1365
  _defineProperty(this, "url", void 0);
1351
1366
  _defineProperty(this, "executeRequests", true);
1352
1367
  this.sdkKey = options.sdkKey;
1353
1368
  this.logger = options.logger;
1354
1369
  this.sdkIdentity = options.sdkIdentity;
1370
+ this.metaContext = options.metaContext;
1355
1371
  this.url = options.urlFactory("client/telemetry/v1", options.baseUrl);
1356
1372
  }
1357
1373
  async report({ context, discreteEvents, aggregatedEvents, droppedEvents }) {
@@ -1363,7 +1379,9 @@ var ClientEventReporter = class {
1363
1379
  clientSdkKey: this.sdkKey,
1364
1380
  metaContext: {
1365
1381
  sdkName: this.sdkIdentity.sdkName,
1366
- sdkVersion: this.sdkIdentity.sdkVersion
1382
+ sdkVersion: this.sdkIdentity.sdkVersion,
1383
+ appName: this.metaContext.appName,
1384
+ appVersion: this.metaContext.appVersion
1367
1385
  },
1368
1386
  context,
1369
1387
  discreteEvents,
@@ -1798,16 +1816,18 @@ const urlFactory = (input, base) => new MinimalUrl(input, base);
1798
1816
  //#endregion
1799
1817
  //#region src/client.ts
1800
1818
  const createClient = (clientSdkKey, clientOptions) => {
1801
- var _clientOptions$logger, _clientOptions$connec;
1819
+ var _clientOptions$logger, _clientOptions$connec, _clientOptions$metada;
1802
1820
  const sdkIdentity = {
1803
1821
  sdkName: "react-native-sdk",
1804
- sdkVersion: "1.4.0"
1822
+ sdkVersion: "1.5.1"
1805
1823
  };
1806
1824
  const logger = (_clientOptions$logger = clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.logger) !== null && _clientOptions$logger !== void 0 ? _clientOptions$logger : createConsoleLogger("warn");
1825
+ const baseUrl = (clientOptions === null || clientOptions === void 0 || (_clientOptions$connec = clientOptions.connection) === null || _clientOptions$connec === void 0 ? void 0 : _clientOptions$connec.url) ? urlFactory(clientOptions.connection.url) : CLIENT_BASE_URL;
1807
1826
  return new DefaultConfigDirectorClient(new ReactNativeTelemetryClient({
1808
1827
  sdkKey: clientSdkKey,
1809
1828
  sdkIdentity,
1810
- baseUrl: (clientOptions === null || clientOptions === void 0 || (_clientOptions$connec = clientOptions.connection) === null || _clientOptions$connec === void 0 ? void 0 : _clientOptions$connec.url) ? urlFactory(clientOptions.connection.url) : CLIENT_BASE_URL,
1829
+ metaContext: (_clientOptions$metada = clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.metadata) !== null && _clientOptions$metada !== void 0 ? _clientOptions$metada : {},
1830
+ baseUrl,
1811
1831
  logger,
1812
1832
  urlFactory
1813
1833
  }), clientSdkKey, sdkIdentity, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@configdirector/react-native-sdk",
3
- "version": "1.4.0",
3
+ "version": "1.5.1",
4
4
  "description": "React Native client SDK for ConfigDirector. ConfigDirector is a remote configuration and feature flag service.",
5
5
  "license": "MIT",
6
6
  "author": "ConfigDirector",