@suprsend/node-sdk 1.12.0 → 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 +21 -0
- package/dist/object_edit.js +6 -12
- package/dist/object_edit_internal_helper.js +40 -301
- package/dist/objects_api.js +193 -242
- package/dist/request_json/workflow.json +7 -29
- package/dist/request_json/workflow_trigger.json +7 -29
- package/dist/subscriber.js +10 -27
- package/dist/subscriber_helper.js +33 -291
- 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 +400 -98
- 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 +6 -0
- package/src/object_edit.js +6 -6
- package/src/object_edit_internal_helper.js +37 -295
- package/src/objects_api.js +97 -93
- package/src/request_json/workflow.json +7 -29
- package/src/request_json/workflow_trigger.json +7 -29
- package/src/subscriber.js +8 -20
- package/src/subscriber_helper.js +34 -284
- 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 +207 -27
- 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 +113 -8
- package/dist/language_codes.js +0 -197
- package/src/language_codes.js +0 -188
package/src/user_edit.js
ADDED
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import {
|
|
2
|
+
uuid,
|
|
3
|
+
get_apparent_identity_event_size,
|
|
4
|
+
InputValueError,
|
|
5
|
+
epoch_milliseconds,
|
|
6
|
+
is_empty,
|
|
7
|
+
is_string,
|
|
8
|
+
is_object,
|
|
9
|
+
} from "./utils";
|
|
10
|
+
import _UserEditInternalHelper from "./user_edit_internal_helper";
|
|
11
|
+
import {
|
|
12
|
+
IDENTITY_SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES,
|
|
13
|
+
IDENTITY_SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE,
|
|
14
|
+
} from "./constants";
|
|
15
|
+
|
|
16
|
+
class UserEdit {
|
|
17
|
+
constructor(config, distinct_id) {
|
|
18
|
+
this.config = config;
|
|
19
|
+
this.distinct_id = distinct_id;
|
|
20
|
+
|
|
21
|
+
this.__errors = [];
|
|
22
|
+
this.__info = [];
|
|
23
|
+
|
|
24
|
+
this.operations = [];
|
|
25
|
+
this._helper = new _UserEditInternalHelper();
|
|
26
|
+
|
|
27
|
+
this.__warnings_list = [];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get warnings() {
|
|
31
|
+
return this.__info;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
get errors() {
|
|
35
|
+
return this.__errors;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
get_payload() {
|
|
39
|
+
return { operations: this.operations };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get_async_payload() {
|
|
43
|
+
return {
|
|
44
|
+
$schema: "2",
|
|
45
|
+
$insert_id: uuid(),
|
|
46
|
+
$time: epoch_milliseconds(),
|
|
47
|
+
env: this.config.workspace_key,
|
|
48
|
+
distinct_id: this.distinct_id,
|
|
49
|
+
$user_operations: this.operations,
|
|
50
|
+
properties: { $ss_sdk_version: this.config.user_agent },
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
as_json_async() {
|
|
55
|
+
return {
|
|
56
|
+
distinct_id: this.distinct_id,
|
|
57
|
+
$user_operations: this.operations,
|
|
58
|
+
warnings: this.__warnings_list,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
validate_payload_size(payload) {
|
|
63
|
+
const apparent_size = get_apparent_identity_event_size(payload);
|
|
64
|
+
if (apparent_size > IDENTITY_SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES) {
|
|
65
|
+
throw new InputValueError(
|
|
66
|
+
`User Payload size too big - ${apparent_size} Bytes, ` +
|
|
67
|
+
`must not cross ${IDENTITY_SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE}`
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
return [payload, apparent_size];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
validate_body() {
|
|
74
|
+
this.__warnings_list = [];
|
|
75
|
+
if (!is_empty(this.__info)) {
|
|
76
|
+
const msg = `[distinct_id: ${this.distinct_id}]` + this.__info.join("\n");
|
|
77
|
+
this.__warnings_list.push(msg);
|
|
78
|
+
console.log(`WARNING: ${msg}`);
|
|
79
|
+
}
|
|
80
|
+
if (!is_empty(this.__errors)) {
|
|
81
|
+
const msg =
|
|
82
|
+
`[distinct_id: ${this.distinct_id}]` + this.__errors.join("\n");
|
|
83
|
+
this.__warnings_list.push(msg);
|
|
84
|
+
console.log(`ERROR: ${msg}`);
|
|
85
|
+
}
|
|
86
|
+
return this.__warnings_list;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
_collect_operation() {
|
|
90
|
+
const resp = this._helper.get_operation_result();
|
|
91
|
+
if (!is_empty(resp["errors"])) {
|
|
92
|
+
this.__errors = [...this.__errors, ...resp["errors"]];
|
|
93
|
+
}
|
|
94
|
+
if (!is_empty(resp["info"])) {
|
|
95
|
+
this.__info = [...this.__info, ...resp["info"]];
|
|
96
|
+
}
|
|
97
|
+
if (!is_empty(resp["operation"])) {
|
|
98
|
+
this.operations.push(resp["operation"]);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
append(arg1, arg2 = null) {
|
|
103
|
+
const caller = "append";
|
|
104
|
+
if (!is_string(arg1) && !is_object(arg1)) {
|
|
105
|
+
this.__errors.push(`[${caller}] arg1 must be either string or a dict`);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (is_string(arg1)) {
|
|
109
|
+
if (!arg2) {
|
|
110
|
+
this.__errors.push(
|
|
111
|
+
`[${caller}] if arg1 is a string, then arg2 must be passed`
|
|
112
|
+
);
|
|
113
|
+
return;
|
|
114
|
+
} else {
|
|
115
|
+
this._helper._append_kv(arg1, arg2, {}, caller);
|
|
116
|
+
this._collect_operation();
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
for (let item in arg1) {
|
|
120
|
+
this._helper._append_kv(item, arg1[item], arg1, caller);
|
|
121
|
+
}
|
|
122
|
+
this._collect_operation();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
set(arg1, arg2 = null) {
|
|
127
|
+
const caller = "set";
|
|
128
|
+
if (!is_string(arg1) && !is_object(arg1)) {
|
|
129
|
+
this.__errors.push(`[${caller}] arg1 must be String or a dict`);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (typeof arg1 === "string") {
|
|
133
|
+
if (arg2 === null || arg2 === undefined) {
|
|
134
|
+
this.__errors.push(
|
|
135
|
+
`[${caller}] if arg1 is a string, then arg2 must be passed`
|
|
136
|
+
);
|
|
137
|
+
return;
|
|
138
|
+
} else {
|
|
139
|
+
this._helper._set_kv(arg1, arg2, caller);
|
|
140
|
+
this._collect_operation();
|
|
141
|
+
}
|
|
142
|
+
} else {
|
|
143
|
+
for (let item in arg1) {
|
|
144
|
+
this._helper._set_kv(item, arg1[item], arg1, caller);
|
|
145
|
+
}
|
|
146
|
+
this._collect_operation();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
set_once(arg1, arg2 = null) {
|
|
151
|
+
const caller = "set_once";
|
|
152
|
+
if (!is_string(arg1) && !is_object(arg1)) {
|
|
153
|
+
this.__errors.push(`[${caller}] arg1 must be String or a dict`);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (is_string(arg1)) {
|
|
157
|
+
if (arg2 === null || arg2 === undefined) {
|
|
158
|
+
this.__errors.push(
|
|
159
|
+
`[${caller}] if arg1 is a string, then arg2 must be passed`
|
|
160
|
+
);
|
|
161
|
+
return;
|
|
162
|
+
} else {
|
|
163
|
+
this._helper._set_once_kv(arg1, arg2, caller);
|
|
164
|
+
this._collect_operation();
|
|
165
|
+
}
|
|
166
|
+
} else {
|
|
167
|
+
for (let item in arg1) {
|
|
168
|
+
this._helper._set_once_kv(item, arg1[item], arg1, caller);
|
|
169
|
+
}
|
|
170
|
+
this._collect_operation();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
increment(arg1, arg2 = null) {
|
|
175
|
+
const caller = "increment";
|
|
176
|
+
if (!is_string(arg1) && !is_object(arg1)) {
|
|
177
|
+
this.__errors.push(`[${caller}] arg1 must be String or a dict`);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (is_string(arg1)) {
|
|
181
|
+
if (arg2 === null || arg2 === undefined) {
|
|
182
|
+
this.__errors.push(
|
|
183
|
+
`[${caller}] if arg1 is a string, then arg2 must be passed`
|
|
184
|
+
);
|
|
185
|
+
return;
|
|
186
|
+
} else {
|
|
187
|
+
this._helper._increment_kv(arg1, arg2, caller);
|
|
188
|
+
this._collect_operation();
|
|
189
|
+
}
|
|
190
|
+
} else {
|
|
191
|
+
for (let item in arg1) {
|
|
192
|
+
this._helper._increment_kv(item, arg1[item], arg1, caller);
|
|
193
|
+
}
|
|
194
|
+
this._collect_operation();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
remove(arg1, arg2 = null) {
|
|
199
|
+
const caller = "remove";
|
|
200
|
+
if (!is_string(arg1) && !is_object(arg1)) {
|
|
201
|
+
this.__errors.push(`[${caller}] arg1 must be either string or a dict`);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (is_string(arg1)) {
|
|
205
|
+
if (arg2 === null || arg2 === undefined) {
|
|
206
|
+
this.__errors.push(
|
|
207
|
+
`[${caller}] if arg1 is a string, then arg2 must be passed`
|
|
208
|
+
);
|
|
209
|
+
return;
|
|
210
|
+
} else {
|
|
211
|
+
this._helper._remove_kv(arg1, arg2, {}, caller);
|
|
212
|
+
this._collect_operation();
|
|
213
|
+
}
|
|
214
|
+
} else {
|
|
215
|
+
for (let item in arg1) {
|
|
216
|
+
this._helper._remove_kv(item, arg1[item], arg1, caller);
|
|
217
|
+
}
|
|
218
|
+
this._collect_operation();
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
unset(key) {
|
|
223
|
+
const caller = "unset";
|
|
224
|
+
if (!is_string(key) && !Array.isArray(key)) {
|
|
225
|
+
this.__errors.push(
|
|
226
|
+
`[${caller}] key must be either String or List[string]`
|
|
227
|
+
);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
if (is_string(key)) {
|
|
231
|
+
this._helper._unset_k(key, caller);
|
|
232
|
+
this._collect_operation();
|
|
233
|
+
} else {
|
|
234
|
+
for (const k of key) {
|
|
235
|
+
this._helper._unset_k(k, caller);
|
|
236
|
+
}
|
|
237
|
+
this._collect_operation();
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// ------------------------ Preferred language
|
|
242
|
+
set_preferred_language(lang_code) {
|
|
243
|
+
const caller = "set_preferred_language";
|
|
244
|
+
this._helper._set_preferred_language(lang_code, caller);
|
|
245
|
+
this._collect_operation();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// ------------------------ Timezone
|
|
249
|
+
set_timezone(timezone) {
|
|
250
|
+
const caller = "set_timezone";
|
|
251
|
+
this._helper._set_timezone(timezone, caller);
|
|
252
|
+
this._collect_operation();
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// ------------------------ Email
|
|
256
|
+
add_email(value) {
|
|
257
|
+
const caller = "add_email";
|
|
258
|
+
this._helper._add_email(value, caller);
|
|
259
|
+
this._collect_operation();
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
remove_email(value) {
|
|
263
|
+
const caller = "remove_email";
|
|
264
|
+
this._helper._remove_email(value, caller);
|
|
265
|
+
this._collect_operation();
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// ------------------------ SMS
|
|
269
|
+
add_sms(value) {
|
|
270
|
+
const caller = "add_sms";
|
|
271
|
+
this._helper._add_sms(value, caller);
|
|
272
|
+
this._collect_operation();
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
remove_sms(value) {
|
|
276
|
+
const caller = "remove_sms";
|
|
277
|
+
this._helper._remove_sms(value, caller);
|
|
278
|
+
this._collect_operation();
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// ------------------------ Whatsapp
|
|
282
|
+
add_whatsapp(value) {
|
|
283
|
+
const caller = "add_whatsapp";
|
|
284
|
+
this._helper._add_whatsapp(value, caller);
|
|
285
|
+
this._collect_operation();
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
remove_whatsapp(value) {
|
|
289
|
+
const caller = "remove_whatsapp";
|
|
290
|
+
this._helper._remove_whatsapp(value, caller);
|
|
291
|
+
this._collect_operation();
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// ------------------------ Androidpush
|
|
295
|
+
add_androidpush(value, provider = null) {
|
|
296
|
+
const caller = "add_androidpush";
|
|
297
|
+
this._helper._add_androidpush(value, provider, caller);
|
|
298
|
+
this._collect_operation();
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
remove_androidpush(value, provider = null) {
|
|
302
|
+
const caller = "remove_androidpush";
|
|
303
|
+
this._helper._remove_androidpush(value, provider, caller);
|
|
304
|
+
this._collect_operation();
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// ------------------------ Iospush [providers: apns]
|
|
308
|
+
add_iospush(value, provider = null) {
|
|
309
|
+
const caller = "add_iospush";
|
|
310
|
+
this._helper._add_iospush(value, provider, caller);
|
|
311
|
+
this._collect_operation();
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
remove_iospush(value, provider = null) {
|
|
315
|
+
const caller = "remove_iospush";
|
|
316
|
+
this._helper._remove_iospush(value, provider, caller);
|
|
317
|
+
this._collect_operation();
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// ------------------------ Webpush [providers: vapid]
|
|
321
|
+
add_webpush(value, provider = null) {
|
|
322
|
+
const caller = "add_webpush";
|
|
323
|
+
this._helper._add_webpush(value, provider, caller);
|
|
324
|
+
this._collect_operation();
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
remove_webpush(value, provider = null) {
|
|
328
|
+
const caller = "remove_webpush";
|
|
329
|
+
this._helper._remove_webpush(value, provider, caller);
|
|
330
|
+
this._collect_operation();
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// ------------------------ Slack
|
|
334
|
+
add_slack(value) {
|
|
335
|
+
const caller = "add_slack";
|
|
336
|
+
this._helper._add_slack(value, caller);
|
|
337
|
+
this._collect_operation();
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
remove_slack(value) {
|
|
341
|
+
const caller = "remove_slack";
|
|
342
|
+
this._helper._remove_slack(value, caller);
|
|
343
|
+
this._collect_operation();
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// ------------------------ MS Teams
|
|
347
|
+
add_ms_teams(value) {
|
|
348
|
+
const caller = "add_ms_teams";
|
|
349
|
+
this._helper._add_ms_teams(value, caller);
|
|
350
|
+
this._collect_operation();
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
remove_ms_teams(value) {
|
|
354
|
+
const caller = "remove_ms_teams";
|
|
355
|
+
this._helper._remove_ms_teams(value, caller);
|
|
356
|
+
this._collect_operation();
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
export default UserEdit;
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { 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
|
+
class _UserEditInternalHelper {
|
|
29
|
+
constructor() {
|
|
30
|
+
this.__dict_set = {};
|
|
31
|
+
this.__dict_set_once = {};
|
|
32
|
+
this.__dict_increment = {};
|
|
33
|
+
this.__dict_append = {};
|
|
34
|
+
this.__dict_remove = {};
|
|
35
|
+
this.__list_unset = [];
|
|
36
|
+
this.__errors = [];
|
|
37
|
+
this.__info = [];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
reset() {
|
|
41
|
+
this.__dict_set = {};
|
|
42
|
+
this.__dict_append = {};
|
|
43
|
+
this.__dict_remove = {};
|
|
44
|
+
this.__list_unset = [];
|
|
45
|
+
this.__dict_set_once = {};
|
|
46
|
+
this.__dict_increment = {};
|
|
47
|
+
this.__errors = [];
|
|
48
|
+
this.__info = [];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
get_operation_result() {
|
|
52
|
+
const operation = this.__form_operation();
|
|
53
|
+
const ret_val = {
|
|
54
|
+
errors: this.__errors,
|
|
55
|
+
info: this.__info,
|
|
56
|
+
operation: operation,
|
|
57
|
+
};
|
|
58
|
+
this.reset();
|
|
59
|
+
return ret_val;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
__form_operation() {
|
|
63
|
+
const event = {};
|
|
64
|
+
if (!is_empty(this.__dict_set)) {
|
|
65
|
+
event["$set"] = this.__dict_set;
|
|
66
|
+
}
|
|
67
|
+
if (!is_empty(this.__dict_set_once)) {
|
|
68
|
+
event["$set_once"] = this.__dict_set_once;
|
|
69
|
+
}
|
|
70
|
+
if (!is_empty(this.__dict_increment)) {
|
|
71
|
+
event["$add"] = this.__dict_increment;
|
|
72
|
+
}
|
|
73
|
+
if (!is_empty(this.__dict_append)) {
|
|
74
|
+
event["$append"] = this.__dict_append;
|
|
75
|
+
}
|
|
76
|
+
if (!is_empty(this.__dict_remove)) {
|
|
77
|
+
event["$remove"] = this.__dict_remove;
|
|
78
|
+
}
|
|
79
|
+
if (!is_empty(this.__list_unset)) {
|
|
80
|
+
event["$unset"] = this.__list_unset;
|
|
81
|
+
}
|
|
82
|
+
return event;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// ------------------------
|
|
86
|
+
__validate_key_basic(key, caller) {
|
|
87
|
+
if (!is_string(key)) {
|
|
88
|
+
this.__info.push(
|
|
89
|
+
`[${caller}] skipping key: ${key}. key must be a string`
|
|
90
|
+
);
|
|
91
|
+
return [key, false];
|
|
92
|
+
}
|
|
93
|
+
key = key.trim();
|
|
94
|
+
if (!key) {
|
|
95
|
+
this.__info.push(`[${caller}] skipping key: empty string`);
|
|
96
|
+
return [key, false];
|
|
97
|
+
}
|
|
98
|
+
return [key, true];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
__is_identity_key(key) {
|
|
102
|
+
return IDENT_KEYS_ALL.includes(key);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// -------------------------
|
|
106
|
+
_append_kv(key, val, kwargs = {}, caller = "append") {
|
|
107
|
+
const [k, is_k_valid] = this.__validate_key_basic(key, caller);
|
|
108
|
+
if (!is_k_valid) return;
|
|
109
|
+
if (this.__is_identity_key(k)) {
|
|
110
|
+
this.__add_identity(k, val, kwargs, caller);
|
|
111
|
+
} else {
|
|
112
|
+
this.__dict_append[k] = val;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
_remove_kv(key, val, kwargs = {}, caller = "remove") {
|
|
117
|
+
const [k, is_k_valid] = this.__validate_key_basic(key, caller);
|
|
118
|
+
if (!is_k_valid) return;
|
|
119
|
+
if (this.__is_identity_key(k)) {
|
|
120
|
+
this.__remove_identity(k, val, kwargs, caller);
|
|
121
|
+
} else {
|
|
122
|
+
this.__dict_remove[k] = val;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
_unset_k(key, caller = "unset") {
|
|
127
|
+
const [k, is_k_valid] = this.__validate_key_basic(key, caller);
|
|
128
|
+
if (!is_k_valid) return;
|
|
129
|
+
this.__list_unset.push(k);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
_set_kv(key, val, caller = "set") {
|
|
133
|
+
const [k, is_k_valid] = this.__validate_key_basic(key, caller);
|
|
134
|
+
if (!is_k_valid) return;
|
|
135
|
+
this.__dict_set[k] = val;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
_set_once_kv(key, val, caller = "set_once") {
|
|
139
|
+
const [k, is_k_valid] = this.__validate_key_basic(key, caller);
|
|
140
|
+
if (!is_k_valid) return;
|
|
141
|
+
this.__dict_set_once[k] = val;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
_increment_kv(key, val, caller = "increment") {
|
|
145
|
+
const [k, is_k_valid] = this.__validate_key_basic(key, caller);
|
|
146
|
+
if (!is_k_valid) return;
|
|
147
|
+
this.__dict_increment[k] = val;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
_set_preferred_language(lang_code, caller) {
|
|
151
|
+
this.__dict_set[KEY_PREFERRED_LANGUAGE] = lang_code;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
_set_timezone(timezone, caller) {
|
|
155
|
+
this.__dict_set[KEY_TIMEZONE] = timezone;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
__add_identity(key, val, kwargs, caller) {
|
|
159
|
+
const new_caller = `${caller}:${key}`;
|
|
160
|
+
switch (key) {
|
|
161
|
+
case IDENT_KEY_EMAIL:
|
|
162
|
+
this._add_email(val, new_caller);
|
|
163
|
+
break;
|
|
164
|
+
case IDENT_KEY_SMS:
|
|
165
|
+
this._add_sms(val, new_caller);
|
|
166
|
+
break;
|
|
167
|
+
case IDENT_KEY_WHATSAPP:
|
|
168
|
+
this._add_whatsapp(val, new_caller);
|
|
169
|
+
break;
|
|
170
|
+
case IDENT_KEY_ANDROIDPUSH:
|
|
171
|
+
this._add_androidpush(val, kwargs[KEY_ID_PROVIDER], new_caller);
|
|
172
|
+
break;
|
|
173
|
+
case IDENT_KEY_IOSPUSH:
|
|
174
|
+
this._add_iospush(val, kwargs[KEY_ID_PROVIDER], new_caller);
|
|
175
|
+
break;
|
|
176
|
+
case IDENT_KEY_WEBPUSH:
|
|
177
|
+
this._add_webpush(val, kwargs[KEY_ID_PROVIDER], new_caller);
|
|
178
|
+
break;
|
|
179
|
+
case IDENT_KEY_SLACK:
|
|
180
|
+
this._add_slack(val, new_caller);
|
|
181
|
+
break;
|
|
182
|
+
case IDENT_KEY_MS_TEAMS:
|
|
183
|
+
this._add_ms_teams(val, new_caller);
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
__remove_identity(key, val, kwargs, caller) {
|
|
189
|
+
const new_caller = `${caller}:${key}`;
|
|
190
|
+
switch (key) {
|
|
191
|
+
case IDENT_KEY_EMAIL:
|
|
192
|
+
this._remove_email(val, new_caller);
|
|
193
|
+
break;
|
|
194
|
+
case IDENT_KEY_SMS:
|
|
195
|
+
this._remove_sms(val, new_caller);
|
|
196
|
+
break;
|
|
197
|
+
case IDENT_KEY_WHATSAPP:
|
|
198
|
+
this._remove_whatsapp(val, new_caller);
|
|
199
|
+
break;
|
|
200
|
+
case IDENT_KEY_ANDROIDPUSH:
|
|
201
|
+
this._remove_androidpush(val, kwargs[KEY_ID_PROVIDER], new_caller);
|
|
202
|
+
break;
|
|
203
|
+
case IDENT_KEY_IOSPUSH:
|
|
204
|
+
this._remove_iospush(val, kwargs[KEY_ID_PROVIDER], new_caller);
|
|
205
|
+
break;
|
|
206
|
+
case IDENT_KEY_WEBPUSH:
|
|
207
|
+
this._remove_webpush(val, kwargs[KEY_ID_PROVIDER], new_caller);
|
|
208
|
+
break;
|
|
209
|
+
case IDENT_KEY_SLACK:
|
|
210
|
+
this._remove_slack(val, new_caller);
|
|
211
|
+
break;
|
|
212
|
+
case IDENT_KEY_MS_TEAMS:
|
|
213
|
+
this._remove_ms_teams(val, new_caller);
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// ------------------------ Email
|
|
219
|
+
_add_email(value, caller) {
|
|
220
|
+
this.__dict_append[IDENT_KEY_EMAIL] = value;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
_remove_email(value, caller) {
|
|
224
|
+
this.__dict_remove[IDENT_KEY_EMAIL] = value;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// ------------------------ SMS
|
|
228
|
+
_add_sms(value, caller) {
|
|
229
|
+
this.__dict_append[IDENT_KEY_SMS] = value;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
_remove_sms(value, caller) {
|
|
233
|
+
this.__dict_remove[IDENT_KEY_SMS] = value;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// ------------------------ Whatsapp
|
|
237
|
+
_add_whatsapp(value, caller) {
|
|
238
|
+
this.__dict_append[IDENT_KEY_WHATSAPP] = value;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
_remove_whatsapp(value, caller) {
|
|
242
|
+
this.__dict_remove[IDENT_KEY_WHATSAPP] = value;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// ------------------------ Androidpush
|
|
246
|
+
_add_androidpush(value, provider, caller) {
|
|
247
|
+
this.__dict_append[IDENT_KEY_ANDROIDPUSH] = value;
|
|
248
|
+
this.__dict_append[KEY_ID_PROVIDER] = provider;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
_remove_androidpush(value, provider, caller) {
|
|
252
|
+
this.__dict_remove[IDENT_KEY_ANDROIDPUSH] = value;
|
|
253
|
+
this.__dict_remove[KEY_ID_PROVIDER] = provider;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// ------------------------ Iospush
|
|
257
|
+
_add_iospush(value, provider, caller) {
|
|
258
|
+
this.__dict_append[IDENT_KEY_IOSPUSH] = value;
|
|
259
|
+
this.__dict_append[KEY_ID_PROVIDER] = provider;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
_remove_iospush(value, provider, caller) {
|
|
263
|
+
this.__dict_remove[IDENT_KEY_IOSPUSH] = value;
|
|
264
|
+
this.__dict_remove[KEY_ID_PROVIDER] = provider;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// ------------------------ Webpush
|
|
268
|
+
_add_webpush(value, provider, caller) {
|
|
269
|
+
this.__dict_append[IDENT_KEY_WEBPUSH] = value;
|
|
270
|
+
this.__dict_append[KEY_ID_PROVIDER] = provider;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
_remove_webpush(value, provider, caller) {
|
|
274
|
+
this.__dict_remove[IDENT_KEY_WEBPUSH] = value;
|
|
275
|
+
this.__dict_remove[KEY_ID_PROVIDER] = provider;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// ------------------------ Slack
|
|
279
|
+
_add_slack(value, caller) {
|
|
280
|
+
this.__dict_append[IDENT_KEY_SLACK] = value;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
_remove_slack(value, caller) {
|
|
284
|
+
this.__dict_remove[IDENT_KEY_SLACK] = value;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// ------------------------ MS Teams
|
|
288
|
+
_add_ms_teams(value, caller) {
|
|
289
|
+
this.__dict_append[IDENT_KEY_MS_TEAMS] = value;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
_remove_ms_teams(value, caller) {
|
|
293
|
+
this.__dict_remove[IDENT_KEY_MS_TEAMS] = value;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export default _UserEditInternalHelper;
|