@idm-plugin/vessel 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/ais/src/index.d.ts +74 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +296 -0
- package/dist/index.umd.cjs +1 -0
- package/package.json +66 -0
package/README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { RequestOptions } from '../../index';
|
|
2
|
+
/**
|
|
3
|
+
* AIS记录
|
|
4
|
+
*/
|
|
5
|
+
export interface AISRecord {
|
|
6
|
+
mmsi?: number;
|
|
7
|
+
name?: string;
|
|
8
|
+
imo?: number;
|
|
9
|
+
callSign?: string;
|
|
10
|
+
lat?: number;
|
|
11
|
+
lng?: number;
|
|
12
|
+
length?: number;
|
|
13
|
+
width?: number;
|
|
14
|
+
draught?: number;
|
|
15
|
+
sog?: number;
|
|
16
|
+
cog?: number;
|
|
17
|
+
hdg?: number;
|
|
18
|
+
rot?: number;
|
|
19
|
+
eta?: number;
|
|
20
|
+
destination?: string;
|
|
21
|
+
positionTime?: number;
|
|
22
|
+
status?: number;
|
|
23
|
+
labelCn?: string;
|
|
24
|
+
labelEn?: string;
|
|
25
|
+
method?: string;
|
|
26
|
+
vendor?: string;
|
|
27
|
+
deleted?: boolean;
|
|
28
|
+
utc?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface VesselRecord {
|
|
31
|
+
mmsi?: number;
|
|
32
|
+
name?: string;
|
|
33
|
+
imo?: number;
|
|
34
|
+
callSign?: string;
|
|
35
|
+
length?: number;
|
|
36
|
+
breadth?: number;
|
|
37
|
+
draught?: number;
|
|
38
|
+
deadweight?: number;
|
|
39
|
+
vendor?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface AuthToken {
|
|
42
|
+
accessToken: string;
|
|
43
|
+
tokenType?: string;
|
|
44
|
+
expiresIn?: number;
|
|
45
|
+
scope?: string;
|
|
46
|
+
jti?: string;
|
|
47
|
+
issuedAt?: string;
|
|
48
|
+
}
|
|
49
|
+
export declare class AISImpl {
|
|
50
|
+
/**
|
|
51
|
+
* 解析AIS状态码
|
|
52
|
+
* @param status
|
|
53
|
+
*/
|
|
54
|
+
parseStatus(status: number): {
|
|
55
|
+
labelCn: string;
|
|
56
|
+
labelEn: string;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export declare class MyVesselImpl extends AISImpl {
|
|
60
|
+
private readonly clientId;
|
|
61
|
+
private readonly clientSecret;
|
|
62
|
+
private token;
|
|
63
|
+
constructor(clientId: string, clientSecret: string);
|
|
64
|
+
authToken(options?: RequestOptions): Promise<void>;
|
|
65
|
+
realTimePosition(mmsi: number, options?: RequestOptions): Promise<AISRecord>;
|
|
66
|
+
trajectory(mmsi: number, startTime: string, endTime: string, offset: number, scale?: boolean, options?: RequestOptions): Promise<any>;
|
|
67
|
+
}
|
|
68
|
+
export declare class HifleetImpl extends AISImpl {
|
|
69
|
+
private readonly token;
|
|
70
|
+
constructor(token: string);
|
|
71
|
+
realTimePosition(mmsi: number, options?: RequestOptions): Promise<AISRecord>;
|
|
72
|
+
search(kw: string, options?: RequestOptions): Promise<VesselRecord>;
|
|
73
|
+
trajectory(mmsi: number, startTime: string, endTime: string, offset: number, scale?: boolean, options?: RequestOptions): Promise<AISRecord[]>;
|
|
74
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
var $ = Object.defineProperty;
|
|
2
|
+
var A = (Y, h, s) => h in Y ? $(Y, h, { enumerable: !0, configurable: !0, writable: !0, value: s }) : Y[h] = s;
|
|
3
|
+
var v = (Y, h, s) => (A(Y, typeof h != "symbol" ? h + "" : h, s), s);
|
|
4
|
+
import y from "got";
|
|
5
|
+
import * as P from "log4js";
|
|
6
|
+
import l from "moment";
|
|
7
|
+
const p = P.getLogger();
|
|
8
|
+
class _ {
|
|
9
|
+
/**
|
|
10
|
+
* 解析AIS状态码
|
|
11
|
+
* @param status
|
|
12
|
+
*/
|
|
13
|
+
parseStatus(h) {
|
|
14
|
+
let s, o;
|
|
15
|
+
switch (h) {
|
|
16
|
+
case 0:
|
|
17
|
+
s = "在航(主机推动)", o = "The engine is in use";
|
|
18
|
+
break;
|
|
19
|
+
case 1:
|
|
20
|
+
s = "锚泊", o = "Anchored";
|
|
21
|
+
break;
|
|
22
|
+
case 2:
|
|
23
|
+
s = "失控", o = "Not operated";
|
|
24
|
+
break;
|
|
25
|
+
case 3:
|
|
26
|
+
s = "操纵受限", o = "Limited airworthiness";
|
|
27
|
+
break;
|
|
28
|
+
case 4:
|
|
29
|
+
s = "吃水受限", o = "Limited by ship's draft";
|
|
30
|
+
break;
|
|
31
|
+
case 5:
|
|
32
|
+
s = "靠泊", o = "Mooring";
|
|
33
|
+
break;
|
|
34
|
+
case 6:
|
|
35
|
+
s = "搁浅", o = "Stranded";
|
|
36
|
+
break;
|
|
37
|
+
case 7:
|
|
38
|
+
s = "捕捞作业", o = "Engaged in fishing";
|
|
39
|
+
break;
|
|
40
|
+
case 8:
|
|
41
|
+
s = "靠帆船提供动力", o = "Sailing";
|
|
42
|
+
break;
|
|
43
|
+
default:
|
|
44
|
+
s = "未定义", o = "Undefined";
|
|
45
|
+
}
|
|
46
|
+
return { labelCn: s, labelEn: o };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
class L extends _ {
|
|
50
|
+
constructor(s, o) {
|
|
51
|
+
super();
|
|
52
|
+
v(this, "clientId");
|
|
53
|
+
v(this, "clientSecret");
|
|
54
|
+
v(this, "token");
|
|
55
|
+
this.clientId = s, this.clientSecret = o;
|
|
56
|
+
}
|
|
57
|
+
async authToken(s = {}) {
|
|
58
|
+
const o = "https://svc.data.myvessel.cn/ada/oauth/token", c = {
|
|
59
|
+
searchParams: {
|
|
60
|
+
client_id: this.clientId,
|
|
61
|
+
client_secret: this.clientSecret,
|
|
62
|
+
grant_type: "client_credentials"
|
|
63
|
+
}
|
|
64
|
+
}, a = await y.post(o, c).json();
|
|
65
|
+
p.info("[%s] fetch access token from: %s - %j", s.requestId, o, a), a.error || (this.token = {
|
|
66
|
+
accessToken: a.access_token,
|
|
67
|
+
tokenType: a.token_type,
|
|
68
|
+
expiresIn: a.expires_in,
|
|
69
|
+
scope: a.scope,
|
|
70
|
+
jti: a.jti,
|
|
71
|
+
issuedAt: l().utc().format()
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
async realTimePosition(s, o = {}) {
|
|
75
|
+
var d, f, g;
|
|
76
|
+
(!this.token || l().diff(l(this.token.issuedAt), "seconds") > ((d = this.token) == null ? void 0 : d.expiresIn) - 300) && await this.authToken(o);
|
|
77
|
+
const c = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit", a = {
|
|
78
|
+
headers: {
|
|
79
|
+
Authorization: `${(f = this.token) == null ? void 0 : f.tokenType} ${(g = this.token) == null ? void 0 : g.accessToken}`
|
|
80
|
+
},
|
|
81
|
+
searchParams: { mmsi: s }
|
|
82
|
+
};
|
|
83
|
+
p.info("[%s] fetch realtime position from: %s - %j", o.requestId, c, a);
|
|
84
|
+
const e = await y.get(c, a).json();
|
|
85
|
+
if (e.code)
|
|
86
|
+
return p.warn("[%s] fetch realtime position failed: %j", o.requestId, c, { message: e.message, status: e.status, code: e.code }), e;
|
|
87
|
+
const t = e.data;
|
|
88
|
+
for (const r in t)
|
|
89
|
+
!isNaN(t[r]) && Number(t[r]) !== 1 / 0 && (t[r] = Number(t[r]));
|
|
90
|
+
const m = l(`${t.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
91
|
+
return {
|
|
92
|
+
mmsi: t.mmsi,
|
|
93
|
+
name: t.vesselName,
|
|
94
|
+
imo: t.imo,
|
|
95
|
+
callSign: t.callsign,
|
|
96
|
+
lat: t.lat,
|
|
97
|
+
lng: t.lon,
|
|
98
|
+
length: t.length,
|
|
99
|
+
width: t.width,
|
|
100
|
+
draught: t.currDraught,
|
|
101
|
+
sog: t.sog,
|
|
102
|
+
cog: t.cog,
|
|
103
|
+
hdg: t.hdg,
|
|
104
|
+
rot: t.rot,
|
|
105
|
+
eta: t.eta,
|
|
106
|
+
destination: t.dest,
|
|
107
|
+
positionTime: m.unix(),
|
|
108
|
+
status: t.status,
|
|
109
|
+
labelCn: t.statusNameCn,
|
|
110
|
+
labelEn: t.statusNameEn,
|
|
111
|
+
method: "position",
|
|
112
|
+
vendor: "myVessel",
|
|
113
|
+
utc: m.utc().format()
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
async trajectory(s, o, c, a, e = !0, t = {}) {
|
|
117
|
+
var H, T, D;
|
|
118
|
+
(!this.token || l().diff(l(this.token.issuedAt), "seconds") > this.token.expiresIn - 300) && await this.authToken(t);
|
|
119
|
+
const m = await this.realTimePosition(s, t), u = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/track";
|
|
120
|
+
let d = l(o);
|
|
121
|
+
const f = l(c);
|
|
122
|
+
if (e) {
|
|
123
|
+
const n = f.diff(d, "d", !0);
|
|
124
|
+
(n < 0 || n > 30) && (d = f.clone().subtract(30, "d"));
|
|
125
|
+
}
|
|
126
|
+
const g = {
|
|
127
|
+
headers: {
|
|
128
|
+
Authorization: `${(H = this.token) == null ? void 0 : H.tokenType} ${(T = this.token) == null ? void 0 : T.accessToken}`
|
|
129
|
+
},
|
|
130
|
+
json: {
|
|
131
|
+
mmsi: s,
|
|
132
|
+
startTime: d.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),
|
|
133
|
+
endTime: f.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
p.info("[%s] fetch trajectory from: %s - %j", t.requestId, u, g);
|
|
137
|
+
const r = await y.post(u, g).json();
|
|
138
|
+
if (r.code)
|
|
139
|
+
return p.warn("[%s] fetch trajectory failed: %j", t.requestId, u, { message: r.message, status: r.status, code: r.code }), r;
|
|
140
|
+
let j = -1;
|
|
141
|
+
const b = l(`${(D = r.data[0]) == null ? void 0 : D.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00"), N = [];
|
|
142
|
+
return r.data.forEach((n) => {
|
|
143
|
+
for (const k in n)
|
|
144
|
+
!isNaN(n[k]) && Number(n[k]) !== 1 / 0 && (n[k] = Number(n[k]));
|
|
145
|
+
const M = l(`${n.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00"), i = n.eta ? l(`${n.eta} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00") : void 0, w = n.status, { labelCn: S, labelEn: q } = this.parseStatus(w), x = {
|
|
146
|
+
mmsi: n.mmsi,
|
|
147
|
+
imo: m == null ? void 0 : m.imo,
|
|
148
|
+
lat: n.lat,
|
|
149
|
+
lng: n.lon,
|
|
150
|
+
sog: n.sog,
|
|
151
|
+
cog: n.cog,
|
|
152
|
+
hdg: n.hdg,
|
|
153
|
+
draught: n.draught,
|
|
154
|
+
status: w,
|
|
155
|
+
eta: i == null ? void 0 : i.unix(),
|
|
156
|
+
destination: n.dest,
|
|
157
|
+
positionTime: M.unix(),
|
|
158
|
+
labelCn: S,
|
|
159
|
+
labelEn: q,
|
|
160
|
+
method: "trajectory",
|
|
161
|
+
vendor: "myVessel",
|
|
162
|
+
utc: M.utc().format()
|
|
163
|
+
}, I = Math.floor(M.diff(b, "minute", !0) / (a || 1));
|
|
164
|
+
I !== j && (j = I, N.push(x));
|
|
165
|
+
}), N;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
class V extends _ {
|
|
169
|
+
constructor(s) {
|
|
170
|
+
super();
|
|
171
|
+
v(this, "token");
|
|
172
|
+
this.token = s;
|
|
173
|
+
}
|
|
174
|
+
async realTimePosition(s, o = {}) {
|
|
175
|
+
const c = "https://api.hifleet.com/position/position/get/token", a = {
|
|
176
|
+
searchParams: {
|
|
177
|
+
mmsi: s,
|
|
178
|
+
usertoken: this.token
|
|
179
|
+
}
|
|
180
|
+
}, e = await y.post(c, a).json();
|
|
181
|
+
p.info("[%s] fetch realtime position from: %s - %j", o.requestId, c, a);
|
|
182
|
+
const t = e == null ? void 0 : e.list;
|
|
183
|
+
if (!t)
|
|
184
|
+
return e;
|
|
185
|
+
for (const r in t)
|
|
186
|
+
!isNaN(t[r]) && Number(t[r]) !== 1 / 0 && (t[r] = Number(t[r]));
|
|
187
|
+
t.status = t.sp > 3 ? 0 : 1;
|
|
188
|
+
const m = t.status, { labelCn: u, labelEn: d } = this.parseStatus(m), f = l(`${t.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
189
|
+
return {
|
|
190
|
+
mmsi: t.m,
|
|
191
|
+
name: t.n,
|
|
192
|
+
imo: t.imonumber,
|
|
193
|
+
callSign: t.callsign,
|
|
194
|
+
lat: Math.round(t.la / 60 * 1e5) / 1e5,
|
|
195
|
+
lng: Math.round(t.lo / 60 * 1e5) / 1e5,
|
|
196
|
+
length: t.l,
|
|
197
|
+
width: t.w,
|
|
198
|
+
draught: t.draught,
|
|
199
|
+
sog: t.sp,
|
|
200
|
+
cog: t.co,
|
|
201
|
+
hdg: t.h,
|
|
202
|
+
rot: isNaN(t.rot) ? 0 : t.rot,
|
|
203
|
+
eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(t.eta) ? l(`${t.eta} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00").unix() : void 0,
|
|
204
|
+
destination: t.destination,
|
|
205
|
+
positionTime: f.unix(),
|
|
206
|
+
utc: f.utc().format(),
|
|
207
|
+
status: m,
|
|
208
|
+
labelCn: u,
|
|
209
|
+
labelEn: d,
|
|
210
|
+
method: "position",
|
|
211
|
+
vendor: "hifleet"
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
async search(s, o = {}) {
|
|
215
|
+
let c = "https://www.hifleet.com/hifleetapi/searchVesselOL.do";
|
|
216
|
+
const a = {
|
|
217
|
+
searchParams: {
|
|
218
|
+
keyword: s
|
|
219
|
+
},
|
|
220
|
+
headers: {
|
|
221
|
+
Referer: "https://www.hifleet.com",
|
|
222
|
+
Origin: "https://www.hifleet.com",
|
|
223
|
+
Host: "www.hifleet.com"
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
let e = await y.post(c, a).json();
|
|
227
|
+
p.info("[%s] fetch vessel props from: %s - %j", o.requestId, c, a), e instanceof Array && (e = e[0]);
|
|
228
|
+
for (const m in e)
|
|
229
|
+
!isNaN(e[m]) && Number(e[m]) !== 1 / 0 && (e[m] = Number(e[m]));
|
|
230
|
+
const t = {
|
|
231
|
+
mmsi: e.m,
|
|
232
|
+
name: e.n,
|
|
233
|
+
imo: e.i,
|
|
234
|
+
callSign: e.c,
|
|
235
|
+
length: e.l,
|
|
236
|
+
breadth: e.b,
|
|
237
|
+
draught: e.dr
|
|
238
|
+
};
|
|
239
|
+
return c = "https://www.hifleet.com/hifleetapi/sameShipSearch.do", e = await y.post(c, a).json(), p.info("[%s] fetch vessel dead weight from: %s - %j", o.requestId, c, a), e instanceof Array && (e = e[0]), e && (t.deadweight = Number(e.dwt)), t;
|
|
240
|
+
}
|
|
241
|
+
async trajectory(s, o, c, a, e = !0, t = {}) {
|
|
242
|
+
var D, n, M;
|
|
243
|
+
const m = await this.realTimePosition(s, t);
|
|
244
|
+
let u = l(o);
|
|
245
|
+
const d = l(c), f = l();
|
|
246
|
+
if (e) {
|
|
247
|
+
let i = d.diff(u, "d", !0);
|
|
248
|
+
i < 0 ? u = d.clone().subtract(40, "d") : i < 30 ? u.subtract(10, "d") : i < 60 ? u.subtract(5, "d") : u = d.clone().subtract(80, "d"), i = f.diff(d, "d", !0), d.add(i > 10 ? 240 : i * 24, "h");
|
|
249
|
+
}
|
|
250
|
+
const g = {
|
|
251
|
+
searchParams: {
|
|
252
|
+
endtime: d.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
|
|
253
|
+
starttime: u.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
|
|
254
|
+
mmsi: s,
|
|
255
|
+
usertoken: this.token
|
|
256
|
+
}
|
|
257
|
+
}, r = "https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token", j = await y.get(r, g).json();
|
|
258
|
+
p.info("[%s] fetch trajectory from: %s - %j", t.requestId, r, g);
|
|
259
|
+
let b;
|
|
260
|
+
j && (b = ((n = (D = j.ships) == null ? void 0 : D.offors) == null ? void 0 : n.ship) || [], b.length || p.warn("[%s] got vessel trajectory failed: %j", t.requestId, j));
|
|
261
|
+
const N = [];
|
|
262
|
+
let H = -1;
|
|
263
|
+
const T = l(`${(M = b == null ? void 0 : b[0]) == null ? void 0 : M.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
264
|
+
for (const i of b) {
|
|
265
|
+
for (const k in i)
|
|
266
|
+
!isNaN(i[k]) && Number(i[k]) !== 1 / 0 && (i[k] = Number(i[k]));
|
|
267
|
+
const w = l(`${i.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
268
|
+
i.status = i.sp > 4 ? 0 : 1;
|
|
269
|
+
const { labelEn: S, labelCn: q } = this.parseStatus(i.status), x = {
|
|
270
|
+
mmsi: i.m,
|
|
271
|
+
name: i.n,
|
|
272
|
+
imo: m == null ? void 0 : m.imo,
|
|
273
|
+
lat: i.la,
|
|
274
|
+
lng: i.lo,
|
|
275
|
+
draught: i.draught,
|
|
276
|
+
sog: i.sp,
|
|
277
|
+
cog: i.co,
|
|
278
|
+
hdg: i.hdg,
|
|
279
|
+
positionTime: w.unix(),
|
|
280
|
+
utc: w.utc().format(),
|
|
281
|
+
status: i.status,
|
|
282
|
+
labelCn: q,
|
|
283
|
+
labelEn: S,
|
|
284
|
+
method: "trajectory",
|
|
285
|
+
vendor: "hifleet"
|
|
286
|
+
}, I = Math.floor(w.diff(T, "minute", !0) / (a || 1));
|
|
287
|
+
I !== H && (H = I, N.push(x));
|
|
288
|
+
}
|
|
289
|
+
return N;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
export {
|
|
293
|
+
_ as AISImpl,
|
|
294
|
+
V as HifleetImpl,
|
|
295
|
+
L as MyVesselImpl
|
|
296
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(f,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("got"),require("log4js"),require("moment")):typeof define=="function"&&define.amd?define(["exports","got","log4js","moment"],c):(f=typeof globalThis<"u"?globalThis:f||self,c(f["idm-plugin-rabbitmq"]={},f.got,f.log4js,f.moment))})(this,function(f,c,j,l){"use strict";var C=Object.defineProperty;var V=(f,c,j)=>c in f?C(f,c,{enumerable:!0,configurable:!0,writable:!0,value:j}):f[c]=j;var S=(f,c,j)=>(V(f,typeof c!="symbol"?c+"":c,j),j);function $(Y){const M=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(Y){for(const s in Y)if(s!=="default"){const i=Object.getOwnPropertyDescriptor(Y,s);Object.defineProperty(M,s,i.get?i:{enumerable:!0,get:()=>Y[s]})}}return M.default=Y,Object.freeze(M)}const g=$(j).getLogger();class _{parseStatus(M){let s,i;switch(M){case 0:s="在航(主机推动)",i="The engine is in use";break;case 1:s="锚泊",i="Anchored";break;case 2:s="失控",i="Not operated";break;case 3:s="操纵受限",i="Limited airworthiness";break;case 4:s="吃水受限",i="Limited by ship's draft";break;case 5:s="靠泊",i="Mooring";break;case 6:s="搁浅",i="Stranded";break;case 7:s="捕捞作业",i="Engaged in fishing";break;case 8:s="靠帆船提供动力",i="Sailing";break;default:s="未定义",i="Undefined"}return{labelCn:s,labelEn:i}}}class A extends _{constructor(s,i){super();S(this,"clientId");S(this,"clientSecret");S(this,"token");this.clientId=s,this.clientSecret=i}async authToken(s={}){const i="https://svc.data.myvessel.cn/ada/oauth/token",d={searchParams:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},a=await c.post(i,d).json();g.info("[%s] fetch access token from: %s - %j",s.requestId,i,a),a.error||(this.token={accessToken:a.access_token,tokenType:a.token_type,expiresIn:a.expires_in,scope:a.scope,jti:a.jti,issuedAt:l().utc().format()})}async realTimePosition(s,i={}){var h,p,k;(!this.token||l().diff(l(this.token.issuedAt),"seconds")>((h=this.token)==null?void 0:h.expiresIn)-300)&&await this.authToken(i);const d="https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit",a={headers:{Authorization:`${(p=this.token)==null?void 0:p.tokenType} ${(k=this.token)==null?void 0:k.accessToken}`},searchParams:{mmsi:s}};g.info("[%s] fetch realtime position from: %s - %j",i.requestId,d,a);const e=await c.get(d,a).json();if(e.code)return g.warn("[%s] fetch realtime position failed: %j",i.requestId,d,{message:e.message,status:e.status,code:e.code}),e;const t=e.data;for(const r in t)!isNaN(t[r])&&Number(t[r])!==1/0&&(t[r]=Number(t[r]));const u=l(`${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:u.unix(),status:t.status,labelCn:t.statusNameCn,labelEn:t.statusNameEn,method:"position",vendor:"myVessel",utc:u.utc().format()}}async trajectory(s,i,d,a,e=!0,t={}){var H,q,T;(!this.token||l().diff(l(this.token.issuedAt),"seconds")>this.token.expiresIn-300)&&await this.authToken(t);const u=await this.realTimePosition(s,t),m="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track";let h=l(i);const p=l(d);if(e){const o=p.diff(h,"d",!0);(o<0||o>30)&&(h=p.clone().subtract(30,"d"))}const k={headers:{Authorization:`${(H=this.token)==null?void 0:H.tokenType} ${(q=this.token)==null?void 0:q.accessToken}`},json:{mmsi:s,startTime:h.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),endTime:p.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")}};g.info("[%s] fetch trajectory from: %s - %j",t.requestId,m,k);const r=await c.post(m,k).json();if(r.code)return g.warn("[%s] fetch trajectory failed: %j",t.requestId,m,{message:r.message,status:r.status,code:r.code}),r;let w=-1;const y=l(`${(T=r.data[0])==null?void 0:T.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),D=[];return r.data.forEach(o=>{for(const b in o)!isNaN(o[b])&&Number(o[b])!==1/0&&(o[b]=Number(o[b]));const I=l(`${o.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),n=o.eta?l(`${o.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"):void 0,N=o.status,{labelCn:x,labelEn:O}=this.parseStatus(N),P={mmsi:o.mmsi,imo:u==null?void 0:u.imo,lat:o.lat,lng:o.lon,sog:o.sog,cog:o.cog,hdg:o.hdg,draught:o.draught,status:N,eta:n==null?void 0:n.unix(),destination:o.dest,positionTime:I.unix(),labelCn:x,labelEn:O,method:"trajectory",vendor:"myVessel",utc:I.utc().format()},v=Math.floor(I.diff(y,"minute",!0)/(a||1));v!==w&&(w=v,D.push(P))}),D}}class E extends _{constructor(s){super();S(this,"token");this.token=s}async realTimePosition(s,i={}){const d="https://api.hifleet.com/position/position/get/token",a={searchParams:{mmsi:s,usertoken:this.token}},e=await c.post(d,a).json();g.info("[%s] fetch realtime position from: %s - %j",i.requestId,d,a);const t=e==null?void 0:e.list;if(!t)return e;for(const r in t)!isNaN(t[r])&&Number(t[r])!==1/0&&(t[r]=Number(t[r]));t.status=t.sp>3?0:1;const u=t.status,{labelCn:m,labelEn:h}=this.parseStatus(u),p=l(`${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)?l(`${t.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00").unix():void 0,destination:t.destination,positionTime:p.unix(),utc:p.utc().format(),status:u,labelCn:m,labelEn:h,method:"position",vendor:"hifleet"}}async search(s,i={}){let d="https://www.hifleet.com/hifleetapi/searchVesselOL.do";const a={searchParams:{keyword:s},headers:{Referer:"https://www.hifleet.com",Origin:"https://www.hifleet.com",Host:"www.hifleet.com"}};let e=await c.post(d,a).json();g.info("[%s] fetch vessel props from: %s - %j",i.requestId,d,a),e instanceof Array&&(e=e[0]);for(const u in e)!isNaN(e[u])&&Number(e[u])!==1/0&&(e[u]=Number(e[u]));const t={mmsi:e.m,name:e.n,imo:e.i,callSign:e.c,length:e.l,breadth:e.b,draught:e.dr};return d="https://www.hifleet.com/hifleetapi/sameShipSearch.do",e=await c.post(d,a).json(),g.info("[%s] fetch vessel dead weight from: %s - %j",i.requestId,d,a),e instanceof Array&&(e=e[0]),e&&(t.deadweight=Number(e.dwt)),t}async trajectory(s,i,d,a,e=!0,t={}){var T,o,I;const u=await this.realTimePosition(s,t);let m=l(i);const h=l(d),p=l();if(e){let n=h.diff(m,"d",!0);n<0?m=h.clone().subtract(40,"d"):n<30?m.subtract(10,"d"):n<60?m.subtract(5,"d"):m=h.clone().subtract(80,"d"),n=p.diff(h,"d",!0),h.add(n>10?240:n*24,"h")}const k={searchParams:{endtime:h.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),starttime:m.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),mmsi:s,usertoken:this.token}},r="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",w=await c.get(r,k).json();g.info("[%s] fetch trajectory from: %s - %j",t.requestId,r,k);let y;w&&(y=((o=(T=w.ships)==null?void 0:T.offors)==null?void 0:o.ship)||[],y.length||g.warn("[%s] got vessel trajectory failed: %j",t.requestId,w));const D=[];let H=-1;const q=l(`${(I=y==null?void 0:y[0])==null?void 0:I.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const n of y){for(const b in n)!isNaN(n[b])&&Number(n[b])!==1/0&&(n[b]=Number(n[b]));const N=l(`${n.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");n.status=n.sp>4?0:1;const{labelEn:x,labelCn:O}=this.parseStatus(n.status),P={mmsi:n.m,name:n.n,imo:u==null?void 0:u.imo,lat:n.la,lng:n.lo,draught:n.draught,sog:n.sp,cog:n.co,hdg:n.hdg,positionTime:N.unix(),utc:N.utc().format(),status:n.status,labelCn:O,labelEn:x,method:"trajectory",vendor:"hifleet"},v=Math.floor(N.diff(q,"minute",!0)/(a||1));v!==H&&(H=v,D.push(P))}return D}}f.AISImpl=_,f.HifleetImpl=E,f.MyVesselImpl=A,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@idm-plugin/vessel",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"description": "idm plugin for vessel",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"idm",
|
|
9
|
+
"vessel"
|
|
10
|
+
],
|
|
11
|
+
"author": "chenheng@idmwx.com",
|
|
12
|
+
"contributors": [
|
|
13
|
+
"ChenHeng"
|
|
14
|
+
],
|
|
15
|
+
"license": "GPL-3.0",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"main": "./dist/index.umd.cjs",
|
|
20
|
+
"module": "./dist/index.js",
|
|
21
|
+
"types": "index.d.ts",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"dev": "vite --config ./build/base.config.ts",
|
|
24
|
+
"build": "vite build --config ./build/lib.config.ts",
|
|
25
|
+
"lint:fix": "eslint --fix --ext .js,.ts,.",
|
|
26
|
+
"prettier": "yarn lint:fix && prettier --write '**/*.{js,ts}'",
|
|
27
|
+
"release": "yarn build && yarn publish --access public"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"got": "11",
|
|
31
|
+
"log4js": "^6.9.1",
|
|
32
|
+
"moment": "^2.30.1"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/jest": "^25.2.2",
|
|
36
|
+
"@types/node": "^18.14.2",
|
|
37
|
+
"@typescript-eslint/eslint-plugin": "^5.53.0",
|
|
38
|
+
"@typescript-eslint/parser": "^5.53.0",
|
|
39
|
+
"@vitejs/plugin-vue": "^4.2.3",
|
|
40
|
+
"eslint": "^8.35.0",
|
|
41
|
+
"eslint-config-prettier": "^8.6.0",
|
|
42
|
+
"eslint-define-config": "^1.15.0",
|
|
43
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
44
|
+
"jest": "^26.6.3",
|
|
45
|
+
"lint-staged": "^13.1.2",
|
|
46
|
+
"prettier": "^2.8.4",
|
|
47
|
+
"sass": "^1.58.3",
|
|
48
|
+
"simple-git-hooks": "^2.8.1",
|
|
49
|
+
"stylelint": "^15.2.0",
|
|
50
|
+
"supertest": "^4.0.2",
|
|
51
|
+
"ts-jest": "^26.5.3",
|
|
52
|
+
"ts-node-dev": "^2.0.0-0",
|
|
53
|
+
"tsconfig-paths": "^3.12.0",
|
|
54
|
+
"typescript": "^4.9.3",
|
|
55
|
+
"vite": "^4.1.0",
|
|
56
|
+
"vite-plugin-dts": "^2.0.2",
|
|
57
|
+
"vite-plugin-static-copy": "^0.17.0"
|
|
58
|
+
},
|
|
59
|
+
"lint-staged": {
|
|
60
|
+
"*.{ts,tsx,js}": "eslint --fix",
|
|
61
|
+
"*.{ts,tsx,js,scss}": "prettier --write"
|
|
62
|
+
},
|
|
63
|
+
"simple-git-hooks": {
|
|
64
|
+
"pre-commit": "yarn exec lint-staged"
|
|
65
|
+
}
|
|
66
|
+
}
|