@suprsend/node-sdk 1.0.0 → 1.1.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.
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports["default"] = get_attachment_json_for_file;
8
+ exports["default"] = get_attachment_json;
9
9
 
10
10
  var _path = _interopRequireDefault(require("path"));
11
11
 
@@ -13,14 +13,47 @@ var _mimeTypes = _interopRequireDefault(require("mime-types"));
13
13
 
14
14
  var _utils = require("./utils");
15
15
 
16
- function get_attachment_json_for_file(file_path) {
16
+ function check_is_web_url() {
17
+ var file_path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
18
+ return file_path.startsWith("http://") || file_path.startsWith("https://");
19
+ }
20
+
21
+ function get_attachment_json_for_file(file_path, file_name, ignore_if_error) {
17
22
  var abs_path = _path["default"].resolve((0, _utils.resolveTilde)(file_path));
18
23
 
24
+ var final_file_name = _path["default"].basename(abs_path);
25
+
26
+ if (file_name && file_name.trim()) {
27
+ final_file_name = file_name.trim();
28
+ }
29
+
19
30
  return {
20
- filename: _path["default"].basename(abs_path),
31
+ filename: final_file_name,
21
32
  contentType: _mimeTypes["default"].lookup(abs_path),
22
- data: (0, _utils.base64Encode)(abs_path)
33
+ data: (0, _utils.base64Encode)(abs_path),
34
+ url: null,
35
+ ignore_if_error: ignore_if_error
23
36
  };
24
37
  }
25
38
 
39
+ function get_attachment_json_for_url(file_url, file_name, ignore_if_error) {
40
+ return {
41
+ filename: file_name,
42
+ contentType: null,
43
+ data: null,
44
+ url: file_url,
45
+ ignore_if_error: ignore_if_error
46
+ };
47
+ }
48
+
49
+ function get_attachment_json(file_path, file_name) {
50
+ var ignore_if_error = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
51
+
52
+ if (check_is_web_url(file_path)) {
53
+ return get_attachment_json_for_url(file_path, file_name, ignore_if_error);
54
+ } else {
55
+ return get_attachment_json_for_file(file_path, file_name, ignore_if_error);
56
+ }
57
+ }
58
+
26
59
  module.exports = exports.default;
package/dist/constants.js CHANGED
@@ -3,13 +3,19 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.WORKFLOW_RUNTIME_KEYS_POTENTIAL_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.DEFAULT_UAT_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;
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.DEFAULT_UAT_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
9
  exports.DEFAULT_URL = DEFAULT_URL;
10
- var DEFAULT_UAT_URL = "https://collector-staging.suprsend.workers.dev/"; // a API call should not have apparent body size of more than 800KB
10
+ var DEFAULT_UAT_URL = "https://collector-staging.suprsend.workers.dev/"; // an Event should not have apparent body size of more than 100KB
11
11
 
12
12
  exports.DEFAULT_UAT_URL = DEFAULT_UAT_URL;
13
+ var SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES = 100 * 1024; // 100 * 1024
14
+
15
+ exports.SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES = SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES;
16
+ var SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE = "100KB"; // a API call should not have apparent body size of more than 800KB
17
+
18
+ exports.SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE = SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE;
13
19
  var BODY_MAX_APPARENT_SIZE_IN_BYTES = 800 * 1024; // 800 * 1024
14
20
 
15
21
  exports.BODY_MAX_APPARENT_SIZE_IN_BYTES = BODY_MAX_APPARENT_SIZE_IN_BYTES;
@@ -27,7 +33,7 @@ var MAX_WORKFLOWS_IN_BULK_API = 100; // max event-records in one bulk api call
27
33
  exports.MAX_WORKFLOWS_IN_BULK_API = MAX_WORKFLOWS_IN_BULK_API;
28
34
  var MAX_EVENTS_IN_BULK_API = 100;
29
35
  exports.MAX_EVENTS_IN_BULK_API = MAX_EVENTS_IN_BULK_API;
30
- var ALLOW_ATTACHMENTS_IN_BULK_API = false;
36
+ var ALLOW_ATTACHMENTS_IN_BULK_API = true;
31
37
  exports.ALLOW_ATTACHMENTS_IN_BULK_API = ALLOW_ATTACHMENTS_IN_BULK_API;
32
38
  var ATTACHMENT_UPLOAD_ENABLED = false; // -- single Identity event limit
33
39
 
package/dist/event.js CHANGED
@@ -36,12 +36,13 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
36
36
  var RESERVED_EVENT_NAMES = ["$identify", "$notification_delivered", "$notification_dismiss", "$notification_clicked", "$app_launched", "$user_login", "$user_logout"];
37
37
 
38
38
  var Event = /*#__PURE__*/function () {
39
- function Event(distinct_id, event_name, properties, idempotency_key) {
39
+ function Event(distinct_id, event_name, properties) {
40
+ var kwargs = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
40
41
  (0, _classCallCheck2["default"])(this, Event);
41
42
  this.distinct_id = distinct_id;
42
43
  this.event_name = event_name;
43
44
  this.properties = properties;
44
- this.idempotency_key = idempotency_key; // --- validate
45
+ this.idempotency_key = kwargs === null || kwargs === void 0 ? void 0 : kwargs.idempotency_key; // --- validate
45
46
 
46
47
  this.__validate_distinct_id();
47
48
 
@@ -101,7 +102,12 @@ var Event = /*#__PURE__*/function () {
101
102
  }, {
102
103
  key: "add_attachment",
103
104
  value: function add_attachment(file_path) {
104
- var attachment = (0, _attachment["default"])(file_path); // --- add the attachment to properties->$attachments
105
+ var _kwargs$ignore_if_err;
106
+
107
+ var kwargs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
108
+ var file_name = kwargs === null || kwargs === void 0 ? void 0 : kwargs.file_name;
109
+ 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;
110
+ var attachment = (0, _attachment["default"])(file_path, file_name, ignore_if_error); // --- add the attachment to properties->$attachments
105
111
 
106
112
  if (!this.properties["$attachments"]) {
107
113
  this.properties["$attachments"] = [];
@@ -132,8 +138,8 @@ var Event = /*#__PURE__*/function () {
132
138
  event_dict = (0, _utils.validate_track_event_schema)(event_dict);
133
139
  var apparent_size = (0, _utils.get_apparent_event_size)(event_dict, is_part_of_bulk);
134
140
 
135
- if (apparent_size > _constants.BODY_MAX_APPARENT_SIZE_IN_BYTES) {
136
- throw new _utils.SuprsendError("Event properties too big - ".concat(apparent_size, " Bytes,must not cross ").concat(_constants.BODY_MAX_APPARENT_SIZE_IN_BYTES_READABLE));
141
+ if (apparent_size > _constants.SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES) {
142
+ throw new _utils.SuprsendError("Event size too big - ".concat(apparent_size, " Bytes,must not cross ").concat(_constants.SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE));
137
143
  }
138
144
 
139
145
  return [event_dict, apparent_size];
@@ -133,8 +133,8 @@ var _BulkEventsChunk = /*#__PURE__*/function () {
133
133
  return false;
134
134
  }
135
135
 
136
- if (event_size > _constants.BODY_MAX_APPARENT_SIZE_IN_BYTES) {
137
- throw new _utils.SuprsendError("workflow body (discounting attachment if any) too big - ".concat(event_size, " Bytes, must not cross ").concat(_constants.BODY_MAX_APPARENT_SIZE_IN_BYTES_READABLE));
136
+ if (event_size > _constants.SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES) {
137
+ throw new _utils.SuprsendError("Event properties too big - ".concat(event_size, " Bytes, must not cross ").concat(_constants.SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE));
138
138
  }
139
139
 
140
140
  if (this.__running_size + event_size > _constants.BODY_MAX_APPARENT_SIZE_IN_BYTES) {
package/dist/index.js CHANGED
@@ -127,6 +127,12 @@ var Suprsend = /*#__PURE__*/function () {
127
127
  }, {
128
128
  key: "add_attachment",
129
129
  value: function add_attachment(body, file_path) {
130
+ var _kwargs$ignore_if_err;
131
+
132
+ var kwargs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
133
+ var file_name = kwargs === null || kwargs === void 0 ? void 0 : kwargs.file_name;
134
+ 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;
135
+
130
136
  if (!body.data) {
131
137
  body.data = {};
132
138
  }
@@ -135,7 +141,7 @@ var Suprsend = /*#__PURE__*/function () {
135
141
  throw new _utils.SuprsendError("data must be an object");
136
142
  }
137
143
 
138
- var attachment = (0, _attachment["default"])(file_path);
144
+ var attachment = (0, _attachment["default"])(file_path, file_name, ignore_if_error);
139
145
 
140
146
  if (!body.data["$attachments"]) {
141
147
  body["data"]["$attachments"] = [];
@@ -161,8 +167,8 @@ var Suprsend = /*#__PURE__*/function () {
161
167
  key: "track",
162
168
  value: function track(distinct_id, event_name) {
163
169
  var properties = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
164
- var idempotency_key = arguments.length > 3 ? arguments[3] : undefined;
165
- var event = new _event["default"](distinct_id, event_name, properties, idempotency_key);
170
+ var kwargs = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
171
+ var event = new _event["default"](distinct_id, event_name, properties, kwargs);
166
172
  return this._eventcollector.collect(event);
167
173
  }
168
174
  }, {
@@ -133,8 +133,8 @@ var _BulkSubscribersChunk = /*#__PURE__*/function () {
133
133
  return false;
134
134
  }
135
135
 
136
- if (event_size > _constants.BODY_MAX_APPARENT_SIZE_IN_BYTES) {
137
- throw new SuprsendError("workflow body (discounting attachment if any) too big - ".concat(event_size, " Bytes, must not cross ").concat(_constants.BODY_MAX_APPARENT_SIZE_IN_BYTES_READABLE));
136
+ if (event_size > _constants.IDENTITY_SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES) {
137
+ throw new SuprsendError("Event too big - ".concat(event_size, " Bytes, must not cross ").concat(_constants.IDENTITY_SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE));
138
138
  }
139
139
 
140
140
  if (this.__running_size + event_size > _constants.BODY_MAX_APPARENT_SIZE_IN_BYTES) {
package/dist/workflow.js CHANGED
@@ -28,7 +28,8 @@ var _attachment = _interopRequireDefault(require("./attachment"));
28
28
  var _constants = require("./constants");
29
29
 
30
30
  var Workflow = /*#__PURE__*/function () {
31
- function Workflow(body, idempotency_key) {
31
+ function Workflow(body) {
32
+ var kwargs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
32
33
  (0, _classCallCheck2["default"])(this, Workflow);
33
34
 
34
35
  if (!(body instanceof Object)) {
@@ -36,13 +37,18 @@ var Workflow = /*#__PURE__*/function () {
36
37
  }
37
38
 
38
39
  this.body = body;
39
- this.idempotency_key = idempotency_key;
40
+ this.idempotency_key = kwargs === null || kwargs === void 0 ? void 0 : kwargs.idempotency_key;
40
41
  }
41
42
 
42
43
  (0, _createClass2["default"])(Workflow, [{
43
44
  key: "add_attachment",
44
45
  value: function add_attachment() {
46
+ var _kwargs$ignore_if_err;
47
+
45
48
  var file_path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
49
+ var kwargs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
50
+ var file_name = kwargs === null || kwargs === void 0 ? void 0 : kwargs.file_name;
51
+ 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;
46
52
 
47
53
  if (!this.body.data) {
48
54
  this.body.data = {};
@@ -52,7 +58,7 @@ var Workflow = /*#__PURE__*/function () {
52
58
  throw new _utils.SuprsendError("data must be a dictionary");
53
59
  }
54
60
 
55
- var attachment = (0, _attachment["default"])(file_path);
61
+ var attachment = (0, _attachment["default"])(file_path, file_name, ignore_if_error);
56
62
 
57
63
  if (!this.body.data["$attachments"]) {
58
64
  this.body["data"]["$attachments"] = [];
@@ -73,8 +79,8 @@ var Workflow = /*#__PURE__*/function () {
73
79
  this.body = (0, _utils.validate_workflow_body_schema)(this.body);
74
80
  var apparent_size = (0, _utils.get_apparent_workflow_body_size)(this.body, is_part_of_bulk); // review
75
81
 
76
- if (apparent_size > _constants.BODY_MAX_APPARENT_SIZE_IN_BYTES) {
77
- throw new _utils.SuprsendError("workflow body (discounting attachment if any) too big - ".concat(apparent_size, " Bytes, must not cross ").concat(_constants.BODY_MAX_APPARENT_SIZE_IN_BYTES_READABLE));
82
+ if (apparent_size > _constants.SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES) {
83
+ throw new _utils.SuprsendError("workflow body too big - ".concat(apparent_size, " Bytes, must not cross ").concat(_constants.SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE));
78
84
  }
79
85
 
80
86
  return [this.body, apparent_size];
@@ -133,8 +133,8 @@ var _BulkWorkflowsChunk = /*#__PURE__*/function () {
133
133
  return false;
134
134
  }
135
135
 
136
- if (body_size > _constants.BODY_MAX_APPARENT_SIZE_IN_BYTES) {
137
- throw new _utils.SuprsendError("workflow body (discounting attachment if any) too big - ".concat(body_size, " Bytes, must not cross ").concat(_constants.BODY_MAX_APPARENT_SIZE_IN_BYTES_READABLE));
136
+ if (body_size > _constants.SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES) {
137
+ throw new _utils.SuprsendError("workflow body too big - ".concat(body_size, " Bytes, must not cross ").concat(_constants.SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE));
138
138
  }
139
139
 
140
140
  if (this.__running_size + body_size > _constants.BODY_MAX_APPARENT_SIZE_IN_BYTES) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suprsend/node-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Suprsend Node SDK to trigger workflow from backend",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/attachment.js CHANGED
@@ -2,11 +2,43 @@ import path from "path";
2
2
  import mime from "mime-types";
3
3
  import { base64Encode, resolveTilde } from "./utils";
4
4
 
5
- export default function get_attachment_json_for_file(file_path) {
5
+ function check_is_web_url(file_path = "") {
6
+ return file_path.startsWith("http://") || file_path.startsWith("https://");
7
+ }
8
+
9
+ function get_attachment_json_for_file(file_path, file_name, ignore_if_error) {
6
10
  const abs_path = path.resolve(resolveTilde(file_path));
11
+ let final_file_name = path.basename(abs_path);
12
+ if (file_name && file_name.trim()) {
13
+ final_file_name = file_name.trim();
14
+ }
7
15
  return {
8
- filename: path.basename(abs_path),
16
+ filename: final_file_name,
9
17
  contentType: mime.lookup(abs_path),
10
18
  data: base64Encode(abs_path),
19
+ url: null,
20
+ ignore_if_error: ignore_if_error,
21
+ };
22
+ }
23
+
24
+ function get_attachment_json_for_url(file_url, file_name, ignore_if_error) {
25
+ return {
26
+ filename: file_name,
27
+ contentType: null,
28
+ data: null,
29
+ url: file_url,
30
+ ignore_if_error: ignore_if_error,
11
31
  };
12
32
  }
33
+
34
+ export default function get_attachment_json(
35
+ file_path,
36
+ file_name,
37
+ ignore_if_error = false
38
+ ) {
39
+ if (check_is_web_url(file_path)) {
40
+ return get_attachment_json_for_url(file_path, file_name, ignore_if_error);
41
+ } else {
42
+ return get_attachment_json_for_file(file_path, file_name, ignore_if_error);
43
+ }
44
+ }
package/src/constants.js CHANGED
@@ -3,6 +3,10 @@ export const DEFAULT_URL = "https://hub.suprsend.com/";
3
3
  export const DEFAULT_UAT_URL =
4
4
  "https://collector-staging.suprsend.workers.dev/";
5
5
 
6
+ // an Event should not have apparent body size of more than 100KB
7
+ export const SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES = 100 * 1024; // 100 * 1024
8
+ export const SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE = "100KB";
9
+
6
10
  // a API call should not have apparent body size of more than 800KB
7
11
  export const BODY_MAX_APPARENT_SIZE_IN_BYTES = 800 * 1024; // 800 * 1024
8
12
  export const BODY_MAX_APPARENT_SIZE_IN_BYTES_READABLE = "800KB";
@@ -18,7 +22,7 @@ export const MAX_WORKFLOWS_IN_BULK_API = 100;
18
22
  // max event-records in one bulk api call
19
23
  export const MAX_EVENTS_IN_BULK_API = 100;
20
24
 
21
- export const ALLOW_ATTACHMENTS_IN_BULK_API = false;
25
+ export const ALLOW_ATTACHMENTS_IN_BULK_API = true;
22
26
  export const ATTACHMENT_UPLOAD_ENABLED = false;
23
27
 
24
28
  // -- single Identity event limit
package/src/event.js CHANGED
@@ -10,10 +10,10 @@ import {
10
10
  } from "./utils";
11
11
  import get_request_signature from "./signature";
12
12
  import axios from "axios";
13
- import get_attachment_json_for_file from "./attachment";
13
+ import get_attachment_json from "./attachment";
14
14
  import {
15
- BODY_MAX_APPARENT_SIZE_IN_BYTES,
16
- BODY_MAX_APPARENT_SIZE_IN_BYTES_READABLE,
15
+ SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES,
16
+ SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE,
17
17
  } from "./constants";
18
18
 
19
19
  const RESERVED_EVENT_NAMES = [
@@ -27,11 +27,11 @@ const RESERVED_EVENT_NAMES = [
27
27
  ];
28
28
 
29
29
  export default class Event {
30
- constructor(distinct_id, event_name, properties, idempotency_key) {
30
+ constructor(distinct_id, event_name, properties, kwargs = {}) {
31
31
  this.distinct_id = distinct_id;
32
32
  this.event_name = event_name;
33
33
  this.properties = properties;
34
- this.idempotency_key = idempotency_key;
34
+ this.idempotency_key = kwargs?.idempotency_key;
35
35
  // --- validate
36
36
  this.__validate_distinct_id();
37
37
  this.__validate_event_name();
@@ -79,8 +79,14 @@ export default class Event {
79
79
  this.event_name = event_name;
80
80
  }
81
81
 
82
- add_attachment(file_path) {
83
- const attachment = get_attachment_json_for_file(file_path);
82
+ add_attachment(file_path, kwargs = {}) {
83
+ const file_name = kwargs?.file_name;
84
+ const ignore_if_error = kwargs?.ignore_if_error ?? false;
85
+ const attachment = get_attachment_json(
86
+ file_path,
87
+ file_name,
88
+ ignore_if_error
89
+ );
84
90
  // --- add the attachment to properties->$attachments
85
91
  if (!this.properties["$attachments"]) {
86
92
  this.properties["$attachments"] = [];
@@ -103,9 +109,9 @@ export default class Event {
103
109
  }
104
110
  event_dict = validate_track_event_schema(event_dict);
105
111
  const apparent_size = get_apparent_event_size(event_dict, is_part_of_bulk);
106
- if (apparent_size > BODY_MAX_APPARENT_SIZE_IN_BYTES) {
112
+ if (apparent_size > SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES) {
107
113
  throw new SuprsendError(
108
- `Event properties too big - ${apparent_size} Bytes,must not cross ${BODY_MAX_APPARENT_SIZE_IN_BYTES_READABLE}`
114
+ `Event size too big - ${apparent_size} Bytes,must not cross ${SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE}`
109
115
  );
110
116
  }
111
117
  return [event_dict, apparent_size];
@@ -1,4 +1,6 @@
1
1
  import {
2
+ SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES,
3
+ SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE,
2
4
  ALLOW_ATTACHMENTS_IN_BULK_API,
3
5
  BODY_MAX_APPARENT_SIZE_IN_BYTES,
4
6
  BODY_MAX_APPARENT_SIZE_IN_BYTES_READABLE,
@@ -84,9 +86,9 @@ class _BulkEventsChunk {
84
86
  if (this.__check_limit_reached()) {
85
87
  return false;
86
88
  }
87
- if (event_size > BODY_MAX_APPARENT_SIZE_IN_BYTES) {
89
+ if (event_size > SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES) {
88
90
  throw new SuprsendError(
89
- `workflow body (discounting attachment if any) too big - ${event_size} Bytes, must not cross ${BODY_MAX_APPARENT_SIZE_IN_BYTES_READABLE}`
91
+ `Event properties too big - ${event_size} Bytes, must not cross ${SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE}`
90
92
  );
91
93
  }
92
94
  if (this.__running_size + event_size > BODY_MAX_APPARENT_SIZE_IN_BYTES) {
package/src/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { SuprsendError, SuprsendConfigError } from "./utils";
2
- import get_attachment_json_for_file from "./attachment";
2
+ import get_attachment_json from "./attachment";
3
3
  import Workflow, { _WorkflowTrigger } from "./workflow";
4
4
  import { BulkWorkflowsFactory } from "./workflows_bulk";
5
5
  import Event, { EventCollector } from "./event";
@@ -78,14 +78,20 @@ class Suprsend {
78
78
  return base_url;
79
79
  }
80
80
 
81
- add_attachment(body, file_path) {
81
+ add_attachment(body, file_path, kwargs = {}) {
82
+ const file_name = kwargs?.file_name;
83
+ const ignore_if_error = kwargs?.ignore_if_error ?? false;
82
84
  if (!body.data) {
83
85
  body.data = {};
84
86
  }
85
87
  if (!body.data instanceof Object) {
86
88
  throw new SuprsendError("data must be an object");
87
89
  }
88
- const attachment = get_attachment_json_for_file(file_path);
90
+ const attachment = get_attachment_json(
91
+ file_path,
92
+ file_name,
93
+ ignore_if_error
94
+ );
89
95
  if (!body.data["$attachments"]) {
90
96
  body["data"]["$attachments"] = [];
91
97
  }
@@ -103,13 +109,8 @@ class Suprsend {
103
109
  return this._workflow_trigger.trigger(wf_ins);
104
110
  }
105
111
 
106
- track(distinct_id, event_name, properties = {}, idempotency_key) {
107
- const event = new Event(
108
- distinct_id,
109
- event_name,
110
- properties,
111
- idempotency_key
112
- );
112
+ track(distinct_id, event_name, properties = {}, kwargs = {}) {
113
+ const event = new Event(distinct_id, event_name, properties, kwargs);
113
114
  return this._eventcollector.collect(event);
114
115
  }
115
116
 
@@ -1,4 +1,6 @@
1
1
  import {
2
+ IDENTITY_SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES,
3
+ IDENTITY_SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE,
2
4
  BODY_MAX_APPARENT_SIZE_IN_BYTES,
3
5
  BODY_MAX_APPARENT_SIZE_IN_BYTES_READABLE,
4
6
  MAX_IDENTITY_EVENTS_IN_BULK_API,
@@ -82,9 +84,9 @@ class _BulkSubscribersChunk {
82
84
  if (this.__check_limit_reached()) {
83
85
  return false;
84
86
  }
85
- if (event_size > BODY_MAX_APPARENT_SIZE_IN_BYTES) {
87
+ if (event_size > IDENTITY_SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES) {
86
88
  throw new SuprsendError(
87
- `workflow body (discounting attachment if any) too big - ${event_size} Bytes, must not cross ${BODY_MAX_APPARENT_SIZE_IN_BYTES_READABLE}`
89
+ `Event too big - ${event_size} Bytes, must not cross ${IDENTITY_SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE}`
88
90
  );
89
91
  }
90
92
  if (this.__running_size + event_size > BODY_MAX_APPARENT_SIZE_IN_BYTES) {
package/src/workflow.js CHANGED
@@ -5,29 +5,35 @@ import {
5
5
  validate_workflow_body_schema,
6
6
  get_apparent_workflow_body_size,
7
7
  } from "./utils";
8
- import get_attachment_json_for_file from "./attachment";
8
+ import get_attachment_json from "./attachment";
9
9
  import {
10
- BODY_MAX_APPARENT_SIZE_IN_BYTES,
11
- BODY_MAX_APPARENT_SIZE_IN_BYTES_READABLE,
10
+ SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES,
11
+ SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE,
12
12
  } from "./constants";
13
13
 
14
14
  export default class Workflow {
15
- constructor(body, idempotency_key) {
15
+ constructor(body, kwargs = {}) {
16
16
  if (!(body instanceof Object)) {
17
17
  throw new SuprsendError("workflow body must be a json/dictionary");
18
18
  }
19
19
  this.body = body;
20
- this.idempotency_key = idempotency_key;
20
+ this.idempotency_key = kwargs?.idempotency_key;
21
21
  }
22
22
 
23
- add_attachment(file_path = "") {
23
+ add_attachment(file_path = "", kwargs = {}) {
24
+ const file_name = kwargs?.file_name;
25
+ const ignore_if_error = kwargs?.ignore_if_error ?? false;
24
26
  if (!this.body.data) {
25
27
  this.body.data = {};
26
28
  }
27
29
  if (!(this.body instanceof Object)) {
28
30
  throw new SuprsendError("data must be a dictionary");
29
31
  }
30
- const attachment = get_attachment_json_for_file(file_path);
32
+ const attachment = get_attachment_json(
33
+ file_path,
34
+ file_name,
35
+ ignore_if_error
36
+ );
31
37
 
32
38
  if (!this.body.data["$attachments"]) {
33
39
  this.body["data"]["$attachments"] = [];
@@ -45,9 +51,9 @@ export default class Workflow {
45
51
  this.body,
46
52
  is_part_of_bulk
47
53
  ); // review
48
- if (apparent_size > BODY_MAX_APPARENT_SIZE_IN_BYTES) {
54
+ if (apparent_size > SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES) {
49
55
  throw new SuprsendError(
50
- `workflow body (discounting attachment if any) too big - ${apparent_size} Bytes, must not cross ${BODY_MAX_APPARENT_SIZE_IN_BYTES_READABLE}`
56
+ `workflow body too big - ${apparent_size} Bytes, must not cross ${SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE}`
51
57
  );
52
58
  }
53
59
  return [this.body, apparent_size];
@@ -1,4 +1,6 @@
1
1
  import {
2
+ SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES,
3
+ SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE,
2
4
  BODY_MAX_APPARENT_SIZE_IN_BYTES,
3
5
  BODY_MAX_APPARENT_SIZE_IN_BYTES_READABLE,
4
6
  MAX_WORKFLOWS_IN_BULK_API,
@@ -84,9 +86,9 @@ class _BulkWorkflowsChunk {
84
86
  if (this.__check_limit_reached()) {
85
87
  return false;
86
88
  }
87
- if (body_size > BODY_MAX_APPARENT_SIZE_IN_BYTES) {
89
+ if (body_size > SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES) {
88
90
  throw new SuprsendError(
89
- `workflow body (discounting attachment if any) too big - ${body_size} Bytes, must not cross ${BODY_MAX_APPARENT_SIZE_IN_BYTES_READABLE}`
91
+ `workflow body too big - ${body_size} Bytes, must not cross ${SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE}`
90
92
  );
91
93
  }
92
94
  if (this.__running_size + body_size > BODY_MAX_APPARENT_SIZE_IN_BYTES) {