anhedral 0.10.1 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/README.md +79 -124
  2. package/assets/patches/LICENSE.braces +21 -0
  3. package/assets/patches/LICENSE.node-forge +50 -0
  4. package/assets/patches/audit-deps.mjs +167 -0
  5. package/assets/patches/braces@3.0.3.patch +127 -0
  6. package/assets/patches/node-forge@1.4.0.patch +41 -0
  7. package/dist/auth-schema.js +3 -3
  8. package/dist/bin.js +284 -163
  9. package/dist/capabilities.d.ts +4 -4
  10. package/dist/capabilities.js +6 -2
  11. package/dist/capability-contract.d.ts +47 -0
  12. package/dist/capability-contract.js +153 -0
  13. package/dist/catalog-model.d.ts +24 -0
  14. package/dist/catalog-model.js +1 -0
  15. package/dist/catalog-registration.d.ts +16 -0
  16. package/dist/catalog-registration.js +22 -0
  17. package/dist/catalog-snapshot.d.ts +5 -0
  18. package/dist/catalog-snapshot.js +97 -0
  19. package/dist/cli-arguments.d.ts +16 -0
  20. package/dist/cli-arguments.js +115 -0
  21. package/dist/cli-output.d.ts +8 -0
  22. package/dist/cli-output.js +236 -0
  23. package/dist/cloudflare.d.ts +14 -3
  24. package/dist/cloudflare.js +196 -36
  25. package/dist/command-schema.d.ts +21 -0
  26. package/dist/command-schema.js +418 -0
  27. package/dist/delivery.d.ts +12 -5
  28. package/dist/delivery.js +173 -39
  29. package/dist/dependencies.d.ts +24 -0
  30. package/dist/dependencies.js +48 -0
  31. package/dist/dependency-patches.d.ts +7 -0
  32. package/dist/dependency-patches.js +125 -0
  33. package/dist/index.d.ts +26 -1
  34. package/dist/index.js +17 -1
  35. package/dist/inspector-model.d.ts +123 -0
  36. package/dist/inspector-model.js +1 -0
  37. package/dist/integration-service-readers.d.ts +13 -0
  38. package/dist/integration-service-readers.js +173 -0
  39. package/dist/lifecycle-model.d.ts +15 -0
  40. package/dist/lifecycle-model.js +20 -0
  41. package/dist/lifecycle.d.ts +11 -0
  42. package/dist/lifecycle.js +91 -0
  43. package/dist/mobile-delivery.d.ts +100 -0
  44. package/dist/mobile-delivery.js +319 -0
  45. package/dist/neon-service-data.d.ts +8 -0
  46. package/dist/neon-service-data.js +117 -0
  47. package/dist/platforms/mobile.js +8 -5
  48. package/dist/pnpm-policy.d.ts +2 -2
  49. package/dist/pnpm-policy.js +19 -45
  50. package/dist/project-catalog.d.ts +41 -0
  51. package/dist/project-catalog.js +288 -0
  52. package/dist/project-config.d.ts +14 -0
  53. package/dist/project-config.js +89 -0
  54. package/dist/project-inspector.d.ts +4 -0
  55. package/dist/project-inspector.js +702 -0
  56. package/dist/project-lifecycle.d.ts +25 -0
  57. package/dist/project-lifecycle.js +57 -0
  58. package/dist/project-state.d.ts +22 -1
  59. package/dist/project-state.js +361 -27
  60. package/dist/provider-auth.d.ts +41 -0
  61. package/dist/provider-auth.js +209 -0
  62. package/dist/provider-readiness.js +27 -10
  63. package/dist/providers/adapters.d.ts +17 -0
  64. package/dist/providers/adapters.js +272 -0
  65. package/dist/providers/api.d.ts +29 -0
  66. package/dist/providers/api.js +253 -0
  67. package/dist/providers/config.d.ts +15 -0
  68. package/dist/providers/config.js +182 -0
  69. package/dist/providers/definitions.d.ts +318 -0
  70. package/dist/providers/definitions.js +127 -0
  71. package/dist/providers/provision.d.ts +24 -0
  72. package/dist/providers/provision.js +76 -0
  73. package/dist/providers/receipts.d.ts +20 -0
  74. package/dist/providers/receipts.js +66 -0
  75. package/dist/providers/recovery-verification.d.ts +7 -0
  76. package/dist/providers/recovery-verification.js +112 -0
  77. package/dist/providers/recovery.d.ts +30 -0
  78. package/dist/providers/recovery.js +34 -0
  79. package/dist/providers/runtime.d.ts +10 -0
  80. package/dist/providers/runtime.js +254 -0
  81. package/dist/providers/schema.d.ts +28 -0
  82. package/dist/providers/schema.js +49 -0
  83. package/dist/providers/state.d.ts +55 -0
  84. package/dist/providers/state.js +289 -0
  85. package/dist/provision.d.ts +10 -1
  86. package/dist/provision.js +91 -4
  87. package/dist/r2-service-data.d.ts +2 -0
  88. package/dist/r2-service-data.js +136 -0
  89. package/dist/readiness.js +9 -13
  90. package/dist/registry/add.d.ts +6 -0
  91. package/dist/registry/add.js +93 -22
  92. package/dist/registry/commands.d.ts +3 -2
  93. package/dist/registry/commands.js +52 -15
  94. package/dist/registry/options.d.ts +1 -1
  95. package/dist/registry/options.js +5 -4
  96. package/dist/registry/preview.d.ts +11 -0
  97. package/dist/registry/preview.js +91 -0
  98. package/dist/registry/receipt.d.ts +1 -0
  99. package/dist/registry/receipt.js +19 -4
  100. package/dist/registry/resolve.js +5 -1
  101. package/dist/registry/usage.d.ts +10 -0
  102. package/dist/registry/usage.js +18 -37
  103. package/dist/render.d.ts +2 -0
  104. package/dist/render.js +6 -0
  105. package/dist/runtime-policy.d.ts +4 -0
  106. package/dist/runtime-policy.js +21 -0
  107. package/dist/scaffold/auth.js +3 -19
  108. package/dist/scaffold/bootstrap.js +2 -2
  109. package/dist/scaffold/compose.js +9 -3
  110. package/dist/scaffold/database.js +107 -25
  111. package/dist/scaffold/documentation.js +18 -13
  112. package/dist/scaffold/lint.d.ts +4 -0
  113. package/dist/scaffold/lint.js +56 -0
  114. package/dist/scaffold/neon-realtime.d.ts +2 -0
  115. package/dist/scaffold/neon-realtime.js +97 -0
  116. package/dist/scaffold/stack-documentation.js +1 -1
  117. package/dist/scaffold/void.d.ts +4 -0
  118. package/dist/scaffold/void.js +256 -0
  119. package/dist/scaffold/web.js +7 -1
  120. package/dist/scaffold/workspace.js +127 -25
  121. package/dist/service-deletion.d.ts +29 -0
  122. package/dist/service-deletion.js +195 -0
  123. package/dist/service-descriptor.d.ts +10 -0
  124. package/dist/service-descriptor.js +78 -0
  125. package/dist/service-model.d.ts +49 -0
  126. package/dist/service-model.js +8 -0
  127. package/dist/service-operations.d.ts +29 -0
  128. package/dist/service-operations.js +78 -0
  129. package/dist/service-readers.d.ts +8 -0
  130. package/dist/service-readers.js +247 -0
  131. package/dist/services-command.d.ts +39 -0
  132. package/dist/services-command.js +100 -0
  133. package/dist/ship.d.ts +348 -0
  134. package/dist/ship.js +237 -0
  135. package/dist/stack-registry.d.ts +4 -2
  136. package/dist/stack-registry.js +48 -12
  137. package/dist/standard.d.ts +2 -1
  138. package/dist/standard.js +33 -14
  139. package/dist/transaction.d.ts +2 -0
  140. package/dist/transaction.js +10 -0
  141. package/dist/util.js +17 -2
  142. package/dist/vercel.d.ts +5 -3
  143. package/dist/vercel.js +96 -14
  144. package/dist/version.d.ts +1 -1
  145. package/dist/version.js +1 -1
  146. package/dist/vinext.d.ts +1 -0
  147. package/dist/vinext.js +13 -1
  148. package/dist/void-execution.d.ts +10 -0
  149. package/dist/void-execution.js +94 -0
  150. package/dist/void-migrations.d.ts +6 -0
  151. package/dist/void-migrations.js +110 -0
  152. package/dist/void-state.d.ts +16 -0
  153. package/dist/void-state.js +65 -0
  154. package/dist/void.d.ts +3 -0
  155. package/dist/void.js +5 -0
  156. package/docs/cli-design.md +67 -0
  157. package/docs/delivery-workflow.md +32 -17
  158. package/docs/plugin-ui.md +102 -0
  159. package/docs/provider-configuration.md +116 -0
  160. package/docs/stack-standard.md +175 -0
  161. package/docs/void-verification.md +185 -0
  162. package/package.json +29 -23
  163. package/assets/anhedral-cli-init-technical.svg +0 -322
  164. package/assets/anhedral-cli-init.svg +0 -322
  165. package/assets/anhedral-mark.svg +0 -4
  166. package/assets/anhedral.svg +0 -4
  167. package/assets/favicon.ico +0 -0
  168. package/assets/security/LICENSES.txt +0 -63
  169. package/assets/security/audit-deps.mjs +0 -300
  170. package/assets/security/braces-regression.mjs +0 -102
  171. package/assets/security/braces@3.0.3.patch +0 -285
  172. package/assets/security/decode-uri-component@0.2.2.patch +0 -149
  173. package/assets/security/decoder-regression.mjs +0 -37
  174. package/assets/security/forge-regression.mjs +0 -46
  175. package/assets/security/manifest.json +0 -53
  176. package/assets/security/node-forge@1.4.0.patch +0 -26
  177. package/dist/managed-hosting.d.ts +0 -49
  178. package/dist/managed-hosting.js +0 -373
  179. package/dist/security-backports.d.ts +0 -3
  180. package/dist/security-backports.js +0 -26
  181. package/docs/application-stack-standard.md +0 -104
  182. package/docs/managed-hosting-architecture.md +0 -87
  183. package/docs/sponsorships.md +0 -25
