Skip to content

fix: correct DocumentType enum, numeric Language, drop empty Payments#14

Merged
BenKalsky merged 1 commit into
mainfrom
feat/document-type-enum-fixes
May 13, 2026
Merged

fix: correct DocumentType enum, numeric Language, drop empty Payments#14
BenKalsky merged 1 commit into
mainfrom
feat/document-type-enum-fixes

Conversation

@BenKalsky
Copy link
Copy Markdown
Member

Summary

Smoke-testing 0.3.0 against the live SUMIT API surfaced four divergences between the helper and what SUMIT actually accepts.

  • DocumentType: SUMIT_DOCUMENT_TYPE.TransactionInvoice = 1 was wrong — code 1 is InvoiceAndReceipt (חשבונית מס-קבלה). The correct value for the pre-payment "חשבון עסקה" is ProformaInvoice = 3. Expanded the constant to cover the full Accounting_Typed_DocumentType enum; kept TransactionInvoice as a deprecated alias.
  • Language: SUMIT rejected Details.Language: "he" with Error converting value "he". It's actually Accounting_Typed_Language — a numeric enum (Hebrew=0, English=1, …). The helper now accepts both numeric codes and the shorthand strings "he"/"en"/"ar"/"es" and converts. New SUMIT_LANGUAGE constant.
  • Payments: SUMIT rejected Payments: [] on document creation. The payload now omits the Payments key.
  • SearchMode: Customer.SearchMode was hardcoded to 0, preventing upserts. Now derived — id1, externalIdentifier2, else 0. Explicit caller value still wins.

Also strips whitespace-only optional fields (emailAddress, phone, taxId, item description, sku, etc.) — SUMIT rejects empty strings on several optional fields.

Test plan

  • pnpm test — 27 passing (9 new for the new behaviors)
  • pnpm typecheck
  • pnpm build
  • Smoke-tested against SUMIT sandbox via Quoty: created a חשבון עסקה successfully with documentType: 3, language: "he" (auto-converted), and externalIdentifier (auto SearchMode=2).

Breaking changes

None for code that passes numeric documentType directly. Code using SUMIT_DOCUMENT_TYPE.TransactionInvoice will keep compiling (alias) but produces the wrong document type — release notes call this out explicitly so consumers update to .ProformaInvoice.

🤖 Generated with Claude Code

Real-world smoke-test against SUMIT's /accounting/documents/create/
surfaced four divergences between 0.3.0 and what SUMIT actually accepts:

1. DocumentType=1 created a חשבונית מס-קבלה (Tax Invoice-Receipt), not
   the pre-payment "חשבון עסקה" we claimed. The correct value for
   ProformaInvoice is 3, per SUMIT's Accounting_Typed_DocumentType enum.
   SUMIT_DOCUMENT_TYPE is now expanded to cover the full enum; the
   incorrect TransactionInvoice=1 constant is retained as a deprecated
   alias for backwards compatibility.

2. Details.Language as a string ("he"/"en") was rejected with:
     "Details.Language: Error converting value \"he\""
   SUMIT's Accounting_Typed_Language is a numeric enum
   (0=Hebrew, 1=English, 2=Arabic, 3=Spanish). The helper now accepts
   either a numeric code or the shorthand strings and converts. New
   SUMIT_LANGUAGE constant exposes the enum.

3. Empty Payments arrays were rejected on document creation. The
   payload now omits the Payments key entirely.

4. Customer.SearchMode was hardcoded to 0, which prevented upserts.
   It's now derived: SUMIT id -> 1, ExternalIdentifier -> 2, else 0.
   Explicit caller value still wins.

Also strips whitespace-only optional fields (emailAddress, phone, taxId,
item description, sku, etc.) — SUMIT rejects empty strings on several
optional fields rather than treating them as absent.

9 new tests; 27 total passing. Zero new runtime dependencies.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@BenKalsky BenKalsky merged commit d3e5604 into main May 13, 2026
1 check passed
@BenKalsky BenKalsky deleted the feat/document-type-enum-fixes branch May 13, 2026 23:41
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 534438e2ad

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/index.ts
// supplied, and 0 (create new) otherwise. Matches SUMIT's documented modes.
const derivedSearchMode: SumitCustomerSearchMode =
params.customer.searchMode ??
(params.customer.id ? 1 : params.customer.externalIdentifier ? 2 : 0);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Derive search mode after trimming blank IDs

When customer.id is a whitespace-only value and externalIdentifier is also present, this truthiness check selects SearchMode: 1, but the later blankToUndefined(params.customer.id) omits ID from the payload. That leaves a request that asks SUMIT to search by ID without sending an ID, so the valid ExternalIdentifier path is not used; this can happen with optional form fields that arrive as spaces, which this change otherwise tries to strip.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant