@renterra/sdk 0.2.0 → 0.2.1
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 +31 -3
- package/dist/generated/contracts.d.ts +159 -6
- package/dist/generated/list-filters.d.ts +4519 -0
- package/dist/generated/list-filters.js +1 -0
- package/dist/generated/resources.d.ts +1310 -70
- package/dist/generated/resources.js +86 -13
- package/dist/generated/rest.d.ts +4862 -920
- package/dist/generated/schemas.js +644 -42
- package/dist/index.d.ts +2 -1
- package/dist/mcp.d.ts +12 -6
- package/dist/mcp.js +1 -0
- package/dist/rest.d.ts +7091 -327
- package/dist/rest.js +5 -1
- package/dist/runtime.d.ts +8052 -0
- package/dist/runtime.js +49 -0
- package/dist/transport.d.ts +7 -5
- package/dist/transport.js +18 -4
- package/package.json +22 -18
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { EnvHttpProxyAgent, fetch as proxyFetch } from "undici";
|
|
2
|
+
import { connectRenterra as connectSdk } from "./rest.js";
|
|
3
|
+
export { RenterraError } from "./transport.js";
|
|
4
|
+
export async function connectRenterra(options = {}) {
|
|
5
|
+
const token = process.env.RENTERRA_API_TOKEN;
|
|
6
|
+
if (!token)
|
|
7
|
+
throw new Error("Renterra runtime credentials are unavailable");
|
|
8
|
+
const origin = new URL(RENTERRA_RUNTIME_API_ORIGIN).origin;
|
|
9
|
+
const dispatcher = new EnvHttpProxyAgent();
|
|
10
|
+
try {
|
|
11
|
+
const client = await connectSdk({
|
|
12
|
+
...options,
|
|
13
|
+
mode: "oauth",
|
|
14
|
+
apiOrigin: origin,
|
|
15
|
+
accessToken: () => token,
|
|
16
|
+
fetch: async (input, init) => {
|
|
17
|
+
const request = new Request(input, init);
|
|
18
|
+
const url = new URL(request.url);
|
|
19
|
+
if (url.origin !== origin || !url.pathname.startsWith("/v1/"))
|
|
20
|
+
throw new Error("Runtime SDK requests must target the configured Renterra API");
|
|
21
|
+
const response = await proxyFetch(url.href, {
|
|
22
|
+
method: request.method,
|
|
23
|
+
headers: Object.fromEntries(request.headers),
|
|
24
|
+
body: request.method === "GET" || request.method === "HEAD"
|
|
25
|
+
? undefined
|
|
26
|
+
: new Uint8Array(await request.arrayBuffer()),
|
|
27
|
+
signal: request.signal,
|
|
28
|
+
redirect: "error",
|
|
29
|
+
dispatcher,
|
|
30
|
+
});
|
|
31
|
+
return new Response(response.status === 204 || response.status === 304 ? null : await response.arrayBuffer(), {
|
|
32
|
+
status: response.status,
|
|
33
|
+
statusText: response.statusText,
|
|
34
|
+
headers: Object.fromEntries(response.headers),
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
...client,
|
|
40
|
+
signOut: async () => {
|
|
41
|
+
await dispatcher.close();
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
await dispatcher.close();
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
}
|
package/dist/transport.d.ts
CHANGED
|
@@ -5,25 +5,27 @@ export type RenterraCallOptions = {
|
|
|
5
5
|
timeout?: number;
|
|
6
6
|
idempotencyKey?: string;
|
|
7
7
|
};
|
|
8
|
+
export type RenterraErrorDetails = Readonly<Record<string, unknown>>;
|
|
8
9
|
export declare class RenterraError extends Error {
|
|
9
10
|
readonly status: number;
|
|
10
11
|
readonly code: string;
|
|
12
|
+
readonly details?: RenterraErrorDetails | undefined;
|
|
11
13
|
readonly name = "RenterraError";
|
|
12
|
-
constructor(status: number, code: string, message: string);
|
|
14
|
+
constructor(status: number, code: string, message: string, details?: RenterraErrorDetails | undefined);
|
|
13
15
|
}
|
|
14
16
|
declare function unwrap<T>(promise: Promise<{
|
|
15
17
|
data?: T;
|
|
16
18
|
error?: unknown;
|
|
17
19
|
response: Response;
|
|
18
20
|
}>): Promise<T>;
|
|
19
|
-
declare function requestOptions(options?: RenterraCallOptions): {
|
|
21
|
+
declare function requestOptions(options?: RenterraCallOptions, headers?: Record<string, string>): {
|
|
20
22
|
headers?: {
|
|
21
|
-
"Idempotency-Key"
|
|
23
|
+
"Idempotency-Key"?: string | undefined;
|
|
22
24
|
} | undefined;
|
|
23
25
|
signal?: AbortSignal | undefined;
|
|
24
26
|
};
|
|
25
|
-
export declare function createResourceTransport(client: Client<paths>): {
|
|
26
|
-
client: Client<paths,
|
|
27
|
+
export declare function createResourceTransport(client: Client<paths, "application/json">): {
|
|
28
|
+
client: Client<paths, "application/json">;
|
|
27
29
|
unwrap: typeof unwrap;
|
|
28
30
|
requestOptions: typeof requestOptions;
|
|
29
31
|
};
|
package/dist/transport.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
export class RenterraError extends Error {
|
|
2
2
|
status;
|
|
3
3
|
code;
|
|
4
|
+
details;
|
|
4
5
|
name = "RenterraError";
|
|
5
|
-
constructor(status, code, message) {
|
|
6
|
+
constructor(status, code, message, details) {
|
|
6
7
|
super(message);
|
|
7
8
|
this.status = status;
|
|
8
9
|
this.code = code;
|
|
10
|
+
this.details = details;
|
|
9
11
|
}
|
|
10
12
|
}
|
|
11
13
|
async function unwrap(promise) {
|
|
@@ -20,18 +22,30 @@ async function unwrap(promise) {
|
|
|
20
22
|
const message = body && typeof body === "object" && "message" in body && typeof body.message === "string"
|
|
21
23
|
? body.message
|
|
22
24
|
: `API request failed (${result.response.status})`;
|
|
23
|
-
|
|
25
|
+
const details = body &&
|
|
26
|
+
typeof body === "object" &&
|
|
27
|
+
"details" in body &&
|
|
28
|
+
body.details &&
|
|
29
|
+
typeof body.details === "object" &&
|
|
30
|
+
!Array.isArray(body.details)
|
|
31
|
+
? Object.fromEntries(Object.entries(body.details))
|
|
32
|
+
: undefined;
|
|
33
|
+
throw new RenterraError(result.response.status, code, message, details);
|
|
24
34
|
}
|
|
25
35
|
return result.data;
|
|
26
36
|
}
|
|
27
|
-
function requestOptions(options) {
|
|
37
|
+
function requestOptions(options, headers) {
|
|
28
38
|
const signals = [
|
|
29
39
|
options?.signal,
|
|
30
40
|
options?.timeout ? AbortSignal.timeout(options.timeout) : undefined,
|
|
31
41
|
].filter((signal) => signal !== undefined);
|
|
42
|
+
const requestHeaders = {
|
|
43
|
+
...headers,
|
|
44
|
+
...(options?.idempotencyKey ? { "Idempotency-Key": options.idempotencyKey } : {}),
|
|
45
|
+
};
|
|
32
46
|
return {
|
|
33
47
|
...(signals.length > 0 ? { signal: AbortSignal.any(signals) } : {}),
|
|
34
|
-
...(
|
|
48
|
+
...(Object.keys(requestHeaders).length ? { headers: requestHeaders } : {}),
|
|
35
49
|
};
|
|
36
50
|
}
|
|
37
51
|
export function createResourceTransport(client) {
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@renterra/sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Typed Renterra REST API client with host sessions and browser OAuth",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/renterra/
|
|
9
|
-
"directory": "packages/sdk"
|
|
8
|
+
"url": "git+https://github.com/renterra/sdk.git"
|
|
10
9
|
},
|
|
11
10
|
"type": "module",
|
|
12
11
|
"files": [
|
|
13
|
-
"dist"
|
|
12
|
+
"dist",
|
|
13
|
+
"!dist/runtime-sdk"
|
|
14
14
|
],
|
|
15
15
|
"exports": {
|
|
16
16
|
"./mcp": {
|
|
@@ -30,23 +30,27 @@
|
|
|
30
30
|
"openapi-fetch": "0.17.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@
|
|
33
|
+
"@biomejs/biome": "2.5.6",
|
|
34
34
|
"@types/node": "24.13.3",
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"tsx": "
|
|
35
|
+
"dts-bundle-generator": "^10.0.0",
|
|
36
|
+
"esbuild": "0.28.1",
|
|
37
|
+
"tsx": "4.20.5",
|
|
38
38
|
"typescript": "5.9.3",
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"
|
|
39
|
+
"undici": "7.30.1",
|
|
40
|
+
"vitest": "4.1.12",
|
|
41
|
+
"zod": "4.6.7"
|
|
42
|
+
},
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=24.22.1"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
|
-
"generate": "
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
47
|
+
"generate": "node scripts/install-contracts.mjs",
|
|
48
|
+
"contracts:update": "node scripts/update-contracts.mjs",
|
|
49
|
+
"build": "pnpm run generate && tsc -p tsconfig.build.json",
|
|
50
|
+
"typecheck": "pnpm run generate && tsc --noEmit && tsc -p tsconfig.scripts.json",
|
|
51
|
+
"test": "pnpm run generate && node --test scripts/*.node-test.mjs && vitest run",
|
|
52
|
+
"format": "biome check --write .",
|
|
53
|
+
"check-format": "biome check .",
|
|
54
|
+
"runtime:bundle": "pnpm run generate && tsx scripts/bundle-runtime.ts"
|
|
51
55
|
}
|
|
52
56
|
}
|