Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@equinor/fusion-framework-module-http

Package Overview
Dependencies
Maintainers
3
Versions
126
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@equinor/fusion-framework-module-http - npm Package Compare versions

Comparing version 0.1.0-beta.0 to 0.1.0-beta.1

19

dist/esm/provider.js

@@ -6,2 +6,11 @@ export class ClientNotFoundException extends Error {

}
const isURL = (url) => {
const pattern = new RegExp('^(https?:\\/\\/)?' +
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.?)+[a-z]{2,}|' +
'((\\d{1,3}\\.){3}\\d{1,3}))' +
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' +
'(\\?[;&a-z\\d%_.~+=-]*)?' +
'(\\#[-a-z\\d_]*)?$', 'i');
return pattern.test(url);
};
export class HttpClientProvider {

@@ -16,8 +25,12 @@ config;

createClient(key) {
if (!this.hasClient(key)) {
let config = this.config.clients[key];
if (!config && isURL(key)) {
config = { baseUri: key };
}
else {
throw new ClientNotFoundException(`No registered http client for key [${key}]`);
}
const { defaultUri, onCreate, ctor = this.config.defaultHttpClientCtor, requestHandler = this.config.defaultHttpRequestHandler, } = this.config.clients[key];
const { baseUri, onCreate, ctor = this.config.defaultHttpClientCtor, requestHandler = this.config.defaultHttpRequestHandler, } = config;
const options = { requestHandler };
const instance = new ctor(defaultUri || '', options);
const instance = new ctor(baseUri || '', options);
onCreate && onCreate(instance);

@@ -24,0 +37,0 @@ return instance;

2

dist/types/configurator.d.ts

@@ -9,3 +9,3 @@ import { HttpRequestHandler, HttpRequestInit, IHttpClient } from './client';

interface HttpClientOptions<TClient extends IHttpClient> {
defaultUri?: string;
baseUri?: string;
ctor?: HttpClientConstructor<TClient>;

@@ -12,0 +12,0 @@ onCreate?: (client: TClient) => void;

{
"name": "@equinor/fusion-framework-module-http",
"version": "0.1.0-beta.0",
"version": "0.1.0-beta.1",
"description": "",

@@ -24,3 +24,3 @@ "main": "./dist/esm/index.js",

"dependencies": {
"@equinor/fusion-framework-module": "^0.1.0-beta.0"
"@equinor/fusion-framework-module": "^0.1.0-beta.1"
},

@@ -35,3 +35,3 @@ "types": "index.d.ts",

},
"gitHead": "6fcf14ad456aad818c9e8b3a575b14e2b23ca6b7"
"gitHead": "e1d4d80409b59433fbd00703254e13032ada8680"
}

@@ -15,3 +15,3 @@ import { HttpRequestHandler, HttpRequestInit, IHttpClient } from './client';

interface HttpClientOptions<TClient extends IHttpClient> {
defaultUri?: string;
baseUri?: string;
ctor?: HttpClientConstructor<TClient>;

@@ -18,0 +18,0 @@ onCreate?: (client: TClient) => void;

@@ -27,2 +27,15 @@ import { HttpClient } from './client';

const isURL = (url: string) => {
const pattern = new RegExp(
'^(https?:\\/\\/)?' + // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.?)+[a-z]{2,}|' + // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
'(\\#[-a-z\\d_]*)?$',
'i'
); // fragment locator
return pattern.test(url);
};
export class HttpClientProvider<TClient extends HttpClient>

@@ -38,13 +51,16 @@ implements IHttpClientProvider<TClient>

public createClient(key: string): TClient {
if (!this.hasClient(key)) {
let config = this.config.clients[key];
if (!config && isURL(key)) {
config = { baseUri: key };
} else {
throw new ClientNotFoundException(`No registered http client for key [${key}]`);
}
const {
defaultUri,
baseUri,
onCreate,
ctor = this.config.defaultHttpClientCtor,
requestHandler = this.config.defaultHttpRequestHandler,
} = this.config.clients[key];
} = config;
const options = { requestHandler };
const instance = new ctor(defaultUri || '', options) as TClient;
const instance = new ctor(baseUri || '', options) as TClient;
onCreate && onCreate(instance as TClient);

@@ -51,0 +67,0 @@ return instance as TClient;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc