spec-3nweb-server 1.8.4 → 1.8.6
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/routes/owner/archive-obj-version.js +2 -2
- package/build/3nstorage/routes/owner/cancel-trans.js +2 -2
- package/build/3nstorage/routes/owner/delete-obj.js +2 -2
- package/build/3nstorage/routes/owner/get-current-obj.js +3 -4
- package/build/3nstorage/routes/owner/param-setter.js +2 -6
- package/build/asmail/routes/config/param-setter.js +2 -2
- package/build/asmail/routes/delivery/finalize-delivery.js +2 -2
- package/build/asmail/routes/delivery/put-obj.js +2 -2
- package/build/asmail/routes/delivery/sender-authorization.js +2 -2
- package/build/asmail/routes/retrieval/remove-message.js +2 -2
- package/build/cli/signup-cmd.js +0 -1
- package/build/lib-server/routes/sessions/close.js +2 -2
- package/build/lib-server/routes/sessions/mid-auth.js +2 -5
- package/build/main.js +12 -15
- package/build/mock/tls-options.js +46 -44
- package/build/signup/routes/add.js +4 -4
- 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/routes/owner/archive-obj-version.ts +73 -0
- package/ts-code/3nstorage/routes/owner/cancel-trans.ts +58 -0
- package/ts-code/3nstorage/routes/owner/delete-obj.ts +103 -0
- package/ts-code/3nstorage/routes/owner/get-archived-obj-ver.ts +111 -0
- package/ts-code/3nstorage/routes/owner/get-current-obj.ts +122 -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 +284 -0
- package/ts-code/3nstorage/routes/owner/session-params.ts +49 -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/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 +50 -0
- package/ts-code/asmail/routes/delivery/pre-flight.ts +132 -0
- package/ts-code/asmail/routes/delivery/provide-recipient-pubkey.ts +58 -0
- package/ts-code/asmail/routes/delivery/put-metadata.ts +94 -0
- package/ts-code/asmail/routes/delivery/put-obj.ts +166 -0
- package/ts-code/asmail/routes/delivery/restart-session.ts +130 -0
- package/ts-code/asmail/routes/delivery/sender-authorization.ts +81 -0
- package/ts-code/asmail/routes/delivery/start-session.ts +151 -0
- package/ts-code/asmail/routes/retrieval/get-message-meta.ts +53 -0
- package/ts-code/asmail/routes/retrieval/get-message-obj.ts +109 -0
- package/ts-code/asmail/routes/retrieval/list-messages.ts +70 -0
- package/ts-code/asmail/routes/retrieval/remove-message.ts +47 -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,495 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2015 - 2017, 2020, 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
|
+
/*
|
|
19
|
+
* This module is recipient boxes factory.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { Readable } from 'stream';
|
|
23
|
+
import { Inbox, ObjReader, AuthSenderPolicy, SC, MailEventsSink, InboxParams } from './inbox';
|
|
24
|
+
import * as deliveryApi from '../../lib-common/service-api/asmail/delivery';
|
|
25
|
+
import * as retrievalApi from '../../lib-common/service-api/asmail/retrieval';
|
|
26
|
+
import { userDataInRootFolder } from '../../lib-server/resources/server-data-folders';
|
|
27
|
+
|
|
28
|
+
export { SC } from './inbox';
|
|
29
|
+
|
|
30
|
+
export const BIN_TYPE = 'application/octet-stream';
|
|
31
|
+
|
|
32
|
+
interface AddressToSizeMap {
|
|
33
|
+
[address: string]: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param lst is a map from addresses to numeric values
|
|
38
|
+
* @param address
|
|
39
|
+
* @return numeric value found in the list, or undefined,
|
|
40
|
+
* if neither address, nor its domain can be matched in the list.
|
|
41
|
+
*/
|
|
42
|
+
function findMatchIn(lst: AddressToSizeMap, address: string): number|undefined {
|
|
43
|
+
// check address as a whole
|
|
44
|
+
let v = lst[address];
|
|
45
|
+
if ('undefined' !== typeof v) { return v; }
|
|
46
|
+
// check address' own domain
|
|
47
|
+
const ind = address.indexOf('@');
|
|
48
|
+
if (ind < 0) { return; }
|
|
49
|
+
address = address.substring(ind+1);
|
|
50
|
+
if (address.length === 0) { return; }
|
|
51
|
+
v = lst['@'+address];
|
|
52
|
+
if ('undefined' !== typeof v) { return v; }
|
|
53
|
+
// check parent domains
|
|
54
|
+
while (true) {
|
|
55
|
+
const ind = address.indexOf('.');
|
|
56
|
+
if (ind < 0) { return; }
|
|
57
|
+
address = address.substring(ind+1);
|
|
58
|
+
if (address.length === 0) { return; }
|
|
59
|
+
v = lst['@*.'+address];
|
|
60
|
+
if ('undefined' !== typeof v) { return v; }
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @param inbox
|
|
66
|
+
* @param msgSize is a number of message bytes
|
|
67
|
+
* @returns a promise, resolvable to
|
|
68
|
+
* (1) least number between given number of bytes, and free space of
|
|
69
|
+
* a given inbox;
|
|
70
|
+
* (2) -1 (less than zero), if there is no free space in the inbox.
|
|
71
|
+
*/
|
|
72
|
+
async function adaptToFreeSpaceLeft(
|
|
73
|
+
inbox: Inbox, msgSize: number
|
|
74
|
+
): Promise<number> {
|
|
75
|
+
const bytesFree = await inbox.freeSpace();
|
|
76
|
+
return ((bytesFree > 0) ? Math.min(bytesFree, msgSize) : -1);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @param inbox
|
|
81
|
+
* @param invitation is a string invitation token, or undefined.
|
|
82
|
+
* @returns a promise, resolvable to
|
|
83
|
+
* (1) zero (0), if leaving mail is forbidden,
|
|
84
|
+
* (2) greater than zero maximum message length, and
|
|
85
|
+
* (3) -1 (less than zero), if mail cannot be accepted due to full
|
|
86
|
+
* mail box.
|
|
87
|
+
*/
|
|
88
|
+
async function allowedMsgSizeForAnonSender(
|
|
89
|
+
inbox: Inbox, invitation: string|undefined
|
|
90
|
+
): Promise<number> {
|
|
91
|
+
const policy = await inbox.getParam('anonymous/policy');
|
|
92
|
+
if (policy.accept) {
|
|
93
|
+
|
|
94
|
+
// XXX this misses case when invite allows for bigger messages,
|
|
95
|
+
// while without invite messages are also allowed.
|
|
96
|
+
|
|
97
|
+
if (policy.acceptWithInvitesOnly) {
|
|
98
|
+
if (invitation) {
|
|
99
|
+
const invites = await inbox.getParam('anonymous/invites');
|
|
100
|
+
const sizeForInvite = invites[invitation];
|
|
101
|
+
return ((typeof sizeForInvite === 'number') ?
|
|
102
|
+
adaptToFreeSpaceLeft(inbox, sizeForInvite) : 0
|
|
103
|
+
);
|
|
104
|
+
} else {
|
|
105
|
+
return 0;
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
return await adaptToFreeSpaceLeft(inbox, policy.defaultMsgSize);
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
return 0;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @param inbox
|
|
117
|
+
* @param sender is sender string address
|
|
118
|
+
* @param invitation is a string invitation token, or undefined.
|
|
119
|
+
* @returns a promise, resolvable to
|
|
120
|
+
* (1) zero (0), if leaving mail is forbidden,
|
|
121
|
+
* (2) greater than zero maximum message length, and
|
|
122
|
+
* (3) -1 (less than zero), if mail cannot be accepted due to full mail
|
|
123
|
+
* box.
|
|
124
|
+
*/
|
|
125
|
+
async function allowedMsgSizeForAuthSender(
|
|
126
|
+
inbox: Inbox, sender: string, invitation: string|undefined
|
|
127
|
+
): Promise<number> {
|
|
128
|
+
const results = await Promise.all<any>([
|
|
129
|
+
inbox.getParam('authenticated/policy'),
|
|
130
|
+
inbox.getParam('authenticated/whitelist')
|
|
131
|
+
])
|
|
132
|
+
const policy: AuthSenderPolicy = results[0];
|
|
133
|
+
const sizeFromWL = findMatchIn(<AddressToSizeMap> results[1], sender);
|
|
134
|
+
// check whitelist for specific size
|
|
135
|
+
if (typeof sizeFromWL === 'number') {
|
|
136
|
+
return adaptToFreeSpaceLeft(inbox, sizeFromWL);
|
|
137
|
+
} else if (typeof sizeFromWL !== 'undefined') {
|
|
138
|
+
return adaptToFreeSpaceLeft(inbox, policy.defaultMsgSize);
|
|
139
|
+
}
|
|
140
|
+
// exit if only whitelist contacts are allowed
|
|
141
|
+
if (policy.acceptFromWhiteListOnly) { return 0; }
|
|
142
|
+
// if needed, apply blacklist
|
|
143
|
+
if (policy.applyBlackList) {
|
|
144
|
+
const bList = await inbox.getParam('authenticated/blacklist');
|
|
145
|
+
if (typeof findMatchIn(bList, sender) === 'undefined') {
|
|
146
|
+
return adaptToFreeSpaceLeft(inbox, policy.defaultMsgSize);
|
|
147
|
+
} else {
|
|
148
|
+
return 0;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return adaptToFreeSpaceLeft(inbox, policy.defaultMsgSize);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export type GetParam<P extends keyof InboxParams> = (
|
|
155
|
+
userId: string
|
|
156
|
+
) => Promise<InboxParams[P]>;
|
|
157
|
+
export type SetParam<P extends keyof InboxParams> = (
|
|
158
|
+
userId: string, param: InboxParams[P]
|
|
159
|
+
) => Promise<boolean>;
|
|
160
|
+
|
|
161
|
+
export type EventsSink = MailEventsSink;
|
|
162
|
+
|
|
163
|
+
export interface Recipients {
|
|
164
|
+
config: ASMailServiceConfig;
|
|
165
|
+
delivery: MsgDelivery;
|
|
166
|
+
retrieval: MsgRetrieval;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export interface ASMailServiceConfig {
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* This checks existence of a given user, returning a promise, resolvable
|
|
173
|
+
* either to true, when given user id is known, or to false, when it is not.
|
|
174
|
+
*/
|
|
175
|
+
exists: (userId: string) => Promise<boolean>;
|
|
176
|
+
|
|
177
|
+
getPubKey: GetParam<'pubkey'>;
|
|
178
|
+
setPubKey: SetParam<'pubkey'>;
|
|
179
|
+
|
|
180
|
+
getAnonSenderPolicy: GetParam<'anonymous/policy'>;
|
|
181
|
+
setAnonSenderPolicy: SetParam<'anonymous/policy'>;
|
|
182
|
+
|
|
183
|
+
getAnonSenderInvites: GetParam<'anonymous/invites'>;
|
|
184
|
+
setAnonSenderInvites: SetParam<'anonymous/invites'>;
|
|
185
|
+
|
|
186
|
+
getAuthSenderPolicy: GetParam<'authenticated/policy'>;
|
|
187
|
+
setAuthSenderPolicy: SetParam<'authenticated/policy'>;
|
|
188
|
+
|
|
189
|
+
getAuthSenderInvites: GetParam<'authenticated/invites'>;
|
|
190
|
+
setAuthSenderInvites: SetParam<'authenticated/invites'>;
|
|
191
|
+
|
|
192
|
+
getAuthSenderBlacklist: GetParam<'authenticated/blacklist'>;
|
|
193
|
+
setAuthSenderBlacklist: SetParam<'authenticated/blacklist'>;
|
|
194
|
+
|
|
195
|
+
getAuthSenderWhitelist: GetParam<'authenticated/whitelist'>;
|
|
196
|
+
setAuthSenderWhitelist: SetParam<'authenticated/whitelist'>;
|
|
197
|
+
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export interface MsgDelivery {
|
|
201
|
+
|
|
202
|
+
getPubKey: ASMailServiceConfig['getPubKey'];
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* This tells what is an allowable maximum message size for a given
|
|
206
|
+
* recipient, for a given sender and/or under a given invitation token.
|
|
207
|
+
* Function returns a promise, resolvable to
|
|
208
|
+
* (1) zero (0), if leaving mail is forbidden,
|
|
209
|
+
* (2) greater than zero maximum message length, and
|
|
210
|
+
* (3) -1 (less than zero), if mail cannot be accepted due to full mail
|
|
211
|
+
* box.
|
|
212
|
+
*/
|
|
213
|
+
allowedMaxMsgSize: (
|
|
214
|
+
recipient: string, sender: string|undefined, invitation: string|undefined
|
|
215
|
+
) => Promise<number>;
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* This allocates storage for a message returning a promise, resolvable to
|
|
219
|
+
* (1) message id, when a folder for new message has been created,
|
|
220
|
+
* (2) undefined, if recipient is unknown.
|
|
221
|
+
*/
|
|
222
|
+
setMsgStorage: (
|
|
223
|
+
recipient: string, msgMeta: deliveryApi.msgMeta.Request,
|
|
224
|
+
authSender: string|undefined, invite: string|undefined, maxMsgLength: number
|
|
225
|
+
) => Promise<string>;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* This saves object's bytes, returning a promise, resolvable when saving
|
|
229
|
+
* is OK, otherwise, promise rejects with string error code from SC.
|
|
230
|
+
*/
|
|
231
|
+
saveObj: (
|
|
232
|
+
recipient: string, msgId: string, objId: string,
|
|
233
|
+
fstReq: deliveryApi.PutObjFirstQueryOpts|undefined,
|
|
234
|
+
sndReq: deliveryApi.PutObjSecondQueryOpts|undefined,
|
|
235
|
+
bytesLen: number, bytes: Readable
|
|
236
|
+
) => Promise<void>;
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* This returns parameter of a message that is still in delivery, identified
|
|
240
|
+
* by given recipient and message id. If message is unknown, or if it has
|
|
241
|
+
* already been delivered, error code is thrown.
|
|
242
|
+
* Rejected promise may have a string error code from SC.
|
|
243
|
+
*/
|
|
244
|
+
incompleteMsgDeliveryParams: (
|
|
245
|
+
recipient: string, msgId: string
|
|
246
|
+
) => Promise<{ maxMsgLength: number; currentMsgLength: number; }>;
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* This finalizes delivery of a message, returning a promise.
|
|
250
|
+
* Rejected promise may have a string error code from SC.
|
|
251
|
+
*/
|
|
252
|
+
finalizeDelivery: (
|
|
253
|
+
recipient: string, msgId: string
|
|
254
|
+
) => Promise<void>;
|
|
255
|
+
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export interface MsgRetrieval {
|
|
259
|
+
|
|
260
|
+
exists: ASMailServiceConfig['exists'];
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* This returns a promise, resolvable to array with ids of available
|
|
264
|
+
* messages. Rejected promise may have a string error code from SC.
|
|
265
|
+
*/
|
|
266
|
+
getMsgIds: (
|
|
267
|
+
userId: string, fromTS: number|undefined, toTS: number|undefined
|
|
268
|
+
) => Promise<retrievalApi.listMsgs.Reply>;
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* This returns a promise, resolvable to message meta.
|
|
272
|
+
* Rejected promise may have a string error code from SC.
|
|
273
|
+
*/
|
|
274
|
+
getMsgMeta: (userId: string, msgId: string) => Promise<retrievalApi.MsgMeta>;
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* This deletes a message returning a promise, resolvable when message is
|
|
278
|
+
* removed.
|
|
279
|
+
* Rejected promise may have a string error code from SC.
|
|
280
|
+
*/
|
|
281
|
+
deleteMsg: (userId: string, msgId: string) => Promise<void>;
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* This returns a promise, resolvable to readable stream of object bytes.
|
|
285
|
+
* Rejected promise may be passing string error code from SC.
|
|
286
|
+
*/
|
|
287
|
+
getObj: (
|
|
288
|
+
userId: string, msgId: string, objId: string,
|
|
289
|
+
header: boolean, segsOffset: number, segsLimit: number|undefined
|
|
290
|
+
) => Promise<ObjReader>;
|
|
291
|
+
|
|
292
|
+
setMailEventsSink(sink: EventsSink): void;
|
|
293
|
+
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export function makeRecipients(
|
|
297
|
+
rootFolder: string,
|
|
298
|
+
writeBufferSize?: string|number, readBufferSize?: string|number
|
|
299
|
+
): Recipients {
|
|
300
|
+
|
|
301
|
+
const boxes = new Map<string, Inbox>();
|
|
302
|
+
|
|
303
|
+
let mailEventsSink: EventsSink|undefined = undefined;
|
|
304
|
+
|
|
305
|
+
async function getInbox(userId: string): Promise<Inbox> {
|
|
306
|
+
if (!mailEventsSink) {
|
|
307
|
+
throw new Error(`Mail events sink is not set`);
|
|
308
|
+
}
|
|
309
|
+
let inbox = boxes.get(userId);
|
|
310
|
+
if (inbox) {
|
|
311
|
+
try {
|
|
312
|
+
await inbox.ensureUserExistsOnDisk();
|
|
313
|
+
return inbox;
|
|
314
|
+
} catch (err) {
|
|
315
|
+
boxes.delete(userId);
|
|
316
|
+
throw err;
|
|
317
|
+
}
|
|
318
|
+
} else {
|
|
319
|
+
const userFolder = userDataInRootFolder(rootFolder, userId);
|
|
320
|
+
inbox = await Inbox.make(
|
|
321
|
+
userFolder, userId, mailEventsSink, writeBufferSize, readBufferSize
|
|
322
|
+
);
|
|
323
|
+
boxes.set(userId, inbox);
|
|
324
|
+
return inbox;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const config: ASMailServiceConfig = {
|
|
329
|
+
|
|
330
|
+
exists: async userId => {
|
|
331
|
+
try {
|
|
332
|
+
await getInbox(userId);
|
|
333
|
+
return true;
|
|
334
|
+
} catch (err) {
|
|
335
|
+
if (err !== SC.USER_UNKNOWN) { throw err; }
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
},
|
|
339
|
+
|
|
340
|
+
getPubKey: async recipient => {
|
|
341
|
+
const inbox = await getInbox(recipient);
|
|
342
|
+
return inbox.getParam('pubkey');
|
|
343
|
+
},
|
|
344
|
+
setPubKey: async (userId, pkey) => {
|
|
345
|
+
const inbox = await getInbox(userId);
|
|
346
|
+
return inbox.setPubKey(pkey);
|
|
347
|
+
},
|
|
348
|
+
|
|
349
|
+
getAnonSenderPolicy: async recipient => {
|
|
350
|
+
const inbox = await getInbox(recipient);
|
|
351
|
+
return inbox.getParam('anonymous/policy');
|
|
352
|
+
},
|
|
353
|
+
setAnonSenderPolicy: async (userId, policy) => {
|
|
354
|
+
const inbox = await getInbox(userId);
|
|
355
|
+
return inbox.setAnonSenderPolicy(policy);
|
|
356
|
+
},
|
|
357
|
+
|
|
358
|
+
getAnonSenderInvites: async recipient => {
|
|
359
|
+
const inbox = await getInbox(recipient);
|
|
360
|
+
return inbox.getParam('anonymous/invites');
|
|
361
|
+
},
|
|
362
|
+
setAnonSenderInvites: async (userId, invites) => {
|
|
363
|
+
const inbox = await getInbox(userId);
|
|
364
|
+
return inbox.setAnonSenderInvites(invites);
|
|
365
|
+
},
|
|
366
|
+
|
|
367
|
+
getAuthSenderPolicy: async recipient => {
|
|
368
|
+
const inbox = await getInbox(recipient);
|
|
369
|
+
return inbox.getParam('authenticated/policy');
|
|
370
|
+
},
|
|
371
|
+
setAuthSenderPolicy: async (userId, policy) => {
|
|
372
|
+
const inbox = await getInbox(userId);
|
|
373
|
+
return inbox.setAuthSenderPolicy(policy);
|
|
374
|
+
},
|
|
375
|
+
|
|
376
|
+
getAuthSenderInvites: async recipient => {
|
|
377
|
+
const inbox = await getInbox(recipient);
|
|
378
|
+
return inbox.getParam('authenticated/invites');
|
|
379
|
+
},
|
|
380
|
+
setAuthSenderInvites: async (userId, invites) => {
|
|
381
|
+
const inbox = await getInbox(userId);
|
|
382
|
+
return inbox.setAnonSenderInvites(invites);
|
|
383
|
+
},
|
|
384
|
+
|
|
385
|
+
getAuthSenderBlacklist: async recipient => {
|
|
386
|
+
const inbox = await getInbox(recipient);
|
|
387
|
+
return inbox.getParam('authenticated/blacklist');
|
|
388
|
+
},
|
|
389
|
+
setAuthSenderBlacklist: async (userId, list) => {
|
|
390
|
+
const inbox = await getInbox(userId);
|
|
391
|
+
return inbox.setAuthSenderBlacklist(list);
|
|
392
|
+
},
|
|
393
|
+
|
|
394
|
+
getAuthSenderWhitelist: async recipient => {
|
|
395
|
+
const inbox = await getInbox(recipient);
|
|
396
|
+
return inbox.getParam('authenticated/whitelist');
|
|
397
|
+
},
|
|
398
|
+
setAuthSenderWhitelist: async (userId, list) => {
|
|
399
|
+
const inbox = await getInbox(userId);
|
|
400
|
+
return inbox.setAuthSenderWhitelist(list);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
};
|
|
404
|
+
Object.freeze(config);
|
|
405
|
+
|
|
406
|
+
const delivery: MsgDelivery = {
|
|
407
|
+
|
|
408
|
+
getPubKey: config.getPubKey,
|
|
409
|
+
|
|
410
|
+
allowedMaxMsgSize: async (recipient, sender, invitation) => {
|
|
411
|
+
const inbox = await getInbox(recipient);
|
|
412
|
+
// XXX move these two functions into inbox
|
|
413
|
+
if (sender) {
|
|
414
|
+
return allowedMsgSizeForAuthSender(inbox, sender, invitation);
|
|
415
|
+
} else {
|
|
416
|
+
return allowedMsgSizeForAnonSender(inbox, invitation);
|
|
417
|
+
}
|
|
418
|
+
},
|
|
419
|
+
|
|
420
|
+
setMsgStorage: async (
|
|
421
|
+
recipient, msgMeta, authSender, invite, maxMsgLength
|
|
422
|
+
) => {
|
|
423
|
+
const inbox = await getInbox(recipient);
|
|
424
|
+
return inbox.recordMsgMeta(msgMeta, authSender, invite, maxMsgLength);
|
|
425
|
+
},
|
|
426
|
+
|
|
427
|
+
saveObj: async (
|
|
428
|
+
recipient, msgId, objId, fstReq, sndReq, bytesLen, bytes
|
|
429
|
+
) => {
|
|
430
|
+
const inbox = await getInbox(recipient);
|
|
431
|
+
if (fstReq) {
|
|
432
|
+
return inbox.startSavingObj(msgId, objId, bytes, bytesLen, fstReq);
|
|
433
|
+
} else if (sndReq) {
|
|
434
|
+
return inbox.continueSavingObj(msgId, objId, bytes, bytesLen, sndReq);
|
|
435
|
+
} else {
|
|
436
|
+
throw new Error(`Missing both request options`);
|
|
437
|
+
}
|
|
438
|
+
},
|
|
439
|
+
|
|
440
|
+
finalizeDelivery: async (recipient, msgId) => {
|
|
441
|
+
const inbox = await getInbox(recipient);
|
|
442
|
+
return inbox.completeMsgDelivery(msgId);
|
|
443
|
+
},
|
|
444
|
+
|
|
445
|
+
incompleteMsgDeliveryParams: async (recipient, msgId) => {
|
|
446
|
+
const inbox = await getInbox(recipient);
|
|
447
|
+
return inbox.getIncompleteMsgParams(msgId);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
};
|
|
451
|
+
Object.freeze(delivery);
|
|
452
|
+
|
|
453
|
+
const retrieval: MsgRetrieval = {
|
|
454
|
+
|
|
455
|
+
exists: config.exists,
|
|
456
|
+
|
|
457
|
+
getMsgIds: async (userId, fromTS, toTS) => {
|
|
458
|
+
const inbox = await getInbox(userId);
|
|
459
|
+
return inbox.getMsgIds(fromTS, toTS);
|
|
460
|
+
},
|
|
461
|
+
|
|
462
|
+
getMsgMeta: async (userId, msgId) => {
|
|
463
|
+
const inbox = await getInbox(userId);
|
|
464
|
+
return inbox.getMsgMeta(msgId, true);
|
|
465
|
+
},
|
|
466
|
+
|
|
467
|
+
deleteMsg: async (userId, msgId) => {
|
|
468
|
+
const inbox = await getInbox(userId);
|
|
469
|
+
return inbox.rmMsg(msgId);
|
|
470
|
+
},
|
|
471
|
+
|
|
472
|
+
getObj: async (userId, msgId, objId, header, segsOffset, segsLimit) => {
|
|
473
|
+
const inbox = await getInbox(userId);
|
|
474
|
+
return inbox.getObj(msgId, objId, header, segsOffset, segsLimit);
|
|
475
|
+
},
|
|
476
|
+
|
|
477
|
+
setMailEventsSink(sink: EventsSink): void {
|
|
478
|
+
if (mailEventsSink) {
|
|
479
|
+
throw new Error(`Mail events sink is already set`);
|
|
480
|
+
}
|
|
481
|
+
mailEventsSink = sink;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
};
|
|
485
|
+
Object.freeze(retrieval);
|
|
486
|
+
|
|
487
|
+
const recipients: Recipients = {
|
|
488
|
+
config, delivery, retrieval
|
|
489
|
+
};
|
|
490
|
+
Object.freeze(recipients);
|
|
491
|
+
|
|
492
|
+
return recipients;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2017 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 { InMemorySessions } from '../../lib-server/resources/mem-backed-sessions-factory';
|
|
19
|
+
import { Request as Req, SessionParams, Factory } from '../../lib-server/resources/sessions';
|
|
20
|
+
|
|
21
|
+
export type SessionsFactory = Factory<SessionParams>;
|
|
22
|
+
export type Request = Req<SessionParams>;
|
|
23
|
+
|
|
24
|
+
function makeSessionParams(): SessionParams {
|
|
25
|
+
return { userId: (undefined as any) };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* This returns factory, that works properly in a single process application,
|
|
30
|
+
* clearing up sessions that past given timeout.
|
|
31
|
+
* @param timeout is a session timeout in seconds
|
|
32
|
+
*/
|
|
33
|
+
export function makeSessionFactory(timeout: number): SessionsFactory {
|
|
34
|
+
return InMemorySessions.factory<SessionParams>(timeout, makeSessionParams);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,96 @@
|
|
|
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 { Express } from 'express';
|
|
19
|
+
import { emptyBody } from '../lib-server/middleware/body-parsers';
|
|
20
|
+
import { UserSockets, AppWithWSs } from '../lib-server/web-sockets/app';
|
|
21
|
+
import { ServerEvents } from '../lib-server/web-sockets/server-events';
|
|
22
|
+
import { SessionsFactory } from './resources/sessions';
|
|
23
|
+
import { MsgRetrieval } from './resources/recipients';
|
|
24
|
+
import { MidAuthorizer } from '../lib-server/routes/sessions/mid-auth';
|
|
25
|
+
import { closeSession } from '../lib-server/routes/sessions/close';
|
|
26
|
+
import { listMsgIds } from './routes/retrieval/list-messages';
|
|
27
|
+
import { getMsgMeta } from './routes/retrieval/get-message-meta';
|
|
28
|
+
import { deleteMsg } from './routes/retrieval/remove-message';
|
|
29
|
+
import { getMsgObj } from './routes/retrieval/get-message-obj';
|
|
30
|
+
import * as api from '../lib-common/service-api/asmail/retrieval';
|
|
31
|
+
import { addMailerIdLoginRoutes } from '../lib-server/mid-access';
|
|
32
|
+
|
|
33
|
+
const WS_PING_PERIOD_MILLIS = 2*60*1000;
|
|
34
|
+
|
|
35
|
+
export function makeApp(
|
|
36
|
+
domain: string, sessions: SessionsFactory, recipients: MsgRetrieval, midAuthorizer: MidAuthorizer
|
|
37
|
+
): AppWithWSs {
|
|
38
|
+
|
|
39
|
+
const app = new AppWithWSs();
|
|
40
|
+
|
|
41
|
+
setHttpPart(app.http, domain, sessions, recipients, midAuthorizer);
|
|
42
|
+
setWSPart(app, sessions, recipients);
|
|
43
|
+
|
|
44
|
+
return app;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function setWSPart(app: AppWithWSs, sessions: SessionsFactory, recipients: MsgRetrieval): void {
|
|
48
|
+
const sockets = new UserSockets(sessions.ensureAuthorizedSessionForSocketStart(), WS_PING_PERIOD_MILLIS);
|
|
49
|
+
|
|
50
|
+
const mailEvents = new ServerEvents(
|
|
51
|
+
undefined,
|
|
52
|
+
[ api.msgRecievedCompletely.EVENT_NAME, api.msgMainObjRecieved.EVENT_NAME ],
|
|
53
|
+
sockets.socketGetter
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
// give events ipc to both ends
|
|
57
|
+
sockets.addSocketIPC(mailEvents);
|
|
58
|
+
recipients.setMailEventsSink(mailEvents.eventsSink);
|
|
59
|
+
|
|
60
|
+
app.addWS(api.wsEventChannel.URL_END, sockets);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function setHttpPart(
|
|
64
|
+
app: Express, domain: string, sessions: SessionsFactory, recipients: MsgRetrieval, midAuthorizer: MidAuthorizer
|
|
65
|
+
): void {
|
|
66
|
+
app.disable('etag');
|
|
67
|
+
|
|
68
|
+
// Login
|
|
69
|
+
addMailerIdLoginRoutes(app, domain, '/'+api.midLogin.MID_URL_PART, sessions, recipients.exists, midAuthorizer);
|
|
70
|
+
|
|
71
|
+
// *** Require authorized session for everything below ***
|
|
72
|
+
app.use(sessions.ensureAuthorizedSession());
|
|
73
|
+
|
|
74
|
+
app.post('/'+api.closeSession.URL_END,
|
|
75
|
+
emptyBody(),
|
|
76
|
+
closeSession()
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
app.get('/'+api.listMsgs.EXPRESS_URL_END,
|
|
80
|
+
listMsgIds(recipients.getMsgIds)
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
app.get('/'+api.msgMetadata.EXPRESS_URL_END,
|
|
84
|
+
getMsgMeta(recipients.getMsgMeta)
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
app.delete('/'+api.rmMsg.EXPRESS_URL_END,
|
|
88
|
+
deleteMsg(recipients.deleteMsg)
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
app.get('/'+api.msgObj.EXPRESS_URL_END,
|
|
92
|
+
getMsgObj(recipients.getObj)
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
Object.freeze(exports);
|
|
@@ -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);
|