anhedral 0.15.0 → 0.16.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.
Files changed (308) hide show
  1. package/README.md +29 -38
  2. package/assets/stack/ai-schema.ts.txt +5 -0
  3. package/assets/stack/ai.ts.txt +30 -0
  4. package/assets/stack/api-index.ts.txt +15 -0
  5. package/assets/stack/auth-features.ts.txt +4 -0
  6. package/assets/stack/auth-journal.json.txt +13 -0
  7. package/assets/stack/auth-migration.sql.txt +53 -0
  8. package/assets/stack/auth-routes.ts.txt +11 -0
  9. package/assets/stack/auth-schema.ts.txt +64 -0
  10. package/assets/stack/auth-snapshot.json.txt +346 -0
  11. package/assets/stack/auth.ts.txt +32 -0
  12. package/assets/stack/billing-mode.ts.txt +8 -0
  13. package/assets/stack/billing-schema.ts.txt +11 -0
  14. package/assets/stack/desktop.rs.txt +21 -0
  15. package/assets/stack/entitlement-guard.ts.txt +32 -0
  16. package/assets/stack/entitlements.ts.txt +8 -0
  17. package/assets/stack/events-schema.ts.txt +12 -0
  18. package/assets/stack/events.ts.txt +59 -0
  19. package/assets/stack/mobile-auth.ts.txt +25 -0
  20. package/assets/stack/mobile-billing.tsx.txt +63 -0
  21. package/assets/stack/mobile-session.tsx.txt +83 -0
  22. package/assets/stack/native-button.tsx.txt +108 -0
  23. package/assets/stack/native-global.css.txt +4 -0
  24. package/assets/stack/native-lib-utils.ts.txt +5 -0
  25. package/assets/stack/native-metro.config.js.txt +6 -0
  26. package/assets/stack/native-nativewind-env.d.ts.txt +1 -0
  27. package/assets/stack/native-tailwind.config.js.txt +73 -0
  28. package/assets/stack/native-text.tsx.txt +89 -0
  29. package/assets/stack/purchases.ts.txt +65 -0
  30. package/assets/stack/revenuecat.ts.txt +88 -0
  31. package/assets/stack/rtc-schema.ts.txt +10 -0
  32. package/assets/stack/rtc.ts.txt +122 -0
  33. package/assets/stack/security.ts.txt +31 -0
  34. package/assets/stack/storage.ts.txt +36 -0
  35. package/assets/stack/stripe.ts.txt +126 -0
  36. package/assets/stack/web-sign-in.tsx.txt +51 -0
  37. package/assets/ui/LICENSE.react-native-reusables +21 -0
  38. package/assets/ui/UPSTREAM.json +7 -1
  39. package/assets/ui/catalog.json +891 -0
  40. package/assets/ui/extensions/registry.json +6 -0
  41. package/assets/ui/native/_controls.tsx +521 -0
  42. package/assets/ui/native/_core.tsx +118 -0
  43. package/assets/ui/native/_data.tsx +200 -0
  44. package/assets/ui/native/_display.tsx +453 -0
  45. package/assets/ui/native/_feedback.tsx +242 -0
  46. package/assets/ui/native/_legacy-dialog.tsx +38 -0
  47. package/assets/ui/native/_motion.tsx +520 -0
  48. package/assets/ui/native/_overlay.tsx +402 -0
  49. package/assets/ui/native/_selection.tsx +366 -0
  50. package/assets/ui/native/accordion.tsx +1 -0
  51. package/assets/ui/native/alert-dialog.tsx +11 -0
  52. package/assets/ui/native/alert.tsx +1 -0
  53. package/assets/ui/native/aspect-ratio.tsx +1 -0
  54. package/assets/ui/native/attachment.tsx +8 -0
  55. package/assets/ui/native/avatar.tsx +8 -0
  56. package/assets/ui/native/badge.tsx +1 -0
  57. package/assets/ui/native/breadcrumb.tsx +9 -0
  58. package/assets/ui/native/bubble.tsx +1 -0
  59. package/assets/ui/native/button-group.tsx +1 -0
  60. package/assets/ui/native/button.tsx +2 -1
  61. package/assets/ui/native/calendar.tsx +170 -0
  62. package/assets/ui/native/card.tsx +16 -5
  63. package/assets/ui/native/carousel.tsx +1 -0
  64. package/assets/ui/native/chart.tsx +193 -0
  65. package/assets/ui/native/checkbox.tsx +1 -0
  66. package/assets/ui/native/code-block.tsx +137 -0
  67. package/assets/ui/native/collapsible.tsx +1 -0
  68. package/assets/ui/native/combobox.tsx +1 -0
  69. package/assets/ui/native/command.tsx +11 -0
  70. package/assets/ui/native/context-menu.tsx +16 -0
  71. package/assets/ui/native/data-table.tsx +1 -0
  72. package/assets/ui/native/date-picker.tsx +43 -0
  73. package/assets/ui/native/dialog.tsx +14 -74
  74. package/assets/ui/native/direction.tsx +1 -0
  75. package/assets/ui/native/drawer.tsx +10 -0
  76. package/assets/ui/native/dropdown-menu.tsx +16 -0
  77. package/assets/ui/native/empty.tsx +8 -0
  78. package/assets/ui/native/field.tsx +13 -0
  79. package/assets/ui/native/hover-card.tsx +1 -0
  80. package/assets/ui/native/input-group.tsx +8 -0
  81. package/assets/ui/native/input-otp.tsx +1 -0
  82. package/assets/ui/native/input.tsx +2 -1
  83. package/assets/ui/native/item.tsx +12 -0
  84. package/assets/ui/native/kbd.tsx +1 -0
  85. package/assets/ui/native/marker.tsx +1 -0
  86. package/assets/ui/native/menubar.tsx +17 -0
  87. package/assets/ui/native/message-scroller.tsx +6 -0
  88. package/assets/ui/native/message.tsx +10 -0
  89. package/assets/ui/native/native-select.tsx +1 -0
  90. package/assets/ui/native/navigation-menu.tsx +10 -0
  91. package/assets/ui/native/pagination.tsx +9 -0
  92. package/assets/ui/native/popover.tsx +1 -0
  93. package/assets/ui/native/progress.tsx +1 -0
  94. package/assets/ui/native/questionnaire.tsx +130 -0
  95. package/assets/ui/native/radio-group.tsx +1 -0
  96. package/assets/ui/native/registry.json +1103 -0
  97. package/assets/ui/native/resizable.tsx +1 -0
  98. package/assets/ui/native/scroll-area.tsx +1 -0
  99. package/assets/ui/native/select.tsx +11 -0
  100. package/assets/ui/native/separator.tsx +1 -0
  101. package/assets/ui/native/sheet.tsx +10 -0
  102. package/assets/ui/native/sidebar.tsx +22 -0
  103. package/assets/ui/native/skeleton.tsx +1 -0
  104. package/assets/ui/native/slider.tsx +1 -0
  105. package/assets/ui/native/spinner.tsx +1 -0
  106. package/assets/ui/native/switch.tsx +1 -0
  107. package/assets/ui/native/table.tsx +10 -0
  108. package/assets/ui/native/tabs.tsx +1 -0
  109. package/assets/ui/native/textarea.tsx +1 -0
  110. package/assets/ui/native/toast.tsx +11 -0
  111. package/assets/ui/native/toggle-group.tsx +1 -0
  112. package/assets/ui/native/toggle.tsx +1 -0
  113. package/assets/ui/native/tooltip.tsx +1 -0
  114. package/assets/ui/native/trace.tsx +20 -0
  115. package/assets/ui/native/typography.tsx +15 -0
  116. package/dist/bin.js +7 -12
  117. package/dist/capabilities.d.ts +4 -33
  118. package/dist/capabilities.js +2 -66
  119. package/dist/capability-catalog.d.ts +83 -0
  120. package/dist/capability-catalog.js +121 -0
  121. package/dist/capability-command.d.ts +3 -0
  122. package/dist/capability-command.js +188 -0
  123. package/dist/capability-editor.d.ts +17 -0
  124. package/dist/capability-editor.js +97 -0
  125. package/dist/capability-recipes.d.ts +4 -0
  126. package/dist/capability-recipes.js +520 -0
  127. package/dist/capability-references.d.ts +4 -0
  128. package/dist/capability-references.js +7 -0
  129. package/dist/cli-commands.d.ts +1 -2
  130. package/dist/cli-commands.js +10 -104
  131. package/dist/cli-output.d.ts +1 -2
  132. package/dist/cli-output.js +6 -251
  133. package/dist/command-schema.js +39 -322
  134. package/dist/dependencies.d.ts +29 -6
  135. package/dist/dependencies.js +61 -14
  136. package/dist/index.d.ts +1 -42
  137. package/dist/index.js +1 -27
  138. package/dist/platforms/mobile.js +1 -20
  139. package/dist/platforms/web.d.ts +1 -1
  140. package/dist/platforms/web.js +27 -75
  141. package/dist/project-config.d.ts +2 -13
  142. package/dist/project-config.js +10 -82
  143. package/dist/registry/options.js +1 -5
  144. package/dist/registry/resolve.d.ts +1 -1
  145. package/dist/registry/resolve.js +2 -10
  146. package/dist/registry/usage.js +3 -9
  147. package/dist/scaffold/backend.js +0 -3
  148. package/dist/scaffold/database.js +2 -1
  149. package/dist/scaffold/documentation.js +82 -20
  150. package/dist/scaffold/expo-runtime.js +3 -4
  151. package/dist/scaffold/native-ui.js +12 -7
  152. package/dist/scaffold/stack-documentation.js +1 -1
  153. package/dist/scaffold/storage.d.ts +2 -0
  154. package/dist/scaffold/storage.js +21 -0
  155. package/dist/scaffold/workspace.js +26 -21
  156. package/dist/stack-registry.d.ts +2 -8
  157. package/dist/stack-registry.js +11 -87
  158. package/dist/standard.js +1 -11
  159. package/dist/ui-catalog.d.ts +26 -0
  160. package/dist/ui-catalog.js +31 -0
  161. package/dist/ui-command.d.ts +3 -0
  162. package/dist/ui-command.js +219 -0
  163. package/dist/ui-project.d.ts +22 -0
  164. package/dist/ui-project.js +110 -0
  165. package/dist/version.d.ts +1 -1
  166. package/dist/version.js +1 -1
  167. package/docs/anhedral-stack.md +4 -20
  168. package/docs/capabilities.md +110 -0
  169. package/docs/native-ui.md +102 -0
  170. package/docs/software-factory.md +16 -44
  171. package/docs/stack-standard.md +11 -60
  172. package/docs/ui.md +33 -0
  173. package/docs/verification.md +191 -0
  174. package/package.json +19 -18
  175. package/dist/access.d.ts +0 -10
  176. package/dist/access.js +0 -93
  177. package/dist/auth-schema-snapshot.d.ts +0 -346
  178. package/dist/auth-schema-snapshot.js +0 -347
  179. package/dist/auth-schema.d.ts +0 -1
  180. package/dist/auth-schema.js +0 -57
  181. package/dist/capability-contract.d.ts +0 -47
  182. package/dist/capability-contract.js +0 -129
  183. package/dist/catalog-model.d.ts +0 -24
  184. package/dist/catalog-model.js +0 -1
  185. package/dist/catalog-registration.d.ts +0 -16
  186. package/dist/catalog-registration.js +0 -22
  187. package/dist/catalog-snapshot.d.ts +0 -5
  188. package/dist/catalog-snapshot.js +0 -97
  189. package/dist/cli-delivery.d.ts +0 -3
  190. package/dist/cli-delivery.js +0 -112
  191. package/dist/cloudflare.d.ts +0 -25
  192. package/dist/cloudflare.js +0 -226
  193. package/dist/delivery-evidence.d.ts +0 -62
  194. package/dist/delivery-evidence.js +0 -157
  195. package/dist/delivery.d.ts +0 -82
  196. package/dist/delivery.js +0 -489
  197. package/dist/inspector-model.d.ts +0 -123
  198. package/dist/inspector-model.js +0 -1
  199. package/dist/integration-service-readers.d.ts +0 -12
  200. package/dist/integration-service-readers.js +0 -92
  201. package/dist/lifecycle-model.d.ts +0 -15
  202. package/dist/lifecycle-model.js +0 -20
  203. package/dist/lifecycle.d.ts +0 -11
  204. package/dist/lifecycle.js +0 -91
  205. package/dist/management.d.ts +0 -3
  206. package/dist/management.js +0 -47
  207. package/dist/mobile-delivery.d.ts +0 -77
  208. package/dist/mobile-delivery.js +0 -370
  209. package/dist/project-catalog.d.ts +0 -41
  210. package/dist/project-catalog.js +0 -288
  211. package/dist/project-inspector.d.ts +0 -4
  212. package/dist/project-inspector.js +0 -671
  213. package/dist/project-lifecycle.d.ts +0 -25
  214. package/dist/project-lifecycle.js +0 -57
  215. package/dist/project-state.d.ts +0 -47
  216. package/dist/project-state.js +0 -480
  217. package/dist/provider-auth.d.ts +0 -41
  218. package/dist/provider-auth.js +0 -180
  219. package/dist/provider-readiness.d.ts +0 -30
  220. package/dist/provider-readiness.js +0 -85
  221. package/dist/providers/adapters.d.ts +0 -17
  222. package/dist/providers/adapters.js +0 -103
  223. package/dist/providers/api.d.ts +0 -29
  224. package/dist/providers/api.js +0 -253
  225. package/dist/providers/config.d.ts +0 -15
  226. package/dist/providers/config.js +0 -136
  227. package/dist/providers/definitions.d.ts +0 -115
  228. package/dist/providers/definitions.js +0 -42
  229. package/dist/providers/provision.d.ts +0 -24
  230. package/dist/providers/provision.js +0 -76
  231. package/dist/providers/receipts.d.ts +0 -20
  232. package/dist/providers/receipts.js +0 -56
  233. package/dist/providers/recovery-verification.d.ts +0 -7
  234. package/dist/providers/recovery-verification.js +0 -52
  235. package/dist/providers/recovery.d.ts +0 -30
  236. package/dist/providers/recovery.js +0 -34
  237. package/dist/providers/runtime.d.ts +0 -10
  238. package/dist/providers/runtime.js +0 -234
  239. package/dist/providers/schema.d.ts +0 -28
  240. package/dist/providers/schema.js +0 -49
  241. package/dist/providers/state.d.ts +0 -55
  242. package/dist/providers/state.js +0 -283
  243. package/dist/provision.d.ts +0 -47
  244. package/dist/provision.js +0 -208
  245. package/dist/r2-service-data.d.ts +0 -2
  246. package/dist/r2-service-data.js +0 -136
  247. package/dist/readiness.d.ts +0 -23
  248. package/dist/readiness.js +0 -117
  249. package/dist/registry/add.d.ts +0 -24
  250. package/dist/registry/add.js +0 -210
  251. package/dist/registry/bootstrap.d.ts +0 -3
  252. package/dist/registry/bootstrap.js +0 -5
  253. package/dist/registry/commands.d.ts +0 -3
  254. package/dist/registry/commands.js +0 -83
  255. package/dist/registry/preview.d.ts +0 -11
  256. package/dist/registry/preview.js +0 -91
  257. package/dist/registry/receipt.d.ts +0 -3
  258. package/dist/registry/receipt.js +0 -68
  259. package/dist/repository.d.ts +0 -24
  260. package/dist/repository.js +0 -96
  261. package/dist/scaffold/auth.d.ts +0 -2
  262. package/dist/scaffold/auth.js +0 -76
  263. package/dist/scaffold/billing-config.d.ts +0 -1
  264. package/dist/scaffold/billing-config.js +0 -73
  265. package/dist/scaffold/billing-contracts.d.ts +0 -2
  266. package/dist/scaffold/billing-contracts.js +0 -48
  267. package/dist/scaffold/billing-providers.d.ts +0 -1
  268. package/dist/scaffold/billing-providers.js +0 -249
  269. package/dist/scaffold/billing-schema.d.ts +0 -1
  270. package/dist/scaffold/billing-schema.js +0 -34
  271. package/dist/scaffold/billing-security.d.ts +0 -1
  272. package/dist/scaffold/billing-security.js +0 -46
  273. package/dist/scaffold/billing-server.d.ts +0 -1
  274. package/dist/scaffold/billing-server.js +0 -139
  275. package/dist/scaffold/billing-store.d.ts +0 -1
  276. package/dist/scaffold/billing-store.js +0 -72
  277. package/dist/scaffold/billing.d.ts +0 -2
  278. package/dist/scaffold/billing.js +0 -208
  279. package/dist/scaffold/expo-auth.d.ts +0 -3
  280. package/dist/scaffold/expo-auth.js +0 -203
  281. package/dist/scaffold/expo-billing.d.ts +0 -3
  282. package/dist/scaffold/expo-billing.js +0 -257
  283. package/dist/scaffold/integrations.d.ts +0 -2
  284. package/dist/scaffold/integrations.js +0 -11
  285. package/dist/scaffold/managed-email.d.ts +0 -3
  286. package/dist/scaffold/managed-email.js +0 -47
  287. package/dist/scaffold/password-reset.d.ts +0 -1
  288. package/dist/scaffold/password-reset.js +0 -99
  289. package/dist/scaffold/private-files.d.ts +0 -2
  290. package/dist/scaffold/private-files.js +0 -78
  291. package/dist/scaffold/web-billing.d.ts +0 -2
  292. package/dist/scaffold/web-billing.js +0 -48
  293. package/dist/service-deletion.d.ts +0 -29
  294. package/dist/service-deletion.js +0 -195
  295. package/dist/service-descriptor.d.ts +0 -10
  296. package/dist/service-descriptor.js +0 -71
  297. package/dist/service-model.d.ts +0 -49
  298. package/dist/service-model.js +0 -8
  299. package/dist/service-operations.d.ts +0 -29
  300. package/dist/service-operations.js +0 -48
  301. package/dist/service-readers.d.ts +0 -8
  302. package/dist/service-readers.js +0 -216
  303. package/dist/services-command.d.ts +0 -39
  304. package/dist/services-command.js +0 -96
  305. package/dist/ship.d.ts +0 -35
  306. package/dist/ship.js +0 -107
  307. package/docs/assets/anhedral-stack-light.png +0 -0
  308. package/docs/assets/anhedral-stack.png +0 -0
