@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.
Files changed (210) hide show
  1. package/README.md +55 -14
  2. package/dist-standalone/_deps/mldsa-wasm/dist/mldsa.js +1920 -1
  3. package/dist-standalone/_deps/shared/cjs/errors.js +729 -1
  4. package/dist-standalone/_deps/shared/cjs/index.js +463 -1
  5. package/dist-standalone/_deps/shared/cjs/types.js +315 -1
  6. package/dist-standalone/_deps/shared/errors.js +244 -1
  7. package/dist-standalone/_deps/shared/index.js +72 -1
  8. package/dist-standalone/_deps/shared/types.js +86 -1
  9. package/dist-standalone/_deps/ux-helpers/cjs/errors.js +1 -1
  10. package/dist-standalone/_deps/ux-helpers/cjs/index.js +1 -1
  11. package/dist-standalone/_deps/ux-helpers/cjs/pagination.js +1 -1
  12. package/dist-standalone/_deps/ux-helpers/cjs/progress.js +1 -1
  13. package/dist-standalone/_deps/ux-helpers/cjs/search.js +1 -1
  14. package/dist-standalone/_deps/ux-helpers/cjs/types.js +1 -1
  15. package/dist-standalone/_deps/ux-helpers/errors.js +1 -1
  16. package/dist-standalone/_deps/ux-helpers/index.js +1 -1
  17. package/dist-standalone/_deps/ux-helpers/pagination.js +1 -1
  18. package/dist-standalone/_deps/ux-helpers/progress.js +1 -1
  19. package/dist-standalone/_deps/ux-helpers/search.js +1 -1
  20. package/dist-standalone/_deps/xchange/auto-accept.js +1 -1
  21. package/dist-standalone/_deps/xchange/cjs/auto-accept.js +1 -1
  22. package/dist-standalone/_deps/xchange/cjs/errors.js +1 -1
  23. package/dist-standalone/_deps/xchange/cjs/index.js +1 -1
  24. package/dist-standalone/_deps/xchange/cjs/invite-client.js +1 -1
  25. package/dist-standalone/_deps/xchange/cjs/lazy-init.js +1 -1
  26. package/dist-standalone/_deps/xchange/cjs/trust-integration.js +1 -1
  27. package/dist-standalone/_deps/xchange/cjs/xchange.js +1 -1
  28. package/dist-standalone/_deps/xchange/errors.js +1 -1
  29. package/dist-standalone/_deps/xchange/index.js +1 -1
  30. package/dist-standalone/_deps/xchange/invite-client.js +1 -1
  31. package/dist-standalone/_deps/xchange/lazy-init.js +1 -1
  32. package/dist-standalone/_deps/xchange/trust-integration.js +1 -1
  33. package/dist-standalone/_deps/xchange/xchange.js +1 -1
  34. package/dist-standalone/_deps/xregistry/cjs/discovery.js +1 -1
  35. package/dist-standalone/_deps/xregistry/cjs/errors.js +1 -1
  36. package/dist-standalone/_deps/xregistry/cjs/index.js +1 -1
  37. package/dist-standalone/_deps/xregistry/cjs/registry.js +1 -1
  38. package/dist-standalone/_deps/xregistry/cjs/schema.js +1 -1
  39. package/dist-standalone/_deps/xregistry/cjs/types.js +1 -1
  40. package/dist-standalone/_deps/xregistry/discovery.js +1 -1
  41. package/dist-standalone/_deps/xregistry/errors.js +1 -1
  42. package/dist-standalone/_deps/xregistry/index.js +1 -1
  43. package/dist-standalone/_deps/xregistry/registry.js +1 -1
  44. package/dist-standalone/_deps/xregistry/schema.js +1 -1
  45. package/dist-standalone/_deps/xregistry/types.js +1 -1
  46. package/dist-standalone/agent-call.js +659 -1
  47. package/dist-standalone/agent-sdk.js +328 -1
  48. package/dist-standalone/agent.js +1800 -1
  49. package/dist-standalone/approval.js +193 -1
  50. package/dist-standalone/async-iterators.js +382 -1
  51. package/dist-standalone/auth.js +219 -1
  52. package/dist-standalone/auto-accept.js +229 -1
  53. package/dist-standalone/backup-config.js +201 -1
  54. package/dist-standalone/backup.js +326 -1
  55. package/dist-standalone/batch-operations.js +388 -1
  56. package/dist-standalone/cancellation.js +477 -1
  57. package/dist-standalone/checkpoint.js +186 -1
  58. package/dist-standalone/circuit-breaker.js +468 -1
  59. package/dist-standalone/cjs/agent-call.js +701 -1
  60. package/dist-standalone/cjs/agent-sdk.js +332 -1
  61. package/dist-standalone/cjs/agent.js +1837 -1
  62. package/dist-standalone/cjs/approval.js +199 -1
  63. package/dist-standalone/cjs/async-iterators.js +392 -1
  64. package/dist-standalone/cjs/auth.js +225 -1
  65. package/dist-standalone/cjs/auto-accept.js +233 -1
  66. package/dist-standalone/cjs/backup-config.js +207 -1
  67. package/dist-standalone/cjs/backup.js +330 -1
  68. package/dist-standalone/cjs/batch-operations.js +397 -1
  69. package/dist-standalone/cjs/cancellation.js +490 -1
  70. package/dist-standalone/cjs/checkpoint.js +193 -1
  71. package/dist-standalone/cjs/circuit-breaker.js +476 -1
  72. package/dist-standalone/cjs/cli/init.js +492 -1
  73. package/dist-standalone/cjs/config-validation.js +522 -1
  74. package/dist-standalone/cjs/connect.js +312 -1
  75. package/dist-standalone/cjs/connection-pool.js +506 -1
  76. package/dist-standalone/cjs/correlation-id.js +339 -1
  77. package/dist-standalone/cjs/crypto-utils.js +176 -1
  78. package/dist-standalone/cjs/debug-mode.js +534 -1
  79. package/dist-standalone/cjs/did-document.js +101 -1
  80. package/dist-standalone/cjs/did-privateme.js +130 -1
  81. package/dist-standalone/cjs/did-web.js +201 -1
  82. package/dist-standalone/cjs/discovery.js +462 -1
  83. package/dist-standalone/cjs/dual-mode.js +251 -1
  84. package/dist-standalone/cjs/email-templates.js +313 -1
  85. package/dist-standalone/cjs/email-transport.js +239 -1
  86. package/dist-standalone/cjs/envelope.js +538 -1
  87. package/dist-standalone/cjs/errors.js +913 -1
  88. package/dist-standalone/cjs/event-emitter.js +461 -1
  89. package/dist-standalone/cjs/gateway-state.js +55 -1
  90. package/dist-standalone/cjs/gateway-transport.js +120 -1
  91. package/dist-standalone/cjs/graceful-degradation.js +403 -1
  92. package/dist-standalone/cjs/guardrails.js +223 -1
  93. package/dist-standalone/cjs/health-check.js +336 -1
  94. package/dist-standalone/cjs/http-compat.js +272 -1
  95. package/dist-standalone/cjs/http-status-map.js +571 -1
  96. package/dist-standalone/cjs/identity.js +645 -1
  97. package/dist-standalone/cjs/index.js +406 -1
  98. package/dist-standalone/cjs/invitation.js +421 -1
  99. package/dist-standalone/cjs/invite.js +328 -1
  100. package/dist-standalone/cjs/key-agreement.js +335 -1
  101. package/dist-standalone/cjs/lazy-init.js +300 -1
  102. package/dist-standalone/cjs/logger.js +291 -1
  103. package/dist-standalone/cjs/mdns-discovery.js +202 -1
  104. package/dist-standalone/cjs/nonce-store.js +80 -1
  105. package/dist-standalone/cjs/pairing-manager.js +223 -1
  106. package/dist-standalone/cjs/plugin-system.js +264 -1
  107. package/dist-standalone/cjs/plugins/logging.js +168 -1
  108. package/dist-standalone/cjs/plugins/metrics.js +181 -1
  109. package/dist-standalone/cjs/plugins/validation.js +302 -1
  110. package/dist-standalone/cjs/policy.js +320 -1
  111. package/dist-standalone/cjs/progress-callbacks.js +583 -1
  112. package/dist-standalone/cjs/redis-nonce-store.js +76 -1
  113. package/dist-standalone/cjs/registry-middleware.js +50 -1
  114. package/dist-standalone/cjs/retry-strategies.js +544 -1
  115. package/dist-standalone/cjs/retry-transport.js +102 -1
  116. package/dist-standalone/cjs/runtime/browser.js +533 -1
  117. package/dist-standalone/cjs/runtime/edge.js +526 -1
  118. package/dist-standalone/cjs/runtime/react-native.js +394 -1
  119. package/dist-standalone/cjs/security-policy.js +245 -1
  120. package/dist-standalone/cjs/serialization.js +1040 -1
  121. package/dist-standalone/cjs/split-channel.js +225 -1
  122. package/dist-standalone/cjs/subscription-proof.js +230 -1
  123. package/dist-standalone/cjs/succession.js +148 -1
  124. package/dist-standalone/cjs/timeouts.js +412 -1
  125. package/dist-standalone/cjs/trace-context.js +424 -1
  126. package/dist-standalone/cjs/trace-spans.js +495 -1
  127. package/dist-standalone/cjs/transport.js +63 -1
  128. package/dist-standalone/cjs/trust-registry.js +991 -1
  129. package/dist-standalone/cjs/types/error-response.js +56 -1
  130. package/dist-standalone/cjs/vault-auth.js +178 -1
  131. package/dist-standalone/cjs/vault-store-loader.js +194 -1
  132. package/dist-standalone/cjs/verify.js +25 -1
  133. package/dist-standalone/cjs/version-info.js +543 -1
  134. package/dist-standalone/cjs/xfetch.js +340 -1
  135. package/dist-standalone/cli/init.js +455 -1
  136. package/dist-standalone/cli/setup.js +514 -1
  137. package/dist-standalone/cli/types.js +27 -1
  138. package/dist-standalone/cli/xbind.js +148 -1
  139. package/dist-standalone/config-validation.js +513 -1
  140. package/dist-standalone/connect.js +274 -1
  141. package/dist-standalone/connection-pool.js +500 -1
  142. package/dist-standalone/correlation-id.js +326 -1
  143. package/dist-standalone/crypto-utils.js +157 -1
  144. package/dist-standalone/debug-mode.js +510 -1
  145. package/dist-standalone/did-document.js +96 -1
  146. package/dist-standalone/did-privateme.js +121 -1
  147. package/dist-standalone/did-web.js +196 -1
  148. package/dist-standalone/discovery.js +458 -1
  149. package/dist-standalone/dual-mode.js +247 -1
  150. package/dist-standalone/email-templates.js +309 -1
  151. package/dist-standalone/email-transport.js +232 -1
  152. package/dist-standalone/envelope.js +525 -1
  153. package/dist-standalone/errors.js +896 -1
  154. package/dist-standalone/event-emitter.js +456 -1
  155. package/dist-standalone/gateway-state.js +51 -1
  156. package/dist-standalone/gateway-transport.js +116 -1
  157. package/dist-standalone/graceful-degradation.js +396 -1
  158. package/dist-standalone/guardrails.js +216 -1
  159. package/dist-standalone/health-check.js +332 -1
  160. package/dist-standalone/http-compat.js +267 -1
  161. package/dist-standalone/http-status-map.js +561 -1
  162. package/dist-standalone/identity.js +619 -1
  163. package/dist-standalone/index.js +78 -1
  164. package/dist-standalone/invitation.js +415 -1
  165. package/dist-standalone/invite.js +324 -1
  166. package/dist-standalone/key-agreement.js +325 -1
  167. package/dist-standalone/lazy-init.js +295 -1
  168. package/dist-standalone/logger.js +285 -1
  169. package/dist-standalone/mdns-discovery.js +195 -1
  170. package/dist-standalone/nonce-store.js +76 -1
  171. package/dist-standalone/pairing-manager.js +219 -1
  172. package/dist-standalone/plugin-system.js +257 -1
  173. package/dist-standalone/plugins/logging.js +163 -1
  174. package/dist-standalone/plugins/metrics.js +176 -1
  175. package/dist-standalone/plugins/validation.js +297 -1
  176. package/dist-standalone/policy.js +315 -1
  177. package/dist-standalone/progress-callbacks.js +576 -1
  178. package/dist-standalone/redis-nonce-store.js +72 -1
  179. package/dist-standalone/registry-middleware.js +47 -1
  180. package/dist-standalone/retry-strategies.js +534 -1
  181. package/dist-standalone/retry-transport.js +98 -1
  182. package/dist-standalone/runtime/browser.js +516 -1
  183. package/dist-standalone/runtime/edge.js +511 -1
  184. package/dist-standalone/runtime/react-native.js +383 -1
  185. package/dist-standalone/security-policy.js +239 -1
  186. package/dist-standalone/serialization.js +1031 -1
  187. package/dist-standalone/split-channel.js +219 -1
  188. package/dist-standalone/subscription-proof.js +224 -1
  189. package/dist-standalone/succession.js +142 -1
  190. package/dist-standalone/timeouts.js +398 -1
  191. package/dist-standalone/trace-context.js +414 -1
  192. package/dist-standalone/trace-spans.js +488 -1
  193. package/dist-standalone/transport.js +59 -1
  194. package/dist-standalone/trust-registry.js +950 -1
  195. package/dist-standalone/types/error-response.js +52 -1
  196. package/dist-standalone/vault-auth.js +174 -1
  197. package/dist-standalone/vault-store-loader.js +187 -1
  198. package/dist-standalone/verify.js +16 -1
  199. package/dist-standalone/version-info.js +530 -1
  200. package/dist-standalone/xfetch.js +335 -1
  201. package/package.json +4 -13
  202. package/share1.dat +0 -0
  203. package/dist-standalone/_deps/mldsa-wasm/LICENSE +0 -24
  204. package/dist-standalone/_deps/mldsa-wasm/package.json +0 -46
  205. package/dist-standalone/_deps/shared/cjs/package.json +0 -1
  206. package/dist-standalone/_deps/ux-helpers/cjs/package.json +0 -1
  207. package/dist-standalone/_deps/xchange/cjs/package.json +0 -1
  208. package/dist-standalone/_deps/xregistry/cjs/package.json +0 -1
  209. package/dist-standalone/cjs/package.json +0 -3
  210. package/dist-standalone/package.json +0 -10
@@ -1 +1,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
+ "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";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
+ "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";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;
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
+ }