@camstack/server 1.2.943 → 1.2.944

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 (157) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/closure-pins.json +350 -0
  3. package/dist/api/core/auth-sessions.procedures.js +18 -0
  4. package/dist/api/core/auth.router.js +19 -6
  5. package/dist/api/server-upload.js +17 -1
  6. package/dist/api/trpc/generated-cap-routers.js +83 -0
  7. package/dist/auth/native-return.js +9 -3
  8. package/dist/auth/sso-routes.js +5 -1
  9. package/dist/core/addon/instance-lifecycle.js +4 -1
  10. package/dist/core/auth/handoff-code.service.js +35 -1
  11. package/dist/server-root/index.js +313 -70
  12. package/package.json +21 -11
  13. package/system/dist/{action-index-B1fgpQBt.mjs → action-index-DpYmsOKh.mjs} +1 -1
  14. package/system/dist/{action-index-B_cLRwXJ.js → action-index-Dz9rd1qa.js} +1 -1
  15. package/system/dist/{addon-settings.cap-CZ4MC7ha.mjs → addon-settings.cap-CHpmuaQG.mjs} +1 -1
  16. package/system/dist/{addon-settings.cap-DrLdMFIe.js → addon-settings.cap-nZVHPo3X.js} +1 -1
  17. package/system/dist/{alert-episode-Be--PngO.mjs → alert-episode-D-1VUUkZ.mjs} +1 -1
  18. package/system/dist/{alert-episode-Bqktmt-i.js → alert-episode-DaQ3prSe.js} +1 -1
  19. package/system/dist/{base-addon-CRsXtYFG.js → base-addon-BG7p06Hb.js} +136 -15
  20. package/system/dist/{base-addon-BcS6r1cT.mjs → base-addon-BcVoYZbC.mjs} +136 -15
  21. package/system/dist/{base-device-DAdWzDOl.js → base-device-DeSNiwZ4.js} +4 -4
  22. package/system/dist/{base-device-DJXF5eDN.mjs → base-device-w_MD0Bf4.mjs} +4 -4
  23. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  24. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  25. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  26. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  27. package/system/dist/builtins/alerts/alerts.addon.js +3 -3
  28. package/system/dist/builtins/alerts/alerts.addon.mjs +3 -3
  29. package/system/dist/builtins/autotrack/index.js +1 -1
  30. package/system/dist/builtins/autotrack/index.mjs +1 -1
  31. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +1 -1
  32. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +1 -1
  33. package/system/dist/builtins/calendars/calendars.addon.js +1 -1
  34. package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
  35. package/system/dist/builtins/camera-grid/index.js +3 -3
  36. package/system/dist/builtins/camera-grid/index.mjs +3 -3
  37. package/system/dist/builtins/composer/composer.addon.js +7 -7
  38. package/system/dist/builtins/composer/composer.addon.mjs +7 -7
  39. package/system/dist/builtins/console-logging/index.js +1 -1
  40. package/system/dist/builtins/console-logging/index.mjs +1 -1
  41. package/system/dist/builtins/core-blocks/actions-store.d.ts +2 -0
  42. package/system/dist/builtins/core-blocks/block-supervisor.d.ts +16 -4
  43. package/system/dist/builtins/core-blocks/core-block-store.d.ts +2 -0
  44. package/system/dist/builtins/core-blocks/core-blocks.addon.js +1018 -323
  45. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +986 -291
  46. package/system/dist/builtins/core-blocks/migrations/index.d.ts +5 -2
  47. package/system/dist/builtins/core-blocks/migrations/tag-ids.d.ts +42 -0
  48. package/system/dist/builtins/core-blocks/migrations/tags-as-records.d.ts +47 -0
  49. package/system/dist/builtins/core-blocks/record-kinds.d.ts +12 -1
  50. package/system/dist/builtins/core-blocks/runs-api.d.ts +3 -1
  51. package/system/dist/builtins/core-blocks/runs-ledger.d.ts +3 -1
  52. package/system/dist/builtins/core-blocks/scheduler/scheduler-store.d.ts +2 -0
  53. package/system/dist/builtins/core-blocks/tags-service.d.ts +52 -27
  54. package/system/dist/builtins/core-blocks/tags-wiring.d.ts +2 -0
  55. package/system/dist/builtins/core-notifier/core-notifier.addon.js +76 -67
  56. package/system/dist/builtins/core-notifier/core-notifier.addon.mjs +76 -67
  57. package/system/dist/builtins/device-history/device-history.addon.js +4 -4
  58. package/system/dist/builtins/device-history/device-history.addon.mjs +4 -4
  59. package/system/dist/builtins/device-manager/device-manager.addon.js +1602 -760
  60. package/system/dist/builtins/device-manager/device-manager.addon.mjs +1588 -746
  61. package/system/dist/builtins/device-manager/device-meta-actions.d.ts +13 -136
  62. package/system/dist/builtins/device-manager/device-meta-types.d.ts +5 -1
  63. package/system/dist/builtins/device-manager/device-provider-context.d.ts +9 -0
  64. package/system/dist/builtins/device-manager/device-row-store.d.ts +21 -4
  65. package/system/dist/builtins/device-manager/device-search.d.ts +6 -0
  66. package/system/dist/builtins/device-manager/location-alignment.d.ts +9 -2
  67. package/system/dist/builtins/device-manager/migrate-device.d.ts +7 -2
  68. package/system/dist/builtins/device-manager/migrate-hardware-state.d.ts +132 -1
  69. package/system/dist/builtins/device-manager/migrations/device-tag-ids.d.ts +25 -0
  70. package/system/dist/builtins/device-manager/migrations/index.d.ts +16 -0
  71. package/system/dist/builtins/device-manager/migrations/orphan-children.d.ts +33 -0
  72. package/system/dist/builtins/device-manager/migrations/ports.d.ts +17 -0
  73. package/system/dist/builtins/device-manager/migrations/rooms-as-records.d.ts +52 -0
  74. package/system/dist/builtins/device-manager/record-kinds.d.ts +3 -1
  75. package/system/dist/builtins/device-manager/removal-cleanup.d.ts +7 -0
  76. package/system/dist/builtins/device-manager/room-actions.d.ts +27 -0
  77. package/system/dist/builtins/device-manager/room-store.d.ts +19 -0
  78. package/system/dist/builtins/device-manager/tag-names.d.ts +32 -0
  79. package/system/dist/builtins/device-manager/wireable-enum-catalog.d.ts +18 -0
  80. package/system/dist/builtins/hub-forwarder/index.js +1 -1
  81. package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
  82. package/system/dist/builtins/keychain/index.js +2 -2
  83. package/system/dist/builtins/keychain/index.mjs +2 -2
  84. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  85. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  86. package/system/dist/builtins/local-auth/local-auth.addon.js +1 -1
  87. package/system/dist/builtins/local-auth/local-auth.addon.mjs +1 -1
  88. package/system/dist/builtins/local-network/local-network.addon.js +2 -2
  89. package/system/dist/builtins/local-network/local-network.addon.mjs +2 -2
  90. package/system/dist/builtins/loki-logging/index.js +2 -2
  91. package/system/dist/builtins/loki-logging/index.mjs +2 -2
  92. package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  93. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  94. package/system/dist/builtins/platform-probe/index.js +1 -1
  95. package/system/dist/builtins/platform-probe/index.mjs +1 -1
  96. package/system/dist/builtins/record-entries/index.js +1 -1
  97. package/system/dist/builtins/record-entries/index.mjs +1 -1
  98. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  99. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  100. package/system/dist/builtins/snapshot/index.js +1 -1
  101. package/system/dist/builtins/snapshot/index.mjs +1 -1
  102. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  103. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  104. package/system/dist/builtins/sqlite-storage/index.js +1 -1
  105. package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
  106. package/system/dist/builtins/sqlite-storage/migrations/migration-engine.d.ts +3 -1
  107. package/system/dist/builtins/sqlite-storage/migrations/migrations-provider.d.ts +1 -0
  108. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +15 -10
  109. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +15 -10
  110. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
  111. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
  112. package/system/dist/builtins/system-config/system-config.addon.js +1 -1
  113. package/system/dist/builtins/system-config/system-config.addon.mjs +1 -1
  114. package/system/dist/builtins/winston-logging/index.js +2 -2
  115. package/system/dist/builtins/winston-logging/index.mjs +2 -2
  116. package/system/dist/{command-catalog-C29hVOOg.js → command-catalog-CI0tu1Nt.js} +1 -1
  117. package/system/dist/{command-catalog-xAeqxbZk.mjs → command-catalog-zwlIA3T5.mjs} +1 -1
  118. package/system/dist/{composition-sources-C327LGFn.mjs → composition-sources-CXxXfh1z.mjs} +1 -1
  119. package/system/dist/{composition-sources-Do5qM6EB.js → composition-sources-DNgSItK-.js} +1 -1
  120. package/system/dist/{core-blocks.cap-CdTGUKtr.js → core-blocks.cap-BHEok4VO.js} +125 -373
  121. package/system/dist/{core-blocks.cap-DLkEfV5b.mjs → core-blocks.cap-CPgZRcpj.mjs} +109 -327
  122. package/system/dist/{device-manager.cap-DJs8izI6.js → device-manager.cap-B9qVf7ag.js} +163 -22
  123. package/system/dist/{device-manager.cap-eYrj1Ezp.mjs → device-manager.cap-CV4KGp3e.mjs} +134 -17
  124. package/system/dist/{error.cap-CU1FB6uE.mjs → error.cap-B8l7L8e4.mjs} +7 -1
  125. package/system/dist/{error.cap-BuKbL3Ac.js → error.cap-BqlvgBJd.js} +7 -1
  126. package/system/dist/file-host-worker.js +1 -1
  127. package/system/dist/file-host-worker.mjs +1 -1
  128. package/system/dist/index.js +7 -7
  129. package/system/dist/index.mjs +6 -6
  130. package/system/dist/{legacy-integration-rows-door-CdqYAj-o.js → legacy-integration-rows-door-BK8eoGlF.js} +1 -1
  131. package/system/dist/{legacy-integration-rows-door-LSgpClpX.mjs → legacy-integration-rows-door-CwzC5XNk.mjs} +1 -1
  132. package/system/dist/{migration-DGAc6ywR.mjs → migration-BvbfW9g-.mjs} +6 -0
  133. package/system/dist/{migration-BOQlFZCN.js → migration-CHPdAdNh.js} +6 -0
  134. package/system/dist/{prefix-walk-BFnw8NBu.js → named-entity-store-DFwLij9c.js} +244 -90
  135. package/system/dist/{prefix-walk-Mtij0NNT.mjs → named-entity-store-DOnyyFFf.mjs} +195 -89
  136. package/system/dist/{notification-rules.cap-BUIuYPlQ.mjs → notification-rules.cap-ClvK6QT1.mjs} +10 -5
  137. package/system/dist/{notification-rules.cap-BJKUjizS.js → notification-rules.cap-uSLoe2pA.js} +10 -5
  138. package/system/dist/{notification-targets-DMW7xgR2.js → notification-targets-ChqpBbtR.js} +2 -2
  139. package/system/dist/{notification-targets-4bGYH5J7.mjs → notification-targets-DUA6-F2t.mjs} +2 -2
  140. package/system/dist/{device-row-store-CTocYKqC.mjs → record-kinds-BD2xv4Pd.mjs} +222 -93
  141. package/system/dist/{device-row-store-C0P2H18h.js → record-kinds-BV8Gcpsx.js} +246 -93
  142. package/system/dist/records/named-entity-store.d.ts +60 -0
  143. package/system/dist/{rename-composition-block-Cdh-dRmY.mjs → rename-composition-block-C3QQ9UUE.mjs} +134 -33
  144. package/system/dist/{rename-composition-block-D9Uc1AF7.js → rename-composition-block-Cx3X8QSm.js} +134 -33
  145. package/system/dist/{retention-source.cap-C6Hy0hlM.js → retention-source.cap-A-TMhU5O.js} +1 -1
  146. package/system/dist/{retention-source.cap-550kkyp5.mjs → retention-source.cap-Ct07pM30.mjs} +1 -1
  147. package/system/dist/{storage-admin.cap-Ci4QbL6P.mjs → storage-admin.cap-C54s9_B9.mjs} +8 -2
  148. package/system/dist/{storage-admin.cap-DqW1ol4j.js → storage-admin.cap-DSPHi7ut.js} +8 -2
  149. package/system/dist/{stream-catalog.cap-CjEQFknc.js → stream-catalog.cap-7WPsugOy.js} +1 -1
  150. package/system/dist/{stream-catalog.cap-DVniDdRD.mjs → stream-catalog.cap-CzwRDaqT.mjs} +1 -1
  151. package/system/dist/{tag-BxLazvVb.js → tag-BLraBqvp.js} +12 -0
  152. package/system/dist/{tag-uZBAq6ox.mjs → tag-DU8pm9Bi.mjs} +7 -1
  153. package/system/dist/time-window-B6UhCArd.js +679 -0
  154. package/system/dist/time-window-BnUBULgu.mjs +578 -0
  155. package/system/dist/{wal-maintenance-BgYiAy5b.js → wal-maintenance-CkPfVApC.js} +0 -0
  156. package/system/dist/{wal-maintenance-Bey5ChBb.mjs → wal-maintenance-u84_1sVl.mjs} +0 -0
  157. package/system/package.json +1 -1
