@renai-labs/sdk 0.1.12 → 0.1.14
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/dist/client.js +2 -3
- package/dist/error.d.ts +15 -0
- package/dist/error.js +35 -0
- package/dist/generated/types.gen.d.ts +1 -0
- package/dist/generated/zod.gen.d.ts +1 -0
- package/dist/generated/zod.gen.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createClient } from "./generated/client";
|
|
2
2
|
import { client as defaultClient } from "./generated/client.gen";
|
|
3
3
|
import { RenClient } from "./generated/sdk.gen";
|
|
4
|
+
import { ApiError } from "./error";
|
|
4
5
|
export function createRenClient(config = {}) {
|
|
5
6
|
const { auth, ...rest } = config;
|
|
6
7
|
const merged = { credentials: "include", ...rest };
|
|
@@ -16,9 +17,7 @@ export function createRenClient(config = {}) {
|
|
|
16
17
|
const path = request ? new URL(request.url).pathname : undefined;
|
|
17
18
|
const method = request?.method;
|
|
18
19
|
const status = response?.status;
|
|
19
|
-
|
|
20
|
-
return Object.assign(body, { status, path, method });
|
|
21
|
-
return { body, status, path, method };
|
|
20
|
+
return new ApiError({ status, path, method, body });
|
|
22
21
|
});
|
|
23
22
|
return new RenClient({ client });
|
|
24
23
|
}
|
package/dist/error.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type ApiErrorInit = {
|
|
2
|
+
status?: number;
|
|
3
|
+
path?: string;
|
|
4
|
+
method?: string;
|
|
5
|
+
body: unknown;
|
|
6
|
+
};
|
|
7
|
+
export declare class ApiError extends Error {
|
|
8
|
+
readonly status?: number;
|
|
9
|
+
readonly path?: string;
|
|
10
|
+
readonly method?: string;
|
|
11
|
+
readonly error?: string;
|
|
12
|
+
readonly body: unknown;
|
|
13
|
+
constructor(init: ApiErrorInit);
|
|
14
|
+
}
|
|
15
|
+
export declare function isApiError(value: unknown): value is ApiError;
|
package/dist/error.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export class ApiError extends Error {
|
|
2
|
+
status;
|
|
3
|
+
path;
|
|
4
|
+
method;
|
|
5
|
+
error;
|
|
6
|
+
body;
|
|
7
|
+
constructor(init) {
|
|
8
|
+
super(buildMessage(init));
|
|
9
|
+
this.name = "ApiError";
|
|
10
|
+
this.status = init.status;
|
|
11
|
+
this.path = init.path;
|
|
12
|
+
this.method = init.method;
|
|
13
|
+
this.error = extractDetail(init.body);
|
|
14
|
+
this.body = init.body;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function isApiError(value) {
|
|
18
|
+
return value instanceof ApiError;
|
|
19
|
+
}
|
|
20
|
+
function extractDetail(body) {
|
|
21
|
+
if (body && typeof body === "object" && "error" in body) {
|
|
22
|
+
const detail = body.error;
|
|
23
|
+
if (typeof detail === "string" && detail.trim())
|
|
24
|
+
return detail;
|
|
25
|
+
}
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
function buildMessage({ status, path, method, body }) {
|
|
29
|
+
const detail = extractDetail(body);
|
|
30
|
+
if (detail)
|
|
31
|
+
return detail;
|
|
32
|
+
const route = [method, path].filter(Boolean).join(" ");
|
|
33
|
+
const code = status ? ` (${status})` : "";
|
|
34
|
+
return route ? `${route}${code} failed` : `Request failed${code || ""}`;
|
|
35
|
+
}
|
|
@@ -12068,6 +12068,7 @@ export declare const zTelegramUnlinkResponse: z.ZodVoid;
|
|
|
12068
12068
|
export declare const zTelegramClaimCodeBody: z.ZodObject<{
|
|
12069
12069
|
projectId: z.ZodString;
|
|
12070
12070
|
defaultProjectAgentId: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
12071
|
+
fallbackSenderUserId: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
12071
12072
|
}, z.core.$strip>;
|
|
12072
12073
|
export declare const zTelegramClaimCodeQuery: z.ZodObject<{
|
|
12073
12074
|
scope: z.ZodOptional<z.ZodEnum<{
|
|
@@ -3716,6 +3716,7 @@ export const zTelegramUnlinkResponse = z.void();
|
|
|
3716
3716
|
export const zTelegramClaimCodeBody = z.object({
|
|
3717
3717
|
projectId: z.string().min(1),
|
|
3718
3718
|
defaultProjectAgentId: z.string().min(1).nullish().default(null),
|
|
3719
|
+
fallbackSenderUserId: z.string().min(1).nullish().default(null),
|
|
3719
3720
|
});
|
|
3720
3721
|
export const zTelegramClaimCodeQuery = z.object({
|
|
3721
3722
|
scope: z.enum(["user"]).optional(),
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED