@suprsend/web-sdk 0.1.28 → 0.1.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cdn_bundle.js +1 -1
- package/dist/cjs_bundle.js +1 -1
- package/package.json +1 -1
- package/serviceworker/serviceworker.js +5 -1
- package/src/index.js +1 -1
- package/src/user.js +39 -12
- package/src/utils.js +3 -2
- package/src/web_push.js +4 -5
package/package.json
CHANGED
|
@@ -63,7 +63,11 @@ function validate_notification(notification_obj) {
|
|
|
63
63
|
var validated_notification_obj = {};
|
|
64
64
|
for (var item in notification_obj) {
|
|
65
65
|
if (valid_notification_params.includes(item)) {
|
|
66
|
-
if (
|
|
66
|
+
if (
|
|
67
|
+
url_fields.includes(item) &&
|
|
68
|
+
notification_obj[item] &&
|
|
69
|
+
!notification_obj[item].startsWith("http")
|
|
70
|
+
) {
|
|
67
71
|
validated_notification_obj[
|
|
68
72
|
item
|
|
69
73
|
] = `${suprsend_config.imgkit_root}${notification_obj[item]}`;
|
package/src/index.js
CHANGED
|
@@ -122,7 +122,7 @@ class SuprSend {
|
|
|
122
122
|
!utils.is_internal_event(event) &&
|
|
123
123
|
utils.has_special_char(event)
|
|
124
124
|
) {
|
|
125
|
-
console.log("
|
|
125
|
+
console.log("SuprSend: key cannot start with $ or ss_");
|
|
126
126
|
return;
|
|
127
127
|
}
|
|
128
128
|
const super_props = utils.get_parsed_local_store_data(
|
package/src/user.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import utils from "./utils";
|
|
2
2
|
import config from "./config";
|
|
3
|
-
import { regex } from "./constants";
|
|
3
|
+
import { regex, constants } from "./constants";
|
|
4
4
|
import { parsePhoneNumber } from "libphonenumber-js";
|
|
5
5
|
|
|
6
6
|
class User {
|
|
@@ -18,6 +18,25 @@ class User {
|
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
_call_flush_immediately(properties) {
|
|
22
|
+
utils
|
|
23
|
+
.api(constants.api_events_route, {
|
|
24
|
+
env: config.env_key,
|
|
25
|
+
distinct_id: this.instance.distinct_id,
|
|
26
|
+
$insert_id: utils.uuid(),
|
|
27
|
+
$time: utils.epoch_milliseconds(),
|
|
28
|
+
...properties,
|
|
29
|
+
})
|
|
30
|
+
.then((res) => {
|
|
31
|
+
if (!res.ok) {
|
|
32
|
+
throw new Error("Error in Fetch");
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
.catch(() => {
|
|
36
|
+
this._call_indentity(properties);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
21
40
|
_allow_special_char_events = (key) => {
|
|
22
41
|
return (
|
|
23
42
|
key === "$email" ||
|
|
@@ -45,7 +64,7 @@ class User {
|
|
|
45
64
|
if (regex.email.test(email)) {
|
|
46
65
|
this.append(key, email);
|
|
47
66
|
} else {
|
|
48
|
-
console.log("
|
|
67
|
+
console.log("SuprSend: Provide valid Email ID");
|
|
49
68
|
}
|
|
50
69
|
}
|
|
51
70
|
|
|
@@ -55,10 +74,10 @@ class User {
|
|
|
55
74
|
if (mobile_number.isValid()) {
|
|
56
75
|
this.append(key, mobile);
|
|
57
76
|
} else {
|
|
58
|
-
console.log("
|
|
77
|
+
console.log("SuprSend: Provide valid Mobile number");
|
|
59
78
|
}
|
|
60
79
|
} catch (err) {
|
|
61
|
-
console.log("
|
|
80
|
+
console.log("SuprSend: Provide valid Mobile number");
|
|
62
81
|
}
|
|
63
82
|
}
|
|
64
83
|
|
|
@@ -92,11 +111,15 @@ class User {
|
|
|
92
111
|
}
|
|
93
112
|
}
|
|
94
113
|
|
|
95
|
-
remove(key, value) {
|
|
114
|
+
remove(key, value, config = {}) {
|
|
96
115
|
const allow_special_tags = this._allow_special_char_events(key);
|
|
97
116
|
const data = utils.format_props({ key, value, allow_special_tags });
|
|
98
117
|
if (!utils.is_empty(data)) {
|
|
99
|
-
|
|
118
|
+
if (config?.flush_immediately) {
|
|
119
|
+
this._call_flush_immediately({ $remove: data });
|
|
120
|
+
} else {
|
|
121
|
+
this._call_indentity({ $remove: data });
|
|
122
|
+
}
|
|
100
123
|
}
|
|
101
124
|
}
|
|
102
125
|
|
|
@@ -106,7 +129,7 @@ class User {
|
|
|
106
129
|
if (!utils.has_special_char(key)) {
|
|
107
130
|
formatted_data = [key];
|
|
108
131
|
} else {
|
|
109
|
-
console.log("
|
|
132
|
+
console.log("SuprSend: key cannot start with $ or ss_");
|
|
110
133
|
}
|
|
111
134
|
} else if (Array.isArray(key)) {
|
|
112
135
|
formatted_data = [];
|
|
@@ -154,11 +177,15 @@ class User {
|
|
|
154
177
|
}
|
|
155
178
|
|
|
156
179
|
remove_webpush(push = "") {
|
|
157
|
-
this.remove(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
180
|
+
this.remove(
|
|
181
|
+
{
|
|
182
|
+
$webpush: push,
|
|
183
|
+
$device_id: this.instance?.env_properties?.$device_id,
|
|
184
|
+
$pushvendor: "vapid",
|
|
185
|
+
},
|
|
186
|
+
null,
|
|
187
|
+
{ flush_immediately: true }
|
|
188
|
+
);
|
|
162
189
|
}
|
|
163
190
|
}
|
|
164
191
|
|
package/src/utils.js
CHANGED
|
@@ -208,7 +208,7 @@ function format_props({ key, value, allow_special_tags = false }) {
|
|
|
208
208
|
for (let item in key) {
|
|
209
209
|
if (key[item] !== undefined) {
|
|
210
210
|
if (!allow_special_tags && has_special_char(item)) {
|
|
211
|
-
console.log("
|
|
211
|
+
console.log("SuprSend: key cannot start with $ or ss_");
|
|
212
212
|
continue;
|
|
213
213
|
}
|
|
214
214
|
formatted_data[String(item)] = key[item];
|
|
@@ -216,7 +216,7 @@ function format_props({ key, value, allow_special_tags = false }) {
|
|
|
216
216
|
}
|
|
217
217
|
} else if (value != undefined) {
|
|
218
218
|
if (!allow_special_tags && has_special_char(String(key))) {
|
|
219
|
-
console.log("
|
|
219
|
+
console.log("SuprSend: key cannot start with $ or ss_");
|
|
220
220
|
return;
|
|
221
221
|
}
|
|
222
222
|
formatted_data = { [String(key)]: value };
|
|
@@ -280,4 +280,5 @@ export default {
|
|
|
280
280
|
is_empty,
|
|
281
281
|
bulk_call_api,
|
|
282
282
|
is_internal_event,
|
|
283
|
+
api,
|
|
283
284
|
};
|
package/src/web_push.js
CHANGED
|
@@ -21,11 +21,10 @@ class WebPush {
|
|
|
21
21
|
return navigator.serviceWorker
|
|
22
22
|
.register(`/${config.service_worker_file}`)
|
|
23
23
|
.then((registration) => {
|
|
24
|
-
console.log("Service worker successfully registered.");
|
|
25
24
|
this._subscribe_push(registration);
|
|
26
25
|
})
|
|
27
26
|
.catch((err) => {
|
|
28
|
-
console.error("Unable to register service worker.", err);
|
|
27
|
+
console.error("SuprSend: Unable to register service worker.", err);
|
|
29
28
|
});
|
|
30
29
|
};
|
|
31
30
|
|
|
@@ -66,7 +65,7 @@ class WebPush {
|
|
|
66
65
|
const subscription = await this._get_subscription();
|
|
67
66
|
if (!subscription) {
|
|
68
67
|
if (!config.vapid_key) {
|
|
69
|
-
console.log("Provide vapid key while calling init");
|
|
68
|
+
console.log("SuprSend: Provide vapid key while calling init");
|
|
70
69
|
return;
|
|
71
70
|
}
|
|
72
71
|
const applicationServerKey = utils.urlB64ToUint8Array(config.vapid_key);
|
|
@@ -76,7 +75,7 @@ class WebPush {
|
|
|
76
75
|
});
|
|
77
76
|
this.user.add_webpush(subscription);
|
|
78
77
|
} else {
|
|
79
|
-
|
|
78
|
+
// pass
|
|
80
79
|
}
|
|
81
80
|
}
|
|
82
81
|
};
|
|
@@ -98,7 +97,7 @@ class WebPush {
|
|
|
98
97
|
if (this._check_push_support()) {
|
|
99
98
|
this._subscribe_with_delay();
|
|
100
99
|
} else {
|
|
101
|
-
console.log("
|
|
100
|
+
console.log("SuprSend: Web Push isn't supported");
|
|
102
101
|
}
|
|
103
102
|
};
|
|
104
103
|
|