signalk-flags 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/.prettierrc.json +5 -0
- package/CHANGELOG.md +7 -0
- package/LICENSE +201 -0
- package/README.md +60 -0
- package/package.json +35 -0
- package/plugin/index.d.ts +15 -0
- package/plugin/index.js +275 -0
- package/plugin/mid.d.ts +3 -0
- package/plugin/mid.js +296 -0
- package/plugin/openApi.json +175 -0
- package/signalk-flags-1.0.0.tgz +0 -0
package/.prettierrc.json
ADDED
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Signal K Flag Resources Plugin:
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
## About
|
|
5
|
+
|
|
6
|
+
Signal K server plugin that:
|
|
7
|
+
1. Makes country flag images (svg) images available under `/signalk/v2/api/resources/flags`
|
|
8
|
+
1. Populates both the `flag` and `port` attributes for a vessel based on the received MMSI value.
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### HTTP API endpoints
|
|
12
|
+
|
|
13
|
+
Flag images (in svg format) can be retrieved by making HTTP requests to the available API endpoints, the definitions of which can be found in the **Signal K Admin Console** by clicking on **OpenAPI** and selecting **plugins/signalk-flags**.
|
|
14
|
+
|
|
15
|
+
#### Using MMSI
|
|
16
|
+
|
|
17
|
+
- `/signalk/v2/api/resources/flags/mmsi/{vessel_mmsi}`
|
|
18
|
+
|
|
19
|
+
_Example: Return flag image for the MMSI = 211456789_
|
|
20
|
+
```bash
|
|
21
|
+
HTTP GET "/signalk/v2/api/resources/flags/mmsi/211456789
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
#### Using Country Code
|
|
25
|
+
|
|
26
|
+
- `/signalk/v2/api/resources/flags/country/{country_code}`
|
|
27
|
+
|
|
28
|
+
_`country_code` = two-character country code_
|
|
29
|
+
|
|
30
|
+
_Example: Return the New Zealand flag image_
|
|
31
|
+
```bash
|
|
32
|
+
HTTP GET "/signalk/v2/api/resources/flags/country/nz"
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
### Vessel Schema Atttributes
|
|
38
|
+
|
|
39
|
+
The plugin also populates both the `flag` and `port` attributes for a vessel based on the received MMSI value as follows:
|
|
40
|
+
|
|
41
|
+
- `flag` = two letter country code _(e.g. "DE")_
|
|
42
|
+
- `port` = name of the country _(e.g. "Germany")_
|
|
43
|
+
|
|
44
|
+
The attributes are then available as part of the Signal K data model and can be retrieved along with other vessel data.
|
|
45
|
+
|
|
46
|
+
_Example: Fetch vessel details via HTTP request to Signal K API_
|
|
47
|
+
```bash
|
|
48
|
+
HTTP GET "vessels.urn:mrn:signalk:uuid:eec3888d-5925-4e81-b6d4-3d2ff98edeeb"
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
_Example Response:_
|
|
52
|
+
```JSON
|
|
53
|
+
{
|
|
54
|
+
"mmsi": 211456789,
|
|
55
|
+
"name": "My Vessel",
|
|
56
|
+
"flag": "DE",
|
|
57
|
+
"port": "Germany"
|
|
58
|
+
... // remainder of vessel data
|
|
59
|
+
}
|
|
60
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "signalk-flags",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Country Flags plugin for Signal K server.",
|
|
5
|
+
"main": "plugin/index.js",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"signalk-node-server-plugin"
|
|
8
|
+
],
|
|
9
|
+
"repository": "https://github.com/panaaj/signalk-icons",
|
|
10
|
+
"author": "AdrianP",
|
|
11
|
+
"contributors": [
|
|
12
|
+
{
|
|
13
|
+
"name": "panaaj@hotmail.com"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"license": "Apache-20",
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"build-declaration": "tsc --declaration --allowJs false",
|
|
20
|
+
"watch": "npm run build -- -w",
|
|
21
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
22
|
+
"start": "npm run build -- -w",
|
|
23
|
+
"format": "prettier --write src/*"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@signalk/server-api": "^2.3.0",
|
|
27
|
+
"flag-icons": "^7.3.2"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/express": "^4.17.6",
|
|
31
|
+
"prettier": "^2.5.1",
|
|
32
|
+
"typescript": "^4.5.4"
|
|
33
|
+
},
|
|
34
|
+
"signalk-plugin-enabled-by-default": true
|
|
35
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
}
|
|
10
|
+
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
|
+
}
|
|
15
|
+
export {};
|
package/plugin/index.js
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
const fs_1 = require("fs");
|
|
39
|
+
const promises_1 = require("fs/promises");
|
|
40
|
+
const path_1 = __importDefault(require("path"));
|
|
41
|
+
const server_api_1 = require("@signalk/server-api");
|
|
42
|
+
const openapi = __importStar(require("./openApi.json"));
|
|
43
|
+
const mid_1 = require("./mid");
|
|
44
|
+
const CONFIG_SCHEMA = {
|
|
45
|
+
properties: {}
|
|
46
|
+
};
|
|
47
|
+
const CONFIG_UISCHEMA = {};
|
|
48
|
+
module.exports = (server) => {
|
|
49
|
+
let subscriptions = []; // stream subscriptions
|
|
50
|
+
const FLAGS_API_PATH = '/signalk/v2/api/resources/flags';
|
|
51
|
+
let IMG_BASE_PATH = '';
|
|
52
|
+
const plugin = {
|
|
53
|
+
id: 'signalk-flags',
|
|
54
|
+
name: 'Country Flag Resources',
|
|
55
|
+
schema: () => CONFIG_SCHEMA,
|
|
56
|
+
uiSchema: () => CONFIG_UISCHEMA,
|
|
57
|
+
start: (options, restart) => {
|
|
58
|
+
doStartup(options);
|
|
59
|
+
},
|
|
60
|
+
stop: () => {
|
|
61
|
+
doShutdown();
|
|
62
|
+
},
|
|
63
|
+
registerWithRouter: (router) => {
|
|
64
|
+
server.debug(`Required for OpenApi support.`);
|
|
65
|
+
return router;
|
|
66
|
+
},
|
|
67
|
+
getOpenApi: () => Object.assign({}, openapi)
|
|
68
|
+
};
|
|
69
|
+
let settings = {};
|
|
70
|
+
const doStartup = (options) => {
|
|
71
|
+
try {
|
|
72
|
+
server.debug(`${plugin.name} starting.......`);
|
|
73
|
+
if (options) {
|
|
74
|
+
settings = options;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
// save defaults if no options loaded
|
|
78
|
+
server.savePluginOptions(settings, () => {
|
|
79
|
+
server.debug(`Default configuration applied...`);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
server.debug(`Applied configuration: ${JSON.stringify(settings)}`);
|
|
83
|
+
server.setPluginStatus(`Started`);
|
|
84
|
+
// initialise plugin
|
|
85
|
+
initialise();
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
const msg = `Started with errors!`;
|
|
89
|
+
server.setPluginError(msg);
|
|
90
|
+
server.error('error: ' + error);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const doShutdown = () => {
|
|
94
|
+
server.debug(`${plugin.name} stopping.......`);
|
|
95
|
+
server.debug('** Un-registering Update Handler(s) **');
|
|
96
|
+
subscriptions.forEach((b) => b());
|
|
97
|
+
subscriptions = [];
|
|
98
|
+
const msg = 'Stopped.';
|
|
99
|
+
server.setPluginStatus(msg);
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* initialise plugin
|
|
103
|
+
*/
|
|
104
|
+
const initialise = () => {
|
|
105
|
+
server.debug('Initialising ....');
|
|
106
|
+
// setup subscriptions
|
|
107
|
+
initSubscriptions();
|
|
108
|
+
initFs();
|
|
109
|
+
initFlagsEndpoints();
|
|
110
|
+
};
|
|
111
|
+
// register DELTA stream message handler
|
|
112
|
+
const initSubscriptions = () => {
|
|
113
|
+
server.debug('Initialising Stream Subscription....');
|
|
114
|
+
const subscription = {
|
|
115
|
+
context: 'vessels.*',
|
|
116
|
+
subscribe: [
|
|
117
|
+
{
|
|
118
|
+
path: '',
|
|
119
|
+
period: 500
|
|
120
|
+
}
|
|
121
|
+
]
|
|
122
|
+
};
|
|
123
|
+
server.subscriptionmanager.subscribe(subscription, subscriptions, (error) => {
|
|
124
|
+
server.error(`${plugin.id} Error: ${error}`);
|
|
125
|
+
}, (delta) => {
|
|
126
|
+
if (!delta.updates) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const context = delta.context;
|
|
130
|
+
delta.updates.forEach((u) => {
|
|
131
|
+
if (!(0, server_api_1.hasValues)(u)) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
u.values.forEach((v) => {
|
|
135
|
+
if (v.path === '' && '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
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Check filesystem path(s)
|
|
163
|
+
*/
|
|
164
|
+
const initFs = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
165
|
+
const p = path_1.default.resolve(server.getDataDirPath()).split('/');
|
|
166
|
+
const sp = p.slice(0, p.indexOf('.signalk') + 1).join('/');
|
|
167
|
+
// dev env
|
|
168
|
+
const DEV_PATH = path_1.default.join(sp, 'node_modules', plugin.id, 'node_modules', 'flag-icons', 'flags');
|
|
169
|
+
// prod env
|
|
170
|
+
const PRD_PATH = path_1.default.join(sp, 'node_modules', 'flag-icons', 'flags');
|
|
171
|
+
try {
|
|
172
|
+
yield (0, promises_1.access)(PRD_PATH, fs_1.constants.W_OK | fs_1.constants.R_OK);
|
|
173
|
+
server.debug(`${PRD_PATH} - OK...Flag images found.`);
|
|
174
|
+
IMG_BASE_PATH = PRD_PATH;
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
server.debug(`${PRD_PATH} does NOT exist!`);
|
|
178
|
+
server.debug(`Trying secondary path....${DEV_PATH}`);
|
|
179
|
+
try {
|
|
180
|
+
yield (0, promises_1.access)(DEV_PATH, fs_1.constants.W_OK | fs_1.constants.R_OK);
|
|
181
|
+
server.debug(`${DEV_PATH} - OK...Flag images found.`);
|
|
182
|
+
IMG_BASE_PATH = DEV_PATH;
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
server.debug(`${DEV_PATH} does NOT exist either!`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
/**
|
|
190
|
+
* Initialise flag resource endpoints
|
|
191
|
+
*/
|
|
192
|
+
const initFlagsEndpoints = () => {
|
|
193
|
+
server.debug(`** Registering Flag resources endpoint(s) **`);
|
|
194
|
+
server.get(`${FLAGS_API_PATH}/mmsi/:mmsi`, (req, res) => {
|
|
195
|
+
server.debug(`** ${req.method} ${req.path}`);
|
|
196
|
+
iconFromMmsi(req.params.mmsi, req.query.aspect, res);
|
|
197
|
+
});
|
|
198
|
+
server.get(`${FLAGS_API_PATH}/country/:code`, (req, res) => {
|
|
199
|
+
server.debug(`** ${req.method} ${req.path}`);
|
|
200
|
+
iconFromCountryCode(req.params.code, req.query.aspect, res);
|
|
201
|
+
});
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* Send flag for the supplied two letter country code
|
|
205
|
+
* @param aspect Aspect ratio default= '4x3'
|
|
206
|
+
* @returns svg file contents
|
|
207
|
+
*/
|
|
208
|
+
const iconFromCountryCode = (code, aspect = '4x3', res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
209
|
+
try {
|
|
210
|
+
const flag = `${IMG_BASE_PATH}/${aspect}/${code.toLowerCase()}.svg`;
|
|
211
|
+
// check flag file exists
|
|
212
|
+
yield (0, promises_1.access)(flag, fs_1.constants.R_OK);
|
|
213
|
+
res.sendFile(flag, (err) => {
|
|
214
|
+
if (err) {
|
|
215
|
+
res.status(400).json({
|
|
216
|
+
state: 'FAILED',
|
|
217
|
+
statusCode: 400,
|
|
218
|
+
message: err.message
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
res.status(400).json({
|
|
225
|
+
state: 'FAILED',
|
|
226
|
+
statusCode: 400,
|
|
227
|
+
message: `Flag for supplied country code (${code}) NOT found!`
|
|
228
|
+
});
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
/**
|
|
233
|
+
* Send flag derived from the supplied MMSI
|
|
234
|
+
* @param aspect Flag icon aspect ratio '1x1' or '4x3'
|
|
235
|
+
* @returns svg file contents
|
|
236
|
+
*/
|
|
237
|
+
const iconFromMmsi = (mmsi, aspect = '4x3', res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
238
|
+
try {
|
|
239
|
+
const country = countryFromMmsi(mmsi);
|
|
240
|
+
const flag = `${IMG_BASE_PATH}/${aspect}/${country[0].toLowerCase()}.svg`;
|
|
241
|
+
// check flag file exists
|
|
242
|
+
yield (0, promises_1.access)(flag, fs_1.constants.R_OK);
|
|
243
|
+
res.sendFile(flag, (err) => {
|
|
244
|
+
if (err) {
|
|
245
|
+
res.status(400).json({
|
|
246
|
+
state: 'FAILED',
|
|
247
|
+
statusCode: 400,
|
|
248
|
+
message: err.message
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
catch (error) {
|
|
254
|
+
res.status(400).json({
|
|
255
|
+
state: 'FAILED',
|
|
256
|
+
statusCode: 400,
|
|
257
|
+
message: `Flag for supplied MMSI (${mmsi}) not found!`
|
|
258
|
+
});
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
/**
|
|
263
|
+
* Get country details from supplied MMSI
|
|
264
|
+
* @param mmsi Maritime mobile service identifier
|
|
265
|
+
* @returns Array containing country details
|
|
266
|
+
*/
|
|
267
|
+
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];
|
|
273
|
+
};
|
|
274
|
+
return plugin;
|
|
275
|
+
};
|
package/plugin/mid.d.ts
ADDED
package/plugin/mid.js
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MID = void 0;
|
|
4
|
+
// source: https://github.com/michaeljfazio/MIDs/blob/master/mids.json
|
|
5
|
+
exports.MID = {
|
|
6
|
+
'201': ['AL', 'ALB', '', 'Albania'],
|
|
7
|
+
'202': ['AD', 'AND', '', 'Andorra'],
|
|
8
|
+
'203': ['AT', 'AUT', '', 'Austria'],
|
|
9
|
+
'204': ['PT', 'PRT', 'PT-20', 'Azores'],
|
|
10
|
+
'205': ['BE', 'BEL', '', 'Belgium'],
|
|
11
|
+
'206': ['BY', 'BLR', '', 'Belarus'],
|
|
12
|
+
'207': ['BG', 'BGR', '', 'Bulgaria'],
|
|
13
|
+
'208': ['VA', 'VAT', '', 'Vatican City State'],
|
|
14
|
+
'209': ['CY', 'CYP', '', 'Cyprus'],
|
|
15
|
+
'210': ['CY', 'CYP', '', 'Cyprus'],
|
|
16
|
+
'211': ['DE', 'DEU', '', 'Germany'],
|
|
17
|
+
'212': ['CY', 'CYP', '', 'Cyprus'],
|
|
18
|
+
'213': ['GE', 'GEO', '', 'Georgia'],
|
|
19
|
+
'214': ['MD', 'MDA', '', 'Moldova'],
|
|
20
|
+
'215': ['MT', 'MLT', '', 'Malta'],
|
|
21
|
+
'216': ['AM', 'ARM', '', 'Armenia'],
|
|
22
|
+
'218': ['DE', 'DEU', '', 'Germany'],
|
|
23
|
+
'219': ['DK', 'DNK', '', 'Denmark'],
|
|
24
|
+
'220': ['DK', 'DNK', '', 'Denmark'],
|
|
25
|
+
'224': ['ES', 'ESP', '', 'Spain'],
|
|
26
|
+
'225': ['ES', 'ESP', '', 'Spain'],
|
|
27
|
+
'226': ['FR', 'FRA', '', 'France'],
|
|
28
|
+
'227': ['FR', 'FRA', '', 'France'],
|
|
29
|
+
'228': ['FR', 'FRA', '', 'France'],
|
|
30
|
+
'229': ['MT', 'MLT', '', 'Malta'],
|
|
31
|
+
'230': ['FI', 'FIN', '', 'Finland'],
|
|
32
|
+
'231': ['FO', 'FRO', '', 'Faroe Islands'],
|
|
33
|
+
'232': ['GB', 'GBR', '', 'United Kingdom'],
|
|
34
|
+
'233': ['GB', 'GBR', '', 'United Kingdom'],
|
|
35
|
+
'234': ['GB', 'GBR', '', 'United Kingdom'],
|
|
36
|
+
'235': ['GB', 'GBR', '', 'United Kingdom'],
|
|
37
|
+
'236': ['GI', 'GIB', '', 'Gibraltar'],
|
|
38
|
+
'237': ['GR', 'GRC', '', 'Greece'],
|
|
39
|
+
'238': ['HR', 'HRV', '', 'Croatia'],
|
|
40
|
+
'239': ['GR', 'GRC', '', 'Greece'],
|
|
41
|
+
'240': ['GR', 'GRC', '', 'Greece'],
|
|
42
|
+
'241': ['GR', 'GRC', '', 'Greece'],
|
|
43
|
+
'242': ['MA', 'MAR', '', 'Morocco'],
|
|
44
|
+
'243': ['HU', 'HUN', '', 'Hungary'],
|
|
45
|
+
'244': ['NL', 'NLD', '', 'Netherlands'],
|
|
46
|
+
'245': ['NL', 'NLD', '', 'Netherlands'],
|
|
47
|
+
'246': ['NL', 'NLD', '', 'Netherlands'],
|
|
48
|
+
'247': ['IT', 'ITA', '', 'Italy'],
|
|
49
|
+
'248': ['MT', 'MLT', '', 'Malta'],
|
|
50
|
+
'249': ['MT', 'MLT', '', 'Malta'],
|
|
51
|
+
'250': ['IE', 'IRL', '', 'Ireland'],
|
|
52
|
+
'251': ['IS', 'ISL', '', 'Iceland'],
|
|
53
|
+
'252': ['LI', 'LIE', '', 'Liechtenstein'],
|
|
54
|
+
'253': ['LU', 'LUX', '', 'Luxembourg'],
|
|
55
|
+
'254': ['MC', 'MCO', '', 'Monaco'],
|
|
56
|
+
'255': ['PT', 'PRT', 'PT-30', 'Madeira'],
|
|
57
|
+
'256': ['MT', 'MLT', '', 'Malta'],
|
|
58
|
+
'257': ['NO', 'NOR', '', 'Norway'],
|
|
59
|
+
'258': ['NO', 'NOR', '', 'Norway'],
|
|
60
|
+
'259': ['NO', 'NOR', '', 'Norway'],
|
|
61
|
+
'261': ['PL', 'POL', '', 'Poland'],
|
|
62
|
+
'262': ['ME', 'MNE', '', 'Montenegro'],
|
|
63
|
+
'263': ['PT', 'PRT', '', 'Portugal'],
|
|
64
|
+
'264': ['RO', 'ROU', '', 'Romania'],
|
|
65
|
+
'265': ['SE', 'SWE', '', 'Sweden'],
|
|
66
|
+
'266': ['SE', 'SWE', '', 'Sweden'],
|
|
67
|
+
'267': ['SK', 'SVK', '', 'Slovak Republic'],
|
|
68
|
+
'268': ['SM', 'SMR', '', 'San Marino'],
|
|
69
|
+
'269': ['CH', 'CHE', '', 'Switzerland'],
|
|
70
|
+
'270': ['CZ', 'CZE', '', 'Czech Republic'],
|
|
71
|
+
'271': ['TR', 'TUR', '', 'Turkey'],
|
|
72
|
+
'272': ['UA', 'UKR', '', 'Ukraine'],
|
|
73
|
+
'273': ['RU', 'RUS', '', 'Russia'],
|
|
74
|
+
'274': ['MK', 'MKD', '', 'Macedonia'],
|
|
75
|
+
'275': ['LV', 'LVA', '', 'Latvia'],
|
|
76
|
+
'276': ['EE', 'EST', '', 'Estonia'],
|
|
77
|
+
'277': ['LT', 'LTU', '', 'Lithuania'],
|
|
78
|
+
'278': ['SI', 'SVN', '', 'Slovenia'],
|
|
79
|
+
'279': ['RS', 'SRB', '', 'Serbia'],
|
|
80
|
+
'301': ['AI', 'AIA', '', 'Anguilla'],
|
|
81
|
+
'303': ['US', 'USA', 'US-AK', 'Alaska'],
|
|
82
|
+
'304': ['AG', 'ATG', '', 'Antigua and Barbuda'],
|
|
83
|
+
'305': ['AG', 'ATG', '', 'Antigua and Barbuda'],
|
|
84
|
+
'306': ['CW', 'CUW', '', 'Antilles'],
|
|
85
|
+
'307': ['AW', 'ABW', '', 'Aruba'],
|
|
86
|
+
'308': ['BS', 'BHS', '', 'Bahamas'],
|
|
87
|
+
'309': ['BS', 'BHS', '', 'Bahamas'],
|
|
88
|
+
'310': ['BM', 'BMU', '', 'Bermuda'],
|
|
89
|
+
'311': ['BS', 'BMU', '', 'Bahamas'],
|
|
90
|
+
'312': ['BZ', 'BLZ', '', 'Belize'],
|
|
91
|
+
'314': ['BB', 'BRB', '', 'Barbados'],
|
|
92
|
+
'316': ['CA', 'CAN', '', 'Canada'],
|
|
93
|
+
'319': ['KY', 'CYM', '', 'Cayman Islands'],
|
|
94
|
+
'321': ['CR', 'CRI', '', 'Costa Rica'],
|
|
95
|
+
'323': ['CU', 'CUB', '', 'Cuba'],
|
|
96
|
+
'325': ['DM', 'DMA', '', 'Dominica'],
|
|
97
|
+
'327': ['DO', 'DOM', '', 'Dominican Republic'],
|
|
98
|
+
'329': ['GP', 'GLP', '', 'Guadeloupe'],
|
|
99
|
+
'330': ['GD', 'GRD', '', 'Grenada'],
|
|
100
|
+
'331': ['GL', 'GRL', '', 'Greenland'],
|
|
101
|
+
'332': ['GT', 'GTM', '', 'Guatemala'],
|
|
102
|
+
'335': ['HN', 'HND', '', 'Honduras'],
|
|
103
|
+
'336': ['HT', 'HTI', '', 'Haiti'],
|
|
104
|
+
'338': ['US', 'USA', '', 'United States of America'],
|
|
105
|
+
'339': ['JM', 'JAM', '', 'Jamaica'],
|
|
106
|
+
'341': ['KN', 'KNA', '', 'Saint Kitts and Nevis'],
|
|
107
|
+
'343': ['LC', 'LCA', '', 'Saint Lucia'],
|
|
108
|
+
'345': ['MX', 'MEX', '', 'Mexico'],
|
|
109
|
+
'347': ['MQ', 'MTQ', '', 'Martinique'],
|
|
110
|
+
'348': ['MS', 'MSR', '', 'Montserrat'],
|
|
111
|
+
'350': ['NI', 'NIC', '', 'Nicaragua'],
|
|
112
|
+
'351': ['PA', 'PAN', '', 'Panama'],
|
|
113
|
+
'352': ['PA', 'PAN', '', 'Panama'],
|
|
114
|
+
'353': ['PA', 'PAN', '', 'Panama'],
|
|
115
|
+
'354': ['PA', 'PAN', '', 'Panama'],
|
|
116
|
+
'355': ['PA', 'PAN', '', 'Panama'],
|
|
117
|
+
'356': ['PA', 'PAN', '', 'Panama'],
|
|
118
|
+
'357': ['PA', 'PAN', '', 'Panama'],
|
|
119
|
+
'358': ['PR', 'PRI', '', 'Puerto Rico'],
|
|
120
|
+
'359': ['SV', 'SLV', '', 'El Salvador'],
|
|
121
|
+
'361': ['PM', 'SPM', '', 'Saint Pierre and Miquelon'],
|
|
122
|
+
'362': ['TT', 'TTO', '', 'Trinidad and Tobago'],
|
|
123
|
+
'364': ['TC', 'TCA', '', 'Turks and Caicos Islands'],
|
|
124
|
+
'366': ['US', 'USA', '', 'United States of America'],
|
|
125
|
+
'367': ['US', 'USA', '', 'United States of America'],
|
|
126
|
+
'368': ['US', 'USA', '', 'United States of America'],
|
|
127
|
+
'369': ['US', 'USA', '', 'United States of America'],
|
|
128
|
+
'370': ['PA', 'PAN', '', 'Panama'],
|
|
129
|
+
'371': ['PA', 'PAN', '', 'Panama'],
|
|
130
|
+
'372': ['PA', 'PAN', '', 'Panama'],
|
|
131
|
+
'373': ['PA', 'PAN', '', 'Panama'],
|
|
132
|
+
'374': ['PA', 'PAN', '', 'Panama'],
|
|
133
|
+
'375': ['VC', 'VCT', '', 'Saint Vincent and the Grenadines'],
|
|
134
|
+
'376': ['VC', 'VCT', '', 'Saint Vincent and the Grenadines'],
|
|
135
|
+
'377': ['VC', 'VCT', '', 'Saint Vincent and the Grenadines'],
|
|
136
|
+
'378': ['VG', 'VGB', '', 'British Virgin Islands'],
|
|
137
|
+
'379': ['VI', 'VIR', '', 'United States Virgin Islands'],
|
|
138
|
+
'401': ['AF', 'AFG', '', 'Afghanistan'],
|
|
139
|
+
'403': ['SA', 'SAU', '', 'Saudi Arabia'],
|
|
140
|
+
'405': ['BD', 'BGD', '', 'Bangladesh'],
|
|
141
|
+
'408': ['BH', 'BHR', '', 'Bahrain'],
|
|
142
|
+
'410': ['BT', 'BTN', '', 'Bhutan'],
|
|
143
|
+
'412': ['CN', 'CHN', '', 'China'],
|
|
144
|
+
'413': ['CN', 'CHN', '', 'China'],
|
|
145
|
+
'414': ['CN', 'CHN', '', 'China'],
|
|
146
|
+
'416': ['TW', 'TWN', '', 'Taiwan'],
|
|
147
|
+
'417': ['LK', 'LKA', '', 'Sri Lanka'],
|
|
148
|
+
'419': ['IN', 'IND', '', 'India'],
|
|
149
|
+
'422': ['IR', 'IRN', '', 'Iran'],
|
|
150
|
+
'423': ['AZ', 'AZE', '', 'Azerbaijan'],
|
|
151
|
+
'425': ['IQ', 'IRQ', '', 'Iraq'],
|
|
152
|
+
'428': ['IL', 'ISR', '', 'Israel'],
|
|
153
|
+
'431': ['JP', 'JPN', '', 'Japan'],
|
|
154
|
+
'432': ['JP', 'JPN', '', 'Japan'],
|
|
155
|
+
'434': ['TM', 'TKM', '', 'Turkmenistan'],
|
|
156
|
+
'436': ['KZ', 'KAZ', '', 'Kazakhstan'],
|
|
157
|
+
'437': ['UZ', 'UZB', '', 'Uzbekistan'],
|
|
158
|
+
'438': ['JO', 'JOR', '', 'Jordan'],
|
|
159
|
+
'440': ['KR', 'KOR', '', 'Korea'],
|
|
160
|
+
'441': ['KR', 'KOR', '', 'Korea'],
|
|
161
|
+
'443': ['PS', 'PSE', '', 'State of Palestine'],
|
|
162
|
+
'445': ['KP', 'PRK', '', "Democratic People's Republic of Korea"],
|
|
163
|
+
'447': ['KW', 'KWT', '', 'Kuwait'],
|
|
164
|
+
'450': ['LB', 'LBN', '', 'Lebanon'],
|
|
165
|
+
'451': ['KG', 'KGZ', '', 'Kyrgyz Republic'],
|
|
166
|
+
'453': ['MO', 'MAC', '', 'Macao'],
|
|
167
|
+
'455': ['MV', 'MDV', '', 'Maldives'],
|
|
168
|
+
'457': ['MN', 'MNG', '', 'Mongolia'],
|
|
169
|
+
'459': ['NP', 'NPL', '', 'Nepal'],
|
|
170
|
+
'461': ['OM', 'OMN', '', 'Oman'],
|
|
171
|
+
'463': ['PK', 'PAK', '', 'Pakistan'],
|
|
172
|
+
'466': ['QA', 'QAT', '', 'Qatar (State of)'],
|
|
173
|
+
'468': ['SY', 'SYR', '', 'Syrian Arab Republic'],
|
|
174
|
+
'470': ['AE', 'ARE', '', 'United Arab Emirates'],
|
|
175
|
+
'472': ['TJ', 'TJK', '', 'Tajikistan'],
|
|
176
|
+
'473': ['YE', 'YEM', '', 'Yemen'],
|
|
177
|
+
'475': ['YE', 'YEM', '', 'Yemen'],
|
|
178
|
+
'477': ['HK', 'HKG', '', 'Hong Kong'],
|
|
179
|
+
'478': ['BA', 'BIH', '', 'Bosnia and Herzegovina'],
|
|
180
|
+
'501': ['FR', 'FRA', 'AQ', 'Adelie Land'],
|
|
181
|
+
'503': ['AU', 'AUS', '', 'Australia'],
|
|
182
|
+
'506': ['MM', 'MMR', '', 'Myanmar'],
|
|
183
|
+
'508': ['BN', 'BRN', '', 'Brunei Darussalam'],
|
|
184
|
+
'510': ['FM', 'FSM', '', 'Micronesia'],
|
|
185
|
+
'511': ['PW', 'PLW', '', 'Palau'],
|
|
186
|
+
'512': ['NZ', 'NZL', '', 'New Zealand'],
|
|
187
|
+
'514': ['KH', 'KHM', '', 'Cambodia'],
|
|
188
|
+
'515': ['KH', 'KHM', '', 'Cambodia'],
|
|
189
|
+
'516': ['CX', 'CXR', '', 'Christmas Island'],
|
|
190
|
+
'518': ['CK', 'COK', '', 'Cook Islands'],
|
|
191
|
+
'520': ['FJ', 'FJI', '', 'Fiji'],
|
|
192
|
+
'523': ['CC', 'CCK', '', 'Cocos (Keeling) Islands'],
|
|
193
|
+
'525': ['ID', 'IDN', '', 'Indonesia'],
|
|
194
|
+
'529': ['KI', 'KIR', '', 'Kiribati'],
|
|
195
|
+
'531': ['LA', 'LAO', '', "Lao People's Democratic Republic"],
|
|
196
|
+
'533': ['MY', 'MYS', '', 'Malaysia'],
|
|
197
|
+
'536': ['MP', 'MNP', '', 'Northern Mariana Islands'],
|
|
198
|
+
'538': ['MH', 'MHL', '', 'Marshall Islands'],
|
|
199
|
+
'540': ['NC', 'NCL', '', 'New Caledonia'],
|
|
200
|
+
'542': ['NU', 'NIU', '', 'Niue'],
|
|
201
|
+
'544': ['NR', 'NRU', '', 'Nauru'],
|
|
202
|
+
'546': ['PF', 'PYF', '', 'French Polynesia'],
|
|
203
|
+
'548': ['PH', 'PHL', '', 'Philippines'],
|
|
204
|
+
'553': ['PG', 'PNG', '', 'Papua New Guinea'],
|
|
205
|
+
'555': ['PN', 'PCN', '', 'Pitcairn Island'],
|
|
206
|
+
'557': ['SB', 'SLB', '', 'Solomon Islands'],
|
|
207
|
+
'559': ['AS', 'ASM', '', 'American Samoa'],
|
|
208
|
+
'561': ['WS', 'WSM', '', 'Samoa'],
|
|
209
|
+
'563': ['SG', 'SGP', '', 'Singapore'],
|
|
210
|
+
'564': ['SG', 'SGP', '', 'Singapore'],
|
|
211
|
+
'565': ['SG', 'SGP', '', 'Singapore'],
|
|
212
|
+
'566': ['SG', 'SGP', '', 'Singapore'],
|
|
213
|
+
'567': ['TH', 'THA', '', 'Thailand'],
|
|
214
|
+
'570': ['TO', 'TON', '', 'Tonga'],
|
|
215
|
+
'572': ['TV', 'TUV', '', 'Tuvalu'],
|
|
216
|
+
'574': ['VN', 'VNM', '', 'Viet Nam'],
|
|
217
|
+
'576': ['VU', 'VUT', '', 'Vanuatu'],
|
|
218
|
+
'577': ['VU', 'VUT', '', 'Vanuatu'],
|
|
219
|
+
'578': ['WF', 'WLF', '', 'Wallis and Futuna Islands'],
|
|
220
|
+
'601': ['ZA', 'ZAF', '', 'South Africa'],
|
|
221
|
+
'603': ['AO', 'AGO', '', 'Angola'],
|
|
222
|
+
'605': ['DZ', 'DZA', '', 'Algeria'],
|
|
223
|
+
'607': ['FR', 'FRA', 'TF', 'Saint Paul and Amsterdam Islands'],
|
|
224
|
+
'608': ['GB', 'GBR', 'AC', 'Ascension Island'],
|
|
225
|
+
'609': ['BI', 'BDI', '', 'Burundi'],
|
|
226
|
+
'610': ['BJ', 'BEN', '', 'Benin'],
|
|
227
|
+
'611': ['BW', 'BWA', '', 'Botswana'],
|
|
228
|
+
'612': ['CF', 'CAF', '', 'Central African Republic'],
|
|
229
|
+
'613': ['CM', 'CMR', '', 'Cameroon'],
|
|
230
|
+
'615': ['CG', 'COG', '', 'Congo'],
|
|
231
|
+
'616': ['KM', 'COM', '', 'Comoros'],
|
|
232
|
+
'617': ['CV', 'CPV', '', 'Cabo Verde'],
|
|
233
|
+
'618': ['FR', 'FRA', 'TF', 'Crozet Archipelago'],
|
|
234
|
+
'619': ['CI', 'CIV', '', 'Ivory Coast'],
|
|
235
|
+
'620': ['KM', 'COM', '', 'Comoros'],
|
|
236
|
+
'621': ['DJ', 'DJI', '', 'Djibouti'],
|
|
237
|
+
'622': ['EG', 'EGY', '', 'Egypt'],
|
|
238
|
+
'624': ['ET', 'ETH', '', 'Ethiopia'],
|
|
239
|
+
'625': ['ER', 'ERI', '', 'Eritrea'],
|
|
240
|
+
'626': ['GA', 'GAB', '', 'Gabonese Republic'],
|
|
241
|
+
'627': ['GH', 'GHA', '', 'Ghana'],
|
|
242
|
+
'629': ['GM', 'GMB', '', 'Gambia'],
|
|
243
|
+
'630': ['GW', 'GNB', '', 'Guinea-Bissau'],
|
|
244
|
+
'631': ['GQ', 'GNQ', '', 'Equatorial Guinea'],
|
|
245
|
+
'632': ['GN', 'GIN', '', 'Guinea'],
|
|
246
|
+
'633': ['BF', 'BFA', '', 'Burkina Faso'],
|
|
247
|
+
'634': ['KE', 'KEN', '', 'Kenya'],
|
|
248
|
+
'635': ['FR', 'FRA', 'TF', 'Kerguelen Islands'],
|
|
249
|
+
'636': ['LR', 'LBR', '', 'Liberia'],
|
|
250
|
+
'637': ['LR', 'LBR', '', 'Liberia'],
|
|
251
|
+
'638': ['SS', 'SSD', '', 'South Sudan'],
|
|
252
|
+
'642': ['LY', 'LBY', '', 'Libya'],
|
|
253
|
+
'644': ['LS', 'LSO', '', 'Lesotho'],
|
|
254
|
+
'645': ['MU', 'MUS', '', 'Mauritius'],
|
|
255
|
+
'647': ['MG', 'MDG', '', 'Madagascar'],
|
|
256
|
+
'649': ['ML', 'MLI', '', 'Mali'],
|
|
257
|
+
'650': ['MZ', 'MOZ', '', 'Mozambique'],
|
|
258
|
+
'654': ['MR', 'MRT', '', 'Mauritania'],
|
|
259
|
+
'655': ['MW', 'MWI', '', 'Malawi'],
|
|
260
|
+
'656': ['NE', 'NER', '', 'Niger'],
|
|
261
|
+
'657': ['NG', 'NGA', '', 'Nigeria'],
|
|
262
|
+
'659': ['NA', 'NAM', '', 'Namibia'],
|
|
263
|
+
'660': ['RE', 'REU', '', 'Reunion'],
|
|
264
|
+
'661': ['RW', 'RWA', '', 'Rwanda'],
|
|
265
|
+
'662': ['SD', 'SDN', '', 'Sudan'],
|
|
266
|
+
'663': ['SN', 'SEN', '', 'Senegal'],
|
|
267
|
+
'664': ['SC', 'SYC', '', 'Seychelles'],
|
|
268
|
+
'665': ['SH', 'SHN', '', 'Saint Helena'],
|
|
269
|
+
'666': ['SO', 'SOM', '', 'Somali Democratic Republic'],
|
|
270
|
+
'667': ['SL', 'SLE', '', 'Sierra Leone'],
|
|
271
|
+
'668': ['ST', 'STP', '', 'Sao Tome and Principe'],
|
|
272
|
+
'669': ['SZ', 'SWZ', '', 'Swaziland'],
|
|
273
|
+
'670': ['TD', 'TCD', '', 'Chad'],
|
|
274
|
+
'671': ['TG', 'TGO', '', 'Togolese Republic'],
|
|
275
|
+
'672': ['TN', 'TUN', '', 'Tunisian Republic'],
|
|
276
|
+
'674': ['TZ', 'TZA', '', 'Tanzania'],
|
|
277
|
+
'675': ['UG', 'UGA', '', 'Uganda'],
|
|
278
|
+
'676': ['CD', 'COD', '', 'Democratic Republic of the Congo'],
|
|
279
|
+
'677': ['TZ', 'TZA', '', 'Tanzania'],
|
|
280
|
+
'678': ['ZM', 'ZMB', '', 'Zambia'],
|
|
281
|
+
'679': ['ZW', 'ZWE', '', 'Zimbabwe'],
|
|
282
|
+
'701': ['AR', 'ARG', '', 'Argentine Republic'],
|
|
283
|
+
'710': ['BR', 'BRA', '', 'Brazil'],
|
|
284
|
+
'720': ['BO', 'BOL', '', 'Bolivia'],
|
|
285
|
+
'725': ['CL', 'CHL', '', 'Chile'],
|
|
286
|
+
'730': ['CO', 'COL', '', 'Colombia'],
|
|
287
|
+
'735': ['EC', 'ECU', '', 'Ecuador'],
|
|
288
|
+
'740': ['FK', 'FLK', '', 'Falkland Islands'],
|
|
289
|
+
'745': ['GF', 'GUF', '', 'Guiana'],
|
|
290
|
+
'750': ['GY', 'GUY', '', 'Guyana'],
|
|
291
|
+
'755': ['PY', 'PRY', '', 'Paraguay'],
|
|
292
|
+
'760': ['PE', 'PER', '', 'Peru'],
|
|
293
|
+
'765': ['SR', 'SUR', '', 'Suriname'],
|
|
294
|
+
'770': ['UY', 'URY', '', 'Uruguay'],
|
|
295
|
+
'775': ['VE', 'VEN', '', 'Venezuela']
|
|
296
|
+
};
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
{
|
|
2
|
+
"openapi": "3.0.0",
|
|
3
|
+
"info": {
|
|
4
|
+
"version": "2.5.0",
|
|
5
|
+
"title": "Signal K Flags API",
|
|
6
|
+
"description": "API endpoints exposed by `signalk-flags` plugin for displaying flags based on MMSI or country code.",
|
|
7
|
+
"termsOfService": "http://signalk.org/terms/",
|
|
8
|
+
"license": {
|
|
9
|
+
"name": "Apache 2.0",
|
|
10
|
+
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"externalDocs": {
|
|
14
|
+
"url": "http://signalk.org/specification/",
|
|
15
|
+
"description": "Signal K specification."
|
|
16
|
+
},
|
|
17
|
+
"servers": [
|
|
18
|
+
{
|
|
19
|
+
"url": "/"
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"tags": [
|
|
23
|
+
{
|
|
24
|
+
"name": "Flags",
|
|
25
|
+
"description": "Endpoints for retrieving country flags."
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"components": {
|
|
29
|
+
"schemas": {},
|
|
30
|
+
"responses": {
|
|
31
|
+
"200OKResponse": {
|
|
32
|
+
"description": "Successful operation",
|
|
33
|
+
"content": {
|
|
34
|
+
"application/json": {
|
|
35
|
+
"schema": {
|
|
36
|
+
"type": "object",
|
|
37
|
+
"description": "Request success response",
|
|
38
|
+
"properties": {
|
|
39
|
+
"state": {
|
|
40
|
+
"type": "string",
|
|
41
|
+
"enum": ["COMPLETED"]
|
|
42
|
+
},
|
|
43
|
+
"statusCode": {
|
|
44
|
+
"type": "number",
|
|
45
|
+
"enum": [200]
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"required": ["state", "statusCode"]
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"ErrorResponse": {
|
|
54
|
+
"description": "Failed operation",
|
|
55
|
+
"content": {
|
|
56
|
+
"application/json": {
|
|
57
|
+
"schema": {
|
|
58
|
+
"type": "object",
|
|
59
|
+
"description": "Request error response",
|
|
60
|
+
"properties": {
|
|
61
|
+
"state": {
|
|
62
|
+
"type": "string",
|
|
63
|
+
"enum": ["FAILED"]
|
|
64
|
+
},
|
|
65
|
+
"statusCode": {
|
|
66
|
+
"type": "number",
|
|
67
|
+
"enum": [404]
|
|
68
|
+
},
|
|
69
|
+
"message": {
|
|
70
|
+
"type": "string"
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"required": ["state", "statusCode", "message"]
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"parameters": {
|
|
80
|
+
"mmsi": {
|
|
81
|
+
"in": "path",
|
|
82
|
+
"required": true,
|
|
83
|
+
"name": "mmsi",
|
|
84
|
+
"description": "Maritime Mobile Service Identity (MMSI).",
|
|
85
|
+
"schema": {
|
|
86
|
+
"type": "number",
|
|
87
|
+
"minLength": 9,
|
|
88
|
+
"maxLength": 9,
|
|
89
|
+
"example": 520345561
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
"countryCode": {
|
|
93
|
+
"in": "path",
|
|
94
|
+
"required": true,
|
|
95
|
+
"name": "code",
|
|
96
|
+
"description": "Two letter country code.",
|
|
97
|
+
"schema": {
|
|
98
|
+
"type": "string",
|
|
99
|
+
"minLength": 2,
|
|
100
|
+
"maxLength": 2,
|
|
101
|
+
"example": "al"
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
"aspect": {
|
|
105
|
+
"in": "query",
|
|
106
|
+
"required": false,
|
|
107
|
+
"name": "aspect",
|
|
108
|
+
"description": "Aspect of flag image to return. 4x3 (default)",
|
|
109
|
+
"schema": {
|
|
110
|
+
"type": "string",
|
|
111
|
+
"enum": ["4x3", "1x1"]
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
"securitySchemes": {
|
|
116
|
+
"bearerAuth": {
|
|
117
|
+
"type": "http",
|
|
118
|
+
"scheme": "bearer",
|
|
119
|
+
"bearerFormat": "JWT"
|
|
120
|
+
},
|
|
121
|
+
"cookieAuth": {
|
|
122
|
+
"type": "apiKey",
|
|
123
|
+
"in": "cookie",
|
|
124
|
+
"name": "JAUTHENTICATION"
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
"security": [{ "cookieAuth": [] }, { "bearerAuth": [] }],
|
|
129
|
+
"paths": {
|
|
130
|
+
"/signalk/v2/api/resources/flags/mmsi/{mmsi}": {
|
|
131
|
+
"parameters": [
|
|
132
|
+
{
|
|
133
|
+
"$ref": "#/components/parameters/mmsi"
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"$ref": "#/components/parameters/aspect"
|
|
137
|
+
}
|
|
138
|
+
],
|
|
139
|
+
"get": {
|
|
140
|
+
"tags": ["Flags"],
|
|
141
|
+
"summary": "Returns flag for supplied MMSI.",
|
|
142
|
+
"responses": {
|
|
143
|
+
"default": {
|
|
144
|
+
"description": "Return SVG content for flag derived from the supplied MMSI.",
|
|
145
|
+
"content": {
|
|
146
|
+
"image/svg+xml": {}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
"/signalk/v2/api/resources/flags/country/{code}": {
|
|
153
|
+
"parameters": [
|
|
154
|
+
{
|
|
155
|
+
"$ref": "#/components/parameters/countryCode"
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"$ref": "#/components/parameters/aspect"
|
|
159
|
+
}
|
|
160
|
+
],
|
|
161
|
+
"get": {
|
|
162
|
+
"tags": ["Flags"],
|
|
163
|
+
"summary": "Returns flag for supplied country code.",
|
|
164
|
+
"responses": {
|
|
165
|
+
"default": {
|
|
166
|
+
"description": "Return SVG content for flag derived from the supplied country code.",
|
|
167
|
+
"content": {
|
|
168
|
+
"image/svg+xml": {}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
Binary file
|