@@ -1,12 +1,15 @@
1
1
  import type { AddonMigration } from "@camstack/types";
2
2
  import { type CoreBlocksMigrationPorts } from "./pump-cycle-split.js";
3
+ import { type TagIdsPorts } from "./tag-ids.js";
4
+ import { type TagsAsRecordsPorts } from "./tags-as-records.js";
3
5
  import { type RemoteMigrationPorts } from "./remote-config-migrations.js";
4
6
  export { AUTOMATION_CONFIRMED_VIEW_ID } from "./automation-confirmed-view.js";
5
7
  export { FOUNTAIN_DRINK_DROP_ID } from "./fountain-drink-drop.js";
6
8
  export { REMOTE_COLOUR_ROLES_ID, REMOTE_POWER_DROP_ID, remoteMigrationPortsOver, type RemoteMigrationPorts } from "./remote-config-migrations.js";
7
9
  /** Everything the core-blocks catalogue touches: the block rows, and the stored remotes and templates. */
8
- export type CoreBlocksCatalogPorts = CoreBlocksMigrationPorts & RemoteMigrationPorts;
10
+ export type CoreBlocksCatalogPorts = CoreBlocksMigrationPorts & RemoteMigrationPorts & TagIdsPorts & TagsAsRecordsPorts;
9
11
  export { HELPER_TO_CUSTOMIZE_ID } from "./helper-to-customize.js";
