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
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
const { hairlineWidth } = require('nativewind/theme');
|
|
2
|
-
|
|
3
|
-
/** @type {import('tailwindcss').Config} */
|
|
4
|
-
module.exports = {
|
|
5
|
-
darkMode: 'class',
|
|
6
|
-
content: ['./app/**/*.{ts,tsx}', './components/**/*.{ts,tsx}'],
|
|
7
|
-
presets: [require('nativewind/preset')],
|
|
8
|
-
theme: {
|
|
9
|
-
extend: {
|
|
10
|
-
colors: {
|
|
11
|
-
border: 'hsl(var(--border))',
|
|
12
|
-
input: 'hsl(var(--input))',
|
|
13
|
-
ring: 'hsl(var(--ring))',
|
|
14
|
-
background: 'hsl(var(--background))',
|
|
15
|
-
foreground: 'hsl(var(--foreground))',
|
|
16
|
-
primary: {
|
|
17
|
-
DEFAULT: 'hsl(var(--primary))',
|
|
18
|
-
foreground: 'hsl(var(--primary-foreground))',
|
|
19
|
-
},
|
|
20
|
-
secondary: {
|
|
21
|
-
DEFAULT: 'hsl(var(--secondary))',
|
|
22
|
-
foreground: 'hsl(var(--secondary-foreground))',
|
|
23
|
-
},
|
|
24
|
-
destructive: {
|
|
25
|
-
DEFAULT: 'hsl(var(--destructive))',
|
|
26
|
-
foreground: 'hsl(var(--destructive-foreground))',
|
|
27
|
-
},
|
|
28
|
-
muted: {
|
|
29
|
-
DEFAULT: 'hsl(var(--muted))',
|
|
30
|
-
foreground: 'hsl(var(--muted-foreground))',
|
|
31
|
-
},
|
|
32
|
-
accent: {
|
|
33
|
-
DEFAULT: 'hsl(var(--accent))',
|
|
34
|
-
foreground: 'hsl(var(--accent-foreground))',
|
|
35
|
-
},
|
|
36
|
-
popover: {
|
|
37
|
-
DEFAULT: 'hsl(var(--popover))',
|
|
38
|
-
foreground: 'hsl(var(--popover-foreground))',
|
|
39
|
-
},
|
|
40
|
-
card: {
|
|
41
|
-
DEFAULT: 'hsl(var(--card))',
|
|
42
|
-
foreground: 'hsl(var(--card-foreground))',
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
borderRadius: {
|
|
46
|
-
lg: 'var(--radius)',
|
|
47
|
-
md: 'calc(var(--radius) - 2px)',
|
|
48
|
-
sm: 'calc(var(--radius) - 4px)',
|
|
49
|
-
},
|
|
50
|
-
borderWidth: {
|
|
51
|
-
hairline: hairlineWidth(),
|
|
52
|
-
},
|
|
53
|
-
keyframes: {
|
|
54
|
-
'accordion-down': {
|
|
55
|
-
from: { height: '0' },
|
|
56
|
-
to: { height: 'var(--radix-accordion-content-height)' },
|
|
57
|
-
},
|
|
58
|
-
'accordion-up': {
|
|
59
|
-
from: { height: 'var(--radix-accordion-content-height)' },
|
|
60
|
-
to: { height: '0' },
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
animation: {
|
|
64
|
-
'accordion-down': 'accordion-down 0.2s ease-out',
|
|
65
|
-
'accordion-up': 'accordion-up 0.2s ease-out',
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
future: {
|
|
70
|
-
hoverOnlyWhenSupported: true,
|
|
71
|
-
},
|
|
72
|
-
plugins: [require('tailwindcss-animate')],
|
|
73
|
-
};
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { cn } from '@/lib/utils';
|
|
2
|
-
import { Slot } from '@rn-primitives/slot';
|
|
3
|
-
import { cva, type VariantProps } from 'class-variance-authority';
|
|
4
|
-
import * as React from 'react';
|
|
5
|
-
import { Platform, Text as RNText, type Role } from 'react-native';
|
|
6
|
-
|
|
7
|
-
const textVariants = cva(
|
|
8
|
-
cn(
|
|
9
|
-
'text-foreground text-base',
|
|
10
|
-
Platform.select({
|
|
11
|
-
web: 'select-text',
|
|
12
|
-
}),
|
|
13
|
-
),
|
|
14
|
-
{
|
|
15
|
-
variants: {
|
|
16
|
-
variant: {
|
|
17
|
-
default: '',
|
|
18
|
-
h1: cn(
|
|
19
|
-
'text-center text-4xl font-extrabold tracking-tight',
|
|
20
|
-
Platform.select({ web: 'scroll-m-20 text-balance' }),
|
|
21
|
-
),
|
|
22
|
-
h2: cn(
|
|
23
|
-
'border-border border-b pb-2 text-3xl font-semibold tracking-tight',
|
|
24
|
-
Platform.select({ web: 'scroll-m-20 first:mt-0' }),
|
|
25
|
-
),
|
|
26
|
-
h3: cn('text-2xl font-semibold tracking-tight', Platform.select({ web: 'scroll-m-20' })),
|
|
27
|
-
h4: cn('text-xl font-semibold tracking-tight', Platform.select({ web: 'scroll-m-20' })),
|
|
28
|
-
p: 'mt-3 leading-7 sm:mt-6',
|
|
29
|
-
blockquote: 'mt-4 border-l-2 pl-3 italic sm:mt-6 sm:pl-6',
|
|
30
|
-
code: cn(
|
|
31
|
-
'bg-muted relative rounded px-[0.3rem] py-[0.2rem] font-mono text-sm font-semibold',
|
|
32
|
-
),
|
|
33
|
-
lead: 'text-muted-foreground text-xl',
|
|
34
|
-
large: 'text-lg font-semibold',
|
|
35
|
-
small: 'text-sm font-medium leading-none',
|
|
36
|
-
muted: 'text-muted-foreground text-sm',
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
defaultVariants: {
|
|
40
|
-
variant: 'default',
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
type TextVariantProps = VariantProps<typeof textVariants>;
|
|
46
|
-
|
|
47
|
-
type TextVariant = NonNullable<TextVariantProps['variant']>;
|
|
48
|
-
|
|
49
|
-
const ROLE: Partial<Record<TextVariant, Role>> = {
|
|
50
|
-
h1: 'heading',
|
|
51
|
-
h2: 'heading',
|
|
52
|
-
h3: 'heading',
|
|
53
|
-
h4: 'heading',
|
|
54
|
-
blockquote: Platform.select({ web: 'blockquote' as Role }),
|
|
55
|
-
code: Platform.select({ web: 'code' as Role }),
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const ARIA_LEVEL: Partial<Record<TextVariant, string>> = {
|
|
59
|
-
h1: '1',
|
|
60
|
-
h2: '2',
|
|
61
|
-
h3: '3',
|
|
62
|
-
h4: '4',
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const TextClassContext = React.createContext<string | undefined>(undefined);
|
|
66
|
-
|
|
67
|
-
function Text({
|
|
68
|
-
className,
|
|
69
|
-
asChild = false,
|
|
70
|
-
variant = 'default',
|
|
71
|
-
...props
|
|
72
|
-
}: React.ComponentProps<typeof RNText> &
|
|
73
|
-
React.RefAttributes<typeof RNText> &
|
|
74
|
-
TextVariantProps & {
|
|
75
|
-
asChild?: boolean;
|
|
76
|
-
}) {
|
|
77
|
-
const textClass = React.useContext(TextClassContext);
|
|
78
|
-
const Component = asChild ? Slot : RNText;
|
|
79
|
-
return (
|
|
80
|
-
<Component
|
|
81
|
-
className={cn(textVariants({ variant }), textClass, className)}
|
|
82
|
-
role={variant ? ROLE[variant] : undefined}
|
|
83
|
-
aria-level={variant ? ARIA_LEVEL[variant] : undefined}
|
|
84
|
-
{...props}
|
|
85
|
-
/>
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export { Text, TextClassContext };
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import Purchases, { type PurchasesPackage } from 'react-native-purchases';
|
|
2
|
-
import { Platform } from 'react-native';
|
|
3
|
-
import { authClient } from './auth-client';
|
|
4
|
-
let initialized = false;
|
|
5
|
-
let pending: Promise<unknown> = Promise.resolve();
|
|
6
|
-
function serial<T>(work: () => Promise<T>) {
|
|
7
|
-
const result = pending.then(work, work);
|
|
8
|
-
pending = result.then(
|
|
9
|
-
() => undefined,
|
|
10
|
-
() => undefined,
|
|
11
|
-
);
|
|
12
|
-
return result;
|
|
13
|
-
}
|
|
14
|
-
async function subject() {
|
|
15
|
-
const session = await authClient.getSession();
|
|
16
|
-
if (!session.data) throw Error('Sign in before using purchases');
|
|
17
|
-
return session.data.user.id;
|
|
18
|
-
}
|
|
19
|
-
function publicKey() {
|
|
20
|
-
return Platform.OS === 'ios'
|
|
21
|
-
? process.env.EXPO_PUBLIC_REVENUECAT_IOS_KEY
|
|
22
|
-
: process.env.EXPO_PUBLIC_REVENUECAT_ANDROID_KEY;
|
|
23
|
-
}
|
|
24
|
-
function requiredKey() {
|
|
25
|
-
const value = publicKey();
|
|
26
|
-
if (!value) throw Error('Configure the platform public SDK key');
|
|
27
|
-
return value;
|
|
28
|
-
}
|
|
29
|
-
async function connect() {
|
|
30
|
-
const appUserID = await subject();
|
|
31
|
-
const apiKey = requiredKey();
|
|
32
|
-
if (!initialized) {
|
|
33
|
-
Purchases.configure({ apiKey, appUserID });
|
|
34
|
-
initialized = true;
|
|
35
|
-
} else await Purchases.logIn(appUserID);
|
|
36
|
-
return Purchases.getOfferings();
|
|
37
|
-
}
|
|
38
|
-
export function connectPurchases() {
|
|
39
|
-
return serial(connect);
|
|
40
|
-
}
|
|
41
|
-
export function purchase(value: PurchasesPackage) {
|
|
42
|
-
return serial(async () => {
|
|
43
|
-
await connect();
|
|
44
|
-
return Purchases.purchasePackage(value);
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
export function restorePurchases() {
|
|
48
|
-
return serial(async () => {
|
|
49
|
-
await connect();
|
|
50
|
-
return Purchases.restorePurchases();
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
export function manageSubscriptions() {
|
|
54
|
-
return serial(async () => {
|
|
55
|
-
await connect();
|
|
56
|
-
return Purchases.showManageSubscriptions();
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
export function disconnectPurchases() {
|
|
60
|
-
return serial(async () => {
|
|
61
|
-
if (initialized) await Purchases.logOut();
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
// SDK identity transitions are serialized. Callbacks update presentation only;
|
|
65
|
-
// Hono's canonical provider reconciliation owns all application access decisions.
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { Hono } from 'hono';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { timingSafeEqual } from 'node:crypto';
|
|
4
|
-
import { requireSession } from '../security';
|
|
5
|
-
import { billingEnvironment } from '../billing-mode';
|
|
6
|
-
import type { AppEnv } from '../environment';
|
|
7
|
-
export const revenuecatRoutes = new Hono<AppEnv>();
|
|
8
|
-
const hookConfig = z.object({
|
|
9
|
-
REVENUECAT_WEBHOOK_AUTH: z.string().min(1),
|
|
10
|
-
REVENUECAT_APP_ID: z.string().min(1),
|
|
11
|
-
});
|
|
12
|
-
function authorized(actual: string | undefined, expected: string) {
|
|
13
|
-
const a = new TextEncoder().encode(actual);
|
|
14
|
-
const b = new TextEncoder().encode(expected);
|
|
15
|
-
if (a.byteLength !== b.byteLength) return false;
|
|
16
|
-
return timingSafeEqual(a, b);
|
|
17
|
-
}
|
|
18
|
-
revenuecatRoutes.post('/webhooks/revenuecat', async (c) => {
|
|
19
|
-
const config = hookConfig.safeParse(c.env);
|
|
20
|
-
if (!config.success) return c.json({ error: 'Webhook needs configuration' }, 503);
|
|
21
|
-
if (!authorized(c.req.header('authorization'), config.data.REVENUECAT_WEBHOOK_AUTH))
|
|
22
|
-
return c.json({ error: 'Unauthorized' }, 401);
|
|
23
|
-
const schema = z.object({
|
|
24
|
-
event: z.object({
|
|
25
|
-
id: z.string().min(1).max(512),
|
|
26
|
-
environment: z.literal({ sandbox: 'SANDBOX', live: 'PRODUCTION' }[billingEnvironment(c.env)]),
|
|
27
|
-
app_id: z.literal(config.data.REVENUECAT_APP_ID),
|
|
28
|
-
}),
|
|
29
|
-
});
|
|
30
|
-
const body = schema.safeParse(await c.req.json().catch(() => null));
|
|
31
|
-
if (!body.success) return c.json({ error: 'Invalid webhook or scope' }, 400);
|
|
32
|
-
await c.env.DB.prepare(
|
|
33
|
-
'INSERT OR IGNORE INTO billing_receipt(provider,event_id,received_at) VALUES (?,?,?)',
|
|
34
|
-
)
|
|
35
|
-
.bind('revenuecat', body.data.event.id, Date.now())
|
|
36
|
-
.run();
|
|
37
|
-
return c.json({ received: true });
|
|
38
|
-
});
|
|
39
|
-
const statusConfig = z.object({
|
|
40
|
-
REVENUECAT_SECRET_KEY: z.string().min(1),
|
|
41
|
-
REVENUECAT_ENTITLEMENT: z.string().min(1),
|
|
42
|
-
});
|
|
43
|
-
const subscriberSchema = z.object({
|
|
44
|
-
subscriber: z.object({
|
|
45
|
-
entitlements: z.record(
|
|
46
|
-
z.string(),
|
|
47
|
-
z.object({ expires_date: z.string().nullable(), product_identifier: z.string() }),
|
|
48
|
-
),
|
|
49
|
-
subscriptions: z.record(z.string(), z.object({ is_sandbox: z.boolean() })),
|
|
50
|
-
}),
|
|
51
|
-
});
|
|
52
|
-
type Subscriber = z.infer<typeof subscriberSchema>['subscriber'];
|
|
53
|
-
const current = (expires: string | null) => expires === null || Date.parse(expires) > Date.now();
|
|
54
|
-
function entitled(subscriber: Subscriber, key: string, sandbox: boolean) {
|
|
55
|
-
const item = subscriber.entitlements[key];
|
|
56
|
-
if (!item) return false;
|
|
57
|
-
const product = subscriber.subscriptions[item.product_identifier];
|
|
58
|
-
if (!product) return false;
|
|
59
|
-
return product.is_sandbox === sandbox && current(item.expires_date);
|
|
60
|
-
}
|
|
61
|
-
export async function revenuecatEntitled(env: AppEnv['Bindings'], userId: string) {
|
|
62
|
-
const config = statusConfig.parse(env);
|
|
63
|
-
const response = await fetch(
|
|
64
|
-
'https://api.revenuecat.com/v1/subscribers/' + encodeURIComponent(userId),
|
|
65
|
-
{
|
|
66
|
-
headers: { Authorization: 'Bearer ' + config.REVENUECAT_SECRET_KEY },
|
|
67
|
-
signal: AbortSignal.timeout(10000),
|
|
68
|
-
},
|
|
69
|
-
);
|
|
70
|
-
if (!response.ok) throw Error('RevenueCat unavailable');
|
|
71
|
-
const data = subscriberSchema.parse(await response.json());
|
|
72
|
-
return entitled(
|
|
73
|
-
data.subscriber,
|
|
74
|
-
config.REVENUECAT_ENTITLEMENT,
|
|
75
|
-
billingEnvironment(env) === 'sandbox',
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
revenuecatRoutes.get('/billing/mobile-status', requireSession, async (c) => {
|
|
79
|
-
try {
|
|
80
|
-
return c.json({
|
|
81
|
-
entitled: await revenuecatEntitled(c.env, c.get('userId')),
|
|
82
|
-
provider: 'revenuecat',
|
|
83
|
-
environment: billingEnvironment(c.env),
|
|
84
|
-
});
|
|
85
|
-
} catch {
|
|
86
|
-
return c.json({ error: 'Billing needs configuration or is temporarily unavailable' }, 503);
|
|
87
|
-
}
|
|
88
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { sqliteTable, text, integer, index } from 'drizzle-orm/sqlite-core';
|
|
2
|
-
export const rtcSession = sqliteTable(
|
|
3
|
-
'rtc_session',
|
|
4
|
-
{
|
|
5
|
-
id: text('id').primaryKey(),
|
|
6
|
-
userId: text('user_id').notNull(),
|
|
7
|
-
createdAt: integer('created_at').notNull(),
|
|
8
|
-
},
|
|
9
|
-
(t) => [index('rtc_session_user_time').on(t.userId, t.createdAt)],
|
|
10
|
-
);
|
package/assets/stack/rtc.ts.txt
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { Hono, type Context } from 'hono';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { requireSession } from '../security';
|
|
4
|
-
import type { AppEnv } from '../environment';
|
|
5
|
-
export const rtcRoutes = new Hono<AppEnv>();
|
|
6
|
-
const identifier = z.string().regex(/^[a-zA-Z0-9_-]{1,128}$/);
|
|
7
|
-
const configuration = z.object({ RTC_APP_ID: identifier, RTC_APP_SECRET: z.string().min(1) });
|
|
8
|
-
const description = z.object({
|
|
9
|
-
type: z.enum(['offer', 'answer']),
|
|
10
|
-
sdp: z.string().min(1).max(128000),
|
|
11
|
-
});
|
|
12
|
-
const track = z.discriminatedUnion('location', [
|
|
13
|
-
z.object({ location: z.literal('local'), mid: identifier.optional(), trackName: identifier }),
|
|
14
|
-
z.object({ location: z.literal('remote'), sessionId: identifier, trackName: identifier }),
|
|
15
|
-
]);
|
|
16
|
-
const trackRequest = z.object({
|
|
17
|
-
sessionDescription: description.optional(),
|
|
18
|
-
tracks: z.array(track).min(1).max(10),
|
|
19
|
-
});
|
|
20
|
-
const closeRequest = z
|
|
21
|
-
.object({
|
|
22
|
-
force: z.boolean().default(false),
|
|
23
|
-
sessionDescription: description.optional(),
|
|
24
|
-
tracks: z
|
|
25
|
-
.array(z.object({ mid: identifier }))
|
|
26
|
-
.min(1)
|
|
27
|
-
.max(10),
|
|
28
|
-
})
|
|
29
|
-
.refine((value) => value.force || !!value.sessionDescription);
|
|
30
|
-
const renegotiateRequest = z.object({
|
|
31
|
-
sessionDescription: description.extend({ type: z.literal('answer') }),
|
|
32
|
-
});
|
|
33
|
-
async function provider(env: AppEnv['Bindings'], path: string, body?: unknown, method = 'POST') {
|
|
34
|
-
return fetch(
|
|
35
|
-
'https://rtc.live.cloudflare.com/v1/apps/' + encodeURIComponent(env.RTC_APP_ID!) + path,
|
|
36
|
-
{
|
|
37
|
-
method,
|
|
38
|
-
headers: {
|
|
39
|
-
Authorization: 'Bearer ' + env.RTC_APP_SECRET,
|
|
40
|
-
'Content-Type': 'application/json',
|
|
41
|
-
},
|
|
42
|
-
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
43
|
-
signal: AbortSignal.timeout(10000),
|
|
44
|
-
},
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
async function owns(c: Context<AppEnv>, id: string) {
|
|
48
|
-
return !!(await c.env.DB.prepare('SELECT id FROM rtc_session WHERE id = ? AND user_id = ?')
|
|
49
|
-
.bind(id, c.get('userId'))
|
|
50
|
-
.first());
|
|
51
|
-
}
|
|
52
|
-
rtcRoutes.use('/rtc/*', requireSession);
|
|
53
|
-
rtcRoutes.use('/rtc/*', async (c, next) => {
|
|
54
|
-
if (!configuration.safeParse(c.env).success)
|
|
55
|
-
return c.json({ error: 'Configure Cloudflare Realtime SFU first' }, 503);
|
|
56
|
-
await next();
|
|
57
|
-
});
|
|
58
|
-
rtcRoutes.use('/rtc/session/:id/*', async (c, next) => {
|
|
59
|
-
const id = identifier.safeParse(c.req.param('id'));
|
|
60
|
-
if (!id.success) return c.json({ error: 'Invalid session' }, 400);
|
|
61
|
-
if (!(await owns(c, id.data))) return c.json({ error: 'Not found' }, 404);
|
|
62
|
-
await next();
|
|
63
|
-
});
|
|
64
|
-
async function allocate(c: Context<AppEnv>, reservation: string) {
|
|
65
|
-
return c.env.DB.prepare(
|
|
66
|
-
'INSERT INTO rtc_session(id,user_id,created_at) SELECT ?,?,? WHERE (SELECT COUNT(*) FROM rtc_session WHERE user_id = ? AND created_at > ?) < 10',
|
|
67
|
-
)
|
|
68
|
-
.bind(reservation, c.get('userId'), Date.now(), c.get('userId'), Date.now() - 3600000)
|
|
69
|
-
.run();
|
|
70
|
-
}
|
|
71
|
-
async function createProviderSession(c: Context<AppEnv>) {
|
|
72
|
-
const response = await provider(c.env, '/sessions/new');
|
|
73
|
-
if (!response.ok) return null;
|
|
74
|
-
const body = (await response.json()) as { sessionId?: unknown };
|
|
75
|
-
const result = identifier.safeParse(body.sessionId);
|
|
76
|
-
return result.success ? result.data : null;
|
|
77
|
-
}
|
|
78
|
-
rtcRoutes.post('/rtc/session', async (c) => {
|
|
79
|
-
const reservation = crypto.randomUUID();
|
|
80
|
-
const quota = await allocate(c, reservation);
|
|
81
|
-
if (!quota.meta.changes) return c.json({ error: 'RTC session limit reached' }, 429);
|
|
82
|
-
// Uncertain provider failures retain the reservation for the bounded hour.
|
|
83
|
-
const sessionId = await createProviderSession(c);
|
|
84
|
-
if (!sessionId) return c.json({ error: 'RTC provider unavailable' }, 503);
|
|
85
|
-
await c.env.DB.prepare('UPDATE rtc_session SET id = ? WHERE id = ? AND user_id = ?')
|
|
86
|
-
.bind(sessionId, reservation, c.get('userId'))
|
|
87
|
-
.run();
|
|
88
|
-
return c.json({ sessionId }, 201);
|
|
89
|
-
});
|
|
90
|
-
async function operation(c: Context<AppEnv>, endpoint: string, body: unknown, method: string) {
|
|
91
|
-
const response = await provider(
|
|
92
|
-
c.env,
|
|
93
|
-
'/sessions/' + encodeURIComponent(c.req.param('id')!) + endpoint,
|
|
94
|
-
body,
|
|
95
|
-
method,
|
|
96
|
-
);
|
|
97
|
-
if (!response.ok) return c.json({ error: 'RTC operation rejected' }, 502);
|
|
98
|
-
return c.json(await response.json());
|
|
99
|
-
}
|
|
100
|
-
async function permitted(c: Context<AppEnv>, value: z.infer<typeof track>) {
|
|
101
|
-
if (value.location === 'local') return true;
|
|
102
|
-
// A multi-user product replaces this with reviewed room/membership rules.
|
|
103
|
-
return owns(c, value.sessionId);
|
|
104
|
-
}
|
|
105
|
-
rtcRoutes.post('/rtc/session/:id/tracks', async (c) => {
|
|
106
|
-
const body = trackRequest.safeParse(await c.req.json().catch(() => null));
|
|
107
|
-
if (!body.success) return c.json({ error: 'Invalid tracks' }, 400);
|
|
108
|
-
for (const value of body.data.tracks) {
|
|
109
|
-
if (!(await permitted(c, value))) return c.json({ error: 'Remote session forbidden' }, 403);
|
|
110
|
-
}
|
|
111
|
-
return operation(c, '/tracks/new', body.data, 'POST');
|
|
112
|
-
});
|
|
113
|
-
rtcRoutes.post('/rtc/session/:id/close', async (c) => {
|
|
114
|
-
const body = closeRequest.safeParse(await c.req.json().catch(() => null));
|
|
115
|
-
if (!body.success) return c.json({ error: 'Invalid close request' }, 400);
|
|
116
|
-
return operation(c, '/tracks/close', body.data, 'PUT');
|
|
117
|
-
});
|
|
118
|
-
rtcRoutes.post('/rtc/session/:id/renegotiate', async (c) => {
|
|
119
|
-
const body = renegotiateRequest.safeParse(await c.req.json().catch(() => null));
|
|
120
|
-
if (!body.success) return c.json({ error: 'Invalid SDP' }, 400);
|
|
121
|
-
return operation(c, '/renegotiate', body.data, 'PUT');
|
|
122
|
-
});
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { useState } from 'react';
|
|
3
|
-
import { authClient } from '@/lib/auth-client';
|
|
4
|
-
import { Button } from '@/components/ui/button';
|
|
5
|
-
import { Input } from '@/components/ui/input';
|
|
6
|
-
import { Label } from '@/components/ui/label';
|
|
7
|
-
export default function SignIn() {
|
|
8
|
-
const [email, setEmail] = useState('');
|
|
9
|
-
const [password, setPassword] = useState('');
|
|
10
|
-
const [message, setMessage] = useState('');
|
|
11
|
-
const [busy, setBusy] = useState(false);
|
|
12
|
-
async function submit(event: React.FormEvent<HTMLFormElement>) {
|
|
13
|
-
event.preventDefault();
|
|
14
|
-
setBusy(true);
|
|
15
|
-
try {
|
|
16
|
-
const result = await authClient.signIn.email({ email, password });
|
|
17
|
-
setMessage(result.error?.message ?? 'Signed in');
|
|
18
|
-
} catch {
|
|
19
|
-
setMessage('Unable to sign in');
|
|
20
|
-
} finally {
|
|
21
|
-
setBusy(false);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return (
|
|
25
|
-
<form onSubmit={submit} className="stack">
|
|
26
|
-
<h1>Sign in</h1>
|
|
27
|
-
<Label htmlFor="email">Email</Label>
|
|
28
|
-
<Input
|
|
29
|
-
id="email"
|
|
30
|
-
type="email"
|
|
31
|
-
autoComplete="email"
|
|
32
|
-
required
|
|
33
|
-
value={email}
|
|
34
|
-
onChange={(event) => setEmail(event.target.value)}
|
|
35
|
-
/>
|
|
36
|
-
<Label htmlFor="password">Password</Label>
|
|
37
|
-
<Input
|
|
38
|
-
id="password"
|
|
39
|
-
type="password"
|
|
40
|
-
autoComplete="current-password"
|
|
41
|
-
required
|
|
42
|
-
value={password}
|
|
43
|
-
onChange={(event) => setPassword(event.target.value)}
|
|
44
|
-
/>
|
|
45
|
-
<Button type="submit" disabled={busy}>
|
|
46
|
-
Sign in
|
|
47
|
-
</Button>
|
|
48
|
-
<p role="status">{message}</p>
|
|
49
|
-
</form>
|
|
50
|
-
);
|
|
51
|
-
}
|
package/dist/capabilities.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { StandardOptions } from './registry/types.js';
|
|
2
|
-
export declare function createSetupPlan(options: StandardOptions, registry?: import("./registry/resolve.js").ResolvedStackRegistry): {
|
|
3
|
-
schemaVersion: number;
|
|
4
|
-
cliVersion: string;
|
|
5
|
-
root: string;
|
|
6
|
-
name: string;
|
|
7
|
-
products: ("next" | "hono" | "r2" | "styling" | "d1")[];
|
|
8
|
-
dryRun: boolean;
|
|
9
|
-
registry: import("./registry/resolve.js").ResolvedStackRegistry;
|
|
10
|
-
resourcesProvisioned: boolean;
|
|
11
|
-
};
|
package/dist/capabilities.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { resolveStackRegistry } from './registry/resolve.js';
|
|
2
|
-
import { GENERATOR_VERSION } from './version.js';
|
|
3
|
-
export function createSetupPlan(options, registry = resolveStackRegistry(options)) {
|
|
4
|
-
return {
|
|
5
|
-
schemaVersion: 1,
|
|
6
|
-
cliVersion: GENERATOR_VERSION,
|
|
7
|
-
root: options.root,
|
|
8
|
-
name: options.name,
|
|
9
|
-
products: options.products,
|
|
10
|
-
dryRun: options.dryRun,
|
|
11
|
-
registry,
|
|
12
|
-
resourcesProvisioned: false,
|
|
13
|
-
};
|
|
14
|
-
}
|
package/dist/dependency-order.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/** Sort a directed dependency graph in O(vertices + edges), rejecting unresolved edges and cycles. */
|
|
2
|
-
export function dependencyOrder(graph, label) {
|
|
3
|
-
const visiting = new Set();
|
|
4
|
-
const visited = new Set();
|
|
5
|
-
const order = [];
|
|
6
|
-
const visit = (name) => {
|
|
7
|
-
if (visited.has(name))
|
|
8
|
-
return;
|
|
9
|
-
if (visiting.has(name))
|
|
10
|
-
throw new Error(`${label} dependency cycle at ${name}.`);
|
|
11
|
-
const dependencies = graph.get(name);
|
|
12
|
-
if (!dependencies)
|
|
13
|
-
throw new Error(`${label} dependency missing: ${name}.`);
|
|
14
|
-
visiting.add(name);
|
|
15
|
-
for (const dependency of dependencies)
|
|
16
|
-
visit(dependency);
|
|
17
|
-
visiting.delete(name);
|
|
18
|
-
visited.add(name);
|
|
19
|
-
order.push(name);
|
|
20
|
-
};
|
|
21
|
-
for (const name of graph.keys())
|
|
22
|
-
visit(name);
|
|
23
|
-
return order;
|
|
24
|
-
}
|
package/dist/platforms/lint.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function writeReactLintConfig(directory: string): void;
|
package/dist/platforms/lint.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { writeFile } from '../util.js';
|
|
3
|
-
export function writeReactLintConfig(directory) {
|
|
4
|
-
writeFile(path.join(directory, 'eslint.config.mjs'), 'import { config } from "@workspace/eslint-config/react-internal";\nexport default [...config, { files: ["**/*.{ts,tsx,cts}"], languageOptions: { parserOptions: { babelOptions: { babelrc: false, configFile: false, parserOpts: { plugins: ["jsx", "typescript"] } } } }, rules: { "no-undef": "off", "no-unused-vars": "off" } }];\n');
|
|
5
|
-
}
|