@renterra/sdk 0.2.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 +75 -0
- package/dist/browser-oauth.d.ts +11 -0
- package/dist/browser-oauth.js +169 -0
- package/dist/debug.d.ts +11 -0
- package/dist/debug.js +69 -0
- package/dist/generated/contracts.d.ts +607 -0
- package/dist/generated/contracts.js +1 -0
- package/dist/generated/resources.d.ts +1014 -0
- package/dist/generated/resources.js +87 -0
- package/dist/generated/rest.d.ts +2744 -0
- package/dist/generated/rest.js +1 -0
- package/dist/generated/schemas.d.ts +6 -0
- package/dist/generated/schemas.js +2728 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2 -0
- package/dist/mcp.d.ts +456 -0
- package/dist/mcp.js +185 -0
- package/dist/rest.d.ts +1296 -0
- package/dist/rest.js +47 -0
- package/dist/transport.d.ts +30 -0
- package/dist/transport.js +39 -0
- package/package.json +52 -0
package/dist/rest.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import createClient from "openapi-fetch";
|
|
2
|
+
import { createBrowserOAuth } from "./browser-oauth.js";
|
|
3
|
+
import { createResources } from "./generated/resources.js";
|
|
4
|
+
import { createResourceTransport } from "./transport.js";
|
|
5
|
+
export async function connectRenterra(options = {}) {
|
|
6
|
+
const hosted = typeof window !== "undefined" && window.location.pathname.startsWith("/beta/artifact-file/");
|
|
7
|
+
const mode = options.mode ?? (hosted ? "session" : "oauth");
|
|
8
|
+
if (mode === "session" && typeof window === "undefined")
|
|
9
|
+
throw new Error("Session authentication requires the Renterra browser host");
|
|
10
|
+
const origin = mode === "session"
|
|
11
|
+
? window.location.origin
|
|
12
|
+
: new URL(options.apiOrigin ?? "https://api.getrenterra.com").origin;
|
|
13
|
+
const fetchFn = options.fetch ?? globalThis.fetch;
|
|
14
|
+
const oauthOptions = {
|
|
15
|
+
issuer: options.issuer ?? "https://app.getrenterra.com/api/auth",
|
|
16
|
+
resource: new URL("/v1", origin).href,
|
|
17
|
+
redirectUri: options.redirectUri,
|
|
18
|
+
clientId: options.clientId,
|
|
19
|
+
fetch: fetchFn,
|
|
20
|
+
};
|
|
21
|
+
const oauth = mode === "oauth" && !options.accessToken ? createBrowserOAuth(oauthOptions) : undefined;
|
|
22
|
+
const client = createClient({
|
|
23
|
+
baseUrl: origin,
|
|
24
|
+
fetch: async (request) => {
|
|
25
|
+
const url = new URL(request.url);
|
|
26
|
+
const headers = new Headers(request.headers);
|
|
27
|
+
if (mode === "session") {
|
|
28
|
+
url.pathname = url.pathname.replace(/^\/v1(?=\/|$)/, "/v1/app");
|
|
29
|
+
headers.delete("authorization");
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
const token = options.accessToken ? await options.accessToken() : await oauth?.accessToken();
|
|
33
|
+
if (!token)
|
|
34
|
+
throw new Error("Missing OAuth authorization");
|
|
35
|
+
headers.set("authorization", `Bearer ${token}`);
|
|
36
|
+
}
|
|
37
|
+
return fetchFn(new Request(url, new Request(request, {
|
|
38
|
+
headers,
|
|
39
|
+
credentials: mode === "session" ? "same-origin" : "omit",
|
|
40
|
+
})));
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
...createResources(createResourceTransport(client)),
|
|
45
|
+
signOut: () => oauth?.clear(),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Client } from "openapi-fetch";
|
|
2
|
+
import type { paths } from "./generated/rest.js";
|
|
3
|
+
export type RenterraCallOptions = {
|
|
4
|
+
signal?: AbortSignal;
|
|
5
|
+
timeout?: number;
|
|
6
|
+
idempotencyKey?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare class RenterraError extends Error {
|
|
9
|
+
readonly status: number;
|
|
10
|
+
readonly code: string;
|
|
11
|
+
readonly name = "RenterraError";
|
|
12
|
+
constructor(status: number, code: string, message: string);
|
|
13
|
+
}
|
|
14
|
+
declare function unwrap<T>(promise: Promise<{
|
|
15
|
+
data?: T;
|
|
16
|
+
error?: unknown;
|
|
17
|
+
response: Response;
|
|
18
|
+
}>): Promise<T>;
|
|
19
|
+
declare function requestOptions(options?: RenterraCallOptions): {
|
|
20
|
+
headers?: {
|
|
21
|
+
"Idempotency-Key": string;
|
|
22
|
+
} | undefined;
|
|
23
|
+
signal?: AbortSignal | undefined;
|
|
24
|
+
};
|
|
25
|
+
export declare function createResourceTransport(client: Client<paths>): {
|
|
26
|
+
client: Client<paths, `${string}/${string}`>;
|
|
27
|
+
unwrap: typeof unwrap;
|
|
28
|
+
requestOptions: typeof requestOptions;
|
|
29
|
+
};
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export class RenterraError extends Error {
|
|
2
|
+
status;
|
|
3
|
+
code;
|
|
4
|
+
name = "RenterraError";
|
|
5
|
+
constructor(status, code, message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.status = status;
|
|
8
|
+
this.code = code;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
async function unwrap(promise) {
|
|
12
|
+
const result = await promise;
|
|
13
|
+
if (!result.response.ok) {
|
|
14
|
+
const body = result.error && typeof result.error === "object" && "error" in result.error
|
|
15
|
+
? result.error.error
|
|
16
|
+
: undefined;
|
|
17
|
+
const code = body && typeof body === "object" && "code" in body && typeof body.code === "string"
|
|
18
|
+
? body.code
|
|
19
|
+
: "request_failed";
|
|
20
|
+
const message = body && typeof body === "object" && "message" in body && typeof body.message === "string"
|
|
21
|
+
? body.message
|
|
22
|
+
: `API request failed (${result.response.status})`;
|
|
23
|
+
throw new RenterraError(result.response.status, code, message);
|
|
24
|
+
}
|
|
25
|
+
return result.data;
|
|
26
|
+
}
|
|
27
|
+
function requestOptions(options) {
|
|
28
|
+
const signals = [
|
|
29
|
+
options?.signal,
|
|
30
|
+
options?.timeout ? AbortSignal.timeout(options.timeout) : undefined,
|
|
31
|
+
].filter((signal) => signal !== undefined);
|
|
32
|
+
return {
|
|
33
|
+
...(signals.length > 0 ? { signal: AbortSignal.any(signals) } : {}),
|
|
34
|
+
...(options?.idempotencyKey ? { headers: { "Idempotency-Key": options.idempotencyKey } } : {}),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export function createResourceTransport(client) {
|
|
38
|
+
return { client, unwrap, requestOptions };
|
|
39
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@renterra/sdk",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Typed Renterra REST API client with host sessions and browser OAuth",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/renterra/code.git",
|
|
9
|
+
"directory": "packages/sdk"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"exports": {
|
|
16
|
+
"./mcp": {
|
|
17
|
+
"types": "./dist/mcp.d.ts",
|
|
18
|
+
"default": "./dist/mcp.js"
|
|
19
|
+
},
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "restricted"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@modelcontextprotocol/sdk": "1.32.1",
|
|
30
|
+
"openapi-fetch": "0.17.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@orpc/openapi": "2.0.0-beta.47",
|
|
34
|
+
"@types/node": "24.13.3",
|
|
35
|
+
"json-schema-to-typescript": "^15.0.4",
|
|
36
|
+
"openapi-typescript": "7.13.0",
|
|
37
|
+
"tsx": "^4.7.0",
|
|
38
|
+
"typescript": "5.9.3",
|
|
39
|
+
"vitest": "^4.1.12",
|
|
40
|
+
"zod": "4.6.7",
|
|
41
|
+
"@renterra/lib": "0.0.0",
|
|
42
|
+
"@renterra/database": "0.0.0",
|
|
43
|
+
"@renterra/zod": "0.0.0",
|
|
44
|
+
"@renterra/tsconfig": "0.0.0"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"generate": "tsx scripts/generate-contracts.ts && tsx --tsconfig ../../apps/api/tsconfig.json scripts/generate-rest.ts",
|
|
48
|
+
"build": "tsc -p tsconfig.build.json",
|
|
49
|
+
"typecheck": "tsc --noEmit && tsc -p tsconfig.scripts.json",
|
|
50
|
+
"test": "vitest run"
|
|
51
|
+
}
|
|
52
|
+
}
|