Skip to content

Commit

Permalink
Merge branch 'develop' into task/SDK-3413/remote_config
Browse files Browse the repository at this point in the history
  • Loading branch information
KambleSonam authored Jan 24, 2024
2 parents 579b2b7 + 1e34ba0 commit 0cdefcd
Show file tree
Hide file tree
Showing 14 changed files with 440 additions and 697 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/sw_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Build SW Webpush
on:
push:
branches:
- master
- develop
pull_request:
branches:
- master
- develop
types: [opened, synchronize, reopened]
jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- name: Use node.js version 10.x
uses: actions/[email protected]
with:
node-version: '10.x'
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install packages
run: yarn
- name: Build package
run: yarn run build_sw
36 changes: 36 additions & 0 deletions .github/workflows/sw_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Release sw_webpush.min.js to s3
on:
release:
types: [published]
jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- name: Use node.js version 10.x
uses: actions/[email protected]
with:
node-version: '10.x'
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install packages
run: yarn
- name: Build package
run: yarn run build_sw
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Copy file to S3
run: |
aws s3 cp sw_webpush.min.js s3://${{ secrets.S3_BUCKET_PATH }}
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Change Log
All notable changes to this project will be documented in this file.

## [1.6.10] - 17 Jan, 2023
- Fixes a bug related to Web Inbox rendering on mobile browser

## [1.6.9] - 6 Dec, 2023
- Adds public method markReadInboxMessagesForIds.
- Adds public method setLibrary to set the Flutter version.
- Fixes a bug related to Web Inbox scroll.
- Triggers an event to manage inline script errors related to Content Security Policy.

## [1.6.8] - 9 Nov, 2023
- Adds handling for email unsubscribe.

