UNPKG

nextcloud-node-client

Version:

Nextcloud client API for node.js TypeScript applications

51 lines (50 loc) 2.17 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const debug_1 = __importDefault(require("debug")); const error_1 = __importDefault(require("./error")); const server_1 = __importDefault(require("./server")); const debug = debug_1.default("NCEnvironment"); class Environment { constructor() { this.url = process.env.NEXTCLOUD_URL; this.userName = process.env.NEXTCLOUD_USERNAME; this.password = process.env.NEXTCLOUD_PASSWORD; if ((process.env.TEST_RECORDING_ACTIVE && (process.env.TEST_RECORDING_ACTIVE === "0" || process.env.TEST_RECORDING_ACTIVE === "false" || process.env.TEST_RECORDING_ACTIVE === "inactive")) || !process.env.TEST_RECORDING_ACTIVE) { this.recordingActive = false; } else { this.recordingActive = true; } } /** * returns the nextcloud credentials that is defined in the * "user-provided" service section of the VCAP_SERVICES environment * @param instanceName the name of the nextcloud user provided service instance * @returns credentials from the VCAP_SERVICES environment (user provided service) */ getServer() { if (!this.url) { throw new error_1.default("NCEnvironment: NEXTCLOUD_URL not defined in environment", "ERR_NEXTCLOUD_URL_NOT_DEFINED"); } if (!this.userName) { throw new error_1.default("NCEnvironment: NEXTCLOUD_USERNAME not defined in environment", "ERR_NEXTCLOUD_USERNAME_NOT_DEFINED"); } if (!this.password) { throw new error_1.default("NCEnvironment: NEXTCLOUD_PASSWORD not defined in environment", "ERR_NEXTCLOUD_PASSWORD_NOT_DEFINED"); } return new server_1.default({ basicAuth: { password: this.password, username: this.userName, }, logRequestResponse: this.recordingActive, url: this.url, }); } } exports.default = Environment;