@suprsend/node-sdk 1.2.0 → 1.4.0
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/README.md +1 -1
- package/dist/constants.js +2 -2
- package/dist/event.js +15 -29
- package/dist/events_bulk.js +13 -27
- package/dist/index.js +4 -6
- package/dist/request_json/list_broadcast.json +19 -0
- package/dist/subscriber.js +30 -92
- package/dist/subscriber_helper.js +43 -76
- package/dist/{subscribers_list.js → subscriber_list.js} +94 -61
- package/dist/subscribers_bulk.js +35 -63
- package/dist/workflow.js +15 -30
- package/dist/workflows_bulk.js +13 -28
- package/package.json +1 -1
- package/src/constants.js +2 -2
- package/src/event.js +10 -20
- package/src/events_bulk.js +11 -20
- package/src/index.js +3 -8
- package/src/request_json/list_broadcast.json +19 -0
- package/src/subscriber.js +27 -63
- package/src/subscriber_helper.js +36 -77
- package/src/{subscribers_list.js → subscriber_list.js} +53 -53
- package/src/subscribers_bulk.js +15 -28
- package/src/workflow.js +10 -20
- package/src/workflows_bulk.js +11 -21
package/dist/workflow.js
CHANGED
|
@@ -106,18 +106,7 @@ var _WorkflowTrigger = /*#__PURE__*/function () {
|
|
|
106
106
|
(0, _createClass2["default"])(_WorkflowTrigger, [{
|
|
107
107
|
key: "_get_url",
|
|
108
108
|
value: function _get_url() {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (this.config.include_signature_param) {
|
|
112
|
-
if (this.config.auth_enabled) {
|
|
113
|
-
url_template = url_template + "?verify=true";
|
|
114
|
-
} else {
|
|
115
|
-
url_template = url_template + "?verify=false";
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
var url_formatted = "".concat(this.config.base_url).concat(this.config.workspace_key).concat(url_template);
|
|
120
|
-
return url_formatted;
|
|
109
|
+
return "".concat(this.config.base_url).concat(this.config.workspace_key, "/trigger/");
|
|
121
110
|
}
|
|
122
111
|
}, {
|
|
123
112
|
key: "_get_headers",
|
|
@@ -151,24 +140,20 @@ var _WorkflowTrigger = /*#__PURE__*/function () {
|
|
|
151
140
|
case 0:
|
|
152
141
|
headers = this._get_headers();
|
|
153
142
|
content_text = JSON.stringify(workflow_body);
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
_context.prev = 3;
|
|
161
|
-
_context.next = 6;
|
|
143
|
+
signature = (0, _signature["default"])(this.url, "POST", content_text, headers, this.config.workspace_secret);
|
|
144
|
+
headers["Authorization"] = "".concat(this.config.workspace_key, ":").concat(signature);
|
|
145
|
+
_context.prev = 4;
|
|
146
|
+
_context.next = 7;
|
|
162
147
|
return _axios["default"].post(this.url, content_text, {
|
|
163
148
|
headers: headers
|
|
164
149
|
});
|
|
165
150
|
|
|
166
|
-
case
|
|
151
|
+
case 7:
|
|
167
152
|
response = _context.sent;
|
|
168
153
|
ok_response = Math.floor(response.status / 100) == 2;
|
|
169
154
|
|
|
170
155
|
if (!ok_response) {
|
|
171
|
-
_context.next =
|
|
156
|
+
_context.next = 13;
|
|
172
157
|
break;
|
|
173
158
|
}
|
|
174
159
|
|
|
@@ -179,7 +164,7 @@ var _WorkflowTrigger = /*#__PURE__*/function () {
|
|
|
179
164
|
message: response.statusText
|
|
180
165
|
});
|
|
181
166
|
|
|
182
|
-
case
|
|
167
|
+
case 13:
|
|
183
168
|
return _context.abrupt("return", {
|
|
184
169
|
success: false,
|
|
185
170
|
status: "fail",
|
|
@@ -187,13 +172,13 @@ var _WorkflowTrigger = /*#__PURE__*/function () {
|
|
|
187
172
|
message: response.statusText
|
|
188
173
|
});
|
|
189
174
|
|
|
190
|
-
case
|
|
191
|
-
_context.next =
|
|
175
|
+
case 14:
|
|
176
|
+
_context.next = 19;
|
|
192
177
|
break;
|
|
193
178
|
|
|
194
|
-
case
|
|
195
|
-
_context.prev =
|
|
196
|
-
_context.t0 = _context["catch"](
|
|
179
|
+
case 16:
|
|
180
|
+
_context.prev = 16;
|
|
181
|
+
_context.t0 = _context["catch"](4);
|
|
197
182
|
return _context.abrupt("return", {
|
|
198
183
|
success: false,
|
|
199
184
|
status: "fail",
|
|
@@ -201,12 +186,12 @@ var _WorkflowTrigger = /*#__PURE__*/function () {
|
|
|
201
186
|
message: _context.t0.message
|
|
202
187
|
});
|
|
203
188
|
|
|
204
|
-
case
|
|
189
|
+
case 19:
|
|
205
190
|
case "end":
|
|
206
191
|
return _context.stop();
|
|
207
192
|
}
|
|
208
193
|
}
|
|
209
|
-
}, _callee, this, [[
|
|
194
|
+
}, _callee, this, [[4, 16]]);
|
|
210
195
|
}));
|
|
211
196
|
|
|
212
197
|
function send(_x) {
|
package/dist/workflows_bulk.js
CHANGED
|
@@ -75,18 +75,7 @@ var _BulkWorkflowsChunk = /*#__PURE__*/function () {
|
|
|
75
75
|
(0, _createClass2["default"])(_BulkWorkflowsChunk, [{
|
|
76
76
|
key: "__get_url",
|
|
77
77
|
value: function __get_url() {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (this.config.include_signature_param) {
|
|
81
|
-
if (this.config.auth_enabled) {
|
|
82
|
-
url_template = url_template + "?verify=true";
|
|
83
|
-
} else {
|
|
84
|
-
url_template = url_template + "?verify=false";
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
var url_formatted = "".concat(this.config.base_url).concat(this.config.workspace_key).concat(url_template);
|
|
89
|
-
return url_formatted;
|
|
78
|
+
return "".concat(this.config.base_url).concat(this.config.workspace_key, "/trigger/");
|
|
90
79
|
}
|
|
91
80
|
}, {
|
|
92
81
|
key: "__common_headers",
|
|
@@ -159,20 +148,16 @@ var _BulkWorkflowsChunk = /*#__PURE__*/function () {
|
|
|
159
148
|
switch (_context.prev = _context.next) {
|
|
160
149
|
case 0:
|
|
161
150
|
headers = _objectSpread(_objectSpread({}, this.__headers), this.__dynamic_headers());
|
|
162
|
-
content_text = JSON.stringify(this.__chunk);
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
_context.prev = 3;
|
|
170
|
-
_context.next = 6;
|
|
151
|
+
content_text = JSON.stringify(this.__chunk);
|
|
152
|
+
signature = (0, _signature["default"])(this.__url, "POST", content_text, headers, this.config.workspace_secret);
|
|
153
|
+
headers["Authorization"] = "".concat(this.config.workspace_key, ":").concat(signature);
|
|
154
|
+
_context.prev = 4;
|
|
155
|
+
_context.next = 7;
|
|
171
156
|
return _axios["default"].post(this.__url, content_text, {
|
|
172
157
|
headers: headers
|
|
173
158
|
});
|
|
174
159
|
|
|
175
|
-
case
|
|
160
|
+
case 7:
|
|
176
161
|
response = _context.sent;
|
|
177
162
|
ok_response = Math.floor(response.status / 100) == 2;
|
|
178
163
|
|
|
@@ -202,12 +187,12 @@ var _BulkWorkflowsChunk = /*#__PURE__*/function () {
|
|
|
202
187
|
};
|
|
203
188
|
}
|
|
204
189
|
|
|
205
|
-
_context.next =
|
|
190
|
+
_context.next = 16;
|
|
206
191
|
break;
|
|
207
192
|
|
|
208
|
-
case
|
|
209
|
-
_context.prev =
|
|
210
|
-
_context.t0 = _context["catch"](
|
|
193
|
+
case 12:
|
|
194
|
+
_context.prev = 12;
|
|
195
|
+
_context.t0 = _context["catch"](4);
|
|
211
196
|
error_status = _context.t0.status || 500;
|
|
212
197
|
return _context.abrupt("return", {
|
|
213
198
|
status: "fail",
|
|
@@ -225,12 +210,12 @@ var _BulkWorkflowsChunk = /*#__PURE__*/function () {
|
|
|
225
210
|
})
|
|
226
211
|
});
|
|
227
212
|
|
|
228
|
-
case
|
|
213
|
+
case 16:
|
|
229
214
|
case "end":
|
|
230
215
|
return _context.stop();
|
|
231
216
|
}
|
|
232
217
|
}
|
|
233
|
-
}, _callee, this, [[
|
|
218
|
+
}, _callee, this, [[4, 12]]);
|
|
234
219
|
}));
|
|
235
220
|
|
|
236
221
|
function trigger() {
|
package/package.json
CHANGED
package/src/constants.js
CHANGED
|
@@ -26,7 +26,7 @@ export const ALLOW_ATTACHMENTS_IN_BULK_API = true;
|
|
|
26
26
|
export const ATTACHMENT_UPLOAD_ENABLED = false;
|
|
27
27
|
|
|
28
28
|
// -- single Identity event limit
|
|
29
|
-
export const IDENTITY_SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES =
|
|
30
|
-
export const IDENTITY_SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE = "
|
|
29
|
+
export const IDENTITY_SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES = 10 * 1024;
|
|
30
|
+
export const IDENTITY_SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE = "10KB";
|
|
31
31
|
|
|
32
32
|
export const MAX_IDENTITY_EVENTS_IN_BULK_API = 400;
|
package/src/event.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
is_object,
|
|
3
2
|
is_string,
|
|
4
3
|
SuprsendError,
|
|
5
4
|
has_special_char,
|
|
@@ -130,15 +129,7 @@ export class EventCollector {
|
|
|
130
129
|
}
|
|
131
130
|
|
|
132
131
|
__get_url() {
|
|
133
|
-
|
|
134
|
-
if (this.config.include_signature_param) {
|
|
135
|
-
if (this.config.auth_enabled) {
|
|
136
|
-
url_template = url_template + "?verify=true";
|
|
137
|
-
} else {
|
|
138
|
-
url_template = url_template + "?verify=false";
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
return `${this.config.base_url}${url_template}`;
|
|
132
|
+
return `${this.config.base_url}event/`;
|
|
142
133
|
}
|
|
143
134
|
|
|
144
135
|
__common_headers() {
|
|
@@ -161,16 +152,15 @@ export class EventCollector {
|
|
|
161
152
|
async send(event) {
|
|
162
153
|
const headers = { ...this.__headers, ...this.__dynamic_headers() };
|
|
163
154
|
const content_text = JSON.stringify(event);
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
155
|
+
const signature = get_request_signature(
|
|
156
|
+
this.__url,
|
|
157
|
+
"POST",
|
|
158
|
+
content_text,
|
|
159
|
+
headers,
|
|
160
|
+
this.config.workspace_secret
|
|
161
|
+
);
|
|
162
|
+
headers["Authorization"] = `${this.config.workspace_key}:${signature}`;
|
|
163
|
+
|
|
174
164
|
try {
|
|
175
165
|
const response = await axios.post(this.__url, content_text, { headers });
|
|
176
166
|
const ok_response = Math.floor(response.status / 100) == 2;
|
package/src/events_bulk.js
CHANGED
|
@@ -36,15 +36,7 @@ class _BulkEventsChunk {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
__get_url() {
|
|
39
|
-
|
|
40
|
-
if (this.config.include_signature_param) {
|
|
41
|
-
if (this.config.auth_enabled) {
|
|
42
|
-
url_template = url_template + "?verify=true";
|
|
43
|
-
} else {
|
|
44
|
-
url_template = url_template + "?verify=false";
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
const url_formatted = `${this.config.base_url}${url_template}`;
|
|
39
|
+
const url_formatted = `${this.config.base_url}event/`;
|
|
48
40
|
return url_formatted;
|
|
49
41
|
}
|
|
50
42
|
|
|
@@ -105,17 +97,16 @@ class _BulkEventsChunk {
|
|
|
105
97
|
async trigger() {
|
|
106
98
|
const headers = { ...this.__headers, ...this.__dynamic_headers() };
|
|
107
99
|
const content_text = JSON.stringify(this.__chunk);
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
100
|
+
|
|
101
|
+
const signature = get_request_signature(
|
|
102
|
+
this.__url,
|
|
103
|
+
"POST",
|
|
104
|
+
content_text,
|
|
105
|
+
headers,
|
|
106
|
+
this.config.workspace_secret
|
|
107
|
+
);
|
|
108
|
+
headers["Authorization"] = `${this.config.workspace_key}:${signature}`;
|
|
109
|
+
|
|
119
110
|
try {
|
|
120
111
|
const response = await axios.post(this.__url, content_text, { headers });
|
|
121
112
|
const ok_response = Math.floor(response.status / 100) == 2;
|
package/src/index.js
CHANGED
|
@@ -6,10 +6,7 @@ import Event, { EventCollector } from "./event";
|
|
|
6
6
|
import { BulkEventsFactory } from "./events_bulk";
|
|
7
7
|
import SubscriberFactory from "./subscriber";
|
|
8
8
|
import BulkSubscribersFactory from "./subscribers_bulk";
|
|
9
|
-
import {
|
|
10
|
-
SubscribersListApi,
|
|
11
|
-
SubscribersListBroadcast,
|
|
12
|
-
} from "./subscribers_list";
|
|
9
|
+
import { SubscriberListsApi, SubscriberListBroadcast } from "./subscriber_list";
|
|
13
10
|
import BrandsApi from "./brands";
|
|
14
11
|
import { DEFAULT_UAT_URL, DEFAULT_URL } from "./constants";
|
|
15
12
|
|
|
@@ -22,8 +19,6 @@ class Suprsend {
|
|
|
22
19
|
this.config = config;
|
|
23
20
|
|
|
24
21
|
this.base_url = this._get_url(config.base_url);
|
|
25
|
-
this.auth_enabled = config.auth_enabled !== false;
|
|
26
|
-
this.include_signature_param = config.include_signature_param !== false;
|
|
27
22
|
this.user_agent = `suprsend/${
|
|
28
23
|
package_json.version
|
|
29
24
|
};node/${process.version.slice(1)}`;
|
|
@@ -38,7 +33,7 @@ class Suprsend {
|
|
|
38
33
|
this._user = new SubscriberFactory(this);
|
|
39
34
|
|
|
40
35
|
this.brands = new BrandsApi(this);
|
|
41
|
-
this.
|
|
36
|
+
this.subscriber_lists = new SubscriberListsApi(this);
|
|
42
37
|
|
|
43
38
|
this._validate();
|
|
44
39
|
}
|
|
@@ -131,4 +126,4 @@ class Suprsend {
|
|
|
131
126
|
}
|
|
132
127
|
}
|
|
133
128
|
|
|
134
|
-
export { Suprsend, Event, Workflow,
|
|
129
|
+
export { Suprsend, Event, Workflow, SubscriberListBroadcast };
|
|
@@ -31,6 +31,25 @@
|
|
|
31
31
|
"minLength": 1,
|
|
32
32
|
"description": "SubscriberList id"
|
|
33
33
|
},
|
|
34
|
+
"channels": {
|
|
35
|
+
"type": "array",
|
|
36
|
+
"items": {
|
|
37
|
+
"type": "string",
|
|
38
|
+
"enum": [
|
|
39
|
+
"androidpush",
|
|
40
|
+
"iospush",
|
|
41
|
+
"webpush",
|
|
42
|
+
"email",
|
|
43
|
+
"sms",
|
|
44
|
+
"whatsapp",
|
|
45
|
+
"slack",
|
|
46
|
+
"inbox",
|
|
47
|
+
"messenger"
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
"minItems": 0,
|
|
51
|
+
"description": "channels on which notification to be broadcast. e.g ['androidpush', 'iospush']"
|
|
52
|
+
},
|
|
34
53
|
"template": {
|
|
35
54
|
"$ref": "#/definitions/non_empty_string",
|
|
36
55
|
"description": "slug of Template"
|
package/src/subscriber.js
CHANGED
|
@@ -44,31 +44,16 @@ export class Subscriber {
|
|
|
44
44
|
this.config = config;
|
|
45
45
|
this.distinct_id = distinct_id;
|
|
46
46
|
this.__url = this.__get_url();
|
|
47
|
-
this.
|
|
47
|
+
this.__super_props = this.__super_properties();
|
|
48
48
|
|
|
49
49
|
this.__errors = [];
|
|
50
50
|
this.__info = [];
|
|
51
|
-
this.
|
|
52
|
-
this.
|
|
53
|
-
this._set_count = 0;
|
|
54
|
-
this._unset_count = 0;
|
|
55
|
-
this._events = [];
|
|
56
|
-
this._helper = new _SubscriberInternalHelper(
|
|
57
|
-
distinct_id,
|
|
58
|
-
config.workspace_key
|
|
59
|
-
);
|
|
51
|
+
this.user_operations = [];
|
|
52
|
+
this._helper = new _SubscriberInternalHelper();
|
|
60
53
|
}
|
|
61
54
|
|
|
62
55
|
__get_url() {
|
|
63
|
-
|
|
64
|
-
if (this.config.include_signature_param) {
|
|
65
|
-
if (this.config.auth_enabled) {
|
|
66
|
-
url_template = url_template + "?verify=true";
|
|
67
|
-
} else {
|
|
68
|
-
url_template = url_template + "?verify=false";
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return `${this.config.base_url}${url_template}`;
|
|
56
|
+
return `${this.config.base_url}event/`;
|
|
72
57
|
}
|
|
73
58
|
|
|
74
59
|
__get_headers() {
|
|
@@ -85,30 +70,16 @@ export class Subscriber {
|
|
|
85
70
|
};
|
|
86
71
|
}
|
|
87
72
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
this.
|
|
97
|
-
|
|
98
|
-
) {
|
|
99
|
-
const user_identify_event = {
|
|
100
|
-
$insert_id: uuid(),
|
|
101
|
-
$time: epoch_milliseconds(),
|
|
102
|
-
env: this.config.workspace_key,
|
|
103
|
-
event: "$identify",
|
|
104
|
-
properties: {
|
|
105
|
-
$identified_id: this.distinct_id,
|
|
106
|
-
...this.__supr_props,
|
|
107
|
-
},
|
|
108
|
-
};
|
|
109
|
-
all_events = [user_identify_event, ...all_events];
|
|
110
|
-
}
|
|
111
|
-
return all_events;
|
|
73
|
+
get_events() {
|
|
74
|
+
return {
|
|
75
|
+
$schema: "2",
|
|
76
|
+
$insert_id: uuid(),
|
|
77
|
+
$time: epoch_milliseconds(),
|
|
78
|
+
env: this.config.workspace_key,
|
|
79
|
+
distinct_id: this.distinct_id,
|
|
80
|
+
$user_operations: this.user_operations,
|
|
81
|
+
properties: this.__super_props,
|
|
82
|
+
};
|
|
112
83
|
}
|
|
113
84
|
|
|
114
85
|
validate_event_size(event_dict) {
|
|
@@ -147,22 +118,19 @@ export class Subscriber {
|
|
|
147
118
|
const is_part_of_bulk = false;
|
|
148
119
|
this.validate_body(is_part_of_bulk);
|
|
149
120
|
const headers = this.__get_headers();
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
121
|
+
const event = this.get_events();
|
|
122
|
+
const [validated_ev, size] = this.validate_event_size(event);
|
|
123
|
+
const content_text = JSON.stringify(validated_ev);
|
|
124
|
+
|
|
125
|
+
const signature = get_request_signature(
|
|
126
|
+
this.__url,
|
|
127
|
+
"POST",
|
|
128
|
+
content_text,
|
|
129
|
+
headers,
|
|
130
|
+
this.config.workspace_secret
|
|
131
|
+
);
|
|
132
|
+
headers["Authorization"] = `${this.config.workspace_key}:${signature}`;
|
|
154
133
|
|
|
155
|
-
const content_text = JSON.stringify(events);
|
|
156
|
-
if (this.config.auth_enabled) {
|
|
157
|
-
const signature = get_request_signature(
|
|
158
|
-
this.__url,
|
|
159
|
-
"POST",
|
|
160
|
-
content_text,
|
|
161
|
-
headers,
|
|
162
|
-
this.config.workspace_secret
|
|
163
|
-
);
|
|
164
|
-
headers["Authorization"] = `${this.config.workspace_key}:${signature}`;
|
|
165
|
-
}
|
|
166
134
|
try {
|
|
167
135
|
const response = await axios.post(this.__url, content_text, { headers });
|
|
168
136
|
const ok_response = Math.floor(response.status / 100) == 2;
|
|
@@ -200,11 +168,7 @@ export class Subscriber {
|
|
|
200
168
|
this.__info = [...this.__info, ...resp["info"]];
|
|
201
169
|
}
|
|
202
170
|
if (!is_empty(resp["event"])) {
|
|
203
|
-
this.
|
|
204
|
-
this._set_count += resp["set"];
|
|
205
|
-
this._append_count += resp["append"];
|
|
206
|
-
this._remove_count += resp["remove"];
|
|
207
|
-
this._unset_count += resp["unset"];
|
|
171
|
+
this.user_operations.push(resp["event"]);
|
|
208
172
|
}
|
|
209
173
|
}
|
|
210
174
|
|
package/src/subscriber_helper.js
CHANGED
|
@@ -80,16 +80,12 @@ export default class _SubscriberInternalHelper {
|
|
|
80
80
|
this.workspace_key = workspace_key;
|
|
81
81
|
|
|
82
82
|
this.__dict_set = {};
|
|
83
|
-
this.__set_count = 0;
|
|
84
83
|
|
|
85
84
|
this.__dict_append = {};
|
|
86
|
-
this.__append_count = 0;
|
|
87
85
|
|
|
88
86
|
this.__dict_remove = {};
|
|
89
|
-
this.__remove_count = 0;
|
|
90
87
|
|
|
91
88
|
this.__list_unset = [];
|
|
92
|
-
this.__unset_count = 0;
|
|
93
89
|
|
|
94
90
|
this.__errors = [];
|
|
95
91
|
this.__info = [];
|
|
@@ -97,17 +93,9 @@ export default class _SubscriberInternalHelper {
|
|
|
97
93
|
|
|
98
94
|
reset() {
|
|
99
95
|
this.__dict_set = {};
|
|
100
|
-
this.__set_count = 0;
|
|
101
|
-
|
|
102
96
|
this.__dict_append = {};
|
|
103
|
-
this.__append_count = 0;
|
|
104
|
-
|
|
105
97
|
this.__dict_remove = {};
|
|
106
|
-
this.__remove_count = 0;
|
|
107
|
-
|
|
108
98
|
this.__list_unset = [];
|
|
109
|
-
this.__unset_count = 0;
|
|
110
|
-
|
|
111
99
|
this.__errors = [];
|
|
112
100
|
this.__info = [];
|
|
113
101
|
}
|
|
@@ -118,48 +106,26 @@ export default class _SubscriberInternalHelper {
|
|
|
118
106
|
errors: this.__errors,
|
|
119
107
|
info: this.__info,
|
|
120
108
|
event: evt,
|
|
121
|
-
set: this.__set_count,
|
|
122
|
-
append: this.__append_count,
|
|
123
|
-
remove: this.__remove_count,
|
|
124
|
-
unset: this.__unset_count,
|
|
125
109
|
};
|
|
126
110
|
this.reset();
|
|
127
111
|
return ret_val;
|
|
128
112
|
}
|
|
129
113
|
|
|
130
114
|
__form_event() {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
env: this.workspace_key,
|
|
141
|
-
distinct_id: this.distinct_id,
|
|
142
|
-
};
|
|
143
|
-
if (!is_empty(this.__dict_set)) {
|
|
144
|
-
event["$set"] = this.__dict_set;
|
|
145
|
-
this.__set_count += 1;
|
|
146
|
-
}
|
|
147
|
-
if (!is_empty(this.__dict_append)) {
|
|
148
|
-
event["$append"] = this.__dict_append;
|
|
149
|
-
this.__append_count += 1;
|
|
150
|
-
}
|
|
151
|
-
if (!is_empty(this.__dict_remove)) {
|
|
152
|
-
event["$remove"] = this.__dict_remove;
|
|
153
|
-
this.__remove_count += 1;
|
|
154
|
-
}
|
|
155
|
-
if (!is_empty(this.__list_unset)) {
|
|
156
|
-
event["$unset"] = this.__list_unset;
|
|
157
|
-
this.__unset_count += 1;
|
|
158
|
-
}
|
|
159
|
-
return event;
|
|
160
|
-
} else {
|
|
161
|
-
return;
|
|
115
|
+
const event = {};
|
|
116
|
+
if (!is_empty(this.__dict_set)) {
|
|
117
|
+
event["$set"] = this.__dict_set;
|
|
118
|
+
}
|
|
119
|
+
if (!is_empty(this.__dict_append)) {
|
|
120
|
+
event["$append"] = this.__dict_append;
|
|
121
|
+
}
|
|
122
|
+
if (!is_empty(this.__dict_remove)) {
|
|
123
|
+
event["$remove"] = this.__dict_remove;
|
|
162
124
|
}
|
|
125
|
+
if (!is_empty(this.__list_unset)) {
|
|
126
|
+
event["$unset"] = this.__list_unset;
|
|
127
|
+
}
|
|
128
|
+
return event;
|
|
163
129
|
}
|
|
164
130
|
|
|
165
131
|
__validate_key_basic(key, caller) {
|
|
@@ -240,33 +206,25 @@ export default class _SubscriberInternalHelper {
|
|
|
240
206
|
}
|
|
241
207
|
|
|
242
208
|
__add_identity(key, value, args, caller) {
|
|
209
|
+
const new_caller = `${caller}:${key}`;
|
|
243
210
|
switch (key) {
|
|
244
211
|
case IDENT_KEY_EMAIL:
|
|
245
|
-
this._add_email(value,
|
|
212
|
+
this._add_email(value, new_caller);
|
|
246
213
|
break;
|
|
247
214
|
case IDENT_KEY_SMS:
|
|
248
|
-
this._add_sms(value,
|
|
215
|
+
this._add_sms(value, new_caller);
|
|
249
216
|
break;
|
|
250
217
|
case IDENT_KEY_WHATSAPP:
|
|
251
|
-
this._add_whatsapp(value,
|
|
218
|
+
this._add_whatsapp(value, new_caller);
|
|
252
219
|
break;
|
|
253
220
|
case IDENT_KEY_ANDROIDPUSH:
|
|
254
|
-
this._add_androidpush(value, args[KEY_PUSHVENDOR],
|
|
255
|
-
if (this.__dict_append[KEY_PUSHVENDOR]) {
|
|
256
|
-
args[KEY_PUSHVENDOR] = this.__dict_append[KEY_PUSHVENDOR];
|
|
257
|
-
}
|
|
221
|
+
this._add_androidpush(value, args[KEY_PUSHVENDOR], new_caller);
|
|
258
222
|
break;
|
|
259
223
|
case IDENT_KEY_IOSPUSH:
|
|
260
|
-
this._add_iospush(value, args[KEY_PUSHVENDOR],
|
|
261
|
-
if (this.__dict_append[KEY_PUSHVENDOR]) {
|
|
262
|
-
args[KEY_PUSHVENDOR] = this.__dict_append[KEY_PUSHVENDOR];
|
|
263
|
-
}
|
|
224
|
+
this._add_iospush(value, args[KEY_PUSHVENDOR], new_caller);
|
|
264
225
|
break;
|
|
265
226
|
case IDENT_KEY_WEBPUSH:
|
|
266
|
-
this._add_webpush(value, args[KEY_PUSHVENDOR],
|
|
267
|
-
if (this.__dict_append[KEY_PUSHVENDOR]) {
|
|
268
|
-
args[KEY_PUSHVENDOR] = this.__dict_append[KEY_PUSHVENDOR];
|
|
269
|
-
}
|
|
227
|
+
this._add_webpush(value, args[KEY_PUSHVENDOR], new_caller);
|
|
270
228
|
break;
|
|
271
229
|
case IDENT_KEY_SLACK:
|
|
272
230
|
this._add_slack(value, caller);
|
|
@@ -277,33 +235,25 @@ export default class _SubscriberInternalHelper {
|
|
|
277
235
|
}
|
|
278
236
|
|
|
279
237
|
__remove_identity(key, value, args, caller) {
|
|
238
|
+
const new_caller = `${caller}:${key}`;
|
|
280
239
|
switch (key) {
|
|
281
240
|
case IDENT_KEY_EMAIL:
|
|
282
|
-
this._remove_email(value,
|
|
241
|
+
this._remove_email(value, new_caller);
|
|
283
242
|
break;
|
|
284
243
|
case IDENT_KEY_SMS:
|
|
285
|
-
this._remove_sms(value,
|
|
244
|
+
this._remove_sms(value, new_caller);
|
|
286
245
|
break;
|
|
287
246
|
case IDENT_KEY_WHATSAPP:
|
|
288
|
-
this._remove_whatsapp(value,
|
|
247
|
+
this._remove_whatsapp(value, new_caller);
|
|
289
248
|
break;
|
|
290
249
|
case IDENT_KEY_ANDROIDPUSH:
|
|
291
|
-
this._remove_androidpush(value, args[KEY_PUSHVENDOR],
|
|
292
|
-
if (this.__dict_remove[KEY_PUSHVENDOR]) {
|
|
293
|
-
args[KEY_PUSHVENDOR] = this.__dict_remove[KEY_PUSHVENDOR];
|
|
294
|
-
}
|
|
250
|
+
this._remove_androidpush(value, args[KEY_PUSHVENDOR], new_caller);
|
|
295
251
|
break;
|
|
296
252
|
case IDENT_KEY_IOSPUSH:
|
|
297
|
-
this._remove_iospush(value, args[KEY_PUSHVENDOR],
|
|
298
|
-
if (this.__dict_remove[KEY_PUSHVENDOR]) {
|
|
299
|
-
args[KEY_PUSHVENDOR] = this.__dict_remove[KEY_PUSHVENDOR];
|
|
300
|
-
}
|
|
253
|
+
this._remove_iospush(value, args[KEY_PUSHVENDOR], new_caller);
|
|
301
254
|
break;
|
|
302
255
|
case IDENT_KEY_WEBPUSH:
|
|
303
|
-
this._remove_webpush(value, args[KEY_PUSHVENDOR],
|
|
304
|
-
if (this.__dict_remove[KEY_PUSHVENDOR]) {
|
|
305
|
-
args[KEY_PUSHVENDOR] = this.__dict_remove[KEY_PUSHVENDOR];
|
|
306
|
-
}
|
|
256
|
+
this._remove_webpush(value, args[KEY_PUSHVENDOR], new_caller);
|
|
307
257
|
break;
|
|
308
258
|
case IDENT_KEY_SLACK:
|
|
309
259
|
this._remove_slack(val, caller);
|
|
@@ -430,6 +380,9 @@ export default class _SubscriberInternalHelper {
|
|
|
430
380
|
if (!provider) {
|
|
431
381
|
provider = "fcm";
|
|
432
382
|
}
|
|
383
|
+
if (typeof provider === "string") {
|
|
384
|
+
provider = provider.toLocaleLowerCase();
|
|
385
|
+
}
|
|
433
386
|
if (!["fcm", "xiaomi", "oppo"].includes(provider)) {
|
|
434
387
|
this.__errors.push(
|
|
435
388
|
`[${caller}] unsupported androidpush provider ${provider}`
|
|
@@ -475,6 +428,9 @@ export default class _SubscriberInternalHelper {
|
|
|
475
428
|
if (!provider) {
|
|
476
429
|
provider = "apns";
|
|
477
430
|
}
|
|
431
|
+
if (typeof provider === "string") {
|
|
432
|
+
provider = provider.toLocaleLowerCase();
|
|
433
|
+
}
|
|
478
434
|
if (!["apns"].includes(provider)) {
|
|
479
435
|
this.__errors.push(
|
|
480
436
|
`[${caller}] unsupported iospush provider ${provider}`
|
|
@@ -521,6 +477,9 @@ export default class _SubscriberInternalHelper {
|
|
|
521
477
|
if (!provider) {
|
|
522
478
|
provider = "vapid";
|
|
523
479
|
}
|
|
480
|
+
if (typeof provider === "string") {
|
|
481
|
+
provider = provider.toLocaleLowerCase();
|
|
482
|
+
}
|
|
524
483
|
if (!["vapid"].includes(provider)) {
|
|
525
484
|
this.__errors.push(
|
|
526
485
|
`[${caller}] unsupported webpush provider ${provider}`
|