firebase-admin-ql
Version:
A powerful library that bridges Firebase Admin SDK with PostgreSQL, simplifies interaction with stored procedures, facilitates seamless third-party API calls using fetch, and provides utility functions to streamline backend operations.
43 lines • 2.07 kB
JavaScript
;
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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.APIFetcher = void 0;
const v2_1 = require("firebase-functions/v2");
class APIFetcher {
constructor(method, baseUrl, body, apiSecret, otherHeader) {
this._fetcher = (url, headers) => __awaiter(this, void 0, void 0, function* () {
try {
const response = yield fetch(url, {
method: this._method,
headers: headers !== null && headers !== void 0 ? headers : Object.assign({ "Authorization": `Bearer ${this._secretKey}`, "Content-Type": "application/json" }, this._otherHeader),
body: JSON.stringify(this._body),
});
v2_1.logger.log("api response: ", response);
return response;
}
catch (error) {
v2_1.logger.log("api error: ", error);
}
return;
});
this.apiCall = (endpoint) => __awaiter(this, void 0, void 0, function* () {
const url = this._baseUrl + endpoint;
return yield this._fetcher(url);
});
this._method = method;
this._body = body;
this._baseUrl = baseUrl;
this._secretKey = apiSecret;
this._otherHeader = otherHeader;
}
}
exports.APIFetcher = APIFetcher;
//# sourceMappingURL=api_caller.js.map