@getdevteam/analytics-react-native 0.1.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/dist/index.cjs +142 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +18 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +103 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
REACT_NATIVE_SDK_NAME: () => REACT_NATIVE_SDK_NAME,
|
|
34
|
+
REACT_NATIVE_SDK_VERSION: () => REACT_NATIVE_SDK_VERSION,
|
|
35
|
+
collectReactNativeContext: () => collectReactNativeContext,
|
|
36
|
+
createAnalytics: () => createAnalytics,
|
|
37
|
+
createAsyncStorageAdapter: () => createAsyncStorageAdapter,
|
|
38
|
+
installAppStateFlush: () => installAppStateFlush,
|
|
39
|
+
osNameFromPlatform: () => osNameFromPlatform
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(index_exports);
|
|
42
|
+
var import_analytics_core = require("@getdevteam/analytics-core");
|
|
43
|
+
|
|
44
|
+
// src/appState.ts
|
|
45
|
+
var import_react_native = require("react-native");
|
|
46
|
+
function installAppStateFlush(client) {
|
|
47
|
+
const onChange = (state) => {
|
|
48
|
+
if (state === "background" || state === "inactive") {
|
|
49
|
+
void client.flush();
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const subscription = import_react_native.AppState.addEventListener("change", onChange);
|
|
53
|
+
return () => subscription.remove();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/context.ts
|
|
57
|
+
var import_react_native2 = require("react-native");
|
|
58
|
+
function osNameFromPlatform(os) {
|
|
59
|
+
switch (os) {
|
|
60
|
+
case "ios":
|
|
61
|
+
return "iOS";
|
|
62
|
+
case "android":
|
|
63
|
+
return "Android";
|
|
64
|
+
case "macos":
|
|
65
|
+
return "macOS";
|
|
66
|
+
case "windows":
|
|
67
|
+
return "Windows";
|
|
68
|
+
default:
|
|
69
|
+
return os;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function collectReactNativeContext() {
|
|
73
|
+
const context = { platform: "react-native" };
|
|
74
|
+
try {
|
|
75
|
+
context.os_name = osNameFromPlatform(import_react_native2.Platform.OS);
|
|
76
|
+
context.os_version = String(import_react_native2.Platform.Version);
|
|
77
|
+
context.device_type = import_react_native2.Platform.isTV ? "tv" : import_react_native2.Platform.isPad ? "tablet" : "mobile";
|
|
78
|
+
} catch {
|
|
79
|
+
}
|
|
80
|
+
return context;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/storage.ts
|
|
84
|
+
var import_async_storage = __toESM(require("@react-native-async-storage/async-storage"), 1);
|
|
85
|
+
function createAsyncStorageAdapter() {
|
|
86
|
+
return {
|
|
87
|
+
getItem: async (key) => {
|
|
88
|
+
try {
|
|
89
|
+
return await import_async_storage.default.getItem(key);
|
|
90
|
+
} catch {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
setItem: async (key, value) => {
|
|
95
|
+
try {
|
|
96
|
+
await import_async_storage.default.setItem(key, value);
|
|
97
|
+
} catch {
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
removeItem: async (key) => {
|
|
101
|
+
try {
|
|
102
|
+
await import_async_storage.default.removeItem(key);
|
|
103
|
+
} catch {
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// src/index.ts
|
|
110
|
+
var REACT_NATIVE_SDK_NAME = "@getdevteam/analytics-react-native";
|
|
111
|
+
var REACT_NATIVE_SDK_VERSION = "0.1.0";
|
|
112
|
+
function createAnalytics(config) {
|
|
113
|
+
const client = (0, import_analytics_core.createClient)({
|
|
114
|
+
...config,
|
|
115
|
+
storage: config.storage ?? createAsyncStorageAdapter()
|
|
116
|
+
});
|
|
117
|
+
client.setContext({
|
|
118
|
+
sdk_name: REACT_NATIVE_SDK_NAME,
|
|
119
|
+
sdk_version: REACT_NATIVE_SDK_VERSION,
|
|
120
|
+
...collectReactNativeContext(),
|
|
121
|
+
...config.context
|
|
122
|
+
});
|
|
123
|
+
const removeAppStateFlush = installAppStateFlush(client);
|
|
124
|
+
return {
|
|
125
|
+
...client,
|
|
126
|
+
shutdown: async () => {
|
|
127
|
+
removeAppStateFlush();
|
|
128
|
+
await client.shutdown();
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
133
|
+
0 && (module.exports = {
|
|
134
|
+
REACT_NATIVE_SDK_NAME,
|
|
135
|
+
REACT_NATIVE_SDK_VERSION,
|
|
136
|
+
collectReactNativeContext,
|
|
137
|
+
createAnalytics,
|
|
138
|
+
createAsyncStorageAdapter,
|
|
139
|
+
installAppStateFlush,
|
|
140
|
+
osNameFromPlatform
|
|
141
|
+
});
|
|
142
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/appState.ts","../src/context.ts","../src/storage.ts"],"sourcesContent":["import {\n createClient,\n type AnalyticsClient,\n type ClientConfig,\n type EventContext,\n} from \"@getdevteam/analytics-core\";\nimport { installAppStateFlush } from \"./appState\";\nimport { collectReactNativeContext } from \"./context\";\nimport { createAsyncStorageAdapter } from \"./storage\";\n\nexport const REACT_NATIVE_SDK_NAME = \"@getdevteam/analytics-react-native\";\nexport const REACT_NATIVE_SDK_VERSION = \"0.1.0\";\n\nexport interface ReactNativeAnalyticsConfig extends ClientConfig {\n context?: Partial<EventContext>;\n}\n\nexport function createAnalytics(config: ReactNativeAnalyticsConfig): AnalyticsClient {\n const client = createClient({\n ...config,\n storage: config.storage ?? createAsyncStorageAdapter(),\n });\n\n client.setContext({\n sdk_name: REACT_NATIVE_SDK_NAME,\n sdk_version: REACT_NATIVE_SDK_VERSION,\n ...collectReactNativeContext(),\n ...config.context,\n });\n\n const removeAppStateFlush = installAppStateFlush(client);\n\n return {\n ...client,\n shutdown: async () => {\n removeAppStateFlush();\n await client.shutdown();\n },\n };\n}\n\nexport { installAppStateFlush } from \"./appState\";\nexport { collectReactNativeContext, osNameFromPlatform } from \"./context\";\nexport { createAsyncStorageAdapter } from \"./storage\";\nexport type {\n AnalyticsClient,\n AnalyticsLogger,\n ClientConfig,\n EventContext,\n FetchLike,\n LogSeverity,\n Properties,\n StorageAdapter,\n} from \"@getdevteam/analytics-core\";\n","import { AppState, type AppStateStatus } from \"react-native\";\nimport type { AnalyticsClient } from \"@getdevteam/analytics-core\";\n\nexport function installAppStateFlush(client: AnalyticsClient): () => void {\n const onChange = (state: AppStateStatus): void => {\n if (state === \"background\" || state === \"inactive\") {\n void client.flush();\n }\n };\n const subscription = AppState.addEventListener(\"change\", onChange);\n return () => subscription.remove();\n}\n","import { Platform } from \"react-native\";\nimport type { EventContext } from \"@getdevteam/analytics-core\";\n\nexport function osNameFromPlatform(os: string): string {\n switch (os) {\n case \"ios\":\n return \"iOS\";\n case \"android\":\n return \"Android\";\n case \"macos\":\n return \"macOS\";\n case \"windows\":\n return \"Windows\";\n default:\n return os;\n }\n}\n\nexport function collectReactNativeContext(): EventContext {\n const context: EventContext = { platform: \"react-native\" };\n try {\n context.os_name = osNameFromPlatform(Platform.OS);\n context.os_version = String(Platform.Version);\n context.device_type = Platform.isTV ? \"tv\" : Platform.isPad ? \"tablet\" : \"mobile\";\n } catch {\n // Platform constants can be unavailable outside a real RN runtime; the platform tag alone still stands\n }\n return context;\n}\n","import AsyncStorage from \"@react-native-async-storage/async-storage\";\nimport type { StorageAdapter } from \"@getdevteam/analytics-core\";\n\nexport function createAsyncStorageAdapter(): StorageAdapter {\n return {\n getItem: async (key) => {\n try {\n return await AsyncStorage.getItem(key);\n } catch {\n return null;\n }\n },\n setItem: async (key, value) => {\n try {\n await AsyncStorage.setItem(key, value);\n } catch {\n // storage unavailable; queue persistence degrades gracefully\n }\n },\n removeItem: async (key) => {\n try {\n await AsyncStorage.removeItem(key);\n } catch {\n // ignore\n }\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAKO;;;ACLP,0BAA8C;AAGvC,SAAS,qBAAqB,QAAqC;AACxE,QAAM,WAAW,CAAC,UAAgC;AAChD,QAAI,UAAU,gBAAgB,UAAU,YAAY;AAClD,WAAK,OAAO,MAAM;AAAA,IACpB;AAAA,EACF;AACA,QAAM,eAAe,6BAAS,iBAAiB,UAAU,QAAQ;AACjE,SAAO,MAAM,aAAa,OAAO;AACnC;;;ACXA,IAAAA,uBAAyB;AAGlB,SAAS,mBAAmB,IAAoB;AACrD,UAAQ,IAAI;AAAA,IACV,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;AAEO,SAAS,4BAA0C;AACxD,QAAM,UAAwB,EAAE,UAAU,eAAe;AACzD,MAAI;AACF,YAAQ,UAAU,mBAAmB,8BAAS,EAAE;AAChD,YAAQ,aAAa,OAAO,8BAAS,OAAO;AAC5C,YAAQ,cAAc,8BAAS,OAAO,OAAO,8BAAS,QAAQ,WAAW;AAAA,EAC3E,QAAQ;AAAA,EAER;AACA,SAAO;AACT;;;AC5BA,2BAAyB;AAGlB,SAAS,4BAA4C;AAC1D,SAAO;AAAA,IACL,SAAS,OAAO,QAAQ;AACtB,UAAI;AACF,eAAO,MAAM,qBAAAC,QAAa,QAAQ,GAAG;AAAA,MACvC,QAAQ;AACN,eAAO;AAAA,MACT;AAAA,IACF;AAAA,IACA,SAAS,OAAO,KAAK,UAAU;AAC7B,UAAI;AACF,cAAM,qBAAAA,QAAa,QAAQ,KAAK,KAAK;AAAA,MACvC,QAAQ;AAAA,MAER;AAAA,IACF;AAAA,IACA,YAAY,OAAO,QAAQ;AACzB,UAAI;AACF,cAAM,qBAAAA,QAAa,WAAW,GAAG;AAAA,MACnC,QAAQ;AAAA,MAER;AAAA,IACF;AAAA,EACF;AACF;;;AHjBO,IAAM,wBAAwB;AAC9B,IAAM,2BAA2B;AAMjC,SAAS,gBAAgB,QAAqD;AACnF,QAAM,aAAS,oCAAa;AAAA,IAC1B,GAAG;AAAA,IACH,SAAS,OAAO,WAAW,0BAA0B;AAAA,EACvD,CAAC;AAED,SAAO,WAAW;AAAA,IAChB,UAAU;AAAA,IACV,aAAa;AAAA,IACb,GAAG,0BAA0B;AAAA,IAC7B,GAAG,OAAO;AAAA,EACZ,CAAC;AAED,QAAM,sBAAsB,qBAAqB,MAAM;AAEvD,SAAO;AAAA,IACL,GAAG;AAAA,IACH,UAAU,YAAY;AACpB,0BAAoB;AACpB,YAAM,OAAO,SAAS;AAAA,IACxB;AAAA,EACF;AACF;","names":["import_react_native","AsyncStorage"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AnalyticsClient, EventContext, StorageAdapter, ClientConfig } from '@getdevteam/analytics-core';
|
|
2
|
+
export { AnalyticsClient, AnalyticsLogger, ClientConfig, EventContext, FetchLike, LogSeverity, Properties, StorageAdapter } from '@getdevteam/analytics-core';
|
|
3
|
+
|
|
4
|
+
declare function installAppStateFlush(client: AnalyticsClient): () => void;
|
|
5
|
+
|
|
6
|
+
declare function osNameFromPlatform(os: string): string;
|
|
7
|
+
declare function collectReactNativeContext(): EventContext;
|
|
8
|
+
|
|
9
|
+
declare function createAsyncStorageAdapter(): StorageAdapter;
|
|
10
|
+
|
|
11
|
+
declare const REACT_NATIVE_SDK_NAME = "@getdevteam/analytics-react-native";
|
|
12
|
+
declare const REACT_NATIVE_SDK_VERSION = "0.1.0";
|
|
13
|
+
interface ReactNativeAnalyticsConfig extends ClientConfig {
|
|
14
|
+
context?: Partial<EventContext>;
|
|
15
|
+
}
|
|
16
|
+
declare function createAnalytics(config: ReactNativeAnalyticsConfig): AnalyticsClient;
|
|
17
|
+
|
|
18
|
+
export { REACT_NATIVE_SDK_NAME, REACT_NATIVE_SDK_VERSION, type ReactNativeAnalyticsConfig, collectReactNativeContext, createAnalytics, createAsyncStorageAdapter, installAppStateFlush, osNameFromPlatform };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AnalyticsClient, EventContext, StorageAdapter, ClientConfig } from '@getdevteam/analytics-core';
|
|
2
|
+
export { AnalyticsClient, AnalyticsLogger, ClientConfig, EventContext, FetchLike, LogSeverity, Properties, StorageAdapter } from '@getdevteam/analytics-core';
|
|
3
|
+
|
|
4
|
+
declare function installAppStateFlush(client: AnalyticsClient): () => void;
|
|
5
|
+
|
|
6
|
+
declare function osNameFromPlatform(os: string): string;
|
|
7
|
+
declare function collectReactNativeContext(): EventContext;
|
|
8
|
+
|
|
9
|
+
declare function createAsyncStorageAdapter(): StorageAdapter;
|
|
10
|
+
|
|
11
|
+
declare const REACT_NATIVE_SDK_NAME = "@getdevteam/analytics-react-native";
|
|
12
|
+
declare const REACT_NATIVE_SDK_VERSION = "0.1.0";
|
|
13
|
+
interface ReactNativeAnalyticsConfig extends ClientConfig {
|
|
14
|
+
context?: Partial<EventContext>;
|
|
15
|
+
}
|
|
16
|
+
declare function createAnalytics(config: ReactNativeAnalyticsConfig): AnalyticsClient;
|
|
17
|
+
|
|
18
|
+
export { REACT_NATIVE_SDK_NAME, REACT_NATIVE_SDK_VERSION, type ReactNativeAnalyticsConfig, collectReactNativeContext, createAnalytics, createAsyncStorageAdapter, installAppStateFlush, osNameFromPlatform };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import {
|
|
3
|
+
createClient
|
|
4
|
+
} from "@getdevteam/analytics-core";
|
|
5
|
+
|
|
6
|
+
// src/appState.ts
|
|
7
|
+
import { AppState } from "react-native";
|
|
8
|
+
function installAppStateFlush(client) {
|
|
9
|
+
const onChange = (state) => {
|
|
10
|
+
if (state === "background" || state === "inactive") {
|
|
11
|
+
void client.flush();
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const subscription = AppState.addEventListener("change", onChange);
|
|
15
|
+
return () => subscription.remove();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// src/context.ts
|
|
19
|
+
import { Platform } from "react-native";
|
|
20
|
+
function osNameFromPlatform(os) {
|
|
21
|
+
switch (os) {
|
|
22
|
+
case "ios":
|
|
23
|
+
return "iOS";
|
|
24
|
+
case "android":
|
|
25
|
+
return "Android";
|
|
26
|
+
case "macos":
|
|
27
|
+
return "macOS";
|
|
28
|
+
case "windows":
|
|
29
|
+
return "Windows";
|
|
30
|
+
default:
|
|
31
|
+
return os;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function collectReactNativeContext() {
|
|
35
|
+
const context = { platform: "react-native" };
|
|
36
|
+
try {
|
|
37
|
+
context.os_name = osNameFromPlatform(Platform.OS);
|
|
38
|
+
context.os_version = String(Platform.Version);
|
|
39
|
+
context.device_type = Platform.isTV ? "tv" : Platform.isPad ? "tablet" : "mobile";
|
|
40
|
+
} catch {
|
|
41
|
+
}
|
|
42
|
+
return context;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/storage.ts
|
|
46
|
+
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
47
|
+
function createAsyncStorageAdapter() {
|
|
48
|
+
return {
|
|
49
|
+
getItem: async (key) => {
|
|
50
|
+
try {
|
|
51
|
+
return await AsyncStorage.getItem(key);
|
|
52
|
+
} catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
setItem: async (key, value) => {
|
|
57
|
+
try {
|
|
58
|
+
await AsyncStorage.setItem(key, value);
|
|
59
|
+
} catch {
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
removeItem: async (key) => {
|
|
63
|
+
try {
|
|
64
|
+
await AsyncStorage.removeItem(key);
|
|
65
|
+
} catch {
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// src/index.ts
|
|
72
|
+
var REACT_NATIVE_SDK_NAME = "@getdevteam/analytics-react-native";
|
|
73
|
+
var REACT_NATIVE_SDK_VERSION = "0.1.0";
|
|
74
|
+
function createAnalytics(config) {
|
|
75
|
+
const client = createClient({
|
|
76
|
+
...config,
|
|
77
|
+
storage: config.storage ?? createAsyncStorageAdapter()
|
|
78
|
+
});
|
|
79
|
+
client.setContext({
|
|
80
|
+
sdk_name: REACT_NATIVE_SDK_NAME,
|
|
81
|
+
sdk_version: REACT_NATIVE_SDK_VERSION,
|
|
82
|
+
...collectReactNativeContext(),
|
|
83
|
+
...config.context
|
|
84
|
+
});
|
|
85
|
+
const removeAppStateFlush = installAppStateFlush(client);
|
|
86
|
+
return {
|
|
87
|
+
...client,
|
|
88
|
+
shutdown: async () => {
|
|
89
|
+
removeAppStateFlush();
|
|
90
|
+
await client.shutdown();
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
export {
|
|
95
|
+
REACT_NATIVE_SDK_NAME,
|
|
96
|
+
REACT_NATIVE_SDK_VERSION,
|
|
97
|
+
collectReactNativeContext,
|
|
98
|
+
createAnalytics,
|
|
99
|
+
createAsyncStorageAdapter,
|
|
100
|
+
installAppStateFlush,
|
|
101
|
+
osNameFromPlatform
|
|
102
|
+
};
|
|
103
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/appState.ts","../src/context.ts","../src/storage.ts"],"sourcesContent":["import {\n createClient,\n type AnalyticsClient,\n type ClientConfig,\n type EventContext,\n} from \"@getdevteam/analytics-core\";\nimport { installAppStateFlush } from \"./appState\";\nimport { collectReactNativeContext } from \"./context\";\nimport { createAsyncStorageAdapter } from \"./storage\";\n\nexport const REACT_NATIVE_SDK_NAME = \"@getdevteam/analytics-react-native\";\nexport const REACT_NATIVE_SDK_VERSION = \"0.1.0\";\n\nexport interface ReactNativeAnalyticsConfig extends ClientConfig {\n context?: Partial<EventContext>;\n}\n\nexport function createAnalytics(config: ReactNativeAnalyticsConfig): AnalyticsClient {\n const client = createClient({\n ...config,\n storage: config.storage ?? createAsyncStorageAdapter(),\n });\n\n client.setContext({\n sdk_name: REACT_NATIVE_SDK_NAME,\n sdk_version: REACT_NATIVE_SDK_VERSION,\n ...collectReactNativeContext(),\n ...config.context,\n });\n\n const removeAppStateFlush = installAppStateFlush(client);\n\n return {\n ...client,\n shutdown: async () => {\n removeAppStateFlush();\n await client.shutdown();\n },\n };\n}\n\nexport { installAppStateFlush } from \"./appState\";\nexport { collectReactNativeContext, osNameFromPlatform } from \"./context\";\nexport { createAsyncStorageAdapter } from \"./storage\";\nexport type {\n AnalyticsClient,\n AnalyticsLogger,\n ClientConfig,\n EventContext,\n FetchLike,\n LogSeverity,\n Properties,\n StorageAdapter,\n} from \"@getdevteam/analytics-core\";\n","import { AppState, type AppStateStatus } from \"react-native\";\nimport type { AnalyticsClient } from \"@getdevteam/analytics-core\";\n\nexport function installAppStateFlush(client: AnalyticsClient): () => void {\n const onChange = (state: AppStateStatus): void => {\n if (state === \"background\" || state === \"inactive\") {\n void client.flush();\n }\n };\n const subscription = AppState.addEventListener(\"change\", onChange);\n return () => subscription.remove();\n}\n","import { Platform } from \"react-native\";\nimport type { EventContext } from \"@getdevteam/analytics-core\";\n\nexport function osNameFromPlatform(os: string): string {\n switch (os) {\n case \"ios\":\n return \"iOS\";\n case \"android\":\n return \"Android\";\n case \"macos\":\n return \"macOS\";\n case \"windows\":\n return \"Windows\";\n default:\n return os;\n }\n}\n\nexport function collectReactNativeContext(): EventContext {\n const context: EventContext = { platform: \"react-native\" };\n try {\n context.os_name = osNameFromPlatform(Platform.OS);\n context.os_version = String(Platform.Version);\n context.device_type = Platform.isTV ? \"tv\" : Platform.isPad ? \"tablet\" : \"mobile\";\n } catch {\n // Platform constants can be unavailable outside a real RN runtime; the platform tag alone still stands\n }\n return context;\n}\n","import AsyncStorage from \"@react-native-async-storage/async-storage\";\nimport type { StorageAdapter } from \"@getdevteam/analytics-core\";\n\nexport function createAsyncStorageAdapter(): StorageAdapter {\n return {\n getItem: async (key) => {\n try {\n return await AsyncStorage.getItem(key);\n } catch {\n return null;\n }\n },\n setItem: async (key, value) => {\n try {\n await AsyncStorage.setItem(key, value);\n } catch {\n // storage unavailable; queue persistence degrades gracefully\n }\n },\n removeItem: async (key) => {\n try {\n await AsyncStorage.removeItem(key);\n } catch {\n // ignore\n }\n },\n };\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,OAIK;;;ACLP,SAAS,gBAAqC;AAGvC,SAAS,qBAAqB,QAAqC;AACxE,QAAM,WAAW,CAAC,UAAgC;AAChD,QAAI,UAAU,gBAAgB,UAAU,YAAY;AAClD,WAAK,OAAO,MAAM;AAAA,IACpB;AAAA,EACF;AACA,QAAM,eAAe,SAAS,iBAAiB,UAAU,QAAQ;AACjE,SAAO,MAAM,aAAa,OAAO;AACnC;;;ACXA,SAAS,gBAAgB;AAGlB,SAAS,mBAAmB,IAAoB;AACrD,UAAQ,IAAI;AAAA,IACV,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;AAEO,SAAS,4BAA0C;AACxD,QAAM,UAAwB,EAAE,UAAU,eAAe;AACzD,MAAI;AACF,YAAQ,UAAU,mBAAmB,SAAS,EAAE;AAChD,YAAQ,aAAa,OAAO,SAAS,OAAO;AAC5C,YAAQ,cAAc,SAAS,OAAO,OAAO,SAAS,QAAQ,WAAW;AAAA,EAC3E,QAAQ;AAAA,EAER;AACA,SAAO;AACT;;;AC5BA,OAAO,kBAAkB;AAGlB,SAAS,4BAA4C;AAC1D,SAAO;AAAA,IACL,SAAS,OAAO,QAAQ;AACtB,UAAI;AACF,eAAO,MAAM,aAAa,QAAQ,GAAG;AAAA,MACvC,QAAQ;AACN,eAAO;AAAA,MACT;AAAA,IACF;AAAA,IACA,SAAS,OAAO,KAAK,UAAU;AAC7B,UAAI;AACF,cAAM,aAAa,QAAQ,KAAK,KAAK;AAAA,MACvC,QAAQ;AAAA,MAER;AAAA,IACF;AAAA,IACA,YAAY,OAAO,QAAQ;AACzB,UAAI;AACF,cAAM,aAAa,WAAW,GAAG;AAAA,MACnC,QAAQ;AAAA,MAER;AAAA,IACF;AAAA,EACF;AACF;;;AHjBO,IAAM,wBAAwB;AAC9B,IAAM,2BAA2B;AAMjC,SAAS,gBAAgB,QAAqD;AACnF,QAAM,SAAS,aAAa;AAAA,IAC1B,GAAG;AAAA,IACH,SAAS,OAAO,WAAW,0BAA0B;AAAA,EACvD,CAAC;AAED,SAAO,WAAW;AAAA,IAChB,UAAU;AAAA,IACV,aAAa;AAAA,IACb,GAAG,0BAA0B;AAAA,IAC7B,GAAG,OAAO;AAAA,EACZ,CAAC;AAED,QAAM,sBAAsB,qBAAqB,MAAM;AAEvD,SAAO;AAAA,IACL,GAAG;AAAA,IACH,UAAU,YAAY;AACpB,0BAAoB;AACpB,YAAM,OAAO,SAAS;AAAA,IACxB;AAAA,EACF;AACF;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@getdevteam/analytics-react-native",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "React Native SDK for the DevTeam analytics and logging platform.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/getdevteam-ai/analytics",
|
|
9
|
+
"directory": "src/sdk/packages/react-native"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "./dist/index.cjs",
|
|
13
|
+
"module": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"import": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"require": {
|
|
22
|
+
"types": "./dist/index.d.cts",
|
|
23
|
+
"default": "./dist/index.cjs"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": ["dist"],
|
|
28
|
+
"sideEffects": false,
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsup",
|
|
34
|
+
"test": "vitest run",
|
|
35
|
+
"typecheck": "tsc --noEmit"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@getdevteam/analytics-core": "0.1.0"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"@react-native-async-storage/async-storage": ">=1.19.0",
|
|
42
|
+
"react-native": ">=0.72"
|
|
43
|
+
},
|
|
44
|
+
"peerDependenciesMeta": {
|
|
45
|
+
"@react-native-async-storage/async-storage": {
|
|
46
|
+
"optional": true
|
|
47
|
+
},
|
|
48
|
+
"react-native": {
|
|
49
|
+
"optional": true
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"tsup": "^8.5.0",
|
|
54
|
+
"typescript": "^5.8.3",
|
|
55
|
+
"vitest": "^3.2.4"
|
|
56
|
+
}
|
|
57
|
+
}
|