Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/34622-cloud-home-url-console.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@object-ui/app-shell': patch
---

feat(app-shell): the marketplace "Open on Cloud" link opens the runtime's declared `cloudHomeUrl`

Clause-②: yes (widening)
Metadata-protocol: none

The Console reads the top-level `cloudHomeUrl` from `GET /api/v1/runtime/config` as served (an absent, empty or non-string value stays absent; nothing is composed in its place) and exposes it as `getCloudHomeUrl()`. The install dialog's "Open on Cloud" link, shown when the caller's cloud environments cannot be listed, opens it when it is declared.

When the runtime declares no `cloudHomeUrl`, the link behaves as before: it opens `cloudConsoleUrl()`, and it is not drawn on a runtime that names no upstream cloud.
16 changes: 16 additions & 0 deletions .changeset/34622-cloud-home-url-server.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
'@objectstack/cloud-connection': patch
---

feat(cloud-connection): `RuntimeConfigPlugin` serves a declared `cloudHomeUrl`

Clause-②: yes (widening)
Metadata-protocol: none

`RuntimeConfigPluginConfig` takes a new optional `cloudHomeUrl`: the absolute URL of the control plane's console home page. When a host declares it, `GET /api/v1/runtime/config` serves it verbatim as a top-level `cloudHomeUrl`, beside `cloudUrl` and `upgradeUrl`. It follows the `upgradeUrl` contract:

- Host option only. There is no env var: the distribution whose control plane serves the page fills it.
- Absent by default. An unset, empty or whitespace-only value serves no key at all, never `""` or a guessed default.
- Absolute or refused. A relative path or a non-`http(s)` scheme is not served, and the mount log names the option and the refused value.

Nothing changes for a host that does not declare it.
4 changes: 3 additions & 1 deletion packages/cloud-connection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ the **absolute** URL of the control plane's upgrade / billing page — beside th
| Key | Type | Default | Meaning |
|---|---|---|---|
| `upgradeUrl` | absolute `http(s)` URL | **absent** | Where the Console sends a user who chooses "upgrade" (AI quota exhausted, plan limit hit). Declared by the host that owns the page and served verbatim; no key means "render no link". |
| `cloudHomeUrl` | absolute `http(s)` URL | **absent** | The control plane's console home page, opened by the marketplace's "Open on Cloud" link. Same contract as `upgradeUrl`: host option only, served verbatim, refused at mount when not absolute; no key means the link keeps its `cloudUrl` target. |

