Skip to content

feat(amego): amegoErrorHint() — merchant-actionable guidance for account-level errors#1

Merged
linyiru merged 2 commits into
mainfrom
amego-error-hints
Jul 7, 2026
Merged

feat(amego): amegoErrorHint() — merchant-actionable guidance for account-level errors#1
linyiru merged 2 commits into
mainfrom
amego-error-hints

Conversation

@linyiru

@linyiru linyiru commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

What

  • amegoErrorHint(rawCode | InvoiceError): string | undefined (new, @paid-tw/einvoice-amego): translates Amego's account/setup-level raw error codes into display-ready zh-TW guidance — the codes where only the merchant can act in the Amego backend, and where the terse original message (「IP 錯誤」) doesn't say what to do.
    • Account & API-access setup: 12 13 14 16 19 22
    • Transient Amego-side: 10 15 18 21 (→ 稍後再試)
    • 字軌用罄: 3040111 3040191
    • Everything else → undefined (callers fall back to error.message)
  • fix: unrun devDependency — tsdown 0.22 loads tsdown.config.ts via its optional peer unrun; a fresh pnpm install never provides it, so every package's build failed on a clean checkout.

Why

Integrating this SDK into Recur, a real merchant's key kept failing validation with the generic AUTH message. The actual cause was rawCode 14 — an IP allowlist configured in the Amego backend, which unconditionally rejects cloud egress IPs (verified live 2026-07). Neither 14 nor 22 (API access not enabled) is guessable by the merchant from the raw message; every integrator will end up hand-rolling this same table.

Verification

pnpm build && pnpm typecheck && pnpm lint && pnpm format:check && pnpm test all green (750 passed; 7 new tests in hints.test.ts covering code lookup, numeric codes, InvoiceError extraction, foreign-provider rejection, and business-code exclusions). READMEs (zh + en) + changeset (minor) included.

linyiru added 2 commits July 6, 2026 19:01
…nstalls

tsdown 0.22 loads tsdown.config.ts via its optional peer "unrun", which a
fresh pnpm install never provides — every package's build died with
'Failed to import module "unrun"' on a clean checkout (and typecheck
cascaded into missing-dist errors). Declare it explicitly.
…unt-level errors

Amego's setup-level failures (IP allowlist 14, API access not enabled 22,
bad App Key 16, UBN mismatch 12, account inactive/suspended 13/19),
transient provider-side codes (10/15/18/21), and number-track exhaustion
(3040111/3040191) all require the merchant to act in the Amego backend —
but rawCode + the terse original message ('IP 錯誤') don't say what to do.
amegoErrorHint() maps them to display-ready zh-TW guidance; everything
else returns undefined so callers fall back to error.message. Accepts a
raw code or an InvoiceError (isInvoiceError-guarded, amego-only).

Code 14 behavior verified against a real merchant account: an Amego-side
IP allowlist rejects cloud egress IPs unconditionally (2026-07).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds an Amego-specific helper to translate a small, curated set of account/setup-level Amego raw error codes into merchant-actionable zh-TW hints, and fixes clean-checkout builds by adding unrun as a devDependency required by tsdown’s config loading.

Changes:

  • Add amegoErrorHint() with a focused raw-code → zh-TW guidance table for merchant-actionable Amego account/setup and transient provider-side errors.
  • Export the new helper from @paid-tw/einvoice-amego and add a dedicated vitest suite covering expected behaviors and exclusions.
  • Add unrun to root devDependencies and update the lockfile to unblock tsdown builds on clean installs; update READMEs and add a changeset for a minor release.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pnpm-lock.yaml Adds unrun@0.3.1 to the lockfile and wires it into the tsdown snapshot.
packages/einvoice-amego/src/index.ts Exports amegoErrorHint from the package entrypoint.
packages/einvoice-amego/src/hints.ts Implements the hint table and amegoErrorHint() lookup + InvoiceError extraction/guarding.
packages/einvoice-amego/src/hints.test.ts Adds tests for code lookup, numeric codes, InvoiceError extraction, provider filtering, and exclusions.
packages/einvoice-amego/README.md Documents opt-in error hints usage and covered codes in zh-TW.
packages/einvoice-amego/README.en.md Documents opt-in error hints usage and covered codes in English.
package.json Adds unrun to root devDependencies to satisfy tsdown’s optional peer usage.
.changeset/amego-error-hints.md Adds a minor changeset describing the new API and its behavior.
Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@linyiru linyiru merged commit 72f4669 into main Jul 7, 2026
5 checks passed
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.

2 participants