@suprsend/web-sdk 0.1.28 → 0.1.29

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suprsend/web-sdk",
3
- "version": "0.1.28",
3
+ "version": "0.1.29",
4
4
  "description": "This is sdk used to integrate suprsend functionality in javascript applications",
5
5
  "main": "dist/cjs_bundle.js",
6
6
  "scripts": {
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" ||
@@ -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
- this._call_indentity({ $remove: data });
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
 
@@ -154,11 +177,15 @@ class User {
154
177
  }
155
178
 
156
179
  remove_webpush(push = "") {
157
- this.remove({
158
- $webpush: push,
159
- $device_id: this.instance?.env_properties?.$device_id,
160
- $pushvendor: "vapid",
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
@@ -280,4 +280,5 @@ export default {
280
280
  is_empty,
281
281
  bulk_call_api,
282
282
  is_internal_event,
283
+ api,
283
284
  };