diff --git a/lib/api.ts b/lib/api.ts index 7a1a624..3b39015 100644 --- a/lib/api.ts +++ b/lib/api.ts @@ -1,5 +1,6 @@ import FormData from 'form-data'; import OAuth from './api/oauth.js'; +import Locate from './api/locate.js'; import Package from './api/package.js'; import Query from './api/query.js'; import Mission from './api/mission.js'; @@ -21,6 +22,7 @@ export const CommandList: Record = { package: 'Package', oauth: 'OAuth', mission: 'Mission', + locate: 'Locate', 'mission-log': 'MissionLog', 'mission-layer': 'MissionLayer', credential: 'Credentials', @@ -53,6 +55,7 @@ export default class TAKAPI { Injectors: Injectors; Repeater: Repeater; Group: Group; + Locate: Locate; Video: Video; Export: Export; Query: Query; @@ -72,6 +75,7 @@ export default class TAKAPI { this.Credentials = new Credentials(this); this.Contacts = new Contacts(this); this.Subscription = new Subscription(this); + this.Locate = new Locate(this); this.Group = new Group(this); this.Video = new Video(this); this.Injectors = new Injectors(this); diff --git a/lib/api/groups.ts b/lib/api/groups.ts index 596046c..22cdfcd 100644 --- a/lib/api/groups.ts +++ b/lib/api/groups.ts @@ -17,15 +17,27 @@ export const GroupListInput = Type.Object({ useCache: Type.Optional(Type.Boolean()) }) +export const MemberListInput = Type.Object({ + groupNameFilter: Type.String() +}) + export const TAKList_Group = TAKList(Group); +export const TAKList_Member = TAKList(Group); export default class GroupCommands extends Commands { schema = { list: { - description: 'List Missions', + description: 'List Groups', params: Type.Object({}), query: Type.Object({}), formats: [ CommandOutputFormat.JSON ] + }, + + 'list-members': { + description: 'List Members', + params: Type.Object({}), + query: Type.Object(MemberListInput), + formats: [ CommandOutputFormat.JSON ] } } @@ -40,6 +52,19 @@ export default class GroupCommands extends Commands { return `${channel.name} - ${channel.description}`; }).join('\n'); } + } else if (args._[3] === 'list-members') { + const list = await this.members({ + groupNameFilter: args.groupNameFilter || '' + }); + + if (args.format === 'json') { + return list; + } else { + return list.data.map((member) => { + console.error(member); + return `${channel.name} - ${channel.description}`; + }).join('\n'); + } } else { throw new Error('Unsupported Subcommand'); } @@ -80,4 +105,23 @@ export default class GroupCommands extends Commands { body }); } + + async members( + query: Static = {} + ): Promise> { + const url = new URL(`/Marti/api/groups/members`, this.api.url); + + let q: keyof Static; + for (q in query) { + if (query[q] !== undefined) { + url.searchParams.append(q, String(query[q])); + } + } + + console.error(url); + + return await this.api.fetch(url, { + method: 'GET' + }); + } }