anhedral 0.15.0 → 0.17.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 (246) hide show
  1. package/README.md +82 -34
  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 +0 -11
  39. package/assets/ui/catalog.json +891 -0
  40. package/assets/ui/extensions/registry.json +6 -0
  41. package/dist/bin.js +7 -12
  42. package/dist/capabilities.d.ts +4 -33
  43. package/dist/capabilities.js +2 -66
  44. package/dist/capability-catalog.d.ts +83 -0
  45. package/dist/capability-catalog.js +121 -0
  46. package/dist/capability-command.d.ts +3 -0
  47. package/dist/capability-command.js +188 -0
  48. package/dist/capability-editor.d.ts +17 -0
  49. package/dist/capability-editor.js +97 -0
  50. package/dist/capability-recipes.d.ts +4 -0
  51. package/dist/capability-recipes.js +520 -0
  52. package/dist/capability-references.d.ts +4 -0
  53. package/dist/capability-references.js +7 -0
  54. package/dist/cli-commands.d.ts +1 -2
  55. package/dist/cli-commands.js +10 -104
  56. package/dist/cli-output.d.ts +1 -2
  57. package/dist/cli-output.js +6 -251
  58. package/dist/command-schema.js +39 -322
  59. package/dist/dependencies.d.ts +29 -9
  60. package/dist/dependencies.js +57 -64
  61. package/dist/index.d.ts +1 -42
  62. package/dist/index.js +1 -27
  63. package/dist/platforms/web.d.ts +1 -1
  64. package/dist/platforms/web.js +27 -75
  65. package/dist/project-config.d.ts +2 -13
  66. package/dist/project-config.js +10 -82
  67. package/dist/registry/options.js +1 -5
  68. package/dist/registry/resolve.d.ts +1 -1
  69. package/dist/registry/resolve.js +4 -10
  70. package/dist/registry/usage.js +3 -9
  71. package/dist/scaffold/backend.js +0 -3
  72. package/dist/scaffold/database.js +2 -1
  73. package/dist/scaffold/documentation.js +56 -25
  74. package/dist/scaffold/stack-documentation.js +1 -1
  75. package/dist/scaffold/storage.d.ts +2 -0
  76. package/dist/scaffold/storage.js +21 -0
  77. package/dist/scaffold/workspace.js +21 -22
  78. package/dist/stack-registry.d.ts +2 -10
  79. package/dist/stack-registry.js +12 -98
  80. package/dist/standard.js +1 -11
  81. package/dist/ui-catalog.d.ts +26 -0
  82. package/dist/ui-catalog.js +31 -0
  83. package/dist/ui-command.d.ts +3 -0
  84. package/dist/ui-command.js +219 -0
  85. package/dist/ui-project.d.ts +22 -0
  86. package/dist/ui-project.js +110 -0
  87. package/dist/version.d.ts +1 -1
  88. package/dist/version.js +1 -1
  89. package/docs/anhedral-stack.md +12 -23
  90. package/docs/assets/anhedral-stack-light.png +0 -0
  91. package/docs/assets/anhedral-stack.png +0 -0
  92. package/docs/capabilities.md +110 -0
  93. package/docs/native-ui.md +47 -0
  94. package/docs/software-factory.md +35 -50
  95. package/docs/stack-standard.md +19 -70
  96. package/docs/ui.md +33 -0
  97. package/docs/verification.md +6 -876
  98. package/package.json +21 -16
  99. package/assets/ui/native/button.tsx +0 -85
  100. package/assets/ui/native/card.tsx +0 -33
  101. package/assets/ui/native/dialog.tsx +0 -75
  102. package/assets/ui/native/input.tsx +0 -27
  103. package/assets/ui/native/label.tsx +0 -4
  104. package/assets/ui/native/layout.tsx +0 -26
  105. package/assets/ui/native/text.tsx +0 -20
  106. package/assets/ui/native/theme-switcher.tsx +0 -22
  107. package/assets/ui/theme-storage.ts +0 -25
  108. package/assets/ui/theme.tsx +0 -66
  109. package/dist/access.d.ts +0 -10
  110. package/dist/access.js +0 -93
  111. package/dist/auth-schema-snapshot.d.ts +0 -346
  112. package/dist/auth-schema-snapshot.js +0 -347
  113. package/dist/auth-schema.d.ts +0 -1
  114. package/dist/auth-schema.js +0 -57
  115. package/dist/capability-contract.d.ts +0 -47
  116. package/dist/capability-contract.js +0 -129
  117. package/dist/catalog-model.d.ts +0 -24
  118. package/dist/catalog-model.js +0 -1
  119. package/dist/catalog-registration.d.ts +0 -16
  120. package/dist/catalog-registration.js +0 -22
  121. package/dist/catalog-snapshot.d.ts +0 -5
  122. package/dist/catalog-snapshot.js +0 -97
  123. package/dist/cli-delivery.d.ts +0 -3
  124. package/dist/cli-delivery.js +0 -112
  125. package/dist/cloudflare.d.ts +0 -25
  126. package/dist/cloudflare.js +0 -226
  127. package/dist/delivery-evidence.d.ts +0 -62
  128. package/dist/delivery-evidence.js +0 -157
  129. package/dist/delivery.d.ts +0 -82
  130. package/dist/delivery.js +0 -489
  131. package/dist/inspector-model.d.ts +0 -123
  132. package/dist/inspector-model.js +0 -1
  133. package/dist/integration-service-readers.d.ts +0 -12
  134. package/dist/integration-service-readers.js +0 -92
  135. package/dist/lifecycle-model.d.ts +0 -15
  136. package/dist/lifecycle-model.js +0 -20
  137. package/dist/lifecycle.d.ts +0 -11
  138. package/dist/lifecycle.js +0 -91
  139. package/dist/management.d.ts +0 -3
  140. package/dist/management.js +0 -47
  141. package/dist/mobile-delivery.d.ts +0 -77
  142. package/dist/mobile-delivery.js +0 -370
  143. package/dist/platforms/mobile.d.ts +0 -2
  144. package/dist/platforms/mobile.js +0 -156
  145. package/dist/project-catalog.d.ts +0 -41
  146. package/dist/project-catalog.js +0 -288
  147. package/dist/project-inspector.d.ts +0 -4
  148. package/dist/project-inspector.js +0 -671
  149. package/dist/project-lifecycle.d.ts +0 -25
  150. package/dist/project-lifecycle.js +0 -57
  151. package/dist/project-state.d.ts +0 -47
  152. package/dist/project-state.js +0 -480
  153. package/dist/provider-auth.d.ts +0 -41
  154. package/dist/provider-auth.js +0 -180
  155. package/dist/provider-readiness.d.ts +0 -30
  156. package/dist/provider-readiness.js +0 -85
  157. package/dist/providers/adapters.d.ts +0 -17
  158. package/dist/providers/adapters.js +0 -103
  159. package/dist/providers/api.d.ts +0 -29
  160. package/dist/providers/api.js +0 -253
  161. package/dist/providers/config.d.ts +0 -15
  162. package/dist/providers/config.js +0 -136
  163. package/dist/providers/definitions.d.ts +0 -115
  164. package/dist/providers/definitions.js +0 -42
  165. package/dist/providers/provision.d.ts +0 -24
  166. package/dist/providers/provision.js +0 -76
  167. package/dist/providers/receipts.d.ts +0 -20
  168. package/dist/providers/receipts.js +0 -56
  169. package/dist/providers/recovery-verification.d.ts +0 -7
  170. package/dist/providers/recovery-verification.js +0 -52
  171. package/dist/providers/recovery.d.ts +0 -30
  172. package/dist/providers/recovery.js +0 -34
  173. package/dist/providers/runtime.d.ts +0 -10
  174. package/dist/providers/runtime.js +0 -234
  175. package/dist/providers/schema.d.ts +0 -28
  176. package/dist/providers/schema.js +0 -49
  177. package/dist/providers/state.d.ts +0 -55
  178. package/dist/providers/state.js +0 -283
  179. package/dist/provision.d.ts +0 -47
  180. package/dist/provision.js +0 -208
  181. package/dist/r2-service-data.d.ts +0 -2
  182. package/dist/r2-service-data.js +0 -136
  183. package/dist/readiness.d.ts +0 -23
  184. package/dist/readiness.js +0 -117
  185. package/dist/registry/add.d.ts +0 -24
  186. package/dist/registry/add.js +0 -210
  187. package/dist/registry/bootstrap.d.ts +0 -3
  188. package/dist/registry/bootstrap.js +0 -5
  189. package/dist/registry/commands.d.ts +0 -3
  190. package/dist/registry/commands.js +0 -83
  191. package/dist/registry/preview.d.ts +0 -11
  192. package/dist/registry/preview.js +0 -91
  193. package/dist/registry/receipt.d.ts +0 -3
  194. package/dist/registry/receipt.js +0 -68
  195. package/dist/repository.d.ts +0 -24
  196. package/dist/repository.js +0 -96
  197. package/dist/scaffold/auth.d.ts +0 -2
  198. package/dist/scaffold/auth.js +0 -76
  199. package/dist/scaffold/billing-config.d.ts +0 -1
  200. package/dist/scaffold/billing-config.js +0 -73
  201. package/dist/scaffold/billing-contracts.d.ts +0 -2
  202. package/dist/scaffold/billing-contracts.js +0 -48
  203. package/dist/scaffold/billing-providers.d.ts +0 -1
  204. package/dist/scaffold/billing-providers.js +0 -249
  205. package/dist/scaffold/billing-schema.d.ts +0 -1
  206. package/dist/scaffold/billing-schema.js +0 -34
  207. package/dist/scaffold/billing-security.d.ts +0 -1
  208. package/dist/scaffold/billing-security.js +0 -46
  209. package/dist/scaffold/billing-server.d.ts +0 -1
  210. package/dist/scaffold/billing-server.js +0 -139
  211. package/dist/scaffold/billing-store.d.ts +0 -1
  212. package/dist/scaffold/billing-store.js +0 -72
  213. package/dist/scaffold/billing.d.ts +0 -2
  214. package/dist/scaffold/billing.js +0 -208
  215. package/dist/scaffold/expo-auth.d.ts +0 -3
  216. package/dist/scaffold/expo-auth.js +0 -203
  217. package/dist/scaffold/expo-billing.d.ts +0 -3
  218. package/dist/scaffold/expo-billing.js +0 -257
  219. package/dist/scaffold/expo-runtime.d.ts +0 -3
  220. package/dist/scaffold/expo-runtime.js +0 -43
  221. package/dist/scaffold/integrations.d.ts +0 -2
  222. package/dist/scaffold/integrations.js +0 -11
  223. package/dist/scaffold/managed-email.d.ts +0 -3
  224. package/dist/scaffold/managed-email.js +0 -47
  225. package/dist/scaffold/native-ui.d.ts +0 -2
  226. package/dist/scaffold/native-ui.js +0 -69
  227. package/dist/scaffold/password-reset.d.ts +0 -1
  228. package/dist/scaffold/password-reset.js +0 -99
  229. package/dist/scaffold/private-files.d.ts +0 -2
  230. package/dist/scaffold/private-files.js +0 -78
  231. package/dist/scaffold/web-billing.d.ts +0 -2
  232. package/dist/scaffold/web-billing.js +0 -48
  233. package/dist/service-deletion.d.ts +0 -29
  234. package/dist/service-deletion.js +0 -195
  235. package/dist/service-descriptor.d.ts +0 -10
  236. package/dist/service-descriptor.js +0 -71
  237. package/dist/service-model.d.ts +0 -49
  238. package/dist/service-model.js +0 -8
  239. package/dist/service-operations.d.ts +0 -29
  240. package/dist/service-operations.js +0 -48
  241. package/dist/service-readers.d.ts +0 -8
  242. package/dist/service-readers.js +0 -216
  243. package/dist/services-command.d.ts +0 -39
  244. package/dist/services-command.js +0 -96
  245. package/dist/ship.d.ts +0 -35
  246. package/dist/ship.js +0 -107