12
+ export { CORE_BLOCKS_TAG_IDS_ID, tagIdsPortsOver, type TagIdsPorts } from "./tag-ids.js";
13
+ export { TAGS_AS_RECORDS_ID, tagsAsRecordsPortsOver, type TagsAsRecordsPorts } from "./tags-as-records.js";
10
14
  export { coreBlocksMigrationPorts, PUMP_CYCLE_SPLIT_ID, type CoreBlocksMigrationPorts, type StoredBlockRow } from "./pump-cycle-split.js";
11
- /** The `core-blocks` catalogue (D987): offered to the engine when the hub-resident addon initialises. */
12
15
  export declare const ADDON_MIGRATIONS: readonly AddonMigration<CoreBlocksCatalogPorts>[];
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Every core-blocks record that carries tags gets the ids of those tags (D1089, the
3
+ * core-blocks step of the tags migration): `tagIds` is added beside the kept `tags` names,
4
+ * aligned by index, each id derived from the folded name (`tagIdFromKey`) so the device
5
+ * manager and the notification rules mint the same id for the same name without reading each
6
+ * other. The names stay for one release.
7
+ *
8
+ * Four owners: core blocks (the tags sit on the block inside the row body), schedulers,
9
+ * templates and actions. A row with no tags, or one that already has `tagIds`, is left
10
+ * alone, so a rerun edits nothing. A row whose names repeat one tag in two spellings is
11
+ * rewritten with both fields de-duplicated, so the index alignment holds. Each row is
12
+ * replaced only if it is still at the revision that was read; a row changed meanwhile fails
13
+ * the run, which retries on the next boot.
14
+ */
15
+ import { type IScopedLogger, type MigrationProcedureResult, type RecordKindHandle } from "@camstack/types";
16
+ import type { ActionRowBody, CoreBlockRowBody, SchedulerRowBody, TemplateRowBody } from "../record-kinds.js";
17
+ export declare const CORE_BLOCKS_TAG_IDS_ID = "core-blocks/2026-11-23-tag-ids";
18
+ export type TaggedOwner = "blocks" | "schedulers" | "templates" | "actions";
19
+ /** A record's tags as the migration reads them. */
20
+ export interface TaggedRow {
21
+ readonly owner: TaggedOwner;
22
+ readonly id: string;
23
+ readonly rev: number;
24
+ readonly tags: readonly string[];
25
+ readonly hasTagIds: boolean;
26
+ }
27
+ export interface TagIdsPorts {
28
+ /** Every record that carries tags, of the four owners. Throws when one cannot be read in full. */
29
+ listTaggedRows(): Promise<readonly TaggedRow[]>;
30
+ /** Write the ids (and the de-duplicated names when `tags` is given), refused if the row moved. */
31
+ writeTagIds(row: TaggedRow, tagIds: readonly string[], tags: readonly string[] | null): Promise<void>;
32
+ info(message: string, meta: Readonly<Record<string, unknown>>): void;
33
+ }
34
+ /** The four record kinds the migration walks. */
35
+ export interface TagIdsKinds {
36
+ readonly blocks: RecordKindHandle<CoreBlockRowBody>;
37
+ readonly schedulers: RecordKindHandle<SchedulerRowBody>;
38
+ readonly templates: RecordKindHandle<TemplateRowBody>;
39
+ readonly actions: RecordKindHandle<ActionRowBody>;
40
+ }
41
+ export declare function tagIdsPortsOver(kinds: TagIdsKinds, logger: IScopedLogger): TagIdsPorts;
42
+ export declare function addTagIds(ports: TagIdsPorts): Promise<MigrationProcedureResult>;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Tags become records with an id (D1089, the last step of the tags migration).
3
+ *
4
+ * Before: a tag was a NAME on the records it labelled; its only registry was a style row
5
+ * (`tag-styles`: colour and icon). After: one `tags` record per tag in use or styled, whose
6
+ * id is the one the per-owner steps already wrote into `tagIds` (`tagIdFromKey` of the folded
7
+ * name), carrying the colour and icon of its style. The style rows are then deleted.
8
+ *
9
+ * Idempotent and ordered so a crash loses nothing: every record is written BEFORE any style
10
+ * row is deleted, an existing record is never overwritten (a seed never overwrites), and a
11
+ * rerun finds no style row and every tag present. The display spelling is the style's, else
12
+ * the one used most (the first alphabetically on a tie).
13
+ *
14
+ * `dependsOn` the owner steps that add `tagIds`, so a record exists under the id they used.
15
+ * Names held by owners outside this addon (the device manager, the notification rules) are
16
+ * read best effort: one that cannot be reached right now is logged and skipped, because its
17
+ * tag is created on first use by `ensureTag` and its rows keep the kept names meanwhile; a
18
+ * styled tag is carried either way.
19
+ */
20
+ import { type IScopedLogger, type MigrationProcedureResult, type RecordKindHandle, type TagBody, type TagStyle } from "@camstack/types";
21
+ import type { TagStyleRowBody } from "../record-kinds.js";
22
+ import type { TagIdsPorts } from "./tag-ids.js";
23
+ export declare const TAGS_AS_RECORDS_ID = "core-blocks/2026-11-23-tags-as-records";
24
+ export interface TagsAsRecordsPorts {
25
+ /** Every tag name carried by the core-blocks records, repeats kept (they weigh the spelling). */
26
+ localNames(): Promise<readonly string[]>;
27
+ /** The names the other owners carry, or `null` when they cannot be read right now. */
28
+ externalNames(): Promise<readonly string[] | null>;
29
+ listStyles(): Promise<readonly {
30
+ readonly id: string;
31
+ readonly style: TagStyle;
32
+ }[]>;
33
+ existingTagIds(): Promise<ReadonlySet<string>>;
34
+ /** Create the record `id`; refused when it exists. */
35
+ createTag(id: string, body: TagBody): Promise<void>;
36
+ deleteStyle(id: string): Promise<void>;
37
+ info(message: string, meta: Readonly<Record<string, unknown>>): void;
38
+ warn(message: string, meta: Readonly<Record<string, unknown>>): void;
39
+ }
40
+ export declare function tagsAsRecordsPortsOver(input: {
41
+ readonly tagIds: TagIdsPorts;
42
+ readonly external: () => Promise<readonly string[]>;
43
+ readonly styles: RecordKindHandle<TagStyleRowBody>;
44
+ readonly tags: RecordKindHandle<TagBody>;
45
+ readonly logger: IScopedLogger;
46
+ }): TagsAsRecordsPorts;
47
+ export declare function writeTagRecords(ports: TagsAsRecordsPorts): Promise<MigrationProcedureResult>;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Record kinds owned by core-blocks (phase 4).
3
3
  */
