@pybara/pybara-js 0.1.0 → 0.2.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/README.md CHANGED
@@ -10,10 +10,14 @@ You keep your own UI — payment-method list, amount selector, form fields. `Pyb
10
10
  npm install @pybara/pybara-js
11
11
  ```
12
12
 
13
- No bundler? The IIFE build exposes `window.Pybara`:
13
+ No bundler? The IIFE build exposes `window.Pybara` — the same calls as the module:
14
14
 
15
15
  ```html
16
16
  <script src="https://unpkg.com/@pybara/pybara-js/dist/pybara-js.iife.js"></script>
17
+ <script>
18
+ const pybara = Pybara.checkout({ siteUrl, siteName, recipientPrincipal });
19
+ // await pybara.open({ amount: 100 }) on click — identical to the ESM surface
20
+ </script>
17
21
  ```
18
22
 
19
23
  ## Add Pybara as a payment method
@@ -0,0 +1,135 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://docs.pybara.com/pybara-js/checkout.schema.json",
4
+ "title": "Pybara.checkout() config",
5
+ "description": "Config object for Pybara.checkout() in @pybara/pybara-js — bind once per site. The checkout refuses to open until the site is verified in Pybara Wallet (_pybara-payto DNS record) and the widget terms are accepted. The open() payment params are under #/$defs/payment.",
6
+ "type": "object",
7
+ "additionalProperties": false,
8
+ "required": ["recipientPrincipal", "siteUrl", "siteName"],
9
+ "properties": {
10
+ "recipientPrincipal": {
11
+ "type": "string",
12
+ "minLength": 1,
13
+ "description": "Recipient's wallet principal — the same one the site's _pybara-payto DNS record lists. The registry does not serve it; the integrator passes it."
14
+ },
15
+ "siteUrl": {
16
+ "type": "string",
17
+ "minLength": 1,
18
+ "description": "The site's URL as registered in Pybara Wallet, e.g. 'https://example.com'. Normalized by the SDK: a bare domain reads as https, query/fragment/default ports/trailing slashes drop, a path is kept."
19
+ },
20
+ "siteName": {
21
+ "type": "string",
22
+ "minLength": 1,
23
+ "description": "Site display name — shown in the checkout frame and stored as the subscription name on recurring payments."
24
+ },
25
+ "currency": {
26
+ "type": "string",
27
+ "pattern": "^[A-Za-z]{3}$",
28
+ "default": "USD",
29
+ "description": "Fiat currency the amounts passed to open() are in (ISO 4217, e.g. 'EUR'). Converted to USD for payment."
30
+ },
31
+ "siteCountry": {
32
+ "type": "string",
33
+ "pattern": "^[A-Za-z]{2}$",
34
+ "description": "Site base country (ISO 3166-1 alpha-2)."
35
+ },
36
+ "notifyEmail": {
37
+ "type": "string",
38
+ "description": "Site operator's contact email — terms warnings, per-payment notification emails."
39
+ },
40
+ "notifyDonations": {
41
+ "type": "boolean",
42
+ "default": true,
43
+ "description": "false silences the per-payment notification email at notifyEmail."
44
+ },
45
+ "thankYouMessage": {
46
+ "type": "string",
47
+ "description": "Replaces the success screen's default title."
48
+ },
49
+ "thankYouRedirectUrl": {
50
+ "type": "string",
51
+ "format": "uri",
52
+ "description": "Redirect target once the payer leaves the success screen (PDF receipt, member area)."
53
+ },
54
+ "recipientTosVersion": {
55
+ "type": "string",
56
+ "description": "The terms version the recipient (site operator) accepted, e.g. '1-0' — forwarded so settle stores it with the payment log."
57
+ },
58
+ "recipientTosAcceptedAt": {
59
+ "type": "string",
60
+ "format": "date-time",
61
+ "description": "Recipient terms acceptance timestamp (ISO 8601 UTC) — same forwarding role as recipientTosVersion."
62
+ },
63
+ "pluginVersion": {
64
+ "type": "string",
65
+ "description": "The integration version forwarding the payment — set by Pybara plugins only. When set, the widget terms gate is skipped: plugins check their own terms server-side."
66
+ },
67
+ "staging": {
68
+ "type": "boolean",
69
+ "default": false,
70
+ "description": "Staging environment — staging canisters and staging.pybara.io. Never on a live site."
71
+ },
72
+ "debug": {
73
+ "type": "boolean",
74
+ "default": false,
75
+ "description": "Console diagnostics."
76
+ }
77
+ },
78
+ "$defs": {
79
+ "payment": {
80
+ "title": "checkout.open() params",
81
+ "description": "One payment attempt — the params of a single open() call.",
82
+ "type": "object",
83
+ "additionalProperties": false,
84
+ "required": ["amount"],
85
+ "properties": {
86
+ "amount": {
87
+ "type": "number",
88
+ "exclusiveMinimum": 0,
89
+ "description": "Amount in the checkout's currency; the USD equivalent must be ≥ $0.50."
90
+ },
91
+ "currency": {
92
+ "type": "string",
93
+ "pattern": "^[A-Za-z]{3}$",
94
+ "description": "Per-call fiat override (ISO 4217) — defaults to the checkout's currency."
95
+ },
96
+ "frequency": {
97
+ "enum": ["weekly", "monthly", "yearly", "every2min"],
98
+ "description": "Recurring pull interval — omit for a one-time payment. 'every2min' exists for testing."
99
+ },
100
+ "durationMonths": {
101
+ "enum": [3, 6, 12, 24],
102
+ "description": "Recurring length in months — omit with frequency for an unlimited subscription."
103
+ },
104
+ "donorIsAnonymous": {
105
+ "type": "boolean",
106
+ "description": "Hide the payer's identity on the public record."
107
+ },
108
+ "donorMessage": {
109
+ "type": "string",
110
+ "description": "Message from the payer to the recipient — seeds the field the payer can edit on the confirm screen."
111
+ },
112
+ "wantsTaxReceipt": {
113
+ "type": "boolean",
114
+ "description": "Prefills the 'I'd like a tax receipt' checkbox — shown only when the recipient is registered and issues receipts."
115
+ },
116
+ "donorFirstName": { "type": "string" },
117
+ "donorLastName": { "type": "string" },
118
+ "donorEmail": { "type": "string", "description": "Prefills the receipt-address field — a payer who leaves an email gets a payment record." },
119
+ "donorCompany": { "type": "string" },
120
+ "donorCountry": { "type": "string" },
121
+ "donorAddressLine1": { "type": "string" },
122
+ "donorAddressLine2": { "type": "string" },
123
+ "donorAddressCity": { "type": "string" },
124
+ "donorAddressState": { "type": "string" },
125
+ "donorAddressPostalCode": { "type": "string" },
126
+ "donorAddressCountry": { "type": "string" },
127
+ "donorTosVersion": { "type": "string", "description": "Terms version the payer accepted, if the host collected one." },
128
+ "donorTosAcceptedAt": { "type": "string", "format": "date-time" },
129
+ "onSuccess": { "description": "function (CheckoutResult) => void — called once the payment is confirmed on-chain; not expressible in JSON." },
130
+ "onError": { "description": "function (Error) => void — called on frame-level errors; not expressible in JSON." },
131
+ "onClose": { "description": "function () => void — called when the payer closes the checkout; not expressible in JSON." }
132
+ }
133
+ }
134
+ }
135
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../src/checkout.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,KAAK,cAAc,EAEnB,KAAK,aAAa,EAEnB,MAAM,SAAS,CAAC;AAUjB;;;;;;GAMG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAyB;IAChD,OAAO,CAAC,WAAW,CAAkC;IACrD,OAAO,CAAC,QAAQ,CAAO;IACvB,OAAO,CAAC,KAAK,CAA8B;IAC3C,OAAO,CAAC,IAAI,CAA2B;IACvC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,aAAa,CAA8B;IACnD,iHAAiH;IACjH,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgB;gBAE1B,UAAU,EAAE,cAAc;IAKtC;;;;OAIG;IACG,IAAI,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IA+DjD,4EAA4E;IAC5E,KAAK,IAAI,IAAI;YAIC,IAAI;IAqClB,OAAO,CAAC,iBAAiB;IAkDzB;;;OAGG;IACH,OAAO,CAAC,cAAc;IAgDtB,6FAA6F;IAC7F,OAAO,CAAC,gBAAgB;CAOzB"}
1
+ {"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../src/checkout.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,KAAK,cAAc,EAEnB,KAAK,aAAa,EAEnB,MAAM,SAAS,CAAC;AAUjB;;;;;;GAMG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAyB;IAChD,OAAO,CAAC,WAAW,CAAkC;IACrD,OAAO,CAAC,QAAQ,CAAO;IACvB,OAAO,CAAC,KAAK,CAA8B;IAC3C,OAAO,CAAC,IAAI,CAA2B;IACvC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,aAAa,CAA8B;IACnD,iHAAiH;IACjH,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgB;gBAE1B,UAAU,EAAE,cAAc;IAKtC;;;;OAIG;IACG,IAAI,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAkEjD,4EAA4E;IAC5E,KAAK,IAAI,IAAI;YAIC,IAAI;IAqClB,OAAO,CAAC,iBAAiB;IAkDzB;;;OAGG;IACH,OAAO,CAAC,cAAc;IAgDtB,6FAA6F;IAC7F,OAAO,CAAC,gBAAgB;CAOzB"}
package/dist/gate.d.ts CHANGED
@@ -1,14 +1,20 @@
1
1
  /**
2
- * Gate for autonomous embeds (no plugin): kill switches + the widget's terms of service.
2
+ * Gate for autonomous embeds (no plugin): the widget terms + the donate kill switches.
3
3
  *
4
4
  * A custom form built on Pybara.checkout() is the same product surface as the donate widget — a site embeds it under the widget's terms.
5
5
  * The two packages share no code, so the gate is duplicated on each side: keep the response shape and the semantics in sync with widget-core/src/gate.ts.
6
6
  */
