@openreceive/browser 0.2.3 → 0.3.0

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/dist/headless.js CHANGED
@@ -6,6 +6,7 @@ import {
6
6
  OPENRECEIVE_CHECKOUT_ELEMENT_EVENTS,
7
7
  OPENRECEIVE_CHECKOUT_ELEMENT_PARTS,
8
8
  OPENRECEIVE_CHECKOUT_ELEMENT_PART_SELECTORS,
9
+ OPENRECEIVE_CHECKOUT_ELEMENT_SLOTS,
9
10
  OPENRECEIVE_CHECKOUT_ELEMENT_TAG_NAME,
10
11
  OPENRECEIVE_COPY_FEEDBACK_MS,
11
12
  OPENRECEIVE_DEFAULT_POLL_INTERVAL_MS,
@@ -23,7 +24,6 @@ import {
23
24
  buildMethodGridEntries,
24
25
  checkoutElementStyles,
25
26
  checkoutLabels,
26
- checkoutRoutes,
27
27
  copyInvoice,
28
28
  createBlockExplorerUrl,
29
29
  createCheckoutActionEvent,
@@ -36,7 +36,7 @@ import {
36
36
  createCheckoutStatusModel,
37
37
  createDetailExternalLink,
38
38
  createLightningInvoiceDecodeUrl,
39
- createPaymentDataEntries,
39
+ createMethodGridDisplay,
40
40
  createPaymentWizardController,
41
41
  createPaymentWizardModel,
42
42
  createPaymentWizardSelection,
@@ -57,9 +57,7 @@ import {
57
57
  enterCheckoutResumePath,
58
58
  escapeHtml,
59
59
  findReusableLightningInvoice,
60
- findSwapGridGroup,
61
60
  formatAmountCaption,
62
- formatChooseNetworkHeading,
63
61
  formatDepositAmount,
64
62
  formatFiatAmount,
65
63
  formatMsats,
@@ -69,6 +67,7 @@ import {
69
67
  getExplorerNetwork,
70
68
  getNetworkIcon,
71
69
  getPaymentMethodIcon,
70
+ getRouteIconPath,
72
71
  getRouteNetworkLabel,
73
72
  getSwapOptionIcon,
74
73
  getSwapRefundFormError,
@@ -82,10 +81,9 @@ import {
82
81
  networkCheckClasses,
83
82
  networkMobileRevealClasses,
84
83
  networkSummaryIconClasses,
84
+ normalizeSwapStartInvoice,
85
85
  openWallet,
86
- optionalSafeInteger,
87
86
  orClasses,
88
- overlaySwapRefundStaging,
89
87
  parseBooleanAttribute,
90
88
  parseMethodPickerKey,
91
89
  parseOptionalInteger,
@@ -93,25 +91,25 @@ import {
93
91
  parseResolvedTheme,
94
92
  parseThemePreference,
95
93
  paymentAccentId,
94
+ paymentIconPaths,
96
95
  paymentIconUrls,
97
96
  paymentMethods,
97
+ postJson,
98
98
  prepareCheckout,
99
- readJsonResponse,
100
99
  requestCheckout,
101
- requestHeaders,
102
- resolveBrowserLogger,
103
- resolvePreservedNetworkSelection,
100
+ requestSwapRefund,
104
101
  resolveTransactionDetailRows,
105
- sanitizeBrowserLogEntry,
102
+ resolveWizardSelection,
106
103
  selectCheckoutDisplayInvoice,
104
+ selectCurrentSwapInvoice,
105
+ startSwapRequest,
107
106
  swapAssetMatchesRoute,
108
- swapGroupLimitOption,
107
+ swapDepositRisk,
109
108
  swapOptionLimitMessage,
109
+ swapOptionLimitSentence,
110
110
  swapPickerKey,
111
- updatePaymentWizardSelection,
112
- updateSelectedSwapNetworks,
113
- wizardNetworkGroupIds
114
- } from "./chunk-JFJBHGR4.js";
111
+ updatePaymentWizardSelection
112
+ } from "./chunk-NVEGYGZ5.js";
115
113
 
116
114
  // src/internal/checkout-props.ts
117
115
  var CREATE_MODE_ONLY_PROPS = [
@@ -141,201 +139,11 @@ function validateCheckoutProps(props) {
141
139
  }
142
140
 
143
141
  // src/internal/checkout-session.ts
144
- import { recordOrEmpty as recordOrEmpty2 } from "@openreceive/core";
145
-
146
- // src/internal/swap-http.ts
147
- import { nonEmptyString, recordOrEmpty } from "@openreceive/core";
148
- async function postJson(options) {
149
- const { body } = options;
150
- const routes = checkoutRoutes(options.prefix);
151
- const reference = nonEmptyString(body.reference);
152
- const action = nonEmptyString(body.action);
153
- if (action !== void 0 && action !== "swap_quote" && action !== "refund_swap") {
154
- throw new Error(`Unrecognized checkout action ${action}.`);
155
- }
156
- emitSwapActionLog(options.logger, "requested", body);
157
- try {
158
- const result = action === "swap_quote" ? await requestJson(options, routes.swapsQuote, {
159
- reference,
160
- pay_in_asset: body.pay_in_asset
161
- }) : action === "refund_swap" ? await refundRequest(options, routes, body, reference) : await requestJson(options, routes.paymentsCheck, withoutAction(body));
162
- if (action === "refund_swap") {
163
- emitSwapActionLog(options.logger, "succeeded", body, swapActionResultFields(result));
164
- }
165
- return result;
166
- } catch (error) {
167
- emitSwapActionLog(options.logger, "failed", body, {
168
- error_message: error instanceof Error ? error.message : String(error)
169
- });
170
- throw error;
171
- }
172
- }
173
- function normalizeSwapStartInvoice(body) {
174
- const outer = recordOrEmpty(body);
175
- const swap = recordOrEmpty(outer.swap ?? body);
176
- const checkout = recordOrEmpty(swap.checkout);
177
- const paymentHash = nonEmptyString(swap.payment_hash ?? checkout.payment_hash);
178
- if (paymentHash === void 0 || nonEmptyString(swap.provider) === void 0 || nonEmptyString(swap.pay_in_asset) === void 0 || nonEmptyString(swap.deposit_address) === void 0 || nonEmptyString(swap.deposit_amount) === void 0 || nonEmptyString(swap.provider_state) === void 0 || typeof swap.provider_expires_at !== "number") {
179
- throw new Error("Swap response did not include provider instructions.");
180
- }
181
- const amountMsats = optionalSafeInteger(checkout.amount_msats, "amount_msats");
182
- return {
183
- invoice_id: paymentHash,
184
- rail: "swap",
185
- payment_hash: paymentHash,
186
- ...amountMsats === void 0 ? {} : { amount_msats: amountMsats },
187
- transaction_state: "pending",
188
- workflow_state: "invoice_created",
189
- expires_at: swap.provider_expires_at,
190
- swap: {
191
- provider: swap.provider,
192
- pay_in_asset: swap.pay_in_asset,
193
- deposit_address: swap.deposit_address,
194
- deposit_amount: swap.deposit_amount,
195
- provider_state: swap.provider_state,
196
- provider_expires_at: swap.provider_expires_at,
197
- ...copyOptionalSwapFields(swap)
198
- }
199
- };
200
- }
201
- async function startSwapRequest(options) {
202
- const logBody = {
203
- action: "start_swap",
204
- reference: options.reference,
205
- pay_in_asset: options.payInAsset
206
- };
207
- emitSwapActionLog(options.logger, "requested", logBody);
208
- try {
209
- const body = await requestJson(options, checkoutRoutes(options.prefix).swaps, {
210
- reference: options.reference,
211
- pay_in_asset: options.payInAsset
212
- });
213
- emitSwapActionLog(options.logger, "succeeded", logBody, swapActionResultFields(body));
214
- return normalizeSwapStartInvoice(body);
215
- } catch (error) {
216
- emitSwapActionLog(options.logger, "failed", logBody, {
217
- error_message: error instanceof Error ? error.message : String(error)
218
- });
219
- throw error;
220
- }
221
- }
222
- async function requestSwapRefund(options) {
223
- const payment = options.invoices.find(
224
- (invoice) => invoice != null && (invoice.swap?.attempt_id ?? invoice.invoice_id) === options.attemptId
225
- );
226
- if (payment?.payment_hash === void 0) {
227
- throw new Error("Swap refund requires the original payment hash.");
228
- }
229
- const body = await postJson({
230
- fetch: options.fetch,
231
- prefix: options.prefix,
232
- ...options.logger === void 0 ? {} : { logger: options.logger },
233
- ...options.headers === void 0 ? {} : { headers: options.headers },
234
- body: {
235
- ...options.reference === void 0 ? {} : { reference: options.reference },
236
- payment_hash: payment.payment_hash,
237
- action: "refund_swap",
238
- attempt_id: options.attemptId,
239
- refund_address: options.refundAddress,
240
- confirm: options.confirm
241
- }
242
- });
243
- return normalizeSwapStartInvoice(body);
244
- }
245
- async function refundRequest(options, routes, body, reference) {
246
- if (reference === void 0) throw new Error("Swap refund requires reference.");
247
- const refundAddress = nonEmptyString(body.refund_address);
248
- if (refundAddress === void 0) throw new Error("Swap refund requires refund_address.");
249
- const paymentHash = nonEmptyString(body.payment_hash);
250
- if (paymentHash === void 0) throw new Error("Swap refund requires payment_hash.");
251
- if (body.confirm === true) {
252
- const status2 = recordOrEmpty(
253
- await requestJson(options, routes.swapsRefunds, {
254
- reference,
255
- payment_hash: paymentHash,
256
- refund_address: refundAddress
257
- })
258
- );
259
- return { swap: status2 };
260
- }
261
- const status = recordOrEmpty(
262
- await requestJson(options, routes.swapsStatus, {
263
- reference,
264
- payment_hash: paymentHash
265
- })
266
- );
267
- return { swap: { ...status, refund_address: refundAddress } };
268
- }
269
- function withoutAction(body) {
270
- const { action: _action, ...rest } = body;
271
- return rest;
272
- }
273
- async function requestJson(options, url, body) {
274
- const fetcher = options.fetch;
275
- const response = await fetcher(url, {
276
- method: "POST",
277
- headers: requestHeaders(options.headers),
278
- body: JSON.stringify(body)
279
- });
280
- return readJsonResponse(response, "OpenReceive request failed.");
281
- }
282
- function copyOptionalSwapFields(swap) {
283
- const output = {};
284
- for (const key of [
285
- "deposit_memo",
286
- "deposit_tx_id",
287
- "payout_tx_id",
288
- "refund_tx_id",
289
- "refund_reason",
290
- "refund_amount",
291
- "attention",
292
- "attempt_id",
293
- "provider_order_id",
294
- "refund_address",
295
- "attention_reason",
296
- "deposit_received_amount",
297
- "fee"
298
- ]) {
299
- if (swap[key] !== void 0) output[key] = swap[key];
300
- }
301
- return output;
302
- }
303
- function emitSwapActionLog(logger, outcome, body, extra = {}) {
304
- const sink = resolveBrowserLogger(logger);
305
- if (sink === void 0) return;
306
- const action = nonEmptyString(body.action);
307
- if (action !== "start_swap" && action !== "refund_swap") return;
308
- const event = action === "start_swap" ? `swap.start.${outcome}` : `swap.refund.${outcome}`;
309
- const level = outcome === "failed" ? "warn" : outcome === "requested" ? "debug" : "info";
310
- try {
311
- sink(
312
- sanitizeBrowserLogEntry({
313
- level,
314
- event,
315
- message: `${action === "start_swap" ? "Swap start" : "Swap refund"} ${outcome}.`,
316
- reference: nonEmptyString(body.reference),
317
- pay_in_asset: nonEmptyString(body.pay_in_asset),
318
- ...action === "refund_swap" ? { confirm: body.confirm === true } : {},
319
- ...extra
320
- })
321
- );
322
- } catch {
323
- }
324
- }
325
- function swapActionResultFields(body) {
326
- const swap = recordOrEmpty(recordOrEmpty(body).swap ?? body);
327
- return {
328
- payment_hash: nonEmptyString(swap.payment_hash),
329
- provider_state: nonEmptyString(swap.provider_state),
330
- attention: typeof swap.attention === "boolean" ? swap.attention : void 0
331
- };
332
- }
333
-
334
- // src/internal/checkout-session.ts
142
+ import { recordOrEmpty } from "@openreceive/core";
335
143
  var SWAP_START_FAILED = "Could not prepare the payment address. Please try again.";
336
144
  var MINT_FAILED = "Could not create the Lightning invoice. Please try again.";
337
145
  function normalizeSwapQuote(body) {
338
- const quote = recordOrEmpty2(recordOrEmpty2(body).quote ?? body);
146
+ const quote = recordOrEmpty(recordOrEmpty(body).quote ?? body);
339
147
  const payInAsset = quote.pay_in_asset ?? quote.pay_asset;
340
148
  return typeof payInAsset === "string" ? { ...quote, pay_in_asset: payInAsset } : void 0;
341
149
  }
@@ -607,6 +415,9 @@ function sharedElementAttributes(options) {
607
415
  if (options.decodeLinkUrl !== void 0) {
608
416
  attributes[OPENRECEIVE_CHECKOUT_ELEMENT_ATTRIBUTES.decodeLinkUrl] = options.decodeLinkUrl;
609
417
  }
418
+ if (isSet(options.assetBaseUrl)) {
419
+ attributes[OPENRECEIVE_CHECKOUT_ELEMENT_ATTRIBUTES.assetBaseUrl] = options.assetBaseUrl;
420
+ }
610
421
  if (options.polling !== void 0) {
611
422
  attributes[OPENRECEIVE_CHECKOUT_ELEMENT_ATTRIBUTES.polling] = String(options.polling);
612
423
  }
@@ -765,6 +576,9 @@ function createCheckoutShell(snapshot, options = {}) {
765
576
  themeToggle
766
577
  };
767
578
  }
579
+
580
+ // src/headless.ts
581
+ import { createAssetBaseUrlResolver } from "@openreceive/provider-data";
768
582
  export {
769
583
  BrowserRequestError,
770
584
  OPENRECEIVE_CHECKOUT_DATA_ATTRIBUTES,
@@ -773,6 +587,7 @@ export {
773
587
  OPENRECEIVE_CHECKOUT_ELEMENT_EVENTS,
774
588
  OPENRECEIVE_CHECKOUT_ELEMENT_PARTS,
775
589
  OPENRECEIVE_CHECKOUT_ELEMENT_PART_SELECTORS,
590
+ OPENRECEIVE_CHECKOUT_ELEMENT_SLOTS,
776
591
  OPENRECEIVE_CHECKOUT_ELEMENT_TAG_NAME,
777
592
  OPENRECEIVE_COPY_FEEDBACK_MS,
778
593
  OPENRECEIVE_DEFAULT_POLL_INTERVAL_MS,
@@ -792,6 +607,7 @@ export {
792
607
  checkoutElementStyles,
793
608
  checkoutLabels,
794
609
  copyInvoice,
610
+ createAssetBaseUrlResolver,
795
611
  createBlockExplorerUrl,
796
612
  createCheckoutActionEvent,
797
613
  createCheckoutController,
@@ -808,7 +624,7 @@ export {
808
624
  createCheckoutStatusModel,
809
625
  createDetailExternalLink,
810
626
  createLightningInvoiceDecodeUrl,
811
- createPaymentDataEntries,
627
+ createMethodGridDisplay,
812
628
  createPaymentWizardController,
813
629
  createPaymentWizardModel,
814
630
  createPaymentWizardSelection,
@@ -832,9 +648,7 @@ export {
832
648
  deriveStatus,
833
649
  enterCheckoutResumePath,
834
650
  escapeHtml,
835
- findSwapGridGroup,
836
651
  formatAmountCaption,
837
- formatChooseNetworkHeading,
838
652
  formatDepositAmount,
839
653
  formatFiatAmount,
840
654
  formatMsats,
@@ -844,6 +658,7 @@ export {
844
658
  getExplorerNetwork,
845
659
  getNetworkIcon,
846
660
  getPaymentMethodIcon,
661
+ getRouteIconPath,
847
662
  getRouteNetworkLabel,
848
663
  getSwapOptionIcon,
849
664
  getSwapRefundFormError,
@@ -858,7 +673,6 @@ export {
858
673
  normalizeSwapStartInvoice,
859
674
  openWallet,
860
675
  orClasses,
861
- overlaySwapRefundStaging,
862
676
  parseBooleanAttribute,
863
677
  parseMethodPickerKey,
864
678
  parseOptionalInteger,
@@ -866,6 +680,7 @@ export {
866
680
  parseResolvedTheme,
867
681
  parseThemePreference,
868
682
  paymentAccentId,
683
+ paymentIconPaths,
869
684
  paymentIconUrls,
870
685
  paymentMethods,
871
686
  postJson,
@@ -873,19 +688,19 @@ export {
873
688
  readThemePreference,
874
689
  requestCheckout,
875
690
  requestSwapRefund,
876
- resolvePreservedNetworkSelection,
877
691
  resolveTransactionDetailRows,
692
+ resolveWizardSelection,
878
693
  selectCheckoutDisplayInvoice,
694
+ selectCurrentSwapInvoice,
879
695
  startSwapRequest,
880
696
  swapAssetMatchesRoute,
881
- swapGroupLimitOption,
697
+ swapDepositRisk,
882
698
  swapOptionLimitMessage,
699
+ swapOptionLimitSentence,
883
700
  swapPickerKey,
884
701
  syncStoredThemeControls,
885
702
  toggleStoredThemeControls,
886
703
  updatePaymentWizardSelection,
887
- updateSelectedSwapNetworks,
888
704
  validateCheckoutProps,
889
- wizardNetworkGroupIds,
890
705
  writeThemePreference
891
706
  };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { aJ as BrowserLogLevel } from './status-B1vDOhvh.js';
2
- export { aK as BrowserLogEntry, V as BrowserLogger, B as BrowserLoggerOption, X as BrowserRequestError, Y as CheckoutController, Z as CheckoutControllerOptions, k as CheckoutSnapshot, h as CheckoutState, aL as CopyInvoiceOptions, aM as GuestCheckoutResumeController, aN as GuestCheckoutResumeOptions, aO as OpenWalletOptions, aP as PrepareCheckoutOptions, aQ as QrOptions, aR as RequestCheckoutOptions, aj as Status, aS as StatusInvoiceLike, U as UnixSeconds, am as copyInvoice, ao as createCheckoutController, aT as createGuestCheckoutResume, aU as createGuestOrderFetcher, aV as createLightningUri, aW as createQrPngDataUrl, at as createQrSvg, ax as deriveStatus, ay as enterCheckoutResumePath, aG as openWallet, aH as prepareCheckout, aI as requestCheckout } from './status-B1vDOhvh.js';
1
+ import { aM as BrowserLogLevel } from './status-C-zvqBau.js';
2
+ export { aN as BrowserLogEntry, V as BrowserLogger, B as BrowserLoggerOption, X as BrowserRequestError, Y as CheckoutController, Z as CheckoutControllerOptions, g as CheckoutSnapshot, i as CheckoutState, aO as CopyInvoiceOptions, aP as GuestCheckoutResumeController, aQ as GuestCheckoutResumeOptions, aR as OpenWalletOptions, aS as PrepareCheckoutOptions, aT as QrOptions, aU as RequestCheckoutOptions, ak as Status, aV as StatusInvoiceLike, U as UnixSeconds, ap as copyInvoice, ar as createCheckoutController, aW as createGuestCheckoutResume, aX as createGuestOrderFetcher, aY as createLightningUri, aZ as createQrPngDataUrl, aw as createQrSvg, aA as deriveStatus, aB as enterCheckoutResumePath, aJ as openWallet, aK as prepareCheckout, aL as requestCheckout } from './status-C-zvqBau.js';
3
3
  import '@openreceive/provider-data';
4
4
  import '@openreceive/core';
5
5
 
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  openWallet,
14
14
  prepareCheckout,
15
15
  requestCheckout
16
- } from "./chunk-JFJBHGR4.js";
16
+ } from "./chunk-NVEGYGZ5.js";
17
17
  export {
18
18
  BrowserRequestError,
19
19
  copyInvoice,