@idm-plugin/vessel 1.1.7 → 1.1.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.
- package/dist/ais/src/index.d.ts +36 -13
- package/dist/alert/src/index.d.ts +10 -5
- package/dist/index.d.ts +0 -3
- package/dist/index.js +41 -35
- package/dist/index.umd.cjs +1 -1
- package/package.json +3 -1
package/dist/ais/src/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { RequestOptions } from '../../index';
|
|
2
1
|
/**
|
|
3
2
|
* AIS记录
|
|
4
3
|
*/
|
|
@@ -61,30 +60,54 @@ export declare class MyVesselImpl extends AISImpl {
|
|
|
61
60
|
private readonly clientSecret;
|
|
62
61
|
private token;
|
|
63
62
|
constructor(clientId: string, clientSecret: string);
|
|
64
|
-
authToken(options?:
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
authToken(options?: {
|
|
64
|
+
requestId?: string;
|
|
65
|
+
}): Promise<void>;
|
|
66
|
+
realTimePosition(mmsi: number, options?: {
|
|
67
|
+
requestId?: string;
|
|
68
|
+
}): Promise<AISRecord>;
|
|
69
|
+
trajectory(mmsi: number, startTime: string, endTime: string, offset: number, scale?: boolean, options?: {
|
|
70
|
+
requestId?: string;
|
|
71
|
+
}): Promise<AISRecord[]>;
|
|
67
72
|
private trajectoryIn30Day;
|
|
68
73
|
}
|
|
69
74
|
export declare class HifleetImpl extends AISImpl {
|
|
70
75
|
private readonly token;
|
|
71
76
|
constructor(token: string);
|
|
72
|
-
realTimePosition(mmsi: number, options?:
|
|
73
|
-
|
|
74
|
-
|
|
77
|
+
realTimePosition(mmsi: number, options?: {
|
|
78
|
+
requestId?: string;
|
|
79
|
+
}): Promise<AISRecord>;
|
|
80
|
+
search(kw: string, options?: {
|
|
81
|
+
requestId?: string;
|
|
82
|
+
}): Promise<VesselRecord>;
|
|
83
|
+
trajectory(mmsi: number, startTime: string, endTime: string, offset: number, scale?: boolean, options?: {
|
|
84
|
+
requestId?: string;
|
|
85
|
+
}): Promise<AISRecord[]>;
|
|
75
86
|
}
|
|
76
87
|
export declare class ShipxyImpl extends AISImpl {
|
|
77
88
|
private readonly token;
|
|
78
89
|
constructor(token: string);
|
|
79
|
-
realTimePosition(mmsi: number, options?:
|
|
80
|
-
|
|
90
|
+
realTimePosition(mmsi: number, options?: {
|
|
91
|
+
requestId?: string;
|
|
92
|
+
}): Promise<AISRecord>;
|
|
93
|
+
trajectory(mmsi: number, startTime: string, endTime: string, offset: number, scale?: boolean, options?: {
|
|
94
|
+
requestId?: string;
|
|
95
|
+
}): Promise<AISRecord[]>;
|
|
81
96
|
}
|
|
82
97
|
export declare class MyShipImpl extends AISImpl {
|
|
83
98
|
private readonly token;
|
|
84
99
|
constructor(token: string);
|
|
85
|
-
getShipId(mmsi: any, options?:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
100
|
+
getShipId(mmsi: any, options?: {
|
|
101
|
+
requestId?: string;
|
|
102
|
+
}): Promise<string>;
|
|
103
|
+
getShipInfo(shipId: string, options?: {
|
|
104
|
+
requestId?: string;
|
|
105
|
+
}): Promise<AISRecord>;
|
|
106
|
+
realTimePosition(mmsi: number, options?: {
|
|
107
|
+
requestId?: string;
|
|
108
|
+
}): Promise<AISRecord>;
|
|
109
|
+
trajectory(mmsi: number, startTime: string, endTime: string, offset: number, scale?: boolean, options?: {
|
|
110
|
+
requestId?: string;
|
|
111
|
+
}): Promise<AISRecord[]>;
|
|
89
112
|
private trajectoryIn30Day;
|
|
90
113
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { RequestOptions } from '../../../build/packages/index';
|
|
2
1
|
export declare enum AlertLevel {
|
|
3
2
|
NOTICE = "NOTICE",
|
|
4
3
|
WARN = "WARN",
|
|
@@ -9,7 +8,7 @@ export declare enum AlertLevel {
|
|
|
9
8
|
}
|
|
10
9
|
export interface AlertRule {
|
|
11
10
|
operator: string;
|
|
12
|
-
number: number;
|
|
11
|
+
number: number | string;
|
|
13
12
|
level: string;
|
|
14
13
|
time: number;
|
|
15
14
|
key?: string;
|
|
@@ -23,21 +22,27 @@ export declare class AlertHelper {
|
|
|
23
22
|
*
|
|
24
23
|
* @param options
|
|
25
24
|
*/
|
|
26
|
-
parsePrinciple(rule: string, options?:
|
|
25
|
+
parsePrinciple(rule: string, options?: {
|
|
26
|
+
requestId?: string;
|
|
27
|
+
}): any;
|
|
27
28
|
/**
|
|
28
29
|
* 解析单一告警规则
|
|
29
30
|
* e.g.1 [>,maxCP,WARN,0,TotCons_VLSFO]
|
|
30
31
|
* @param rule
|
|
31
32
|
* @param options
|
|
32
33
|
*/
|
|
33
|
-
parseRule(rule: string, options?:
|
|
34
|
+
parseRule(rule: string, options?: {
|
|
35
|
+
requestId?: string;
|
|
36
|
+
}): AlertRule | undefined;
|
|
34
37
|
/**
|
|
35
38
|
* 检查航路点天气
|
|
36
39
|
* @param sample 航路点
|
|
37
40
|
* @param principle 告警规则
|
|
38
41
|
* @param options
|
|
39
42
|
*/
|
|
40
|
-
checkWeather(sample: any[], principle: any, options?:
|
|
43
|
+
checkWeather(sample: any[], principle: any, options?: {
|
|
44
|
+
requestId?: string;
|
|
45
|
+
}): {
|
|
41
46
|
sample: any[];
|
|
42
47
|
dangerous: number;
|
|
43
48
|
severe: number;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ var q = (M, u, e) => (O(M, typeof u != "symbol" ? u + "" : u, e), e);
|
|
|
4
4
|
import Y from "got";
|
|
5
5
|
import W from "@log4js-node/log4js-api";
|
|
6
6
|
import p from "moment";
|
|
7
|
-
const
|
|
7
|
+
const b = W.getLogger("vessel");
|
|
8
8
|
class V {
|
|
9
9
|
/**
|
|
10
10
|
* 解析AIS状态码
|
|
@@ -62,7 +62,7 @@ class U extends V {
|
|
|
62
62
|
grant_type: "client_credentials"
|
|
63
63
|
}
|
|
64
64
|
}, o = await Y.post(n, a).json();
|
|
65
|
-
|
|
65
|
+
b.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,
|
|
@@ -80,10 +80,10 @@ class U extends V {
|
|
|
80
80
|
},
|
|
81
81
|
searchParams: { mmsi: e }
|
|
82
82
|
};
|
|
83
|
-
|
|
83
|
+
b.info("[%s] fetch realtime position from: %s - %j", n.requestId, a, o);
|
|
84
84
|
const s = await Y.get(a, o).json();
|
|
85
85
|
if (s.code)
|
|
86
|
-
return
|
|
86
|
+
return b.warn("[%s] fetch realtime position failed: %j", n.requestId, a, { message: s.message, status: s.status, code: s.code }), s;
|
|
87
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]));
|
|
@@ -121,10 +121,10 @@ class U extends V {
|
|
|
121
121
|
return await this.trajectoryIn30Day(e, i, h, r, o, c, t), c;
|
|
122
122
|
}
|
|
123
123
|
async trajectoryIn30Day(e, n, a, o, s, t, r = {}) {
|
|
124
|
-
var d,
|
|
124
|
+
var d, j, w, y, v;
|
|
125
125
|
const i = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/track", h = {
|
|
126
126
|
headers: {
|
|
127
|
-
Authorization: `${(d = this.token) == null ? void 0 : d.tokenType} ${(
|
|
127
|
+
Authorization: `${(d = this.token) == null ? void 0 : d.tokenType} ${(j = this.token) == null ? void 0 : j.accessToken}`
|
|
128
128
|
},
|
|
129
129
|
json: {
|
|
130
130
|
mmsi: e,
|
|
@@ -132,10 +132,10 @@ class U extends V {
|
|
|
132
132
|
endTime: a.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")
|
|
133
133
|
}
|
|
134
134
|
};
|
|
135
|
-
|
|
135
|
+
b.info("[%s] fetch trajectory from: %s - %j", r.requestId, i, h);
|
|
136
136
|
const c = await Y.post(i, h).json();
|
|
137
137
|
if (c.code)
|
|
138
|
-
return
|
|
138
|
+
return b.warn("[%s] fetch trajectory failed: %j", r.requestId, i, { message: c.message, status: c.status, code: c.code }), c;
|
|
139
139
|
let f = -1;
|
|
140
140
|
const m = p(`${(y = (w = c.data) == null ? void 0 : w[0]) == null ? void 0 : y.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
141
141
|
return (v = c.data) == null || v.forEach((g) => {
|
|
@@ -177,10 +177,10 @@ class J extends V {
|
|
|
177
177
|
usertoken: this.token
|
|
178
178
|
}
|
|
179
179
|
}, s = await Y.post(a, o).json();
|
|
180
|
-
|
|
180
|
+
b.info("[%s] fetch realtime position from: %s - %j", n.requestId, a, o);
|
|
181
181
|
const t = s == null ? void 0 : s.list;
|
|
182
182
|
if (!t)
|
|
183
|
-
return
|
|
183
|
+
return b.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;
|
|
@@ -223,7 +223,7 @@ class J extends V {
|
|
|
223
223
|
}
|
|
224
224
|
};
|
|
225
225
|
let s = await Y.post(a, o).json();
|
|
226
|
-
|
|
226
|
+
b.info("[%s] fetch vessel props from: %s - %j", n.requestId, a, o), s instanceof Array && (s = s[0]);
|
|
227
227
|
for (const r in s)
|
|
228
228
|
!isNaN(s[r]) && Number(s[r]) !== 1 / 0 && (s[r] = Number(s[r]));
|
|
229
229
|
const t = {
|
|
@@ -235,7 +235,7 @@ class J extends V {
|
|
|
235
235
|
breadth: s.b,
|
|
236
236
|
draught: s.dr
|
|
237
237
|
};
|
|
238
|
-
return a = "https://www.hifleet.com/hifleetapi/sameShipSearch.do", s = await Y.post(a, o).json(),
|
|
238
|
+
return a = "https://www.hifleet.com/hifleetapi/sameShipSearch.do", s = await Y.post(a, o).json(), b.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
240
|
async trajectory(e, n, a, o, s = !0, t = {}) {
|
|
241
241
|
var g, I, N;
|
|
@@ -254,13 +254,13 @@ class J extends V {
|
|
|
254
254
|
usertoken: this.token
|
|
255
255
|
}
|
|
256
256
|
}, m = "https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token", d = await Y.get(m, f).json();
|
|
257
|
-
|
|
258
|
-
let
|
|
259
|
-
d && (
|
|
257
|
+
b.info("[%s] fetch trajectory from: %s - %j", t.requestId, m, f);
|
|
258
|
+
let j;
|
|
259
|
+
d && (j = ((I = (g = d.ships) == null ? void 0 : g.offors) == null ? void 0 : I.ship) || [], j.length || b.warn("[%s] fetch trajectory failed: %j", t.requestId, d));
|
|
260
260
|
const w = [];
|
|
261
261
|
let y = -1;
|
|
262
|
-
const v = p(`${(N =
|
|
263
|
-
for (const l of
|
|
262
|
+
const v = p(`${(N = j == null ? void 0 : j[0]) == null ? void 0 : N.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
263
|
+
for (const l of j) {
|
|
264
264
|
for (const x in l)
|
|
265
265
|
!isNaN(l[x]) && Number(l[x]) !== 1 / 0 && (l[x] = Number(l[x]));
|
|
266
266
|
const E = p(`${l.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
@@ -302,7 +302,7 @@ class Q extends V {
|
|
|
302
302
|
enc: 1
|
|
303
303
|
}
|
|
304
304
|
}, o = "https://api.shipxy.com/apicall/GetSingleShip", s = await Y.get(o, a).json();
|
|
305
|
-
if (
|
|
305
|
+
if (b.info("[%s] fetch realtime position from: %s - %j", n.requestId, o, a), (s == null ? void 0 : s.status) !== 0)
|
|
306
306
|
return s;
|
|
307
307
|
const t = s.data[0];
|
|
308
308
|
for (const f in t)
|
|
@@ -343,9 +343,9 @@ class Q extends V {
|
|
|
343
343
|
etm: h.unix()
|
|
344
344
|
}
|
|
345
345
|
}, m = await Y.get(c, f).json();
|
|
346
|
-
if (
|
|
346
|
+
if (b.info("[%s] fetch trajectory from: %s - %j", t.requestId, c, f), (m == null ? void 0 : m.status) !== 0)
|
|
347
347
|
return m;
|
|
348
|
-
const d = m == null ? void 0 : m.points,
|
|
348
|
+
const d = m == null ? void 0 : m.points, j = [], w = p.unix((v = d[0]) == null ? void 0 : v.utc);
|
|
349
349
|
let y = -1;
|
|
350
350
|
for (const g of d) {
|
|
351
351
|
const I = p.unix(g.utc), N = {
|
|
@@ -360,9 +360,9 @@ class Q extends V {
|
|
|
360
360
|
method: "trajectory",
|
|
361
361
|
vendor: "shipxy"
|
|
362
362
|
}, l = Math.floor(I.diff(w, "minute", !0) / (o || 1));
|
|
363
|
-
l !== y && (y = l,
|
|
363
|
+
l !== y && (y = l, j.push(N));
|
|
364
364
|
}
|
|
365
|
-
return
|
|
365
|
+
return j;
|
|
366
366
|
}
|
|
367
367
|
}
|
|
368
368
|
class X extends V {
|
|
@@ -380,7 +380,7 @@ class X extends V {
|
|
|
380
380
|
mmsiList: e
|
|
381
381
|
}
|
|
382
382
|
}, o = "https://api3.myships.com/sp/ships/getShipIdByMMSI", s = await Y.post(o, a).json();
|
|
383
|
-
return
|
|
383
|
+
return b.info("[%s] fetch ship id from: %s - %j", n.requestId, o, a), s.code !== "0" ? s : s.data[0].shipId;
|
|
384
384
|
}
|
|
385
385
|
async getShipInfo(e, n = {}) {
|
|
386
386
|
const a = {
|
|
@@ -391,11 +391,11 @@ class X extends V {
|
|
|
391
391
|
shipId: e
|
|
392
392
|
}
|
|
393
393
|
}, o = "https://api3.myships.com/sp/ships/aissta", s = await Y.post(o, a).json();
|
|
394
|
-
if (
|
|
394
|
+
if (b.info("[%s] fetch ship info from: %s - %j", n.requestId, o, a), s.code !== "0")
|
|
395
395
|
return s;
|
|
396
396
|
const t = s.data;
|
|
397
397
|
let r = t.imo;
|
|
398
|
-
return e === "407170" && (r = "9198379",
|
|
398
|
+
return e === "407170" && (r = "9198379", b.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,
|
|
@@ -414,7 +414,7 @@ class X extends V {
|
|
|
414
414
|
shipId: a
|
|
415
415
|
}
|
|
416
416
|
}, t = "https://api3.myships.com/sp/ships/position/latest", r = await Y.post(t, s).json();
|
|
417
|
-
|
|
417
|
+
b.info("[%s] fetch realtime position from: %s - %j", n.requestId, t, s);
|
|
418
418
|
const i = r.data[0];
|
|
419
419
|
for (const d in i)
|
|
420
420
|
!isNaN(i[d]) && Number(i[d]) !== 1 / 0 && (i[d] = Number(i[d]));
|
|
@@ -455,13 +455,13 @@ class X extends V {
|
|
|
455
455
|
endTime: a
|
|
456
456
|
}
|
|
457
457
|
}, c = "https://api3.myships.com/sp/ships/position/history", f = await Y.post(c, h).json();
|
|
458
|
-
if (
|
|
459
|
-
return
|
|
458
|
+
if (b.info("[%s] fetch trajectory from: %s - %j", i.requestId, c, h), f.code !== "0")
|
|
459
|
+
return b.warn("[%s] invoke myship trajectory failed: %j", i.requestId, f), f;
|
|
460
460
|
const m = f.data;
|
|
461
461
|
for (const y in m)
|
|
462
462
|
!isNaN(m[y]) && Number(m[y]) !== 1 / 0 && (m[y] = Number(m[y]));
|
|
463
463
|
const d = p.unix((w = m[0]) == null ? void 0 : w.posTime);
|
|
464
|
-
let
|
|
464
|
+
let j = -1;
|
|
465
465
|
for (const y of m) {
|
|
466
466
|
const v = p.unix(y.posTime), g = {
|
|
467
467
|
imo: o == null ? void 0 : o.imo,
|
|
@@ -477,7 +477,7 @@ class X extends V {
|
|
|
477
477
|
method: "trajectory",
|
|
478
478
|
vendor: "myship"
|
|
479
479
|
}, I = Math.floor(v.diff(d, "minute", !0) / (t || 1));
|
|
480
|
-
I !==
|
|
480
|
+
I !== j && (j = I, r.push(g));
|
|
481
481
|
}
|
|
482
482
|
return r;
|
|
483
483
|
}
|
|
@@ -496,7 +496,7 @@ class L {
|
|
|
496
496
|
parsePrinciple(u, e = {}) {
|
|
497
497
|
var t, r, i;
|
|
498
498
|
$.info("[%s] parse rule: %s", e.requestId, u);
|
|
499
|
-
const n = new RegExp("(?<=\\[)(.+)(
|
|
499
|
+
const n = new RegExp("(?<=\\[)(.+)(?=])", "g"), a = u.match(n) ? (t = u.match(n)) == null ? void 0 : t[0] : void 0, o = a == null ? void 0 : a.split(";");
|
|
500
500
|
if (!o)
|
|
501
501
|
return;
|
|
502
502
|
const s = {};
|
|
@@ -521,9 +521,15 @@ class L {
|
|
|
521
521
|
parseRule(u, e = {}) {
|
|
522
522
|
var s;
|
|
523
523
|
$.info("[%s] parse rule: %s", e.requestId, u), u = u.startsWith("[") ? u : `[${u}`, u = u.endsWith("]") ? u : `${u}]`;
|
|
524
|
-
const n = new RegExp("(?<=\\[)(.+?)(
|
|
524
|
+
const n = new RegExp("(?<=\\[)(.+?)(?=])", "g"), a = (s = u == null ? void 0 : u.match(n)) == null ? void 0 : s[0], o = a == null ? void 0 : a.split(",");
|
|
525
525
|
if (o)
|
|
526
|
-
return {
|
|
526
|
+
return {
|
|
527
|
+
operator: o[0],
|
|
528
|
+
number: Number.isNaN(Number(o[1])) ? o[1] : Number(o[1]),
|
|
529
|
+
level: o[2],
|
|
530
|
+
time: Number(o[3]),
|
|
531
|
+
key: o[4]
|
|
532
|
+
};
|
|
527
533
|
}
|
|
528
534
|
/**
|
|
529
535
|
* 检查航路点天气
|
|
@@ -532,9 +538,9 @@ class L {
|
|
|
532
538
|
* @param options
|
|
533
539
|
*/
|
|
534
540
|
checkWeather(u, e, n = {}) {
|
|
535
|
-
var d,
|
|
541
|
+
var d, j, w, y, v, g, I, N, l, E, _, R, H, S, x;
|
|
536
542
|
let a = 0, o = 0, s = 0, t = 0;
|
|
537
|
-
const r = Math.round(((
|
|
543
|
+
const r = Math.round(((j = (d = e == null ? void 0 : e.SEVERE) == null ? void 0 : d.sigWave) == null ? void 0 : j.number) * 1.6 * 100) / 100, i = (y = (w = e == null ? void 0 : e.SEVERE) == null ? void 0 : w.sigWave) == null ? void 0 : y.number, h = (g = (v = e == null ? void 0 : e.HEAVY) == null ? void 0 : v.sigWave) == null ? void 0 : g.number, c = Math.round((((N = (I = e == null ? void 0 : e.SEVERE) == null ? void 0 : I.wind) == null ? void 0 : N.number) + 2) * 100) / 100, f = (E = (l = e == null ? void 0 : e.SEVERE) == null ? void 0 : l.wind) == null ? void 0 : E.number, m = (R = (_ = e == null ? void 0 : e.HEAVY) == null ? void 0 : _.wind) == null ? void 0 : R.number;
|
|
538
544
|
for (let A = 0; A < (u == null ? void 0 : u.length); A++) {
|
|
539
545
|
const k = u[A], T = (S = (H = k == null ? void 0 : k.meteo) == null ? void 0 : H.wave) == null ? void 0 : S.sig, D = (x = k == null ? void 0 : k.meteo) == null ? void 0 : x.wind, P = A ? p(k.eta).diff(p(u[A - 1].eta), "hour", !0) : 0;
|
|
540
546
|
t = P > t ? P : t, $.info("[%s] check sig.wave: %j", n.requestId, { ...T, dgThd4Wv: r, svThd4Wv: i, hvThd4Wv: h }), (T == null ? void 0 : T.height) >= r ? k.isDangerous = !0 : (T == null ? void 0 : T.height) >= i ? k.isSevere = !0 : (T == null ? void 0 : T.height) >= h && (k.isHeavy = !0), $.info("[%s] check wind: %j", n.requestId, { ...D, dgThd4Wd: c, svThd4Wd: f, hvThd4Wd: m }), (D == null ? void 0 : D.scale) >= c ? (k.isDangerous = !0, delete k.isSevere, delete k.isHeavy) : (D == null ? void 0 : D.scale) > f ? (k.isDangerous || (k.isSevere = !0), delete k.isHeavy) : (D == null ? void 0 : D.scale) === m && !k.isDangerous && !k.isSevere && (k.isHeavy = !0), a += k.isDangerous ? P : 0, o += k.isSevere ? P : 0, s += k.isHeavy ? P : 0;
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(j,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("got"),require("@log4js-node/log4js-api"),require("moment")):typeof define=="function"&&define.amd?define(["exports","got","@log4js-node/log4js-api","moment"],y):(j=typeof globalThis<"u"?globalThis:j||self,y(j["idm-plugin-rabbitmq"]={},j.got,j["@log4js-node/log4js-api"],j.moment))})(this,function(j,y,E,g){"use strict";var U=Object.defineProperty;var J=(j,y,E)=>y in j?U(j,y,{enumerable:!0,configurable:!0,writable:!0,value:E}):j[y]=E;var A=(j,y,E)=>(J(j,typeof y!="symbol"?y+"":y,E),E);const I=E.getLogger("vessel");class V{parseStatus(p){let e,a;switch(p){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 L extends V{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();I.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:g().utc().format()})}async realTimePosition(e,a={}){var d,c,l;(!this.token||g().diff(g(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}};I.info("[%s] fetch realtime position from: %s - %j",a.requestId,n,o);const s=await y.get(n,o).json();if(s.code)return I.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 u in t)!isNaN(t[u])&&Number(t[u])!==1/0&&(t[u]=Number(t[u]));const r=g(`${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||g().diff(g(this.token.issuedAt),"seconds")>this.token.expiresIn-300)&&await this.authToken(t);const r=await this.realTimePosition(e,t),i=g(a),d=g(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 h,b,Y,k,w;const i="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",d={headers:{Authorization:`${(h=this.token)==null?void 0:h.tokenType} ${(b=this.token)==null?void 0:b.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")}};I.info("[%s] fetch trajectory from: %s - %j",r.requestId,i,d);const c=await y.post(i,d).json();if(c.code)return I.warn("[%s] fetch trajectory failed: %j",r.requestId,i,{message:c.message,status:c.status,code:c.code}),c;let l=-1;const u=g(`${(k=(Y=c.data)==null?void 0:Y[0])==null?void 0:k.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return(w=c.data)==null||w.forEach(m=>{for(const T in m)!isNaN(m[T])&&Number(m[T])!==1/0&&(m[T]=Number(m[T]));const v=g(`${m.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),N=m.eta?g(`${m.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"):void 0,f=m.status,{labelCn:q,labelEn:R}=this.parseStatus(f),P={mmsi:m.mmsi,imo:o==null?void 0:o.imo,lat:m.lat,lng:m.lon,sog:m.sog,cog:m.cog,hdg:m.hdg,draught:m.draught,status:f,eta:N==null?void 0:N.unix(),destination:m.dest,positionTime:v.unix(),labelCn:q,labelEn:R,method:"trajectory",vendor:"myVessel",utc:v.utc().format()},x=Math.floor(v.diff(u,"minute",!0)/(s||1));x!==l&&(l=x,t.push(P))}),t}}class z extends V{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();I.info("[%s] fetch realtime position from: %s - %j",a.requestId,n,o);const t=s==null?void 0:s.list;if(!t)return I.warn("[%s] fetch realtime position failed: %j",a.requestId,n,s),s;for(const u in t)!isNaN(t[u])&&Number(t[u])!==1/0&&(t[u]=Number(t[u]));t.status=t.sp>3?0:1;const r=t.status,{labelCn:i,labelEn:d}=this.parseStatus(r),c=g(`${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)?g(`${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();I.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(),I.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 m,v,N;const r=await this.realTimePosition(e,t);let i=g(a);const d=g(n),c=g();if(s){let f=d.diff(i,"d",!0);f<0?i=d.clone().subtract(40,"d"):f<30?i.subtract(10,"d"):f<60?i.subtract(5,"d"):i=d.clone().subtract(80,"d"),f=c.diff(d,"d",!0),d.add(f>10?240:f*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}},u="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",h=await y.get(u,l).json();I.info("[%s] fetch trajectory from: %s - %j",t.requestId,u,l);let b;h&&(b=((v=(m=h.ships)==null?void 0:m.offors)==null?void 0:v.ship)||[],b.length||I.warn("[%s] fetch trajectory failed: %j",t.requestId,h));const Y=[];let k=-1;const w=g(`${(N=b==null?void 0:b[0])==null?void 0:N.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const f of b){for(const _ in f)!isNaN(f[_])&&Number(f[_])!==1/0&&(f[_]=Number(f[_]));const q=g(`${f.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");f.status=f.sp>4?0:1;const{labelEn:R,labelCn:P}=this.parseStatus(f.status),x={mmsi:f.m,name:f.n,imo:r==null?void 0:r.imo,lat:f.la,lng:f.lo,draught:f.draught,sog:f.sp,cog:f.co,hdg:f.hdg,positionTime:q.unix(),utc:q.utc().format(),status:f.status,labelCn:P,labelEn:R,method:"trajectory",vendor:"hifleet"},T=Math.floor(q.diff(w,"minute",!0)/(o||1));T!==k&&(k=T,Y.push(x))}return Y}}class F extends V{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(I.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=g.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 w;const r=await this.realTimePosition(e,t),i=g(a),d=g(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()}},u=await y.get(c,l).json();if(I.info("[%s] fetch trajectory from: %s - %j",t.requestId,c,l),(u==null?void 0:u.status)!==0)return u;const h=u==null?void 0:u.points,b=[],Y=g.unix((w=h[0])==null?void 0:w.utc);let k=-1;for(const m of h){const v=g.unix(m.utc),N={imo:r==null?void 0:r.imo,mmsi:e,sog:Math.round(m.sog*3600/1e3/1852*100)/100,cog:Math.round(m.cog/100*100)/100,lat:Math.round(m.lat/1e6*1e5)/1e5,lng:Math.round(m.lon/1e6*1e5)/1e5,positionTime:v.unix(),utc:v.utc().format(),method:"trajectory",vendor:"shipxy"},f=Math.floor(v.diff(Y,"minute",!0)/(o||1));f!==k&&(k=f,b.push(N))}return b}}class G extends V{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 I.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(I.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",I.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();I.info("[%s] fetch realtime position from: %s - %j",a.requestId,t,s);const i=r.data[0];for(const h in i)!isNaN(i[h])&&Number(i[h])!==1/0&&(i[h]=Number(i[h]));const{labelCn:d,labelEn:c}=await this.parseStatus(i.aisNavStatus),l=g.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=g(a),i=g(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(I.info("[%s] fetch trajectory from: %s - %j",i.requestId,c,d),l.code!=="0")return I.warn("[%s] invoke myship trajectory failed: %j",i.requestId,l),l;const u=l.data;for(const k in u)!isNaN(u[k])&&Number(u[k])!==1/0&&(u[k]=Number(u[k]));const h=g.unix((Y=u[0])==null?void 0:Y.posTime);let b=-1;for(const k of u){const w=g.unix(k.posTime),m={imo:o==null?void 0:o.imo,mmsi:s,lat:Math.round(k.lat/1e4/60*1e5)/1e5,lng:Math.round(k.lon/1e4/60*1e5)/1e5,sog:Math.round(k.sog/10*100)/100,cog:Math.round(k.cog/10*100)/100,hdg:Math.round(k.heading*100)/100,rot:Math.round(k.rot*100)/100,positionTime:w.unix(),utc:w.utc().format(),method:"trajectory",vendor:"myship"},v=Math.floor(w.diff(h,"minute",!0)/(t||1));v!==b&&(b=v,r.push(m))}return r}}const O=E.getLogger("vessel");var C=(S=>(S.NOTICE="NOTICE",S.WARN="WARN",S.HEAVY="HEAVY",S.SEVERE="SEVERE",S.ERROR="ERROR",S.FATAL="FATAL",S))(C||{});class K{parsePrinciple(p,e={}){var t,r,i;O.info("[%s] parse rule: %s",e.requestId,p);const a=new RegExp("(?<=\\[)(.+)(?=\\])","g"),n=p.match(a)?(t=p.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,u=c.length;l<u;l++){const h=this.parseRule(c[l]);h&&(s[h.level]?h.key?s[h.level][h==null?void 0:h.key]=h:s[h.level]=h:h.key?s[h.level]={[h==null?void 0:h.key]:h}:s[h.level]=h)}}return s}parseRule(p,e={}){var s;O.info("[%s] parse rule: %s",e.requestId,p),p=p.startsWith("[")?p:`[${p}`,p=p.endsWith("]")?p:`${p}]`;const a=new RegExp("(?<=\\[)(.+?)(?=\\])","g"),n=(s=p==null?void 0:p.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(p,e,a={}){var h,b,Y,k,w,m,v,N,f,q,R,P,x,T,_;let n=0,o=0,s=0,t=0;const r=Math.round(((b=(h=e==null?void 0:e.SEVERE)==null?void 0:h.sigWave)==null?void 0:b.number)*1.6*100)/100,i=(k=(Y=e==null?void 0:e.SEVERE)==null?void 0:Y.sigWave)==null?void 0:k.number,d=(m=(w=e==null?void 0:e.HEAVY)==null?void 0:w.sigWave)==null?void 0:m.number,c=Math.round((((N=(v=e==null?void 0:e.SEVERE)==null?void 0:v.wind)==null?void 0:N.number)+2)*100)/100,l=(q=(f=e==null?void 0:e.SEVERE)==null?void 0:f.wind)==null?void 0:q.number,u=(P=(R=e==null?void 0:e.HEAVY)==null?void 0:R.wind)==null?void 0:P.number;for(let $=0;$<(p==null?void 0:p.length);$++){const M=p[$],H=(T=(x=M==null?void 0:M.meteo)==null?void 0:x.wave)==null?void 0:T.sig,D=(_=M==null?void 0:M.meteo)==null?void 0:_.wind,W=$?g(M.eta).diff(g(p[$-1].eta),"hour",!0):0;t=W>t?W:t,O.info("[%s] check sig.wave: %j",a.requestId,{...H,dgThd4Wv:r,svThd4Wv:i,hvThd4Wv:d}),(H==null?void 0:H.height)>=r?M.isDangerous=!0:(H==null?void 0:H.height)>=i?M.isSevere=!0:(H==null?void 0:H.height)>=d&&(M.isHeavy=!0),O.info("[%s] check wind: %j",a.requestId,{...D,dgThd4Wd:c,svThd4Wd:l,hvThd4Wd:u}),(D==null?void 0:D.scale)>=c?(M.isDangerous=!0,delete M.isSevere,delete M.isHeavy):(D==null?void 0:D.scale)>l?(M.isDangerous||(M.isSevere=!0),delete M.isHeavy):(D==null?void 0:D.scale)===u&&!M.isDangerous&&!M.isSevere&&(M.isHeavy=!0),n+=M.isDangerous?W:0,o+=M.isSevere?W:0,s+=M.isHeavy?W:0}return n=Math.round(n*100)/100,o=Math.round(o*100)/100,s=Math.round(s*100)/100,t=Math.round(t),{sample:p,dangerous:n,severe:o,heavy:s,step:t<3?3:t,wind:{dgThd4Wd:c,svThd4Wd:l,hvThd4Wd:u},sig:{dgThd4Wv:r,svThd4Wv:i,hvThd4Wv:d}}}}const B=new K;j.AISImpl=V,j.AlertHelper=K,j.AlertLevel=C,j.HifleetImpl=z,j.MyShipImpl=G,j.MyVesselImpl=L,j.ShipxyImpl=F,j.alertHelper=B,Object.defineProperty(j,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(j,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("got"),require("@log4js-node/log4js-api"),require("moment")):typeof define=="function"&&define.amd?define(["exports","got","@log4js-node/log4js-api","moment"],y):(j=typeof globalThis<"u"?globalThis:j||self,y(j["idm-plugin-rabbitmq"]={},j.got,j["@log4js-node/log4js-api"],j.moment))})(this,function(j,y,E,g){"use strict";var U=Object.defineProperty;var J=(j,y,E)=>y in j?U(j,y,{enumerable:!0,configurable:!0,writable:!0,value:E}):j[y]=E;var A=(j,y,E)=>(J(j,typeof y!="symbol"?y+"":y,E),E);const b=E.getLogger("vessel");class V{parseStatus(p){let e,a;switch(p){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 L extends V{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();b.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:g().utc().format()})}async realTimePosition(e,a={}){var d,c,l;(!this.token||g().diff(g(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}};b.info("[%s] fetch realtime position from: %s - %j",a.requestId,n,o);const s=await y.get(n,o).json();if(s.code)return b.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 u in t)!isNaN(t[u])&&Number(t[u])!==1/0&&(t[u]=Number(t[u]));const r=g(`${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||g().diff(g(this.token.issuedAt),"seconds")>this.token.expiresIn-300)&&await this.authToken(t);const r=await this.realTimePosition(e,t),i=g(a),d=g(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 h,I,Y,k,w;const i="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",d={headers:{Authorization:`${(h=this.token)==null?void 0:h.tokenType} ${(I=this.token)==null?void 0:I.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")}};b.info("[%s] fetch trajectory from: %s - %j",r.requestId,i,d);const c=await y.post(i,d).json();if(c.code)return b.warn("[%s] fetch trajectory failed: %j",r.requestId,i,{message:c.message,status:c.status,code:c.code}),c;let l=-1;const u=g(`${(k=(Y=c.data)==null?void 0:Y[0])==null?void 0:k.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return(w=c.data)==null||w.forEach(m=>{for(const T in m)!isNaN(m[T])&&Number(m[T])!==1/0&&(m[T]=Number(m[T]));const v=g(`${m.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),N=m.eta?g(`${m.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"):void 0,f=m.status,{labelCn:q,labelEn:R}=this.parseStatus(f),P={mmsi:m.mmsi,imo:o==null?void 0:o.imo,lat:m.lat,lng:m.lon,sog:m.sog,cog:m.cog,hdg:m.hdg,draught:m.draught,status:f,eta:N==null?void 0:N.unix(),destination:m.dest,positionTime:v.unix(),labelCn:q,labelEn:R,method:"trajectory",vendor:"myVessel",utc:v.utc().format()},x=Math.floor(v.diff(u,"minute",!0)/(s||1));x!==l&&(l=x,t.push(P))}),t}}class z extends V{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();b.info("[%s] fetch realtime position from: %s - %j",a.requestId,n,o);const t=s==null?void 0:s.list;if(!t)return b.warn("[%s] fetch realtime position failed: %j",a.requestId,n,s),s;for(const u in t)!isNaN(t[u])&&Number(t[u])!==1/0&&(t[u]=Number(t[u]));t.status=t.sp>3?0:1;const r=t.status,{labelCn:i,labelEn:d}=this.parseStatus(r),c=g(`${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)?g(`${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();b.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(),b.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 m,v,N;const r=await this.realTimePosition(e,t);let i=g(a);const d=g(n),c=g();if(s){let f=d.diff(i,"d",!0);f<0?i=d.clone().subtract(40,"d"):f<30?i.subtract(10,"d"):f<60?i.subtract(5,"d"):i=d.clone().subtract(80,"d"),f=c.diff(d,"d",!0),d.add(f>10?240:f*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}},u="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",h=await y.get(u,l).json();b.info("[%s] fetch trajectory from: %s - %j",t.requestId,u,l);let I;h&&(I=((v=(m=h.ships)==null?void 0:m.offors)==null?void 0:v.ship)||[],I.length||b.warn("[%s] fetch trajectory failed: %j",t.requestId,h));const Y=[];let k=-1;const w=g(`${(N=I==null?void 0:I[0])==null?void 0:N.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const f of I){for(const _ in f)!isNaN(f[_])&&Number(f[_])!==1/0&&(f[_]=Number(f[_]));const q=g(`${f.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");f.status=f.sp>4?0:1;const{labelEn:R,labelCn:P}=this.parseStatus(f.status),x={mmsi:f.m,name:f.n,imo:r==null?void 0:r.imo,lat:f.la,lng:f.lo,draught:f.draught,sog:f.sp,cog:f.co,hdg:f.hdg,positionTime:q.unix(),utc:q.utc().format(),status:f.status,labelCn:P,labelEn:R,method:"trajectory",vendor:"hifleet"},T=Math.floor(q.diff(w,"minute",!0)/(o||1));T!==k&&(k=T,Y.push(x))}return Y}}class F extends V{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(b.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=g.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 w;const r=await this.realTimePosition(e,t),i=g(a),d=g(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()}},u=await y.get(c,l).json();if(b.info("[%s] fetch trajectory from: %s - %j",t.requestId,c,l),(u==null?void 0:u.status)!==0)return u;const h=u==null?void 0:u.points,I=[],Y=g.unix((w=h[0])==null?void 0:w.utc);let k=-1;for(const m of h){const v=g.unix(m.utc),N={imo:r==null?void 0:r.imo,mmsi:e,sog:Math.round(m.sog*3600/1e3/1852*100)/100,cog:Math.round(m.cog/100*100)/100,lat:Math.round(m.lat/1e6*1e5)/1e5,lng:Math.round(m.lon/1e6*1e5)/1e5,positionTime:v.unix(),utc:v.utc().format(),method:"trajectory",vendor:"shipxy"},f=Math.floor(v.diff(Y,"minute",!0)/(o||1));f!==k&&(k=f,I.push(N))}return I}}class G extends V{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 b.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(b.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",b.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();b.info("[%s] fetch realtime position from: %s - %j",a.requestId,t,s);const i=r.data[0];for(const h in i)!isNaN(i[h])&&Number(i[h])!==1/0&&(i[h]=Number(i[h]));const{labelCn:d,labelEn:c}=await this.parseStatus(i.aisNavStatus),l=g.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=g(a),i=g(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(b.info("[%s] fetch trajectory from: %s - %j",i.requestId,c,d),l.code!=="0")return b.warn("[%s] invoke myship trajectory failed: %j",i.requestId,l),l;const u=l.data;for(const k in u)!isNaN(u[k])&&Number(u[k])!==1/0&&(u[k]=Number(u[k]));const h=g.unix((Y=u[0])==null?void 0:Y.posTime);let I=-1;for(const k of u){const w=g.unix(k.posTime),m={imo:o==null?void 0:o.imo,mmsi:s,lat:Math.round(k.lat/1e4/60*1e5)/1e5,lng:Math.round(k.lon/1e4/60*1e5)/1e5,sog:Math.round(k.sog/10*100)/100,cog:Math.round(k.cog/10*100)/100,hdg:Math.round(k.heading*100)/100,rot:Math.round(k.rot*100)/100,positionTime:w.unix(),utc:w.utc().format(),method:"trajectory",vendor:"myship"},v=Math.floor(w.diff(h,"minute",!0)/(t||1));v!==I&&(I=v,r.push(m))}return r}}const O=E.getLogger("vessel");var C=(S=>(S.NOTICE="NOTICE",S.WARN="WARN",S.HEAVY="HEAVY",S.SEVERE="SEVERE",S.ERROR="ERROR",S.FATAL="FATAL",S))(C||{});class K{parsePrinciple(p,e={}){var t,r,i;O.info("[%s] parse rule: %s",e.requestId,p);const a=new RegExp("(?<=\\[)(.+)(?=])","g"),n=p.match(a)?(t=p.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,u=c.length;l<u;l++){const h=this.parseRule(c[l]);h&&(s[h.level]?h.key?s[h.level][h==null?void 0:h.key]=h:s[h.level]=h:h.key?s[h.level]={[h==null?void 0:h.key]:h}:s[h.level]=h)}}return s}parseRule(p,e={}){var s;O.info("[%s] parse rule: %s",e.requestId,p),p=p.startsWith("[")?p:`[${p}`,p=p.endsWith("]")?p:`${p}]`;const a=new RegExp("(?<=\\[)(.+?)(?=])","g"),n=(s=p==null?void 0:p.match(a))==null?void 0:s[0],o=n==null?void 0:n.split(",");if(o)return{operator:o[0],number:Number.isNaN(Number(o[1]))?o[1]:Number(o[1]),level:o[2],time:Number(o[3]),key:o[4]}}checkWeather(p,e,a={}){var h,I,Y,k,w,m,v,N,f,q,R,P,x,T,_;let n=0,o=0,s=0,t=0;const r=Math.round(((I=(h=e==null?void 0:e.SEVERE)==null?void 0:h.sigWave)==null?void 0:I.number)*1.6*100)/100,i=(k=(Y=e==null?void 0:e.SEVERE)==null?void 0:Y.sigWave)==null?void 0:k.number,d=(m=(w=e==null?void 0:e.HEAVY)==null?void 0:w.sigWave)==null?void 0:m.number,c=Math.round((((N=(v=e==null?void 0:e.SEVERE)==null?void 0:v.wind)==null?void 0:N.number)+2)*100)/100,l=(q=(f=e==null?void 0:e.SEVERE)==null?void 0:f.wind)==null?void 0:q.number,u=(P=(R=e==null?void 0:e.HEAVY)==null?void 0:R.wind)==null?void 0:P.number;for(let $=0;$<(p==null?void 0:p.length);$++){const M=p[$],H=(T=(x=M==null?void 0:M.meteo)==null?void 0:x.wave)==null?void 0:T.sig,D=(_=M==null?void 0:M.meteo)==null?void 0:_.wind,W=$?g(M.eta).diff(g(p[$-1].eta),"hour",!0):0;t=W>t?W:t,O.info("[%s] check sig.wave: %j",a.requestId,{...H,dgThd4Wv:r,svThd4Wv:i,hvThd4Wv:d}),(H==null?void 0:H.height)>=r?M.isDangerous=!0:(H==null?void 0:H.height)>=i?M.isSevere=!0:(H==null?void 0:H.height)>=d&&(M.isHeavy=!0),O.info("[%s] check wind: %j",a.requestId,{...D,dgThd4Wd:c,svThd4Wd:l,hvThd4Wd:u}),(D==null?void 0:D.scale)>=c?(M.isDangerous=!0,delete M.isSevere,delete M.isHeavy):(D==null?void 0:D.scale)>l?(M.isDangerous||(M.isSevere=!0),delete M.isHeavy):(D==null?void 0:D.scale)===u&&!M.isDangerous&&!M.isSevere&&(M.isHeavy=!0),n+=M.isDangerous?W:0,o+=M.isSevere?W:0,s+=M.isHeavy?W:0}return n=Math.round(n*100)/100,o=Math.round(o*100)/100,s=Math.round(s*100)/100,t=Math.round(t),{sample:p,dangerous:n,severe:o,heavy:s,step:t<3?3:t,wind:{dgThd4Wd:c,svThd4Wd:l,hvThd4Wd:u},sig:{dgThd4Wv:r,svThd4Wv:i,hvThd4Wv:d}}}}const B=new K;j.AISImpl=V,j.AlertHelper=K,j.AlertLevel=C,j.HifleetImpl=z,j.MyShipImpl=G,j.MyVesselImpl=L,j.ShipxyImpl=F,j.alertHelper=B,Object.defineProperty(j,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.1.
|
|
4
|
+
"version": "1.1.9",
|
|
5
5
|
"description": "idm plugin for vessel",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"keywords": [
|
|
@@ -27,6 +27,8 @@
|
|
|
27
27
|
"release": "yarn build && yarn publish --access public"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
+
"@idm-plugin/geo": "^1.2.7",
|
|
31
|
+
"@idm-plugin/meteo": "^0.0.2",
|
|
30
32
|
"@log4js-node/log4js-api": "^1.0.2",
|
|
31
33
|
"got": "11",
|
|
32
34
|
"moment": "^2.30.1"
|