@metrichor/epi2me-client-web
Advanced tools
Comparing version 0.1.10209158 to 0.1.10211367
@@ -11,3 +11,3 @@ import type { Dictionary } from 'ts-runtime-typecheck'; | ||
}; | ||
export type RestrictedFetch = (url: string, info?: RestrictedRequestInfo) => Promise<RestrictedResponse>; | ||
export type RestrictedFetch = (url: string, info: RestrictedRequestInfo) => Promise<RestrictedResponse>; | ||
//# sourceMappingURL=restricted_fetch.type.d.ts.map |
17
index.js
@@ -220,2 +220,15 @@ 'use strict'; | ||
async function session_jwt_common(fetcher, endpoint = DEFAULT_ENDPOINT) { | ||
const uri = new URL('validate', resolve_endpoint(endpoint)); | ||
const res = await fetcher(uri.toString(), { method: 'POST' }); | ||
if (!res.ok) { | ||
throw new Error(res.statusText); | ||
} | ||
const data = await res.json(); | ||
if (!data.valid || typeof data.jwt !== 'string') { | ||
throw new Error('Invalid credentials'); | ||
} | ||
return data.jwt; | ||
} | ||
const SIGNATURE_ALGO = { name: 'HMAC', hash: { name: 'SHA-1' } }; | ||
@@ -253,2 +266,5 @@ const TEXT_ENCODER = new TextEncoder(); | ||
} | ||
function session_jwt(options) { | ||
return session_jwt_common((uri, info) => authenticated_fetch(uri, info, options), options.endpoint); | ||
} | ||
@@ -279,1 +295,2 @@ Object.defineProperty(exports, 'ApolloError', { | ||
exports.resolve_endpoint = resolve_endpoint; | ||
exports.session_jwt = session_jwt; |
{ | ||
"name": "@metrichor/epi2me-client-web", | ||
"version": "0.1.10209158", | ||
"version": "0.1.10211367", | ||
"license": "MPL-2.0", | ||
@@ -5,0 +5,0 @@ "author": "Metrichor <support@nanoporetech.com>", |
@@ -9,2 +9,3 @@ import { ApolloClient } from '@apollo/client/core'; | ||
export declare function authenticated_fetch(info: RequestInfo, init: RequestInit, options: WebClientOptions): Promise<Response>; | ||
export declare function session_jwt(options: WebClientOptions): Promise<string>; | ||
export { parse_key } from './parse_key'; | ||
@@ -11,0 +12,0 @@ export * from '../common/index'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36429
42
632