@glasshome/sync-layer 0.7.2 → 0.8.1

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 (58) hide show
  1. package/dist/index.d.ts +1291 -54
  2. package/dist/index.js +203 -304
  3. package/dist/service-C8H42I-Q.d.ts +459 -0
  4. package/dist/solid/index.d.ts +119 -6
  5. package/dist/solid/index.js +20 -15
  6. package/dist/{statistics-CtRfIF6D.js → statistics-DyCCTwv2.js} +83 -95
  7. package/dist/worker/worker-main.d.ts +11 -8
  8. package/dist/worker/worker-main.js +2 -3
  9. package/dist/{worker-main-C-3QM4di.js → worker-main-D_wyGAIG.js} +47 -157
  10. package/package.json +4 -4
  11. package/dist/calendar/track.d.ts +0 -19
  12. package/dist/calendar/types.d.ts +0 -32
  13. package/dist/camera/fetch.d.ts +0 -16
  14. package/dist/camera/query.d.ts +0 -15
  15. package/dist/camera/types.d.ts +0 -85
  16. package/dist/camera/webrtc.d.ts +0 -31
  17. package/dist/commands/service.d.ts +0 -53
  18. package/dist/commands/types.d.ts +0 -113
  19. package/dist/connection/adapter.d.ts +0 -48
  20. package/dist/connection/auth.d.ts +0 -126
  21. package/dist/connection/bridged.d.ts +0 -16
  22. package/dist/connection/manager.d.ts +0 -51
  23. package/dist/connection/subscription-manager.d.ts +0 -48
  24. package/dist/connection/subscriptions.d.ts +0 -31
  25. package/dist/connection/types.d.ts +0 -151
  26. package/dist/core/privileged-conn.d.ts +0 -29
  27. package/dist/core/reducers.d.ts +0 -99
  28. package/dist/core/store.d.ts +0 -100
  29. package/dist/core/types.d.ts +0 -339
  30. package/dist/demo/demo-data.d.ts +0 -24
  31. package/dist/demo/demo-provider.d.ts +0 -40
  32. package/dist/demo/energy-sim.d.ts +0 -112
  33. package/dist/energy/prefs.d.ts +0 -56
  34. package/dist/entities/area-views.d.ts +0 -32
  35. package/dist/entities/index.d.ts +0 -54
  36. package/dist/entities/views.d.ts +0 -35
  37. package/dist/history/constants.d.ts +0 -16
  38. package/dist/history/fetch.d.ts +0 -19
  39. package/dist/history/query.d.ts +0 -27
  40. package/dist/history/statistics.d.ts +0 -55
  41. package/dist/history/types.d.ts +0 -146
  42. package/dist/host-api.d.ts +0 -50
  43. package/dist/media/url.d.ts +0 -14
  44. package/dist/query/area-builder.d.ts +0 -25
  45. package/dist/query/builder.d.ts +0 -18
  46. package/dist/query/helpers.d.ts +0 -21
  47. package/dist/query/memoization.d.ts +0 -18
  48. package/dist/query/projections.d.ts +0 -74
  49. package/dist/query/types.d.ts +0 -260
  50. package/dist/solid/hooks.d.ts +0 -119
  51. package/dist/solid/indices.d.ts +0 -15
  52. package/dist/weather/fetch.d.ts +0 -19
  53. package/dist/weather/query.d.ts +0 -23
  54. package/dist/weather/types.d.ts +0 -126
  55. package/dist/worker/bridge-client.d.ts +0 -47
  56. package/dist/worker/enforcement.d.ts +0 -53
  57. package/dist/worker/protocol.d.ts +0 -129
  58. package/dist/worker/token-store.d.ts +0 -3
