@camstack/addon-provider-reolink 1.2.58 → 1.2.60

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/addon.js CHANGED
@@ -5943,6 +5943,40 @@ var BaseAddon = class {
5943
5943
  deviceSettingsSchema() {
5944
5944
  return null;
5945
5945
  }
5946
+ /**
5947
+ * INTEGRATION-LEVEL SETTINGS — declare which of this addon's global sections
5948
+ * ARE the configuration of its integration.
5949
+ *
5950
+ * Return the `ConfigSection.id`s, from {@link globalSettingsSchema}, that an
5951
+ * operator should find on the addon's integration page (System →
5952
+ * Integrations → <name>) rather than only in the cluster-wide list of every
5953
+ * addon. Empty (the default) means the addon has no integration-level
5954
+ * settings and no such surface is offered — this is opt-in, because whether
5955
+ * an addon's configuration IS its integration's configuration depends on the
5956
+ * nature of the integration.
5957
+ *
5958
+ * WHAT THIS IS NOT. It is not a scope. The selected sections keep living in
5959
+ * the ONE global schema, in the ONE addon store, written by the ONE
5960
+ * `updateGlobalSettings` path. There is deliberately no
5961
+ * `updateIntegrationSettings`: a second write path is how a surface acquires
5962
+ * a second store key, and this repo has shipped that twice (`btmPath@hub`,
5963
+ * D266). Selecting sections cannot introduce a key that selecting cannot.
5964
+ *
5965
+ * WHY IT IS A LIST OF SECTION IDS AND NOT A MARKER ON THE SECTION.
5966
+ * `ConfigFieldBase` used to carry `scope?: 'device' | 'global'` and it was
5967
+ * removed with the reason recorded at
5968
+ * `packages/types/src/interfaces/config-ui.ts:249` — *"a field's scope is
5969
+ * determined by WHICH schema it lives in, not by a field-level marker."* A
5970
+ * marker sprinkled across sections also has to borrow a field that already
5971
+ * means something else; borrowing `section.tab` put the literal word
5972
+ * "integration" into an operator-facing tab bar, because `tab` means "how to
5973
+ * GROUP this visually" and cannot also mean "where this lives" (D269
5974
+ * supersedes D268). One declaration, in one place, next to the schema whose
5975
+ * ids it names.
5976
+ */
5977
+ integrationSettingSections() {
5978
+ return [];
5979
+ }
5946
5980
  async getGlobalSettings(overlay, cap, nodeId) {
5947
5981
  const schema = this.globalSettingsSchema(cap);
5948
5982
  if (!schema) return { sections: [] };
@@ -5953,6 +5987,55 @@ var BaseAddon = class {
5953
5987
  } : projected);
5954
5988
  }
5955
5989
  /**
5990
+ * The integration-level view of this addon's settings: exactly the sections
5991
+ * named by {@link integrationSettingSections}, hydrated from the SAME store
5992
+ * `getGlobalSettings` reads, and narrowed to cluster-scoped fields.
5993
+ *
5994
+ * Returns `null` when the addon declared nothing — an addon that opts out has
5995
+ * no integration settings surface at all, rather than an empty one that reads
5996
+ * as a failed load.
5997
+ *
5998
+ * Three properties hold BY CONSTRUCTION, which is why they are here in core
5999
+ * and not in whichever UI happens to render this:
6000
+ *
6001
+ * 1. **One key.** The payload is a SUBSET of the global schema, so a field
6002
+ * shown here is the same field, with the same bare key, that the addon's
6003
+ * own page shows. There is no integration-specific writer — callers save
6004
+ * through `updateGlobalSettings` — so a second store key is unreachable,
6005
+ * not merely discouraged.
6006
+ * 2. **No node scope.** `perNode: true` fields are DROPPED. Their store key
6007
+ * is `<key>@<nodeId>` and an integration is not a node; whichever node
6008
+ * such a field silently picked would be a wrong answer for the operator
6009
+ * who opened the page (D266).
6010
+ * 3. **No silent typo.** A declared id that names no section throws. The
6011
+ * alternative — skip it — turns a rename into a surface that quietly
6012
+ * empties, which looks exactly like an addon with nothing to configure.
6013
+ */
6014
+ async getIntegrationSettings(nodeId) {
6015
+ const declared = this.integrationSettingSections();
6016
+ if (declared.length === 0) return null;
6017
+ const schema = this.globalSettingsSchema();
6018
+ if (!schema) throw new Error(`${this.constructor.name}: integrationSettingSections() names [${declared.join(", ")}] but globalSettingsSchema() returns null.`);
6019
+ const byId = new Map(schema.sections.map((section) => [section.id, section]));
6020
+ const sections = [];
6021
+ for (const id of declared) {
6022
+ const section = byId.get(id);
6023
+ if (!section) throw new Error(`${this.constructor.name}: integrationSettingSections() names unknown section "${id}". Known sections: [${[...byId.keys()].join(", ")}].`);
6024
+ const fields = dropPerNodeFields(section.fields);
6025
+ if (fields.length === 0) continue;
6026
+ sections.push({
6027
+ ...section,
6028
+ fields
6029
+ });
6030
+ }
6031
+ if (sections.length === 0) return null;
6032
+ const projected = await this.resolveGlobalStore(nodeId);
6033
+ return hydrateSchema({
6034
+ ...schema,
6035
+ sections
6036
+ }, projected);
6037
+ }
6038
+ /**
5956
6039
  * The raw addon store PROJECTED onto the target node's bare per-node keys:
5957
6040
  * every `perNode: true` field carries THAT node's scoped value on its bare
5958
6041
  * key (absent scoped key ⇒ key absent, so the schema `default` wins — no
@@ -6256,6 +6339,41 @@ var BaseAddon = class {
6256
6339
  * `hydrateSchema` does. Valueless structural fields (separator/info/…)
6257
6340
  * don't declare `perNode` and are excluded by the `in` narrowing.
6258
6341
  */
