UNPKG

@viewdo/dxp-story-cli

Version:

DXP Story Management CLI

117 lines 4.99 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; 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.StripoApiService = void 0; const axios_1 = __importDefault(require("axios")); const typedi_1 = require("typedi"); const ConsoleService_1 = require("./ConsoleService"); const ConventionService_1 = require("./ConventionService"); const Utilities_1 = require("./Utilities"); const https_1 = __importDefault(require("https")); let StripoApiService = class StripoApiService { constructor(console, conventions) { this.console = console; this._baseURL = `${conventions.stripo_api_url}`; this._api = axios_1.default.create({ baseURL: this._baseURL, httpsAgent: new https_1.default.Agent({ rejectUnauthorized: false }) }); } withToken(token) { this._api = axios_1.default.create({ baseURL: this._baseURL, headers: { 'Stripo-Api-Auth': `${token}`, 'ContentType': 'application/json' }, httpsAgent: new https_1.default.Agent({ rejectUnauthorized: false }) }); return this; } _handleError(err) { return (0, Utilities_1.handleAxiosError)(err); } getFolders() { return __awaiter(this, void 0, void 0, function* () { let api_path = `/folders/EMAIL`; this.console.debug(`API: GET ${this._baseURL}${api_path}`.gray); try { const r = yield this._api.get(api_path); return r.data; } catch (err) { return this._handleError(err); } }); } getEmails(folderId) { return __awaiter(this, void 0, void 0, function* () { let api_path = `/emails?folderId=${folderId}&limit=1000`; // prevent need for implementing paging this.console.debug(`API: GET ${this._baseURL}${api_path}`.gray); try { const r = yield this._api.get(api_path); return r.data.data; // ...yup } catch (err) { return this._handleError(err); } }); } getRawEmail(emailId) { return __awaiter(this, void 0, void 0, function* () { let api_path = `/raw-email/${emailId}`; this.console.debug(`API: GET ${this._baseURL}${api_path}`.gray); try { const r = yield this._api.get(api_path); return r.data; } catch (err) { return this._handleError(err); } }); } getEmailExport(emailId) { return __awaiter(this, void 0, void 0, function* () { let api_path = `export/html/emails/${emailId}`; this.console.debug(`API: GET ${this._baseURL}${api_path}`.gray); try { const r = yield this._api.get(api_path); return r.data; } catch (err) { return this._handleError(err); } }); } }; exports.StripoApiService = StripoApiService; exports.StripoApiService = StripoApiService = __decorate([ (0, typedi_1.Service)(), __metadata("design:paramtypes", [ConsoleService_1.ConsoleService, ConventionService_1.ConventionService]) ], StripoApiService); //# sourceMappingURL=StripoAPIService.js.map