@somewhere-cloud/cli 0.38.155 → 0.38.157
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/CHANGELOG.md +8 -1
- package/dist/commands/docs.js +1 -1
- package/dist/lib/bundle.js +286 -188
- package/dist/lib/bundle.js.map +3 -3
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -3
- package/dist/docs/adopt.md +0 -39
- package/dist/docs/analytics.md +0 -161
- package/dist/docs/api-reference.md +0 -339
- package/dist/docs/api-surface.md +0 -2067
- package/dist/docs/app-mcp.md +0 -162
- package/dist/docs/architecture-patterns.md +0 -334
- package/dist/docs/auth-client.md +0 -531
- package/dist/docs/billing.md +0 -76
- package/dist/docs/browser.md +0 -639
- package/dist/docs/calendar.md +0 -298
- package/dist/docs/changes.md +0 -323
- package/dist/docs/cli.md +0 -407
- package/dist/docs/common-mistakes.md +0 -199
- package/dist/docs/connect-agent.md +0 -72
- package/dist/docs/cors.md +0 -114
- package/dist/docs/cron.md +0 -167
- package/dist/docs/database-engine.md +0 -167
- package/dist/docs/declared-data.md +0 -1656
- package/dist/docs/declared-files.md +0 -475
- package/dist/docs/deploy-intelligence.md +0 -188
- package/dist/docs/deploy.md +0 -733
- package/dist/docs/design-system.md +0 -273
- package/dist/docs/dev-environments.md +0 -496
- package/dist/docs/domain-ownership.md +0 -31
- package/dist/docs/domains.md +0 -370
- package/dist/docs/feedback.md +0 -88
- package/dist/docs/file-tools.md +0 -116
- package/dist/docs/functions.md +0 -489
- package/dist/docs/getting-started.md +0 -238
- package/dist/docs/github.md +0 -95
- package/dist/docs/google-calendar.md +0 -212
- package/dist/docs/groups.md +0 -836
- package/dist/docs/guarantees.md +0 -58
- package/dist/docs/handled-for-you.md +0 -224
- package/dist/docs/inspect.md +0 -171
- package/dist/docs/limits.md +0 -68
- package/dist/docs/live-data.md +0 -197
- package/dist/docs/live.md +0 -92
- package/dist/docs/local-dev.md +0 -30
- package/dist/docs/migration-supabase.md +0 -58
- package/dist/docs/payments.md +0 -1102
- package/dist/docs/portability.md +0 -194
- package/dist/docs/postgres.md +0 -301
- package/dist/docs/pricing-comparison.md +0 -42
- package/dist/docs/pricing.md +0 -39
- package/dist/docs/project-groups.md +0 -107
- package/dist/docs/projects.md +0 -380
- package/dist/docs/recipe-ai-agent.md +0 -112
- package/dist/docs/recipe-ai-features.md +0 -227
- package/dist/docs/recipe-ai-receipts.md +0 -783
- package/dist/docs/recipe-background-jobs.md +0 -369
- package/dist/docs/recipe-booking.md +0 -348
- package/dist/docs/recipe-csv-import.md +0 -390
- package/dist/docs/recipe-ecommerce.md +0 -127
- package/dist/docs/recipe-email.md +0 -282
- package/dist/docs/recipe-escalation.md +0 -133
- package/dist/docs/recipe-file-uploads.md +0 -159
- package/dist/docs/recipe-import-app.md +0 -110
- package/dist/docs/recipe-login.md +0 -457
- package/dist/docs/recipe-multi-chat.md +0 -198
- package/dist/docs/recipe-paid-api.md +0 -161
- package/dist/docs/recipe-pdfs.md +0 -205
- package/dist/docs/recipe-push-notifications.md +0 -107
- package/dist/docs/recipe-seo.md +0 -200
- package/dist/docs/recipe-signed-in-app.md +0 -330
- package/dist/docs/render.md +0 -99
- package/dist/docs/rooms.md +0 -554
- package/dist/docs/sdk.md +0 -287
- package/dist/docs/sdks.md +0 -24
- package/dist/docs/search.md +0 -199
- package/dist/docs/security-model.md +0 -168
- package/dist/docs/setup.md +0 -212
- package/dist/docs/smoke.md +0 -102
- package/dist/docs/speed.md +0 -298
- package/dist/docs/sql-compatibility.md +0 -96
- package/dist/docs/sw.agent.md +0 -248
- package/dist/docs/sw.ai.md +0 -1291
- package/dist/docs/sw.auth.md +0 -1811
- package/dist/docs/sw.billing.md +0 -171
- package/dist/docs/sw.db.md +0 -2128
- package/dist/docs/sw.email.md +0 -661
- package/dist/docs/sw.endpoint.md +0 -187
- package/dist/docs/sw.env.md +0 -303
- package/dist/docs/sw.fetch.md +0 -115
- package/dist/docs/sw.fs.md +0 -424
- package/dist/docs/sw.groups.md +0 -836
- package/dist/docs/sw.image.md +0 -69
- package/dist/docs/sw.jobs.md +0 -520
- package/dist/docs/sw.logs.md +0 -61
- package/dist/docs/sw.mail.md +0 -106
- package/dist/docs/sw.notifications.md +0 -78
- package/dist/docs/sw.push.md +0 -161
- package/dist/docs/sw.rateLimit.md +0 -67
- package/dist/docs/sw.web.md +0 -128
- package/dist/docs/tasks.md +0 -269
- package/dist/docs/test.md +0 -220
- package/dist/docs/tool-reference-account.md +0 -7
- package/dist/docs/tool-reference-ai.md +0 -121
- package/dist/docs/tool-reference-analytics.md +0 -37
- package/dist/docs/tool-reference-api.md +0 -19
- package/dist/docs/tool-reference-artifacts.md +0 -35
- package/dist/docs/tool-reference-auth.md +0 -163
- package/dist/docs/tool-reference-browser.md +0 -114
- package/dist/docs/tool-reference-code.md +0 -26
- package/dist/docs/tool-reference-connect.md +0 -21
- package/dist/docs/tool-reference-cron.md +0 -48
- package/dist/docs/tool-reference-db.md +0 -282
- package/dist/docs/tool-reference-domains.md +0 -107
- package/dist/docs/tool-reference-email.md +0 -55
- package/dist/docs/tool-reference-env.md +0 -19
- package/dist/docs/tool-reference-feedback.md +0 -56
- package/dist/docs/tool-reference-fs.md +0 -265
- package/dist/docs/tool-reference-github.md +0 -57
- package/dist/docs/tool-reference-groups.md +0 -85
- package/dist/docs/tool-reference-help.md +0 -29
- package/dist/docs/tool-reference-jobs.md +0 -39
- package/dist/docs/tool-reference-live.md +0 -48
- package/dist/docs/tool-reference-logs.md +0 -16
- package/dist/docs/tool-reference-payments.md +0 -44
- package/dist/docs/tool-reference-project.md +0 -706
- package/dist/docs/tool-reference-push.md +0 -78
- package/dist/docs/tool-reference-rate-limit.md +0 -18
- package/dist/docs/tool-reference-search.md +0 -68
- package/dist/docs/tool-reference-security.md +0 -42
- package/dist/docs/tool-reference-smoke.md +0 -17
- package/dist/docs/tool-reference-stock-photos.md +0 -20
- package/dist/docs/tool-reference-tasks.md +0 -73
- package/dist/docs/tool-reference-telegram.md +0 -32
- package/dist/docs/tool-reference-usage.md +0 -9
- package/dist/docs/tool-reference-web.md +0 -71
- package/dist/docs/tool-reference-webhooks.md +0 -9
- package/dist/docs/troubleshooting.md +0 -411
- package/dist/docs/typed-functions.md +0 -94
- package/dist/docs/verify-before-deploy.md +0 -67
- package/dist/docs/vs-supabase.md +0 -75
- package/dist/docs/vs-vercel.md +0 -103
package/dist/docs/sw.billing.md
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
# sw.billing — plans & feature gating for YOUR app's users
|
|
2
|
-
|
|
3
|
-
Define the plans YOUR app sells and the features each one unlocks, then gate
|
|
4
|
-
anything with a single check. You gate on a stable feature name (`'export'`),
|
|
5
|
-
never on a plan name or a Stripe price — so renaming or re-pricing a plan never
|
|
6
|
-
touches your gate code. This is the entitlement layer that pairs with
|
|
7
|
-
`sw.payments` (which collects the money): a confirmed live plan checkout
|
|
8
|
-
sets the user's plan, and `sw.billing` turns that plan into yes/no answers.
|
|
9
|
-
Test purchases are recorded separately and do not unlock these live features.
|
|
10
|
-
|
|
11
|
-
(Looking for OUR pricing tiers — what somewhere.cloud charges YOU? That's
|
|
12
|
-
`docs({ topic: 'billing' })`. This topic is about the plans YOUR app offers
|
|
13
|
-
ITS users.)
|
|
14
|
-
|
|
15
|
-
## 1. Define your plans (in code, once)
|
|
16
|
-
|
|
17
|
-
```js
|
|
18
|
-
// from a protected setup path (below); idempotent, so re-run it when plans change
|
|
19
|
-
await sw.billing.definePlans([
|
|
20
|
-
{ slug: 'free', name: 'Free', features: [] },
|
|
21
|
-
{ slug: 'pro', name: 'Pro', price_cents: 2000, interval: 'month',
|
|
22
|
-
stripe_price_id: 'price_...', // required for live checkout; omit for a test monthly or yearly plan
|
|
23
|
-
features: ['export', 'api_access', { feature: 'seats', limit: 10 }] },
|
|
24
|
-
]);
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
- Any caller of `definePlans` replaces the catalog, so run it only from a
|
|
28
|
-
path you control: `POST /v1/entitlements/plans` with your developer key
|
|
29
|
-
(body `{ project_id, plans }`), or a function that first checks
|
|
30
|
-
`await sw.auth.requireUser(req, { role: 'admin' })`. Never from a handler
|
|
31
|
-
any visitor can call.
|
|
32
|
-
- The list becomes your catalog. An omitted plan is removed unless a user
|
|
33
|
-
still has it; those plans are kept and returned in `retained_plan_slugs`
|
|
34
|
-
with a warning. Repeating the same definition is safe.
|
|
35
|
-
- `slug` is what a user's plan is set to. `features` are free-form names you
|
|
36
|
-
invent and gate on; a feature can carry an optional numeric `limit`.
|
|
37
|
-
- `price_cents` and `interval` describe your plan. In test mode, a monthly
|
|
38
|
-
or yearly plan can use them at checkout without a Stripe price ID. Defining
|
|
39
|
-
a plan creates no charge; `sw.payments` starts checkout.
|
|
40
|
-
- View the catalog with `GET /v1/entitlements/plans?project_id=<id>`. Define plans in your code.
|
|
41
|
-
|
|
42
|
-
## 2. Gate a feature
|
|
43
|
-
|
|
44
|
-
Server side, in a function:
|
|
45
|
-
|
|
46
|
-
```js
|
|
47
|
-
if (await sw.billing.has('export')) {
|
|
48
|
-
// ...do the gated thing
|
|
49
|
-
}
|
|
50
|
-
const ent = await sw.billing.entitlements();
|
|
51
|
-
// ent = { plan: 'pro', plan_defined: true, features: ['export','api_access','seats'], limits: { seats: 10 } }
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
`has()` and `entitlements()` read the currently recorded live billing
|
|
55
|
-
grant on every call. Checkout completion affects access after platform payment
|
|
56
|
-
processing; cancellation may retain access until the paid period ends.
|
|
57
|
-
|
|
58
|
-
Client side, render an explicit observation fetched from your authenticated
|
|
59
|
-
function. The browser's sign-in user does not contain paid assertions.
|
|
60
|
-
A minimal server route is:
|
|
61
|
-
|
|
62
|
-
```ts
|
|
63
|
-
export default async function billing(req: Request, sw: SomewhereRuntimeContext) {
|
|
64
|
-
await sw.auth.requireUser(req);
|
|
65
|
-
const { plan, features } = await sw.billing.entitlements();
|
|
66
|
-
return Response.json({ plan, features }, { headers: { 'Cache-Control': 'no-store' } });
|
|
67
|
-
}
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
Your UI fetches that route with its session, starting in `loading`, changing
|
|
71
|
-
to `ready` only after a successful validated answer, and to `unavailable`
|
|
72
|
-
on failure. Discard observations when the signed-in account changes; cancel
|
|
73
|
-
or ignore late answers from the previous account. Refresh after checkout.
|
|
74
|
-
Do not turn a failed billing request into a free plan or an upgrade prompt.
|
|
75
|
-
|
|
76
|
-
```tsx
|
|
77
|
-
import { useEntitlements, Gate, type BillingObservation } from '@somewhere-cloud/sdk/react';
|
|
78
|
-
|
|
79
|
-
type ExportActions = {
|
|
80
|
-
billing: BillingObservation;
|
|
81
|
-
onExport: () => void;
|
|
82
|
-
onUpgrade: () => void;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
export function ExportButton({ billing, onExport, onUpgrade }: ExportActions) {
|
|
86
|
-
const access = useEntitlements(billing);
|
|
87
|
-
if (access.status === 'loading') return <button type="button" disabled>Checking access</button>;
|
|
88
|
-
if (access.status === 'unavailable') return <p>Access could not be checked. Try again.</p>;
|
|
89
|
-
return access.has('export')
|
|
90
|
-
? <button type="button" onClick={onExport}>Export</button>
|
|
91
|
-
: <button type="button" onClick={onUpgrade}>Upgrade to export</button>;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export function ExportGate({ billing, onExport, onUpgrade }: ExportActions) {
|
|
95
|
-
return (
|
|
96
|
-
<Gate billing={billing} feature="export"
|
|
97
|
-
pending={<p>Checking access</p>}
|
|
98
|
-
unavailable={<p>Access could not be checked. Try again.</p>}
|
|
99
|
-
fallback={<button type="button" onClick={onUpgrade}>Upgrade to export</button>}>
|
|
100
|
-
<button type="button" onClick={onExport}>Export</button>
|
|
101
|
-
</Gate>
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
These helpers choose presentation only. The function performing the operation
|
|
107
|
-
must still enforce `await sw.billing.has('export')`. Passing no observation
|
|
108
|
-
to `useEntitlements` or `Gate`, or calling the old synchronous
|
|
109
|
-
`auth.billing.has()` / `auth.billing.entitlements()`, throws
|
|
110
|
-
`BILLING_EXPLICIT_CHECK_REQUIRED` with the server-check remedy. No helper
|
|
111
|
-
silently reads paid fields from sign-in identity or starts a billing request.
|
|
112
|
-
|
|
113
|
-
`auth.billing.plans()` returns the catalog for rendering a pricing page.
|
|
114
|
-
|
|
115
|
-
## 3. Drop-in pricing + manage UI (React)
|
|
116
|
-
|
|
117
|
-
Pricing and manage-subscription components use the @somewhere-cloud/sdk/auth
|
|
118
|
-
session. Pass the current plan from your explicit billing observation; wait
|
|
119
|
-
for that observation before offering a new subscription:
|
|
120
|
-
|
|
121
|
-
```tsx
|
|
122
|
-
// src/pages/BillingPage.tsx
|
|
123
|
-
import { PricingTable, BillingPortal } from '@somewhere-cloud/sdk/react';
|
|
124
|
-
|
|
125
|
-
export function BillingPage({ currentPlan }: { currentPlan: string }) {
|
|
126
|
-
return (
|
|
127
|
-
<>
|
|
128
|
-
{/* Your catalog plans, current plan highlighted; Subscribe → checkout */}
|
|
129
|
-
<PricingTable currentPlan={currentPlan} />
|
|
130
|
-
{/* One-click "manage/cancel" via the Stripe portal */}
|
|
131
|
-
<BillingPortal />
|
|
132
|
-
</>
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
Both are logic-only/unstyled — theme with the `sw-*` class hooks
|
|
138
|
-
(`sw-pricing-table`, `sw-plan[data-current]`, `sw-plan-name/-price/-features/-cta`,
|
|
139
|
-
`sw-billing-portal`). Prefer to wire it yourself? The same actions are on the
|
|
140
|
-
client: `auth.billing.subscribe(planSlug)` and `auth.billing.openBillingPortal()`
|
|
141
|
-
(both redirect to Stripe; success/cancel/return default to the current page).
|
|
142
|
-
|
|
143
|
-
Subscribe checks out for the SIGNED-IN user (resolved server-side from the
|
|
144
|
-
session, never a client-supplied id) and the platform resolves the plan's price
|
|
145
|
-
from your active catalog. In test mode, define a plan with `price_cents`
|
|
146
|
-
and `interval: 'month'` or `'year'`; checkout creates the recurring test
|
|
147
|
-
price for you, including on the shared test account. An existing
|
|
148
|
-
`stripe_price_id` is used directly. For live checkout, set that ID to a
|
|
149
|
-
price on your connected Stripe account.
|
|
150
|
-
|
|
151
|
-
## 4. How a user gets a plan
|
|
152
|
-
|
|
153
|
-
You don't write webhook code. `sw.payments.checkoutForUser({ plan })`
|
|
154
|
-
(what `<PricingTable>` calls under the hood) starts a Checkout Session; when
|
|
155
|
-
a live payment is confirmed, the platform grants the selected plan and
|
|
156
|
-
`sw.billing` reflects it. Payment retries retain access. Scheduled cancellation
|
|
157
|
-
retains access until the subscription ends; unpaid, paused, canceled and expired
|
|
158
|
-
subscriptions have no paid access. Test checkout never changes live access.
|
|
159
|
-
(`docs({ topic: 'payments' })` covers the checkout side.)
|
|
160
|
-
|
|
161
|
-
## Notes
|
|
162
|
-
|
|
163
|
-
- For the current plan name, use `(await sw.billing.entitlements()).plan`
|
|
164
|
-
in an authenticated function. Sign-in identity has no billing fields.
|
|
165
|
-
- A browser observation can become stale after it is fetched. It is for
|
|
166
|
-
presentation; paid operations must check billing on the server.
|
|
167
|
-
- REST (if you're not in a function): `POST /v1/entitlements/plans` (define,
|
|
168
|
-
developer key), `GET /v1/entitlements/plans` (catalog), `GET
|
|
169
|
-
/v1/entitlements/me`, `GET /v1/entitlements/has?feature=…`.
|
|
170
|
-
|
|
171
|
-
Related topics: `payments`, `auth-client`, `sw.auth`.
|