@enbox/dwn-server 0.0.2 → 0.0.4

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 (309) hide show
  1. package/LICENSE +3 -2
  2. package/README.md +115 -215
  3. package/dist/esm/src/admin/activity-log.d.ts +44 -0
  4. package/dist/esm/src/admin/activity-log.d.ts.map +1 -0
  5. package/dist/esm/src/admin/activity-log.js +85 -0
  6. package/dist/esm/src/admin/activity-log.js.map +1 -0
  7. package/dist/esm/src/admin/admin-api.d.ts +61 -0
  8. package/dist/esm/src/admin/admin-api.d.ts.map +1 -0
  9. package/dist/esm/src/admin/admin-api.js +1047 -0
  10. package/dist/esm/src/admin/admin-api.js.map +1 -0
  11. package/dist/esm/src/admin/admin-auth.d.ts +9 -0
  12. package/dist/esm/src/admin/admin-auth.d.ts.map +1 -0
  13. package/dist/esm/src/admin/admin-auth.js +45 -0
  14. package/dist/esm/src/admin/admin-auth.js.map +1 -0
  15. package/dist/esm/src/admin/admin-store.d.ts +111 -0
  16. package/dist/esm/src/admin/admin-store.d.ts.map +1 -0
  17. package/dist/esm/src/admin/admin-store.js +376 -0
  18. package/dist/esm/src/admin/admin-store.js.map +1 -0
  19. package/dist/esm/src/admin/audit-log.d.ts +94 -0
  20. package/dist/esm/src/admin/audit-log.d.ts.map +1 -0
  21. package/dist/esm/src/admin/audit-log.js +220 -0
  22. package/dist/esm/src/admin/audit-log.js.map +1 -0
  23. package/dist/esm/src/admin/index.d.ts +10 -0
  24. package/dist/esm/src/admin/index.d.ts.map +1 -0
  25. package/dist/esm/src/admin/index.js +7 -0
  26. package/dist/esm/src/admin/index.js.map +1 -0
  27. package/dist/esm/src/admin/types.d.ts +306 -0
  28. package/dist/esm/src/admin/types.d.ts.map +1 -0
  29. package/dist/esm/src/admin/types.js +2 -0
  30. package/dist/esm/src/admin/types.js.map +1 -0
  31. package/dist/esm/src/admin/webhook-manager.d.ts +55 -0
  32. package/dist/esm/src/admin/webhook-manager.d.ts.map +1 -0
  33. package/dist/esm/src/admin/webhook-manager.js +184 -0
  34. package/dist/esm/src/admin/webhook-manager.js.map +1 -0
  35. package/dist/esm/src/config.d.ts +124 -9
  36. package/dist/esm/src/config.d.ts.map +1 -1
  37. package/dist/esm/src/config.js +155 -13
  38. package/dist/esm/src/config.js.map +1 -1
  39. package/dist/esm/src/connection/connection-manager.d.ts +32 -9
  40. package/dist/esm/src/connection/connection-manager.d.ts.map +1 -1
  41. package/dist/esm/src/connection/connection-manager.js +38 -5
  42. package/dist/esm/src/connection/connection-manager.js.map +1 -1
  43. package/dist/esm/src/connection/flow-controller.d.ts +53 -0
  44. package/dist/esm/src/connection/flow-controller.d.ts.map +1 -0
  45. package/dist/esm/src/connection/flow-controller.js +101 -0
  46. package/dist/esm/src/connection/flow-controller.js.map +1 -0
  47. package/dist/esm/src/connection/socket-connection.d.ts +54 -18
  48. package/dist/esm/src/connection/socket-connection.d.ts.map +1 -1
  49. package/dist/esm/src/connection/socket-connection.js +102 -40
  50. package/dist/esm/src/connection/socket-connection.js.map +1 -1
  51. package/dist/esm/src/delivery-service.d.ts +43 -0
  52. package/dist/esm/src/delivery-service.d.ts.map +1 -0
  53. package/dist/esm/src/delivery-service.js +574 -0
  54. package/dist/esm/src/delivery-service.js.map +1 -0
  55. package/dist/esm/src/dwn-error.d.ts +10 -1
  56. package/dist/esm/src/dwn-error.d.ts.map +1 -1
  57. package/dist/esm/src/dwn-error.js +9 -0
  58. package/dist/esm/src/dwn-error.js.map +1 -1
  59. package/dist/esm/src/dwn-server.d.ts +13 -6
  60. package/dist/esm/src/dwn-server.d.ts.map +1 -1
  61. package/dist/esm/src/dwn-server.js +199 -24
  62. package/dist/esm/src/dwn-server.js.map +1 -1
  63. package/dist/esm/src/http-api.d.ts +28 -13
  64. package/dist/esm/src/http-api.d.ts.map +1 -1
  65. package/dist/esm/src/http-api.js +649 -374
  66. package/dist/esm/src/http-api.js.map +1 -1
  67. package/dist/esm/src/index.d.ts +6 -2
  68. package/dist/esm/src/index.d.ts.map +1 -1
  69. package/dist/esm/src/index.js +4 -1
  70. package/dist/esm/src/index.js.map +1 -1
  71. package/dist/esm/src/json-rpc-api.js +2 -1
  72. package/dist/esm/src/json-rpc-api.js.map +1 -1
  73. package/dist/esm/src/json-rpc-handlers/dwn/process-message.d.ts.map +1 -1
  74. package/dist/esm/src/json-rpc-handlers/dwn/process-message.js +109 -7
  75. package/dist/esm/src/json-rpc-handlers/dwn/process-message.js.map +1 -1
  76. package/dist/esm/src/json-rpc-handlers/subscription/ack.d.ts +20 -0
  77. package/dist/esm/src/json-rpc-handlers/subscription/ack.d.ts.map +1 -0
  78. package/dist/esm/src/json-rpc-handlers/subscription/ack.js +41 -0
  79. package/dist/esm/src/json-rpc-handlers/subscription/ack.js.map +1 -0
  80. package/dist/esm/src/json-rpc-handlers/subscription/close.d.ts.map +1 -1
  81. package/dist/esm/src/json-rpc-handlers/subscription/close.js +1 -1
  82. package/dist/esm/src/json-rpc-handlers/subscription/close.js.map +1 -1
  83. package/dist/esm/src/json-rpc-handlers/subscription/index.d.ts +1 -0
  84. package/dist/esm/src/json-rpc-handlers/subscription/index.d.ts.map +1 -1
  85. package/dist/esm/src/json-rpc-handlers/subscription/index.js +1 -0
  86. package/dist/esm/src/json-rpc-handlers/subscription/index.js.map +1 -1
  87. package/dist/esm/src/lib/json-rpc-router.d.ts +25 -8
  88. package/dist/esm/src/lib/json-rpc-router.d.ts.map +1 -1
  89. package/dist/esm/src/lib/json-rpc-router.js.map +1 -1
  90. package/dist/esm/src/lib/sql-utils.d.ts +6 -0
  91. package/dist/esm/src/lib/sql-utils.d.ts.map +1 -0
  92. package/dist/esm/src/lib/sql-utils.js +8 -0
  93. package/dist/esm/src/lib/sql-utils.js.map +1 -0
  94. package/dist/esm/src/main.js +0 -6
  95. package/dist/esm/src/main.js.map +1 -1
  96. package/dist/esm/src/message-processed-hook.d.ts +35 -0
  97. package/dist/esm/src/message-processed-hook.d.ts.map +1 -0
  98. package/dist/esm/src/message-processed-hook.js +2 -0
  99. package/dist/esm/src/message-processed-hook.js.map +1 -0
  100. package/dist/esm/src/metrics.d.ts +14 -2
  101. package/dist/esm/src/metrics.d.ts.map +1 -1
  102. package/dist/esm/src/metrics.js +41 -1
  103. package/dist/esm/src/metrics.js.map +1 -1
  104. package/dist/esm/src/plugins/event-log-nats.d.ts +25 -0
  105. package/dist/esm/src/plugins/event-log-nats.d.ts.map +1 -0
  106. package/dist/esm/src/plugins/event-log-nats.js +379 -0
  107. package/dist/esm/src/plugins/event-log-nats.js.map +1 -0
  108. package/dist/esm/src/rate-limiter.d.ts +60 -0
  109. package/dist/esm/src/rate-limiter.d.ts.map +1 -0
  110. package/dist/esm/src/rate-limiter.js +116 -0
  111. package/dist/esm/src/rate-limiter.js.map +1 -0
  112. package/dist/esm/src/registration/jwt-provider-auth-plugin.d.ts +53 -0
  113. package/dist/esm/src/registration/jwt-provider-auth-plugin.d.ts.map +1 -0
  114. package/dist/esm/src/registration/jwt-provider-auth-plugin.js +90 -0
  115. package/dist/esm/src/registration/jwt-provider-auth-plugin.js.map +1 -0
  116. package/dist/esm/src/registration/open-auth-handler.d.ts +37 -0
  117. package/dist/esm/src/registration/open-auth-handler.d.ts.map +1 -0
  118. package/dist/esm/src/registration/open-auth-handler.js +214 -0
  119. package/dist/esm/src/registration/open-auth-handler.js.map +1 -0
  120. package/dist/esm/src/registration/proof-of-work-manager.d.ts +1 -1
  121. package/dist/esm/src/registration/proof-of-work-manager.d.ts.map +1 -1
  122. package/dist/esm/src/registration/proof-of-work-manager.js +3 -3
  123. package/dist/esm/src/registration/proof-of-work-manager.js.map +1 -1
  124. package/dist/esm/src/registration/provider-auth-plugin.d.ts +46 -0
  125. package/dist/esm/src/registration/provider-auth-plugin.d.ts.map +1 -0
  126. package/dist/esm/src/registration/provider-auth-plugin.js +29 -0
  127. package/dist/esm/src/registration/provider-auth-plugin.js.map +1 -0
  128. package/dist/esm/src/registration/registration-manager.d.ts +28 -5
  129. package/dist/esm/src/registration/registration-manager.d.ts.map +1 -1
  130. package/dist/esm/src/registration/registration-manager.js +83 -12
  131. package/dist/esm/src/registration/registration-manager.js.map +1 -1
  132. package/dist/esm/src/registration/registration-store.d.ts +83 -3
  133. package/dist/esm/src/registration/registration-store.d.ts.map +1 -1
  134. package/dist/esm/src/registration/registration-store.js +248 -11
  135. package/dist/esm/src/registration/registration-store.js.map +1 -1
  136. package/dist/esm/src/storage.d.ts +5 -5
  137. package/dist/esm/src/storage.d.ts.map +1 -1
  138. package/dist/esm/src/storage.js +105 -24
  139. package/dist/esm/src/storage.js.map +1 -1
  140. package/dist/esm/src/web5-connect/sql-ttl-cache.d.ts.map +1 -1
  141. package/dist/esm/src/web5-connect/sql-ttl-cache.js +11 -3
  142. package/dist/esm/src/web5-connect/sql-ttl-cache.js.map +1 -1
  143. package/dist/esm/src/web5-connect/web5-connect-server.d.ts.map +1 -1
  144. package/dist/esm/src/web5-connect/web5-connect-server.js +2 -2
  145. package/dist/esm/src/web5-connect/web5-connect-server.js.map +1 -1
  146. package/dist/esm/src/ws-api.d.ts +18 -4
  147. package/dist/esm/src/ws-api.d.ts.map +1 -1
  148. package/dist/esm/src/ws-api.js +12 -16
  149. package/dist/esm/src/ws-api.js.map +1 -1
  150. package/package.json +34 -53
  151. package/src/admin/activity-log.ts +100 -0
  152. package/src/admin/admin-api.ts +1308 -0
  153. package/src/admin/admin-auth.ts +56 -0
  154. package/src/admin/admin-store.ts +515 -0
  155. package/src/admin/audit-log.ts +327 -0
  156. package/src/admin/index.ts +34 -0
  157. package/src/admin/types.ts +352 -0
  158. package/src/admin/webhook-manager.ts +245 -0
  159. package/src/config.ts +190 -22
  160. package/src/connection/connection-manager.ts +67 -17
  161. package/src/connection/flow-controller.ts +117 -0
  162. package/src/connection/socket-connection.ts +144 -67
  163. package/src/delivery-service.ts +740 -0
  164. package/src/dwn-error.ts +11 -2
  165. package/src/dwn-server.ts +254 -39
  166. package/src/http-api.ts +736 -392
  167. package/src/index.ts +13 -2
  168. package/src/json-rpc-api.ts +2 -1
  169. package/src/json-rpc-handlers/dwn/process-message.ts +149 -15
  170. package/src/json-rpc-handlers/subscription/ack.ts +63 -0
  171. package/src/json-rpc-handlers/subscription/close.ts +5 -9
  172. package/src/json-rpc-handlers/subscription/index.ts +1 -0
  173. package/src/lib/json-rpc-router.ts +26 -11
  174. package/src/lib/sql-utils.ts +7 -0
  175. package/src/main.ts +0 -8
  176. package/src/message-processed-hook.ts +33 -0
  177. package/src/metrics.ts +57 -8
  178. package/src/plugins/event-log-nats.ts +466 -0
  179. package/src/process-handlers.ts +5 -5
  180. package/src/rate-limiter.ts +143 -0
  181. package/src/registration/jwt-provider-auth-plugin.ts +119 -0
  182. package/src/registration/open-auth-handler.ts +263 -0
  183. package/src/registration/proof-of-work-manager.ts +11 -10
  184. package/src/registration/provider-auth-plugin.ts +84 -0
  185. package/src/registration/registration-manager.ts +129 -31
  186. package/src/registration/registration-store.ts +332 -22
  187. package/src/storage.ts +136 -40
  188. package/src/web5-connect/sql-ttl-cache.ts +12 -5
  189. package/src/web5-connect/web5-connect-server.ts +9 -8
  190. package/src/ws-api.ts +39 -26
  191. package/dist/cjs/index.js +0 -6811
  192. package/dist/cjs/package.json +0 -1
  193. package/dist/esm/src/json-rpc-socket.d.ts +0 -39
  194. package/dist/esm/src/json-rpc-socket.d.ts.map +0 -1
  195. package/dist/esm/src/json-rpc-socket.js +0 -125
  196. package/dist/esm/src/json-rpc-socket.js.map +0 -1
  197. package/dist/esm/src/lib/http-server-shutdown-handler.d.ts +0 -10
  198. package/dist/esm/src/lib/http-server-shutdown-handler.d.ts.map +0 -1
  199. package/dist/esm/src/lib/http-server-shutdown-handler.js +0 -65
  200. package/dist/esm/src/lib/http-server-shutdown-handler.js.map +0 -1
  201. package/dist/esm/src/lib/json-rpc.d.ts +0 -54
  202. package/dist/esm/src/lib/json-rpc.d.ts.map +0 -1
  203. package/dist/esm/src/lib/json-rpc.js +0 -60
  204. package/dist/esm/src/lib/json-rpc.js.map +0 -1
  205. package/dist/esm/src/registration/proof-of-work-types.d.ts +0 -8
  206. package/dist/esm/src/registration/proof-of-work-types.d.ts.map +0 -1
  207. package/dist/esm/src/registration/proof-of-work-types.js +0 -2
  208. package/dist/esm/src/registration/proof-of-work-types.js.map +0 -1
  209. package/dist/esm/src/registration/registration-types.d.ts +0 -18
  210. package/dist/esm/src/registration/registration-types.d.ts.map +0 -1
  211. package/dist/esm/src/registration/registration-types.js +0 -2
  212. package/dist/esm/src/registration/registration-types.js.map +0 -1
  213. package/dist/esm/tests/common-scenario-validator.d.ts +0 -11
  214. package/dist/esm/tests/common-scenario-validator.d.ts.map +0 -1
  215. package/dist/esm/tests/common-scenario-validator.js +0 -114
  216. package/dist/esm/tests/common-scenario-validator.js.map +0 -1
  217. package/dist/esm/tests/connection/connection-manager.spec.d.ts +0 -2
  218. package/dist/esm/tests/connection/connection-manager.spec.d.ts.map +0 -1
  219. package/dist/esm/tests/connection/connection-manager.spec.js +0 -47
  220. package/dist/esm/tests/connection/connection-manager.spec.js.map +0 -1
  221. package/dist/esm/tests/connection/socket-connection.spec.d.ts +0 -2
  222. package/dist/esm/tests/connection/socket-connection.spec.d.ts.map +0 -1
  223. package/dist/esm/tests/connection/socket-connection.spec.js +0 -125
  224. package/dist/esm/tests/connection/socket-connection.spec.js.map +0 -1
  225. package/dist/esm/tests/cors/http-api.browser.d.ts +0 -2
  226. package/dist/esm/tests/cors/http-api.browser.d.ts.map +0 -1
  227. package/dist/esm/tests/cors/http-api.browser.js +0 -60
  228. package/dist/esm/tests/cors/http-api.browser.js.map +0 -1
  229. package/dist/esm/tests/cors/ping.browser.d.ts +0 -2
  230. package/dist/esm/tests/cors/ping.browser.d.ts.map +0 -1
  231. package/dist/esm/tests/cors/ping.browser.js +0 -7
  232. package/dist/esm/tests/cors/ping.browser.js.map +0 -1
  233. package/dist/esm/tests/dwn-process-message.spec.d.ts +0 -2
  234. package/dist/esm/tests/dwn-process-message.spec.d.ts.map +0 -1
  235. package/dist/esm/tests/dwn-process-message.spec.js +0 -172
  236. package/dist/esm/tests/dwn-process-message.spec.js.map +0 -1
  237. package/dist/esm/tests/dwn-server.spec.d.ts +0 -2
  238. package/dist/esm/tests/dwn-server.spec.d.ts.map +0 -1
  239. package/dist/esm/tests/dwn-server.spec.js +0 -49
  240. package/dist/esm/tests/dwn-server.spec.js.map +0 -1
  241. package/dist/esm/tests/http-api.spec.d.ts +0 -2
  242. package/dist/esm/tests/http-api.spec.d.ts.map +0 -1
  243. package/dist/esm/tests/http-api.spec.js +0 -775
  244. package/dist/esm/tests/http-api.spec.js.map +0 -1
  245. package/dist/esm/tests/json-rpc-socket.spec.d.ts +0 -2
  246. package/dist/esm/tests/json-rpc-socket.spec.d.ts.map +0 -1
  247. package/dist/esm/tests/json-rpc-socket.spec.js +0 -225
  248. package/dist/esm/tests/json-rpc-socket.spec.js.map +0 -1
  249. package/dist/esm/tests/plugins/data-store-sqlite.d.ts +0 -17
  250. package/dist/esm/tests/plugins/data-store-sqlite.d.ts.map +0 -1
  251. package/dist/esm/tests/plugins/data-store-sqlite.js +0 -23
  252. package/dist/esm/tests/plugins/data-store-sqlite.js.map +0 -1
  253. package/dist/esm/tests/plugins/event-log-sqlite.d.ts +0 -17
  254. package/dist/esm/tests/plugins/event-log-sqlite.d.ts.map +0 -1
  255. package/dist/esm/tests/plugins/event-log-sqlite.js +0 -23
  256. package/dist/esm/tests/plugins/event-log-sqlite.js.map +0 -1
  257. package/dist/esm/tests/plugins/event-stream-in-memory.d.ts +0 -17
  258. package/dist/esm/tests/plugins/event-stream-in-memory.d.ts.map +0 -1
  259. package/dist/esm/tests/plugins/event-stream-in-memory.js +0 -21
  260. package/dist/esm/tests/plugins/event-stream-in-memory.js.map +0 -1
  261. package/dist/esm/tests/plugins/message-store-sqlite.d.ts +0 -17
  262. package/dist/esm/tests/plugins/message-store-sqlite.d.ts.map +0 -1
  263. package/dist/esm/tests/plugins/message-store-sqlite.js +0 -23
  264. package/dist/esm/tests/plugins/message-store-sqlite.js.map +0 -1
  265. package/dist/esm/tests/plugins/resumable-task-store-sqlite.d.ts +0 -17
  266. package/dist/esm/tests/plugins/resumable-task-store-sqlite.d.ts.map +0 -1
  267. package/dist/esm/tests/plugins/resumable-task-store-sqlite.js +0 -23
  268. package/dist/esm/tests/plugins/resumable-task-store-sqlite.js.map +0 -1
  269. package/dist/esm/tests/process-handler.spec.d.ts +0 -2
  270. package/dist/esm/tests/process-handler.spec.d.ts.map +0 -1
  271. package/dist/esm/tests/process-handler.spec.js +0 -60
  272. package/dist/esm/tests/process-handler.spec.js.map +0 -1
  273. package/dist/esm/tests/registration/proof-of-work-manager.spec.d.ts +0 -2
  274. package/dist/esm/tests/registration/proof-of-work-manager.spec.d.ts.map +0 -1
  275. package/dist/esm/tests/registration/proof-of-work-manager.spec.js +0 -157
  276. package/dist/esm/tests/registration/proof-of-work-manager.spec.js.map +0 -1
  277. package/dist/esm/tests/rpc-subscribe-close.spec.d.ts +0 -2
  278. package/dist/esm/tests/rpc-subscribe-close.spec.d.ts.map +0 -1
  279. package/dist/esm/tests/rpc-subscribe-close.spec.js +0 -81
  280. package/dist/esm/tests/rpc-subscribe-close.spec.js.map +0 -1
  281. package/dist/esm/tests/scenarios/dynamic-plugin-loading.spec.d.ts +0 -2
  282. package/dist/esm/tests/scenarios/dynamic-plugin-loading.spec.d.ts.map +0 -1
  283. package/dist/esm/tests/scenarios/dynamic-plugin-loading.spec.js +0 -73
  284. package/dist/esm/tests/scenarios/dynamic-plugin-loading.spec.js.map +0 -1
  285. package/dist/esm/tests/scenarios/registration.spec.d.ts +0 -2
  286. package/dist/esm/tests/scenarios/registration.spec.d.ts.map +0 -1
  287. package/dist/esm/tests/scenarios/registration.spec.js +0 -507
  288. package/dist/esm/tests/scenarios/registration.spec.js.map +0 -1
  289. package/dist/esm/tests/scenarios/web5-connect.spec.d.ts +0 -2
  290. package/dist/esm/tests/scenarios/web5-connect.spec.d.ts.map +0 -1
  291. package/dist/esm/tests/scenarios/web5-connect.spec.js +0 -137
  292. package/dist/esm/tests/scenarios/web5-connect.spec.js.map +0 -1
  293. package/dist/esm/tests/test-dwn.d.ts +0 -7
  294. package/dist/esm/tests/test-dwn.d.ts.map +0 -1
  295. package/dist/esm/tests/test-dwn.js +0 -34
  296. package/dist/esm/tests/test-dwn.js.map +0 -1
  297. package/dist/esm/tests/utils.d.ts +0 -46
  298. package/dist/esm/tests/utils.d.ts.map +0 -1
  299. package/dist/esm/tests/utils.js +0 -116
  300. package/dist/esm/tests/utils.js.map +0 -1
  301. package/dist/esm/tests/ws-api.spec.d.ts +0 -2
  302. package/dist/esm/tests/ws-api.spec.d.ts.map +0 -1
  303. package/dist/esm/tests/ws-api.spec.js +0 -327
  304. package/dist/esm/tests/ws-api.spec.js.map +0 -1
  305. package/src/json-rpc-socket.ts +0 -155
  306. package/src/lib/http-server-shutdown-handler.ts +0 -79
  307. package/src/lib/json-rpc.ts +0 -126
  308. package/src/registration/proof-of-work-types.ts +0 -7
  309. package/src/registration/registration-types.ts +0 -18