package/dist/index.js CHANGED
@@ -4,11 +4,27 @@ export { CAPABILITIES, CAPABILITY_REGISTRY, createSetupPlan } from './capabiliti
4
4
  export { inspectProject, validateSetupPlan } from './readiness.js';
5
5
  export { registerApplication, readApplication, connectApplication, planDelivery, shipApplication, applicationStatus, verifyApplication, rollbackApplication, recoverApplication, } from './delivery.js';
6
6
  export { planProvisioning, provisionApplication } from './provision.js';
7
+ export { supportsVoidRuntime, VOID_VERSION, VOID_NODE_ENGINE } from './void.js';
7
8
  export { registerVercelApplication, connectVercelApplication, planVercelDelivery, shipVercelApplication, vercelApplicationStatus, verifyVercelApplication, rollbackVercelApplication, adoptVercelApplication, recoverVercelApplication, } from './vercel.js';
8
9
  export { setupRepository, githubRepository } from './repository.js';
9
10
  export { inspectProviderReadiness } from './provider-readiness.js';
10
- export { registerManagedApplication, stageManagedVersion, saveManagedVersion, deployManagedVersion, managedApplicationStatus, } from './managed-hosting.js';
11
11
  export { STACK_REGISTRY, STACK_ITEMS, getStackItem } from './stack-registry.js';
