@idm-plugin/vessel 1.0.3 → 1.0.5

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.
@@ -43,5 +43,16 @@ export declare class AlertHelper {
43
43
  severe: number;
44
44
  heavy: number;
45
45
  step: number;
46
+ wind: {
47
+ dgThd4Wd: number;
48
+ svThd4Wd: number;
49
+ hvThd4Wd: number;
50
+ };
51
+ sig: {
52
+ dgThd4Wv: number;
53
+ svThd4Wv: number;
54
+ hvThd4Wv: number;
55
+ };
46
56
  };
47
57
  }
58
+ export declare const alertHelper: AlertHelper;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  var C = Object.defineProperty;
2
- var O = (j, c, s) => c in j ? C(j, c, { enumerable: !0, configurable: !0, writable: !0, value: s }) : j[c] = s;
3
- var q = (j, c, s) => (O(j, typeof c != "symbol" ? c + "" : c, s), s);
2
+ var O = (j, c, e) => c in j ? C(j, c, { enumerable: !0, configurable: !0, writable: !0, value: e }) : j[c] = e;
3
+ var q = (j, c, e) => (O(j, typeof c != "symbol" ? c + "" : c, e), e);
4
4
  import Y from "got";
5
5
  import * as W from "log4js";
6
6
  import p from "moment";
@@ -11,58 +11,58 @@ class V {
11
11
  * @param status
12
12
  */
13
13
  parseStatus(c) {
14
- let s, a;
14
+ let e, n;
15
15
  switch (c) {
16
16
  case 0:
17
- s = "在航(主机推动)", a = "The engine is in use";
17
+ e = "在航(主机推动)", n = "The engine is in use";
18
18
  break;
19
19
  case 1:
20
- s = "锚泊", a = "Anchored";
20
+ e = "锚泊", n = "Anchored";
21
21
  break;
22
22
  case 2:
23
- s = "失控", a = "Not operated";
23
+ e = "失控", n = "Not operated";
24
24
  break;
25
25
  case 3:
26
- s = "操纵受限", a = "Limited airworthiness";
26
+ e = "操纵受限", n = "Limited airworthiness";
27
27
  break;
28
28
  case 4:
29
- s = "吃水受限", a = "Limited by ship's draft";
29
+ e = "吃水受限", n = "Limited by ship's draft";
30
30
  break;
31
31
  case 5:
32
- s = "靠泊", a = "Mooring";
32
+ e = "靠泊", n = "Mooring";
33
33
  break;
34
34
  case 6:
35
- s = "搁浅", a = "Stranded";
35
+ e = "搁浅", n = "Stranded";
36
36
  break;
37
37
  case 7:
38
- s = "捕捞作业", a = "Engaged in fishing";
38
+ e = "捕捞作业", n = "Engaged in fishing";
39
39
  break;
40
40
  case 8:
41
- s = "靠帆船提供动力", a = "Sailing";
41
+ e = "靠帆船提供动力", n = "Sailing";
42
42
  break;
43
43
  default:
44
- s = "未定义", a = "Undefined";
44
+ e = "未定义", n = "Undefined";
45
45
  }
46
- return { labelCn: s, labelEn: a };
46
+ return { labelCn: e, labelEn: n };
47
47
  }
48
48
  }
