@pybara/pybara-js 0.6.0 → 0.8.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/pybara-js.js CHANGED
@@ -1,26 +1,26 @@
1
1
  /* Pybara.js - pybara.com */
2
2
  import { n as e, r as t, t as n } from "./admin-B1pVP25-.js";
3
- import { t as r } from "./modal-CvQ7qr5d.js";
4
- var i = {
3
+ import { r, t as i } from "./modal-BiPk8xwF.js";
4
+ var a = {
5
5
  widget: "donate-widget",
6
6
  recurring: "donate-widget-recurring"
7
7
  };
8
- function a(e, t) {
8
+ function o(e, t) {
9
9
  let n = (e) => {
10
10
  let t = /^(\d+)-(\d+)$/.exec(e);
11
11
  return t ? [Number(t[1]), Number(t[2])] : null;
12
12
  }, r = n(e), i = n(t);
13
13
  return !r || !i ? !1 : r[0] > i[0] || r[0] === i[0] && r[1] >= i[1];
14
14
  }
15
- async function o(e) {
15
+ async function s(e) {
16
16
  let t = await fetch(e);
17
17
  if (!t.ok) throw Error(`HTTP ${t.status} from ${e}`);
18
18
  return await t.json();
19
19
  }
20
- async function s(t, n, r) {
21
- let s = e[t], c = `https://${s.admin_core}.raw.icp0.io/widget-config`, l = `https://${s.admin_regs}.raw.icp0.io/widget-terms?site_url=${encodeURIComponent(n)}&principal=${encodeURIComponent(r)}`, u, d;
20
+ async function c(t, n, r) {
21
+ let i = e[t], c = `https://${i.admin_core}.raw.icp0.io/widget-config`, l = `https://${i.admin_regs}.raw.icp0.io/widget-terms?site_url=${encodeURIComponent(n)}&principal=${encodeURIComponent(r)}`, u, d;
22
22
  try {
23
- [u, d] = await Promise.all([o(c), o(l)]);
23
+ [u, d] = await Promise.all([s(c), s(l)]);
24
24
  } catch (e) {
25
25
  return {
26
26
  show: !1,
@@ -29,13 +29,13 @@ async function s(t, n, r) {
29
29
  };
30
30
  }
31
31
  let f = u.kill_switch?.plugins ?? {};
32
- return f[i.widget]?.enabled === !0 ? !d.signed || !d.version ? {
32
+ return f[a.widget]?.enabled === !0 ? !d.signed || !d.version ? {
33
33
  show: !1,
34
34
  cause: "terms",
35
35
  reason: `${n} has not accepted the widget's terms in Pybara Wallet (Manage › Sites › Add a site without a plugin)`
36
- } : a(d.version, "1-0") ? {
36
+ } : o(d.version, "1-0") ? {
37
37
  show: !0,
38
- recurring: f[i.recurring]?.enabled === !0
38
+ recurring: f[a.recurring]?.enabled === !0
39
39
  } : {
40
40
  show: !1,
41
41
  cause: "terms",
@@ -48,13 +48,116 @@ async function s(t, n, r) {
48
48
  }
49
49
  //#endregion
50
50
  //#region src/types.ts
51
- var c = class extends Error {
51
+ var l = class extends Error {
52
52
  constructor(e, t) {
53
53
  super(t), this.name = "PybaraError", this.code = e;
54
54
  }
55
- }, l = /^(0|[1-9]\d*)(\.\d+)?$/, u = /^[a-z0-9-]{1,64}$/, d = class {
55
+ };
56
+ //#endregion
57
+ //#region src/buttons.ts
58
+ function u(e) {
59
+ let t = typeof e?.height == "number" && Number.isFinite(e.height) ? Math.round(e.height) : 45;
60
+ return Math.min(55, Math.max(25, t));
61
+ }
62
+ function d(e, t) {
63
+ return e?.shape === "sharp" ? "0" : e?.shape === "rect" ? "4px" : `${t / 2}px`;
64
+ }
65
+ function f(e) {
66
+ let t = typeof e == "string" ? document.querySelector(e) : e;
67
+ if (!t) throw new l("INVALID_CONFIG", `buttons().render(): no element matches ${JSON.stringify(e)}`);
68
+ return t;
69
+ }
70
+ function p(e, t) {
71
+ if (typeof t?.createPayment != "function") throw new l("INVALID_CONFIG", "buttons(): \"createPayment\" is required, a function returning the payment from the form, e.g. () => ({ amount: form.amount.value, currency: \"EUR\" })");
72
+ let n = new URL(e.walletUrl).origin, i = [], a = null;
73
+ async function o() {
74
+ try {
75
+ let n = await t.createPayment();
76
+ await e.open({
77
+ ...n,
78
+ onSuccess: t.onSuccess,
79
+ onError: t.onError,
80
+ onClose: t.onClose
81
+ });
82
+ } catch (e) {
83
+ t.onError?.(e instanceof Error ? e : Error(String(e)));
84
+ }
85
+ }
86
+ function s(s) {
87
+ let c = f(s), l = u(t.style), p = document.createElement("div");
88
+ p.style.cssText = `position:relative;width:100%;height:${l}px;`;
89
+ let m = document.createElement("div");
90
+ m.setAttribute("aria-hidden", "true"), m.style.cssText = `position:absolute;inset:0;border-radius:${d(t.style, l)};background:rgba(128,128,128,0.16);`;
91
+ let h = document.createElement("iframe");
92
+ h.src = `${n}/button`, h.title = "Pybara", h.style.cssText = "position:absolute;inset:0;width:100%;height:100%;border:0;opacity:0;color-scheme:normal;background:transparent;", p.append(m, h), c.appendChild(p);
93
+ let g = !1, _ = null, v = {};
94
+ a ??= v;
95
+ let y = (e) => {
96
+ h.contentWindow?.postMessage(e, n);
97
+ }, b = (e) => {
98
+ _ = e, g && y({
99
+ type: "pybara_button_availability",
100
+ v: 1,
101
+ status: e.status
102
+ }), a ??= v, a === v && t.onStateChange?.(e);
103
+ }, x = setTimeout(() => {
104
+ if (g) return;
105
+ m.remove(), t.hideWhenUnavailable === !0 && (p.style.height = "0px");
106
+ let e = `Pybara: the button (${n}/button) did not load within ${r / 1e3} seconds; pybara.io may be unreachable from this browser.`;
107
+ console.warn(e), a ??= v, a === v && t.onStateChange?.({
108
+ status: "unavailable",
109
+ reason: "BUTTON_UNAVAILABLE",
110
+ detail: e
111
+ });
112
+ }, r);
113
+ h.addEventListener("load", () => {
114
+ y({
115
+ type: "pybara_button_init",
116
+ v: 1,
117
+ style: t.style ?? {},
118
+ hideWhenUnavailable: t.hideWhenUnavailable === !0
119
+ });
120
+ }, { once: !0 });
121
+ let S = (e) => {
122
+ if (e.origin !== n || e.source !== h.contentWindow) return;
123
+ let t = e.data;
124
+ t?.type === "pybara_button_ready" || t?.type === "pybara_button_resize" ? (typeof t.height == "number" && (p.style.height = `${t.height}px`), g || (g = !0, clearTimeout(x), h.style.opacity = "1", m.remove(), _ && y({
125
+ type: "pybara_button_availability",
126
+ v: 1,
127
+ status: _.status
128
+ }))) : t?.type === "pybara_button_click" && o();
129
+ };
130
+ window.addEventListener("message", S);
131
+ let C = e.subscribeAvailability(b);
132
+ i.push(() => {
133
+ clearTimeout(x), window.removeEventListener("message", S), C(), a === v && (a = null), p.remove();
134
+ });
135
+ }
136
+ return {
137
+ render: s,
138
+ destroy() {
139
+ for (let e of i.splice(0)) e();
140
+ }
141
+ };
142
+ }
143
+ //#endregion
144
+ //#region src/checkout.ts
145
+ var m = /^(0|[1-9]\d*)(\.\d+)?$/, h = /^[a-z0-9-]{1,64}$/, g = class {
56
146
  constructor(e) {
57
- this.adminClient = null, this.modal = null, this.gateOutcome = null, this.isOpen = !1, this.completedPayment = !1, this.activePayment = null, this.lastPrecheck = {}, this.config = m(e), this.ready = this.init(), this.config.onAvailability && this.precheck();
147
+ this.adminClient = null, this.modal = null, this.gateOutcome = null, this.isOpen = !1, this.completedPayment = !1, this.activePayment = null, this.lastPrecheck = {}, this.availabilityListeners = /* @__PURE__ */ new Set(), this.latestAvailability = null, this.config = y(e), this.config.onAvailability && this.availabilityListeners.add(this.config.onAvailability), this.ready = this.init(), this.config.onAvailability && this.precheck();
148
+ }
149
+ buttons(e) {
150
+ return p({
151
+ walletUrl: t[this.config.staging ? "staging" : "prod"],
152
+ open: (e) => this.open(e),
153
+ subscribeAvailability: (e) => (this.availabilityListeners.add(e), this.latestAvailability ? e(this.latestAvailability) : !this.config.onAvailability && this.availabilityListeners.size === 1 && this.precheck(this.lastPrecheck), () => {
154
+ this.availabilityListeners.delete(e);
155
+ })
156
+ }, e);
157
+ }
158
+ emitAvailability(e) {
159
+ this.latestAvailability = e;
160
+ for (let t of this.availabilityListeners) t(e);
58
161
  }
59
162
  precheck(e = {}) {
60
163
  let t = typeof e.amount == "number" && Number.isFinite(e.amount) ? String(e.amount) : e.amount;
@@ -64,25 +167,24 @@ var c = class extends Error {
64
167
  }, this.sendPrecheck();
65
168
  }
66
169
  async sendPrecheck() {
67
- let e = this.config.onAvailability;
68
- if (!e) return;
170
+ if (this.availabilityListeners.size === 0) return;
69
171
  await this.ready;
70
- let t = this.gateOutcome;
71
- if (t && !t.show) {
72
- let n = t.cause === "unreadable" ? {
172
+ let e = this.gateOutcome;
173
+ if (e && !e.show) {
174
+ let t = e.cause === "unreadable" ? {
73
175
  status: "retry-later",
74
176
  reason: "GATE_UNREADABLE",
75
- detail: `Pybara: ${t.reason}; the checkout tries again at the click.`
76
- } : t.cause === "switched-off" ? {
177
+ detail: `Pybara: ${e.reason}; the checkout tries again at the click.`
178
+ } : e.cause === "switched-off" ? {
77
179
  status: "unavailable",
78
180
  reason: "SWITCHED_OFF",
79
- detail: `Pybara: ${t.reason}.`
181
+ detail: `Pybara: ${e.reason}.`
80
182
  } : {
81
183
  status: "unavailable",
82
184
  reason: "SITE_NOT_READY",
83
- detail: `Pybara: ${t.reason}; the site owner does this, not the page. https://docs.pybara.com/pybara-js/setup/`
185
+ detail: `Pybara: ${e.reason}; the site owner does this, not the page. https://docs.pybara.com/pybara-js/setup/`
84
186
  };
85
- n.detail && console.warn(n.detail), e(n);
187
+ t.detail && console.warn(t.detail), this.emitAvailability(t);
86
188
  } else this.modal?.precheck({
87
189
  beneficiary: this.config.recipientPrincipal,
88
190
  siteUrl: this.config.siteUrl,
@@ -93,18 +195,18 @@ var c = class extends Error {
93
195
  return this.gateOutcome;
94
196
  }
95
197
  async open(e) {
96
- if (await this.ready, this.gateOutcome && !this.gateOutcome.show) throw new c("GATE_REFUSED", this.gateOutcome.reason ?? "This site cannot accept Pybara payments yet.");
97
- let t = f(e.amount);
98
- if (t === null) throw new c("INVALID_CONFIG", `open(): "amount" must be a decimal string in the currency's major units, e.g. "12.34", or a positive number — got ${JSON.stringify(e.amount)}`);
198
+ if (await this.ready, this.gateOutcome && !this.gateOutcome.show) throw new l("GATE_REFUSED", this.gateOutcome.reason ?? "This site cannot accept Pybara payments yet.");
199
+ let t = _(e.amount);
200
+ if (t === null) throw new l("INVALID_CONFIG", `open(): "amount" must be a decimal string in the currency's major units, e.g. "12.34", or a positive number — got ${JSON.stringify(e.amount)}`);
99
201
  let n = e.currency ?? this.config.currency;
100
- if (!n) throw new c("INVALID_CONFIG", "open(): \"currency\" is required — pass it to open(), or set it once in Pybara.checkout()");
101
- if (!/^[A-Z]{3}$/.test(n)) throw new c("INVALID_CONFIG", `open(): "currency" must be an uppercase ISO 4217 code, e.g. "EUR" — got ${JSON.stringify(n)}`);
102
- if (e.durationMonths != null && !e.frequency) throw new c("INVALID_CONFIG", "open(): \"durationMonths\" needs a \"frequency\"");
202
+ if (!n) throw new l("INVALID_CONFIG", "open(): \"currency\" is required — pass it to open(), or set it once in Pybara.checkout()");
203
+ if (!/^[A-Z]{3}$/.test(n)) throw new l("INVALID_CONFIG", `open(): "currency" must be an uppercase ISO 4217 code, e.g. "EUR" — got ${JSON.stringify(n)}`);
204
+ if (e.durationMonths != null && !e.frequency) throw new l("INVALID_CONFIG", "open(): \"durationMonths\" needs a \"frequency\"");
103
205
  let r = e.frequency ? {
104
206
  frequency: e.frequency,
105
207
  ...e.durationMonths == null ? {} : { durationMonths: e.durationMonths }
106
208
  } : void 0;
107
- if (r && this.gateOutcome && this.gateOutcome.show && !this.gateOutcome.recurring) throw new c("GATE_REFUSED", "Recurring payments are temporarily unavailable.");
209
+ if (r && this.gateOutcome && this.gateOutcome.show && !this.gateOutcome.recurring) throw new l("GATE_REFUSED", "Recurring payments are temporarily unavailable.");
108
210
  if (this.isOpen) return;
109
211
  this.isOpen = !0;
110
212
  let i = !1;
@@ -115,7 +217,7 @@ var c = class extends Error {
115
217
  }
116
218
  this.modal || this.initCheckoutModal();
117
219
  let a = this.modal;
118
- if (!a) throw this.isOpen = !1, new c("CHECKOUT_FAILED", "The checkout modal could not be initialised.");
220
+ if (!a) throw this.isOpen = !1, new l("CHECKOUT_FAILED", "The checkout modal could not be initialised.");
119
221
  if (i) this.isOpen = !1, a.renderTerminalState("This recipient is currently unable to accept donations."), this.initCheckoutModal();
120
222
  else {
121
223
  this.activePayment = e;
@@ -123,14 +225,14 @@ var c = class extends Error {
123
225
  a.show({
124
226
  modalData: {
125
227
  beneficiary: this.config.recipientPrincipal,
126
- salt: h(),
228
+ salt: b(),
127
229
  reference: this.config.siteName
128
230
  },
129
231
  recurring: r,
130
232
  checkout: this.checkoutFor(e, t, n)
131
233
  });
132
234
  } catch (e) {
133
- throw this.isOpen = !1, this.activePayment = null, g(e);
235
+ throw this.isOpen = !1, this.activePayment = null, x(e);
134
236
  }
135
237
  }
136
238
  }
@@ -154,44 +256,44 @@ var c = class extends Error {
154
256
  r && console.error("🧩 pybara-js: admin client init failed:", e);
155
257
  }
156
258
  })(), o = (async () => {
157
- this.config.pluginVersion || (this.gateOutcome = await s(t, this.config.siteUrl, this.config.recipientPrincipal), !this.gateOutcome.show && r && console.warn("🧩 pybara-js: gate refused —", this.gateOutcome.reason));
259
+ this.config.pluginVersion || (this.gateOutcome = await c(t, this.config.siteUrl, this.config.recipientPrincipal), !this.gateOutcome.show && r && console.warn("🧩 pybara-js: gate refused —", this.gateOutcome.reason));
158
260
  })();
159
261
  await Promise.all([a, o]);
160
262
  }
161
263
  initCheckoutModal() {
162
- let e = this.config.staging ? "staging" : "prod", n = this.config, i = this;
163
- this.modal = new r({
264
+ let e = this.config.staging ? "staging" : "prod", n = this.config, r = this;
265
+ this.modal = new i({
164
266
  walletUrl: t[e],
165
267
  context: "donation",
166
268
  thankYouMessage: n.thankYouMessage,
167
269
  locale: n.locale,
168
- onAvailability: n.onAvailability,
270
+ onAvailability: (e) => r.emitAvailability(e),
169
271
  onSuccess: (e) => {
170
- i.completedPayment = !0;
171
- let t = i.activePayment, r = t?.frequency != null, a = {
272
+ r.completedPayment = !0;
273
+ let t = r.activePayment, i = t?.frequency != null, a = {
172
274
  blockIndex: e.blockIndex,
173
275
  reference: e.reference,
174
276
  token: e.token,
175
- recurring: r,
277
+ recurring: i,
176
278
  frequency: t?.frequency,
177
- durationMonths: r ? t?.durationMonths ?? void 0 : void 0,
178
- isUnlimited: r && t?.durationMonths == null,
279
+ durationMonths: i ? t?.durationMonths ?? void 0 : void 0,
280
+ isUnlimited: i && t?.durationMonths == null,
179
281
  payerPrincipal: e.payerPrincipal,
180
282
  recipientPrincipal: n.recipientPrincipal
181
283
  };
182
284
  t?.onSuccess?.(a);
183
285
  },
184
286
  onError: (e) => {
185
- i.isOpen = !1;
186
- let t = i.activePayment;
187
- i.activePayment = null, t?.onError?.(g(e)), i.modal = null, i.initCheckoutModal();
287
+ r.isOpen = !1;
288
+ let t = r.activePayment;
289
+ r.activePayment = null, t?.onError?.(x(e)), r.modal = null, r.initCheckoutModal();
188
290
  },
189
291
  onClose: () => {
190
- i.isOpen = !1;
191
- let e = i.activePayment;
192
- i.activePayment = null, e?.onClose?.(), i.completedPayment && n.thankYouRedirectUrl ? window.location.href = n.thankYouRedirectUrl : (i.completedPayment = !1, i.modal = null, i.initCheckoutModal());
292
+ r.isOpen = !1;
293
+ let e = r.activePayment;
294
+ r.activePayment = null, e?.onClose?.(), r.completedPayment && n.thankYouRedirectUrl ? window.location.href = n.thankYouRedirectUrl : (r.completedPayment = !1, r.modal = null, r.initCheckoutModal());
193
295
  }
194
- }), n.onAvailability && this.modal && Object.keys(this.lastPrecheck).length > 0 && this.sendPrecheck();
296
+ }), this.availabilityListeners.size > 0 && this.modal && Object.keys(this.lastPrecheck).length > 0 && this.sendPrecheck();
195
297
  }
196
298
  checkoutFor(e, t, n) {
197
299
  let r = this.config;
@@ -245,11 +347,11 @@ var c = class extends Error {
245
347
  n.rel = "preconnect", n.href = new URL(t[e]).origin, n.crossOrigin = "anonymous", document.head.appendChild(n);
246
348
  }
247
349
  };
248
- function f(e) {
350
+ function _(e) {
249
351
  let t = typeof e == "number" && Number.isFinite(e) ? String(e) : e;
250
- return typeof t != "string" || !l.test(t) || !/[1-9]/.test(t) ? null : t;
352
+ return typeof t != "string" || !m.test(t) || !/[1-9]/.test(t) ? null : t;
251
353
  }
252
- function p(e) {
354
+ function v(e) {
253
355
  let t = e.trim();
254
356
  if (!t) return null;
255
357
  let n;
@@ -260,14 +362,14 @@ function p(e) {
260
362
  }
261
363
  return n.protocol !== "https:" && n.protocol !== "http:" ? null : n.origin + n.pathname.replace(/\/+$/, "");
262
364
  }
263
- function m(e) {
264
- if (!e.recipientPrincipal) throw new c("INVALID_CONFIG", "Pybara.checkout: \"recipientPrincipal\" is required");
265
- if (!e.siteUrl) throw new c("INVALID_CONFIG", "Pybara.checkout: \"siteUrl\" is required");
266
- let t = p(e.siteUrl);
267
- if (!t) throw new c("INVALID_CONFIG", `Pybara.checkout: "siteUrl" is not a valid http(s) URL: ${e.siteUrl}`);
268
- if (!e.siteName) throw new c("INVALID_CONFIG", "Pybara.checkout: \"siteName\" is required");
269
- if (e.currency != null && !/^[A-Z]{3}$/.test(e.currency)) throw new c("INVALID_CONFIG", `Pybara.checkout: "currency" must be an uppercase ISO 4217 code, e.g. "EUR" — got ${JSON.stringify(e.currency)}`);
270
- if (e.platform != null && !u.test(e.platform)) throw new c("INVALID_CONFIG", "Pybara.checkout: \"platform\" must be a lowercase slug (a-z, 0-9, -), at most 64 characters");
365
+ function y(e) {
366
+ if (!e.recipientPrincipal) throw new l("INVALID_CONFIG", "Pybara.checkout: \"recipientPrincipal\" is required");
367
+ if (!e.siteUrl) throw new l("INVALID_CONFIG", "Pybara.checkout: \"siteUrl\" is required");
368
+ let t = v(e.siteUrl);
369
+ if (!t) throw new l("INVALID_CONFIG", `Pybara.checkout: "siteUrl" is not a valid http(s) URL: ${e.siteUrl}`);
370
+ if (!e.siteName) throw new l("INVALID_CONFIG", "Pybara.checkout: \"siteName\" is required");
371
+ if (e.currency != null && !/^[A-Z]{3}$/.test(e.currency)) throw new l("INVALID_CONFIG", `Pybara.checkout: "currency" must be an uppercase ISO 4217 code, e.g. "EUR" — got ${JSON.stringify(e.currency)}`);
372
+ if (e.platform != null && !h.test(e.platform)) throw new l("INVALID_CONFIG", "Pybara.checkout: \"platform\" must be a lowercase slug (a-z, 0-9, -), at most 64 characters");
271
373
  return {
272
374
  ...e,
273
375
  siteUrl: t,
@@ -275,18 +377,18 @@ function m(e) {
275
377
  debug: e.debug ?? !1
276
378
  };
277
379
  }
278
- function h() {
380
+ function b() {
279
381
  let e = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16));
280
382
  return btoa(String.fromCharCode(...e));
281
383
  }
282
- function g(e) {
384
+ function x(e) {
283
385
  return e instanceof Error ? e : Error(String(e));
284
386
  }
285
387
  //#endregion
286
388
  //#region src/index.ts
287
- function _(e) {
288
- return new d(e);
389
+ function S(e) {
390
+ return new g(e);
289
391
  }
290
- var v = { checkout: _ };
392
+ var C = { checkout: S };
291
393
  //#endregion
292
- export { v as Pybara, d as PybaraCheckout, c as PybaraError, _ as checkout };
394
+ export { C as Pybara, g as PybaraCheckout, l as PybaraError, S as checkout };
package/dist/types.d.ts CHANGED
@@ -86,6 +86,39 @@ export interface PaymentParams {
86
86
  /** Called when the payer closes the modal — after success or on manual close. */
87
87
  onClose?: () => void;
88
88
  }
89
+ /** The payment a button's createPayment() returns: open()'s params, without the callbacks, which buttons() takes itself. */
90
+ export type ButtonPayment = Omit<PaymentParams, 'onSuccess' | 'onError' | 'onClose'>;
91
+ /** Options for checkout.buttons(): a "Pybara" button, served by Pybara, that opens this checkout on click. */
92
+ export interface ButtonsOptions {
93
+ /**
94
+ * Passed to the button as given, and read by it: `color` 'brand' | 'black' | 'white' (PayPal's names; its 'gold', 'blue' and 'silver' read as 'brand'), `shape` 'pill' | 'rect' | 'sharp', `height` 25–55 px (PayPal's range, default 45).
95
+ * Copy a PayPal button's style and the two match. A value the button doesn't know falls back to its default.
96
+ */
97
+ style?: {
98
+ color?: string;
99
+ shape?: string;
100
+ height?: number;
101
+ };
102
+ /** Collapse the button to no height when Pybara is unavailable on this page; by default its slot stays, empty, so the layout never moves. */
103
+ hideWhenUnavailable?: boolean;
104
+ /** Called on the payer's click: the payment from the form's current values, as open() takes it (amount, currency, frequency, donor fields). */
105
+ createPayment: () => ButtonPayment | Promise<ButtonPayment>;
106
+ /** The button's availability, the checkout's answer as onAvailability gives it: update the page around the button with it, e.g. show `message` below the minimum. */
107
+ onStateChange?: (availability: Availability) => void;
108
+ /** Called once the payment is confirmed on-chain. */
109
+ onSuccess?: (result: CheckoutResult) => void;
110
+ /** A refusal, from createPayment(), open() or the checkout. */
111
+ onError?: (error: Error) => void;
112
+ /** The payer closed the checkout. */
113
+ onClose?: () => void;
114
+ }
115
+ /** What checkout.buttons() returns. */
116
+ export interface PybaraButtons {
117
+ /** Draw a button in the element (or the first element matching the selector), at the style's height and the element's full width. Call it again to draw another button with the same options. */
118
+ render(container: string | HTMLElement): void;
119
+ /** Remove every button these options drew, and stop listening for them. */
120
+ destroy(): void;
121
+ }
89
122
  /** Result passed to the onSuccess callback once the payment is confirmed. */
90
123
  export interface CheckoutResult {
91
124
  /** Ledger block index of the confirmed transaction, as the frame reports it. */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,8IAA8I;AAC9I,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,WAAW,CAAC;AAEtE,iEAAiE;AACjE,MAAM,WAAW,cAAc;IAC7B,uKAAuK;IACvK,kBAAkB,EAAE,MAAM,CAAC;IAC3B,gIAAgI;IAChI,OAAO,EAAE,MAAM,CAAC;IAChB,iHAAiH;IACjH,QAAQ,EAAE,MAAM,CAAC;IACjB,uLAAuL;IACvL,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mDAAmD;IACnD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,yJAAyJ;IACzJ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2FAA2F;IAC3F,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,8CAA8C;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2PAA2P;IAC3P,QAAQ,C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C,IAAI,EAAE,eAAe,CAAC;gBAEnB,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM;CAKnD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pybara/pybara-js",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "description": "Accept crypto payments and donations with Pybara on any page — a callable checkout, in the stripe-js / paypal-js convention.",
5
5
  "keywords": [
6
6
  "pybara",