@@ -1,60 +0,0 @@
1
- import sinon from 'sinon';
2
- import { config } from '../src/config.js';
3
- import { DwnServer } from '../src/dwn-server.js';
4
- import { expect } from 'chai';
5
- import { getTestDwn } from './test-dwn.js';
6
- import { Poller } from '@enbox/dwn-sdk-js';
7
- describe('Process Handlers', function () {
8
- let dwn;
9
- let dwnServer;
10
- let processExitStub;
11
- beforeEach(async function () {
12
- const dwn = await getTestDwn();
13
- dwnServer = new DwnServer({ dwn, config: config });
14
- await dwnServer.start();
15
- processExitStub = sinon.stub(process, 'exit');
16
- });
17
- afterEach(async () => {
18
- await dwnServer.stop();
19
- processExitStub.restore();
20
- });
21
- it('should stop when SIGINT is emitted', async function () {
22
- process.emit('SIGINT');
23
- Poller.pollUntilSuccessOrTimeout(async () => {
24
- expect(dwnServer.httpServer.listening).to.be.false;
25
- expect(processExitStub.called).to.be.false; // Ensure process.exit is not called
26
- });
27
- });
28
- it('should stop when SIGTERM is emitted', async function () {
29
- process.emit('SIGTERM');
30
- Poller.pollUntilSuccessOrTimeout(async () => {
31
- expect(dwnServer.httpServer.listening).to.be.false;
32
- expect(processExitStub.called).to.be.false; // Ensure process.exit is not called
33
- });
34
- });
35
- it('should log an error for an uncaught exception', async () => {
36
- // IMPORTANT: this test is a bit tricky to write because
37
- // existing process `uncaughtException` listener/handler will result will trigger an error when we force an `uncaughtException` event
38
- // causing the test to fail. So we need to remove the existing listener and add them back after the test.
39
- // To be in full control of the test, we also create the DWN server (which adds it's own `uncaughtException` listener)
40
- // AFTER removing the existing listener.
41
- await dwnServer.stop();
42
- // storing then removing existing listeners and adding back at the very end of the test
43
- const existingUncaughtExceptionListeners = [...process.listeners('uncaughtException')];
44
- process.removeAllListeners('uncaughtException');
45
- dwnServer = new DwnServer({ dwn, config: config });
46
- await dwnServer.start();
47
- const consoleErrorStub = sinon.stub(console, 'error'); // Stub console.error
48
- const errorMessage = 'Test uncaught exception';
49
- const error = new Error(errorMessage);
50
- process.emit('uncaughtException', error);
51
- // Ensure console.error was called with the expected error message
52
- console.log('console.error call count', consoleErrorStub.callCount);
53
- expect(consoleErrorStub.calledOnce).to.be.true;
54
- // Restore the original console.error
55
- consoleErrorStub.restore();
56
- // add back original listeners
57
- existingUncaughtExceptionListeners.forEach(listener => process.on('uncaughtException', listener));
58
- });
59
- });
60
- //# sourceMappingURL=process-handler.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"process-handler.spec.js","sourceRoot":"","sources":["../../../tests/process-handler.spec.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,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"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=proof-of-work-manager.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"proof-of-work-manager.spec.d.ts","sourceRoot":"","sources":["../../../../tests/registration/proof-of-work-manager.spec.ts"],"names":[],"mappings":""}
@@ -1,157 +0,0 @@
1
- import sinon from 'sinon';
2
- import { expect } from 'chai';
3
- import { useFakeTimers } from 'sinon';
4
- import { v4 as uuidv4 } from 'uuid';
5
- import { ProofOfWorkManager } from '../..//src/registration/proof-of-work-manager.js';
6
- import { randomBytes } from 'crypto';
7
- import { ProofOfWork } from '../../src/registration/proof-of-work.js';
8
- describe('ProofOfWorkManager', function () {
9
- let clock;
10
- before(async function () {
11
- clock = useFakeTimers({ shouldAdvanceTime: true });
12
- });
13
- beforeEach(async function () {
14
- });
15
- afterEach(async function () {
16
- });
17
- after(function () {
18
- clock.restore();
19
- });
20
- it('should continue to periodically refresh the challenge nonce and proof-of-work difficulty even if the refresh logic throws error.', async function () {
21
- const desiredSolveCountPerMinute = 10;
22
- const initialMaximumAllowedHashValue = 'FFFFFFFF';
23
- const proofOfWorkManager = await ProofOfWorkManager.create({
24
- autoStart: true,
25
- desiredSolveCountPerMinute,
26
- initialMaximumAllowedHashValue,
27
- });
28
- // stub that throws half the time
29
- const stub = () => {
30
- // Generate a random number between 0 and 1
31
- const random = Math.random();
32
- // If the random number is less than 0.5, throw an error
33
- if (random < 0.5) {
34
- throw new Error('Random error');
35
- }
36
- };
37
- const challengeNonceRefreshSpy = sinon.stub(proofOfWorkManager, 'refreshChallengeNonce').callsFake(stub);
38
- const maximumAllowedHashValueRefreshSpy = sinon.stub(proofOfWorkManager, 'refreshMaximumAllowedHashValue').callsFake(stub);
39
- clock.tick(60 * 60 * 1000);
40
- // 1 hour divided by the challenge refresh frequency
41
- const expectedChallengeNonceRefreshCount = 60 * 60 / proofOfWorkManager.challengeRefreshFrequencyInSeconds;
42
- // 1 hour divided by the challenge refresh frequency
43
- const expectedDifficultyReevaluationCount = 60 * 60 / proofOfWorkManager.difficultyReevaluationFrequencyInSeconds;
44
- expect(challengeNonceRefreshSpy.callCount).to.greaterThanOrEqual(expectedChallengeNonceRefreshCount);
45
- expect(maximumAllowedHashValueRefreshSpy.callCount).to.greaterThanOrEqual(expectedDifficultyReevaluationCount);
46
- });
47
- it('should accept previous and next challenge nonce to account for server time drift when challenge seed is given.', async function () {
48
- const desiredSolveCountPerMinute = 10;
49
- const initialMaximumAllowedHashValue = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'; // always accept
50
- const challengeSeed = randomBytes(32).toString('hex');
51
- const proofOfWorkManager = await ProofOfWorkManager.create({
52
- autoStart: true,
53
- desiredSolveCountPerMinute,
54
- challengeSeed,
55
- initialMaximumAllowedHashValue,
56
- });
57
- const previousChallengeNonce = proofOfWorkManager['challengeNonces'].previousChallengeNonce;
58
- const nextChallengeNonce = proofOfWorkManager['challengeNonces'].nextChallengeNonce;
59
- expect(previousChallengeNonce?.length).to.equal(64);
60
- expect(nextChallengeNonce?.length).to.equal(64);
61
- const requestData = 'irrelevant';
62
- // Expect to accept response nonce generated using previous challenge nonce.
63
- const responseNonceUsingPreviousChallengeNonce = ProofOfWork.findQualifiedResponseNonce({
64
- challengeNonce: previousChallengeNonce,
65
- maximumAllowedHashValue: initialMaximumAllowedHashValue,
66
- requestData
67
- });
68
- await proofOfWorkManager.verifyProofOfWork({
69
- challengeNonce: previousChallengeNonce,
70
- responseNonce: responseNonceUsingPreviousChallengeNonce,
71
- requestData
72
- });
73
- // Expect to accept response nonce generated using next challenge nonce.
74
- const responseNonceUsingNextChallengeNonce = ProofOfWork.findQualifiedResponseNonce({
75
- challengeNonce: nextChallengeNonce,
76
- maximumAllowedHashValue: initialMaximumAllowedHashValue,
77
- requestData
78
- });
79
- await proofOfWorkManager.verifyProofOfWork({
80
- challengeNonce: nextChallengeNonce,
81
- responseNonce: responseNonceUsingNextChallengeNonce,
82
- requestData
83
- });
84
- });
85
- it('should increase difficulty if proof-of-work rate goes above desired rate and reduce difficulty as proof-of-work rate falls below desired rate.', async function () {
86
- const desiredSolveCountPerMinute = 10;
87
- const initialMaximumAllowedHashValue = 'FFFFFFFF';
88
- const proofOfWorkManager = await ProofOfWorkManager.create({
89
- autoStart: true,
90
- desiredSolveCountPerMinute,
91
- initialMaximumAllowedHashValue,
92
- });
93
- // Load up desiredSolveRatePerMinute number of proof-of-work entries, so all future new entries will increase the complexity.
94
- for (let i = 0; i < desiredSolveCountPerMinute; i++) {
95
- await proofOfWorkManager.recordProofOfWork(uuidv4());
96
- }
97
- let baselineMaximumAllowedHashValue = proofOfWorkManager.currentMaximumAllowedHashValue;
98
- let lastMaximumAllowedHashValue = BigInt('0x' + initialMaximumAllowedHashValue);
99
- const lastSolveCountPerMinute = 0;
100
- for (let i = 0; i < 100; i++) {
101
- // Simulating 1 proof-of-work per second for 100 seconds.
102
- await proofOfWorkManager.recordProofOfWork(uuidv4());
103
- expect(proofOfWorkManager.currentSolveCountPerMinute).to.be.greaterThanOrEqual(lastSolveCountPerMinute);
104
- clock.tick(1000);
105
- // The maximum allowed hash value should be monotonically decreasing as more proof-of-work is submitted.
106
- expect(proofOfWorkManager.currentMaximumAllowedHashValue <= lastMaximumAllowedHashValue).to.be.true;
107
- lastMaximumAllowedHashValue = proofOfWorkManager.currentMaximumAllowedHashValue;
108
- }
109
- expect(proofOfWorkManager.currentMaximumAllowedHashValue < baselineMaximumAllowedHashValue).to.be.true;
110
- // Simulated 100 seconds has passed, so all proof-of-work entries should be removed.
111
- clock.tick(100_000);
112
- clock.runToLast();
113
- expect(proofOfWorkManager.currentSolveCountPerMinute).to.equal(0);
114
- baselineMaximumAllowedHashValue = proofOfWorkManager.currentMaximumAllowedHashValue;
115
- for (let i = 0; i < 100; i++) {
116
- // Simulating no proof-of-work load for 100 seconds.
117
- clock.tick(1000);
118
- // The maximum allowed hash value should be monotonically increasing again.
119
- expect(proofOfWorkManager.currentMaximumAllowedHashValue >= lastMaximumAllowedHashValue).to.be.true;
120
- lastMaximumAllowedHashValue = proofOfWorkManager.currentMaximumAllowedHashValue;
121
- }
122
- expect(proofOfWorkManager.currentMaximumAllowedHashValue > baselineMaximumAllowedHashValue).to.be.true;
123
- });
124
- it('should reduce difficulty back to initial difficulty when proof-of-work rate is lower than desired rate for long enough', async function () {
125
- const desiredSolveCountPerMinute = 10;
126
- const initialMaximumAllowedHashValue = 'FFFFFFFF';
127
- const initialMaximumAllowedHashValueAsBigInt = BigInt('0x' + initialMaximumAllowedHashValue);
128
- const proofOfWorkManager = await ProofOfWorkManager.create({
129
- autoStart: true,
130
- desiredSolveCountPerMinute,
131
- initialMaximumAllowedHashValue,
132
- });
133
- // Load up desiredSolveRatePerMinute number of proof-of-work entries, so all future new entries will increase the complexity.
134
- for (let i = 0; i < desiredSolveCountPerMinute; i++) {
135
- await proofOfWorkManager.recordProofOfWork(uuidv4());
136
- }
137
- // Simulating 1 proof-of-work per second for 100 seconds to increase proof-of-work difficulty.
138
- for (let i = 0; i < 100; i++) {
139
- await proofOfWorkManager.recordProofOfWork(uuidv4());
140
- clock.tick(1000);
141
- }
142
- expect(proofOfWorkManager.currentMaximumAllowedHashValue < initialMaximumAllowedHashValueAsBigInt).to.be.true;
143
- // Simulated 1 hour has passed.
144
- clock.tick(60 * 60 * 1000);
145
- clock.runToLast();
146
- expect(proofOfWorkManager.currentMaximumAllowedHashValue === initialMaximumAllowedHashValueAsBigInt).to.be.true;
147
- });
148
- it('should use default difficulty if not given', async function () {
149
- const desiredSolveCountPerMinute = 10;
150
- const proofOfWorkManager = await ProofOfWorkManager.create({
151
- autoStart: false,
152
- desiredSolveCountPerMinute,
153
- });
154
- expect(proofOfWorkManager.currentMaximumAllowedHashValue).to.equal(BigInt('0x' + ProofOfWorkManager.defaultMaximumAllowedHashValue));
155
- });
156
- });
157
- //# sourceMappingURL=proof-of-work-manager.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"proof-of-work-manager.spec.js","sourceRoot":"","sources":["../../../../tests/registration/proof-of-work-manager.spec.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kDAAkD,CAAC;AACtF,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AAEtE,QAAQ,CAAC,oBAAoB,EAAE;IAC7B,IAAI,KAAK,CAAC;IAEV,MAAM,CAAC,KAAK;QACV,KAAK,GAAG,aAAa,CAAC,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;IAEH,UAAU,CAAC,KAAK;IAChB,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,KAAK;IACf,CAAC,CAAC,CAAC;IAEH,KAAK,CAAC;QACJ,KAAK,CAAC,OAAO,EAAE,CAAC;IAClB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kIAAkI,EAAE,KAAK;QAC1I,MAAM,0BAA0B,GAAG,EAAE,CAAC;QACtC,MAAM,8BAA8B,GAAG,UAAU,CAAC;QAClD,MAAM,kBAAkB,GAAG,MAAM,kBAAkB,CAAC,MAAM,CAAC;YACzD,SAAS,EAAE,IAAI;YACf,0BAA0B;YAC1B,8BAA8B;SAC/B,CAAC,CAAC;QAEH,iCAAiC;QACjC,MAAM,IAAI,GAAG,GAAS,EAAE;YACtB,2CAA2C;YAC3C,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;YAE7B,wDAAwD;YACxD,IAAI,MAAM,GAAG,GAAG,EAAE,CAAC;gBACjB,MA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AC,CAAC;QAC3B,KAAK,CAAC,SAAS,EAAE,CAAC;QAElB,MAAM,CAAC,kBAAkB,CAAC,8BAA8B,KAAK,sCAAsC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;IAClH,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4CAA4C,EAAE,KAAK;QACpD,MAAM,0BAA0B,GAAG,EAAE,CAAC;QACtC,MAAM,kBAAkB,GAAG,MAAM,kBAAkB,CAAC,MAAM,CAAC;YACzD,SAAS,EAAE,KAAK;YAChB,0BAA0B;SAC3B,CAAC,CAAC;QAEH,MAAM,CAAC,kBAAkB,CAAC,8BAA8B,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,GAAG,kBAAkB,CAAC,8BAA8B,CAAC,CAAC,CAAC;IACvI,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=rpc-subscribe-close.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rpc-subscribe-close.spec.d.ts","sourceRoot":"","sources":["../../../tests/rpc-subscribe-close.spec.ts"],"names":[],"mappings":""}
@@ -1,81 +0,0 @@
1
- import { expect } from 'chai';
2
- import sinon from 'sinon';
3
- import { v4 as uuidv4 } from 'uuid';
4
- import { JsonRpcErrorCodes, createJsonRpcRequest, createJsonRpcSubscriptionRequest } from '../src/lib/json-rpc.js';
5
- import { getTestDwn } from './test-dwn.js';
6
- import { handleSubscriptionsClose } from '../src/json-rpc-handlers/subscription/close.js';
7
- import { SocketConnection } from '../src/connection/socket-connection.js';
8
- import { DwnServerError, DwnServerErrorCode } from '../src/dwn-error.js';
9
- describe('handleDwnProcessMessage', function () {
10
- it('should return an error if no socket connection exists', async function () {
11
- const requestId = uuidv4();
12
- const dwnRequest = createJsonRpcRequest(requestId, 'rpc.subscribe.close', {});
13
- const dwn = await getTestDwn();
14
- const context = { dwn, transport: 'ws' };
15
- const { jsonRpcResponse } = await handleSubscriptionsClose(dwnRequest, context);
16
- expect(jsonRpcResponse.error).to.exist;
17
- expect(jsonRpcResponse.error.code).to.equal(JsonRpcErrorCodes.InvalidRequest);
18
- expect(jsonRpcResponse.error.message).to.equal('socket connection does not exist');
19
- });
20
- it('should return an error if no subscribe options exist', async function () {
21
- const requestId = uuidv4();
22
- const dwnRequest = createJsonRpcRequest(requestId, 'rpc.subscribe.close', {});
23
- const socketConnection = sinon.createStubInstance(SocketConnection);
24
- const dwn = await getTestDwn();
25
- const context = { dwn, transport: 'ws', socketConnection };
26
- const { jsonRpcResponse } = await handleSubscriptionsClose(dwnRequest, context);
27
- expect(jsonRpcResponse.error).to.exist;
28
- expect(jsonRpcResponse.error.code).to.equal(JsonRpcErrorCodes.InvalidRequest);
29
- expect(jsonRpcResponse.error.message).to.equal('subscribe options do not exist');
30
- });
31
- it('should return an error if close subscription throws ConnectionSubscriptionJsonRpcIdNotFound', async function () {
32
- const requestId = uuidv4();
33
- const id = 'some-id';
34
- const dwnRequest = createJsonRpcSubscriptionRequest(requestId, 'rpc.subscribe.close', {}, id);
35
- const socketConnection = sinon.createStubInstance(SocketConnection);
36
- socketConnection.closeSubscription.throws(new DwnServerError(DwnServerErrorCode.ConnectionSubscriptionJsonRpcIdNotFound, ''));
37
- const dwn = await getTestDwn();
38
- const context = { dwn, transport: 'ws', socketConnection };
39
- const { jsonRpcResponse } = await handleSubscriptionsClose(dwnRequest, context);
40
- expect(jsonRpcResponse.error).to.exist;
41
- expect(jsonRpcResponse.error.code).to.equal(JsonRpcErrorCodes.InvalidParams);
42
- expect(jsonRpcResponse.error.message).to.equal(`subscription ${id} does not exist.`);
43
- });
44
- it('should return an error if close subscription throws ConnectionSubscriptionJsonRpcIdNotFound', async function () {
45
- const requestId = uuidv4();
46
- const id = 'some-id';
47
- const dwnRequest = createJsonRpcSubscriptionRequest(requestId, 'rpc.subscribe.close', {}, id);
48
- const socketConnection = sinon.createStubInstance(SocketConnection);
49
- socketConnection.closeSubscription.throws(new Error('unknown error'));
50
- const dwn = await getTestDwn();
51
- const context = { dwn, transport: 'ws', socketConnection };
52
- const { jsonRpcResponse } = await handleSubscriptionsClose(dwnRequest, context);
53
- expect(jsonRpcResponse.error).to.exist;
54
- expect(jsonRpcResponse.error.code).to.equal(JsonRpcErrorCodes.InternalError);
55
- expect(jsonRpcResponse.error.message).to.equal(`unknown subscription close error for ${id}: unknown error`);
56
- });
57
- it('should return a success', async function () {
58
- const requestId = uuidv4();
59
- const id = 'some-id';
60
- const dwnRequest = createJsonRpcSubscriptionRequest(requestId, 'rpc.subscribe.close', {}, id);
61
- const socketConnection = sinon.createStubInstance(SocketConnection);
62
- const dwn = await getTestDwn();
63
- const context = { dwn, transport: 'ws', socketConnection };
64
- const { jsonRpcResponse } = await handleSubscriptionsClose(dwnRequest, context);
65
- expect(jsonRpcResponse.error).to.not.exist;
66
- });
67
- it('handler should generate a request Id if one is not provided with the request', async function () {
68
- const requestId = uuidv4();
69
- const id = 'some-id';
70
- const dwnRequest = createJsonRpcSubscriptionRequest(requestId, 'rpc.subscribe.close', {}, id);
71
- delete dwnRequest.id; // delete request id
72
- const socketConnection = sinon.createStubInstance(SocketConnection);
73
- const dwn = await getTestDwn();
74
- const context = { dwn, transport: 'ws', socketConnection };
75
- const { jsonRpcResponse } = await handleSubscriptionsClose(dwnRequest, context);
76
- expect(jsonRpcResponse.error).to.not.exist;
77
- expect(jsonRpcResponse.id).to.exist;
78
- expect(jsonRpcResponse.id).to.not.equal(id);
79
- });
80
- });
81
- //# sourceMappingURL=rpc-subscribe-close.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rpc-subscribe-close.spec.js","sourceRoot":"","sources":["../../../tests/rpc-subscribe-close.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,M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AC,eAAe,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC;QAC3C,MAAM,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC;QACpC,MAAM,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=dynamic-plugin-loading.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dynamic-plugin-loading.spec.d.ts","sourceRoot":"","sources":["../../../../tests/scenarios/dynamic-plugin-loading.spec.ts"],"names":[],"mappings":""}
@@ -1,73 +0,0 @@
1
- import chaiAsPromised from 'chai-as-promised';
2
- import chai, { expect } from 'chai';
3
- import DataStoreSqlite from '../plugins/data-store-sqlite.js';
4
- import EventLogSqlite from '../plugins/event-log-sqlite.js';
5
- import EventStreamInMemory from '../plugins/event-stream-in-memory.js';
6
- import sinon from 'sinon';
7
- import { config } from '../../src/config.js';
8
- import { DwnServer } from '../../src/dwn-server.js';
9
- import { DidDht, DidKey, UniversalResolver } from '@enbox/dids';
10
- import CommonScenarioValidator from '../common-scenario-validator.js';
11
- import MessageStoreSqlite from '../plugins/message-store-sqlite.js';
12
- import ResumableTaskStoreSqlite from '../plugins/resumable-task-store-sqlite.js';
13
- // node.js 18 and earlier needs globalThis.crypto polyfill
14
- if (!globalThis.crypto) {
15
- // @ts-ignore
16
- globalThis.crypto = webcrypto;
17
- }
18
- chai.use(chaiAsPromised);
19
- describe('Dynamic DWN plugin loading', function () {
20
- let dwnServer;
21
- afterEach(async () => {
22
- if (dwnServer !== undefined) {
23
- await dwnServer.stop();
24
- }
25
- });
26
- it('should fail dynamically loading a non-existent plugin', async () => {
27
- const dwnServerConfigCopy = { ...config }; // not touching the original config
28
- dwnServerConfigCopy.dataStore = './non-existent-plugin.js';
29
- const invalidDwnServer = new DwnServer({ config: dwnServerConfigCopy });
30
- await expect(invalidDwnServer.start()).to.be.rejectedWith('Failed to load component at ./non-existent-plugin.js');
31
- });
32
- it('should be able to dynamically load and use custom data store implementation', async () => {
33
- // Scenario:
34
- // 1. Configure DWN to load a custom data store plugin.
35
- // 2. Validate that the constructor of the plugin is called.
36
- // 3. Validate that the DWN instance is using the custom data store plugin.
37
- // NOTE: was not able to spy on constructor directly, so spying on a method that is called in the constructor
38
- const customMessageStoreConstructorSpy = sinon.spy(MessageStoreSqlite, 'spyingTheConstructor');
39
- const customDataStoreConstructorSpy = sinon.spy(DataStoreSqlite, 'spyingTheConstructor');
40
- const customResumableTaskStoreConstructorSpy = sinon.spy(ResumableTaskStoreSqlite, 'spyingTheConstructor');
41
- const customEventLogConstructorSpy = sinon.spy(EventLogSqlite, 'spyingTheConstructor');
42
- const customEventStreamConstructorSpy = sinon.spy(EventStreamInMemory, 'spyingTheConstructor');
43
- // 1. Configure DWN to load a custom data store plugin.
44
- const dwnServerConfigCopy = { ...config }; // not touching the original config
45
- // TODO: remove below after https://github.com/TBD54566975/dwn-server/issues/144 is resolved
46
- // The default config is not reliable because other tests modify it.
47
- dwnServerConfigCopy.registrationStoreUrl = undefined; // allow all traffic
48
- dwnServerConfigCopy.messageStore = '../tests/plugins/message-store-sqlite.js';
49
- dwnServerConfigCopy.dataStore = '../tests/plugins/data-store-sqlite.js';
50
- dwnServerConfigCopy.resumableTaskStore = '../tests/plugins/resumable-task-store-sqlite.js';
51
- dwnServerConfigCopy.eventLog = '../tests/plugins/event-log-sqlite.js';
52
- dwnServerConfigCopy.eventStreamPluginPath = '../tests/plugins/event-stream-in-memory.js';
53
- // 2. Validate that the constructor of the plugin is called.
54
- // CRITICAL: We need to create a custom DID resolver that does not use a LevelDB based cache (which is the default cache used in `DWN`)
55
- // otherwise we will receive a `Database is not open` coming from LevelDB.
56
- // This is likely due to the fact that LevelDB is the default cache used in `DWN`, and we have tests creating default DWN instances,
57
- // so here we have to create a DWN that does not use the same LevelDB cache to avoid hitting LevelDB locked issues.
58
- // Long term we should investigate and unify approach of DWN instantiation taken by tests to avoid this "workaround" entirely.
59
- const didResolver = new UniversalResolver({
60
- didResolvers: [DidDht, DidKey],
61
- });
62
- dwnServer = new DwnServer({ config: dwnServerConfigCopy, didResolver });
63
- await dwnServer.start();
64
- expect(customMessageStoreConstructorSpy.calledOnce).to.be.true;
65
- expect(customDataStoreConstructorSpy.calledOnce).to.be.true;
66
- expect(customResumableTaskStoreConstructorSpy.calledOnce).to.be.true;
67
- expect(customEventLogConstructorSpy.calledOnce).to.be.true;
68
- expect(customEventStreamConstructorSpy.calledOnce).to.be.true;
69
- // 3. Validate that the DWN instance is using the custom data store plugin.
70
- await CommonScenarioValidator.sanityTestDwnReadWrite(dwnServerConfigCopy.baseUrl);
71
- });
72
- });
73
- //# sourceMappingURL=dynamic-plugin-loading.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dynamic-plugin-loading.spec.js","sourceRoot":"","sources":["../../../../tests/scenarios/dynamic-plugin-loading.spec.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,IAAI,EAAE,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,eAAe,MAAM,iCAAiC,CAAC;AAC9D,OAAO,cAAc,MAAM,gCAAgC,CAAC;AAC5D,OAAO,mBAAmB,MAAM,sCAAsC,CAAC;AACvE,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,uBAAuB,MAAM,iCAAiC,CAAC;AACtE,OAAO,kBAAkB,MAAM,oCAAoC,CAAC;AACpE,OA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EAAE,CAAC,IAAI,CAAC;QAC3D,MAAM,CAAC,+BAA+B,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;QAE9D,2EAA2E;QAC3E,MAAM,uBAAuB,CAAC,sBAAsB,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;IACpF,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=registration.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"registration.spec.d.ts","sourceRoot":"","sources":["../../../../tests/scenarios/registration.spec.ts"],"names":[],"mappings":""}