12
12
  export { inspectWorkspaceGraph } from './workspace-graph.js';
13
13
  export { resolveStackRegistry } from './registry/resolve.js';
14
14
  export { addStackItems } from './registry/add.js';
15
+ export { PROVIDER_AUTH, requiredProviders, authenticateProviders } from './provider-auth.js';
16
+ export { buildMobileApplication } from './mobile-delivery.js';
17
+ export { shipCloudflareApplication } from './ship.js';
18
+ export { shipSelectedStack, shipSelectedVercelApplication } from './ship.js';
19
+ export { planProviderProvisioning, provisionSelectedProviders } from './providers/provision.js';
20
+ export { providerConfigurationTemplate } from './providers/config.js';
21
+ export { validateProviderConfiguration } from './providers/config.js';
22
+ export { PROVIDER_CONFIGURATION_SCHEMA } from './providers/schema.js';
23
+ export { PROVIDER_DEFINITIONS } from './providers/definitions.js';
24
+ export { applicationRuntime } from './providers/runtime.js';
25
+ export { readLifecycleOperation } from './lifecycle.js';
26
+ export { integrationStatus, recoverIntegrationResource } from './providers/recovery.js';
27
+ export { CAPABILITY_CONTRACT, formatCapabilityContract } from './capability-contract.js';
28
+ export { recoverDeliveryLock } from './project-state.js';
29
+ export { inspectApplication } from './project-inspector.js';
30
+ export { PROJECT_CONFIG_FILE, readProjectConfig, readProjectSection, writeProjectSection, hasProjectSection, } from './project-config.js';
@@ -0,0 +1,123 @@
1
+ import type { LifecycleOperation } from './lifecycle-model.js';
2
+ export interface InspectionSection<T> {
3
+ state: 'available' | 'unavailable';
4
+ data: T;
5
+ error?: string;
6
+ }
7
+ export type DependencyField = 'dependencies' | 'devDependencies' | 'peerDependencies' | 'optionalDependencies';
8
+ export interface WorkspaceEvidence {
9
+ name: string;
10
+ directory: string;
11
+ dependencies: {
12
+ name: string;
13
+ kind: DependencyField;
14
+ }[];
15
+ }
16
+ export interface BindingEvidence {
17
+ application: string;
18
+ name: string;
19
+ kind: string;
20
+ configured: boolean;
21
+ identifierRequired: boolean;
22
+ resourceId: string | null;
23
+ }
24
+ export interface ReleaseEvidence {
25
+ id: string;
26
+ state: string;
27
+ commit: string;
28
+ recordedAt: string | null;
29
+ url: string | null;
30
+ kind: 'deployment' | 'build';
31
+ operationState?: string;
32
+ platform?: string;
33
+ profile?: string;
34
+ artifact?: string;
35
+ }
36
+ export interface TargetEvidence {
37
+ id: string;
38
+ provider: 'cloudflare' | 'vercel' | 'expo' | 'desktop' | 'extension';
39
+ application: string;
40
+ audience: 'public' | 'private' | 'unconfigured' | 'not-applicable';
41
+ accountReference: string | null;
42
+ latestAttempt: ReleaseEvidence | null;
43
+ lastSuccessful: ReleaseEvidence | null;
44
+ delivery: 'implemented' | 'artifact-only' | 'scaffold-only';
45
+ liveStatus: 'unknown';
46
+ error?: string;
47
+ }
48
+ export interface IntegrationEvidence {
49
+ provider: string;
50
+ operations: {
51
+ operation: string;
52
+ status: 'pending' | 'complete';
53
+ resources: Record<string, string>;
54
+ recovery: string;
55
+ kind: string | null;
56
+ }[];
57
+ }
58
+ export interface ResourceEvidence {
59
+ kind: string;
60
+ name: string;
61
+ id: string;
62
+ reused: boolean | null;
63
+ createdByProject?: boolean | null;
64
+ recordedAt: string | null;
65
+ }
66
+ /** Browser-safe projection. Read time never substitutes for provider evidence time. */
67
+ export interface ProjectInspection {
68
+ schemaVersion: 1;
69
+ lifecycle?: import('./project-lifecycle.js').ProjectLifecycle;
70
+ name: string;
71
+ inspectedAt: string;
72
+ authentication: {
73
+ state: 'not-checked';
74
+ };
75
+ liveStatus: {
76
+ state: 'unknown';
77
+ };
78
+ limits: string[];
79
+ selection: InspectionSection<{
80
+ cliVersion: string | null;
81
+ products: string[];
82
+ hosting: 'cloudflare' | 'vercel' | null;
83
+ }>;
84
+ setupProviders: InspectionSection<{
85
+ id: string;
86
+ managementCredential: string | null;
87
+ ownerSteps: string[];
88
+ authentication: 'not-checked';
89
+ permissions: 'unknown';
90
+ billing: 'unknown';
91
+ }[]>;
92
+ workspaces: InspectionSection<WorkspaceEvidence[]>;
93
+ configuration: InspectionSection<{
94
+ bindings: BindingEvidence[];
95
+ schedules: {
96
+ application: string;
97
+ expression: string;
98
+ }[];
99
+ environment: {
100
+ application: string;
101
+ name: string;
102
+ }[];
103
+ }>;
104
+ targets: InspectionSection<TargetEvidence[]>;
105
+ integrations: InspectionSection<IntegrationEvidence[]>;
106
+ cloudflareResources: InspectionSection<ResourceEvidence[]>;
107
+ serviceDeletions?: InspectionSection<{
108
+ resourceId: string;
109
+ kind: string;
110
+ name: string;
111
+ state: 'pending' | 'deleted' | 'uncertain';
112
+ recordedAt: string | null;
113
+ }[]>;
114
+ readiness: InspectionSection<{
115
+ localReady: boolean;
116
+ checks: {
117
+ id: string;
118
+ ok: boolean;
119
+ detail: string;
120
+ }[];
121
+ }>;
122
+ operation: InspectionSection<LifecycleOperation | null>;
123
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ import { type IntegrationProvider, type ProviderSettings } from './providers/config.js';
2
+ import { type ApiRequest } from './providers/api.js';
3
+ import type { ServiceMetrics, ServiceObservation } from './service-model.js';
4
+ export interface IntegrationService {
5
+ provider: IntegrationProvider;
6
+ settings: ProviderSettings;
7
+ resources: Record<string, string>;
8
+ }
9
+ export declare function resolveIntegrationService(root: string, key: string): IntegrationService;
10
+ export declare function integrationRequest(service: IntegrationService, env?: NodeJS.ProcessEnv, send?: typeof fetch): ApiRequest;
11
+ export declare function inspectIntegrationResource(service: IntegrationService, api: ApiRequest): Promise<Record<string, unknown>>;
12
+ export declare function observeIntegrationService(service: IntegrationService, api: ApiRequest): Promise<ServiceObservation>;
13
+ export declare function posthogServiceMetrics(service: IntegrationService, api: ApiRequest, hours?: number): Promise<ServiceMetrics>;
@@ -0,0 +1,173 @@
1
+ import { inspectApplication } from './project-inspector.js';
2
+ import { providerConfiguration, setting, } from './providers/config.js';
3
+ import { INTEGRATION_PROVIDERS } from './providers/definitions.js';
4
+ import { providerApi, ProviderRequestError, resourceId } from './providers/api.js';
5
+ import { record } from './service-readers.js';
6
+ export function resolveIntegrationService(root, key) {
7
+ const inspection = inspectApplication(root);
8
+ const match = key.match(/^(provider|integration):([a-z]+)(?::(.+))?$/);
9
+ if (!match ||
10
+ !INTEGRATION_PROVIDERS.includes(match[2]) ||
11
+ !inspection.setupProviders.data.some((provider) => provider.id === match[2]))
12
+ throw new Error('Choose a selected integration service.');
13
+ const provider = match[2];
14
+ let resources = {};
15
+ if (match[1] === 'integration') {
16
+ const operation = inspection.integrations.data
17
+ .find((entry) => entry.provider === provider)
18
+ ?.operations.find((entry) => entry.operation === match[3]);
19
+ if (!operation || operation.status !== 'complete')
20
+ throw new Error('The integration operation is not complete.');
21
+ resources = operation.resources;
22
+ }
23
+ const settings = providerConfiguration(root).providers[provider];
24
+ if (!settings)
25
+ throw new Error('Complete the selected provider configuration.');
26
+ return { provider, settings, resources };
27
+ }
28
+ export function integrationRequest(service, env = process.env, send = fetch) {
29
+ return providerApi(service.provider, service.settings, env, send, {
30
+ maxAttempts: 1,
31
+ totalTimeoutMs: 10000,
32
+ attemptTimeoutMs: 10000,
33
+ });
34
+ }
35
+ function selected(service, field, receipt) {
36
+ const configured = setting(service.settings, field);
37
+ const recorded = service.resources[receipt];
38
+ if (configured && recorded && configured !== recorded)
39
+ throw new Error('Configured and recorded integration identities differ.');
40
+ return resourceId(configured || recorded);
41
+ }
42
+ export async function inspectIntegrationResource(service, api) {
43
+ const { provider, settings } = service;
44
+ let value;
45
+ let expected;
46
+ let returned;
47
+ if (provider === 'neon') {
48
+ expected = selected(service, 'projectId', 'project');
49
+ value = record(record(await api(`/api/v2/projects/${expected}`)).project);
50
+ returned = value.id;
51
+ if (value.org_id !== setting(settings, 'organizationId'))
52
+ throw new Error('Neon organization differs.');
53
+ }
54
+ else if (provider === 'clerk') {
55
+ if (record(await api('/v1/platform/me')).subject !== setting(settings, 'workspaceId'))
56
+ throw new Error('Clerk workspace differs.');
57
+ expected = selected(service, 'applicationId', 'application');
58
+ value = record(await api(`/v1/platform/applications/${expected}?include_secret_keys=false`));
59
+ returned = value.application_id;
60
+ }
61
+ else if (provider === 'resend') {
62
+ expected = selected(service, 'domainId', 'domain');
63
+ value = record(await api(`/domains/${expected}`));
64
+ returned = value.id;
65
+ if (value.name !== setting(settings, 'domain'))
66
+ throw new Error('Resend domain differs.');
67
+ }
68
+ else if (provider === 'stripe') {
69
+ if (record(await api('/v1/account')).id !== setting(settings, 'accountId'))
70
+ throw new Error('Stripe account differs.');
71
+ expected = resourceId(service.resources.webhook);
72
+ value = record(await api(`/v1/webhook_endpoints/${expected}`));
73
+ returned = value.id;
74
+ if (value.livemode !== (setting(settings, 'mode') === 'live') ||
75
+ value.url !== setting(settings, 'webhookUrl'))
76
+ throw new Error('Stripe environment or webhook differs.');
77
+ }
78
+ else if (provider === 'revenuecat') {
79
+ expected = selected(service, 'projectId', 'project');
80
+ value = record(await api(`/v2/projects/${expected}`));
81
+ returned = value.id;
82
+ }
83
+ else if (provider === 'sentry') {
84
+ const organization = resourceId(setting(settings, 'organization'));
85
+ const slug = resourceId(setting(settings, 'project'));
86
+ value = record(await api(`/api/0/projects/${organization}/${slug}/`));
87
+ expected = resourceId(service.resources.project ?? value.id);
88
+ returned = value.id;
89
+ if (record(value.organization).slug !== organization || value.slug !== slug)
90
+ throw new Error('Sentry organization or project differs.');
91
+ }
92
+ else if (provider === 'posthog') {
93
+ expected = selected(service, 'projectId', 'project');
94
+ const organization = resourceId(setting(settings, 'organizationId'));
95
+ value = record(await api(`/api/organizations/${organization}/projects/${expected}/`));
96
+ returned = String(value.id);
97
+ if (value.organization !== organization)
98
+ throw new Error('PostHog organization differs.');
99
+ }
100
+ else {
101
+ expected = selected(service, 'projectId', 'project');
102
+ value = record(await api(`/v1/organization/projects/${expected}`));
103
+ returned = value.id;
104
+ }
105
+ if (String(returned) !== expected)
106
+ throw new Error('Provider resource identity differs.');
107
+ return value;
108
+ }
109
+ export async function observeIntegrationService(service, api) {
110
+ const fetchedAt = new Date().toISOString();
111
+ try {
112
+ const value = await inspectIntegrationResource(service, api);
113
+ const name = typeof value.name === 'string' && value.name.length <= 256 ? value.name : undefined;
114
+ return {
115
+ state: 'available',
116
+ fetchedAt,
117
+ ...(name ? { name } : {}),
118
+ message: 'Provider confirmed the selected resource and account context. Application health is separate.',
119
+ };
120
+ }
121
+ catch (error) {
122
+ const status = error instanceof ProviderRequestError ? error.status : undefined;
123
+ return {
124
+ state: status === 404
125
+ ? 'not-found'
126
+ : status === 401 || status === 403
127
+ ? 'permission-required'
128
+ : 'unavailable',
129
+ fetchedAt,
130
+ message: 'Selected integration could not be verified. Check account configuration, identity and scoped permissions.',
131
+ };
132
+ }
133
+ }
134
+ export async function posthogServiceMetrics(service, api, hours = 24) {
135
+ if (service.provider !== 'posthog' || ![1, 24, 168].includes(hours))
136
+ throw new Error('Unsupported analytics selection.');
137
+ await inspectIntegrationResource(service, api);
138
+ const end = new Date().toISOString();
139
+ const start = new Date(Date.parse(end) - hours * 3600000).toISOString();
140
+ const id = selected(service, 'projectId', 'project');
141
+ const date = (value) => value.slice(0, 19).replace('T', ' ');
142
+ const value = record(await api(`/api/projects/${id}/query/`, 'POST', {
143
+ query: {
144
+ kind: 'HogQLQuery',
145
+ query: `SELECT formatDateTime(timestamp, '%Y-%m-%dT%H:00:00Z', 'UTC') AS time, count() AS events, uniqExact(distinct_id) AS visitors FROM events WHERE timestamp >= toDateTime('${date(start)}', 'UTC') AND timestamp < toDateTime('${date(end)}', 'UTC') GROUP BY time ORDER BY time LIMIT 1000`,
146
+ },
147
+ name: 'Anhedral selected-project hourly analytics',
148
+ async: false,
149
+ }));
150
+ if (!Array.isArray(value.results) || value.results.length >= 1000)
151
+ throw new Error('Analytics is pending, truncated or unavailable.');
152
+ const points = value.results.map((row) => {
153
+ if (!Array.isArray(row) ||
154
+ row.length !== 3 ||
155
+ typeof row[0] !== 'string' ||
156
+ !Number.isFinite(Date.parse(row[0])) ||
157
+ row
158
+ .slice(1)
159
+ .some((count) => typeof count !== 'number' || !Number.isFinite(count) || count < 0))
160
+ throw new Error('Unsupported analytics output.');
161
+ return { time: row[0], values: { events: row[1], visitors: row[2] } };
162
+ });
163
+ return {
164
+ start,
165
+ end,
166
+ fetchedAt: new Date().toISOString(),
167
+ source: 'PostHog hourly product analytics',
168
+ timezone: 'UTC',
169
+ sampled: false,
170
+ points,
171
+ units: { events: 'count', visitors: 'hourly bucket count' },
172
+ };
173
+ }
@@ -0,0 +1,15 @@
1
+ export type OperationState = 'running' | 'blocked' | 'completed' | 'failed';
2
+ export type PhaseState = 'running' | 'completed' | 'failed';
3
+ export interface LifecycleOperation {
4
+ schemaVersion: 1;
5
+ id: string;
6
+ target: 'cloudflare' | 'vercel' | 'mixed' | 'mobile';
7
+ state: OperationState;
8
+ startedAt: string;
9
+ updatedAt: string;
10
+ phases: {
11
+ name: string;
12
+ state: PhaseState;
13
+ }[];
14
+ }
15
+ export declare function isLifecycleOperation(value: unknown): value is LifecycleOperation;
@@ -0,0 +1,20 @@
1
+ export function isLifecycleOperation(value) {
2
+ if (!value || typeof value !== 'object' || Array.isArray(value))
3
+ return false;
4
+ const operation = value;
5
+ return (operation.schemaVersion === 1 &&
6
+ typeof operation.id === 'string' &&
7
+ /^[a-f0-9-]{36}$/.test(operation.id) &&
8
+ ['cloudflare', 'vercel', 'mixed', 'mobile'].includes(operation.target) &&
9
+ ['running', 'blocked', 'completed', 'failed'].includes(operation.state) &&
10
+ [operation.startedAt, operation.updatedAt].every((date) => typeof date === 'string' && Number.isFinite(Date.parse(date))) &&
11
+ Array.isArray(operation.phases) &&
12
+ operation.phases.length <= 100 &&
13
+ operation.phases.every((phase) => phase &&
14
+ typeof phase.name === 'string' &&
15
+ /^[a-z][a-z-]{0,63}$/.test(phase.name) &&
16
+ ['running', 'completed', 'failed'].includes(phase.state)) &&
17
+ new Set(operation.phases.map((phase) => phase.name)).size === operation.phases.length &&
18
+ Object.keys(operation).every((key) => ['schemaVersion', 'id', 'target', 'state', 'startedAt', 'updatedAt', 'phases'].includes(key)) &&
19
+ operation.phases.every((phase) => Object.keys(phase).every((key) => ['name', 'state'].includes(key))));
20
+ }
@@ -0,0 +1,11 @@
1
+ import { type DeliveryRunner } from './project-state.js';
2
+ import { type LifecycleOperation } from './lifecycle-model.js';
3
+ export type { LifecycleOperation, OperationState, PhaseState } from './lifecycle-model.js';
4
+ export interface LifecycleSession {
5
+ phase<T>(name: string, action: () => Promise<T>): Promise<T>;
6
+ }
7
+ /** A nonsecret record of execution; a completed phase is not product acceptance. */
8
+ export declare function readLifecycleOperation(root: string): LifecycleOperation | null;
9
+ export declare function withLifecycleOperation<T>(root: string, target: LifecycleOperation['target'], run: DeliveryRunner, action: (session: LifecycleSession) => Promise<T>): Promise<T & {
10
+ operation: LifecycleOperation;
11
+ }>;
@@ -0,0 +1,91 @@
1
+ import path from 'node:path';
2
+ import { existsSync, lstatSync, realpathSync } from 'node:fs';
3
+ import { randomUUID } from 'node:crypto';
4
+ import { readBoundedFile, MAX_PROJECT_JSON_BYTES } from './bounded-file.js';
5
+ import { atomicJson, withApplicationLock } from './project-state.js';
6
+ import { isLifecycleOperation } from './lifecycle-model.js';
7
+ /** A nonsecret record of execution; a completed phase is not product acceptance. */
8
+ export function readLifecycleOperation(root) {
9
+ root = realpathSync(root);
10
+ const file = path.join(root, '.anhedral/operation.json');
11
+ if (!existsSync(file))
12
+ return null;
13
+ if (realpathSync(path.dirname(file)) !== path.join(root, '.anhedral') ||
14
+ lstatSync(file).isSymbolicLink())
15
+ throw new Error('Invalid lifecycle state location.');
16
+ let value;
17
+ try {
18
+ value = JSON.parse(readBoundedFile(file, MAX_PROJECT_JSON_BYTES).toString('utf8'));
19
+ }
20
+ catch {
21
+ throw new Error('Invalid lifecycle state.');
22
+ }
23
+ if (!isLifecycleOperation(value))
24
+ throw new Error('Invalid lifecycle state.');
25
+ return value;
26
+ }
27
+ export async function withLifecycleOperation(root, target, run, action) {
28
+ root = realpathSync(root);
29
+ const env = { ...process.env, CI: '1', NO_COLOR: '1' };
30
+ const relative = '.anhedral/operation.json';
31
+ if ((await run('git', ['ls-files', '--', relative], root, env)).trim() ||
32
+ (await run('git', ['check-ignore', '--no-index', '--', relative], root, env)).trim() !==
33
+ relative)
34
+ throw new Error('Ignore .anhedral/ before recording a shipping operation.');
35
+ return withApplicationLock(root, async () => {
36
+ readLifecycleOperation(root);
37
+ const now = new Date().toISOString();
38
+ const operation = {
39
+ schemaVersion: 1,
40
+ id: randomUUID(),
41
+ target,
42
+ state: 'running',
43
+ startedAt: now,
44
+ updatedAt: now,
45
+ phases: [],
46
+ };
47
+ const save = () => {
48
+ operation.updatedAt = new Date().toISOString();
49
+ atomicJson(path.join(root, relative), operation);
50
+ };
51
+ save();
52
+ const session = {
53
+ async phase(name, task) {
54
+ if (!/^[a-z][a-z-]{0,63}$/.test(name) ||
55
+ operation.phases.some((phase) => phase.name === name) ||
56
+ operation.phases.length >= 100)
57
+ throw new Error('Invalid or duplicate lifecycle phase.');
58
+ const phase = { name, state: 'running' };
59
+ operation.phases.push(phase);
60
+ save();
61
+ try {
62
+ const result = await task();
63
+ phase.state = 'completed';
64
+ save();
65
+ return result;
66
+ }
67
+ catch (error) {
68
+ phase.state = 'failed';
69
+ save();
70
+ throw error;
71
+ }
72
+ },
73
+ };
74
+ try {
75
+ const result = await action(session);
76
+ const state = result && typeof result === 'object' && 'state' in result ? result.state : undefined;
77
+ operation.state = ['partial', 'failed'].includes(String(state))
78
+ ? 'failed'
79
+ : ['configuration-required', 'provider-configuration-required', 'building'].includes(String(state))
80
+ ? 'blocked'
81
+ : 'completed';
82
+ save();
83
+ return Object.assign({}, result, { operation });
84
+ }
85
+ catch (error) {
86
+ operation.state = 'failed';
87
+ save();
88
+ throw error;
89
+ }
90
+ });
91
+ }
@@ -0,0 +1,100 @@
1
+ import { type DeliveryRunner } from './project-state.js';
2
+ export interface MobileBuildOptions {
3
+ platform: 'ios' | 'android';
4
+ profile: string;
5
+ dryRun?: boolean;
6
+ }
7
+ /** EAS builds produce artifacts; store submission is a separate user action. */
8
+ export declare function buildMobileApplication(root: string, options: MobileBuildOptions, run?: DeliveryRunner): Promise<{
9
+ commit: string;
10
+ platform: "android" | "ios";
11
+ profile: string;
12
+ buildId: any;
13
+ downloadUrl: string;
14
+ state: string;
15
+ storeSubmission: boolean;
16
+ artifact: string;
17
+ buildPageUrl?: string | undefined;
18
+ schemaVersion: number;
19
+ projectId: string;
20
+ owner: any;
21
+ slug: any;
22
+ recordedAt: string;
23
+ } | {
24
+ platform: "android" | "ios";
25
+ profile: string;
26
+ command: string[];
27
+ mutation: boolean;
28
+ storeSubmission: boolean;
29
+ integrations: {
30
+ schemaVersion: number;
31
+ providers: {
32
+ provider: keyof import("./index.js").ProviderSettingsById;
33
+ settings: import("./providers/definitions.js").NeonSettings | import("./providers/definitions.js").ClerkSettings | import("./providers/definitions.js").ResendSettings | import("./providers/definitions.js").StripeSettings | import("./providers/definitions.js").RevenueCatSettings | import("./providers/definitions.js").SentrySettings | import("./providers/definitions.js").PostHogSettings | import("./providers/definitions.js").OpenAISettings;
34
+ credential: string;
35
+ missing: string[];
36
+ }[];
37
+ configured: boolean;
38
+ mutation: boolean;
39
+ };
40
+ state?: undefined;
41
+ deployed?: undefined;
42
+ nextAction?: undefined;
43
+ schemaVersion?: undefined;
44
+ buildId?: undefined;
45
+ buildPageUrl?: undefined;
46
+ commit?: undefined;
47
+ } | {
48
+ state: string;
49
+ deployed: boolean;
50
+ integrations: {
51
+ schemaVersion: number;
52
+ results: {
53
+ provider: string;
54
+ resources: Record<string, string>;
55
+ ready: boolean;
56
+ nextActions: string[];
57
+ }[];
58
+ ready: boolean;
59
+ configuredFiles: string[];
60
+ mutation: boolean;
61
+ };
62
+ storeSubmission: boolean;
63
+ platform?: undefined;
64
+ profile?: undefined;
65
+ command?: undefined;
66
+ mutation?: undefined;
67
+ nextAction?: undefined;
68
+ schemaVersion?: undefined;
69
+ buildId?: undefined;
70
+ buildPageUrl?: undefined;
71
+ commit?: undefined;
72
+ } | {
73
+ state: string;
74
+ deployed: boolean;
75
+ storeSubmission: boolean;
76
+ nextAction: string;
77
+ platform?: undefined;
78
+ profile?: undefined;
79
+ command?: undefined;
80
+ mutation?: undefined;
81
+ integrations?: undefined;
82
+ schemaVersion?: undefined;
83
+ buildId?: undefined;
84
+ buildPageUrl?: undefined;
85
+ commit?: undefined;
86
+ } | {
87
+ schemaVersion: number;
88
+ state: string;
89
+ buildId: any;
90
+ buildPageUrl: string;
91
+ commit: string;
92
+ platform: "android" | "ios";
93
+ profile: string;
94
+ storeSubmission: boolean;
95
+ nextAction: string;
96
+ command?: undefined;
97
+ mutation?: undefined;
98
+ integrations?: undefined;
99
+ deployed?: undefined;
100
+ }>;