@jeeny/jeeny-js-sdk v1.0.11
The jeeny-js-sdk package provides an intuitive and typesafe way to interact with the Jeeny API.
š Jeeny.com
What is Jeeny?
Jeeny is a warehouse management system and enterprise resource planning API. It is a headless system for procurement, inventory, standard operating procedures, manufacturing, and fulfillment. Without replacing your current systems you can extend, enhance, and embed in order to create the customizations your teams need.
Table of contents
- Why use this
- Installation
- Authentication
- Import
- Setting the user
- Usage
- Available queries and mutations
- Error handling
- React SDK
Why use this?
The Jeeny JavaScript/TypeScript SDK provides a few advantages over rolling your own API layer.
- Autocomplete - a self-documenting API that provides tree-like access to the API, showcasing all available queries and mutations in your IDE
- Validation - see errors in your code before compiling with validation that always matches our latest spec
- Inline documentation - view property and record documentation in your IDE
- Up-to-date - always have access to the latest features
Installation
yarn add @jeeny/jeeny-js-sdk
npm install @jeeny/jeeny-js-sdk
Authentication
When you first import the Jeeny class you will need to authenticate with your companyId and API key.
You can get your free API key from the Jeeny Hub under the Headless menu.
Import
import { Jeeny } from "@jeeny/jeeny-js-sdk";
const jeeny = new Jeeny({
apiKey: TOKEN,
companyId: COMPANY_ID,
});
Adding default user information
You can set a default user string to send to Jeeny. This default user string will be added to records in places like createdBy
, updatedBy
, etc.
import { Jeeny } from "@jeeny/jeeny-js-sdk";
const jeeny = new Jeeny({
apiKey: TOKEN,
companyId: COMPANY_ID,
user: "oracle_application"
});
Setting the user
At any point in time you can change the user string that is sent to Jeeny. This can be useful if are going to authenticate users before they can access your application. For the best experience, you should match your userIds with users created in the Jeeny system and pass a Jeeny userId. This lets the Jeeny system add more information to records and provide better indexing and querying.
You can create users in the Jeeny Hub.
jeeny.setUser("test-user");
Usage
This SDK was built in TypeScript (but works great with JavaScript too). It is fully typed and meant to be self-documenting. This means that autocomplete will provide all available query and mutation options to you. Properties will have inline documentation that matches our GraphQL introspection. Validation is built-in so that you can't pass incorrect objects to endpoints.
It's a wrapper around the Jeeny API and so our official API documentation can provide further insight into using this SDK. You can also see a complete API reference in a single page if that's easier for you.
import { Jeeny } from "@jeeny/jeeny-js-sdk";
const newItem = await jeeny.items.createItem({
data: {
status: "active",
name: "Wooden block",
partNumber: "ABC-123",
},
});
const id = newItem.createItem?.id ?? "";
console.log(`Created a new item with id ${newItem.createItem?.id}`);
const existingItem = await jeeny.items.getItem({ id });
console.log("Existing item", existingItem.getItem);
Available queries and mutations
The following top level record types are available. The links below will take you to the official API documentation that will display all available queries and mutations for that specific record type.
Error handling
Errors can easily be caught and acted upon. The error message will tell you what went wrong - typically it is a validation issue from incorrect user input.
const newItem = await jeeny.items
.createItem({
data: {
status: "active",
name: "Wooden block",
partNumber: "ABC-123",
},
})
.catch((e) => {
console.log(e.response.errors);
});
or
try {
const newItem = await jeeny.items
.createItem({
data: {
status: "active",
name: "Wooden block",
partNumber: "ABC-123",
},
})
} catch (e) {
console.log(e.response.errors);
}
The errors
object looks like this and can hold multiple errors:
[
{
message: 'Variable "$data" got invalid value { status: "active", partNumber: "ABC-123" }; Field "name" of required type "String!" was not provided.',
extensions: { code: 'BAD_USER_INPUT', exception: [Object] }
}
]
React SDK
If you're building a UI in React we have a great SDK that lets the API fade into the background. Table, form, and action components are provided (fully typed and validated). Check it out here.
Author
š¤ Jeeny
- Website: https://jeeny.com
- Github: @jeeny-os
š¤ Contributing
Contributions, issues and feature requests are welcome!Feel free to check issues page.
Show your support
Give a āļø if this project helped you!
š License
Copyright Ā© 2023 Jeeny. This project is MIT licensed.
This README was generated with ā¤ļø by readme-md-generator