@@ -0,0 +1,32 @@
1
+ import { z } from 'zod';
2
+ import { betterAuth } from 'better-auth/minimal';
3
+ import { drizzleAdapter } from '@better-auth/drizzle-adapter';
4
+ import { platformAuthPlugins } from './auth-platform';
5
+ import { bearer } from 'better-auth/plugins/bearer';
6
+ import { createDatabase } from '@workspace/db';
7
+ import * as schema from '@workspace/db/schema';
8
+ import { authFeatures } from './auth-features';
9
+ import type { AppEnv } from './environment';
10
+
11
+ export const authConfiguration = z.object({
12
+ PUBLIC_APP_URL: z.url().regex(/^https?:\/\//),
13
+ BETTER_AUTH_SECRET: z.string().min(32),
14
+ });
15
+ export function createAuth(env: AppEnv['Bindings']) {
16
+ const configuration = authConfiguration.parse(env);
17
+ const origin = new URL(configuration.PUBLIC_APP_URL).origin;
18
+ return betterAuth({
19
+ secret: configuration.BETTER_AUTH_SECRET,
20
+ baseURL: origin,
21
+ basePath: '/api/auth',
22
+ database: drizzleAdapter(createDatabase(env.DB), { provider: 'sqlite', schema }),
23
+ emailAndPassword: { enabled: authFeatures.emailPassword },
24
+ trustedOrigins: [
25
+ origin,
26
+ ...(env.AUTH_TRUSTED_ORIGINS?.split(',')
27
+ .map((v) => v.trim())
28
+ .filter(Boolean) ?? []),
29
+ ],
30
+ plugins: [bearer(), ...platformAuthPlugins()],
31
+ });
32
+ }
@@ -0,0 +1,8 @@
1
+ import { z } from 'zod';
2
+ import type { AppEnv } from './environment';
3
+ const environment = z.enum(['sandbox', 'live']);
4
+ export function billingEnvironment(env: AppEnv['Bindings']) {
5
+ return environment.parse(env.BILLING_ENVIRONMENT || 'sandbox');
6
+ }
7
+ // The CLI never sets live mode or credentials. Operators choose the environment
8
+ // explicitly, configure matching provider scope and validate it before rollout.
@@ -0,0 +1,11 @@
1
+ import { sqliteTable, text, integer, primaryKey } from 'drizzle-orm/sqlite-core';
2
+ // Durable receipts deduplicate delivery; they are not proof of an entitlement.
3
+ export const billingReceipt = sqliteTable(
4
+ 'billing_receipt',
5
+ {
6
+ provider: text('provider').notNull(),
7
+ eventId: text('event_id').notNull(),
8
+ receivedAt: integer('received_at').notNull(),
9
+ },
10
+ (t) => [primaryKey({ columns: [t.provider, t.eventId] })],
11
+ );
@@ -0,0 +1,21 @@
1
+ use gpui::{App, Application, Context, Window, WindowOptions, div, prelude::*};
2
+
3
+ struct Desktop;
4
+ impl Render for Desktop {
5
+ fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
6
+ div()
7
+ .flex()
8
+ .flex_col()
9
+ .p_8()
10
+ .gap_4()
11
+ .child("Your native application")
12
+ .child("Configure an authenticated backend client for your product.")
13
+ }
14
+ }
15
+ fn main() {
16
+ Application::new().run(|cx: &mut App| {
17
+ cx.open_window(WindowOptions::default(), |_, cx| cx.new(|_| Desktop))
18
+ .expect("Open application window");
19
+ cx.activate(true);
20
+ });
21
+ }
@@ -0,0 +1,32 @@
1
+ import { type MiddlewareHandler } from 'hono';
2
+ import { z } from 'zod';
3
+ import { billingProviders } from './billing-providers';
4
+ import type { AppEnv } from './environment';
5
+ const policy = z.enum(['stripe', 'revenuecat', 'either']);
6
+ function selectedProviders(env: AppEnv['Bindings']) {
7
+ const selected = policy.parse(env.BILLING_PROVIDER);
8
+ return selected === 'either' ? Object.keys(billingProviders) : [selected];
9
+ }
10
+ async function providerEntitlement(name: string, env: AppEnv['Bindings'], subject: string) {
11
+ const resolve = billingProviders[name];
12
+ if (!resolve) throw Error('Selected billing provider is not installed');
13
+ return resolve(env, subject);
14
+ }
15
+ async function entitled(env: AppEnv['Bindings'], subject: string) {
16
+ const checks = await Promise.all(
17
+ selectedProviders(env).map((name) => providerEntitlement(name, env, subject).catch(() => null)),
18
+ );
19
+ if (checks.includes(true)) return true;
20
+ if (checks.includes(null)) throw Error('Billing provider unavailable');
21
+ return false;
22
+ }
23
+ export const requireEntitlement: MiddlewareHandler<AppEnv> = async (c, next) => {
24
+ if (!c.get('userId')) return c.json({ error: 'Unauthorized' }, 401);
25
+ try {
26
+ if (!(await entitled(c.env, c.get('userId'))))
27
+ return c.json({ error: 'Subscription required' }, 403);
28
+ } catch {
29
+ return c.json({ error: 'Billing needs configuration or is temporarily unavailable' }, 503);
30
+ }
31
+ await next();
32
+ };
@@ -0,0 +1,8 @@
1
+ import { Hono } from 'hono';
2
+ import { requireSession } from '../security';
3
+ import { requireEntitlement } from '../entitlement-guard';
4
+ import type { AppEnv } from '../environment';
5
+ export const entitlementRoutes = new Hono<AppEnv>();
6
+ entitlementRoutes.get('/billing/access', requireSession, requireEntitlement, (c) =>
7
+ c.json({ allowed: true }),
8
+ );
@@ -0,0 +1,12 @@
1
+ import { sqliteTable, text, integer, index } from 'drizzle-orm/sqlite-core';
2
+ export const applicationEvent = sqliteTable(
3
+ 'application_event',
4
+ {
5
+ id: text('id').primaryKey(),
6
+ userId: text('user_id').notNull(),
7
+ topic: text('topic').notNull(),
8
+ data: text('data').notNull(),
9
+ createdAt: integer('created_at').notNull(),
10
+ },
11
+ (t) => [index('application_event_user_time').on(t.userId, t.createdAt)],
12
+ );
@@ -0,0 +1,59 @@
1
+ import { Hono } from 'hono';
2
+ import { streamSSE } from 'hono/streaming';
3
+ import { z } from 'zod';
4
+ import { requireSession } from '../security';
5
+ import type { AppEnv } from '../environment';
6
+ export const eventRoutes = new Hono<AppEnv>();
7
+ const input = z.object({
8
+ topic: z.string().regex(/^[a-zA-Z0-9._-]{1,80}$/),
9
+ data: z.unknown().optional(),
10
+ });
11
+ function eventCursor(header: string | undefined) {
12
+ if (!header) return { since: Date.now(), afterId: '' };
13
+ const match = /^(\d+):([a-f0-9-]{36})$/.exec(header);
14
+ if (!match) return null;
15
+ const since = Number(match[1]);
16
+ if (!Number.isSafeInteger(since)) return null;
17
+ return { since, afterId: match[2] };
18
+ }
19
+ eventRoutes.use('/events', requireSession);
20
+ eventRoutes.post('/events', async (c) => {
21
+ const body = input.safeParse(await c.req.json().catch(() => null));
22
+ if (!body.success) return c.json({ error: 'Invalid event' }, 400);
23
+ const data = JSON.stringify(body.data.data ?? null);
24
+ if (new TextEncoder().encode(data).byteLength > 8192)
25
+ return c.json({ error: 'Event too large' }, 413);
26
+ const id = crypto.randomUUID();
27
+ // Allocate a strictly increasing owner cursor atomically, including equal-ms writes.
28
+ await c.env.DB.prepare(
29
+ 'INSERT INTO application_event(id,user_id,topic,data,created_at) SELECT ?,?,?,?,MAX(?,COALESCE((SELECT MAX(created_at)+1 FROM application_event WHERE user_id=?),0))',
30
+ )
31
+ .bind(id, c.get('userId'), body.data.topic, data, Date.now(), c.get('userId'))
32
+ .run();
33
+ return c.json({ id }, 201);
34
+ });
35
+ eventRoutes.get('/events', (c) => {
36
+ const userId = c.get('userId');
37
+ const cursor = eventCursor(c.req.header('last-event-id'));
38
+ if (!cursor) return c.json({ error: 'Invalid event cursor' }, 400);
39
+ return streamSSE(c, async (stream) => {
40
+ for (let tick = 0; tick < 30 && !stream.aborted; tick++) {
41
+ const rows = await c.env.DB.prepare(
42
+ 'SELECT id,topic,data,created_at FROM application_event WHERE user_id = ? AND (created_at > ? OR (created_at = ? AND id > ?)) ORDER BY created_at,id LIMIT 100',
43
+ )
44
+ .bind(userId, cursor.since, cursor.since, cursor.afterId)
45
+ .all<{ id: string; topic: string; data: string; created_at: number }>();
46
+ for (const row of rows.results) {
47
+ await stream.writeSSE({
48
+ id: row.created_at + ':' + row.id,
49
+ event: row.topic,
50
+ data: row.data,
51
+ });
52
+ cursor.since = row.created_at;
53
+ cursor.afterId = row.id;
54
+ }
55
+ await stream.writeSSE({ event: 'heartbeat', data: '{}' });
56
+ await stream.sleep(1000);
57
+ }
58
+ });
59
+ });
@@ -0,0 +1,25 @@
1
+ import { createAuthClient } from 'better-auth/react';
2
+ import { expoClient } from '@better-auth/expo/client';
3
+ import * as SecureStore from 'expo-secure-store';
4
+ const configured = process.env.EXPO_PUBLIC_API_URL;
5
+ const baseURL = configured || 'http://127.0.0.1:8787';
6
+ if (configured && !__DEV__ && !configured.startsWith('https://'))
7
+ throw Error('Production API connections require HTTPS');
8
+ export const authClient = createAuthClient({
9
+ baseURL,
10
+ plugins: [expoClient({ scheme: __SCHEME__, storagePrefix: __SCHEME__, storage: SecureStore })],
11
+ });
12
+ export async function apiRequest(route: string, init: RequestInit = {}) {
13
+ if (!/^\/[a-zA-Z0-9/_?=&%.-]*$/.test(route)) throw Error('Choose an application API path');
14
+ const headers = new Headers(init.headers);
15
+ headers.delete('authorization');
16
+ headers.delete('origin');
17
+ const cookie = await authClient.getCookie();
18
+ if (cookie) headers.set('cookie', cookie);
19
+ headers.set('expo-origin', __SCHEME__ + '://');
20
+ return fetch(baseURL.replace(/\/$/, '') + '/api' + route, {
21
+ ...init,
22
+ headers,
23
+ redirect: 'error',
24
+ });
25
+ }
@@ -0,0 +1,63 @@
1
+ import { useState } from 'react';
2
+ import { View, Text } from 'react-native';
3
+ import { type PurchasesPackage } from 'react-native-purchases';
4
+ import {
5
+ connectPurchases,
6
+ purchase,
7
+ restorePurchases,
8
+ manageSubscriptions,
9
+ } from '../lib/purchases';
10
+ import { ActionButton } from './action-button';
11
+ export function BillingControls() {
12
+ const [packages, setPackages] = useState<PurchasesPackage[]>([]);
13
+ const [message, setMessage] = useState('');
14
+ const [busy, setBusy] = useState(false);
15
+ async function action(work: () => Promise<unknown>) {
16
+ setBusy(true);
17
+ try {
18
+ await work();
19
+ setMessage('Subscription updated.');
20
+ } catch {
21
+ setMessage('Purchase service is unavailable or the action was cancelled.');
22
+ } finally {
23
+ setBusy(false);
24
+ }
25
+ }
26
+ return (
27
+ <View style={{ padding: 16, gap: 8 }}>
28
+ <ActionButton
29
+ label="View subscriptions"
30
+ disabled={busy}
31
+ onPress={() =>
32
+ void action(async () => {
33
+ const offerings = await connectPurchases();
34
+ setPackages(
35
+ (offerings.current?.availablePackages ?? []).filter(
36
+ (value) => value.product.subscriptionPeriod !== null,
37
+ ),
38
+ );
39
+ })
40
+ }
41
+ />
42
+ {packages.map((value) => (
43
+ <ActionButton
44
+ key={value.identifier}
45
+ label={value.product.title + ' ' + value.product.priceString}
46
+ disabled={busy}
47
+ onPress={() => void action(() => purchase(value))}
48
+ />
49
+ ))}
50
+ <ActionButton
51
+ label="Restore purchases"
52
+ disabled={busy}
53
+ onPress={() => void action(restorePurchases)}
54
+ />
55
+ <ActionButton
56
+ label="Manage subscriptions"
57
+ disabled={busy}
58
+ onPress={() => void action(manageSubscriptions)}
59
+ />
60
+ <Text accessibilityLiveRegion="polite">{message}</Text>
61
+ </View>
62
+ );
63
+ }
@@ -0,0 +1,83 @@
1
+ import { useState, type ReactNode } from 'react';
2
+ import { View, Text, TextInput } from 'react-native';
3
+ import { authClient, apiRequest } from '../lib/auth-client';
4
+ import { ActionButton } from './action-button';
5
+
6
+ export function SessionControls({
7
+ children,
8
+ onSignOut,
9
+ }: {
10
+ children?: ReactNode;
11
+ onSignOut?: () => Promise<void>;
12
+ }) {
13
+ if (!process.env.EXPO_PUBLIC_API_URL) return <Text>Connection setup is required.</Text>;
14
+ return <ConfiguredSessionControls onSignOut={onSignOut}>{children}</ConfiguredSessionControls>;
15
+ }
16
+ function ConfiguredSessionControls({
17
+ children,
18
+ onSignOut,
19
+ }: {
20
+ children?: ReactNode;
21
+ onSignOut?: () => Promise<void>;
22
+ }) {
23
+ const { data: session } = authClient.useSession();
24
+ const [email, setEmail] = useState('');
25
+ const [password, setPassword] = useState('');
26
+ const [message, setMessage] = useState('');
27
+ const [busy, setBusy] = useState(false);
28
+ async function verifySignIn() {
29
+ const result = await authClient.signIn.email({ email, password });
30
+ if (result.error) throw Error('Sign in failed');
31
+ const response = await apiRequest('/session');
32
+ if (!response.ok) throw Error('Session unavailable');
33
+ }
34
+ async function signIn() {
35
+ setBusy(true);
36
+ try {
37
+ await verifySignIn();
38
+ setMessage('Signed in');
39
+ } catch {
40
+ setMessage('Unable to sign in');
41
+ } finally {
42
+ setBusy(false);
43
+ }
44
+ }
45
+
46
+ async function signOut() {
47
+ try {
48
+ await onSignOut?.();
49
+ } catch {
50
+ setMessage('The purchase connection needs attention.');
51
+ } finally {
52
+ await authClient.signOut();
53
+ }
54
+ }
55
+ if (session)
56
+ return (
57
+ <View>
58
+ <Text>{session.user.email}</Text>
59
+ {children}
60
+ <ActionButton label="Sign out" onPress={() => void signOut()} />
61
+ </View>
62
+ );
63
+ return (
64
+ <View style={{ padding: 16, gap: 8 }}>
65
+ <Text>Sign in</Text>
66
+ <TextInput
67
+ accessibilityLabel="Email"
68
+ autoCapitalize="none"
69
+ keyboardType="email-address"
70
+ value={email}
71
+ onChangeText={setEmail}
72
+ />
73
+ <TextInput
74
+ accessibilityLabel="Password"
75
+ secureTextEntry
76
+ value={password}
77
+ onChangeText={setPassword}
78
+ />
79
+ <ActionButton label="Sign in" disabled={busy} onPress={() => void signIn()} />
80
+ <Text accessibilityLiveRegion="polite">{message}</Text>
81
+ </View>
82
+ );
83
+ }
@@ -0,0 +1,108 @@
1
+ import { TextClassContext } from '@/components/ui/text';
2
+ import { cn } from '@/lib/utils';
3
+ import { cva, type VariantProps } from 'class-variance-authority';
4
+ import { Platform, Pressable } from 'react-native';
5
+
6
+ const buttonVariants = cva(
7
+ cn(
8
+ 'group shrink-0 flex-row items-center justify-center gap-2 rounded-md shadow-none',
9
+ Platform.select({
10
+ web: "focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive whitespace-nowrap outline-none transition-all focus-visible:ring-[3px] disabled:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",
11
+ }),
12
+ ),
13
+ {
14
+ variants: {
15
+ variant: {
16
+ default: cn(
17
+ 'bg-primary active:bg-primary/90 shadow-sm shadow-black/5',
18
+ Platform.select({ web: 'hover:bg-primary/90' }),
19
+ ),
20
+ destructive: cn(
21
+ 'bg-destructive active:bg-destructive/90 dark:bg-destructive/60 shadow-sm shadow-black/5',
22
+ Platform.select({
23
+ web: 'hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40',
24
+ }),
25
+ ),
26
+ outline: cn(
27
+ 'border-border bg-background active:bg-accent dark:bg-input/30 dark:border-input dark:active:bg-input/50 border shadow-sm shadow-black/5',
28
+ Platform.select({
29
+ web: 'hover:bg-accent dark:hover:bg-input/50',
30
+ }),
31
+ ),
32
+ secondary: cn(
33
+ 'bg-secondary active:bg-secondary/80 shadow-sm shadow-black/5',
34
+ Platform.select({ web: 'hover:bg-secondary/80' }),
35
+ ),
36
+ ghost: cn(
37
+ 'active:bg-accent dark:active:bg-accent/50',
38
+ Platform.select({ web: 'hover:bg-accent dark:hover:bg-accent/50' }),
39
+ ),
40
+ link: '',
41
+ },
42
+ size: {
43
+ default: cn('h-10 px-4 py-2 sm:h-9', Platform.select({ web: 'has-[>svg]:px-3' })),
44
+ sm: cn('h-9 gap-1.5 rounded-md px-3 sm:h-8', Platform.select({ web: 'has-[>svg]:px-2.5' })),
45
+ lg: cn('h-11 rounded-md px-6 sm:h-10', Platform.select({ web: 'has-[>svg]:px-4' })),
46
+ icon: 'h-10 w-10 sm:h-9 sm:w-9',
47
+ },
48
+ },
49
+ defaultVariants: {
50
+ variant: 'default',
51
+ size: 'default',
52
+ },
53
+ },
54
+ );
55
+
56
+ const buttonTextVariants = cva(
57
+ cn(
58
+ 'text-foreground text-sm font-medium',
59
+ Platform.select({ web: 'pointer-events-none transition-colors' }),
60
+ ),
61
+ {
62
+ variants: {
63
+ variant: {
64
+ default: 'text-primary-foreground',
65
+ destructive: 'text-white',
66
+ outline: cn(
67
+ 'group-active:text-accent-foreground',
68
+ Platform.select({ web: 'group-hover:text-accent-foreground' }),
69
+ ),
70
+ secondary: 'text-secondary-foreground',
71
+ ghost: 'group-active:text-accent-foreground',
72
+ link: cn(
73
+ 'text-primary group-active:underline',
74
+ Platform.select({ web: 'underline-offset-4 hover:underline group-hover:underline' }),
75
+ ),
76
+ },
77
+ size: {
78
+ default: '',
79
+ sm: '',
80
+ lg: '',
81
+ icon: '',
82
+ },
83
+ },
84
+ defaultVariants: {
85
+ variant: 'default',
86
+ size: 'default',
87
+ },
88
+ },
89
+ );
90
+
91
+ type ButtonProps = React.ComponentProps<typeof Pressable> &
92
+ React.RefAttributes<typeof Pressable> &
93
+ VariantProps<typeof buttonVariants>;
94
+
95
+ function Button({ className, variant, size, ...props }: ButtonProps) {
96
+ return (
97
+ <TextClassContext.Provider value={buttonTextVariants({ variant, size })}>
98
+ <Pressable
99
+ className={cn(props.disabled && 'opacity-50', buttonVariants({ variant, size }), className)}
100
+ role="button"
101
+ {...props}
102
+ />
103
+ </TextClassContext.Provider>
104
+ );
105
+ }
106
+
107
+ export { Button, buttonTextVariants, buttonVariants };
108
+ export type { ButtonProps };
@@ -0,0 +1,4 @@
1
+ @import '../../packages/styling/globals.css';
2
+ @tailwind base;
3
+ @tailwind components;
4
+ @tailwind utilities;
@@ -0,0 +1,5 @@
1
+ import { clsx, type ClassValue } from 'clsx';
2
+ import { twMerge } from 'tailwind-merge';
3
+ export function cn(...inputs: ClassValue[]) {
4
+ return twMerge(clsx(inputs));
5
+ }
@@ -0,0 +1,6 @@
1
+ const { getDefaultConfig } = require('expo/metro-config');
2
+ const { withNativeWind } = require('nativewind/metro');
3
+ module.exports = withNativeWind(getDefaultConfig(__dirname), {
4
+ input: './global.css',
5
+ inlineRem: 16,
6
+ });
@@ -0,0 +1 @@
1
+ /// <reference types="nativewind/types" />
@@ -0,0 +1,73 @@
1
+ const { hairlineWidth } = require('nativewind/theme');
2
+
3
+ /** @type {import('tailwindcss').Config} */
4
+ module.exports = {
5
+ darkMode: 'class',
6
+ content: ['./app/**/*.{ts,tsx}', './components/**/*.{ts,tsx}'],
7
+ presets: [require('nativewind/preset')],
8
+ theme: {
9
+ extend: {
10
+ colors: {
11
+ border: 'hsl(var(--border))',
12
+ input: 'hsl(var(--input))',
13
+ ring: 'hsl(var(--ring))',
14
+ background: 'hsl(var(--background))',
15
+ foreground: 'hsl(var(--foreground))',
16
+ primary: {
17
+ DEFAULT: 'hsl(var(--primary))',
18
+ foreground: 'hsl(var(--primary-foreground))',
19
+ },
20
+ secondary: {
21
+ DEFAULT: 'hsl(var(--secondary))',
22
+ foreground: 'hsl(var(--secondary-foreground))',
23
+ },
24
+ destructive: {
25
+ DEFAULT: 'hsl(var(--destructive))',
26
+ foreground: 'hsl(var(--destructive-foreground))',
27
+ },
28
+ muted: {
29
+ DEFAULT: 'hsl(var(--muted))',
30
+ foreground: 'hsl(var(--muted-foreground))',
31
+ },
32
+ accent: {
33
+ DEFAULT: 'hsl(var(--accent))',
34
+ foreground: 'hsl(var(--accent-foreground))',
35
+ },
36
+ popover: {
37
+ DEFAULT: 'hsl(var(--popover))',
38
+ foreground: 'hsl(var(--popover-foreground))',
39
+ },
40
+ card: {
41
+ DEFAULT: 'hsl(var(--card))',
42
+ foreground: 'hsl(var(--card-foreground))',
43
+ },
44
+ },
45
+ borderRadius: {
46
+ lg: 'var(--radius)',
47
+ md: 'calc(var(--radius) - 2px)',
48
+ sm: 'calc(var(--radius) - 4px)',
49
+ },
50
+ borderWidth: {
51
+ hairline: hairlineWidth(),
52
+ },
53
+ keyframes: {
54
+ 'accordion-down': {
55
+ from: { height: '0' },
56
+ to: { height: 'var(--radix-accordion-content-height)' },
57
+ },
58
+ 'accordion-up': {
59
+ from: { height: 'var(--radix-accordion-content-height)' },
60
+ to: { height: '0' },
61
+ },
62
+ },
63
+ animation: {
64
+ 'accordion-down': 'accordion-down 0.2s ease-out',
65
+ 'accordion-up': 'accordion-up 0.2s ease-out',
66
+ },
67
+ },
68
+ },
69
+ future: {
70
+ hoverOnlyWhenSupported: true,
71
+ },
72
+ plugins: [require('tailwindcss-animate')],
73
+ };
@@ -0,0 +1,89 @@
1
+ import { cn } from '@/lib/utils';
2
+ import { Slot } from '@rn-primitives/slot';
3
+ import { cva, type VariantProps } from 'class-variance-authority';
4
+ import * as React from 'react';
5
+ import { Platform, Text as RNText, type Role } from 'react-native';
6
+
7
+ const textVariants = cva(
8
+ cn(
9
+ 'text-foreground text-base',
10
+ Platform.select({
11
+ web: 'select-text',
12
+ }),
13
+ ),
14
+ {
15
+ variants: {
16
+ variant: {
17
+ default: '',
18
+ h1: cn(
19
+ 'text-center text-4xl font-extrabold tracking-tight',
20
+ Platform.select({ web: 'scroll-m-20 text-balance' }),
21
+ ),
22
+ h2: cn(
23
+ 'border-border border-b pb-2 text-3xl font-semibold tracking-tight',
24
+ Platform.select({ web: 'scroll-m-20 first:mt-0' }),
25
+ ),
26
+ h3: cn('text-2xl font-semibold tracking-tight', Platform.select({ web: 'scroll-m-20' })),
27
+ h4: cn('text-xl font-semibold tracking-tight', Platform.select({ web: 'scroll-m-20' })),
28
+ p: 'mt-3 leading-7 sm:mt-6',
29
+ blockquote: 'mt-4 border-l-2 pl-3 italic sm:mt-6 sm:pl-6',
30
+ code: cn(
31
+ 'bg-muted relative rounded px-[0.3rem] py-[0.2rem] font-mono text-sm font-semibold',
32
+ ),
33
+ lead: 'text-muted-foreground text-xl',
34
+ large: 'text-lg font-semibold',
35
+ small: 'text-sm font-medium leading-none',
36
+ muted: 'text-muted-foreground text-sm',
37
+ },
38
+ },
39
+ defaultVariants: {
40
+ variant: 'default',
41
+ },
42
+ },
43
+ );
44
+
45
+ type TextVariantProps = VariantProps<typeof textVariants>;
46
+
47
+ type TextVariant = NonNullable<TextVariantProps['variant']>;
48
+
49
+ const ROLE: Partial<Record<TextVariant, Role>> = {
50
+ h1: 'heading',
51
+ h2: 'heading',
52
+ h3: 'heading',
53
+ h4: 'heading',
54
+ blockquote: Platform.select({ web: 'blockquote' as Role }),
55
+ code: Platform.select({ web: 'code' as Role }),
56
+ };
57
+
58
+ const ARIA_LEVEL: Partial<Record<TextVariant, string>> = {
59
+ h1: '1',
60
+ h2: '2',
61
+ h3: '3',
62
+ h4: '4',
63
+ };
64
+
65
+ const TextClassContext = React.createContext<string | undefined>(undefined);
66
+
67
+ function Text({
68
+ className,
69
+ asChild = false,
70
+ variant = 'default',
71
+ ...props
72
+ }: React.ComponentProps<typeof RNText> &
73
+ React.RefAttributes<typeof RNText> &
74
+ TextVariantProps & {
75
+ asChild?: boolean;
76
+ }) {
77
+ const textClass = React.useContext(TextClassContext);
78
+ const Component = asChild ? Slot : RNText;
79
+ return (
80
+ <Component
81
+ className={cn(textVariants({ variant }), textClass, className)}
82
+ role={variant ? ROLE[variant] : undefined}
83
+ aria-level={variant ? ARIA_LEVEL[variant] : undefined}
84
+ {...props}
85
+ />
86
+ );
87
+ }
88
+
89
+ export { Text, TextClassContext };