@bandeira-tech/b3nd-web 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/dist/apps/mod.js +1 -1
- package/dist/{chunk-XH4OLKBV.js → chunk-7U5JDFQW.js} +2 -5
- package/dist/{chunk-G6JDROB4.js → chunk-FUMSJI3N.js} +13 -13
- package/dist/{chunk-PMBS2GFA.js → chunk-LFUC4ETD.js} +9 -12
- package/dist/{chunk-C2ZIFM22.js → chunk-T43IWAQK.js} +17 -24
- package/dist/{chunk-QHDBFVLU.js → chunk-YJKJJ323.js} +0 -4
- package/dist/{chunk-2D2RT2DW.js → chunk-Z3LAGZSM.js} +3 -8
- package/dist/clients/http/mod.d.ts +1 -1
- package/dist/clients/http/mod.js +1 -1
- package/dist/clients/local-storage/mod.d.ts +1 -1
- package/dist/clients/local-storage/mod.js +1 -1
- package/dist/clients/websocket/mod.d.ts +1 -1
- package/dist/clients/websocket/mod.js +1 -1
- package/dist/encrypt/mod.js +1 -1
- package/dist/src/mod.web.d.ts +1 -1
- package/dist/src/mod.web.js +10 -10
- package/dist/{types-Bw0Boe0n.d.ts → types-oQCx3U-_.d.ts} +2 -2
- package/dist/wallet/mod.js +1 -1
- package/package.json +2 -2
package/dist/apps/mod.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
// clients/local-storage/mod.ts
|
|
2
2
|
var LocalStorageClient = class {
|
|
3
|
-
config;
|
|
4
|
-
schema;
|
|
5
|
-
storage;
|
|
6
3
|
constructor(config) {
|
|
7
4
|
this.config = {
|
|
8
5
|
keyPrefix: config.keyPrefix || "b3nd:",
|
|
@@ -133,8 +130,8 @@ var LocalStorageClient = class {
|
|
|
133
130
|
} else if (sortBy === "timestamp") {
|
|
134
131
|
const aData = this.getStoredData(a.uri);
|
|
135
132
|
const bData = this.getStoredData(b.uri);
|
|
136
|
-
const aTs =
|
|
137
|
-
const bTs =
|
|
133
|
+
const aTs = aData?.ts || 0;
|
|
134
|
+
const bTs = bData?.ts || 0;
|
|
138
135
|
comparison = aTs - bTs;
|
|
139
136
|
}
|
|
140
137
|
return sortOrder === "asc" ? comparison : -comparison;
|
|
@@ -36,23 +36,23 @@ function decodeHex(hex) {
|
|
|
36
36
|
return bytes;
|
|
37
37
|
}
|
|
38
38
|
function encodeBase64(bytes) {
|
|
39
|
-
if (typeof
|
|
40
|
-
|
|
41
|
-
bytes.forEach((b) => binary += String.fromCharCode(b));
|
|
42
|
-
return btoa(binary);
|
|
39
|
+
if (typeof Buffer !== "undefined") {
|
|
40
|
+
return Buffer.from(bytes).toString("base64");
|
|
43
41
|
}
|
|
44
|
-
|
|
42
|
+
let binary = "";
|
|
43
|
+
bytes.forEach((b) => binary += String.fromCharCode(b));
|
|
44
|
+
return btoa(binary);
|
|
45
45
|
}
|
|
46
46
|
function decodeBase64(b64) {
|
|
47
|
-
if (typeof
|
|
48
|
-
|
|
49
|
-
const bytes = new Uint8Array(binary.length);
|
|
50
|
-
for (let i = 0; i < binary.length; i++) {
|
|
51
|
-
bytes[i] = binary.charCodeAt(i);
|
|
52
|
-
}
|
|
53
|
-
return bytes;
|
|
47
|
+
if (typeof Buffer !== "undefined") {
|
|
48
|
+
return new Uint8Array(Buffer.from(b64, "base64"));
|
|
54
49
|
}
|
|
55
|
-
|
|
50
|
+
const binary = atob(b64);
|
|
51
|
+
const bytes = new Uint8Array(binary.length);
|
|
52
|
+
for (let i = 0; i < binary.length; i++) {
|
|
53
|
+
bytes[i] = binary.charCodeAt(i);
|
|
54
|
+
}
|
|
55
|
+
return bytes;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
// encrypt/mod.ts
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
// clients/http/mod.ts
|
|
2
2
|
var HttpClient = class {
|
|
3
|
-
baseUrl;
|
|
4
|
-
headers;
|
|
5
|
-
timeout;
|
|
6
3
|
constructor(config) {
|
|
7
4
|
this.baseUrl = config.url.replace(/\/$/, "");
|
|
8
5
|
this.headers = config.headers || {};
|
|
@@ -109,19 +106,19 @@ var HttpClient = class {
|
|
|
109
106
|
try {
|
|
110
107
|
const { protocol, domain, path } = this.parseUri(uri);
|
|
111
108
|
const params = new URLSearchParams();
|
|
112
|
-
if (options
|
|
109
|
+
if (options?.page) {
|
|
113
110
|
params.set("page", options.page.toString());
|
|
114
111
|
}
|
|
115
|
-
if (options
|
|
112
|
+
if (options?.limit) {
|
|
116
113
|
params.set("limit", options.limit.toString());
|
|
117
114
|
}
|
|
118
|
-
if (options
|
|
115
|
+
if (options?.pattern) {
|
|
119
116
|
params.set("pattern", options.pattern);
|
|
120
117
|
}
|
|
121
|
-
if (options
|
|
118
|
+
if (options?.sortBy) {
|
|
122
119
|
params.set("sortBy", options.sortBy);
|
|
123
120
|
}
|
|
124
|
-
if (options
|
|
121
|
+
if (options?.sortOrder) {
|
|
125
122
|
params.set("sortOrder", options.sortOrder);
|
|
126
123
|
}
|
|
127
124
|
const queryString = params.toString();
|
|
@@ -135,8 +132,8 @@ var HttpClient = class {
|
|
|
135
132
|
success: true,
|
|
136
133
|
data: [],
|
|
137
134
|
pagination: {
|
|
138
|
-
page:
|
|
139
|
-
limit:
|
|
135
|
+
page: options?.page || 1,
|
|
136
|
+
limit: options?.limit || 50
|
|
140
137
|
}
|
|
141
138
|
};
|
|
142
139
|
}
|
|
@@ -147,8 +144,8 @@ var HttpClient = class {
|
|
|
147
144
|
success: true,
|
|
148
145
|
data: [],
|
|
149
146
|
pagination: {
|
|
150
|
-
page:
|
|
151
|
-
limit:
|
|
147
|
+
page: options?.page || 1,
|
|
148
|
+
limit: options?.limit || 50
|
|
152
149
|
}
|
|
153
150
|
};
|
|
154
151
|
}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
// clients/websocket/mod.ts
|
|
2
2
|
var WebSocketClient = class {
|
|
3
|
-
config;
|
|
4
|
-
ws = null;
|
|
5
|
-
connected = false;
|
|
6
|
-
reconnectAttempts = 0;
|
|
7
|
-
reconnectTimer = null;
|
|
8
|
-
pendingRequests = /* @__PURE__ */ new Map();
|
|
9
|
-
messageHandler = this.handleMessage.bind(this);
|
|
10
|
-
closeHandler = this.handleClose.bind(this);
|
|
11
|
-
errorHandler = this.handleError.bind(this);
|
|
12
3
|
constructor(config) {
|
|
4
|
+
this.ws = null;
|
|
5
|
+
this.connected = false;
|
|
6
|
+
this.reconnectAttempts = 0;
|
|
7
|
+
this.reconnectTimer = null;
|
|
8
|
+
this.pendingRequests = /* @__PURE__ */ new Map();
|
|
9
|
+
this.messageHandler = this.handleMessage.bind(this);
|
|
10
|
+
this.closeHandler = this.handleClose.bind(this);
|
|
11
|
+
this.errorHandler = this.handleError.bind(this);
|
|
13
12
|
this.config = {
|
|
14
13
|
timeout: 3e4,
|
|
15
14
|
...config,
|
|
@@ -26,19 +25,17 @@ var WebSocketClient = class {
|
|
|
26
25
|
* Ensure WebSocket connection is established
|
|
27
26
|
*/
|
|
28
27
|
async ensureConnected() {
|
|
29
|
-
|
|
30
|
-
if (this.connected && ((_a = this.ws) == null ? void 0 : _a.readyState) === WebSocket.OPEN) {
|
|
28
|
+
if (this.connected && this.ws?.readyState === WebSocket.OPEN) {
|
|
31
29
|
return;
|
|
32
30
|
}
|
|
33
|
-
if (
|
|
31
|
+
if (this.ws?.readyState === WebSocket.CONNECTING) {
|
|
34
32
|
return new Promise((resolve, reject) => {
|
|
35
33
|
const timeout = setTimeout(() => reject(new Error("Connection timeout")), this.config.timeout);
|
|
36
34
|
const checkConnection = () => {
|
|
37
|
-
var _a2, _b2;
|
|
38
35
|
if (this.connected) {
|
|
39
36
|
clearTimeout(timeout);
|
|
40
37
|
resolve();
|
|
41
|
-
} else if (
|
|
38
|
+
} else if (this.ws?.readyState === WebSocket.CLOSED || this.ws?.readyState === WebSocket.CLOSING) {
|
|
42
39
|
clearTimeout(timeout);
|
|
43
40
|
reject(new Error("Connection failed"));
|
|
44
41
|
} else {
|
|
@@ -78,8 +75,7 @@ var WebSocketClient = class {
|
|
|
78
75
|
this.ws.addEventListener("close", this.closeHandler);
|
|
79
76
|
this.ws.addEventListener("error", this.errorHandler);
|
|
80
77
|
const timeout = setTimeout(() => {
|
|
81
|
-
|
|
82
|
-
(_a = this.ws) == null ? void 0 : _a.close();
|
|
78
|
+
this.ws?.close();
|
|
83
79
|
reject(new Error("Connection timeout"));
|
|
84
80
|
}, this.config.timeout);
|
|
85
81
|
this.ws.addEventListener("open", () => clearTimeout(timeout), { once: true });
|
|
@@ -108,10 +104,9 @@ var WebSocketClient = class {
|
|
|
108
104
|
* Handle WebSocket close
|
|
109
105
|
*/
|
|
110
106
|
handleClose() {
|
|
111
|
-
var _a;
|
|
112
107
|
this.connected = false;
|
|
113
108
|
this.cleanupPendingRequests(new Error("WebSocket connection closed"));
|
|
114
|
-
if (
|
|
109
|
+
if (this.config.reconnect?.enabled && this.reconnectAttempts < (this.config.reconnect.maxAttempts || 5)) {
|
|
115
110
|
this.scheduleReconnect();
|
|
116
111
|
}
|
|
117
112
|
}
|
|
@@ -126,11 +121,10 @@ var WebSocketClient = class {
|
|
|
126
121
|
* Schedule reconnection attempt
|
|
127
122
|
*/
|
|
128
123
|
scheduleReconnect() {
|
|
129
|
-
var _a, _b;
|
|
130
124
|
if (this.reconnectTimer) {
|
|
131
125
|
clearTimeout(this.reconnectTimer);
|
|
132
126
|
}
|
|
133
|
-
const delay =
|
|
127
|
+
const delay = this.config.reconnect?.backoff === "exponential" ? (this.config.reconnect.interval || 1e3) * Math.pow(2, this.reconnectAttempts) : this.config.reconnect?.interval || 1e3;
|
|
134
128
|
this.reconnectTimer = setTimeout(() => {
|
|
135
129
|
this.reconnectAttempts++;
|
|
136
130
|
this.connect().catch(() => {
|
|
@@ -153,7 +147,6 @@ var WebSocketClient = class {
|
|
|
153
147
|
async sendRequest(type, payload) {
|
|
154
148
|
await this.ensureConnected();
|
|
155
149
|
return new Promise((resolve, reject) => {
|
|
156
|
-
var _a;
|
|
157
150
|
const id = crypto.randomUUID();
|
|
158
151
|
const request = { id, type, payload };
|
|
159
152
|
const timeout = setTimeout(() => {
|
|
@@ -172,7 +165,7 @@ var WebSocketClient = class {
|
|
|
172
165
|
timeout
|
|
173
166
|
});
|
|
174
167
|
try {
|
|
175
|
-
|
|
168
|
+
this.ws?.send(JSON.stringify(request));
|
|
176
169
|
} catch (error) {
|
|
177
170
|
this.pendingRequests.delete(id);
|
|
178
171
|
clearTimeout(timeout);
|
|
@@ -211,8 +204,8 @@ var WebSocketClient = class {
|
|
|
211
204
|
success: true,
|
|
212
205
|
data: [],
|
|
213
206
|
pagination: {
|
|
214
|
-
page:
|
|
215
|
-
limit:
|
|
207
|
+
page: options?.page || 1,
|
|
208
|
+
limit: options?.limit || 50
|
|
216
209
|
}
|
|
217
210
|
};
|
|
218
211
|
}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
// wallet/client.ts
|
|
2
2
|
var WalletClient = class {
|
|
3
|
-
walletServerUrl;
|
|
4
|
-
apiBasePath;
|
|
5
|
-
fetchImpl;
|
|
6
|
-
currentSession = null;
|
|
7
3
|
constructor(config) {
|
|
4
|
+
this.currentSession = null;
|
|
8
5
|
this.walletServerUrl = config.walletServerUrl.replace(/\/$/, "");
|
|
9
6
|
if (!config.apiBasePath || typeof config.apiBasePath !== "string") {
|
|
10
7
|
throw new Error("apiBasePath is required (e.g., '/api/v1')");
|
|
@@ -41,15 +38,13 @@ var WalletClient = class {
|
|
|
41
38
|
* Get current username (if authenticated)
|
|
42
39
|
*/
|
|
43
40
|
getUsername() {
|
|
44
|
-
|
|
45
|
-
return ((_a = this.currentSession) == null ? void 0 : _a.username) || null;
|
|
41
|
+
return this.currentSession?.username || null;
|
|
46
42
|
}
|
|
47
43
|
/**
|
|
48
44
|
* Get current JWT token (if authenticated)
|
|
49
45
|
*/
|
|
50
46
|
getToken() {
|
|
51
|
-
|
|
52
|
-
return ((_a = this.currentSession) == null ? void 0 : _a.token) || null;
|
|
47
|
+
return this.currentSession?.token || null;
|
|
53
48
|
}
|
|
54
49
|
/**
|
|
55
50
|
* Clear current session (logout)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { N as NodeProtocolInterface, a as HttpClientConfig, g as WriteResult, R as ReadResult, b as ListOptions, c as ListResult, D as DeleteResult, H as HealthStatus } from '../../types-
|
|
1
|
+
import { N as NodeProtocolInterface, a as HttpClientConfig, g as WriteResult, R as ReadResult, b as ListOptions, c as ListResult, D as DeleteResult, H as HealthStatus } from '../../types-oQCx3U-_.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* HttpClient - HTTP implementation of NodeProtocolInterface
|
package/dist/clients/http/mod.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { N as NodeProtocolInterface, d as LocalStorageClientConfig, g as WriteResult, R as ReadResult, b as ListOptions, c as ListResult, D as DeleteResult, H as HealthStatus } from '../../types-
|
|
1
|
+
import { N as NodeProtocolInterface, d as LocalStorageClientConfig, g as WriteResult, R as ReadResult, b as ListOptions, c as ListResult, D as DeleteResult, H as HealthStatus } from '../../types-oQCx3U-_.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* LocalStorageClient - Browser localStorage implementation of NodeProtocolInterface
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { N as NodeProtocolInterface, W as WebSocketClientConfig, g as WriteResult, R as ReadResult, b as ListOptions, c as ListResult, D as DeleteResult, H as HealthStatus } from '../../types-
|
|
1
|
+
import { N as NodeProtocolInterface, W as WebSocketClientConfig, g as WriteResult, R as ReadResult, b as ListOptions, c as ListResult, D as DeleteResult, H as HealthStatus } from '../../types-oQCx3U-_.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* WebSocketClient - WebSocket implementation of NodeProtocolInterface
|
package/dist/encrypt/mod.js
CHANGED
package/dist/src/mod.web.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { C as ClientError, D as DeleteResult, H as HealthStatus, a as HttpClientConfig, L as ListItem, b as ListOptions, c as ListResult, d as LocalStorageClientConfig, N as NodeProtocolInterface, P as PersistenceRecord, R as ReadResult, S as Schema, V as ValidationFn, W as WebSocketClientConfig, e as WebSocketRequest, f as WebSocketResponse, g as WriteResult } from '../types-
|
|
1
|
+
export { C as ClientError, D as DeleteResult, H as HealthStatus, a as HttpClientConfig, L as ListItem, b as ListOptions, c as ListResult, d as LocalStorageClientConfig, N as NodeProtocolInterface, P as PersistenceRecord, R as ReadResult, S as Schema, V as ValidationFn, W as WebSocketClientConfig, e as WebSocketRequest, f as WebSocketResponse, g as WriteResult } from '../types-oQCx3U-_.js';
|
|
2
2
|
export { HttpClient } from '../clients/http/mod.js';
|
|
3
3
|
export { WebSocketClient } from '../clients/websocket/mod.js';
|
|
4
4
|
export { LocalStorageClient } from '../clients/local-storage/mod.js';
|
package/dist/src/mod.web.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AppsClient
|
|
3
|
-
} from "../chunk-QHDBFVLU.js";
|
|
4
1
|
import {
|
|
5
2
|
mod_exports
|
|
6
|
-
} from "../chunk-
|
|
7
|
-
import {
|
|
8
|
-
WalletClient
|
|
9
|
-
} from "../chunk-2D2RT2DW.js";
|
|
3
|
+
} from "../chunk-FUMSJI3N.js";
|
|
10
4
|
import {
|
|
11
5
|
HttpClient
|
|
12
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-LFUC4ETD.js";
|
|
13
7
|
import {
|
|
14
8
|
LocalStorageClient
|
|
15
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-7U5JDFQW.js";
|
|
16
10
|
import {
|
|
17
11
|
WebSocketClient
|
|
18
|
-
} from "../chunk-
|
|
12
|
+
} from "../chunk-T43IWAQK.js";
|
|
13
|
+
import {
|
|
14
|
+
AppsClient
|
|
15
|
+
} from "../chunk-YJKJJ323.js";
|
|
16
|
+
import {
|
|
17
|
+
WalletClient
|
|
18
|
+
} from "../chunk-Z3LAGZSM.js";
|
|
19
19
|
import "../chunk-MLKGABMK.js";
|
|
20
20
|
export {
|
|
21
21
|
AppsClient,
|
|
@@ -198,8 +198,8 @@ interface LocalStorageClientConfig {
|
|
|
198
198
|
*/
|
|
199
199
|
declare class ClientError extends Error {
|
|
200
200
|
readonly code: string;
|
|
201
|
-
readonly details?: unknown;
|
|
202
|
-
constructor(message: string, code: string, details?: unknown);
|
|
201
|
+
readonly details?: unknown | undefined;
|
|
202
|
+
constructor(message: string, code: string, details?: unknown | undefined);
|
|
203
203
|
}
|
|
204
204
|
/**
|
|
205
205
|
* WebSocket protocol types for request/response communication
|
package/dist/wallet/mod.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bandeira-tech/b3nd-web",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Browser-focused B3nd SDK bundle",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/src/mod.web.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"dist"
|
|
41
41
|
],
|
|
42
42
|
"scripts": {
|
|
43
|
-
"build": "tsup src/mod.web.ts wallet/mod.ts apps/mod.ts encrypt/mod.ts clients/http/mod.ts clients/local-storage/mod.ts clients/websocket/mod.ts --dts --format esm --out-dir dist --clean",
|
|
43
|
+
"build": "tsup src/mod.web.ts wallet/mod.ts apps/mod.ts encrypt/mod.ts clients/http/mod.ts clients/local-storage/mod.ts clients/websocket/mod.ts --dts --format esm --out-dir dist --clean --tsconfig tsconfig.web.json",
|
|
44
44
|
"clean": "rm -rf dist",
|
|
45
45
|
"lint": "deno lint src/",
|
|
46
46
|
"format": "deno fmt src/"
|