Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.
/ js-client Public archive

Commit

Permalink
Merge branch 'dev' of https://github.com/gravwell/js-client into fix/…
Browse files Browse the repository at this point in the history
…extractor
  • Loading branch information
LucasPaganini committed Jun 21, 2022
2 parents 5b6af56 + e99e3db commit b4b6a4b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
13 changes: 6 additions & 7 deletions src/functions/kits/delete-one-archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@
* MIT license. See the LICENSE file for details.
**************************************************************************/

import { APIContext, buildHTTPRequestWithAuthFromContext, buildURL } from '../utils';
import { APIContext, buildHTTPRequestWithAuthFromContext, buildURL, parseJSONResponse } from '../utils';

export const makeDeleteOneKitArchive = (context: APIContext) => {
return async (archiveID: string): Promise<boolean> => {
const path = '/api/kits/build/history/' + archiveID;
const url = buildURL(path, { ...context, protocol: 'http' });
return async (archiveID: string): Promise<void> => {
const templatePath = '/api/kits/build/history/{archiveID}';
const url = buildURL(templatePath, { ...context, protocol: 'http', pathParams: { archiveID } });

const req = buildHTTPRequestWithAuthFromContext(context);

const respnse = await context.fetch(url, { ...req, method: 'DELETE' });
// The API response is empty so we just check on status
return respnse.status === 200;
const raw = await context.fetch(url, { ...req, method: 'DELETE' });
return parseJSONResponse(raw, { expect: 'void' });
};
};
26 changes: 16 additions & 10 deletions src/functions/logs/create-one-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,24 @@ import {
} from '../utils';

export const makeCreateOneLog = (context: APIContext) => {
const templatePath = '/api/logging/{lowerCaseRawLogLevel}';

return async (level: LogLevel, message: string): Promise<void> => {
const templatePath = '/api/logging/{lowerCaseRawLogLevel}';
const lowerCaseRawLogLevel = toRawLogLevel(level).toLowerCase();
const url = buildURL(templatePath, { ...context, protocol: 'http', pathParams: { lowerCaseRawLogLevel } });
try {
const lowerCaseRawLogLevel = toRawLogLevel(level).toLowerCase();
const url = buildURL(templatePath, { ...context, protocol: 'http', pathParams: { lowerCaseRawLogLevel } });

const baseRequestOptions: HTTPRequestOptions = {
body: JSON.stringify({ Body: message }),
};
const req = buildHTTPRequestWithAuthFromContext(context, baseRequestOptions);
const baseRequestOptions: HTTPRequestOptions = {
body: JSON.stringify({ Body: message }),
};
const req = buildHTTPRequestWithAuthFromContext(context, baseRequestOptions);

const raw = await context.fetch(url, { ...req, method: 'POST' });
const success = await parseJSONResponse<boolean>(raw);
if (!success) throw Error(`Couldn't create the log`);
const raw = await context.fetch(url, { ...req, method: 'POST' });
const success = await parseJSONResponse<boolean>(raw);
if (!success) throw Error(`Couldn't create the log`);
} catch (err) {
if (err instanceof Error) throw err;
throw Error('Unknown error');
}
};
};
2 changes: 1 addition & 1 deletion src/services/kits/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export interface KitsService {
readonly all: () => Promise<Array<KitArchive>>;
};
readonly delete: {
readonly one: (archiveID: string) => Promise<boolean>;
readonly one: (archiveID: string) => Promise<void>;
};
};
}

0 comments on commit b4b6a4b

Please sign in to comment.