UNPKG

fsm-sdk

Version:

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

73 lines 3.43 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.ServiceCallAPI = void 0; const request_options_factory_1 = require("../request-options.factory"); /** * Service for performing business actions on service calls. * Provides methods to cancel and manage service call lifecycle. */ class ServiceCallAPI { constructor(_config, _http, _auth) { this._config = _config; this._http = _http; this._auth = _auth; } /** * Constructs the API URL for service call business actions. * * @param {string} path - Path to append to the base URL. * @returns {string} The complete API URL. * @see https://api.sap.com/api/service_management_ext/resource/Service_Call_Business_Actions */ getApiUrl(path = '') { return `${this._config.baseUrl}/service-management/v2/servicecalls/${path}`; } /** * Cancels a service call by its ID. * * @param {string} id - Service call ID (also supports code=$ or externalId=$ format). * @param {object} options - Optional cancellation parameters. * @param {string} options.cancellationReason - Reason for cancellation. * @param {UdfValue[]} options.udfValues - User-defined field values. * @returns {Promise<{ activity: Activity }>} A promise resolving to the cancelled service call. */ cancel(id, // also support code=$ or externalId=$ options = {}) { return __awaiter(this, void 0, void 0, function* () { const token = yield this._auth.ensureToken(this._config); return this._http.request(this.getApiUrl(`${id}/actions/cancel`), { method: 'POST', headers: request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config), body: JSON.stringify(options) }); }); } /** * Marks a service call as technically complete. * * @param {string} id - Service call ID (also supports code=$ or externalId=$ format). * @returns {Promise<{ activity: Activity }>} A promise resolving to the service call. */ technicallyComplete(id // also support code=$ or externalId=$ ) { return __awaiter(this, void 0, void 0, function* () { const token = yield this._auth.ensureToken(this._config); return this._http.request(this.getApiUrl(`${id}/actions/technically-complete`), { method: 'POST', headers: request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config), body: JSON.stringify({}) }); }); } } exports.ServiceCallAPI = ServiceCallAPI; //# sourceMappingURL=service-call-api.service.js.map