Skip to content

Add Locate & Members API #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/api.ts
Original file line number Diff line number Diff line change
@@ -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 @@
package: 'Package',
oauth: 'OAuth',
mission: 'Mission',
locate: 'Locate',
'mission-log': 'MissionLog',
'mission-layer': 'MissionLayer',
credential: 'Credentials',
@@ -53,6 +55,7 @@
Injectors: Injectors;
Repeater: Repeater;
Group: Group;
Locate: Locate;
Video: Video;
Export: Export;
Query: Query;
@@ -72,6 +75,7 @@
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);
@@ -104,7 +108,7 @@
* @param {URL|String} url - Full URL or API fragment to request
* @param {Object} [opts={}] - Options
*/
async fetch(url: URL, opts: any = {}, raw=false) {

Check warning on line 111 in lib/api.ts

GitHub Actions / test

Unexpected any. Specify a different type

Check warning on line 111 in lib/api.ts

GitHub Actions / test

Unexpected any. Specify a different type
url = this.stdurl(url);

try {
@@ -130,7 +134,7 @@

if (raw) return res;

let bdy: any = {};

Check warning on line 137 in lib/api.ts

GitHub Actions / test

Unexpected any. Specify a different type

Check warning on line 137 in lib/api.ts

GitHub Actions / test

Unexpected any. Specify a different type

if ((res.status < 200 || res.status >= 400)) {
try {
46 changes: 45 additions & 1 deletion lib/api/groups.ts
Original file line number Diff line number Diff line change
@@ -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<typeof MemberListInput> = {}
): Promise<Static<typeof TAKList_Member>> {
const url = new URL(`/Marti/api/groups/members`, this.api.url);

let q: keyof Static<typeof MemberListInput>;
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'
});
}
}

Unchanged files with check annotations Beta

): Promise<Static<typeof Feature.Feature>[]> {
const feats: Static<typeof Feature.Feature>[] = [];
const res: any = xmljs.xml2js(await this.latestCots(name, opts), { compact: true });

Check warning on line 297 in lib/api/mission.ts

GitHub Actions / test

Unexpected any. Specify a different type

Check warning on line 297 in lib/api/mission.ts

GitHub Actions / test

Unexpected any. Specify a different type
if (!Object.keys(res.events).length) return feats;
if (!res.events.event || (Array.isArray(res.events.event) && !res.events.event.length)) return feats;
throw new Err(400, new Error(`Status: ${authres.status}: ${text}`), 'Non-200 Response from Auth Server - Token');
}
const body: any = JSON.parse(text);

Check warning on line 55 in lib/api/oauth.ts

GitHub Actions / test

Unexpected any. Specify a different type

Check warning on line 55 in lib/api/oauth.ts

GitHub Actions / test

Unexpected any. Specify a different type
if (body.error === 'invalid_grant' && body.error_description.startsWith('Bad credentials')) {
throw new Err(400, null, 'Invalid Username or Password');
async historyFeats(uid: string, opts?: Static<typeof HistoryOptions>): Promise<Array<Static<typeof Feature.Feature>>> {
const feats: Static<typeof Feature.Feature>[] = [];
const res: any = xmljs.xml2js(await this.history(uid, opts), { compact: true });

Check warning on line 45 in lib/api/query.ts

GitHub Actions / test

Unexpected any. Specify a different type

Check warning on line 45 in lib/api/query.ts

GitHub Actions / test

Unexpected any. Specify a different type
if (!Object.keys(res).length || !Object.keys(res.events).length) return feats;
if (!res.events.event || (Array.isArray(res.events.event) && !res.events.event.length)) return feats;
}
async fetch(api: TAKAPI, url: URL, opts: any): Promise<any> {

Check warning on line 25 in lib/auth.ts

GitHub Actions / test

Unexpected any. Specify a different type

Check warning on line 25 in lib/auth.ts

GitHub Actions / test

Unexpected any. Specify a different type

Check warning on line 25 in lib/auth.ts

GitHub Actions / test

Unexpected any. Specify a different type

Check warning on line 25 in lib/auth.ts

GitHub Actions / test

Unexpected any. Specify a different type
return await fetch(url, opts);
}
}
this.jwt = token;
}
async fetch(api: TAKAPI, url: URL, opts: any): Promise<any> {

Check warning on line 51 in lib/auth.ts

GitHub Actions / test

Unexpected any. Specify a different type

Check warning on line 51 in lib/auth.ts

GitHub Actions / test

Unexpected any. Specify a different type

Check warning on line 51 in lib/auth.ts

GitHub Actions / test

Unexpected any. Specify a different type

Check warning on line 51 in lib/auth.ts

GitHub Actions / test

Unexpected any. Specify a different type
const jar = new CookieJar();
await jar.setCookie(new Cookie({ key: 'access_token', value: this.jwt }), String(api.url));
this.jwt = jwt;
}
async fetch(api: TAKAPI, url: URL, opts: any): Promise<any> {

Check warning on line 75 in lib/auth.ts

GitHub Actions / test

Unexpected any. Specify a different type

Check warning on line 75 in lib/auth.ts

GitHub Actions / test

Unexpected any. Specify a different type
const jar = new CookieJar();
await jar.setCookie(new Cookie({ key: 'access_token', value: this.jwt }), String(api.url));