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,346 @@
1
+ {
2
+ "version": "6",
3
+ "dialect": "sqlite",
4
+ "id": "b0e40d2d-45e2-4317-9f1b-ec413de82c9f",
5
+ "prevId": "00000000-0000-0000-0000-000000000000",
6
+ "tables": {
7
+ "account": {
8
+ "name": "account",
9
+ "columns": {
10
+ "id": {
11
+ "name": "id",
12
+ "type": "text",
13
+ "primaryKey": true,
14
+ "notNull": true,
15
+ "autoincrement": false
16
+ },
17
+ "account_id": {
18
+ "name": "account_id",
19
+ "type": "text",
20
+ "primaryKey": false,
21
+ "notNull": true,
22
+ "autoincrement": false
23
+ },
24
+ "provider_id": {
25
+ "name": "provider_id",
26
+ "type": "text",
27
+ "primaryKey": false,
28
+ "notNull": true,
29
+ "autoincrement": false
30
+ },
31
+ "user_id": {
32
+ "name": "user_id",
33
+ "type": "text",
34
+ "primaryKey": false,
35
+ "notNull": true,
36
+ "autoincrement": false
37
+ },
38
+ "access_token": {
39
+ "name": "access_token",
40
+ "type": "text",
41
+ "primaryKey": false,
42
+ "notNull": false,
43
+ "autoincrement": false
44
+ },
45
+ "refresh_token": {
46
+ "name": "refresh_token",
47
+ "type": "text",
48
+ "primaryKey": false,
49
+ "notNull": false,
50
+ "autoincrement": false
51
+ },
52
+ "id_token": {
53
+ "name": "id_token",
54
+ "type": "text",
55
+ "primaryKey": false,
56
+ "notNull": false,
57
+ "autoincrement": false
58
+ },
59
+ "access_token_expires_at": {
60
+ "name": "access_token_expires_at",
61
+ "type": "integer",
62
+ "primaryKey": false,
63
+ "notNull": false,
64
+ "autoincrement": false
65
+ },
66
+ "refresh_token_expires_at": {
67
+ "name": "refresh_token_expires_at",
68
+ "type": "integer",
69
+ "primaryKey": false,
70
+ "notNull": false,
71
+ "autoincrement": false
72
+ },
73
+ "scope": {
74
+ "name": "scope",
75
+ "type": "text",
76
+ "primaryKey": false,
77
+ "notNull": false,
78
+ "autoincrement": false
79
+ },
80
+ "password": {
81
+ "name": "password",
82
+ "type": "text",
83
+ "primaryKey": false,
84
+ "notNull": false,
85
+ "autoincrement": false
86
+ },
87
+ "created_at": {
88
+ "name": "created_at",
89
+ "type": "integer",
90
+ "primaryKey": false,
91
+ "notNull": true,
92
+ "autoincrement": false
93
+ },
94
+ "updated_at": {
95
+ "name": "updated_at",
96
+ "type": "integer",
97
+ "primaryKey": false,
98
+ "notNull": true,
99
+ "autoincrement": false
100
+ }
101
+ },
102
+ "indexes": {
103
+ "account_user_id_idx": {
104
+ "name": "account_user_id_idx",
105
+ "columns": ["user_id"],
106
+ "isUnique": false
107
+ }
108
+ },
109
+ "foreignKeys": {
110
+ "account_user_id_user_id_fk": {
111
+ "name": "account_user_id_user_id_fk",
112
+ "tableFrom": "account",
113
+ "tableTo": "user",
114
+ "columnsFrom": ["user_id"],
115
+ "columnsTo": ["id"],
116
+ "onDelete": "cascade",
117
+ "onUpdate": "no action"
118
+ }
119
+ },
120
+ "compositePrimaryKeys": {},
121
+ "uniqueConstraints": {},
122
+ "checkConstraints": {}
123
+ },
124
+ "session": {
125
+ "name": "session",
126
+ "columns": {
127
+ "id": {
128
+ "name": "id",
129
+ "type": "text",
130
+ "primaryKey": true,
131
+ "notNull": true,
132
+ "autoincrement": false
133
+ },
134
+ "expires_at": {
135
+ "name": "expires_at",
136
+ "type": "integer",
137
+ "primaryKey": false,
138
+ "notNull": true,
139
+ "autoincrement": false
140
+ },
141
+ "token": {
142
+ "name": "token",
143
+ "type": "text",
144
+ "primaryKey": false,
145
+ "notNull": true,
146
+ "autoincrement": false
147
+ },
148
+ "created_at": {
149
+ "name": "created_at",
150
+ "type": "integer",
151
+ "primaryKey": false,
152
+ "notNull": true,
153
+ "autoincrement": false
154
+ },
155
+ "updated_at": {
156
+ "name": "updated_at",
157
+ "type": "integer",
158
+ "primaryKey": false,
159
+ "notNull": true,
160
+ "autoincrement": false
161
+ },
162
+ "ip_address": {
163
+ "name": "ip_address",
164
+ "type": "text",
165
+ "primaryKey": false,
166
+ "notNull": false,
167
+ "autoincrement": false
168
+ },
169
+ "user_agent": {
170
+ "name": "user_agent",
171
+ "type": "text",
172
+ "primaryKey": false,
173
+ "notNull": false,
174
+ "autoincrement": false
175
+ },
176
+ "user_id": {
177
+ "name": "user_id",
178
+ "type": "text",
179
+ "primaryKey": false,
180
+ "notNull": true,
181
+ "autoincrement": false
182
+ }
183
+ },
184
+ "indexes": {
185
+ "session_token_unique": {
186
+ "name": "session_token_unique",
187
+ "columns": ["token"],
188
+ "isUnique": true
189
+ },
190
+ "session_user_id_idx": {
191
+ "name": "session_user_id_idx",
192
+ "columns": ["user_id"],
193
+ "isUnique": false
194
+ }
195
+ },
196
+ "foreignKeys": {
197
+ "session_user_id_user_id_fk": {
198
+ "name": "session_user_id_user_id_fk",
199
+ "tableFrom": "session",
200
+ "tableTo": "user",
201
+ "columnsFrom": ["user_id"],
202
+ "columnsTo": ["id"],
203
+ "onDelete": "cascade",
204
+ "onUpdate": "no action"
205
+ }
206
+ },
207
+ "compositePrimaryKeys": {},
208
+ "uniqueConstraints": {},
209
+ "checkConstraints": {}
210
+ },
211
+ "user": {
212
+ "name": "user",
213
+ "columns": {
214
+ "id": {
215
+ "name": "id",
216
+ "type": "text",
217
+ "primaryKey": true,
218
+ "notNull": true,
219
+ "autoincrement": false
220
+ },
221
+ "name": {
222
+ "name": "name",
223
+ "type": "text",
224
+ "primaryKey": false,
225
+ "notNull": true,
226
+ "autoincrement": false
227
+ },
228
+ "email": {
229
+ "name": "email",
230
+ "type": "text",
231
+ "primaryKey": false,
232
+ "notNull": true,
233
+ "autoincrement": false
234
+ },
235
+ "email_verified": {
236
+ "name": "email_verified",
237
+ "type": "integer",
238
+ "primaryKey": false,
239
+ "notNull": true,
240
+ "autoincrement": false,
241
+ "default": false
242
+ },
243
+ "image": {
244
+ "name": "image",
245
+ "type": "text",
246
+ "primaryKey": false,
247
+ "notNull": false,
248
+ "autoincrement": false
249
+ },
250
+ "created_at": {
251
+ "name": "created_at",
252
+ "type": "integer",
253
+ "primaryKey": false,
254
+ "notNull": true,
255
+ "autoincrement": false
256
+ },
257
+ "updated_at": {
258
+ "name": "updated_at",
259
+ "type": "integer",
260
+ "primaryKey": false,
261
+ "notNull": true,
262
+ "autoincrement": false
263
+ }
264
+ },
265
+ "indexes": {
266
+ "user_email_unique": {
267
+ "name": "user_email_unique",
268
+ "columns": ["email"],
269
+ "isUnique": true
270
+ }
271
+ },
272
+ "foreignKeys": {},
273
+ "compositePrimaryKeys": {},
274
+ "uniqueConstraints": {},
275
+ "checkConstraints": {}
276
+ },
277
+ "verification": {
278
+ "name": "verification",
279
+ "columns": {
280
+ "id": {
281
+ "name": "id",
282
+ "type": "text",
283
+ "primaryKey": true,
284
+ "notNull": true,
285
+ "autoincrement": false
286
+ },
287
+ "identifier": {
288
+ "name": "identifier",
289
+ "type": "text",
290
+ "primaryKey": false,
291
+ "notNull": true,
292
+ "autoincrement": false
293
+ },
294
+ "value": {
295
+ "name": "value",
296
+ "type": "text",
297
+ "primaryKey": false,
298
+ "notNull": true,
299
+ "autoincrement": false
300
+ },
301
+ "expires_at": {
302
+ "name": "expires_at",
303
+ "type": "integer",
304
+ "primaryKey": false,
305
+ "notNull": true,
306
+ "autoincrement": false
307
+ },
308
+ "created_at": {
309
+ "name": "created_at",
310
+ "type": "integer",
311
+ "primaryKey": false,
312
+ "notNull": true,
313
+ "autoincrement": false
314
+ },
315
+ "updated_at": {
316
+ "name": "updated_at",
317
+ "type": "integer",
318
+ "primaryKey": false,
319
+ "notNull": true,
320
+ "autoincrement": false
321
+ }
322
+ },
323
+ "indexes": {
324
+ "verification_identifier_idx": {
325
+ "name": "verification_identifier_idx",
326
+ "columns": ["identifier"],
327
+ "isUnique": false
328
+ }
329
+ },
330
+ "foreignKeys": {},
331
+ "compositePrimaryKeys": {},
332
+ "uniqueConstraints": {},
333
+ "checkConstraints": {}
334
+ }
335
+ },
336
+ "views": {},
337
+ "enums": {},
338
+ "_meta": {
339
+ "schemas": {},
340
+ "tables": {},
341
+ "columns": {}
342
+ },
343
+ "internal": {
344
+ "indexes": {}
345
+ }
346
+ }
@@ -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
+ }