@selfhelp/shared 1.3.2 → 1.4.0

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.
@@ -0,0 +1,446 @@
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ /**
6
+ * Cross-repo SelfHelp distribution contracts: registry index + release metadata
7
+ * (core / frontend / scheduler / worker / plugin), security advisories,
8
+ * compatibility rules, signed trusted keys, the per-instance manifest + lock +
9
+ * inventory, update preflight, backup manifest, and support-bundle metadata.
10
+ *
11
+ * `@selfhelp/shared` is the cross-repo contract SOURCE for these shapes so the
12
+ * web frontend, mobile app, and plugins can consume them without importing the
13
+ * manager. The SelfHelp Manager (`sh-manager/packages/schemas`) keeps the
14
+ * runtime Zod validators + JSON schemas; both MUST stay in parity (verified by
15
+ * `src/types/__tests__/distribution.test.ts` against the manager's example
16
+ * fixtures). The shapes mirror
17
+ * `sh-selfhelp_backend/docs/archive/core-installation-and-distribution-plan.md`.
18
+ *
19
+ * These files are written by the manager as camelCase JSON, so (unlike the
20
+ * snake_case CMS API contracts in `./api/system`) these contracts are camelCase.
21
+ */
22
+
23
+ /**
24
+ * Canonical release channels, shared verbatim across the registry wire schema
25
+ * (`sh2-plugin-registry/registry.schema.json`), the SelfHelp Manager
26
+ * (`@shm/schemas`), and the backend (`RegistryReleaseRef::CHANNELS`). `test` is
27
+ * the staging/rehearsal channel used to dry-run a publish→install→update before
28
+ * promoting to `stable`. Kept as a runtime tuple so cross-repo parity can be
29
+ * asserted (see `__tests__/channel-parity.test.ts`).
30
+ */
31
+ export const RELEASE_CHANNELS = ['stable', 'beta', 'nightly', 'test'] as const;
32
+ export type ReleaseChannel = (typeof RELEASE_CHANNELS)[number];
33
+ export type InstanceMode = 'production' | 'local';
34
+ export type TrustLevel = 'official' | 'reviewed' | 'untrusted';
35
+ export type AdvisorySeverity = 'low' | 'medium' | 'high' | 'critical';
36
+
37
+ /** Ed25519 detached-signature block shared by every signed registry payload. */
38
+ export interface SignatureBlock {
39
+ signature: string;
40
+ keyId: string;
41
+ signedPayload?: string;
42
+ signedPayloadSha256?: string;
43
+ }
44
+
45
+ // ---------------------------------------------------------------------------
46
+ // Server inventory (/opt/selfhelp/selfhelp.server.json)
47
+ // ---------------------------------------------------------------------------
48
+
49
+ export type InstanceStatus =
50
+ | 'active'
51
+ | 'disabled'
52
+ | 'removed_keep_data'
53
+ | 'installing'
54
+ | 'updating'
55
+ | 'error';
56
+
57
+ export interface InventoryInstanceEntry {
58
+ instanceId: string;
59
+ domain: string;
60
+ path: string;
61
+ composeProject: string;
62
+ status: InstanceStatus;
63
+ }
64
+
65
+ export interface ServerInventory {
66
+ inventoryVersion: number;
67
+ serverId: string;
68
+ manager: {
69
+ name: string;
70
+ repository: string;
71
+ version: string;
72
+ };
73
+ proxy: {
74
+ type: 'traefik';
75
+ network: string;
76
+ composePath: string;
77
+ };
78
+ instances: InventoryInstanceEntry[];
79
+ }
80
+
81
+ // ---------------------------------------------------------------------------
82
+ // Instance manifest (selfhelp.instance.json)
83
+ // ---------------------------------------------------------------------------
84
+
85
+ export interface InstanceVersions {
86
+ selfhelp: string;
87
+ backend: string;
88
+ frontend: string;
89
+ scheduler: string;
90
+ worker: string;
91
+ pluginApi: string;
92
+ }
93
+
94
+ export interface InstanceImages {
95
+ backend: string;
96
+ frontend: string;
97
+ scheduler: string;
98
+ worker: string;
99
+ mysql: string;
100
+ redis: string;
101
+ mercure: string;
102
+ }
103
+
104
+ export interface InstanceRouting {
105
+ publicFrontendUrl: string;
106
+ browserApiPrefix: string;
107
+ internalSymfonyUrl: string;
108
+ symfonyApiPrefix: string;
109
+ }
110
+
111
+ export interface InstalledPlugin {
112
+ id: string;
113
+ version: string;
114
+ }
115
+
116
+ export interface InstanceResourceConfig {
117
+ memoryLimitMb?: number;
118
+ cpuLimit?: number;
119
+ diskWarnThresholdGb?: number;
120
+ logMaxSizeMb?: number;
121
+ logMaxFiles?: number;
122
+ }
123
+
124
+ export interface InstanceManifest {
125
+ manifestVersion: number;
126
+ instanceId: string;
127
+ displayName: string;
128
+ domain: string;
129
+ mode: InstanceMode;
130
+ createdAt: string;
131
+ updatedAt: string;
132
+ registry: {
133
+ id: string;
134
+ url: string;
135
+ channel: ReleaseChannel;
136
+ };
137
+ versions: InstanceVersions;
138
+ images: InstanceImages;
139
+ routing: InstanceRouting;
140
+ installedPlugins: InstalledPlugin[];
141
+ resources?: InstanceResourceConfig;
142
+ }
143
+
144
+ // ---------------------------------------------------------------------------
145
+ // Instance lock file (selfhelp.lock.json)
146
+ // ---------------------------------------------------------------------------
147
+
148
+ export interface LockServiceEntry {
149
+ image: string;
150
+ digest: string;
151
+ }
152
+
153
+ export interface LockPluginEntry {
154
+ version: string;
155
+ artifactSha256: string;
156
+ signature: string;
157
+ keyId: string;
158
+ compatibility: {
159
+ core: string;
160
+ pluginApi: string;
161
+ };
162
+ }
163
+
164
+ export interface InstanceLock {
165
+ lockfileVersion: number;
166
+ generatedAt: string;
167
+ operationId?: string;
168
+ registry: {
169
+ id: string;
170
+ url: string;
171
+ metadataSha256: string;
172
+ };
173
+ core: {
174
+ version: string;
175
+ backendImageDigest: string;
176
+ frontendImageDigest: string;
177
+ schedulerImageDigest: string;
178
+ workerImageDigest: string;
179
+ migrationVersion: string;
180
+ pluginApiVersion: string;
181
+ signedPayloadSha256: string;
182
+ };
183
+ services: {
184
+ mysql: LockServiceEntry;
185
+ redis: LockServiceEntry;
186
+ mercure: LockServiceEntry;
187
+ };
188
+ plugins: Record<string, LockPluginEntry>;
189
+ }
190
+
191
+ // ---------------------------------------------------------------------------
192
+ // Registry index + release metadata
193
+ // ---------------------------------------------------------------------------
194
+
195
+ export interface RegistryReleaseRef {
196
+ id: string;
197
+ version: string;
198
+ channel: ReleaseChannel;
199
+ releaseUrl: string;
200
+ blocked?: boolean;
201
+ }
202
+
203
+ export interface RegistryIndex {
204
+ schemaVersion: string;
205
+ requiresManager: string;
206
+ publishedAt: string;
207
+ baseUrl: string;
208
+ publisher: {
209
+ name: string;
210
+ url: string;
211
+ };
212
+ core: RegistryReleaseRef[];
213
+ frontend: RegistryReleaseRef[];
214
+ scheduler: RegistryReleaseRef[];
215
+ worker: RegistryReleaseRef[];
216
+ plugins: RegistryReleaseRef[];
217
+ advisoriesUrl?: string;
218
+ compatibilityUrl?: string;
219
+ trustedKeysUrl?: string;
220
+ }
221
+
222
+ export interface DatabaseMigrationMetadata {
223
+ migrationRange: string;
224
+ destructive: boolean;
225
+ requiresBackup: boolean;
226
+ manualConfirmationRequired: boolean;
227
+ minimumSafeRollbackPoint?: string;
228
+ automaticRollback?: string;
229
+ }
230
+
231
+ export interface ImageRef {
232
+ image: string;
233
+ digest: string;
234
+ phpVersion?: string;
235
+ }
236
+
237
+ export interface RuntimeServiceRange {
238
+ supportedVersions: string;
239
+ minimumRequired?: string;
240
+ recommendedVersion?: string;
241
+ recommendedImage: string;
242
+ recommendedDigest?: string;
243
+ updateRequired?: boolean;
244
+ majorUpgradeRequiresManualApproval?: boolean;
245
+ }
246
+
247
+ export interface RuntimeServicePolicy {
248
+ php?: { backendImagePhpVersion: string };
249
+ mysql: RuntimeServiceRange;
250
+ redis: RuntimeServiceRange;
251
+ mercure: RuntimeServiceRange;
252
+ traefik?: RuntimeServiceRange;
253
+ }
254
+
255
+ export interface CoreRelease {
256
+ kind: 'selfhelp-core-release';
257
+ id: string;
258
+ version: string;
259
+ channel: ReleaseChannel;
260
+ releasedAt: string;
261
+ minimumDirectUpgradeFrom: string;
262
+ pluginApiVersion: string;
263
+ backend: ImageRef;
264
+ worker: ImageRef;
265
+ scheduler: ImageRef;
266
+ frontendCompatibility: { requiredFrontendRange: string };
267
+ database: DatabaseMigrationMetadata;
268
+ runtime?: RuntimeServicePolicy;
269
+ artifacts?: { sbom?: { url: string; sha256: string } };
270
+ security: SignatureBlock;
271
+ blocked?: boolean;
272
+ }
273
+
274
+ export interface FrontendRelease {
275
+ kind: 'selfhelp-frontend-release';
276
+ id: string;
277
+ version: string;
278
+ channel: ReleaseChannel;
279
+ image: string;
280
+ digest: string;
281
+ builtFrom?: { nextStandalone: boolean; sharedPackageVersion: string };
282
+ backendCompatibility: { requiredCoreRange: string; requiredApiVersion: string };
283
+ security: SignatureBlock;
284
+ blocked?: boolean;
285
+ }
286
+
287
+ /** Compatibility descriptor shared by core-coupled service releases. */
288
+ export interface ServiceBackendCompatibility {
289
+ requiredCoreRange: string;
290
+ requiredApiVersion?: string;
291
+ }
292
+
293
+ /** Scheduled-jobs runner release, resolved/pinned as a first-class artifact. */
294
+ export interface SchedulerRelease {
295
+ kind: 'selfhelp-scheduler-release';
296
+ id: string;
297
+ version: string;
298
+ channel: ReleaseChannel;
299
+ image: string;
300
+ digest: string;
301
+ builtFrom?: Record<string, unknown>;
302
+ backendCompatibility: ServiceBackendCompatibility;
303
+ security: SignatureBlock;
304
+ blocked?: boolean;
305
+ }
306
+
307
+ /** Messenger worker release, resolved/pinned as a first-class artifact. */
308
+ export interface WorkerRelease {
309
+ kind: 'selfhelp-worker-release';
310
+ id: string;
311
+ version: string;
312
+ channel: ReleaseChannel;
313
+ image: string;
314
+ digest: string;
315
+ builtFrom?: Record<string, unknown>;
316
+ backendCompatibility: ServiceBackendCompatibility;
317
+ security: SignatureBlock;
318
+ blocked?: boolean;
319
+ }
320
+
321
+ export interface PluginRelease {
322
+ kind: 'selfhelp-plugin-release';
323
+ id: string;
324
+ version: string;
325
+ channel: ReleaseChannel;
326
+ official: boolean;
327
+ compatibility: { core: string; pluginApi: string };
328
+ dependencies?: { plugins: { id: string; range: string }[] };
329
+ artifacts: { manifestUrl: string; archiveUrl: string; sha256: string };
330
+ security: SignatureBlock;
331
+ blocked?: boolean;
332
+ }
333
+
334
+ // ---------------------------------------------------------------------------
335
+ // Compatibility + advisories
336
+ // ---------------------------------------------------------------------------
337
+
338
+ export interface CompatibilityRules {
339
+ schemaVersion: string;
340
+ rules: {
341
+ selfhelp: string;
342
+ runtime: RuntimeServicePolicy;
343
+ }[];
344
+ }
345
+
346
+ export interface AdvisoryAffected {
347
+ kind: 'core' | 'frontend' | 'plugin';
348
+ id?: string;
349
+ versions: string;
350
+ }
351
+
352
+ export interface SecurityAdvisory {
353
+ id: string;
354
+ severity: AdvisorySeverity;
355
+ affected: AdvisoryAffected[];
356
+ fixed: { kind: 'core' | 'frontend' | 'plugin'; id?: string; version: string }[];
357
+ recommendedAction: string;
358
+ blocked: boolean;
359
+ detailsUrl?: string;
360
+ }
361
+
362
+ export interface AdvisoryFeed {
363
+ schemaVersion: string;
364
+ advisories: SecurityAdvisory[];
365
+ }
366
+
367
+ export interface TrustedKey {
368
+ keyId: string;
369
+ publicKey: string;
370
+ algorithm: 'ed25519';
371
+ status: 'active' | 'revoked';
372
+ }
373
+
374
+ export interface TrustedKeysFile {
375
+ schemaVersion: string;
376
+ keys: TrustedKey[];
377
+ }
378
+
379
+ // ---------------------------------------------------------------------------
380
+ // Preflight / update plan
381
+ // ---------------------------------------------------------------------------
382
+
383
+ export type PreflightStatus = 'ok' | 'warning' | 'blocked';
384
+ export type CheckSeverity = 'info' | 'warning' | 'error';
385
+
386
+ export interface PreflightCheck {
387
+ code: string;
388
+ severity: CheckSeverity;
389
+ message: string;
390
+ }
391
+
392
+ export interface PreflightOption {
393
+ type: string;
394
+ version?: string;
395
+ label: string;
396
+ }
397
+
398
+ export interface UpdatePreflightResult {
399
+ preflightVersion: number;
400
+ status: PreflightStatus;
401
+ instanceId: string;
402
+ currentVersion: string;
403
+ targetVersion: string;
404
+ checks: PreflightCheck[];
405
+ options: PreflightOption[];
406
+ database: {
407
+ destructive: boolean;
408
+ requiresBackup: boolean;
409
+ manualConfirmationRequired: boolean;
410
+ };
411
+ rollback: {
412
+ automaticBeforeMigrations: boolean;
413
+ /**
414
+ * MVP policy: automatic rollback is NEVER promised after a destructive
415
+ * migration (the only recovery is restoring the verified backup).
416
+ */
417
+ automaticAfterDestructiveMigrations: boolean;
418
+ };
419
+ }
420
+
421
+ // ---------------------------------------------------------------------------
422
+ // Backup manifest + support bundle
423
+ // ---------------------------------------------------------------------------
424
+
425
+ export interface BackupManifest {
426
+ backupManifestVersion: number;
427
+ backupId: string;
428
+ instanceId: string;
429
+ createdAt: string;
430
+ mode: 'maintenance' | 'online';
431
+ selfhelpVersion: string;
432
+ migrationVersion: string;
433
+ plugins: InstalledPlugin[];
434
+ includedAreas: string[];
435
+ files: { path: string; sha256: string; bytes: number }[];
436
+ }
437
+
438
+ export interface SupportBundleMeta {
439
+ supportBundleVersion: number;
440
+ instanceId: string;
441
+ createdAt: string;
442
+ managerVersion: string;
443
+ schemaVersions: Record<string, number | string>;
444
+ redactionApplied: true;
445
+ contents: string[];
446
+ }
@@ -14,4 +14,5 @@ export * from './styles/unknown';
14
14
  export * from './pages';
15
15
  export * from './auth';
16
16
  export * from './api';
17
+ export * from './distribution';
17
18
  export * from './mantine/common';