@qlever-llc/trellis 0.8.4 → 0.9.0-rc.10
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/README.md +1 -1
- package/bin/trellis-generate.js +0 -0
- package/esm/auth/browser/login.d.ts.map +1 -1
- package/esm/auth/browser/login.js +46 -3
- package/esm/auth/browser/portal.d.ts.map +1 -1
- package/esm/auth/browser/portal.js +5 -1
- package/esm/auth/browser/session.d.ts +18 -7
- package/esm/auth/browser/session.d.ts.map +1 -1
- package/esm/auth/browser/session.js +47 -11
- package/esm/auth/browser/storage.d.ts +6 -1
- package/esm/auth/browser/storage.d.ts.map +1 -1
- package/esm/auth/browser/storage.js +15 -3
- package/esm/auth/browser.d.ts +2 -2
- package/esm/auth/browser.d.ts.map +1 -1
- package/esm/auth/browser.js +1 -1
- package/esm/auth/device_activation.d.ts +36 -33
- package/esm/auth/device_activation.d.ts.map +1 -1
- package/esm/auth/device_activation.js +26 -22
- package/esm/auth/mod.d.ts +4 -4
- package/esm/auth/mod.d.ts.map +1 -1
- package/esm/auth/mod.js +2 -2
- package/esm/auth/proof.d.ts +3 -1
- package/esm/auth/proof.d.ts.map +1 -1
- package/esm/auth/proof.js +21 -15
- package/esm/auth/protocol.d.ts +2457 -941
- package/esm/auth/protocol.d.ts.map +1 -1
- package/esm/auth/protocol.js +747 -375
- package/esm/auth/schemas.d.ts +25 -4
- package/esm/auth/schemas.d.ts.map +1 -1
- package/esm/auth/schemas.js +14 -4
- package/esm/auth/session_auth.d.ts +1 -1
- package/esm/auth/session_auth.d.ts.map +1 -1
- package/esm/auth/session_auth.js +7 -1
- package/esm/client_connect.d.ts +2 -0
- package/esm/client_connect.d.ts.map +1 -1
- package/esm/client_connect.js +76 -15
- package/esm/contract.d.ts +3 -0
- package/esm/contract.d.ts.map +1 -1
- package/esm/contract_support/mod.d.ts +422 -43
- package/esm/contract_support/mod.d.ts.map +1 -1
- package/esm/contract_support/mod.js +734 -33
- package/esm/contract_support/protocol.d.ts +20 -5
- package/esm/contract_support/protocol.d.ts.map +1 -1
- package/esm/contract_support/protocol.js +18 -10
- package/esm/contract_support/runtime.d.ts +11 -0
- package/esm/contract_support/runtime.d.ts.map +1 -1
- package/esm/contract_support/schema_pointers.d.ts.map +1 -1
- package/esm/contract_support/schema_pointers.js +32 -14
- package/esm/device.d.ts +2 -0
- package/esm/device.d.ts.map +1 -1
- package/esm/device.js +3 -0
- package/esm/errors/AuthError.d.ts +2 -1
- package/esm/errors/AuthError.d.ts.map +1 -1
- package/esm/errors/AuthError.js +8 -3
- package/esm/errors/index.d.ts +4 -4
- package/esm/errors/index.d.ts.map +1 -1
- package/esm/errors/index.js +1 -0
- package/esm/generated-sdk/auth/api.d.ts +27 -9
- package/esm/generated-sdk/auth/api.d.ts.map +1 -1
- package/esm/generated-sdk/auth/api.js +16 -590
- package/esm/generated-sdk/auth/client.d.ts +91 -85
- package/esm/generated-sdk/auth/client.d.ts.map +1 -1
- package/esm/generated-sdk/auth/contract.d.ts +1 -1
- package/esm/generated-sdk/auth/contract.d.ts.map +1 -1
- package/esm/generated-sdk/auth/contract.js +4 -2
- package/esm/generated-sdk/auth/mod.d.ts +1 -0
- package/esm/generated-sdk/auth/mod.d.ts.map +1 -1
- package/esm/generated-sdk/auth/owned_api.d.ts +3 -0
- package/esm/generated-sdk/auth/owned_api.d.ts.map +1 -0
- package/esm/generated-sdk/auth/owned_api.js +594 -0
- package/esm/generated-sdk/auth/schemas.d.ts +9959 -5160
- package/esm/generated-sdk/auth/schemas.d.ts.map +1 -1
- package/esm/generated-sdk/auth/schemas.js +136 -137
- package/esm/generated-sdk/auth/types.d.ts +2418 -1557
- package/esm/generated-sdk/auth/types.d.ts.map +1 -1
- package/esm/generated-sdk/auth/types.js +1 -1
- package/esm/generated-sdk/health/api.d.ts +24 -9
- package/esm/generated-sdk/health/api.d.ts.map +1 -1
- package/esm/generated-sdk/health/api.js +12 -20
- package/esm/generated-sdk/health/client.d.ts +2 -1
- package/esm/generated-sdk/health/client.d.ts.map +1 -1
- package/esm/generated-sdk/health/contract.d.ts.map +1 -1
- package/esm/generated-sdk/health/contract.js +2 -0
- package/esm/generated-sdk/health/owned_api.d.ts +3 -0
- package/esm/generated-sdk/health/owned_api.d.ts.map +1 -0
- package/esm/generated-sdk/health/owned_api.js +16 -0
- package/esm/generated-sdk/health/types.d.ts +2 -0
- package/esm/generated-sdk/health/types.d.ts.map +1 -1
- package/esm/generated-sdk/jobs/api.d.ts +33 -9
- package/esm/generated-sdk/jobs/api.d.ts.map +1 -1
- package/esm/generated-sdk/jobs/api.js +22 -87
- package/esm/generated-sdk/jobs/client.d.ts +9 -2
- package/esm/generated-sdk/jobs/client.d.ts.map +1 -1
- package/esm/generated-sdk/jobs/contract.d.ts +1 -1
- package/esm/generated-sdk/jobs/contract.d.ts.map +1 -1
- package/esm/generated-sdk/jobs/contract.js +4 -2
- package/esm/generated-sdk/jobs/owned_api.d.ts +3 -0
- package/esm/generated-sdk/jobs/owned_api.d.ts.map +1 -0
- package/esm/generated-sdk/jobs/owned_api.js +118 -0
- package/esm/generated-sdk/jobs/schemas.d.ts +336 -123
- package/esm/generated-sdk/jobs/schemas.d.ts.map +1 -1
- package/esm/generated-sdk/jobs/schemas.js +17 -15
- package/esm/generated-sdk/jobs/types.d.ts +144 -34
- package/esm/generated-sdk/jobs/types.d.ts.map +1 -1
- package/esm/generated-sdk/jobs/types.js +36 -1
- package/esm/generated-sdk/state/api.d.ts +27 -9
- package/esm/generated-sdk/state/api.d.ts.map +1 -1
- package/esm/generated-sdk/state/api.js +16 -71
- package/esm/generated-sdk/state/client.d.ts +4 -2
- package/esm/generated-sdk/state/client.d.ts.map +1 -1
- package/esm/generated-sdk/state/contract.d.ts +1 -1
- package/esm/generated-sdk/state/contract.d.ts.map +1 -1
- package/esm/generated-sdk/state/contract.js +4 -2
- package/esm/generated-sdk/state/owned_api.d.ts +3 -0
- package/esm/generated-sdk/state/owned_api.d.ts.map +1 -0
- package/esm/generated-sdk/state/owned_api.js +66 -0
- package/esm/generated-sdk/state/schemas.d.ts +264 -284
- package/esm/generated-sdk/state/schemas.d.ts.map +1 -1
- package/esm/generated-sdk/state/schemas.js +6 -6
- package/esm/generated-sdk/state/types.d.ts +24 -23
- package/esm/generated-sdk/state/types.d.ts.map +1 -1
- package/esm/generated-sdk/state/types.js +1 -1
- package/esm/generated-sdk/trellis-core/api.d.ts +27 -9
- package/esm/generated-sdk/trellis-core/api.d.ts.map +1 -1
- package/esm/generated-sdk/trellis-core/api.js +16 -39
- package/esm/generated-sdk/trellis-core/client.d.ts +5 -2
- package/esm/generated-sdk/trellis-core/client.d.ts.map +1 -1
- package/esm/generated-sdk/trellis-core/contract.d.ts +1 -1
- package/esm/generated-sdk/trellis-core/contract.d.ts.map +1 -1
- package/esm/generated-sdk/trellis-core/contract.js +4 -2
- package/esm/generated-sdk/trellis-core/owned_api.d.ts +3 -0
- package/esm/generated-sdk/trellis-core/owned_api.d.ts.map +1 -0
- package/esm/generated-sdk/trellis-core/owned_api.js +42 -0
- package/esm/generated-sdk/trellis-core/schemas.d.ts +259 -11
- package/esm/generated-sdk/trellis-core/schemas.d.ts.map +1 -1
- package/esm/generated-sdk/trellis-core/schemas.js +5 -3
- package/esm/generated-sdk/trellis-core/types.d.ts +56 -1
- package/esm/generated-sdk/trellis-core/types.d.ts.map +1 -1
- package/esm/generated-sdk/trellis-core/types.js +1 -1
- package/esm/helpers.d.ts.map +1 -1
- package/esm/index.d.ts +4 -3
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -0
- package/esm/jobs.d.ts +10 -1
- package/esm/jobs.d.ts.map +1 -1
- package/esm/jobs.js +16 -1
- package/esm/kv.d.ts.map +1 -1
- package/esm/kv.js +10 -4
- package/esm/models/auth/rpc/Logout.d.ts +4 -4
- package/esm/models/auth/rpc/Logout.d.ts.map +1 -1
- package/esm/models/auth/rpc/Logout.js +2 -2
- package/esm/models/trellis/Page.d.ts +2 -0
- package/esm/models/trellis/Page.d.ts.map +1 -0
- package/esm/models/trellis/Page.js +1 -0
- package/esm/models/trellis/State.d.ts +1 -0
- package/esm/models/trellis/State.d.ts.map +1 -1
- package/esm/models/trellis/State.js +1 -0
- package/esm/models/trellis/rpc/StateList.d.ts +9 -12
- package/esm/models/trellis/rpc/StateList.d.ts.map +1 -1
- package/esm/models/trellis/rpc/StateList.js +16 -18
- package/esm/npm/src/auth/browser/login.d.ts.map +1 -1
- package/esm/npm/src/auth/browser/login.js +46 -3
- package/esm/npm/src/auth/browser/portal.d.ts.map +1 -1
- package/esm/npm/src/auth/browser/portal.js +5 -1
- package/esm/npm/src/auth/browser/session.d.ts +18 -7
- package/esm/npm/src/auth/browser/session.d.ts.map +1 -1
- package/esm/npm/src/auth/browser/session.js +47 -11
- package/esm/npm/src/auth/browser/storage.d.ts +6 -1
- package/esm/npm/src/auth/browser/storage.d.ts.map +1 -1
- package/esm/npm/src/auth/browser/storage.js +15 -3
- package/esm/npm/src/auth/browser.d.ts +2 -2
- package/esm/npm/src/auth/browser.d.ts.map +1 -1
- package/esm/npm/src/auth/browser.js +1 -1
- package/esm/npm/src/auth/device_activation.d.ts +36 -33
- package/esm/npm/src/auth/device_activation.d.ts.map +1 -1
- package/esm/npm/src/auth/device_activation.js +26 -22
- package/esm/npm/src/auth/mod.d.ts +4 -4
- package/esm/npm/src/auth/mod.d.ts.map +1 -1
- package/esm/npm/src/auth/mod.js +2 -2
- package/esm/npm/src/auth/proof.d.ts +3 -1
- package/esm/npm/src/auth/proof.d.ts.map +1 -1
- package/esm/npm/src/auth/proof.js +21 -15
- package/esm/npm/src/auth/protocol.d.ts +2457 -941
- package/esm/npm/src/auth/protocol.d.ts.map +1 -1
- package/esm/npm/src/auth/protocol.js +747 -375
- package/esm/npm/src/auth/schemas.d.ts +25 -4
- package/esm/npm/src/auth/schemas.d.ts.map +1 -1
- package/esm/npm/src/auth/schemas.js +14 -4
- package/esm/npm/src/auth/session_auth.d.ts +1 -1
- package/esm/npm/src/auth/session_auth.d.ts.map +1 -1
- package/esm/npm/src/auth/session_auth.js +7 -1
- package/esm/npm/src/client_connect.d.ts +2 -0
- package/esm/npm/src/client_connect.d.ts.map +1 -1
- package/esm/npm/src/client_connect.js +76 -15
- package/esm/npm/src/contract.d.ts +3 -0
- package/esm/npm/src/contract.d.ts.map +1 -1
- package/esm/npm/src/contract_support/mod.d.ts +422 -43
- package/esm/npm/src/contract_support/mod.d.ts.map +1 -1
- package/esm/npm/src/contract_support/mod.js +734 -33
- package/esm/npm/src/contract_support/protocol.d.ts +20 -5
- package/esm/npm/src/contract_support/protocol.d.ts.map +1 -1
- package/esm/npm/src/contract_support/protocol.js +18 -10
- package/esm/npm/src/contract_support/runtime.d.ts +11 -0
- package/esm/npm/src/contract_support/runtime.d.ts.map +1 -1
- package/esm/npm/src/contract_support/schema_pointers.d.ts.map +1 -1
- package/esm/npm/src/contract_support/schema_pointers.js +32 -14
- package/esm/npm/src/device/deno.d.ts.map +1 -1
- package/esm/npm/src/device/deno.js +6 -0
- package/esm/npm/src/device.d.ts +2 -0
- package/esm/npm/src/device.d.ts.map +1 -1
- package/esm/npm/src/device.js +3 -0
- package/esm/npm/src/errors/AuthError.d.ts +2 -1
- package/esm/npm/src/errors/AuthError.d.ts.map +1 -1
- package/esm/npm/src/errors/AuthError.js +8 -3
- package/esm/npm/src/errors/index.d.ts +4 -4
- package/esm/npm/src/errors/index.d.ts.map +1 -1
- package/esm/npm/src/errors/index.js +1 -0
- package/esm/npm/src/generate.js +39 -26
- package/esm/npm/src/helpers.d.ts.map +1 -1
- package/esm/npm/src/index.d.ts +4 -3
- package/esm/npm/src/index.d.ts.map +1 -1
- package/esm/npm/src/index.js +1 -0
- package/esm/npm/src/jobs.d.ts +10 -1
- package/esm/npm/src/jobs.d.ts.map +1 -1
- package/esm/npm/src/jobs.js +16 -1
- package/esm/npm/src/kv.d.ts.map +1 -1
- package/esm/npm/src/kv.js +10 -4
- package/esm/npm/src/models/auth/rpc/Logout.d.ts +4 -4
- package/esm/npm/src/models/auth/rpc/Logout.d.ts.map +1 -1
- package/esm/npm/src/models/auth/rpc/Logout.js +2 -2
- package/esm/npm/src/models/trellis/Page.d.ts +2 -0
- package/esm/npm/src/models/trellis/Page.d.ts.map +1 -0
- package/esm/npm/src/models/trellis/Page.js +1 -0
- package/esm/npm/src/models/trellis/State.d.ts +1 -0
- package/esm/npm/src/models/trellis/State.d.ts.map +1 -1
- package/esm/npm/src/models/trellis/State.js +1 -0
- package/esm/npm/src/models/trellis/rpc/StateList.d.ts +9 -12
- package/esm/npm/src/models/trellis/rpc/StateList.d.ts.map +1 -1
- package/esm/npm/src/models/trellis/rpc/StateList.js +16 -18
- package/esm/npm/src/operations.d.ts +16 -7
- package/esm/npm/src/operations.d.ts.map +1 -1
- package/esm/npm/src/operations.js +84 -19
- package/esm/npm/src/runtime_transport.d.ts +2 -0
- package/esm/npm/src/runtime_transport.d.ts.map +1 -1
- package/esm/npm/src/runtime_transport.js +1 -0
- package/esm/npm/src/server/internal_jobs/active-job.d.ts +2 -1
- package/esm/npm/src/server/internal_jobs/active-job.d.ts.map +1 -1
- package/esm/npm/src/server/internal_jobs/active-job.js +3 -0
- package/esm/npm/src/server/internal_jobs/job-manager.d.ts +4 -1
- package/esm/npm/src/server/internal_jobs/job-manager.d.ts.map +1 -1
- package/esm/npm/src/server/internal_jobs/job-manager.js +61 -1
- package/esm/npm/src/server/internal_jobs/projection.js +1 -0
- package/esm/npm/src/server/internal_jobs/runtime-worker.d.ts +13 -1
- package/esm/npm/src/server/internal_jobs/runtime-worker.d.ts.map +1 -1
- package/esm/npm/src/server/internal_jobs/runtime-worker.js +73 -13
- package/esm/npm/src/server/internal_jobs/types.d.ts +19 -0
- package/esm/npm/src/server/internal_jobs/types.d.ts.map +1 -1
- package/esm/npm/src/server/internal_jobs/types.js +10 -0
- package/esm/npm/src/server/runtime.d.ts +1 -0
- package/esm/npm/src/server/runtime.d.ts.map +1 -1
- package/esm/npm/src/server/service.d.ts +10 -1
- package/esm/npm/src/server/service.d.ts.map +1 -1
- package/esm/npm/src/server/service.js +210 -64
- package/esm/npm/src/server/transfer.d.ts.map +1 -1
- package/esm/npm/src/server/transfer.js +4 -0
- package/esm/npm/src/server.d.ts.map +1 -1
- package/esm/npm/src/server.js +337 -34
- package/esm/npm/src/store.d.ts +8 -1
- package/esm/npm/src/store.d.ts.map +1 -1
- package/esm/npm/src/store.js +46 -8
- package/esm/npm/src/transfer.d.ts +3 -0
- package/esm/npm/src/transfer.d.ts.map +1 -1
- package/esm/npm/src/transfer.js +20 -30
- package/esm/npm/src/trellis.d.ts +85 -22
- package/esm/npm/src/trellis.d.ts.map +1 -1
- package/esm/npm/src/trellis.js +525 -61
- package/esm/operations.d.ts +16 -7
- package/esm/operations.d.ts.map +1 -1
- package/esm/operations.js +84 -19
- package/esm/runtime_transport.d.ts +2 -0
- package/esm/runtime_transport.d.ts.map +1 -1
- package/esm/runtime_transport.js +1 -0
- package/esm/store.d.ts +8 -1
- package/esm/store.d.ts.map +1 -1
- package/esm/store.js +46 -8
- package/esm/transfer.d.ts +3 -0
- package/esm/transfer.d.ts.map +1 -1
- package/esm/transfer.js +20 -30
- package/esm/trellis.d.ts +85 -22
- package/esm/trellis.d.ts.map +1 -1
- package/esm/trellis.js +525 -61
- package/package.json +6 -3
- package/script/auth/browser/login.d.ts.map +1 -1
- package/script/auth/browser/login.js +46 -3
- package/script/auth/browser/portal.d.ts.map +1 -1
- package/script/auth/browser/portal.js +5 -1
- package/script/auth/browser/session.d.ts +18 -7
- package/script/auth/browser/session.d.ts.map +1 -1
- package/script/auth/browser/session.js +47 -11
- package/script/auth/browser/storage.d.ts +6 -1
- package/script/auth/browser/storage.d.ts.map +1 -1
- package/script/auth/browser/storage.js +15 -3
- package/script/auth/browser.d.ts +2 -2
- package/script/auth/browser.d.ts.map +1 -1
- package/script/auth/browser.js +2 -1
- package/script/auth/device_activation.d.ts +36 -33
- package/script/auth/device_activation.d.ts.map +1 -1
- package/script/auth/device_activation.js +25 -21
- package/script/auth/mod.d.ts +4 -4
- package/script/auth/mod.d.ts.map +1 -1
- package/script/auth/mod.js +132 -137
- package/script/auth/proof.d.ts +3 -1
- package/script/auth/proof.d.ts.map +1 -1
- package/script/auth/proof.js +21 -15
- package/script/auth/protocol.d.ts +2457 -941
- package/script/auth/protocol.d.ts.map +1 -1
- package/script/auth/protocol.js +749 -377
- package/script/auth/schemas.d.ts +25 -4
- package/script/auth/schemas.d.ts.map +1 -1
- package/script/auth/schemas.js +16 -5
- package/script/auth/session_auth.d.ts +1 -1
- package/script/auth/session_auth.d.ts.map +1 -1
- package/script/auth/session_auth.js +7 -1
- package/script/client_connect.d.ts +2 -0
- package/script/client_connect.d.ts.map +1 -1
- package/script/client_connect.js +76 -15
- package/script/contract.d.ts +3 -0
- package/script/contract.d.ts.map +1 -1
- package/script/contract_support/mod.d.ts +422 -43
- package/script/contract_support/mod.d.ts.map +1 -1
- package/script/contract_support/mod.js +757 -51
- package/script/contract_support/protocol.d.ts +20 -5
- package/script/contract_support/protocol.d.ts.map +1 -1
- package/script/contract_support/protocol.js +20 -11
- package/script/contract_support/runtime.d.ts +11 -0
- package/script/contract_support/runtime.d.ts.map +1 -1
- package/script/contract_support/schema_pointers.d.ts.map +1 -1
- package/script/contract_support/schema_pointers.js +32 -14
- package/script/device.d.ts +2 -0
- package/script/device.d.ts.map +1 -1
- package/script/device.js +3 -0
- package/script/errors/AuthError.d.ts +2 -1
- package/script/errors/AuthError.d.ts.map +1 -1
- package/script/errors/AuthError.js +8 -3
- package/script/errors/index.d.ts +4 -4
- package/script/errors/index.d.ts.map +1 -1
- package/script/errors/index.js +1 -0
- package/script/generated-sdk/auth/api.d.ts +27 -9
- package/script/generated-sdk/auth/api.d.ts.map +1 -1
- package/script/generated-sdk/auth/api.js +17 -591
- package/script/generated-sdk/auth/client.d.ts +91 -85
- package/script/generated-sdk/auth/client.d.ts.map +1 -1
- package/script/generated-sdk/auth/contract.d.ts +1 -1
- package/script/generated-sdk/auth/contract.d.ts.map +1 -1
- package/script/generated-sdk/auth/contract.js +4 -2
- package/script/generated-sdk/auth/mod.d.ts +1 -0
- package/script/generated-sdk/auth/mod.d.ts.map +1 -1
- package/script/generated-sdk/auth/owned_api.d.ts +3 -0
- package/script/generated-sdk/auth/owned_api.d.ts.map +1 -0
- package/script/generated-sdk/auth/owned_api.js +597 -0
- package/script/generated-sdk/auth/schemas.d.ts +9959 -5160
- package/script/generated-sdk/auth/schemas.d.ts.map +1 -1
- package/script/generated-sdk/auth/schemas.js +139 -140
- package/script/generated-sdk/auth/types.d.ts +2418 -1557
- package/script/generated-sdk/auth/types.d.ts.map +1 -1
- package/script/generated-sdk/auth/types.js +1 -1
- package/script/generated-sdk/health/api.d.ts +24 -9
- package/script/generated-sdk/health/api.d.ts.map +1 -1
- package/script/generated-sdk/health/api.js +13 -21
- package/script/generated-sdk/health/client.d.ts +2 -1
- package/script/generated-sdk/health/client.d.ts.map +1 -1
- package/script/generated-sdk/health/contract.d.ts.map +1 -1
- package/script/generated-sdk/health/contract.js +2 -0
- package/script/generated-sdk/health/owned_api.d.ts +3 -0
- package/script/generated-sdk/health/owned_api.d.ts.map +1 -0
- package/script/generated-sdk/health/owned_api.js +19 -0
- package/script/generated-sdk/health/types.d.ts +2 -0
- package/script/generated-sdk/health/types.d.ts.map +1 -1
- package/script/generated-sdk/jobs/api.d.ts +33 -9
- package/script/generated-sdk/jobs/api.d.ts.map +1 -1
- package/script/generated-sdk/jobs/api.js +23 -88
- package/script/generated-sdk/jobs/client.d.ts +9 -2
- package/script/generated-sdk/jobs/client.d.ts.map +1 -1
- package/script/generated-sdk/jobs/contract.d.ts +1 -1
- package/script/generated-sdk/jobs/contract.d.ts.map +1 -1
- package/script/generated-sdk/jobs/contract.js +4 -2
- package/script/generated-sdk/jobs/owned_api.d.ts +3 -0
- package/script/generated-sdk/jobs/owned_api.d.ts.map +1 -0
- package/script/generated-sdk/jobs/owned_api.js +154 -0
- package/script/generated-sdk/jobs/schemas.d.ts +336 -123
- package/script/generated-sdk/jobs/schemas.d.ts.map +1 -1
- package/script/generated-sdk/jobs/schemas.js +18 -16
- package/script/generated-sdk/jobs/types.d.ts +144 -34
- package/script/generated-sdk/jobs/types.d.ts.map +1 -1
- package/script/generated-sdk/jobs/types.js +38 -2
- package/script/generated-sdk/state/api.d.ts +27 -9
- package/script/generated-sdk/state/api.d.ts.map +1 -1
- package/script/generated-sdk/state/api.js +17 -72
- package/script/generated-sdk/state/client.d.ts +4 -2
- package/script/generated-sdk/state/client.d.ts.map +1 -1
- package/script/generated-sdk/state/contract.d.ts +1 -1
- package/script/generated-sdk/state/contract.d.ts.map +1 -1
- package/script/generated-sdk/state/contract.js +4 -2
- package/script/generated-sdk/state/owned_api.d.ts +3 -0
- package/script/generated-sdk/state/owned_api.d.ts.map +1 -0
- package/script/generated-sdk/state/owned_api.js +69 -0
- package/script/generated-sdk/state/schemas.d.ts +264 -284
- package/script/generated-sdk/state/schemas.d.ts.map +1 -1
- package/script/generated-sdk/state/schemas.js +6 -6
- package/script/generated-sdk/state/types.d.ts +24 -23
- package/script/generated-sdk/state/types.d.ts.map +1 -1
- package/script/generated-sdk/state/types.js +1 -1
- package/script/generated-sdk/trellis-core/api.d.ts +27 -9
- package/script/generated-sdk/trellis-core/api.d.ts.map +1 -1
- package/script/generated-sdk/trellis-core/api.js +17 -40
- package/script/generated-sdk/trellis-core/client.d.ts +5 -2
- package/script/generated-sdk/trellis-core/client.d.ts.map +1 -1
- package/script/generated-sdk/trellis-core/contract.d.ts +1 -1
- package/script/generated-sdk/trellis-core/contract.d.ts.map +1 -1
- package/script/generated-sdk/trellis-core/contract.js +4 -2
- package/script/generated-sdk/trellis-core/owned_api.d.ts +3 -0
- package/script/generated-sdk/trellis-core/owned_api.d.ts.map +1 -0
- package/script/generated-sdk/trellis-core/owned_api.js +45 -0
- package/script/generated-sdk/trellis-core/schemas.d.ts +259 -11
- package/script/generated-sdk/trellis-core/schemas.d.ts.map +1 -1
- package/script/generated-sdk/trellis-core/schemas.js +6 -4
- package/script/generated-sdk/trellis-core/types.d.ts +56 -1
- package/script/generated-sdk/trellis-core/types.d.ts.map +1 -1
- package/script/generated-sdk/trellis-core/types.js +1 -1
- package/script/helpers.d.ts.map +1 -1
- package/script/index.d.ts +4 -3
- package/script/index.d.ts.map +1 -1
- package/script/index.js +5 -2
- package/script/jobs.d.ts +10 -1
- package/script/jobs.d.ts.map +1 -1
- package/script/jobs.js +17 -2
- package/script/kv.d.ts.map +1 -1
- package/script/kv.js +10 -4
- package/script/models/auth/rpc/Logout.d.ts +4 -4
- package/script/models/auth/rpc/Logout.d.ts.map +1 -1
- package/script/models/auth/rpc/Logout.js +3 -3
- package/script/models/trellis/Page.d.ts +2 -0
- package/script/models/trellis/Page.d.ts.map +1 -0
- package/script/models/trellis/Page.js +6 -0
- package/script/models/trellis/State.d.ts +1 -0
- package/script/models/trellis/State.d.ts.map +1 -1
- package/script/models/trellis/State.js +1 -0
- package/script/models/trellis/rpc/StateList.d.ts +9 -12
- package/script/models/trellis/rpc/StateList.d.ts.map +1 -1
- package/script/models/trellis/rpc/StateList.js +16 -18
- package/script/npm/src/auth/browser/login.d.ts.map +1 -1
- package/script/npm/src/auth/browser/login.js +46 -3
- package/script/npm/src/auth/browser/portal.d.ts.map +1 -1
- package/script/npm/src/auth/browser/portal.js +5 -1
- package/script/npm/src/auth/browser/session.d.ts +18 -7
- package/script/npm/src/auth/browser/session.d.ts.map +1 -1
- package/script/npm/src/auth/browser/session.js +47 -11
- package/script/npm/src/auth/browser/storage.d.ts +6 -1
- package/script/npm/src/auth/browser/storage.d.ts.map +1 -1
- package/script/npm/src/auth/browser/storage.js +15 -3
- package/script/npm/src/auth/browser.d.ts +2 -2
- package/script/npm/src/auth/browser.d.ts.map +1 -1
- package/script/npm/src/auth/browser.js +2 -1
- package/script/npm/src/auth/device_activation.d.ts +36 -33
- package/script/npm/src/auth/device_activation.d.ts.map +1 -1
- package/script/npm/src/auth/device_activation.js +25 -21
- package/script/npm/src/auth/mod.d.ts +4 -4
- package/script/npm/src/auth/mod.d.ts.map +1 -1
- package/script/npm/src/auth/mod.js +132 -137
- package/script/npm/src/auth/proof.d.ts +3 -1
- package/script/npm/src/auth/proof.d.ts.map +1 -1
- package/script/npm/src/auth/proof.js +21 -15
- package/script/npm/src/auth/protocol.d.ts +2457 -941
- package/script/npm/src/auth/protocol.d.ts.map +1 -1
- package/script/npm/src/auth/protocol.js +749 -377
- package/script/npm/src/auth/schemas.d.ts +25 -4
- package/script/npm/src/auth/schemas.d.ts.map +1 -1
- package/script/npm/src/auth/schemas.js +16 -5
- package/script/npm/src/auth/session_auth.d.ts +1 -1
- package/script/npm/src/auth/session_auth.d.ts.map +1 -1
- package/script/npm/src/auth/session_auth.js +7 -1
- package/script/npm/src/client_connect.d.ts +2 -0
- package/script/npm/src/client_connect.d.ts.map +1 -1
- package/script/npm/src/client_connect.js +76 -15
- package/script/npm/src/contract.d.ts +3 -0
- package/script/npm/src/contract.d.ts.map +1 -1
- package/script/npm/src/contract_support/mod.d.ts +422 -43
- package/script/npm/src/contract_support/mod.d.ts.map +1 -1
- package/script/npm/src/contract_support/mod.js +757 -51
- package/script/npm/src/contract_support/protocol.d.ts +20 -5
- package/script/npm/src/contract_support/protocol.d.ts.map +1 -1
- package/script/npm/src/contract_support/protocol.js +20 -11
- package/script/npm/src/contract_support/runtime.d.ts +11 -0
- package/script/npm/src/contract_support/runtime.d.ts.map +1 -1
- package/script/npm/src/contract_support/schema_pointers.d.ts.map +1 -1
- package/script/npm/src/contract_support/schema_pointers.js +32 -14
- package/script/npm/src/device/deno.d.ts.map +1 -1
- package/script/npm/src/device/deno.js +6 -0
- package/script/npm/src/device.d.ts +2 -0
- package/script/npm/src/device.d.ts.map +1 -1
- package/script/npm/src/device.js +3 -0
- package/script/npm/src/errors/AuthError.d.ts +2 -1
- package/script/npm/src/errors/AuthError.d.ts.map +1 -1
- package/script/npm/src/errors/AuthError.js +8 -3
- package/script/npm/src/errors/index.d.ts +4 -4
- package/script/npm/src/errors/index.d.ts.map +1 -1
- package/script/npm/src/errors/index.js +1 -0
- package/script/npm/src/generate.js +39 -59
- package/script/npm/src/helpers.d.ts.map +1 -1
- package/script/npm/src/index.d.ts +4 -3
- package/script/npm/src/index.d.ts.map +1 -1
- package/script/npm/src/index.js +5 -2
- package/script/npm/src/jobs.d.ts +10 -1
- package/script/npm/src/jobs.d.ts.map +1 -1
- package/script/npm/src/jobs.js +17 -2
- package/script/npm/src/kv.d.ts.map +1 -1
- package/script/npm/src/kv.js +10 -4
- package/script/npm/src/models/auth/rpc/Logout.d.ts +4 -4
- package/script/npm/src/models/auth/rpc/Logout.d.ts.map +1 -1
- package/script/npm/src/models/auth/rpc/Logout.js +3 -3
- package/script/npm/src/models/trellis/Page.d.ts +2 -0
- package/script/npm/src/models/trellis/Page.d.ts.map +1 -0
- package/script/npm/src/models/trellis/Page.js +6 -0
- package/script/npm/src/models/trellis/State.d.ts +1 -0
- package/script/npm/src/models/trellis/State.d.ts.map +1 -1
- package/script/npm/src/models/trellis/State.js +1 -0
- package/script/npm/src/models/trellis/rpc/StateList.d.ts +9 -12
- package/script/npm/src/models/trellis/rpc/StateList.d.ts.map +1 -1
- package/script/npm/src/models/trellis/rpc/StateList.js +16 -18
- package/script/npm/src/operations.d.ts +16 -7
- package/script/npm/src/operations.d.ts.map +1 -1
- package/script/npm/src/operations.js +84 -19
- package/script/npm/src/runtime_transport.d.ts +2 -0
- package/script/npm/src/runtime_transport.d.ts.map +1 -1
- package/script/npm/src/runtime_transport.js +2 -1
- package/script/npm/src/server/internal_jobs/active-job.d.ts +2 -1
- package/script/npm/src/server/internal_jobs/active-job.d.ts.map +1 -1
- package/script/npm/src/server/internal_jobs/active-job.js +3 -0
- package/script/npm/src/server/internal_jobs/job-manager.d.ts +4 -1
- package/script/npm/src/server/internal_jobs/job-manager.d.ts.map +1 -1
- package/script/npm/src/server/internal_jobs/job-manager.js +61 -1
- package/script/npm/src/server/internal_jobs/projection.js +1 -0
- package/script/npm/src/server/internal_jobs/runtime-worker.d.ts +13 -1
- package/script/npm/src/server/internal_jobs/runtime-worker.d.ts.map +1 -1
- package/script/npm/src/server/internal_jobs/runtime-worker.js +74 -13
- package/script/npm/src/server/internal_jobs/types.d.ts +19 -0
- package/script/npm/src/server/internal_jobs/types.d.ts.map +1 -1
- package/script/npm/src/server/internal_jobs/types.js +11 -1
- package/script/npm/src/server/runtime.d.ts +1 -0
- package/script/npm/src/server/runtime.d.ts.map +1 -1
- package/script/npm/src/server/service.d.ts +10 -1
- package/script/npm/src/server/service.d.ts.map +1 -1
- package/script/npm/src/server/service.js +208 -62
- package/script/npm/src/server/transfer.d.ts.map +1 -1
- package/script/npm/src/server/transfer.js +4 -0
- package/script/npm/src/server.d.ts.map +1 -1
- package/script/npm/src/server.js +336 -33
- package/script/npm/src/store.d.ts +8 -1
- package/script/npm/src/store.d.ts.map +1 -1
- package/script/npm/src/store.js +46 -8
- package/script/npm/src/transfer.d.ts +3 -0
- package/script/npm/src/transfer.d.ts.map +1 -1
- package/script/npm/src/transfer.js +19 -29
- package/script/npm/src/trellis.d.ts +85 -22
- package/script/npm/src/trellis.d.ts.map +1 -1
- package/script/npm/src/trellis.js +525 -61
- package/script/operations.d.ts +16 -7
- package/script/operations.d.ts.map +1 -1
- package/script/operations.js +84 -19
- package/script/runtime_transport.d.ts +2 -0
- package/script/runtime_transport.d.ts.map +1 -1
- package/script/runtime_transport.js +2 -1
- package/script/store.d.ts +8 -1
- package/script/store.d.ts.map +1 -1
- package/script/store.js +46 -8
- package/script/transfer.d.ts +3 -0
- package/script/transfer.d.ts.map +1 -1
- package/script/transfer.js +19 -29
- package/script/trellis.d.ts +85 -22
- package/script/trellis.d.ts.map +1 -1
- package/script/trellis.js +525 -61
- package/src/_dnt.polyfills.ts +274 -0
- package/src/_dnt.shims.ts +64 -0
- package/src/auth/browser/login.ts +295 -0
- package/src/auth/browser/portal.ts +75 -0
- package/src/auth/browser/session.ts +197 -0
- package/src/auth/browser/storage.ts +105 -0
- package/src/auth/browser.ts +82 -0
- package/src/auth/device_activation.ts +715 -0
- package/src/auth/keys.ts +116 -0
- package/src/auth/mod.ts +298 -0
- package/src/auth/proof.ts +111 -0
- package/src/auth/protocol.ts +1629 -0
- package/src/auth/schemas.ts +145 -0
- package/src/auth/session_auth.ts +167 -0
- package/src/auth/time.ts +15 -0
- package/src/auth/trellis_id.ts +9 -0
- package/src/auth/types.ts +4 -0
- package/src/auth/utils.ts +87 -0
- package/src/auth.ts +2 -0
- package/src/browser.ts +8 -0
- package/src/client.ts +164 -0
- package/src/client_connect.ts +1328 -0
- package/src/codec.ts +107 -0
- package/src/connection.ts +466 -0
- package/src/contract.ts +84 -0
- package/src/contract_support/canonical.ts +217 -0
- package/src/contract_support/mod.ts +5079 -0
- package/src/contract_support/protocol.ts +213 -0
- package/src/contract_support/runtime.ts +129 -0
- package/src/contract_support/schema_pointers.ts +161 -0
- package/src/contracts.ts +9 -0
- package/src/device/deno.ts +941 -0
- package/src/device.ts +989 -0
- package/src/env.ts +1 -0
- package/src/errors/AuthError.ts +82 -0
- package/src/errors/KVError.ts +47 -0
- package/src/errors/RemoteError.ts +111 -0
- package/src/errors/StoreError.ts +43 -0
- package/src/errors/TransferError.ts +43 -0
- package/src/errors/TransportError.ts +48 -0
- package/src/errors/TrellisError.ts +20 -0
- package/src/errors/ValidationError.ts +80 -0
- package/src/errors/index.ts +195 -0
- package/src/generate.ts +329 -0
- package/src/globals.ts +26 -0
- package/src/health.ts +28 -0
- package/src/helpers.ts +63 -0
- package/src/host/mod.ts +9 -0
- package/src/host/node.ts +9 -0
- package/src/index.ts +233 -0
- package/src/jobs.ts +344 -0
- package/src/kv.ts +564 -0
- package/src/models/auth/rpc/Logout.ts +15 -0
- package/src/models/trellis/Page.ts +6 -0
- package/src/models/trellis/State.ts +55 -0
- package/src/models/trellis/TrellisError.ts +21 -0
- package/src/models/trellis/rpc/StateDelete.ts +13 -0
- package/src/models/trellis/rpc/StateGet.ts +25 -0
- package/src/models/trellis/rpc/StateList.ts +26 -0
- package/src/models/trellis/rpc/StatePut.ts +42 -0
- package/src/operations.ts +1508 -0
- package/src/runtime_transport.ts +132 -0
- package/src/sdk/auth.ts +2 -0
- package/src/sdk/core.ts +2 -0
- package/src/sdk/health.ts +2 -0
- package/src/sdk/jobs.ts +2 -0
- package/src/sdk/state.ts +2 -0
- package/src/server/health.ts +379 -0
- package/src/server/health_rpc.ts +51 -0
- package/src/server/health_schemas.ts +61 -0
- package/src/server/internal_jobs/active-job.ts +115 -0
- package/src/server/internal_jobs/bindings.ts +26 -0
- package/src/server/internal_jobs/cancellation-registry.ts +71 -0
- package/src/server/internal_jobs/heartbeat.ts +120 -0
- package/src/server/internal_jobs/job-manager.ts +456 -0
- package/src/server/internal_jobs/projection.ts +48 -0
- package/src/server/internal_jobs/runtime-worker.ts +741 -0
- package/src/server/internal_jobs/types.ts +124 -0
- package/src/server/runtime.ts +27 -0
- package/src/server/service.ts +2377 -0
- package/src/server/subscription.ts +143 -0
- package/src/server/transfer.ts +962 -0
- package/src/server.ts +1725 -0
- package/src/server_logger.ts +10 -0
- package/src/service/deno.ts +18 -0
- package/src/service/mod.ts +68 -0
- package/src/service/node.ts +18 -0
- package/src/store.ts +658 -0
- package/src/tasks.ts +34 -0
- package/src/telemetry/carrier.ts +35 -0
- package/src/telemetry/core.ts +31 -0
- package/src/telemetry/env.ts +23 -0
- package/src/telemetry/mod.ts +26 -0
- package/src/telemetry/nats.ts +15 -0
- package/src/telemetry/result.ts +20 -0
- package/src/telemetry/trace.ts +39 -0
- package/src/telemetry/trellis.ts +1 -0
- package/src/tracing.ts +28 -0
- package/src/transfer.ts +602 -0
- package/src/trellis.ts +3650 -0
- package/esm/models/trellis/Paginate.d.ts +0 -7
- package/esm/models/trellis/Paginate.d.ts.map +0 -1
- package/esm/models/trellis/Paginate.js +0 -5
- package/esm/npm/src/models/trellis/Paginate.d.ts +0 -7
- package/esm/npm/src/models/trellis/Paginate.d.ts.map +0 -1
- package/esm/npm/src/models/trellis/Paginate.js +0 -5
- package/script/models/trellis/Paginate.d.ts +0 -7
- package/script/models/trellis/Paginate.d.ts.map +0 -1
- package/script/models/trellis/Paginate.js +0 -11
- package/script/npm/src/models/trellis/Paginate.d.ts +0 -7
- package/script/npm/src/models/trellis/Paginate.d.ts.map +0 -1
- package/script/npm/src/models/trellis/Paginate.js +0 -11
|
@@ -0,0 +1,941 @@
|
|
|
1
|
+
import "../_dnt.polyfills.js";
|
|
2
|
+
import * as dntShim from "../_dnt.shims.js";
|
|
3
|
+
import { dirname, join } from "@std/path";
|
|
4
|
+
import type { StaticDecode } from "typebox";
|
|
5
|
+
import { Type } from "typebox";
|
|
6
|
+
import { Value } from "typebox/value";
|
|
7
|
+
|
|
8
|
+
import { deriveDeviceIdentity } from "../auth.js";
|
|
9
|
+
import type {
|
|
10
|
+
TrellisDeviceActivatedActivationState,
|
|
11
|
+
TrellisDeviceActivationArgs,
|
|
12
|
+
TrellisDeviceLocalActivationState,
|
|
13
|
+
TrellisDevicePendingActivationState,
|
|
14
|
+
} from "../device.js";
|
|
15
|
+
import {
|
|
16
|
+
resumeDeviceActivationWithDeps,
|
|
17
|
+
startDeviceActivationWithDeps,
|
|
18
|
+
} from "../device.js";
|
|
19
|
+
import { base64urlDecode, base64urlEncode } from "../auth/utils.js";
|
|
20
|
+
import type { TrellisAPI } from "../contracts.js";
|
|
21
|
+
import { signDeviceWaitRequest } from "../auth/device_activation.js";
|
|
22
|
+
|
|
23
|
+
const PendingActivationStateSchema = Type.Object({
|
|
24
|
+
status: Type.Literal("pending"),
|
|
25
|
+
contractDigest: Type.String({ minLength: 1 }),
|
|
26
|
+
publicIdentityKey: Type.String({ minLength: 1 }),
|
|
27
|
+
instanceId: Type.String({ minLength: 1 }),
|
|
28
|
+
deploymentId: Type.String({ minLength: 1 }),
|
|
29
|
+
flowId: Type.String({ minLength: 1 }),
|
|
30
|
+
nonce: Type.String({ minLength: 1 }),
|
|
31
|
+
activationUrl: Type.String({ minLength: 1 }),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const ActivatedActivationStateSchema = Type.Object({
|
|
35
|
+
status: Type.Literal("activated"),
|
|
36
|
+
contractDigest: Type.String({ minLength: 1 }),
|
|
37
|
+
publicIdentityKey: Type.String({ minLength: 1 }),
|
|
38
|
+
instanceId: Type.String({ minLength: 1 }),
|
|
39
|
+
deploymentId: Type.String({ minLength: 1 }),
|
|
40
|
+
flowId: Type.String({ minLength: 1 }),
|
|
41
|
+
nonce: Type.String({ minLength: 1 }),
|
|
42
|
+
activationUrl: Type.String({ minLength: 1 }),
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const LocalActivationStateSchema = Type.Union([
|
|
46
|
+
PendingActivationStateSchema,
|
|
47
|
+
ActivatedActivationStateSchema,
|
|
48
|
+
]);
|
|
49
|
+
|
|
50
|
+
const PersistedActivationStateSchema = Type.Object({
|
|
51
|
+
version: Type.Literal(1),
|
|
52
|
+
localState: LocalActivationStateSchema,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
type PersistedActivationState = StaticDecode<
|
|
56
|
+
typeof PersistedActivationStateSchema
|
|
57
|
+
>;
|
|
58
|
+
|
|
59
|
+
const ClientTransportEndpointsSchema = Type.Object({
|
|
60
|
+
natsServers: Type.Array(Type.String({ minLength: 1 }), { minItems: 1 }),
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const ClientTransportsSchema = Type.Object({
|
|
64
|
+
native: Type.Optional(ClientTransportEndpointsSchema),
|
|
65
|
+
websocket: Type.Optional(ClientTransportEndpointsSchema),
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const DeviceBootstrapReadySchema = Type.Object({
|
|
69
|
+
status: Type.Literal("ready"),
|
|
70
|
+
connectInfo: Type.Object({
|
|
71
|
+
instanceId: Type.String({ minLength: 1 }),
|
|
72
|
+
deploymentId: Type.String({ minLength: 1 }),
|
|
73
|
+
contractId: Type.String({ minLength: 1 }),
|
|
74
|
+
contractDigest: Type.String({ minLength: 1 }),
|
|
75
|
+
transports: ClientTransportsSchema,
|
|
76
|
+
transport: Type.Object({
|
|
77
|
+
sentinel: Type.Object({
|
|
78
|
+
jwt: Type.String({ minLength: 1 }),
|
|
79
|
+
seed: Type.String({ minLength: 1 }),
|
|
80
|
+
}),
|
|
81
|
+
}),
|
|
82
|
+
auth: Type.Object({
|
|
83
|
+
mode: Type.Literal("device_identity"),
|
|
84
|
+
iatSkewSeconds: Type.Integer({ minimum: 1 }),
|
|
85
|
+
}),
|
|
86
|
+
}),
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const DeviceBootstrapActivationRequiredSchema = Type.Object({
|
|
90
|
+
status: Type.Literal("activation_required"),
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const DeviceBootstrapNotReadySchema = Type.Object({
|
|
94
|
+
status: Type.Literal("not_ready"),
|
|
95
|
+
reason: Type.String({ minLength: 1 }),
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const WaitForDeviceActivationPendingSchema = Type.Object({
|
|
99
|
+
status: Type.Literal("pending"),
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const WaitForDeviceActivationActivatedSchema = Type.Object({
|
|
103
|
+
status: Type.Literal("activated"),
|
|
104
|
+
activatedAt: Type.String({ minLength: 1 }),
|
|
105
|
+
confirmationCode: Type.Optional(Type.String({ minLength: 1 })),
|
|
106
|
+
connectInfo: DeviceBootstrapReadySchema.properties.connectInfo,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const WaitForDeviceActivationRejectedSchema = Type.Object({
|
|
110
|
+
status: Type.Literal("rejected"),
|
|
111
|
+
reason: Type.Optional(Type.String({ minLength: 1 })),
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
type DeviceBootstrapResponse =
|
|
115
|
+
| {
|
|
116
|
+
status: "ready";
|
|
117
|
+
connectInfo: StaticDecode<typeof DeviceBootstrapReadySchema>["connectInfo"];
|
|
118
|
+
}
|
|
119
|
+
| { status: "activation_required" }
|
|
120
|
+
| { status: "not_ready"; reason: string };
|
|
121
|
+
|
|
122
|
+
type DeviceActivationWaitStatus =
|
|
123
|
+
| { status: "pending"; retryAfterMs?: number }
|
|
124
|
+
| {
|
|
125
|
+
status: "activated";
|
|
126
|
+
connectInfo: StaticDecode<typeof DeviceBootstrapReadySchema>["connectInfo"];
|
|
127
|
+
}
|
|
128
|
+
| { status: "not_ready"; reason: string }
|
|
129
|
+
| { status: "rejected"; reason?: string };
|
|
130
|
+
|
|
131
|
+
type PendingActivationResolution =
|
|
132
|
+
| { status: "pending" }
|
|
133
|
+
| { status: "activated" }
|
|
134
|
+
| { status: "not_ready"; reason: string }
|
|
135
|
+
| { status: "stale" };
|
|
136
|
+
|
|
137
|
+
const DEFAULT_WAIT_POLL_INTERVAL_MS = 3_000;
|
|
138
|
+
|
|
139
|
+
type DeviceActivationStateStoreOptions = {
|
|
140
|
+
trellisUrl: string;
|
|
141
|
+
rootSecret: Uint8Array | string;
|
|
142
|
+
contractDigest: string;
|
|
143
|
+
stateDir?: string;
|
|
144
|
+
statePath?: string;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
type DeviceActivationStateStore = {
|
|
148
|
+
readonly statePath: string;
|
|
149
|
+
load(): Promise<TrellisDeviceLocalActivationState | null>;
|
|
150
|
+
save(state: TrellisDeviceLocalActivationState): Promise<void>;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Options for the Deno-only device activation status helper.
|
|
155
|
+
*/
|
|
156
|
+
export type CheckDeviceActivationArgs<
|
|
157
|
+
TApi extends TrellisAPI = TrellisAPI,
|
|
158
|
+
TContract extends {
|
|
159
|
+
CONTRACT_ID: string;
|
|
160
|
+
CONTRACT_DIGEST: string;
|
|
161
|
+
CONTRACT: { displayName?: string };
|
|
162
|
+
API: { trellis: TApi };
|
|
163
|
+
} = {
|
|
164
|
+
CONTRACT_ID: string;
|
|
165
|
+
CONTRACT_DIGEST: string;
|
|
166
|
+
CONTRACT: { displayName?: string };
|
|
167
|
+
API: { trellis: TApi };
|
|
168
|
+
},
|
|
169
|
+
> = TrellisDeviceActivationArgs<TApi, TContract> & {
|
|
170
|
+
stateDir?: string;
|
|
171
|
+
statePath?: string;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Activation status for a device that is already ready to connect.
|
|
176
|
+
*/
|
|
177
|
+
export type TrellisDeviceActivatedStatus = {
|
|
178
|
+
status: "activated";
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Activation status for a device that cannot proceed yet.
|
|
183
|
+
*/
|
|
184
|
+
export type TrellisDeviceNotReadyStatus = {
|
|
185
|
+
status: "not_ready";
|
|
186
|
+
reason: string;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Activation status for a device that still needs activation.
|
|
191
|
+
*/
|
|
192
|
+
export type TrellisDeviceActivationRequiredStatus = {
|
|
193
|
+
status: "activation_required";
|
|
194
|
+
activationUrl: string;
|
|
195
|
+
waitForOnlineApproval(
|
|
196
|
+
opts?: { signal?: AbortSignal },
|
|
197
|
+
): Promise<TrellisDeviceActivatedStatus>;
|
|
198
|
+
acceptConfirmationCode(code: string): Promise<TrellisDeviceActivatedStatus>;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Caller-facing activation status union for Deno device runtimes.
|
|
203
|
+
*/
|
|
204
|
+
export type TrellisDeviceActivationStatus =
|
|
205
|
+
| TrellisDeviceActivatedStatus
|
|
206
|
+
| TrellisDeviceNotReadyStatus
|
|
207
|
+
| TrellisDeviceActivationRequiredStatus;
|
|
208
|
+
|
|
209
|
+
function normalizeRootSecret(rootSecret: Uint8Array | string): Uint8Array {
|
|
210
|
+
if (typeof rootSecret === "string") {
|
|
211
|
+
const decoded = base64urlDecode(rootSecret.trim());
|
|
212
|
+
if (decoded.length === 0) {
|
|
213
|
+
throw new Error("rootSecret must not be empty");
|
|
214
|
+
}
|
|
215
|
+
return decoded;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (rootSecret.length === 0) {
|
|
219
|
+
throw new Error("rootSecret must not be empty");
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return rootSecret;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function isNotFoundError(error: unknown): boolean {
|
|
226
|
+
return error instanceof dntShim.Deno.errors.NotFound;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function isAlreadyExistsError(error: unknown): boolean {
|
|
230
|
+
return error instanceof dntShim.Deno.errors.AlreadyExists;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function tempStatePath(statePath: string): string {
|
|
234
|
+
return `${statePath}.tmp-${crypto.randomUUID()}`;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function backupStatePath(statePath: string): string {
|
|
238
|
+
return `${statePath}.bak`;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function defaultActivationStateDir(): string {
|
|
242
|
+
if (dntShim.Deno.build.os === "windows") {
|
|
243
|
+
const base = dntShim.Deno.env.get("LOCALAPPDATA") ?? dntShim.Deno.env.get("APPDATA");
|
|
244
|
+
if (!base) {
|
|
245
|
+
throw new Error(
|
|
246
|
+
"Could not resolve a default Trellis device state directory: LOCALAPPDATA or APPDATA is not set.",
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
return join(base, "Trellis", "device-activation");
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const home = dntShim.Deno.env.get("HOME");
|
|
253
|
+
if (!home) {
|
|
254
|
+
throw new Error(
|
|
255
|
+
"Could not resolve a default Trellis device state directory: HOME is not set.",
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (dntShim.Deno.build.os === "darwin") {
|
|
260
|
+
return join(
|
|
261
|
+
home,
|
|
262
|
+
"Library",
|
|
263
|
+
"Application Support",
|
|
264
|
+
"Trellis",
|
|
265
|
+
"device-activation",
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return join(
|
|
270
|
+
dntShim.Deno.env.get("XDG_STATE_HOME") ?? join(home, ".local", "state"),
|
|
271
|
+
"trellis",
|
|
272
|
+
"device-activation",
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
async function hashOrigin(origin: string): Promise<string> {
|
|
277
|
+
const digest = await crypto.subtle.digest(
|
|
278
|
+
"SHA-256",
|
|
279
|
+
new TextEncoder().encode(origin),
|
|
280
|
+
);
|
|
281
|
+
return base64urlEncode(new Uint8Array(digest));
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
async function deriveStoreIdentity(
|
|
285
|
+
args: DeviceActivationStateStoreOptions,
|
|
286
|
+
): Promise<{ publicIdentityKey: string }> {
|
|
287
|
+
const identity = await deriveDeviceIdentity(
|
|
288
|
+
normalizeRootSecret(args.rootSecret),
|
|
289
|
+
);
|
|
290
|
+
return {
|
|
291
|
+
publicIdentityKey: identity.publicIdentityKey,
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function parsePersistedState(text: string): TrellisDeviceLocalActivationState {
|
|
296
|
+
let parsed: unknown;
|
|
297
|
+
try {
|
|
298
|
+
parsed = JSON.parse(text);
|
|
299
|
+
} catch (cause) {
|
|
300
|
+
throw new Error(
|
|
301
|
+
"Stored Trellis device activation state is not valid JSON.",
|
|
302
|
+
{
|
|
303
|
+
cause,
|
|
304
|
+
},
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (!Value.Check(PersistedActivationStateSchema, parsed)) {
|
|
309
|
+
throw new Error(
|
|
310
|
+
"Stored Trellis device activation state has an invalid shape.",
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const persisted = Value.Parse(
|
|
315
|
+
PersistedActivationStateSchema,
|
|
316
|
+
parsed,
|
|
317
|
+
) as PersistedActivationState;
|
|
318
|
+
return persisted.localState;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function assertLocalStateMatchesIdentity(args: {
|
|
322
|
+
state: TrellisDeviceLocalActivationState;
|
|
323
|
+
publicIdentityKey: string;
|
|
324
|
+
}): void {
|
|
325
|
+
if (args.state.publicIdentityKey !== args.publicIdentityKey) {
|
|
326
|
+
throw new Error(
|
|
327
|
+
"Stored Trellis device activation state does not match the provided root secret.",
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function assertLocalStateMatchesContract(args: {
|
|
333
|
+
state: TrellisDeviceLocalActivationState;
|
|
334
|
+
contractDigest: string;
|
|
335
|
+
}): void {
|
|
336
|
+
if (args.state.contractDigest !== args.contractDigest) {
|
|
337
|
+
throw new Error(
|
|
338
|
+
"Stored Trellis device activation state does not match the requested contract digest.",
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
async function resolveDeviceActivationStatePath(
|
|
344
|
+
args: DeviceActivationStateStoreOptions,
|
|
345
|
+
): Promise<string> {
|
|
346
|
+
if (args.statePath) {
|
|
347
|
+
return args.statePath;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
const { publicIdentityKey } = await deriveStoreIdentity(args);
|
|
351
|
+
const origin = new URL(args.trellisUrl).origin;
|
|
352
|
+
const originHash = await hashOrigin(origin);
|
|
353
|
+
const fileName =
|
|
354
|
+
`activation-state-v1-${originHash}-${args.contractDigest}-${publicIdentityKey}.json`;
|
|
355
|
+
|
|
356
|
+
return join(args.stateDir ?? defaultActivationStateDir(), fileName);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
async function openDeviceActivationStateStore(
|
|
360
|
+
args: DeviceActivationStateStoreOptions,
|
|
361
|
+
): Promise<DeviceActivationStateStore> {
|
|
362
|
+
const { publicIdentityKey } = await deriveStoreIdentity(args);
|
|
363
|
+
const statePath = await resolveDeviceActivationStatePath(args);
|
|
364
|
+
const stateBackupPath = backupStatePath(statePath);
|
|
365
|
+
|
|
366
|
+
return {
|
|
367
|
+
statePath,
|
|
368
|
+
async load(): Promise<TrellisDeviceLocalActivationState | null> {
|
|
369
|
+
for (const path of [statePath, stateBackupPath]) {
|
|
370
|
+
try {
|
|
371
|
+
const text = await dntShim.Deno.readTextFile(path);
|
|
372
|
+
const state = parsePersistedState(text);
|
|
373
|
+
assertLocalStateMatchesIdentity({ state, publicIdentityKey });
|
|
374
|
+
assertLocalStateMatchesContract({
|
|
375
|
+
state,
|
|
376
|
+
contractDigest: args.contractDigest,
|
|
377
|
+
});
|
|
378
|
+
return state;
|
|
379
|
+
} catch (error) {
|
|
380
|
+
if (isNotFoundError(error)) {
|
|
381
|
+
continue;
|
|
382
|
+
}
|
|
383
|
+
throw error;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
return null;
|
|
387
|
+
},
|
|
388
|
+
async save(state: TrellisDeviceLocalActivationState): Promise<void> {
|
|
389
|
+
if (!Value.Check(LocalActivationStateSchema, state)) {
|
|
390
|
+
throw new Error(
|
|
391
|
+
"Trellis device activation state has an invalid shape.",
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
assertLocalStateMatchesIdentity({ state, publicIdentityKey });
|
|
396
|
+
assertLocalStateMatchesContract({
|
|
397
|
+
state,
|
|
398
|
+
contractDigest: args.contractDigest,
|
|
399
|
+
});
|
|
400
|
+
await dntShim.Deno.mkdir(dirname(statePath), { recursive: true });
|
|
401
|
+
const nextText =
|
|
402
|
+
JSON.stringify({ version: 1, localState: state }, null, 2) +
|
|
403
|
+
"\n";
|
|
404
|
+
const nextPath = tempStatePath(statePath);
|
|
405
|
+
try {
|
|
406
|
+
await dntShim.Deno.writeTextFile(nextPath, nextText);
|
|
407
|
+
try {
|
|
408
|
+
await dntShim.Deno.rename(nextPath, statePath);
|
|
409
|
+
} catch (error) {
|
|
410
|
+
if (!isAlreadyExistsError(error)) {
|
|
411
|
+
throw error;
|
|
412
|
+
}
|
|
413
|
+
try {
|
|
414
|
+
await dntShim.Deno.remove(stateBackupPath);
|
|
415
|
+
} catch (backupError) {
|
|
416
|
+
if (!isNotFoundError(backupError)) {
|
|
417
|
+
throw backupError;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
await dntShim.Deno.rename(statePath, stateBackupPath);
|
|
421
|
+
try {
|
|
422
|
+
await dntShim.Deno.rename(nextPath, statePath);
|
|
423
|
+
await dntShim.Deno.remove(stateBackupPath);
|
|
424
|
+
} catch (renameError) {
|
|
425
|
+
try {
|
|
426
|
+
await dntShim.Deno.rename(stateBackupPath, statePath);
|
|
427
|
+
} catch (rollbackError) {
|
|
428
|
+
if (!isNotFoundError(rollbackError)) {
|
|
429
|
+
throw rollbackError;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
throw renameError;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
} catch (error) {
|
|
436
|
+
try {
|
|
437
|
+
await dntShim.Deno.remove(nextPath);
|
|
438
|
+
} catch (cleanupError) {
|
|
439
|
+
if (!isNotFoundError(cleanupError)) {
|
|
440
|
+
throw cleanupError;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
throw error;
|
|
444
|
+
}
|
|
445
|
+
},
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
function readResponseReason(text: string): string | null {
|
|
450
|
+
if (!text) {
|
|
451
|
+
return null;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
try {
|
|
455
|
+
const parsed = JSON.parse(text) as Record<string, unknown>;
|
|
456
|
+
if (typeof parsed.reason === "string" && parsed.reason.length > 0) {
|
|
457
|
+
return parsed.reason;
|
|
458
|
+
}
|
|
459
|
+
} catch {
|
|
460
|
+
return text;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
return text;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
function parseResponseRecord(text: string): Record<string, unknown> | null {
|
|
467
|
+
if (text.length === 0) {
|
|
468
|
+
return null;
|
|
469
|
+
}
|
|
470
|
+
try {
|
|
471
|
+
const parsed = JSON.parse(text);
|
|
472
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed)
|
|
473
|
+
? parsed as Record<string, unknown>
|
|
474
|
+
: null;
|
|
475
|
+
} catch {
|
|
476
|
+
return null;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
async function fetchDeviceBootstrap(args: {
|
|
481
|
+
trellisUrl: string;
|
|
482
|
+
publicIdentityKey: string;
|
|
483
|
+
identitySeed: Uint8Array | string;
|
|
484
|
+
contractDigest: string;
|
|
485
|
+
iat?: number;
|
|
486
|
+
}): Promise<DeviceBootstrapResponse> {
|
|
487
|
+
let iat = args.iat;
|
|
488
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
489
|
+
const request = await signDeviceWaitRequest({
|
|
490
|
+
flowId: "connect-info",
|
|
491
|
+
publicIdentityKey: args.publicIdentityKey,
|
|
492
|
+
nonce: "connect-info",
|
|
493
|
+
identitySeed: args.identitySeed,
|
|
494
|
+
contractDigest: args.contractDigest,
|
|
495
|
+
iat,
|
|
496
|
+
});
|
|
497
|
+
const bootstrapRequest = {
|
|
498
|
+
publicIdentityKey: request.publicIdentityKey,
|
|
499
|
+
contractDigest: request.contractDigest,
|
|
500
|
+
iat: request.iat,
|
|
501
|
+
sig: request.sig,
|
|
502
|
+
};
|
|
503
|
+
const response = await fetch(
|
|
504
|
+
new URL("/auth/devices/connect-info", args.trellisUrl),
|
|
505
|
+
{
|
|
506
|
+
method: "POST",
|
|
507
|
+
headers: { "Content-Type": "application/json" },
|
|
508
|
+
body: JSON.stringify(bootstrapRequest),
|
|
509
|
+
},
|
|
510
|
+
);
|
|
511
|
+
if (!response.ok) {
|
|
512
|
+
const responseText = await response.text();
|
|
513
|
+
const parsed = parseResponseRecord(responseText);
|
|
514
|
+
const reason = typeof parsed?.reason === "string"
|
|
515
|
+
? parsed.reason
|
|
516
|
+
: responseText;
|
|
517
|
+
const serverNow = typeof parsed?.serverNow === "number"
|
|
518
|
+
? parsed.serverNow
|
|
519
|
+
: null;
|
|
520
|
+
if (
|
|
521
|
+
attempt === 0 &&
|
|
522
|
+
response.status === 400 &&
|
|
523
|
+
reason === "iat_out_of_range" &&
|
|
524
|
+
serverNow !== null
|
|
525
|
+
) {
|
|
526
|
+
iat = serverNow;
|
|
527
|
+
continue;
|
|
528
|
+
}
|
|
529
|
+
if (
|
|
530
|
+
response.status === 404 &&
|
|
531
|
+
(reason === "unknown_device" || reason === "activation_required")
|
|
532
|
+
) {
|
|
533
|
+
return { status: "activation_required" };
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
throw new Error(
|
|
537
|
+
`Device bootstrap failed: ${response.status}${
|
|
538
|
+
reason ? ` ${reason}` : ""
|
|
539
|
+
}`,
|
|
540
|
+
);
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
const payload = await response.json();
|
|
544
|
+
if (Value.Check(DeviceBootstrapReadySchema, payload)) {
|
|
545
|
+
return payload;
|
|
546
|
+
}
|
|
547
|
+
if (Value.Check(DeviceBootstrapActivationRequiredSchema, payload)) {
|
|
548
|
+
return payload;
|
|
549
|
+
}
|
|
550
|
+
if (Value.Check(DeviceBootstrapNotReadySchema, payload)) {
|
|
551
|
+
return payload;
|
|
552
|
+
}
|
|
553
|
+
throw new Error("Device bootstrap returned an invalid response");
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
throw new Error("Device bootstrap time synchronization failed");
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
async function fetchDeviceActivationWaitStatus(args: {
|
|
560
|
+
trellisUrl: string;
|
|
561
|
+
flowId: string;
|
|
562
|
+
publicIdentityKey: string;
|
|
563
|
+
identitySeed: Uint8Array | string;
|
|
564
|
+
contractDigest: string;
|
|
565
|
+
nonce: string;
|
|
566
|
+
signal?: AbortSignal;
|
|
567
|
+
iat?: number;
|
|
568
|
+
}): Promise<DeviceActivationWaitStatus> {
|
|
569
|
+
let iat = args.iat;
|
|
570
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
571
|
+
const request = await signDeviceWaitRequest({
|
|
572
|
+
flowId: args.flowId,
|
|
573
|
+
publicIdentityKey: args.publicIdentityKey,
|
|
574
|
+
nonce: args.nonce,
|
|
575
|
+
identitySeed: args.identitySeed,
|
|
576
|
+
contractDigest: args.contractDigest,
|
|
577
|
+
iat,
|
|
578
|
+
});
|
|
579
|
+
const response = await fetch(
|
|
580
|
+
new URL("/auth/devices/activate/wait", args.trellisUrl),
|
|
581
|
+
{
|
|
582
|
+
method: "POST",
|
|
583
|
+
headers: { "Content-Type": "application/json" },
|
|
584
|
+
body: JSON.stringify(request),
|
|
585
|
+
signal: args.signal,
|
|
586
|
+
},
|
|
587
|
+
);
|
|
588
|
+
if (!response.ok) {
|
|
589
|
+
if (response.status === 429) {
|
|
590
|
+
return { status: "pending", ...retryAfterStatus(response) };
|
|
591
|
+
}
|
|
592
|
+
const responseText = await response.text();
|
|
593
|
+
const parsed = parseResponseRecord(responseText);
|
|
594
|
+
const reason = typeof parsed?.reason === "string"
|
|
595
|
+
? parsed.reason
|
|
596
|
+
: responseText;
|
|
597
|
+
const serverNow = typeof parsed?.serverNow === "number"
|
|
598
|
+
? parsed.serverNow
|
|
599
|
+
: null;
|
|
600
|
+
if (
|
|
601
|
+
attempt === 0 &&
|
|
602
|
+
response.status === 400 &&
|
|
603
|
+
reason === "iat_out_of_range" &&
|
|
604
|
+
serverNow !== null
|
|
605
|
+
) {
|
|
606
|
+
iat = serverNow;
|
|
607
|
+
continue;
|
|
608
|
+
}
|
|
609
|
+
if (response.status === 403 && reason === "contract_digest_not_allowed") {
|
|
610
|
+
return { status: "not_ready", reason };
|
|
611
|
+
}
|
|
612
|
+
throw new Error(
|
|
613
|
+
`Device activation status failed: ${response.status}${
|
|
614
|
+
reason ? ` ${reason}` : ""
|
|
615
|
+
}`,
|
|
616
|
+
);
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
const payload = await response.json();
|
|
620
|
+
if (Value.Check(WaitForDeviceActivationPendingSchema, payload)) {
|
|
621
|
+
return payload;
|
|
622
|
+
}
|
|
623
|
+
if (Value.Check(WaitForDeviceActivationActivatedSchema, payload)) {
|
|
624
|
+
return payload;
|
|
625
|
+
}
|
|
626
|
+
if (Value.Check(WaitForDeviceActivationRejectedSchema, payload)) {
|
|
627
|
+
return payload;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
throw new Error("Device activation status returned an invalid response");
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
throw new Error("Device activation status time synchronization failed");
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
function retryAfterStatus(response: Response): { retryAfterMs?: number } {
|
|
637
|
+
const value = response.headers.get("Retry-After");
|
|
638
|
+
if (!value) return {};
|
|
639
|
+
|
|
640
|
+
const seconds = Number(value);
|
|
641
|
+
if (Number.isFinite(seconds) && seconds >= 0) {
|
|
642
|
+
return { retryAfterMs: seconds * 1_000 };
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
const dateMs = Date.parse(value);
|
|
646
|
+
if (!Number.isFinite(dateMs)) return {};
|
|
647
|
+
return { retryAfterMs: Math.max(0, dateMs - Date.now()) };
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
function activatedStatus(): TrellisDeviceActivatedStatus {
|
|
651
|
+
return { status: "activated" };
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
function sleep(ms: number, signal?: AbortSignal): Promise<void> {
|
|
655
|
+
return new Promise((resolve, reject) => {
|
|
656
|
+
if (signal?.aborted) {
|
|
657
|
+
reject(signal.reason ?? new Error("Aborted"));
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
const timer = setTimeout(() => {
|
|
662
|
+
signal?.removeEventListener("abort", onAbort);
|
|
663
|
+
resolve();
|
|
664
|
+
}, ms);
|
|
665
|
+
const onAbort = () => {
|
|
666
|
+
clearTimeout(timer);
|
|
667
|
+
signal?.removeEventListener("abort", onAbort);
|
|
668
|
+
reject(signal?.reason ?? new Error("Aborted"));
|
|
669
|
+
};
|
|
670
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
function createActivatedLocalState(
|
|
675
|
+
localState:
|
|
676
|
+
| TrellisDevicePendingActivationState
|
|
677
|
+
| TrellisDeviceActivatedActivationState,
|
|
678
|
+
): TrellisDeviceActivatedActivationState {
|
|
679
|
+
return {
|
|
680
|
+
...localState,
|
|
681
|
+
status: "activated",
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
function assertActivationConnectInfoMatchesContract(args: {
|
|
686
|
+
contractId: string;
|
|
687
|
+
contractDigest: string;
|
|
688
|
+
connectInfo: StaticDecode<typeof DeviceBootstrapReadySchema>["connectInfo"];
|
|
689
|
+
}): void {
|
|
690
|
+
if (
|
|
691
|
+
args.connectInfo.contractId !== args.contractId ||
|
|
692
|
+
args.connectInfo.contractDigest !== args.contractDigest
|
|
693
|
+
) {
|
|
694
|
+
throw new Error(
|
|
695
|
+
"Trellis activation status returned connection details for a different contract.",
|
|
696
|
+
);
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
async function waitForActivationCompletion(args: {
|
|
701
|
+
trellisUrl: string;
|
|
702
|
+
rootSecret: Uint8Array | string;
|
|
703
|
+
contractId: string;
|
|
704
|
+
contractDigest: string;
|
|
705
|
+
localState: TrellisDevicePendingActivationState;
|
|
706
|
+
signal?: AbortSignal;
|
|
707
|
+
}): Promise<TrellisDeviceActivatedActivationState> {
|
|
708
|
+
const identity = await deriveDeviceIdentity(
|
|
709
|
+
normalizeRootSecret(args.rootSecret),
|
|
710
|
+
);
|
|
711
|
+
|
|
712
|
+
while (true) {
|
|
713
|
+
const waitStatus = await fetchDeviceActivationWaitStatus({
|
|
714
|
+
trellisUrl: args.trellisUrl,
|
|
715
|
+
publicIdentityKey: identity.publicIdentityKey,
|
|
716
|
+
identitySeed: identity.identitySeed,
|
|
717
|
+
contractDigest: args.contractDigest,
|
|
718
|
+
flowId: args.localState.flowId,
|
|
719
|
+
nonce: args.localState.nonce,
|
|
720
|
+
signal: args.signal,
|
|
721
|
+
});
|
|
722
|
+
|
|
723
|
+
if (waitStatus.status === "activated") {
|
|
724
|
+
assertActivationConnectInfoMatchesContract({
|
|
725
|
+
contractId: args.contractId,
|
|
726
|
+
contractDigest: args.contractDigest,
|
|
727
|
+
connectInfo: waitStatus.connectInfo,
|
|
728
|
+
});
|
|
729
|
+
return createActivatedLocalState(args.localState);
|
|
730
|
+
}
|
|
731
|
+
if (waitStatus.status === "rejected") {
|
|
732
|
+
throw new Error(
|
|
733
|
+
`device activation rejected: ${waitStatus.reason ?? "unknown_reason"}`,
|
|
734
|
+
);
|
|
735
|
+
}
|
|
736
|
+
if (waitStatus.status === "not_ready") {
|
|
737
|
+
throw new Error(`device activation not ready: ${waitStatus.reason}`);
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
await sleep(
|
|
741
|
+
Math.max(DEFAULT_WAIT_POLL_INTERVAL_MS, waitStatus.retryAfterMs ?? 0),
|
|
742
|
+
args.signal,
|
|
743
|
+
);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
async function createActivationRequiredStatus<
|
|
748
|
+
TApi extends TrellisAPI,
|
|
749
|
+
TContract extends {
|
|
750
|
+
CONTRACT_ID: string;
|
|
751
|
+
CONTRACT_DIGEST: string;
|
|
752
|
+
CONTRACT: { displayName?: string };
|
|
753
|
+
API: { trellis: TApi };
|
|
754
|
+
},
|
|
755
|
+
>(args: {
|
|
756
|
+
checkArgs: CheckDeviceActivationArgs<TApi, TContract>;
|
|
757
|
+
store: DeviceActivationStateStore;
|
|
758
|
+
localState: TrellisDeviceLocalActivationState | null;
|
|
759
|
+
}): Promise<TrellisDeviceActivationRequiredStatus> {
|
|
760
|
+
const session = args.localState?.status === "pending"
|
|
761
|
+
? await resumeDeviceActivationWithDeps({
|
|
762
|
+
trellisUrl: args.checkArgs.trellisUrl,
|
|
763
|
+
contract: args.checkArgs.contract,
|
|
764
|
+
rootSecret: args.checkArgs.rootSecret,
|
|
765
|
+
localState: args.localState,
|
|
766
|
+
}, { now: () => Date.now() })
|
|
767
|
+
: await startDeviceActivationWithDeps({
|
|
768
|
+
trellisUrl: args.checkArgs.trellisUrl,
|
|
769
|
+
contract: args.checkArgs.contract,
|
|
770
|
+
rootSecret: args.checkArgs.rootSecret,
|
|
771
|
+
}, { now: () => Date.now() });
|
|
772
|
+
|
|
773
|
+
if (args.localState?.status !== "pending") {
|
|
774
|
+
await args.store.save(session.localState);
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
let completedState: TrellisDeviceActivatedActivationState | null = null;
|
|
778
|
+
let completionPromise: Promise<TrellisDeviceActivatedStatus> | null = null;
|
|
779
|
+
const finish = async (
|
|
780
|
+
nextState: () => Promise<TrellisDeviceActivatedActivationState>,
|
|
781
|
+
): Promise<TrellisDeviceActivatedStatus> => {
|
|
782
|
+
if (completedState) {
|
|
783
|
+
return activatedStatus();
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
if (completionPromise) {
|
|
787
|
+
return await completionPromise;
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
completionPromise = (async () => {
|
|
791
|
+
const nextCompletedState = await nextState();
|
|
792
|
+
await args.store.save(nextCompletedState);
|
|
793
|
+
completedState = nextCompletedState;
|
|
794
|
+
return activatedStatus();
|
|
795
|
+
})();
|
|
796
|
+
try {
|
|
797
|
+
return await completionPromise;
|
|
798
|
+
} catch (error) {
|
|
799
|
+
completionPromise = null;
|
|
800
|
+
throw error;
|
|
801
|
+
}
|
|
802
|
+
};
|
|
803
|
+
|
|
804
|
+
return {
|
|
805
|
+
status: "activation_required",
|
|
806
|
+
activationUrl: session.activationUrl,
|
|
807
|
+
waitForOnlineApproval(opts?: { signal?: AbortSignal }) {
|
|
808
|
+
return finish(() =>
|
|
809
|
+
waitForActivationCompletion({
|
|
810
|
+
trellisUrl: args.checkArgs.trellisUrl,
|
|
811
|
+
rootSecret: args.checkArgs.rootSecret,
|
|
812
|
+
contractId: args.checkArgs.contract.CONTRACT_ID,
|
|
813
|
+
contractDigest: args.checkArgs.contract.CONTRACT_DIGEST,
|
|
814
|
+
localState: session.localState,
|
|
815
|
+
signal: opts?.signal,
|
|
816
|
+
})
|
|
817
|
+
);
|
|
818
|
+
},
|
|
819
|
+
acceptConfirmationCode(code: string) {
|
|
820
|
+
return finish(() => session.acceptConfirmationCode(code));
|
|
821
|
+
},
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
async function resolvePendingActivation(args: {
|
|
826
|
+
trellisUrl: string;
|
|
827
|
+
publicIdentityKey: string;
|
|
828
|
+
identitySeed: Uint8Array;
|
|
829
|
+
contractId: string;
|
|
830
|
+
contractDigest: string;
|
|
831
|
+
localState: TrellisDevicePendingActivationState;
|
|
832
|
+
store: DeviceActivationStateStore;
|
|
833
|
+
}): Promise<PendingActivationResolution> {
|
|
834
|
+
const waitStatus = await fetchDeviceActivationWaitStatus({
|
|
835
|
+
trellisUrl: args.trellisUrl,
|
|
836
|
+
publicIdentityKey: args.publicIdentityKey,
|
|
837
|
+
identitySeed: args.identitySeed,
|
|
838
|
+
contractDigest: args.contractDigest,
|
|
839
|
+
flowId: args.localState.flowId,
|
|
840
|
+
nonce: args.localState.nonce,
|
|
841
|
+
});
|
|
842
|
+
|
|
843
|
+
if (waitStatus.status === "activated") {
|
|
844
|
+
assertActivationConnectInfoMatchesContract({
|
|
845
|
+
contractId: args.contractId,
|
|
846
|
+
contractDigest: args.contractDigest,
|
|
847
|
+
connectInfo: waitStatus.connectInfo,
|
|
848
|
+
});
|
|
849
|
+
await args.store.save(createActivatedLocalState(args.localState));
|
|
850
|
+
return { status: "activated" };
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
if (waitStatus.status === "rejected") {
|
|
854
|
+
return { status: "stale" };
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
if (waitStatus.status === "not_ready") {
|
|
858
|
+
return waitStatus;
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
return { status: "pending" };
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
/**
|
|
865
|
+
* Reports Deno device activation status and hides local activation persistence details.
|
|
866
|
+
*/
|
|
867
|
+
export async function checkDeviceActivation<
|
|
868
|
+
TApi extends TrellisAPI,
|
|
869
|
+
TContract extends {
|
|
870
|
+
CONTRACT_ID: string;
|
|
871
|
+
CONTRACT_DIGEST: string;
|
|
872
|
+
CONTRACT: { displayName?: string };
|
|
873
|
+
API: { trellis: TApi };
|
|
874
|
+
},
|
|
875
|
+
>(
|
|
876
|
+
args: CheckDeviceActivationArgs<TApi, TContract>,
|
|
877
|
+
): Promise<TrellisDeviceActivationStatus> {
|
|
878
|
+
const store = await openDeviceActivationStateStore({
|
|
879
|
+
trellisUrl: args.trellisUrl,
|
|
880
|
+
rootSecret: args.rootSecret,
|
|
881
|
+
contractDigest: args.contract.CONTRACT_DIGEST,
|
|
882
|
+
stateDir: args.stateDir,
|
|
883
|
+
statePath: args.statePath,
|
|
884
|
+
});
|
|
885
|
+
let localState = await store.load();
|
|
886
|
+
const identity = await deriveDeviceIdentity(
|
|
887
|
+
normalizeRootSecret(args.rootSecret),
|
|
888
|
+
);
|
|
889
|
+
const bootstrap = await fetchDeviceBootstrap({
|
|
890
|
+
trellisUrl: args.trellisUrl,
|
|
891
|
+
publicIdentityKey: identity.publicIdentityKey,
|
|
892
|
+
identitySeed: identity.identitySeed,
|
|
893
|
+
contractDigest: args.contract.CONTRACT_DIGEST,
|
|
894
|
+
});
|
|
895
|
+
|
|
896
|
+
if (bootstrap.status === "ready") {
|
|
897
|
+
assertActivationConnectInfoMatchesContract({
|
|
898
|
+
contractId: args.contract.CONTRACT_ID,
|
|
899
|
+
contractDigest: args.contract.CONTRACT_DIGEST,
|
|
900
|
+
connectInfo: bootstrap.connectInfo,
|
|
901
|
+
});
|
|
902
|
+
if (localState?.status === "pending") {
|
|
903
|
+
await store.save(createActivatedLocalState(localState));
|
|
904
|
+
}
|
|
905
|
+
return activatedStatus();
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
if (bootstrap.status === "not_ready") {
|
|
909
|
+
return bootstrap;
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
if (localState?.status === "pending") {
|
|
913
|
+
const pendingStatus = await resolvePendingActivation({
|
|
914
|
+
trellisUrl: args.trellisUrl,
|
|
915
|
+
publicIdentityKey: identity.publicIdentityKey,
|
|
916
|
+
identitySeed: identity.identitySeed,
|
|
917
|
+
contractId: args.contract.CONTRACT_ID,
|
|
918
|
+
contractDigest: args.contract.CONTRACT_DIGEST,
|
|
919
|
+
localState,
|
|
920
|
+
store,
|
|
921
|
+
});
|
|
922
|
+
|
|
923
|
+
if (pendingStatus.status === "activated") {
|
|
924
|
+
return activatedStatus();
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
if (pendingStatus.status === "not_ready") {
|
|
928
|
+
return pendingStatus;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
if (pendingStatus.status === "stale") {
|
|
932
|
+
localState = null;
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
return await createActivationRequiredStatus({
|
|
937
|
+
checkArgs: args,
|
|
938
|
+
store,
|
|
939
|
+
localState,
|
|
940
|
+
});
|
|
941
|
+
}
|