From 6c0a0dd27b4eecf905ef30b949f8918491c1f8cc Mon Sep 17 00:00:00 2001 From: Jan Kobersky Date: Thu, 12 Sep 2024 11:58:03 +0200 Subject: [PATCH] Fixed dev features for cordova and update docs --- docs/Troubleshooting.md | 4 ++-- gulpfile.js | 1 + .../cordova/src/internal/Utils.ts | 1 - src/debug/PowerAuthDebug.ts | 17 ++++++++++++----- src/internal/NativeWrapper.ts | 4 ++-- src/internal/Utils.ts | 1 - testapp-cordova/src/App.tsx | 3 +++ 7 files changed, 20 insertions(+), 11 deletions(-) diff --git a/docs/Troubleshooting.md b/docs/Troubleshooting.md index 03cb978..01c4737 100644 --- a/docs/Troubleshooting.md +++ b/docs/Troubleshooting.md @@ -16,12 +16,12 @@ PowerAuthDebug.traceNativeCodeCalls(true, true); ``` -The `PowerAuthDebug` class is effective only if global `__DEV__` constant is `true`. We don't want to log the sensitive information to the console in the production application. +The `PowerAuthDebug` class is effective only when `isEnabled` is `true`. We don't want to log the sensitive information to the console in the production application. ## Dumping native objects -If `__DEV__` mode is turned on, then you can dump information about all native objects allocated and used by PowerAuth Mobile JS SDK: +If `PowerAuthDebug.isEnabled` is turned on, then you can dump information about all native objects allocated and used by PowerAuth Mobile JS SDK: ```javascript // Dump all objects diff --git a/gulpfile.js b/gulpfile.js index e055268..a36ff7b 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -115,6 +115,7 @@ const tmpDir = ".build"; const copyCDVSourceFiles = () => gulp .src("src/**/**.ts", { base: ".", allowEmpty: true }) + .pipe(replace("__DEV__", "false")) // replace reaact-native __DEV__ with false by default .pipe(gulp.dest(CDV_tempDir)); const copyCDVPatchSourceFiles = () => diff --git a/other-platforms-support/cordova/src/internal/Utils.ts b/other-platforms-support/cordova/src/internal/Utils.ts index 365f25f..8b58d8f 100644 --- a/other-platforms-support/cordova/src/internal/Utils.ts +++ b/other-platforms-support/cordova/src/internal/Utils.ts @@ -16,7 +16,6 @@ export class Utils { - static isDev = false // TODO: set real value static platformOs = this.detectPlatform() // TODO: we should probably make this more robust diff --git a/src/debug/PowerAuthDebug.ts b/src/debug/PowerAuthDebug.ts index f94c308..39c409e 100644 --- a/src/debug/PowerAuthDebug.ts +++ b/src/debug/PowerAuthDebug.ts @@ -17,32 +17,39 @@ import { PowerAuthError } from "../index"; import { NativeWrapper } from "../internal/NativeWrapper"; import { NativeObjectRegister } from "./NativeObjectRegister"; -import { Utils } from "../internal/Utils"; /** * The `PowerAuthDebug` class provides a various functionality that can * help application develoepr with debugging the problem with React Native PowerAuth mobile SDK. */ export class PowerAuthDebug { + + /** + * If debug features are enabled. + * + * Initial value = `__DEV__` + */ + static isEnabled = __DEV__ + /** * Enable or disable detailed log with calls to native code. Be aware that this feature is - * effective only if global __DEV__ constant is `true`. + * effective only if `isEnabled` static property is `true`. * @param traceFailure If set to `true`, then SDK will print a detailed error if native call fails. * @param traceEachCall If set to `true`, then SDK will print a detailed information about each call to the native code. */ static traceNativeCodeCalls(traceFailure: boolean, traceEachCall: boolean = false) { - if (Utils.isDev) { + if (this.isEnabled) { NativeWrapper.setDebugFeatures(traceFailure, traceEachCall) } } /** * Function prints debug information about all native objects registered in native module. Note that the function - * is effective ony if native module is compiled in DEBUG mode and if global `__DEV__` constant is `true`. + * is effective ony if native module is compiled in DEBUG mode and if `isEnabled` static property is `true`. * @param instanceId If provided, then prints only objects that belongs to PowerAuth instance with given identifier. */ static async dumpNativeObjects(instanceId: string | undefined = undefined): Promise { - if (Utils.isDev) { + if (this.isEnabled) { if (instanceId) { console.log(`List of native objects associated with instance '${instanceId}' = [`) } else { diff --git a/src/internal/NativeWrapper.ts b/src/internal/NativeWrapper.ts index c5eefca..5fd75a2 100644 --- a/src/internal/NativeWrapper.ts +++ b/src/internal/NativeWrapper.ts @@ -181,12 +181,12 @@ export class NativeWrapper { } /** - * Enable or disable low level debug features. The __DEV__ variable must be true. + * Enable or disable low level debug features. The `PowerAuthDebug.isEnabled` variable must be true. * @param traceFail If true, then detailed log entry about failure will be printed to the console. * @param traceCall If true, then each call to native code will be printed with a detailed information. */ static setDebugFeatures(traceFail: boolean, traceCall: boolean) { - if (Utils.isDev) { + if (PowerAuthDebug.isEnabled) { if (traceCall || traceFail) { this.thisTrampoline = new DebugThisCall(traceCall, traceFail) this.staticTrampoline = new DebugStaticCall(traceCall, traceFail) diff --git a/src/internal/Utils.ts b/src/internal/Utils.ts index 871b7b4..acb7ad2 100644 --- a/src/internal/Utils.ts +++ b/src/internal/Utils.ts @@ -17,6 +17,5 @@ import { Platform } from 'react-native'; export class Utils { - static isDev = __DEV__; static platformOs = Platform.OS; } \ No newline at end of file diff --git a/testapp-cordova/src/App.tsx b/testapp-cordova/src/App.tsx index 3188e50..abc9b2f 100644 --- a/testapp-cordova/src/App.tsx +++ b/testapp-cordova/src/App.tsx @@ -24,6 +24,9 @@ function onDeviceReady() { // Cordova is now initialized. Have fun! + // enable debug + PowerAuthDebug.isEnabled = true; + const statusEl = document.getElementById('tests-status'); const progressEl = document.getElementById('tests-progress'); const messageEl = document.getElementById("test-message");