fsm-sdk
Version:
Node.JS sdk to interface with SAP Field Service Management APIs.
40 lines • 2.44 kB
JavaScript
;
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.BatchAPIService = void 0;
const polyfills_1 = require("../../polyfills");
const batch_request_model_1 = require("./batch-request.model");
const batch_response_1 = require("./batch-response");
const request_options_factory_1 = require("../request-options.factory");
class BatchAPIService {
constructor(_config, _http, _auth) {
this._config = _config;
this._http = _http;
this._auth = _auth;
}
batch(actions) {
return __awaiter(this, void 0, void 0, function* () {
const token = yield this._auth.ensureToken(this._config);
const body = new batch_request_model_1.BatchRequest(token, this._config, actions).toString();
const queryParams = new polyfills_1.URLSearchParams(Object.assign(Object.assign({ clientIdentifier: this._config.clientIdentifier, dtos: request_options_factory_1.RequestOptionsFactory.getDTOVersionsString(actions.map(it => it.dtoName)) }, request_options_factory_1.RequestOptionsFactory.getRequestAccountQueryParams(token, this._config))));
const responseBody = yield this._http.request(`${this._config.baseUrl}/api/data/batch/v1?${queryParams}`, {
method: 'POST',
headers: Object.assign({ 'content-type': 'multipart/mixed;boundary="======boundary======"' }, request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config)),
body
});
return responseBody !== null
? new batch_response_1.BatchResponse(responseBody).toJson()
: [];
});
}
}
exports.BatchAPIService = BatchAPIService;
//# sourceMappingURL=batch-api.service.js.map