@bavenir/spade-node-js-client
Version:
A client-side JavaScript library that can be used to iteract with Data Broker's API.
50 lines (49 loc) • 2.38 kB
JavaScript
;
/**
* Copyright (C) 2024 bAvenir
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
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());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Client = void 0;
const axios_1 = __importDefault(require("axios"));
class Client {
constructor(config) {
this._config = config;
}
get(path, config) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield (0, axios_1.default)(Object.assign(Object.assign({}, config), { method: 'get', url: `${this._config.url}/${path}`, headers: Object.assign({}, config === null || config === void 0 ? void 0 : config.headers), auth: {
username: this._config.clientId,
password: this._config.clientSecret,
} }));
return response.data;
});
}
post(path, config) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield (0, axios_1.default)(Object.assign(Object.assign({}, config), { method: 'post', url: `${this._config.url}/${path}`, headers: Object.assign({}, config === null || config === void 0 ? void 0 : config.headers), auth: {
username: this._config.clientId,
password: this._config.clientSecret,
} }));
return response.data;
});
}
}
exports.Client = Client;