@suprsend/node-sdk 1.9.1 → 1.10.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 +1 -1
- package/dist/constants.js +2 -4
- package/dist/index.js +12 -5
- 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 +7 -1
- 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 +16 -7
- 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 +6 -0
- 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 +33 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# suprsend-node-sdk
|
|
2
2
|
This package can be included in a node project to easily integrate with `Suprsend` platform.
|
|
3
3
|
|
|
4
|
-
Refer full documentation [here](https://docs.suprsend.com/docs/
|
|
4
|
+
Refer full documentation [here](https://docs.suprsend.com/docs/nodejs-sdk)
|
|
5
5
|
|
|
6
6
|
### Installation
|
|
7
7
|
`suprsend-node-sdk` is available as npm package. You can install using npm or yarn.
|
package/dist/constants.js
CHANGED
|
@@ -3,14 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.WORKFLOW_RUNTIME_KEYS_POTENTIAL_SIZE_IN_BYTES = exports.SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE = exports.SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES = exports.MAX_WORKFLOWS_IN_BULK_API = exports.MAX_IDENTITY_EVENTS_IN_BULK_API = exports.MAX_EVENTS_IN_BULK_API = exports.IDENTITY_SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE = exports.IDENTITY_SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES = exports.DEFAULT_URL = exports.
|
|
6
|
+
exports.WORKFLOW_RUNTIME_KEYS_POTENTIAL_SIZE_IN_BYTES = exports.SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE = exports.SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES = exports.MAX_WORKFLOWS_IN_BULK_API = exports.MAX_IDENTITY_EVENTS_IN_BULK_API = exports.MAX_EVENTS_IN_BULK_API = exports.IDENTITY_SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE = exports.IDENTITY_SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES = exports.DEFAULT_URL = exports.BODY_MAX_APPARENT_SIZE_IN_BYTES_READABLE = exports.BODY_MAX_APPARENT_SIZE_IN_BYTES = exports.ATTACHMENT_URL_POTENTIAL_SIZE_IN_BYTES = exports.ATTACHMENT_UPLOAD_ENABLED = exports.ALLOW_ATTACHMENTS_IN_BULK_API = void 0;
|
|
7
7
|
// Default urls
|
|
8
8
|
var DEFAULT_URL = "https://hub.suprsend.com/";
|
|
9
|
-
exports.DEFAULT_URL = DEFAULT_URL;
|
|
10
|
-
var DEFAULT_UAT_URL = "https://collector-staging.suprsend.workers.dev/";
|
|
11
9
|
|
|
12
10
|
// an Event should not have apparent body size of more than 100KB
|
|
13
|
-
exports.
|
|
11
|
+
exports.DEFAULT_URL = DEFAULT_URL;
|
|
14
12
|
var SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES = 100 * 1024; // 100 * 1024
|
|
15
13
|
exports.SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES = SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES;
|
|
16
14
|
var SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE = "100KB";
|
package/dist/index.js
CHANGED
|
@@ -24,12 +24,20 @@ Object.defineProperty(exports, "Workflow", {
|
|
|
24
24
|
return _workflow["default"];
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
|
+
Object.defineProperty(exports, "WorkflowTriggerRequest", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function get() {
|
|
30
|
+
return _workflow_request["default"];
|
|
31
|
+
}
|
|
32
|
+
});
|
|
27
33
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
28
34
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
29
35
|
var _utils = require("./utils");
|
|
30
36
|
var _attachment = _interopRequireDefault(require("./attachment"));
|
|
31
37
|
var _workflow = _interopRequireWildcard(require("./workflow"));
|
|
32
38
|
var _workflows_bulk = require("./workflows_bulk");
|
|
39
|
+
var _workflow_request = _interopRequireDefault(require("./workflow_request"));
|
|
40
|
+
var _workflow_api = _interopRequireDefault(require("./workflow_api"));
|
|
33
41
|
var _event = _interopRequireWildcard(require("./event"));
|
|
34
42
|
var _events_bulk = require("./events_bulk");
|
|
35
43
|
var _subscriber = _interopRequireDefault(require("./subscriber"));
|
|
@@ -58,6 +66,7 @@ var Suprsend = /*#__PURE__*/function () {
|
|
|
58
66
|
this._user = new _subscriber["default"](this);
|
|
59
67
|
this.brands = new _brands["default"](this);
|
|
60
68
|
this.tenants = new _tenant["default"](this);
|
|
69
|
+
this.workflows = new _workflow_api["default"](this);
|
|
61
70
|
this.subscriber_lists = new _subscriber_list.SubscriberListsApi(this);
|
|
62
71
|
this._validate();
|
|
63
72
|
}
|
|
@@ -99,11 +108,7 @@ var Suprsend = /*#__PURE__*/function () {
|
|
|
99
108
|
base_url = base_url.trim();
|
|
100
109
|
}
|
|
101
110
|
if (!base_url) {
|
|
102
|
-
|
|
103
|
-
base_url = _constants.DEFAULT_UAT_URL;
|
|
104
|
-
} else {
|
|
105
|
-
base_url = _constants.DEFAULT_URL;
|
|
106
|
-
}
|
|
111
|
+
base_url = _constants.DEFAULT_URL;
|
|
107
112
|
}
|
|
108
113
|
base_url = base_url.trim();
|
|
109
114
|
if (!base_url.endsWith("/")) {
|
|
@@ -116,6 +121,7 @@ var Suprsend = /*#__PURE__*/function () {
|
|
|
116
121
|
value: function add_attachment(body, file_path) {
|
|
117
122
|
var _kwargs$ignore_if_err;
|
|
118
123
|
var kwargs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
124
|
+
console.warn('This method is deprecated. Use "WorkflowTriggerRequest.add_attachment()" instead');
|
|
119
125
|
var file_name = kwargs === null || kwargs === void 0 ? void 0 : kwargs.file_name;
|
|
120
126
|
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;
|
|
121
127
|
if (!(body !== null && body !== void 0 && body.data)) {
|
|
@@ -147,6 +153,7 @@ var Suprsend = /*#__PURE__*/function () {
|
|
|
147
153
|
value: function track(distinct_id, event_name) {
|
|
148
154
|
var properties = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
149
155
|
var kwargs = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
156
|
+
console.warn('This method is deprecated. Use "track_event(Event)" instead');
|
|
150
157
|
var event = new _event["default"](distinct_id, event_name, properties, kwargs);
|
|
151
158
|
return this._eventcollector.collect(event);
|
|
152
159
|
}
|
|
@@ -214,6 +214,10 @@
|
|
|
214
214
|
"type": ["string", "null"],
|
|
215
215
|
"description": "preferred_language: 2-letter language code in ISO 639-1 Alpha-2 code format. e.g en (for English)"
|
|
216
216
|
},
|
|
217
|
+
"$timezone": {
|
|
218
|
+
"type": ["string", "null"],
|
|
219
|
+
"description": "timezone: in IANA timezone format e.g 'America/Los_Angeles'"
|
|
220
|
+
},
|
|
217
221
|
"$channels": {
|
|
218
222
|
"type": "array",
|
|
219
223
|
"items": {
|
|
@@ -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) {
|
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;
|