4
- import { ActionStepSchema, ActionVariableSchema, type TagStyle, type Scheduler, AutomationStateDocSchema, TemplateKindSchema, type DefinedRecordKind } from "@camstack/types";
4
+ import { ActionStepSchema, ActionVariableSchema, type TagBody, type TagStyle, type Scheduler, AutomationStateDocSchema, TemplateKindSchema, type DefinedRecordKind } from "@camstack/types";
5
5
  import { z } from "zod";
6
6
  export declare const CORE_BLOCKS_COLLECTION = "core_blocks";
7
7
  export declare const CORE_BLOCK_SETTINGS_COLLECTION = "core-blocks:settings";
@@ -28,6 +28,8 @@ export type RunsRowBody = {
28
28
  readonly traces: z.infer<typeof AutomationStateDocSchema>["traces"];
29
29
  readonly lastError: string | null;
30
30
  readonly updatedAt: number;
31
+ /** The devices an automation turned on and owes an off ("on for a time"). */
32
+ readonly onForHolds?: z.infer<typeof AutomationStateDocSchema>["onForHolds"];
31
33
  };
32
34
  export declare const RunsRowBodySchema: z.ZodType<RunsRowBody>;
33
35
  /** An internal action: the operator's steps and variables. The row id is the bare uuid. */