Expand Down
847 changes: 158 additions & 689 deletions clevertap.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion clevertap.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions clevertap.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "clevertap.js",
"scripts": {
"build": "rollup --config rollup.config.js",
"build_sw": "rollup --config sw_rollup.config.js",
"test": "eslint --fix test && jest",
"test:coverage": "rm -rf coverage && jest --coverage"
},
Expand Down
19 changes: 14 additions & 5 deletions src/modules/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,26 +200,29 @@ export default class ProfileHandler extends Array {
* Adds array or single value against a key/property in profile object
*/
_handleMultiValueAdd (propKey, propVal, command) {
// Initialize array
var array = []

// Check if globalProfileMap is null, initialize if needed
if ($ct.globalProfileMap == null) {
$ct.globalProfileMap = StorageManager.readFromLSorCookie(PR_COOKIE) || {}
}
// if the value to be set is either string or number

// Check if the value to be set is either string or number
if (typeof propVal === 'string' || typeof propVal === 'number') {
if ($ct.globalProfileMap.hasOwnProperty(propKey)) {
array = $ct.globalProfileMap[propKey]
array.push(typeof propVal === 'number' ? propVal : propVal.toLowerCase())
} else {
$ct.globalProfileMap[propKey] = propVal
}
// if propVal is an array
} else {
// Check if propVal is an array
if ($ct.globalProfileMap.hasOwnProperty(propKey)) {
array = Array.isArray($ct.globalProfileMap[propKey]) ? $ct.globalProfileMap[propKey] : [$ct.globalProfileMap[propKey]]
}
/**
* checks for case sensitive inputs and filters the same ones
*/

// Check for case-sensitive inputs and filter the same ones
for (var i = 0; i < propVal.length; i++) {
if (typeof propVal[i] === 'number' && !array.includes(propVal[i])) {
array.push(propVal[i])
Expand All @@ -231,9 +234,15 @@ export default class ProfileHandler extends Array {
console.error('Array supports only string or number type values')
}
}

// Update globalProfileMap with the array
$ct.globalProfileMap[propKey] = array
}

// Save to local storage or cookie
StorageManager.saveToLSorCookie(PR_COOKIE, $ct.globalProfileMap)

// Call the sendMultiValueData function
this.sendMultiValueData(propKey, propVal, command)
}

Expand Down
3 changes: 2 additions & 1 deletion src/modules/web-inbox/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ export const getInboxPosition = (e, inboxHeight, inboxWidth) => {
const selectorLeft = selectorRect.left + horizontalScroll
const selectorRight = selectorRect.right + horizontalScroll
const selectorTop = selectorRect.top + verticalScroll
const selectorBottom = selectorRect.bottom + verticalScroll
// const selectorBottom = selectorRect.bottom + verticalScroll
const selectorBottom = selectorRect.bottom
const selectorHeight = selectorRect.height
const selectorWidth = selectorRect.width
const selectorCenter = {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/web-inbox/inboxStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export const inboxContainerStyles = ({
margin-top: 16px;
}
@media only screen and (min-width: 420px) {
@media only screen and (min-width: 480px) {
#inbox {
width: var(--inbox-width, 392px);
height: var(--inbox-height, 546px);
Expand Down
10 changes: 10 additions & 0 deletions src/util/tr.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ const _tr = (msg, {
if (document.getElementById(divId) != null) {
return
}

$ct.campaignDivMap[campaignId] = divId
const isBanner = displayObj.layout === 2
const msgDiv = document.createElement('div')
Expand Down Expand Up @@ -501,6 +502,10 @@ const _tr = (msg, {
const ifrm = (iframe.contentWindow) ? iframe.contentWindow : (iframe.contentDocument.document) ? iframe.contentDocument.document : iframe.contentDocument
const doc = ifrm.document

// Dispatch event for popup box/banner close
const closeCampaign = new Event('CT_campaign_rendered')
document.dispatchEvent(closeCampaign)

doc.open()
doc.write(html)

Expand Down Expand Up @@ -720,6 +725,7 @@ const _tr = (msg, {
if (doCampHouseKeeping(targetingMsgJson) === false) {
return
}

const campaignId = targetingMsgJson.wzrk_id.split('_')[0]
$ct.campaignDivMap[campaignId] = 'intentPreview'
let legacy = false
Expand Down Expand Up @@ -812,6 +818,10 @@ const _tr = (msg, {
const ifrm = (iframe.contentWindow) ? iframe.contentWindow : (iframe.contentDocument.document) ? iframe.contentDocument.document : iframe.contentDocument
const doc = ifrm.document

// Dispatch event for interstitial/exit intent close
const closeCampaign = new Event('CT_campaign_rendered')
document.dispatchEvent(closeCampaign)

doc.open()
doc.write(html)
if (targetingMsgJson.display['custom-editor']) {
Expand Down
35 changes: 35 additions & 0 deletions sw_rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import resolve from '@rollup/plugin-node-resolve'
import babel from '@rollup/plugin-babel'
import replace from '@rollup/plugin-replace'
import { eslint } from 'rollup-plugin-eslint'
import { terser } from 'rollup-plugin-terser'
import { version } from './package.json'
import sourcemaps from 'rollup-plugin-sourcemaps'

export default {
input: 'sw_webpush.js',
output: [
{
name: 'sw_webpush',
file: 'sw_webpush.min.js',
format: 'umd',
plugins: [terser()]
}
],
plugins: [
resolve(),
sourcemaps(),
eslint({
fix: true,
throwOnError: true
}),
replace({
preventAssignment: true,
delimiters: ['', ''],
$$PACKAGE_VERSION$$: version
}),
babel({
babelHelpers: 'bundled'
})
]
}
136 changes: 136 additions & 0 deletions sw_webpush.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/* eslint-disable handle-callback-err */
/* eslint-disable no-use-before-define */
/* eslint-disable no-undef */
/**
* Author: Jashan Shewakramani
* Last updated: 27 June 2016
* Description: Service worker for handling chrome push notifications
*
* NOTES:
* -> "self" refers to the global ServiceWorker Object
* -> This script is registered to the browser from a.js
* -> We're only handling notification clicks; "delivered" is handled by NB
* -> Use Google's closure compiler on http://closure-compiler.appspot.com/ for minifying
*/

importScripts('https://d2r1yp2w7bby2u.cloudfront.net/js/localforage.min.js')
// var CACHE_VERSION = 3;
// var CURRENT_CACHES = {
// prefetch: 'prefetch-cache-v' + CACHE_VERSION
// };

if (typeof globalRedirectPath === 'undefined') {
// set up some variables we need gobally
var globalNotificationData
// global redirect path for backward compatibility
var globalRedirectPath // when showing thr url; we need to log to LC before opening up the deep link
}

self.addEventListener('install', function (event) {
// force this service worker to become the active service worker; removes any previous implementations or migrations
self.skipWaiting()
console.log('CT Service worker installed')
})

self.addEventListener('activate', function (event) {
console.log('CT Service worker activated')
})

self.addEventListener('push', function (event) {
console.log('Push event: ', event)
// get all the notification data
var notificationData = JSON.parse(event.data.text())
var title = notificationData.title
var notificationOptions = notificationData.notificationOptions
var data = notificationOptions.data
var key
if (typeof data !== 'undefined') {
key = data.wzrk_id
}
if (typeof key === 'undefined') {
key = title
}
localforage.setItem(key, event.data.text()).then(function (value) {
// console.log("persisted");
}).catch(function (err) {
// This code runs if there were any errors
console.log('Error in persisting')
})

// two global variables for backward compatibility
globalRedirectPath = notificationData.redirectPath
globalNotificationData = notificationData

var raiseNotificationViewedPath = notificationData.raiseNotificationViewedPath
if (typeof raiseNotificationViewedPath !== 'undefined') {
// raise notification viewed event
fetch(raiseNotificationViewedPath, { mode: 'no-cors' }) // ignore the response
}
event.waitUntil(self.registration.showNotification(title, notificationOptions))
})

function onClick (event, redirectPath, notificationData) {
var finalDeepLink = redirectPath
var silentRequest = true // are opening up a new window or sending a quiet get request from here?
if (event.action === 'action1') {
// button 1 was clicked
if (typeof notificationData.notificationOptions.actions[0].deepLink !== 'undefined') {
finalDeepLink += '&r=' + encodeURIComponent(notificationData.notificationOptions.actions[0].deepLink)
silentRequest = false
}
finalDeepLink += '&b=' + encodeURIComponent('button1')
} else if (event.action === 'action2') {
// the second button was clicked
if (typeof notificationData.notificationOptions.actions[1].deepLink !== 'undefined') {
finalDeepLink += '&r=' + encodeURIComponent(notificationData.notificationOptions.actions[1].deepLink)
silentRequest = false
}
finalDeepLink += '&b=' + encodeURIComponent('button2')
} else {
// general click
if (typeof notificationData.deepLink !== 'undefined') {
finalDeepLink += '&r=' + encodeURIComponent(notificationData.deepLink)
silentRequest = false
}

finalDeepLink += '&b=' + encodeURIComponent('button0')
}

if (silentRequest) {
fireSilentRequest(finalDeepLink)
} else {
clients.openWindow(finalDeepLink)
}
event.notification.close()
}

self.addEventListener('notificationclick', function (event) {
var notification = event.notification
var data = notification.data
var key
if (typeof data !== 'undefined' && data !== null) {
key = data.wzrk_id
}
if (typeof key === 'undefined') {
key = notification.title
}
var promise = localforage.getItem(key).then(function (value) {
var notificationData = JSON.parse(value)
var redirectPath = notificationData.redirectPath
onClick(event, redirectPath, notificationData)
}).catch(function (err) {
// This code runs if there were any errors
// onClick below for backward compatibility
onClick(event, globalRedirectPath, globalNotificationData)
console.log(err)
})
event.waitUntil(promise)
})

var fireSilentRequest = function (url) {
// add the silent parameter to the deeplink so that LC knows not to raise an error
url += '&s=true'

// use the fetch API to make a silent request (we don't care about the response here)
fetch(url, { mode: 'no-cors' })
}
1 change: 1 addition & 0 deletions sw_webpush.min.js

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

0 comments on commit 0cdefcd

Please sign in to comment.