@camstack/addon-provider-dreo 0.2.37 → 0.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.
package/dist/addon.js CHANGED
@@ -5952,6 +5952,40 @@ var BaseAddon = class {
5952
5952
  deviceSettingsSchema() {
5953
5953
  return null;
5954
5954
  }
5955
+ /**
5956
+ * INTEGRATION-LEVEL SETTINGS — declare which of this addon's global sections
5957
+ * ARE the configuration of its integration.
5958
+ *
5959
+ * Return the `ConfigSection.id`s, from {@link globalSettingsSchema}, that an
5960
+ * operator should find on the addon's integration page (System →
5961
+ * Integrations → <name>) rather than only in the cluster-wide list of every
5962
+ * addon. Empty (the default) means the addon has no integration-level
5963
+ * settings and no such surface is offered — this is opt-in, because whether
5964
+ * an addon's configuration IS its integration's configuration depends on the
5965
+ * nature of the integration.
5966
+ *
5967
+ * WHAT THIS IS NOT. It is not a scope. The selected sections keep living in
5968
+ * the ONE global schema, in the ONE addon store, written by the ONE
5969
+ * `updateGlobalSettings` path. There is deliberately no
5970
+ * `updateIntegrationSettings`: a second write path is how a surface acquires
5971
+ * a second store key, and this repo has shipped that twice (`btmPath@hub`,
5972
+ * D266). Selecting sections cannot introduce a key that selecting cannot.
5973
+ *
5974
+ * WHY IT IS A LIST OF SECTION IDS AND NOT A MARKER ON THE SECTION.
5975
+ * `ConfigFieldBase` used to carry `scope?: 'device' | 'global'` and it was
5976
+ * removed with the reason recorded at
5977
+ * `packages/types/src/interfaces/config-ui.ts:249` — *"a field's scope is
5978
+ * determined by WHICH schema it lives in, not by a field-level marker."* A
5979
+ * marker sprinkled across sections also has to borrow a field that already
5980
+ * means something else; borrowing `section.tab` put the literal word
5981
+ * "integration" into an operator-facing tab bar, because `tab` means "how to
5982
+ * GROUP this visually" and cannot also mean "where this lives" (D269
5983
+ * supersedes D268). One declaration, in one place, next to the schema whose
5984
+ * ids it names.
5985
+ */
5986
+ integrationSettingSections() {
5987
+ return [];
5988
+ }
5955
5989
  async getGlobalSettings(overlay, cap, nodeId) {
5956
5990
  const schema = this.globalSettingsSchema(cap);
5957
5991
  if (!schema) return { sections: [] };
@@ -5962,6 +5996,55 @@ var BaseAddon = class {
5962
5996
  } : projected);
5963
5997
  }
