@launchdarkly/react-native-client-sdk 0.1.0-alpha

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 (85) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/LICENSE +13 -0
  3. package/README.md +120 -0
  4. package/dist/package.json +77 -0
  5. package/dist/src/ReactNativeLDClient.d.ts +6 -0
  6. package/dist/src/ReactNativeLDClient.d.ts.map +1 -0
  7. package/dist/src/ReactNativeLDClient.js +21 -0
  8. package/dist/src/ReactNativeLDClient.js.map +1 -0
  9. package/dist/src/hooks/index.d.ts +4 -0
  10. package/dist/src/hooks/index.d.ts.map +1 -0
  11. package/dist/src/hooks/index.js +4 -0
  12. package/dist/src/hooks/index.js.map +1 -0
  13. package/dist/src/hooks/useLDClient.d.ts +3 -0
  14. package/dist/src/hooks/useLDClient.d.ts.map +1 -0
  15. package/dist/src/hooks/useLDClient.js +8 -0
  16. package/dist/src/hooks/useLDClient.js.map +1 -0
  17. package/dist/src/hooks/variation/index.d.ts +3 -0
  18. package/dist/src/hooks/variation/index.d.ts.map +1 -0
  19. package/dist/src/hooks/variation/index.js +3 -0
  20. package/dist/src/hooks/variation/index.js.map +1 -0
  21. package/dist/src/hooks/variation/useTypedVariation.d.ts +32 -0
  22. package/dist/src/hooks/variation/useTypedVariation.d.ts.map +1 -0
  23. package/dist/src/hooks/variation/useTypedVariation.js +62 -0
  24. package/dist/src/hooks/variation/useTypedVariation.js.map +1 -0
  25. package/dist/src/hooks/variation/useVariation.d.ts +131 -0
  26. package/dist/src/hooks/variation/useVariation.d.ts.map +1 -0
  27. package/dist/src/hooks/variation/useVariation.js +132 -0
  28. package/dist/src/hooks/variation/useVariation.js.map +1 -0
  29. package/dist/src/index.d.ts +6 -0
  30. package/dist/src/index.d.ts.map +1 -0
  31. package/dist/src/index.js +15 -0
  32. package/dist/src/index.js.map +1 -0
  33. package/dist/src/platform/ConditionalAsyncStorage.d.ts +20 -0
  34. package/dist/src/platform/ConditionalAsyncStorage.d.ts.map +1 -0
  35. package/dist/src/platform/ConditionalAsyncStorage.js +29 -0
  36. package/dist/src/platform/ConditionalAsyncStorage.js.map +1 -0
  37. package/dist/src/platform/index.d.ts +4 -0
  38. package/dist/src/platform/index.d.ts.map +1 -0
  39. package/dist/src/platform/index.js +81 -0
  40. package/dist/src/platform/index.js.map +1 -0
  41. package/dist/src/polyfills/CustomEvent.d.ts +17 -0
  42. package/dist/src/polyfills/CustomEvent.d.ts.map +1 -0
  43. package/dist/src/polyfills/CustomEvent.js +13 -0
  44. package/dist/src/polyfills/CustomEvent.js.map +1 -0
  45. package/dist/src/polyfills/btoa.d.ts +2 -0
  46. package/dist/src/polyfills/btoa.d.ts.map +1 -0
  47. package/dist/src/polyfills/btoa.js +12 -0
  48. package/dist/src/polyfills/btoa.js.map +1 -0
  49. package/dist/src/polyfills/index.d.ts +5 -0
  50. package/dist/src/polyfills/index.d.ts.map +1 -0
  51. package/dist/src/polyfills/index.js +12 -0
  52. package/dist/src/polyfills/index.js.map +1 -0
  53. package/dist/src/polyfills/uuid.d.ts +10 -0
  54. package/dist/src/polyfills/uuid.d.ts.map +1 -0
  55. package/dist/src/polyfills/uuid.js +17 -0
  56. package/dist/src/polyfills/uuid.js.map +1 -0
  57. package/dist/src/provider/LDProvider.d.ts +22 -0
  58. package/dist/src/provider/LDProvider.d.ts.map +1 -0
  59. package/dist/src/provider/LDProvider.js +29 -0
  60. package/dist/src/provider/LDProvider.js.map +1 -0
  61. package/dist/src/provider/index.d.ts +3 -0
  62. package/dist/src/provider/index.d.ts.map +1 -0
  63. package/dist/src/provider/index.js +4 -0
  64. package/dist/src/provider/index.js.map +1 -0
  65. package/dist/src/provider/reactContext.d.ts +8 -0
  66. package/dist/src/provider/reactContext.d.ts.map +1 -0
  67. package/dist/src/provider/reactContext.js +7 -0
  68. package/dist/src/provider/reactContext.js.map +1 -0
  69. package/dist/src/provider/setupListeners.d.ts +6 -0
  70. package/dist/src/provider/setupListeners.d.ts.map +1 -0
  71. package/dist/src/provider/setupListeners.js +7 -0
  72. package/dist/src/provider/setupListeners.js.map +1 -0
  73. package/dist/src/react-native-sse/EventSource.d.ts +47 -0
  74. package/dist/src/react-native-sse/EventSource.d.ts.map +1 -0
  75. package/dist/src/react-native-sse/EventSource.js +264 -0
  76. package/dist/src/react-native-sse/EventSource.js.map +1 -0
  77. package/dist/src/react-native-sse/index.d.ts +3 -0
  78. package/dist/src/react-native-sse/index.d.ts.map +1 -0
  79. package/dist/src/react-native-sse/index.js +3 -0
  80. package/dist/src/react-native-sse/index.js.map +1 -0
  81. package/dist/src/react-native-sse/types.d.ts +59 -0
  82. package/dist/src/react-native-sse/types.d.ts.map +1 -0
  83. package/dist/src/react-native-sse/types.js +2 -0
  84. package/dist/src/react-native-sse/types.js.map +1 -0
  85. package/package.json +77 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # Changelog
