Skip to content

feat(provider-ids): stable canonical-id resolver (closes #2256) - #2316

Merged
github-actions[bot] merged 1 commit into
Smartdevs17:mainfrom
IVANLI2412:fix/issue-2256-provider-ids
Nov 24, 2026
Merged

github-actions[bot] merged 1 commit into
Smartdevs17:mainfrom
IVANLI2412:fix/issue-2256-provider-ids

Conversation

@IVANLI2412

Copy link
Copy Markdown
Contributor

Closes #2256

Summary

Adds a stable, provider-agnostic canonical-id resolver behind the two requested paths, with no unrelated churn.

backend/src/lib/providerId.ts (zero-dependency, pure, side-effect-free):

  • canonicalizeProviderId() / resolveProviderId() fold any provider identifier into <provider>:<normalized-id>-<8-hex FNV-1a> (wire-format version 1).
  • normalizeExternalId() trims, Unicode NFKD-folds, lower-cases, strips configured provider prefixes (cus_, PAY-, ch_, ...) and collapses separators to a single -. Non-ASCII becomes a separator; length is bounded (128 normalized / 512 raw).
  • The hash is fnv1a32(provider + "\0" + normalizedId), so case/separator/prefix/Unicode equivalents collapse to one id while different providers and different ids stay distinct.
  • parseProviderIdentifier(), areSameProviderId(), validateCanonicalIdConfig(), fnv1a32(), ProviderIdError with stable codes, config-driven known-provider allow-list with custom-provider support, idempotent passthrough of already-canonical strings, and a createCanonicalIdResolver() factory with metrics/logger hooks (rejections emit recordRejected + warn and rethrow the typed error).
  • JSDoc on all public functions; no TODOs, orphan scripts, or new docs files.

packages/billing-types/ (new @subtrackr/billing-types package):

  • Shared vocabulary only: CANONICAL_ID_VERSION, CANONICAL_ID_PATTERN, CANONICAL_ID_PATTERN_SOURCE, KNOWN_PROVIDERS, ProviderKind, CanonicalProviderId, PROVIDER_PREFIXES, PROVIDER_ID_ERROR_CODES, MAX_NORMALIZED_ID_LENGTH, DEFAULT_ALLOW_CUSTOM_PROVIDERS. The backend imports these instead of duplicating them.

Tests

  • backend/src/lib/__tests__/providerId.test.ts — 30 tests: constants/error surface, config validation, parsing, normalisation (case, separators, prefixes, Unicode), determinism and canonical well-formedness, cross-provider distinctness, Unicode folding, already-canonical passthrough, every failure code, resolution records, equality, and metrics/logger hooks.
  • packages/billing-types/src/__tests__/index.test.ts — 5 tests: version/limits, provider set, canonical pattern positives/negatives, shared prefixes, shared error codes.

Verification evidence

Run with no node_modules using Node 26 native TypeScript type-stripping against the real .ts sources (explicit .ts import extensions):

  • node verify_2256.mjs → 52 passed, 0 failed (exit 0)
  • Jest shim runner over both test files → backend 30 passed / 0 failed, billing 5 passed / 0 failed (35 total, exit 0)
  • python tools/check_secrets.py → [OK], SECRETS_EXIT=0

Payouts

Base Mainnet (USDC/ETH): 0xC5dD2Ea54FF138bb3f71D3466092eA31eF115868
Solana (USDC/SOL): DN3pfYEvdkoTBP4oaEVvemsr98fZPhDSAbfVfmewRGQ5
PayPal: ivanzenteno3@gmail.com

@github-actions
github-actions Bot merged commit a3d3d06 into Smartdevs17:main Nov 24, 2026
7 of 27 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.

Normalise provider identifiers behind a stable canonical-id resolver

1 participant