Skip to content
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jupiterone/jupiterone-client-nodejs",
"version": "2.1.0",
"version": "2.1.1",
"description": "A node.js client wrapper for JupiterOne public API",
"repository": {
"type": "git",
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ export class JupiterOneClient {
let progress: any;

do {
this.logger.debug({j1ql}, "Sending query");
const res = await this.graphClient.query({
query: QUERY_V1,
variables: {
Expand All @@ -389,6 +390,7 @@ export class JupiterOneClient {
throw new Error(`JupiterOne returned error(s) for query: '${j1ql}'`);
}

this.logger.debug(res.data, "Retrieved response");
const deferredUrl = res.data.queryV1.url;
let status = JobStatus.IN_PROGRESS;
let statusFile: any;
Expand All @@ -400,7 +402,7 @@ export class JupiterOneClient {
} seconds.`,
);
}
this.logger.trace('Sleeping to wait for JobCompletion');
this.logger.debug('Sleeping to wait for JobCompletion');
await sleep(100);
statusFile = await networkRequest(deferredUrl);
status = statusFile.status;
Expand All @@ -411,6 +413,7 @@ export class JupiterOneClient {
throw new Error(`JupiterOne returned error(s) for query: '${statusFile.error}'`);
}

this.logger.info("Retrieving query data");
const result = statusFile.data;

if (showProgress && !limitCheck) {
Expand Down
19 changes: 12 additions & 7 deletions src/networkRequest.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
// Temporary helper file because it's difficult to mock in the current architecture

import fetch from 'node-fetch';
import { retry } from "@lifeomic/attempt";

export const networkRequest = async (
url: string,
): Promise<Record<string, unknown>> => {
const result = await fetch(url);
const result = await retry(async () => {
console.log(`Fetching ${url}`);
const result = await fetch(url);
const { status } = result;

const { status, headers } = result;
if (status < 200 || status >= 300) {
const body = await result.text();
throw new Error(`HTTP request failed (${status}): ${body}`);
}

if (status < 200 || status >= 300) {
const body = await result.text();
throw new Error(`HTTP request failed (${status}): ${body}`);
}
return result;
});

const contentType = headers.get('content-type');
const contentType = result.headers.get('content-type');
if (contentType?.includes('application/json') === false) {
const body = await result.text();
throw new Error(`HTTP response is not JSON but ${contentType}: ${body}`);
Expand Down