@flatfile/safe-api
Version:
Flatfile Safe API client with streaming capabilities
37 lines (36 loc) • 1.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseRequest = void 0;
class BaseRequest {
constructor(params, payload) {
this.params = params;
this.payload = payload;
this.isRaw = false;
this._headers = {};
this.query = {};
}
getPath() {
let path = this.path;
this.params.forEach((param, i) => {
path = path.replace(`:param${i}`, param);
});
return path;
}
getConfig() {
return {
headers: this._headers
};
}
getUrl() {
const baseUrl = process.env.FLATFILE_API_URL || 'https://api.flatfile.io';
const url = new URL(this.getPath(), baseUrl);
// Add query parameters
Object.entries(this.query).forEach(([key, value]) => {
if (value !== undefined) {
url.searchParams.append(key, String(value));
}
});
return url.toString();
}
}
exports.BaseRequest = BaseRequest;