UNPKG

qus-canvas

Version:
61 lines (60 loc) 3.09 kB
"use strict"; 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.CanvasHttpConnector = void 0; /* * MIT License * * Copyright (c) 2024 Quantum Unit Solutions * Author: David Meikle * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ const node_http_connector_1 = require("node-http-connector"); class CanvasHttpConnector extends node_http_connector_1.HttpClient { constructor(canvasBaseUrl, headers) { super(canvasBaseUrl); this.headers = headers; this.enableLogging(); this.setAuthToken(headers.token); } addServiceIdentifierHeader(headers) { var _a; return Object.assign(Object.assign({}, headers), { 'X-Service-Identifier': (_a = this.serviceIdentifier) !== null && _a !== void 0 ? _a : '' }); } request(method_1, endpoint_1) { const _super = Object.create(null, { request: { get: () => super.request } }); return __awaiter(this, arguments, void 0, function* (method, endpoint, data = null, config = {}) { config = config || { headers: this.headers }; const headers = this.addServiceIdentifierHeader(config.headers || this.headers); return _super.request.call(this, method, endpoint, data, Object.assign(Object.assign({}, config), { headers })); }); } } exports.CanvasHttpConnector = CanvasHttpConnector;