Skip to content

Commit c1e3a93

Browse files
authored
host: Remove build-time realm URLs (#1527)
The only build-time realm configuration now is resolvedBaseRealmURL.
1 parent 37d00c8 commit c1e3a93

35 files changed

+292
-179
lines changed

packages/host/app/components/card-catalog/modal.gts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,8 @@ export default class CardCatalogModal extends Component<Signature> {
395395
dismissModal: false,
396396
query,
397397
originalQuery: query,
398-
availableRealmUrls: this.cardService.realmURLs,
399-
selectedRealmUrls: this.cardService.realmURLs,
398+
availableRealmUrls: this.cardService.unresolvedRealmURLs,
399+
selectedRealmUrls: this.cardService.unresolvedRealmURLs,
400400
});
401401
this.stateStack.push(cardCatalogState);
402402

packages/host/app/components/matrix/login.gts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ export default class Login extends Component<Signature> {
196196
throw e;
197197
}
198198
if (auth) {
199-
await this.router.refresh();
200199
await this.matrixService.start(auth);
200+
await this.router.refresh();
201201
} else {
202202
throw new Error(
203203
`bug: should be impossible to get here - successful matrix login with no auth response`,

packages/host/app/components/operator-mode/code-submode.gts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,10 +606,32 @@ export default class CodeSubmode extends Component<Signature> {
606606
if (!this.createFileModal) {
607607
throw new Error(`bug: CreateFileModal not instantiated`);
608608
}
609+
610+
let destinationRealm: string | undefined;
611+
612+
if (sourceInstance && this.realm.canWrite(sourceInstance.id)) {
613+
destinationRealm = this.realm.url(sourceInstance.id);
614+
}
615+
616+
if (
617+
definitionClass?.ref &&
618+
this.realm.canWrite(definitionClass.ref.module)
619+
) {
620+
destinationRealm = this.realm.url(definitionClass.ref.module);
621+
}
622+
623+
if (!destinationRealm && this.realm.defaultWritableRealm) {
624+
destinationRealm = this.realm.defaultWritableRealm.path;
625+
}
626+
627+
if (!destinationRealm) {
628+
throw new Error('No writable realm found');
629+
}
630+
609631
this.isCreateModalOpen = true;
610632
let url = await this.createFileModal.createNewFile(
611633
fileType,
612-
new URL(this.realm.userDefaultRealm.path),
634+
new URL(destinationRealm),
613635
definitionClass,
614636
sourceInstance,
615637
);

packages/host/app/components/operator-mode/workspace-chooser.gts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default class WorkspaceChooser extends Component<Signature> {
1414
<div class='workspace-chooser' data-test-workspace-chooser>
1515
<span class='workspace-chooser__title'>Your Workspaces</span>
1616
<ul>
17-
{{#each this.cardService.realmURLs as |realmURL|}}
17+
{{#each this.cardService.userRealms as |realmURL|}}
1818
<li class='workspace' data-test-workspace>{{realmURL}}</li>
1919
{{/each}}
2020
</ul>

packages/host/app/components/pill-menu/usage.gts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import { TrackedObject } from 'tracked-built-ins';
1010

1111
import { IconX } from '@cardstack/boxel-ui/icons';
1212

13-
import { getPlural } from '@cardstack/runtime-common';
14-
15-
import ENV from '@cardstack/host/config/environment';
13+
import { baseRealm, getPlural } from '@cardstack/runtime-common';
1614

1715
import { getCard } from '@cardstack/host/resources/card-resource';
1816

@@ -24,8 +22,10 @@ import PillMenu from './index';
2422

2523
import type { PillMenuItem } from './index';
2624

27-
const { ownRealmURL } = ENV;
28-
const sampleCardURLs = [`${ownRealmURL}Author/1`, `${ownRealmURL}BlogPost/1`];
25+
const sampleCardURLs = [
26+
`${baseRealm.url}SkillCard/card-editing`,
27+
`${baseRealm.url}SkillCard/generate-product-requirements`,
28+
];
2929

3030
export default class PillMenuUsage extends Component {
3131
headerIconURL = headerIcon;

packages/host/app/components/realm-dropdown.gts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,14 @@ export default class RealmDropdown extends Component<Signature> {
150150
return selectedRealm;
151151
}
152152

153+
let defaultWritableRealm = this.realm.defaultWritableRealm;
154+
155+
if (!defaultWritableRealm) {
156+
return undefined;
157+
}
158+
153159
return this.realms.find(
154-
(realm) => realm.path === this.realm.userDefaultRealm.path,
160+
(realm) => realm.path === defaultWritableRealm!.path,
155161
);
156162
}
157163
}

packages/host/app/components/search-sheet/card-query-results.gts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default class CardQueryResults extends Component<Signature> {
3030
@service declare cardService: CardService;
3131

3232
get realms() {
33-
return this.cardService.realmURLs;
33+
return this.cardService.unresolvedRealmURLs;
3434
}
3535
get query() {
3636
let { searchKey } = this.args;

packages/host/app/components/search-sheet/index.gts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export default class SearchSheet extends Component<Signature> {
174174
}
175175
let cardURL = this.searchKey;
176176

177-
let maybeIndexCardURL = this.cardService.realmURLs.find(
177+
let maybeIndexCardURL = this.cardService.unresolvedRealmURLs.find(
178178
(u) => u === cardURL + '/',
179179
);
180180
let cardResource = getCard(this, () => maybeIndexCardURL ?? cardURL, {

packages/host/app/components/with-known-realms-loaded.gts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default class WithKnownRealmsLoaded extends Component<Signature> {
2323
}
2424

2525
private loadRealmsTask = task(async () => {
26-
let realmURLs = this.cardService.realmURLs;
26+
let realmURLs = this.cardService.unresolvedRealmURLs;
2727
await Promise.all(
2828
realmURLs.map(
2929
async (realmURL) => await this.realm.ensureRealmMeta(realmURL),

packages/host/app/config/environment.d.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,13 @@ declare const config: {
1111
locationType: 'history' | 'hash' | 'none' | 'auto';
1212
rootURL: string;
1313
APP: Record<string, unknown>;
14-
ownRealmURL: string;
15-
otherRealmURLs: string[];
16-
testRealmURLs: string[];
1714
matrixURL: string;
1815
matrixServerName: string;
1916
experimentalAIEnabled: boolean;
2017
resolvedBaseRealmURL: string;
2118
hostsOwnAssets: boolean;
2219
realmsServed?: string[];
2320
logLevels: string;
24-
resolvedOwnRealmURL: string;
2521
autoSaveDelayMs: number;
2622
monacoDebounceMs: number;
2723
monacoCursorDebounceMs: number;

packages/host/app/controllers/card.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { tracked } from '@glimmer/tracking';
33

44
export default class CardController extends Controller {
55
queryParams = [
6+
'card',
67
'operatorModeState',
78
'operatorModeEnabled',
89
// `sid` and `clientSecret` come from email verification process to reset password

packages/host/app/resources/search.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class Search extends Resource<Args> {
3737

3838
modify(_positional: never[], named: Args['named']) {
3939
let { query, realms, isLive, doWhileRefreshing } = named;
40-
this.realmsToSearch = realms ?? this.cardService.realmURLs;
40+
this.realmsToSearch = realms ?? this.cardService.unresolvedRealmURLs;
4141

4242
this.loaded = this.search.perform(query);
4343
waitForPromise(this.loaded);

packages/host/app/router.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11
import EmberRouter from '@ember/routing/router';
22
import config from '@cardstack/host/config/environment';
3-
const { ownRealmURL, resolvedOwnRealmURL, hostsOwnAssets } = config;
3+
const { hostsOwnAssets } = config;
44

55
export default class Router extends EmberRouter {
66
location = config.locationType;
77
rootURL = config.rootURL;
88
}
99

10-
// When resolvedOwnRealmURL is available, that is actually the path in the browser.
11-
// It will not be available when running in fastboot.
12-
// When paths of resolvedOwnRealmURL and ownRealmURL are not symmetrical,
13-
// that means that means the resolvedOwnRealmURL should be used instead of ownRealmURL.
14-
let path = new URL(resolvedOwnRealmURL ?? ownRealmURL).pathname.replace(
15-
/\/$/,
16-
'',
17-
);
18-
1910
Router.map(function () {
2011
this.route('host-freestyle', { path: '/_freestyle' });
2112
this.route('indexer', { path: '/indexer/:id' });
@@ -25,7 +16,7 @@ Router.map(function () {
2516
// component exists to support the indexer
2617
this.route('acceptance-test-setup');
2718

28-
if (!path || hostsOwnAssets) {
19+
if (hostsOwnAssets) {
2920
this.route('index-card', { path: '/' });
3021
}
3122
});

packages/host/app/routes/card.gts

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ import MatrixService from '@cardstack/host/services/matrix-service';
1414
import OperatorModeStateService, {
1515
SerializedState as OperatorModeSerializedState,
1616
} from '@cardstack/host/services/operator-mode-state-service';
17+
import Realm from '@cardstack/host/services/realm';
1718
import RealmInfoService from '@cardstack/host/services/realm-info-service';
1819

1920
import { CardDef } from 'https://cardstack.com/base/card-api';
2021

2122
import type CardService from '../services/card-service';
2223

23-
const { ownRealmURL, loginMessageTimeoutMs } = ENV;
24+
const { hostsOwnAssets, loginMessageTimeoutMs, rootURL } = ENV;
2425

2526
export type Model = CardDef | null;
2627

@@ -47,35 +48,48 @@ export default class RenderCard extends Route<Model | null> {
4748
@service declare router: RouterService;
4849
@service declare operatorModeStateService: OperatorModeStateService;
4950
@service declare matrixService: MatrixService;
51+
@service declare realm: Realm;
5052
@service declare realmInfoService: RealmInfoService;
5153

5254
hasLoadMatrixBeenExecuted = false;
5355

5456
async model(params: {
57+
card?: string;
5558
path: string;
5659
operatorModeState: string;
5760
operatorModeEnabled: boolean;
5861
}): Promise<Model> {
5962
let { path, operatorModeState, operatorModeEnabled } = params;
6063
path = path || '';
61-
let url = path
62-
? new URL(`/${path}`, ownRealmURL)
63-
: new URL('./', ownRealmURL);
6464

6565
try {
6666
await this.loadMatrix.perform();
67-
let isPublicReadableRealm = await this.realmInfoService.isPublicReadable(
68-
new URL(ownRealmURL),
69-
);
67+
7068
let model = null;
71-
if (!isPublicReadableRealm && !this.matrixService.isLoggedIn) {
72-
return model;
73-
}
74-
let cardResource = getCard(this, () => url.href);
75-
await cardResource.loaded;
76-
model = cardResource.card;
77-
if (!model) {
78-
throw new Error(`Could not find ${url}`);
69+
70+
if (params.card) {
71+
let directlyRequestedCardResource = getCard(this, () => params.card);
72+
await directlyRequestedCardResource.loaded;
73+
74+
if (directlyRequestedCardResource?.card) {
75+
model = directlyRequestedCardResource.card;
76+
}
77+
} else if (!hostsOwnAssets) {
78+
let externalURL = new URL(document.location.href);
79+
let pathOnRoot = `${rootURL}${path}`;
80+
let prospectiveCardURL = new URL(pathOnRoot, externalURL);
81+
82+
let resource = getCard(this, () => prospectiveCardURL.href);
83+
await resource.loaded;
84+
85+
if (resource.card) {
86+
model = resource.card;
87+
}
88+
} else {
89+
let indexCardURL = new URL(this.realm.defaultReadableRealm.path);
90+
let indexCardResource = getCard(this, () => indexCardURL.href);
91+
await indexCardResource.loaded;
92+
model = indexCardResource.card;
7993
}
8094

8195
if (operatorModeEnabled) {
@@ -97,11 +111,8 @@ export default class RenderCard extends Route<Model | null> {
97111
return model ?? null;
98112
} catch (e) {
99113
console.error(e);
100-
(e as any).loadType = params.operatorModeEnabled
101-
? 'stack'
102-
: url.href === ownRealmURL
103-
? 'index'
104-
: 'card';
114+
115+
(e as any).loadType = params.operatorModeEnabled ? 'stack' : 'card';
105116
(e as any).operatorModeState = params.operatorModeState;
106117
throw e;
107118
}
@@ -112,16 +123,16 @@ export default class RenderCard extends Route<Model | null> {
112123
// so users will be redirected to operator mode.
113124
// We can update the codes below after we have a clear idea on how to implement authentication in guest mode.
114125
let isPublicReadableRealm = await this.realmInfoService.isPublicReadable(
115-
new URL(ownRealmURL),
126+
new URL(this.realm.defaultReadableRealm.path),
116127
);
117128
if (
118129
!isPublicReadableRealm &&
119130
!transition.to?.queryParams['operatorModeEnabled']
120131
) {
121132
let path = transition.to?.params?.path ?? '';
122133
let url = path
123-
? new URL(`/${path}`, ownRealmURL)
124-
: new URL('./', ownRealmURL);
134+
? new URL(`/${path}`, this.realm.defaultReadableRealm.path)
135+
: new URL('./', this.realm.defaultReadableRealm.path);
125136
await this.router.replaceWith(`card`, {
126137
queryParams: {
127138
operatorModeEnabled: 'true',

0 commit comments

Comments
 (0)