@openfort/react-native 0.1.17 → 0.1.19

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.
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export const SDK_INFO = {
5
5
  name: '@openfort/react-native',
6
- version: '0.1.15',
6
+ version: '0.1.18',
7
7
  description: 'React Native client for Openfort',
8
8
  homepage: 'https://openfort.io/docs',
9
9
  };
@@ -49,7 +49,7 @@ export function createOpenfortClient({ baseConfiguration, overrides, shieldConfi
49
49
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
50
  digest: digest,
51
51
  },
52
- storage: createNormalizedStorage(SecureStorageAdapter),
52
+ storage: createNormalizedStorage(baseConfiguration.publishableKey, SecureStorageAdapter),
53
53
  },
54
54
  shieldConfiguration,
55
55
  });
@@ -2,19 +2,12 @@
2
2
  import * as SecureStore from 'expo-secure-store';
3
3
  import { logger } from '../lib/logger';
4
4
  import { NativeStorageUtils } from '../native';
5
- // Define the StorageKeys enum values that match the Openfort SDK
6
- var StorageKeys;
7
- (function (StorageKeys) {
8
- StorageKeys["AUTHENTICATION"] = "openfort.authentication";
9
- StorageKeys["SIGNER"] = "openfort.signer";
10
- StorageKeys["CONFIGURATION"] = "openfort.configuration";
11
- StorageKeys["ACCOUNT"] = "openfort.account";
12
- StorageKeys["TEST"] = "openfort.test";
13
- StorageKeys["RECOVERY"] = "openfort.recovery";
14
- StorageKeys["SESSION"] = "openfort.session";
15
- StorageKeys["PKCE_STATE"] = "openfort.pkce_state";
16
- StorageKeys["PKCE_VERIFIER"] = "openfort.pkce_verifier";
17
- })(StorageKeys || (StorageKeys = {}));
5
+ /**
6
+ * Tracks pending write operations per key.
7
+ * This ensures `get` waits for any in-flight `save` to complete,
8
+ * providing read-after-write consistency while keeping `save` synchronous.
9
+ */
10
+ const pendingWrites = new Map();
18
11
  /**
19
12
  * Storage adapter backed by {@link SecureStore} that matches the {@link Storage} interface expected by `@openfort/openfort-js`.
20
13
  *
@@ -24,6 +17,11 @@ export const SecureStorageAdapter = {
24
17
  async get(key) {
25
18
  try {
26
19
  const normalizedKey = normalizeKey(key);
20
+ // Wait for any pending write to complete before reading
21
+ const pendingWrite = pendingWrites.get(normalizedKey);
22
+ if (pendingWrite) {
23
+ await pendingWrite;
24
+ }
27
25
  const result = await SecureStore.getItemAsync(normalizedKey, NativeStorageUtils.getStorageOptions());
28
26
  // If result is a string (as expected), return it
29
27
  if (typeof result === 'string' || result === null) {
@@ -45,14 +43,21 @@ export const SecureStorageAdapter = {
45
43
  }
46
44
  },
47
45
  async save(key, value) {
48
- try {
49
- const normalizedKey = normalizeKey(key);
50
- await SecureStore.setItemAsync(normalizedKey, value, NativeStorageUtils.getStorageOptions());
51
- }
52
- catch (error) {
53
- logger.warn('Failed to set item in secure store', error);
54
- throw error;
55
- }
46
+ const normalizedKey = normalizeKey(key);
47
+ const writePromise = (async () => {
48
+ try {
49
+ await SecureStore.setItemAsync(normalizedKey, value, NativeStorageUtils.getStorageOptions());
50
+ }
51
+ catch (error) {
52
+ logger.warn('Failed to set item in secure store', error);
53
+ throw error;
54
+ }
55
+ finally {
56
+ pendingWrites.delete(normalizedKey);
57
+ }
58
+ })();
59
+ pendingWrites.set(normalizedKey, writePromise);
60
+ return writePromise;
56
61
  },
57
62
  async remove(key) {
58
63
  try {
@@ -78,7 +83,7 @@ export const SecureStorageAdapter = {
78
83
  },
79
84
  };
80
85
  /**
81
- * Normalises an Openfort storage key for use with Expo Secure Store.
86
+ * Normalizes an Openfort storage key for use with Expo Secure Store.
82
87
  *
83
88
  * @param key - The key provided by the Openfort SDK.
84
89
  * @returns A key that is safe to use with Expo Secure Store.
@@ -87,66 +92,36 @@ function normalizeKey(key) {
87
92
  return key.replaceAll(':', '-');
88
93
  }
89
94
  /**
90
- * Creates a type-safe storage adapter that bridges the Openfort SDK storage API with the React Native implementation.
95
+ * Creates a storage adapter that bridges the Openfort SDK storage API with the React Native implementation.
96
+ * The core SDK's ScopedStorage handles key scoping, so this adapter simply passes keys through.
91
97
  *
98
+ * @param _publishableKey - Unused. Key scoping is handled by the core SDK.
92
99
  * @param customStorage - Optional custom storage implementation. When omitted the {@link SecureStorageAdapter} is used.
93
100
  * @returns An object that satisfies the {@link Storage} interface expected by `@openfort/openfort-js`.
94
101
  */
