@amplytools/react-native-amply-sdk 0.1.0 → 0.1.2

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,15 +1,15 @@
1
1
  {
2
2
  "name": "@amplytools/react-native-amply-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "React Native SDK for Amply: Mobile SDK to orchestrate in-app experiences and campaigns remotely, without app releases",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "https://github.com/amply/amply-react-native.git"
8
+ "url": "https://github.com/amply-tools/amply-react-native.git"
9
9
  },
10
- "homepage": "https://github.com/amply/amply-react-native",
10
+ "homepage": "https://github.com/amply-tools/amply-react-native",
11
11
  "bugs": {
12
- "url": "https://github.com/amply/amply-react-native/issues"
12
+ "url": "https://github.com/amply-tools/amply-react-native/issues"
13
13
  },
14
14
  "main": "dist/index.js",
15
15
  "module": "dist/index.mjs",
@@ -18,9 +18,6 @@
18
18
  "source": "src/index.ts",
19
19
  "files": [
20
20
  "android/",
21
- "!android/.cxx/",
22
- "!android/build/",
23
- "!android/.gradle/",
24
21
  "ios/",
25
22
  "dist/",
26
23
  "src/",
@@ -46,6 +43,7 @@
46
43
  "react-native": ">=0.79.0"
47
44
  },
48
45
  "devDependencies": {
46
+ "@babel/core": "^7.28.6",
49
47
  "@react-native/codegen": "0.81.4",
50
48
  "@react-native/eslint-config": "^0.74.81",
51
49
  "@react-native/typescript-config": "0.81.0",
@@ -57,6 +55,7 @@
57
55
  "expo": "^54.0.0",
58
56
  "expo-module-scripts": "^3.5.0",
59
57
  "jest": "^29.7.0",
58
+ "metro-react-native-babel-preset": "^0.77.0",
60
59
  "typescript": "^5.4.0"
61
60
  },
