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
19 changes: 19 additions & 0 deletions .changeset/34722-installed-apps-updates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
'@object-ui/app-shell': patch
'@object-ui/i18n': patch
---

feat(app-shell): Setup › Installed Apps shows which apps have a newer version, links to their upgrade, and folds module packages under their app

Clause-②: yes (widening — locale keys only)
Metadata-protocol: none

Setup › Installed Apps (the Packages page opened with `?source=marketplace`) is now the administrator's view of installed apps:

- **Update available.** When the marketplace lists an app at a higher version than the one installed, the app's line shows the marketplace's own "Update available → vX" badge, decided by the same rule the marketplace pages use. The badge links to the app's marketplace page, where the upgrade runs unchanged. The page also says how many apps have a newer version. An app that is up to date, or that the catalog does not list, has no badge.
- **Catalog unavailable.** When the catalog cannot be read, or the runtime has no marketplace, the list is drawn as before with one line saying the update information cannot be read. It is never drawn as "up to date".
- **One line per app.** A module package (`type: 'module'`) that declares its app in `manifest.dependencies` is folded under that app's line and shown on demand. The tie is the one the server's disable door already reads. No new key is involved.
- **Administrator columns.** The columns are Name, Version, Status, Source and Update. The package id and the Scope badge stay on Studio's Packages.
- **Developer doors stay in Studio.** Import, New Package, the platform packages switch and the Source chip's "Show all" are not drawn on this view. Studio › Overview › Packages, the same page without `source`, keeps all of them.

The badge's words stay in the lazy `marketplace` namespace, which this view now loads. The console's eager language pack does not grow. Nine new strings are added to the lazy `studio` namespace, in English and Chinese.
6 changes: 4 additions & 2 deletions content/docs/deployment/marketplace-handbook.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ the detail.
with `?keepData=true` every row stays, sample rows included, and no door
tells them apart any more, so purge first if you want them gone.
7. **Enable and disable.** **Setup → Installed Apps** lists the apps installed
from the marketplace, each package of a suite as its own row. An admin with
from the marketplace, one line per app: a module package that declares
exactly one installed app in its `manifest.dependencies` is folded under
that app's line, and the app's toggle shows it. An admin with
`manage_metadata` may disable a writable package, and a **module of an
installed app**: a `type: 'module'` package that declares an installed
`type: 'app'` package in its `manifest.dependencies`
Expand Down Expand Up @@ -296,7 +298,7 @@ An app ships extras in one of two shapes:
A customer who does not use one of your modules can switch it off, per
environment, with `PATCH /api/v1/packages/:id/disable`, and back on with
`PATCH /api/v1/packages/:id/enable`. In the Console, the admin opens the
module's row in **Setup → Installed Apps** (or **Setup → Packages** for a suite
module's row under its app's line in **Setup → Installed Apps** (or **Setup → Packages** for a suite
booted from code) and presses **Disable**, then confirms. The row's
`disableable` key on `GET /api/v1/packages` is the runtime's own answer to
whether the disable door accepts the package, and the Console offers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@
* 3. walks every OTHER door's relative imports inside this directory
* (transitively) and holds that every `marketplace.*` key those files
* spell is in the RESIDENT pack — the package entry's `en`, which holds no
* namespace key.
* namespace key;
* 4. treats a door as gated by its importers only when it is DECLARED in
* {@link HOOK_GATED_DOORS}: every file outside this directory that imports
* it is listed there, and each listed file asks for the namespace itself
* (`useMarketplaceNamespace()`), drawing the door's component only once it
* is ready (objectstack#34722). An undeclared importer makes the door an
* ordinary ungated one again, so step 3 reads its keys.
*
* TypeScript's own parser reads the sources, so a key or an import written in
* a comment is never read as code.
Expand All @@ -42,6 +48,22 @@ const rel = (file: string) => relative(UI_ROOT, file).split(sep).join('/');
/** The pages behind the frame: what reaches them is gated by construction. */
const GATED_PAGES = ['MarketplacePage.tsx', 'MarketplacePackagePage.tsx'].map((f) => join(MARKETPLACE_DIR, f));

/**
* Doors whose every outside importer asks for the namespace itself, door by
* door (step 4): the door file, then the files allowed to import it.
*/
const HOOK_GATED_DOORS = new Map<string, readonly string[]>([
[
join(MARKETPLACE_DIR, 'UpdateAvailableBadge.tsx'),
// Setup → Installed Apps draws the badge in its Update cell (objectstack#34722).
['packages/app-shell/src/views/metadata-admin/PackagesPage.tsx'],
],
]);

/** The namespace module, and the hook a hook-gated importer must call from it. */
const NAMESPACE_MODULE = '@object-ui/i18n/namespaces/marketplace';
const NAMESPACE_HOOK = 'useMarketplaceNamespace';

const isSource = (name: string) =>
/\.(ts|tsx)$/.test(name) && !/\.(test|spec)\.(ts|tsx)$/.test(name) && !name.endsWith('.d.ts');

Expand Down Expand Up @@ -155,10 +177,48 @@ for (const file of allSources()) {
}
}