@@ -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 };
@@ -0,0 +1,65 @@
1
+ import Purchases, { type PurchasesPackage } from 'react-native-purchases';
2
+ import { Platform } from 'react-native';
3
+ import { authClient } from './auth-client';
4
+ let initialized = false;
5
+ let pending: Promise<unknown> = Promise.resolve();
6
+ function serial<T>(work: () => Promise<T>) {
7
+ const result = pending.then(work, work);
8
+ pending = result.then(
9
+ () => undefined,
10
+ () => undefined,
11
+ );
12
+ return result;
13
+ }
14
+ async function subject() {
15
+ const session = await authClient.getSession();
16
+ if (!session.data) throw Error('Sign in before using purchases');
17
+ return session.data.user.id;
18
+ }
19
+ function publicKey() {
20
+ return Platform.OS === 'ios'
21
+ ? process.env.EXPO_PUBLIC_REVENUECAT_IOS_KEY
22
+ : process.env.EXPO_PUBLIC_REVENUECAT_ANDROID_KEY;
23
+ }
24
+ function requiredKey() {
25
+ const value = publicKey();
26
+ if (!value) throw Error('Configure the platform public SDK key');
27
+ return value;
28
+ }
29
+ async function connect() {
30
+ const appUserID = await subject();
31
+ const apiKey = requiredKey();
32
+ if (!initialized) {
33
+ Purchases.configure({ apiKey, appUserID });
34
+ initialized = true;
35
+ } else await Purchases.logIn(appUserID);
36
+ return Purchases.getOfferings();
37
+ }
38
+ export function connectPurchases() {
39
+ return serial(connect);
40
+ }
41
+ export function purchase(value: PurchasesPackage) {
42
+ return serial(async () => {
43
+ await connect();
44
+ return Purchases.purchasePackage(value);
45
+ });
46
+ }
47
+ export function restorePurchases() {
48
+ return serial(async () => {
49
+ await connect();
50
+ return Purchases.restorePurchases();
51
+ });
52
+ }
53
+ export function manageSubscriptions() {
54
+ return serial(async () => {
55
+ await connect();
56
+ return Purchases.showManageSubscriptions();
57
+ });
58
+ }
59
+ export function disconnectPurchases() {
60
+ return serial(async () => {
61
+ if (initialized) await Purchases.logOut();
62
+ });
63
+ }
64
+ // SDK identity transitions are serialized. Callbacks update presentation only;
65
+ // Hono's canonical provider reconciliation owns all application access decisions.
@@ -0,0 +1,88 @@
1
+ import { Hono } from 'hono';
2
+ import { z } from 'zod';
3
+ import { timingSafeEqual } from 'node:crypto';
4
+ import { requireSession } from '../security';
5
+ import { billingEnvironment } from '../billing-mode';
6
+ import type { AppEnv } from '../environment';
7
+ export const revenuecatRoutes = new Hono<AppEnv>();
8
+ const hookConfig = z.object({
9
+ REVENUECAT_WEBHOOK_AUTH: z.string().min(1),
10
+ REVENUECAT_APP_ID: z.string().min(1),
11
+ });
12
+ function authorized(actual: string | undefined, expected: string) {
13
+ const a = new TextEncoder().encode(actual);
14
+ const b = new TextEncoder().encode(expected);
15
+ if (a.byteLength !== b.byteLength) return false;
16
+ return timingSafeEqual(a, b);
17
+ }
18
+ revenuecatRoutes.post('/webhooks/revenuecat', async (c) => {
19
+ const config = hookConfig.safeParse(c.env);
20
+ if (!config.success) return c.json({ error: 'Webhook needs configuration' }, 503);
21
+ if (!authorized(c.req.header('authorization'), config.data.REVENUECAT_WEBHOOK_AUTH))
22
+ return c.json({ error: 'Unauthorized' }, 401);
23
+ const schema = z.object({
24
+ event: z.object({
25
+ id: z.string().min(1).max(512),
26
+ environment: z.literal({ sandbox: 'SANDBOX', live: 'PRODUCTION' }[billingEnvironment(c.env)]),
27
+ app_id: z.literal(config.data.REVENUECAT_APP_ID),
28
+ }),
29
+ });
30
+ const body = schema.safeParse(await c.req.json().catch(() => null));
31
+ if (!body.success) return c.json({ error: 'Invalid webhook or scope' }, 400);
32
+ await c.env.DB.prepare(
33
+ 'INSERT OR IGNORE INTO billing_receipt(provider,event_id,received_at) VALUES (?,?,?)',
34
+ )
35
+ .bind('revenuecat', body.data.event.id, Date.now())
36
+ .run();
37
+ return c.json({ received: true });
38
+ });
39
+ const statusConfig = z.object({
40
+ REVENUECAT_SECRET_KEY: z.string().min(1),
41
+ REVENUECAT_ENTITLEMENT: z.string().min(1),
42
+ });
43
+ const subscriberSchema = z.object({
44
+ subscriber: z.object({
45
+ entitlements: z.record(
46
+ z.string(),
47
+ z.object({ expires_date: z.string().nullable(), product_identifier: z.string() }),
48
+ ),
49
+ subscriptions: z.record(z.string(), z.object({ is_sandbox: z.boolean() })),
50
+ }),
51
+ });
52
+ type Subscriber = z.infer<typeof subscriberSchema>['subscriber'];
53
+ const current = (expires: string | null) => expires === null || Date.parse(expires) > Date.now();
54
+ function entitled(subscriber: Subscriber, key: string, sandbox: boolean) {
55
+ const item = subscriber.entitlements[key];
56
+ if (!item) return false;
57
+ const product = subscriber.subscriptions[item.product_identifier];
58
+ if (!product) return false;
59
+ return product.is_sandbox === sandbox && current(item.expires_date);
60
+ }
61
+ export async function revenuecatEntitled(env: AppEnv['Bindings'], userId: string) {
62
+ const config = statusConfig.parse(env);
63
+ const response = await fetch(
64
+ 'https://api.revenuecat.com/v1/subscribers/' + encodeURIComponent(userId),
65
+ {
66
+ headers: { Authorization: 'Bearer ' + config.REVENUECAT_SECRET_KEY },
67
+ signal: AbortSignal.timeout(10000),
68
+ },
69
+ );
70
+ if (!response.ok) throw Error('RevenueCat unavailable');
71
+ const data = subscriberSchema.parse(await response.json());
72
+ return entitled(
73
+ data.subscriber,
74
+ config.REVENUECAT_ENTITLEMENT,
75
+ billingEnvironment(env) === 'sandbox',
76
+ );
77
+ }
78
+ revenuecatRoutes.get('/billing/mobile-status', requireSession, async (c) => {
79
+ try {
80
+ return c.json({
81
+ entitled: await revenuecatEntitled(c.env, c.get('userId')),
82
+ provider: 'revenuecat',
83
+ environment: billingEnvironment(c.env),
84
+ });
85
+ } catch {
86
+ return c.json({ error: 'Billing needs configuration or is temporarily unavailable' }, 503);
87
+ }
88
+ });
@@ -0,0 +1,10 @@
1
+ import { sqliteTable, text, integer, index } from 'drizzle-orm/sqlite-core';
2
+ export const rtcSession = sqliteTable(
3
+ 'rtc_session',
4
+ {
5
+ id: text('id').primaryKey(),
6
+ userId: text('user_id').notNull(),
7
+ createdAt: integer('created_at').notNull(),
8
+ },
9
+ (t) => [index('rtc_session_user_time').on(t.userId, t.createdAt)],
10
+ );
@@ -0,0 +1,122 @@
1
+ import { Hono, type Context } from 'hono';
2
+ import { z } from 'zod';
3
+ import { requireSession } from '../security';
4
+ import type { AppEnv } from '../environment';
5
+ export const rtcRoutes = new Hono<AppEnv>();
6
+ const identifier = z.string().regex(/^[a-zA-Z0-9_-]{1,128}$/);
7
+ const configuration = z.object({ RTC_APP_ID: identifier, RTC_APP_SECRET: z.string().min(1) });
8
+ const description = z.object({
9
+ type: z.enum(['offer', 'answer']),
10
+ sdp: z.string().min(1).max(128000),
11
+ });
12
+ const track = z.discriminatedUnion('location', [
13
+ z.object({ location: z.literal('local'), mid: identifier.optional(), trackName: identifier }),
14
+ z.object({ location: z.literal('remote'), sessionId: identifier, trackName: identifier }),
15
+ ]);
16
+ const trackRequest = z.object({
17
+ sessionDescription: description.optional(),
18
+ tracks: z.array(track).min(1).max(10),
19
+ });
20
+ const closeRequest = z
21
+ .object({
22
+ force: z.boolean().default(false),
23
+ sessionDescription: description.optional(),
24
+ tracks: z
25
+ .array(z.object({ mid: identifier }))
26
+ .min(1)
27
+ .max(10),
28
+ })
29
+ .refine((value) => value.force || !!value.sessionDescription);
30
+ const renegotiateRequest = z.object({
31
+ sessionDescription: description.extend({ type: z.literal('answer') }),
32
+ });
33
+ async function provider(env: AppEnv['Bindings'], path: string, body?: unknown, method = 'POST') {
34
+ return fetch(
35
+ 'https://rtc.live.cloudflare.com/v1/apps/' + encodeURIComponent(env.RTC_APP_ID!) + path,
36
+ {
37
+ method,
38
+ headers: {
39
+ Authorization: 'Bearer ' + env.RTC_APP_SECRET,
40
+ 'Content-Type': 'application/json',
41
+ },
42
+ ...(body === undefined ? {} : { body: JSON.stringify(body) }),
43
+ signal: AbortSignal.timeout(10000),
44
+ },
45
+ );
46
+ }
47
+ async function owns(c: Context<AppEnv>, id: string) {
48
+ return !!(await c.env.DB.prepare('SELECT id FROM rtc_session WHERE id = ? AND user_id = ?')
49
+ .bind(id, c.get('userId'))
50
+ .first());
51
+ }
52
+ rtcRoutes.use('/rtc/*', requireSession);
53
+ rtcRoutes.use('/rtc/*', async (c, next) => {
54
+ if (!configuration.safeParse(c.env).success)
55
+ return c.json({ error: 'Configure Cloudflare Realtime SFU first' }, 503);
56
+ await next();
57
+ });
58
+ rtcRoutes.use('/rtc/session/:id/*', async (c, next) => {
59
+ const id = identifier.safeParse(c.req.param('id'));
60
+ if (!id.success) return c.json({ error: 'Invalid session' }, 400);
61
+ if (!(await owns(c, id.data))) return c.json({ error: 'Not found' }, 404);
62
+ await next();
63
+ });
64
+ async function allocate(c: Context<AppEnv>, reservation: string) {
65
+ return c.env.DB.prepare(
66
+ 'INSERT INTO rtc_session(id,user_id,created_at) SELECT ?,?,? WHERE (SELECT COUNT(*) FROM rtc_session WHERE user_id = ? AND created_at > ?) < 10',
67
+ )
68
+ .bind(reservation, c.get('userId'), Date.now(), c.get('userId'), Date.now() - 3600000)
69
+ .run();
70
+ }
71
+ async function createProviderSession(c: Context<AppEnv>) {
72
+ const response = await provider(c.env, '/sessions/new');
73
+ if (!response.ok) return null;
74
+ const body = (await response.json()) as { sessionId?: unknown };
75
+ const result = identifier.safeParse(body.sessionId);
76
+ return result.success ? result.data : null;
77
+ }
78
+ rtcRoutes.post('/rtc/session', async (c) => {
79
+ const reservation = crypto.randomUUID();
80
+ const quota = await allocate(c, reservation);
81
+ if (!quota.meta.changes) return c.json({ error: 'RTC session limit reached' }, 429);
82
+ // Uncertain provider failures retain the reservation for the bounded hour.
83
+ const sessionId = await createProviderSession(c);
84
+ if (!sessionId) return c.json({ error: 'RTC provider unavailable' }, 503);
85
+ await c.env.DB.prepare('UPDATE rtc_session SET id = ? WHERE id = ? AND user_id = ?')
86
+ .bind(sessionId, reservation, c.get('userId'))
87
+ .run();
88
+ return c.json({ sessionId }, 201);
89
+ });
90
+ async function operation(c: Context<AppEnv>, endpoint: string, body: unknown, method: string) {
91
+ const response = await provider(
92
+ c.env,
93
+ '/sessions/' + encodeURIComponent(c.req.param('id')!) + endpoint,
94
+ body,
95
+ method,
96
+ );
97
+ if (!response.ok) return c.json({ error: 'RTC operation rejected' }, 502);
98
+ return c.json(await response.json());
99
+ }
100
+ async function permitted(c: Context<AppEnv>, value: z.infer<typeof track>) {
101
+ if (value.location === 'local') return true;
102
+ // A multi-user product replaces this with reviewed room/membership rules.
103
+ return owns(c, value.sessionId);
104
+ }
105
+ rtcRoutes.post('/rtc/session/:id/tracks', async (c) => {
106
+ const body = trackRequest.safeParse(await c.req.json().catch(() => null));
107
+ if (!body.success) return c.json({ error: 'Invalid tracks' }, 400);
108
+ for (const value of body.data.tracks) {
109
+ if (!(await permitted(c, value))) return c.json({ error: 'Remote session forbidden' }, 403);
110
+ }
111
+ return operation(c, '/tracks/new', body.data, 'POST');
112
+ });
113
+ rtcRoutes.post('/rtc/session/:id/close', async (c) => {
114
+ const body = closeRequest.safeParse(await c.req.json().catch(() => null));
115
+ if (!body.success) return c.json({ error: 'Invalid close request' }, 400);
116
+ return operation(c, '/tracks/close', body.data, 'PUT');
117
+ });
118
+ rtcRoutes.post('/rtc/session/:id/renegotiate', async (c) => {
119
+ const body = renegotiateRequest.safeParse(await c.req.json().catch(() => null));
120
+ if (!body.success) return c.json({ error: 'Invalid SDP' }, 400);
121
+ return operation(c, '/renegotiate', body.data, 'PUT');
122
+ });