@softfault/blacketjs 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.
- package/README.md +210 -0
- package/dist/client.d.ts +620 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/http.d.ts +86 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +734 -0
- package/dist/socket.d.ts +121 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/types.d.ts +420 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +43 -0
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { BlacketJson, BlacketRecord, BlacketUploadFile, BlacketUploadResponse } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* options for {@link BlacketClient} and the low-level http helper
|
|
4
|
+
*/
|
|
5
|
+
export type BlacketClientOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* api origin (defaults to `https://blacket.org`)
|
|
8
|
+
*/
|
|
9
|
+
baseUrl?: string;
|
|
10
|
+
/**
|
|
11
|
+
* raw cookie header value used for authenticated requests
|
|
12
|
+
*/
|
|
13
|
+
cookie?: string;
|
|
14
|
+
/**
|
|
15
|
+
* extra headers added to every http and socket request
|
|
16
|
+
*/
|
|
17
|
+
headers?: HeadersInit;
|
|
18
|
+
/**
|
|
19
|
+
* request timeout in milliseconds. defaults to 10000 (10s)
|
|
20
|
+
*/
|
|
21
|
+
timeoutMs?: number;
|
|
22
|
+
/**
|
|
23
|
+
* number of times to retry 503 responses. defaults to 2
|
|
24
|
+
*/
|
|
25
|
+
retry503?: number;
|
|
26
|
+
/**
|
|
27
|
+
* custom fetch implementation for tests or alternate runtimes
|
|
28
|
+
*/
|
|
29
|
+
fetch?: typeof fetch;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* thrown when blacket returns a non-json or otherwise unwrapped failed response
|
|
33
|
+
*/
|
|
34
|
+
export declare class BlacketHttpError extends Error {
|
|
35
|
+
/**
|
|
36
|
+
* http response status
|
|
37
|
+
*/
|
|
38
|
+
readonly status: number;
|
|
39
|
+
/**
|
|
40
|
+
* parsed response body, or text when json parsing failed
|
|
41
|
+
*/
|
|
42
|
+
readonly body: unknown;
|
|
43
|
+
constructor(status: number, body: unknown);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* minimal http client used by the sdk categories
|
|
47
|
+
*/
|
|
48
|
+
export declare class BlacketHttp {
|
|
49
|
+
/**
|
|
50
|
+
* normalized base api url
|
|
51
|
+
*/
|
|
52
|
+
readonly baseUrl: string;
|
|
53
|
+
private readonly cookie?;
|
|
54
|
+
private readonly headers?;
|
|
55
|
+
private readonly timeoutMs;
|
|
56
|
+
private readonly retry503;
|
|
57
|
+
private readonly fetchFn;
|
|
58
|
+
constructor(options?: BlacketClientOptions);
|
|
59
|
+
/**
|
|
60
|
+
* sends a get request and parses the response
|
|
61
|
+
*/
|
|
62
|
+
get<T = unknown>(path: string): Promise<T>;
|
|
63
|
+
/**
|
|
64
|
+
* sends a json post request and parses the response
|
|
65
|
+
*/
|
|
66
|
+
post<T = unknown>(path: string, body?: BlacketJson | BlacketRecord): Promise<T>;
|
|
67
|
+
/**
|
|
68
|
+
* runs blacket's signed upload flow and returns the public url
|
|
69
|
+
*/
|
|
70
|
+
upload<T extends BlacketUploadResponse = BlacketUploadResponse>(path: string, file: BlacketUploadFile): Promise<T>;
|
|
71
|
+
/**
|
|
72
|
+
* builds a websocket url for the configured base url
|
|
73
|
+
*/
|
|
74
|
+
socketUrl(path?: string): string;
|
|
75
|
+
/**
|
|
76
|
+
* builds websocket headers, including the configured cookie
|
|
77
|
+
*/
|
|
78
|
+
socketHeaders(headers?: HeadersInit): Headers;
|
|
79
|
+
private request;
|
|
80
|
+
private requestHeaders;
|
|
81
|
+
private url;
|
|
82
|
+
private readBody;
|
|
83
|
+
private isRecord;
|
|
84
|
+
private wait;
|
|
85
|
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CAAC,CAAC,CAAC;IAIhD;;OAEG;IACG,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,WAAW,GAAG,aAAkB,GAAG,OAAO,CAAC,CAAC,CAAC;IAIzF;;OAEG;IACG,MAAM,CAAC,CAAC,SAAS,qBAAqB,GAAG,qBAAqB,EAChE,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,iBAAiB,GACxB,OAAO,CAAC,CAAC,CAAC;IAuCb;;OAEG;IACH,SAAS,CAAC,IAAI,SAAmB,GAAG,MAAM;IAM1C;;OAEG;IACH,aAAa,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO;YAc/B,OAAO;IAyCrB,OAAO,CAAC,cAAc;IAmBtB,OAAO,CAAC,GAAG;YAQG,QAAQ;IActB,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,IAAI;CAGf"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { BlacketClient } from "./client";
|
|
2
|
+
export { BlacketHttp, BlacketHttpError, type BlacketClientOptions } from "./http";
|
|
3
|
+
export { BlacketSocket, type BlacketSocketCallback, type BlacketSocketEmitEvents, type BlacketSocketEvents, type BlacketSocketMessage, type BlacketSocketOptions, } from "./socket";
|
|
4
|
+
export type * from "./types";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,KAAK,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAClF,OAAO,EACH,aAAa,EACb,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,EAC5B,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,GAC5B,MAAM,UAAU,CAAC;AAClB,mBAAmB,SAAS,CAAC"}
|