@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.
Files changed (142) hide show
  1. package/CHANGELOG.md +8 -1
  2. package/dist/commands/docs.js +1 -1
  3. package/dist/lib/bundle.js +286 -188
  4. package/dist/lib/bundle.js.map +3 -3
  5. package/npm-shrinkwrap.json +2 -2
  6. package/package.json +2 -3
  7. package/dist/docs/adopt.md +0 -39
  8. package/dist/docs/analytics.md +0 -161
  9. package/dist/docs/api-reference.md +0 -339
  10. package/dist/docs/api-surface.md +0 -2067
  11. package/dist/docs/app-mcp.md +0 -162
  12. package/dist/docs/architecture-patterns.md +0 -334
  13. package/dist/docs/auth-client.md +0 -531
  14. package/dist/docs/billing.md +0 -76
  15. package/dist/docs/browser.md +0 -639
  16. package/dist/docs/calendar.md +0 -298
  17. package/dist/docs/changes.md +0 -323
  18. package/dist/docs/cli.md +0 -407
  19. package/dist/docs/common-mistakes.md +0 -199
  20. package/dist/docs/connect-agent.md +0 -72
  21. package/dist/docs/cors.md +0 -114
  22. package/dist/docs/cron.md +0 -167
  23. package/dist/docs/database-engine.md +0 -167
  24. package/dist/docs/declared-data.md +0 -1656
  25. package/dist/docs/declared-files.md +0 -475
  26. package/dist/docs/deploy-intelligence.md +0 -188
  27. package/dist/docs/deploy.md +0 -733
  28. package/dist/docs/design-system.md +0 -273
  29. package/dist/docs/dev-environments.md +0 -496
  30. package/dist/docs/domain-ownership.md +0 -31
  31. package/dist/docs/domains.md +0 -370
  32. package/dist/docs/feedback.md +0 -88
  33. package/dist/docs/file-tools.md +0 -116
  34. package/dist/docs/functions.md +0 -489
  35. package/dist/docs/getting-started.md +0 -238
  36. package/dist/docs/github.md +0 -95
  37. package/dist/docs/google-calendar.md +0 -212
  38. package/dist/docs/groups.md +0 -836
  39. package/dist/docs/guarantees.md +0 -58
  40. package/dist/docs/handled-for-you.md +0 -224
  41. package/dist/docs/inspect.md +0 -171
  42. package/dist/docs/limits.md +0 -68
  43. package/dist/docs/live-data.md +0 -197
  44. package/dist/docs/live.md +0 -92
  45. package/dist/docs/local-dev.md +0 -30
  46. package/dist/docs/migration-supabase.md +0 -58
  47. package/dist/docs/payments.md +0 -1102
  48. package/dist/docs/portability.md +0 -194
  49. package/dist/docs/postgres.md +0 -301
  50. package/dist/docs/pricing-comparison.md +0 -42
  51. package/dist/docs/pricing.md +0 -39
  52. package/dist/docs/project-groups.md +0 -107
  53. package/dist/docs/projects.md +0 -380
  54. package/dist/docs/recipe-ai-agent.md +0 -112
  55. package/dist/docs/recipe-ai-features.md +0 -227
  56. package/dist/docs/recipe-ai-receipts.md +0 -783
  57. package/dist/docs/recipe-background-jobs.md +0 -369
  58. package/dist/docs/recipe-booking.md +0 -348
  59. package/dist/docs/recipe-csv-import.md +0 -390
  60. package/dist/docs/recipe-ecommerce.md +0 -127
  61. package/dist/docs/recipe-email.md +0 -282
  62. package/dist/docs/recipe-escalation.md +0 -133
  63. package/dist/docs/recipe-file-uploads.md +0 -159
  64. package/dist/docs/recipe-import-app.md +0 -110
  65. package/dist/docs/recipe-login.md +0 -457
  66. package/dist/docs/recipe-multi-chat.md +0 -198
  67. package/dist/docs/recipe-paid-api.md +0 -161
  68. package/dist/docs/recipe-pdfs.md +0 -205
  69. package/dist/docs/recipe-push-notifications.md +0 -107
  70. package/dist/docs/recipe-seo.md +0 -200
  71. package/dist/docs/recipe-signed-in-app.md +0 -330
  72. package/dist/docs/render.md +0 -99
  73. package/dist/docs/rooms.md +0 -554
  74. package/dist/docs/sdk.md +0 -287
  75. package/dist/docs/sdks.md +0 -24
  76. package/dist/docs/search.md +0 -199
  77. package/dist/docs/security-model.md +0 -168
  78. package/dist/docs/setup.md +0 -212
  79. package/dist/docs/smoke.md +0 -102
  80. package/dist/docs/speed.md +0 -298
  81. package/dist/docs/sql-compatibility.md +0 -96
  82. package/dist/docs/sw.agent.md +0 -248
  83. package/dist/docs/sw.ai.md +0 -1291
  84. package/dist/docs/sw.auth.md +0 -1811
  85. package/dist/docs/sw.billing.md +0 -171
  86. package/dist/docs/sw.db.md +0 -2128
  87. package/dist/docs/sw.email.md +0 -661
  88. package/dist/docs/sw.endpoint.md +0 -187
  89. package/dist/docs/sw.env.md +0 -303
  90. package/dist/docs/sw.fetch.md +0 -115
  91. package/dist/docs/sw.fs.md +0 -424
  92. package/dist/docs/sw.groups.md +0 -836
  93. package/dist/docs/sw.image.md +0 -69
  94. package/dist/docs/sw.jobs.md +0 -520
  95. package/dist/docs/sw.logs.md +0 -61
  96. package/dist/docs/sw.mail.md +0 -106
  97. package/dist/docs/sw.notifications.md +0 -78
  98. package/dist/docs/sw.push.md +0 -161
  99. package/dist/docs/sw.rateLimit.md +0 -67
  100. package/dist/docs/sw.web.md +0 -128
  101. package/dist/docs/tasks.md +0 -269
  102. package/dist/docs/test.md +0 -220
  103. package/dist/docs/tool-reference-account.md +0 -7
  104. package/dist/docs/tool-reference-ai.md +0 -121
  105. package/dist/docs/tool-reference-analytics.md +0 -37
  106. package/dist/docs/tool-reference-api.md +0 -19
  107. package/dist/docs/tool-reference-artifacts.md +0 -35
  108. package/dist/docs/tool-reference-auth.md +0 -163
  109. package/dist/docs/tool-reference-browser.md +0 -114
  110. package/dist/docs/tool-reference-code.md +0 -26
  111. package/dist/docs/tool-reference-connect.md +0 -21
  112. package/dist/docs/tool-reference-cron.md +0 -48
  113. package/dist/docs/tool-reference-db.md +0 -282
  114. package/dist/docs/tool-reference-domains.md +0 -107
  115. package/dist/docs/tool-reference-email.md +0 -55
  116. package/dist/docs/tool-reference-env.md +0 -19
  117. package/dist/docs/tool-reference-feedback.md +0 -56
  118. package/dist/docs/tool-reference-fs.md +0 -265
  119. package/dist/docs/tool-reference-github.md +0 -57
  120. package/dist/docs/tool-reference-groups.md +0 -85
  121. package/dist/docs/tool-reference-help.md +0 -29
  122. package/dist/docs/tool-reference-jobs.md +0 -39
  123. package/dist/docs/tool-reference-live.md +0 -48
  124. package/dist/docs/tool-reference-logs.md +0 -16
  125. package/dist/docs/tool-reference-payments.md +0 -44
  126. package/dist/docs/tool-reference-project.md +0 -706
  127. package/dist/docs/tool-reference-push.md +0 -78
  128. package/dist/docs/tool-reference-rate-limit.md +0 -18
  129. package/dist/docs/tool-reference-search.md +0 -68
  130. package/dist/docs/tool-reference-security.md +0 -42
  131. package/dist/docs/tool-reference-smoke.md +0 -17
  132. package/dist/docs/tool-reference-stock-photos.md +0 -20
  133. package/dist/docs/tool-reference-tasks.md +0 -73
  134. package/dist/docs/tool-reference-telegram.md +0 -32
  135. package/dist/docs/tool-reference-usage.md +0 -9
  136. package/dist/docs/tool-reference-web.md +0 -71
  137. package/dist/docs/tool-reference-webhooks.md +0 -9
  138. package/dist/docs/troubleshooting.md +0 -411
  139. package/dist/docs/typed-functions.md +0 -94
  140. package/dist/docs/verify-before-deploy.md +0 -67
  141. package/dist/docs/vs-supabase.md +0 -75
  142. package/dist/docs/vs-vercel.md +0 -103
@@ -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`.