@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,151 @@
|
|
|
1
|
+
import Err from '@openaddresses/batch-error';
|
|
2
|
+
import { Type } from '@sinclair/typebox';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
4
|
+
import Commands, { CommandOutputFormat } from '../commands.js';
|
|
5
|
+
export const FeedInput = Type.Object({
|
|
6
|
+
uuid: Type.Optional(Type.String()),
|
|
7
|
+
active: Type.Boolean({ default: true }),
|
|
8
|
+
alias: Type.String(),
|
|
9
|
+
url: Type.String(),
|
|
10
|
+
});
|
|
11
|
+
export const VideoConnectionCreateInput = Type.Object({
|
|
12
|
+
groups: Type.Optional(Type.Array(Type.String())),
|
|
13
|
+
uuid: Type.Optional(Type.String()),
|
|
14
|
+
active: Type.Boolean({
|
|
15
|
+
default: true
|
|
16
|
+
}),
|
|
17
|
+
alias: Type.String(),
|
|
18
|
+
feeds: Type.Array(FeedInput)
|
|
19
|
+
});
|
|
20
|
+
export const VideoConnectionUpdateInput = Type.Object({
|
|
21
|
+
uuid: Type.Optional(Type.String()),
|
|
22
|
+
active: Type.Boolean({
|
|
23
|
+
default: true
|
|
24
|
+
}),
|
|
25
|
+
alias: Type.String(),
|
|
26
|
+
feeds: Type.Array(FeedInput)
|
|
27
|
+
});
|
|
28
|
+
export const Feed = Type.Object({
|
|
29
|
+
uuid: Type.String(),
|
|
30
|
+
active: Type.Boolean(),
|
|
31
|
+
alias: Type.String(),
|
|
32
|
+
url: Type.String(),
|
|
33
|
+
order: Type.Union([Type.Integer(), Type.Null()]),
|
|
34
|
+
macAddress: Type.String(),
|
|
35
|
+
roverPort: Type.String(),
|
|
36
|
+
ignoreEmbeddedKLV: Type.String(),
|
|
37
|
+
source: Type.Union([Type.String(), Type.Null()]),
|
|
38
|
+
networkTimeout: Type.String(),
|
|
39
|
+
bufferTime: Type.String(),
|
|
40
|
+
rtspReliable: Type.String(),
|
|
41
|
+
thumbnail: Type.Union([Type.String(), Type.Null()]),
|
|
42
|
+
classification: Type.Union([Type.String(), Type.Null()]),
|
|
43
|
+
latitude: Type.Union([Type.String(), Type.Null()]),
|
|
44
|
+
longitude: Type.Union([Type.String(), Type.Null()]),
|
|
45
|
+
fov: Type.Union([Type.String(), Type.Null()]),
|
|
46
|
+
heading: Type.Union([Type.String(), Type.Null()]),
|
|
47
|
+
range: Type.Union([Type.String(), Type.Null()]),
|
|
48
|
+
width: Type.Union([Type.Integer(), Type.Null()]),
|
|
49
|
+
height: Type.Union([Type.Integer(), Type.Null()]),
|
|
50
|
+
bitrate: Type.Union([Type.Integer(), Type.Null()]),
|
|
51
|
+
});
|
|
52
|
+
export const VideoConnection = Type.Object({
|
|
53
|
+
uuid: Type.String(),
|
|
54
|
+
active: Type.Boolean(),
|
|
55
|
+
alias: Type.String(),
|
|
56
|
+
thumbnail: Type.Union([Type.String(), Type.Null()]),
|
|
57
|
+
classification: Type.Union([Type.String(), Type.Null()]),
|
|
58
|
+
feeds: Type.Array(Feed)
|
|
59
|
+
});
|
|
60
|
+
export const VideoConnectionList = Type.Object({
|
|
61
|
+
videoConnections: Type.Array(VideoConnection)
|
|
62
|
+
});
|
|
63
|
+
export const VideoConnectionListInput = Type.Object({
|
|
64
|
+
protocol: Type.Optional(Type.String())
|
|
65
|
+
});
|
|
66
|
+
export default class VideoCommands extends Commands {
|
|
67
|
+
schema = {
|
|
68
|
+
list: {
|
|
69
|
+
description: 'List V2 Video Configs',
|
|
70
|
+
params: Type.Object({}),
|
|
71
|
+
query: Type.Object({}),
|
|
72
|
+
formats: [CommandOutputFormat.JSON]
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
async cli(args) {
|
|
76
|
+
if (args._[3] === 'list') {
|
|
77
|
+
return await this.list();
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
throw new Error('Unsupported Subcommand');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async list(query = {}) {
|
|
84
|
+
const url = new URL(`/Marti/api/video`, this.api.url);
|
|
85
|
+
let q;
|
|
86
|
+
for (q in query) {
|
|
87
|
+
if (query[q] !== undefined) {
|
|
88
|
+
url.searchParams.append(q, String(query[q]));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return await this.api.fetch(url, {
|
|
92
|
+
method: 'GET'
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
async update(connection) {
|
|
96
|
+
const url = new URL(`/Marti/api/video/${connection.uuid}`, this.api.url);
|
|
97
|
+
if (!connection.uuid)
|
|
98
|
+
throw new Err(400, null, 'UUID must be set when updating Video');
|
|
99
|
+
await this.api.fetch(url, {
|
|
100
|
+
method: 'PUT',
|
|
101
|
+
body: {
|
|
102
|
+
...connection,
|
|
103
|
+
feeds: connection.feeds.map((feed) => {
|
|
104
|
+
if (!feed.uuid)
|
|
105
|
+
feed.uuid = randomUUID();
|
|
106
|
+
return feed;
|
|
107
|
+
})
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
return await this.get(connection.uuid);
|
|
111
|
+
}
|
|
112
|
+
async create(connection) {
|
|
113
|
+
const url = new URL(`/Marti/api/video`, this.api.url);
|
|
114
|
+
const uuid = connection.uuid || randomUUID();
|
|
115
|
+
if (connection.groups) {
|
|
116
|
+
for (const group of connection.groups) {
|
|
117
|
+
url.searchParams.append('group', group);
|
|
118
|
+
}
|
|
119
|
+
delete connection.groups;
|
|
120
|
+
}
|
|
121
|
+
await this.api.fetch(url, {
|
|
122
|
+
method: 'POST',
|
|
123
|
+
body: {
|
|
124
|
+
videoConnections: [{
|
|
125
|
+
uuid,
|
|
126
|
+
...connection,
|
|
127
|
+
feeds: connection.feeds.map((feed) => {
|
|
128
|
+
return {
|
|
129
|
+
uuid: randomUUID(),
|
|
130
|
+
...feed,
|
|
131
|
+
};
|
|
132
|
+
})
|
|
133
|
+
}]
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
return await this.get(uuid);
|
|
137
|
+
}
|
|
138
|
+
async get(uid) {
|
|
139
|
+
const url = new URL(`/Marti/api/video/${encodeURIComponent(uid)}`, this.api.url);
|
|
140
|
+
return await this.api.fetch(url, {
|
|
141
|
+
method: 'GET'
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
async delete(uid) {
|
|
145
|
+
const url = new URL(`/Marti/api/video/${encodeURIComponent(uid)}`, this.api.url);
|
|
146
|
+
await this.api.fetch(url, {
|
|
147
|
+
method: 'DELETE'
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=video.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"video.js","sourceRoot":"","sources":["../../../lib/api/video.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,4BAA4B,CAAC;AAE7C,OAAO,EAAU,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,QAAQ,EAAE,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAE/D,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC;IACjC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;IAClC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IACvC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE;IACpB,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE;CACrB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,0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,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAEjF,OAAO,MAAM,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE;YAC7B,MAAM,EAAE,KAAK;SAChB,CAAC,CAAC;IACP,CAAC;IAED,KAAK,CAAC,MAAM,CACR,GAAW;QAEX,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,oBAAoB,kBAAkB,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAEjF,MAAM,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE;YACtB,MAAM,EAAE,QAAQ;SACnB,CAAC,CAAC;IACP,CAAC;CACJ"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import OAuth from './api/oauth.js';
|
|
2
|
+
import Package from './api/package.js';
|
|
3
|
+
import Certificate from './api/certificate.js';
|
|
4
|
+
import Query from './api/query.js';
|
|
5
|
+
import Locate from './api/locate.js';
|
|
6
|
+
import Mission from './api/mission.js';
|
|
7
|
+
import MissionInvite from './api/mission-invite.js';
|
|
8
|
+
import MissionLog from './api/mission-log.js';
|
|
9
|
+
import MissionLayer from './api/mission-layer.js';
|
|
10
|
+
import Credentials from './api/credentials.js';
|
|
11
|
+
import Security from './api/security.js';
|
|
12
|
+
import Contacts from './api/contacts.js';
|
|
13
|
+
import Profile from './api/profile.js';
|
|
14
|
+
import Files from './api/files.js';
|
|
15
|
+
import Iconsets from './api/iconsets.js';
|
|
16
|
+
import Injectors from './api/injectors.js';
|
|
17
|
+
import Repeater from './api/repeater.js';
|
|
18
|
+
import Group from './api/groups.js';
|
|
19
|
+
import Subscription from './api/subscriptions.js';
|
|
20
|
+
import Video from './api/video.js';
|
|
21
|
+
import Export from './api/export.js';
|
|
22
|
+
import * as auth from './auth.js';
|
|
23
|
+
export declare const CommandList: Record<string, keyof TAKAPI>;
|
|
24
|
+
/**
|
|
25
|
+
* Handle TAK HTTP API Operations
|
|
26
|
+
* @class
|
|
27
|
+
*/
|
|
28
|
+
export default class TAKAPI {
|
|
29
|
+
auth: auth.APIAuth;
|
|
30
|
+
url: URL;
|
|
31
|
+
Package: Package;
|
|
32
|
+
OAuth: OAuth;
|
|
33
|
+
Locate: Locate;
|
|
34
|
+
Security: Security;
|
|
35
|
+
Iconsets: Iconsets;
|
|
36
|
+
Mission: Mission;
|
|
37
|
+
MissionLog: MissionLog;
|
|
38
|
+
MissionInvite: MissionInvite;
|
|
39
|
+
MissionLayer: MissionLayer;
|
|
40
|
+
Credentials: Credentials;
|
|
41
|
+
Contacts: Contacts;
|
|
42
|
+
Certificate: Certificate;
|
|
43
|
+
Subscription: Subscription;
|
|
44
|
+
Profile: Profile;
|
|
45
|
+
Injectors: Injectors;
|
|
46
|
+
Repeater: Repeater;
|
|
47
|
+
Group: Group;
|
|
48
|
+
Video: Video;
|
|
49
|
+
Export: Export;
|
|
50
|
+
Query: Query;
|
|
51
|
+
Files: Files;
|
|
52
|
+
constructor(url: URL, auth: auth.APIAuth);
|
|
53
|
+
static init(url: URL, auth: auth.APIAuth): Promise<TAKAPI>;
|
|
54
|
+
stdurl(url: string | URL): URL;
|
|
55
|
+
/**
|
|
56
|
+
* Standardize interactions with the backend API
|
|
57
|
+
*
|
|
58
|
+
* @param {URL|String} url - Full URL or API fragment to request
|
|
59
|
+
* @param {Object} [opts={}] - Options
|
|
60
|
+
*/
|
|
61
|
+
fetch(url: URL, opts?: any, raw?: boolean): Promise<any>;
|
|
62
|
+
}
|
package/dist/lib/api.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import FormData from 'form-data';
|
|
2
|
+
import OAuth from './api/oauth.js';
|
|
3
|
+
import Package from './api/package.js';
|
|
4
|
+
import Certificate from './api/certificate.js';
|
|
5
|
+
import Query from './api/query.js';
|
|
6
|
+
import Locate from './api/locate.js';
|
|
7
|
+
import Mission from './api/mission.js';
|
|
8
|
+
import MissionInvite from './api/mission-invite.js';
|
|
9
|
+
import MissionLog from './api/mission-log.js';
|
|
10
|
+
import MissionLayer from './api/mission-layer.js';
|
|
11
|
+
import Credentials from './api/credentials.js';
|
|
12
|
+
import Security from './api/security.js';
|
|
13
|
+
import Contacts from './api/contacts.js';
|
|
14
|
+
import Profile from './api/profile.js';
|
|
15
|
+
import Files from './api/files.js';
|
|
16
|
+
import Iconsets from './api/iconsets.js';
|
|
17
|
+
import Injectors from './api/injectors.js';
|
|
18
|
+
import Repeater from './api/repeater.js';
|
|
19
|
+
import Group from './api/groups.js';
|
|
20
|
+
import Subscription from './api/subscriptions.js';
|
|
21
|
+
import Video from './api/video.js';
|
|
22
|
+
import Export from './api/export.js';
|
|
23
|
+
import Err from '@openaddresses/batch-error';
|
|
24
|
+
export const CommandList = {
|
|
25
|
+
package: 'Package',
|
|
26
|
+
security: 'Security',
|
|
27
|
+
profile: 'Profile',
|
|
28
|
+
oauth: 'OAuth',
|
|
29
|
+
locate: 'Locate',
|
|
30
|
+
mission: 'Mission',
|
|
31
|
+
'mission-invite': 'MissionInvite',
|
|
32
|
+
'mission-log': 'MissionLog',
|
|
33
|
+
'mission-layer': 'MissionLayer',
|
|
34
|
+
credential: 'Credentials',
|
|
35
|
+
certificate: 'Certificate',
|
|
36
|
+
iconsets: 'Iconsets',
|
|
37
|
+
contact: 'Contacts',
|
|
38
|
+
subscription: 'Subscription',
|
|
39
|
+
injector: 'Injectors',
|
|
40
|
+
repeater: 'Repeater',
|
|
41
|
+
group: 'Group',
|
|
42
|
+
video: 'Video',
|
|
43
|
+
export: 'Export',
|
|
44
|
+
query: 'Query',
|
|
45
|
+
file: 'Files'
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Handle TAK HTTP API Operations
|
|
49
|
+
* @class
|
|
50
|
+
*/
|
|
51
|
+
export default class TAKAPI {
|
|
52
|
+
auth;
|
|
53
|
+
url;
|
|
54
|
+
Package;
|
|
55
|
+
OAuth;
|
|
56
|
+
Locate;
|
|
57
|
+
Security;
|
|
58
|
+
Iconsets;
|
|
59
|
+
Mission;
|
|
60
|
+
MissionLog;
|
|
61
|
+
MissionInvite;
|
|
62
|
+
MissionLayer;
|
|
63
|
+
Credentials;
|
|
64
|
+
Contacts;
|
|
65
|
+
Certificate;
|
|
66
|
+
Subscription;
|
|
67
|
+
Profile;
|
|
68
|
+
Injectors;
|
|
69
|
+
Repeater;
|
|
70
|
+
Group;
|
|
71
|
+
Video;
|
|
72
|
+
Export;
|
|
73
|
+
Query;
|
|
74
|
+
Files;
|
|
75
|
+
constructor(url, auth) {
|
|
76
|
+
this.url = url;
|
|
77
|
+
this.auth = auth;
|
|
78
|
+
this.Query = new Query(this);
|
|
79
|
+
this.Security = new Security(this);
|
|
80
|
+
this.Locate = new Locate(this);
|
|
81
|
+
this.Package = new Package(this);
|
|
82
|
+
this.Profile = new Profile(this);
|
|
83
|
+
this.Certificate = new Certificate(this);
|
|
84
|
+
this.OAuth = new OAuth(this);
|
|
85
|
+
this.Export = new Export(this);
|
|
86
|
+
this.Iconsets = new Iconsets(this);
|
|
87
|
+
this.Mission = new Mission(this);
|
|
88
|
+
this.MissionLog = new MissionLog(this);
|
|
89
|
+
this.MissionInvite = new MissionInvite(this);
|
|
90
|
+
this.MissionLayer = new MissionLayer(this);
|
|
91
|
+
this.Credentials = new Credentials(this);
|
|
92
|
+
this.Contacts = new Contacts(this);
|
|
93
|
+
this.Subscription = new Subscription(this);
|
|
94
|
+
this.Group = new Group(this);
|
|
95
|
+
this.Video = new Video(this);
|
|
96
|
+
this.Injectors = new Injectors(this);
|
|
97
|
+
this.Repeater = new Repeater(this);
|
|
98
|
+
this.Files = new Files(this);
|
|
99
|
+
}
|
|
100
|
+
static async init(url, auth) {
|
|
101
|
+
const api = new TAKAPI(url, auth);
|
|
102
|
+
await api.auth.init(api);
|
|
103
|
+
return api;
|
|
104
|
+
}
|
|
105
|
+
stdurl(url) {
|
|
106
|
+
try {
|
|
107
|
+
url = new URL(url);
|
|
108
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
url = new URL(url, this.url);
|
|
112
|
+
}
|
|
113
|
+
return url;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Standardize interactions with the backend API
|
|
117
|
+
*
|
|
118
|
+
* @param {URL|String} url - Full URL or API fragment to request
|
|
119
|
+
* @param {Object} [opts={}] - Options
|
|
120
|
+
*/
|
|
121
|
+
async fetch(url, opts = {}, raw = false) {
|
|
122
|
+
url = this.stdurl(url);
|
|
123
|
+
try {
|
|
124
|
+
if (!opts.headers)
|
|
125
|
+
opts.headers = {};
|
|
126
|
+
if ((isPlainObject(opts.body) || Array.isArray(opts.body))
|
|
127
|
+
&& (!opts.headers['Content-Type']
|
|
128
|
+
|| opts.headers['Content-Type'].startsWith('application/json'))) {
|
|
129
|
+
opts.body = JSON.stringify(opts.body);
|
|
130
|
+
opts.headers['Content-Type'] = 'application/json';
|
|
131
|
+
}
|
|
132
|
+
else if (opts.body instanceof FormData) {
|
|
133
|
+
opts.headers = opts.body.getHeaders();
|
|
134
|
+
}
|
|
135
|
+
else if (opts.body instanceof URLSearchParams) {
|
|
136
|
+
opts.headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
137
|
+
opts.body = String(opts.body);
|
|
138
|
+
}
|
|
139
|
+
const res = await this.auth.fetch(this, url, opts);
|
|
140
|
+
if (raw)
|
|
141
|
+
return res;
|
|
142
|
+
let bdy = {};
|
|
143
|
+
if ((res.status < 200 || res.status >= 400)) {
|
|
144
|
+
try {
|
|
145
|
+
bdy = await res.text();
|
|
146
|
+
}
|
|
147
|
+
catch (err) {
|
|
148
|
+
console.error(err);
|
|
149
|
+
bdy = null;
|
|
150
|
+
}
|
|
151
|
+
throw new Err(res.status, null, bdy || `Status Code: ${res.status}`);
|
|
152
|
+
}
|
|
153
|
+
if (res.headers.get('content-type') === 'application/json') {
|
|
154
|
+
return await res.json();
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
return await res.text();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
if (err instanceof Error && err.name === 'PublicError')
|
|
162
|
+
throw err;
|
|
163
|
+
throw new Err(400, null, err instanceof Error ? err.message : String(err));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function isPlainObject(value) {
|
|
168
|
+
return value?.constructor === Object;
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../lib/api.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,KAAK,MAAM,gBAAgB,CAAC;AACnC,OAAO,OAAO,MAAM,kBAAkB,CAAC;AACvC,OAAO,WAAW,MAAM,sBAAsB,CAAC;AAC/C,OAAO,KAAK,MAAM,gBAAgB,CAAC;AACnC,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,OAAO,MAAM,kBAAkB,CAAC;AACvC,OAAO,aAAa,MAAM,yBAAyB,CAAC;AACpD,OAAO,UAAU,MAAM,sBAAsB,CAAC;AAC9C,OAAO,YAAY,MAAM,wBAAwB,CAAC;AAClD,OAAO,WAAW,MAAM,sBAAsB,CAAC;AAC/C,OAAO,QAAQ,MAAM,mBAAmB,CAAC;AACzC,OAAO,QAAQ,MAAM,mBAAmB,CAAC;AACzC,OAAO,OAAO,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,MAAM,gBAAgB,CAAC;AACnC,OAAO,QAAQ,MAAM,mBAAmB,CAAC;AACzC,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,QAAQ,MAAM,mBAAmB,CAAC;AACzC,OAAO,KAAK,MAAM,iBAAiB,CAAC;AACpC,OAAO,YAAY,MAAM,wBAAwB,CAAC;AAClD,OAAO,KAAK,MAAM,gBAAgB,CAA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M,GAAG,CAAC,IAAI,EAAE,CAAC;YAC5B,CAAC;iBAAM,CAAC;gBACJ,OAAO,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;YAC5B,CAAC;QACL,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,IAAI,GAAG,YAAY,KAAK,IAAI,GAAG,CAAC,IAAI,KAAK,aAAa;gBAAE,MAAM,GAAG,CAAC;YAClE,MAAM,IAAI,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QAC/E,CAAC;IACL,CAAC;CACJ;AAED,SAAS,aAAa,CAAC,KAAa;IAChC,OAAQ,KAAK,EAAE,WAAW,KAAK,MAAM,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import TAKAPI from './api.js';
|
|
2
|
+
/**
|
|
3
|
+
* Store the TAK Client Certificate for a connection
|
|
4
|
+
*/
|
|
5
|
+
export declare const TAKAuth: import("@sinclair/typebox").TObject<{
|
|
6
|
+
cert: import("@sinclair/typebox").TString;
|
|
7
|
+
key: import("@sinclair/typebox").TString;
|
|
8
|
+
passphrase: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
9
|
+
ca: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
10
|
+
rejectUnauthorized: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
11
|
+
}>;
|
|
12
|
+
export declare class APIAuth {
|
|
13
|
+
init(api: TAKAPI): Promise<void>;
|
|
14
|
+
fetch(api: TAKAPI, url: URL, opts: any): Promise<any>;
|
|
15
|
+
}
|
|
16
|
+
export declare class APIAuthPassword extends APIAuth {
|
|
17
|
+
username: string;
|
|
18
|
+
password: string;
|
|
19
|
+
jwt: string;
|
|
20
|
+
constructor(username: string, password: string);
|
|
21
|
+
init(api: TAKAPI): Promise<void>;
|
|
22
|
+
fetch(api: TAKAPI, url: URL, opts: any): Promise<any>;
|
|
23
|
+
}
|
|
24
|
+
export declare class APIAuthToken extends APIAuth {
|
|
25
|
+
jwt?: string;
|
|
26
|
+
constructor(jwt: string);
|
|
27
|
+
fetch(api: TAKAPI, url: URL, opts: any): Promise<any>;
|
|
28
|
+
}
|
|
29
|
+
export declare class APIAuthCertificate extends APIAuth {
|
|
30
|
+
cert: string;
|
|
31
|
+
key: string;
|
|
32
|
+
constructor(cert: string, key: string);
|
|
33
|
+
fetch(api: TAKAPI, url: URL, opts: any): Promise<any>;
|
|
34
|
+
}
|
package/dist/lib/auth.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import fetch from './fetch.js';
|
|
2
|
+
import { Type } from '@sinclair/typebox';
|
|
3
|
+
import { Client } from 'undici';
|
|
4
|
+
import stream2buffer from './stream.js';
|
|
5
|
+
/**
|
|
6
|
+
* Store the TAK Client Certificate for a connection
|
|
7
|
+
*/
|
|
8
|
+
export const TAKAuth = Type.Object({
|
|
9
|
+
cert: Type.String(),
|
|
10
|
+
key: Type.String(),
|
|
11
|
+
passphrase: Type.Optional(Type.String()),
|
|
12
|
+
ca: Type.Optional(Type.String()),
|
|
13
|
+
rejectUnauthorized: Type.Optional(Type.Boolean())
|
|
14
|
+
});
|
|
15
|
+
export class APIAuth {
|
|
16
|
+
async init(api) {
|
|
17
|
+
}
|
|
18
|
+
async fetch(api, url, opts) {
|
|
19
|
+
return await fetch(url, opts);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export class APIAuthPassword extends APIAuth {
|
|
23
|
+
username;
|
|
24
|
+
password;
|
|
25
|
+
jwt;
|
|
26
|
+
constructor(username, password) {
|
|
27
|
+
super();
|
|
28
|
+
this.username = username;
|
|
29
|
+
this.password = password;
|
|
30
|
+
this.jwt = '';
|
|
31
|
+
}
|
|
32
|
+
async init(api) {
|
|
33
|
+
const { token } = await api.OAuth.login({
|
|
34
|
+
username: this.username,
|
|
35
|
+
password: this.password
|
|
36
|
+
});
|
|
37
|
+
this.jwt = token;
|
|
38
|
+
}
|
|
39
|
+
async fetch(api, url, opts) {
|
|
40
|
+
opts.headers = opts.headers || {};
|
|
41
|
+
opts.credentials = 'include';
|
|
42
|
+
if (!opts.headers.Authorization && this.jwt) {
|
|
43
|
+
opts.headers.Authorization = `Bearer ${this.jwt}`;
|
|
44
|
+
}
|
|
45
|
+
return await fetch(url, opts);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export class APIAuthToken extends APIAuth {
|
|
49
|
+
jwt;
|
|
50
|
+
constructor(jwt) {
|
|
51
|
+
super();
|
|
52
|
+
this.jwt = jwt;
|
|
53
|
+
}
|
|
54
|
+
async fetch(api, url, opts) {
|
|
55
|
+
opts.headers = opts.headers || {};
|
|
56
|
+
opts.credentials = 'include';
|
|
57
|
+
if (!opts.headers.Authorization && this.jwt) {
|
|
58
|
+
opts.headers.Authorization = `Bearer ${this.jwt}`;
|
|
59
|
+
}
|
|
60
|
+
return await fetch(url, opts);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export class APIAuthCertificate extends APIAuth {
|
|
64
|
+
cert;
|
|
65
|
+
key;
|
|
66
|
+
constructor(cert, key) {
|
|
67
|
+
super();
|
|
68
|
+
this.cert = cert;
|
|
69
|
+
this.key = key;
|
|
70
|
+
}
|
|
71
|
+
async fetch(api, url, opts) {
|
|
72
|
+
const client = new Client(api.url.origin, {
|
|
73
|
+
connect: {
|
|
74
|
+
key: this.key,
|
|
75
|
+
cert: this.cert,
|
|
76
|
+
rejectUnauthorized: false,
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
const res = await client.request({
|
|
80
|
+
path: String(url).replace(api.url.origin, ''),
|
|
81
|
+
...opts
|
|
82
|
+
});
|
|
83
|
+
return {
|
|
84
|
+
status: res.statusCode,
|
|
85
|
+
body: res.body,
|
|
86
|
+
// Make this similiar to the fetch standard
|
|
87
|
+
headers: new Map(Object.entries(res.headers)),
|
|
88
|
+
text: async () => {
|
|
89
|
+
return String(await stream2buffer(res.body));
|
|
90
|
+
},
|
|
91
|
+
json: async () => {
|
|
92
|
+
return JSON.parse(String(await stream2buffer(res.body)));
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../lib/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,aAAa,MAAO,aAAa,CAAC;AAEzC;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC;IAC/B,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE;IACnB,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE;IAClB,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;IACxC,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;IAChC,kBAAkB,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;CACpD,CAAC,CAAA;AAEF,MAAM,OAAO,OAAO;IAChB,KAAK,CAAC,IAAI,CAAC,GAAW;IAEtB,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,GAAW,EAAE,GAAQ,EAAE,IAAS;QACxC,OAAO,MAAM,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAClC,CAAC;CACJ;AAED,MAAM,OAAO,eAAgB,SAAQ,OAAO;IACxC,QAAQ,CAAS;IACjB,QAAQ,CAAS;IACjB,GAAG,CAAS;IAEZ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D,CAAC;YACD,IAAI,EAAE,KAAK,IAAI,EAAE;gBACb,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAC7D,CAAC;SACJ,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ParsedArgs } from 'minimist';
|
|
2
|
+
import TAKAPI from './api.js';
|
|
3
|
+
import type { TObject } from '@sinclair/typebox';
|
|
4
|
+
export declare const CommandConfig: TObject<{
|
|
5
|
+
version: import("@sinclair/typebox").TInteger;
|
|
6
|
+
profiles: import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, TObject<{
|
|
7
|
+
host: import("@sinclair/typebox").TString;
|
|
8
|
+
ports: TObject<{
|
|
9
|
+
marti: import("@sinclair/typebox").TInteger;
|
|
10
|
+
webtak: import("@sinclair/typebox").TInteger;
|
|
11
|
+
stream: import("@sinclair/typebox").TInteger;
|
|
12
|
+
}>;
|
|
13
|
+
auth: import("@sinclair/typebox").TOptional<TObject<{
|
|
14
|
+
cert: import("@sinclair/typebox").TString;
|
|
15
|
+
key: import("@sinclair/typebox").TString;
|
|
16
|
+
passphrase: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
17
|
+
ca: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
18
|
+
rejectUnauthorized: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
19
|
+
}>>;
|
|
20
|
+
}>>;
|
|
21
|
+
}>;
|
|
22
|
+
export declare enum CommandOutputFormat {
|
|
23
|
+
JSON = "json",
|
|
24
|
+
GEOJSON = "geojson",
|
|
25
|
+
XML = "xml",
|
|
26
|
+
BINARY = "binary"
|
|
27
|
+
}
|
|
28
|
+
export default class Commands {
|
|
29
|
+
api: TAKAPI;
|
|
30
|
+
schema: Record<string, {
|
|
31
|
+
description: string;
|
|
32
|
+
params: TObject<any>;
|
|
33
|
+
query: TObject<any>;
|
|
34
|
+
formats: Array<CommandOutputFormat>;
|
|
35
|
+
}>;
|
|
36
|
+
constructor(api: TAKAPI);
|
|
37
|
+
cli(args: ParsedArgs): Promise<object | string>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { TAKAuth } from './auth.js';
|
|
2
|
+
import { Type } from '@sinclair/typebox';
|
|
3
|
+
export const CommandConfig = Type.Object({
|
|
4
|
+
version: Type.Integer(),
|
|
5
|
+
profiles: Type.Record(Type.String(), Type.Object({
|
|
6
|
+
host: Type.String(),
|
|
7
|
+
ports: Type.Object({
|
|
8
|
+
marti: Type.Integer(),
|
|
9
|
+
webtak: Type.Integer(),
|
|
10
|
+
stream: Type.Integer()
|
|
11
|
+
}),
|
|
12
|
+
auth: Type.Optional(TAKAuth)
|
|
13
|
+
}))
|
|
14
|
+
});
|
|
15
|
+
export var CommandOutputFormat;
|
|
16
|
+
(function (CommandOutputFormat) {
|
|
17
|
+
CommandOutputFormat["JSON"] = "json";
|
|
18
|
+
CommandOutputFormat["GEOJSON"] = "geojson";
|
|
19
|
+
CommandOutputFormat["XML"] = "xml";
|
|
20
|
+
CommandOutputFormat["BINARY"] = "binary";
|
|
21
|
+
})(CommandOutputFormat || (CommandOutputFormat = {}));
|
|
22
|
+
export default class Commands {
|
|
23
|
+
api;
|
|
24
|
+
schema = {};
|
|
25
|
+
constructor(api) {
|
|
26
|
+
this.api = api;
|
|
27
|
+
}
|
|
28
|
+
async cli(args) {
|
|
29
|
+
if (!args)
|
|
30
|
+
throw new Error('Args object must be provided');
|
|
31
|
+
throw new Error('Command not yet supported');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.js","sourceRoot":"","sources":["../../lib/commands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC;IACrC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;IACvB,QAAQ,EAAE,IAAI,CAAC,MAAM,CACjB,IAAI,CAAC,MAAM,EAAE,EACb,IAAI,CAAC,MAAM,CAAC;QACR,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE;QACnB,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC;YACf,KAAK,EAAE,IAAI,CAAC,OAAO,EAAE;YACrB,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE;YACtB,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE;SACzB,CAAC;QACF,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;KAC/B,CAAC,CACL;CACJ,CAAC,CAAA;AAEF,MAAM,CAAN,IAAY,mBAKX;AALD,WAAY,mBAAmB;IAC3B,oCAAa,CAAA;IACb,0CAAmB,CAAA;IACnB,kCAAW,CAAA;IACX,wCAAiB,CAAA;AACrB,CAAC,EALW,mBAAmB,KAAnB,mBAAmB,QAK9B;AAED,MAAM,CAAC,OAAO,OAAO,QAAQ;IACzB,GAAG,CAAS;IAEZ,MAAM,GAKD,EAAE,CAAC;IAER,YAAY,GAAW;QACnB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,IAAgB;QACtB,IAAI,CAAC,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAC3D,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IACjD,CAAC;CACJ"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Static, TSchema } from "@sinclair/typebox";
|
|
2
|
+
import { Response } from 'undici';
|
|
3
|
+
import type { RequestInfo, RequestInit } from 'undici';
|
|
4
|
+
export declare class TypedResponse extends Response {
|
|
5
|
+
constructor(response: Response);
|
|
6
|
+
typed<T extends TSchema>(type: T): Promise<Static<T>>;
|
|
7
|
+
}
|
|
8
|
+
export default function (input: RequestInfo, init?: RequestInit): Promise<TypedResponse>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import Err from '@openaddresses/batch-error';
|
|
2
|
+
import { TypeCompiler } from "@sinclair/typebox/compiler";
|
|
3
|
+
import { fetch, Response } from 'undici';
|
|
4
|
+
export class TypedResponse extends Response {
|
|
5
|
+
constructor(response) {
|
|
6
|
+
super(response.body, {
|
|
7
|
+
status: response.status,
|
|
8
|
+
statusText: response.statusText,
|
|
9
|
+
headers: response.headers,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
async typed(type) {
|
|
13
|
+
const body = await this.json();
|
|
14
|
+
const typeChecker = TypeCompiler.Compile(type);
|
|
15
|
+
const result = typeChecker.Check(body);
|
|
16
|
+
if (result)
|
|
17
|
+
return body;
|
|
18
|
+
const errors = typeChecker.Errors(body);
|
|
19
|
+
const firstError = errors.First();
|
|
20
|
+
throw new Err(500, null, `Internal Validation Error: ${JSON.stringify(firstError)}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export default async function (input, init) {
|
|
24
|
+
return new TypedResponse(await fetch(input, init));
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../lib/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,4BAA4B,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAGzC,MAAM,OAAO,aAAc,SAAQ,QAAQ;IACvC,YAAY,QAAkB;QAC1B,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE;YACjB,MAAM,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