62
61
  "engines": {
package/src/index.ts CHANGED
@@ -8,12 +8,62 @@ import type {
8
8
  DataSetType,
9
9
  DeepLinkEvent,
10
10
  EventRecord,
11
+ LogLevel,
11
12
  TrackEventPayload,
12
13
  } from './nativeSpecs/NativeAmplyModule';
13
14
 
14
15
  let deepLinkRegistered = false;
16
+ let debugLogListenerRegistered = false;
15
17
  const deepLinkSubscriptions = new Set<() => void>();
16
18
 
19
+ /**
20
+ * Format a debug log entry for console output.
21
+ */
22
+ function formatDebugLog(event: EventRecord): string {
23
+ const props = event.properties as {
24
+ level?: string;
25
+ category?: string;
26
+ message?: string;
27
+ };
28
+ const level = props.level?.toUpperCase() || 'DEBUG';
29
+ const category = props.category || '';
30
+ return `[Amply ${level}] [${category}] ${props.message || ''}`;
31
+ }
32
+
33
+ /**
34
+ * Set up debug log listener that outputs to console.
35
+ * This is called automatically when debug mode is enabled.
36
+ */
37
+ function ensureDebugLogListener(): void {
38
+ if (debugLogListenerRegistered) {
39
+ return;
40
+ }
41
+ debugLogListenerRegistered = true;
42
+
43
+ addSystemEventListenerInternal((event: EventRecord) => {
44
+ if (event.name === 'DebugLog') {
45
+ const formattedLog = formatDebugLog(event);
46
+ const props = event.properties as {level?: string};
47
+ const level = props.level?.toLowerCase();
48
+
49
+ // Use appropriate console method based on log level
50
+ switch (level) {
51
+ case 'error':
52
+ console.error(formattedLog);
53
+ break;
54
+ case 'warn':
55
+ console.warn(formattedLog);
56
+ break;
57
+ case 'debug':
58
+ console.debug(formattedLog);
59
+ break;
60
+ default:
61
+ console.log(formattedLog);
62
+ }
63
+ }
64
+ });
65
+ }
66
+
17
67
  async function ensureDeepLinkRegistration(): Promise<void> {
18
68
  if (!deepLinkRegistered) {
19
69
  console.log('[Amply] Calling registerDeepLinkListener on native module');
@@ -38,9 +88,34 @@ function trackDeepLinkSubscription(subscription?: {remove?: () => void}): () =>
38
88
  }
39
89
 
40
90
  export async function initialize(config: AmplyInitializationConfig): Promise<void> {
91
+ // Set up debug log listener if debug mode is enabled
92
+ if (config.debug || config.logLevel) {
93
+ ensureDebugLogListener();
94
+ }
95
+
41
96
  await getNativeModule().initialize(config);
42
97
  }
43
98
 
99
+ /**
100
+ * Set the log level at runtime.
101
+ * @param level The log level: 'none' | 'error' | 'warn' | 'info' | 'debug'
102
+ */
103
+ export function setLogLevel(level: LogLevel): void {
104
+ // Ensure debug log listener is set up when changing log level
105
+ if (level !== 'none') {
106
+ ensureDebugLogListener();
107
+ }
108
+ getNativeModule().setLogLevel(level);
109
+ }
110
+
111
+ /**
112
+ * Get the current log level.
113
+ * @returns The current log level
114
+ */
115
+ export function getLogLevel(): LogLevel {
116
+ return getNativeModule().getLogLevel() as LogLevel;
117
+ }
118
+
44
119
  export function isInitialized(): boolean {
45
120
  return getNativeModule().isInitialized();
46
121
  }
@@ -88,6 +163,7 @@ export type {
88
163
  DataSetType,
89
164
  DeepLinkEvent,
90
165
  EventRecord,
166
+ LogLevel,
91
167
  TrackEventPayload,
92
168
  };
93
169
 
@@ -111,5 +187,7 @@ export default {
111
187
  addSystemEventListener,
112
188
  addSystemEventsListener,
113
189
  removeAllListeners,
190
+ setLogLevel,
191
+ getLogLevel,
114
192
  systemEvents,
115
193
  };
@@ -4,6 +4,16 @@ import type {EventEmitter} from 'react-native/Libraries/Types/CodegenTypes';
4
4
 
5
5
  type JsonMap = {[key: string]: unknown};
6
6
 
7
+ /**
8
+ * Log level for SDK debug output.
9
+ * - 'none': No logging
10
+ * - 'error': Only errors
11
+ * - 'warn': Errors and warnings
12
+ * - 'info': SDK lifecycle events (init, session start/end)
13
+ * - 'debug': Everything including campaign evaluation details
14
+ */
15
+ export type LogLevel = 'none' | 'error' | 'warn' | 'info' | 'debug';
16
+
7
17
  export type AmplyInitializationConfig = {
8
18
  appId: string;
9
19
  apiKeyPublic: string;
@@ -11,6 +21,16 @@ export type AmplyInitializationConfig = {
11
21
  endpoint?: string | null;
12
22
  datasetPrefetch?: DataSetType[] | null;
13
23
  defaultConfig?: string | null;
24
+ /**
25
+ * Enable debug logging. Shorthand for logLevel: 'debug'.
26
+ * When true, logs will appear in the Metro console.
27
+ */
28
+ debug?: boolean | null;
29
+ /**
30
+ * Set the log level for SDK output.
31
+ * Takes precedence over `debug` if both are specified.
32
+ */
33
+ logLevel?: LogLevel | null;
14
34
  };
15
35
 
16
36
  export type EventType = 'custom' | 'system';
@@ -71,6 +91,16 @@ export interface Spec extends TurboModule {
71
91
  getRecentEvents(limit: number): Promise<EventRecord[]>;
72
92
  getDataSetSnapshot(type: DataSetType): Promise<DataSetSnapshot>;
73
93
  registerDeepLinkListener(): void;
94
+ /**
95
+ * Set the log level at runtime.
96
+ * @param level The log level to set
97
+ */
98
+ setLogLevel(level: string): void;
99
+ /**
100
+ * Get the current log level.
101
+ * @returns The current log level as a string
102
+ */
103
+ getLogLevel(): string;
74
104
  readonly onSystemEvent: EventEmitter<SystemEventPayload>;
75
105
  readonly onDeepLink: EventEmitter<DeepLinkEvent>;
76
106
  addListener(eventName: string): void;