create-usebecky 0.0.0-stage → 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 +80 -2
- package/dist/create.js +842 -0
- package/dist/extension-skill/usebecky-extension/SKILL.md +181 -0
- package/dist/extension-skill/usebecky-extension/references/accounts.md +125 -0
- package/dist/extension-skill/usebecky-extension/references/dev-server.md +102 -0
- package/dist/extension-skill/usebecky-extension/references/manifest.md +104 -0
- package/dist/extension-skill/usebecky-extension/references/oauth-and-tokens.md +179 -0
- package/dist/extension-skill/usebecky-extension/references/partner-api.md +87 -0
- package/dist/extension-skill/usebecky-extension/references/submit-and-pricing.md +31 -0
- package/dist/extension-skill/usebecky-extension/references/ui.md +172 -0
- package/dist/extension-skill/usebecky-extension/references/webhooks.md +97 -0
- package/dist/index.js +10 -0
- package/dist/keys.js +72 -0
- package/dist/platform.js +104 -0
- package/dist/pm.js +69 -0
- package/dist/prompts.js +242 -0
- package/dist/scaffold.js +108 -0
- package/dist/setup.js +130 -0
- package/dist/shared/ai.js +203 -0
- package/dist/shared/extension-skill.js +107 -0
- package/dist/shared/framework.js +460 -0
- package/dist/shared/hosted.js +8 -0
- package/dist/shared/ui.js +141 -0
- package/dist/skill/usebecky/SKILL.md +339 -0
- package/dist/skill/usebecky/references/access-rules.md +307 -0
- package/dist/skill/usebecky/references/addons.md +68 -0
- package/dist/skill/usebecky/references/analytics.md +166 -0
- package/dist/skill/usebecky/references/android.md +434 -0
- package/dist/skill/usebecky/references/auth.md +379 -0
- package/dist/skill/usebecky/references/cache.md +51 -0
- package/dist/skill/usebecky/references/components.md +127 -0
- package/dist/skill/usebecky/references/emails.md +105 -0
- package/dist/skill/usebecky/references/expo.md +147 -0
- package/dist/skill/usebecky/references/functions.md +99 -0
- package/dist/skill/usebecky/references/hosting.md +119 -0
- package/dist/skill/usebecky/references/http-api.md +233 -0
- package/dist/skill/usebecky/references/ios.md +355 -0
- package/dist/skill/usebecky/references/payments.md +493 -0
- package/dist/skill/usebecky/references/realtime.md +143 -0
- package/dist/skill/usebecky/references/scheduled-jobs.md +82 -0
- package/dist/skill/usebecky/references/sdk.md +838 -0
- package/dist/skill/usebecky/references/storage.md +210 -0
- package/dist/skill/usebecky/references/templates.md +191 -0
- package/dist/skill/usebecky/references/wordpress.md +87 -0
- package/dist/templates.js +74 -0
- package/package.json +37 -4
- package/templates/expo/App.tsx +48 -0
- package/templates/expo/README.md +59 -0
- package/templates/expo/_env.example +4 -0
- package/templates/expo/_gitignore +12 -0
- package/templates/expo/app.json +25 -0
- package/templates/expo/assets/icon.png +0 -0
- package/templates/expo/brand.ts +7 -0
- package/templates/expo/components/Avatar.tsx +75 -0
- package/templates/expo/components/ui.tsx +57 -0
- package/templates/expo/index.ts +4 -0
- package/templates/expo/lib/theme.ts +43 -0
- package/templates/expo/lib/usebecky.ts +15 -0
- package/templates/expo/package.json +29 -0
- package/templates/expo/screens/Home.tsx +187 -0
- package/templates/expo/screens/SignIn.tsx +112 -0
- package/templates/expo/tsconfig.json +6 -0
- package/templates/expo/usebecky.template.json +36 -0
- package/templates/extension/README.md +128 -0
- package/templates/extension/_env.example +21 -0
- package/templates/extension/_gitignore +11 -0
- package/templates/extension/logo.svg +1 -0
- package/templates/extension/package.json +25 -0
- package/templates/extension/src/accounts.ts +90 -0
- package/templates/extension/src/app.ts +178 -0
- package/templates/extension/src/pages.ts +108 -0
- package/templates/extension/src/replay-guard.ts +17 -0
- package/templates/extension/src/server.ts +57 -0
- package/templates/extension/src/settings.ts +69 -0
- package/templates/extension/src/ui.ts +70 -0
- package/templates/extension/test/app.test.ts +222 -0
- package/templates/extension/tsconfig.json +16 -0
- package/templates/extension/usebecky-extension.json +36 -0
- package/templates/extension/usebecky.template.json +22 -0
- package/templates/landing/README.md +43 -0
- package/templates/landing/_env.example +4 -0
- package/templates/landing/_gitignore +9 -0
- package/templates/landing/index.html +16 -0
- package/templates/landing/package.json +28 -0
- package/templates/landing/public/icon.svg +1 -0
- package/templates/landing/src/App.tsx +97 -0
- package/templates/landing/src/components/Contact.tsx +43 -0
- package/templates/landing/src/components/Counter.tsx +34 -0
- package/templates/landing/src/components/Feedback.tsx +36 -0
- package/templates/landing/src/components/Logo.tsx +11 -0
- package/templates/landing/src/components/Receipt.tsx +128 -0
- package/templates/landing/src/components/Setup.tsx +20 -0
- package/templates/landing/src/components/fields.tsx +63 -0
- package/templates/landing/src/content.ts +22 -0
- package/templates/landing/src/index.css +119 -0
- package/templates/landing/src/lib/usebecky.ts +11 -0
- package/templates/landing/src/lib/waitlist.ts +46 -0
- package/templates/landing/src/main.tsx +12 -0
- package/templates/landing/src/vite-env.d.ts +6 -0
- package/templates/landing/tsconfig.json +19 -0
- package/templates/landing/usebecky.template.json +20 -0
- package/templates/landing/vite.config.ts +10 -0
- package/templates/notes/README.md +68 -0
- package/templates/notes/_env.example +4 -0
- package/templates/notes/_gitignore +9 -0
- package/templates/notes/index.html +15 -0
- package/templates/notes/package.json +28 -0
- package/templates/notes/public/icon.svg +1 -0
- package/templates/notes/src/App.tsx +35 -0
- package/templates/notes/src/brand.ts +7 -0
- package/templates/notes/src/components/Composer.tsx +113 -0
- package/templates/notes/src/components/NoteEntry.tsx +151 -0
- package/templates/notes/src/components/Notes.tsx +163 -0
- package/templates/notes/src/components/Setup.tsx +44 -0
- package/templates/notes/src/components/SignIn.tsx +112 -0
- package/templates/notes/src/components/icons.tsx +54 -0
- package/templates/notes/src/index.css +105 -0
- package/templates/notes/src/lib/notes.ts +68 -0
- package/templates/notes/src/lib/usebecky.ts +9 -0
- package/templates/notes/src/main.tsx +22 -0
- package/templates/notes/src/vite-env.d.ts +6 -0
- package/templates/notes/tsconfig.json +19 -0
- package/templates/notes/usebecky.template.json +34 -0
- package/templates/notes/vite.config.ts +10 -0
- package/templates/saas/README.md +69 -0
- package/templates/saas/_env.example +10 -0
- package/templates/saas/_gitignore +11 -0
- package/templates/saas/app/(app)/account/ManageBilling.tsx +26 -0
- package/templates/saas/app/(app)/account/page.tsx +71 -0
- package/templates/saas/app/(app)/dashboard/Projects.tsx +227 -0
- package/templates/saas/app/(app)/dashboard/page.tsx +21 -0
- package/templates/saas/app/(app)/layout.tsx +29 -0
- package/templates/saas/app/(app)/premium/page.tsx +62 -0
- package/templates/saas/app/auth/callback/page.tsx +33 -0
- package/templates/saas/app/globals.css +143 -0
- package/templates/saas/app/icon.svg +1 -0
- package/templates/saas/app/layout.tsx +20 -0
- package/templates/saas/app/page.tsx +87 -0
- package/templates/saas/app/pricing/Plans.tsx +133 -0
- package/templates/saas/app/pricing/TestCardHint.tsx +18 -0
- package/templates/saas/app/pricing/page.tsx +21 -0
- package/templates/saas/app/setup/page.tsx +34 -0
- package/templates/saas/app/sign-in/SignInForm.tsx +195 -0
- package/templates/saas/app/sign-in/page.tsx +21 -0
- package/templates/saas/brand.ts +10 -0
- package/templates/saas/components/AppNav.tsx +45 -0
- package/templates/saas/components/Logo.tsx +22 -0
- package/templates/saas/components/SiteHeader.tsx +50 -0
- package/templates/saas/components/Status.tsx +15 -0
- package/templates/saas/lib/session.ts +26 -0
- package/templates/saas/lib/usebecky.ts +11 -0
- package/templates/saas/next-env.d.ts +5 -0
- package/templates/saas/next.config.ts +5 -0
- package/templates/saas/package.json +26 -0
- package/templates/saas/postcss.config.mjs +3 -0
- package/templates/saas/tsconfig.json +21 -0
- package/templates/saas/usebecky.template.json +31 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Emails
|
|
2
|
+
|
|
3
|
+
Every email a project's users get is in Dashboard → Emails (sidebar): **All emails** (every email, rendered; click to edit), **Sent** (log + delivery status + blocked addresses), **Brand** (app name, logo, colour, email footer), **Sender** (sender name, reply-to, own domain, advanced SMTP). Emails are sent through usebecky's email provider: nothing to set up, delivery is tracked. Newsletters to many people are a separate feature (Dashboard → Newsletter; `sdk.md` section 13). Guide: https://usebecky.com/docs/guides/emails.
|
|
4
|
+
|
|
5
|
+
## Dashboard-only (no code)
|
|
6
|
+
|
|
7
|
+
- Built-in emails: confirm sign-up, magic link, password reset, invite, email change (always on), welcome (off by default; once per user after confirming, or after sign-up when confirmation is off, or after a first social login with a verified email; never for users created with the secret key or in the dashboard). Plus form auto-replies and newsletter confirmations (set up in Forms / Newsletter).
|
|
8
|
+
- Editing: subject, heading, text (plain text, no HTML), button text, small print. Variables `{{app_name}}`, `{{email}}`, `{{name}}` (from `user_metadata.name`), `{{site_url}}`, plus `{{link}}` and `{{code}}` in the sign-in emails. A line containing only `{{code}}` shows the code big. Unknown variables are rejected; sign-in emails must keep a button, `{{link}}` or `{{code}}`.
|
|
9
|
+
- Brand (Emails → Brand): logo (PNG/JPG/SVG/WebP ≤ 2 MB, normalized), colour (button + links), app name. Used by every branded email (templates, `emails.send` without `html`, forms, newsletter).
|
|
10
|
+
- Footer (Emails → Brand → Email footer): company name, postal address, privacy / imprint / terms links, contact email; "More details": company details (EU/German businesses usually need them in business emails), help page, extra text per language, per-language links. Shown at the bottom of every branded email. Raw `html` sends are sent as is: tell the user to add their own footer there.
|
|
11
|
+
- Sender (Emails → Sender): sender name, reply-to. **Own domain** (Pro: 1 per project, Business: 5): add the domain, copy the DNS records (3 DKIM CNAMEs, MX + SPF TXT on `bounce.<domain>`, optional DMARC TXT), "Check now", then pick the From address. Free: shared usebecky address with the app name as sender name. Advanced: the project's own SMTP provider (Pro+), wins over the domain.
|
|
12
|
+
- Sent emails are kept 30 days (addresses masked; sign-in links and codes hidden in the stored copy). Emails go to real inboxes also while developing.
|
|
13
|
+
- Mobile apps: the 6-digit `{{code}}` is the easiest sign-in on a phone (links open the browser, not the app): `verifyCode` in every SDK.
|
|
14
|
+
|
|
15
|
+
## Languages
|
|
16
|
+
|
|
17
|
+
Built-in translations (all built-in emails + layout words + footer labels): en, de, fr, es, it, nl, pt, pl. Any other BCP-47 code can be added as a custom language (the customer writes the text; until then the default language's text is used). Turn languages on in Emails → Languages → Manage (≤ 20, one default). Pro/Business can translate with AI in the editor (200 / 1,000 translations per month).
|
|
18
|
+
|
|
19
|
+
The server picks each email's language: per-call `locale` → the user's `user_metadata.locale` → the request's `Accept-Language` → the project's default language (exact `pt-BR` → `pt` → next step; invalid codes are ignored, never an error). Browsers send `Accept-Language` by themselves, so most web apps need no code. Never build your own translation of the built-in emails.
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
// src/lib/usebecky.ts: the app has its own language picker → tell usebecky (optional)
|
|
23
|
+
import { createClient } from 'usebecky'
|
|
24
|
+
|
|
25
|
+
export const baas = createClient(import.meta.env.VITE_USEBECKY_PUBLISHABLE_KEY, { locale: 'de' }) // Accept-Language on every request
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
// inside an async function:
|
|
30
|
+
baas.setLocale('fr') // later, when the user switches language (null = the browser's language again)
|
|
31
|
+
await baas.auth.updateUser({ data: { locale: 'fr' } }) // remembered for every later email, also ones sent from a server
|
|
32
|
+
await baas.auth.resetPassword('ada@example.com', { locale: 'fr' }) // one email only; also signUp, sendMagicLink, resend(email, type, { locale }), updateUser({ email, locale })
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Swift: `UseBecky.Options(locale: "de")`, `baas.setLocale("de")`, `locale:` on `signUp`, `sendMagicLink`, `resetPassword`, `resend`, `updateUser`; default `Accept-Language` = the device's preferred languages. Kotlin: `UseBecky(..., locale = "de")`, `baas.setLocale("de")`, `locale =` on the same calls; default = `Locale.getDefault()`. Server: `baas.auth.admin.inviteUser(email, { locale })`, `baas.emails.send({ locale })`.
|
|
36
|
+
|
|
37
|
+
## Send your own email (server only, secret key)
|
|
38
|
+
|
|
39
|
+
Never from a browser or an app: the call needs the secret key. A Swift, Kotlin or Expo app asks your server (or reacts to a webhook event there), and the server sends.
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
// send-email.ts: server only (needs USEBECKY_SECRET_KEY in the environment)
|
|
43
|
+
import { baas } from 'usebecky/server'
|
|
44
|
+
|
|
45
|
+
// Your own words in the branded layout (logo, colour, footer)
|
|
46
|
+
const { data, error } = await baas.emails.send({
|
|
47
|
+
to: 'ada@example.com', // one address per call
|
|
48
|
+
subject: 'Your order shipped',
|
|
49
|
+
heading: 'Good news!', // optional
|
|
50
|
+
text: 'Order #42 is on its way.\n\nTrack it below.', // blank line = new paragraph
|
|
51
|
+
buttonText: 'Track order', // optional, needs buttonUrl (http/https)
|
|
52
|
+
buttonUrl: 'https://myapp.com/orders/42',
|
|
53
|
+
replyTo: 'support@myapp.com', // optional
|
|
54
|
+
locale: 'de', // optional: language of the layout words (footer links, "button not working?")
|
|
55
|
+
}) // { data: { id, status? } } (id of the entry in Emails → Sent)
|
|
56
|
+
|
|
57
|
+
// A template the customer made in Dashboard → Emails → New email (id slug), in the person's language
|
|
58
|
+
await baas.emails.send({ to: 'ada@example.com', template: 'order-shipped', data: { order_id: '42' }, locale: 'de' })
|
|
59
|
+
// missing data for a {{blank}} → 400 listing them; unknown template id → 404 listing the ids. Free: 3 own templates, paid: unlimited
|
|
60
|
+
|
|
61
|
+
// Attachments, scheduling, tags, exactly-once
|
|
62
|
+
await baas.emails.send({
|
|
63
|
+
to: 'ada@example.com', subject: 'Your invoice', text: 'Attached.',
|
|
64
|
+
attachments: [{ filename: 'invoice.pdf', content: Buffer.from('%PDF-1.7 ...'), contentType: 'application/pdf' }], // ≤ 10 files, 5 MB Free / 10 MB paid; no executables/scripts
|
|
65
|
+
sendAt: new Date(Date.now() + 3600_000), // ≤ 7 days ahead → status 'scheduled'; baas.emails.cancel(id) while scheduled
|
|
66
|
+
tags: [{ name: 'order', value: '42' }], // ≤ 10; filter in Emails → Sent; included in email.* events
|
|
67
|
+
idempotencyKey: 'invoice-42', // Idempotency-Key header: same key within 24 h = no second email (409 if the body differs)
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
// Many at once (≤ 100; each counts toward limits; per-email results in order)
|
|
71
|
+
const batch = await baas.emails.batch([{ to: 'a@x.com', subject: 'Hi', text: 'Hello' }, { to: 'b@x.com', template: 'weekly-report' }])
|
|
72
|
+
// batch.data.results: [{ id, status?, error: UseBeckyError | null }]
|
|
73
|
+
|
|
74
|
+
// Status and delivery events
|
|
75
|
+
if (data) await baas.emails.get(data.id) // { data: { id, status, to, subject, template, locale, tags, reason, created_at, send_at, events: [{ type, at, reason? }] } }
|
|
76
|
+
// Own HTML instead of the layout: baas.emails.send({ to, subject, html }) (sent as is: no logo, no footer; heading/button not allowed with html)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Any other server language: `POST /email/v1/send` with the secret key (body in snake_case: `to, subject, text, html, heading, button_text, button_url, reply_to, locale, template, data, attachments: [{ filename, content (base64), content_type }], send_at, tags`; optional `Idempotency-Key` header). Also `POST /email/v1/batch` (`{ emails: [...] }`), `GET /email/v1/emails/:id`, `DELETE /email/v1/emails/:id` (cancel a scheduled one).
|
|
80
|
+
|
|
81
|
+
```sh
|
|
82
|
+
curl -s -X POST "$USEBECKY_URL/email/v1/send" -H "apikey: $USEBECKY_SECRET_KEY" -H 'content-type: application/json' \
|
|
83
|
+
-d '{"to":"ada@example.com","template":"order-shipped","data":{"order_id":"42"},"locale":"de"}'
|
|
84
|
+
# → {"id": "<email log id>"}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Statuses: `scheduled`, `sent` (handed to the provider), `delivered`, `delayed`, `bounced`, `complained` (marked as spam), `suppressed` (not sent: address blocked), `failed`, `cancelled`.
|
|
88
|
+
|
|
89
|
+
| Error | Status | Meaning |
|
|
90
|
+
|---|---|---|
|
|
91
|
+
| `secret_key_required` | 403 | Sent with the publishable key: move the call to a server |
|
|
92
|
+
| `invalid_email` | 400 | Bad address, unknown field, or heading/button together with `html` |
|
|
93
|
+
| `recipient_suppressed` | 422 | The address bounced or marked an email as spam before (Emails → Sent → Blocked addresses → "Allow again") |
|
|
94
|
+
| `email_sending_paused` | 403 | The project's emails are paused (too many bounces / spam complaints); fix the list, then contact support |
|
|
95
|
+
| `rate_limited` | 429 | More than 60 per minute per project |
|
|
96
|
+
| `email_daily_limit` | 429 | Rolling 24 h cap: 100 on Free, 10,000 on paid plans (only your own emails count) |
|
|
97
|
+
| `smtp_*` | 502 | The project's own SMTP server refused it (`smtp_auth_failed`, `smtp_recipient_rejected`, ...); `details.email_id` points to the log |
|
|
98
|
+
| `email_send_failed` | 503 | The shared sender is down; retry later |
|
|
99
|
+
|
|
100
|
+
Blocked addresses (suppression list): permanent bounces and spam complaints are added automatically; sign-in endpoints still answer normally (never reveal it). Projects with ≥ 100 emails in 30 days and > 5% permanent bounces or > 0.3% complaints are paused (`email_sending_paused`); fix the list, then contact support.
|
|
101
|
+
|
|
102
|
+
## Events
|
|
103
|
+
|
|
104
|
+
- `email.sent`, `email.delivered`, `email.delayed`, `email.bounced`, `email.complained`, `email.suppressed`, `email.failed` (developer webhooks; `baas.events.on('email.bounced', ...)` or `'email.*'`): `{ email: { id, to (masked), template_id, kind, subject, status, reason, error, tags, locale, created_at }, user_id }`. Never sent for test emails.
|
|
105
|
+
- Onboarding sequences: keep the welcome email off and call `baas.emails.send` from a `user.created` event handler (`sdk.md` section 9). Delayed emails: `sendAt` (≤ 7 days) or a scheduled job that calls your server (`scheduled-jobs.md`).
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# Expo / React Native
|
|
2
|
+
|
|
3
|
+
Expo and React Native apps are JavaScript: they use the `usebecky` npm package (`createClient` from `usebecky`) with the publishable key, never the Swift or Kotlin SDKs. Every call returns `{ data, error }` and never throws, like the rest of the JS SDK (`sdk.md`). Guide with complete files: https://usebecky.com/docs/frameworks/expo. A ready-made Expo starter: `npx usebecky create` (pick Expo).
|
|
4
|
+
|
|
5
|
+
## Rules
|
|
6
|
+
|
|
7
|
+
1. `.env` holds only `EXPO_PUBLIC_USEBECKY_URL` and `EXPO_PUBLIC_USEBECKY_PUBLISHABLE_KEY` (`npx usebecky init` writes exactly these). `EXPO_PUBLIC_` values are compiled into the app, so never put the secret key (`ub_sk_...`) there or anywhere in the app. Sending push or emails and admin work run on a server.
|
|
8
|
+
2. Create the client once with `storage: AsyncStorage` (users stay signed in after a restart) and `detectSessionInUrl: false` (no address bar).
|
|
9
|
+
3. Deep links use the `scheme` in `app.json`: set it to your reverse-domain app id, `"scheme": "com.example.mynotes"` (the same as `ios.bundleIdentifier` / `android.package`). Use your app's bundle ID (iOS) / application ID (Android) as the scheme: it is unique to your app, so another app can't register the same scheme and catch the sign-in. Replace `com.example.mynotes` with your own bundle ID / application ID.
|
|
10
|
+
4. Allowed redirect URLs (Dashboard → Auth → Settings): `com.example.mynotes://**`, plus `exp://**` only while you develop in Expo Go. Remove `exp://**` before you publish.
|
|
11
|
+
5. Restart with `npx expo start -c` after editing `.env` or `app.json`.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
`npx expo install usebecky @react-native-async-storage/async-storage expo-web-browser expo-linking react-native-get-random-values`.
|
|
16
|
+
|
|
17
|
+
## Client
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
// lib/usebecky.ts
|
|
21
|
+
import 'react-native-get-random-values' // crypto.getRandomValues for PKCE social sign-in; keep it first
|
|
22
|
+
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
23
|
+
import { createClient } from 'usebecky'
|
|
24
|
+
|
|
25
|
+
export const baas = createClient(process.env.EXPO_PUBLIC_USEBECKY_URL!, process.env.EXPO_PUBLIC_USEBECKY_PUBLISHABLE_KEY!, {
|
|
26
|
+
storage: AsyncStorage,
|
|
27
|
+
detectSessionInUrl: false,
|
|
28
|
+
})
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Files in `lib/` import it as `./usebecky`; screens at the root as `./lib/usebecky`.
|
|
32
|
+
|
|
33
|
+
Email language: React Native doesn't reliably send the phone's language, so pass it for sign-in emails in the user's language: `locale: getLocales()[0]?.languageTag` (from `expo-localization`) in the options above, or `baas.setLocale(...)` later (`emails.md`).
|
|
34
|
+
|
|
35
|
+
## Sign-in
|
|
36
|
+
|
|
37
|
+
Email and a 6-digit code work everywhere, Expo Go included: `baas.auth.sendMagicLink(email, { createUser: true })`, then `baas.auth.verifyCode(email, code)`.
|
|
38
|
+
|
|
39
|
+
Sign in with Apple (iOS; recommend it first on iPhones, no redirect needed). Needs a development build, not Expo Go, plus Dashboard → Auth → Sign-in methods → Apple → on, with the bundle ID under "iOS bundle ID / Android client IDs (for native sign-in)":
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
// lib/apple-sign-in.ts
|
|
43
|
+
import * as AppleAuthentication from 'expo-apple-authentication'
|
|
44
|
+
import * as Crypto from 'expo-crypto'
|
|
45
|
+
import { baas } from './usebecky'
|
|
46
|
+
|
|
47
|
+
/** Shows Apple's sheet (throws ERR_REQUEST_CANCELED if the user cancels), then signs in. */
|
|
48
|
+
export async function signInWithApple() {
|
|
49
|
+
const rawNonce = Crypto.randomUUID()
|
|
50
|
+
const hashedNonce = await Crypto.digestStringAsync(Crypto.CryptoDigestAlgorithm.SHA256, rawNonce) // hex
|
|
51
|
+
const credential = await AppleAuthentication.signInAsync({
|
|
52
|
+
requestedScopes: [AppleAuthentication.AppleAuthenticationScope.FULL_NAME, AppleAuthentication.AppleAuthenticationScope.EMAIL],
|
|
53
|
+
nonce: hashedNonce,
|
|
54
|
+
})
|
|
55
|
+
if (!credential.identityToken) throw new Error('Apple returned no identity token.')
|
|
56
|
+
return baas.auth.signInWithIdToken({ provider: 'apple', token: credential.identityToken, nonce: rawNonce }) // { data: { user, session }, error }
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Google / GitHub in the in-app browser. PKCE is automatic (needs `crypto.getRandomValues`: the `react-native-get-random-values` import above; without it the SDK warns and falls back to tokens in the URL): `signInWith` puts a code challenge in the URL and keeps the verifier; `setSessionFromUrl` swaps the one-time `?code=` for the session (no tokens in the URL):
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
// lib/google-sign-in.ts
|
|
64
|
+
import * as Linking from 'expo-linking'
|
|
65
|
+
import * as WebBrowser from 'expo-web-browser'
|
|
66
|
+
import { baas } from './usebecky'
|
|
67
|
+
|
|
68
|
+
/** Returns an error message to show, or null (signed in, or the user closed the browser). */
|
|
69
|
+
export async function signInWithGoogle(): Promise<string | null> {
|
|
70
|
+
const redirectTo = Linking.createURL('auth') // com.example.mynotes://auth in a build, exp://<computer>/--/auth in Expo Go
|
|
71
|
+
const { data, error } = await baas.auth.signInWith('google', { redirectTo, skipBrowserRedirect: true })
|
|
72
|
+
if (error) return error.message
|
|
73
|
+
const result = await WebBrowser.openAuthSessionAsync(data.url, redirectTo)
|
|
74
|
+
if (result.type !== 'success') return null // the user closed the browser
|
|
75
|
+
const signedIn = await baas.auth.setSessionFromUrl(result.url)
|
|
76
|
+
return signedIn.error ? signedIn.error.message : null
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
- The browser shows the Site URL and doesn't close: the redirect URL isn't allowed (rule 4).
|
|
81
|
+
- Bot protection for sign-in needs a captcha widget (`captchaToken` on `signUp`, `signIn`, `sendMagicLink`, `resetPassword`; `auth.md`). An app can't show one easily; keep sign-in protection off for apps and protect web forms instead.
|
|
82
|
+
|
|
83
|
+
## Push notifications
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
// lib/push.ts
|
|
87
|
+
import * as Notifications from 'expo-notifications'
|
|
88
|
+
import { baas } from './usebecky'
|
|
89
|
+
|
|
90
|
+
// Call after sign-in, e.g. from a "Turn on notifications" button
|
|
91
|
+
export async function turnOnNotifications() {
|
|
92
|
+
const { status } = await Notifications.requestPermissionsAsync()
|
|
93
|
+
if (status !== 'granted') return null
|
|
94
|
+
const device = await Notifications.getDevicePushTokenAsync() // the phone's APNs / FCM token, not the Expo push token
|
|
95
|
+
const { data, error } = await baas.push.register({ platform: device.type === 'ios' ? 'ios' : 'android', token: device.data as string, appId: 'com.example.mynotes' })
|
|
96
|
+
if (error) console.warn(error.message)
|
|
97
|
+
return data // PushDevice
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Push and the native Apple sheet need a development build (`npx expo install expo-dev-client`, then `eas build --profile development --platform ios|android`): Expo Go can't receive push on Android, and on iOS its token belongs to Expo Go. Android also needs `google-services.json` and `"googleServicesFile": "./google-services.json"` under `"android"` in `app.json`. Credentials go in Dashboard → Push notifications → Setup; sending is server-side (`sdk.md` section 14). Check it works: Dashboard → Push notifications → Devices lists the phone.
|
|
102
|
+
|
|
103
|
+
## Payments (Stripe)
|
|
104
|
+
|
|
105
|
+
Outside a browser `checkout()` returns `{ url }` without redirecting. App links work as `successUrl` / `cancelUrl` when allowed (rule 4); the server bounces Stripe back to them.
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
// lib/upgrade.ts
|
|
109
|
+
import * as Linking from 'expo-linking'
|
|
110
|
+
import * as WebBrowser from 'expo-web-browser'
|
|
111
|
+
import { baas } from './usebecky'
|
|
112
|
+
|
|
113
|
+
export async function upgradeToPro(): Promise<{ isPro: boolean; error: string | null }> {
|
|
114
|
+
const returnTo = Linking.createURL('checkout') // com.example.mynotes://checkout in a build
|
|
115
|
+
const { data, error } = await baas.payments.checkout('pro_monthly', { successUrl: returnTo, cancelUrl: returnTo })
|
|
116
|
+
if (error) return { isPro: false, error: error.message }
|
|
117
|
+
const res = await WebBrowser.openAuthSessionAsync(data.url, returnTo)
|
|
118
|
+
if (res.type !== 'success' || !res.url.includes('session_id=')) return { isPro: false, error: null } // closed or canceled
|
|
119
|
+
const { data: isPro } = await baas.payments.waitForAccess('pro') // the webhook lands a few seconds later
|
|
120
|
+
return { isPro: isPro === true, error: null }
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Mention the App Store / Google Play rules for digital goods when adding Stripe to an app.
|
|
125
|
+
|
|
126
|
+
## Forms, newsletter, files, realtime
|
|
127
|
+
|
|
128
|
+
Same JS calls as on the web: `baas.forms.submit('contact', { name, email, message })` (never send `_gotcha`; clear the form's "Allowed websites" for apps), `baas.newsletter.subscribe(email, { tags: ['app'] })`, `baas.realtime.subscribe(...)` (`sdk.md`). Uploads from the device: give `upload()` a `FormData` holding the file's `uri`:
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
// lib/avatar.ts
|
|
132
|
+
import * as ImagePicker from 'expo-image-picker'
|
|
133
|
+
import { baas } from './usebecky'
|
|
134
|
+
|
|
135
|
+
export async function pickAndUploadAvatar() {
|
|
136
|
+
const user = baas.auth.getSession().data.session?.user
|
|
137
|
+
const picked = await ImagePicker.launchImageLibraryAsync({ mediaTypes: ['images'], quality: 0.8 })
|
|
138
|
+
if (!user || picked.canceled) return null
|
|
139
|
+
const asset = picked.assets[0]
|
|
140
|
+
const form = new FormData()
|
|
141
|
+
// React Native's FormData takes { uri, name, type } for a file (TypeScript's DOM types don't know it, hence `as any`)
|
|
142
|
+
form.append('file', { uri: asset.uri, name: 'avatar.jpg', type: asset.mimeType ?? 'image/jpeg' } as any)
|
|
143
|
+
const { data, error } = await baas.storage.from('avatars').upload(`${user.id}/avatar.jpg`, form, { upsert: true })
|
|
144
|
+
if (error) console.warn(error.message)
|
|
145
|
+
return data // { path, fullPath, id }
|
|
146
|
+
}
|
|
147
|
+
```
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# Functions (your own code on usebecky)
|
|
2
|
+
|
|
3
|
+
A function is one TypeScript/JavaScript file with one handler. It runs on usebecky's servers, so the app needs no server of its own for webhooks, emails after sign-up, payments follow-ups or nightly jobs. Use a function instead of `usebecky/server` on your own server whenever the project has no server. Guide: https://usebecky.com/docs/guides/functions.
|
|
4
|
+
|
|
5
|
+
## Writing one
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
// usebecky/functions/hello.ts
|
|
9
|
+
import type { FunctionHandler } from 'usebecky/server'
|
|
10
|
+
|
|
11
|
+
const handler: FunctionHandler = async (req, ctx) => {
|
|
12
|
+
const name = new URL(req.url).searchParams.get('name') ?? 'world'
|
|
13
|
+
console.log('Saying hello to', name) // shows in Dashboard → Logs → Functions
|
|
14
|
+
return Response.json({ message: `Hello, ${name}!` })
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default handler
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
- `req`: the request (Fetch API `Request`): `req.method`, `req.headers`, `await req.json()`, `await req.text()`.
|
|
21
|
+
- `ctx.baas`: an admin client for the project, already signed in (no keys in your code): `ctx.baas.admin.from('table')` (bypasses access rules), `ctx.baas.as(req)` (as the calling user, rules apply), `ctx.baas.auth.admin`, `ctx.baas.emails.send()`, `ctx.baas.push.send()`, `ctx.baas.functions.invoke()`.
|
|
22
|
+
- `ctx.user`: the signed-in user who called it (`{ id, email, role, app_metadata, user_metadata, ... }`) or `null`.
|
|
23
|
+
- `ctx.env`: secrets from Functions → Secrets (or `npx usebecky functions secrets set NAME=value`). Never hard-code API keys.
|
|
24
|
+
- `ctx.event`: the event when a trigger started it (see below), else `null`. `ctx.trigger`: `'http' | 'schedule' | 'event' | 'database' | 'test'`.
|
|
25
|
+
- Return a `Response`, or a plain value: objects become JSON, strings text, nothing 204.
|
|
26
|
+
|
|
27
|
+
Rules of the runtime: Node 24, `fetch()` for every outgoing call (public internet only; private and local addresses are blocked; `node:http`, `node:net` and WebSockets are not available), files only in the current (temporary) folder, no child processes. Limits per plan, per project: Free 2 functions, 10 s per run, 128 MB; Pro 10 functions, 30 s, 256 MB; Business unlimited functions, 300 s, 1 GB. For the whole team (all its projects added up): runs a month Free 10,000, Pro 250,000, Business 3,000,000; compute time (the CPU time functions actually use; waiting for `fetch()` or the database doesn't count) Free 1 hour, Pro 20 hours, Business 200 hours a month. At the team's limit, in every project of the team, Free answers `402 compute_quota_exceeded` until the 1st (UTC) or an upgrade; Pro and Business keep running slower (half the CPU, 2 runs at a time, a run may wait a few seconds; `429 function_busy` past 30 s). Keep heavy work out of hot paths (cache results in a table or Storage). Crypto-mining is forbidden: requests to pools' mining endpoints are refused (their websites and APIs work), and mining traffic to a pool the function's own code names stops the run and suspends the project's functions (`403 functions_suspended`). Request and response bodies up to 6 MB. Cookies set by a function are dropped.
|
|
28
|
+
|
|
29
|
+
Written in the dashboard: one file, imports only `usebecky` and Node built-ins (`node:crypto`, ...), no `enum`/`namespace`. With npm packages or several files: write them in `usebecky/functions/` and deploy with the CLI (bundled with esbuild).
|
|
30
|
+
|
|
31
|
+
## Deploying (CLI)
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install --save-dev esbuild # once: the CLI bundles with your esbuild
|
|
35
|
+
npx usebecky functions new send-welcome # writes usebecky/functions/send-welcome.ts
|
|
36
|
+
npx usebecky functions new hook --template receive-webhook # templates: empty, hello, welcome-email, grant-credits, receive-webhook, nightly-cleanup
|
|
37
|
+
npx usebecky functions deploy # every function in usebecky/functions/ (or: deploy send-welcome)
|
|
38
|
+
npx usebecky functions secrets set STRIPE_SECRET_KEY=sk_live_... WEBHOOK_SECRET=whsec_...
|
|
39
|
+
npx usebecky functions logs send-welcome --errors # latest runs with their console output
|
|
40
|
+
npx usebecky functions list
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Files and folders starting with `_` in `usebecky/functions/` are shared code (import them from functions). Every deploy is a new version; roll back with one click in Dashboard → Functions → Versions.
|
|
44
|
+
|
|
45
|
+
## Calling one (HTTP trigger)
|
|
46
|
+
|
|
47
|
+
URL: `<project API>/functions/v1/<name>` (plus any extra path), any method. Who may call it is set per function: **public** (anyone with the publishable key), **signed-in users only**, or **servers only** (secret key).
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
// src/components/SendWelcome.tsx
|
|
51
|
+
import { baas } from '../lib/usebecky'
|
|
52
|
+
|
|
53
|
+
export function SendWelcome() {
|
|
54
|
+
async function send() {
|
|
55
|
+
// Sends the publishable key and the signed-in user's token (so ctx.user is set).
|
|
56
|
+
const { data, error } = await baas.functions.invoke('send-welcome', { body: { plan: 'pro' } })
|
|
57
|
+
if (error) return alert(error.message) // error.code: function_error, function_timeout, not_signed_in, ...
|
|
58
|
+
console.log(data) // parsed JSON (or text)
|
|
59
|
+
}
|
|
60
|
+
return <button onClick={send}>Send</button>
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
// inside an async function:
|
|
66
|
+
import { baas } from 'usebecky/server'
|
|
67
|
+
|
|
68
|
+
const report = await baas.functions.invoke('monthly-report', { method: 'GET', query: { month: '2026-11' } }) // secret key: "servers only" works
|
|
69
|
+
const asUser = await baas.as('user-access-token').functions.invoke('members') // as the user who called your server
|
|
70
|
+
console.log(report.data, asUser.data)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Options: `body` (objects → JSON; strings, Blob, FormData raw), `method` (default POST), `headers`, `query`, `path` (extra path), `responseType: 'text' | 'blob'`. Swift: `try await baas.functions.invoke("send-welcome", body: ["plan": "pro"])`; Kotlin: `baas.functions.invoke("send-welcome", body = mapOf("plan" to "pro"))`; any other stack: `POST /functions/v1/<name>` with the `apikey` header (`references/http-api.md`).
|
|
74
|
+
|
|
75
|
+
Webhooks from other services (Stripe, GitHub, a shop): a public function with the publishable key in the URL, `https://<api>/functions/v1/receive-webhook?apikey=ub_pk_...`, and a signature check with a secret from `ctx.env` (template "Receive a webhook").
|
|
76
|
+
|
|
77
|
+
## Other triggers (set up in Dashboard → Functions → Triggers)
|
|
78
|
+
|
|
79
|
+
- **Events**: any platform event (`user.created`, `purchase.completed`, `subscription.created`, `form.submitted`, `email.failed`, ...). `ctx.event` is the same envelope a webhook gets: `{ id, type, created_at, project, data }`. Failed runs are retried (10 s, 1 m, 5 m, 30 m, 2 h); answering 4xx stops the retries.
|
|
80
|
+
- **Schedule**: a scheduled job "Run a function" (`ctx.event.type === 'job.run'`, `ctx.event.data.job.name`).
|
|
81
|
+
- **Database changes**: a database webhook with a function as target (`ctx.event.type` = `db.row.inserted | db.row.updated | db.row.deleted`, `ctx.event.data` = `{ table, record, old_record }`).
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
// usebecky/functions/welcome-email.ts
|
|
85
|
+
import type { FunctionHandler } from 'usebecky/server'
|
|
86
|
+
|
|
87
|
+
// Trigger: the "user.created" event.
|
|
88
|
+
const handler: FunctionHandler = async (_req, ctx) => {
|
|
89
|
+
const user = ctx.event?.data?.user
|
|
90
|
+
if (!user?.email) return new Response('No user in this event', { status: 400 })
|
|
91
|
+
const { error } = await ctx.baas.emails.send({ to: user.email, subject: 'Welcome!', text: 'Thanks for signing up.' })
|
|
92
|
+
if (error) throw new Error(error.message) // a thrown error fails the run: it is logged and retried
|
|
93
|
+
return { sent: true }
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export default handler
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
A failing run emits the `function.failed` webhook event (at most once a minute per function). Errors are not shown to callers (they get `function_error` and an `invocation_id`); the details are in Dashboard → Logs → Functions.
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Hosting (Business plan): put the app online
|
|
2
|
+
|
|
3
|
+
usebecky hosts the user's **static site** (a folder of built files) or **Node.js app** (their server) next to the backend. **Business** only: on Free and Pro the dashboard shows an upgrade card and the CLI answers `plan_required` with an upgrade link. Tell the user to upgrade; don't suggest workarounds on usebecky. Guide: https://usebecky.com/docs/guides/hosting
|
|
4
|
+
|
|
5
|
+
- Every site gets `https://<name>.usebecky.site` (name: 3–40 of `a-z 0-9 -`, globally unique) and its own domains.
|
|
6
|
+
- Every deploy is kept unchanged and has a preview address `https://<name>--<short id>.usebecky.site` (not indexed by search engines). **Production** points at one deploy; rollback moves the pointer (instant, nothing re-uploaded).
|
|
7
|
+
- **Prebuilt only**: the build runs on the user's machine or in CI; usebecky receives the output. There are no server-side builds.
|
|
8
|
+
|
|
9
|
+
## Deploy
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npx usebecky deploy # in the app folder: detect → build → upload → print preview + production address
|
|
13
|
+
npx usebecky deploy --prod # same, and make it production
|
|
14
|
+
npx usebecky deploy dist # a folder without package.json is uploaded as is (static)
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
- Flags: `--site <name>`, `--prod`, `--project <ref>`, `--no-build` (upload the last build), `-y` (no questions).
|
|
18
|
+
- First deploy: asks for the site name, creates the site, goes to production by itself, and writes `usebecky/hosting.json` (`{ "project": "<ref>", "site": "<name>", "kind": "static" }`, no secrets, commit it: CI with a deploy token reads it too). Later deploys are previews unless `--prod`.
|
|
19
|
+
- The build command comes from the lock file (npm/pnpm/yarn/bun): `npm run build` etc. Only files usebecky doesn't have yet are uploaded.
|
|
20
|
+
- Never uploaded: `.git`, `.env`, `.env.*`, `.npmrc`, `.DS_Store`, `Thumbs.db`, `usebecky/`, and `node_modules` for static sites. More exclusions: `.usebeckyignore` (gitignore-style lines: `name`, `folder/`, `*.log`, `docs/**`).
|
|
21
|
+
- Static sites can also be dropped into Dashboard → Hosting → New site → Drag and drop (a built folder or a .zip).
|
|
22
|
+
|
|
23
|
+
## What each framework needs
|
|
24
|
+
|
|
25
|
+
| App | Make sure | Uploaded | Kind |
|
|
26
|
+
|---|---|---|---|
|
|
27
|
+
| Plain HTML | an `index.html` | the folder | static |
|
|
28
|
+
| Vite (React/Vue/Svelte), CRA, Gatsby, Angular, Astro without adapter | a `build` script | `dist/`, `build/`, `public/`, `dist/<project>/browser`, `dist/` | static |
|
|
29
|
+
| Next.js | `output: 'standalone'` (server) or `output: 'export'` (static) in next.config; without `output` the CLI stops | `.next/standalone` + `.next/static` + `public` (start `node server.js`) / `out/` | node / static |
|
|
30
|
+
| SvelteKit | `@sveltejs/adapter-node` or `@sveltejs/adapter-static` (not adapter-auto) | `build/` (+ production node_modules, start `node build/index.js`) | node / static |
|
|
31
|
+
| Nuxt | `nuxt build` (`npm run generate` when the site is static) | `.output/` (start `node server/index.mjs`) / `.output/public` | node / static |
|
|
32
|
+
| Remix / React Router | `@remix-run/serve` / `@react-router/serve` and a `start` script | `build/` + production node_modules | node |
|
|
33
|
+
| Astro + `@astrojs/node` | | `dist/` + production node_modules (start `node ./dist/server/entry.mjs`) | node |
|
|
34
|
+
| Express, Hono, Fastify, Koa | a `start` script (or `main`) | the project folder + production node_modules (devDependencies left out) | node |
|
|
35
|
+
|
|
36
|
+
Node.js apps (Node 24, Linux):
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
// server.ts (Node.js app on usebecky Hosting)
|
|
40
|
+
import { createServer } from 'node:http'
|
|
41
|
+
|
|
42
|
+
const port = Number(process.env.PORT) || 3000 // usebecky sets PORT: always listen on it
|
|
43
|
+
createServer((req, res) => res.end('ok')).listen(port)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
- `"start": "node server.js"` without `--env-file=.env` (the `.env` file is never uploaded, so `node --env-file=.env` would fail). Keep `--env-file` in a separate `dev` script.
|
|
47
|
+
- Sleeps after 15 idle minutes, wakes in about 3 s on the next request; "Keep warm" (Settings, 1 site per project) keeps it running. Memory 512 MB (or 1 GB), 0.5 CPU.
|
|
48
|
+
- The disk isn't kept across restarts: save uploads in Storage, data in the database. WebSockets work.
|
|
49
|
+
- Native modules (`.node` files: bcrypt, sharp, …) built on macOS/Windows don't run; deploy from CI (Linux) instead.
|
|
50
|
+
- Logs: `npx usebecky hosting logs [--follow]` or the site's Logs tab.
|
|
51
|
+
|
|
52
|
+
## Environment variables and keys
|
|
53
|
+
|
|
54
|
+
- Node.js sites get `USEBECKY_URL` and `USEBECKY_PUBLISHABLE_KEY` automatically. `usebecky/server` also needs the secret key: the user switches on **Give this site the secret key** (site → Environment), which adds `USEBECKY_SECRET_KEY`. Don't tell them to paste the secret key as a variable.
|
|
55
|
+
- Own values: `npx usebecky hosting env set NAME=value ...`, `env list` (names only, values never shown), `env unset NAME`. A change restarts the app on its next visit (no new deploy needed).
|
|
56
|
+
- Static sites have no runtime variables: `VITE_…` / `NEXT_PUBLIC_…` are baked in at build time. Only the URL and the publishable key may go there. **Never put the secret key (`ub_sk_…`) in a static site or any `VITE_`/`NEXT_PUBLIC_` variable.**
|
|
57
|
+
|
|
58
|
+
## CI (GitHub Actions)
|
|
59
|
+
|
|
60
|
+
A **deploy token** (Dashboard → Hosting → Deploy tokens, shown once, project-scoped, can only deploy) in the env var `USEBECKY_DEPLOY_TOKEN`, plus `--project` and `--site`; the site must already exist (a deploy token can't create sites). `npx usebecky hosting github` writes this file:
|
|
61
|
+
|
|
62
|
+
```yaml
|
|
63
|
+
# .github/workflows/usebecky-deploy.yml
|
|
64
|
+
# Deploys to usebecky Hosting: pushes to main go live, pull requests get a preview address.
|
|
65
|
+
# Needs the repository secret USEBECKY_DEPLOY_TOKEN (Dashboard → Hosting → Deploy tokens).
|
|
66
|
+
name: Deploy to usebecky
|
|
67
|
+
|
|
68
|
+
on:
|
|
69
|
+
push:
|
|
70
|
+
branches: [main]
|
|
71
|
+
pull_request:
|
|
72
|
+
|
|
73
|
+
jobs:
|
|
74
|
+
deploy:
|
|
75
|
+
# Pull requests from forks can't read your secrets, so they are skipped.
|
|
76
|
+
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
|
|
77
|
+
runs-on: ubuntu-latest
|
|
78
|
+
steps:
|
|
79
|
+
- uses: actions/checkout@v4
|
|
80
|
+
- uses: actions/setup-node@v4
|
|
81
|
+
with:
|
|
82
|
+
node-version: 24
|
|
83
|
+
- run: npm ci
|
|
84
|
+
- run: npx --yes usebecky deploy --project k3x9q2m7p4ab --site my-app ${{ github.event_name == 'push' && '--prod' || '' }}
|
|
85
|
+
env:
|
|
86
|
+
USEBECKY_DEPLOY_TOKEN: ${{ secrets.USEBECKY_DEPLOY_TOKEN }}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
- **Never commit a deploy token** or write it into any file: GitHub → Settings → Secrets and variables → Actions → `USEBECKY_DEPLOY_TOKEN`. Leaked → delete it under Deploy tokens and create a new one.
|
|
90
|
+
- Build-time public values (`VITE_USEBECKY_URL`, `VITE_USEBECKY_PUBLISHABLE_KEY`, `NEXT_PUBLIC_…`) go into the deploy step's `env:` from GitHub **variables** (`${{ vars.NAME }}`), because `.env.local` isn't in the repository.
|
|
91
|
+
|
|
92
|
+
## Rollback, domains, settings
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
npx usebecky hosting list # sites
|
|
96
|
+
npx usebecky hosting deploys # deploys, newest first (short id, preview address, production marked)
|
|
97
|
+
npx usebecky hosting rollback [<deploy>] # production back to an earlier deploy (default: the one before)
|
|
98
|
+
npx usebecky hosting promote <deploy> # make a preview production
|
|
99
|
+
npx usebecky hosting domains add www.myapp.com # prints the DNS records; also: list | check <host> | remove <host>
|
|
100
|
+
CLOUDFLARE_API_TOKEN=… npx usebecky hosting domains add www.myapp.com --dns cloudflare # DNS at Cloudflare: writes the records there and checks them
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
All `hosting` commands take `--site <name>` (default: `usebecky/hosting.json`) and `--project <ref>`.
|
|
104
|
+
|
|
105
|
+
- Domains (up to 10 per project): subdomain → CNAME to `domains.usebecky.com` + TXT `_usebecky-challenge.<name>`; apex (`myapp.com`) → an A record (value shown in the dashboard) + the TXT. Status: Waiting for DNS → Getting a certificate → Live. Cloudflare: "DNS only" (grey cloud). After it's live, set Auth → Settings → Site URL and Allowed redirect URLs to the new address. This is the website's domain, not the API's custom domain (Settings → Custom domain).
|
|
106
|
+
- Certificates: hosted sites and the API domain get theirs automatically (Let's Encrypt, renewed by themselves; Dashboard → SSL certificates lists them). For a server **outside** usebecky the user gets one on that page (Free 1, Pro 10, Business 50): pick a domain from the Domains page; on usebecky DNS nothing else, else one CNAME `_acme-challenge.<name>` per name. The server keeps it fresh with the daily job the page shows (POSIX sh + curl, download key `ubcert_…` in `Authorization: Bearer`, files at `/certificates/v1/<id>/fullchain.pem` / `privkey.pem`). Never put a download key or private key in the repo. Webhook `certificate.renewed` on each renewal. Guide: https://usebecky.com/docs/guides/ssl-certificates
|
|
107
|
+
- Static settings: **Single-page app** (unknown paths serve `index.html`; switch on for React Router/Vue Router apps). `_headers` and `_redirects` files in the uploaded folder (Netlify / Cloudflare Pages format; with Vite put them in `public/`). Hashed assets are cached for a year, HTML is revalidated.
|
|
108
|
+
|
|
109
|
+
## Limits (Business) and errors
|
|
110
|
+
|
|
111
|
+
For the whole team (all its projects added up): 10 sites · 100 GB bandwidth per month · 10 GB stored files. Per project: 500 MB per deploy upload · 100 deploys per day · 10 custom domains · 1 site kept warm. Per Node.js site: 512 MB / 1 GB memory, 0.5 CPU, sleeps after 15 minutes.
|
|
112
|
+
|
|
113
|
+
| Error | Meaning | Fix |
|
|
114
|
+
|---|---|---|
|
|
115
|
+
| `plan_required` (402) | Not on Business | Upgrade in Settings → Usage & plan |
|
|
116
|
+
| `quota_exceeded` | A hosting limit (sites, deploys per day, upload size, bandwidth); `details.quota` says which | Smaller upload, delete a site, or wait for the reset |
|
|
117
|
+
| Not signed in | No login and no `USEBECKY_DEPLOY_TOKEN` | `npx usebecky login` (local) or the deploy token (CI) |
|
|
118
|
+
| Next.js / SvelteKit stops | No `output` in next.config / `adapter-auto` | Add `output: 'standalone'`/`'export'`; install adapter-node/adapter-static |
|
|
119
|
+
| "This site is not available" | usebecky disabled the site (abuse) | The owner writes to hello@algorithmo.de |
|