@capybara-hq/kernel 0.1.0-rc.53 → 0.1.0-rc.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/config/schema.d.ts +4 -0
- package/dist/config/schema.js +29 -0
- package/dist/db/kernel-schema.d.ts +10 -0
- package/dist/errors.d.ts +19 -0
- package/dist/errors.js +19 -0
- package/dist/http/api.module.js +8 -0
- package/dist/http/app.js +9 -0
- package/dist/http/meta.controller.d.ts +33 -0
- package/dist/http/meta.controller.js +72 -0
- package/dist/identity/app-auth.controller.d.ts +25 -0
- package/dist/identity/app-auth.controller.js +64 -0
- package/dist/identity/app-auth.d.ts +66 -0
- package/dist/identity/app-auth.js +203 -0
- package/dist/identity/app-auth.schemas.d.ts +47 -0
- package/dist/identity/app-auth.schemas.js +43 -0
- package/dist/identity/identity.module.d.ts +1 -1
- package/dist/identity/identity.module.js +4 -1
- package/dist/infra/config/kernel-config.service.js +2 -0
- package/dist/infra/outbox/registry.d.ts +14 -0
- package/dist/infra/outbox/registry.js +15 -0
- package/dist/infra/throttler/named-throttlers.d.ts +3 -2
- package/dist/infra/throttler/named-throttlers.js +14 -2
- package/dist/platform/exclusions.js +23 -0
- package/dist/platform/operation.js +1 -1
- package/dist/platform/ops/platform-icons.ops.d.ts +14 -0
- package/dist/platform/ops/platform-icons.ops.js +117 -0
- package/dist/platform/platform-ops.module.d.ts +2 -1
- package/dist/platform/platform-ops.module.js +3 -0
- package/dist/platform/route-schemas.js +3 -0
- package/dist/runtime/maintenance.d.ts +5 -2
- package/dist/runtime/maintenance.js +15 -4
- package/dist/themes/platform-icon-objects.d.ts +51 -0
- package/dist/themes/platform-icon-objects.js +113 -0
- package/dist/themes/platform-icon-public.controller.d.ts +17 -0
- package/dist/themes/platform-icon-public.controller.js +58 -0
- package/dist/themes/platform-icon.controller.d.ts +22 -0
- package/dist/themes/platform-icon.controller.js +65 -0
- package/dist/themes/platform-icon.schemas.d.ts +48 -0
- package/dist/themes/platform-icon.schemas.js +53 -0
- package/dist/themes/platform-icon.service.d.ts +83 -0
- package/dist/themes/platform-icon.service.js +301 -0
- package/dist/themes/themes.module.d.ts +4 -1
- package/dist/themes/themes.module.js +9 -4
- package/package.json +3 -3
- package/src/migrations/0164_platform_icons.sql +10 -0
|
@@ -30,6 +30,7 @@ import { SETUP_CHECK_ROUTES } from "../setup/setup-checks.schemas.js";
|
|
|
30
30
|
import { SETUP_GUIDE_ROUTES } from "../setup/setup-guides.schemas.js";
|
|
31
31
|
import { SHARE_ROUTES } from "../shares/shares.schemas.js";
|
|
32
32
|
import { SKILL_ROUTES } from "../skills/skills.schemas.js";
|
|
33
|
+
import { PLATFORM_ICON_ROUTES } from "../themes/platform-icon.schemas.js";
|
|
33
34
|
import { THEME_ROUTES } from "../themes/themes.schemas.js";
|
|
34
35
|
import { APPROVAL_ROUTES } from "../tools/approvals.schemas.js";
|
|
35
36
|
import { CONNECTOR_ROUTES } from "../tools/connectors.schemas.js";
|
|
@@ -74,6 +75,8 @@ export const ROUTE_SCHEMAS = [
|
|
|
74
75
|
...ME_ROUTES,
|
|
75
76
|
// themes (themes spec §9)
|
|
76
77
|
...THEME_ROUTES,
|
|
78
|
+
// the platform icon (mobile layout spec §10.2.1)
|
|
79
|
+
...PLATFORM_ICON_ROUTES,
|
|
77
80
|
// a plugin's suggested appearance (client extensions spec §6.5)
|
|
78
81
|
...APPEARANCE_ROUTES,
|
|
79
82
|
// setup guide checks (setup guides v2 §10.3, §12)
|
|
@@ -10,6 +10,7 @@ import { SandboxOperationReconcileJob } from "../sandbox/operation-reconcile.job
|
|
|
10
10
|
import { SandboxService } from "../sandbox/sandbox.service.js";
|
|
11
11
|
import { ScheduledTaskFirer } from "../schedules/fire.js";
|
|
12
12
|
import { ShareObjects } from "../shares/share-objects.js";
|
|
13
|
+
import { PlatformIconObjects } from "../themes/platform-icon-objects.js";
|
|
13
14
|
import { DeviceOpResolver } from "../tools/device-op-resolver.js";
|
|
14
15
|
import { ToolDrift } from "../tools/drift.js";
|
|
15
16
|
import { PermissionApprovalJobs } from "../tools/permission-approval-jobs.js";
|
|
@@ -27,7 +28,8 @@ export declare const MAINTENANCE_CONCURRENCY = 5;
|
|
|
27
28
|
* {@link processStopTree} and `deliver-to-parent` → {@link processDeliverToParent} (both in
|
|
28
29
|
* runtime/subagents/tree-jobs.ts, over {@link Waits}), `owned-plugin-cleanup` →
|
|
29
30
|
* {@link OwnedPluginCleanup}, `sched-fire` and `sched-settle` → {@link ScheduledTaskFirer}, `device-op-resolve` →
|
|
30
|
-
* {@link DeviceOpResolver}, `share-object-delete` → {@link ShareObjects}
|
|
31
|
+
* {@link DeviceOpResolver}, `share-object-delete` → {@link ShareObjects}, `platform-icon-delete` →
|
|
32
|
+
* {@link PlatformIconObjects}). The name of a periodic job (a `@LockedCron` / `@LockedInterval` job,
|
|
31
33
|
* such as `sandbox-suspend-idle`) runs that job's body once ({@link ScheduledRuns.runNow}), as the
|
|
32
34
|
* maintenance handlers did when those jobs were schedulers on this queue: an operator's or a
|
|
33
35
|
* test's one-off run, not a second schedule (decision R23 of the Nest kernel spec). Any other
|
|
@@ -49,8 +51,9 @@ export declare class MaintenanceProcessor extends WorkerHost<Worker> {
|
|
|
49
51
|
private readonly log;
|
|
50
52
|
private readonly operations;
|
|
51
53
|
private readonly shareObjects;
|
|
54
|
+
private readonly platformIcons;
|
|
52
55
|
private readonly snapshots?;
|
|
53
|
-
constructor(permissionApprovals: Pick<PermissionApprovalJobs, "recheck">, waits: Pick<Waits, "processTimeout" | "childFinished" | "stopChildren" | "stopDescendantsOfStopped" | "stopTree">, sandbox: Pick<SandboxService, "destroyDevice" | "resetFileSystem" | "revokeDeadHolder">, drift: Pick<ToolDrift, "check">, directory: Pick<DirectorySync, "runSyncJob">, deletion: Pick<RunDeletion, "stopOrg" | "stopTree">, offboarding: Pick<Offboarding, "stopRun">, runs: Pick<RunQueue, "ensureRun">, ownedCleanup: Pick<OwnedPluginCleanup, "run">, scheduledTasks: Pick<ScheduledTaskFirer, "fire" | "settle">, deviceOps: Pick<DeviceOpResolver, "resolve">, scheduled: Pick<ScheduledRuns, "runNow">, log: Pick<KernelLogger, "error" | "warn">, operations: Pick<SandboxOperationReconcileJob, "reconcile" | "revoke">, shareObjects: Pick<ShareObjects, "deleteObject">, snapshots?: Pick<CloudPermissionSnapshots, "reconcileDevice"> | undefined);
|
|
56
|
+
constructor(permissionApprovals: Pick<PermissionApprovalJobs, "recheck">, waits: Pick<Waits, "processTimeout" | "childFinished" | "stopChildren" | "stopDescendantsOfStopped" | "stopTree">, sandbox: Pick<SandboxService, "destroyDevice" | "resetFileSystem" | "revokeDeadHolder">, drift: Pick<ToolDrift, "check">, directory: Pick<DirectorySync, "runSyncJob">, deletion: Pick<RunDeletion, "stopOrg" | "stopTree">, offboarding: Pick<Offboarding, "stopRun">, runs: Pick<RunQueue, "ensureRun">, ownedCleanup: Pick<OwnedPluginCleanup, "run">, scheduledTasks: Pick<ScheduledTaskFirer, "fire" | "settle">, deviceOps: Pick<DeviceOpResolver, "resolve">, scheduled: Pick<ScheduledRuns, "runNow">, log: Pick<KernelLogger, "error" | "warn">, operations: Pick<SandboxOperationReconcileJob, "reconcile" | "revoke">, shareObjects: Pick<ShareObjects, "deleteObject">, platformIcons: Pick<PlatformIconObjects, "deleteObject">, snapshots?: Pick<CloudPermissionSnapshots, "reconcileDevice"> | undefined);
|
|
54
57
|
process(job: Job, token?: string): Promise<void>;
|
|
55
58
|
/** Starts consuming (worker role, after the extensions loaded; built with `autorun: false`). */
|
|
56
59
|
start(): void;
|
|
@@ -33,6 +33,7 @@ import { SandboxService } from "../sandbox/sandbox.service.js";
|
|
|
33
33
|
import { ScheduledTaskFireModule, ScheduledTaskFirer } from "../schedules/fire.js";
|
|
34
34
|
import { SCHED_FIRE_JOB, SCHED_SETTLE_JOB, } from "../schedules/job-ids.js";
|
|
35
35
|
import { SHARE_OBJECT_DELETE_JOB, ShareObjects, ShareObjectsModule, } from "../shares/share-objects.js";
|
|
36
|
+
import { PLATFORM_ICON_DELETE_JOB, PlatformIconObjects, PlatformIconObjectsModule, } from "../themes/platform-icon-objects.js";
|
|
36
37
|
import { DeviceOpResolver } from "../tools/device-op-resolver.js";
|
|
37
38
|
import { ToolDrift } from "../tools/drift.js";
|
|
38
39
|
import { DRIFT_CONNECTOR_JOB } from "../tools/job-ids.js";
|
|
@@ -55,7 +56,8 @@ export const MAINTENANCE_CONCURRENCY = 5;
|
|
|
55
56
|
* {@link processStopTree} and `deliver-to-parent` → {@link processDeliverToParent} (both in
|
|
56
57
|
* runtime/subagents/tree-jobs.ts, over {@link Waits}), `owned-plugin-cleanup` →
|
|
57
58
|
* {@link OwnedPluginCleanup}, `sched-fire` and `sched-settle` → {@link ScheduledTaskFirer}, `device-op-resolve` →
|
|
58
|
-
* {@link DeviceOpResolver}, `share-object-delete` → {@link ShareObjects}
|
|
59
|
+
* {@link DeviceOpResolver}, `share-object-delete` → {@link ShareObjects}, `platform-icon-delete` →
|
|
60
|
+
* {@link PlatformIconObjects}). The name of a periodic job (a `@LockedCron` / `@LockedInterval` job,
|
|
59
61
|
* such as `sandbox-suspend-idle`) runs that job's body once ({@link ScheduledRuns.runNow}), as the
|
|
60
62
|
* maintenance handlers did when those jobs were schedulers on this queue: an operator's or a
|
|
61
63
|
* test's one-off run, not a second schedule (decision R23 of the Nest kernel spec). Any other
|
|
@@ -77,8 +79,9 @@ let MaintenanceProcessor = class MaintenanceProcessor extends WorkerHost {
|
|
|
77
79
|
log;
|
|
78
80
|
operations;
|
|
79
81
|
shareObjects;
|
|
82
|
+
platformIcons;
|
|
80
83
|
snapshots;
|
|
81
|
-
constructor(permissionApprovals, waits, sandbox, drift, directory, deletion, offboarding, runs, ownedCleanup, scheduledTasks, deviceOps, scheduled, log, operations, shareObjects, snapshots) {
|
|
84
|
+
constructor(permissionApprovals, waits, sandbox, drift, directory, deletion, offboarding, runs, ownedCleanup, scheduledTasks, deviceOps, scheduled, log, operations, shareObjects, platformIcons, snapshots) {
|
|
82
85
|
super();
|
|
83
86
|
this.permissionApprovals = permissionApprovals;
|
|
84
87
|
this.waits = waits;
|
|
@@ -95,6 +98,7 @@ let MaintenanceProcessor = class MaintenanceProcessor extends WorkerHost {
|
|
|
95
98
|
this.log = log;
|
|
96
99
|
this.operations = operations;
|
|
97
100
|
this.shareObjects = shareObjects;
|
|
101
|
+
this.platformIcons = platformIcons;
|
|
98
102
|
this.snapshots = snapshots;
|
|
99
103
|
}
|
|
100
104
|
process(job, token) {
|
|
@@ -197,6 +201,10 @@ let MaintenanceProcessor = class MaintenanceProcessor extends WorkerHost {
|
|
|
197
201
|
case SHARE_OBJECT_DELETE_JOB:
|
|
198
202
|
await this.shareObjects.deleteObject(job.data);
|
|
199
203
|
return;
|
|
204
|
+
// a platform icon object no row names any more, or an upload's orphan check (§10.2.1)
|
|
205
|
+
case PLATFORM_ICON_DELETE_JOB:
|
|
206
|
+
await this.platformIcons.deleteObject(job.data);
|
|
207
|
+
return;
|
|
200
208
|
default:
|
|
201
209
|
if (await this.scheduled.runNow(job.name))
|
|
202
210
|
return;
|
|
@@ -236,8 +244,9 @@ MaintenanceProcessor = __decorate([
|
|
|
236
244
|
__param(12, Inject(KERNEL_LOGGER)),
|
|
237
245
|
__param(13, Inject(SandboxOperationReconcileJob)),
|
|
238
246
|
__param(14, Inject(ShareObjects)),
|
|
239
|
-
__param(15,
|
|
240
|
-
__param(
|
|
247
|
+
__param(15, Inject(PlatformIconObjects)),
|
|
248
|
+
__param(16, Optional()),
|
|
249
|
+
__param(16, Inject(CloudPermissionSnapshots))
|
|
241
250
|
], MaintenanceProcessor);
|
|
242
251
|
export { MaintenanceProcessor };
|
|
243
252
|
/**
|
|
@@ -264,6 +273,8 @@ MaintenanceModule = __decorate([
|
|
|
264
273
|
ScheduledTaskFireModule,
|
|
265
274
|
// the share snapshot deletion
|
|
266
275
|
ShareObjectsModule,
|
|
276
|
+
// the platform icon object deletion
|
|
277
|
+
PlatformIconObjectsModule,
|
|
267
278
|
QueueModule.registerQueue(MAINTENANCE_QUEUE_NAME),
|
|
268
279
|
],
|
|
269
280
|
providers: [
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
2
|
+
import { LockService } from "../infra/lock/lock.service.js";
|
|
3
|
+
import type { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
4
|
+
import { StorageService } from "../storage/storage.service.js";
|
|
5
|
+
import type { PlatformIconPurpose } from "./platform-icon.schemas.js";
|
|
6
|
+
/** The object key of an icon, relative to the kernel's `deployment/` prefix. */
|
|
7
|
+
export declare const platformIconKey: (purpose: PlatformIconPurpose, sha256: string) => string;
|
|
8
|
+
/** The `LockService` key of a purpose's icon writes and deletions (no `:`). */
|
|
9
|
+
export declare const platformIconLockKey: (purpose: PlatformIconPurpose) => string;
|
|
10
|
+
/** How long a write or the deletion job holds the purpose's lock without renewal, and waits for it. */
|
|
11
|
+
export declare const PLATFORM_ICON_LOCK: {
|
|
12
|
+
readonly ttlMs: 30000;
|
|
13
|
+
readonly waitMs: 10000;
|
|
14
|
+
};
|
|
15
|
+
/** The maintenance job that deletes one icon object no row names. */
|
|
16
|
+
export declare const PLATFORM_ICON_DELETE_JOB = "platform-icon-delete";
|
|
17
|
+
/** Outbox id of the deletion a replace or clear owes for the object the row stopped naming. */
|
|
18
|
+
export declare const platformIconDeleteJobId: (purpose: PlatformIconPurpose, sha256: string) => string;
|
|
19
|
+
/** Outbox id of the delayed check an upload owes for its own object before writing it. */
|
|
20
|
+
export declare const platformIconOrphanJobId: (purpose: PlatformIconPurpose, sha256: string) => string;
|
|
21
|
+
/** How long after an upload starts its orphan check runs (the upload is long done by then). */
|
|
22
|
+
export declare const PLATFORM_ICON_ORPHAN_DELAY_MS: number;
|
|
23
|
+
/** The data of a {@link PLATFORM_ICON_DELETE_JOB}. */
|
|
24
|
+
export interface PlatformIconDeleteData {
|
|
25
|
+
purpose: PlatformIconPurpose;
|
|
26
|
+
objectKey: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Owes the deletion of a purpose's object in the caller's transaction: at once (`runAt` absent,
|
|
30
|
+
* a replace or clear) or later (an upload's orphan check, under its own id).
|
|
31
|
+
*/
|
|
32
|
+
export declare function owePlatformIconDelete(outbox: Pick<OutboxService, "add">, purpose: PlatformIconPurpose, sha256: string, opts?: {
|
|
33
|
+
orphanCheck?: boolean;
|
|
34
|
+
}): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Runs a {@link PLATFORM_ICON_DELETE_JOB} (the maintenance processor dispatches it here). Under
|
|
37
|
+
* the purpose's lock it deletes the object unless the purpose's row names it; delivered twice it
|
|
38
|
+
* is harmless (deleting a missing object is a no-op). A lock it cannot take in time throws, and
|
|
39
|
+
* BullMQ retries the job.
|
|
40
|
+
*/
|
|
41
|
+
export declare class PlatformIconObjects {
|
|
42
|
+
private readonly db;
|
|
43
|
+
private readonly locks;
|
|
44
|
+
private readonly storage;
|
|
45
|
+
constructor(db: KernelDb, locks: LockService, storage: Pick<StorageService, "deployment">);
|
|
46
|
+
/** Deletes the object unless the row names it; see the class comment. */
|
|
47
|
+
deleteObject(data: PlatformIconDeleteData): Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
/** {@link PlatformIconObjects} for the maintenance worker (storage, the database and locks only). */
|
|
50
|
+
export declare class PlatformIconObjectsModule {
|
|
51
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
|
+
};
|
|
10
|
+
import { Inject, Injectable, Module } from "@nestjs/common";
|
|
11
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
12
|
+
import { LockService } from "../infra/lock/lock.service.js";
|
|
13
|
+
import { MAINTENANCE_QUEUE_NAME } from "../runtime/maintenance-queue.js";
|
|
14
|
+
import { StorageModule } from "../storage/storage.module.js";
|
|
15
|
+
import { StorageService } from "../storage/storage.service.js";
|
|
16
|
+
/**
|
|
17
|
+
* Platform icon objects in object storage (mobile layout spec §10.2.1): the icon of a purpose with
|
|
18
|
+
* SHA-256 `h` is `platform-icons/<purpose>-<h>.<png|svg>` under the kernel's `deployment/` prefix,
|
|
19
|
+
* so the same bytes always land on the same key. An upload writes its object before the row that
|
|
20
|
+
* names it; an object no row names is deleted through the outbox ({@link PLATFORM_ICON_DELETE_JOB}):
|
|
21
|
+
* the upload owes a delayed check of its own object first (an upload that never commits leaves no
|
|
22
|
+
* orphan), and a replace or clear owes the deletion of the object the row stops naming.
|
|
23
|
+
*
|
|
24
|
+
* Because keys are content addressed, a later upload of the same bytes may name a key again after
|
|
25
|
+
* its deletion was owed: uploads, clears and the job hold {@link platformIconLockKey} for the
|
|
26
|
+
* purpose, so the job's "no row names it" check and its delete never interleave with an upload
|
|
27
|
+
* between its object write and its commit.
|
|
28
|
+
*/
|
|
29
|
+
/** The file extension of a purpose's object (its type is fixed by the purpose). */
|
|
30
|
+
const extensionOf = (purpose) => purpose === "favicon" ? "svg" : "png";
|
|
31
|
+
/** The object key of an icon, relative to the kernel's `deployment/` prefix. */
|
|
32
|
+
export const platformIconKey = (purpose, sha256) => `platform-icons/${purpose}-${sha256}.${extensionOf(purpose)}`;
|
|
33
|
+
/** True when `key` is one {@link platformIconKey} makes for `purpose`. */
|
|
34
|
+
const isIconKeyOf = (purpose, key) => new RegExp(`^platform-icons/${purpose}-[0-9a-f]{64}\\.${extensionOf(purpose)}$`).test(key);
|
|
35
|
+
/** The `LockService` key of a purpose's icon writes and deletions (no `:`). */
|
|
36
|
+
export const platformIconLockKey = (purpose) => `platform-icon-${purpose}`;
|
|
37
|
+
/** How long a write or the deletion job holds the purpose's lock without renewal, and waits for it. */
|
|
38
|
+
export const PLATFORM_ICON_LOCK = { ttlMs: 30_000, waitMs: 10_000 };
|
|
39
|
+
/** The maintenance job that deletes one icon object no row names. */
|
|
40
|
+
export const PLATFORM_ICON_DELETE_JOB = "platform-icon-delete";
|
|
41
|
+
/** Outbox id of the deletion a replace or clear owes for the object the row stopped naming. */
|
|
42
|
+
export const platformIconDeleteJobId = (purpose, sha256) => `platform-icon-delete-${purpose}-${sha256}`;
|
|
43
|
+
/** Outbox id of the delayed check an upload owes for its own object before writing it. */
|
|
44
|
+
export const platformIconOrphanJobId = (purpose, sha256) => `platform-icon-orphan-${purpose}-${sha256}`;
|
|
45
|
+
/** How long after an upload starts its orphan check runs (the upload is long done by then). */
|
|
46
|
+
export const PLATFORM_ICON_ORPHAN_DELAY_MS = 10 * 60 * 1000;
|
|
47
|
+
/**
|
|
48
|
+
* Owes the deletion of a purpose's object in the caller's transaction: at once (`runAt` absent,
|
|
49
|
+
* a replace or clear) or later (an upload's orphan check, under its own id).
|
|
50
|
+
*/
|
|
51
|
+
export async function owePlatformIconDelete(outbox, purpose, sha256, opts = {}) {
|
|
52
|
+
const data = { purpose, objectKey: platformIconKey(purpose, sha256) };
|
|
53
|
+
await outbox.add({
|
|
54
|
+
queue: MAINTENANCE_QUEUE_NAME,
|
|
55
|
+
name: PLATFORM_ICON_DELETE_JOB,
|
|
56
|
+
jobId: opts.orphanCheck
|
|
57
|
+
? platformIconOrphanJobId(purpose, sha256)
|
|
58
|
+
: platformIconDeleteJobId(purpose, sha256),
|
|
59
|
+
data,
|
|
60
|
+
...(opts.orphanCheck && { runAt: new Date(Date.now() + PLATFORM_ICON_ORPHAN_DELAY_MS) }),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Runs a {@link PLATFORM_ICON_DELETE_JOB} (the maintenance processor dispatches it here). Under
|
|
65
|
+
* the purpose's lock it deletes the object unless the purpose's row names it; delivered twice it
|
|
66
|
+
* is harmless (deleting a missing object is a no-op). A lock it cannot take in time throws, and
|
|
67
|
+
* BullMQ retries the job.
|
|
68
|
+
*/
|
|
69
|
+
let PlatformIconObjects = class PlatformIconObjects {
|
|
70
|
+
db;
|
|
71
|
+
locks;
|
|
72
|
+
storage;
|
|
73
|
+
constructor(db, locks, storage) {
|
|
74
|
+
this.db = db;
|
|
75
|
+
this.locks = locks;
|
|
76
|
+
this.storage = storage;
|
|
77
|
+
}
|
|
78
|
+
/** Deletes the object unless the row names it; see the class comment. */
|
|
79
|
+
async deleteObject(data) {
|
|
80
|
+
if (!isIconKeyOf(data.purpose, data.objectKey)) {
|
|
81
|
+
// never delete anything outside the purpose's own icon keys, whatever the job data says
|
|
82
|
+
throw new Error(`platform-icon-delete: unexpected object key for ${data.purpose}`);
|
|
83
|
+
}
|
|
84
|
+
await this.locks.run(platformIconLockKey(data.purpose), PLATFORM_ICON_LOCK, async () => {
|
|
85
|
+
const row = await this.db
|
|
86
|
+
.selectFrom("platform_icons")
|
|
87
|
+
.select("object_key")
|
|
88
|
+
.where("purpose", "=", data.purpose)
|
|
89
|
+
.executeTakeFirst();
|
|
90
|
+
if (row?.object_key === data.objectKey)
|
|
91
|
+
return;
|
|
92
|
+
await this.storage.deployment().delete(data.objectKey);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
PlatformIconObjects = __decorate([
|
|
97
|
+
Injectable(),
|
|
98
|
+
__param(0, Inject(KernelDb)),
|
|
99
|
+
__param(1, Inject(LockService)),
|
|
100
|
+
__param(2, Inject(StorageService))
|
|
101
|
+
], PlatformIconObjects);
|
|
102
|
+
export { PlatformIconObjects };
|
|
103
|
+
/** {@link PlatformIconObjects} for the maintenance worker (storage, the database and locks only). */
|
|
104
|
+
let PlatformIconObjectsModule = class PlatformIconObjectsModule {
|
|
105
|
+
};
|
|
106
|
+
PlatformIconObjectsModule = __decorate([
|
|
107
|
+
Module({
|
|
108
|
+
imports: [StorageModule],
|
|
109
|
+
providers: [PlatformIconObjects],
|
|
110
|
+
exports: [PlatformIconObjects],
|
|
111
|
+
})
|
|
112
|
+
], PlatformIconObjectsModule);
|
|
113
|
+
export { PlatformIconObjectsModule };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { FastifyReply } from "fastify";
|
|
2
|
+
import type { z } from "zod";
|
|
3
|
+
import { PlatformIconParams, PlatformIconQuery } from "./platform-icon.schemas.js";
|
|
4
|
+
import { PlatformIconService } from "./platform-icon.service.js";
|
|
5
|
+
/**
|
|
6
|
+
* The platform icon's bytes (mobile layout spec §10.2.1), public: the PWA manifest, the favicons
|
|
7
|
+
* and native clients read it before sign-in, and an icon is not sensitive. `?v=<sha256>` (the URL
|
|
8
|
+
* the settings list) is cached as immutable; without `v` the response is revalidated; a `v` that is
|
|
9
|
+
* not the current hash, or a purpose with no upload, is 404 `platform_icon.not_found` (the web then
|
|
10
|
+
* uses its built-in icon). The type is fixed by the purpose, with `nosniff`; the SVG favicon also
|
|
11
|
+
* gets a sandbox CSP, so opened directly it runs nothing and loads nothing.
|
|
12
|
+
*/
|
|
13
|
+
export declare class PlatformIconPublicController {
|
|
14
|
+
private readonly icons;
|
|
15
|
+
constructor(icons: PlatformIconService);
|
|
16
|
+
icon({ purpose }: z.infer<typeof PlatformIconParams>, { v }: z.infer<typeof PlatformIconQuery>, reply: FastifyReply): Promise<void>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
|
+
};
|
|
10
|
+
import { Controller, Get, Inject, Res } from "@nestjs/common";
|
|
11
|
+
import { Public } from "../identity/principal.js";
|
|
12
|
+
import { createZodDto } from "../infra/validation/create-zod-dto.js";
|
|
13
|
+
import { ZParam, ZQuery } from "../infra/validation/zod-params.js";
|
|
14
|
+
import { PlatformIconParams, PlatformIconQuery } from "./platform-icon.schemas.js";
|
|
15
|
+
import { PlatformIconService } from "./platform-icon.service.js";
|
|
16
|
+
class PlatformIconPublicParamsDto extends createZodDto(PlatformIconParams, "PlatformIconPublicParams") {
|
|
17
|
+
}
|
|
18
|
+
class PlatformIconQueryDto extends createZodDto(PlatformIconQuery, "PlatformIconQuery") {
|
|
19
|
+
}
|
|
20
|
+
/** With the current hash in `v` the URL's bytes never change. */
|
|
21
|
+
const IMMUTABLE = "public, max-age=31536000, immutable";
|
|
22
|
+
/**
|
|
23
|
+
* The platform icon's bytes (mobile layout spec §10.2.1), public: the PWA manifest, the favicons
|
|
24
|
+
* and native clients read it before sign-in, and an icon is not sensitive. `?v=<sha256>` (the URL
|
|
25
|
+
* the settings list) is cached as immutable; without `v` the response is revalidated; a `v` that is
|
|
26
|
+
* not the current hash, or a purpose with no upload, is 404 `platform_icon.not_found` (the web then
|
|
27
|
+
* uses its built-in icon). The type is fixed by the purpose, with `nosniff`; the SVG favicon also
|
|
28
|
+
* gets a sandbox CSP, so opened directly it runs nothing and loads nothing.
|
|
29
|
+
*/
|
|
30
|
+
let PlatformIconPublicController = class PlatformIconPublicController {
|
|
31
|
+
icons;
|
|
32
|
+
constructor(icons) {
|
|
33
|
+
this.icons = icons;
|
|
34
|
+
}
|
|
35
|
+
async icon({ purpose }, { v }, reply) {
|
|
36
|
+
const icon = await this.icons.read(purpose, v);
|
|
37
|
+
reply
|
|
38
|
+
.header("content-type", icon.contentType)
|
|
39
|
+
.header("x-content-type-options", "nosniff")
|
|
40
|
+
.header("cache-control", icon.immutable ? IMMUTABLE : "no-cache");
|
|
41
|
+
if (icon.contentType === "image/svg+xml") {
|
|
42
|
+
reply.header("content-security-policy", "default-src 'none'; style-src 'unsafe-inline'; sandbox");
|
|
43
|
+
}
|
|
44
|
+
await reply.send(Buffer.from(icon.bytes.buffer, icon.bytes.byteOffset, icon.bytes.byteLength));
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
__decorate([
|
|
48
|
+
Public(),
|
|
49
|
+
Get(":purpose"),
|
|
50
|
+
__param(0, ZParam(PlatformIconPublicParamsDto)),
|
|
51
|
+
__param(1, ZQuery(PlatformIconQueryDto)),
|
|
52
|
+
__param(2, Res())
|
|
53
|
+
], PlatformIconPublicController.prototype, "icon", null);
|
|
54
|
+
PlatformIconPublicController = __decorate([
|
|
55
|
+
Controller("api/v1/platform/icon"),
|
|
56
|
+
__param(0, Inject(PlatformIconService))
|
|
57
|
+
], PlatformIconPublicController);
|
|
58
|
+
export { PlatformIconPublicController };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import { type Principal } from "../identity/principal.js";
|
|
3
|
+
import { PlatformIconBody, PlatformIconParams, type PlatformIconView } from "./platform-icon.schemas.js";
|
|
4
|
+
import { PlatformIconService } from "./platform-icon.service.js";
|
|
5
|
+
/**
|
|
6
|
+
* The platform icon setting (`/api/v1/admin/platform/icons*`, mobile layout spec §10.2.1): the
|
|
7
|
+
* app icon, its maskable variant and the SVG favicon the PWA manifest, the favicons and native
|
|
8
|
+
* clients use. Super admins only (one installed app per deployment); service tokens 403. The
|
|
9
|
+
* upload is JSON base64 so the Platform tool mirrors it (`admin.set-icon`).
|
|
10
|
+
*/
|
|
11
|
+
export declare class PlatformIconController {
|
|
12
|
+
private readonly icons;
|
|
13
|
+
constructor(icons: PlatformIconService);
|
|
14
|
+
/** `{ icons }`: every uploaded icon with its public URL; a purpose not listed uses the default. */
|
|
15
|
+
list(): Promise<{
|
|
16
|
+
icons: PlatformIconView[];
|
|
17
|
+
}>;
|
|
18
|
+
/** Uploads the icon of a purpose (PNG 512 × 512 for app / maskable, SVG for favicon, ≤ 1 MiB). */
|
|
19
|
+
set(principal: Principal, { purpose }: z.infer<typeof PlatformIconParams>, body: z.infer<typeof PlatformIconBody>): Promise<PlatformIconView>;
|
|
20
|
+
/** Restores the built-in icon of a purpose; 204 also when none was uploaded. */
|
|
21
|
+
clear(principal: Principal, { purpose }: z.infer<typeof PlatformIconParams>): Promise<void>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
|
+
};
|
|
10
|
+
import { Controller, Delete, Get, HttpCode, Inject, Put } from "@nestjs/common";
|
|
11
|
+
import { CurrentPrincipal, SuperAdmin } from "../identity/principal.js";
|
|
12
|
+
import { writeActorOf } from "../identity/write-actor.js";
|
|
13
|
+
import { createZodDto } from "../infra/validation/create-zod-dto.js";
|
|
14
|
+
import { ZBody, ZParam } from "../infra/validation/zod-params.js";
|
|
15
|
+
import { PlatformIconBody, PlatformIconParams, } from "./platform-icon.schemas.js";
|
|
16
|
+
import { PlatformIconService } from "./platform-icon.service.js";
|
|
17
|
+
class PlatformIconParamsDto extends createZodDto(PlatformIconParams, "PlatformIconParams") {
|
|
18
|
+
}
|
|
19
|
+
class PlatformIconBodyDto extends createZodDto(PlatformIconBody, "PlatformIconBody") {
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The platform icon setting (`/api/v1/admin/platform/icons*`, mobile layout spec §10.2.1): the
|
|
23
|
+
* app icon, its maskable variant and the SVG favicon the PWA manifest, the favicons and native
|
|
24
|
+
* clients use. Super admins only (one installed app per deployment); service tokens 403. The
|
|
25
|
+
* upload is JSON base64 so the Platform tool mirrors it (`admin.set-icon`).
|
|
26
|
+
*/
|
|
27
|
+
let PlatformIconController = class PlatformIconController {
|
|
28
|
+
icons;
|
|
29
|
+
constructor(icons) {
|
|
30
|
+
this.icons = icons;
|
|
31
|
+
}
|
|
32
|
+
/** `{ icons }`: every uploaded icon with its public URL; a purpose not listed uses the default. */
|
|
33
|
+
list() {
|
|
34
|
+
return this.icons.list();
|
|
35
|
+
}
|
|
36
|
+
/** Uploads the icon of a purpose (PNG 512 × 512 for app / maskable, SVG for favicon, ≤ 1 MiB). */
|
|
37
|
+
set(principal, { purpose }, body) {
|
|
38
|
+
return this.icons.set(purpose, body.contentType, body.dataBase64, writeActorOf(principal));
|
|
39
|
+
}
|
|
40
|
+
/** Restores the built-in icon of a purpose; 204 also when none was uploaded. */
|
|
41
|
+
async clear(principal, { purpose }) {
|
|
42
|
+
await this.icons.clear(purpose, writeActorOf(principal));
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
__decorate([
|
|
46
|
+
Get()
|
|
47
|
+
], PlatformIconController.prototype, "list", null);
|
|
48
|
+
__decorate([
|
|
49
|
+
Put(":purpose"),
|
|
50
|
+
__param(0, CurrentPrincipal()),
|
|
51
|
+
__param(1, ZParam(PlatformIconParamsDto)),
|
|
52
|
+
__param(2, ZBody(PlatformIconBodyDto))
|
|
53
|
+
], PlatformIconController.prototype, "set", null);
|
|
54
|
+
__decorate([
|
|
55
|
+
Delete(":purpose"),
|
|
56
|
+
HttpCode(204),
|
|
57
|
+
__param(0, CurrentPrincipal()),
|
|
58
|
+
__param(1, ZParam(PlatformIconParamsDto))
|
|
59
|
+
], PlatformIconController.prototype, "clear", null);
|
|
60
|
+
PlatformIconController = __decorate([
|
|
61
|
+
Controller("api/v1/admin/platform/icons"),
|
|
62
|
+
SuperAdmin(),
|
|
63
|
+
__param(0, Inject(PlatformIconService))
|
|
64
|
+
], PlatformIconController);
|
|
65
|
+
export { PlatformIconController };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { RouteSchemas } from "../platform/route-schemas.js";
|
|
3
|
+
/**
|
|
4
|
+
* The platform icon (mobile layout spec §10.2.1): `app` the 512 × 512 PNG app icon, `maskable`
|
|
5
|
+
* its 512 × 512 PNG variant with the subject inside the central 80 % safe zone, `favicon` an SVG.
|
|
6
|
+
*/
|
|
7
|
+
export declare const PLATFORM_ICON_PURPOSES: readonly ["app", "maskable", "favicon"];
|
|
8
|
+
export type PlatformIconPurpose = (typeof PLATFORM_ICON_PURPOSES)[number];
|
|
9
|
+
/** The largest icon file in bytes (1 MiB), whatever its purpose. */
|
|
10
|
+
export declare const PLATFORM_ICON_MAX_BYTES: number;
|
|
11
|
+
/** The one size of a PNG icon (`app`, `maskable`), in pixels. */
|
|
12
|
+
export declare const PLATFORM_ICON_PNG_SIZE = 512;
|
|
13
|
+
/**
|
|
14
|
+
* The longest `dataBase64` the route reads: the base64 of 1.5 MiB, so a file somewhat over
|
|
15
|
+
* {@link PLATFORM_ICON_MAX_BYTES} still reaches the size check and is refused with
|
|
16
|
+
* `platform_icon.too_large` (the route's body limit, `PLATFORM_ICON_BODY_LIMIT`, admits it).
|
|
17
|
+
*/
|
|
18
|
+
export declare const PLATFORM_ICON_MAX_BASE64: number;
|
|
19
|
+
/** `:purpose` of the icon routes. */
|
|
20
|
+
export declare const PlatformIconParams: z.ZodObject<{
|
|
21
|
+
purpose: z.ZodEnum<{
|
|
22
|
+
app: "app";
|
|
23
|
+
favicon: "favicon";
|
|
24
|
+
maskable: "maskable";
|
|
25
|
+
}>;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
|
+
/** `PUT /api/v1/admin/platform/icons/:purpose`: the file as standard base64. */
|
|
28
|
+
export declare const PlatformIconBody: z.ZodObject<{
|
|
29
|
+
contentType: z.ZodEnum<{
|
|
30
|
+
"image/png": "image/png";
|
|
31
|
+
"image/svg+xml": "image/svg+xml";
|
|
32
|
+
}>;
|
|
33
|
+
dataBase64: z.ZodString;
|
|
34
|
+
}, z.core.$strict>;
|
|
35
|
+
/** `GET /api/v1/platform/icon/:purpose`: `v` is the SHA-256 the URL was built with. */
|
|
36
|
+
export declare const PlatformIconQuery: z.ZodObject<{
|
|
37
|
+
v: z.ZodOptional<z.ZodString>;
|
|
38
|
+
}, z.core.$strip>;
|
|
39
|
+
/** One uploaded icon as the admin routes return it. */
|
|
40
|
+
export interface PlatformIconView {
|
|
41
|
+
purpose: PlatformIconPurpose;
|
|
42
|
+
/** The public URL, carrying the hash: `/api/v1/platform/icon/<purpose>?v=<sha256>`. */
|
|
43
|
+
url: string;
|
|
44
|
+
sha256: string;
|
|
45
|
+
updatedAt: string;
|
|
46
|
+
}
|
|
47
|
+
/** The admin icon routes the Platform operations mirror (`check:platform-ops` keys). */
|
|
48
|
+
export declare const PLATFORM_ICON_ROUTES: readonly RouteSchemas[];
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* The platform icon (mobile layout spec §10.2.1): `app` the 512 × 512 PNG app icon, `maskable`
|
|
4
|
+
* its 512 × 512 PNG variant with the subject inside the central 80 % safe zone, `favicon` an SVG.
|
|
5
|
+
*/
|
|
6
|
+
export const PLATFORM_ICON_PURPOSES = ["app", "maskable", "favicon"];
|
|
7
|
+
/** The largest icon file in bytes (1 MiB), whatever its purpose. */
|
|
8
|
+
export const PLATFORM_ICON_MAX_BYTES = 1024 * 1024;
|
|
9
|
+
/** The one size of a PNG icon (`app`, `maskable`), in pixels. */
|
|
10
|
+
export const PLATFORM_ICON_PNG_SIZE = 512;
|
|
11
|
+
/**
|
|
12
|
+
* The longest `dataBase64` the route reads: the base64 of 1.5 MiB, so a file somewhat over
|
|
13
|
+
* {@link PLATFORM_ICON_MAX_BYTES} still reaches the size check and is refused with
|
|
14
|
+
* `platform_icon.too_large` (the route's body limit, `PLATFORM_ICON_BODY_LIMIT`, admits it).
|
|
15
|
+
*/
|
|
16
|
+
export const PLATFORM_ICON_MAX_BASE64 = 4 * Math.ceil((1.5 * PLATFORM_ICON_MAX_BYTES) / 3);
|
|
17
|
+
/** `:purpose` of the icon routes. */
|
|
18
|
+
export const PlatformIconParams = z.object({
|
|
19
|
+
purpose: z
|
|
20
|
+
.enum(PLATFORM_ICON_PURPOSES)
|
|
21
|
+
.describe("Which icon: app (the 512 × 512 PNG app icon), maskable (its 512 × 512 PNG variant whose subject stays inside the central 80 % safe zone) or favicon (an SVG)."),
|
|
22
|
+
});
|
|
23
|
+
/** `PUT /api/v1/admin/platform/icons/:purpose`: the file as standard base64. */
|
|
24
|
+
export const PlatformIconBody = z
|
|
25
|
+
.object({
|
|
26
|
+
contentType: z
|
|
27
|
+
.enum(["image/png", "image/svg+xml"])
|
|
28
|
+
.describe("image/png for app and maskable, image/svg+xml for favicon."),
|
|
29
|
+
dataBase64: z
|
|
30
|
+
.string()
|
|
31
|
+
.min(1)
|
|
32
|
+
.max(PLATFORM_ICON_MAX_BASE64)
|
|
33
|
+
.regex(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/, "dataBase64 must be standard base64 (A-Z, a-z, 0-9, +, / with = padding)")
|
|
34
|
+
.describe("The file's bytes as standard base64, at most 1 MiB decoded (an SVG favicon at most 128 KiB)."),
|
|
35
|
+
})
|
|
36
|
+
.strict();
|
|
37
|
+
/** `GET /api/v1/platform/icon/:purpose`: `v` is the SHA-256 the URL was built with. */
|
|
38
|
+
export const PlatformIconQuery = z.object({
|
|
39
|
+
v: z
|
|
40
|
+
.string()
|
|
41
|
+
.regex(/^[0-9a-f]{64}$/, "v must be a SHA-256 in lower-case hex")
|
|
42
|
+
.optional(),
|
|
43
|
+
});
|
|
44
|
+
/** The admin icon routes the Platform operations mirror (`check:platform-ops` keys). */
|
|
45
|
+
export const PLATFORM_ICON_ROUTES = [
|
|
46
|
+
{ route: "GET /api/v1/admin/platform/icons" },
|
|
47
|
+
{
|
|
48
|
+
route: "PUT /api/v1/admin/platform/icons/:purpose",
|
|
49
|
+
params: PlatformIconParams,
|
|
50
|
+
body: PlatformIconBody,
|
|
51
|
+
},
|
|
52
|
+
{ route: "DELETE /api/v1/admin/platform/icons/:purpose", params: PlatformIconParams },
|
|
53
|
+
];
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { SuperAdminLock } from "../identity/super-admin.js";
|
|
2
|
+
import type { WriteActor } from "../identity/write-actor.js";
|
|
3
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
4
|
+
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
5
|
+
import { LockService } from "../infra/lock/lock.service.js";
|
|
6
|
+
import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
7
|
+
import { StorageService } from "../storage/storage.service.js";
|
|
8
|
+
import { type PlatformIconPurpose, type PlatformIconView } from "./platform-icon.schemas.js";
|
|
9
|
+
/** A validated icon, ready to store: the bytes to write and their SHA-256. */
|
|
10
|
+
export interface PlatformIconFile {
|
|
11
|
+
purpose: PlatformIconPurpose;
|
|
12
|
+
contentType: "image/png" | "image/svg+xml";
|
|
13
|
+
bytes: Uint8Array;
|
|
14
|
+
sha256: string;
|
|
15
|
+
}
|
|
16
|
+
/** The public URL of an icon: the hash in `v` changes on upload, so it is cached as immutable. */
|
|
17
|
+
export declare const platformIconUrl: (purpose: PlatformIconPurpose, sha256: string) => string;
|
|
18
|
+
/**
|
|
19
|
+
* Checks an upload (nothing is rendered or resized): at most 1 MiB; `app` and `maskable` a PNG
|
|
20
|
+
* (signature, an `IHDR` first chunk with a valid CRC-32, ending with `IEND`) of exactly 512 × 512;
|
|
21
|
+
* `favicon` an SVG of at most 128 KiB, parsed with the theme
|
|
22
|
+
* logo sanitizer (a strict XML parser, an `<svg>` root in the SVG namespace with a viewBox, no
|
|
23
|
+
* script, style element, event handler or external reference) and stored as its sanitized output.
|
|
24
|
+
* Throws the refusal as `platform_icon.*`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function checkPlatformIcon(purpose: PlatformIconPurpose, declared: "image/png" | "image/svg+xml", dataBase64: string): PlatformIconFile;
|
|
27
|
+
/**
|
|
28
|
+
* The platform icon setting (mobile layout spec §10.2.1): the super admin's uploads (the app icon,
|
|
29
|
+
* its maskable variant, the SVG favicon), stored in object storage under the kernel's
|
|
30
|
+
* `deployment/` prefix with a row per purpose in `capybara.platform_icons`; the public read the
|
|
31
|
+
* manifest, favicons and native clients use. Writes are audited (`platform.icon.updated`,
|
|
32
|
+
* `platform.icon.cleared`) and serialized per purpose (see `platform-icon-objects.ts`).
|
|
33
|
+
*/
|
|
34
|
+
export declare class PlatformIconService {
|
|
35
|
+
private readonly db;
|
|
36
|
+
readonly txHost: TransactionHost;
|
|
37
|
+
private readonly outbox;
|
|
38
|
+
private readonly adminLock;
|
|
39
|
+
private readonly locks;
|
|
40
|
+
private readonly storage;
|
|
41
|
+
constructor(db: KernelDb, txHost: TransactionHost, outbox: OutboxService, adminLock: SuperAdminLock, locks: LockService, storage: StorageService);
|
|
42
|
+
/** Every uploaded icon, in purpose order (`app`, `maskable`, `favicon`). */
|
|
43
|
+
list(): Promise<{
|
|
44
|
+
icons: PlatformIconView[];
|
|
45
|
+
}>;
|
|
46
|
+
/**
|
|
47
|
+
* The icon of a purpose now, `{ purpose, sha256, url }`, or null when the default is in use:
|
|
48
|
+
* what other features (the meta document, the manifest) build the icon URL from.
|
|
49
|
+
*/
|
|
50
|
+
current(purpose: PlatformIconPurpose): Promise<{
|
|
51
|
+
purpose: PlatformIconPurpose;
|
|
52
|
+
sha256: string;
|
|
53
|
+
url: string;
|
|
54
|
+
} | null>;
|
|
55
|
+
/** The upload's checks alone (the Platform operation's precheck); throws the write's refusal. */
|
|
56
|
+
check(purpose: PlatformIconPurpose, contentType: "image/png" | "image/svg+xml", dataBase64: string): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Sets the icon of a purpose. Under the purpose's lock: first the orphan check of the new object
|
|
59
|
+
* is owed (a committed intent), then the object is written, then the row in a transaction that
|
|
60
|
+
* also owes the deletion of the object the row named before (none when the bytes are the same).
|
|
61
|
+
*/
|
|
62
|
+
set(purpose: PlatformIconPurpose, contentType: "image/png" | "image/svg+xml", dataBase64: string, actor: WriteActor, auditDetail?: Record<string, unknown>): Promise<PlatformIconView>;
|
|
63
|
+
/** The intent: the new object's delayed orphan check, owed before the object is written. */
|
|
64
|
+
private oweOrphanCheck;
|
|
65
|
+
/** The row naming the written object, the old object's deletion and the audit event. */
|
|
66
|
+
private commit;
|
|
67
|
+
/**
|
|
68
|
+
* Restores the default of a purpose: the row goes and its object's deletion is owed. Clearing a
|
|
69
|
+
* purpose with no upload changes nothing; returns whether a row was removed.
|
|
70
|
+
*/
|
|
71
|
+
clear(purpose: PlatformIconPurpose, actor: WriteActor, auditDetail?: Record<string, unknown>): Promise<boolean>;
|
|
72
|
+
private remove;
|
|
73
|
+
/**
|
|
74
|
+
* The stored bytes of a purpose for the public route, or `platform_icon.not_found` when the
|
|
75
|
+
* default is in use, `v` names another upload, or the object is missing. `immutable` is true
|
|
76
|
+
* when `v` is the current hash (the URL then never changes meaning).
|
|
77
|
+
*/
|
|
78
|
+
read(purpose: PlatformIconPurpose, v: string | undefined): Promise<{
|
|
79
|
+
contentType: string;
|
|
80
|
+
bytes: Uint8Array;
|
|
81
|
+
immutable: boolean;
|
|
82
|
+
}>;
|
|
83
|
+
}
|