@suprsend/node-sdk 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/brands.js ADDED
@@ -0,0 +1,245 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = void 0;
9
+
10
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
+
12
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
+
14
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
15
+
16
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
17
+
18
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
19
+
20
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
21
+
22
+ var _signature = _interopRequireDefault(require("./signature"));
23
+
24
+ var _utils = require("./utils");
25
+
26
+ var _axios = _interopRequireDefault(require("axios"));
27
+
28
+ 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; }
29
+
30
+ 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; }
31
+
32
+ var BrandsApi = /*#__PURE__*/function () {
33
+ function BrandsApi(config) {
34
+ (0, _classCallCheck2["default"])(this, BrandsApi);
35
+ this.config = config;
36
+ this.list_url = this.__list_url();
37
+ this.__headers = this.__common_headers();
38
+ }
39
+
40
+ (0, _createClass2["default"])(BrandsApi, [{
41
+ key: "__list_url",
42
+ value: function __list_url() {
43
+ var list_uri_template = "".concat(this.config.base_url, "v1/brand/");
44
+ return list_uri_template;
45
+ }
46
+ }, {
47
+ key: "__common_headers",
48
+ value: function __common_headers() {
49
+ return {
50
+ "Content-Type": "application/json; charset=utf-8",
51
+ "User-Agent": this.config.user_agent
52
+ };
53
+ }
54
+ }, {
55
+ key: "cleaned_limit_offset",
56
+ value: function cleaned_limit_offset(limit, offset) {
57
+ var cleaned_limit = typeof limit === "number" && limit > 0 && limit <= 1000 ? limit : 20;
58
+ var cleaned_offset = typeof offset === "number" && offset >= 0 ? offset : 0;
59
+ return [cleaned_limit, cleaned_offset];
60
+ }
61
+ }, {
62
+ key: "__dynamic_headers",
63
+ value: function __dynamic_headers() {
64
+ return {
65
+ Date: new Date().toUTCString()
66
+ };
67
+ }
68
+ }, {
69
+ key: "list",
70
+ value: function () {
71
+ var _list = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
72
+ var kwargs,
73
+ limit,
74
+ offset,
75
+ _this$cleaned_limit_o,
76
+ _this$cleaned_limit_o2,
77
+ cleaned_limit,
78
+ cleaner_offset,
79
+ final_url_obj,
80
+ final_url_string,
81
+ headers,
82
+ signature,
83
+ response,
84
+ _args = arguments;
85
+
86
+ return _regenerator["default"].wrap(function _callee$(_context) {
87
+ while (1) {
88
+ switch (_context.prev = _context.next) {
89
+ case 0:
90
+ kwargs = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
91
+ limit = kwargs === null || kwargs === void 0 ? void 0 : kwargs.limit;
92
+ offset = kwargs === null || kwargs === void 0 ? void 0 : kwargs.offset;
93
+ _this$cleaned_limit_o = this.cleaned_limit_offset(limit, offset), _this$cleaned_limit_o2 = (0, _slicedToArray2["default"])(_this$cleaned_limit_o, 2), cleaned_limit = _this$cleaned_limit_o2[0], cleaner_offset = _this$cleaned_limit_o2[1];
94
+ final_url_obj = new URL(this.list_url);
95
+ final_url_obj.searchParams.append("limit", cleaned_limit);
96
+ final_url_obj.searchParams.append("offset", cleaner_offset);
97
+ final_url_string = final_url_obj.href;
98
+ headers = _objectSpread(_objectSpread({}, this.__headers), this.__dynamic_headers());
99
+ signature = (0, _signature["default"])(final_url_string, "GET", "", headers, this.config.workspace_secret);
100
+ headers["Authorization"] = "".concat(this.config.workspace_key, ":").concat(signature);
101
+ _context.prev = 11;
102
+ _context.next = 14;
103
+ return _axios["default"].get(final_url_string, {
104
+ headers: headers
105
+ });
106
+
107
+ case 14:
108
+ response = _context.sent;
109
+ return _context.abrupt("return", response.data);
110
+
111
+ case 18:
112
+ _context.prev = 18;
113
+ _context.t0 = _context["catch"](11);
114
+ throw new _utils.SuprsendApiError(_context.t0);
115
+
116
+ case 21:
117
+ case "end":
118
+ return _context.stop();
119
+ }
120
+ }
121
+ }, _callee, this, [[11, 18]]);
122
+ }));
123
+
124
+ function list() {
125
+ return _list.apply(this, arguments);
126
+ }
127
+
128
+ return list;
129
+ }()
130
+ }, {
131
+ key: "detail_url",
132
+ value: function detail_url() {
133
+ var brand_id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
134
+ var cleaned_brand_id = brand_id.toString().trim();
135
+ var brand_id_encoded = encodeURI(cleaned_brand_id);
136
+ var url = "".concat(this.list_url).concat(brand_id_encoded, "/");
137
+ return url;
138
+ }
139
+ }, {
140
+ key: "get",
141
+ value: function () {
142
+ var _get = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
143
+ var brand_id,
144
+ url,
145
+ headers,
146
+ signature,
147
+ response,
148
+ _args2 = arguments;
149
+ return _regenerator["default"].wrap(function _callee2$(_context2) {
150
+ while (1) {
151
+ switch (_context2.prev = _context2.next) {
152
+ case 0:
153
+ brand_id = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : "";
154
+ url = this.detail_url(brand_id);
155
+ headers = _objectSpread(_objectSpread({}, this.__headers), this.__dynamic_headers());
156
+ signature = (0, _signature["default"])(url, "GET", "", headers, this.config.workspace_secret);
157
+ headers["Authorization"] = "".concat(this.config.workspace_key, ":").concat(signature);
158
+ _context2.prev = 5;
159
+ _context2.next = 8;
160
+ return _axios["default"].get(url, {
161
+ headers: headers
162
+ });
163
+
164
+ case 8:
165
+ response = _context2.sent;
166
+ return _context2.abrupt("return", response.data);
167
+
168
+ case 12:
169
+ _context2.prev = 12;
170
+ _context2.t0 = _context2["catch"](5);
171
+ throw new _utils.SuprsendApiError(_context2.t0);
172
+
173
+ case 15:
174
+ case "end":
175
+ return _context2.stop();
176
+ }
177
+ }
178
+ }, _callee2, this, [[5, 12]]);
179
+ }));
180
+
181
+ function get() {
182
+ return _get.apply(this, arguments);
183
+ }
184
+
185
+ return get;
186
+ }()
187
+ }, {
188
+ key: "upsert",
189
+ value: function () {
190
+ var _upsert = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
191
+ var brand_id,
192
+ brand_payload,
193
+ url,
194
+ headers,
195
+ content_text,
196
+ signature,
197
+ response,
198
+ _args3 = arguments;
199
+ return _regenerator["default"].wrap(function _callee3$(_context3) {
200
+ while (1) {
201
+ switch (_context3.prev = _context3.next) {
202
+ case 0:
203
+ brand_id = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : "";
204
+ brand_payload = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {};
205
+ url = this.detail_url(brand_id);
206
+ headers = _objectSpread(_objectSpread({}, this.__headers), this.__dynamic_headers());
207
+ content_text = JSON.stringify(brand_payload);
208
+ signature = (0, _signature["default"])(url, "POST", content_text, headers, this.config.workspace_secret);
209
+ headers["Authorization"] = "".concat(this.config.workspace_key, ":").concat(signature);
210
+ _context3.prev = 7;
211
+ _context3.next = 10;
212
+ return _axios["default"].post(url, content_text, {
213
+ headers: headers
214
+ });
215
+
216
+ case 10:
217
+ response = _context3.sent;
218
+ return _context3.abrupt("return", response.data);
219
+
220
+ case 14:
221
+ _context3.prev = 14;
222
+ _context3.t0 = _context3["catch"](7);
223
+ throw new _utils.SuprsendApiError(_context3.t0);
224
+
225
+ case 17:
226
+ case "end":
227
+ return _context3.stop();
228
+ }
229
+ }
230
+ }, _callee3, this, [[7, 14]]);
231
+ }));
232
+
233
+ function upsert() {
234
+ return _upsert.apply(this, arguments);
235
+ }
236
+
237
+ return upsert;
238
+ }()
239
+ }]);
240
+ return BrandsApi;
241
+ }();
242
+
243
+ var _default = BrandsApi;
244
+ exports["default"] = _default;
245
+ module.exports = exports.default;
package/dist/event.js CHANGED
@@ -42,7 +42,8 @@ var Event = /*#__PURE__*/function () {
42
42
  this.distinct_id = distinct_id;
43
43
  this.event_name = event_name;
44
44
  this.properties = properties;
45
- this.idempotency_key = kwargs === null || kwargs === void 0 ? void 0 : kwargs.idempotency_key; // --- validate
45
+ this.idempotency_key = kwargs === null || kwargs === void 0 ? void 0 : kwargs.idempotency_key;
46
+ this.brand_id = kwargs === null || kwargs === void 0 ? void 0 : kwargs.brand_id; // --- validate
46
47
 
47
48
  this.__validate_distinct_id();
48
49
 
@@ -135,6 +136,10 @@ var Event = /*#__PURE__*/function () {
135
136
  event_dict["$idempotency_key"] = this.idempotency_key;
136
137
  }
137
138
 
139
+ if (this.brand_id) {
140
+ event_dict["brand_id"] = this.brand_id;
141
+ }
142
+
138
143
  event_dict = (0, _utils.validate_track_event_schema)(event_dict);
139
144
  var apparent_size = (0, _utils.get_apparent_event_size)(event_dict, is_part_of_bulk);
140
145
 
package/dist/index.js CHANGED
@@ -41,6 +41,8 @@ var _subscriber = _interopRequireDefault(require("./subscriber"));
41
41
 
42
42
  var _subscribers_bulk = _interopRequireDefault(require("./subscribers_bulk"));
43
43
 
44
+ var _brands = _interopRequireDefault(require("./brands"));
45
+
44
46
  var _constants = require("./constants");
45
47
 
46
48
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -66,6 +68,7 @@ var Suprsend = /*#__PURE__*/function () {
66
68
  this._bulk_events = new _events_bulk.BulkEventsFactory(this);
67
69
  this._bulk_users = new _subscribers_bulk["default"](this);
68
70
  this._user = new _subscriber["default"](this);
71
+ this.brands = new _brands["default"](this);
69
72
 
70
73
  this._validate();
71
74
  }
@@ -11,6 +11,11 @@
11
11
  "maxLength": 64,
12
12
  "description": "unique id provided by client for request"
13
13
  },
