Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support non-ascii characters by upgrading common JS core #66

Merged
merged 4 commits into from
Jan 8, 2025

Conversation

aarsilv
Copy link
Contributor

@aarsilv aarsilv commented Jan 3, 2025

Eppo Internal:
🎟️ Ticket: FF-3769 - Update React Native SDK to use latest common JS module to support non-ascii characters
🗨️ Slack Thread: "...flag text encoding problem..."
👯 Related PR: js-sdk-common #187

Motivation and Context

SDKs need to be able to handle special, non-ASCII characters.

Description

We update our common module, which switches from using js-base64's btoaPolyfill() and atobPolyfill() to encode and decode respectively.

The former is designed only to handle ASCII characters and bytes (docs), while the latter is designed for strings and can handle all characters.

I've also added the shared test suite to our tests

How has this been tested?

@@ -72,4 +72,4 @@ lib/
.node-version
.python-version

test/data
src/__tests__/data
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Co-locating test data with tests

rm -rf $(testDataDir)
mkdir -p $(tempDir)
git clone -b ${branchName} --depth 1 --single-branch ${githubRepoLink} ${gitDataDir}
cp ${gitDataDir}rac-experiments-v3.json ${testDataDir}
cp -r ${gitDataDir}assignment-v2 ${testDataDir}
cp -r ${gitDataDir}ufc ${testDataDir}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating the test data to UFC

@@ -51,7 +51,7 @@
"registry": "https://registry.npmjs.org/"
},
"dependencies": {
"@eppo/js-client-sdk-common": "4.3.0",
"@eppo/js-client-sdk-common": "^4.7.1",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔧 Core of the change

@@ -105,7 +113,9 @@ describe('EppoReactNativeClient integration test', () => {
const mockConfigStore = td.object<EppoAsyncStorage>();
const mockLogger = td.object<IAssignmentLogger>();
td.when(mockConfigStore.get(flagKey)).thenReturn(null);
const client_instance = new EppoReactNativeClient(mockConfigStore);
const client_instance = new EppoReactNativeClient({
flagConfigurationStore: mockConfigStore,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signature of the core repository constructor has changed from an argument list to an options object

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mea culpa

@@ -227,3 +241,63 @@ describe('EppoReactNativeClient integration test', () => {
expect(EppoReactNativeClient.initialized).toBe(false);
});
});

describe('UFC Obfuscated Test Cases', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shared test cases!

@@ -0,0 +1,101 @@
import * as fs from 'fs';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is largely taken from the node repository. Future us should just export this common functionality in the common module as well.

@@ -59,13 +60,15 @@ export class EppoAsyncStorage
private environment: Environment | null = null;
private configFetchedAt: string | null = null;
private configPublishedAt: string | null = null;
private format: FormatEnum | null = null;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated common repository now has a format property for IConfigurationStore

@felipecsl
Copy link
Member

@aarsilv is this ready for review? still in draft mode

Copy link
Member

@felipecsl felipecsl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@@ -105,7 +113,9 @@ describe('EppoReactNativeClient integration test', () => {
const mockConfigStore = td.object<EppoAsyncStorage>();
const mockLogger = td.object<IAssignmentLogger>();
td.when(mockConfigStore.get(flagKey)).thenReturn(null);
const client_instance = new EppoReactNativeClient(mockConfigStore);
const client_instance = new EppoReactNativeClient({
flagConfigurationStore: mockConfigStore,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mea culpa

public static instance: EppoReactNativeClient = new EppoReactNativeClient({
flagConfigurationStore: asyncStorage,
isObfuscated: true,
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

much better without all those undefineds

@aarsilv aarsilv marked this pull request as ready for review January 6, 2025 02:48
@greghuels
Copy link
Contributor

@aarsilv I tested this out in RN 0.72 and it works.

Before
Screenshot 2025-01-06 at 6 57 52 AM

After
Screenshot 2025-01-06 at 6 57 02 AM

@aarsilv aarsilv merged commit 008c65a into main Jan 8, 2025
3 checks passed
@aarsilv aarsilv deleted the aaron/ff-3769/update-common-sdk branch January 8, 2025 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants