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,429 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2015 - 2016, 2020 - 2021 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 provides administrative functionality, like adding new users,
|
|
20
|
+
* changing users quotas, etc.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import * as fs from '../../lib-common/async-fs-node';
|
|
24
|
+
import { writeFileSync, readdirSync } from 'fs';
|
|
25
|
+
import * as jwk from '../../lib-common/jwkeys';
|
|
26
|
+
import * as nacl from 'ecma-nacl';
|
|
27
|
+
import { UserMidParams, UserStorageParams } from '../../lib-common/admin-api/signup';
|
|
28
|
+
import * as asmailConf from '../../lib-common/service-api/asmail/config';
|
|
29
|
+
import { join } from 'path';
|
|
30
|
+
import { createFolderTreeSync, treeInRootFolder, treeInDefaultsFolder, DefaultsDataTree, addressToFName, treeInUserFolder, createFolderTree } from '../../lib-server/resources/server-data-folders';
|
|
31
|
+
import { MultiDomainSignupCtx, SignupContext, addressesForName, canCreateUser, parseToken, areTokensSame } from '../signup-tokens';
|
|
32
|
+
import { errWithCause } from '../../lib-common/exceptions/error';
|
|
33
|
+
|
|
34
|
+
export const SC = {
|
|
35
|
+
USER_ALREADY_EXIST: 'user-already-exist',
|
|
36
|
+
CREATION_UNAUTHORIZED: 'creation-unauthorized'
|
|
37
|
+
};
|
|
38
|
+
Object.freeze(SC);
|
|
39
|
+
|
|
40
|
+
const MID_KEY_USE = 'login-pub-key';
|
|
41
|
+
|
|
42
|
+
function checkDefaultMidKeyParams(params: UserMidParams): boolean {
|
|
43
|
+
const ok = ('object' === typeof params.defaultPKey) &&
|
|
44
|
+
!!params.defaultPKey &&
|
|
45
|
+
jwk.isLikeJsonKey(params.defaultPKey.pkey) &&
|
|
46
|
+
(typeof params.defaultPKey.kdParams === 'object') &&
|
|
47
|
+
!!params.defaultPKey.kdParams;
|
|
48
|
+
if (!ok) { return false; }
|
|
49
|
+
try {
|
|
50
|
+
jwk.keyFromJson(params.defaultPKey.pkey, MID_KEY_USE,
|
|
51
|
+
nacl.box.JWK_ALG_NAME, nacl.box.KEY_LENGTH);
|
|
52
|
+
return true;
|
|
53
|
+
} catch (err) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function validateUserMidParams(params: UserMidParams): boolean {
|
|
59
|
+
const ok = ('object' === typeof params) && !!params &&
|
|
60
|
+
checkDefaultMidKeyParams(params) &&
|
|
61
|
+
Array.isArray(params.otherPKeys) &&
|
|
62
|
+
(params.otherPKeys.length > 0);
|
|
63
|
+
if (!ok) { return false; }
|
|
64
|
+
for (const pkey of params.otherPKeys) {
|
|
65
|
+
try {
|
|
66
|
+
jwk.keyFromJson(pkey, MID_KEY_USE,
|
|
67
|
+
nacl.box.JWK_ALG_NAME, nacl.box.KEY_LENGTH);
|
|
68
|
+
} catch (err) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
if (!pkey.kid) { return false; }
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function validateUserStorageParams(params: UserStorageParams): boolean {
|
|
77
|
+
return ((typeof params === 'object') && !!params &&
|
|
78
|
+
(typeof params.kdParams === 'object') && !!params.kdParams);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* This returns a promise, resolvable to an array of domains, that are
|
|
83
|
+
* available for a given token. Array may be empty, when there are no
|
|
84
|
+
* such domains.
|
|
85
|
+
* @param signupToken
|
|
86
|
+
* @return a promise, resolvable to available addresses for a given name.
|
|
87
|
+
* If array is empty, there are no available addresses for a given name.
|
|
88
|
+
*/
|
|
89
|
+
export type IAvailableDomains = (
|
|
90
|
+
signupToken: string|undefined
|
|
91
|
+
) => Promise<string[]>;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* This returns a promise, resolvable to an array of addresses, that are
|
|
95
|
+
* available for a given string. Array may be empty, when there are no
|
|
96
|
+
* such addresses.
|
|
97
|
+
* @param name is a name part of address, or not a domain part.
|
|
98
|
+
* @param signupToken
|
|
99
|
+
* @return a promise, resolvable to available addresses for a given name.
|
|
100
|
+
* If array is empty, there are no available addresses for a given name.
|
|
101
|
+
*/
|
|
102
|
+
export type IAvailableAddressesForName = (
|
|
103
|
+
name: string, signupToken: string|undefined
|
|
104
|
+
) => Promise<string[]>;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* This creates a user, returning a promise, resolvable when a new account has
|
|
108
|
+
* been created for a given user id.
|
|
109
|
+
* @param userId is user's address. Notice that this is not a canonical form,
|
|
110
|
+
* but user-likable variant.
|
|
111
|
+
* @param midParams MailerId parameters to save
|
|
112
|
+
* @param storeParams storage parameters to save
|
|
113
|
+
* @param signupToken
|
|
114
|
+
* @return a promise, resolvable, when user is added, and all parameters are
|
|
115
|
+
* saved.
|
|
116
|
+
*/
|
|
117
|
+
export type IAdd = (
|
|
118
|
+
userId: string, midParams: UserMidParams, storeParams: any,
|
|
119
|
+
signupToken: string|undefined
|
|
120
|
+
) => Promise<void>;
|
|
121
|
+
|
|
122
|
+
export interface Factory {
|
|
123
|
+
getAvailableDomains: IAvailableDomains;
|
|
124
|
+
getAvailableAddresses: IAvailableAddressesForName;
|
|
125
|
+
add: IAdd;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async function writeJson(path: string, json: any): Promise<void> {
|
|
129
|
+
return fs.writeFile(path, JSON.stringify(json),
|
|
130
|
+
{ encoding: 'utf8', flag: 'w', mode: '660' });
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function writeJsonSync(path: string, json: any): void {
|
|
134
|
+
writeFileSync(path, JSON.stringify(json),
|
|
135
|
+
{ encoding: 'utf8', flag: 'w', mode: '660' });
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function setGeneralDefaults(defaults: DefaultsDataTree): void {
|
|
139
|
+
const infoFolder = defaults.info.path;
|
|
140
|
+
writeJsonSync(join(infoFolder, 'quota'), 100*1024*1024*1024);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function setStoreDefaults(store: DefaultsDataTree['store']): void {
|
|
144
|
+
const sp = store.params.path;
|
|
145
|
+
writeJsonSync(join(sp, 'key-deriv'), null);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function setMailDefaults(mail: DefaultsDataTree['mail']): void {
|
|
149
|
+
writeJsonSync(join(mail.params.path, 'pubkey'), null);
|
|
150
|
+
const anonFolder = mail.params.anonymous.path;
|
|
151
|
+
const anonPolicy: asmailConf.p.anonSenderPolicy.Policy = {
|
|
152
|
+
accept: true,
|
|
153
|
+
acceptWithInvitesOnly: false,
|
|
154
|
+
defaultMsgSize: 1024*1024
|
|
155
|
+
};
|
|
156
|
+
writeJsonSync(join(anonFolder, 'policy'), anonPolicy);
|
|
157
|
+
writeJsonSync(join(anonFolder, 'invites'), {});
|
|
158
|
+
const authFolder = mail.params.authenticated.path;
|
|
159
|
+
const authPolicy: asmailConf.p.authSenderPolicy.Policy = {
|
|
160
|
+
acceptWithInvitesOnly: false,
|
|
161
|
+
acceptFromWhiteListOnly: false,
|
|
162
|
+
applyBlackList: true,
|
|
163
|
+
defaultMsgSize: 1024*1024
|
|
164
|
+
}
|
|
165
|
+
writeJsonSync(join(authFolder, 'policy'), authPolicy);
|
|
166
|
+
writeJsonSync(join(authFolder, 'whitelist'), {});
|
|
167
|
+
writeJsonSync(join(authFolder, 'blacklist'), {});
|
|
168
|
+
writeJsonSync(join(authFolder, 'invites'), {});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
class Users {
|
|
173
|
+
|
|
174
|
+
private readonly users: string;
|
|
175
|
+
private readonly defaults: string;
|
|
176
|
+
private readonly tokens: string;
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
constructor(
|
|
180
|
+
rootFolder: string,
|
|
181
|
+
private readonly noTokenFile?: string
|
|
182
|
+
) {
|
|
183
|
+
if (!fs.existsFolderSync(rootFolder)) { throw new Error(
|
|
184
|
+
`Given root folder does not exist: ${rootFolder}`); }
|
|
185
|
+
const folders = treeInRootFolder(rootFolder);
|
|
186
|
+
createFolderTreeSync(folders);
|
|
187
|
+
this.users = folders.users.path;
|
|
188
|
+
this.defaults = folders.defaults.path;
|
|
189
|
+
this.tokens = folders.tokens.path;
|
|
190
|
+
this.populateDefaultsIfEmpty();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
private populateDefaultsIfEmpty(): void {
|
|
194
|
+
if (readdirSync(this.defaults).length > 0) { return; }
|
|
195
|
+
const defaults = treeInDefaultsFolder(this.defaults);
|
|
196
|
+
createFolderTreeSync(defaults);
|
|
197
|
+
setGeneralDefaults(defaults);
|
|
198
|
+
setMailDefaults(defaults.mail);
|
|
199
|
+
setStoreDefaults(defaults.store);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
private userFolderPath(userId: string): string {
|
|
203
|
+
return join(this.users, addressToFName(userId));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
async add(
|
|
207
|
+
userId: string, midParams: UserMidParams, storeKeyDerivParams: any,
|
|
208
|
+
signupToken: string|undefined
|
|
209
|
+
): Promise<void> {
|
|
210
|
+
if (!validateUserMidParams(midParams)) { throw new Error(
|
|
211
|
+
'Invalid MailerId parameters are given'); }
|
|
212
|
+
if (!storeKeyDerivParams) { throw new Error(
|
|
213
|
+
'Store key derivation parameters are not given'); }
|
|
214
|
+
const rmToken = await this.checkIfCreationAllowed(userId, signupToken);
|
|
215
|
+
const userFolder = this.userFolderPath(userId);
|
|
216
|
+
await fs.mkdir(userFolder).catch((err: fs.FileException) => {
|
|
217
|
+
if (err.alreadyExists) {
|
|
218
|
+
throw SC.USER_ALREADY_EXIST;
|
|
219
|
+
} else {
|
|
220
|
+
throw err;
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
try {
|
|
224
|
+
// make folder tree
|
|
225
|
+
const tree = treeInUserFolder(userFolder);
|
|
226
|
+
await createFolderTree(tree);
|
|
227
|
+
// record user id
|
|
228
|
+
await fs.writeFile(
|
|
229
|
+
join(tree.info.path, 'userid'),
|
|
230
|
+
userId, { encoding: 'utf8', flag: 'w', mode: '440' });
|
|
231
|
+
// copy defaults
|
|
232
|
+
await fs.copyTree(this.defaults, userFolder);
|
|
233
|
+
// record mid parameters
|
|
234
|
+
await writeJson(
|
|
235
|
+
join(tree.info.path, 'mid-params'),
|
|
236
|
+
midParams);
|
|
237
|
+
// record storage params
|
|
238
|
+
await writeJson(
|
|
239
|
+
join(tree.store.params.path, 'key-deriv'),
|
|
240
|
+
storeKeyDerivParams);
|
|
241
|
+
if (rmToken) {
|
|
242
|
+
await rmToken();
|
|
243
|
+
}
|
|
244
|
+
} catch (e) {
|
|
245
|
+
await fs.rmDirWithContent(userFolder).catch(err => {});
|
|
246
|
+
throw e;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
private async checkIfCreationAllowed(
|
|
251
|
+
userId: string, signupToken: string|undefined
|
|
252
|
+
): Promise<(() => Promise<void>)|undefined> {
|
|
253
|
+
if (signupToken) {
|
|
254
|
+
const t = parseToken(signupToken);
|
|
255
|
+
if (!t) { throw SC.CREATION_UNAUTHORIZED; }
|
|
256
|
+
const ctxFilePath = join(this.tokens, t.tokenFile);
|
|
257
|
+
const str = await fs.readFile(ctxFilePath, { encoding: 'utf8' })
|
|
258
|
+
.catch((exc: fs.FileException) => {
|
|
259
|
+
throw (exc.notFound ? SC.CREATION_UNAUTHORIZED : exc);
|
|
260
|
+
});
|
|
261
|
+
try {
|
|
262
|
+
const ctx = JSON.parse(str) as SignupContext;
|
|
263
|
+
if (ctx.token && !areTokensSame(t.tokenBytes, ctx.token)) {
|
|
264
|
+
throw SC.CREATION_UNAUTHORIZED;
|
|
265
|
+
}
|
|
266
|
+
if (canCreateUser(userId, ctx)) {
|
|
267
|
+
if (ctx.type === 'single-user') {
|
|
268
|
+
return () => fs.unlink(ctxFilePath).catch(noop);
|
|
269
|
+
} else {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
} catch (err) {
|
|
274
|
+
throw errWithCause(err, `Error occured in using file ${
|
|
275
|
+
ctxFilePath} as a signup context.`);
|
|
276
|
+
}
|
|
277
|
+
} else if (this.noTokenFile) {
|
|
278
|
+
try {
|
|
279
|
+
const str = await fs.readFile(
|
|
280
|
+
this.noTokenFile, { encoding: 'utf8' });
|
|
281
|
+
const ctx = JSON.parse(str) as MultiDomainSignupCtx;
|
|
282
|
+
if (canCreateUser(userId, ctx)) { return; }
|
|
283
|
+
} catch (exc) {
|
|
284
|
+
if (!(exc as fs.FileException).notFound) {
|
|
285
|
+
throw errWithCause(exc, `Error occured in using file ${
|
|
286
|
+
this.noTokenFile} as a no-token signup context.`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
throw SC.CREATION_UNAUTHORIZED;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
async getAvailableDomains(signupToken: string|undefined): Promise<string[]> {
|
|
294
|
+
if (signupToken) {
|
|
295
|
+
const t = parseToken(signupToken);
|
|
296
|
+
if (!t) { return []; }
|
|
297
|
+
const ctxFilePath = join(this.tokens, t.tokenFile);
|
|
298
|
+
const str = await fs.readFile(ctxFilePath, { encoding: 'utf8' })
|
|
299
|
+
.catch((exc: fs.FileException) => {
|
|
300
|
+
if (exc.notFound) { return; }
|
|
301
|
+
else { throw exc; }
|
|
302
|
+
});
|
|
303
|
+
if (!str) {
|
|
304
|
+
return [];
|
|
305
|
+
}
|
|
306
|
+
try {
|
|
307
|
+
const ctx = JSON.parse(str) as SignupContext;
|
|
308
|
+
if ((ctx.type === 'single-user')
|
|
309
|
+
|| (ctx.token && !areTokensSame(t.tokenBytes, ctx.token))) {
|
|
310
|
+
return [];
|
|
311
|
+
} else {
|
|
312
|
+
return ctx.domains;
|
|
313
|
+
}
|
|
314
|
+
} catch (err) {
|
|
315
|
+
throw errWithCause(err, `Error occured in using file ${
|
|
316
|
+
ctxFilePath} as a signup context.`);
|
|
317
|
+
}
|
|
318
|
+
} else if (this.noTokenFile) {
|
|
319
|
+
try {
|
|
320
|
+
const str = await fs.readFile(
|
|
321
|
+
this.noTokenFile, { encoding: 'utf8' });
|
|
322
|
+
const ctx = JSON.parse(str) as MultiDomainSignupCtx;
|
|
323
|
+
return ctx.domains;
|
|
324
|
+
} catch (exc) {
|
|
325
|
+
if ((exc as fs.FileException).notFound) {
|
|
326
|
+
return [];
|
|
327
|
+
} else {
|
|
328
|
+
throw errWithCause(exc, `Error occured in using file ${
|
|
329
|
+
this.noTokenFile} as a no-token signup context.`);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
} else {
|
|
333
|
+
return [];
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
async getAvailableAddresses(
|
|
338
|
+
name: string, signupToken: string|undefined
|
|
339
|
+
): Promise<string[]> {
|
|
340
|
+
if (signupToken) {
|
|
341
|
+
const t = parseToken(signupToken);
|
|
342
|
+
if (!t) { return []; }
|
|
343
|
+
const ctxFilePath = join(this.tokens, t.tokenFile);
|
|
344
|
+
const str = await fs.readFile(ctxFilePath, { encoding: 'utf8' })
|
|
345
|
+
.catch((exc: fs.FileException) => {
|
|
346
|
+
if (exc.notFound) { return; }
|
|
347
|
+
else { throw exc; }
|
|
348
|
+
});
|
|
349
|
+
if (!str) {
|
|
350
|
+
return [];
|
|
351
|
+
}
|
|
352
|
+
try {
|
|
353
|
+
const ctx = JSON.parse(str) as SignupContext;
|
|
354
|
+
if (ctx.token && !areTokensSame(t.tokenBytes, ctx.token)) {
|
|
355
|
+
return [];
|
|
356
|
+
}
|
|
357
|
+
return this.availableAddressInCtx(name, ctx);
|
|
358
|
+
} catch (err) {
|
|
359
|
+
throw errWithCause(err, `Error occured in using file ${
|
|
360
|
+
ctxFilePath} as a signup context.`);
|
|
361
|
+
}
|
|
362
|
+
} else if (this.noTokenFile) {
|
|
363
|
+
try {
|
|
364
|
+
const str = await fs.readFile(
|
|
365
|
+
this.noTokenFile, { encoding: 'utf8' });
|
|
366
|
+
const ctx = JSON.parse(str) as MultiDomainSignupCtx;
|
|
367
|
+
return this.availableAddressInCtx(name, ctx);
|
|
368
|
+
} catch (exc) {
|
|
369
|
+
if ((exc as fs.FileException).notFound) {
|
|
370
|
+
return [];
|
|
371
|
+
} else {
|
|
372
|
+
throw errWithCause(exc, `Error occured in using file ${
|
|
373
|
+
this.noTokenFile} as a no-token signup context.`);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
} else {
|
|
377
|
+
return [];
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
private async availableAddressInCtx(
|
|
382
|
+
name: string, ctx: SignupContext
|
|
383
|
+
): Promise<string[]> {
|
|
384
|
+
const allIds = addressesForName(name, ctx);
|
|
385
|
+
if (!allIds) {
|
|
386
|
+
return [];
|
|
387
|
+
}
|
|
388
|
+
const availableIds: string[] = [];
|
|
389
|
+
for (const userId of allIds) {
|
|
390
|
+
const userExist = await this.isUserPresent(userId);
|
|
391
|
+
if (!userExist) {
|
|
392
|
+
availableIds.push(userId);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return availableIds;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
private async isUserPresent(id: string): Promise<boolean> {
|
|
399
|
+
const userFolder = this.userFolderPath(id);
|
|
400
|
+
try {
|
|
401
|
+
const stats = await fs.stat(userFolder);
|
|
402
|
+
return stats.isDirectory();
|
|
403
|
+
} catch (err) {
|
|
404
|
+
if ((err as fs.FileException).notFound) { return false; }
|
|
405
|
+
else { throw err; }
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
wrap(): Factory {
|
|
410
|
+
const wrap: Factory = {
|
|
411
|
+
getAvailableDomains: this.getAvailableDomains.bind(this),
|
|
412
|
+
getAvailableAddresses: this.getAvailableAddresses.bind(this),
|
|
413
|
+
add: this.add.bind(this),
|
|
414
|
+
};
|
|
415
|
+
Object.freeze(wrap);
|
|
416
|
+
return wrap;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function noop() {}
|
|
422
|
+
|
|
423
|
+
export function makeFactory(
|
|
424
|
+
rootFolder: string, noTokenFile: string|undefined
|
|
425
|
+
): Factory {
|
|
426
|
+
return (new Users(rootFolder, noTokenFile)).wrap();
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2015 - 2016, 2020, 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 { addUser as api, ERR_SC } from '../../lib-common/admin-api/signup';
|
|
20
|
+
import { IAdd, SC as userSC, validateUserMidParams, validateUserStorageParams } from '../resources/users';
|
|
21
|
+
import { checkAndTransformAddress } from '../../lib-common/canonical-address';
|
|
22
|
+
|
|
23
|
+
export function addUser(addUserFunc: IAdd): RequestHandler {
|
|
24
|
+
|
|
25
|
+
return async function(req, res, next) {
|
|
26
|
+
|
|
27
|
+
const {
|
|
28
|
+
mailerId, storage, userId, signupToken
|
|
29
|
+
} = req.body as api.Request;
|
|
30
|
+
|
|
31
|
+
if (('string' !== typeof userId)
|
|
32
|
+
|| !checkAndTransformAddress(userId)) {
|
|
33
|
+
res.status(ERR_SC.malformed).send('Given user id is malformed.');
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (!validateUserMidParams(mailerId)) {
|
|
37
|
+
res.status(ERR_SC.malformed).send('MailerId parameters are malformed.');
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (!validateUserStorageParams(storage)) {
|
|
41
|
+
res.status(ERR_SC.malformed).send('Storage parameters are malformed.');
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if ((signupToken !== undefined) && (typeof signupToken !== 'string')) {
|
|
45
|
+
res.status(ERR_SC.malformed).send('signupToken is invalid.');
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
await addUserFunc(userId, mailerId, storage.kdParams, signupToken);
|
|
51
|
+
res.status(api.SC.ok).send();
|
|
52
|
+
} catch (err) {
|
|
53
|
+
if (err === userSC.USER_ALREADY_EXIST) {
|
|
54
|
+
res.status(api.SC.userAlreadyExists).send();
|
|
55
|
+
} else if (err === userSC.CREATION_UNAUTHORIZED) {
|
|
56
|
+
res.status(api.SC.unauthorized).send();
|
|
57
|
+
} else {
|
|
58
|
+
next(err);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2015 - 2016, 2020 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 { availableAddressesForName as api, ERR_SC } from '../../lib-common/admin-api/signup';
|
|
20
|
+
import { IAvailableAddressesForName } from '../resources/users';
|
|
21
|
+
|
|
22
|
+
export function availableAddresses(
|
|
23
|
+
availableAddressesFunc: IAvailableAddressesForName
|
|
24
|
+
): RequestHandler {
|
|
25
|
+
|
|
26
|
+
return async function (req, res, next) {
|
|
27
|
+
|
|
28
|
+
const { name, signupToken } = req.body as api.Request;
|
|
29
|
+
|
|
30
|
+
if ((typeof name !== 'string') || (name.indexOf('@') >= 0)) {
|
|
31
|
+
res.status(ERR_SC.malformed).send('name is missing or invalid.');
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if ((signupToken !== undefined) && (typeof signupToken !== 'string')) {
|
|
35
|
+
res.status(ERR_SC.malformed).send('signupToken is invalid.');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
const addresses = await availableAddressesFunc(name, signupToken);
|
|
41
|
+
res.status(api.SC.ok).json(addresses);
|
|
42
|
+
} catch (err) {
|
|
43
|
+
next(err);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2021 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 { availableDomains as api, ERR_SC } from '../../lib-common/admin-api/signup';
|
|
20
|
+
import { IAvailableDomains } from '../resources/users';
|
|
21
|
+
|
|
22
|
+
export function availableDomains(
|
|
23
|
+
availableDomainsFunc: IAvailableDomains
|
|
24
|
+
): RequestHandler {
|
|
25
|
+
|
|
26
|
+
return async function (req, res, next) {
|
|
27
|
+
|
|
28
|
+
const { signupToken } = req.body as api.Request;
|
|
29
|
+
|
|
30
|
+
if ((signupToken !== undefined) && (typeof signupToken !== 'string')) {
|
|
31
|
+
res.status(ERR_SC.malformed).send('signupToken is invalid.');
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
const addresses = await availableDomainsFunc(signupToken);
|
|
37
|
+
res.status(api.SC.ok).json(addresses);
|
|
38
|
+
} catch (err) {
|
|
39
|
+
next(err);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2015 - 2016, 2020 - 2021, 2024 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 * as express from 'express';
|
|
19
|
+
import { json as parseJSON } from '../lib-server/middleware/body-parsers';
|
|
20
|
+
import { ErrLogger, makeErrHandler } from '../lib-server/middleware/error-handler';
|
|
21
|
+
import { makeFactory as makeUserFactory } from './resources/users';
|
|
22
|
+
import { addUser } from './routes/add';
|
|
23
|
+
import { availableAddresses } from './routes/get-available-addresses';
|
|
24
|
+
import { availableDomains } from './routes/get-available-domains';
|
|
25
|
+
import * as signupApi from '../lib-common/admin-api/signup';
|
|
26
|
+
import { Configurations } from '../services';
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
export function makeSignupApp(
|
|
30
|
+
conf: Configurations, errLogger?: ErrLogger
|
|
31
|
+
): express.Express {
|
|
32
|
+
const app = express();
|
|
33
|
+
app.disable('etag');
|
|
34
|
+
|
|
35
|
+
const noTokenFile = (conf.signup ? conf.signup.noTokenFile : undefined);
|
|
36
|
+
const users = makeUserFactory(conf.rootFolder, noTokenFile);
|
|
37
|
+
|
|
38
|
+
app.post('/'+signupApi.availableDomains.URL_END,
|
|
39
|
+
parseJSON('1kb'),
|
|
40
|
+
availableDomains(users.getAvailableDomains));
|
|
41
|
+
app.post('/'+signupApi.availableAddressesForName.URL_END,
|
|
42
|
+
parseJSON('1kb'),
|
|
43
|
+
availableAddresses(users.getAvailableAddresses));
|
|
44
|
+
app.post('/'+signupApi.addUser.URL_END,
|
|
45
|
+
parseJSON('4kb'),
|
|
46
|
+
addUser(users.add));
|
|
47
|
+
|
|
48
|
+
app.use(makeErrHandler(errLogger));
|
|
49
|
+
|
|
50
|
+
return app;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
Object.freeze(exports);
|