Skip to content

Commit 0246f6a

Browse files
authored
FF-2139 Fixes "Property 'atob' doesn't exist" errors in RN 0.72 (#48)
* Fixes "Property 'atob' doesn't exist" errors in RN 0.72 * fix types
1 parent 0b34482 commit 0246f6a

File tree

4 files changed

+95
-20
lines changed

4 files changed

+95
-20
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eppo/react-native-sdk",
3-
"version": "3.0.1",
3+
"version": "3.0.2",
44
"description": "Eppo React Native SDK",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",
@@ -51,7 +51,7 @@
5151
"registry": "https://registry.npmjs.org/"
5252
},
5353
"dependencies": {
54-
"@eppo/js-client-sdk-common": "3.0.2",
54+
"@eppo/js-client-sdk-common": "3.2.0",
5555
"@react-native-async-storage/async-storage": "^1.18.0",
5656
"md5": "^2.3.0"
5757
},
@@ -147,4 +147,4 @@
147147
]
148148
]
149149
}
150-
}
150+
}

src/async-storage.spec.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import type { Flag, VariationType } from '@eppo/js-client-sdk-common';
12
import { EppoAsyncStorage, STORAGE_KEY } from './async-storage';
23
import AsyncStorage from '@react-native-async-storage/async-storage';
4+
import type { Variation } from '@eppo/js-client-sdk-common/dist/interfaces';
35

