Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@onfleet/node-onfleet
Advanced tools
Read this document in another language: English, French, 正體中文
Visit our blog post on the API wrapper project to learn more about our initiatives. If you have any questions, please reach out to Onfleet by submitting an issue here or contact support@onfleet.com
The Onfleet Node.js library provides convenient access to the Onfleet API.
npm install @onfleet/node-onfleet
Before using the API wrapper, you will need to obtain an API key from your organization admin. Creation and integration of API keys are performed through the Onfleet dashboard.
To start utilizing the Onfleet API, you simply need to create an Onfleet object with your API key:
const onfleet = new Onfleet('<api_key>');
Once the Onfleet object is created, you can use a utility function to test on the authentication endpoint, this function returns a boolean:
onfleet.verifyKey();
Once the Onfleet object is created, you will get access to all the API endpoints as documented in the Onfleet API documentation. Here are some usage case:
Run npm test
Rate limiting is enforced by the API with a threshold of 20 requests per second across all your organization's API keys, learn more about it here.
The node-onfleet
API wrapper returns the body of a Response object.
The base URL for the Onfleet API is https://onfleet.com/api/v2
, here are the supported CRUD operations for each endpoint:
<endpoint> | GET | POST | PUT | DELETE |
---|---|---|---|---|
Admins | get() | create(obj) | update(id, obj) | deleteOne(id) |
Containers | get(id, 'workers'), get(id, 'teams'), get(id, 'organizations') | x | update(id, obj) | x |
Destinations | get(id) | create(obj) | x | x |
Hubs | get() | x | x | x |
Organization | get(), get(id) | x | insertTask(id, obj) | x |
Recipients | get(id), get(name, 'name'), get(phone, 'phone') | create(obj) | update(id, obj) | x |
Tasks | get(query), get(id), get(shortId, 'shortId') | create(obj), clone(id), forceComplete(id), batch(obj), autoAssign(obj) | update(id, obj) | deleteOne(id) |
Teams | get(), get(id) | create(obj) | update(id, obj), insertTask(id, obj) | deleteOne(id) |
Webhooks | get() | create(obj) | x | deleteOne(id) |
Workers | get(), get(query), get(id), getByLocation(obj), getSchedule(id) | create(obj), setSchedule(id, obj) | update(id, obj), insertTask(id, obj) | deleteOne(id) |
To get all the documents within an endpoint, this returns a Promise containing an array of results:
get();
get(<queryParam> (optional));
onfleet.workers.get().then((resultArray) => {
// do something with the array containing all workers
});
Option to use query parameters for some certain endpoints, refer back to API documents for endpoints that support query parameters:
onfleet.workers.get({phones: '<phone_number>'}).then((res) => {
// do something with the one result found
});
onfleet.tasks.get({from: '<from_time>', to: '<to_time>'}).then((result) => {
// do something with the results found
});
Note: Query parameters can be in any forms as long as it is a JSON object, for example:
{ 'analytics': 'true' }
works, so as{ analytics: true }
To get one of the document within an endpoint, if optional paramName is not provided, wrapper will search by ID. If paramName is provided, it will search by paramName:
get(<parameter>, <paramName> (optional), <queryParam> (optional));
Options for paramName: id, name, phone, shortId (see table above).
/**
* GET for Workers
*/
onfleet.workers.get('<24_digit_id>').then((result) => {
// do something with the one result found
});
onfleet.workers.get('<24_digit_id>', { analytics: true }).then((result) => {
// do something with the one result found
});
/**
* GET for Tasks
*/
onfleet.tasks.get('<shortId>', 'shortId').then((result) => {
// do something with the one result found
});
/**
* GET for Recipients
*/
onfleet.recipients.get('<phone_number>', 'phone').then((result) => {
// do something with the one result found
});
onfleet.recipients.get('<recipient_name>', 'name').then((result) => {
// do something with the one result found
});
onfleet.recipients.get('<recipient_name>', 'name', { skipPhoneNumberValidation: true}).then((result) => {
// do something with the one result found
});
/**
* GET for Containers
*/
onfleet.containers.get('<24_digit_id>', 'workers').then((result) => {
// do something with the one result found
});
onfleet.containers.get('<24_digit_id>', 'teams').then((result) => {
// do something with the one result found
});
onfleet.containers.get('<24_digit_id>', 'organizations').then((result) => {
// do something with the one result found
});
To get a driver by location, use the getByLocation
function:
getByLocation(<queryParam>);
const location = {
longitude: -122.404,
latitude: 37.789,
radius: 10000
}
onfleet.workers.getByLocation(location).then((result) => {
// shows the on-duty workers at the specific location
});
To create a document within an endpoint:
create(<object>);
const driver = {
name: 'A Swartz',
phone: '617-342-8853',
teams: ['W*8bF5jY11Rk05E0bXBHiGg2'],
vehicle: {
type: 'CAR',
description: 'Tesla Model 3',
licensePlate: 'FKNS9A',
color: 'purple',
},
};
onfleet.workers.create(driver);
Extended POST requests include clone
, forceComplete
, batchCreate
, autoAssign
on the tasks endpoint and setSchedule
on the workers endpoint:
onfleet.tasks.clone('<24_digit_id>');
onfleet.tasks.forceComplete('<24_digit_id>', '<completion_details>');
onfleet.tasks.batchCreate('<task_object_array>');
onfleet.tasks.autoAssign('<auto_assign_object>');
onfleet.workers.setSchedule('<24_digit_id>', newSchedule);
For more details, check our documentation on clone, forceComplete, batchCreate, autoAssign, and setSchedule
To update a document within an endpoint:
update(<id>, <object>);
const updateBody = {
name: 'New Driver Name',
};
onfleet.workers.update('<24_digit_id>', updateBody);
onfleet.workers.insertTask('kAQ*G5hnqlOq4jVvwtGNuacl', insertedTask).then(result => {
// do something
});
To delete a document within an endpoint:
deleteOne(<id>);
onfleet.workers.deleteOne('<24_digit_id>');
Get all the recipients (if it exist):
onfleet.tasks.get({from: '1557936000000', to: '1558022400000'}).then((res) => {
for (let element of res) {
if (element.recipients[0] !== undefined) {
// do something with the recipients
}
}
}).catch((err) => {
// do something with the error
});
Async/await can also be used in this following case:
async function findAllWorkers() {
try {
let response = await onfleet.workers.get();
// do something with the response
} catch(err) {
throw new Error(err);
}
};
findAllWorkers();
Inefficient pattern, use metadata instead:
onfleet.workers.get().then((res) => {
for (let element of res) {
if (element.name == 'some_name') {
onfleet.teams.get(element.teams[0]).then((result) => {
// do something with the team
})
}
}
}).catch((err) => {
// do something with the error
});
[1.0.4] - 2019-09-18
eslint-util
package.json vulnerability fixFAQs
Onfleet's Node.js API Wrapper Package
The npm package @onfleet/node-onfleet receives a total of 4,620 weekly downloads. As such, @onfleet/node-onfleet popularity was classified as popular.
We found that @onfleet/node-onfleet demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.