@camstack/system 1.2.81 → 1.2.82

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.
Files changed (51) hide show
  1. package/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  2. package/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  3. package/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  4. package/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  5. package/dist/builtins/alerts/alerts.addon.js +1 -1
  6. package/dist/builtins/alerts/alerts.addon.mjs +1 -1
  7. package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +1 -1
  8. package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +1 -1
  9. package/dist/builtins/console-logging/index.js +1 -1
  10. package/dist/builtins/console-logging/index.mjs +1 -1
  11. package/dist/builtins/core-blocks/core-blocks.addon.js +1 -1
  12. package/dist/builtins/core-blocks/core-blocks.addon.mjs +1 -1
  13. package/dist/builtins/device-manager/device-manager.addon.js +1 -1
  14. package/dist/builtins/device-manager/device-manager.addon.mjs +1 -1
  15. package/dist/builtins/doorbell/virtual-doorbell.addon.js +1 -1
  16. package/dist/builtins/doorbell/virtual-doorbell.addon.mjs +1 -1
  17. package/dist/builtins/hub-forwarder/index.js +1 -1
  18. package/dist/builtins/hub-forwarder/index.mjs +1 -1
  19. package/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  20. package/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  21. package/dist/builtins/local-auth/local-auth.addon.js +1 -1
  22. package/dist/builtins/local-auth/local-auth.addon.mjs +1 -1
  23. package/dist/builtins/local-network/local-network.addon.js +1 -1
  24. package/dist/builtins/local-network/local-network.addon.mjs +1 -1
  25. package/dist/builtins/loki-logging/index.js +1 -1
  26. package/dist/builtins/loki-logging/index.mjs +1 -1
  27. package/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  28. package/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  29. package/dist/builtins/platform-probe/index.js +1 -1
  30. package/dist/builtins/platform-probe/index.mjs +1 -1
  31. package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  32. package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  33. package/dist/builtins/snapshot/index.js +1 -1
  34. package/dist/builtins/snapshot/index.mjs +1 -1
  35. package/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  36. package/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  37. package/dist/builtins/sqlite-storage/sqlite-settings.addon.js +1 -1
  38. package/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +1 -1
  39. package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
  40. package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
  41. package/dist/builtins/system-config/system-config.addon.js +1 -1
  42. package/dist/builtins/system-config/system-config.addon.mjs +1 -1
  43. package/dist/builtins/winston-logging/index.js +1 -1
  44. package/dist/builtins/winston-logging/index.mjs +1 -1
  45. package/dist/{dist-CA2mim74.js → dist-DUDXaubL.js} +144 -6
  46. package/dist/{dist-DZOZtn-0.mjs → dist-DpL4mUA4.mjs} +144 -6
  47. package/dist/index.js +165 -36
  48. package/dist/index.mjs +165 -36
  49. package/dist/kernel/addon-installer.d.ts +54 -2
  50. package/dist/kernel/addon-loader.d.ts +33 -0
  51. package/package.json +1 -1
@@ -3305,8 +3305,31 @@ var AdoptionJobSchema = z.object({
3305
3305
  error: z.string().nullable()
3306
3306
  });
