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 +701 -2
- package/dist/analytics/client.d.ts +219 -0
- package/dist/analytics/client.js +923 -0
- package/dist/analytics/cmp.d.ts +20 -0
- package/dist/analytics/cmp.js +166 -0
- package/dist/analytics/context.d.ts +29 -0
- package/dist/analytics/context.js +97 -0
- package/dist/auth/client.d.ts +401 -0
- package/dist/auth/client.js +1081 -0
- package/dist/auth/webauthn.d.ts +18 -0
- package/dist/auth/webauthn.js +138 -0
- package/dist/cli/ai.d.ts +54 -0
- package/dist/cli/ai.js +202 -0
- package/dist/cli/analytics.d.ts +53 -0
- package/dist/cli/analytics.js +357 -0
- package/dist/cli/config.d.ts +75 -0
- package/dist/cli/config.js +718 -0
- package/dist/cli/db.d.ts +48 -0
- package/dist/cli/db.js +215 -0
- package/dist/cli/deploy-api.d.ts +168 -0
- package/dist/cli/deploy-api.js +177 -0
- package/dist/cli/deploy-ci.d.ts +15 -0
- package/dist/cli/deploy-ci.js +54 -0
- package/dist/cli/deploy-detect.d.ts +64 -0
- package/dist/cli/deploy-detect.js +249 -0
- package/dist/cli/deploy-files.d.ts +112 -0
- package/dist/cli/deploy-files.js +778 -0
- package/dist/cli/deploy.d.ts +10 -0
- package/dist/cli/deploy.js +430 -0
- package/dist/cli/emails.d.ts +29 -0
- package/dist/cli/emails.js +122 -0
- package/dist/cli/framework.d.ts +135 -0
- package/dist/cli/framework.js +459 -0
- package/dist/cli/functions.d.ts +59 -0
- package/dist/cli/functions.js +426 -0
- package/dist/cli/hosting.d.ts +4 -0
- package/dist/cli/hosting.js +532 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +9 -0
- package/dist/cli/payments.d.ts +35 -0
- package/dist/cli/payments.js +176 -0
- package/dist/cli/push.d.ts +36 -0
- package/dist/cli/push.js +172 -0
- package/dist/cli/run.d.ts +65 -0
- package/dist/cli/run.js +850 -0
- package/dist/cli/social.d.ts +52 -0
- package/dist/cli/social.js +532 -0
- package/dist/cli/tokens.d.ts +28 -0
- package/dist/cli/tokens.js +114 -0
- package/dist/cli/ui.d.ts +38 -0
- package/dist/cli/ui.js +140 -0
- package/dist/client.d.ts +94 -0
- package/dist/client.js +156 -0
- package/dist/db/query.d.ts +162 -0
- package/dist/db/query.js +336 -0
- package/dist/db/types.d.ts +93 -0
- package/dist/db/types.js +4 -0
- package/dist/forms/client.d.ts +65 -0
- package/dist/forms/client.js +106 -0
- package/dist/functions/client.d.ts +37 -0
- package/dist/functions/client.js +76 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +16 -0
- package/dist/lib/dashboard-paths.d.ts +4 -0
- package/dist/lib/dashboard-paths.js +8 -0
- package/dist/lib/env.d.ts +9 -0
- package/dist/lib/env.js +55 -0
- package/dist/lib/errors.d.ts +22 -0
- package/dist/lib/errors.js +90 -0
- package/dist/lib/hosted.d.ts +2 -0
- package/dist/lib/hosted.js +7 -0
- package/dist/lib/http.d.ts +59 -0
- package/dist/lib/http.js +172 -0
- package/dist/lib/jwt.d.ts +1 -0
- package/dist/lib/jwt.js +31 -0
- package/dist/lib/locale.d.ts +12 -0
- package/dist/lib/locale.js +51 -0
- package/dist/lib/pkce.d.ts +20 -0
- package/dist/lib/pkce.js +124 -0
- package/dist/lib/storage-adapter.d.ts +15 -0
- package/dist/lib/storage-adapter.js +91 -0
- package/dist/lib/types.d.ts +339 -0
- package/dist/lib/types.js +1 -0
- package/dist/newsletter/client.d.ts +140 -0
- package/dist/newsletter/client.js +85 -0
- package/dist/payments/client.d.ts +352 -0
- package/dist/payments/client.js +323 -0
- package/dist/push/client.d.ts +110 -0
- package/dist/push/client.js +179 -0
- package/dist/realtime/client.d.ts +131 -0
- package/dist/realtime/client.js +513 -0
- package/dist/server/analytics.d.ts +176 -0
- package/dist/server/analytics.js +49 -0
- package/dist/server/cache.d.ts +74 -0
- package/dist/server/cache.js +154 -0
- package/dist/server/emails.d.ts +142 -0
- package/dist/server/emails.js +123 -0
- package/dist/server/events.d.ts +357 -0
- package/dist/server/events.js +219 -0
- package/dist/server/functions.d.ts +40 -0
- package/dist/server/functions.js +1 -0
- package/dist/server/http-utils.d.ts +10 -0
- package/dist/server/http-utils.js +115 -0
- package/dist/server/index.d.ts +195 -0
- package/dist/server/index.js +314 -0
- package/dist/server/payments.d.ts +218 -0
- package/dist/server/payments.js +150 -0
- package/dist/server/push.d.ts +85 -0
- package/dist/server/push.js +37 -0
- package/dist/server/usage.d.ts +43 -0
- package/dist/server/usage.js +8 -0
- package/dist/storage/client.d.ts +143 -0
- package/dist/storage/client.js +224 -0
- package/package.json +52 -4
- package/skill/usebecky/SKILL.md +339 -0
- package/skill/usebecky/references/access-rules.md +307 -0
- package/skill/usebecky/references/addons.md +68 -0
- package/skill/usebecky/references/analytics.md +166 -0
- package/skill/usebecky/references/android.md +434 -0
- package/skill/usebecky/references/auth.md +379 -0
- package/skill/usebecky/references/cache.md +51 -0
- package/skill/usebecky/references/components.md +127 -0
- package/skill/usebecky/references/emails.md +105 -0
- package/skill/usebecky/references/expo.md +147 -0
- package/skill/usebecky/references/functions.md +99 -0
- package/skill/usebecky/references/hosting.md +119 -0
- package/skill/usebecky/references/http-api.md +233 -0
- package/skill/usebecky/references/ios.md +355 -0
- package/skill/usebecky/references/payments.md +493 -0
- package/skill/usebecky/references/realtime.md +143 -0
- package/skill/usebecky/references/scheduled-jobs.md +82 -0
- package/skill/usebecky/references/sdk.md +838 -0
- package/skill/usebecky/references/storage.md +210 -0
- package/skill/usebecky/references/templates.md +191 -0
- package/skill/usebecky/references/wordpress.md +87 -0
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import type { UseBeckyError } from './errors.ts';
|
|
2
|
+
/** Every SDK call resolves to this. Check `error` first; when it is null, `data` is set. */
|
|
3
|
+
export type Result<T> = {
|
|
4
|
+
data: T;
|
|
5
|
+
error: null;
|
|
6
|
+
} | {
|
|
7
|
+
data: null;
|
|
8
|
+
error: UseBeckyError;
|
|
9
|
+
};
|
|
10
|
+
export interface Identity {
|
|
11
|
+
provider: string;
|
|
12
|
+
provider_id: string;
|
|
13
|
+
email: string | null;
|
|
14
|
+
created_at: string;
|
|
15
|
+
}
|
|
16
|
+
export interface Factor {
|
|
17
|
+
id: string;
|
|
18
|
+
type: 'totp';
|
|
19
|
+
status: 'verified' | 'unverified';
|
|
20
|
+
friendly_name: string | null;
|
|
21
|
+
created_at: string;
|
|
22
|
+
}
|
|
23
|
+
export interface User {
|
|
24
|
+
id: string;
|
|
25
|
+
email: string | null;
|
|
26
|
+
email_confirmed_at: string | null;
|
|
27
|
+
phone: string | null;
|
|
28
|
+
created_at: string;
|
|
29
|
+
updated_at: string;
|
|
30
|
+
last_sign_in_at: string | null;
|
|
31
|
+
app_metadata: {
|
|
32
|
+
provider?: string;
|
|
33
|
+
providers?: string[];
|
|
34
|
+
[key: string]: unknown;
|
|
35
|
+
};
|
|
36
|
+
user_metadata: Record<string, any>;
|
|
37
|
+
identities: Identity[];
|
|
38
|
+
factors: Factor[];
|
|
39
|
+
banned_until: string | null;
|
|
40
|
+
is_anonymous: boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface Session {
|
|
43
|
+
access_token: string;
|
|
44
|
+
token_type: 'bearer' | string;
|
|
45
|
+
/** Seconds the access token is valid for. */
|
|
46
|
+
expires_in: number;
|
|
47
|
+
/** Unix time (seconds) when the access token expires. */
|
|
48
|
+
expires_at: number;
|
|
49
|
+
refresh_token: string;
|
|
50
|
+
user: User;
|
|
51
|
+
/** True when the user has an authenticator app and must still enter a code (`auth.mfa.verify`). */
|
|
52
|
+
mfa_required?: boolean;
|
|
53
|
+
}
|
|
54
|
+
export type AuthChangeEvent = 'INITIAL_SESSION' | 'SIGNED_IN' | 'SIGNED_OUT' | 'TOKEN_REFRESHED' | 'USER_UPDATED' | 'PASSWORD_RECOVERY' | 'MFA_CHALLENGE_VERIFIED';
|
|
55
|
+
export type OAuthProvider = 'google' | 'github' | 'apple' | 'microsoft' | 'discord' | 'gitlab' | 'linkedin' | 'slack' | 'x' | (string & {});
|
|
56
|
+
/** A passkey of the signed-in user (`baas.auth.passkeys.list()`). */
|
|
57
|
+
export interface Passkey {
|
|
58
|
+
id: string;
|
|
59
|
+
/** A name the user recognizes, e.g. "iCloud Keychain" or "Work laptop". */
|
|
60
|
+
friendly_name: string | null;
|
|
61
|
+
created_at: string;
|
|
62
|
+
last_used_at: string | null;
|
|
63
|
+
/** 'multiDevice' = synced (iCloud Keychain, Google Password Manager, 1Password); 'singleDevice' = one device or security key. */
|
|
64
|
+
device_type: 'singleDevice' | 'multiDevice';
|
|
65
|
+
backed_up: boolean;
|
|
66
|
+
transports: string[];
|
|
67
|
+
}
|
|
68
|
+
export interface AuthSettings {
|
|
69
|
+
signup_enabled: boolean;
|
|
70
|
+
email_password: boolean;
|
|
71
|
+
magic_link: boolean;
|
|
72
|
+
providers: Record<string, boolean>;
|
|
73
|
+
mfa_totp: boolean;
|
|
74
|
+
site_url: string;
|
|
75
|
+
/** Passkey sign-in is on (`signInWithPasskey`). */
|
|
76
|
+
passkeys?: boolean;
|
|
77
|
+
/** Phone sign-in with text-message codes is on (`signInWithPhone`). */
|
|
78
|
+
phone?: boolean;
|
|
79
|
+
/** Guest sign-in is on (`signInAnonymously`). */
|
|
80
|
+
anonymous?: boolean;
|
|
81
|
+
/** At least one company single sign-on connection is on (`signInWithSSO`). */
|
|
82
|
+
sso?: boolean;
|
|
83
|
+
/** Bot protection, when turned on: which widget to show and which calls need its token (`captchaToken`). */
|
|
84
|
+
captcha?: CaptchaInfo | null;
|
|
85
|
+
}
|
|
86
|
+
/** Public bot-protection settings (never the secret). */
|
|
87
|
+
export interface CaptchaInfo {
|
|
88
|
+
provider: 'turnstile' | 'hcaptcha';
|
|
89
|
+
/** Public site key for the widget. */
|
|
90
|
+
site_key: string;
|
|
91
|
+
/** Calls that need a token: 'signup' (also guest sign-in) | 'signin' | 'magic_link' | 'recover' | 'phone' | 'forms' | 'newsletter'. */
|
|
92
|
+
features: ('signup' | 'signin' | 'magic_link' | 'recover' | 'phone' | 'forms' | 'newsletter')[];
|
|
93
|
+
}
|
|
94
|
+
export interface Price {
|
|
95
|
+
id: string;
|
|
96
|
+
key: string;
|
|
97
|
+
product_key: string;
|
|
98
|
+
/** Amount in minor units (cents). 1999 = $19.99 */
|
|
99
|
+
amount: number;
|
|
100
|
+
currency: string;
|
|
101
|
+
interval: 'month' | 'year' | null;
|
|
102
|
+
trial_days: number | null;
|
|
103
|
+
active: boolean;
|
|
104
|
+
/** A variant's name, like `'M / Black'` (one-time prices); null for a plain price. Older servers leave it out. */
|
|
105
|
+
name?: string | null;
|
|
106
|
+
/** `false` when it is sold out. Older servers leave it out. */
|
|
107
|
+
in_stock?: boolean;
|
|
108
|
+
/** How many are left, only when few are (at or below the shop's threshold, e.g. "Only 3 left"); else null. */
|
|
109
|
+
stock_left?: number | null;
|
|
110
|
+
}
|
|
111
|
+
export interface Product {
|
|
112
|
+
id: string;
|
|
113
|
+
key: string;
|
|
114
|
+
name: string;
|
|
115
|
+
description: string | null;
|
|
116
|
+
type: 'subscription' | 'one_time';
|
|
117
|
+
features: string[];
|
|
118
|
+
active: boolean;
|
|
119
|
+
image_url: string | null;
|
|
120
|
+
prices: Price[];
|
|
121
|
+
/** True when buying this product unlocks a file (`payments.download(key)`). */
|
|
122
|
+
has_download: boolean;
|
|
123
|
+
/** Always null in the public catalog (the file location is never exposed). */
|
|
124
|
+
download: {
|
|
125
|
+
bucket: string;
|
|
126
|
+
path: string;
|
|
127
|
+
} | null;
|
|
128
|
+
/** A physical product: checkout asks for a shipping address. Older servers leave it out. */
|
|
129
|
+
shipping?: boolean;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Who pays for a subscription: `'paid'` (through Stripe), `'trial'` (a Stripe subscription in its free trial)
|
|
133
|
+
* or `'gift'` (you gave it to the user for free, from the dashboard or `baas.payments.gift()`).
|
|
134
|
+
*/
|
|
135
|
+
export type SubscriptionSource = 'paid' | 'trial' | 'gift';
|
|
136
|
+
export interface Subscription {
|
|
137
|
+
id: string;
|
|
138
|
+
/** A running gift is `'active'`; an ended gift is `'canceled'`. */
|
|
139
|
+
status: 'trialing' | 'active' | 'past_due' | 'canceled' | 'incomplete' | 'incomplete_expired' | 'unpaid' | 'paused';
|
|
140
|
+
/** The price that was bought. `null` for gifts (nothing was bought). */
|
|
141
|
+
price_key: string | null;
|
|
142
|
+
product_key: string;
|
|
143
|
+
/** End of the paid period. For gifts: when the gift ends (`null` = no end date). */
|
|
144
|
+
current_period_end: string | null;
|
|
145
|
+
trial_end: string | null;
|
|
146
|
+
/** True when it won't renew. For gifts: true when the gift has an end date. */
|
|
147
|
+
cancel_at_period_end: boolean;
|
|
148
|
+
created_at: string;
|
|
149
|
+
/** Who pays: `'paid'`, `'trial'` or `'gift'` (free, given by you). */
|
|
150
|
+
source: SubscriptionSource;
|
|
151
|
+
/** `true`: paid with real money. `false`: made in Stripe test mode (test cards). `null`: a gift (neither). */
|
|
152
|
+
livemode?: boolean | null;
|
|
153
|
+
/** `true`: no access right now, although `status` may say `'active'`. A dispute is open and your project removes
|
|
154
|
+
* access right away (its payments are paused in Stripe too), or a lost dispute or a fraud refund ended it and
|
|
155
|
+
* Stripe's cancellation is on its way. Always `false` for gifts. */
|
|
156
|
+
access_paused?: boolean;
|
|
157
|
+
/** Gifts only: when it started and when it ends (`ends_at: null` = no end date). `null` for paid subscriptions. */
|
|
158
|
+
gift: {
|
|
159
|
+
starts_at: string;
|
|
160
|
+
ends_at: string | null;
|
|
161
|
+
} | null;
|
|
162
|
+
}
|
|
163
|
+
/** Your app's payments mode: `'test'` while you build (Stripe's test cards, nothing is charged), `'live'` once
|
|
164
|
+
* you switched to live in Dashboard → Payments → Go live (real cards, real money). */
|
|
165
|
+
export type PaymentsMode = 'test' | 'live';
|
|
166
|
+
/** Where a user's access to a feature comes from (`payments.checkAccess()`): a paid or trial subscription,
|
|
167
|
+
* a one-time purchase, a gift (only when nothing paid grants it), or `null` (no access). */
|
|
168
|
+
export type AccessSource = 'subscription' | 'purchase' | 'gift' | null;
|
|
169
|
+
export interface AccessInfo {
|
|
170
|
+
access: boolean;
|
|
171
|
+
source: AccessSource;
|
|
172
|
+
}
|
|
173
|
+
export interface Purchase {
|
|
174
|
+
id: string;
|
|
175
|
+
product_key: string;
|
|
176
|
+
price_key: string;
|
|
177
|
+
amount: number;
|
|
178
|
+
currency: string;
|
|
179
|
+
/** `disputed`: the buyer disputed the payment with their bank and access is paused until it's decided (only with
|
|
180
|
+
* "Remove access right away"); `disputed_lost`: the dispute was lost and access ended, like `refunded`. */
|
|
181
|
+
status: 'paid' | 'refunded' | 'disputed' | 'disputed_lost';
|
|
182
|
+
/** `true`: paid with real money. `false`: made in Stripe test mode. */
|
|
183
|
+
livemode?: boolean;
|
|
184
|
+
created_at: string;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Where an order stands. `pending`: not paid yet (the checkout is open, or a bank payment is on its way); `paid`;
|
|
188
|
+
* `partly_refunded` / `refunded`: money went back; `canceled`: a bank payment failed; `expired`: the checkout was
|
|
189
|
+
* abandoned.
|
|
190
|
+
*/
|
|
191
|
+
export type OrderStatus = 'pending' | 'paid' | 'partly_refunded' | 'refunded' | 'canceled' | 'expired';
|
|
192
|
+
/** One line of an order, as it was bought (the catalog may change later). Amounts in minor units (cents). */
|
|
193
|
+
export interface OrderItem {
|
|
194
|
+
product_key: string;
|
|
195
|
+
price_key: string;
|
|
196
|
+
name: string;
|
|
197
|
+
/** The variant, like `'M / Black'`, and its SKU (null for a plain price). */
|
|
198
|
+
variant: string | null;
|
|
199
|
+
sku: string | null;
|
|
200
|
+
/** Shipped to the buyer. */
|
|
201
|
+
shipping: boolean;
|
|
202
|
+
unit_amount: number;
|
|
203
|
+
quantity: number;
|
|
204
|
+
amount: number;
|
|
205
|
+
/** How many of this line were refunded (refunds by line, from the dashboard). */
|
|
206
|
+
refunded_quantity?: number;
|
|
207
|
+
}
|
|
208
|
+
/** What happened to the goods of a paid order: `unfulfilled` (to send), `shipped`, `delivered`, or `fulfilled`
|
|
209
|
+
* (nothing to send: digital products only, as soon as it is paid). */
|
|
210
|
+
export type OrderFulfillment = 'unfulfilled' | 'shipped' | 'delivered' | 'fulfilled';
|
|
211
|
+
/** A short-lived link to a file the order bought (`url` is null when the file can't be found right now). */
|
|
212
|
+
export interface OrderDownload {
|
|
213
|
+
product_key: string;
|
|
214
|
+
name: string;
|
|
215
|
+
url: string | null;
|
|
216
|
+
expires_in: number;
|
|
217
|
+
}
|
|
218
|
+
/** A shipping address as Stripe's checkout collected it. `country` is a two-letter code like `'DE'`. */
|
|
219
|
+
export interface OrderAddress {
|
|
220
|
+
name: string | null;
|
|
221
|
+
line1: string | null;
|
|
222
|
+
line2: string | null;
|
|
223
|
+
city: string | null;
|
|
224
|
+
state: string | null;
|
|
225
|
+
postal_code: string | null;
|
|
226
|
+
country: string | null;
|
|
227
|
+
}
|
|
228
|
+
/** A shop order: one checkout of one or more one-time products (`payments.checkout({ items })`). */
|
|
229
|
+
export interface Order {
|
|
230
|
+
id: string;
|
|
231
|
+
/** #1001, #1002, … (test and live mode count separately); null until the checkout is completed. */
|
|
232
|
+
number: number | null;
|
|
233
|
+
status: OrderStatus;
|
|
234
|
+
/** Who bought it, as entered on Stripe's checkout page. */
|
|
235
|
+
email: string | null;
|
|
236
|
+
name: string | null;
|
|
237
|
+
currency: string;
|
|
238
|
+
/** Minor units. `subtotal` is the lines before the discount; `total` is what was paid. */
|
|
239
|
+
subtotal: number;
|
|
240
|
+
discount: number;
|
|
241
|
+
shipping: number;
|
|
242
|
+
tax: number;
|
|
243
|
+
total: number;
|
|
244
|
+
amount_refunded: number;
|
|
245
|
+
/** Physical products: where it goes, the buyer's phone (when the shop asks for it) and the shipping rate they chose. */
|
|
246
|
+
shipping_address: OrderAddress | null;
|
|
247
|
+
phone: string | null;
|
|
248
|
+
shipping_rate: {
|
|
249
|
+
id: string;
|
|
250
|
+
name: string;
|
|
251
|
+
amount: number;
|
|
252
|
+
min_days: number | null;
|
|
253
|
+
max_days: number | null;
|
|
254
|
+
} | null;
|
|
255
|
+
/** Shipping: the state, the carrier, the tracking number and link (once the shop marked it shipped). */
|
|
256
|
+
fulfillment: OrderFulfillment;
|
|
257
|
+
carrier: string | null;
|
|
258
|
+
tracking_number: string | null;
|
|
259
|
+
tracking_url: string | null;
|
|
260
|
+
shipped_at: string | null;
|
|
261
|
+
delivered_at: string | null;
|
|
262
|
+
items: OrderItem[];
|
|
263
|
+
/** Your own key/value pairs from `checkout({ metadata })`. */
|
|
264
|
+
metadata: Record<string, string>;
|
|
265
|
+
livemode: boolean;
|
|
266
|
+
created_at: string | null;
|
|
267
|
+
paid_at: string | null;
|
|
268
|
+
canceled_at: string | null;
|
|
269
|
+
refunded_at: string | null;
|
|
270
|
+
/** Only from `payments.orders.get()`: links to the files of a paid order. */
|
|
271
|
+
downloads?: OrderDownload[];
|
|
272
|
+
}
|
|
273
|
+
/** A page of orders (`payments.orders.list()`), newest first. */
|
|
274
|
+
export interface OrderList {
|
|
275
|
+
orders: Order[];
|
|
276
|
+
/** Pass to `list({ cursor })` for the next page; null on the last one. */
|
|
277
|
+
next_cursor: string | null;
|
|
278
|
+
prev_cursor: string | null;
|
|
279
|
+
}
|
|
280
|
+
export interface BillingInfo {
|
|
281
|
+
/** The mode payments run in right now. Only rows that count in it are listed (live ones always; test ones
|
|
282
|
+
* only in test mode). Older servers leave it out. */
|
|
283
|
+
mode?: PaymentsMode;
|
|
284
|
+
customer_id: string | null;
|
|
285
|
+
subscriptions: Subscription[];
|
|
286
|
+
purchases: Purchase[];
|
|
287
|
+
entitlements: string[];
|
|
288
|
+
}
|
|
289
|
+
export interface Bucket {
|
|
290
|
+
id: string;
|
|
291
|
+
name: string;
|
|
292
|
+
public: boolean;
|
|
293
|
+
file_size_limit: number | null;
|
|
294
|
+
allowed_mime_types: string[] | null;
|
|
295
|
+
created_at: string;
|
|
296
|
+
updated_at: string;
|
|
297
|
+
}
|
|
298
|
+
export interface FileObject {
|
|
299
|
+
name: string;
|
|
300
|
+
/** null for folders */
|
|
301
|
+
id: string | null;
|
|
302
|
+
metadata: {
|
|
303
|
+
size?: number;
|
|
304
|
+
mimetype?: string;
|
|
305
|
+
etag?: string;
|
|
306
|
+
cacheControl?: string;
|
|
307
|
+
[key: string]: unknown;
|
|
308
|
+
} | null;
|
|
309
|
+
created_at: string | null;
|
|
310
|
+
updated_at: string | null;
|
|
311
|
+
/** Files only: changes with every new upload. Pass it to `getPublicUrl(path, { version })`. */
|
|
312
|
+
version?: string | null;
|
|
313
|
+
}
|
|
314
|
+
export interface ObjectInfo {
|
|
315
|
+
id: string;
|
|
316
|
+
bucket_id: string;
|
|
317
|
+
name: string;
|
|
318
|
+
owner: string | null;
|
|
319
|
+
metadata: {
|
|
320
|
+
size?: number;
|
|
321
|
+
mimetype?: string;
|
|
322
|
+
etag?: string;
|
|
323
|
+
cacheControl?: string;
|
|
324
|
+
[key: string]: unknown;
|
|
325
|
+
};
|
|
326
|
+
created_at: string;
|
|
327
|
+
updated_at: string;
|
|
328
|
+
}
|
|
329
|
+
export type ChangeEvent = 'INSERT' | 'UPDATE' | 'DELETE';
|
|
330
|
+
export interface Change<Row = Record<string, any>> {
|
|
331
|
+
event: ChangeEvent;
|
|
332
|
+
table: string;
|
|
333
|
+
/** The row after the change (null for DELETE). */
|
|
334
|
+
new: Row | null;
|
|
335
|
+
/** For UPDATE and DELETE: the primary key of the changed row. Null for INSERT. */
|
|
336
|
+
old: Partial<Row> | null;
|
|
337
|
+
commit_timestamp: string;
|
|
338
|
+
}
|
|
339
|
+
export type PresenceState<T = Record<string, any>> = Record<string, T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { UseBeckyError } from '../lib/errors.ts';
|
|
2
|
+
import type { HttpClient } from '../lib/http.ts';
|
|
3
|
+
import type { Result } from '../lib/types.ts';
|
|
4
|
+
export interface NewsletterSubscribeOptions {
|
|
5
|
+
/** Key of the list (Dashboard → Newsletter → Settings → Lists). Default: your default list. */
|
|
6
|
+
list?: string;
|
|
7
|
+
/** Shown in the dashboard and usable in emails as {{name}}. */
|
|
8
|
+
name?: string;
|
|
9
|
+
/** Up to 10 labels, e.g. ['homepage'] to know where people signed up. */
|
|
10
|
+
tags?: string[];
|
|
11
|
+
/** Token from the Turnstile / hCaptcha widget, when bot protection is on for newsletter sign-ups. */
|
|
12
|
+
captchaToken?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface NewsletterSubscribeResult {
|
|
15
|
+
/** 'pending' when the list uses double opt-in (they must click the link in the email first), else 'subscribed'. */
|
|
16
|
+
status: 'pending' | 'subscribed';
|
|
17
|
+
/** A friendly message to show, e.g. "Thanks! Check your inbox and click the link to confirm your subscription." */
|
|
18
|
+
message: string;
|
|
19
|
+
}
|
|
20
|
+
export type NewsletterSubscriberStatus = 'pending' | 'subscribed' | 'unsubscribed' | 'bounced' | 'complained';
|
|
21
|
+
/** A subscriber as your server sees it (`usebecky/server` → baas.newsletter). */
|
|
22
|
+
export interface NewsletterSubscriber {
|
|
23
|
+
id: string;
|
|
24
|
+
list_id: string;
|
|
25
|
+
email: string;
|
|
26
|
+
name: string | null;
|
|
27
|
+
/** Only 'subscribed' people get your campaigns. */
|
|
28
|
+
status: NewsletterSubscriberStatus;
|
|
29
|
+
/** How they were added: 'form' (sign-up), 'api' (your server), 'import' or 'manual' (dashboard). */
|
|
30
|
+
source: 'form' | 'api' | 'import' | 'manual';
|
|
31
|
+
tags: string[];
|
|
32
|
+
/** When they agreed to get your emails (null while pending). */
|
|
33
|
+
consent_at: string | null;
|
|
34
|
+
consent_ip_hash: string | null;
|
|
35
|
+
added_by: string | null;
|
|
36
|
+
/** The app user with this email, when known. */
|
|
37
|
+
user_id: string | null;
|
|
38
|
+
confirmation_sent_at: string | null;
|
|
39
|
+
unsubscribed_at: string | null;
|
|
40
|
+
created_at: string;
|
|
41
|
+
updated_at: string;
|
|
42
|
+
/** How they joined, and whether that proves consent (sign-up and confirmation time, where they agreed). */
|
|
43
|
+
consent?: NewsletterConsentRecord;
|
|
44
|
+
}
|
|
45
|
+
/** The consent record of a subscriber. */
|
|
46
|
+
export interface NewsletterConsentRecord {
|
|
47
|
+
method: 'form' | 'import' | 'api' | 'dashboard';
|
|
48
|
+
method_label: string;
|
|
49
|
+
/** double_opt_in (clicked a confirmation email), single_opt_in, confirmed_elsewhere, existing_customer (soft opt-in) or consent_pending. */
|
|
50
|
+
basis: 'double_opt_in' | 'single_opt_in' | 'confirmed_elsewhere' | 'existing_customer' | 'consent_pending' | null;
|
|
51
|
+
basis_label: string;
|
|
52
|
+
/** 'incomplete' when the record can't show when and where they agreed. */
|
|
53
|
+
proof: 'complete' | 'incomplete' | 'pending';
|
|
54
|
+
proof_note: string;
|
|
55
|
+
signed_up_at: string | null;
|
|
56
|
+
confirmed_at: string | null;
|
|
57
|
+
/** Where they agreed, e.g. "signup form on shop.com". */
|
|
58
|
+
source: string | null;
|
|
59
|
+
wording: string | null;
|
|
60
|
+
wording_hash: string | null;
|
|
61
|
+
signup_ip_hash: string | null;
|
|
62
|
+
confirm_ip_hash: string | null;
|
|
63
|
+
import_batch_id: string | null;
|
|
64
|
+
confirmation_email_sent_at: string | null;
|
|
65
|
+
confirm_by: string | null;
|
|
66
|
+
}
|
|
67
|
+
export declare function checkEmailArg(email: unknown, example: string): UseBeckyError | null;
|
|
68
|
+
export declare class NewsletterClient {
|
|
69
|
+
private http;
|
|
70
|
+
constructor(http: HttpClient);
|
|
71
|
+
/**
|
|
72
|
+
* Sign someone up for your newsletter.
|
|
73
|
+
*
|
|
74
|
+
* const { data, error } = await baas.newsletter.subscribe(email, { name, list: 'weekly', tags: ['footer'] })
|
|
75
|
+
* if (error) showError(error.message)
|
|
76
|
+
* else showMessage(data.message) // "Thanks! Check your inbox ..."
|
|
77
|
+
*
|
|
78
|
+
* When someone is signed in with the same email, the subscription is linked to their user.
|
|
79
|
+
*/
|
|
80
|
+
subscribe(email: string, options?: NewsletterSubscribeOptions): Promise<Result<NewsletterSubscribeResult>>;
|
|
81
|
+
}
|
|
82
|
+
export interface NewsletterAddOptions {
|
|
83
|
+
/** List key or id. Default: your default list. */
|
|
84
|
+
list?: string;
|
|
85
|
+
name?: string;
|
|
86
|
+
tags?: string[];
|
|
87
|
+
/**
|
|
88
|
+
* 'send_confirmation' (default): they get an email and are subscribed after clicking the link.
|
|
89
|
+
* 'already_agreed': subscribed right away. Use it only when they asked for your emails (e.g. ticked a box).
|
|
90
|
+
*/
|
|
91
|
+
consent?: 'already_agreed' | 'send_confirmation';
|
|
92
|
+
/** With 'already_agreed': where they agreed, e.g. "checkbox at checkout on shop.com" (kept as proof). */
|
|
93
|
+
consentSource?: string;
|
|
94
|
+
/** With 'already_agreed': when they agreed, e.g. "2025-03-01" or an ISO date and time (kept as proof). */
|
|
95
|
+
confirmedAt?: string;
|
|
96
|
+
}
|
|
97
|
+
export interface NewsletterListOptions {
|
|
98
|
+
/** List key or id. Default: your default list. */
|
|
99
|
+
list?: string;
|
|
100
|
+
status?: NewsletterSubscriberStatus | NewsletterSubscriberStatus[];
|
|
101
|
+
tag?: string;
|
|
102
|
+
/** Searches email and name. */
|
|
103
|
+
search?: string;
|
|
104
|
+
/** 1–100, default 50. */
|
|
105
|
+
limit?: number;
|
|
106
|
+
/** `nextCursor` from the previous page. */
|
|
107
|
+
cursor?: string;
|
|
108
|
+
}
|
|
109
|
+
export interface ServerNewsletter {
|
|
110
|
+
/**
|
|
111
|
+
* Add someone (idempotent): already on the list → returned as is with new tags added (`created: false`).
|
|
112
|
+
* People who unsubscribed are never added back: `error.code === 'previously_unsubscribed'`.
|
|
113
|
+
*/
|
|
114
|
+
add(email: string, options?: NewsletterAddOptions): Promise<Result<{
|
|
115
|
+
subscriber: NewsletterSubscriber;
|
|
116
|
+
created: boolean;
|
|
117
|
+
confirmationSent: boolean;
|
|
118
|
+
}>>;
|
|
119
|
+
/** Stop all newsletters to this address on the list. `found: false` when it isn't on the list. */
|
|
120
|
+
unsubscribe(email: string, options?: {
|
|
121
|
+
list?: string;
|
|
122
|
+
}): Promise<Result<{
|
|
123
|
+
found: boolean;
|
|
124
|
+
changed: boolean;
|
|
125
|
+
subscriber: NewsletterSubscriber | null;
|
|
126
|
+
}>>;
|
|
127
|
+
/** One page of subscribers, newest first. */
|
|
128
|
+
list(options?: NewsletterListOptions): Promise<Result<{
|
|
129
|
+
subscribers: NewsletterSubscriber[];
|
|
130
|
+
nextCursor: string | null;
|
|
131
|
+
total: number;
|
|
132
|
+
list: {
|
|
133
|
+
id: string;
|
|
134
|
+
key: string;
|
|
135
|
+
name: string;
|
|
136
|
+
};
|
|
137
|
+
}>>;
|
|
138
|
+
}
|
|
139
|
+
/** `baas.newsletter` for `usebecky/server`. `http` must carry the secret key. */
|
|
140
|
+
export declare function serverNewsletter(http: HttpClient): ServerNewsletter;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// Newsletter: let people sign up for your newsletter from your app or website.
|
|
2
|
+
//
|
|
3
|
+
// const { data, error } = await baas.newsletter.subscribe('ada@example.com', { name: 'Ada' })
|
|
4
|
+
// // data: { status: 'pending', message: 'Thanks! Check your inbox and click the link to confirm your subscription.' }
|
|
5
|
+
//
|
|
6
|
+
// With double opt-in (the default) the person gets an email and is only subscribed after clicking
|
|
7
|
+
// the link in it. The answer is the same whether or not the address was already on the list, so
|
|
8
|
+
// nobody can use your form to find out who subscribed. API: POST /newsletter/v1/subscribe.
|
|
9
|
+
//
|
|
10
|
+
// Your server (secret key) can also add, list and unsubscribe people: see `usebecky/server` → baas.newsletter.
|
|
11
|
+
import { UseBeckyError } from "../lib/errors.js";
|
|
12
|
+
function invalid(message, hint) {
|
|
13
|
+
return new UseBeckyError({ code: 'invalid_input', message, hint, status: 0 });
|
|
14
|
+
}
|
|
15
|
+
export function checkEmailArg(email, example) {
|
|
16
|
+
if (typeof email !== 'string' || !email.trim())
|
|
17
|
+
return invalid(`Pass the email address as the first argument, e.g. ${example}.`);
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
export class NewsletterClient {
|
|
21
|
+
http;
|
|
22
|
+
constructor(http) {
|
|
23
|
+
this.http = http;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Sign someone up for your newsletter.
|
|
27
|
+
*
|
|
28
|
+
* const { data, error } = await baas.newsletter.subscribe(email, { name, list: 'weekly', tags: ['footer'] })
|
|
29
|
+
* if (error) showError(error.message)
|
|
30
|
+
* else showMessage(data.message) // "Thanks! Check your inbox ..."
|
|
31
|
+
*
|
|
32
|
+
* When someone is signed in with the same email, the subscription is linked to their user.
|
|
33
|
+
*/
|
|
34
|
+
async subscribe(email, options = {}) {
|
|
35
|
+
const bad = checkEmailArg(email, 'baas.newsletter.subscribe("ada@example.com")');
|
|
36
|
+
if (bad)
|
|
37
|
+
return { data: null, error: bad };
|
|
38
|
+
if (options.tags !== undefined && (!Array.isArray(options.tags) || options.tags.some((t) => typeof t !== 'string'))) {
|
|
39
|
+
return { data: null, error: invalid('"tags" must be a list of texts, e.g. { tags: ["homepage"] }.') };
|
|
40
|
+
}
|
|
41
|
+
const body = { email: email.trim() };
|
|
42
|
+
if (options.list)
|
|
43
|
+
body.list = options.list;
|
|
44
|
+
if (options.name)
|
|
45
|
+
body.name = options.name;
|
|
46
|
+
if (options.tags?.length)
|
|
47
|
+
body.tags = options.tags;
|
|
48
|
+
if (options.captchaToken)
|
|
49
|
+
body.captcha_token = options.captchaToken;
|
|
50
|
+
const res = await this.http.request('/newsletter/v1/subscribe', { method: 'POST', body });
|
|
51
|
+
if (res.error)
|
|
52
|
+
return { data: null, error: res.error };
|
|
53
|
+
return { data: { status: res.data?.status === 'subscribed' ? 'subscribed' : 'pending', message: res.data?.message ?? '' }, error: null };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** `baas.newsletter` for `usebecky/server`. `http` must carry the secret key. */
|
|
57
|
+
export function serverNewsletter(http) {
|
|
58
|
+
return {
|
|
59
|
+
async add(email, o = {}) {
|
|
60
|
+
const bad = checkEmailArg(email, 'baas.newsletter.add("ada@example.com", { consent: "already_agreed" })');
|
|
61
|
+
if (bad)
|
|
62
|
+
return { data: null, error: bad };
|
|
63
|
+
const res = await http.request('/newsletter/v1/subscribers', { method: 'POST', body: { email: email.trim(), list: o.list, name: o.name, tags: o.tags, consent: o.consent, consent_source: o.consentSource, confirmed_at: o.confirmedAt } });
|
|
64
|
+
if (res.error)
|
|
65
|
+
return { data: null, error: res.error };
|
|
66
|
+
return { data: { subscriber: res.data.subscriber, created: !!res.data.created, confirmationSent: !!res.data.confirmation_sent }, error: null };
|
|
67
|
+
},
|
|
68
|
+
async unsubscribe(email, o = {}) {
|
|
69
|
+
const bad = checkEmailArg(email, 'baas.newsletter.unsubscribe("ada@example.com")');
|
|
70
|
+
if (bad)
|
|
71
|
+
return { data: null, error: bad };
|
|
72
|
+
const res = await http.request('/newsletter/v1/subscribers/unsubscribe', { method: 'POST', body: { email: email.trim(), list: o.list } });
|
|
73
|
+
if (res.error)
|
|
74
|
+
return { data: null, error: res.error };
|
|
75
|
+
return { data: { found: !!res.data.found, changed: !!res.data.changed, subscriber: res.data.subscriber ?? null }, error: null };
|
|
76
|
+
},
|
|
77
|
+
async list(o = {}) {
|
|
78
|
+
const status = Array.isArray(o.status) ? o.status.join(',') : o.status;
|
|
79
|
+
const res = await http.request('/newsletter/v1/subscribers', { query: { list: o.list, status, tag: o.tag, q: o.search, limit: o.limit, cursor: o.cursor } });
|
|
80
|
+
if (res.error)
|
|
81
|
+
return { data: null, error: res.error };
|
|
82
|
+
return { data: { subscribers: res.data.subscribers ?? [], nextCursor: res.data.next_cursor ?? null, total: res.data.total ?? 0, list: res.data.list }, error: null };
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|