@@ -37,6 +39,7 @@ export type ActionRowBody = {
37
39
  readonly variables?: z.infer<typeof ActionVariableSchema>[];
38
40
  readonly minDelaySec?: number;
39
41
  readonly tags?: string[];
42
+ readonly tagIds?: string[];
40
43
  readonly createdAt: number;
41
44
  readonly updatedAt: number;
42
45
  };
@@ -64,6 +67,7 @@ export type TemplateRowBody = {
64
67
  readonly name: string;
65
68
  readonly payload: unknown;
66
69
  readonly tags?: string[];
70
+ readonly tagIds?: string[];
67
71
  readonly createdAt: number;
68
72
  readonly updatedAt: number;
69
73
  };
@@ -76,6 +80,12 @@ export declare const TemplateRowBodySchema: z.ZodType<TemplateRowBody>;
76
80
  export type TagStyleRowBody = TagStyle;
77
81
  export declare const TagStyleRowBodySchema: z.ZodType<TagStyleRowBody>;
78
82
  /**
83
+ * A tag (D1089): a record with an opaque id, carrying its name, colour, icon and
84
+ * description. Every owner references the id, so a rename is ONE write here.
85
+ */
86
+ export type TagRowBody = TagBody;
87
+ export declare const TagRowBodySchema: z.ZodType<TagRowBody>;
88
+ /**
79
89
  * A pending timed run (D993): the device is on and the hub owes it an off at
80
90
  * `activeUntil`. One row per device, written BEFORE the device is switched on,
81
91
  * so a crash can only ever cost a harmless extra off at boot. Row id = the
@@ -97,6 +107,7 @@ export type CoreBlocksRecordKindsMap = {
97
107
  readonly "scheduler-state": DefinedRecordKind<z.ZodType<SchedulerStateRowBody>>;
98
108
  readonly "action-links": DefinedRecordKind<z.ZodType<ActionLinksRowBody>>;
99
109
  readonly templates: DefinedRecordKind<z.ZodType<TemplateRowBody>>;
110
+ readonly tags: DefinedRecordKind<z.ZodType<TagRowBody>>;
100
111
  readonly "tag-styles": DefinedRecordKind<z.ZodType<TagStyleRowBody>>;
101
112
  readonly settings: DefinedRecordKind<z.ZodType<CoreBlockSettingsBody>>;
102
113
  };
@@ -7,13 +7,15 @@
7
7
  * reads as a trace that never happened. The operator reads through `getTraces`,
8
8
  * which is admin-tier and takes no stamp.
9
9
  */
10
- import { type AutomationRunTrace, type AutomationStateDoc, type IScopedLogger } from "@camstack/types";
10
+ import { type AutomationRunTrace, type AutomationStateDoc, type IScopedLogger, type OnForHold } from "@camstack/types";
11
11
  import { type RunsLedger } from "./runs-ledger.js";
12
12
  export interface ReportAutomationRunInput {
13
13
  readonly blockId: string;
14
14
  readonly trace?: AutomationRunTrace;
15
15
  readonly runStartedAt?: number;
16
16
  readonly keepTraces?: number;
17
+ /** The devices the block holds on, whole: an empty list releases them all. */
18
+ readonly onForHolds?: readonly OnForHold[];
17
19
  }
