spec-3nweb-server 1.8.5 → 1.8.7

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 (340) hide show
  1. package/.gitlab-ci-linux.yml +50 -0
  2. package/.gitlab-ci-mac.yml +29 -0
  3. package/.gitlab-ci-windows.yml +29 -0
  4. package/.gitlab-ci.yml +63 -0
  5. package/build/3nstorage/resources/store.d.ts +2 -2
  6. package/build/3nstorage/resources/store.js +1 -1
  7. package/build/3nstorage/resources/users.d.ts +3 -3
  8. package/build/3nstorage/resources/users.js +1 -1
  9. package/build/3nstorage/resources/utils.d.ts +6 -0
  10. package/build/3nstorage/resources/utils.js +41 -0
  11. package/build/3nstorage/routes/owner/archive-obj-version.js +8 -10
  12. package/build/3nstorage/routes/owner/cancel-trans.js +5 -4
  13. package/build/3nstorage/routes/owner/delete-obj.js +7 -8
  14. package/build/3nstorage/routes/owner/get-archived-obj-ver.js +11 -13
  15. package/build/3nstorage/routes/owner/get-current-obj.js +7 -6
  16. package/build/3nstorage/routes/owner/get-obj-status.js +8 -8
  17. package/build/3nstorage/routes/owner/put-current-obj.js +25 -55
  18. package/build/3nstorage/routes/owner/session-params.js +2 -0
  19. package/build/asmail/resources/utils.d.ts +6 -0
  20. package/build/asmail/resources/utils.js +36 -0
  21. package/build/asmail/routes/delivery/finalize-delivery.js +3 -2
  22. package/build/asmail/routes/delivery/pre-flight.js +9 -26
  23. package/build/asmail/routes/delivery/provide-recipient-pubkey.js +4 -3
  24. package/build/asmail/routes/delivery/put-metadata.js +13 -21
  25. package/build/asmail/routes/delivery/put-obj.js +19 -25
  26. package/build/asmail/routes/delivery/restart-session.d.ts +4 -8
  27. package/build/asmail/routes/delivery/restart-session.js +10 -23
  28. package/build/asmail/routes/delivery/sender-authorization.js +5 -5
  29. package/build/asmail/routes/delivery/start-session.js +9 -24
  30. package/build/asmail/routes/retrieval/get-message-meta.js +4 -7
  31. package/build/asmail/routes/retrieval/get-message-obj.js +10 -7
  32. package/build/asmail/routes/retrieval/list-messages.js +4 -4
  33. package/build/asmail/routes/retrieval/remove-message.js +3 -2
  34. package/build/mock/tls-options.js +46 -44
  35. package/build/tests/admin-proto/signup.d.ts +1 -0
  36. package/build/tests/admin-proto/signup.js +235 -0
  37. package/build/tests/jasmine.d.ts +1 -0
  38. package/build/tests/jasmine.js +32 -0
  39. package/build/tests/libs-for-tests/3nstorage.d.ts +22 -0
  40. package/build/tests/libs-for-tests/3nstorage.js +123 -0
  41. package/build/tests/libs-for-tests/asmail.d.ts +22 -0
  42. package/build/tests/libs-for-tests/asmail.js +179 -0
  43. package/build/tests/libs-for-tests/assert.d.ts +1 -0
  44. package/build/tests/libs-for-tests/assert.js +26 -0
  45. package/build/tests/libs-for-tests/async-jasmine.d.ts +7 -0
  46. package/build/tests/libs-for-tests/async-jasmine.js +77 -0
  47. package/build/tests/libs-for-tests/bytes-equal.d.ts +1 -0
  48. package/build/tests/libs-for-tests/bytes-equal.js +34 -0
  49. package/build/tests/libs-for-tests/json-copy.d.ts +1 -0
  50. package/build/tests/libs-for-tests/json-copy.js +45 -0
  51. package/build/tests/libs-for-tests/json-equal.d.ts +4 -0
  52. package/build/tests/libs-for-tests/json-equal.js +67 -0
  53. package/build/tests/libs-for-tests/mailerid.d.ts +13 -0
  54. package/build/tests/libs-for-tests/mailerid.js +114 -0
  55. package/build/tests/libs-for-tests/pkl.d.ts +28 -0
  56. package/build/tests/libs-for-tests/pkl.js +89 -0
  57. package/build/tests/libs-for-tests/server-components/3nstorage.d.ts +20 -0
  58. package/build/tests/libs-for-tests/server-components/3nstorage.js +200 -0
  59. package/build/tests/libs-for-tests/server-components/admin.d.ts +6 -0
  60. package/build/tests/libs-for-tests/server-components/admin.js +43 -0
  61. package/build/tests/libs-for-tests/server-components/asmail.d.ts +16 -0
  62. package/build/tests/libs-for-tests/server-components/asmail.js +143 -0
  63. package/build/tests/libs-for-tests/server-components/component.d.ts +13 -0
  64. package/build/tests/libs-for-tests/server-components/component.js +77 -0
  65. package/build/tests/libs-for-tests/server-components/mailerid.d.ts +10 -0
  66. package/build/tests/libs-for-tests/server-components/mailerid.js +103 -0
  67. package/build/tests/libs-for-tests/server-runner.d.ts +15 -0
  68. package/build/tests/libs-for-tests/server-runner.js +69 -0
  69. package/build/tests/libs-for-tests/spec-assembly.d.ts +6 -0
  70. package/build/tests/libs-for-tests/spec-assembly.js +55 -0
  71. package/build/tests/libs-for-tests/ws-utils.d.ts +3 -0
  72. package/build/tests/libs-for-tests/ws-utils.js +59 -0
  73. package/build/tests/libs-for-tests/xhr-utils.d.ts +61 -0
  74. package/build/tests/libs-for-tests/xhr-utils.js +154 -0
  75. package/build/tests/protocols/3nstorage/owner/specs/archive-obj-ver.d.ts +2 -0
  76. package/build/tests/protocols/3nstorage/owner/specs/archive-obj-ver.js +84 -0
  77. package/build/tests/protocols/3nstorage/owner/specs/archive-root-ver.d.ts +2 -0
  78. package/build/tests/protocols/3nstorage/owner/specs/archive-root-ver.js +78 -0
  79. package/build/tests/protocols/3nstorage/owner/specs/delete-archive-obj-ver.d.ts +2 -0
  80. package/build/tests/protocols/3nstorage/owner/specs/delete-archive-obj-ver.js +83 -0
  81. package/build/tests/protocols/3nstorage/owner/specs/delete-archive-root-ver.d.ts +2 -0
  82. package/build/tests/protocols/3nstorage/owner/specs/delete-archive-root-ver.js +77 -0
  83. package/build/tests/protocols/3nstorage/owner/specs/delete-obj.d.ts +2 -0
  84. package/build/tests/protocols/3nstorage/owner/specs/delete-obj.js +75 -0
  85. package/build/tests/protocols/3nstorage/owner/specs/events.d.ts +2 -0
  86. package/build/tests/protocols/3nstorage/owner/specs/events.js +91 -0
  87. package/build/tests/protocols/3nstorage/owner/specs/get-current-obj.d.ts +2 -0
  88. package/build/tests/protocols/3nstorage/owner/specs/get-current-obj.js +269 -0
  89. package/build/tests/protocols/3nstorage/owner/specs/get-current-root.d.ts +2 -0
  90. package/build/tests/protocols/3nstorage/owner/specs/get-current-root.js +262 -0
  91. package/build/tests/protocols/3nstorage/owner/specs/get-obj-status.d.ts +2 -0
  92. package/build/tests/protocols/3nstorage/owner/specs/get-obj-status.js +79 -0
  93. package/build/tests/protocols/3nstorage/owner/specs/get-root-status.d.ts +2 -0
  94. package/build/tests/protocols/3nstorage/owner/specs/get-root-status.js +72 -0
  95. package/build/tests/protocols/3nstorage/owner/specs/put-current-obj.d.ts +2 -0
  96. package/build/tests/protocols/3nstorage/owner/specs/put-current-obj.js +287 -0
  97. package/build/tests/protocols/3nstorage/owner/specs/put-current-root.d.ts +2 -0
  98. package/build/tests/protocols/3nstorage/owner/specs/put-current-root.js +274 -0
  99. package/build/tests/protocols/3nstorage/owner/specs/trans-cancel-root.d.ts +2 -0
  100. package/build/tests/protocols/3nstorage/owner/specs/trans-cancel-root.js +73 -0
  101. package/build/tests/protocols/3nstorage/owner/specs/trans-cancel.d.ts +2 -0
  102. package/build/tests/protocols/3nstorage/owner/specs/trans-cancel.js +72 -0
  103. package/build/tests/protocols/3nstorage/owner/test-utils.d.ts +14 -0
  104. package/build/tests/protocols/3nstorage/owner/test-utils.js +54 -0
  105. package/build/tests/protocols/3nstorage/owner.d.ts +1 -0
  106. package/build/tests/protocols/3nstorage/owner.js +138 -0
  107. package/build/tests/protocols/asmail/config.d.ts +1 -0
  108. package/build/tests/protocols/asmail/config.js +117 -0
  109. package/build/tests/protocols/asmail/delivery/specs/finalize-delivery.d.ts +2 -0
  110. package/build/tests/protocols/asmail/delivery/specs/finalize-delivery.js +60 -0
  111. package/build/tests/protocols/asmail/delivery/specs/provide-recipient-pubkey.d.ts +2 -0
  112. package/build/tests/protocols/asmail/delivery/specs/provide-recipient-pubkey.js +68 -0
  113. package/build/tests/protocols/asmail/delivery/specs/put-metadata.d.ts +2 -0
  114. package/build/tests/protocols/asmail/delivery/specs/put-metadata.js +83 -0
  115. package/build/tests/protocols/asmail/delivery/specs/put-obj.d.ts +2 -0
  116. package/build/tests/protocols/asmail/delivery/specs/put-obj.js +123 -0
  117. package/build/tests/protocols/asmail/delivery/specs/restart-session.d.ts +2 -0
  118. package/build/tests/protocols/asmail/delivery/specs/restart-session.js +79 -0
  119. package/build/tests/protocols/asmail/delivery/specs/start-session.d.ts +2 -0
  120. package/build/tests/protocols/asmail/delivery/specs/start-session.js +64 -0
  121. package/build/tests/protocols/asmail/delivery/test-utils.d.ts +16 -0
  122. package/build/tests/protocols/asmail/delivery/test-utils.js +46 -0
  123. package/build/tests/protocols/asmail/delivery.d.ts +1 -0
  124. package/build/tests/protocols/asmail/delivery.js +46 -0
  125. package/build/tests/protocols/asmail/retrieval/specs/events.d.ts +2 -0
  126. package/build/tests/protocols/asmail/retrieval/specs/events.js +62 -0
  127. package/build/tests/protocols/asmail/retrieval/specs/get-message-meta.d.ts +2 -0
  128. package/build/tests/protocols/asmail/retrieval/specs/get-message-meta.js +70 -0
  129. package/build/tests/protocols/asmail/retrieval/specs/get-message-obj.d.ts +2 -0
  130. package/build/tests/protocols/asmail/retrieval/specs/get-message-obj.js +166 -0
  131. package/build/tests/protocols/asmail/retrieval/specs/list-messages.d.ts +2 -0
  132. package/build/tests/protocols/asmail/retrieval/specs/list-messages.js +96 -0
  133. package/build/tests/protocols/asmail/retrieval/specs/remove-message.d.ts +2 -0
  134. package/build/tests/protocols/asmail/retrieval/specs/remove-message.js +66 -0
  135. package/build/tests/protocols/asmail/retrieval/test-utils.d.ts +17 -0
  136. package/build/tests/protocols/asmail/retrieval/test-utils.js +46 -0
  137. package/build/tests/protocols/asmail/retrieval.d.ts +1 -0
  138. package/build/tests/protocols/asmail/retrieval.js +92 -0
  139. package/build/tests/protocols/mailerid.d.ts +1 -0
  140. package/build/tests/protocols/mailerid.js +210 -0
  141. package/build/tests/shared-checks/check-mid-login.d.ts +2 -0
  142. package/build/tests/shared-checks/check-mid-login.js +131 -0
  143. package/build/tests/shared-checks/requests.d.ts +20 -0
  144. package/build/tests/shared-checks/requests.js +123 -0
  145. package/package.json +1 -1
  146. package/packing/create-deb.sh +57 -0
  147. package/packing/deb/lib/systemd/system/3nweb.service +11 -0
  148. package/packing/deb/postinst +44 -0
  149. package/packing/deb/usr/share/doc/3nweb-server/conf-for-postinstall.yaml +19 -0
  150. package/packing/deb/usr/share/doc/3nweb-server/copyright +22 -0
  151. package/publish-task.sh +10 -0
  152. package/push-to-github.sh +105 -0
  153. package/ts-code/3nstorage/3nstorage-app.ts +99 -0
  154. package/ts-code/3nstorage/owner.ts +178 -0
  155. package/ts-code/3nstorage/resources/sessions.ts +37 -0
  156. package/ts-code/3nstorage/resources/store.ts +896 -0
  157. package/ts-code/3nstorage/resources/users.ts +258 -0
  158. package/ts-code/3nstorage/resources/utils.ts +45 -0
  159. package/ts-code/3nstorage/routes/owner/archive-obj-version.ts +71 -0
  160. package/ts-code/3nstorage/routes/owner/cancel-trans.ts +60 -0
  161. package/ts-code/3nstorage/routes/owner/delete-obj.ts +99 -0
  162. package/ts-code/3nstorage/routes/owner/get-archived-obj-ver.ts +109 -0
  163. package/ts-code/3nstorage/routes/owner/get-current-obj.ts +124 -0
  164. package/ts-code/3nstorage/routes/owner/get-obj-status.ts +55 -0
  165. package/ts-code/3nstorage/routes/owner/param-getter.ts +51 -0
  166. package/ts-code/3nstorage/routes/owner/param-setter.ts +50 -0
  167. package/ts-code/3nstorage/routes/owner/put-current-obj.ts +257 -0
  168. package/ts-code/3nstorage/routes/owner/session-params.ts +50 -0
  169. package/ts-code/3nstorage/shared.ts +43 -0
  170. package/ts-code/asmail/asmail-app.ts +91 -0
  171. package/ts-code/asmail/config.ts +96 -0
  172. package/ts-code/asmail/delivery.ts +94 -0
  173. package/ts-code/asmail/resources/delivery-sessions.ts +118 -0
  174. package/ts-code/asmail/resources/inbox.ts +696 -0
  175. package/ts-code/asmail/resources/recipients.ts +495 -0
  176. package/ts-code/asmail/resources/sessions.ts +37 -0
  177. package/ts-code/asmail/resources/utils.ts +41 -0
  178. package/ts-code/asmail/retrieval.ts +96 -0
  179. package/ts-code/asmail/routes/config/param-getter.ts +49 -0
  180. package/ts-code/asmail/routes/config/param-setter.ts +49 -0
  181. package/ts-code/asmail/routes/delivery/finalize-delivery.ts +51 -0
  182. package/ts-code/asmail/routes/delivery/pre-flight.ts +118 -0
  183. package/ts-code/asmail/routes/delivery/provide-recipient-pubkey.ts +58 -0
  184. package/ts-code/asmail/routes/delivery/put-metadata.ts +85 -0
  185. package/ts-code/asmail/routes/delivery/put-obj.ts +152 -0
  186. package/ts-code/asmail/routes/delivery/restart-session.ts +117 -0
  187. package/ts-code/asmail/routes/delivery/sender-authorization.ts +81 -0
  188. package/ts-code/asmail/routes/delivery/start-session.ts +136 -0
  189. package/ts-code/asmail/routes/retrieval/get-message-meta.ts +50 -0
  190. package/ts-code/asmail/routes/retrieval/get-message-obj.ts +106 -0
  191. package/ts-code/asmail/routes/retrieval/list-messages.ts +68 -0
  192. package/ts-code/asmail/routes/retrieval/remove-message.ts +48 -0
  193. package/ts-code/cli/index.ts +82 -0
  194. package/ts-code/cli/run-cmd.ts +81 -0
  195. package/ts-code/cli/show-sample-config.ts +78 -0
  196. package/ts-code/cli/signup-cmd.ts +229 -0
  197. package/ts-code/cli/user-cmd.ts +68 -0
  198. package/ts-code/cli/utils.ts +105 -0
  199. package/ts-code/config/default-confs.ts +22 -0
  200. package/ts-code/config/from-yaml.ts +35 -0
  201. package/ts-code/config/letsencrypt.ts +77 -0
  202. package/ts-code/config/signup.ts +137 -0
  203. package/ts-code/lib-common/admin-api/signup.ts +120 -0
  204. package/ts-code/lib-common/assert.ts +22 -0
  205. package/ts-code/lib-common/async-fs-node.ts +656 -0
  206. package/ts-code/lib-common/buffer-utils.ts +124 -0
  207. package/ts-code/lib-common/byte-streaming/common.ts +166 -0
  208. package/ts-code/lib-common/bytes-equal.ts +25 -0
  209. package/ts-code/lib-common/canonical-address.ts +92 -0
  210. package/ts-code/lib-common/exceptions/error.ts +44 -0
  211. package/ts-code/lib-common/exceptions/file.ts +84 -0
  212. package/ts-code/lib-common/exceptions/http.ts +69 -0
  213. package/ts-code/lib-common/ipc/generic-ipc.ts +750 -0
  214. package/ts-code/lib-common/ipc/ws-ipc.ts +117 -0
  215. package/ts-code/lib-common/json-equal.ts +55 -0
  216. package/ts-code/lib-common/json-utils.ts +130 -0
  217. package/ts-code/lib-common/jwkeys.ts +246 -0
  218. package/ts-code/lib-common/map-of-sets.ts +60 -0
  219. package/ts-code/lib-common/mid-sigs-NaCl-Ed.ts +677 -0
  220. package/ts-code/lib-common/objs-on-disk/file-layout.ts +480 -0
  221. package/ts-code/lib-common/objs-on-disk/obj-file.ts +325 -0
  222. package/ts-code/lib-common/objs-on-disk/utils.ts +201 -0
  223. package/ts-code/lib-common/objs-on-disk/v1-obj-file-format.ts +329 -0
  224. package/ts-code/lib-common/processes.ts +501 -0
  225. package/ts-code/lib-common/random-node.ts +79 -0
  226. package/ts-code/lib-common/service-api/3nstorage/owner.ts +559 -0
  227. package/ts-code/lib-common/service-api/3nstorage/root-route.ts +22 -0
  228. package/ts-code/lib-common/service-api/asmail/config.ts +144 -0
  229. package/ts-code/lib-common/service-api/asmail/delivery.ts +250 -0
  230. package/ts-code/lib-common/service-api/asmail/retrieval.ts +238 -0
  231. package/ts-code/lib-common/service-api/asmail/root-route.ts +22 -0
  232. package/ts-code/lib-common/service-api/ipc-api.ts +44 -0
  233. package/ts-code/lib-common/service-api/locker.ts +44 -0
  234. package/ts-code/lib-common/service-api/mailer-id/login.ts +80 -0
  235. package/ts-code/lib-common/service-api/mailer-id/provisioning.ts +64 -0
  236. package/ts-code/lib-common/service-api/mailer-id/root-route.ts +25 -0
  237. package/ts-code/lib-common/service-api/pub-key-login.ts +75 -0
  238. package/ts-code/lib-common/service-api/web-socket-base.ts +87 -0
  239. package/ts-code/lib-common/session-encryptor.ts +54 -0
  240. package/ts-code/lib-common/time-window-cache.ts +74 -0
  241. package/ts-code/lib-common/transferable.d.ts +30 -0
  242. package/ts-code/lib-server/conf-util.ts +35 -0
  243. package/ts-code/lib-server/mid-access.ts +45 -0
  244. package/ts-code/lib-server/middleware/body-parsers.ts +248 -0
  245. package/ts-code/lib-server/middleware/error-handler.ts +79 -0
  246. package/ts-code/lib-server/pkl-access.ts +46 -0
  247. package/ts-code/lib-server/resources/dns.ts +151 -0
  248. package/ts-code/lib-server/resources/mailerid-authorizer.ts +115 -0
  249. package/ts-code/lib-server/resources/mem-backed-sessions-factory.ts +132 -0
  250. package/ts-code/lib-server/resources/server-data-folders.ts +160 -0
  251. package/ts-code/lib-server/resources/server-key-for-pkl-challenge.ts +41 -0
  252. package/ts-code/lib-server/resources/sessions.ts +232 -0
  253. package/ts-code/lib-server/resources/user-files.ts +147 -0
  254. package/ts-code/lib-server/routes/pub-key-login/complete-exchange.ts +63 -0
  255. package/ts-code/lib-server/routes/pub-key-login/start-exchange.ts +189 -0
  256. package/ts-code/lib-server/routes/sessions/close.ts +27 -0
  257. package/ts-code/lib-server/routes/sessions/mid-auth.ts +77 -0
  258. package/ts-code/lib-server/routes/sessions/start.ts +116 -0
  259. package/ts-code/lib-server/web-sockets/app.ts +339 -0
  260. package/ts-code/lib-server/web-sockets/server-events.ts +63 -0
  261. package/ts-code/lib.ts +29 -0
  262. package/ts-code/locker/locker-app.ts +60 -0
  263. package/ts-code/locker/resources/lockers.ts +17 -0
  264. package/ts-code/locker/resources/sessions.ts +37 -0
  265. package/ts-code/locker/routes/create-locker.ts +47 -0
  266. package/ts-code/mailerId/mailerId-app.ts +107 -0
  267. package/ts-code/mailerId/resources/certifier.ts +181 -0
  268. package/ts-code/mailerId/resources/sessions.ts +44 -0
  269. package/ts-code/mailerId/resources/users.ts +88 -0
  270. package/ts-code/mailerId/routes/certify.ts +68 -0
  271. package/ts-code/main.ts +304 -0
  272. package/ts-code/mock/dns.ts +106 -0
  273. package/ts-code/mock/mock-as-child-proc.ts +130 -0
  274. package/ts-code/mock/node-child-ipc.ts +69 -0
  275. package/ts-code/mock/run-in-proc.ts +111 -0
  276. package/ts-code/mock/tls-options.ts +73 -0
  277. package/ts-code/services.ts +138 -0
  278. package/ts-code/signup/resources/users.ts +429 -0
  279. package/ts-code/signup/routes/add.ts +65 -0
  280. package/ts-code/signup/routes/get-available-addresses.ts +49 -0
  281. package/ts-code/signup/routes/get-available-domains.ts +45 -0
  282. package/ts-code/signup/signup-app.ts +54 -0
  283. package/ts-code/signup/signup-tokens.ts +148 -0
  284. package/ts-code/tests/admin-proto/signup.ts +277 -0
  285. package/ts-code/tests/jasmine.ts +37 -0
  286. package/ts-code/tests/libs-for-tests/3nstorage.ts +144 -0
  287. package/ts-code/tests/libs-for-tests/asmail.ts +220 -0
  288. package/ts-code/tests/libs-for-tests/assert.ts +22 -0
  289. package/ts-code/tests/libs-for-tests/async-jasmine.ts +89 -0
  290. package/ts-code/tests/libs-for-tests/bytes-equal.ts +25 -0
  291. package/ts-code/tests/libs-for-tests/json-copy.ts +38 -0
  292. package/ts-code/tests/libs-for-tests/json-equal.ts +55 -0
  293. package/ts-code/tests/libs-for-tests/mailerid.ts +123 -0
  294. package/ts-code/tests/libs-for-tests/pkl.ts +127 -0
  295. package/ts-code/tests/libs-for-tests/server-components/3nstorage.ts +206 -0
  296. package/ts-code/tests/libs-for-tests/server-components/admin.ts +49 -0
  297. package/ts-code/tests/libs-for-tests/server-components/asmail.ts +152 -0
  298. package/ts-code/tests/libs-for-tests/server-components/component.ts +90 -0
  299. package/ts-code/tests/libs-for-tests/server-components/mailerid.ts +114 -0
  300. package/ts-code/tests/libs-for-tests/server-runner.ts +82 -0
  301. package/ts-code/tests/libs-for-tests/spec-assembly.ts +60 -0
  302. package/ts-code/tests/libs-for-tests/ws-utils.ts +61 -0
  303. package/ts-code/tests/libs-for-tests/xhr-utils.ts +179 -0
  304. package/ts-code/tests/protocols/3nstorage/owner/specs/archive-obj-ver.ts +100 -0
  305. package/ts-code/tests/protocols/3nstorage/owner/specs/archive-root-ver.ts +91 -0
  306. package/ts-code/tests/protocols/3nstorage/owner/specs/delete-archive-obj-ver.ts +99 -0
  307. package/ts-code/tests/protocols/3nstorage/owner/specs/delete-archive-root-ver.ts +90 -0
  308. package/ts-code/tests/protocols/3nstorage/owner/specs/delete-obj.ts +84 -0
  309. package/ts-code/tests/protocols/3nstorage/owner/specs/events.ts +125 -0
  310. package/ts-code/tests/protocols/3nstorage/owner/specs/get-current-obj.ts +298 -0
  311. package/ts-code/tests/protocols/3nstorage/owner/specs/get-current-root.ts +290 -0
  312. package/ts-code/tests/protocols/3nstorage/owner/specs/get-obj-status.ts +88 -0
  313. package/ts-code/tests/protocols/3nstorage/owner/specs/get-root-status.ts +80 -0
  314. package/ts-code/tests/protocols/3nstorage/owner/specs/put-current-obj.ts +366 -0
  315. package/ts-code/tests/protocols/3nstorage/owner/specs/put-current-root.ts +329 -0
  316. package/ts-code/tests/protocols/3nstorage/owner/specs/trans-cancel-root.ts +86 -0
  317. package/ts-code/tests/protocols/3nstorage/owner/specs/trans-cancel.ts +86 -0
  318. package/ts-code/tests/protocols/3nstorage/owner/test-utils.ts +72 -0
  319. package/ts-code/tests/protocols/3nstorage/owner.ts +198 -0
  320. package/ts-code/tests/protocols/asmail/config.ts +172 -0
  321. package/ts-code/tests/protocols/asmail/delivery/specs/finalize-delivery.ts +69 -0
  322. package/ts-code/tests/protocols/asmail/delivery/specs/provide-recipient-pubkey.ts +88 -0
  323. package/ts-code/tests/protocols/asmail/delivery/specs/put-metadata.ts +102 -0
  324. package/ts-code/tests/protocols/asmail/delivery/specs/put-obj.ts +156 -0
  325. package/ts-code/tests/protocols/asmail/delivery/specs/restart-session.ts +97 -0
  326. package/ts-code/tests/protocols/asmail/delivery/specs/start-session.ts +79 -0
  327. package/ts-code/tests/protocols/asmail/delivery/test-utils.ts +64 -0
  328. package/ts-code/tests/protocols/asmail/delivery.ts +56 -0
  329. package/ts-code/tests/protocols/asmail/retrieval/specs/events.ts +78 -0
  330. package/ts-code/tests/protocols/asmail/retrieval/specs/get-message-meta.ts +80 -0
  331. package/ts-code/tests/protocols/asmail/retrieval/specs/get-message-obj.ts +197 -0
  332. package/ts-code/tests/protocols/asmail/retrieval/specs/list-messages.ts +110 -0
  333. package/ts-code/tests/protocols/asmail/retrieval/specs/remove-message.ts +74 -0
  334. package/ts-code/tests/protocols/asmail/retrieval/test-utils.ts +60 -0
  335. package/ts-code/tests/protocols/asmail/retrieval.ts +115 -0
  336. package/ts-code/tests/protocols/mailerid.ts +271 -0
  337. package/ts-code/tests/shared-checks/check-mid-login.ts +164 -0
  338. package/ts-code/tests/shared-checks/requests.ts +135 -0
  339. package/ts-code/tsconfig.json +11 -0
  340. package/ts-code/web3n.d.ts +1068 -0