6342
+ /**
6343
+ * The same fields with every `perNode: true` one removed, recursing into layout
6344
+ * containers exactly as {@link collectPerNodeFieldKeys} does. A container left
6345
+ * with no child is dropped rather than rendered empty.
6346
+ *
6347
+ * Used by `getIntegrationSettings`: an integration is not a node, so a field
6348
+ * whose store key is `<key>@<nodeId>` has no node to belong to there.
6349
+ */
6350
+ function dropPerNodeFields(fields) {
6351
+ const kept = [];
6352
+ for (const field of fields) {
6353
+ if (field.type === "group") {
6354
+ const inner = dropPerNodeFields(field.fields);
6355
+ if (inner.length > 0) kept.push({
6356
+ ...field,
6357
+ fields: inner
6358
+ });
6359
+ continue;
6360
+ }
6361
+ if (field.type === "sub-tabs") {
6362
+ const tabs = field.tabs.map((tab) => ({
6363
+ ...tab,
6364
+ fields: dropPerNodeFields(tab.fields)
6365
+ })).filter((tab) => tab.fields.length > 0);
6366
+ if (tabs.length > 0) kept.push({
6367
+ ...field,
6368
+ tabs
6369
+ });
6370
+ continue;
6371
+ }
6372
+ if ("perNode" in field && field.perNode === true) continue;
6373
+ kept.push(field);
6374
+ }
6375
+ return kept;
6376
+ }
6259
6377
  function collectPerNodeFieldKeys(fields) {
6260
6378
  const collected = [];
6261
6379
  for (const field of fields) {
@@ -9863,6 +9981,9 @@ method(object({
9863
9981
  kind: "mutation",
9864
9982
  auth: "admin"
9865
9983
  }), method(object({
9984
+ addonId: string(),
9985
+ nodeId: string().optional()
9986
+ }), SettingsSchemaWithValuesSchema.nullable()), method(object({
9866
9987
  addonId: string(),
9867
9988
  deviceId: number(),
9868
9989
  nodeId: string().optional()
@@ -32545,6 +32666,12 @@ Object.freeze({
32545
32666
  addonId: null,
32546
32667
  access: "view"
32547
32668
  },
32669
+ "addonSettings.getIntegrationSettings": {
32670
+ capName: "addon-settings",
32671
+ capScope: "system",
32672
+ addonId: null,
32673
+ access: "view"
32674
+ },
32548
32675
  "addonSettings.updateDeviceSettings": {
32549
32676
  capName: "addon-settings",
32550
32677
  capScope: "system",
@@ -236221,10 +236348,12 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
236221
236348
  * descriptors served by the `stream-catalog` cap (broker PULLS via
236222
236349
  * `registerStreamCatalogProvider`).
236223
236350
  *
236224
- * Returns `[]` (logging at debug, matching the prior early-returns) on
236225
- * the battery-sleep gate, `ensureApi` failure, or
236226
- * `buildVideoStreamOptions` failure the broker simply sees no
236227
- * descriptors for the device until the next reconcile.
236351
+ * Returns `[]` only when there is genuinely nothing to say: the
236352
+ * battery-sleep gate (logged at debug), or a camera that connected and
236353
+ * reported zero streams. An `ensureApi` / `buildVideoStreamOptions` failure
236354
+ * THROWS `[]` and an error are not the same fact, and the broker needs
236355
+ * the difference to keep the device's existing entry and to schedule its
236356
+ * per-device backoff instead of treating the camera as stream-less.
236228
236357
  *
236229
236358
  * This method only BUILDS descriptors — it never opens an upstream
236230
236359
  * session or touches the broker.
@@ -236352,10 +236481,22 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
236352
236481
  channel: ownChannel,
236353
236482
  onNvr: true
236354
236483
  } : void 0;
236484
+ const readStreamOptions = async (current) => withTimeout(buildOptions ? current.buildVideoStreamOptions(buildOptions) : current.buildVideoStreamOptions(), 1e4, "buildVideoStreamOptions");
236355
236485
  try {
236356
- streamOptions = await withTimeout(buildOptions ? api.buildVideoStreamOptions(buildOptions) : api.buildVideoStreamOptions(), 1e4, "buildVideoStreamOptions");
236486
+ streamOptions = await readStreamOptions(api);
236357
236487
  } catch (err) {
236358
- throw new Error(`buildStreamCatalog: buildVideoStreamOptions failed for device ${this.id}: ${err instanceof Error ? err.message : String(err)}`, { cause: err });
236488
+ if (isChild) throw new Error(`buildStreamCatalog: buildVideoStreamOptions failed for device ${this.id}: ${err instanceof Error ? err.message : String(err)}`, { cause: err });
236489
+ this.ctx.logger.warn("buildStreamCatalog: stream options read failed — dropping the Baichuan session and retrying once", {
236490
+ tags: { deviceId: this.id },
236491
+ meta: { error: err instanceof Error ? err.message : String(err) }
236492
+ });
236493
+ await this.dropBaichuanSession("stream-catalog-retry");
236494
+ try {
236495
+ streamOptions = await readStreamOptions(await withTimeout(this.ensureApi(), 1e4, "ensureApi"));
236496
+ } catch (retryErr) {
236497
+ throw new Error(`buildStreamCatalog: buildVideoStreamOptions failed for device ${this.id} (after one re-auth retry): ${retryErr instanceof Error ? retryErr.message : String(retryErr)}`, { cause: retryErr });
236498
+ }
236499
+ this.ctx.logger.info("buildStreamCatalog: stream options read recovered after re-auth", { tags: { deviceId: this.id } });
236359
236500
  }
236360
236501
  const channelCount = this.channelCount();
236361
236502
  const desired = /* @__PURE__ */ new Map();
@@ -239237,6 +239378,30 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
239237
239378
  * `awake` push (or a snapshot demand from the operator) will
239238
239379
  * lazily call `ensureApi()` and re-establish the client.
239239
239380
  */
239381
+ /**
239382
+ * Close and forget the cached control-channel client so the NEXT
239383
+ * `ensureApi()` performs a fresh login.
239384
+ *
239385
+ * The one thing `scheduleReconnect` cannot express: an EXPIRED session on a
239386
+ * socket that is still open. No `close`/`error` ever fires, so the reconnect
239387
+ * ladder is never armed, and `ensureApi`'s `if (this.api) return this.api`
239388
+ * keeps handing back a client whose every request answers `responseCode
239389
+ * 400`. Callers that see an application-level rejection they believe is a
239390
+ * dead session call this and retry ONCE — they must never loop on it.
239391
+ *
239392
+ * Same teardown the `disconnectAll` / debug-options paths use: `close()`
239393
+ * best-effort, then null the field. Active RFC 4571 servers are untouched —
239394
+ * each owns a dedicated socket and survives a control-channel reset (see
239395
+ * `scheduleReconnect`).
239396
+ */
239397
+ async dropBaichuanSession(reason) {
239398
+ const current = this.api;
239399
+ this.api = null;
239400
+ if (!current) return;
239401
+ try {
239402
+ await current.close({ reason });
239403
+ } catch {}
239404
+ }
239240
239405
  scheduleReconnect(reason) {
239241
239406
  if (this.reconnectTimer) return;
239242
239407
  if (this.isBattery) {
@@ -240861,6 +241026,12 @@ var ReolinkEmailPushServer = class {
240861
241026
  //#endregion
240862
241027
  //#region src/email-push-schema.ts
240863
241028
  /**
241029
+ * The ids of the sections above, in render order — the value the addon hands
241030
+ * to `BaseAddon.integrationSettingSections()`. Exported so the declaration and
241031
+ * the schema cannot drift: core throws if an id here names no section.
241032
+ */
241033
+ var EMAIL_PUSH_SECTION_IDS = ["email-push", "email-push-auth"];
241034
+ /**
240864
241035
  * Addon-level settings UI for the Reolink email/SMTP push intake.
240865
241036
  *
240866
241037
  * Rendered under the provider's addon settings (Cluster → addon config).
@@ -240872,6 +241043,28 @@ var ReolinkEmailPushServer = class {
240872
241043
  * `requiresRestart` is intentionally NOT set — the provider handles the
240873
241044
  * restart itself in `onConfigChanged` (a targeted SMTP rebind, not a full
240874
241045
  * addon teardown).
241046
+ *
241047
+ * ── These sections ARE the Reolink integration's configuration ──────────
241048
+ *
241049
+ * Both are declared in `ReolinkAddon.integrationSettingSections()`, so core
241050
+ * serves them on System → Integrations → Reolink. The operator looks for "the
241051
+ * Reolink SMTP port" under Reolink; this puts it there.
241052
+ *
241053
+ * They EARN that placement, and the reason is the test any future declaration
241054
+ * must pass: they configure ONE SMTP server in ONE provider process, serving
241055
+ * every Reolink camera at once. There is no per-camera copy to confuse them
241056
+ * with, which is exactly why a per-camera home would be nonsense and a
241057
+ * per-integration home is correct. A setting that differs per camera belongs
241058
+ * in `deviceSettingsSchema`, never here.
241059
+ *
241060
+ * The declaration does not move the values: they remain the same bare keys in
241061
+ * the same addon store, still reachable from System → Settings, still written
241062
+ * by `updateGlobalSettings` — there is no integration-specific writer at all.
241063
+ * See ADR-0269.
241064
+ *
241065
+ * `tab` is deliberately NOT used to express this. It means "how to group this
241066
+ * visually", and an earlier design that overloaded it put the literal word
241067
+ * "integration" into an operator-facing tab bar (D268 → D269).
240875
241068
  */
240876
241069
  function buildEmailPushSettingsSchema(recommendedHost) {
240877
241070
  return { sections: [{
@@ -241240,9 +241433,30 @@ var ReolinkProviderAddon = class extends BaseDeviceProvider {
241240
241433
  this.ctx.logger.warn("email-push: restart after settings change failed", { meta: { error: err instanceof Error ? err.message : String(err) } });
241241
241434
  });
241242
241435
  }
241243
- async getGlobalSettings() {
241244
- const raw = await this.resolveGlobalStore();
241245
- return hydrateSchema(buildEmailPushSettingsSchema(listLanHosts()[0] ?? "127.0.0.1"), raw);
241436
+ /**
241437
+ * The addon's global settings schema.
241438
+ *
241439
+ * This used to override `getGlobalSettings()` wholesale, on the belief that a
241440
+ * dynamic `recommendedHost` could not come from a static schema declaration.
241441
+ * It can: `listLanHosts()` is synchronous, so the schema builder runs here
241442
+ * and `BaseAddon.getGlobalSettings` does the identical
241443
+ * `resolveGlobalStore` + `hydrateSchema` the override did by hand.
241444
+ *
241445
+ * Declaring the SCHEMA rather than overriding the GETTER is what lets core
241446
+ * serve `getIntegrationSettings()` — it selects the declared sections out of
241447
+ * this schema, so an addon that hides its schema behind a getter has nothing
241448
+ * for core to select from.
241449
+ */
241450
+ globalSettingsSchema() {
241451
+ return buildEmailPushSettingsSchema(listLanHosts()[0] ?? "127.0.0.1");
241452
+ }
241453
+ /**
241454
+ * Both email-push sections ARE this integration's configuration — one SMTP
241455
+ * server serving every Reolink camera. See `email-push-schema.ts` for why
241456
+ * that earns a per-integration home and not a per-camera one.
241457
+ */
241458
+ integrationSettingSections() {
241459
+ return EMAIL_PUSH_SECTION_IDS;
241246
241460
  }
241247
241461
  async onInitialize() {
241248
241462
  const regs = await super.onInitialize();
package/dist/addon.mjs CHANGED
@@ -5938,6 +5938,40 @@ var BaseAddon = class {
5938
5938
  deviceSettingsSchema() {
5939
5939
  return null;
5940
5940
  }
5941
+ /**
5942
+ * INTEGRATION-LEVEL SETTINGS — declare which of this addon's global sections
5943
+ * ARE the configuration of its integration.
5944
+ *
5945
+ * Return the `ConfigSection.id`s, from {@link globalSettingsSchema}, that an
5946
+ * operator should find on the addon's integration page (System →
5947
+ * Integrations → <name>) rather than only in the cluster-wide list of every
5948
+ * addon. Empty (the default) means the addon has no integration-level
5949
+ * settings and no such surface is offered — this is opt-in, because whether
5950
+ * an addon's configuration IS its integration's configuration depends on the
5951
+ * nature of the integration.
5952
+ *
5953
+ * WHAT THIS IS NOT. It is not a scope. The selected sections keep living in
5954
+ * the ONE global schema, in the ONE addon store, written by the ONE
5955
+ * `updateGlobalSettings` path. There is deliberately no
5956
+ * `updateIntegrationSettings`: a second write path is how a surface acquires
5957
+ * a second store key, and this repo has shipped that twice (`btmPath@hub`,
5958
+ * D266). Selecting sections cannot introduce a key that selecting cannot.
5959
+ *
5960
+ * WHY IT IS A LIST OF SECTION IDS AND NOT A MARKER ON THE SECTION.
5961
+ * `ConfigFieldBase` used to carry `scope?: 'device' | 'global'` and it was
5962
+ * removed with the reason recorded at
5963
+ * `packages/types/src/interfaces/config-ui.ts:249` — *"a field's scope is
5964
+ * determined by WHICH schema it lives in, not by a field-level marker."* A
5965
+ * marker sprinkled across sections also has to borrow a field that already
5966
+ * means something else; borrowing `section.tab` put the literal word
5967
+ * "integration" into an operator-facing tab bar, because `tab` means "how to
5968
+ * GROUP this visually" and cannot also mean "where this lives" (D269
5969
+ * supersedes D268). One declaration, in one place, next to the schema whose
5970
+ * ids it names.
5971
+ */
5972
+ integrationSettingSections() {
5973
+ return [];
5974
+ }
5941
5975
  async getGlobalSettings(overlay, cap, nodeId) {
5942
5976
  const schema = this.globalSettingsSchema(cap);
5943
5977
  if (!schema) return { sections: [] };
@@ -5948,6 +5982,55 @@ var BaseAddon = class {
5948
5982
  } : projected);
5949
5983
  }
5950
5984
  /**
5985
+ * The integration-level view of this addon's settings: exactly the sections
5986
+ * named by {@link integrationSettingSections}, hydrated from the SAME store
5987
+ * `getGlobalSettings` reads, and narrowed to cluster-scoped fields.
5988
+ *
5989
+ * Returns `null` when the addon declared nothing — an addon that opts out has
5990
+ * no integration settings surface at all, rather than an empty one that reads
5991
+ * as a failed load.
5992
+ *
5993
+ * Three properties hold BY CONSTRUCTION, which is why they are here in core
5994
+ * and not in whichever UI happens to render this:
5995
+ *
5996
+ * 1. **One key.** The payload is a SUBSET of the global schema, so a field
5997
+ * shown here is the same field, with the same bare key, that the addon's
5998
+ * own page shows. There is no integration-specific writer — callers save
5999
+ * through `updateGlobalSettings` — so a second store key is unreachable,
6000
+ * not merely discouraged.
6001
+ * 2. **No node scope.** `perNode: true` fields are DROPPED. Their store key
6002
+ * is `<key>@<nodeId>` and an integration is not a node; whichever node
6003
+ * such a field silently picked would be a wrong answer for the operator
6004
+ * who opened the page (D266).
6005
+ * 3. **No silent typo.** A declared id that names no section throws. The
6006
+ * alternative — skip it — turns a rename into a surface that quietly
6007
+ * empties, which looks exactly like an addon with nothing to configure.
6008
+ */
6009
+ async getIntegrationSettings(nodeId) {
6010
+ const declared = this.integrationSettingSections();
6011
+ if (declared.length === 0) return null;
6012
+ const schema = this.globalSettingsSchema();
6013
+ if (!schema) throw new Error(`${this.constructor.name}: integrationSettingSections() names [${declared.join(", ")}] but globalSettingsSchema() returns null.`);
6014
+ const byId = new Map(schema.sections.map((section) => [section.id, section]));
6015
+ const sections = [];
6016
+ for (const id of declared) {
6017
+ const section = byId.get(id);
6018
+ if (!section) throw new Error(`${this.constructor.name}: integrationSettingSections() names unknown section "${id}". Known sections: [${[...byId.keys()].join(", ")}].`);
6019
+ const fields = dropPerNodeFields(section.fields);
6020
+ if (fields.length === 0) continue;
6021
+ sections.push({
6022
+ ...section,
6023
+ fields
6024
+ });
6025
+ }
6026
+ if (sections.length === 0) return null;
6027
+ const projected = await this.resolveGlobalStore(nodeId);
6028
+ return hydrateSchema({
6029
+ ...schema,
6030
+ sections
6031
+ }, projected);
6032
+ }
6033
+ /**
5951
6034
  * The raw addon store PROJECTED onto the target node's bare per-node keys:
5952
6035
  * every `perNode: true` field carries THAT node's scoped value on its bare
5953
6036
  * key (absent scoped key ⇒ key absent, so the schema `default` wins — no
@@ -6251,6 +6334,41 @@ var BaseAddon = class {
6251
6334
  * `hydrateSchema` does. Valueless structural fields (separator/info/…)
6252
6335
  * don't declare `perNode` and are excluded by the `in` narrowing.
6253
6336
  */
6337
+ /**
6338
+ * The same fields with every `perNode: true` one removed, recursing into layout
6339
+ * containers exactly as {@link collectPerNodeFieldKeys} does. A container left
6340
+ * with no child is dropped rather than rendered empty.
6341
+ *
6342
+ * Used by `getIntegrationSettings`: an integration is not a node, so a field
6343
+ * whose store key is `<key>@<nodeId>` has no node to belong to there.
6344
+ */
6345
+ function dropPerNodeFields(fields) {
6346
+ const kept = [];
6347
+ for (const field of fields) {
6348
+ if (field.type === "group") {
6349
+ const inner = dropPerNodeFields(field.fields);
6350
+ if (inner.length > 0) kept.push({
6351
+ ...field,
6352
+ fields: inner
6353
+ });
6354
+ continue;
6355
+ }
6356
+ if (field.type === "sub-tabs") {
6357
+ const tabs = field.tabs.map((tab) => ({
6358
+ ...tab,
6359
+ fields: dropPerNodeFields(tab.fields)
6360
+ })).filter((tab) => tab.fields.length > 0);
6361
+ if (tabs.length > 0) kept.push({
6362
+ ...field,
6363
+ tabs
6364
+ });
6365
+ continue;
6366
+ }
6367
+ if ("perNode" in field && field.perNode === true) continue;
6368
+ kept.push(field);
6369
+ }
6370
+ return kept;
6371
+ }
6254
6372
  function collectPerNodeFieldKeys(fields) {
6255
6373
  const collected = [];
6256
6374
  for (const field of fields) {
@@ -9858,6 +9976,9 @@ method(object({
9858
9976
  kind: "mutation",
9859
9977
  auth: "admin"
9860
9978
  }), method(object({
9979
+ addonId: string(),
9980
+ nodeId: string().optional()
9981
+ }), SettingsSchemaWithValuesSchema.nullable()), method(object({
9861
9982
  addonId: string(),
9862
9983
  deviceId: number(),
9863
9984
  nodeId: string().optional()
@@ -32540,6 +32661,12 @@ Object.freeze({
32540
32661
  addonId: null,
32541
32662
  access: "view"
32542
32663
  },
32664
+ "addonSettings.getIntegrationSettings": {
32665
+ capName: "addon-settings",
32666
+ capScope: "system",
32667
+ addonId: null,
32668
+ access: "view"
32669
+ },
32543
32670
  "addonSettings.updateDeviceSettings": {
32544
32671
  capName: "addon-settings",
32545
32672
  capScope: "system",
@@ -236201,10 +236328,12 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
236201
236328
  * descriptors served by the `stream-catalog` cap (broker PULLS via
236202
236329
  * `registerStreamCatalogProvider`).
236203
236330
  *
236204
- * Returns `[]` (logging at debug, matching the prior early-returns) on
236205
- * the battery-sleep gate, `ensureApi` failure, or
236206
- * `buildVideoStreamOptions` failure the broker simply sees no
236207
- * descriptors for the device until the next reconcile.
236331
+ * Returns `[]` only when there is genuinely nothing to say: the
236332
+ * battery-sleep gate (logged at debug), or a camera that connected and
236333
+ * reported zero streams. An `ensureApi` / `buildVideoStreamOptions` failure
236334
+ * THROWS `[]` and an error are not the same fact, and the broker needs
236335
+ * the difference to keep the device's existing entry and to schedule its
236336
+ * per-device backoff instead of treating the camera as stream-less.
236208
236337
  *
236209
236338
  * This method only BUILDS descriptors — it never opens an upstream
236210
236339
  * session or touches the broker.
@@ -236332,10 +236461,22 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
236332
236461
  channel: ownChannel,
236333
236462
  onNvr: true
236334
236463
  } : void 0;
236464
+ const readStreamOptions = async (current) => withTimeout(buildOptions ? current.buildVideoStreamOptions(buildOptions) : current.buildVideoStreamOptions(), 1e4, "buildVideoStreamOptions");
236335
236465
  try {
236336
- streamOptions = await withTimeout(buildOptions ? api.buildVideoStreamOptions(buildOptions) : api.buildVideoStreamOptions(), 1e4, "buildVideoStreamOptions");
236466
+ streamOptions = await readStreamOptions(api);
236337
236467
  } catch (err) {
236338
- throw new Error(`buildStreamCatalog: buildVideoStreamOptions failed for device ${this.id}: ${err instanceof Error ? err.message : String(err)}`, { cause: err });
236468
+ if (isChild) throw new Error(`buildStreamCatalog: buildVideoStreamOptions failed for device ${this.id}: ${err instanceof Error ? err.message : String(err)}`, { cause: err });
236469
+ this.ctx.logger.warn("buildStreamCatalog: stream options read failed — dropping the Baichuan session and retrying once", {
236470
+ tags: { deviceId: this.id },
236471
+ meta: { error: err instanceof Error ? err.message : String(err) }
236472
+ });
236473
+ await this.dropBaichuanSession("stream-catalog-retry");
236474
+ try {
236475
+ streamOptions = await readStreamOptions(await withTimeout(this.ensureApi(), 1e4, "ensureApi"));
236476
+ } catch (retryErr) {
236477
+ throw new Error(`buildStreamCatalog: buildVideoStreamOptions failed for device ${this.id} (after one re-auth retry): ${retryErr instanceof Error ? retryErr.message : String(retryErr)}`, { cause: retryErr });
236478
+ }
236479
+ this.ctx.logger.info("buildStreamCatalog: stream options read recovered after re-auth", { tags: { deviceId: this.id } });
236339
236480
  }
236340
236481
  const channelCount = this.channelCount();
236341
236482
  const desired = /* @__PURE__ */ new Map();
@@ -239217,6 +239358,30 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
239217
239358
  * `awake` push (or a snapshot demand from the operator) will
239218
239359
  * lazily call `ensureApi()` and re-establish the client.
239219
239360
  */
239361
+ /**
239362
+ * Close and forget the cached control-channel client so the NEXT
239363
+ * `ensureApi()` performs a fresh login.
239364
+ *
239365
+ * The one thing `scheduleReconnect` cannot express: an EXPIRED session on a
239366
+ * socket that is still open. No `close`/`error` ever fires, so the reconnect
239367
+ * ladder is never armed, and `ensureApi`'s `if (this.api) return this.api`
239368
+ * keeps handing back a client whose every request answers `responseCode
239369
+ * 400`. Callers that see an application-level rejection they believe is a
239370
+ * dead session call this and retry ONCE — they must never loop on it.
239371
+ *
239372
+ * Same teardown the `disconnectAll` / debug-options paths use: `close()`
239373
+ * best-effort, then null the field. Active RFC 4571 servers are untouched —
239374
+ * each owns a dedicated socket and survives a control-channel reset (see
239375
+ * `scheduleReconnect`).
239376
+ */
239377
+ async dropBaichuanSession(reason) {
239378
+ const current = this.api;
239379
+ this.api = null;
239380
+ if (!current) return;
239381
+ try {
239382
+ await current.close({ reason });
239383
+ } catch {}
239384
+ }
239220
239385
  scheduleReconnect(reason) {
239221
239386
  if (this.reconnectTimer) return;
239222
239387
  if (this.isBattery) {
@@ -240841,6 +241006,12 @@ var ReolinkEmailPushServer = class {
240841
241006
  //#endregion
240842
241007
  //#region src/email-push-schema.ts
240843
241008
  /**
241009
+ * The ids of the sections above, in render order — the value the addon hands
241010
+ * to `BaseAddon.integrationSettingSections()`. Exported so the declaration and
241011
+ * the schema cannot drift: core throws if an id here names no section.
241012
+ */
241013
+ var EMAIL_PUSH_SECTION_IDS = ["email-push", "email-push-auth"];
241014
+ /**
240844
241015
  * Addon-level settings UI for the Reolink email/SMTP push intake.
240845
241016
  *
240846
241017
  * Rendered under the provider's addon settings (Cluster → addon config).
@@ -240852,6 +241023,28 @@ var ReolinkEmailPushServer = class {
240852
241023
  * `requiresRestart` is intentionally NOT set — the provider handles the
240853
241024
  * restart itself in `onConfigChanged` (a targeted SMTP rebind, not a full
240854
241025
  * addon teardown).
241026
+ *
241027
+ * ── These sections ARE the Reolink integration's configuration ──────────
241028
+ *
241029
+ * Both are declared in `ReolinkAddon.integrationSettingSections()`, so core
241030
+ * serves them on System → Integrations → Reolink. The operator looks for "the
241031
+ * Reolink SMTP port" under Reolink; this puts it there.
241032
+ *
241033
+ * They EARN that placement, and the reason is the test any future declaration
241034
+ * must pass: they configure ONE SMTP server in ONE provider process, serving
241035
+ * every Reolink camera at once. There is no per-camera copy to confuse them
241036
+ * with, which is exactly why a per-camera home would be nonsense and a
241037
+ * per-integration home is correct. A setting that differs per camera belongs
241038
+ * in `deviceSettingsSchema`, never here.
241039
+ *
241040
+ * The declaration does not move the values: they remain the same bare keys in
241041
+ * the same addon store, still reachable from System → Settings, still written
241042
+ * by `updateGlobalSettings` — there is no integration-specific writer at all.
241043
+ * See ADR-0269.
241044
+ *
241045
+ * `tab` is deliberately NOT used to express this. It means "how to group this
241046
+ * visually", and an earlier design that overloaded it put the literal word
241047
+ * "integration" into an operator-facing tab bar (D268 → D269).
240855
241048
  */
240856
241049
  function buildEmailPushSettingsSchema(recommendedHost) {
240857
241050
  return { sections: [{
@@ -241220,9 +241413,30 @@ var ReolinkProviderAddon = class extends BaseDeviceProvider {
241220
241413
  this.ctx.logger.warn("email-push: restart after settings change failed", { meta: { error: err instanceof Error ? err.message : String(err) } });
241221
241414
  });
241222
241415
  }
241223
- async getGlobalSettings() {
241224
- const raw = await this.resolveGlobalStore();
241225
- return hydrateSchema(buildEmailPushSettingsSchema(listLanHosts()[0] ?? "127.0.0.1"), raw);
241416
+ /**
241417
+ * The addon's global settings schema.
241418
+ *
241419
+ * This used to override `getGlobalSettings()` wholesale, on the belief that a
241420
+ * dynamic `recommendedHost` could not come from a static schema declaration.
241421
+ * It can: `listLanHosts()` is synchronous, so the schema builder runs here
241422
+ * and `BaseAddon.getGlobalSettings` does the identical
241423
+ * `resolveGlobalStore` + `hydrateSchema` the override did by hand.
241424
+ *
241425
+ * Declaring the SCHEMA rather than overriding the GETTER is what lets core
241426
+ * serve `getIntegrationSettings()` — it selects the declared sections out of
241427
+ * this schema, so an addon that hides its schema behind a getter has nothing
241428
+ * for core to select from.
241429
+ */
241430
+ globalSettingsSchema() {
241431
+ return buildEmailPushSettingsSchema(listLanHosts()[0] ?? "127.0.0.1");
241432
+ }
241433
+ /**
241434
+ * Both email-push sections ARE this integration's configuration — one SMTP
241435
+ * server serving every Reolink camera. See `email-push-schema.ts` for why
241436
+ * that earns a per-integration home and not a per-camera one.
241437
+ */
241438
+ integrationSettingSections() {
241439
+ return EMAIL_PUSH_SECTION_IDS;
241226
241440
  }
241227
241441
  async onInitialize() {
241228
241442
  const regs = await super.onInitialize();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/addon-provider-reolink",
3
- "version": "1.2.58",
3
+ "version": "1.2.60",
4
4
  "description": "Reolink camera device provider addon for CamStack — native Baichuan protocol",
5
5
  "keywords": [
6
6
  "camstack",
@@ -44,7 +44,8 @@
44
44
  "mode": "standalone",
45
45
  "execution": {
46
46
  "placement": "hub-only",
47
- "heapProfile": "heavy"
47
+ "heapProfile": "heavy",
48
+ "rssBudgetMb": 1024
48
49
  },
49
50
  "capabilities": [
50
51
  {