46
describe('EppoAsyncStorage', () => {
57
let storage: EppoAsyncStorage;
@@ -10,26 +12,49 @@ describe('EppoAsyncStorage', () => {
1012
AsyncStorage.getItem = jest.fn();
1113
});
1214

15+
const buildFlag = (key: string, variationValues: string[]): Flag => {
16+
const variations: Record<string, Variation> = {};
17+
variationValues.forEach((variationValue) => {
18+
variations[variationValue] = {
19+
key: variationValue,
20+
value: variationValue,
21+
};
22+
});
23+
return {
24+
key,
25+
enabled: true,
26+
variationType: 'STRING' as VariationType,
27+
variations,
28+
allocations: [],
29+
totalShards: 1,
30+
};
31+
};
32+
1333
describe('setEntries', () => {
1434
it('should set entries and update AsyncStorage', async () => {
1535
expect(storage.isInitialized()).toBe(false);
1636

17-
const entries = { key1: 'newvalue1', key2: 'newvalue2' };
37+
const flag1 = buildFlag('flag-key1', ['control-1', 'experiment-1']);
38+
const flag2 = buildFlag('flag-key2', ['control-2', 'experiment-2']);
39+
const entries = { key1: flag1, key2: flag2 };
1840
await storage.setEntries(entries);
1941

2042
expect(AsyncStorage.setItem).toHaveBeenCalledWith(
2143
STORAGE_KEY,
2244
JSON.stringify(entries)
2345
);
24-
expect(storage.get('key1')).toBe('newvalue1');
25-
expect(storage.get('key2')).toBe('newvalue2');
46+
expect(storage.get('key1')).toEqual(flag1);
47+
expect(storage.get('key2')).toEqual(flag2);
2648
expect(storage.isInitialized()).toBe(true);
2749
});
2850
});
2951

3052
describe('getKeys', () => {
3153
it('should return all keys in the cache', async () => {
32-
const entries = { key1: 'value1', key2: 'value2', key3: 'value3' };
54+
const flag1 = buildFlag('flag-key1', ['control-1', 'experiment-1']);
55+
const flag2 = buildFlag('flag-key2', ['control-2', 'experiment-2']);
56+
const flag3 = buildFlag('flag-key3', ['control-3', 'experiment-3']);
57+
const entries = { key1: flag1, key2: flag2, key3: flag3 };
3358
await storage.setEntries(entries);
3459

3560
const keys = storage.getKeys();

src/async-storage.ts

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
import type { IConfigurationStore } from '@eppo/js-client-sdk-common';
1+
import type {
2+
IAsyncStore,
3+
IConfigurationStore,
4+
ISyncStore,
5+
} from '@eppo/js-client-sdk-common';
6+
import type {
7+
Flag,
8+
ObfuscatedFlag,
9+
} from '@eppo/js-client-sdk-common/dist/interfaces';
210
import AsyncStorage from '@react-native-async-storage/async-storage';
311

412
// Bump this version number when we make breaking changes to the cache.
513
export const STORAGE_KEY = '@eppo/sdk-cache-ufc';
614

7-
export class EppoAsyncStorage implements IConfigurationStore {
15+
class AsyncStorageStore<T> implements ISyncStore<T> {
816
private cache: { [key: string]: any } = {};
917
private _isInitialized = false;
1018

@@ -27,7 +35,7 @@ export class EppoAsyncStorage implements IConfigurationStore {
2735
return Object.keys(this.cache);
2836
}
2937

30-
public setEntries<T>(entries: Record<string, T>): void {
38+
public setEntries(entries: Record<string, T>): void {
3139
for (var key in entries) {
3240
this.cache[key] = entries[key];
3341
}
@@ -36,3 +44,45 @@ export class EppoAsyncStorage implements IConfigurationStore {
3644
this._isInitialized = true;
3745
}
3846
}
47+
48+
export class EppoAsyncStorage
49+
implements IConfigurationStore<Flag | ObfuscatedFlag>
50+
{
51+
servingStore: ISyncStore<Flag | ObfuscatedFlag>;
52+
persistentStore: IAsyncStore<Flag | ObfuscatedFlag> | null;
53+
private initialized: boolean;
54+
55+
constructor() {
56+
this.servingStore = new AsyncStorageStore<Flag | ObfuscatedFlag>();
57+
this.persistentStore = null;
58+
this.initialized = false;
59+
}
60+
61+
init(): Promise<void> {
62+
this.initialized = true;
63+
return Promise.resolve();
64+
}
65+
66+
get(key: string): Flag | ObfuscatedFlag | null {
67+
return this.servingStore.get(key);
68+
}
69+
70+
getKeys(): string[] {
71+
return this.servingStore.getKeys();
72+
}
73+
74+
async isExpired(): Promise<boolean> {
75+
return true;
76+
}
77+
78+
isInitialized(): boolean {
79+
return this.initialized;
80+
}
81+
82+
async setEntries(
83+
entries: Record<string, Flag | ObfuscatedFlag>
84+
): Promise<void> {
85+
this.servingStore.setEntries(entries);
86+
this.initialized = true;
87+
}
88+
}

yarn.lock

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,15 +1213,15 @@
12131213
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
12141214
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
12151215

1216-
"@eppo/js-client-sdk-common@3.0.2":
1217-
version "3.0.2"
1218-
resolved "https://registry.yarnpkg.com/@eppo/js-client-sdk-common/-/js-client-sdk-common-3.0.2.tgz#c1929fcad1b67676657d721cdc37561da108565d"
1219-
integrity sha512-Px7ppXMiWSNYYBRWORLcPSnOSreZASYzvn58CD1ZmKXDIruEOMD/39OUttDHex+tIj26f/BsVZNJzkR4zaD4Lg==
1216+
"@eppo/js-client-sdk-common@3.2.0":
1217+
version "3.2.0"
1218+
resolved "https://registry.yarnpkg.com/@eppo/js-client-sdk-common/-/js-client-sdk-common-3.2.0.tgz#e96895e3c74471f41892feb31d56c67f36c1b3e6"
1219+
integrity sha512-ua+4Mez7Ti/4XDPSKWbR8gg611UN9XnvModWAE7sjrHP60QNfmhvW6m+jXepDgQFRsybU0xXrddZQiVbDcCrUQ==
12201220
dependencies:
1221+
js-base64 "^3.7.7"
12211222
md5 "^2.3.0"
12221223
pino "^8.19.0"
12231224
semver "^7.5.4"
1224-
universal-base64 "^2.1.0"
12251225

12261226
"@eslint-community/eslint-utils@^4.2.0":
12271227
version "4.4.0"
@@ -5526,6 +5526,11 @@ joi@^17.2.1:
55265526
"@sideway/formula" "^3.0.1"
55275527
"@sideway/pinpoint" "^2.0.0"
55285528

5529+
js-base64@^3.7.7:
5530+
version "3.7.7"
5531+
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-3.7.7.tgz#e51b84bf78fbf5702b9541e2cb7bfcb893b43e79"
5532+
integrity sha512-7rCnleh0z2CkXhH67J8K1Ytz0b2Y+yxTPL+/KOJoa20hfnVQ/3/T6W/KflYI4bRHRagNeXeU2bkNGI3v1oS/lw==
5533+
55295534
js-sdsl@^4.1.4:
55305535
version "4.4.0"
55315536
resolved "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.4.0.tgz"
@@ -8256,11 +8261,6 @@ union-value@^1.0.0:
82568261
is-extendable "^0.1.1"
82578262
set-value "^2.0.1"
82588263

8259-
universal-base64@^2.1.0:
8260-
version "2.1.0"
8261-
resolved "https://registry.yarnpkg.com/universal-base64/-/universal-base64-2.1.0.tgz#511af92b3a07340fc2647036045aadb3bedcc320"
8262-
integrity sha512-WeOkACVnIXJZr/qlv7++Rl1zuZOHN96v2yS5oleUuv8eJOs5j9M5U3xQEIoWqn1OzIuIcgw0fswxWnUVGDfW6g==
8263-
82648264
universalify@^0.1.0:
82658265
version "0.1.2"
82668266
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66"

0 commit comments

Comments
 (0)