@somewhere-cloud/cli 0.38.154 → 0.38.155

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