@suprsend/node-sdk 1.11.0 → 1.12.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/index.js +4 -2
- package/dist/object_edit.js +358 -0
- package/dist/{object_helper.js → object_edit_internal_helper.js} +34 -37
- package/dist/objects_api.js +576 -0
- package/dist/subscriber.js +2 -1
- package/dist/subscriber_helper.js +49 -114
- package/dist/users_api.js +233 -0
- package/package.json +1 -1
- package/src/index.js +3 -1
- package/src/object_edit.js +308 -0
- package/src/object_edit_internal_helper.js +590 -0
- package/src/objects_api.js +316 -0
- package/src/subscriber.js +2 -1
- package/src/subscriber_helper.js +24 -98
- package/src/users_api.js +121 -0
- package/types/index.d.ts +61 -11
- package/dist/object.js +0 -902
- package/src/object.js +0 -618
- 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 = "fcm") {
|
|
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 = "fcm") {
|
|
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 = "apns") {
|
|
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 = "apns") {
|
|
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 = "vapid") {
|
|
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 = "vapid") {
|
|
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
|
+
}
|