18
20
  export interface RunsApi {
19
21
  reportAutomationRun(input: ReportAutomationRunInput): Promise<void>;
@@ -18,7 +18,7 @@
18
18
  * write="a block or an Action run reports a run; the ring is bounded by `keepTraces`"
19
19
  * retention="deleted with the block / action; orphans swept at start"
20
20
  */
21
- import { type AutomationRunTrace, type AutomationStateDoc, type IScopedLogger, type RecordKindHandle } from "@camstack/types";
21
+ import { type AutomationRunTrace, type AutomationStateDoc, type IScopedLogger, type OnForHold, type RecordKindHandle } from "@camstack/types";
22
22
  import type { RunsRowBody } from "./record-kinds.js";
23
23
  export declare const AUTOMATION_OWNER_PREFIX = "automation:";
24
24
  export declare const ACTION_OWNER_PREFIX = "action:";
@@ -32,6 +32,8 @@ export interface RunsReport {
32
32
  readonly trace?: AutomationRunTrace;
33
33
  readonly runStartedAt?: number;
34
34
  readonly keepTraces?: number;
35
+ /** Replaces the held devices; absent keeps what the row has. */
36
+ readonly onForHolds?: readonly OnForHold[];
35
37
  }
36
38
  export interface RunsLedgerView extends AutomationStateDoc {
37
39
  readonly lastError: string | null;
@@ -23,6 +23,8 @@ export declare class SchedulersStore {
23
23
  * `updatedAt`.
24
24
  */
25
25
  setTags(schedulerId: string, tags: readonly string[]): Promise<void>;
26
+ /** Replace the tag ids of a scheduler (D1089); everything else is left as it is. */
27
+ setTagIds(schedulerId: string, tagIds: readonly string[]): Promise<void>;
26
28
  delete(schedulerId: string): Promise<boolean>;
27
29
  processedUntil(schedulerId: string): Promise<number | null>;
28
30
  setProcessedUntil(schedulerId: string, at: number): Promise<void>;
@@ -1,34 +1,46 @@
1
1
  /**
2
- * The `tags` cap (D1054). A tag lives on the record it labels — a core block, a
3
- * scheduler, a template, an action, a device, a notification rule — and only
4
- * its STYLE (colour token, icon) is registered here. This service is the one place that knows every owner
5
- * kind, so `rename` and `remove` are ONE server operation that rewrites all of
6
- * them; the browser never drives that sequence (a closed tab would split the
7
- * fleet across two spellings).
2
+ * The `tags` cap (D1089). A tag is a RECORD with an opaque id; a core block, a
3
+ * scheduler, a template, an action, a device and a notification rule carry the
4
+ * id, and the name, colour, icon and description live on the record only. So
5
+ * `updateTag` — a rename included — is ONE write to ONE record, and no owner
6
+ * has to be reachable. `deleteTag` keeps the one fan-out that remains: it
7
+ * clears the id from every owner, and refuses while an owner cannot be read.
8
+ *
9
+ * `list`, `setStyle`, `rename` and `remove` are the old name-based surface, now
10
+ * thin shims over the entity methods (kept for one release).
8
11
  *
9
12
  * Owners are reached through {@link TagOwnerPort}s: the local stores directly,
10
13
  * the devices and notification rules through their caps over `ctx.api` — never
11
- * a second copy. An owner that cannot be read degrades `list` (its count is
12
- * `null`) and refuses `rename` / `remove` before any write.
13
- * Tags compare trimmed and case-insensitively (`sameTag`).
14
+ * a second copy. A names-only owner (a notification rule, until its own
15
+ * migration lands) still carries text; the service keeps its names in step.
14
16
  */
15
- import { type IScopedLogger, type ITagsProvider, type RecordKindHandle, type TagUsageCounts } from "@camstack/types";
16
- import type { TagStyleRowBody } from "./record-kinds.js";
17
+ import { type IScopedLogger, type ITagsProvider, type RecordKindHandle, type TagBody, type TagUsageCounts } from "@camstack/types";
17
18
  /** One record that may carry tags. `id` is the owner's own id, as text. */
18
19
  export interface TagOwnerRecord {
19
20
  readonly id: string;
21
+ /** The tag names kept on the record (D1089: kept beside the ids for one release). */
20
22
  readonly tags: readonly string[];
23
+ /** The tag ids the record carries; empty before its owner migrated. */
24
+ readonly tagIds: readonly string[];
21
25
  }
22
26
  /** How the service reads and rewrites the tags of one owner kind. */
23
27
  export interface TagOwnerPort {
28
+ /** `ids`: the owner stores tag ids. `names`: it still stores text only. */
29
+ readonly storage: "ids" | "names";
24
30
  list(): Promise<readonly TagOwnerRecord[]>;
31
+ setTagIds(id: string, tagIds: string[]): Promise<void>;
25
32
  setTags(id: string, tags: string[]): Promise<void>;
33
+ /**
34
+ * Both in ONE write, for an owner whose names-only write would drop the ids (a notification
35
+ * rule). Absent: the service calls `setTagIds` then `setTags`.
36
+ */
37
+ setTagsAndIds?(id: string, tags: string[], tagIds: string[]): Promise<void>;
26
38
  }
27
39
  export type TagOwnerKind = keyof TagUsageCounts;
28
40
  export type TagOwnerPorts = Readonly<Record<TagOwnerKind, TagOwnerPort>>;
29
41
  /**
30
- * A rename or remove refused because one owner kind could not be read. Nothing
31
- * was written; `owner` names which one, so the operator knows what to bring back.
42
+ * A delete refused because one owner kind could not be read. Nothing was
43
+ * written; `owner` names which one, so the operator knows what to bring back.
32
44
  */
33
45
  export declare class TagOwnerUnreachableError extends Error {
34
46
  readonly owner: TagOwnerKind;
@@ -37,31 +49,44 @@ export declare class TagOwnerUnreachableError extends Error {
37
49
  }
38
50
  export interface TagsServiceDeps {
39
51
  readonly owners: TagOwnerPorts;
40
- /** Row id = `tagKey(name)`. */
41
- readonly styles: RecordKindHandle<TagStyleRowBody>;
52
+ /** Record id = the tag id (D1089). */
53
+ readonly tags: RecordKindHandle<TagBody>;
42
54
  readonly logger: IScopedLogger;
43
55
  }
44
56
  export declare class TagsService implements ITagsProvider {
45
57
  private readonly deps;
58
+ private readonly store;
59
+ private loaded;
46
60
  constructor(deps: TagsServiceDeps);
47
- private readStyles;
61
+ /** Read the records once; every method awaits it. */
62
+ private ready;
63
+ readonly ensureTag: ITagsProvider["ensureTag"];
64
+ readonly listTags: ITagsProvider["listTags"];
65
+ readonly updateTag: ITagsProvider["updateTag"];
66
+ readonly deleteTag: ITagsProvider["deleteTag"];
48
67
  readonly list: ITagsProvider["list"];
49
68
  readonly setStyle: ITagsProvider["setStyle"];
50
69
  readonly rename: ITagsProvider["rename"];
51
70
  readonly remove: ITagsProvider["remove"];
71
+ private patched;
52
72
  /**
53
- * Apply `change` to every record carrying `tag`, on every owner kind. A record
54
- * that fails is logged and the rest are still attempted; the call then throws,
55
- * and the style is NOT touched — the tag still names the failed records, so the
56
- * operator repeats the same call (every step is idempotent).
73
+ * Remove `tag` from every owner record that carries it, or — with `into` —
74
+ * replace it with that tag. Every owner is READ first: one that cannot be
75
+ * read refuses the whole call before anything is written.
57
76
  */
58
- private rewrite;
77
+ private clearFromOwners;
78
+ private rewriteRecord;
79
+ /** How many records carry `tag` (by id or kept name) — the shim's `updated`; an unreadable owner counts 0. */
80
+ private countCarrying;
59
81
  /**
60
- * An owner's records for a rewrite. One that cannot be read refuses the whole
61
- * call BEFORE anything is written: a rename applied to only some owners would
62
- * leave the fleet split across two spellings.
82
+ * A safety net for a record that still holds text only (an owner, or a node whose
83
+ * notification center has not run its tag-ids step yet): the tag record was renamed once, so
84
+ * the names such a record keeps are moved here, or it would keep naming a tag nothing
85
+ * carries any more.
86
+ * An owner that cannot be read is logged and skipped, never the cause of a failed rename.
63
87
  */
64
- private readOwnerOrRefuse;
65
- /** The style follows the tag; a merge onto a styled target keeps the TARGET's style. */
66
- private moveStyle;
88
+ private followRenameOnNamesOnlyOwners;
89
+ /** Names-only tags: a name on owners that have no record for it (a pre-migration state). */
90
+ private renameNamesOnly;
91
+ private removeNamesOnly;
67
92
  }
@@ -16,6 +16,7 @@ export interface TagsRuntimeDeps {
16
16
  /** A spec swaps the rule owner; production reads the notification rules over `api`. */
17
17
  readonly notificationRules?: TagOwnerPort;
18
18
  }
19
+ export declare function devicesPort(api: () => AddonApi | undefined): TagOwnerPort;
19
20
  /**
20
21
  * A notification rule's owner-port id is `<kind>:<ruleId>`: event rules,
21
22
  * summaries, timelapses and calendar-events rules live in separate stores, so
@@ -26,4 +27,5 @@ export declare function parseRuleTagOwnerId(id: string): {
26
27
  kind: NcTaggedRuleKind;
27
28
  ruleId: string;
28
29
  };
30
+ export declare function notificationRulesPort(api: () => AddonApi | undefined): TagOwnerPort;
29
31
  export declare function buildTagsService(deps: TagsRuntimeDeps): TagsService;
@@ -3,73 +3,92 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  require("../../chunk-Cek0wNdY.js");
6
- const require_base_addon = require("../../base-addon-CRsXtYFG.js");
6
+ const require_base_addon = require("../../base-addon-BG7p06Hb.js");
7
7
  const require_scoped_settings = require("../../scoped-settings-CylSSq_8.js");
8
- const require_notification_targets = require("../../notification-targets-DMW7xgR2.js");
9
- const require_notification_rules_cap = require("../../notification-rules.cap-BJKUjizS.js");
8
+ const require_notification_targets = require("../../notification-targets-ChqpBbtR.js");
9
+ const require_notification_rules_cap = require("../../notification-rules.cap-uSLoe2pA.js");
10
+ const require_time_window = require("../../time-window-B6UhCArd.js");
10
11
  const require_integration_instances_cap = require("../../integration-instances.cap-DSieF1w3.js");
11
12
  let zod = require("zod");
12
13
  let node_crypto = require("node:crypto");
13
- //#region ../types/dist/esm/notification/schedule.mjs
14
- var WEEKDAY_TO_DAY = {
15
- Sun: 0,
16
- Mon: 1,
17
- Tue: 2,
18
- Wed: 3,
19
- Thu: 4,
20
- Fri: 5,
21
- Sat: 6
22
- };
14
+ //#region ../types/dist/esm/time/clock-range.mjs
23
15
  /**
24
- * One formatter per timezone, built once (D647 review I4). Constructing an
25
- * `Intl.DateTimeFormat` is the expensive part of this function, and a caller
26
- * that asks about many instants — a window scan — used to build one per
27
- * instant. `null` = an invalid IANA name (the host timezone is used).
16
+ * Stored clock ranges (numeric weekdays, minutes of the day) read as a
17
+ * {@link TimeWindow}. Two stored formats, a notification schedule window and a
18
+ * recording band, keep their shape and ask "is this instant inside" of the one
19
+ * evaluator, {@link judgeTimeWindow}, through this adapter.
28
20
  */
29
- var FORMATTERS = /* @__PURE__ */ new Map();
30
- function formatterFor(timezone) {
31
- const held = FORMATTERS.get(timezone);
32
- if (held !== void 0) return held;
33
- let made;
34
- try {
35
- made = new Intl.DateTimeFormat("en-US", {
36
- timeZone: timezone,
37
- weekday: "short",
38
- hour: "numeric",
39
- minute: "numeric",
40
- hourCycle: "h23"
41
- });
42
- } catch {
43
- made = null;
21
+ var MINUTES_PER_DAY = 1440;
22
+ var MINUTES_PER_HOUR = 60;
23
+ function clockOfMinute(minuteOfDay) {
24
+ const wrapped = minuteOfDay % MINUTES_PER_DAY;
25
+ return {
26
+ kind: "clock",
27
+ hh: Math.floor(wrapped / MINUTES_PER_HOUR),
28
+ mm: wrapped % MINUTES_PER_HOUR
29
+ };
30
+ }
31
+ /** A numeric weekday list as keys; a number outside 0-6 is dropped. */
32
+ function weekdayKeysOf(days) {
33
+ const keys = [];
34
+ for (const day of days) {
35
+ const key = require_time_window.weekdayKeyOfIndex(day);
36
+ if (key !== void 0) keys.push(key);
44
37
  }
45
- FORMATTERS.set(timezone, made);
46
- return made;
38
+ return keys;
47
39
  }
48
- /** Resolve (weekday, minute-of-day) of `atMs` in the schedule's timezone.
49
- * An invalid/unknown IANA name falls back to the host timezone. */
50
- function localDayMinute(atMs, timezone) {
51
- const d = new Date(atMs);
52
- const formatter = timezone !== void 0 ? formatterFor(timezone) : null;
53
- if (formatter !== null) try {
54
- const parts = formatter.formatToParts(d);
55
- let weekday;
56
- let hour;
57
- let minute;
58
- for (const p of parts) if (p.type === "weekday") weekday = p.value;
59
- else if (p.type === "hour") hour = Number(p.value);
60
- else if (p.type === "minute") minute = Number(p.value);
61
- const day = weekday !== void 0 ? WEEKDAY_TO_DAY[weekday] : void 0;
62
- if (day !== void 0 && hour !== void 0 && minute !== void 0) return {
63
- day,
64
- minute: hour * 60 + minute
65
- };
66
- } catch {}
40
+ /**
41
+ * The window of a stored clock range. `startMinute` is inclusive and
42
+ * `endMinute` exclusive; `endMinute` may be 1440 (the end of the day), and
43
+ * `startMinute > endMinute` crosses midnight. `startMinute === endMinute` is
44
+ * the WHOLE local day on `days` (what a recording band means by it); a caller
45
+ * for which equal ends mean "empty" must not build a window (the notification
46
+ * schedule skips it). `days` undefined = every day.
47
+ */
48
+ function clockRangeWindow(days, startMinute, endMinute) {
49
+ const daysPart = days === void 0 ? {} : { days: weekdayKeysOf(days) };
50
+ if (startMinute === endMinute) return daysPart;
67
51
  return {
68
- day: d.getDay(),
69
- minute: d.getHours() * 60 + d.getMinutes()
52
+ ...daysPart,
53
+ between: {
54
+ from: clockOfMinute(startMinute),
55
+ to: clockOfMinute(endMinute)
56
+ }
70
57
  };
71
58
  }
72
59
  /**
60
+ * Is `atMs` inside the stored clock range on `site`. Same arguments as
61
+ * {@link clockRangeWindow}; the answer is the shared evaluator's.
62
+ */
63
+ function isWithinClockRange(days, startMinute, endMinute, atMs, site) {
64
+ return require_time_window.isWithinTimeWindow(clockRangeWindow(days, startMinute, endMinute), atMs, site);
65
+ }
66
+ var hostZone;
67
+ /**
68
+ * The host's IANA zone, resolved once and cached for the life of the process.
69
+ * The cache can be stale only if the host zone changes while running (a TZ edit
70
+ * or a laptop crossing zones); a restart picks the new zone up. A DST change is
71
+ * not a zone change and never stales it.
72
+ */
73
+ function hostTimeZone() {
74
+ hostZone ??= new Intl.DateTimeFormat().resolvedOptions().timeZone;
75
+ return hostZone;
76
+ }
77
+ //#endregion
78
+ //#region ../types/dist/esm/notification/schedule.mjs
79
+ /** An absent or unknown IANA name reads the host zone. */
80
+ function scheduleZone(timezone) {
81
+ return timezone !== void 0 && require_time_window.isKnownTimeZone(timezone) ? timezone : hostTimeZone();
82
+ }
83
+ /**
84
+ * A window with no listed day, or whose start equals its end, is EMPTY in this
85
+ * vocabulary (it never matches); the shared model would read equal ends as a
86
+ * whole day, so such a window is not handed to it.
87
+ */
88
+ function isEmptyWindow(w) {
89
+ return w.days.length === 0 || w.startMinute === w.endMinute;
90
+ }
91
+ /**
73
92
  * Is the schedule active at `atMs`? No schedule = always active. Windows
74
93
  * are OR'd; a window with `startMinute > endMinute` crosses midnight (it
75
94
  * starts on a listed day and spills into the next). `invert` flips the
@@ -77,18 +96,8 @@ function localDayMinute(atMs, timezone) {
77
96
  */
78
97
  function isScheduleActive(schedule, atMs) {
79
98
  if (schedule === void 0) return true;
80
- const { day, minute } = localDayMinute(atMs, schedule.timezone);
81
- const prevDay = (day + 6) % 7;
82
- let inside = false;
83
- for (const w of schedule.windows) if (w.startMinute <= w.endMinute) {
84
- if (w.days.includes(day) && minute >= w.startMinute && minute < w.endMinute) {
85
- inside = true;
86
- break;
87
- }
88
- } else if (w.days.includes(day) && minute >= w.startMinute || w.days.includes(prevDay) && minute < w.endMinute) {
89
- inside = true;
90
- break;
91
- }
99
+ const site = require_time_window.zoneOnlySite(scheduleZone(schedule.timezone));
100
+ const inside = schedule.windows.some((w) => !isEmptyWindow(w) && isWithinClockRange(w.days, w.startMinute, w.endMinute, atMs, site));
92
101
  return schedule.invert === true ? !inside : inside;
93
102
  }
94
103
  //#endregion