@private.me/xbind 3.0.2 → 3.0.3

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 (221) hide show
  1. package/README.md +2366 -204
  2. package/README.md.backup +2121 -0
  3. package/dist-standalone/_deps/mldsa-wasm/dist/mldsa.js +1 -1920
  4. package/dist-standalone/_deps/shared/cjs/errors.js +1 -729
  5. package/dist-standalone/_deps/shared/cjs/index.js +1 -463
  6. package/dist-standalone/_deps/shared/cjs/types.js +1 -315
  7. package/dist-standalone/_deps/shared/errors.js +1 -244
  8. package/dist-standalone/_deps/shared/index.js +1 -72
  9. package/dist-standalone/_deps/shared/types.js +1 -86
  10. package/dist-standalone/_deps/ux-helpers/cjs/errors.js +1 -1
  11. package/dist-standalone/_deps/ux-helpers/cjs/index.js +1 -1
  12. package/dist-standalone/_deps/ux-helpers/cjs/pagination.js +1 -1
  13. package/dist-standalone/_deps/ux-helpers/cjs/progress.js +1 -1
  14. package/dist-standalone/_deps/ux-helpers/cjs/search.js +1 -1
  15. package/dist-standalone/_deps/ux-helpers/cjs/types.js +1 -1
  16. package/dist-standalone/_deps/ux-helpers/errors.js +1 -1
  17. package/dist-standalone/_deps/ux-helpers/index.js +1 -1
  18. package/dist-standalone/_deps/ux-helpers/pagination.js +1 -1
  19. package/dist-standalone/_deps/ux-helpers/progress.js +1 -1
  20. package/dist-standalone/_deps/ux-helpers/search.js +1 -1
  21. package/dist-standalone/_deps/xchange/auto-accept.js +1 -1
  22. package/dist-standalone/_deps/xchange/cjs/auto-accept.js +1 -1
  23. package/dist-standalone/_deps/xchange/cjs/errors.js +1 -1
  24. package/dist-standalone/_deps/xchange/cjs/index.js +1 -1
  25. package/dist-standalone/_deps/xchange/cjs/invite-client.js +1 -1
  26. package/dist-standalone/_deps/xchange/cjs/lazy-init.js +1 -1
  27. package/dist-standalone/_deps/xchange/cjs/trust-integration.js +1 -1
  28. package/dist-standalone/_deps/xchange/cjs/xchange.js +1 -1
  29. package/dist-standalone/_deps/xchange/errors.js +1 -1
  30. package/dist-standalone/_deps/xchange/index.js +1 -1
  31. package/dist-standalone/_deps/xchange/invite-client.js +1 -1
  32. package/dist-standalone/_deps/xchange/lazy-init.js +1 -1
  33. package/dist-standalone/_deps/xchange/trust-integration.js +1 -1
  34. package/dist-standalone/_deps/xchange/xchange.js +1 -1
  35. package/dist-standalone/_deps/xregistry/cjs/discovery.js +1 -1
  36. package/dist-standalone/_deps/xregistry/cjs/errors.js +1 -1
  37. package/dist-standalone/_deps/xregistry/cjs/index.js +1 -1
  38. package/dist-standalone/_deps/xregistry/cjs/registry.js +1 -1
  39. package/dist-standalone/_deps/xregistry/cjs/schema.js +1 -1
  40. package/dist-standalone/_deps/xregistry/cjs/types.js +1 -1
  41. package/dist-standalone/_deps/xregistry/discovery.js +1 -1
  42. package/dist-standalone/_deps/xregistry/errors.js +1 -1
  43. package/dist-standalone/_deps/xregistry/index.js +1 -1
  44. package/dist-standalone/_deps/xregistry/registry.js +1 -1
  45. package/dist-standalone/_deps/xregistry/schema.js +1 -1
  46. package/dist-standalone/_deps/xregistry/types.js +1 -1
  47. package/dist-standalone/agent-call.d.ts +2 -2
  48. package/dist-standalone/agent-call.js +1 -659
  49. package/dist-standalone/agent-sdk.js +1 -328
  50. package/dist-standalone/agent.d.ts +2 -0
  51. package/dist-standalone/agent.js +1 -1800
  52. package/dist-standalone/approval.js +1 -193
  53. package/dist-standalone/async-iterators.d.ts +3 -3
  54. package/dist-standalone/async-iterators.js +1 -382
  55. package/dist-standalone/auth.js +1 -219
  56. package/dist-standalone/auto-accept.js +1 -229
  57. package/dist-standalone/backup-config.js +1 -201
  58. package/dist-standalone/backup.js +1 -326
  59. package/dist-standalone/batch-operations.js +1 -388
  60. package/dist-standalone/cancellation.js +1 -477
  61. package/dist-standalone/checkpoint.js +1 -186
  62. package/dist-standalone/circuit-breaker.js +1 -468
  63. package/dist-standalone/cjs/agent-call.js +1 -701
  64. package/dist-standalone/cjs/agent-sdk.js +1 -332
  65. package/dist-standalone/cjs/agent.js +1 -1837
  66. package/dist-standalone/cjs/approval.js +1 -199
  67. package/dist-standalone/cjs/async-iterators.js +1 -392
  68. package/dist-standalone/cjs/auth.js +1 -225
  69. package/dist-standalone/cjs/auto-accept.js +1 -233
  70. package/dist-standalone/cjs/backup-config.js +1 -207
  71. package/dist-standalone/cjs/backup.js +1 -330
  72. package/dist-standalone/cjs/batch-operations.js +1 -397
  73. package/dist-standalone/cjs/cancellation.js +1 -490
  74. package/dist-standalone/cjs/checkpoint.js +1 -193
  75. package/dist-standalone/cjs/circuit-breaker.js +1 -476
  76. package/dist-standalone/cjs/cli/init.js +1 -492
  77. package/dist-standalone/cjs/config-validation.js +1 -522
  78. package/dist-standalone/cjs/connect.js +1 -312
  79. package/dist-standalone/cjs/connection-pool.js +1 -506
  80. package/dist-standalone/cjs/correlation-id.js +1 -339
  81. package/dist-standalone/cjs/crypto-utils.js +1 -176
  82. package/dist-standalone/cjs/debug-mode.js +1 -534
  83. package/dist-standalone/cjs/did-document.js +1 -101
  84. package/dist-standalone/cjs/did-privateme.js +1 -130
  85. package/dist-standalone/cjs/did-web.js +1 -201
  86. package/dist-standalone/cjs/discovery.js +1 -462
  87. package/dist-standalone/cjs/dual-mode.js +1 -251
  88. package/dist-standalone/cjs/email-templates.js +1 -313
  89. package/dist-standalone/cjs/email-transport.js +1 -239
  90. package/dist-standalone/cjs/envelope.js +1 -538
  91. package/dist-standalone/cjs/errors.js +1 -913
  92. package/dist-standalone/cjs/event-emitter.js +1 -461
  93. package/dist-standalone/cjs/gateway-state.js +1 -55
  94. package/dist-standalone/cjs/gateway-transport.js +1 -120
  95. package/dist-standalone/cjs/graceful-degradation.js +1 -403
  96. package/dist-standalone/cjs/guardrails.js +1 -223
  97. package/dist-standalone/cjs/health-check.js +1 -336
  98. package/dist-standalone/cjs/http-compat.js +1 -272
  99. package/dist-standalone/cjs/http-status-map.js +1 -571
  100. package/dist-standalone/cjs/identity.js +1 -645
  101. package/dist-standalone/cjs/index.js +1 -406
  102. package/dist-standalone/cjs/invitation.js +1 -421
  103. package/dist-standalone/cjs/invite.js +1 -328
  104. package/dist-standalone/cjs/key-agreement.js +1 -335
  105. package/dist-standalone/cjs/lazy-init.js +1 -300
  106. package/dist-standalone/cjs/logger.js +1 -291
  107. package/dist-standalone/cjs/loopback-transport.js +1 -0
  108. package/dist-standalone/cjs/mdns-discovery.js +1 -202
  109. package/dist-standalone/cjs/nonce-store.js +1 -80
  110. package/dist-standalone/cjs/pairing-manager.js +1 -223
  111. package/dist-standalone/cjs/plugin-system.js +1 -264
  112. package/dist-standalone/cjs/plugins/logging.js +1 -168
  113. package/dist-standalone/cjs/plugins/metrics.js +1 -181
  114. package/dist-standalone/cjs/plugins/validation.js +1 -302
  115. package/dist-standalone/cjs/policy.js +1 -320
  116. package/dist-standalone/cjs/progress-callbacks.js +1 -583
  117. package/dist-standalone/cjs/redis-nonce-store.js +1 -76
  118. package/dist-standalone/cjs/registry-middleware.js +1 -50
  119. package/dist-standalone/cjs/retry-strategies.js +1 -544
  120. package/dist-standalone/cjs/retry-transport.js +1 -102
  121. package/dist-standalone/cjs/runtime/browser.js +1 -533
  122. package/dist-standalone/cjs/runtime/edge.js +1 -526
  123. package/dist-standalone/cjs/runtime/react-native.js +1 -394
  124. package/dist-standalone/cjs/security-policy.js +1 -245
  125. package/dist-standalone/cjs/serialization.js +1 -1040
  126. package/dist-standalone/cjs/split-channel.js +1 -225
  127. package/dist-standalone/cjs/subscription-proof.js +1 -230
  128. package/dist-standalone/cjs/succession.js +1 -148
  129. package/dist-standalone/cjs/timeouts.js +1 -412
  130. package/dist-standalone/cjs/trace-context.js +1 -424
  131. package/dist-standalone/cjs/trace-spans.js +1 -495
  132. package/dist-standalone/cjs/transport.js +1 -63
  133. package/dist-standalone/cjs/trust-registry.js +1 -991
  134. package/dist-standalone/cjs/types/error-response.js +1 -56
  135. package/dist-standalone/cjs/vault-auth.js +1 -178
  136. package/dist-standalone/cjs/vault-store-loader.js +1 -194
  137. package/dist-standalone/cjs/verify.js +1 -25
  138. package/dist-standalone/cjs/version-info.js +1 -543
  139. package/dist-standalone/cjs/xfetch.js +1 -340
  140. package/dist-standalone/cli/init.js +1 -455
  141. package/dist-standalone/cli/setup.js +1 -514
  142. package/dist-standalone/cli/types.js +1 -27
  143. package/dist-standalone/cli/xbind.js +1 -148
  144. package/dist-standalone/config-validation.js +1 -513
  145. package/dist-standalone/connect.js +1 -274
  146. package/dist-standalone/connection-pool.js +1 -500
  147. package/dist-standalone/correlation-id.js +1 -326
  148. package/dist-standalone/crypto-utils.d.ts +2 -7
  149. package/dist-standalone/crypto-utils.js +1 -157
  150. package/dist-standalone/debug-mode.js +1 -510
  151. package/dist-standalone/did-document.js +1 -96
  152. package/dist-standalone/did-privateme.js +1 -121
  153. package/dist-standalone/did-web.js +1 -196
  154. package/dist-standalone/discovery.js +1 -458
  155. package/dist-standalone/dual-mode.js +1 -247
  156. package/dist-standalone/email-templates.js +1 -309
  157. package/dist-standalone/email-transport.d.ts +2 -2
  158. package/dist-standalone/email-transport.js +1 -232
  159. package/dist-standalone/envelope.js +1 -525
  160. package/dist-standalone/errors.d.ts +13 -3
  161. package/dist-standalone/errors.js +1 -896
  162. package/dist-standalone/event-emitter.js +1 -456
  163. package/dist-standalone/gateway-state.d.ts +1 -1
  164. package/dist-standalone/gateway-state.js +1 -51
  165. package/dist-standalone/gateway-transport.js +1 -116
  166. package/dist-standalone/graceful-degradation.js +1 -396
  167. package/dist-standalone/guardrails.js +1 -216
  168. package/dist-standalone/health-check.d.ts +5 -1
  169. package/dist-standalone/health-check.js +1 -332
  170. package/dist-standalone/http-compat.d.ts +1 -1
  171. package/dist-standalone/http-compat.js +1 -267
  172. package/dist-standalone/http-status-map.js +1 -561
  173. package/dist-standalone/identity.js +1 -619
  174. package/dist-standalone/index.d.ts +15 -4
  175. package/dist-standalone/index.js +1 -78
  176. package/dist-standalone/invitation.js +1 -415
  177. package/dist-standalone/invite.js +1 -324
  178. package/dist-standalone/key-agreement.js +1 -325
  179. package/dist-standalone/lazy-init.d.ts +11 -6
  180. package/dist-standalone/lazy-init.js +1 -295
  181. package/dist-standalone/logger.js +1 -285
  182. package/dist-standalone/loopback-transport.d.ts +87 -0
  183. package/dist-standalone/loopback-transport.js +1 -0
  184. package/dist-standalone/mdns-discovery.js +1 -195
  185. package/dist-standalone/nonce-store.js +1 -76
  186. package/dist-standalone/pairing-manager.js +1 -219
  187. package/dist-standalone/plugin-system.js +1 -257
  188. package/dist-standalone/plugins/logging.js +1 -163
  189. package/dist-standalone/plugins/metrics.d.ts +4 -4
  190. package/dist-standalone/plugins/metrics.js +1 -176
  191. package/dist-standalone/plugins/validation.js +1 -297
  192. package/dist-standalone/policy.js +1 -315
  193. package/dist-standalone/progress-callbacks.js +1 -576
  194. package/dist-standalone/redis-nonce-store.js +1 -72
  195. package/dist-standalone/registry-middleware.js +1 -47
  196. package/dist-standalone/retry-strategies.js +1 -534
  197. package/dist-standalone/retry-transport.js +1 -98
  198. package/dist-standalone/runtime/browser.js +1 -516
  199. package/dist-standalone/runtime/edge.js +1 -511
  200. package/dist-standalone/runtime/react-native.d.ts +1 -1
  201. package/dist-standalone/runtime/react-native.js +1 -383
  202. package/dist-standalone/security-policy.js +1 -239
  203. package/dist-standalone/serialization.js +1 -1031
  204. package/dist-standalone/split-channel.js +1 -219
  205. package/dist-standalone/subscription-proof.js +1 -224
  206. package/dist-standalone/succession.js +1 -142
  207. package/dist-standalone/timeouts.js +1 -398
  208. package/dist-standalone/trace-context.js +1 -414
  209. package/dist-standalone/trace-spans.js +1 -488
  210. package/dist-standalone/transport.js +1 -59
  211. package/dist-standalone/trust-registry.d.ts +3 -3
  212. package/dist-standalone/trust-registry.js +1 -950
  213. package/dist-standalone/types/error-response.js +1 -52
  214. package/dist-standalone/vault-auth.js +1 -174
  215. package/dist-standalone/vault-store-loader.d.ts +9 -0
  216. package/dist-standalone/vault-store-loader.js +1 -187
  217. package/dist-standalone/verify.js +1 -16
  218. package/dist-standalone/version-info.js +1 -530
  219. package/dist-standalone/xfetch.js +1 -335
  220. package/package.json +1 -1
  221. package/share1.dat +0 -0
