@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.
Files changed (42) hide show
  1. package/README.md +83 -136
  2. package/dist/client.d.ts +30 -102
  3. package/dist/client.d.ts.map +1 -1
  4. package/dist/client.js +120 -325
  5. package/dist/client.js.map +1 -1
  6. package/dist/errors.d.ts +48 -93
  7. package/dist/errors.d.ts.map +1 -1
  8. package/dist/errors.js +131 -137
  9. package/dist/errors.js.map +1 -1
  10. package/dist/generated/compiled.d.ts +182 -0
  11. package/dist/generated/compiled.d.ts.map +1 -0
  12. package/dist/generated/compiled.js +25761 -0
  13. package/dist/generated/compiled.js.map +1 -0
  14. package/dist/generated/types.d.ts +387 -0
  15. package/dist/generated/types.d.ts.map +1 -0
  16. package/dist/generated/types.js +2 -0
  17. package/dist/generated/types.js.map +1 -0
  18. package/dist/generated/validation.d.ts +18 -0
  19. package/dist/generated/validation.d.ts.map +1 -0
  20. package/dist/generated/validation.js +184 -0
  21. package/dist/generated/validation.js.map +1 -0
  22. package/dist/generated/validators.d.ts +3 -0
  23. package/dist/generated/validators.d.ts.map +1 -0
  24. package/dist/generated/validators.js +10 -0
  25. package/dist/generated/validators.js.map +1 -0
  26. package/dist/http.d.ts +91 -35
  27. package/dist/http.d.ts.map +1 -1
  28. package/dist/http.js +345 -243
  29. package/dist/http.js.map +1 -1
  30. package/dist/index.d.ts +8 -5
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +7 -5
  33. package/dist/index.js.map +1 -1
  34. package/dist/types.d.ts +90 -83
  35. package/dist/types.d.ts.map +1 -1
  36. package/dist/types.js +16 -155
  37. package/dist/types.js.map +1 -1
  38. package/dist/wait.d.ts +65 -0
  39. package/dist/wait.d.ts.map +1 -0
  40. package/dist/wait.js +192 -0
  41. package/dist/wait.js.map +1 -0
  42. package/package.json +6 -3
package/dist/http.d.ts CHANGED
@@ -1,45 +1,101 @@
1
1
  /**
2
- * The single HTTP transport used by the SDK.
2
+ * HTTP transport for `@syndroo/sdk`.
3
3
  *
4
- * Invariants this module enforces for every request:
4
+ * Scope, deliberately narrow:
5
5
  *
6
- * - exactly one network request per call; the SDK never retries a write,
7
- * because a retry without a stable idempotency key can duplicate a post;
8
- * - redirects are not followed, so the `Authorization` header can never reach
9
- * a redirect target;
10
- * - every request is bounded by a finite deadline;
11
- * - the response body is read with a size limit, so an oversized or hostile
12
- * response cannot exhaust the caller's memory;
13
- * - no logging, so credentials and content never reach stdout or stderr.
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
- export declare const DEFAULT_TIMEOUT_MS = 30000;
16
- export declare const DEFAULT_MAX_RESPONSE_BYTES: number;
17
- export declare const MIN_MAX_RESPONSE_BYTES = 1024;
18
- export interface TransportConfig {
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
- timeoutMs: number;
22
- maxResponseBytes: number;
23
- }
24
- export interface TransportRequest {
25
- method: "GET" | "POST";
26
- path: string;
27
- query?: Record<string, string> | undefined;
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
- export declare function sendRequest(config: TransportConfig, request: TransportRequest): Promise<TransportResponse>;
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
- * Node keeps the process alive for a pending timer. An SDK call must not pin a
42
- * CLI process open after its response or its deadline.
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 unrefTimer(handle: unknown): void;
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
@@ -1 +1 @@
1
- {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAYH,eAAO,MAAM,kBAAkB,QAAS,CAAC;AACzC,eAAO,MAAM,0BAA0B,QAAkB,CAAC;AAC1D,eAAO,MAAM,sBAAsB,OAAO,CAAC;AAI3C,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,KAAK,GAAG,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,CA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