@capybara-hq/kernel 0.1.0-rc.120 → 0.1.0-rc.122

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 (230) hide show
  1. package/dist/background/finish.d.ts +5 -1
  2. package/dist/background/finish.js +29 -18
  3. package/dist/background/launch.d.ts +0 -5
  4. package/dist/background/launch.js +1 -6
  5. package/dist/background/managed.js +1 -4
  6. package/dist/background/poll.job.d.ts +3 -25
  7. package/dist/background/poll.job.js +20 -112
  8. package/dist/background/render.d.ts +2 -8
  9. package/dist/background/render.js +3 -17
  10. package/dist/background/stop.d.ts +15 -16
  11. package/dist/background/stop.js +39 -76
  12. package/dist/background/store.d.ts +17 -45
  13. package/dist/background/store.js +60 -94
  14. package/dist/background/tasks.service.d.ts +2 -5
  15. package/dist/background/tasks.service.js +9 -20
  16. package/dist/background/wake.js +3 -2
  17. package/dist/catalog/admin-catalog.controller.d.ts +2 -18
  18. package/dist/catalog/admin-catalog.controller.js +2 -28
  19. package/dist/catalog/catalog-content.d.ts +1 -5
  20. package/dist/catalog/catalog-items.d.ts +2 -6
  21. package/dist/catalog/catalog-items.js +5 -26
  22. package/dist/catalog/catalog-scope.service.d.ts +1 -121
  23. package/dist/catalog/catalog-scope.service.js +12 -552
  24. package/dist/catalog/catalog.service.d.ts +4 -15
  25. package/dist/catalog/catalog.service.js +7 -35
  26. package/dist/catalog/job-ids.d.ts +0 -18
  27. package/dist/catalog/job-ids.js +0 -20
  28. package/dist/catalog/marketplaces.service.d.ts +1 -1
  29. package/dist/catalog/org-catalog.service.js +6 -20
  30. package/dist/catalog/org-plugin-uploads.controller.d.ts +4 -19
  31. package/dist/catalog/org-plugin-uploads.controller.js +6 -34
  32. package/dist/catalog/org-plugin-uploads.d.ts +3 -10
  33. package/dist/catalog/org-plugin-uploads.js +4 -18
  34. package/dist/catalog/org-plugin-uploads.schemas.js +0 -1
  35. package/dist/catalog/owned-items.d.ts +6 -11
  36. package/dist/catalog/owned-items.js +10 -20
  37. package/dist/catalog/ownership.d.ts +3 -29
  38. package/dist/catalog/ownership.js +4 -54
  39. package/dist/catalog/platform-components.d.ts +5 -11
  40. package/dist/catalog/platform-components.js +8 -15
  41. package/dist/catalog/plugin-import.d.ts +3 -42
  42. package/dist/catalog/plugin-import.js +26 -195
  43. package/dist/catalog/plugin-install.js +1 -6
  44. package/dist/catalog/plugin-package.d.ts +1 -0
  45. package/dist/catalog/plugin-package.js +5 -0
  46. package/dist/catalog/plugin-upgrade.d.ts +3 -26
  47. package/dist/catalog/plugin-upgrade.js +20 -103
  48. package/dist/catalog/request-rules.js +4 -6
  49. package/dist/catalog/scope-sync.js +2 -4
  50. package/dist/catalog/scope.d.ts +2 -5
  51. package/dist/channels/jobs.d.ts +3 -3
  52. package/dist/channels/jobs.js +4 -3
  53. package/dist/channels/outbound.d.ts +1 -0
  54. package/dist/channels/outbound.js +32 -8
  55. package/dist/config/load.d.ts +0 -25
  56. package/dist/config/load.js +0 -57
  57. package/dist/config/schema.js +2 -3
  58. package/dist/conversations/attachments.service.js +3 -5
  59. package/dist/conversations/conversations.service.d.ts +3 -3
  60. package/dist/conversations/conversations.service.js +3 -3
  61. package/dist/conversations/job-org.d.ts +3 -0
  62. package/dist/conversations/job-org.js +11 -0
  63. package/dist/conversations/prompt-suggestions.d.ts +2 -7
  64. package/dist/conversations/prompt-suggestions.js +29 -27
  65. package/dist/conversations/titles.d.ts +3 -4
  66. package/dist/conversations/titles.js +19 -30
  67. package/dist/db/kernel-schema.d.ts +6 -16
  68. package/dist/db/pool.js +7 -2
  69. package/dist/devices/devices.controller.d.ts +0 -5
  70. package/dist/devices/devices.controller.js +2 -20
  71. package/dist/devices/devices.service.d.ts +1 -17
  72. package/dist/devices/devices.service.js +0 -22
  73. package/dist/errors.d.ts +1 -5
  74. package/dist/errors.js +1 -5
  75. package/dist/evals/judge.d.ts +3 -0
  76. package/dist/evals/judge.js +1 -1
  77. package/dist/evals/run-replay.d.ts +1 -1
  78. package/dist/evals/run-replay.js +26 -29
  79. package/dist/evals/step-replay.d.ts +3 -1
  80. package/dist/evals/step-replay.js +10 -1
  81. package/dist/evals/worker.d.ts +3 -1
  82. package/dist/evals/worker.js +53 -21
  83. package/dist/extensions/deployment-config-store.js +18 -14
  84. package/dist/extensions/effective-config.d.ts +1 -5
  85. package/dist/extensions/effective-config.js +1 -5
  86. package/dist/extensions/hooks.d.ts +3 -1
  87. package/dist/extensions/hooks.js +7 -2
  88. package/dist/extensions/installs.d.ts +2 -14
  89. package/dist/extensions/installs.js +10 -32
  90. package/dist/extensions/org-config.d.ts +3 -4
  91. package/dist/extensions/org-config.js +3 -4
  92. package/dist/extensions/plugin-guides.d.ts +0 -1
  93. package/dist/extensions/plugin-guides.js +0 -1
  94. package/dist/extensions/plugin-icons.d.ts +0 -1
  95. package/dist/extensions/plugin-icons.js +0 -3
  96. package/dist/files/blob-sweep.job.d.ts +2 -11
  97. package/dist/files/blob-sweep.job.js +7 -21
  98. package/dist/files/hash-job.d.ts +5 -15
  99. package/dist/files/hash-job.js +14 -33
  100. package/dist/files/library-jobs.module.d.ts +1 -6
  101. package/dist/files/library-jobs.module.js +3 -9
  102. package/dist/identity/api-tokens.js +54 -40
  103. package/dist/identity/auth.guard.js +2 -2
  104. package/dist/identity/sessions.js +7 -3
  105. package/dist/identity/settings.js +5 -21
  106. package/dist/inbox/inbox.service.d.ts +2 -3
  107. package/dist/inbox/org-notices.d.ts +0 -14
  108. package/dist/inbox/platform-inbox.service.d.ts +1 -8
  109. package/dist/inbox/platform-inbox.service.js +2 -6
  110. package/dist/inbox/platform-notices.d.ts +3 -3
  111. package/dist/index.d.ts +0 -4
  112. package/dist/index.js +0 -3
  113. package/dist/infra/database/database.module.js +2 -1
  114. package/dist/infra/database/org-scope.d.ts +5 -3
  115. package/dist/infra/database/org-scope.js +7 -1
  116. package/dist/infra/database/scoped-dialect.d.ts +3 -1
  117. package/dist/infra/database/scoped-dialect.js +17 -5
  118. package/dist/infra/events/kernel-events.d.ts +2 -0
  119. package/dist/infra/outbox/outbox.service.d.ts +2 -0
  120. package/dist/infra/outbox/outbox.service.js +10 -0
  121. package/dist/infra/outbox/registry.d.ts +0 -41
  122. package/dist/infra/outbox/registry.js +0 -37
  123. package/dist/models/embeddings.d.ts +0 -5
  124. package/dist/models/embeddings.js +28 -35
  125. package/dist/models/images.d.ts +3 -8
  126. package/dist/models/images.js +19 -37
  127. package/dist/models/purposes.d.ts +7 -2
  128. package/dist/models/purposes.js +16 -3
  129. package/dist/orgs/device-network-setting.d.ts +0 -44
  130. package/dist/orgs/device-network-setting.js +0 -83
  131. package/dist/orgs/invitations.service.js +34 -30
  132. package/dist/orgs/offboarding.d.ts +2 -2
  133. package/dist/orgs/offboarding.js +2 -2
  134. package/dist/orgs/orgs.service.d.ts +1 -1
  135. package/dist/orgs/orgs.service.js +19 -15
  136. package/dist/orgs/settings.service.d.ts +19 -14
  137. package/dist/orgs/settings.service.js +12 -37
  138. package/dist/platform/exclusions.js +0 -11
  139. package/dist/platform/ops/catalog-admin.ops.js +0 -8
  140. package/dist/platform/ops/devices.ops.js +0 -28
  141. package/dist/platform/ops/extensions-admin.ops.js +3 -3
  142. package/dist/platform/ops/inbox.ops.js +5 -22
  143. package/dist/platform/ops/org-plugins.ops.d.ts +1 -3
  144. package/dist/platform/ops/org-plugins.ops.js +11 -67
  145. package/dist/plugin-reads/plugin-reads.service.js +2 -1
  146. package/dist/roles/worker.module.js +0 -9
  147. package/dist/runtime/hook-calls.d.ts +13 -6
  148. package/dist/runtime/hook-calls.js +26 -4
  149. package/dist/runtime/maintenance.d.ts +3 -12
  150. package/dist/runtime/maintenance.js +25 -55
  151. package/dist/runtime/model-call.d.ts +4 -2
  152. package/dist/runtime/model-call.js +59 -58
  153. package/dist/runtime/providers.d.ts +27 -1
  154. package/dist/runtime/providers.js +57 -0
  155. package/dist/runtime/run-jobs.d.ts +1 -1
  156. package/dist/runtime/run-processors.d.ts +3 -9
  157. package/dist/runtime/run-worker.d.ts +2 -0
  158. package/dist/runtime/run-worker.js +23 -8
  159. package/dist/runtime/subagents/deliveries.js +6 -1
  160. package/dist/runtime/subagents/dispatch.d.ts +3 -3
  161. package/dist/runtime/write-base.service.d.ts +2 -3
  162. package/dist/runtime/write-base.service.js +3 -5
  163. package/dist/sandbox/device-sandbox-settings.d.ts +38 -92
  164. package/dist/sandbox/device-sandbox-settings.js +19 -325
  165. package/dist/sandbox/jobs.d.ts +3 -14
  166. package/dist/sandbox/jobs.js +2 -20
  167. package/dist/sandbox/modes.d.ts +5 -45
  168. package/dist/sandbox/modes.js +3 -60
  169. package/dist/sandbox/operation-authority.js +0 -11
  170. package/dist/sandbox/operation-intents.d.ts +32 -9
  171. package/dist/sandbox/operation-intents.js +241 -32
  172. package/dist/sandbox/operation-intents.module.js +2 -1
  173. package/dist/sandbox/operation-reconcile.job.d.ts +9 -11
  174. package/dist/sandbox/operation-reconcile.job.js +119 -33
  175. package/dist/sandbox/operation-revoke.d.ts +20 -0
  176. package/dist/sandbox/operation-revoke.js +3 -0
  177. package/dist/sandbox/permission-ceiling-writes.d.ts +1 -2
  178. package/dist/sandbox/permission-ceiling-writes.js +3 -6
  179. package/dist/sandbox/permission-config-publication.d.ts +1 -28
  180. package/dist/sandbox/permission-config-publication.js +14 -211
  181. package/dist/sandbox/permission-facts.d.ts +4 -15
  182. package/dist/sandbox/permission-facts.js +7 -29
  183. package/dist/sandbox/permission-instance-writes.d.ts +1 -4
  184. package/dist/sandbox/permission-instance-writes.js +1 -55
  185. package/dist/sandbox/providers.d.ts +1 -6
  186. package/dist/sandbox/providers.js +1 -15
  187. package/dist/sandbox/review/classifier.js +12 -13
  188. package/dist/sandbox/sandbox.module.js +3 -6
  189. package/dist/sandbox/sandbox.service.d.ts +17 -123
  190. package/dist/sandbox/sandbox.service.js +239 -998
  191. package/dist/shares/liveness.d.ts +1 -2
  192. package/dist/shares/liveness.js +1 -2
  193. package/dist/shares/shares.module.d.ts +1 -2
  194. package/dist/shares/shares.module.js +2 -5
  195. package/dist/shares/shares.service.js +1 -2
  196. package/dist/tools/builtins/image/generate.js +7 -15
  197. package/dist/tools/builtins/sandbox/common.d.ts +0 -2
  198. package/dist/tools/builtins/sandbox/common.js +1 -27
  199. package/dist/tools/builtins/sandbox/task-list.js +10 -10
  200. package/dist/tools/builtins/sandbox/task-output.d.ts +3 -10
  201. package/dist/tools/builtins/sandbox/task-output.js +13 -83
  202. package/dist/tools/builtins/sandbox/task-stop.js +18 -22
  203. package/dist/tools/builtins/vision/read-image.js +9 -10
  204. package/dist/tools/builtins/web/extract.js +9 -10
  205. package/package.json +3 -3
  206. package/src/migrations/0206_retire_org_extension_uploads.sql +125 -0
  207. package/src/migrations/0207_confirm_device_instance_destruction.sql +25 -0
  208. package/src/migrations/0208_convert_stored_permission_settings.sql +189 -0
  209. package/dist/background/retire-legacy-tasks.job.d.ts +0 -57
  210. package/dist/background/retire-legacy-tasks.job.js +0 -149
  211. package/dist/catalog/owned-plugin-cleanup.d.ts +0 -47
  212. package/dist/catalog/owned-plugin-cleanup.js +0 -140
  213. package/dist/config/permission-migration.d.ts +0 -34
  214. package/dist/config/permission-migration.js +0 -115
  215. package/dist/devices/legacy-cleanup.job.d.ts +0 -34
  216. package/dist/devices/legacy-cleanup.job.js +0 -147
  217. package/dist/files/library-backfill.d.ts +0 -63
  218. package/dist/files/library-backfill.js +0 -143
  219. package/dist/infra/cli/permission-cutover.d.ts +0 -59
  220. package/dist/infra/cli/permission-cutover.js +0 -107
  221. package/dist/sandbox/cloud-permission-snapshot.d.ts +0 -159
  222. package/dist/sandbox/cloud-permission-snapshot.js +0 -430
  223. package/dist/sandbox/cloud-permission-snapshot.module.d.ts +0 -8
  224. package/dist/sandbox/cloud-permission-snapshot.module.js +0 -34
  225. package/dist/sandbox/legacy-retirement.d.ts +0 -284
  226. package/dist/sandbox/legacy-retirement.js +0 -1165
  227. package/dist/sandbox/legacy-retirement.module.d.ts +0 -8
  228. package/dist/sandbox/legacy-retirement.module.js +0 -25
  229. package/dist/shares/share-objects.d.ts +0 -47
  230. package/dist/shares/share-objects.js +0 -93
