UNPKG

fsm-sdk

Version:

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

222 lines 13 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.ActivityAPI = void 0; const polyfills_1 = require("../../polyfills"); const request_options_factory_1 = require("../request-options.factory"); const activity_bulk_api_service_1 = require("./activity-bulk-api.service"); class ActivityAPI { constructor(_config, _http, _auth) { this._config = _config; this._http = _http; this._auth = _auth; this.bulk = new activity_bulk_api_service_1.ActivityBulkAPI(this._config, this._http, this._auth); } /** * Constructs the API URL for activity bulk 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/Activity_Business_Actions */ getApiUrl(path = '') { return `${this._config.baseUrl}/service-management/v2/activities/${path}`; // note: "api/" segment is missing on the routing. } /** * Cancels an activity by its ID. * * @param {string} id - Activity ID (also supports code=$ or externalId=$ format). * @param {object} options - Optional cancellation parameters. * @param {boolean} options.cancelServiceCallConfirmed - Whether service call cancellation is confirmed. * @param {string} options.cancellationReason - Reason for cancellation. * @param {UdfValue[]} options.udfValues - User-defined field values. * @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. * @returns {Promise<{ activity: Activity }>} A promise resolving to the cancelled activity. */ cancel(id, // also support code=$ or externalId=$, options = {}, params = {}) { 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${(Object.keys(params || {}).length ? `?${new polyfills_1.URLSearchParams(params)}` : '')}`), { method: 'POST', headers: request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config), body: JSON.stringify(options) }); }); } /** * Closes an activity by its ID. * * @param {string} id - Activity ID (also supports code=$ or externalId=$ format). * @param {object} options - Optional closing parameters. * @param {UdfValue[]} options.udfValues - User-defined field values. * @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. * @returns {Promise<{ activity: Activity }>} A promise resolving to the closed activity. */ close(id, // also support code=$ or externalId=$, options = {}, params = {}) { return __awaiter(this, void 0, void 0, function* () { const token = yield this._auth.ensureToken(this._config); return this._http.request(this.getApiUrl(`${id}/actions/close${(Object.keys(params || {}).length ? `?${new polyfills_1.URLSearchParams(params)}` : '')}`), { method: 'POST', headers: request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config), body: JSON.stringify(options) }); }); } /** * Duplicates an activity by its ID. * * @param {string} id - Activity ID (also supports code=$ or externalId=$ format). * @param {object} options - Optional duplication parameters. * @param {string} options.crew - Crew identifier. * @param {string[]} options.responsibles - Array of responsible person identifiers. * @param {string} options.startDateTime - Start date and time in ISO 8601 format. * @param {string} options.unit - Unit identifier. * @param {UdfValue[]} options.udfValues - User-defined field values. * @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. * @returns {Promise<{ activity: Activity }>} A promise resolving to the duplicated activity. */ duplicate(id, // also support code=$ or externalId=$, options = {}, params = {}) { return __awaiter(this, void 0, void 0, function* () { const token = yield this._auth.ensureToken(this._config); return this._http.request(this.getApiUrl(`${id}/actions/duplicate${(Object.keys(params || {}).length ? `?${new polyfills_1.URLSearchParams(params)}` : '')}`), { method: 'POST', headers: request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config), body: JSON.stringify(options) }); }); } /** * Plans an activity by its ID. * * @param {string} id - Activity ID (also supports code=$ or externalId=$ format). * @param {object} options - Optional planning parameters. * @param {string} options.crew - Crew identifier. * @param {UnifiedIdentifier} options.technician - Technician identifier. * @param {string} options.startDateTime - Start date and time in ISO 8601 format. * @param {boolean} options.startDateTimeFixed - Whether start date/time is fixed. * @param {number} options.plannedDurationInMinutes - Planned duration in minutes. * @param {number} options.travelTimeFromInMinutes - Travel time from in minutes. * @param {number} options.travelTimeToInMinutes - Travel time to in minutes. * @param {string} options.endDateTime - End date and time in ISO 8601 format. * @param {boolean} options.endDateTimeFixed - Whether end date/time is fixed. * @param {UdfValue[]} options.udfValues - User-defined field values. * @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. * @returns {Promise<{ activity: Activity }>} A promise resolving to the planned activity. */ plan(id, // also support code=$ or externalId=$, options = {}, params = {}) { return __awaiter(this, void 0, void 0, function* () { const token = yield this._auth.ensureToken(this._config); return this._http.request(this.getApiUrl(`${id}/actions/plan${(Object.keys(params || {}).length ? `?${new polyfills_1.URLSearchParams(params)}` : '')}`), { method: 'POST', headers: request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config), body: JSON.stringify(options) }); }); } /** * Releases an activity by its ID. * * @param {string} id - Activity ID (also supports code=$ or externalId=$ format). * @param {object} options - Optional release parameters. * @param {UdfValue[]} options.udfValues - User-defined field values. * @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. * @returns {Promise<{ activity: Activity }>} A promise resolving to the released activity. */ release(id, // also support code=$ or externalId=$, options = {}, params = {}) { return __awaiter(this, void 0, void 0, function* () { const token = yield this._auth.ensureToken(this._config); return this._http.request(this.getApiUrl(`${id}/actions/release${(Object.keys(params || {}).length ? `?${new polyfills_1.URLSearchParams(params)}` : '')}`), { method: 'POST', headers: request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config), body: JSON.stringify(options) }); }); } /** * Replans an activity to a different technician. * * @param {string} id - Activity ID (also supports code=$ or externalId=$ format). * @param {object} options - Optional replanning parameters. * @param {string} options.crew - Crew identifier. * @param {UnifiedIdentifier} options.technician - New technician identifier. * @param {string} options.startDateTime - New start date and time in ISO 8601 format. * @param {boolean} options.startDateTimeFixed - Whether start date/time is fixed. * @param {number} options.plannedDurationInMinutes - Planned duration in minutes. * @param {number} options.travelTimeFromInMinutes - Travel time from in minutes. * @param {number} options.travelTimeToInMinutes - Travel time to in minutes. * @param {string} options.endDateTime - End date and time in ISO 8601 format. * @param {boolean} options.endDateTimeFixed - Whether end date/time is fixed. * @param {UdfValue[]} options.udfValues - User-defined field values. * @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. * @returns {Promise<{ activity: Activity }>} A promise resolving to the replanned activity. */ replan(id, // also support code=$ or externalId=$, options = {}, params = {}) { return __awaiter(this, void 0, void 0, function* () { const token = yield this._auth.ensureToken(this._config); return this._http.request(this.getApiUrl(`${id}/actions/replan${(Object.keys(params || {}).length ? `?${new polyfills_1.URLSearchParams(params)}` : '')}`), { method: 'POST', headers: request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config), body: JSON.stringify(options) }); }); } /** * Reschedules an activity to a different time slot and/or technician. * * @param {string} id - Activity ID (also supports code=$ or externalId=$ format). * @param {object} options - Optional rescheduling parameters. * @param {string} options.crew - Crew identifier. * @param {UnifiedIdentifier} options.technician - New technician identifier. * @param {string} options.startDateTime - New start date and time in ISO 8601 format. * @param {boolean} options.startDateTimeFixed - Whether start date/time is fixed. * @param {number} options.plannedDurationInMinutes - Planned duration in minutes. * @param {number} options.travelTimeFromInMinutes - Travel time from in minutes. * @param {number} options.travelTimeToInMinutes - Travel time to in minutes. * @param {string} options.endDateTime - End date and time in ISO 8601 format. * @param {boolean} options.endDateTimeFixed - Whether end date/time is fixed. * @param {UdfValue[]} options.udfValues - User-defined field values. * @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. * @returns {Promise<{ activity: Activity }>} A promise resolving to the rescheduled activity. */ reschedule(id, // also support code=$ or externalId=$, options = {}, params = {}) { return __awaiter(this, void 0, void 0, function* () { const token = yield this._auth.ensureToken(this._config); return this._http.request(this.getApiUrl(`${id}/actions/reschedule${(Object.keys(params || {}).length ? `?${new polyfills_1.URLSearchParams(params)}` : '')}`), { method: 'POST', headers: request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config), body: JSON.stringify(options) }); }); } } exports.ActivityAPI = ActivityAPI; //# sourceMappingURL=activity-api.service.js.map