3307
3307
  /**
3308
- * Per-camera FUNCTION SWITCHES — the one coherent on/off surface over the
3309
- * pipeline functions an operator thinks in terms of.
3308
+ * Per-camera FUNCTION SWITCHES.
3309
+ *
3310
+ * ## The aggregate group is being withdrawn — the BADGE is not (D113)
3311
+ *
3312
+ * This file shipped as "the one coherent on/off surface over the pipeline
3313
+ * functions an operator thinks in terms of". The operator's verdict on
3314
+ * 2026-08-12 was that the coherent surface bought complexity and no clarity:
3315
+ * every function already had a settings page of its own, and a second place to
3316
+ * turn it off is a second place to look. Each switch is going back to its own
3317
+ * component's original options — detection to the detection-pipeline wrapper
3318
+ * binding, audio analysis to its own, recording to `RecordingConfig.enabled`
3319
+ * (which was always first-class; the switch was a veneer over
3320
+ * `recording.setDeviceConfig`), notifications to a notification-center
3321
+ * per-device setting, the two camera planes to their own components.
3322
+ *
3323
+ * What survives is {@link composeSwitchedOff}: `CameraStatus.switchedOff`, the
3324
+ * thing that lets a status surface say DISABLED instead of BROKEN, recomposed
3325
+ * straight from the authorities with no group in the middle. That rule was
3326
+ * never about a control panel.
3327
+ *
3328
+ * Everything else here — {@link CAMERA_SWITCH_CATALOG}, {@link CameraSwitch},
3329
+ * {@link deriveCameraSwitches}, the `pipelineOrchestrator.getCameraSwitches` /
3330
+ * `setCameraSwitch` pair — is a COMPATIBILITY surface for as long as deployed
3331
+ * viewers (v1.0.305) and the admin UI still call it. It is deleted when they
3332
+ * stop; nothing new may be built on it.
3310
3333
  *
3311
3334
  * ## This file adds no state
3312
3335
  *
@@ -16538,9 +16561,16 @@ var CameraStatusSchema = z.object({
16538
16561
  audio: CameraAudioStatusSchema.nullable(),
16539
16562
  recording: CameraRecordingStatusSchema.nullable(),
16540
16563
  /**
16541
- * Per-camera function switches an OPERATOR has turned off
16564
+ * Per-camera functions an OPERATOR has turned off
16542
16565
  * ([D61](../../../../docs/decisions/adr-0067.md)).
16543
16566
  *
16567
+ * Composed from the AUTHORITIES themselves — the wrapper bindings,
16568
+ * `RecordingConfig.enabled`, the notification mute, the broker's audio
16569
+ * policy, the camera's own microphone — via `composeSwitchedOff`, not from
16570
+ * the deprecated `getCameraSwitches` group ([D113](../../../../docs/decisions/adr-0113.md)).
16571
+ * The badge outlives the control panel: the panel was a convenience, this is
16572
+ * the difference between a camera being off and a camera being dead.
16573
+ *
16544
16574
  * This is the difference between DISABLED and BROKEN. A camera whose
16545
16575
  * `detection` block reports zero fps and whose `switchedOff` contains
16546
16576
  * `'object-detection'` was switched off by a person; the same camera with an
@@ -16979,6 +17009,10 @@ var pipelineOrchestratorCapability = {
16979
17009
  agentNodeId: z.string().optional()
16980
17010
  }), CameraPipelineConfigSchema),
16981
17011
  /**
17012
+ * @deprecated The aggregate switch group is being withdrawn
17013
+ * ([D113](../../../../docs/decisions/adr-0113.md)). Build nothing new on
17014
+ * this pair; read the authority directly.
17015
+ *
16982
17016
  * The whole per-camera function switch group, DERIVED — never a stored
16983
17017
  * list ([D61](../../../../docs/decisions/adr-0067.md)).
16984
17018
  *
@@ -16992,9 +17026,23 @@ var pipelineOrchestratorCapability = {
16992
17026
  * `auth: 'view'` deliberately — a NON-admin must be able to see that a
16993
17027
  * camera is quiet because somebody switched it off. Only the mutation is
16994
17028
  * admin-gated.
17029
+ *
17030
+ * **Removal plan.** It stays and it KEEPS WORKING while shipped viewers
17031
+ * (v1.0.305) and the admin UI still call it — removing it now is a broken
17032
+ * app on a device nobody can redeploy from here. It is served by a thin
17033
+ * shim over the same authorities (`camera-switch-service.ts`), so the
17034
+ * behaviour of the pair is the behaviour of the authorities by
17035
+ * construction. It is deleted once every surface reaches its own
17036
+ * component's options and the last caller is gone. Nothing on this server
17037
+ * reads it: `CameraStatus.switchedOff` is composed from the authorities
17038
+ * directly via `composeSwitchedOff`.
16995
17039
  */
