@drakkar.software/octobot-client 0.4.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/README.md +140 -0
- package/dist/client/adapters/accounts.d.ts +66 -0
- package/dist/client/adapters/accounts.d.ts.map +1 -0
- package/dist/client/adapters/accounts.js +214 -0
- package/dist/client/adapters/accounts.js.map +1 -0
- package/dist/client/adapters/actionHandle.d.ts +29 -0
- package/dist/client/adapters/actionHandle.d.ts.map +1 -0
- package/dist/client/adapters/actionHandle.js +34 -0
- package/dist/client/adapters/actionHandle.js.map +1 -0
- package/dist/client/adapters/automations.d.ts +31 -0
- package/dist/client/adapters/automations.d.ts.map +1 -0
- package/dist/client/adapters/automations.js +79 -0
- package/dist/client/adapters/automations.js.map +1 -0
- package/dist/client/adapters/documents.d.ts +55 -0
- package/dist/client/adapters/documents.d.ts.map +1 -0
- package/dist/client/adapters/documents.js +66 -0
- package/dist/client/adapters/documents.js.map +1 -0
- package/dist/client/adapters/nodeApi.d.ts +25 -0
- package/dist/client/adapters/nodeApi.d.ts.map +1 -0
- package/dist/client/adapters/nodeApi.js +81 -0
- package/dist/client/adapters/nodeApi.js.map +1 -0
- package/dist/client/adapters/settings.d.ts +16 -0
- package/dist/client/adapters/settings.d.ts.map +1 -0
- package/dist/client/adapters/settings.js +43 -0
- package/dist/client/adapters/settings.js.map +1 -0
- package/dist/client/adapters/strategies.d.ts +17 -0
- package/dist/client/adapters/strategies.d.ts.map +1 -0
- package/dist/client/adapters/strategies.js +75 -0
- package/dist/client/adapters/strategies.js.map +1 -0
- package/dist/client/connect/connect.d.ts +40 -0
- package/dist/client/connect/connect.d.ts.map +1 -0
- package/dist/client/connect/connect.js +133 -0
- package/dist/client/connect/connect.js.map +1 -0
- package/dist/client/connect/readOnly.d.ts +97 -0
- package/dist/client/connect/readOnly.d.ts.map +1 -0
- package/dist/client/connect/readOnly.js +167 -0
- package/dist/client/connect/readOnly.js.map +1 -0
- package/dist/client/core/errors.d.ts +80 -0
- package/dist/client/core/errors.d.ts.map +1 -0
- package/dist/client/core/errors.js +154 -0
- package/dist/client/core/errors.js.map +1 -0
- package/dist/client/core/options.d.ts +44 -0
- package/dist/client/core/options.d.ts.map +1 -0
- package/dist/client/core/options.js +2 -0
- package/dist/client/core/options.js.map +1 -0
- package/dist/client/core/session.d.ts +90 -0
- package/dist/client/core/session.d.ts.map +1 -0
- package/dist/client/core/session.js +72 -0
- package/dist/client/core/session.js.map +1 -0
- package/dist/client/core/views.d.ts +40 -0
- package/dist/client/core/views.d.ts.map +1 -0
- package/dist/client/core/views.js +32 -0
- package/dist/client/core/views.js.map +1 -0
- package/dist/client/index.d.ts +16 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +9 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/mirror/collections.d.ts +125 -0
- package/dist/client/mirror/collections.d.ts.map +1 -0
- package/dist/client/mirror/collections.js +118 -0
- package/dist/client/mirror/collections.js.map +1 -0
- package/dist/client/mirror/index.d.ts +4 -0
- package/dist/client/mirror/index.d.ts.map +1 -0
- package/dist/client/mirror/index.js +4 -0
- package/dist/client/mirror/index.js.map +1 -0
- package/dist/client/mirror/writer.d.ts +39 -0
- package/dist/client/mirror/writer.d.ts.map +1 -0
- package/dist/client/mirror/writer.js +50 -0
- package/dist/client/mirror/writer.js.map +1 -0
- package/dist/client/pairing/mirrorGrant.d.ts +91 -0
- package/dist/client/pairing/mirrorGrant.d.ts.map +1 -0
- package/dist/client/pairing/mirrorGrant.js +99 -0
- package/dist/client/pairing/mirrorGrant.js.map +1 -0
- package/dist/client/pairing/mirrorReader.d.ts +99 -0
- package/dist/client/pairing/mirrorReader.d.ts.map +1 -0
- package/dist/client/pairing/mirrorReader.js +117 -0
- package/dist/client/pairing/mirrorReader.js.map +1 -0
- package/dist/client/pairing/pairingGrantExchange.d.ts +135 -0
- package/dist/client/pairing/pairingGrantExchange.d.ts.map +1 -0
- package/dist/client/pairing/pairingGrantExchange.js +186 -0
- package/dist/client/pairing/pairingGrantExchange.js.map +1 -0
- package/dist/client/pairing/pairingRequest.d.ts +82 -0
- package/dist/client/pairing/pairingRequest.d.ts.map +1 -0
- package/dist/client/pairing/pairingRequest.js +120 -0
- package/dist/client/pairing/pairingRequest.js.map +1 -0
- package/dist/client/strategy.d.ts +36 -0
- package/dist/client/strategy.d.ts.map +1 -0
- package/dist/client/strategy.js +26 -0
- package/dist/client/strategy.js.map +1 -0
- package/dist/collections/index.d.ts +3 -0
- package/dist/collections/index.d.ts.map +1 -0
- package/dist/collections/index.js +3 -0
- package/dist/collections/index.js.map +1 -0
- package/dist/collections/nodeCollections.d.ts +57 -0
- package/dist/collections/nodeCollections.d.ts.map +1 -0
- package/dist/collections/nodeCollections.js +40 -0
- package/dist/collections/nodeCollections.js.map +1 -0
- package/dist/collections/paths.d.ts +7 -0
- package/dist/collections/paths.d.ts.map +1 -0
- package/dist/collections/paths.js +13 -0
- package/dist/collections/paths.js.map +1 -0
- package/dist/crypto/collectionKeys.d.ts +28 -0
- package/dist/crypto/collectionKeys.d.ts.map +1 -0
- package/dist/crypto/collectionKeys.js +53 -0
- package/dist/crypto/collectionKeys.js.map +1 -0
- package/dist/crypto/hkdf.d.ts +14 -0
- package/dist/crypto/hkdf.d.ts.map +1 -0
- package/dist/crypto/hkdf.js +19 -0
- package/dist/crypto/hkdf.js.map +1 -0
- package/dist/crypto/index.d.ts +5 -0
- package/dist/crypto/index.d.ts.map +1 -0
- package/dist/crypto/index.js +5 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/crypto/secretEncryptor.d.ts +20 -0
- package/dist/crypto/secretEncryptor.d.ts.map +1 -0
- package/dist/crypto/secretEncryptor.js +82 -0
- package/dist/crypto/secretEncryptor.js.map +1 -0
- package/dist/crypto/wireConstants.d.ts +14 -0
- package/dist/crypto/wireConstants.d.ts.map +1 -0
- package/dist/crypto/wireConstants.js +17 -0
- package/dist/crypto/wireConstants.js.map +1 -0
- package/dist/identity/address.d.ts +3 -0
- package/dist/identity/address.d.ts.map +1 -0
- package/dist/identity/address.js +17 -0
- package/dist/identity/address.js.map +1 -0
- package/dist/identity/bip39-wordlist.d.ts +2 -0
- package/dist/identity/bip39-wordlist.d.ts.map +1 -0
- package/dist/identity/bip39-wordlist.js +2051 -0
- package/dist/identity/bip39-wordlist.js.map +1 -0
- package/dist/identity/capProvider.d.ts +45 -0
- package/dist/identity/capProvider.d.ts.map +1 -0
- package/dist/identity/capProvider.js +80 -0
- package/dist/identity/capProvider.js.map +1 -0
- package/dist/identity/derivationSchemes.d.ts +25 -0
- package/dist/identity/derivationSchemes.d.ts.map +1 -0
- package/dist/identity/derivationSchemes.js +34 -0
- package/dist/identity/derivationSchemes.js.map +1 -0
- package/dist/identity/evm.d.ts +8 -0
- package/dist/identity/evm.d.ts.map +1 -0
- package/dist/identity/evm.js +78 -0
- package/dist/identity/evm.js.map +1 -0
- package/dist/identity/index.d.ts +10 -0
- package/dist/identity/index.d.ts.map +1 -0
- package/dist/identity/index.js +10 -0
- package/dist/identity/index.js.map +1 -0
- package/dist/identity/keys.d.ts +17 -0
- package/dist/identity/keys.d.ts.map +1 -0
- package/dist/identity/keys.js +36 -0
- package/dist/identity/keys.js.map +1 -0
- package/dist/identity/mnemonic.d.ts +4 -0
- package/dist/identity/mnemonic.d.ts.map +1 -0
- package/dist/identity/mnemonic.js +93 -0
- package/dist/identity/mnemonic.js.map +1 -0
- package/dist/identity/pairing.d.ts +45 -0
- package/dist/identity/pairing.d.ts.map +1 -0
- package/dist/identity/pairing.js +91 -0
- package/dist/identity/pairing.js.map +1 -0
- package/dist/identity/pairingRequest.d.ts +99 -0
- package/dist/identity/pairingRequest.d.ts.map +1 -0
- package/dist/identity/pairingRequest.js +217 -0
- package/dist/identity/pairingRequest.js.map +1 -0
- package/dist/identity/secret.d.ts +32 -0
- package/dist/identity/secret.d.ts.map +1 -0
- package/dist/identity/secret.js +54 -0
- package/dist/identity/secret.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/bytes.d.ts +11 -0
- package/dist/internal/bytes.d.ts.map +1 -0
- package/dist/internal/bytes.js +38 -0
- package/dist/internal/bytes.js.map +1 -0
- package/dist/node-api/dexPair.d.ts +24 -0
- package/dist/node-api/dexPair.d.ts.map +1 -0
- package/dist/node-api/dexPair.js +39 -0
- package/dist/node-api/dexPair.js.map +1 -0
- package/dist/node-api/dsl.d.ts +10 -0
- package/dist/node-api/dsl.d.ts.map +1 -0
- package/dist/node-api/dsl.js +7 -0
- package/dist/node-api/dsl.js.map +1 -0
- package/dist/node-api/exchanges.d.ts +49 -0
- package/dist/node-api/exchanges.d.ts.map +1 -0
- package/dist/node-api/exchanges.js +32 -0
- package/dist/node-api/exchanges.js.map +1 -0
- package/dist/node-api/index.d.ts +12 -0
- package/dist/node-api/index.d.ts.map +1 -0
- package/dist/node-api/index.js +12 -0
- package/dist/node-api/index.js.map +1 -0
- package/dist/node-api/marketMaking.d.ts +39 -0
- package/dist/node-api/marketMaking.d.ts.map +1 -0
- package/dist/node-api/marketMaking.js +44 -0
- package/dist/node-api/marketMaking.js.map +1 -0
- package/dist/node-api/octobots.d.ts +14 -0
- package/dist/node-api/octobots.d.ts.map +1 -0
- package/dist/node-api/octobots.js +16 -0
- package/dist/node-api/octobots.js.map +1 -0
- package/dist/node-api/orderBookPreview.d.ts +11 -0
- package/dist/node-api/orderBookPreview.d.ts.map +1 -0
- package/dist/node-api/orderBookPreview.js +7 -0
- package/dist/node-api/orderBookPreview.js.map +1 -0
- package/dist/node-api/pairing.d.ts +39 -0
- package/dist/node-api/pairing.d.ts.map +1 -0
- package/dist/node-api/pairing.js +61 -0
- package/dist/node-api/pairing.js.map +1 -0
- package/dist/node-api/pairs.d.ts +32 -0
- package/dist/node-api/pairs.d.ts.map +1 -0
- package/dist/node-api/pairs.js +72 -0
- package/dist/node-api/pairs.js.map +1 -0
- package/dist/node-api/requiredFunds.d.ts +11 -0
- package/dist/node-api/requiredFunds.d.ts.map +1 -0
- package/dist/node-api/requiredFunds.js +7 -0
- package/dist/node-api/requiredFunds.js.map +1 -0
- package/dist/node-api/setup.d.ts +25 -0
- package/dist/node-api/setup.d.ts.map +1 -0
- package/dist/node-api/setup.js +13 -0
- package/dist/node-api/setup.js.map +1 -0
- package/dist/node-api/wallet.d.ts +55 -0
- package/dist/node-api/wallet.d.ts.map +1 -0
- package/dist/node-api/wallet.js +87 -0
- package/dist/node-api/wallet.js.map +1 -0
- package/dist/protocol/actions.d.ts +40 -0
- package/dist/protocol/actions.d.ts.map +1 -0
- package/dist/protocol/actions.js +118 -0
- package/dist/protocol/actions.js.map +1 -0
- package/dist/protocol/documents.d.ts +25 -0
- package/dist/protocol/documents.d.ts.map +1 -0
- package/dist/protocol/documents.js +2 -0
- package/dist/protocol/documents.js.map +1 -0
- package/dist/protocol/index.d.ts +10 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/index.js +12 -0
- package/dist/protocol/index.js.map +1 -0
- package/dist/protocol/orchestration/createAutomation.d.ts +61 -0
- package/dist/protocol/orchestration/createAutomation.d.ts.map +1 -0
- package/dist/protocol/orchestration/createAutomation.js +71 -0
- package/dist/protocol/orchestration/createAutomation.js.map +1 -0
- package/dist/protocol/poll.d.ts +4 -0
- package/dist/protocol/poll.d.ts.map +1 -0
- package/dist/protocol/poll.js +4 -0
- package/dist/protocol/poll.js.map +1 -0
- package/dist/protocol/proposal.d.ts +36 -0
- package/dist/protocol/proposal.d.ts.map +1 -0
- package/dist/protocol/proposal.js +39 -0
- package/dist/protocol/proposal.js.map +1 -0
- package/dist/protocol/state.d.ts +87 -0
- package/dist/protocol/state.d.ts.map +1 -0
- package/dist/protocol/state.js +303 -0
- package/dist/protocol/state.js.map +1 -0
- package/dist/protocol/strategy/build.d.ts +44 -0
- package/dist/protocol/strategy/build.d.ts.map +1 -0
- package/dist/protocol/strategy/build.js +50 -0
- package/dist/protocol/strategy/build.js.map +1 -0
- package/dist/protocol/strategy/builders.d.ts +252 -0
- package/dist/protocol/strategy/builders.d.ts.map +1 -0
- package/dist/protocol/strategy/builders.js +382 -0
- package/dist/protocol/strategy/builders.js.map +1 -0
- package/dist/protocol/strategy/index.d.ts +5 -0
- package/dist/protocol/strategy/index.d.ts.map +1 -0
- package/dist/protocol/strategy/index.js +4 -0
- package/dist/protocol/strategy/index.js.map +1 -0
- package/dist/protocol/strategy/kinds.d.ts +2 -0
- package/dist/protocol/strategy/kinds.d.ts.map +1 -0
- package/dist/protocol/strategy/kinds.js +2 -0
- package/dist/protocol/strategy/kinds.js.map +1 -0
- package/dist/protocol/strategy/patch.d.ts +59 -0
- package/dist/protocol/strategy/patch.d.ts.map +1 -0
- package/dist/protocol/strategy/patch.js +253 -0
- package/dist/protocol/strategy/patch.js.map +1 -0
- package/dist/protocol/symbols.d.ts +8 -0
- package/dist/protocol/symbols.d.ts.map +1 -0
- package/dist/protocol/symbols.js +11 -0
- package/dist/protocol/symbols.js.map +1 -0
- package/dist/transport/constants.d.ts +8 -0
- package/dist/transport/constants.d.ts.map +1 -0
- package/dist/transport/constants.js +8 -0
- package/dist/transport/constants.js.map +1 -0
- package/dist/transport/documents.d.ts +27 -0
- package/dist/transport/documents.d.ts.map +1 -0
- package/dist/transport/documents.js +34 -0
- package/dist/transport/documents.js.map +1 -0
- package/dist/transport/index.d.ts +8 -0
- package/dist/transport/index.d.ts.map +1 -0
- package/dist/transport/index.js +8 -0
- package/dist/transport/index.js.map +1 -0
- package/dist/transport/probe.d.ts +44 -0
- package/dist/transport/probe.d.ts.map +1 -0
- package/dist/transport/probe.js +121 -0
- package/dist/transport/probe.js.map +1 -0
- package/dist/transport/rendezvous.d.ts +116 -0
- package/dist/transport/rendezvous.d.ts.map +1 -0
- package/dist/transport/rendezvous.js +139 -0
- package/dist/transport/rendezvous.js.map +1 -0
- package/dist/transport/rest.d.ts +35 -0
- package/dist/transport/rest.d.ts.map +1 -0
- package/dist/transport/rest.js +58 -0
- package/dist/transport/rest.js.map +1 -0
- package/dist/transport/syncClient.d.ts +14 -0
- package/dist/transport/syncClient.d.ts.map +1 -0
- package/dist/transport/syncClient.js +30 -0
- package/dist/transport/syncClient.js.map +1 -0
- package/dist/transport/urls.d.ts +35 -0
- package/dist/transport/urls.d.ts.map +1 -0
- package/dist/transport/urls.js +126 -0
- package/dist/transport/urls.js.map +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { Strategy as ProtocolStrategy, UserActionConfiguration } from '@drakkar.software/octobot-protocol';
|
|
2
|
+
import { type ClientSession } from '../core/session.js';
|
|
3
|
+
import type { CallOptions } from '../core/options.js';
|
|
4
|
+
import type { AccountInput } from '../adapters/accounts.js';
|
|
5
|
+
import type { CreateAutomationInput } from '../adapters/automations.js';
|
|
6
|
+
import type { AccountView, AutomationView } from '../core/views.js';
|
|
7
|
+
import { type ReadOnlyDocumentsApi } from '../adapters/documents.js';
|
|
8
|
+
export type { AccountView, AccountKind, AutomationView, Holding } from '../core/views.js';
|
|
9
|
+
export type { AccountInput } from '../adapters/accounts.js';
|
|
10
|
+
export type { CreateAutomationInput } from '../adapters/automations.js';
|
|
11
|
+
/** A write call built its action(s) but never sent them — the session has no
|
|
12
|
+
* append rights. `payload` is the QR-encodable `ActionProposal`; a
|
|
13
|
+
* privileged client (real append rights) scans/decodes it and executes it
|
|
14
|
+
* after a human confirms. See `protocol/proposal.ts`. */
|
|
15
|
+
export interface ProposedAction {
|
|
16
|
+
actions: UserActionConfiguration[];
|
|
17
|
+
payload: string;
|
|
18
|
+
}
|
|
19
|
+
/** A session with no append rights (`ops` never includes `'write'`, enforced
|
|
20
|
+
* by the node) built from `connectReadOnlyDevice()`. Every write method
|
|
21
|
+
* that would normally return an `ActionHandle` returns a `ProposedAction`
|
|
22
|
+
* instead — same method names, so a caller migrating between the two client
|
|
23
|
+
* kinds doesn't rename anything, just changes what it does with the
|
|
24
|
+
* result. */
|
|
25
|
+
export interface ReadOnlyAccountsApi {
|
|
26
|
+
list(opts?: CallOptions): Promise<AccountView[]>;
|
|
27
|
+
get(id: string, opts?: CallOptions): Promise<AccountView | null>;
|
|
28
|
+
create(input: AccountInput, opts?: CallOptions): Promise<ProposedAction>;
|
|
29
|
+
update(id: string, input: AccountInput, opts?: CallOptions): Promise<ProposedAction>;
|
|
30
|
+
delete(id: string, opts?: CallOptions): Promise<ProposedAction>;
|
|
31
|
+
refresh(ids?: string[], opts?: CallOptions): Promise<ProposedAction>;
|
|
32
|
+
}
|
|
33
|
+
export interface ReadOnlyAutomationsApi {
|
|
34
|
+
list(opts?: CallOptions): Promise<AutomationView[]>;
|
|
35
|
+
get(id: string, opts?: CallOptions): Promise<AutomationView | null>;
|
|
36
|
+
create(input: CreateAutomationInput, opts?: CallOptions): Promise<ProposedAction>;
|
|
37
|
+
update(id: string, input: CreateAutomationInput, opts?: CallOptions): Promise<ProposedAction>;
|
|
38
|
+
stop(id: string, opts?: CallOptions): Promise<ProposedAction>;
|
|
39
|
+
}
|
|
40
|
+
export interface ReadOnlyStrategiesApi {
|
|
41
|
+
list(opts?: CallOptions): Promise<ProtocolStrategy[]>;
|
|
42
|
+
get(id: string, version?: string, opts?: CallOptions): Promise<ProtocolStrategy | null>;
|
|
43
|
+
create(strategy: ProtocolStrategy, opts?: CallOptions): Promise<ProposedAction>;
|
|
44
|
+
update(strategy: ProtocolStrategy, opts?: CallOptions): Promise<ProposedAction>;
|
|
45
|
+
delete(id: string, opts?: CallOptions): Promise<ProposedAction>;
|
|
46
|
+
}
|
|
47
|
+
export type ReadOnlyOctoBotClient = {
|
|
48
|
+
readonly url: string;
|
|
49
|
+
readonly userId: string;
|
|
50
|
+
readonly accounts: ReadOnlyAccountsApi;
|
|
51
|
+
readonly automations: ReadOnlyAutomationsApi;
|
|
52
|
+
readonly strategies: ReadOnlyStrategiesApi;
|
|
53
|
+
/** Escape hatch: `pull` only, and only for a granted collection — an
|
|
54
|
+
* ungranted collection throws `OctoBotScopeError` before any network
|
|
55
|
+
* request, since this session was never given the key to decrypt it.
|
|
56
|
+
* No `push`/`append`: this client has no append rights by design (see
|
|
57
|
+
* the accounts/automations/strategies APIs above, which propose instead
|
|
58
|
+
* of appending), and `settings`/`node` are not exposed here at all —
|
|
59
|
+
* `settings` because the default grant never covers that collection, and
|
|
60
|
+
* `node`'s REST endpoints need `basicAuth`, which a pairing payload never
|
|
61
|
+
* carries. */
|
|
62
|
+
readonly documents: ReadOnlyDocumentsApi;
|
|
63
|
+
close(): void;
|
|
64
|
+
};
|
|
65
|
+
export declare function createReadOnlyOctoBotClient(session: ClientSession): ReadOnlyOctoBotClient;
|
|
66
|
+
export type ConnectReadOnlyOptions = {
|
|
67
|
+
/** Injected fetch — proxies, mTLS, React Native polyfills, test stubs.
|
|
68
|
+
* Default: `globalThis.fetch`. */
|
|
69
|
+
fetch?: typeof fetch;
|
|
70
|
+
/** Default per-request timeout, ms. Default 10_000. */
|
|
71
|
+
timeoutMs?: number;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Connect to a self-hosted OctoBot node using a read-only pairing payload —
|
|
75
|
+
* a bearer credential a privileged device minted with `createReadOnlyPairing()`
|
|
76
|
+
* (`@drakkar.software/octobot-client/identity`), NOT a wallet seed. There is
|
|
77
|
+
* no seed anywhere on this path.
|
|
78
|
+
*
|
|
79
|
+
* The returned client's write methods (`accounts.create/update/delete`,
|
|
80
|
+
* `automations.create/update/stop`, `strategies.create/update/delete`) never
|
|
81
|
+
* append anything — this package never calls the node's append endpoint on
|
|
82
|
+
* this session's behalf. (The node does not yet enforce a cap's `ops` scope
|
|
83
|
+
* itself — every collection currently grants `self` role by identity alone,
|
|
84
|
+
* regardless of `ops` — so this is presently a client-side guarantee, not a
|
|
85
|
+
* node-enforced one; see `OctoBotScopeError`.) Instead they build the
|
|
86
|
+
* action(s) and return a `ProposedAction`: the built configuration(s) plus a
|
|
87
|
+
* QR-encodable payload for a privileged device to scan, review, and execute.
|
|
88
|
+
*
|
|
89
|
+
* ```ts
|
|
90
|
+
* const octobot = await connectReadOnlyDevice(pairingPayload)
|
|
91
|
+
* const accounts = await octobot.accounts.list() // works
|
|
92
|
+
* const proposed = await octobot.automations.stop(automationId) // builds, doesn't send
|
|
93
|
+
* console.log(proposed.payload) // render this as a QR
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export declare function connectReadOnlyDevice(pairingPayload: string, opts?: ConnectReadOnlyOptions): Promise<ReadOnlyOctoBotClient>;
|
|
97
|
+
//# sourceMappingURL=readOnly.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readOnly.d.ts","sourceRoot":"","sources":["../../../src/client/connect/readOnly.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,IAAI,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAA;AAG/G,OAAO,EAAyB,KAAK,aAAa,EAA2B,MAAM,oBAAoB,CAAA;AACvG,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAInE,OAAO,EAA8B,KAAK,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AAwBhG,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AACzF,YAAY,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAC3D,YAAY,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAEvE;;;0DAG0D;AAC1D,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,uBAAuB,EAAE,CAAA;IAClC,OAAO,EAAE,MAAM,CAAA;CAChB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AACH,wBAAsB,qBAAqB,CACzC,cAAc,EAAE,MAAM,EACtB,IAAI,GAAE,sBAA2B,GAChC,OAAO,CAAC,qBAAqB,CAAC,CA+BhC"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { parseReadOnlyPairing } from '../../identity/pairing.js';
|
|
2
|
+
import { SYNC_FETCH_TIMEOUT_MS } from '../../crypto/wireConstants.js';
|
|
3
|
+
import { createReadOnlySession } from '../core/session.js';
|
|
4
|
+
import { createAccountsApi, toAccountGraph, pullAccountsDocument } from '../adapters/accounts.js';
|
|
5
|
+
import { createAutomationsApi } from '../adapters/automations.js';
|
|
6
|
+
import { createStrategiesApi } from '../adapters/strategies.js';
|
|
7
|
+
import { createReadOnlyDocumentsApi } from '../adapters/documents.js';
|
|
8
|
+
import { OctoBotConfigError, rethrowAsOctoBotError } from '../core/errors.js';
|
|
9
|
+
import { accountAuthIdFor, exchangeConfigIdFor, buildCreateAccountConfig, buildEditAccountConfig, buildDeleteAccountConfig, buildRefreshAccountsConfig, buildCreateAccountAuthConfig, buildEditAccountAuthConfig, buildDeleteAccountAuthConfig, buildCreateExchangeConfigConfig, buildEditExchangeConfigConfig, buildDeleteExchangeConfigConfig, buildCreateStrategyConfig, buildEditStrategyConfig, buildDeleteStrategyConfig, buildCreateAutomationConfig, buildEditAutomationConfig, buildStopAutomationConfig, } from '../../protocol/actions.js';
|
|
10
|
+
import { encodeActionProposal } from '../../protocol/proposal.js';
|
|
11
|
+
function proposalOf(actions, label) {
|
|
12
|
+
return { actions: actions.map((a) => a.configuration), payload: encodeActionProposal(actions, { label }) };
|
|
13
|
+
}
|
|
14
|
+
const neverAppend = () => {
|
|
15
|
+
throw new Error('read-only client: this session has no append rights, this should never be called');
|
|
16
|
+
};
|
|
17
|
+
function createReadOnlyAccountsApi(session) {
|
|
18
|
+
const base = createAccountsApi(session, neverAppend);
|
|
19
|
+
return {
|
|
20
|
+
list: base.list,
|
|
21
|
+
get: base.get,
|
|
22
|
+
async create(input) {
|
|
23
|
+
const { account, auth, exchangeConfig } = toAccountGraph(input);
|
|
24
|
+
const entries = [];
|
|
25
|
+
if (auth)
|
|
26
|
+
entries.push({ configuration: buildCreateAccountAuthConfig(auth) });
|
|
27
|
+
if (exchangeConfig)
|
|
28
|
+
entries.push({ configuration: buildCreateExchangeConfigConfig(exchangeConfig) });
|
|
29
|
+
entries.push({ configuration: buildCreateAccountConfig(account) });
|
|
30
|
+
return proposalOf(entries, `Create account "${input.name}"`);
|
|
31
|
+
},
|
|
32
|
+
async update(id, input) {
|
|
33
|
+
const { account, auth, exchangeConfig } = toAccountGraph({ ...input, id });
|
|
34
|
+
const existing = await pullAccountsDocument(session)
|
|
35
|
+
.then(({ data }) => (data.accounts ?? []).find((a) => a.id === id))
|
|
36
|
+
.catch(() => undefined);
|
|
37
|
+
if (existing?.created_at)
|
|
38
|
+
account.created_at = existing.created_at;
|
|
39
|
+
const entries = [];
|
|
40
|
+
if (auth)
|
|
41
|
+
entries.push({ configuration: buildEditAccountAuthConfig(auth) });
|
|
42
|
+
if (exchangeConfig)
|
|
43
|
+
entries.push({ configuration: buildEditExchangeConfigConfig(exchangeConfig) });
|
|
44
|
+
entries.push({ configuration: buildEditAccountConfig(id, account) });
|
|
45
|
+
return proposalOf(entries, `Update account "${input.name}"`);
|
|
46
|
+
},
|
|
47
|
+
async delete(id) {
|
|
48
|
+
return proposalOf([
|
|
49
|
+
{ configuration: buildDeleteAccountConfig(id) },
|
|
50
|
+
{ configuration: buildDeleteAccountAuthConfig(accountAuthIdFor(id)) },
|
|
51
|
+
{ configuration: buildDeleteExchangeConfigConfig(exchangeConfigIdFor(id)) },
|
|
52
|
+
], `Delete account ${id}`);
|
|
53
|
+
},
|
|
54
|
+
async refresh(accountIds) {
|
|
55
|
+
return proposalOf([{ configuration: buildRefreshAccountsConfig(accountIds) }], 'Refresh account balances');
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function createReadOnlyAutomationsApi(session) {
|
|
60
|
+
const base = createAutomationsApi(session, neverAppend);
|
|
61
|
+
return {
|
|
62
|
+
list: base.list,
|
|
63
|
+
get: base.get,
|
|
64
|
+
async create(input) {
|
|
65
|
+
// Same node-side race `runCreateAutomation` sequences around: the node
|
|
66
|
+
// resolves `automation_create`'s strategy by (id, version) against its
|
|
67
|
+
// StrategyProvider, which only the confirmed `strategy_create` fills.
|
|
68
|
+
// This session can't poll for that confirmation itself (no append
|
|
69
|
+
// rights) — the executing side must, before appending the second entry.
|
|
70
|
+
return proposalOf([
|
|
71
|
+
{ configuration: buildCreateStrategyConfig(input.strategy) },
|
|
72
|
+
{ configuration: buildCreateAutomationConfig(input), after: 'previous-confirmed' },
|
|
73
|
+
], `Create automation "${input.name}"`);
|
|
74
|
+
},
|
|
75
|
+
async update(id, input) {
|
|
76
|
+
return proposalOf([
|
|
77
|
+
{ configuration: buildEditStrategyConfig(input.strategy) },
|
|
78
|
+
{ configuration: buildEditAutomationConfig({ ...input, automationId: id }) },
|
|
79
|
+
], `Update automation "${input.name}"`);
|
|
80
|
+
},
|
|
81
|
+
async stop(id) {
|
|
82
|
+
return proposalOf([{ configuration: buildStopAutomationConfig(id) }], `Stop automation ${id}`);
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function createReadOnlyStrategiesApi(session) {
|
|
87
|
+
const base = createStrategiesApi(session, neverAppend);
|
|
88
|
+
return {
|
|
89
|
+
list: base.list,
|
|
90
|
+
get: base.get,
|
|
91
|
+
async create(strategy) {
|
|
92
|
+
return proposalOf([{ configuration: buildCreateStrategyConfig(strategy) }], `Create strategy "${strategy.name}"`);
|
|
93
|
+
},
|
|
94
|
+
async update(strategy) {
|
|
95
|
+
return proposalOf([{ configuration: buildEditStrategyConfig(strategy) }], `Update strategy "${strategy.name}"`);
|
|
96
|
+
},
|
|
97
|
+
async delete(id) {
|
|
98
|
+
return proposalOf([{ configuration: buildDeleteStrategyConfig(id) }], `Delete strategy ${id}`);
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
export function createReadOnlyOctoBotClient(session) {
|
|
103
|
+
return {
|
|
104
|
+
url: session.origin,
|
|
105
|
+
userId: session.userId,
|
|
106
|
+
accounts: createReadOnlyAccountsApi(session),
|
|
107
|
+
automations: createReadOnlyAutomationsApi(session),
|
|
108
|
+
strategies: createReadOnlyStrategiesApi(session),
|
|
109
|
+
documents: createReadOnlyDocumentsApi(session),
|
|
110
|
+
close: () => session.close(),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Connect to a self-hosted OctoBot node using a read-only pairing payload —
|
|
115
|
+
* a bearer credential a privileged device minted with `createReadOnlyPairing()`
|
|
116
|
+
* (`@drakkar.software/octobot-client/identity`), NOT a wallet seed. There is
|
|
117
|
+
* no seed anywhere on this path.
|
|
118
|
+
*
|
|
119
|
+
* The returned client's write methods (`accounts.create/update/delete`,
|
|
120
|
+
* `automations.create/update/stop`, `strategies.create/update/delete`) never
|
|
121
|
+
* append anything — this package never calls the node's append endpoint on
|
|
122
|
+
* this session's behalf. (The node does not yet enforce a cap's `ops` scope
|
|
123
|
+
* itself — every collection currently grants `self` role by identity alone,
|
|
124
|
+
* regardless of `ops` — so this is presently a client-side guarantee, not a
|
|
125
|
+
* node-enforced one; see `OctoBotScopeError`.) Instead they build the
|
|
126
|
+
* action(s) and return a `ProposedAction`: the built configuration(s) plus a
|
|
127
|
+
* QR-encodable payload for a privileged device to scan, review, and execute.
|
|
128
|
+
*
|
|
129
|
+
* ```ts
|
|
130
|
+
* const octobot = await connectReadOnlyDevice(pairingPayload)
|
|
131
|
+
* const accounts = await octobot.accounts.list() // works
|
|
132
|
+
* const proposed = await octobot.automations.stop(automationId) // builds, doesn't send
|
|
133
|
+
* console.log(proposed.payload) // render this as a QR
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
export async function connectReadOnlyDevice(pairingPayload, opts = {}) {
|
|
137
|
+
let parsed;
|
|
138
|
+
try {
|
|
139
|
+
parsed = parseReadOnlyPairing(pairingPayload);
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
throw new OctoBotConfigError(`invalid read-only pairing payload: ${err instanceof Error ? err.message : String(err)}`);
|
|
143
|
+
}
|
|
144
|
+
const fetchImpl = opts.fetch ?? globalThis.fetch;
|
|
145
|
+
const defaultTimeoutMs = opts.timeoutMs ?? SYNC_FETCH_TIMEOUT_MS;
|
|
146
|
+
const origin = `${parsed.node.secure ? 'https' : 'http'}://${parsed.node.host}:${parsed.node.port}`;
|
|
147
|
+
const capProvider = {
|
|
148
|
+
getCap: async () => ({ cap: parsed.cap, devEdPrivHex: parsed.device.edPriv }),
|
|
149
|
+
getUserId: async () => parsed.userId,
|
|
150
|
+
};
|
|
151
|
+
try {
|
|
152
|
+
const session = createReadOnlySession({
|
|
153
|
+
origin,
|
|
154
|
+
node: parsed.node,
|
|
155
|
+
userId: parsed.userId,
|
|
156
|
+
fetch: fetchImpl,
|
|
157
|
+
defaultTimeoutMs,
|
|
158
|
+
capProvider,
|
|
159
|
+
collectionKeys: parsed.collectionKeys,
|
|
160
|
+
});
|
|
161
|
+
return createReadOnlyOctoBotClient(session);
|
|
162
|
+
}
|
|
163
|
+
catch (err) {
|
|
164
|
+
rethrowAsOctoBotError(err);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=readOnly.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readOnly.js","sourceRoot":"","sources":["../../../src/client/connect/readOnly.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAA;AACrE,OAAO,EAAE,qBAAqB,EAA+C,MAAM,oBAAoB,CAAA;AAKvG,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,oBAAoB,EAAqB,MAAM,yBAAyB,CAAA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AAA;IAEnG,MAAM,WAAW,GAAuB;QACtC,MAAM,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QAC7E,SAAS,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,CAAC,MAAM;KACrC,CAAA;IAED,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,qBAAqB,CAAC;YACpC,MAAM;YACN,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,KAAK,EAAE,SAAS;YAChB,gBAAgB;YAChB,WAAW;YACX,cAAc,EAAE,MAAM,CAAC,cAAc;SACtC,CAAC,CAAA;QACF,OAAO,2BAA2B,CAAC,OAAO,CAAC,CAAA;IAC7C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,qBAAqB,CAAC,GAAG,CAAC,CAAA;IAC5B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { SeedDerivation } from './options.js';
|
|
2
|
+
export type OctoBotErrorCode = 'config' | 'unreachable' | 'timeout' | 'unauthorized' | 'http' | 'conflict' | 'action_failed' | 'action_timeout' | 'aborted' | 'forbidden_collection';
|
|
3
|
+
/** Base class for every error this package throws. Every method that can
|
|
4
|
+
* fail throws one of these (or lets an `AbortError` DOMException through
|
|
5
|
+
* unwrapped, per the platform convention). Switch on `code` rather than
|
|
6
|
+
* `instanceof` when the check has to survive across a duplicated package
|
|
7
|
+
* instance (a monorepo hoisting quirk, a bundler that doesn't dedupe). */
|
|
8
|
+
export declare class OctoBotError extends Error {
|
|
9
|
+
readonly code: OctoBotErrorCode;
|
|
10
|
+
readonly cause?: unknown;
|
|
11
|
+
constructor(code: OctoBotErrorCode, message: string, cause?: unknown);
|
|
12
|
+
}
|
|
13
|
+
/** Bad `ConnectOptions` — an unparseable `url`, or a `node.*` call made
|
|
14
|
+
* without the `basicAuth` credentials it requires. */
|
|
15
|
+
export declare class OctoBotConfigError extends OctoBotError {
|
|
16
|
+
constructor(message: string);
|
|
17
|
+
}
|
|
18
|
+
/** The node could not be reached at all — offline, wrong port, timed out, or
|
|
19
|
+
* the connect-time abort fired. */
|
|
20
|
+
export declare class OctoBotConnectionError extends OctoBotError {
|
|
21
|
+
constructor(code: 'unreachable' | 'timeout' | 'aborted', message: string, cause?: unknown);
|
|
22
|
+
}
|
|
23
|
+
/** The node answered, but did not authorize this wallet. Carries what the
|
|
24
|
+
* seed actually derived to, so the message can name the mismatch instead of
|
|
25
|
+
* just saying "unauthorized". */
|
|
26
|
+
export declare class OctoBotAuthError extends OctoBotError {
|
|
27
|
+
readonly address: string;
|
|
28
|
+
readonly userId: string;
|
|
29
|
+
readonly derivation: SeedDerivation;
|
|
30
|
+
constructor(address: string, userId: string, derivation: SeedDerivation);
|
|
31
|
+
}
|
|
32
|
+
/** A node REST call (`client.node.*`) answered with a non-2xx status. */
|
|
33
|
+
export declare class OctoBotHttpError extends OctoBotError {
|
|
34
|
+
readonly status: number;
|
|
35
|
+
constructor(status: number, cause?: unknown);
|
|
36
|
+
}
|
|
37
|
+
/** A document push raced another writer's push — the `baseHash` you pushed
|
|
38
|
+
* against is no longer the server's current hash. Pull again and retry. */
|
|
39
|
+
export declare class OctoBotConflictError extends OctoBotError {
|
|
40
|
+
readonly serverHash: string | null;
|
|
41
|
+
constructor(serverHash: string | null, cause?: unknown, message?: string);
|
|
42
|
+
}
|
|
43
|
+
/** The node executed a queued action and rejected it. Not retriable by
|
|
44
|
+
* resubmitting the same configuration unchanged. */
|
|
45
|
+
export declare class OctoBotActionError extends OctoBotError {
|
|
46
|
+
readonly phase?: string;
|
|
47
|
+
readonly detail: string | null;
|
|
48
|
+
constructor(detail: string | null, phase?: string, cause?: unknown);
|
|
49
|
+
}
|
|
50
|
+
/** `ActionHandle.settled()` gave up waiting — the node never confirmed
|
|
51
|
+
* within the timeout budget. Not necessarily a failure; the action may
|
|
52
|
+
* still complete. */
|
|
53
|
+
export declare class OctoBotTimeoutError extends OctoBotError {
|
|
54
|
+
readonly phase?: string;
|
|
55
|
+
constructor(phase?: string, cause?: unknown);
|
|
56
|
+
}
|
|
57
|
+
/** A read-only session tried to read/write a collection its pairing grant
|
|
58
|
+
* doesn't cover — thrown client-side, before any network request, by
|
|
59
|
+
* `ClientSession.collectionEncryptor()`. This is not merely a courtesy: the
|
|
60
|
+
* node does not yet enforce a cap's collection scope itself (every
|
|
61
|
+
* collection is currently `readRoles=["self"], writeRoles=["self"]`, which
|
|
62
|
+
* a device cap always satisfies regardless of its `scope`), so this
|
|
63
|
+
* client-side check is presently the ONLY thing keeping a read-only session
|
|
64
|
+
* inside its granted collections. */
|
|
65
|
+
export declare class OctoBotScopeError extends OctoBotError {
|
|
66
|
+
readonly collection: string;
|
|
67
|
+
constructor(collection: string);
|
|
68
|
+
}
|
|
69
|
+
export declare function isOctoBotError(e: unknown): e is OctoBotError;
|
|
70
|
+
/** Translate a raw transport/orchestration error into the public
|
|
71
|
+
* `OctoBotError` hierarchy. Does NOT touch an `AbortError` — see
|
|
72
|
+
* `rethrowAsOctoBotError` below, which every `client.*` method's catch
|
|
73
|
+
* actually calls. */
|
|
74
|
+
export declare function toOctoBotError(err: unknown): OctoBotError;
|
|
75
|
+
/** What every `client.*` method's `catch` block calls. Lets an `AbortError`
|
|
76
|
+
* DOMException through unwrapped (the platform convention a caller's own
|
|
77
|
+
* `signal` handling already expects) and wraps everything else as an
|
|
78
|
+
* `OctoBotError`. */
|
|
79
|
+
export declare function rethrowAsOctoBotError(err: unknown): never;
|
|
80
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/client/core/errors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAGlD,MAAM,MAAM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qBAAa,kBAAmB,SAAQ,YAAY;IAClD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;gBAClB,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAMnE;AAED;;sBAEsB;AACtB,qBAAa,mBAAoB,SAAQ,YAAY;IACnD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;gBACX,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAK5C;AAED;;;;;;;sCAOsC;AACtC,qBAAa,iBAAkB,SAAQ,YAAY;IACjD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;gBACf,UAAU,EAAE,MAAM;CAK/B;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,YAAY,CAE5D;AAED;;;sBAGsB;AACtB,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,YAAY,CAuBzD;AAED;;;sBAGsB;AACtB,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,OAAO,GAAG,KAAK,CAGzD"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { StarfishHttpError, ConflictError } from '@drakkar.software/starfish-client';
|
|
2
|
+
import { NodeHttpError } from '../../transport/rest.js';
|
|
3
|
+
import { AutomationActionFailedError, AutomationTimeoutError } from '../../protocol/orchestration/createAutomation.js';
|
|
4
|
+
/** Base class for every error this package throws. Every method that can
|
|
5
|
+
* fail throws one of these (or lets an `AbortError` DOMException through
|
|
6
|
+
* unwrapped, per the platform convention). Switch on `code` rather than
|
|
7
|
+
* `instanceof` when the check has to survive across a duplicated package
|
|
8
|
+
* instance (a monorepo hoisting quirk, a bundler that doesn't dedupe). */
|
|
9
|
+
export class OctoBotError extends Error {
|
|
10
|
+
code;
|
|
11
|
+
cause;
|
|
12
|
+
constructor(code, message, cause) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = 'OctoBotError';
|
|
15
|
+
this.code = code;
|
|
16
|
+
this.cause = cause;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Bad `ConnectOptions` — an unparseable `url`, or a `node.*` call made
|
|
20
|
+
* without the `basicAuth` credentials it requires. */
|
|
21
|
+
export class OctoBotConfigError extends OctoBotError {
|
|
22
|
+
constructor(message) {
|
|
23
|
+
super('config', message);
|
|
24
|
+
this.name = 'OctoBotConfigError';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** The node could not be reached at all — offline, wrong port, timed out, or
|
|
28
|
+
* the connect-time abort fired. */
|
|
29
|
+
export class OctoBotConnectionError extends OctoBotError {
|
|
30
|
+
constructor(code, message, cause) {
|
|
31
|
+
super(code, message, cause);
|
|
32
|
+
this.name = 'OctoBotConnectionError';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** The node answered, but did not authorize this wallet. Carries what the
|
|
36
|
+
* seed actually derived to, so the message can name the mismatch instead of
|
|
37
|
+
* just saying "unauthorized". */
|
|
38
|
+
export class OctoBotAuthError extends OctoBotError {
|
|
39
|
+
address;
|
|
40
|
+
userId;
|
|
41
|
+
derivation;
|
|
42
|
+
constructor(address, userId, derivation) {
|
|
43
|
+
super('unauthorized', `the node did not authorize ${address} (derived under '${derivation}'). ` +
|
|
44
|
+
`If this seed phrase was generated by an app using a non-standard derivation, ` +
|
|
45
|
+
`try seedDerivation: 'auto' or the other explicit value.`);
|
|
46
|
+
this.name = 'OctoBotAuthError';
|
|
47
|
+
this.address = address;
|
|
48
|
+
this.userId = userId;
|
|
49
|
+
this.derivation = derivation;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** A node REST call (`client.node.*`) answered with a non-2xx status. */
|
|
53
|
+
export class OctoBotHttpError extends OctoBotError {
|
|
54
|
+
status;
|
|
55
|
+
constructor(status, cause) {
|
|
56
|
+
super('http', `Node request failed: HTTP ${status}`, cause);
|
|
57
|
+
this.name = 'OctoBotHttpError';
|
|
58
|
+
this.status = status;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** A document push raced another writer's push — the `baseHash` you pushed
|
|
62
|
+
* against is no longer the server's current hash. Pull again and retry. */
|
|
63
|
+
export class OctoBotConflictError extends OctoBotError {
|
|
64
|
+
serverHash;
|
|
65
|
+
constructor(serverHash, cause, message = 'push conflict: the document changed since it was last pulled') {
|
|
66
|
+
super('conflict', message, cause);
|
|
67
|
+
this.name = 'OctoBotConflictError';
|
|
68
|
+
this.serverHash = serverHash;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/** The node executed a queued action and rejected it. Not retriable by
|
|
72
|
+
* resubmitting the same configuration unchanged. */
|
|
73
|
+
export class OctoBotActionError extends OctoBotError {
|
|
74
|
+
phase;
|
|
75
|
+
detail;
|
|
76
|
+
constructor(detail, phase, cause) {
|
|
77
|
+
super('action_failed', `action failed${detail ? `: ${detail}` : ''}`, cause);
|
|
78
|
+
this.name = 'OctoBotActionError';
|
|
79
|
+
this.phase = phase;
|
|
80
|
+
this.detail = detail;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** `ActionHandle.settled()` gave up waiting — the node never confirmed
|
|
84
|
+
* within the timeout budget. Not necessarily a failure; the action may
|
|
85
|
+
* still complete. */
|
|
86
|
+
export class OctoBotTimeoutError extends OctoBotError {
|
|
87
|
+
phase;
|
|
88
|
+
constructor(phase, cause) {
|
|
89
|
+
super('action_timeout', 'timed out waiting for the node to confirm', cause);
|
|
90
|
+
this.name = 'OctoBotTimeoutError';
|
|
91
|
+
this.phase = phase;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/** A read-only session tried to read/write a collection its pairing grant
|
|
95
|
+
* doesn't cover — thrown client-side, before any network request, by
|
|
96
|
+
* `ClientSession.collectionEncryptor()`. This is not merely a courtesy: the
|
|
97
|
+
* node does not yet enforce a cap's collection scope itself (every
|
|
98
|
+
* collection is currently `readRoles=["self"], writeRoles=["self"]`, which
|
|
99
|
+
* a device cap always satisfies regardless of its `scope`), so this
|
|
100
|
+
* client-side check is presently the ONLY thing keeping a read-only session
|
|
101
|
+
* inside its granted collections. */
|
|
102
|
+
export class OctoBotScopeError extends OctoBotError {
|
|
103
|
+
collection;
|
|
104
|
+
constructor(collection) {
|
|
105
|
+
super('forbidden_collection', `read-only session: no key granted for collection "${collection}"`);
|
|
106
|
+
this.name = 'OctoBotScopeError';
|
|
107
|
+
this.collection = collection;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export function isOctoBotError(e) {
|
|
111
|
+
return e instanceof OctoBotError;
|
|
112
|
+
}
|
|
113
|
+
/** Translate a raw transport/orchestration error into the public
|
|
114
|
+
* `OctoBotError` hierarchy. Does NOT touch an `AbortError` — see
|
|
115
|
+
* `rethrowAsOctoBotError` below, which every `client.*` method's catch
|
|
116
|
+
* actually calls. */
|
|
117
|
+
export function toOctoBotError(err) {
|
|
118
|
+
if (err instanceof OctoBotError)
|
|
119
|
+
return err;
|
|
120
|
+
if (err instanceof AutomationActionFailedError)
|
|
121
|
+
return new OctoBotActionError(err.detail, err.phase, err);
|
|
122
|
+
if (err instanceof AutomationTimeoutError)
|
|
123
|
+
return new OctoBotTimeoutError(err.phase, err);
|
|
124
|
+
if (err instanceof ConflictError) {
|
|
125
|
+
// The shipped starfish-client exposes the server's authoritative hash
|
|
126
|
+
// as `.currentHash`, not `.serverHash` — reading the wrong field name
|
|
127
|
+
// meant `OctoBotConflictError.serverHash`, the documented retry hint,
|
|
128
|
+
// was silently always null.
|
|
129
|
+
return new OctoBotConflictError(err.currentHash || null, err);
|
|
130
|
+
}
|
|
131
|
+
if (err instanceof StarfishHttpError) {
|
|
132
|
+
if (err.status === 401 || err.status === 403) {
|
|
133
|
+
return new OctoBotError('unauthorized', `sync request rejected: HTTP ${err.status}`, err);
|
|
134
|
+
}
|
|
135
|
+
return new OctoBotError('http', `sync request failed: HTTP ${err.status}`, err);
|
|
136
|
+
}
|
|
137
|
+
if (err instanceof NodeHttpError)
|
|
138
|
+
return new OctoBotHttpError(err.status, err);
|
|
139
|
+
// A base OctoBotError here would make `instanceof OctoBotConnectionError`
|
|
140
|
+
// false on the path most callers actually hit (anything that isn't a
|
|
141
|
+
// recognized typed error, i.e. "could not reach the node at all") —
|
|
142
|
+
// README.md documents that class for exactly this case.
|
|
143
|
+
return new OctoBotConnectionError('unreachable', err instanceof Error ? err.message : String(err), err);
|
|
144
|
+
}
|
|
145
|
+
/** What every `client.*` method's `catch` block calls. Lets an `AbortError`
|
|
146
|
+
* DOMException through unwrapped (the platform convention a caller's own
|
|
147
|
+
* `signal` handling already expects) and wraps everything else as an
|
|
148
|
+
* `OctoBotError`. */
|
|
149
|
+
export function rethrowAsOctoBotError(err) {
|
|
150
|
+
if (err instanceof DOMException && err.name === 'AbortError')
|
|
151
|
+
throw err;
|
|
152
|
+
throw toOctoBotError(err);
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/client/core/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAA;AACpF,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAEvD,OAAO,EAAE,2BAA2B,EAAE,sBAAsB,EAAE,MAAM,kDAAkD,CAAA;AActH;;;;2EAI2E;AAC3E,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC5B,IAAI,CAAkB;IACb,KAAK,CAAU;IACjC,YAAY,IAAsB,EAAE,OAAe,EAAE,KAAe;QAClE,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,cAAc,CAAA;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,KAAK,GAAG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,CAAC,EAAE,GAAG,CAAC,CAAA;AACzG,CAAC;AAED;;;sBAGsB;AACtB,MAAM,UAAU,qBAAqB,CAAC,GAAY;IAChD,IAAI,GAAG,YAAY,YAAY,IAAI,GAAG,CAAC,IAAI,KAAK,YAAY;QAAE,MAAM,GAAG,CAAA;IACvE,MAAM,cAAc,CAAC,GAAG,CAAC,CAAA;AAC3B,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** A `DerivationScheme.id` (see `identity/derivationSchemes.ts`) or `'auto'`. */
|
|
2
|
+
export type SeedDerivation = string;
|
|
3
|
+
export type ConnectOptions = {
|
|
4
|
+
/** Node origin: `'http://192.168.1.10:5001'`, `'https://mybot.example.com'`.
|
|
5
|
+
* A bare `host` / `host:port` is also accepted (parsed the same way the
|
|
6
|
+
* node-pairing flow parses one). */
|
|
7
|
+
url: string;
|
|
8
|
+
/** BIP39 seed phrase, or a 0x-prefixed secp256k1 private key. */
|
|
9
|
+
seed: string;
|
|
10
|
+
/** Which derivation turns the phrase into the wallet.
|
|
11
|
+
* - `'bip44'` (default) — the standard `m/44'/60'/0'/0/0` path, what a
|
|
12
|
+
* node's own pairing QR carries. The only scheme this package ships;
|
|
13
|
+
* register another via `registerDerivationScheme` for a different
|
|
14
|
+
* wallet type and pass its id here.
|
|
15
|
+
* - `'auto'` — try every registered scheme, probe the node, keep whichever
|
|
16
|
+
* it authorizes. Costs one extra round-trip per scheme; only meaningful
|
|
17
|
+
* with `verify: true` (the default). */
|
|
18
|
+
seedDerivation?: SeedDerivation;
|
|
19
|
+
/** HTTP Basic credentials for the node's `/api/v1` REST surface. Only a
|
|
20
|
+
* node paired by an older QR has these — without them `client.node.wallet`,
|
|
21
|
+
* `.dslKeywords` and `.exportWallet`/`.createGenericProcessBot` throw
|
|
22
|
+
* `OctoBotConfigError`. */
|
|
23
|
+
basicAuth?: {
|
|
24
|
+
address: string;
|
|
25
|
+
password: string;
|
|
26
|
+
};
|
|
27
|
+
/** Injected fetch — proxies, mTLS, React Native polyfills, test stubs.
|
|
28
|
+
* Default: `globalThis.fetch`. */
|
|
29
|
+
fetch?: typeof fetch;
|
|
30
|
+
/** Default per-request timeout, ms. Default 10_000. */
|
|
31
|
+
timeoutMs?: number;
|
|
32
|
+
/** Aborts the connect handshake only — not the returned client. */
|
|
33
|
+
signal?: AbortSignal;
|
|
34
|
+
/** Probe the node and the sync auth before resolving. Default `true`.
|
|
35
|
+
* `false` skips all I/O in `connectOctoBot()` — the first real call
|
|
36
|
+
* surfaces any problem instead. */
|
|
37
|
+
verify?: boolean;
|
|
38
|
+
};
|
|
39
|
+
/** Every method that does I/O takes these last. */
|
|
40
|
+
export type CallOptions = {
|
|
41
|
+
signal?: AbortSignal;
|
|
42
|
+
timeoutMs?: number;
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../src/client/core/options.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,MAAM,MAAM,cAAc,GAAG,MAAM,CAAA;AAEnC,MAAM,MAAM,cAAc,GAAG;IAC3B;;yCAEqC;IACrC,GAAG,EAAE,MAAM,CAAA;IACX,iEAAiE;IACjE,IAAI,EAAE,MAAM,CAAA;IACZ;;;;;;;+CAO2C;IAC3C,cAAc,CAAC,EAAE,cAAc,CAAA;IAC/B;;;gCAG4B;IAC5B,SAAS,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAA;IACjD;uCACmC;IACnC,KAAK,CAAC,EAAE,OAAO,KAAK,CAAA;IACpB,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,mEAAmE;IACnE,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB;;wCAEoC;IACpC,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,mDAAmD;AACnD,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../../src/client/core/options.ts"],"names":[],"mappings":""}
|