anhedral 0.18.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 +6 -6
- package/assets/contracts/deployment-provenance.json +6 -6
- package/assets/contracts/operations-provenance.json +2 -1
- 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/root.tsx.txt +1 -2
- package/assets/launch/server.ts.txt +4 -2
- 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/capability-catalog.d.ts +3 -57
- package/dist/capability-catalog.js +3 -90
- package/dist/capability-command.d.ts +2 -2
- package/dist/capability-command.js +32 -96
- package/dist/capability-recipes.js +8 -343
- package/dist/cli-commands.js +3 -1
- package/dist/command-schema.js +106 -0
- package/dist/command-types.d.ts +1 -0
- package/dist/composition.d.ts +4 -14
- package/dist/composition.js +6 -6
- package/dist/contracts/cli-transport.d.ts +139 -40
- package/dist/contracts/cli-transport.js +96 -27
- package/dist/contracts/deployment.d.ts +7 -56
- package/dist/contracts/deployment.js +9 -45
- package/dist/contracts/production-transport.d.ts +71 -0
- package/dist/contracts/production-transport.js +56 -0
- package/dist/contracts/source-profile.js +1 -1
- package/dist/contracts/staging-transport.d.ts +2 -2
- package/dist/dependencies.d.ts +0 -27
- package/dist/dependencies.js +3 -67
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -2
- package/dist/launch.d.ts +11 -5
- package/dist/launch.js +21 -9
- package/dist/platform-command.js +245 -42
- package/dist/platform-production.d.ts +16 -0
- package/dist/platform-production.js +135 -0
- package/dist/platform-state.d.ts +2 -0
- package/dist/platform-state.js +23 -1
- package/dist/platforms/tanstack.d.ts +2 -0
- package/dist/platforms/tanstack.js +113 -20
- package/dist/registry/usage.js +1 -0
- package/dist/scaffold/bootstrap.d.ts +3 -3
- package/dist/scaffold/styling.d.ts +3 -2
- package/dist/ui-catalog.d.ts +3 -5
- package/dist/ui-catalog.js +8 -24
- package/dist/ui-command.d.ts +1 -1
- package/dist/ui-command.js +18 -57
- package/dist/ui-project.d.ts +2 -2
- package/dist/ui-project.js +8 -36
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/capabilities.md +7 -7
- package/docs/software-factory.md +55 -16
- package/docs/stack-standard.md +1 -1
- package/package.json +1 -4
- 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/event-retention.sql.txt +0 -10
- 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 -47
- 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 -141
- 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 -109
- package/dist/workspace-graph.d.ts +0 -7
- package/dist/workspace-graph.js +0 -74
- /package/dist/{registry/types.js → command-types.js} +0 -0
package/docs/software-factory.md
CHANGED
|
@@ -25,7 +25,7 @@ with revision, checks, failures and remaining gaps. Keep raw reports in ignored
|
|
|
25
25
|
`.artifacts/`. Historical notes are not current instructions.
|
|
26
26
|
|
|
27
27
|
Canonical docs live in `docs/`; `pnpm build` refreshes bundled plugin references.
|
|
28
|
-
Current generated app guidance lives in `src/launch.ts
|
|
28
|
+
Current generated app guidance lives in `src/launch.ts`. OJ runs development and builds for the single TanStack Start foundation. Preserve shipped
|
|
29
29
|
reference paths, source-generation safety, dependency patch gates, UI provenance,
|
|
30
30
|
licenses and exact-artifact packaging. A build does not publish npm or update an
|
|
31
31
|
installed plugin. See [Contributing](https://github.com/anhedral/anhedral-cli/blob/main/.github/CONTRIBUTING.md)
|
|
@@ -48,7 +48,7 @@ dist module or private import requires explicit review. Portable contracts are
|
|
|
48
48
|
synced only from a reviewed, licensed Platform projection with exact provenance,
|
|
49
49
|
never as a build side effect. Local credential scanning additionally retains the
|
|
50
50
|
CLI's stricter source-upload policy. Plugin packaging accepts its explicit reviewed
|
|
51
|
-
|
|
51
|
+
skills-only file set, refuses linked distribution roots and verifies the bounded
|
|
52
52
|
publisher archive format before npm publication. Oversized unscanned text is an
|
|
53
53
|
explicit review failure, not a clean secret scan.
|
|
54
54
|
|
|
@@ -62,11 +62,17 @@ application matrices remain in [Full validation](https://github.com/anhedral/anh
|
|
|
62
62
|
|
|
63
63
|
`node scripts/tanstack-runtime-smoke.mjs` installs a disposable Anhedral Stack
|
|
64
64
|
application and exercises local workerd, SSR/server functions, progressive backend,
|
|
65
|
-
private storage and the generated Stripe build/migration path.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
passed and failed evidence. Tests are not provider deployment acceptance.
|
|
65
|
+
private storage and the generated Stripe build/migration path. The compiled web
|
|
66
|
+
and API Workers run together with the migrated local D1 state. Bundle measurements
|
|
67
|
+
follow OJ’s emitted Worker configuration and count its runtime modules. It uses
|
|
68
|
+
isolated local data, never a configured database or live payment provider. Preserve source/tool/lock identities and distinguish prepared,
|
|
69
|
+
passed and failed evidence. Tests are not provider deployment acceptance. Run
|
|
70
|
+
`node tests/test-generated-config-lint.mjs <installed-workspace>` to exercise the
|
|
71
|
+
generated web ESLint policy; runtime proof checks both web-only and composed source.
|
|
72
|
+
|
|
73
|
+
Backend server entries call TanStack’s `createStartHandler(defaultStreamHandler)` directly so request-local API bindings survive OJ compilation. Source additions repair the exact previous owned adapter and preserve customer edits.
|
|
74
|
+
|
|
75
|
+
OJ dev commands attach an explicit host value with `--host=<hostname>`, as required by the pinned runtime. Generated workspaces explicitly allow dependency build scripts only for esbuild and workerd through the pnpm `allowBuilds` map. This keeps installation noninteractive under the pinned pnpm release and pnpm11 without allowing arbitrary dependency scripts.
|
|
70
76
|
|
|
71
77
|
## Platform CLI access and source upload
|
|
72
78
|
|
|
@@ -86,6 +92,24 @@ JSON is unchanged and context inspection never creates a project or starts login
|
|
|
86
92
|
Explicit `--api-url` and `--credential-file` select the origin/store; saved state
|
|
87
93
|
cannot override either. API access must be separately enabled by Platform operators.
|
|
88
94
|
|
|
95
|
+
After generating source, run `projects list --human` to discover the selected
|
|
96
|
+
team's projects and accessible team IDs. Use `--team <uuid>` to select another
|
|
97
|
+
team and `--cursor <uuid>` for the next page. `projects create --name <name>
|
|
98
|
+
--link --human` registers a new Platform project and links the current directory;
|
|
99
|
+
omit `--link` to register it without changing local context. `--summary <text>`
|
|
100
|
+
is optional. Creation registers existing source for upload; it does not generate
|
|
101
|
+
another application or start a deployment. `projects create --dry-run` validates
|
|
102
|
+
the proposed input locally without authentication or network access.
|
|
103
|
+
|
|
104
|
+
Creation saves its request identity under `.anhedral/platform/` before sending
|
|
105
|
+
it. Repeat the same command after interruption to recover the same project;
|
|
106
|
+
changed input, identity or team requires review and an explicit `--new` request.
|
|
107
|
+
`--link` refuses a different existing local link. Init's source identity remains
|
|
108
|
+
unchanged. Platform checks current team membership and project permissions.
|
|
109
|
+
Project creation, linking and unlinking share a workspace lock. After a process
|
|
110
|
+
crash, inspect `.anhedral/platform/project-operation.lock` and remove only that
|
|
111
|
+
lock after confirming no project operation is running; preserve the request journal.
|
|
112
|
+
|
|
89
113
|
`link --project <uuid> --team <uuid>` checks current build authority and saves an
|
|
90
114
|
origin/principal-bound link under ignored `.anhedral/platform/`. `unlink` removes
|
|
91
115
|
that local link. `source upload --dry-run` inspects packaging; `source upload`
|
|
@@ -111,8 +135,8 @@ of subsequent local edits. The manifest follows Platform's `deploymentManifestSc
|
|
|
111
135
|
in `src/contracts/deployment.ts`; it must match the archive's recorded composition,
|
|
112
136
|
capabilities, CLI version and existing standalone identity. Runtime-profile admission is server-owned. Staged server sources include Hono/D1
|
|
113
137
|
and web candidates; source support does not establish a deployed cohort or provider readiness. Plans bind source/lockfile/migrations,
|
|
114
|
-
routing state, principal epoch and project authority.
|
|
115
|
-
|
|
138
|
+
routing state, principal epoch and project authority. Signed plans report current artifact, source-version and dependency-lock compatibility.
|
|
139
|
+
A null project configuration revision means deployment has not yet captured its environment snapshot; it is not a request to find an operator approver.
|
|
116
140
|
Anhedral Stack source composition version 2 records framework foundation
|
|
117
141
|
`tanstack-start`; the public runtime profile is `anhedral-stack`. Its five compositions are
|
|
118
142
|
web-only, backend (`hono` plus `database-auth`), backend/R2, backend/Stripe and
|
|
@@ -122,7 +146,7 @@ not current public selections or hosted support.
|
|
|
122
146
|
Continue selecting an explicit manifest; the CLI never infers an admitted artifact
|
|
123
147
|
from locally generated source. Native candidate receipts name an immutable registry
|
|
124
148
|
image with `scope: candidate-workspace`; legacy isolated-build receipts remain valid.
|
|
125
|
-
Both describe build
|
|
149
|
+
Both describe automatic build compatibility, not a requirement for a human artifact approver. Plans list exact runtime, source-version or lockfile mismatches and remediation. Do not relabel source provenance to clear a mismatch.
|
|
126
150
|
|
|
127
151
|
`deploy prepare` reserves an immutable candidate. `deploy status` reads
|
|
128
152
|
`awaiting-runtime`, `building`, `built`, `ready` or `failed`. A built candidate grants no
|
|
@@ -154,17 +178,32 @@ retains one generation-bound request across retries. `--new` starts another
|
|
|
154
178
|
deployment after reviewing the current state. Saved receipts must match their
|
|
155
179
|
project, candidate, request and generation before replay. CLI runtime admission remains a
|
|
156
180
|
separate server gate; a built source upload alone is not a ready candidate.
|
|
181
|
+
`production status` reads current production generation, deployment history and approval policy. `production deploy --candidate <uuid> --name <slug>` freezes production configuration and publishes through the signed-in user's existing production permissions. Self-service teams need no second approver; an explicit independent-review policy remains enforced. Lost responses reuse the saved request and generation; use `--new` only for another candidate, name or deliberate deployment.
|
|
182
|
+
|
|
157
183
|
`logs` reads bounded, redacted runtime events, defaulting to staging. Select
|
|
158
184
|
production explicitly with `--environment production`; filter by deployment,
|
|
159
185
|
level, source or range, and pass `--cursor` for the next page. Coverage, dropped
|
|
160
186
|
events and seven-day retention are part of the response.
|
|
161
187
|
|
|
162
|
-
The plugin
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
188
|
+
The plugin contains CLI usage instructions only. It registers no MCP server, remote
|
|
189
|
+
app, OAuth connection or executable hook, and it does not bundle a CLI runtime.
|
|
190
|
+
Users run the reviewed CLI version in a host terminal; managed project operations
|
|
191
|
+
use the separately configured CLI client described above. Packaging admits only
|
|
192
|
+
reviewed skills, references, assets and host manifests, and rejects connection files
|
|
193
|
+
or executable declarations. `tests/test-plugin-codex.test.mjs` installs the exact
|
|
194
|
+
archive in an isolated Codex home and verifies both skills with no MCP, app or hook
|
|
195
|
+
registration when Codex is available (`ANHEDRAL_CODEX_BIN` overrides the binary).
|
|
196
|
+
|
|
197
|
+
One distribution directory, `plugin/`, serves Codex and Claude Code. Codex reads
|
|
198
|
+
`plugin.json` and `skills/*/agents/openai.yaml`; Claude Code reads
|
|
199
|
+
`.claude-plugin/plugin.json` and the same `skills/*/SKILL.md`. Packaging validates
|
|
200
|
+
both manifests against one release identity. Root `.claude-plugin/marketplace.json`
|
|
201
|
+
is the Claude marketplace; add it with `claude plugin marketplace add
|
|
202
|
+
anhedral/anhedral-cli`, then install `anhedral@anhedral`. The existing pinned tag
|
|
203
|
+
predates the Claude files and this cleanup; a coordinated versioned release is
|
|
204
|
+
required before those changes are installable from the public marketplace. Local
|
|
205
|
+
review uses `claude plugin validate --strict plugin`, `claude --plugin-dir plugin`
|
|
206
|
+
and a temporary Codex marketplace, without account connection.
|
|
168
207
|
|
|
169
208
|
The CLI and plugin share one release version. Build prepares the
|
|
170
209
|
marketplace pointer to that version's immutable `plugin-v<version>` tag; it does
|
package/docs/stack-standard.md
CHANGED
|
@@ -8,4 +8,4 @@ When selected, Hono owns privileged business/auth/data/storage operations. Web s
|
|
|
8
8
|
|
|
9
9
|
Auth methods and payment providers require explicit activation. Apply reviewed migrations separately from builds/startup. Source-owned UI preserves semantic tokens, consumer edits and upstream licensing; see [UI ownership](ui.md).
|
|
10
10
|
|
|
11
|
-
Recorded source provenance is not a hosting receipt. Runtime profile `anhedral-stack` identifies the current deployment contract; exact artifact/runtime policy, current authority and production approval still apply.
|
|
11
|
+
Recorded source provenance is not a hosting receipt. Runtime profile `anhedral-stack` identifies the current deployment contract; exact artifact/runtime policy, current authority and production approval still apply. Legacy generators, framework aliases and compatibility stack selection are removed. OJ is pinned by the generated runtime manifest.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "anhedral",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
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": {
|
|
@@ -74,7 +74,6 @@
|
|
|
74
74
|
"pretest": "pnpm build",
|
|
75
75
|
"prepublishOnly": "pnpm test:all",
|
|
76
76
|
"test:cli:validation": "node --test tests/test-cli-validation.test.mjs",
|
|
77
|
-
"test:contracts:types": "node tests/test-generated-contracts-types.mjs",
|
|
78
77
|
"test:pack": "pnpm build && node tests/test-packed-cli.js",
|
|
79
78
|
"test:pack:exact": "node tests/test-packed-cli.js .artifacts/release/metadata.json",
|
|
80
79
|
"test:packlist": "pnpm build && node tests/test-packlist.js",
|
|
@@ -84,7 +83,6 @@
|
|
|
84
83
|
"release:pack": "pnpm build && pnpm plugin:build && node scripts/create-release-artifact.mjs && node scripts/check-release-secrets.mjs .artifacts/release/metadata.json",
|
|
85
84
|
"release:artifact:verify": "node scripts/verify-release-artifact.mjs .artifacts/release/metadata.json && node scripts/check-release-secrets.mjs .artifacts/release/metadata.json",
|
|
86
85
|
"release:artifact:smoke": "node tests/test-packed-cli.js .artifacts/release/metadata.json",
|
|
87
|
-
"test:standard": "pnpm build && node --test tests/test-standard.test.mjs",
|
|
88
86
|
"test:unit": "node --test --test-concurrency=4 --test-reporter=spec tests/*.test.mjs",
|
|
89
87
|
"test:integration": "pnpm build && node tests/test-generated-apps.mjs",
|
|
90
88
|
"format": "prettier --write src scripts tests \"assets/patches/*.mjs\" assets/ui assets/security && node scripts/stack-template-format.mjs --write",
|
|
@@ -92,7 +90,6 @@
|
|
|
92
90
|
"plugin:build": "node scripts/check-plugin.mjs",
|
|
93
91
|
"plugin:check": "node scripts/check-plugin.mjs",
|
|
94
92
|
"test:patch": "node tests/test-braces-install.mjs && node tests/test-forge-install.mjs",
|
|
95
|
-
"test:next-runtime": "pnpm build && node scripts/next-runtime-smoke.mjs",
|
|
96
93
|
"check:boundaries": "node scripts/repository-boundaries.mjs",
|
|
97
94
|
"test:tanstack-runtime": "pnpm build && node scripts/tanstack-runtime-smoke.mjs",
|
|
98
95
|
"check:standalone": "node scripts/standalone-checkout.mjs"
|
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,10 +0,0 @@
|
|
|
1
|
-
-- Private event-feed consumer example, never a migration or scheduled CLI task.
|
|
2
|
-
-- Review the owner and cutoff against the active replay window before executing.
|
|
3
|
-
-- Delete at most 100 expired rows belonging to the selected authenticated owner.
|
|
4
|
-
DELETE FROM application_event
|
|
5
|
-
WHERE id IN (
|
|
6
|
-
SELECT id FROM application_event
|
|
7
|
-
WHERE user_id = ? AND created_at < ?
|
|
8
|
-
ORDER BY created_at, id
|
|
9
|
-
LIMIT 100
|
|
10
|
-
);
|
|
@@ -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" />
|