@camstack/addon-mqtt-broker 1.2.37 → 1.2.38

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.
@@ -5961,6 +5961,40 @@ var BaseAddon = class {
5961
5961
  deviceSettingsSchema() {
5962
5962
  return null;
5963
5963
  }
5964
+ /**
5965
+ * INTEGRATION-LEVEL SETTINGS — declare which of this addon's global sections
5966
+ * ARE the configuration of its integration.
5967
+ *
5968
+ * Return the `ConfigSection.id`s, from {@link globalSettingsSchema}, that an
5969
+ * operator should find on the addon's integration page (System →
5970
+ * Integrations → <name>) rather than only in the cluster-wide list of every
5971
+ * addon. Empty (the default) means the addon has no integration-level
5972
+ * settings and no such surface is offered — this is opt-in, because whether
5973
+ * an addon's configuration IS its integration's configuration depends on the
5974
+ * nature of the integration.
5975
+ *
5976
+ * WHAT THIS IS NOT. It is not a scope. The selected sections keep living in
5977
+ * the ONE global schema, in the ONE addon store, written by the ONE
5978
+ * `updateGlobalSettings` path. There is deliberately no
5979
+ * `updateIntegrationSettings`: a second write path is how a surface acquires
5980
+ * a second store key, and this repo has shipped that twice (`btmPath@hub`,
5981
+ * D266). Selecting sections cannot introduce a key that selecting cannot.
5982
+ *
5983
+ * WHY IT IS A LIST OF SECTION IDS AND NOT A MARKER ON THE SECTION.
5984
+ * `ConfigFieldBase` used to carry `scope?: 'device' | 'global'` and it was
5985
+ * removed with the reason recorded at
5986
+ * `packages/types/src/interfaces/config-ui.ts:249` — *"a field's scope is
5987
+ * determined by WHICH schema it lives in, not by a field-level marker."* A
5988
+ * marker sprinkled across sections also has to borrow a field that already
5989
+ * means something else; borrowing `section.tab` put the literal word
5990
+ * "integration" into an operator-facing tab bar, because `tab` means "how to
5991
+ * GROUP this visually" and cannot also mean "where this lives" (D269
5992
+ * supersedes D268). One declaration, in one place, next to the schema whose
5993
+ * ids it names.
5994
+ */
5995
+ integrationSettingSections() {
5996
+ return [];
5997
+ }
5964
5998
  async getGlobalSettings(overlay, cap, nodeId) {
5965
5999
  const schema = this.globalSettingsSchema(cap);
5966
6000
  if (!schema) return { sections: [] };
@@ -5971,6 +6005,55 @@ var BaseAddon = class {
5971
6005
  } : projected);
5972
6006
  }
