@suprsend/web-sdk 0.1.26 → 0.1.27

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.
@@ -0,0 +1 @@
1
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suprsend/web-sdk",
3
- "version": "0.1.26",
3
+ "version": "0.1.27",
4
4
  "description": "This is sdk used to integrate suprsend functionality in javascript applications",
5
5
  "main": "dist/cjs_bundle.js",
6
6
  "scripts": {
@@ -23,13 +23,13 @@
23
23
  "access": "public"
24
24
  },
25
25
  "devDependencies": {
26
- "@babel/core": "^7.15.0",
27
- "@babel/preset-env": "^7.15.0",
28
- "babel-loader": "^8.2.2",
26
+ "@babel/core": "^7.18.5",
27
+ "@babel/preset-env": "^7.18.2",
28
+ "babel-loader": "^8.2.5",
29
29
  "webpack": "^5.51.1",
30
30
  "webpack-cli": "^4.8.0"
31
31
  },
32
32
  "dependencies": {
33
- "libphonenumber-js": "^1.9.43"
33
+ "libphonenumber-js": "^1.10.7"
34
34
  }
35
35
  }
package/src/constants.js CHANGED
@@ -46,3 +46,5 @@ export const os_useragent_map = {
46
46
  Android: "Android",
47
47
  Linux: "Linux",
48
48
  };
49
+
50
+ export const regex = { email: /\S+@\S+\.\S+/ };
package/src/index.js CHANGED
@@ -15,7 +15,7 @@ class SuprSend {
15
15
  var distinct_id = utils.get_cookie(constants.distinct_id);
16
16
  if (!suprSendInstance) {
17
17
  suprSendInstance = {};
18
- this.setCustomConfig(config_keys);
18
+ this._set_custom_config(config_keys);
19
19
  }
20
20
  if (!distinct_id) {
21
21
  distinct_id = utils.uuid();
@@ -25,7 +25,7 @@ class SuprSend {
25
25
  this.user = new User(suprSendInstance);
26
26
  this.web_push = new WebPush(suprSendInstance);
27
27
  this.web_push.update_subscription();
28
- SuprSend.setEnvProperties();
28
+ SuprSend._set_env_properties();
29
29
  if (!initialisedAt) {
30
30
  utils.bulk_call_api();
31
31
  this.track(internal_events.app_launched);
@@ -33,7 +33,7 @@ class SuprSend {
33
33
  initialisedAt = new Date();
34
34
  }
35
35
 
36
- static setEnvProperties() {
36
+ static _set_env_properties() {
37
37
  let device_id = utils.get_local_storage_item(constants.device_id_key);
38
38
  if (!device_id) {
39
39
  device_id = utils.uuid();
@@ -49,7 +49,7 @@ class SuprSend {
49
49
  };
50
50
  }
51
51
 
52
- setCustomConfigProperty(key, value = "", mandatory = false) {
52
+ _set_custom_config_property(key, value = "", mandatory = false) {
53
53
  if (value) {
54
54
  config[key] = value;
55
55
  } else {
@@ -59,12 +59,16 @@ class SuprSend {
59
59
  }
60
60
  }
61
61
 
62
- setCustomConfig(config_keys) {
63
- this.setCustomConfigProperty("env_key", config_keys.env, true);
64
- this.setCustomConfigProperty("signing_key", config_keys.signing_key, true);
65
- this.setCustomConfigProperty("api_url", config_keys?.api_url);
66
- this.setCustomConfigProperty("vapid_key", config_keys?.vapid_key);
67
- this.setCustomConfigProperty(
62
+ _set_custom_config(config_keys) {
63
+ this._set_custom_config_property("env_key", config_keys.env, true);
64
+ this._set_custom_config_property(
65
+ "signing_key",
66
+ config_keys.signing_key,
67
+ true
68
+ );
69
+ this._set_custom_config_property("api_url", config_keys?.api_url);
70
+ this._set_custom_config_property("vapid_key", config_keys?.vapid_key);
71
+ this._set_custom_config_property(
68
72
  "service_worker_file",
69
73
  config_keys?.sw_file_name
70
74
  );
@@ -156,7 +160,7 @@ class SuprSend {
156
160
  utils.remove_local_storage_item(constants.super_properties_key);
157
161
  this.user = new User(suprSendInstance);
158
162
  this.web_push = new WebPush(suprSendInstance);
159
- SuprSend.setEnvProperties();
163
+ SuprSend._set_env_properties();
160
164
  }
161
165
  }
162
166
 
package/src/user.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import utils from "./utils";
2
2
  import config from "./config";
3
+ import { regex } from "./constants";
3
4
  import { parsePhoneNumber } from "libphonenumber-js";
4
5
 
5
6
  class User {
@@ -40,6 +41,14 @@ class User {
40
41
  return obj;
41
42
  }
42
43
 
44
+ _validate_email_and_send(key, email) {
45
+ if (regex.email.test(email)) {
46
+ this.append(key, email);
47
+ } else {
48
+ console.log("Suprsend: Provide valid Email ID");
49
+ }
50
+ }
51
+
43
52
  _validate_mobile_and_send(key, mobile) {
44
53
  try {
45
54
  const mobile_number = parsePhoneNumber(mobile);
@@ -113,7 +122,7 @@ class User {
113
122
  }
114
123
 
115
124
  add_email(email = "") {
116
- this.append("$email", email);
125
+ this._validate_email_and_send("$email", email);
117
126
  }
118
127
 
119
128
  remove_email(email = "") {