fsm-sdk
Version:
Node.JS sdk to interface with SAP Field Service Management APIs.
165 lines • 7.83 kB
JavaScript
"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.RulesAPIService = void 0;
const polyfills_1 = require("../../polyfills");
const request_options_factory_1 = require("../request-options.factory");
/**
* Rules API Service for FSM Business Rules
*
* Implements business rule engine to validate and execute custom rules.
* Stores business rule definitions and rule executions.
*
* @see https://api.sap.com/api/cloud_rules_service_ext/overview
*/
class RulesAPIService {
constructor(_config, _http, _auth) {
this._config = _config;
this._http = _http;
this._auth = _auth;
}
/**
* Constructs the API URL for rules operations.
*
* @param {string} path - Path to append to the base URL.
* @returns {string} The complete API URL.
*/
getApiUrl(path = '') {
return `${this._config.baseUrl}/cloud-rules-service/api/v1/rules${path ? '/' + path : ''}`;
}
/**
* Get all rules with optional filtering and pagination.
*
* @param {object} params - Optional query parameters for filtering, pagination, and sorting.
* @param {string} params.kafkaEventName - Filter by Kafka event name.
* @param {string} params.code - Filter by rule code.
* @param {string} params.name - Filter by rule name.
* @param {boolean} params.embedded - Filter by embedded status.
* @param {boolean} params.enabled - Filter by enabled status.
* @param {EventType} params.eventType - Filter by event type.
* @param {string} params.objectType - Filter by object type.
* @param {HealthState} params.healthState - Filter by health state.
* @param {number} params.page - Page number for pagination.
* @param {number} params.size - Page size for pagination.
* @param {string} params.sortBy - Field to sort by (default: 'name').
* @param {string} params.order - Sort order: 'asc' or 'desc' (default: 'asc').
* @param {string} params.search - Search text.
* @returns {Promise<PageRuleDto | null>} A promise resolving to paginated rules.
*/
getRules(params) {
return __awaiter(this, void 0, void 0, function* () {
const token = yield this._auth.ensureToken(this._config);
const queryString = params ? `?${new polyfills_1.URLSearchParams(params)}` : '';
return this._http.request(this.getApiUrl() + queryString, {
method: 'GET',
headers: request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config)
});
});
}
/**
* Create a new rule.
*
* @param {object} data - Rule data to create.
* @returns {Promise<RuleDto | null>} A promise resolving to the created rule.
*/
createRule(data) {
return __awaiter(this, void 0, void 0, function* () {
const token = yield this._auth.ensureToken(this._config);
return this._http.request(this.getApiUrl(), {
method: 'POST',
headers: request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config),
body: JSON.stringify(data)
});
});
}
/**
* Get a specific rule by ID.
*
* @param {string} id - Rule identifier (UUID).
* @returns {Promise<RuleDto | null>} A promise resolving to the rule.
*/
getRule(id) {
return __awaiter(this, void 0, void 0, function* () {
const token = yield this._auth.ensureToken(this._config);
return this._http.request(this.getApiUrl(id), {
method: 'GET',
headers: request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config)
});
});
}
/**
* Update an existing rule (partial update).
*
* @param {string} id - Rule identifier (UUID).
* @param {object} data - Partial rule data to update.
* @returns {Promise<RuleDto | null>} A promise resolving to the updated rule.
*/
updateRule(id, data) {
return __awaiter(this, void 0, void 0, function* () {
const token = yield this._auth.ensureToken(this._config);
return this._http.request(this.getApiUrl(id), {
method: 'PATCH',
headers: request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config),
body: JSON.stringify(data)
});
});
}
/**
* Create or update a rule (full replace or create).
*
* @param {string} id - Rule identifier (UUID).
* @param {object} data - Complete rule data.
* @returns {Promise<RuleDto | null>} A promise resolving to the created or updated rule.
*/
createOrUpdateRule(id, data) {
return __awaiter(this, void 0, void 0, function* () {
const token = yield this._auth.ensureToken(this._config);
return this._http.request(this.getApiUrl(id), {
method: 'PUT',
headers: request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config),
body: JSON.stringify(data)
});
});
}
/**
* Get execution records for a specific rule.
*
* @param {string} id - Rule identifier (UUID).
* @param {object} params - Optional query parameters for filtering, pagination, and sorting.
* @param {string} params.executionDateFrom - Filter by execution date from (ISO date format).
* @param {string} params.executionDateTo - Filter by execution date to (ISO date format).
* @param {ExecutionStatus} params.status - Filter by execution status.
* @param {string} params.objectId - Filter by object ID.
* @param {string} params.userId - Filter by user ID.
* @param {string} params.clientId - Filter by client ID.
* @param {string} params.requestId - Filter by request ID.
* @param {EventType} params.eventType - Filter by event type.
* @param {string} params.errorMessage - Filter by error message.
* @param {number} params.page - Page number for pagination.
* @param {number} params.size - Page size for pagination.
* @param {string} params.sortBy - Field to sort by.
* @param {string} params.sortOrder - Sort order: 'asc' or 'desc'.
* @param {string} params.search - Search text.
* @returns {Promise<PageCustomRuleExecutionRecordDto | null>} A promise resolving to paginated execution records.
*/
getRuleExecutionRecords(id, params) {
return __awaiter(this, void 0, void 0, function* () {
const token = yield this._auth.ensureToken(this._config);
const queryString = params ? `?${new polyfills_1.URLSearchParams(params)}` : '';
return this._http.request(this.getApiUrl(`${id}/executionRecords`) + queryString, {
method: 'GET',
headers: request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config)
});
});
}
}
exports.RulesAPIService = RulesAPIService;
//# sourceMappingURL=rules-api.service.js.map