UNPKG

@fullstory/server-api-client

Version:

The official FullStory server API client SDK for NodeJS.

90 lines 3.93 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.EventsImpl = void 0; const index_1 = require("./api/index"); const batch_1 = require("./batch"); class BatchEventsJobImpl extends batch_1.BatchJobImpl { constructor(fsOpts, request = { requests: [] }, opts = {}, includeSchema = false) { super(request, new BatchEventsRequesterImpl(fsOpts, includeSchema), opts); } } class BatchEventsRequesterImpl { constructor(fsOpts, includeSchema) { this.fsOpts = fsOpts; this.includeSchema = includeSchema; this.batchEventsImpl = new index_1.EventsBatchImportApi(fsOpts); } requestCreateJob(request) { var _a; return __awaiter(this, void 0, void 0, function* () { const rsp = yield this.batchEventsImpl.createBatchEventsImportJob(request); // make sure job metadata exist const job = rsp.body; if (!((_a = job === null || job === void 0 ? void 0 : job.job) === null || _a === void 0 ? void 0 : _a.id)) { throw new Error(`Unable to get job ID after creating job, server status: ${rsp.httpStatusCode}`); } return job; }); } requestImports(jobId, pageToken) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.batchEventsImpl.getBatchEventsImports({ jobId, pageToken, includeSchema: this.includeSchema }); const results = res.body; if (!results) { throw new Error('API did not response with expected body'); } return results; }); } requestImportErrors(jobId, pageToken) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.batchEventsImpl.getBatchEventsImportErrors({ jobId, pageToken }); const results = res.body; if (!results) { throw new Error('API did not response with expected body'); } return results; }); } requestJobStatus(jobId) { return __awaiter(this, void 0, void 0, function* () { const rsp = yield this.batchEventsImpl.getBatchEventsImportStatus({ jobId }); const body = rsp.body; if (!body) { throw new Error('API did not response with any results'); } return body; }); } } //////////////////////////////////// // Exported Event Interface //////////////////////////////////// class EventsImpl { constructor(opts) { this.opts = opts; this.eventsImpl = new index_1.EventsApi(opts); } withOptions(opts) { return new EventsImpl(Object.assign(Object.assign({}, this.opts), opts)); } create(...request) { return __awaiter(this, void 0, void 0, function* () { return this.eventsImpl.createEvent(...request); }); } batchCreate(request, jobOptions) { return new BatchEventsJobImpl(this.opts, request === null || request === void 0 ? void 0 : request.body, jobOptions, request === null || request === void 0 ? void 0 : request.includeSchema); } } exports.EventsImpl = EventsImpl; //# sourceMappingURL=events.js.map