5973
6007
  /**
6008
+ * The integration-level view of this addon's settings: exactly the sections
6009
+ * named by {@link integrationSettingSections}, hydrated from the SAME store
6010
+ * `getGlobalSettings` reads, and narrowed to cluster-scoped fields.
6011
+ *
6012
+ * Returns `null` when the addon declared nothing — an addon that opts out has
6013
+ * no integration settings surface at all, rather than an empty one that reads
6014
+ * as a failed load.
6015
+ *
6016
+ * Three properties hold BY CONSTRUCTION, which is why they are here in core
6017
+ * and not in whichever UI happens to render this:
6018
+ *
6019
+ * 1. **One key.** The payload is a SUBSET of the global schema, so a field
6020
+ * shown here is the same field, with the same bare key, that the addon's
6021
+ * own page shows. There is no integration-specific writer — callers save
6022
+ * through `updateGlobalSettings` — so a second store key is unreachable,
6023
+ * not merely discouraged.
6024
+ * 2. **No node scope.** `perNode: true` fields are DROPPED. Their store key
6025
+ * is `<key>@<nodeId>` and an integration is not a node; whichever node
6026
+ * such a field silently picked would be a wrong answer for the operator
6027
+ * who opened the page (D266).
6028
+ * 3. **No silent typo.** A declared id that names no section throws. The
6029
+ * alternative — skip it — turns a rename into a surface that quietly
6030
+ * empties, which looks exactly like an addon with nothing to configure.
6031
+ */
6032
+ async getIntegrationSettings(nodeId) {
6033
+ const declared = this.integrationSettingSections();
6034
+ if (declared.length === 0) return null;
6035
+ const schema = this.globalSettingsSchema();
6036
+ if (!schema) throw new Error(`${this.constructor.name}: integrationSettingSections() names [${declared.join(", ")}] but globalSettingsSchema() returns null.`);
6037
+ const byId = new Map(schema.sections.map((section) => [section.id, section]));
6038
+ const sections = [];
6039
+ for (const id of declared) {
6040
+ const section = byId.get(id);
6041
+ if (!section) throw new Error(`${this.constructor.name}: integrationSettingSections() names unknown section "${id}". Known sections: [${[...byId.keys()].join(", ")}].`);
6042
+ const fields = dropPerNodeFields(section.fields);
6043
+ if (fields.length === 0) continue;
6044
+ sections.push({
6045
+ ...section,
6046
+ fields
6047
+ });
6048
+ }
6049
+ if (sections.length === 0) return null;
6050
+ const projected = await this.resolveGlobalStore(nodeId);
6051
+ return hydrateSchema({
6052
+ ...schema,
6053
+ sections
6054
+ }, projected);
6055
+ }
6056
+ /**
5974
6057
  * The raw addon store PROJECTED onto the target node's bare per-node keys:
5975
6058
  * every `perNode: true` field carries THAT node's scoped value on its bare
5976
6059
  * key (absent scoped key ⇒ key absent, so the schema `default` wins — no
@@ -6274,6 +6357,41 @@ var BaseAddon = class {
6274
6357
  * `hydrateSchema` does. Valueless structural fields (separator/info/…)
6275
6358
  * don't declare `perNode` and are excluded by the `in` narrowing.
6276
6359
  */
