@openreceive/react 0.4.23 → 0.4.25

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/index.d.ts CHANGED
@@ -48,6 +48,12 @@ interface UseCheckoutOptions extends CheckoutData, Omit<CheckoutEventHandlers, "
48
48
  readonly prefix?: string;
49
49
  /** Header name the page's `<meta name="csrf-token">` is sent under; default `X-CSRF-Token`. */
50
50
  readonly csrfHeader?: string;
51
+ /**
52
+ * The fetch the status poll and the swap refund calls go through. Default
53
+ * `globalThis.fetch`. Pass one that adds an `Authorization` header when the
54
+ * app's session is a bearer token rather than a cookie.
55
+ */
56
+ readonly fetch?: typeof globalThis.fetch;
51
57
  readonly polling?: boolean;
52
58
  readonly pollIntervalMs?: number;
53
59
  }
@@ -142,10 +148,19 @@ interface CheckoutComponents {
142
148
  type CheckoutChildren = React.ReactNode | ((model: UseCheckoutResult) => React.ReactNode);
143
149
  interface CheckoutProps extends CheckoutComponentProps, CheckoutEventHandlers, Omit<React.HTMLAttributes<HTMLElement>, "children" | "prefix" | "onCopy" | "onError"> {
144
150
  /**
145
- * Create mode (`reference`, no `checkout`): the component creates the checkout against
146
- * `${prefix}/checkouts`, then polls `${prefix}/payments/check`. Later requests carry
147
- * `reference` and the displayed `payment_hash`; the host remains responsible for
148
- * authorization, order display, and routing. This fetch makes those create calls.
151
+ * The fetch every checkout request goes through, in both modes: prepare and
152
+ * create, the `${prefix}/payments/check` poll, and the swap quote, start,
153
+ * status and refund calls. Default `globalThis.fetch`, which sends the page's
154
+ * cookies. An app whose session is a bearer token (supabase-js keeps it in
155
+ * localStorage) passes a fetch that adds the `Authorization` header, so its
156
+ * `authorize` sees the same session on every call. The host remains
157
+ * responsible for authorization, order display, and routing.
158
+ */
159
+ readonly fetch?: typeof globalThis.fetch;
160
+ /**
161
+ * @deprecated The old name of `fetch`, from when it covered only the create
162
+ * calls. It now covers every request, as `fetch` does; `fetch` wins when both
163
+ * are set. It will be removed in a later release.
149
164
  */
150
165
  readonly createFetch?: typeof globalThis.fetch;
151
166
  /** `false` turns status polling off entirely. */
package/dist/index.js CHANGED
@@ -763,6 +763,9 @@ function useCheckout(options) {
763
763
  const refreshStatusRef = React6.useRef(refreshStatus);
764
764
  refreshStatusRef.current = refreshStatus;
765
765
  const polls = refreshStatus !== void 0;
766
+ const fetchRef = React6.useRef(options.fetch);
767
+ fetchRef.current = options.fetch;
768
+ const hostFetch = options.fetch !== void 0;
766
769
  const prefix = options.polling === false ? void 0 : options.prefix;
767
770
  const snapshotRef = React6.useRef(snapshot);
768
771
  snapshotRef.current = snapshot;
@@ -775,6 +778,9 @@ function useCheckout(options) {
775
778
  } : {},
776
779
  ...prefix === void 0 ? {} : { prefix },
777
780
  ...options.csrfHeader === void 0 ? {} : { csrfHeader: options.csrfHeader },
781
+ ...hostFetch ? {
782
+ fetch: (input, init) => (fetchRef.current ?? globalThis.fetch)(input, init)
783
+ } : {},
778
784
  pollIntervalMs: options.pollIntervalMs,
779
785
  // Omit logger when unset so @openreceive/browser attaches its default console sink.
780
786
  // Pass `false` through to disable; wrap custom sinks so inline host callbacks stay stable.
@@ -802,7 +808,7 @@ function useCheckout(options) {
802
808
  controller.stop();
803
809
  if (controllerRef.current === controller) controllerRef.current = null;
804
810
  };
805
- }, [checkoutIdentity, polls, prefix, options.csrfHeader, options.pollIntervalMs]);
811
+ }, [checkoutIdentity, polls, prefix, options.csrfHeader, options.pollIntervalMs, hostFetch]);
806
812
  const publicStatus = deriveStatus(state);
807
813
  const richStatus = createCheckoutStatusModel2(state);
