diff --git a/.changeset/34622-cloud-home-url-console.md b/.changeset/34622-cloud-home-url-console.md new file mode 100644 index 00000000000..91671fccbad --- /dev/null +++ b/.changeset/34622-cloud-home-url-console.md @@ -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. diff --git a/.changeset/34622-cloud-home-url-server.md b/.changeset/34622-cloud-home-url-server.md new file mode 100644 index 00000000000..f97cb2d2844 --- /dev/null +++ b/.changeset/34622-cloud-home-url-server.md @@ -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. diff --git a/packages/cloud-connection/README.md b/packages/cloud-connection/README.md index 5046091ca00..1daff581946 100644 --- a/packages/cloud-connection/README.md +++ b/packages/cloud-connection/README.md @@ -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 { @@ -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 diff --git a/packages/cloud-connection/src/runtime-config-plugin.ts b/packages/cloud-connection/src/runtime-config-plugin.ts index 59a33550ac6..e83d0216bee 100644 --- a/packages/cloud-connection/src/runtime-config-plugin.ts +++ b/packages/cloud-connection/src/runtime-config-plugin.ts @@ -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 @@ -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). @@ -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 @@ -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(); @@ -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 @@ -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 } : {}), diff --git a/packages/cloud-connection/src/runtime-config-upgrade-url.test.ts b/packages/cloud-connection/src/runtime-config-upgrade-url.test.ts index 17f0334bca6..4a833271652 100644 --- a/packages/cloud-connection/src/runtime-config-upgrade-url.test.ts +++ b/packages/cloud-connection/src/runtime-config-upgrade-url.test.ts @@ -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'; @@ -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); + }); +}); diff --git a/ui/packages/app-shell/src/console/marketplace/MarketplacePackagePage.tsx b/ui/packages/app-shell/src/console/marketplace/MarketplacePackagePage.tsx index c3bd5ec30fb..c6f6fa05384 100644 --- a/ui/packages/app-shell/src/console/marketplace/MarketplacePackagePage.tsx +++ b/ui/packages/app-shell/src/console/marketplace/MarketplacePackagePage.tsx @@ -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'; @@ -1982,11 +1982,13 @@ function MarketplacePackagePageBody() {