@orbitflare/sdk 0.1.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.
Files changed (66) hide show
  1. package/README.md +228 -0
  2. package/dist/address.d.ts +7 -0
  3. package/dist/address.d.ts.map +1 -0
  4. package/dist/address.js +8 -0
  5. package/dist/address.js.map +1 -0
  6. package/dist/config.d.ts +31 -0
  7. package/dist/config.d.ts.map +1 -0
  8. package/dist/config.js +111 -0
  9. package/dist/config.js.map +1 -0
  10. package/dist/credentials.d.ts +2 -0
  11. package/dist/credentials.d.ts.map +1 -0
  12. package/dist/credentials.js +25 -0
  13. package/dist/credentials.js.map +1 -0
  14. package/dist/endpoint.d.ts +10 -0
  15. package/dist/endpoint.d.ts.map +1 -0
  16. package/dist/endpoint.js +53 -0
  17. package/dist/endpoint.js.map +1 -0
  18. package/dist/error.d.ts +36 -0
  19. package/dist/error.d.ts.map +1 -0
  20. package/dist/error.js +115 -0
  21. package/dist/error.js.map +1 -0
  22. package/dist/grpc.d.ts +55 -0
  23. package/dist/grpc.d.ts.map +1 -0
  24. package/dist/grpc.js +269 -0
  25. package/dist/grpc.js.map +1 -0
  26. package/dist/index.d.ts +9 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +9 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/jetstream.d.ts +55 -0
  31. package/dist/jetstream.d.ts.map +1 -0
  32. package/dist/jetstream.js +261 -0
  33. package/dist/jetstream.js.map +1 -0
  34. package/dist/proto/geyser.d.ts +495 -0
  35. package/dist/proto/geyser.d.ts.map +1 -0
  36. package/dist/proto/geyser.js +5095 -0
  37. package/dist/proto/geyser.js.map +1 -0
  38. package/dist/proto/google/protobuf/timestamp.d.ts +123 -0
  39. package/dist/proto/google/protobuf/timestamp.d.ts.map +1 -0
  40. package/dist/proto/google/protobuf/timestamp.js +90 -0
  41. package/dist/proto/google/protobuf/timestamp.js.map +1 -0
  42. package/dist/proto/jetstream.d.ts +290 -0
  43. package/dist/proto/jetstream.d.ts.map +1 -0
  44. package/dist/proto/jetstream.js +2926 -0
  45. package/dist/proto/jetstream.js.map +1 -0
  46. package/dist/proto/solana-storage.d.ts +155 -0
  47. package/dist/proto/solana-storage.d.ts.map +1 -0
  48. package/dist/proto/solana-storage.js +2147 -0
  49. package/dist/proto/solana-storage.js.map +1 -0
  50. package/dist/proto.d.ts +4 -0
  51. package/dist/proto.d.ts.map +1 -0
  52. package/dist/proto.js +4 -0
  53. package/dist/proto.js.map +1 -0
  54. package/dist/retry.d.ts +10 -0
  55. package/dist/retry.d.ts.map +1 -0
  56. package/dist/retry.js +17 -0
  57. package/dist/retry.js.map +1 -0
  58. package/dist/rpc.d.ts +87 -0
  59. package/dist/rpc.d.ts.map +1 -0
  60. package/dist/rpc.js +300 -0
  61. package/dist/rpc.js.map +1 -0
  62. package/dist/ws.d.ts +82 -0
  63. package/dist/ws.d.ts.map +1 -0
  64. package/dist/ws.js +412 -0
  65. package/dist/ws.js.map +1 -0
  66. package/package.json +104 -0
