@camstack/addon-provider-mqtt-ha 0.1.7 → 0.1.8

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 (3) hide show
  1. package/dist/addon.js +229 -196
  2. package/dist/addon.mjs +229 -196
  3. package/package.json +1 -1
package/dist/addon.js CHANGED
@@ -7830,6 +7830,12 @@ function normalizeAddonInitResult(result) {
7830
7830
  if (Array.isArray(result)) return { providers: result };
7831
7831
  return result;
7832
7832
  }
7833
+ /**
7834
+ * The share-view scope kinds a `csv_*` share token can carry. The hub mints
7835
+ * and validates them (`share-token.service.ts` builds its enum from this
7836
+ * list); a data plane names the kinds it ACCEPTS in `share`.
7837
+ */
7838
+ var SHARE_VIEW_KINDS = ["grid-view", "events-view"];
7833
7839
  /** The wire shape of {@link PeerBytesTicket} — see the type for what it is. */
7834
7840
  var PeerBytesTicketSchema = object({
7835
7841
  /** `http://127.0.0.1:<port>/<token>`. One `GET` takes it. */
@@ -12495,6 +12501,229 @@ var ConvertResultSchema = object({
12495
12501
  files: array(string()).readonly()
12496
12502
  })).readonly()
12497
12503
  });