/**
* A declared hook-gated door whose outside importers are all declared for it
* and all call the namespace hook (step 4); anything less leaves it ungated.
*/
const isHookGated = (file: string) => {
const allowed = HOOK_GATED_DOORS.get(file);
return (
!!allowed &&
[...(doors.get(file) ?? [])].every(
(importer) => allowed.includes(importer) && callsNamespaceHook(join(UI_ROOT, importer)),
)
);
};

/** Whether `file` imports {@link NAMESPACE_HOOK} from {@link NAMESPACE_MODULE} and calls it. */
function callsNamespaceHook(file: string): boolean {
const sf = parse(file);
let imported = false;
let called = false;
const visit = (node: ts.Node) => {
if (
ts.isImportDeclaration(node) &&
ts.isStringLiteral(node.moduleSpecifier) &&
node.moduleSpecifier.text === NAMESPACE_MODULE &&
node.importClause?.namedBindings &&
ts.isNamedImports(node.importClause.namedBindings) &&
node.importClause.namedBindings.elements.some((e) => e.name.text === NAMESPACE_HOOK && !e.propertyName)
) {
imported = true;
} else if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === NAMESPACE_HOOK) {
called = true;
}
ts.forEachChild(node, visit);
};
visit(sf);
return imported && called;
}

/** Every file in this directory reachable from an ungated door, following relative imports inside it. */
const ungated = new Set<string>();
{
const queue = [...doors.keys()].filter((file) => !GATED_PAGES.includes(file));
const queue = [...doors.keys()].filter((file) => !GATED_PAGES.includes(file) && !isHookGated(file));
while (queue.length > 0) {
const file = queue.pop()!;
if (ungated.has(file) || GATED_PAGES.includes(file)) continue;
Expand Down Expand Up @@ -218,6 +278,23 @@ describe('the marketplace namespace boundary (objectstack#30588)', () => {
expect(outside).toEqual([]);
});

it.each([...HOOK_GATED_DOORS].map(([door, importers]) => [rel(door), door, importers] as const))(
'%s is drawn only by importers that ask for the namespace themselves (objectstack#34722)',
(_name, door, importers) => {
// Lit control: the door really is imported from outside this directory.
const actual = [...(doors.get(door) ?? [])];
expect(actual.length).toBeGreaterThan(0);
// Every outside importer is declared for it — an undeclared one would
// draw the door's keys without the namespace.
expect(actual.filter((importer) => !importers.includes(importer))).toEqual([]);
for (const importer of importers) {
expect(callsNamespaceHook(join(UI_ROOT, importer)), `${importer} calls ${NAMESPACE_HOOK}()`).toBe(true);
}
// And the door is outside the resident-key walk only because of this.
expect(ungated.has(door)).toBe(false);
},
);

it('the probe key the frame waits on is NOT resident (the pack really is lighter)', () => {
expect(lookup(en, 'marketplace.title')).toBeUndefined();
expect(typeof lookup(en, 'marketplace.action.uninstall')).toBe('string');
Expand Down
Loading
Loading