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

@frui.ts/apiclient

Package Overview
Dependencies
Maintainers
5
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@frui.ts/apiclient - npm Package Compare versions

Comparing version 1.0.0-alpha.8 to 1.0.0-alpha.9

130

dist/fetchApiConnector.js
"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) {

@@ -22,29 +11,2 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -55,7 +17,7 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

exports.FetchApiConnector = exports.handleErrorStatusMiddleware = exports.appendJsonHeader = exports.appendContentTypeHeader = exports.jsonContentType = void 0;
var helpers_1 = require("@frui.ts/helpers");
var fetchError_1 = __importDefault(require("./fetchError"));
const helpers_1 = require("@frui.ts/helpers");
const fetchError_1 = __importDefault(require("./fetchError"));
exports.jsonContentType = "application/json";
function appendContentTypeHeader(contentType, params) {
return __assign(__assign({}, params), { headers: __assign(__assign({}, (params !== null && params !== void 0 ? params : {}).headers), { "Content-Type": contentType }) });
return Object.assign(Object.assign({}, params), { headers: Object.assign(Object.assign({}, (params !== null && params !== void 0 ? params : {}).headers), { "Content-Type": contentType }) });
}

@@ -68,28 +30,19 @@ exports.appendContentTypeHeader = appendContentTypeHeader;

