A lightweight package for client-side apps to easily access and manage data from Basta's online auctions, providing a seamless integration for creating engaging auction experiences. A React library for integrating with the Basta API, providing type-safe GraphQL clients for both the Client API and Management API.
npm install basta-js
# or
pnpm add basta-js
# or
yarn add basta-js- Type-safe GraphQL client generated with genql
- React Context and Hooks for easy API access
- Support for both Client API and Management API
- Built with TypeScript
- React 16.8+ support
- All currency amounts follow the ISO 4217 standard. See here.
Wrap your application with the BastaProvider and configure the relevant API/s:
import { BastaProvider } from "basta-js";
function App() {
return (
<BastaProvider
clientApi={{
headers: {
// Add any custom headers here, e.g.: 'Authorization': 'Bearer client-token'
},
}}
// managementApi={{}}
>
<YourApp />
</BastaProvider>
);
}There are two ways to access the Client API:
Returns both clientApi and managementApi (nullable):
import { useBasta } from "basta-js";
function SomeComponent() {
const { clientApi } = useBasta();
const fetchSale = async () => {
const response = await clientApi?.query({
sale: {
__args: { id: "your-sale-id" },
id: true,
title: true,
description: true,
},
});
console.log(response?.sale);
};
return <div>Your component</div>;
}Returns a non-null Client instance (throws if not configured):
import { useClientApi } from "basta-js";
function SomeComponent() {
const clientApi = useClientApi();
const fetchSale = async () => {
const response = await clientApi.query({
sale: {
__args: { id: "your-sale-id" },
id: true,
title: true,
description: true,
},
});
console.log(response.sale);
};
return <div>Your component</div>;
}interface BastaProviderProps {
clientApi?: {
url?: string;
headers?: Record<string, string>;
wsUrl?: string;
};
managementApi?: {
url?: string;
headers?: Record<string, string>;
wsUrl?: string;
};
}useBasta(): Returns{ clientApi: Client | null, managementApi: Client | null }useClientApi(): ReturnsClient(non-null, throws if not configured)useManagementApi(): ReturnsClient(non-null, throws if not configured)
BastaProvider: Context provider for configuring and accessing the Basta APIs
# Build the library
pnpm build
# Format code
pnpm format
pnpm format:fix
# Update the Client API schema
pnpm client:update
# Update the Management API schema
pnpm manage:updateThis will prompt you to select an API version (e.g., 2022-10, unstable) and regenerate the client from the latest GraphQL schema.
For the Management API you'll have to supply an Account ID and API Key, you can put them in an .env file and the script will pick it up for you. Otherwise you'll be prompted for it by the script.
There are a couple of example projects setup within this repo for demonstration purposes. They can be run by doing pnpm example:next or pnpm example:vite. For the nextjs project you are required to have a .env file in the examples/nextjs folder for the extra authentication needed to perform queries with the management api.
react16.8.0 or higherurql5.0.0 or highergraphql-ws6.0.0 or higher (optional)
Right now this is a manual process.
- Update the
package.jsonversion - run
pnpm buildfor a new dist folder (probably smart to clear dist folder beforehand) - run the
pnpm publishscript, make sure you're logged in on your terminal with correct access to publish new versions