@@ -1,47 +0,0 @@
1
- import type { CapabilityGrant } from "@glasshome/widget-contract";
2
- import type { SyncLayerConnection } from "../connection/types";
3
- import type { AuthMode, ConnState } from "./protocol";
4
- /**
5
- * Main-thread side of the HA bridge. Wraps the Worker and exposes:
6
- * - a SyncLayerConnection facade so the existing store/subscription/command
7
- * code runs unchanged, with all HA traffic tunneled through the worker
8
- * - registerWidget(), which mints the per-widget MessagePort the SDK's
9
- * service hooks call through (capability-checked in the worker)
10
- *
11
- * The Worker reference and its privileged channel live in this module's
12
- * closures only.
13
- */
14
- export interface BridgeConnectOptions {
15
- url: string;
16
- mode: AuthMode;
17
- proxyWsPath?: string;
18
- proxyTicket?: string;
19
- }
20
- export interface BridgeEvents {
21
- onConnState?: (state: ConnState) => void;
22
- onReadyAfterReconnect?: () => void;
23
- onDenial?: (denial: {
24
- widgetId: string;
25
- domain: string;
26
- service: string;
27
- entityIds: string[];
28
- message: string;
29
- }) => void;
30
- }
31
- export interface HaBridge {
32
- /** Resolves on socket-up; rejects with BridgeNeedsAuthError when the worker has no stored OAuth tokens. */
33
- connect(opts: BridgeConnectOptions): Promise<void>;
34
- disconnect(): void;
35
- reconnect(): void;
36
- clearTokens(): void;
37
- conn: SyncLayerConnection;
38
- registerWidget(widgetId: string, caps: CapabilityGrant[]): MessagePort;
39
- unregisterWidget(widgetId: string): void;
40
- /** Forward visibility/pageshow so the worker can drive suspend/reconnect. Returns teardown. */
41
- forwardLifecycle(): () => void;
42
- terminate(): void;
43
- }
44
- export declare class BridgeNeedsAuthError extends Error {
45
- constructor();
46
- }
47
- export declare function createHaBridge(worker: Worker, events?: BridgeEvents): HaBridge;
@@ -1,53 +0,0 @@
1
- import { type CapabilityGrant } from "@glasshome/widget-contract";
2
- /**
3
- * Capability enforcement for widget service calls. Pure and registry-backed:
4
- * the worker feeds it its own mirror of the HA registries, so expansion never
5
- * trusts anything computed in the widget's realm.
6
- */
7
- export interface EntityFacts {
8
- deviceId: string | null;
9
- areaId: string | null;
10
- labels: string[];
11
- }
12
- export interface DeviceFacts {
13
- areaId: string | null;
14
- labels: string[];
15
- }
16
- export interface ServiceCallShape {
17
- domain: string;
18
- service: string;
19
- data?: Record<string, unknown>;
20
- target?: Record<string, unknown>;
21
- }
22
- export declare class RegistryMirror {
23
- readonly entities: Map<string, EntityFacts>;
24
- readonly devices: Map<string, DeviceFacts>;
25
- replace(entityRegistry: {
26
- entity_id: string;
27
- device_id: string | null;
28
- area_id: string | null;
29
- labels?: string[];
30
- }[], deviceRegistry: {
31
- id: string;
32
- area_id: string | null;
33
- labels?: string[];
34
- }[]): void;
35
- entityAreaId(entityId: string): string | null;
36
- entityLabels(entityId: string): string[];
37
- }
38
- /**
39
- * Expand a service call to the concrete entity ids it can touch. Reads BOTH
40
- * `target` and the legacy id fields inside `data` — HA honors entity_id (and
41
- * friends) in service data, so ignoring it would let a call bypass entity
42
- * narrowing.
43
- */
44
- export declare function expandTargets(call: ServiceCallShape, registry: RegistryMirror): string[];
45
- export type EnforcementVerdict = {
46
- allowed: true;
47
- entityIds: string[];
48
- } | {
49
- allowed: false;
50
- entityIds: string[];
51
- message: string;
52
- };
53
- export declare function enforceServiceCall(caps: readonly CapabilityGrant[], call: ServiceCallShape, registry: RegistryMirror): EnforcementVerdict;
@@ -1,129 +0,0 @@
1
- import type { CapabilityGrant } from "@glasshome/widget-contract";
2
- /**
3
- * Message protocol between the main thread and the HA bridge worker.
4
- *
5
- * Two channels with different privilege:
6
- * - The worker's own message port (privileged): full tunnel to the HA socket.
7
- * Held in closure by the bridge client; never handed to widget code.
8
- * - Per-widget MessagePorts: exactly one verb (call_service), validated
9
- * against the widget's granted capabilities inside the worker.
10
- */
11
- export type AuthMode = {
12
- kind: "token";
13
- token: string;
14
- } | {
15
- kind: "brokered";
16
- mintUrl: string;
17
- } | {
18
- kind: "oauth";
19
- data?: OAuthTokenData;
20
- };
21
- /** Serializable subset of home-assistant-js-websocket AuthData. */
22
- export interface OAuthTokenData {
23
- hassUrl: string;
24
- clientId: string | null;
25
- access_token: string;
26
- refresh_token: string;
27
- expires: number;
28
- expires_in: number;
29
- }
30
- export type MainToWorker = {
31
- k: "connect";
32
- url: string;
33
- mode: AuthMode;
34
- /** Proxy WS endpoint to use instead of the HA host. A path (web, resolved
35
- * same-origin) or an absolute ws(s)/http(s) URL (native, where the worker
36
- * origin is localhost, not dash-server). */
37
- proxyWsPath?: string;
38
- /** Short-lived ticket authorizing the proxy WS + broker mint when a
39
- * cross-origin cookie/bearer can't ride them (native). */
40
- proxyTicket?: string;
41
- } | {
42
- k: "send";
43
- id: number;
44
- message: unknown;
45
- } | {
46
- k: "sub";
47
- id: number;
48
- kind: "events" | "message";
49
- eventType?: string;
50
- message?: unknown;
51
- } | {
52
- k: "unsub";
53
- id: number;
54
- } | {
55
- k: "visibility";
56
- hidden: boolean;
57
- } | {
58
- k: "pageshow_persisted";
59
- } | {
60
- k: "reconnect";
61
- } | {
62
- k: "disconnect";
63
- } | {
64
- k: "clear_tokens";
65
- } | {
66
- k: "register_widget";
67
- widgetId: string;
68
- caps: CapabilityGrant[];
69
- } | {
70
- k: "unregister_widget";
71
- widgetId: string;
72
- };
73
- export type ConnState = "connected" | "disconnected" | "reconnecting";
74
- export type WorkerToMain = {
75
- k: "connect_result";
76
- ok: boolean;
77
- error?: string;
78
- /** OAuth mode with no stored tokens: main thread must run interactive auth. */
79
- needsAuth?: boolean;
80
- } | {
81
- k: "conn";
82
- state: ConnState;
83
- }
84
- /** Fired after a reconnect completes; main thread reloads data + resubscribes. */
85
- | {
86
- k: "ready_after_reconnect";
87
- } | {
88
- k: "result";
89
- id: number;
90
- ok: boolean;
91
- result?: unknown;
92
- error?: string;
93
- } | {
94
- k: "event";
95
- id: number;
96
- payload: unknown;
97
- } | {
98
- k: "sub_end";
99
- id: number;
100
- error?: string;
101
- } | {
102
- k: "denial";
103
- widgetId: string;
104
- domain: string;
105
- service: string;
106
- entityIds: string[];
107
- message: string;
108
- };
109
- /** Widget port: request. The only verb widget code can reach. */
110
- export interface WidgetServiceCall {
111
- id: number;
112
- domain: string;
113
- service: string;
114
- data?: Record<string, unknown>;
115
- target?: Record<string, unknown>;
116
- /** Opt in to HA's service response (return_response). Only set for services
117
- that support/require it; HA errors otherwise. */
118
- returnResponse?: boolean;
119
- }
120
- export type WidgetServiceResult = {
121
- id: number;
122
- ok: true;
123
- result?: unknown;
124
- } | {
125
- id: number;
126
- ok: false;
127
- code: "CAPABILITY_DENIED" | "UNAVAILABLE" | "ERROR";
128
- message: string;
129
- };
@@ -1,3 +0,0 @@
1
- import type { OAuthTokenData } from "./protocol";
2
- export declare function loadTokens(): Promise<OAuthTokenData | null>;
3
- export declare function saveTokens(data: OAuthTokenData | null): Promise<void>;