@camstack/addon-terminal 0.1.135 → 0.1.136
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
|
@@ -7828,6 +7828,12 @@ function normalizeAddonInitResult(result) {
|
|
|
7828
7828
|
if (Array.isArray(result)) return { providers: result };
|
|
7829
7829
|
return result;
|
|
7830
7830
|
}
|
|
7831
|
+
/**
|
|
7832
|
+
* The share-view scope kinds a `csv_*` share token can carry. The hub mints
|
|
7833
|
+
* and validates them (`share-token.service.ts` builds its enum from this
|
|
7834
|
+
* list); a data plane names the kinds it ACCEPTS in `share`.
|
|
7835
|
+
*/
|
|
7836
|
+
var SHARE_VIEW_KINDS = ["grid-view", "events-view"];
|
|
7831
7837
|
/** The wire shape of {@link PeerBytesTicket} — see the type for what it is. */
|
|
7832
7838
|
var PeerBytesTicketSchema = object({
|
|
7833
7839
|
/** `http://127.0.0.1:<port>/<token>`. One `GET` takes it. */
|
|
@@ -12584,6 +12590,229 @@ var ConvertResultSchema = object({
|
|
|
12584
12590
|
files: array(string()).readonly()
|
|
12585
12591
|
})).readonly()
|
|
12586
12592
|
});
|
|
12593
|
+
/**
|
|
12594
|
+
* Zod schemas for persisted record types.
|
|
12595
|
+
*
|
|
12596
|
+
* These schemas serve as the single source of truth for types that are
|
|
12597
|
+
* stored in the settings-store backend and retrieved via tRPC. They
|
|
12598
|
+
* replace the manual TypeScript interfaces with schema-derived types,
|
|
12599
|
+
* enabling runtime validation when reading from the backend.
|
|
12600
|
+
*
|
|
12601
|
+
* Convention: each schema is named `<Type>Schema`, the inferred TS type
|
|
12602
|
+
* keeps the original name for backward compatibility.
|
|
12603
|
+
*/
|
|
12604
|
+
/**
|
|
12605
|
+
* Auth model (v2 — 2026-05-12 caps-only):
|
|
12606
|
+
*
|
|
12607
|
+
* Two principals:
|
|
12608
|
+
* - `isAdmin: true` — full bypass. Admin scope set is ignored.
|
|
12609
|
+
* - `isAdmin: false` — every call gated by `scopes` (see TokenScope).
|
|
12610
|
+
*
|
|
12611
|
+
* No role enum. There used to be `viewer / agent / scoped` and earlier
|
|
12612
|
+
* `super_admin` — collapsed onto the single boolean because every
|
|
12613
|
+
* non-admin caller is governed by the same scope-check rules; the
|
|
12614
|
+
* distinction was only ever used to route role-specific procedures
|
|
12615
|
+
* which we no longer have. CLI / webhook integrations are `cst_*` tokens
|
|
12616
|
+
* with `isAdmin: false` + an explicit scope list.
|
|
12617
|
+
*/
|
|
12618
|
+
/** Per-method access flavour. Materialised on every cap method via codegen. */
|
|
12619
|
+
var MethodAccessSchema = _enum([
|
|
12620
|
+
"view",
|
|
12621
|
+
"create",
|
|
12622
|
+
"delete"
|
|
12623
|
+
]);
|
|
12624
|
+
/**
|
|
12625
|
+
* A single scope grant. Three forms — checked in matcher with OR
|
|
12626
|
+
* semantics; the first match decides whether the call passes:
|
|
12627
|
+
*
|
|
12628
|
+
* - `category` — broadest. `target: 'device' | 'system'` selects every
|
|
12629
|
+
* cap with the matching `scope` declaration. New caps inherit grants
|
|
12630
|
+
* automatically — adding a device cap to the codebase makes it
|
|
12631
|
+
* reachable to every user with `category:device [...]` without a
|
|
12632
|
+
* re-grant. Use this for "family viewer" / "operator" tiers.
|
|
12633
|
+
*
|
|
12634
|
+
* - `addon` — every cap that ships inside a given addon id. Niche;
|
|
12635
|
+
* useful when an integration needs to interact with one specific
|
|
12636
|
+
* addon's surface regardless of how many caps it exports.
|
|
12637
|
+
*
|
|
12638
|
+
* - `capability` — the most precise form. Single cap name. Use for
|
|
12639
|
+
* integration tokens where you want to grant `addons.installPackage`
|
|
12640
|
+
* and nothing else.
|
|
12641
|
+
*
|
|
12642
|
+
* `access` is REQUIRED with min 1 element. `admin` bypass is the
|
|
12643
|
+
* "give me everything" escape; there is no wildcard scope.
|
|
12644
|
+
*/
|
|
12645
|
+
var AllowedProviderSchema = union([literal("*"), array(string())]);
|
|
12646
|
+
var AllowedDevicesSchema = record(string(), union([literal("*"), array(string())]));
|
|
12647
|
+
var CapScopeSchema = _enum(["device", "system"]);
|
|
12648
|
+
/**
|
|
12649
|
+
* DeviceSelector (scope model v3 — 2026-08-12).
|
|
12650
|
+
*
|
|
12651
|
+
* A `device` grant no longer carries a frozen list of deviceIds. It carries
|
|
12652
|
+
* a SELECTOR the matcher resolves against the live fleet, so the grant can be
|
|
12653
|
+
* DYNAMIC: a `types:['camera']` selector automatically covers a camera added
|
|
12654
|
+
* AFTER the grant was minted — no re-grant, no re-login.
|
|
12655
|
+
*
|
|
12656
|
+
* - `all` — every device in the deployment. The broad viewer/operator
|
|
12657
|
+
* lever without a `category` grant (a `category` grant also covers device
|
|
12658
|
+
* caps that carry no deviceId; `all` is specifically the device set).
|
|
12659
|
+
* - `ids` — an explicit deviceId list. This is what a v2 `device:[…]`
|
|
12660
|
+
* grant migrates to (see {@link TokenScopeSchema}); STATIC — a new camera
|
|
12661
|
+
* is NOT covered until the grant is edited.
|
|
12662
|
+
* - `types` — every device of a `DeviceType` (e.g. every `camera`).
|
|
12663
|
+
* DYNAMIC. A device that changes type, or a new device of the type,
|
|
12664
|
+
* re-resolves on the next request.
|
|
12665
|
+
* - `locations` — every device whose operator-assigned `location` label is
|
|
12666
|
+
* in the set (e.g. "Garden", "Front door"). DYNAMIC. A device with a
|
|
12667
|
+
* null/unset location matches NO `locations` selector.
|
|
12668
|
+
*/
|
|
12669
|
+
var DeviceSelectorSchema = discriminatedUnion("kind", [
|
|
12670
|
+
object({ kind: literal("all") }),
|
|
12671
|
+
object({
|
|
12672
|
+
kind: literal("ids"),
|
|
12673
|
+
ids: array(number().int()).min(1)
|
|
12674
|
+
}),
|
|
12675
|
+
object({
|
|
12676
|
+
kind: literal("types"),
|
|
12677
|
+
types: array(_enum(DeviceType)).min(1)
|
|
12678
|
+
}),
|
|
12679
|
+
object({
|
|
12680
|
+
kind: literal("locations"),
|
|
12681
|
+
locations: array(string().min(1)).min(1)
|
|
12682
|
+
})
|
|
12683
|
+
]);
|
|
12684
|
+
var DeviceTokenScopeSchema = object({
|
|
12685
|
+
type: literal("device"),
|
|
12686
|
+
/** The device SET this grant covers — resolved against the live fleet. */
|
|
12687
|
+
selector: DeviceSelectorSchema,
|
|
12688
|
+
access: array(MethodAccessSchema).min(1),
|
|
12689
|
+
/**
|
|
12690
|
+
* Whether a grant on a PARENT device transparently covers its accessory
|
|
12691
|
+
* CHILDREN (siren / floodlight / PIR) via the persisted-parentage walk.
|
|
12692
|
+
* Direction is parent → children ONLY.
|
|
12693
|
+
*
|
|
12694
|
+
* Absent → the matcher DERIVES it from the access flavour: `view`
|
|
12695
|
+
* inherits (a camera viewer sees the camera's accessories), `create` /
|
|
12696
|
+
* `delete` do NOT (actuating/removing a child is an explicit act the
|
|
12697
|
+
* operator must grant on the child, not inherit from the parent). Set it
|
|
12698
|
+
* explicitly to override that default per grant.
|
|
12699
|
+
*/
|
|
12700
|
+
includeLinked: boolean().optional()
|
|
12701
|
+
});
|
|
12702
|
+
/**
|
|
12703
|
+
* v2 → v3 lazy migration. A pre-v3 `device` grant carried
|
|
12704
|
+
* `targets: string[]` (stringified deviceIds); it rewrites to the equivalent
|
|
12705
|
+
* `selector: {kind:'ids', ids}`. Applied as a `preprocess` so it runs on
|
|
12706
|
+
* EVERY parse path — stored records AND the JWT-carried scope arrays
|
|
12707
|
+
* normalised at the request boundary ({@link normalizeTokenScopes} in
|
|
12708
|
+
* `device-selector.ts`). Chosen over a one-time DB migration because a
|
|
12709
|
+
* migration cannot reach a JWT already in a client's hands; parse-time
|
|
12710
|
+
* migration covers both without a flag day. No cast — the raw object is read
|
|
12711
|
+
* through `Reflect.get` (its static type is `unknown`).
|
|
12712
|
+
*/
|
|
12713
|
+
function migrateLegacyTokenScope(raw) {
|
|
12714
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return raw;
|
|
12715
|
+
if (Reflect.get(raw, "type") !== "device") return raw;
|
|
12716
|
+
if (Reflect.get(raw, "selector") !== void 0) return raw;
|
|
12717
|
+
const targets = Reflect.get(raw, "targets");
|
|
12718
|
+
if (!Array.isArray(targets)) return raw;
|
|
12719
|
+
return {
|
|
12720
|
+
type: "device",
|
|
12721
|
+
selector: {
|
|
12722
|
+
kind: "ids",
|
|
12723
|
+
ids: targets.map((t) => typeof t === "string" ? Number(t) : t).filter((n) => typeof n === "number" && Number.isInteger(n))
|
|
12724
|
+
},
|
|
12725
|
+
access: Reflect.get(raw, "access")
|
|
12726
|
+
};
|
|
12727
|
+
}
|
|
12728
|
+
var TokenScopeSchema = preprocess(migrateLegacyTokenScope, discriminatedUnion("type", [
|
|
12729
|
+
object({
|
|
12730
|
+
type: literal("category"),
|
|
12731
|
+
target: CapScopeSchema,
|
|
12732
|
+
access: array(MethodAccessSchema).min(1)
|
|
12733
|
+
}),
|
|
12734
|
+
object({
|
|
12735
|
+
type: literal("capability"),
|
|
12736
|
+
target: string(),
|
|
12737
|
+
access: array(MethodAccessSchema).min(1)
|
|
12738
|
+
}),
|
|
12739
|
+
object({
|
|
12740
|
+
type: literal("addon"),
|
|
12741
|
+
target: string(),
|
|
12742
|
+
access: array(MethodAccessSchema).min(1)
|
|
12743
|
+
}),
|
|
12744
|
+
DeviceTokenScopeSchema
|
|
12745
|
+
]));
|
|
12746
|
+
object({
|
|
12747
|
+
id: string(),
|
|
12748
|
+
username: string(),
|
|
12749
|
+
passwordHash: string(),
|
|
12750
|
+
/**
|
|
12751
|
+
* Admin bypass. When true, the middleware skips the scope-access
|
|
12752
|
+
* check entirely. There is no other axis of privilege; the legacy
|
|
12753
|
+
* role enum collapsed onto this boolean in v2.
|
|
12754
|
+
*/
|
|
12755
|
+
isAdmin: boolean().default(false),
|
|
12756
|
+
allowedProviders: AllowedProviderSchema,
|
|
12757
|
+
allowedDevices: AllowedDevicesSchema,
|
|
12758
|
+
/**
|
|
12759
|
+
* Scopes granted to this user. Admins bypass; their `scopes` is
|
|
12760
|
+
* ignored. Non-admins without scopes are locked out of every
|
|
12761
|
+
* protected call.
|
|
12762
|
+
*/
|
|
12763
|
+
scopes: array(TokenScopeSchema).default([]),
|
|
12764
|
+
createdAt: number(),
|
|
12765
|
+
updatedAt: number()
|
|
12766
|
+
});
|
|
12767
|
+
object({
|
|
12768
|
+
id: string(),
|
|
12769
|
+
label: string(),
|
|
12770
|
+
isAdmin: boolean().default(false),
|
|
12771
|
+
allowedProviders: AllowedProviderSchema,
|
|
12772
|
+
allowedDevices: AllowedDevicesSchema,
|
|
12773
|
+
tokenHash: string(),
|
|
12774
|
+
tokenPrefix: string(),
|
|
12775
|
+
createdAt: number(),
|
|
12776
|
+
lastUsedAt: number().optional()
|
|
12777
|
+
});
|
|
12778
|
+
object({
|
|
12779
|
+
id: string(),
|
|
12780
|
+
userId: string(),
|
|
12781
|
+
name: string(),
|
|
12782
|
+
tokenHash: string(),
|
|
12783
|
+
tokenPrefix: string(),
|
|
12784
|
+
scopes: array(TokenScopeSchema),
|
|
12785
|
+
expiresAt: number().nullish(),
|
|
12786
|
+
lastUsedAt: number().nullish(),
|
|
12787
|
+
createdAt: number()
|
|
12788
|
+
});
|
|
12789
|
+
/** What a share-view grant lets its holder see. */
|
|
12790
|
+
var ShareViewGrantSchema = object({
|
|
12791
|
+
kind: _enum(SHARE_VIEW_KINDS),
|
|
12792
|
+
deviceIds: array(number().int().nonnegative()).min(1).max(64),
|
|
12793
|
+
/** Talk-back, opt-in at mint time; absent means off. */
|
|
12794
|
+
talk: boolean().optional()
|
|
12795
|
+
});
|
|
12796
|
+
var ShareViewScopeSchema = object({
|
|
12797
|
+
type: literal("share-view"),
|
|
12798
|
+
grant: ShareViewGrantSchema
|
|
12799
|
+
});
|
|
12800
|
+
var AddonRoutesScopeSchema = object({
|
|
12801
|
+
type: literal("addon-routes"),
|
|
12802
|
+
access: array(MethodAccessSchema).min(1)
|
|
12803
|
+
});
|
|
12804
|
+
var CredentialScopeSchema = union([
|
|
12805
|
+
literal("*"),
|
|
12806
|
+
ShareViewScopeSchema,
|
|
12807
|
+
AddonRoutesScopeSchema,
|
|
12808
|
+
TokenScopeSchema
|
|
12809
|
+
]);
|
|
12810
|
+
object({
|
|
12811
|
+
kind: literal("credential"),
|
|
12812
|
+
sub: string().min(1),
|
|
12813
|
+
jti: string().min(16),
|
|
12814
|
+
scopes: array(CredentialScopeSchema).min(1)
|
|
12815
|
+
});
|
|
12587
12816
|
_enum(["new-session", "step-up"]);
|
|
12588
12817
|
/** The languages the hub's app landing pages are written in (D858). */
|
|
12589
12818
|
var AppPageLangSchema = _enum(["en", "it"]);
|
|
@@ -43980,202 +44209,6 @@ method(object({}), object({ rules: array(NcRuleSchema) }), { auth: "admin" }), m
|
|
|
43980
44209
|
auth: "admin"
|
|
43981
44210
|
}), method(NcAlarmSensorsInputSchema, NcAlarmSensorsSchema, { auth: "admin" });
|
|
43982
44211
|
/**
|
|
43983
|
-
* Zod schemas for persisted record types.
|
|
43984
|
-
*
|
|
43985
|
-
* These schemas serve as the single source of truth for types that are
|
|
43986
|
-
* stored in the settings-store backend and retrieved via tRPC. They
|
|
43987
|
-
* replace the manual TypeScript interfaces with schema-derived types,
|
|
43988
|
-
* enabling runtime validation when reading from the backend.
|
|
43989
|
-
*
|
|
43990
|
-
* Convention: each schema is named `<Type>Schema`, the inferred TS type
|
|
43991
|
-
* keeps the original name for backward compatibility.
|
|
43992
|
-
*/
|
|
43993
|
-
/**
|
|
43994
|
-
* Auth model (v2 — 2026-05-12 caps-only):
|
|
43995
|
-
*
|
|
43996
|
-
* Two principals:
|
|
43997
|
-
* - `isAdmin: true` — full bypass. Admin scope set is ignored.
|
|
43998
|
-
* - `isAdmin: false` — every call gated by `scopes` (see TokenScope).
|
|
43999
|
-
*
|
|
44000
|
-
* No role enum. There used to be `viewer / agent / scoped` and earlier
|
|
44001
|
-
* `super_admin` — collapsed onto the single boolean because every
|
|
44002
|
-
* non-admin caller is governed by the same scope-check rules; the
|
|
44003
|
-
* distinction was only ever used to route role-specific procedures
|
|
44004
|
-
* which we no longer have. CLI / webhook integrations are `cst_*` tokens
|
|
44005
|
-
* with `isAdmin: false` + an explicit scope list.
|
|
44006
|
-
*/
|
|
44007
|
-
/** Per-method access flavour. Materialised on every cap method via codegen. */
|
|
44008
|
-
var MethodAccessSchema = _enum([
|
|
44009
|
-
"view",
|
|
44010
|
-
"create",
|
|
44011
|
-
"delete"
|
|
44012
|
-
]);
|
|
44013
|
-
/**
|
|
44014
|
-
* A single scope grant. Three forms — checked in matcher with OR
|
|
44015
|
-
* semantics; the first match decides whether the call passes:
|
|
44016
|
-
*
|
|
44017
|
-
* - `category` — broadest. `target: 'device' | 'system'` selects every
|
|
44018
|
-
* cap with the matching `scope` declaration. New caps inherit grants
|
|
44019
|
-
* automatically — adding a device cap to the codebase makes it
|
|
44020
|
-
* reachable to every user with `category:device [...]` without a
|
|
44021
|
-
* re-grant. Use this for "family viewer" / "operator" tiers.
|
|
44022
|
-
*
|
|
44023
|
-
* - `addon` — every cap that ships inside a given addon id. Niche;
|
|
44024
|
-
* useful when an integration needs to interact with one specific
|
|
44025
|
-
* addon's surface regardless of how many caps it exports.
|
|
44026
|
-
*
|
|
44027
|
-
* - `capability` — the most precise form. Single cap name. Use for
|
|
44028
|
-
* integration tokens where you want to grant `addons.installPackage`
|
|
44029
|
-
* and nothing else.
|
|
44030
|
-
*
|
|
44031
|
-
* `access` is REQUIRED with min 1 element. `admin` bypass is the
|
|
44032
|
-
* "give me everything" escape; there is no wildcard scope.
|
|
44033
|
-
*/
|
|
44034
|
-
var AllowedProviderSchema = union([literal("*"), array(string())]);
|
|
44035
|
-
var AllowedDevicesSchema = record(string(), union([literal("*"), array(string())]));
|
|
44036
|
-
var CapScopeSchema = _enum(["device", "system"]);
|
|
44037
|
-
/**
|
|
44038
|
-
* DeviceSelector (scope model v3 — 2026-08-12).
|
|
44039
|
-
*
|
|
44040
|
-
* A `device` grant no longer carries a frozen list of deviceIds. It carries
|
|
44041
|
-
* a SELECTOR the matcher resolves against the live fleet, so the grant can be
|
|
44042
|
-
* DYNAMIC: a `types:['camera']` selector automatically covers a camera added
|
|
44043
|
-
* AFTER the grant was minted — no re-grant, no re-login.
|
|
44044
|
-
*
|
|
44045
|
-
* - `all` — every device in the deployment. The broad viewer/operator
|
|
44046
|
-
* lever without a `category` grant (a `category` grant also covers device
|
|
44047
|
-
* caps that carry no deviceId; `all` is specifically the device set).
|
|
44048
|
-
* - `ids` — an explicit deviceId list. This is what a v2 `device:[…]`
|
|
44049
|
-
* grant migrates to (see {@link TokenScopeSchema}); STATIC — a new camera
|
|
44050
|
-
* is NOT covered until the grant is edited.
|
|
44051
|
-
* - `types` — every device of a `DeviceType` (e.g. every `camera`).
|
|
44052
|
-
* DYNAMIC. A device that changes type, or a new device of the type,
|
|
44053
|
-
* re-resolves on the next request.
|
|
44054
|
-
* - `locations` — every device whose operator-assigned `location` label is
|
|
44055
|
-
* in the set (e.g. "Garden", "Front door"). DYNAMIC. A device with a
|
|
44056
|
-
* null/unset location matches NO `locations` selector.
|
|
44057
|
-
*/
|
|
44058
|
-
var DeviceSelectorSchema = discriminatedUnion("kind", [
|
|
44059
|
-
object({ kind: literal("all") }),
|
|
44060
|
-
object({
|
|
44061
|
-
kind: literal("ids"),
|
|
44062
|
-
ids: array(number().int()).min(1)
|
|
44063
|
-
}),
|
|
44064
|
-
object({
|
|
44065
|
-
kind: literal("types"),
|
|
44066
|
-
types: array(_enum(DeviceType)).min(1)
|
|
44067
|
-
}),
|
|
44068
|
-
object({
|
|
44069
|
-
kind: literal("locations"),
|
|
44070
|
-
locations: array(string().min(1)).min(1)
|
|
44071
|
-
})
|
|
44072
|
-
]);
|
|
44073
|
-
var DeviceTokenScopeSchema = object({
|
|
44074
|
-
type: literal("device"),
|
|
44075
|
-
/** The device SET this grant covers — resolved against the live fleet. */
|
|
44076
|
-
selector: DeviceSelectorSchema,
|
|
44077
|
-
access: array(MethodAccessSchema).min(1),
|
|
44078
|
-
/**
|
|
44079
|
-
* Whether a grant on a PARENT device transparently covers its accessory
|
|
44080
|
-
* CHILDREN (siren / floodlight / PIR) via the persisted-parentage walk.
|
|
44081
|
-
* Direction is parent → children ONLY.
|
|
44082
|
-
*
|
|
44083
|
-
* Absent → the matcher DERIVES it from the access flavour: `view`
|
|
44084
|
-
* inherits (a camera viewer sees the camera's accessories), `create` /
|
|
44085
|
-
* `delete` do NOT (actuating/removing a child is an explicit act the
|
|
44086
|
-
* operator must grant on the child, not inherit from the parent). Set it
|
|
44087
|
-
* explicitly to override that default per grant.
|
|
44088
|
-
*/
|
|
44089
|
-
includeLinked: boolean().optional()
|
|
44090
|
-
});
|
|
44091
|
-
/**
|
|
44092
|
-
* v2 → v3 lazy migration. A pre-v3 `device` grant carried
|
|
44093
|
-
* `targets: string[]` (stringified deviceIds); it rewrites to the equivalent
|
|
44094
|
-
* `selector: {kind:'ids', ids}`. Applied as a `preprocess` so it runs on
|
|
44095
|
-
* EVERY parse path — stored records AND the JWT-carried scope arrays
|
|
44096
|
-
* normalised at the request boundary ({@link normalizeTokenScopes} in
|
|
44097
|
-
* `device-selector.ts`). Chosen over a one-time DB migration because a
|
|
44098
|
-
* migration cannot reach a JWT already in a client's hands; parse-time
|
|
44099
|
-
* migration covers both without a flag day. No cast — the raw object is read
|
|
44100
|
-
* through `Reflect.get` (its static type is `unknown`).
|
|
44101
|
-
*/
|
|
44102
|
-
function migrateLegacyTokenScope(raw) {
|
|
44103
|
-
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return raw;
|
|
44104
|
-
if (Reflect.get(raw, "type") !== "device") return raw;
|
|
44105
|
-
if (Reflect.get(raw, "selector") !== void 0) return raw;
|
|
44106
|
-
const targets = Reflect.get(raw, "targets");
|
|
44107
|
-
if (!Array.isArray(targets)) return raw;
|
|
44108
|
-
return {
|
|
44109
|
-
type: "device",
|
|
44110
|
-
selector: {
|
|
44111
|
-
kind: "ids",
|
|
44112
|
-
ids: targets.map((t) => typeof t === "string" ? Number(t) : t).filter((n) => typeof n === "number" && Number.isInteger(n))
|
|
44113
|
-
},
|
|
44114
|
-
access: Reflect.get(raw, "access")
|
|
44115
|
-
};
|
|
44116
|
-
}
|
|
44117
|
-
var TokenScopeSchema = preprocess(migrateLegacyTokenScope, discriminatedUnion("type", [
|
|
44118
|
-
object({
|
|
44119
|
-
type: literal("category"),
|
|
44120
|
-
target: CapScopeSchema,
|
|
44121
|
-
access: array(MethodAccessSchema).min(1)
|
|
44122
|
-
}),
|
|
44123
|
-
object({
|
|
44124
|
-
type: literal("capability"),
|
|
44125
|
-
target: string(),
|
|
44126
|
-
access: array(MethodAccessSchema).min(1)
|
|
44127
|
-
}),
|
|
44128
|
-
object({
|
|
44129
|
-
type: literal("addon"),
|
|
44130
|
-
target: string(),
|
|
44131
|
-
access: array(MethodAccessSchema).min(1)
|
|
44132
|
-
}),
|
|
44133
|
-
DeviceTokenScopeSchema
|
|
44134
|
-
]));
|
|
44135
|
-
object({
|
|
44136
|
-
id: string(),
|
|
44137
|
-
username: string(),
|
|
44138
|
-
passwordHash: string(),
|
|
44139
|
-
/**
|
|
44140
|
-
* Admin bypass. When true, the middleware skips the scope-access
|
|
44141
|
-
* check entirely. There is no other axis of privilege; the legacy
|
|
44142
|
-
* role enum collapsed onto this boolean in v2.
|
|
44143
|
-
*/
|
|
44144
|
-
isAdmin: boolean().default(false),
|
|
44145
|
-
allowedProviders: AllowedProviderSchema,
|
|
44146
|
-
allowedDevices: AllowedDevicesSchema,
|
|
44147
|
-
/**
|
|
44148
|
-
* Scopes granted to this user. Admins bypass; their `scopes` is
|
|
44149
|
-
* ignored. Non-admins without scopes are locked out of every
|
|
44150
|
-
* protected call.
|
|
44151
|
-
*/
|
|
44152
|
-
scopes: array(TokenScopeSchema).default([]),
|
|
44153
|
-
createdAt: number(),
|
|
44154
|
-
updatedAt: number()
|
|
44155
|
-
});
|
|
44156
|
-
object({
|
|
44157
|
-
id: string(),
|
|
44158
|
-
label: string(),
|
|
44159
|
-
isAdmin: boolean().default(false),
|
|
44160
|
-
allowedProviders: AllowedProviderSchema,
|
|
44161
|
-
allowedDevices: AllowedDevicesSchema,
|
|
44162
|
-
tokenHash: string(),
|
|
44163
|
-
tokenPrefix: string(),
|
|
44164
|
-
createdAt: number(),
|
|
44165
|
-
lastUsedAt: number().optional()
|
|
44166
|
-
});
|
|
44167
|
-
object({
|
|
44168
|
-
id: string(),
|
|
44169
|
-
userId: string(),
|
|
44170
|
-
name: string(),
|
|
44171
|
-
tokenHash: string(),
|
|
44172
|
-
tokenPrefix: string(),
|
|
44173
|
-
scopes: array(TokenScopeSchema),
|
|
44174
|
-
expiresAt: number().nullish(),
|
|
44175
|
-
lastUsedAt: number().nullish(),
|
|
44176
|
-
createdAt: number()
|
|
44177
|
-
});
|
|
44178
|
-
/**
|
|
44179
44212
|
* `oauth-integration` — a collection cap by which an addon declares
|
|
44180
44213
|
* itself a linkable OAuth client of the hub's core `/oauth2/*` server.
|
|
44181
44214
|
* Each provider returns a static descriptor; the core enumerates them
|
package/dist/addon.mjs
CHANGED
|
@@ -7805,6 +7805,12 @@ function normalizeAddonInitResult(result) {
|
|
|
7805
7805
|
if (Array.isArray(result)) return { providers: result };
|
|
7806
7806
|
return result;
|
|
7807
7807
|
}
|
|
7808
|
+
/**
|
|
7809
|
+
* The share-view scope kinds a `csv_*` share token can carry. The hub mints
|
|
7810
|
+
* and validates them (`share-token.service.ts` builds its enum from this
|
|
7811
|
+
* list); a data plane names the kinds it ACCEPTS in `share`.
|
|
7812
|
+
*/
|
|
7813
|
+
var SHARE_VIEW_KINDS = ["grid-view", "events-view"];
|
|
7808
7814
|
/** The wire shape of {@link PeerBytesTicket} — see the type for what it is. */
|
|
7809
7815
|
var PeerBytesTicketSchema = object({
|
|
7810
7816
|
/** `http://127.0.0.1:<port>/<token>`. One `GET` takes it. */
|
|
@@ -12561,6 +12567,229 @@ var ConvertResultSchema = object({
|
|
|
12561
12567
|
files: array(string()).readonly()
|
|
12562
12568
|
})).readonly()
|
|
12563
12569
|
});
|
|
12570
|
+
/**
|
|
12571
|
+
* Zod schemas for persisted record types.
|
|
12572
|
+
*
|
|
12573
|
+
* These schemas serve as the single source of truth for types that are
|
|
12574
|
+
* stored in the settings-store backend and retrieved via tRPC. They
|
|
12575
|
+
* replace the manual TypeScript interfaces with schema-derived types,
|
|
12576
|
+
* enabling runtime validation when reading from the backend.
|
|
12577
|
+
*
|
|
12578
|
+
* Convention: each schema is named `<Type>Schema`, the inferred TS type
|
|
12579
|
+
* keeps the original name for backward compatibility.
|
|
12580
|
+
*/
|
|
12581
|
+
/**
|
|
12582
|
+
* Auth model (v2 — 2026-05-12 caps-only):
|
|
12583
|
+
*
|
|
12584
|
+
* Two principals:
|
|
12585
|
+
* - `isAdmin: true` — full bypass. Admin scope set is ignored.
|
|
12586
|
+
* - `isAdmin: false` — every call gated by `scopes` (see TokenScope).
|
|
12587
|
+
*
|
|
12588
|
+
* No role enum. There used to be `viewer / agent / scoped` and earlier
|
|
12589
|
+
* `super_admin` — collapsed onto the single boolean because every
|
|
12590
|
+
* non-admin caller is governed by the same scope-check rules; the
|
|
12591
|
+
* distinction was only ever used to route role-specific procedures
|
|
12592
|
+
* which we no longer have. CLI / webhook integrations are `cst_*` tokens
|
|
12593
|
+
* with `isAdmin: false` + an explicit scope list.
|
|
12594
|
+
*/
|
|
12595
|
+
/** Per-method access flavour. Materialised on every cap method via codegen. */
|
|
12596
|
+
var MethodAccessSchema = _enum([
|
|
12597
|
+
"view",
|
|
12598
|
+
"create",
|
|
12599
|
+
"delete"
|
|
12600
|
+
]);
|
|
12601
|
+
/**
|
|
12602
|
+
* A single scope grant. Three forms — checked in matcher with OR
|
|
12603
|
+
* semantics; the first match decides whether the call passes:
|
|
12604
|
+
*
|
|
12605
|
+
* - `category` — broadest. `target: 'device' | 'system'` selects every
|
|
12606
|
+
* cap with the matching `scope` declaration. New caps inherit grants
|
|
12607
|
+
* automatically — adding a device cap to the codebase makes it
|
|
12608
|
+
* reachable to every user with `category:device [...]` without a
|
|
12609
|
+
* re-grant. Use this for "family viewer" / "operator" tiers.
|
|
12610
|
+
*
|
|
12611
|
+
* - `addon` — every cap that ships inside a given addon id. Niche;
|
|
12612
|
+
* useful when an integration needs to interact with one specific
|
|
12613
|
+
* addon's surface regardless of how many caps it exports.
|
|
12614
|
+
*
|
|
12615
|
+
* - `capability` — the most precise form. Single cap name. Use for
|
|
12616
|
+
* integration tokens where you want to grant `addons.installPackage`
|
|
12617
|
+
* and nothing else.
|
|
12618
|
+
*
|
|
12619
|
+
* `access` is REQUIRED with min 1 element. `admin` bypass is the
|
|
12620
|
+
* "give me everything" escape; there is no wildcard scope.
|
|
12621
|
+
*/
|
|
12622
|
+
var AllowedProviderSchema = union([literal("*"), array(string())]);
|
|
12623
|
+
var AllowedDevicesSchema = record(string(), union([literal("*"), array(string())]));
|
|
12624
|
+
var CapScopeSchema = _enum(["device", "system"]);
|
|
12625
|
+
/**
|
|
12626
|
+
* DeviceSelector (scope model v3 — 2026-08-12).
|
|
12627
|
+
*
|
|
12628
|
+
* A `device` grant no longer carries a frozen list of deviceIds. It carries
|
|
12629
|
+
* a SELECTOR the matcher resolves against the live fleet, so the grant can be
|
|
12630
|
+
* DYNAMIC: a `types:['camera']` selector automatically covers a camera added
|
|
12631
|
+
* AFTER the grant was minted — no re-grant, no re-login.
|
|
12632
|
+
*
|
|
12633
|
+
* - `all` — every device in the deployment. The broad viewer/operator
|
|
12634
|
+
* lever without a `category` grant (a `category` grant also covers device
|
|
12635
|
+
* caps that carry no deviceId; `all` is specifically the device set).
|
|
12636
|
+
* - `ids` — an explicit deviceId list. This is what a v2 `device:[…]`
|
|
12637
|
+
* grant migrates to (see {@link TokenScopeSchema}); STATIC — a new camera
|
|
12638
|
+
* is NOT covered until the grant is edited.
|
|
12639
|
+
* - `types` — every device of a `DeviceType` (e.g. every `camera`).
|
|
12640
|
+
* DYNAMIC. A device that changes type, or a new device of the type,
|
|
12641
|
+
* re-resolves on the next request.
|
|
12642
|
+
* - `locations` — every device whose operator-assigned `location` label is
|
|
12643
|
+
* in the set (e.g. "Garden", "Front door"). DYNAMIC. A device with a
|
|
12644
|
+
* null/unset location matches NO `locations` selector.
|
|
12645
|
+
*/
|
|
12646
|
+
var DeviceSelectorSchema = discriminatedUnion("kind", [
|
|
12647
|
+
object({ kind: literal("all") }),
|
|
12648
|
+
object({
|
|
12649
|
+
kind: literal("ids"),
|
|
12650
|
+
ids: array(number().int()).min(1)
|
|
12651
|
+
}),
|
|
12652
|
+
object({
|
|
12653
|
+
kind: literal("types"),
|
|
12654
|
+
types: array(_enum(DeviceType)).min(1)
|
|
12655
|
+
}),
|
|
12656
|
+
object({
|
|
12657
|
+
kind: literal("locations"),
|
|
12658
|
+
locations: array(string().min(1)).min(1)
|
|
12659
|
+
})
|
|
12660
|
+
]);
|
|
12661
|
+
var DeviceTokenScopeSchema = object({
|
|
12662
|
+
type: literal("device"),
|
|
12663
|
+
/** The device SET this grant covers — resolved against the live fleet. */
|
|
12664
|
+
selector: DeviceSelectorSchema,
|
|
12665
|
+
access: array(MethodAccessSchema).min(1),
|
|
12666
|
+
/**
|
|
12667
|
+
* Whether a grant on a PARENT device transparently covers its accessory
|
|
12668
|
+
* CHILDREN (siren / floodlight / PIR) via the persisted-parentage walk.
|
|
12669
|
+
* Direction is parent → children ONLY.
|
|
12670
|
+
*
|
|
12671
|
+
* Absent → the matcher DERIVES it from the access flavour: `view`
|
|
12672
|
+
* inherits (a camera viewer sees the camera's accessories), `create` /
|
|
12673
|
+
* `delete` do NOT (actuating/removing a child is an explicit act the
|
|
12674
|
+
* operator must grant on the child, not inherit from the parent). Set it
|
|
12675
|
+
* explicitly to override that default per grant.
|
|
12676
|
+
*/
|
|
12677
|
+
includeLinked: boolean().optional()
|
|
12678
|
+
});
|
|
12679
|
+
/**
|
|
12680
|
+
* v2 → v3 lazy migration. A pre-v3 `device` grant carried
|
|
12681
|
+
* `targets: string[]` (stringified deviceIds); it rewrites to the equivalent
|
|
12682
|
+
* `selector: {kind:'ids', ids}`. Applied as a `preprocess` so it runs on
|
|
12683
|
+
* EVERY parse path — stored records AND the JWT-carried scope arrays
|
|
12684
|
+
* normalised at the request boundary ({@link normalizeTokenScopes} in
|
|
12685
|
+
* `device-selector.ts`). Chosen over a one-time DB migration because a
|
|
12686
|
+
* migration cannot reach a JWT already in a client's hands; parse-time
|
|
12687
|
+
* migration covers both without a flag day. No cast — the raw object is read
|
|
12688
|
+
* through `Reflect.get` (its static type is `unknown`).
|
|
12689
|
+
*/
|
|
12690
|
+
function migrateLegacyTokenScope(raw) {
|
|
12691
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return raw;
|
|
12692
|
+
if (Reflect.get(raw, "type") !== "device") return raw;
|
|
12693
|
+
if (Reflect.get(raw, "selector") !== void 0) return raw;
|
|
12694
|
+
const targets = Reflect.get(raw, "targets");
|
|
12695
|
+
if (!Array.isArray(targets)) return raw;
|
|
12696
|
+
return {
|
|
12697
|
+
type: "device",
|
|
12698
|
+
selector: {
|
|
12699
|
+
kind: "ids",
|
|
12700
|
+
ids: targets.map((t) => typeof t === "string" ? Number(t) : t).filter((n) => typeof n === "number" && Number.isInteger(n))
|
|
12701
|
+
},
|
|
12702
|
+
access: Reflect.get(raw, "access")
|
|
12703
|
+
};
|
|
12704
|
+
}
|
|
12705
|
+
var TokenScopeSchema = preprocess(migrateLegacyTokenScope, discriminatedUnion("type", [
|
|
12706
|
+
object({
|
|
12707
|
+
type: literal("category"),
|
|
12708
|
+
target: CapScopeSchema,
|
|
12709
|
+
access: array(MethodAccessSchema).min(1)
|
|
12710
|
+
}),
|
|
12711
|
+
object({
|
|
12712
|
+
type: literal("capability"),
|
|
12713
|
+
target: string(),
|
|
12714
|
+
access: array(MethodAccessSchema).min(1)
|
|
12715
|
+
}),
|
|
12716
|
+
object({
|
|
12717
|
+
type: literal("addon"),
|
|
12718
|
+
target: string(),
|
|
12719
|
+
access: array(MethodAccessSchema).min(1)
|
|
12720
|
+
}),
|
|
12721
|
+
DeviceTokenScopeSchema
|
|
12722
|
+
]));
|
|
12723
|
+
object({
|
|
12724
|
+
id: string(),
|
|
12725
|
+
username: string(),
|
|
12726
|
+
passwordHash: string(),
|
|
12727
|
+
/**
|
|
12728
|
+
* Admin bypass. When true, the middleware skips the scope-access
|
|
12729
|
+
* check entirely. There is no other axis of privilege; the legacy
|
|
12730
|
+
* role enum collapsed onto this boolean in v2.
|
|
12731
|
+
*/
|
|
12732
|
+
isAdmin: boolean().default(false),
|
|
12733
|
+
allowedProviders: AllowedProviderSchema,
|
|
12734
|
+
allowedDevices: AllowedDevicesSchema,
|
|
12735
|
+
/**
|
|
12736
|
+
* Scopes granted to this user. Admins bypass; their `scopes` is
|
|
12737
|
+
* ignored. Non-admins without scopes are locked out of every
|
|
12738
|
+
* protected call.
|
|
12739
|
+
*/
|
|
12740
|
+
scopes: array(TokenScopeSchema).default([]),
|
|
12741
|
+
createdAt: number(),
|
|
12742
|
+
updatedAt: number()
|
|
12743
|
+
});
|
|
12744
|
+
object({
|
|
12745
|
+
id: string(),
|
|
12746
|
+
label: string(),
|
|
12747
|
+
isAdmin: boolean().default(false),
|
|
12748
|
+
allowedProviders: AllowedProviderSchema,
|
|
12749
|
+
allowedDevices: AllowedDevicesSchema,
|
|
12750
|
+
tokenHash: string(),
|
|
12751
|
+
tokenPrefix: string(),
|
|
12752
|
+
createdAt: number(),
|
|
12753
|
+
lastUsedAt: number().optional()
|
|
12754
|
+
});
|
|
12755
|
+
object({
|
|
12756
|
+
id: string(),
|
|
12757
|
+
userId: string(),
|
|
12758
|
+
name: string(),
|
|
12759
|
+
tokenHash: string(),
|
|
12760
|
+
tokenPrefix: string(),
|
|
12761
|
+
scopes: array(TokenScopeSchema),
|
|
12762
|
+
expiresAt: number().nullish(),
|
|
12763
|
+
lastUsedAt: number().nullish(),
|
|
12764
|
+
createdAt: number()
|
|
12765
|
+
});
|
|
12766
|
+
/** What a share-view grant lets its holder see. */
|
|
12767
|
+
var ShareViewGrantSchema = object({
|
|
12768
|
+
kind: _enum(SHARE_VIEW_KINDS),
|
|
12769
|
+
deviceIds: array(number().int().nonnegative()).min(1).max(64),
|
|
12770
|
+
/** Talk-back, opt-in at mint time; absent means off. */
|
|
12771
|
+
talk: boolean().optional()
|
|
12772
|
+
});
|
|
12773
|
+
var ShareViewScopeSchema = object({
|
|
12774
|
+
type: literal("share-view"),
|
|
12775
|
+
grant: ShareViewGrantSchema
|
|
12776
|
+
});
|
|
12777
|
+
var AddonRoutesScopeSchema = object({
|
|
12778
|
+
type: literal("addon-routes"),
|
|
12779
|
+
access: array(MethodAccessSchema).min(1)
|
|
12780
|
+
});
|
|
12781
|
+
var CredentialScopeSchema = union([
|
|
12782
|
+
literal("*"),
|
|
12783
|
+
ShareViewScopeSchema,
|
|
12784
|
+
AddonRoutesScopeSchema,
|
|
12785
|
+
TokenScopeSchema
|
|
12786
|
+
]);
|
|
12787
|
+
object({
|
|
12788
|
+
kind: literal("credential"),
|
|
12789
|
+
sub: string().min(1),
|
|
12790
|
+
jti: string().min(16),
|
|
12791
|
+
scopes: array(CredentialScopeSchema).min(1)
|
|
12792
|
+
});
|
|
12564
12793
|
_enum(["new-session", "step-up"]);
|
|
12565
12794
|
/** The languages the hub's app landing pages are written in (D858). */
|
|
12566
12795
|
var AppPageLangSchema = _enum(["en", "it"]);
|
|
@@ -43957,202 +44186,6 @@ method(object({}), object({ rules: array(NcRuleSchema) }), { auth: "admin" }), m
|
|
|
43957
44186
|
auth: "admin"
|
|
43958
44187
|
}), method(NcAlarmSensorsInputSchema, NcAlarmSensorsSchema, { auth: "admin" });
|
|
43959
44188
|
/**
|
|
43960
|
-
* Zod schemas for persisted record types.
|
|
43961
|
-
*
|
|
43962
|
-
* These schemas serve as the single source of truth for types that are
|
|
43963
|
-
* stored in the settings-store backend and retrieved via tRPC. They
|
|
43964
|
-
* replace the manual TypeScript interfaces with schema-derived types,
|
|
43965
|
-
* enabling runtime validation when reading from the backend.
|
|
43966
|
-
*
|
|
43967
|
-
* Convention: each schema is named `<Type>Schema`, the inferred TS type
|
|
43968
|
-
* keeps the original name for backward compatibility.
|
|
43969
|
-
*/
|
|
43970
|
-
/**
|
|
43971
|
-
* Auth model (v2 — 2026-05-12 caps-only):
|
|
43972
|
-
*
|
|
43973
|
-
* Two principals:
|
|
43974
|
-
* - `isAdmin: true` — full bypass. Admin scope set is ignored.
|
|
43975
|
-
* - `isAdmin: false` — every call gated by `scopes` (see TokenScope).
|
|
43976
|
-
*
|
|
43977
|
-
* No role enum. There used to be `viewer / agent / scoped` and earlier
|
|
43978
|
-
* `super_admin` — collapsed onto the single boolean because every
|
|
43979
|
-
* non-admin caller is governed by the same scope-check rules; the
|
|
43980
|
-
* distinction was only ever used to route role-specific procedures
|
|
43981
|
-
* which we no longer have. CLI / webhook integrations are `cst_*` tokens
|
|
43982
|
-
* with `isAdmin: false` + an explicit scope list.
|
|
43983
|
-
*/
|
|
43984
|
-
/** Per-method access flavour. Materialised on every cap method via codegen. */
|
|
43985
|
-
var MethodAccessSchema = _enum([
|
|
43986
|
-
"view",
|
|
43987
|
-
"create",
|
|
43988
|
-
"delete"
|
|
43989
|
-
]);
|
|
43990
|
-
/**
|
|
43991
|
-
* A single scope grant. Three forms — checked in matcher with OR
|
|
43992
|
-
* semantics; the first match decides whether the call passes:
|
|
43993
|
-
*
|
|
43994
|
-
* - `category` — broadest. `target: 'device' | 'system'` selects every
|
|
43995
|
-
* cap with the matching `scope` declaration. New caps inherit grants
|
|
43996
|
-
* automatically — adding a device cap to the codebase makes it
|
|
43997
|
-
* reachable to every user with `category:device [...]` without a
|
|
43998
|
-
* re-grant. Use this for "family viewer" / "operator" tiers.
|
|
43999
|
-
*
|
|
44000
|
-
* - `addon` — every cap that ships inside a given addon id. Niche;
|
|
44001
|
-
* useful when an integration needs to interact with one specific
|
|
44002
|
-
* addon's surface regardless of how many caps it exports.
|
|
44003
|
-
*
|
|
44004
|
-
* - `capability` — the most precise form. Single cap name. Use for
|
|
44005
|
-
* integration tokens where you want to grant `addons.installPackage`
|
|
44006
|
-
* and nothing else.
|
|
44007
|
-
*
|
|
44008
|
-
* `access` is REQUIRED with min 1 element. `admin` bypass is the
|
|
44009
|
-
* "give me everything" escape; there is no wildcard scope.
|
|
44010
|
-
*/
|
|
44011
|
-
var AllowedProviderSchema = union([literal("*"), array(string())]);
|
|
44012
|
-
var AllowedDevicesSchema = record(string(), union([literal("*"), array(string())]));
|
|
44013
|
-
var CapScopeSchema = _enum(["device", "system"]);
|
|
44014
|
-
/**
|
|
44015
|
-
* DeviceSelector (scope model v3 — 2026-08-12).
|
|
44016
|
-
*
|
|
44017
|
-
* A `device` grant no longer carries a frozen list of deviceIds. It carries
|
|
44018
|
-
* a SELECTOR the matcher resolves against the live fleet, so the grant can be
|
|
44019
|
-
* DYNAMIC: a `types:['camera']` selector automatically covers a camera added
|
|
44020
|
-
* AFTER the grant was minted — no re-grant, no re-login.
|
|
44021
|
-
*
|
|
44022
|
-
* - `all` — every device in the deployment. The broad viewer/operator
|
|
44023
|
-
* lever without a `category` grant (a `category` grant also covers device
|
|
44024
|
-
* caps that carry no deviceId; `all` is specifically the device set).
|
|
44025
|
-
* - `ids` — an explicit deviceId list. This is what a v2 `device:[…]`
|
|
44026
|
-
* grant migrates to (see {@link TokenScopeSchema}); STATIC — a new camera
|
|
44027
|
-
* is NOT covered until the grant is edited.
|
|
44028
|
-
* - `types` — every device of a `DeviceType` (e.g. every `camera`).
|
|
44029
|
-
* DYNAMIC. A device that changes type, or a new device of the type,
|
|
44030
|
-
* re-resolves on the next request.
|
|
44031
|
-
* - `locations` — every device whose operator-assigned `location` label is
|
|
44032
|
-
* in the set (e.g. "Garden", "Front door"). DYNAMIC. A device with a
|
|
44033
|
-
* null/unset location matches NO `locations` selector.
|
|
44034
|
-
*/
|
|
44035
|
-
var DeviceSelectorSchema = discriminatedUnion("kind", [
|
|
44036
|
-
object({ kind: literal("all") }),
|
|
44037
|
-
object({
|
|
44038
|
-
kind: literal("ids"),
|
|
44039
|
-
ids: array(number().int()).min(1)
|
|
44040
|
-
}),
|
|
44041
|
-
object({
|
|
44042
|
-
kind: literal("types"),
|
|
44043
|
-
types: array(_enum(DeviceType)).min(1)
|
|
44044
|
-
}),
|
|
44045
|
-
object({
|
|
44046
|
-
kind: literal("locations"),
|
|
44047
|
-
locations: array(string().min(1)).min(1)
|
|
44048
|
-
})
|
|
44049
|
-
]);
|
|
44050
|
-
var DeviceTokenScopeSchema = object({
|
|
44051
|
-
type: literal("device"),
|
|
44052
|
-
/** The device SET this grant covers — resolved against the live fleet. */
|
|
44053
|
-
selector: DeviceSelectorSchema,
|
|
44054
|
-
access: array(MethodAccessSchema).min(1),
|
|
44055
|
-
/**
|
|
44056
|
-
* Whether a grant on a PARENT device transparently covers its accessory
|
|
44057
|
-
* CHILDREN (siren / floodlight / PIR) via the persisted-parentage walk.
|
|
44058
|
-
* Direction is parent → children ONLY.
|
|
44059
|
-
*
|
|
44060
|
-
* Absent → the matcher DERIVES it from the access flavour: `view`
|
|
44061
|
-
* inherits (a camera viewer sees the camera's accessories), `create` /
|
|
44062
|
-
* `delete` do NOT (actuating/removing a child is an explicit act the
|
|
44063
|
-
* operator must grant on the child, not inherit from the parent). Set it
|
|
44064
|
-
* explicitly to override that default per grant.
|
|
44065
|
-
*/
|
|
44066
|
-
includeLinked: boolean().optional()
|
|
44067
|
-
});
|
|
44068
|
-
/**
|
|
44069
|
-
* v2 → v3 lazy migration. A pre-v3 `device` grant carried
|
|
44070
|
-
* `targets: string[]` (stringified deviceIds); it rewrites to the equivalent
|
|
44071
|
-
* `selector: {kind:'ids', ids}`. Applied as a `preprocess` so it runs on
|
|
44072
|
-
* EVERY parse path — stored records AND the JWT-carried scope arrays
|
|
44073
|
-
* normalised at the request boundary ({@link normalizeTokenScopes} in
|
|
44074
|
-
* `device-selector.ts`). Chosen over a one-time DB migration because a
|
|
44075
|
-
* migration cannot reach a JWT already in a client's hands; parse-time
|
|
44076
|
-
* migration covers both without a flag day. No cast — the raw object is read
|
|
44077
|
-
* through `Reflect.get` (its static type is `unknown`).
|
|
44078
|
-
*/
|
|
44079
|
-
function migrateLegacyTokenScope(raw) {
|
|
44080
|
-
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return raw;
|
|
44081
|
-
if (Reflect.get(raw, "type") !== "device") return raw;
|
|
44082
|
-
if (Reflect.get(raw, "selector") !== void 0) return raw;
|
|
44083
|
-
const targets = Reflect.get(raw, "targets");
|
|
44084
|
-
if (!Array.isArray(targets)) return raw;
|
|
44085
|
-
return {
|
|
44086
|
-
type: "device",
|
|
44087
|
-
selector: {
|
|
44088
|
-
kind: "ids",
|
|
44089
|
-
ids: targets.map((t) => typeof t === "string" ? Number(t) : t).filter((n) => typeof n === "number" && Number.isInteger(n))
|
|
44090
|
-
},
|
|
44091
|
-
access: Reflect.get(raw, "access")
|
|
44092
|
-
};
|
|
44093
|
-
}
|
|
44094
|
-
var TokenScopeSchema = preprocess(migrateLegacyTokenScope, discriminatedUnion("type", [
|
|
44095
|
-
object({
|
|
44096
|
-
type: literal("category"),
|
|
44097
|
-
target: CapScopeSchema,
|
|
44098
|
-
access: array(MethodAccessSchema).min(1)
|
|
44099
|
-
}),
|
|
44100
|
-
object({
|
|
44101
|
-
type: literal("capability"),
|
|
44102
|
-
target: string(),
|
|
44103
|
-
access: array(MethodAccessSchema).min(1)
|
|
44104
|
-
}),
|
|
44105
|
-
object({
|
|
44106
|
-
type: literal("addon"),
|
|
44107
|
-
target: string(),
|
|
44108
|
-
access: array(MethodAccessSchema).min(1)
|
|
44109
|
-
}),
|
|
44110
|
-
DeviceTokenScopeSchema
|
|
44111
|
-
]));
|
|
44112
|
-
object({
|
|
44113
|
-
id: string(),
|
|
44114
|
-
username: string(),
|
|
44115
|
-
passwordHash: string(),
|
|
44116
|
-
/**
|
|
44117
|
-
* Admin bypass. When true, the middleware skips the scope-access
|
|
44118
|
-
* check entirely. There is no other axis of privilege; the legacy
|
|
44119
|
-
* role enum collapsed onto this boolean in v2.
|
|
44120
|
-
*/
|
|
44121
|
-
isAdmin: boolean().default(false),
|
|
44122
|
-
allowedProviders: AllowedProviderSchema,
|
|
44123
|
-
allowedDevices: AllowedDevicesSchema,
|
|
44124
|
-
/**
|
|
44125
|
-
* Scopes granted to this user. Admins bypass; their `scopes` is
|
|
44126
|
-
* ignored. Non-admins without scopes are locked out of every
|
|
44127
|
-
* protected call.
|
|
44128
|
-
*/
|
|
44129
|
-
scopes: array(TokenScopeSchema).default([]),
|
|
44130
|
-
createdAt: number(),
|
|
44131
|
-
updatedAt: number()
|
|
44132
|
-
});
|
|
44133
|
-
object({
|
|
44134
|
-
id: string(),
|
|
44135
|
-
label: string(),
|
|
44136
|
-
isAdmin: boolean().default(false),
|
|
44137
|
-
allowedProviders: AllowedProviderSchema,
|
|
44138
|
-
allowedDevices: AllowedDevicesSchema,
|
|
44139
|
-
tokenHash: string(),
|
|
44140
|
-
tokenPrefix: string(),
|
|
44141
|
-
createdAt: number(),
|
|
44142
|
-
lastUsedAt: number().optional()
|
|
44143
|
-
});
|
|
44144
|
-
object({
|
|
44145
|
-
id: string(),
|
|
44146
|
-
userId: string(),
|
|
44147
|
-
name: string(),
|
|
44148
|
-
tokenHash: string(),
|
|
44149
|
-
tokenPrefix: string(),
|
|
44150
|
-
scopes: array(TokenScopeSchema),
|
|
44151
|
-
expiresAt: number().nullish(),
|
|
44152
|
-
lastUsedAt: number().nullish(),
|
|
44153
|
-
createdAt: number()
|
|
44154
|
-
});
|
|
44155
|
-
/**
|
|
44156
44189
|
* `oauth-integration` — a collection cap by which an addon declares
|
|
44157
44190
|
* itself a linkable OAuth client of the hub's core `/oauth2/*` server.
|
|
44158
44191
|
* Each provider returns a static descriptor; the core enumerates them
|