95
- export function createNormalizedStorage(customStorage) {
102
+ export function createNormalizedStorage(_publishableKey, customStorage) {
96
103
  const baseStorage = customStorage || SecureStorageAdapter;
97
104
  return {
98
105
  async get(key) {
99
- // Convert the unknown key to our StorageKeys enum
100
- const storageKey = keyToStorageKeys(key);
101
- const result = await baseStorage.get(storageKey);
102
- return result;
106
+ const keyString = String(key);
107
+ return baseStorage.get(keyString);
103
108
  },
104
109
  save(key, value) {
105
- logger.info(`Saving to storage key: ${key}, value: ${value}`);
106
- const storageKey = keyToStorageKeys(key);
110
+ const keyString = String(key);
107
111
  // Fire and forget - don't await as the SDK expects synchronous behavior
108
- baseStorage.save(storageKey, value).catch((error) => {
112
+ baseStorage.save(keyString, value).catch((error) => {
109
113
  logger.error('Failed to save to storage', error);
110
114
  });
111
115
  },
112
116
  remove(key) {
113
- logger.info(`Removing from storage key: ${key}`);
114
- const storageKey = keyToStorageKeys(key);
117
+ const keyString = String(key);
115
118
  // Fire and forget - don't await as the SDK expects synchronous behavior
116
- baseStorage.remove(storageKey).catch((error) => {
119
+ baseStorage.remove(keyString).catch((error) => {
117
120
  logger.error('Failed to remove from storage', error);
118
121
  });
119
122
  },
120
123
  flush() {
121
- logger.info('Flushing storage');
122
124
  baseStorage.flush();
123
125
  },
124
126
  };
125
127
  }
126
- /**
127
- * Converts a key provided by the Openfort SDK to the local {@link StorageKeys} enum.
128
- *
129
- * @param key - Value provided by the Openfort SDK. Can be a string or an enum-like
130
- * object.
131
- * @returns The matching {@link StorageKeys} value.
132
- * @throws {Error} When the key cannot be mapped to one of the known storage keys.
133
- */
134
- function keyToStorageKeys(key) {
135
- if (typeof key === 'string') {
136
- // Check if the string matches one of our enum values
137
- const storageKey = Object.values(StorageKeys).find((value) => value === key);
138
- if (storageKey) {
139
- return storageKey;
140
- }
141
- }
142
- // If it's an enum-like object, try to get its value
143
- if (typeof key === 'object' && key !== null && 'toString' in key) {
144
- const keyString = key.toString();
145
- const storageKey = Object.values(StorageKeys).find((value) => value === keyString);
146
- if (storageKey) {
147
- return storageKey;
148
- }
149
- }
150
- // Fallback: throw an error for unknown keys
151
- throw new Error(`Unknown storage key: ${key}. Expected one of: ${Object.values(StorageKeys).join(', ')}`);
152
- }
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export declare const SDK_INFO: {
5
5
  readonly name: "@openfort/react-native";
6
- readonly version: "0.1.15";
6
+ readonly version: "0.1.18";
7
7
  readonly description: "React Native client for Openfort";
8
8
  readonly homepage: "https://openfort.io/docs";
9
9
  };
@@ -1,21 +1,10 @@
1
1
  import type { Storage } from '@openfort/openfort-js';
2
- declare enum StorageKeys {
3
- AUTHENTICATION = "openfort.authentication",
4
- SIGNER = "openfort.signer",
5
- CONFIGURATION = "openfort.configuration",
6
- ACCOUNT = "openfort.account",
7
- TEST = "openfort.test",
8
- RECOVERY = "openfort.recovery",
9
- SESSION = "openfort.session",
10
- PKCE_STATE = "openfort.pkce_state",
11
- PKCE_VERIFIER = "openfort.pkce_verifier"
12
- }
13
2
  interface OpenfortStorage {
14
- get(key: StorageKeys): Promise<string | null>;
15
- save(key: StorageKeys, value: string): Promise<void>;
16
- remove(key: StorageKeys): Promise<void>;
3
+ get(key: string): Promise<string | null>;
4
+ save(key: string, value: string): Promise<void>;
5
+ remove(key: string): Promise<void>;
17
6
  flush(): void;
18
- keyExists(key: StorageKeys): Promise<boolean>;
7
+ keyExists(key: string): Promise<boolean>;
19
8
  getStorageInfo(): Promise<{
20
9
  isAvailable: boolean;
21
10
  platform: string;
@@ -29,10 +18,12 @@ interface OpenfortStorage {
29
18
  */
30
19
  export declare const SecureStorageAdapter: OpenfortStorage;
31
20
  /**
32
- * Creates a type-safe storage adapter that bridges the Openfort SDK storage API with the React Native implementation.
21
+ * Creates a storage adapter that bridges the Openfort SDK storage API with the React Native implementation.
22
+ * The core SDK's ScopedStorage handles key scoping, so this adapter simply passes keys through.
33
23
  *
24
+ * @param _publishableKey - Unused. Key scoping is handled by the core SDK.
34
25
  * @param customStorage - Optional custom storage implementation. When omitted the {@link SecureStorageAdapter} is used.
35
26
  * @returns An object that satisfies the {@link Storage} interface expected by `@openfort/openfort-js`.
36
27
  */
37
- export declare function createNormalizedStorage(customStorage?: OpenfortStorage): Storage;
28
+ export declare function createNormalizedStorage(_publishableKey: string, customStorage?: OpenfortStorage): Storage;
38
29
  export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@openfort/react-native",
3
3
  "main": "dist/index.js",
4
- "version": "0.1.17",
4
+ "version": "0.1.19",
5
5
  "license": "MIT",
6
6
  "description": "React Native SDK for Openfort platform integration",
7
7
  "types": "dist/types/index.d.ts",
@@ -16,7 +16,7 @@
16
16
  }
17
17
  },
18
18
  "dependencies": {
19
- "@openfort/openfort-js": "^0.10.38"
19
+ "@openfort/openfort-js": "^0.10.39"
20
20
  },
21
21
  "peerDependencies": {
22
22
  "expo-apple-authentication": "*",