5964
5998
  /**
5999
+ * The integration-level view of this addon's settings: exactly the sections
6000
+ * named by {@link integrationSettingSections}, hydrated from the SAME store
6001
+ * `getGlobalSettings` reads, and narrowed to cluster-scoped fields.
6002
+ *
6003
+ * Returns `null` when the addon declared nothing — an addon that opts out has
6004
+ * no integration settings surface at all, rather than an empty one that reads
6005
+ * as a failed load.
6006
+ *
6007
+ * Three properties hold BY CONSTRUCTION, which is why they are here in core
6008
+ * and not in whichever UI happens to render this:
6009
+ *
6010
+ * 1. **One key.** The payload is a SUBSET of the global schema, so a field
6011
+ * shown here is the same field, with the same bare key, that the addon's
6012
+ * own page shows. There is no integration-specific writer — callers save
6013
+ * through `updateGlobalSettings` — so a second store key is unreachable,
6014
+ * not merely discouraged.
6015
+ * 2. **No node scope.** `perNode: true` fields are DROPPED. Their store key
6016
+ * is `<key>@<nodeId>` and an integration is not a node; whichever node
6017
+ * such a field silently picked would be a wrong answer for the operator
6018
+ * who opened the page (D266).
6019
+ * 3. **No silent typo.** A declared id that names no section throws. The
6020
+ * alternative — skip it — turns a rename into a surface that quietly
6021
+ * empties, which looks exactly like an addon with nothing to configure.
6022
+ */
6023
+ async getIntegrationSettings(nodeId) {
6024
+ const declared = this.integrationSettingSections();
6025
+ if (declared.length === 0) return null;
6026
+ const schema = this.globalSettingsSchema();
6027
+ if (!schema) throw new Error(`${this.constructor.name}: integrationSettingSections() names [${declared.join(", ")}] but globalSettingsSchema() returns null.`);
6028
+ const byId = new Map(schema.sections.map((section) => [section.id, section]));
6029
+ const sections = [];
6030
+ for (const id of declared) {
6031
+ const section = byId.get(id);
6032
+ if (!section) throw new Error(`${this.constructor.name}: integrationSettingSections() names unknown section "${id}". Known sections: [${[...byId.keys()].join(", ")}].`);
6033
+ const fields = dropPerNodeFields(section.fields);
6034
+ if (fields.length === 0) continue;
6035
+ sections.push({
6036
+ ...section,
6037
+ fields
6038
+ });
6039
+ }
6040
+ if (sections.length === 0) return null;
6041
+ const projected = await this.resolveGlobalStore(nodeId);
6042
+ return hydrateSchema({
6043
+ ...schema,
6044
+ sections
6045
+ }, projected);
6046
+ }
6047
+ /**
5965
6048
  * The raw addon store PROJECTED onto the target node's bare per-node keys:
5966
6049
  * every `perNode: true` field carries THAT node's scoped value on its bare
5967
6050
  * key (absent scoped key ⇒ key absent, so the schema `default` wins — no
@@ -6265,6 +6348,41 @@ var BaseAddon = class {
6265
6348
  * `hydrateSchema` does. Valueless structural fields (separator/info/…)
6266
6349
  * don't declare `perNode` and are excluded by the `in` narrowing.
6267
6350
  */