@@ -2,7 +2,6 @@ import { z } from "zod";
2
2
  import type { KernelSchemaDb } from "../db/kernel-schema.js";
3
3
  import type { KernelConfigService } from "../infra/config/kernel-config.service.js";
4
4
  import type { KernelLogger } from "../log.js";
5
- import { type DeviceNetworkSetting } from "../orgs/device-network-setting.js";
6
5
  import type { DeviceNetworkMode, DeviceSandboxSettings } from "./device-sandbox.js";
7
6
  /**
8
7
  * The platform's device sandbox settings (approval-only profiles design, "Settings model"): the
@@ -13,23 +12,12 @@ import type { DeviceNetworkMode, DeviceSandboxSettings } from "./device-sandbox.
13
12
  * console > {@link DEVICE_SANDBOX_DEFAULTS}. A field set in the startup config is read-only in the
14
13
  * admin console. An invalid stored value reads narrower with a warning (fail closed): `off`, and
15
14
  * the allowlist.
16
- *
17
- * Before 0.1.0 the old keys are converted, never aliased: the deployment settings
18
- * `devicesFullAccess` and `devicesAutoMode` and the org keys `fullAccess`, `autoMode` and
19
- * `cloudNetwork` are read (the narrower wins) until the permission configuration publication
20
- * converts them ({@link convertStoredPermissionKeys}); writes keep a still stored old key in step
21
- * for replicas of the previous version. An old `off` kept every device on the allowlist, so it
22
- * converts to `outsideSandbox: off` plus an allowlist network ceiling (never wider).
23
15
  */
