Include extend response types #29
Labels
No labels
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
javascript
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
ckreidl/katanatools#29
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
For certain resources, Katana accepts an
extendparameter. For example: when querying aproductone can passextend: ['supplier']to have Katana return the default supplier record linked to that product. In thekatana-clientpackage, we currently include optional fields for eachextendoption in the schema, but this leads to a lot of null coalescing in consumers.This really is a shortcoming of Katana's OpenAPI spec, from which our schemas were derived.
Other examples:
The
variantresource acceptsextend: ['product_or_material'], which includes aproduct_or_materialvalue in the response type, which can be either aKatanaProductor aKatanaMaterial. If thatextendparameter is absent from the request this value does not exist or is an empty object.I'd like to investigate options on how this shortcoming in the published OpenAPI spec can be addressed while staying as true as possible to the spec and providing the best dx possible.
@coderabbitai plan
Coding Plan
Summary
WithExtend<Base, ExtendKeys>) that conditionally make extended fields required based on the extend values specifiedproduct_or_materialfield onKatanaVariantto complete type coverage, with inline documentation marking it as a spec gapSPEC_GAPS.mdto catalog known OpenAPI spec deficiencies for developer reference and support ticket evidenceDesign Choices
Design Choice 1: How should we handle the return type when extend is specified vs. omitted?
Options Considered:
listWithExtend()) that always return extended typesChosen Option: 1
Rationale: Option 1 (function overloads): Maintains existing API surface, provides precise types when extend is specified, and falls back to current optional-field types when extend is omitted—no breaking changes for existing consumers.
Design Choice 2: How should we model the `product_or_material` union for variants?
Options Considered:
product_or_material?: KatanaProduct | KatanaMaterialas a union typetypefield to distinguish product vs materialproduct?: KatanaProductandmaterial?: KatanaMaterialfieldsChosen Option: 1
Rationale: Option 1 (union type): Matches Katana's actual API response shape where a single field contains either type, and aligns with how other extended fields are modeled.
Design Choice 3: What is the impact on existing consumers of the katana-client package?
Options Considered:
Chosen Option: 2
Rationale: Option 2 (additive-only): This implementation introduces zero breaking changes. Function overloads add type precision for callers who specify extend, while existing code that omits extend or doesn't use the extended fields continues to work unchanged. All extended fields remain optional on base interfaces—overloads only provide narrower types when explicitly requested.
💡 User Tips
Regenerate the plan with different choices with
@coderabbitai <feedback>.Implementation Steps
Phase 1: Type Infrastructure — Utility Types and Extended Interfaces
Establish the foundation of TypeScript utility types that enable conditional typing based on extend parameter values. This phase creates reusable type-level infrastructure that the resource methods will leverage.
Task 1: Create Extend Utility Types
Define mapped types that conditionally add required fields based on extend values passed by the caller.
packages/katana-client/src/types.tsfor extend-related utility typesExtendableFieldsmapped type that associates extend string literals to their corresponding interface types (e.g.,'supplier' → KatanaSupplier,'variant' → KatanaProductVariant | KatanaInventoryVariant,'location' → KatanaLocation,'product_or_material' → KatanaProduct | KatanaMaterial)WithExtend<Base, ExtendKeys>generic type that takes a base interface and an array of extend keys, producing a new type where those fields are required instead of optionalTask 2: Add Missing product_or_material Field to KatanaVariant
Fix the gap where
KatanaVariantacceptsextend: ["product_or_material"]but lacks the corresponding response field. This is a known deviation from the published OpenAPI spec.product_or_material?: KatanaProduct | KatanaMaterialto theKatanaVariantinterface inpackages/katana-client/src/types.ts/** @specGap Katana OpenAPI spec omits this field; added for extend: ['product_or_material'] support */)Task 3: Create Extended Response Type Aliases
Define convenient type aliases for common extended response shapes to simplify overload declarations.
packages/katana-client/src/types.ts, create aliases likeKatanaProductWithSupplier,KatanaVariantWithProductOrMaterial,KatanaInventoryItemWithVariant,KatanaInventoryItemWithLocation,KatanaInventoryItemWithBothWithExtendutility type internally but provide readable names for method signaturessrc/types.ts(they're already re-exported viasrc/index.ts)🤖 Prompt for AI agents
Phase 2: Resource Method Overloads — Products, Materials, Variants
Add function overloads to resource methods that accept extend parameters, providing precise return types when callers specify which extensions they want.
Task 1: Add Overloads to ProductsResource
Implement overloads for list and get methods that return supplier as required when extend includes
'supplier'.packages/katana-client/src/resources/products.ts, add overload signatures before the existinglistandgetmethod implementationsextend: ['supplier'], return type uses the extended interface withsupplierrequired../typesTask 2: Add Overloads to MaterialsResource
Apply the same overload pattern for materials, which also supports
extend: ['supplier'].packages/katana-client/src/resources/materials.ts, add overload signatures forlistandgetmethodsextend: ['supplier']returnsKatanaMaterialWithSupplierTask 3: Add Overloads to VariantsResource
Implement overloads for the variant resource's product_or_material extension.
packages/katana-client/src/resources/variants.ts, add overload signatures forlistandgetmethodsextend: ['product_or_material']is specified, return type includes the field as requiredKatanaVariantWithProductOrMaterialtype🤖 Prompt for AI agents
Phase 3: Resource Method Overloads — Sales Orders, Purchase Orders, Inventory
Complete the overload coverage for remaining resources, with special attention to inventory's multiple extend options.
Task 1: Add Overloads to SalesOrderRowsResource
Handle the variant extension for sales order rows.
packages/katana-client/src/resources/salesOrderRows.ts, add overload forlistmethod only (no get method exists)extend: ['variant']is specified, return response type withvariantas required fieldTask 2: Add Overloads to PurchaseOrdersResource
Handle the supplier extension for purchase orders.
packages/katana-client/src/resources/purchaseOrders.ts, add overload forlistmethod onlyextend: ['supplier']is specified, return response type withsupplieras requiredTask 3: Add Overloads to InventoryResource
Handle inventory's multiple extend options: variant, location, or both.
packages/katana-client/src/resources/inventory.ts, add multiple overloads for thelistmethodextend: ['variant', 'location']or['location', 'variant']returns both fields as requiredextend: ['variant']returns variant as required, location optionalextend: ['location']returns location as required, variant optional🤖 Prompt for AI agents
Phase 4: Documentation and Type Exports
Ensure the new type-level features are discoverable and properly documented for consumers.
Task 1: Create SPEC_GAPS.md
Document known OpenAPI spec deficiencies to serve as developer reference and evidence for Katana support tickets.
packages/katana-client/SPEC_GAPS.mdto catalog known spec issuesKatanaVariant.product_or_materialfield omission (extend response field missing from spec)Task 2: Update Type Exports
Verify all new utility types and extended interfaces are properly exported.
packages/katana-client/src/types.tsexports to ensure all new types are includedsrc/index.tsre-exports from types.ts, so no changes needed therepnpm buildin katana-client to verify type declarations are generated correctlyTask 3: Add JSDoc Documentation
Document the overloaded methods and new utility types for IDE discoverability.
WithExtendutility type explaining its purpose and usage pattern@exampletags showing how to use extend for precise return types@specGaptag convention for any fields or types that deviate from the published OpenAPI specTask 4: Update README with Extend Usage
Add documentation about the improved extend typing to the package README.
packages/katana-client/README.md, add a section explaining the extend parameter behaviorSPEC_GAPS.mdfor known OpenAPI spec deficiencies🤖 Prompt for AI agents
Research
The katana-client package provides a TypeScript API client for Katana MRP with 18 resources. Six resources support the
extendparameter (products, materials, variants, purchaseOrders, salesOrderRows, inventory). Currently, extended fields (likesupplier,variant,location) are modeled as permanently optional properties on response interfaces intypes.ts, regardless of whether the caller requests them viaextend. Request schemas insrc/schemas/usez.array(z.enum([...]))to constrain valid extend values. The katana-mcp package consumes katana-client but only uses Zod schemas for input validation and passes responses through without field-level access, minimizing impact from type changes.🚀 Next Steps
🤖 All AI agent prompts combined
💡 Iterate on the plan with:
@coderabbitai <feedback>💬 Have feedback or questions? Drop into our discord!
@coderabbitai one of the issues i'm facing in this is the desire to stick to the published openapi spec. if for nothing else it could perhaps provide a little motivation to katana to update their spec, which is something i've opened more than a couple support tickets on. at the same time, i utilize this library in another project where i rely heavily on the
extendparameter and have to add an undesirable number of workarounds or null coalesces, and i'm sure that other developers will find themselves in a similar situation.I've updated the plan above based on your feedback. Ready to proceed when you are!
addressed in pr #30