@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
package/src/users_api.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import get_request_signature from "./signature";
|
|
2
|
+
import { SuprsendApiError } from "./utils";
|
|
3
|
+
import axios from "axios";
|
|
4
|
+
|
|
5
|
+
export default class UsersApi {
|
|
6
|
+
constructor(config) {
|
|
7
|
+
this.config = config;
|
|
8
|
+
this.list_url = `${this.config.base_url}v1/user/`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
get_headers() {
|
|
12
|
+
return {
|
|
13
|
+
"Content-Type": "application/json; charset=utf-8",
|
|
14
|
+
"User-Agent": this.config.user_agent,
|
|
15
|
+
Date: new Date().toISOString(), // Adjust to your header date format
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
validate_distinct_id(distinct_id) {
|
|
20
|
+
if (!distinct_id || distinct_id.trim() === "") {
|
|
21
|
+
throw new Error("missing distinct_id");
|
|
22
|
+
}
|
|
23
|
+
return distinct_id.trim();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
detail_url(distinct_id) {
|
|
27
|
+
return `${this.list_url}${encodeURIComponent(distinct_id)}/`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async get(distinct_id) {
|
|
31
|
+
const validated_distinct_id = this.validate_distinct_id(distinct_id);
|
|
32
|
+
const url = this.detail_url(validated_distinct_id);
|
|
33
|
+
const headers = this.get_headers();
|
|
34
|
+
const signature = get_request_signature(
|
|
35
|
+
url,
|
|
36
|
+
"GET",
|
|
37
|
+
"",
|
|
38
|
+
headers,
|
|
39
|
+
this.config.workspace_secret
|
|
40
|
+
);
|
|
41
|
+
headers["Authorization"] = `${this.config.workspace_key}:${signature}`;
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
const response = await axios.get(url, { headers });
|
|
45
|
+
return response.data;
|
|
46
|
+
} catch (err) {
|
|
47
|
+
throw new SuprsendApiError(err);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async delete(distinct_id) {
|
|
52
|
+
const validated_distinct_id = this.validate_distinct_id(distinct_id);
|
|
53
|
+
const url = this.detail_url(validated_distinct_id);
|
|
54
|
+
const headers = this.get_headers();
|
|
55
|
+
const signature = get_request_signature(
|
|
56
|
+
url,
|
|
57
|
+
"DELETE",
|
|
58
|
+
"",
|
|
59
|
+
headers,
|
|
60
|
+
this.config.workspace_secret
|
|
61
|
+
);
|
|
62
|
+
headers["Authorization"] = `${this.config.workspace_key}:${signature}`;
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
const response = await axios.delete(url, { headers });
|
|
66
|
+
if (response.status >= 200 && response.status < 300) {
|
|
67
|
+
return { success: true, status_code: response.status };
|
|
68
|
+
} else {
|
|
69
|
+
throw new SuprsendApiError(response.statusText);
|
|
70
|
+
}
|
|
71
|
+
} catch (err) {
|
|
72
|
+
throw new SuprsendApiError(err);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async get_objects_subscribed_to(distinct_id, options = {}) {
|
|
77
|
+
const validated_distinct_id = this.validate_distinct_id(distinct_id);
|
|
78
|
+
const params = new URLSearchParams(options).toString();
|
|
79
|
+
const url = this.detail_url(validated_distinct_id);
|
|
80
|
+
const subscription_url = `${url}subscribed_to/object/?${params}`;
|
|
81
|
+
const headers = this.get_headers();
|
|
82
|
+
const signature = get_request_signature(
|
|
83
|
+
subscription_url,
|
|
84
|
+
"GET",
|
|
85
|
+
"",
|
|
86
|
+
headers,
|
|
87
|
+
this.config.workspace_secret
|
|
88
|
+
);
|
|
89
|
+
headers["Authorization"] = `${this.config.workspace_key}:${signature}`;
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
const response = await axios.get(subscription_url, { headers });
|
|
93
|
+
return response.data;
|
|
94
|
+
} catch (err) {
|
|
95
|
+
throw new SuprsendApiError(err);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async get_lists_subscribed_to(distinct_id, options = {}) {
|
|
100
|
+
const validated_distinct_id = this.validate_distinct_id(distinct_id);
|
|
101
|
+
const params = new URLSearchParams(options).toString();
|
|
102
|
+
const url = this.detail_url(validated_distinct_id);
|
|
103
|
+
const subscription_url = `${url}subscribed_to/list/?${params}`;
|
|
104
|
+
const headers = this.get_headers();
|
|
105
|
+
const signature = get_request_signature(
|
|
106
|
+
subscription_url,
|
|
107
|
+
"GET",
|
|
108
|
+
"",
|
|
109
|
+
headers,
|
|
110
|
+
this.config.workspace_secret
|
|
111
|
+
);
|
|
112
|
+
headers["Authorization"] = `${this.config.workspace_key}:${signature}`;
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
const response = await axios.get(subscription_url, { headers });
|
|
116
|
+
return response.data;
|
|
117
|
+
} catch (err) {
|
|
118
|
+
throw new SuprsendApiError(err);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -238,31 +238,63 @@ declare namespace suprsend {
|
|
|
238
238
|
|
|
239
239
|
// objects
|
|
240
240
|
interface ObjectsApi {
|
|
241
|
-
list(
|
|
241
|
+
list(
|
|
242
|
+
object_type: string,
|
|
243
|
+
options?: { limit?: number; after?: string; before?: string }
|
|
244
|
+
): Promise<Dictionary>;
|
|
242
245
|
|
|
243
246
|
get(object_type: string, object_id: string): Promise<Dictionary>;
|
|
244
247
|
|
|
245
|
-
upsert(
|
|
248
|
+
upsert(
|
|
249
|
+
object_type: string,
|
|
250
|
+
object_id: string,
|
|
251
|
+
payload?: Dictionary
|
|
252
|
+
): Promise<Dictionary>;
|
|
246
253
|
|
|
247
|
-
edit(
|
|
254
|
+
edit(instance: ObjectEdit): Promise<Dictionary>;
|
|
255
|
+
|
|
256
|
+
edit(
|
|
257
|
+
object_type: string,
|
|
258
|
+
object_id: string,
|
|
259
|
+
payload?: Dictionary
|
|
260
|
+
): Promise<Dictionary>;
|
|
248
261
|
|
|
249
262
|
delete(object_type: string, object_id: string): Promise<Dictionary>;
|
|
250
263
|
|
|
251
|
-
bulk_delete(
|
|
264
|
+
bulk_delete(
|
|
265
|
+
object_type: string,
|
|
266
|
+
payload: { object_ids: string[] }
|
|
267
|
+
): Promise<Dictionary>;
|
|
268
|
+
|
|
269
|
+
get_subscriptions(
|
|
270
|
+
object_type: string,
|
|
271
|
+
object_id: string,
|
|
272
|
+
options?: { limit?: number; after?: string; before?: string }
|
|
273
|
+
): Promise<Dictionary>;
|
|
252
274
|
|
|
253
|
-
|
|
275
|
+
create_subscriptions(
|
|
276
|
+
object_type: string,
|
|
277
|
+
object_id: string,
|
|
278
|
+
payload: Dictionary
|
|
279
|
+
): Promise<Dictionary>;
|
|
254
280
|
|
|
255
|
-
|
|
281
|
+
delete_subscriptions(
|
|
282
|
+
object_type: string,
|
|
283
|
+
object_id: string,
|
|
284
|
+
payload: Dictionary
|
|
285
|
+
): Promise<Dictionary>;
|
|
256
286
|
|
|
257
|
-
|
|
287
|
+
get_objects_subscribed_to(
|
|
288
|
+
object_type: string,
|
|
289
|
+
object_id: string,
|
|
290
|
+
options?: { limit?: number; after?: string; before?: string }
|
|
291
|
+
): Promise<Dictionary>;
|
|
258
292
|
|
|
259
|
-
get_instance(object_type: string, object_id: string):
|
|
293
|
+
get_instance(object_type: string, object_id: string): ObjectEdit;
|
|
260
294
|
}
|
|
261
295
|
|
|
262
296
|
// subscribers
|
|
263
|
-
interface
|
|
264
|
-
save(): Promise<SResponse>;
|
|
265
|
-
|
|
297
|
+
interface ObjectEdit {
|
|
266
298
|
append(key: string | Dictionary, value?: any): void;
|
|
267
299
|
set(key: string | Dictionary, value?: any): void;
|
|
268
300
|
set_once(key: string | Dictionary, value?: any): void;
|
|
@@ -298,6 +330,22 @@ declare namespace suprsend {
|
|
|
298
330
|
remove_ms_teams(value: Dictionary): void;
|
|
299
331
|
}
|
|
300
332
|
|
|
333
|
+
interface UsersApi {
|
|
334
|
+
get(distinct_id: string): Promise<Dictionary>;
|
|
335
|
+
|
|
336
|
+
delete(distinct_id: string): Promise<Dictionary>;
|
|
337
|
+
|
|
338
|
+
get_objects_subscribed_to(
|
|
339
|
+
distinct_id: string,
|
|
340
|
+
options?: { limit?: number; after?: string; before?: string }
|
|
341
|
+
): Promise<Dictionary>;
|
|
342
|
+
|
|
343
|
+
get_lists_subscribed_to(
|
|
344
|
+
distinct_id: string,
|
|
345
|
+
options?: { limit?: number; after?: string; before?: string }
|
|
346
|
+
): Promise<Dictionary>;
|
|
347
|
+
}
|
|
348
|
+
|
|
301
349
|
interface Suprsend {
|
|
302
350
|
new (
|
|
303
351
|
workspace_env: string,
|
|
@@ -323,6 +371,8 @@ declare namespace suprsend {
|
|
|
323
371
|
|
|
324
372
|
objects: ObjectsApi;
|
|
325
373
|
|
|
374
|
+
users: UsersApi;
|
|
375
|
+
|
|
326
376
|
add_attachment(
|
|
327
377
|
body: Dictionary,
|
|
328
378
|
file_path: string,
|