@suprsend/node-sdk 0.0.5 → 0.0.6

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.
Files changed (3) hide show
  1. package/dist/utils.js +193 -1
  2. package/package.json +1 -1
  3. package/src/utils.js +182 -1
package/dist/utils.js CHANGED
@@ -30,6 +30,198 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
30
30
 
31
31
  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; } }
32
32
 
33
+ var schema = {
34
+ $schema: "http://json-schema.org/draft-07/schema#",
35
+ $id: "http://github.com/suprsend/suprsend-node-sdk/request_json/workflow.json",
36
+ title: "workflow_request",
37
+ description: "Json schema for workflow request",
38
+ $comment: "Json schema for workflow request",
39
+ type: "object",
40
+ properties: {
41
+ name: {
42
+ $ref: "#/definitions/non_empty_string",
43
+ description: "name of workflow"
44
+ },
45
+ template: {
46
+ $ref: "#/definitions/non_empty_string",
47
+ description: "slug of Template"
48
+ },
49
+ notification_category: {
50
+ $ref: "#/definitions/non_empty_string",
51
+ description: "slug of Notification category"
52
+ },
53
+ delay: {
54
+ type: ["string", "integer"],
55
+ minimum: 0,
56
+ description: "If string: format [XX]d[XX]h[XX]m[XX]s e.g 1d2h30m10s(for 1day 2hours 30minutes 10sec). If integer: value in number of seconds"
57
+ },
58
+ trigger_at: {
59
+ $ref: "#/definitions/non_empty_string",
60
+ description: "timestamp in ISO-8601 format. e.g 2021-08-27T20:14:51.643Z"
61
+ },
62
+ priority_algorithm: {
63
+ type: "boolean"
64
+ },
65
+ users: {
66
+ type: "array",
67
+ items: {
68
+ $ref: "#/definitions/user_setting"
69
+ },
70
+ minItems: 1,
71
+ maxItems: 100,
72
+ description: "user object to run workflow for. At least 1 user is required"
73
+ },
74
+ data: {
75
+ type: "object",
76
+ description: "variables to be used in workflow. e.g replacing templates variables."
77
+ }
78
+ },
79
+ required: ["name", "template", "notification_category", "users", "data"],
80
+ definitions: {
81
+ non_empty_string: {
82
+ type: "string",
83
+ minLength: 2
84
+ },
85
+ mobile_number_pattern: {
86
+ type: "string",
87
+ minLength: 8,
88
+ pattern: "^\\+[0-9\\s]+",
89
+ message: {
90
+ required: 'Either a mobile-number or an array of mobile-numbers. e.g ["41446681800"]',
91
+ pattern: "number must start with + and must contain country code. e.g. +41446681800"
92
+ }
93
+ },
94
+ email_pattern: {
95
+ type: "string",
96
+ format: "email",
97
+ pattern: "^\\S+@\\S+\\.\\S+$",
98
+ description: "email of an user",
99
+ minLength: 6,
100
+ maxLength: 127,
101
+ message: {
102
+ required: "",
103
+ pattern: "value in email format required. e.g. user@example.com"
104
+ }
105
+ },
106
+ user_setting: {
107
+ type: "object",
108
+ properties: {
109
+ distinct_id: {
110
+ $ref: "#/definitions/non_empty_string"
111
+ },
112
+ $email: {
113
+ oneOf: [{
114
+ $ref: "#/definitions/email_pattern"
115
+ }, {
116
+ type: "array",
117
+ uniqueItems: true,
118
+ maxItems: 10,
119
+ minItems: 1,
120
+ items: {
121
+ $ref: "#/definitions/email_pattern"
122
+ }
123
+ }]
124
+ },
125
+ $sms: {
126
+ oneOf: [{
127
+ $ref: "#/definitions/mobile_number_pattern"
128
+ }, {
129
+ type: "array",
130
+ uniqueItems: true,
131
+ maxItems: 10,
132
+ minItems: 1,
133
+ items: {
134
+ $ref: "#/definitions/mobile_number_pattern"
135
+ }
136
+ }]
137
+ },
138
+ $androidpush: {
139
+ oneOf: [{
140
+ $ref: "#/definitions/non_empty_string"
141
+ }, {
142
+ type: "array",
143
+ uniqueItems: true,
144
+ maxItems: 10,
145
+ minItems: 1,
146
+ items: {
147
+ $ref: "#/definitions/non_empty_string"
148
+ }
149
+ }]
150
+ },
151
+ $iospush: {
152
+ oneOf: [{
153
+ $ref: "#/definitions/non_empty_string"
154
+ }, {
155
+ type: "array",
156
+ uniqueItems: true,
157
+ maxItems: 10,
158
+ minItems: 1,
159
+ items: {
160
+ $ref: "#/definitions/non_empty_string"
161
+ }
162
+ }]
163
+ },
164
+ $whatsapp: {
165
+ oneOf: [{
166
+ $ref: "#/definitions/mobile_number_pattern"
167
+ }, {
168
+ type: "array",
169
+ uniqueItems: true,
170
+ maxItems: 10,
171
+ minItems: 1,
172
+ items: {
173
+ $ref: "#/definitions/mobile_number_pattern"
174
+ }
175
+ }]
176
+ },
177
+ $webpush: {
178
+ oneOf: [{
179
+ type: "object",
180
+ minProperties: 1
181
+ }, {
182
+ type: "array",
183
+ uniqueItems: true,
184
+ maxItems: 10,
185
+ minItems: 1,
186
+ items: {
187
+ type: "object",
188
+ minProperties: 1
189
+ }
190
+ }]
191
+ },
192
+ $inbox: {
193
+ oneOf: [{
194
+ $ref: "#/definitions/non_empty_string"
195
+ }, {
196
+ type: "array",
197
+ uniqueItems: true,
198
+ maxItems: 10,
199
+ minItems: 1,
200
+ items: {
201
+ $ref: "#/definitions/non_empty_string"
202
+ }
203
+ }]
204
+ },
205
+ $messenger: {
206
+ oneOf: [{
207
+ $ref: "#/definitions/non_empty_string"
208
+ }, {
209
+ type: "array",
210
+ uniqueItems: true,
211
+ maxItems: 10,
212
+ minItems: 1,
213
+ items: {
214
+ $ref: "#/definitions/non_empty_string"
215
+ }
216
+ }]
217
+ }
218
+ },
219
+ required: ["distinct_id"],
220
+ additionalProperties: false
221
+ }
222
+ }
223
+ };
224
+
33
225
  function base64Encode(file) {
34
226
  var body = _fs["default"].readFileSync(file);
35
227
 
@@ -54,7 +246,7 @@ function _get_schema(schema_name) {
54
246
  var schema_body = __JSON_SCHEMAS[schema_name];
55
247
 
56
248
  if (!schema_body) {
57
- schema_body = _load_json_schema(schema_name);
249
+ schema_body = schema;
58
250
  __JSON_SCHEMAS[schema_name] = schema_body;
59
251
  }
60
252
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suprsend/node-sdk",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "Suprsend Node SDK to trigger workflow from backend",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/utils.js CHANGED
@@ -2,6 +2,187 @@ import os from "os";
2
2
  import fs from "fs";
3
3
  import path from "path";
4
4
 
5
+ const schema = {
6
+ $schema: "http://json-schema.org/draft-07/schema#",
7
+ $id: "http://github.com/suprsend/suprsend-node-sdk/request_json/workflow.json",
8
+ title: "workflow_request",
9
+ description: "Json schema for workflow request",
10
+ $comment: "Json schema for workflow request",
11
+ type: "object",
12
+ properties: {
13
+ name: {
14
+ $ref: "#/definitions/non_empty_string",
15
+ description: "name of workflow",
16
+ },
17
+ template: {
18
+ $ref: "#/definitions/non_empty_string",
19
+ description: "slug of Template",
20
+ },
21
+ notification_category: {
22
+ $ref: "#/definitions/non_empty_string",
23
+ description: "slug of Notification category",
24
+ },
25
+ delay: {
26
+ type: ["string", "integer"],
27
+ minimum: 0,
28
+ description:
29
+ "If string: format [XX]d[XX]h[XX]m[XX]s e.g 1d2h30m10s(for 1day 2hours 30minutes 10sec). If integer: value in number of seconds",
30
+ },
31
+ trigger_at: {
32
+ $ref: "#/definitions/non_empty_string",
33
+ description: "timestamp in ISO-8601 format. e.g 2021-08-27T20:14:51.643Z",
34
+ },
35
+ priority_algorithm: { type: "boolean" },
36
+ users: {
37
+ type: "array",
38
+ items: { $ref: "#/definitions/user_setting" },
39
+ minItems: 1,
40
+ maxItems: 100,
41
+ description:
42
+ "user object to run workflow for. At least 1 user is required",
43
+ },
44
+ data: {
45
+ type: "object",
46
+ description:
47
+ "variables to be used in workflow. e.g replacing templates variables.",
48
+ },
49
+ },
50
+ required: ["name", "template", "notification_category", "users", "data"],
51
+ definitions: {
52
+ non_empty_string: {
53
+ type: "string",
54
+ minLength: 2,
55
+ },
56
+ mobile_number_pattern: {
57
+ type: "string",
58
+ minLength: 8,
59
+ pattern: "^\\+[0-9\\s]+",
60
+ message: {
61
+ required:
62
+ 'Either a mobile-number or an array of mobile-numbers. e.g ["41446681800"]',
63
+ pattern:
64
+ "number must start with + and must contain country code. e.g. +41446681800",
65
+ },
66
+ },
67
+ email_pattern: {
68
+ type: "string",
69
+ format: "email",
70
+ pattern: "^\\S+@\\S+\\.\\S+$",
71
+ description: "email of an user",
72
+ minLength: 6,
73
+ maxLength: 127,
74
+ message: {
75
+ required: "",
76
+ pattern: "value in email format required. e.g. user@example.com",
77
+ },
78
+ },
79
+ user_setting: {
80
+ type: "object",
81
+ properties: {
82
+ distinct_id: { $ref: "#/definitions/non_empty_string" },
83
+ $email: {
84
+ oneOf: [
85
+ { $ref: "#/definitions/email_pattern" },
86
+ {
87
+ type: "array",
88
+ uniqueItems: true,
89
+ maxItems: 10,
90
+ minItems: 1,
91
+ items: { $ref: "#/definitions/email_pattern" },
92
+ },
93
+ ],
94
+ },
95
+ $sms: {
96
+ oneOf: [
97
+ { $ref: "#/definitions/mobile_number_pattern" },
98
+ {
99
+ type: "array",
100
+ uniqueItems: true,
101
+ maxItems: 10,
102
+ minItems: 1,
103
+ items: { $ref: "#/definitions/mobile_number_pattern" },
104
+ },
105
+ ],
106
+ },
107
+ $androidpush: {
108
+ oneOf: [
109
+ { $ref: "#/definitions/non_empty_string" },
110
+ {
111
+ type: "array",
112
+ uniqueItems: true,
113
+ maxItems: 10,
114
+ minItems: 1,
115
+ items: { $ref: "#/definitions/non_empty_string" },
116
+ },
117
+ ],
118
+ },
119
+ $iospush: {
120
+ oneOf: [
121
+ { $ref: "#/definitions/non_empty_string" },
122
+ {
123
+ type: "array",
124
+ uniqueItems: true,
125
+ maxItems: 10,
126
+ minItems: 1,
127
+ items: { $ref: "#/definitions/non_empty_string" },
128
+ },
129
+ ],
130
+ },
131
+ $whatsapp: {
132
+ oneOf: [
133
+ { $ref: "#/definitions/mobile_number_pattern" },
134
+ {
135
+ type: "array",
136
+ uniqueItems: true,
137
+ maxItems: 10,
138
+ minItems: 1,
139
+ items: { $ref: "#/definitions/mobile_number_pattern" },
140
+ },
141
+ ],
142
+ },
143
+ $webpush: {
144
+ oneOf: [
145
+ { type: "object", minProperties: 1 },
146
+ {
147
+ type: "array",
148
+ uniqueItems: true,
149
+ maxItems: 10,
150
+ minItems: 1,
151
+ items: { type: "object", minProperties: 1 },
152
+ },
153
+ ],
154
+ },
155
+ $inbox: {
156
+ oneOf: [
157
+ { $ref: "#/definitions/non_empty_string" },
158
+ {
159
+ type: "array",
160
+ uniqueItems: true,
161
+ maxItems: 10,
162
+ minItems: 1,
163
+ items: { $ref: "#/definitions/non_empty_string" },
164
+ },
165
+ ],
166
+ },
167
+ $messenger: {
168
+ oneOf: [
169
+ { $ref: "#/definitions/non_empty_string" },
170
+ {
171
+ type: "array",
172
+ uniqueItems: true,
173
+ maxItems: 10,
174
+ minItems: 1,
175
+ items: { $ref: "#/definitions/non_empty_string" },
176
+ },
177
+ ],
178
+ },
179
+ },
180
+ required: ["distinct_id"],
181
+ additionalProperties: false,
182
+ },
183
+ },
184
+ };
185
+
5
186
  export function base64Encode(file) {
6
187
  var body = fs.readFileSync(file);
7
188
  return body.toString("base64");
@@ -24,7 +205,7 @@ let __JSON_SCHEMAS = {};
24
205
  export function _get_schema(schema_name) {
25
206
  var schema_body = __JSON_SCHEMAS[schema_name];
26
207
  if (!schema_body) {
27
- schema_body = _load_json_schema(schema_name);
208
+ schema_body = schema;
28
209
  __JSON_SCHEMAS[schema_name] = schema_body;
29
210
  }
30
211
  return schema_body;