New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@rh-support/api

Package Overview
Dependencies
Maintainers
6
Versions
191
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rh-support/api - npm Package Compare versions

Comparing version 0.1.42 to 0.2.0

2

lib/cjs/solutionEngine/product.js

@@ -23,4 +23,4 @@ "use strict";

fetch_1.addQueryParamsToUri(uri, params);
return fetch_1.getUri(uri, { signal: abortSignal }, __assign(__assign({}, fetch_1.defaultAdditionalOptions), { useCookieOnly: true }));
return fetch_1.getUri(uri, { signal: abortSignal }, __assign(__assign({}, fetch_1.defaultAdditionalOptions), { isUnAuthedCall: true }));
}
exports.getSEProductsList = getSEProductsList;

@@ -44,2 +44,3 @@ export interface IGetSessionParams {

isCep?: boolean;
clusterId?: string;
}

@@ -46,0 +47,0 @@ export interface ISessionItem {

export interface IAdditionalOptions {
dataType?: string;
externalUrl?: boolean;
isUnAuthedCall?: boolean;
useCookieOnly?: boolean;
}
/**
* - dataType
* This indicates the datatype of the response. Currently response handles handles dataType = 'text' scenario
* -----------
* - isUnAuthedCall
* use this param when you don't want to pass any kind of auth in your API call.
* -----------
* - useCookieOnly
* Hydra either needs auth token or cookies but cannnot accept both.
* Since credentials 'omit' of http fetch is not suppoorted by XHR that's used by the fetch polyfill on ie11,
* we can only pass auth via cookie.
*/
export declare const defaultAdditionalOptions: IAdditionalOptions;

@@ -18,3 +30,3 @@ declare global {

export declare function postFormUri<T>(uri: any, formData: FormData, extraParams?: RequestInit, additionalOptions?: IAdditionalOptions): Promise<T>;
export declare function putUri<T>(uri: any, body: any, extraParams?: RequestInit, additionalOptions?: IAdditionalOptions): Promise<T>;
export declare function putUri<T>(uri: any, body?: any, extraParams?: RequestInit, additionalOptions?: IAdditionalOptions): Promise<T>;
export declare function patchUri<T>(uri: any, body: any, extraParams?: RequestInit, additionalOptions?: IAdditionalOptions): Promise<T>;

@@ -21,0 +33,0 @@ export declare function deleteUri<T>(uri: any, extraParams?: RequestInit, additionalOptions?: IAdditionalOptions): Promise<T>;

@@ -67,12 +67,21 @@ "use strict";

var env_1 = __importDefault(require("./env"));
var isIE11 = ((!(window.ActiveXObject) && 'ActiveXObject' in window));
/**
* - dataType
* This indicates the datatype of the response. Currently response handles handles dataType = 'text' scenario
* -----------
* - isUnAuthedCall
* use this param when you don't want to pass any kind of auth in your API call.
* -----------
* - useCookieOnly
* Hydra either needs auth token or cookies but cannnot accept both.
* Since credentials 'omit' of http fetch is not suppoorted by XHR that's used by the fetch polyfill on ie11,
* we can only pass auth via cookie.
*/
exports.defaultAdditionalOptions = {
dataType: null,
externalUrl: false,
useCookieOnly: false
isUnAuthedCall: false,
useCookieOnly: isIE11
};
var baseParams = {
// adding this because according to MDN, fetch will set credentials to same-origin by default,
// which will let to inclusion of cookies into the request
// https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
credentials: 'omit',
headers: {

@@ -87,3 +96,10 @@ Accept: 'application/json'

// add false and 0 to query params
if (params[k] || params[k] === false || params[k] === 0 || (includeEmptyString && params[k] === '')) {
if (Array.isArray(params[k])) {
params[k] && params[k].forEach(function (item) {
if (item !== '') {
uri.addQueryParam(k, item);
}
});
}
else if (params[k] || params[k] === false || params[k] === 0 || (includeEmptyString && params[k] === '')) {
uri.addQueryParam(k, params[k]);

@@ -103,3 +119,4 @@ }

// https://medium.com/@pashozator/logging-api-errors-to-sentry-grouping-and-passing-additional-data-6f9d4ef91a9b
window.sessionjs.reportProblem(error, {
var session = getKeycloakSession();
session && session.reportProblem && session.reportProblem(error, {
tags: {

@@ -111,5 +128,3 @@ portal_app: window.app || '@rh-support/api'

});
// sendToSentry(error, {error: getErrorMessageForSentry(response.url, response.status)});
}
return;
};

@@ -146,5 +161,4 @@ function errorHandler(response) {

}
function getIsTokenExpired() {
// For portal sessionjs we use the below line because in sessionjs we don't get the isTokenExpired() function directly
return get_1.default(window, 'portal.session._state.keycloak.isTokenExpired');
function getKeycloakSession() {
return get_1.default(window, 'portal.session') || get_1.default(window, 'sessionjs');
}

@@ -156,7 +170,7 @@ // If the token is expiring within 30 seconds, go ahead and refresh it. Using 30 seconds considering jwt.js checks if

if (duration === void 0) { duration = 30; }
var _isTokenExpired = getIsTokenExpired();
return _isTokenExpired && _isTokenExpired(duration);
var isTokenExpired = get_1.default(getKeycloakSession(), '_state.keycloak.isTokenExpired');
return isTokenExpired && isTokenExpired(duration);
}
function forceTokenRefresh() {
var session = get_1.default(window, 'portal.session') || get_1.default(window, 'sessionjs');
var session = getKeycloakSession();
if (!session) {

@@ -188,13 +202,17 @@ return;

function getToken() {
var token = get_1.default(window, 'portal.session._state.keycloak.token');
return token ? "Bearer " + token : null;
var session = getKeycloakSession();
var token = get_1.default(session, '_state.keycloak.token');
var isAuthenticated = get_1.default(session, 'isAuthenticated');
return token && isAuthenticated() ? "Bearer " + token : null;
}
function responseHandler(response, dataType) {
function responseHandler(response, additionalOptions) {
try {
if (response.ok) {
var contentType = response.headers.get('content-type');
if (dataType !== 'text' && contentType && includes_1.default(contentType, 'json')) {
return response.json().then(function (j) { return Promise.resolve(j); }).catch(function (e) { return Promise.resolve({}); });
if (additionalOptions.dataType !== 'text' && contentType && includes_1.default(contentType, 'json')) {
return response.json()
.then(function (j) { return Promise.resolve(j); })
.catch(function (e) { return Promise.resolve({}); });
}
else if (dataType === 'text' || (contentType && includes_1.default(contentType, 'text'))) {
else if (additionalOptions.dataType === 'text' || (contentType && includes_1.default(contentType, 'text'))) {
return response.text();

@@ -205,3 +223,5 @@ }

// https://github.com/github/fetch/issues/268#issuecomment-176544728
return response.text().then(function (j) { return Promise.resolve(j ? JSON.parse(j) : {}); }).catch(function (e) { return Promise.resolve({}); });
return response.text()
.then(function (j) { return Promise.resolve(j ? JSON.parse(j) : {}); })
.catch(function (e) { return Promise.resolve({}); });
}

@@ -233,3 +253,3 @@ }

}
function fetchURIWithParams(uri, params, dataType) {
function fetchURIWithParams(uri, params, additionalOptions) {
return __awaiter(this, void 0, void 0, function () {

@@ -244,3 +264,3 @@ var response, error_1;

response = _a.sent();
return [2 /*return*/, responseHandler(response, dataType)];
return [2 /*return*/, responseHandler(response, additionalOptions)];
case 2:

@@ -257,31 +277,36 @@ error_1 = _a.sent();

return __awaiter(this, void 0, void 0, function () {
var isIE11;
var error_2;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
isIE11 = ((!(window.ActiveXObject) && 'ActiveXObject' in window));
if (!(isTokenAboutToExpire() && !additionalOptions.externalUrl && !env_1.default.auth)) return [3 /*break*/, 2];
if (!!additionalOptions.isUnAuthedCall) return [3 /*break*/, 5];
if (!(!env_1.default.auth && isTokenAboutToExpire())) return [3 /*break*/, 4];
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, forceTokenRefresh()];
case 1:
case 2:
_a.sent();
_a.label = 2;
case 2:
if (!additionalOptions.externalUrl) {
if (env_1.default.auth) {
params.headers['Authorization'] = env_1.default.auth;
// Added ActiveXObject check for detecting IE11 and setting authorization only in browsers other than IE11
}
else if (!isIE11 && getToken() && !additionalOptions.useCookieOnly) {
params.headers['Authorization'] = getToken();
}
else {
// In IE servers give cached responses thus adding cache burst param
isIE11 && uri.addQueryParam('cache-burst-param', new Date().getTime());
// tslint:disable-next-line:no-console
console.info("Didn't add Auth headers " + (isIE11 ?
'in IE11 browser' : additionalOptions.useCookieOnly ?
'explicitly mentioned to use cookie' : 'as token was missing') + ", relying on auth cookie being passed");
}
return [3 /*break*/, 4];
case 3:
error_2 = _a.sent();
console.error(error_2);
return [3 /*break*/, 4];
case 4:
if (env_1.default.auth) {
params.headers['Authorization'] = env_1.default.auth;
}
return [2 /*return*/, fetchURIWithParams(uri, params, additionalOptions.dataType)];
else if (!additionalOptions.useCookieOnly && getToken()) {
params.headers['Authorization'] = getToken();
}
else {
// In IE servers give cached responses thus adding cache burst param
isIE11 && uri.addQueryParam('cache-burst-param', new Date().getTime());
// tslint:disable-next-line:no-console
console.info("Didn't add Auth headers " + (isIE11 ?
'in IE11 browser' : additionalOptions.useCookieOnly ?
'because explicitly mentioned to use cookie' : 'as token was missing') + ", relying on auth cookie being passed");
}
_a.label = 5;
case 5: return [2 /*return*/, fetchURIWithParams(uri, params, additionalOptions)];
}

@@ -291,6 +316,10 @@ });

}
function getRequestCredentialsForOptions(additionalOptions) {
return additionalOptions.isUnAuthedCall || !additionalOptions.useCookieOnly ? 'omit' : 'include';
}
function getUri(uri, extraParams, additionalOptions) {
if (additionalOptions === void 0) { additionalOptions = exports.defaultAdditionalOptions; }
var params = {
method: 'GET'
method: 'GET',
credentials: getRequestCredentialsForOptions(additionalOptions)
};

@@ -306,2 +335,3 @@ mergeRequestOptions(params, baseParams);

method: 'GET',
credentials: getRequestCredentialsForOptions(additionalOptions),
headers: {

@@ -321,2 +351,3 @@ 'Content-Type': 'application/json'

method: 'POST',
credentials: getRequestCredentialsForOptions(additionalOptions),
headers: {

@@ -337,2 +368,3 @@ 'Content-Type': 'application/json',

method: 'POST',
credentials: getRequestCredentialsForOptions(additionalOptions),
headers: {

@@ -355,2 +387,3 @@ // Default enctype of html form element

method: 'PUT',
credentials: getRequestCredentialsForOptions(additionalOptions),
headers: {

@@ -370,2 +403,3 @@ 'Content-Type': 'application/json'

method: 'PATCH',
credentials: getRequestCredentialsForOptions(additionalOptions),
headers: {

@@ -385,2 +419,3 @@ 'Content-Type': 'application/json'

method: 'DELETE',
credentials: getRequestCredentialsForOptions(additionalOptions)
};

@@ -396,2 +431,3 @@ mergeRequestOptions(params, baseParams);

method: 'DELETE',
credentials: getRequestCredentialsForOptions(additionalOptions),
headers: {

@@ -398,0 +434,0 @@ 'Content-Type': 'application/json'

@@ -6,3 +6,3 @@ import Env from '../utils/env';

addQueryParamsToUri(uri, params);
return getUri(uri, { signal: abortSignal }, Object.assign(Object.assign({}, defaultAdditionalOptions), { useCookieOnly: true }));
return getUri(uri, { signal: abortSignal }, Object.assign(Object.assign({}, defaultAdditionalOptions), { isUnAuthedCall: true }));
}

@@ -44,2 +44,3 @@ export interface IGetSessionParams {

isCep?: boolean;
clusterId?: string;
}

@@ -46,0 +47,0 @@ export interface ISessionItem {

export interface IAdditionalOptions {
dataType?: string;
externalUrl?: boolean;
isUnAuthedCall?: boolean;
useCookieOnly?: boolean;
}
/**
* - dataType
* This indicates the datatype of the response. Currently response handles handles dataType = 'text' scenario
* -----------
* - isUnAuthedCall
* use this param when you don't want to pass any kind of auth in your API call.
* -----------
* - useCookieOnly
* Hydra either needs auth token or cookies but cannnot accept both.
* Since credentials 'omit' of http fetch is not suppoorted by XHR that's used by the fetch polyfill on ie11,
* we can only pass auth via cookie.
*/
export declare const defaultAdditionalOptions: IAdditionalOptions;

@@ -18,3 +30,3 @@ declare global {

export declare function postFormUri<T>(uri: any, formData: FormData, extraParams?: RequestInit, additionalOptions?: IAdditionalOptions): Promise<T>;
export declare function putUri<T>(uri: any, body: any, extraParams?: RequestInit, additionalOptions?: IAdditionalOptions): Promise<T>;
export declare function putUri<T>(uri: any, body?: any, extraParams?: RequestInit, additionalOptions?: IAdditionalOptions): Promise<T>;
export declare function patchUri<T>(uri: any, body: any, extraParams?: RequestInit, additionalOptions?: IAdditionalOptions): Promise<T>;

@@ -21,0 +33,0 @@ export declare function deleteUri<T>(uri: any, extraParams?: RequestInit, additionalOptions?: IAdditionalOptions): Promise<T>;

@@ -24,12 +24,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

import Env from './env';
const isIE11 = ((!(window.ActiveXObject) && 'ActiveXObject' in window));
/**
* - dataType
* This indicates the datatype of the response. Currently response handles handles dataType = 'text' scenario
* -----------
* - isUnAuthedCall
* use this param when you don't want to pass any kind of auth in your API call.
* -----------
* - useCookieOnly
* Hydra either needs auth token or cookies but cannnot accept both.
* Since credentials 'omit' of http fetch is not suppoorted by XHR that's used by the fetch polyfill on ie11,
* we can only pass auth via cookie.
*/
export const defaultAdditionalOptions = {
dataType: null,
externalUrl: false,
useCookieOnly: false
isUnAuthedCall: false,
useCookieOnly: isIE11
};
const baseParams = {
// adding this because according to MDN, fetch will set credentials to same-origin by default,
// which will let to inclusion of cookies into the request
// https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
credentials: 'omit',
headers: {

@@ -43,3 +52,10 @@ Accept: 'application/json'

// add false and 0 to query params
if (params[k] || params[k] === false || params[k] === 0 || (includeEmptyString && params[k] === '')) {
if (Array.isArray(params[k])) {
params[k] && params[k].forEach((item) => {
if (item !== '') {
uri.addQueryParam(k, item);
}
});
}
else if (params[k] || params[k] === false || params[k] === 0 || (includeEmptyString && params[k] === '')) {
uri.addQueryParam(k, params[k]);

@@ -58,3 +74,4 @@ }

// https://medium.com/@pashozator/logging-api-errors-to-sentry-grouping-and-passing-additional-data-6f9d4ef91a9b
window.sessionjs.reportProblem(error, {
const session = getKeycloakSession();
session && session.reportProblem && session.reportProblem(error, {
tags: {

@@ -66,5 +83,3 @@ portal_app: window.app || '@rh-support/api'

});
// sendToSentry(error, {error: getErrorMessageForSentry(response.url, response.status)});
}
return;
};

@@ -101,5 +116,4 @@ function errorHandler(response) {

}
function getIsTokenExpired() {
// For portal sessionjs we use the below line because in sessionjs we don't get the isTokenExpired() function directly
return get(window, 'portal.session._state.keycloak.isTokenExpired');
function getKeycloakSession() {
return get(window, 'portal.session') || get(window, 'sessionjs');
}

@@ -110,7 +124,7 @@ // If the token is expiring within 30 seconds, go ahead and refresh it. Using 30 seconds considering jwt.js checks if

function isTokenAboutToExpire(duration = 30) {
const _isTokenExpired = getIsTokenExpired();
return _isTokenExpired && _isTokenExpired(duration);
const isTokenExpired = get(getKeycloakSession(), '_state.keycloak.isTokenExpired');
return isTokenExpired && isTokenExpired(duration);
}
function forceTokenRefresh() {
const session = get(window, 'portal.session') || get(window, 'sessionjs');
const session = getKeycloakSession();
if (!session) {

@@ -142,13 +156,17 @@ return;

function getToken() {
const token = get(window, 'portal.session._state.keycloak.token');
return token ? `Bearer ${token}` : null;
const session = getKeycloakSession();
const token = get(session, '_state.keycloak.token');
const isAuthenticated = get(session, 'isAuthenticated');
return token && isAuthenticated() ? `Bearer ${token}` : null;
}
function responseHandler(response, dataType) {
function responseHandler(response, additionalOptions) {
try {
if (response.ok) {
const contentType = response.headers.get('content-type');
if (dataType !== 'text' && contentType && includes(contentType, 'json')) {
return response.json().then(j => Promise.resolve(j)).catch(e => Promise.resolve({}));
if (additionalOptions.dataType !== 'text' && contentType && includes(contentType, 'json')) {
return response.json()
.then(j => Promise.resolve(j))
.catch(e => Promise.resolve({}));
}
else if (dataType === 'text' || (contentType && includes(contentType, 'text'))) {
else if (additionalOptions.dataType === 'text' || (contentType && includes(contentType, 'text'))) {
return response.text();

@@ -159,3 +177,5 @@ }

// https://github.com/github/fetch/issues/268#issuecomment-176544728
return response.text().then(j => Promise.resolve(j ? JSON.parse(j) : {})).catch(e => Promise.resolve({}));
return response.text()
.then(j => Promise.resolve(j ? JSON.parse(j) : {}))
.catch(e => Promise.resolve({}));
}

@@ -187,7 +207,7 @@ }

}
function fetchURIWithParams(uri, params, dataType) {
function fetchURIWithParams(uri, params, additionalOptions) {
return __awaiter(this, void 0, void 0, function* () {
try {
const response = yield fetch(uri.toString(), params);
return responseHandler(response, dataType);
return responseHandler(response, additionalOptions);
}

@@ -202,12 +222,15 @@ catch (error) {

return __awaiter(this, void 0, void 0, function* () {
const isIE11 = ((!(window.ActiveXObject) && 'ActiveXObject' in window));
if (isTokenAboutToExpire() && !additionalOptions.externalUrl && !Env.auth) {
yield forceTokenRefresh();
}
if (!additionalOptions.externalUrl) {
if (!additionalOptions.isUnAuthedCall) {
if (!Env.auth && isTokenAboutToExpire()) {
try {
yield forceTokenRefresh();
}
catch (error) {
console.error(error);
}
}
if (Env.auth) {
params.headers['Authorization'] = Env.auth;
// Added ActiveXObject check for detecting IE11 and setting authorization only in browsers other than IE11
}
else if (!isIE11 && getToken() && !additionalOptions.useCookieOnly) {
else if (!additionalOptions.useCookieOnly && getToken()) {
params.headers['Authorization'] = getToken();

@@ -221,11 +244,15 @@ }

'in IE11 browser' : additionalOptions.useCookieOnly ?
'explicitly mentioned to use cookie' : 'as token was missing'}, relying on auth cookie being passed`);
'because explicitly mentioned to use cookie' : 'as token was missing'}, relying on auth cookie being passed`);
}
}
return fetchURIWithParams(uri, params, additionalOptions.dataType);
return fetchURIWithParams(uri, params, additionalOptions);
});
}
function getRequestCredentialsForOptions(additionalOptions) {
return additionalOptions.isUnAuthedCall || !additionalOptions.useCookieOnly ? 'omit' : 'include';
}
export function getUri(uri, extraParams, additionalOptions = defaultAdditionalOptions) {
const params = {
method: 'GET'
method: 'GET',
credentials: getRequestCredentialsForOptions(additionalOptions)
};

@@ -239,2 +266,3 @@ mergeRequestOptions(params, baseParams);

method: 'GET',
credentials: getRequestCredentialsForOptions(additionalOptions),
headers: {

@@ -252,2 +280,3 @@ 'Content-Type': 'application/json'

method: 'POST',
credentials: getRequestCredentialsForOptions(additionalOptions),
headers: {

@@ -266,2 +295,3 @@ 'Content-Type': 'application/json',

method: 'POST',
credentials: getRequestCredentialsForOptions(additionalOptions),
headers: {

@@ -282,2 +312,3 @@ // Default enctype of html form element

method: 'PUT',
credentials: getRequestCredentialsForOptions(additionalOptions),
headers: {

@@ -295,2 +326,3 @@ 'Content-Type': 'application/json'

method: 'PATCH',
credentials: getRequestCredentialsForOptions(additionalOptions),
headers: {

@@ -308,2 +340,3 @@ 'Content-Type': 'application/json'

method: 'DELETE',
credentials: getRequestCredentialsForOptions(additionalOptions)
};

@@ -317,2 +350,3 @@ mergeRequestOptions(params, baseParams);

method: 'DELETE',
credentials: getRequestCredentialsForOptions(additionalOptions),
headers: {

@@ -319,0 +353,0 @@ 'Content-Type': 'application/json'

{
"name": "@rh-support/api",
"version": "0.1.42",
"version": "0.2.0",
"description": "Contains all the backend API calls",

@@ -43,3 +43,3 @@ "author": "Vikas Rathee <vrathee@redhat.com>",

"peerDependencies": {
"hydrajs": "git+https://gitlab.cee.redhat.com/redhataccess/hydrajs.git#2.1.85"
"hydrajs": "git+https://gitlab.cee.redhat.com/redhataccess/hydrajs.git#3.0.0"
},

@@ -49,7 +49,7 @@ "dependencies": {

"btoa-lite": "^1.0.0",
"hydrajs": "git+https://gitlab.cee.redhat.com/redhataccess/hydrajs.git#2.1.85",
"hydrajs": "git+https://gitlab.cee.redhat.com/redhataccess/hydrajs.git#3.0.0",
"jsuri": "^1.3.1",
"lodash": "^4.17.15"
},
"gitHead": "a38bc9522897c66e538cc1b9dba8fe93856a90f3"
"gitHead": "59148fbcded7fb13348e4fc18143eeb36a0c6cf7"
}

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

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