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,122 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2017, 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 { GetCurrentObj, SC as storeSC } from '../../resources/users';
|
|
20
|
+
import { GetObjQueryOpts, ERR_SC, HTTP_HEADER, BIN_TYPE, currentObj as api } from '../../../lib-common/service-api/3nstorage/owner';
|
|
21
|
+
import { Request } from '../../resources/sessions';
|
|
22
|
+
import { errWithCause, stringifyErr } from '../../../lib-common/exceptions/error';
|
|
23
|
+
import { EMPTY_BUFFER } from '../../../lib-common/buffer-utils';
|
|
24
|
+
|
|
25
|
+
function extractQueryOptions(req: Request): undefined|{
|
|
26
|
+
header: boolean; limit: number|undefined; ofs: number;
|
|
27
|
+
ver: number|undefined;
|
|
28
|
+
} {
|
|
29
|
+
// query fields are string or undefined, yet, type info helps the show
|
|
30
|
+
const query: GetObjQueryOpts = req.query;
|
|
31
|
+
|
|
32
|
+
const header = ((query.header as any) === 'true');
|
|
33
|
+
|
|
34
|
+
const ofs = (query.ofs ? parseInt(query.ofs as any) : 0);
|
|
35
|
+
if (isNaN(ofs) ||
|
|
36
|
+
(ofs < 0) ||
|
|
37
|
+
(header && (ofs > 0))) { return; }
|
|
38
|
+
|
|
39
|
+
const limit = (query.limit ? parseInt(query.limit as any) : undefined);
|
|
40
|
+
if (limit !== undefined) {
|
|
41
|
+
if (isNaN(limit) ||
|
|
42
|
+
(limit < 0) ||
|
|
43
|
+
(!header && (limit === 0))) { return; }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let ver = (query.ver ? parseInt(query.ver as any) : undefined);
|
|
47
|
+
if (ver !== undefined) {
|
|
48
|
+
if (isNaN(ver!)) {
|
|
49
|
+
ver = undefined;
|
|
50
|
+
} else if (ver < 1) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return { header, limit, ofs, ver };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function getCurrentObj(
|
|
59
|
+
root: boolean, getCurrentObjFunc: GetCurrentObj
|
|
60
|
+
): RequestHandler {
|
|
61
|
+
if ('function' !== typeof getCurrentObjFunc) { throw new TypeError(
|
|
62
|
+
"Given argument 'getCurrentObjFunc' must be function, but is not."); }
|
|
63
|
+
|
|
64
|
+
return async (req: Request, res, next) => {
|
|
65
|
+
|
|
66
|
+
const userId = req.session.params.userId;
|
|
67
|
+
const objId: string = (root ? null as any : req.params.objId);
|
|
68
|
+
|
|
69
|
+
const opts = extractQueryOptions(req);
|
|
70
|
+
if (!opts) {
|
|
71
|
+
res.status(ERR_SC.malformed).send("Bad query parameters");
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
const { version, reader } = await getCurrentObjFunc(userId, objId,
|
|
77
|
+
opts.header, opts.ofs, opts.limit);
|
|
78
|
+
if (opts.ver) {
|
|
79
|
+
if (opts.ver !== version) {
|
|
80
|
+
res.set(HTTP_HEADER.objVersion, `${version}`);
|
|
81
|
+
res.status(api.SC.unknownObjVer).send();
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
res.set(HTTP_HEADER.objVersion, `${version}`);
|
|
86
|
+
}
|
|
87
|
+
res.status(api.SC.okGet);
|
|
88
|
+
res.set(HTTP_HEADER.contentType, BIN_TYPE);
|
|
89
|
+
res.set(HTTP_HEADER.contentLength, `${reader.len}`);
|
|
90
|
+
if (opts.header) {
|
|
91
|
+
res.set(HTTP_HEADER.objHeaderLength, `${reader.headerLen}`);
|
|
92
|
+
}
|
|
93
|
+
res.set(HTTP_HEADER.objSegmentsLength, `${reader.segsLen}`);
|
|
94
|
+
if (reader.len > 0) {
|
|
95
|
+
try {
|
|
96
|
+
await reader.pipe!(res);
|
|
97
|
+
} catch (err) {
|
|
98
|
+
console.error(stringifyErr(errWithCause(err, `Wasn't able to complete sending segments due to error in piping`)));
|
|
99
|
+
} finally {
|
|
100
|
+
res.end();
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
res.send(EMPTY_BUFFER);
|
|
104
|
+
}
|
|
105
|
+
} catch (err) {
|
|
106
|
+
if ("string" !== typeof err) {
|
|
107
|
+
next(err);
|
|
108
|
+
} else if ((err === storeSC.OBJ_UNKNOWN)
|
|
109
|
+
|| (err === storeSC.OBJ_VER_UNKNOWN)) {
|
|
110
|
+
res.status(api.SC.unknownObj).send(objId ? `Object ${objId} is unknown.` : `Root object is not set.`);
|
|
111
|
+
} else if (err === storeSC.USER_UNKNOWN) {
|
|
112
|
+
res.status(ERR_SC.server).send(`Recipient disappeared from the system.`);
|
|
113
|
+
req.session.close();
|
|
114
|
+
} else {
|
|
115
|
+
next(new Error(`Unhandled storage error code: ${err}`));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2022 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 { GetObjStatus, SC as storeSC } from '../../resources/users';
|
|
20
|
+
import { objStatus as api, ERR_SC } from '../../../lib-common/service-api/3nstorage/owner';
|
|
21
|
+
import { Request } from '../../resources/sessions';
|
|
22
|
+
|
|
23
|
+
export function getObjStatus(
|
|
24
|
+
root: boolean, getObjStatusFunc: GetObjStatus
|
|
25
|
+
): RequestHandler {
|
|
26
|
+
if ('function' !== typeof getObjStatusFunc) { throw new TypeError(
|
|
27
|
+
"Given argument 'getObjStatusFunc' must be function, but is not."); }
|
|
28
|
+
|
|
29
|
+
return async (req: Request, res, next) => {
|
|
30
|
+
|
|
31
|
+
const userId = req.session.params.userId;
|
|
32
|
+
const objId: string = (root ? null as any : req.params.objId);
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
const lst = await getObjStatusFunc(userId, objId);
|
|
36
|
+
res.status(api.SC.ok).json(lst);
|
|
37
|
+
} catch (err) {
|
|
38
|
+
if ("string" !== typeof err) {
|
|
39
|
+
next(err);
|
|
40
|
+
} else if (err === storeSC.OBJ_UNKNOWN) {
|
|
41
|
+
res.status(api.SC.unknownObj).send(root ?
|
|
42
|
+
`Root object is set.` : `Object ${objId} is unknown.`);
|
|
43
|
+
} else if (err === storeSC.USER_UNKNOWN) {
|
|
44
|
+
res.status(ERR_SC.server).send(
|
|
45
|
+
"Recipient disappeared from the system.");
|
|
46
|
+
req.session.close();
|
|
47
|
+
} else {
|
|
48
|
+
next(new Error("Unhandled storage error code: "+err));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2015 - 2016 3NSoft Inc.
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
5
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
6
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
7
|
+
version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful, but
|
|
10
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
See the GNU General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU General Public License along with
|
|
15
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { RequestHandler } from 'express';
|
|
19
|
+
import { SC as storeSC } from '../../resources/users';
|
|
20
|
+
import { PARAM_SC, ERR_SC } from '../../../lib-common/service-api/3nstorage/owner';
|
|
21
|
+
import { Request } from '../../resources/sessions';
|
|
22
|
+
|
|
23
|
+
export function getParam<T>(
|
|
24
|
+
paramGetter: (userId: string) => Promise<T>
|
|
25
|
+
): RequestHandler {
|
|
26
|
+
|
|
27
|
+
if ('function' !== typeof paramGetter) { throw new TypeError(
|
|
28
|
+
"Given argument 'paramGetter' must be function, but is not."); }
|
|
29
|
+
|
|
30
|
+
return async (req: Request, res, next) => {
|
|
31
|
+
|
|
32
|
+
const session = req.session;
|
|
33
|
+
const userId = session.params.userId;
|
|
34
|
+
|
|
35
|
+
try{
|
|
36
|
+
const value = await paramGetter(userId);
|
|
37
|
+
res.status(PARAM_SC.ok).json(value);
|
|
38
|
+
} catch (err) {
|
|
39
|
+
if (err === storeSC.USER_UNKNOWN) {
|
|
40
|
+
res.status(ERR_SC.server).send(
|
|
41
|
+
"Recipient disappeared from the system.");
|
|
42
|
+
session.close();
|
|
43
|
+
} else {
|
|
44
|
+
next(err);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2015 - 2016, 2026 3NSoft Inc.
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
5
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
6
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
7
|
+
version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful, but
|
|
10
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
See the GNU General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU General Public License along with
|
|
15
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { RequestHandler } from 'express';
|
|
19
|
+
import { SC as storeSC } from '../../resources/users';
|
|
20
|
+
import { PARAM_SC, ERR_SC } from '../../../lib-common/service-api/3nstorage/owner';
|
|
21
|
+
import { Request } from '../../resources/sessions';
|
|
22
|
+
|
|
23
|
+
export function setParam<T>(
|
|
24
|
+
paramSetter: (userId: string, param: T) => Promise<boolean>
|
|
25
|
+
): RequestHandler {
|
|
26
|
+
|
|
27
|
+
return async (req: Request, res, next) => {
|
|
28
|
+
|
|
29
|
+
const session = req.session;
|
|
30
|
+
const userId = session.params.userId;
|
|
31
|
+
const pValue: T = req.body;
|
|
32
|
+
|
|
33
|
+
try{
|
|
34
|
+
const valChanged = await paramSetter(userId, pValue)
|
|
35
|
+
if (valChanged) {
|
|
36
|
+
res.status(PARAM_SC.ok).send();
|
|
37
|
+
} else {
|
|
38
|
+
res.status(ERR_SC.malformed).send('Malformed parameter value.');
|
|
39
|
+
}
|
|
40
|
+
} catch (err) {
|
|
41
|
+
if (err === storeSC.USER_UNKNOWN) {
|
|
42
|
+
res.status(ERR_SC.server).send("Recipient disappeared from the system.");
|
|
43
|
+
session.close();
|
|
44
|
+
} else {
|
|
45
|
+
next(err);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
}
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2017, 2019 - 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, Response } from 'express';
|
|
19
|
+
import { SaveNewObjVersion, SC as saveSC, MismatchedObjVerException } from '../../resources/users';
|
|
20
|
+
import { currentObj as api, ERR_SC, HTTP_HEADER, BIN_TYPE, PutObjFirstQueryOpts, PutObjSecondQueryOpts, DiffInfo, sanitizedDiff, ErrorReply } from '../../../lib-common/service-api/3nstorage/owner';
|
|
21
|
+
import { stringToNumOfBytes } from '../../../lib-server/conf-util';
|
|
22
|
+
import { Request } from '../../resources/sessions';
|
|
23
|
+
import { attachByteDrainToRequest } from '../../../lib-server/middleware/body-parsers';
|
|
24
|
+
import { Readable as ReadableStream } from 'stream';
|
|
25
|
+
import { BytesFIFOBuffer } from '../../../lib-common/byte-streaming/common';
|
|
26
|
+
import { defer, Deferred } from '../../../lib-common/processes';
|
|
27
|
+
import { utf8, base64urlSafe } from '../../../lib-common/buffer-utils';
|
|
28
|
+
|
|
29
|
+
export function saveCurrentObj(
|
|
30
|
+
root: boolean, saveObjFunc: SaveNewObjVersion, chunkLimit: string|number
|
|
31
|
+
): RequestHandler {
|
|
32
|
+
if ('function' !== typeof saveObjFunc) { throw new TypeError(
|
|
33
|
+
"Given argument 'saveObjFunc' must be function, but is not."); }
|
|
34
|
+
const maxChunkSize = stringToNumOfBytes(chunkLimit);
|
|
35
|
+
|
|
36
|
+
return async (req: Request, res, next) => {
|
|
37
|
+
|
|
38
|
+
if (!req.is(BIN_TYPE)) {
|
|
39
|
+
attachByteDrainToRequest(req);
|
|
40
|
+
res.status(ERR_SC.wrongContentType).json( <ErrorReply> {
|
|
41
|
+
error: `Content-Type must be ${BIN_TYPE} for this call.`
|
|
42
|
+
});
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const userId = req.session.params.userId;
|
|
47
|
+
const objId: string = (root ? null as any : req.params.objId);
|
|
48
|
+
|
|
49
|
+
// get and check Content-Length, implicitly sending replies for bad length
|
|
50
|
+
let len = getContentLenOrSendError(req, res, maxChunkSize);
|
|
51
|
+
if (len === undefined) {
|
|
52
|
+
attachByteDrainToRequest(req);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// extract and check query parameters
|
|
57
|
+
const opts = extractQueryOptions(req);
|
|
58
|
+
if (!opts) { return replyToMalformed(req, "Bad query parameters", res); }
|
|
59
|
+
const { fstReq, sndReq } = opts;
|
|
60
|
+
|
|
61
|
+
let diff: DiffInfo|undefined;
|
|
62
|
+
|
|
63
|
+
if (fstReq) {
|
|
64
|
+
|
|
65
|
+
if (!root && objId) {
|
|
66
|
+
if (!base64urlSafe.allCharsFromAlphabet(objId!)) {
|
|
67
|
+
return replyToMalformed(req, "Bad object id", res);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// cross-check given lengths
|
|
72
|
+
const diffAndHeader = fstReq.header +
|
|
73
|
+
(fstReq.diff ? fstReq.diff : 0);
|
|
74
|
+
if (diffAndHeader > len) {
|
|
75
|
+
return replyToMalformed(req, "Bad query parameters", res);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// read diff, if it is expected
|
|
79
|
+
if (fstReq.diff) {
|
|
80
|
+
let diffBytes = await readChunkFrom(req, fstReq.diff).catch(noop);
|
|
81
|
+
if (diffBytes) {
|
|
82
|
+
len -= fstReq.diff;
|
|
83
|
+
} else {
|
|
84
|
+
return replyToMalformed(req, "Cannot read diff bytes", res);
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
const diffFromReq = JSON.parse(utf8.open(diffBytes));
|
|
88
|
+
diff = sanitizedDiff(diffFromReq, fstReq.ver);
|
|
89
|
+
if (!diff) {
|
|
90
|
+
return replyToMalformed(req, "Malformed diff info", res);
|
|
91
|
+
}
|
|
92
|
+
} catch (err) {
|
|
93
|
+
return replyToMalformed(req, "Malformed diff info", res);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
} else if (sndReq) {
|
|
98
|
+
|
|
99
|
+
if ((len === 0) && !sndReq.last) {
|
|
100
|
+
return replyToMalformed(req, "No segment bytes", res);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
const transactionId = await saveObjFunc(
|
|
107
|
+
userId, objId, fstReq, diff, sndReq, len, req);
|
|
108
|
+
const reply: api.ReplyToPut = (transactionId ? { transactionId } : {});
|
|
109
|
+
res.status(api.SC.okPut).json(reply);
|
|
110
|
+
} catch (err) {
|
|
111
|
+
if ("string" !== typeof err) {
|
|
112
|
+
if ((err as MismatchedObjVerException).type === 'mismatched-obj-ver') {
|
|
113
|
+
const rep: api.MismatchedObjVerReply = {
|
|
114
|
+
error: "Current object version doesn't match assumed one.",
|
|
115
|
+
current_version: (err as MismatchedObjVerException).current_version
|
|
116
|
+
};
|
|
117
|
+
res.set(HTTP_HEADER.objVersion, `${(err as MismatchedObjVerException).current_version}`);
|
|
118
|
+
res.status(api.SC.mismatchedObjVer).json(rep);
|
|
119
|
+
} else {
|
|
120
|
+
next(err);
|
|
121
|
+
}
|
|
122
|
+
} else if ((err === saveSC.OBJ_UNKNOWN)
|
|
123
|
+
|| (err === saveSC.OBJ_VER_UNKNOWN)) {
|
|
124
|
+
res.status(api.SC.unknownObj).json( <ErrorReply> {
|
|
125
|
+
error: `Unknown object ${objId}.`
|
|
126
|
+
});
|
|
127
|
+
} else if (err === saveSC.TRANSACTION_UNKNOWN) {
|
|
128
|
+
res.status(api.SC.unknownTransaction).json( <ErrorReply> {
|
|
129
|
+
error: "Unknown transaction."
|
|
130
|
+
});
|
|
131
|
+
} else if ((err === saveSC.OBJ_EXIST)
|
|
132
|
+
|| (err === saveSC.OBJ_VER_EXIST)) {
|
|
133
|
+
res.status(api.SC.objAlreadyExists).json( <ErrorReply> {
|
|
134
|
+
error: "Object already exists."
|
|
135
|
+
});
|
|
136
|
+
} else if (err === saveSC.CONCURRENT_TRANSACTION) {
|
|
137
|
+
res.status(api.SC.concurrentTransaction).json( <ErrorReply> {
|
|
138
|
+
error: `Object ${objId} is currently under a transaction.`
|
|
139
|
+
});
|
|
140
|
+
} else if (err === saveSC.USER_UNKNOWN) {
|
|
141
|
+
res.status(ERR_SC.server).json( <ErrorReply> {
|
|
142
|
+
error: "Recipient disappeared from the system."
|
|
143
|
+
});
|
|
144
|
+
req.session.close();
|
|
145
|
+
} else if (err === saveSC.NOT_ENOUGH_SPACE) {
|
|
146
|
+
res.status(ERR_SC.noSpace).json( <ErrorReply> {
|
|
147
|
+
error: "Reached storage limits."
|
|
148
|
+
});
|
|
149
|
+
} else if (err === saveSC.OBJ_FILE_INCOMPLETE) {
|
|
150
|
+
res.status(api.SC.objIncomplete).json( <ErrorReply> {
|
|
151
|
+
error: "Object version file is incomplete."
|
|
152
|
+
});
|
|
153
|
+
} else {
|
|
154
|
+
next(new Error(`Unhandled storage error code: ${err}`));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function extractQueryOptions(req: Request): undefined|{
|
|
161
|
+
fstReq?: PutObjFirstQueryOpts; sndReq?: PutObjSecondQueryOpts;
|
|
162
|
+
} {
|
|
163
|
+
if ((req.query as any as PutObjSecondQueryOpts).trans) {
|
|
164
|
+
// this is the second (not first) request
|
|
165
|
+
// query fields are string or undefined, yet, type info helps the show
|
|
166
|
+
const query = req.query as any as PutObjSecondQueryOpts;
|
|
167
|
+
|
|
168
|
+
const trans = query.trans;
|
|
169
|
+
|
|
170
|
+
const last = ((query.last as any) === 'true');
|
|
171
|
+
|
|
172
|
+
const ofs = parseInt(query.ofs as any);
|
|
173
|
+
if (isNaN(ofs)) { return; }
|
|
174
|
+
|
|
175
|
+
return { sndReq: { last, ofs, trans } };
|
|
176
|
+
|
|
177
|
+
} else {
|
|
178
|
+
// this is the first request
|
|
179
|
+
// query fields are string or undefined, yet, type info helps the show
|
|
180
|
+
const query = req.query as any as PutObjFirstQueryOpts;
|
|
181
|
+
|
|
182
|
+
const ver = parseInt(query.ver as any);
|
|
183
|
+
if (isNaN(ver) || (ver < 1)) { return; }
|
|
184
|
+
|
|
185
|
+
const diff = (query.diff ? parseInt(query.diff as any) : undefined);
|
|
186
|
+
if (diff !== undefined) {
|
|
187
|
+
if (isNaN(diff) || (diff < 2) || (diff > 1024)) { return; }
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const header = parseInt(query.header as any);
|
|
191
|
+
if (isNaN(header) || (header < 1)) { return; }
|
|
192
|
+
|
|
193
|
+
const last = ((query.last as any) === 'true');
|
|
194
|
+
|
|
195
|
+
return { fstReq: { diff, header, last, ver } };
|
|
196
|
+
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function getContentLenOrSendError(
|
|
201
|
+
req: Request, res: Response, maxChunkSize: number
|
|
202
|
+
): number|undefined {
|
|
203
|
+
const contentLength = parseInt(req.get(HTTP_HEADER.contentLength)!);
|
|
204
|
+
if (isNaN(contentLength)) {
|
|
205
|
+
res.status(ERR_SC.contentLenMissing).json( <ErrorReply> {
|
|
206
|
+
error: "Content-Length header is required with proper number." });
|
|
207
|
+
} else if (contentLength > maxChunkSize) {
|
|
208
|
+
res.status(ERR_SC.contentTooLong).json( <ErrorReply> {
|
|
209
|
+
error: "Request body is too long." });
|
|
210
|
+
} else {
|
|
211
|
+
return contentLength;
|
|
212
|
+
}
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const EARLY_END_OF_STREAM_ERR_STR = `Unexpected end of stream`;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* This returns a promise of bytes, read from a given stream.
|
|
220
|
+
* Given stream will be paused, when bytes are read. Beware.
|
|
221
|
+
* @param stream
|
|
222
|
+
* @param bytesToRead is a number of bytes to read from a stream. Error is
|
|
223
|
+
* thrown, if stream ends too early.
|
|
224
|
+
*/
|
|
225
|
+
function readChunkFrom(
|
|
226
|
+
stream: ReadableStream, bytesToRead: number
|
|
227
|
+
): Promise<Uint8Array> {
|
|
228
|
+
if (bytesToRead < 1) { throw new Error(
|
|
229
|
+
`Illegal number of bytes to read from stream: ${bytesToRead}`); }
|
|
230
|
+
|
|
231
|
+
const buffer = new BytesFIFOBuffer();
|
|
232
|
+
let deferred: Deferred<Uint8Array>|undefined = defer<Uint8Array>();
|
|
233
|
+
|
|
234
|
+
const complete = (bytes?: Uint8Array, err?: any) => {
|
|
235
|
+
if (!deferred) { return; }
|
|
236
|
+
if (bytes) {
|
|
237
|
+
deferred.resolve(bytes);
|
|
238
|
+
} else {
|
|
239
|
+
deferred.reject(err);
|
|
240
|
+
buffer.clear();
|
|
241
|
+
}
|
|
242
|
+
deferred = undefined;
|
|
243
|
+
stream.removeListener('data', onData);
|
|
244
|
+
stream.removeListener('error', onError);
|
|
245
|
+
stream.removeListener('end', onEnd);
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
const onData = (data: Buffer) => {
|
|
249
|
+
if (!deferred) { return; }
|
|
250
|
+
buffer.push(data);
|
|
251
|
+
if (buffer.length < bytesToRead) { return; }
|
|
252
|
+
stream.pause();
|
|
253
|
+
complete(buffer.getBytes(bytesToRead));
|
|
254
|
+
if (buffer.length === 0) { return; }
|
|
255
|
+
const bytesToUnshift = buffer.getBytes(undefined)!;
|
|
256
|
+
stream.unshift(Buffer.from(
|
|
257
|
+
bytesToUnshift.buffer as ArrayBuffer, bytesToUnshift.byteOffset, bytesToUnshift.length));
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
const onEnd = () => {
|
|
261
|
+
if (!deferred) { return; }
|
|
262
|
+
complete(undefined, EARLY_END_OF_STREAM_ERR_STR);
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
const onError = (err?: any) => {
|
|
266
|
+
if (!deferred) { return; }
|
|
267
|
+
complete(undefined, err);
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
stream.on('data', onData);
|
|
271
|
+
stream.on('error', onError);
|
|
272
|
+
stream.on('end', onEnd);
|
|
273
|
+
|
|
274
|
+
return deferred.promise;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function replyToMalformed(req: Request, msg: string, res: Response): void {
|
|
278
|
+
attachByteDrainToRequest(req);
|
|
279
|
+
res.status(ERR_SC.malformed).json( <ErrorReply> { error: msg });
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function noop() {}
|
|
283
|
+
|
|
284
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2015 - 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 { RequestHandler } from 'express';
|
|
19
|
+
import { SC as storeSC } from '../../resources/users';
|
|
20
|
+
import { sessionParams as api, ERR_SC } from '../../../lib-common/service-api/3nstorage/owner';
|
|
21
|
+
import { stringToNumOfBytes } from '../../../lib-server/conf-util';
|
|
22
|
+
import { Request } from '../../resources/sessions';
|
|
23
|
+
|
|
24
|
+
export function sessionParams(maxChunk: number|string): RequestHandler {
|
|
25
|
+
const maxChunkSize = stringToNumOfBytes(maxChunk);
|
|
26
|
+
|
|
27
|
+
return async (req: Request, res, next) => {
|
|
28
|
+
|
|
29
|
+
const userId = req.session.params.userId;
|
|
30
|
+
|
|
31
|
+
try{
|
|
32
|
+
const reply: api.Reply = { maxChunkSize };
|
|
33
|
+
res.status(api.SC.ok).json(reply);
|
|
34
|
+
} catch (err) {
|
|
35
|
+
if ("string" !== typeof err) {
|
|
36
|
+
next(err);
|
|
37
|
+
} else if (err === storeSC.USER_UNKNOWN) {
|
|
38
|
+
res.status(ERR_SC.server).send(
|
|
39
|
+
"Recipient disappeared from the system.");
|
|
40
|
+
req.session.close();
|
|
41
|
+
} else {
|
|
42
|
+
next(new Error("Unhandled storage error code: "+err));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2015 - 2016 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 { Factory as UsersFactory } from './resources/users';
|
|
21
|
+
import { SessionsFactory } from './resources/sessions';
|
|
22
|
+
//import * as api from '../../lib-common/service-api/3nstorage/shared';
|
|
23
|
+
|
|
24
|
+
export function makeSharedStorageApp(
|
|
25
|
+
sessions: SessionsFactory, users: UsersFactory
|
|
26
|
+
): express.Express {
|
|
27
|
+
|
|
28
|
+
const app = express();
|
|
29
|
+
app.disable('etag');
|
|
30
|
+
|
|
31
|
+
// TODO add sharing routes with proper session creation for authorities/capabilities
|
|
32
|
+
// If capacity needs only PKL entry, then manipulations can be done anonymously.
|
|
33
|
+
// If in addition to PKL, MailerId is required, then it sort of let's server
|
|
34
|
+
// protect against loosing capabilities by user's peers, but at a cost of
|
|
35
|
+
// anonymity.
|
|
36
|
+
// Should we allow MailerId-only authenticating capabilities? No,
|
|
37
|
+
// since sharing peer will anyway need to have a file to store long names
|
|
38
|
+
// and file keys.
|
|
39
|
+
|
|
40
|
+
return app;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
Object.freeze(exports);
|