@eso-status/service-alerts 1.0.8 → 1.0.9

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.
@@ -4,109 +4,109 @@ import { RawEsoStatus } from '@eso-status/types';
4
4
  */
5
5
  export default class ServiceAlertConnector {
6
6
  /**
7
- * URL to get remote content
8
- *
9
- * @public
10
- * @static
11
- *
12
- * @return string URL to get remote content
13
- */
14
- static url: string;
7
+ * URL to get remote content
8
+ *
9
+ * @public
10
+ * @static
11
+ *
12
+ * @return string URL to get remote content
13
+ */
14
+ static readonly url = "https://help.elderscrollsonline.com/app/answers/detail/a_id/4320";
15
15
  /**
16
- * Methode used to get raw content of the remote website
17
- *
18
- * @public
19
- * @static
20
- *
21
- * @return Promise<string> Raw content of the remote website
22
- */
16
+ * Methode used to get raw content of the remote website
17
+ *
18
+ * @public
19
+ * @static
20
+ *
21
+ * @return Promise<string> Raw content of the remote website
22
+ */
23
23
  static getRemoteContent(): Promise<string>;
24
24
  /**
25
- * Methode used to select raw content containing eso servers status information
26
- *
27
- * @public
28
- * @static
29
- *
30
- * @param remoteContent Raw content of the remote website
31
- * @return string Raw content containing eso servers status information
32
- */
25
+ * Methode used to select raw content containing eso servers status information
26
+ *
27
+ * @public
28
+ * @static
29
+ *
30
+ * @param remoteContent Raw content of the remote website
31
+ * @return string Raw content containing eso servers status information
32
+ */
33
33
  static getFilterContent(remoteContent: string): string;
34
34
  /**
35
- * Methode used to get list of each raw information by date
36
- *
37
- * @public
38
- * @static
39
- *
40
- * @param filteredContent string Raw content containing eso servers status information
41
- * @return string[] List of each information by date
42
- */
35
+ * Methode used to get list of each raw information by date
36
+ *
37
+ * @public
38
+ * @static
39
+ *
40
+ * @param filteredContent string Raw content containing eso servers status information
41
+ * @return string[] List of each information by date
42
+ */
43
43
  static changeFilterContentForList(filteredContent: string): string[];
44
44
  /**
45
- * Methode used to get raw data of content list
46
- *
47
- * @public
48
- * @static
49
- *
50
- * @param filteredContentList string[] Raw data of content list
51
- * @return {raw: string, rawDate: string, rawData: string[]}[] Raw data of content list
52
- */
45
+ * Methode used to get raw data of content list
46
+ *
47
+ * @public
48
+ * @static
49
+ *
50
+ * @param filteredContentList string[] Raw data of content list
51
+ * @return {raw: string, rawDate: string, rawData: string[]}[] Raw data of content list
52
+ */
53
53
  static getRawData(filteredContentList: string[]): {
54
54
  raw: string;
55
55
  rawDate: string;
56
56
  rawData: string[];
57
57
  }[];
58
58
  /**
59
- * Methode used to get list of split raw data of content list
60
- *
61
- * @public
62
- * @static
63
- *
64
- * @param rawData {raw: string, rawDate: string, rawData: string[]}[] Raw data of content list
65
- * @return RawEsoStatus[] Split raw data of content list
66
- */
59
+ * Methode used to get list of split raw data of content list
60
+ *
61
+ * @public
62
+ * @static
63
+ *
64
+ * @param rawData {raw: string, rawDate: string, rawData: string[]}[] Raw data of content list
65
+ * @return RawEsoStatus[] Split raw data of content list
66
+ */
67
67
  static splitRawData(rawData: {
68
68
  raw: string;
69
69
  rawDate: string;
70
70
  rawData: string[];
71
71
  }[]): RawEsoStatus[];
72
72
  /**
73
- * Methode used to get slug of split raw data of content list
74
- *
75
- * @public
76
- * @static
77
- *
78
- * @param splitRawData RawEsoStatus[] Split raw data of content list
79
- * @return RawEsoStatus[] Split raw data of content list with slug
80
- */
73
+ * Methode used to get slug of split raw data of content list
74
+ *
75
+ * @public
76
+ * @static
77
+ *
78
+ * @param splitRawData RawEsoStatus[] Split raw data of content list
79
+ * @return RawEsoStatus[] Split raw data of content list with slug
80
+ */
81
81
  static getSlugOfSplitRawData(splitRawData: RawEsoStatus[]): RawEsoStatus[];
82
82
  /**
83
- * Methode used to get split raw data of content list by slug
84
- *
85
- * @public
86
- * @static
87
- *
88
- * @param splitRawDataWithSlug RawEsoStatus[] Split raw data of content list with slug
89
- * @return RawEsoStatus[] Split raw data of content list by slug
90
- */
83
+ * Methode used to get split raw data of content list by slug
84
+ *
85
+ * @public
86
+ * @static
87
+ *
88
+ * @param splitRawDataWithSlug RawEsoStatus[] Split raw data of content list with slug
89
+ * @return RawEsoStatus[] Split raw data of content list by slug
90
+ */
91
91
  static splitRawDataList(splitRawDataWithSlug: RawEsoStatus[]): RawEsoStatus[];
92
92
  /**
93
- * Methode used to get last element by slug
94
- *
95
- * @public
96
- * @static
97
- *
98
- * @param splitRawDataList RawEsoStatus[] Split raw data of content list by slug
99
- * @return RawEsoStatus[] Raw eso server status list sorted by date
100
- */
93
+ * Methode used to get last element by slug
94
+ *
95
+ * @public
96
+ * @static
97
+ *
98
+ * @param splitRawDataList RawEsoStatus[] Split raw data of content list by slug
99
+ * @return RawEsoStatus[] Raw eso server status list sorted by date
100
+ */
101
101
  static getLastRawData(splitRawDataList: RawEsoStatus[]): RawEsoStatus[];
102
102
  /**
103
- * Methode used to get last eso status server with data
104
- *
105
- * @public
106
- * @static
107
- *
108
- * @param lastRawData RawEsoStatus[] Raw eso server status list sorted by date
109
- * @return RawEsoStatus[] Last eso status server with data
110
- */
103
+ * Methode used to get last eso status server with data
104
+ *
105
+ * @public
106
+ * @static
107
+ *
108
+ * @param lastRawData RawEsoStatus[] Raw eso server status list sorted by date
109
+ * @return RawEsoStatus[] Last eso status server with data
110
+ */
111
111
  static getData(lastRawData: RawEsoStatus[]): RawEsoStatus[];
112
112
  }