12504
+ /**
12505
+ * Zod schemas for persisted record types.
12506
+ *
12507
+ * These schemas serve as the single source of truth for types that are
12508
+ * stored in the settings-store backend and retrieved via tRPC. They
12509
+ * replace the manual TypeScript interfaces with schema-derived types,
12510
+ * enabling runtime validation when reading from the backend.
12511
+ *
12512
+ * Convention: each schema is named `<Type>Schema`, the inferred TS type
12513
+ * keeps the original name for backward compatibility.
12514
+ */
12515
+ /**
12516
+ * Auth model (v2 — 2026-05-12 caps-only):
12517
+ *
12518
+ * Two principals:
12519
+ * - `isAdmin: true` — full bypass. Admin scope set is ignored.
12520
+ * - `isAdmin: false` — every call gated by `scopes` (see TokenScope).
12521
+ *
12522
+ * No role enum. There used to be `viewer / agent / scoped` and earlier
12523
+ * `super_admin` — collapsed onto the single boolean because every
12524
+ * non-admin caller is governed by the same scope-check rules; the
12525
+ * distinction was only ever used to route role-specific procedures
12526
+ * which we no longer have. CLI / webhook integrations are `cst_*` tokens
12527
+ * with `isAdmin: false` + an explicit scope list.
12528
+ */
12529
+ /** Per-method access flavour. Materialised on every cap method via codegen. */
12530
+ var MethodAccessSchema = _enum([
12531
+ "view",
12532
+ "create",
12533
+ "delete"
12534
+ ]);
12535
+ /**
12536
+ * A single scope grant. Three forms — checked in matcher with OR
12537
+ * semantics; the first match decides whether the call passes:
12538
+ *
12539
+ * - `category` — broadest. `target: 'device' | 'system'` selects every
12540
+ * cap with the matching `scope` declaration. New caps inherit grants
12541
+ * automatically — adding a device cap to the codebase makes it
12542
+ * reachable to every user with `category:device [...]` without a
12543
+ * re-grant. Use this for "family viewer" / "operator" tiers.
12544
+ *
12545
+ * - `addon` — every cap that ships inside a given addon id. Niche;
12546
+ * useful when an integration needs to interact with one specific
12547
+ * addon's surface regardless of how many caps it exports.
12548
+ *
12549
+ * - `capability` — the most precise form. Single cap name. Use for
12550
+ * integration tokens where you want to grant `addons.installPackage`
12551
+ * and nothing else.
12552
+ *
12553
+ * `access` is REQUIRED with min 1 element. `admin` bypass is the
12554
+ * "give me everything" escape; there is no wildcard scope.
12555
+ */
12556
+ var AllowedProviderSchema = union([literal("*"), array(string())]);
12557
+ var AllowedDevicesSchema = record(string(), union([literal("*"), array(string())]));
12558
+ var CapScopeSchema = _enum(["device", "system"]);
12559
+ /**
12560
+ * DeviceSelector (scope model v3 — 2026-08-12).
12561
+ *
12562
+ * A `device` grant no longer carries a frozen list of deviceIds. It carries
12563
+ * a SELECTOR the matcher resolves against the live fleet, so the grant can be
12564
+ * DYNAMIC: a `types:['camera']` selector automatically covers a camera added
12565
+ * AFTER the grant was minted — no re-grant, no re-login.
12566
+ *
12567
+ * - `all` — every device in the deployment. The broad viewer/operator
12568
+ * lever without a `category` grant (a `category` grant also covers device
12569
+ * caps that carry no deviceId; `all` is specifically the device set).
12570
+ * - `ids` — an explicit deviceId list. This is what a v2 `device:[…]`
12571
+ * grant migrates to (see {@link TokenScopeSchema}); STATIC — a new camera
12572
+ * is NOT covered until the grant is edited.
12573
+ * - `types` — every device of a `DeviceType` (e.g. every `camera`).
12574
+ * DYNAMIC. A device that changes type, or a new device of the type,
12575
+ * re-resolves on the next request.
12576
+ * - `locations` — every device whose operator-assigned `location` label is
12577
+ * in the set (e.g. "Garden", "Front door"). DYNAMIC. A device with a
12578
+ * null/unset location matches NO `locations` selector.
12579
+ */
12580
+ var DeviceSelectorSchema = discriminatedUnion("kind", [
12581
+ object({ kind: literal("all") }),
12582
+ object({
12583
+ kind: literal("ids"),
12584
+ ids: array(number().int()).min(1)
12585
+ }),
12586
+ object({
12587
+ kind: literal("types"),
12588
+ types: array(_enum(DeviceType)).min(1)
12589
+ }),
12590
+ object({
12591
+ kind: literal("locations"),
12592
+ locations: array(string().min(1)).min(1)
12593
+ })
12594
+ ]);
12595
+ var DeviceTokenScopeSchema = object({
12596
+ type: literal("device"),
12597
+ /** The device SET this grant covers — resolved against the live fleet. */
12598
+ selector: DeviceSelectorSchema,
12599
+ access: array(MethodAccessSchema).min(1),
12600
+ /**
12601
+ * Whether a grant on a PARENT device transparently covers its accessory
12602
+ * CHILDREN (siren / floodlight / PIR) via the persisted-parentage walk.
12603
+ * Direction is parent → children ONLY.
12604
+ *
12605
+ * Absent → the matcher DERIVES it from the access flavour: `view`
12606
+ * inherits (a camera viewer sees the camera's accessories), `create` /
12607
+ * `delete` do NOT (actuating/removing a child is an explicit act the
12608
+ * operator must grant on the child, not inherit from the parent). Set it
12609
+ * explicitly to override that default per grant.
12610
+ */
12611
+ includeLinked: boolean().optional()
12612
+ });
12613
+ /**
12614
+ * v2 → v3 lazy migration. A pre-v3 `device` grant carried
12615
+ * `targets: string[]` (stringified deviceIds); it rewrites to the equivalent
12616
+ * `selector: {kind:'ids', ids}`. Applied as a `preprocess` so it runs on
12617
+ * EVERY parse path — stored records AND the JWT-carried scope arrays
12618
+ * normalised at the request boundary ({@link normalizeTokenScopes} in
12619
+ * `device-selector.ts`). Chosen over a one-time DB migration because a
12620
+ * migration cannot reach a JWT already in a client's hands; parse-time
12621
+ * migration covers both without a flag day. No cast — the raw object is read
12622
+ * through `Reflect.get` (its static type is `unknown`).
12623
+ */
12624
+ function migrateLegacyTokenScope(raw) {
12625
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return raw;
12626
+ if (Reflect.get(raw, "type") !== "device") return raw;
12627
+ if (Reflect.get(raw, "selector") !== void 0) return raw;
12628
+ const targets = Reflect.get(raw, "targets");
12629
+ if (!Array.isArray(targets)) return raw;
12630
+ return {
12631
+ type: "device",
12632
+ selector: {
12633
+ kind: "ids",
12634
+ ids: targets.map((t) => typeof t === "string" ? Number(t) : t).filter((n) => typeof n === "number" && Number.isInteger(n))
12635
+ },
12636
+ access: Reflect.get(raw, "access")
12637
+ };
12638
+ }
12639
+ var TokenScopeSchema = preprocess(migrateLegacyTokenScope, discriminatedUnion("type", [
12640
+ object({
12641
+ type: literal("category"),
12642
+ target: CapScopeSchema,
12643
+ access: array(MethodAccessSchema).min(1)
12644
+ }),
12645
+ object({
12646
+ type: literal("capability"),
12647
+ target: string(),
12648
+ access: array(MethodAccessSchema).min(1)
12649
+ }),
12650
+ object({
12651
+ type: literal("addon"),
12652
+ target: string(),
12653
+ access: array(MethodAccessSchema).min(1)
12654
+ }),
12655
+ DeviceTokenScopeSchema
12656
+ ]));
12657
+ object({
12658
+ id: string(),
12659
+ username: string(),
12660
+ passwordHash: string(),
12661
+ /**
12662
+ * Admin bypass. When true, the middleware skips the scope-access
12663
+ * check entirely. There is no other axis of privilege; the legacy
12664
+ * role enum collapsed onto this boolean in v2.
12665
+ */
12666
+ isAdmin: boolean().default(false),
12667
+ allowedProviders: AllowedProviderSchema,
12668
+ allowedDevices: AllowedDevicesSchema,
12669
+ /**
12670
+ * Scopes granted to this user. Admins bypass; their `scopes` is
12671
+ * ignored. Non-admins without scopes are locked out of every
12672
+ * protected call.
12673
+ */
12674
+ scopes: array(TokenScopeSchema).default([]),
12675
+ createdAt: number(),
12676
+ updatedAt: number()
12677
+ });
12678
+ object({
12679
+ id: string(),
12680
+ label: string(),
12681
+ isAdmin: boolean().default(false),
12682
+ allowedProviders: AllowedProviderSchema,
12683
+ allowedDevices: AllowedDevicesSchema,
12684
+ tokenHash: string(),
12685
+ tokenPrefix: string(),
12686
+ createdAt: number(),
12687
+ lastUsedAt: number().optional()
12688
+ });
12689
+ object({
12690
+ id: string(),
12691
+ userId: string(),
12692
+ name: string(),
12693
+ tokenHash: string(),
12694
+ tokenPrefix: string(),
12695
+ scopes: array(TokenScopeSchema),
12696
+ expiresAt: number().nullish(),
12697
+ lastUsedAt: number().nullish(),
12698
+ createdAt: number()
12699
+ });
12700
+ /** What a share-view grant lets its holder see. */
12701
+ var ShareViewGrantSchema = object({
12702
+ kind: _enum(SHARE_VIEW_KINDS),
12703
+ deviceIds: array(number().int().nonnegative()).min(1).max(64),
12704
+ /** Talk-back, opt-in at mint time; absent means off. */
12705
+ talk: boolean().optional()
12706
+ });
12707
+ var ShareViewScopeSchema = object({
12708
+ type: literal("share-view"),
12709
+ grant: ShareViewGrantSchema
12710
+ });
12711
+ var AddonRoutesScopeSchema = object({
12712
+ type: literal("addon-routes"),
12713
+ access: array(MethodAccessSchema).min(1)
12714
+ });
12715
+ var CredentialScopeSchema = union([
12716
+ literal("*"),
12717
+ ShareViewScopeSchema,
12718
+ AddonRoutesScopeSchema,
12719
+ TokenScopeSchema
12720
+ ]);
12721
+ object({
12722
+ kind: literal("credential"),
12723
+ sub: string().min(1),
12724
+ jti: string().min(16),
12725
+ scopes: array(CredentialScopeSchema).min(1)
12726
+ });
12498
12727
  _enum(["new-session", "step-up"]);
