@metrevals/inspect-scout-viewer 0.2.3-beta.1763116516 → 0.2.3-beta.1763120092

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,8 @@
1
1
  import { ScanApi } from './api';
2
- export declare const apiScoutServer: () => ScanApi;
2
+ export type HeaderProvider = () => Promise<Record<string, string>>;
3
+ export declare const apiScoutServer: (options?: {
4
+ apiBaseUrl?: string;
5
+ headerProvider?: HeaderProvider;
6
+ resultsDir?: string;
7
+ }) => ScanApi;
3
8
  //# sourceMappingURL=api-scout-server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"api-scout-server.d.ts","sourceRoot":"","sources":["../../src/api/api-scout-server.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiB,OAAO,EAAE,MAAM,OAAO,CAAC;AAE/C,eAAO,MAAM,cAAc,QAAO,OA0CjC,CAAC"}
1
+ {"version":3,"file":"api-scout-server.d.ts","sourceRoot":"","sources":["../../src/api/api-scout-server.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiB,OAAO,EAAE,MAAM,OAAO,CAAC;AAG/C,MAAM,MAAM,cAAc,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAEnE,eAAO,MAAM,cAAc,GACzB,UAAS;IACP,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,UAAU,CAAC,EAAE,MAAM,CAAC;CAChB,KACL,OAgCF,CAAC"}
@@ -0,0 +1,26 @@
1
+ type HttpMethod = "GET" | "POST" | "PUT" | "DELETE";
2
+ export declare class ApiError extends Error {
3
+ status: number;
4
+ constructor(status: number, message: string);
5
+ }
6
+ export interface Request<T> {
7
+ headers?: Record<string, string>;
8
+ body?: string;
9
+ parse?: (text: string) => Promise<T>;
10
+ handleError?: (status: number) => T | undefined;
11
+ }
12
+ export type HeaderProvider = () => Promise<Record<string, string>>;
13
+ export interface ServerRequestApi {
14
+ fetchString: (method: HttpMethod, path: string, headers?: Record<string, string>, body?: string) => Promise<{
15
+ parsed: any;
16
+ raw: string;
17
+ }>;
18
+ fetchBytes: (method: HttpMethod, path: string) => Promise<ArrayBuffer>;
19
+ fetchType: <T>(method: HttpMethod, path: string, request?: Request<T>) => Promise<{
20
+ raw: string;
21
+ parsed: T;
22
+ }>;
23
+ }
24
+ export declare function serverRequestApi(baseUrl?: string, getHeaders?: HeaderProvider): ServerRequestApi;
25
+ export {};
26
+ //# sourceMappingURL=request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/api/request.ts"],"names":[],"mappings":"AAEA,KAAK,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC;AAEpD,qBAAa,QAAS,SAAQ,KAAK;IACjC,MAAM,EAAE,MAAM,CAAC;gBACH,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAI5C;AAED,MAAM,WAAW,OAAO,CAAC,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IACrC,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,CAAC,GAAG,SAAS,CAAC;CACjD;AAED,MAAM,MAAM,cAAc,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAEnE,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,CACX,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAChC,IAAI,CAAC,EAAE,MAAM,KACV,OAAO,CAAC;QACX,MAAM,EAAE,GAAG,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;KACb,CAAC,CAAC;IACH,UAAU,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;IACvE,SAAS,EAAE,CAAC,CAAC,EACX,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,KACjB,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,CAAC,CAAA;KAAE,CAAC,CAAC;CAC1C;AAED,wBAAgB,gBAAgB,CAC9B,OAAO,CAAC,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,cAAc,GAC1B,gBAAgB,CAiKlB"}
package/lib/index.js CHANGED
@@ -113799,39 +113799,160 @@ const NoPersistence = {
113799
113799
  removeItem: (_name) => {
113800
113800
  }
113801
113801
  };
113802
- const apiScoutServer = () => {
113803
- return {
113804
- getScan: async (scanLocation) => {
113805
- const response = await fetch(
113806
- `/api/scan/${encodeURIComponent(scanLocation)}`
113802
+ class ApiError extends Error {
113803
+ status;
113804
+ constructor(status, message2) {
113805
+ super(message2);
113806
+ this.status = status;
113807
+ }
113808
+ }
113809
+ function serverRequestApi(baseUrl, getHeaders) {
113810
+ const apiUrl = baseUrl;
113811
+ function buildApiUrl(path) {
113812
+ const base2 = apiUrl.endsWith("/") ? apiUrl.slice(0, -1) : apiUrl;
113813
+ const cleanPath = path.startsWith("/") ? path : `/${path}`;
113814
+ return base2 + cleanPath;
113815
+ }
113816
+ function isApiCrossOrigin() {
113817
+ try {
113818
+ return Boolean(
113819
+ apiUrl && new URL(apiUrl).origin !== window.location.origin
113807
113820
  );
113808
- if (!response.ok) {
113809
- throw new Error(`Failed to fetch scan: ${response.statusText}`);
113821
+ } catch (error2) {
113822
+ return false;
113823
+ }
113824
+ }
113825
+ const fetchType = async (method, path, request) => {
113826
+ const url = buildApiUrl(path);
113827
+ const responseHeaders = {
113828
+ Accept: "application/json",
113829
+ Pragma: "no-cache",
113830
+ Expires: "0",
113831
+ "Cache-Control": "no-cache",
113832
+ ...request?.headers
113833
+ };
113834
+ if (getHeaders) {
113835
+ const globalHeaders = await getHeaders();
113836
+ Object.assign(responseHeaders, globalHeaders);
113837
+ }
113838
+ if (request?.body) {
113839
+ responseHeaders["Content-Type"] = "application/json";
113840
+ }
113841
+ const response = await fetch(url, {
113842
+ method,
113843
+ headers: responseHeaders,
113844
+ body: request?.body,
113845
+ credentials: isApiCrossOrigin() ? "include" : "same-origin"
113846
+ });
113847
+ if (!response.ok) {
113848
+ const errorResponse = request?.handleError?.(response.status);
113849
+ if (errorResponse) {
113850
+ return {
113851
+ raw: response.statusText,
113852
+ parsed: errorResponse
113853
+ };
113810
113854
  }
113811
- const responsObj = await response.json();
113812
- return responsObj;
113855
+ const message2 = await response.text() || response.statusText;
113856
+ throw new ApiError(
113857
+ response.status,
113858
+ `API Error ${response.status}: ${message2}`
113859
+ );
113860
+ }
113861
+ const text2 = await response.text();
113862
+ const parse5 = request?.parse || asyncJsonParse;
113863
+ return {
113864
+ parsed: await parse5(text2),
113865
+ raw: text2
113866
+ };
113867
+ };
113868
+ const fetchString = async (method, path, headers, body) => {
113869
+ const url = buildApiUrl(path);
113870
+ const requestHeaders = {
113871
+ Accept: "application/json",
113872
+ Pragma: "no-cache",
113873
+ Expires: "0",
113874
+ "Cache-Control": "no-cache",
113875
+ ...headers
113876
+ };
113877
+ if (getHeaders) {
113878
+ const globalHeaders = await getHeaders();
113879
+ Object.assign(requestHeaders, globalHeaders);
113880
+ }
113881
+ if (body) {
113882
+ requestHeaders["Content-Type"] = "application/json";
113883
+ }
113884
+ const response = await fetch(url, {
113885
+ method,
113886
+ headers: requestHeaders,
113887
+ body,
113888
+ credentials: isApiCrossOrigin() ? "include" : "same-origin"
113889
+ });
113890
+ if (response.ok) {
113891
+ const text2 = await response.text();
113892
+ return {
113893
+ parsed: await asyncJsonParse(text2),
113894
+ raw: text2
113895
+ };
113896
+ }
113897
+ const message2 = await response.text() || response.statusText;
113898
+ throw new ApiError(response.status, `HTTP ${response.status}: ${message2}`);
113899
+ };
113900
+ const fetchBytes = async (method, path) => {
113901
+ const url = buildApiUrl(path);
113902
+ const headers = {
113903
+ Accept: "application/octet-stream",
113904
+ Pragma: "no-cache",
113905
+ Expires: "0",
113906
+ "Cache-Control": "no-cache"
113907
+ };
113908
+ if (getHeaders) {
113909
+ const globalHeaders = await getHeaders();
113910
+ Object.assign(headers, globalHeaders);
113911
+ }
113912
+ const response = await fetch(url, {
113913
+ method,
113914
+ headers,
113915
+ credentials: isApiCrossOrigin() ? "include" : "same-origin"
113916
+ });
113917
+ if (!response.ok) {
113918
+ const message2 = await response.text() || response.statusText;
113919
+ throw new ApiError(
113920
+ response.status,
113921
+ `HTTP ${response.status}: ${message2}`
113922
+ );
113923
+ }
113924
+ return await response.arrayBuffer();
113925
+ };
113926
+ return {
113927
+ fetchString,
113928
+ fetchBytes,
113929
+ fetchType
113930
+ };
113931
+ }
113932
+ const apiScoutServer = (options = {}) => {
113933
+ const { apiBaseUrl, headerProvider, resultsDir } = options;
113934
+ const requestApi = serverRequestApi(apiBaseUrl || "/api", headerProvider);
113935
+ return {
113936
+ getScan: async (scanLocation) => {
113937
+ return (await requestApi.fetchType(
113938
+ "GET",
113939
+ `/scan/${encodeURIComponent(scanLocation)}`
113940
+ )).parsed;
113813
113941
  },
113814
113942
  getScans: async () => {
113815
- const response = await fetch("/api/scans?status_only=true");
113816
- if (!response.ok) {
113817
- throw new Error(`Failed to fetch scans: ${response.statusText}`);
113943
+ let query2 = "/scans?status_only=true";
113944
+ if (resultsDir) {
113945
+ query2 += `&results_dir=${encodeURIComponent(resultsDir)}`;
113818
113946
  }
113819
- const responseObj = await response.json();
113820
- return responseObj;
113947
+ return (await requestApi.fetchType("GET", query2)).parsed;
113821
113948
  },
113822
113949
  getScannerDataframe: async (scanLocation, scanner) => {
113823
- const response = await fetch(
113824
- `/api/scanner_df/${encodeURIComponent(
113950
+ return await requestApi.fetchBytes(
113951
+ "GET",
113952
+ `/scanner_df/${encodeURIComponent(
113825
113953
  scanLocation
113826
113954
  )}?scanner=${encodeURIComponent(scanner)}`
113827
113955
  );
113828
- if (!response.ok) {
113829
- throw new Error(
113830
- `Failed to fetch scanner dataframe: ${response.statusText}`
113831
- );
113832
- }
113833
- const arrayBuffer = await response.arrayBuffer();
113834
- return arrayBuffer;
113835
113956
  },
113836
113957
  storage: NoPersistence
113837
113958
  };