package/README.md ADDED
@@ -0,0 +1,228 @@
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/orbitflare/orbitflare-sdk-ts/main/assets/banner.png" alt="@orbitflare/sdk" width="100%">
3
+ </p>
4
+
5
+ <p align="center">
6
+ <a href="https://www.npmjs.com/package/@orbitflare/sdk"><img src="https://img.shields.io/npm/v/@orbitflare/sdk.svg?style=flat-square&color=3CAB9C&labelColor=041815" alt="npm"></a>
7
+ <a href="https://docs.orbitflare.com/sdk/overview"><img src="https://img.shields.io/badge/docs-orbitflare.com-3CAB9C?style=flat-square&labelColor=041815" alt="Documentation"></a>
8
+ </p>
9
+
10
+ # @orbitflare/sdk
11
+
12
+ TypeScript SDK for [OrbitFlare](https://orbitflare.com) - RPC, gRPC (Yellowstone Geyser), JetStream, and WebSocket clients for Solana.
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ npm install @orbitflare/sdk
18
+ ```
19
+
20
+ The RPC client works out of the box. Add only the peer dependencies for the transports you actually use:
21
+
22
+ ```bash
23
+ npm install ws # WebSocket subscriptions
24
+ npm install @grpc/grpc-js # gRPC streaming (Yellowstone, JetStream)
25
+ npm install yaml # YAML stream config files
26
+ ```
27
+
28
+ ## RPC
29
+
30
+ ```ts
31
+ import { RpcClientBuilder } from '@orbitflare/sdk';
32
+
33
+ const client = new RpcClientBuilder()
34
+ .url('http://ny.rpc.orbitflare.com')
35
+ .commitment('confirmed')
36
+ .build();
37
+
38
+ const slot = await client.getSlot();
39
+ const balance = await client.getBalance('CKs1E69a2e9TmH4mKKLrXFF8kD3ZnwKjoEuXa6sz9WqX');
40
+ const { blockhash, lastValidBlockHeight } = await client.getLatestBlockhash();
41
+
42
+ const inflation = await client.request('getInflationRate', []);
43
+
44
+ const raw = await client.requestRaw(
45
+ '{"jsonrpc":"2.0","id":1,"method":"getHealth","params":[]}',
46
+ );
47
+ ```
48
+
49
+ ### Typed helpers
50
+
51
+ | Method | Returns |
52
+ |---|---|
53
+ | `getSlot()` | Current slot (`number`) |
54
+ | `getBalance(address)` | Lamports (`number`) |
55
+ | `getAccountInfo(address)` | Account data or `null` |
56
+ | `getMultipleAccounts(addresses)` | Array of accounts (auto-chunks to 100) |
57
+ | `getLatestBlockhash()` | `{ blockhash, lastValidBlockHeight }` |
58
+ | `getTransaction(signature)` | Full transaction with metadata |
59
+ | `getSignaturesForAddress(address, limit)` | Recent signatures |
60
+ | `getProgramAccounts(programId)` | All accounts owned by a program |
61
+ | `getRecentPrioritizationFees(addresses)` | Recent priority fees |
62
+ | `sendTransaction(txBase64)` | Signature string |
63
+ | `simulateTransaction(txBase64)` | Simulation result |
64
+ | `getTokenAccountsByOwner(owner, mint?, programId?)` | Token accounts |
65
+ | `getTransactionsForAddress(address, options)` | Full transaction history with filters and pagination (OrbitFlare-specific) |
66
+ | `request(method, params)` | Any RPC method by name |
67
+ | `requestRaw(body)` | Raw JSON-RPC body string |
68
+
69
+ ## gRPC (Yellowstone Geyser)
70
+
71
+ Subscribe using a YAML config file:
72
+
73
+ ```yaml
74
+ # grpc.yml
75
+ transactions:
76
+ pumpfun:
77
+ vote: false
78
+ failed: false
79
+ account_include:
80
+ - "6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P"
81
+
82
+ commitment: confirmed
83
+ ```
84
+
85
+ ```ts
86
+ import { GeyserClientBuilder } from '@orbitflare/sdk';
87
+
88
+ const client = new GeyserClientBuilder()
89
+ .url('http://ny.rpc.orbitflare.com:10000')
90
+ .build();
91
+
92
+ const stream = client.subscribeYaml('grpc.yml');
93
+
94
+ for await (const update of stream) {
95
+ if (update.transaction) {
96
+ console.log(`slot=${update.transaction.slot}`);
97
+ }
98
+ }
99
+ ```
100
+
101
+ The YAML format supports `${ENV_VAR}` expansion. You can also call `client.subscribe(request)` with a programmatically constructed `SubscribeRequest`.
102
+
103
+ ## JetStream
104
+
105
+ ```yaml
106
+ # jetstream.yml
107
+ transactions:
108
+ raydium:
109
+ account_include:
110
+ - "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"
111
+ ```
112
+
113
+ ```ts
114
+ import { JetstreamClientBuilder } from '@orbitflare/sdk';
115
+
116
+ const client = new JetstreamClientBuilder()
117
+ .url('http://ny.jetstream.orbitflare.com')
118
+ .build();
119
+
120
+ const stream = client.subscribeYaml('jetstream.yml');
121
+
122
+ for await (const update of stream) {
123
+ if (update.transaction) {
124
+ console.log(`slot=${update.transaction.slot}`);
125
+ }
126
+ }
127
+ ```
128
+
129
+ ## WebSocket
130
+
131
+ ```ts
132
+ import { WsClientBuilder } from '@orbitflare/sdk';
133
+
134
+ const client = await new WsClientBuilder()
135
+ .url('ws://ny.rpc.orbitflare.com')
136
+ .build();
137
+
138
+ const sub = await client.slotSubscribe();
139
+
140
+ while (true) {
141
+ const slot = await sub.next();
142
+ if (slot === undefined) break;
143
+ console.log(slot);
144
+ }
145
+ ```
146
+
147
+ Subscription types: `accountSubscribe`, `logsSubscribe`, `slotSubscribe`, `signatureSubscribe`. All auto-resubscribe on reconnect.
148
+
149
+ ## Endpoint failover
150
+
151
+ All clients support multiple endpoints with automatic failover and health tracking.
152
+
153
+ ```ts
154
+ const client = new RpcClientBuilder()
155
+ .urls([
156
+ 'http://ny.rpc.orbitflare.com',
157
+ 'http://fra.rpc.orbitflare.com',
158
+ 'http://ams.rpc.orbitflare.com',
159
+ ])
160
+ .build();
161
+ ```
162
+
163
+ Failing endpoints are quarantined with exponential cooldown (10s, 20s, 40s, max 60s) and automatically retried once the cooldown expires. Healthy endpoints are always preferred.
164
+
165
+ ## Retry
166
+
167
+ RPC calls retry on transient errors (5xx, 429, connection resets, Solana error codes -32005, -32007, -32014, -32015, -32016) with exponential backoff before failing over to the next endpoint. 429 responses with a `Retry-After` header are respected.
168
+
169
+ gRPC, JetStream, and WebSocket connections use active ping/pong to detect dead connections. Configurable via the builder:
170
+
171
+ ```ts
172
+ const client = new GeyserClientBuilder()
173
+ .url('http://ny.rpc.orbitflare.com:10000')
174
+ .pingIntervalSecs(15) // send a ping every 15s (default: 10)
175
+ .maxMissedPongs(5) // kill connection after 5 missed pongs (default: 3)
176
+ .build();
177
+ ```
178
+
179
+ All three streaming clients reconnect automatically on disconnection. WebSocket also re-subscribes all active subscriptions after reconnecting.
180
+
181
+ Configure retry behavior:
182
+
183
+ ```ts
184
+ import { RpcClientBuilder } from '@orbitflare/sdk';
185
+
186
+ const client = new RpcClientBuilder()
187
+ .url('http://ny.rpc.orbitflare.com')
188
+ .retry({
189
+ initialDelayMs: 200,
190
+ maxDelayMs: 15_000,
191
+ multiplier: 2.0,
192
+ maxAttempts: 5,
193
+ })
194
+ .build();
195
+ ```
196
+
197
+ ## Environment variables
198
+
199
+ | Variable | Used by | Purpose |
200
+ |---|---|---|
201
+ | `ORBITFLARE_LICENSE_KEY` | RPC, WebSocket | API key appended to endpoint URLs |
202
+ | `ORBITFLARE_RPC_URL` | RPC | Default endpoint if `.url()` is not called |
203
+ | `ORBITFLARE_WS_URL` | WebSocket | Default endpoint if `.url()` is not called |
204
+ | `ORBITFLARE_GRPC_URL` | gRPC | Default endpoint if `.url()` is not called |
205
+ | `ORBITFLARE_JETSTREAM_URL` | JetStream | Default endpoint if `.url()` is not called |
206
+
207
+ ## Examples
208
+
209
+ Eight runnable examples live in [`examples/`](./examples), covering every transport in basic and full variants.
210
+
211
+ ```bash
212
+ git clone https://github.com/orbitflare/orbitflare-sdk-ts.git
213
+ cd orbitflare-sdk-ts
214
+ npm install
215
+ npm run proto
216
+ npm run build
217
+
218
+ export ORBITFLARE_LICENSE_KEY=ORBIT-...
219
+
220
+ npm run example:rpc-basic
221
+ npm run example:rpc-full
222
+ npm run example:ws-basic
223
+ npm run example:ws-full
224
+ npm run example:grpc-basic
225
+ npm run example:grpc-full
226
+ npm run example:jetstream-basic
227
+ npm run example:jetstream-full
228
+ ```
@@ -0,0 +1,7 @@
1
+ import { ChannelCredentials } from '@grpc/grpc-js';
2
+ export interface ParsedAddress {
3
+ target: string;
4
+ credentials: ChannelCredentials;
5
+ }
6
+ export declare function parseAddress(url: string): ParsedAddress;
7
+ //# sourceMappingURL=address.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../src/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,kBAAkB,CAAC;CACjC;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAMvD"}
@@ -0,0 +1,8 @@
1
+ import { ChannelCredentials } from '@grpc/grpc-js';
2
+ export function parseAddress(url) {
3
+ const u = new URL(url);
4
+ const port = u.port || (u.protocol === 'https:' ? '443' : '80');
5
+ const credentials = u.protocol === 'https:' ? ChannelCredentials.createSsl() : ChannelCredentials.createInsecure();
6
+ return { target: `${u.hostname}:${port}`, credentials };
7
+ }
8
+ //# sourceMappingURL=address.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"address.js","sourceRoot":"","sources":["../src/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAOnD,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IACvB,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAChE,MAAM,WAAW,GACf,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,kBAAkB,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,kBAAkB,CAAC,cAAc,EAAE,CAAC;IACjG,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC,QAAQ,IAAI,IAAI,EAAE,EAAE,WAAW,EAAE,CAAC;AAC1D,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { type SubscribeRequest as GeyserSubscribeRequest } from './proto/geyser.js';
2
+ import { type SubscribeRequest as JetstreamSubscribeRequest } from './proto/jetstream.js';
3
+ export interface TransactionFilter {
4
+ vote?: boolean;
5
+ failed?: boolean;
6
+ account_include?: string[];
7
+ account_exclude?: string[];
8
+ account_required?: string[];
9
+ }
10
+ export interface AccountFilter {
11
+ account?: string[];
12
+ owner?: string[];
13
+ }
14
+ export interface SlotFilter {
15
+ filter_by_commitment?: boolean;
16
+ }
17
+ export interface GeyserStreamConfig {
18
+ transactions?: Record<string, TransactionFilter>;
19
+ accounts?: Record<string, AccountFilter>;
20
+ slots?: Record<string, SlotFilter>;
21
+ commitment?: string;
22
+ }
23
+ export interface JetstreamStreamConfig {
24
+ transactions?: Record<string, TransactionFilter>;
25
+ accounts?: Record<string, AccountFilter>;
26
+ }
27
+ export declare function loadGeyserConfig(path: string): GeyserStreamConfig;
28
+ export declare function loadJetstreamConfig(path: string): JetstreamStreamConfig;
29
+ export declare function geyserConfigToRequest(cfg: GeyserStreamConfig): GeyserSubscribeRequest;
30
+ export declare function jetstreamConfigToRequest(cfg: JetstreamStreamConfig): JetstreamSubscribeRequest;
31
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,KAAK,gBAAgB,IAAI,sBAAsB,EAIhD,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,KAAK,gBAAgB,IAAI,yBAAyB,EAGnD,MAAM,sBAAsB,CAAC;AAE9B,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,MAAM,WAAW,UAAU;IACzB,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED,MAAM,WAAW,kBAAkB;IACjC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IACjD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,qBAAqB;IACpC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IACjD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CAC1C;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,CAEjE;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,qBAAqB,CAEvE;AAsCD,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,kBAAkB,GAAG,sBAAsB,CA4CrF;AAED,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,qBAAqB,GAAG,yBAAyB,CAwB9F"}
package/dist/config.js ADDED
@@ -0,0 +1,111 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { parse as parseYaml } from 'yaml';
3
+ import { OrbitflareError } from './error.js';
4
+ import { CommitmentLevel, } from './proto/geyser.js';
5
+ export function loadGeyserConfig(path) {
6
+ return readYaml(path);
7
+ }
8
+ export function loadJetstreamConfig(path) {
9
+ return readYaml(path);
10
+ }
11
+ function readYaml(path) {
12
+ let raw;
13
+ try {
14
+ raw = readFileSync(path, 'utf8');
15
+ }
16
+ catch (e) {
17
+ throw OrbitflareError.config(`failed to read ${path}: ${e?.message ?? e}`);
18
+ }
19
+ const expanded = expandEnv(raw);
20
+ try {
21
+ return parseYaml(expanded);
22
+ }
23
+ catch (e) {
24
+ throw OrbitflareError.config(`failed to parse yaml: ${e?.message ?? e}`);
25
+ }
26
+ }
27
+ function expandEnv(input) {
28
+ return input.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g, (_, name) => {
29
+ const v = process.env[name];
30
+ if (v === undefined) {
31
+ throw OrbitflareError.config(`failed to expand env vars: $${name} not set`);
32
+ }
33
+ return v;
34
+ });
35
+ }
36
+ function parseCommitment(s) {
37
+ switch ((s ?? '').toLowerCase()) {
38
+ case 'processed':
39
+ return CommitmentLevel.PROCESSED;
40
+ case 'finalized':
41
+ return CommitmentLevel.FINALIZED;
42
+ default:
43
+ return CommitmentLevel.CONFIRMED;
44
+ }
45
+ }
46
+ export function geyserConfigToRequest(cfg) {
47
+ const transactions = {};
48
+ for (const [name, f] of Object.entries(cfg.transactions ?? {})) {
49
+ transactions[name] = {
50
+ vote: f.vote,
51
+ failed: f.failed,
52
+ signature: undefined,
53
+ accountInclude: f.account_include ?? [],
54
+ accountExclude: f.account_exclude ?? [],
55
+ accountRequired: f.account_required ?? [],
56
+ };
57
+ }
58
+ const accounts = {};
59
+ for (const [name, f] of Object.entries(cfg.accounts ?? {})) {
60
+ accounts[name] = {
61
+ account: f.account ?? [],
62
+ owner: f.owner ?? [],
63
+ filters: [],
64
+ nonemptyTxnSignature: undefined,
65
+ };
66
+ }
67
+ const slots = {};
68
+ for (const [name, f] of Object.entries(cfg.slots ?? {})) {
69
+ slots[name] = {
70
+ filterByCommitment: f.filter_by_commitment,
71
+ interslotUpdates: undefined,
72
+ };
73
+ }
74
+ return {
75
+ accounts,
76
+ slots,
77
+ transactions,
78
+ transactionsStatus: {},
79
+ blocks: {},
80
+ blocksMeta: {},
81
+ entry: {},
82
+ commitment: parseCommitment(cfg.commitment),
83
+ accountsDataSlice: [],
84
+ ping: { id: 1 },
85
+ fromSlot: undefined,
86
+ };
87
+ }
88
+ export function jetstreamConfigToRequest(cfg) {
89
+ const transactions = {};
90
+ for (const [name, f] of Object.entries(cfg.transactions ?? {})) {
91
+ transactions[name] = {
92
+ accountInclude: f.account_include ?? [],
93
+ accountExclude: f.account_exclude ?? [],
94
+ accountRequired: f.account_required ?? [],
95
+ };
96
+ }
97
+ const accounts = {};
98
+ for (const [name, f] of Object.entries(cfg.accounts ?? {})) {
99
+ accounts[name] = {
100
+ account: f.account ?? [],
101
+ owner: f.owner ?? [],
102
+ filters: [],
103
+ };
104
+ }
105
+ return {
106
+ transactions,
107
+ accounts,
108
+ ping: { id: 1 },
109
+ };
110
+ }
111
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,E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AAG;YACf,OAAO,EAAE,CAAC,CAAC,OAAO,IAAI,EAAE;YACxB,KAAK,EAAE,CAAC,CAAC,KAAK,IAAI,EAAE;YACpB,OAAO,EAAE,EAAE;SACZ,CAAC;IACJ,CAAC;IAED,OAAO;QACL,YAAY;QACZ,QAAQ;QACR,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE;KACa,CAAC;AACjC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function applyApiKey(url: string, apiKey: string): string;
2
+ //# sourceMappingURL=credentials.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAgB/D"}
@@ -0,0 +1,25 @@
1
+ export function applyApiKey(url, apiKey) {
2
+ if (apiKey === '' || url.includes('api_key='))
3
+ return url;
4
+ let base;
5
+ let sep;
6
+ if (url.includes('?')) {
7
+ base = url;
8
+ sep = '&';
9
+ }
10
+ else if (hasPath(url)) {
11
+ base = url;
12
+ sep = '?';
13
+ }
14
+ else {
15
+ base = `${url}/`;
16
+ sep = '?';
17
+ }
18
+ return `${base}${sep}api_key=${apiKey}`;
19
+ }
20
+ function hasPath(url) {
21
+ const idx = url.indexOf('://');
22
+ const after = idx === -1 ? url : url.slice(idx + 3);
23
+ return after.includes('/');
24
+ }
25
+ //# sourceMappingURL=credentials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials.js","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,WAAW,CAAC,GAAW,EAAE,MAAc;IACrD,IAAI,MAAM,KAAK,EAAE,IAAI,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC;QAAE,OAAO,GAAG,CAAC;IAE1D,IAAI,IAAY,CAAC;IACjB,IAAI,GAAW,CAAC;IAChB,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACtB,IAAI,GAAG,GAAG,CAAC;QACX,GAAG,GAAG,GAAG,CAAC;IACZ,CAAC;SAAM,IAAI,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACxB,IAAI,GAAG,GAAG,CAAC;QACX,GAAG,GAAG,GAAG,CAAC;IACZ,CAAC;SAAM,CAAC;QACN,IAAI,GAAG,GAAG,GAAG,GAAG,CAAC;QACjB,GAAG,GAAG,GAAG,CAAC;IACZ,CAAC;IACD,OAAO,GAAG,IAAI,GAAG,GAAG,WAAW,MAAM,EAAE,CAAC;AAC1C,CAAC;AAED,SAAS,OAAO,CAAC,GAAW;IAC1B,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC/B,MAAM,KAAK,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;IACpD,OAAO,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,10 @@
1
+ export declare class EndpointSet {
2
+ private endpoints;
3
+ constructor(primary: string, fallbacks?: string[]);
4
+ get length(): number;
5
+ get(idx: number): string;
6
+ pick(): number;
7
+ markSuccess(idx: number): void;
8
+ markFailure(idx: number): void;
9
+ }
10
+ //# sourceMappingURL=endpoint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoint.d.ts","sourceRoot":"","sources":["../src/endpoint.ts"],"names":[],"mappings":"AAMA,qBAAa,WAAW;IACtB,OAAO,CAAC,SAAS,CAAa;gBAElB,OAAO,EAAE,MAAM,EAAE,SAAS,GAAE,MAAM,EAAO;IASrD,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAMxB,IAAI,IAAI,MAAM;IAgBd,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAO9B,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;CAQ/B"}
@@ -0,0 +1,53 @@
1
+ export class EndpointSet {
2
+ endpoints;
3
+ constructor(primary, fallbacks = []) {
4
+ const now = Date.now();
5
+ this.endpoints = [primary, ...fallbacks].map((url) => ({
6
+ url,
7
+ consecutiveFailures: 0,
8
+ availableAfter: now,
9
+ }));
10
+ }
11
+ get length() {
12
+ return this.endpoints.length;
13
+ }
14
+ get(idx) {
15
+ const ep = this.endpoints[idx];
16
+ if (!ep)
17
+ throw new RangeError(`endpoint index ${idx} out of bounds`);
18
+ return ep.url;
19
+ }
20
+ pick() {
21
+ const now = Date.now();
22
+ for (let i = 0; i < this.endpoints.length; i++) {
23
+ if (now >= this.endpoints[i].availableAfter)
24
+ return i;
25
+ }
26
+ let bestIdx = 0;
27
+ let best = this.endpoints[0].availableAfter;
28
+ for (let i = 1; i < this.endpoints.length; i++) {
29
+ if (this.endpoints[i].availableAfter < best) {
30
+ best = this.endpoints[i].availableAfter;
31
+ bestIdx = i;
32
+ }
33
+ }
34
+ return bestIdx;
35
+ }
36
+ markSuccess(idx) {
37
+ const ep = this.endpoints[idx];
38
+ if (!ep)
39
+ return;
40
+ ep.consecutiveFailures = 0;
41
+ ep.availableAfter = Date.now();
42
+ }
43
+ markFailure(idx) {
44
+ const ep = this.endpoints[idx];
45
+ if (!ep)
46
+ return;
47
+ ep.consecutiveFailures += 1;
48
+ const shift = Math.min(ep.consecutiveFailures, 4);
49
+ const secs = Math.min(5 << shift, 60);
50
+ ep.availableAfter = Date.now() + secs * 1000;
51
+ }
52
+ }
53
+ //# sourceMappingURL=endpoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoint.js","sourceRoot":"","sources":["../src/endpoint.ts"],"names":[],"mappings":"AAMA,MAAM,OAAO,WAAW;IACd,SAAS,CAAa;IAE9B,YAAY,OAAe,EAAE,YAAsB,EAAE;QAC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AAC,cAAc,CAAC;gBACzC,OAAO,GAAG,CAAC,CAAC;YACd,CAAC;QACH,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,WAAW,CAAC,GAAW;QACrB,MAAM,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QAC/B,IAAI,CAAC,EAAE;YAAE,OAAO;QAChB,EAAE,CAAC,mBAAmB,GAAG,CAAC,CAAC;QAC3B,EAAE,CAAC,cAAc,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACjC,CAAC;IAED,WAAW,CAAC,GAAW;QACrB,MAAM,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QAC/B,IAAI,CAAC,EAAE;YAAE,OAAO;QAChB,EAAE,CAAC,mBAAmB,IAAI,CAAC,CAAC;QAC5B,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,CAAC,CAAC;QAClD,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,EAAE,EAAE,CAAC,CAAC;QACtC,EAAE,CAAC,cAAc,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;IAC/C,CAAC;CACF"}
@@ -0,0 +1,36 @@
1
+ export type ErrorKind = 'transport' | 'rpc' | 'grpc' | 'rateLimited' | 'auth' | 'timeout' | 'stream' | 'config' | 'serialization';
2
+ export interface RpcErrorPayload {
3
+ code: number;
4
+ message: string;
5
+ }
6
+ export interface GrpcErrorPayload {
7
+ code: number;
8
+ message: string;
9
+ }
10
+ export declare class OrbitflareError extends Error {
11
+ readonly kind: ErrorKind;
12
+ readonly rpc?: RpcErrorPayload;
13
+ readonly grpc?: GrpcErrorPayload;
14
+ readonly retryAfterMs?: number;
15
+ readonly cause?: unknown;
16
+ constructor(kind: ErrorKind, message: string, extra?: {
17
+ rpc?: RpcErrorPayload;
18
+ grpc?: GrpcErrorPayload;
19
+ retryAfterMs?: number;
20
+ cause?: unknown;
21
+ });
22
+ static transport(cause: unknown, message?: string): OrbitflareError;
23
+ static rpc(code: number, message: string): OrbitflareError;
24
+ static grpc(code: number, message: string): OrbitflareError;
25
+ static rateLimited(retryAfterMs?: number): OrbitflareError;
26
+ static auth(message: string): OrbitflareError;
27
+ static timeout(): OrbitflareError;
28
+ static stream(message: string): OrbitflareError;
29
+ static config(message: string): OrbitflareError;
30
+ static serialization(message: string): OrbitflareError;
31
+ isRetryable(): boolean;
32
+ retryAfter(): number | undefined;
33
+ withEndpoint(endpoint: string): OrbitflareError;
34
+ }
35
+ export declare function sanitizeUrl(url: string): string;
36
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GACjB,WAAW,GACX,KAAK,GACL,MAAM,GACN,aAAa,GACb,MAAM,GACN,SAAS,GACT,QAAQ,GACR,QAAQ,GACR,eAAe,CAAC;AAEpB,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,eAAgB,SAAQ,KAAK;IACxC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,GAAG,CAAC,EAAE,eAAe,CAAC;IAC/B,QAAQ,CAAC,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACjC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;gBAGvB,IAAI,EAAE,SAAS,EACf,OAAO,EAAE,MAAM,EACf,KAAK,GAAE;QACL,GAAG,CAAC,EAAE,eAAe,CAAC;QACt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