@@ -1,264 +1 @@
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
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PluginBuilder=exports.MiddlewareChain=void 0,exports.createPluginContext=createPluginContext,exports.createPlugin=createPlugin;const shared_1=require("../_deps/shared/index.js");class MiddlewareChain{plugins=[];initialized=!1;constructor(e=[]){this.plugins=[...e].sort((e,r)=>(e.priority??100)-(r.priority??100))}register(e){return this.plugins.some(r=>r.name===e.name)?(0,shared_1.err)(`PLUGIN_ALREADY_REGISTERED:${e.name}`):(this.plugins.push(e),this.plugins.sort((e,r)=>(e.priority??100)-(r.priority??100)),(0,shared_1.ok)(void 0))}unregister(e){const r=this.plugins.findIndex(r=>r.name===e);return-1===r?(0,shared_1.err)(`PLUGIN_NOT_FOUND:${e}`):(this.plugins.splice(r,1),(0,shared_1.ok)(void 0))}getPlugins(){return[...this.plugins]}async initialize(){if(this.initialized)return(0,shared_1.ok)(void 0);for(const e of this.plugins)if(e.onInit){const r=await e.onInit();if(!1===r.ok)return(0,shared_1.err)(`PLUGIN_INIT_FAILED:${e.name}:${r.error}`)}return this.initialized=!0,(0,shared_1.ok)(void 0)}async destroy(){const e=[];for(const r of this.plugins)if(r.onDestroy){const t=await r.onDestroy();!1===t.ok&&e.push(`${r.name}:${t.error}`)}return this.initialized=!1,e.length>0?(0,shared_1.err)(`PLUGIN_DESTROY_FAILED:${e.join(",")}`):(0,shared_1.ok)(void 0)}async executeSend(e,r){if(!this.initialized)return(0,shared_1.err)("MIDDLEWARE_NOT_INITIALIZED");let t=e;for(const e of this.plugins)if(e.onSend){const i=await e.onSend(t,r);if(!1===i.ok)return(0,shared_1.err)(`PLUGIN_HOOK_FAILED:${e.name}:${i.error}`);const n=i.value;if(n.abort)return(0,shared_1.err)(`PLUGIN_ABORTED:${e.name}:${n.reason??"no reason"}`);t=n.payload,n.metadata&&Object.assign(r.metadata,n.metadata)}return(0,shared_1.ok)(t)}async executeReceive(e,r){if(!this.initialized)return(0,shared_1.err)("MIDDLEWARE_NOT_INITIALIZED");let t=e;for(const e of this.plugins)if(e.onReceive){const i=await e.onReceive(t,r);if(!1===i.ok)return(0,shared_1.err)(`PLUGIN_HOOK_FAILED:${e.name}:${i.error}`);const n=i.value;if(n.abort)return(0,shared_1.err)(`PLUGIN_ABORTED:${e.name}:${n.reason??"no reason"}`);t=n.payload,n.metadata&&Object.assign(r.metadata,n.metadata)}return(0,shared_1.ok)(t)}async executeEncrypt(e,r){if(!this.initialized)return(0,shared_1.err)("MIDDLEWARE_NOT_INITIALIZED");let t=e;for(const e of this.plugins)if(e.onEncrypt){const i=await e.onEncrypt(t,r);if(!1===i.ok)return(0,shared_1.err)(`PLUGIN_HOOK_FAILED:${e.name}:${i.error}`);const n=i.value;if(n.abort)return(0,shared_1.err)(`PLUGIN_ABORTED:${e.name}:${n.reason??"no reason"}`);t=n.payload,n.metadata&&Object.assign(r.metadata,n.metadata)}return(0,shared_1.ok)(t)}async executeDecrypt(e,r){if(!this.initialized)return(0,shared_1.err)("MIDDLEWARE_NOT_INITIALIZED");let t=e;for(const e of this.plugins)if(e.onDecrypt){const i=await e.onDecrypt(t,r);if(!1===i.ok)return(0,shared_1.err)(`PLUGIN_HOOK_FAILED:${e.name}:${i.error}`);const n=i.value;if(n.abort)return(0,shared_1.err)(`PLUGIN_ABORTED:${e.name}:${n.reason??"no reason"}`);t=n.payload,n.metadata&&Object.assign(r.metadata,n.metadata)}return(0,shared_1.ok)(t)}}function createPluginContext(e,r={}){return{agent:e,recipient:r.recipient,scope:r.scope,timestamp:r.timestamp??Date.now(),state:r.state??new Map,metadata:r.metadata??{}}}exports.MiddlewareChain=MiddlewareChain;class PluginBuilder{plugin={};constructor(e,r){this.plugin.name=e,this.plugin.version=r}description(e){return this.plugin.description=e,this}priority(e){return this.plugin.priority=e,this}onSend(e){return this.plugin.onSend=e,this}onReceive(e){return this.plugin.onReceive=e,this}onEncrypt(e){return this.plugin.onEncrypt=e,this}onDecrypt(e){return this.plugin.onDecrypt=e,this}onInit(e){return this.plugin.onInit=e,this}onDestroy(e){return this.plugin.onDestroy=e,this}build(){if(!this.plugin.name||!this.plugin.version)throw new Error("Plugin name and version are required");return this.plugin}}function createPlugin(e,r){return new PluginBuilder(e,r)}exports.PluginBuilder=PluginBuilder;
@@ -1,168 +1 @@
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
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LoggingPlugin=exports.LogLevel=void 0,exports.createLoggingPlugin=createLoggingPlugin;const shared_1=require("../../_deps/shared/index.js");var LogLevel;!function(e){e.DEBUG="debug",e.INFO="info",e.WARN="warn",e.ERROR="error"}(LogLevel||(exports.LogLevel=LogLevel={}));class LoggingPlugin{name="logging";version="1.0.0";description="Captures message processing events for debugging and audit trails";priority=10;options;logs=[];constructor(e={}){this.options={level:e.level??LogLevel.INFO,includeSize:e.includeSize??!0,includeMetadata:e.includeMetadata??!1,logHandler:e.logHandler??(e=>{console.log(JSON.stringify(e))}),filter:e.filter??(()=>!0)}}onInit(){return this.log({timestamp:(new Date).toISOString(),level:LogLevel.INFO,event:"send",agent:"system",metadata:{message:"Logging plugin initialized"}}),(0,shared_1.ok)(void 0)}onDestroy(){return this.log({timestamp:(new Date).toISOString(),level:LogLevel.INFO,event:"send",agent:"system",metadata:{message:"Logging plugin destroyed",totalLogs:this.logs.length}}),this.logs=[],(0,shared_1.ok)(void 0)}onSend(e,t){const i=this.options.includeSize?this.estimateSize(e):void 0;return this.log({timestamp:(new Date).toISOString(),level:LogLevel.INFO,event:"send",agent:t.agent.did,recipient:t.recipient,scope:t.scope,payloadSize:i,metadata:this.options.includeMetadata?t.metadata:void 0}),(0,shared_1.ok)({payload:e})}onReceive(e,t){const i=this.options.includeSize?this.estimateSize(e):void 0;return this.log({timestamp:(new Date).toISOString(),level:LogLevel.INFO,event:"receive",agent:t.agent.did,recipient:e.sender,scope:t.scope,payloadSize:i,metadata:this.options.includeMetadata?t.metadata:void 0}),(0,shared_1.ok)({payload:e})}onEncrypt(e,t){return this.log({timestamp:(new Date).toISOString(),level:LogLevel.DEBUG,event:"encrypt",agent:t.agent.did,recipient:t.recipient,scope:t.scope,payloadSize:this.options.includeSize?e.length:void 0,metadata:this.options.includeMetadata?t.metadata:void 0}),(0,shared_1.ok)({payload:e})}onDecrypt(e,t){return this.log({timestamp:(new Date).toISOString(),level:LogLevel.DEBUG,event:"decrypt",agent:t.agent.did,scope:t.scope,payloadSize:this.options.includeSize?e.length:void 0,metadata:this.options.includeMetadata?t.metadata:void 0}),(0,shared_1.ok)({payload:e})}getLogs(){return[...this.logs]}clearLogs(){this.logs=[]}getFilteredLogs(e){return this.logs.filter(e)}log(e){this.shouldLog(e.level)&&this.options.filter(e)&&(this.logs.push(e),this.options.logHandler(e))}shouldLog(e){const t=[LogLevel.DEBUG,LogLevel.INFO,LogLevel.WARN,LogLevel.ERROR],i=t.indexOf(this.options.level);return t.indexOf(e)>=i}estimateSize(e){if(e instanceof Uint8Array)return e.length;try{return JSON.stringify(e).length}catch{return 0}}}function createLoggingPlugin(e){return new LoggingPlugin(e)}exports.LoggingPlugin=LoggingPlugin;
@@ -1,181 +1 @@
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
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.MetricsPlugin=void 0,exports.createMetricsPlugin=createMetricsPlugin;const shared_1=require("../../_deps/shared/index.js");class MetricsPlugin{name="metrics";version="1.0.0";description="Tracks performance metrics, message counts, and error rates";priority=20;options;metrics=[];startTime=Date.now();exportTimer;constructor(t={}){this.options={highResolution:t.highResolution??!0,maxMetrics:t.maxMetrics??1e4,onExport:t.onExport??(()=>{}),exportInterval:t.exportInterval??6e4}}onInit(){return this.startTime=Date.now(),this.options.exportInterval>0&&(this.exportTimer=setInterval(()=>{this.export()},this.options.exportInterval)),(0,shared_1.ok)(void 0)}onDestroy(){return this.exportTimer&&(clearInterval(this.exportTimer),this.exportTimer=void 0),this.export(),this.metrics=[],(0,shared_1.ok)(void 0)}onSend(t,e){const r=this.now(),s=this.now();return this.record({timestamp:Date.now(),event:"send",duration:s-r,success:!0}),(0,shared_1.ok)({payload:t})}onReceive(t,e){const r=this.now(),s=this.now();return this.record({timestamp:Date.now(),event:"receive",duration:s-r,success:!0}),(0,shared_1.ok)({payload:t})}onEncrypt(t,e){const r=this.now(),s=this.now();return this.record({timestamp:Date.now(),event:"encrypt",duration:s-r,success:!0}),(0,shared_1.ok)({payload:t})}onDecrypt(t,e){const r=this.now(),s=this.now();return this.record({timestamp:Date.now(),event:"decrypt",duration:s-r,success:!0}),(0,shared_1.ok)({payload:t})}getMetrics(){return[...this.metrics]}getAggregatedMetrics(){const t=this.metrics.filter(t=>"send"===t.event),e=this.metrics.filter(t=>"receive"===t.event),r=this.metrics.filter(t=>"encrypt"===t.event),s=this.metrics.filter(t=>"decrypt"===t.event),i=this.metrics.filter(t=>!t.success),n=t=>0===t.length?0:t.reduce((t,e)=>t+e.duration,0)/t.length,o=this.metrics.length;return{totalSends:t.length,totalReceives:e.length,totalEncrypts:r.length,totalDecrypts:s.length,avgSendDuration:n(t),avgReceiveDuration:n(e),avgEncryptDuration:n(r),avgDecryptDuration:n(s),totalErrors:i.length,errorRate:o>0?i.length/o:0,uptime:Date.now()-this.startTime}}clearMetrics(){this.metrics=[],this.startTime=Date.now()}export(){this.metrics.length>0&&this.options.onExport([...this.metrics])}getMetricsInRange(t,e){return this.metrics.filter(r=>r.timestamp>=t&&r.timestamp<=e)}getMetricsByEvent(t){return this.metrics.filter(e=>e.event===t)}record(t){this.metrics.push(t),this.metrics.length>this.options.maxMetrics&&this.metrics.shift()}now(){return this.options.highResolution&&"undefined"!=typeof performance?performance.now():Date.now()}}function createMetricsPlugin(t){return new MetricsPlugin(t)}exports.MetricsPlugin=MetricsPlugin;