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
16 changes: 16 additions & 0 deletions .changeset/install-sample-language-and-counts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
"@objectstack/cloud-connection": patch
"@object-ui/app-shell": patch
"@object-ui/i18n": patch
---

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

The widening: a new read-only route, `GET /api/v1/marketplace/install-local/seed-locale`, served to `manage_metadata` holders, and a new `objects` member on the install answer's `seeded`; nothing that was served before changes.

The local marketplace install confirm now names the language an app's sample records will load in, when the app ships them per language. It asks the runtime first: `GET /api/v1/marketplace/install-local/seed-locale?appDefaultLocale=` answers `{ locale, source }` from the install's own choice (the organization's language setting, then the installing user's language, then the app's declared default). When that language is not the one the administrator reads the console in, the confirm says so and links to Language & Region, where the organization's language is set. The order of that choice is unchanged.

The install answer's `seeded` gains `objects`: the run split by object, whether the package defines each object, and why each skipped row was not written (`existing`, `withdrawn`, `noRowToUpdate`). The install note now counts only the package's own records as sample records, so it agrees with the clear and the sample-data count. Rows written to an object the package does not define (a platform object's timeline pointers) and updates that found no record are named instead of counted. "Already here, or deleted after an earlier load" is said only for rows where that is true. `inserted`, `updated` and `skipped` keep their meaning, and a runtime without `objects` is read as before.

A reinstall confirm opens with a reinstall's line, and no longer suggests an Everyone grant the administrator already accepted.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* nine doors refuse on it; `/status` reads it only to decide what it
* serves (#24148) and refuses no one.
* - `MarketplaceInstallLocalPlugin` reads it in ONE place
* (`resolveInstallPrincipal`), and all six doors answer a held session
* (`resolveInstallPrincipal`), and all seven doors answer a held session
* through the same refusal (`refuseHeldSession`).
*
* Each consults `evaluateAuthGate` (`@objectstack/core`) once, with no request
Expand Down Expand Up @@ -392,14 +392,15 @@ async function mountInstallLocal(storageDir: string) {
};
}

/** The six doors, addressed with what each needs to act. */
/** The seven doors, addressed with what each needs to act. */
const IL_DOORS = [
{ route: `POST ${IL}`, body: { manifest: APP } },
{ route: `GET ${IL}`, body: {} },
{ route: `DELETE ${IL}/:manifestId`, body: {} },
{ route: `POST ${IL}/:manifestId/reseed-sample-data`, body: {} },
{ route: `POST ${IL}/:manifestId/purge-sample-data`, body: {} },
{ route: `GET ${IL}/:manifestId/sample-data`, body: {} },
{ route: `GET ${IL}/seed-locale`, body: {} },
] as const;

/** Install the app as the un-held operator, so the follow-on doors have a target. */
Expand All @@ -411,15 +412,15 @@ async function seedInstall(storageDir: string) {
}

describe('ADR-0069 at MarketplaceInstallLocalPlugin', () => {
it('census: six routes, none allow-listed, all six covered below', async () => {
it('census: seven routes, none allow-listed, all seven covered below', async () => {
const { rawApp } = await mountInstallLocal(dir);
const keys = [...rawApp.routes.keys()].sort();
expect(keys).toEqual(IL_DOORS.map((d) => d.route).sort());
for (const key of keys) expect(isAuthGateAllowlisted(key.split(' ')[1]), key).toBe(false);
});

for (const { user, gate } of HELD) {
it(`HELD (${gate.code}): all six doors answer 403 with the gate's code, before any effect and before the ledger is touched`, async () => {
it(`HELD (${gate.code}): all seven doors answer 403 with the gate's code, before any effect and before the ledger is touched`, async () => {
await seedInstall(dir);
const ledgerBefore = existsSync(join(dir, LEDGER_FILE));
const { rawApp, effects } = await mountInstallLocal(dir);
Expand All @@ -442,6 +443,9 @@ describe('ADR-0069 at MarketplaceInstallLocalPlugin', () => {
const counted = await rawApp.routes.get(`GET ${IL}/:manifestId/sample-data`)!(makeC(`http://localhost${IL}`, 'u_member', {}, APP.id));
expect(counted.status, JSON.stringify(counted.payload)).toBe(200);
expect(counted.payload.success).toBe(true);
const language = await rawApp.routes.get(`GET ${IL}/seed-locale`)!(makeC(`http://localhost${IL}`, 'u_member'));
expect(language.status, JSON.stringify(language.payload)).toBe(200);
expect(language.payload.success).toBe(true);
for (const route of [`POST ${IL}/:manifestId/reseed-sample-data`, `POST ${IL}/:manifestId/purge-sample-data`, `DELETE ${IL}/:manifestId`]) {
const res = await rawApp.routes.get(route)!(makeC(`http://localhost${IL}`, 'u_member', {}, APP.id));
expect(res.status, `${route}: ${JSON.stringify(res.payload)}`).toBe(200);
Expand Down
12 changes: 12 additions & 0 deletions packages/cloud-connection/src/cloud-connection-route-ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,18 @@ export const CLOUD_CONNECTION_ROUTE_LEDGER: readonly CloudConnectionRouteLedgerE
+ 'takes no query parameter. Behind `manage_metadata`, the purge\'s gate, since it exists to tell an operator '
+ 'what a purge would remove; no `@objectstack/client` method builds this URL, for the reason purge has none.',
},
{
route: 'GET /api/v1/marketplace/install-local/seed-locale',
family: 'marketplace-install-local',
mountedIn: 'marketplace-install-local-plugin.ts',
disposition: 'server-only',
note:
'the read-only language an install would load locale-scoped sample data in, and which rung chose it '
+ '(the runtime\'s `resolveSeedLocaleForLoad`, the install\'s own resolver), so the Console\'s install confirm '
+ 'names it before the install. Its one query parameter is the package\'s declared default locale. Behind '
+ '`manage_metadata`, the install\'s gate, and writes nothing; no `@objectstack/client` method builds it, for the '
+ 'reason the install has none.',
},

// ── marketplace browse passthrough ─────────────────────────────────
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,15 @@ function withKey(
};
}

/** The six doors, addressed with what each needs to act. */
/** The seven doors, addressed with what each needs to act. */
const IL_DOORS = [
{ route: `POST ${IL}`, body: { manifest: APP } },
{ route: `GET ${IL}`, body: {} },
{ route: `DELETE ${IL}/:manifestId`, body: {} },
{ route: `POST ${IL}/:manifestId/reseed-sample-data`, body: {} },
{ route: `POST ${IL}/:manifestId/purge-sample-data`, body: {} },
{ route: `GET ${IL}/:manifestId/sample-data`, body: {} },
{ route: `GET ${IL}/seed-locale`, body: {} },
] as const;

let dir: string;
Expand All @@ -243,7 +244,7 @@ afterEach(() => {
});

describe('install-local doors — a key answers as its owner\'s session does (#23455, ruling C′)', () => {
it('REFUSES a key whose owner holds MFA_REQUIRED on all six doors, with the session\'s 403 code and message, before any effect', async () => {
it('REFUSES a key whose owner holds MFA_REQUIRED on all seven doors, with the session\'s 403 code and message, before any effect', async () => {
const postures: Record<string, Posture[]> = {};
const m = await mountInstallLocal(dir, postures);
// Installed by the same key while its owner is not held, so the
Expand Down
78 changes: 74 additions & 4 deletions packages/cloud-connection/src/marketplace-install-local-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,14 @@ import {
} from '@objectstack/metadata-protocol';
import { resolveThrownHttpError, type ThrownHttpError } from '@objectstack/types';
import { unknownQueryParamRefusalMessage } from '@objectstack/rest';
import {
describeSeedTally,
packageObjectNames,
resolveSeedLocaleForPreview,
SEED_LOCALE_QUERY_PARAMS,
tallySeedObjects,
type SeedObjectTally,
} from './marketplace-install-seed-report.js';
import { composedClusterDriver, declaresMultiReplicaOnRedis, MULTI_REPLICA_PACKAGE_CHANGE_REFUSED } from '@objectstack/service-cluster';

/** What the auth service's in-process session read answers, as `AuthSessionApi` declares it. */
Expand Down Expand Up @@ -2132,9 +2140,12 @@ export class MarketplaceInstallLocalPlugin implements Plugin {
const reseedHandler = async (c: any) => this.handleReseed(c, ctx);
const purgeHandler = async (c: any) => this.handlePurge(c, ctx);
const sampleDataCountHandler = async (c: any) => this.handleSampleDataCount(c, ctx);
const seedLocaleHandler = async (c: any) => this.handleSeedLocale(c, ctx);

if (typeof rawApp.post === 'function') rawApp.post(ROUTE_BASE, postHandler);
if (typeof rawApp.get === 'function') rawApp.get(ROUTE_BASE, getHandler);
// [#39681] Before `/:manifestId` routes, so `seed-locale` is never read as a manifest id.
if (typeof rawApp.get === 'function') rawApp.get(`${ROUTE_BASE}/seed-locale`, seedLocaleHandler);
if (typeof rawApp.get === 'function') rawApp.get(`${ROUTE_BASE}/:manifestId/sample-data`, sampleDataCountHandler);
if (typeof rawApp.delete === 'function') rawApp.delete(`${ROUTE_BASE}/:manifestId`, deleteHandler);
if (typeof rawApp.post === 'function') {
Expand Down Expand Up @@ -7157,6 +7168,49 @@ export class MarketplaceInstallLocalPlugin implements Plugin {
* `count: 0` for a copy made without the sample data, the purge's
* `503` for a receipt that was not read.
*/
/**
* [#39681] `GET …/install-local/seed-locale?appDefaultLocale=` — the
* language an install run now would load locale-scoped sample data in,
* and which rung chose it, so the install confirm names it before the
* install. The same resolver and the same inputs as the install's own
* seed (`runInlineSeed`): the caller's active organization, the caller,
* and the package's declared default, which the confirm reads off the
* body it is about to install. Behind the install's gate; it writes
* nothing. A settings or user read that throws is a `500`, never a guess.
*/
private handleSeedLocale = async (c: any, ctx: PluginContext): Promise<Response> => {
const admission = await this.requireInstallCapability(c, ctx, 'Reading the sample-data language');
if (!admission.ok) return admission.response;
const query = typeof c.req?.query === 'function' ? c.req.query() : undefined;
const queryRefusal = unknownQueryParamRefusalMessage(query, SEED_LOCALE_QUERY_PARAMS);
if (queryRefusal) {
return c.json({ success: false, error: { code: 'VALIDATION_ERROR', message: queryRefusal } }, 400);
}
const appDefault = typeof query?.appDefaultLocale === 'string' ? query.appDefaultLocale : undefined;
// The organization the install's rows would land in: the active one
// under a wall, none otherwise (the settings service's own reach).
let organizationId: string | undefined;
if (organizationWallActive(ctx)) organizationId = (await this.resolveActiveOrgId(c, ctx)) ?? undefined;
try {
const data = await resolveSeedLocaleForPreview(ctx, {
organizationId,
userId: admission.userId,
appDefaultLocale: appDefault,
});
return c.json({ success: true, data }, 200);
} catch (err: any) {
ctx.logger?.warn?.(`[MarketplaceInstallLocal] the sample-data language could not be read: ${err?.message ?? err}`);
return c.json({
success: false,
error: {
code: 'INTERNAL_ERROR',
message: `The sample-data language could not be read: ${err?.message ?? err}. The organization's language `
+ 'setting or your own language may exist and was not read, so no language is named.',
},
}, 500);
}
};

private handleSampleDataCount = async (c: any, ctx: PluginContext): Promise<Response> => {
const admission = await this.requireInstallCapability(c, ctx, 'Counting sample data');
if (!admission.ok) return admission.response;
Expand Down Expand Up @@ -7920,7 +7974,7 @@ export class MarketplaceInstallLocalPlugin implements Plugin {
ctx: PluginContext,
manifest: any,
opts: { seedNow: boolean; c?: any; door?: Exclude<SampleDataDoor, 'purge'>; userId?: string },
): Promise<{ translationsLoaded: number; seeded: { mode: 'inline' | 'replayer' | 'skipped' | 'refused'; inserted?: number; updated?: number; skipped?: number; errors?: number; reason?: string; errorSample?: string; errorList?: any[]; droppedRefs?: number } }> => {
): Promise<{ translationsLoaded: number; seeded: { mode: 'inline' | 'replayer' | 'skipped' | 'refused'; inserted?: number; updated?: number; skipped?: number; errors?: number; reason?: string; errorSample?: string; errorList?: any[]; droppedRefs?: number; objects?: SeedObjectTally[] } }> => {
const appId = String(manifest?.id ?? 'unknown');
let translationsLoaded = 0;
let seedSummary: any = { mode: 'skipped', reason: 'no-datasets' };
Expand Down Expand Up @@ -8079,8 +8133,21 @@ export class MarketplaceInstallLocalPlugin implements Plugin {
// The whole run, failures included: the console's install
// result lists `errorList` (each record or link that did
// not load) beside the `errors` and `droppedRefs` counts.
seedSummary = { mode: 'inline', ...s };
ctx.logger?.info?.(`[MarketplaceInstallLocal] inline seed for ${appId}${organizationId ? ` (org=${organizationId})` : ''}: inserted=${s.inserted} updated=${s.updated} skipped=${s.skipped} errors=${s.errors}`);
// [#39681] `objects` says which rows are the package's
// records and which were written to other objects (a
// platform object's timeline pointers), and why each
// skipped row was not written, so the install result
// can agree with the sample-data count and name them.
// The rows already landed, so an unreadable object list
// leaves the tally as the loader gave it, never the run.
let own: Set<string> | undefined;
try { own = packageObjectNames(resolveStackCollection(manifest, 'objects')); } catch { /* tally as loaded */ }
// A run with no per-object report (a stand-in seed) reports none.
const tallied = Array.isArray(s.objects) ? s.objects : [];
const objects = own ? tallied.map((t) => ({ ...t, inPackage: own.has(t.object) })) : tallied;
seedSummary = { mode: 'inline', ...s, objects };
const tally = describeSeedTally(objects);
ctx.logger?.info?.(`[MarketplaceInstallLocal] inline seed for ${appId}${organizationId ? ` (org=${organizationId})` : ''}: inserted=${s.inserted} updated=${s.updated} skipped=${s.skipped} errors=${s.errors}${tally ? ` — ${tally}` : ''}`);
}
}
} catch (err: any) {
Expand Down Expand Up @@ -8202,7 +8269,7 @@ export class MarketplaceInstallLocalPlugin implements Plugin {
organizationId?: string,
localeFrom: { userId?: string; app?: unknown } = {},
owner: SeedOwnerOfLoad = { userId: null, door: 'seed', none: 'no person named' },
): Promise<{ inserted: number; updated: number; skipped: number; errors: number; errorList: any[]; droppedRefs: number; errorSample?: string }> => {
): Promise<{ inserted: number; updated: number; skipped: number; errors: number; errorList: any[]; droppedRefs: number; errorSample?: string; objects: SeedObjectTally[] }> => {
const ql: any = ctx.getService('objectql');
let metadata: any;
try { metadata = ctx.getService('metadata'); } catch { /* none */ }
Expand Down Expand Up @@ -8268,6 +8335,9 @@ export class MarketplaceInstallLocalPlugin implements Plugin {
// report WHY nothing landed (e.g. a locked DB, a missing table,
// a failed validation) instead of a bare "0 rows".
errorSample: result.errors[0]?.message,
// [#39681] The run by object, and why each skipped row was not
// written. Which objects are the package's is the caller's to say.
objects: tallySeedObjects(result?.results),
};
};

Expand Down
Loading
Loading