@omnixdp/business-objects
v0.3.0
Published
TypeScript client for the Omni xDP Business Objects API.
Downloads
285
Readme
@omnixdp/business-objects
TypeScript SDK for the Omni xDP Business Objects API.
The package wraps /v1/business-objects with OAuth client_credentials helpers, request builders, response parsing, and a small fetch client that works in browsers, Next.js Client Components, and React Server Components.
Install
npm install @omnixdp/business-objectsCreate a client
import { createBusinessObjectsClient } from "@omnixdp/business-objects";
const businessObjects = createBusinessObjectsClient({
baseUrl: "https://api.example.com",
clientCredentials: {
clientId: process.env.OMNIXDP_BO_CLIENT_ID!,
clientSecret: process.env.OMNIXDP_BO_CLIENT_SECRET!
}
});Next.js usage
Keep API client secrets on the server when possible.
import { createBusinessObjectsClient } from "@omnixdp/business-objects";
const businessObjects = createBusinessObjectsClient({
baseUrl: process.env.OMNIXDP_API_URL!,
clientCredentials: {
clientId: process.env.OMNIXDP_BO_CLIENT_ID!,
clientSecret: process.env.OMNIXDP_BO_CLIENT_SECRET!
}
});
export default async function DataObjectsPage() {
const objects = await businessObjects.listDataObjects({
spaceId: "space_1",
dataTypeId: "type_1",
limit: 20
});
return <pre>{JSON.stringify(objects, null, 2)}</pre>;
}Browser warning
This API uses OAuth client_credentials. If you configure clientCredentials in a browser context, the SDK logs a warning because the secret may be exposed in the JavaScript bundle. Use a server-side proxy or route handler when possible.
Generated data object types
Use @omnixdp/typegen to regenerate Business Objects data types after data types or global fields change in the admin.
npx omnixdp-typegen \
--api-url https://api.example.com \
--business-objects-token "$OMNIXDP_BO_TOKEN" \
--bo-space products \
--out src/omnixdp.generated.tsimport { createBusinessObjectsClient, createTypedBusinessObjectsClient } from "@omnixdp/business-objects";
import type { BusinessObjectsClient } from "./omnixdp.generated";
const businessObjects: BusinessObjectsClient = createTypedBusinessObjectsClient(
createBusinessObjectsClient({
baseUrl: process.env.OMNIXDP_API_URL!,
accessToken: process.env.OMNIXDP_BO_TOKEN!
})
);
const products = await businessObjects.listDataObjects({
spaceId: "space_1",
dataTypeId: "type_1",
dataTypeApiIdentifier: "product"
});
products[0]?.data.sku;
const comment = await businessObjects.getDataTreeNode("object_1", "comments", "node_1", {
spaceId: "space_1",
dataTypeApiIdentifier: "product"
});
comment.data;Methods
getAccessToken(options)request(method, pathSegments, options)rawRequest(method, pathSegments, options)listSpaces,createSpace,updateSpace,deleteSpacelistCatalogTypes,listCatalogs,getCatalog,createCatalog,updateCatalog,deleteCataloggetCategory,updateCategorylistDataTypeslistDataObjects,getDataObject,createDataObject,updateDataObject,archiveDataObject,unarchiveDataObject,deleteDataObject,uploadDataObjectFieldgetDataTreeNode,createDataTreeNode,updateDataTreeNode,moveDataTreeNode,deleteDataTreeNodelistLanguages,listGlobalFields
DataTree node helpers export BusinessObjectsDataTreeNode, BusinessObjectsDataTreeNodeOptions, BusinessObjectsCreateDataTreeNodeBody, BusinessObjectsUpdateDataTreeNodeBody, and BusinessObjectsMoveDataTreeNodeBody.
Failed Business Objects API responses throw BusinessObjectsApiError with status, code, details, and the parsed response body when available.