24
16
  export type OutsideSandboxPermission = "allowed" | "off";
25
17
  /** The `deployment_settings` key of the super admin's outside-sandbox choice. */
26
18
  export declare const DEVICES_OUTSIDE_SANDBOX_SETTING = "devicesOutsideSandbox";
27
19
  /** The `deployment_settings` key of the super admin's network choice. */
28
20
  export declare const DEVICES_NETWORK_SETTING = "devicesNetwork";
29
- /** The old key of the outside-sandbox choice (B1's Full switch), read only to convert it. */
30
- export declare const LEGACY_DEVICES_FULL_ACCESS_SETTING = "devicesFullAccess";
31
- /** The key B1 converted (the auto-mode switch), read only to convert it. */
32
- export declare const LEGACY_DEVICES_AUTO_MODE_SETTING = "devicesAutoMode";
33
21
  /** What a deployment with neither the startup config nor the stored choice says. */
34
22
  export declare const DEVICE_SANDBOX_DEFAULTS: DeviceSandboxSettings;
35
23
  /** The stored outside-sandbox choice: `permission` absent follows the default. */
@@ -125,24 +113,10 @@ export declare function parseStoredDevicesOutsideSandbox(value: unknown, log?: P
125
113
  * warning, narrower, never wider.
126
114
  */
127
115
  export declare function parseStoredDevicesNetwork(value: unknown, log?: Pick<KernelLogger, "warn">): DevicesNetworkStored;
128
- /**
129
- * Converts a stored old `devicesFullAccess` (`{ permission }`): the same permission, and an `off`
130
- * also limits the network ceiling to the allowlist; an invalid value converts to `off` with a
131
- * warning, never absent.
132
- */
133
- export declare function parseLegacyStoredDevicesFullAccess(value: unknown, log?: Pick<KernelLogger, "warn">): StoredDeviceSandbox;
134
- /** Converts a stored old `devicesAutoMode` (`{ mode }`) like {@link parseLegacyStoredDevicesFullAccess}. */
135
- export declare function parseLegacyStoredDevicesAutoMode(value: unknown, log?: Pick<KernelLogger, "warn">): StoredDeviceSandbox;
136
116
  /** The stored outside-sandbox choice with `patch` applied (`permission: null` clears it). */
137
117
  export declare function applyDevicesOutsideSandboxPatch(_stored: DevicesOutsideSandboxStored, patch: DevicesOutsideSandboxPatch): DevicesOutsideSandboxStored;
138
118
  /** The stored network choice with `patch` applied (a null field clears it). */
139
119
  export declare function applyDevicesNetworkPatch(stored: DevicesNetworkStored, patch: DevicesNetworkPatch): DevicesNetworkStored;
140
- /**
141
- * The narrower of two stored choices, field by field: `off` / `allowlist` when either says so;
142
- * otherwise `a`'s value, else `b`'s (an absent value follows the default, the widest, so `allowed`
143
- * or `open` over absent says the same and is kept, as a conversion must be exact).
144
- */
145
- export declare function narrowerStoredDeviceSandbox(a: StoredDeviceSandbox, b: StoredDeviceSandbox): StoredDeviceSandbox;
146
120
  /**
147
121
  * The effective settings and their sources, pure (the reader below adds the database read). The
148
122
  * startup config fields are optional with no schema default, so a defined value with a source
@@ -154,19 +128,8 @@ export declare function resolveDeviceSandboxSettings(configured: ConfiguredDevic
154
128
  export declare const deviceSandboxSettingsOf: (view: DeviceSandboxSettingsView) => DeviceSandboxSettings;
155
129
  /** The startup config's values and sources. */
156
130
  export declare function configuredDeviceSandbox(config: Pick<KernelConfigService, "get" | "fieldSource">): ConfiguredDeviceSandbox;
157
- /**
158
- * The old permission value written next to the new keys for replicas of the previous version
159
- * (their Full switch): `allowed` only when running outside the sandbox is allowed AND the network
160
- * ceiling is open, else `off`, so an old replica never reads Full where a new one keeps devices on
161
- * the allowlist. `outside` absent with an open ceiling stays absent (follow the default).
162
- */
163
- export declare function legacyPermissionFor(outside: OutsideSandboxPermission | undefined, ceiling: DeviceNetworkMode | undefined): OutsideSandboxPermission | undefined;
164
- /** The stored choices, read live (in the caller's transaction when there is one). */
165
- export declare function readStoredDeviceSandbox(db: KernelSchemaDb, log?: Pick<KernelLogger, "warn">, configuredCeiling?: DeviceNetworkMode): Promise<StoredDeviceSandbox>;
166
- /** The old platform keys still stored (a write then keeps them in step until they are converted). */
167
- export declare function legacyPlatformKeysStored(db: KernelSchemaDb): Promise<string[]>;
168
- /** The value an old platform key stores for `permission` (absent: follow the default). */
169
- export declare const legacyPlatformValue: (key: string, permission: OutsideSandboxPermission | undefined) => unknown;
131
+ /** Read the current deployment choices in the caller's transaction. */
132
+ export declare function readStoredDeviceSandbox(db: KernelSchemaDb, log?: Pick<KernelLogger, "warn">): Promise<StoredDeviceSandbox>;
170
133
  /**
171
134
  * The platform's effective device sandbox settings with their sources, read live from PG at every
172
135
  * use (so a change applies on every replica at once): see {@link resolveDeviceSandboxSettings}.
@@ -174,57 +137,40 @@ export declare const legacyPlatformValue: (key: string, permission: OutsideSandb
174
137
  export declare function readDeviceSandboxSettingsView(db: KernelSchemaDb, config: Pick<KernelConfigService, "get" | "fieldSource">, log?: Pick<KernelLogger, "warn">): Promise<DeviceSandboxSettingsView>;
175
138
  /** The platform's effective device sandbox settings (the layer `effectiveDeviceSandbox` takes). */
176
139
  export declare function readDeviceSandboxSettings(db: KernelSchemaDb, config: Pick<KernelConfigService, "get" | "fieldSource">, log?: Pick<KernelLogger, "warn">): Promise<DeviceSandboxSettings>;
177
- /** An org's stored device sandbox keys, as every reader sees them. */
178
- export interface OrgDeviceSandboxStored {
179
- outsideSandbox?: OutsideSandboxPermission | undefined;
180
- deviceNetwork?: DeviceNetworkSetting | undefined;
181
- }
182
- /**
183
- * An org's `outsideSandbox` and `deviceNetwork` read over the new and the old keys (fail closed).
184
- * `deviceNetwork` present (a `{}` follow marker included) means this version wrote the settings:
185
- * - absent: the old keys are all there is and convert in full (design, "Migration"):
186
- * `fullAccess` / `autoMode` -> `outsideSandbox` (invalid: `off`), `cloudNetwork` ->
187
- * {@link convertLegacyCloudNetwork}, and an old `off` also narrows the ceiling to the allowlist;
188
- * - present: an old permission written in step ({@link legacyPermissionFor} `outsideSandbox` and
189
- * the org's own ceiling; the platform's ceiling reaches old replicas through the platform's own
190
- * old key) and a `cloudNetwork` written in step ({@link legacyCloudNetworkOf}) say nothing more;
191
- * one that differs (an old replica wrote it) narrows as a conversion would.
192
- */
193
- export declare function orgDeviceSandboxOf(raw: unknown): OrgDeviceSandboxStored;
194
- /** Whether an org's stored settings still hold an old permission key. */
195
- export declare const orgLegacyKeysStored: (raw: unknown) => boolean;
196
- /**
197
- * The old org keys written next to the new ones while any of them is still stored (`written` is
198
- * the settings object about to be stored; `stored` the one it replaces): `fullAccess` / `autoMode`
199
- * carry {@link legacyPermissionFor} `outsideSandbox` and the org's ceiling, `cloudNetwork` carries
200
- * {@link legacyCloudNetworkOf} `deviceNetwork`; a value that says nothing removes the old key.
201
- * `deviceNetwork` cleared is stored as `{}`, the marker that this version wrote the settings.
202
- */
203
- export declare function keepOrgLegacyKeysInStep(written: Record<string, unknown>, stored: Record<string, unknown>): void;
204
- /**
205
- * Locks the org rows {@link convertStoredPermissionKeys} would convert, in id order, before the
206
- * caller takes the platform authority write lock: the global lock order puts the org row before
207
- * the permission authority locks (a fenced prelude holds an org row while it waits for its shared
208
- * platform lock). The conversion itself then finds its rows already held.
209
- */
210
- export declare function lockOrgsWithStoredPermissionKeys(db: KernelSchemaDb): Promise<void>;
211
- /** What the conversion needs of the startup config: the configured network ceiling. */
212
- export interface PermissionKeyConversionContext {
213
- configuredCeiling?: DeviceNetworkMode | undefined;
214
- }
215
- /**
216
- * The conversion of the stored permission keys (design, "Migration"), run inside the permission
217
- * configuration publication transaction under the platform authority write lock (which excludes
218
- * every org and device writer; the caller locked the org rows to convert before it,
219
- * {@link lockOrgsWithStoredPermissionKeys}), at every publication: old keys an old replica writes
220
- * later are converted too. It stores exactly what every reader saw ({@link storedOf},
221
- * {@link orgDeviceSandboxOf}), never wider, and removes the old keys:
222
- * - the deployment settings `devicesAutoMode` / `devicesFullAccess` become `devicesOutsideSandbox`
223
- * and `devicesNetwork` (an empty network removes the row);
224
- * - every org's `autoMode` / `fullAccess` / `cloudNetwork` become `outsideSandbox` and
225
- * `deviceNetwork` (absent stays absent: the org follows the platform).
226
- * Each platform or org whose network an old `off` narrowed to the allowlist is named in one
227
- * warning, with how to reopen it. Idempotent; never refuses.
228
- */
229
- export declare function convertStoredPermissionKeys(db: KernelSchemaDb, log?: Pick<KernelLogger, "warn">, context?: PermissionKeyConversionContext): Promise<void>;
140
+ export declare const OrgDeviceSandboxStoredSchema: z.ZodObject<{
141
+ outsideSandbox: z.ZodCatch<z.ZodOptional<z.ZodEnum<{
142
+ allowed: "allowed";
143
+ off: "off";
144
+ }>>>;
145
+ deviceNetwork: z.ZodOptional<z.ZodPipe<z.ZodCatch<z.ZodObject<{
146
+ default: z.ZodOptional<z.ZodEnum<{
147
+ allowlist: "allowlist";
148
+ open: "open";
149
+ }>>;
150
+ ceiling: z.ZodOptional<z.ZodEnum<{
151
+ allowlist: "allowlist";
152
+ open: "open";
153
+ }>>;
154
+ base: z.ZodOptional<z.ZodEnum<{
155
+ none: "none";
156
+ platform: "platform";
157
+ }>>;
158
+ extraHosts: z.ZodOptional<z.ZodArray<z.ZodString>>;
159
+ excludedHosts: z.ZodOptional<z.ZodArray<z.ZodString>>;
160
+ }, z.core.$strict>>, z.ZodTransform<{
161
+ default?: "allowlist" | "open" | undefined;
162
+ ceiling?: "allowlist" | "open" | undefined;
163
+ base?: "none" | "platform" | undefined;
164
+ extraHosts?: string[] | undefined;
165
+ excludedHosts?: string[] | undefined;
166
+ } | undefined, {
167
+ default?: "allowlist" | "open" | undefined;
168
+ ceiling?: "allowlist" | "open" | undefined;
169
+ base?: "none" | "platform" | undefined;
170
+ extraHosts?: string[] | undefined;
171
+ excludedHosts?: string[] | undefined;
172
+ }>>>;
173
+ }, z.core.$strip>;
174
+ /** Read the org's current choices. A missing choice follows the platform. */
175
+ export declare function orgDeviceSandboxOf(raw: unknown): z.infer<typeof OrgDeviceSandboxStoredSchema>;
230
176
  export {};
@@ -1,16 +1,9 @@
1
- import { sql } from "kysely";
2
1
  import { z } from "zod";
3
- import { convertLegacyCloudNetwork, DeviceNetworkSettingSchema, invalidDeviceNetwork, legacyCloudNetworkOf, narrowerDeviceNetwork, withAllowlistCeiling, } from "../orgs/device-network-setting.js";
2
+ import { DeviceNetworkSettingSchema, invalidDeviceNetwork, } from "../orgs/device-network-setting.js";
4
3
  /** The `deployment_settings` key of the super admin's outside-sandbox choice. */
5
4
  export const DEVICES_OUTSIDE_SANDBOX_SETTING = "devicesOutsideSandbox";
6
5
  /** The `deployment_settings` key of the super admin's network choice. */
7
6
  export const DEVICES_NETWORK_SETTING = "devicesNetwork";
8
- /** The old key of the outside-sandbox choice (B1's Full switch), read only to convert it. */
9
- export const LEGACY_DEVICES_FULL_ACCESS_SETTING = "devicesFullAccess";
10
- /** The key B1 converted (the auto-mode switch), read only to convert it. */
11
- export const LEGACY_DEVICES_AUTO_MODE_SETTING = "devicesAutoMode";
12
- /** The org settings keys the publication converts. */
13
- const LEGACY_ORG_KEYS = ["autoMode", "fullAccess", "cloudNetwork"];
14
7
  /** What a deployment with neither the startup config nor the stored choice says. */
15
8
  export const DEVICE_SANDBOX_DEFAULTS = {
16
9
  outsideSandbox: "allowed",
@@ -73,37 +66,6 @@ export function parseStoredDevicesNetwork(value, log) {
73
66
  });
74
67
  return { default: "allowlist", ceiling: "allowlist" };
75
68
  }
