@suprsend/node-sdk 0.0.6 → 0.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.
- package/dist/event.js +205 -0
- package/dist/identity.js +417 -0
- package/dist/identity_helper.js +648 -0
- package/dist/index.js +12 -0
- package/dist/request_json/event.json +47 -0
- package/dist/request_json/workflow.json +49 -3
- package/dist/signature.js +1 -1
- package/dist/utils.js +42 -224
- package/dist/workflow.js +4 -2
- package/package.json +5 -4
- package/src/event.js +148 -0
- package/src/identity.js +281 -0
- package/src/identity_helper.js +463 -0
- package/src/index.js +8 -0
- package/src/request_json/event.json +47 -0
- package/src/request_json/workflow.json +49 -3
- package/src/signature.js +1 -4
- package/src/utils.js +28 -204
- package/src/workflow.js +5 -3
package/dist/event.js
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
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 _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
+
|
|
14
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
+
|
|
16
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
17
|
+
|
|
18
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
19
|
+
|
|
20
|
+
var _utils = require("./utils");
|
|
21
|
+
|
|
22
|
+
var _signature = _interopRequireDefault(require("./signature"));
|
|
23
|
+
|
|
24
|
+
var _jsonschema = require("jsonschema");
|
|
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); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
31
|
+
|
|
32
|
+
var event_schema = require("./request_json/event.json");
|
|
33
|
+
|
|
34
|
+
var RESERVED_EVENT_NAMES = ["$identify", "$notification_delivered", "$notification_dismiss", "$notification_clicked", "$app_launched", "$user_login", "$user_logout"];
|
|
35
|
+
|
|
36
|
+
var EventCollector = /*#__PURE__*/function () {
|
|
37
|
+
function EventCollector(config) {
|
|
38
|
+
(0, _classCallCheck2["default"])(this, EventCollector);
|
|
39
|
+
this.config = config;
|
|
40
|
+
this.__url = this.__get_url();
|
|
41
|
+
this.__headers = this.__common_headers();
|
|
42
|
+
this.__supr_props = this.__super_properties();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
(0, _createClass2["default"])(EventCollector, [{
|
|
46
|
+
key: "__get_url",
|
|
47
|
+
value: function __get_url() {
|
|
48
|
+
var url_template = "event/";
|
|
49
|
+
|
|
50
|
+
if (this.config.include_signature_param) {
|
|
51
|
+
if (this.config.auth_enabled) {
|
|
52
|
+
url_template = url_template + "?verify=true";
|
|
53
|
+
} else {
|
|
54
|
+
url_template = url_template + "?verify=false";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return "".concat(this.config.base_url).concat(url_template);
|
|
59
|
+
}
|
|
60
|
+
}, {
|
|
61
|
+
key: "__common_headers",
|
|
62
|
+
value: function __common_headers() {
|
|
63
|
+
return {
|
|
64
|
+
"Content-Type": "application/json; charset=utf-8",
|
|
65
|
+
"User-Agent": this.config.user_agent
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}, {
|
|
69
|
+
key: "__dynamic_headers",
|
|
70
|
+
value: function __dynamic_headers() {
|
|
71
|
+
return {
|
|
72
|
+
Date: new Date().toUTCString()
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}, {
|
|
76
|
+
key: "__super_properties",
|
|
77
|
+
value: function __super_properties() {
|
|
78
|
+
return {
|
|
79
|
+
$ss_sdk_version: this.config.user_agent
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}, {
|
|
83
|
+
key: "__check_event_prefix",
|
|
84
|
+
value: function __check_event_prefix(event_name) {
|
|
85
|
+
if (!RESERVED_EVENT_NAMES.includes(event_name)) {
|
|
86
|
+
if ((0, _utils.has_special_char)(event_name)) {
|
|
87
|
+
throw new _utils.SuprsendError("event_names starting with [$,ss_] are reserved");
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}, {
|
|
92
|
+
key: "__validate_event_name",
|
|
93
|
+
value: function __validate_event_name(event_name) {
|
|
94
|
+
if (!(0, _utils.is_string)(event_name)) {
|
|
95
|
+
throw new _utils.SuprsendError("event_name must be a string");
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
event_name = event_name.trim();
|
|
99
|
+
|
|
100
|
+
this.__check_event_prefix(event_name);
|
|
101
|
+
|
|
102
|
+
return event_name;
|
|
103
|
+
}
|
|
104
|
+
}, {
|
|
105
|
+
key: "validate_track_event_schema",
|
|
106
|
+
value: function validate_track_event_schema(data) {
|
|
107
|
+
if (!data["properties"]) {
|
|
108
|
+
data["properties"] = {};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
var schema = event_schema;
|
|
112
|
+
var v = new _jsonschema.Validator();
|
|
113
|
+
var validated_data = v.validate(data, schema);
|
|
114
|
+
|
|
115
|
+
if (validated_data.valid) {
|
|
116
|
+
return data;
|
|
117
|
+
} else {
|
|
118
|
+
var error_obj = validated_data.errors[0];
|
|
119
|
+
var error_msg = "".concat(error_obj.property, " ").concat(error_obj.message);
|
|
120
|
+
throw new _utils.SuprsendError(error_msg);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}, {
|
|
124
|
+
key: "collect",
|
|
125
|
+
value: function collect(distinct_id, event_name) {
|
|
126
|
+
var properties = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
127
|
+
event_name = this.__validate_event_name(event_name);
|
|
128
|
+
|
|
129
|
+
if (!(0, _utils.is_object)(properties)) {
|
|
130
|
+
throw new _utils.SuprsendError("properties must be a dictionary");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
properties = _objectSpread(_objectSpread({}, properties), this.__supr_props);
|
|
134
|
+
var event = {
|
|
135
|
+
$insert_id: (0, _utils.uuid)(),
|
|
136
|
+
$time: (0, _utils.epoch_milliseconds)(),
|
|
137
|
+
event: event_name,
|
|
138
|
+
env: this.config.env_key,
|
|
139
|
+
distinct_id: distinct_id,
|
|
140
|
+
properties: properties
|
|
141
|
+
};
|
|
142
|
+
event = this.validate_track_event_schema(event);
|
|
143
|
+
return this.send(event);
|
|
144
|
+
}
|
|
145
|
+
}, {
|
|
146
|
+
key: "send",
|
|
147
|
+
value: function () {
|
|
148
|
+
var _send = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(event) {
|
|
149
|
+
var headers, content_text, signature, response;
|
|
150
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
151
|
+
while (1) {
|
|
152
|
+
switch (_context.prev = _context.next) {
|
|
153
|
+
case 0:
|
|
154
|
+
headers = _objectSpread(_objectSpread({}, this.__headers), this.__dynamic_headers());
|
|
155
|
+
content_text = JSON.stringify(event);
|
|
156
|
+
|
|
157
|
+
if (this.config.auth_enabled) {
|
|
158
|
+
signature = (0, _signature["default"])(this.__url, "POST", content_text, headers, this.config.env_secret);
|
|
159
|
+
headers["Authorization"] = "".concat(this.config.env_key, ":").concat(signature);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
_context.prev = 3;
|
|
163
|
+
_context.next = 6;
|
|
164
|
+
return _axios["default"].post(this.__url, content_text, {
|
|
165
|
+
headers: headers
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
case 6:
|
|
169
|
+
response = _context.sent;
|
|
170
|
+
return _context.abrupt("return", {
|
|
171
|
+
status_code: response.status,
|
|
172
|
+
success: true,
|
|
173
|
+
message: response.statusText
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
case 10:
|
|
177
|
+
_context.prev = 10;
|
|
178
|
+
_context.t0 = _context["catch"](3);
|
|
179
|
+
return _context.abrupt("return", {
|
|
180
|
+
status_code: 400,
|
|
181
|
+
success: false,
|
|
182
|
+
message: _context.t0.message
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
case 13:
|
|
186
|
+
case "end":
|
|
187
|
+
return _context.stop();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}, _callee, this, [[3, 10]]);
|
|
191
|
+
}));
|
|
192
|
+
|
|
193
|
+
function send(_x) {
|
|
194
|
+
return _send.apply(this, arguments);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return send;
|
|
198
|
+
}()
|
|
199
|
+
}]);
|
|
200
|
+
return EventCollector;
|
|
201
|
+
}();
|
|
202
|
+
|
|
203
|
+
var _default = EventCollector;
|
|
204
|
+
exports["default"] = _default;
|
|
205
|
+
module.exports = exports.default;
|
package/dist/identity.js
ADDED
|
@@ -0,0 +1,417 @@
|
|
|
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 _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
13
|
+
|
|
14
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
15
|
+
|
|
16
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
17
|
+
|
|
18
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
19
|
+
|
|
20
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
21
|
+
|
|
22
|
+
var _utils = require("./utils");
|
|
23
|
+
|
|
24
|
+
var _signature = _interopRequireDefault(require("./signature"));
|
|
25
|
+
|
|
26
|
+
var _axios = _interopRequireDefault(require("axios"));
|
|
27
|
+
|
|
28
|
+
var _identity_helper = _interopRequireDefault(require("./identity_helper"));
|
|
29
|
+
|
|
30
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
31
|
+
|
|
32
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
33
|
+
|
|
34
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
35
|
+
|
|
36
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
37
|
+
|
|
38
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
39
|
+
|
|
40
|
+
var UserIdentityFactory = /*#__PURE__*/function () {
|
|
41
|
+
function UserIdentityFactory(config) {
|
|
42
|
+
(0, _classCallCheck2["default"])(this, UserIdentityFactory);
|
|
43
|
+
this.config = config;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
(0, _createClass2["default"])(UserIdentityFactory, [{
|
|
47
|
+
key: "new_user",
|
|
48
|
+
value: function new_user(distinct_id) {
|
|
49
|
+
if (!(0, _utils.is_string)(distinct_id)) {
|
|
50
|
+
throw new _utils.SuprsendError("distinct_id must be a string. an Id which uniquely identify a user in your app");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
distinct_id = distinct_id.trim();
|
|
54
|
+
|
|
55
|
+
if (!distinct_id) {
|
|
56
|
+
throw new _utils.SuprsendError("distinct_id must be passed");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return new UserIdentity(this.config, distinct_id);
|
|
60
|
+
}
|
|
61
|
+
}]);
|
|
62
|
+
return UserIdentityFactory;
|
|
63
|
+
}();
|
|
64
|
+
|
|
65
|
+
exports["default"] = UserIdentityFactory;
|
|
66
|
+
|
|
67
|
+
var UserIdentity = /*#__PURE__*/function () {
|
|
68
|
+
function UserIdentity(config, distinct_id) {
|
|
69
|
+
(0, _classCallCheck2["default"])(this, UserIdentity);
|
|
70
|
+
this.config = config;
|
|
71
|
+
this.distinct_id = distinct_id;
|
|
72
|
+
this.__url = this.__get_url();
|
|
73
|
+
this.__supr_props = this.__super_properties();
|
|
74
|
+
this.__errors = [];
|
|
75
|
+
this.__info = [];
|
|
76
|
+
this._append_count = 0;
|
|
77
|
+
this._remove_count = 0;
|
|
78
|
+
this._events = [];
|
|
79
|
+
this._helper = new _identity_helper["default"](distinct_id, config.env_key);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
(0, _createClass2["default"])(UserIdentity, [{
|
|
83
|
+
key: "__get_url",
|
|
84
|
+
value: function __get_url() {
|
|
85
|
+
var url_template = "event/";
|
|
86
|
+
|
|
87
|
+
if (this.config.include_signature_param) {
|
|
88
|
+
if (this.config.auth_enabled) {
|
|
89
|
+
url_template = url_template + "?verify=true";
|
|
90
|
+
} else {
|
|
91
|
+
url_template = url_template + "?verify=false";
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return "".concat(this.config.base_url).concat(url_template);
|
|
96
|
+
}
|
|
97
|
+
}, {
|
|
98
|
+
key: "__get_headers",
|
|
99
|
+
value: function __get_headers() {
|
|
100
|
+
return {
|
|
101
|
+
"Content-Type": "application/json; charset=utf-8",
|
|
102
|
+
Date: new Date().toUTCString(),
|
|
103
|
+
"User-Agent": this.config.user_agent
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}, {
|
|
107
|
+
key: "__super_properties",
|
|
108
|
+
value: function __super_properties() {
|
|
109
|
+
return {
|
|
110
|
+
$ss_sdk_version: this.config.user_agent
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}, {
|
|
114
|
+
key: "__get_events",
|
|
115
|
+
value: function __get_events() {
|
|
116
|
+
var all_events = this._events;
|
|
117
|
+
|
|
118
|
+
var _iterator = _createForOfIteratorHelper(all_events),
|
|
119
|
+
_step;
|
|
120
|
+
|
|
121
|
+
try {
|
|
122
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
123
|
+
var e = _step.value;
|
|
124
|
+
e["properties"] = this.__supr_props;
|
|
125
|
+
}
|
|
126
|
+
} catch (err) {
|
|
127
|
+
_iterator.e(err);
|
|
128
|
+
} finally {
|
|
129
|
+
_iterator.f();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (this._append_count > 0) {
|
|
133
|
+
var user_identify_event = {
|
|
134
|
+
$insert_id: (0, _utils.uuid)(),
|
|
135
|
+
$time: (0, _utils.epoch_milliseconds)(),
|
|
136
|
+
env: this.config.env_key,
|
|
137
|
+
event: "$identify",
|
|
138
|
+
properties: _objectSpread({
|
|
139
|
+
$anon_id: this.distinct_id,
|
|
140
|
+
$identified_id: this.distinct_id
|
|
141
|
+
}, this.__super_properties)
|
|
142
|
+
};
|
|
143
|
+
all_events.push(user_identify_event);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return all_events;
|
|
147
|
+
}
|
|
148
|
+
}, {
|
|
149
|
+
key: "__validate_body",
|
|
150
|
+
value: function __validate_body() {
|
|
151
|
+
if (!(0, _utils.is_empty)(this.__info)) {
|
|
152
|
+
console.log("WARNING: " + this.__info.join("\n"));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (!(0, _utils.is_empty)(this.__errors)) {
|
|
156
|
+
throw new _utils.SuprsendError("ERROR: " + this.__errors.join("\n"));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if ((0, _utils.is_empty)(this._events)) {
|
|
160
|
+
throw new _utils.SuprsendError("ERROR: no user properties have been edited. Use user.append/remove/unset method to update user properties");
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}, {
|
|
164
|
+
key: "save",
|
|
165
|
+
value: function () {
|
|
166
|
+
var _save = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
|
167
|
+
var headers, events, content_text, signature, response;
|
|
168
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
169
|
+
while (1) {
|
|
170
|
+
switch (_context.prev = _context.next) {
|
|
171
|
+
case 0:
|
|
172
|
+
this.__validate_body();
|
|
173
|
+
|
|
174
|
+
headers = this.__get_headers();
|
|
175
|
+
events = this.__get_events();
|
|
176
|
+
content_text = JSON.stringify(events);
|
|
177
|
+
|
|
178
|
+
if (this.config.auth_enabled) {
|
|
179
|
+
signature = (0, _signature["default"])(this.__url, "POST", content_text, headers, this.config.env_secret);
|
|
180
|
+
headers["Authorization"] = "".concat(this.config.env_key, ":").concat(signature);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
_context.prev = 5;
|
|
184
|
+
_context.next = 8;
|
|
185
|
+
return _axios["default"].post(this.__url, content_text, {
|
|
186
|
+
headers: headers
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
case 8:
|
|
190
|
+
response = _context.sent;
|
|
191
|
+
return _context.abrupt("return", {
|
|
192
|
+
status_code: response.status,
|
|
193
|
+
success: true,
|
|
194
|
+
message: response.statusText
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
case 12:
|
|
198
|
+
_context.prev = 12;
|
|
199
|
+
_context.t0 = _context["catch"](5);
|
|
200
|
+
return _context.abrupt("return", {
|
|
201
|
+
status_code: 400,
|
|
202
|
+
success: false,
|
|
203
|
+
message: _context.t0.message
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
case 15:
|
|
207
|
+
case "end":
|
|
208
|
+
return _context.stop();
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}, _callee, this, [[5, 12]]);
|
|
212
|
+
}));
|
|
213
|
+
|
|
214
|
+
function save() {
|
|
215
|
+
return _save.apply(this, arguments);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return save;
|
|
219
|
+
}()
|
|
220
|
+
}, {
|
|
221
|
+
key: "_collect_event",
|
|
222
|
+
value: function _collect_event() {
|
|
223
|
+
var resp = this._helper.get_identity_events();
|
|
224
|
+
|
|
225
|
+
if (!(0, _utils.is_empty)(resp["errors"])) {
|
|
226
|
+
this.__errors = [].concat((0, _toConsumableArray2["default"])(this.__errors), (0, _toConsumableArray2["default"])(resp["errors"]));
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (!(0, _utils.is_empty)(resp["info"])) {
|
|
230
|
+
this.__info = [].concat((0, _toConsumableArray2["default"])(this.__info), (0, _toConsumableArray2["default"])(resp["info"]));
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (!(0, _utils.is_empty)(resp["event"])) {
|
|
234
|
+
this._events.push(resp["event"]);
|
|
235
|
+
|
|
236
|
+
this._append_count += resp["append"];
|
|
237
|
+
this._remove_count += resp["remove"];
|
|
238
|
+
this._unset_count += resp["unset"];
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}, {
|
|
242
|
+
key: "append",
|
|
243
|
+
value: function append(key, value) {
|
|
244
|
+
var caller = "append";
|
|
245
|
+
|
|
246
|
+
if (!(0, _utils.is_string)(key) && !(0, _utils.is_object)(key)) {
|
|
247
|
+
this.__errors.push("[".concat(caller, "] arg1 must be either string or a dict"));
|
|
248
|
+
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if ((0, _utils.is_string)(key)) {
|
|
253
|
+
if (!value) {
|
|
254
|
+
this.__errors.push("[".concat(caller, "] if arg1 is a string, then arg2 must be passed"));
|
|
255
|
+
|
|
256
|
+
return;
|
|
257
|
+
} else {
|
|
258
|
+
this._helper._append_kv(key, value, {}, caller);
|
|
259
|
+
|
|
260
|
+
this._collect_event();
|
|
261
|
+
}
|
|
262
|
+
} else {
|
|
263
|
+
for (var item in key) {
|
|
264
|
+
this._helper._append_kv(item, key[item], key, caller);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
this._collect_event();
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}, {
|
|
271
|
+
key: "remove",
|
|
272
|
+
value: function remove(key, value) {
|
|
273
|
+
var caller = "remove";
|
|
274
|
+
|
|
275
|
+
if (!(0, _utils.is_string)(key) && !(0, _utils.is_object)(key)) {
|
|
276
|
+
this.__errors.push("[".concat(caller, "] arg1 must be either string or a dict"));
|
|
277
|
+
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if ((0, _utils.is_string)(key)) {
|
|
282
|
+
if (!value) {
|
|
283
|
+
this.__errors.push("[".concat(caller, "] if arg1 is a string, then arg2 must be passed"));
|
|
284
|
+
|
|
285
|
+
return;
|
|
286
|
+
} else {
|
|
287
|
+
this._helper._remove_kv(key, value, {}, caller);
|
|
288
|
+
|
|
289
|
+
this._collect_event();
|
|
290
|
+
}
|
|
291
|
+
} else {
|
|
292
|
+
for (var item in key) {
|
|
293
|
+
this._helper._remove_kv(item, key[item], key, caller);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
this._collect_event();
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}, {
|
|
300
|
+
key: "add_email",
|
|
301
|
+
value: function add_email(email) {
|
|
302
|
+
var caller = "add_email";
|
|
303
|
+
|
|
304
|
+
this._helper._add_email(email, caller);
|
|
305
|
+
|
|
306
|
+
this._collect_event();
|
|
307
|
+
}
|
|
308
|
+
}, {
|
|
309
|
+
key: "remove_email",
|
|
310
|
+
value: function remove_email(email) {
|
|
311
|
+
var caller = "remove_email";
|
|
312
|
+
|
|
313
|
+
this._helper._remove_email(email, caller);
|
|
314
|
+
|
|
315
|
+
this._collect_event();
|
|
316
|
+
}
|
|
317
|
+
}, {
|
|
318
|
+
key: "add_sms",
|
|
319
|
+
value: function add_sms(mobile_no) {
|
|
320
|
+
var caller = "add_sms";
|
|
321
|
+
|
|
322
|
+
this._helper._add_sms(mobile_no, caller);
|
|
323
|
+
|
|
324
|
+
this._collect_event();
|
|
325
|
+
}
|
|
326
|
+
}, {
|
|
327
|
+
key: "remove_sms",
|
|
328
|
+
value: function remove_sms(mobile_no) {
|
|
329
|
+
var caller = "remove_sms";
|
|
330
|
+
|
|
331
|
+
this._helper._remove_sms(mobile_no, caller);
|
|
332
|
+
|
|
333
|
+
this._collect_event();
|
|
334
|
+
}
|
|
335
|
+
}, {
|
|
336
|
+
key: "add_whatsapp",
|
|
337
|
+
value: function add_whatsapp(mobile_no) {
|
|
338
|
+
var caller = "add_whatsapp";
|
|
339
|
+
|
|
340
|
+
this._helper._add_whatsapp(mobile_no, caller);
|
|
341
|
+
|
|
342
|
+
this._collect_event();
|
|
343
|
+
}
|
|
344
|
+
}, {
|
|
345
|
+
key: "remove_whatsapp",
|
|
346
|
+
value: function remove_whatsapp(mobile_no) {
|
|
347
|
+
var caller = "remove_whatsapp";
|
|
348
|
+
|
|
349
|
+
this._helper._remove_whatsapp(mobile_no, caller);
|
|
350
|
+
|
|
351
|
+
this._collect_event();
|
|
352
|
+
}
|
|
353
|
+
}, {
|
|
354
|
+
key: "add_androidpush",
|
|
355
|
+
value: function add_androidpush(push_token) {
|
|
356
|
+
var provider = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "fcm";
|
|
357
|
+
var caller = "add_androidpush";
|
|
358
|
+
|
|
359
|
+
this._helper._add_androidpush(push_token, provider, caller);
|
|
360
|
+
|
|
361
|
+
this._collect_event();
|
|
362
|
+
}
|
|
363
|
+
}, {
|
|
364
|
+
key: "remove_androidpush",
|
|
365
|
+
value: function remove_androidpush(push_token) {
|
|
366
|
+
var provider = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "fcm";
|
|
367
|
+
var caller = "remove_androidpush";
|
|
368
|
+
|
|
369
|
+
this._helper._remove_androidpush(push_token, provider, caller);
|
|
370
|
+
|
|
371
|
+
this._collect_event();
|
|
372
|
+
}
|
|
373
|
+
}, {
|
|
374
|
+
key: "add_iospush",
|
|
375
|
+
value: function add_iospush(push_token) {
|
|
376
|
+
var provider = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "apns";
|
|
377
|
+
var caller = "add_iospush";
|
|
378
|
+
|
|
379
|
+
this._helper._add_iospush(push_token, provider, caller);
|
|
380
|
+
|
|
381
|
+
this._collect_event();
|
|
382
|
+
}
|
|
383
|
+
}, {
|
|
384
|
+
key: "remove_iospush",
|
|
385
|
+
value: function remove_iospush(push_token) {
|
|
386
|
+
var provider = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "apns";
|
|
387
|
+
var caller = "remove_iospush";
|
|
388
|
+
|
|
389
|
+
this._helper._remove_iospush(push_token, provider, caller);
|
|
390
|
+
|
|
391
|
+
this._collect_event();
|
|
392
|
+
}
|
|
393
|
+
}, {
|
|
394
|
+
key: "add_webpush",
|
|
395
|
+
value: function add_webpush(push_token) {
|
|
396
|
+
var provider = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "vapid";
|
|
397
|
+
var caller = "add_webpush";
|
|
398
|
+
|
|
399
|
+
this._helper._add_webpush(push_token, provider, caller);
|
|
400
|
+
|
|
401
|
+
this._collect_event();
|
|
402
|
+
}
|
|
403
|
+
}, {
|
|
404
|
+
key: "remove_webpush",
|
|
405
|
+
value: function remove_webpush(push_token) {
|
|
406
|
+
var provider = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "vapid";
|
|
407
|
+
var caller = "remove_webpush";
|
|
408
|
+
|
|
409
|
+
this._helper._remove_webpush(push_token, provider, caller);
|
|
410
|
+
|
|
411
|
+
this._collect_event();
|
|
412
|
+
}
|
|
413
|
+
}]);
|
|
414
|
+
return UserIdentity;
|
|
415
|
+
}();
|
|
416
|
+
|
|
417
|
+
module.exports = exports.default;
|