@workerbase/sdk
Advanced tools
Comparing version 0.1.15-beta.16 to 0.1.15-beta.17
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -38,4 +49,20 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.doRequest = void 0; | ||
var axios_1 = __importDefault(require("axios")); | ||
var parseurl_1 = __importDefault(require("parseurl")); | ||
var apiVersion = 'v1'; | ||
@@ -46,22 +73,75 @@ exports.doRequest = function (api, endpoint, options, internalHostname) { | ||
return __awaiter(void 0, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, { | ||
data: {}, | ||
// `status` is the HTTP status code from the server response | ||
status: 200, | ||
// `statusText` is the HTTP status message from the server response | ||
// As of HTTP/2 status text is blank or unsupported. | ||
// (HTTP/2 RFC: https://www.rfc-editor.org/rfc/rfc7540#section-8.1.2.4) | ||
statusText: 'OK', | ||
// `headers` the HTTP headers that the server responded with | ||
// All header names are lower cased and can be accessed using the bracket notation. | ||
// Example: `response.headers['content-type']` | ||
headers: {}, | ||
// `config` is the config that was provided to `axios` for the request | ||
config: {}, | ||
// `request` is the request that generated this response | ||
// It is the last ClientRequest instance in node.js (in redirects) | ||
// and an XMLHttpRequest instance in the browser | ||
request: {}, | ||
}]; | ||
var baseUrl, url, response, err_1, errorMessage, errorToThrow, _a, tmpVar1, tmpVar2, otherErrorData; | ||
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8; | ||
return __generator(this, function (_9) { | ||
switch (_9.label) { | ||
case 0: | ||
if (!api.url) { | ||
throw new Error('No WB_API_URL in environment or option found'); | ||
} | ||
if (!api.accesstoken) { | ||
throw new Error('No WB_ACCESS_TOKEN in environment or option found'); | ||
} | ||
if (process.env.DEBUG) { | ||
console.log({ | ||
WB_ENABLE_INTERNAL_ROUTING: process.env.WB_ENABLE_INTERNAL_ROUTING, | ||
internalHostname: internalHostname, | ||
}); | ||
} | ||
if (process.env.WB_ENABLE_INTERNAL_ROUTING && internalHostname) { | ||
// eslint-disable-next-line no-param-reassign | ||
api.url = "http://" + internalHostname + ":3000/"; | ||
} | ||
baseUrl = parseurl_1.default({ url: api.url }).href; | ||
url = endpoint === 'graphql' | ||
? baseUrl + "graphql" | ||
: baseUrl + "api/" + apiVersion + "/" + endpoint; | ||
_9.label = 1; | ||
case 1: | ||
_9.trys.push([1, 3, , 4]); | ||
if (process.env.DEBUG) { | ||
console.log(__assign({ url: url, headers: __assign({ accesstoken: api.accesstoken, 'User-Agent': "workerbase-sdk (" + api.version + ")", 'Content-Type': 'application/json' }, options.headers), method: 'GET' }, options)); | ||
} | ||
return [4 /*yield*/, axios_1.default(__assign({ url: url, headers: __assign({ accesstoken: api.accesstoken, 'User-Agent': "workerbase-sdk (" + api.version + ")", 'Content-Type': 'application/json' }, options.headers), method: 'GET' }, options))]; | ||
case 2: | ||
response = _9.sent(); | ||
return [2 /*return*/, response]; | ||
case 3: | ||
err_1 = _9.sent(); | ||
errorMessage = err_1.message; | ||
if (((_c = (_b = err_1.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.errorMessage) === 'HTTP Trigger failed' && ((_g = (_f = (_e = (_d = err_1.response) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.error) === null || _f === void 0 ? void 0 : _f.additionalData) === null || _g === void 0 ? void 0 : _g.errors)) { | ||
errorMessage = (_l = (_k = (_j = (_h = err_1.response) === null || _h === void 0 ? void 0 : _h.data) === null || _j === void 0 ? void 0 : _j.error) === null || _k === void 0 ? void 0 : _k.additionalData) === null || _l === void 0 ? void 0 : _l.errors.map(function (ruleError) { | ||
var _a, _b; | ||
var ruleErrorReason = ((_a = ruleError === null || ruleError === void 0 ? void 0 : ruleError.err) === null || _a === void 0 ? void 0 : _a.message) ? ": " + ((_b = ruleError === null || ruleError === void 0 ? void 0 : ruleError.err) === null || _b === void 0 ? void 0 : _b.message) : ""; | ||
var message = "Connector triggering RuleId " + ruleError.ruleId + " failed " + ruleErrorReason; | ||
return message.trim(); | ||
}).join(", "); | ||
} | ||
else if (((_o = (_m = err_1.response) === null || _m === void 0 ? void 0 : _m.data) === null || _o === void 0 ? void 0 : _o.errorMessage) && | ||
typeof ((_q = (_p = err_1.response) === null || _p === void 0 ? void 0 : _p.data) === null || _q === void 0 ? void 0 : _q.errorMessage) === 'string') { | ||
errorMessage = (_s = (_r = err_1.response) === null || _r === void 0 ? void 0 : _r.data) === null || _s === void 0 ? void 0 : _s.errorMessage; | ||
} | ||
else if (((_u = (_t = err_1.response) === null || _t === void 0 ? void 0 : _t.data) === null || _u === void 0 ? void 0 : _u.errorMessage) && | ||
typeof ((_w = (_v = err_1.response) === null || _v === void 0 ? void 0 : _v.data) === null || _w === void 0 ? void 0 : _w.errorMessage) === 'object') { | ||
errorMessage = JSON.stringify((_y = (_x = err_1.response) === null || _x === void 0 ? void 0 : _x.data) === null || _y === void 0 ? void 0 : _y.errorMessage); | ||
} | ||
else if ((_z = err_1.response) === null || _z === void 0 ? void 0 : _z.data) { | ||
errorMessage = JSON.stringify((_0 = err_1.response) === null || _0 === void 0 ? void 0 : _0.data); | ||
} | ||
errorToThrow = new Error(errorMessage); | ||
Object.assign(errorToThrow, { | ||
requestUrl: ((_2 = (_1 = err_1 === null || err_1 === void 0 ? void 0 : err_1.request) === null || _1 === void 0 ? void 0 : _1.res) === null || _2 === void 0 ? void 0 : _2.responseUrl) || url, | ||
requestMethod: (_3 = err_1 === null || err_1 === void 0 ? void 0 : err_1.request) === null || _3 === void 0 ? void 0 : _3.method, | ||
requestData: (_4 = err_1 === null || err_1 === void 0 ? void 0 : err_1.config) === null || _4 === void 0 ? void 0 : _4.data, | ||
requestParams: (_5 = err_1 === null || err_1 === void 0 ? void 0 : err_1.config) === null || _5 === void 0 ? void 0 : _5.params, | ||
responseStatusCode: (_6 = err_1 === null || err_1 === void 0 ? void 0 : err_1.response) === null || _6 === void 0 ? void 0 : _6.status, | ||
responseData: (_7 = err_1 === null || err_1 === void 0 ? void 0 : err_1.response) === null || _7 === void 0 ? void 0 : _7.data, | ||
}); | ||
if ((_8 = err_1.response) === null || _8 === void 0 ? void 0 : _8.data) { | ||
_a = err_1.response.data, tmpVar1 = _a.errorMessage, tmpVar2 = _a.success, otherErrorData = __rest(_a, ["errorMessage", "success"]); | ||
Object.assign(errorToThrow, otherErrorData); | ||
} | ||
throw errorToThrow; | ||
case 4: return [2 /*return*/]; | ||
} | ||
}); | ||
@@ -68,0 +148,0 @@ }); |
{ | ||
"name": "@workerbase/sdk", | ||
"version": "0.1.15-beta.16", | ||
"version": "0.1.15-beta.17", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
133624
1951
27