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
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@miakapp/cli",
"version": "4.3.0",
"version": "4.3.1",
"description": "Agent-first Miakapp command line: check, build, publish, activate and roll back home interfaces",
"type": "module",
"engines": {
Expand Down
18 changes: 12 additions & 6 deletions packages/cli/src/control-plane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,31 @@ export interface Discovery {
readonly pushAudience: string;
readonly componentsAudience: string;
/**
* `https://<trusted web origin>/app?home={home_id}` when the deployment
* `https://<trusted web origin>/app/{home_id}` (or `/h/{home_id}`, or the
* legacy `/app?home={home_id}`) when the deployment
* declares where residents open homes. The only source of a `home_url`; the
* artifact `url` is never a resident link.
*/
readonly homeUrlTemplate?: string;
}

const HOME_URL_SUFFIX = '/app?home={home_id}';
/** The home link shapes a Miakapp web app answers, newest first. */
const HOME_URL_SUFFIXES = ['/app/{home_id}', '/h/{home_id}', '/app?home={home_id}'] as const;

/**
* Accepts exactly `<canonical https origin>/app?home={home_id}`: no path, no
* Accepts exactly `<canonical https origin>` followed by one of
* HOME_URL_SUFFIXES: no other path, no
* credentials, no port games, nothing a server could use to point residents
* somewhere else under a plausible-looking link.
*/
export function parseHomeUrlTemplate(value: unknown): string {
if (typeof value !== 'string' || !value.endsWith(HOME_URL_SUFFIX)) {
throw contractError('home_url_template is not <origin>/app?home={home_id}');
const suffix = typeof value === 'string'
? HOME_URL_SUFFIXES.find((candidate) => value.endsWith(candidate))
: undefined;
if (typeof value !== 'string' || suffix === undefined) {
throw contractError('home_url_template is not <origin>/app/{home_id}');
}
const origin = value.slice(0, -HOME_URL_SUFFIX.length);
const origin = value.slice(0, -suffix.length);
canonicalHttpsUrl(origin, 'home_url_template origin');
if (new URL(origin).origin !== origin) {
throw contractError('home_url_template must be rooted at a bare origin');
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
*/
export const PACKAGE_NAME = '@miakapp/cli';

export const CLI_VERSION = '4.3.0';
export const CLI_VERSION = '4.3.1';
9 changes: 8 additions & 1 deletion packages/cli/test/app-publication.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,13 @@ describe('app manifest', () => {
});

describe('discovery home link', () => {
test('accepts exactly <origin>/app?home={home_id}', () => {
test('accepts exactly <origin>/app/{home_id}, /h/{home_id} or the legacy ?home=', () => {
expect(parseHomeUrlTemplate(TEMPLATE)).toBe(TEMPLATE);
for (const current of ['https://app.example.test/app/{home_id}', 'https://app.example.test/h/{home_id}']) {
expect(parseHomeUrlTemplate(current)).toBe(current);
}
expect(homeUrl({ homeUrlTemplate: 'https://app.example.test/app/{home_id}' }, 'maison-a'))
.toBe('https://app.example.test/app/maison-a');
expect(homeUrl({ homeUrlTemplate: TEMPLATE }, 'maison-a')).toBe('https://app.example.test/app?home=maison-a');
expect(homeUrl({}, 'maison-a')).toBeNull();
for (const bad of [
Expand All @@ -67,6 +72,8 @@ describe('discovery home link', () => {
'https://app.example.test/app?home={home_id}&next=https://evil.example',
'https://app.example.test/v1/components/{home_id}.js',
'https://app.example.test/app?home=fixed',
'https://app.example.test/x/app/{home_id}',
'https://app.example.test/app/{home_id}/extra',
]) {
expect(() => parseHomeUrlTemplate(bad)).toThrow();
}
Expand Down
Loading