UNPKG

fsm-sdk

Version:

Node.JS sdk to interface with SAP Field Service Management APIs.

107 lines 5.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.TranslationApiService = void 0; const polyfills_1 = require("../../polyfills"); const request_options_factory_1 = require("../request-options.factory"); class TranslationApiService { constructor(_config, _http, _auth) { this._config = _config; this._http = _http; this._auth = _auth; } // https://api.sap.com/api/cloud_translation_service_ext/overview getApiUrl(path) { return `${this._config.baseUrl}/cloud-translation-service/api/v1/translations/${path}`; } getLabels(params) { return __awaiter(this, void 0, void 0, function* () { const token = yield this._auth.ensureToken(this._config); return this._http.request(this.getApiUrl(`labels` + (params ? `?${new polyfills_1.URLSearchParams(params)}` : '')), { method: 'GET', headers: request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config) }); }); } postLabel(data) { return __awaiter(this, void 0, void 0, function* () { const token = yield this._auth.ensureToken(this._config); return this._http.request(this.getApiUrl('labels'), { method: 'POST', headers: request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config), body: JSON.stringify(data) }); }); } putLabel(data) { return __awaiter(this, void 0, void 0, function* () { if (!data.id) throw new Error('id is required for update'); const token = yield this._auth.ensureToken(this._config); return this._http.request(this.getApiUrl(`labels/${data.id}`), { method: 'PUT', headers: request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config), body: JSON.stringify(data) }); }); } deleteLabel(id) { return __awaiter(this, void 0, void 0, function* () { const token = yield this._auth.ensureToken(this._config); return this._http.request(this.getApiUrl(`labels/${id}`), { method: 'DELETE', headers: request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config) }); }); } getValues(params) { return __awaiter(this, void 0, void 0, function* () { const token = yield this._auth.ensureToken(this._config); return this._http.request(this.getApiUrl(`values` + (params ? `?${new polyfills_1.URLSearchParams(params)}` : '')), { method: 'GET', headers: request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config) }); }); } postValue(data) { return __awaiter(this, void 0, void 0, function* () { const token = yield this._auth.ensureToken(this._config); return this._http.request(this.getApiUrl('values'), { method: 'POST', headers: request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config), body: JSON.stringify(data) }); }); } putValue(data) { return __awaiter(this, void 0, void 0, function* () { if (!data.id) throw new Error('id is required for update'); const token = yield this._auth.ensureToken(this._config); return this._http.request(this.getApiUrl(`values/${data.id}`), { method: 'PUT', headers: request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config), body: JSON.stringify(data) }); }); } deleteValue(id) { return __awaiter(this, void 0, void 0, function* () { const token = yield this._auth.ensureToken(this._config); return this._http.request(this.getApiUrl(`values/${id}`), { method: 'DELETE', headers: request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config) }); }); } } exports.TranslationApiService = TranslationApiService; //# sourceMappingURL=translations-api.service.js.map