@fullstory/server-api-client
Version:
The official FullStory server API client SDK for NodeJS.
276 lines • 11.5 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.UsersApi = void 0;
const http_1 = require("../../http");
const errors_1 = require("../../errors");
class UsersApi {
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 user with the specified details.
* @summary Create User
* @param body
* @param idempotencyKey Optional header for making the request idempotent
*/
createUser(request) {
return __awaiter(this, void 0, void 0, function* () {
const { body, idempotencyKey, } = request;
const apiPath = `${this.basePath}/v2/users`;
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);
}
});
}
/**
* Delete a single user by FullStory generated user ID.
* @summary Delete User
* @param id The FullStory-generated id for the user.
*/
deleteUser(request) {
return __awaiter(this, void 0, void 0, function* () {
const { id, } = request;
const apiPath = `${this.basePath}/v2/users/{id}`
.replace('{' + 'id' + '}', encodeURIComponent(String(id)));
const url = new URL(apiPath);
const queryParams = new URLSearchParams();
const headerParams = {};
const queryStr = queryParams.toString();
const requestOptions = {
method: 'DELETE',
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);
}
});
}
/**
* Delete a single user by uid.
* @summary Delete User
* @param uid The application-specific ID you've given to the user
*/
deleteUserByUid(request) {
return __awaiter(this, void 0, void 0, function* () {
const { uid, } = request;
const apiPath = `${this.basePath}/v2/users`;
const url = new URL(apiPath);
const queryParams = new URLSearchParams();
const headerParams = {};
if (uid !== undefined) {
queryParams.set('uid', uid);
}
const queryStr = queryParams.toString();
const requestOptions = {
method: 'DELETE',
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);
}
});
}
/**
* Retrieve details for a single user
* @summary Get User
* @param id The FullStory assigned user ID
* @param includeSchema Whether to include the schema in the response.
*/
getUser(request) {
return __awaiter(this, void 0, void 0, function* () {
const { id, includeSchema, } = request;
const apiPath = `${this.basePath}/v2/users/{id}`
.replace('{' + 'id' + '}', encodeURIComponent(String(id)));
const url = new URL(apiPath);
const queryParams = new URLSearchParams();
const headerParams = {};
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);
}
});
}
/**
* Retrieve a list of users matching the supplied filter criteria
* @summary Get Users
* @param uid The application-specific ID you've given to a user
* @param email The email address associated with a user
* @param displayName The nice-looking name for a user
* @param isIdentified Whether or not a user is anonymous or identified
* @param pageToken The token indicating the page of users to fetch. The same filter criteria should be supplied. This value should not be specified when requesting the first page of users.
* @param includeSchema Whether to include schemas in the response.
*/
listUsers(request) {
return __awaiter(this, void 0, void 0, function* () {
const { uid, email, displayName, isIdentified, pageToken, includeSchema, } = request;
const apiPath = `${this.basePath}/v2/users`;
const url = new URL(apiPath);
const queryParams = new URLSearchParams();
const headerParams = {};
if (uid !== undefined) {
queryParams.set('uid', uid);
}
if (email !== undefined) {
queryParams.set('email', email);
}
if (displayName !== undefined) {
queryParams.set('display_name', displayName);
}
if (isIdentified !== undefined) {
queryParams.set('is_identified', String(isIdentified));
}
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);
}
});
}
/**
* Updates a user with the specified details
* @summary Update User
* @param id The FullStory assigned user ID
* @param body
*/
updateUser(request) {
return __awaiter(this, void 0, void 0, function* () {
const { id, body, } = request;
const apiPath = `${this.basePath}/v2/users/{id}`
.replace('{' + 'id' + '}', encodeURIComponent(String(id)));
const url = new URL(apiPath);
const queryParams = new URLSearchParams();
const headerParams = {};
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.UsersApi = UsersApi;
//# sourceMappingURL=UsersApi.js.map