16996
17040
  getCameraSwitches: method(z.object({ deviceId: z.number() }), CameraSwitchGroupSchema),
16997
17041
  /**
17042
+ * @deprecated See {@link getCameraSwitches}. Write the authority — the
17043
+ * wrapper binding, `RecordingConfig.enabled`, the notification mute — not
17044
+ * this ([D113](../../../../docs/decisions/adr-0113.md)).
17045
+ *
16998
17046
  * Flip ONE switch, routed to its existing authority.
16999
17047
  *
17000
17048
  * Never writes a parallel map: `recording` patches `RecordingConfig.enabled`
@@ -25240,10 +25288,42 @@ var recordingCapability = {
25240
25288
  */
25241
25289
  /** Playback-speed multiplier for the render (1 = realtime). */
25242
25290
  var ExportSpeedSchema = z.number().min(.25).max(32);
25291
+ /**
25292
+ * One dense interval, in SECONDS FROM THE EXPORT'S OWN `fromMs`.
25293
+ *
25294
+ * Relative and not absolute epoch on purpose: the renderer's frame-select
25295
+ * expression sees ffmpeg's `t`, which starts at 0 for the export's source
25296
+ * playlist. Handing it absolute epochs would make every call site responsible
25297
+ * for the same subtraction, and the one that forgot would emit a filter that
25298
+ * selects nothing — silently, as a uniform timelapse.
25299
+ */
25300
+ var ExportDenseRangeSchema = z.object({
25301
+ fromSec: z.number().nonnegative(),
25302
+ toSec: z.number().nonnegative()
25303
+ }).refine((r) => r.toSec > r.fromSec, { message: "dense range must have toSec > fromSec" });
25304
+ /**
25305
+ * Dense-interval overlay for a timelapse: sample at `dense.everyMs` INSIDE the
25306
+ * listed ranges and at the base `everyMs` everywhere else.
25307
+ *
25308
+ * `everyMs` must be strictly smaller than the base cadence — a dense rate that
25309
+ * is not denser renders a uniform timelapse the operator believes is two-rate.
25310
+ */
25311
+ var ExportDenseSchema = z.object({
25312
+ everyMs: z.number().int().positive(),
25313
+ ranges: z.array(ExportDenseRangeSchema).min(1).max(200)
25314
+ });
25243
25315
  /** Timelapse cadence — sample one source frame per `everyMs`, output at `outputFps`. */
25244
25316
  var ExportTimelapseSchema = z.object({
25245
25317
  everyMs: z.number().int().positive(),
25246
- outputFps: z.number().int().min(1).max(60).optional()
25318
+ outputFps: z.number().int().min(1).max(60).optional(),
25319
+ /** Optional second, FASTER rate over the intervals that matter. */
25320
+ dense: ExportDenseSchema.optional()
25321
+ }).superRefine((v, ctx) => {
25322
+ if (v.dense !== void 0 && v.dense.everyMs >= v.everyMs) ctx.addIssue({
25323
+ code: z.ZodIssueCode.custom,
25324
+ message: "dense.everyMs must be strictly smaller than the base everyMs",
25325
+ path: ["dense", "everyMs"]
25326
+ });
25247
25327
  });
