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

@equinor/fusion

Package Overview
Dependencies
Maintainers
2
Versions
485
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@equinor/fusion - npm Package Compare versions

Comparing version 0.1.42 to 0.1.43

2

lib/http/apiClients/FusionClient.js

@@ -18,4 +18,4 @@ import BaseApiClient from "./BaseApiClient";

const url = this.resourceCollections.fusion.appIcon(appKey);
return await this.httpClient.getAsync(url);
return await this.httpClient.getStringAsync(url);
}
}

@@ -5,3 +5,3 @@ export declare type HttpResponse<T> = {

status: number;
refreshPromise: Promise<HttpResponse<T>> | null;
refreshPromise?: Promise<HttpResponse<T>> | null;
};

@@ -9,2 +9,3 @@ import { HttpResponse } from "./HttpResponse";

getAsync<T, TExpectedErrorResponse>(url: string, init?: RequestInit): Promise<HttpResponse<T>>;
getStringAsync<TExpectedErrorResponse>(url: string, init?: RequestInit): Promise<HttpResponse<string>>;
/**

@@ -11,0 +12,0 @@ * Perform a POST request

@@ -16,2 +16,3 @@ import { IAuthContainer } from "../../auth/AuthContainer";

getAsync<T, TExpectedErrorResponse>(url: string, init?: RequestInit): Promise<HttpResponse<T>>;
getStringAsync<TExpectedErrorResponse>(url: string, init?: RequestInit): Promise<HttpResponse<string>>;
postAsync<TBody, TResponse, TExpectedErrorResponse>(url: string, body: TBody, init?: RequestInit): Promise<HttpResponse<TResponse>>;

@@ -27,2 +28,4 @@ putAsync<TBody, TResponse, TExpectedErrorResponse>(url: string, body: TBody, init?: RequestInit): Promise<HttpResponse<TResponse>>;

private transformRequestAsync;
private parseResponseJSONAsync;
private parseResponseStringAsync;
private parseResponseAsync;

@@ -29,0 +32,0 @@ private responseIsRefreshable;

@@ -16,2 +16,11 @@ import uuid from "uuid/v1";

async getAsync(url, init) {
const result = await this.getStringAsync(url, init);
const data = JSON.parse(result.data);
return {
data,
headers: result.headers,
status: result.status,
};
}
async getStringAsync(url, init) {
// Reuse GET requests in progress

@@ -26,7 +35,15 @@ const requestInProgress = this.getRequestInProgress(url);

const request = this.performFetchAsync(url, init);
this.requestsInProgress[url] = request;
const response = await request;
delete this.requestsInProgress[url];
await this.resourceCache.updateAsync(url, response);
return response;
this.requestsInProgress[url] = new Promise(async (resolve, reject) => {
try {
const response = await request;
const data = await this.parseResponseStringAsync(response);
delete this.requestsInProgress[url];
await this.resourceCache.updateAsync(url, data);
resolve(data);
}
catch (e) {
reject(e);
}
});
return await this.requestsInProgress[url];
}

@@ -40,7 +57,9 @@ catch (error) {

init = ensureRequestInit(init, init => (Object.assign({}, init, { method: "POST", body: JSON.stringify(body) })));
return await this.performFetchAsync(url, init);
const response = await this.performFetchAsync(url, init);
return await this.parseResponseAsync(response);
}
async putAsync(url, body, init) {
init = ensureRequestInit(init, init => (Object.assign({}, init, { method: "PUT", body: JSON.stringify(body) })));
return await this.performFetchAsync(url, init);
const response = await this.performFetchAsync(url, init);
return await this.parseResponseAsync(response);
}

@@ -82,3 +101,3 @@ transformHeaders(init, transform) {

}
async parseResponseAsync(response) {
async parseResponseJSONAsync(response) {
try {

@@ -93,2 +112,20 @@ const json = await response.json();

}
async parseResponseStringAsync(response) {
const data = await response.text();
// TODO: Update cache status?
return {
data,
status: response.status,
headers: response.headers,
};
}
async parseResponseAsync(response) {
const data = await this.parseResponseJSONAsync(response);
// TODO: Update cache status?
return {
data,
status: response.status,
headers: response.headers,
};
}
responseIsRefreshable(response) {

@@ -104,18 +141,6 @@ return response.headers.get("x-pp-is-refreshable") !== null;

// Add more info
const errorResponse = await this.parseResponseAsync(response);
const errorResponse = await this.parseResponseJSONAsync(response);
throw new HttpClientRequestFailedError(url, response.status, errorResponse);
}
const data = await this.parseResponseAsync(response);
let refreshPromise = null;
if (this.responseIsRefreshable(response)) {
const refreshOptions = this.addRefreshHeader(options);
refreshPromise = this.performFetchAsync(url, refreshOptions);
}
// TODO: Update cache status?
return {
data,
status: response.status,
headers: response.headers,
refreshPromise,
};
return response;
}

@@ -122,0 +147,0 @@ catch (error) {

{
"name": "@equinor/fusion",
"version": "0.1.42",
"version": "0.1.43",
"description": "Everything a Fusion app needs to communicate with the core",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

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