@idm-plugin/vessel 1.0.0 → 1.0.1

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.
@@ -72,3 +72,18 @@ export declare class HifleetImpl extends AISImpl {
72
72
  search(kw: string, options?: RequestOptions): Promise<VesselRecord>;
73
73
  trajectory(mmsi: number, startTime: string, endTime: string, offset: number, scale?: boolean, options?: RequestOptions): Promise<AISRecord[]>;
74
74
  }
75
+ export declare class ShipxyImpl extends AISImpl {
76
+ private readonly token;
77
+ constructor(token: string);
78
+ realTimePosition(mmsi: number, options?: RequestOptions): Promise<AISRecord>;
79
+ trajectory(mmsi: number, startTime: string, endTime: string, offset: number, scale?: boolean, options?: RequestOptions): Promise<AISRecord[]>;
80
+ }
81
+ export declare class MyShipImpl extends AISImpl {
82
+ private readonly token;
83
+ constructor(token: string);
84
+ getShipId(mmsi: any, options?: RequestOptions): Promise<string>;
85
+ getShipInfo(shipId: string, options?: RequestOptions): Promise<AISRecord>;
86
+ realTimePosition(mmsi: number, options?: RequestOptions): Promise<AISRecord>;
87
+ trajectory(mmsi: number, startTime: string, endTime: string, offset: number, scale?: boolean, options?: RequestOptions): Promise<AISRecord[]>;
88
+ private trajectoryIn30Day;
89
+ }
package/dist/index.js CHANGED
@@ -1,18 +1,18 @@
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";
1
+ var P = Object.defineProperty;
2
+ var $ = (I, M, s) => M in I ? P(I, M, { enumerable: !0, configurable: !0, writable: !0, value: s }) : I[M] = s;
3
+ var x = (I, M, s) => ($(I, typeof M != "symbol" ? M + "" : M, s), s);
4
+ import b from "got";
5
+ import * as E from "log4js";
6
6
  import l from "moment";