7
- export interface WidgetGate {
8
- show: boolean;
9
- reason: string | null;
10
- }
11
- /** Old signature pages are superseded by the floor — a signature below the floor counts as unsigned. */
7
+ /** The widget terms version this release requires: raised only by a release that needs new terms, so most updates keep showing on sites that accepted older ones. */
12
8
  export declare const REQUIRED_WIDGET_TERMS_VERSION = "1-0";
13
- export declare function checkWidgetGate(env: 'prod' | 'staging', siteOrigin: string, principal: string): Promise<WidgetGate>;
9
+ export type WidgetGate = {
10
+ show: false;
11
+ reason: string;
12
+ } | {
13
+ show: true;
14
+ recurring: boolean;
15
+ };
16
+ /** Whether `accepted` is at least `required`, both `major-minor`, compared as numbers. */
17
+ export declare function versionAtLeast(accepted: string, required: string): boolean;
18
+ /** Reads core's /widget-config and regs' /widget-terms in parallel, and says whether the checkout may open, and with recurring. */
19
+ export declare function checkWidgetGate(env: 'prod' | 'staging', siteUrl: string, recipientPrincipal: string): Promise<WidgetGate>;
14
20
  //# sourceMappingURL=gate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"gate.d.ts","sourceRoot":"","sources":["../src/gate.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AAEH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED,wGAAwG;AACxG,eAAO,MAAM,6BAA6B,QAAQ,CAAC;AAoBnD,wBAAsB,eAAe,CACnC,GAAG,EAAE,MAAM,GAAG,SAAS,EACvB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,UAAU,CAAC,CA4CrB"}
