@bevorai/sdk 0.0.0-stage → 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 (130) hide show
  1. package/README.md +179 -2
  2. package/dist/client.d.ts +86 -0
  3. package/dist/client.d.ts.map +1 -0
  4. package/dist/client.js +171 -0
  5. package/dist/client.js.map +1 -0
  6. package/dist/errors.d.ts +109 -0
  7. package/dist/errors.d.ts.map +1 -0
  8. package/dist/errors.js +132 -0
  9. package/dist/errors.js.map +1 -0
  10. package/dist/graph/call-node.d.ts +47 -0
  11. package/dist/graph/call-node.d.ts.map +1 -0
  12. package/dist/graph/call-node.js +338 -0
  13. package/dist/graph/call-node.js.map +1 -0
  14. package/dist/graph/cursor.d.ts +46 -0
  15. package/dist/graph/cursor.d.ts.map +1 -0
  16. package/dist/graph/cursor.js +149 -0
  17. package/dist/graph/cursor.js.map +1 -0
  18. package/dist/graph/field-metadata.d.ts +24 -0
  19. package/dist/graph/field-metadata.d.ts.map +1 -0
  20. package/dist/graph/field-metadata.js +72 -0
  21. package/dist/graph/field-metadata.js.map +1 -0
  22. package/dist/graph/graph.d.ts +87 -0
  23. package/dist/graph/graph.d.ts.map +1 -0
  24. package/dist/graph/graph.js +354 -0
  25. package/dist/graph/graph.js.map +1 -0
  26. package/dist/helpers/call-chain.d.ts +11 -0
  27. package/dist/helpers/call-chain.d.ts.map +1 -0
  28. package/dist/helpers/call-chain.js +79 -0
  29. package/dist/helpers/call-chain.js.map +1 -0
  30. package/dist/helpers/sarif.d.ts +21 -0
  31. package/dist/helpers/sarif.d.ts.map +1 -0
  32. package/dist/helpers/sarif.js +191 -0
  33. package/dist/helpers/sarif.js.map +1 -0
  34. package/dist/helpers/source-fingerprint.d.ts +32 -0
  35. package/dist/helpers/source-fingerprint.d.ts.map +1 -0
  36. package/dist/helpers/source-fingerprint.js +115 -0
  37. package/dist/helpers/source-fingerprint.js.map +1 -0
  38. package/dist/helpers/static-analysis.d.ts +18 -0
  39. package/dist/helpers/static-analysis.d.ts.map +1 -0
  40. package/dist/helpers/static-analysis.js +89 -0
  41. package/dist/helpers/static-analysis.js.map +1 -0
  42. package/dist/index.d.ts +31 -0
  43. package/dist/index.d.ts.map +1 -0
  44. package/dist/index.js +29 -0
  45. package/dist/index.js.map +1 -0
  46. package/dist/node.d.ts +4 -0
  47. package/dist/node.d.ts.map +1 -0
  48. package/dist/node.js +26 -0
  49. package/dist/node.js.map +1 -0
  50. package/dist/pagination.d.ts +13 -0
  51. package/dist/pagination.d.ts.map +1 -0
  52. package/dist/pagination.js +30 -0
  53. package/dist/pagination.js.map +1 -0
  54. package/dist/resources/analyses.d.ts +90 -0
  55. package/dist/resources/analyses.d.ts.map +1 -0
  56. package/dist/resources/analyses.js +250 -0
  57. package/dist/resources/analyses.js.map +1 -0
  58. package/dist/resources/chats.d.ts +48 -0
  59. package/dist/resources/chats.d.ts.map +1 -0
  60. package/dist/resources/chats.js +114 -0
  61. package/dist/resources/chats.js.map +1 -0
  62. package/dist/resources/codes.d.ts +64 -0
  63. package/dist/resources/codes.d.ts.map +1 -0
  64. package/dist/resources/codes.js +200 -0
  65. package/dist/resources/codes.js.map +1 -0
  66. package/dist/resources/files.d.ts +26 -0
  67. package/dist/resources/files.d.ts.map +1 -0
  68. package/dist/resources/files.js +45 -0
  69. package/dist/resources/files.js.map +1 -0
  70. package/dist/resources/findings.d.ts +49 -0
  71. package/dist/resources/findings.d.ts.map +1 -0
  72. package/dist/resources/findings.js +84 -0
  73. package/dist/resources/findings.js.map +1 -0
  74. package/dist/resources/nodes.d.ts +33 -0
  75. package/dist/resources/nodes.d.ts.map +1 -0
  76. package/dist/resources/nodes.js +65 -0
  77. package/dist/resources/nodes.js.map +1 -0
  78. package/dist/resources/projects.d.ts +11 -0
  79. package/dist/resources/projects.d.ts.map +1 -0
  80. package/dist/resources/projects.js +14 -0
  81. package/dist/resources/projects.js.map +1 -0
  82. package/dist/resources/shared.d.ts +14 -0
  83. package/dist/resources/shared.d.ts.map +1 -0
  84. package/dist/resources/shared.js +2 -0
  85. package/dist/resources/shared.js.map +1 -0
  86. package/dist/resources/summary.d.ts +17 -0
  87. package/dist/resources/summary.d.ts.map +1 -0
  88. package/dist/resources/summary.js +27 -0
  89. package/dist/resources/summary.js.map +1 -0
  90. package/dist/resources/transitions.d.ts +25 -0
  91. package/dist/resources/transitions.d.ts.map +1 -0
  92. package/dist/resources/transitions.js +30 -0
  93. package/dist/resources/transitions.js.map +1 -0
  94. package/dist/resources/users.d.ts +19 -0
  95. package/dist/resources/users.d.ts.map +1 -0
  96. package/dist/resources/users.js +36 -0
  97. package/dist/resources/users.js.map +1 -0
  98. package/dist/resources/versions.d.ts +20 -0
  99. package/dist/resources/versions.d.ts.map +1 -0
  100. package/dist/resources/versions.js +25 -0
  101. package/dist/resources/versions.js.map +1 -0
  102. package/dist/streaming.d.ts +43 -0
  103. package/dist/streaming.d.ts.map +1 -0
  104. package/dist/streaming.js +147 -0
  105. package/dist/streaming.js.map +1 -0
  106. package/dist/types/graph-data.d.ts +62 -0
  107. package/dist/types/graph-data.d.ts.map +1 -0
  108. package/dist/types/graph-data.js +2 -0
  109. package/dist/types/graph-data.js.map +1 -0
  110. package/dist/types/literals.d.ts +27 -0
  111. package/dist/types/literals.d.ts.map +1 -0
  112. package/dist/types/literals.js +16 -0
  113. package/dist/types/literals.js.map +1 -0
  114. package/dist/types/node-types.d.ts +5 -0
  115. package/dist/types/node-types.d.ts.map +1 -0
  116. package/dist/types/node-types.js +292 -0
  117. package/dist/types/node-types.js.map +1 -0
  118. package/dist/types/requests.d.ts +205 -0
  119. package/dist/types/requests.d.ts.map +1 -0
  120. package/dist/types/requests.js +3 -0
  121. package/dist/types/requests.js.map +1 -0
  122. package/dist/types/responses.d.ts +448 -0
  123. package/dist/types/responses.d.ts.map +1 -0
  124. package/dist/types/responses.js +11 -0
  125. package/dist/types/responses.js.map +1 -0
  126. package/dist/types/static-analysis.d.ts +28 -0
  127. package/dist/types/static-analysis.d.ts.map +1 -0
  128. package/dist/types/static-analysis.js +93 -0
  129. package/dist/types/static-analysis.js.map +1 -0
  130. package/package.json +46 -5
