@suprsend/node-sdk 1.11.1 → 1.13.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/dist/constants.js +2 -8
- package/dist/event.js +2 -2
- package/dist/events_bulk.js +2 -2
- package/dist/index.js +25 -2
- package/dist/object_edit.js +352 -0
- package/dist/object_edit_internal_helper.js +395 -0
- package/dist/objects_api.js +527 -0
- package/dist/request_json/workflow.json +7 -29
- package/dist/request_json/workflow_trigger.json +7 -29
- package/dist/subscriber.js +12 -28
- package/dist/subscriber_helper.js +40 -363
- package/dist/subscriber_list.js +2 -2
- package/dist/user_edit.js +412 -0
- package/dist/user_edit_internal_helper.js +363 -0
- package/dist/users_api.js +535 -0
- package/dist/users_edit_bulk.js +312 -0
- package/dist/workflow.js +2 -2
- package/dist/workflow_request.js +2 -2
- package/dist/workflow_trigger_bulk.js +2 -2
- package/dist/workflows_bulk.js +2 -2
- package/package.json +1 -1
- package/src/constants.js +0 -4
- package/src/event.js +4 -5
- package/src/events_bulk.js +3 -5
- package/src/index.js +9 -1
- package/src/object_edit.js +308 -0
- package/src/object_edit_internal_helper.js +332 -0
- package/src/objects_api.js +320 -0
- package/src/request_json/workflow.json +7 -29
- package/src/request_json/workflow_trigger.json +7 -29
- package/src/subscriber.js +10 -21
- package/src/subscriber_helper.js +41 -365
- package/src/subscriber_list.js +4 -4
- package/src/user_edit.js +360 -0
- package/src/user_edit_internal_helper.js +297 -0
- package/src/users_api.js +301 -0
- package/src/users_edit_bulk.js +211 -0
- package/src/workflow.js +4 -5
- package/src/workflow_request.js +4 -4
- package/src/workflow_trigger_bulk.js +2 -4
- package/src/workflows_bulk.js +3 -5
- package/types/index.d.ts +168 -13
- package/dist/language_codes.js +0 -197
- package/dist/object.js +0 -919
- package/dist/object_helper.js +0 -659
- package/src/language_codes.js +0 -188
- package/src/object.js +0 -621
- package/src/object_helper.js +0 -593
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { is_object, is_empty, is_string } from "./utils";
|
|
2
|
+
import _ObjectEditInternalHelper from "./object_edit_internal_helper";
|
|
3
|
+
|
|
4
|
+
export default class ObjectEdit {
|
|
5
|
+
constructor(config, object_type, object_id) {
|
|
6
|
+
this.config = config;
|
|
7
|
+
this.object_type = object_type;
|
|
8
|
+
this.object_id = object_id;
|
|
9
|
+
|
|
10
|
+
this.__errors = [];
|
|
11
|
+
this.__info = [];
|
|
12
|
+
this.operations = [];
|
|
13
|
+
this._helper = new _ObjectEditInternalHelper();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
get_object_type() {
|
|
17
|
+
return this.object_type;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get_object_id() {
|
|
21
|
+
return this.object_id;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get_warnings() {
|
|
25
|
+
return this.__info;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get_errors() {
|
|
29
|
+
return this.__errors;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get_payload() {
|
|
33
|
+
return { operations: this.operations };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
validate_body() {
|
|
37
|
+
if (!is_empty(this.__info)) {
|
|
38
|
+
const msg = `[object: ${this.object_type}/${
|
|
39
|
+
this.object_id
|
|
40
|
+
}] ${this.__info.join("\n")}`;
|
|
41
|
+
console.log(`WARNING: ${msg}`);
|
|
42
|
+
}
|
|
43
|
+
if (!is_empty(this.__errors)) {
|
|
44
|
+
const msg = `[object: ${this.object_type}/${
|
|
45
|
+
this.object_id
|
|
46
|
+
}] ${this.__errors.join("\n")}`;
|
|
47
|
+
console.log(`ERROR: ${msg}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
_collect_operation() {
|
|
52
|
+
const resp = this._helper._get_operation_result();
|
|
53
|
+
if (!is_empty(resp["errors"])) {
|
|
54
|
+
this.__errors = [...this.__errors, ...resp["errors"]];
|
|
55
|
+
}
|
|
56
|
+
if (!is_empty(resp["info"])) {
|
|
57
|
+
this.__info = [...this.__info, ...resp["info"]];
|
|
58
|
+
}
|
|
59
|
+
if (!is_empty(resp["operation"])) {
|
|
60
|
+
this.operations.push(resp["operation"]);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
append(key, value) {
|
|
65
|
+
const caller = "append";
|
|
66
|
+
if (!is_string(key) && !is_object(key)) {
|
|
67
|
+
this.__errors.push(`[${caller}] arg1 must be either string or a dict`);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (is_string(key)) {
|
|
71
|
+
if (!value) {
|
|
72
|
+
this.__errors.push(
|
|
73
|
+
`[${caller}] if arg1 is a string, then arg2 must be passed`
|
|
74
|
+
);
|
|
75
|
+
return;
|
|
76
|
+
} else {
|
|
77
|
+
this._helper._append_kv(key, value, {}, caller);
|
|
78
|
+
this._collect_operation();
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
for (let item in key) {
|
|
82
|
+
this._helper._append_kv(item, key[item], key, caller);
|
|
83
|
+
}
|
|
84
|
+
this._collect_operation();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
set(key, value) {
|
|
89
|
+
const caller = "set";
|
|
90
|
+
if (!is_string(key) && !is_object(key)) {
|
|
91
|
+
this.__errors.push(`[${caller}] arg1 must be either string or a dict`);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (is_string(key)) {
|
|
95
|
+
if (value === null || value === undefined) {
|
|
96
|
+
this.__errors.push(
|
|
97
|
+
`[${caller}] if arg1 is a string, then arg2 must be passed`
|
|
98
|
+
);
|
|
99
|
+
return;
|
|
100
|
+
} else {
|
|
101
|
+
this._helper._set_kv(key, value, {}, caller);
|
|
102
|
+
this._collect_operation();
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
for (let item in key) {
|
|
106
|
+
this._helper._set_kv(item, key[item], key, caller);
|
|
107
|
+
}
|
|
108
|
+
this._collect_operation();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
set_once(key, value) {
|
|
113
|
+
const caller = "set_once";
|
|
114
|
+
if (!is_string(key) && !is_object(key)) {
|
|
115
|
+
this.__errors.push(`[${caller}] arg1 must be either string or a dict`);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (is_string(key)) {
|
|
119
|
+
if (value === null || value === undefined) {
|
|
120
|
+
this.__errors.push(
|
|
121
|
+
`[${caller}] if arg1 is a string, then arg2 must be passed`
|
|
122
|
+
);
|
|
123
|
+
return;
|
|
124
|
+
} else {
|
|
125
|
+
this._helper._set_once_kv(key, value, {}, caller);
|
|
126
|
+
this._collect_operation();
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
for (let item in key) {
|
|
130
|
+
this._helper._set_once_kv(item, key[item], key, caller);
|
|
131
|
+
}
|
|
132
|
+
this._collect_operation();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
increment(key, value) {
|
|
137
|
+
const caller = "increment";
|
|
138
|
+
if (!is_string(key) && !is_object(key)) {
|
|
139
|
+
this.__errors.push(`[${caller}] arg1 must be either string or a dict`);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (is_string(key)) {
|
|
143
|
+
if (value === null || value === undefined) {
|
|
144
|
+
this.__errors.push(
|
|
145
|
+
`[${caller}] if arg1 is a string, then arg2 must be passed`
|
|
146
|
+
);
|
|
147
|
+
return;
|
|
148
|
+
} else {
|
|
149
|
+
this._helper._increment_kv(key, value, {}, caller);
|
|
150
|
+
this._collect_operation();
|
|
151
|
+
}
|
|
152
|
+
} else {
|
|
153
|
+
for (let item in key) {
|
|
154
|
+
this._helper._increment_kv(item, key[item], key, caller);
|
|
155
|
+
}
|
|
156
|
+
this._collect_operation();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
remove(key, value) {
|
|
161
|
+
const caller = "remove";
|
|
162
|
+
if (!is_string(key) && !is_object(key)) {
|
|
163
|
+
this.__errors.push(`[${caller}] arg1 must be either string or a dict`);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (is_string(key)) {
|
|
167
|
+
if (!value) {
|
|
168
|
+
this.__errors.push(
|
|
169
|
+
`[${caller}] if arg1 is a string, then arg2 must be passed`
|
|
170
|
+
);
|
|
171
|
+
return;
|
|
172
|
+
} else {
|
|
173
|
+
this._helper._remove_kv(key, value, {}, caller);
|
|
174
|
+
this._collect_operation();
|
|
175
|
+
}
|
|
176
|
+
} else {
|
|
177
|
+
for (let item in key) {
|
|
178
|
+
this._helper._remove_kv(item, key[item], key, caller);
|
|
179
|
+
}
|
|
180
|
+
this._collect_operation();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
unset(key) {
|
|
185
|
+
const caller = "unset";
|
|
186
|
+
if (!is_string(key) && !Array.isArray(key)) {
|
|
187
|
+
this.__errors.push(`[${caller}] key must be either string or array`);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (is_string(key)) {
|
|
191
|
+
this._helper._unset_k(key, caller);
|
|
192
|
+
this._collect_operation();
|
|
193
|
+
} else {
|
|
194
|
+
for (let item of key) {
|
|
195
|
+
this._helper._unset_k(item, caller);
|
|
196
|
+
}
|
|
197
|
+
this._collect_operation();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
set_preferred_language(lang_code) {
|
|
202
|
+
const caller = "set_preferred_language";
|
|
203
|
+
this._helper._set_preferred_language(lang_code, caller);
|
|
204
|
+
this._collect_operation();
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
set_timezone(timezone) {
|
|
208
|
+
const caller = "set_timezone";
|
|
209
|
+
this._helper._set_timezone(timezone, caller);
|
|
210
|
+
this._collect_operation();
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
add_email(email) {
|
|
214
|
+
const caller = "add_email";
|
|
215
|
+
this._helper._add_email(email, caller);
|
|
216
|
+
this._collect_operation();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
remove_email(email) {
|
|
220
|
+
const caller = "remove_email";
|
|
221
|
+
this._helper._remove_email(email, caller);
|
|
222
|
+
this._collect_operation();
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
add_sms(mobile_no) {
|
|
226
|
+
const caller = "add_sms";
|
|
227
|
+
this._helper._add_sms(mobile_no, caller);
|
|
228
|
+
this._collect_operation();
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
remove_sms(mobile_no) {
|
|
232
|
+
const caller = "remove_sms";
|
|
233
|
+
this._helper._remove_sms(mobile_no, caller);
|
|
234
|
+
this._collect_operation();
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
add_whatsapp(mobile_no) {
|
|
238
|
+
const caller = "add_whatsapp";
|
|
239
|
+
this._helper._add_whatsapp(mobile_no, caller);
|
|
240
|
+
this._collect_operation();
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
remove_whatsapp(mobile_no) {
|
|
244
|
+
const caller = "remove_whatsapp";
|
|
245
|
+
this._helper._remove_whatsapp(mobile_no, caller);
|
|
246
|
+
this._collect_operation();
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
add_androidpush(push_token, provider) {
|
|
250
|
+
const caller = "add_androidpush";
|
|
251
|
+
this._helper._add_androidpush(push_token, provider, caller);
|
|
252
|
+
this._collect_operation();
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
remove_androidpush(push_token, provider) {
|
|
256
|
+
const caller = "remove_androidpush";
|
|
257
|
+
this._helper._remove_androidpush(push_token, provider, caller);
|
|
258
|
+
this._collect_operation();
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
add_iospush(push_token, provider) {
|
|
262
|
+
const caller = "add_iospush";
|
|
263
|
+
this._helper._add_iospush(push_token, provider, caller);
|
|
264
|
+
this._collect_operation();
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
remove_iospush(push_token, provider) {
|
|
268
|
+
const caller = "remove_iospush";
|
|
269
|
+
this._helper._remove_iospush(push_token, provider, caller);
|
|
270
|
+
this._collect_operation();
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
add_webpush(push_token, provider) {
|
|
274
|
+
const caller = "add_webpush";
|
|
275
|
+
this._helper._add_webpush(push_token, provider, caller);
|
|
276
|
+
this._collect_operation();
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
remove_webpush(push_token, provider) {
|
|
280
|
+
const caller = "remove_webpush";
|
|
281
|
+
this._helper._remove_webpush(push_token, provider, caller);
|
|
282
|
+
this._collect_operation();
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
add_slack(value) {
|
|
286
|
+
const caller = "add_slack";
|
|
287
|
+
this._helper._add_slack(value, caller);
|
|
288
|
+
this._collect_operation();
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
remove_slack(value) {
|
|
292
|
+
const caller = "remove_slack";
|
|
293
|
+
this._helper._remove_slack(value, caller);
|
|
294
|
+
this._collect_operation();
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
add_ms_teams(value) {
|
|
298
|
+
const caller = "add_ms_teams";
|
|
299
|
+
this._helper._add_ms_teams(value, caller);
|
|
300
|
+
this._collect_operation();
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
remove_ms_teams(value) {
|
|
304
|
+
const caller = "remove_ms_teams";
|
|
305
|
+
this._helper._remove_ms_teams(value, caller);
|
|
306
|
+
this._collect_operation();
|
|
307
|
+
}
|
|
308
|
+
}
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { is_object, has_special_char, is_empty, is_string } from "./utils";
|
|
2
|
+
|
|
3
|
+
// ---------- Identity keys
|
|
4
|
+
const IDENT_KEY_EMAIL = "$email";
|
|
5
|
+
const IDENT_KEY_SMS = "$sms";
|
|
6
|
+
const IDENT_KEY_ANDROIDPUSH = "$androidpush";
|
|
7
|
+
const IDENT_KEY_IOSPUSH = "$iospush";
|
|
8
|
+
const IDENT_KEY_WHATSAPP = "$whatsapp";
|
|
9
|
+
const IDENT_KEY_WEBPUSH = "$webpush";
|
|
10
|
+
const IDENT_KEY_SLACK = "$slack";
|
|
11
|
+
const IDENT_KEY_MS_TEAMS = "$ms_teams";
|
|
12
|
+
|
|
13
|
+
const IDENT_KEYS_ALL = [
|
|
14
|
+
IDENT_KEY_EMAIL,
|
|
15
|
+
IDENT_KEY_SMS,
|
|
16
|
+
IDENT_KEY_ANDROIDPUSH,
|
|
17
|
+
IDENT_KEY_IOSPUSH,
|
|
18
|
+
IDENT_KEY_WHATSAPP,
|
|
19
|
+
IDENT_KEY_WEBPUSH,
|
|
20
|
+
IDENT_KEY_SLACK,
|
|
21
|
+
IDENT_KEY_MS_TEAMS,
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
const KEY_ID_PROVIDER = "$id_provider";
|
|
25
|
+
const KEY_PREFERRED_LANGUAGE = "$preferred_language";
|
|
26
|
+
const KEY_TIMEZONE = "$timezone";
|
|
27
|
+
|
|
28
|
+
export default class _ObjectEditInternalHelper {
|
|
29
|
+
constructor() {
|
|
30
|
+
this.__dict_set = {};
|
|
31
|
+
|
|
32
|
+
this.__dict_set_once = {};
|
|
33
|
+
|
|
34
|
+
this.__dict_increment = {};
|
|
35
|
+
|
|
36
|
+
this.__dict_append = {};
|
|
37
|
+
|
|
38
|
+
this.__dict_remove = {};
|
|
39
|
+
|
|
40
|
+
this.__list_unset = [];
|
|
41
|
+
|
|
42
|
+
this.__errors = [];
|
|
43
|
+
this.__info = [];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
reset() {
|
|
47
|
+
this.__dict_set = {};
|
|
48
|
+
this.__dict_set_once = {};
|
|
49
|
+
this.__dict_increment = {};
|
|
50
|
+
this.__dict_append = {};
|
|
51
|
+
this.__dict_remove = {};
|
|
52
|
+
this.__list_unset = [];
|
|
53
|
+
this.__errors = [];
|
|
54
|
+
this.__info = [];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
_get_operation_result() {
|
|
58
|
+
const operation = this.__form_operation();
|
|
59
|
+
const ret_val = {
|
|
60
|
+
errors: this.__errors,
|
|
61
|
+
info: this.__info,
|
|
62
|
+
operation: operation,
|
|
63
|
+
};
|
|
64
|
+
this.reset();
|
|
65
|
+
return ret_val;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
__form_operation() {
|
|
69
|
+
const ops = {};
|
|
70
|
+
if (!is_empty(this.__dict_set)) {
|
|
71
|
+
ops["$set"] = this.__dict_set;
|
|
72
|
+
}
|
|
73
|
+
if (!is_empty(this.__dict_set_once)) {
|
|
74
|
+
ops["$set_once"] = this.__dict_set_once;
|
|
75
|
+
}
|
|
76
|
+
if (!is_empty(this.__dict_increment)) {
|
|
77
|
+
ops["$add"] = this.__dict_increment;
|
|
78
|
+
}
|
|
79
|
+
if (!is_empty(this.__dict_append)) {
|
|
80
|
+
ops["$append"] = this.__dict_append;
|
|
81
|
+
}
|
|
82
|
+
if (!is_empty(this.__dict_remove)) {
|
|
83
|
+
ops["$remove"] = this.__dict_remove;
|
|
84
|
+
}
|
|
85
|
+
if (!is_empty(this.__list_unset)) {
|
|
86
|
+
ops["$unset"] = this.__list_unset;
|
|
87
|
+
}
|
|
88
|
+
return ops;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
__validate_key_basic(key, caller) {
|
|
92
|
+
if (!is_string(key)) {
|
|
93
|
+
this.__info.push(
|
|
94
|
+
`[${caller}] skipping key: ${key}. key must be a string`
|
|
95
|
+
);
|
|
96
|
+
return [key, false];
|
|
97
|
+
}
|
|
98
|
+
key = key.trim();
|
|
99
|
+
if (!key) {
|
|
100
|
+
this.__info.push(`[${caller}] skipping key: empty string`);
|
|
101
|
+
return [key, false];
|
|
102
|
+
}
|
|
103
|
+
return [key, true];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
__is_identity_key(key) {
|
|
107
|
+
return IDENT_KEYS_ALL.includes(key);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
_append_kv(key, value, args = {}, caller = "append") {
|
|
111
|
+
const [validated_key, is_k_valid] = this.__validate_key_basic(key, caller);
|
|
112
|
+
if (!is_k_valid) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (this.__is_identity_key(validated_key)) {
|
|
116
|
+
this.__add_identity(validated_key, value, args, caller);
|
|
117
|
+
} else {
|
|
118
|
+
this.__dict_append[validated_key] = value;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
_set_kv(key, value, args = {}, caller = "set") {
|
|
123
|
+
const [validated_key, is_k_valid] = this.__validate_key_basic(key, caller);
|
|
124
|
+
if (!is_k_valid) {
|
|
125
|
+
return;
|
|
126
|
+
} else {
|
|
127
|
+
this.__dict_set[validated_key] = value;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
_set_once_kv(key, value, args = {}, caller = "set_once") {
|
|
132
|
+
const [validated_key, is_k_valid] = this.__validate_key_basic(key, caller);
|
|
133
|
+
if (!is_k_valid) {
|
|
134
|
+
return;
|
|
135
|
+
} else {
|
|
136
|
+
this.__dict_set_once[validated_key] = value;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
_increment_kv(key, value, args = {}, caller = "increment") {
|
|
141
|
+
const [validated_key, is_k_valid] = this.__validate_key_basic(key, caller);
|
|
142
|
+
if (!is_k_valid) {
|
|
143
|
+
return;
|
|
144
|
+
} else {
|
|
145
|
+
this.__dict_increment[validated_key] = value;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
_remove_kv(key, value, args = {}, caller = "remove") {
|
|
150
|
+
const [validated_key, is_k_valid] = this.__validate_key_basic(key, caller);
|
|
151
|
+
if (!is_k_valid) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (this.__is_identity_key(validated_key)) {
|
|
155
|
+
this.__remove_identity(validated_key, value, args, caller);
|
|
156
|
+
} else {
|
|
157
|
+
this.__dict_remove[validated_key] = value;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
_unset_k(key, caller = "unset") {
|
|
162
|
+
const [validated_key, is_k_valid] = this.__validate_key_basic(key, caller);
|
|
163
|
+
if (!is_k_valid) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
this.__list_unset.push(validated_key);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
_set_preferred_language(lang_code, caller) {
|
|
170
|
+
this.__dict_set[KEY_PREFERRED_LANGUAGE] = lang_code;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
_set_timezone(timezone, caller) {
|
|
174
|
+
this.__dict_set[KEY_TIMEZONE] = timezone;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
__add_identity(key, value, args, caller) {
|
|
178
|
+
const new_caller = `${caller}:${key}`;
|
|
179
|
+
switch (key) {
|
|
180
|
+
case IDENT_KEY_EMAIL:
|
|
181
|
+
this._add_email(value, new_caller);
|
|
182
|
+
break;
|
|
183
|
+
case IDENT_KEY_SMS:
|
|
184
|
+
this._add_sms(value, new_caller);
|
|
185
|
+
break;
|
|
186
|
+
case IDENT_KEY_WHATSAPP:
|
|
187
|
+
this._add_whatsapp(value, new_caller);
|
|
188
|
+
break;
|
|
189
|
+
case IDENT_KEY_ANDROIDPUSH:
|
|
190
|
+
this._add_androidpush(value, args[KEY_ID_PROVIDER], new_caller);
|
|
191
|
+
break;
|
|
192
|
+
case IDENT_KEY_IOSPUSH:
|
|
193
|
+
this._add_iospush(value, args[KEY_ID_PROVIDER], new_caller);
|
|
194
|
+
break;
|
|
195
|
+
case IDENT_KEY_WEBPUSH:
|
|
196
|
+
this._add_webpush(value, args[KEY_ID_PROVIDER], new_caller);
|
|
197
|
+
break;
|
|
198
|
+
case IDENT_KEY_SLACK:
|
|
199
|
+
this._add_slack(value, caller);
|
|
200
|
+
break;
|
|
201
|
+
case IDENT_KEY_MS_TEAMS:
|
|
202
|
+
this._add_ms_teams(value, caller);
|
|
203
|
+
break;
|
|
204
|
+
default:
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
__remove_identity(key, value, args, caller) {
|
|
210
|
+
const new_caller = `${caller}:${key}`;
|
|
211
|
+
switch (key) {
|
|
212
|
+
case IDENT_KEY_EMAIL:
|
|
213
|
+
this._remove_email(value, new_caller);
|
|
214
|
+
break;
|
|
215
|
+
case IDENT_KEY_SMS:
|
|
216
|
+
this._remove_sms(value, new_caller);
|
|
217
|
+
break;
|
|
218
|
+
case IDENT_KEY_WHATSAPP:
|
|
219
|
+
this._remove_whatsapp(value, new_caller);
|
|
220
|
+
break;
|
|
221
|
+
case IDENT_KEY_ANDROIDPUSH:
|
|
222
|
+
this._remove_androidpush(value, args[KEY_ID_PROVIDER], new_caller);
|
|
223
|
+
break;
|
|
224
|
+
case IDENT_KEY_IOSPUSH:
|
|
225
|
+
this._remove_iospush(value, args[KEY_ID_PROVIDER], new_caller);
|
|
226
|
+
break;
|
|
227
|
+
case IDENT_KEY_WEBPUSH:
|
|
228
|
+
this._remove_webpush(value, args[KEY_ID_PROVIDER], new_caller);
|
|
229
|
+
break;
|
|
230
|
+
case IDENT_KEY_SLACK:
|
|
231
|
+
this._remove_slack(val, caller);
|
|
232
|
+
break;
|
|
233
|
+
case IDENT_KEY_MS_TEAMS:
|
|
234
|
+
this._remove_ms_teams(val, caller);
|
|
235
|
+
break;
|
|
236
|
+
default:
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
__check_ident_val_string(value, caller) {
|
|
242
|
+
const message = "value must be a string with proper value";
|
|
243
|
+
if (!is_string(value)) {
|
|
244
|
+
this.__errors.push(`[${caller}] ${message}`);
|
|
245
|
+
return [value, false];
|
|
246
|
+
}
|
|
247
|
+
value = value.trim();
|
|
248
|
+
if (!value) {
|
|
249
|
+
this.__errors.push(`[${caller}] ${message}`);
|
|
250
|
+
return [value, false];
|
|
251
|
+
}
|
|
252
|
+
return [value, true];
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// email methods
|
|
256
|
+
_add_email(email, caller) {
|
|
257
|
+
this.__dict_append[IDENT_KEY_EMAIL] = email;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
_remove_email(email, caller) {
|
|
261
|
+
this.__dict_remove[IDENT_KEY_EMAIL] = email;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// sms methods
|
|
265
|
+
_add_sms(mobile_no, caller) {
|
|
266
|
+
this.__dict_append[IDENT_KEY_SMS] = mobile_no;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
_remove_sms(mobile_no, caller) {
|
|
270
|
+
this.__dict_remove[IDENT_KEY_SMS] = mobile_no;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// whatsapp methods
|
|
274
|
+
_add_whatsapp(mobile_no, caller) {
|
|
275
|
+
this.__dict_append[IDENT_KEY_WHATSAPP] = mobile_no;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
_remove_whatsapp(mobile_no, caller) {
|
|
279
|
+
this.__dict_remove[IDENT_KEY_WHATSAPP] = mobile_no;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// android push methods
|
|
283
|
+
_add_androidpush(push_token, provider, caller) {
|
|
284
|
+
this.__dict_append[IDENT_KEY_ANDROIDPUSH] = push_token;
|
|
285
|
+
this.__dict_append[KEY_ID_PROVIDER] = provider;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
_remove_androidpush(push_token, provider) {
|
|
289
|
+
this.__dict_remove[IDENT_KEY_ANDROIDPUSH] = push_token;
|
|
290
|
+
this.__dict_remove[KEY_ID_PROVIDER] = provider;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// ios push methods
|
|
294
|
+
_add_iospush(push_token, provider, caller) {
|
|
295
|
+
this.__dict_append[IDENT_KEY_IOSPUSH] = push_token;
|
|
296
|
+
this.__dict_append[KEY_ID_PROVIDER] = provider;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
_remove_iospush(push_token, provider, caller) {
|
|
300
|
+
this.__dict_remove[IDENT_KEY_IOSPUSH] = push_token;
|
|
301
|
+
this.__dict_remove[KEY_ID_PROVIDER] = provider;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// web push methods
|
|
305
|
+
_add_webpush(push_token, provider, caller) {
|
|
306
|
+
this.__dict_append[IDENT_KEY_WEBPUSH] = push_token;
|
|
307
|
+
this.__dict_append[KEY_ID_PROVIDER] = provider;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
_remove_webpush(push_token, provider, caller) {
|
|
311
|
+
this.__dict_remove[IDENT_KEY_WEBPUSH] = push_token;
|
|
312
|
+
this.__dict_remove[KEY_ID_PROVIDER] = provider;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// slack methods
|
|
316
|
+
_add_slack(value, caller) {
|
|
317
|
+
this.__dict_append[IDENT_KEY_SLACK] = value;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
_remove_slack(value, caller) {
|
|
321
|
+
this.__dict_remove[IDENT_KEY_SLACK] = value;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// ms teams methods
|
|
325
|
+
_add_ms_teams(value, caller) {
|
|
326
|
+
this.__dict_append[IDENT_KEY_MS_TEAMS] = value;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
_remove_ms_teams(value, caller) {
|
|
330
|
+
this.__dict_remove[IDENT_KEY_MS_TEAMS] = value;
|
|
331
|
+
}
|
|
332
|
+
}
|