@advenue/react-native 0.3.1 → 0.4.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.
@@ -0,0 +1,63 @@
1
+ // Adapters over the native modules' built-in storage (UserDefaults /
2
+ // SharedPreferences + iOS Keychain), so the app never supplies storage —
3
+ // Adjust/AppsFlyer parity. Pure functions over a passed module (rather than
4
+ // resolving the module themselves) so they stay unit-testable and respect the
5
+ // test mocks of './native'.
6
+ import type { SecureStorageAdapter, StorageAdapter } from '@advenue/sdk-core';
7
+
8
+ interface NativeStorageFns {
9
+ storageGetItem?(key: string): string | null;
10
+ storageSetItem?(key: string, value: string): void;
11
+ storageRemoveItem?(key: string): void;
12
+ }
13
+
14
+ interface NativeSecureFns {
15
+ secureGetItem?(key: string): string | null;
16
+ secureSetItem?(key: string, value: string): void;
17
+ secureRemoveItem?(key: string): void;
18
+ }
19
+
20
+ /**
21
+ * Wraps a native module's built-in key/value storage as the sync
22
+ * {@link StorageAdapter}. Returns null when the module is absent or predates
23
+ * the storage capability (feature-detected), so callers fall back.
24
+ */
25
+ export function createNativeStorage(mod: unknown): StorageAdapter | null {
26
+ const m = mod as NativeStorageFns | null;
27
+ if (
28
+ !m ||
29
+ typeof m.storageGetItem !== 'function' ||
30
+ typeof m.storageSetItem !== 'function' ||
31
+ typeof m.storageRemoveItem !== 'function'
32
+ ) {
33
+ return null;
34
+ }
35
+ return {
36
+ getItem: (key) => m.storageGetItem?.(key) ?? null,
37
+ setItem: (key, value) => m.storageSetItem?.(key, value),
38
+ removeItem: (key) => m.storageRemoveItem?.(key),
39
+ };
40
+ }
41
+
42
+ /**
43
+ * Wraps the iOS module's Keychain functions as the async
44
+ * {@link SecureStorageAdapter} (with erasure support). Returns null when the
45
+ * module is absent or predates the capability — including all of Android,
46
+ * which has no reinstall-durable store.
47
+ */
48
+ export function createNativeSecureStore(mod: unknown): SecureStorageAdapter | null {
49
+ const m = mod as NativeSecureFns | null;
50
+ if (
51
+ !m ||
52
+ typeof m.secureGetItem !== 'function' ||
53
+ typeof m.secureSetItem !== 'function' ||
54
+ typeof m.secureRemoveItem !== 'function'
55
+ ) {
56
+ return null;
57
+ }
58
+ return {
59
+ getItemAsync: async (key) => m.secureGetItem?.(key) ?? null,
60
+ setItemAsync: async (key, value) => m.secureSetItem?.(key, value),
61
+ deleteItemAsync: async (key) => m.secureRemoveItem?.(key),
62
+ };
63
+ }
package/src/native.ts CHANGED
@@ -25,6 +25,19 @@ export function getAndroidNative(): AdvenueAndroidNativeModule | null {
25
25
  }
26
26
  }
27
27
 
28
+ /**
29
+ * Lazy access to React Native's Platform.OS ('ios' | 'android' | 'web' |
30
+ * 'windows' | 'macos'). Returns null when react-native isn't resolvable, so
31
+ * callers can require an explicit platform instead of guessing.
32
+ */
33
+ export function getPlatformOS(): string | null {
34
+ try {
35
+ return (require('react-native') as { Platform: { OS: string } }).Platform.OS ?? null;
36
+ } catch {
37
+ return null;
38
+ }
39
+ }
40
+
28
41
  /** Subscription handle returned by AppState.addEventListener. */
29
42
  export interface AppStateSubscription {
30
43
  remove(): void;
@@ -8,6 +8,8 @@ import type { SecureStorageAdapter } from '@advenue/sdk-core';
8
8
  export interface SecureStoreLike {
9
9
  getItemAsync(key: string): Promise<string | null>;
10
10
  setItemAsync(key: string, value: string): Promise<void>;
11
+ /** Optional — forwarded so GDPR erasure can wipe the durable entries. */
12
+ deleteItemAsync?(key: string): Promise<void>;
11
13
  }
12
14
 
13
15
  /** Wraps expo-secure-store as an Advenue SecureStorageAdapter (async, durable). */
@@ -15,5 +17,10 @@ export function createSecureStore(secureStore: SecureStoreLike): SecureStorageAd
15
17
  return {
16
18
  getItemAsync: async (key) => (await secureStore.getItemAsync(key)) ?? null,
17
19
  setItemAsync: (key, value) => secureStore.setItemAsync(key, value),
20
+ ...(secureStore.deleteItemAsync
21
+ ? {
22
+ deleteItemAsync: (key: string) => secureStore.deleteItemAsync?.(key) ?? Promise.resolve(),
23
+ }
24
+ : {}),
18
25
  };
19
26
  }