@steedos/client 3.0.0-beta.2 → 3.0.0-beta.8

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/lib/client4.d.ts CHANGED
@@ -63,9 +63,9 @@ export default class SteedosClient {
63
63
  headers: {
64
64
  [x: string]: string;
65
65
  };
66
- method?: string | undefined;
67
- url?: string | undefined;
68
- credentials?: "omit" | "same-origin" | "include" | undefined;
66
+ method?: string;
67
+ url?: string;
68
+ credentials?: "omit" | "same-origin" | "include";
69
69
  body?: any;
70
70
  };
71
71
  getTranslations: (url: string) => Promise<Record<string, string>>;
package/lib/client4.js CHANGED
@@ -1,117 +1,29 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
- return new (P || (P = Promise))(function (resolve, reject) {
31
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
- step((generator = generator.apply(thisArg, _arguments || [])).next());
35
- });
36
- };
37
- var __generator = (this && this.__generator) || function (thisArg, body) {
38
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
- function verb(n) { return function (v) { return step([n, v]); }; }
41
- function step(op) {
42
- if (f) throw new TypeError("Generator is already executing.");
43
- while (_) try {
44
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
45
- if (y = 0, t) op = [op[0] & 2, t.value];
46
- switch (op[0]) {
47
- case 0: case 1: t = op; break;
48
- case 4: _.label++; return { value: op[1], done: false };
49
- case 5: _.label++; y = op[1]; op = [0]; continue;
50
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
- default:
52
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
- if (t[2]) _.ops.pop();
57
- _.trys.pop(); continue;
58
- }
59
- op = body.call(thisArg, _);
60
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
- }
63
- };
64
- var __read = (this && this.__read) || function (o, n) {
65
- var m = typeof Symbol === "function" && o[Symbol.iterator];
66
- if (!m) return o;
67
- var i = m.call(o), r, ar = [], e;
68
- try {
69
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
70
- }
71
- catch (error) { e = { error: error }; }
72
- finally {
73
- try {
74
- if (r && !r.done && (m = i["return"])) m.call(i);
75
- }
76
- finally { if (e) throw e.error; }
77
- }
78
- return ar;
79
- };
80
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
81
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
82
- if (ar || !(i in from)) {
83
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
84
- ar[i] = from[i];
85
- }
86
- }
87
- return to.concat(ar || Array.prototype.slice.call(from));
88
- };
89
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
90
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
91
4
  };
92
5
  Object.defineProperty(exports, "__esModule", { value: true });
93
6
  exports.ClientError = exports.DEFAULT_LIMIT_AFTER = exports.DEFAULT_LIMIT_BEFORE = exports.HEADER_X_VERSION_ID = void 0;
94
- var fetch_etag_1 = __importDefault(require("./fetch_etag"));
95
- var sentry_1 = require("./utils/sentry");
96
- var helpers_1 = require("./utils/helpers");
97
- var sobject_1 = __importDefault(require("./sobject"));
98
- var graphql_1 = __importDefault(require("./graphql"));
99
- var HEADER_AUTH = 'Authorization';
100
- var HEADER_BEARER = 'Bearer';
101
- var HEADER_REQUESTED_WITH = 'X-Requested-With';
102
- var HEADER_USER_AGENT = 'User-Agent';
103
- var HEADER_X_CLUSTER_ID = 'X-Cluster-Id';
104
- var HEADER_X_CSRF_TOKEN = 'X-CSRF-Token';
7
+ const fetch_etag_1 = __importDefault(require("./fetch_etag"));
8
+ const sentry_1 = require("./utils/sentry");
9
+ const helpers_1 = require("./utils/helpers");
10
+ const sobject_1 = __importDefault(require("./sobject"));
11
+ const graphql_1 = __importDefault(require("./graphql"));
12
+ const HEADER_AUTH = 'Authorization';
13
+ const HEADER_BEARER = 'Bearer';
14
+ const HEADER_REQUESTED_WITH = 'X-Requested-With';
15
+ const HEADER_USER_AGENT = 'User-Agent';
16
+ const HEADER_X_CLUSTER_ID = 'X-Cluster-Id';
17
+ const HEADER_X_CSRF_TOKEN = 'X-CSRF-Token';
105
18
  exports.HEADER_X_VERSION_ID = 'X-Version-Id';