package/README.md CHANGED
@@ -1,3 +1,180 @@
1
- # Temporary Holding Version
1
+ # @bevor/sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ TypeScript SDK for the [Bevor](https://bevor.io) API: smart contract security analysis for Solidity.
4
+
5
+ > **Research preview.** The API and this SDK may change between minor versions until 1.0.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @bevor/sdk
11
+ # or
12
+ pnpm add @bevor/sdk
13
+ ```
14
+
15
+ Requires Node 20.3+ (or any runtime with `fetch` and `AbortSignal.any`). The package is ESM.
16
+
17
+ ## Quickstart
18
+
19
+ Create an API key in the Bevor dashboard, then:
20
+
21
+ ```ts
22
+ import { readFile } from "node:fs/promises";
23
+ import { BevorClient } from "@bevor/sdk";
24
+
25
+ const client = new BevorClient({ apiKey: "bvr_..." });
26
+
27
+ const code = await client.codes.createPaste({
28
+ content: await readFile("Vault.sol", "utf8"),
29
+ });
30
+
31
+ const created = await client.analyses.createRoot({ code_id: code.id });
32
+ if (!created.is_created)
33
+ throw new Error("an analysis for this code already exists");
34
+ const { analysis } = created;
35
+
36
+ const run = await client.analyses.run(analysis.id, undefined, {
37
+ withStreaming: true,
38
+ });
39
+ for await (const event of run.streamCompletion()) {
40
+ console.log(event.type, event.payload.status);
41
+ }
42
+
43
+ const findings = await client.analyses.listFindings(analysis.id);
44
+ for (const finding of findings.results) {
45
+ console.log(finding.level, finding.name);
46
+ }
47
+ ```
48
+
49
+ ## Usage
50
+
51
+ Every method takes optional per-call `RequestOptions` as its last argument: `headers`, an abort
52
+ `signal` and a `timeout` in ms. Client-wide `defaultHeaders`, `timeout` (default 120 s) and a custom
53
+ `fetch` are set on the constructor.
54
+
55
+ Responses are the API's JSON, typed. Timestamps are ISO 8601 strings.
56
+
57
+ ### Bound resources
58
+
59
+ `with(id)` returns the same methods without the id argument:
60
+
61
+ ```ts
62
+ const analysis = client.analyses.with(analysisId);
63
+ await analysis.commit();
64
+ await analysis.listFindings({ version_id: versionId });
65
+
66
+ const nodes = client.codes.with(codeId).nodes;
67
+ const entrypoints = await nodes.list({ entrypoint_only: true });
68
+ ```
69
+
70
+ ### Pagination
71
+
72
+ List endpoints return one page. Pass `withPagination: true` to accumulate pages:
73
+
74
+ ```ts
75
+ const findings = await client.findings.list(
76
+ { level: "critical" },
77
+ { withPagination: true },
78
+ );
79
+ while (findings.hasMore) await findings.fetchNext();
80
+ console.log(findings.results.length);
81
+ ```
82
+
83
+ ### Streaming
84
+
85
+ `analyses.run`, `analyses.retry`, `codes.uploadFolderZip`, `codes.createPublicRepo` and
86
+ `codes.createConnectedRepo` accept `withStreaming: true` and return an `EventResource`. Its
87
+ `streamCompletion()` yields progress events until processing finishes. Status events
88
+ (`analysis.pipeline`, `code.status`) refresh `.data`; the others (`analysis.run`, `code.step`) are
89
+ progress only. Each event's `type` is its SSE event name, so unions narrow with a `switch`.
90
+
91
+ Chat replies stream with `chats.stream`:
92
+
93
+ ```ts
94
+ const token = await client.chats.sessionToken(chatId);
95
+ for await (const message of client.chats.stream(chatId, token, {
96
+ message: "Is deposit reentrant?",
97
+ })) {
98
+ if (message.event_type === "text")
99
+ process.stdout.write(message.content ?? "");
100
+ }
101
+ ```
102
+
103
+ ### Uploading a folder
104
+
105
+ ```ts
106
+ import { fingerprintSource } from "@bevor/sdk";
107
+ import { directoryFiles } from "@bevor/sdk/node";
108
+
109
+ const { zip, nFiles, versionFingerprint } = await fingerprintSource(
110
+ await directoryFiles("./contracts"),
111
+ "contracts",
112
+ );
113
+ if (nFiles === 0) throw new Error("no UTF-8 source files found after filters");
114
+
115
+ const signingKey = await client.codes.generateSigningKey();
116
+ const upload = await client.codes.uploadFolderZip(signingKey, zip, {
117
+ withStreaming: true,
118
+ });
119
+ for await (const event of upload.streamCompletion()) {
120
+ if (event.type === "code.step") console.log(event.payload.step);
121
+ }
122
+ ```
123
+
124
+ The zip and fingerprint follow the same file rules as the API, so `versionFingerprint` matches the
125
+ code version's `version_fingerprint`.
126
+
127
+ ### Graph
128
+
129
+ `Graph` loads a code version's nodes, edges and files for local traversal:
130
+
131
+ ```ts
132
+ import { Graph } from "@bevor/sdk";
133
+
134
+ const graph = new Graph(client, codeId);
135
+ await graph.build();
136
+
137
+ const chain = graph.getCallChain(entrypointId);
138
+ console.log(chain.toText());
139
+
140
+ const source = await graph.reconstructChunk(entrypointId, {
141
+ withDocstring: true,
142
+ });
143
+ ```
144
+
145
+ ### Errors
146
+
147
+ Error responses with a known code throw a typed subclass of `BaseError` (`NotFoundError`,
148
+ `InvalidStateException`, `RateLimitException`, ...) carrying `code`, `statusCode` and `message`.
149
+ Any other non-2xx response throws `APIError` with the `status` and raw `body`.
150
+
151
+ ```ts
152
+ import { NotFoundError } from "@bevor/sdk";
153
+
154
+ try {
155
+ await client.findings.get(findingId);
156
+ } catch (error) {
157
+ if (error instanceof NotFoundError) return null;
158
+ throw error;
159
+ }
160
+ ```
161
+
162
+ ### SARIF
163
+
164
+ ```ts
165
+ import { bevorToSarif, sarifToBevor } from "@bevor/sdk";
166
+
167
+ const sarif = await bevorToSarif(graph, findings.results);
168
+ await client.analyses.addFindings(analysisId, {
169
+ findings: sarifToBevor(sarifLog),
170
+ });
171
+ ```
172
+
173
+
174
+ ## Documentation
175
+
176
+ Full API reference and guides: https://bevor.io/docs
177
+
178
+ ## License
179
+
180
+ MIT
@@ -0,0 +1,86 @@
1
+ import { PaginatedResource } from "./pagination.js";
2
+ import { AnalysisResources } from "./resources/analyses.js";
3
+ import { ChatResources } from "./resources/chats.js";
4
+ import { CodesResources } from "./resources/codes.js";
5
+ import { FindingResources } from "./resources/findings.js";
6
+ import { ProjectResources } from "./resources/projects.js";
7
+ import { AnalysisSummaryResources } from "./resources/summary.js";
8
+ import { TransitionResources } from "./resources/transitions.js";
9
+ import { AnalysisVersionsResources } from "./resources/versions.js";
10
+ import type { Pagination } from "./types/responses.js";
11
+ export type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
12
+ type QueryScalar = string | number | boolean;
13
+ export type QueryValue = QueryScalar | readonly QueryScalar[] | null | undefined;
14
+ /** Any object whose values are query-serializable (works with interfaces, unlike an index signature). */
15
+ export type QueryInput<Q> = {
16
+ [K in keyof Q]: QueryValue;
17
+ };
18
+ export type QueryRecord = Readonly<Record<string, QueryValue>>;
19
+ export interface ClientOptions {
20
+ apiKey: string;
21
+ /** Defaults to https://api.bevor.io */
22
+ baseURL?: string;
23
+ /** Sent with every request. */
24
+ defaultHeaders?: Record<string, string>;
25
+ /** Request timeout in ms. Defaults to 120 000. For streams, this is the max idle time between chunks. */
26
+ timeout?: number;
27
+ /** Custom fetch implementation. Defaults to the global `fetch`. */
28
+ fetch?: typeof fetch;
29
+ }
30
+ /** Per-call options accepted by every resource method. */
31
+ export interface RequestOptions {
32
+ headers?: Record<string, string>;
33
+ signal?: AbortSignal;
34
+ /** Overrides the client timeout for this call, in ms. */
35
+ timeout?: number;
36
+ }
37
+ export interface PaginationOptions extends RequestOptions {
38
+ withPagination?: boolean;
39
+ }
40
+ export interface StreamingOptions extends RequestOptions {
41
+ withStreaming?: boolean;
42
+ }
43
+ export interface RequestConfig<Q, B> extends RequestOptions {
44
+ query?: Q;
45
+ /** Serialized as a JSON body. `undefined` keys are dropped, `null` values are sent. */
46
+ json?: B;
47
+ /** A raw body; mutually exclusive with `json`. */
48
+ body?: Uint8Array | FormData;
49
+ /** Send the `Authorization` header. Defaults to true. */
50
+ authenticated?: boolean;
51
+ }
52
+ /** Drops null, undefined and empty-string values; repeats the key for arrays. */
53
+ export declare const buildQuery: <Q extends QueryInput<Q>>(query: Q | undefined) => URLSearchParams;
54
+ /** Raises the registered error for a non-2xx response, or an `APIError` when the body has no known code. */
55
+ export declare const throwForResponse: (response: Response) => Promise<never>;
56
+ export declare class BevorClient {
57
+ #private;
58
+ readonly baseURL: string;
59
+ readonly defaultHeaders: Readonly<Record<string, string>>;
60
+ readonly timeout: number;
61
+ readonly codes: CodesResources;
62
+ readonly chats: ChatResources;
63
+ readonly analyses: AnalysisResources;
64
+ readonly transitions: TransitionResources;
65
+ readonly analysisVersions: AnalysisVersionsResources;
66
+ readonly summary: AnalysisSummaryResources;
67
+ readonly findings: FindingResources;
68
+ readonly projects: ProjectResources;
69
+ constructor(options: ClientOptions);
70
+ /**
71
+ * Sends a request and returns the parsed JSON body (`null` for empty responses).
72
+ * Throws a registered `BaseError` subclass, or `APIError`, for non-2xx responses.
73
+ */
74
+ request<T, Q extends QueryInput<Q> = QueryRecord, B = never>(method: HttpMethod, path: string, init?: RequestConfig<Q, B>): Promise<T>;
75
+ /**
76
+ * Sends a request and yields the response body line by line.
77
+ * `timeout` is the max idle time between chunks, not a total deadline.
78
+ */
79
+ streamLines<Q extends QueryInput<Q> = QueryRecord, B = never>(method: HttpMethod, path: string, init?: RequestConfig<Q, B>): AsyncGenerator<string>;
80
+ /** GETs a paginated list; with `withPagination`, wraps it to fetch further pages. */
81
+ paginate<T, Q extends QueryInput<Q> & {
82
+ page?: number | null;
83
+ }>(path: string, query: Q | undefined, options: PaginationOptions): Promise<Pagination<T> | PaginatedResource<T>>;
84
+ }
85
+ export {};
86
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,E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AS,UAAU,CAAC,CAAC,CAAC,GAAG,WAAW,EAAE,CAAC,GAAG,KAAK,EAChE,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAM,GAC5B,OAAO,CAAC,CAAC,CAAC,CAUZ;IAED;;;OAGG;IACI,WAAW,CAAC,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,GAAG,WAAW,EAAE,CAAC,GAAG,KAAK,EAClE,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAM,GAC5B,cAAc,CAAC,MAAM,CAAC,CAUxB;IAED,qFAAqF;IAC/E,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,GAAG;QAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,EACnE,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,CAAC,GAAG,SAAS,EACpB,OAAO,EAAE,iBAAiB,GACxB,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAS/C;CA2BD"}
package/dist/client.js ADDED
@@ -0,0 +1,171 @@
1
+ import { APIError, ERROR_REGISTRY } from "./errors.js";
2
+ import { PaginatedResource } from "./pagination.js";
3
+ import { AnalysisResources } from "./resources/analyses.js";
4
+ import { ChatResources } from "./resources/chats.js";
5
+ import { CodesResources } from "./resources/codes.js";
6
+ import { FindingResources } from "./resources/findings.js";
7
+ import { ProjectResources } from "./resources/projects.js";
8
+ import { AnalysisSummaryResources } from "./resources/summary.js";
9
+ import { TransitionResources } from "./resources/transitions.js";
10
+ import { AnalysisVersionsResources } from "./resources/versions.js";
11
+ import { decodeText, splitLines } from "./streaming.js";
12
+ const DEFAULT_BASE_URL = "https://api.bevor.io";
13
+ const DEFAULT_TIMEOUT = 120_000;
14
+ const trimSlashes = (value) => value.replace(/^\/+|\/+$/g, "");
15
+ const scalarToString = (value) => typeof value === "boolean" ? (value ? "true" : "false") : String(value);
16
+ /** Drops null, undefined and empty-string values; repeats the key for arrays. */
17
+ export const buildQuery = (query) => {
18
+ const params = new URLSearchParams();
19
+ if (!query)
20
+ return params;
21
+ for (const [key, value] of Object.entries(query)) {
22
+ if (value === null || value === undefined || value === "")
23
+ continue;
24
+ if (Array.isArray(value)) {
25
+ for (const item of value)
26
+ params.append(key, scalarToString(item));
27
+ }
28
+ else {
29
+ params.append(key, scalarToString(value));
30
+ }
31
+ }
32
+ return params;
33
+ };
34
+ const isJsonObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
35
+ const toText = (value) => typeof value === "string" ? value : JSON.stringify(value);
36
+ /** Raises the registered error for a non-2xx response, or an `APIError` when the body has no known code. */
37
+ export const throwForResponse = async (response) => {
38
+ const text = await response.text().catch(() => "");
39
+ let body = null;
40
+ try {
41
+ body = JSON.parse(text);
42
+ }
43
+ catch {
44
+ throw new APIError(response.status, text);
45
+ }
46
+ if (!isJsonObject(body) || body.code === null || body.code === undefined) {
47
+ throw new APIError(response.status, text);
48
+ }
49
+ const code = toText(body.code);
50
+ const { message, detail } = body;
51
+ const resolved = message !== null && message !== undefined
52
+ ? toText(message)
53
+ : detail !== null && detail !== undefined
54
+ ? toText(detail)
55
+ : JSON.stringify(body);
56
+ const ErrorClass = ERROR_REGISTRY[code];
57
+ if (!ErrorClass)
58
+ throw new APIError(response.status, text);
59
+ throw new ErrorClass(resolved);
60
+ };
61
+ const idleTimeout = (ms, signal) => {
62
+ const controller = new AbortController();
63
+ let timer;
64
+ const stop = () => clearTimeout(timer);
65
+ const touch = () => {
66
+ stop();
67
+ timer = setTimeout(() => controller.abort(new DOMException(`No data received for ${ms}ms`, "TimeoutError")), ms);
68
+ };
69
+ touch();
70
+ return {
71
+ signal: signal
72
+ ? AbortSignal.any([signal, controller.signal])
73
+ : controller.signal,
74
+ touch,
75
+ stop,
76
+ };
77
+ };
78
+ export class BevorClient {
79
+ baseURL;
80
+ defaultHeaders;
81
+ timeout;
82
+ #apiKey;
83
+ #fetch;
84
+ codes;
85
+ chats;
86
+ analyses;
87
+ transitions;
88
+ analysisVersions;
89
+ summary;
90
+ findings;
91
+ projects;
92
+ constructor(options) {
93
+ this.#apiKey = options.apiKey;
94
+ this.baseURL = (options.baseURL ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
95
+ this.defaultHeaders = { ...options.defaultHeaders };
96
+ this.timeout = options.timeout ?? DEFAULT_TIMEOUT;
97
+ this.#fetch = options.fetch ?? ((input, init) => fetch(input, init));
98
+ this.codes = new CodesResources(this);
99
+ this.chats = new ChatResources(this);
100
+ this.analyses = new AnalysisResources(this);
101
+ this.transitions = new TransitionResources(this);
102
+ this.analysisVersions = new AnalysisVersionsResources(this);
103
+ this.summary = new AnalysisSummaryResources(this);
104
+ this.findings = new FindingResources(this);
105
+ this.projects = new ProjectResources(this);
106
+ }
107
+ /**
108
+ * Sends a request and returns the parsed JSON body (`null` for empty responses).
109
+ * Throws a registered `BaseError` subclass, or `APIError`, for non-2xx responses.
110
+ */
111
+ async request(method, path, init = {}) {
112
+ const deadline = AbortSignal.timeout(init.timeout ?? this.timeout);
113
+ const signal = init.signal
114
+ ? AbortSignal.any([init.signal, deadline])
115
+ : deadline;
116
+ const response = await this.#send(method, path, init, signal);
117
+ if (!response.ok)
118
+ return throwForResponse(response);
119
+ const text = await response.text();
120
+ if (response.status === 204 || !text)
121
+ return null;
122
+ return JSON.parse(text);
123
+ }
124
+ /**
125
+ * Sends a request and yields the response body line by line.
126
+ * `timeout` is the max idle time between chunks, not a total deadline.
127
+ */
128
+ async *streamLines(method, path, init = {}) {
129
+ const idle = idleTimeout(init.timeout ?? this.timeout, init.signal);
130
+ try {
131
+ const response = await this.#send(method, path, init, idle.signal);
132
+ if (!response.ok)
133
+ await throwForResponse(response);
134
+ if (!response.body)
135
+ return;
136
+ yield* splitLines(decodeText(response.body, idle.touch));
137
+ }
138
+ finally {
139
+ idle.stop();
140
+ }
141
+ }
142
+ /** GETs a paginated list; with `withPagination`, wraps it to fetch further pages. */
143
+ async paginate(path, query, options) {
144
+ const { withPagination, ...requestOptions } = options;
145
+ const fetchPage = (page) => this.request("GET", path, {
146
+ ...requestOptions,
147
+ query: { ...query, page },
148
+ });
149
+ const first = await fetchPage(query?.page ?? 0);
150
+ return withPagination ? new PaginatedResource(first, fetchPage) : first;
151
+ }
152
+ #send(method, path, init, signal) {
153
+ const query = buildQuery(init.query).toString();
154
+ const url = `${this.baseURL}/${trimSlashes(path)}${query ? `?${query}` : ""}`;
155
+ // later sources override earlier ones, case-insensitively
156
+ const headers = new Headers();
157
+ if (init.authenticated !== false)
158
+ headers.set("Authorization", `Bearer ${this.#apiKey}`);
159
+ for (const [name, value] of Object.entries(this.defaultHeaders))
160
+ headers.set(name, value);
161
+ let body = init.body;
162
+ if (init.json !== undefined) {
163
+ headers.set("Content-Type", "application/json");
164
+ body = JSON.stringify(init.json);
165
+ }
166
+ for (const [name, value] of Object.entries(init.headers ?? {}))
167
+ headers.set(name, value);
168
+ return this.#fetch(url, { method, headers, body, signal });
169
+ }
170
+ }
171
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAsB,cAAc,EAAE,MAAM,aAAa,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO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AAO,EAAE,CAAC,CAAC;QACxD,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC;YAC9D,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC1B,IAAI,IAAI,GAA+C,IAAI,CAAC,IAAI,CAAC;QACjE,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC7B,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;YAChD,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClC,CAAC;QACD,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC;YAC7D,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAE1B,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;IAC5D,CAAC;CACD"}
@@ -0,0 +1,109 @@
1
+ export type AppErrorTypes = "auth.session_expired" | "auth.unauthorized" | "auth.unauthenticated" | "auth.payment_required" | "auth.invalid_permissions" | "auth.invalid_scope" | "error.bad_request" | "error.not_found" | "error.plan_limit" | "error.invalid_state" | "error.integrity" | "error.database" | "error.validation" | "error.server" | "code.unsupported" | "code.conflict" | "app.rate_limit" | "payment.error" | "payment.failed";
2
+ /**
3
+ * A non-2xx response that carries no recognised Bevor error code
4
+ * (proxies, gateways, validation errors, unknown codes).
5
+ */
6
+ export declare class APIError extends Error {
7
+ readonly status: number;
8
+ readonly body: string;
9
+ constructor(status: number, body: string);
10
+ }
11
+ /** Base class for errors the API reports with a known `code`. */
12
+ export declare abstract class BaseError extends Error {
13
+ abstract readonly code: AppErrorTypes;
14
+ abstract readonly statusCode: number;
15
+ constructor(message?: string | null);
16
+ get details(): {
17
+ message: string;
18
+ code: AppErrorTypes;
19
+ };
20
+ }
21
+ /** Base class for all authentication/authorization errors. */
22
+ export declare abstract class AuthException extends BaseError {
23
+ }
24
+ /** Base class for all code-related errors. */
25
+ export declare abstract class CodeException extends BaseError {
26
+ }
27
+ /** Base class for all payment-related errors. */
28
+ export declare class PaymentException extends BaseError {
29
+ readonly code: AppErrorTypes;
30
+ readonly statusCode: number;
31
+ }
32
+ /** Too many requests. Retrying later succeeds. */
33
+ export declare class RateLimitException extends BaseError {
34
+ readonly code = "app.rate_limit";
35
+ readonly statusCode = 429;
36
+ }
37
+ export declare class SessionExpiredError extends AuthException {
38
+ readonly code = "auth.session_expired";
39
+ readonly statusCode = 401;
40
+ }
41
+ export declare class UnauthenticatedError extends AuthException {
42
+ readonly code = "auth.unauthenticated";
43
+ readonly statusCode = 401;
44
+ }
45
+ export declare class PaymentRequiredError extends AuthException {
46
+ readonly code = "auth.payment_required";
47
+ readonly statusCode = 402;
48
+ }
49
+ export declare class UnauthorizedError extends AuthException {
50
+ readonly code = "auth.unauthorized";
51
+ readonly statusCode = 403;
52
+ }
53
+ /** Authenticated, but not allowed. Re-authenticating won't fix it. */
54
+ export declare class InvalidPermissionsError extends AuthException {
55
+ readonly code = "auth.invalid_permissions";
56
+ readonly statusCode = 403;
57
+ }
58
+ export declare class InvalidScopeError extends AuthException {
59
+ readonly code = "auth.invalid_scope";
60
+ readonly statusCode = 403;
61
+ }
62
+ /**
63
+ * The request is wrong for this endpoint, regardless of any resource's state.
64
+ * e.g. a required header is missing, or the project kind doesn't support the route.
65
+ */
66
+ export declare class BadRequestException extends BaseError {
67
+ readonly code = "error.bad_request";
68
+ readonly statusCode = 400;
69
+ }
70
+ /** Doesn't exist, was deleted, or isn't visible to the caller. */
71
+ export declare class NotFoundError extends BaseError {
72
+ readonly code = "error.not_found";
73
+ readonly statusCode = 404;
74
+ }
75
+ /**
76
+ * The resource's current state forbids the action. e.g. a pipeline is running,
77
+ * changes are staged, or it already exists.
78
+ */
79
+ export declare class InvalidStateException extends BaseError {
80
+ readonly code = "error.invalid_state";
81
+ readonly statusCode = 409;
82
+ }
83
+ /** Our failure, or an upstream service's. Retrying may succeed. */
84
+ export declare class ServerException extends BaseError {
85
+ readonly code = "error.server";
86
+ readonly statusCode = 500;
87
+ }
88
+ /** A plan or usage limit was reached. Retrying won't help, upgrading will. */
89
+ export declare class PlanLimitException extends BaseError {
90
+ readonly code = "error.plan_limit";
91
+ readonly statusCode = 402;
92
+ }
93
+ export declare class CodeUnsupportedException extends CodeException {
94
+ readonly code = "code.unsupported";
95
+ readonly statusCode = 400;
96
+ }
97
+ export declare class CodeConflictException extends CodeException {
98
+ readonly code = "code.conflict";
99
+ readonly statusCode = 409;
100
+ }
101
+ export declare class PaymentFailedException extends PaymentException {
102
+ readonly code: AppErrorTypes;
103
+ readonly statusCode: number;
104
+ }
105
+ type ErrorClass = new (message?: string | null) => BaseError;
106
+ /** Used to reconstruct typed errors from HTTP error response bodies. */
107
+ export declare const ERROR_REGISTRY: Partial<Record<AppErrorTypes, ErrorClass>>;
108
+ export {};
109
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GACtB,sBAAsB,GACtB,mBAAmB,GACnB,sBAAsB,GACtB,uBAAuB,GACvB,0BAA0B,GAC1B,oBAAoB,GACpB,mBAAmB,GACnB,iBAAiB,GACjB,kBAAkB,GAClB,qBAAqB,GACrB,iBAAiB,GACjB,gBAAgB,GAChB,kBAAkB,GAClB,cAAc,GACd,kBAAkB,GAClB,eAAe,GACf,gBAAgB,GAChB,eAAe,GACf,gBAAgB,CAAC;AAEpB;;;GAGG;AACH,qBAAa,QAAS,SAAQ,KAAK;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,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