49
- class G extends V {
50
- constructor(s, a) {
49
+ class B extends V {
50
+ constructor(e, n) {
51
51
  super();
52
52
  q(this, "clientId");
53
53
  q(this, "clientSecret");
54
54
  q(this, "token");
55
- this.clientId = s, this.clientSecret = a;
55
+ this.clientId = e, this.clientSecret = n;
56
56
  }
57
- async authToken(s = {}) {
58
- const a = "https://svc.data.myvessel.cn/ada/oauth/token", n = {
57
+ async authToken(e = {}) {
58
+ const n = "https://svc.data.myvessel.cn/ada/oauth/token", a = {
59
59
  searchParams: {
60
60
  client_id: this.clientId,
61
61
  client_secret: this.clientSecret,
62
62
  grant_type: "client_credentials"
63
63
  }
64
- }, o = await Y.post(a, n).json();
65
- M.info("[%s] fetch access token from: %s - %j", s.requestId, a, o), o.error || (this.token = {
64
+ }, o = await Y.post(n, a).json();
65
+ M.info("[%s] fetch access token from: %s - %j", e.requestId, n, o), o.error || (this.token = {
66
66
  accessToken: o.access_token,
67
67
  tokenType: o.token_type,
68
68
  expiresIn: o.expires_in,
@@ -71,20 +71,20 @@ class G extends V {
71
71
  issuedAt: p().utc().format()
72
72
  });
73
73
  }
74
- async realTimePosition(s, a = {}) {
74
+ async realTimePosition(e, n = {}) {
75
75
  var d, h, f;
76
- (!this.token || p().diff(p(this.token.issuedAt), "seconds") > ((d = this.token) == null ? void 0 : d.expiresIn) - 300) && await this.authToken(a);
77
- const n = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit", o = {
76
+ (!this.token || p().diff(p(this.token.issuedAt), "seconds") > ((d = this.token) == null ? void 0 : d.expiresIn) - 300) && await this.authToken(n);
77
+ const a = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit", o = {
78
78
  headers: {
79
79
  Authorization: `${(h = this.token) == null ? void 0 : h.tokenType} ${(f = this.token) == null ? void 0 : f.accessToken}`
80
80
  },
81
- searchParams: { mmsi: s }
81
+ searchParams: { mmsi: e }
82
82
  };
83
- M.info("[%s] fetch realtime position from: %s - %j", a.requestId, n, o);
84
- const e = await Y.get(n, o).json();
85
- if (e.code)
86
- return M.warn("[%s] fetch realtime position failed: %j", a.requestId, n, { message: e.message, status: e.status, code: e.code }), e;
87
- const t = e.data;
83
+ M.info("[%s] fetch realtime position from: %s - %j", n.requestId, a, o);
84
+ const s = await Y.get(a, o).json();
85
+ if (s.code)
86
+ return M.warn("[%s] fetch realtime position failed: %j", n.requestId, a, { message: s.message, status: s.status, code: s.code }), s;
87
+ const t = s.data;
88
88
  for (const m in t)
89
89
  !isNaN(t[m]) && Number(t[m]) !== 1 / 0 && (t[m] = Number(t[m]));
90
90
  const r = p(`${t.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
@@ -113,23 +113,23 @@ class G extends V {
113
113
  utc: r.utc().format()
114
114
  };
115
115
  }
116
- async trajectory(s, a, n, o, e = !0, t = {}) {
116
+ async trajectory(e, n, a, o, s = !0, t = {}) {
117
117
  (!this.token || p().diff(p(this.token.issuedAt), "seconds") > this.token.expiresIn - 300) && await this.authToken(t);
118
- const r = await this.realTimePosition(s, t), i = p(a), d = p(n), h = [];
118
+ const r = await this.realTimePosition(e, t), i = p(n), d = p(a), h = [];
119
119
  for (; d.diff(i, "day", !0) > 30; )
120
- await this.trajectoryIn30Day(s, i, i.clone().add(30, "day"), r, o, h, t), i.add(30, "day");
121
- return await this.trajectoryIn30Day(s, i, d, r, o, h, t), h;
120
+ await this.trajectoryIn30Day(e, i, i.clone().add(30, "day"), r, o, h, t), i.add(30, "day");
121
+ return await this.trajectoryIn30Day(e, i, d, r, o, h, t), h;
122
122
  }
123
- async trajectoryIn30Day(s, a, n, o, e, t, r = {}) {
123
+ async trajectoryIn30Day(e, n, a, o, s, t, r = {}) {
124
124
  var u, b, w, k, v;
125
125
  const i = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/track", d = {
126
126
  headers: {
127
127
  Authorization: `${(u = this.token) == null ? void 0 : u.tokenType} ${(b = this.token) == null ? void 0 : b.accessToken}`
128
128
  },
129
129
  json: {
130
- mmsi: s,
131
- startTime: a.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),
132
- endTime: n.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")
130
+ mmsi: e,
131
+ startTime: n.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),
132
+ endTime: a.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")
133
133
  }
134
134
  };
135
135
  M.info("[%s] fetch trajectory from: %s - %j", r.requestId, i, d);
@@ -159,28 +159,28 @@ class G extends V {
159
159
  method: "trajectory",
160
160
  vendor: "myVessel",
161
161
  utc: I.utc().format()
162
- }, E = Math.floor(I.diff(m, "minute", !0) / (e || 1));
162
+ }, E = Math.floor(I.diff(m, "minute", !0) / (s || 1));
163
163
  E !== f && (f = E, t.push(R));
164
164
  }), t;
165
165
  }
166
166
  }
167
- class B extends V {
168
- constructor(s) {
167
+ class U extends V {
168
+ constructor(e) {
169
169
  super();
170
170
  q(this, "token");
171
- this.token = s;
171
+ this.token = e;
172
172
  }
173
- async realTimePosition(s, a = {}) {
174
- const n = "https://api.hifleet.com/position/position/get/token", o = {
173
+ async realTimePosition(e, n = {}) {
174
+ const a = "https://api.hifleet.com/position/position/get/token", o = {
175
175
  searchParams: {
176
- mmsi: s,
176
+ mmsi: e,
177
177
  usertoken: this.token
178
178
  }
179
- }, e = await Y.post(n, o).json();
180
- M.info("[%s] fetch realtime position from: %s - %j", a.requestId, n, o);
181
- const t = e == null ? void 0 : e.list;
179
+ }, s = await Y.post(a, o).json();
180
+ M.info("[%s] fetch realtime position from: %s - %j", n.requestId, a, o);
181
+ const t = s == null ? void 0 : s.list;
182
182
  if (!t)
183
- return M.warn("[%s] fetch realtime position failed: %j", a.requestId, n, e), e;
183
+ return M.warn("[%s] fetch realtime position failed: %j", n.requestId, a, s), s;
184
184
  for (const m in t)
185
185
  !isNaN(t[m]) && Number(t[m]) !== 1 / 0 && (t[m] = Number(t[m]));
186
186
  t.status = t.sp > 3 ? 0 : 1;
@@ -210,11 +210,11 @@ class B extends V {
210
210
  vendor: "hifleet"
211
211
  };
212
212
  }
213
- async search(s, a = {}) {
214
- let n = "https://www.hifleet.com/hifleetapi/searchVesselOL.do";
213
+ async search(e, n = {}) {
214
+ let a = "https://www.hifleet.com/hifleetapi/searchVesselOL.do";
215
215
  const o = {
216
216
  searchParams: {
217
- keyword: s
217
+ keyword: e
218
218
  },
219
219
  headers: {
220
220
  Referer: "https://www.hifleet.com",
@@ -222,27 +222,27 @@ class B extends V {
222
222
  Host: "www.hifleet.com"
223
223
  }
224
224
  };
225
- let e = await Y.post(n, o).json();
226
- M.info("[%s] fetch vessel props from: %s - %j", a.requestId, n, o), e instanceof Array && (e = e[0]);
227
- for (const r in e)
228
- !isNaN(e[r]) && Number(e[r]) !== 1 / 0 && (e[r] = Number(e[r]));
225
+ let s = await Y.post(a, o).json();
226
+ M.info("[%s] fetch vessel props from: %s - %j", n.requestId, a, o), s instanceof Array && (s = s[0]);
227
+ for (const r in s)
228
+ !isNaN(s[r]) && Number(s[r]) !== 1 / 0 && (s[r] = Number(s[r]));
229
229
  const t = {
230
- mmsi: e.m,
231
- name: e.n,
232
- imo: e.i,
233
- callSign: e.c,
234
- length: e.l,
235
- breadth: e.b,
236
- draught: e.dr
230
+ mmsi: s.m,
231
+ name: s.n,
232
+ imo: s.i,
233
+ callSign: s.c,
234
+ length: s.l,
235
+ breadth: s.b,
236
+ draught: s.dr
237
237
  };
238
- return n = "https://www.hifleet.com/hifleetapi/sameShipSearch.do", e = await Y.post(n, o).json(), M.info("[%s] fetch vessel dead weight from: %s - %j", a.requestId, n, o), e instanceof Array && (e = e[0]), e && (t.deadweight = Number(e.dwt)), t;
238
+ return a = "https://www.hifleet.com/hifleetapi/sameShipSearch.do", s = await Y.post(a, o).json(), M.info("[%s] fetch vessel dead weight from: %s - %j", n.requestId, a, o), s instanceof Array && (s = s[0]), s && (t.deadweight = Number(s.dwt)), t;
239
239
  }
240
- async trajectory(s, a, n, o, e = !0, t = {}) {
240
+ async trajectory(e, n, a, o, s = !0, t = {}) {
241
241
  var g, I, S;
242
- const r = await this.realTimePosition(s, t);
243
- let i = p(a);
244
- const d = p(n), h = p();
245
- if (e) {
242
+ const r = await this.realTimePosition(e, t);
243
+ let i = p(n);
244
+ const d = p(a), h = p();
245
+ if (s) {
246
246
  let l = d.diff(i, "d", !0);
247
247
  l < 0 ? i = d.clone().subtract(40, "d") : l < 30 ? i.subtract(10, "d") : l < 60 ? i.subtract(5, "d") : i = d.clone().subtract(80, "d"), l = h.diff(d, "d", !0), d.add(l > 10 ? 240 : l * 24, "h");
248
248
  }
@@ -250,7 +250,7 @@ class B extends V {
250
250
  searchParams: {
251
251
  endtime: d.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
252
252
  starttime: i.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
253
- mmsi: s,
253
+ mmsi: e,
254
254
  usertoken: this.token
255
255
  }
256
256
  }, m = "https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token", u = await Y.get(m, f).json();
@@ -288,23 +288,23 @@ class B extends V {
288
288
  return w;
289
289
  }
290
290
  }
291
- class U extends V {
292
- constructor(s) {
291
+ class J extends V {
292
+ constructor(e) {
293
293
  super();
294
294
  q(this, "token");
295
- this.token = s;
295
+ this.token = e;
296
296
  }
297
- async realTimePosition(s, a = {}) {
298
- const n = {
297
+ async realTimePosition(e, n = {}) {
298
+ const a = {
299
299
  searchParams: {
300
- id: s,
300
+ id: e,
301
301
  k: this.token,
302
302
  enc: 1
303
303
  }
304
- }, o = "https://api.shipxy.com/apicall/GetSingleShip", e = await Y.get(o, n).json();
305
- if (M.info("[%s] fetch realtime position from: %s - %j", a.requestId, o, n), (e == null ? void 0 : e.status) !== 0)
306
- return e;
307
- const t = e.data[0];
304
+ }, o = "https://api.shipxy.com/apicall/GetSingleShip", s = await Y.get(o, a).json();
305
+ if (M.info("[%s] fetch realtime position from: %s - %j", n.requestId, o, a), (s == null ? void 0 : s.status) !== 0)
306
+ return s;
307
+ const t = s.data[0];
308
308
  for (const f in t)
309
309
  !isNaN(t[f]) && Number(t[f]) !== 1 / 0 && (t[f] = Number(t[f]));
310
310
  const { labelCn: r, labelEn: i } = await this.parseStatus(t.navistat), d = p.unix(t.lasttime);
@@ -331,11 +331,11 @@ class U extends V {
331
331
  vendor: "shipxy"
332
332
  };
333
333
  }
334
- async trajectory(s, a, n, o, e = !0, t = {}) {
334
+ async trajectory(e, n, a, o, s = !0, t = {}) {
335
335
  var v;
336
- const r = await this.realTimePosition(s, t), i = p(a), d = p(n), h = "https://api.shipxy.com/apicall/GetShipTrack", f = {
336
+ const r = await this.realTimePosition(e, t), i = p(n), d = p(a), h = "https://api.shipxy.com/apicall/GetShipTrack", f = {
337
337
  searchParams: {
338
- id: s,
338
+ id: e,
339
339
  k: this.token,
340
340
  enc: 1,
341
341
  cut: 0,
@@ -350,7 +350,7 @@ class U extends V {
350
350
  for (const g of u) {
351
351
  const I = p.unix(g.utc), S = {
352
352
  imo: r == null ? void 0 : r.imo,
353
- mmsi: s,
353
+ mmsi: e,
354
354
  sog: Math.round(g.sog * 3600 / 1e3 / 1852 * 100) / 100,
355
355
  cog: Math.round(g.cog / 100 * 100) / 100,
356
356
  lat: Math.round(g.lat / 1e6 * 1e5) / 1e5,
@@ -365,37 +365,37 @@ class U extends V {
365
365
  return b;
366
366
  }
367
367
  }
368
- class J extends V {
369
- constructor(s) {
368
+ class Q extends V {
369
+ constructor(e) {
370
370
  super();
371
371
  q(this, "token");
372
- this.token = s;
372
+ this.token = e;
373
373
  }
374
- async getShipId(s, a = {}) {
375
- const n = {
374
+ async getShipId(e, n = {}) {
375
+ const a = {
376
376
  headers: {
377
377
  appKey: this.token
378
378
  },
379
379
  json: {
380
- mmsiList: s
380
+ mmsiList: e
381
381
  }
382
- }, o = "https://api3.myships.com/sp/ships/getShipIdByMMSI", e = await Y.post(o, n).json();
383
- return M.info("[%s] fetch ship id from: %s - %j", a.requestId, o, n), e.code !== "0" ? e : e.data[0].shipId;
382
+ }, o = "https://api3.myships.com/sp/ships/getShipIdByMMSI", s = await Y.post(o, a).json();
383
+ return M.info("[%s] fetch ship id from: %s - %j", n.requestId, o, a), s.code !== "0" ? s : s.data[0].shipId;
384
384
  }
385
- async getShipInfo(s, a = {}) {
386
- const n = {
385
+ async getShipInfo(e, n = {}) {
386
+ const a = {
387
387
  headers: {
388
388
  appKey: this.token
389
389
  },
390
390
  json: {
391
- shipId: s
391
+ shipId: e
392
392
  }
393
- }, o = "https://api3.myships.com/sp/ships/aissta", e = await Y.post(o, n).json();
394
- if (M.info("[%s] fetch ship info from: %s - %j", a.requestId, o, n), e.code !== "0")
395
- return e;
396
- const t = e.data;
393
+ }, o = "https://api3.myships.com/sp/ships/aissta", s = await Y.post(o, a).json();
394
+ if (M.info("[%s] fetch ship info from: %s - %j", n.requestId, o, a), s.code !== "0")
395
+ return s;
396
+ const t = s.data;
397
397
  let r = t.imo;
398
- return s === "407170" && (r = "9198379", M.warn("[%s] ship(%s) imo error: %s, should be %s", a.requestId, s, t.imo, r)), {
398
+ return e === "407170" && (r = "9198379", M.warn("[%s] ship(%s) imo error: %s, should be %s", n.requestId, e, t.imo, r)), {
399
399
  mmsi: t.mmsi,
400
400
  name: t.shipnameEn,
401
401
  imo: r,
@@ -405,23 +405,23 @@ class J extends V {
405
405
  draught: (t.draught || 100) / 10
406
406
  };
407
407
  }
408
- async realTimePosition(s, a = {}) {
409
- const n = await this.getShipId(s, a), o = await this.getShipInfo(n, a), e = {
408
+ async realTimePosition(e, n = {}) {
409
+ const a = await this.getShipId(e, n), o = await this.getShipInfo(a, n), s = {
410
410
  headers: {
411
411
  appKey: this.token
412
412
  },
413
413
  json: {
414
- shipId: n
414
+ shipId: a
415
415
  }
416
- }, t = "https://api3.myships.com/sp/ships/position/latest", r = await Y.post(t, e).json();
417
- M.info("[%s] fetch realtime position from: %s - %j", a.requestId, t, e);
416
+ }, t = "https://api3.myships.com/sp/ships/position/latest", r = await Y.post(t, s).json();
417
+ M.info("[%s] fetch realtime position from: %s - %j", n.requestId, t, s);
418
418
  const i = r.data[0];
419
419
  for (const u in i)
420
420
  !isNaN(i[u]) && Number(i[u]) !== 1 / 0 && (i[u] = Number(i[u]));
421
421
  const { labelCn: d, labelEn: h } = await this.parseStatus(i.aisNavStatus), f = p.unix(i.posTime);
422
422
  return {
423
423
  ...o,
424
- mmsi: s,
424
+ mmsi: e,
425
425
  lat: Math.round(i.lat / 1e4 / 60 * 1e5) / 1e5,
426
426
  lng: Math.round(i.lon / 1e4 / 60 * 1e5) / 1e5,
427
427
  sog: Math.round(i.sog / 10 * 100) / 100,
@@ -437,22 +437,22 @@ class J extends V {
437
437
  vendor: "myship"
438
438
  };
439
439
  }
440
- async trajectory(s, a, n, o, e = !0, t = {}) {
441
- const r = p(a), i = p(n), d = await this.getShipId(s), h = await this.getShipInfo(d), f = [];
440
+ async trajectory(e, n, a, o, s = !0, t = {}) {
441
+ const r = p(n), i = p(a), d = await this.getShipId(e), h = await this.getShipInfo(d), f = [];
442
442
  for (; i.diff(r, "day", !0) > 30; )
443
- await this.trajectoryIn30Day(d, r.unix(), r.add(30, "day").unix(), h, s, o, f);
444
- return await this.trajectoryIn30Day(d, r.unix(), i.unix(), h, s, o, f), f;
443
+ await this.trajectoryIn30Day(d, r.unix(), r.add(30, "day").unix(), h, e, o, f);
444
+ return await this.trajectoryIn30Day(d, r.unix(), i.unix(), h, e, o, f), f;
445
445
  }
446
- async trajectoryIn30Day(s, a, n, o, e, t, r, i = {}) {
446
+ async trajectoryIn30Day(e, n, a, o, s, t, r, i = {}) {
447
447
  var w;
448
448
  const d = {
449
449
  headers: {
450
450
  appKey: this.token
451
451
  },
452
452
  json: {
453
- shipId: s,
454
- startTime: a,
455
- endTime: n
453
+ shipId: e,
454
+ startTime: n,
455
+ endTime: a
456
456
  }
457
457
  }, h = "https://api3.myships.com/sp/ships/position/history", f = await Y.post(h, d).json();
458
458
  if (M.info("[%s] fetch trajectory from: %s - %j", i.requestId, h, d), f.code !== "0")
@@ -465,7 +465,7 @@ class J extends V {
465
465
  for (const k of m) {
466
466
  const v = p.unix(k.posTime), g = {
467
467
  imo: o == null ? void 0 : o.imo,
468
- mmsi: e,
468
+ mmsi: s,
469
469
  lat: Math.round(k.lat / 1e4 / 60 * 1e5) / 1e5,
470
470
  lng: Math.round(k.lon / 1e4 / 60 * 1e5) / 1e5,
471
471
  sog: Math.round(k.sog / 10 * 100) / 100,
@@ -484,7 +484,7 @@ class J extends V {
484
484
  }
485
485
  const $ = W.getLogger();
486
486
  var K = /* @__PURE__ */ ((j) => (j.NOTICE = "NOTICE", j.WARN = "WARN", j.HEAVY = "HEAVY", j.SEVERE = "SEVERE", j.ERROR = "ERROR", j.FATAL = "FATAL", j))(K || {});
487
- class Q {
487
+ class L {
488
488
  /**
489
489
  * 解析告警规则, 多规则场景
490
490
  * @param rule
@@ -493,24 +493,24 @@ class Q {
493
493
  *
494
494
  * @param options
495
495
  */
496
- parsePrinciple(c, s = {}) {
496
+ parsePrinciple(c, e = {}) {
497
497
  var t, r, i;
498
- $.info("[%s] parse rule: %s", s.requestId, c);
499
- const a = new RegExp("(?<=\\[)(.+)(?=\\])", "g"), n = c.match(a) ? (t = c.match(a)) == null ? void 0 : t[0] : void 0, o = n == null ? void 0 : n.split(";");
498
+ $.info("[%s] parse rule: %s", e.requestId, c);
499
+ const n = new RegExp("(?<=\\[)(.+)(?=\\])", "g"), a = c.match(n) ? (t = c.match(n)) == null ? void 0 : t[0] : void 0, o = a == null ? void 0 : a.split(";");
500
500
  if (!o)
501
501
  return;
502
- const e = {};
502
+ const s = {};
503
503
  for (let d = 0; d < (o == null ? void 0 : o.length); d++) {
504
- const h = (i = (r = o[d].match(a)) == null ? void 0 : r[0]) == null ? void 0 : i.split("],");
504
+ const h = (i = (r = o[d].match(n)) == null ? void 0 : r[0]) == null ? void 0 : i.split("],");
505
505
  if (d === 0 && !h)
506
- e.scope = o[0];
506
+ s.scope = o[0];
507
507
  else if (h)
508
508
  for (let f = 0, m = h.length; f < m; f++) {
509
509
  const u = this.parseRule(h[f]);
510
- u && (e[u.level] ? u.key ? e[u.level][u == null ? void 0 : u.key] = u : e[u.level] = u : u.key ? e[u.level] = { [u == null ? void 0 : u.key]: u } : e[u.level] = u);
510
+ u && (s[u.level] ? u.key ? s[u.level][u == null ? void 0 : u.key] = u : s[u.level] = u : u.key ? s[u.level] = { [u == null ? void 0 : u.key]: u } : s[u.level] = u);
511
511
  }
512
512
  }
513
- return e;
513
+ return s;
514
514
  }
515
515
  /**
516
516
  * 解析单一告警规则
@@ -518,10 +518,10 @@ class Q {
518
518
  * @param rule
519
519
  * @param options
520
520
  */
521
- parseRule(c, s = {}) {
522
- var e;
523
- $.info("[%s] parse rule: %s", s.requestId, c), c = c.startsWith("[") ? c : `[${c}`, c = c.endsWith("]") ? c : `${c}]`;
524
- const a = new RegExp("(?<=\\[)(.+?)(?=\\])", "g"), n = (e = c == null ? void 0 : c.match(a)) == null ? void 0 : e[0], o = n == null ? void 0 : n.split(",");
521
+ parseRule(c, e = {}) {
522
+ var s;
523
+ $.info("[%s] parse rule: %s", e.requestId, c), c = c.startsWith("[") ? c : `[${c}`, c = c.endsWith("]") ? c : `${c}]`;
524
+ const n = new RegExp("(?<=\\[)(.+?)(?=\\])", "g"), a = (s = c == null ? void 0 : c.match(n)) == null ? void 0 : s[0], o = a == null ? void 0 : a.split(",");
525
525
  if (o)
526
526
  return { operator: o[0], number: Number(o[1]), level: o[2], time: Number(o[3]), key: o[4] };
527
527
  }
@@ -531,23 +531,25 @@ class Q {
531
531
  * @param principle 告警规则
532
532
  * @param options
533
533
  */
534
- checkWeather(c, s, a = {}) {
534
+ checkWeather(c, e, n = {}) {
535
535
  var u, b, w, k, v, g, I, S, l, H, _, R, E, N, x;
536
- let n = 0, o = 0, e = 0, t = 0;
537
- const r = ((b = (u = s == null ? void 0 : s.SEVERE) == null ? void 0 : u.sigWave) == null ? void 0 : b.number) * 1.6, i = (k = (w = s == null ? void 0 : s.SEVERE) == null ? void 0 : w.sigWave) == null ? void 0 : k.number, d = (g = (v = s == null ? void 0 : s.HEAVY) == null ? void 0 : v.sigWave) == null ? void 0 : g.number, h = ((S = (I = s == null ? void 0 : s.SEVERE) == null ? void 0 : I.wind) == null ? void 0 : S.number) + 2, f = (H = (l = s == null ? void 0 : s.SEVERE) == null ? void 0 : l.wind) == null ? void 0 : H.number, m = (R = (_ = s == null ? void 0 : s.HEAVY) == null ? void 0 : _.wind) == null ? void 0 : R.number;
536
+ let a = 0, o = 0, s = 0, t = 0;
537
+ const r = ((b = (u = e == null ? void 0 : e.SEVERE) == null ? void 0 : u.sigWave) == null ? void 0 : b.number) * 1.6, i = (k = (w = e == null ? void 0 : e.SEVERE) == null ? void 0 : w.sigWave) == null ? void 0 : k.number, d = (g = (v = e == null ? void 0 : e.HEAVY) == null ? void 0 : v.sigWave) == null ? void 0 : g.number, h = ((S = (I = e == null ? void 0 : e.SEVERE) == null ? void 0 : I.wind) == null ? void 0 : S.number) + 2, f = (H = (l = e == null ? void 0 : e.SEVERE) == null ? void 0 : l.wind) == null ? void 0 : H.number, m = (R = (_ = e == null ? void 0 : e.HEAVY) == null ? void 0 : _.wind) == null ? void 0 : R.number;
538
538
  for (let A = 1; A < (c == null ? void 0 : c.length); A++) {
539
539
  const y = c[A], T = (N = (E = y == null ? void 0 : y.meteo) == null ? void 0 : E.wave) == null ? void 0 : N.sig, D = (x = y == null ? void 0 : y.meteo) == null ? void 0 : x.wind, P = p(y.eta).diff(p(c[A - 1].eta), "hour", !0);
540
- t = P > t ? P : t, $.info("[%s] check sig.wave: %j", a.requestId, { ...T, dgThd4Wv: r, svThd4Wv: i, hvThd4Wv: d }), (T == null ? void 0 : T.height) >= r ? y.isDangerous = !0 : (T == null ? void 0 : T.height) >= i ? y.isSevere = !0 : (T == null ? void 0 : T.height) >= d && (y.isHeavy = !0), $.info("[%s] check wind: %j", a.requestId, { ...D, dgThd4Wd: h, svThd4Wd: f, hvThd4Wd: m }), (D == null ? void 0 : D.scale) >= h ? (y.isDangerous = !0, delete y.isSevere, delete y.isHeavy) : (D == null ? void 0 : D.scale) > f ? (y.isDangerous || (y.isSevere = !0), delete y.isHeavy) : (D == null ? void 0 : D.scale) === m && !y.isDangerous && !y.isSevere && (y.isHeavy = !0), n += y.isDangerous ? P : 0, o += y.isSevere ? P : 0, e += y.isHeavy ? P : 0, A === 1 && (c[0].isDangerous = y.isDangerous, c[0].isSevere = y.isSevere, c[0].isHeavy = y.isHeavy);
540
+ t = P > t ? P : t, $.info("[%s] check sig.wave: %j", n.requestId, { ...T, dgThd4Wv: r, svThd4Wv: i, hvThd4Wv: d }), (T == null ? void 0 : T.height) >= r ? y.isDangerous = !0 : (T == null ? void 0 : T.height) >= i ? y.isSevere = !0 : (T == null ? void 0 : T.height) >= d && (y.isHeavy = !0), $.info("[%s] check wind: %j", n.requestId, { ...D, dgThd4Wd: h, svThd4Wd: f, hvThd4Wd: m }), (D == null ? void 0 : D.scale) >= h ? (y.isDangerous = !0, delete y.isSevere, delete y.isHeavy) : (D == null ? void 0 : D.scale) > f ? (y.isDangerous || (y.isSevere = !0), delete y.isHeavy) : (D == null ? void 0 : D.scale) === m && !y.isDangerous && !y.isSevere && (y.isHeavy = !0), a += y.isDangerous ? P : 0, o += y.isSevere ? P : 0, s += y.isHeavy ? P : 0, A === 1 && (c[0].isDangerous = y.isDangerous, c[0].isSevere = y.isSevere, c[0].isHeavy = y.isHeavy);
541
541
  }
542
- return n = Math.round(n * 100) / 100, o = Math.round(o * 100) / 100, e = Math.round(e * 100) / 100, t = Math.round(t), { sample: c, dangerous: n, severe: o, heavy: e, step: t < 3 ? 3 : t };
542
+ return a = Math.round(a * 100) / 100, o = Math.round(o * 100) / 100, s = Math.round(s * 100) / 100, t = Math.round(t), { sample: c, dangerous: a, severe: o, heavy: s, step: t < 3 ? 3 : t, wind: { dgThd4Wd: h, svThd4Wd: f, hvThd4Wd: m }, sig: { dgThd4Wv: r, svThd4Wv: i, hvThd4Wv: d } };
543
543
  }
544
544
  }
545
+ const X = new L();
545
546
  export {
546
547
  V as AISImpl,
547
- Q as AlertHelper,
548
+ L as AlertHelper,
548
549
  K as AlertLevel,
549
- B as HifleetImpl,
550
- J as MyShipImpl,
551
- G as MyVesselImpl,
552
- U as ShipxyImpl
550
+ U as HifleetImpl,
551
+ Q as MyShipImpl,
552
+ B as MyVesselImpl,
553
+ J as ShipxyImpl,
554
+ X as alertHelper
553
555
  };
@@ -1 +1 @@
1
- (function(b,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("got"),require("log4js"),require("moment")):typeof define=="function"&&define.amd?define(["exports","got","log4js","moment"],y):(b=typeof globalThis<"u"?globalThis:b||self,y(b["idm-plugin-rabbitmq"]={},b.got,b.log4js,b.moment))})(this,function(b,y,q,p){"use strict";var J=Object.defineProperty;var Q=(b,y,q)=>y in b?J(b,y,{enumerable:!0,configurable:!0,writable:!0,value:q}):b[y]=q;var A=(b,y,q)=>(Q(b,typeof y!="symbol"?y+"":y,q),q);function L(I){const h=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(I){for(const e in I)if(e!=="default"){const a=Object.getOwnPropertyDescriptor(I,e);Object.defineProperty(h,e,a.get?a:{enumerable:!0,get:()=>I[e]})}}return h.default=I,Object.freeze(h)}const C=L(q),M=C.getLogger();class O{parseStatus(h){let e,a;switch(h){case 0:e="在航(主机推动)",a="The engine is in use";break;case 1:e="锚泊",a="Anchored";break;case 2:e="失控",a="Not operated";break;case 3:e="操纵受限",a="Limited airworthiness";break;case 4:e="吃水受限",a="Limited by ship's draft";break;case 5:e="靠泊",a="Mooring";break;case 6:e="搁浅",a="Stranded";break;case 7:e="捕捞作业",a="Engaged in fishing";break;case 8:e="靠帆船提供动力",a="Sailing";break;default:e="未定义",a="Undefined"}return{labelCn:e,labelEn:a}}}class z extends O{constructor(e,a){super();A(this,"clientId");A(this,"clientSecret");A(this,"token");this.clientId=e,this.clientSecret=a}async authToken(e={}){const a="https://svc.data.myvessel.cn/ada/oauth/token",n={searchParams:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},o=await y.post(a,n).json();M.info("[%s] fetch access token from: %s - %j",e.requestId,a,o),o.error||(this.token={accessToken:o.access_token,tokenType:o.token_type,expiresIn:o.expires_in,scope:o.scope,jti:o.jti,issuedAt:p().utc().format()})}async realTimePosition(e,a={}){var d,c,l;(!this.token||p().diff(p(this.token.issuedAt),"seconds")>((d=this.token)==null?void 0:d.expiresIn)-300)&&await this.authToken(a);const n="https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit",o={headers:{Authorization:`${(c=this.token)==null?void 0:c.tokenType} ${(l=this.token)==null?void 0:l.accessToken}`},searchParams:{mmsi:e}};M.info("[%s] fetch realtime position from: %s - %j",a.requestId,n,o);const s=await y.get(n,o).json();if(s.code)return M.warn("[%s] fetch realtime position failed: %j",a.requestId,n,{message:s.message,status:s.status,code:s.code}),s;const t=s.data;for(const f in t)!isNaN(t[f])&&Number(t[f])!==1/0&&(t[f]=Number(t[f]));const r=p(`${t.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:t.mmsi,name:t.vesselName,imo:t.imo,callSign:t.callsign,lat:t.lat,lng:t.lon,length:t.length,width:t.width,draught:t.currDraught,sog:t.sog,cog:t.cog,hdg:t.hdg,rot:t.rot,eta:t.eta,destination:t.dest,positionTime:r.unix(),status:t.status,labelCn:t.statusNameCn,labelEn:t.statusNameEn,method:"position",vendor:"myVessel",utc:r.utc().format()}}async trajectory(e,a,n,o,s=!0,t={}){(!this.token||p().diff(p(this.token.issuedAt),"seconds")>this.token.expiresIn-300)&&await this.authToken(t);const r=await this.realTimePosition(e,t),i=p(a),d=p(n),c=[];for(;d.diff(i,"day",!0)>30;)await this.trajectoryIn30Day(e,i,i.clone().add(30,"day"),r,o,c,t),i.add(30,"day");return await this.trajectoryIn30Day(e,i,d,r,o,c,t),c}async trajectoryIn30Day(e,a,n,o,s,t,r={}){var u,v,Y,j,S;const i="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",d={headers:{Authorization:`${(u=this.token)==null?void 0:u.tokenType} ${(v=this.token)==null?void 0:v.accessToken}`},json:{mmsi:e,startTime:a.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),endTime:n.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")}};M.info("[%s] fetch trajectory from: %s - %j",r.requestId,i,d);const c=await y.post(i,d).json();if(c.code)return M.warn("[%s] fetch trajectory failed: %j",r.requestId,i,{message:c.message,status:c.status,code:c.code}),c;let l=-1;const f=p(`${(j=(Y=c.data)==null?void 0:Y[0])==null?void 0:j.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return(S=c.data)==null||S.forEach(g=>{for(const T in g)!isNaN(g[T])&&Number(g[T])!==1/0&&(g[T]=Number(g[T]));const w=p(`${g.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),N=g.eta?p(`${g.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"):void 0,m=g.status,{labelCn:E,labelEn:P}=this.parseStatus(m),R={mmsi:g.mmsi,imo:o==null?void 0:o.imo,lat:g.lat,lng:g.lon,sog:g.sog,cog:g.cog,hdg:g.hdg,draught:g.draught,status:m,eta:N==null?void 0:N.unix(),destination:g.dest,positionTime:w.unix(),labelCn:E,labelEn:P,method:"trajectory",vendor:"myVessel",utc:w.utc().format()},x=Math.floor(w.diff(f,"minute",!0)/(s||1));x!==l&&(l=x,t.push(R))}),t}}class F extends O{constructor(e){super();A(this,"token");this.token=e}async realTimePosition(e,a={}){const n="https://api.hifleet.com/position/position/get/token",o={searchParams:{mmsi:e,usertoken:this.token}},s=await y.post(n,o).json();M.info("[%s] fetch realtime position from: %s - %j",a.requestId,n,o);const t=s==null?void 0:s.list;if(!t)return M.warn("[%s] fetch realtime position failed: %j",a.requestId,n,s),s;for(const f in t)!isNaN(t[f])&&Number(t[f])!==1/0&&(t[f]=Number(t[f]));t.status=t.sp>3?0:1;const r=t.status,{labelCn:i,labelEn:d}=this.parseStatus(r),c=p(`${t.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:t.m,name:t.n,imo:t.imonumber,callSign:t.callsign,lat:Math.round(t.la/60*1e5)/1e5,lng:Math.round(t.lo/60*1e5)/1e5,length:t.l,width:t.w,draught:t.draught,sog:t.sp,cog:t.co,hdg:t.h,rot:isNaN(t.rot)?0:t.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(t.eta)?p(`${t.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00").unix():void 0,destination:t.destination,positionTime:c.unix(),utc:c.utc().format(),status:r,labelCn:i,labelEn:d,method:"position",vendor:"hifleet"}}async search(e,a={}){let n="https://www.hifleet.com/hifleetapi/searchVesselOL.do";const o={searchParams:{keyword:e},headers:{Referer:"https://www.hifleet.com",Origin:"https://www.hifleet.com",Host:"www.hifleet.com"}};let s=await y.post(n,o).json();M.info("[%s] fetch vessel props from: %s - %j",a.requestId,n,o),s instanceof Array&&(s=s[0]);for(const r in s)!isNaN(s[r])&&Number(s[r])!==1/0&&(s[r]=Number(s[r]));const t={mmsi:s.m,name:s.n,imo:s.i,callSign:s.c,length:s.l,breadth:s.b,draught:s.dr};return n="https://www.hifleet.com/hifleetapi/sameShipSearch.do",s=await y.post(n,o).json(),M.info("[%s] fetch vessel dead weight from: %s - %j",a.requestId,n,o),s instanceof Array&&(s=s[0]),s&&(t.deadweight=Number(s.dwt)),t}async trajectory(e,a,n,o,s=!0,t={}){var g,w,N;const r=await this.realTimePosition(e,t);let i=p(a);const d=p(n),c=p();if(s){let m=d.diff(i,"d",!0);m<0?i=d.clone().subtract(40,"d"):m<30?i.subtract(10,"d"):m<60?i.subtract(5,"d"):i=d.clone().subtract(80,"d"),m=c.diff(d,"d",!0),d.add(m>10?240:m*24,"h")}const l={searchParams:{endtime:d.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),starttime:i.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),mmsi:e,usertoken:this.token}},f="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",u=await y.get(f,l).json();M.info("[%s] fetch trajectory from: %s - %j",t.requestId,f,l);let v;u&&(v=((w=(g=u.ships)==null?void 0:g.offors)==null?void 0:w.ship)||[],v.length||M.warn("[%s] fetch trajectory failed: %j",t.requestId,u));const Y=[];let j=-1;const S=p(`${(N=v==null?void 0:v[0])==null?void 0:N.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const m of v){for(const _ in m)!isNaN(m[_])&&Number(m[_])!==1/0&&(m[_]=Number(m[_]));const E=p(`${m.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");m.status=m.sp>4?0:1;const{labelEn:P,labelCn:R}=this.parseStatus(m.status),x={mmsi:m.m,name:m.n,imo:r==null?void 0:r.imo,lat:m.la,lng:m.lo,draught:m.draught,sog:m.sp,cog:m.co,hdg:m.hdg,positionTime:E.unix(),utc:E.utc().format(),status:m.status,labelCn:R,labelEn:P,method:"trajectory",vendor:"hifleet"},T=Math.floor(E.diff(S,"minute",!0)/(o||1));T!==j&&(j=T,Y.push(x))}return Y}}class G extends O{constructor(e){super();A(this,"token");this.token=e}async realTimePosition(e,a={}){const n={searchParams:{id:e,k:this.token,enc:1}},o="https://api.shipxy.com/apicall/GetSingleShip",s=await y.get(o,n).json();if(M.info("[%s] fetch realtime position from: %s - %j",a.requestId,o,n),(s==null?void 0:s.status)!==0)return s;const t=s.data[0];for(const l in t)!isNaN(t[l])&&Number(t[l])!==1/0&&(t[l]=Number(t[l]));const{labelCn:r,labelEn:i}=await this.parseStatus(t.navistat),d=p.unix(t.lasttime);return{mmsi:t.ShipID,name:t.name,imo:t.imo,callSign:t.callsign,lat:Math.round(t.lat/1e6*1e5)/1e5,lng:Math.round(t.lon/1e6*1e5)/1e5,length:Math.round(t.length/10*100)/100,width:Math.round(t.width/10*100)/100,draught:Math.round(t.draught/1e3*100)/100,sog:Math.round(t.sog*3600/1e3/1852*100)/100,cog:Math.round(t.cog/100*100)/100,hdg:Math.round(t.hdg/100*100)/100,rot:Math.round(t.rot/100*100)/100,positionTime:t.lasttime,utc:d.utc().format(),status:t.navistat,labelEn:i,labelCn:r,method:"position",vendor:"shipxy"}}async trajectory(e,a,n,o,s=!0,t={}){var S;const r=await this.realTimePosition(e,t),i=p(a),d=p(n),c="https://api.shipxy.com/apicall/GetShipTrack",l={searchParams:{id:e,k:this.token,enc:1,cut:0,btm:i.unix(),etm:d.unix()}},f=await y.get(c,l).json();if(M.info("[%s] fetch trajectory from: %s - %j",t.requestId,c,l),(f==null?void 0:f.status)!==0)return f;const u=f==null?void 0:f.points,v=[],Y=p.unix((S=u[0])==null?void 0:S.utc);let j=-1;for(const g of u){const w=p.unix(g.utc),N={imo:r==null?void 0:r.imo,mmsi:e,sog:Math.round(g.sog*3600/1e3/1852*100)/100,cog:Math.round(g.cog/100*100)/100,lat:Math.round(g.lat/1e6*1e5)/1e5,lng:Math.round(g.lon/1e6*1e5)/1e5,positionTime:w.unix(),utc:w.utc().format(),method:"trajectory",vendor:"shipxy"},m=Math.floor(w.diff(Y,"minute",!0)/(o||1));m!==j&&(j=m,v.push(N))}return v}}class B extends O{constructor(e){super();A(this,"token");this.token=e}async getShipId(e,a={}){const n={headers:{appKey:this.token},json:{mmsiList:e}},o="https://api3.myships.com/sp/ships/getShipIdByMMSI",s=await y.post(o,n).json();return M.info("[%s] fetch ship id from: %s - %j",a.requestId,o,n),s.code!=="0"?s:s.data[0].shipId}async getShipInfo(e,a={}){const n={headers:{appKey:this.token},json:{shipId:e}},o="https://api3.myships.com/sp/ships/aissta",s=await y.post(o,n).json();if(M.info("[%s] fetch ship info from: %s - %j",a.requestId,o,n),s.code!=="0")return s;const t=s.data;let r=t.imo;return e==="407170"&&(r="9198379",M.warn("[%s] ship(%s) imo error: %s, should be %s",a.requestId,e,t.imo,r)),{mmsi:t.mmsi,name:t.shipnameEn,imo:r,callSign:t.callSign,length:t.length,width:t.breadth,draught:(t.draught||100)/10}}async realTimePosition(e,a={}){const n=await this.getShipId(e,a),o=await this.getShipInfo(n,a),s={headers:{appKey:this.token},json:{shipId:n}},t="https://api3.myships.com/sp/ships/position/latest",r=await y.post(t,s).json();M.info("[%s] fetch realtime position from: %s - %j",a.requestId,t,s);const i=r.data[0];for(const u in i)!isNaN(i[u])&&Number(i[u])!==1/0&&(i[u]=Number(i[u]));const{labelCn:d,labelEn:c}=await this.parseStatus(i.aisNavStatus),l=p.unix(i.posTime);return{...o,mmsi:e,lat:Math.round(i.lat/1e4/60*1e5)/1e5,lng:Math.round(i.lon/1e4/60*1e5)/1e5,sog:Math.round(i.sog/10*100)/100,cog:Math.round(i.cog/10*100)/100,hdg:Math.round(i.heading*100)/100,rot:Math.round(i.rot*100)/100,positionTime:i.posTime,utc:l.utc().format(),status:i.aisNavStatus,labelEn:c,labelCn:d,method:"position",vendor:"myship"}}async trajectory(e,a,n,o,s=!0,t={}){const r=p(a),i=p(n),d=await this.getShipId(e),c=await this.getShipInfo(d),l=[];for(;i.diff(r,"day",!0)>30;)await this.trajectoryIn30Day(d,r.unix(),r.add(30,"day").unix(),c,e,o,l);return await this.trajectoryIn30Day(d,r.unix(),i.unix(),c,e,o,l),l}async trajectoryIn30Day(e,a,n,o,s,t,r,i={}){var Y;const d={headers:{appKey:this.token},json:{shipId:e,startTime:a,endTime:n}},c="https://api3.myships.com/sp/ships/position/history",l=await y.post(c,d).json();if(M.info("[%s] fetch trajectory from: %s - %j",i.requestId,c,d),l.code!=="0")return M.warn("[%s] invoke myship trajectory failed: %j",i.requestId,l),l;const f=l.data;for(const j in f)!isNaN(f[j])&&Number(f[j])!==1/0&&(f[j]=Number(f[j]));const u=p.unix((Y=f[0])==null?void 0:Y.posTime);let v=-1;for(const j of f){const S=p.unix(j.posTime),g={imo:o==null?void 0:o.imo,mmsi:s,lat:Math.round(j.lat/1e4/60*1e5)/1e5,lng:Math.round(j.lon/1e4/60*1e5)/1e5,sog:Math.round(j.sog/10*100)/100,cog:Math.round(j.cog/10*100)/100,hdg:Math.round(j.heading*100)/100,rot:Math.round(j.rot*100)/100,positionTime:S.unix(),utc:S.utc().format(),method:"trajectory",vendor:"myship"},w=Math.floor(S.diff(u,"minute",!0)/(t||1));w!==v&&(v=w,r.push(g))}return r}}const W=C.getLogger();var K=(I=>(I.NOTICE="NOTICE",I.WARN="WARN",I.HEAVY="HEAVY",I.SEVERE="SEVERE",I.ERROR="ERROR",I.FATAL="FATAL",I))(K||{});class U{parsePrinciple(h,e={}){var t,r,i;W.info("[%s] parse rule: %s",e.requestId,h);const a=new RegExp("(?<=\\[)(.+)(?=\\])","g"),n=h.match(a)?(t=h.match(a))==null?void 0:t[0]:void 0,o=n==null?void 0:n.split(";");if(!o)return;const s={};for(let d=0;d<(o==null?void 0:o.length);d++){const c=(i=(r=o[d].match(a))==null?void 0:r[0])==null?void 0:i.split("],");if(d===0&&!c)s.scope=o[0];else if(c)for(let l=0,f=c.length;l<f;l++){const u=this.parseRule(c[l]);u&&(s[u.level]?u.key?s[u.level][u==null?void 0:u.key]=u:s[u.level]=u:u.key?s[u.level]={[u==null?void 0:u.key]:u}:s[u.level]=u)}}return s}parseRule(h,e={}){var s;W.info("[%s] parse rule: %s",e.requestId,h),h=h.startsWith("[")?h:`[${h}`,h=h.endsWith("]")?h:`${h}]`;const a=new RegExp("(?<=\\[)(.+?)(?=\\])","g"),n=(s=h==null?void 0:h.match(a))==null?void 0:s[0],o=n==null?void 0:n.split(",");if(o)return{operator:o[0],number:Number(o[1]),level:o[2],time:Number(o[3]),key:o[4]}}checkWeather(h,e,a={}){var u,v,Y,j,S,g,w,N,m,E,P,R,x,T,_;let n=0,o=0,s=0,t=0;const r=((v=(u=e==null?void 0:e.SEVERE)==null?void 0:u.sigWave)==null?void 0:v.number)*1.6,i=(j=(Y=e==null?void 0:e.SEVERE)==null?void 0:Y.sigWave)==null?void 0:j.number,d=(g=(S=e==null?void 0:e.HEAVY)==null?void 0:S.sigWave)==null?void 0:g.number,c=((N=(w=e==null?void 0:e.SEVERE)==null?void 0:w.wind)==null?void 0:N.number)+2,l=(E=(m=e==null?void 0:e.SEVERE)==null?void 0:m.wind)==null?void 0:E.number,f=(R=(P=e==null?void 0:e.HEAVY)==null?void 0:P.wind)==null?void 0:R.number;for(let V=1;V<(h==null?void 0:h.length);V++){const k=h[V],D=(T=(x=k==null?void 0:k.meteo)==null?void 0:x.wave)==null?void 0:T.sig,H=(_=k==null?void 0:k.meteo)==null?void 0:_.wind,$=p(k.eta).diff(p(h[V-1].eta),"hour",!0);t=$>t?$:t,W.info("[%s] check sig.wave: %j",a.requestId,{...D,dgThd4Wv:r,svThd4Wv:i,hvThd4Wv:d}),(D==null?void 0:D.height)>=r?k.isDangerous=!0:(D==null?void 0:D.height)>=i?k.isSevere=!0:(D==null?void 0:D.height)>=d&&(k.isHeavy=!0),W.info("[%s] check wind: %j",a.requestId,{...H,dgThd4Wd:c,svThd4Wd:l,hvThd4Wd:f}),(H==null?void 0:H.scale)>=c?(k.isDangerous=!0,delete k.isSevere,delete k.isHeavy):(H==null?void 0:H.scale)>l?(k.isDangerous||(k.isSevere=!0),delete k.isHeavy):(H==null?void 0:H.scale)===f&&!k.isDangerous&&!k.isSevere&&(k.isHeavy=!0),n+=k.isDangerous?$:0,o+=k.isSevere?$:0,s+=k.isHeavy?$:0,V===1&&(h[0].isDangerous=k.isDangerous,h[0].isSevere=k.isSevere,h[0].isHeavy=k.isHeavy)}return n=Math.round(n*100)/100,o=Math.round(o*100)/100,s=Math.round(s*100)/100,t=Math.round(t),{sample:h,dangerous:n,severe:o,heavy:s,step:t<3?3:t}}}b.AISImpl=O,b.AlertHelper=U,b.AlertLevel=K,b.HifleetImpl=F,b.MyShipImpl=B,b.MyVesselImpl=z,b.ShipxyImpl=G,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
1
+ (function(b,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("got"),require("log4js"),require("moment")):typeof define=="function"&&define.amd?define(["exports","got","log4js","moment"],y):(b=typeof globalThis<"u"?globalThis:b||self,y(b["idm-plugin-rabbitmq"]={},b.got,b.log4js,b.moment))})(this,function(b,y,q,p){"use strict";var Q=Object.defineProperty;var X=(b,y,q)=>y in b?Q(b,y,{enumerable:!0,configurable:!0,writable:!0,value:q}):b[y]=q;var A=(b,y,q)=>(X(b,typeof y!="symbol"?y+"":y,q),q);function z(I){const f=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(I){for(const e in I)if(e!=="default"){const a=Object.getOwnPropertyDescriptor(I,e);Object.defineProperty(f,e,a.get?a:{enumerable:!0,get:()=>I[e]})}}return f.default=I,Object.freeze(f)}const C=z(q),M=C.getLogger();class O{parseStatus(f){let e,a;switch(f){case 0:e="在航(主机推动)",a="The engine is in use";break;case 1:e="锚泊",a="Anchored";break;case 2:e="失控",a="Not operated";break;case 3:e="操纵受限",a="Limited airworthiness";break;case 4:e="吃水受限",a="Limited by ship's draft";break;case 5:e="靠泊",a="Mooring";break;case 6:e="搁浅",a="Stranded";break;case 7:e="捕捞作业",a="Engaged in fishing";break;case 8:e="靠帆船提供动力",a="Sailing";break;default:e="未定义",a="Undefined"}return{labelCn:e,labelEn:a}}}class F extends O{constructor(e,a){super();A(this,"clientId");A(this,"clientSecret");A(this,"token");this.clientId=e,this.clientSecret=a}async authToken(e={}){const a="https://svc.data.myvessel.cn/ada/oauth/token",n={searchParams:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},o=await y.post(a,n).json();M.info("[%s] fetch access token from: %s - %j",e.requestId,a,o),o.error||(this.token={accessToken:o.access_token,tokenType:o.token_type,expiresIn:o.expires_in,scope:o.scope,jti:o.jti,issuedAt:p().utc().format()})}async realTimePosition(e,a={}){var d,c,l;(!this.token||p().diff(p(this.token.issuedAt),"seconds")>((d=this.token)==null?void 0:d.expiresIn)-300)&&await this.authToken(a);const n="https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit",o={headers:{Authorization:`${(c=this.token)==null?void 0:c.tokenType} ${(l=this.token)==null?void 0:l.accessToken}`},searchParams:{mmsi:e}};M.info("[%s] fetch realtime position from: %s - %j",a.requestId,n,o);const s=await y.get(n,o).json();if(s.code)return M.warn("[%s] fetch realtime position failed: %j",a.requestId,n,{message:s.message,status:s.status,code:s.code}),s;const t=s.data;for(const h in t)!isNaN(t[h])&&Number(t[h])!==1/0&&(t[h]=Number(t[h]));const r=p(`${t.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:t.mmsi,name:t.vesselName,imo:t.imo,callSign:t.callsign,lat:t.lat,lng:t.lon,length:t.length,width:t.width,draught:t.currDraught,sog:t.sog,cog:t.cog,hdg:t.hdg,rot:t.rot,eta:t.eta,destination:t.dest,positionTime:r.unix(),status:t.status,labelCn:t.statusNameCn,labelEn:t.statusNameEn,method:"position",vendor:"myVessel",utc:r.utc().format()}}async trajectory(e,a,n,o,s=!0,t={}){(!this.token||p().diff(p(this.token.issuedAt),"seconds")>this.token.expiresIn-300)&&await this.authToken(t);const r=await this.realTimePosition(e,t),i=p(a),d=p(n),c=[];for(;d.diff(i,"day",!0)>30;)await this.trajectoryIn30Day(e,i,i.clone().add(30,"day"),r,o,c,t),i.add(30,"day");return await this.trajectoryIn30Day(e,i,d,r,o,c,t),c}async trajectoryIn30Day(e,a,n,o,s,t,r={}){var u,v,Y,j,S;const i="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",d={headers:{Authorization:`${(u=this.token)==null?void 0:u.tokenType} ${(v=this.token)==null?void 0:v.accessToken}`},json:{mmsi:e,startTime:a.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),endTime:n.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")}};M.info("[%s] fetch trajectory from: %s - %j",r.requestId,i,d);const c=await y.post(i,d).json();if(c.code)return M.warn("[%s] fetch trajectory failed: %j",r.requestId,i,{message:c.message,status:c.status,code:c.code}),c;let l=-1;const h=p(`${(j=(Y=c.data)==null?void 0:Y[0])==null?void 0:j.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return(S=c.data)==null||S.forEach(g=>{for(const T in g)!isNaN(g[T])&&Number(g[T])!==1/0&&(g[T]=Number(g[T]));const w=p(`${g.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),N=g.eta?p(`${g.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"):void 0,m=g.status,{labelCn:E,labelEn:P}=this.parseStatus(m),R={mmsi:g.mmsi,imo:o==null?void 0:o.imo,lat:g.lat,lng:g.lon,sog:g.sog,cog:g.cog,hdg:g.hdg,draught:g.draught,status:m,eta:N==null?void 0:N.unix(),destination:g.dest,positionTime:w.unix(),labelCn:E,labelEn:P,method:"trajectory",vendor:"myVessel",utc:w.utc().format()},x=Math.floor(w.diff(h,"minute",!0)/(s||1));x!==l&&(l=x,t.push(R))}),t}}class G extends O{constructor(e){super();A(this,"token");this.token=e}async realTimePosition(e,a={}){const n="https://api.hifleet.com/position/position/get/token",o={searchParams:{mmsi:e,usertoken:this.token}},s=await y.post(n,o).json();M.info("[%s] fetch realtime position from: %s - %j",a.requestId,n,o);const t=s==null?void 0:s.list;if(!t)return M.warn("[%s] fetch realtime position failed: %j",a.requestId,n,s),s;for(const h in t)!isNaN(t[h])&&Number(t[h])!==1/0&&(t[h]=Number(t[h]));t.status=t.sp>3?0:1;const r=t.status,{labelCn:i,labelEn:d}=this.parseStatus(r),c=p(`${t.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:t.m,name:t.n,imo:t.imonumber,callSign:t.callsign,lat:Math.round(t.la/60*1e5)/1e5,lng:Math.round(t.lo/60*1e5)/1e5,length:t.l,width:t.w,draught:t.draught,sog:t.sp,cog:t.co,hdg:t.h,rot:isNaN(t.rot)?0:t.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(t.eta)?p(`${t.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00").unix():void 0,destination:t.destination,positionTime:c.unix(),utc:c.utc().format(),status:r,labelCn:i,labelEn:d,method:"position",vendor:"hifleet"}}async search(e,a={}){let n="https://www.hifleet.com/hifleetapi/searchVesselOL.do";const o={searchParams:{keyword:e},headers:{Referer:"https://www.hifleet.com",Origin:"https://www.hifleet.com",Host:"www.hifleet.com"}};let s=await y.post(n,o).json();M.info("[%s] fetch vessel props from: %s - %j",a.requestId,n,o),s instanceof Array&&(s=s[0]);for(const r in s)!isNaN(s[r])&&Number(s[r])!==1/0&&(s[r]=Number(s[r]));const t={mmsi:s.m,name:s.n,imo:s.i,callSign:s.c,length:s.l,breadth:s.b,draught:s.dr};return n="https://www.hifleet.com/hifleetapi/sameShipSearch.do",s=await y.post(n,o).json(),M.info("[%s] fetch vessel dead weight from: %s - %j",a.requestId,n,o),s instanceof Array&&(s=s[0]),s&&(t.deadweight=Number(s.dwt)),t}async trajectory(e,a,n,o,s=!0,t={}){var g,w,N;const r=await this.realTimePosition(e,t);let i=p(a);const d=p(n),c=p();if(s){let m=d.diff(i,"d",!0);m<0?i=d.clone().subtract(40,"d"):m<30?i.subtract(10,"d"):m<60?i.subtract(5,"d"):i=d.clone().subtract(80,"d"),m=c.diff(d,"d",!0),d.add(m>10?240:m*24,"h")}const l={searchParams:{endtime:d.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),starttime:i.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),mmsi:e,usertoken:this.token}},h="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",u=await y.get(h,l).json();M.info("[%s] fetch trajectory from: %s - %j",t.requestId,h,l);let v;u&&(v=((w=(g=u.ships)==null?void 0:g.offors)==null?void 0:w.ship)||[],v.length||M.warn("[%s] fetch trajectory failed: %j",t.requestId,u));const Y=[];let j=-1;const S=p(`${(N=v==null?void 0:v[0])==null?void 0:N.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const m of v){for(const _ in m)!isNaN(m[_])&&Number(m[_])!==1/0&&(m[_]=Number(m[_]));const E=p(`${m.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");m.status=m.sp>4?0:1;const{labelEn:P,labelCn:R}=this.parseStatus(m.status),x={mmsi:m.m,name:m.n,imo:r==null?void 0:r.imo,lat:m.la,lng:m.lo,draught:m.draught,sog:m.sp,cog:m.co,hdg:m.hdg,positionTime:E.unix(),utc:E.utc().format(),status:m.status,labelCn:R,labelEn:P,method:"trajectory",vendor:"hifleet"},T=Math.floor(E.diff(S,"minute",!0)/(o||1));T!==j&&(j=T,Y.push(x))}return Y}}class B extends O{constructor(e){super();A(this,"token");this.token=e}async realTimePosition(e,a={}){const n={searchParams:{id:e,k:this.token,enc:1}},o="https://api.shipxy.com/apicall/GetSingleShip",s=await y.get(o,n).json();if(M.info("[%s] fetch realtime position from: %s - %j",a.requestId,o,n),(s==null?void 0:s.status)!==0)return s;const t=s.data[0];for(const l in t)!isNaN(t[l])&&Number(t[l])!==1/0&&(t[l]=Number(t[l]));const{labelCn:r,labelEn:i}=await this.parseStatus(t.navistat),d=p.unix(t.lasttime);return{mmsi:t.ShipID,name:t.name,imo:t.imo,callSign:t.callsign,lat:Math.round(t.lat/1e6*1e5)/1e5,lng:Math.round(t.lon/1e6*1e5)/1e5,length:Math.round(t.length/10*100)/100,width:Math.round(t.width/10*100)/100,draught:Math.round(t.draught/1e3*100)/100,sog:Math.round(t.sog*3600/1e3/1852*100)/100,cog:Math.round(t.cog/100*100)/100,hdg:Math.round(t.hdg/100*100)/100,rot:Math.round(t.rot/100*100)/100,positionTime:t.lasttime,utc:d.utc().format(),status:t.navistat,labelEn:i,labelCn:r,method:"position",vendor:"shipxy"}}async trajectory(e,a,n,o,s=!0,t={}){var S;const r=await this.realTimePosition(e,t),i=p(a),d=p(n),c="https://api.shipxy.com/apicall/GetShipTrack",l={searchParams:{id:e,k:this.token,enc:1,cut:0,btm:i.unix(),etm:d.unix()}},h=await y.get(c,l).json();if(M.info("[%s] fetch trajectory from: %s - %j",t.requestId,c,l),(h==null?void 0:h.status)!==0)return h;const u=h==null?void 0:h.points,v=[],Y=p.unix((S=u[0])==null?void 0:S.utc);let j=-1;for(const g of u){const w=p.unix(g.utc),N={imo:r==null?void 0:r.imo,mmsi:e,sog:Math.round(g.sog*3600/1e3/1852*100)/100,cog:Math.round(g.cog/100*100)/100,lat:Math.round(g.lat/1e6*1e5)/1e5,lng:Math.round(g.lon/1e6*1e5)/1e5,positionTime:w.unix(),utc:w.utc().format(),method:"trajectory",vendor:"shipxy"},m=Math.floor(w.diff(Y,"minute",!0)/(o||1));m!==j&&(j=m,v.push(N))}return v}}class U extends O{constructor(e){super();A(this,"token");this.token=e}async getShipId(e,a={}){const n={headers:{appKey:this.token},json:{mmsiList:e}},o="https://api3.myships.com/sp/ships/getShipIdByMMSI",s=await y.post(o,n).json();return M.info("[%s] fetch ship id from: %s - %j",a.requestId,o,n),s.code!=="0"?s:s.data[0].shipId}async getShipInfo(e,a={}){const n={headers:{appKey:this.token},json:{shipId:e}},o="https://api3.myships.com/sp/ships/aissta",s=await y.post(o,n).json();if(M.info("[%s] fetch ship info from: %s - %j",a.requestId,o,n),s.code!=="0")return s;const t=s.data;let r=t.imo;return e==="407170"&&(r="9198379",M.warn("[%s] ship(%s) imo error: %s, should be %s",a.requestId,e,t.imo,r)),{mmsi:t.mmsi,name:t.shipnameEn,imo:r,callSign:t.callSign,length:t.length,width:t.breadth,draught:(t.draught||100)/10}}async realTimePosition(e,a={}){const n=await this.getShipId(e,a),o=await this.getShipInfo(n,a),s={headers:{appKey:this.token},json:{shipId:n}},t="https://api3.myships.com/sp/ships/position/latest",r=await y.post(t,s).json();M.info("[%s] fetch realtime position from: %s - %j",a.requestId,t,s);const i=r.data[0];for(const u in i)!isNaN(i[u])&&Number(i[u])!==1/0&&(i[u]=Number(i[u]));const{labelCn:d,labelEn:c}=await this.parseStatus(i.aisNavStatus),l=p.unix(i.posTime);return{...o,mmsi:e,lat:Math.round(i.lat/1e4/60*1e5)/1e5,lng:Math.round(i.lon/1e4/60*1e5)/1e5,sog:Math.round(i.sog/10*100)/100,cog:Math.round(i.cog/10*100)/100,hdg:Math.round(i.heading*100)/100,rot:Math.round(i.rot*100)/100,positionTime:i.posTime,utc:l.utc().format(),status:i.aisNavStatus,labelEn:c,labelCn:d,method:"position",vendor:"myship"}}async trajectory(e,a,n,o,s=!0,t={}){const r=p(a),i=p(n),d=await this.getShipId(e),c=await this.getShipInfo(d),l=[];for(;i.diff(r,"day",!0)>30;)await this.trajectoryIn30Day(d,r.unix(),r.add(30,"day").unix(),c,e,o,l);return await this.trajectoryIn30Day(d,r.unix(),i.unix(),c,e,o,l),l}async trajectoryIn30Day(e,a,n,o,s,t,r,i={}){var Y;const d={headers:{appKey:this.token},json:{shipId:e,startTime:a,endTime:n}},c="https://api3.myships.com/sp/ships/position/history",l=await y.post(c,d).json();if(M.info("[%s] fetch trajectory from: %s - %j",i.requestId,c,d),l.code!=="0")return M.warn("[%s] invoke myship trajectory failed: %j",i.requestId,l),l;const h=l.data;for(const j in h)!isNaN(h[j])&&Number(h[j])!==1/0&&(h[j]=Number(h[j]));const u=p.unix((Y=h[0])==null?void 0:Y.posTime);let v=-1;for(const j of h){const S=p.unix(j.posTime),g={imo:o==null?void 0:o.imo,mmsi:s,lat:Math.round(j.lat/1e4/60*1e5)/1e5,lng:Math.round(j.lon/1e4/60*1e5)/1e5,sog:Math.round(j.sog/10*100)/100,cog:Math.round(j.cog/10*100)/100,hdg:Math.round(j.heading*100)/100,rot:Math.round(j.rot*100)/100,positionTime:S.unix(),utc:S.utc().format(),method:"trajectory",vendor:"myship"},w=Math.floor(S.diff(u,"minute",!0)/(t||1));w!==v&&(v=w,r.push(g))}return r}}const W=C.getLogger();var K=(I=>(I.NOTICE="NOTICE",I.WARN="WARN",I.HEAVY="HEAVY",I.SEVERE="SEVERE",I.ERROR="ERROR",I.FATAL="FATAL",I))(K||{});class L{parsePrinciple(f,e={}){var t,r,i;W.info("[%s] parse rule: %s",e.requestId,f);const a=new RegExp("(?<=\\[)(.+)(?=\\])","g"),n=f.match(a)?(t=f.match(a))==null?void 0:t[0]:void 0,o=n==null?void 0:n.split(";");if(!o)return;const s={};for(let d=0;d<(o==null?void 0:o.length);d++){const c=(i=(r=o[d].match(a))==null?void 0:r[0])==null?void 0:i.split("],");if(d===0&&!c)s.scope=o[0];else if(c)for(let l=0,h=c.length;l<h;l++){const u=this.parseRule(c[l]);u&&(s[u.level]?u.key?s[u.level][u==null?void 0:u.key]=u:s[u.level]=u:u.key?s[u.level]={[u==null?void 0:u.key]:u}:s[u.level]=u)}}return s}parseRule(f,e={}){var s;W.info("[%s] parse rule: %s",e.requestId,f),f=f.startsWith("[")?f:`[${f}`,f=f.endsWith("]")?f:`${f}]`;const a=new RegExp("(?<=\\[)(.+?)(?=\\])","g"),n=(s=f==null?void 0:f.match(a))==null?void 0:s[0],o=n==null?void 0:n.split(",");if(o)return{operator:o[0],number:Number(o[1]),level:o[2],time:Number(o[3]),key:o[4]}}checkWeather(f,e,a={}){var u,v,Y,j,S,g,w,N,m,E,P,R,x,T,_;let n=0,o=0,s=0,t=0;const r=((v=(u=e==null?void 0:e.SEVERE)==null?void 0:u.sigWave)==null?void 0:v.number)*1.6,i=(j=(Y=e==null?void 0:e.SEVERE)==null?void 0:Y.sigWave)==null?void 0:j.number,d=(g=(S=e==null?void 0:e.HEAVY)==null?void 0:S.sigWave)==null?void 0:g.number,c=((N=(w=e==null?void 0:e.SEVERE)==null?void 0:w.wind)==null?void 0:N.number)+2,l=(E=(m=e==null?void 0:e.SEVERE)==null?void 0:m.wind)==null?void 0:E.number,h=(R=(P=e==null?void 0:e.HEAVY)==null?void 0:P.wind)==null?void 0:R.number;for(let V=1;V<(f==null?void 0:f.length);V++){const k=f[V],H=(T=(x=k==null?void 0:k.meteo)==null?void 0:x.wave)==null?void 0:T.sig,D=(_=k==null?void 0:k.meteo)==null?void 0:_.wind,$=p(k.eta).diff(p(f[V-1].eta),"hour",!0);t=$>t?$:t,W.info("[%s] check sig.wave: %j",a.requestId,{...H,dgThd4Wv:r,svThd4Wv:i,hvThd4Wv:d}),(H==null?void 0:H.height)>=r?k.isDangerous=!0:(H==null?void 0:H.height)>=i?k.isSevere=!0:(H==null?void 0:H.height)>=d&&(k.isHeavy=!0),W.info("[%s] check wind: %j",a.requestId,{...D,dgThd4Wd:c,svThd4Wd:l,hvThd4Wd:h}),(D==null?void 0:D.scale)>=c?(k.isDangerous=!0,delete k.isSevere,delete k.isHeavy):(D==null?void 0:D.scale)>l?(k.isDangerous||(k.isSevere=!0),delete k.isHeavy):(D==null?void 0:D.scale)===h&&!k.isDangerous&&!k.isSevere&&(k.isHeavy=!0),n+=k.isDangerous?$:0,o+=k.isSevere?$:0,s+=k.isHeavy?$:0,V===1&&(f[0].isDangerous=k.isDangerous,f[0].isSevere=k.isSevere,f[0].isHeavy=k.isHeavy)}return n=Math.round(n*100)/100,o=Math.round(o*100)/100,s=Math.round(s*100)/100,t=Math.round(t),{sample:f,dangerous:n,severe:o,heavy:s,step:t<3?3:t,wind:{dgThd4Wd:c,svThd4Wd:l,hvThd4Wd:h},sig:{dgThd4Wv:r,svThd4Wv:i,hvThd4Wv:d}}}}const J=new L;b.AISImpl=O,b.AlertHelper=L,b.AlertLevel=K,b.HifleetImpl=G,b.MyShipImpl=U,b.MyVesselImpl=F,b.ShipxyImpl=B,b.alertHelper=J,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@idm-plugin/vessel",
3
3
  "private": false,
4
- "version": "1.0.3",
4
+ "version": "1.0.5",
5
5
  "description": "idm plugin for vessel",
6
6
  "type": "module",
7
7
  "keywords": [