anhedral 0.17.0 → 0.19.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.
- package/README.md +33 -68
- package/assets/contracts/LICENSE +201 -0
- package/assets/contracts/LICENSE.environment +201 -0
- package/assets/contracts/LICENSE.operations +201 -0
- package/assets/contracts/deployment-provenance.json +15 -0
- package/assets/contracts/environment-provenance.json +11 -0
- package/assets/contracts/operations-provenance.json +12 -0
- package/assets/launch/application.server.ts.txt +13 -0
- package/assets/launch/auth-client.ts.txt +4 -0
- package/assets/launch/home.tsx.txt +20 -0
- package/assets/launch/minimal-application.server.ts.txt +5 -0
- package/assets/launch/minimal-server.ts.txt +7 -0
- package/assets/launch/oj/OJ.LICENSE +21 -0
- package/assets/launch/oj/run.mjs +82 -0
- package/assets/launch/oj/runtime.json +21 -0
- package/assets/launch/request-context.ts.txt +3 -0
- package/assets/launch/root.tsx.txt +26 -0
- package/assets/launch/router.tsx.txt +21 -0
- package/assets/launch/server.ts.txt +15 -0
- package/assets/launch/sign-in.tsx.txt +53 -0
- package/assets/launch/styles.css.txt +19 -0
- package/assets/security/credential-patterns.d.mts +3 -0
- package/assets/security/credential-patterns.mjs +59 -0
- package/assets/stack/api-index.ts.txt +6 -1
- package/assets/stack/stripe.ts.txt +30 -13
- package/assets/ui/catalog.json +36 -324
- package/dist/{platforms/web.d.ts → api-proxy.d.ts} +1 -3
- package/dist/api-proxy.js +48 -0
- package/dist/bin.js +55 -36
- package/dist/capability-catalog.d.ts +36 -57
- package/dist/capability-catalog.js +65 -67
- package/dist/capability-command.d.ts +3 -3
- package/dist/capability-command.js +146 -59
- package/dist/capability-editor.js +6 -5
- package/dist/capability-recipes.js +9 -296
- package/dist/cli-arguments.d.ts +2 -0
- package/dist/cli-arguments.js +101 -50
- package/dist/cli-commands.d.ts +1 -1
- package/dist/cli-commands.js +31 -5
- package/dist/cli-errors.d.ts +18 -0
- package/dist/cli-errors.js +63 -0
- package/dist/cli-output.d.ts +22 -0
- package/dist/cli-output.js +42 -7
- package/dist/command-runner.js +88 -0
- package/dist/command-schema.d.ts +16 -0
- package/dist/command-schema.js +496 -21
- package/dist/command-types.d.ts +1 -0
- package/dist/command-types.js +1 -0
- package/dist/completion.d.ts +2 -0
- package/dist/completion.js +201 -0
- package/dist/composition.d.ts +25 -0
- package/dist/composition.js +28 -0
- package/dist/contracts/cli-transport.d.ts +316 -0
- package/dist/contracts/cli-transport.js +236 -0
- package/dist/contracts/deployment.d.ts +233 -0
- package/dist/contracts/deployment.js +198 -0
- package/dist/contracts/environment-file.d.ts +7 -0
- package/dist/contracts/environment-file.js +112 -0
- package/dist/contracts/environment-transport.d.ts +79 -0
- package/dist/contracts/environment-transport.js +110 -0
- package/dist/contracts/production-transport.d.ts +71 -0
- package/dist/contracts/production-transport.js +56 -0
- package/dist/contracts/runtime-logs-transport.d.ts +127 -0
- package/dist/contracts/runtime-logs-transport.js +50 -0
- package/dist/contracts/source-bundle.d.ts +11 -0
- package/dist/contracts/source-bundle.js +197 -0
- package/dist/contracts/source-profile.d.ts +4 -0
- package/dist/contracts/source-profile.js +5 -0
- package/dist/contracts/staging-transport.d.ts +79 -0
- package/dist/contracts/staging-transport.js +43 -0
- package/dist/dependencies.d.ts +9 -27
- package/dist/dependencies.js +19 -66
- package/dist/index.d.ts +4 -2
- package/dist/index.js +3 -1
- package/dist/launch.d.ts +27 -0
- package/dist/launch.js +262 -0
- package/dist/platform-command.d.ts +9 -0
- package/dist/platform-command.js +787 -0
- package/dist/platform-environment.d.ts +18 -0
- package/dist/platform-environment.js +257 -0
- package/dist/platform-operations.d.ts +26 -0
- package/dist/platform-operations.js +155 -0
- package/dist/platform-production.d.ts +16 -0
- package/dist/platform-production.js +135 -0
- package/dist/platform-source.d.ts +8 -0
- package/dist/platform-source.js +111 -0
- package/dist/platform-state.d.ts +15 -0
- package/dist/platform-state.js +229 -0
- package/dist/platforms/tanstack.d.ts +10 -0
- package/dist/platforms/tanstack.js +248 -0
- package/dist/registry/usage.d.ts +4 -1
- package/dist/registry/usage.js +59 -4
- package/dist/scaffold/bootstrap.d.ts +3 -3
- package/dist/scaffold/styling.d.ts +3 -2
- package/dist/transaction.js +28 -3
- package/dist/ui-catalog.d.ts +3 -5
- package/dist/ui-catalog.js +8 -24
- package/dist/ui-command.d.ts +3 -1
- package/dist/ui-command.js +74 -72
- package/dist/ui-project.d.ts +4 -2
- package/dist/ui-project.js +40 -38
- package/dist/util.js +40 -61
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/capabilities.md +23 -89
- package/docs/software-factory.md +208 -9
- package/docs/stack-standard.md +7 -17
- package/docs/ui.md +9 -22
- package/package.json +26 -22
- package/assets/stack/ai-schema.ts.txt +0 -5
- package/assets/stack/ai.ts.txt +0 -30
- package/assets/stack/desktop.rs.txt +0 -21
- package/assets/stack/events-schema.ts.txt +0 -12
- package/assets/stack/events.ts.txt +0 -59
- package/assets/stack/mobile-auth.ts.txt +0 -25
- package/assets/stack/mobile-billing.tsx.txt +0 -63
- package/assets/stack/mobile-session.tsx.txt +0 -83
- package/assets/stack/native-button.tsx.txt +0 -108
- package/assets/stack/native-global.css.txt +0 -4
- package/assets/stack/native-lib-utils.ts.txt +0 -5
- package/assets/stack/native-metro.config.js.txt +0 -6
- package/assets/stack/native-nativewind-env.d.ts.txt +0 -1
- package/assets/stack/native-tailwind.config.js.txt +0 -73
- package/assets/stack/native-text.tsx.txt +0 -89
- package/assets/stack/purchases.ts.txt +0 -65
- package/assets/stack/revenuecat.ts.txt +0 -88
- package/assets/stack/rtc-schema.ts.txt +0 -10
- package/assets/stack/rtc.ts.txt +0 -122
- package/assets/stack/web-sign-in.tsx.txt +0 -51
- package/dist/capabilities.d.ts +0 -11
- package/dist/capabilities.js +0 -14
- package/dist/dependency-order.d.ts +0 -2
- package/dist/dependency-order.js +0 -24
- package/dist/platforms/lint.d.ts +0 -1
- package/dist/platforms/lint.js +0 -5
- package/dist/platforms/web.js +0 -251
- package/dist/project-config.d.ts +0 -3
- package/dist/project-config.js +0 -16
- package/dist/registry/context.d.ts +0 -3
- package/dist/registry/context.js +0 -20
- package/dist/registry/options.d.ts +0 -2
- package/dist/registry/options.js +0 -44
- package/dist/registry/resolve.d.ts +0 -11
- package/dist/registry/resolve.js +0 -46
- package/dist/registry/types.d.ts +0 -60
- package/dist/scaffold/api.d.ts +0 -2
- package/dist/scaffold/api.js +0 -38
- package/dist/scaffold/backend.d.ts +0 -2
- package/dist/scaffold/backend.js +0 -36
- package/dist/scaffold/compose.d.ts +0 -4
- package/dist/scaffold/compose.js +0 -30
- package/dist/scaffold/database.d.ts +0 -2
- package/dist/scaffold/database.js +0 -41
- package/dist/scaffold/documentation.d.ts +0 -2
- package/dist/scaffold/documentation.js +0 -71
- package/dist/scaffold/environment.d.ts +0 -4
- package/dist/scaffold/environment.js +0 -22
- package/dist/scaffold/stack-documentation.d.ts +0 -2
- package/dist/scaffold/stack-documentation.js +0 -6
- package/dist/scaffold/storage.d.ts +0 -2
- package/dist/scaffold/storage.js +0 -21
- package/dist/scaffold/workspace.d.ts +0 -3
- package/dist/scaffold/workspace.js +0 -131
- package/dist/stack-registry.d.ts +0 -35
- package/dist/stack-registry.js +0 -189
- package/dist/standard.d.ts +0 -8
- package/dist/standard.js +0 -94
- package/dist/workspace-graph.d.ts +0 -7
- package/dist/workspace-graph.js +0 -74
- package/docs/anhedral-stack.md +0 -12
- package/docs/assets/anhedral-stack-light.png +0 -0
- package/docs/assets/anhedral-stack.png +0 -0
- package/docs/native-ui.md +0 -47
- /package/dist/{registry/types.js → command-runner.d.ts} +0 -0
package/docs/ui.md
CHANGED
|
@@ -1,33 +1,20 @@
|
|
|
1
1
|
# Anhedral UI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Anhedral UI is the source-owned web UI layer of the **Anhedral Stack**, using official shadcn and semantic theme tokens. It is a catalog/installer convention, not another runtime component library.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
6
|
anhedral ui list --json
|
|
7
|
-
anhedral ui
|
|
8
|
-
anhedral ui
|
|
9
|
-
anhedral ui
|
|
10
|
-
anhedral ui diff button --native
|
|
11
|
-
anhedral ui doctor --all
|
|
12
|
-
anhedral ui add card --all --dry-run --json
|
|
7
|
+
anhedral ui add card --web
|
|
8
|
+
anhedral ui diff card --web
|
|
9
|
+
anhedral ui doctor --web
|
|
13
10
|
```
|
|
14
11
|
|
|
15
|
-
|
|
12
|
+
Init already creates web UI configuration and reviewed Button, Input and Label source. `list` reads the packaged web catalog offline. `init`, `add`, `diff` and `doctor` select an Anhedral Stack web application through the working directory or `--cwd`; `--web` is optional. Current public commands do not select mobile/native targets or arbitrary framework applications.
|
|
16
13
|
|
|
17
|
-
|
|
14
|
+
`--dry-run --json` previews configuration/installation without network or writes. Selected destinations, metadata and attribution paths are preflighted before installation. CLI-owned writes refuse symlinked metadata destinations. Bounded consumer manifest/configuration links remain supported where their targets are regular files. Ambiguous or invalid targets stop before installation.
|
|
18
15
|
|
|
19
|
-
|
|
16
|
+
The pinned official shadcn CLI resolves registry dependencies and copies source. `add` never requests overwrite; review diffs and reconcile customizations explicitly. `diff` delegates to the upstream preview. Installer failure can leave partial upstream changes, so inspect Git before retrying.
|
|
20
17
|
|
|
21
|
-
`
|
|
18
|
+
`assets/ui/catalog.json` owns the web inventory and pinned installer. `.anhedral-ui.json` records catalog/platform ownership, not automatic updates or runtime certification. Preserve applicable MIT notices under `ANHEDRAL_UI_LICENSES/`, existing components, semantic tokens and source attribution.
|
|
22
19
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
## Ownership and provenance
|
|
26
|
-
|
|
27
|
-
`assets/ui/catalog.json` records the catalog revision, upstream sources, dependency metadata and pinned installer. Availability is not parity or runtime certification. RNR URLs are live upstream endpoints; the catalog's recorded source revision describes the inventory, not an immutable downloaded artifact. Review registry changes before installing into sensitive consumers.
|
|
28
|
-
|
|
29
|
-
`.anhedral-ui.json` records platform, catalog revision and source ownership; it does not automatically update components. `ANHEDRAL_UI_LICENSES/` retains the relevant MIT notice. No Anhedral runtime package is introduced. Theme through consumer CSS variables and existing tokens. Future native extensions require a focused product need, upstream provenance/license and native consumer evidence; broad parity is not a release prerequisite.
|
|
30
|
-
|
|
31
|
-
Validate web flows in a browser. Validate native interactions in Android/iOS development builds, including accessibility, overlays, keyboard and lifecycle. Typechecking or an Expo web export does not establish device acceptance. The retired exhaustive port is preserved outside the active CLI; `docs/native-ui.md` records its recovery identity and migration path.
|
|
32
|
-
|
|
33
|
-
For a generated Anhedral workspace, `anhedral add expo` creates the native application after its core source prerequisites, and `anhedral add native-ui` prepares its NativeWind/RNR integration without replacing product UI. The UI component commands remain independent of backend activation. See [stack additions](capabilities.md).
|
|
20
|
+
Validate browser behavior, keyboard focus and interactions. Typechecking or source completeness alone is not browser acceptance. Backend services are independent additions; UI installation does not require authentication, a database or storage. See [stack additions](capabilities.md).
|
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "anhedral",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.19.0",
|
|
4
|
+
"description": "Generate the Anhedral Stack as editable source: start with web UI, then add backend, storage and payments.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"import": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./deployment": {
|
|
12
|
+
"types": "./dist/contracts/deployment.d.ts",
|
|
13
|
+
"import": "./dist/contracts/deployment.js"
|
|
10
14
|
}
|
|
11
15
|
},
|
|
12
16
|
"types": "./dist/index.d.ts",
|
|
@@ -26,10 +30,6 @@
|
|
|
26
30
|
"docs/stack-standard.md",
|
|
27
31
|
"docs/software-factory.md",
|
|
28
32
|
"docs/verification.md",
|
|
29
|
-
"docs/anhedral-stack.md",
|
|
30
|
-
"docs/assets/anhedral-stack.png",
|
|
31
|
-
"docs/assets/anhedral-stack-light.png",
|
|
32
|
-
"docs/native-ui.md",
|
|
33
33
|
"docs/ui.md",
|
|
34
34
|
"assets/stack",
|
|
35
35
|
"docs/capabilities.md",
|
|
@@ -38,7 +38,10 @@
|
|
|
38
38
|
"assets/ui/extensions",
|
|
39
39
|
"assets/ui/LICENSE.shadcn",
|
|
40
40
|
"assets/ui/LICENSE.react-native-reusables",
|
|
41
|
-
"assets/ui/UPSTREAM.json"
|
|
41
|
+
"assets/ui/UPSTREAM.json",
|
|
42
|
+
"assets/contracts",
|
|
43
|
+
"assets/security",
|
|
44
|
+
"assets/launch"
|
|
42
45
|
],
|
|
43
46
|
"homepage": "https://github.com/anhedral/anhedral-cli#readme",
|
|
44
47
|
"repository": {
|
|
@@ -58,20 +61,19 @@
|
|
|
58
61
|
"scripts": {
|
|
59
62
|
"scaffold": "node dist/bin.js init",
|
|
60
63
|
"clean": "node scripts/clean.mjs",
|
|
61
|
-
"build": "pnpm clean && tsc && node scripts/prepare-cli.mjs",
|
|
64
|
+
"build": "node scripts/standalone-checkout.mjs && pnpm clean && tsc && node scripts/prepare-cli.mjs",
|
|
62
65
|
"prepare": "pnpm build",
|
|
63
66
|
"typecheck": "tsc --noEmit",
|
|
64
|
-
"check:hygiene": "node scripts/check-source-hygiene.mjs",
|
|
67
|
+
"check:hygiene": "node scripts/check-source-hygiene.mjs && node scripts/check-environment-contract.mjs && node scripts/check-operations-contract.mjs",
|
|
65
68
|
"check:security": "node scripts/check-security-policy.mjs",
|
|
66
69
|
"check:release-policy": "node scripts/check-release-policy.mjs",
|
|
67
70
|
"check:release-secrets": "node scripts/check-release-secrets.mjs",
|
|
68
|
-
"lint": "pnpm typecheck && pnpm format:check && pnpm check:hygiene && pnpm check:release-policy",
|
|
71
|
+
"lint": "pnpm typecheck && pnpm format:check && pnpm check:hygiene && pnpm check:release-policy && pnpm check:boundaries",
|
|
69
72
|
"audit:osv": "node scripts/audit-osv.mjs",
|
|
70
73
|
"test": "pnpm test:unit",
|
|
71
74
|
"pretest": "pnpm build",
|
|
72
75
|
"prepublishOnly": "pnpm test:all",
|
|
73
76
|
"test:cli:validation": "node --test tests/test-cli-validation.test.mjs",
|
|
74
|
-
"test:contracts:types": "node tests/test-generated-contracts-types.mjs",
|
|
75
77
|
"test:pack": "pnpm build && node tests/test-packed-cli.js",
|
|
76
78
|
"test:pack:exact": "node tests/test-packed-cli.js .artifacts/release/metadata.json",
|
|
77
79
|
"test:packlist": "pnpm build && node tests/test-packlist.js",
|
|
@@ -81,29 +83,30 @@
|
|
|
81
83
|
"release:pack": "pnpm build && pnpm plugin:build && node scripts/create-release-artifact.mjs && node scripts/check-release-secrets.mjs .artifacts/release/metadata.json",
|
|
82
84
|
"release:artifact:verify": "node scripts/verify-release-artifact.mjs .artifacts/release/metadata.json && node scripts/check-release-secrets.mjs .artifacts/release/metadata.json",
|
|
83
85
|
"release:artifact:smoke": "node tests/test-packed-cli.js .artifacts/release/metadata.json",
|
|
84
|
-
"test:standard": "pnpm build && node --test tests/test-standard.test.mjs",
|
|
85
86
|
"test:unit": "node --test --test-concurrency=4 --test-reporter=spec tests/*.test.mjs",
|
|
86
87
|
"test:integration": "pnpm build && node tests/test-generated-apps.mjs",
|
|
87
|
-
"format": "prettier --write src scripts tests \"assets/patches/*.mjs\" assets/ui && node scripts/stack-template-format.mjs --write",
|
|
88
|
-
"format:check": "prettier --check src scripts tests \"assets/patches/*.mjs\" assets/ui && node scripts/stack-template-format.mjs",
|
|
88
|
+
"format": "prettier --write src scripts tests \"assets/patches/*.mjs\" assets/ui assets/security && node scripts/stack-template-format.mjs --write",
|
|
89
|
+
"format:check": "prettier --check src scripts tests \"assets/patches/*.mjs\" assets/ui assets/security && node scripts/stack-template-format.mjs",
|
|
89
90
|
"plugin:build": "node scripts/check-plugin.mjs",
|
|
90
91
|
"plugin:check": "node scripts/check-plugin.mjs",
|
|
91
92
|
"test:patch": "node tests/test-braces-install.mjs && node tests/test-forge-install.mjs",
|
|
92
|
-
"
|
|
93
|
+
"check:boundaries": "node scripts/repository-boundaries.mjs",
|
|
94
|
+
"test:tanstack-runtime": "pnpm build && node scripts/tanstack-runtime-smoke.mjs",
|
|
95
|
+
"check:standalone": "node scripts/standalone-checkout.mjs"
|
|
93
96
|
},
|
|
94
97
|
"keywords": [
|
|
95
98
|
"cli",
|
|
96
99
|
"scaffold",
|
|
97
100
|
"typescript",
|
|
98
|
-
"
|
|
101
|
+
"anhedral-stack",
|
|
102
|
+
"tanstack-start",
|
|
99
103
|
"hono",
|
|
104
|
+
"better-auth",
|
|
100
105
|
"cloudflare",
|
|
101
106
|
"d1",
|
|
102
107
|
"r2",
|
|
103
108
|
"drizzle",
|
|
104
|
-
"
|
|
105
|
-
"nextjs",
|
|
106
|
-
"opennext"
|
|
109
|
+
"stripe"
|
|
107
110
|
],
|
|
108
111
|
"license": "Apache-2.0",
|
|
109
112
|
"packageManager": "pnpm@10.34.5",
|
|
@@ -111,11 +114,12 @@
|
|
|
111
114
|
"@types/node": "20.19.43",
|
|
112
115
|
"hono": "4.13.13",
|
|
113
116
|
"prettier": "3.9.10",
|
|
114
|
-
"typescript": "5.9.3"
|
|
115
|
-
"zod": "4.6.6"
|
|
117
|
+
"typescript": "5.9.3"
|
|
116
118
|
},
|
|
117
119
|
"dependencies": {
|
|
118
120
|
"jsonc-parser": "3.3.1",
|
|
119
|
-
"yaml": "2.9.1"
|
|
121
|
+
"yaml": "2.9.1",
|
|
122
|
+
"zod": "4.6.6",
|
|
123
|
+
"ignore": "7.0.14"
|
|
120
124
|
}
|
|
121
125
|
}
|
package/assets/stack/ai.ts.txt
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Hono } from 'hono';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { requireSession } from '../security';
|
|
4
|
-
import type { AppEnv } from '../environment';
|
|
5
|
-
export const aiRoutes = new Hono<AppEnv>();
|
|
6
|
-
const configuration = z.object({
|
|
7
|
-
AI_MODEL: z.string().min(1),
|
|
8
|
-
AI_DAILY_LIMIT: z.coerce.number().int().min(1).max(1000),
|
|
9
|
-
});
|
|
10
|
-
const input = z.object({ prompt: z.string().trim().min(1).max(4000) });
|
|
11
|
-
aiRoutes.post('/ai/generate', requireSession, async (c) => {
|
|
12
|
-
const config = configuration.safeParse(c.env);
|
|
13
|
-
if (!config.success)
|
|
14
|
-
return c.json({ error: 'Choose a model and a daily limit from 1 to 1000' }, 503);
|
|
15
|
-
const body = input.safeParse(await c.req.json().catch(() => null));
|
|
16
|
-
if (!body.success) return c.json({ error: 'Prompt must contain 1–4000 characters' }, 400);
|
|
17
|
-
const key = c.get('userId') + ':' + new Date().toISOString().slice(0, 10);
|
|
18
|
-
const quota = await c.env.DB.prepare(
|
|
19
|
-
'INSERT INTO ai_usage(id,count) VALUES (?,1) ON CONFLICT(id) DO UPDATE SET count = count + 1 WHERE count < ? RETURNING count',
|
|
20
|
-
)
|
|
21
|
-
.bind(key, config.data.AI_DAILY_LIMIT)
|
|
22
|
-
.first();
|
|
23
|
-
if (!quota) return c.json({ error: 'Daily AI limit reached' }, 429);
|
|
24
|
-
// Failed provider calls consume quota as well; retrying cannot bypass the limit.
|
|
25
|
-
const result = await c.env.AI.run(config.data.AI_MODEL as Parameters<Ai['run']>[0], {
|
|
26
|
-
messages: [{ role: 'user', content: body.data.prompt }],
|
|
27
|
-
max_tokens: 512,
|
|
28
|
-
});
|
|
29
|
-
return c.json({ result });
|
|
30
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
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
|
-
);
|
|
@@ -1,59 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,108 +0,0 @@
|
|
|
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 };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/// <reference types="nativewind/types" />
|