signalk-flags 1.0.1 → 1.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "signalk-flags",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Country Flags plugin for Signal K server.",
5
5
  "main": "plugin/index.js",
6
6
  "keywords": [
@@ -18,10 +18,11 @@
18
18
  "format": "prettier --write src/*"
19
19
  },
20
20
  "dependencies": {
21
- "@signalk/server-api": "^2.3.0",
21
+ "@signalk/server-api": "^2.9.0",
22
22
  "flag-icons": "^7.3.2"
23
23
  },
24
24
  "devDependencies": {
25
+ "@types/baconjs": "^0.7.34",
25
26
  "@types/express": "^4.17.6",
26
27
  "prettier": "^2.5.1",
27
28
  "typescript": "^4.5.4"
package/plugin/index.d.ts CHANGED
@@ -1,15 +1,4 @@
1
1
  import { Application } from 'express';
2
- import { Delta, ServerAPI } from '@signalk/server-api';
3
- interface SKDeltaSubscription {
4
- context: string;
5
- subscribe: Array<{
6
- path: string;
7
- period: number;
8
- }>;
9
- }
2
+ import { ServerAPI } from '@signalk/server-api';
10
3
  export interface FlagsApp extends ServerAPI, Application {
11
- subscriptionmanager: {
12
- subscribe: (subscribe: SKDeltaSubscription, unsubscribes: Array<any>, errorCallback: (error: any) => void, deltaCallback: (delta: Delta) => void) => void;
13
- };
14
4
  }
15
- export {};
package/plugin/index.js CHANGED
@@ -40,7 +40,6 @@ const promises_1 = require("fs/promises");
40
40
  const path_1 = __importDefault(require("path"));
41
41
  const server_api_1 = require("@signalk/server-api");
42
42
  const openapi = __importStar(require("./openApi.json"));
43
- const mid_1 = require("./mid");
44
43
  const CONFIG_SCHEMA = {
45
44
  properties: {}
46
45
  };
@@ -133,25 +132,29 @@ module.exports = (server) => {
133
132
  }
134
133
  u.values.forEach((v) => {
135
134
  if (v.path === '' && v.value && 'mmsi' in v.value) {
136
- const country = countryFromMmsi(v.value.mmsi);
137
- if (country) {
138
- server.handleMessage(plugin.id, {
139
- context: context,
140
- updates: [
141
- {
142
- values: [
143
- {
144
- path: 'flag',
145
- value: country[0]
146
- },
147
- {
148
- path: 'port',
149
- value: country[3]
150
- }
151
- ]
152
- }
153
- ]
154
- });
135
+ // if doesn't already have flag property
136
+ const vf = server.getPath(`${context}.flag`);
137
+ if (!vf) {
138
+ const country = countryFromMmsi(v.value.mmsi);
139
+ if (country) {
140
+ server.handleMessage(plugin.id, {
141
+ context: context,
142
+ updates: [
143
+ {
144
+ values: [
145
+ {
146
+ path: 'flag',
147
+ value: country.alpha2
148
+ },
149
+ {
150
+ path: 'port',
151
+ value: country.name
152
+ }
153
+ ]
154
+ }
155
+ ]
156
+ });
157
+ }
155
158
  }
156
159
  }
157
160
  });
@@ -237,7 +240,7 @@ module.exports = (server) => {
237
240
  const iconFromMmsi = (mmsi, aspect = '4x3', res) => __awaiter(void 0, void 0, void 0, function* () {
238
241
  try {
239
242
  const country = countryFromMmsi(mmsi);
240
- const flag = `${IMG_BASE_PATH}/${aspect}/${country[0].toLowerCase()}.svg`;
243
+ const flag = `${IMG_BASE_PATH}/${aspect}/${country === null || country === void 0 ? void 0 : country.alpha2.toLowerCase()}.svg`;
241
244
  // check flag file exists
242
245
  yield (0, promises_1.access)(flag, fs_1.constants.R_OK);
243
246
  res.sendFile(flag, (err) => {
@@ -262,14 +265,10 @@ module.exports = (server) => {
262
265
  /**
263
266
  * Get country details from supplied MMSI
264
267
  * @param mmsi Maritime mobile service identifier
265
- * @returns Array containing country details
268
+ * @returns Object containing country details
266
269
  */
267
270
  const countryFromMmsi = (mmsi) => {
268
- if (typeof mmsi === 'number') {
269
- mmsi = mmsi.toString();
270
- }
271
- const mid = mmsi.slice(0, 3);
272
- return mid_1.MID[mid];
271
+ return (0, server_api_1.getFlagCountry)(mmsi);
273
272
  };
274
273
  return plugin;
275
274
  };
package/CHANGELOG.md DELETED
@@ -1,11 +0,0 @@
1
- # CHANGELOG: Signal K Flag Resources - Signal K plugin
2
-
3
- ## v1.0.1
4
-
5
- - **Fix**: Issue where test for MMSI throwing errors.
6
-
7
- ## v1.0.0
8
-
9
- - Initial release.
10
-
11
-