Skip to content
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

Inital Load #315

Merged
merged 19 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
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
18 changes: 2 additions & 16 deletions api/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import fs from 'node:fs';
import path from 'node:path';
import cors from 'cors';
import jwt from 'jsonwebtoken';
import express, { Request, Response } from 'express';
import express from 'express';
import SwaggerUI from 'swagger-ui-express';
import history, {Context} from 'connect-history-api-fallback';
import Schema from '@openaddresses/batch-schema';
Expand All @@ -25,8 +24,6 @@ const args = minimist(process.argv, {
'noevents', // Disable Initialization of Second Level Events
'nometrics', // Disable Sending AWS CloudWatch Metrics about each conn
'nosinks', // Disable Push to Sinks
'local' // (experimental) Disable external calls on startup (for developing in low connectivity)
// Note this is the min for serving requests - it doesn't make it particularly functional
],
string: [
'postgres', // Postgres Connection String
Expand Down Expand Up @@ -55,7 +52,6 @@ if (import.meta.url === `file://${process.argv[1]}`) {
nometrics: args.nometrics || false,
nosinks: args.nosinks || false,
nocache: args.nocache || false,
local: args.local || false,
});
await server(config);
}
Expand Down Expand Up @@ -85,6 +81,7 @@ export default async function server(config: Config) {
allowedHeaders: [
'Content-Type',
'Authorization',
'MissionAuthorization',
'Content-Length',
'x-requested-with'
],
Expand Down Expand Up @@ -113,17 +110,6 @@ export default async function server(config: Config) {

await schema.api();

if (config.local) {
// Mock WebTAK API to allow any username & Password
app.get('/oauth/token', (req: Request, res: Response) => {
return res.json({
access_token: jwt.sign({
user_name: req.params.username
}, config.SigningSecret)
});
});
}

await schema.load(
new URL('./routes/', import.meta.url),
config,
Expand Down
4 changes: 3 additions & 1 deletion api/lib/api/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export default class {
const params = new URLSearchParams();
let q: keyof Static<typeof ExportInput>;
for (q in query) {
params.append(q, String(query[q]));
if (query[q] !== undefined ) {
params.append(q, String(query[q]));
}
}

const res = await this.api.fetch(url, {
Expand Down
37 changes: 25 additions & 12 deletions api/lib/api/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export const Group = Type.Object({
description: Type.Optional(Type.String())
})

export const GroupListInput = Type.Object({
useCache: Type.Optional(Type.Boolean())
})

export default class {
api: TAKAPI;
Expand All @@ -20,25 +23,35 @@ export default class {
this.api = api;
}

async list(query: {
useCache?: boolean;

[key: string]: unknown;
}): Promise<TAKList<Static<typeof Group>>> {
async list(
query: Static<typeof GroupListInput> = {}
): Promise<TAKList<Static<typeof Group>>> {
const url = new URL(`/Marti/api/groups/all`, this.api.url);
for (const q in query) url.searchParams.append(q, String(query[q]));

let q: keyof Static<typeof GroupListInput>;
for (q in query) {
if (query[q] !== undefined) {
url.searchParams.append(q, String(query[q]));
}
}

return await this.api.fetch(url, {
method: 'GET'
});
}

async update(body: Static<typeof Group>[], query: {
clientUid?: string;

[key: string]: unknown;
}): Promise<void> {
async update(
body: Static<typeof Group>[],
query: Static<typeof GroupListInput> = {}
): Promise<void> {
const url = new URL(`/Marti/api/groups/active`, this.api.url);
for (const q in query) url.searchParams.append(q, String(query[q]));

let q: keyof Static<typeof GroupListInput>;
for (q in query) {
if (query[q] !== undefined) {
url.searchParams.append(q, String(query[q]));
}
}

await this.api.fetch(url, {
method: 'PUT',
Expand Down
42 changes: 36 additions & 6 deletions api/lib/api/mission-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,12 @@ export default class {
const url = new URL(`/Marti/api/missions/guid/${this.#encodeName(name)}/layers`, this.api.url);

let q: keyof Static<typeof CreateInput>;
for (q in query) url.searchParams.append(q, String(query[q]));
for (q in query) {
if (query[q] !== undefined) {
url.searchParams.append(q, String(query[q]));
}
}

return await this.api.fetch(url, {
method: 'PUT',
headers: this.#headers(opts),
Expand All @@ -173,7 +178,12 @@ export default class {
const url = new URL(`/Marti/api/missions/${this.#encodeName(name)}/layers`, this.api.url);

let q: keyof Static<typeof CreateInput>;
for (q in query) url.searchParams.append(q, String(query[q]));
for (q in query) {
if (query[q] !== undefined) {
url.searchParams.append(q, String(query[q]));
}
}

return await this.api.fetch(url, {
method: 'PUT',
headers: this.#headers(opts),
Expand All @@ -191,7 +201,12 @@ export default class {
const url = new URL(`/Marti/api/missions/guid/${this.#encodeName(name)}/layers/${layer}/name`, this.api.url);

let q: keyof Static<typeof RenameInput>;
for (q in query) url.searchParams.append(q, String(query[q]));
for (q in query) {
if (query[q] !== undefined) {
url.searchParams.append(q, String(query[q]));
}
}

return await this.api.fetch(url, {
method: 'PUT',
headers: this.#headers(opts),
Expand All @@ -200,7 +215,12 @@ export default class {
const url = new URL(`/Marti/api/missions/${this.#encodeName(name)}/layers/${layer}/name`, this.api.url);

let q: keyof Static<typeof RenameInput>;
for (q in query) url.searchParams.append(q, String(query[q]));
for (q in query) {
if (query[q] !== undefined) {
url.searchParams.append(q, String(query[q]));
}
}

return await this.api.fetch(url, {
method: 'PUT',
headers: this.#headers(opts),
Expand All @@ -217,7 +237,12 @@ export default class {
const url = new URL(`/Marti/api/missions/guid/${this.#encodeName(name)}/layers`, this.api.url);

let q: keyof Static<typeof DeleteInput>;
for (q in query) url.searchParams.append(q, String(query[q]));
for (q in query) {
if (query[q] !== undefined) {
url.searchParams.append(q, String(query[q]));
}
}

return await this.api.fetch(url, {
method: 'DELETE',
headers: this.#headers(opts),
Expand All @@ -226,7 +251,12 @@ export default class {
const url = new URL(`/Marti/api/missions/${this.#encodeName(name)}/layers`, this.api.url);

let q: keyof Static<typeof DeleteInput>;
for (q in query) url.searchParams.append(q, String(query[q]));
for (q in query) {
if (query[q] !== undefined) {
url.searchParams.append(q, String(query[q]));
}
}

return await this.api.fetch(url, {
method: 'DELETE',
headers: this.#headers(opts),
Expand Down
Loading
Loading