12499
12728
  /** The languages the hub's app landing pages are written in (D858). */
12500
12729
  var AppPageLangSchema = _enum(["en", "it"]);
@@ -43989,202 +44218,6 @@ method(object({}), object({ rules: array(NcRuleSchema) }), { auth: "admin" }), m
43989
44218
  auth: "admin"
43990
44219
  }), method(NcAlarmSensorsInputSchema, NcAlarmSensorsSchema, { auth: "admin" });
43991
44220
  /**
43992
- * Zod schemas for persisted record types.
43993
- *
43994
- * These schemas serve as the single source of truth for types that are
43995
- * stored in the settings-store backend and retrieved via tRPC. They
43996
- * replace the manual TypeScript interfaces with schema-derived types,
43997
- * enabling runtime validation when reading from the backend.
43998
- *
43999
- * Convention: each schema is named `<Type>Schema`, the inferred TS type
44000
- * keeps the original name for backward compatibility.
44001
- */
44002
- /**
44003
- * Auth model (v2 — 2026-05-12 caps-only):
44004
- *
44005
- * Two principals:
44006
- * - `isAdmin: true` — full bypass. Admin scope set is ignored.
44007
- * - `isAdmin: false` — every call gated by `scopes` (see TokenScope).
44008
- *
44009
- * No role enum. There used to be `viewer / agent / scoped` and earlier
44010
- * `super_admin` — collapsed onto the single boolean because every
44011
- * non-admin caller is governed by the same scope-check rules; the
44012
- * distinction was only ever used to route role-specific procedures
44013
- * which we no longer have. CLI / webhook integrations are `cst_*` tokens
44014
- * with `isAdmin: false` + an explicit scope list.
44015
- */
44016
- /** Per-method access flavour. Materialised on every cap method via codegen. */
44017
- var MethodAccessSchema = _enum([
44018
- "view",
44019
- "create",
44020
- "delete"
44021
- ]);
44022
- /**
44023
- * A single scope grant. Three forms — checked in matcher with OR
44024
- * semantics; the first match decides whether the call passes:
44025
- *
44026
- * - `category` — broadest. `target: 'device' | 'system'` selects every
44027
- * cap with the matching `scope` declaration. New caps inherit grants
44028
- * automatically — adding a device cap to the codebase makes it
44029
- * reachable to every user with `category:device [...]` without a
44030
- * re-grant. Use this for "family viewer" / "operator" tiers.
44031
- *
44032
- * - `addon` — every cap that ships inside a given addon id. Niche;
44033
- * useful when an integration needs to interact with one specific
44034
- * addon's surface regardless of how many caps it exports.
44035
- *
44036
- * - `capability` — the most precise form. Single cap name. Use for
44037
- * integration tokens where you want to grant `addons.installPackage`
44038
- * and nothing else.
44039
- *
44040
- * `access` is REQUIRED with min 1 element. `admin` bypass is the
44041
- * "give me everything" escape; there is no wildcard scope.
44042
- */
44043
- var AllowedProviderSchema = union([literal("*"), array(string())]);
44044
- var AllowedDevicesSchema = record(string(), union([literal("*"), array(string())]));
44045
- var CapScopeSchema = _enum(["device", "system"]);
44046
- /**
44047
- * DeviceSelector (scope model v3 — 2026-08-12).
44048
- *
44049
- * A `device` grant no longer carries a frozen list of deviceIds. It carries
44050
- * a SELECTOR the matcher resolves against the live fleet, so the grant can be
44051
- * DYNAMIC: a `types:['camera']` selector automatically covers a camera added
44052
- * AFTER the grant was minted — no re-grant, no re-login.
44053
- *
44054
- * - `all` — every device in the deployment. The broad viewer/operator
44055
- * lever without a `category` grant (a `category` grant also covers device
44056
- * caps that carry no deviceId; `all` is specifically the device set).
44057
- * - `ids` — an explicit deviceId list. This is what a v2 `device:[…]`
44058
- * grant migrates to (see {@link TokenScopeSchema}); STATIC — a new camera
44059
- * is NOT covered until the grant is edited.
44060
- * - `types` — every device of a `DeviceType` (e.g. every `camera`).
44061
- * DYNAMIC. A device that changes type, or a new device of the type,
44062
- * re-resolves on the next request.
44063
- * - `locations` — every device whose operator-assigned `location` label is
44064
- * in the set (e.g. "Garden", "Front door"). DYNAMIC. A device with a
44065
- * null/unset location matches NO `locations` selector.
44066
- */
44067
- var DeviceSelectorSchema = discriminatedUnion("kind", [
44068
- object({ kind: literal("all") }),
44069
- object({
44070
- kind: literal("ids"),
44071
- ids: array(number().int()).min(1)
44072
- }),
44073
- object({
44074
- kind: literal("types"),
44075
- types: array(_enum(DeviceType)).min(1)
44076
- }),
44077
- object({
44078
- kind: literal("locations"),
44079
- locations: array(string().min(1)).min(1)
44080
- })
44081
- ]);
44082
- var DeviceTokenScopeSchema = object({
44083
- type: literal("device"),
44084
- /** The device SET this grant covers — resolved against the live fleet. */
44085
- selector: DeviceSelectorSchema,
44086
- access: array(MethodAccessSchema).min(1),
44087
- /**
44088
- * Whether a grant on a PARENT device transparently covers its accessory
44089
- * CHILDREN (siren / floodlight / PIR) via the persisted-parentage walk.
44090
- * Direction is parent → children ONLY.
44091
- *
44092
- * Absent → the matcher DERIVES it from the access flavour: `view`
44093
- * inherits (a camera viewer sees the camera's accessories), `create` /
44094
- * `delete` do NOT (actuating/removing a child is an explicit act the
44095
- * operator must grant on the child, not inherit from the parent). Set it
44096
- * explicitly to override that default per grant.
44097
- */
44098
- includeLinked: boolean().optional()
44099
- });
44100
- /**
44101
- * v2 → v3 lazy migration. A pre-v3 `device` grant carried
44102
- * `targets: string[]` (stringified deviceIds); it rewrites to the equivalent
44103
- * `selector: {kind:'ids', ids}`. Applied as a `preprocess` so it runs on
44104
- * EVERY parse path — stored records AND the JWT-carried scope arrays
44105
- * normalised at the request boundary ({@link normalizeTokenScopes} in
44106
- * `device-selector.ts`). Chosen over a one-time DB migration because a
44107
- * migration cannot reach a JWT already in a client's hands; parse-time
44108
- * migration covers both without a flag day. No cast — the raw object is read
44109
- * through `Reflect.get` (its static type is `unknown`).
44110
- */
44111
- function migrateLegacyTokenScope(raw) {
44112
- if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return raw;
44113
- if (Reflect.get(raw, "type") !== "device") return raw;
44114
- if (Reflect.get(raw, "selector") !== void 0) return raw;
44115
- const targets = Reflect.get(raw, "targets");
44116
- if (!Array.isArray(targets)) return raw;
44117
- return {
44118
- type: "device",
44119
- selector: {
44120
- kind: "ids",
44121
- ids: targets.map((t) => typeof t === "string" ? Number(t) : t).filter((n) => typeof n === "number" && Number.isInteger(n))
44122
- },
44123
- access: Reflect.get(raw, "access")
44124
- };
44125
- }
44126
- var TokenScopeSchema = preprocess(migrateLegacyTokenScope, discriminatedUnion("type", [
44127
- object({
44128
- type: literal("category"),
44129
- target: CapScopeSchema,
44130
- access: array(MethodAccessSchema).min(1)
44131
- }),
44132
- object({
44133
- type: literal("capability"),
44134
- target: string(),
44135
- access: array(MethodAccessSchema).min(1)
44136
- }),
44137
- object({
44138
- type: literal("addon"),
44139
- target: string(),
44140
- access: array(MethodAccessSchema).min(1)
44141
- }),
44142
- DeviceTokenScopeSchema
44143
- ]));
44144
- object({
44145
- id: string(),
44146
- username: string(),
44147
- passwordHash: string(),
44148
- /**
44149
- * Admin bypass. When true, the middleware skips the scope-access
44150
- * check entirely. There is no other axis of privilege; the legacy
44151
- * role enum collapsed onto this boolean in v2.
44152
- */
44153
- isAdmin: boolean().default(false),
44154
- allowedProviders: AllowedProviderSchema,
44155
- allowedDevices: AllowedDevicesSchema,
44156
- /**
44157
- * Scopes granted to this user. Admins bypass; their `scopes` is
44158
- * ignored. Non-admins without scopes are locked out of every
44159
- * protected call.
44160
- */
44161
- scopes: array(TokenScopeSchema).default([]),
44162
- createdAt: number(),
44163
- updatedAt: number()
44164
- });
44165
- object({
44166
- id: string(),
44167
- label: string(),
44168
- isAdmin: boolean().default(false),
44169
- allowedProviders: AllowedProviderSchema,
44170
- allowedDevices: AllowedDevicesSchema,
44171
- tokenHash: string(),
44172
- tokenPrefix: string(),
44173
- createdAt: number(),
44174
- lastUsedAt: number().optional()
44175
- });
44176
- object({
44177
- id: string(),
44178
- userId: string(),
44179
- name: string(),
44180
- tokenHash: string(),
44181
- tokenPrefix: string(),
44182
- scopes: array(TokenScopeSchema),
44183
- expiresAt: number().nullish(),
44184
- lastUsedAt: number().nullish(),
44185
- createdAt: number()
44186
- });
44187
- /**
44188
44221
  * `oauth-integration` — a collection cap by which an addon declares
44189
44222
  * itself a linkable OAuth client of the hub's core `/oauth2/*` server.
44190
44223
  * Each provider returns a static descriptor; the core enumerates them
package/dist/addon.mjs CHANGED
@@ -7831,6 +7831,12 @@ function normalizeAddonInitResult(result) {
7831
7831
  if (Array.isArray(result)) return { providers: result };
7832
7832
  return result;
7833
7833
  }
7834
+ /**
7835
+ * The share-view scope kinds a `csv_*` share token can carry. The hub mints
7836
+ * and validates them (`share-token.service.ts` builds its enum from this
7837
+ * list); a data plane names the kinds it ACCEPTS in `share`.
7838
+ */
7839
+ var SHARE_VIEW_KINDS = ["grid-view", "events-view"];
7834
7840
  /** The wire shape of {@link PeerBytesTicket} — see the type for what it is. */
