@metrichor/epi2me-client-web
Advanced tools
Comparing version 0.1.10205535 to 0.1.10209158
import type { Dictionary } from 'ts-runtime-typecheck'; | ||
import type { ClientOptions } from './ClientOptions.type'; | ||
import type { RestrictedHeaderInit } from './restricted_fetch.type'; | ||
export declare function common_headers(client: ClientOptions['client'], source_headers?: HeadersInit): Dictionary<string>; | ||
export declare function normalise_headers(headers?: HeadersInit): Dictionary<string>; | ||
export declare function normalise_headers(headers?: RestrictedHeaderInit): Dictionary<string>; | ||
//# sourceMappingURL=common_headers.d.ts.map |
35
index.js
@@ -182,9 +182,2 @@ 'use strict'; | ||
const SIGNATURE_ALGO = { name: 'HMAC', hash: { name: 'SHA-1' } }; | ||
const TEXT_ENCODER = new TextEncoder(); | ||
function parse_key(secret) { | ||
const bytes = TEXT_ENCODER.encode(secret); | ||
return crypto.subtle.importKey('raw', bytes, SIGNATURE_ALGO, false, ['sign']); | ||
} | ||
function create_mock_client(client, on_request) { | ||
@@ -209,2 +202,28 @@ const mock_link = create_mock_http_link(on_request); | ||
async function register_profile_common(code, description, endpoint, fetcher) { | ||
const url = new URL('apiaccess', resolve_endpoint(endpoint)); | ||
const res = await fetcher(url.toString(), { | ||
method: 'POST', | ||
headers: { | ||
'content-type': 'application/json', | ||
}, | ||
body: JSON.stringify({ code, description }), | ||
}); | ||
if (!res.ok) { | ||
throw new Error(res.statusText); | ||
} | ||
const response = (await res.json()); | ||
if ('detail' in response) { | ||
throw new Error(`Invalid registration code: ${response.detail}.`); | ||
} | ||
return endpoint === DEFAULT_ENDPOINT ? response : { endpoint, ...response }; | ||
} | ||
const SIGNATURE_ALGO = { name: 'HMAC', hash: { name: 'SHA-1' } }; | ||
const TEXT_ENCODER = new TextEncoder(); | ||
function parse_key(secret) { | ||
const bytes = TEXT_ENCODER.encode(secret); | ||
return crypto.subtle.importKey('raw', bytes, SIGNATURE_ALGO, false, ['sign']); | ||
} | ||
function create_epi2me_client_jwt(options, on_error) { | ||
@@ -230,2 +249,3 @@ var _a; | ||
} | ||
const register_profile = (code, description, endpoint = DEFAULT_ENDPOINT) => register_profile_common(code, description, endpoint, fetch); | ||
async function authenticated_fetch(info, init, options) { | ||
@@ -258,2 +278,3 @@ const headers = await sign_message(init, options); | ||
exports.parse_key = parse_key; | ||
exports.register_profile = register_profile; | ||
exports.resolve_endpoint = resolve_endpoint; |
{ | ||
"name": "@metrichor/epi2me-client-web", | ||
"version": "0.1.10205535", | ||
"version": "0.1.10209158", | ||
"license": "MPL-2.0", | ||
@@ -5,0 +5,0 @@ "author": "Metrichor <support@nanoporetech.com>", |
@@ -7,2 +7,3 @@ import { ApolloClient } from '@apollo/client/core'; | ||
export declare function create_epi2me_client(options: WebClientOptions, on_error?: ErrorHandler): ApolloClient<unknown>; | ||
export declare const register_profile: (code: string, description: string, endpoint?: string) => Promise<import("../common/register_profile.type").CredentialsResponse>; | ||
export declare function authenticated_fetch(info: RequestInfo, init: RequestInit, options: WebClientOptions): Promise<Response>; | ||
@@ -9,0 +10,0 @@ export { parse_key } from './parse_key'; |
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
34641
40
598
4