Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@fullstory/server-api-client
Advanced tools
The official FullStory server API client SDK for NodeJS.
This package is in beta preview. It relies on unreleased beta API endpoints that may contain breaking changes without notice, do not use in production.
The Official FullStory server API client SDK for NodeJS. The SDK is designed for easy usage to make server-to-server HTTP API requests. For more information visit our developer site.
To use our in-browser module, we also provide a FullStory browser SDK.
# npm
npm install @fullstory/server-api-client
# yarn
yarn add @fullstory/server-api-client
Use the init
function to initialize the FullStory client with your API key.
import { init } from '@fullstory/server-api-client';
const fsClient = init({ apiKey: '<YOUR_API_KEY>' });
Use users
to access the users api
const { users } = fsClient;
const createResponse = await users.create({
uid: 'user123',
display_name: 'Display Name',
email: 'user123@example.com',
properties: {
pricing_plan: 'paid',
popup_help: true,
total_spent: 14.5,
},
});
// get user by the fullstory assigned id
const getResponse = await users.get('123456');
// get user by the application-specific uid
const listResponse = await users.list('user123');
// update user by the fullstory assigned id
const updatedResponse = await users.update('123456',
{ display_name: 'New Display Name' });
// delete user by the fullstory assigned id
await users.delete('123456');
Use events
to access the events api
const { events } = fsClient;
const createResponse = await events.create({
user: {
id: '123456',
},
session: {
use_most_recent: true,
},
context: {
web: {
url: 'https://www.example.com',
referrer_url: 'https://www.referrer.com',
},
device: {
ip: '127.0.0.1',
serial_number: 'ABC',
},
location: {
latitude: 33.80177165865808,
longitude: -84.39222238465959,
},
},
events: [
{
name: 'Support Ticket',
timestamp: '2022-03-15T14:23:23Z',
properties: {
id: 424242,
priority: 'Normal',
source: 'Email',
title: 'Account locked out',
},
},
{
name: "Another Event",
}
]
});
Create a batch users import job
// array of users to be imported
const requests = [
{
uid: 'user123',
display_name: 'Display Name',
email: 'user123@example.com',
properties: {
pricing_plan: 'paid',
popup_help: true,
total_spent: 14.5,
},
},
{
uid: 'user456',
},
{
uid: 'user789',
display_name: 'A New User',
},
];
// create a job object
const job = users.batchCreate(requests);
// you can add more requests before executing
job.add([
{ display_name: 'Someone Else' },
{ display_name: 'Last User' },
]);
Create a batch events import job
// array of events requests to be imported
const requests = [
{
user: {
id: '123456',
},
session: {
use_most_recent: true,
},
context: {
web: {
url: 'https://www.example.com',
},
},
events: [
{
name: 'Support Ticket',
timestamp: '2022-03-15T14:23:23Z',
properties: {
source: 'Email',
title: 'Account locked out',
},
},
{
name: "Another Event",
},
{
name: "More Events",
}
]
},
{
user: {
id: '000000',
},
session: {
use_most_recent: true,
},
events: [
{
name: 'Events - 1',
},
{
name: "Events - 2",
},
{
name: "Events - 3",
}
]
}
];
// create a job object
const job = events.batchCreate(requests);
// you can add more requests before executing
job.add([
{
user: {
id: '999999',
},
events: [
{
name: 'Events - 1',
},
]
}
]);
Batch Import Options
Each job can be created with different options:
const options = {
// poll job status every one minute
pollInterval: 60000,
// retry 5 times on API errors before aborting
maxRetry: 5,
}
Adding listeners for a batch import job and executing the job
Once the job is created successfully, created
listeners are invoked with the job's information.
The job then starts to poll on the server to get the latest job status at an interval:
done
state (COMPLETED
or FAILED
), we automatically retrieve the results, by calling get batch imports:The error
listeners are called anytime an error is encountered, may be called more than once.
The abort
listeners is called only once per job, if non-recoverable errors had occurred, such as multiple API failures had been encountered that exceeds the max number of retries.
job
// register listeners before executing
.on('created', job => {
console.log('batch job successfully created', job.getId());
})
.on('processing', job => {
console.log('get notified when job status polled and is still processing', job.getId());
})
.on('error', error => {
console.log('an error had occurred during the import', error);
})
.on('abort', error => {
console.error('an unrecoverable error had occurred and the job had been aborted', error);
})
.on('done', (imported, failed) => {
console.log('the batch imported job is done');
console.log('items successfully imported', imported);
console.log('items failed to be imported', failed);
})
// execute the job by calling the server API
job.execute();
Note: Any
error
,abort
ordone
listeners registered after the job has been executed, the callback may be called immediately with any historical data from the job, if any error had occurred, or if the job is already aborted or done, respectively.
It is recommended to have one batch import job of a resource type at a given time. However in case you need to create multiple batch import jobs by calling batchCreate
multiple times. The jobs may be concurrently executed. In this case that the server APIs may return rate limiting errors. It is recommended to adjust the pollingInterval
option accordingly.
The batch import job execution will retry if rate limit or other transient errors are encountered up to a max number of retries.
init
may throw an error when the required options fields are not satisfied.
Functions in the FullStory client may throw FSError
objects. For import jobs, the FSError
object is provided to the on error
callbacks.
If needed, the name
field identifies the type of error. The SDK also provides isFSError
function to check if an error object is a typed FSError
.
See errors for more information.
try {
...
} catch (err: unknown) {
if (isFSError(err)) {
switch (err.name) {
case FSErrorName.ERROR_RATE_LIMITED:
console.log('FullStory server API returned HTTP 429 Too Many Requests.');
console.log(`received 'retry - after' header, retry in ${err.getRetryAfter()} milliseconds.`);
break;
case FSErrorName.ERROR_PARSE_RESPONSE:
console.log('Unable to parse FullStory server API responses.');
console.log(`Raw response received ${(err as FSParserError).fsErrorPayload}.`);
break;
case FSErrorName.ERROR_FULLSTORY:
// API errors except 429s
console.log('FullStory server API returned non-2xx responses.');
console.log(`Status: ${(err as FSApiError).httpStatusCode}.`);
console.log(`Response: ${(err as FSApiError).fsErrorPayload}.`);
break;
case FSErrorName.ERROR_TIMEOUT:
console.log('Timeout exceeded while making FullStory server API requests.');
break;
case FSErrorName.ERROR_MAX_RETRY:
console.log('Max number of retries exceeded during batch import job execution.');
break;
case FSErrorName.ERROR_UNKNOWN:
console.log('Unexpected error occurred.');
break;
}
}
}
1.0.0-beta.2
FAQs
The official FullStory server API client SDK for NodeJS.
The npm package @fullstory/server-api-client receives a total of 2,167 weekly downloads. As such, @fullstory/server-api-client popularity was classified as popular.
We found that @fullstory/server-api-client demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.