Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removing enable api testing #338

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
228 changes: 197 additions & 31 deletions clevertap.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion clevertap.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion clevertap.min.js

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion src/clevertap.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { hasWebInboxSettingsInLS, checkAndRegisterWebInboxElements, initializeWe
import { Variable } from './modules/variables/variable'
import VariableStore from './modules/variables/variableStore'
import { checkBuilder, addAntiFlicker } from './modules/visualBuilder/pageBuilder'
import { setServerKey } from './modules/webPushPrompt/prompt'
import { processSoftPrompt, setServerKey } from './modules/webPushPrompt/prompt'

export default class CleverTap {
#logger
Expand Down Expand Up @@ -548,7 +548,13 @@ export default class CleverTap {
}
api.enableWebPush = (enabled, applicationServerKey) => {
setServerKey(applicationServerKey)
StorageManager.saveToLSorCookie('applicationServerKeyReceived', true)
this.notifications._enableWebPush(enabled, applicationServerKey)
const isWebPushConfigPresent = StorageManager.readFromLSorCookie('webPushConfigResponseReceived')
const isNotificationPushCalled = StorageManager.readFromLSorCookie('notificationPushCalled')
if (isWebPushConfigPresent && isNotificationPushCalled) {
processSoftPrompt()
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider adding error handling for storage operations.

Storage operations could fail in private browsing mode or when storage is full. Consider wrapping the storage operations in try-catch blocks.

-      StorageManager.saveToLSorCookie('applicationServerKeyReceived', true)
-      this.notifications._enableWebPush(enabled, applicationServerKey)
-      const isWebPushConfigPresent = StorageManager.readFromLSorCookie('webPushConfigResponseReceived')
-      const isNotificationPushCalled = StorageManager.readFromLSorCookie('notificationPushCalled')
-      if (isWebPushConfigPresent && isNotificationPushCalled) {
-        processSoftPrompt()
-      }
+      try {
+        StorageManager.saveToLSorCookie('applicationServerKeyReceived', true)
+        this.notifications._enableWebPush(enabled, applicationServerKey)
+        const isWebPushConfigPresent = StorageManager.readFromLSorCookie('webPushConfigResponseReceived')
+        const isNotificationPushCalled = StorageManager.readFromLSorCookie('notificationPushCalled')
+        if (isWebPushConfigPresent && isNotificationPushCalled) {
+          processSoftPrompt()
+        }
+      } catch (error) {
+        logger.error('Failed to process web push setup:', error)
+        // Fallback: Enable web push without soft prompt
+        this.notifications._enableWebPush(enabled, applicationServerKey)
+      }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
StorageManager.saveToLSorCookie('applicationServerKeyReceived', true)
this.notifications._enableWebPush(enabled, applicationServerKey)
const isWebPushConfigPresent = StorageManager.readFromLSorCookie('webPushConfigResponseReceived')
const isNotificationPushCalled = StorageManager.readFromLSorCookie('notificationPushCalled')
if (isWebPushConfigPresent && isNotificationPushCalled) {
processSoftPrompt()
}
try {
StorageManager.saveToLSorCookie('applicationServerKeyReceived', true)
this.notifications._enableWebPush(enabled, applicationServerKey)
const isWebPushConfigPresent = StorageManager.readFromLSorCookie('webPushConfigResponseReceived')
const isNotificationPushCalled = StorageManager.readFromLSorCookie('notificationPushCalled')
if (isWebPushConfigPresent && isNotificationPushCalled) {
processSoftPrompt()
}
} catch (error) {
logger.error('Failed to process web push setup:', error)
// Fallback: Enable web push without soft prompt
this.notifications._enableWebPush(enabled, applicationServerKey)
}

}
api.tr = (msg) => {
_tr(msg, {
Expand Down
Loading
Loading