76
- /** What an old outside-sandbox value converts to: `off` also narrows the network ceiling. */
77
- const ofLegacyPermission = (permission) => permission === undefined
78
- ? { outsideSandbox: {}, network: {} }
79
- : {
80
- outsideSandbox: { permission },
81
- network: permission === "off" ? { ceiling: "allowlist" } : {},
82
- };
83
- /**
84
- * Converts a stored old `devicesFullAccess` (`{ permission }`): the same permission, and an `off`
85
- * also limits the network ceiling to the allowlist; an invalid value converts to `off` with a
86
- * warning, never absent.
87
- */
88
- export function parseLegacyStoredDevicesFullAccess(value, log) {
89
- const parsed = DevicesOutsideSandboxStoredSchema.safeParse(value);
90
- if (parsed.success)
91
- return ofLegacyPermission(parsed.data.permission);
92
- log?.warn("invalid deployment setting devicesFullAccess; it converts to off", {
93
- key: LEGACY_DEVICES_FULL_ACCESS_SETTING,
94
- });
95
- return ofLegacyPermission("off");
96
- }
97
- /** Converts a stored old `devicesAutoMode` (`{ mode }`) like {@link parseLegacyStoredDevicesFullAccess}. */
98
- export function parseLegacyStoredDevicesAutoMode(value, log) {
99
- const parsed = z.object({ mode: Permission.optional() }).strict().safeParse(value);
100
- if (parsed.success)
101
- return ofLegacyPermission(parsed.data.mode);
102
- log?.warn("invalid deployment setting devicesAutoMode; it converts to off", {
103
- key: LEGACY_DEVICES_AUTO_MODE_SETTING,
104
- });
105
- return ofLegacyPermission("off");
106
- }
107
69
  /** The stored outside-sandbox choice with `patch` applied (`permission: null` clears it). */
