anhedral 0.13.0 → 0.16.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 +23 -229
- package/assets/patches/audit-deps.mjs +12 -2
- package/assets/stack/ai-schema.ts.txt +5 -0
- package/assets/stack/ai.ts.txt +30 -0
- package/assets/stack/api-index.ts.txt +15 -0
- package/assets/stack/auth-features.ts.txt +4 -0
- package/assets/stack/auth-journal.json.txt +13 -0
- package/assets/stack/auth-migration.sql.txt +53 -0
- package/assets/stack/auth-routes.ts.txt +11 -0
- package/assets/stack/auth-schema.ts.txt +64 -0
- package/assets/stack/auth-snapshot.json.txt +346 -0
- package/assets/stack/auth.ts.txt +32 -0
- package/assets/stack/billing-mode.ts.txt +8 -0
- package/assets/stack/billing-schema.ts.txt +11 -0
- package/assets/stack/desktop.rs.txt +21 -0
- package/assets/stack/entitlement-guard.ts.txt +32 -0
- package/assets/stack/entitlements.ts.txt +8 -0
- package/assets/stack/events-schema.ts.txt +12 -0
- package/assets/stack/events.ts.txt +59 -0
- package/assets/stack/mobile-auth.ts.txt +25 -0
- package/assets/stack/mobile-billing.tsx.txt +63 -0
- package/assets/stack/mobile-session.tsx.txt +83 -0
- package/assets/stack/native-button.tsx.txt +108 -0
- package/assets/stack/native-global.css.txt +4 -0
- package/assets/stack/native-lib-utils.ts.txt +5 -0
- package/assets/stack/native-metro.config.js.txt +6 -0
- package/assets/stack/native-nativewind-env.d.ts.txt +1 -0
- package/assets/stack/native-tailwind.config.js.txt +73 -0
- package/assets/stack/native-text.tsx.txt +89 -0
- package/assets/stack/purchases.ts.txt +65 -0
- package/assets/stack/revenuecat.ts.txt +88 -0
- package/assets/stack/rtc-schema.ts.txt +10 -0
- package/assets/stack/rtc.ts.txt +122 -0
- package/assets/stack/security.ts.txt +31 -0
- package/assets/stack/storage.ts.txt +36 -0
- package/assets/stack/stripe.ts.txt +126 -0
- package/assets/stack/web-sign-in.tsx.txt +51 -0
- package/assets/ui/LICENSE.react-native-reusables +21 -0
- package/assets/ui/LICENSE.shadcn +21 -0
- package/assets/ui/UPSTREAM.json +39 -0
- package/assets/ui/catalog.json +891 -0
- package/assets/ui/extensions/registry.json +6 -0
- package/assets/ui/native/_controls.tsx +521 -0
- package/assets/ui/native/_core.tsx +118 -0
- package/assets/ui/native/_data.tsx +200 -0
- package/assets/ui/native/_display.tsx +453 -0
- package/assets/ui/native/_feedback.tsx +242 -0
- package/assets/ui/native/_legacy-dialog.tsx +38 -0
- package/assets/ui/native/_motion.tsx +520 -0
- package/assets/ui/native/_overlay.tsx +402 -0
- package/assets/ui/native/_selection.tsx +366 -0
- package/assets/ui/native/accordion.tsx +1 -0
- package/assets/ui/native/alert-dialog.tsx +11 -0
- package/assets/ui/native/alert.tsx +1 -0
- package/assets/ui/native/aspect-ratio.tsx +1 -0
- package/assets/ui/native/attachment.tsx +8 -0
- package/assets/ui/native/avatar.tsx +8 -0
- package/assets/ui/native/badge.tsx +1 -0
- package/assets/ui/native/breadcrumb.tsx +9 -0
- package/assets/ui/native/bubble.tsx +1 -0
- package/assets/ui/native/button-group.tsx +1 -0
- package/assets/ui/native/button.tsx +86 -0
- package/assets/ui/native/calendar.tsx +170 -0
- package/assets/ui/native/card.tsx +44 -0
- package/assets/ui/native/carousel.tsx +1 -0
- package/assets/ui/native/chart.tsx +193 -0
- package/assets/ui/native/checkbox.tsx +1 -0
- package/assets/ui/native/code-block.tsx +137 -0
- package/assets/ui/native/collapsible.tsx +1 -0
- package/assets/ui/native/combobox.tsx +1 -0
- package/assets/ui/native/command.tsx +11 -0
- package/assets/ui/native/context-menu.tsx +16 -0
- package/assets/ui/native/data-table.tsx +1 -0
- package/assets/ui/native/date-picker.tsx +43 -0
- package/assets/ui/native/dialog.tsx +15 -0
- package/assets/ui/native/direction.tsx +1 -0
- package/assets/ui/native/drawer.tsx +10 -0
- package/assets/ui/native/dropdown-menu.tsx +16 -0
- package/assets/ui/native/empty.tsx +8 -0
- package/assets/ui/native/field.tsx +13 -0
- package/assets/ui/native/hover-card.tsx +1 -0
- package/assets/ui/native/input-group.tsx +8 -0
- package/assets/ui/native/input-otp.tsx +1 -0
- package/assets/ui/native/input.tsx +28 -0
- package/assets/ui/native/item.tsx +12 -0
- package/assets/ui/native/kbd.tsx +1 -0
- package/assets/ui/native/label.tsx +4 -0
- package/assets/ui/native/layout.tsx +26 -0
- package/assets/ui/native/marker.tsx +1 -0
- package/assets/ui/native/menubar.tsx +17 -0
- package/assets/ui/native/message-scroller.tsx +6 -0
- package/assets/ui/native/message.tsx +10 -0
- package/assets/ui/native/native-select.tsx +1 -0
- package/assets/ui/native/navigation-menu.tsx +10 -0
- package/assets/ui/native/pagination.tsx +9 -0
- package/assets/ui/native/popover.tsx +1 -0
- package/assets/ui/native/progress.tsx +1 -0
- package/assets/ui/native/questionnaire.tsx +130 -0
- package/assets/ui/native/radio-group.tsx +1 -0
- package/assets/ui/native/registry.json +1103 -0
- package/assets/ui/native/resizable.tsx +1 -0
- package/assets/ui/native/scroll-area.tsx +1 -0
- package/assets/ui/native/select.tsx +11 -0
- package/assets/ui/native/separator.tsx +1 -0
- package/assets/ui/native/sheet.tsx +10 -0
- package/assets/ui/native/sidebar.tsx +22 -0
- package/assets/ui/native/skeleton.tsx +1 -0
- package/assets/ui/native/slider.tsx +1 -0
- package/assets/ui/native/spinner.tsx +1 -0
- package/assets/ui/native/switch.tsx +1 -0
- package/assets/ui/native/table.tsx +10 -0
- package/assets/ui/native/tabs.tsx +1 -0
- package/assets/ui/native/text.tsx +20 -0
- package/assets/ui/native/textarea.tsx +1 -0
- package/assets/ui/native/theme-switcher.tsx +22 -0
- package/assets/ui/native/toast.tsx +11 -0
- package/assets/ui/native/toggle-group.tsx +1 -0
- package/assets/ui/native/toggle.tsx +1 -0
- package/assets/ui/native/tooltip.tsx +1 -0
- package/assets/ui/native/trace.tsx +20 -0
- package/assets/ui/native/typography.tsx +15 -0
- package/assets/ui/theme-storage.ts +25 -0
- package/assets/ui/theme.tsx +66 -0
- package/assets/ui/web/button.tsx +59 -0
- package/assets/ui/web/input.tsx +21 -0
- package/assets/ui/web/label.tsx +19 -0
- package/dist/bin.js +7 -12
- package/dist/capabilities.d.ts +4 -33
- package/dist/capabilities.js +2 -84
- package/dist/capability-catalog.d.ts +83 -0
- package/dist/capability-catalog.js +121 -0
- package/dist/capability-command.d.ts +3 -0
- package/dist/capability-command.js +188 -0
- package/dist/capability-editor.d.ts +17 -0
- package/dist/capability-editor.js +97 -0
- package/dist/capability-recipes.d.ts +4 -0
- package/dist/capability-recipes.js +520 -0
- package/dist/capability-references.d.ts +4 -0
- package/dist/capability-references.js +7 -0
- package/dist/cli-commands.d.ts +1 -2
- package/dist/cli-commands.js +10 -104
- package/dist/cli-output.d.ts +1 -2
- package/dist/cli-output.js +6 -251
- package/dist/command-schema.js +40 -374
- package/dist/dependencies.d.ts +34 -62
- package/dist/dependencies.js +112 -199
- package/dist/index.d.ts +1 -45
- package/dist/index.js +1 -30
- package/dist/platforms/mobile.js +29 -139
- package/dist/platforms/web.d.ts +3 -0
- package/dist/platforms/web.js +251 -0
- package/dist/project-config.d.ts +2 -13
- package/dist/project-config.js +10 -83
- package/dist/registry/context.js +0 -1
- package/dist/registry/options.js +6 -40
- package/dist/registry/resolve.d.ts +3 -4
- package/dist/registry/resolve.js +18 -108
- package/dist/registry/types.d.ts +1 -7
- package/dist/registry/usage.js +3 -9
- package/dist/runtime-policy.d.ts +0 -2
- package/dist/runtime-policy.js +0 -16
- package/dist/scaffold/backend.d.ts +0 -4
- package/dist/scaffold/backend.js +1 -189
- package/dist/scaffold/bootstrap.d.ts +2 -3
- package/dist/scaffold/bootstrap.js +37 -43
- package/dist/scaffold/compose.js +2 -14
- package/dist/scaffold/database.d.ts +1 -1
- package/dist/scaffold/database.js +19 -126
- package/dist/scaffold/documentation.d.ts +0 -1
- package/dist/scaffold/documentation.js +82 -84
- package/dist/scaffold/expo-runtime.d.ts +2 -2
- package/dist/scaffold/expo-runtime.js +9 -101
- package/dist/scaffold/native-ui.d.ts +2 -0
- package/dist/scaffold/native-ui.js +74 -0
- package/dist/scaffold/stack-documentation.d.ts +0 -1
- package/dist/scaffold/stack-documentation.js +3 -49
- package/dist/scaffold/storage.d.ts +2 -0
- package/dist/scaffold/storage.js +21 -0
- package/dist/scaffold/styling.d.ts +1 -1
- package/dist/scaffold/styling.js +20 -28
- package/dist/scaffold/workspace.js +63 -199
- package/dist/stack-registry.d.ts +2 -58
- package/dist/stack-registry.js +22 -446
- package/dist/standard.js +7 -24
- package/dist/ui-catalog.d.ts +26 -0
- package/dist/ui-catalog.js +31 -0
- package/dist/ui-command.d.ts +3 -0
- package/dist/ui-command.js +219 -0
- package/dist/ui-project.d.ts +22 -0
- package/dist/ui-project.js +110 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/anhedral-stack.md +4 -119
- package/docs/capabilities.md +110 -0
- package/docs/native-ui.md +102 -0
- package/docs/software-factory.md +16 -577
- package/docs/stack-standard.md +11 -307
- package/docs/ui.md +33 -0
- package/docs/verification.md +511 -0
- package/package.json +26 -27
- package/dist/access.d.ts +0 -10
- package/dist/access.js +0 -93
- package/dist/auth-schema-snapshot.d.ts +0 -346
- package/dist/auth-schema-snapshot.js +0 -347
- package/dist/auth-schema.d.ts +0 -1
- package/dist/auth-schema.js +0 -57
- package/dist/capability-contract.d.ts +0 -47
- package/dist/capability-contract.js +0 -168
- package/dist/catalog-model.d.ts +0 -24
- package/dist/catalog-model.js +0 -1
- package/dist/catalog-registration.d.ts +0 -16
- package/dist/catalog-registration.js +0 -22
- package/dist/catalog-snapshot.d.ts +0 -5
- package/dist/catalog-snapshot.js +0 -97
- package/dist/cli-delivery.d.ts +0 -3
- package/dist/cli-delivery.js +0 -172
- package/dist/cloudflare.d.ts +0 -25
- package/dist/cloudflare.js +0 -226
- package/dist/delivery-evidence.d.ts +0 -62
- package/dist/delivery-evidence.js +0 -186
- package/dist/delivery.d.ts +0 -88
- package/dist/delivery.js +0 -570
- package/dist/inspector-model.d.ts +0 -123
- package/dist/inspector-model.js +0 -1
- package/dist/integration-service-readers.d.ts +0 -13
- package/dist/integration-service-readers.js +0 -173
- package/dist/lifecycle-model.d.ts +0 -15
- package/dist/lifecycle-model.js +0 -20
- package/dist/lifecycle.d.ts +0 -11
- package/dist/lifecycle.js +0 -91
- package/dist/management.d.ts +0 -3
- package/dist/management.js +0 -47
- package/dist/mobile-delivery.d.ts +0 -77
- package/dist/mobile-delivery.js +0 -366
- package/dist/neon-service-data.d.ts +0 -8
- package/dist/neon-service-data.js +0 -117
- package/dist/platforms/desktop.d.ts +0 -2
- package/dist/platforms/desktop.js +0 -415
- package/dist/platforms/extension.d.ts +0 -2
- package/dist/platforms/extension.js +0 -328
- package/dist/project-catalog.d.ts +0 -41
- package/dist/project-catalog.js +0 -288
- package/dist/project-inspector.d.ts +0 -4
- package/dist/project-inspector.js +0 -702
- package/dist/project-lifecycle.d.ts +0 -25
- package/dist/project-lifecycle.js +0 -57
- package/dist/project-state.d.ts +0 -49
- package/dist/project-state.js +0 -563
- package/dist/provider-auth.d.ts +0 -41
- package/dist/provider-auth.js +0 -215
- package/dist/provider-readiness.d.ts +0 -30
- package/dist/provider-readiness.js +0 -104
- package/dist/providers/adapters.d.ts +0 -17
- package/dist/providers/adapters.js +0 -278
- package/dist/providers/api.d.ts +0 -29
- package/dist/providers/api.js +0 -253
- package/dist/providers/config.d.ts +0 -15
- package/dist/providers/config.js +0 -182
- package/dist/providers/definitions.d.ts +0 -318
- package/dist/providers/definitions.js +0 -127
- package/dist/providers/provision.d.ts +0 -24
- package/dist/providers/provision.js +0 -76
- package/dist/providers/receipts.d.ts +0 -20
- package/dist/providers/receipts.js +0 -66
- package/dist/providers/recovery-verification.d.ts +0 -7
- package/dist/providers/recovery-verification.js +0 -112
- package/dist/providers/recovery.d.ts +0 -30
- package/dist/providers/recovery.js +0 -34
- package/dist/providers/runtime.d.ts +0 -10
- package/dist/providers/runtime.js +0 -265
- package/dist/providers/schema.d.ts +0 -28
- package/dist/providers/schema.js +0 -49
- package/dist/providers/state.d.ts +0 -55
- package/dist/providers/state.js +0 -289
- package/dist/provision.d.ts +0 -55
- package/dist/provision.js +0 -284
- package/dist/r2-service-data.d.ts +0 -2
- package/dist/r2-service-data.js +0 -136
- package/dist/readiness.d.ts +0 -23
- package/dist/readiness.js +0 -122
- package/dist/registry/add.d.ts +0 -24
- package/dist/registry/add.js +0 -270
- package/dist/registry/bootstrap.d.ts +0 -2
- package/dist/registry/bootstrap.js +0 -14
- package/dist/registry/commands.d.ts +0 -3
- package/dist/registry/commands.js +0 -85
- package/dist/registry/presets.d.ts +0 -4
- package/dist/registry/presets.js +0 -41
- package/dist/registry/preview.d.ts +0 -11
- package/dist/registry/preview.js +0 -91
- package/dist/registry/receipt.d.ts +0 -3
- package/dist/registry/receipt.js +0 -68
- package/dist/repository.d.ts +0 -24
- package/dist/repository.js +0 -96
- package/dist/scaffold/auth.d.ts +0 -3
- package/dist/scaffold/auth.js +0 -151
- package/dist/scaffold/billing-config.d.ts +0 -1
- package/dist/scaffold/billing-config.js +0 -73
- package/dist/scaffold/billing-contracts.d.ts +0 -2
- package/dist/scaffold/billing-contracts.js +0 -48
- package/dist/scaffold/billing-providers.d.ts +0 -1
- package/dist/scaffold/billing-providers.js +0 -249
- package/dist/scaffold/billing-schema.d.ts +0 -1
- package/dist/scaffold/billing-schema.js +0 -34
- package/dist/scaffold/billing-security.d.ts +0 -1
- package/dist/scaffold/billing-security.js +0 -46
- package/dist/scaffold/billing-server.d.ts +0 -1
- package/dist/scaffold/billing-server.js +0 -139
- package/dist/scaffold/billing-store.d.ts +0 -1
- package/dist/scaffold/billing-store.js +0 -72
- package/dist/scaffold/billing.d.ts +0 -2
- package/dist/scaffold/billing.js +0 -216
- package/dist/scaffold/cloudflare-services.d.ts +0 -8
- package/dist/scaffold/cloudflare-services.js +0 -198
- package/dist/scaffold/expo-auth.d.ts +0 -3
- package/dist/scaffold/expo-auth.js +0 -192
- package/dist/scaffold/expo-billing.d.ts +0 -3
- package/dist/scaffold/expo-billing.js +0 -292
- package/dist/scaffold/integrations.d.ts +0 -4
- package/dist/scaffold/integrations.js +0 -12
- package/dist/scaffold/lint.d.ts +0 -4
- package/dist/scaffold/lint.js +0 -56
- package/dist/scaffold/neon-realtime.d.ts +0 -2
- package/dist/scaffold/neon-realtime.js +0 -97
- package/dist/scaffold/services.d.ts +0 -5
- package/dist/scaffold/services.js +0 -108
- package/dist/scaffold/stream.d.ts +0 -2
- package/dist/scaffold/stream.js +0 -114
- package/dist/scaffold/void.d.ts +0 -4
- package/dist/scaffold/void.js +0 -264
- package/dist/scaffold/web.d.ts +0 -2
- package/dist/scaffold/web.js +0 -130
- package/dist/service-deletion.d.ts +0 -29
- package/dist/service-deletion.js +0 -195
- package/dist/service-descriptor.d.ts +0 -10
- package/dist/service-descriptor.js +0 -78
- package/dist/service-model.d.ts +0 -49
- package/dist/service-model.js +0 -8
- package/dist/service-operations.d.ts +0 -29
- package/dist/service-operations.js +0 -78
- package/dist/service-readers.d.ts +0 -8
- package/dist/service-readers.js +0 -247
- package/dist/services-command.d.ts +0 -39
- package/dist/services-command.js +0 -102
- package/dist/ship.d.ts +0 -348
- package/dist/ship.js +0 -239
- package/dist/vercel-project.d.ts +0 -101
- package/dist/vercel-project.js +0 -305
- package/dist/vercel.d.ts +0 -67
- package/dist/vercel.js +0 -581
- package/dist/vinext.d.ts +0 -2
- package/dist/vinext.js +0 -86
- package/dist/void-execution.d.ts +0 -10
- package/dist/void-execution.js +0 -94
- package/dist/void-migrations.d.ts +0 -6
- package/dist/void-migrations.js +0 -110
- package/dist/void-state.d.ts +0 -16
- package/dist/void-state.js +0 -65
- package/dist/void.d.ts +0 -3
- package/dist/void.js +0 -5
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
import { writeEnvironmentFile } from './environment.js';
|
|
2
|
-
import { readFileSync } from 'node:fs';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { STACK_DEPENDENCIES } from '../dependencies.js';
|
|
5
|
-
import { patchPackage, put } from './files.js';
|
|
6
|
-
/** Native store purchases and web Stripe checkout share only server-verified entitlements. */
|
|
7
|
-
export function scaffoldExpoBilling({ root, has }) {
|
|
8
|
-
if (!has('expo'))
|
|
9
|
-
return;
|
|
10
|
-
const directory = 'apps/mobile';
|
|
11
|
-
if (!has('better-auth')) {
|
|
12
|
-
put(root, `${directory}/billing-integration.md`, '# Native billing integration\n\nThe selected Clerk identity needs its native session adapter before using the authenticated billing APIs. Supply verified session headers to createBillingClient from @workspace/contracts. Do not use a client-selected account ID to authorize access.\n');
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
if (has('revenuecat')) {
|
|
16
|
-
writeEnvironmentFile(root, `${directory}/.env.example`, {
|
|
17
|
-
EXPO_PUBLIC_REVENUECAT_IOS_API_KEY: '',
|
|
18
|
-
EXPO_PUBLIC_REVENUECAT_ANDROID_API_KEY: '',
|
|
19
|
-
});
|
|
20
|
-
patchPackage(root, `${directory}/package.json`, {
|
|
21
|
-
dependencies: { 'react-native-purchases': STACK_DEPENDENCIES['react-native-purchases'] },
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
put(root, `${directory}/lib/billing-api.ts`, `import { createBillingClient } from '@workspace/contracts';
|
|
25
|
-
export const billingApi = createBillingClient();
|
|
26
|
-
`);
|
|
27
|
-
put(root, `${directory}/lib/billing-api.native.ts`, `import { createBillingClient } from '@workspace/contracts';
|
|
28
|
-
import { nativeApiOrigin } from './api-client';
|
|
29
|
-
import { getAuthClient } from './auth-client.native';
|
|
30
|
-
|
|
31
|
-
function client() {
|
|
32
|
-
return createBillingClient(nativeApiOrigin() + '/api/billing', {
|
|
33
|
-
credentials: 'omit', headers: async () => {
|
|
34
|
-
const headers = new Headers();
|
|
35
|
-
headers.set('cookie', await getAuthClient().getCookie());
|
|
36
|
-
return headers;
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
export const billingApi = {
|
|
41
|
-
identity: () => client().identity(), entitlements: () => client().entitlements(),
|
|
42
|
-
refresh: () => client().refresh(), checkout: (plan: string, key: string) => client().checkout(plan, key),
|
|
43
|
-
portal: () => client().portal(),
|
|
44
|
-
};
|
|
45
|
-
`);
|
|
46
|
-
put(root, `${directory}/lib/billing-platform.ts`, `export interface StoreOffer { id: string; label: string; price: string }
|
|
47
|
-
export const billingPlatform = 'web';
|
|
48
|
-
export async function connectStore(_userId: string): Promise<void> {}
|
|
49
|
-
export async function disconnectStore(): Promise<void> {}
|
|
50
|
-
export async function storeOffers(): Promise<StoreOffer[]> { return []; }
|
|
51
|
-
export async function purchaseStoreOffer(_id: string): Promise<void> { throw new Error('Native store purchases require a device build.'); }
|
|
52
|
-
export async function restoreStorePurchases(): Promise<void> { throw new Error('Restore purchases in the native app.'); }
|
|
53
|
-
export async function manageStorePurchases(): Promise<void> { throw new Error('Native store management requires a device build.'); }
|
|
54
|
-
export function checkoutKey(): string { return crypto.randomUUID(); }
|
|
55
|
-
export async function openBillingURL(value: string): Promise<void> {
|
|
56
|
-
const url = new URL(value);
|
|
57
|
-
if (url.protocol !== 'https:') throw new Error('Billing navigation requires HTTPS.');
|
|
58
|
-
if (!['checkout.stripe.com', 'billing.stripe.com'].includes(url.hostname)) throw new Error('Unrecognized Stripe destination.');
|
|
59
|
-
globalThis.location.assign(url.href);
|
|
60
|
-
}
|
|
61
|
-
`);
|
|
62
|
-
if (has('revenuecat'))
|
|
63
|
-
put(root, `${directory}/lib/billing-platform.native.ts`, nativeStoreSource());
|
|
64
|
-
else
|
|
65
|
-
put(root, `${directory}/lib/billing-platform.native.ts`, `export type { StoreOffer } from './billing-platform';
|
|
66
|
-
export const billingPlatform = 'native';
|
|
67
|
-
export async function connectStore(_userId: string): Promise<void> {}
|
|
68
|
-
export async function disconnectStore(): Promise<void> {}
|
|
69
|
-
export async function storeOffers(): Promise<import('./billing-platform').StoreOffer[]> { return []; }
|
|
70
|
-
export async function purchaseStoreOffer(_id: string): Promise<void> { throw new Error('RevenueCat is not selected.'); }
|
|
71
|
-
export async function restoreStorePurchases(): Promise<void> { throw new Error('RevenueCat is not selected.'); }
|
|
72
|
-
export async function manageStorePurchases(): Promise<void> { throw new Error('RevenueCat is not selected.'); }
|
|
73
|
-
export function checkoutKey(): string { throw new Error('Stripe checkout is web-only.'); }
|
|
74
|
-
export async function openBillingURL(_url: string): Promise<void> { throw new Error('Stripe checkout is web-only.'); }
|
|
75
|
-
`);
|
|
76
|
-
put(root, `${directory}/app/billing.tsx`, billingScreenSource());
|
|
77
|
-
const account = `${directory}/app/account.tsx`;
|
|
78
|
-
const source = readFileSync(path.join(root, account), 'utf8');
|
|
79
|
-
const linked = source.includes('href="/billing"')
|
|
80
|
-
? source
|
|
81
|
-
: source.replace('<Link href="/">Home</Link>', '<Link href="/billing">Subscription and entitlements</Link>\n <Link href="/">Home</Link>');
|
|
82
|
-
if (linked.includes('await disconnectStore();'))
|
|
83
|
-
return;
|
|
84
|
-
put(root, account, "import { disconnectStore } from '@/lib/billing-platform';\n" +
|
|
85
|
-
linked.replace('const result = await getAuthClient().signOut();', 'await disconnectStore();\n const result = await getAuthClient().signOut();'));
|
|
86
|
-
}
|
|
87
|
-
function nativeStoreSource() {
|
|
88
|
-
return `import Purchases from 'react-native-purchases';
|
|
89
|
-
import { Linking, Platform } from 'react-native';
|
|
90
|
-
import type { StoreOffer } from './billing-platform';
|
|
91
|
-
export const billingPlatform = 'native';
|
|
92
|
-
let generation = 0;
|
|
93
|
-
let account: string | null = null;
|
|
94
|
-
let queue: Promise<void> = Promise.resolve();
|
|
95
|
-
|
|
96
|
-
function serial<T>(action: () => Promise<T>): Promise<T> {
|
|
97
|
-
const next = queue.then(action, action);
|
|
98
|
-
queue = next.then(() => undefined, () => undefined);
|
|
99
|
-
return next;
|
|
100
|
-
}
|
|
101
|
-
function platformKey(): string {
|
|
102
|
-
const keys: Partial<Record<string, string>> = {
|
|
103
|
-
ios: process.env.EXPO_PUBLIC_REVENUECAT_IOS_API_KEY,
|
|
104
|
-
android: process.env.EXPO_PUBLIC_REVENUECAT_ANDROID_API_KEY,
|
|
105
|
-
};
|
|
106
|
-
return keys[Platform.OS] ?? '';
|
|
107
|
-
}
|
|
108
|
-
function assertIdentity(token: number): void {
|
|
109
|
-
if (token !== generation) throw new Error('The signed-in account changed. Refresh subscriptions.');
|
|
110
|
-
if (!account) throw new Error('Sign in before using purchases.');
|
|
111
|
-
}
|
|
112
|
-
async function assertStoreIdentity(token: number): Promise<void> {
|
|
113
|
-
assertIdentity(token);
|
|
114
|
-
if (await Purchases.getAppUserID() !== account) throw new Error('The store account differs from the verified application account.');
|
|
115
|
-
assertIdentity(token);
|
|
116
|
-
}
|
|
117
|
-
export async function connectStore(userId: string): Promise<void> {
|
|
118
|
-
const token = ++generation;
|
|
119
|
-
account = null;
|
|
120
|
-
await serial(async () => {
|
|
121
|
-
await configureIdentity(userId);
|
|
122
|
-
if (token === generation) account = userId;
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
async function configureIdentity(userId: string): Promise<void> {
|
|
126
|
-
const apiKey = platformKey();
|
|
127
|
-
if (!apiKey) throw new Error('Configure the platform public RevenueCat SDK key and rebuild the native app.');
|
|
128
|
-
if (await Purchases.isConfigured()) await Purchases.logIn(userId);
|
|
129
|
-
else Purchases.configure({ apiKey, appUserID: userId });
|
|
130
|
-
await verifyConfiguredIdentity(userId);
|
|
131
|
-
}
|
|
132
|
-
async function verifyConfiguredIdentity(userId: string): Promise<void> {
|
|
133
|
-
if (await Purchases.getAppUserID() !== userId) throw new Error('Store identity synchronization failed.');
|
|
134
|
-
}
|
|
135
|
-
export async function disconnectStore(): Promise<void> {
|
|
136
|
-
++generation; account = null;
|
|
137
|
-
const operation = serial(async () => {
|
|
138
|
-
if (!(await Purchases.isConfigured())) return;
|
|
139
|
-
if (!(await Purchases.isAnonymous())) await Purchases.logOut();
|
|
140
|
-
});
|
|
141
|
-
await bestEffortLogout(operation);
|
|
142
|
-
}
|
|
143
|
-
async function bestEffortLogout(operation: Promise<void>): Promise<void> {
|
|
144
|
-
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
145
|
-
try {
|
|
146
|
-
await Promise.race([operation.catch(() => undefined), new Promise<void>((resolve) => { timer = setTimeout(resolve, 5000); })]);
|
|
147
|
-
} finally { clearTimeout(timer); }
|
|
148
|
-
}
|
|
149
|
-
async function availablePackages() {
|
|
150
|
-
const offerings = await Purchases.getOfferings();
|
|
151
|
-
return offerings.current?.availablePackages ?? [];
|
|
152
|
-
}
|
|
153
|
-
export async function storeOffers(): Promise<StoreOffer[]> {
|
|
154
|
-
const token = generation;
|
|
155
|
-
return serial(async () => {
|
|
156
|
-
await assertStoreIdentity(token);
|
|
157
|
-
const items = await availablePackages();
|
|
158
|
-
await assertStoreIdentity(token);
|
|
159
|
-
return items.map((item) => ({ id: item.identifier, label: item.product.title, price: item.product.priceString }));
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
export async function purchaseStoreOffer(id: string): Promise<void> {
|
|
163
|
-
const token = generation;
|
|
164
|
-
await serial(async () => {
|
|
165
|
-
await assertStoreIdentity(token);
|
|
166
|
-
const item = (await availablePackages()).find((entry) => entry.identifier === id);
|
|
167
|
-
if (!item) throw new Error('This offering is no longer available. Refresh subscriptions.');
|
|
168
|
-
await assertStoreIdentity(token);
|
|
169
|
-
await Purchases.purchasePackage(item);
|
|
170
|
-
await assertStoreIdentity(token);
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
export async function restoreStorePurchases(): Promise<void> {
|
|
174
|
-
const token = generation;
|
|
175
|
-
await serial(async () => { await assertStoreIdentity(token); await Purchases.restorePurchases(); await assertStoreIdentity(token); });
|
|
176
|
-
}
|
|
177
|
-
export async function manageStorePurchases(): Promise<void> {
|
|
178
|
-
const token = generation;
|
|
179
|
-
await serial(async () => {
|
|
180
|
-
await assertStoreIdentity(token);
|
|
181
|
-
const info = await Purchases.getCustomerInfo();
|
|
182
|
-
await assertStoreIdentity(token);
|
|
183
|
-
if (!info.managementURL) throw new Error('No store subscription management link is available.');
|
|
184
|
-
const url = new URL(info.managementURL);
|
|
185
|
-
if (url.protocol !== 'https:') throw new Error('Store management requires HTTPS.');
|
|
186
|
-
await Linking.openURL(url.href);
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
export function checkoutKey(): string { throw new Error('Stripe checkout is web-only.'); }
|
|
190
|
-
export async function openBillingURL(_url: string): Promise<void> { throw new Error('Stripe checkout is web-only.'); }
|
|
191
|
-
`;
|
|
192
|
-
}
|
|
193
|
-
function billingScreenSource() {
|
|
194
|
-
return `import { useCallback, useEffect, useRef, useState } from 'react';
|
|
195
|
-
import { Redirect } from 'expo-router';
|
|
196
|
-
import { ScrollView, Text, View } from 'react-native';
|
|
197
|
-
import type { BillingIdentity, BillingEntitlements } from '@workspace/contracts';
|
|
198
|
-
import { AuthConfiguration } from '@/components/auth-configuration';
|
|
199
|
-
import { Button } from '@/components/ui/button';
|
|
200
|
-
import { getAuthClient } from '@/lib/auth-client';
|
|
201
|
-
import { billingApi } from '@/lib/billing-api';
|
|
202
|
-
import { billingPlatform, checkoutKey, connectStore, disconnectStore, manageStorePurchases, openBillingURL, purchaseStoreOffer, restoreStorePurchases, storeOffers, type StoreOffer } from '@/lib/billing-platform';
|
|
203
|
-
|
|
204
|
-
export default function BillingRoute() { return <AuthConfiguration><Billing /></AuthConfiguration>; }
|
|
205
|
-
type Data = { identity: BillingIdentity; state: BillingEntitlements; offers: StoreOffer[] };
|
|
206
|
-
function billingError(error: unknown): string {
|
|
207
|
-
const message = error instanceof Error ? error.message : 'Billing is unavailable. Try again later.';
|
|
208
|
-
if (message === 'API request failed (409).') return 'A checkout, subscription, or billing update already exists. Retry shortly, continue your checkout, or manage your current subscription.';
|
|
209
|
-
return message;
|
|
210
|
-
}
|
|
211
|
-
function assertAccount(identity: BillingIdentity, userId: string, isCurrent: () => boolean) {
|
|
212
|
-
if (!isCurrent()) throw new Error('The signed-in account changed.');
|
|
213
|
-
if (identity.appUserId !== userId) throw new Error('The signed-in billing account changed.');
|
|
214
|
-
}
|
|
215
|
-
async function connectIdentity(identity: BillingIdentity, userId: string, isCurrent: () => boolean) {
|
|
216
|
-
assertAccount(identity, userId, isCurrent);
|
|
217
|
-
if (identity.providers.revenuecat) await connectStore(identity.appUserId);
|
|
218
|
-
assertAccount(identity, userId, isCurrent);
|
|
219
|
-
}
|
|
220
|
-
async function loadBilling(userId: string, isCurrent: () => boolean): Promise<Data> {
|
|
221
|
-
const identity = await billingApi.identity();
|
|
222
|
-
await connectIdentity(identity, userId, isCurrent);
|
|
223
|
-
const state = await billingApi.entitlements();
|
|
224
|
-
const offers = identity.providers.revenuecat ? await storeOffers() : [];
|
|
225
|
-
return { identity, state, offers };
|
|
226
|
-
}
|
|
227
|
-
function Billing() {
|
|
228
|
-
const { data: session, isPending } = getAuthClient().useSession();
|
|
229
|
-
const userId = session?.user.id;
|
|
230
|
-
const [data, setData] = useState<Data | null>(null);
|
|
231
|
-
const [message, setMessage] = useState('');
|
|
232
|
-
const [pending, setPending] = useState(false);
|
|
233
|
-
const [reload, setReload] = useState(0);
|
|
234
|
-
const attempts = useRef<Record<string, string>>({});
|
|
235
|
-
const generation = useRef(0);
|
|
236
|
-
const invalidate = useCallback(() => { ++generation.current; void disconnectStore(); }, []);
|
|
237
|
-
useEffect(() => {
|
|
238
|
-
const token = ++generation.current;
|
|
239
|
-
if (userId) void loadBilling(userId, () => token === generation.current).then(
|
|
240
|
-
(current) => { if (token === generation.current) setData(current); },
|
|
241
|
-
(error) => { if (token === generation.current) setMessage(billingError(error)); },
|
|
242
|
-
);
|
|
243
|
-
return invalidate;
|
|
244
|
-
}, [userId, reload, invalidate]);
|
|
245
|
-
function updateCurrent(token: number, action: () => void) { if (token === generation.current) action(); }
|
|
246
|
-
async function run(action: () => Promise<void>) {
|
|
247
|
-
const token = generation.current;
|
|
248
|
-
setPending(true); setMessage('');
|
|
249
|
-
try {
|
|
250
|
-
await action();
|
|
251
|
-
const state = await billingApi.refresh();
|
|
252
|
-
updateCurrent(token, () => setData((previous) => previous && { ...previous, state }));
|
|
253
|
-
} catch (error) { updateCurrent(token, () => setMessage(billingError(error))); }
|
|
254
|
-
finally { updateCurrent(token, () => setPending(false)); }
|
|
255
|
-
}
|
|
256
|
-
async function checkout(plan: string) {
|
|
257
|
-
const key = attempts.current[plan] ??= checkoutKey();
|
|
258
|
-
const result = await billingApi.checkout(plan, key);
|
|
259
|
-
await openBillingURL(result.url);
|
|
260
|
-
}
|
|
261
|
-
if (isPending) return <Text>Restoring session…</Text>;
|
|
262
|
-
if (!session) return <Redirect href="/sign-in" />;
|
|
263
|
-
return <SessionBilling userId={session.user.id} data={data} message={message} pending={pending} run={run} checkout={checkout} retry={() => setReload((value) => value + 1)} />;
|
|
264
|
-
}
|
|
265
|
-
function SessionBilling({ userId, data, message, pending, run, checkout, retry }: Actions & { userId: string; data: Data | null; message: string; checkout: (plan: string) => Promise<void>; retry: () => void }) {
|
|
266
|
-
if (data?.identity.appUserId !== userId) return <View style={{ padding: 24, gap: 12 }}><Text>{message || 'Loading subscriptions…'}</Text><Button onPress={retry}>Retry subscriptions</Button></View>;
|
|
267
|
-
return <BillingContent data={data} message={message} pending={pending} run={run} checkout={checkout} />;
|
|
268
|
-
}
|
|
269
|
-
function Entitlements({ state }: { state: BillingEntitlements }) {
|
|
270
|
-
return <View><Text accessibilityRole="header">Last server-verified access</Text>{state.entitlements.map((item) => <Text key={item.key}>{item.key}: {item.active ? 'Active' : 'Inactive'}</Text>)}<Text>Checked: {state.checkedAt}</Text></View>;
|
|
271
|
-
}
|
|
272
|
-
type Actions = { pending: boolean; run: (action: () => Promise<void>) => Promise<void> };
|
|
273
|
-
function WebPlans({ data, pending, run, checkout }: Actions & { data: Data; checkout: (plan: string) => Promise<void> }) {
|
|
274
|
-
if (!data.identity.providers.stripe) return <Text>Web checkout is not configured for this product.</Text>;
|
|
275
|
-
return <View style={{ gap: 12 }}>{data.identity.plans.map((plan) => <Button key={plan.id} disabled={pending} onPress={() => void run(() => checkout(plan.id))}>{plan.label}</Button>)}<Button disabled={pending} onPress={() => void run(async () => openBillingURL((await billingApi.portal()).url))}>Manage web subscription</Button></View>;
|
|
276
|
-
}
|
|
277
|
-
function NativePlans({ data, pending, run }: Actions & { data: Data }) {
|
|
278
|
-
if (!data.identity.providers.revenuecat) return <Text>Native store purchases are not selected.</Text>;
|
|
279
|
-
return <View style={{ gap: 12 }}>{data.offers.map((offer) => <Button key={offer.id} disabled={pending} onPress={() => void run(() => purchaseStoreOffer(offer.id))}>{offer.label + ' — ' + offer.price}</Button>)}<Button disabled={pending} onPress={() => void run(restoreStorePurchases)}>Restore purchases</Button><Button disabled={pending} onPress={() => void run(manageStorePurchases)}>Manage store subscription</Button></View>;
|
|
280
|
-
}
|
|
281
|
-
function BillingContent({ data, message, pending, run, checkout }: Actions & { data: Data; message: string; checkout: (plan: string) => Promise<void> }) {
|
|
282
|
-
return <ScrollView contentContainerStyle={{ padding: 24, gap: 16 }}>
|
|
283
|
-
<Text accessibilityRole="header">Subscriptions</Text>
|
|
284
|
-
<Entitlements state={data.state} />
|
|
285
|
-
{billingPlatform === 'web' ? <WebPlans data={data} pending={pending} run={run} checkout={checkout} /> : <NativePlans data={data} pending={pending} run={run} />}
|
|
286
|
-
<Button disabled={pending} onPress={() => void run(async () => undefined)}>Refresh server access</Button>
|
|
287
|
-
<Text accessibilityLiveRegion="polite">{message}</Text>
|
|
288
|
-
<Text>Purchases grant access only after server verification. Store account transfers follow the configured provider policy.</Text>
|
|
289
|
-
</ScrollView>;
|
|
290
|
-
}
|
|
291
|
-
`;
|
|
292
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { RecipeContext } from '../registry/types.js';
|
|
2
|
-
export declare function scaffoldPrivateFiles({ root, runtimeApp }: RecipeContext): void;
|
|
3
|
-
export declare function scaffoldStripe(context: RecipeContext): void;
|
|
4
|
-
export declare function scaffoldRevenueCat(context: RecipeContext): void;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { put } from './files.js';
|
|
2
|
-
import { scaffoldBilling } from './billing.js';
|
|
3
|
-
export function scaffoldPrivateFiles({ root, runtimeApp }) {
|
|
4
|
-
put(root, `apps/${runtimeApp}/private-files.md`, '# Private files\n\nFILES is a private R2 Worker binding. Authenticate the request and enforce file-level product authorization before calling get/put/delete. No public buckets, R2 keys, generic download endpoints, or client credentials are generated. Use the binding directly in Hono or import env from cloudflare:workers in Vinext; explicit OpenNext uses getCloudflareContext.\n');
|
|
5
|
-
}
|
|
6
|
-
export function scaffoldStripe(context) {
|
|
7
|
-
scaffoldBilling(context);
|
|
8
|
-
}
|
|
9
|
-
export function scaffoldRevenueCat(context) {
|
|
10
|
-
scaffoldBilling(context);
|
|
11
|
-
put(context.root, 'packages/billing/revenuecat.md', '# RevenueCat + Stripe\n\nConfigure web/App Store/Play Store products and offerings in client-owned accounts. Add the platform SDK to each selected app. Verify signed provider webhooks, reconcile entitlement authority, and keep transactional idempotent credits/quotas separate from subscription status. No payment activation occurs during init.\n');
|
|
12
|
-
}
|
package/dist/scaffold/lint.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
/** Fresh bootstrap only: framework-specific lint tooling belongs to its app. */
|
|
2
|
-
export declare function normalizeSharedLint(root: string): void;
|
|
3
|
-
/** Keep the starter's React/TypeScript rules and add the web app's Next API rules. */
|
|
4
|
-
export declare function writeWebLint(root: string): void;
|
package/dist/scaffold/lint.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { existsSync, rmSync } from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { json, put, readJson } from './files.js';
|
|
4
|
-
/** Fresh bootstrap only: framework-specific lint tooling belongs to its app. */
|
|
5
|
-
export function normalizeSharedLint(root) {
|
|
6
|
-
const file = 'packages/eslint-config/package.json';
|
|
7
|
-
if (!existsSync(path.join(root, file)))
|
|
8
|
-
return;
|
|
9
|
-
const manifest = readJson(root, file);
|
|
10
|
-
for (const group of [
|
|
11
|
-
'dependencies',
|
|
12
|
-
'devDependencies',
|
|
13
|
-
'peerDependencies',
|
|
14
|
-
'optionalDependencies',
|
|
15
|
-
]) {
|
|
16
|
-
const dependencies = manifest[group];
|
|
17
|
-
if (dependencies && typeof dependencies === 'object' && !Array.isArray(dependencies))
|
|
18
|
-
delete dependencies['@next/eslint-plugin-next'];
|
|
19
|
-
}
|
|
20
|
-
if (manifest.exports && typeof manifest.exports === 'object' && !Array.isArray(manifest.exports))
|
|
21
|
-
delete manifest.exports['./next-js'];
|
|
22
|
-
json(root, file, manifest);
|
|
23
|
-
rmSync(path.join(root, 'packages/eslint-config/next.js'), { force: true });
|
|
24
|
-
}
|
|
25
|
-
/** Keep the starter's React/TypeScript rules and add the web app's Next API rules. */
|
|
26
|
-
export function writeWebLint(root) {
|
|
27
|
-
put(root, 'apps/web/eslint.config.js', `import { globalIgnores } from 'eslint/config';
|
|
28
|
-
import pluginNext from '@next/eslint-plugin-next';
|
|
29
|
-
import typescriptParser from '@typescript-eslint/parser';
|
|
30
|
-
import typescriptPlugin from '@typescript-eslint/eslint-plugin';
|
|
31
|
-
import { config as reactConfig } from '@workspace/eslint-config/react-internal';
|
|
32
|
-
|
|
33
|
-
export default [
|
|
34
|
-
...reactConfig,
|
|
35
|
-
{
|
|
36
|
-
files: ['**/*.{js,jsx,mjs,cjs,ts,tsx}'],
|
|
37
|
-
languageOptions: { parser: typescriptParser, parserOptions: { ecmaFeatures: { jsx: true } } },
|
|
38
|
-
plugins: { '@typescript-eslint': typescriptPlugin },
|
|
39
|
-
rules: { 'no-unused-vars': 'off', '@typescript-eslint/no-unused-vars': 'error' },
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
files: ['**/*.{ts,tsx}'],
|
|
43
|
-
// TypeScript checks undefined names; ESLint's core rule cannot model types.
|
|
44
|
-
rules: { 'no-undef': 'off' },
|
|
45
|
-
},
|
|
46
|
-
globalIgnores(['.next/**', 'out/**', 'build/**', 'next-env.d.ts', '.open-next/**', '.wrangler/**', '.void/**', 'dist/**', 'cloudflare-env.d.ts']),
|
|
47
|
-
{
|
|
48
|
-
plugins: { '@next/next': pluginNext },
|
|
49
|
-
rules: {
|
|
50
|
-
...pluginNext.configs.recommended.rules,
|
|
51
|
-
...pluginNext.configs['core-web-vitals'].rules,
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
];
|
|
55
|
-
`);
|
|
56
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { rmSync } from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { STACK_DEPENDENCIES } from '../dependencies.js';
|
|
4
|
-
import { patchPackage, put, sharedPackage } from './files.js';
|
|
5
|
-
import { writeEnvironmentFile } from './environment.js';
|
|
6
|
-
export function scaffoldNeonRealtime({ root, options, runtimeApp }) {
|
|
7
|
-
const directory = 'packages/neon-realtime';
|
|
8
|
-
sharedPackage(root, 'neon-realtime', '', {
|
|
9
|
-
'@neon/realtime': STACK_DEPENDENCIES['@neon/realtime'],
|
|
10
|
-
'@neon/realtime-drizzle': STACK_DEPENDENCIES['@neon/realtime-drizzle'],
|
|
11
|
-
'drizzle-orm': STACK_DEPENDENCIES['drizzle-orm'],
|
|
12
|
-
});
|
|
13
|
-
rmSync(path.join(root, directory, 'src/index.ts'));
|
|
14
|
-
patchPackage(root, `${directory}/package.json`, {
|
|
15
|
-
exports: { './server': './src/server.ts', './client': './src/client.ts' },
|
|
16
|
-
});
|
|
17
|
-
put(root, `${directory}/src/server.ts`, `import { createRealtime } from '@neon/realtime/server';
|
|
18
|
-
import { drizzleAdapter } from '@neon/realtime-drizzle';
|
|
19
|
-
|
|
20
|
-
function databaseName(connectionString: string): string {
|
|
21
|
-
let database: string;
|
|
22
|
-
try {
|
|
23
|
-
const url = new URL(connectionString);
|
|
24
|
-
if (!['postgres:', 'postgresql:'].includes(url.protocol)) throw new Error();
|
|
25
|
-
database = decodeURIComponent(url.pathname.slice(1));
|
|
26
|
-
if (!/^[^/]+$/.test(database)) throw new Error();
|
|
27
|
-
} catch {
|
|
28
|
-
throw new Error('Configure a PostgreSQL DATABASE_URL with the intended database name.');
|
|
29
|
-
}
|
|
30
|
-
return database;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Import this entry point only from server code. Sealing is local Web Crypto work.
|
|
34
|
-
export function createNeonRealtime(options: { secret: string; databaseUrl: string }) {
|
|
35
|
-
if (!options.secret.trim()) throw new Error('Configure the branch NEON_REALTIME_SECRET on the server.');
|
|
36
|
-
return createRealtime({ secret: options.secret, db: databaseName(options.databaseUrl), adapter: drizzleAdapter() });
|
|
37
|
-
}
|
|
38
|
-
`);
|
|
39
|
-
put(root, `${directory}/src/client.ts`, `import { createRealtimeClient } from '@neon/realtime/client';
|
|
40
|
-
import { drizzleParsers } from '@neon/realtime-drizzle/client';
|
|
41
|
-
|
|
42
|
-
export type { SealedLiveQuery, LiveQuerySnapshot, LiveQueryState } from '@neon/realtime/client';
|
|
43
|
-
|
|
44
|
-
// One client per database; close it on sign-out and unsubscribe on component cleanup.
|
|
45
|
-
export function createNeonRealtimeClient(url: string) {
|
|
46
|
-
return createRealtimeClient({ url, parsers: { ...drizzleParsers } });
|
|
47
|
-
}
|
|
48
|
-
`);
|
|
49
|
-
const app = `apps/${runtimeApp}`;
|
|
50
|
-
const native = runtimeApp === 'web' && options.hosting === 'vercel';
|
|
51
|
-
writeEnvironmentFile(root, `${app}/${native ? '.env.example' : '.dev.vars.example'}`, {
|
|
52
|
-
NEON_REALTIME_SECRET: '',
|
|
53
|
-
});
|
|
54
|
-
if (!native)
|
|
55
|
-
put(root, `${app}/${runtimeApp === 'api' ? 'src/' : ''}neon-realtime-secrets.d.ts`, runtimeApp === 'api'
|
|
56
|
-
? 'interface Env { NEON_REALTIME_SECRET: string }\n'
|
|
57
|
-
: 'declare namespace Cloudflare { interface Env { NEON_REALTIME_SECRET: string } }\n');
|
|
58
|
-
put(root, `${directory}/README.md`, neonRealtimeGuide);
|
|
59
|
-
}
|
|
60
|
-
const neonRealtimeGuide = `# Neon Realtime (beta)
|
|
61
|
-
|
|
62
|
-
This package streams PostgreSQL SELECT results through Neon's managed Realtime service. It shares packages/db and does not create a second database or Worker. The separate --realtime option creates Cloudflare Durable Object WebSocket rooms; both options can coexist.
|
|
63
|
-
|
|
64
|
-
## Branch setup
|
|
65
|
-
|
|
66
|
-
Enable Realtime on the intended Neon branch using the Neon Console or neon realtime enable. This is a manual operation; Anhedral's Neon database provisioning does not enable Realtime. Check beta availability first: aws-us-east-1, aws-us-east-2, aws-eu-central-1 and aws-ap-southeast-1 (reviewed 2026-10-16). Claimed projects only. Enabling Realtime requires logical replication; review this change before applying it. Configure the service's allowedOrigins for the exact development and production browser origins.
|
|
67
|
-
|
|
68
|
-
Copy that branch's NEON_REALTIME_SECRET into the selected server app's ignored runtime file using its generated environment example. Use .env.local for native Next.js on Vercel, .env for Void, or .dev.vars for Wrangler. For anhedral ship, use file permissions 0600. Keep the database URL and secret on the server, in the same branch/environment. The root .env.example is an inventory, not an automatically loaded runtime file. Store all Anhedral project settings in the existing anhedral.json; no additional provider config file is needed.
|
|
69
|
-
|
|
70
|
-
NEON_REALTIME_URL is a public transport URL from the branch's Realtime page. Pass it explicitly to the client factory or expose only that URL through the frontend's public build environment (NEXT_PUBLIC_NEON_REALTIME_URL for web; use the platform's public prefix elsewhere). Never prefix the secret or DATABASE_URL with NEXT_PUBLIC_, VITE_ or EXPO_PUBLIC_. No public sealing route is generated.
|
|
71
|
-
|
|
72
|
-
## Server integration
|
|
73
|
-
|
|
74
|
-
Add @workspace/neon-realtime and @workspace/db as workspace:* dependencies of the server app when implementing product routes. Import createNeonRealtime from @workspace/neon-realtime/server and createDatabase from @workspace/db. Pass { secret: env.NEON_REALTIME_SECRET, databaseUrl: env.DATABASE_URL } to createNeonRealtime; use the existing database factory to build Drizzle selects. The Realtime adapter compiles queries without executing them through the HTTP driver; normal writes and migrations still use packages/db.
|
|
75
|
-
|
|
76
|
-
Authenticate each sealing request with the selected identity system. Validate request parameters, derive the user identity from the verified session, and build a bounded SELECT scoped to that user's rows or membership joins. Then call await realtime.seal({ query }) and return its JSON with Cache-Control: private, no-store over HTTPS. Do not accept SQL or an owner ID from the browser, cache sealed queries across users, or expose secret-bearing configuration. Recheck authentication and authorization on every renewal. Never subscribe to auth/session/credential tables.
|
|
77
|
-
|
|
78
|
-
Tables need stable replica identity (normally a primary key). Queries must be read-only and deterministic: functions such as now() cannot be used in live selects. Selected Drizzle keys must match SQL result column names; alias camelCase/computed fields explicitly. Use drizzleParsers from this package's client factory so dates/timestamps agree with Drizzle's types. RLS is not supported in the beta: put access rules in the query itself, including live membership joins when immediate membership revocation is required.
|
|
79
|
-
|
|
80
|
-
## Client lifecycle
|
|
81
|
-
|
|
82
|
-
Add @workspace/neon-realtime as a workspace:* dependency of each client app. Import createNeonRealtimeClient and the SealedLiveQuery row type from @workspace/neon-realtime/client. This entry point contains no server factory, ORM or credentials. Create one client per database with the public URL. Fetch a sealed query from your authenticated endpoint, then call client.subscribe(sealedQuery) and subscription.onChange(render). Snapshots include connecting/live/stale/error/closed state; surface errors and stale data in the UI.
|
|
83
|
-
|
|
84
|
-
Capabilities currently expire after 60 seconds. Schedule an authenticated refresh before expiresAt and call subscription.renew(next); use the returned expiry for the next refresh. A changed query or parameters require a new subscription. Stop renewal timers and call subscription.unsubscribe() on unmount; close the shared client on sign-out to clear subscriptions and user data. Treat terminal errors separately from reconnects. Sealed queries are bearer credentials until expiry: keep them out of URLs, logs and persistent browser storage. The optional upstream React and TanStack bindings can manage renewal; they are not dependencies of this framework-neutral package.
|
|
85
|
-
|
|
86
|
-
## Acceptance
|
|
87
|
-
|
|
88
|
-
Test two users with disjoint rows, denied/expired sessions and renewal, membership removal during a subscription, query/parameter changes, stale/error states, reconnects and cleanup. Apply reviewed schema migrations separately. No service is enabled or deployed by init. The beta transport may change and has no performance guarantees. Realtime is free during beta, but database compute and egress can incur charges.
|
|
89
|
-
|
|
90
|
-
Official references:
|
|
91
|
-
|
|
92
|
-
- https://neon.com/docs/realtime/overview
|
|
93
|
-
- https://neon.com/docs/realtime/quickstart
|
|
94
|
-
- https://neon.com/docs/realtime/guides/queries
|
|
95
|
-
- https://neon.com/docs/realtime/guides/subscribing
|
|
96
|
-
- https://neon.com/docs/realtime/examples/drizzle
|
|
97
|
-
`;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { RecipeContext } from '../registry/types.js';
|
|
2
|
-
export declare function scaffoldRealtime({ root, options }: RecipeContext): void;
|
|
3
|
-
export declare function scaffoldQueues({ root, options }: RecipeContext): void;
|
|
4
|
-
export declare function scaffoldCron({ root, options }: RecipeContext): void;
|
|
5
|
-
export declare function scaffoldWorkflows({ root, options }: RecipeContext): void;
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { resourceName } from '../render.js';
|
|
2
|
-
import { workerConfig, worker } from './files.js';
|
|
3
|
-
export function scaffoldRealtime({ root, options }) {
|
|
4
|
-
worker(root, 'realtime', {
|
|
5
|
-
...workerConfig(resourceName(options.name, 'realtime')),
|
|
6
|
-
durable_objects: { bindings: [{ name: 'ROOMS', class_name: 'Room' }] },
|
|
7
|
-
migrations: [{ tag: 'v1', new_sqlite_classes: ['Room'] }],
|
|
8
|
-
}, `import { DurableObject } from 'cloudflare:workers';
|
|
9
|
-
export class Room extends DurableObject<Env> {
|
|
10
|
-
async fetch(request: Request): Promise<Response> {
|
|
11
|
-
if (request.headers.get('Upgrade')?.toLowerCase() !== 'websocket') {
|
|
12
|
-
return new Response('WebSocket required', { status: 426 });
|
|
13
|
-
}
|
|
14
|
-
const pair = new WebSocketPair();
|
|
15
|
-
this.ctx.acceptWebSocket(pair[1]);
|
|
16
|
-
return new Response(null, { status: 101, webSocket: pair[0] });
|
|
17
|
-
}
|
|
18
|
-
webSocketMessage(sender: WebSocket, message: string | ArrayBuffer) {
|
|
19
|
-
const size = typeof message === 'string'
|
|
20
|
-
? new TextEncoder().encode(message).byteLength
|
|
21
|
-
: message.byteLength;
|
|
22
|
-
if (size > 16384) {
|
|
23
|
-
sender.close(1009, 'Message too large');
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
this.#broadcastToPeers(sender, message);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
#broadcastToPeers(sender: WebSocket, message: string | ArrayBuffer) {
|
|
30
|
-
for (const socket of this.ctx.getWebSockets()) {
|
|
31
|
-
if (socket !== sender) socket.send(message);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
export default {
|
|
36
|
-
async fetch(): Promise<Response> {
|
|
37
|
-
// Authenticate and authorize room membership, then forward to env.ROOMS.getByName(room).fetch(request).
|
|
38
|
-
// Use short-lived single-use tickets for browser WebSockets. Never expose a long-lived service secret.
|
|
39
|
-
return new Response('Configure room authorization before enabling connections', { status: 501 });
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
`);
|
|
43
|
-
}
|
|
44
|
-
export function scaffoldQueues({ root, options }) {
|
|
45
|
-
worker(root, 'jobs', {
|
|
46
|
-
...workerConfig(resourceName(options.name, 'jobs')),
|
|
47
|
-
queues: {
|
|
48
|
-
producers: [{ binding: 'JOBS', queue: resourceName(options.name, 'jobs') }],
|
|
49
|
-
consumers: [
|
|
50
|
-
{
|
|
51
|
-
queue: resourceName(options.name, 'jobs'),
|
|
52
|
-
max_batch_size: 10,
|
|
53
|
-
max_retries: 3,
|
|
54
|
-
dead_letter_queue: resourceName(options.name, 'jobs-dlq'),
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
|
-
},
|
|
58
|
-
}, `export default {
|
|
59
|
-
async queue(batch: MessageBatch<unknown>): Promise<void> {
|
|
60
|
-
for (const message of batch.messages) {
|
|
61
|
-
// Add transactional idempotency and product processing before acknowledging.
|
|
62
|
-
console.error('Job handler requires product implementation', message.id);
|
|
63
|
-
message.retry({ delaySeconds: 60 });
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
};
|
|
67
|
-
`);
|
|
68
|
-
}
|
|
69
|
-
export function scaffoldCron({ root, options }) {
|
|
70
|
-
worker(root, 'scheduled', {
|
|
71
|
-
...workerConfig(resourceName(options.name, 'scheduled')),
|
|
72
|
-
triggers: { crons: ['0 * * * *'] },
|
|
73
|
-
}, `export default {
|
|
74
|
-
async scheduled(controller: ScheduledController): Promise<void> {
|
|
75
|
-
// Define a product schedule, idempotency key, overlap policy, and failure alerts before release.
|
|
76
|
-
console.log('Scheduled trigger', controller.scheduledTime);
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
`);
|
|
80
|
-
}
|
|
81
|
-
export function scaffoldWorkflows({ root, options }) {
|
|
82
|
-
worker(root, 'workflows', {
|
|
83
|
-
...workerConfig(resourceName(options.name, 'workflows')),
|
|
84
|
-
workflows: [
|
|
85
|
-
{
|
|
86
|
-
name: resourceName(options.name, 'workflow'),
|
|
87
|
-
binding: 'WORKFLOW',
|
|
88
|
-
class_name: 'ApplicationWorkflow',
|
|
89
|
-
},
|
|
90
|
-
],
|
|
91
|
-
}, `import { WorkflowEntrypoint, type WorkflowEvent, type WorkflowStep } from 'cloudflare:workers';
|
|
92
|
-
export class ApplicationWorkflow extends WorkflowEntrypoint<Env, { operationId: string }> {
|
|
93
|
-
async run(event: WorkflowEvent<{ operationId: string }>, step: WorkflowStep) {
|
|
94
|
-
return step.do('validate', { retries: { limit: 3, delay: '10 seconds', backoff: 'exponential' } }, async () => {
|
|
95
|
-
if (typeof event.payload.operationId !== 'string' || !event.payload.operationId) {
|
|
96
|
-
throw new Error('operationId required');
|
|
97
|
-
}
|
|
98
|
-
return { operationId: event.payload.operationId };
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
export default {
|
|
103
|
-
async fetch() {
|
|
104
|
-
return new Response('Use an authorized server binding to create workflows', { status: 403 });
|
|
105
|
-
},
|
|
106
|
-
};
|
|
107
|
-
`);
|
|
108
|
-
}
|