7
- const p = P.getLogger();
8
- class _ {
7
+ const g = E.getLogger();
8
+ class v {
9
9
  /**
10
10
  * 解析AIS状态码
11
11
  * @param status
12
12
  */
13
- parseStatus(h) {
13
+ parseStatus(M) {
14
14
  let s, o;
15
- switch (h) {
15
+ switch (M) {
16
16
  case 0:
17
17
  s = "在航(主机推动)", o = "The engine is in use";
18
18
  break;
@@ -46,48 +46,48 @@ class _ {
46
46
  return { labelCn: s, labelEn: o };
47
47
  }
48
48
  }
49
- class L extends _ {
49
+ class L extends v {
50
50
  constructor(s, o) {
51
51
  super();
52
- v(this, "clientId");
53
- v(this, "clientSecret");
54
- v(this, "token");
52
+ x(this, "clientId");
53
+ x(this, "clientSecret");
54
+ x(this, "token");
55
55
  this.clientId = s, this.clientSecret = o;
56
56
  }
57
57
  async authToken(s = {}) {
58
- const o = "https://svc.data.myvessel.cn/ada/oauth/token", c = {
58
+ const o = "https://svc.data.myvessel.cn/ada/oauth/token", r = {
59
59
  searchParams: {
60
60
  client_id: this.clientId,
61
61
  client_secret: this.clientSecret,
62
62
  grant_type: "client_credentials"
63
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,
64
+ }, i = await b.post(o, r).json();
65
+ g.info("[%s] fetch access token from: %s - %j", s.requestId, o, i), i.error || (this.token = {
66
+ accessToken: i.access_token,
67
+ tokenType: i.token_type,
68
+ expiresIn: i.expires_in,
69
+ scope: i.scope,
70
+ jti: i.jti,
71
71
  issuedAt: l().utc().format()
72
72
  });
73
73
  }
74
74
  async realTimePosition(s, o = {}) {
75
- var d, f, g;
75
+ var d, f, m;
76
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 = {
77
+ const r = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit", i = {
78
78
  headers: {
79
- Authorization: `${(f = this.token) == null ? void 0 : f.tokenType} ${(g = this.token) == null ? void 0 : g.accessToken}`
79
+ Authorization: `${(f = this.token) == null ? void 0 : f.tokenType} ${(m = this.token) == null ? void 0 : m.accessToken}`
80
80
  },
81
81
  searchParams: { mmsi: s }
82
82
  };
83
- p.info("[%s] fetch realtime position from: %s - %j", o.requestId, c, a);
84
- const e = await y.get(c, a).json();
83
+ g.info("[%s] fetch realtime position from: %s - %j", o.requestId, r, i);
84
+ const e = await b.get(r, i).json();
85
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;
86
+ return g.warn("[%s] fetch realtime position failed: %j", o.requestId, r, { message: e.message, status: e.status, code: e.code }), e;
87
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");
88
+ for (const c in t)
89
+ !isNaN(t[c]) && Number(t[c]) !== 1 / 0 && (t[c] = Number(t[c]));
90
+ const a = l(`${t.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
91
91
  return {
92
92
  mmsi: t.mmsi,
93
93
  name: t.vesselName,
@@ -104,28 +104,28 @@ class L extends _ {
104
104
  rot: t.rot,
105
105
  eta: t.eta,
106
106
  destination: t.dest,
107
- positionTime: m.unix(),
107
+ positionTime: a.unix(),
108
108
  status: t.status,
109
109
  labelCn: t.statusNameCn,
110
110
  labelEn: t.statusNameEn,
111
111
  method: "position",
112
112
  vendor: "myVessel",
113
- utc: m.utc().format()
113
+ utc: a.utc().format()
114
114
  };
115
115
  }
116
- async trajectory(s, o, c, a, e = !0, t = {}) {
117
- var H, T, D;
116
+ async trajectory(s, o, r, i, e = !0, t = {}) {
117
+ var p, w, j;
118
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";
119
+ const a = await this.realTimePosition(s, t), n = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/track";
120
120
  let d = l(o);
121
- const f = l(c);
121
+ const f = l(r);
122
122
  if (e) {
123
- const n = f.diff(d, "d", !0);
124
- (n < 0 || n > 30) && (d = f.clone().subtract(30, "d"));
123
+ const u = f.diff(d, "d", !0);
124
+ (u < 0 || u > 30) && (d = f.clone().subtract(30, "d"));
125
125
  }
126
- const g = {
126
+ const m = {
127
127
  headers: {
128
- Authorization: `${(H = this.token) == null ? void 0 : H.tokenType} ${(T = this.token) == null ? void 0 : T.accessToken}`
128
+ Authorization: `${(p = this.token) == null ? void 0 : p.tokenType} ${(w = this.token) == null ? void 0 : w.accessToken}`
129
129
  },
130
130
  json: {
131
131
  mmsi: s,
@@ -133,59 +133,59 @@ class L extends _ {
133
133
  endTime: f.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")
134
134
  }
135
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,
136
+ g.info("[%s] fetch trajectory from: %s - %j", t.requestId, n, m);
137
+ const c = await b.post(n, m).json();
138
+ if (c.code)
139
+ return g.warn("[%s] fetch trajectory failed: %j", t.requestId, n, { message: c.message, status: c.status, code: c.code }), c;
140
+ let y = -1;
141
+ const k = l(`${(j = c.data[0]) == null ? void 0 : j.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00"), Y = [];
142
+ return c.data.forEach((u) => {
143
+ for (const N in u)
144
+ !isNaN(u[N]) && Number(u[N]) !== 1 / 0 && (u[N] = Number(u[N]));
145
+ const S = l(`${u.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00"), h = u.eta ? l(`${u.eta} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00") : void 0, T = u.status, { labelCn: q, labelEn: H } = this.parseStatus(T), _ = {
146
+ mmsi: u.mmsi,
147
+ imo: a == null ? void 0 : a.imo,
148
+ lat: u.lat,
149
+ lng: u.lon,
150
+ sog: u.sog,
151
+ cog: u.cog,
152
+ hdg: u.hdg,
153
+ draught: u.draught,
154
+ status: T,
155
+ eta: h == null ? void 0 : h.unix(),
156
+ destination: u.dest,
157
+ positionTime: S.unix(),
158
+ labelCn: q,
159
+ labelEn: H,
160
160
  method: "trajectory",
161
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;
162
+ utc: S.utc().format()
163
+ }, D = Math.floor(S.diff(k, "minute", !0) / (i || 1));
164
+ D !== y && (y = D, Y.push(_));
165
+ }), Y;
166
166
  }
167
167
  }
168
- class V extends _ {
168
+ class K extends v {
169
169
  constructor(s) {
170
170
  super();
171
- v(this, "token");
171
+ x(this, "token");
172
172
  this.token = s;
173
173
  }
174
174
  async realTimePosition(s, o = {}) {
175
- const c = "https://api.hifleet.com/position/position/get/token", a = {
175
+ const r = "https://api.hifleet.com/position/position/get/token", i = {
176
176
  searchParams: {
177
177
  mmsi: s,
178
178
  usertoken: this.token
179
179
  }
180
- }, e = await y.post(c, a).json();
181
- p.info("[%s] fetch realtime position from: %s - %j", o.requestId, c, a);
180
+ }, e = await b.post(r, i).json();
181
+ g.info("[%s] fetch realtime position from: %s - %j", o.requestId, r, i);
182
182
  const t = e == null ? void 0 : e.list;
183
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]));
184
+ return g.warn("[%s] fetch realtime position failed: %j", o.requestId, r, e), e;
185
+ for (const c in t)
186
+ !isNaN(t[c]) && Number(t[c]) !== 1 / 0 && (t[c] = Number(t[c]));
187
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");
188
+ const a = t.status, { labelCn: n, labelEn: d } = this.parseStatus(a), f = l(`${t.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
189
189
  return {
190
190
  mmsi: t.m,
191
191
  name: t.n,
@@ -204,16 +204,16 @@ class V extends _ {
204
204
  destination: t.destination,
205
205
  positionTime: f.unix(),
206
206
  utc: f.utc().format(),
207
- status: m,
208
- labelCn: u,
207
+ status: a,
208
+ labelCn: n,
209
209
  labelEn: d,
210
210
  method: "position",
211
211
  vendor: "hifleet"
212
212
  };
213
213
  }
214
214
  async search(s, o = {}) {
215
- let c = "https://www.hifleet.com/hifleetapi/searchVesselOL.do";
216
- const a = {
215
+ let r = "https://www.hifleet.com/hifleetapi/searchVesselOL.do";
216
+ const i = {
217
217
  searchParams: {
218
218
  keyword: s
219
219
  },
@@ -223,10 +223,10 @@ class V extends _ {
223
223
  Host: "www.hifleet.com"
224
224
  }
225
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]));
226
+ let e = await b.post(r, i).json();
227
+ g.info("[%s] fetch vessel props from: %s - %j", o.requestId, r, i), e instanceof Array && (e = e[0]);
228
+ for (const a in e)
229
+ !isNaN(e[a]) && Number(e[a]) !== 1 / 0 && (e[a] = Number(e[a]));
230
230
  const t = {
231
231
  mmsi: e.m,
232
232
  name: e.n,
@@ -236,61 +236,257 @@ class V extends _ {
236
236
  breadth: e.b,
237
237
  draught: e.dr
238
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;
239
+ return r = "https://www.hifleet.com/hifleetapi/sameShipSearch.do", e = await b.post(r, i).json(), g.info("[%s] fetch vessel dead weight from: %s - %j", o.requestId, r, i), e instanceof Array && (e = e[0]), e && (t.deadweight = Number(e.dwt)), t;
240
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();
241
+ async trajectory(s, o, r, i, e = !0, t = {}) {
242
+ var j, u, S;
243
+ const a = await this.realTimePosition(s, t);
244
+ let n = l(o);
245
+ const d = l(r), f = l();
246
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");
247
+ let h = d.diff(n, "d", !0);
248
+ h < 0 ? n = d.clone().subtract(40, "d") : h < 30 ? n.subtract(10, "d") : h < 60 ? n.subtract(5, "d") : n = d.clone().subtract(80, "d"), h = f.diff(d, "d", !0), d.add(h > 10 ? 240 : h * 24, "h");
249
249
  }
250
- const g = {
250
+ const m = {
251
251
  searchParams: {
252
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"),
253
+ starttime: n.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
254
254
  mmsi: s,
255
255
  usertoken: this.token
256
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,
257
+ }, c = "https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token", y = await b.get(c, m).json();
258
+ g.info("[%s] fetch trajectory from: %s - %j", t.requestId, c, m);
259
+ let k;
260
+ y && (k = ((u = (j = y.ships) == null ? void 0 : j.offors) == null ? void 0 : u.ship) || [], k.length || g.warn("[%s] fetch trajectory failed: %j", t.requestId, y));
261
+ const Y = [];
262
+ let p = -1;
263
+ const w = l(`${(S = k == null ? void 0 : k[0]) == null ? void 0 : S.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
264
+ for (const h of k) {
265
+ for (const N in h)
266
+ !isNaN(h[N]) && Number(h[N]) !== 1 / 0 && (h[N] = Number(h[N]));
267
+ const T = l(`${h.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
268
+ h.status = h.sp > 4 ? 0 : 1;
269
+ const { labelEn: q, labelCn: H } = this.parseStatus(h.status), _ = {
270
+ mmsi: h.m,
271
+ name: h.n,
272
+ imo: a == null ? void 0 : a.imo,
273
+ lat: h.la,
274
+ lng: h.lo,
275
+ draught: h.draught,
276
+ sog: h.sp,
277
+ cog: h.co,
278
+ hdg: h.hdg,
279
+ positionTime: T.unix(),
280
+ utc: T.utc().format(),
281
+ status: h.status,
282
+ labelCn: H,
283
+ labelEn: q,
284
+ method: "trajectory",
285
+ vendor: "hifleet"
286
+ }, D = Math.floor(T.diff(w, "minute", !0) / (i || 1));
287
+ D !== p && (p = D, Y.push(_));
288
+ }
289
+ return Y;
290
+ }
291
+ }
292
+ class V extends v {
293
+ constructor(s) {
294
+ super();
295
+ x(this, "token");
296
+ this.token = s;
297
+ }
298
+ async realTimePosition(s, o = {}) {
299
+ const r = {
300
+ searchParams: {
301
+ id: s,
302
+ k: this.token,
303
+ enc: 1
304
+ }
305
+ }, i = "https://api.shipxy.com/apicall/GetSingleShip", e = await b.get(i, r).json();
306
+ if (g.info("[%s] fetch realtime position from: %s - %j", o.requestId, i, r), (e == null ? void 0 : e.status) !== 0)
307
+ return e;
308
+ const t = e.data[0];
309
+ for (const m in t)
310
+ !isNaN(t[m]) && Number(t[m]) !== 1 / 0 && (t[m] = Number(t[m]));
311
+ const { labelCn: a, labelEn: n } = await this.parseStatus(t.navistat), d = l.unix(t.lasttime);
312
+ return {
313
+ mmsi: t.ShipID,
314
+ name: t.name,
315
+ imo: t.imo,
316
+ callSign: t.callsign,
317
+ lat: Math.round(t.lat / 1e6 * 1e5) / 1e5,
318
+ lng: Math.round(t.lon / 1e6 * 1e5) / 1e5,
319
+ length: Math.round(t.length / 10 * 100) / 100,
320
+ width: Math.round(t.width / 10 * 100) / 100,
321
+ draught: Math.round(t.draught / 1e3 * 100) / 100,
322
+ sog: Math.round(t.sog * 3600 / 1e3 / 1852 * 100) / 100,
323
+ cog: Math.round(t.cog / 100 * 100) / 100,
324
+ hdg: Math.round(t.hdg / 100 * 100) / 100,
325
+ rot: Math.round(t.rot / 100 * 100) / 100,
326
+ positionTime: t.lasttime,
327
+ utc: d.utc().format(),
328
+ status: t.navistat,
329
+ labelEn: n,
330
+ labelCn: a,
331
+ method: "position",
332
+ vendor: "shipxy"
333
+ };
334
+ }
335
+ async trajectory(s, o, r, i, e = !0, t = {}) {
336
+ var w;
337
+ const a = await this.realTimePosition(s, t), n = l(o), d = l(r), f = "https://api.shipxy.com/apicall/GetShipTrack", m = {
338
+ searchParams: {
339
+ id: s,
340
+ k: this.token,
341
+ enc: 1,
342
+ cut: 0,
343
+ btm: n.unix(),
344
+ etm: d.unix()
345
+ }
346
+ }, c = await b.get(f, m).json();
347
+ if (g.info("[%s] fetch trajectory from: %s - %j", t.requestId, f, m), (c == null ? void 0 : c.status) !== 0)
348
+ return c;
349
+ const y = c == null ? void 0 : c.points, k = [], Y = l.unix((w = y[0]) == null ? void 0 : w.utc);
350
+ let p = -1;
351
+ for (const j of y) {
352
+ const u = l.unix(j.utc), S = {
353
+ imo: a == null ? void 0 : a.imo,
354
+ mmsi: s,
355
+ sog: Math.round(j.sog * 3600 / 1e3 / 1852 * 100) / 100,
356
+ cog: Math.round(j.cog / 100 * 100) / 100,
357
+ lat: Math.round(j.lat / 1e6 * 1e5) / 1e5,
358
+ lng: Math.round(j.lon / 1e6 * 1e5) / 1e5,
359
+ positionTime: u.unix(),
360
+ utc: u.utc().format(),
361
+ method: "trajectory",
362
+ vendor: "shipxy"
363
+ }, h = Math.floor(u.diff(Y, "minute", !0) / (i || 1));
364
+ h !== p && (p = h, k.push(S));
365
+ }
366
+ return k;
367
+ }
368
+ }
369
+ class z extends v {
370
+ constructor(s) {
371
+ super();
372
+ x(this, "token");
373
+ this.token = s;
374
+ }
375
+ async getShipId(s, o = {}) {
376
+ const r = {
377
+ headers: {
378
+ appKey: this.token
379
+ },
380
+ json: {
381
+ mmsiList: s
382
+ }
383
+ }, i = "https://api3.myships.com/sp/ships/getShipIdByMMSI", e = await b.post(i, r).json();
384
+ return g.info("[%s] fetch ship id from: %s - %j", o.requestId, i, r), e.code !== "0" ? e : e.data[0].shipId;
385
+ }
386
+ async getShipInfo(s, o = {}) {
387
+ const r = {
388
+ headers: {
389
+ appKey: this.token
390
+ },
391
+ json: {
392
+ shipId: s
393
+ }
394
+ }, i = "https://api3.myships.com/sp/ships/aissta", e = await b.post(i, r).json();
395
+ if (g.info("[%s] fetch ship info from: %s - %j", o.requestId, i, r), e.code !== "0")
396
+ return e;
397
+ const t = e.data;
398
+ let a = t.imo;
399
+ return s === "407170" && (a = "9198379", g.warn("[%s] ship(%s) imo error: %s, should be %s", o.requestId, s, t.imo, a)), {
400
+ mmsi: t.mmsi,
401
+ name: t.shipnameEn,
402
+ imo: a,
403
+ callSign: t.callSign,
404
+ length: t.length,
405
+ width: t.breadth,
406
+ draught: (t.draught || 100) / 10
407
+ };
408
+ }
409
+ async realTimePosition(s, o = {}) {
410
+ const r = await this.getShipId(s, o), i = await this.getShipInfo(r, o), e = {
411
+ headers: {
412
+ appKey: this.token
413
+ },
414
+ json: {
415
+ shipId: r
416
+ }
417
+ }, t = "https://api3.myships.com/sp/ships/position/latest", a = await b.post(t, e).json();
418
+ g.info("[%s] fetch realtime position from: %s - %j", o.requestId, t, e);
419
+ const n = a.data[0];
420
+ for (const y in n)
421
+ !isNaN(n[y]) && Number(n[y]) !== 1 / 0 && (n[y] = Number(n[y]));
422
+ const { labelCn: d, labelEn: f } = await this.parseStatus(n.aisNavStatus), m = l.unix(n.posTime);
423
+ return {
424
+ ...i,
425
+ mmsi: s,
426
+ lat: Math.round(n.lat / 1e4 / 60 * 1e5) / 1e5,
427
+ lng: Math.round(n.lon / 1e4 / 60 * 1e5) / 1e5,
428
+ sog: Math.round(n.sog / 10 * 100) / 100,
429
+ cog: Math.round(n.cog / 10 * 100) / 100,
430
+ hdg: Math.round(n.heading * 100) / 100,
431
+ rot: Math.round(n.rot * 100) / 100,
432
+ positionTime: n.posTime,
433
+ utc: m.utc().format(),
434
+ status: n.aisNavStatus,
435
+ labelEn: f,
436
+ labelCn: d,
437
+ method: "position",
438
+ vendor: "myship"
439
+ };
440
+ }
441
+ async trajectory(s, o, r, i, e = !0, t = {}) {
442
+ const a = l(o), n = l(r), d = await this.getShipId(s), f = await this.getShipInfo(d), m = [];
443
+ for (; n.diff(a, "day", !0) > 30; )
444
+ await this.trajectoryIn30Day(d, a.unix(), a.add(30, "day").unix(), f, s, i, m);
445
+ return await this.trajectoryIn30Day(d, a.unix(), n.unix(), f, s, i, m), m;
446
+ }
447
+ async trajectoryIn30Day(s, o, r, i, e, t, a, n = {}) {
448
+ var Y;
449
+ const d = {
450
+ headers: {
451
+ appKey: this.token
452
+ },
453
+ json: {
454
+ shipId: s,
455
+ startTime: o,
456
+ endTime: r
457
+ }
458
+ }, f = "https://api3.myships.com/sp/ships/position/history", m = await b.post(f, d).json();
459
+ if (g.info("[%s] fetch trajectory from: %s - %j", n.requestId, f, d), m.code !== "0")
460
+ return g.warn("[%s] invoke myship trajectory failed: %j", n.requestId, m), m;
461
+ const c = m.data;
462
+ for (const p in c)
463
+ !isNaN(c[p]) && Number(c[p]) !== 1 / 0 && (c[p] = Number(c[p]));
464
+ const y = l.unix((Y = c[0]) == null ? void 0 : Y.posTime);
465
+ let k = -1;
466
+ for (const p of c) {
467
+ const w = l.unix(p.posTime), j = {
468
+ imo: i == null ? void 0 : i.imo,
469
+ mmsi: e,
470
+ lat: Math.round(p.lat / 1e4 / 60 * 1e5) / 1e5,
471
+ lng: Math.round(p.lon / 1e4 / 60 * 1e5) / 1e5,
472
+ sog: Math.round(p.sog / 10 * 100) / 100,
473
+ cog: Math.round(p.cog / 10 * 100) / 100,
474
+ hdg: Math.round(p.heading * 100) / 100,
475
+ rot: Math.round(p.rot * 100) / 100,
279
476
  positionTime: w.unix(),
280
477
  utc: w.utc().format(),
281
- status: i.status,
282
- labelCn: q,
283
- labelEn: S,
284
478
  method: "trajectory",
285
- vendor: "hifleet"
286
- }, I = Math.floor(w.diff(T, "minute", !0) / (a || 1));
287
- I !== H && (H = I, N.push(x));
479
+ vendor: "myship"
480
+ }, u = Math.floor(w.diff(y, "minute", !0) / (t || 1));
481
+ u !== k && (k = u, a.push(j));
288
482
  }
289
- return N;
483
+ return a;
290
484
  }
291
485
  }
292
486
  export {
293
- _ as AISImpl,
294
- V as HifleetImpl,
295
- L as MyVesselImpl
487
+ v as AISImpl,
488
+ K as HifleetImpl,
489
+ z as MyShipImpl,
490
+ L as MyVesselImpl,
491
+ V as ShipxyImpl
296
492
  };
@@ -1 +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"})});
1
+ (function(y,p){typeof exports=="object"&&typeof module<"u"?p(exports,require("got"),require("log4js"),require("moment")):typeof define=="function"&&define.amd?define(["exports","got","log4js","moment"],p):(y=typeof globalThis<"u"?globalThis:y||self,p(y["idm-plugin-rabbitmq"]={},y.got,y.log4js,y.moment))})(this,function(y,p,x,l){"use strict";var V=Object.defineProperty;var K=(y,p,x)=>p in y?V(y,p,{enumerable:!0,configurable:!0,writable:!0,value:x}):y[p]=x;var q=(y,p,x)=>(K(y,typeof p!="symbol"?p+"":p,x),x);function $(w){const S=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(w){for(const s in w)if(s!=="default"){const i=Object.getOwnPropertyDescriptor(w,s);Object.defineProperty(S,s,i.get?i:{enumerable:!0,get:()=>w[s]})}}return S.default=w,Object.freeze(S)}const j=$(x).getLogger();class v{parseStatus(S){let s,i;switch(S){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 E extends v{constructor(s,i){super();q(this,"clientId");q(this,"clientSecret");q(this,"token");this.clientId=s,this.clientSecret=i}async authToken(s={}){const i="https://svc.data.myvessel.cn/ada/oauth/token",r={searchParams:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},o=await p.post(i,r).json();j.info("[%s] fetch access token from: %s - %j",s.requestId,i,o),o.error||(this.token={accessToken:o.access_token,tokenType:o.token_type,expiresIn:o.expires_in,scope:o.scope,jti:o.jti,issuedAt:l().utc().format()})}async realTimePosition(s,i={}){var h,m,f;(!this.token||l().diff(l(this.token.issuedAt),"seconds")>((h=this.token)==null?void 0:h.expiresIn)-300)&&await this.authToken(i);const r="https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit",o={headers:{Authorization:`${(m=this.token)==null?void 0:m.tokenType} ${(f=this.token)==null?void 0:f.accessToken}`},searchParams:{mmsi:s}};j.info("[%s] fetch realtime position from: %s - %j",i.requestId,r,o);const e=await p.get(r,o).json();if(e.code)return j.warn("[%s] fetch realtime position failed: %j",i.requestId,r,{message:e.message,status:e.status,code:e.code}),e;const t=e.data;for(const c in t)!isNaN(t[c])&&Number(t[c])!==1/0&&(t[c]=Number(t[c]));const a=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:a.unix(),status:t.status,labelCn:t.statusNameCn,labelEn:t.statusNameEn,method:"position",vendor:"myVessel",utc:a.utc().format()}}async trajectory(s,i,r,o,e=!0,t={}){var g,I,M;(!this.token||l().diff(l(this.token.issuedAt),"seconds")>this.token.expiresIn-300)&&await this.authToken(t);const a=await this.realTimePosition(s,t),n="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track";let h=l(i);const m=l(r);if(e){const d=m.diff(h,"d",!0);(d<0||d>30)&&(h=m.clone().subtract(30,"d"))}const f={headers:{Authorization:`${(g=this.token)==null?void 0:g.tokenType} ${(I=this.token)==null?void 0:I.accessToken}`},json:{mmsi:s,startTime:h.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),endTime:m.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")}};j.info("[%s] fetch trajectory from: %s - %j",t.requestId,n,f);const c=await p.post(n,f).json();if(c.code)return j.warn("[%s] fetch trajectory failed: %j",t.requestId,n,{message:c.message,status:c.status,code:c.code}),c;let k=-1;const b=l(`${(M=c.data[0])==null?void 0:M.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),Y=[];return c.data.forEach(d=>{for(const N in d)!isNaN(d[N])&&Number(d[N])!==1/0&&(d[N]=Number(d[N]));const T=l(`${d.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),u=d.eta?l(`${d.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"):void 0,D=d.status,{labelCn:_,labelEn:P}=this.parseStatus(D),O={mmsi:d.mmsi,imo:a==null?void 0:a.imo,lat:d.lat,lng:d.lon,sog:d.sog,cog:d.cog,hdg:d.hdg,draught:d.draught,status:D,eta:u==null?void 0:u.unix(),destination:d.dest,positionTime:T.unix(),labelCn:_,labelEn:P,method:"trajectory",vendor:"myVessel",utc:T.utc().format()},H=Math.floor(T.diff(b,"minute",!0)/(o||1));H!==k&&(k=H,Y.push(O))}),Y}}class A extends v{constructor(s){super();q(this,"token");this.token=s}async realTimePosition(s,i={}){const r="https://api.hifleet.com/position/position/get/token",o={searchParams:{mmsi:s,usertoken:this.token}},e=await p.post(r,o).json();j.info("[%s] fetch realtime position from: %s - %j",i.requestId,r,o);const t=e==null?void 0:e.list;if(!t)return j.warn("[%s] fetch realtime position failed: %j",i.requestId,r,e),e;for(const c in t)!isNaN(t[c])&&Number(t[c])!==1/0&&(t[c]=Number(t[c]));t.status=t.sp>3?0:1;const a=t.status,{labelCn:n,labelEn:h}=this.parseStatus(a),m=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:m.unix(),utc:m.utc().format(),status:a,labelCn:n,labelEn:h,method:"position",vendor:"hifleet"}}async search(s,i={}){let r="https://www.hifleet.com/hifleetapi/searchVesselOL.do";const o={searchParams:{keyword:s},headers:{Referer:"https://www.hifleet.com",Origin:"https://www.hifleet.com",Host:"www.hifleet.com"}};let e=await p.post(r,o).json();j.info("[%s] fetch vessel props from: %s - %j",i.requestId,r,o),e instanceof Array&&(e=e[0]);for(const a in e)!isNaN(e[a])&&Number(e[a])!==1/0&&(e[a]=Number(e[a]));const t={mmsi:e.m,name:e.n,imo:e.i,callSign:e.c,length:e.l,breadth:e.b,draught:e.dr};return r="https://www.hifleet.com/hifleetapi/sameShipSearch.do",e=await p.post(r,o).json(),j.info("[%s] fetch vessel dead weight from: %s - %j",i.requestId,r,o),e instanceof Array&&(e=e[0]),e&&(t.deadweight=Number(e.dwt)),t}async trajectory(s,i,r,o,e=!0,t={}){var M,d,T;const a=await this.realTimePosition(s,t);let n=l(i);const h=l(r),m=l();if(e){let u=h.diff(n,"d",!0);u<0?n=h.clone().subtract(40,"d"):u<30?n.subtract(10,"d"):u<60?n.subtract(5,"d"):n=h.clone().subtract(80,"d"),u=m.diff(h,"d",!0),h.add(u>10?240:u*24,"h")}const f={searchParams:{endtime:h.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),starttime:n.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),mmsi:s,usertoken:this.token}},c="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",k=await p.get(c,f).json();j.info("[%s] fetch trajectory from: %s - %j",t.requestId,c,f);let b;k&&(b=((d=(M=k.ships)==null?void 0:M.offors)==null?void 0:d.ship)||[],b.length||j.warn("[%s] fetch trajectory failed: %j",t.requestId,k));const Y=[];let g=-1;const I=l(`${(T=b==null?void 0:b[0])==null?void 0:T.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const u of b){for(const N in u)!isNaN(u[N])&&Number(u[N])!==1/0&&(u[N]=Number(u[N]));const D=l(`${u.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");u.status=u.sp>4?0:1;const{labelEn:_,labelCn:P}=this.parseStatus(u.status),O={mmsi:u.m,name:u.n,imo:a==null?void 0:a.imo,lat:u.la,lng:u.lo,draught:u.draught,sog:u.sp,cog:u.co,hdg:u.hdg,positionTime:D.unix(),utc:D.utc().format(),status:u.status,labelCn:P,labelEn:_,method:"trajectory",vendor:"hifleet"},H=Math.floor(D.diff(I,"minute",!0)/(o||1));H!==g&&(g=H,Y.push(O))}return Y}}class C extends v{constructor(s){super();q(this,"token");this.token=s}async realTimePosition(s,i={}){const r={searchParams:{id:s,k:this.token,enc:1}},o="https://api.shipxy.com/apicall/GetSingleShip",e=await p.get(o,r).json();if(j.info("[%s] fetch realtime position from: %s - %j",i.requestId,o,r),(e==null?void 0:e.status)!==0)return e;const t=e.data[0];for(const f in t)!isNaN(t[f])&&Number(t[f])!==1/0&&(t[f]=Number(t[f]));const{labelCn:a,labelEn:n}=await this.parseStatus(t.navistat),h=l.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:h.utc().format(),status:t.navistat,labelEn:n,labelCn:a,method:"position",vendor:"shipxy"}}async trajectory(s,i,r,o,e=!0,t={}){var I;const a=await this.realTimePosition(s,t),n=l(i),h=l(r),m="https://api.shipxy.com/apicall/GetShipTrack",f={searchParams:{id:s,k:this.token,enc:1,cut:0,btm:n.unix(),etm:h.unix()}},c=await p.get(m,f).json();if(j.info("[%s] fetch trajectory from: %s - %j",t.requestId,m,f),(c==null?void 0:c.status)!==0)return c;const k=c==null?void 0:c.points,b=[],Y=l.unix((I=k[0])==null?void 0:I.utc);let g=-1;for(const M of k){const d=l.unix(M.utc),T={imo:a==null?void 0:a.imo,mmsi:s,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:d.unix(),utc:d.utc().format(),method:"trajectory",vendor:"shipxy"},u=Math.floor(d.diff(Y,"minute",!0)/(o||1));u!==g&&(g=u,b.push(T))}return b}}class L extends v{constructor(s){super();q(this,"token");this.token=s}async getShipId(s,i={}){const r={headers:{appKey:this.token},json:{mmsiList:s}},o="https://api3.myships.com/sp/ships/getShipIdByMMSI",e=await p.post(o,r).json();return j.info("[%s] fetch ship id from: %s - %j",i.requestId,o,r),e.code!=="0"?e:e.data[0].shipId}async getShipInfo(s,i={}){const r={headers:{appKey:this.token},json:{shipId:s}},o="https://api3.myships.com/sp/ships/aissta",e=await p.post(o,r).json();if(j.info("[%s] fetch ship info from: %s - %j",i.requestId,o,r),e.code!=="0")return e;const t=e.data;let a=t.imo;return s==="407170"&&(a="9198379",j.warn("[%s] ship(%s) imo error: %s, should be %s",i.requestId,s,t.imo,a)),{mmsi:t.mmsi,name:t.shipnameEn,imo:a,callSign:t.callSign,length:t.length,width:t.breadth,draught:(t.draught||100)/10}}async realTimePosition(s,i={}){const r=await this.getShipId(s,i),o=await this.getShipInfo(r,i),e={headers:{appKey:this.token},json:{shipId:r}},t="https://api3.myships.com/sp/ships/position/latest",a=await p.post(t,e).json();j.info("[%s] fetch realtime position from: %s - %j",i.requestId,t,e);const n=a.data[0];for(const k in n)!isNaN(n[k])&&Number(n[k])!==1/0&&(n[k]=Number(n[k]));const{labelCn:h,labelEn:m}=await this.parseStatus(n.aisNavStatus),f=l.unix(n.posTime);return{...o,mmsi:s,lat:Math.round(n.lat/1e4/60*1e5)/1e5,lng:Math.round(n.lon/1e4/60*1e5)/1e5,sog:Math.round(n.sog/10*100)/100,cog:Math.round(n.cog/10*100)/100,hdg:Math.round(n.heading*100)/100,rot:Math.round(n.rot*100)/100,positionTime:n.posTime,utc:f.utc().format(),status:n.aisNavStatus,labelEn:m,labelCn:h,method:"position",vendor:"myship"}}async trajectory(s,i,r,o,e=!0,t={}){const a=l(i),n=l(r),h=await this.getShipId(s),m=await this.getShipInfo(h),f=[];for(;n.diff(a,"day",!0)>30;)await this.trajectoryIn30Day(h,a.unix(),a.add(30,"day").unix(),m,s,o,f);return await this.trajectoryIn30Day(h,a.unix(),n.unix(),m,s,o,f),f}async trajectoryIn30Day(s,i,r,o,e,t,a,n={}){var Y;const h={headers:{appKey:this.token},json:{shipId:s,startTime:i,endTime:r}},m="https://api3.myships.com/sp/ships/position/history",f=await p.post(m,h).json();if(j.info("[%s] fetch trajectory from: %s - %j",n.requestId,m,h),f.code!=="0")return j.warn("[%s] invoke myship trajectory failed: %j",n.requestId,f),f;const c=f.data;for(const g in c)!isNaN(c[g])&&Number(c[g])!==1/0&&(c[g]=Number(c[g]));const k=l.unix((Y=c[0])==null?void 0:Y.posTime);let b=-1;for(const g of c){const I=l.unix(g.posTime),M={imo:o==null?void 0:o.imo,mmsi:e,lat:Math.round(g.lat/1e4/60*1e5)/1e5,lng:Math.round(g.lon/1e4/60*1e5)/1e5,sog:Math.round(g.sog/10*100)/100,cog:Math.round(g.cog/10*100)/100,hdg:Math.round(g.heading*100)/100,rot:Math.round(g.rot*100)/100,positionTime:I.unix(),utc:I.utc().format(),method:"trajectory",vendor:"myship"},d=Math.floor(I.diff(k,"minute",!0)/(t||1));d!==b&&(b=d,a.push(M))}return a}}y.AISImpl=v,y.HifleetImpl=A,y.MyShipImpl=L,y.MyVesselImpl=E,y.ShipxyImpl=C,Object.defineProperty(y,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.0",
4
+ "version": "1.0.1",
5
5
  "description": "idm plugin for vessel",
6
6
  "type": "module",
7
7
  "keywords": [