/** * @pwngh/economy-lab * * Copyright (c) Preston Neal * * This source code is licensed under the MIT license found in the * LICENSE.md file in the root directory of this source tree. * * @license MIT */ import type { PayoutProviderStatus, Processor } from '../ports.js'; /** * Structural `fetch` shape rather than the built-in type, so tests can inject a stand-in and the * file typechecks on any runtime. */ export type FetchLike = (input: string, init?: { method?: string; headers?: Record; body?: string; signal?: AbortSignal; }) => Promise<{ ok: boolean; status: number; text(): Promise; }>; export interface HttpProcessorConfig { /** The provider URL each payout submission is POSTed to. */ endpoint: string; /** Sent in the Authorization header. Never written to logs or error details. */ apiKey?: string; /** Supplies the `fetch` implementation. Defaults to the global `fetch`; tests pass a stand-in. */ fetch?: FetchLike; } /** * Build a {@link Processor} that pays sellers via an external provider over HTTP. It asks the * provider to send money; it does not touch our ledger. * * `submitPayout` POSTs `{ key, userId, amount }`: the idempotency key (a resend pays out only * once), an opaque recipient token (no personal information), and the USD to pay as a decimal * string. It reads back the provider's reference id. A failed send or non-2xx status is * retryable. A 2xx with no reference id is non-retryable: the money may already have been sent, * so retrying could pay twice; reconciliation resolves the ambiguity. * * @see {@link https://economy-lab-docs.pages.dev/economy/ports/processor/ Processor} for how the * payout port plugs into the ledger. */ export declare function httpProcessor(config: HttpProcessorConfig): Processor; /** * An in-memory {@link Processor} for demos and tests: it accepts every payout, records it under a * deterministic `providerRef`, and answers a resend of the same idempotency key with the same ref, * so the retry-safety contract holds without a real provider. Pass `status` to make the optional * probe report a fixed state (e.g. `'SETTLED'` so a demo sweep settles without a webhook); omitted, * there is no probe, matching a real provider that reports only by webhook. */ export declare function memoryProcessor(options?: { status?: PayoutProviderStatus['state']; }): Processor;