108
70
  export function applyDevicesOutsideSandboxPatch(_stored, patch) {
109
71
  return patch.permission === null ? {} : { permission: patch.permission };
@@ -120,26 +82,6 @@ export function applyDevicesNetworkPatch(stored, patch) {
120
82
  }
121
83
  return next;
122
84
  }
123
- const narrowerMode = (a, b) => a === "allowlist" || b === "allowlist" ? "allowlist" : (a ?? b);
124
- /**
125
- * The narrower of two stored choices, field by field: `off` / `allowlist` when either says so;
126
- * otherwise `a`'s value, else `b`'s (an absent value follows the default, the widest, so `allowed`
127
- * or `open` over absent says the same and is kept, as a conversion must be exact).
128
- */
129
- export function narrowerStoredDeviceSandbox(a, b) {
130
- const permission = a.outsideSandbox.permission === "off" || b.outsideSandbox.permission === "off"
131
- ? "off"
132
- : (a.outsideSandbox.permission ?? b.outsideSandbox.permission);
133
- const def = narrowerMode(a.network.default, b.network.default);
134
- const ceiling = narrowerMode(a.network.ceiling, b.network.ceiling);
135
- return {
136
- outsideSandbox: permission === undefined ? {} : { permission },
137
- network: {
138
- ...(def !== undefined && { default: def }),
139
- ...(ceiling !== undefined && { ceiling }),
140
- },
141
- };
142
- }
143
85
  /**
144
86
  * The effective settings and their sources, pure (the reader below adds the database read). The
145
87
  * startup config fields are optional with no schema default, so a defined value with a source
@@ -184,287 +126,39 @@ export function configuredDeviceSandbox(config) {
184
126
  },
185
127
  };
186
128
  }
187
- /** The stored platform rows, by key. */
188
- async function storedRows(db, forUpdate = false) {
189
- let q = db
129
+ /** Read the current deployment choices in the caller's transaction. */
130
+ export async function readStoredDeviceSandbox(db, log) {
131
+ const rows = await db
190
132
  .selectFrom("deployment_settings")
191
133
  .select(["key", "value"])
192
- .where("key", "in", [
193
- DEVICES_OUTSIDE_SANDBOX_SETTING,
194
- DEVICES_NETWORK_SETTING,
195
- LEGACY_DEVICES_FULL_ACCESS_SETTING,
196
- LEGACY_DEVICES_AUTO_MODE_SETTING,
197
- ]);
198
- if (forUpdate)
199
- q = q.forUpdate();
200
- const rows = await q.execute();
201
- return new Map(rows.map((r) => [r.key, r.value]));
202
- }
203
- /** The old platform keys of `rows`, each converted. */
204
- function legacyOf(rows, log) {
205
- const out = [];
206
- if (rows.has(LEGACY_DEVICES_AUTO_MODE_SETTING))
207
- out.push({
208
- key: LEGACY_DEVICES_AUTO_MODE_SETTING,
209
- value: parseLegacyStoredDevicesAutoMode(rows.get(LEGACY_DEVICES_AUTO_MODE_SETTING), log),
210
- });
211
- if (rows.has(LEGACY_DEVICES_FULL_ACCESS_SETTING))
212
- out.push({
213
- key: LEGACY_DEVICES_FULL_ACCESS_SETTING,
214
- value: parseLegacyStoredDevicesFullAccess(rows.get(LEGACY_DEVICES_FULL_ACCESS_SETTING), log),
215
- });
216
- return out;
217
- }
218
- /**
219
- * The old permission value written next to the new keys for replicas of the previous version
220
- * (their Full switch): `allowed` only when running outside the sandbox is allowed AND the network
221
- * ceiling is open, else `off`, so an old replica never reads Full where a new one keeps devices on
222
- * the allowlist. `outside` absent with an open ceiling stays absent (follow the default).
223
- */
224
- export function legacyPermissionFor(outside, ceiling) {
225
- return outside === "off" || ceiling === "allowlist" ? "off" : outside;
226
- }
227
- /**
228
- * The stored choices of `rows` over every key (fail closed). Without `devicesOutsideSandbox` the
229
- * old keys are all there is: each converts in full (an `off` also narrows the network ceiling).
230
- * With it, an old key written in step ({@link legacyPermissionFor} the new keys and the effective
231
- * ceiling, `configuredCeiling` from the startup config winning over the stored one) says nothing
232
- * more; one that differs (an old replica wrote it) narrows as a conversion would.
233
- */
234
- function storedOf(rows, log, configuredCeiling) {
235
- const current = {
236
- outsideSandbox: parseStoredDevicesOutsideSandbox(rows.get(DEVICES_OUTSIDE_SANDBOX_SETTING), log),
237
- network: parseStoredDevicesNetwork(rows.get(DEVICES_NETWORK_SETTING), log),
134
+ .where("key", "in", [DEVICES_OUTSIDE_SANDBOX_SETTING, DEVICES_NETWORK_SETTING])
135
+ .execute();
136
+ const values = new Map(rows.map((row) => [row.key, row.value]));
137
+ return {
138
+ outsideSandbox: parseStoredDevicesOutsideSandbox(values.get(DEVICES_OUTSIDE_SANDBOX_SETTING), log),
139
+ network: parseStoredDevicesNetwork(values.get(DEVICES_NETWORK_SETTING), log),
238
140
  };
239
- const marked = rows.has(DEVICES_OUTSIDE_SANDBOX_SETTING);
240
- const inStep = legacyPermissionFor(current.outsideSandbox.permission, configuredCeiling ?? current.network.ceiling);
241
- let out = current;
242
- for (const { value } of legacyOf(rows, log)) {
243
- if (marked && value.outsideSandbox.permission === inStep)
244
- continue;
245
- out = narrowerStoredDeviceSandbox(out, value);
246
- }
247
- return out;
248
- }
249
- /** The stored choices, read live (in the caller's transaction when there is one). */
250
- export async function readStoredDeviceSandbox(db, log, configuredCeiling) {
251
- return storedOf(await storedRows(db), log, configuredCeiling);
252
141
  }
253
- /** The old platform keys still stored (a write then keeps them in step until they are converted). */
254
- export async function legacyPlatformKeysStored(db) {
255
- return [...(await storedRows(db)).keys()].filter((k) => k === LEGACY_DEVICES_FULL_ACCESS_SETTING || k === LEGACY_DEVICES_AUTO_MODE_SETTING);
256
- }
257
- /** The value an old platform key stores for `permission` (absent: follow the default). */
258
- export const legacyPlatformValue = (key, permission) => key === LEGACY_DEVICES_AUTO_MODE_SETTING
259
- ? permission === undefined
260
- ? {}
261
- : { mode: permission }
262
- : permission === undefined
263
- ? {}
264
- : { permission };
265
- /** The configured network ceiling (it wins over the stored one), or undefined. */
266
- const configuredCeilingOf = (c) => c.sources.networkCeiling !== undefined ? c.networkCeiling : undefined;
267
142
  /**
268
143
  * The platform's effective device sandbox settings with their sources, read live from PG at every
269
144
  * use (so a change applies on every replica at once): see {@link resolveDeviceSandboxSettings}.
270
145
  */
271
146
  export async function readDeviceSandboxSettingsView(db, config, log) {
272
147
  const configured = configuredDeviceSandbox(config);
273
- return resolveDeviceSandboxSettings(configured, await readStoredDeviceSandbox(db, log, configuredCeilingOf(configured)));
148
+ return resolveDeviceSandboxSettings(configured, await readStoredDeviceSandbox(db, log));
274
149
  }
275
150
  /** The platform's effective device sandbox settings (the layer `effectiveDeviceSandbox` takes). */
276
151
  export async function readDeviceSandboxSettings(db, config, log) {
277
152
  return deviceSandboxSettingsOf(await readDeviceSandboxSettingsView(db, config, log));
278
153
  }
279
154
  const asObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v) ? v : {};
280
- /** JSON with object keys sorted (PG's jsonb reorders them), for comparing stored values. */
281
- const canonical = (v) => JSON.stringify(v, (_k, x) => x !== null && typeof x === "object" && !Array.isArray(x)
282
- ? Object.fromEntries(Object.entries(x).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)))
283
- : x);
284
- /** An old org permission value converted: invalid reads as `off`. */
285
- const legacyOrgPermission = (v) => {
286
- const parsed = Permission.safeParse(v);
287
- return parsed.success ? parsed.data : "off";
288
- };
289
- /**
290
- * An org's `outsideSandbox` and `deviceNetwork` read over the new and the old keys (fail closed).
291
- * `deviceNetwork` present (a `{}` follow marker included) means this version wrote the settings:
292
- * - absent: the old keys are all there is and convert in full (design, "Migration"):
293
- * `fullAccess` / `autoMode` -> `outsideSandbox` (invalid: `off`), `cloudNetwork` ->
294
- * {@link convertLegacyCloudNetwork}, and an old `off` also narrows the ceiling to the allowlist;
295
- * - present: an old permission written in step ({@link legacyPermissionFor} `outsideSandbox` and
296
- * the org's own ceiling; the platform's ceiling reaches old replicas through the platform's own
297
- * old key) and a `cloudNetwork` written in step ({@link legacyCloudNetworkOf}) say nothing more;
298
- * one that differs (an old replica wrote it) narrows as a conversion would.
299
- */
155
+ export const OrgDeviceSandboxStoredSchema = z.object({
156
+ outsideSandbox: Permission.optional().catch("off"),
157
+ deviceNetwork: DeviceNetworkSettingSchema.catch(invalidDeviceNetwork)
158
+ .transform((network) => (Object.keys(network).length > 0 ? network : undefined))
159
+ .optional(),
160
+ });
161
+ /** Read the org's current choices. A missing choice follows the platform. */
300
162
  export function orgDeviceSandboxOf(raw) {
301
- const stored = asObject(raw);
302
- const parsedOutside = Permission.optional().safeParse(stored.outsideSandbox);
303
- const current = parsedOutside.success
304
- ? parsedOutside.data
305
- : "off";
306
- const legacy = ["autoMode", "fullAccess"]
307
- .filter((k) => k in stored)
308
- .map((k) => legacyOrgPermission(stored[k]));
309
- const marked = "deviceNetwork" in stored && stored.deviceNetwork !== undefined;
310
- if (!marked) {
311
- const outsideSandbox = current === "off" || legacy.includes("off") ? "off" : (current ?? legacy[0]);
312
- let deviceNetwork = convertLegacyCloudNetwork(stored.cloudNetwork);
313
- if (legacy.includes("off"))
314
- deviceNetwork = withAllowlistCeiling(deviceNetwork);
315
- return {
316
- ...(outsideSandbox !== undefined && { outsideSandbox }),
317
- ...(deviceNetwork !== undefined && { deviceNetwork }),
318
- };
319
- }
320
- const parsed = DeviceNetworkSettingSchema.safeParse(stored.deviceNetwork);
321
- let deviceNetwork = parsed.success
322
- ? parsed.data
323
- : invalidDeviceNetwork();
324
- if (deviceNetwork !== undefined && Object.keys(deviceNetwork).length === 0)
325
- deviceNetwork = undefined;
326
- // what the new keys alone would have written in step, before any old key narrows them
327
- const inStep = legacyPermissionFor(current, deviceNetwork?.ceiling);
328
- if ("cloudNetwork" in stored &&
329
- canonical(stored.cloudNetwork) !== canonical(legacyCloudNetworkOf(deviceNetwork)))
330
- deviceNetwork = narrowerDeviceNetwork(deviceNetwork ?? {}, convertLegacyCloudNetwork(stored.cloudNetwork));
331
- let outsideSandbox = current;
332
- for (const value of legacy) {
333
- if (value === inStep)
334
- continue;
335
- if (value === "off") {
336
- outsideSandbox = "off";
337
- deviceNetwork = withAllowlistCeiling(deviceNetwork);
338
- }
339
- else
340
- outsideSandbox ??= value;
341
- }
342
- return {
343
- ...(outsideSandbox !== undefined && { outsideSandbox }),
344
- ...(deviceNetwork !== undefined && { deviceNetwork }),
345
- };
346
- }
347
- /** Whether an org's stored settings still hold an old permission key. */
348
- export const orgLegacyKeysStored = (raw) => LEGACY_ORG_KEYS.some((k) => k in asObject(raw));
349
- /**
350
- * The old org keys written next to the new ones while any of them is still stored (`written` is
351
- * the settings object about to be stored; `stored` the one it replaces): `fullAccess` / `autoMode`
352
- * carry {@link legacyPermissionFor} `outsideSandbox` and the org's ceiling, `cloudNetwork` carries
353
- * {@link legacyCloudNetworkOf} `deviceNetwork`; a value that says nothing removes the old key.
354
- * `deviceNetwork` cleared is stored as `{}`, the marker that this version wrote the settings.
355
- */
356
- export function keepOrgLegacyKeysInStep(written, stored) {
357
- if (!orgLegacyKeysStored(stored))
358
- return;
359
- const outside = written.outsideSandbox;
360
- const network = written.deviceNetwork;
361
- const legacy = legacyPermissionFor(outside, network?.ceiling);
362
- for (const k of ["autoMode", "fullAccess"]) {
363
- if (!(k in stored))
364
- continue;
365
- if (legacy === undefined)
366
- delete written[k];
367
- else
368
- written[k] = legacy;
369
- }
370
- if ("cloudNetwork" in stored) {
371
- const old = legacyCloudNetworkOf(network);
372
- if (old === undefined)
373
- delete written.cloudNetwork;
374
- else
375
- written.cloudNetwork = old;
376
- }
377
- if (network === undefined)
378
- written.deviceNetwork = {};
379
- }
380
- /**
381
- * Locks the org rows {@link convertStoredPermissionKeys} would convert, in id order, before the
382
- * caller takes the platform authority write lock: the global lock order puts the org row before
383
- * the permission authority locks (a fenced prelude holds an org row while it waits for its shared
384
- * platform lock). The conversion itself then finds its rows already held.
385
- */
386
- export async function lockOrgsWithStoredPermissionKeys(db) {
387
- await db
388
- .selectFrom("orgs")
389
- .select("id")
390
- .where(sql `settings ?| ${sql.val([...LEGACY_ORG_KEYS])}::text[]`)
391
- .orderBy("id")
392
- // the conversion updates only `settings`, a non-key column: the org row lock's mode (OrgLock),
393
- // which leaves foreign key checks against the org (FOR KEY SHARE) unblocked
394
- .forNoKeyUpdate()
395
- .execute();
396
- }
397
- /**
398
- * The conversion of the stored permission keys (design, "Migration"), run inside the permission
399
- * configuration publication transaction under the platform authority write lock (which excludes
400
- * every org and device writer; the caller locked the org rows to convert before it,
401
- * {@link lockOrgsWithStoredPermissionKeys}), at every publication: old keys an old replica writes
402
- * later are converted too. It stores exactly what every reader saw ({@link storedOf},
403
- * {@link orgDeviceSandboxOf}), never wider, and removes the old keys:
404
- * - the deployment settings `devicesAutoMode` / `devicesFullAccess` become `devicesOutsideSandbox`
405
- * and `devicesNetwork` (an empty network removes the row);
406
- * - every org's `autoMode` / `fullAccess` / `cloudNetwork` become `outsideSandbox` and
407
- * `deviceNetwork` (absent stays absent: the org follows the platform).
408
- * Each platform or org whose network an old `off` narrowed to the allowlist is named in one
409
- * warning, with how to reopen it. Idempotent; never refuses.
410
- */
411
- export async function convertStoredPermissionKeys(db, log, context = {}) {
412
- const rows = await storedRows(db, true);
413
- const legacy = legacyOf(rows, log);
414
- if (legacy.length > 0) {
415
- const converted = storedOf(rows, log, context.configuredCeiling);
416
- const before = parseStoredDevicesNetwork(rows.get(DEVICES_NETWORK_SETTING));
417
- const upsert = (key, value) => db
418
- .insertInto("deployment_settings")
419
- .values({ key, value: JSON.stringify(value) })
420
- .onConflict((oc) => oc.column("key").doUpdateSet({ value: JSON.stringify(value) }))
421
- .execute();
422
- await upsert(DEVICES_OUTSIDE_SANDBOX_SETTING, converted.outsideSandbox);
423
- if (Object.keys(converted.network).length > 0)
424
- await upsert(DEVICES_NETWORK_SETTING, converted.network);
425
- else
426
- await db
427
- .deleteFrom("deployment_settings")
428
- .where("key", "=", DEVICES_NETWORK_SETTING)
429
- .execute();
430
- await db
431
- .deleteFrom("deployment_settings")
432
- .where("key", "in", [LEGACY_DEVICES_AUTO_MODE_SETTING, LEGACY_DEVICES_FULL_ACCESS_SETTING])
433
- .execute();
434
- if (converted.network.ceiling === "allowlist" && before.ceiling !== "allowlist")
435
- log?.warn("permission configuration conversion: the platform's old Full access off now keeps every device on the allowlist network (devicesNetwork ceiling allowlist); a super admin reopens it in the admin console settings (devicesNetwork.ceiling open)", { key: DEVICES_NETWORK_SETTING });
436
- }
437
- const orgs = await db
438
- .selectFrom("orgs")
439
- .select(["id", "settings"])
440
- .where(sql `settings ?| ${sql.val([...LEGACY_ORG_KEYS])}::text[]`)
441
- .orderBy("id")
442
- .forNoKeyUpdate()
443
- .execute();
444
- for (const org of orgs) {
445
- const stored = asObject(org.settings);
446
- for (const k of ["autoMode", "fullAccess"])
447
- if (k in stored && !Permission.safeParse(stored[k]).success)
448
- log?.warn(`org settings: stored ${k} is invalid; it converts to outsideSandbox off`, {
449
- orgId: org.id,
450
- });
451
- const { outsideSandbox, deviceNetwork } = orgDeviceSandboxOf(stored);
452
- const { autoMode: _a, fullAccess: _f, ...withoutPermission } = stored;
453
- // the network without the old permission: what an old off narrowed, for the warning
454
- const was = orgDeviceSandboxOf(withoutPermission).deviceNetwork;
455
- const { cloudNetwork: _c, outsideSandbox: _o, deviceNetwork: _d, ...rest } = withoutPermission;
456
- await db
457
- .updateTable("orgs")
458
- .set({
459
- settings: JSON.stringify({
460
- ...rest,
461
- ...(outsideSandbox !== undefined && { outsideSandbox }),
462
- ...(deviceNetwork !== undefined && { deviceNetwork }),
463
- }),
464
- })
465
- .where("id", "=", org.id)
466
- .execute();
467
- if (deviceNetwork?.ceiling === "allowlist" && was?.ceiling !== "allowlist")
468
- log?.warn(`permission configuration conversion: org ${org.id}'s old Full access off now keeps its devices on the allowlist network (deviceNetwork ceiling allowlist); an org admin reopens it in the organization settings (deviceNetwork.ceiling open)`, { orgId: org.id });
469
- }
163
+ return OrgDeviceSandboxStoredSchema.parse(asObject(raw));
470
164
  }
