Include extend response types #29

Closed
opened 2026-03-21 19:51:46 +00:00 by chris-kreidl · 5 comments
chris-kreidl commented 2026-03-21 19:51:46 +00:00 (Migrated from github.com)

For certain resources, Katana accepts an extend parameter. For example: when querying a product one can pass extend: ['supplier'] to have Katana return the default supplier record linked to that product. In the katana-client package, we currently include optional fields for each extend option 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 variant resource accepts extend: ['product_or_material'], which includes a product_or_material value in the response type, which can be either a KatanaProduct or a KatanaMaterial. If that extend parameter 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.

For certain resources, Katana accepts an `extend` parameter. For example: when querying a `product` one can pass `extend: ['supplier']` to have Katana return the default supplier record linked to that product. In the `katana-client` package, we currently include optional fields for each `extend` option 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 `variant` resource accepts `extend: ['product_or_material']`, which includes a `product_or_material` value in the response type, which can be either a `KatanaProduct` or a `KatanaMaterial`. If that `extend` parameter 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.
chris-kreidl commented 2026-03-21 20:07:40 +00:00 (Migrated from github.com)

@coderabbitai plan

@coderabbitai plan
coderabbitai[bot] commented 2026-03-21 20:15:03 +00:00 (Migrated from github.com)

Coding Plan

Summary

  • Introduce TypeScript utility types (WithExtend<Base, ExtendKeys>) that conditionally make extended fields required based on the extend values specified
  • Add function overloads to all six resources that support extend, providing precise return types when callers specify their desired extensions
  • Fix the missing product_or_material field on KatanaVariant to complete type coverage, with inline documentation marking it as a spec gap
  • Create SPEC_GAPS.md to catalog known OpenAPI spec deficiencies for developer reference and support ticket evidence
  • Maintain full backward compatibility—existing code without explicit extend values continues to receive optional fields with zero breaking changes
Design Choices
Design Choice 1: How should we handle the return type when extend is specified vs. omitted?

Options Considered:

  1. Function overloads that return different types based on whether extend is present in params
  2. Generic methods with conditional return types that infer from the extend parameter
  3. Separate method variants (e.g., listWithExtend()) that always return extended types

Chosen 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:

  1. Add product_or_material?: KatanaProduct | KatanaMaterial as a union type
  2. Create a discriminated union with a type field to distinguish product vs material
  3. Add separate product?: KatanaProduct and material?: KatanaMaterial fields

Chosen 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:

  1. Breaking changes that require consumer updates
  2. Additive-only changes that maintain full backward compatibility

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.

  • Create a new section in packages/katana-client/src/types.ts for extend-related utility types
  • Define an ExtendableFields mapped 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)
  • Create a 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 optional
Task 2: Add Missing product_or_material Field to KatanaVariant

Fix the gap where KatanaVariant accepts extend: ["product_or_material"] but lacks the corresponding response field. This is a known deviation from the published OpenAPI spec.

  • Add product_or_material?: KatanaProduct | KatanaMaterial to the KatanaVariant interface in packages/katana-client/src/types.ts
  • Include an inline JSDoc comment marking this as a spec gap (e.g., /** @specGap Katana OpenAPI spec omits this field; added for extend: ['product_or_material'] support */)
  • Position the field alongside similar extended fields for consistency
Task 3: Create Extended Response Type Aliases