function handleErrorStatusMiddleware(response) {
return __awaiter(this, void 0, void 0, function () {
var content, _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
if (response.status >= 200 && response.status < 300) {
return [2, response];
}
_b.label = 1;
case 1:
_b.trys.push([1, 3, , 4]);
return [4, response.json()];
case 2:
content = _b.sent();
return [3, 4];
case 3:
_a = _b.sent();
throw new fetchError_1.default(response);
case 4: throw new fetchError_1.default(response, content);
}
});
return __awaiter(this, void 0, void 0, function* () {
if (response.status >= 200 && response.status < 300) {
return response;
}
let content;
try {
content = yield response.json();
}
catch (_a) {
throw new fetchError_1.default(response);
}
throw new fetchError_1.default(response, content);
});
}
exports.handleErrorStatusMiddleware = handleErrorStatusMiddleware;
var FetchApiConnector = (function () {
function FetchApiConnector(configuration) {
class FetchApiConnector {
constructor(configuration) {
var _a, _b, _c;

@@ -100,32 +53,31 @@ this.fetchFunction = (_a = configuration === null || configuration === void 0 ? void 0 : configuration.fetchFunction) !== null && _a !== void 0 ? _a : (0, helpers_1.bind)(window.fetch, window);

}
FetchApiConnector.prototype.get = function (url, params) {
return this.fetchFunction(url, __assign(__assign({}, params), { method: "GET" })).then(this.middleware);
};
FetchApiConnector.prototype.post = function (url, body, params) {
return this.fetchFunction(url, __assign(__assign({}, params), { method: "POST", body: body })).then(this.middleware);
};
FetchApiConnector.prototype.postObject = function (url, content, params) {
get(url, params) {
return this.fetchFunction(url, Object.assign(Object.assign({}, params), { method: "GET" })).then(this.middleware);
}
post(url, body, params) {
return this.fetchFunction(url, Object.assign(Object.assign({}, params), { method: "POST", body })).then(this.middleware);
}
postObject(url, content, params) {
return this.post(url, this.serializer(content), appendJsonHeader(params));
};
FetchApiConnector.prototype.put = function (url, body, params) {
return this.fetchFunction(url, __assign(__assign({}, params), { method: "PUT", body: body })).then(this.middleware);
};
FetchApiConnector.prototype.putObject = function (url, content, params) {
}
put(url, body, params) {
return this.fetchFunction(url, Object.assign(Object.assign({}, params), { method: "PUT", body })).then(this.middleware);
}
putObject(url, content, params) {
return this.put(url, this.serializer(content), appendJsonHeader(params));
};
FetchApiConnector.prototype.patch = function (url, body, params) {
return this.fetchFunction(url, __assign(__assign({}, params), { method: "PATCH", body: body })).then(this.middleware);
};
FetchApiConnector.prototype.patchObject = function (url, content, params) {
}
patch(url, body, params) {
return this.fetchFunction(url, Object.assign(Object.assign({}, params), { method: "PATCH", body })).then(this.middleware);
}
patchObject(url, content, params) {
return this.patch(url, this.serializer(content), appendJsonHeader(params));
};
FetchApiConnector.prototype.delete = function (url, body, params) {
return this.fetchFunction(url, __assign(__assign({}, params), { method: "DELETE", body: body })).then(this.middleware);
};
FetchApiConnector.prototype.deleteObject = function (url, content, params) {
}
delete(url, body, params) {
return this.fetchFunction(url, Object.assign(Object.assign({}, params), { method: "DELETE", body })).then(this.middleware);
}
deleteObject(url, content, params) {
return this.delete(url, this.serializer(content), appendJsonHeader(params));
};
return FetchApiConnector;
}());
}
}
exports.FetchApiConnector = FetchApiConnector;
//# sourceMappingURL=fetchApiConnector.js.map
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var FetchError = (function (_super) {
__extends(FetchError, _super);
function FetchError(response, content) {
var _this = _super.call(this, response.statusText) || this;
_this.response = response;
_this.content = content;
_this.handled = false;
return _this;
class FetchError extends Error {
constructor(response, content) {
super(response.statusText);
this.response = response;
this.content = content;
this.handled = false;
}
return FetchError;
}(Error));
}
exports.default = FetchError;
//# sourceMappingURL=fetchError.js.map
"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);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RestRequestBuilder = exports.appendUrl = exports.appendAcceptHeader = exports.ContentTypes = void 0;
var qs_1 = require("qs");
var cleanupRegex = /\/+$/g;
const qs_1 = require("qs");
const cleanupRegex = /\/+$/g;
exports.ContentTypes = {

@@ -21,16 +10,12 @@ json: "application/json,text/json",

function appendAcceptHeader(params, acceptContentType) {
return __assign(__assign({}, params), { headers: __assign(__assign({}, (params !== null && params !== void 0 ? params : {}).headers), { Accept: acceptContentType }) });
return Object.assign(Object.assign({}, params), { headers: Object.assign(Object.assign({}, (params !== null && params !== void 0 ? params : {}).headers), { Accept: acceptContentType }) });
}
exports.appendAcceptHeader = appendAcceptHeader;
function appendUrl(base) {
var segments = [];
for (var _i = 1; _i < arguments.length; _i++) {
segments[_i - 1] = arguments[_i];
}
var basePath = base.replace(cleanupRegex, "");
return segments.length ? basePath + "/" + segments.join("/") : basePath;
function appendUrl(base, ...segments) {
const basePath = base.replace(cleanupRegex, "");
return segments.length ? `${basePath}/${segments.join("/")}` : basePath;
}
exports.appendUrl = appendUrl;
var RestRequestBuilder = (function () {
function RestRequestBuilder(apiConnector, baseUrl, params) {
class RestRequestBuilder {
constructor(apiConnector, baseUrl, params) {
this.apiConnector = apiConnector;

@@ -40,93 +25,88 @@ this.baseUrl = baseUrl;

this.objectContentType = exports.ContentTypes.json;
this.objectDeserializer = function (x) { return x.json(); };
this.objectDeserializer = x => x.json();
this.reset();
}
Object.defineProperty(RestRequestBuilder.prototype, "url", {
get: function () {
return this.urlValue;
},
enumerable: false,
configurable: true
});
RestRequestBuilder.prototype.reset = function () {
get url() {
return this.urlValue;
}
reset() {
this.urlValue = this.baseUrl.replace(cleanupRegex, "");
};
RestRequestBuilder.prototype.path = function (path) {
}
path(path) {
this.urlValue += "/" + path;
return this;
};
RestRequestBuilder.prototype.all = function (path) {
}
all(path) {
this.urlValue += "/" + path;
return this;
};
RestRequestBuilder.prototype.one = function (path, id) {
}
one(path, id) {
this.urlValue += "/" + path;
if (id !== undefined) {
this.urlValue += "/" + id;
this.urlValue += `/${id}`;
}
return this;
};
RestRequestBuilder.prototype.get = function (queryParams) {
var requestUrl = this.appendQuery(this.urlValue, queryParams);
var params = appendAcceptHeader(this.params, this.objectContentType);
}
get(queryParams) {
const requestUrl = this.appendQuery(this.urlValue, queryParams);
const params = appendAcceptHeader(this.params, this.objectContentType);
return this.apiConnector.get(requestUrl, params).then(this.objectDeserializer);
};
RestRequestBuilder.prototype.getRaw = function (queryParams) {
var requestUrl = this.appendQuery(this.urlValue, queryParams);
}
getRaw(queryParams) {
const requestUrl = this.appendQuery(this.urlValue, queryParams);
return this.apiConnector.get(requestUrl, this.params);
};
RestRequestBuilder.prototype.post = function (content) {
var params = appendAcceptHeader(this.params, this.objectContentType);
}
post(content) {
const params = appendAcceptHeader(this.params, this.objectContentType);
return this.apiConnector.postObject(this.urlValue, content, params).then(this.objectDeserializer);
};
RestRequestBuilder.prototype.postOnly = function (content) {
}
postOnly(content) {
return this.apiConnector.postObject(this.urlValue, content, this.params);
};
RestRequestBuilder.prototype.postData = function (data) {
}
postData(data) {
return this.apiConnector.post(this.urlValue, data, this.params);
};
RestRequestBuilder.prototype.put = function (content) {
var params = appendAcceptHeader(this.params, this.objectContentType);
}
put(content) {
const params = appendAcceptHeader(this.params, this.objectContentType);
return this.apiConnector.putObject(this.urlValue, content, params).then(this.objectDeserializer);
};
RestRequestBuilder.prototype.putOnly = function (content) {
}
putOnly(content) {
return this.apiConnector.putObject(this.urlValue, content, this.params);
};
RestRequestBuilder.prototype.putData = function (data) {
}
putData(data) {
return this.apiConnector.put(this.urlValue, data, this.params);
};
RestRequestBuilder.prototype.patch = function (content) {
var params = appendAcceptHeader(this.params, this.objectContentType);
}
patch(content) {
const params = appendAcceptHeader(this.params, this.objectContentType);
return this.apiConnector.patchObject(this.urlValue, content, params).then(this.objectDeserializer);
};
RestRequestBuilder.prototype.patchOnly = function (content) {
}
patchOnly(content) {
return this.apiConnector.patchObject(this.urlValue, content, this.params);
};
RestRequestBuilder.prototype.patchData = function (data) {
}
patchData(data) {
return this.apiConnector.patch(this.urlValue, data, this.params);
};
RestRequestBuilder.prototype.delete = function (content) {
}
delete(content) {
return content
? this.apiConnector.deleteObject(this.urlValue, content, this.params)
: this.apiConnector.delete(this.urlValue, undefined, this.params);
};
RestRequestBuilder.prototype.withBaseUrl = function (url) {
}
withBaseUrl(url) {
this.urlValue = url;
return this;
};
RestRequestBuilder.prototype.getQueryString = function (query, queryStringOptions) {
}
getQueryString(query, queryStringOptions) {
var _a;
return (0, qs_1.stringify)(query, (_a = queryStringOptions !== null && queryStringOptions !== void 0 ? queryStringOptions : this.queryStringOptions) !== null && _a !== void 0 ? _a : RestRequestBuilder.DefaultQueryStringOptions);
};
RestRequestBuilder.prototype.appendQuery = function (url, query, queryStringOptions) {
}
appendQuery(url, query, queryStringOptions) {
if (!query) {
return url;
}
var queryString = typeof query === "string" ? query : this.getQueryString(query, queryStringOptions);
return url + "?" + queryString;
};
RestRequestBuilder.DefaultQueryStringOptions = { skipNulls: true };
return RestRequestBuilder;
}());
const queryString = typeof query === "string" ? query : this.getQueryString(query, queryStringOptions);
return `${url}?${queryString}`;
}
}
exports.RestRequestBuilder = RestRequestBuilder;
RestRequestBuilder.DefaultQueryStringOptions = { skipNulls: true };
//# sourceMappingURL=restRequestBuilder.js.map

@@ -6,3 +6,3 @@ {

},
"version": "1.0.0-alpha.8",
"version": "1.0.0-alpha.9",
"description": "Frui.ts helpers for HTTP communication",

@@ -36,3 +36,3 @@ "keywords": [

"dependencies": {
"@frui.ts/helpers": "^1.0.0-alpha.8",
"@frui.ts/helpers": "^1.0.0-alpha.9",
"qs": "^6.10.1"

@@ -43,3 +43,3 @@ },

},
"gitHead": "e774efd68e7bd49b83461fdcae0d110c2b69da90"
"gitHead": "718298c96617555dd2121f87a2dfefb3ea16d039"
}

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