808
814
  React6.useEffect(() => {
@@ -2992,6 +2998,7 @@ function CheckoutCreate(props) {
2992
2998
  const {
2993
2999
  onError,
2994
3000
  metadata,
3001
+ fetch: fetchProp,
2995
3002
  createFetch,
2996
3003
  className,
2997
3004
  classNames,
@@ -3012,8 +3019,8 @@ function CheckoutCreate(props) {
3012
3019
  onErrorRef.current = onError;
3013
3020
  const metadataRef = React10.useRef(metadata);
3014
3021
  metadataRef.current = metadata;
3015
- const createFetchRef = React10.useRef(createFetch);
3016
- createFetchRef.current = createFetch;
3022
+ const fetchRef = React10.useRef(fetchProp ?? createFetch);
3023
+ fetchRef.current = fetchProp ?? createFetch;
3017
3024
  const createdCheckoutRef = React10.useRef(created.checkout);
3018
3025
  createdCheckoutRef.current = created.checkout;
3019
3026
  const session = useCheckoutSession({
@@ -3026,7 +3033,7 @@ function CheckoutCreate(props) {
3026
3033
  reference: id,
3027
3034
  ...csrfHeader === void 0 ? {} : { csrfHeader },
3028
3035
  ...metadataRef.current === void 0 ? {} : { metadata: metadataRef.current },
3029
- ...createFetchRef.current === void 0 ? {} : { fetch: createFetchRef.current }
3036
+ ...fetchRef.current === void 0 ? {} : { fetch: fetchRef.current }
3030
3037
  }),
3031
3038
  // One stable CheckoutView across the mint: swapping the rendered shell
3032
3039
  // remounted PaymentWizard and wiped the payer's method selection.
@@ -3050,11 +3057,11 @@ function CheckoutCreate(props) {
3050
3057
  signal: action.signal,
3051
3058
  reference,
3052
3059
  ...csrfHeader === void 0 ? {} : { csrfHeader },
3053
- ...createFetchRef.current === void 0 ? {} : { fetch: createFetchRef.current }
3060
+ ...fetchRef.current === void 0 ? {} : { fetch: fetchRef.current }
3054
3061
  }).then(
3055
3062
  (checkout) => cancelled || !action.isCurrent() || resumePaymentHash === void 0 ? checkout : resumeCheckoutAttempt({
3056
3063
  signal: action.signal,
3057
- fetch: createFetchRef.current ?? globalThis.fetch,
3064
+ fetch: fetchRef.current ?? globalThis.fetch,
3058
3065
  prefix: resolvedPrefix,
3059
3066
  ...csrfHeader === void 0 ? {} : { csrfHeader },
3060
3067
  reference,
@@ -3167,7 +3174,9 @@ function CheckoutView(props) {
3167
3174
  prefix = OPENRECEIVE_DEFAULT_PREFIX,
3168
3175
  csrfHeader,
3169
3176
  metadata: _metadata,
3170
- createFetch: _createFetch,
3177
+ // Read by the view too: the poll and the swap calls go through it.
3178
+ fetch: fetchProp,
3179
+ createFetch,
3171
3180
  // Not `_`-prefixed like its neighbours: the view reads it, to infer
3172
3181
  // `resumable` for the refund screen. Still destructured out so it never
3173
3182
  // reaches the rendered <section>.
@@ -3206,6 +3215,7 @@ function CheckoutView(props) {
3206
3215
  className,
3207
3216
  ...sectionProps
3208
3217
  } = props;
3218
+ const hostFetch = fetchProp ?? createFetch;
3209
3219
  const checkoutModel = useCheckout({
3210
3220
  checkout,
3211
3221
  logger,
@@ -3218,7 +3228,8 @@ function CheckoutView(props) {
3218
3228
  onState,
3219
3229
  onSettled,
3220
3230
  polling,
3221
- ...pollIntervalMs === void 0 ? {} : { pollIntervalMs }
3231
+ ...pollIntervalMs === void 0 ? {} : { pollIntervalMs },
3232
+ ...hostFetch === void 0 ? {} : { fetch: hostFetch }
3222
3233
  });
3223
3234
  const theme = useTheme({
3224
3235
  defaultTheme,
@@ -3465,6 +3476,7 @@ function CheckoutView(props) {
3465
3476
  onSwapFocusChange: setSwapFocused,
3466
3477
  onLightningFocusChange: setLightningFocused,
3467
3478
  prefix,
3479
+ ...hostFetch === void 0 ? {} : { fetch: hostFetch },
3468
3480
  csrfHeader,
3469
3481
  qrEncoder,
3470
3482
  decodeLinkUrl,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openreceive/react",
3
- "version": "0.4.23",
3
+ "version": "0.4.25",
4
4
  "description": "React components and hooks for Bitcoin Lightning checkout and optional USDT, USDC, SOL and ETH swaps.",
5
5
  "keywords": [
6
6
  "bitcoin",
@@ -19,8 +19,8 @@
19
19
  "main": "./dist/index.js",
20
20
  "types": "./dist/index.d.ts",
21
21
  "dependencies": {
22
- "@openreceive/browser": "0.4.23",
23
- "@openreceive/core": "0.4.23"
22
+ "@openreceive/browser": "0.4.25",
23
+ "@openreceive/core": "0.4.25"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "react": ">=18.0.0"