Skip to content

feat/fedex customer references full support#1089

Merged
danh91 merged 3 commits into
karrioapi:mainfrom
saunders-book-co:feat/fedex-customer-references-full-support
Jun 23, 2026
Merged

feat/fedex customer references full support#1089
danh91 merged 3 commits into
karrioapi:mainfrom
saunders-book-co:feat/fedex-customer-references-full-support

Conversation

@ChrisNolan

Copy link
Copy Markdown
Contributor

This change expands FedEx shipment customerReferences support from a single hardcoded invoice reference to full multi-type handling.

What changed

  • Added FedEx customer reference builders in provider utils and wired them into shipment request creation.
  • Implemented reference mapping for:
    • CUSTOMER_REFERENCE (from shipment reference)
    • INVOICE_NUMBER (from customs invoice, with options fallback)
    • DEPARTMENT_NUMBER (from options)
    • P_O_NUMBER (from options)
    • RMA_ASSOCIATION (from options)
  • Applied FedEx length constraints per reference type (including conservative CUSTOMER_REFERENCE limit for Ground compatibility).
  • Removed incorrect PO mapping from package reference values.

What is now available (was not before)

  • FedEx requests now send multiple valid customer reference types in the correct shipment sections (commercial invoice and package line items), instead of only a hardcoded invoice reference.
  • API callers can now populate FedEx-specific references via shipment options (for example fedex_po_number, fedex_department_number, fedex_rma_association) and have them forwarded to FedEx correctly.
  • Added focused unit coverage for reference construction/collection plus regression validation in FedEx shipment tests.

@vercel

vercel Bot commented May 21, 2026

Copy link
Copy Markdown

@ChrisNolan is attempting to deploy a commit to the karrio Team on Vercel.

A member of the Team first needs to authorize it.

@ChrisNolan ChrisNolan force-pushed the feat/fedex-customer-references-full-support branch from 70c110f to 1db4e8b Compare May 21, 2026 15:45
@andersonvom

Copy link
Copy Markdown

This is great! I was about to put together a PR to address this very issue, but you beat me to it 🥳

@zebradots

Copy link
Copy Markdown
Contributor

Also about to submit a PR for this same functionality, but glad to see it's already been done!

@danh91

danh91 commented Jun 23, 2026

Copy link
Copy Markdown
Member

Reviewed — looks good, approving. Thanks @ChrisNolan — this fixes the long-standing REF-field gap (#1082) and the test coverage is excellent.

We're going to apply some cleanups in the release branch (2026.1.32) to bring it in line with karrio conventions, and I'll leave inline notes on the specific spots. In short: build the customerReferences lists inline in the request tree (the lib.identity(...) / comprehension idiom UPS and FedEx already use) instead of a collect_customer_references helper that returns a keyed dict and gets called twice, and declare the new reference inputs as proper OptionEnums in units.py rather than raw payload.options lookups. Same behavior, your fixtures still pass.

Merging so it ships in 2026.1.32.

@danh91 danh91 merged commit 4851c79 into karrioapi:main Jun 23, 2026
1 of 3 checks passed
danh91 added a commit that referenced this pull request Jun 23, 2026
…1089)

Cleanup of the merged #1089 to fit karrio conventions:
- Build the customerReferences lists inline in the request tree (the
  lib.identity / comprehension idiom used by UPS + the rest of FedEx) instead
  of a collect_customer_references() helper that returned a keyed dict and was
  called twice per request.
- Declare fedex_department_number / fedex_po_number / fedex_rma_association as
  proper OptionEnums (+ i18n) so they're accessed via options.* and surface in
  the schema, instead of raw payload.options dict lookups with dual spellings.
- Remove now-dead helpers (build_customer_reference, collect_customer_references,
  CUSTOMER_REFERENCE_MAX_LENGTH) and their imports from utils.py.
- Replace the mock-based helper unit tests (test_utils.py) with a request-level
  assertion in test_shipment.py; the canonical full-dict tests already cover
  INVOICE_NUMBER + CUSTOMER_REFERENCE output.

Serialized output unchanged (51 fedex tests pass).
danh91 added a commit that referenced this pull request Jun 23, 2026
…1089)

Cleanup of the merged #1089 to fit karrio conventions:
- Build the customerReferences lists inline in the request tree (the
  lib.identity / comprehension idiom used by UPS + the rest of FedEx) instead
  of a collect_customer_references() helper that returned a keyed dict and was
  called twice per request.
- Declare fedex_department_number / fedex_po_number / fedex_rma_association as
  proper OptionEnums (+ i18n) so they're accessed via options.* and surface in
  the schema, instead of raw payload.options dict lookups with dual spellings.