@@ -1,155 +1,112 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- 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;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
4
  };
38
5
  Object.defineProperty(exports, "__esModule", { value: true });
39
- var ServiceAlertsElement_1 = require("../classes/ServiceAlertsElement");
40
- var axios = require('axios');
6
+ const axios_1 = __importDefault(require("axios"));
7
+ const ServiceAlertsElement_1 = __importDefault(require("../classes/ServiceAlertsElement"));
8
+ const serviceAlertsStartMarker = '<!-- ENTER ESO SERVICE ALERTS BELOW THIS LINE -->';
41
9
  /**
42
10
  * Connector used to get data from https://help.elderscrollsonline.com/app/answers/detail/a_id/4320
43
11
  */
44
- var ServiceAlertConnector = /** @class */ (function () {
45
- function ServiceAlertConnector() {
46
- }
12
+ // eslint-disable-next-line @typescript-eslint/no-extraneous-class -- the published 1.x API exposes static methods, called as is by @eso-status/api 1.x
13
+ class ServiceAlertConnector {
47
14
  /**
48
- * Methode used to get raw content of the remote website
49
- *
50
- * @public
51
- * @static
52
- *
53
- * @return Promise<string> Raw content of the remote website
54
- */
55
- ServiceAlertConnector.getRemoteContent = function () {
56
- return __awaiter(this, void 0, void 0, function () {
57
- var response;
58
- return __generator(this, function (_a) {
59
- switch (_a.label) {
60
- case 0: return [4 /*yield*/, axios.get(ServiceAlertConnector.url)];
61
- case 1:
62
- response = _a.sent();
63
- if ((response === null || response === void 0 ? void 0 : response.status) !== 200) {
64
- throw new Error("Bad response ".concat(response === null || response === void 0 ? void 0 : response.status, " (").concat(response === null || response === void 0 ? void 0 : response.data, ")"));
65
- }
66
- else if (!(response === null || response === void 0 ? void 0 : response.data)) {
67
- throw new Error("Empty response ".concat(response === null || response === void 0 ? void 0 : response.status, " (").concat(response === null || response === void 0 ? void 0 : response.data, ")"));
68
- }
69
- else {
70
- return [2 /*return*/, response === null || response === void 0 ? void 0 : response.data];
71
- }
72
- return [2 /*return*/];
73
- }
74
- });
75
- });
76
- };
15
+ * Methode used to get raw content of the remote website
16
+ *
17
+ * @public
18
+ * @static
19
+ *
20
+ * @return Promise<string> Raw content of the remote website
21
+ */
22
+ static async getRemoteContent() {
23
+ const response = await axios_1.default.get(ServiceAlertConnector.url);
24
+ if (response.status !== 200) {
25
+ throw new Error(`Bad response ${String(response.status)} (${response.data})`);
26
+ }
27
+ else if (!response.data) {
28
+ throw new Error(`Empty response ${String(response.status)} (${response.data})`);
29
+ }
30
+ else {
31
+ return response.data;
32
+ }
33
+ }
77
34
  /**
78
- * Methode used to select raw content containing eso servers status information
79
- *
80
- * @public
81
- * @static
82
- *
83
- * @param remoteContent Raw content of the remote website
84
- * @return string Raw content containing eso servers status information
85
- */
86
- ServiceAlertConnector.getFilterContent = function (remoteContent) {
87
- var resultRemoveBefore = remoteContent.split('<div><!-- ENTER ESO SERVICE ALERTS BELOW THIS LINE -->');
35
+ * Methode used to select raw content containing eso servers status information
36
+ *
37
+ * @public
38
+ * @static
39
+ *
40
+ * @param remoteContent Raw content of the remote website
41
+ * @return string Raw content containing eso servers status information
42
+ */
43
+ static getFilterContent(remoteContent) {
44
+ const resultRemoveBefore = remoteContent.split(serviceAlertsStartMarker);
88
45
  if (resultRemoveBefore.length >= 2) {
89
- var resultRemoveAfter = resultRemoveBefore[1].split('<p>&nbsp;</p>');
46
+ const resultRemoveAfter = resultRemoveBefore[1].split('<p>&nbsp;</p>');
90
47
  if (resultRemoveAfter.length >= 2) {
91
- return "<div><!-- ENTER ESO SERVICE ALERTS BELOW THIS LINE -->".concat(resultRemoveAfter[0], "<p>&nbsp;</p>");
48
+ return `${serviceAlertsStartMarker}${resultRemoveAfter[0]}<p>&nbsp;</p>`;
92
49
  }
93
50
  }
94
51
  return '';
95
- };
52
+ }
96
53
  /**
97
- * Methode used to get list of each raw information by date
98
- *
99
- * @public
100
- * @static
101
- *
102
- * @param filteredContent string Raw content containing eso servers status information
103
- * @return string[] List of each information by date
104
- */
105
- ServiceAlertConnector.changeFilterContentForList = function (filteredContent) {
54
+ * Methode used to get list of each raw information by date
55
+ *
56
+ * @public
57
+ * @static
58
+ *
59
+ * @param filteredContent string Raw content containing eso servers status information
60
+ * @return string[] List of each information by date
61
+ */
62
+ static changeFilterContentForList(filteredContent) {
106
63
  return filteredContent
107
64
  .split('<hr')
108
- .filter(function (item) { return !item.includes('&nbsp;'); });
109
- };
65
+ .filter((item) => !item.includes('&nbsp;'));
66
+ }
110
67
  /**
111
- * Methode used to get raw data of content list
112
- *
113
- * @public
114
- * @static
115
- *
116
- * @param filteredContentList string[] Raw data of content list
117
- * @return {raw: string, rawDate: string, rawData: string[]}[] Raw data of content list
118
- */
119
- ServiceAlertConnector.getRawData = function (filteredContentList) {
120
- return filteredContentList.map(function (item) {
121
- var list = item
68
+ * Methode used to get raw data of content list
69
+ *
70
+ * @public
71
+ * @static
72
+ *
73
+ * @param filteredContentList string[] Raw data of content list
74
+ * @return {raw: string, rawDate: string, rawData: string[]}[] Raw data of content list
75
+ */
76
+ static getRawData(filteredContentList) {
77
+ return filteredContentList.map((item) => {
78
+ const list = item
122
79
  .split('</p>')
123
- .map(function (line) {
124
- var newLine = line;
125
- newLine = newLine.replace('\n', '')
126
- .replace('\n', '')
80
+ .map((line) => {
81
+ let newLine = line;
82
+ newLine = newLine
83
+ .replace(/\n/g, '')
127
84
  .replace('</p>', '')
128
- .replace('<div><!-- ENTER ESO SERVICE ALERTS BELOW THIS LINE -->', '')
85
+ .replace(serviceAlertsStartMarker, '')
129
86
  .replace('<p>', '');
130
87
  return newLine;
131
88
  })
132
- .filter(function (line) { return line.length > 2; });
89
+ .filter((line) => line.length > 2);
133
90
  return {
134
91
  raw: item,
135
92
  rawDate: list[0],
136
93
  rawData: list.slice(1, list.length),
137
94
  };
138
95
  });
139
- };
96
+ }
140
97
  /**
141
- * Methode used to get list of split raw data of content list
142
- *
143
- * @public
144
- * @static
145
- *
146
- * @param rawData {raw: string, rawDate: string, rawData: string[]}[] Raw data of content list
147
- * @return RawEsoStatus[] Split raw data of content list
148
- */
149
- ServiceAlertConnector.splitRawData = function (rawData) {
150
- var list = [];
151
- rawData.forEach(function (item) {
152
- item.rawData.forEach(function (line) {
98
+ * Methode used to get list of split raw data of content list
99
+ *
100
+ * @public
101
+ * @static
102
+ *
103
+ * @param rawData {raw: string, rawDate: string, rawData: string[]}[] Raw data of content list
104
+ * @return RawEsoStatus[] Split raw data of content list
105
+ */
106
+ static splitRawData(rawData) {
107
+ const list = [];
108
+ rawData.forEach((item) => {
109
+ item.rawData.forEach((line) => {
153
110
  list.push({
154
111
  sources: [ServiceAlertConnector.url],
155
112
  raw: [item.raw],
@@ -159,42 +116,38 @@ var ServiceAlertConnector = /** @class */ (function () {
159
116
  });
160
117
  });
161
118
  return list;
162
- };
119
+ }
163
120
  /**
164
- * Methode used to get slug of split raw data of content list
165
- *
166
- * @public
167
- * @static
168
- *
169
- * @param splitRawData RawEsoStatus[] Split raw data of content list
170
- * @return RawEsoStatus[] Split raw data of content list with slug
171
- */
172
- ServiceAlertConnector.getSlugOfSplitRawData = function (splitRawData) {
173
- return splitRawData.map(function (item) {
174
- var _a;
175
- return ({
176
- sources: item.sources,
177
- raw: item.raw,
178
- rawDate: item.rawDate,
179
- rawData: item.rawData,
180
- slugs: ServiceAlertsElement_1.default.getSlug((_a = item.rawData) !== null && _a !== void 0 ? _a : ''),
181
- });
182
- });
183
- };
121
+ * Methode used to get slug of split raw data of content list
122
+ *
123
+ * @public
124
+ * @static
125
+ *
126
+ * @param splitRawData RawEsoStatus[] Split raw data of content list
127
+ * @return RawEsoStatus[] Split raw data of content list with slug
128
+ */
129
+ static getSlugOfSplitRawData(splitRawData) {
130
+ return splitRawData.map((item) => ({
131
+ sources: item.sources,
132
+ raw: item.raw,
133
+ rawDate: item.rawDate,
134
+ rawData: item.rawData,
135
+ slugs: ServiceAlertsElement_1.default.getSlug(item.rawData ?? ''),
136
+ }));
137
+ }
184
138
  /**
185
- * Methode used to get split raw data of content list by slug
186
- *
187
- * @public
188
- * @static
189
- *
190
- * @param splitRawDataWithSlug RawEsoStatus[] Split raw data of content list with slug
191
- * @return RawEsoStatus[] Split raw data of content list by slug
192
- */
193
- ServiceAlertConnector.splitRawDataList = function (splitRawDataWithSlug) {
194
- var list = [];
195
- splitRawDataWithSlug.forEach(function (item) {
196
- var _a;
197
- (_a = item.slugs) === null || _a === void 0 ? void 0 : _a.forEach(function (slug) {
139
+ * Methode used to get split raw data of content list by slug
140
+ *
141
+ * @public
142
+ * @static
143
+ *
144
+ * @param splitRawDataWithSlug RawEsoStatus[] Split raw data of content list with slug
145
+ * @return RawEsoStatus[] Split raw data of content list by slug
146
+ */
147
+ static splitRawDataList(splitRawDataWithSlug) {
148
+ const list = [];
149
+ splitRawDataWithSlug.forEach((item) => {
150
+ item.slugs?.forEach((slug) => {
198
151
  list.push({
199
152
  sources: item.sources,
200
153
  raw: item.raw,
@@ -205,59 +158,57 @@ var ServiceAlertConnector = /** @class */ (function () {
205
158
  });
206
159
  });
207
160
  return list;
208
- };
161
+ }
209
162
  /**
210
- * Methode used to get last element by slug
211
- *
212
- * @public
213
- * @static
214
- *
215
- * @param splitRawDataList RawEsoStatus[] Split raw data of content list by slug
216
- * @return RawEsoStatus[] Raw eso server status list sorted by date
217
- */
218
- ServiceAlertConnector.getLastRawData = function (splitRawDataList) {
219
- var last = [];
220
- var list = [];
221
- splitRawDataList.forEach(function (item) {
222
- if (item && item.slugs && !last.includes(item.slugs[0])) {
163
+ * Methode used to get last element by slug
164
+ *
165
+ * @public
166
+ * @static
167
+ *
168
+ * @param splitRawDataList RawEsoStatus[] Split raw data of content list by slug
169
+ * @return RawEsoStatus[] Raw eso server status list sorted by date
170
+ */
171
+ static getLastRawData(splitRawDataList) {
172
+ const last = [];
173
+ const list = [];
174
+ splitRawDataList.forEach((item) => {
175
+ if (item.slugs && !last.includes(item.slugs[0])) {
223
176
  last.push(item.slugs[0]);
224
177
  list.push(item);
225
178
  }
226
179
  });
227
180
  return list;
228
- };
181
+ }
229
182
  /**
230
- * Methode used to get last eso status server with data
231
- *
232
- * @public
233
- * @static
234
- *
235
- * @param lastRawData RawEsoStatus[] Raw eso server status list sorted by date
236
- * @return RawEsoStatus[] Last eso status server with data
237
- */
238
- ServiceAlertConnector.getData = function (lastRawData) {
239
- return lastRawData.map(function (item) {
240
- var _a, _b;
241
- var newItem = item;
183
+ * Methode used to get last eso status server with data
184
+ *
185
+ * @public
186
+ * @static
187
+ *
188
+ * @param lastRawData RawEsoStatus[] Raw eso server status list sorted by date
189
+ * @return RawEsoStatus[] Last eso status server with data
190
+ */
191
+ static getData(lastRawData) {
192
+ return lastRawData.map((item) => {
193
+ const newItem = item;
242
194
  if (newItem.slugs) {
243
- newItem.dates = [ServiceAlertsElement_1.default.getDate((_a = newItem.rawDate) !== null && _a !== void 0 ? _a : '')];
195
+ newItem.dates = [ServiceAlertsElement_1.default.getDate(newItem.rawDate ?? '')];
244
196
  newItem.type = ServiceAlertsElement_1.default.getType(newItem.slugs[0]);
245
197
  newItem.support = ServiceAlertsElement_1.default.getSupport(newItem.slugs[0]);
246
198
  newItem.zone = ServiceAlertsElement_1.default.getZone(newItem.slugs[0]);
247
- newItem.status = ServiceAlertsElement_1.default.getStatus((_b = newItem.rawData) !== null && _b !== void 0 ? _b : '');
199
+ newItem.status = ServiceAlertsElement_1.default.getStatus(newItem.rawData ?? '');
248
200
  }
249
201
  return newItem;
250
202
  });
251
- };
252
- /**
253
- * URL to get remote content
254
- *
255
- * @public
256
- * @static
257
- *
258
- * @return string URL to get remote content
259
- */
260
- ServiceAlertConnector.url = 'https://help.elderscrollsonline.com/app/answers/detail/a_id/4320';
261
- return ServiceAlertConnector;
262
- }());
203
+ }
204
+ }
205
+ /**
206
+ * URL to get remote content
207
+ *
208
+ * @public
209
+ * @static
210
+ *
211
+ * @return string URL to get remote content
212
+ */
213
+ ServiceAlertConnector.url = 'https://help.elderscrollsonline.com/app/answers/detail/a_id/4320';
263
214
  exports.default = ServiceAlertConnector;
package/lib/index.d.ts CHANGED
@@ -4,12 +4,12 @@ import { RawEsoStatus } from '@eso-status/types';
4
4
  */
5
5
  export declare class ServiceAlerts {
6
6
  /**
7
- * Methode used to get Service Alerts data
8
- *
9
- * @public
10
- * @static
11
- *
12
- * @return Promise<RawEsoStatus[]> Service Alerts elements
13
- */
7
+ * Methode used to get Service Alerts data
8
+ *
9
+ * @public
10
+ * @static
11
+ *
12
+ * @return Promise<RawEsoStatus[]> Service Alerts elements
13
+ */
14
14
  static getData(): Promise<RawEsoStatus[]>;
15
15
  }