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.
- package/.gitlab-ci-linux.yml +50 -0
- package/.gitlab-ci-mac.yml +29 -0
- package/.gitlab-ci-windows.yml +29 -0
- package/.gitlab-ci.yml +63 -0
- package/build/3nstorage/resources/store.d.ts +2 -2
- package/build/3nstorage/resources/store.js +1 -1
- package/build/3nstorage/resources/users.d.ts +3 -3
- package/build/3nstorage/resources/users.js +1 -1
- package/build/3nstorage/resources/utils.d.ts +6 -0
- package/build/3nstorage/resources/utils.js +41 -0
- package/build/3nstorage/routes/owner/archive-obj-version.js +8 -10
- package/build/3nstorage/routes/owner/cancel-trans.js +5 -4
- package/build/3nstorage/routes/owner/delete-obj.js +7 -8
- package/build/3nstorage/routes/owner/get-archived-obj-ver.js +11 -13
- package/build/3nstorage/routes/owner/get-current-obj.js +7 -6
- package/build/3nstorage/routes/owner/get-obj-status.js +8 -8
- package/build/3nstorage/routes/owner/put-current-obj.js +25 -55
- package/build/3nstorage/routes/owner/session-params.js +2 -0
- package/build/asmail/resources/utils.d.ts +6 -0
- package/build/asmail/resources/utils.js +36 -0
- package/build/asmail/routes/delivery/finalize-delivery.js +3 -2
- package/build/asmail/routes/delivery/pre-flight.js +9 -26
- package/build/asmail/routes/delivery/provide-recipient-pubkey.js +4 -3
- package/build/asmail/routes/delivery/put-metadata.js +13 -21
- package/build/asmail/routes/delivery/put-obj.js +19 -25
- package/build/asmail/routes/delivery/restart-session.d.ts +4 -8
- package/build/asmail/routes/delivery/restart-session.js +10 -23
- package/build/asmail/routes/delivery/sender-authorization.js +5 -5
- package/build/asmail/routes/delivery/start-session.js +9 -24
- package/build/asmail/routes/retrieval/get-message-meta.js +4 -7
- package/build/asmail/routes/retrieval/get-message-obj.js +10 -7
- package/build/asmail/routes/retrieval/list-messages.js +4 -4
- package/build/asmail/routes/retrieval/remove-message.js +3 -2
- package/build/mock/tls-options.js +46 -44
- package/build/tests/admin-proto/signup.d.ts +1 -0
- package/build/tests/admin-proto/signup.js +235 -0
- package/build/tests/jasmine.d.ts +1 -0
- package/build/tests/jasmine.js +32 -0
- package/build/tests/libs-for-tests/3nstorage.d.ts +22 -0
- package/build/tests/libs-for-tests/3nstorage.js +123 -0
- package/build/tests/libs-for-tests/asmail.d.ts +22 -0
- package/build/tests/libs-for-tests/asmail.js +179 -0
- package/build/tests/libs-for-tests/assert.d.ts +1 -0
- package/build/tests/libs-for-tests/assert.js +26 -0
- package/build/tests/libs-for-tests/async-jasmine.d.ts +7 -0
- package/build/tests/libs-for-tests/async-jasmine.js +77 -0
- package/build/tests/libs-for-tests/bytes-equal.d.ts +1 -0
- package/build/tests/libs-for-tests/bytes-equal.js +34 -0
- package/build/tests/libs-for-tests/json-copy.d.ts +1 -0
- package/build/tests/libs-for-tests/json-copy.js +45 -0
- package/build/tests/libs-for-tests/json-equal.d.ts +4 -0
- package/build/tests/libs-for-tests/json-equal.js +67 -0
- package/build/tests/libs-for-tests/mailerid.d.ts +13 -0
- package/build/tests/libs-for-tests/mailerid.js +114 -0
- package/build/tests/libs-for-tests/pkl.d.ts +28 -0
- package/build/tests/libs-for-tests/pkl.js +89 -0
- package/build/tests/libs-for-tests/server-components/3nstorage.d.ts +20 -0
- package/build/tests/libs-for-tests/server-components/3nstorage.js +200 -0
- package/build/tests/libs-for-tests/server-components/admin.d.ts +6 -0
- package/build/tests/libs-for-tests/server-components/admin.js +43 -0
- package/build/tests/libs-for-tests/server-components/asmail.d.ts +16 -0
- package/build/tests/libs-for-tests/server-components/asmail.js +143 -0
- package/build/tests/libs-for-tests/server-components/component.d.ts +13 -0
- package/build/tests/libs-for-tests/server-components/component.js +77 -0
- package/build/tests/libs-for-tests/server-components/mailerid.d.ts +10 -0
- package/build/tests/libs-for-tests/server-components/mailerid.js +103 -0
- package/build/tests/libs-for-tests/server-runner.d.ts +15 -0
- package/build/tests/libs-for-tests/server-runner.js +69 -0
- package/build/tests/libs-for-tests/spec-assembly.d.ts +6 -0
- package/build/tests/libs-for-tests/spec-assembly.js +55 -0
- package/build/tests/libs-for-tests/ws-utils.d.ts +3 -0
- package/build/tests/libs-for-tests/ws-utils.js +59 -0
- package/build/tests/libs-for-tests/xhr-utils.d.ts +61 -0
- package/build/tests/libs-for-tests/xhr-utils.js +154 -0
- package/build/tests/protocols/3nstorage/owner/specs/archive-obj-ver.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/archive-obj-ver.js +84 -0
- package/build/tests/protocols/3nstorage/owner/specs/archive-root-ver.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/archive-root-ver.js +78 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-archive-obj-ver.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-archive-obj-ver.js +83 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-archive-root-ver.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-archive-root-ver.js +77 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-obj.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-obj.js +75 -0
- package/build/tests/protocols/3nstorage/owner/specs/events.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/events.js +91 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-current-obj.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-current-obj.js +269 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-current-root.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-current-root.js +262 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-obj-status.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-obj-status.js +79 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-root-status.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-root-status.js +72 -0
- package/build/tests/protocols/3nstorage/owner/specs/put-current-obj.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/put-current-obj.js +287 -0
- package/build/tests/protocols/3nstorage/owner/specs/put-current-root.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/put-current-root.js +274 -0
- package/build/tests/protocols/3nstorage/owner/specs/trans-cancel-root.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/trans-cancel-root.js +73 -0
- package/build/tests/protocols/3nstorage/owner/specs/trans-cancel.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/trans-cancel.js +72 -0
- package/build/tests/protocols/3nstorage/owner/test-utils.d.ts +14 -0
- package/build/tests/protocols/3nstorage/owner/test-utils.js +54 -0
- package/build/tests/protocols/3nstorage/owner.d.ts +1 -0
- package/build/tests/protocols/3nstorage/owner.js +138 -0
- package/build/tests/protocols/asmail/config.d.ts +1 -0
- package/build/tests/protocols/asmail/config.js +117 -0
- package/build/tests/protocols/asmail/delivery/specs/finalize-delivery.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/finalize-delivery.js +60 -0
- package/build/tests/protocols/asmail/delivery/specs/provide-recipient-pubkey.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/provide-recipient-pubkey.js +68 -0
- package/build/tests/protocols/asmail/delivery/specs/put-metadata.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/put-metadata.js +83 -0
- package/build/tests/protocols/asmail/delivery/specs/put-obj.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/put-obj.js +123 -0
- package/build/tests/protocols/asmail/delivery/specs/restart-session.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/restart-session.js +79 -0
- package/build/tests/protocols/asmail/delivery/specs/start-session.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/start-session.js +64 -0
- package/build/tests/protocols/asmail/delivery/test-utils.d.ts +16 -0
- package/build/tests/protocols/asmail/delivery/test-utils.js +46 -0
- package/build/tests/protocols/asmail/delivery.d.ts +1 -0
- package/build/tests/protocols/asmail/delivery.js +46 -0
- package/build/tests/protocols/asmail/retrieval/specs/events.d.ts +2 -0
- package/build/tests/protocols/asmail/retrieval/specs/events.js +62 -0
- package/build/tests/protocols/asmail/retrieval/specs/get-message-meta.d.ts +2 -0
- package/build/tests/protocols/asmail/retrieval/specs/get-message-meta.js +70 -0
- package/build/tests/protocols/asmail/retrieval/specs/get-message-obj.d.ts +2 -0
- package/build/tests/protocols/asmail/retrieval/specs/get-message-obj.js +166 -0
- package/build/tests/protocols/asmail/retrieval/specs/list-messages.d.ts +2 -0
- package/build/tests/protocols/asmail/retrieval/specs/list-messages.js +96 -0
- package/build/tests/protocols/asmail/retrieval/specs/remove-message.d.ts +2 -0
- package/build/tests/protocols/asmail/retrieval/specs/remove-message.js +66 -0
- package/build/tests/protocols/asmail/retrieval/test-utils.d.ts +17 -0
- package/build/tests/protocols/asmail/retrieval/test-utils.js +46 -0
- package/build/tests/protocols/asmail/retrieval.d.ts +1 -0
- package/build/tests/protocols/asmail/retrieval.js +92 -0
- package/build/tests/protocols/mailerid.d.ts +1 -0
- package/build/tests/protocols/mailerid.js +210 -0
- package/build/tests/shared-checks/check-mid-login.d.ts +2 -0
- package/build/tests/shared-checks/check-mid-login.js +131 -0
- package/build/tests/shared-checks/requests.d.ts +20 -0
- package/build/tests/shared-checks/requests.js +123 -0
- package/package.json +1 -1
- package/packing/create-deb.sh +57 -0
- package/packing/deb/lib/systemd/system/3nweb.service +11 -0
- package/packing/deb/postinst +44 -0
- package/packing/deb/usr/share/doc/3nweb-server/conf-for-postinstall.yaml +19 -0
- package/packing/deb/usr/share/doc/3nweb-server/copyright +22 -0
- package/publish-task.sh +10 -0
- package/push-to-github.sh +105 -0
- package/ts-code/3nstorage/3nstorage-app.ts +99 -0
- package/ts-code/3nstorage/owner.ts +178 -0
- package/ts-code/3nstorage/resources/sessions.ts +37 -0
- package/ts-code/3nstorage/resources/store.ts +896 -0
- package/ts-code/3nstorage/resources/users.ts +258 -0
- package/ts-code/3nstorage/resources/utils.ts +45 -0
- package/ts-code/3nstorage/routes/owner/archive-obj-version.ts +71 -0
- package/ts-code/3nstorage/routes/owner/cancel-trans.ts +60 -0
- package/ts-code/3nstorage/routes/owner/delete-obj.ts +99 -0
- package/ts-code/3nstorage/routes/owner/get-archived-obj-ver.ts +109 -0
- package/ts-code/3nstorage/routes/owner/get-current-obj.ts +124 -0
- package/ts-code/3nstorage/routes/owner/get-obj-status.ts +55 -0
- package/ts-code/3nstorage/routes/owner/param-getter.ts +51 -0
- package/ts-code/3nstorage/routes/owner/param-setter.ts +50 -0
- package/ts-code/3nstorage/routes/owner/put-current-obj.ts +257 -0
- package/ts-code/3nstorage/routes/owner/session-params.ts +50 -0
- package/ts-code/3nstorage/shared.ts +43 -0
- package/ts-code/asmail/asmail-app.ts +91 -0
- package/ts-code/asmail/config.ts +96 -0
- package/ts-code/asmail/delivery.ts +94 -0
- package/ts-code/asmail/resources/delivery-sessions.ts +118 -0
- package/ts-code/asmail/resources/inbox.ts +696 -0
- package/ts-code/asmail/resources/recipients.ts +495 -0
- package/ts-code/asmail/resources/sessions.ts +37 -0
- package/ts-code/asmail/resources/utils.ts +41 -0
- package/ts-code/asmail/retrieval.ts +96 -0
- package/ts-code/asmail/routes/config/param-getter.ts +49 -0
- package/ts-code/asmail/routes/config/param-setter.ts +49 -0
- package/ts-code/asmail/routes/delivery/finalize-delivery.ts +51 -0
- package/ts-code/asmail/routes/delivery/pre-flight.ts +118 -0
- package/ts-code/asmail/routes/delivery/provide-recipient-pubkey.ts +58 -0
- package/ts-code/asmail/routes/delivery/put-metadata.ts +85 -0
- package/ts-code/asmail/routes/delivery/put-obj.ts +152 -0
- package/ts-code/asmail/routes/delivery/restart-session.ts +117 -0
- package/ts-code/asmail/routes/delivery/sender-authorization.ts +81 -0
- package/ts-code/asmail/routes/delivery/start-session.ts +136 -0
- package/ts-code/asmail/routes/retrieval/get-message-meta.ts +50 -0
- package/ts-code/asmail/routes/retrieval/get-message-obj.ts +106 -0
- package/ts-code/asmail/routes/retrieval/list-messages.ts +68 -0
- package/ts-code/asmail/routes/retrieval/remove-message.ts +48 -0
- package/ts-code/cli/index.ts +82 -0
- package/ts-code/cli/run-cmd.ts +81 -0
- package/ts-code/cli/show-sample-config.ts +78 -0
- package/ts-code/cli/signup-cmd.ts +229 -0
- package/ts-code/cli/user-cmd.ts +68 -0
- package/ts-code/cli/utils.ts +105 -0
- package/ts-code/config/default-confs.ts +22 -0
- package/ts-code/config/from-yaml.ts +35 -0
- package/ts-code/config/letsencrypt.ts +77 -0
- package/ts-code/config/signup.ts +137 -0
- package/ts-code/lib-common/admin-api/signup.ts +120 -0
- package/ts-code/lib-common/assert.ts +22 -0
- package/ts-code/lib-common/async-fs-node.ts +656 -0
- package/ts-code/lib-common/buffer-utils.ts +124 -0
- package/ts-code/lib-common/byte-streaming/common.ts +166 -0
- package/ts-code/lib-common/bytes-equal.ts +25 -0
- package/ts-code/lib-common/canonical-address.ts +92 -0
- package/ts-code/lib-common/exceptions/error.ts +44 -0
- package/ts-code/lib-common/exceptions/file.ts +84 -0
- package/ts-code/lib-common/exceptions/http.ts +69 -0
- package/ts-code/lib-common/ipc/generic-ipc.ts +750 -0
- package/ts-code/lib-common/ipc/ws-ipc.ts +117 -0
- package/ts-code/lib-common/json-equal.ts +55 -0
- package/ts-code/lib-common/json-utils.ts +130 -0
- package/ts-code/lib-common/jwkeys.ts +246 -0
- package/ts-code/lib-common/map-of-sets.ts +60 -0
- package/ts-code/lib-common/mid-sigs-NaCl-Ed.ts +677 -0
- package/ts-code/lib-common/objs-on-disk/file-layout.ts +480 -0
- package/ts-code/lib-common/objs-on-disk/obj-file.ts +325 -0
- package/ts-code/lib-common/objs-on-disk/utils.ts +201 -0
- package/ts-code/lib-common/objs-on-disk/v1-obj-file-format.ts +329 -0
- package/ts-code/lib-common/processes.ts +501 -0
- package/ts-code/lib-common/random-node.ts +79 -0
- package/ts-code/lib-common/service-api/3nstorage/owner.ts +559 -0
- package/ts-code/lib-common/service-api/3nstorage/root-route.ts +22 -0
- package/ts-code/lib-common/service-api/asmail/config.ts +144 -0
- package/ts-code/lib-common/service-api/asmail/delivery.ts +250 -0
- package/ts-code/lib-common/service-api/asmail/retrieval.ts +238 -0
- package/ts-code/lib-common/service-api/asmail/root-route.ts +22 -0
- package/ts-code/lib-common/service-api/ipc-api.ts +44 -0
- package/ts-code/lib-common/service-api/locker.ts +44 -0
- package/ts-code/lib-common/service-api/mailer-id/login.ts +80 -0
- package/ts-code/lib-common/service-api/mailer-id/provisioning.ts +64 -0
- package/ts-code/lib-common/service-api/mailer-id/root-route.ts +25 -0
- package/ts-code/lib-common/service-api/pub-key-login.ts +75 -0
- package/ts-code/lib-common/service-api/web-socket-base.ts +87 -0
- package/ts-code/lib-common/session-encryptor.ts +54 -0
- package/ts-code/lib-common/time-window-cache.ts +74 -0
- package/ts-code/lib-common/transferable.d.ts +30 -0
- package/ts-code/lib-server/conf-util.ts +35 -0
- package/ts-code/lib-server/mid-access.ts +45 -0
- package/ts-code/lib-server/middleware/body-parsers.ts +248 -0
- package/ts-code/lib-server/middleware/error-handler.ts +79 -0
- package/ts-code/lib-server/pkl-access.ts +46 -0
- package/ts-code/lib-server/resources/dns.ts +151 -0
- package/ts-code/lib-server/resources/mailerid-authorizer.ts +115 -0
- package/ts-code/lib-server/resources/mem-backed-sessions-factory.ts +132 -0
- package/ts-code/lib-server/resources/server-data-folders.ts +160 -0
- package/ts-code/lib-server/resources/server-key-for-pkl-challenge.ts +41 -0
- package/ts-code/lib-server/resources/sessions.ts +232 -0
- package/ts-code/lib-server/resources/user-files.ts +147 -0
- package/ts-code/lib-server/routes/pub-key-login/complete-exchange.ts +63 -0
- package/ts-code/lib-server/routes/pub-key-login/start-exchange.ts +189 -0
- package/ts-code/lib-server/routes/sessions/close.ts +27 -0
- package/ts-code/lib-server/routes/sessions/mid-auth.ts +77 -0
- package/ts-code/lib-server/routes/sessions/start.ts +116 -0
- package/ts-code/lib-server/web-sockets/app.ts +339 -0
- package/ts-code/lib-server/web-sockets/server-events.ts +63 -0
- package/ts-code/lib.ts +29 -0
- package/ts-code/locker/locker-app.ts +60 -0
- package/ts-code/locker/resources/lockers.ts +17 -0
- package/ts-code/locker/resources/sessions.ts +37 -0
- package/ts-code/locker/routes/create-locker.ts +47 -0
- package/ts-code/mailerId/mailerId-app.ts +107 -0
- package/ts-code/mailerId/resources/certifier.ts +181 -0
- package/ts-code/mailerId/resources/sessions.ts +44 -0
- package/ts-code/mailerId/resources/users.ts +88 -0
- package/ts-code/mailerId/routes/certify.ts +68 -0
- package/ts-code/main.ts +304 -0
- package/ts-code/mock/dns.ts +106 -0
- package/ts-code/mock/mock-as-child-proc.ts +130 -0
- package/ts-code/mock/node-child-ipc.ts +69 -0
- package/ts-code/mock/run-in-proc.ts +111 -0
- package/ts-code/mock/tls-options.ts +73 -0
- package/ts-code/services.ts +138 -0
- package/ts-code/signup/resources/users.ts +429 -0
- package/ts-code/signup/routes/add.ts +65 -0
- package/ts-code/signup/routes/get-available-addresses.ts +49 -0
- package/ts-code/signup/routes/get-available-domains.ts +45 -0
- package/ts-code/signup/signup-app.ts +54 -0
- package/ts-code/signup/signup-tokens.ts +148 -0
- package/ts-code/tests/admin-proto/signup.ts +277 -0
- package/ts-code/tests/jasmine.ts +37 -0
- package/ts-code/tests/libs-for-tests/3nstorage.ts +144 -0
- package/ts-code/tests/libs-for-tests/asmail.ts +220 -0
- package/ts-code/tests/libs-for-tests/assert.ts +22 -0
- package/ts-code/tests/libs-for-tests/async-jasmine.ts +89 -0
- package/ts-code/tests/libs-for-tests/bytes-equal.ts +25 -0
- package/ts-code/tests/libs-for-tests/json-copy.ts +38 -0
- package/ts-code/tests/libs-for-tests/json-equal.ts +55 -0
- package/ts-code/tests/libs-for-tests/mailerid.ts +123 -0
- package/ts-code/tests/libs-for-tests/pkl.ts +127 -0
- package/ts-code/tests/libs-for-tests/server-components/3nstorage.ts +206 -0
- package/ts-code/tests/libs-for-tests/server-components/admin.ts +49 -0
- package/ts-code/tests/libs-for-tests/server-components/asmail.ts +152 -0
- package/ts-code/tests/libs-for-tests/server-components/component.ts +90 -0
- package/ts-code/tests/libs-for-tests/server-components/mailerid.ts +114 -0
- package/ts-code/tests/libs-for-tests/server-runner.ts +82 -0
- package/ts-code/tests/libs-for-tests/spec-assembly.ts +60 -0
- package/ts-code/tests/libs-for-tests/ws-utils.ts +61 -0
- package/ts-code/tests/libs-for-tests/xhr-utils.ts +179 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/archive-obj-ver.ts +100 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/archive-root-ver.ts +91 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/delete-archive-obj-ver.ts +99 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/delete-archive-root-ver.ts +90 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/delete-obj.ts +84 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/events.ts +125 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/get-current-obj.ts +298 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/get-current-root.ts +290 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/get-obj-status.ts +88 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/get-root-status.ts +80 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/put-current-obj.ts +366 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/put-current-root.ts +329 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/trans-cancel-root.ts +86 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/trans-cancel.ts +86 -0
- package/ts-code/tests/protocols/3nstorage/owner/test-utils.ts +72 -0
- package/ts-code/tests/protocols/3nstorage/owner.ts +198 -0
- package/ts-code/tests/protocols/asmail/config.ts +172 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/finalize-delivery.ts +69 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/provide-recipient-pubkey.ts +88 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/put-metadata.ts +102 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/put-obj.ts +156 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/restart-session.ts +97 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/start-session.ts +79 -0
- package/ts-code/tests/protocols/asmail/delivery/test-utils.ts +64 -0
- package/ts-code/tests/protocols/asmail/delivery.ts +56 -0
- package/ts-code/tests/protocols/asmail/retrieval/specs/events.ts +78 -0
- package/ts-code/tests/protocols/asmail/retrieval/specs/get-message-meta.ts +80 -0
- package/ts-code/tests/protocols/asmail/retrieval/specs/get-message-obj.ts +197 -0
- package/ts-code/tests/protocols/asmail/retrieval/specs/list-messages.ts +110 -0
- package/ts-code/tests/protocols/asmail/retrieval/specs/remove-message.ts +74 -0
- package/ts-code/tests/protocols/asmail/retrieval/test-utils.ts +60 -0
- package/ts-code/tests/protocols/asmail/retrieval.ts +115 -0
- package/ts-code/tests/protocols/mailerid.ts +271 -0
- package/ts-code/tests/shared-checks/check-mid-login.ts +164 -0
- package/ts-code/tests/shared-checks/requests.ts +135 -0
- package/ts-code/tsconfig.json +11 -0
- package/ts-code/web3n.d.ts +1068 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2015 - 2016, 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 { SignedLoad } from '../../../lib-common/jwkeys';
|
|
20
|
+
import { authSender 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
|
+
export type IMidAuthorizer = (
|
|
25
|
+
rpDomain: string, sessionId: string, userId: string,
|
|
26
|
+
mailerIdAssertion: SignedLoad, userCert: SignedLoad, provCert: SignedLoad
|
|
27
|
+
) => Promise<boolean>;
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* This creates an authorize-sender route handler.
|
|
32
|
+
* @param relyingPartyDomain at which this service operates, as seen by client
|
|
33
|
+
* @param mailerIdAuthorizingFunc is a function returning promise, which
|
|
34
|
+
* resolves into boolean flag, with true value for authorization passing,
|
|
35
|
+
* and false for failed authorization.
|
|
36
|
+
*/
|
|
37
|
+
export function authorize(relyingPartyDomain: string, midAuthorizingFunc: IMidAuthorizer): RequestHandler {
|
|
38
|
+
|
|
39
|
+
return async (req: Request, res, next) => {
|
|
40
|
+
|
|
41
|
+
if (req.session.isAuthorized) {
|
|
42
|
+
return replyWithErr(ERR_SC.duplicateReq, "This protocol request has already been served.", res);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const rb: api.Request = req.body;
|
|
46
|
+
const sender = req.session.params.sender;
|
|
47
|
+
const sessionId = req.session.id;
|
|
48
|
+
|
|
49
|
+
if (!sender) {
|
|
50
|
+
// This case must be rejected, because place for authorizing
|
|
51
|
+
// anonymous connection is at the session start.
|
|
52
|
+
replyWithErr(api.SC.authFailed, "Server is not accepting provided credentials.", res);
|
|
53
|
+
req.session.close();
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (!rb.assertion || !rb.userCert || !rb.provCert) {
|
|
58
|
+
replyWithErr(ERR_SC.malformed, "No credentials given.", res);
|
|
59
|
+
req.session.close();
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
const certsVerified = await midAuthorizingFunc(
|
|
65
|
+
relyingPartyDomain, sessionId, sender, rb.assertion, rb.userCert, rb.provCert
|
|
66
|
+
);
|
|
67
|
+
if (certsVerified) {
|
|
68
|
+
req.session.isAuthorized = true;
|
|
69
|
+
res.status(api.SC.ok).send();
|
|
70
|
+
} else {
|
|
71
|
+
replyWithErr(api.SC.authFailed, "Server is not accepting provided credentials.", res);
|
|
72
|
+
req.session.close();
|
|
73
|
+
}
|
|
74
|
+
} catch (err) {
|
|
75
|
+
next(err);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,136 @@
|
|
|
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, Response } from 'express';
|
|
19
|
+
import { GenerateSession, Request } from '../../resources/delivery-sessions';
|
|
20
|
+
import { SC as recipSC, MsgDelivery } from '../../resources/recipients';
|
|
21
|
+
import { sessionStart as api, ERR_SC } from '../../../lib-common/service-api/asmail/delivery';
|
|
22
|
+
import { checkAndTransformAddress } from '../../../lib-common/canonical-address';
|
|
23
|
+
import { replyWithErr } from '../../resources/utils';
|
|
24
|
+
|
|
25
|
+
export type Redirect = (userId: string) => Promise<string>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* This creates a start-session route handler.
|
|
29
|
+
* @param allowedMsgSizeFunc is a function returning promises, that
|
|
30
|
+
* may resolve to
|
|
31
|
+
* (1) undefined, if recipient is unknown,
|
|
32
|
+
* (2) zero (0), if leaving mail is forbidden,
|
|
33
|
+
* (3) greater than zero maximum message length, and
|
|
34
|
+
* (4) -1, if mail cannot be accepted due to full mail box.
|
|
35
|
+
* @param sessionGenFunc is a promise returning function that generates new
|
|
36
|
+
* session objects.
|
|
37
|
+
* @param redirectFunc is an optional function that returns a promise,
|
|
38
|
+
* resolvable to
|
|
39
|
+
* (1) string with URI for ASMail service, which is serving given recipient,
|
|
40
|
+
* (2) undefined, if it is this server should service given recipient.
|
|
41
|
+
*/
|
|
42
|
+
export function startSession(
|
|
43
|
+
allowedMsgSizeFunc: MsgDelivery['allowedMaxMsgSize'],
|
|
44
|
+
sessionGenFunc: GenerateSession, redirectFunc?: Redirect
|
|
45
|
+
): RequestHandler {
|
|
46
|
+
|
|
47
|
+
async function serveRequestHere(
|
|
48
|
+
recipient: string, sender: string|undefined,
|
|
49
|
+
invitation: string|undefined, res: Response
|
|
50
|
+
): Promise<void> {
|
|
51
|
+
const msgSize = await allowedMsgSizeFunc(recipient, sender, invitation);
|
|
52
|
+
if (msgSize > 0) {
|
|
53
|
+
const session = await sessionGenFunc();
|
|
54
|
+
session.params.recipient = recipient;
|
|
55
|
+
session.params.sender = sender;
|
|
56
|
+
session.params.invite = invitation;
|
|
57
|
+
session.params.maxMsgLength = msgSize;
|
|
58
|
+
if (!sender) {
|
|
59
|
+
// message delivery is allowed for anonymous
|
|
60
|
+
// sender, thus, we set isAuthorized flag here
|
|
61
|
+
session.isAuthorized = true;
|
|
62
|
+
}
|
|
63
|
+
res.status(api.SC.ok).json( <api.Reply> {
|
|
64
|
+
sessionId: session.id,
|
|
65
|
+
maxMsgLength: msgSize
|
|
66
|
+
});
|
|
67
|
+
} else if (msgSize === 0) {
|
|
68
|
+
replyWithErr(
|
|
69
|
+
api.SC.senderNotAllowed,
|
|
70
|
+
`${sender ? sender : "Anonymous sender "} is not allowed to leave mail for ${recipient}`, res
|
|
71
|
+
);
|
|
72
|
+
} else if (msgSize === -1) {
|
|
73
|
+
replyWithErr(api.SC.inboxFull, `Mail box for ${recipient} is full.`, res);
|
|
74
|
+
} else {
|
|
75
|
+
throw new Error(`Unrecognized code ${msgSize} for message size limits.`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return async (req: Request, res, next) => {
|
|
80
|
+
|
|
81
|
+
const rb: api.Request = req.body;
|
|
82
|
+
const recipient = checkAndTransformAddress(rb.recipient);
|
|
83
|
+
let sender = rb.sender;
|
|
84
|
+
const invitation = rb.invitation;
|
|
85
|
+
const session = req.session;
|
|
86
|
+
|
|
87
|
+
// already existing session indicates repeated call, which should be bounced off
|
|
88
|
+
if (session) {
|
|
89
|
+
replyWithErr(ERR_SC.duplicateReq, "This protocol request has already been served.", res);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// missing recipient makes a bad request
|
|
94
|
+
if (!recipient) {
|
|
95
|
+
replyWithErr(ERR_SC.malformed, "Recipient is either missing in the request, or is malformed", res);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// if sender is given, we canonicalize the address
|
|
100
|
+
if (sender) {
|
|
101
|
+
sender = checkAndTransformAddress(sender);
|
|
102
|
+
if (!sender) {
|
|
103
|
+
return replyWithErr(ERR_SC.malformed, "Sender field is malformed", res);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// check invitation field
|
|
108
|
+
if ((invitation !== undefined) && (typeof invitation !== 'string')) {
|
|
109
|
+
return replyWithErr(ERR_SC.malformed, "Inviation field is malformed", res);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
if (redirectFunc) {
|
|
114
|
+
const redirectTo = await redirectFunc(recipient)
|
|
115
|
+
if (redirectTo) {
|
|
116
|
+
res.status(api.SC.redirect).json({
|
|
117
|
+
redirect: redirectTo
|
|
118
|
+
} as api.RedirectReply);
|
|
119
|
+
} else {
|
|
120
|
+
await serveRequestHere(recipient, sender, invitation, res);
|
|
121
|
+
}
|
|
122
|
+
} else {
|
|
123
|
+
await serveRequestHere(recipient, sender, invitation, res);
|
|
124
|
+
}
|
|
125
|
+
} catch (err) {
|
|
126
|
+
if (err === recipSC.USER_UNKNOWN) {
|
|
127
|
+
replyWithErr(api.SC.unknownRecipient, `Recipient ${recipient} is unknown.`, res);
|
|
128
|
+
} else {
|
|
129
|
+
next(err);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,50 @@
|
|
|
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, MsgRetrieval } from '../../resources/recipients';
|
|
20
|
+
import { msgMetadata as api, ERR_SC } from '../../../lib-common/service-api/asmail/retrieval';
|
|
21
|
+
import { Request } from '../../resources/sessions';
|
|
22
|
+
import { replyWithErr } from '../../resources/utils';
|
|
23
|
+
|
|
24
|
+
export function getMsgMeta(
|
|
25
|
+
getMsgMetaFunc: MsgRetrieval['getMsgMeta']
|
|
26
|
+
): RequestHandler {
|
|
27
|
+
return async (req: Request, res, next) => {
|
|
28
|
+
const userId = req.session.params.userId;
|
|
29
|
+
const msgId: string = req.params.msgId;
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
const meta = await getMsgMetaFunc(userId, msgId);
|
|
33
|
+
res.status(api.SC.ok).json(meta);
|
|
34
|
+
} catch (err) {
|
|
35
|
+
if ("string" !== typeof err) {
|
|
36
|
+
next(err);
|
|
37
|
+
} else if (err === recipSC.MSG_UNKNOWN) {
|
|
38
|
+
replyWithErr(api.SC.unknownMsg, "Message "+msgId+" is unknown.", res);
|
|
39
|
+
} else if (err === recipSC.USER_UNKNOWN) {
|
|
40
|
+
replyWithErr(ERR_SC.server, "Recipient disappeared from the system.", res);
|
|
41
|
+
req.session.close();
|
|
42
|
+
} else {
|
|
43
|
+
next(new Error("Unhandled storage error code: "+err));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,106 @@
|
|
|
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 } from 'express';
|
|
19
|
+
import { SC as recipSC, MsgRetrieval, BIN_TYPE } from '../../resources/recipients';
|
|
20
|
+
import { GetObjQueryOpts, ERR_SC, msgObj as api, HTTP_HEADER } from '../../../lib-common/service-api/asmail/retrieval';
|
|
21
|
+
import { Request } from '../../resources/sessions';
|
|
22
|
+
import { errWithCause } from '../../../lib-common/exceptions/error';
|
|
23
|
+
import { EMPTY_BUFFER } from '../../../lib-common/buffer-utils';
|
|
24
|
+
import { getObjIdFromParams, replyWithErr } from '../../resources/utils';
|
|
25
|
+
|
|
26
|
+
function extractQueryOptions(req: Request): undefined|{
|
|
27
|
+
header: boolean; limit: number|undefined; ofs: number;
|
|
28
|
+
} {
|
|
29
|
+
// query fields are string or undefined, yet, type info helps the show
|
|
30
|
+
const query: GetObjQueryOpts = req.query;
|
|
31
|
+
|
|
32
|
+
const header = ((query.header as any) === 'true');
|
|
33
|
+
|
|
34
|
+
const ofs = (query.ofs ? parseInt(query.ofs as any) : 0);
|
|
35
|
+
if (isNaN(ofs) || (ofs < 0) || (header && (ofs > 0))) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const limit = (query.limit ? parseInt(query.limit as any) : undefined);
|
|
40
|
+
if (limit !== undefined) {
|
|
41
|
+
if (isNaN(limit) || (limit < 0) || (!header && (limit === 0))) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return { header, limit, ofs };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function getMsgObj(
|
|
50
|
+
getMsgObjFunc: MsgRetrieval['getObj']
|
|
51
|
+
): RequestHandler {
|
|
52
|
+
return async (req: Request, res, next) => {
|
|
53
|
+
|
|
54
|
+
const userId = req.session.params.userId;
|
|
55
|
+
const msgId: string = req.params.msgId;
|
|
56
|
+
|
|
57
|
+
const { objId, objIdParseErr } = getObjIdFromParams(req);
|
|
58
|
+
if (objIdParseErr) {
|
|
59
|
+
return replyWithErr(ERR_SC.malformed, objIdParseErr, res);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const opts = extractQueryOptions(req);
|
|
63
|
+
if (!opts) {
|
|
64
|
+
return replyWithErr(ERR_SC.malformed, "Bad query parameters", res);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
try{
|
|
68
|
+
const reader = await getMsgObjFunc(userId, msgId, objId, opts.header, opts.ofs, opts.limit);
|
|
69
|
+
res.status(api.SC.ok);
|
|
70
|
+
res.set(HTTP_HEADER.contentType, BIN_TYPE);
|
|
71
|
+
res.set(HTTP_HEADER.contentLength, `${reader.len}`);
|
|
72
|
+
if (opts.header) {
|
|
73
|
+
res.set(HTTP_HEADER.objHeaderLength, `${reader.headerLen}`);
|
|
74
|
+
}
|
|
75
|
+
res.set(HTTP_HEADER.objSegmentsLength, `${reader.segsLen}`);
|
|
76
|
+
if (reader.len > 0) {
|
|
77
|
+
try {
|
|
78
|
+
await reader.pipe!(res);
|
|
79
|
+
} catch (err) {
|
|
80
|
+
console.error(errWithCause(
|
|
81
|
+
err, `Wasn't able to complete sending segments due to error in piping`
|
|
82
|
+
));
|
|
83
|
+
} finally {
|
|
84
|
+
res.end();
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
res.send(EMPTY_BUFFER);
|
|
88
|
+
}
|
|
89
|
+
} catch (err) {
|
|
90
|
+
if ("string" !== typeof err) {
|
|
91
|
+
next(err);
|
|
92
|
+
} else if (err === recipSC.OBJ_UNKNOWN) {
|
|
93
|
+
replyWithErr(api.SC.unknownMsgOrObj, `Object ${objId} is unknown.`, res);
|
|
94
|
+
} else if (err === recipSC.MSG_UNKNOWN) {
|
|
95
|
+
replyWithErr(api.SC.unknownMsgOrObj, `Message ${msgId} is unknown.`, res);
|
|
96
|
+
} else if (err === recipSC.USER_UNKNOWN) {
|
|
97
|
+
replyWithErr(ERR_SC.server, `Recipient disappeared from the system.`, res);
|
|
98
|
+
req.session.close();
|
|
99
|
+
} else {
|
|
100
|
+
next(new Error(`Unhandled storage error code: ${err}`));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,68 @@
|
|
|
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, MsgRetrieval } from '../../resources/recipients';
|
|
20
|
+
import { listMsgs as api, ERR_SC, ListMsgsOpts } from '../../../lib-common/service-api/asmail/retrieval';
|
|
21
|
+
import { Request } from '../../resources/sessions';
|
|
22
|
+
import { replyWithErr } from '../../resources/utils';
|
|
23
|
+
|
|
24
|
+
export function listMsgIds(
|
|
25
|
+
listMsgIdsFunc: MsgRetrieval['getMsgIds']
|
|
26
|
+
): RequestHandler {
|
|
27
|
+
return async (req: Request, res, next) => {
|
|
28
|
+
const userId = req.session.params.userId;
|
|
29
|
+
|
|
30
|
+
const opts = extractQueryOptions(req);
|
|
31
|
+
if (!opts) {
|
|
32
|
+
return replyWithErr(ERR_SC.malformed, "Bad query parameters", res);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
const { from, to } = opts;
|
|
37
|
+
const msgIds = await listMsgIdsFunc(userId, from, to);
|
|
38
|
+
res.status(api.SC.ok).json(msgIds);
|
|
39
|
+
} catch (err) {
|
|
40
|
+
if ("string" !== typeof err) {
|
|
41
|
+
next(err);
|
|
42
|
+
} else if (err === recipSC.USER_UNKNOWN) {
|
|
43
|
+
replyWithErr(ERR_SC.server, "Recipient disappeared from the system.", res);
|
|
44
|
+
req.session.close();
|
|
45
|
+
} else {
|
|
46
|
+
next(new Error("Unhandled storage error code: "+err));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function extractQueryOptions(req: Request): ListMsgsOpts|undefined {
|
|
54
|
+
const query: ListMsgsOpts = req.query;
|
|
55
|
+
|
|
56
|
+
const from = (query.from ? parseInt(query.from as any) : undefined);
|
|
57
|
+
if ((from !== undefined) && (isNaN(from) || (from <= 0))) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const to = (query.to ? parseInt(query.to as any) : undefined);
|
|
61
|
+
if ((to !== undefined) && (isNaN(to) || (to <= 0))) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return { from, to };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2015 - 2016, 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, MsgRetrieval } from '../../resources/recipients';
|
|
20
|
+
import { rmMsg as api, ERR_SC } from '../../../lib-common/service-api/asmail/retrieval';
|
|
21
|
+
import { Request } from '../../resources/sessions';
|
|
22
|
+
import { replyWithErr } from '../../resources/utils';
|
|
23
|
+
|
|
24
|
+
export function deleteMsg(delMsgFunc: MsgRetrieval['deleteMsg']): RequestHandler {
|
|
25
|
+
return async (req: Request, res, next) => {
|
|
26
|
+
const userId = req.session.params.userId;
|
|
27
|
+
const msgId: string = req.params.msgId;
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
await delMsgFunc(userId, msgId);
|
|
31
|
+
res.status(api.SC.ok).send();
|
|
32
|
+
} catch (err) {
|
|
33
|
+
if ("string" !== typeof err) {
|
|
34
|
+
next(err);
|
|
35
|
+
} else if (err === recipSC.MSG_UNKNOWN) {
|
|
36
|
+
replyWithErr(api.SC.unknownMsg, "Message "+msgId+" is unknown.", res);
|
|
37
|
+
} else if (err === recipSC.USER_UNKNOWN) {
|
|
38
|
+
replyWithErr(ERR_SC.server, "Recipient disappeared from the system.", res);
|
|
39
|
+
req.session.close();
|
|
40
|
+
} else {
|
|
41
|
+
next(new Error("Unhandled storage error code: "+err));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2023, 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 { EXECUTABLE_NAME } from "../config/default-confs";
|
|
19
|
+
import { ParsedRunArgs, parseRunArgs, runCmd } from "./run-cmd";
|
|
20
|
+
import { sampleConfig, showSampleConfigCmd } from "./show-sample-config";
|
|
21
|
+
import { ParsedSignupArgs, parseSignupArgs, signupCmd } from "./signup-cmd";
|
|
22
|
+
import { CliUsageDisplay, HelpArg, UsageSection, helpOpt, parseArgv, toErrorUsage, toUsageDisplay } from "./utils";
|
|
23
|
+
|
|
24
|
+
export { CliUsageDisplay } from "./utils";
|
|
25
|
+
|
|
26
|
+
function mainUsage(execName: string): UsageSection[] {
|
|
27
|
+
return [
|
|
28
|
+
{
|
|
29
|
+
header: execName,
|
|
30
|
+
content: `Server of all 3NWeb utilities: MailerId, ASMail, 3NStorage.`
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
header: `Usage:`,
|
|
34
|
+
content: `${execName} [command]`
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
header: 'Available commands:',
|
|
38
|
+
content: [
|
|
39
|
+
runCmd,
|
|
40
|
+
signupCmd,
|
|
41
|
+
showSampleConfigCmd
|
|
42
|
+
]
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
header: '',
|
|
46
|
+
content: `Use "${execName} [command] --help" for more information about a command.`
|
|
47
|
+
}
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function parseProcessArgv(): {
|
|
52
|
+
runCmd?: ParsedRunArgs;
|
|
53
|
+
signupCmd?: ParsedSignupArgs;
|
|
54
|
+
showUsage?: CliUsageDisplay;
|
|
55
|
+
showSampleConfig?: CliUsageDisplay;
|
|
56
|
+
} {
|
|
57
|
+
const args = process.argv.slice(2);
|
|
58
|
+
if (args.length === 0) {
|
|
59
|
+
return toUsageDisplay(0, mainUsage(EXECUTABLE_NAME));
|
|
60
|
+
}
|
|
61
|
+
if (args[0] === runCmd.name) {
|
|
62
|
+
return parseRunArgs(args.slice(1), EXECUTABLE_NAME);
|
|
63
|
+
} else if (args[0] === signupCmd.name) {
|
|
64
|
+
return parseSignupArgs(args.slice(1), EXECUTABLE_NAME);
|
|
65
|
+
} else if (args[0] === showSampleConfigCmd.name) {
|
|
66
|
+
return { showSampleConfig: {
|
|
67
|
+
txtToDisplay: sampleConfig, exitStatus: 0
|
|
68
|
+
}};
|
|
69
|
+
} else {
|
|
70
|
+
const opts = parseArgv<HelpArg>(args, [ helpOpt ], { partial: true });
|
|
71
|
+
if (opts.help) {
|
|
72
|
+
return toUsageDisplay(0, mainUsage(EXECUTABLE_NAME));
|
|
73
|
+
}
|
|
74
|
+
return toUsageDisplay(-1, toErrorUsage(
|
|
75
|
+
mainUsage(EXECUTABLE_NAME),
|
|
76
|
+
`Unknown command '${args[0]}'`
|
|
77
|
+
));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2023 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 { CliUsageDisplay, CommandDef, OptionDef, UsageSection, helpOpt, parseArgv, toErrorUsage, toUsageDisplay } from "./utils";
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
export const runCmd: CommandDef<'run'> = {
|
|
22
|
+
name: 'run',
|
|
23
|
+
summary: 'runs 3NWeb services'
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function runUsage(execName: string): UsageSection[] {
|
|
27
|
+
return [
|
|
28
|
+
{
|
|
29
|
+
content: `This command runs some or all 3NWeb services. Configuration is read from a yaml file.`
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
header: 'Usage:',
|
|
33
|
+
content: `${execName} ${runCmd.name} [options] [config_file]`
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
header: 'Options:',
|
|
37
|
+
optionList: runOpts
|
|
38
|
+
}
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const runOpts: OptionDef[] = [
|
|
43
|
+
{
|
|
44
|
+
name: 'config',
|
|
45
|
+
alias: 'c',
|
|
46
|
+
type: String,
|
|
47
|
+
typeLabel: '{underline <file>}',
|
|
48
|
+
description: `path of a configuration yaml file`
|
|
49
|
+
},
|
|
50
|
+
helpOpt
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
export interface ParsedRunArgs {
|
|
54
|
+
config?: string;
|
|
55
|
+
help?: boolean;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function parseRunArgs(args: string[], execName: string): {
|
|
59
|
+
runCmd?: ParsedRunArgs;
|
|
60
|
+
showUsage?: CliUsageDisplay;
|
|
61
|
+
} {
|
|
62
|
+
if (args.length === 0) {
|
|
63
|
+
return toUsageDisplay(0, runUsage(execName));
|
|
64
|
+
}
|
|
65
|
+
const runArgs = parseArgv<ParsedRunArgs>(args, runOpts, { partial: true });
|
|
66
|
+
if (runArgs.help) {
|
|
67
|
+
return toUsageDisplay(0, runUsage(execName));
|
|
68
|
+
} else if (runArgs.config) {
|
|
69
|
+
return { runCmd: runArgs };
|
|
70
|
+
} else if (runArgs._unknown) {
|
|
71
|
+
return { runCmd: { config: runArgs._unknown[0] } };
|
|
72
|
+
} else {
|
|
73
|
+
return toUsageDisplay(-1, toErrorUsage(
|
|
74
|
+
runUsage(execName),
|
|
75
|
+
`Missing configuration file path.`
|
|
76
|
+
));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
Object.freeze(exports);
|