2
+
3
+ All notable changes to the LaunchDarkly SDK for React Native will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org).
package/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2023 Catamorphic, Co.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,120 @@
1
+ # LaunchDarkly React Native SDK
2
+
3
+ > [!WARNING]
4
+ > UNSUPPORTED This SDK is in pre-release development and is not supported.
5
+
6
+ [![NPM][sdk-react-native-npm-badge]][sdk-react-native-npm-link]
7
+ [![Actions Status][sdk-react-native-ci-badge]][sdk-react-native-ci]
8
+ [![Documentation][sdk-react-native-ghp-badge]][sdk-react-native-ghp-link]
9
+ [![NPM][sdk-react-native-dm-badge]][sdk-react-native-npm-link]
10
+ [![NPM][sdk-react-native-dt-badge]][sdk-react-native-npm-link]
11
+
12
+ The LaunchDarkly React Native SDK is designed primarily for use in mobile environments. It follows the client-side LaunchDarkly model for multi-user contexts.
13
+
14
+ This SDK is a replacement of [launchdarkly-react-native-client-sdk](https://github.com/launchdarkly/react-native-client-sdk). Please consider updating your application to use this package instead.
15
+
16
+ For more information, see the [complete reference guide for this SDK](https://docs.launchdarkly.com/sdk/client-side/react-native).
17
+
18
+ ## Install
19
+
20
+ ```shell
21
+ yarn add @launchdarkly/react-native-client-sdk
22
+ ```
23
+
24
+ Additionally, the LaunchDarkly React-Native SDK uses
25
+ [@react-native-async-storage/async-storage](https://github.com/react-native-async-storage/async-storage)
26
+ for bootstrapping. This is a native dependency.
27
+
28
+ If you are using expo, then installing this package from npm like above and re-running pod install should suffice.
29
+
30
+ If you are not using expo, you will need to explicitly add
31
+ @react-native-async-storage/async-storage as a dependency to your project
32
+ and re-run pod install for [auto-linking to work](https://github.com/react-native-community/cli/issues/1347).
33
+
34
+ ## Quickstart
35
+
36
+ 1. Wrap your application with `LDProvider` passing it an LDClient and
37
+ an LDContext:
38
+
39
+ ```jsx
40
+ // App.tsx
41
+ import { LDProvider, ReactNativeLDClient } from '@launchdarkly/react-native-client-sdk';
42
+
43
+ const featureClient = new ReactNativeLDClient('mobile-key');
44
+ const userContext = { kind: 'user', key: 'test-user-1' };
45
+
46
+ const App = () => (
47
+ <LDProvider client={featureClient} context={userContext}>
48
+ <Welcome />
49
+ </LDProvider>
50
+ );
51
+
52
+ export default App;
53
+ ```
54
+
55
+ 2. Then in a child component, evaluate flags with `useBoolVariation`:
56
+
57
+ ```jsx
58
+ import { useBoolVariation } from '@launchdarkly/react-native-client-sdk';
59
+
60
+ export default function Welcome() {
61
+ const flagValue = useBoolVariation('flag-key', false);
62
+
63
+ return (
64
+ <View style={styles.container}>
65
+ <Text>Welcome to LaunchDarkly</Text>
66
+ <Text>Flag value is {`${flagValue}`}</Text>
67
+ </View>
68
+ );
69
+ }
70
+ ```
71
+
72
+ See the full [example app](https://github.com/launchdarkly/js-core/tree/main/packages/sdk/react-native/example).
73
+
74
+ ## Developing this SDK
75
+
76
+ 1. Build all the code in the `js-core` repo:
77
+
78
+ ```shell
79
+ # at js-core repo root
80
+ yarn && yarn build
81
+ ```
82
+
83
+ 2. The example app uses [react-native-dotenv](https://github.com/goatandsheep/react-native-dotenv)
84
+ to manage environment variables. Under `packages/sdk/react-native/example`
85
+ create an `.env` file and add your mobile key:
86
+
87
+ ```shell
88
+ echo "MOBILE_KEY=mob-abc" >> packages/sdk/react-native/example/.env
89
+ ```
90
+
91
+ 3. Run the example app. This will link the local react-native sdk code to the
92
+ example app for development:
93
+
94
+ ```shell
95
+ # in react-native/example
96
+ yarn && yarn ios-go
97
+ ```
98
+
99
+ ## About LaunchDarkly
100
+
101
+ - LaunchDarkly is a continuous delivery platform that provides feature flags as a service and allows developers to iterate quickly and safely. We allow you to easily flag your features and manage them from the LaunchDarkly dashboard. With LaunchDarkly, you can:
102
+ - Roll out a new feature to a subset of your users (like a group of users who opt-in to a beta tester group), gathering feedback and bug reports from real-world use cases.
103
+ - Gradually roll out a feature to an increasing percentage of users, and track the effect that the feature has on key metrics (for instance, how likely is a user to complete a purchase if they have feature A versus feature B?).
104
+ - Turn off a feature that you realize is causing performance problems in production, without needing to re-deploy, or even restart the application with a changed configuration file.
105
+ - Grant access to certain features based on user attributes, like payment plan (eg: users on the ‘gold’ plan get access to more features than users in the ‘silver’ plan). Disable parts of your application to facilitate maintenance, without taking everything offline.
106
+ - LaunchDarkly provides feature flag SDKs for a wide variety of languages and technologies. Read [our documentation](https://docs.launchdarkly.com/sdk) for a complete list.
107
+ - Explore LaunchDarkly
108
+ - [launchdarkly.com](https://www.launchdarkly.com/ 'LaunchDarkly Main Website') for more information
109
+ - [docs.launchdarkly.com](https://docs.launchdarkly.com/ 'LaunchDarkly Documentation') for our documentation and SDK reference guides
110
+ - [apidocs.launchdarkly.com](https://apidocs.launchdarkly.com/ 'LaunchDarkly API Documentation') for our API documentation
111
+ - [blog.launchdarkly.com](https://blog.launchdarkly.com/ 'LaunchDarkly Blog Documentation') for the latest product updates
112
+
113
+ [sdk-react-native-ci-badge]: https://github.com/launchdarkly/js-core/actions/workflows/react-native.yml/badge.svg
114
+ [sdk-react-native-ci]: https://github.com/launchdarkly/js-core/actions/workflows/react-native.yml
115
+ [sdk-react-native-npm-badge]: https://img.shields.io/npm/v/@launchdarkly/react-native-client-sdk.svg?style=flat-square
116
+ [sdk-react-native-npm-link]: https://www.npmjs.com/package/@launchdarkly/react-native-client-sdk
117
+ [sdk-react-native-ghp-badge]: https://img.shields.io/static/v1?label=GitHub+Pages&message=API+reference&color=00add8
118
+ [sdk-react-native-ghp-link]: https://launchdarkly.github.io/js-core/packages/sdk/react-native/docs/
119
+ [sdk-react-native-dm-badge]: https://img.shields.io/npm/dm/@launchdarkly/react-native-client-sdk.svg?style=flat-square
120
+ [sdk-react-native-dt-badge]: https://img.shields.io/npm/dt/@launchdarkly/react-native-client-sdk.svg?style=flat-square
@@ -0,0 +1,77 @@
1
+ {
2
+ "name": "@launchdarkly/react-native-client-sdk",
3
+ "version": "0.1.0-alpha",
4
+ "description": "React Native LaunchDarkly SDK",
5
+ "homepage": "https://github.com/launchdarkly/js-core/tree/main/packages/sdk/react-native",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/launchdarkly/js-core.git"
9
+ },
10
+ "license": "Apache-2.0",
11
+ "packageManager": "yarn@3.4.1",
12
+ "keywords": [
13
+ "launchdarkly",
14
+ "react-native"
15
+ ],
16
+ "type": "commonjs",
17
+ "main": "./dist/src/index.js",
18
+ "types": "./dist/src/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/src/index.d.ts",
22
+ "default": "./dist/src/index.js"
23
+ }
24
+ },
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "scripts": {
29
+ "clean": "rimraf dist",
30
+ "build": "npx tsc && yarn link-dev",
31
+ "tsw": "yarn tsc --watch",
32
+ "start": "rimraf dist && yarn tsw",
33
+ "lint": "eslint . --ext .ts",
34
+ "prettier": "prettier --write '**/*.@(js|ts|tsx|json|css)' --ignore-path ../../../.prettierignore",
35
+ "test": "NODE_OPTIONS=\"--experimental-vm-modules --no-warnings\" jest --ci --runInBand",
36
+ "coverage": "yarn test --coverage",
37
+ "check": "yarn prettier && yarn lint && yarn build && yarn test",
38
+ "link-dev": "./link-dev.sh",
39
+ "android": "yarn && yarn ./example && yarn build && (cd example/ && yarn android-release)",
40
+ "ios": "yarn && yarn ./example && yarn build && (cd example/ && yarn ios-go)"
41
+ },
42
+ "peerDependencies": {
43
+ "react": "*",
44
+ "react-native": "*"
45
+ },
46
+ "dependencies": {
47
+ "@launchdarkly/js-client-sdk-common": "0.1.0-alpha",
48
+ "@react-native-async-storage/async-storage": "^1.21.0",
49
+ "base64-js": "^1.5.1",
50
+ "event-target-shim": "^6.0.2"
51
+ },
52
+ "devDependencies": {
53
+ "@trivago/prettier-plugin-sort-imports": "^4.1.1",
54
+ "@types/jest": "^29.5.0",
55
+ "@types/react": "^18.2.31",
56
+ "@typescript-eslint/eslint-plugin": "^6.1.0",
57
+ "@typescript-eslint/parser": "^6.1.0",
58
+ "eslint": "^8.45.0",
59
+ "eslint-config-airbnb-base": "^15.0.0",
60
+ "eslint-config-airbnb-typescript": "^17.1.0",
61
+ "eslint-config-prettier": "^8.8.0",
62
+ "eslint-plugin-import": "^2.27.5",
63
+ "eslint-plugin-prettier": "^5.0.0",
64
+ "jest": "^29.5.0",
65
+ "launchdarkly-js-test-helpers": "^2.2.0",
66
+ "prettier": "^3.0.0",
67
+ "react": "^18.2.0",
68
+ "react-native": "^0.73.1",
69
+ "rimraf": "^5.0.5",
70
+ "ts-jest": "^29.1.0",
71
+ "typedoc": "0.25.0",
72
+ "typescript": "5.1.6"
73
+ },
74
+ "installConfig": {
75
+ "hoistingLimits": "workspaces"
76
+ }
77
+ }
@@ -0,0 +1,6 @@
1
+ import { LDClientImpl, type LDContext, type LDOptions } from '@launchdarkly/js-client-sdk-common';
2
+ export default class ReactNativeLDClient extends LDClientImpl {
3
+ constructor(sdkKey: string, options?: LDOptions);
4
+ createStreamUriPath(context: LDContext): string;
5
+ }
6
+ //# sourceMappingURL=ReactNativeLDClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReactNativeLDClient.d.ts","sourceRoot":"","sources":["../../src/ReactNativeLDClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,YAAY,EACZ,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,oCAAoC,CAAC;AAI5C,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,YAAY;gBAC/C,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,SAAc;IAiB1C,mBAAmB,CAAC,OAAO,EAAE,SAAS;CAGhD"}
@@ -0,0 +1,21 @@
1
+ import { base64UrlEncode, BasicLogger, LDClientImpl, } from '@launchdarkly/js-client-sdk-common';
2
+ import createPlatform from './platform';
3
+ export default class ReactNativeLDClient extends LDClientImpl {
4
+ constructor(sdkKey, options = {}) {
5
+ var _a;
6
+ const logger = (_a = options.logger) !== null && _a !== void 0 ? _a : new BasicLogger({
7
+ level: 'debug',
8
+ // eslint-disable-next-line no-console
9
+ destination: console.log,
10
+ });
11
+ const internalOptions = {
12
+ analyticsEventPath: `/mobile`,
13
+ diagnosticEventPath: `/mobile/events/diagnostic`,
14
+ };
15
+ super(sdkKey, createPlatform(logger), Object.assign(Object.assign({}, options), { logger }), internalOptions);
16
+ }
17
+ createStreamUriPath(context) {
18
+ return `/meval/${base64UrlEncode(JSON.stringify(context), this.platform.encoding)}`;
19
+ }
20
+ }
21
+ //# sourceMappingURL=ReactNativeLDClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReactNativeLDClient.js","sourceRoot":"","sources":["../../src/ReactNativeLDClient.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,WAAW,EAEX,YAAY,GAGb,MAAM,oCAAoC,CAAC;AAE5C,OAAO,cAAc,MAAM,YAAY,CAAC;AAExC,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,YAAY;IAC3D,YAAY,MAAc,EAAE,UAAqB,EAAE;;QACjD,MAAM,MAAM,GACV,MAAA,OAAO,CAAC,MAAM,mCACd,IAAI,WAAW,CAAC;YACd,KAAK,EAAE,OAAO;YACd,sCAAsC;YACtC,WAAW,EAAE,OAAO,CAAC,GAAG;SACzB,CAAC,CAAC;QAEL,MAAM,eAAe,GAA+B;YAClD,kBAAkB,EAAE,SAAS;YAC7B,mBAAmB,EAAE,2BAA2B;SACjD,CAAC;QAEF,KAAK,CAAC,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,kCAAO,OAAO,KAAE,MAAM,KAAI,eAAe,CAAC,CAAC;IACjF,CAAC;IAEQ,mBAAmB,CAAC,OAAkB;QAC7C,OAAO,UAAU,eAAe,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAS,CAAC,EAAE,CAAC;IACvF,CAAC;CACF"}
@@ -0,0 +1,4 @@
1
+ import useLDClient from './useLDClient';
2
+ export * from './variation';
3
+ export { useLDClient };
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,eAAe,CAAC;AAExC,cAAc,aAAa,CAAC;AAE5B,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -0,0 +1,4 @@
1
+ import useLDClient from './useLDClient';
2
+ export * from './variation';
3
+ export { useLDClient };
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,eAAe,CAAC;AAExC,cAAc,aAAa,CAAC;AAE5B,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const useLDClient: () => import("@launchdarkly/js-client-sdk-common").LDClient;
2
+ export default useLDClient;
3
+ //# sourceMappingURL=useLDClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLDClient.d.ts","sourceRoot":"","sources":["../../../src/hooks/useLDClient.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,WAAW,6DAGhB,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { useContext } from 'react';
2
+ import { context } from '../provider/reactContext';
3
+ const useLDClient = () => {
4
+ const { client } = useContext(context);
5
+ return client;
6
+ };
7
+ export default useLDClient;
8
+ //# sourceMappingURL=useLDClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLDClient.js","sourceRoot":"","sources":["../../../src/hooks/useLDClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAEnC,OAAO,EAAE,OAAO,EAAgB,MAAM,0BAA0B,CAAC;AAEjE,MAAM,WAAW,GAAG,GAAG,EAAE;IACvB,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAe,OAAO,CAAC,CAAC;IACrD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './useVariation';
2
+ export * from './useTypedVariation';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hooks/variation/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './useVariation';
2
+ export * from './useTypedVariation';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/hooks/variation/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { LDEvaluationDetailTyped } from '@launchdarkly/js-client-sdk-common';
2
+ /**
3
+ * Determines the strongly typed variation of a feature flag.
4
+ *
5
+ * @param key The unique key of the feature flag.
6
+ * @param defaultValue The default value of the flag, to be used if the value is not available
7
+ * from LaunchDarkly.
8
+ * @returns
9
+ * The strongly typed value.
10
+ */
11
+ export declare const useTypedVariation: <T extends unknown>(key: string, defaultValue: T) => T;
12
+ /**
13
+ * Determines the strongly typed variation of a feature flag for a context, along with information about
14
+ * how it was calculated.
15
+ *
16
+ * The `reason` property of the result will also be included in analytics events, if you are
17
+ * capturing detailed event data for this flag.
18
+ *
19
+ * If the flag variation does not have the specified type, defaultValue is returned. The reason will
20
+ * indicate an error of the type `WRONG_KIND` in this case.
21
+ *
22
+ * For more information, see the [SDK reference
23
+ * guide](https://docs.launchdarkly.com/sdk/features/evaluation-reasons#react-native).
24
+ *
25
+ * @param key The unique key of the feature flag.
26
+ * @param defaultValue The default value of the flag, to be used if the value is not available
27
+ * from LaunchDarkly.
28
+ * @returns
29
+ * The result (as an {@link LDEvaluationDetailTyped<T>}).
30
+ */
31
+ export declare const useTypedVariationDetail: <T extends unknown>(key: string, defaultValue: T) => LDEvaluationDetailTyped<T>;
32
+ //# sourceMappingURL=useTypedVariation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTypedVariation.d.ts","sourceRoot":"","sources":["../../../../src/hooks/variation/useTypedVariation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAI7E;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,2BACvB,MAAM,uBAkBZ,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,uBAAuB,2BAC7B,MAAM,gDA2BZ,CAAC"}
@@ -0,0 +1,62 @@
1
+ import useLDClient from '../useLDClient';
2
+ /**
3
+ * Determines the strongly typed variation of a feature flag.
4
+ *
5
+ * @param key The unique key of the feature flag.
6
+ * @param defaultValue The default value of the flag, to be used if the value is not available
7
+ * from LaunchDarkly.
8
+ * @returns
9
+ * The strongly typed value.
10
+ */
11
+ export const useTypedVariation = (key, defaultValue) => {
12
+ const ldClient = useLDClient();
13
+ switch (typeof defaultValue) {
14
+ case 'boolean':
15
+ return ldClient.boolVariation(key, defaultValue);
16
+ case 'number':
17
+ return ldClient.numberVariation(key, defaultValue);
18
+ case 'string':
19
+ return ldClient.stringVariation(key, defaultValue);
20
+ case 'undefined':
21
+ case 'object':
22
+ return ldClient.jsonVariation(key, defaultValue);
23
+ default:
24
+ return ldClient.variation(key, defaultValue);
25
+ }
26
+ };
27
+ /**
28
+ * Determines the strongly typed variation of a feature flag for a context, along with information about
29
+ * how it was calculated.
30
+ *
31
+ * The `reason` property of the result will also be included in analytics events, if you are
32
+ * capturing detailed event data for this flag.
33
+ *
34
+ * If the flag variation does not have the specified type, defaultValue is returned. The reason will
35
+ * indicate an error of the type `WRONG_KIND` in this case.
36
+ *
37
+ * For more information, see the [SDK reference
38
+ * guide](https://docs.launchdarkly.com/sdk/features/evaluation-reasons#react-native).
39
+ *
40
+ * @param key The unique key of the feature flag.
41
+ * @param defaultValue The default value of the flag, to be used if the value is not available
42
+ * from LaunchDarkly.
43
+ * @returns
44
+ * The result (as an {@link LDEvaluationDetailTyped<T>}).
45
+ */
46
+ export const useTypedVariationDetail = (key, defaultValue) => {
47
+ const ldClient = useLDClient();
48
+ switch (typeof defaultValue) {
49
+ case 'boolean':
50
+ return ldClient.boolVariationDetail(key, defaultValue);
51
+ case 'number':
52
+ return ldClient.numberVariationDetail(key, defaultValue);
53
+ case 'string':
54
+ return ldClient.stringVariationDetail(key, defaultValue);
55
+ case 'undefined':
56
+ case 'object':
57
+ return ldClient.jsonVariationDetail(key, defaultValue);
58
+ default:
59
+ return ldClient.variationDetail(key, defaultValue);
60
+ }
61
+ };
62
+ //# sourceMappingURL=useTypedVariation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTypedVariation.js","sourceRoot":"","sources":["../../../../src/hooks/variation/useTypedVariation.ts"],"names":[],"mappings":"AAEA,OAAO,WAAW,MAAM,gBAAgB,CAAC;AAEzC;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,GAAW,EACX,YAAe,EACZ,EAAE;IACL,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAE/B,QAAQ,OAAO,YAAY,EAAE;QAC3B,KAAK,SAAS;YACZ,OAAO,QAAQ,CAAC,aAAa,CAAC,GAAG,EAAE,YAAuB,CAAM,CAAC;QACnE,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC,eAAe,CAAC,GAAG,EAAE,YAAsB,CAAM,CAAC;QACpE,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC,eAAe,CAAC,GAAG,EAAE,YAAsB,CAAM,CAAC;QACpE,KAAK,WAAW,CAAC;QACjB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC,aAAa,CAAC,GAAG,EAAE,YAAY,CAAM,CAAC;QACxD;YACE,OAAO,QAAQ,CAAC,SAAS,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;KAChD;AACH,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,GAAW,EACX,YAAe,EACa,EAAE;IAC9B,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAE/B,QAAQ,OAAO,YAAY,EAAE;QAC3B,KAAK,SAAS;YACZ,OAAO,QAAQ,CAAC,mBAAmB,CACjC,GAAG,EACH,YAAuB,CACM,CAAC;QAClC,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC,qBAAqB,CACnC,GAAG,EACH,YAAsB,CACO,CAAC;QAClC,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC,qBAAqB,CACnC,GAAG,EACH,YAAsB,CACO,CAAC;QAClC,KAAK,WAAW,CAAC;QACjB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC,mBAAmB,CAAC,GAAG,EAAE,YAAY,CAA+B,CAAC;QACvF;YACE,OAAO,QAAQ,CAAC,eAAe,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;KACtD;AACH,CAAC,CAAC"}
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Determines the boolean variation of a feature flag.
3
+ *
4
+ * If the flag variation does not have a boolean value, defaultValue is returned.
5
+ *
6
+ * @param key The unique key of the feature flag.
7
+ * @param defaultValue The default value of the flag, to be used if the value is not available
8
+ * from LaunchDarkly.
9
+ * @returns
10
+ * The boolean value.
11
+ */
12
+ export declare const useBoolVariation: (key: string, defaultValue: boolean) => boolean;
13
+ /**
14
+ * Determines the boolean variation of a feature flag for a context, along with information about
15
+ * how it was calculated.
16
+ *
17
+ * The `reason` property of the result will also be included in analytics events, if you are
18
+ * capturing detailed event data for this flag.
19
+ *
20
+ * If the flag variation does not have a boolean value, defaultValue is returned. The reason will
21
+ * indicate an error of the type `WRONG_KIND` in this case.
22
+ *
23
+ * For more information, see the [SDK reference
24
+ * guide](https://docs.launchdarkly.com/sdk/features/evaluation-reasons#react-native).
25
+ *
26
+ * @param key The unique key of the feature flag.
27
+ * @param defaultValue The default value of the flag, to be used if the value is not available
28
+ * from LaunchDarkly.
29
+ * @returns
30
+ * The result (as an {@link LDEvaluationDetailTyped<boolean>}).
31
+ */
32
+ export declare const useBoolVariationDetail: (key: string, defaultValue: boolean) => import("@launchdarkly/js-sdk-common").LDEvaluationDetailTyped<boolean>;
33
+ /**
34
+ * Determines the numeric variation of a feature flag.
35
+ *
36
+ * If the flag variation does not have a numeric value, defaultValue is returned.
37
+ *
38
+ * @param key The unique key of the feature flag.
39
+ * @param defaultValue The default value of the flag, to be used if the value is not available
40
+ * from LaunchDarkly.
41
+ * @returns
42
+ * The numeric value.
43
+ */
44
+ export declare const useNumberVariation: (key: string, defaultValue: number) => number;
45
+ /**
46
+ * Determines the numeric variation of a feature flag for a context, along with information about
47
+ * how it was calculated.
48
+ *
49
+ * The `reason` property of the result will also be included in analytics events, if you are
50
+ * capturing detailed event data for this flag.
51
+ *
52
+ * If the flag variation does not have a numeric value, defaultValue is returned. The reason will
53
+ * indicate an error of the type `WRONG_KIND` in this case.
54
+ *
55
+ * For more information, see the [SDK reference
56
+ * guide](https://docs.launchdarkly.com/sdk/features/evaluation-reasons#react-native).
57
+ *
58
+ * @param key The unique key of the feature flag.
59
+ * @param defaultValue The default value of the flag, to be used if the value is not available
60
+ * from LaunchDarkly.
61
+ * @returns
62
+ * The result (as an {@link LDEvaluationDetailTyped<number>}).
63
+ */
64
+ export declare const useNumberVariationDetail: (key: string, defaultValue: number) => import("@launchdarkly/js-sdk-common").LDEvaluationDetailTyped<number>;
65
+ /**
66
+ * Determines the string variation of a feature flag.
67
+ *
68
+ * If the flag variation does not have a string value, defaultValue is returned.
69
+ *
70
+ * @param key The unique key of the feature flag.
71
+ * @param defaultValue The default value of the flag, to be used if the value is not available
72
+ * from LaunchDarkly.
73
+ * @returns
74
+ * The string value.
75
+ */
76
+ export declare const useStringVariation: (key: string, defaultValue: string) => string;
77
+ /**
78
+ * Determines the string variation of a feature flag for a context, along with information about
79
+ * how it was calculated.
80
+ *
81
+ * The `reason` property of the result will also be included in analytics events, if you are
82
+ * capturing detailed event data for this flag.
83
+ *
84
+ * If the flag variation does not have a string value, defaultValue is returned. The reason will
85
+ * indicate an error of the type `WRONG_KIND` in this case.
86
+ *
87
+ * For more information, see the [SDK reference
88
+ * guide](https://docs.launchdarkly.com/sdk/features/evaluation-reasons#react-native).
89
+ *
90
+ * @param key The unique key of the feature flag.
91
+ * @param defaultValue The default value of the flag, to be used if the value is not available
92
+ * from LaunchDarkly.
93
+ * @returns
94
+ * The result (as an {@link LDEvaluationDetailTyped<string>}).
95
+ */
96
+ export declare const useStringVariationDetail: (key: string, defaultValue: string) => import("@launchdarkly/js-sdk-common").LDEvaluationDetailTyped<string>;
97
+ /**
98
+ * Determines the json variation of a feature flag.
99
+ *
100
+ * This version may be favored in TypeScript versus `variation` because it returns
101
+ * an `unknown` type instead of `any`. `unknown` will require a cast before usage.
102
+ *
103
+ * @param key The unique key of the feature flag.
104
+ * @param defaultValue The default value of the flag, to be used if the value is not available
105
+ * from LaunchDarkly.
106
+ * @returns
107
+ * The json value.
108
+ */
109
+ export declare const useJsonVariation: (key: string, defaultValue: unknown) => unknown;
110
+ /**
111
+ * Determines the json variation of a feature flag for a context, along with information about how it
112
+ * was calculated.
113
+ *
114
+ * The `reason` property of the result will also be included in analytics events, if you are
115
+ * capturing detailed event data for this flag.
116
+ *
117
+ * This version may be favored in TypeScript versus `variation` because it returns
118
+ * an `unknown` type instead of `any`. `unknown` will require a cast before usage.
119
+ *
120
+ * For more information, see the [SDK reference
121
+ * guide](https://docs.launchdarkly.com/sdk/features/evaluation-reasons#react-native).
122
+ *
123
+ * @param key The unique key of the feature flag.
124
+ * @param defaultValue The default value of the flag, to be used if the value is not available
125
+ * from LaunchDarkly.
126
+ * @returns
127
+ * If you provided a callback, then nothing. Otherwise, a Promise which will be resolved with
128
+ * the result (as an{@link LDEvaluationDetailTyped<unknown>}).
129
+ */
130
+ export declare const useJsonVariationDetail: (key: string, defaultValue: unknown) => import("@launchdarkly/js-sdk-common").LDEvaluationDetailTyped<unknown>;
131
+ //# sourceMappingURL=useVariation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useVariation.d.ts","sourceRoot":"","sources":["../../../../src/hooks/variation/useVariation.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,gBAAgB,QAAS,MAAM,gBAAgB,OAAO,YACpB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,sBAAsB,QAAS,MAAM,gBAAgB,OAAO,2EACpB,CAAC;AAEtD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,kBAAkB,QAAS,MAAM,gBAAgB,MAAM,WACtB,CAAC;AAE/C;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,wBAAwB,QAAS,MAAM,gBAAgB,MAAM,0EACtB,CAAC;AAErD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,kBAAkB,QAAS,MAAM,gBAAgB,MAAM,WACtB,CAAC;AAE/C;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,wBAAwB,QAAS,MAAM,gBAAgB,MAAM,0EACtB,CAAC;AAErD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gBAAgB,QAAS,MAAM,gBAAgB,OAAO,YACpB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,sBAAsB,QAAS,MAAM,gBAAgB,OAAO,2EACpB,CAAC"}