@@ -0,0 +1,49 @@
1
+ /*
2
+ Copyright (C) 2015 - 2016, 2025 3NSoft Inc.
3
+
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU General Public License as published by the Free Software
6
+ Foundation, either version 3 of the License, or (at your option) any later
7
+ version.
8
+
9
+ This program is distributed in the hope that it will be useful, but
10
+ WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ See the GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License along with
15
+ this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ import { RequestHandler } from 'express';
19
+ import { GetParam, SC as recipSC } from '../../resources/recipients';
20
+ import { PARAM_SC, ERR_SC } from '../../../lib-common/service-api/asmail/config';
21
+ import { Request } from '../../resources/sessions';
22
+ import { InboxParams } from '../../resources/inbox';
23
+
24
+ export function getParam<P extends keyof InboxParams>(
25
+ paramGetter: GetParam<P>
26
+ ): RequestHandler {
27
+ return async (req: Request, res, next) => {
28
+
29
+ const session = req.session;
30
+ const userId = session.params.userId;
31
+
32
+ try{
33
+ const value = await paramGetter(userId);
34
+ res.status(PARAM_SC.ok).json(value);
35
+ } catch (err) {
36
+ if (err === recipSC.USER_UNKNOWN) {
37
+ res.status(ERR_SC.server).send(
38
+ "Recipient disappeared from the system."
39
+ );
40
+ session.close();
41
+ } else {
42
+ next(err);
43
+ }
44
+ }
45
+
46
+ };
47
+ }
48
+
49
+ Object.freeze(exports);
@@ -0,0 +1,49 @@
1
+ /*
2
+ Copyright (C) 2015 - 2016, 2025 - 2026 3NSoft Inc.
3
+
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU General Public License as published by the Free Software
6
+ Foundation, either version 3 of the License, or (at your option) any later
7
+ version.
8
+
9
+ This program is distributed in the hope that it will be useful, but
10
+ WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ See the GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License along with
15
+ this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ import { RequestHandler } from 'express';
19
+ import { SetParam, SC as recipSC } from '../../resources/recipients';
20
+ import { PARAM_SC, ERR_SC } from '../../../lib-common/service-api/asmail/config';
21
+ import { Request } from '../../resources/sessions';
22
+ import { InboxParams } from '../../resources/inbox';
23
+
24
+ export function setParam<P extends keyof InboxParams>(paramSetter: SetParam<P>): RequestHandler {
25
+ return async (req: Request, res, next) => {
26
+
27
+ const session = req.session;
28
+ const userId = session.params.userId;
29
+ const pValue: InboxParams[P] = req.body;
30
+
31
+ try{
32
+ const valChanged = await paramSetter(userId, pValue)
33
+ if (valChanged) {
34
+ res.status(PARAM_SC.ok).send();
35
+ } else {
36
+ res.status(ERR_SC.malformed).send('Malformed parameter value.');
37
+ }
38
+ } catch (err) {
39
+ if (err === recipSC.USER_UNKNOWN) {
40
+ res.status(ERR_SC.server).send("Recipient disappeared from the system.");
41
+ session.close();
42
+ } else {
43
+ next(err);
44
+ }
45
+
46
+ }
47
+
48
+ };
49
+ }
@@ -0,0 +1,51 @@
1
+ /*
2
+ Copyright (C) 2015 - 2016, 2025 - 2026 3NSoft Inc.
3
+
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU General Public License as published by the Free Software
6
+ Foundation, either version 3 of the License, or (at your option) any later
7
+ version.
8
+
9
+ This program is distributed in the hope that it will be useful, but
10
+ WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ See the GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License along with
15
+ this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ import { RequestHandler } from 'express';
19
+ import { SC as recipSC, MsgDelivery } from '../../resources/recipients';
20
+ import { Request } from '../../resources/delivery-sessions';
21
+ import { completion as api, ERR_SC } from '../../../lib-common/service-api/asmail/delivery';
22
+ import { replyWithErr } from '../../resources/utils';
23
+
24
+ export function finalizeDelivery(finDelivFunc: MsgDelivery['finalizeDelivery']): RequestHandler {
25
+ return async (req: Request, res, next) => {
26
+ const session = req.session;
27
+ const recipient = session.params.recipient;
28
+ const msgId = session.params.msgId;
29
+
30
+ try {
31
+ await finDelivFunc(recipient, msgId);
32
+ session.close();
33
+ res.status(api.SC.ok).send();
34
+ } catch (err) {
35
+ if ('string' !== typeof err) {
36
+ next(err);
37
+ } else if (err === recipSC.USER_UNKNOWN) {
38
+ session.close();
39
+ replyWithErr(ERR_SC.server, "Recipient disappeared from the system.", res);
40
+ } else if (err === recipSC.MSG_UNKNOWN) {
41
+ session.close();
42
+ replyWithErr(ERR_SC.server, "Message disappeared from the system.", res);
43
+ } else {
44
+ next(new Error("Unhandled storage error code: "+err));
45
+ }
46
+ }
47
+
48
+ };
49
+ }
50
+
51
+ Object.freeze(exports);
@@ -0,0 +1,118 @@
1
+ /*
2
+ Copyright (C) 2015 - 2017, 2025 - 2026 3NSoft Inc.
3
+
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU General Public License as published by the Free Software
6
+ Foundation, either version 3 of the License, or (at your option) any later
7
+ version.
8
+
9
+ This program is distributed in the hope that it will be useful, but
10
+ WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ See the GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License along with
15
+ this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ import { RequestHandler, Response } from 'express';
19
+ import { SC as recipSC, MsgDelivery } from '../../resources/recipients';
20
+ import { preFlight as api, ERR_SC } from '../../../lib-common/service-api/asmail/delivery';
21
+ import { Request } from '../../resources/delivery-sessions';
22
+ import { Redirect } from './start-session';
23
+ import { checkAndTransformAddress } from '../../../lib-common/canonical-address';
24
+ import { replyWithErr } from '../../resources/utils';
25
+
26
+ /**
27
+ * This creates a pre-flight route handler.
28
+ * @param allowedMsgSizeFunc is a function returning promises, that may resolve to
29
+ * (1) undefined, if recipient is unknown,
30
+ * (2) zero (0), if leaving mail is forbidden,
31
+ * (3) greater than zero maximum message length, and
32
+ * (4) -1, if mail cannot be accepted due to full mail box.
33
+ * @param redirectFunc is an optional function that returns a promise,
34
+ * resolvable to
35
+ * (1) string with URI for ASMail service, which is serving given recipient,
36
+ * (2) undefined, if it is this server should service given recipient.
37
+ */
38
+ export function preFlight(
39
+ allowedMsgSizeFunc: MsgDelivery['allowedMaxMsgSize'], redirectFunc?: Redirect
40
+ ): RequestHandler {
41
+
42
+ async function serveRequestHere(
43
+ recipient: string, sender: string|undefined,
44
+ invitation: string|undefined, res: Response
45
+ ): Promise<void> {
46
+ const msgSize = await allowedMsgSizeFunc(recipient, sender, invitation);
47
+ if (msgSize > 0) {
48
+ res.status(api.SC.ok).json({
49
+ maxMsgLength: msgSize
50
+ } as api.Reply);
51
+ } else if (msgSize === 0) {
52
+ replyWithErr(
53
+ api.SC.senderNotAllowed,
54
+ `${sender ? sender : "Anonymous sender "} is not allowed to leave mail for ${recipient}`, res
55
+ );
56
+ } else if (msgSize === -1) {
57
+ replyWithErr(api.SC.inboxFull, `Mail box for ${recipient} is full.`, res);
58
+ } else {
59
+ throw new Error(`Unrecognized code ${msgSize} for message size limits.`);
60
+ }
61
+ }
62
+
63
+ return async (req: Request, res, next) => {
64
+
65
+ const rb: api.Request = req.body;
66
+ const recipient = checkAndTransformAddress(rb.recipient);
67
+ let sender = rb.sender;
68
+ const invitation = rb.invitation;
69
+ const session = req.session;
70
+
71
+ // already existing session indicates repeated call, which should be bounced off
72
+ if (session) {
73
+ return replyWithErr(ERR_SC.duplicateReq, "This protocol request has already been served.", res);
74
+ }
75
+
76
+ // missing recipient makes a bad request
77
+ if (!recipient) {
78
+ return replyWithErr(ERR_SC.malformed, "Recipient is either missing in the request, or is malformed", res);
79
+ }
80
+
81
+ // if sender is given, we canonicalize the address
82
+ if (sender) {
83
+ sender = checkAndTransformAddress(sender);
84
+ if (!sender) {
85
+ return replyWithErr(ERR_SC.malformed, "Sender field is malformed", res);
86
+ }
87
+ }
88
+
89
+ // check invitation field
90
+ if ((invitation !== undefined) && (typeof invitation !== 'string')) {
91
+ return replyWithErr(ERR_SC.malformed, "Inviation field is malformed", res);
92
+ }
93
+
94
+ try {
95
+ if (redirectFunc) {
96
+ const redirectTo = await redirectFunc(recipient);
97
+ if (redirectTo) {
98
+ res.status(api.SC.redirect).json(<api.RedirectReply> {
99
+ redirect: redirectTo
100
+ });
101
+ } else {
102
+ await serveRequestHere(recipient, sender, invitation, res);
103
+ }
104
+ } else {
105
+ await serveRequestHere(recipient, sender, invitation, res);
106
+ }
107
+ } catch (err) {
108
+ if (err === recipSC.USER_UNKNOWN) {
109
+ replyWithErr(api.SC.unknownRecipient, `Recipient ${recipient} is unknown.`, res);
110
+ } else {
111
+ next(err);
112
+ }
113
+ }
114
+
115
+ };
116
+ }
117
+
118
+ Object.freeze(exports);
@@ -0,0 +1,58 @@
1
+ /*
2
+ Copyright (C) 2015 - 2016, 2025 - 2026 3NSoft Inc.
3
+
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU General Public License as published by the Free Software
6
+ Foundation, either version 3 of the License, or (at your option) any later
7
+ version.
8
+
9
+ This program is distributed in the hope that it will be useful, but
10
+ WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ See the GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License along with
15
+ this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ import { RequestHandler } from 'express';
19
+ import { SC as recipSC, MsgDelivery } from '../../resources/recipients';
20
+ import { initPubKey as api, ERR_SC } from '../../../lib-common/service-api/asmail/delivery';
21
+ import { Request } from '../../resources/delivery-sessions';
22
+ import { replyWithErr } from '../../resources/utils';
23
+
24
+ /**
25
+ * This creates a get-init-pub-key route handler.
26
+ * @param pkeyProvidingFunc is a function that provides recipient's public key
27
+ * for use in this communication.
28
+ */
29
+ export function getRecipientPubKey(
30
+ pkeyProvidingFunc: MsgDelivery['getPubKey']
31
+ ): RequestHandler {
32
+ return async (req: Request, res, next) => {
33
+
34
+ const session = req.session;
35
+
36
+ try{
37
+ const certs = await pkeyProvidingFunc(session.params.recipient);
38
+ if (certs) {
39
+ res.status(api.SC.ok).json(certs);
40
+ } else {
41
+ replyWithErr(api.SC.pkeyNotRegistered, 'No public key registered for the recipient.', res);
42
+ session.close();
43
+ }
44
+ } catch (err) {
45
+ if (typeof err !== "string") {
46
+ next(err);
47
+ } else if (err === recipSC.USER_UNKNOWN) {
48
+ replyWithErr(ERR_SC.server, "Recipient disappeared from the system.", res);
49
+ session.close();
50
+ } else {
51
+ next(new Error("Unhandled storage error code: "+err));
52
+ }
53
+ }
54
+
55
+ };
56
+ }
57
+
58
+ Object.freeze(exports);
@@ -0,0 +1,85 @@
1
+ /*
2
+ Copyright (C) 2015 - 2016, 2025 - 2026 3NSoft Inc.
3
+
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU General Public License as published by the Free Software
6
+ Foundation, either version 3 of the License, or (at your option) any later
7
+ version.
8
+
9
+ This program is distributed in the hope that it will be useful, but
10
+ WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ See the GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License along with
15
+ this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ import { RequestHandler } from 'express';
19
+ import { SC as recipSC, MsgDelivery } from '../../resources/recipients';
20
+ import { msgMeta as api, ERR_SC } from '../../../lib-common/service-api/asmail/delivery';
21
+ import * as confUtil from '../../../lib-server/conf-util';
22
+ import { Request } from '../../resources/delivery-sessions';
23
+ import { base64urlSafe } from '../../../lib-common/buffer-utils';
24
+ import { replyWithErr } from '../../resources/utils';
25
+
26
+ function findProblemWithObjIds(ids: string[]): string|undefined {
27
+ if (!Array.isArray(ids)) {
28
+ return "Object ids are missing.";
29
+ }
30
+ const checkedIds = new Set<string>();
31
+ for (const objId of ids) {
32
+ if (checkedIds.has(objId)) {
33
+ return "Duplication of object ids.";
34
+ }
35
+ if (!base64urlSafe.allCharsFromAlphabet(objId!)) {
36
+ return "Object id is invalid.";
37
+ }
38
+ checkedIds.add(objId);
39
+ }
40
+ return;
41
+ }
42
+
43
+ export function saveMetadata(
44
+ setMsgStorageFunc: MsgDelivery['setMsgStorage'], maxChunk: string|number
45
+ ): RequestHandler {
46
+
47
+ const maxChunkSize = confUtil.stringToNumOfBytes(maxChunk);
48
+
49
+ return async (req: Request, res, next) => {
50
+ const session = req.session;
51
+ if (session.params.msgId) {
52
+ return replyWithErr(ERR_SC.duplicateReq, "This protocol request has already been served.", res);
53
+ }
54
+
55
+ const recipient = session.params.recipient;
56
+ const msgMeta: api.Request = req.body;
57
+
58
+ const objIds = msgMeta.objIds;
59
+ const errWithWithObjIds = findProblemWithObjIds(objIds);
60
+ if (errWithWithObjIds) {
61
+ return replyWithErr(ERR_SC.malformed, errWithWithObjIds, res);
62
+ }
63
+
64
+ try {
65
+ const msgId = await setMsgStorageFunc(
66
+ recipient, msgMeta, session.params.sender, session.params.invite, session.params.maxMsgLength
67
+ );
68
+ session.params.msgId = msgId;
69
+ res.status(api.SC.ok).json({
70
+ msgId,
71
+ maxChunkSize
72
+ } as api.Reply);
73
+ } catch (err) {
74
+ if ("string" !== typeof err) {
75
+ next(err);
76
+ } else if (err === recipSC.USER_UNKNOWN) {
77
+ replyWithErr(ERR_SC.server, "Recipient disappeared from the system.", res);
78
+ session.close();
79
+ }
80
+ }
81
+
82
+ };
83
+ }
84
+
85
+ Object.freeze(exports);
@@ -0,0 +1,152 @@
1
+ /*
2
+ Copyright (C) 2015 - 2017, 2019 - 2020, 2025 - 2026 3NSoft Inc.
3
+
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU General Public License as published by the Free Software
6
+ Foundation, either version 3 of the License, or (at your option) any later
7
+ version.
8
+
9
+ This program is distributed in the hope that it will be useful, but
10
+ WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ See the GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License along with
15
+ this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ import { RequestHandler, Response } from 'express';
19
+ import { SC as recipSC, MsgDelivery, BIN_TYPE } from '../../resources/recipients';
20
+ import { msgObj as api, ERR_SC, HTTP_HEADER, PutObjFirstQueryOpts, PutObjSecondQueryOpts } from '../../../lib-common/service-api/asmail/delivery';
21
+ import * as confUtil from '../../../lib-server/conf-util';
22
+ import { Request } from '../../resources/delivery-sessions';
23
+ import { getObjIdFromParams, replyWithErr } from '../../resources/utils';
24
+
25
+ export function saveMsgObj(saveObjFunc: MsgDelivery['saveObj'], chunkLimit: string|number): RequestHandler {
26
+
27
+ const maxChunkSize = confUtil.stringToNumOfBytes(chunkLimit);
28
+
29
+ return async (req: Request, res, next) => {
30
+
31
+ if (!req.is(BIN_TYPE)) {
32
+ return replyWithErr(ERR_SC.wrongContentType, `Content-Type must be ${BIN_TYPE} for this call.`, res, req);
33
+ }
34
+
35
+ const session = req.session;
36
+ const recipient = session.params.recipient;
37
+ const msgId = session.params.msgId;
38
+
39
+ if (!msgId) {
40
+ return replyWithErr(ERR_SC.earlyReq, "Metadata has not been sent, yet.", res, req);
41
+ }
42
+
43
+ const { objId, objIdParseErr } = getObjIdFromParams(req);
44
+ if (objIdParseErr) {
45
+ return replyWithErr(ERR_SC.malformed, objIdParseErr, res);
46
+ }
47
+
48
+ // get and check Content-Length, implicitly sending replies for bad length
49
+ let len = getContentLenOrSendError(req, res, maxChunkSize);
50
+ if (len === undefined) {
51
+ return;
52
+ }
53
+
54
+ // extract and check query parameters
55
+ const opts = extractQueryOptions(req);
56
+ if (!opts) {
57
+ return replyWithErr(ERR_SC.malformed, "Bad query parameters", res, req);
58
+ }
59
+
60
+ if (opts.fstReq) {
61
+ // check options versus chunk length
62
+ if (opts.fstReq.header > len) {
63
+ return replyWithErr(ERR_SC.malformed, "Bad query parameters", res, req);
64
+ }
65
+ } else if (opts.sndReq) {
66
+ // check options versus chunk length
67
+ if ((len === 0) && !opts.sndReq.last) {
68
+ return replyWithErr(ERR_SC.malformed, "No segment bytes", res, req);
69
+ }
70
+ } else {
71
+ return next(new Error(`This place should not be reachable`));
72
+ }
73
+
74
+ // ensure that it is ok space-wise to save additional bytes
75
+ const allowedSpace = (session.params.maxMsgLength - session.params.currentMsgLength);
76
+ if (len <= allowedSpace) {
77
+ session.params.currentMsgLength += len;
78
+ } else {
79
+ return replyWithErr(ERR_SC.contentTooLong, "This request goes over the message limit.", res, req);
80
+ }
81
+
82
+ try {
83
+ await saveObjFunc(recipient, msgId, objId, opts.fstReq, opts.sndReq, len, req);
84
+ res.status(api.SC.ok).send();
85
+ } catch (err) {
86
+ session.params.currentMsgLength -= len;
87
+ if ("string" !== typeof err) {
88
+ next(err);
89
+ } else if (err === recipSC.USER_UNKNOWN) {
90
+ replyWithErr(ERR_SC.server, "Recipient disappeared from the system.", res);
91
+ session.close();
92
+ } else if (err === recipSC.OBJ_EXIST) {
93
+ replyWithErr(api.SC.objAlreadyExists, `Object ${objId} already exists.`, res);
94
+ } else if (err === recipSC.MSG_UNKNOWN) {
95
+ replyWithErr(ERR_SC.server, "Message disappeared from the system.", res);
96
+ session.close();
97
+ } else if (err === recipSC.OBJ_UNKNOWN) {
98
+ replyWithErr(api.SC.unknownObj, `Object ${objId} is unknown.`, res);
99
+ } else if (err === recipSC.WRONG_OBJ_STATE) {
100
+ replyWithErr(ERR_SC.malformed, `Object ${objId} is not in a different state.`, res);
101
+ } else if (err === recipSC.OBJ_FILE_INCOMPLETE) {
102
+ replyWithErr(ERR_SC.objIncomplete, `Object ${objId} is not complete.`, res);
103
+ } else {
104
+ next(new Error(`Unhandled storage error code: ${err}`));
105
+ }
106
+ }
107
+ };
108
+ }
109
+
110
+ function extractQueryOptions(req: Request): undefined|{
111
+ fstReq?: PutObjFirstQueryOpts; sndReq?: PutObjSecondQueryOpts;
112
+ } {
113
+ if ((req.query as any as PutObjFirstQueryOpts).header) {
114
+ // this is the first request
115
+ // query fields are string or undefined, yet, type info helps the show
116
+ const query = req.query as any as PutObjFirstQueryOpts;
117
+
118
+ const header = parseInt(query.header as any);
119
+ if (isNaN(header) || (header < 1)) { return; }
120
+
121
+ const last = ((query.last as any) === 'true');
122
+
123
+ return { fstReq: { header, last } };
124
+
125
+ } else {
126
+ // this is the second (not first) request
127
+ // query fields are string or undefined, yet, type info helps the show
128
+ const query = req.query as any as PutObjSecondQueryOpts;
129
+
130
+ const last = ((query.last as any) === 'true');
131
+
132
+ const ofs = parseInt(query.ofs as any);
133
+ if (isNaN(ofs) || (ofs < 0)) { return; }
134
+
135
+ return { sndReq: { ofs, last } };
136
+
137
+ }
138
+ }
139
+
140
+ function getContentLenOrSendError(req: Request, res: Response, maxChunkSize: number): number|undefined {
141
+ const contentLength = parseInt(req.get(HTTP_HEADER.contentLength)!);
142
+ if (isNaN(contentLength)) {
143
+ replyWithErr(ERR_SC.contentLenMissing, "Content-Length header is required with proper number.", res, req);
144
+ } else if (contentLength > maxChunkSize) {
145
+ replyWithErr(ERR_SC.contentTooLong, "Request body is too long.", res, req);
146
+ } else {
147
+ return contentLength;
148
+ }
149
+ return;
150
+ }
151
+
152
+ Object.freeze(exports);
@@ -0,0 +1,117 @@
1
+ /*
2
+ Copyright (C) 2017, 2025 - 2026 3NSoft Inc.
3
+
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU General Public License as published by the Free Software
6
+ Foundation, either version 3 of the License, or (at your option) any later
7
+ version.
8
+
9
+ This program is distributed in the hope that it will be useful, but
10
+ WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ See the GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License along with
15
+ this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ import { RequestHandler, Response } from 'express';
19
+ import { SC as recipSC, MsgDelivery } from '../../resources/recipients';
20
+ import { sessionRestart as api, ERR_SC } from '../../../lib-common/service-api/asmail/delivery';
21
+ import { Request, GenerateSession, GetSessionForMsg } from '../../resources/delivery-sessions';
22
+ import { Redirect } from './start-session';
23
+ import { checkAndTransformAddress } from '../../../lib-common/canonical-address';
24
+ import * as confUtil from '../../../lib-server/conf-util';
25
+ import { replyWithErr } from '../../resources/utils';
26
+
27
+ /**
28
+ * This creates a session restart route handler.
29
+ * @param sessionGenFunc is a promise returning function that generates new session objects.
30
+ * @param sessionForMsgFunc is a function that promises existing session for a known message in delivery.
31
+ * @param incompleteMsgFunc is a function that promises parameters of a message that is still in delivery.
32
+ * @param redirectFunc is an optional function that returns a promise, resolvable to
33
+ * (1) string with URI for ASMail service, which is serving given recipient,
34
+ * (2) undefined, if it is this server should service given recipient.
35
+ */
36
+ export function restartSession(
37
+ sessionGenFunc: GenerateSession,sessionForMsgFunc: GetSessionForMsg,
38
+ incompleteMsgFunc: MsgDelivery['incompleteMsgDeliveryParams'],
39
+ maxChunk: string|number, redirectFunc?: Redirect
40
+ ): RequestHandler {
41
+
42
+ const maxChunkSize = confUtil.stringToNumOfBytes(maxChunk);
43
+
44
+ async function serveRequestHere(
45
+ recipient: string, msgId: string, res: Response
46
+ ): Promise<void> {
47
+ let session = await sessionForMsgFunc(recipient, msgId);
48
+ if (!session) {
49
+ const msgParams = await incompleteMsgFunc(recipient, msgId);
50
+ session = await sessionGenFunc();
51
+ session.isAuthorized = true;
52
+ session.params.recipient = recipient;
53
+ session.params.msgId = msgId;
54
+ session.params.currentMsgLength = msgParams.currentMsgLength;
55
+ session.params.maxMsgLength = msgParams.maxMsgLength;
56
+ }
57
+ res.status(api.SC.ok).json( <api.Reply> {
58
+ maxMsgLength: session.params.maxMsgLength,
59
+ sessionId: session.id,
60
+ maxChunkSize
61
+ });
62
+ }
63
+
64
+ return async (req: Request, res, next) => {
65
+
66
+ const rb: api.Request = req.body;
67
+ const recipient = checkAndTransformAddress(rb.recipient);
68
+ const msgId = rb.msgId;
69
+ const session = req.session;
70
+
71
+ // session is opened, and is even mentioned in a header
72
+ if (session) {
73
+ res.status(api.SC.ok).json( <api.Reply> {
74
+ maxMsgLength: session.params.maxMsgLength,
75
+ sessionId: session.id,
76
+ maxChunkSize
77
+ });
78
+ return;
79
+ }
80
+
81
+ // missing recipient makes a bad request
82
+ if (!recipient) {
83
+ return replyWithErr(ERR_SC.malformed, "Recipient is either missing in the request, or is malformed", res);
84
+ }
85
+
86
+ // check message id
87
+ if (typeof msgId !== 'string') {
88
+ return replyWithErr(ERR_SC.malformed, "Message id is either missing, or is malformed", res);
89
+ }
90
+
91
+ try {
92
+ if (redirectFunc) {
93
+ const redirectTo = await redirectFunc(recipient);
94
+ if (redirectTo) {
95
+ res.status(api.SC.redirect).json(<api.RedirectReply> {
96
+ redirect: redirectTo
97
+ });
98
+ } else {
99
+ await serveRequestHere(recipient, msgId, res);
100
+ }
101
+ } else {
102
+ await serveRequestHere(recipient, msgId, res);
103
+ }
104
+ } catch (err) {
105
+ if (err === recipSC.USER_UNKNOWN) {
106
+ replyWithErr(api.SC.unknownRecipient, `Recipient ${recipient} is unknown.`, res);
107
+ } else if (err === recipSC.MSG_UNKNOWN) {
108
+ replyWithErr(api.SC.unknownMsg, `Recipient ${recipient} is unknown.`, res);
109
+ } else {
110
+ next(err);
111
+ }
112
+ }
113
+
114
+ };
115
+ }
116
+
117
+ Object.freeze(exports);