@fullstory/server-api-client
Version:
The official FullStory server API client SDK for NodeJS.
185 lines • 8.38 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.UsersBatchImportApi = void 0;
const http_1 = require("../../http");
const errors_1 = require("../../errors");
class UsersBatchImportApi {
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 a batch user import job with the given list of users\' information.
* @summary Create Batch Import
* @param body
* @param idempotencyKey Optional header for making the request idempotent
*/
createBatchUserImportJob(request) {
return __awaiter(this, void 0, void 0, function* () {
const { body, idempotencyKey, } = request;
const apiPath = `${this.basePath}/v2/users/batch`;
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);
}
});
}
/**
* Get the error message and code for any users that failed from a user import job.
* @summary Get Batch Import Errors
* @param jobId ID that can be used to check the status and retrieve results for the batch import
* @param pageToken The token that can be used in a request to fetch the next page of results
*/
getBatchUserImportErrors(request) {
return __awaiter(this, void 0, void 0, function* () {
const { jobId, pageToken, } = request;
const apiPath = `${this.basePath}/v2/users/batch/{job_id}/errors`
.replace('{' + 'job_id' + '}', encodeURIComponent(String(jobId)));
const url = new URL(apiPath);
const queryParams = new URLSearchParams();
const headerParams = {};
if (pageToken !== undefined) {
queryParams.set('page_token', pageToken);
}
const queryStr = queryParams.toString();
const requestOptions = {
method: 'GET',
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, undefined);
}
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);
}
});
}
/**
* Get the status for a batch user import job with job details.
* @summary Get Batch Import Job Details
* @param jobId ID that can be used to check the status and retrieve results for the batch import
*/
getBatchUserImportStatus(request) {
return __awaiter(this, void 0, void 0, function* () {
const { jobId, } = request;
const apiPath = `${this.basePath}/v2/users/batch/{job_id}`
.replace('{' + 'job_id' + '}', encodeURIComponent(String(jobId)));
const url = new URL(apiPath);
const queryParams = new URLSearchParams();
const headerParams = {};
const queryStr = queryParams.toString();
const requestOptions = {
method: 'GET',
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, undefined);
}
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);
}
});
}
/**
* Get the FullStory id and user details for successful users imported from a batch user import job.
* @summary Get Batch Imported Users
* @param jobId ID that can be used to check the status and retrieve results for the batch import
* @param pageToken The token that can be used in a request to fetch the next page of results
* @param includeSchema Whether to include schemas in the response.
*/
getBatchUserImports(request) {
return __awaiter(this, void 0, void 0, function* () {
const { jobId, pageToken, includeSchema, } = request;
const apiPath = `${this.basePath}/v2/users/batch/{job_id}/imports`
.replace('{' + 'job_id' + '}', encodeURIComponent(String(jobId)));
const url = new URL(apiPath);
const queryParams = new URLSearchParams();
const headerParams = {};
if (pageToken !== undefined) {
queryParams.set('page_token', pageToken);
}
if (includeSchema !== undefined) {
queryParams.set('include_schema', String(includeSchema));
}
const queryStr = queryParams.toString();
const requestOptions = {
method: 'GET',
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, undefined);
}
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.UsersBatchImportApi = UsersBatchImportApi;
//# sourceMappingURL=UsersBatchImportApi.js.map