@@ -13879,6 +13879,26 @@ fn variant_pki_get_addr_error_rs_to_js<'a>(
1387913879 Ok(js_obj)
1388013880}
1388113881
13882+ // RemoveDeviceDataError
13883+
13884+ #[allow(dead_code)]
13885+ fn variant_remove_device_data_error_rs_to_js<'a>(
13886+ cx: &mut impl Context<'a>,
13887+ rs_obj: libparsec::RemoveDeviceDataError,
13888+ ) -> NeonResult<Handle<'a, JsObject>> {
13889+ let js_obj = cx.empty_object();
13890+ let js_display = JsString::try_new(cx, &rs_obj.to_string()).or_throw(cx)?;
13891+ js_obj.set(cx, "error", js_display)?;
13892+ match rs_obj {
13893+ libparsec::RemoveDeviceDataError::FailedToRemoveData { .. } => {
13894+ let js_tag =
13895+ JsString::try_new(cx, "RemoveDeviceDataErrorFailedToRemoveData").or_throw(cx)?;
13896+ js_obj.set(cx, "tag", js_tag)?;
13897+ }
13898+ }
13899+ Ok(js_obj)
13900+ }
13901+
1388213902// RemoveDeviceError
1388313903
1388413904#[allow(dead_code)]
@@ -25470,6 +25490,65 @@ fn pki_remove_local_pending(mut cx: FunctionContext) -> JsResult<JsPromise> {
2547025490 Ok(promise)
2547125491}
2547225492
25493+ // remove_device_data
25494+ fn remove_device_data(mut cx: FunctionContext) -> JsResult<JsPromise> {
25495+ crate::init_sentry();
25496+ let config = {
25497+ let js_val = cx.argument::<JsObject>(0)?;
25498+ struct_client_config_js_to_rs(&mut cx, js_val)?
25499+ };
25500+ let device_id = {
25501+ let js_val = cx.argument::<JsString>(1)?;
25502+ {
25503+ let custom_from_rs_string = |s: String| -> Result<libparsec::DeviceID, _> {
25504+ libparsec::DeviceID::from_hex(s.as_str()).map_err(|e| e.to_string())
25505+ };
25506+ match custom_from_rs_string(js_val.value(&mut cx)) {
25507+ Ok(val) => val,
25508+ Err(err) => return cx.throw_type_error(err),
25509+ }
25510+ }
25511+ };
25512+ let channel = cx.channel();
25513+ let (deferred, promise) = cx.promise();
25514+
25515+ // TODO: Promises are not cancellable in Javascript by default, should we add a custom cancel method ?
25516+ let _handle = crate::TOKIO_RUNTIME
25517+ .lock()
25518+ .expect("Mutex is poisoned")
25519+ .spawn(async move {
25520+ let ret = libparsec::remove_device_data(config, device_id).await;
25521+
25522+ deferred.settle_with(&channel, move |mut cx| {
25523+ let js_ret = match ret {
25524+ Ok(ok) => {
25525+ let js_obj = JsObject::new(&mut cx);
25526+ let js_tag = JsBoolean::new(&mut cx, true);
25527+ js_obj.set(&mut cx, "ok", js_tag)?;
25528+ let js_value = {
25529+ #[allow(clippy::let_unit_value)]
25530+ let _ = ok;
25531+ JsNull::new(&mut cx)
25532+ };
25533+ js_obj.set(&mut cx, "value", js_value)?;
25534+ js_obj
25535+ }
25536+ Err(err) => {
25537+ let js_obj = cx.empty_object();
25538+ let js_tag = JsBoolean::new(&mut cx, false);
25539+ js_obj.set(&mut cx, "ok", js_tag)?;
25540+ let js_err = variant_remove_device_data_error_rs_to_js(&mut cx, err)?;
25541+ js_obj.set(&mut cx, "error", js_err)?;
25542+ js_obj
25543+ }
25544+ };
25545+ Ok(js_ret)
25546+ });
25547+ });
25548+
25549+ Ok(promise)
25550+ }
25551+
2547325552// show_certificate_selection_dialog_windows_only
2547425553fn show_certificate_selection_dialog_windows_only(mut cx: FunctionContext) -> JsResult<JsPromise> {
2547525554 crate::init_sentry();
@@ -29902,6 +29981,7 @@ pub fn register_meths(cx: &mut ModuleContext) -> NeonResult<()> {
2990229981 cx.export_function("pkiEnrollmentInfo", pki_enrollment_info)?;
2990329982 cx.export_function("pkiEnrollmentSubmit", pki_enrollment_submit)?;
2990429983 cx.export_function("pkiRemoveLocalPending", pki_remove_local_pending)?;
29984+ cx.export_function("removeDeviceData", remove_device_data)?;
2990529985 cx.export_function(
2990629986 "showCertificateSelectionDialogWindowsOnly",
2990729987 show_certificate_selection_dialog_windows_only,
0 commit comments