7835
7841
  var PeerBytesTicketSchema = object({
7836
7842
  /** `http://127.0.0.1:<port>/<token>`. One `GET` takes it. */
@@ -12496,6 +12502,229 @@ var ConvertResultSchema = object({
12496
12502
  files: array(string()).readonly()
12497
12503
  })).readonly()
12498
12504
  });
12505
+ /**
12506
+ * Zod schemas for persisted record types.
12507
+ *
12508
+ * These schemas serve as the single source of truth for types that are
12509
+ * stored in the settings-store backend and retrieved via tRPC. They
12510
+ * replace the manual TypeScript interfaces with schema-derived types,
12511
+ * enabling runtime validation when reading from the backend.
12512
+ *
12513
+ * Convention: each schema is named `<Type>Schema`, the inferred TS type
12514
+ * keeps the original name for backward compatibility.
12515
+ */
12516
+ /**
12517
+ * Auth model (v2 — 2026-05-12 caps-only):
12518
+ *
12519
+ * Two principals:
12520
+ * - `isAdmin: true` — full bypass. Admin scope set is ignored.
12521
+ * - `isAdmin: false` — every call gated by `scopes` (see TokenScope).
12522
+ *
12523
+ * No role enum. There used to be `viewer / agent / scoped` and earlier
12524
+ * `super_admin` — collapsed onto the single boolean because every
12525
+ * non-admin caller is governed by the same scope-check rules; the
12526
+ * distinction was only ever used to route role-specific procedures
12527
+ * which we no longer have. CLI / webhook integrations are `cst_*` tokens
12528
+ * with `isAdmin: false` + an explicit scope list.
12529
+ */
12530
+ /** Per-method access flavour. Materialised on every cap method via codegen. */
12531
+ var MethodAccessSchema = _enum([
12532
+ "view",
12533
+ "create",
12534
+ "delete"
12535
+ ]);
12536
+ /**
12537
+ * A single scope grant. Three forms — checked in matcher with OR
12538
+ * semantics; the first match decides whether the call passes:
12539
+ *
12540
+ * - `category` — broadest. `target: 'device' | 'system'` selects every
12541
+ * cap with the matching `scope` declaration. New caps inherit grants
12542
+ * automatically — adding a device cap to the codebase makes it
12543
+ * reachable to every user with `category:device [...]` without a
12544
+ * re-grant. Use this for "family viewer" / "operator" tiers.
12545
+ *
12546
+ * - `addon` — every cap that ships inside a given addon id. Niche;
12547
+ * useful when an integration needs to interact with one specific
12548
+ * addon's surface regardless of how many caps it exports.
12549
+ *
12550
+ * - `capability` — the most precise form. Single cap name. Use for
12551
+ * integration tokens where you want to grant `addons.installPackage`
12552
+ * and nothing else.
12553
+ *
12554
+ * `access` is REQUIRED with min 1 element. `admin` bypass is the
12555
+ * "give me everything" escape; there is no wildcard scope.
12556
+ */
12557
+ var AllowedProviderSchema = union([literal("*"), array(string())]);
12558
+ var AllowedDevicesSchema = record(string(), union([literal("*"), array(string())]));
12559
+ var CapScopeSchema = _enum(["device", "system"]);
12560
+ /**
12561
+ * DeviceSelector (scope model v3 — 2026-08-12).
12562
+ *
12563
+ * A `device` grant no longer carries a frozen list of deviceIds. It carries
12564
+ * a SELECTOR the matcher resolves against the live fleet, so the grant can be
12565
+ * DYNAMIC: a `types:['camera']` selector automatically covers a camera added
12566
+ * AFTER the grant was minted — no re-grant, no re-login.
12567
+ *
12568
+ * - `all` — every device in the deployment. The broad viewer/operator
12569
+ * lever without a `category` grant (a `category` grant also covers device
12570
+ * caps that carry no deviceId; `all` is specifically the device set).
12571
+ * - `ids` — an explicit deviceId list. This is what a v2 `device:[…]`
12572
+ * grant migrates to (see {@link TokenScopeSchema}); STATIC — a new camera
12573
+ * is NOT covered until the grant is edited.
12574
+ * - `types` — every device of a `DeviceType` (e.g. every `camera`).
12575
+ * DYNAMIC. A device that changes type, or a new device of the type,
12576
+ * re-resolves on the next request.
12577
+ * - `locations` — every device whose operator-assigned `location` label is
12578
+ * in the set (e.g. "Garden", "Front door"). DYNAMIC. A device with a
12579
+ * null/unset location matches NO `locations` selector.
12580
+ */
12581
+ var DeviceSelectorSchema = discriminatedUnion("kind", [
12582
+ object({ kind: literal("all") }),
12583
+ object({
12584
+ kind: literal("ids"),
12585
+ ids: array(number().int()).min(1)
12586
+ }),
12587
+ object({
12588
+ kind: literal("types"),
12589
+ types: array(_enum(DeviceType)).min(1)
12590
+ }),
12591
+ object({
12592
+ kind: literal("locations"),
12593
+ locations: array(string().min(1)).min(1)
12594
+ })
12595
+ ]);
12596
+ var DeviceTokenScopeSchema = object({
12597
+ type: literal("device"),
12598
+ /** The device SET this grant covers — resolved against the live fleet. */
12599
+ selector: DeviceSelectorSchema,
12600
+ access: array(MethodAccessSchema).min(1),
12601
+ /**
12602
+ * Whether a grant on a PARENT device transparently covers its accessory
12603
+ * CHILDREN (siren / floodlight / PIR) via the persisted-parentage walk.
12604
+ * Direction is parent → children ONLY.
12605
+ *
12606
+ * Absent → the matcher DERIVES it from the access flavour: `view`
12607
+ * inherits (a camera viewer sees the camera's accessories), `create` /
12608
+ * `delete` do NOT (actuating/removing a child is an explicit act the
12609
+ * operator must grant on the child, not inherit from the parent). Set it
12610
+ * explicitly to override that default per grant.
12611
+ */
12612
+ includeLinked: boolean().optional()
12613
+ });
12614
+ /**
12615
+ * v2 → v3 lazy migration. A pre-v3 `device` grant carried
12616
+ * `targets: string[]` (stringified deviceIds); it rewrites to the equivalent
12617
+ * `selector: {kind:'ids', ids}`. Applied as a `preprocess` so it runs on
12618
+ * EVERY parse path — stored records AND the JWT-carried scope arrays
12619
+ * normalised at the request boundary ({@link normalizeTokenScopes} in
12620
+ * `device-selector.ts`). Chosen over a one-time DB migration because a
12621
+ * migration cannot reach a JWT already in a client's hands; parse-time
12622
+ * migration covers both without a flag day. No cast — the raw object is read
12623
+ * through `Reflect.get` (its static type is `unknown`).
12624
+ */
12625
+ function migrateLegacyTokenScope(raw) {
12626
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return raw;
12627
+ if (Reflect.get(raw, "type") !== "device") return raw;
12628
+ if (Reflect.get(raw, "selector") !== void 0) return raw;
12629
+ const targets = Reflect.get(raw, "targets");
12630
+ if (!Array.isArray(targets)) return raw;
12631
+ return {
12632
+ type: "device",
12633
+ selector: {
12634
+ kind: "ids",
12635
+ ids: targets.map((t) => typeof t === "string" ? Number(t) : t).filter((n) => typeof n === "number" && Number.isInteger(n))
12636
+ },
12637
+ access: Reflect.get(raw, "access")
12638
+ };
12639
+ }
12640
+ var TokenScopeSchema = preprocess(migrateLegacyTokenScope, discriminatedUnion("type", [
12641
+ object({
12642
+ type: literal("category"),
12643
+ target: CapScopeSchema,
12644
+ access: array(MethodAccessSchema).min(1)
12645
+ }),
12646
+ object({
12647
+ type: literal("capability"),
12648
+ target: string(),
12649
+ access: array(MethodAccessSchema).min(1)
12650
+ }),
12651
+ object({
12652
+ type: literal("addon"),
12653
+ target: string(),
12654
+ access: array(MethodAccessSchema).min(1)
12655
+ }),
12656
+ DeviceTokenScopeSchema
12657
+ ]));
12658
+ object({
12659
+ id: string(),
12660
+ username: string(),
12661
+ passwordHash: string(),
12662
+ /**
12663
+ * Admin bypass. When true, the middleware skips the scope-access
12664
+ * check entirely. There is no other axis of privilege; the legacy
12665
+ * role enum collapsed onto this boolean in v2.
12666
+ */
12667
+ isAdmin: boolean().default(false),
12668
+ allowedProviders: AllowedProviderSchema,
12669
+ allowedDevices: AllowedDevicesSchema,
12670
+ /**
12671
+ * Scopes granted to this user. Admins bypass; their `scopes` is
12672
+ * ignored. Non-admins without scopes are locked out of every
12673
+ * protected call.
12674
+ */
12675
+ scopes: array(TokenScopeSchema).default([]),
12676
+ createdAt: number(),
12677
+ updatedAt: number()
12678
+ });
12679
+ object({
12680
+ id: string(),
12681
+ label: string(),
12682
+ isAdmin: boolean().default(false),
12683
+ allowedProviders: AllowedProviderSchema,
12684
+ allowedDevices: AllowedDevicesSchema,
12685
+ tokenHash: string(),
12686
+ tokenPrefix: string(),
12687
+ createdAt: number(),
12688
+ lastUsedAt: number().optional()
12689
+ });
12690
+ object({
12691
+ id: string(),
12692
+ userId: string(),
12693
+ name: string(),
12694
+ tokenHash: string(),
12695
+ tokenPrefix: string(),
12696
+ scopes: array(TokenScopeSchema),
12697
+ expiresAt: number().nullish(),
12698
+ lastUsedAt: number().nullish(),
12699
+ createdAt: number()
12700
+ });
12701
+ /** What a share-view grant lets its holder see. */
12702
+ var ShareViewGrantSchema = object({
12703
+ kind: _enum(SHARE_VIEW_KINDS),
12704
+ deviceIds: array(number().int().nonnegative()).min(1).max(64),
12705
+ /** Talk-back, opt-in at mint time; absent means off. */
12706
+ talk: boolean().optional()
12707
+ });
12708
+ var ShareViewScopeSchema = object({
12709
+ type: literal("share-view"),
12710
+ grant: ShareViewGrantSchema
12711
+ });
12712
+ var AddonRoutesScopeSchema = object({
12713
+ type: literal("addon-routes"),
12714
+ access: array(MethodAccessSchema).min(1)
12715
+ });
12716
+ var CredentialScopeSchema = union([
12717
+ literal("*"),
12718
+ ShareViewScopeSchema,
12719
+ AddonRoutesScopeSchema,
12720
+ TokenScopeSchema
12721
+ ]);
12722
+ object({
12723
+ kind: literal("credential"),
12724
+ sub: string().min(1),
12725
+ jti: string().min(16),
12726
+ scopes: array(CredentialScopeSchema).min(1)
12727
+ });
12499
12728
  _enum(["new-session", "step-up"]);