1
+ {"version":3,"file":"gate.d.ts","sourceRoot":"","sources":["../src/gate.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AAEH,qKAAqK;AACrK,eAAO,MAAM,6BAA6B,QAAQ,CAAC;AAKnD,MAAM,MAAM,UAAU,GAAG;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAAC;AAW9F,0FAA0F;AAC1F,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAS1E;AAQD,mIAAmI;AACnI,wBAAsB,eAAe,CACnC,GAAG,EAAE,MAAM,GAAG,SAAS,EACvB,OAAO,EAAE,MAAM,EACf,kBAAkB,EAAE,MAAM,GACzB,OAAO,CAAC,UAAU,CAAC,CAkCrB"}
package/dist/index.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import { PybaraCheckout } from './checkout';
2
2
  import { CheckoutConfig } from './types';
3
+ /**
4
+ * Bind a site once — resolves the recipient record, the fiat rate and the terms gate,
5
+ * and prewarms the checkout iframe so open() is instant on the payer's click.
6
+ */
7
+ export declare function checkout(config: CheckoutConfig): PybaraCheckout;
3
8
  export declare const Pybara: {
4
- /**
5
- * Bind a site once — resolves the recipient record, the fiat rate and the terms gate,
6
- * and prewarms the checkout iframe so open() is instant on the payer's click.
7
- */
8
- checkout(config: CheckoutConfig): PybaraCheckout;
9
+ checkout: typeof checkout;
9
10
  };
10
11
  export { PybaraCheckout } from './checkout';
11
12
  export { type CheckoutConfig, type CheckoutResult, type Frequency, type PaymentParams, PybaraError, type PybaraErrorCode, } from './types';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,eAAO,MAAM,MAAM;IACjB;;;OAGG;qBACc,cAAc,GAAG,cAAc;CAGjD,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,WAAW,EACX,KAAK,eAAe,GACrB,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,cAAc,CAE/D;AAID,eAAO,MAAM,MAAM;;CAAe,CAAC;AAEnC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,WAAW,EACX,KAAK,eAAe,GACrB,MAAM,SAAS,CAAC"}