Page MenuHomePhabricator

D11573.diff
No OneTemporary

D11573.diff

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
@@ -165,7 +165,13 @@
jsi::String userID,
jsi::String deviceID,
jsi::String accessToken) override;
+ virtual void innerSetCommServicesAuthMetadata(
+ std::string userID,
+ std::string deviceID,
+ std::string accessToken);
virtual jsi::Value getCommServicesAuthMetadata(jsi::Runtime &rt) override;
+ virtual jsi::Value clearCommServicesAuthMetadata(jsi::Runtime &rt) override;
+ virtual void innerClearCommServicesAuthMetadata();
virtual jsi::Value setCommServicesAccessToken(
jsi::Runtime &rt,
jsi::String accessToken) override;
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
@@ -1496,6 +1496,7 @@
taskType job = [this, promise]() {
std::string error;
try {
+ this->innerClearCommServicesAuthMetadata();
DatabaseManager::clearSensitiveData();
} catch (const std::exception &e) {
error = e.what();
@@ -1601,92 +1602,101 @@
rt,
[this, userIDStr, deviceIDStr, accessTokenStr](
jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
- taskType job =
- [this, promise, userIDStr, deviceIDStr, accessTokenStr]() {
- std::string error;
- try {
- CommSecureStore::set(CommSecureStore::userID, userIDStr);
- CommSecureStore::set(CommSecureStore::deviceID, deviceIDStr);
- CommSecureStore::set(
- CommSecureStore::commServicesAccessToken, accessTokenStr);
- CommServicesAuthMetadataEmitter::sendAuthMetadataToJS(
- accessTokenStr, userIDStr);
- } catch (const std::exception &e) {
- error = e.what();
- }
- this->jsInvoker_->invokeAsync([error, promise]() {
- if (error.size()) {
- promise->reject(error);
- } else {
- promise->resolve(jsi::Value::undefined());
- }
- });
- };
- GlobalDBSingleton::instance.scheduleOrRunCancellable(
- job, promise, this->jsInvoker_);
+ std::string error;
+ try {
+ this->innerSetCommServicesAuthMetadata(
+ userIDStr, deviceIDStr, accessTokenStr);
+ } catch (const std::exception &e) {
+ error = e.what();
+ }
+ this->jsInvoker_->invokeAsync([error, promise]() {
+ if (error.size()) {
+ promise->reject(error);
+ } else {
+ promise->resolve(jsi::Value::undefined());
+ }
+ });
});
}
+void CommCoreModule::innerSetCommServicesAuthMetadata(
+ std::string userID,
+ std::string deviceID,
+ std::string accessToken) {
+ CommSecureStore::set(CommSecureStore::userID, userID);
+ CommSecureStore::set(CommSecureStore::deviceID, deviceID);
+ CommSecureStore::set(CommSecureStore::commServicesAccessToken, accessToken);
+ CommServicesAuthMetadataEmitter::sendAuthMetadataToJS(accessToken, userID);
+}
+
jsi::Value CommCoreModule::getCommServicesAuthMetadata(jsi::Runtime &rt) {
return createPromiseAsJSIValue(
rt, [this](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
- taskType job = [this, &innerRt, promise]() {
- std::string error;
- std::string userID;
- std::string deviceID;
- std::string accessToken;
- try {
- folly::Optional<std::string> userIDOpt =
- CommSecureStore::get(CommSecureStore::userID);
- if (userIDOpt.hasValue()) {
- userID = userIDOpt.value();
- }
- folly::Optional<std::string> deviceIDOpt =
- CommSecureStore::get(CommSecureStore::deviceID);
- if (deviceIDOpt.hasValue()) {
- deviceID = deviceIDOpt.value();
- }
- folly::Optional<std::string> accessTokenOpt =
- CommSecureStore::get(CommSecureStore::commServicesAccessToken);
- if (accessTokenOpt.hasValue()) {
- accessToken = accessTokenOpt.value();
- }
- } catch (const std::exception &e) {
- error = e.what();
+ std::string error;
+ std::string userID;
+ std::string deviceID;
+ std::string accessToken;
+ try {
+ folly::Optional<std::string> userIDOpt =
+ CommSecureStore::get(CommSecureStore::userID);
+ if (userIDOpt.hasValue()) {
+ userID = userIDOpt.value();
}
- this->jsInvoker_->invokeAsync(
- [&innerRt, error, userID, deviceID, accessToken, promise]() {
- if (error.size()) {
- promise->reject(error);
- } else {
- auto authMetadata = jsi::Object(innerRt);
- if (!userID.empty()) {
- authMetadata.setProperty(
- innerRt,
- "userID",
- jsi::String::createFromUtf8(innerRt, userID));
- }
- if (!deviceID.empty()) {
- authMetadata.setProperty(
- innerRt,
- "deviceID",
- jsi::String::createFromUtf8(innerRt, deviceID));
- }
- if (!accessToken.empty()) {
- authMetadata.setProperty(
- innerRt,
- "accessToken",
- jsi::String::createFromUtf8(innerRt, accessToken));
- }
- promise->resolve(std::move(authMetadata));
+ folly::Optional<std::string> deviceIDOpt =
+ CommSecureStore::get(CommSecureStore::deviceID);
+ if (deviceIDOpt.hasValue()) {
+ deviceID = deviceIDOpt.value();
+ }
+ folly::Optional<std::string> accessTokenOpt =
+ CommSecureStore::get(CommSecureStore::commServicesAccessToken);
+ if (accessTokenOpt.hasValue()) {
+ accessToken = accessTokenOpt.value();
+ }
+ } catch (const std::exception &e) {
+ error = e.what();
+ }
+ this->jsInvoker_->invokeAsync(
+ [&innerRt, error, userID, deviceID, accessToken, promise]() {
+ if (error.size()) {
+ promise->reject(error);
+ } else {
+ auto authMetadata = jsi::Object(innerRt);
+ if (!userID.empty()) {
+ authMetadata.setProperty(
+ innerRt,
+ "userID",
+ jsi::String::createFromUtf8(innerRt, userID));
}
- });
- };
- GlobalDBSingleton::instance.scheduleOrRunCancellable(
- job, promise, this->jsInvoker_);
+ if (!deviceID.empty()) {
+ authMetadata.setProperty(
+ innerRt,
+ "deviceID",
+ jsi::String::createFromUtf8(innerRt, deviceID));
+ }
+ if (!accessToken.empty()) {
+ authMetadata.setProperty(
+ innerRt,
+ "accessToken",
+ jsi::String::createFromUtf8(innerRt, accessToken));
+ }
+ promise->resolve(std::move(authMetadata));
+ }
+ });
});
}
+jsi::Value CommCoreModule::clearCommServicesAuthMetadata(jsi::Runtime &rt) {
+ return this->setCommServicesAuthMetadata(
+ rt,
+ jsi::String::createFromUtf8(rt, ""),
+ jsi::String::createFromUtf8(rt, ""),
+ jsi::String::createFromUtf8(rt, ""));
+}
+
+void CommCoreModule::innerClearCommServicesAuthMetadata() {
+ return this->innerSetCommServicesAuthMetadata("", "", "");
+}
+
jsi::Value CommCoreModule::setCommServicesAccessToken(
jsi::Runtime &rt,
jsi::String accessToken) {
@@ -1695,47 +1705,39 @@
rt,
[this, accessTokenStr](
jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
- taskType job = [this, promise, accessTokenStr]() {
- std::string error;
- try {
- CommSecureStore::set(
- CommSecureStore::commServicesAccessToken, accessTokenStr);
- } catch (const std::exception &e) {
- error = e.what();
+ std::string error;
+ try {
+ CommSecureStore::set(
+ CommSecureStore::commServicesAccessToken, accessTokenStr);
+ } catch (const std::exception &e) {
+ error = e.what();
+ }
+ this->jsInvoker_->invokeAsync([error, promise]() {
+ if (error.size()) {
+ promise->reject(error);
+ } else {
+ promise->resolve(jsi::Value::undefined());
}
- this->jsInvoker_->invokeAsync([error, promise]() {
- if (error.size()) {
- promise->reject(error);
- } else {
- promise->resolve(jsi::Value::undefined());
- }
- });
- };
- GlobalDBSingleton::instance.scheduleOrRunCancellable(
- job, promise, this->jsInvoker_);
+ });
});
}
jsi::Value CommCoreModule::clearCommServicesAccessToken(jsi::Runtime &rt) {
return createPromiseAsJSIValue(
rt, [this](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
- taskType job = [this, promise]() {
- std::string error;
- try {
- CommSecureStore::set(CommSecureStore::commServicesAccessToken, "");
- } catch (const std::exception &e) {
- error = e.what();
+ std::string error;
+ try {
+ CommSecureStore::set(CommSecureStore::commServicesAccessToken, "");
+ } catch (const std::exception &e) {
+ error = e.what();
+ }
+ this->jsInvoker_->invokeAsync([error, promise]() {
+ if (error.size()) {
+ promise->reject(error);
+ } else {
+ promise->resolve(jsi::Value::undefined());
}
- this->jsInvoker_->invokeAsync([error, promise]() {
- if (error.size()) {
- promise->reject(error);
- } else {
- promise->resolve(jsi::Value::undefined());
- }
- });
- };
- GlobalDBSingleton::instance.scheduleOrRunCancellable(
- job, promise, this->jsInvoker_);
+ });
});
}
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
@@ -161,6 +161,9 @@
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getCommServicesAuthMetadata(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->getCommServicesAuthMetadata(rt);
}
+static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_clearCommServicesAuthMetadata(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
+ return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->clearCommServicesAuthMetadata(rt);
+}
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setCommServicesAccessToken(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->setCommServicesAccessToken(rt, args[0].asString(rt));
}
@@ -238,6 +241,7 @@
methodMap_["generateRandomString"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_generateRandomString};
methodMap_["setCommServicesAuthMetadata"] = MethodMetadata {3, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setCommServicesAuthMetadata};
methodMap_["getCommServicesAuthMetadata"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getCommServicesAuthMetadata};
+ methodMap_["clearCommServicesAuthMetadata"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_clearCommServicesAuthMetadata};
methodMap_["setCommServicesAccessToken"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setCommServicesAccessToken};
methodMap_["clearCommServicesAccessToken"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_clearCommServicesAccessToken};
methodMap_["startBackupHandler"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_startBackupHandler};
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
@@ -68,6 +68,7 @@
virtual jsi::Value generateRandomString(jsi::Runtime &rt, double size) = 0;
virtual jsi::Value setCommServicesAuthMetadata(jsi::Runtime &rt, jsi::String userID, jsi::String deviceID, jsi::String accessToken) = 0;
virtual jsi::Value getCommServicesAuthMetadata(jsi::Runtime &rt) = 0;
+ virtual jsi::Value clearCommServicesAuthMetadata(jsi::Runtime &rt) = 0;
virtual jsi::Value setCommServicesAccessToken(jsi::Runtime &rt, jsi::String accessToken) = 0;
virtual jsi::Value clearCommServicesAccessToken(jsi::Runtime &rt) = 0;
virtual void startBackupHandler(jsi::Runtime &rt) = 0;
@@ -481,6 +482,14 @@
return bridging::callFromJs<jsi::Value>(
rt, &T::getCommServicesAuthMetadata, jsInvoker_, instance_);
}
+ jsi::Value clearCommServicesAuthMetadata(jsi::Runtime &rt) override {
+ static_assert(
+ bridging::getParameterCount(&T::clearCommServicesAuthMetadata) == 1,
+ "Expected clearCommServicesAuthMetadata(...) to have 1 parameters");
+
+ return bridging::callFromJs<jsi::Value>(
+ rt, &T::clearCommServicesAuthMetadata, jsInvoker_, instance_);
+ }
jsi::Value setCommServicesAccessToken(jsi::Runtime &rt, jsi::String accessToken) override {
static_assert(
bridging::getParameterCount(&T::setCommServicesAccessToken) == 2,
diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js
--- a/native/schema/CommCoreModuleSchema.js
+++ b/native/schema/CommCoreModuleSchema.js
@@ -139,6 +139,7 @@
accessToken: string,
) => Promise<void>;
+getCommServicesAuthMetadata: () => Promise<CommServicesAuthMetadata>;
+ +clearCommServicesAuthMetadata: () => Promise<void>;
+setCommServicesAccessToken: (accessToken: string) => Promise<void>;
+clearCommServicesAccessToken: () => Promise<void>;
+startBackupHandler: () => void;

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 6:24 PM (21 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2576950
Default Alt Text
D11573.diff (14 KB)

Event Timeline