25248
25328
  /**
25249
25329
  * Render options. `speed` and `timelapse` are mutually exclusive. `includeAudio`
@@ -25301,6 +25381,19 @@ var ExportDownloadSchema = z.object({
25301
25381
  url: z.string(),
25302
25382
  endpoints: z.array(z.string())
25303
25383
  });
25384
+ /**
25385
+ * A finished export's bytes, inline.
25386
+ *
25387
+ * `bytes` is the DECODED length — the number the caller bounds and logs
25388
+ * against, so nobody has to infer it from the base64 length.
25389
+ */
25390
+ var ExportBytesSchema = z.object({
25391
+ base64: z.string(),
25392
+ contentType: z.string(),
25393
+ /** Suggested filename, extension included. */
25394
+ name: z.string(),
25395
+ bytes: z.number().int().nonnegative()
25396
+ });
25304
25397
  var recordingExportCapability = {
25305
25398
  name: "recordingExport",
25306
25399
  scope: "system",
@@ -25340,6 +25433,27 @@ var recordingExportCapability = {
25340
25433
  getDownloadUrl: method(z.object({ exportId: z.string() }), ExportDownloadSchema, {
25341
25434
  kind: "query",
25342
25435
  auth: "protected"
25436
+ }),
25437
+ /**
25438
+ * The finished file's BYTES, base64, for a caller that must republish them
25439
+ * somewhere a session-less fetcher can reach.
25440
+ *
25441
+ * `getDownloadUrl` is the right answer for a human: the download route is
25442
+ * served `access: 'authenticated'`, which a browser satisfies and a
25443
+ * notifier BACKEND does not. It answers a RELATIVE path, so it is not even
25444
+ * a URL an outside fetcher could try. This method exists for the one case
25445
+ * that needs the other thing — a scheduled timelapse whose video has to
25446
+ * become a public attachment on the notification artifact plane.
25447
+ *
25448
+ * Deliberately narrow: `ready` only (a queued, rendering, failed, expired
25449
+ * or deleted export has no file, and answering "0 bytes" for one is how a
25450
+ * caller ships an empty attachment), still inside its lifetime, and under
25451
+ * {@link RECORDING_EXPORT_MAX_READ_BYTES}. Every refusal throws with the
25452
+ * reason — none of them is silent.
25453
+ */
25454
+ readExportBytes: method(z.object({ exportId: z.string() }), ExportBytesSchema, {
25455
+ kind: "query",
25456
+ auth: "protected"
25343
25457
  })
25344
25458
  }
25345
25459
  };
