@tak-ps/node-tak 11.18.1 → 11.19.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/.github/workflows/release.yml +3 -0
- package/CHANGELOG.md +8 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +183 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.js +204 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/api/certificate.d.ts +70 -0
- package/dist/lib/api/certificate.js +62 -0
- package/dist/lib/api/certificate.js.map +1 -0
- package/dist/lib/api/contacts.d.ts +24 -0
- package/dist/lib/api/contacts.js +44 -0
- package/dist/lib/api/contacts.js.map +1 -0
- package/dist/lib/api/credentials.d.ts +21 -0
- package/dist/lib/api/credentials.js +83 -0
- package/dist/lib/api/credentials.js.map +1 -0
- package/dist/lib/api/export.d.ts +21 -0
- package/dist/lib/api/export.js +37 -0
- package/dist/lib/api/export.js.map +1 -0
- package/dist/lib/api/files.d.ts +77 -0
- package/dist/lib/api/files.js +170 -0
- package/dist/lib/api/files.js.map +1 -0
- package/dist/lib/api/groups.d.ts +43 -0
- package/dist/lib/api/groups.js +68 -0
- package/dist/lib/api/groups.js.map +1 -0
- package/dist/lib/api/iconsets.d.ts +27 -0
- package/dist/lib/api/iconsets.js +42 -0
- package/dist/lib/api/iconsets.js.map +1 -0
- package/dist/lib/api/injectors.d.ts +52 -0
- package/dist/lib/api/injectors.js +82 -0
- package/dist/lib/api/injectors.js.map +1 -0
- package/dist/lib/api/locate.d.ts +13 -0
- package/dist/lib/api/locate.js +27 -0
- package/dist/lib/api/locate.js.map +1 -0
- package/dist/lib/api/mission-invite.d.ts +36 -0
- package/dist/lib/api/mission-invite.js +55 -0
- package/dist/lib/api/mission-invite.js.map +1 -0
- package/dist/lib/api/mission-layer.d.ts +137 -0
- package/dist/lib/api/mission-layer.js +247 -0
- package/dist/lib/api/mission-layer.js.map +1 -0
- package/dist/lib/api/mission-log.d.ts +75 -0
- package/dist/lib/api/mission-log.js +117 -0
- package/dist/lib/api/mission-log.js.map +1 -0
- package/dist/lib/api/mission.d.ts +556 -0
- package/dist/lib/api/mission.js +708 -0
- package/dist/lib/api/mission.js.map +1 -0
- package/dist/lib/api/oauth.d.ts +22 -0
- package/dist/lib/api/oauth.js +55 -0
- package/dist/lib/api/oauth.js.map +1 -0
- package/dist/lib/api/package.d.ts +40 -0
- package/dist/lib/api/package.js +70 -0
- package/dist/lib/api/package.js.map +1 -0
- package/dist/lib/api/profile.d.ts +9 -0
- package/dist/lib/api/profile.js +16 -0
- package/dist/lib/api/profile.js.map +1 -0
- package/dist/lib/api/query.d.ts +16 -0
- package/dist/lib/api/query.js +60 -0
- package/dist/lib/api/query.js.map +1 -0
- package/dist/lib/api/repeater.d.ts +47 -0
- package/dist/lib/api/repeater.js +62 -0
- package/dist/lib/api/repeater.js.map +1 -0
- package/dist/lib/api/security.d.ts +110 -0
- package/dist/lib/api/security.js +123 -0
- package/dist/lib/api/security.js.map +1 -0
- package/dist/lib/api/subscriptions.d.ts +103 -0
- package/dist/lib/api/subscriptions.js +74 -0
- package/dist/lib/api/subscriptions.js.map +1 -0
- package/dist/lib/api/types.d.ts +41 -0
- package/dist/lib/api/types.js +42 -0
- package/dist/lib/api/types.js.map +1 -0
- package/dist/lib/api/video.d.ts +139 -0
- package/dist/lib/api/video.js +151 -0
- package/dist/lib/api/video.js.map +1 -0
- package/dist/lib/api.d.ts +62 -0
- package/dist/lib/api.js +170 -0
- package/dist/lib/api.js.map +1 -0
- package/dist/lib/auth.d.ts +34 -0
- package/dist/lib/auth.js +97 -0
- package/dist/lib/auth.js.map +1 -0
- package/dist/lib/commands.d.ts +38 -0
- package/dist/lib/commands.js +34 -0
- package/dist/lib/commands.js.map +1 -0
- package/dist/lib/fetch.d.ts +8 -0
- package/dist/lib/fetch.js +26 -0
- package/dist/lib/fetch.js.map +1 -0
- package/dist/lib/stream.d.ts +2 -0
- package/dist/lib/stream.js +9 -0
- package/dist/lib/stream.js.map +1 -0
- package/dist/test/default.test.d.ts +1 -0
- package/dist/test/default.test.js +8 -0
- package/dist/test/default.test.js.map +1 -0
- package/dist/test/findCoT.test.d.ts +1 -0
- package/dist/test/findCoT.test.js +85 -0
- package/dist/test/findCoT.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/lib/api/certificate.ts +89 -0
- package/lib/api.ts +4 -0
- package/package.json +1 -1
|
@@ -0,0 +1,708 @@
|
|
|
1
|
+
import xmljs from 'xml-js';
|
|
2
|
+
import CoT, { CoTParser } from '@tak-ps/node-cot';
|
|
3
|
+
import { Type } from '@sinclair/typebox';
|
|
4
|
+
import Err from '@openaddresses/batch-error';
|
|
5
|
+
import { TAKItem, TAKList } from './types.js';
|
|
6
|
+
import { MissionLog } from './mission-log.js';
|
|
7
|
+
import Commands, { CommandOutputFormat } from '../commands.js';
|
|
8
|
+
export var MissionSubscriberRole;
|
|
9
|
+
(function (MissionSubscriberRole) {
|
|
10
|
+
MissionSubscriberRole["MISSION_OWNER"] = "MISSION_OWNER";
|
|
11
|
+
MissionSubscriberRole["MISSION_SUBSCRIBER"] = "MISSION_SUBSCRIBER";
|
|
12
|
+
MissionSubscriberRole["MISSION_READONLY_SUBSCRIBER"] = "MISSION_READONLY_SUBSCRIBER";
|
|
13
|
+
})(MissionSubscriberRole || (MissionSubscriberRole = {}));
|
|
14
|
+
export const MissionContent = Type.Object({
|
|
15
|
+
keywords: Type.Array(Type.String()),
|
|
16
|
+
name: Type.String(),
|
|
17
|
+
hash: Type.String(),
|
|
18
|
+
submissionTime: Type.String(),
|
|
19
|
+
uid: Type.String(),
|
|
20
|
+
size: Type.Integer(),
|
|
21
|
+
creatorUid: Type.Optional(Type.String()),
|
|
22
|
+
mimeType: Type.Optional(Type.String()),
|
|
23
|
+
submitter: Type.Optional(Type.String()),
|
|
24
|
+
expiration: Type.Integer()
|
|
25
|
+
});
|
|
26
|
+
export const MissionChange = Type.Object({
|
|
27
|
+
isFederatedChange: Type.Boolean(),
|
|
28
|
+
type: Type.String(),
|
|
29
|
+
missionName: Type.String(),
|
|
30
|
+
timestamp: Type.String(),
|
|
31
|
+
serverTime: Type.String(),
|
|
32
|
+
creatorUid: Type.Optional(Type.String()),
|
|
33
|
+
contentUid: Type.Optional(Type.String()),
|
|
34
|
+
details: Type.Optional(Type.Object({
|
|
35
|
+
type: Type.String(),
|
|
36
|
+
callsign: Type.String(),
|
|
37
|
+
color: Type.Optional(Type.String()),
|
|
38
|
+
location: Type.Object({
|
|
39
|
+
lat: Type.Number(),
|
|
40
|
+
lon: Type.Number()
|
|
41
|
+
})
|
|
42
|
+
})),
|
|
43
|
+
contentResource: Type.Optional(MissionContent)
|
|
44
|
+
});
|
|
45
|
+
export const Mission = Type.Object({
|
|
46
|
+
name: Type.String(),
|
|
47
|
+
description: Type.String(),
|
|
48
|
+
chatRoom: Type.Optional(Type.String()),
|
|
49
|
+
baseLayer: Type.Optional(Type.String()),
|
|
50
|
+
bbox: Type.Optional(Type.String()),
|
|
51
|
+
path: Type.Optional(Type.String()),
|
|
52
|
+
classification: Type.Optional(Type.String()),
|
|
53
|
+
tool: Type.String(),
|
|
54
|
+
keywords: Type.Array(Type.String()),
|
|
55
|
+
creatorUid: Type.Optional(Type.String()),
|
|
56
|
+
createTime: Type.String(),
|
|
57
|
+
externalData: Type.Array(Type.Unknown()),
|
|
58
|
+
feeds: Type.Array(Type.Unknown()),
|
|
59
|
+
mapLayers: Type.Array(Type.Unknown()),
|
|
60
|
+
ownerRole: Type.Optional(Type.Object({
|
|
61
|
+
permissions: Type.Array(Type.String()),
|
|
62
|
+
type: Type.Enum(MissionSubscriberRole)
|
|
63
|
+
})),
|
|
64
|
+
inviteOnly: Type.Boolean(),
|
|
65
|
+
expiration: Type.Number(),
|
|
66
|
+
guid: Type.String(),
|
|
67
|
+
uids: Type.Array(Type.Unknown()),
|
|
68
|
+
logs: Type.Optional(Type.Array(MissionLog)), // Only present if ?logs=true
|
|
69
|
+
contents: Type.Array(Type.Object({
|
|
70
|
+
timestamp: Type.String(),
|
|
71
|
+
creatorUid: Type.Optional(Type.String()),
|
|
72
|
+
data: MissionContent
|
|
73
|
+
})),
|
|
74
|
+
passwordProtected: Type.Boolean(),
|
|
75
|
+
token: Type.Optional(Type.String()), // Only present when mission created
|
|
76
|
+
groups: Type.Optional(Type.Union([Type.String(), Type.Array(Type.String())])), // Only present on Mission.get()
|
|
77
|
+
missionChanges: Type.Optional(Type.Array(MissionChange)) // Only present on Mission.get()
|
|
78
|
+
});
|
|
79
|
+
export const MissionRole = Type.Object({
|
|
80
|
+
permissions: Type.Array(Type.String()),
|
|
81
|
+
hibernateLazyInitializer: Type.Optional(Type.Any()),
|
|
82
|
+
type: Type.Enum(MissionSubscriberRole)
|
|
83
|
+
});
|
|
84
|
+
export const MissionSubscriber = Type.Object({
|
|
85
|
+
token: Type.Optional(Type.String()),
|
|
86
|
+
clientUid: Type.String(),
|
|
87
|
+
username: Type.String(),
|
|
88
|
+
createTime: Type.String(),
|
|
89
|
+
role: MissionRole
|
|
90
|
+
});
|
|
91
|
+
export const MissionOptions = Type.Object({
|
|
92
|
+
token: Type.Optional(Type.String())
|
|
93
|
+
});
|
|
94
|
+
export const AttachContentsInput = Type.Object({
|
|
95
|
+
hashes: Type.Optional(Type.Array(Type.String())),
|
|
96
|
+
uids: Type.Optional(Type.Array(Type.String())),
|
|
97
|
+
});
|
|
98
|
+
export const DetachContentsInput = Type.Object({
|
|
99
|
+
hash: Type.Optional(Type.String()),
|
|
100
|
+
uid: Type.Optional(Type.String())
|
|
101
|
+
});
|
|
102
|
+
export const MissionChangesInput = Type.Object({
|
|
103
|
+
secago: Type.Optional(Type.Integer()),
|
|
104
|
+
start: Type.Optional(Type.String()),
|
|
105
|
+
end: Type.Optional(Type.String()),
|
|
106
|
+
squashed: Type.Optional(Type.Boolean())
|
|
107
|
+
});
|
|
108
|
+
export const SubscribedInput = Type.Object({
|
|
109
|
+
uid: Type.String(),
|
|
110
|
+
});
|
|
111
|
+
export const UnsubscribeInput = Type.Object({
|
|
112
|
+
uid: Type.String(),
|
|
113
|
+
disconnectOnly: Type.Optional(Type.Boolean())
|
|
114
|
+
});
|
|
115
|
+
export const SubscriptionInput = Type.Object({
|
|
116
|
+
uid: Type.String(),
|
|
117
|
+
});
|
|
118
|
+
export const SubscribeInput = Type.Object({
|
|
119
|
+
uid: Type.String(),
|
|
120
|
+
password: Type.Optional(Type.String()),
|
|
121
|
+
secago: Type.Optional(Type.Integer()),
|
|
122
|
+
start: Type.Optional(Type.String()),
|
|
123
|
+
end: Type.Optional(Type.String())
|
|
124
|
+
});
|
|
125
|
+
export const MissionDeleteInput = Type.Object({
|
|
126
|
+
creatorUid: Type.Optional(Type.String()),
|
|
127
|
+
deepDelete: Type.Optional(Type.Boolean())
|
|
128
|
+
});
|
|
129
|
+
export const GetInput = Type.Object({
|
|
130
|
+
password: Type.Optional(Type.String()),
|
|
131
|
+
changes: Type.Optional(Type.Boolean()),
|
|
132
|
+
logs: Type.Optional(Type.Boolean()),
|
|
133
|
+
secago: Type.Optional(Type.Integer()),
|
|
134
|
+
start: Type.Optional(Type.String()),
|
|
135
|
+
end: Type.Optional(Type.String())
|
|
136
|
+
});
|
|
137
|
+
export const SetRoleInput = Type.Object({
|
|
138
|
+
clientUid: Type.String(),
|
|
139
|
+
username: Type.String(),
|
|
140
|
+
role: MissionRole
|
|
141
|
+
});
|
|
142
|
+
export const MissionListInput = Type.Object({
|
|
143
|
+
passwordProtected: Type.Optional(Type.Boolean()),
|
|
144
|
+
defaultRole: Type.Optional(Type.Boolean()),
|
|
145
|
+
tool: Type.Optional(Type.String())
|
|
146
|
+
});
|
|
147
|
+
export const MissionCreateInput = Type.Object({
|
|
148
|
+
name: Type.String(),
|
|
149
|
+
group: Type.Optional(Type.Union([Type.Array(Type.String()), Type.String()])),
|
|
150
|
+
keywords: Type.Optional(Type.Array(Type.String())),
|
|
151
|
+
creatorUid: Type.String(),
|
|
152
|
+
description: Type.Optional(Type.String({ default: '' })),
|
|
153
|
+
chatRoom: Type.Optional(Type.String()),
|
|
154
|
+
baseLayer: Type.Optional(Type.String()),
|
|
155
|
+
bbox: Type.Optional(Type.String()),
|
|
156
|
+
boundingPolygon: Type.Optional(Type.Array(Type.String())),
|
|
157
|
+
path: Type.Optional(Type.String()),
|
|
158
|
+
classification: Type.Optional(Type.String()),
|
|
159
|
+
tool: Type.Optional(Type.String({ default: 'public' })),
|
|
160
|
+
password: Type.Optional(Type.String()),
|
|
161
|
+
defaultRole: Type.Optional(Type.String()),
|
|
162
|
+
expiration: Type.Optional(Type.Integer()),
|
|
163
|
+
inviteOnly: Type.Optional(Type.Boolean({ default: false })),
|
|
164
|
+
allowDupe: Type.Optional(Type.Boolean({ default: false })),
|
|
165
|
+
});
|
|
166
|
+
export const MissionUpdateInput = Type.Object({
|
|
167
|
+
creatorUid: Type.Optional(Type.String()),
|
|
168
|
+
description: Type.Optional(Type.String()),
|
|
169
|
+
keywords: Type.Optional(Type.Array(Type.String())),
|
|
170
|
+
chatRoom: Type.Optional(Type.String()),
|
|
171
|
+
baseLayer: Type.Optional(Type.String()),
|
|
172
|
+
group: Type.Optional(Type.Union([Type.Array(Type.String()), Type.String()])),
|
|
173
|
+
bbox: Type.Optional(Type.String()),
|
|
174
|
+
path: Type.Optional(Type.String()),
|
|
175
|
+
classification: Type.Optional(Type.String()),
|
|
176
|
+
tool: Type.Optional(Type.String()),
|
|
177
|
+
expiration: Type.Optional(Type.Integer()),
|
|
178
|
+
inviteOnly: Type.Optional(Type.Boolean()),
|
|
179
|
+
});
|
|
180
|
+
export const GUIDMatch = new RegExp(/^[{]?[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}[}]?$/);
|
|
181
|
+
export const TAKList_Mission = TAKList(Mission);
|
|
182
|
+
export const TAKList_MissionInvites = TAKList(Type.String());
|
|
183
|
+
export const TAKList_MissionChange = TAKList(MissionChange);
|
|
184
|
+
export const TAKList_MissionSubscriber = TAKList(MissionSubscriber);
|
|
185
|
+
export const TAKItem_MissionSubscriber = TAKItem(MissionSubscriber);
|
|
186
|
+
/**
|
|
187
|
+
* @class
|
|
188
|
+
*/
|
|
189
|
+
export default class MissionCommands extends Commands {
|
|
190
|
+
schema = {
|
|
191
|
+
list: {
|
|
192
|
+
description: 'List Missions',
|
|
193
|
+
params: Type.Object({}),
|
|
194
|
+
query: Type.Object({}),
|
|
195
|
+
formats: [CommandOutputFormat.JSON]
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
async cli(args) {
|
|
199
|
+
if (args._[3] === 'list') {
|
|
200
|
+
const list = await this.list({});
|
|
201
|
+
if (args.format === 'json') {
|
|
202
|
+
return list;
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
return list.data.map((mission) => {
|
|
206
|
+
return `${mission.name} - ${mission.description}`;
|
|
207
|
+
}).join('\n');
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
throw new Error('Unsupported Subcommand');
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
#isGUID(id) {
|
|
215
|
+
return GUIDMatch.test(id);
|
|
216
|
+
}
|
|
217
|
+
#encodeName(name) {
|
|
218
|
+
return encodeURIComponent(name.trim());
|
|
219
|
+
}
|
|
220
|
+
/*
|
|
221
|
+
* The Mission type is currently cast from an unknown to a Mission
|
|
222
|
+
* from the fetch call from the server. There are a few standardizations
|
|
223
|
+
* we make for better usability.
|
|
224
|
+
*/
|
|
225
|
+
#stdMission(mission) {
|
|
226
|
+
if (mission.description === undefined)
|
|
227
|
+
mission.description = '';
|
|
228
|
+
return mission;
|
|
229
|
+
}
|
|
230
|
+
#headers(opts) {
|
|
231
|
+
if (opts && opts.token) {
|
|
232
|
+
return {
|
|
233
|
+
MissionAuthorization: `Bearer ${opts.token}`
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
return {};
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Return Zip archive of Mission Sync
|
|
242
|
+
*
|
|
243
|
+
* {@link https://docs.tak.gov/api/takserver/redoc#tag/mission-api/operation/getMissionArchive_1 TAK Server Docs}.
|
|
244
|
+
*/
|
|
245
|
+
async getArchive(name, opts) {
|
|
246
|
+
const url = new URL(`/Marti/api/missions/${this.#encodeName(name)}/archive`, this.api.url);
|
|
247
|
+
const res = await this.api.fetch(url, {
|
|
248
|
+
method: 'GET',
|
|
249
|
+
headers: this.#headers(opts),
|
|
250
|
+
}, true);
|
|
251
|
+
return res.body;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Return Mission Sync changes in a given time range
|
|
255
|
+
*
|
|
256
|
+
* {@link https://docs.tak.gov/api/takserver/redoc#tag/mission-api/operation/getMissionChanges TAK Server Docs}.
|
|
257
|
+
*/
|
|
258
|
+
async changes(name, query, opts) {
|
|
259
|
+
if (this.#isGUID(name))
|
|
260
|
+
name = (await this.getGuid(name, {}, opts)).name;
|
|
261
|
+
const url = new URL(`/Marti/api/missions/${this.#encodeName(name)}/changes`, this.api.url);
|
|
262
|
+
let q;
|
|
263
|
+
for (q in query) {
|
|
264
|
+
if (query[q] !== undefined) {
|
|
265
|
+
url.searchParams.append(q, String(query[q]));
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
const changes = await this.api.fetch(url, {
|
|
269
|
+
method: 'GET',
|
|
270
|
+
headers: this.#headers(opts),
|
|
271
|
+
});
|
|
272
|
+
return changes;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Return all current features in the Data Sync as CoT GeoJSON Features
|
|
276
|
+
*/
|
|
277
|
+
async latestFeats(name, opts) {
|
|
278
|
+
const feats = [];
|
|
279
|
+
const res = xmljs.xml2js(await this.latestCots(name, opts), { compact: true });
|
|
280
|
+
if (!Object.keys(res.events).length)
|
|
281
|
+
return feats;
|
|
282
|
+
if (!res.events.event || (Array.isArray(res.events.event) && !res.events.event.length))
|
|
283
|
+
return feats;
|
|
284
|
+
for (const event of Array.isArray(res.events.event) ? res.events.event : [res.events.event]) {
|
|
285
|
+
feats.push(await CoTParser.to_geojson(new CoT({ event })));
|
|
286
|
+
}
|
|
287
|
+
return feats;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Return all current features in the Data Sync as CoT GeoJSON Features
|
|
291
|
+
*
|
|
292
|
+
* {@link https://docs.tak.gov/api/takserver/redoc#tag/mission-api/operation/getLatestMissionCotEvents TAK Server Docs}.
|
|
293
|
+
*/
|
|
294
|
+
async latestCots(name, opts) {
|
|
295
|
+
const url = this.#isGUID(name)
|
|
296
|
+
? new URL(`/Marti/api/missions/guid/${encodeURIComponent(name)}/cot`, this.api.url)
|
|
297
|
+
: new URL(`/Marti/api/missions/${this.#encodeName(name)}/cot`, this.api.url);
|
|
298
|
+
return await this.api.fetch(url, {
|
|
299
|
+
method: 'GET',
|
|
300
|
+
headers: this.#headers(opts)
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Return users associated with this mission
|
|
305
|
+
*
|
|
306
|
+
* {@link https://docs.tak.gov/api/takserver/redoc#tag/mission-api/operation/getMissionContacts TAK Server Docs}.
|
|
307
|
+
*/
|
|
308
|
+
async contacts(name, opts) {
|
|
309
|
+
const url = this.#isGUID(name)
|
|
310
|
+
? new URL(`/Marti/api/missions/guid/${encodeURIComponent(name)}/contacts`, this.api.url)
|
|
311
|
+
: new URL(`/Marti/api/missions/${this.#encodeName(name)}/contacts`, this.api.url);
|
|
312
|
+
return await this.api.fetch(url, {
|
|
313
|
+
method: 'GET',
|
|
314
|
+
headers: this.#headers(opts)
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Remove a file from the mission
|
|
319
|
+
*
|
|
320
|
+
* {@link https://docs.tak.gov/api/takserver/redoc#tag/mission-api/operation/removeMissionContent TAK Server Docs}.
|
|
321
|
+
*/
|
|
322
|
+
async detachContents(name, body, opts) {
|
|
323
|
+
const url = this.#isGUID(name)
|
|
324
|
+
? new URL(`/Marti/api/missions/guid/${encodeURIComponent(name)}/contents`, this.api.url)
|
|
325
|
+
: new URL(`/Marti/api/missions/${this.#encodeName(name)}/contents`, this.api.url);
|
|
326
|
+
if (body.hash)
|
|
327
|
+
url.searchParams.append('hash', body.hash);
|
|
328
|
+
if (body.uid)
|
|
329
|
+
url.searchParams.append('uid', body.uid);
|
|
330
|
+
return await this.api.fetch(url, {
|
|
331
|
+
method: 'DELETE',
|
|
332
|
+
headers: this.#headers(opts),
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Attach a file resource by hash from the TAK Server file manager
|
|
337
|
+
*
|
|
338
|
+
* {@link https://docs.tak.gov/api/takserver/redoc#tag/mission-api/operation/addMissionContent TAK Server Docs}.
|
|
339
|
+
*/
|
|
340
|
+
async attachContents(name, body, opts) {
|
|
341
|
+
const url = this.#isGUID(name)
|
|
342
|
+
? new URL(`/Marti/api/missions/guid/${encodeURIComponent(name)}/contents`, this.api.url)
|
|
343
|
+
: new URL(`/Marti/api/missions/${this.#encodeName(name)}/contents`, this.api.url);
|
|
344
|
+
return await this.api.fetch(url, {
|
|
345
|
+
method: 'PUT',
|
|
346
|
+
headers: this.#headers(opts),
|
|
347
|
+
body
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Upload a Mission Package
|
|
352
|
+
*
|
|
353
|
+
* {@link https://docs.tak.gov/api/takserver/redoc#tag/mission-api/operation/addMissionPackage TAK Server Docs}.
|
|
354
|
+
*/
|
|
355
|
+
async upload(name, creatorUid, body, opts) {
|
|
356
|
+
if (this.#isGUID(name))
|
|
357
|
+
name = (await this.getGuid(name, {}, opts)).name;
|
|
358
|
+
const url = new URL(`/Marti/api/missions/${this.#encodeName(name)}/contents/missionpackage`, this.api.url);
|
|
359
|
+
url.searchParams.append('creatorUid', creatorUid);
|
|
360
|
+
return await this.api.fetch(url, {
|
|
361
|
+
method: 'PUT',
|
|
362
|
+
headers: this.#headers(opts),
|
|
363
|
+
body
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Return UIDs associated with any subscribed users
|
|
368
|
+
*
|
|
369
|
+
* {@link https://docs.tak.gov/api/takserver/redoc#tag/mission-api/operation/getMissionSubscriptions TAK Server Docs}.
|
|
370
|
+
*/
|
|
371
|
+
async subscriptions(name, opts) {
|
|
372
|
+
const url = this.#isGUID(name)
|
|
373
|
+
? new URL(`/Marti/api/missions/guid/${encodeURIComponent(name)}/subscriptions`, this.api.url)
|
|
374
|
+
: new URL(`/Marti/api/missions/${this.#encodeName(name)}/subscriptions`, this.api.url);
|
|
375
|
+
return await this.api.fetch(url, {
|
|
376
|
+
method: 'GET',
|
|
377
|
+
headers: this.#headers(opts),
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Return permissions associated with any subscribed users
|
|
382
|
+
*
|
|
383
|
+
* {@link https://docs.tak.gov/api/takserver/redoc#tag/mission-api/operation/getMissionSubscriptionRoles TAK Server Docs}.
|
|
384
|
+
*/
|
|
385
|
+
async subscriptionRoles(name, opts) {
|
|
386
|
+
const url = this.#isGUID(name)
|
|
387
|
+
? new URL(`/Marti/api/missions/guid/${encodeURIComponent(name)}/subscriptions/roles`, this.api.url)
|
|
388
|
+
: new URL(`/Marti/api/missions/${this.#encodeName(name)}/subscriptions/roles`, this.api.url);
|
|
389
|
+
return await this.api.fetch(url, {
|
|
390
|
+
method: 'GET',
|
|
391
|
+
headers: this.#headers(opts),
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Return Role associated with a given mission if subscribed
|
|
396
|
+
*
|
|
397
|
+
* {@link https://docs.tak.gov/api/takserver/redoc#tag/mission-api/operation/setMissionRole TAK Server Docs}.
|
|
398
|
+
*/
|
|
399
|
+
async setRole(name, query, opts) {
|
|
400
|
+
const url = this.#isGUID(name)
|
|
401
|
+
? new URL(`/Marti/api/missions/guid/${encodeURIComponent(name)}/role`, this.api.url)
|
|
402
|
+
: new URL(`/Marti/api/missions/${this.#encodeName(name)}/role`, this.api.url);
|
|
403
|
+
let q;
|
|
404
|
+
for (q in query) {
|
|
405
|
+
if (query[q] !== undefined) {
|
|
406
|
+
url.searchParams.append(q, String(query[q]));
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
const res = await this.api.fetch(url, {
|
|
410
|
+
method: 'PUT',
|
|
411
|
+
headers: this.#headers(opts),
|
|
412
|
+
});
|
|
413
|
+
return res.data;
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Return Role associated with a given mission if subscribed
|
|
417
|
+
*
|
|
418
|
+
* {@link https://docs.tak.gov/api/takserver/redoc#tag/mission-api/operation/getMissionRoleFromToken TAK Server Docs}.
|
|
419
|
+
*/
|
|
420
|
+
async role(name, opts) {
|
|
421
|
+
const url = this.#isGUID(name)
|
|
422
|
+
? new URL(`/Marti/api/missions/guid/${encodeURIComponent(name)}/role`, this.api.url)
|
|
423
|
+
: new URL(`/Marti/api/missions/${this.#encodeName(name)}/role`, this.api.url);
|
|
424
|
+
const res = await this.api.fetch(url, {
|
|
425
|
+
method: 'GET',
|
|
426
|
+
headers: this.#headers(opts),
|
|
427
|
+
});
|
|
428
|
+
return res.data;
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Return subscription associated with a given mission if subscribed
|
|
432
|
+
*
|
|
433
|
+
* {@link https://docs.tak.gov/api/takserver/redoc#tag/mission-api/operation/getSubscriptionForUser TAK Server Docs}.
|
|
434
|
+
*/
|
|
435
|
+
async subscription(name, query, opts) {
|
|
436
|
+
const url = this.#isGUID(name)
|
|
437
|
+
? new URL(`/Marti/api/missions/guid/${encodeURIComponent(name)}/subscription`, this.api.url)
|
|
438
|
+
: new URL(`/Marti/api/missions/${this.#encodeName(name)}/subscription`, this.api.url);
|
|
439
|
+
let q;
|
|
440
|
+
for (q in query) {
|
|
441
|
+
if (query[q] !== undefined) {
|
|
442
|
+
url.searchParams.append(q, String(query[q]));
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
const res = await this.api.fetch(url, {
|
|
446
|
+
method: 'GET',
|
|
447
|
+
headers: this.#headers(opts),
|
|
448
|
+
});
|
|
449
|
+
return res.data;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Subscribe to a mission
|
|
453
|
+
*
|
|
454
|
+
* {@link https://docs.tak.gov/api/takserver/redoc#tag/mission-api/operation/createMissionSubscription TAK Server Docs}.
|
|
455
|
+
*/
|
|
456
|
+
async subscribe(name, query, opts) {
|
|
457
|
+
const url = this.#isGUID(name)
|
|
458
|
+
? new URL(`/Marti/api/missions/guid/${encodeURIComponent(name)}/subscription`, this.api.url)
|
|
459
|
+
: new URL(`/Marti/api/missions/${this.#encodeName(name)}/subscription`, this.api.url);
|
|
460
|
+
let q;
|
|
461
|
+
for (q in query) {
|
|
462
|
+
if (query[q] !== undefined) {
|
|
463
|
+
url.searchParams.append(q, String(query[q]));
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
return await this.api.fetch(url, {
|
|
467
|
+
method: 'PUT',
|
|
468
|
+
headers: this.#headers(opts),
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Unsubscribe from a mission
|
|
473
|
+
*
|
|
474
|
+
* {@link https://docs.tak.gov/api/takserver/redoc#tag/mission-api/operation/deleteMissionSubscription TAK Server Docs}.
|
|
475
|
+
*/
|
|
476
|
+
async unsubscribe(name, query, opts) {
|
|
477
|
+
const url = this.#isGUID(name)
|
|
478
|
+
? new URL(`/Marti/api/missions/guid/${encodeURIComponent(name)}/subscription`, this.api.url)
|
|
479
|
+
: new URL(`/Marti/api/missions/${this.#encodeName(name)}/subscription`, this.api.url);
|
|
480
|
+
let q;
|
|
481
|
+
for (q in query) {
|
|
482
|
+
if (query[q] !== undefined) {
|
|
483
|
+
url.searchParams.append(q, String(query[q]));
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
return await this.api.fetch(url, {
|
|
487
|
+
method: 'DELETE',
|
|
488
|
+
headers: this.#headers(opts),
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* List missions in currently active channels
|
|
493
|
+
*
|
|
494
|
+
* {@link https://docs.tak.gov/api/takserver/redoc#tag/mission-api/operation/getAllMissions_1 TAK Server Docs}.
|
|
495
|
+
*/
|
|
496
|
+
async list(query) {
|
|
497
|
+
const url = new URL('/Marti/api/missions', this.api.url);
|
|
498
|
+
let q;
|
|
499
|
+
for (q in query) {
|
|
500
|
+
if (query[q] !== undefined) {
|
|
501
|
+
url.searchParams.append(q, String(query[q]));
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
return await this.api.fetch(url, {
|
|
505
|
+
method: 'GET'
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Get mission by its GUID
|
|
510
|
+
*
|
|
511
|
+
* {@link https://docs.tak.gov/api/takserver/redoc#tag/mission-api/operation/getMissionByGuid TAK Server Docs}.
|
|
512
|
+
*/
|
|
513
|
+
async getGuid(guid, query, opts) {
|
|
514
|
+
const url = new URL(`/Marti/api/missions/guid/${encodeURIComponent(guid)}`, this.api.url);
|
|
515
|
+
let q;
|
|
516
|
+
for (q in query) {
|
|
517
|
+
if (query[q] !== undefined) {
|
|
518
|
+
url.searchParams.append(q, String(query[q]));
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
const missions = await this.api.fetch(url, {
|
|
522
|
+
method: 'GET',
|
|
523
|
+
headers: this.#headers(opts),
|
|
524
|
+
});
|
|
525
|
+
if (!missions.data.length)
|
|
526
|
+
throw new Err(404, null, `No Mission for GUID: ${guid}`);
|
|
527
|
+
return this.#stdMission(missions.data[0]);
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* Check if you have access to a given mission
|
|
531
|
+
*/
|
|
532
|
+
async access(name, opts) {
|
|
533
|
+
try {
|
|
534
|
+
const url = this.#isGUID(name)
|
|
535
|
+
? new URL(`/Marti/api/missions/guid/${encodeURIComponent(name)}`, this.api.url)
|
|
536
|
+
: new URL(`/Marti/api/missions/${this.#encodeName(name)}`, this.api.url);
|
|
537
|
+
const missions = await this.api.fetch(url, {
|
|
538
|
+
method: 'GET',
|
|
539
|
+
headers: this.#headers(opts),
|
|
540
|
+
});
|
|
541
|
+
if (!missions.data.length)
|
|
542
|
+
return false;
|
|
543
|
+
return true;
|
|
544
|
+
}
|
|
545
|
+
catch (err) {
|
|
546
|
+
console.error(err);
|
|
547
|
+
return false;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Update Mission
|
|
552
|
+
*
|
|
553
|
+
* {@link https://docs.tak.gov/api/takserver/redoc#tag/mission-api/operation/createMissionAllowDupe TAK Server Docs}.
|
|
554
|
+
*/
|
|
555
|
+
async update(name, body, opts) {
|
|
556
|
+
let mission = await this.get(name, {}, opts);
|
|
557
|
+
const url = new URL(`/Marti/api/missions/${encodeURIComponent(mission.name)}`, this.api.url);
|
|
558
|
+
const bodyParams = {
|
|
559
|
+
group: body.group ?? mission.groups,
|
|
560
|
+
creatorUid: body.creatorUid ?? mission.creatorUid,
|
|
561
|
+
description: body.description ?? mission.description,
|
|
562
|
+
chatRoom: body.chatRoom ?? mission.chatRoom,
|
|
563
|
+
baseLayer: body.baseLayer ?? mission.baseLayer,
|
|
564
|
+
bbox: body.bbox ?? mission.bbox,
|
|
565
|
+
path: body.path ?? mission.path,
|
|
566
|
+
classification: body.classification ?? mission.classification,
|
|
567
|
+
tool: body.tool ?? mission.tool,
|
|
568
|
+
expiration: body.expiration ?? mission.expiration,
|
|
569
|
+
inviteOnly: body.inviteOnly ?? mission.inviteOnly
|
|
570
|
+
};
|
|
571
|
+
let q;
|
|
572
|
+
for (q in bodyParams) {
|
|
573
|
+
if (body[q] !== undefined) {
|
|
574
|
+
url.searchParams.append(q, String(body[q]));
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
url.searchParams.append('allowDupe', 'false');
|
|
578
|
+
const missions = await this.api.fetch(url, {
|
|
579
|
+
method: 'POST'
|
|
580
|
+
});
|
|
581
|
+
if (!missions.data.length)
|
|
582
|
+
throw new Error('Create Mission didn\'t return a mission or an error');
|
|
583
|
+
mission = missions.data[0];
|
|
584
|
+
if (body.keywords && body.keywords.length) {
|
|
585
|
+
mission = await this.#putKeywords(mission.name, body.keywords, {
|
|
586
|
+
token: mission.token
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
return this.#stdMission(mission);
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* Get mission by its Name
|
|
593
|
+
*
|
|
594
|
+
* {@link https://docs.tak.gov/api/takserver/redoc#tag/mission-api/operation/getMission TAK Server Docs}.
|
|
595
|
+
*/
|
|
596
|
+
async get(name, query, opts) {
|
|
597
|
+
const url = this.#isGUID(name)
|
|
598
|
+
? new URL(`/Marti/api/missions/guid/${encodeURIComponent(name)}`, this.api.url)
|
|
599
|
+
: new URL(`/Marti/api/missions/${this.#encodeName(name)}`, this.api.url);
|
|
600
|
+
let q;
|
|
601
|
+
for (q in query) {
|
|
602
|
+
if (query[q] !== undefined) {
|
|
603
|
+
url.searchParams.append(q, String(query[q]));
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
const missions = await this.api.fetch(url, {
|
|
607
|
+
method: 'GET',
|
|
608
|
+
headers: this.#headers(opts),
|
|
609
|
+
});
|
|
610
|
+
if (!missions.data.length)
|
|
611
|
+
throw new Err(404, null, `No Mission for Name: ${name}`);
|
|
612
|
+
return this.#stdMission(missions.data[0]);
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* Create a new mission
|
|
616
|
+
*
|
|
617
|
+
* {@link https://docs.tak.gov/api/takserver/redoc#tag/mission-api/operation/createMission TAK Server Docs}.
|
|
618
|
+
*/
|
|
619
|
+
async create(body) {
|
|
620
|
+
const url = new URL(`/Marti/api/missions/${this.#encodeName(body.name)}`, this.api.url);
|
|
621
|
+
// I want to keep this 1:1 with the TAK Server Source Code
|
|
622
|
+
// eslint-disable-next-line no-useless-escape
|
|
623
|
+
if (!body.name.match(/^[\p{L}\p{N}\w\d\s\.\(\)!=@#$&^*_\-\+\[\]\{\}:,\.\/\|\\]*$/u)) {
|
|
624
|
+
throw new Err(400, null, 'Mission Name contains an invalid Character');
|
|
625
|
+
}
|
|
626
|
+
else if (body.name.length === 0) {
|
|
627
|
+
throw new Err(400, null, 'Mission Name must have a length > 0');
|
|
628
|
+
}
|
|
629
|
+
else if (body.name.length > 1024) {
|
|
630
|
+
throw new Err(400, null, 'Mission Name cannot exceed 1024 characters');
|
|
631
|
+
}
|
|
632
|
+
else if (body.name.includes('/')) {
|
|
633
|
+
throw new Err(400, null, 'Mission Name cannot contain forward slashes');
|
|
634
|
+
}
|
|
635
|
+
if (body.description === undefined)
|
|
636
|
+
body.description = '';
|
|
637
|
+
if (body.group && Array.isArray(body.group))
|
|
638
|
+
body.group = body.group.join(',');
|
|
639
|
+
let q;
|
|
640
|
+
for (q in body) {
|
|
641
|
+
if (body[q] !== undefined && !['name', 'keywords'].includes(q)) {
|
|
642
|
+
url.searchParams.append(q, String(body[q]));
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
const missions = await this.api.fetch(url, {
|
|
646
|
+
method: 'POST'
|
|
647
|
+
});
|
|
648
|
+
if (!missions.data.length)
|
|
649
|
+
throw new Error('Create Mission didn\'t return a mission or an error');
|
|
650
|
+
let mission = missions.data[0];
|
|
651
|
+
if (body.keywords && body.keywords.length) {
|
|
652
|
+
mission = await this.#putKeywords(mission.name, body.keywords, {
|
|
653
|
+
token: mission.token
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
return this.#stdMission(mission);
|
|
657
|
+
}
|
|
658
|
+
/**
|
|
659
|
+
* Update Mission Keywords
|
|
660
|
+
*/
|
|
661
|
+
async #putKeywords(name, keywords, opts) {
|
|
662
|
+
const url = new URL(`/Marti/api/missions/${this.#encodeName(name)}/keywords`, this.api.url);
|
|
663
|
+
const missions = await this.api.fetch(url, {
|
|
664
|
+
method: 'PUT',
|
|
665
|
+
headers: this.#headers(opts),
|
|
666
|
+
body: keywords
|
|
667
|
+
});
|
|
668
|
+
if (!missions.data.length)
|
|
669
|
+
throw new Error('Create Mission didn\'t return a mission or an error');
|
|
670
|
+
const mission = missions.data[0];
|
|
671
|
+
return this.#stdMission(mission);
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* Delete a mission
|
|
675
|
+
*
|
|
676
|
+
* {@link https://docs.tak.gov/api/takserver/redoc#tag/mission-api/operation/deleteMission TAK Server Docs}.
|
|
677
|
+
*/
|
|
678
|
+
async delete(name, query, opts) {
|
|
679
|
+
if (this.#isGUID(name)) {
|
|
680
|
+
const url = new URL('/Marti/api/missions', this.api.url);
|
|
681
|
+
url.searchParams.append('guid', name);
|
|
682
|
+
let q;
|
|
683
|
+
for (q in query) {
|
|
684
|
+
if (query[q] !== undefined) {
|
|
685
|
+
url.searchParams.append(q, String(query[q]));
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
return await this.api.fetch(url, {
|
|
689
|
+
method: 'DELETE',
|
|
690
|
+
headers: this.#headers(opts),
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
else {
|
|
694
|
+
const url = new URL(`/Marti/api/missions/${this.#encodeName(name)}`, this.api.url);
|
|
695
|
+
let q;
|
|
696
|
+
for (q in query) {
|
|
697
|
+
if (query[q] !== undefined) {
|
|
698
|
+
url.searchParams.append(q, String(query[q]));
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
return await this.api.fetch(url, {
|
|
702
|
+
method: 'DELETE',
|
|
703
|
+
headers: this.#headers(opts),
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
//# sourceMappingURL=mission.js.map
|