@@ -2,15 +2,9 @@ import type { Job, Queue } from "bullmq";
2
2
  import { LockService } from "../infra/lock/lock.service.js";
3
3
  import type { OutboxService } from "../infra/outbox/outbox.service.js";
4
4
  import type { KernelLogger } from "../log.js";
5
- import type { CloudPermissionSnapshots } from "./cloud-permission-snapshot.js";
6
5
  import { SandboxService } from "./sandbox.service.js";
7
6
  /** The idle suspension sweep (every minute, once per tick across replicas). */
8
7
  export declare const SANDBOX_SUSPEND_JOB = "sandbox-suspend-idle";
9
- /**
10
- * The lifecycle reconcile of cloud devices carrying the reconcile marker through their provider's
11
- * `update` (permission activation B-12; every minute, once per tick across replicas).
12
- */
13
- export declare const SANDBOX_RECONCILE_JOB = "sandbox-reconcile-limits";
14
8
  /** The inactivity destruction sweep (hourly, once per tick across replicas). */
15
9
  export declare const SANDBOX_DESTROY_JOB = "sandbox-destroy-inactive";
16
10
  /**
@@ -61,9 +55,7 @@ export declare class SandboxJobs {
61
55
  * The worker side of {@link SANDBOX_RESET_FILES_JOB}: `resetFileSystem` under the exclusive lease;
62
56
  * a failure fails the job (retried).
63
57
  */