@@ -32063,6 +32177,12 @@ var METHOD_ACCESS_MAP = Object.freeze({
32063
32177
  addonId: null,
32064
32178
  access: "view"
32065
32179
  },
32180
+ "recordingExport.readExportBytes": {
32181
+ capName: "recordingExport",
32182
+ capScope: "system",
32183
+ addonId: null,
32184
+ access: "view"
32185
+ },
32066
32186
  "sceneMonitor.captureReference": {
32067
32187
  capName: "scene-monitor",
32068
32188
  capScope: "device",
@@ -33480,10 +33600,28 @@ TimelapseRuleInputSchema.extend({
33480
33600
  */
33481
33601
  ownerUserId: z.string().optional(),
33482
33602
  /**
33483
- * Epoch-ms of the last successful generation the 1-hour re-generation
33484
- * guard's durable state (predecessor parity). Absent = never generated.
33603
+ * Epoch-ms of the NEWEST successful generation across every camera of this
33604
+ * rule. What a UI shows, and the compatibility floor for
33605
+ * {@link readTimelapseGeneratedAt}. Absent = never generated.
33485
33606
  */
33486
33607
  lastGeneratedAt: z.number().optional(),
33608
+ /**
33609
+ * PER-CAMERA generation state, keyed by `String(deviceId)` — the
33610
+ * re-generation guard's real durable state.
33611
+ *
33612
+ * One rule covers several cameras and each renders its own video, so a rule
33613
+ * -wide stamp is wrong in the direction that DESTROYS work: camera A
33614
+ * succeeding at 06:05 tells camera B, whose render failed, that it is
33615
+ * already done — and B's night is gone for good, because the window will not
33616
+ * come back.
33617
+ *
33618
+ * ADDITIVE, so the migration is free: a row written before this field simply
33619
+ * has no map, and {@link readTimelapseGeneratedAt} falls back to
33620
+ * {@link TimelapseRuleSchema.shape.lastGeneratedAt}. Reading an old row as
33621
+ * "never generated" would re-render and re-notify every camera of every rule
33622
+ * once, on the deploy that shipped the map.
33623
+ */
33624
+ generatedByDevice: z.record(z.string(), z.number()).optional(),
33487
33625
  /** userId of the caller who created the rule (server-stamped). */
33488
33626
  createdBy: z.string(),
33489
33627
  createdAt: z.number(),
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_chunk = require("./chunk-Cek0wNdY.js");
3
- const require_dist = require("./dist-CA2mim74.js");
3
+ const require_dist = require("./dist-DUDXaubL.js");
4
4
  const require_builtins_alerts_alerts_addon = require("./builtins/alerts/alerts.addon.js");
5
5
  require("./builtins/alerts/index.js");
6
6
  const require_formatter = require("./formatter-DqAKDlvN.js");
@@ -3072,6 +3072,74 @@ function isRecord$1(value) {
3072
3072
  return typeof value === "object" && value !== null && !Array.isArray(value);
3073
3073
  }
3074
3074
  /**
3075
+ * How far up from the entry file to look for the owning `package.json`
3076
+ * (`<pkg>/dist/chunks/x.js` → 3 hops). Bounded so a loose module outside a
3077
+ * package can't walk to the filesystem root.
3078
+ */
3079
+ var PACKAGE_JSON_LOOKUP_DEPTH = 4;
3080
+ /** Version from the `package.json` that owns `entryPath`, or null. */
3081
+ function readOwningPackageVersion(entryPath) {
3082
+ let dir = node_path.dirname(entryPath);
3083
+ for (let hop = 0; hop < PACKAGE_JSON_LOOKUP_DEPTH; hop++) {
3084
+ try {
3085
+ const version = require_dist.asJsonObject(require_dist.parseJsonUnknown(node_fs.readFileSync(node_path.join(dir, "package.json"), "utf-8")))?.["version"];
3086
+ if (typeof version === "string" && version.length > 0) return version;
3087
+ } catch {}
3088
+ const parent = node_path.dirname(dir);
3089
+ if (parent === dir) break;
3090
+ dir = parent;
3091
+ }
3092
+ return null;
3093
+ }
3094
+ /**
3095
+ * Cache-bust key for an addon entry module: the `?v=` query that makes each
3096
+ * on-disk REVISION of `entryPath` a distinct ESM module URL. Returns null when
3097
+ * the entry cannot be stat'd — the caller then does a plain import.
3098
+ *
3099
+ * The key is `<version>-<content hash>`, and BOTH halves are load-bearing
3100
+ * because each on its own has a documented way of not changing across a real
3101
+ * redeploy:
3102
+ *
3103
+ * - **mtime does not change.** `npm pack` normalises every file's mtime in the
3104
+ * tarball to 499162500000 (1985-10-26); every install path here extracts
3105
+ * such a tarball, so the entry file of v1.0.0 and of v1.0.99 carry the same
3106
+ * mtime. An mtime-only key (what this used to be) is a NO-OP — it produced
3107
+ * one byte-identical URL for every version of every addon ever installed.
3108
+ * - **the version does not change** on a `camstack deploy` of an unbumped
3109
+ * workspace package — the whole dev loop.
3110
+ * - **the entry hash does not change** when a multi-chunk dist alters a chunk
3111
+ * the entry only re-exports; the version bump covers that case.
3112
+ *
3113
+ * Hashing the entry costs one extra read of an already-read file (~1.5 MB for
3114
+ * the largest addon bundle, single-digit ms) once per addon load. Cheap against
3115
+ * what a stale key costs: hub-main keeps validating `addons.custom` input
3116
+ * against the OLD `customActions` schema — silently STRIPPING newly-added
3117
+ * fields — and, worse, Node caches a load that THREW as a rejected module and
3118
+ * replays that rejection for every later retry at the same URL. On 2026-08-12
3119
+ * `@camstack/addon-export-hap` burned 126 identical failed load retries over
3120
+ * 10.5h, none of which could have succeeded: the fixed bytes on disk were never
3121
+ * read.
3122
+ *
3123
+ * Never throws: an unreadable version degrades to the mtime, an unreadable body
3124
+ * to mtime+size.
3125
+ */
3126
+ function addonModuleCacheKey(entryPath) {
3127
+ let stat;
3128
+ try {
3129
+ stat = node_fs.statSync(entryPath);
3130
+ } catch {
3131
+ return null;
3132
+ }
3133
+ const version = readOwningPackageVersion(entryPath) ?? `m${stat.mtimeMs}`;
3134
+ let content;
3135
+ try {
3136
+ content = (0, node_crypto.createHash)("sha1").update(node_fs.readFileSync(entryPath)).digest("hex").slice(0, 16);
3137
+ } catch {
3138
+ content = `m${stat.mtimeMs}s${stat.size}`;
3139
+ }
3140
+ return `${version}-${content}`;
3141
+ }
3142
+ /**
3075
3143
  * Import an addon entry module FRESH on every load, defeating Node's
3076
3144
  * per-URL ESM module cache.
3077
3145
  *
@@ -3080,23 +3148,15 @@ function isRecord$1(value) {
3080
3148
  * redeploy returns the STALE previously-cached module. The addon RUNNER child
3081
3149
  * is a fresh process so it reloads correctly — but hub-main also imports the
3082
3150
  * module to read its static catalog (`customActions` Zod schemas, addon class)
3083
- * for the `addons.custom` "validate on the way in" guard. Without cache-busting
3084
- * that guard keeps validating against the OLD schema, silently STRIPPING any
3085
- * newly-added custom-action input field until a full hub restart (observed:
3086
- * benchmark `deviceKey`/multi-device fan-out fields dropped after redeploy).
3151
+ * for the `addons.custom` "validate on the way in" guard.
3087
3152
  *
3088
- * Appending a `?v=<mtimeMs>` query makes each on-disk version a distinct module
3089
- * URL, so a redeploy (new mtime) loads the fresh module. Falls back to a plain
3090
- * import if the file can't be stat'd.
3153
+ * The distinguishing key is {@link addonModuleCacheKey}; a plain import is the
3154
+ * fallback when the entry cannot be stat'd.
3091
3155
  */
3092
3156
  async function importAddonModuleFresh(entryPath) {
3093
- let bust;
3094
- try {
3095
- bust = node_fs.statSync(entryPath).mtimeMs;
3096
- } catch {
3097
- return import(entryPath);
3098
- }
3099
- return import(`${(0, node_url.pathToFileURL)(entryPath).href}?v=${bust}`);
3157
+ const bust = addonModuleCacheKey(entryPath);
3158
+ if (bust === null) return import(entryPath);
3159
+ return import(`${(0, node_url.pathToFileURL)(entryPath).href}?v=${encodeURIComponent(bust)}`);
3100
3160
  }
3101
3161
  /**
3102
3162
  * Package.json manifest boundary: the `camstack` field is authored by third-party
@@ -4518,6 +4578,79 @@ var AddonInstaller = class AddonInstaller {
4518
4578
  force: true
4519
4579
  }).catch(() => void 0)));
4520
4580
  }
4581
+ /**
4582
+ * Make `pkgDir` (an addon tree that has NOT been swapped in yet) runnable:
4583
+ * strip the host-provided deps from its manifest, then `npm install` whatever
4584
+ * survives.
4585
+ *
4586
+ * ONE implementation for every path that materialises an addon tree —
4587
+ * `installFromTgz` (deploy/upload) and `applyUpdateFromStaged` (OTA). The OTA
4588
+ * path did not have it, and that is a whole outage class: an addon declaring
4589
+ * `camstack.runtimeDependencies` was broken by its FIRST OTA update, its dist
4590
+ * landing without `node_modules`. Every load then threw `Cannot find module`
4591
+ * and the retry loop replayed it — `@camstack/addon-export-hap`, 126 failed
4592
+ * load retries over 10.5h on 2026-08-12; `@camstack/addon-remote-storage`
4593
+ * (`@aws-sdk/*`, `webdav`) is the same landmine.
4594
+ *
4595
+ * **Strip.** `@camstack/*` are host-provided system packages that resolve via
4596
+ * the host's node_modules (Node walks up from the installed addon dir). Left
4597
+ * in, this `npm install` pulls the LAST PUBLISHED `@camstack/types` (etc.)
4598
+ * into the addon's OWN node_modules where it SHADOWS the host's fresh copy —
4599
+ * local additions to a system package silently never reach the deployed
4600
+ * addon. Addon dists are self-contained besides, so `stripBundledDeps` keeps
4601
+ * only what the manifest explicitly declares in
4602
+ * `camstack.runtimeDependencies` (see fs-utils / ADR-0027). Nothing left to
4603
+ * install is the COMMON case: skip npm rather than pay an empty round-trip.
4604
+ *
4605
+ * **Failure is FATAL.** This used to warn-and-continue on the tgz path ("the
4606
+ * addon may still load if imports are lazy") — live cost: a host with no npm
4607
+ * (packaged Electron Mac agent) installed every runtime-dep addon WITHOUT its
4608
+ * node_modules for DAYS; each reported "running" while its entry failed at
4609
+ * import (`Cannot find module 'sharp'`), the detection group ran 1/3 members,
4610
+ * and the node silently dropped out of the balancer. Throwing here is what
4611
+ * keeps the PREVIOUS install intact: every caller builds the tree before it
4612
+ * swaps, so an abort simply means the swap never happens.
4613
+ *
4614
+ * A missing/unreadable manifest is NOT fatal — it is logged and skipped. The
4615
+ * callers validate the tree themselves, and a tree with no readable
4616
+ * package.json has no declared deps to install (the loader will skip the
4617
+ * package entirely).
4618
+ */
4619
+ async installRuntimeDependencies(pkgDir, packageName) {
4620
+ const pkgJsonPath = node_path.join(pkgDir, "package.json");
4621
+ const pkgView = readPackageJson(pkgJsonPath);
4622
+ if (pkgView == null) {
4623
+ this.logger.error(`${packageName} — no readable package.json in the prepared tree; runtime dependencies NOT installed`, { meta: { pkgJsonPath } });
4624
+ return;
4625
+ }
4626
+ const strippedManifest = stripBundledDeps(pkgView.raw);
4627
+ await node_fs.promises.writeFile(pkgJsonPath, JSON.stringify(strippedManifest, null, 2));
4628
+ const deps = require_dist.asJsonObject(strippedManifest["dependencies"]);
4629
+ const depNames = deps ? Object.keys(deps) : [];
4630
+ if (depNames.length === 0) return;
4631
+ this.logger.info(`${packageName} — installing runtime dependencies`, { meta: {
4632
+ stagingDir: pkgDir,
4633
+ dependencies: depNames
4634
+ } });
4635
+ try {
4636
+ await require_manifest_python_deps.runNpm([
4637
+ "install",
4638
+ "--omit=dev",
4639
+ "--omit=peer",
4640
+ "--no-audit",
4641
+ "--no-fund",
4642
+ "--no-package-lock",
4643
+ ...this.registry ? ["--registry", this.registry] : []
4644
+ ], this.npmRunOptions(pkgDir, 24e4));
4645
+ } catch (err) {
4646
+ this.logger.error(`${packageName} — runtime dependency install FAILED; update ABORTED (a swapped-in copy would fail every load with "Cannot find module")`, { meta: {
4647
+ pkgDir,
4648
+ dependencies: depNames,
4649
+ error: require_dist.errMsg(err)
4650
+ } });
4651
+ throw new Error(`${packageName} — runtime dependency install failed: ${require_dist.errMsg(err)}`, { cause: err });
4652
+ }
4653
+ }
4521
4654
  /** Install addon from a tgz file (uploaded or downloaded) */
4522
4655
  async installFromTgz(tgzPath) {
4523
4656
  const stagingRoot = node_path.join(this.addonsDir, ".staging");
@@ -4541,25 +4674,7 @@ var AddonInstaller = class AddonInstaller {
4541
4674
  if (!pkgView) throw new Error(`Invalid package.json at ${pkgJsonPath}`);
4542
4675
  if (!pkgView.camstackAddons) throw new Error(`Package ${pkgView.name} has no camstack.addons manifest`);
4543
4676
  const targetDir = node_path.join(this.addonsDir, pkgView.name);
4544
- const strippedManifest = stripBundledDeps(pkgView.raw);
4545
- await node_fs.promises.writeFile(pkgJsonPath, JSON.stringify(strippedManifest, null, 2));
4546
- const strippedRuntimeDeps = strippedManifest["dependencies"];
4547
- if (strippedRuntimeDeps != null && typeof strippedRuntimeDeps === "object" && Object.keys(strippedRuntimeDeps).length > 0) {
4548
- this.logger.info(`${pkgView.name} — installing runtime dependencies`, { meta: { stagingDir: pkgDir } });
4549
- try {
4550
- await require_manifest_python_deps.runNpm([
4551
- "install",
4552
- "--omit=dev",
4553
- "--omit=peer",
4554
- "--no-audit",
4555
- "--no-fund",
4556
- "--no-package-lock",
4557
- ...this.registry ? ["--registry", this.registry] : []
4558
- ], this.npmRunOptions(pkgDir, 24e4));
4559
- } catch (err) {
4560
- throw new Error(`${pkgView.name} — runtime dependency install failed: ${require_dist.errMsg(err)}`, { cause: err });
4561
- }
4562
- }
4677
+ await this.installRuntimeDependencies(pkgDir, pkgView.name);
4563
4678
  try {
4564
4679
  await require_manifest_python_deps.installManifestNativeDeps(pkgDir, pkgView.raw, this.logger, this.registry, this.npmCacheDir);
4565
4680
  } catch (nativeErr) {
@@ -4671,18 +4786,32 @@ var AddonInstaller = class AddonInstaller {
4671
4786
  * replaces step 2 ("install new version") with an atomic directory
4672
4787
  * move of `stagedPath` into `addonDir`.
4673
4788
  *
4789
+ * "Skips npm entirely" is true only of the REGISTRY round-trip: the staged
4790
+ * tree is the raw unpacked tarball, so the addon's own
4791
+ * `camstack.runtimeDependencies` still have to be installed into it, exactly
4792
+ * as `installFromTgz` does. Skipping that is what broke every runtime-dep
4793
+ * addon on its first OTA update — see {@link installRuntimeDependencies}.
4794
+ *
4795
+ * Order matters and is `installFromTgz`'s: the tree is COMPLETED FIRST, and
4796
+ * the live install is only then backed up and replaced. So the addon keeps
4797
+ * serving the old version for the whole (minutes-long) npm install, the swap
4798
+ * window stays two renames wide, and a dependency failure aborts with the
4799
+ * previous version untouched instead of leaving a dependency-less copy live.
4800
+ *
4674
4801
  * On cross-device move (EXDEV) falls back to a recursive copy followed
4675
4802
  * by removal of the staged directory. On any swap failure the backup is
4676
4803
  * restored and the error is rethrown — identical recovery to `applyUpdate`.
4677
4804
  *
4678
- * Throws if the package is not tracked in the manifest or if `addonDir`
4679
- * is missing (same preconditions as `applyUpdate`).
4805
+ * Throws if the package is not tracked in the manifest, if `addonDir`
4806
+ * is missing (same preconditions as `applyUpdate`), or if the runtime-dep
4807
+ * install fails.
4680
4808
  */
4681
4809
  async applyUpdateFromStaged(packageName, version, stagedPath) {
4682
4810
  const current = this.manifest.get(packageName);
4683
4811
  if (current == null) throw new Error(`Cannot update ${packageName}: not currently tracked in manifest`);
4684
4812
  const addonDir = node_path.join(this.addonsDir, packageName);
4685
4813
  if (!node_fs.existsSync(addonDir)) throw new Error(`Cannot update ${packageName}: install dir ${addonDir} missing`);
4814
+ await this.installRuntimeDependencies(stagedPath, packageName);
4686
4815
  const ts = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
4687
4816
  const backupRoot = node_path.join(this.addonsDir, ".backups", packageName);
4688
4817
  ensureDir(backupRoot);