12500
12729
  /** The languages the hub's app landing pages are written in (D858). */
12501
12730
  var AppPageLangSchema = _enum(["en", "it"]);
@@ -43990,202 +44219,6 @@ method(object({}), object({ rules: array(NcRuleSchema) }), { auth: "admin" }), m
43990
44219
  auth: "admin"
43991
44220
  }), method(NcAlarmSensorsInputSchema, NcAlarmSensorsSchema, { auth: "admin" });
43992
44221
  /**
43993
- * Zod schemas for persisted record types.
43994
- *
43995
- * These schemas serve as the single source of truth for types that are
43996
- * stored in the settings-store backend and retrieved via tRPC. They
43997
- * replace the manual TypeScript interfaces with schema-derived types,
43998
- * enabling runtime validation when reading from the backend.
43999
- *
44000
- * Convention: each schema is named `<Type>Schema`, the inferred TS type
44001
- * keeps the original name for backward compatibility.
44002
- */
44003
- /**
44004
- * Auth model (v2 — 2026-05-12 caps-only):
44005
- *
44006
- * Two principals:
44007
- * - `isAdmin: true` — full bypass. Admin scope set is ignored.
44008
- * - `isAdmin: false` — every call gated by `scopes` (see TokenScope).
44009
- *
44010
- * No role enum. There used to be `viewer / agent / scoped` and earlier
44011
- * `super_admin` — collapsed onto the single boolean because every
44012
- * non-admin caller is governed by the same scope-check rules; the
44013
- * distinction was only ever used to route role-specific procedures
44014
- * which we no longer have. CLI / webhook integrations are `cst_*` tokens
44015
- * with `isAdmin: false` + an explicit scope list.
44016
- */
44017
- /** Per-method access flavour. Materialised on every cap method via codegen. */
44018
- var MethodAccessSchema = _enum([
44019
- "view",
44020
- "create",
44021
- "delete"
44022
- ]);
44023
- /**
44024
- * A single scope grant. Three forms — checked in matcher with OR
44025
- * semantics; the first match decides whether the call passes:
44026
- *
44027
- * - `category` — broadest. `target: 'device' | 'system'` selects every
44028
- * cap with the matching `scope` declaration. New caps inherit grants
44029
- * automatically — adding a device cap to the codebase makes it
44030
- * reachable to every user with `category:device [...]` without a
44031
- * re-grant. Use this for "family viewer" / "operator" tiers.
44032
- *
44033
- * - `addon` — every cap that ships inside a given addon id. Niche;
44034
- * useful when an integration needs to interact with one specific
44035
- * addon's surface regardless of how many caps it exports.
44036
- *
44037
- * - `capability` — the most precise form. Single cap name. Use for
44038
- * integration tokens where you want to grant `addons.installPackage`
44039
- * and nothing else.
44040
- *
44041
- * `access` is REQUIRED with min 1 element. `admin` bypass is the
44042
- * "give me everything" escape; there is no wildcard scope.
44043
- */
44044
- var AllowedProviderSchema = union([literal("*"), array(string())]);
44045
- var AllowedDevicesSchema = record(string(), union([literal("*"), array(string())]));
44046
- var CapScopeSchema = _enum(["device", "system"]);
44047
- /**
44048
- * DeviceSelector (scope model v3 — 2026-08-12).
44049
- *
44050
- * A `device` grant no longer carries a frozen list of deviceIds. It carries
44051
- * a SELECTOR the matcher resolves against the live fleet, so the grant can be
44052
- * DYNAMIC: a `types:['camera']` selector automatically covers a camera added
44053
- * AFTER the grant was minted — no re-grant, no re-login.
44054
- *
44055
- * - `all` — every device in the deployment. The broad viewer/operator
44056
- * lever without a `category` grant (a `category` grant also covers device
44057
- * caps that carry no deviceId; `all` is specifically the device set).
44058
- * - `ids` — an explicit deviceId list. This is what a v2 `device:[…]`
44059
- * grant migrates to (see {@link TokenScopeSchema}); STATIC — a new camera
44060
- * is NOT covered until the grant is edited.
44061
- * - `types` — every device of a `DeviceType` (e.g. every `camera`).
44062
- * DYNAMIC. A device that changes type, or a new device of the type,
44063
- * re-resolves on the next request.
44064
- * - `locations` — every device whose operator-assigned `location` label is
44065
- * in the set (e.g. "Garden", "Front door"). DYNAMIC. A device with a
44066
- * null/unset location matches NO `locations` selector.
44067
- */
44068
- var DeviceSelectorSchema = discriminatedUnion("kind", [
44069
- object({ kind: literal("all") }),
44070
- object({
44071
- kind: literal("ids"),
44072
- ids: array(number().int()).min(1)
44073
- }),
44074
- object({
44075
- kind: literal("types"),
44076
- types: array(_enum(DeviceType)).min(1)
44077
- }),
44078
- object({
44079
- kind: literal("locations"),
44080
- locations: array(string().min(1)).min(1)
44081
- })
44082
- ]);
44083
- var DeviceTokenScopeSchema = object({
44084
- type: literal("device"),
44085
- /** The device SET this grant covers — resolved against the live fleet. */
44086
- selector: DeviceSelectorSchema,
44087
- access: array(MethodAccessSchema).min(1),
44088
- /**
44089
- * Whether a grant on a PARENT device transparently covers its accessory
44090
- * CHILDREN (siren / floodlight / PIR) via the persisted-parentage walk.
44091
- * Direction is parent → children ONLY.
44092
- *
44093
- * Absent → the matcher DERIVES it from the access flavour: `view`
44094
- * inherits (a camera viewer sees the camera's accessories), `create` /
44095
- * `delete` do NOT (actuating/removing a child is an explicit act the
44096
- * operator must grant on the child, not inherit from the parent). Set it
44097
- * explicitly to override that default per grant.
44098
- */
44099
- includeLinked: boolean().optional()
44100
- });
44101
- /**
44102
- * v2 → v3 lazy migration. A pre-v3 `device` grant carried
44103
- * `targets: string[]` (stringified deviceIds); it rewrites to the equivalent
44104
- * `selector: {kind:'ids', ids}`. Applied as a `preprocess` so it runs on
44105
- * EVERY parse path — stored records AND the JWT-carried scope arrays
44106
- * normalised at the request boundary ({@link normalizeTokenScopes} in
44107
- * `device-selector.ts`). Chosen over a one-time DB migration because a
44108
- * migration cannot reach a JWT already in a client's hands; parse-time
44109
- * migration covers both without a flag day. No cast — the raw object is read
44110
- * through `Reflect.get` (its static type is `unknown`).
44111
- */
44112
- function migrateLegacyTokenScope(raw) {
44113
- if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return raw;
44114
- if (Reflect.get(raw, "type") !== "device") return raw;
44115
- if (Reflect.get(raw, "selector") !== void 0) return raw;
44116
- const targets = Reflect.get(raw, "targets");
44117
- if (!Array.isArray(targets)) return raw;
44118
- return {
44119
- type: "device",
44120
- selector: {
44121
- kind: "ids",
44122
- ids: targets.map((t) => typeof t === "string" ? Number(t) : t).filter((n) => typeof n === "number" && Number.isInteger(n))
44123
- },
44124
- access: Reflect.get(raw, "access")
44125
- };
44126
- }
44127
- var TokenScopeSchema = preprocess(migrateLegacyTokenScope, discriminatedUnion("type", [
44128
- object({
44129
- type: literal("category"),
44130
- target: CapScopeSchema,
44131
- access: array(MethodAccessSchema).min(1)
44132
- }),
44133
- object({
44134
- type: literal("capability"),
44135
- target: string(),
44136
- access: array(MethodAccessSchema).min(1)
44137
- }),
44138
- object({
44139
- type: literal("addon"),
44140
- target: string(),
44141
- access: array(MethodAccessSchema).min(1)
44142
- }),
44143
- DeviceTokenScopeSchema
44144
- ]));
44145
- object({
44146
- id: string(),
44147
- username: string(),
44148
- passwordHash: string(),
44149
- /**
44150
- * Admin bypass. When true, the middleware skips the scope-access
44151
- * check entirely. There is no other axis of privilege; the legacy
44152
- * role enum collapsed onto this boolean in v2.
44153
- */
44154
- isAdmin: boolean().default(false),
44155
- allowedProviders: AllowedProviderSchema,
44156
- allowedDevices: AllowedDevicesSchema,
44157
- /**
44158
- * Scopes granted to this user. Admins bypass; their `scopes` is
44159
- * ignored. Non-admins without scopes are locked out of every
44160
- * protected call.
44161
- */
44162
- scopes: array(TokenScopeSchema).default([]),
44163
- createdAt: number(),
44164
- updatedAt: number()
44165
- });
44166
- object({
44167
- id: string(),
44168
- label: string(),
44169
- isAdmin: boolean().default(false),
44170
- allowedProviders: AllowedProviderSchema,
44171
- allowedDevices: AllowedDevicesSchema,
44172
- tokenHash: string(),
44173
- tokenPrefix: string(),
44174
- createdAt: number(),
44175
- lastUsedAt: number().optional()
44176
- });
44177
- object({
44178
- id: string(),
44179
- userId: string(),
44180
- name: string(),
44181
- tokenHash: string(),
44182
- tokenPrefix: string(),
44183
- scopes: array(TokenScopeSchema),
44184
- expiresAt: number().nullish(),
44185
- lastUsedAt: number().nullish(),
44186
- createdAt: number()
44187
- });
44188
- /**
44189
44222
  * `oauth-integration` — a collection cap by which an addon declares
44190
44223
  * itself a linkable OAuth client of the hub's core `/oauth2/*` server.
44191
44224
  * Each provider returns a static descriptor; the core enumerates them
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/addon-provider-mqtt-ha",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Home Assistant MQTT discovery import provider for CamStack — adopts entities published on homeassistant/+/+/config",
5
5
  "keywords": [
6
6
  "camstack",