@amerged/ohmyhost-cli 0.1.56 → 0.1.57
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 +1 -1
- package/dist/bin.js +1 -1
- package/dist/{chunk-HNFWXGDN.js → chunk-GODV5QDC.js} +579 -76
- package/dist/index.js +7 -1
- package/package.json +1 -1
- package/src/apps/product-cli/package.json +1 -1
- package/src/apps/product-cli/src/cli.ts +150 -11
- package/src/apps/product-cli/src/command.ts +185 -4
- package/src/apps/product-cli/src/product-api.ts +126 -3
- package/src/apps/product-cli/src/repository-init.ts +8 -0
- package/src/apps/product-cli/src/runtime-contract.ts +43 -5
- package/src/apps/product-cli/src/user-token-file.ts +73 -0
- package/src/packages/contracts/src/credit-pricing.ts +1 -1
- package/src/packages/contracts/src/database-events.ts +67 -0
- package/src/packages/contracts/src/framework-admission.ts +5 -4
- package/src/packages/contracts/src/framework-source-rules.ts +9 -2
- package/src/packages/contracts/src/index.ts +9 -0
- package/src/packages/contracts/src/operation-deployment-result.ts +121 -1
- package/src/packages/contracts/src/operation-failure.ts +72 -1
- package/src/packages/contracts/src/problem-policy.ts +13 -1
- package/src/packages/contracts/src/secret-names.ts +3 -2
- package/src/packages/sdk-ts/package.json +1 -1
- package/src/packages/sdk-ts/src/generated/index.ts +30 -0
- package/src/packages/sdk-ts/src/generated/sdk.gen.ts +216 -2
- package/src/packages/sdk-ts/src/generated/types.gen.ts +370 -1
|
@@ -46,6 +46,8 @@ import {
|
|
|
46
46
|
assertDatabaseWatchDeleted,
|
|
47
47
|
assertDatabaseWatchPage,
|
|
48
48
|
assertDatabaseWebhookTest,
|
|
49
|
+
assertDatabaseWebhookSubscription,
|
|
50
|
+
assertDatabaseWebhookSubscriptionActivation,
|
|
49
51
|
type DatabaseExecutionUsagePage,
|
|
50
52
|
type DatabaseSchedule,
|
|
51
53
|
type DatabaseScheduleDeleted,
|
|
@@ -65,6 +67,9 @@ import {
|
|
|
65
67
|
type DatabaseWebhookPage,
|
|
66
68
|
type DatabaseWebhookReplayAccepted,
|
|
67
69
|
type DatabaseWebhookTestResult,
|
|
70
|
+
type DatabaseWebhookCreateRequest,
|
|
71
|
+
type DatabaseWebhookSubscription,
|
|
72
|
+
type DatabaseWebhookSubscriptionActivation,
|
|
68
73
|
} from "@ohmyhost/contracts/database-events";
|
|
69
74
|
import type { DatabaseComputeSelection } from "@ohmyhost/contracts/database-sizes";
|
|
70
75
|
import {
|
|
@@ -128,6 +133,7 @@ import {
|
|
|
128
133
|
setProjectPoweredByFlag,
|
|
129
134
|
createDeployment,
|
|
130
135
|
createProject,
|
|
136
|
+
addProjectDevelopmentEnvironment,
|
|
131
137
|
planProjectDataChange,
|
|
132
138
|
createProjectDataChange,
|
|
133
139
|
submitFeedback,
|
|
@@ -175,6 +181,9 @@ import {
|
|
|
175
181
|
listProjectDatabaseAccess,
|
|
176
182
|
revokeProjectDatabaseAccess,
|
|
177
183
|
createProjectDatabaseWebhook,
|
|
184
|
+
activateDatabaseWebhookSubscription,
|
|
185
|
+
deactivateDatabaseWebhookSubscription,
|
|
186
|
+
getDatabaseWebhookSubscription,
|
|
178
187
|
listProjectDatabaseWebhooks,
|
|
179
188
|
getProjectDatabaseWebhook,
|
|
180
189
|
deleteProjectDatabaseWebhook,
|
|
@@ -232,10 +241,17 @@ export interface ProjectCreateInput {
|
|
|
232
241
|
readonly name: string;
|
|
233
242
|
readonly dataMode?: "shared" | "isolated";
|
|
234
243
|
readonly devAccessMode?: "protected" | "public";
|
|
244
|
+
readonly includeDevelopmentEnvironment?: boolean;
|
|
235
245
|
readonly region?: "us" | "eu";
|
|
236
246
|
readonly idempotencyKey: string;
|
|
237
247
|
}
|
|
238
248
|
|
|
249
|
+
interface WebhookSubscriptionScope {
|
|
250
|
+
readonly projectId: string;
|
|
251
|
+
readonly environment: "dev" | "prod";
|
|
252
|
+
readonly subscriptionId: string;
|
|
253
|
+
}
|
|
254
|
+
|
|
239
255
|
/** One column of a table to create; nullable, identity and default are optional as the REST body allows. */
|
|
240
256
|
export interface DatabaseTableColumnInput {
|
|
241
257
|
readonly name: string;
|
|
@@ -400,6 +416,22 @@ export interface ProductApi {
|
|
|
400
416
|
readonly eventTypes: readonly DatabaseWebhookEventPattern[];
|
|
401
417
|
readonly headers: Readonly<Record<string, string>>;
|
|
402
418
|
}): Promise<DatabaseWebhookCreated>;
|
|
419
|
+
getDatabaseWebhookSubscription(
|
|
420
|
+
input: WebhookSubscriptionScope,
|
|
421
|
+
): Promise<DatabaseWebhookSubscription>;
|
|
422
|
+
activateDatabaseWebhookSubscription(
|
|
423
|
+
input: WebhookSubscriptionScope & {
|
|
424
|
+
readonly generation: number;
|
|
425
|
+
readonly idempotencyKey: string;
|
|
426
|
+
readonly request: DatabaseWebhookCreateRequest;
|
|
427
|
+
},
|
|
428
|
+
): Promise<DatabaseWebhookSubscriptionActivation>;
|
|
429
|
+
deactivateDatabaseWebhookSubscription(
|
|
430
|
+
input: WebhookSubscriptionScope & {
|
|
431
|
+
readonly generation: number;
|
|
432
|
+
readonly idempotencyKey: string;
|
|
433
|
+
},
|
|
434
|
+
): Promise<DatabaseWebhookSubscription>;
|
|
403
435
|
listProjectDatabaseWebhooks(input: {
|
|
404
436
|
readonly projectId: string;
|
|
405
437
|
readonly environment: "dev" | "prod";
|
|
@@ -543,6 +575,10 @@ export interface ProductApi {
|
|
|
543
575
|
cursor?: string,
|
|
544
576
|
): Promise<import("@ohmyhost/sdk-ts").FeedbackStatus>;
|
|
545
577
|
createProject(input: ProjectCreateInput): Promise<Operation>;
|
|
578
|
+
addProjectDevelopmentEnvironment(input: {
|
|
579
|
+
readonly projectId: string;
|
|
580
|
+
readonly idempotencyKey: string;
|
|
581
|
+
}): Promise<Operation>;
|
|
546
582
|
getOperation(operationId: string): Promise<Operation>;
|
|
547
583
|
reconcileOperation(input: {
|
|
548
584
|
readonly operationId: string;
|
|
@@ -585,7 +621,7 @@ export interface ProductApi {
|
|
|
585
621
|
planDeployment(input: {
|
|
586
622
|
readonly projectId: string;
|
|
587
623
|
readonly commitSha: string;
|
|
588
|
-
readonly environment
|
|
624
|
+
readonly environment?: "dev" | "prod";
|
|
589
625
|
}): Promise<DeploymentPlan>;
|
|
590
626
|
createDeployment(input: {
|
|
591
627
|
readonly projectId: string;
|
|
@@ -1150,6 +1186,77 @@ export class GeneratedSdkProductApi implements ProductApi {
|
|
|
1150
1186
|
return value;
|
|
1151
1187
|
}
|
|
1152
1188
|
|
|
1189
|
+
public async getDatabaseWebhookSubscription(
|
|
1190
|
+
input: WebhookSubscriptionScope,
|
|
1191
|
+
): Promise<DatabaseWebhookSubscription> {
|
|
1192
|
+
const value = await getDatabaseWebhookSubscription(
|
|
1193
|
+
{
|
|
1194
|
+
project_id: input.projectId,
|
|
1195
|
+
environment: input.environment,
|
|
1196
|
+
subscription_id: input.subscriptionId,
|
|
1197
|
+
},
|
|
1198
|
+
{ client: this.#client },
|
|
1199
|
+
);
|
|
1200
|
+
assertDatabaseWebhookSubscription(value);
|
|
1201
|
+
if (value.id !== input.subscriptionId || value.environment !== input.environment)
|
|
1202
|
+
throw new TypeError(WEBHOOK_SCOPE_MISMATCH);
|
|
1203
|
+
return value;
|
|
1204
|
+
}
|
|
1205
|
+
public async activateDatabaseWebhookSubscription(
|
|
1206
|
+
input: WebhookSubscriptionScope & {
|
|
1207
|
+
generation: number;
|
|
1208
|
+
idempotencyKey: string;
|
|
1209
|
+
request: DatabaseWebhookCreateRequest;
|
|
1210
|
+
},
|
|
1211
|
+
): Promise<DatabaseWebhookSubscriptionActivation> {
|
|
1212
|
+
const value = await activateDatabaseWebhookSubscription(
|
|
1213
|
+
{
|
|
1214
|
+
project_id: input.projectId,
|
|
1215
|
+
environment: input.environment,
|
|
1216
|
+
subscription_id: input.subscriptionId,
|
|
1217
|
+
generation: input.generation,
|
|
1218
|
+
"Idempotency-Key": input.idempotencyKey,
|
|
1219
|
+
databaseWebhookCreateRequest: {
|
|
1220
|
+
...input.request,
|
|
1221
|
+
event_types: [...input.request.event_types],
|
|
1222
|
+
headers: { ...input.request.headers },
|
|
1223
|
+
},
|
|
1224
|
+
},
|
|
1225
|
+
{ client: this.#client },
|
|
1226
|
+
);
|
|
1227
|
+
assertDatabaseWebhookSubscriptionActivation(value);
|
|
1228
|
+
if (
|
|
1229
|
+
value.id !== input.subscriptionId ||
|
|
1230
|
+
value.environment !== input.environment ||
|
|
1231
|
+
value.generation !== input.generation
|
|
1232
|
+
)
|
|
1233
|
+
throw new TypeError(WEBHOOK_SCOPE_MISMATCH);
|
|
1234
|
+
return value;
|
|
1235
|
+
}
|
|
1236
|
+
public async deactivateDatabaseWebhookSubscription(
|
|
1237
|
+
input: WebhookSubscriptionScope & { generation: number; idempotencyKey: string },
|
|
1238
|
+
): Promise<DatabaseWebhookSubscription> {
|
|
1239
|
+
const value = await deactivateDatabaseWebhookSubscription(
|
|
1240
|
+
{
|
|
1241
|
+
project_id: input.projectId,
|
|
1242
|
+
environment: input.environment,
|
|
1243
|
+
subscription_id: input.subscriptionId,
|
|
1244
|
+
generation: input.generation,
|
|
1245
|
+
"Idempotency-Key": input.idempotencyKey,
|
|
1246
|
+
},
|
|
1247
|
+
{ client: this.#client },
|
|
1248
|
+
);
|
|
1249
|
+
assertDatabaseWebhookSubscription(value);
|
|
1250
|
+
if (
|
|
1251
|
+
value.id !== input.subscriptionId ||
|
|
1252
|
+
value.environment !== input.environment ||
|
|
1253
|
+
value.generation !== input.generation ||
|
|
1254
|
+
value.state !== "inactive"
|
|
1255
|
+
)
|
|
1256
|
+
throw new TypeError(WEBHOOK_SCOPE_MISMATCH);
|
|
1257
|
+
return value;
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1153
1260
|
public async listProjectDatabaseWebhooks(
|
|
1154
1261
|
input: Parameters<ProductApi["listProjectDatabaseWebhooks"]>[0],
|
|
1155
1262
|
): Promise<DatabaseWebhookPage> {
|
|
@@ -1520,6 +1627,9 @@ export class GeneratedSdkProductApi implements ProductApi {
|
|
|
1520
1627
|
name: input.name,
|
|
1521
1628
|
...(input.dataMode === undefined ? {} : { data_mode: input.dataMode }),
|
|
1522
1629
|
...(input.devAccessMode === undefined ? {} : { dev_access_mode: input.devAccessMode }),
|
|
1630
|
+
...(input.includeDevelopmentEnvironment === undefined
|
|
1631
|
+
? {}
|
|
1632
|
+
: { include_development_environment: input.includeDevelopmentEnvironment }),
|
|
1523
1633
|
...(input.region === undefined ? {} : { region: input.region }),
|
|
1524
1634
|
},
|
|
1525
1635
|
},
|
|
@@ -1527,6 +1637,16 @@ export class GeneratedSdkProductApi implements ProductApi {
|
|
|
1527
1637
|
);
|
|
1528
1638
|
}
|
|
1529
1639
|
|
|
1640
|
+
public async addProjectDevelopmentEnvironment(input: {
|
|
1641
|
+
projectId: string;
|
|
1642
|
+
idempotencyKey: string;
|
|
1643
|
+
}): Promise<Operation> {
|
|
1644
|
+
return addProjectDevelopmentEnvironment(
|
|
1645
|
+
{ project_id: input.projectId, "Idempotency-Key": input.idempotencyKey, body: {} },
|
|
1646
|
+
{ client: this.#client },
|
|
1647
|
+
);
|
|
1648
|
+
}
|
|
1649
|
+
|
|
1530
1650
|
public async getOperation(operationId: string): Promise<Operation> {
|
|
1531
1651
|
return getOperation({ operation_id: operationId }, { client: this.#client });
|
|
1532
1652
|
}
|
|
@@ -1668,12 +1788,15 @@ export class GeneratedSdkProductApi implements ProductApi {
|
|
|
1668
1788
|
public async planDeployment(input: {
|
|
1669
1789
|
readonly projectId: string;
|
|
1670
1790
|
readonly commitSha: string;
|
|
1671
|
-
readonly environment
|
|
1791
|
+
readonly environment?: "dev" | "prod";
|
|
1672
1792
|
}): Promise<DeploymentPlan> {
|
|
1673
1793
|
return planDeployment(
|
|
1674
1794
|
{
|
|
1675
1795
|
project_id: input.projectId,
|
|
1676
|
-
planDeploymentRequest: {
|
|
1796
|
+
planDeploymentRequest: {
|
|
1797
|
+
commit_sha: input.commitSha,
|
|
1798
|
+
...(input.environment === undefined ? {} : { environment: input.environment }),
|
|
1799
|
+
},
|
|
1677
1800
|
},
|
|
1678
1801
|
{ client: this.#client },
|
|
1679
1802
|
);
|
|
@@ -111,6 +111,10 @@ const MAIL_RUNTIME_BINDINGS = Object.freeze([
|
|
|
111
111
|
"OHMYHOST_PROJECT_ID",
|
|
112
112
|
]);
|
|
113
113
|
const AI_RUNTIME_BINDINGS = Object.freeze(["OHMYHOST_AI_BASE_URL", "OHMYHOST_AI_KEY"]);
|
|
114
|
+
const BROWSER_RUNTIME_BINDINGS = Object.freeze([
|
|
115
|
+
"OHMYHOST_BROWSER_BASE_URL",
|
|
116
|
+
"OHMYHOST_BROWSER_KEY",
|
|
117
|
+
]);
|
|
114
118
|
// The runtime release is published unchanged as `@amerged/ohmyhost-runtime`; this pinned alias keeps
|
|
115
119
|
// its import name and, unlike the website archive each release removes, stays installable.
|
|
116
120
|
const CUSTOMER_RUNTIME_SOURCE = `npm:@amerged/ohmyhost-runtime@${cliPackage.version}`;
|
|
@@ -384,6 +388,7 @@ export async function initializeRepository(
|
|
|
384
388
|
// Mail stays an explicit choice: Better Auth or a detected mail package never enables it.
|
|
385
389
|
const targetMail = existingConfiguration?.mail?.enabled === true;
|
|
386
390
|
const targetAi = existingConfiguration?.ai?.enabled === true;
|
|
391
|
+
const targetBrowser = existingConfiguration?.browser?.enabled === true;
|
|
387
392
|
const targetStorage = r2 || supabaseStorage;
|
|
388
393
|
// TanStack Start binds storage only on edge, as a Vite app does through its companion.
|
|
389
394
|
const tanStackRuntime =
|
|
@@ -432,6 +437,7 @@ export async function initializeRepository(
|
|
|
432
437
|
auth: targetBetterAuth,
|
|
433
438
|
mail: targetMail,
|
|
434
439
|
ai: targetAi,
|
|
440
|
+
browser: targetBrowser,
|
|
435
441
|
storage: targetStorage,
|
|
436
442
|
});
|
|
437
443
|
const companion = companionRequired
|
|
@@ -1618,6 +1624,7 @@ type RuntimeCapabilities = Readonly<{
|
|
|
1618
1624
|
auth: boolean;
|
|
1619
1625
|
mail: boolean;
|
|
1620
1626
|
ai: boolean;
|
|
1627
|
+
browser: boolean;
|
|
1621
1628
|
storage: boolean;
|
|
1622
1629
|
}>;
|
|
1623
1630
|
|
|
@@ -1635,6 +1642,7 @@ function runtimeContract(capabilities: RuntimeCapabilities): Readonly<{
|
|
|
1635
1642
|
...(capabilities.database ? ["OHMYHOST_DATABASE"] : []),
|
|
1636
1643
|
...(capabilities.mail ? MAIL_RUNTIME_BINDINGS : []),
|
|
1637
1644
|
...(capabilities.ai ? AI_RUNTIME_BINDINGS : []),
|
|
1645
|
+
...(capabilities.browser ? BROWSER_RUNTIME_BINDINGS : []),
|
|
1638
1646
|
]),
|
|
1639
1647
|
].sort(),
|
|
1640
1648
|
),
|
|
@@ -28,6 +28,7 @@ import type {
|
|
|
28
28
|
import { isSaasCnameTarget, type SaasCnameTarget } from "@ohmyhost/contracts/platform-origins";
|
|
29
29
|
import {
|
|
30
30
|
publicOperationFailure,
|
|
31
|
+
parseMigrationFailureDiagnostic,
|
|
31
32
|
publicOperationReconciliation,
|
|
32
33
|
type PublicOperationFailure,
|
|
33
34
|
type PublicOperationReconciliation,
|
|
@@ -818,6 +819,7 @@ export const parseProjectStatus = (value: unknown): Readonly<Record<string, unkn
|
|
|
818
819
|
"prod_url",
|
|
819
820
|
"latest_operation",
|
|
820
821
|
"cleanup_state",
|
|
822
|
+
"custom_domains",
|
|
821
823
|
]);
|
|
822
824
|
const handle = input["handle"];
|
|
823
825
|
if (
|
|
@@ -854,6 +856,19 @@ export const parseProjectStatus = (value: unknown): Readonly<Record<string, unkn
|
|
|
854
856
|
}
|
|
855
857
|
}
|
|
856
858
|
if (input["head_deployment"] !== null) parseProjectDeployment(input["head_deployment"]);
|
|
859
|
+
if (input["custom_domains"] !== undefined) {
|
|
860
|
+
if (!Array.isArray(input["custom_domains"]) || input["custom_domains"].length > 64)
|
|
861
|
+
throw new ResponseContractError();
|
|
862
|
+
for (const raw of input["custom_domains"]) {
|
|
863
|
+
const domain = exactRecord(raw, ["hostname", "environment", "state"]);
|
|
864
|
+
if (
|
|
865
|
+
!isPaidHostname(domain["hostname"]) ||
|
|
866
|
+
domain["environment"] !== "prod" ||
|
|
867
|
+
!["awaiting_deployment", "pending", "active", "deleting"].includes(String(domain["state"]))
|
|
868
|
+
)
|
|
869
|
+
throw new ResponseContractError();
|
|
870
|
+
}
|
|
871
|
+
}
|
|
857
872
|
if (input["environments"] !== undefined) {
|
|
858
873
|
const environments = input["environments"];
|
|
859
874
|
if (!Array.isArray(environments) || environments.length > 2) throw new ResponseContractError();
|
|
@@ -1518,22 +1533,45 @@ export const parseOperation = (value: unknown): PublicOperation => {
|
|
|
1518
1533
|
* detail, and only an exact catalog sentence naming the refused file; it is rendered again here.
|
|
1519
1534
|
*/
|
|
1520
1535
|
function parseOperationFailure(value: unknown): PublicOperationFailure {
|
|
1521
|
-
const input = exactRecord(value, [
|
|
1536
|
+
const input = exactRecord(value, [
|
|
1537
|
+
"code",
|
|
1538
|
+
"message",
|
|
1539
|
+
"retryable",
|
|
1540
|
+
"suggested_action",
|
|
1541
|
+
"detail",
|
|
1542
|
+
"migration",
|
|
1543
|
+
]);
|
|
1522
1544
|
const detail = input["detail"];
|
|
1523
|
-
const
|
|
1545
|
+
const framework =
|
|
1524
1546
|
detail === undefined || input["code"] !== "auto_deploy_plan_rejected"
|
|
1525
1547
|
? null
|
|
1526
1548
|
: frameworkConversionDiagnosticFromDetail(detail);
|
|
1549
|
+
const migration =
|
|
1550
|
+
input["migration"] === undefined ? null : parseMigrationFailureDiagnostic(input["migration"]);
|
|
1551
|
+
const normalize = (value: Record<string, unknown>) =>
|
|
1552
|
+
JSON.stringify(
|
|
1553
|
+
Object.fromEntries(Object.entries(value).sort(([a], [b]) => a.localeCompare(b))),
|
|
1554
|
+
);
|
|
1527
1555
|
if (
|
|
1528
1556
|
typeof input["code"] !== "string" ||
|
|
1529
1557
|
!boundedString(input["message"], 1, 512) ||
|
|
1530
1558
|
input["retryable"] !== false ||
|
|
1531
1559
|
!boundedString(input["suggested_action"], 1, 500) ||
|
|
1532
|
-
(detail !== undefined &&
|
|
1560
|
+
(detail !== undefined && framework === null) ||
|
|
1561
|
+
(input["migration"] !== undefined &&
|
|
1562
|
+
(input["code"] !== "database_migration_failed" ||
|
|
1563
|
+
migration === null ||
|
|
1564
|
+
normalize(input["migration"] as Record<string, unknown>) !==
|
|
1565
|
+
normalize(migration as unknown as Record<string, unknown>)))
|
|
1566
|
+
)
|
|
1567
|
+
throw new ResponseContractError();
|
|
1568
|
+
const safe = publicOperationFailure(input["code"], migration ?? framework);
|
|
1569
|
+
if (
|
|
1570
|
+
safe.code !== input["code"] ||
|
|
1571
|
+
safe.detail !== detail ||
|
|
1572
|
+
JSON.stringify(safe.migration) !== JSON.stringify(migration ?? undefined)
|
|
1533
1573
|
)
|
|
1534
1574
|
throw new ResponseContractError();
|
|
1535
|
-
const safe = publicOperationFailure(input["code"], diagnostic);
|
|
1536
|
-
if (safe.code !== input["code"] || safe.detail !== detail) throw new ResponseContractError();
|
|
1537
1575
|
return safe;
|
|
1538
1576
|
}
|
|
1539
1577
|
|
|
@@ -27,6 +27,79 @@ export class UserTokenFileError extends Error {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
export class PrivateSecretFileError extends Error {
|
|
31
|
+
readonly code = "private_output_invalid";
|
|
32
|
+
constructor() {
|
|
33
|
+
super(
|
|
34
|
+
"Choose a new private output file outside the repository or ignored by Git. Existing files and links are never replaced. After an uncertain activation, retry the same key and request with a new output file.",
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Reserve a new owner-only secret file before a provider mutation. Existing paths are never changed. */
|
|
40
|
+
export async function preparePrivateSecretFile(output: string) {
|
|
41
|
+
const path = resolve(output);
|
|
42
|
+
let file: FileHandle | undefined;
|
|
43
|
+
try {
|
|
44
|
+
await requireIgnoredTokenFile(path);
|
|
45
|
+
file = await open(
|
|
46
|
+
path,
|
|
47
|
+
constants.O_RDWR | constants.O_CREAT | constants.O_EXCL | (constants.O_NOFOLLOW ?? 0),
|
|
48
|
+
0o600,
|
|
49
|
+
);
|
|
50
|
+
const handle = file;
|
|
51
|
+
await secureTokenFile(path, handle);
|
|
52
|
+
const identity = await handle.stat();
|
|
53
|
+
if (!identity.isFile() || identity.nlink !== 1 || identity.size !== 0)
|
|
54
|
+
throw new PrivateSecretFileError();
|
|
55
|
+
return {
|
|
56
|
+
path,
|
|
57
|
+
async save(value: string): Promise<void> {
|
|
58
|
+
try {
|
|
59
|
+
if (!/^[\x21-\x7e]{16,512}$/u.test(value)) throw new PrivateSecretFileError();
|
|
60
|
+
const current = await lstat(path),
|
|
61
|
+
before = await handle.stat();
|
|
62
|
+
if (
|
|
63
|
+
!current.isFile() ||
|
|
64
|
+
current.isSymbolicLink() ||
|
|
65
|
+
current.nlink !== 1 ||
|
|
66
|
+
current.ino !== identity.ino ||
|
|
67
|
+
current.dev !== identity.dev ||
|
|
68
|
+
before.size !== 0
|
|
69
|
+
)
|
|
70
|
+
throw new PrivateSecretFileError();
|
|
71
|
+
await handle.writeFile(value, "utf8");
|
|
72
|
+
await handle.sync();
|
|
73
|
+
const after = await lstat(path),
|
|
74
|
+
stored = Buffer.alloc(Buffer.byteLength(value));
|
|
75
|
+
try {
|
|
76
|
+
const read = await handle.read(stored, 0, stored.length, 0);
|
|
77
|
+
if (
|
|
78
|
+
!after.isFile() ||
|
|
79
|
+
after.isSymbolicLink() ||
|
|
80
|
+
after.nlink !== 1 ||
|
|
81
|
+
after.ino !== identity.ino ||
|
|
82
|
+
after.dev !== identity.dev ||
|
|
83
|
+
after.size !== stored.length ||
|
|
84
|
+
read.bytesRead !== stored.length ||
|
|
85
|
+
stored.toString("utf8") !== value
|
|
86
|
+
)
|
|
87
|
+
throw new PrivateSecretFileError();
|
|
88
|
+
} finally {
|
|
89
|
+
stored.fill(0);
|
|
90
|
+
}
|
|
91
|
+
} catch {
|
|
92
|
+
throw new PrivateSecretFileError();
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
close: () => handle.close(),
|
|
96
|
+
};
|
|
97
|
+
} catch {
|
|
98
|
+
await file?.close();
|
|
99
|
+
throw new PrivateSecretFileError();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
30
103
|
/** What to do next; once a key was issued, the answer names it so it can be revoked. */
|
|
31
104
|
const tokenFileAction = (code: UserTokenFileError["code"], keyId: string | undefined): string => {
|
|
32
105
|
switch (code) {
|
|
@@ -107,7 +107,7 @@ export function assertOrganizationCreditUsage(
|
|
|
107
107
|
throw new TypeError("Invalid usage meter");
|
|
108
108
|
if (
|
|
109
109
|
typeof meter["quantity"] !== "string" ||
|
|
110
|
-
!/^(0|[1-9][0-9]{0,29})(\.[0-9]{1,
|
|
110
|
+
!/^(0|[1-9][0-9]{0,29})(\.[0-9]{1,20})?$/u.test(meter["quantity"]) ||
|
|
111
111
|
!amount(meter["charged_micros"])
|
|
112
112
|
)
|
|
113
113
|
throw new TypeError("Invalid usage amount");
|
|
@@ -140,6 +140,22 @@ export interface DatabaseWebhookCreated extends DatabaseWebhook {
|
|
|
140
140
|
readonly secret: string;
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
+
/** A client-owned subscription remains identifiable across confirmed deactivations. */
|
|
144
|
+
export interface DatabaseWebhookSubscription {
|
|
145
|
+
readonly id: string;
|
|
146
|
+
readonly environment: DatabaseEnvironment;
|
|
147
|
+
readonly state: "creating" | "active" | "deactivating" | "inactive";
|
|
148
|
+
readonly generation: number;
|
|
149
|
+
readonly provider_id: string | null;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Only an authenticated activation or its exact retry may reveal this generation's secret. */
|
|
153
|
+
export interface DatabaseWebhookSubscriptionActivation extends DatabaseWebhookSubscription {
|
|
154
|
+
readonly state: "active";
|
|
155
|
+
readonly provider_id: string;
|
|
156
|
+
readonly secret: string;
|
|
157
|
+
}
|
|
158
|
+
|
|
143
159
|
export interface DatabaseWebhookPage {
|
|
144
160
|
readonly items: readonly DatabaseWebhook[];
|
|
145
161
|
}
|
|
@@ -281,6 +297,20 @@ export function parseDatabaseWebhookId(value: unknown): string {
|
|
|
281
297
|
return value;
|
|
282
298
|
}
|
|
283
299
|
|
|
300
|
+
export function parseDatabaseWebhookSubscriptionId(value: unknown): string {
|
|
301
|
+
if (!matches(value, /^[0-7][0-9A-HJKMNP-TV-Z]{25}$/u))
|
|
302
|
+
throw new TypeError("Invalid database webhook subscription id");
|
|
303
|
+
return value;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export function parseDatabaseWebhookGeneration(value: unknown): number {
|
|
307
|
+
if (typeof value !== "string" || !/^[1-9][0-9]*$/u.test(value))
|
|
308
|
+
throw new TypeError("Invalid database webhook generation");
|
|
309
|
+
const generation = Number(value);
|
|
310
|
+
if (!Number.isSafeInteger(generation)) throw new TypeError("Invalid database webhook generation");
|
|
311
|
+
return generation;
|
|
312
|
+
}
|
|
313
|
+
|
|
284
314
|
export function parseDatabaseWatchId(value: unknown): string {
|
|
285
315
|
if (!isDatabaseWatchTriggerName(value)) throw new TypeError("Invalid database watch id");
|
|
286
316
|
return value;
|
|
@@ -431,6 +461,43 @@ export function assertDatabaseWebhook(value: unknown): asserts value is Database
|
|
|
431
461
|
assertWebhookFields(value);
|
|
432
462
|
}
|
|
433
463
|
|
|
464
|
+
const SUBSCRIPTION_KEYS = ["id", "environment", "state", "generation", "provider_id"];
|
|
465
|
+
function assertSubscriptionFields(value: Record<string, unknown>): void {
|
|
466
|
+
if (
|
|
467
|
+
!matches(value["id"], /^[0-7][0-9A-HJKMNP-TV-Z]{25}$/u) ||
|
|
468
|
+
!oneOf(["dev", "prod"] as const, value["environment"]) ||
|
|
469
|
+
!oneOf(["creating", "active", "deactivating", "inactive"] as const, value["state"]) ||
|
|
470
|
+
!Number.isSafeInteger(value["generation"]) ||
|
|
471
|
+
Number(value["generation"]) < 1 ||
|
|
472
|
+
!(value["provider_id"] === null || matches(value["provider_id"], WEBHOOK_ID_PATTERN)) ||
|
|
473
|
+
(value["state"] === "creating" && value["provider_id"] !== null) ||
|
|
474
|
+
((value["state"] === "active" || value["state"] === "deactivating") &&
|
|
475
|
+
value["provider_id"] === null)
|
|
476
|
+
)
|
|
477
|
+
throw new TypeError("Invalid database webhook subscription");
|
|
478
|
+
}
|
|
479
|
+
export function assertDatabaseWebhookSubscription(
|
|
480
|
+
value: unknown,
|
|
481
|
+
): asserts value is DatabaseWebhookSubscription {
|
|
482
|
+
if (!record(value) || !exact(value, SUBSCRIPTION_KEYS))
|
|
483
|
+
throw new TypeError("Invalid database webhook subscription");
|
|
484
|
+
assertSubscriptionFields(value);
|
|
485
|
+
}
|
|
486
|
+
export function assertDatabaseWebhookSubscriptionActivation(
|
|
487
|
+
value: unknown,
|
|
488
|
+
): asserts value is DatabaseWebhookSubscriptionActivation {
|
|
489
|
+
if (!record(value) || !exact(value, [...SUBSCRIPTION_KEYS, "secret"]))
|
|
490
|
+
throw new TypeError("Invalid database webhook subscription activation");
|
|
491
|
+
assertSubscriptionFields(value);
|
|
492
|
+
if (
|
|
493
|
+
value["state"] !== "active" ||
|
|
494
|
+
value["provider_id"] === null ||
|
|
495
|
+
typeof value["secret"] !== "string" ||
|
|
496
|
+
!/^[\x21-\x7e]{16,512}$/u.test(value["secret"])
|
|
497
|
+
)
|
|
498
|
+
throw new TypeError("Invalid database webhook subscription activation");
|
|
499
|
+
}
|
|
500
|
+
|
|
434
501
|
export function assertDatabaseWatch(value: unknown): asserts value is DatabaseWatch {
|
|
435
502
|
if (
|
|
436
503
|
!record(value) ||
|
|
@@ -518,8 +518,9 @@ const FRAMEWORK_CONVERSION_DETAILS = Object.freeze({
|
|
|
518
518
|
text: {
|
|
519
519
|
nextjs: "runtime.mode: edge",
|
|
520
520
|
"vite-static":
|
|
521
|
-
"runtime.mode: edge with src/ohmyhost/companion.ts when database, auth, mail, ai, storage or functions.crons is set, and static otherwise",
|
|
522
|
-
"tanstack-start":
|
|
521
|
+
"runtime.mode: edge with src/ohmyhost/companion.ts when database, auth, mail, ai, browser, storage or functions.crons is set, and static otherwise",
|
|
522
|
+
"tanstack-start":
|
|
523
|
+
"runtime.mode: edge, or static without functions.crons, storage, ai and browser",
|
|
523
524
|
astro: "runtime.mode: static for prerendered sites, or edge with the Cloudflare adapter",
|
|
524
525
|
},
|
|
525
526
|
},
|
|
@@ -550,7 +551,7 @@ const FRAMEWORK_CONVERSION_DETAILS = Object.freeze({
|
|
|
550
551
|
build_option_unsupported: {
|
|
551
552
|
paths: ["repository_config"],
|
|
552
553
|
template:
|
|
553
|
-
'"{{path}}" sets a build option this runtime ignores: build.ssg_cache_max_mib
|
|
554
|
+
'"{{path}}" sets a build option this runtime ignores: build.ssg_cache_max_mib and build.next_revalidate_path apply only to Next.js, and runtime.mode: functions takes only build.install. Remove the option, commit and push the change, then plan the new commit.',
|
|
554
555
|
},
|
|
555
556
|
application_root_missing: {
|
|
556
557
|
paths: ["repository_config"],
|
|
@@ -589,7 +590,7 @@ const FRAMEWORK_CONVERSION_DETAILS = Object.freeze({
|
|
|
589
590
|
companion_entry_required: {
|
|
590
591
|
paths: ["module"],
|
|
591
592
|
template:
|
|
592
|
-
'"{{path}}" is missing. A Vite app with runtime.mode: edge or with database, auth, mail, ai, storage or functions.crons needs this Worker module with export default { fetch }. Add it, or use runtime.mode: static without those settings; commit and push the change, then plan the new commit.',
|
|
593
|
+
'"{{path}}" is missing. A Vite app with runtime.mode: edge or with database, auth, mail, ai, browser, storage or functions.crons needs this Worker module with export default { fetch }. Add it, or use runtime.mode: static without those settings; commit and push the change, then plan the new commit.',
|
|
593
594
|
},
|
|
594
595
|
worker_module_required: {
|
|
595
596
|
paths: ["module"],
|
|
@@ -225,6 +225,7 @@ export function viteCompanionRequired(configuration: OhmyhostConfig): boolean {
|
|
|
225
225
|
configuration.auth?.provider === "better-auth" ||
|
|
226
226
|
configuration.mail?.enabled === true ||
|
|
227
227
|
configuration.ai?.enabled === true ||
|
|
228
|
+
configuration.browser?.enabled === true ||
|
|
228
229
|
configuration.storage !== undefined ||
|
|
229
230
|
(configuration.functions?.crons.length ?? 0) > 0
|
|
230
231
|
);
|
|
@@ -646,7 +647,11 @@ function configurationFindings(input: FrameworkSourceRuleInput): FrameworkConver
|
|
|
646
647
|
findings.push(
|
|
647
648
|
diagnostic({ code: "runtime_mode_unsupported", path: REPOSITORY_CONFIG, framework }),
|
|
648
649
|
);
|
|
649
|
-
if (
|
|
650
|
+
if (
|
|
651
|
+
build !== null &&
|
|
652
|
+
framework !== "nextjs" &&
|
|
653
|
+
(build.ssg_cache_max_mib !== undefined || build.next_revalidate_path === true)
|
|
654
|
+
)
|
|
650
655
|
findings.push(diagnostic({ code: "build_option_unsupported", path: REPOSITORY_CONFIG }));
|
|
651
656
|
const output =
|
|
652
657
|
framework === "astro"
|
|
@@ -703,6 +708,7 @@ function runtimeModeAdmitted(
|
|
|
703
708
|
configuration.database?.enabled !== true &&
|
|
704
709
|
configuration.mail?.enabled !== true &&
|
|
705
710
|
configuration.ai?.enabled !== true &&
|
|
711
|
+
configuration.browser?.enabled !== true &&
|
|
706
712
|
configuration.auth?.provider !== "better-auth")
|
|
707
713
|
);
|
|
708
714
|
if (framework === "nextjs") return mode === "edge";
|
|
@@ -713,7 +719,8 @@ function runtimeModeAdmitted(
|
|
|
713
719
|
(mode === "static" &&
|
|
714
720
|
!crons &&
|
|
715
721
|
configuration.storage === undefined &&
|
|
716
|
-
configuration.ai?.enabled !== true
|
|
722
|
+
configuration.ai?.enabled !== true &&
|
|
723
|
+
configuration.browser?.enabled !== true)
|
|
717
724
|
);
|
|
718
725
|
}
|
|
719
726
|
|
|
@@ -26,6 +26,8 @@ export type OhmyhostApplicationBuild = Readonly<{
|
|
|
26
26
|
output: string;
|
|
27
27
|
/** Maximum private immutable Next.js prerender cache, in MiB; defaults to 32. */
|
|
28
28
|
ssg_cache_max_mib?: number;
|
|
29
|
+
/** Opt into the writable, deployment-scoped Next.js revalidatePath cache. */
|
|
30
|
+
next_revalidate_path?: boolean;
|
|
29
31
|
}>;
|
|
30
32
|
export type OhmyhostFunctionsBuild = Readonly<{ install: string }>;
|
|
31
33
|
|
|
@@ -61,6 +63,7 @@ export interface OhmyhostConfig {
|
|
|
61
63
|
enabled: boolean;
|
|
62
64
|
jurisdiction?: "eu" | "any";
|
|
63
65
|
}>;
|
|
66
|
+
readonly browser?: Readonly<{ enabled: boolean }>;
|
|
64
67
|
readonly functions?: Readonly<{ crons: readonly string[] }>;
|
|
65
68
|
readonly credits?: Readonly<{
|
|
66
69
|
monthly_budget: number;
|
|
@@ -98,6 +101,9 @@ export function parseOhmyhostConfig(value: unknown): OhmyhostConfig {
|
|
|
98
101
|
...((input.build as OhmyhostApplicationBuild).ssg_cache_max_mib === undefined
|
|
99
102
|
? {}
|
|
100
103
|
: { ssg_cache_max_mib: (input.build as OhmyhostApplicationBuild).ssg_cache_max_mib }),
|
|
104
|
+
...((input.build as OhmyhostApplicationBuild).next_revalidate_path === true
|
|
105
|
+
? { next_revalidate_path: true }
|
|
106
|
+
: {}),
|
|
101
107
|
}),
|
|
102
108
|
runtime: Object.freeze({
|
|
103
109
|
mode: input.runtime.mode,
|
|
@@ -138,6 +144,9 @@ export function parseOhmyhostConfig(value: unknown): OhmyhostConfig {
|
|
|
138
144
|
...(input.ai.jurisdiction === undefined ? {} : { jurisdiction: input.ai.jurisdiction }),
|
|
139
145
|
}),
|
|
140
146
|
}),
|
|
147
|
+
...(input.browser === undefined
|
|
148
|
+
? {}
|
|
149
|
+
: { browser: Object.freeze({ enabled: input.browser.enabled }) }),
|
|
141
150
|
...(input.functions === undefined
|
|
142
151
|
? {}
|
|
143
152
|
: {
|