6360
+ /**
6361
+ * The same fields with every `perNode: true` one removed, recursing into layout
6362
+ * containers exactly as {@link collectPerNodeFieldKeys} does. A container left
6363
+ * with no child is dropped rather than rendered empty.
6364
+ *
6365
+ * Used by `getIntegrationSettings`: an integration is not a node, so a field
6366
+ * whose store key is `<key>@<nodeId>` has no node to belong to there.
6367
+ */
6368
+ function dropPerNodeFields(fields) {
6369
+ const kept = [];
6370
+ for (const field of fields) {
6371
+ if (field.type === "group") {
6372
+ const inner = dropPerNodeFields(field.fields);
6373
+ if (inner.length > 0) kept.push({
6374
+ ...field,
6375
+ fields: inner
6376
+ });
6377
+ continue;
6378
+ }
6379
+ if (field.type === "sub-tabs") {
6380
+ const tabs = field.tabs.map((tab) => ({
6381
+ ...tab,
6382
+ fields: dropPerNodeFields(tab.fields)
6383
+ })).filter((tab) => tab.fields.length > 0);
6384
+ if (tabs.length > 0) kept.push({
6385
+ ...field,
6386
+ tabs
6387
+ });
6388
+ continue;
6389
+ }
6390
+ if ("perNode" in field && field.perNode === true) continue;
6391
+ kept.push(field);
6392
+ }
6393
+ return kept;
6394
+ }
6277
6395
  function collectPerNodeFieldKeys(fields) {
6278
6396
  const collected = [];
6279
6397
  for (const field of fields) {
@@ -9427,6 +9545,9 @@ method(object({
9427
9545
  kind: "mutation",
9428
9546
  auth: "admin"
9429
9547
  }), method(object({
9548
+ addonId: string(),
9549
+ nodeId: string().optional()
9550
+ }), SettingsSchemaWithValuesSchema.nullable()), method(object({
9430
9551
  addonId: string(),
9431
9552
  deviceId: number(),
9432
9553
  nodeId: string().optional()
@@ -27889,6 +28010,12 @@ Object.freeze({
27889
28010
  addonId: null,
27890
28011
  access: "view"
27891
28012
  },
28013
+ "addonSettings.getIntegrationSettings": {
28014
+ capName: "addon-settings",
28015
+ capScope: "system",
28016
+ addonId: null,
28017
+ access: "view"
28018
+ },
27892
28019
  "addonSettings.updateDeviceSettings": {
27893
28020
  capName: "addon-settings",
27894
28021
  capScope: "system",
@@ -5956,6 +5956,40 @@ var BaseAddon = class {
5956
5956
  deviceSettingsSchema() {
5957
5957
  return null;
5958
5958
  }
5959
+ /**
5960
+ * INTEGRATION-LEVEL SETTINGS — declare which of this addon's global sections
5961
+ * ARE the configuration of its integration.
5962
+ *
5963
+ * Return the `ConfigSection.id`s, from {@link globalSettingsSchema}, that an
5964
+ * operator should find on the addon's integration page (System →
5965
+ * Integrations → <name>) rather than only in the cluster-wide list of every
5966
+ * addon. Empty (the default) means the addon has no integration-level
5967
+ * settings and no such surface is offered — this is opt-in, because whether
5968
+ * an addon's configuration IS its integration's configuration depends on the
5969
+ * nature of the integration.
5970
+ *
5971
+ * WHAT THIS IS NOT. It is not a scope. The selected sections keep living in
5972
+ * the ONE global schema, in the ONE addon store, written by the ONE
5973
+ * `updateGlobalSettings` path. There is deliberately no
5974
+ * `updateIntegrationSettings`: a second write path is how a surface acquires
5975
+ * a second store key, and this repo has shipped that twice (`btmPath@hub`,
5976
+ * D266). Selecting sections cannot introduce a key that selecting cannot.
5977
+ *
5978
+ * WHY IT IS A LIST OF SECTION IDS AND NOT A MARKER ON THE SECTION.
5979
+ * `ConfigFieldBase` used to carry `scope?: 'device' | 'global'` and it was
5980
+ * removed with the reason recorded at
5981
+ * `packages/types/src/interfaces/config-ui.ts:249` — *"a field's scope is
5982
+ * determined by WHICH schema it lives in, not by a field-level marker."* A
5983
+ * marker sprinkled across sections also has to borrow a field that already
5984
+ * means something else; borrowing `section.tab` put the literal word
5985
+ * "integration" into an operator-facing tab bar, because `tab` means "how to
5986
+ * GROUP this visually" and cannot also mean "where this lives" (D269
5987
+ * supersedes D268). One declaration, in one place, next to the schema whose
5988
+ * ids it names.
5989
+ */
5990
+ integrationSettingSections() {
5991
+ return [];
5992
+ }
5959
5993
  async getGlobalSettings(overlay, cap, nodeId) {
5960
5994
  const schema = this.globalSettingsSchema(cap);
5961
5995
  if (!schema) return { sections: [] };
@@ -5966,6 +6000,55 @@ var BaseAddon = class {
5966
6000
  } : projected);
5967
6001
  }
5968
6002
  /**
6003
+ * The integration-level view of this addon's settings: exactly the sections
6004
+ * named by {@link integrationSettingSections}, hydrated from the SAME store
6005
+ * `getGlobalSettings` reads, and narrowed to cluster-scoped fields.
6006
+ *
6007
+ * Returns `null` when the addon declared nothing — an addon that opts out has
6008
+ * no integration settings surface at all, rather than an empty one that reads
6009
+ * as a failed load.
6010
+ *
6011
+ * Three properties hold BY CONSTRUCTION, which is why they are here in core
6012
+ * and not in whichever UI happens to render this:
6013
+ *
6014
+ * 1. **One key.** The payload is a SUBSET of the global schema, so a field
6015
+ * shown here is the same field, with the same bare key, that the addon's
6016
+ * own page shows. There is no integration-specific writer — callers save
6017
+ * through `updateGlobalSettings` — so a second store key is unreachable,
6018
+ * not merely discouraged.
6019
+ * 2. **No node scope.** `perNode: true` fields are DROPPED. Their store key
6020
+ * is `<key>@<nodeId>` and an integration is not a node; whichever node
6021
+ * such a field silently picked would be a wrong answer for the operator
6022
+ * who opened the page (D266).
6023
+ * 3. **No silent typo.** A declared id that names no section throws. The
6024
+ * alternative — skip it — turns a rename into a surface that quietly
6025
+ * empties, which looks exactly like an addon with nothing to configure.
6026
+ */
6027
+ async getIntegrationSettings(nodeId) {
6028
+ const declared = this.integrationSettingSections();
6029
+ if (declared.length === 0) return null;
6030
+ const schema = this.globalSettingsSchema();
6031
+ if (!schema) throw new Error(`${this.constructor.name}: integrationSettingSections() names [${declared.join(", ")}] but globalSettingsSchema() returns null.`);
6032
+ const byId = new Map(schema.sections.map((section) => [section.id, section]));
6033
+ const sections = [];
6034
+ for (const id of declared) {
6035
+ const section = byId.get(id);
6036
+ if (!section) throw new Error(`${this.constructor.name}: integrationSettingSections() names unknown section "${id}". Known sections: [${[...byId.keys()].join(", ")}].`);
6037
+ const fields = dropPerNodeFields(section.fields);
6038
+ if (fields.length === 0) continue;
6039
+ sections.push({
6040
+ ...section,
6041
+ fields
6042
+ });
6043
+ }
6044
+ if (sections.length === 0) return null;
6045
+ const projected = await this.resolveGlobalStore(nodeId);
6046
+ return hydrateSchema({
6047
+ ...schema,
6048
+ sections
6049
+ }, projected);
6050
+ }
6051
+ /**
5969
6052
  * The raw addon store PROJECTED onto the target node's bare per-node keys:
5970
6053
  * every `perNode: true` field carries THAT node's scoped value on its bare
5971
6054
  * key (absent scoped key ⇒ key absent, so the schema `default` wins — no
@@ -6269,6 +6352,41 @@ var BaseAddon = class {
6269
6352
  * `hydrateSchema` does. Valueless structural fields (separator/info/…)
6270
6353
  * don't declare `perNode` and are excluded by the `in` narrowing.
6271
6354
  */
6355
+ /**
6356
+ * The same fields with every `perNode: true` one removed, recursing into layout
6357
+ * containers exactly as {@link collectPerNodeFieldKeys} does. A container left
6358
+ * with no child is dropped rather than rendered empty.
6359
+ *
6360
+ * Used by `getIntegrationSettings`: an integration is not a node, so a field
6361
+ * whose store key is `<key>@<nodeId>` has no node to belong to there.
6362
+ */
6363
+ function dropPerNodeFields(fields) {
6364
+ const kept = [];
6365
+ for (const field of fields) {
6366
+ if (field.type === "group") {
6367
+ const inner = dropPerNodeFields(field.fields);
6368
+ if (inner.length > 0) kept.push({
6369
+ ...field,
6370
+ fields: inner
6371
+ });
6372
+ continue;
6373
+ }
6374
+ if (field.type === "sub-tabs") {
6375
+ const tabs = field.tabs.map((tab) => ({
6376
+ ...tab,
6377
+ fields: dropPerNodeFields(tab.fields)
6378
+ })).filter((tab) => tab.fields.length > 0);
6379
+ if (tabs.length > 0) kept.push({
6380
+ ...field,
6381
+ tabs
6382
+ });
6383
+ continue;
6384
+ }
6385
+ if ("perNode" in field && field.perNode === true) continue;
6386
+ kept.push(field);
6387
+ }
6388
+ return kept;
6389
+ }
6272
6390
  function collectPerNodeFieldKeys(fields) {
6273
6391
  const collected = [];
6274
6392
  for (const field of fields) {
@@ -9422,6 +9540,9 @@ method(object({
9422
9540
  kind: "mutation",
9423
9541
  auth: "admin"
9424
9542
  }), method(object({
9543
+ addonId: string(),
9544
+ nodeId: string().optional()
9545
+ }), SettingsSchemaWithValuesSchema.nullable()), method(object({
9425
9546
  addonId: string(),
9426
9547
  deviceId: number(),
9427
9548
  nodeId: string().optional()
@@ -27884,6 +28005,12 @@ Object.freeze({
27884
28005
  addonId: null,
27885
28006
  access: "view"
27886
28007
  },
28008
+ "addonSettings.getIntegrationSettings": {
28009
+ capName: "addon-settings",
28010
+ capScope: "system",
28011
+ addonId: null,
28012
+ access: "view"
28013
+ },
27887
28014
  "addonSettings.updateDeviceSettings": {
27888
28015
  capName: "addon-settings",
27889
28016
  capScope: "system",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/addon-mqtt-broker",
3
- "version": "1.2.37",
3
+ "version": "1.2.38",
4
4
  "description": "MQTT broker registry addon for CamStack — manages external broker entries + an optional embedded aedes broker. Consumers spin up their own `mqtt.js` clients via the `mqtt-broker` cap.",
5
5
  "keywords": [
6
6
  "camstack",