@private.me/xbind 3.0.1 → 3.0.2
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/README.md +55 -14
- package/dist-standalone/_deps/mldsa-wasm/dist/mldsa.js +1920 -1
- package/dist-standalone/_deps/shared/cjs/errors.js +729 -1
- package/dist-standalone/_deps/shared/cjs/index.js +463 -1
- package/dist-standalone/_deps/shared/cjs/types.js +315 -1
- package/dist-standalone/_deps/shared/errors.js +244 -1
- package/dist-standalone/_deps/shared/index.js +72 -1
- package/dist-standalone/_deps/shared/types.js +86 -1
- package/dist-standalone/_deps/ux-helpers/cjs/errors.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/index.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/progress.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/search.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/types.js +1 -1
- package/dist-standalone/_deps/ux-helpers/errors.js +1 -1
- package/dist-standalone/_deps/ux-helpers/index.js +1 -1
- package/dist-standalone/_deps/ux-helpers/pagination.js +1 -1
- package/dist-standalone/_deps/ux-helpers/progress.js +1 -1
- package/dist-standalone/_deps/ux-helpers/search.js +1 -1
- package/dist-standalone/_deps/xchange/auto-accept.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/auto-accept.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/errors.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/index.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/invite-client.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/lazy-init.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/trust-integration.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/xchange.js +1 -1
- package/dist-standalone/_deps/xchange/errors.js +1 -1
- package/dist-standalone/_deps/xchange/index.js +1 -1
- package/dist-standalone/_deps/xchange/invite-client.js +1 -1
- package/dist-standalone/_deps/xchange/lazy-init.js +1 -1
- package/dist-standalone/_deps/xchange/trust-integration.js +1 -1
- package/dist-standalone/_deps/xchange/xchange.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/discovery.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/errors.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/index.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/registry.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/schema.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/types.js +1 -1
- package/dist-standalone/_deps/xregistry/discovery.js +1 -1
- package/dist-standalone/_deps/xregistry/errors.js +1 -1
- package/dist-standalone/_deps/xregistry/index.js +1 -1
- package/dist-standalone/_deps/xregistry/registry.js +1 -1
- package/dist-standalone/_deps/xregistry/schema.js +1 -1
- package/dist-standalone/_deps/xregistry/types.js +1 -1
- package/dist-standalone/agent-call.js +659 -1
- package/dist-standalone/agent-sdk.js +328 -1
- package/dist-standalone/agent.js +1800 -1
- package/dist-standalone/approval.js +193 -1
- package/dist-standalone/async-iterators.js +382 -1
- package/dist-standalone/auth.js +219 -1
- package/dist-standalone/auto-accept.js +229 -1
- package/dist-standalone/backup-config.js +201 -1
- package/dist-standalone/backup.js +326 -1
- package/dist-standalone/batch-operations.js +388 -1
- package/dist-standalone/cancellation.js +477 -1
- package/dist-standalone/checkpoint.js +186 -1
- package/dist-standalone/circuit-breaker.js +468 -1
- package/dist-standalone/cjs/agent-call.js +701 -1
- package/dist-standalone/cjs/agent-sdk.js +332 -1
- package/dist-standalone/cjs/agent.js +1837 -1
- package/dist-standalone/cjs/approval.js +199 -1
- package/dist-standalone/cjs/async-iterators.js +392 -1
- package/dist-standalone/cjs/auth.js +225 -1
- package/dist-standalone/cjs/auto-accept.js +233 -1
- package/dist-standalone/cjs/backup-config.js +207 -1
- package/dist-standalone/cjs/backup.js +330 -1
- package/dist-standalone/cjs/batch-operations.js +397 -1
- package/dist-standalone/cjs/cancellation.js +490 -1
- package/dist-standalone/cjs/checkpoint.js +193 -1
- package/dist-standalone/cjs/circuit-breaker.js +476 -1
- package/dist-standalone/cjs/cli/init.js +492 -1
- package/dist-standalone/cjs/config-validation.js +522 -1
- package/dist-standalone/cjs/connect.js +312 -1
- package/dist-standalone/cjs/connection-pool.js +506 -1
- package/dist-standalone/cjs/correlation-id.js +339 -1
- package/dist-standalone/cjs/crypto-utils.js +176 -1
- package/dist-standalone/cjs/debug-mode.js +534 -1
- package/dist-standalone/cjs/did-document.js +101 -1
- package/dist-standalone/cjs/did-privateme.js +130 -1
- package/dist-standalone/cjs/did-web.js +201 -1
- package/dist-standalone/cjs/discovery.js +462 -1
- package/dist-standalone/cjs/dual-mode.js +251 -1
- package/dist-standalone/cjs/email-templates.js +313 -1
- package/dist-standalone/cjs/email-transport.js +239 -1
- package/dist-standalone/cjs/envelope.js +538 -1
- package/dist-standalone/cjs/errors.js +913 -1
- package/dist-standalone/cjs/event-emitter.js +461 -1
- package/dist-standalone/cjs/gateway-state.js +55 -1
- package/dist-standalone/cjs/gateway-transport.js +120 -1
- package/dist-standalone/cjs/graceful-degradation.js +403 -1
- package/dist-standalone/cjs/guardrails.js +223 -1
- package/dist-standalone/cjs/health-check.js +336 -1
- package/dist-standalone/cjs/http-compat.js +272 -1
- package/dist-standalone/cjs/http-status-map.js +571 -1
- package/dist-standalone/cjs/identity.js +645 -1
- package/dist-standalone/cjs/index.js +406 -1
- package/dist-standalone/cjs/invitation.js +421 -1
- package/dist-standalone/cjs/invite.js +328 -1
- package/dist-standalone/cjs/key-agreement.js +335 -1
- package/dist-standalone/cjs/lazy-init.js +300 -1
- package/dist-standalone/cjs/logger.js +291 -1
- package/dist-standalone/cjs/mdns-discovery.js +202 -1
- package/dist-standalone/cjs/nonce-store.js +80 -1
- package/dist-standalone/cjs/pairing-manager.js +223 -1
- package/dist-standalone/cjs/plugin-system.js +264 -1
- package/dist-standalone/cjs/plugins/logging.js +168 -1
- package/dist-standalone/cjs/plugins/metrics.js +181 -1
- package/dist-standalone/cjs/plugins/validation.js +302 -1
- package/dist-standalone/cjs/policy.js +320 -1
- package/dist-standalone/cjs/progress-callbacks.js +583 -1
- package/dist-standalone/cjs/redis-nonce-store.js +76 -1
- package/dist-standalone/cjs/registry-middleware.js +50 -1
- package/dist-standalone/cjs/retry-strategies.js +544 -1
- package/dist-standalone/cjs/retry-transport.js +102 -1
- package/dist-standalone/cjs/runtime/browser.js +533 -1
- package/dist-standalone/cjs/runtime/edge.js +526 -1
- package/dist-standalone/cjs/runtime/react-native.js +394 -1
- package/dist-standalone/cjs/security-policy.js +245 -1
- package/dist-standalone/cjs/serialization.js +1040 -1
- package/dist-standalone/cjs/split-channel.js +225 -1
- package/dist-standalone/cjs/subscription-proof.js +230 -1
- package/dist-standalone/cjs/succession.js +148 -1
- package/dist-standalone/cjs/timeouts.js +412 -1
- package/dist-standalone/cjs/trace-context.js +424 -1
- package/dist-standalone/cjs/trace-spans.js +495 -1
- package/dist-standalone/cjs/transport.js +63 -1
- package/dist-standalone/cjs/trust-registry.js +991 -1
- package/dist-standalone/cjs/types/error-response.js +56 -1
- package/dist-standalone/cjs/vault-auth.js +178 -1
- package/dist-standalone/cjs/vault-store-loader.js +194 -1
- package/dist-standalone/cjs/verify.js +25 -1
- package/dist-standalone/cjs/version-info.js +543 -1
- package/dist-standalone/cjs/xfetch.js +340 -1
- package/dist-standalone/cli/init.js +455 -1
- package/dist-standalone/cli/setup.js +514 -1
- package/dist-standalone/cli/types.js +27 -1
- package/dist-standalone/cli/xbind.js +148 -1
- package/dist-standalone/config-validation.js +513 -1
- package/dist-standalone/connect.js +274 -1
- package/dist-standalone/connection-pool.js +500 -1
- package/dist-standalone/correlation-id.js +326 -1
- package/dist-standalone/crypto-utils.js +157 -1
- package/dist-standalone/debug-mode.js +510 -1
- package/dist-standalone/did-document.js +96 -1
- package/dist-standalone/did-privateme.js +121 -1
- package/dist-standalone/did-web.js +196 -1
- package/dist-standalone/discovery.js +458 -1
- package/dist-standalone/dual-mode.js +247 -1
- package/dist-standalone/email-templates.js +309 -1
- package/dist-standalone/email-transport.js +232 -1
- package/dist-standalone/envelope.js +525 -1
- package/dist-standalone/errors.js +896 -1
- package/dist-standalone/event-emitter.js +456 -1
- package/dist-standalone/gateway-state.js +51 -1
- package/dist-standalone/gateway-transport.js +116 -1
- package/dist-standalone/graceful-degradation.js +396 -1
- package/dist-standalone/guardrails.js +216 -1
- package/dist-standalone/health-check.js +332 -1
- package/dist-standalone/http-compat.js +267 -1
- package/dist-standalone/http-status-map.js +561 -1
- package/dist-standalone/identity.js +619 -1
- package/dist-standalone/index.js +78 -1
- package/dist-standalone/invitation.js +415 -1
- package/dist-standalone/invite.js +324 -1
- package/dist-standalone/key-agreement.js +325 -1
- package/dist-standalone/lazy-init.js +295 -1
- package/dist-standalone/logger.js +285 -1
- package/dist-standalone/mdns-discovery.js +195 -1
- package/dist-standalone/nonce-store.js +76 -1
- package/dist-standalone/pairing-manager.js +219 -1
- package/dist-standalone/plugin-system.js +257 -1
- package/dist-standalone/plugins/logging.js +163 -1
- package/dist-standalone/plugins/metrics.js +176 -1
- package/dist-standalone/plugins/validation.js +297 -1
- package/dist-standalone/policy.js +315 -1
- package/dist-standalone/progress-callbacks.js +576 -1
- package/dist-standalone/redis-nonce-store.js +72 -1
- package/dist-standalone/registry-middleware.js +47 -1
- package/dist-standalone/retry-strategies.js +534 -1
- package/dist-standalone/retry-transport.js +98 -1
- package/dist-standalone/runtime/browser.js +516 -1
- package/dist-standalone/runtime/edge.js +511 -1
- package/dist-standalone/runtime/react-native.js +383 -1
- package/dist-standalone/security-policy.js +239 -1
- package/dist-standalone/serialization.js +1031 -1
- package/dist-standalone/split-channel.js +219 -1
- package/dist-standalone/subscription-proof.js +224 -1
- package/dist-standalone/succession.js +142 -1
- package/dist-standalone/timeouts.js +398 -1
- package/dist-standalone/trace-context.js +414 -1
- package/dist-standalone/trace-spans.js +488 -1
- package/dist-standalone/transport.js +59 -1
- package/dist-standalone/trust-registry.js +950 -1
- package/dist-standalone/types/error-response.js +52 -1
- package/dist-standalone/vault-auth.js +174 -1
- package/dist-standalone/vault-store-loader.js +187 -1
- package/dist-standalone/verify.js +16 -1
- package/dist-standalone/version-info.js +530 -1
- package/dist-standalone/xfetch.js +335 -1
- package/package.json +4 -13
- package/share1.dat +0 -0
- package/dist-standalone/_deps/mldsa-wasm/LICENSE +0 -24
- package/dist-standalone/_deps/mldsa-wasm/package.json +0 -46
- package/dist-standalone/_deps/shared/cjs/package.json +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/package.json +0 -1
- package/dist-standalone/_deps/xchange/cjs/package.json +0 -1
- package/dist-standalone/_deps/xregistry/cjs/package.json +0 -1
- package/dist-standalone/cjs/package.json +0 -3
- package/dist-standalone/package.json +0 -10
|
@@ -1 +1,264 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module plugin-system
|
|
4
|
+
* Extensible plugin and middleware architecture for xBind
|
|
5
|
+
*
|
|
6
|
+
* Provides hooks for message processing, encryption, decryption, and custom logic.
|
|
7
|
+
* Supports both synchronous and asynchronous plugin execution.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.PluginBuilder = exports.MiddlewareChain = void 0;
|
|
11
|
+
exports.createPluginContext = createPluginContext;
|
|
12
|
+
exports.createPlugin = createPlugin;
|
|
13
|
+
const shared_1 = require("../_deps/shared/index.js");
|
|
14
|
+
/**
|
|
15
|
+
* Middleware chain executor.
|
|
16
|
+
* Runs plugins in priority order and handles errors.
|
|
17
|
+
*/
|
|
18
|
+
class MiddlewareChain {
|
|
19
|
+
plugins = [];
|
|
20
|
+
initialized = false;
|
|
21
|
+
constructor(plugins = []) {
|
|
22
|
+
this.plugins = [...plugins].sort((a, b) => (a.priority ?? 100) - (b.priority ?? 100));
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Register a plugin.
|
|
26
|
+
* Plugins are automatically sorted by priority after registration.
|
|
27
|
+
*/
|
|
28
|
+
register(plugin) {
|
|
29
|
+
if (this.plugins.some((p) => p.name === plugin.name)) {
|
|
30
|
+
return (0, shared_1.err)(`PLUGIN_ALREADY_REGISTERED:${plugin.name}`);
|
|
31
|
+
}
|
|
32
|
+
this.plugins.push(plugin);
|
|
33
|
+
this.plugins.sort((a, b) => (a.priority ?? 100) - (b.priority ?? 100));
|
|
34
|
+
return (0, shared_1.ok)(undefined);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Unregister a plugin by name.
|
|
38
|
+
*/
|
|
39
|
+
unregister(name) {
|
|
40
|
+
const index = this.plugins.findIndex((p) => p.name === name);
|
|
41
|
+
if (index === -1) {
|
|
42
|
+
return (0, shared_1.err)(`PLUGIN_NOT_FOUND:${name}`);
|
|
43
|
+
}
|
|
44
|
+
this.plugins.splice(index, 1);
|
|
45
|
+
return (0, shared_1.ok)(undefined);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get all registered plugins.
|
|
49
|
+
*/
|
|
50
|
+
getPlugins() {
|
|
51
|
+
return [...this.plugins];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Initialize all plugins.
|
|
55
|
+
* Must be called before executing hooks.
|
|
56
|
+
*/
|
|
57
|
+
async initialize() {
|
|
58
|
+
if (this.initialized) {
|
|
59
|
+
return (0, shared_1.ok)(undefined);
|
|
60
|
+
}
|
|
61
|
+
for (const plugin of this.plugins) {
|
|
62
|
+
if (plugin.onInit) {
|
|
63
|
+
const result = await plugin.onInit();
|
|
64
|
+
if (result.ok === false) {
|
|
65
|
+
return (0, shared_1.err)(`PLUGIN_INIT_FAILED:${plugin.name}:${result.error}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
this.initialized = true;
|
|
70
|
+
return (0, shared_1.ok)(undefined);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Destroy all plugins and cleanup resources.
|
|
74
|
+
*/
|
|
75
|
+
async destroy() {
|
|
76
|
+
const errors = [];
|
|
77
|
+
for (const plugin of this.plugins) {
|
|
78
|
+
if (plugin.onDestroy) {
|
|
79
|
+
const result = await plugin.onDestroy();
|
|
80
|
+
if (result.ok === false) {
|
|
81
|
+
errors.push(`${plugin.name}:${result.error}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
this.initialized = false;
|
|
86
|
+
if (errors.length > 0) {
|
|
87
|
+
return (0, shared_1.err)(`PLUGIN_DESTROY_FAILED:${errors.join(',')}`);
|
|
88
|
+
}
|
|
89
|
+
return (0, shared_1.ok)(undefined);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Execute onSend hooks.
|
|
93
|
+
*/
|
|
94
|
+
async executeSend(payload, context) {
|
|
95
|
+
if (!this.initialized) {
|
|
96
|
+
return (0, shared_1.err)('MIDDLEWARE_NOT_INITIALIZED');
|
|
97
|
+
}
|
|
98
|
+
let currentPayload = payload;
|
|
99
|
+
for (const plugin of this.plugins) {
|
|
100
|
+
if (plugin.onSend) {
|
|
101
|
+
const result = await plugin.onSend(currentPayload, context);
|
|
102
|
+
if (result.ok === false) {
|
|
103
|
+
return (0, shared_1.err)(`PLUGIN_HOOK_FAILED:${plugin.name}:${result.error}`);
|
|
104
|
+
}
|
|
105
|
+
const hookResult = result.value;
|
|
106
|
+
if (hookResult.abort) {
|
|
107
|
+
return (0, shared_1.err)(`PLUGIN_ABORTED:${plugin.name}:${hookResult.reason ?? 'no reason'}`);
|
|
108
|
+
}
|
|
109
|
+
currentPayload = hookResult.payload;
|
|
110
|
+
if (hookResult.metadata) {
|
|
111
|
+
Object.assign(context.metadata, hookResult.metadata);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return (0, shared_1.ok)(currentPayload);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Execute onReceive hooks.
|
|
119
|
+
*/
|
|
120
|
+
async executeReceive(envelope, context) {
|
|
121
|
+
if (!this.initialized) {
|
|
122
|
+
return (0, shared_1.err)('MIDDLEWARE_NOT_INITIALIZED');
|
|
123
|
+
}
|
|
124
|
+
let currentEnvelope = envelope;
|
|
125
|
+
for (const plugin of this.plugins) {
|
|
126
|
+
if (plugin.onReceive) {
|
|
127
|
+
const result = await plugin.onReceive(currentEnvelope, context);
|
|
128
|
+
if (result.ok === false) {
|
|
129
|
+
return (0, shared_1.err)(`PLUGIN_HOOK_FAILED:${plugin.name}:${result.error}`);
|
|
130
|
+
}
|
|
131
|
+
const hookResult = result.value;
|
|
132
|
+
if (hookResult.abort) {
|
|
133
|
+
return (0, shared_1.err)(`PLUGIN_ABORTED:${plugin.name}:${hookResult.reason ?? 'no reason'}`);
|
|
134
|
+
}
|
|
135
|
+
currentEnvelope = hookResult.payload;
|
|
136
|
+
if (hookResult.metadata) {
|
|
137
|
+
Object.assign(context.metadata, hookResult.metadata);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return (0, shared_1.ok)(currentEnvelope);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Execute onEncrypt hooks.
|
|
145
|
+
*/
|
|
146
|
+
async executeEncrypt(plaintext, context) {
|
|
147
|
+
if (!this.initialized) {
|
|
148
|
+
return (0, shared_1.err)('MIDDLEWARE_NOT_INITIALIZED');
|
|
149
|
+
}
|
|
150
|
+
let currentPlaintext = plaintext;
|
|
151
|
+
for (const plugin of this.plugins) {
|
|
152
|
+
if (plugin.onEncrypt) {
|
|
153
|
+
const result = await plugin.onEncrypt(currentPlaintext, context);
|
|
154
|
+
if (result.ok === false) {
|
|
155
|
+
return (0, shared_1.err)(`PLUGIN_HOOK_FAILED:${plugin.name}:${result.error}`);
|
|
156
|
+
}
|
|
157
|
+
const hookResult = result.value;
|
|
158
|
+
if (hookResult.abort) {
|
|
159
|
+
return (0, shared_1.err)(`PLUGIN_ABORTED:${plugin.name}:${hookResult.reason ?? 'no reason'}`);
|
|
160
|
+
}
|
|
161
|
+
currentPlaintext = hookResult.payload;
|
|
162
|
+
if (hookResult.metadata) {
|
|
163
|
+
Object.assign(context.metadata, hookResult.metadata);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return (0, shared_1.ok)(currentPlaintext);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Execute onDecrypt hooks.
|
|
171
|
+
*/
|
|
172
|
+
async executeDecrypt(plaintext, context) {
|
|
173
|
+
if (!this.initialized) {
|
|
174
|
+
return (0, shared_1.err)('MIDDLEWARE_NOT_INITIALIZED');
|
|
175
|
+
}
|
|
176
|
+
let currentPlaintext = plaintext;
|
|
177
|
+
for (const plugin of this.plugins) {
|
|
178
|
+
if (plugin.onDecrypt) {
|
|
179
|
+
const result = await plugin.onDecrypt(currentPlaintext, context);
|
|
180
|
+
if (result.ok === false) {
|
|
181
|
+
return (0, shared_1.err)(`PLUGIN_HOOK_FAILED:${plugin.name}:${result.error}`);
|
|
182
|
+
}
|
|
183
|
+
const hookResult = result.value;
|
|
184
|
+
if (hookResult.abort) {
|
|
185
|
+
return (0, shared_1.err)(`PLUGIN_ABORTED:${plugin.name}:${hookResult.reason ?? 'no reason'}`);
|
|
186
|
+
}
|
|
187
|
+
currentPlaintext = hookResult.payload;
|
|
188
|
+
if (hookResult.metadata) {
|
|
189
|
+
Object.assign(context.metadata, hookResult.metadata);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return (0, shared_1.ok)(currentPlaintext);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
exports.MiddlewareChain = MiddlewareChain;
|
|
197
|
+
/**
|
|
198
|
+
* Create a plugin context.
|
|
199
|
+
*/
|
|
200
|
+
function createPluginContext(agent, options = {}) {
|
|
201
|
+
return {
|
|
202
|
+
agent,
|
|
203
|
+
recipient: options.recipient,
|
|
204
|
+
scope: options.scope,
|
|
205
|
+
timestamp: options.timestamp ?? Date.now(),
|
|
206
|
+
state: options.state ?? new Map(),
|
|
207
|
+
metadata: options.metadata ?? {},
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Plugin builder for creating plugins with a fluent API.
|
|
212
|
+
*/
|
|
213
|
+
class PluginBuilder {
|
|
214
|
+
plugin = {};
|
|
215
|
+
constructor(name, version) {
|
|
216
|
+
this.plugin.name = name;
|
|
217
|
+
this.plugin.version = version;
|
|
218
|
+
}
|
|
219
|
+
description(desc) {
|
|
220
|
+
this.plugin.description = desc;
|
|
221
|
+
return this;
|
|
222
|
+
}
|
|
223
|
+
priority(p) {
|
|
224
|
+
this.plugin.priority = p;
|
|
225
|
+
return this;
|
|
226
|
+
}
|
|
227
|
+
onSend(hook) {
|
|
228
|
+
this.plugin.onSend = hook;
|
|
229
|
+
return this;
|
|
230
|
+
}
|
|
231
|
+
onReceive(hook) {
|
|
232
|
+
this.plugin.onReceive = hook;
|
|
233
|
+
return this;
|
|
234
|
+
}
|
|
235
|
+
onEncrypt(hook) {
|
|
236
|
+
this.plugin.onEncrypt = hook;
|
|
237
|
+
return this;
|
|
238
|
+
}
|
|
239
|
+
onDecrypt(hook) {
|
|
240
|
+
this.plugin.onDecrypt = hook;
|
|
241
|
+
return this;
|
|
242
|
+
}
|
|
243
|
+
onInit(hook) {
|
|
244
|
+
this.plugin.onInit = hook;
|
|
245
|
+
return this;
|
|
246
|
+
}
|
|
247
|
+
onDestroy(hook) {
|
|
248
|
+
this.plugin.onDestroy = hook;
|
|
249
|
+
return this;
|
|
250
|
+
}
|
|
251
|
+
build() {
|
|
252
|
+
if (!this.plugin.name || !this.plugin.version) {
|
|
253
|
+
throw new Error('Plugin name and version are required');
|
|
254
|
+
}
|
|
255
|
+
return this.plugin;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
exports.PluginBuilder = PluginBuilder;
|
|
259
|
+
/**
|
|
260
|
+
* Create a plugin builder.
|
|
261
|
+
*/
|
|
262
|
+
function createPlugin(name, version) {
|
|
263
|
+
return new PluginBuilder(name, version);
|
|
264
|
+
}
|
|
@@ -1 +1,168 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module plugins/logging
|
|
4
|
+
* Logging plugin for xBind plugin system
|
|
5
|
+
*
|
|
6
|
+
* Captures send, receive, encrypt, and decrypt events for debugging and audit trails.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.LoggingPlugin = exports.LogLevel = void 0;
|
|
10
|
+
exports.createLoggingPlugin = createLoggingPlugin;
|
|
11
|
+
const shared_1 = require("../../_deps/shared/index.js");
|
|
12
|
+
/**
|
|
13
|
+
* Log level enum.
|
|
14
|
+
*/
|
|
15
|
+
var LogLevel;
|
|
16
|
+
(function (LogLevel) {
|
|
17
|
+
LogLevel["DEBUG"] = "debug";
|
|
18
|
+
LogLevel["INFO"] = "info";
|
|
19
|
+
LogLevel["WARN"] = "warn";
|
|
20
|
+
LogLevel["ERROR"] = "error";
|
|
21
|
+
})(LogLevel || (exports.LogLevel = LogLevel = {}));
|
|
22
|
+
/**
|
|
23
|
+
* Logging plugin implementation.
|
|
24
|
+
* Captures all message processing events and outputs structured logs.
|
|
25
|
+
*/
|
|
26
|
+
class LoggingPlugin {
|
|
27
|
+
name = 'logging';
|
|
28
|
+
version = '1.0.0';
|
|
29
|
+
description = 'Captures message processing events for debugging and audit trails';
|
|
30
|
+
priority = 10; // Execute early
|
|
31
|
+
options;
|
|
32
|
+
logs = [];
|
|
33
|
+
constructor(options = {}) {
|
|
34
|
+
this.options = {
|
|
35
|
+
level: options.level ?? LogLevel.INFO,
|
|
36
|
+
includeSize: options.includeSize ?? true,
|
|
37
|
+
includeMetadata: options.includeMetadata ?? false,
|
|
38
|
+
logHandler: options.logHandler ?? ((entry) => console.log(JSON.stringify(entry))),
|
|
39
|
+
filter: options.filter ?? (() => true),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
onInit() {
|
|
43
|
+
this.log({
|
|
44
|
+
timestamp: new Date().toISOString(),
|
|
45
|
+
level: LogLevel.INFO,
|
|
46
|
+
event: 'send',
|
|
47
|
+
agent: 'system',
|
|
48
|
+
metadata: { message: 'Logging plugin initialized' },
|
|
49
|
+
});
|
|
50
|
+
return (0, shared_1.ok)(undefined);
|
|
51
|
+
}
|
|
52
|
+
onDestroy() {
|
|
53
|
+
this.log({
|
|
54
|
+
timestamp: new Date().toISOString(),
|
|
55
|
+
level: LogLevel.INFO,
|
|
56
|
+
event: 'send',
|
|
57
|
+
agent: 'system',
|
|
58
|
+
metadata: { message: 'Logging plugin destroyed', totalLogs: this.logs.length },
|
|
59
|
+
});
|
|
60
|
+
this.logs = [];
|
|
61
|
+
return (0, shared_1.ok)(undefined);
|
|
62
|
+
}
|
|
63
|
+
onSend(payload, context) {
|
|
64
|
+
const size = this.options.includeSize ? this.estimateSize(payload) : undefined;
|
|
65
|
+
this.log({
|
|
66
|
+
timestamp: new Date().toISOString(),
|
|
67
|
+
level: LogLevel.INFO,
|
|
68
|
+
event: 'send',
|
|
69
|
+
agent: context.agent.did,
|
|
70
|
+
recipient: context.recipient,
|
|
71
|
+
scope: context.scope,
|
|
72
|
+
payloadSize: size,
|
|
73
|
+
metadata: this.options.includeMetadata ? context.metadata : undefined,
|
|
74
|
+
});
|
|
75
|
+
return (0, shared_1.ok)({ payload });
|
|
76
|
+
}
|
|
77
|
+
onReceive(envelope, context) {
|
|
78
|
+
const size = this.options.includeSize ? this.estimateSize(envelope) : undefined;
|
|
79
|
+
this.log({
|
|
80
|
+
timestamp: new Date().toISOString(),
|
|
81
|
+
level: LogLevel.INFO,
|
|
82
|
+
event: 'receive',
|
|
83
|
+
agent: context.agent.did,
|
|
84
|
+
recipient: envelope.sender,
|
|
85
|
+
scope: context.scope,
|
|
86
|
+
payloadSize: size,
|
|
87
|
+
metadata: this.options.includeMetadata ? context.metadata : undefined,
|
|
88
|
+
});
|
|
89
|
+
return (0, shared_1.ok)({ payload: envelope });
|
|
90
|
+
}
|
|
91
|
+
onEncrypt(plaintext, context) {
|
|
92
|
+
this.log({
|
|
93
|
+
timestamp: new Date().toISOString(),
|
|
94
|
+
level: LogLevel.DEBUG,
|
|
95
|
+
event: 'encrypt',
|
|
96
|
+
agent: context.agent.did,
|
|
97
|
+
recipient: context.recipient,
|
|
98
|
+
scope: context.scope,
|
|
99
|
+
payloadSize: this.options.includeSize ? plaintext.length : undefined,
|
|
100
|
+
metadata: this.options.includeMetadata ? context.metadata : undefined,
|
|
101
|
+
});
|
|
102
|
+
return (0, shared_1.ok)({ payload: plaintext });
|
|
103
|
+
}
|
|
104
|
+
onDecrypt(plaintext, context) {
|
|
105
|
+
this.log({
|
|
106
|
+
timestamp: new Date().toISOString(),
|
|
107
|
+
level: LogLevel.DEBUG,
|
|
108
|
+
event: 'decrypt',
|
|
109
|
+
agent: context.agent.did,
|
|
110
|
+
scope: context.scope,
|
|
111
|
+
payloadSize: this.options.includeSize ? plaintext.length : undefined,
|
|
112
|
+
metadata: this.options.includeMetadata ? context.metadata : undefined,
|
|
113
|
+
});
|
|
114
|
+
return (0, shared_1.ok)({ payload: plaintext });
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Get all captured logs.
|
|
118
|
+
*/
|
|
119
|
+
getLogs() {
|
|
120
|
+
return [...this.logs];
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Clear all logs.
|
|
124
|
+
*/
|
|
125
|
+
clearLogs() {
|
|
126
|
+
this.logs = [];
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Get logs filtered by criteria.
|
|
130
|
+
*/
|
|
131
|
+
getFilteredLogs(filter) {
|
|
132
|
+
return this.logs.filter(filter);
|
|
133
|
+
}
|
|
134
|
+
log(entry) {
|
|
135
|
+
if (!this.shouldLog(entry.level)) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (!this.options.filter(entry)) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
this.logs.push(entry);
|
|
142
|
+
this.options.logHandler(entry);
|
|
143
|
+
}
|
|
144
|
+
shouldLog(level) {
|
|
145
|
+
const levels = [LogLevel.DEBUG, LogLevel.INFO, LogLevel.WARN, LogLevel.ERROR];
|
|
146
|
+
const thresholdIndex = levels.indexOf(this.options.level);
|
|
147
|
+
const currentIndex = levels.indexOf(level);
|
|
148
|
+
return currentIndex >= thresholdIndex;
|
|
149
|
+
}
|
|
150
|
+
estimateSize(value) {
|
|
151
|
+
if (value instanceof Uint8Array) {
|
|
152
|
+
return value.length;
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
return JSON.stringify(value).length;
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
return 0;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
exports.LoggingPlugin = LoggingPlugin;
|
|
163
|
+
/**
|
|
164
|
+
* Create a logging plugin with options.
|
|
165
|
+
*/
|
|
166
|
+
function createLoggingPlugin(options) {
|
|
167
|
+
return new LoggingPlugin(options);
|
|
168
|
+
}
|
|
@@ -1 +1,181 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module plugins/metrics
|
|
4
|
+
* Metrics plugin for xBind plugin system
|
|
5
|
+
*
|
|
6
|
+
* Tracks performance metrics, message counts, and error rates.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.MetricsPlugin = void 0;
|
|
10
|
+
exports.createMetricsPlugin = createMetricsPlugin;
|
|
11
|
+
const shared_1 = require("../../_deps/shared/index.js");
|
|
12
|
+
/**
|
|
13
|
+
* Metrics plugin implementation.
|
|
14
|
+
* Tracks performance and usage statistics for all operations.
|
|
15
|
+
*/
|
|
16
|
+
class MetricsPlugin {
|
|
17
|
+
name = 'metrics';
|
|
18
|
+
version = '1.0.0';
|
|
19
|
+
description = 'Tracks performance metrics, message counts, and error rates';
|
|
20
|
+
priority = 20; // Execute after logging
|
|
21
|
+
options;
|
|
22
|
+
metrics = [];
|
|
23
|
+
startTime = Date.now();
|
|
24
|
+
exportTimer;
|
|
25
|
+
constructor(options = {}) {
|
|
26
|
+
this.options = {
|
|
27
|
+
highResolution: options.highResolution ?? true,
|
|
28
|
+
maxMetrics: options.maxMetrics ?? 10000,
|
|
29
|
+
onExport: options.onExport ?? (() => { }),
|
|
30
|
+
exportInterval: options.exportInterval ?? 60000,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
onInit() {
|
|
34
|
+
this.startTime = Date.now();
|
|
35
|
+
if (this.options.exportInterval > 0) {
|
|
36
|
+
this.exportTimer = setInterval(() => {
|
|
37
|
+
this.export();
|
|
38
|
+
}, this.options.exportInterval);
|
|
39
|
+
}
|
|
40
|
+
return (0, shared_1.ok)(undefined);
|
|
41
|
+
}
|
|
42
|
+
onDestroy() {
|
|
43
|
+
if (this.exportTimer) {
|
|
44
|
+
clearInterval(this.exportTimer);
|
|
45
|
+
this.exportTimer = undefined;
|
|
46
|
+
}
|
|
47
|
+
this.export();
|
|
48
|
+
this.metrics = [];
|
|
49
|
+
return (0, shared_1.ok)(undefined);
|
|
50
|
+
}
|
|
51
|
+
onSend(payload, context) {
|
|
52
|
+
const start = this.now();
|
|
53
|
+
// Simulate processing
|
|
54
|
+
const end = this.now();
|
|
55
|
+
this.record({
|
|
56
|
+
timestamp: Date.now(),
|
|
57
|
+
event: 'send',
|
|
58
|
+
duration: end - start,
|
|
59
|
+
success: true,
|
|
60
|
+
});
|
|
61
|
+
return (0, shared_1.ok)({ payload });
|
|
62
|
+
}
|
|
63
|
+
onReceive(envelope, context) {
|
|
64
|
+
const start = this.now();
|
|
65
|
+
// Simulate processing
|
|
66
|
+
const end = this.now();
|
|
67
|
+
this.record({
|
|
68
|
+
timestamp: Date.now(),
|
|
69
|
+
event: 'receive',
|
|
70
|
+
duration: end - start,
|
|
71
|
+
success: true,
|
|
72
|
+
});
|
|
73
|
+
return (0, shared_1.ok)({ payload: envelope });
|
|
74
|
+
}
|
|
75
|
+
onEncrypt(plaintext, context) {
|
|
76
|
+
const start = this.now();
|
|
77
|
+
// Simulate processing
|
|
78
|
+
const end = this.now();
|
|
79
|
+
this.record({
|
|
80
|
+
timestamp: Date.now(),
|
|
81
|
+
event: 'encrypt',
|
|
82
|
+
duration: end - start,
|
|
83
|
+
success: true,
|
|
84
|
+
});
|
|
85
|
+
return (0, shared_1.ok)({ payload: plaintext });
|
|
86
|
+
}
|
|
87
|
+
onDecrypt(plaintext, context) {
|
|
88
|
+
const start = this.now();
|
|
89
|
+
// Simulate processing
|
|
90
|
+
const end = this.now();
|
|
91
|
+
this.record({
|
|
92
|
+
timestamp: Date.now(),
|
|
93
|
+
event: 'decrypt',
|
|
94
|
+
duration: end - start,
|
|
95
|
+
success: true,
|
|
96
|
+
});
|
|
97
|
+
return (0, shared_1.ok)({ payload: plaintext });
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Get all captured metrics.
|
|
101
|
+
*/
|
|
102
|
+
getMetrics() {
|
|
103
|
+
return [...this.metrics];
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get aggregated metrics summary.
|
|
107
|
+
*/
|
|
108
|
+
getAggregatedMetrics() {
|
|
109
|
+
const sends = this.metrics.filter((m) => m.event === 'send');
|
|
110
|
+
const receives = this.metrics.filter((m) => m.event === 'receive');
|
|
111
|
+
const encrypts = this.metrics.filter((m) => m.event === 'encrypt');
|
|
112
|
+
const decrypts = this.metrics.filter((m) => m.event === 'decrypt');
|
|
113
|
+
const errors = this.metrics.filter((m) => !m.success);
|
|
114
|
+
const avgDuration = (items) => {
|
|
115
|
+
if (items.length === 0)
|
|
116
|
+
return 0;
|
|
117
|
+
return items.reduce((sum, m) => sum + m.duration, 0) / items.length;
|
|
118
|
+
};
|
|
119
|
+
const total = this.metrics.length;
|
|
120
|
+
return {
|
|
121
|
+
totalSends: sends.length,
|
|
122
|
+
totalReceives: receives.length,
|
|
123
|
+
totalEncrypts: encrypts.length,
|
|
124
|
+
totalDecrypts: decrypts.length,
|
|
125
|
+
avgSendDuration: avgDuration(sends),
|
|
126
|
+
avgReceiveDuration: avgDuration(receives),
|
|
127
|
+
avgEncryptDuration: avgDuration(encrypts),
|
|
128
|
+
avgDecryptDuration: avgDuration(decrypts),
|
|
129
|
+
totalErrors: errors.length,
|
|
130
|
+
errorRate: total > 0 ? errors.length / total : 0,
|
|
131
|
+
uptime: Date.now() - this.startTime,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Clear all metrics.
|
|
136
|
+
*/
|
|
137
|
+
clearMetrics() {
|
|
138
|
+
this.metrics = [];
|
|
139
|
+
this.startTime = Date.now();
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Export metrics using the configured callback.
|
|
143
|
+
*/
|
|
144
|
+
export() {
|
|
145
|
+
if (this.metrics.length > 0) {
|
|
146
|
+
this.options.onExport([...this.metrics]);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Get metrics for a specific time range.
|
|
151
|
+
*/
|
|
152
|
+
getMetricsInRange(startTime, endTime) {
|
|
153
|
+
return this.metrics.filter((m) => m.timestamp >= startTime && m.timestamp <= endTime);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Get metrics for a specific event type.
|
|
157
|
+
*/
|
|
158
|
+
getMetricsByEvent(event) {
|
|
159
|
+
return this.metrics.filter((m) => m.event === event);
|
|
160
|
+
}
|
|
161
|
+
record(entry) {
|
|
162
|
+
this.metrics.push(entry);
|
|
163
|
+
// Enforce max metrics limit
|
|
164
|
+
if (this.metrics.length > this.options.maxMetrics) {
|
|
165
|
+
this.metrics.shift(); // Remove oldest
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
now() {
|
|
169
|
+
if (this.options.highResolution && typeof performance !== 'undefined') {
|
|
170
|
+
return performance.now();
|
|
171
|
+
}
|
|
172
|
+
return Date.now();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
exports.MetricsPlugin = MetricsPlugin;
|
|
176
|
+
/**
|
|
177
|
+
* Create a metrics plugin with options.
|
|
178
|
+
*/
|
|
179
|
+
function createMetricsPlugin(options) {
|
|
180
|
+
return new MetricsPlugin(options);
|
|
181
|
+
}
|