@pybara/donate-widget 0.0.0-stage → 1.0.0-beta.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 +143 -2
- package/dist/config.d.ts +32 -0
- package/dist/i18n/en.d.ts +38 -0
- package/dist/i18n/index.d.ts +10 -0
- package/dist/index.d.ts +14 -0
- package/dist/pybara-donate.iife.js +464 -0
- package/dist/pybara-donate.js +8640 -0
- package/dist/types.d.ts +119 -0
- package/dist/ui/amount-selector.d.ts +28 -0
- package/dist/ui/recurring-options.d.ts +33 -0
- package/dist/ui/styles.d.ts +8 -0
- package/dist/widget.d.ts +55 -0
- package/package.json +64 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pybara OÜ
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,144 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Pybara Donate Widget
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A donation widget for any website: visitors give in crypto on the Internet Computer, from their own wallet, and the donation is paid to yours. One script, no server, no WordPress needed.
|
|
4
|
+
|
|
5
|
+
## Quick start
|
|
6
|
+
|
|
7
|
+
```html
|
|
8
|
+
<div id="pybara-donate"></div>
|
|
9
|
+
<script src="https://cdn.jsdelivr.net/npm/@pybara/donate-widget@beta/dist/pybara-donate.iife.js"></script>
|
|
10
|
+
<script>
|
|
11
|
+
PybaraDonate.init({
|
|
12
|
+
target: '#pybara-donate', // where the widget renders
|
|
13
|
+
recipientPrincipal: 'xxxxx-xxxxx-...', // your Pybara Wallet's principal
|
|
14
|
+
siteUrl: 'https://example.com', // your site's address
|
|
15
|
+
siteName: 'Example Charity', // the name donors see
|
|
16
|
+
});
|
|
17
|
+
</script>
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
These four options are required; every other one is optional, with the defaults in [Configuration](#configuration).
|
|
21
|
+
|
|
22
|
+
`@beta` follows the latest beta. To stay on one version, use it instead, for example `@1.0.0-beta.1`.
|
|
23
|
+
|
|
24
|
+
## ES module
|
|
25
|
+
|
|
26
|
+
In a bundled app (Vite, Next.js, …), install the package instead of the script tag:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @pybara/donate-widget@beta
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { init } from '@pybara/donate-widget';
|
|
34
|
+
|
|
35
|
+
init({
|
|
36
|
+
target: '#pybara-donate',
|
|
37
|
+
recipientPrincipal: 'xxxxx-xxxxx-...',
|
|
38
|
+
siteUrl: 'https://example.com',
|
|
39
|
+
siteName: 'Example Charity',
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The package also exports the `DonationWidget` class (what `init` returns), `destroyAll()`, and the config types — all typed.
|
|
44
|
+
|
|
45
|
+
## Before it shows
|
|
46
|
+
|
|
47
|
+
The widget stays hidden until your site is set up in [Pybara Wallet](https://pybara.io), under **Manage › Sites › Add a site without a plugin**:
|
|
48
|
+
|
|
49
|
+
1. **Your site's DNS record** lists your wallet. This needs a domain of your own: a platform subdomain (`*.replit.app` and the like) cannot hold the record.
|
|
50
|
+
2. **You accept the widget's terms** for that site, in the same place.
|
|
51
|
+
|
|
52
|
+
Until then, and whenever Pybara pauses the widget, nothing is shown, and your browser's console says why. The checkout itself pays only a wallet your site's DNS record lists, whatever the page does.
|
|
53
|
+
|
|
54
|
+
## Pricing
|
|
55
|
+
|
|
56
|
+
A single platform fee per donation: no monthly fees, no setup fees. Your rate is set by the year of your site's first donation, and locked to it for life:
|
|
57
|
+
|
|
58
|
+
- **Go live in 2026:** 1% per donation, locked for life (the founder rate)
|
|
59
|
+
- **Go live in 2027:** 1.5% per donation, locked for life
|
|
60
|
+
- **From 2028:** the then-current standard rate, published on [pybara.com](https://pybara.com)
|
|
61
|
+
|
|
62
|
+
The fee also covers the network fees. Donors give the exact amount they choose, and you receive your full share: at the founder rate, exactly 99% of every donation. The split is made on-chain by a publicly auditable canister whose code cannot change, and which refuses any fee above 3%. Your site's rate is shown in Pybara Wallet, under **Manage › Sites**.
|
|
63
|
+
|
|
64
|
+
The one exception is AutoStable: if you have a token converted to a stablecoin as it arrives, set in Pybara Wallet, the conversion's cost is deducted on top of the platform fee.
|
|
65
|
+
|
|
66
|
+
## Configuration
|
|
67
|
+
|
|
68
|
+
### Required
|
|
69
|
+
|
|
70
|
+
| Option | Type | Description |
|
|
71
|
+
|--------|------|-------------|
|
|
72
|
+
| `target` | `string \| HTMLElement` | CSS selector or element to render into |
|
|
73
|
+
| `recipientPrincipal` | `string` | Your Pybara Wallet's principal, the one your DNS record lists |
|
|
74
|
+
| `siteUrl` | `string` | Your site's address, e.g. `https://example.com`: the origin of the page the widget is on, or the checkout refuses the donation |
|
|
75
|
+
| `siteName` | `string` | The name donors see |
|
|
76
|
+
|
|
77
|
+
### Optional
|
|
78
|
+
|
|
79
|
+
| Option | Type | Default | Description |
|
|
80
|
+
|--------|------|---------|-------------|
|
|
81
|
+
| `presetAmounts` | `number[]` | `[5, 10, 25, 50]` | Up to 6 preset amounts, in the display currency, each at least 0.50 |
|
|
82
|
+
| `allowCustom` | `boolean` | `true` | Let donors enter their own amount |
|
|
83
|
+
| `allowRecurring` | `boolean` | `true` | Offer recurring donations |
|
|
84
|
+
| `defaultFrequency` | `string` | `'monthly'` | `'weekly'`, `'monthly'` or `'yearly'` |
|
|
85
|
+
| `defaultDurationInMonths` | `number \| null` | `12` | The recurring duration preselected: `3`, `6`, `12` or `24` months, or `null` for no end date; donors can change it |
|
|
86
|
+
| `tokens` | `string[]` | All supported | Tokens donors may give: `'ckUSDC'`, `'ckUSDT'`, `'ckBTC'`, `'ckETH'`, `'ICP'` |
|
|
87
|
+
| `title` | `string` | — | Shown above the amounts |
|
|
88
|
+
| `description` | `string` | — | Shown below the title |
|
|
89
|
+
| `buttonLabel` | `string` | Donate, in the widget's language | The button's label |
|
|
90
|
+
| `thankYouMessage` | `string` | — | Replaces the success screen's title, which is otherwise shown in the donor's language |
|
|
91
|
+
| `thankYouRedirectUrl` | `string` | — | Where to send donors afterwards |
|
|
92
|
+
| `primaryColor` | `string` | `'#7c3aed'` | Accent colour (hex) |
|
|
93
|
+
| `theme` | `'light' \| 'dark' \| 'auto'` | `'light'` | `'auto'` follows your page's background and its theme switcher |
|
|
94
|
+
| `currency` | `string` | `'USD'` | Display currency (ISO 4217), e.g. `'EUR'` |
|
|
95
|
+
| `locale` | `string` | Browser's | Interface language: `'en'`, `'fr'`, `'de'`, `'es'`, `'it'`, `'pt'`, `'nl'`, `'pl'`, `'ro'`, `'ja'`, `'ko'` or `'zh-CN'` |
|
|
96
|
+
| `fontUrl` | `string` | — | A `.woff2` font of your own; none is loaded otherwise |
|
|
97
|
+
| `onSuccess` | `function` | — | Called once the donation is made |
|
|
98
|
+
| `onError` | `function` | — | Called on an error |
|
|
99
|
+
| `onClose` | `function` | — | Called when the checkout is closed without donating |
|
|
100
|
+
| `staging` | `boolean` | `false` | Use Pybara's staging environment, for testing |
|
|
101
|
+
| `debug` | `boolean` | `false` | Log details to the console |
|
|
102
|
+
|
|
103
|
+
### Example with options
|
|
104
|
+
|
|
105
|
+
```js
|
|
106
|
+
PybaraDonate.init({
|
|
107
|
+
target: '#pybara-donate',
|
|
108
|
+
recipientPrincipal: 'xxxxx-xxxxx-...',
|
|
109
|
+
siteUrl: 'https://example.com',
|
|
110
|
+
siteName: 'Example Charity',
|
|
111
|
+
primaryColor: '#e11d48',
|
|
112
|
+
currency: 'EUR',
|
|
113
|
+
locale: 'fr',
|
|
114
|
+
presetAmounts: [5, 10, 25],
|
|
115
|
+
tokens: ['ckUSDC', 'ICP'],
|
|
116
|
+
buttonLabel: 'Soutenir',
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Theming
|
|
121
|
+
|
|
122
|
+
- **`light`** (default) and **`dark`** cards, or **`auto`**, which samples your page's background and follows your theme switcher and the visitor's system setting.
|
|
123
|
+
- **The accent colour** is adjusted where needed so text stays readable on the card; buttons keep your exact colour.
|
|
124
|
+
|
|
125
|
+
## Languages
|
|
126
|
+
|
|
127
|
+
English, French, German, Spanish, Italian, Portuguese, Dutch, Polish, Romanian, Japanese, Korean and Chinese (simplified), chosen from the visitor's browser unless `locale` is set. The checkout follows the same language.
|
|
128
|
+
|
|
129
|
+
## Content Security Policy
|
|
130
|
+
|
|
131
|
+
On a site with a strict Content Security Policy, allow:
|
|
132
|
+
|
|
133
|
+
- `script-src`: `https://cdn.jsdelivr.net`
|
|
134
|
+
- `frame-src`: `https://pybara.io`, where donors pay
|
|
135
|
+
- `connect-src`: `https://icp-api.io`, `https://*.raw.icp0.io` and `https://api.frankfurter.app`, for Pybara's settings and the exchange rates
|
|
136
|
+
- `img-src`: `https://assets.pybara.com`
|
|
137
|
+
|
|
138
|
+
## Learn more
|
|
139
|
+
|
|
140
|
+
[docs.pybara.com](https://docs.pybara.com/widget/overview/)
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
MIT
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { DonationWidgetConfig, Frequency } from './types.js';
|
|
2
|
+
export declare const DEFAULT_PRESET_AMOUNTS: number[];
|
|
3
|
+
export declare const DEFAULT_FREQUENCY: Frequency;
|
|
4
|
+
export declare const DEFAULT_DURATION_IN_MONTHS = 12;
|
|
5
|
+
export declare const DEFAULT_PRIMARY_COLOR = "#7c3aed";
|
|
6
|
+
export declare const DEFAULT_THEME: "light";
|
|
7
|
+
export declare const VALID_THEMES: readonly ["light", "dark", "auto"];
|
|
8
|
+
export declare const DEFAULT_CURRENCY = "USD";
|
|
9
|
+
/** Currency symbol map — add entries as needed */
|
|
10
|
+
export declare const CURRENCY_SYMBOLS: Record<string, string>;
|
|
11
|
+
/** Get the display symbol for a currency code */
|
|
12
|
+
export declare function getCurrencySymbol(currency: string): string;
|
|
13
|
+
export declare const DEFAULT_TOKENS: string[];
|
|
14
|
+
export declare const VALID_FREQUENCIES: Frequency[];
|
|
15
|
+
export declare const VALID_DURATION_MONTHS: number[];
|
|
16
|
+
/**
|
|
17
|
+
* Seconds between pulls, per frequency. Must match subs.mo's allowedFrequencies, which is the canister that actually schedules them.
|
|
18
|
+
* A duration is wall-clock time, so the number of pulls it buys is the duration divided by one of these.
|
|
19
|
+
*/
|
|
20
|
+
export declare const FREQUENCY_SECONDS: Record<Frequency, number>;
|
|
21
|
+
/** Seconds in a month, matching the 30 days subs.mo's `monthly` interval uses. */
|
|
22
|
+
export declare const MONTH_SECONDS = 2592000;
|
|
23
|
+
/** Minimum donation amount in USD */
|
|
24
|
+
export declare const MIN_DONATION_USD = 0.5;
|
|
25
|
+
/** Maximum preset amounts allowed */
|
|
26
|
+
export declare const MAX_PRESET_COUNT = 6;
|
|
27
|
+
/**
|
|
28
|
+
* Validate and merge user config with defaults.
|
|
29
|
+
* Throws on invalid required fields.
|
|
30
|
+
*/
|
|
31
|
+
export declare function resolveConfig(userConfig: DonationWidgetConfig): Required<Pick<DonationWidgetConfig, 'target' | 'recipientPrincipal' | 'siteUrl' | 'siteName' | 'presetAmounts' | 'allowCustom' | 'allowRecurring' | 'defaultFrequency' | 'defaultDurationInMonths' | 'tokens' | 'buttonLabel' | 'primaryColor' | 'theme' | 'currency' | 'debug' | 'staging'>> & Partial<Pick<DonationWidgetConfig, 'title' | 'description' | 'thankYouMessage' | 'thankYouRedirectUrl' | 'locale' | 'onSuccess' | 'onError' | 'onClose' | 'fontUrl'>>;
|
|
32
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* English translations (default)
|
|
3
|
+
*/
|
|
4
|
+
declare const en: {
|
|
5
|
+
amount: {
|
|
6
|
+
customPlaceholder: string;
|
|
7
|
+
};
|
|
8
|
+
recurring: {
|
|
9
|
+
toggleLabel: string;
|
|
10
|
+
frequency: string;
|
|
11
|
+
duration: string;
|
|
12
|
+
weekly: string;
|
|
13
|
+
monthly: string;
|
|
14
|
+
yearly: string;
|
|
15
|
+
every2min: string;
|
|
16
|
+
months3: string;
|
|
17
|
+
months6: string;
|
|
18
|
+
months12: string;
|
|
19
|
+
months24: string;
|
|
20
|
+
unlimited: string;
|
|
21
|
+
comingSoon: string;
|
|
22
|
+
notSupported: string;
|
|
23
|
+
};
|
|
24
|
+
widget: {
|
|
25
|
+
errorGeneric: string;
|
|
26
|
+
footerText: string;
|
|
27
|
+
donationFallbackName: string;
|
|
28
|
+
cryptoPayments: string;
|
|
29
|
+
donateButton: string;
|
|
30
|
+
};
|
|
31
|
+
errors: {
|
|
32
|
+
minimumDonation: string;
|
|
33
|
+
minimumToken: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export type Translations = typeof en;
|
|
37
|
+
export default en;
|
|
38
|
+
//# sourceMappingURL=en.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { default as enType } from './en.js';
|
|
2
|
+
export type Translations = typeof enType;
|
|
3
|
+
export declare const SUPPORTED_LOCALES: string[];
|
|
4
|
+
/** Detect browser locale (normalized) */
|
|
5
|
+
export declare function detectLocale(): string;
|
|
6
|
+
/** Get translations for a locale, with English fallback */
|
|
7
|
+
export declare function getTranslations(locale?: string): Translations;
|
|
8
|
+
/** Interpolate {{variable}} placeholders in a string */
|
|
9
|
+
export declare function t(template: string, values?: Record<string, string>): string;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DonationResult, DonationWidgetConfig, Frequency, RecurringConfig } from './types.js';
|
|
2
|
+
import { DonationWidget } from './widget.js';
|
|
3
|
+
/**
|
|
4
|
+
* Initialize a donation widget on the page.
|
|
5
|
+
* Can be called multiple times with different targets.
|
|
6
|
+
*/
|
|
7
|
+
export declare function init(config: DonationWidgetConfig): DonationWidget;
|
|
8
|
+
/**
|
|
9
|
+
* Destroy all active widget instances.
|
|
10
|
+
*/
|
|
11
|
+
export declare function destroyAll(): void;
|
|
12
|
+
export type { DonationResult, DonationWidgetConfig, Frequency, RecurringConfig };
|
|
13
|
+
export { DonationWidget };
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|