@synthient/synthient 1.0.1 → 2.0.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/LICENSE +198 -11
- package/README.md +407 -84
- package/dist/client.d.ts +98 -39
- package/dist/client.js +141 -90
- package/dist/errors.d.ts +72 -0
- package/dist/errors.js +122 -0
- package/dist/events.d.ts +217 -0
- package/dist/events.js +1 -0
- package/dist/feed.d.ts +75 -0
- package/dist/feed.js +192 -0
- package/dist/grpcschema.d.ts +56 -0
- package/dist/grpcschema.js +278 -0
- package/dist/index.d.ts +23 -5
- package/dist/index.js +20 -21
- package/dist/options.d.ts +5 -0
- package/dist/options.js +23 -0
- package/dist/transport.d.ts +76 -0
- package/dist/transport.js +328 -0
- package/dist/types.d.ts +248 -0
- package/dist/types.js +4 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +2 -0
- package/package.json +70 -12
- package/dist/constants.d.ts +0 -2
- package/dist/constants.js +0 -5
- package/dist/exceptions.d.ts +0 -33
- package/dist/exceptions.js +0 -48
- package/dist/models.d.ts +0 -191
- package/dist/models.js +0 -221
- package/dist/utils.d.ts +0 -15
- package/dist/utils.js +0 -29
- package/src/client.ts +0 -106
- package/src/constants.ts +0 -2
- package/src/exceptions.ts +0 -44
- package/src/index.ts +0 -5
- package/src/models.ts +0 -276
- package/src/utils.ts +0 -28
- package/tsconfig.json +0 -15
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetches the protobuf schema of the Synthient gRPC API using gRPC server reflection.
|
|
3
|
+
* It needs the optional peer dependencies `@grpc/grpc-js` and `@bufbuild/protobuf`.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { create, fromBinary } from "@bufbuild/protobuf";
|
|
8
|
+
import { BinaryReader, BinaryWriter, WireType } from "@bufbuild/protobuf/wire";
|
|
9
|
+
import { FileDescriptorProtoSchema, FileDescriptorSetSchema, } from "@bufbuild/protobuf/wkt";
|
|
10
|
+
import { Client, Metadata, credentials, status } from "@grpc/grpc-js";
|
|
11
|
+
import { SynthientError } from "./errors.js";
|
|
12
|
+
import { checkTimeout, resolveAPIKey } from "./options.js";
|
|
13
|
+
export const DEFAULT_ENDPOINT = "grpc.synthient.com:443";
|
|
14
|
+
const MAX_MESSAGE_SIZE = 32 << 20;
|
|
15
|
+
const METHOD = "/grpc.reflection.v1.ServerReflection/ServerReflectionInfo";
|
|
16
|
+
const FILE_BY_FILENAME = 3;
|
|
17
|
+
const FILE_CONTAINING_SYMBOL = 4;
|
|
18
|
+
const LIST_SERVICES = 7;
|
|
19
|
+
const EXPLANATIONS = {
|
|
20
|
+
[status.UNAUTHENTICATED]: "Missing or invalid API key.",
|
|
21
|
+
[status.PERMISSION_DENIED]: "This API key does not have permission to inspect gRPC schemas.",
|
|
22
|
+
[status.NOT_FOUND]: "No protobuf schema found for the requested symbol. Fetch without symbols to list the available services.",
|
|
23
|
+
[status.UNIMPLEMENTED]: "The gRPC endpoint does not expose server reflection.",
|
|
24
|
+
[status.UNAVAILABLE]: "Could not reach the gRPC endpoint. Check the address, network access, and TLS settings.",
|
|
25
|
+
[status.DEADLINE_EXCEEDED]: "Timed out reading protobuf schemas from gRPC reflection. Use a longer timeout.",
|
|
26
|
+
};
|
|
27
|
+
/** Fetching the schema failed. {@link explain} describes common causes. */
|
|
28
|
+
export class SchemaError extends SynthientError {
|
|
29
|
+
name = "SchemaError";
|
|
30
|
+
/**
|
|
31
|
+
* The gRPC status code, as in `status` from `@grpc/grpc-js`, or undefined when the
|
|
32
|
+
* failure was not a gRPC status.
|
|
33
|
+
*/
|
|
34
|
+
code;
|
|
35
|
+
constructor(message, code, options) {
|
|
36
|
+
super(message, options);
|
|
37
|
+
this.code = code;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Fetches the protobuf files that define `options.symbols`, or every listed service,
|
|
42
|
+
* along with all of their imports.
|
|
43
|
+
*/
|
|
44
|
+
export async function fetchSchema(options = {}) {
|
|
45
|
+
const { endpoint, host } = normalizeEndpoint(options.endpoint ?? "");
|
|
46
|
+
const timeout = options.timeout ?? 30_000;
|
|
47
|
+
checkTimeout(timeout);
|
|
48
|
+
const signal = options.signal;
|
|
49
|
+
signal?.throwIfAborted();
|
|
50
|
+
const metadata = new Metadata();
|
|
51
|
+
const apiKey = resolveAPIKey(options.apiKey);
|
|
52
|
+
if (apiKey !== "") {
|
|
53
|
+
metadata.set("x-api-key", apiKey);
|
|
54
|
+
}
|
|
55
|
+
const client = new Client(endpoint, options.plaintext ? credentials.createInsecure() : credentials.createSsl(), { "grpc.max_receive_message_length": MAX_MESSAGE_SIZE });
|
|
56
|
+
const call = client.makeBidiStreamRequest(METHOD, (request) => Buffer.from(request), (response) => response, metadata, { deadline: Date.now() + timeout });
|
|
57
|
+
const cancel = () => {
|
|
58
|
+
call.cancel();
|
|
59
|
+
};
|
|
60
|
+
signal?.addEventListener("abort", cancel, { once: true });
|
|
61
|
+
const replies = call[Symbol.asyncIterator]();
|
|
62
|
+
// Sends every request before reading any reply; the server answers in request order.
|
|
63
|
+
const ask = async (field, values) => {
|
|
64
|
+
for (const value of values) {
|
|
65
|
+
const request = new BinaryWriter()
|
|
66
|
+
.tag(1, WireType.LengthDelimited)
|
|
67
|
+
.string(host)
|
|
68
|
+
.tag(field, WireType.LengthDelimited)
|
|
69
|
+
.string(value)
|
|
70
|
+
.finish();
|
|
71
|
+
call.write(request);
|
|
72
|
+
}
|
|
73
|
+
const answers = [];
|
|
74
|
+
while (answers.length < values.length) {
|
|
75
|
+
const next = await replies.next();
|
|
76
|
+
if (next.done) {
|
|
77
|
+
throw new SchemaError("reflection stream ended early");
|
|
78
|
+
}
|
|
79
|
+
const reply = decodeReply(next.value);
|
|
80
|
+
if (reply.error) {
|
|
81
|
+
throw new SchemaError(reply.error.message || "reflection failed", reply.error.code);
|
|
82
|
+
}
|
|
83
|
+
answers.push(reply);
|
|
84
|
+
}
|
|
85
|
+
return answers;
|
|
86
|
+
};
|
|
87
|
+
const files = new Map();
|
|
88
|
+
const addFiles = (reply) => {
|
|
89
|
+
if (!reply.files) {
|
|
90
|
+
throw new SchemaError("reflection response has no file descriptors");
|
|
91
|
+
}
|
|
92
|
+
for (const bytes of reply.files) {
|
|
93
|
+
let file;
|
|
94
|
+
try {
|
|
95
|
+
file = fromBinary(FileDescriptorProtoSchema, bytes);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
throw new SchemaError("reflection returned an invalid file descriptor", undefined, {
|
|
99
|
+
cause: error,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
if (!file.name) {
|
|
103
|
+
throw new SchemaError("reflection returned a file descriptor without a name");
|
|
104
|
+
}
|
|
105
|
+
if (!files.has(file.name)) {
|
|
106
|
+
files.set(file.name, file);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
try {
|
|
111
|
+
const requested = Array.from(options.symbols ?? [], (symbol) => symbol.trim());
|
|
112
|
+
let symbols = [...new Set(requested)].filter((symbol) => symbol !== "");
|
|
113
|
+
if (symbols.length === 0) {
|
|
114
|
+
const [reply] = await ask(LIST_SERVICES, [""]);
|
|
115
|
+
if (!reply?.services) {
|
|
116
|
+
throw new SchemaError("reflection response has no service list");
|
|
117
|
+
}
|
|
118
|
+
symbols = reply.services
|
|
119
|
+
.map((name) => name.trim())
|
|
120
|
+
.filter((name) => name !== "" && !name.startsWith("grpc.reflection."))
|
|
121
|
+
.sort();
|
|
122
|
+
}
|
|
123
|
+
if (symbols.length === 0) {
|
|
124
|
+
throw new SchemaError("server lists no services");
|
|
125
|
+
}
|
|
126
|
+
for (const reply of await ask(FILE_CONTAINING_SYMBOL, symbols)) {
|
|
127
|
+
addFiles(reply);
|
|
128
|
+
}
|
|
129
|
+
for (;;) {
|
|
130
|
+
const imports = [...files.values()].flatMap((file) => file.dependency);
|
|
131
|
+
const missing = [...new Set(imports)].filter((name) => !files.has(name)).sort();
|
|
132
|
+
if (missing.length === 0) {
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
for (const reply of await ask(FILE_BY_FILENAME, missing)) {
|
|
136
|
+
addFiles(reply);
|
|
137
|
+
}
|
|
138
|
+
const unresolved = missing.find((name) => !files.has(name));
|
|
139
|
+
if (unresolved !== undefined) {
|
|
140
|
+
throw new SchemaError(`reflection did not return dependency ${unresolved}`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
endpoint,
|
|
145
|
+
symbols,
|
|
146
|
+
descriptorSet: create(FileDescriptorSetSchema, { file: dependencyOrder(files) }),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
if (signal?.aborted) {
|
|
151
|
+
throw signal.reason;
|
|
152
|
+
}
|
|
153
|
+
if (error instanceof Error &&
|
|
154
|
+
!(error instanceof SchemaError) &&
|
|
155
|
+
"code" in error &&
|
|
156
|
+
typeof error.code === "number") {
|
|
157
|
+
const { details } = error;
|
|
158
|
+
throw new SchemaError(details || "reflection failed", error.code, { cause: error });
|
|
159
|
+
}
|
|
160
|
+
throw error;
|
|
161
|
+
}
|
|
162
|
+
finally {
|
|
163
|
+
signal?.removeEventListener("abort", cancel);
|
|
164
|
+
call.on("error", () => undefined);
|
|
165
|
+
call.cancel();
|
|
166
|
+
client.close();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Converts `raw`, in any form {@link FetchSchemaOptions.endpoint} accepts, to host:port.
|
|
171
|
+
* `host` is the bare host name, without brackets or a port.
|
|
172
|
+
*/
|
|
173
|
+
export function normalizeEndpoint(raw) {
|
|
174
|
+
let value = raw.trim() || DEFAULT_ENDPOINT;
|
|
175
|
+
if (value.includes("://")) {
|
|
176
|
+
value = URL.parse(value)?.host ?? "";
|
|
177
|
+
}
|
|
178
|
+
value = value.replace(/\/$/, "");
|
|
179
|
+
if (value === "") {
|
|
180
|
+
throw new TypeError("empty gRPC endpoint");
|
|
181
|
+
}
|
|
182
|
+
let host = value;
|
|
183
|
+
if (value.startsWith("[")) {
|
|
184
|
+
const close = value.indexOf("]");
|
|
185
|
+
host = value.slice(1, close === -1 ? undefined : close);
|
|
186
|
+
if (close !== -1 && value.slice(close + 1).startsWith(":")) {
|
|
187
|
+
return { endpoint: value, host };
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
else if (value.split(":").length === 2) {
|
|
191
|
+
return { endpoint: value, host: value.slice(0, value.indexOf(":")) };
|
|
192
|
+
}
|
|
193
|
+
return { endpoint: host.includes(":") ? `[${host}]:443` : `${host}:443`, host };
|
|
194
|
+
}
|
|
195
|
+
/** Returns a human-readable explanation of a common fetch error, or "". */
|
|
196
|
+
export function explain(error) {
|
|
197
|
+
if (!(error instanceof SchemaError) || error.code === undefined) {
|
|
198
|
+
return "";
|
|
199
|
+
}
|
|
200
|
+
return EXPLANATIONS[error.code] ?? "";
|
|
201
|
+
}
|
|
202
|
+
// Decodes a ServerReflectionResponse, keeping only the fields fetchSchema uses.
|
|
203
|
+
function decodeReply(bytes) {
|
|
204
|
+
const reply = {};
|
|
205
|
+
try {
|
|
206
|
+
decode(bytes, (field, reader) => {
|
|
207
|
+
if (field === 4) {
|
|
208
|
+
const files = [];
|
|
209
|
+
decode(reader.bytes(), (inner, value) => {
|
|
210
|
+
if (inner === 1) {
|
|
211
|
+
files.push(value.bytes());
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
reply.files = files;
|
|
215
|
+
}
|
|
216
|
+
else if (field === 6) {
|
|
217
|
+
const services = [];
|
|
218
|
+
decode(reader.bytes(), (inner, value) => {
|
|
219
|
+
if (inner === 1) {
|
|
220
|
+
decode(value.bytes(), (name, service) => {
|
|
221
|
+
if (name === 1) {
|
|
222
|
+
services.push(service.string());
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
reply.services = services;
|
|
228
|
+
}
|
|
229
|
+
else if (field === 7) {
|
|
230
|
+
const error = { code: status.UNKNOWN, message: "" };
|
|
231
|
+
decode(reader.bytes(), (inner, value) => {
|
|
232
|
+
if (inner === 1) {
|
|
233
|
+
error.code = value.int32();
|
|
234
|
+
}
|
|
235
|
+
else if (inner === 2) {
|
|
236
|
+
error.message = value.string();
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
reply.error = error;
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
throw new SchemaError("invalid reflection response", undefined, { cause: error });
|
|
245
|
+
}
|
|
246
|
+
return reply;
|
|
247
|
+
}
|
|
248
|
+
// Fields the visitor leaves unread are skipped.
|
|
249
|
+
function decode(bytes, visit) {
|
|
250
|
+
const reader = new BinaryReader(bytes);
|
|
251
|
+
while (reader.pos < reader.len) {
|
|
252
|
+
const [field, wireType] = reader.tag();
|
|
253
|
+
const start = reader.pos;
|
|
254
|
+
visit(field, reader);
|
|
255
|
+
if (reader.pos === start) {
|
|
256
|
+
reader.skip(wireType, field);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
function dependencyOrder(files) {
|
|
261
|
+
const ordered = [];
|
|
262
|
+
const visited = new Set();
|
|
263
|
+
const visit = (name) => {
|
|
264
|
+
const file = files.get(name);
|
|
265
|
+
if (!file || visited.has(name)) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
visited.add(name);
|
|
269
|
+
for (const dependency of [...file.dependency].sort()) {
|
|
270
|
+
visit(dependency);
|
|
271
|
+
}
|
|
272
|
+
ordered.push(file);
|
|
273
|
+
};
|
|
274
|
+
for (const name of [...files.keys()].sort()) {
|
|
275
|
+
visit(name);
|
|
276
|
+
}
|
|
277
|
+
return ordered;
|
|
278
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The official Node.js client for the Synthient API: IP and domain intelligence,
|
|
3
|
+
* account details, and real-time and bulk data feeds.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { Synthient } from "@synthient/synthient";
|
|
8
|
+
*
|
|
9
|
+
* const client = new Synthient(); // reads SYNTHIENT_API_KEY
|
|
10
|
+
* const info = await client.lookupIP("8.8.8.8");
|
|
11
|
+
* console.log(info.intelligence?.risk_score);
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @module
|
|
15
|
+
*/
|
|
16
|
+
export { DEFAULT_BASE_URL, Synthient, type ClientOptions, type LookupDomainOptions, } from "./client.ts";
|
|
17
|
+
export { APIConnectionError, APIError, APITimeoutError, SynthientError, type APIErrorInit, } from "./errors.ts";
|
|
18
|
+
export type * from "./events.ts";
|
|
19
|
+
export { Feed, dailyExport, hourlyExport, type ListExportsOptions } from "./feed.ts";
|
|
20
|
+
export type { Fetch, RequestOptions, ResponseMetadata } from "./transport.ts";
|
|
21
|
+
export { toDate } from "./types.ts";
|
|
22
|
+
export type * from "./types.ts";
|
|
23
|
+
export { VERSION } from "./version.ts";
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
__exportStar(require("./utils"), exports);
|
|
1
|
+
/**
|
|
2
|
+
* The official Node.js client for the Synthient API: IP and domain intelligence,
|
|
3
|
+
* account details, and real-time and bulk data feeds.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { Synthient } from "@synthient/synthient";
|
|
8
|
+
*
|
|
9
|
+
* const client = new Synthient(); // reads SYNTHIENT_API_KEY
|
|
10
|
+
* const info = await client.lookupIP("8.8.8.8");
|
|
11
|
+
* console.log(info.intelligence?.risk_score);
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @module
|
|
15
|
+
*/
|
|
16
|
+
export { DEFAULT_BASE_URL, Synthient, } from "./client.js";
|
|
17
|
+
export { APIConnectionError, APIError, APITimeoutError, SynthientError, } from "./errors.js";
|
|
18
|
+
export { Feed, dailyExport, hourlyExport } from "./feed.js";
|
|
19
|
+
export { toDate } from "./types.js";
|
|
20
|
+
export { VERSION } from "./version.js";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Rejects a key that a header cannot carry, without putting the key in the error message. */
|
|
2
|
+
export declare function resolveAPIKey(apiKey: string | undefined): string;
|
|
3
|
+
/** The upper bound is the longest delay setTimeout accepts. */
|
|
4
|
+
export declare function checkTimeout(timeout: number): void;
|
|
5
|
+
export declare function limitQuery(limit: number | undefined): Record<string, string>;
|
package/dist/options.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Rejects a key that a header cannot carry, without putting the key in the error message. */
|
|
2
|
+
export function resolveAPIKey(apiKey) {
|
|
3
|
+
const key = (apiKey ?? process.env.SYNTHIENT_API_KEY ?? "").trim();
|
|
4
|
+
if (/[^\x20-\x7e]/.test(key)) {
|
|
5
|
+
throw new TypeError("invalid API key: it must be printable ASCII");
|
|
6
|
+
}
|
|
7
|
+
return key;
|
|
8
|
+
}
|
|
9
|
+
/** The upper bound is the longest delay setTimeout accepts. */
|
|
10
|
+
export function checkTimeout(timeout) {
|
|
11
|
+
if (!Number.isInteger(timeout) || timeout < 1 || timeout > 2 ** 31 - 1) {
|
|
12
|
+
throw new RangeError("timeout must be an integer number of milliseconds from 1 to 2147483647");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function limitQuery(limit) {
|
|
16
|
+
if (limit === undefined) {
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
if (!Number.isSafeInteger(limit) || limit < 1) {
|
|
20
|
+
throw new RangeError("limit must be a positive integer");
|
|
21
|
+
}
|
|
22
|
+
return { limit: String(limit) };
|
|
23
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { APIError } from "./errors.ts";
|
|
2
|
+
export type Fetch = (input: string, init: RequestInit) => Promise<Response>;
|
|
3
|
+
export interface ResponseMetadata {
|
|
4
|
+
status: number;
|
|
5
|
+
/** The X-Request-Id header, or "". */
|
|
6
|
+
requestID: string;
|
|
7
|
+
/**
|
|
8
|
+
* A copy of the response headers, including RateLimit-Limit, RateLimit-Remaining,
|
|
9
|
+
* and RateLimit-Reset when present. Headers can contain sensitive data, such as
|
|
10
|
+
* presigned download URLs.
|
|
11
|
+
*/
|
|
12
|
+
headers: Headers;
|
|
13
|
+
}
|
|
14
|
+
export interface RequestOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Cancels the call, which rejects with the signal's reason. Use `AbortSignal.timeout(ms)`
|
|
17
|
+
* to bound a whole call, including retries.
|
|
18
|
+
*/
|
|
19
|
+
signal?: AbortSignal | undefined;
|
|
20
|
+
}
|
|
21
|
+
export type Wait = (ms: number, signal: AbortSignal | undefined) => Promise<void>;
|
|
22
|
+
export declare const kWait: unique symbol;
|
|
23
|
+
export interface TransportConfig {
|
|
24
|
+
apiKey: string;
|
|
25
|
+
baseURL: URL;
|
|
26
|
+
maxRetries: number;
|
|
27
|
+
timeout: number;
|
|
28
|
+
fetch: Fetch;
|
|
29
|
+
userAgent: string;
|
|
30
|
+
onResponse: ((metadata: ResponseMetadata) => void) | undefined;
|
|
31
|
+
wait: Wait;
|
|
32
|
+
}
|
|
33
|
+
export interface Request {
|
|
34
|
+
method?: "GET" | "POST";
|
|
35
|
+
path: string;
|
|
36
|
+
query?: Record<string, string>;
|
|
37
|
+
body?: string;
|
|
38
|
+
accept?: string;
|
|
39
|
+
policy: "transient" | "rateLimit";
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Its signal follows the caller's signal and an idle timer that runs only while the
|
|
43
|
+
* attempt waits on the network.
|
|
44
|
+
*/
|
|
45
|
+
export declare class Attempt {
|
|
46
|
+
#private;
|
|
47
|
+
readonly caller: AbortSignal | undefined;
|
|
48
|
+
readonly signal: AbortSignal;
|
|
49
|
+
constructor(caller: AbortSignal | undefined, timeout: number, surface?: "api" | "storage");
|
|
50
|
+
/**
|
|
51
|
+
* Storage failures are rebuilt without their message or cause, either of which can
|
|
52
|
+
* contain the presigned URL.
|
|
53
|
+
*/
|
|
54
|
+
watch<T>(work: Promise<T>): Promise<T>;
|
|
55
|
+
}
|
|
56
|
+
export declare class Transport {
|
|
57
|
+
#private;
|
|
58
|
+
constructor(config: TransportConfig);
|
|
59
|
+
url(request: Request): string;
|
|
60
|
+
/** The caller must read or cancel the returned response's body. */
|
|
61
|
+
send(request: Request, signal?: AbortSignal): Promise<[Response, Attempt]>;
|
|
62
|
+
json<T extends object>(request: Request, signal?: AbortSignal): Promise<T>;
|
|
63
|
+
stream(request: Request, signal?: AbortSignal): Promise<ReadableStream<Uint8Array>>;
|
|
64
|
+
error(response: Response, attempt: Attempt): Promise<APIError>;
|
|
65
|
+
/**
|
|
66
|
+
* The API key is never sent to the storage host. Errors never include the presigned
|
|
67
|
+
* URL, and storage error bodies are discarded.
|
|
68
|
+
*/
|
|
69
|
+
download(start: URL, signal?: AbortSignal): Promise<ReadableStream<Uint8Array>>;
|
|
70
|
+
}
|
|
71
|
+
export declare function isHTTP(url: URL | null): url is URL;
|
|
72
|
+
export declare function redirectTarget(from: URL, response: Response): URL;
|
|
73
|
+
export declare function wait(ms: number, signal: AbortSignal | undefined): Promise<void>;
|
|
74
|
+
export declare function backoff(attempt: number): number;
|
|
75
|
+
/** Discards a body so its connection can be reused. */
|
|
76
|
+
export declare function drain(response: Response, attempt: Attempt): Promise<void>;
|