@openreceive/http 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +57 -0
- package/dist/adapter-surface-BtXnvW2q.d.ts +722 -0
- package/dist/adapter-surface.d.ts +3 -0
- package/dist/adapter-surface.js +20 -0
- package/dist/chunk-5S24YV7E.js +2228 -0
- package/dist/index.d.ts +411 -0
- package/dist/index.js +74 -0
- package/package.json +59 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
import { OpenReceive, PaymentCheck } from '@openreceive/node';
|
|
2
|
+
export { Checkout, CreateCheckoutAmount, OpenReceive, PaymentCheck, SwapCheckout } from '@openreceive/node';
|
|
3
|
+
import { H as Host, R as ReconcilableAttempt, S as SqlAdapter } from './adapter-surface-BtXnvW2q.js';
|
|
4
|
+
export { A as AttemptStatus, a as Authorize, b as AuthorizeAction, c as AuthorizeContext, d as AuthorizeResource, C as CheckoutCreatedHook, e as CheckoutCreatedInput, f as CreateHostDbOptions, g as CreateHostOptions, h as CreateHostRepositoryOptions, i as CreateHttpHandlerOptions, j as CreateStackOptions, k as HostError, l as HttpError, m as HttpHandler, I as IpRateLimitConfig, N as NotificationListener, n as NotificationWorker, O as OPENRECEIVE_ATTEMPT_EXPIRY_GRACE_SECONDS, o as OPENRECEIVE_RECONCILE_BATCH_SIZE, P as PaymentInsert, p as PaymentRecord, q as PaymentRepository, r as PaymentSettlement, s as PaymentSettlementHook, t as RateLimit, u as ReconciliationTransition, v as ResolveCheckoutContext, w as ResolveCheckoutHook, x as ResolvedHostCheckout, y as ServiceErrorShape, z as SettlementEvent, B as SettlementEventHook, D as SettlementRecord, E as SqlClient, F as SqlDatabase, G as SqlPaymentRepository, J as SqlPaymentsOptions, K as SqlQuery, L as Stack, M as StackStorage, Q as StackWallet, T as createHost, U as createHttpHandler, V as createIpRateLimit, W as createProxyRateLimitingConfig, X as createRequestId, Y as createSqlPayments, Z as createStack, _ as errorResponse, $ as hostError, a0 as isServiceErrorShape, a1 as isStackOptions, a2 as jsonResponse, a3 as mapHostRouteError, a4 as paymentsSchemaSql, a5 as resolveClientIp, a6 as startNotificationListener, a7 as startNotificationWorker } from './adapter-surface-BtXnvW2q.js';
|
|
5
|
+
export { OPENRECEIVE_PAYMENTS_SCHEMA_VERSION } from '@openreceive/core';
|
|
6
|
+
|
|
7
|
+
/** The pieces of a framework request the bridge needs, framework-agnostic. */
|
|
8
|
+
interface NodeRequestParts {
|
|
9
|
+
readonly method: string;
|
|
10
|
+
readonly headers: Readonly<Record<string, string | string[] | undefined>>;
|
|
11
|
+
/** Request path (may include the query string). */
|
|
12
|
+
readonly url: string;
|
|
13
|
+
/** Scheme reported by the framework (respecting its trust-proxy setting). */
|
|
14
|
+
readonly protocol?: string;
|
|
15
|
+
/** Body already parsed by the framework's body parser, when present. */
|
|
16
|
+
readonly parsedBody?: unknown;
|
|
17
|
+
}
|
|
18
|
+
/** Convert a parsed framework request into the Web Request the handler speaks. */
|
|
19
|
+
declare function webRequest(parts: NodeRequestParts): Request;
|
|
20
|
+
/**
|
|
21
|
+
* True when the adapter should hand this request to the OpenReceive handler
|
|
22
|
+
* instead of the surrounding app. A root mount (`prefix: "/"`) claims only the
|
|
23
|
+
* library's own paths.
|
|
24
|
+
*/
|
|
25
|
+
declare function isUnderPrefix(pathname: string, prefix: string): boolean;
|
|
26
|
+
|
|
27
|
+
/** Wire shape of the OpenAPI `PrepareCheckoutRequest` schema (snake_case JSON body). */
|
|
28
|
+
type WirePrepareCheckoutRequest = {
|
|
29
|
+
readonly reference: string;
|
|
30
|
+
};
|
|
31
|
+
/** Wire shape of the OpenAPI `PrepareCheckoutResponse` schema (snake_case JSON body). */
|
|
32
|
+
type WirePrepareCheckoutResponse = {
|
|
33
|
+
readonly reference: string;
|
|
34
|
+
readonly amount_msats: number;
|
|
35
|
+
readonly fiat_quote?: null | WireFiatQuote;
|
|
36
|
+
readonly payment_methods: readonly WirePaymentMethod[];
|
|
37
|
+
};
|
|
38
|
+
/** Wire shape of the OpenAPI `CreateCheckoutRequest` schema (snake_case JSON body). */
|
|
39
|
+
type WireCreateCheckoutRequest = {
|
|
40
|
+
readonly reference: string;
|
|
41
|
+
readonly memo?: string;
|
|
42
|
+
readonly metadata?: Record<string, unknown>;
|
|
43
|
+
};
|
|
44
|
+
/** Wire shape of the OpenAPI `Checkout` schema (snake_case JSON body). */
|
|
45
|
+
type WireCheckout = {
|
|
46
|
+
readonly reference: string;
|
|
47
|
+
readonly payment_hash: string;
|
|
48
|
+
readonly bolt11: string;
|
|
49
|
+
readonly amount_msats: number;
|
|
50
|
+
readonly created_at: number;
|
|
51
|
+
readonly expires_at: number;
|
|
52
|
+
readonly fiat_quote?: null | WireFiatQuote;
|
|
53
|
+
};
|
|
54
|
+
/** Wire shape of the OpenAPI `CreateCheckoutResponse` schema (snake_case JSON body). */
|
|
55
|
+
type WireCreateCheckoutResponse = {
|
|
56
|
+
readonly checkout: WireCheckout;
|
|
57
|
+
};
|
|
58
|
+
/** Wire shape of the OpenAPI `PaymentCheckRequest` schema (snake_case JSON body). */
|
|
59
|
+
type WirePaymentCheckRequest = {
|
|
60
|
+
readonly reference: string;
|
|
61
|
+
readonly payment_hash: string;
|
|
62
|
+
};
|
|
63
|
+
/** Wire shape of the OpenAPI `PaymentStatus` schema (snake_case JSON body). */
|
|
64
|
+
type WirePaymentStatus = "pending" | "settled" | "expired" | "failed" | "not_found";
|
|
65
|
+
/** Wire shape of the OpenAPI `PaymentMethod` schema (snake_case JSON body). */
|
|
66
|
+
type WirePaymentMethod = {
|
|
67
|
+
readonly pay_in_asset: string;
|
|
68
|
+
readonly label: string;
|
|
69
|
+
readonly network_label: string;
|
|
70
|
+
readonly provider: string;
|
|
71
|
+
readonly available: boolean;
|
|
72
|
+
readonly unavailable_reason?: string;
|
|
73
|
+
readonly unavailable_message?: string;
|
|
74
|
+
readonly pay_amount?: string;
|
|
75
|
+
readonly minimum_pay_amount?: string;
|
|
76
|
+
readonly maximum_pay_amount?: string;
|
|
77
|
+
readonly minimum_invoice_amount_msats?: number;
|
|
78
|
+
readonly maximum_invoice_amount_msats?: number;
|
|
79
|
+
};
|
|
80
|
+
/** Wire shape of the OpenAPI `FiatQuote` schema (snake_case JSON body). */
|
|
81
|
+
type WireFiatQuote = {
|
|
82
|
+
readonly fiat: {
|
|
83
|
+
readonly currency: string;
|
|
84
|
+
readonly value: string;
|
|
85
|
+
};
|
|
86
|
+
readonly btc_fiat_price: string;
|
|
87
|
+
readonly amount_sats: number;
|
|
88
|
+
readonly amount_msats: number;
|
|
89
|
+
readonly source: "static_mock" | "primary" | "fallback";
|
|
90
|
+
readonly as_of: number;
|
|
91
|
+
readonly expires_at: number;
|
|
92
|
+
};
|
|
93
|
+
/** Wire shape of the OpenAPI `PaymentDetails` schema (snake_case JSON body). */
|
|
94
|
+
type WirePaymentDetails = {
|
|
95
|
+
readonly transaction?: {
|
|
96
|
+
readonly payment_hash?: string;
|
|
97
|
+
readonly state?: string;
|
|
98
|
+
readonly transaction_state?: string;
|
|
99
|
+
readonly amount_msats?: number;
|
|
100
|
+
readonly fees_paid_msats?: number;
|
|
101
|
+
readonly created_at?: number;
|
|
102
|
+
readonly settled_at?: number;
|
|
103
|
+
readonly expires_at?: number;
|
|
104
|
+
};
|
|
105
|
+
readonly observed_at: number;
|
|
106
|
+
readonly paid_at_source?: "settled_at" | "observed_at";
|
|
107
|
+
};
|
|
108
|
+
/** Wire shape of the OpenAPI `PaymentCheck` schema (snake_case JSON body). */
|
|
109
|
+
type WirePaymentCheck = {
|
|
110
|
+
readonly payment_hash: string;
|
|
111
|
+
readonly status: WirePaymentStatus;
|
|
112
|
+
readonly paid_at?: number;
|
|
113
|
+
readonly details?: WirePaymentDetails;
|
|
114
|
+
readonly payment_methods: readonly WirePaymentMethod[];
|
|
115
|
+
};
|
|
116
|
+
/** Wire shape of the OpenAPI `SwapQuoteRequest` schema (snake_case JSON body). */
|
|
117
|
+
type WireSwapQuoteRequest = {
|
|
118
|
+
readonly reference: string;
|
|
119
|
+
readonly pay_in_asset: string;
|
|
120
|
+
};
|
|
121
|
+
/** Wire shape of the OpenAPI `CreateSwapRequest` schema (snake_case JSON body). */
|
|
122
|
+
type WireCreateSwapRequest = {
|
|
123
|
+
readonly reference: string;
|
|
124
|
+
readonly pay_in_asset: string;
|
|
125
|
+
readonly memo?: string;
|
|
126
|
+
readonly metadata?: Record<string, unknown>;
|
|
127
|
+
};
|
|
128
|
+
/** Wire shape of the OpenAPI `SwapPayInAsset` schema (snake_case JSON body). */
|
|
129
|
+
type WireSwapPayInAsset = "SOL_SOL" | "USDT_TRON" | "USDT_SOL" | "USDC_SOL" | "ETH_ETH" | "USDT_ETH" | "USDC_ETH";
|
|
130
|
+
/** Wire shape of the OpenAPI `SwapProviderState` schema (snake_case JSON body). */
|
|
131
|
+
type WireSwapProviderState = "creating_provider_order" | "awaiting_deposit" | "confirming" | "exchanging" | "paying_invoice" | "completed" | "expired" | "refund_required" | "refund_pending" | "refunded" | "attention" | "failed";
|
|
132
|
+
/** Wire shape of the OpenAPI `SwapFee` schema (snake_case JSON body). */
|
|
133
|
+
type WireSwapFee = {
|
|
134
|
+
readonly currency: string;
|
|
135
|
+
readonly pay_in_fiat: string;
|
|
136
|
+
readonly payout_fiat: string;
|
|
137
|
+
};
|
|
138
|
+
/** Wire shape of the OpenAPI `SwapQuote` schema (snake_case JSON body). */
|
|
139
|
+
type WireSwapQuote = {
|
|
140
|
+
readonly provider: string;
|
|
141
|
+
readonly pay_asset: WireSwapPayInAsset;
|
|
142
|
+
readonly available: boolean;
|
|
143
|
+
readonly pay_amount?: string;
|
|
144
|
+
readonly minimum_pay_amount?: string;
|
|
145
|
+
readonly maximum_pay_amount?: string;
|
|
146
|
+
readonly minimum_invoice_amount_msats?: number;
|
|
147
|
+
readonly maximum_invoice_amount_msats?: number;
|
|
148
|
+
readonly unavailable_reason?: string;
|
|
149
|
+
readonly unavailable_message?: string;
|
|
150
|
+
};
|
|
151
|
+
/** Wire shape of the OpenAPI `Swap` schema (snake_case JSON body). */
|
|
152
|
+
type WireSwap = {
|
|
153
|
+
readonly payment_hash: string;
|
|
154
|
+
readonly reference: string;
|
|
155
|
+
readonly provider: string;
|
|
156
|
+
readonly pay_in_asset: WireSwapPayInAsset;
|
|
157
|
+
readonly deposit_address: string;
|
|
158
|
+
readonly deposit_memo?: string;
|
|
159
|
+
readonly deposit_amount: string;
|
|
160
|
+
readonly provider_state: WireSwapProviderState;
|
|
161
|
+
readonly provider_expires_at: number;
|
|
162
|
+
readonly deposit_tx_id?: string;
|
|
163
|
+
readonly payout_tx_id?: string;
|
|
164
|
+
readonly refund_tx_id?: string;
|
|
165
|
+
readonly refund_reason?: string;
|
|
166
|
+
readonly refund_amount?: string;
|
|
167
|
+
readonly attention?: boolean;
|
|
168
|
+
readonly attention_reason?: string;
|
|
169
|
+
readonly deposit_received_amount?: string;
|
|
170
|
+
readonly emergency_repeat?: boolean;
|
|
171
|
+
readonly provider_order_id?: string;
|
|
172
|
+
readonly fee?: WireSwapFee;
|
|
173
|
+
};
|
|
174
|
+
/** Wire shape of the OpenAPI `SwapCheckout` schema (snake_case JSON body). */
|
|
175
|
+
type WireSwapCheckout = {
|
|
176
|
+
readonly payment_hash: string;
|
|
177
|
+
readonly reference: string;
|
|
178
|
+
readonly provider: string;
|
|
179
|
+
readonly pay_in_asset: WireSwapPayInAsset;
|
|
180
|
+
readonly deposit_address: string;
|
|
181
|
+
readonly deposit_memo?: string;
|
|
182
|
+
readonly deposit_amount: string;
|
|
183
|
+
readonly provider_state: WireSwapProviderState;
|
|
184
|
+
readonly provider_expires_at: number;
|
|
185
|
+
readonly deposit_tx_id?: string;
|
|
186
|
+
readonly payout_tx_id?: string;
|
|
187
|
+
readonly refund_tx_id?: string;
|
|
188
|
+
readonly refund_reason?: string;
|
|
189
|
+
readonly refund_amount?: string;
|
|
190
|
+
readonly attention?: boolean;
|
|
191
|
+
readonly attention_reason?: string;
|
|
192
|
+
readonly deposit_received_amount?: string;
|
|
193
|
+
readonly emergency_repeat?: boolean;
|
|
194
|
+
readonly provider_order_id?: string;
|
|
195
|
+
readonly fee?: WireSwapFee;
|
|
196
|
+
} & {
|
|
197
|
+
readonly checkout: WireCheckout;
|
|
198
|
+
};
|
|
199
|
+
/** Wire shape of the OpenAPI `CreateSwapResponse` schema (snake_case JSON body). */
|
|
200
|
+
type WireCreateSwapResponse = {
|
|
201
|
+
readonly swap: WireSwapCheckout;
|
|
202
|
+
};
|
|
203
|
+
/** Wire shape of the OpenAPI `RatesResponse` schema (snake_case JSON body). */
|
|
204
|
+
type WireRatesResponse = {
|
|
205
|
+
readonly bitcoin: Record<string, string>;
|
|
206
|
+
};
|
|
207
|
+
/** Wire shape of the OpenAPI `Error` schema (snake_case JSON body). */
|
|
208
|
+
type WireError = {
|
|
209
|
+
readonly code: "NOT_IMPLEMENTED" | "RESTRICTED" | "UNAUTHORIZED" | "FORBIDDEN" | "RATE_LIMITED" | "QUOTA_EXCEEDED" | "INTERNAL" | "UNSUPPORTED_ENCRYPTION" | "OTHER" | "NOT_FOUND" | "TIMEOUT" | "INVALID_REQUEST" | "WALLET_UNAVAILABLE" | "INVOICE_EXPIRED" | "UNSUPPORTED_METHOD" | "CONFLICT";
|
|
210
|
+
readonly message: string;
|
|
211
|
+
readonly request_id?: string;
|
|
212
|
+
readonly retryable?: boolean;
|
|
213
|
+
readonly details?: Record<string, unknown>;
|
|
214
|
+
};
|
|
215
|
+
/** Wire shape of the `POST /swaps/refunds` request body (snake_case JSON body). */
|
|
216
|
+
type WireRefundSwapRequest = {
|
|
217
|
+
readonly reference: string;
|
|
218
|
+
readonly payment_hash: string;
|
|
219
|
+
readonly refund_address: string;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
interface Reconciler {
|
|
223
|
+
stop(): void;
|
|
224
|
+
readonly done: Promise<void>;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* One bounded reconciliation pass: scan the wallet for every pending attempt,
|
|
228
|
+
* deliver settlements at least once, and persist terminal transitions so closed
|
|
229
|
+
* attempts leave the scan set. Attempt closure requires a successful wallet
|
|
230
|
+
* scan at or after expiry plus grace — a local clock alone never closes a row,
|
|
231
|
+
* because a payment could have settled while the application was offline.
|
|
232
|
+
*
|
|
233
|
+
* A walk cut short by its page cap decides nothing: the core scan omits the
|
|
234
|
+
* hashes it could not reach, so those attempts get no transition this pass and
|
|
235
|
+
* stay pending instead of being closed on an unproven `not_found`.
|
|
236
|
+
*
|
|
237
|
+
* Returns the per-hash `PaymentCheck` results of the pass so callers (notably
|
|
238
|
+
* `payments/check`) can serve a requested hash straight from the pass instead
|
|
239
|
+
* of adding a second per-invoice wallet walk. Results are keyed by hash and
|
|
240
|
+
* may cover fewer hashes than were scanned.
|
|
241
|
+
*/
|
|
242
|
+
declare function reconcileHostPayments(input: {
|
|
243
|
+
readonly service: OpenReceive;
|
|
244
|
+
readonly host: Host;
|
|
245
|
+
readonly overlapSeconds?: number;
|
|
246
|
+
readonly maxPages?: number;
|
|
247
|
+
readonly clock?: () => number;
|
|
248
|
+
/**
|
|
249
|
+
* The pending attempts to scan, when the caller already listed them. The
|
|
250
|
+
* opportunistic gate does — it sizes the gate interval from the same batch —
|
|
251
|
+
* so passing it here saves a second identical read on every winning pass,
|
|
252
|
+
* which is the request path.
|
|
253
|
+
*/
|
|
254
|
+
readonly attempts?: readonly ReconcilableAttempt[];
|
|
255
|
+
}): Promise<readonly PaymentCheck[]>;
|
|
256
|
+
/**
|
|
257
|
+
* Poll and reconcile only the pending attempts in the ledger. Every pass goes
|
|
258
|
+
* through the durable `claimReconcileGate`, so N worker instances — and the
|
|
259
|
+
* request-path opportunistic reconcile — collapse to one real wallet scan per
|
|
260
|
+
* gate interval instead of each running its own.
|
|
261
|
+
*/
|
|
262
|
+
declare function startReconciler(input: {
|
|
263
|
+
readonly service: OpenReceive;
|
|
264
|
+
readonly host: Host;
|
|
265
|
+
readonly pollIntervalMs?: number;
|
|
266
|
+
readonly signal?: AbortSignal;
|
|
267
|
+
readonly overlapSeconds?: number;
|
|
268
|
+
readonly clock?: () => number;
|
|
269
|
+
/**
|
|
270
|
+
* Observes per-pass failures (wallet, repository, or callback errors). The
|
|
271
|
+
* reconciler always retries from the ledger on the next pass; without this
|
|
272
|
+
* hook failures are reported once per distinct message via console.warn so a
|
|
273
|
+
* permanently failing reconciler is never silent.
|
|
274
|
+
*/
|
|
275
|
+
readonly onError?: (error: unknown) => void;
|
|
276
|
+
}): Promise<Reconciler>;
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Floor for the durable reconcile-gate interval: at most one real wallet scan
|
|
280
|
+
* per two seconds across EVERY worker sharing the host database. This gate is
|
|
281
|
+
* the NWC rate limit for settlement scans — open tabs polling `payments/check`
|
|
282
|
+
* (~3s) all share the one global pass instead of fanning out wallet walks.
|
|
283
|
+
*/
|
|
284
|
+
declare const OPENRECEIVE_MIN_RECONCILE_INTERVAL_SECONDS: 2;
|
|
285
|
+
/**
|
|
286
|
+
* Wall-clock bound on an awaited request-path pass: a slow wallet must not
|
|
287
|
+
* hang user-facing requests. A timed-out pass counts as a failed scan; the
|
|
288
|
+
* gate stays claimed so the next interval retries without a stampede.
|
|
289
|
+
*/
|
|
290
|
+
declare const OPENRECEIVE_RECONCILE_SCAN_TIMEOUT_MS: 9000;
|
|
291
|
+
/** Page cap per wallet-history walk on the awaited request path. */
|
|
292
|
+
declare const OPENRECEIVE_RECONCILE_SCAN_MAX_PAGES: 50;
|
|
293
|
+
type OpportunisticReconcileResult = {
|
|
294
|
+
readonly reason: "ran";
|
|
295
|
+
readonly checks: readonly PaymentCheck[];
|
|
296
|
+
} | {
|
|
297
|
+
readonly reason: "no_pending" | "gate_busy" | "scan_failed";
|
|
298
|
+
};
|
|
299
|
+
interface MaybeReconcilePaymentsOptions {
|
|
300
|
+
readonly service: OpenReceive;
|
|
301
|
+
readonly host: Host;
|
|
302
|
+
/** Gate interval floor. Default (and minimum) 2 seconds. */
|
|
303
|
+
readonly minIntervalSeconds?: number;
|
|
304
|
+
readonly overlapSeconds?: number;
|
|
305
|
+
readonly scanTimeoutMs?: number;
|
|
306
|
+
readonly maxPages?: number;
|
|
307
|
+
readonly clock?: () => number;
|
|
308
|
+
/** Observes failed scans. Default: console.warn — a failure never propagates. */
|
|
309
|
+
readonly onError?: (error: unknown) => void;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* The gate interval for the current pending set: the configured floor,
|
|
313
|
+
* stretched by invoice age (2s while any pending invoice is under 2 minutes
|
|
314
|
+
* old, 6s under 5 minutes, else 12s).
|
|
315
|
+
*/
|
|
316
|
+
declare function reconcileIntervalSeconds(attempts: readonly ReconcilableAttempt[], now: number, minIntervalSeconds?: number): number;
|
|
317
|
+
/**
|
|
318
|
+
* Opportunistic settlement discovery, piggybacked on any later OpenReceive
|
|
319
|
+
* call: skip without a wallet call when nothing is pending, try the durable
|
|
320
|
+
* `openreceive_meta` gate (`gate_busy` means another worker just scanned —
|
|
321
|
+
* skip the wallet), otherwise AWAIT one bounded `reconcileHostPayments`
|
|
322
|
+
* pass (serverless-safe) and return its per-hash results.
|
|
323
|
+
*
|
|
324
|
+
* Never throws: a failed or timed-out scan is reported (default console.warn)
|
|
325
|
+
* and returns `scan_failed` — the caller's own request must not fail because a
|
|
326
|
+
* settlement sweep did. The gate's `claimed_at` is left in place on failure so
|
|
327
|
+
* a broken wallet cannot stampede; the next interval retries.
|
|
328
|
+
*
|
|
329
|
+
* The HTTP handler calls this on every mounted payment route by default
|
|
330
|
+
* (`opportunisticReconcile`; unauthenticated `GET /rates` is excluded so
|
|
331
|
+
* crawlers and health checks cannot consume the scan budget); it is exported
|
|
332
|
+
* so hosts can also drive it from their own routes or middleware (host-only
|
|
333
|
+
* routes never auto-run it).
|
|
334
|
+
*/
|
|
335
|
+
declare function maybeReconcilePayments(input: MaybeReconcilePaymentsOptions): Promise<OpportunisticReconcileResult>;
|
|
336
|
+
|
|
337
|
+
type SqlDialect = SqlAdapter["dialect"];
|
|
338
|
+
/** The raw-query slice of a Knex instance or transaction. */
|
|
339
|
+
interface KnexExecutorLike {
|
|
340
|
+
raw(sql: string, bindings: readonly unknown[]): Promise<unknown>;
|
|
341
|
+
}
|
|
342
|
+
/** Structural view of a Knex instance. */
|
|
343
|
+
interface KnexLike extends KnexExecutorLike {
|
|
344
|
+
transaction<T>(run: (trx: KnexExecutorLike) => Promise<T>): Promise<T>;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Wrap a Knex instance. Knex hands the SQL and bindings to the driver
|
|
348
|
+
* verbatim (`?` is already the sqlite placeholder, and `$n` postgres SQL
|
|
349
|
+
* contains no `?` for Knex to rewrite); only the RESULT shape differs per
|
|
350
|
+
* driver. The sqlite3 driver resolves the rows array itself; pg wraps them in
|
|
351
|
+
* `{ rows }` — reaching into `result[0]` would return the first ROW on
|
|
352
|
+
* sqlite, which breaks every repository read.
|
|
353
|
+
*/
|
|
354
|
+
declare function knexDb(knex: KnexLike, dialect: SqlDialect): SqlAdapter;
|
|
355
|
+
/** The raw-query slice of a PrismaClient or interactive-transaction client. */
|
|
356
|
+
interface PrismaExecutorLike {
|
|
357
|
+
$queryRawUnsafe(sql: string, ...params: unknown[]): Promise<unknown>;
|
|
358
|
+
$executeRawUnsafe(sql: string, ...params: unknown[]): Promise<unknown>;
|
|
359
|
+
}
|
|
360
|
+
/** Structural view of a PrismaClient. */
|
|
361
|
+
interface PrismaLike extends PrismaExecutorLike {
|
|
362
|
+
$transaction<T>(run: (tx: PrismaExecutorLike) => Promise<T>): Promise<T>;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Wrap a PrismaClient. Match `dialect` to the Prisma datasource provider.
|
|
366
|
+
* Prisma splits raw SQL across two calls — `$queryRawUnsafe` resolves rows,
|
|
367
|
+
* `$executeRawUnsafe` resolves an affected-row count — so statements are
|
|
368
|
+
* routed by whether they return rows.
|
|
369
|
+
*/
|
|
370
|
+
declare function prismaDb(prisma: PrismaLike, dialect: SqlDialect): SqlAdapter;
|
|
371
|
+
/** The raw-query slice of a TypeORM DataSource or transaction EntityManager. */
|
|
372
|
+
interface TypeOrmExecutorLike {
|
|
373
|
+
query(sql: string, params?: unknown[]): Promise<unknown>;
|
|
374
|
+
}
|
|
375
|
+
/** Structural view of a TypeORM DataSource. */
|
|
376
|
+
interface TypeOrmLike extends TypeOrmExecutorLike {
|
|
377
|
+
transaction<T>(run: (manager: TypeOrmExecutorLike) => Promise<T>): Promise<T>;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Wrap a TypeORM DataSource. `query` passes the SQL through verbatim and
|
|
381
|
+
* already resolves rows on both drivers. The transaction callback must run
|
|
382
|
+
* through the transaction's own EntityManager — falling back to the
|
|
383
|
+
* DataSource would execute settlement statements outside the transaction.
|
|
384
|
+
*/
|
|
385
|
+
declare function typeOrmDb(dataSource: TypeOrmLike, dialect: SqlDialect): SqlAdapter;
|
|
386
|
+
/** The raw-query slice of a Sequelize instance or a managed Transaction. */
|
|
387
|
+
interface SequelizeExecutorLike {
|
|
388
|
+
query(sql: string, options?: {
|
|
389
|
+
readonly bind?: readonly unknown[];
|
|
390
|
+
readonly transaction?: unknown;
|
|
391
|
+
}): Promise<unknown>;
|
|
392
|
+
}
|
|
393
|
+
/** Structural view of a Sequelize instance. */
|
|
394
|
+
interface SequelizeLike extends SequelizeExecutorLike {
|
|
395
|
+
transaction<T>(run: (transaction: unknown) => Promise<T>): Promise<T>;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Wrap a Sequelize instance.
|
|
399
|
+
*
|
|
400
|
+
* Sequelize takes bind parameters under `bind` (not positional arguments) and
|
|
401
|
+
* carries the transaction on the SAME instance via an options key rather than
|
|
402
|
+
* a separate executor object — so the transaction callback threads the
|
|
403
|
+
* managed transaction back into every statement. Without that, settlement
|
|
404
|
+
* statements would run outside the transaction on the instance's own pool.
|
|
405
|
+
*
|
|
406
|
+
* `sequelize.query` resolves `[rows, metadata]` for a SELECT and metadata
|
|
407
|
+
* alone for a write, so a non-array result reads as no rows.
|
|
408
|
+
*/
|
|
409
|
+
declare function sequelizeDb(sequelize: SequelizeLike, dialect: SqlDialect): SqlAdapter;
|
|
410
|
+
|
|
411
|
+
export { Host, type KnexLike, type MaybeReconcilePaymentsOptions, type NodeRequestParts, OPENRECEIVE_MIN_RECONCILE_INTERVAL_SECONDS, OPENRECEIVE_RECONCILE_SCAN_MAX_PAGES, OPENRECEIVE_RECONCILE_SCAN_TIMEOUT_MS, type OpportunisticReconcileResult, type PrismaLike, ReconcilableAttempt, type Reconciler, type SequelizeLike, SqlAdapter, type SqlDialect, type TypeOrmLike, type WireCheckout, type WireCreateCheckoutRequest, type WireCreateCheckoutResponse, type WireCreateSwapRequest, type WireCreateSwapResponse, type WireError, type WireFiatQuote, type WirePaymentCheck, type WirePaymentCheckRequest, type WirePaymentDetails, type WirePaymentMethod, type WirePaymentStatus, type WirePrepareCheckoutRequest, type WirePrepareCheckoutResponse, type WireRatesResponse, type WireRefundSwapRequest, type WireSwap, type WireSwapCheckout, type WireSwapFee, type WireSwapPayInAsset, type WireSwapProviderState, type WireSwapQuote, type WireSwapQuoteRequest, isUnderPrefix, knexDb, maybeReconcilePayments, prismaDb, reconcileHostPayments, reconcileIntervalSeconds, sequelizeDb, startReconciler, typeOrmDb, webRequest };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HostError,
|
|
3
|
+
HttpError,
|
|
4
|
+
OPENRECEIVE_ATTEMPT_EXPIRY_GRACE_SECONDS,
|
|
5
|
+
OPENRECEIVE_MIN_RECONCILE_INTERVAL_SECONDS,
|
|
6
|
+
OPENRECEIVE_PAYMENTS_SCHEMA_VERSION,
|
|
7
|
+
OPENRECEIVE_RECONCILE_BATCH_SIZE,
|
|
8
|
+
OPENRECEIVE_RECONCILE_SCAN_MAX_PAGES,
|
|
9
|
+
OPENRECEIVE_RECONCILE_SCAN_TIMEOUT_MS,
|
|
10
|
+
createHost,
|
|
11
|
+
createHttpHandler,
|
|
12
|
+
createIpRateLimit,
|
|
13
|
+
createProxyRateLimitingConfig,
|
|
14
|
+
createRequestId,
|
|
15
|
+
createSqlPayments,
|
|
16
|
+
createStack,
|
|
17
|
+
errorResponse,
|
|
18
|
+
hostError,
|
|
19
|
+
isServiceErrorShape,
|
|
20
|
+
isStackOptions,
|
|
21
|
+
isUnderPrefix,
|
|
22
|
+
jsonResponse,
|
|
23
|
+
knexDb,
|
|
24
|
+
mapHostRouteError,
|
|
25
|
+
maybeReconcilePayments,
|
|
26
|
+
paymentsSchemaSql,
|
|
27
|
+
prismaDb,
|
|
28
|
+
reconcileHostPayments,
|
|
29
|
+
reconcileIntervalSeconds,
|
|
30
|
+
resolveClientIp,
|
|
31
|
+
sequelizeDb,
|
|
32
|
+
startNotificationListener,
|
|
33
|
+
startNotificationWorker,
|
|
34
|
+
startReconciler,
|
|
35
|
+
typeOrmDb,
|
|
36
|
+
webRequest
|
|
37
|
+
} from "./chunk-5S24YV7E.js";
|
|
38
|
+
export {
|
|
39
|
+
HostError,
|
|
40
|
+
HttpError,
|
|
41
|
+
OPENRECEIVE_ATTEMPT_EXPIRY_GRACE_SECONDS,
|
|
42
|
+
OPENRECEIVE_MIN_RECONCILE_INTERVAL_SECONDS,
|
|
43
|
+
OPENRECEIVE_PAYMENTS_SCHEMA_VERSION,
|
|
44
|
+
OPENRECEIVE_RECONCILE_BATCH_SIZE,
|
|
45
|
+
OPENRECEIVE_RECONCILE_SCAN_MAX_PAGES,
|
|
46
|
+
OPENRECEIVE_RECONCILE_SCAN_TIMEOUT_MS,
|
|
47
|
+
createHost,
|
|
48
|
+
createHttpHandler,
|
|
49
|
+
createIpRateLimit,
|
|
50
|
+
createProxyRateLimitingConfig,
|
|
51
|
+
createRequestId,
|
|
52
|
+
createSqlPayments,
|
|
53
|
+
createStack,
|
|
54
|
+
errorResponse,
|
|
55
|
+
hostError,
|
|
56
|
+
isServiceErrorShape,
|
|
57
|
+
isStackOptions,
|
|
58
|
+
isUnderPrefix,
|
|
59
|
+
jsonResponse,
|
|
60
|
+
knexDb,
|
|
61
|
+
mapHostRouteError,
|
|
62
|
+
maybeReconcilePayments,
|
|
63
|
+
paymentsSchemaSql,
|
|
64
|
+
prismaDb,
|
|
65
|
+
reconcileHostPayments,
|
|
66
|
+
reconcileIntervalSeconds,
|
|
67
|
+
resolveClientIp,
|
|
68
|
+
sequelizeDb,
|
|
69
|
+
startNotificationListener,
|
|
70
|
+
startNotificationWorker,
|
|
71
|
+
startReconciler,
|
|
72
|
+
typeOrmDb,
|
|
73
|
+
webRequest
|
|
74
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openreceive/http",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Framework-neutral (Web Request/Response) HTTP handler for OpenReceive checkout that builds on @openreceive/node and requires its Node runtime: request routing, host integration, and payment-attempt persistence.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"bitcoin",
|
|
7
|
+
"lightning",
|
|
8
|
+
"payments",
|
|
9
|
+
"nwc",
|
|
10
|
+
"bolt11",
|
|
11
|
+
"openreceive",
|
|
12
|
+
"checkout",
|
|
13
|
+
"http"
|
|
14
|
+
],
|
|
15
|
+
"type": "module",
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"main": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@openreceive/core": "0.2.1",
|
|
21
|
+
"@openreceive/node": "0.2.1"
|
|
22
|
+
},
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"import": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./adapter-surface": {
|
|
29
|
+
"types": "./dist/adapter-surface.d.ts",
|
|
30
|
+
"import": "./dist/adapter-surface.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"README.md",
|
|
36
|
+
"LICENSE"
|
|
37
|
+
],
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsup src/index.ts src/adapter-surface.ts --format esm --dts --clean --target es2022 --out-dir dist",
|
|
40
|
+
"prepack": "npm run build"
|
|
41
|
+
},
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"author": "OpenReceive <info@openreceive.org>",
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "git+https://github.com/openreceive/openreceive.git",
|
|
47
|
+
"directory": "packages/js/http"
|
|
48
|
+
},
|
|
49
|
+
"bugs": {
|
|
50
|
+
"url": "https://github.com/openreceive/openreceive/issues"
|
|
51
|
+
},
|
|
52
|
+
"homepage": "https://openreceive.org",
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
55
|
+
},
|
|
56
|
+
"engines": {
|
|
57
|
+
"node": ">=22"
|
|
58
|
+
}
|
|
59
|
+
}
|