@camstack/addon-provider-homematic 1.2.139 → 1.2.140
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 +229 -196
- package/dist/addon.mjs +229 -196
- package/package.json +1 -1
package/dist/addon.js
CHANGED
|
@@ -7938,6 +7938,12 @@ function normalizeAddonInitResult(result) {
|
|
|
7938
7938
|
if (Array.isArray(result)) return { providers: result };
|
|
7939
7939
|
return result;
|
|
7940
7940
|
}
|
|
7941
|
+
/**
|
|
7942
|
+
* The share-view scope kinds a `csv_*` share token can carry. The hub mints
|
|
7943
|
+
* and validates them (`share-token.service.ts` builds its enum from this
|
|
7944
|
+
* list); a data plane names the kinds it ACCEPTS in `share`.
|
|
7945
|
+
*/
|
|
7946
|
+
var SHARE_VIEW_KINDS = ["grid-view", "events-view"];
|
|
7941
7947
|
/** The wire shape of {@link PeerBytesTicket} — see the type for what it is. */
|
|
7942
7948
|
var PeerBytesTicketSchema = object({
|
|
7943
7949
|
/** `http://127.0.0.1:<port>/<token>`. One `GET` takes it. */
|
|
@@ -12803,6 +12809,229 @@ var ConvertResultSchema = object({
|
|
|
12803
12809
|
files: array(string()).readonly()
|
|
12804
12810
|
})).readonly()
|
|
12805
12811
|
});
|
|
12812
|
+
/**
|
|
12813
|
+
* Zod schemas for persisted record types.
|
|
12814
|
+
*
|
|
12815
|
+
* These schemas serve as the single source of truth for types that are
|
|
12816
|
+
* stored in the settings-store backend and retrieved via tRPC. They
|
|
12817
|
+
* replace the manual TypeScript interfaces with schema-derived types,
|
|
12818
|
+
* enabling runtime validation when reading from the backend.
|
|
12819
|
+
*
|
|
12820
|
+
* Convention: each schema is named `<Type>Schema`, the inferred TS type
|
|
12821
|
+
* keeps the original name for backward compatibility.
|
|
12822
|
+
*/
|
|
12823
|
+
/**
|
|
12824
|
+
* Auth model (v2 — 2026-05-12 caps-only):
|
|
12825
|
+
*
|
|
12826
|
+
* Two principals:
|
|
12827
|
+
* - `isAdmin: true` — full bypass. Admin scope set is ignored.
|
|
12828
|
+
* - `isAdmin: false` — every call gated by `scopes` (see TokenScope).
|
|
12829
|
+
*
|
|
12830
|
+
* No role enum. There used to be `viewer / agent / scoped` and earlier
|
|
12831
|
+
* `super_admin` — collapsed onto the single boolean because every
|
|
12832
|
+
* non-admin caller is governed by the same scope-check rules; the
|
|
12833
|
+
* distinction was only ever used to route role-specific procedures
|
|
12834
|
+
* which we no longer have. CLI / webhook integrations are `cst_*` tokens
|
|
12835
|
+
* with `isAdmin: false` + an explicit scope list.
|
|
12836
|
+
*/
|
|
12837
|
+
/** Per-method access flavour. Materialised on every cap method via codegen. */
|
|
12838
|
+
var MethodAccessSchema = _enum([
|
|
12839
|
+
"view",
|
|
12840
|
+
"create",
|
|
12841
|
+
"delete"
|
|
12842
|
+
]);
|
|
12843
|
+
/**
|
|
12844
|
+
* A single scope grant. Three forms — checked in matcher with OR
|
|
12845
|
+
* semantics; the first match decides whether the call passes:
|
|
12846
|
+
*
|
|
12847
|
+
* - `category` — broadest. `target: 'device' | 'system'` selects every
|
|
12848
|
+
* cap with the matching `scope` declaration. New caps inherit grants
|
|
12849
|
+
* automatically — adding a device cap to the codebase makes it
|
|
12850
|
+
* reachable to every user with `category:device [...]` without a
|
|
12851
|
+
* re-grant. Use this for "family viewer" / "operator" tiers.
|
|
12852
|
+
*
|
|
12853
|
+
* - `addon` — every cap that ships inside a given addon id. Niche;
|
|
12854
|
+
* useful when an integration needs to interact with one specific
|
|
12855
|
+
* addon's surface regardless of how many caps it exports.
|
|
12856
|
+
*
|
|
12857
|
+
* - `capability` — the most precise form. Single cap name. Use for
|
|
12858
|
+
* integration tokens where you want to grant `addons.installPackage`
|
|
12859
|
+
* and nothing else.
|
|
12860
|
+
*
|
|
12861
|
+
* `access` is REQUIRED with min 1 element. `admin` bypass is the
|
|
12862
|
+
* "give me everything" escape; there is no wildcard scope.
|
|
12863
|
+
*/
|
|
12864
|
+
var AllowedProviderSchema = union([literal("*"), array(string())]);
|
|
12865
|
+
var AllowedDevicesSchema = record(string(), union([literal("*"), array(string())]));
|
|
12866
|
+
var CapScopeSchema = _enum(["device", "system"]);
|
|
12867
|
+
/**
|
|
12868
|
+
* DeviceSelector (scope model v3 — 2026-08-12).
|
|
12869
|
+
*
|
|
12870
|
+
* A `device` grant no longer carries a frozen list of deviceIds. It carries
|
|
12871
|
+
* a SELECTOR the matcher resolves against the live fleet, so the grant can be
|
|
12872
|
+
* DYNAMIC: a `types:['camera']` selector automatically covers a camera added
|
|
12873
|
+
* AFTER the grant was minted — no re-grant, no re-login.
|
|
12874
|
+
*
|
|
12875
|
+
* - `all` — every device in the deployment. The broad viewer/operator
|
|
12876
|
+
* lever without a `category` grant (a `category` grant also covers device
|
|
12877
|
+
* caps that carry no deviceId; `all` is specifically the device set).
|
|
12878
|
+
* - `ids` — an explicit deviceId list. This is what a v2 `device:[…]`
|
|
12879
|
+
* grant migrates to (see {@link TokenScopeSchema}); STATIC — a new camera
|
|
12880
|
+
* is NOT covered until the grant is edited.
|
|
12881
|
+
* - `types` — every device of a `DeviceType` (e.g. every `camera`).
|
|
12882
|
+
* DYNAMIC. A device that changes type, or a new device of the type,
|
|
12883
|
+
* re-resolves on the next request.
|
|
12884
|
+
* - `locations` — every device whose operator-assigned `location` label is
|
|
12885
|
+
* in the set (e.g. "Garden", "Front door"). DYNAMIC. A device with a
|
|
12886
|
+
* null/unset location matches NO `locations` selector.
|
|
12887
|
+
*/
|
|
12888
|
+
var DeviceSelectorSchema = discriminatedUnion("kind", [
|
|
12889
|
+
object({ kind: literal("all") }),
|
|
12890
|
+
object({
|
|
12891
|
+
kind: literal("ids"),
|
|
12892
|
+
ids: array(number().int()).min(1)
|
|
12893
|
+
}),
|
|
12894
|
+
object({
|
|
12895
|
+
kind: literal("types"),
|
|
12896
|
+
types: array(_enum(DeviceType)).min(1)
|
|
12897
|
+
}),
|
|
12898
|
+
object({
|
|
12899
|
+
kind: literal("locations"),
|
|
12900
|
+
locations: array(string().min(1)).min(1)
|
|
12901
|
+
})
|
|
12902
|
+
]);
|
|
12903
|
+
var DeviceTokenScopeSchema = object({
|
|
12904
|
+
type: literal("device"),
|
|
12905
|
+
/** The device SET this grant covers — resolved against the live fleet. */
|
|
12906
|
+
selector: DeviceSelectorSchema,
|
|
12907
|
+
access: array(MethodAccessSchema).min(1),
|
|
12908
|
+
/**
|
|
12909
|
+
* Whether a grant on a PARENT device transparently covers its accessory
|
|
12910
|
+
* CHILDREN (siren / floodlight / PIR) via the persisted-parentage walk.
|
|
12911
|
+
* Direction is parent → children ONLY.
|
|
12912
|
+
*
|
|
12913
|
+
* Absent → the matcher DERIVES it from the access flavour: `view`
|
|
12914
|
+
* inherits (a camera viewer sees the camera's accessories), `create` /
|
|
12915
|
+
* `delete` do NOT (actuating/removing a child is an explicit act the
|
|
12916
|
+
* operator must grant on the child, not inherit from the parent). Set it
|
|
12917
|
+
* explicitly to override that default per grant.
|
|
12918
|
+
*/
|
|
12919
|
+
includeLinked: boolean().optional()
|
|
12920
|
+
});
|
|
12921
|
+
/**
|
|
12922
|
+
* v2 → v3 lazy migration. A pre-v3 `device` grant carried
|
|
12923
|
+
* `targets: string[]` (stringified deviceIds); it rewrites to the equivalent
|
|
12924
|
+
* `selector: {kind:'ids', ids}`. Applied as a `preprocess` so it runs on
|
|
12925
|
+
* EVERY parse path — stored records AND the JWT-carried scope arrays
|
|
12926
|
+
* normalised at the request boundary ({@link normalizeTokenScopes} in
|
|
12927
|
+
* `device-selector.ts`). Chosen over a one-time DB migration because a
|
|
12928
|
+
* migration cannot reach a JWT already in a client's hands; parse-time
|
|
12929
|
+
* migration covers both without a flag day. No cast — the raw object is read
|
|
12930
|
+
* through `Reflect.get` (its static type is `unknown`).
|
|
12931
|
+
*/
|
|
12932
|
+
function migrateLegacyTokenScope(raw) {
|
|
12933
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return raw;
|
|
12934
|
+
if (Reflect.get(raw, "type") !== "device") return raw;
|
|
12935
|
+
if (Reflect.get(raw, "selector") !== void 0) return raw;
|
|
12936
|
+
const targets = Reflect.get(raw, "targets");
|
|
12937
|
+
if (!Array.isArray(targets)) return raw;
|
|
12938
|
+
return {
|
|
12939
|
+
type: "device",
|
|
12940
|
+
selector: {
|
|
12941
|
+
kind: "ids",
|
|
12942
|
+
ids: targets.map((t) => typeof t === "string" ? Number(t) : t).filter((n) => typeof n === "number" && Number.isInteger(n))
|
|
12943
|
+
},
|
|
12944
|
+
access: Reflect.get(raw, "access")
|
|
12945
|
+
};
|
|
12946
|
+
}
|
|
12947
|
+
var TokenScopeSchema = preprocess(migrateLegacyTokenScope, discriminatedUnion("type", [
|
|
12948
|
+
object({
|
|
12949
|
+
type: literal("category"),
|
|
12950
|
+
target: CapScopeSchema,
|
|
12951
|
+
access: array(MethodAccessSchema).min(1)
|
|
12952
|
+
}),
|
|
12953
|
+
object({
|
|
12954
|
+
type: literal("capability"),
|
|
12955
|
+
target: string(),
|
|
12956
|
+
access: array(MethodAccessSchema).min(1)
|
|
12957
|
+
}),
|
|
12958
|
+
object({
|
|
12959
|
+
type: literal("addon"),
|
|
12960
|
+
target: string(),
|
|
12961
|
+
access: array(MethodAccessSchema).min(1)
|
|
12962
|
+
}),
|
|
12963
|
+
DeviceTokenScopeSchema
|
|
12964
|
+
]));
|
|
12965
|
+
object({
|
|
12966
|
+
id: string(),
|
|
12967
|
+
username: string(),
|
|
12968
|
+
passwordHash: string(),
|
|
12969
|
+
/**
|
|
12970
|
+
* Admin bypass. When true, the middleware skips the scope-access
|
|
12971
|
+
* check entirely. There is no other axis of privilege; the legacy
|
|
12972
|
+
* role enum collapsed onto this boolean in v2.
|
|
12973
|
+
*/
|
|
12974
|
+
isAdmin: boolean().default(false),
|
|
12975
|
+
allowedProviders: AllowedProviderSchema,
|
|
12976
|
+
allowedDevices: AllowedDevicesSchema,
|
|
12977
|
+
/**
|
|
12978
|
+
* Scopes granted to this user. Admins bypass; their `scopes` is
|
|
12979
|
+
* ignored. Non-admins without scopes are locked out of every
|
|
12980
|
+
* protected call.
|
|
12981
|
+
*/
|
|
12982
|
+
scopes: array(TokenScopeSchema).default([]),
|
|
12983
|
+
createdAt: number(),
|
|
12984
|
+
updatedAt: number()
|
|
12985
|
+
});
|
|
12986
|
+
object({
|
|
12987
|
+
id: string(),
|
|
12988
|
+
label: string(),
|
|
12989
|
+
isAdmin: boolean().default(false),
|
|
12990
|
+
allowedProviders: AllowedProviderSchema,
|
|
12991
|
+
allowedDevices: AllowedDevicesSchema,
|
|
12992
|
+
tokenHash: string(),
|
|
12993
|
+
tokenPrefix: string(),
|
|
12994
|
+
createdAt: number(),
|
|
12995
|
+
lastUsedAt: number().optional()
|
|
12996
|
+
});
|
|
12997
|
+
object({
|
|
12998
|
+
id: string(),
|
|
12999
|
+
userId: string(),
|
|
13000
|
+
name: string(),
|
|
13001
|
+
tokenHash: string(),
|
|
13002
|
+
tokenPrefix: string(),
|
|
13003
|
+
scopes: array(TokenScopeSchema),
|
|
13004
|
+
expiresAt: number().nullish(),
|
|
13005
|
+
lastUsedAt: number().nullish(),
|
|
13006
|
+
createdAt: number()
|
|
13007
|
+
});
|
|
13008
|
+
/** What a share-view grant lets its holder see. */
|
|
13009
|
+
var ShareViewGrantSchema = object({
|
|
13010
|
+
kind: _enum(SHARE_VIEW_KINDS),
|
|
13011
|
+
deviceIds: array(number().int().nonnegative()).min(1).max(64),
|
|
13012
|
+
/** Talk-back, opt-in at mint time; absent means off. */
|
|
13013
|
+
talk: boolean().optional()
|
|
13014
|
+
});
|
|
13015
|
+
var ShareViewScopeSchema = object({
|
|
13016
|
+
type: literal("share-view"),
|
|
13017
|
+
grant: ShareViewGrantSchema
|
|
13018
|
+
});
|
|
13019
|
+
var AddonRoutesScopeSchema = object({
|
|
13020
|
+
type: literal("addon-routes"),
|
|
13021
|
+
access: array(MethodAccessSchema).min(1)
|
|
13022
|
+
});
|
|
13023
|
+
var CredentialScopeSchema = union([
|
|
13024
|
+
literal("*"),
|
|
13025
|
+
ShareViewScopeSchema,
|
|
13026
|
+
AddonRoutesScopeSchema,
|
|
13027
|
+
TokenScopeSchema
|
|
13028
|
+
]);
|
|
13029
|
+
object({
|
|
13030
|
+
kind: literal("credential"),
|
|
13031
|
+
sub: string().min(1),
|
|
13032
|
+
jti: string().min(16),
|
|
13033
|
+
scopes: array(CredentialScopeSchema).min(1)
|
|
13034
|
+
});
|
|
12806
13035
|
_enum(["new-session", "step-up"]);
|
|
12807
13036
|
/** The languages the hub's app landing pages are written in (D858). */
|
|
12808
13037
|
var AppPageLangSchema = _enum(["en", "it"]);
|
|
@@ -44459,202 +44688,6 @@ method(object({}), object({ rules: array(NcRuleSchema) }), { auth: "admin" }), m
|
|
|
44459
44688
|
auth: "admin"
|
|
44460
44689
|
}), method(NcAlarmSensorsInputSchema, NcAlarmSensorsSchema, { auth: "admin" });
|
|
44461
44690
|
/**
|
|
44462
|
-
* Zod schemas for persisted record types.
|
|
44463
|
-
*
|
|
44464
|
-
* These schemas serve as the single source of truth for types that are
|
|
44465
|
-
* stored in the settings-store backend and retrieved via tRPC. They
|
|
44466
|
-
* replace the manual TypeScript interfaces with schema-derived types,
|
|
44467
|
-
* enabling runtime validation when reading from the backend.
|
|
44468
|
-
*
|
|
44469
|
-
* Convention: each schema is named `<Type>Schema`, the inferred TS type
|
|
44470
|
-
* keeps the original name for backward compatibility.
|
|
44471
|
-
*/
|
|
44472
|
-
/**
|
|
44473
|
-
* Auth model (v2 — 2026-05-12 caps-only):
|
|
44474
|
-
*
|
|
44475
|
-
* Two principals:
|
|
44476
|
-
* - `isAdmin: true` — full bypass. Admin scope set is ignored.
|
|
44477
|
-
* - `isAdmin: false` — every call gated by `scopes` (see TokenScope).
|
|
44478
|
-
*
|
|
44479
|
-
* No role enum. There used to be `viewer / agent / scoped` and earlier
|
|
44480
|
-
* `super_admin` — collapsed onto the single boolean because every
|
|
44481
|
-
* non-admin caller is governed by the same scope-check rules; the
|
|
44482
|
-
* distinction was only ever used to route role-specific procedures
|
|
44483
|
-
* which we no longer have. CLI / webhook integrations are `cst_*` tokens
|
|
44484
|
-
* with `isAdmin: false` + an explicit scope list.
|
|
44485
|
-
*/
|
|
44486
|
-
/** Per-method access flavour. Materialised on every cap method via codegen. */
|
|
44487
|
-
var MethodAccessSchema = _enum([
|
|
44488
|
-
"view",
|
|
44489
|
-
"create",
|
|
44490
|
-
"delete"
|
|
44491
|
-
]);
|
|
44492
|
-
/**
|
|
44493
|
-
* A single scope grant. Three forms — checked in matcher with OR
|
|
44494
|
-
* semantics; the first match decides whether the call passes:
|
|
44495
|
-
*
|
|
44496
|
-
* - `category` — broadest. `target: 'device' | 'system'` selects every
|
|
44497
|
-
* cap with the matching `scope` declaration. New caps inherit grants
|
|
44498
|
-
* automatically — adding a device cap to the codebase makes it
|
|
44499
|
-
* reachable to every user with `category:device [...]` without a
|
|
44500
|
-
* re-grant. Use this for "family viewer" / "operator" tiers.
|
|
44501
|
-
*
|
|
44502
|
-
* - `addon` — every cap that ships inside a given addon id. Niche;
|
|
44503
|
-
* useful when an integration needs to interact with one specific
|
|
44504
|
-
* addon's surface regardless of how many caps it exports.
|
|
44505
|
-
*
|
|
44506
|
-
* - `capability` — the most precise form. Single cap name. Use for
|
|
44507
|
-
* integration tokens where you want to grant `addons.installPackage`
|
|
44508
|
-
* and nothing else.
|
|
44509
|
-
*
|
|
44510
|
-
* `access` is REQUIRED with min 1 element. `admin` bypass is the
|
|
44511
|
-
* "give me everything" escape; there is no wildcard scope.
|
|
44512
|
-
*/
|
|
44513
|
-
var AllowedProviderSchema = union([literal("*"), array(string())]);
|
|
44514
|
-
var AllowedDevicesSchema = record(string(), union([literal("*"), array(string())]));
|
|
44515
|
-
var CapScopeSchema = _enum(["device", "system"]);
|
|
44516
|
-
/**
|
|
44517
|
-
* DeviceSelector (scope model v3 — 2026-08-12).
|
|
44518
|
-
*
|
|
44519
|
-
* A `device` grant no longer carries a frozen list of deviceIds. It carries
|
|
44520
|
-
* a SELECTOR the matcher resolves against the live fleet, so the grant can be
|
|
44521
|
-
* DYNAMIC: a `types:['camera']` selector automatically covers a camera added
|
|
44522
|
-
* AFTER the grant was minted — no re-grant, no re-login.
|
|
44523
|
-
*
|
|
44524
|
-
* - `all` — every device in the deployment. The broad viewer/operator
|
|
44525
|
-
* lever without a `category` grant (a `category` grant also covers device
|
|
44526
|
-
* caps that carry no deviceId; `all` is specifically the device set).
|
|
44527
|
-
* - `ids` — an explicit deviceId list. This is what a v2 `device:[…]`
|
|
44528
|
-
* grant migrates to (see {@link TokenScopeSchema}); STATIC — a new camera
|
|
44529
|
-
* is NOT covered until the grant is edited.
|
|
44530
|
-
* - `types` — every device of a `DeviceType` (e.g. every `camera`).
|
|
44531
|
-
* DYNAMIC. A device that changes type, or a new device of the type,
|
|
44532
|
-
* re-resolves on the next request.
|
|
44533
|
-
* - `locations` — every device whose operator-assigned `location` label is
|
|
44534
|
-
* in the set (e.g. "Garden", "Front door"). DYNAMIC. A device with a
|
|
44535
|
-
* null/unset location matches NO `locations` selector.
|
|
44536
|
-
*/
|
|
44537
|
-
var DeviceSelectorSchema = discriminatedUnion("kind", [
|
|
44538
|
-
object({ kind: literal("all") }),
|
|
44539
|
-
object({
|
|
44540
|
-
kind: literal("ids"),
|
|
44541
|
-
ids: array(number().int()).min(1)
|
|
44542
|
-
}),
|
|
44543
|
-
object({
|
|
44544
|
-
kind: literal("types"),
|
|
44545
|
-
types: array(_enum(DeviceType)).min(1)
|
|
44546
|
-
}),
|
|
44547
|
-
object({
|
|
44548
|
-
kind: literal("locations"),
|
|
44549
|
-
locations: array(string().min(1)).min(1)
|
|
44550
|
-
})
|
|
44551
|
-
]);
|
|
44552
|
-
var DeviceTokenScopeSchema = object({
|
|
44553
|
-
type: literal("device"),
|
|
44554
|
-
/** The device SET this grant covers — resolved against the live fleet. */
|
|
44555
|
-
selector: DeviceSelectorSchema,
|
|
44556
|
-
access: array(MethodAccessSchema).min(1),
|
|
44557
|
-
/**
|
|
44558
|
-
* Whether a grant on a PARENT device transparently covers its accessory
|
|
44559
|
-
* CHILDREN (siren / floodlight / PIR) via the persisted-parentage walk.
|
|
44560
|
-
* Direction is parent → children ONLY.
|
|
44561
|
-
*
|
|
44562
|
-
* Absent → the matcher DERIVES it from the access flavour: `view`
|
|
44563
|
-
* inherits (a camera viewer sees the camera's accessories), `create` /
|
|
44564
|
-
* `delete` do NOT (actuating/removing a child is an explicit act the
|
|
44565
|
-
* operator must grant on the child, not inherit from the parent). Set it
|
|
44566
|
-
* explicitly to override that default per grant.
|
|
44567
|
-
*/
|
|
44568
|
-
includeLinked: boolean().optional()
|
|
44569
|
-
});
|
|
44570
|
-
/**
|
|
44571
|
-
* v2 → v3 lazy migration. A pre-v3 `device` grant carried
|
|
44572
|
-
* `targets: string[]` (stringified deviceIds); it rewrites to the equivalent
|
|
44573
|
-
* `selector: {kind:'ids', ids}`. Applied as a `preprocess` so it runs on
|
|
44574
|
-
* EVERY parse path — stored records AND the JWT-carried scope arrays
|
|
44575
|
-
* normalised at the request boundary ({@link normalizeTokenScopes} in
|
|
44576
|
-
* `device-selector.ts`). Chosen over a one-time DB migration because a
|
|
44577
|
-
* migration cannot reach a JWT already in a client's hands; parse-time
|
|
44578
|
-
* migration covers both without a flag day. No cast — the raw object is read
|
|
44579
|
-
* through `Reflect.get` (its static type is `unknown`).
|
|
44580
|
-
*/
|
|
44581
|
-
function migrateLegacyTokenScope(raw) {
|
|
44582
|
-
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return raw;
|
|
44583
|
-
if (Reflect.get(raw, "type") !== "device") return raw;
|
|
44584
|
-
if (Reflect.get(raw, "selector") !== void 0) return raw;
|
|
44585
|
-
const targets = Reflect.get(raw, "targets");
|
|
44586
|
-
if (!Array.isArray(targets)) return raw;
|
|
44587
|
-
return {
|
|
44588
|
-
type: "device",
|
|
44589
|
-
selector: {
|
|
44590
|
-
kind: "ids",
|
|
44591
|
-
ids: targets.map((t) => typeof t === "string" ? Number(t) : t).filter((n) => typeof n === "number" && Number.isInteger(n))
|
|
44592
|
-
},
|
|
44593
|
-
access: Reflect.get(raw, "access")
|
|
44594
|
-
};
|
|
44595
|
-
}
|
|
44596
|
-
var TokenScopeSchema = preprocess(migrateLegacyTokenScope, discriminatedUnion("type", [
|
|
44597
|
-
object({
|
|
44598
|
-
type: literal("category"),
|
|
44599
|
-
target: CapScopeSchema,
|
|
44600
|
-
access: array(MethodAccessSchema).min(1)
|
|
44601
|
-
}),
|
|
44602
|
-
object({
|
|
44603
|
-
type: literal("capability"),
|
|
44604
|
-
target: string(),
|
|
44605
|
-
access: array(MethodAccessSchema).min(1)
|
|
44606
|
-
}),
|
|
44607
|
-
object({
|
|
44608
|
-
type: literal("addon"),
|
|
44609
|
-
target: string(),
|
|
44610
|
-
access: array(MethodAccessSchema).min(1)
|
|
44611
|
-
}),
|
|
44612
|
-
DeviceTokenScopeSchema
|
|
44613
|
-
]));
|
|
44614
|
-
object({
|
|
44615
|
-
id: string(),
|
|
44616
|
-
username: string(),
|
|
44617
|
-
passwordHash: string(),
|
|
44618
|
-
/**
|
|
44619
|
-
* Admin bypass. When true, the middleware skips the scope-access
|
|
44620
|
-
* check entirely. There is no other axis of privilege; the legacy
|
|
44621
|
-
* role enum collapsed onto this boolean in v2.
|
|
44622
|
-
*/
|
|
44623
|
-
isAdmin: boolean().default(false),
|
|
44624
|
-
allowedProviders: AllowedProviderSchema,
|
|
44625
|
-
allowedDevices: AllowedDevicesSchema,
|
|
44626
|
-
/**
|
|
44627
|
-
* Scopes granted to this user. Admins bypass; their `scopes` is
|
|
44628
|
-
* ignored. Non-admins without scopes are locked out of every
|
|
44629
|
-
* protected call.
|
|
44630
|
-
*/
|
|
44631
|
-
scopes: array(TokenScopeSchema).default([]),
|
|
44632
|
-
createdAt: number(),
|
|
44633
|
-
updatedAt: number()
|
|
44634
|
-
});
|
|
44635
|
-
object({
|
|
44636
|
-
id: string(),
|
|
44637
|
-
label: string(),
|
|
44638
|
-
isAdmin: boolean().default(false),
|
|
44639
|
-
allowedProviders: AllowedProviderSchema,
|
|
44640
|
-
allowedDevices: AllowedDevicesSchema,
|
|
44641
|
-
tokenHash: string(),
|
|
44642
|
-
tokenPrefix: string(),
|
|
44643
|
-
createdAt: number(),
|
|
44644
|
-
lastUsedAt: number().optional()
|
|
44645
|
-
});
|
|
44646
|
-
object({
|
|
44647
|
-
id: string(),
|
|
44648
|
-
userId: string(),
|
|
44649
|
-
name: string(),
|
|
44650
|
-
tokenHash: string(),
|
|
44651
|
-
tokenPrefix: string(),
|
|
44652
|
-
scopes: array(TokenScopeSchema),
|
|
44653
|
-
expiresAt: number().nullish(),
|
|
44654
|
-
lastUsedAt: number().nullish(),
|
|
44655
|
-
createdAt: number()
|
|
44656
|
-
});
|
|
44657
|
-
/**
|
|
44658
44691
|
* `oauth-integration` — a collection cap by which an addon declares
|
|
44659
44692
|
* itself a linkable OAuth client of the hub's core `/oauth2/*` server.
|
|
44660
44693
|
* Each provider returns a static descriptor; the core enumerates them
|
package/dist/addon.mjs
CHANGED
|
@@ -7939,6 +7939,12 @@ function normalizeAddonInitResult(result) {
|
|
|
7939
7939
|
if (Array.isArray(result)) return { providers: result };
|
|
7940
7940
|
return result;
|
|
7941
7941
|
}
|
|
7942
|
+
/**
|
|
7943
|
+
* The share-view scope kinds a `csv_*` share token can carry. The hub mints
|
|
7944
|
+
* and validates them (`share-token.service.ts` builds its enum from this
|
|
7945
|
+
* list); a data plane names the kinds it ACCEPTS in `share`.
|
|
7946
|
+
*/
|
|
7947
|
+
var SHARE_VIEW_KINDS = ["grid-view", "events-view"];
|
|
7942
7948
|
/** The wire shape of {@link PeerBytesTicket} — see the type for what it is. */
|
|
7943
7949
|
var PeerBytesTicketSchema = object({
|
|
7944
7950
|
/** `http://127.0.0.1:<port>/<token>`. One `GET` takes it. */
|
|
@@ -12804,6 +12810,229 @@ var ConvertResultSchema = object({
|
|
|
12804
12810
|
files: array(string()).readonly()
|
|
12805
12811
|
})).readonly()
|
|
12806
12812
|
});
|
|
12813
|
+
/**
|
|
12814
|
+
* Zod schemas for persisted record types.
|
|
12815
|
+
*
|
|
12816
|
+
* These schemas serve as the single source of truth for types that are
|
|
12817
|
+
* stored in the settings-store backend and retrieved via tRPC. They
|
|
12818
|
+
* replace the manual TypeScript interfaces with schema-derived types,
|
|
12819
|
+
* enabling runtime validation when reading from the backend.
|
|
12820
|
+
*
|
|
12821
|
+
* Convention: each schema is named `<Type>Schema`, the inferred TS type
|
|
12822
|
+
* keeps the original name for backward compatibility.
|
|
12823
|
+
*/
|
|
12824
|
+
/**
|
|
12825
|
+
* Auth model (v2 — 2026-05-12 caps-only):
|
|
12826
|
+
*
|
|
12827
|
+
* Two principals:
|
|
12828
|
+
* - `isAdmin: true` — full bypass. Admin scope set is ignored.
|
|
12829
|
+
* - `isAdmin: false` — every call gated by `scopes` (see TokenScope).
|
|
12830
|
+
*
|
|
12831
|
+
* No role enum. There used to be `viewer / agent / scoped` and earlier
|
|
12832
|
+
* `super_admin` — collapsed onto the single boolean because every
|
|
12833
|
+
* non-admin caller is governed by the same scope-check rules; the
|
|
12834
|
+
* distinction was only ever used to route role-specific procedures
|
|
12835
|
+
* which we no longer have. CLI / webhook integrations are `cst_*` tokens
|
|
12836
|
+
* with `isAdmin: false` + an explicit scope list.
|
|
12837
|
+
*/
|
|
12838
|
+
/** Per-method access flavour. Materialised on every cap method via codegen. */
|
|
12839
|
+
var MethodAccessSchema = _enum([
|
|
12840
|
+
"view",
|
|
12841
|
+
"create",
|
|
12842
|
+
"delete"
|
|
12843
|
+
]);
|
|
12844
|
+
/**
|
|
12845
|
+
* A single scope grant. Three forms — checked in matcher with OR
|
|
12846
|
+
* semantics; the first match decides whether the call passes:
|
|
12847
|
+
*
|
|
12848
|
+
* - `category` — broadest. `target: 'device' | 'system'` selects every
|
|
12849
|
+
* cap with the matching `scope` declaration. New caps inherit grants
|
|
12850
|
+
* automatically — adding a device cap to the codebase makes it
|
|
12851
|
+
* reachable to every user with `category:device [...]` without a
|
|
12852
|
+
* re-grant. Use this for "family viewer" / "operator" tiers.
|
|
12853
|
+
*
|
|
12854
|
+
* - `addon` — every cap that ships inside a given addon id. Niche;
|
|
12855
|
+
* useful when an integration needs to interact with one specific
|
|
12856
|
+
* addon's surface regardless of how many caps it exports.
|
|
12857
|
+
*
|
|
12858
|
+
* - `capability` — the most precise form. Single cap name. Use for
|
|
12859
|
+
* integration tokens where you want to grant `addons.installPackage`
|
|
12860
|
+
* and nothing else.
|
|
12861
|
+
*
|
|
12862
|
+
* `access` is REQUIRED with min 1 element. `admin` bypass is the
|
|
12863
|
+
* "give me everything" escape; there is no wildcard scope.
|
|
12864
|
+
*/
|
|
12865
|
+
var AllowedProviderSchema = union([literal("*"), array(string())]);
|
|
12866
|
+
var AllowedDevicesSchema = record(string(), union([literal("*"), array(string())]));
|
|
12867
|
+
var CapScopeSchema = _enum(["device", "system"]);
|
|
12868
|
+
/**
|
|
12869
|
+
* DeviceSelector (scope model v3 — 2026-08-12).
|
|
12870
|
+
*
|
|
12871
|
+
* A `device` grant no longer carries a frozen list of deviceIds. It carries
|
|
12872
|
+
* a SELECTOR the matcher resolves against the live fleet, so the grant can be
|
|
12873
|
+
* DYNAMIC: a `types:['camera']` selector automatically covers a camera added
|
|
12874
|
+
* AFTER the grant was minted — no re-grant, no re-login.
|
|
12875
|
+
*
|
|
12876
|
+
* - `all` — every device in the deployment. The broad viewer/operator
|
|
12877
|
+
* lever without a `category` grant (a `category` grant also covers device
|
|
12878
|
+
* caps that carry no deviceId; `all` is specifically the device set).
|
|
12879
|
+
* - `ids` — an explicit deviceId list. This is what a v2 `device:[…]`
|
|
12880
|
+
* grant migrates to (see {@link TokenScopeSchema}); STATIC — a new camera
|
|
12881
|
+
* is NOT covered until the grant is edited.
|
|
12882
|
+
* - `types` — every device of a `DeviceType` (e.g. every `camera`).
|
|
12883
|
+
* DYNAMIC. A device that changes type, or a new device of the type,
|
|
12884
|
+
* re-resolves on the next request.
|
|
12885
|
+
* - `locations` — every device whose operator-assigned `location` label is
|
|
12886
|
+
* in the set (e.g. "Garden", "Front door"). DYNAMIC. A device with a
|
|
12887
|
+
* null/unset location matches NO `locations` selector.
|
|
12888
|
+
*/
|
|
12889
|
+
var DeviceSelectorSchema = discriminatedUnion("kind", [
|
|
12890
|
+
object({ kind: literal("all") }),
|
|
12891
|
+
object({
|
|
12892
|
+
kind: literal("ids"),
|
|
12893
|
+
ids: array(number().int()).min(1)
|
|
12894
|
+
}),
|
|
12895
|
+
object({
|
|
12896
|
+
kind: literal("types"),
|
|
12897
|
+
types: array(_enum(DeviceType)).min(1)
|
|
12898
|
+
}),
|
|
12899
|
+
object({
|
|
12900
|
+
kind: literal("locations"),
|
|
12901
|
+
locations: array(string().min(1)).min(1)
|
|
12902
|
+
})
|
|
12903
|
+
]);
|
|
12904
|
+
var DeviceTokenScopeSchema = object({
|
|
12905
|
+
type: literal("device"),
|
|
12906
|
+
/** The device SET this grant covers — resolved against the live fleet. */
|
|
12907
|
+
selector: DeviceSelectorSchema,
|
|
12908
|
+
access: array(MethodAccessSchema).min(1),
|
|
12909
|
+
/**
|
|
12910
|
+
* Whether a grant on a PARENT device transparently covers its accessory
|
|
12911
|
+
* CHILDREN (siren / floodlight / PIR) via the persisted-parentage walk.
|
|
12912
|
+
* Direction is parent → children ONLY.
|
|
12913
|
+
*
|
|
12914
|
+
* Absent → the matcher DERIVES it from the access flavour: `view`
|
|
12915
|
+
* inherits (a camera viewer sees the camera's accessories), `create` /
|
|
12916
|
+
* `delete` do NOT (actuating/removing a child is an explicit act the
|
|
12917
|
+
* operator must grant on the child, not inherit from the parent). Set it
|
|
12918
|
+
* explicitly to override that default per grant.
|
|
12919
|
+
*/
|
|
12920
|
+
includeLinked: boolean().optional()
|
|
12921
|
+
});
|
|
12922
|
+
/**
|
|
12923
|
+
* v2 → v3 lazy migration. A pre-v3 `device` grant carried
|
|
12924
|
+
* `targets: string[]` (stringified deviceIds); it rewrites to the equivalent
|
|
12925
|
+
* `selector: {kind:'ids', ids}`. Applied as a `preprocess` so it runs on
|
|
12926
|
+
* EVERY parse path — stored records AND the JWT-carried scope arrays
|
|
12927
|
+
* normalised at the request boundary ({@link normalizeTokenScopes} in
|
|
12928
|
+
* `device-selector.ts`). Chosen over a one-time DB migration because a
|
|
12929
|
+
* migration cannot reach a JWT already in a client's hands; parse-time
|
|
12930
|
+
* migration covers both without a flag day. No cast — the raw object is read
|
|
12931
|
+
* through `Reflect.get` (its static type is `unknown`).
|
|
12932
|
+
*/
|
|
12933
|
+
function migrateLegacyTokenScope(raw) {
|
|
12934
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return raw;
|
|
12935
|
+
if (Reflect.get(raw, "type") !== "device") return raw;
|
|
12936
|
+
if (Reflect.get(raw, "selector") !== void 0) return raw;
|
|
12937
|
+
const targets = Reflect.get(raw, "targets");
|
|
12938
|
+
if (!Array.isArray(targets)) return raw;
|
|
12939
|
+
return {
|
|
12940
|
+
type: "device",
|
|
12941
|
+
selector: {
|
|
12942
|
+
kind: "ids",
|
|
12943
|
+
ids: targets.map((t) => typeof t === "string" ? Number(t) : t).filter((n) => typeof n === "number" && Number.isInteger(n))
|
|
12944
|
+
},
|
|
12945
|
+
access: Reflect.get(raw, "access")
|
|
12946
|
+
};
|
|
12947
|
+
}
|
|
12948
|
+
var TokenScopeSchema = preprocess(migrateLegacyTokenScope, discriminatedUnion("type", [
|
|
12949
|
+
object({
|
|
12950
|
+
type: literal("category"),
|
|
12951
|
+
target: CapScopeSchema,
|
|
12952
|
+
access: array(MethodAccessSchema).min(1)
|
|
12953
|
+
}),
|
|
12954
|
+
object({
|
|
12955
|
+
type: literal("capability"),
|
|
12956
|
+
target: string(),
|
|
12957
|
+
access: array(MethodAccessSchema).min(1)
|
|
12958
|
+
}),
|
|
12959
|
+
object({
|
|
12960
|
+
type: literal("addon"),
|
|
12961
|
+
target: string(),
|
|
12962
|
+
access: array(MethodAccessSchema).min(1)
|
|
12963
|
+
}),
|
|
12964
|
+
DeviceTokenScopeSchema
|
|
12965
|
+
]));
|
|
12966
|
+
object({
|
|
12967
|
+
id: string(),
|
|
12968
|
+
username: string(),
|
|
12969
|
+
passwordHash: string(),
|
|
12970
|
+
/**
|
|
12971
|
+
* Admin bypass. When true, the middleware skips the scope-access
|
|
12972
|
+
* check entirely. There is no other axis of privilege; the legacy
|
|
12973
|
+
* role enum collapsed onto this boolean in v2.
|
|
12974
|
+
*/
|
|
12975
|
+
isAdmin: boolean().default(false),
|
|
12976
|
+
allowedProviders: AllowedProviderSchema,
|
|
12977
|
+
allowedDevices: AllowedDevicesSchema,
|
|
12978
|
+
/**
|
|
12979
|
+
* Scopes granted to this user. Admins bypass; their `scopes` is
|
|
12980
|
+
* ignored. Non-admins without scopes are locked out of every
|
|
12981
|
+
* protected call.
|
|
12982
|
+
*/
|
|
12983
|
+
scopes: array(TokenScopeSchema).default([]),
|
|
12984
|
+
createdAt: number(),
|
|
12985
|
+
updatedAt: number()
|
|
12986
|
+
});
|
|
12987
|
+
object({
|
|
12988
|
+
id: string(),
|
|
12989
|
+
label: string(),
|
|
12990
|
+
isAdmin: boolean().default(false),
|
|
12991
|
+
allowedProviders: AllowedProviderSchema,
|
|
12992
|
+
allowedDevices: AllowedDevicesSchema,
|
|
12993
|
+
tokenHash: string(),
|
|
12994
|
+
tokenPrefix: string(),
|
|
12995
|
+
createdAt: number(),
|
|
12996
|
+
lastUsedAt: number().optional()
|
|
12997
|
+
});
|
|
12998
|
+
object({
|
|
12999
|
+
id: string(),
|
|
13000
|
+
userId: string(),
|
|
13001
|
+
name: string(),
|
|
13002
|
+
tokenHash: string(),
|
|
13003
|
+
tokenPrefix: string(),
|
|
13004
|
+
scopes: array(TokenScopeSchema),
|
|
13005
|
+
expiresAt: number().nullish(),
|
|
13006
|
+
lastUsedAt: number().nullish(),
|
|
13007
|
+
createdAt: number()
|
|
13008
|
+
});
|
|
13009
|
+
/** What a share-view grant lets its holder see. */
|
|
13010
|
+
var ShareViewGrantSchema = object({
|
|
13011
|
+
kind: _enum(SHARE_VIEW_KINDS),
|
|
13012
|
+
deviceIds: array(number().int().nonnegative()).min(1).max(64),
|
|
13013
|
+
/** Talk-back, opt-in at mint time; absent means off. */
|
|
13014
|
+
talk: boolean().optional()
|
|
13015
|
+
});
|
|
13016
|
+
var ShareViewScopeSchema = object({
|
|
13017
|
+
type: literal("share-view"),
|
|
13018
|
+
grant: ShareViewGrantSchema
|
|
13019
|
+
});
|
|
13020
|
+
var AddonRoutesScopeSchema = object({
|
|
13021
|
+
type: literal("addon-routes"),
|
|
13022
|
+
access: array(MethodAccessSchema).min(1)
|
|
13023
|
+
});
|
|
13024
|
+
var CredentialScopeSchema = union([
|
|
13025
|
+
literal("*"),
|
|
13026
|
+
ShareViewScopeSchema,
|
|
13027
|
+
AddonRoutesScopeSchema,
|
|
13028
|
+
TokenScopeSchema
|
|
13029
|
+
]);
|
|
13030
|
+
object({
|
|
13031
|
+
kind: literal("credential"),
|
|
13032
|
+
sub: string().min(1),
|
|
13033
|
+
jti: string().min(16),
|
|
13034
|
+
scopes: array(CredentialScopeSchema).min(1)
|
|
13035
|
+
});
|
|
12807
13036
|
_enum(["new-session", "step-up"]);
|
|
12808
13037
|
/** The languages the hub's app landing pages are written in (D858). */
|
|
12809
13038
|
var AppPageLangSchema = _enum(["en", "it"]);
|
|
@@ -44460,202 +44689,6 @@ method(object({}), object({ rules: array(NcRuleSchema) }), { auth: "admin" }), m
|
|
|
44460
44689
|
auth: "admin"
|
|
44461
44690
|
}), method(NcAlarmSensorsInputSchema, NcAlarmSensorsSchema, { auth: "admin" });
|
|
44462
44691
|
/**
|
|
44463
|
-
* Zod schemas for persisted record types.
|
|
44464
|
-
*
|
|
44465
|
-
* These schemas serve as the single source of truth for types that are
|
|
44466
|
-
* stored in the settings-store backend and retrieved via tRPC. They
|
|
44467
|
-
* replace the manual TypeScript interfaces with schema-derived types,
|
|
44468
|
-
* enabling runtime validation when reading from the backend.
|
|
44469
|
-
*
|
|
44470
|
-
* Convention: each schema is named `<Type>Schema`, the inferred TS type
|
|
44471
|
-
* keeps the original name for backward compatibility.
|
|
44472
|
-
*/
|
|
44473
|
-
/**
|
|
44474
|
-
* Auth model (v2 — 2026-05-12 caps-only):
|
|
44475
|
-
*
|
|
44476
|
-
* Two principals:
|
|
44477
|
-
* - `isAdmin: true` — full bypass. Admin scope set is ignored.
|
|
44478
|
-
* - `isAdmin: false` — every call gated by `scopes` (see TokenScope).
|
|
44479
|
-
*
|
|
44480
|
-
* No role enum. There used to be `viewer / agent / scoped` and earlier
|
|
44481
|
-
* `super_admin` — collapsed onto the single boolean because every
|
|
44482
|
-
* non-admin caller is governed by the same scope-check rules; the
|
|
44483
|
-
* distinction was only ever used to route role-specific procedures
|
|
44484
|
-
* which we no longer have. CLI / webhook integrations are `cst_*` tokens
|
|
44485
|
-
* with `isAdmin: false` + an explicit scope list.
|
|
44486
|
-
*/
|
|
44487
|
-
/** Per-method access flavour. Materialised on every cap method via codegen. */
|
|
44488
|
-
var MethodAccessSchema = _enum([
|
|
44489
|
-
"view",
|
|
44490
|
-
"create",
|
|
44491
|
-
"delete"
|
|
44492
|
-
]);
|
|
44493
|
-
/**
|
|
44494
|
-
* A single scope grant. Three forms — checked in matcher with OR
|
|
44495
|
-
* semantics; the first match decides whether the call passes:
|
|
44496
|
-
*
|
|
44497
|
-
* - `category` — broadest. `target: 'device' | 'system'` selects every
|
|
44498
|
-
* cap with the matching `scope` declaration. New caps inherit grants
|
|
44499
|
-
* automatically — adding a device cap to the codebase makes it
|
|
44500
|
-
* reachable to every user with `category:device [...]` without a
|
|
44501
|
-
* re-grant. Use this for "family viewer" / "operator" tiers.
|
|
44502
|
-
*
|
|
44503
|
-
* - `addon` — every cap that ships inside a given addon id. Niche;
|
|
44504
|
-
* useful when an integration needs to interact with one specific
|
|
44505
|
-
* addon's surface regardless of how many caps it exports.
|
|
44506
|
-
*
|
|
44507
|
-
* - `capability` — the most precise form. Single cap name. Use for
|
|
44508
|
-
* integration tokens where you want to grant `addons.installPackage`
|
|
44509
|
-
* and nothing else.
|
|
44510
|
-
*
|
|
44511
|
-
* `access` is REQUIRED with min 1 element. `admin` bypass is the
|
|
44512
|
-
* "give me everything" escape; there is no wildcard scope.
|
|
44513
|
-
*/
|
|
44514
|
-
var AllowedProviderSchema = union([literal("*"), array(string())]);
|
|
44515
|
-
var AllowedDevicesSchema = record(string(), union([literal("*"), array(string())]));
|
|
44516
|
-
var CapScopeSchema = _enum(["device", "system"]);
|
|
44517
|
-
/**
|
|
44518
|
-
* DeviceSelector (scope model v3 — 2026-08-12).
|
|
44519
|
-
*
|
|
44520
|
-
* A `device` grant no longer carries a frozen list of deviceIds. It carries
|
|
44521
|
-
* a SELECTOR the matcher resolves against the live fleet, so the grant can be
|
|
44522
|
-
* DYNAMIC: a `types:['camera']` selector automatically covers a camera added
|
|
44523
|
-
* AFTER the grant was minted — no re-grant, no re-login.
|
|
44524
|
-
*
|
|
44525
|
-
* - `all` — every device in the deployment. The broad viewer/operator
|
|
44526
|
-
* lever without a `category` grant (a `category` grant also covers device
|
|
44527
|
-
* caps that carry no deviceId; `all` is specifically the device set).
|
|
44528
|
-
* - `ids` — an explicit deviceId list. This is what a v2 `device:[…]`
|
|
44529
|
-
* grant migrates to (see {@link TokenScopeSchema}); STATIC — a new camera
|
|
44530
|
-
* is NOT covered until the grant is edited.
|
|
44531
|
-
* - `types` — every device of a `DeviceType` (e.g. every `camera`).
|
|
44532
|
-
* DYNAMIC. A device that changes type, or a new device of the type,
|
|
44533
|
-
* re-resolves on the next request.
|
|
44534
|
-
* - `locations` — every device whose operator-assigned `location` label is
|
|
44535
|
-
* in the set (e.g. "Garden", "Front door"). DYNAMIC. A device with a
|
|
44536
|
-
* null/unset location matches NO `locations` selector.
|
|
44537
|
-
*/
|
|
44538
|
-
var DeviceSelectorSchema = discriminatedUnion("kind", [
|
|
44539
|
-
object({ kind: literal("all") }),
|
|
44540
|
-
object({
|
|
44541
|
-
kind: literal("ids"),
|
|
44542
|
-
ids: array(number().int()).min(1)
|
|
44543
|
-
}),
|
|
44544
|
-
object({
|
|
44545
|
-
kind: literal("types"),
|
|
44546
|
-
types: array(_enum(DeviceType)).min(1)
|
|
44547
|
-
}),
|
|
44548
|
-
object({
|
|
44549
|
-
kind: literal("locations"),
|
|
44550
|
-
locations: array(string().min(1)).min(1)
|
|
44551
|
-
})
|
|
44552
|
-
]);
|
|
44553
|
-
var DeviceTokenScopeSchema = object({
|
|
44554
|
-
type: literal("device"),
|
|
44555
|
-
/** The device SET this grant covers — resolved against the live fleet. */
|
|
44556
|
-
selector: DeviceSelectorSchema,
|
|
44557
|
-
access: array(MethodAccessSchema).min(1),
|
|
44558
|
-
/**
|
|
44559
|
-
* Whether a grant on a PARENT device transparently covers its accessory
|
|
44560
|
-
* CHILDREN (siren / floodlight / PIR) via the persisted-parentage walk.
|
|
44561
|
-
* Direction is parent → children ONLY.
|
|
44562
|
-
*
|
|
44563
|
-
* Absent → the matcher DERIVES it from the access flavour: `view`
|
|
44564
|
-
* inherits (a camera viewer sees the camera's accessories), `create` /
|
|
44565
|
-
* `delete` do NOT (actuating/removing a child is an explicit act the
|
|
44566
|
-
* operator must grant on the child, not inherit from the parent). Set it
|
|
44567
|
-
* explicitly to override that default per grant.
|
|
44568
|
-
*/
|
|
44569
|
-
includeLinked: boolean().optional()
|
|
44570
|
-
});
|
|
44571
|
-
/**
|
|
44572
|
-
* v2 → v3 lazy migration. A pre-v3 `device` grant carried
|
|
44573
|
-
* `targets: string[]` (stringified deviceIds); it rewrites to the equivalent
|
|
44574
|
-
* `selector: {kind:'ids', ids}`. Applied as a `preprocess` so it runs on
|
|
44575
|
-
* EVERY parse path — stored records AND the JWT-carried scope arrays
|
|
44576
|
-
* normalised at the request boundary ({@link normalizeTokenScopes} in
|
|
44577
|
-
* `device-selector.ts`). Chosen over a one-time DB migration because a
|
|
44578
|
-
* migration cannot reach a JWT already in a client's hands; parse-time
|
|
44579
|
-
* migration covers both without a flag day. No cast — the raw object is read
|
|
44580
|
-
* through `Reflect.get` (its static type is `unknown`).
|
|
44581
|
-
*/
|
|
44582
|
-
function migrateLegacyTokenScope(raw) {
|
|
44583
|
-
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return raw;
|
|
44584
|
-
if (Reflect.get(raw, "type") !== "device") return raw;
|
|
44585
|
-
if (Reflect.get(raw, "selector") !== void 0) return raw;
|
|
44586
|
-
const targets = Reflect.get(raw, "targets");
|
|
44587
|
-
if (!Array.isArray(targets)) return raw;
|
|
44588
|
-
return {
|
|
44589
|
-
type: "device",
|
|
44590
|
-
selector: {
|
|
44591
|
-
kind: "ids",
|
|
44592
|
-
ids: targets.map((t) => typeof t === "string" ? Number(t) : t).filter((n) => typeof n === "number" && Number.isInteger(n))
|
|
44593
|
-
},
|
|
44594
|
-
access: Reflect.get(raw, "access")
|
|
44595
|
-
};
|
|
44596
|
-
}
|
|
44597
|
-
var TokenScopeSchema = preprocess(migrateLegacyTokenScope, discriminatedUnion("type", [
|
|
44598
|
-
object({
|
|
44599
|
-
type: literal("category"),
|
|
44600
|
-
target: CapScopeSchema,
|
|
44601
|
-
access: array(MethodAccessSchema).min(1)
|
|
44602
|
-
}),
|
|
44603
|
-
object({
|
|
44604
|
-
type: literal("capability"),
|
|
44605
|
-
target: string(),
|
|
44606
|
-
access: array(MethodAccessSchema).min(1)
|
|
44607
|
-
}),
|
|
44608
|
-
object({
|
|
44609
|
-
type: literal("addon"),
|
|
44610
|
-
target: string(),
|
|
44611
|
-
access: array(MethodAccessSchema).min(1)
|
|
44612
|
-
}),
|
|
44613
|
-
DeviceTokenScopeSchema
|
|
44614
|
-
]));
|
|
44615
|
-
object({
|
|
44616
|
-
id: string(),
|
|
44617
|
-
username: string(),
|
|
44618
|
-
passwordHash: string(),
|
|
44619
|
-
/**
|
|
44620
|
-
* Admin bypass. When true, the middleware skips the scope-access
|
|
44621
|
-
* check entirely. There is no other axis of privilege; the legacy
|
|
44622
|
-
* role enum collapsed onto this boolean in v2.
|
|
44623
|
-
*/
|
|
44624
|
-
isAdmin: boolean().default(false),
|
|
44625
|
-
allowedProviders: AllowedProviderSchema,
|
|
44626
|
-
allowedDevices: AllowedDevicesSchema,
|
|
44627
|
-
/**
|
|
44628
|
-
* Scopes granted to this user. Admins bypass; their `scopes` is
|
|
44629
|
-
* ignored. Non-admins without scopes are locked out of every
|
|
44630
|
-
* protected call.
|
|
44631
|
-
*/
|
|
44632
|
-
scopes: array(TokenScopeSchema).default([]),
|
|
44633
|
-
createdAt: number(),
|
|
44634
|
-
updatedAt: number()
|
|
44635
|
-
});
|
|
44636
|
-
object({
|
|
44637
|
-
id: string(),
|
|
44638
|
-
label: string(),
|
|
44639
|
-
isAdmin: boolean().default(false),
|
|
44640
|
-
allowedProviders: AllowedProviderSchema,
|
|
44641
|
-
allowedDevices: AllowedDevicesSchema,
|
|
44642
|
-
tokenHash: string(),
|
|
44643
|
-
tokenPrefix: string(),
|
|
44644
|
-
createdAt: number(),
|
|
44645
|
-
lastUsedAt: number().optional()
|
|
44646
|
-
});
|
|
44647
|
-
object({
|
|
44648
|
-
id: string(),
|
|
44649
|
-
userId: string(),
|
|
44650
|
-
name: string(),
|
|
44651
|
-
tokenHash: string(),
|
|
44652
|
-
tokenPrefix: string(),
|
|
44653
|
-
scopes: array(TokenScopeSchema),
|
|
44654
|
-
expiresAt: number().nullish(),
|
|
44655
|
-
lastUsedAt: number().nullish(),
|
|
44656
|
-
createdAt: number()
|
|
44657
|
-
});
|
|
44658
|
-
/**
|
|
44659
44692
|
* `oauth-integration` — a collection cap by which an addon declares
|
|
44660
44693
|
* itself a linkable OAuth client of the hub's core `/oauth2/*` server.
|
|
44661
44694
|
* Each provider returns a static descriptor; the core enumerates them
|
package/package.json
CHANGED