64
- export declare function runSandboxResetFiles(sandbox: Pick<SandboxService, "resetFileSystem">, job: Pick<Job, "data">,
65
- /** B1: a reset establishes the device's exact limits; clears its reconciliation marker. */
66
- snapshots?: Pick<CloudPermissionSnapshots, "reconcileDevice">): Promise<void>;
58
+ export declare function runSandboxResetFiles(sandbox: Pick<SandboxService, "resetFileSystem">, job: Pick<Job, "data">): Promise<void>;
67
59
  /**
68
60
  * The worker side of {@link SANDBOX_DESTROY_FOR_JOB}: `destroyDevice` one by one; a failure is
69
61
  * warned and fails the job (the whole batch is retried) after the others were destroyed.
@@ -72,9 +64,7 @@ export declare function runSandboxDestroyFor(sandbox: Pick<SandboxService, "dest
72
64
  /**
73
65
  * The sandbox sweeps (exactly once per tick across replicas): every minute the idle and overdue
74
66
  * running instances are suspended, every hour the inactive instances are destroyed (files kept)
75
- * and deleted devices, or those of deleted orgs, are destroyed with their files. Every minute,
76
- * too, cloud devices whose limits must be established again get them through their provider's
77
- * `update` when it has one (B-12). All do nothing without a sandbox provider. They replace the
67
+ * and deleted devices, or those of deleted orgs, are destroyed with their files. They replace the
78
68
  * maintenance schedulers `sandbox-suspend-idle-every-minute` and `sandbox-destroy-inactive-hourly`
79
69
  * (retired at worker start).
80
70
  */
@@ -82,8 +72,7 @@ export declare class SandboxSweepJobs {
82
72
  private readonly sandbox;
83
73
  readonly lockService: LockService;
84
74
  readonly log: KernelLogger;
85
- constructor(sandbox: Pick<SandboxService, "suspendIdle" | "destroyInactive" | "reconcileMarked">, lockService: LockService, log: KernelLogger);
75
+ constructor(sandbox: Pick<SandboxService, "suspendIdle" | "destroyInactive">, lockService: LockService, log: KernelLogger);
86
76
  suspendIdle(): Promise<void>;
87
- reconcileLimits(): Promise<void>;
88
77
  destroyInactive(): Promise<void>;
89
78
  }