@capybara-hq/kernel 0.1.0-rc.121 → 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.
- package/dist/background/finish.d.ts +5 -1
- package/dist/background/finish.js +29 -18
- package/dist/background/launch.d.ts +0 -5
- package/dist/background/launch.js +1 -6
- package/dist/background/managed.js +1 -4
- package/dist/background/poll.job.d.ts +3 -25
- package/dist/background/poll.job.js +20 -112
- package/dist/background/render.d.ts +2 -8
- package/dist/background/render.js +3 -17
- package/dist/background/stop.d.ts +15 -16
- package/dist/background/stop.js +39 -76
- package/dist/background/store.d.ts +17 -45
- package/dist/background/store.js +60 -94
- package/dist/background/tasks.service.d.ts +2 -5
- package/dist/background/tasks.service.js +9 -20
- package/dist/background/wake.js +3 -2
- package/dist/catalog/admin-catalog.controller.d.ts +2 -18
- package/dist/catalog/admin-catalog.controller.js +2 -28
- package/dist/catalog/catalog-content.d.ts +1 -5
- package/dist/catalog/catalog-items.d.ts +2 -6
- package/dist/catalog/catalog-items.js +5 -26
- package/dist/catalog/catalog-scope.service.d.ts +1 -121
- package/dist/catalog/catalog-scope.service.js +12 -552
- package/dist/catalog/catalog.service.d.ts +4 -15
- package/dist/catalog/catalog.service.js +7 -35
- package/dist/catalog/job-ids.d.ts +0 -18
- package/dist/catalog/job-ids.js +0 -20
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-catalog.service.js +6 -20
- package/dist/catalog/org-plugin-uploads.controller.d.ts +4 -19
- package/dist/catalog/org-plugin-uploads.controller.js +6 -34
- package/dist/catalog/org-plugin-uploads.d.ts +3 -10
- package/dist/catalog/org-plugin-uploads.js +4 -18
- package/dist/catalog/org-plugin-uploads.schemas.js +0 -1
- package/dist/catalog/owned-items.d.ts +6 -11
- package/dist/catalog/owned-items.js +10 -20
- package/dist/catalog/ownership.d.ts +3 -29
- package/dist/catalog/ownership.js +4 -54
- package/dist/catalog/platform-components.d.ts +5 -11
- package/dist/catalog/platform-components.js +8 -15
- package/dist/catalog/plugin-import.d.ts +3 -42
- package/dist/catalog/plugin-import.js +26 -195
- package/dist/catalog/plugin-install.js +1 -6
- package/dist/catalog/plugin-package.d.ts +1 -0
- package/dist/catalog/plugin-package.js +5 -0
- package/dist/catalog/plugin-upgrade.d.ts +3 -26
- package/dist/catalog/plugin-upgrade.js +20 -103
- package/dist/catalog/request-rules.js +4 -6
- package/dist/catalog/scope-sync.js +2 -4
- package/dist/catalog/scope.d.ts +2 -5
- package/dist/channels/jobs.d.ts +3 -3
- package/dist/channels/jobs.js +4 -3
- package/dist/channels/outbound.d.ts +1 -0
- package/dist/channels/outbound.js +32 -8
- package/dist/config/load.d.ts +0 -25
- package/dist/config/load.js +0 -57
- package/dist/config/schema.js +2 -3
- package/dist/conversations/attachments.service.js +3 -5
- package/dist/conversations/conversations.service.d.ts +3 -3
- package/dist/conversations/conversations.service.js +3 -3
- package/dist/conversations/job-org.d.ts +3 -0
- package/dist/conversations/job-org.js +11 -0
- package/dist/conversations/prompt-suggestions.d.ts +2 -7
- package/dist/conversations/prompt-suggestions.js +29 -27
- package/dist/conversations/titles.d.ts +3 -4
- package/dist/conversations/titles.js +19 -30
- package/dist/db/kernel-schema.d.ts +6 -16
- package/dist/db/pool.js +7 -2
- package/dist/devices/devices.controller.d.ts +0 -5
- package/dist/devices/devices.controller.js +2 -20
- package/dist/devices/devices.service.d.ts +1 -17
- package/dist/devices/devices.service.js +0 -22
- package/dist/errors.d.ts +1 -5
- package/dist/errors.js +1 -5
- package/dist/evals/judge.d.ts +3 -0
- package/dist/evals/judge.js +1 -1
- package/dist/evals/run-replay.d.ts +1 -1
- package/dist/evals/run-replay.js +26 -29
- package/dist/evals/step-replay.d.ts +3 -1
- package/dist/evals/step-replay.js +10 -1
- package/dist/evals/worker.d.ts +3 -1
- package/dist/evals/worker.js +53 -21
- package/dist/extensions/deployment-config-store.js +18 -14
- package/dist/extensions/effective-config.d.ts +1 -5
- package/dist/extensions/effective-config.js +1 -5
- package/dist/extensions/hooks.d.ts +3 -1
- package/dist/extensions/hooks.js +7 -2
- package/dist/extensions/installs.d.ts +2 -14
- package/dist/extensions/installs.js +10 -32
- package/dist/extensions/org-config.d.ts +3 -4
- package/dist/extensions/org-config.js +3 -4
- package/dist/extensions/plugin-guides.d.ts +0 -1
- package/dist/extensions/plugin-guides.js +0 -1
- package/dist/extensions/plugin-icons.d.ts +0 -1
- package/dist/extensions/plugin-icons.js +0 -3
- package/dist/files/blob-sweep.job.d.ts +2 -11
- package/dist/files/blob-sweep.job.js +7 -21
- package/dist/files/hash-job.d.ts +5 -15
- package/dist/files/hash-job.js +14 -33
- package/dist/files/library-jobs.module.d.ts +1 -6
- package/dist/files/library-jobs.module.js +3 -9
- package/dist/identity/api-tokens.js +54 -40
- package/dist/identity/auth.guard.js +2 -2
- package/dist/identity/sessions.js +7 -3
- package/dist/identity/settings.js +5 -21
- package/dist/inbox/inbox.service.d.ts +2 -3
- package/dist/inbox/org-notices.d.ts +0 -14
- package/dist/inbox/platform-inbox.service.d.ts +1 -8
- package/dist/inbox/platform-inbox.service.js +2 -6
- package/dist/inbox/platform-notices.d.ts +3 -3
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -3
- package/dist/infra/database/database.module.js +2 -1
- package/dist/infra/database/org-scope.d.ts +5 -3
- package/dist/infra/database/org-scope.js +7 -1
- package/dist/infra/database/scoped-dialect.d.ts +3 -1
- package/dist/infra/database/scoped-dialect.js +17 -5
- package/dist/infra/events/kernel-events.d.ts +2 -0
- package/dist/infra/outbox/outbox.service.d.ts +2 -0
- package/dist/infra/outbox/outbox.service.js +10 -0
- package/dist/infra/outbox/registry.d.ts +0 -41
- package/dist/infra/outbox/registry.js +0 -37
- package/dist/models/embeddings.d.ts +0 -5
- package/dist/models/embeddings.js +28 -35
- package/dist/models/images.d.ts +3 -8
- package/dist/models/images.js +19 -37
- package/dist/models/purposes.d.ts +7 -2
- package/dist/models/purposes.js +16 -3
- package/dist/orgs/device-network-setting.d.ts +0 -44
- package/dist/orgs/device-network-setting.js +0 -83
- package/dist/orgs/invitations.service.js +34 -30
- package/dist/orgs/offboarding.d.ts +2 -2
- package/dist/orgs/offboarding.js +2 -2
- package/dist/orgs/orgs.service.d.ts +1 -1
- package/dist/orgs/orgs.service.js +19 -15
- package/dist/orgs/settings.service.d.ts +19 -14
- package/dist/orgs/settings.service.js +12 -37
- package/dist/platform/exclusions.js +0 -11
- package/dist/platform/ops/catalog-admin.ops.js +0 -8
- package/dist/platform/ops/devices.ops.js +0 -28
- package/dist/platform/ops/extensions-admin.ops.js +3 -3
- package/dist/platform/ops/inbox.ops.js +5 -22
- package/dist/platform/ops/org-plugins.ops.d.ts +1 -3
- package/dist/platform/ops/org-plugins.ops.js +11 -67
- package/dist/roles/worker.module.js +0 -9
- package/dist/runtime/hook-calls.d.ts +13 -6
- package/dist/runtime/hook-calls.js +26 -4
- package/dist/runtime/maintenance.d.ts +3 -12
- package/dist/runtime/maintenance.js +25 -55
- package/dist/runtime/model-call.d.ts +4 -2
- package/dist/runtime/model-call.js +59 -58
- package/dist/runtime/providers.d.ts +27 -1
- package/dist/runtime/providers.js +57 -0
- package/dist/runtime/run-jobs.d.ts +1 -1
- package/dist/runtime/run-processors.d.ts +3 -9
- package/dist/runtime/run-worker.d.ts +2 -0
- package/dist/runtime/run-worker.js +23 -8
- package/dist/runtime/subagents/deliveries.js +6 -1
- package/dist/runtime/subagents/dispatch.d.ts +3 -3
- package/dist/runtime/write-base.service.d.ts +2 -3
- package/dist/runtime/write-base.service.js +3 -5
- package/dist/sandbox/device-sandbox-settings.d.ts +38 -92
- package/dist/sandbox/device-sandbox-settings.js +19 -325
- package/dist/sandbox/jobs.d.ts +3 -14
- package/dist/sandbox/jobs.js +2 -20
- package/dist/sandbox/modes.d.ts +5 -45
- package/dist/sandbox/modes.js +3 -60
- package/dist/sandbox/operation-authority.js +0 -11
- package/dist/sandbox/operation-intents.d.ts +32 -9
- package/dist/sandbox/operation-intents.js +241 -32
- package/dist/sandbox/operation-intents.module.js +2 -1
- package/dist/sandbox/operation-reconcile.job.d.ts +9 -11
- package/dist/sandbox/operation-reconcile.job.js +119 -33
- package/dist/sandbox/operation-revoke.d.ts +20 -0
- package/dist/sandbox/operation-revoke.js +3 -0
- package/dist/sandbox/permission-ceiling-writes.d.ts +1 -2
- package/dist/sandbox/permission-ceiling-writes.js +3 -6
- package/dist/sandbox/permission-config-publication.d.ts +1 -28
- package/dist/sandbox/permission-config-publication.js +14 -211
- package/dist/sandbox/permission-facts.d.ts +4 -15
- package/dist/sandbox/permission-facts.js +7 -29
- package/dist/sandbox/permission-instance-writes.d.ts +1 -4
- package/dist/sandbox/permission-instance-writes.js +1 -55
- package/dist/sandbox/providers.d.ts +1 -6
- package/dist/sandbox/providers.js +1 -15
- package/dist/sandbox/review/classifier.js +12 -13
- package/dist/sandbox/sandbox.module.js +3 -6
- package/dist/sandbox/sandbox.service.d.ts +17 -123
- package/dist/sandbox/sandbox.service.js +239 -998
- package/dist/shares/liveness.d.ts +1 -2
- package/dist/shares/liveness.js +1 -2
- package/dist/shares/shares.module.d.ts +1 -2
- package/dist/shares/shares.module.js +2 -5
- package/dist/shares/shares.service.js +1 -2
- package/dist/tools/builtins/image/generate.js +7 -15
- package/dist/tools/builtins/sandbox/common.d.ts +0 -2
- package/dist/tools/builtins/sandbox/common.js +1 -27
- package/dist/tools/builtins/sandbox/task-list.js +10 -10
- package/dist/tools/builtins/sandbox/task-output.d.ts +3 -10
- package/dist/tools/builtins/sandbox/task-output.js +13 -83
- package/dist/tools/builtins/sandbox/task-stop.js +18 -22
- package/dist/tools/builtins/vision/read-image.js +9 -10
- package/dist/tools/builtins/web/extract.js +9 -10
- package/package.json +3 -3
- package/src/migrations/0206_retire_org_extension_uploads.sql +125 -0
- package/src/migrations/0207_confirm_device_instance_destruction.sql +25 -0
- package/src/migrations/0208_convert_stored_permission_settings.sql +189 -0
- package/dist/background/retire-legacy-tasks.job.d.ts +0 -57
- package/dist/background/retire-legacy-tasks.job.js +0 -149
- package/dist/catalog/owned-plugin-cleanup.d.ts +0 -47
- package/dist/catalog/owned-plugin-cleanup.js +0 -140
- package/dist/config/permission-migration.d.ts +0 -34
- package/dist/config/permission-migration.js +0 -115
- package/dist/devices/legacy-cleanup.job.d.ts +0 -34
- package/dist/devices/legacy-cleanup.job.js +0 -147
- package/dist/files/library-backfill.d.ts +0 -63
- package/dist/files/library-backfill.js +0 -143
- package/dist/infra/cli/permission-cutover.d.ts +0 -59
- package/dist/infra/cli/permission-cutover.js +0 -107
- package/dist/sandbox/cloud-permission-snapshot.d.ts +0 -159
- package/dist/sandbox/cloud-permission-snapshot.js +0 -430
- package/dist/sandbox/cloud-permission-snapshot.module.d.ts +0 -8
- package/dist/sandbox/cloud-permission-snapshot.module.js +0 -34
- package/dist/sandbox/legacy-retirement.d.ts +0 -284
- package/dist/sandbox/legacy-retirement.js +0 -1165
- package/dist/sandbox/legacy-retirement.module.d.ts +0 -8
- package/dist/sandbox/legacy-retirement.module.js +0 -25
- package/dist/shares/share-objects.d.ts +0 -47
- 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
|
-
|
|
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
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
export
|
|
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 {
|
|
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
|
-
/**
|
|
188
|
-
async function
|
|
189
|
-
|
|
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
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
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
|
|
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
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
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
|
-
|
|
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
|
}
|
package/dist/sandbox/jobs.d.ts
CHANGED
|
@@ -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.
|
|
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"
|
|
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
|
}
|