Skip to content

Commit

Permalink
fix: use orgId from options
Browse files Browse the repository at this point in the history
  • Loading branch information
jozsef-armin-hamos committed Oct 4, 2023
1 parent 16b5e43 commit 90c5496
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
13 changes: 10 additions & 3 deletions src/bundles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
getFilters,
} from './http';

import { MAX_UPLOAD_ATTEMPTS, UPLOAD_CONCURRENCY } from './constants';
import { MAX_RETRY_ATTEMPTS, MAX_UPLOAD_ATTEMPTS, UPLOAD_CONCURRENCY } from './constants';
import { emitter } from './emitter';
import { AnalyzeFoldersOptions } from './interfaces/analysis-options.interface';

Expand Down Expand Up @@ -200,9 +200,10 @@ export async function getSupportedFiles(
source: string,
requestId?: string,
languages?: string[],
orgId?: string,
): Promise<SupportedFiles> {
emitter.supportedFilesLoaded(null);
const resp = await getFilters(baseURL, source, undefined, requestId);
const resp = await getFilters(baseURL, source, MAX_RETRY_ATTEMPTS, requestId, orgId);
if (resp.type === 'error') {
throw resp.error;
}
Expand Down Expand Up @@ -246,7 +247,13 @@ export interface CreateBundleFromFoldersOptions extends ConnectionOptions, Analy
*/
export async function createBundleFromFolders(options: CreateBundleFromFoldersOptions): Promise<FileBundle | null> {
// Fetch supported files to save network traffic
const supportedFiles = await getSupportedFiles(options.baseURL, options.source, options.requestId, options.languages);
const supportedFiles = await getSupportedFiles(
options.baseURL,
options.source,
options.requestId,
options.languages,
options.orgId,
);

// Collect files and create a remote bundle
return await createBundleWithCustomFiles(options, supportedFiles);
Expand Down
4 changes: 2 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ function parseConnectionOptions(options: {
};
}

async function filtersAction(options: { url: string; token: string; source: string; org?: string }) {
const response = await getSupportedFiles(options.url, options.source);
async function filtersAction(options: { url: string; token: string; source: string; org?: string; orgId?: string }) {
const response = await getSupportedFiles(options.url, options.source, undefined, [], options.orgId);
console.log(JSON.stringify(response, null, 2));
}

Expand Down
20 changes: 11 additions & 9 deletions src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface ConnectionOptions {
source: string;
requestId?: string;
org?: string;
orgId?: string;
extraHeaders?: { [key: string]: string };
}

Expand Down Expand Up @@ -180,12 +181,13 @@ export async function getFilters(
source: string,
attempts = MAX_RETRY_ATTEMPTS,
requestId?: string,
orgId?: string,
): Promise<Result<SupportedFiles, GenericErrorTypes>> {
const apiName = 'filters';
let url: string;

try {
url = getURL(baseURL, '/' + apiName, '00000000-0000-0000-0000-00000000');
url = getURL(baseURL, '/' + apiName, orgId);
} catch (err) {
return generateError<GenericErrorTypes>(400, err.message, apiName);
}
Expand Down Expand Up @@ -248,7 +250,7 @@ export async function createBundle(
let url: string;

try {
url = getURL(options.baseURL, '/bundle', options.org);
url = getURL(options.baseURL, '/bundle', options.orgId);
} catch (err) {
return generateError<CreateBundleErrorCodes>(400, err.message, 'createBundle');
}
Expand Down Expand Up @@ -293,7 +295,7 @@ export async function checkBundle(options: CheckBundleOptions): Promise<Result<R
let url: string;

try {
url = getURL(options.baseURL, `/bundle/${options.bundleHash}`, options.org);
url = getURL(options.baseURL, `/bundle/${options.bundleHash}`, options.orgId);
} catch (err) {
return generateError<CheckBundleErrorCodes>(400, err.message, 'checkBundle');
}
Expand Down Expand Up @@ -340,7 +342,7 @@ export async function extendBundle(
let url: string;

try {
url = getURL(options.baseURL, `/bundle/${options.bundleHash}`, options.org);
url = getURL(options.baseURL, `/bundle/${options.bundleHash}`, options.orgId);
} catch (err) {
return generateError<ExtendBundleErrorCodes>(400, err.message, 'extendBundle');
}
Expand Down Expand Up @@ -407,7 +409,7 @@ export async function getAnalysis(
let url: string;

try {
url = getURL(options.baseURL, '/analysis', options.org);
url = getURL(options.baseURL, '/analysis', options.orgId);
} catch (err) {
return generateError<GetAnalysisErrorCodes>(400, err.message, 'getAnalysis');
}
Expand Down Expand Up @@ -476,7 +478,7 @@ export async function initReport(options: UploadReportOptions): Promise<Result<s
let url: string;

try {
url = getURL(options.baseURL, `/report`, options.org);
url = getURL(options.baseURL, `/report`, options.orgId);
} catch (err) {
return generateError<ReportErrorCodes>(400, err.message, 'initReport');
}
Expand Down Expand Up @@ -516,7 +518,7 @@ export async function getReport(options: GetReportOptions): Promise<Result<Uploa
let url: string;

try {
url = getURL(options.baseURL, `/report/${options.pollId}`, options.org);
url = getURL(options.baseURL, `/report/${options.pollId}`, options.orgId);
} catch (err) {
return generateError<ReportErrorCodes>(400, err.message, 'getReport');
}
Expand All @@ -541,7 +543,7 @@ export async function initScmReport(options: ScmUploadReportOptions): Promise<Re
let url: string;

try {
url = getURL(options.baseURL, `/test`, options.org);
url = getURL(options.baseURL, `/test`, options.orgId);
} catch (err) {
return generateError<ReportErrorCodes>(400, err.message, 'initReport');
}
Expand Down Expand Up @@ -574,7 +576,7 @@ export async function getScmReport(
let url: string;

try {
url = getURL(options.baseURL, `/test/${options.pollId}`, options.org);
url = getURL(options.baseURL, `/test/${options.pollId}`, options.orgId);
} catch (err) {
return generateError<ReportErrorCodes>(400, err.message, 'getReport');
}
Expand Down

0 comments on commit 90c5496

Please sign in to comment.