@statsig/react-native-core 2.1.1 → 2.2.0-beta.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/package.json +5 -4
- package/src/AppVisiblityShim.d.ts +1 -0
- package/src/AppVisiblityShim.js +14 -0
- package/src/PreloadedAsyncStorage.d.ts +2 -0
- package/src/PreloadedAsyncStorage.js +55 -0
- package/src/StatsigClientReactNativeBase.d.ts +28 -0
- package/src/StatsigClientReactNativeBase.js +24 -0
- package/src/index.d.ts +1 -2
- package/src/index.js +4 -30
- package/src/StatsigProviderRNSyncStorage.d.ts +0 -2
- package/src/StatsigProviderRNSyncStorage.js +0 -9
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statsig/react-native-core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0-beta.1",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@statsig/client-core": "2.
|
|
6
|
-
"@statsig/
|
|
5
|
+
"@statsig/client-core": "2.2.0-beta.1",
|
|
6
|
+
"@statsig/js-client": "2.2.0-beta.1",
|
|
7
|
+
"@statsig/react-bindings": "2.2.0-beta.1"
|
|
7
8
|
},
|
|
8
9
|
"peerDependencies": {
|
|
9
10
|
"react-native": "0.*",
|
|
10
|
-
"react-native-
|
|
11
|
+
"@react-native-async-storage/async-storage": "1.* || 2.*"
|
|
11
12
|
},
|
|
12
13
|
"type": "commonjs",
|
|
13
14
|
"main": "./src/index.js",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function _applyAppStateVisibilityShim(): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._applyAppStateVisibilityShim = void 0;
|
|
4
|
+
const react_native_1 = require("react-native");
|
|
5
|
+
const client_core_1 = require("@statsig/client-core");
|
|
6
|
+
let isApplied = false;
|
|
7
|
+
function _applyAppStateVisibilityShim() {
|
|
8
|
+
if (isApplied) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
isApplied = true;
|
|
12
|
+
react_native_1.AppState.addEventListener('change', (nextAppState) => (0, client_core_1._notifyVisibilityChanged)(nextAppState === 'active' ? 'foreground' : 'background'));
|
|
13
|
+
}
|
|
14
|
+
exports._applyAppStateVisibilityShim = _applyAppStateVisibilityShim;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports._createPreloadedAsyncStorage = void 0;
|
|
13
|
+
const async_storage_1 = require("@react-native-async-storage/async-storage");
|
|
14
|
+
const client_core_1 = require("@statsig/client-core");
|
|
15
|
+
function _createPreloadedAsyncStorage() {
|
|
16
|
+
const inMemoryStore = {};
|
|
17
|
+
const provider = {
|
|
18
|
+
_isProviderReady: _prefetchFromAsyncStorage(inMemoryStore),
|
|
19
|
+
_getProviderName: function () {
|
|
20
|
+
return 'AsyncStorage';
|
|
21
|
+
},
|
|
22
|
+
_getItem: function (key) {
|
|
23
|
+
var _a;
|
|
24
|
+
return (_a = inMemoryStore[key]) !== null && _a !== void 0 ? _a : null;
|
|
25
|
+
},
|
|
26
|
+
_setItem: function (key, value) {
|
|
27
|
+
inMemoryStore[key] = value;
|
|
28
|
+
async_storage_1.default.setItem(key, value).catch(client_core_1.Log.error);
|
|
29
|
+
},
|
|
30
|
+
_removeItem: function (key) {
|
|
31
|
+
delete inMemoryStore[key];
|
|
32
|
+
async_storage_1.default.removeItem(key).catch(client_core_1.Log.error);
|
|
33
|
+
},
|
|
34
|
+
_getAllKeys: function () {
|
|
35
|
+
return Object.keys(inMemoryStore);
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
return provider;
|
|
39
|
+
}
|
|
40
|
+
exports._createPreloadedAsyncStorage = _createPreloadedAsyncStorage;
|
|
41
|
+
function _prefetchFromAsyncStorage(inMemoryStore) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
const keys = yield async_storage_1.default.getAllKeys();
|
|
44
|
+
yield Promise.all(keys.map((key) => __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
if (!key.startsWith('statsig.')) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const cache = yield async_storage_1.default.getItem(key);
|
|
49
|
+
if (!cache) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
inMemoryStore[key] = cache;
|
|
53
|
+
})));
|
|
54
|
+
});
|
|
55
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { StatsigClient, StatsigOptions, StatsigUser } from '@statsig/js-client';
|
|
2
|
+
export declare class StatsigClientReactNativeBase extends StatsigClient {
|
|
3
|
+
constructor(sdkKey: string, user: StatsigUser, options: {
|
|
4
|
+
disableLogging?: boolean | undefined;
|
|
5
|
+
disableStorage?: boolean | undefined;
|
|
6
|
+
disableCompression?: boolean | undefined;
|
|
7
|
+
disableStatsigEncoding?: boolean | undefined;
|
|
8
|
+
environment?: import("@statsig/client-core").StatsigEnvironment | undefined;
|
|
9
|
+
includeCurrentPageUrlWithEvents?: boolean | undefined;
|
|
10
|
+
logLevel?: import("@statsig/client-core").LogLevel | undefined;
|
|
11
|
+
loggingBufferMaxSize?: number | undefined;
|
|
12
|
+
loggingIntervalMs?: number | undefined;
|
|
13
|
+
networkConfig?: {
|
|
14
|
+
api?: string | undefined;
|
|
15
|
+
logEventUrl?: string | undefined;
|
|
16
|
+
networkOverrideFunc?: ((url: string, args: import("@statsig/client-core").NetworkArgs) => Promise<Response>) | undefined;
|
|
17
|
+
networkTimeoutMs?: number | undefined;
|
|
18
|
+
preventAllNetworkTraffic?: boolean | undefined;
|
|
19
|
+
initializeUrl?: string | undefined;
|
|
20
|
+
} | undefined;
|
|
21
|
+
overrideAdapter?: import("@statsig/client-core").OverrideAdapter | undefined;
|
|
22
|
+
initialSessionID?: string | undefined;
|
|
23
|
+
storageProvider?: import("@statsig/client-core").StorageProvider | undefined;
|
|
24
|
+
dataAdapter?: import("@statsig/client-core").EvaluationsDataAdapter | undefined;
|
|
25
|
+
customUserCacheKeyFunc?: import("@statsig/client-core").CustomCacheKeyGenerator | undefined;
|
|
26
|
+
} | null | undefined, type: 'rn' | 'expo', statsigMetadataAdditions: Record<string, string | undefined>);
|
|
27
|
+
}
|
|
28
|
+
export declare function _setupStatsigForReactNative(type: 'rn' | 'expo', statsigMetadataAdditions: Record<string, string | undefined>, options: StatsigOptions): void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._setupStatsigForReactNative = exports.StatsigClientReactNativeBase = void 0;
|
|
4
|
+
const client_core_1 = require("@statsig/client-core");
|
|
5
|
+
const js_client_1 = require("@statsig/js-client");
|
|
6
|
+
const AppVisiblityShim_1 = require("./AppVisiblityShim");
|
|
7
|
+
const PreloadedAsyncStorage_1 = require("./PreloadedAsyncStorage");
|
|
8
|
+
class StatsigClientReactNativeBase extends js_client_1.StatsigClient {
|
|
9
|
+
constructor(sdkKey, user, options = null, type, statsigMetadataAdditions) {
|
|
10
|
+
const opts = options !== null && options !== void 0 ? options : {};
|
|
11
|
+
_setupStatsigForReactNative(type, statsigMetadataAdditions, opts);
|
|
12
|
+
super(sdkKey, user, opts);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.StatsigClientReactNativeBase = StatsigClientReactNativeBase;
|
|
16
|
+
function _setupStatsigForReactNative(type, statsigMetadataAdditions, options) {
|
|
17
|
+
(0, AppVisiblityShim_1._applyAppStateVisibilityShim)();
|
|
18
|
+
client_core_1.SDKType._setBindingType(type);
|
|
19
|
+
client_core_1.StatsigMetadataProvider.add(statsigMetadataAdditions);
|
|
20
|
+
if (options.storageProvider == null) {
|
|
21
|
+
options.storageProvider = (0, PreloadedAsyncStorage_1._createPreloadedAsyncStorage)();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports._setupStatsigForReactNative = _setupStatsigForReactNative;
|
package/src/index.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export * from './StatsigProviderRNSyncStorage';
|
|
1
|
+
export { StatsigClientReactNativeBase, _setupStatsigForReactNative, } from './StatsigClientReactNativeBase';
|
package/src/index.js
CHANGED
|
@@ -1,32 +1,6 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const storage = new react_native_mmkv_1.MMKV();
|
|
22
|
-
client_core_1.Storage._setProvider({
|
|
23
|
-
_getProviderName: () => 'MMKV Storage',
|
|
24
|
-
_getItem: (key) => storage.getString(key) || null,
|
|
25
|
-
_setItem: (key, value) => storage.set(key, value),
|
|
26
|
-
_removeItem: (key) => storage.delete(key),
|
|
27
|
-
_getAllKeys: () => storage.getAllKeys(),
|
|
28
|
-
});
|
|
29
|
-
react_native_1.AppState.addEventListener('change', (nextAppState) => (0, client_core_1._notifyVisibilityChanged)(nextAppState === 'active' ? 'foreground' : 'background'));
|
|
30
|
-
var StatsigProviderRNSyncStorage_1 = require("./StatsigProviderRNSyncStorage");
|
|
31
|
-
Object.defineProperty(exports, "StatsigProviderRNSyncStorage", { enumerable: true, get: function () { return StatsigProviderRNSyncStorage_1.StatsigProviderRNSyncStorage; } });
|
|
32
|
-
__exportStar(require("./StatsigProviderRNSyncStorage"), exports);
|
|
3
|
+
exports._setupStatsigForReactNative = exports.StatsigClientReactNativeBase = void 0;
|
|
4
|
+
var StatsigClientReactNativeBase_1 = require("./StatsigClientReactNativeBase");
|
|
5
|
+
Object.defineProperty(exports, "StatsigClientReactNativeBase", { enumerable: true, get: function () { return StatsigClientReactNativeBase_1.StatsigClientReactNativeBase; } });
|
|
6
|
+
Object.defineProperty(exports, "_setupStatsigForReactNative", { enumerable: true, get: function () { return StatsigClientReactNativeBase_1._setupStatsigForReactNative; } });
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StatsigProviderRNSyncStorage = void 0;
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const react_bindings_1 = require("@statsig/react-bindings");
|
|
6
|
-
function StatsigProviderRNSyncStorage(props) {
|
|
7
|
-
return (0, jsx_runtime_1.jsx)(react_bindings_1.StatsigProvider, Object.assign({}, props));
|
|
8
|
-
}
|
|
9
|
-
exports.StatsigProviderRNSyncStorage = StatsigProviderRNSyncStorage;
|