Skip to content

Extract shared API client pieces from services into packages #198

Description

@TaprootFreak

Context

DFXswiss/services contains several thin API layers (types + useApi/call wrappers) that are customer/product API contracts, not widget- or staff-UI. Those belong in this monorepo (@dfx.swiss/core + @dfx.swiss/react) so other consumers can reuse them without depending on services.

Staff/compliance, RealUnit tenant, dashboard, and widget shell stay in services.

Goal

Move (or re-export) the shared wire contract into packages, then switch services to the published package APIs and drop the local duplicates.

Scope — extract into packages

1. Virtual / personal IBAN (create) — high priority

Source (services) src/hooks/virtual-iban.hook.ts, src/dto/virtual-iban.dto.ts
Target @dfx.swiss/core (URL + types + optional BuyApi method) and @dfx.swiss/react (hook, e.g. useVirtualIban / extend useBuy)
API POST buy/personalIban
Already in packages PersonalIbanProvider, isPersonalIban / buy quote fields (BuyPaymentInfo.personalIbanProvider)
Gap Create endpoint client + VirtualIban / CreateVirtualIban DTOs

Also consider pure domain helpers from services/src/util/personal-iban.ts (normalize provider, request mapping). Keep widget/URL param handling (personal-iban query, web-component) in services.


2. Recommendation (customer API) — high priority

Source (services) src/hooks/recommendation.hook.ts, src/dto/recommendation.dto.ts
Target core: URLs + types; react: useRecommendation
API GET/POST recommendation, PUT recommendation/:id/confirm, PUT recommendation/:id/reject
Already in packages Auth already accepts recommendationCode
Note Customer-facing only. Staff recommendation graph (support/recommendation-graph/…) stays in services compliance.

3. Payment Link pay-flow contract — medium priority

packages already covers Payment Link CRUD (PaymentLinksApi, usePaymentRoutes, PaymentLink, PaymentLinkPayment, PaymentStandardType, …).

Missing from packages, still only in services:

Source (services) src/dto/payment-link.dto.ts (and related call sites in payment-link contexts)
Target core definitions (+ optional client methods); re-export from react
Candidates PaymentStandard, PaymentLinkPayTerminal, PaymentLinkPayRequest, Quote, TransferInfo / TransferMethod, C2BPaymentMethod, RecipientInfo (pay-flow shape), wait/history URL helpers if stable
Related endpoints used only in services today e.g. paymentLink/standard, paymentLink/payment, paymentLink/payment/wait, paymentLink/history (verify against current API before freezing)

Do not move: POS UI orchestration, MetaMask pay UI, polling timers, merchant session storage — those stay in services.


4. Custody / Safe API client — medium priority

Source (services) src/hooks/safe.hook.ts, src/dto/safe.dto.ts, src/dto/order.dto.ts
Target core: CustodyApi (or similar) + types; react: useCustody / useSafe
API (customer) custody, custody/account, balances/history/order, confirm order, …
Already in packages JWT role Custody
Do not move Staff admin paths (custody/admin/orders, approve) — those stay under services compliance

5. Blockchain helper API — optional / lower priority

Source (services) src/hooks/blockchain-balance.hook.ts, src/hooks/blockchain-transaction.hook.ts
Target core client + react hooks
API POST blockchain/balances, POST blockchain/transaction, POST blockchain/broadcast

Useful for any wallet-integrated consumer; not required if only services uses them long-term.


Explicitly out of scope (stay in services)

  • Staff / compliance: compliance.hook.ts, MROS, recall, Scorechain, call queues, AML review/reset, KYC admin
  • Internal financial dashboard (dashboard/*)
  • RealUnit (customer + compliance + support tenant APIs)
  • Support staff dashboard (support/issue/list, clerks, statistics, templates) — customer chat is already in packages (useSupportChat / SupportApi)
  • Widget shell: app-handling.context, web component, screens, i18n, charts, wallet adapters, PDF builders

Suggested delivery order

  1. Virtual/personal IBAN create + DTOs
  2. Recommendation customer API
  3. Payment Link pay-request types (+ any missing stable endpoints)
  4. Custody/Safe customer client
  5. Blockchain helpers (optional)

Each step: implement in packages → publish (beta then stable per release process) → bump @dfx.swiss/react / @dfx.swiss/core in services → delete local duplicates.


Acceptance criteria

  • Types and URL constants for each in-scope item live in @dfx.swiss/core (and are re-exported from @dfx.swiss/react where hooks exist today)
  • React hooks exist for customer-facing calls where services currently uses local hooks
  • services uses the published packages; local dto/hook copies for in-scope items are removed
  • No staff/compliance/RealUnit/dashboard code is moved into packages
  • packages CONTRIBUTING: no hand-bumped versions in feature PRs (Lerna publish workflow)
  • Breaking changes called out for downstream consumers

References

  • packages CONSUMERS: e.g. DFXswiss/services (pinned npm deps)
  • Local analysis: services has ~188 files importing @dfx.swiss/react, but many extra API paths only via local useApi() wrappers
  • Related existing packages surface: buy (PersonalIbanProvider), payment links CRUD, support customer chat, bank receive-IBAN check

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions