@omnixdp/typegen
v0.8.4
Published
TypeScript type generator for Omni xDP SDK response models.
Readme
@omnixdp/typegen
Generate TypeScript types for Omni xDP SDK responses from live CMS, Business Objects, and Ratings and Reviews schemas.
Install
npm install -D @omnixdp/typegenGenerate
npx omnixdp-typegen \
--api-url https://api.example.com \
--management-client-id "$OMNIXDP_MANAGEMENT_CLIENT_ID" \
--management-client-secret "$OMNIXDP_MANAGEMENT_CLIENT_SECRET" \
--business-objects-client-id "$OMNIXDP_BO_CLIENT_ID" \
--business-objects-client-secret "$OMNIXDP_BO_CLIENT_SECRET" \
--ratings-and-reviews-client-id "$OMNIXDP_RR_CLIENT_ID" \
--ratings-and-reviews-client-secret "$OMNIXDP_RR_CLIENT_SECRET" \
--cms-space marketing \
--bo-space products \
--rr-space storefront-reviews \
--impex \
--out src/omnixdp.generated.tsSpace arguments can be a space id, slug, or exact name. Typegen loads .env and .env.local before evaluating config files, then exchanges client credentials for short-lived access tokens. Existing --management-token, --business-objects-token, and --ratings-and-reviews-token flags remain supported when you already have bearer tokens. Regenerate the output after changing content types, taxonomies, taxonomy types, data types, or global fields in the admin.
Generated CMS taxonomy response aliases use the delivery SDK's typed taxonomy tree shape: term slug and url are part of nested node data when those taxonomy fields are exposed through the Delivery API.
For CMS content types, typegen also emits Cms...References types and a CmsContentReferences map for Delivery API reference expansion results. CmsDeliveryEntry<TApiIdentifier> includes that reference map, so entry.references is typed for requested CMS, Business Objects, and Ratings and Reviews references when the field target is known. Generated CMS delivery entries also include publishedData.taxonomySelections, keyed by taxonomy API identifier, and generated field selectors include this.taxonomySelections plus <referenceName>.taxonomySelections for CMS entry references.
Typegen also emits CmsDeliveryClient and CmsDeliveryOptions for createTypedDeliveryClient. CmsDeliveryClient is the ready-to-use typed client alias, while CmsDeliveryOptions is the generated option map that narrows Delivery SDK method options such as fields, references, filters, taxonomy, sort, and expand to selectors known from the generated CMS content and taxonomy schemas. Generated sort values include id, updatedAt, and content field API identifiers marked Sortable, with -field variants for descending order.
import { createDeliveryClientFromEnv, createTypedDeliveryClient } from "@omnixdp/delivery";
import type { CmsDeliveryClient } from "./omnixdp.generated";
export const delivery: CmsDeliveryClient = createTypedDeliveryClient(createDeliveryClientFromEnv());Typegen also emits generated client aliases for the CMS Management, Business Objects, Ratings and Reviews, and optional IMPEX SDKs:
import { createBusinessObjectsClient, createTypedBusinessObjectsClient } from "@omnixdp/business-objects";
import type { BusinessObjectsClient } from "./omnixdp.generated";
export const businessObjects: BusinessObjectsClient = createTypedBusinessObjectsClient(
createBusinessObjectsClient({
baseUrl: process.env.OMNIXDP_API_URL!,
accessToken: process.env.OMNIXDP_BO_TOKEN!
})
);For Business Objects and Ratings and Reviews DataTree fields, typegen emits node data maps plus method aliases for getDataTreeNode, createDataTreeNode, updateDataTreeNode, moveDataTreeNode, and deleteDataTreeNode request/response shapes. The generated BusinessObjectsClient and RatingsReviewsClient aliases bind those maps so DataTree node data is inferred from dataTypeApiIdentifier and fieldApiIdentifier. Use aliases such as BusinessObjectCreateDataTreeNodeBody<"product", "comments"> or RatingsReviewGetDataTreeNodeResponse<"review_bank", "reviews"> with the matching SDK methods when you need standalone request or response types.
IMPEX has no live schema surface, so pass --impex or set impex: true in config to emit static ImpexResourceTypes and ImpexClient aliases backed by @omnixdp/impex defaults.
Check in CI
npx omnixdp-typegen --config omnixdp.typegen.config.js --check--check fails when the generated output is stale. The generated timestamp is ignored during comparison so a current file does not fail just because the check ran at a different time.
Config File
module.exports = {
apiUrl: process.env.OMNIXDP_API_URL,
managementClientId: process.env.OMNIXDP_MANAGEMENT_CLIENT_ID,
managementClientSecret: process.env.OMNIXDP_MANAGEMENT_CLIENT_SECRET,
businessObjectsClientId: process.env.OMNIXDP_BO_CLIENT_ID,
businessObjectsClientSecret: process.env.OMNIXDP_BO_CLIENT_SECRET,
ratingsAndReviewsClientId: process.env.OMNIXDP_RR_CLIENT_ID,
ratingsAndReviewsClientSecret: process.env.OMNIXDP_RR_CLIENT_SECRET,
cmsSpace: "marketing",
boSpace: "products",
rrSpace: "storefront-reviews",
impex: true,
out: "src/omnixdp.generated.ts"
};