@omnibase/cli 0.11.0 → 0.12.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/dist/commands/cloud.d.ts +23 -0
- package/dist/commands/cloud.d.ts.map +1 -1
- package/dist/commands/cloud.js +373 -14
- package/dist/commands/cloud.js.map +1 -1
- package/dist/commands/permissions.d.ts.map +1 -1
- package/dist/commands/permissions.js +5 -3
- package/dist/commands/permissions.js.map +1 -1
- package/dist/commands/restart.js +1 -1
- package/dist/commands/restart.js.map +1 -1
- package/dist/commands/stripe.d.ts.map +1 -1
- package/dist/commands/stripe.js +15 -8
- package/dist/commands/stripe.js.map +1 -1
- package/dist/lib/omnibase.js +1 -1
- package/dist/lib/omnibase.js.map +1 -1
- package/dist/services/db/generate/policies.d.ts +1 -1
- package/dist/services/db/generate/policies.d.ts.map +1 -1
- package/dist/services/db/generate/policies.js +3 -3
- package/dist/services/db/generate/policies.js.map +1 -1
- package/dist/services/db/generate/rls/diff.d.ts.map +1 -1
- package/dist/services/db/generate/rls/diff.js +60 -4
- package/dist/services/db/generate/rls/diff.js.map +1 -1
- package/dist/services/db/generate/rls/emit.d.ts +1 -0
- package/dist/services/db/generate/rls/emit.d.ts.map +1 -1
- package/dist/services/db/generate/rls/emit.js +29 -4
- package/dist/services/db/generate/rls/emit.js.map +1 -1
- package/dist/services/db/migrate.d.ts.map +1 -1
- package/dist/services/db/migrate.js +8 -4
- package/dist/services/db/migrate.js.map +1 -1
- package/dist/utils/api-client.d.ts.map +1 -1
- package/dist/utils/api-client.js +3 -1
- package/dist/utils/api-client.js.map +1 -1
- package/docker/db/000019_rls_helpers_security_definer.down.sql +75 -0
- package/docker/db/000019_rls_helpers_security_definer.up.sql +84 -0
- package/docker/db/000020_narrow_anon_user_grants.down.sql +10 -0
- package/docker/db/000020_narrow_anon_user_grants.up.sql +64 -0
- package/docker/db/000021_pg_trgm_schema.down.sql +6 -0
- package/docker/db/000021_pg_trgm_schema.up.sql +8 -0
- package/docker/docker-compose.base.yml +3 -7
- package/package.json +2 -2
package/dist/commands/cloud.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
|
+
export declare function unwrapManagedHostingData<T>(body: any): T;
|
|
2
3
|
/**
|
|
3
4
|
* Turn a `wrangler deploy --dry-run --outdir .bundle` output into a
|
|
4
5
|
* self-contained, deploy-ready zip the managed-hosting server hands to
|
|
@@ -7,6 +8,26 @@ import { Command } from "commander";
|
|
|
7
8
|
*/
|
|
8
9
|
export declare function packageWorkerBundle(workersDir: string, secrets?: Record<string, string>): Promise<Buffer>;
|
|
9
10
|
export declare function resolveBundleEntry(bundleDir: string, configuredMain?: string): Promise<string>;
|
|
11
|
+
interface BranchSummary {
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
slug?: string;
|
|
15
|
+
status: string;
|
|
16
|
+
api_url?: string;
|
|
17
|
+
}
|
|
18
|
+
export declare function isGoneBranchStatus(status: string): boolean;
|
|
19
|
+
export declare function findLiveBranchByName(branches: BranchSummary[], name: string): BranchSummary | undefined;
|
|
20
|
+
export declare function pickLiveBranch(branches: BranchSummary[], ref: string): BranchSummary | undefined;
|
|
21
|
+
export interface BranchEnvInput {
|
|
22
|
+
apiUrl: string;
|
|
23
|
+
serviceKey: string;
|
|
24
|
+
managedHostingUrl: string;
|
|
25
|
+
postgrestUrl?: string | null;
|
|
26
|
+
workerDomain?: string;
|
|
27
|
+
cookieDomain?: string;
|
|
28
|
+
dashboardUrl?: string;
|
|
29
|
+
}
|
|
30
|
+
export declare function buildBranchEnv(input: BranchEnvInput): Record<string, string>;
|
|
10
31
|
/**
|
|
11
32
|
* Push config from omnibase.toml to managed hosting.
|
|
12
33
|
*
|
|
@@ -17,9 +38,11 @@ export declare function resolveBundleEntry(bundleDir: string, configuredMain?: s
|
|
|
17
38
|
*
|
|
18
39
|
* {VAR} secrets resolve from process.env → omnibase/.env.<branch>.
|
|
19
40
|
*/
|
|
41
|
+
export declare function stripUnresolvedOidcProviders(payload: Record<string, unknown>): string[];
|
|
20
42
|
export declare function pushEnvConfig(envFlag?: string): Promise<void>;
|
|
21
43
|
/**
|
|
22
44
|
* Add cloud commands to the CLI program
|
|
23
45
|
*/
|
|
24
46
|
export declare function addCloudCommands(program: Command): void;
|
|
47
|
+
export {};
|
|
25
48
|
//# sourceMappingURL=cloud.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloud.d.ts","sourceRoot":"","sources":["../../src/commands/cloud.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"cloud.d.ts","sourceRoot":"","sources":["../../src/commands/cloud.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAmCpC,wBAAgB,wBAAwB,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,CAExD;AA6UD;;;;;GAKG;AACH,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACnC,OAAO,CAAC,MAAM,CAAC,CA6BjB;AAED,wBAAsB,kBAAkB,CACtC,SAAS,EAAE,MAAM,EACjB,cAAc,CAAC,EAAE,MAAM,GACtB,OAAO,CAAC,MAAM,CAAC,CAsBjB;AAkFD,UAAU,aAAa;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAmBD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAE1D;AAED,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,aAAa,EAAE,EACzB,IAAI,EAAE,MAAM,GACX,aAAa,GAAG,SAAS,CAI3B;AAED,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,aAAa,EAAE,EACzB,GAAG,EAAE,MAAM,GACV,aAAa,GAAG,SAAS,CAQ3B;AAyID,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAiC5E;AAoDD;;;;;;;;;GASG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,MAAM,EAAE,CAsBV;AAED,wBAAsB,aAAa,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAqFnE;AAogBD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA2hBvD"}
|
package/dist/commands/cloud.js
CHANGED
|
@@ -36,8 +36,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.unwrapManagedHostingData = unwrapManagedHostingData;
|
|
39
40
|
exports.packageWorkerBundle = packageWorkerBundle;
|
|
40
41
|
exports.resolveBundleEntry = resolveBundleEntry;
|
|
42
|
+
exports.isGoneBranchStatus = isGoneBranchStatus;
|
|
43
|
+
exports.findLiveBranchByName = findLiveBranchByName;
|
|
44
|
+
exports.pickLiveBranch = pickLiveBranch;
|
|
45
|
+
exports.buildBranchEnv = buildBranchEnv;
|
|
46
|
+
exports.stripUnresolvedOidcProviders = stripUnresolvedOidcProviders;
|
|
41
47
|
exports.pushEnvConfig = pushEnvConfig;
|
|
42
48
|
exports.addCloudCommands = addCloudCommands;
|
|
43
49
|
const child_process_1 = require("child_process");
|
|
@@ -55,6 +61,9 @@ const logger_1 = require("../utils/logger");
|
|
|
55
61
|
const errors_1 = require("../utils/errors");
|
|
56
62
|
const api_client_1 = require("../utils/api-client");
|
|
57
63
|
const config_1 = require("../utils/config");
|
|
64
|
+
function unwrapManagedHostingData(body) {
|
|
65
|
+
return (body?.data ?? body);
|
|
66
|
+
}
|
|
58
67
|
/**
|
|
59
68
|
* Login to OmniBase Cloud
|
|
60
69
|
*/
|
|
@@ -67,7 +76,7 @@ async function login(apiKey, options) {
|
|
|
67
76
|
Authorization: `Bearer ${apiKey}`,
|
|
68
77
|
},
|
|
69
78
|
});
|
|
70
|
-
const data = response.data;
|
|
79
|
+
const data = unwrapManagedHostingData(response.data);
|
|
71
80
|
if (!data?.tenant_id) {
|
|
72
81
|
throw new Error("Invalid API key");
|
|
73
82
|
}
|
|
@@ -274,10 +283,12 @@ async function deployWorkers(envFlag, nameFlag, allFlag) {
|
|
|
274
283
|
});
|
|
275
284
|
targets = [selected];
|
|
276
285
|
}
|
|
286
|
+
const failures = [];
|
|
277
287
|
for (const dep of targets) {
|
|
278
288
|
const workersDir = path.join(root, "omnibase", dep.path ?? dep.name);
|
|
279
289
|
if (!fs.existsSync(workersDir)) {
|
|
280
290
|
logger_1.logger.fail(`Deployment '${dep.name}' directory not found: ${workersDir}`);
|
|
291
|
+
failures.push(dep.name);
|
|
281
292
|
continue;
|
|
282
293
|
}
|
|
283
294
|
logger_1.logger.start(`Building '${dep.name}' for ${env.name}...`);
|
|
@@ -290,6 +301,7 @@ async function deployWorkers(envFlag, nameFlag, allFlag) {
|
|
|
290
301
|
}
|
|
291
302
|
catch (error) {
|
|
292
303
|
logger_1.logger.fail(`Build failed for '${dep.name}'. Check the output above.`);
|
|
304
|
+
failures.push(dep.name);
|
|
293
305
|
continue;
|
|
294
306
|
}
|
|
295
307
|
const bundle = await packageWorkerBundle(workersDir, secrets);
|
|
@@ -297,13 +309,18 @@ async function deployWorkers(envFlag, nameFlag, allFlag) {
|
|
|
297
309
|
logger_1.logger.start(`Deploying '${dep.name}'...`);
|
|
298
310
|
try {
|
|
299
311
|
const result = await uploadToManagedHosting(env, bundle, dep.name);
|
|
312
|
+
const deployed = unwrapManagedHostingData(result);
|
|
300
313
|
logger_1.logger.succeed(`${dep.name} deployed`);
|
|
301
|
-
logger_1.logger.log(` URL: ${
|
|
314
|
+
logger_1.logger.log(` URL: ${deployed?.url}`);
|
|
302
315
|
}
|
|
303
316
|
catch (error) {
|
|
304
317
|
logger_1.logger.fail(`${dep.name} deploy failed: ${(0, errors_1.formatHttpError)(error)}`);
|
|
318
|
+
failures.push(dep.name);
|
|
305
319
|
}
|
|
306
320
|
}
|
|
321
|
+
if (failures.length > 0) {
|
|
322
|
+
throw new Error(`Failed to deploy: ${failures.join(", ")}`);
|
|
323
|
+
}
|
|
307
324
|
}
|
|
308
325
|
/**
|
|
309
326
|
* Turn a `wrangler deploy --dry-run --outdir .bundle` output into a
|
|
@@ -407,6 +424,146 @@ async function uploadToManagedHosting(env, bundle, deploymentName = "default") {
|
|
|
407
424
|
throw new Error((0, errors_1.formatHttpError)(error));
|
|
408
425
|
}
|
|
409
426
|
}
|
|
427
|
+
const GONE_BRANCH_STATUSES = new Set(["deleted", "deleting"]);
|
|
428
|
+
const FAILED_BRANCH_STATUSES = new Set([
|
|
429
|
+
"failed",
|
|
430
|
+
"failed_deletion",
|
|
431
|
+
"suspended",
|
|
432
|
+
"deleted",
|
|
433
|
+
]);
|
|
434
|
+
function isGoneBranchStatus(status) {
|
|
435
|
+
return GONE_BRANCH_STATUSES.has(status);
|
|
436
|
+
}
|
|
437
|
+
function findLiveBranchByName(branches, name) {
|
|
438
|
+
return branches.find((branch) => branch.name === name && !isGoneBranchStatus(branch.status));
|
|
439
|
+
}
|
|
440
|
+
function pickLiveBranch(branches, ref) {
|
|
441
|
+
const matches = branches.filter((branch) => branch.id === ref || branch.name === ref || branch.slug === ref);
|
|
442
|
+
return (matches.find((branch) => !isGoneBranchStatus(branch.status)) ?? matches[0]);
|
|
443
|
+
}
|
|
444
|
+
function resolveProjectId(projectIdFlag) {
|
|
445
|
+
const root = (0, environment_1.findOmnibaseRoot)();
|
|
446
|
+
const config = (0, config_1.loadConfig)(root);
|
|
447
|
+
const projectId = projectIdFlag ?? config.project_id;
|
|
448
|
+
if (!projectId) {
|
|
449
|
+
throw new Error("project_id is required. Provide --project-id or set it in omnibase.toml");
|
|
450
|
+
}
|
|
451
|
+
return projectId;
|
|
452
|
+
}
|
|
453
|
+
async function listProjectBranches(api, projectId) {
|
|
454
|
+
const response = await api.get(`/api/v1/projects/${projectId}/branches`);
|
|
455
|
+
return Array.isArray(response.data) ? response.data : [];
|
|
456
|
+
}
|
|
457
|
+
async function getBranchDetail(api, branchId) {
|
|
458
|
+
const response = await api.get(`/api/v1/project_branches/${branchId}`);
|
|
459
|
+
return response.data;
|
|
460
|
+
}
|
|
461
|
+
function isNotFound(error) {
|
|
462
|
+
return axios_1.default.isAxiosError(error) && error.response?.status === 404;
|
|
463
|
+
}
|
|
464
|
+
function sleep(ms) {
|
|
465
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
466
|
+
}
|
|
467
|
+
function parseSeconds(value, fallback) {
|
|
468
|
+
if (value === undefined)
|
|
469
|
+
return fallback;
|
|
470
|
+
const seconds = Number(value);
|
|
471
|
+
if (!Number.isFinite(seconds) || seconds <= 0) {
|
|
472
|
+
throw new Error(`Invalid timeout: ${value}`);
|
|
473
|
+
}
|
|
474
|
+
return seconds;
|
|
475
|
+
}
|
|
476
|
+
async function checkBranchHealth(apiUrl) {
|
|
477
|
+
try {
|
|
478
|
+
const response = await axios_1.default.get(`${apiUrl.replace(/\/+$/, "")}/health/ready`, { timeout: 10000, validateStatus: (status) => status === 200 });
|
|
479
|
+
return response.status === 200;
|
|
480
|
+
}
|
|
481
|
+
catch {
|
|
482
|
+
return false;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
async function waitForBranchActive(api, branchId, timeoutMs, quiet) {
|
|
486
|
+
const deadline = Date.now() + timeoutMs;
|
|
487
|
+
let lastStatus = "";
|
|
488
|
+
while (Date.now() < deadline) {
|
|
489
|
+
let detail;
|
|
490
|
+
try {
|
|
491
|
+
detail = await getBranchDetail(api, branchId);
|
|
492
|
+
}
|
|
493
|
+
catch (error) {
|
|
494
|
+
if (!isNotFound(error))
|
|
495
|
+
throw error;
|
|
496
|
+
}
|
|
497
|
+
if (detail) {
|
|
498
|
+
if (detail.status !== lastStatus) {
|
|
499
|
+
lastStatus = detail.status;
|
|
500
|
+
if (!quiet)
|
|
501
|
+
logger_1.logger.info(`Branch status: ${detail.status}`);
|
|
502
|
+
}
|
|
503
|
+
if (detail.status === "active")
|
|
504
|
+
return detail;
|
|
505
|
+
if (FAILED_BRANCH_STATUSES.has(detail.status)) {
|
|
506
|
+
const message = detail.error_message
|
|
507
|
+
? `${detail.status}: ${detail.error_message}`
|
|
508
|
+
: detail.status;
|
|
509
|
+
throw new Error(`Branch ${detail.name} is ${message}`);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
await sleep(5000);
|
|
513
|
+
}
|
|
514
|
+
throw new Error(`Timed out after ${Math.round(timeoutMs / 1000)}s waiting for branch ${branchId} to become active`);
|
|
515
|
+
}
|
|
516
|
+
async function waitForBranchHealthy(apiUrl, timeoutMs, quiet) {
|
|
517
|
+
const deadline = Date.now() + timeoutMs;
|
|
518
|
+
while (Date.now() < deadline) {
|
|
519
|
+
if (await checkBranchHealth(apiUrl)) {
|
|
520
|
+
if (!quiet)
|
|
521
|
+
logger_1.logger.succeed(`Branch is healthy at ${apiUrl}`);
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
await sleep(5000);
|
|
525
|
+
}
|
|
526
|
+
throw new Error(`Timed out after ${Math.round(timeoutMs / 1000)}s waiting for ${apiUrl}/health/ready`);
|
|
527
|
+
}
|
|
528
|
+
async function getApiServiceKey(api, branchId) {
|
|
529
|
+
try {
|
|
530
|
+
const response = await api.get(`/api/v1/project_branches/${branchId}/api-service-key`);
|
|
531
|
+
const keyData = response.data?.data ?? response.data;
|
|
532
|
+
const serviceKey = keyData?.api_service_key ?? keyData?.service_key;
|
|
533
|
+
if (!serviceKey) {
|
|
534
|
+
throw new Error("API service key missing from response");
|
|
535
|
+
}
|
|
536
|
+
return serviceKey;
|
|
537
|
+
}
|
|
538
|
+
catch (error) {
|
|
539
|
+
throw new Error(`Failed to load branch API service key: ${(0, errors_1.formatHttpError)(error)}`);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
function buildBranchEnv(input) {
|
|
543
|
+
const apiUrl = input.apiUrl.replace(/\/+$/, "");
|
|
544
|
+
const hostname = new URL(apiUrl).hostname;
|
|
545
|
+
const composedSlug = hostname.split(".")[0];
|
|
546
|
+
if (!composedSlug) {
|
|
547
|
+
throw new Error(`Could not derive a branch slug from ${input.apiUrl}`);
|
|
548
|
+
}
|
|
549
|
+
const workerDomain = (input.workerDomain ?? "workers.omnibase.tech").replace(/^\.+/, "");
|
|
550
|
+
const cookieDomain = input.cookieDomain ?? `.${workerDomain}`;
|
|
551
|
+
const dashboardUrl = (input.dashboardUrl ?? `https://${composedSlug}-dashboard.${workerDomain}`).replace(/\/+$/, "");
|
|
552
|
+
const postgrestUrl = (input.postgrestUrl ?? `${apiUrl}/rest/v1`).replace(/\/+$/, "");
|
|
553
|
+
return {
|
|
554
|
+
NEXT_PUBLIC_WEBSITE_URL: dashboardUrl,
|
|
555
|
+
WEBSITE_URL: dashboardUrl,
|
|
556
|
+
ALLOWED_RETURN_URLS: dashboardUrl,
|
|
557
|
+
NEXT_PUBLIC_OMNIBASE_WORKER_URL: dashboardUrl,
|
|
558
|
+
OMNIBASE_API_URL: apiUrl,
|
|
559
|
+
NEXT_PUBLIC_OMNIBASE_API_URL: apiUrl,
|
|
560
|
+
OMNIBASE_POSTGREST_URL: postgrestUrl,
|
|
561
|
+
OMNIBASE_SERVICE_KEY: input.serviceKey,
|
|
562
|
+
MANAGED_HOSTING_API_URL: input.managedHostingUrl,
|
|
563
|
+
NEXT_PUBLIC_MANAGED_HOSTING_API_URL: input.managedHostingUrl,
|
|
564
|
+
OMNIBASE_COOKIE_DOMAIN: cookieDomain,
|
|
565
|
+
};
|
|
566
|
+
}
|
|
410
567
|
/**
|
|
411
568
|
* Resolve a branch for the project from managed hosting. A `--env` value
|
|
412
569
|
* matches by name, slug, or id; otherwise a single branch is auto-selected or
|
|
@@ -452,6 +609,28 @@ async function resolveBranch(managedHostingUrl, projectId, branchFlag) {
|
|
|
452
609
|
*
|
|
453
610
|
* {VAR} secrets resolve from process.env → omnibase/.env.<branch>.
|
|
454
611
|
*/
|
|
612
|
+
function stripUnresolvedOidcProviders(payload) {
|
|
613
|
+
const auth = payload.auth;
|
|
614
|
+
const providers = auth?.oidc;
|
|
615
|
+
if (!Array.isArray(providers))
|
|
616
|
+
return [];
|
|
617
|
+
const dropped = [];
|
|
618
|
+
auth.oidc = providers.filter((provider) => {
|
|
619
|
+
const unresolved = ["client_id", "client_secret"].some((key) => {
|
|
620
|
+
const value = provider[key];
|
|
621
|
+
return typeof value === "string" && /\{[A-Za-z_][A-Za-z0-9_]*\}/.test(value);
|
|
622
|
+
});
|
|
623
|
+
if (unresolved) {
|
|
624
|
+
dropped.push(String(provider.provider ?? "unknown"));
|
|
625
|
+
return false;
|
|
626
|
+
}
|
|
627
|
+
return true;
|
|
628
|
+
});
|
|
629
|
+
if (auth.oidc.length === 0) {
|
|
630
|
+
delete auth.oidc;
|
|
631
|
+
}
|
|
632
|
+
return dropped;
|
|
633
|
+
}
|
|
455
634
|
async function pushEnvConfig(envFlag) {
|
|
456
635
|
const root = (0, environment_1.findOmnibaseRoot)();
|
|
457
636
|
const env = await (0, environment_1.selectEnvironment)(envFlag);
|
|
@@ -478,6 +657,10 @@ async function pushEnvConfig(envFlag) {
|
|
|
478
657
|
(0, config_1.assertValidVersions)(resolved.versions);
|
|
479
658
|
}
|
|
480
659
|
const payload = (0, config_1.cloudConfigOf)(resolved);
|
|
660
|
+
const droppedOidc = stripUnresolvedOidcProviders(payload);
|
|
661
|
+
if (droppedOidc.length > 0) {
|
|
662
|
+
logger_1.logger.warn(`Skipping OIDC provider(s) with unresolved credentials: ${droppedOidc.join(", ")}`);
|
|
663
|
+
}
|
|
481
664
|
const sections = Object.keys(payload);
|
|
482
665
|
if (sections.length === 0) {
|
|
483
666
|
logger_1.logger.info("Nothing to push: omnibase.toml has no cloud config sections.");
|
|
@@ -598,25 +781,142 @@ async function branchList(projectIdFlag) {
|
|
|
598
781
|
throw new Error((0, errors_1.formatHttpError)(error));
|
|
599
782
|
}
|
|
600
783
|
}
|
|
784
|
+
async function branchEnsure(branchName, options) {
|
|
785
|
+
const api = (0, api_client_1.createProfileClient)();
|
|
786
|
+
const projectId = resolveProjectId(options.projectId);
|
|
787
|
+
const quiet = Boolean(options.json);
|
|
788
|
+
if (!quiet)
|
|
789
|
+
logger_1.logger.start(`Resolving branch '${branchName}'...`);
|
|
790
|
+
const branches = await listProjectBranches(api, projectId);
|
|
791
|
+
let branch = findLiveBranchByName(branches, branchName);
|
|
792
|
+
if (branch) {
|
|
793
|
+
if (!quiet)
|
|
794
|
+
logger_1.logger.succeed(`Reusing branch '${branch.name}' (${branch.id})`);
|
|
795
|
+
}
|
|
796
|
+
else {
|
|
797
|
+
if (!options.region || !options.tier || !options.email) {
|
|
798
|
+
throw new Error("--region, --tier, and --email are required when creating a branch");
|
|
799
|
+
}
|
|
800
|
+
if (!quiet)
|
|
801
|
+
logger_1.logger.start(`Creating branch '${branchName}'...`);
|
|
802
|
+
const response = await api.post("/api/v1/project_branches", {
|
|
803
|
+
project_id: projectId,
|
|
804
|
+
branch_name: branchName,
|
|
805
|
+
region: options.region,
|
|
806
|
+
deployment_tier: options.tier,
|
|
807
|
+
billing_email: options.email,
|
|
808
|
+
});
|
|
809
|
+
branch = {
|
|
810
|
+
id: response.data.branch_id,
|
|
811
|
+
name: branchName,
|
|
812
|
+
slug: "",
|
|
813
|
+
status: response.data.status ?? "provisioning",
|
|
814
|
+
};
|
|
815
|
+
if (!quiet)
|
|
816
|
+
logger_1.logger.succeed(`Branch '${branchName}' provisioning started`);
|
|
817
|
+
}
|
|
818
|
+
let detail = {
|
|
819
|
+
...branch,
|
|
820
|
+
project_id: projectId,
|
|
821
|
+
};
|
|
822
|
+
if (options.wait !== false) {
|
|
823
|
+
const timeoutMs = parseSeconds(options.timeout, 1800) * 1000;
|
|
824
|
+
const healthTimeoutMs = parseSeconds(options.healthTimeout, 600) * 1000;
|
|
825
|
+
detail = await waitForBranchActive(api, branch.id, timeoutMs, quiet);
|
|
826
|
+
if (!detail.api_url) {
|
|
827
|
+
throw new Error(`Branch ${detail.name} is active but has no API URL`);
|
|
828
|
+
}
|
|
829
|
+
await waitForBranchHealthy(detail.api_url, healthTimeoutMs, quiet);
|
|
830
|
+
}
|
|
831
|
+
if (options.json) {
|
|
832
|
+
logger_1.logger.log(JSON.stringify({
|
|
833
|
+
id: detail.id,
|
|
834
|
+
name: detail.name,
|
|
835
|
+
slug: detail.slug,
|
|
836
|
+
status: detail.status,
|
|
837
|
+
project_id: detail.project_id,
|
|
838
|
+
api_url: detail.api_url ?? null,
|
|
839
|
+
postgrest_url: detail.postgrest_url ?? null,
|
|
840
|
+
}));
|
|
841
|
+
return;
|
|
842
|
+
}
|
|
843
|
+
logger_1.logger.log("");
|
|
844
|
+
logger_1.logger.log(`Branch: ${detail.name} (${detail.id})`);
|
|
845
|
+
logger_1.logger.log(`Status: ${detail.status}`);
|
|
846
|
+
if (detail.api_url)
|
|
847
|
+
logger_1.logger.log(`API URL: ${detail.api_url}`);
|
|
848
|
+
logger_1.logger.log("");
|
|
849
|
+
logger_1.logger.log(`Next steps:`);
|
|
850
|
+
logger_1.logger.log(` omnibase cloud branch env ${detail.name} --output omnibase/.env.${detail.name}`);
|
|
851
|
+
logger_1.logger.log(` omnibase sync all --env ${detail.name}`);
|
|
852
|
+
logger_1.logger.log(` omnibase cloud workers deploy --all --env ${detail.name}`);
|
|
853
|
+
}
|
|
854
|
+
async function branchEnv(branchRef, options) {
|
|
855
|
+
const api = (0, api_client_1.createProfileClient)();
|
|
856
|
+
const projectId = resolveProjectId(options.projectId);
|
|
857
|
+
logger_1.logger.start(`Resolving branch '${branchRef}'...`);
|
|
858
|
+
const branches = await listProjectBranches(api, projectId);
|
|
859
|
+
const branch = pickLiveBranch(branches, branchRef);
|
|
860
|
+
if (!branch || isGoneBranchStatus(branch.status)) {
|
|
861
|
+
throw new Error(`Branch '${branchRef}' not found in project ${projectId}`);
|
|
862
|
+
}
|
|
863
|
+
const detail = await getBranchDetail(api, branch.id);
|
|
864
|
+
if (!detail.api_url) {
|
|
865
|
+
throw new Error(`Branch '${branchRef}' has no API URL yet`);
|
|
866
|
+
}
|
|
867
|
+
const serviceKey = await getApiServiceKey(api, branch.id);
|
|
868
|
+
const profile = (0, credentials_1.getActiveProfile)();
|
|
869
|
+
const managedHostingUrl = profile?.managed_hosting_url ?? process.env.MANAGED_HOSTING_API_URL;
|
|
870
|
+
if (!managedHostingUrl) {
|
|
871
|
+
throw new Error("No managed hosting URL configured. Run 'omnibase cloud login' or set MANAGED_HOSTING_API_URL.");
|
|
872
|
+
}
|
|
873
|
+
const env = buildBranchEnv({
|
|
874
|
+
apiUrl: detail.api_url,
|
|
875
|
+
postgrestUrl: detail.postgrest_url,
|
|
876
|
+
serviceKey,
|
|
877
|
+
managedHostingUrl,
|
|
878
|
+
workerDomain: options.workerDomain ?? process.env.OMNIBASE_WORKER_DOMAIN,
|
|
879
|
+
cookieDomain: options.cookieDomain ?? process.env.OMNIBASE_COOKIE_DOMAIN,
|
|
880
|
+
dashboardUrl: options.dashboardUrl,
|
|
881
|
+
});
|
|
882
|
+
const content = Object.entries(env)
|
|
883
|
+
.map(([key, value]) => `${key}=${value}`)
|
|
884
|
+
.join("\n") + "\n";
|
|
885
|
+
if (options.output) {
|
|
886
|
+
const target = path.resolve(options.output);
|
|
887
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
888
|
+
fs.writeFileSync(target, content, { mode: 0o600 });
|
|
889
|
+
logger_1.logger.succeed(`Wrote branch environment to ${target}`);
|
|
890
|
+
return;
|
|
891
|
+
}
|
|
892
|
+
logger_1.logger.succeed(`Resolved to ${detail.name} (${detail.id})`);
|
|
893
|
+
logger_1.logger.log(content.trimEnd());
|
|
894
|
+
}
|
|
601
895
|
/**
|
|
602
896
|
* Delete a branch by name or ID
|
|
603
897
|
*/
|
|
604
|
-
async function branchDelete(branchRef, projectIdFlag) {
|
|
605
|
-
const root = (0, environment_1.findOmnibaseRoot)();
|
|
898
|
+
async function branchDelete(branchRef, projectIdFlag, options = {}) {
|
|
606
899
|
const api = (0, api_client_1.createProfileClient)();
|
|
607
|
-
const
|
|
608
|
-
const projectId = projectIdFlag ?? config.project_id;
|
|
609
|
-
if (!projectId) {
|
|
610
|
-
throw new Error("project_id is required. Provide --project-id or set it in omnibase.toml");
|
|
611
|
-
}
|
|
900
|
+
const projectId = resolveProjectId(projectIdFlag);
|
|
612
901
|
logger_1.logger.start(`Resolving branch '${branchRef}'...`);
|
|
613
|
-
const
|
|
614
|
-
const
|
|
615
|
-
const match = branches.find((b) => b.id === branchRef || b.name === branchRef || b.slug === branchRef);
|
|
902
|
+
const branches = await listProjectBranches(api, projectId);
|
|
903
|
+
const match = pickLiveBranch(branches, branchRef);
|
|
616
904
|
if (!match) {
|
|
905
|
+
if (options.ifExists) {
|
|
906
|
+
logger_1.logger.succeed(`Branch '${branchRef}' does not exist`);
|
|
907
|
+
return;
|
|
908
|
+
}
|
|
617
909
|
logger_1.logger.fail(`Branch '${branchRef}' not found`);
|
|
618
910
|
throw new Error(`Branch '${branchRef}' not found in project ${projectId}`);
|
|
619
911
|
}
|
|
912
|
+
if (isGoneBranchStatus(match.status)) {
|
|
913
|
+
if (options.ifExists) {
|
|
914
|
+
logger_1.logger.succeed(`Branch '${branchRef}' is already ${match.status}`);
|
|
915
|
+
return;
|
|
916
|
+
}
|
|
917
|
+
logger_1.logger.fail(`Branch '${branchRef}' is already ${match.status}`);
|
|
918
|
+
throw new Error(`Branch '${branchRef}' is already ${match.status}`);
|
|
919
|
+
}
|
|
620
920
|
logger_1.logger.succeed(`Resolved to ${match.name} (${match.id})`);
|
|
621
921
|
logger_1.logger.start(`Deprovisioning branch '${branchRef}'...`);
|
|
622
922
|
try {
|
|
@@ -1129,6 +1429,60 @@ function addCloudCommands(program) {
|
|
|
1129
1429
|
await (0, errors_1.handleCommandError)(error);
|
|
1130
1430
|
}
|
|
1131
1431
|
});
|
|
1432
|
+
branch
|
|
1433
|
+
.command("ensure <branch>")
|
|
1434
|
+
.summary("Provision a branch if it does not exist and wait for it")
|
|
1435
|
+
.description("Idempotently provision a branch and wait until it is active and its " +
|
|
1436
|
+
"API reports ready.\n\n" +
|
|
1437
|
+
"An existing live branch with the same name is reused, so this is safe " +
|
|
1438
|
+
"to run on every CI job. When no branch exists, `--region`, `--tier`, " +
|
|
1439
|
+
"and `--email` are required.\n\n" +
|
|
1440
|
+
"With `--json`, prints a single JSON object instead of log output. Use " +
|
|
1441
|
+
"`--no-wait` to return as soon as provisioning starts.\n\n" +
|
|
1442
|
+
"```bash\n" +
|
|
1443
|
+
"omnibase cloud branch ensure pr-123 --region syd --tier shared_starter --email ci@example.com\n" +
|
|
1444
|
+
"omnibase cloud branch ensure pr-123 --region syd --tier shared_starter --email ci@example.com --json\n" +
|
|
1445
|
+
"```")
|
|
1446
|
+
.option("--project-id <id>", "Project ID")
|
|
1447
|
+
.option("--region <region>", "Region (e.g. syd)")
|
|
1448
|
+
.option("--tier <tier>", "Deployment tier (e.g. shared_starter)")
|
|
1449
|
+
.option("--email <email>", "Billing email")
|
|
1450
|
+
.option("--no-wait", "Return immediately after provisioning starts")
|
|
1451
|
+
.option("--timeout <seconds>", "Provisioning timeout in seconds", "1800")
|
|
1452
|
+
.option("--health-timeout <seconds>", "Health check timeout in seconds", "600")
|
|
1453
|
+
.option("--json", "Print the resolved branch as JSON")
|
|
1454
|
+
.action(async (branchName, cmdOptions) => {
|
|
1455
|
+
try {
|
|
1456
|
+
await branchEnsure(branchName, cmdOptions);
|
|
1457
|
+
}
|
|
1458
|
+
catch (error) {
|
|
1459
|
+
await (0, errors_1.handleCommandError)(error);
|
|
1460
|
+
}
|
|
1461
|
+
});
|
|
1462
|
+
branch
|
|
1463
|
+
.command("env <branch>")
|
|
1464
|
+
.summary("Export branch URLs and keys as environment variables")
|
|
1465
|
+
.description("Resolve a branch's API URL, PostgREST URL, service key, and dashboard " +
|
|
1466
|
+
"worker URL, then write them as dotenv content.\n\n" +
|
|
1467
|
+
"Use `--output` to write a gitignored `omnibase/.env.<branch>` file " +
|
|
1468
|
+
"before `omnibase sync` or `omnibase cloud workers deploy`.\n\n" +
|
|
1469
|
+
"```bash\n" +
|
|
1470
|
+
"omnibase cloud branch env pr-123 --output omnibase/.env.pr-123\n" +
|
|
1471
|
+
"omnibase cloud branch env pr-123\n" +
|
|
1472
|
+
"```")
|
|
1473
|
+
.option("--project-id <id>", "Project ID")
|
|
1474
|
+
.option("--worker-domain <domain>", "Workers domain", "workers.omnibase.tech")
|
|
1475
|
+
.option("--cookie-domain <domain>", "Cookie domain")
|
|
1476
|
+
.option("--dashboard-url <url>", "Override the dashboard URL")
|
|
1477
|
+
.option("--output <path>", "Write dotenv output to a file")
|
|
1478
|
+
.action(async (branchRef, cmdOptions) => {
|
|
1479
|
+
try {
|
|
1480
|
+
await branchEnv(branchRef, cmdOptions);
|
|
1481
|
+
}
|
|
1482
|
+
catch (error) {
|
|
1483
|
+
await (0, errors_1.handleCommandError)(error);
|
|
1484
|
+
}
|
|
1485
|
+
});
|
|
1132
1486
|
branch
|
|
1133
1487
|
.command("list")
|
|
1134
1488
|
.summary("List project branches")
|
|
@@ -1154,15 +1508,20 @@ function addCloudCommands(program) {
|
|
|
1154
1508
|
.description("Delete a branch by name, slug, or ID. The branch is resolved against " +
|
|
1155
1509
|
"the project's branch list, then deprovisioning is started.\n\n" +
|
|
1156
1510
|
"This is destructive — the branch's database, workers, and services are " +
|
|
1157
|
-
"deprovisioned
|
|
1511
|
+
"deprovisioned. `--if-exists` makes a missing or already deleted branch " +
|
|
1512
|
+
"a no-op, which is useful in cleanup jobs.\n\n" +
|
|
1158
1513
|
"```bash\n" +
|
|
1159
1514
|
"omnibase cloud branch rm staging\n" +
|
|
1515
|
+
"omnibase cloud branch rm pr-123 --if-exists\n" +
|
|
1160
1516
|
"omnibase cloud branch rm br_123 --project-id proj_123\n" +
|
|
1161
1517
|
"```")
|
|
1162
1518
|
.option("--project-id <id>", "Project ID")
|
|
1519
|
+
.option("--if-exists", "Do not fail if the branch is missing or deleted")
|
|
1163
1520
|
.action(async (branchRef, cmdOptions) => {
|
|
1164
1521
|
try {
|
|
1165
|
-
await branchDelete(branchRef, cmdOptions.projectId
|
|
1522
|
+
await branchDelete(branchRef, cmdOptions.projectId, {
|
|
1523
|
+
ifExists: cmdOptions.ifExists,
|
|
1524
|
+
});
|
|
1166
1525
|
}
|
|
1167
1526
|
catch (error) {
|
|
1168
1527
|
await (0, errors_1.handleCommandError)(error);
|