- Remove now-dead helpers (build_customer_reference, collect_customer_references,
  CUSTOMER_REFERENCE_MAX_LENGTH) and their imports from utils.py.
- Replace the mock-based helper unit tests (test_utils.py) with a request-level
  assertion in test_shipment.py; the canonical full-dict tests already cover
  INVOICE_NUMBER + CUSTOMER_REFERENCE output.

Serialized output unchanged (51 fedex tests pass).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Cleanup applied in the 2026.1.32 release branch (patch/2026.1.32): build_customer_reference and collect_customer_references were removed from here.

Why: karrio builds the request tree inline at the call site (see UPS ReferenceNumber and the rest of FedEx's create.py). A helper that returns a {commercial_invoice, package} dict — and is called twice per shipment (once per key) — adds indirection without reuse value, and indexing it by string key is the opposite of inline-tree construction. The per-type length limits are now applied inline via lib.text(value, max=30|20).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In the release branch both collect_customer_references(...)["..."] calls are now built inline in the request tree as [_ref for _ref in [fedex.CustomerReferenceType(...), ...] if _ref.value] — computed once per site, and each site shows exactly which references it includes.

Also: fedex_department_number, fedex_po_number and fedex_rma_association are now declared as OptionEnums in units.py (with i18n), so they're read via options.<name>.state and surface in the schema — instead of raw payload.options.get("fedex_x") or .get("x") lookups with dual key spellings.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Removed in the release branch along with the helpers it covered. These also used mock.MagicMock() for payload/customs/options, whereas karrio tests drive gateway.mapper and assert the serialized request. Coverage is now a request-level test (test_shipment.py::test_create_shipment_request_with_customer_references) plus the canonical full-dict tests, which already assert INVOICE_NUMBER + CUSTOMER_REFERENCE output. Thanks for the thorough original coverage — much appreciated.

danh91 added a commit that referenced this pull request Jun 23, 2026
#1096, #1120, #1095, #1089, #1114, #1118 were merged directly to main by
mistake — they belong on the 2026.1.32 release branch (#1128), where the same
changes already live (cherry-picks + conventions cleanups). No work is lost;
this only removes their effect from main. They will reach main via #1128.
danh91 added a commit that referenced this pull request Jun 23, 2026
…ovements

- pickupType settable via the fedex_pickup_type shipping option, typed with the
  FedExPickupType enum (#1095, @ChrisNolan).
- full multi-type customerReferences (CUSTOMER_REFERENCE/INVOICE_NUMBER/
  DEPARTMENT_NUMBER/P_O_NUMBER/RMA_ASSOCIATION), built inline in the request
  tree; fixes the REF field on labels (#1089, @ChrisNolan; disc #1082).
- pickup: map instruction -> remarks, type fedex_pickup_address_type as an enum
  option, resolve package_location via the FedExPackageLocation enum (#1114,
  @ChrisNolan). Multi-recipient notification emails deferred (EBE-124).
danh91 added a commit that referenced this pull request Jun 23, 2026
…es (#1128)

* fix(server): critical ops + security fixes for 2026.1.32

- providers: guard migration 0093 against cascade data-loss (#1116) — depend on
  manager/0079 so carrier FK columns are dropped before the legacy carrier delete.
- manager: make migration 0078 production-safe — chunked iterator + bulk_update,
  idempotent (#1123).
- events: batch periodic_data_archiving deletes to avoid first-run OOM (#1125).
- settings: import workers before apm so huey binds REDIS_HOST under OTEL (#1124).
- settings: scope MD5 PASSWORD_HASHERS to the test runner only (#1096, @mgradalska).
- core: clean up async DB connections to stop the tracing connection leak
  (#1119/#1120 phase 1, @ChrisNolan) + phase-2 PRD.

* fix(usps): correct v3 API hosts + vendor official OpenAPI specs

- usps + usps_international: update server URLs to apis.usps.com / apis-tem.usps.com
  after USPS retired the legacy Web Tools / api-cat hosts (#1118, @zebradots).
- vendor the official USPS Developer Portal v3 specs (captured 2026-06-23) for
  usps and usps_international, each with a provenance README.

* feat(fedex): pickupType option, full customer references, pickup improvements

- pickupType settable via the fedex_pickup_type shipping option, typed with the
  FedExPickupType enum (#1095, @ChrisNolan).
- full multi-type customerReferences (CUSTOMER_REFERENCE/INVOICE_NUMBER/
  DEPARTMENT_NUMBER/P_O_NUMBER/RMA_ASSOCIATION), built inline in the request
  tree; fixes the REF field on labels (#1089, @ChrisNolan; disc #1082).
- pickup: map instruction -> remarks, type fedex_pickup_address_type as an enum
  option, resolve package_location via the FedExPackageLocation enum (#1114,
  @ChrisNolan). Multi-recipient notification emails deferred (EBE-124).

* chore(rules): require explicit permission before writing to main

Add a hard guardrail to CLAUDE.md + .claude/rules/git-workflow.md: never
merge/push/force-push/revert main (incl. gh pr merge) without explicit
per-action permission; contributor PRs integrate into the release branch, not
main. Adds the rule that was missing when six PRs were merged to main in error.

* fix(dashboard): align tracker client usage with regenerated API types

The 2026.1.32 metadata regen renamed the Trackers retrieve/remove path param
idOrTrackingNumber -> identifier and made TrackingEvent.description nullable.
Update consumers: tracker delete/retrieve calls use { identifier }, and
getEventIcon accepts string | null.

* release: 2026.1.32

Version bump 2026.1.31 -> 2026.1.32 across packages, regenerated API metadata
(REST/GraphQL types, OpenAPI, schemas), CHANGELOG, and frozen requirements.
Removes SPRINT_MCP.md. Bumps community + ee/platform submodules to their
release commits; ee/insiders stays at v2026.1.29 (its main carries #32 /
task_backend, which ship with 2026.5).
alexbilbie pushed a commit to Teleship/karrio that referenced this pull request Jul 7, 2026
…es (karrioapi#1128)

* fix(server): critical ops + security fixes for 2026.1.32

- providers: guard migration 0093 against cascade data-loss (karrioapi#1116) — depend on
  manager/0079 so carrier FK columns are dropped before the legacy carrier delete.
- manager: make migration 0078 production-safe — chunked iterator + bulk_update,
  idempotent (karrioapi#1123).
- events: batch periodic_data_archiving deletes to avoid first-run OOM (karrioapi#1125).
- settings: import workers before apm so huey binds REDIS_HOST under OTEL (karrioapi#1124).
- settings: scope MD5 PASSWORD_HASHERS to the test runner only (karrioapi#1096, @mgradalska).
- core: clean up async DB connections to stop the tracing connection leak
  (karrioapi#1119/karrioapi#1120 phase 1, @ChrisNolan) + phase-2 PRD.

* fix(usps): correct v3 API hosts + vendor official OpenAPI specs

- usps + usps_international: update server URLs to apis.usps.com / apis-tem.usps.com
  after USPS retired the legacy Web Tools / api-cat hosts (karrioapi#1118, @zebradots).
- vendor the official USPS Developer Portal v3 specs (captured 2026-06-23) for
  usps and usps_international, each with a provenance README.

* feat(fedex): pickupType option, full customer references, pickup improvements

- pickupType settable via the fedex_pickup_type shipping option, typed with the
  FedExPickupType enum (karrioapi#1095, @ChrisNolan).
- full multi-type customerReferences (CUSTOMER_REFERENCE/INVOICE_NUMBER/
  DEPARTMENT_NUMBER/P_O_NUMBER/RMA_ASSOCIATION), built inline in the request
  tree; fixes the REF field on labels (karrioapi#1089, @ChrisNolan; disc karrioapi#1082).
- pickup: map instruction -> remarks, type fedex_pickup_address_type as an enum
  option, resolve package_location via the FedExPackageLocation enum (karrioapi#1114,
  @ChrisNolan). Multi-recipient notification emails deferred (EBE-124).

* chore(rules): require explicit permission before writing to main

Add a hard guardrail to CLAUDE.md + .claude/rules/git-workflow.md: never
merge/push/force-push/revert main (incl. gh pr merge) without explicit
per-action permission; contributor PRs integrate into the release branch, not
main. Adds the rule that was missing when six PRs were merged to main in error.

* fix(dashboard): align tracker client usage with regenerated API types

The 2026.1.32 metadata regen renamed the Trackers retrieve/remove path param
idOrTrackingNumber -> identifier and made TrackingEvent.description nullable.
Update consumers: tracker delete/retrieve calls use { identifier }, and
getEventIcon accepts string | null.

* release: 2026.1.32

Version bump 2026.1.31 -> 2026.1.32 across packages, regenerated API metadata
(REST/GraphQL types, OpenAPI, schemas), CHANGELOG, and frozen requirements.
Removes SPRINT_MCP.md. Bumps community + ee/platform submodules to their
release commits; ee/insiders stays at v2026.1.29 (its main carries karrioapi#32 /
task_backend, which ship with 2026.5).
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.

4 participants