@abloatai/ablo 0.34.0 → 0.35.0
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/AGENTS.md +4 -1
- package/CHANGELOG.md +684 -5
- package/README.md +39 -22
- package/dist/BaseSyncedStore.d.ts +152 -44
- package/dist/BaseSyncedStore.js +300 -184
- package/dist/Database.d.ts +9 -24
- package/dist/Database.js +37 -22
- package/dist/InstanceCache.d.ts +25 -4
- package/dist/InstanceCache.js +48 -15
- package/dist/LazyReferenceCollection.d.ts +3 -3
- package/dist/LazyReferenceCollection.js +4 -4
- package/dist/Model.d.ts +6 -6
- package/dist/Model.js +10 -10
- package/dist/ModelRegistry.d.ts +4 -4
- package/dist/ModelRegistry.js +3 -3
- package/dist/{SyncEngineContext.d.ts → RuntimeContext.d.ts} +20 -13
- package/dist/{SyncEngineContext.js → RuntimeContext.js} +11 -12
- package/dist/SyncClient.d.ts +42 -32
- package/dist/SyncClient.js +166 -110
- package/dist/ai-sdk/coordinatedTool.d.ts +2 -2
- package/dist/ai-sdk/coordinatedTool.js +1 -1
- package/dist/ai-sdk/coordinationContext.d.ts +2 -2
- package/dist/ai-sdk/coordinationContext.js +1 -1
- package/dist/ai-sdk/wrap.d.ts +3 -3
- package/dist/ai-sdk/wrap.js +2 -2
- package/dist/auth/index.d.ts +1 -156
- package/dist/auth/index.js +8 -301
- package/dist/cli.cjs +3459 -1126
- package/dist/client/Ablo.d.ts +42 -287
- package/dist/client/Ablo.js +118 -963
- package/dist/client/abloClient.d.ts +309 -0
- package/dist/client/abloClient.js +13 -0
- package/dist/client/clientPrelude.d.ts +52 -0
- package/dist/client/clientPrelude.js +60 -0
- package/dist/client/consoleLogger.d.ts +2 -2
- package/dist/client/coreClient.d.ts +60 -0
- package/dist/client/coreClient.js +118 -0
- package/dist/client/createInternalComponents.d.ts +4 -4
- package/dist/client/createInternalComponents.js +9 -8
- package/dist/client/createModelProxy.d.ts +78 -373
- package/dist/client/createModelProxy.js +114 -86
- package/dist/client/humans.d.ts +48 -0
- package/dist/client/humans.js +52 -0
- package/dist/client/modelRegistration.d.ts +1 -1
- package/dist/client/modelRegistration.js +9 -9
- package/dist/client/options.d.ts +73 -17
- package/dist/client/reactiveEngine.d.ts +48 -0
- package/dist/client/reactiveEngine.js +910 -0
- package/dist/client/resourceTypes.d.ts +9 -250
- package/dist/client/resourceTypes.js +8 -5
- package/dist/client/schemaConfig.d.ts +4 -4
- package/dist/client/schemaConfig.js +6 -2
- package/dist/client/validateAbloOptions.d.ts +3 -2
- package/dist/client/validateAbloOptions.js +1 -1
- package/dist/client/wsMutationExecutor.d.ts +3 -3
- package/dist/client/wsMutationExecutor.js +3 -3
- package/dist/context.d.ts +9 -9
- package/dist/context.js +10 -9
- package/dist/coordination/ClaimLog.d.ts +26 -0
- package/dist/coordination/ClaimLog.js +32 -0
- package/dist/coordination/index.d.ts +1 -15
- package/dist/coordination/index.js +8 -31
- package/dist/core/DatabaseManager.js +1 -1
- package/dist/core/QueryView.d.ts +1 -1
- package/dist/core/QueryView.js +1 -1
- package/dist/core/StoreManager.d.ts +4 -23
- package/dist/core/StoreManager.js +5 -55
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +2 -2
- package/dist/core/storeContract.d.ts +2 -2
- package/dist/docs/catalog.d.ts +72 -0
- package/dist/docs/catalog.js +227 -0
- package/dist/docs/index.d.ts +10 -0
- package/dist/docs/index.js +10 -0
- package/dist/environment.d.ts +1 -40
- package/dist/environment.js +8 -37
- package/dist/index.d.ts +40 -34
- package/dist/index.js +26 -20
- package/dist/interfaces/index.d.ts +44 -134
- package/dist/keys/index.d.ts +1 -77
- package/dist/keys/index.js +8 -190
- package/dist/mutators/{RecordingTransaction.d.ts → RecordingMutation.d.ts} +4 -4
- package/dist/mutators/{RecordingTransaction.js → RecordingMutation.js} +2 -2
- package/dist/mutators/Transaction.d.ts +1 -1
- package/dist/mutators/Transaction.js +1 -1
- package/dist/mutators/UndoManager.d.ts +6 -6
- package/dist/mutators/UndoManager.js +5 -5
- package/dist/mutators/defineMutators.d.ts +3 -3
- package/dist/mutators/defineMutators.js +1 -1
- package/dist/mutators/inverseOp.js +2 -2
- package/dist/mutators/mutateActions.d.ts +3 -3
- package/dist/mutators/mutateActions.js +1 -1
- package/dist/mutators/readerActions.d.ts +1 -1
- package/dist/mutators/undoApply.d.ts +1 -1
- package/dist/mutators/undoApply.js +1 -1
- package/dist/policy/index.d.ts +2 -2
- package/dist/policy/index.js +1 -1
- package/dist/query/client.d.ts +2 -2
- package/dist/query/client.js +4 -4
- package/dist/query/types.d.ts +6 -41
- package/dist/query/types.js +2 -2
- package/dist/react/AbloProvider.d.ts +6 -8
- package/dist/react/AbloProvider.js +5 -7
- package/dist/react/context.d.ts +1 -1
- package/dist/react/context.js +1 -1
- package/dist/react/index.d.ts +5 -5
- package/dist/react/index.js +3 -3
- package/dist/react/internalContext.d.ts +1 -1
- package/dist/react/useAblo.d.ts +3 -3
- package/dist/react/useAblo.js +1 -1
- package/dist/react/useCurrentUserId.js +1 -1
- package/dist/react/useErrorListener.js +1 -1
- package/dist/react/useMutationFailureListener.d.ts +2 -2
- package/dist/react/useMutationFailureListener.js +1 -1
- package/dist/react/useMutators.d.ts +3 -3
- package/dist/react/useMutators.js +3 -3
- package/dist/react/useUndoScope.d.ts +5 -5
- package/dist/react/useUndoScope.js +1 -1
- package/dist/schema/coordination.d.ts +69 -10
- package/dist/schema/coordination.js +86 -9
- package/dist/schema/ddl.js +2 -2
- package/dist/schema/diff.d.ts +1 -1
- package/dist/schema/generate.js +1 -1
- package/dist/schema/index.d.ts +10 -10
- package/dist/schema/index.js +18 -18
- package/dist/schema/queries.d.ts +27 -27
- package/dist/schema/queries.js +23 -23
- package/dist/schema/select.d.ts +3 -3
- package/dist/schema/select.js +3 -3
- package/dist/schema/serialize.d.ts +15 -6
- package/dist/schema/serialize.js +17 -3
- package/dist/schema/sugar.d.ts +6 -7
- package/dist/schema/sugar.js +9 -12
- package/dist/schema/syncDeltaRow.d.ts +4 -152
- package/dist/schema/syncDeltaRow.js +4 -105
- package/dist/server/adapter.d.ts +18 -1
- package/dist/server/commit.d.ts +10 -16
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/readConfig.d.ts +1 -1
- package/dist/source/adapters/drizzle.d.ts +1 -1
- package/dist/source/adapters/drizzle.js +2 -2
- package/dist/source/adapters/kysely.d.ts +1 -1
- package/dist/source/adapters/kysely.js +1 -1
- package/dist/source/adapters/kyselyMutationCore.d.ts +1 -1
- package/dist/source/adapters/kyselyMutationCore.js +2 -2
- package/dist/source/adapters/memory.js +1 -1
- package/dist/source/adapters/prisma.d.ts +8 -3
- package/dist/source/adapters/prisma.js +1 -1
- package/dist/source/connector.js +1 -1
- package/dist/source/connectorProtocol.d.ts +2 -8
- package/dist/source/connectorProtocol.js +3 -2
- package/dist/source/contract.d.ts +29 -17
- package/dist/source/contract.js +27 -22
- package/dist/source/factory.d.ts +1 -1
- package/dist/source/footprint.d.ts +111 -0
- package/dist/source/footprint.js +0 -0
- package/dist/source/idempotency.js +2 -2
- package/dist/source/index.d.ts +1 -0
- package/dist/source/index.js +3 -0
- package/dist/source/next.d.ts +1 -1
- package/dist/source/signing.d.ts +9 -2
- package/dist/source/signing.js +4 -1
- package/dist/source/types.d.ts +6 -4
- package/dist/source/types.js +1 -1
- package/dist/stores/ObjectStore.d.ts +1 -1
- package/dist/stores/SyncActionStore.d.ts +1 -1
- package/dist/stores/SyncActionStore.js +2 -10
- package/dist/stores/syncAction.d.ts +26 -0
- package/dist/stores/syncAction.js +16 -0
- package/dist/surface.d.ts +3 -3
- package/dist/surface.js +6 -4
- package/dist/sync/BootstrapFetcher.d.ts +123 -6
- package/dist/sync/BootstrapFetcher.js +492 -66
- package/dist/sync/ConnectionManager.d.ts +6 -198
- package/dist/sync/ConnectionManager.js +6 -677
- package/dist/sync/OnDemandLoader.d.ts +2 -2
- package/dist/sync/OnDemandLoader.js +60 -21
- package/dist/sync/SubscriptionManager.d.ts +13 -2
- package/dist/sync/SubscriptionManager.js +23 -5
- package/dist/sync/SyncWebSocket.d.ts +27 -510
- package/dist/sync/SyncWebSocket.js +76 -954
- package/dist/sync/awaitClaimGrant.d.ts +4 -44
- package/dist/sync/awaitClaimGrant.js +4 -109
- package/dist/sync/commitFrames.d.ts +6 -40
- package/dist/sync/commitFrames.js +6 -97
- package/dist/sync/contextPorts.d.ts +18 -0
- package/dist/sync/contextPorts.js +31 -0
- package/dist/sync/createClaimStream.d.ts +5 -49
- package/dist/sync/createClaimStream.js +5 -469
- package/dist/sync/createPresenceStream.d.ts +26 -4
- package/dist/sync/createPresenceStream.js +28 -20
- package/dist/sync/createSnapshot.d.ts +2 -2
- package/dist/sync/createSnapshot.js +1 -1
- package/dist/sync/credentialLifecycle.d.ts +5 -173
- package/dist/sync/credentialLifecycle.js +5 -320
- package/dist/sync/deltaPipeline.d.ts +1 -1
- package/dist/sync/participants.d.ts +5 -4
- package/dist/sync/participants.js +29 -22
- package/dist/sync/schemaDrift.d.ts +55 -0
- package/dist/sync/schemaDrift.js +53 -0
- package/dist/sync/schemas.d.ts +21 -32
- package/dist/sync/schemas.js +26 -17
- package/dist/sync/syncPlan.d.ts +3 -3
- package/dist/sync/wsFrameHandlers.d.ts +6 -114
- package/dist/sync/wsFrameHandlers.js +6 -392
- package/dist/testing/fixtures/bootstrap.d.ts +1 -1
- package/dist/testing/fixtures/deltas.d.ts +1 -1
- package/dist/testing/fixtures/httpResponses.d.ts +70 -0
- package/dist/testing/fixtures/httpResponses.js +90 -0
- package/dist/testing/fixtures/models.js +1 -1
- package/dist/testing/helpers/wait.js +1 -1
- package/dist/testing/mocks/MockMutationExecutor.d.ts +2 -2
- package/dist/testing/mocks/MockMutationExecutor.js +8 -14
- package/dist/testing/mocks/MockSyncContext.d.ts +11 -11
- package/dist/testing/mocks/MockSyncContext.js +10 -9
- package/dist/testing/mocks/MockSyncStore.js +1 -1
- package/dist/testing/mocks/MockWebSocket.d.ts +2 -2
- package/dist/transaction/ablo.d.ts +88 -0
- package/dist/transaction/ablo.js +33 -0
- package/dist/{client/auth.d.ts → transaction/auth/apiKey.d.ts} +43 -8
- package/dist/{client/auth.js → transaction/auth/apiKey.js} +19 -0
- package/dist/transaction/auth/bootstrapScope.d.ts +15 -0
- package/dist/transaction/auth/bootstrapScope.js +1 -0
- package/dist/transaction/auth/capability.d.ts +177 -0
- package/dist/transaction/auth/capability.js +199 -0
- package/dist/{auth → transaction/auth}/credentialSource.d.ts +8 -1
- package/dist/{client → transaction/auth}/identity.d.ts +8 -7
- package/dist/{client → transaction/auth}/identity.js +1 -1
- package/dist/transaction/auth/index.d.ts +162 -0
- package/dist/transaction/auth/index.js +304 -0
- package/dist/{auth → transaction/auth}/schemas.d.ts +1 -1
- package/dist/{auth → transaction/auth}/schemas.js +13 -13
- package/dist/{client → transaction/auth}/sessionMint.d.ts +8 -8
- package/dist/{client → transaction/auth}/sessionMint.js +4 -7
- package/dist/transaction/coordination/awaitClaimGrant.d.ts +49 -0
- package/dist/transaction/coordination/awaitClaimGrant.js +112 -0
- package/dist/transaction/coordination/claimMeta.d.ts +49 -0
- package/dist/transaction/coordination/claimMeta.js +52 -0
- package/dist/transaction/coordination/createClaimStream.d.ts +64 -0
- package/dist/transaction/coordination/createClaimStream.js +475 -0
- package/dist/transaction/coordination/events.d.ts +74 -0
- package/dist/transaction/coordination/events.js +7 -0
- package/dist/transaction/coordination/index.d.ts +19 -0
- package/dist/transaction/coordination/index.js +44 -0
- package/dist/transaction/coordination/locator.d.ts +83 -0
- package/dist/transaction/coordination/locator.js +82 -0
- package/dist/transaction/coordination/schema.d.ts +1473 -0
- package/dist/{coordination → transaction/coordination}/schema.js +490 -55
- package/dist/transaction/coordination/targetConflict.d.ts +2 -0
- package/dist/transaction/coordination/targetConflict.js +103 -0
- package/dist/{coordination → transaction/coordination}/trace.d.ts +7 -18
- package/dist/{coordination → transaction/coordination}/trace.js +18 -25
- package/dist/transaction/durableWrites.d.ts +62 -0
- package/dist/{client → transaction}/durableWrites.js +28 -3
- package/dist/transaction/environment.d.ts +105 -0
- package/dist/transaction/environment.js +108 -0
- package/dist/{errorCodes.d.ts → transaction/errorCodes.d.ts} +11 -11
- package/dist/{errorCodes.js → transaction/errorCodes.js} +35 -12
- package/dist/{errors.d.ts → transaction/errors.d.ts} +37 -13
- package/dist/{errors.js → transaction/errors.js} +85 -16
- package/dist/transaction/index.d.ts +20 -0
- package/dist/transaction/index.js +20 -0
- package/dist/transaction/keys/index.d.ts +87 -0
- package/dist/transaction/keys/index.js +207 -0
- package/dist/transaction/log/syncDeltaRow.d.ts +158 -0
- package/dist/transaction/log/syncDeltaRow.js +95 -0
- package/dist/{sync/syncPosition.d.ts → transaction/logPosition.d.ts} +22 -8
- package/dist/{sync/syncPosition.js → transaction/logPosition.js} +15 -6
- package/dist/transaction/logger.d.ts +16 -0
- package/dist/transaction/logger.js +7 -0
- package/dist/transaction/observability.d.ts +53 -0
- package/dist/transaction/observability.js +19 -0
- package/dist/transaction/plugin.d.ts +192 -0
- package/dist/transaction/plugin.js +87 -0
- package/dist/{policy → transaction/policy}/types.d.ts +3 -3
- package/dist/{policy → transaction/policy}/types.js +2 -0
- package/dist/transaction/resources/httpResources.d.ts +266 -0
- package/dist/transaction/resources/httpResources.js +7 -0
- package/dist/transaction/resources/modelOperations.d.ts +319 -0
- package/dist/transaction/resources/modelOperations.js +12 -0
- package/dist/transaction/resources/mutationOptions.d.ts +66 -0
- package/dist/transaction/resources/mutationOptions.js +9 -0
- package/dist/transaction/resources/where.d.ts +85 -0
- package/dist/transaction/resources/where.js +70 -0
- package/dist/{client → transaction/resources}/writeOptionsSchema.d.ts +2 -6
- package/dist/{client → transaction/resources}/writeOptionsSchema.js +9 -5
- package/dist/{schema → transaction/schema}/field.d.ts +5 -5
- package/dist/{schema → transaction/schema}/field.js +5 -5
- package/dist/transaction/schema/loadStrategy.d.ts +45 -0
- package/dist/transaction/schema/loadStrategy.js +46 -0
- package/dist/{schema → transaction/schema}/model.d.ts +50 -35
- package/dist/{schema → transaction/schema}/model.js +30 -20
- package/dist/transaction/schema/openapi.d.ts +57 -0
- package/dist/transaction/schema/openapi.js +340 -0
- package/dist/{schema → transaction/schema}/relation.d.ts +14 -14
- package/dist/{schema → transaction/schema}/relation.js +7 -7
- package/dist/{schema → transaction/schema}/residency.d.ts +0 -9
- package/dist/{schema → transaction/schema}/residency.js +0 -5
- package/dist/{schema → transaction/schema}/roles.d.ts +5 -5
- package/dist/{schema → transaction/schema}/roles.js +5 -5
- package/dist/{schema → transaction/schema}/schema.d.ts +12 -10
- package/dist/{schema → transaction/schema}/schema.js +4 -3
- package/dist/{schema → transaction/schema}/tenancy.d.ts +1 -1
- package/dist/{schema → transaction/schema}/tenancy.js +7 -4
- package/dist/transaction/transactionLayer.d.ts +82 -0
- package/dist/transaction/transactionLayer.js +24 -0
- package/dist/{transactions → transaction/transactions/settlement}/commitEnvelope.d.ts +4 -5
- package/dist/{transactions → transaction/transactions/settlement}/commitEnvelope.js +9 -13
- package/dist/{transactions → transaction/transactions/settlement}/httpCommitEnvelope.d.ts +9 -2
- package/dist/{transactions → transaction/transactions/settlement}/httpCommitEnvelope.js +5 -9
- package/dist/{transactions/durableWriteStore.d.ts → transaction/transactions/settlement/pendingWrite.d.ts} +10 -36
- package/dist/transaction/transactions/settlement/pendingWrite.js +20 -0
- package/dist/transaction/transport/commitFrames.d.ts +90 -0
- package/dist/transaction/transport/commitFrames.js +134 -0
- package/dist/transaction/transport/connectionManager.d.ts +215 -0
- package/dist/transaction/transport/connectionManager.js +673 -0
- package/dist/transaction/transport/credentialLifecycle.d.ts +177 -0
- package/dist/transaction/transport/credentialLifecycle.js +324 -0
- package/dist/{sync → transaction/transport}/heartbeat.d.ts +3 -1
- package/dist/{sync → transaction/transport}/heartbeat.js +6 -4
- package/dist/{client → transaction/transport}/httpClient.d.ts +59 -16
- package/dist/{client → transaction/transport}/httpClient.js +5 -5
- package/dist/transaction/transport/httpOptions.d.ts +33 -0
- package/dist/transaction/transport/httpOptions.js +12 -0
- package/dist/{client → transaction/transport}/httpTransport.js +171 -85
- package/dist/{sync/NetworkProbe.d.ts → transaction/transport/networkProbe.d.ts} +7 -4
- package/dist/{sync/NetworkProbe.js → transaction/transport/networkProbe.js} +14 -13
- package/dist/transaction/transport/wsFrameHandlers.d.ts +128 -0
- package/dist/transaction/transport/wsFrameHandlers.js +429 -0
- package/dist/transaction/transport/wsTransport.d.ts +576 -0
- package/dist/transaction/transport/wsTransport.js +1017 -0
- package/dist/transaction/types/assertExact.d.ts +17 -0
- package/dist/transaction/types/assertExact.js +1 -0
- package/dist/{types → transaction/types}/global.d.ts +17 -2
- package/dist/{types → transaction/types}/global.js +2 -1
- package/dist/{types → transaction/types}/index.d.ts +14 -46
- package/dist/{types → transaction/types}/index.js +7 -16
- package/dist/{types → transaction/types}/streams.d.ts +63 -45
- package/dist/{utils → transaction/utils}/json.d.ts +18 -0
- package/dist/transaction/utils/json.js +276 -0
- package/dist/transaction/wire/accountResponses.d.ts +351 -0
- package/dist/transaction/wire/accountResponses.js +255 -0
- package/dist/transaction/wire/auth.d.ts +49 -0
- package/dist/transaction/wire/auth.js +57 -0
- package/dist/transaction/wire/claimEvent.d.ts +76 -0
- package/dist/transaction/wire/claimEvent.js +73 -0
- package/dist/transaction/wire/claims.d.ts +463 -0
- package/dist/transaction/wire/claims.js +229 -0
- package/dist/{wire → transaction/wire}/commit.d.ts +125 -193
- package/dist/{wire → transaction/wire}/commit.js +68 -47
- package/dist/{wire → transaction/wire}/delta.d.ts +66 -17
- package/dist/{wire → transaction/wire}/delta.js +37 -13
- package/dist/transaction/wire/errorEnvelope.d.ts +72 -0
- package/dist/{wire → transaction/wire}/errorEnvelope.js +36 -5
- package/dist/transaction/wire/feedCursor.d.ts +60 -0
- package/dist/transaction/wire/feedCursor.js +82 -0
- package/dist/transaction/wire/feedEvent.d.ts +177 -0
- package/dist/transaction/wire/feedEvent.js +39 -0
- package/dist/transaction/wire/frames.d.ts +194 -0
- package/dist/transaction/wire/frames.js +50 -0
- package/dist/transaction/wire/inboundFrames.d.ts +552 -0
- package/dist/transaction/wire/inboundFrames.js +116 -0
- package/dist/transaction/wire/index.d.ts +50 -0
- package/dist/transaction/wire/index.js +74 -0
- package/dist/{wire → transaction/wire}/listEnvelope.d.ts +13 -14
- package/dist/transaction/wire/listEnvelope.js +42 -0
- package/dist/transaction/wire/modelResponses.d.ts +85 -0
- package/dist/transaction/wire/modelResponses.js +43 -0
- package/dist/transactions/{TransactionQueue.d.ts → mutations/MutationQueue.d.ts} +79 -38
- package/dist/transactions/{TransactionQueue.js → mutations/MutationQueue.js} +110 -59
- package/dist/transactions/{TransactionStore.d.ts → mutations/MutationStore.d.ts} +8 -8
- package/dist/transactions/{TransactionStore.js → mutations/MutationStore.js} +2 -2
- package/dist/transactions/{coalesceRules.d.ts → mutations/coalesceRules.d.ts} +10 -10
- package/dist/transactions/{coalesceRules.js → mutations/coalesceRules.js} +1 -1
- package/dist/transactions/mutations/commitLatency.d.ts +52 -0
- package/dist/transactions/mutations/commitLatency.js +130 -0
- package/dist/transactions/{commitOutboxStore.d.ts → mutations/commitOutboxStore.d.ts} +1 -5
- package/dist/transactions/{commitOutboxStore.js → mutations/commitOutboxStore.js} +1 -1
- package/dist/transactions/{commitPayload.d.ts → mutations/commitPayload.d.ts} +16 -15
- package/dist/transactions/{commitPayload.js → mutations/commitPayload.js} +12 -12
- package/dist/transactions/{deltaConfirmation.d.ts → mutations/deltaConfirmation.d.ts} +11 -11
- package/dist/transactions/{deltaConfirmation.js → mutations/deltaConfirmation.js} +7 -7
- package/dist/transactions/mutations/durableWriteStore.d.ts +14 -0
- package/dist/transactions/mutations/durableWriteStore.js +12 -0
- package/dist/transactions/{optimisticApply.d.ts → mutations/optimisticApply.d.ts} +7 -7
- package/dist/transactions/{replayValidation.d.ts → mutations/replayValidation.d.ts} +3 -3
- package/dist/transactions/{replayValidation.js → mutations/replayValidation.js} +4 -3
- package/dist/utils/mobxSetup.d.ts +1 -1
- package/dist/utils/mobxSetup.js +5 -2
- package/dist/webhooks/events.d.ts +2 -2
- package/dist/wire/index.d.ts +1 -34
- package/dist/wire/index.js +8 -49
- package/docs/agent-messaging.md +3 -3
- package/docs/agents.md +19 -12
- package/docs/api-keys.md +8 -4
- package/docs/api.md +22 -18
- package/docs/audit.md +2 -0
- package/docs/cli.md +31 -3
- package/docs/client-behavior.md +8 -6
- package/docs/concurrency-convention.md +30 -24
- package/docs/coordination.md +48 -38
- package/docs/data-sources.md +3 -1
- package/docs/debugging.md +5 -3
- package/docs/deployment.md +267 -0
- package/docs/examples/agent-human.md +49 -42
- package/docs/examples/ai-sdk-tool.md +69 -44
- package/docs/examples/existing-python-backend.md +8 -6
- package/docs/examples/nextjs.md +129 -47
- package/docs/examples/scoped-agent.md +45 -44
- package/docs/examples/server-agent.md +46 -26
- package/docs/groups.md +32 -29
- package/docs/guarantees.md +4 -2
- package/docs/how-it-works.md +9 -7
- package/docs/idempotency.md +126 -0
- package/docs/identity.md +58 -54
- package/docs/index.md +172 -84
- package/docs/integration-guide.md +17 -16
- package/docs/interaction-model.md +6 -4
- package/docs/mcp.md +41 -16
- package/docs/migration.md +63 -5
- package/docs/operating-on-your-database.md +111 -0
- package/docs/projects.md +2 -0
- package/docs/quickstart.md +22 -5
- package/docs/react.md +12 -10
- package/docs/schema-contract.md +5 -3
- package/docs/session-settings.md +108 -0
- package/docs/sessions.md +3 -1
- package/docs/webhooks.md +3 -1
- package/llms.txt +47 -17
- package/package.json +10 -8
- package/dist/agent/Agent.d.ts +0 -366
- package/dist/agent/Agent.js +0 -514
- package/dist/agent/index.d.ts +0 -115
- package/dist/agent/index.js +0 -128
- package/dist/agent/session.d.ts +0 -93
- package/dist/agent/session.js +0 -149
- package/dist/agent/types.d.ts +0 -68
- package/dist/agent/types.js +0 -9
- package/dist/client/durableWrites.d.ts +0 -21
- package/dist/coordination/schema.d.ts +0 -722
- package/dist/schema/openapi.d.ts +0 -29
- package/dist/schema/openapi.js +0 -124
- package/dist/transactions/durableWriteStore.js +0 -30
- package/dist/utils/json.js +0 -88
- package/dist/wire/errorEnvelope.d.ts +0 -55
- package/dist/wire/frames.d.ts +0 -197
- package/dist/wire/frames.js +0 -49
- package/dist/wire/listEnvelope.js +0 -18
- /package/dist/{client → transaction/auth}/credentialEndpoint.d.ts +0 -0
- /package/dist/{client → transaction/auth}/credentialEndpoint.js +0 -0
- /package/dist/{auth → transaction/auth}/credentialPolicy.d.ts +0 -0
- /package/dist/{auth → transaction/auth}/credentialPolicy.js +0 -0
- /package/dist/{auth → transaction/auth}/credentialSource.js +0 -0
- /package/dist/{client → transaction/auth}/hostedEndpoints.d.ts +0 -0
- /package/dist/{client → transaction/auth}/hostedEndpoints.js +0 -0
- /package/dist/{client → transaction/coordination}/claimHeartbeatLoop.d.ts +0 -0
- /package/dist/{client → transaction/coordination}/claimHeartbeatLoop.js +0 -0
- /package/dist/{client → transaction}/persistence.d.ts +0 -0
- /package/dist/{client → transaction}/persistence.js +0 -0
- /package/dist/{client → transaction/resources}/functionalUpdate.d.ts +0 -0
- /package/dist/{client → transaction/resources}/functionalUpdate.js +0 -0
- /package/dist/{transactions → transaction/transactions/settlement}/idempotencyKey.d.ts +0 -0
- /package/dist/{transactions → transaction/transactions/settlement}/idempotencyKey.js +0 -0
- /package/dist/{client → transaction/transport}/httpTransport.d.ts +0 -0
- /package/dist/{types → transaction/types}/modelData.d.ts +0 -0
- /package/dist/{types → transaction/types}/modelData.js +0 -0
- /package/dist/{types → transaction/types}/participant.d.ts +0 -0
- /package/dist/{types → transaction/types}/participant.js +0 -0
- /package/dist/{types → transaction/types}/streams.js +0 -0
- /package/dist/{utils → transaction/utils}/asyncIterator.d.ts +0 -0
- /package/dist/{utils → transaction/utils}/asyncIterator.js +0 -0
- /package/dist/{utils → transaction/utils}/duration.d.ts +0 -0
- /package/dist/{utils → transaction/utils}/duration.js +0 -0
- /package/dist/{wire → transaction/wire}/bootstrapReason.d.ts +0 -0
- /package/dist/{wire → transaction/wire}/bootstrapReason.js +0 -0
- /package/dist/{wire → transaction/wire}/protocol.d.ts +0 -0
- /package/dist/{wire → transaction/wire}/protocol.js +0 -0
- /package/dist/{wire → transaction/wire}/protocolVersion.d.ts +0 -0
- /package/dist/{wire → transaction/wire}/protocolVersion.js +0 -0
- /package/dist/transactions/{UnconfirmedWrites.d.ts → mutations/UnconfirmedWrites.d.ts} +0 -0
- /package/dist/transactions/{UnconfirmedWrites.js → mutations/UnconfirmedWrites.js} +0 -0
- /package/dist/transactions/{optimisticApply.js → mutations/optimisticApply.js} +0 -0
|
@@ -59,8 +59,8 @@
|
|
|
59
59
|
*/
|
|
60
60
|
import type { z } from 'zod';
|
|
61
61
|
import type { ClaimParams, ModelRetrieveParams, ModelUpdateParams } from '../client/createModelProxy.js';
|
|
62
|
-
import type { ModelUpdater, ContentionOptions } from '../
|
|
63
|
-
import type { HeldClaim } from '../types/streams.js';
|
|
62
|
+
import type { ModelUpdater, ContentionOptions } from '../transaction/resources/functionalUpdate.js';
|
|
63
|
+
import type { HeldClaim } from '../transaction/types/streams.js';
|
|
64
64
|
export type CoordinationStrategy = 'merge' | 'claim' | 'queue';
|
|
65
65
|
/** The structured result the tool hands back to the model (or the caller). */
|
|
66
66
|
export interface CoordinatedWriteResult<T> {
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
* first-in-first-out, which would require a persistent connection.
|
|
59
59
|
*/
|
|
60
60
|
import { tool } from 'ai';
|
|
61
|
-
import { AbloClaimedError, AbloNotFoundError } from '../errors.js';
|
|
61
|
+
import { AbloClaimedError, AbloNotFoundError } from '../transaction/errors.js';
|
|
62
62
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
63
63
|
export function coordinatedTool(model, options) {
|
|
64
64
|
const strategy = options.strategy ?? 'merge';
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
*/
|
|
19
19
|
import type { LanguageModelV3Middleware } from '@ai-sdk/provider';
|
|
20
20
|
import type { Ablo } from '../client/Ablo.js';
|
|
21
|
-
import type { SchemaRecord } from '../schema/schema.js';
|
|
22
|
-
import type { ClaimTarget } from '../types/streams.js';
|
|
21
|
+
import type { SchemaRecord } from '../transaction/schema/schema.js';
|
|
22
|
+
import type { ClaimTarget } from '../transaction/types/streams.js';
|
|
23
23
|
export type { ClaimTarget };
|
|
24
24
|
export interface CoordinationContextMiddlewareOptions<R extends SchemaRecord = SchemaRecord> {
|
|
25
25
|
readonly agent: Ablo<R> | null;
|
|
@@ -35,7 +35,7 @@ export function coordinationContextMiddleware(options) {
|
|
|
35
35
|
// Look up peer claims on the same target. This reads the agent's reactive
|
|
36
36
|
// `claims.others` array in memory, with no I/O. The type is compared
|
|
37
37
|
// case-insensitively: observed claims carry a lowercased type name (such as
|
|
38
|
-
// `
|
|
38
|
+
// `report`) while callers write the schema's type name (`Report`).
|
|
39
39
|
const wantedType = target.type.toLowerCase();
|
|
40
40
|
const peerClaims = agent.claims.others.filter((claim) => claim.target.type.toLowerCase() === wantedType &&
|
|
41
41
|
claim.target.id === target.id &&
|
package/dist/ai-sdk/wrap.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Tool implementations do not change. Keep tools as normal AI SDK tools; use
|
|
5
5
|
* `ablo.<model>.update({ id, data, claim })` inside `execute`. This wrapper is
|
|
6
6
|
* only for the surrounding model call, when the UI already knows "this turn is
|
|
7
|
-
* about
|
|
7
|
+
* about report_abc" before the model chooses a tool.
|
|
8
8
|
*
|
|
9
9
|
* It declares one realtime claim while the model is generating and injects a
|
|
10
10
|
* short note if someone else is already working on the same target.
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* const wrapped = wrapWithMultiplayer({
|
|
14
14
|
* model: anthropic('claude-opus-4-7'),
|
|
15
15
|
* agent,
|
|
16
|
-
* target: { type: '
|
|
16
|
+
* target: { type: 'Report', id: 'report-abc' },
|
|
17
17
|
* });
|
|
18
18
|
*
|
|
19
19
|
* const result = streamText({
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
import { wrapLanguageModel } from 'ai';
|
|
29
29
|
import type { LanguageModelV3, LanguageModelV3Middleware } from '@ai-sdk/provider';
|
|
30
30
|
import type { Ablo } from '../client/Ablo.js';
|
|
31
|
-
import type { SchemaRecord } from '../schema/schema.js';
|
|
31
|
+
import type { SchemaRecord } from '../transaction/schema/schema.js';
|
|
32
32
|
import { type ClaimTarget } from './coordinationContext.js';
|
|
33
33
|
export interface WrapWithMultiplayerOptions<R extends SchemaRecord = SchemaRecord> {
|
|
34
34
|
/** The base language model to wrap. Consumer brings their own. */
|
package/dist/ai-sdk/wrap.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Tool implementations do not change. Keep tools as normal AI SDK tools; use
|
|
5
5
|
* `ablo.<model>.update({ id, data, claim })` inside `execute`. This wrapper is
|
|
6
6
|
* only for the surrounding model call, when the UI already knows "this turn is
|
|
7
|
-
* about
|
|
7
|
+
* about report_abc" before the model chooses a tool.
|
|
8
8
|
*
|
|
9
9
|
* It declares one realtime claim while the model is generating and injects a
|
|
10
10
|
* short note if someone else is already working on the same target.
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* const wrapped = wrapWithMultiplayer({
|
|
14
14
|
* model: anthropic('claude-opus-4-7'),
|
|
15
15
|
* agent,
|
|
16
|
-
* target: { type: '
|
|
16
|
+
* target: { type: 'Report', id: 'report-abc' },
|
|
17
17
|
* });
|
|
18
18
|
*
|
|
19
19
|
* const result = streamText({
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,156 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Exchanges an API key for a capability token and the scope it grants.
|
|
3
|
-
*
|
|
4
|
-
* The `Ablo({...})` factory calls this during startup when you provide an
|
|
5
|
-
* `apiKey` but no explicit capability token, organization, or user identity. It
|
|
6
|
-
* sends one `POST /auth/capability` request; the server responds with the
|
|
7
|
-
* granted scope and any user metadata, which the client uses to populate its
|
|
8
|
-
* session state. The API key is the only credential you handle directly — this
|
|
9
|
-
* exchange happens automatically behind it.
|
|
10
|
-
*/
|
|
11
|
-
import { type CapabilityExchangeResponse, type EphemeralKeyResponse, type IdentityResolveResponse } from './schemas.js';
|
|
12
|
-
export type { CapabilityExchangeResponse, EphemeralKeyResponse, IdentityResolveResponse, } from './schemas.js';
|
|
13
|
-
export interface ExchangeApiKeyRequest {
|
|
14
|
-
readonly apiKey: string;
|
|
15
|
-
readonly baseUrl: string;
|
|
16
|
-
readonly participantKind: 'user' | 'agent' | 'system';
|
|
17
|
-
readonly participantId?: string;
|
|
18
|
-
readonly syncGroups?: readonly string[];
|
|
19
|
-
readonly operations?: readonly string[];
|
|
20
|
-
readonly ttlSeconds: number;
|
|
21
|
-
readonly label?: string;
|
|
22
|
-
readonly userMeta?: Record<string, unknown>;
|
|
23
|
-
readonly fetch?: typeof fetch;
|
|
24
|
-
readonly timeoutMs?: number;
|
|
25
|
-
}
|
|
26
|
-
export declare function exchangeApiKey(options: ExchangeApiKeyRequest): Promise<CapabilityExchangeResponse>;
|
|
27
|
-
export interface MintUserSessionRequest {
|
|
28
|
-
/** Your secret API key (an `sk_` key). Minting a session is a server-side
|
|
29
|
-
* operation, so it always presents the secret key, never a token derived
|
|
30
|
-
* from it. */
|
|
31
|
-
readonly apiKey: string;
|
|
32
|
-
readonly baseUrl: string;
|
|
33
|
-
/** The end user's identifier in your identity provider. It becomes the
|
|
34
|
-
* session's `participantId`. */
|
|
35
|
-
readonly userId: string;
|
|
36
|
-
/** The organization to mint the session into, for a platform that manages many
|
|
37
|
-
* organizations. Requires the secret key to carry the `ephemeral:mint-any-org`
|
|
38
|
-
* capability. Omit to mint into the key's own organization. */
|
|
39
|
-
readonly organizationId?: string;
|
|
40
|
-
/** Points this session's schema at a shared project while its data stays scoped
|
|
41
|
-
* to `organizationId`. Use this when each customer has its own organization but
|
|
42
|
-
* they all share one schema: keep a single schema project, and every customer's
|
|
43
|
-
* session resolves its schema from it instead of pushing the schema into each
|
|
44
|
-
* organization separately. Requires the secret key to carry the
|
|
45
|
-
* `ephemeral:mint-any-org` capability. Omit to resolve the schema from the
|
|
46
|
-
* session's own organization. */
|
|
47
|
-
readonly schemaProject?: {
|
|
48
|
-
/** The organization that owns the shared schema project. */
|
|
49
|
-
readonly organizationId: string;
|
|
50
|
-
/** The project the schema was pushed under. */
|
|
51
|
-
readonly projectId: string;
|
|
52
|
-
};
|
|
53
|
-
readonly syncGroups?: readonly string[];
|
|
54
|
-
readonly ttlSeconds: number;
|
|
55
|
-
readonly label?: string;
|
|
56
|
-
readonly fetch?: typeof fetch;
|
|
57
|
-
readonly timeoutMs?: number;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Mints an end-user session key (an `ek_` key) by calling
|
|
61
|
-
* `POST /auth/ephemeral-keys`, using your secret key as authorization. Your
|
|
62
|
-
* backend calls this to issue a session that a browser can present as its bearer
|
|
63
|
-
* credential; the server trusts the resulting key because a secret key minted it.
|
|
64
|
-
*
|
|
65
|
-
* This is a distinct endpoint from `/auth/capability`, which exchanges keys for
|
|
66
|
-
* agents and systems and cannot mint sessions for human users.
|
|
67
|
-
*/
|
|
68
|
-
export declare function mintUserSessionKey(options: MintUserSessionRequest): Promise<EphemeralKeyResponse>;
|
|
69
|
-
export interface ResolveIdentityRequest {
|
|
70
|
-
readonly baseUrl: string;
|
|
71
|
-
readonly authToken?: string;
|
|
72
|
-
readonly fetch?: typeof fetch;
|
|
73
|
-
readonly timeoutMs?: number;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Resolves the caller's identity from an authenticated request by calling
|
|
77
|
-
* `GET /auth/identity`. This lets browser and session flows learn who the
|
|
78
|
-
* current user is without requiring the application to pass a user id up front —
|
|
79
|
-
* for example, to key local storage.
|
|
80
|
-
*/
|
|
81
|
-
export declare function resolveIdentity(options: ResolveIdentityRequest): Promise<IdentityResolveResponse>;
|
|
82
|
-
/**
|
|
83
|
-
* Keeps a capability token fresh so a long-lived client never disconnects when
|
|
84
|
-
* its token expires.
|
|
85
|
-
*
|
|
86
|
-
* A capability token has a shorter lifetime — one hour by default — than a
|
|
87
|
-
* typical browser session. Without a refresh, the WebSocket is force-closed at
|
|
88
|
-
* expiry (close code 1008) or the next reconnect fails with a 401, and either way
|
|
89
|
-
* the user sees a mid-session disconnect. The scheduler prevents that by
|
|
90
|
-
* re-minting the token ahead of time.
|
|
91
|
-
*
|
|
92
|
-
* Three triggers share one refresh path:
|
|
93
|
-
*
|
|
94
|
-
* 1. Proactive — a timer set for `expiresAtMs - bufferMs - now`.
|
|
95
|
-
* 2. Visibility — when a hidden tab becomes visible and the token is already
|
|
96
|
-
* within the buffer window, refresh immediately. This covers a
|
|
97
|
-
* background tab whose timers were throttled while it was idle.
|
|
98
|
-
* 3. Reactive — the caller invokes {@link RefreshScheduler.refreshNow} after
|
|
99
|
-
* observing an auth failure, such as a WebSocket close 1008 or
|
|
100
|
-
* 4001.
|
|
101
|
-
*
|
|
102
|
-
* All three await the same in-flight promise, so concurrent triggers mint the
|
|
103
|
-
* token only once. Each successful refresh records the new expiry and reschedules
|
|
104
|
-
* the proactive timer.
|
|
105
|
-
*
|
|
106
|
-
* The refresh margin is `max(60s, ttl/10)` — six minutes for a one-hour token,
|
|
107
|
-
* and it scales down for shorter lifetimes.
|
|
108
|
-
*/
|
|
109
|
-
export interface RefreshSchedulerOptions {
|
|
110
|
-
/** Initial absolute expiry, ms since epoch (server-supplied). */
|
|
111
|
-
readonly initialExpiresAtMs: number;
|
|
112
|
-
/**
|
|
113
|
-
* Performs the token exchange and returns the new expiry. Errors propagate to
|
|
114
|
-
* `onError`; the scheduler stays alive and retries on its next trigger. It does
|
|
115
|
-
* not back off between retries, since the common failure here is a revoked API
|
|
116
|
-
* key, for which retrying would not help.
|
|
117
|
-
*/
|
|
118
|
-
readonly refresh: () => Promise<{
|
|
119
|
-
expiresAtMs: number;
|
|
120
|
-
}>;
|
|
121
|
-
/** Called on every successful refresh. */
|
|
122
|
-
readonly onRefreshed?: (info: {
|
|
123
|
-
expiresAtMs: number;
|
|
124
|
-
}) => void;
|
|
125
|
-
/** Called on every refresh failure. */
|
|
126
|
-
readonly onError?: (error: Error) => void;
|
|
127
|
-
/**
|
|
128
|
-
* Override the buffer (ms ahead of expiry to refresh). Defaults to
|
|
129
|
-
* `max(60_000, ttlMs * 0.1)`. Tests use a tiny value to exercise
|
|
130
|
-
* scheduling without burning real time.
|
|
131
|
-
*/
|
|
132
|
-
readonly bufferMs?: number;
|
|
133
|
-
/**
|
|
134
|
-
* If true, install a `visibilitychange` listener on `document` that
|
|
135
|
-
* triggers a refresh when the tab becomes visible and the token is
|
|
136
|
-
* within the buffer window. No-op if `document` is undefined (Node).
|
|
137
|
-
* Default: true in browser environments.
|
|
138
|
-
*/
|
|
139
|
-
readonly attachVisibilityListener?: boolean;
|
|
140
|
-
/** Time source. Override in tests; defaults to `Date.now`. */
|
|
141
|
-
readonly now?: () => number;
|
|
142
|
-
/** Timer pair. Override in tests. */
|
|
143
|
-
readonly setTimer?: (fn: () => void, ms: number) => ReturnType<typeof setTimeout>;
|
|
144
|
-
readonly clearTimer?: (handle: ReturnType<typeof setTimeout>) => void;
|
|
145
|
-
}
|
|
146
|
-
export interface RefreshScheduler {
|
|
147
|
-
/** Force a refresh now. Idempotent — concurrent calls share one promise. */
|
|
148
|
-
refreshNow(): Promise<{
|
|
149
|
-
expiresAtMs: number;
|
|
150
|
-
}>;
|
|
151
|
-
/** Stop scheduling. Safe to call multiple times. */
|
|
152
|
-
dispose(): void;
|
|
153
|
-
/** Current absolute expiry. Updated after each successful refresh. */
|
|
154
|
-
readonly expiresAtMs: number;
|
|
155
|
-
}
|
|
156
|
-
export declare function createRefreshScheduler(options: RefreshSchedulerOptions): RefreshScheduler;
|
|
1
|
+
export * from '../transaction/auth/index.js';
|
package/dist/auth/index.js
CHANGED
|
@@ -1,301 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
* exchange happens automatically behind it.
|
|
10
|
-
*/
|
|
11
|
-
import { parseCapabilityExchangeResponse, parseEphemeralKeyResponse, parseIdentityResolveResponse, } from './schemas.js';
|
|
12
|
-
import { AbloAuthenticationError, hasWireCode, translateHttpError } from '../errors.js';
|
|
13
|
-
export async function exchangeApiKey(options) {
|
|
14
|
-
if (!options.apiKey) {
|
|
15
|
-
throw new AbloAuthenticationError('No API key found. Set ABLO_API_KEY in your environment — `npx ablo login` ' +
|
|
16
|
-
'then `npx ablo dev` writes it into .env.local for you — or pass ' +
|
|
17
|
-
'`apiKey` to Ablo({ ... }) directly.', { code: 'apikey_missing' });
|
|
18
|
-
}
|
|
19
|
-
if (!options.baseUrl) {
|
|
20
|
-
throw new AbloAuthenticationError('baseUrl is required for capability exchange', { code: 'base_url_missing' });
|
|
21
|
-
}
|
|
22
|
-
const fetcher = options.fetch ?? fetch;
|
|
23
|
-
const url = `${options.baseUrl.replace(/\/+$/, '')}/auth/capability`;
|
|
24
|
-
const timeoutMs = options.timeoutMs ?? 10_000;
|
|
25
|
-
const controller = new AbortController();
|
|
26
|
-
const timer = setTimeout(() => { controller.abort(); }, timeoutMs);
|
|
27
|
-
let response;
|
|
28
|
-
try {
|
|
29
|
-
response = await fetcher(url, {
|
|
30
|
-
method: 'POST',
|
|
31
|
-
headers: {
|
|
32
|
-
'Content-Type': 'application/json',
|
|
33
|
-
Authorization: `Bearer ${options.apiKey}`,
|
|
34
|
-
},
|
|
35
|
-
body: JSON.stringify({
|
|
36
|
-
participantKind: options.participantKind,
|
|
37
|
-
...(options.participantId ? { participantId: options.participantId } : {}),
|
|
38
|
-
syncGroups: options.syncGroups,
|
|
39
|
-
operations: options.operations,
|
|
40
|
-
wideScope: options.wideScope,
|
|
41
|
-
ttlSeconds: options.ttlSeconds,
|
|
42
|
-
label: options.label,
|
|
43
|
-
userMeta: options.userMeta,
|
|
44
|
-
}),
|
|
45
|
-
signal: controller.signal,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
catch (err) {
|
|
49
|
-
throw new AbloAuthenticationError(`apiKey exchange failed: ${err instanceof Error ? err.message : String(err)}`, { code: 'exchange_network_error', cause: err });
|
|
50
|
-
}
|
|
51
|
-
finally {
|
|
52
|
-
clearTimeout(timer);
|
|
53
|
-
}
|
|
54
|
-
if (!response.ok) {
|
|
55
|
-
let body = null;
|
|
56
|
-
try {
|
|
57
|
-
body = await response.json();
|
|
58
|
-
}
|
|
59
|
-
catch {
|
|
60
|
-
// ignore — server returned non-JSON error
|
|
61
|
-
}
|
|
62
|
-
// Route the error through the wire-error translator so the server's envelope
|
|
63
|
-
// (`code`, `message`, `doc_url`) is preserved and mapped to the matching
|
|
64
|
-
// AbloError subclass. Fall back to `exchange_failed` only when the body
|
|
65
|
-
// carried no recognizable error code.
|
|
66
|
-
const requestId = response.headers.get('x-request-id') ?? undefined;
|
|
67
|
-
throw hasWireCode(body)
|
|
68
|
-
? translateHttpError(response.status, body, requestId)
|
|
69
|
-
: new AbloAuthenticationError(`apiKey exchange rejected (${response.status})`, { code: 'exchange_failed', httpStatus: response.status });
|
|
70
|
-
}
|
|
71
|
-
return parseCapabilityExchangeResponse(await response.json());
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Mints an end-user session key (an `ek_` key) by calling
|
|
75
|
-
* `POST /auth/ephemeral-keys`, using your secret key as authorization. Your
|
|
76
|
-
* backend calls this to issue a session that a browser can present as its bearer
|
|
77
|
-
* credential; the server trusts the resulting key because a secret key minted it.
|
|
78
|
-
*
|
|
79
|
-
* This is a distinct endpoint from `/auth/capability`, which exchanges keys for
|
|
80
|
-
* agents and systems and cannot mint sessions for human users.
|
|
81
|
-
*/
|
|
82
|
-
export async function mintUserSessionKey(options) {
|
|
83
|
-
if (!options.apiKey) {
|
|
84
|
-
throw new AbloAuthenticationError('No API key found. Set ABLO_API_KEY in your environment or pass `apiKey` ' +
|
|
85
|
-
'to Ablo({ ... }) directly — user sessions are minted by your backend.', { code: 'apikey_missing' });
|
|
86
|
-
}
|
|
87
|
-
if (!options.baseUrl) {
|
|
88
|
-
throw new AbloAuthenticationError('baseUrl is required for user-session mint', { code: 'base_url_missing' });
|
|
89
|
-
}
|
|
90
|
-
const fetcher = options.fetch ?? fetch;
|
|
91
|
-
const url = `${options.baseUrl.replace(/\/+$/, '')}/auth/ephemeral-keys`;
|
|
92
|
-
const timeoutMs = options.timeoutMs ?? 10_000;
|
|
93
|
-
const controller = new AbortController();
|
|
94
|
-
const timer = setTimeout(() => { controller.abort(); }, timeoutMs);
|
|
95
|
-
let response;
|
|
96
|
-
try {
|
|
97
|
-
response = await fetcher(url, {
|
|
98
|
-
method: 'POST',
|
|
99
|
-
headers: {
|
|
100
|
-
'Content-Type': 'application/json',
|
|
101
|
-
Authorization: `Bearer ${options.apiKey}`,
|
|
102
|
-
},
|
|
103
|
-
body: JSON.stringify({
|
|
104
|
-
user: { id: options.userId },
|
|
105
|
-
...(options.organizationId ? { organizationId: options.organizationId } : {}),
|
|
106
|
-
// The public option is project-centric; map it to the flat wire keys the
|
|
107
|
-
// endpoint expects.
|
|
108
|
-
...(options.schemaProject
|
|
109
|
-
? {
|
|
110
|
-
schemaProjectId: options.schemaProject.projectId,
|
|
111
|
-
schemaOwnerOrgId: options.schemaProject.organizationId,
|
|
112
|
-
}
|
|
113
|
-
: {}),
|
|
114
|
-
...(options.syncGroups ? { syncGroups: options.syncGroups } : {}),
|
|
115
|
-
ttlSeconds: options.ttlSeconds,
|
|
116
|
-
...(options.label ? { label: options.label } : {}),
|
|
117
|
-
}),
|
|
118
|
-
signal: controller.signal,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
catch (err) {
|
|
122
|
-
throw new AbloAuthenticationError(`user-session mint failed: ${err instanceof Error ? err.message : String(err)}`, { code: 'exchange_network_error', cause: err });
|
|
123
|
-
}
|
|
124
|
-
finally {
|
|
125
|
-
clearTimeout(timer);
|
|
126
|
-
}
|
|
127
|
-
if (!response.ok) {
|
|
128
|
-
let body = null;
|
|
129
|
-
try {
|
|
130
|
-
body = await response.json();
|
|
131
|
-
}
|
|
132
|
-
catch {
|
|
133
|
-
// ignore — server returned non-JSON error
|
|
134
|
-
}
|
|
135
|
-
const requestId = response.headers.get('x-request-id') ?? undefined;
|
|
136
|
-
throw hasWireCode(body)
|
|
137
|
-
? translateHttpError(response.status, body, requestId)
|
|
138
|
-
: new AbloAuthenticationError(`user-session mint rejected (${response.status})`, { code: 'exchange_failed', httpStatus: response.status });
|
|
139
|
-
}
|
|
140
|
-
return parseEphemeralKeyResponse(await response.json());
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Resolves the caller's identity from an authenticated request by calling
|
|
144
|
-
* `GET /auth/identity`. This lets browser and session flows learn who the
|
|
145
|
-
* current user is without requiring the application to pass a user id up front —
|
|
146
|
-
* for example, to key local storage.
|
|
147
|
-
*/
|
|
148
|
-
export async function resolveIdentity(options) {
|
|
149
|
-
if (!options.baseUrl) {
|
|
150
|
-
throw new AbloAuthenticationError('baseUrl is required for identity resolve', {
|
|
151
|
-
code: 'base_url_missing',
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
const fetcher = options.fetch ?? fetch;
|
|
155
|
-
const url = `${options.baseUrl.replace(/\/+$/, '')}/auth/identity`;
|
|
156
|
-
const timeoutMs = options.timeoutMs ?? 10_000;
|
|
157
|
-
const controller = new AbortController();
|
|
158
|
-
const timer = setTimeout(() => { controller.abort(); }, timeoutMs);
|
|
159
|
-
let response;
|
|
160
|
-
try {
|
|
161
|
-
const headers = { Accept: 'application/json' };
|
|
162
|
-
if (options.authToken) {
|
|
163
|
-
headers.Authorization = `Bearer ${options.authToken}`;
|
|
164
|
-
}
|
|
165
|
-
response = await fetcher(url, {
|
|
166
|
-
method: 'GET',
|
|
167
|
-
headers,
|
|
168
|
-
signal: controller.signal,
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
catch (err) {
|
|
172
|
-
throw new AbloAuthenticationError(`identity resolve failed: ${err instanceof Error ? err.message : String(err)}`, { code: 'identity_network_error', cause: err });
|
|
173
|
-
}
|
|
174
|
-
finally {
|
|
175
|
-
clearTimeout(timer);
|
|
176
|
-
}
|
|
177
|
-
if (!response.ok) {
|
|
178
|
-
let body = null;
|
|
179
|
-
try {
|
|
180
|
-
body = await response.json();
|
|
181
|
-
}
|
|
182
|
-
catch {
|
|
183
|
-
// ignore non-JSON auth errors
|
|
184
|
-
}
|
|
185
|
-
// Translate the error envelope the same way `exchangeApiKey` does, so the
|
|
186
|
-
// server's precise auth diagnosis (for example `jwt_issuer_untrusted` with
|
|
187
|
-
// its full message) reaches the caller instead of collapsing every 401 to a
|
|
188
|
-
// generic `identity_resolve_failed`.
|
|
189
|
-
const requestId = response.headers.get('x-request-id') ?? undefined;
|
|
190
|
-
throw hasWireCode(body)
|
|
191
|
-
? translateHttpError(response.status, body, requestId)
|
|
192
|
-
: new AbloAuthenticationError(`identity resolve rejected (${response.status})`, { code: 'identity_resolve_failed', httpStatus: response.status });
|
|
193
|
-
}
|
|
194
|
-
return parseIdentityResolveResponse(await response.json());
|
|
195
|
-
}
|
|
196
|
-
const DEFAULT_BUFFER_FLOOR_MS = 60_000;
|
|
197
|
-
const DEFAULT_BUFFER_RATIO = 0.1;
|
|
198
|
-
export function createRefreshScheduler(options) {
|
|
199
|
-
const now = options.now ?? Date.now;
|
|
200
|
-
const setTimer = options.setTimer ?? setTimeout;
|
|
201
|
-
const clearTimer = options.clearTimer ?? clearTimeout;
|
|
202
|
-
let expiresAtMs = options.initialExpiresAtMs;
|
|
203
|
-
let timer = null;
|
|
204
|
-
let inFlight = null;
|
|
205
|
-
let disposed = false;
|
|
206
|
-
// Attach the visibility listener only in a browser-like environment. A
|
|
207
|
-
// non-browser runtime has no `document`, so the default behaves correctly
|
|
208
|
-
// without an explicit opt-out.
|
|
209
|
-
const wantsVisibility = options.attachVisibilityListener ?? true;
|
|
210
|
-
const hasDocument = typeof document !== 'undefined';
|
|
211
|
-
const visibilityActive = wantsVisibility && hasDocument;
|
|
212
|
-
function bufferFor(currentExpiresAtMs) {
|
|
213
|
-
if (typeof options.bufferMs === 'number')
|
|
214
|
-
return options.bufferMs;
|
|
215
|
-
const ttl = currentExpiresAtMs - now();
|
|
216
|
-
return Math.max(DEFAULT_BUFFER_FLOOR_MS, Math.floor(ttl * DEFAULT_BUFFER_RATIO));
|
|
217
|
-
}
|
|
218
|
-
function clearTimerIfAny() {
|
|
219
|
-
if (timer !== null) {
|
|
220
|
-
clearTimer(timer);
|
|
221
|
-
timer = null;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
function schedule() {
|
|
225
|
-
if (disposed)
|
|
226
|
-
return;
|
|
227
|
-
clearTimerIfAny();
|
|
228
|
-
const buffer = bufferFor(expiresAtMs);
|
|
229
|
-
const delay = Math.max(0, expiresAtMs - buffer - now());
|
|
230
|
-
timer = setTimer(() => {
|
|
231
|
-
void refreshNow().catch(() => {
|
|
232
|
-
// onError already fired inside refreshNow; swallow here so
|
|
233
|
-
// the timer callback doesn't surface as an unhandled rejection.
|
|
234
|
-
});
|
|
235
|
-
}, delay);
|
|
236
|
-
}
|
|
237
|
-
function refreshNow() {
|
|
238
|
-
if (disposed) {
|
|
239
|
-
return Promise.reject(new Error('refreshScheduler: disposed'));
|
|
240
|
-
}
|
|
241
|
-
if (inFlight)
|
|
242
|
-
return inFlight;
|
|
243
|
-
inFlight = (async () => {
|
|
244
|
-
try {
|
|
245
|
-
const result = await options.refresh();
|
|
246
|
-
if (disposed)
|
|
247
|
-
return result;
|
|
248
|
-
expiresAtMs = result.expiresAtMs;
|
|
249
|
-
options.onRefreshed?.({ expiresAtMs });
|
|
250
|
-
schedule();
|
|
251
|
-
return result;
|
|
252
|
-
}
|
|
253
|
-
catch (err) {
|
|
254
|
-
const error = err instanceof Error ? err : new Error(String(err));
|
|
255
|
-
options.onError?.(error);
|
|
256
|
-
// Reschedule even on failure so the next window still triggers.
|
|
257
|
-
// The user's apiKey may have been temporarily unreachable.
|
|
258
|
-
if (!disposed)
|
|
259
|
-
schedule();
|
|
260
|
-
throw error;
|
|
261
|
-
}
|
|
262
|
-
finally {
|
|
263
|
-
inFlight = null;
|
|
264
|
-
}
|
|
265
|
-
})();
|
|
266
|
-
return inFlight;
|
|
267
|
-
}
|
|
268
|
-
function onVisibilityChange() {
|
|
269
|
-
if (disposed)
|
|
270
|
-
return;
|
|
271
|
-
if (typeof document === 'undefined')
|
|
272
|
-
return;
|
|
273
|
-
if (document.visibilityState !== 'visible')
|
|
274
|
-
return;
|
|
275
|
-
const buffer = bufferFor(expiresAtMs);
|
|
276
|
-
if (expiresAtMs - now() <= buffer) {
|
|
277
|
-
void refreshNow().catch(() => {
|
|
278
|
-
// already routed through onError
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
if (visibilityActive) {
|
|
283
|
-
document.addEventListener('visibilitychange', onVisibilityChange);
|
|
284
|
-
}
|
|
285
|
-
schedule();
|
|
286
|
-
return {
|
|
287
|
-
refreshNow,
|
|
288
|
-
dispose() {
|
|
289
|
-
if (disposed)
|
|
290
|
-
return;
|
|
291
|
-
disposed = true;
|
|
292
|
-
clearTimerIfAny();
|
|
293
|
-
if (visibilityActive) {
|
|
294
|
-
document.removeEventListener('visibilitychange', onVisibilityChange);
|
|
295
|
-
}
|
|
296
|
-
},
|
|
297
|
-
get expiresAtMs() {
|
|
298
|
-
return expiresAtMs;
|
|
299
|
-
},
|
|
300
|
-
};
|
|
301
|
-
}
|
|
1
|
+
// Moved to @ablo/transaction (ADR 0013 — the settlement core extraction).
|
|
2
|
+
// This shim re-exports it at the original path so in-package importers of
|
|
3
|
+
// `auth/index.js` keep working; rewire to `@ablo/transaction/auth`
|
|
4
|
+
// and delete this shim once the core package is fully wired.
|
|
5
|
+
//
|
|
6
|
+
// Line comments on purpose: tsc copies a leading JSDoc block into the
|
|
7
|
+
// published `.d.ts`, and this note names a package npm has never heard of.
|
|
8
|
+
export * from '../transaction/auth/index.js';
|