diff --git a/native/cpp/CommonCpp/NativeModules/CommCoreModule.h b/native/cpp/CommonCpp/NativeModules/CommCoreModule.h --- a/native/cpp/CommonCpp/NativeModules/CommCoreModule.h +++ b/native/cpp/CommonCpp/NativeModules/CommCoreModule.h @@ -106,6 +106,16 @@ jsi::Runtime &rt, jsi::String accessToken) override; virtual jsi::Value clearCommServicesAccessToken(jsi::Runtime &rt) override; + virtual jsi::Value createNewBackup( + jsi::Runtime &rt, + jsi::String backupSecret, + jsi::String userData) override; + virtual jsi::Value restoreBackup( + jsi::Runtime &rt, + jsi::String backupID, + jsi::String backupSecret, + jsi::String encryptedUserKeys, + jsi::String encryptedUserData) override; public: CommCoreModule(std::shared_ptr jsInvoker); diff --git a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp --- a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp +++ b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp @@ -1055,4 +1055,38 @@ }); } +jsi::Value CommCoreModule::createNewBackup( + jsi::Runtime &rt, + jsi::String backupSecret, + jsi::String userData) { + std::string backupSecretStr = backupSecret.utf8(rt); + std::string userDataStr = userData.utf8(rt); + return createPromiseAsJSIValue( + rt, [=](jsi::Runtime &innerRt, std::shared_ptr promise) { + this->jsInvoker_->invokeAsync([=, &innerRt]() { + promise->resolve( + jsi::String::createFromUtf8(innerRt, std::string(""))); + }); + }); +} + +jsi::Value CommCoreModule::restoreBackup( + jsi::Runtime &rt, + jsi::String backupID, + jsi::String backupSecret, + jsi::String encryptedUserKeys, + jsi::String encryptedUserData) { + std::string backupIDStr = backupID.utf8(rt); + std::string backupSecretStr = backupSecret.utf8(rt); + std::string encryptedUserKeysStr = encryptedUserKeys.utf8(rt); + std::string encryptedUserDataStr = encryptedUserData.utf8(rt); + return createPromiseAsJSIValue( + rt, [=](jsi::Runtime &innerRt, std::shared_ptr promise) { + this->jsInvoker_->invokeAsync([=, &innerRt]() { + promise->resolve( + jsi::String::createFromUtf8(innerRt, std::string(""))); + }); + }); +} + } // namespace comm diff --git a/native/cpp/CommonCpp/_generated/commJSI-generated.cpp b/native/cpp/CommonCpp/_generated/commJSI-generated.cpp --- a/native/cpp/CommonCpp/_generated/commJSI-generated.cpp +++ b/native/cpp/CommonCpp/_generated/commJSI-generated.cpp @@ -128,6 +128,12 @@ static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_clearCommServicesAccessToken(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { return static_cast(&turboModule)->clearCommServicesAccessToken(rt); } +static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_createNewBackup(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + return static_cast(&turboModule)->createNewBackup(rt, args[0].asString(rt), args[1].asString(rt)); +} +static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_restoreBackup(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + return static_cast(&turboModule)->restoreBackup(rt, args[0].asString(rt), args[1].asString(rt), args[2].asString(rt), args[3].asString(rt)); +} CommCoreModuleSchemaCxxSpecJSI::CommCoreModuleSchemaCxxSpecJSI(std::shared_ptr jsInvoker) : TurboModule("CommTurboModule", jsInvoker) { @@ -168,6 +174,8 @@ methodMap_["getCommServicesAuthMetadata"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getCommServicesAuthMetadata}; methodMap_["setCommServicesAccessToken"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setCommServicesAccessToken}; methodMap_["clearCommServicesAccessToken"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_clearCommServicesAccessToken}; + methodMap_["createNewBackup"] = MethodMetadata {2, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_createNewBackup}; + methodMap_["restoreBackup"] = MethodMetadata {4, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_restoreBackup}; } diff --git a/native/cpp/CommonCpp/_generated/commJSI.h b/native/cpp/CommonCpp/_generated/commJSI.h --- a/native/cpp/CommonCpp/_generated/commJSI.h +++ b/native/cpp/CommonCpp/_generated/commJSI.h @@ -57,6 +57,8 @@ virtual jsi::Value getCommServicesAuthMetadata(jsi::Runtime &rt) = 0; virtual jsi::Value setCommServicesAccessToken(jsi::Runtime &rt, jsi::String accessToken) = 0; virtual jsi::Value clearCommServicesAccessToken(jsi::Runtime &rt) = 0; + virtual jsi::Value createNewBackup(jsi::Runtime &rt, jsi::String backupSecret, jsi::String userData) = 0; + virtual jsi::Value restoreBackup(jsi::Runtime &rt, jsi::String backupID, jsi::String backupSecret, jsi::String encryptedUserKeys, jsi::String encryptedUserData) = 0; }; @@ -374,6 +376,22 @@ return bridging::callFromJs( rt, &T::clearCommServicesAccessToken, jsInvoker_, instance_); } + jsi::Value createNewBackup(jsi::Runtime &rt, jsi::String backupSecret, jsi::String userData) override { + static_assert( + bridging::getParameterCount(&T::createNewBackup) == 3, + "Expected createNewBackup(...) to have 3 parameters"); + + return bridging::callFromJs( + rt, &T::createNewBackup, jsInvoker_, instance_, std::move(backupSecret), std::move(userData)); + } + jsi::Value restoreBackup(jsi::Runtime &rt, jsi::String backupID, jsi::String backupSecret, jsi::String encryptedUserKeys, jsi::String encryptedUserData) override { + static_assert( + bridging::getParameterCount(&T::restoreBackup) == 5, + "Expected restoreBackup(...) to have 5 parameters"); + + return bridging::callFromJs( + rt, &T::restoreBackup, jsInvoker_, instance_, std::move(backupID), std::move(backupSecret), std::move(encryptedUserKeys), std::move(encryptedUserData)); + } private: T *instance_; diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js --- a/native/schema/CommCoreModuleSchema.js +++ b/native/schema/CommCoreModuleSchema.js @@ -108,6 +108,13 @@ +getCommServicesAuthMetadata: () => Promise; +setCommServicesAccessToken: (accessToken: string) => Promise; +clearCommServicesAccessToken: () => Promise; + +createNewBackup: (backupSecret: string, userData: string) => Promise; + +restoreBackup: ( + backupID: string, + backupSecret: string, + encryptedUserKeys: string, + encryptedUserData: string, + ) => Promise; } export interface CoreModuleSpec extends Spec {