@suprsend/node-sdk 1.9.1 → 1.11.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 +601 -13
- package/dist/constants.js +2 -4
- package/dist/index.js +14 -5
- package/dist/object.js +902 -0
- package/dist/object_helper.js +659 -0
- package/dist/request_json/workflow.json +4 -0
- package/dist/request_json/workflow_trigger.json +360 -0
- package/dist/subscriber.js +7 -0
- package/dist/subscriber_helper.js +8 -2
- package/dist/utils.js +20 -0
- package/dist/workflow.js +1 -1
- package/dist/workflow_api.js +108 -0
- package/dist/workflow_request.js +93 -0
- package/dist/workflow_trigger_bulk.js +316 -0
- package/package.json +1 -1
- package/src/constants.js +0 -2
- package/src/index.js +18 -7
- package/src/object.js +618 -0
- package/src/object_helper.js +593 -0
- package/src/request_json/workflow.json +4 -0
- package/src/request_json/workflow_trigger.json +360 -0
- package/src/subscriber.js +6 -0
- package/src/subscriber_helper.js +7 -1
- package/src/utils.js +20 -0
- package/src/workflow.js +1 -1
- package/src/workflow_api.js +71 -0
- package/src/workflow_request.js +92 -0
- package/src/workflow_trigger_bulk.js +218 -0
- package/types/index.d.ts +97 -1
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"$id": "http://github.com/suprsend/suprsend-node-sdk/request_json/workflow_trigger.json",
|
|
4
|
+
"title": "workflow_trigger",
|
|
5
|
+
"description": "Json schema for workflow trigger request",
|
|
6
|
+
"$comment": "Json schema for workflow trigger request",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"$idempotency_key": {
|
|
10
|
+
"type": ["string", "null"],
|
|
11
|
+
"maxLength": 255,
|
|
12
|
+
"description": "unique id provided by client for request"
|
|
13
|
+
},
|
|
14
|
+
"tenant_id": {
|
|
15
|
+
"type": ["string", "null"],
|
|
16
|
+
"maxLength": 64,
|
|
17
|
+
"description": "tenant id for workflow to be run in context of a tenant"
|
|
18
|
+
},
|
|
19
|
+
"workflow": {
|
|
20
|
+
"$ref": "#/definitions/non_empty_string",
|
|
21
|
+
"description": "workflow slug"
|
|
22
|
+
},
|
|
23
|
+
"actor": {
|
|
24
|
+
"oneOf": [
|
|
25
|
+
{ "$ref": "#/definitions/non_empty_string" },
|
|
26
|
+
{ "$ref": "#/definitions/user_setting" }
|
|
27
|
+
],
|
|
28
|
+
"description": "actor id/object of workflow"
|
|
29
|
+
},
|
|
30
|
+
"recipients": {
|
|
31
|
+
"type": "array",
|
|
32
|
+
"items": {
|
|
33
|
+
"oneOf": [
|
|
34
|
+
{ "$ref": "#/definitions/non_empty_string" },
|
|
35
|
+
{ "$ref": "#/definitions/user_setting" }
|
|
36
|
+
]
|
|
37
|
+
},
|
|
38
|
+
"minItems": 1,
|
|
39
|
+
"maxItems": 100,
|
|
40
|
+
"description": "list of recipient id/object to run workflow for. At least 1 user is required"
|
|
41
|
+
},
|
|
42
|
+
"data": {
|
|
43
|
+
"type": "object",
|
|
44
|
+
"description": "variables to be used in workflow. e.g replacing templates variables."
|
|
45
|
+
},
|
|
46
|
+
"metadata": {
|
|
47
|
+
"type": "object",
|
|
48
|
+
"description": "metadata of request"
|
|
49
|
+
},
|
|
50
|
+
"cancellation_key": {
|
|
51
|
+
"type": ["string", "null"],
|
|
52
|
+
"maxLength": 255,
|
|
53
|
+
"description": "cancellation key for workflow"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"required": ["workflow", "recipients", "data"],
|
|
57
|
+
"additionalProperties": false,
|
|
58
|
+
"definitions": {
|
|
59
|
+
"non_empty_string": {
|
|
60
|
+
"type": "string",
|
|
61
|
+
"minLength": 1
|
|
62
|
+
},
|
|
63
|
+
"mobile_number_pattern": {
|
|
64
|
+
"type": "string",
|
|
65
|
+
"minLength": 8,
|
|
66
|
+
"pattern": "^\\+[0-9\\s]+",
|
|
67
|
+
"message": {
|
|
68
|
+
"required": "Either a mobile-number or an array of mobile-numbers. e.g [\"+41446681800\"]",
|
|
69
|
+
"pattern": "number must start with + and must contain country code. e.g. +41446681800"
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"email_pattern": {
|
|
73
|
+
"type": "string",
|
|
74
|
+
"format": "email",
|
|
75
|
+
"pattern": "^\\S+@\\S+\\.\\S+$",
|
|
76
|
+
"description": "email of an user",
|
|
77
|
+
"minLength": 6,
|
|
78
|
+
"maxLength": 127,
|
|
79
|
+
"message": {
|
|
80
|
+
"required": "",
|
|
81
|
+
"pattern": "value in email format required. e.g. user@example.com"
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
"slack_setting": {
|
|
85
|
+
"type": "object",
|
|
86
|
+
"properties": {
|
|
87
|
+
"access_token": {
|
|
88
|
+
"type": "string",
|
|
89
|
+
"pattern": "^xox",
|
|
90
|
+
"description": "Bot User OAuth Access Token with prefix xoxb-"
|
|
91
|
+
},
|
|
92
|
+
"channel_id": {
|
|
93
|
+
"type": "string",
|
|
94
|
+
"pattern": "^[cC][a-zA-Z0-9]+$",
|
|
95
|
+
"description": "slack channel id. the bot must be part of it",
|
|
96
|
+
"message": {
|
|
97
|
+
"required": "",
|
|
98
|
+
"pattern": "Slack Channel id format: CXXXXXXXXX"
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
"user_id": {
|
|
102
|
+
"type": "string",
|
|
103
|
+
"pattern": "^[uUwW][a-zA-Z0-9]+$",
|
|
104
|
+
"description": "slack member id of user",
|
|
105
|
+
"message": {
|
|
106
|
+
"required": "",
|
|
107
|
+
"pattern": "Slack Member id format: [U|W]XXXXXXXXX"
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
"email": {
|
|
111
|
+
"$ref": "#/definitions/email_pattern"
|
|
112
|
+
},
|
|
113
|
+
"incoming_webhook": {
|
|
114
|
+
"type": "object",
|
|
115
|
+
"properties": {
|
|
116
|
+
"url": {
|
|
117
|
+
"type": "string",
|
|
118
|
+
"format": "uri",
|
|
119
|
+
"pattern": "^https://hooks.slack.com/",
|
|
120
|
+
"description": "incoming webhook url. e.g https://hooks.slack.com/TXXXXX/BXXXXX/XXXXXXXXXX"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
"additionalProperties": false
|
|
126
|
+
},
|
|
127
|
+
"ms_teams_setting": {
|
|
128
|
+
"type": "object",
|
|
129
|
+
"properties": {
|
|
130
|
+
"tenant_id": {
|
|
131
|
+
"type": "string",
|
|
132
|
+
"description": "ms teams tenant id"
|
|
133
|
+
},
|
|
134
|
+
"service_url": {
|
|
135
|
+
"type": "string",
|
|
136
|
+
"format": "uri",
|
|
137
|
+
"pattern": "^https://smba.trafficmanager.net/",
|
|
138
|
+
"description": "service webhook url. e.g https://smba.trafficmanager.net/XXXXXXXXXX"
|
|
139
|
+
},
|
|
140
|
+
"conversation_id": {
|
|
141
|
+
"type": "string",
|
|
142
|
+
"description": "ms team conversation id"
|
|
143
|
+
},
|
|
144
|
+
"user_id": {
|
|
145
|
+
"type": "string",
|
|
146
|
+
"description": "ms team user id"
|
|
147
|
+
},
|
|
148
|
+
"incoming_webhook": {
|
|
149
|
+
"type": "object",
|
|
150
|
+
"properties": {
|
|
151
|
+
"url": {
|
|
152
|
+
"type": "string",
|
|
153
|
+
"format": "uri",
|
|
154
|
+
"description": "incoming webhook url. e.g https://XXXXX.webhook.office.com/webhookb2/XXXXXXXXXX@XXXXXXXXXX/IncomingWebhook/XXXXXXXXXX/XXXXXXXXXX"
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
"additionalProperties": false
|
|
160
|
+
},
|
|
161
|
+
"androidpush_settings": {
|
|
162
|
+
"type": "object",
|
|
163
|
+
"properties": {
|
|
164
|
+
"token": {
|
|
165
|
+
"type": "string",
|
|
166
|
+
"minLength": 1,
|
|
167
|
+
"description": "androidpush token"
|
|
168
|
+
},
|
|
169
|
+
"provider": {
|
|
170
|
+
"type": "string",
|
|
171
|
+
"enum": ["fcm", "xiaomi", "oppo"],
|
|
172
|
+
"description": "androidpush token provider(fcm/xiaomi)"
|
|
173
|
+
},
|
|
174
|
+
"device_id": { "type": ["string", "null"] }
|
|
175
|
+
},
|
|
176
|
+
"required": ["token", "provider"],
|
|
177
|
+
"additionalProperties": false
|
|
178
|
+
},
|
|
179
|
+
"iospush_settings": {
|
|
180
|
+
"type": "object",
|
|
181
|
+
"properties": {
|
|
182
|
+
"token": {
|
|
183
|
+
"type": "string",
|
|
184
|
+
"minLength": 1,
|
|
185
|
+
"description": "iospush token"
|
|
186
|
+
},
|
|
187
|
+
"provider": {
|
|
188
|
+
"type": "string",
|
|
189
|
+
"enum": ["apns"],
|
|
190
|
+
"description": "iospush token provider(apns)"
|
|
191
|
+
},
|
|
192
|
+
"device_id": { "type": ["string", "null"] }
|
|
193
|
+
},
|
|
194
|
+
"required": ["token", "provider"],
|
|
195
|
+
"additionalProperties": false
|
|
196
|
+
},
|
|
197
|
+
"user_setting": {
|
|
198
|
+
"type": "object",
|
|
199
|
+
"properties": {
|
|
200
|
+
"is_transient": {
|
|
201
|
+
"type": ["boolean", "null"],
|
|
202
|
+
"description": "indicates whether this is a transient user. Profiles are not created for such users."
|
|
203
|
+
},
|
|
204
|
+
"distinct_id": {
|
|
205
|
+
"type": ["string", "null"],
|
|
206
|
+
"description": "distinct_id: Id which uniquely identifies a user in your app"
|
|
207
|
+
},
|
|
208
|
+
"$preferred_language": {
|
|
209
|
+
"type": ["string", "null"],
|
|
210
|
+
"description": "preferred_language: 2-letter language code in ISO 639-1 Alpha-2 code format. e.g en (for English)"
|
|
211
|
+
},
|
|
212
|
+
"$timezone": {
|
|
213
|
+
"type": ["string", "null"],
|
|
214
|
+
"description": "timezone: in IANA timezone format e.g 'America/Los_Angeles'"
|
|
215
|
+
},
|
|
216
|
+
"$channels": {
|
|
217
|
+
"type": "array",
|
|
218
|
+
"items": {
|
|
219
|
+
"type": "string",
|
|
220
|
+
"enum": [
|
|
221
|
+
"androidpush",
|
|
222
|
+
"iospush",
|
|
223
|
+
"webpush",
|
|
224
|
+
"email",
|
|
225
|
+
"sms",
|
|
226
|
+
"whatsapp",
|
|
227
|
+
"slack",
|
|
228
|
+
"inbox",
|
|
229
|
+
"messenger",
|
|
230
|
+
"ms_teams"
|
|
231
|
+
]
|
|
232
|
+
},
|
|
233
|
+
"minItems": 0,
|
|
234
|
+
"description": "user preferred channels. notification will be tried only on specified channels e.g ['email', 'sms']"
|
|
235
|
+
},
|
|
236
|
+
"$email": {
|
|
237
|
+
"oneOf": [
|
|
238
|
+
{ "$ref": "#/definitions/email_pattern" },
|
|
239
|
+
{
|
|
240
|
+
"type": "array",
|
|
241
|
+
"uniqueItems": false,
|
|
242
|
+
"maxItems": 10,
|
|
243
|
+
"minItems": 1,
|
|
244
|
+
"items": { "$ref": "#/definitions/email_pattern" }
|
|
245
|
+
}
|
|
246
|
+
]
|
|
247
|
+
},
|
|
248
|
+
"$sms": {
|
|
249
|
+
"oneOf": [
|
|
250
|
+
{ "$ref": "#/definitions/mobile_number_pattern" },
|
|
251
|
+
{
|
|
252
|
+
"type": "array",
|
|
253
|
+
"uniqueItems": false,
|
|
254
|
+
"maxItems": 10,
|
|
255
|
+
"minItems": 1,
|
|
256
|
+
"items": { "$ref": "#/definitions/mobile_number_pattern" }
|
|
257
|
+
}
|
|
258
|
+
]
|
|
259
|
+
},
|
|
260
|
+
"$androidpush": {
|
|
261
|
+
"oneOf": [
|
|
262
|
+
{ "$ref": "#/definitions/androidpush_settings" },
|
|
263
|
+
{
|
|
264
|
+
"type": "array",
|
|
265
|
+
"uniqueItems": false,
|
|
266
|
+
"maxItems": 10,
|
|
267
|
+
"minItems": 1,
|
|
268
|
+
"items": { "$ref": "#/definitions/androidpush_settings" }
|
|
269
|
+
}
|
|
270
|
+
]
|
|
271
|
+
},
|
|
272
|
+
"$iospush": {
|
|
273
|
+
"oneOf": [
|
|
274
|
+
{ "$ref": "#/definitions/iospush_settings" },
|
|
275
|
+
{
|
|
276
|
+
"type": "array",
|
|
277
|
+
"uniqueItems": false,
|
|
278
|
+
"maxItems": 10,
|
|
279
|
+
"minItems": 1,
|
|
280
|
+
"items": { "$ref": "#/definitions/iospush_settings" }
|
|
281
|
+
}
|
|
282
|
+
]
|
|
283
|
+
},
|
|
284
|
+
"$whatsapp": {
|
|
285
|
+
"oneOf": [
|
|
286
|
+
{ "$ref": "#/definitions/mobile_number_pattern" },
|
|
287
|
+
{
|
|
288
|
+
"type": "array",
|
|
289
|
+
"uniqueItems": false,
|
|
290
|
+
"maxItems": 10,
|
|
291
|
+
"minItems": 1,
|
|
292
|
+
"items": { "$ref": "#/definitions/mobile_number_pattern" }
|
|
293
|
+
}
|
|
294
|
+
]
|
|
295
|
+
},
|
|
296
|
+
"$webpush": {
|
|
297
|
+
"oneOf": [
|
|
298
|
+
{ "type": "object", "minProperties": 1 },
|
|
299
|
+
{
|
|
300
|
+
"type": "array",
|
|
301
|
+
"uniqueItems": false,
|
|
302
|
+
"maxItems": 10,
|
|
303
|
+
"minItems": 1,
|
|
304
|
+
"items": { "type": "object", "minProperties": 1 }
|
|
305
|
+
}
|
|
306
|
+
]
|
|
307
|
+
},
|
|
308
|
+
"$slack": {
|
|
309
|
+
"oneOf": [
|
|
310
|
+
{ "$ref": "#/definitions/slack_setting" },
|
|
311
|
+
{
|
|
312
|
+
"type": "array",
|
|
313
|
+
"uniqueItems": false,
|
|
314
|
+
"maxItems": 10,
|
|
315
|
+
"minItems": 1,
|
|
316
|
+
"items": { "$ref": "#/definitions/slack_setting" }
|
|
317
|
+
}
|
|
318
|
+
]
|
|
319
|
+
},
|
|
320
|
+
"$ms_teams": {
|
|
321
|
+
"oneOf": [
|
|
322
|
+
{ "$ref": "#/definitions/ms_teams_setting" },
|
|
323
|
+
{
|
|
324
|
+
"type": "array",
|
|
325
|
+
"uniqueItems": false,
|
|
326
|
+
"maxItems": 10,
|
|
327
|
+
"minItems": 1,
|
|
328
|
+
"items": { "$ref": "#/definitions/ms_teams_setting" }
|
|
329
|
+
}
|
|
330
|
+
]
|
|
331
|
+
},
|
|
332
|
+
"$inbox": {
|
|
333
|
+
"oneOf": [
|
|
334
|
+
{ "$ref": "#/definitions/non_empty_string" },
|
|
335
|
+
{
|
|
336
|
+
"type": "array",
|
|
337
|
+
"uniqueItems": false,
|
|
338
|
+
"maxItems": 10,
|
|
339
|
+
"minItems": 1,
|
|
340
|
+
"items": { "$ref": "#/definitions/non_empty_string" }
|
|
341
|
+
}
|
|
342
|
+
]
|
|
343
|
+
},
|
|
344
|
+
"$messenger": {
|
|
345
|
+
"oneOf": [
|
|
346
|
+
{ "$ref": "#/definitions/non_empty_string" },
|
|
347
|
+
{
|
|
348
|
+
"type": "array",
|
|
349
|
+
"uniqueItems": false,
|
|
350
|
+
"maxItems": 10,
|
|
351
|
+
"minItems": 1,
|
|
352
|
+
"items": { "$ref": "#/definitions/non_empty_string" }
|
|
353
|
+
}
|
|
354
|
+
]
|
|
355
|
+
}
|
|
356
|
+
},
|
|
357
|
+
"required": []
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
package/dist/subscriber.js
CHANGED
|
@@ -362,6 +362,13 @@ var Subscriber = /*#__PURE__*/function () {
|
|
|
362
362
|
this._helper._set_preferred_language(lang_code, caller);
|
|
363
363
|
this._collect_event();
|
|
364
364
|
}
|
|
365
|
+
}, {
|
|
366
|
+
key: "set_timezone",
|
|
367
|
+
value: function set_timezone(timezone) {
|
|
368
|
+
var caller = "set_timezone";
|
|
369
|
+
this._helper._set_timezone(timezone, caller);
|
|
370
|
+
this._collect_event();
|
|
371
|
+
}
|
|
365
372
|
}, {
|
|
366
373
|
key: "add_email",
|
|
367
374
|
value: function add_email(email) {
|
|
@@ -22,7 +22,8 @@ var IDENT_KEY_MS_TEAMS = "$ms_teams";
|
|
|
22
22
|
var IDENT_KEYS_ALL = [IDENT_KEY_EMAIL, IDENT_KEY_SMS, IDENT_KEY_ANDROIDPUSH, IDENT_KEY_IOSPUSH, IDENT_KEY_WHATSAPP, IDENT_KEY_WEBPUSH, IDENT_KEY_SLACK, IDENT_KEY_MS_TEAMS];
|
|
23
23
|
var KEY_PUSHVENDOR = "$pushvendor";
|
|
24
24
|
var KEY_PREFERRED_LANGUAGE = "$preferred_language";
|
|
25
|
-
var
|
|
25
|
+
var KEY_TIMEZONE = "$timezone";
|
|
26
|
+
var OTHER_RESERVED_KEYS = ["$messenger", "$inbox", KEY_PUSHVENDOR, "$device_id", "$insert_id", "$time", "$set", "$set_once", "$add", "$append", "$remove", "$unset", "$identify", "$anon_id", "$identified_id", KEY_PREFERRED_LANGUAGE, KEY_TIMEZONE, "$notification_delivered", "$notification_dismiss", "$notification_clicked"];
|
|
26
27
|
var SUPER_PROPERTY_KEYS = ["$app_version_string", "$app_build_number", "$brand", "$carrier", "$manufacturer", "$model", "$os", "$ss_sdk_version", "$insert_id", "$time"];
|
|
27
28
|
var ALL_RESERVED_KEYS = [].concat(SUPER_PROPERTY_KEYS, OTHER_RESERVED_KEYS, IDENT_KEYS_ALL);
|
|
28
29
|
var EMAIL_REGEX = /\S+@\S+\.\S+/;
|
|
@@ -237,6 +238,11 @@ var _SubscriberInternalHelper = /*#__PURE__*/function () {
|
|
|
237
238
|
}
|
|
238
239
|
this.__dict_set[KEY_PREFERRED_LANGUAGE] = lang_code;
|
|
239
240
|
}
|
|
241
|
+
}, {
|
|
242
|
+
key: "_set_timezone",
|
|
243
|
+
value: function _set_timezone(timezone, caller) {
|
|
244
|
+
this.__dict_set[KEY_TIMEZONE] = timezone;
|
|
245
|
+
}
|
|
240
246
|
}, {
|
|
241
247
|
key: "__add_identity",
|
|
242
248
|
value: function __add_identity(key, value, args, caller) {
|
|
@@ -306,7 +312,7 @@ var _SubscriberInternalHelper = /*#__PURE__*/function () {
|
|
|
306
312
|
}, {
|
|
307
313
|
key: "__check_ident_val_string",
|
|
308
314
|
value: function __check_ident_val_string(value, caller) {
|
|
309
|
-
var message = "value must a string with proper value";
|
|
315
|
+
var message = "value must be a string with proper value";
|
|
310
316
|
if (!(0, _utils.is_string)(value)) {
|
|
311
317
|
this.__errors.push("[".concat(caller, "] ").concat(message));
|
|
312
318
|
return [value, false];
|
package/dist/utils.js
CHANGED
|
@@ -21,6 +21,7 @@ exports.uuid = uuid;
|
|
|
21
21
|
exports.validate_list_broadcast_body_schema = validate_list_broadcast_body_schema;
|
|
22
22
|
exports.validate_track_event_schema = validate_track_event_schema;
|
|
23
23
|
exports.validate_workflow_body_schema = validate_workflow_body_schema;
|
|
24
|
+
exports.validate_workflow_trigger_body_schema = validate_workflow_trigger_body_schema;
|
|
24
25
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
25
26
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
26
27
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
@@ -39,6 +40,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
39
40
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
|
40
41
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
41
42
|
var workflow_schema = require("./request_json/workflow.json");
|
|
43
|
+
var workflow_trigger_schema = require("./request_json/workflow_trigger.json");
|
|
42
44
|
var event_schema = require("./request_json/event.json");
|
|
43
45
|
var list_broadcast_schema = require("./request_json/list_broadcast.json");
|
|
44
46
|
function base64Encode(file) {
|
|
@@ -156,6 +158,24 @@ function validate_workflow_body_schema(body) {
|
|
|
156
158
|
throw new SuprsendError(error_msg);
|
|
157
159
|
}
|
|
158
160
|
}
|
|
161
|
+
function validate_workflow_trigger_body_schema(body) {
|
|
162
|
+
if (!(body !== null && body !== void 0 && body.data)) {
|
|
163
|
+
body.data = {};
|
|
164
|
+
}
|
|
165
|
+
if (!(body.data instanceof Object)) {
|
|
166
|
+
throw new InputValueError("data must be a object");
|
|
167
|
+
}
|
|
168
|
+
var schema = workflow_trigger_schema;
|
|
169
|
+
var v = new _jsonschema.Validator();
|
|
170
|
+
var validated_data = v.validate(body, schema);
|
|
171
|
+
if (validated_data.valid) {
|
|
172
|
+
return body;
|
|
173
|
+
} else {
|
|
174
|
+
var error_obj = validated_data.errors[0];
|
|
175
|
+
var error_msg = "".concat(error_obj.property, " ").concat(error_obj.message);
|
|
176
|
+
throw new SuprsendError(error_msg);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
159
179
|
function validate_track_event_schema(body) {
|
|
160
180
|
if (!(body !== null && body !== void 0 && body.properties)) {
|
|
161
181
|
body.properties = {};
|
package/dist/workflow.js
CHANGED
|
@@ -43,7 +43,7 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
43
43
|
}
|
|
44
44
|
// if body["data"] is not a dict, not raising error while adding attachment.
|
|
45
45
|
if (!(this.body["data"] instanceof Object)) {
|
|
46
|
-
console.log("WARNING: attachment cannot be added. please make sure body['data'] is a dictionary. Workflow ".concat(JSON.stringify(this.as_json())));
|
|
46
|
+
console.log("WARNING: attachment cannot be added. please make sure body['data'] is a dictionary. Workflow ".concat(JSON.stringify(JSON.stringify(this.as_json()))));
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
49
|
var attachment = (0, _attachment["default"])(file_path, file_name, ignore_if_error);
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports["default"] = void 0;
|
|
8
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
12
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
+
var _axios = _interopRequireDefault(require("axios"));
|
|
14
|
+
var _signature = _interopRequireDefault(require("./signature"));
|
|
15
|
+
var _workflow_trigger_bulk = require("./workflow_trigger_bulk");
|
|
16
|
+
var _workflow_request = _interopRequireDefault(require("./workflow_request"));
|
|
17
|
+
var WorkflowsApi = /*#__PURE__*/function () {
|
|
18
|
+
function WorkflowsApi(config) {
|
|
19
|
+
(0, _classCallCheck2["default"])(this, WorkflowsApi);
|
|
20
|
+
this.config = config;
|
|
21
|
+
this.metadata = {
|
|
22
|
+
"User-Agent": this.config.user_agent
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
(0, _createClass2["default"])(WorkflowsApi, [{
|
|
26
|
+
key: "_get_headers",
|
|
27
|
+
value: function _get_headers() {
|
|
28
|
+
return {
|
|
29
|
+
"Content-Type": "application/json; charset=utf-8",
|
|
30
|
+
Date: new Date().toUTCString(),
|
|
31
|
+
"User-Agent": this.config.user_agent
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}, {
|
|
35
|
+
key: "trigger",
|
|
36
|
+
value: function () {
|
|
37
|
+
var _trigger = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(workflow) {
|
|
38
|
+
var is_part_of_bulk, _workflow$get_final_j, _workflow$get_final_j2, workflow_body, body_size, headers, content_text, url, signature, resp, ok_response, _err$response, _err$response2;
|
|
39
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
40
|
+
while (1) {
|
|
41
|
+
switch (_context.prev = _context.next) {
|
|
42
|
+
case 0:
|
|
43
|
+
is_part_of_bulk = false;
|
|
44
|
+
_workflow$get_final_j = workflow.get_final_json(this.config, is_part_of_bulk), _workflow$get_final_j2 = (0, _slicedToArray2["default"])(_workflow$get_final_j, 2), workflow_body = _workflow$get_final_j2[0], body_size = _workflow$get_final_j2[1];
|
|
45
|
+
_context.prev = 2;
|
|
46
|
+
headers = this._get_headers();
|
|
47
|
+
content_text = JSON.stringify(workflow_body);
|
|
48
|
+
url = "".concat(this.config.base_url, "trigger/");
|
|
49
|
+
signature = (0, _signature["default"])(url, "POST", content_text, headers, this.config.workspace_secret);
|
|
50
|
+
headers["Authorization"] = "".concat(this.config.workspace_key, ":").concat(signature);
|
|
51
|
+
_context.next = 10;
|
|
52
|
+
return _axios["default"].post(url, content_text, {
|
|
53
|
+
headers: headers,
|
|
54
|
+
transformResponse: [function (data) {
|
|
55
|
+
return data;
|
|
56
|
+
}] // dont assume type of response
|
|
57
|
+
});
|
|
58
|
+
case 10:
|
|
59
|
+
resp = _context.sent;
|
|
60
|
+
ok_response = Math.floor(resp.status / 100) === 2;
|
|
61
|
+
return _context.abrupt("return", {
|
|
62
|
+
success: ok_response,
|
|
63
|
+
status: ok_response ? "success" : "fail",
|
|
64
|
+
status_code: resp.status,
|
|
65
|
+
message: resp.data
|
|
66
|
+
});
|
|
67
|
+
case 15:
|
|
68
|
+
_context.prev = 15;
|
|
69
|
+
_context.t0 = _context["catch"](2);
|
|
70
|
+
if (!(_context.t0 !== null && _context.t0 !== void 0 && _context.t0.response)) {
|
|
71
|
+
_context.next = 21;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
return _context.abrupt("return", {
|
|
75
|
+
success: false,
|
|
76
|
+
status: "fail",
|
|
77
|
+
status_code: (_context.t0 === null || _context.t0 === void 0 ? void 0 : (_err$response = _context.t0.response) === null || _err$response === void 0 ? void 0 : _err$response.status) || 500,
|
|
78
|
+
message: _context.t0 === null || _context.t0 === void 0 ? void 0 : (_err$response2 = _context.t0.response) === null || _err$response2 === void 0 ? void 0 : _err$response2.data
|
|
79
|
+
});
|
|
80
|
+
case 21:
|
|
81
|
+
return _context.abrupt("return", {
|
|
82
|
+
success: false,
|
|
83
|
+
status: "fail",
|
|
84
|
+
status_code: 500,
|
|
85
|
+
message: _context.t0.message
|
|
86
|
+
});
|
|
87
|
+
case 22:
|
|
88
|
+
case "end":
|
|
89
|
+
return _context.stop();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}, _callee, this, [[2, 15]]);
|
|
93
|
+
}));
|
|
94
|
+
function trigger(_x) {
|
|
95
|
+
return _trigger.apply(this, arguments);
|
|
96
|
+
}
|
|
97
|
+
return trigger;
|
|
98
|
+
}()
|
|
99
|
+
}, {
|
|
100
|
+
key: "bulk_trigger_instance",
|
|
101
|
+
value: function bulk_trigger_instance() {
|
|
102
|
+
return new _workflow_trigger_bulk.BulkWorkflowTrigger(this.config);
|
|
103
|
+
}
|
|
104
|
+
}]);
|
|
105
|
+
return WorkflowsApi;
|
|
106
|
+
}();
|
|
107
|
+
exports["default"] = WorkflowsApi;
|
|
108
|
+
module.exports = exports.default;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports["default"] = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
10
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
12
|
+
var _utils = require("./utils");
|
|
13
|
+
var _attachment = _interopRequireDefault(require("./attachment"));
|
|
14
|
+
var _constants = require("./constants");
|
|
15
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
16
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
17
|
+
var WorkflowTriggerRequest = /*#__PURE__*/function () {
|
|
18
|
+
function WorkflowTriggerRequest(body) {
|
|
19
|
+
var kwargs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
20
|
+
(0, _classCallCheck2["default"])(this, WorkflowTriggerRequest);
|
|
21
|
+
if (!((0, _typeof2["default"])(body) === "object" && !Array.isArray(body))) {
|
|
22
|
+
throw new _utils.InputValueError("WorkflowTriggerRequest body must be a JSON object/dictionary");
|
|
23
|
+
}
|
|
24
|
+
this.body = body;
|
|
25
|
+
this.idempotency_key = kwargs === null || kwargs === void 0 ? void 0 : kwargs.idempotency_key;
|
|
26
|
+
this.tenant_id = kwargs === null || kwargs === void 0 ? void 0 : kwargs.tenant_id;
|
|
27
|
+
this.cancellation_key = kwargs === null || kwargs === void 0 ? void 0 : kwargs.cancellation_key;
|
|
28
|
+
}
|
|
29
|
+
(0, _createClass2["default"])(WorkflowTriggerRequest, [{
|
|
30
|
+
key: "add_attachment",
|
|
31
|
+
value: function add_attachment() {
|
|
32
|
+
var _kwargs$ignore_if_err;
|
|
33
|
+
var file_path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
|
|
34
|
+
var kwargs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
35
|
+
var file_name = kwargs === null || kwargs === void 0 ? void 0 : kwargs.file_name;
|
|
36
|
+
var ignore_if_error = (_kwargs$ignore_if_err = kwargs === null || kwargs === void 0 ? void 0 : kwargs.ignore_if_error) !== null && _kwargs$ignore_if_err !== void 0 ? _kwargs$ignore_if_err : false;
|
|
37
|
+
if (!this.body.data) {
|
|
38
|
+
this.body.data = {};
|
|
39
|
+
}
|
|
40
|
+
// If body["data"] is not a dictionary, don't raise an error while adding attachment.
|
|
41
|
+
if ((0, _typeof2["default"])(this.body.data) !== "object") {
|
|
42
|
+
console.warn("WARNING: attachment cannot be added. Please make sure body['data'] is a dictionary. WorkflowTriggerRequest ", JSON.stringify(this.as_json()));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
var attachment = (0, _attachment["default"])(file_path, file_name, ignore_if_error);
|
|
46
|
+
if (!attachment) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (!this.body.data.$attachments) {
|
|
50
|
+
this.body.data.$attachments = [];
|
|
51
|
+
}
|
|
52
|
+
this.body.data.$attachments.push(attachment);
|
|
53
|
+
}
|
|
54
|
+
}, {
|
|
55
|
+
key: "get_final_json",
|
|
56
|
+
value: function get_final_json(config) {
|
|
57
|
+
var is_part_of_bulk = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
58
|
+
if (this.idempotency_key) {
|
|
59
|
+
this.body["$idempotency_key"] = this.idempotency_key;
|
|
60
|
+
}
|
|
61
|
+
if (this.tenant_id) {
|
|
62
|
+
this.body["tenant_id"] = this.tenant_id;
|
|
63
|
+
}
|
|
64
|
+
if (this.cancellation_key) {
|
|
65
|
+
this.body.cancellation_key = this.cancellation_key;
|
|
66
|
+
}
|
|
67
|
+
this.body = (0, _utils.validate_workflow_trigger_body_schema)(this.body);
|
|
68
|
+
var apparent_size = (0, _utils.get_apparent_workflow_body_size)(this.body, is_part_of_bulk);
|
|
69
|
+
if (apparent_size > _constants.SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES) {
|
|
70
|
+
throw new _utils.InputValueError("workflow body too big - ".concat(apparent_size, " Bytes, must not exceed ").concat(_constants.SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE));
|
|
71
|
+
}
|
|
72
|
+
return [this.body, apparent_size];
|
|
73
|
+
}
|
|
74
|
+
}, {
|
|
75
|
+
key: "as_json",
|
|
76
|
+
value: function as_json() {
|
|
77
|
+
var body_dict = _objectSpread({}, this.body);
|
|
78
|
+
if (this.idempotency_key) {
|
|
79
|
+
body_dict.$idempotency_key = this.idempotency_key;
|
|
80
|
+
}
|
|
81
|
+
if (this.tenant_id) {
|
|
82
|
+
body_dict.tenant_id = this.tenant_id;
|
|
83
|
+
}
|
|
84
|
+
if (this.cancellation_key) {
|
|
85
|
+
body_dict.cancellation_key = this.cancellation_key;
|
|
86
|
+
}
|
|
87
|
+
return body_dict;
|
|
88
|
+
}
|
|
89
|
+
}]);
|
|
90
|
+
return WorkflowTriggerRequest;
|
|
91
|
+
}();
|
|
92
|
+
exports["default"] = WorkflowTriggerRequest;
|
|
93
|
+
module.exports = exports.default;
|