@seam-rpc/client 3.0.2 → 4.0.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/dist/index.d.ts +2 -4
- package/dist/index.js +10 -15
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { SeamFile, ISeamFile } from "@seam-rpc/core";
|
|
2
|
-
export { SeamFile, ISeamFile };
|
|
3
1
|
export type SeamRequestMiddleware = (context: SeamRequestMiddlewareContext) => void | Promise<void>;
|
|
4
2
|
export type SeamResponseMiddleware = (context: SeamResponseMiddlewareContext) => void | Promise<void>;
|
|
5
3
|
export interface SeamRequestMiddlewareContext {
|
|
6
4
|
request: RequestInit;
|
|
7
5
|
routerName: string;
|
|
8
6
|
funcName: string;
|
|
9
|
-
|
|
7
|
+
input?: Record<string, any>;
|
|
10
8
|
}
|
|
11
9
|
export type SeamResponseMiddlewareContext = SeamRequestMiddlewareContext & {
|
|
12
10
|
response: Response;
|
|
@@ -27,4 +25,4 @@ export declare class SeamClient {
|
|
|
27
25
|
postRequest(middleware: SeamResponseMiddleware): void;
|
|
28
26
|
}
|
|
29
27
|
export declare function createClient(baseUrl: string, options?: SeamClientOptions): SeamClient;
|
|
30
|
-
export declare function callApi(routerName: string, funcName: string,
|
|
28
|
+
export declare function callApi(routerName: string, funcName: string, input?: Record<string, any>): Promise<any>;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { SeamFile };
|
|
1
|
+
import { extractFiles, injectFiles } from "@seam-rpc/core";
|
|
3
2
|
export class SeamClient {
|
|
4
3
|
constructor(baseUrl, options) {
|
|
5
4
|
this.baseUrl = baseUrl;
|
|
@@ -21,11 +20,11 @@ export class SeamClient {
|
|
|
21
20
|
export function createClient(baseUrl, options) {
|
|
22
21
|
return new SeamClient(baseUrl, options);
|
|
23
22
|
}
|
|
24
|
-
export async function callApi(routerName, funcName,
|
|
23
|
+
export async function callApi(routerName, funcName, input) {
|
|
25
24
|
if (!SeamClient._instance)
|
|
26
25
|
throw new Error("Seam Client not instantiated.");
|
|
27
26
|
const seamClient = SeamClient._instance;
|
|
28
|
-
const req = buildRequest(
|
|
27
|
+
const req = buildRequest(input);
|
|
29
28
|
const url = `${seamClient.baseUrl}/${routerName}/${funcName}`;
|
|
30
29
|
if (seamClient.options?.middleware?.request) {
|
|
31
30
|
for (const mw of seamClient.options.middleware.request) {
|
|
@@ -33,7 +32,7 @@ export async function callApi(routerName, funcName, args) {
|
|
|
33
32
|
request: req,
|
|
34
33
|
routerName,
|
|
35
34
|
funcName,
|
|
36
|
-
|
|
35
|
+
input,
|
|
37
36
|
});
|
|
38
37
|
}
|
|
39
38
|
}
|
|
@@ -66,10 +65,9 @@ export async function callApi(routerName, funcName, args) {
|
|
|
66
65
|
if (key.startsWith("file-")) {
|
|
67
66
|
const index = parseInt(key.replace("file-", ""));
|
|
68
67
|
const blob = value;
|
|
69
|
-
const arrayBuffer = await blob.arrayBuffer();
|
|
70
68
|
responseFiles.push({
|
|
71
69
|
path: pathsPart[index],
|
|
72
|
-
file: new
|
|
70
|
+
file: new File([blob], blob.name),
|
|
73
71
|
});
|
|
74
72
|
}
|
|
75
73
|
}
|
|
@@ -82,26 +80,23 @@ export async function callApi(routerName, funcName, args) {
|
|
|
82
80
|
parsedResponse: jsonPart.result,
|
|
83
81
|
routerName,
|
|
84
82
|
funcName,
|
|
85
|
-
|
|
83
|
+
input,
|
|
86
84
|
});
|
|
87
85
|
}
|
|
88
86
|
}
|
|
89
87
|
return jsonPart.result;
|
|
90
88
|
}
|
|
91
89
|
}
|
|
92
|
-
function buildRequest(
|
|
90
|
+
function buildRequest(input = {}) {
|
|
93
91
|
let req;
|
|
94
|
-
const { json, files, paths } = extractFiles(
|
|
92
|
+
const { json, files, paths } = extractFiles(input);
|
|
95
93
|
if (files.length > 0) {
|
|
96
94
|
const formData = new FormData();
|
|
97
95
|
formData.append("json", JSON.stringify(json));
|
|
98
96
|
formData.append("paths", JSON.stringify(paths));
|
|
99
97
|
for (let i = 0; i < files.length; i++) {
|
|
100
98
|
const file = files[i];
|
|
101
|
-
|
|
102
|
-
type: file.mimeType || "application/octet-stream",
|
|
103
|
-
});
|
|
104
|
-
formData.append(`file-${i}`, blob, file.fileName || `file-${i}`);
|
|
99
|
+
formData.append(`file-${i}`, file, file.name || `file-${i}`);
|
|
105
100
|
}
|
|
106
101
|
req = {
|
|
107
102
|
method: "POST",
|
|
@@ -114,7 +109,7 @@ function buildRequest(args) {
|
|
|
114
109
|
headers: {
|
|
115
110
|
"Content-Type": "application/json",
|
|
116
111
|
},
|
|
117
|
-
body: JSON.stringify(
|
|
112
|
+
body: JSON.stringify(input),
|
|
118
113
|
};
|
|
119
114
|
}
|
|
120
115
|
return req;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seam-rpc/client",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -27,6 +27,6 @@
|
|
|
27
27
|
"typescript": "^5.9.2"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@seam-rpc/core": "
|
|
30
|
+
"@seam-rpc/core": "*"
|
|
31
31
|
}
|
|
32
32
|
}
|