```json
{
Expand All @@ -159,7 +160,8 @@ Why it is published rather than composed by the Console: the destination
depends on the console mount, the app slug and the page route — three facts
owned by whoever deploys the control plane — and a consumer in another repo
that guessed them landed on the control plane's API 404. Three properties,
pinned by `runtime-config-upgrade-url.test.ts`:
pinned by `runtime-config-upgrade-url.test.ts` (which pins `cloudHomeUrl` to
the same three):

- **Absent by default.** A vanilla `objectstack dev`, a self-hosted box and an
air-gapped deployment have no billing page. They serve no `upgradeUrl` key at
Expand Down
61 changes: 61 additions & 0 deletions packages/cloud-connection/src/runtime-config-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* {
* cloudUrl: string, // base URL of the upstream cloud ('' = same origin)
* upgradeUrl?: string, // absolute URL of the control plane's upgrade / billing entry — absent unless declared (#14514)
* cloudHomeUrl?: string, // absolute URL of the control plane's console home page — absent unless declared (#34622)
* mapStyleUrl?: string, // the deployment's default map style (OS_CONSOLE_MAP_STYLE_URL) — absent unless set (#26001)
* singleEnvironment: boolean,
* defaultOrgId?, defaultEnvironmentId?, // multi-tenant, per-hostname
Expand Down Expand Up @@ -726,6 +727,35 @@ export interface RuntimeConfigPluginConfig {
* whose control plane serves the page; the cloud subclass fills it.
*/
upgradeUrl?: string;
/**
* Absolute URL of the control plane's console home page, served verbatim
* as the top-level `cloudHomeUrl` key beside `cloudUrl` and `upgradeUrl`
* (#34622).
*
* The tenant Console's marketplace offers an "Open on Cloud" exit when it
* cannot list the caller's cloud environments. Without this key it opens
* `cloudUrl` itself — the control plane's origin, whose landing may route
* a signed-in user straight back into the environment they came from. The
* page that IS the control plane's console home belongs to whoever deploys
* it, so it is declared here by that host, exactly as `upgradeUrl` is
* (maintainer ruling cloud#1850, option A's shape), and the Console opens
* it when the key is present.
*
* ⛔ Default **absent**: unset serves no `cloudHomeUrl` key at all, never an
* empty string or a guessed default. A vanilla `objectstack dev`, a
* self-hosted box and an air-gapped deployment have no control-plane
* console, and the Console reads "no key" as "keep today's link".
* Empty / whitespace-only reads as unset (absent, silent).
*
* ⛔ Must be ABSOLUTE (`http:` / `https:`). A relative path such as
* `/_console` is refused and named at mount time, never forwarded: the
* Console opens this URL from the TENANT origin, where a relative path
* would resolve against the tenant runtime instead of the control plane.
*
* Host option only — no env var. The value belongs to the distribution
* whose control plane serves the page; the cloud subclass fills it.
*/
cloudHomeUrl?: string;
/**
* CEILING for the `features.installLocal` flag — no longer its source
* (#8388).
Expand Down Expand Up @@ -895,6 +925,10 @@ export class RuntimeConfigPlugin implements Plugin {
private readonly upgradeUrl: string | undefined;
/** The refused spelling, kept so `start()` can name it once — same reason as `refusedStage`. */
private readonly refusedUpgradeUrl: string | undefined;
/** The declared console home page, or `undefined` for "send no key" (unset or refused). */
private readonly cloudHomeUrl: string | undefined;
/** The refused spelling, kept so `start()` can name it once — same reason as `refusedStage`. */
private readonly refusedCloudHomeUrl: string | undefined;
/**
* The deployment's default map style (`OS_CONSOLE_MAP_STYLE_URL`), or
* `undefined` for "send no key". Read in `start()`, which refuses a bad
Expand Down Expand Up @@ -966,6 +1000,19 @@ export class RuntimeConfigPlugin implements Plugin {
this.refusedUpgradeUrl = requestedUpgradeUrl !== undefined && this.upgradeUrl === undefined
? requestedUpgradeUrl
: undefined;
// Control-plane console home page (#34622): the same contract as
// `upgradeUrl` above — empty reads as unset, a value that is not an
// absolute http(s) URL is refused and named at mount, an accepted one
// is kept verbatim.
const requestedCloudHomeUrl = typeof config.cloudHomeUrl === 'string' && config.cloudHomeUrl.trim() !== ''
? config.cloudHomeUrl
: undefined;
this.cloudHomeUrl = requestedCloudHomeUrl !== undefined && isAbsoluteHttpUrl(requestedCloudHomeUrl)
? requestedCloudHomeUrl
: undefined;
this.refusedCloudHomeUrl = requestedCloudHomeUrl !== undefined && this.cloudHomeUrl === undefined
? requestedCloudHomeUrl
: undefined;
const envLogoUrl = (typeof process !== 'undefined' ? process.env?.OS_LOGO_URL : undefined)?.trim();
const envFaviconUrl = (typeof process !== 'undefined' ? process.env?.OS_FAVICON_URL : undefined)?.trim();
const envBrandColor = (typeof process !== 'undefined' ? process.env?.OS_BRAND_COLOR : undefined)?.trim();
Expand Down Expand Up @@ -1073,6 +1120,17 @@ export class RuntimeConfigPlugin implements Plugin {
);
}

// The same refusal for the control plane's console home page
// (#34622): declared, refused rather than coerced, and named once.
if (this.refusedCloudHomeUrl !== undefined) {
ctx.logger?.warn?.(
`[RuntimeConfigPlugin] ignoring cloudHomeUrl ${JSON.stringify(this.refusedCloudHomeUrl)} `
+ `(the \`cloudHomeUrl\` option): it must be an absolute http(s) URL — the Console opens it `
+ `from the tenant origin, so a relative path would resolve against the wrong host. `
+ `No cloudHomeUrl key is served and the Console's "Open on Cloud" link keeps its default target.`,
);
}

// Telemetry knobs the operator got wrong (#12681). Same shape and
// same reason as the stage refusal above: they meant to CONFIGURE
// something, the value was not understood, and it was refused
Expand Down Expand Up @@ -1204,6 +1262,9 @@ export class RuntimeConfigPlugin implements Plugin {
// link", so a present-and-undefined property must never
// reach a non-JSON consumer or a test.
...(this.upgradeUrl !== undefined ? { upgradeUrl: this.upgradeUrl } : {}),
// Declared by the host, never derived (#34622); spread for
// the same key-presence reason.
...(this.cloudHomeUrl !== undefined ? { cloudHomeUrl: this.cloudHomeUrl } : {}),
// The operator's default map style (#26001); spread for
// the same key-presence reason.
...(this.mapStyleUrl !== undefined ? { mapStyleUrl: this.mapStyleUrl } : {}),
Expand Down
71 changes: 71 additions & 0 deletions packages/cloud-connection/src/runtime-config-upgrade-url.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
* ABSOLUTE http(s) URL. A relative path is the defect this key exists to remove
* (opened from the tenant origin it resolves against the wrong host), so it is
* refused and named at mount, never forwarded.
*
* The last top-level group pins `cloudHomeUrl` (#34622), the control plane's
* console home page, which the producer holds to the same contract.
*/

import { describe, it, expect } from 'vitest';
Expand Down Expand Up @@ -197,3 +200,71 @@ describe('RuntimeConfigPlugin — upgradeUrl (#14514)', () => {
});
});
});

/** The second declared control-plane address: the console home page (#34622). */
function hasCloudHomeUrlKey(body: any): boolean {
return Object.prototype.hasOwnProperty.call(body, 'cloudHomeUrl');
}

/** The shape the cloud distribution will declare — the control plane's console mount. */
const CLOUD_HOME = 'https://cloud.example.com/_console/';

describe('RuntimeConfigPlugin — cloudHomeUrl (#34622), the same contract as upgradeUrl', () => {
it('declared: served verbatim at the top level beside cloudUrl and upgradeUrl, silently', async () => {
const { body, warnings } = await serve({
controlPlaneUrl: 'https://cloud.example.com',
upgradeUrl: PRICING,
cloudHomeUrl: CLOUD_HOME,
});
expect(hasCloudHomeUrlKey(body)).toBe(true);
expect(body.cloudHomeUrl).toBe(CLOUD_HOME);
expect(body.cloudUrl).toBe('https://cloud.example.com');
expect(body.upgradeUrl).toBe(PRICING);
expect(Object.keys(body.features)).not.toContain('cloudHomeUrl');
expect(Object.keys(body.branding)).not.toContain('cloudHomeUrl');
expect(JSON.parse(JSON.stringify(body)).cloudHomeUrl).toBe(CLOUD_HOME);
expect(warnings).toEqual([]);
});

it('declared: verbatim — no trailing-slash trimming, no case folding, no re-serialisation', async () => {
const spelled = 'http://Cloud.Example.com:8443/_console/?from=marketplace#home';
const { body } = await serve({ cloudHomeUrl: spelled });
expect(body.cloudHomeUrl).toBe(spelled);
});

it('absent: no key at all when nothing declared it, and nothing derived from cloudUrl or upgradeUrl', async () => {
const { body, warnings } = await serve({ controlPlaneUrl: 'https://cloud.example.com', upgradeUrl: PRICING });
expect(hasCloudHomeUrlKey(body)).toBe(false);
expect(Object.prototype.hasOwnProperty.call(JSON.parse(JSON.stringify(body)), 'cloudHomeUrl')).toBe(false);
expect(warnings).toEqual([]);
});

it.each(['', ' '])('empty: a declaration of %j reads as unset — absent, and silent', async (value) => {
const { body, warnings } = await serve({ cloudHomeUrl: value });
expect(hasCloudHomeUrlKey(body)).toBe(false);
expect(warnings).toEqual([]);
});

it.each([
'/_console',
'_console/',
'cloud.example.com/_console',
'javascript:alert(1)',
'ftp://cloud.example.com/_console',
])('refused: %j is not served, and the mount names the option and the value', async (value) => {
const { body, warnings } = await serve({ cloudHomeUrl: value });
expect(hasCloudHomeUrlKey(body)).toBe(false);
const warning = warnings.find((w) => w.includes('cloudHomeUrl'));
expect(warning).toBeDefined();
expect(warning).toContain(JSON.stringify(value));
expect(warning).toContain('absolute');
});

it('a refused cloudHomeUrl leaves a declared upgradeUrl and the rest of the payload untouched', async () => {
const { body, warnings } = await serve({ upgradeUrl: PRICING, cloudHomeUrl: '/_console' });
expect(body.upgradeUrl).toBe(PRICING);
expect(body.cloudUrl).toBe('');
expect(body.features.aiStudio).toBe(true);
expect(warnings.some((w) => w.includes('upgradeUrl'))).toBe(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ import {
takeClearConfirmRequest,
} from './sampleDataNotice.js';
import { SampleDataLeaveBanner } from './SampleDataLeaveBanner.js';
import { getCloudBase, getRuntimeConfig, isMarketplaceEnabled } from '../../runtime-config.js';
import { getCloudBase, getCloudHomeUrl, getRuntimeConfig, isMarketplaceEnabled } from '../../runtime-config.js';
import { emitMetadataRefresh } from '../../assistant/assistantBus.js';
import { useMetadata } from '../../providers/MetadataProvider.js';
import { appRouteSegment, filterActiveApps } from '../../utils/index.js';
Expand Down Expand Up @@ -1982,11 +1982,13 @@ function MarketplacePackagePageBody() {
<AlertCircle className="h-4 w-4 mt-0.5 text-amber-600" aria-hidden="true" />
<div className="flex-1">{envsError}</div>
</div>
{/* Only when the runtime named an upstream cloud. An empty base
used to fall back to a composed vendor URL that 404'd
{/* The control plane's declared console home page when the
runtime serves one (objectstack#34622), else the upstream
cloud's origin, and only when the runtime named one. An empty
base used to fall back to a composed vendor URL that 404'd
(objectui#7253); an `href=""` would reload this page. */}
{cloudConsoleUrl() ? (
<a href={cloudConsoleUrl()} target="_blank" rel="noopener noreferrer">
{(getCloudHomeUrl() ?? cloudConsoleUrl()) ? (
<a href={getCloudHomeUrl() ?? cloudConsoleUrl()} target="_blank" rel="noopener noreferrer">
<Button variant="outline" size="sm" className="w-full">
<ExternalLink className="h-4 w-4 mr-1.5" aria-hidden="true" />
{t('marketplace.action.openOnCloud')}
Expand Down
Loading
Loading