106
- var PER_PAGE_DEFAULT = 60;
107
- var LOGS_PER_PAGE_DEFAULT = 10000;
19
+ const PER_PAGE_DEFAULT = 60;
20
+ const LOGS_PER_PAGE_DEFAULT = 10000;
108
21
  exports.DEFAULT_LIMIT_BEFORE = 30;
109
22
  exports.DEFAULT_LIMIT_AFTER = 30;
110
- var DEFAULT_LOGIN_EXPIRATION_DAYS = 90;
111
- var LOGIN_UNEXPIRING_TOKEN_DAYS = 365 * 100;
112
- var SteedosClient = (function () {
113
- function SteedosClient() {
114
- var _this = this;
23
+ const DEFAULT_LOGIN_EXPIRATION_DAYS = 90;
24
+ const LOGIN_UNEXPIRING_TOKEN_DAYS = 365 * 100;
25
+ class SteedosClient {
26
+ constructor() {
115
27
  this.LOGIN_TOKEN_KEY = "Meteor.loginToken";
116
28
  this.LOGIN_TOKEN_EXPIRES_KEY = "Meteor.loginTokenExpires";
117
29
  this.USER_ID_KEY = "Meteor.userId";
@@ -141,28 +53,25 @@ var SteedosClient = (function () {
141
53
  };
142
54
  this.sobjects = {};
143
55
  this.graphql = new graphql_1.default(this);
144
- this.getTranslations = function (url) {
145
- return _this.doFetch(url, { method: 'get' });
56
+ this.getTranslations = (url) => {
57
+ return this.doFetch(url, { method: 'get' });
146
58
  };
147
- this.logClientError = function (message, level) {
148
- if (level === void 0) { level = 'ERROR'; }
59
+ this.logClientError = (message, level = 'ERROR') => {
149
60
  };
150
- this.login = function (user, password, token, deviceId) {
151
- if (token === void 0) { token = ''; }
152
- if (deviceId === void 0) { deviceId = ''; }
153
- _this.trackEvent('api', 'api_users_login');
154
- var body = {
61
+ this.login = (user, password, token = '', deviceId = '') => {
62
+ this.trackEvent('api', 'api_users_login');
63
+ const body = {
155
64
  device_id: deviceId,
156
- user: user,
157
- password: password,
158
- token: token,
65
+ user,
66
+ password,
67
+ token,
159
68
  locale: "zh-cn"
160
69
  };
161
- return _this.doFetch("".concat(_this.getAccountsRoute(), "/password/login"), { method: 'POST', body: JSON.stringify(body) });
70
+ return this.doFetch(`${this.getAccountsRoute()}/password/login`, { method: 'POST', body: JSON.stringify(body) });
162
71
  };
163
- this.createUser = function (user, token, inviteId, redirect) {
164
- _this.trackEvent('api', 'api_users_createUser');
165
- var queryParams = {};
72
+ this.createUser = (user, token, inviteId, redirect) => {
73
+ this.trackEvent('api', 'api_users_createUser');
74
+ const queryParams = {};
166
75
  if (token) {
167
76
  queryParams.t = token;
168
77
  }
@@ -172,132 +81,106 @@ var SteedosClient = (function () {
172
81
  if (redirect) {
173
82
  queryParams.r = redirect;
174
83
  }
175
- var auth = _this.doFetch("".concat(_this.getAccountsRoute(), "/password/register").concat((0, helpers_1.buildQueryString)(queryParams)), { method: 'POST', body: JSON.stringify(user) });
84
+ const auth = this.doFetch(`${this.getAccountsRoute()}/password/register${(0, helpers_1.buildQueryString)(queryParams)}`, { method: 'POST', body: JSON.stringify(user) });
176
85
  return auth;
177
86
  };
178
- this.createSpace = function (name) {
179
- _this.trackEvent('api', 'api_users_createTenant');
180
- var queryParams = {};
181
- var auth = _this.doFetch("".concat(_this.getBaseRoute(), "/api/v4/spaces/register/tenant").concat((0, helpers_1.buildQueryString)(queryParams)), { method: 'POST', body: JSON.stringify({ name: name }) });
87
+ this.createSpace = (name) => {
88
+ this.trackEvent('api', 'api_users_createTenant');
89
+ const queryParams = {};
90
+ const auth = this.doFetch(`${this.getBaseRoute()}/api/v4/spaces/register/tenant${(0, helpers_1.buildQueryString)(queryParams)}`, { method: 'POST', body: JSON.stringify({ name: name }) });
182
91
  return auth;
183
92
  };
184
- this.sendVerificationToken = function (user) {
185
- _this.trackEvent('api', 'api_users_verify');
186
- var body = {
93
+ this.sendVerificationToken = (user) => {
94
+ this.trackEvent('api', 'api_users_verify');
95
+ const body = {
187
96
  user: user,
188
97
  };
189
- return _this.doFetch("".concat(_this.getAccountsRoute(), "/password/sendVerificationCode"), { method: 'POST', body: JSON.stringify(body) });
98
+ return this.doFetch(`${this.getAccountsRoute()}/password/sendVerificationCode`, { method: 'POST', body: JSON.stringify(body) });
190
99
  };
191
- this.getSettings = function () {
192
- return _this.doFetch("".concat(_this.getAccountsRoute(), "/settings"), { method: 'get' });
100
+ this.getSettings = () => {
101
+ return this.doFetch(`${this.getAccountsRoute()}/settings`, { method: 'get' });
193
102
  };
194
- this.getMe = function () {
195
- return _this.doFetch("".concat(_this.getAccountsRoute(), "/user"), { method: 'get' });
103
+ this.getMe = () => {
104
+ return this.doFetch(`${this.getAccountsRoute()}/user`, { method: 'get' });
196
105
  };
197
- this.getMySpaces = function () {
198
- return _this.doFetch("".concat(_this.getAccountsRoute(), "/user/spaces"), { method: 'get' });
106
+ this.getMySpaces = () => {
107
+ return this.doFetch(`${this.getAccountsRoute()}/user/spaces`, { method: 'get' });
199
108
  };
200
- this.logout = function () { return __awaiter(_this, void 0, void 0, function () {
201
- var response;
202
- return __generator(this, function (_a) {
203
- switch (_a.label) {
204
- case 0:
205
- this.trackEvent('api', 'api_users_logout');
206
- return [4, this.doFetchWithResponse("".concat(this.getAccountsRoute(), "/logout"), { method: 'post' })];
207
- case 1:
208
- response = (_a.sent()).response;
209
- if (response.ok) {
210
- this.token = '';
211
- }
212
- this.serverVersion = '';
213
- return [2, response];
214
- }
215
- });
216
- }); };
217
- this.doFetch = function (url, options) { return __awaiter(_this, void 0, void 0, function () {
218
- var data;
219
- return __generator(this, function (_a) {
220
- switch (_a.label) {
221
- case 0: return [4, this.doFetchWithResponse(url, options)];
222
- case 1:
223
- data = (_a.sent()).data;
224
- return [2, data];
109
+ this.logout = async () => {
110
+ this.trackEvent('api', 'api_users_logout');
111
+ const { response } = await this.doFetchWithResponse(`${this.getAccountsRoute()}/logout`, { method: 'post' });
112
+ if (response.ok) {
113
+ this.token = '';
114
+ }
115
+ this.serverVersion = '';
116
+ return response;
117
+ };
118
+ this.doFetch = async (url, options) => {
119
+ const { data } = await this.doFetchWithResponse(url, options);
120
+ return data;
121
+ };
122
+ this.doFetchWithResponse = async (url, options) => {
123
+ const response = await (0, fetch_etag_1.default)(url, this.getOptions(options));
124
+ const headers = parseAndMergeNestedHeaders(response.headers);
125
+ let data;
126
+ try {
127
+ data = await response.json();
128
+ }
129
+ catch (err) {
130
+ throw new ClientError(this.getUrl(), {
131
+ message: 'Received invalid response from the server.',
132
+ intl: {
133
+ id: 'mobile.request.invalid_response',
134
+ defaultMessage: 'Received invalid response from the server.',
135
+ },
136
+ url,
137
+ });
138
+ }
139
+ if (headers.has(exports.HEADER_X_VERSION_ID) && !headers.get('Cache-Control')) {
140
+ const serverVersion = headers.get(exports.HEADER_X_VERSION_ID);
141
+ if (serverVersion && this.serverVersion !== serverVersion) {
142
+ this.serverVersion = serverVersion;
225
143
  }
226
- });
227
- }); };
228
- this.doFetchWithResponse = function (url, options) { return __awaiter(_this, void 0, void 0, function () {
229
- var response, headers, data, err_1, serverVersion, clusterId, error, msg;
230
- return __generator(this, function (_a) {
231
- switch (_a.label) {
232
- case 0: return [4, (0, fetch_etag_1.default)(url, this.getOptions(options))];
233
- case 1:
234
- response = _a.sent();
235
- headers = parseAndMergeNestedHeaders(response.headers);
236
- _a.label = 2;
237
- case 2:
238
- _a.trys.push([2, 4, , 5]);
239
- return [4, response.json()];
240
- case 3:
241
- data = _a.sent();
242
- return [3, 5];
243
- case 4:
244
- err_1 = _a.sent();
245
- throw new ClientError(this.getUrl(), {
246
- message: 'Received invalid response from the server.',
247
- intl: {
248
- id: 'mobile.request.invalid_response',
249
- defaultMessage: 'Received invalid response from the server.',
250
- },
251
- url: url,
252
- });
253
- case 5:
254
- if (headers.has(exports.HEADER_X_VERSION_ID) && !headers.get('Cache-Control')) {
255
- serverVersion = headers.get(exports.HEADER_X_VERSION_ID);
256
- if (serverVersion && this.serverVersion !== serverVersion) {
257
- this.serverVersion = serverVersion;
258
- }
259
- }
260
- if (headers.has(HEADER_X_CLUSTER_ID)) {
261
- clusterId = headers.get(HEADER_X_CLUSTER_ID);
262
- if (clusterId && this.clusterId !== clusterId) {
263
- this.clusterId = clusterId;
264
- }
265
- }
266
- if (response.ok) {
267
- return [2, {
268
- response: response,
269
- headers: headers,
270
- data: data,
271
- }];
272
- }
273
- error = data && data.error ? data.error : data;
274
- msg = error.message || '';
275
- if (this.logToConsole) {
276
- console.error(msg);
277
- }
278
- throw new ClientError(this.getUrl(), {
279
- message: msg,
280
- server_error_id: data.id,
281
- status_code: error.code,
282
- url: url,
283
- });
144
+ }
145
+ if (headers.has(HEADER_X_CLUSTER_ID)) {
146
+ const clusterId = headers.get(HEADER_X_CLUSTER_ID);
147
+ if (clusterId && this.clusterId !== clusterId) {
148
+ this.clusterId = clusterId;
284
149
  }
150
+ }
151
+ if (response.ok) {
152
+ return {
153
+ response,
154
+ headers: headers,
155
+ data,
156
+ };
157
+ }
158
+ const error = data && data.error ? data.error : data;
159
+ const msg = error.message || '';
160
+ if (this.logToConsole) {
161
+ console.error(msg);
162
+ }
163
+ throw new ClientError(this.getUrl(), {
164
+ message: msg,
165
+ server_error_id: data.id,
166
+ status_code: error.code,
167
+ url,
285
168
  });
286
- }); };
287
- this.changePassword = function (oldPassword, newPassword) {
288
- return _this.doFetch("".concat(_this.getAccountsRoute(), "/password/changePassword"), { method: 'POST', body: JSON.stringify({
169
+ };
170
+ this.changePassword = (oldPassword, newPassword) => {
171
+ return this.doFetch(`${this.getAccountsRoute()}/password/changePassword`, { method: 'POST', body: JSON.stringify({
289
172
  oldPassword: oldPassword,
290
173
  newPassword: newPassword,
291
174
  }) });
292
175
  };
293
- this.verifyEmail = function (email, code) {
294
- return _this.doFetch("".concat(_this.getAccountsRoute(), "/password/verify/email"), { method: 'POST', body: JSON.stringify({
176
+ this.verifyEmail = (email, code) => {
177
+ return this.doFetch(`${this.getAccountsRoute()}/password/verify/email`, { method: 'POST', body: JSON.stringify({
295
178
  email: email,
296
179
  code: code,
297
180
  }) });
298
181
  };
299
- this.verifyMobile = function (mobile, code) {
300
- return _this.doFetch("".concat(_this.getAccountsRoute(), "/password/verify/mobile"), { method: 'POST', body: JSON.stringify({
182
+ this.verifyMobile = (mobile, code) => {
183
+ return this.doFetch(`${this.getAccountsRoute()}/password/verify/mobile`, { method: 'POST', body: JSON.stringify({
301
184
  mobile: mobile,
302
185
  code: code,
303
186
  }) });
@@ -308,7 +191,7 @@ var SteedosClient = (function () {
308
191
  return sobject;
309
192
  };
310
193
  }
311
- SteedosClient.prototype.getUrl = function () {
194
+ getUrl() {
312
195
  if (!this.url) {
313
196
  var href = new URL(window.location.href);
314
197
  var foo = href.pathname.split('/accounts');
@@ -319,92 +202,94 @@ var SteedosClient = (function () {
319
202
  return ROOT_URL_PATH_PREFIX;
320
203
  }
321
204
  return this.url;
322
- };
323
- SteedosClient.prototype.getAbsoluteUrl = function (baseUrl) {
205
+ }
206
+ getAbsoluteUrl(baseUrl) {
324
207
  if (typeof baseUrl !== 'string' || !baseUrl.startsWith('/')) {
325
208
  return baseUrl;
326
209
  }
327
210
  return this.getUrl() + baseUrl;
328
- };
329
- SteedosClient.prototype.setUrl = function (url) {
211
+ }
212
+ setUrl(url) {
330
213
  this.url = url;
331
- };
332
- SteedosClient.prototype.setUserAgent = function (userAgent) {
214
+ }
215
+ setUserAgent(userAgent) {
333
216
  this.userAgent = userAgent;
334
- };
335
- SteedosClient.prototype.getToken = function () {
217
+ }
218
+ getToken() {
336
219
  return this.token;
337
- };
338
- SteedosClient.prototype.setToken = function (token) {
220
+ }
221
+ setToken(token) {
339
222
  this.token = token;
340
223
  this.authToken = this.getSpaceId() + ',' + token;
341
- };
342
- SteedosClient.prototype.getSpaceId = function () {
224
+ }
225
+ getSpaceId() {
343
226
  return this.spaceId;
344
- };
345
- SteedosClient.prototype.setSpaceId = function (spaceId) {
227
+ }
228
+ setSpaceId(spaceId) {
346
229
  this.spaceId = spaceId;
347
230
  this.authToken = spaceId + ',' + this.getToken();
348
- };
349
- SteedosClient.prototype.getAuthToken = function () {
231
+ }
232
+ getAuthToken() {
350
233
  return this.authToken;
351
- };
352
- SteedosClient.prototype.setCSRF = function (csrfToken) {
234
+ }
235
+ setCSRF(csrfToken) {
353
236
  this.csrf = csrfToken;
354
- };
355
- SteedosClient.prototype.setAcceptLanguage = function (locale) {
237
+ }
238
+ setAcceptLanguage(locale) {
356
239
  this.defaultHeaders['Accept-Language'] = locale;
357
- };
358
- SteedosClient.prototype.setEnableLogging = function (enable) {
240
+ }
241
+ setEnableLogging(enable) {
359
242
  this.enableLogging = enable;
360
- };
361
- SteedosClient.prototype.setIncludeCookies = function (include) {
243
+ }
244
+ setIncludeCookies(include) {
362
245
  this.includeCookies = include;
363
- };
364
- SteedosClient.prototype.setUserId = function (userId) {
246
+ }
247
+ setUserId(userId) {
365
248
  this.userId = userId;
366
- };
367
- SteedosClient.prototype.setUserRoles = function (roles) {
249
+ }
250
+ setUserRoles(roles) {
368
251
  this.userRoles = roles;
369
- };
370
- SteedosClient.prototype.setDiagnosticId = function (diagnosticId) {
252
+ }
253
+ setDiagnosticId(diagnosticId) {
371
254
  this.diagnosticId = diagnosticId;
372
- };
373
- SteedosClient.prototype.enableRudderEvents = function () {
255
+ }
256
+ enableRudderEvents() {
374
257
  this.isRudderKeySet = true;
375
- };
376
- SteedosClient.prototype.getServerVersion = function () {
258
+ }
259
+ getServerVersion() {
377
260
  return this.serverVersion;
378
- };
379
- SteedosClient.prototype.getUrlVersion = function () {
261
+ }
262
+ getUrlVersion() {
380
263
  return this.urlVersion;
381
- };
382
- SteedosClient.prototype.getBaseRoute = function () {
383
- return "".concat(this.getUrl()).concat(this.urlVersion);
384
- };
385
- SteedosClient.prototype.getAccountsRoute = function () {
386
- return "".concat(this.getBaseRoute(), "/accounts");
387
- };
388
- SteedosClient.prototype.getCSRFFromCookie = function () {
264
+ }
265
+ getBaseRoute() {
266
+ return `${this.getUrl()}${this.urlVersion}`;
267
+ }
268
+ getAccountsRoute() {
269
+ return `${this.getBaseRoute()}/accounts`;
270
+ }
271
+ getCSRFFromCookie() {
389
272
  if (typeof document !== 'undefined' && typeof document.cookie !== 'undefined') {
390
- var cookies = document.cookie.split(';');
391
- for (var i = 0; i < cookies.length; i++) {
392
- var cookie = cookies[i].trim();
273
+ const cookies = document.cookie.split(';');
274
+ for (let i = 0; i < cookies.length; i++) {
275
+ const cookie = cookies[i].trim();
393
276
  if (cookie.startsWith('MMCSRF=')) {
394
277
  return cookie.replace('MMCSRF=', '');
395
278
  }
396
279
  }
397
280
  }
398
281
  return '';
399
- };
400
- SteedosClient.prototype.getOptions = function (options) {
401
- var _a;
402
- var newOptions = __assign({}, options);
403
- var headers = __assign((_a = {}, _a[HEADER_REQUESTED_WITH] = 'XMLHttpRequest', _a), this.defaultHeaders);
282
+ }
283
+ getOptions(options) {
284
+ const newOptions = { ...options };
285
+ const headers = {
286
+ [HEADER_REQUESTED_WITH]: 'XMLHttpRequest',
287
+ ...this.defaultHeaders,
288
+ };
404
289
  if (this.authToken) {
405
- headers[HEADER_AUTH] = "".concat(HEADER_BEARER, " ").concat(this.authToken);
290
+ headers[HEADER_AUTH] = `${HEADER_BEARER} ${this.authToken}`;
406
291
  }
407
- var csrfToken = this.csrf || this.getCSRFFromCookie();
292
+ const csrfToken = this.csrf || this.getCSRFFromCookie();
408
293
  if (options.method && options.method.toLowerCase() !== 'get' && csrfToken) {
409
294
  headers[HEADER_X_CSRF_TOKEN] = csrfToken;
410
295
  }
@@ -417,18 +302,21 @@ var SteedosClient = (function () {
417
302
  if (newOptions.headers) {
418
303
  Object.assign(headers, newOptions.headers);
419
304
  }
420
- return __assign(__assign({}, newOptions), { headers: headers });
421
- };
422
- SteedosClient.prototype.trackEvent = function (category, event, props) {
305
+ return {
306
+ ...newOptions,
307
+ headers,
308
+ };
309
+ }
310
+ trackEvent(category, event, props) {
423
311
  if (!this.isRudderKeySet) {
424
312
  return;
425
313
  }
426
- var properties = Object.assign({
427
- category: category,
314
+ const properties = Object.assign({
315
+ category,
428
316
  type: event,
429
317
  user_actual_id: this.userId,
430
318
  }, props);
431
- var options = {
319
+ const options = {
432
320
  context: {
433
321
  ip: '0.0.0.0',
434
322
  },
@@ -441,39 +329,35 @@ var SteedosClient = (function () {
441
329
  },
442
330
  anonymousId: '00000000000000000000000000',
443
331
  };
444
- };
445
- return SteedosClient;
446
- }());
332
+ }
333
+ }
447
334
  exports.default = SteedosClient;
448
335
  function parseAndMergeNestedHeaders(originalHeaders) {
449
- var headers = new Map();
450
- var nestedHeaders = new Map();
451
- originalHeaders.forEach(function (val, key) {
452
- var capitalizedKey = key.replace(/\b[a-z]/g, function (l) { return l.toUpperCase(); });
453
- var realVal = val;
336
+ const headers = new Map();
337
+ let nestedHeaders = new Map();
338
+ originalHeaders.forEach((val, key) => {
339
+ const capitalizedKey = key.replace(/\b[a-z]/g, (l) => l.toUpperCase());
340
+ let realVal = val;
454
341
  if (val && val.match(/\n\S+:\s\S+/)) {
455
- var nestedHeaderStrings = val.split('\n');
342
+ const nestedHeaderStrings = val.split('\n');
456
343
  realVal = nestedHeaderStrings.shift();
457
- var moreNestedHeaders = new Map(nestedHeaderStrings.map(function (h) { return h.split(/:\s/); }));
458
- nestedHeaders = new Map(__spreadArray(__spreadArray([], __read(nestedHeaders), false), __read(moreNestedHeaders), false));
344
+ const moreNestedHeaders = new Map(nestedHeaderStrings.map((h) => h.split(/:\s/)));
345
+ nestedHeaders = new Map([...nestedHeaders, ...moreNestedHeaders]);
459
346
  }
460
347
  headers.set(capitalizedKey, realVal);
461
348
  });
462
- return new Map(__spreadArray(__spreadArray([], __read(headers), false), __read(nestedHeaders), false));
349
+ return new Map([...headers, ...nestedHeaders]);
463
350
  }
464
- var ClientError = (function (_super) {
465
- __extends(ClientError, _super);
466
- function ClientError(baseUrl, data) {
467
- var _this = _super.call(this, data.message + ': ' + (0, sentry_1.cleanUrlForLogging)(baseUrl, data.url || '')) || this;
468
- _this.message = data.message;
469
- _this.url = data.url;
470
- _this.intl = data.intl;
471
- _this.server_error_id = data.server_error_id;
472
- _this.status_code = data.status_code;
473
- Object.defineProperty(_this, 'message', { enumerable: true });
474
- return _this;
351
+ class ClientError extends Error {
352
+ constructor(baseUrl, data) {
353
+ super(data.message + ': ' + (0, sentry_1.cleanUrlForLogging)(baseUrl, data.url || ''));
354
+ this.message = data.message;
355
+ this.url = data.url;
356
+ this.intl = data.intl;
357
+ this.server_error_id = data.server_error_id;
358
+ this.status_code = data.status_code;
359
+ Object.defineProperty(this, 'message', { enumerable: true });
475
360
  }
476
- return ClientError;
477
- }(Error));
361
+ }
478
362
  exports.ClientError = ClientError;
479
363
  //# sourceMappingURL=client4.js.map