fix: react native sync (#4405)

This commit is contained in:
Anshuman Pandey
2024-12-06 16:32:45 +05:30
committed by GitHub
parent a9983e1fe0
commit 97a66168c0
6 changed files with 16335 additions and 13117 deletions

View File

@@ -15,9 +15,9 @@
"@formbricks/react-native": "workspace:*",
"expo": "51.0.26",
"expo-status-bar": "1.12.1",
"react": "19.0.0-rc-ed15d500-20241110",
"react-dom": "19.0.0-rc-ed15d500-20241110",
"react-native": "0.74.4",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-native": "0.74.5",
"react-native-webview": "13.8.6"
},
"devDependencies": {

View File

@@ -19,6 +19,7 @@ export const symmetricEncrypt = (text: string, key: string) => {
const _key = Buffer.from(key, BUFFER_ENCODING);
const iv = crypto.randomBytes(IV_LENGTH);
// @ts-expect-error -- the package needs to be built
const cipher = crypto.createCipheriv(ALGORITHM, _key, iv);
let ciphered = cipher.update(text, INPUT_ENCODING, OUTPUT_ENCODING);
ciphered += cipher.final(OUTPUT_ENCODING);
@@ -37,6 +38,7 @@ export const symmetricDecrypt = (text: string, key: string) => {
const components = text.split(":");
const iv_from_ciphertext = Buffer.from(components.shift() || "", OUTPUT_ENCODING);
// @ts-expect-error -- the package needs to be built
const decipher = crypto.createDecipheriv(ALGORITHM, _key, iv_from_ciphertext);
let deciphered = decipher.update(components.join(":"), OUTPUT_ENCODING, INPUT_ENCODING);
deciphered += decipher.final(INPUT_ENCODING);
@@ -48,6 +50,7 @@ export const getHash = (key: string): string => createHash("sha256").update(key)
// create an aes128 encryption function
export const encryptAES128 = (encryptionKey: string, data: string): string => {
// @ts-expect-error -- the package needs to be built
const cipher = createCipheriv("aes-128-ecb", Buffer.from(encryptionKey, "base64"), "");
let encrypted = cipher.update(data, "utf-8", "hex");
encrypted += cipher.final("hex");
@@ -55,6 +58,7 @@ export const encryptAES128 = (encryptionKey: string, data: string): string => {
};
// create an aes128 decryption function
export const decryptAES128 = (encryptionKey: string, data: string): string => {
// @ts-expect-error -- the package needs to be built
const cipher = createDecipheriv("aes-128-ecb", Buffer.from(encryptionKey, "base64"), "");
let decrypted = cipher.update(data, "hex", "utf-8");
decrypted += cipher.final("utf-8");

View File

@@ -260,7 +260,7 @@ export const putFileToLocalStorage = async (
const uploadPath = `${rootDir}/${environmentId}/${accessType}/${fileName}`;
const buffer = Buffer.from(fileBuffer);
const buffer = Buffer.from(fileBuffer as unknown as WithImplicitCoercion<string>);
const bufferBytes = buffer.byteLength;
const maxSize = IS_FORMBRICKS_CLOUD
@@ -276,7 +276,7 @@ export const putFileToLocalStorage = async (
throw err;
}
await writeFile(uploadPath, buffer);
await writeFile(uploadPath, buffer as unknown as any);
} catch (err) {
throw err;
}

View File

@@ -1,6 +1,6 @@
{
"name": "@formbricks/react-native",
"version": "1.1.0",
"version": "1.2.0",
"license": "MIT",
"description": "Formbricks React Native SDK allows you to connect your app to Formbricks, display surveys and trigger events.",
"homepage": "https://formbricks.com",
@@ -45,7 +45,7 @@
"@formbricks/types": "workspace:*",
"@react-native-async-storage/async-storage": "1.23.1",
"@types/react": "18.3.11",
"react": "19.0.0-rc-ed15d500-20241110",
"react": "18.3.1",
"react-native": "0.74.5",
"terser": "5.31.3",
"vite": "5.4.8",

View File

@@ -52,17 +52,6 @@ export const initialize = async (
});
}
// if userId and attributes are available, set them in backend
let updatedAttributes: TAttributes | null = null;
if (c.userId && c.attributes) {
const res = await updateAttributes(c.apiHost, c.environmentId, c.userId, c.attributes);
if (!res.ok) {
return err(res.error) as unknown as Result<void, MissingFieldError | NetworkError | MissingPersonError>;
}
updatedAttributes = res.data;
}
let existingConfig: TJsRNConfig | undefined;
try {
existingConfig = appConfig.get();
@@ -114,6 +103,17 @@ export const initialize = async (
// todo: update attributes
// update attributes in config
// if userId and attributes are available, set them in backend
let updatedAttributes: TAttributes | null = null;
if (c.userId && c.attributes) {
const res = await updateAttributes(c.apiHost, c.environmentId, c.userId, c.attributes);
if (!res.ok) {
return err(res.error) as unknown as Result<void, MissingFieldError | NetworkError | MissingPersonError>;
}
updatedAttributes = res.data;
}
if (updatedAttributes && Object.keys(updatedAttributes).length > 0) {
appConfig.update({
environmentId: appConfig.get().environmentId,

29412
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff