@seam-rpc/client 1.0.5 → 1.1.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.
Files changed (2) hide show
  1. package/package.json +32 -31
  2. package/dist/index.js +0 -95
package/package.json CHANGED
@@ -1,31 +1,32 @@
1
- {
2
- "name": "@seam-rpc/client",
3
- "version": "1.0.5",
4
- "main": "./dist/index.js",
5
- "files": [
6
- "dist"
7
- ],
8
- "scripts": {
9
- "test": "echo \"Error: no test specified\" && exit 1"
10
- },
11
- "keywords": [],
12
- "author": "Daniel Clímaco",
13
- "license": "ISC",
14
- "description": "",
15
- "repository": {
16
- "type": "git",
17
- "url": "git+https://github.com/DanielC49/seam-rpc.git",
18
- "directory": "packages/client"
19
- },
20
- "homepage": "https://github.com/DanielC49/seam-rpc#readme",
21
- "bugs": {
22
- "url": "https://github.com/DanielC49/seam-rpc/issues"
23
- },
24
- "devDependencies": {
25
- "@types/node": "^24.3.1",
26
- "typescript": "^5.9.2"
27
- },
28
- "dependencies": {
29
- "@seam-rpc/core": "^1.0.0"
30
- }
31
- }
1
+ {
2
+ "name": "@seam-rpc/client",
3
+ "version": "1.1.1",
4
+ "main": "./dist/index.js",
5
+ "type": "module",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "scripts": {
10
+ "test": "echo \"Error: no test specified\" && exit 1"
11
+ },
12
+ "keywords": [],
13
+ "author": "Daniel Clímaco",
14
+ "license": "ISC",
15
+ "description": "",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/DanielC49/seam-rpc.git",
19
+ "directory": "packages/client"
20
+ },
21
+ "homepage": "https://github.com/DanielC49/seam-rpc#readme",
22
+ "bugs": {
23
+ "url": "https://github.com/DanielC49/seam-rpc/issues"
24
+ },
25
+ "devDependencies": {
26
+ "@types/node": "^24.3.1",
27
+ "typescript": "^5.9.2"
28
+ },
29
+ "dependencies": {
30
+ "@seam-rpc/core": "^1.0.0"
31
+ }
32
+ }
package/dist/index.js DELETED
@@ -1,95 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.SeamFile = void 0;
13
- exports.setApiUrl = setApiUrl;
14
- exports.callApi = callApi;
15
- const core_1 = require("@seam-rpc/core");
16
- Object.defineProperty(exports, "SeamFile", { enumerable: true, get: function () { return core_1.SeamFile; } });
17
- let apiUrl = null;
18
- function setApiUrl(url) {
19
- apiUrl = url;
20
- }
21
- function callApi(routerName, funcName, args) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- var _a, _b;
24
- if (!apiUrl)
25
- throw new Error("Missing API URL");
26
- let req;
27
- const { json, files, paths } = (0, core_1.extractFiles)(args);
28
- if (files.length > 0) {
29
- const formData = new FormData();
30
- formData.append("json", JSON.stringify(json));
31
- formData.append("paths", JSON.stringify(paths));
32
- for (let i = 0; i < files.length; i++) {
33
- const file = files[i];
34
- const blob = new Blob([new Uint8Array(file.data)], {
35
- type: file.mimeType || "application/octet-stream",
36
- });
37
- formData.append(`file-${i}`, blob, file.fileName || `file-${i}`);
38
- }
39
- req = {
40
- method: "POST",
41
- body: formData,
42
- };
43
- }
44
- else {
45
- req = {
46
- method: "POST",
47
- headers: {
48
- "Content-Type": "application/json",
49
- },
50
- body: JSON.stringify(args),
51
- };
52
- }
53
- const url = `${apiUrl}/${routerName}/${funcName}`;
54
- let res;
55
- try {
56
- res = yield fetch(url, req);
57
- }
58
- catch (err) {
59
- console.log(url, req, err);
60
- throw new Error("Failed to send request.\n" + err);
61
- }
62
- if (!res.ok) {
63
- if (res.status == 400) {
64
- const resError = yield res.json();
65
- throw new Error(resError.error);
66
- }
67
- throw new Error(`Request failed with status ${res.status} ${res.statusText}.`);
68
- }
69
- const contentType = res.headers.get("content-type") || "";
70
- if (contentType.startsWith("application/json")) {
71
- const data = yield res.json();
72
- return data.result;
73
- }
74
- else if (contentType.startsWith("multipart/form-data")) {
75
- const formData = yield res.formData();
76
- const jsonPart = JSON.parse(((_a = formData.get("json")) === null || _a === void 0 ? void 0 : _a.toString()) || "[]");
77
- const pathsPart = JSON.parse(((_b = formData.get("paths")) === null || _b === void 0 ? void 0 : _b.toString()) || "[]");
78
- const responseFiles = [];
79
- for (const [key, value] of formData.entries()) {
80
- if (key.startsWith("file-")) {
81
- const index = parseInt(key.replace("file-", ""));
82
- const blob = value;
83
- const arrayBuffer = yield blob.arrayBuffer();
84
- responseFiles.push({
85
- path: pathsPart[index],
86
- file: new core_1.SeamFile(new Uint8Array(arrayBuffer), blob.name, blob.type),
87
- });
88
- }
89
- }
90
- (0, core_1.injectFiles)(jsonPart, responseFiles);
91
- return jsonPart.result;
92
- }
93
- });
94
- }
95
- // console.log(JSON.stringify(extractFiles(["John", new SeamFile(new Uint8Array([1, 2, 3, 4]))]), null, 4))