@syndroo/sdk 0.4.0-rc.1 → 0.7.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 +83 -136
- package/dist/client.d.ts +30 -102
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +120 -325
- package/dist/client.js.map +1 -1
- package/dist/errors.d.ts +48 -93
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +131 -137
- package/dist/errors.js.map +1 -1
- package/dist/generated/compiled.d.ts +182 -0
- package/dist/generated/compiled.d.ts.map +1 -0
- package/dist/generated/compiled.js +25761 -0
- package/dist/generated/compiled.js.map +1 -0
- package/dist/generated/types.d.ts +387 -0
- package/dist/generated/types.d.ts.map +1 -0
- package/dist/generated/types.js +2 -0
- package/dist/generated/types.js.map +1 -0
- package/dist/generated/validation.d.ts +18 -0
- package/dist/generated/validation.d.ts.map +1 -0
- package/dist/generated/validation.js +184 -0
- package/dist/generated/validation.js.map +1 -0
- package/dist/generated/validators.d.ts +3 -0
- package/dist/generated/validators.d.ts.map +1 -0
- package/dist/generated/validators.js +10 -0
- package/dist/generated/validators.js.map +1 -0
- package/dist/http.d.ts +91 -35
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +345 -243
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +8 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -5
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +90 -83
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +16 -155
- package/dist/types.js.map +1 -1
- package/dist/wait.d.ts +65 -0
- package/dist/wait.d.ts.map +1 -0
- package/dist/wait.js +192 -0
- package/dist/wait.js.map +1 -0
- package/package.json +6 -3
package/dist/http.d.ts
CHANGED
|
@@ -1,45 +1,101 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* HTTP transport for `@syndroo/sdk`.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Scope, deliberately narrow:
|
|
5
5
|
*
|
|
6
|
-
* -
|
|
7
|
-
*
|
|
8
|
-
* -
|
|
9
|
-
* a
|
|
10
|
-
* -
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
6
|
+
* - `POST /v1/connect`, `POST /v1/publish`, `POST /v1/status` only. There is no
|
|
7
|
+
* GET business route, no health probe and no CRUD family.
|
|
8
|
+
* - The bearer secret is required and travels only in the `Authorization`
|
|
9
|
+
* header. It is never placed in a URL, a query string or an error.
|
|
10
|
+
* - The base URL is checked before any socket is opened. Credentials/userinfo,
|
|
11
|
+
* a query and a fragment are rejected, and plain HTTP is accepted only for a
|
|
12
|
+
* loopback host, because a remote cleartext endpoint would expose the bearer
|
|
13
|
+
* secret to the network.
|
|
14
|
+
* - Redirects are never followed (`redirect: "manual"`). Following one would
|
|
15
|
+
* forward the `Authorization` header to an origin the caller never chose.
|
|
16
|
+
* - A request body is bounded and validated by the generated validator (64 KiB);
|
|
17
|
+
* a response is read with a hard 1 MiB cap while streaming, decoded as strict
|
|
18
|
+
* UTF-8 and parsed by the generated bounded parser, then validated as an
|
|
19
|
+
* envelope whose `operation` must match the call.
|
|
20
|
+
* - Transport retries reuse one idempotency key. A valid envelope is never
|
|
21
|
+
* retried, whatever its business result says: `failed`, `partial` and
|
|
22
|
+
* `unknown` are protocol successes, not transport errors.
|
|
14
23
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
export
|
|
24
|
+
import { type WireName } from "./generated/validators.js";
|
|
25
|
+
import type { FetchLike, WireOperation } from "./types.js";
|
|
26
|
+
/** Protocol and transport bounds. Changing one is an API decision. */
|
|
27
|
+
export declare const LIMITS: Readonly<{
|
|
28
|
+
/** Largest request body the wire protocol accepts. */
|
|
29
|
+
maxRequestBytes: 65536;
|
|
30
|
+
/** Largest response body the SDK will buffer. */
|
|
31
|
+
maxResponseBytes: 1048576;
|
|
32
|
+
/** Default per-request deadline. */
|
|
33
|
+
defaultTimeoutMs: 30000;
|
|
34
|
+
/** Smallest accepted per-request deadline. */
|
|
35
|
+
minTimeoutMs: 1;
|
|
36
|
+
/** Largest per-request deadline the protocol allows. */
|
|
37
|
+
maxTimeoutMs: 120000;
|
|
38
|
+
/** Largest number of transport retries the protocol allows. */
|
|
39
|
+
maxTransportRetries: 2;
|
|
40
|
+
/** Longest accepted caller-supplied idempotency key. */
|
|
41
|
+
maxIdempotencyKeyLength: 128;
|
|
42
|
+
}>;
|
|
43
|
+
export type TransportConfig = {
|
|
19
44
|
baseUrl: string;
|
|
20
45
|
apiKey: string;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
json?: unknown;
|
|
29
|
-
idempotencyKey?: string | undefined;
|
|
30
|
-
/** `false` for unauthenticated endpoints such as `/health`. */
|
|
31
|
-
authenticated?: boolean | undefined;
|
|
32
|
-
signal?: AbortSignal | undefined;
|
|
33
|
-
timeoutMs?: number | undefined;
|
|
34
|
-
}
|
|
35
|
-
export interface TransportResponse {
|
|
36
|
-
status: number;
|
|
46
|
+
fetch: FetchLike;
|
|
47
|
+
};
|
|
48
|
+
/** One prepared transport call. */
|
|
49
|
+
export type TransportRequest = {
|
|
50
|
+
operation: WireOperation;
|
|
51
|
+
/** Generated wire name of the request body, used for validation. */
|
|
52
|
+
wireName: WireName;
|
|
37
53
|
body: unknown;
|
|
38
|
-
|
|
39
|
-
|
|
54
|
+
idempotencyKey?: string;
|
|
55
|
+
timeoutMs: number;
|
|
56
|
+
transportRetries: number;
|
|
57
|
+
signal?: AbortSignal;
|
|
58
|
+
};
|
|
59
|
+
/** The loopback hosts that may be reached over plain HTTP. */
|
|
60
|
+
export declare function isLoopbackHostname(hostname: string): boolean;
|
|
40
61
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
62
|
+
* Validate a base URL, or throw a static `INSECURE_BASE_URL` error.
|
|
63
|
+
*
|
|
64
|
+
* Rejected: a non-absolute URL, a scheme other than HTTP or HTTPS, embedded
|
|
65
|
+
* credentials, a query, a fragment, and plain HTTP to anything that is not
|
|
66
|
+
* loopback.
|
|
43
67
|
*/
|
|
44
|
-
export declare function
|
|
68
|
+
export declare function assertUsableBaseUrl(raw: string): URL;
|
|
69
|
+
/** Validate the API key before any request is built. */
|
|
70
|
+
export declare function assertApiKey(apiKey: string): string;
|
|
71
|
+
/** Validate a caller- or SDK-generated idempotency key. */
|
|
72
|
+
export declare function assertIdempotencyKey(key: string): string;
|
|
73
|
+
/** Resolve and bound the per-call transport options. */
|
|
74
|
+
export declare function resolveTransportOptions(options: {
|
|
75
|
+
timeoutMs?: number;
|
|
76
|
+
transportRetries?: number;
|
|
77
|
+
}): {
|
|
78
|
+
timeoutMs: number;
|
|
79
|
+
transportRetries: number;
|
|
80
|
+
};
|
|
81
|
+
/** Keep a pending timer from holding the process open, when the runtime allows it. */
|
|
82
|
+
export declare function unrefTimer(timer: unknown): void;
|
|
83
|
+
/**
|
|
84
|
+
* A transport bound to one base URL and one bearer secret.
|
|
85
|
+
*
|
|
86
|
+
* The class owns the retry loop, so a retry always reuses the same idempotency
|
|
87
|
+
* key: the key is part of `TransportRequest` and is never regenerated.
|
|
88
|
+
*/
|
|
89
|
+
export declare class HttpTransport {
|
|
90
|
+
private readonly baseUrl;
|
|
91
|
+
private readonly apiKey;
|
|
92
|
+
private readonly fetchImpl;
|
|
93
|
+
constructor(config: TransportConfig);
|
|
94
|
+
/** The origin the transport will talk to; safe for tests and diagnostics. */
|
|
95
|
+
get endpointOrigin(): string;
|
|
96
|
+
/** Validate the body, then send it, retrying only transport-level failures. */
|
|
97
|
+
send(request: TransportRequest): Promise<unknown>;
|
|
98
|
+
private buildUrl;
|
|
99
|
+
private attempt;
|
|
100
|
+
}
|
|
45
101
|
//# sourceMappingURL=http.d.ts.map
|
package/dist/http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAIH,OAAO,EAAgB,KAAK,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,KAAK,EAAY,SAAS,EAAa,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhF,sEAAsE;AACtE,eAAO,MAAM,MAAM;IACjB,sDAAsD;;IAEtD,iDAAiD;;IAEjD,oCAAoC;;IAEpC,8CAA8C;;IAE9C,wDAAwD;;IAExD,+DAA+D;;IAE/D,wDAAwD;;EAExD,CAAC;AAwBH,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,SAAS,CAAC;CAClB,CAAC;AAEF,mCAAmC;AACnC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,aAAa,CAAC;IACzB,oEAAoE;IACpE,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,OAAO,CAAC;IACd,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,CAAC;AAEF,8DAA8D;AAC9D,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAiB5D;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAuBpD;AAED,wDAAwD;AACxD,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAKnD;AAED,2DAA2D;AAC3D,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAKxD;AASD,wDAAwD;AACxD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE;IAC/C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,gBAAgB,EAAE,MAAM,CAAA;CAAE,CAUlD;AAED,sFAAsF;AACtF,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAI/C;AA0GD;;;;;GAKG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAM;IAC9B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAY;IAEtC,YAAY,MAAM,EAAE,eAAe,EAIlC;IAED,6EAA6E;IAC7E,IAAI,cAAc,IAAI,MAAM,CAE3B;IAED,+EAA+E;IACzE,IAAI,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,CA4BtD;IAED,OAAO,CAAC,QAAQ;YAKF,OAAO;CA6CtB"}
|