@btps/sdk 0.0.0-stage → 1.1.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/CHANGELOG.md +149 -0
- package/LICENSE +190 -0
- package/NOTICE +25 -0
- package/README.md +261 -2
- package/dist/client/btpsAgent.d.ts +20 -0
- package/dist/client/btpsAgent.js +172 -0
- package/dist/client/btpsClient.d.ts +202 -0
- package/dist/client/btpsClient.js +602 -0
- package/dist/client/btpsTransporter.d.ts +52 -0
- package/dist/client/btpsTransporter.js +249 -0
- package/dist/client/constants.ts/index.d.ts +11 -0
- package/dist/client/constants.ts/index.js +20 -0
- package/dist/client/index.d.ts +12 -0
- package/dist/client/index.js +27 -0
- package/dist/client/libs/schema.d.ts +27604 -0
- package/dist/client/libs/schema.js +56 -0
- package/dist/client/libs/timeouts.d.ts +22 -0
- package/dist/client/libs/timeouts.js +19 -0
- package/dist/client/types/index.d.ts +155 -0
- package/dist/client/types/index.js +7 -0
- package/dist/core/authentication/BtpsAuthentication.d.ts +128 -0
- package/dist/core/authentication/BtpsAuthentication.js +293 -0
- package/dist/core/authentication/index.d.ts +11 -0
- package/dist/core/authentication/index.js +12 -0
- package/dist/core/authentication/keyProof.d.ts +18 -0
- package/dist/core/authentication/keyProof.js +16 -0
- package/dist/core/authentication/storage/InMemoryAuthSessionStore.d.ts +55 -0
- package/dist/core/authentication/storage/InMemoryAuthSessionStore.js +62 -0
- package/dist/core/authentication/storage/InMemoryTokenStore.d.ts +63 -0
- package/dist/core/authentication/storage/InMemoryTokenStore.js +63 -0
- package/dist/core/authentication/types.d.ts +135 -0
- package/dist/core/authentication/types.js +7 -0
- package/dist/core/crypto/decryptVerify.d.ts +9 -0
- package/dist/core/crypto/decryptVerify.js +45 -0
- package/dist/core/crypto/decrypter-interface.d.ts +25 -0
- package/dist/core/crypto/decrypter-interface.js +7 -0
- package/dist/core/crypto/index.d.ts +77 -0
- package/dist/core/crypto/index.js +210 -0
- package/dist/core/crypto/jcs.d.ts +28 -0
- package/dist/core/crypto/jcs.js +60 -0
- package/dist/core/crypto/keygen.d.ts +9 -0
- package/dist/core/crypto/keygen.js +35 -0
- package/dist/core/crypto/pem-decrypter.d.ts +26 -0
- package/dist/core/crypto/pem-decrypter.js +52 -0
- package/dist/core/crypto/pem-signer.d.ts +21 -0
- package/dist/core/crypto/pem-signer.js +34 -0
- package/dist/core/crypto/signEncrypt.d.ts +34 -0
- package/dist/core/crypto/signEncrypt.js +75 -0
- package/dist/core/crypto/signer-interface.d.ts +22 -0
- package/dist/core/crypto/signer-interface.js +7 -0
- package/dist/core/crypto/types.d.ts +79 -0
- package/dist/core/crypto/types.js +7 -0
- package/dist/core/delegation/BtpsDelegator.d.ts +102 -0
- package/dist/core/delegation/BtpsDelegator.js +118 -0
- package/dist/core/delegation/index.d.ts +7 -0
- package/dist/core/delegation/index.js +8 -0
- package/dist/core/error/constant.d.ts +66 -0
- package/dist/core/error/constant.js +194 -0
- package/dist/core/error/index.d.ts +35 -0
- package/dist/core/error/index.js +52 -0
- package/dist/core/error/types.d.ts +16 -0
- package/dist/core/error/types.js +7 -0
- package/dist/core/server/constants/btps-protocol.d.ts +17 -0
- package/dist/core/server/constants/btps-protocol.js +25 -0
- package/dist/core/server/constants/control.d.ts +7 -0
- package/dist/core/server/constants/control.js +11 -0
- package/dist/core/server/constants/currency.d.ts +7 -0
- package/dist/core/server/constants/currency.js +332 -0
- package/dist/core/server/constants/index.d.ts +26 -0
- package/dist/core/server/constants/index.js +61 -0
- package/dist/core/server/constants/limits.d.ts +50 -0
- package/dist/core/server/constants/limits.js +50 -0
- package/dist/core/server/helpers/BtpsMessageQueue.d.ts +13 -0
- package/dist/core/server/helpers/BtpsMessageQueue.js +12 -0
- package/dist/core/server/helpers/InMemoryQueue.d.ts +16 -0
- package/dist/core/server/helpers/InMemoryQueue.js +35 -0
- package/dist/core/server/helpers/index.d.ts +8 -0
- package/dist/core/server/helpers/index.js +9 -0
- package/dist/core/server/schemas/artifacts/agentSchema.d.ts +4565 -0
- package/dist/core/server/schemas/artifacts/agentSchema.js +51 -0
- package/dist/core/server/schemas/artifacts/artifacts.d.ts +4920 -0
- package/dist/core/server/schemas/artifacts/artifacts.js +21 -0
- package/dist/core/server/schemas/artifacts/controlSchema.d.ts +23 -0
- package/dist/core/server/schemas/artifacts/controlSchema.js +18 -0
- package/dist/core/server/schemas/artifacts/identityLookupSchema.d.ts +32 -0
- package/dist/core/server/schemas/artifacts/identityLookupSchema.js +21 -0
- package/dist/core/server/schemas/artifacts/transporterSchema.d.ts +553 -0
- package/dist/core/server/schemas/artifacts/transporterSchema.js +60 -0
- package/dist/core/server/schemas/btpsDocsSchema.d.ts +4519 -0
- package/dist/core/server/schemas/btpsDocsSchema.js +272 -0
- package/dist/core/server/schemas/helpers.d.ts +1612 -0
- package/dist/core/server/schemas/helpers.js +87 -0
- package/dist/core/server/schemas/responseSchema.d.ts +6918 -0
- package/dist/core/server/schemas/responseSchema.js +86 -0
- package/dist/core/server/schemas/schema.d.ts +4916 -0
- package/dist/core/server/schemas/schema.js +70 -0
- package/dist/core/server/schemas/shared.d.ts +21 -0
- package/dist/core/server/schemas/shared.js +18 -0
- package/dist/core/server/types.d.ts +172 -0
- package/dist/core/server/types.js +7 -0
- package/dist/core/storage/AbstractIdentityStore.d.ts +17 -0
- package/dist/core/storage/AbstractIdentityStore.js +13 -0
- package/dist/core/storage/AbstractStorageStore.d.ts +16 -0
- package/dist/core/storage/AbstractStorageStore.js +17 -0
- package/dist/core/storage/JsonIdentityStore.d.ts +29 -0
- package/dist/core/storage/JsonIdentityStore.js +39 -0
- package/dist/core/storage/JsonStorageStore.d.ts +59 -0
- package/dist/core/storage/JsonStorageStore.js +110 -0
- package/dist/core/storage/index.d.ts +11 -0
- package/dist/core/storage/index.js +18 -0
- package/dist/core/storage/types.d.ts +28 -0
- package/dist/core/storage/types.js +7 -0
- package/dist/core/trust/index.d.ts +10 -0
- package/dist/core/trust/index.js +15 -0
- package/dist/core/trust/storage/AbstractTrustStore.d.ts +23 -0
- package/dist/core/trust/storage/AbstractTrustStore.js +13 -0
- package/dist/core/trust/storage/JsonTrustStore.d.ts +33 -0
- package/dist/core/trust/storage/JsonTrustStore.js +42 -0
- package/dist/core/trust/trustUtils.d.ts +78 -0
- package/dist/core/trust/trustUtils.js +41 -0
- package/dist/core/trust/types.d.ts +53 -0
- package/dist/core/trust/types.js +7 -0
- package/dist/core/utils/identity.d.ts +20 -0
- package/dist/core/utils/identity.js +22 -0
- package/dist/core/utils/index.d.ts +70 -0
- package/dist/core/utils/index.js +124 -0
- package/dist/core/utils/types.d.ts +10 -0
- package/dist/core/utils/types.js +7 -0
- package/dist/core/utils/validation.d.ts +14 -0
- package/dist/core/utils/validation.js +13 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/server/btpsServer.d.ts +292 -0
- package/dist/server/btpsServer.js +827 -0
- package/dist/server/index.d.ts +11 -0
- package/dist/server/index.js +15 -0
- package/dist/server/libs/abstractRateLimiter.d.ts +10 -0
- package/dist/server/libs/abstractRateLimiter.js +15 -0
- package/dist/server/libs/artifactSizeGuard.d.ts +27 -0
- package/dist/server/libs/artifactSizeGuard.js +44 -0
- package/dist/server/libs/artifactTimeWindow.d.ts +24 -0
- package/dist/server/libs/artifactTimeWindow.js +30 -0
- package/dist/server/libs/btpsFactory.d.ts +29 -0
- package/dist/server/libs/btpsFactory.js +49 -0
- package/dist/server/libs/btpsLightweightFactory.d.ts +35 -0
- package/dist/server/libs/btpsLightweightFactory.js +37 -0
- package/dist/server/libs/btpsRegistry.d.ts +14 -0
- package/dist/server/libs/btpsRegistry.js +16 -0
- package/dist/server/libs/btpsSimpleMetricsTracker.d.ts +13 -0
- package/dist/server/libs/btpsSimpleMetricsTracker.js +21 -0
- package/dist/server/libs/btpsSimpleRateLimiter.d.ts +28 -0
- package/dist/server/libs/btpsSimpleRateLimiter.js +46 -0
- package/dist/server/libs/connectionTimeout.d.ts +16 -0
- package/dist/server/libs/connectionTimeout.js +14 -0
- package/dist/server/libs/defaultMiddleware.d.ts +8 -0
- package/dist/server/libs/defaultMiddleware.js +128 -0
- package/dist/server/libs/inFlightLimit.d.ts +18 -0
- package/dist/server/libs/inFlightLimit.js +17 -0
- package/dist/server/libs/index.d.ts +18 -0
- package/dist/server/libs/index.js +34 -0
- package/dist/server/libs/middlewareManager.d.ts +59 -0
- package/dist/server/libs/middlewareManager.js +126 -0
- package/dist/server/libs/type.d.ts +22 -0
- package/dist/server/libs/type.js +7 -0
- package/dist/server/types.d.ts +236 -0
- package/dist/server/types.js +7 -0
- package/package.json +126 -4
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2025 Bhupendra Tamang
|
|
4
|
+
* Licensed under the Apache License, Version 2.0
|
|
5
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { BTP_ERROR_IDENTITY, BTPErrorException } from "../core/error/index.js";
|
|
9
|
+
import { BtpsClient } from "./btpsClient.js";
|
|
10
|
+
import { isValidIdentity } from "../core/utils/index.js";
|
|
11
|
+
import { BTP_PROTOCOL_VERSION } from "../core/server/constants/index.js";
|
|
12
|
+
import {
|
|
13
|
+
BTP_TRANSPORTER_DEFAULT_CONNECTION_TTL_SECONDS,
|
|
14
|
+
BTP_TRANSPORTER_DEFAULT_MAX_CONNECTIONS,
|
|
15
|
+
BTP_TRANSPORTER_ERROR_CONNECTION_ALREADY_EXISTS,
|
|
16
|
+
BTP_TRANSPORTER_ERROR_MAX_CONNECTIONS_REACHED
|
|
17
|
+
} from "./constants.ts/index.js";
|
|
18
|
+
import { BtpTransporterArtifactSchema } from "../core/server/schemas/artifacts/transporterSchema.js";
|
|
19
|
+
import { validate } from "../core/utils/validation.js";
|
|
20
|
+
import { EventEmitter } from "events";
|
|
21
|
+
class BtpsTransporter {
|
|
22
|
+
connections = new Map();
|
|
23
|
+
connectionLock = new Map();
|
|
24
|
+
clientOptions;
|
|
25
|
+
maxConnections;
|
|
26
|
+
connectionTTLSeconds;
|
|
27
|
+
emitter = new EventEmitter();
|
|
28
|
+
constructor(options) {
|
|
29
|
+
const { maxConnections, connectionTTLSeconds, ...clientOptions } = options;
|
|
30
|
+
this.maxConnections = maxConnections ?? BTP_TRANSPORTER_DEFAULT_MAX_CONNECTIONS, this.connectionTTLSeconds = connectionTTLSeconds ?? BTP_TRANSPORTER_DEFAULT_CONNECTION_TTL_SECONDS, this.clientOptions = {
|
|
31
|
+
...clientOptions
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
createClient(to, clientOptions) {
|
|
35
|
+
try {
|
|
36
|
+
return {
|
|
37
|
+
client: new BtpsClient({
|
|
38
|
+
to,
|
|
39
|
+
...clientOptions ?? this.clientOptions
|
|
40
|
+
}),
|
|
41
|
+
error: void 0
|
|
42
|
+
};
|
|
43
|
+
} catch (error) {
|
|
44
|
+
return { client: void 0, error };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
attachListeners(connection) {
|
|
48
|
+
connection.listeners = {
|
|
49
|
+
connected: () => {
|
|
50
|
+
connection.isActive = !0, this.emitter.emit("connectionConnected", connection.id);
|
|
51
|
+
},
|
|
52
|
+
end: (endInfo) => {
|
|
53
|
+
connection.isActive = !1, this.emitter.emit("connectionEnd", connection.id, endInfo);
|
|
54
|
+
},
|
|
55
|
+
error: (errorInfo) => {
|
|
56
|
+
connection.isActive = !1, this.emitter.emit("connectionError", connection.id, errorInfo);
|
|
57
|
+
},
|
|
58
|
+
message: (msg) => {
|
|
59
|
+
connection.isActive = !0, this.emitter.emit("connectionMessage", connection.id, msg);
|
|
60
|
+
},
|
|
61
|
+
close: (closeInfo) => {
|
|
62
|
+
connection.isActive = !1, this.emitter.emit("connectionClose", connection.id, closeInfo);
|
|
63
|
+
}
|
|
64
|
+
}, Object.keys(connection.listeners).forEach((event) => {
|
|
65
|
+
connection.client.on(event, connection.listeners[event]);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
detachListeners(connection) {
|
|
69
|
+
connection.listeners && (Object.keys(connection.listeners).forEach((event) => {
|
|
70
|
+
connection.client.off(event, connection.listeners[event]);
|
|
71
|
+
}), delete connection.listeners);
|
|
72
|
+
}
|
|
73
|
+
async performConnectionRegistration(to, clientOptions, override = !1) {
|
|
74
|
+
if (!isValidIdentity(to))
|
|
75
|
+
return {
|
|
76
|
+
connection: void 0,
|
|
77
|
+
error: new BTPErrorException(BTP_ERROR_IDENTITY, {
|
|
78
|
+
cause: "Invalid identity",
|
|
79
|
+
meta: { to }
|
|
80
|
+
})
|
|
81
|
+
};
|
|
82
|
+
if (this.connections.get(to))
|
|
83
|
+
if (override)
|
|
84
|
+
this.deregisterConnection(to);
|
|
85
|
+
else
|
|
86
|
+
return {
|
|
87
|
+
connection: void 0,
|
|
88
|
+
error: new BTPErrorException(BTP_TRANSPORTER_ERROR_CONNECTION_ALREADY_EXISTS, {
|
|
89
|
+
cause: "Connection already exists",
|
|
90
|
+
meta: { to }
|
|
91
|
+
})
|
|
92
|
+
};
|
|
93
|
+
if (this.connections.size >= this.maxConnections) {
|
|
94
|
+
const idlest = [...this.connections.values()].filter((c) => c.inFlight === 0).sort((a, b) => a.lastUsedAt.localeCompare(b.lastUsedAt))[0];
|
|
95
|
+
idlest && this.deregisterConnection(idlest.id);
|
|
96
|
+
}
|
|
97
|
+
if (this.connections.size >= this.maxConnections)
|
|
98
|
+
return {
|
|
99
|
+
connection: void 0,
|
|
100
|
+
error: new BTPErrorException(BTP_TRANSPORTER_ERROR_MAX_CONNECTIONS_REACHED, {
|
|
101
|
+
cause: "Max connections reached",
|
|
102
|
+
meta: { maxConnections: this.maxConnections }
|
|
103
|
+
})
|
|
104
|
+
};
|
|
105
|
+
const dateNow = ( new Date()).toISOString(), { client, error } = this.createClient(to, clientOptions);
|
|
106
|
+
if (error)
|
|
107
|
+
return { connection: void 0, error };
|
|
108
|
+
const newConnection = {
|
|
109
|
+
id: to,
|
|
110
|
+
client,
|
|
111
|
+
createdAt: dateNow,
|
|
112
|
+
updatedAt: dateNow,
|
|
113
|
+
lastUsedAt: dateNow,
|
|
114
|
+
isActive: !1,
|
|
115
|
+
clientOptions: clientOptions ?? { to, ...this.clientOptions },
|
|
116
|
+
getStatus: () => client.getConnectionStates(),
|
|
117
|
+
timeout: this.createConnectionTimeout(to),
|
|
118
|
+
inFlight: 0
|
|
119
|
+
};
|
|
120
|
+
return this.connections.set(to, newConnection), this.attachListeners(newConnection), this.emitter.emit("connectionCreated", to), { connection: newConnection, error: void 0 };
|
|
121
|
+
}
|
|
122
|
+
buildClientErrorResponse(error) {
|
|
123
|
+
return Promise.resolve({
|
|
124
|
+
error
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
createConnectionTimeout(connectionId, ttlSeconds) {
|
|
128
|
+
return setTimeout(
|
|
129
|
+
() => {
|
|
130
|
+
const connection = this.connections.get(connectionId);
|
|
131
|
+
if (connection && connection.inFlight > 0) {
|
|
132
|
+
connection.timeout = this.createConnectionTimeout(connectionId, connection.ttlSeconds);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
this.deregisterConnection(connectionId);
|
|
136
|
+
},
|
|
137
|
+
(ttlSeconds ?? this.connectionTTLSeconds) * 1e3
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
touch(connection) {
|
|
141
|
+
clearTimeout(connection.timeout), connection.timeout = this.createConnectionTimeout(connection.id, connection.ttlSeconds), connection.lastUsedAt = ( new Date()).toISOString();
|
|
142
|
+
}
|
|
143
|
+
async registerConnection(to, clientOptions, override = !1) {
|
|
144
|
+
const existingLock = this.connectionLock.get(to);
|
|
145
|
+
existingLock && await existingLock;
|
|
146
|
+
const registrationPromise = this.performConnectionRegistration(to, clientOptions, override), lockPromise = registrationPromise.then(() => {
|
|
147
|
+
});
|
|
148
|
+
this.connectionLock.set(to, lockPromise);
|
|
149
|
+
const { connection, error } = await registrationPromise;
|
|
150
|
+
if (this.connectionLock.delete(to), error)
|
|
151
|
+
throw error;
|
|
152
|
+
return connection;
|
|
153
|
+
}
|
|
154
|
+
deregisterConnection(to) {
|
|
155
|
+
const connection = this.connections.get(to);
|
|
156
|
+
if (!connection) return;
|
|
157
|
+
const { client, timeout } = connection;
|
|
158
|
+
this.detachListeners(connection), client.destroy(), clearTimeout(timeout), this.connections.delete(to), this.emitter.emit("connectionDestroyed", to);
|
|
159
|
+
}
|
|
160
|
+
async transport(to, artifact, clientOptions) {
|
|
161
|
+
const validationResult = validate(BtpTransporterArtifactSchema, artifact);
|
|
162
|
+
if (!validationResult.success)
|
|
163
|
+
return this.buildClientErrorResponse(
|
|
164
|
+
new BTPErrorException(
|
|
165
|
+
{ message: "Invalid artifact" },
|
|
166
|
+
{ cause: { validationZodError: validationResult.error }, meta: { artifact } }
|
|
167
|
+
)
|
|
168
|
+
);
|
|
169
|
+
if (!this.connections.has(to))
|
|
170
|
+
try {
|
|
171
|
+
await this.registerConnection(to, clientOptions);
|
|
172
|
+
} catch (error) {
|
|
173
|
+
return this.buildClientErrorResponse(error);
|
|
174
|
+
}
|
|
175
|
+
const connection = this.connections.get(to);
|
|
176
|
+
connection.inFlight++, this.touch(connection);
|
|
177
|
+
try {
|
|
178
|
+
return await connection.client.send(artifact, clientOptions?.replyTimeoutMs);
|
|
179
|
+
} finally {
|
|
180
|
+
connection.inFlight--, this.connections.get(to) === connection && this.touch(connection);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
async transportBatch(to, artifacts, clientOptions) {
|
|
184
|
+
return Promise.all(artifacts.map((artifact) => this.transport(to, artifact, clientOptions)));
|
|
185
|
+
}
|
|
186
|
+
getMaxConnections() {
|
|
187
|
+
return this.maxConnections;
|
|
188
|
+
}
|
|
189
|
+
setMaxConnections(maxConnections) {
|
|
190
|
+
this.maxConnections = maxConnections;
|
|
191
|
+
}
|
|
192
|
+
getConnectionTTLSeconds() {
|
|
193
|
+
return this.connectionTTLSeconds;
|
|
194
|
+
}
|
|
195
|
+
updateConnectionTTLSeconds(connectionTTLSeconds, updateExistingConnections = !1) {
|
|
196
|
+
this.connectionTTLSeconds = connectionTTLSeconds, updateExistingConnections && this.connections.forEach((connection) => {
|
|
197
|
+
this.updateConnection(connection.id, void 0, connectionTTLSeconds);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
getClientOptions() {
|
|
201
|
+
return this.clientOptions;
|
|
202
|
+
}
|
|
203
|
+
getProtocolVersion() {
|
|
204
|
+
return BTP_PROTOCOL_VERSION;
|
|
205
|
+
}
|
|
206
|
+
getConnections() {
|
|
207
|
+
return Array.from(this.connections.values()).map((connection) => {
|
|
208
|
+
const { timeout, ...rest } = connection;
|
|
209
|
+
return rest;
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
getConnection(id) {
|
|
213
|
+
const connection = this.connections.get(id);
|
|
214
|
+
if (!connection)
|
|
215
|
+
return;
|
|
216
|
+
const { timeout, ...rest } = connection;
|
|
217
|
+
return rest;
|
|
218
|
+
}
|
|
219
|
+
updateConnection(id, clientOptions, ttlSeconds) {
|
|
220
|
+
const connection = this.connections.get(id);
|
|
221
|
+
if (connection)
|
|
222
|
+
return clientOptions && connection.client.update(clientOptions), ttlSeconds && (connection.ttlSeconds = ttlSeconds, clearTimeout(connection.timeout), connection.timeout = this.createConnectionTimeout(id, ttlSeconds)), connection.updatedAt = ( new Date()).toISOString(), this.emitter.emit("connectionUpdated", id), connection;
|
|
223
|
+
}
|
|
224
|
+
getActiveConnections() {
|
|
225
|
+
return Array.from(this.connections.values()).filter((connection) => connection.isActive);
|
|
226
|
+
}
|
|
227
|
+
getTotalConnections() {
|
|
228
|
+
return this.connections.size;
|
|
229
|
+
}
|
|
230
|
+
getTotalActiveConnections() {
|
|
231
|
+
return this.getActiveConnections().length;
|
|
232
|
+
}
|
|
233
|
+
getMetrics() {
|
|
234
|
+
return {
|
|
235
|
+
totalConnections: this.getTotalConnections(),
|
|
236
|
+
activeConnections: this.getTotalActiveConnections()
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
on = (event, listener) => (this.emitter.on(event, listener), this);
|
|
240
|
+
off = (event, listener) => (this.emitter.off(event, listener), this);
|
|
241
|
+
destroy() {
|
|
242
|
+
this.connections.forEach((connection) => {
|
|
243
|
+
this.deregisterConnection(connection.id);
|
|
244
|
+
}), this.connectionLock.clear(), this.emitter.removeAllListeners(), this.connections.clear();
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
export {
|
|
248
|
+
BtpsTransporter
|
|
249
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2025 Bhupendra Tamang
|
|
4
|
+
* Licensed under the Apache License, Version 2.0
|
|
5
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*/
|
|
7
|
+
import type { BTPError } from '../../core/error/types.js';
|
|
8
|
+
export declare const BTP_TRANSPORTER_DEFAULT_MAX_CONNECTIONS = 10;
|
|
9
|
+
export declare const BTP_TRANSPORTER_DEFAULT_CONNECTION_TTL_SECONDS = 300;
|
|
10
|
+
export declare const BTP_TRANSPORTER_ERROR_CONNECTION_ALREADY_EXISTS: BTPError;
|
|
11
|
+
export declare const BTP_TRANSPORTER_ERROR_MAX_CONNECTIONS_REACHED: BTPError;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2025 Bhupendra Tamang
|
|
4
|
+
* Licensed under the Apache License, Version 2.0
|
|
5
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const BTP_TRANSPORTER_DEFAULT_MAX_CONNECTIONS = 10, BTP_TRANSPORTER_DEFAULT_CONNECTION_TTL_SECONDS = 300, BTP_TRANSPORTER_ERROR_CONNECTION_ALREADY_EXISTS = {
|
|
9
|
+
code: "BTP_TRANSPORTER_ERROR_CONNECTION_ALREADY_EXISTS",
|
|
10
|
+
message: "Connection already exists"
|
|
11
|
+
}, BTP_TRANSPORTER_ERROR_MAX_CONNECTIONS_REACHED = {
|
|
12
|
+
code: "BTP_TRANSPORTER_ERROR_MAX_CONNECTIONS_REACHED",
|
|
13
|
+
message: "Max connections reached"
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
BTP_TRANSPORTER_DEFAULT_CONNECTION_TTL_SECONDS,
|
|
17
|
+
BTP_TRANSPORTER_DEFAULT_MAX_CONNECTIONS,
|
|
18
|
+
BTP_TRANSPORTER_ERROR_CONNECTION_ALREADY_EXISTS,
|
|
19
|
+
BTP_TRANSPORTER_ERROR_MAX_CONNECTIONS_REACHED
|
|
20
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2025 Bhupendra Tamang
|
|
4
|
+
* Licensed under the Apache License, Version 2.0
|
|
5
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*/
|
|
7
|
+
export * from './types/index.js';
|
|
8
|
+
export { BtpsAgent } from './btpsAgent.js';
|
|
9
|
+
export { BtpsClient } from './btpsClient.js';
|
|
10
|
+
export { BtpsTransporter } from './btpsTransporter.js';
|
|
11
|
+
export * from './constants.ts/index.js';
|
|
12
|
+
export { MIN_CONNECT_TIMEOUT_MS, DEFAULT_CONNECT_TIMEOUT_MS, MIN_REPLY_TIMEOUT_MS, DEFAULT_REPLY_TIMEOUT_MS, } from './libs/timeouts.js';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2025 Bhupendra Tamang
|
|
4
|
+
* Licensed under the Apache License, Version 2.0
|
|
5
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export * from "./types/index.js";
|
|
9
|
+
import { BtpsAgent } from "./btpsAgent.js";
|
|
10
|
+
import { BtpsClient } from "./btpsClient.js";
|
|
11
|
+
import { BtpsTransporter } from "./btpsTransporter.js";
|
|
12
|
+
export * from "./constants.ts/index.js";
|
|
13
|
+
import {
|
|
14
|
+
MIN_CONNECT_TIMEOUT_MS,
|
|
15
|
+
DEFAULT_CONNECT_TIMEOUT_MS,
|
|
16
|
+
MIN_REPLY_TIMEOUT_MS,
|
|
17
|
+
DEFAULT_REPLY_TIMEOUT_MS
|
|
18
|
+
} from "./libs/timeouts.js";
|
|
19
|
+
export {
|
|
20
|
+
BtpsAgent,
|
|
21
|
+
BtpsClient,
|
|
22
|
+
BtpsTransporter,
|
|
23
|
+
DEFAULT_CONNECT_TIMEOUT_MS,
|
|
24
|
+
DEFAULT_REPLY_TIMEOUT_MS,
|
|
25
|
+
MIN_CONNECT_TIMEOUT_MS,
|
|
26
|
+
MIN_REPLY_TIMEOUT_MS
|
|
27
|
+
};
|