@fullstory/server-api-client
Version:
The official FullStory server API client SDK for NodeJS.
74 lines • 3.32 kB
JavaScript
;
/* eslint-disable simple-import-sort/exports */
/* eslint-disable simple-import-sort/imports */
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.EventsApi = void 0;
const http_1 = require("../../http");
const errors_1 = require("../../errors");
class EventsApi {
constructor(opts) {
this.defaultBasePath = 'https://api.fullstory.com';
this.basePath = this.defaultBasePath;
// TODO(sabrina): allow injecting http client dependency rather than instantiating here
this.httpClient = new http_1.FSHttpClientImpl(opts);
// allow pointing to a different host for dev or tests
if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
this.basePath = process.env.FS_API_HOST || this.defaultBasePath;
}
}
/**
* Creates one event with the specified details.
* @summary Create Event
* @param body
* @param idempotencyKey Optional header for making the request idempotent
*/
createEvent(request) {
return __awaiter(this, void 0, void 0, function* () {
const { body, idempotencyKey, } = request;
const apiPath = `${this.basePath}/v2/events`;
const url = new URL(apiPath);
const queryParams = new URLSearchParams();
const headerParams = {};
if (idempotencyKey !== undefined) {
headerParams['Idempotency-Key'] = idempotencyKey;
}
const consumes = ['application/json'];
// prefer 'application/json' if supported
if (consumes.indexOf('application/json') >= 0) {
headerParams.accept = 'application/json';
}
else {
headerParams.accept = consumes.join(',');
}
const queryStr = queryParams.toString();
const requestOptions = {
method: 'POST',
headers: headerParams,
hostname: url.hostname,
host: url.host,
port: url.port,
protocol: url.protocol,
path: url.pathname + (queryStr ? '?' + queryStr : ''),
};
try {
return yield this.httpClient.request(requestOptions, body);
}
catch (e) {
// e originates from a callback (node task queue)
// try to append the current stack trace to the error
throw (0, errors_1.chainedFSError)(e);
}
});
}
}
exports.EventsApi = EventsApi;
//# sourceMappingURL=EventsApi.js.map