@fullstory/server-api-client
Version:
The official FullStory server API client SDK for NodeJS.
119 lines • 5.07 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.UsersImpl = void 0;
const index_1 = require("./api/index");
const batch_1 = require("./batch");
const invalidArgument_1 = require("./errors/invalidArgument");
class BatchUsersJobImpl extends batch_1.BatchJobImpl {
constructor(fsOpts, request = { requests: [] }, opts = {}, includeSchema = false) {
super(request, new BatchUsersRequesterImpl(fsOpts, includeSchema), opts);
}
}
class BatchUsersRequesterImpl {
constructor(fsOpts, includeSchema) {
this.fsOpts = fsOpts;
this.includeSchema = includeSchema;
this.batchUsersImpl = new index_1.UsersBatchImportApi(fsOpts);
}
requestCreateJob(request) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const rsp = yield this.batchUsersImpl.createBatchUserImportJob(request);
// make sure job metadata and id 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.batchUsersImpl.getBatchUserImports({ jobId, pageToken, includeSchema: this.includeSchema });
const results = res.body;
if (!results) {
throw new Error('API did not response with any expected body');
}
return results;
});
}
requestImportErrors(jobId, pageToken) {
return __awaiter(this, void 0, void 0, function* () {
const res = yield this.batchUsersImpl.getBatchUserImportErrors({ jobId, pageToken });
const results = res.body;
if (!results) {
throw new Error('API did not response with any results');
}
return results;
});
}
requestJobStatus(jobId) {
return __awaiter(this, void 0, void 0, function* () {
const rsp = yield this.batchUsersImpl.getBatchUserImportStatus({ jobId });
const body = rsp.body;
if (!body) {
throw new Error('API did not response with any results');
}
return body;
});
}
}
////////////////////////////////////
// Exported User Interface
////////////////////////////////////
class UsersImpl {
constructor(opts) {
this.opts = opts;
this.usersImpl = new index_1.UsersApi(opts);
}
withOptions(opts) {
return new UsersImpl(Object.assign(Object.assign({}, this.opts), opts));
}
//TODO(sabrina): move options or make query param a typed object, to make call signature backward compatible when adding query params
get(...request) {
return __awaiter(this, void 0, void 0, function* () {
return this.usersImpl.getUser(...request);
});
}
create(...request) {
return __awaiter(this, void 0, void 0, function* () {
return this.usersImpl.createUser(...request);
});
}
list(...request) {
return __awaiter(this, void 0, void 0, function* () {
return this.usersImpl.listUsers(...request);
});
}
delete(request) {
return __awaiter(this, void 0, void 0, function* () {
const { id, uid } = request;
if (id && !uid) {
return this.usersImpl.deleteUser({ id });
}
if (uid && !id) {
return this.usersImpl.deleteUserByUid({ uid });
}
throw new invalidArgument_1.FSInvalidArgumentError('At least one and only one of id or uid is required.');
});
}
update(...request) {
return __awaiter(this, void 0, void 0, function* () {
return this.usersImpl.updateUser(...request);
});
}
batchCreate(request, jobOptions) {
return new BatchUsersJobImpl(this.opts, request === null || request === void 0 ? void 0 : request.body, jobOptions, request === null || request === void 0 ? void 0 : request.includeSchema);
}
}
exports.UsersImpl = UsersImpl;
//# sourceMappingURL=users.js.map