Define convenient type aliases for common extended response shapes to simplify overload declarations.

  • In packages/katana-client/src/types.ts, create aliases like KatanaProductWithSupplier, KatanaVariantWithProductOrMaterial, KatanaInventoryItemWithVariant, KatanaInventoryItemWithLocation, KatanaInventoryItemWithBoth
  • These aliases use the WithExtend utility type internally but provide readable names for method signatures
  • Export all new types from src/types.ts (they're already re-exported via src/index.ts)
🤖 Prompt for AI agents
Implement the TypeScript type infrastructure in
`packages/katana-client/src/types.ts` that enables conditional typing based on
`extend` parameter values.

- Add a new section in `packages/katana-client/src/types.ts` for extend-related
utility types:
- Define an `ExtendableFields` mapped type associating extend string literals to
their corresponding interface types:
    - `'supplier' → KatanaSupplier`
    - `'variant' → KatanaProductVariant | KatanaInventoryVariant`
    - `'location' → KatanaLocation`
    - `'product_or_material' → KatanaProduct | KatanaMaterial`
- Create a `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 optional
- Add `product_or_material?: KatanaProduct | KatanaMaterial` to the
`KatanaVariant` interface, positioned alongside similar extended fields
- Include an inline JSDoc comment marking this as a spec gap: `/** @specGap
Katana OpenAPI spec omits this field; added for extend: ['product_or_material']
support */`
- Create the following type aliases using `WithExtend` internally:
  - `KatanaProductWithSupplier`
  - `KatanaVariantWithProductOrMaterial`
  - `KatanaInventoryItemWithVariant`
  - `KatanaInventoryItemWithLocation`
  - `KatanaInventoryItemWithBoth`
- Ensure all new types are exported from `src/types.ts` (already re-exported via
`src/index.ts`, so no changes needed there)

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'.

  • In packages/katana-client/src/resources/products.ts, add overload signatures before the existing list and get method implementations
  • First overload: when params includes extend: ['supplier'], return type uses the extended interface with supplier required
  • Second overload: original signature with optional fields (catches all other cases)
  • The implementation signature remains unchanged—only type declarations are added
  • Import new extended types from ../types
Task 2: Add Overloads to MaterialsResource

Apply the same overload pattern for materials, which also supports extend: ['supplier'].

  • In packages/katana-client/src/resources/materials.ts, add overload signatures for list and get methods
  • Follow identical pattern to products: overload for extend: ['supplier'] returns KatanaMaterialWithSupplier
  • Second overload maintains backward compatibility with optional supplier field
Task 3: Add Overloads to VariantsResource

Implement overloads for the variant resource's product_or_material extension.

  • In packages/katana-client/src/resources/variants.ts, add overload signatures for list and get methods
  • When extend: ['product_or_material'] is specified, return type includes the field as required
  • Import the new KatanaVariantWithProductOrMaterial type
🤖 Prompt for AI agents
Add TypeScript function overloads to the Products, Materials, and Variants
resource files to provide precise return types when callers specify `extend`
parameters. Only type declarations are added — implementation signatures remain
unchanged.

**`packages/katana-client/src/resources/products.ts`:**
- Import new extended types from `../types`
- Before the existing `list` and `get` method implementations, add overload
signatures:
- Overload 1: when params includes `extend: ['supplier']`, return type uses the
extended interface with `supplier` required
- Overload 2: original signature with optional fields (catches all other cases)

**`packages/katana-client/src/resources/materials.ts`:**
- Follow the identical pattern to products
- Overload for `extend: ['supplier']` returns `KatanaMaterialWithSupplier`
- Second overload maintains backward compatibility with optional supplier field

**`packages/katana-client/src/resources/variants.ts`:**
- Import `KatanaVariantWithProductOrMaterial` from `../types`
- Add overload signatures for `list` and `get` methods:
- When `extend: ['product_or_material']` is specified, return type includes the
field as required
  - Fallback overload retains existing optional-field behavior

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.

  • In packages/katana-client/src/resources/salesOrderRows.ts, add overload for list method only (no get method exists)
  • When extend: ['variant'] is specified, return response type with variant as required field
Task 2: Add Overloads to PurchaseOrdersResource

Handle the supplier extension for purchase orders.

  • In packages/katana-client/src/resources/purchaseOrders.ts, add overload for list method only
  • When extend: ['supplier'] is specified, return response type with supplier as required
Task 3: Add Overloads to InventoryResource

Handle inventory's multiple extend options: variant, location, or both.

  • In packages/katana-client/src/resources/inventory.ts, add multiple overloads for the list method
  • Overload 1: extend: ['variant', 'location'] or ['location', 'variant'] returns both fields as required
  • Overload 2: extend: ['variant'] returns variant as required, location optional
  • Overload 3: extend: ['location'] returns location as required, variant optional
  • Overload 4: no extend or other combinations fall back to all optional (existing behavior)
  • Order overloads from most specific to least specific so TypeScript matches correctly
🤖 Prompt for AI agents
Add TypeScript function overloads to the SalesOrderRows, PurchaseOrders, and
Inventory resource files. Only type declarations are added — implementation
signatures remain unchanged.

**`packages/katana-client/src/resources/salesOrderRows.ts`:**
- Add overload for `list` method only (no `get` method exists)
- When `extend: ['variant']` is specified, return response type with `variant`
as required field
- Fallback overload retains existing optional-field behavior

**`packages/katana-client/src/resources/purchaseOrders.ts`:**
- Add overload for `list` method only
- When `extend: ['supplier']` is specified, return response type with `supplier`
as required
- Fallback overload retains existing optional-field behavior

**`packages/katana-client/src/resources/inventory.ts`:**
- Add multiple overloads for the `list` method, ordered from most specific to
least specific so TypeScript matches correctly:
- Overload 1: `extend: ['variant', 'location']` or `['location', 'variant']` →
returns both fields as required (`KatanaInventoryItemWithBoth`)
- Overload 2: `extend: ['variant']` → returns variant as required, location
optional (`KatanaInventoryItemWithVariant`)
- Overload 3: `extend: ['location']` → returns location as required, variant
optional (`KatanaInventoryItemWithLocation`)
- Overload 4: no extend or other combinations → falls back to all optional
(existing behavior)

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.

  • Create packages/katana-client/SPEC_GAPS.md to catalog known spec issues
  • Document the KatanaVariant.product_or_material field omission (extend response field missing from spec)
  • Document that all extend-related response fields are typed as always-optional in the spec despite being guaranteed present when requested
  • Include references to relevant Katana API documentation URLs for each gap
  • Structure the file with sections for each resource affected, making it easy to reference in support tickets
Task 2: Update Type Exports

Verify all new utility types and extended interfaces are properly exported.

  • Review packages/katana-client/src/types.ts exports to ensure all new types are included
  • The barrel export in src/index.ts re-exports from types.ts, so no changes needed there
  • Run pnpm build in katana-client to verify type declarations are generated correctly
Task 3: Add JSDoc Documentation

Document the overloaded methods and new utility types for IDE discoverability.

  • Add JSDoc comments to each overload explaining when that signature applies
  • Document the WithExtend utility type explaining its purpose and usage pattern
  • Add @example tags showing how to use extend for precise return types
  • Use @specGap tag convention for any fields or types that deviate from the published OpenAPI spec
Task 4: Update README with Extend Usage

Add documentation about the improved extend typing to the package README.

  • In packages/katana-client/README.md, add a section explaining the extend parameter behavior
  • Show examples of how passing extend provides precise types vs. omitting it
  • Highlight that this eliminates null coalescing when extend is explicitly specified
  • Reference SPEC_GAPS.md for known OpenAPI spec deficiencies
🤖 Prompt for AI agents
Finalize documentation and verify exports for all new types and overloads across
the katana-client package.

**`packages/katana-client/SPEC_GAPS.md` (new file):**
- Create the file to catalog known OpenAPI spec issues
- Document the `KatanaVariant.product_or_material` field omission (extend
response field missing from spec)
- Document that all extend-related response fields are typed as always-optional
in the spec despite being guaranteed present when requested
- Include references to relevant Katana API documentation URLs for each gap
- Structure with sections per affected resource for easy reference in support
tickets

**Type Exports (`packages/katana-client/src/types.ts`):**
- Review all newly added types and aliases to confirm they are exported
- No changes needed in `src/index.ts` as it already re-exports from `types.ts`
- Run `pnpm build` in katana-client to verify type declarations are generated
correctly

**JSDoc (`packages/katana-client/src/types.ts` and all resource files):**
- Add JSDoc comments to each overload signature explaining when that signature
applies
- Document the `WithExtend` utility type with its purpose and usage pattern
- Add `@example` tags to show how using `extend` yields precise return types
- Use `@specGap` tag convention for any fields or types that deviate from the
published OpenAPI spec

**README (`packages/katana-client/README.md`):**
- Add a new section explaining the `extend` parameter behavior
- Include examples comparing usage with and without `extend`, demonstrating
precise types vs. optional fields
- Highlight that explicitly specifying `extend` eliminates the need for null
coalescing
- Reference `SPEC_GAPS.md` for known OpenAPI spec deficiencies
Research

The katana-client package provides a TypeScript API client for Katana MRP with 18 resources. Six resources support the extend parameter (products, materials, variants, purchaseOrders, salesOrderRows, inventory). Currently, extended fields (like supplier, variant, location) are modeled as permanently optional properties on response interfaces in types.ts, regardless of whether the caller requests them via extend. Request schemas in src/schemas/ use z.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
Task: 1

Implement the TypeScript type infrastructure in
`packages/katana-client/src/types.ts` that enables conditional typing based on
`extend` parameter values.

- Add a new section in `packages/katana-client/src/types.ts` for extend-related
utility types:
- Define an `ExtendableFields` mapped type associating extend string literals to
their corresponding interface types:
    - `'supplier' → KatanaSupplier`
    - `'variant' → KatanaProductVariant | KatanaInventoryVariant`
    - `'location' → KatanaLocation`
    - `'product_or_material' → KatanaProduct | KatanaMaterial`
- Create a `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 optional
- Add `product_or_material?: KatanaProduct | KatanaMaterial` to the
`KatanaVariant` interface, positioned alongside similar extended fields
- Include an inline JSDoc comment marking this as a spec gap: `/** @specGap
Katana OpenAPI spec omits this field; added for extend: ['product_or_material']
support */`
- Create the following type aliases using `WithExtend` internally:
  - `KatanaProductWithSupplier`
  - `KatanaVariantWithProductOrMaterial`
  - `KatanaInventoryItemWithVariant`
  - `KatanaInventoryItemWithLocation`
  - `KatanaInventoryItemWithBoth`
- Ensure all new types are exported from `src/types.ts` (already re-exported via
`src/index.ts`, so no changes needed there)
===============================================================================

Task: 2

Add TypeScript function overloads to the Products, Materials, and Variants
resource files to provide precise return types when callers specify `extend`
parameters. Only type declarations are added — implementation signatures remain
unchanged.

**`packages/katana-client/src/resources/products.ts`:**
- Import new extended types from `../types`
- Before the existing `list` and `get` method implementations, add overload
signatures:
- Overload 1: when params includes `extend: ['supplier']`, return type uses the
extended interface with `supplier` required
- Overload 2: original signature with optional fields (catches all other cases)

**`packages/katana-client/src/resources/materials.ts`:**
- Follow the identical pattern to products
- Overload for `extend: ['supplier']` returns `KatanaMaterialWithSupplier`
- Second overload maintains backward compatibility with optional supplier field

**`packages/katana-client/src/resources/variants.ts`:**
- Import `KatanaVariantWithProductOrMaterial` from `../types`
- Add overload signatures for `list` and `get` methods:
- When `extend: ['product_or_material']` is specified, return type includes the
field as required
  - Fallback overload retains existing optional-field behavior
===============================================================================

Task: 3

Add TypeScript function overloads to the SalesOrderRows, PurchaseOrders, and
Inventory resource files. Only type declarations are added — implementation
signatures remain unchanged.

**`packages/katana-client/src/resources/salesOrderRows.ts`:**
- Add overload for `list` method only (no `get` method exists)
- When `extend: ['variant']` is specified, return response type with `variant`
as required field
- Fallback overload retains existing optional-field behavior

**`packages/katana-client/src/resources/purchaseOrders.ts`:**
- Add overload for `list` method only
- When `extend: ['supplier']` is specified, return response type with `supplier`
as required
- Fallback overload retains existing optional-field behavior

**`packages/katana-client/src/resources/inventory.ts`:**
- Add multiple overloads for the `list` method, ordered from most specific to
least specific so TypeScript matches correctly:
- Overload 1: `extend: ['variant', 'location']` or `['location', 'variant']` →
returns both fields as required (`KatanaInventoryItemWithBoth`)
- Overload 2: `extend: ['variant']` → returns variant as required, location
optional (`KatanaInventoryItemWithVariant`)
- Overload 3: `extend: ['location']` → returns location as required, variant
optional (`KatanaInventoryItemWithLocation`)
- Overload 4: no extend or other combinations → falls back to all optional
(existing behavior)
===============================================================================

Task: 4

Finalize documentation and verify exports for all new types and overloads across
the katana-client package.

**`packages/katana-client/SPEC_GAPS.md` (new file):**
- Create the file to catalog known OpenAPI spec issues
- Document the `KatanaVariant.product_or_material` field omission (extend
response field missing from spec)
- Document that all extend-related response fields are typed as always-optional
in the spec despite being guaranteed present when requested
- Include references to relevant Katana API documentation URLs for each gap
- Structure with sections per affected resource for easy reference in support
tickets

**Type Exports (`packages/katana-client/src/types.ts`):**
- Review all newly added types and aliases to confirm they are exported
- No changes needed in `src/index.ts` as it already re-exports from `types.ts`
- Run `pnpm build` in katana-client to verify type declarations are generated
correctly

**JSDoc (`packages/katana-client/src/types.ts` and all resource files):**
- Add JSDoc comments to each overload signature explaining when that signature
applies
- Document the `WithExtend` utility type with its purpose and usage pattern
- Add `@example` tags to show how using `extend` yields precise return types
- Use `@specGap` tag convention for any fields or types that deviate from the
published OpenAPI spec

**README (`packages/katana-client/README.md`):**
- Add a new section explaining the `extend` parameter behavior
- Include examples comparing usage with and without `extend`, demonstrating
precise types vs. optional fields
- Highlight that explicitly specifying `extend` eliminates the need for null
coalescing
- Reference `SPEC_GAPS.md` for known OpenAPI spec deficiencies
💡 Iterate on the plan with: @coderabbitai <feedback>
Example Feedback
- @coderabbitai You can skip phase 3. Add a simple unit test case for phase 2.
- @coderabbitai For design choice 1 go ahead with option 3 and replan.

💬 Have feedback or questions? Drop into our discord!

<!-- This is an auto-generated reply by CodeRabbit --> ## Coding Plan ### Summary - Introduce TypeScript utility types (`WithExtend<Base, ExtendKeys>`) that conditionally make extended fields required based on the extend values specified - Add function overloads to all six resources that support extend, providing precise return types when callers specify their desired extensions - Fix the missing `product_or_material` field on `KatanaVariant` to complete type coverage, with inline documentation marking it as a spec gap - Create `SPEC_GAPS.md` to catalog known OpenAPI spec deficiencies for developer reference and support ticket evidence - Maintain full backward compatibility—existing code without explicit extend values continues to receive optional fields with zero breaking changes <details> <summary><b>Design Choices</b></summary> <details> <summary><b>Design Choice 1: How should we handle the return type when extend is specified vs. omitted?</b></summary> **Options Considered:** 1. Function overloads that return different types based on whether extend is present in params 2. Generic methods with conditional return types that infer from the extend parameter 3. Separate method variants (e.g., `listWithExtend()`) that always return extended types **Chosen 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. </details> <details> <summary><b>Design Choice 2: How should we model the `product_or_material` union for variants?</b></summary> **Options Considered:** 1. Add `product_or_material?: KatanaProduct | KatanaMaterial` as a union type 2. Create a discriminated union with a `type` field to distinguish product vs material 3. Add separate `product?: KatanaProduct` and `material?: KatanaMaterial` fields **Chosen 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. </details> <details> <summary><b>Design Choice 3: What is the impact on existing consumers of the katana-client package?</b></summary> **Options Considered:** 1. Breaking changes that require consumer updates 2. Additive-only changes that maintain full backward compatibility **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. </details> </details> <b>💡 User Tips</b> 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. <details> <summary><b>Task 1: Create Extend Utility Types</b></summary> Define mapped types that conditionally add required fields based on extend values passed by the caller. - Create a new section in `packages/katana-client/src/types.ts` for extend-related utility types - Define an `ExtendableFields` mapped 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`) - Create a `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 optional </details> <details> <summary><b>Task 2: Add Missing product_or_material Field to KatanaVariant</b></summary> Fix the gap where `KatanaVariant` accepts `extend: ["product_or_material"]` but lacks the corresponding response field. This is a known deviation from the published OpenAPI spec. - Add `product_or_material?: KatanaProduct | KatanaMaterial` to the `KatanaVariant` interface in `packages/katana-client/src/types.ts` - Include an inline JSDoc comment marking this as a spec gap (e.g., `/** @specGap Katana OpenAPI spec omits this field; added for extend: ['product_or_material'] support */`) - Position the field alongside similar extended fields for consistency </details> <details> <summary><b>Task 3: Create Extended Response Type Aliases</b></summary> Define convenient type aliases for common extended response shapes to simplify overload declarations. - In `packages/katana-client/src/types.ts`, create aliases like `KatanaProductWithSupplier`, `KatanaVariantWithProductOrMaterial`, `KatanaInventoryItemWithVariant`, `KatanaInventoryItemWithLocation`, `KatanaInventoryItemWithBoth` - These aliases use the `WithExtend` utility type internally but provide readable names for method signatures - Export all new types from `src/types.ts` (they're already re-exported via `src/index.ts`) </details> <details> <summary><b>🤖 Prompt for AI agents</b></summary> ``` Implement the TypeScript type infrastructure in `packages/katana-client/src/types.ts` that enables conditional typing based on `extend` parameter values. - Add a new section in `packages/katana-client/src/types.ts` for extend-related utility types: - Define an `ExtendableFields` mapped type associating extend string literals to their corresponding interface types: - `'supplier' → KatanaSupplier` - `'variant' → KatanaProductVariant | KatanaInventoryVariant` - `'location' → KatanaLocation` - `'product_or_material' → KatanaProduct | KatanaMaterial` - Create a `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 optional - Add `product_or_material?: KatanaProduct | KatanaMaterial` to the `KatanaVariant` interface, positioned alongside similar extended fields - Include an inline JSDoc comment marking this as a spec gap: `/** @specGap Katana OpenAPI spec omits this field; added for extend: ['product_or_material'] support */` - Create the following type aliases using `WithExtend` internally: - `KatanaProductWithSupplier` - `KatanaVariantWithProductOrMaterial` - `KatanaInventoryItemWithVariant` - `KatanaInventoryItemWithLocation` - `KatanaInventoryItemWithBoth` - Ensure all new types are exported from `src/types.ts` (already re-exported via `src/index.ts`, so no changes needed there) ``` </details> ### 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. <details> <summary><b>Task 1: Add Overloads to ProductsResource</b></summary> Implement overloads for list and get methods that return supplier as required when extend includes `'supplier'`. - In `packages/katana-client/src/resources/products.ts`, add overload signatures before the existing `list` and `get` method implementations - First overload: when params includes `extend: ['supplier']`, return type uses the extended interface with `supplier` required - Second overload: original signature with optional fields (catches all other cases) - The implementation signature remains unchanged—only type declarations are added - Import new extended types from `../types` </details> <details> <summary><b>Task 2: Add Overloads to MaterialsResource</b></summary> Apply the same overload pattern for materials, which also supports `extend: ['supplier']`. - In `packages/katana-client/src/resources/materials.ts`, add overload signatures for `list` and `get` methods - Follow identical pattern to products: overload for `extend: ['supplier']` returns `KatanaMaterialWithSupplier` - Second overload maintains backward compatibility with optional supplier field </details> <details> <summary><b>Task 3: Add Overloads to VariantsResource</b></summary> Implement overloads for the variant resource's product_or_material extension. - In `packages/katana-client/src/resources/variants.ts`, add overload signatures for `list` and `get` methods - When `extend: ['product_or_material']` is specified, return type includes the field as required - Import the new `KatanaVariantWithProductOrMaterial` type </details> <details> <summary><b>🤖 Prompt for AI agents</b></summary> ``` Add TypeScript function overloads to the Products, Materials, and Variants resource files to provide precise return types when callers specify `extend` parameters. Only type declarations are added — implementation signatures remain unchanged. **`packages/katana-client/src/resources/products.ts`:** - Import new extended types from `../types` - Before the existing `list` and `get` method implementations, add overload signatures: - Overload 1: when params includes `extend: ['supplier']`, return type uses the extended interface with `supplier` required - Overload 2: original signature with optional fields (catches all other cases) **`packages/katana-client/src/resources/materials.ts`:** - Follow the identical pattern to products - Overload for `extend: ['supplier']` returns `KatanaMaterialWithSupplier` - Second overload maintains backward compatibility with optional supplier field **`packages/katana-client/src/resources/variants.ts`:** - Import `KatanaVariantWithProductOrMaterial` from `../types` - Add overload signatures for `list` and `get` methods: - When `extend: ['product_or_material']` is specified, return type includes the field as required - Fallback overload retains existing optional-field behavior ``` </details> ### 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. <details> <summary><b>Task 1: Add Overloads to SalesOrderRowsResource</b></summary> Handle the variant extension for sales order rows. - In `packages/katana-client/src/resources/salesOrderRows.ts`, add overload for `list` method only (no get method exists) - When `extend: ['variant']` is specified, return response type with `variant` as required field </details> <details> <summary><b>Task 2: Add Overloads to PurchaseOrdersResource</b></summary> Handle the supplier extension for purchase orders. - In `packages/katana-client/src/resources/purchaseOrders.ts`, add overload for `list` method only - When `extend: ['supplier']` is specified, return response type with `supplier` as required </details> <details> <summary><b>Task 3: Add Overloads to InventoryResource</b></summary> Handle inventory's multiple extend options: variant, location, or both. - In `packages/katana-client/src/resources/inventory.ts`, add multiple overloads for the `list` method - Overload 1: `extend: ['variant', 'location']` or `['location', 'variant']` returns both fields as required - Overload 2: `extend: ['variant']` returns variant as required, location optional - Overload 3: `extend: ['location']` returns location as required, variant optional - Overload 4: no extend or other combinations fall back to all optional (existing behavior) - Order overloads from most specific to least specific so TypeScript matches correctly </details> <details> <summary><b>🤖 Prompt for AI agents</b></summary> ``` Add TypeScript function overloads to the SalesOrderRows, PurchaseOrders, and Inventory resource files. Only type declarations are added — implementation signatures remain unchanged. **`packages/katana-client/src/resources/salesOrderRows.ts`:** - Add overload for `list` method only (no `get` method exists) - When `extend: ['variant']` is specified, return response type with `variant` as required field - Fallback overload retains existing optional-field behavior **`packages/katana-client/src/resources/purchaseOrders.ts`:** - Add overload for `list` method only - When `extend: ['supplier']` is specified, return response type with `supplier` as required - Fallback overload retains existing optional-field behavior **`packages/katana-client/src/resources/inventory.ts`:** - Add multiple overloads for the `list` method, ordered from most specific to least specific so TypeScript matches correctly: - Overload 1: `extend: ['variant', 'location']` or `['location', 'variant']` → returns both fields as required (`KatanaInventoryItemWithBoth`) - Overload 2: `extend: ['variant']` → returns variant as required, location optional (`KatanaInventoryItemWithVariant`) - Overload 3: `extend: ['location']` → returns location as required, variant optional (`KatanaInventoryItemWithLocation`) - Overload 4: no extend or other combinations → falls back to all optional (existing behavior) ``` </details> ### Phase 4: Documentation and Type Exports Ensure the new type-level features are discoverable and properly documented for consumers. <details> <summary><b>Task 1: Create SPEC_GAPS.md</b></summary> Document known OpenAPI spec deficiencies to serve as developer reference and evidence for Katana support tickets. - Create `packages/katana-client/SPEC_GAPS.md` to catalog known spec issues - Document the `KatanaVariant.product_or_material` field omission (extend response field missing from spec) - Document that all extend-related response fields are typed as always-optional in the spec despite being guaranteed present when requested - Include references to relevant Katana API documentation URLs for each gap - Structure the file with sections for each resource affected, making it easy to reference in support tickets </details> <details> <summary><b>Task 2: Update Type Exports</b></summary> Verify all new utility types and extended interfaces are properly exported. - Review `packages/katana-client/src/types.ts` exports to ensure all new types are included - The barrel export in `src/index.ts` re-exports from types.ts, so no changes needed there - Run `pnpm build` in katana-client to verify type declarations are generated correctly </details> <details> <summary><b>Task 3: Add JSDoc Documentation</b></summary> Document the overloaded methods and new utility types for IDE discoverability. - Add JSDoc comments to each overload explaining when that signature applies - Document the `WithExtend` utility type explaining its purpose and usage pattern - Add `@example` tags showing how to use extend for precise return types - Use `@specGap` tag convention for any fields or types that deviate from the published OpenAPI spec </details> <details> <summary><b>Task 4: Update README with Extend Usage</b></summary> Add documentation about the improved extend typing to the package README. - In `packages/katana-client/README.md`, add a section explaining the extend parameter behavior - Show examples of how passing extend provides precise types vs. omitting it - Highlight that this eliminates null coalescing when extend is explicitly specified - Reference `SPEC_GAPS.md` for known OpenAPI spec deficiencies </details> <details> <summary><b>🤖 Prompt for AI agents</b></summary> ``` Finalize documentation and verify exports for all new types and overloads across the katana-client package. **`packages/katana-client/SPEC_GAPS.md` (new file):** - Create the file to catalog known OpenAPI spec issues - Document the `KatanaVariant.product_or_material` field omission (extend response field missing from spec) - Document that all extend-related response fields are typed as always-optional in the spec despite being guaranteed present when requested - Include references to relevant Katana API documentation URLs for each gap - Structure with sections per affected resource for easy reference in support tickets **Type Exports (`packages/katana-client/src/types.ts`):** - Review all newly added types and aliases to confirm they are exported - No changes needed in `src/index.ts` as it already re-exports from `types.ts` - Run `pnpm build` in katana-client to verify type declarations are generated correctly **JSDoc (`packages/katana-client/src/types.ts` and all resource files):** - Add JSDoc comments to each overload signature explaining when that signature applies - Document the `WithExtend` utility type with its purpose and usage pattern - Add `@example` tags to show how using `extend` yields precise return types - Use `@specGap` tag convention for any fields or types that deviate from the published OpenAPI spec **README (`packages/katana-client/README.md`):** - Add a new section explaining the `extend` parameter behavior - Include examples comparing usage with and without `extend`, demonstrating precise types vs. optional fields - Highlight that explicitly specifying `extend` eliminates the need for null coalescing - Reference `SPEC_GAPS.md` for known OpenAPI spec deficiencies ``` </details> <details> <summary><b>Research</b></summary> The katana-client package provides a TypeScript API client for Katana MRP with 18 resources. Six resources support the `extend` parameter (products, materials, variants, purchaseOrders, salesOrderRows, inventory). Currently, extended fields (like `supplier`, `variant`, `location`) are modeled as permanently optional properties on response interfaces in `types.ts`, regardless of whether the caller requests them via `extend`. Request schemas in `src/schemas/` use `z.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. </details> --- ### 🚀 Next Steps <details> <summary><b>🤖 All AI agent prompts combined</b></summary> ``` Task: 1 Implement the TypeScript type infrastructure in `packages/katana-client/src/types.ts` that enables conditional typing based on `extend` parameter values. - Add a new section in `packages/katana-client/src/types.ts` for extend-related utility types: - Define an `ExtendableFields` mapped type associating extend string literals to their corresponding interface types: - `'supplier' → KatanaSupplier` - `'variant' → KatanaProductVariant | KatanaInventoryVariant` - `'location' → KatanaLocation` - `'product_or_material' → KatanaProduct | KatanaMaterial` - Create a `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 optional - Add `product_or_material?: KatanaProduct | KatanaMaterial` to the `KatanaVariant` interface, positioned alongside similar extended fields - Include an inline JSDoc comment marking this as a spec gap: `/** @specGap Katana OpenAPI spec omits this field; added for extend: ['product_or_material'] support */` - Create the following type aliases using `WithExtend` internally: - `KatanaProductWithSupplier` - `KatanaVariantWithProductOrMaterial` - `KatanaInventoryItemWithVariant` - `KatanaInventoryItemWithLocation` - `KatanaInventoryItemWithBoth` - Ensure all new types are exported from `src/types.ts` (already re-exported via `src/index.ts`, so no changes needed there) =============================================================================== Task: 2 Add TypeScript function overloads to the Products, Materials, and Variants resource files to provide precise return types when callers specify `extend` parameters. Only type declarations are added — implementation signatures remain unchanged. **`packages/katana-client/src/resources/products.ts`:** - Import new extended types from `../types` - Before the existing `list` and `get` method implementations, add overload signatures: - Overload 1: when params includes `extend: ['supplier']`, return type uses the extended interface with `supplier` required - Overload 2: original signature with optional fields (catches all other cases) **`packages/katana-client/src/resources/materials.ts`:** - Follow the identical pattern to products - Overload for `extend: ['supplier']` returns `KatanaMaterialWithSupplier` - Second overload maintains backward compatibility with optional supplier field **`packages/katana-client/src/resources/variants.ts`:** - Import `KatanaVariantWithProductOrMaterial` from `../types` - Add overload signatures for `list` and `get` methods: - When `extend: ['product_or_material']` is specified, return type includes the field as required - Fallback overload retains existing optional-field behavior =============================================================================== Task: 3 Add TypeScript function overloads to the SalesOrderRows, PurchaseOrders, and Inventory resource files. Only type declarations are added — implementation signatures remain unchanged. **`packages/katana-client/src/resources/salesOrderRows.ts`:** - Add overload for `list` method only (no `get` method exists) - When `extend: ['variant']` is specified, return response type with `variant` as required field - Fallback overload retains existing optional-field behavior **`packages/katana-client/src/resources/purchaseOrders.ts`:** - Add overload for `list` method only - When `extend: ['supplier']` is specified, return response type with `supplier` as required - Fallback overload retains existing optional-field behavior **`packages/katana-client/src/resources/inventory.ts`:** - Add multiple overloads for the `list` method, ordered from most specific to least specific so TypeScript matches correctly: - Overload 1: `extend: ['variant', 'location']` or `['location', 'variant']` → returns both fields as required (`KatanaInventoryItemWithBoth`) - Overload 2: `extend: ['variant']` → returns variant as required, location optional (`KatanaInventoryItemWithVariant`) - Overload 3: `extend: ['location']` → returns location as required, variant optional (`KatanaInventoryItemWithLocation`) - Overload 4: no extend or other combinations → falls back to all optional (existing behavior) =============================================================================== Task: 4 Finalize documentation and verify exports for all new types and overloads across the katana-client package. **`packages/katana-client/SPEC_GAPS.md` (new file):** - Create the file to catalog known OpenAPI spec issues - Document the `KatanaVariant.product_or_material` field omission (extend response field missing from spec) - Document that all extend-related response fields are typed as always-optional in the spec despite being guaranteed present when requested - Include references to relevant Katana API documentation URLs for each gap - Structure with sections per affected resource for easy reference in support tickets **Type Exports (`packages/katana-client/src/types.ts`):** - Review all newly added types and aliases to confirm they are exported - No changes needed in `src/index.ts` as it already re-exports from `types.ts` - Run `pnpm build` in katana-client to verify type declarations are generated correctly **JSDoc (`packages/katana-client/src/types.ts` and all resource files):** - Add JSDoc comments to each overload signature explaining when that signature applies - Document the `WithExtend` utility type with its purpose and usage pattern - Add `@example` tags to show how using `extend` yields precise return types - Use `@specGap` tag convention for any fields or types that deviate from the published OpenAPI spec **README (`packages/katana-client/README.md`):** - Add a new section explaining the `extend` parameter behavior - Include examples comparing usage with and without `extend`, demonstrating precise types vs. optional fields - Highlight that explicitly specifying `extend` eliminates the need for null coalescing - Reference `SPEC_GAPS.md` for known OpenAPI spec deficiencies ``` </details> <details> <summary><b>💡 Iterate on the plan with: <code>@coderabbitai &lt;feedback&gt;</code> </b></summary> ``` Example Feedback - @coderabbitai You can skip phase 3. Add a simple unit test case for phase 2. - @coderabbitai For design choice 1 go ahead with option 3 and replan. ``` </details> --- 💬 Have feedback or questions? Drop into our [discord](https://discord.gg/coderabbit)! <!-- <agentComponentType>plan-edits</agentComponentType> --> <!-- <rawResChunk><planningResult>## Coding Plan ### Summary - Introduce TypeScript utility types (`WithExtend<Base, ExtendKeys>`) that conditionally make extended fields required based on the extend values specified - Add function overloads to all six resources that support extend, providing precise return types when callers specify their desired extensions - Fix the missing `product_or_material` field on `KatanaVariant` to complete type coverage, with inline documentation marking it as a spec gap - Create `SPEC_GAPS.md` to catalog known OpenAPI spec deficiencies for developer reference and support ticket evidence - Maintain full backward compatibility—existing code without explicit extend values continues to receive optional fields with zero breaking changes <details> <summary><b>Design Choices</b></summary> <details> <summary><b>Design Choice 1: How should we handle the return type when extend is specified vs. omitted?</b></summary> **Options Considered:** 1. Function overloads that return different types based on whether extend is present in params 2. Generic methods with conditional return types that infer from the extend parameter 3. Separate method variants (e.g., `listWithExtend()`) that always return extended types **Chosen 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. </details> <details> <summary><b>Design Choice 2: How should we model the `product_or_material` union for variants?</b></summary> **Options Considered:** 1. Add `product_or_material?: KatanaProduct | KatanaMaterial` as a union type 2. Create a discriminated union with a `type` field to distinguish product vs material 3. Add separate `product?: KatanaProduct` and `material?: KatanaMaterial` fields **Chosen 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. </details> <details> <summary><b>Design Choice 3: What is the impact on existing consumers of the katana-client package?</b></summary> **Options Considered:** 1. Breaking changes that require consumer updates 2. Additive-only changes that maintain full backward compatibility **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. </details> </details> <b>💡 User Tips</b> 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. <details> <summary><b>Task 1: Create Extend Utility Types</b></summary> Define mapped types that conditionally add required fields based on extend values passed by the caller. - Create a new section in `packages/katana-client/src/types.ts` for extend-related utility types - Define an `ExtendableFields` mapped 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`) - Create a `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 optional </details> <details> <summary><b>Task 2: Add Missing product_or_material Field to KatanaVariant</b></summary> Fix the gap where `KatanaVariant` accepts `extend: ["product_or_material"]` but lacks the corresponding response field. This is a known deviation from the published OpenAPI spec. - Add `product_or_material?: KatanaProduct | KatanaMaterial` to the `KatanaVariant` interface in `packages/katana-client/src/types.ts` - Include an inline JSDoc comment marking this as a spec gap (e.g., `/** @specGap Katana OpenAPI spec omits this field; added for extend: ['product_or_material'] support */`) - Position the field alongside similar extended fields for consistency </details> <details> <summary><b>Task 3: Create Extended Response Type Aliases</b></summary> Define convenient type aliases for common extended response shapes to simplify overload declarations. - In `packages/katana-client/src/types.ts`, create aliases like `KatanaProductWithSupplier`, `KatanaVariantWithProductOrMaterial`, `KatanaInventoryItemWithVariant`, `KatanaInventoryItemWithLocation`, `KatanaInventoryItemWithBoth` - These aliases use the `WithExtend` utility type internally but provide readable names for method signatures - Export all new types from `src/types.ts` (they're already re-exported via `src/index.ts`) </details> <details> <summary><b>🤖 Prompt for AI agents</b></summary> ``` Implement the TypeScript type infrastructure in `packages/katana-client/src/types.ts` that enables conditional typing based on `extend` parameter values. - Add a new section in `packages/katana-client/src/types.ts` for extend-related utility types: - Define an `ExtendableFields` mapped type associating extend string literals to their corresponding interface types: - `'supplier' → KatanaSupplier` - `'variant' → KatanaProductVariant | KatanaInventoryVariant` - `'location' → KatanaLocation` - `'product_or_material' → KatanaProduct | KatanaMaterial` - Create a `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 optional - Add `product_or_material?: KatanaProduct | KatanaMaterial` to the `KatanaVariant` interface, positioned alongside similar extended fields - Include an inline JSDoc comment marking this as a spec gap: `/** @specGap Katana OpenAPI spec omits this field; added for extend: ['product_or_material'] support */` - Create the following type aliases using `WithExtend` internally: - `KatanaProductWithSupplier` - `KatanaVariantWithProductOrMaterial` - `KatanaInventoryItemWithVariant` - `KatanaInventoryItemWithLocation` - `KatanaInventoryItemWithBoth` - Ensure all new types are exported from `src/types.ts` (already re-exported via `src/index.ts`, so no changes needed there) ``` </details> ### 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. <details> <summary><b>Task 1: Add Overloads to ProductsResource</b></summary> Implement overloads for list and get methods that return supplier as required when extend includes `'supplier'`. - In `packages/katana-client/src/resources/products.ts`, add overload signatures before the existing `list` and `get` method implementations - First overload: when params includes `extend: ['supplier']`, return type uses the extended interface with `supplier` required - Second overload: original signature with optional fields (catches all other cases) - The implementation signature remains unchanged—only type declarations are added - Import new extended types from `../types` </details> <details> <summary><b>Task 2: Add Overloads to MaterialsResource</b></summary> Apply the same overload pattern for materials, which also supports `extend: ['supplier']`. - In `packages/katana-client/src/resources/materials.ts`, add overload signatures for `list` and `get` methods - Follow identical pattern to products: overload for `extend: ['supplier']` returns `KatanaMaterialWithSupplier` - Second overload maintains backward compatibility with optional supplier field </details> <details> <summary><b>Task 3: Add Overloads to VariantsResource</b></summary> Implement overloads for the variant resource's product_or_material extension. - In `packages/katana-client/src/resources/variants.ts`, add overload signatures for `list` and `get` methods - When `extend: ['product_or_material']` is specified, return type includes the field as required - Import the new `KatanaVariantWithProductOrMaterial` type </details> <details> <summary><b>🤖 Prompt for AI agents</b></summary> ``` Add TypeScript function overloads to the Products, Materials, and Variants resource files to provide precise return types when callers specify `extend` parameters. Only type declarations are added — implementation signatures remain unchanged. **`packages/katana-client/src/resources/products.ts`:** - Import new extended types from `../types` - Before the existing `list` and `get` method implementations, add overload signatures: - Overload 1: when params includes `extend: ['supplier']`, return type uses the extended interface with `supplier` required - Overload 2: original signature with optional fields (catches all other cases) **`packages/katana-client/src/resources/materials.ts`:** - Follow the identical pattern to products - Overload for `extend: ['supplier']` returns `KatanaMaterialWithSupplier` - Second overload maintains backward compatibility with optional supplier field **`packages/katana-client/src/resources/variants.ts`:** - Import `KatanaVariantWithProductOrMaterial` from `../types` - Add overload signatures for `list` and `get` methods: - When `extend: ['product_or_material']` is specified, return type includes the field as required - Fallback overload retains existing optional-field behavior ``` </details> ### 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. <details> <summary><b>Task 1: Add Overloads to SalesOrderRowsResource</b></summary> Handle the variant extension for sales order rows. - In `packages/katana-client/src/resources/salesOrderRows.ts`, add overload for `list` method only (no get method exists) - When `extend: ['variant']` is specified, return response type with `variant` as required field </details> <details> <summary><b>Task 2: Add Overloads to PurchaseOrdersResource</b></summary> Handle the supplier extension for purchase orders. - In `packages/katana-client/src/resources/purchaseOrders.ts`, add overload for `list` method only - When `extend: ['supplier']` is specified, return response type with `supplier` as required </details> <details> <summary><b>Task 3: Add Overloads to InventoryResource</b></summary> Handle inventory's multiple extend options: variant, location, or both. - In `packages/katana-client/src/resources/inventory.ts`, add multiple overloads for the `list` method - Overload 1: `extend: ['variant', 'location']` or `['location', 'variant']` returns both fields as required - Overload 2: `extend: ['variant']` returns variant as required, location optional - Overload 3: `extend: ['location']` returns location as required, variant optional - Overload 4: no extend or other combinations fall back to all optional (existing behavior) - Order overloads from most specific to least specific so TypeScript matches correctly </details> <details> <summary><b>🤖 Prompt for AI agents</b></summary> ``` Add TypeScript function overloads to the SalesOrderRows, PurchaseOrders, and Inventory resource files. Only type declarations are added — implementation signatures remain unchanged. **`packages/katana-client/src/resources/salesOrderRows.ts`:** - Add overload for `list` method only (no `get` method exists) - When `extend: ['variant']` is specified, return response type with `variant` as required field - Fallback overload retains existing optional-field behavior **`packages/katana-client/src/resources/purchaseOrders.ts`:** - Add overload for `list` method only - When `extend: ['supplier']` is specified, return response type with `supplier` as required - Fallback overload retains existing optional-field behavior **`packages/katana-client/src/resources/inventory.ts`:** - Add multiple overloads for the `list` method, ordered from most specific to least specific so TypeScript matches correctly: - Overload 1: `extend: ['variant', 'location']` or `['location', 'variant']` → returns both fields as required (`KatanaInventoryItemWithBoth`) - Overload 2: `extend: ['variant']` → returns variant as required, location optional (`KatanaInventoryItemWithVariant`) - Overload 3: `extend: ['location']` → returns location as required, variant optional (`KatanaInventoryItemWithLocation`) - Overload 4: no extend or other combinations → falls back to all optional (existing behavior) ``` </details> ### Phase 4: Documentation and Type Exports Ensure the new type-level features are discoverable and properly documented for consumers. <details> <summary><b>Task 1: Create SPEC_GAPS.md</b></summary> Document known OpenAPI spec deficiencies to serve as developer reference and evidence for Katana support tickets. - Create `packages/katana-client/SPEC_GAPS.md` to catalog known spec issues - Document the `KatanaVariant.product_or_material` field omission (extend response field missing from spec) - Document that all extend-related response fields are typed as always-optional in the spec despite being guaranteed present when requested - Include references to relevant Katana API documentation URLs for each gap - Structure the file with sections for each resource affected, making it easy to reference in support tickets </details> <details> <summary><b>Task 2: Update Type Exports</b></summary> Verify all new utility types and extended interfaces are properly exported. - Review `packages/katana-client/src/types.ts` exports to ensure all new types are included - The barrel export in `src/index.ts` re-exports from types.ts, so no changes needed there - Run `pnpm build` in katana-client to verify type declarations are generated correctly </details> <details> <summary><b>Task 3: Add JSDoc Documentation</b></summary> Document the overloaded methods and new utility types for IDE discoverability. - Add JSDoc comments to each overload explaining when that signature applies - Document the `WithExtend` utility type explaining its purpose and usage pattern - Add `@example` tags showing how to use extend for precise return types - Use `@specGap` tag convention for any fields or types that deviate from the published OpenAPI spec </details> <details> <summary><b>Task 4: Update README with Extend Usage</b></summary> Add documentation about the improved extend typing to the package README. - In `packages/katana-client/README.md`, add a section explaining the extend parameter behavior - Show examples of how passing extend provides precise types vs. omitting it - Highlight that this eliminates null coalescing when extend is explicitly specified - Reference `SPEC_GAPS.md` for known OpenAPI spec deficiencies </details> <details> <summary><b>🤖 Prompt for AI agents</b></summary> ``` Finalize documentation and verify exports for all new types and overloads across the katana-client package. **`packages/katana-client/SPEC_GAPS.md` (new file):** - Create the file to catalog known OpenAPI spec issues - Document the `KatanaVariant.product_or_material` field omission (extend response field missing from spec) - Document that all extend-related response fields are typed as always-optional in the spec despite being guaranteed present when requested - Include references to relevant Katana API documentation URLs for each gap - Structure with sections per affected resource for easy reference in support tickets **Type Exports (`packages/katana-client/src/types.ts`):** - Review all newly added types and aliases to confirm they are exported - No changes needed in `src/index.ts` as it already re-exports from `types.ts` - Run `pnpm build` in katana-client to verify type declarations are generated correctly **JSDoc (`packages/katana-client/src/types.ts` and all resource files):** - Add JSDoc comments to each overload signature explaining when that signature applies - Document the `WithExtend` utility type with its purpose and usage pattern - Add `@example` tags to show how using `extend` yields precise return types - Use `@specGap` tag convention for any fields or types that deviate from the published OpenAPI spec **README (`packages/katana-client/README.md`):** - Add a new section explaining the `extend` parameter behavior - Include examples comparing usage with and without `extend`, demonstrating precise types vs. optional fields - Highlight that explicitly specifying `extend` eliminates the need for null coalescing - Reference `SPEC_GAPS.md` for known OpenAPI spec deficiencies ``` </details> <details> <summary><b>Research</b></summary> The katana-client package provides a TypeScript API client for Katana MRP with 18 resources. Six resources support the `extend` parameter (products, materials, variants, purchaseOrders, salesOrderRows, inventory). Currently, extended fields (like `supplier`, `variant`, `location`) are modeled as permanently optional properties on response interfaces in `types.ts`, regardless of whether the caller requests them via `extend`. Request schemas in `src/schemas/` use `z.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. </details> --- ### 🚀 Next Steps <details> <summary><b>🤖 All AI agent prompts combined</b></summary> ``` Task: 1 Implement the TypeScript type infrastructure in `packages/katana-client/src/types.ts` that enables conditional typing based on `extend` parameter values. - Add a new section in `packages/katana-client/src/types.ts` for extend-related utility types: - Define an `ExtendableFields` mapped type associating extend string literals to their corresponding interface types: - `'supplier' → KatanaSupplier` - `'variant' → KatanaProductVariant | KatanaInventoryVariant` - `'location' → KatanaLocation` - `'product_or_material' → KatanaProduct | KatanaMaterial` - Create a `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 optional - Add `product_or_material?: KatanaProduct | KatanaMaterial` to the `KatanaVariant` interface, positioned alongside similar extended fields - Include an inline JSDoc comment marking this as a spec gap: `/** @specGap Katana OpenAPI spec omits this field; added for extend: ['product_or_material'] support */` - Create the following type aliases using `WithExtend` internally: - `KatanaProductWithSupplier` - `KatanaVariantWithProductOrMaterial` - `KatanaInventoryItemWithVariant` - `KatanaInventoryItemWithLocation` - `KatanaInventoryItemWithBoth` - Ensure all new types are exported from `src/types.ts` (already re-exported via `src/index.ts`, so no changes needed there) =============================================================================== Task: 2 Add TypeScript function overloads to the Products, Materials, and Variants resource files to provide precise return types when callers specify `extend` parameters. Only type declarations are added — implementation signatures remain unchanged. **`packages/katana-client/src/resources/products.ts`:** - Import new extended types from `../types` - Before the existing `list` and `get` method implementations, add overload signatures: - Overload 1: when params includes `extend: ['supplier']`, return type uses the extended interface with `supplier` required - Overload 2: original signature with optional fields (catches all other cases) **`packages/katana-client/src/resources/materials.ts`:** - Follow the identical pattern to products - Overload for `extend: ['supplier']` returns `KatanaMaterialWithSupplier` - Second overload maintains backward compatibility with optional supplier field **`packages/katana-client/src/resources/variants.ts`:** - Import `KatanaVariantWithProductOrMaterial` from `../types` - Add overload signatures for `list` and `get` methods: - When `extend: ['product_or_material']` is specified, return type includes the field as required - Fallback overload retains existing optional-field behavior =============================================================================== Task: 3 Add TypeScript function overloads to the SalesOrderRows, PurchaseOrders, and Inventory resource files. Only type declarations are added — implementation signatures remain unchanged. **`packages/katana-client/src/resources/salesOrderRows.ts`:** - Add overload for `list` method only (no `get` method exists) - When `extend: ['variant']` is specified, return response type with `variant` as required field - Fallback overload retains existing optional-field behavior **`packages/katana-client/src/resources/purchaseOrders.ts`:** - Add overload for `list` method only - When `extend: ['supplier']` is specified, return response type with `supplier` as required - Fallback overload retains existing optional-field behavior **`packages/katana-client/src/resources/inventory.ts`:** - Add multiple overloads for the `list` method, ordered from most specific to least specific so TypeScript matches correctly: - Overload 1: `extend: ['variant', 'location']` or `['location', 'variant']` → returns both fields as required (`KatanaInventoryItemWithBoth`) - Overload 2: `extend: ['variant']` → returns variant as required, location optional (`KatanaInventoryItemWithVariant`) - Overload 3: `extend: ['location']` → returns location as required, variant optional (`KatanaInventoryItemWithLocation`) - Overload 4: no extend or other combinations → falls back to all optional (existing behavior) =============================================================================== Task: 4 Finalize documentation and verify exports for all new types and overloads across the katana-client package. **`packages/katana-client/SPEC_GAPS.md` (new file):** - Create the file to catalog known OpenAPI spec issues - Document the `KatanaVariant.product_or_material` field omission (extend response field missing from spec) - Document that all extend-related response fields are typed as always-optional in the spec despite being guaranteed present when requested - Include references to relevant Katana API documentation URLs for each gap - Structure with sections per affected resource for easy reference in support tickets **Type Exports (`packages/katana-client/src/types.ts`):** - Review all newly added types and aliases to confirm they are exported - No changes needed in `src/index.ts` as it already re-exports from `types.ts` - Run `pnpm build` in katana-client to verify type declarations are generated correctly **JSDoc (`packages/katana-client/src/types.ts` and all resource files):** - Add JSDoc comments to each overload signature explaining when that signature applies - Document the `WithExtend` utility type with its purpose and usage pattern - Add `@example` tags to show how using `extend` yields precise return types - Use `@specGap` tag convention for any fields or types that deviate from the published OpenAPI spec **README (`packages/katana-client/README.md`):** - Add a new section explaining the `extend` parameter behavior - Include examples comparing usage with and without `extend`, demonstrating precise types vs. optional fields - Highlight that explicitly specifying `extend` eliminates the need for null coalescing - Reference `SPEC_GAPS.md` for known OpenAPI spec deficiencies ``` </details> <details> <summary><b>💡 Iterate on the plan with: <code>@coderabbitai &lt;feedback&gt;</code> </b></summary> ``` Example Feedback - @coderabbitai You can skip phase 3. Add a simple unit test case for phase 2. - @coderabbitai For design choice 1 go ahead with option 3 and replan. ``` </details> --- 💬 Have feedback or questions? Drop into our [discord](https://discord.gg/coderabbit)!</planningResult></rawResChunk> --> <!-- <agentComponentType>plan-edits</agentComponentType> -->
chris-kreidl commented 2026-03-21 20:25:33 +00:00 (Migrated from github.com)

@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 extend parameter 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.

@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 `extend` parameter 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.
coderabbitai[bot] commented 2026-03-21 20:28:16 +00:00 (Migrated from github.com)

I've updated the plan above based on your feedback. Ready to proceed when you are!

<!-- This is an auto-generated reply by CodeRabbit --> I've updated the plan above based on your feedback. Ready to proceed when you are!
chris-kreidl commented 2026-03-21 22:41:00 +00:00 (Migrated from github.com)

addressed in pr #30

addressed in pr #30
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
ckreidl/katanatools#29
No description provided.