UNPKG

fsm-sdk

Version:

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

111 lines 5.75 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.CompositeTreeAPI = void 0; const polyfills_1 = require("../../polyfills"); const request_options_factory_1 = require("../request-options.factory"); /** * Service for performing composite tree operations on service calls. * Provides methods to retrieve and manipulate service calls with their nested activity structures. */ class CompositeTreeAPI { constructor(_config, _http, _auth) { this._config = _config; this._http = _http; this._auth = _auth; } /** * Constructs the API URL for composite tree service call operations. * * @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_API_V2 */ getApiUrl(path) { return `${this._config.baseUrl}/service-management/api/v2/composite-tree/service-calls${path}`; } /** * Retrieves a service call with its complete tree structure including nested activities. * * @param {string} id - Service call ID (also supports code=$ or externalId=$ format). * @param {object} params - Optional query parameters. * @param {string} params.fieldsMode - Fields mode: 'INCLUDE', 'EXCLUDE', or 'ADD'. * @param {string[]} params.fields - Fields to include/exclude/add in the response. * @returns {Promise<ServiceCall>} A promise resolving to the service call with nested structure. */ getServiceCall(id, // also support code=$ or externalId=$ params = {}) { return __awaiter(this, void 0, void 0, function* () { const token = yield this._auth.ensureToken(this._config); return this._http.request(this.getApiUrl(`/${id}${(params ? `?${new polyfills_1.URLSearchParams(params)}` : '')}`), { method: 'GET', headers: request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config) }); }); } /** * Creates a new service call with its tree structure. * * @param {Partial<ServiceCall>} data - Service call data to create. * @param {object} params - Optional query parameters. * @param {boolean} params.autoCreateActivity - Whether to automatically create an activity for the service call. * @returns {Promise<ServiceCall>} A promise resolving to the created service call. */ postServiceCall(data, params = {}) { return __awaiter(this, void 0, void 0, function* () { const token = yield this._auth.ensureToken(this._config); return this._http.request(this.getApiUrl(`${(params ? `?${new polyfills_1.URLSearchParams(params)}` : '')}`), { method: 'POST', headers: request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config), body: JSON.stringify(data) }); }); } /** * Updates an existing service call with its tree structure. * * @param {Partial<ServiceCall>} data - Service call data with updates. Must include the id property. * @returns {Promise<ServiceCall>} A promise resolving to the updated service call. */ patchServiceCall(data) { return __awaiter(this, void 0, void 0, function* () { const token = yield this._auth.ensureToken(this._config); return this._http.request(this.getApiUrl(`/${data.id}`), { method: 'PATCH', headers: request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config), body: JSON.stringify(data) }); }); } /** * Retrieves a specific activity within a service call's tree structure. * * @param {string} serviceCallId - Service call ID (also supports code=$ or externalId=$ format). * @param {string} activityId - Activity ID (also supports code=$ or externalId=$ format). * @param {object} params - Optional query parameters. * @param {string} params.fieldsMode - Fields mode: 'INCLUDE', 'EXCLUDE', or 'ADD'. * @param {string[]} params.fields - Fields to include/exclude/add in the response. * @returns {Promise<Activity>} A promise resolving to the activity. */ getServiceCallActivity(serviceCallId, // also support code=$ or externalId=$ activityId, // also support code=$ or externalId=$ params = {}) { return __awaiter(this, void 0, void 0, function* () { const token = yield this._auth.ensureToken(this._config); return this._http.request(this.getApiUrl(`/${serviceCallId}/activities/${activityId}${(params ? `?${new polyfills_1.URLSearchParams(params)}` : '')}`), { method: 'GET', headers: request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config) }); }); } } exports.CompositeTreeAPI = CompositeTreeAPI; //# sourceMappingURL=composite-tree-api.service.js.map