6351
+ /**
6352
+ * The same fields with every `perNode: true` one removed, recursing into layout
6353
+ * containers exactly as {@link collectPerNodeFieldKeys} does. A container left
6354
+ * with no child is dropped rather than rendered empty.
6355
+ *
6356
+ * Used by `getIntegrationSettings`: an integration is not a node, so a field
6357
+ * whose store key is `<key>@<nodeId>` has no node to belong to there.
6358
+ */
6359
+ function dropPerNodeFields(fields) {
6360
+ const kept = [];
6361
+ for (const field of fields) {
6362
+ if (field.type === "group") {
6363
+ const inner = dropPerNodeFields(field.fields);
6364
+ if (inner.length > 0) kept.push({
6365
+ ...field,
6366
+ fields: inner
6367
+ });
6368
+ continue;
6369
+ }
6370
+ if (field.type === "sub-tabs") {
6371
+ const tabs = field.tabs.map((tab) => ({
6372
+ ...tab,
6373
+ fields: dropPerNodeFields(tab.fields)
6374
+ })).filter((tab) => tab.fields.length > 0);
6375
+ if (tabs.length > 0) kept.push({
6376
+ ...field,
6377
+ tabs
6378
+ });
6379
+ continue;
6380
+ }
6381
+ if ("perNode" in field && field.perNode === true) continue;
6382
+ kept.push(field);
6383
+ }
6384
+ return kept;
6385
+ }
6268
6386
  function collectPerNodeFieldKeys(fields) {
6269
6387
  const collected = [];
6270
6388
  for (const field of fields) {
@@ -9434,6 +9552,9 @@ method(object({
9434
9552
  kind: "mutation",
9435
9553
  auth: "admin"
9436
9554
  }), method(object({
9555
+ addonId: string(),
9556
+ nodeId: string().optional()
9557
+ }), SettingsSchemaWithValuesSchema.nullable()), method(object({
9437
9558
  addonId: string(),
9438
9559
  deviceId: number(),
9439
9560
  nodeId: string().optional()
@@ -31552,6 +31673,12 @@ Object.freeze({
31552
31673
  addonId: null,
31553
31674
  access: "view"
31554
31675
  },
31676
+ "addonSettings.getIntegrationSettings": {
31677
+ capName: "addon-settings",
31678
+ capScope: "system",
31679
+ addonId: null,
31680
+ access: "view"
31681
+ },
31555
31682
  "addonSettings.updateDeviceSettings": {
31556
31683
  capName: "addon-settings",
31557
31684
  capScope: "system",
package/dist/addon.mjs CHANGED
@@ -5953,6 +5953,40 @@ var BaseAddon = class {
5953
5953
  deviceSettingsSchema() {
5954
5954
  return null;
5955
5955
  }
5956
+ /**
5957
+ * INTEGRATION-LEVEL SETTINGS — declare which of this addon's global sections
5958
+ * ARE the configuration of its integration.
5959
+ *
5960
+ * Return the `ConfigSection.id`s, from {@link globalSettingsSchema}, that an
5961
+ * operator should find on the addon's integration page (System →
5962
+ * Integrations → <name>) rather than only in the cluster-wide list of every
5963
+ * addon. Empty (the default) means the addon has no integration-level
5964
+ * settings and no such surface is offered — this is opt-in, because whether
5965
+ * an addon's configuration IS its integration's configuration depends on the
5966
+ * nature of the integration.
5967
+ *
5968
+ * WHAT THIS IS NOT. It is not a scope. The selected sections keep living in
5969
+ * the ONE global schema, in the ONE addon store, written by the ONE
5970
+ * `updateGlobalSettings` path. There is deliberately no
5971
+ * `updateIntegrationSettings`: a second write path is how a surface acquires
5972
+ * a second store key, and this repo has shipped that twice (`btmPath@hub`,
5973
+ * D266). Selecting sections cannot introduce a key that selecting cannot.
5974
+ *
5975
+ * WHY IT IS A LIST OF SECTION IDS AND NOT A MARKER ON THE SECTION.
5976
+ * `ConfigFieldBase` used to carry `scope?: 'device' | 'global'` and it was
5977
+ * removed with the reason recorded at
5978
+ * `packages/types/src/interfaces/config-ui.ts:249` — *"a field's scope is
5979
+ * determined by WHICH schema it lives in, not by a field-level marker."* A
5980
+ * marker sprinkled across sections also has to borrow a field that already
5981
+ * means something else; borrowing `section.tab` put the literal word
5982
+ * "integration" into an operator-facing tab bar, because `tab` means "how to
5983
+ * GROUP this visually" and cannot also mean "where this lives" (D269
5984
+ * supersedes D268). One declaration, in one place, next to the schema whose
5985
+ * ids it names.
5986
+ */
5987
+ integrationSettingSections() {
5988
+ return [];
5989
+ }
5956
5990
  async getGlobalSettings(overlay, cap, nodeId) {
5957
5991
  const schema = this.globalSettingsSchema(cap);
5958
5992
  if (!schema) return { sections: [] };
@@ -5963,6 +5997,55 @@ var BaseAddon = class {
5963
5997
  } : projected);
5964
5998
  }
5965
5999
  /**
6000
+ * The integration-level view of this addon's settings: exactly the sections
6001
+ * named by {@link integrationSettingSections}, hydrated from the SAME store
6002
+ * `getGlobalSettings` reads, and narrowed to cluster-scoped fields.
6003
+ *
6004
+ * Returns `null` when the addon declared nothing — an addon that opts out has
6005
+ * no integration settings surface at all, rather than an empty one that reads
6006
+ * as a failed load.
6007
+ *
6008
+ * Three properties hold BY CONSTRUCTION, which is why they are here in core
6009
+ * and not in whichever UI happens to render this:
6010
+ *
6011
+ * 1. **One key.** The payload is a SUBSET of the global schema, so a field
6012
+ * shown here is the same field, with the same bare key, that the addon's
6013
+ * own page shows. There is no integration-specific writer — callers save
6014
+ * through `updateGlobalSettings` — so a second store key is unreachable,
6015
+ * not merely discouraged.
6016
+ * 2. **No node scope.** `perNode: true` fields are DROPPED. Their store key
6017
+ * is `<key>@<nodeId>` and an integration is not a node; whichever node
6018
+ * such a field silently picked would be a wrong answer for the operator
6019
+ * who opened the page (D266).
6020
+ * 3. **No silent typo.** A declared id that names no section throws. The
6021
+ * alternative — skip it — turns a rename into a surface that quietly
6022
+ * empties, which looks exactly like an addon with nothing to configure.
6023
+ */
6024
+ async getIntegrationSettings(nodeId) {
6025
+ const declared = this.integrationSettingSections();
6026
+ if (declared.length === 0) return null;
6027
+ const schema = this.globalSettingsSchema();
6028
+ if (!schema) throw new Error(`${this.constructor.name}: integrationSettingSections() names [${declared.join(", ")}] but globalSettingsSchema() returns null.`);
6029
+ const byId = new Map(schema.sections.map((section) => [section.id, section]));
6030
+ const sections = [];
6031
+ for (const id of declared) {
6032
+ const section = byId.get(id);
6033
+ if (!section) throw new Error(`${this.constructor.name}: integrationSettingSections() names unknown section "${id}". Known sections: [${[...byId.keys()].join(", ")}].`);
6034
+ const fields = dropPerNodeFields(section.fields);
6035
+ if (fields.length === 0) continue;
6036
+ sections.push({
6037
+ ...section,
6038
+ fields
6039
+ });
6040
+ }
6041
+ if (sections.length === 0) return null;
6042
+ const projected = await this.resolveGlobalStore(nodeId);
6043
+ return hydrateSchema({
6044
+ ...schema,
6045
+ sections
6046
+ }, projected);
6047
+ }
6048
+ /**
5966
6049
  * The raw addon store PROJECTED onto the target node's bare per-node keys:
5967
6050
  * every `perNode: true` field carries THAT node's scoped value on its bare
5968
6051
  * key (absent scoped key ⇒ key absent, so the schema `default` wins — no
@@ -6266,6 +6349,41 @@ var BaseAddon = class {
6266
6349
  * `hydrateSchema` does. Valueless structural fields (separator/info/…)
6267
6350
  * don't declare `perNode` and are excluded by the `in` narrowing.
6268
6351
  */
6352
+ /**
6353
+ * The same fields with every `perNode: true` one removed, recursing into layout
6354
+ * containers exactly as {@link collectPerNodeFieldKeys} does. A container left
6355
+ * with no child is dropped rather than rendered empty.
6356
+ *
6357
+ * Used by `getIntegrationSettings`: an integration is not a node, so a field
6358
+ * whose store key is `<key>@<nodeId>` has no node to belong to there.
6359
+ */
6360
+ function dropPerNodeFields(fields) {
6361
+ const kept = [];
6362
+ for (const field of fields) {
6363
+ if (field.type === "group") {
6364
+ const inner = dropPerNodeFields(field.fields);
6365
+ if (inner.length > 0) kept.push({
6366
+ ...field,
6367
+ fields: inner
6368
+ });
6369
+ continue;
6370
+ }
6371
+ if (field.type === "sub-tabs") {
6372
+ const tabs = field.tabs.map((tab) => ({
6373
+ ...tab,
6374
+ fields: dropPerNodeFields(tab.fields)
6375
+ })).filter((tab) => tab.fields.length > 0);
6376
+ if (tabs.length > 0) kept.push({
6377
+ ...field,
6378
+ tabs
6379
+ });
6380
+ continue;
6381
+ }
6382
+ if ("perNode" in field && field.perNode === true) continue;
6383
+ kept.push(field);
6384
+ }
6385
+ return kept;
6386
+ }
6269
6387
  function collectPerNodeFieldKeys(fields) {
6270
6388
  const collected = [];
6271
6389
  for (const field of fields) {
@@ -9435,6 +9553,9 @@ method(object({
9435
9553
  kind: "mutation",
9436
9554
  auth: "admin"
9437
9555
  }), method(object({
9556
+ addonId: string(),
9557
+ nodeId: string().optional()
9558
+ }), SettingsSchemaWithValuesSchema.nullable()), method(object({
9438
9559
  addonId: string(),
9439
9560
  deviceId: number(),
9440
9561
  nodeId: string().optional()
@@ -31553,6 +31674,12 @@ Object.freeze({
31553
31674
  addonId: null,
31554
31675
  access: "view"
31555
31676
  },
31677
+ "addonSettings.getIntegrationSettings": {
31678
+ capName: "addon-settings",
31679
+ capScope: "system",
31680
+ addonId: null,
31681
+ access: "view"
31682
+ },
31556
31683
  "addonSettings.updateDeviceSettings": {
31557
31684
  capName: "addon-settings",
31558
31685
  capScope: "system",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/addon-provider-dreo",
3
- "version": "0.2.37",
3
+ "version": "0.2.38",
4
4
  "description": "Dreo smart-device (fan / air-circulator / purifier / heater / humidifier) device-provider addon for CamStack — wraps the @apocaliss92/nodedreo Dreo cloud client (REST + WebSocket)",
5
5
  "keywords": [
6
6
  "camstack",