backk-frontend-utils
Advanced tools
Comparing version 1.0.6 to 1.0.8
@@ -0,35 +1,46 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
import { Base64 } from 'js-base64'; | ||
import getJwtFromSessionStorage from './getJwtFromSessionStorage'; | ||
import { HTTPS_DEFAULT_PORT } from './constants/constants'; | ||
export default async function callRemoteService(microserviceName, serviceFunctionName, serviceFunctionArgument, microserviceNamespace, jwtStorageEncryptionKey, options) { | ||
export default function callRemoteService(microserviceName, serviceFunctionName, serviceFunctionArgument, microserviceNamespace, jwtStorageEncryptionKey, options) { | ||
var _a, _b, _c; | ||
const serverPort = window.location.search | ||
? (_a = window.location.search.split('serverPort=').pop()) !== null && _a !== void 0 ? _a : HTTPS_DEFAULT_PORT | ||
: HTTPS_DEFAULT_PORT; | ||
try { | ||
const response = await fetch(`https://${window.location.hostname}:${serverPort}/${microserviceName}.${microserviceNamespace}/${serviceFunctionName}`, { | ||
method: (_b = options === null || options === void 0 ? void 0 : options.httpMethod) !== null && _b !== void 0 ? _b : 'POST', | ||
body: serviceFunctionArgument ? JSON.stringify(serviceFunctionArgument) : undefined, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: 'Bearer ' + Base64.encode((_c = getJwtFromSessionStorage(jwtStorageEncryptionKey)) !== null && _c !== void 0 ? _c : ''), | ||
}, | ||
}); | ||
const responseBodyObject = await response.json(); | ||
if (response.ok) { | ||
return [responseBodyObject, null]; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const serverPort = window.location.search | ||
? (_a = window.location.search.split('serverPort=').pop()) !== null && _a !== void 0 ? _a : HTTPS_DEFAULT_PORT | ||
: HTTPS_DEFAULT_PORT; | ||
try { | ||
const response = yield fetch(`https://${window.location.hostname}:${serverPort}/${microserviceName}.${microserviceNamespace}/${serviceFunctionName}`, { | ||
method: (_b = options === null || options === void 0 ? void 0 : options.httpMethod) !== null && _b !== void 0 ? _b : 'POST', | ||
body: serviceFunctionArgument ? JSON.stringify(serviceFunctionArgument) : undefined, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: 'Bearer ' + Base64.encode((_c = getJwtFromSessionStorage(jwtStorageEncryptionKey)) !== null && _c !== void 0 ? _c : ''), | ||
}, | ||
}); | ||
const responseBodyObject = yield response.json(); | ||
if (response.ok) { | ||
return [responseBodyObject, null]; | ||
} | ||
else { | ||
return [null, responseBodyObject]; | ||
} | ||
} | ||
else { | ||
return [null, responseBodyObject]; | ||
catch (error) { | ||
return [ | ||
null, | ||
{ | ||
message: error.message, | ||
}, | ||
]; | ||
} | ||
} | ||
catch (error) { | ||
return [ | ||
null, | ||
{ | ||
message: error.message, | ||
}, | ||
]; | ||
} | ||
}); | ||
} | ||
//# sourceMappingURL=callRemoteService.js.map |
{ | ||
"name": "backk-frontend-utils", | ||
"version": "1.0.6", | ||
"version": "1.0.8", | ||
"description": "Web frontend utils for Backk microservices", | ||
@@ -5,0 +5,0 @@ "author": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
40588
293