14
+ "brand_id": {
15
+ "type": ["string", "null"],
16
+ "maxLength": 64,
17
+ "description": "brand id for workflow to be run in context of a brand"
18
+ },
14
19
  "$insert_id": {
15
20
  "type": "string",
16
21
  "minLength": 36,
@@ -11,6 +11,11 @@
11
11
  "maxLength": 64,
12
12
  "description": "unique id provided by client for request"
13
13
  },
14
+ "brand_id": {
15
+ "type": ["string", "null"],
16
+ "maxLength": 64,
17
+ "description": "brand id for workflow to be run in context of a brand"
18
+ },
14
19
  "name": {
15
20
  "$ref": "#/definitions/non_empty_string",
16
21
  "description": "name of workflow"
package/dist/signature.js CHANGED
@@ -15,14 +15,15 @@ function get_path(url) {
15
15
  }
16
16
 
17
17
  function get_request_signature(url, http_verb, content, headers, secret) {
18
- if (http_verb === "GET") {
19
- return "";
20
- }
18
+ var content_md5 = "";
19
+ var content_type = headers["Content-Type"] || "";
21
20
 
22
- var content_md5 = _crypto["default"].createHash("md5").update(content).digest("hex");
21
+ if (content) {
22
+ content_md5 = _crypto["default"].createHash("md5").update(content).digest("hex");
23
+ }
23
24
 
24
25
  var request_uri = get_path(url);
25
- var sign_string = http_verb + "\n" + content_md5 + "\n" + headers["Content-Type"] + "\n" + headers["Date"] + "\n" + request_uri;
26
+ var sign_string = http_verb + "\n" + content_md5 + "\n" + content_type + "\n" + headers["Date"] + "\n" + request_uri;
26
27
 
27
28
  var hash = _crypto["default"].createHmac("sha256", secret).update(sign_string);
28
29
 
package/dist/utils.js CHANGED
@@ -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.SuprsendError = exports.SuprsendConfigError = void 0;
8
+ exports.SuprsendError = exports.SuprsendConfigError = exports.SuprsendApiError = void 0;
9
9
  exports.base64Encode = base64Encode;
10
10
  exports.epoch_milliseconds = epoch_milliseconds;
11
11
  exports.get_apparent_event_size = get_apparent_event_size;
@@ -114,6 +114,33 @@ var SuprsendConfigError = /*#__PURE__*/function (_Error2) {
114
114
 
115
115
  exports.SuprsendConfigError = SuprsendConfigError;
116
116
 
117
+ var SuprsendApiError = /*#__PURE__*/function (_Error3) {
118
+ (0, _inherits2["default"])(SuprsendApiError, _Error3);
119
+
120
+ var _super3 = _createSuper(SuprsendApiError);
121
+
122
+ function SuprsendApiError(error) {
123
+ var _this3;
124
+
125
+ (0, _classCallCheck2["default"])(this, SuprsendApiError);
126
+ var message;
127
+
128
+ if (error.response) {
129
+ message = "".concat(error.response.status, ": ").concat(error.response.data.message);
130
+ } else {
131
+ message = error.message;
132
+ }
133
+
134
+ _this3 = _super3.call(this, message);
135
+ _this3.name = "SuprsendApiError";
136
+ return _this3;
137
+ }
138
+
139
+ return SuprsendApiError;
140
+ }( /*#__PURE__*/(0, _wrapNativeSuper2["default"])(Error));
141
+
142
+ exports.SuprsendApiError = SuprsendApiError;
143
+
117
144
  function is_string(value) {
118
145
  return typeof value === "string";
119
146
  }
package/dist/workflow.js CHANGED
@@ -38,6 +38,7 @@ var Workflow = /*#__PURE__*/function () {
38
38
 
39
39
  this.body = body;
40
40
  this.idempotency_key = kwargs === null || kwargs === void 0 ? void 0 : kwargs.idempotency_key;
41
+ this.brand_id = kwargs === null || kwargs === void 0 ? void 0 : kwargs.brand_id;
41
42
  }
42
43
 
43
44
  (0, _createClass2["default"])(Workflow, [{
@@ -76,6 +77,10 @@ var Workflow = /*#__PURE__*/function () {
76
77
  this.body["$idempotency_key"] = this.idempotency_key;
77
78
  }
78
79
 
80
+ if (this.brand_id) {
81
+ this.body["brand_id"] = this.brand_id;
82
+ }
83
+
79
84
  this.body = (0, _utils.validate_workflow_body_schema)(this.body);
80
85
  var apparent_size = (0, _utils.get_apparent_workflow_body_size)(this.body, is_part_of_bulk); // review
81
86
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suprsend/node-sdk",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Suprsend Node SDK to trigger workflow from backend",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/brands.js ADDED
@@ -0,0 +1,120 @@
1
+ import get_request_signature from "./signature";
2
+ import { SuprsendApiError } from "./utils";
3
+ import axios from "axios";
4
+
5
+ class BrandsApi {
6
+ constructor(config) {
7
+ this.config = config;
8
+ this.list_url = this.__list_url();
9
+ this.__headers = this.__common_headers();
10
+ }
11
+
12
+ __list_url() {
13
+ const list_uri_template = `${this.config.base_url}v1/brand/`;
14
+ return list_uri_template;
15
+ }
16
+
17
+ __common_headers() {
18
+ return {
19
+ "Content-Type": "application/json; charset=utf-8",
20
+ "User-Agent": this.config.user_agent,
21
+ };
22
+ }
23
+
24
+ cleaned_limit_offset(limit, offset) {
25
+ let cleaned_limit =
26
+ typeof limit === "number" && limit > 0 && limit <= 1000 ? limit : 20;
27
+ let cleaned_offset = typeof offset === "number" && offset >= 0 ? offset : 0;
28
+ return [cleaned_limit, cleaned_offset];
29
+ }
30
+
31
+ __dynamic_headers() {
32
+ return {
33
+ Date: new Date().toUTCString(),
34
+ };
35
+ }
36
+
37
+ async list(kwargs = {}) {
38
+ const limit = kwargs?.limit;
39
+ const offset = kwargs?.offset;
40
+ const [cleaned_limit, cleaner_offset] = this.cleaned_limit_offset(
41
+ limit,
42
+ offset
43
+ );
44
+ const final_url_obj = new URL(this.list_url);
45
+ final_url_obj.searchParams.append("limit", cleaned_limit);
46
+ final_url_obj.searchParams.append("offset", cleaner_offset);
47
+ const final_url_string = final_url_obj.href;
48
+
49
+ const headers = { ...this.__headers, ...this.__dynamic_headers() };
50
+
51
+ const signature = get_request_signature(
52
+ final_url_string,
53
+ "GET",
54
+ "",
55
+ headers,
56
+ this.config.workspace_secret
57
+ );
58
+ headers["Authorization"] = `${this.config.workspace_key}:${signature}`;
59
+
60
+ try {
61
+ const response = await axios.get(final_url_string, { headers });
62
+ return response.data;
63
+ } catch (err) {
64
+ throw new SuprsendApiError(err);
65
+ }
66
+ }
67
+
68
+ detail_url(brand_id = "") {
69
+ const cleaned_brand_id = brand_id.toString().trim();
70
+ const brand_id_encoded = encodeURI(cleaned_brand_id);
71
+ const url = `${this.list_url}${brand_id_encoded}/`;
72
+ return url;
73
+ }
74
+
75
+ async get(brand_id = "") {
76
+ const url = this.detail_url(brand_id);
77
+
78
+ const headers = { ...this.__headers, ...this.__dynamic_headers() };
79
+ const signature = get_request_signature(
80
+ url,
81
+ "GET",
82
+ "",
83
+ headers,
84
+ this.config.workspace_secret
85
+ );
86
+ headers["Authorization"] = `${this.config.workspace_key}:${signature}`;
87
+
88
+ try {
89
+ const response = await axios.get(url, { headers });
90
+ return response.data;
91
+ } catch (err) {
92
+ throw new SuprsendApiError(err);
93
+ }
94
+ }
95
+
96
+ async upsert(brand_id = "", brand_payload = {}) {
97
+ const url = this.detail_url(brand_id);
98
+
99
+ const headers = { ...this.__headers, ...this.__dynamic_headers() };
100
+ const content_text = JSON.stringify(brand_payload);
101
+
102
+ const signature = get_request_signature(
103
+ url,
104
+ "POST",
105
+ content_text,
106
+ headers,
107
+ this.config.workspace_secret
108
+ );
109
+ headers["Authorization"] = `${this.config.workspace_key}:${signature}`;
110
+
111
+ try {
112
+ const response = await axios.post(url, content_text, { headers });
113
+ return response.data;
114
+ } catch (err) {
115
+ throw new SuprsendApiError(err);
116
+ }
117
+ }
118
+ }
119
+
120
+ export default BrandsApi;
package/src/event.js CHANGED
@@ -32,6 +32,7 @@ export default class Event {
32
32
  this.event_name = event_name;
33
33
  this.properties = properties;
34
34
  this.idempotency_key = kwargs?.idempotency_key;
35
+ this.brand_id = kwargs?.brand_id;
35
36
  // --- validate
36
37
  this.__validate_distinct_id();
37
38
  this.__validate_event_name();
@@ -107,6 +108,9 @@ export default class Event {
107
108
  if (this.idempotency_key) {
108
109
  event_dict["$idempotency_key"] = this.idempotency_key;
109
110
  }
111
+ if (this.brand_id) {
112
+ event_dict["brand_id"] = this.brand_id;
113
+ }
110
114
  event_dict = validate_track_event_schema(event_dict);
111
115
  const apparent_size = get_apparent_event_size(event_dict, is_part_of_bulk);
112
116
  if (apparent_size > SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES) {
package/src/index.js CHANGED
@@ -6,6 +6,7 @@ import Event, { EventCollector } from "./event";
6
6
  import { BulkEventsFactory } from "./events_bulk";
7
7
  import SubscriberFactory from "./subscriber";
8
8
  import BulkSubscribersFactory from "./subscribers_bulk";
9
+ import BrandsApi from "./brands";
9
10
  import { DEFAULT_UAT_URL, DEFAULT_URL } from "./constants";
10
11
 
11
12
  const package_json = require("../package.json");
@@ -31,6 +32,9 @@ class Suprsend {
31
32
  this._bulk_users = new BulkSubscribersFactory(this);
32
33
 
33
34
  this._user = new SubscriberFactory(this);
35
+
36
+ this.brands = new BrandsApi(this);
37
+
34
38
  this._validate();
35
39
  }
36
40
 
@@ -11,6 +11,11 @@
11
11
  "maxLength": 64,
12
12
  "description": "unique id provided by client for request"
13
13
  },
14
+ "brand_id": {
15
+ "type": ["string", "null"],
16
+ "maxLength": 64,
17
+ "description": "brand id for workflow to be run in context of a brand"
18
+ },
14
19
  "$insert_id": {
15
20
  "type": "string",
16
21
  "minLength": 36,
@@ -11,6 +11,11 @@
11
11
  "maxLength": 64,
12
12
  "description": "unique id provided by client for request"
13
13
  },
14
+ "brand_id": {
15
+ "type": ["string", "null"],
16
+ "maxLength": 64,
17
+ "description": "brand id for workflow to be run in context of a brand"
18
+ },
14
19
  "name": {
15
20
  "$ref": "#/definitions/non_empty_string",
16
21
  "description": "name of workflow"
package/src/signature.js CHANGED
@@ -12,17 +12,18 @@ export default function get_request_signature(
12
12
  headers,
13
13
  secret
14
14
  ) {
15
- if (http_verb === "GET") {
16
- return "";
15
+ let content_md5 = "";
16
+ let content_type = headers["Content-Type"] || "";
17
+ if (content) {
18
+ content_md5 = crypto.createHash("md5").update(content).digest("hex");
17
19
  }
18
- const content_md5 = crypto.createHash("md5").update(content).digest("hex");
19
20
  const request_uri = get_path(url);
20
21
  const sign_string =
21
22
  http_verb +
22
23
  "\n" +
23
24
  content_md5 +
24
25
  "\n" +
25
- headers["Content-Type"] +
26
+ content_type +
26
27
  "\n" +
27
28
  headers["Date"] +
28
29
  "\n" +
package/src/utils.js CHANGED
@@ -44,6 +44,19 @@ export class SuprsendConfigError extends Error {
44
44
  }
45
45
  }
46
46
 
47
+ export class SuprsendApiError extends Error {
48
+ constructor(error) {
49
+ let message;
50
+ if (error.response) {
51
+ message = `${error.response.status}: ${error.response.data.message}`;
52
+ } else {
53
+ message = error.message;
54
+ }
55
+ super(message);
56
+ this.name = "SuprsendApiError";
57
+ }
58
+ }
59
+
47
60
  export function is_string(value) {
48
61
  return typeof value === "string";
49
62
  }
package/src/workflow.js CHANGED
@@ -18,6 +18,7 @@ export default class Workflow {
18
18
  }
19
19
  this.body = body;
20
20
  this.idempotency_key = kwargs?.idempotency_key;
21
+ this.brand_id = kwargs?.brand_id;
21
22
  }
22
23
 
23
24
  add_attachment(file_path = "", kwargs = {}) {
@@ -46,6 +47,9 @@ export default class Workflow {
46
47
  if (this.idempotency_key) {
47
48
  this.body["$idempotency_key"] = this.idempotency_key;
48
49
  }
50
+ if (this.brand_id) {
51
+ this.body["brand_id"] = this.brand_id;
52
+ }
49
53
  this.body = validate_workflow_body_schema(this.body);
50
54
  const apparent_size = get_apparent_workflow_body_size(
51
55
  this.body,