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,258 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2015 - 2017, 2020, 2025 3NSoft Inc.
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
5
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
6
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
7
|
+
version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful, but
|
|
10
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
See the GNU General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU General Public License along with
|
|
15
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* This module produces users object, which managers users, and manages
|
|
20
|
+
* storage. The whole storage reliance set is located behind user's factory,
|
|
21
|
+
* which is created by this module.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { Readable as ReadableStream } from 'stream';
|
|
25
|
+
import { Store, SC, ObjReader, StorageEventsSink, StorageParams } from './store';
|
|
26
|
+
import { PutObjFirstQueryOpts, PutObjSecondQueryOpts, DiffInfo, ObjStatus } from '../../lib-common/service-api/3nstorage/owner';
|
|
27
|
+
import { userDataInRootFolder } from '../../lib-server/resources/server-data-folders';
|
|
28
|
+
|
|
29
|
+
export { SC, ObjReader, MismatchedObjVerException } from './store';
|
|
30
|
+
|
|
31
|
+
export type UserExists = (userId: string) => Promise<boolean>;
|
|
32
|
+
|
|
33
|
+
export type GetCurrentObj = (
|
|
34
|
+
userId: string, objId: string|null,
|
|
35
|
+
header: boolean, segsOffset: number, segsLimit: number|undefined
|
|
36
|
+
) => Promise<{ version: number; reader: ObjReader; }>;
|
|
37
|
+
|
|
38
|
+
export type SaveNewObjVersion = (
|
|
39
|
+
userId: string, objId: string|null,
|
|
40
|
+
fstReq: PutObjFirstQueryOpts|undefined, diff: DiffInfo|undefined,
|
|
41
|
+
sndReq: PutObjSecondQueryOpts|undefined,
|
|
42
|
+
bytesLen: number, bytes: ReadableStream
|
|
43
|
+
) => Promise<string|undefined>;
|
|
44
|
+
|
|
45
|
+
export type GetArchivedObjVersion = (
|
|
46
|
+
userId: string, objId: string|null, version: number,
|
|
47
|
+
header: boolean, segsOffset: number, segsLimit: number|undefined
|
|
48
|
+
) => Promise<ObjReader>;
|
|
49
|
+
|
|
50
|
+
export type CancelTransaction = (
|
|
51
|
+
userId: string, objId: string, transactionId?: string
|
|
52
|
+
) => Promise<void>;
|
|
53
|
+
|
|
54
|
+
export type ArchiveObjCurrentVersion = (
|
|
55
|
+
userId: string, objId: string, version: number
|
|
56
|
+
) => Promise<void>;
|
|
57
|
+
|
|
58
|
+
export type GetObjStatus = (
|
|
59
|
+
userId: string, objId: string
|
|
60
|
+
) => Promise<ObjStatus>;
|
|
61
|
+
|
|
62
|
+
export type DeleteCurrentObjVersion = (
|
|
63
|
+
userId: string, objId: string, version?: number
|
|
64
|
+
) => Promise<void>;
|
|
65
|
+
|
|
66
|
+
export type DeleteArchivedObjVersion = (
|
|
67
|
+
userId: string, objId: string|null, version: number
|
|
68
|
+
) => Promise<void>;
|
|
69
|
+
|
|
70
|
+
export type GetSpaceQuota = (userId: string) => Promise<number>;
|
|
71
|
+
|
|
72
|
+
type GetParam<P extends keyof StorageParams> = (
|
|
73
|
+
userId: string
|
|
74
|
+
) => Promise<StorageParams[P]>;
|
|
75
|
+
type SetParam<P extends keyof StorageParams> = (
|
|
76
|
+
userId: string, param: StorageParams[P]
|
|
77
|
+
) => Promise<boolean>;
|
|
78
|
+
|
|
79
|
+
export type GetKeyDerivParams = GetParam<'key-deriv'>;
|
|
80
|
+
export type SetKeyDerivParams = SetParam<'key-deriv'>;
|
|
81
|
+
|
|
82
|
+
export type EventsSink = StorageEventsSink;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* This is an external interface, behind which all storage machinery is hidding.
|
|
86
|
+
*/
|
|
87
|
+
export interface Factory {
|
|
88
|
+
exists: UserExists;
|
|
89
|
+
getKeyDerivParams: GetKeyDerivParams;
|
|
90
|
+
setKeyDerivParams: SetKeyDerivParams;
|
|
91
|
+
getSpaceQuota: GetSpaceQuota;
|
|
92
|
+
cancelTransaction: CancelTransaction;
|
|
93
|
+
getCurrentObj: GetCurrentObj;
|
|
94
|
+
saveNewObjVersion: SaveNewObjVersion;
|
|
95
|
+
saveNewRootVersion: SaveNewObjVersion;
|
|
96
|
+
getCurrentRootObj: GetCurrentObj;
|
|
97
|
+
getObjStatus: GetObjStatus;
|
|
98
|
+
archiveObjVersion: ArchiveObjCurrentVersion;
|
|
99
|
+
getArchivedRootVersion: GetArchivedObjVersion;
|
|
100
|
+
getArchivedObjVersion: GetArchivedObjVersion;
|
|
101
|
+
deleteCurrentObjVersion: DeleteCurrentObjVersion;
|
|
102
|
+
deleteArchivedObjVersion: DeleteArchivedObjVersion;
|
|
103
|
+
setStorageEventsSink(sink: EventsSink): void;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function makeFactory(
|
|
107
|
+
rootFolder: string,
|
|
108
|
+
writeBufferSize?: string|number, readBufferSize?: string|number
|
|
109
|
+
): Factory {
|
|
110
|
+
|
|
111
|
+
const stores = new Map<string, Store>();
|
|
112
|
+
|
|
113
|
+
let storageEventsSink: StorageEventsSink|undefined = undefined;
|
|
114
|
+
|
|
115
|
+
async function getStore(userId: string): Promise<Store> {
|
|
116
|
+
if (!storageEventsSink) {
|
|
117
|
+
throw new Error(`Storage events sink is not set`);
|
|
118
|
+
}
|
|
119
|
+
const store = stores.get(userId);
|
|
120
|
+
if (store) {
|
|
121
|
+
try {
|
|
122
|
+
await store.ensureUserExistsOnDisk();
|
|
123
|
+
return store;
|
|
124
|
+
} catch (err) {
|
|
125
|
+
stores.delete(userId);
|
|
126
|
+
throw err;
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
const userFolder = userDataInRootFolder(rootFolder, userId);
|
|
130
|
+
const store = await Store.make(
|
|
131
|
+
userFolder, userId, storageEventsSink,
|
|
132
|
+
writeBufferSize, readBufferSize
|
|
133
|
+
);
|
|
134
|
+
stores.set(userId, store);
|
|
135
|
+
return store;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function makeCurrentObjGetter(isRoot?: boolean): GetCurrentObj {
|
|
140
|
+
return async (userId: string, objId: string|null, header: boolean,
|
|
141
|
+
segsOffset: number, segsLimit: number|undefined) => {
|
|
142
|
+
if ((isRoot && objId) || (!isRoot && !objId)) {
|
|
143
|
+
throw new Error("Mixed object types' functions.");
|
|
144
|
+
}
|
|
145
|
+
const store = await getStore(userId);
|
|
146
|
+
return store.getCurrentObj(objId, header, segsOffset, segsLimit);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function makeArchivedObjGetter(isRoot?: boolean): GetArchivedObjVersion {
|
|
151
|
+
return async (userId: string, objId: string|null, version: number,
|
|
152
|
+
header: boolean, segsOffset: number,
|
|
153
|
+
segsLimit: number|undefined) => {
|
|
154
|
+
if ((isRoot && objId) || (!isRoot && !objId)) {
|
|
155
|
+
throw new Error("Mixed object types' functions.");
|
|
156
|
+
}
|
|
157
|
+
const store = await getStore(userId);
|
|
158
|
+
return store.getArchivedObjVersion(objId, version, header, segsOffset, segsLimit);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function makeObjSaver(isRoot: boolean): SaveNewObjVersion {
|
|
163
|
+
return async (userId: string, objId: string|null,
|
|
164
|
+
fstReq: PutObjFirstQueryOpts|undefined, diff: DiffInfo|undefined,
|
|
165
|
+
sndReq: PutObjSecondQueryOpts|undefined, bytesLen: number,
|
|
166
|
+
bytes: ReadableStream): Promise<string|undefined> => {
|
|
167
|
+
if ((isRoot && objId) || (!isRoot && !objId)) {
|
|
168
|
+
throw new Error("Mixed object types' functions.");
|
|
169
|
+
}
|
|
170
|
+
const store = await getStore(userId);
|
|
171
|
+
if (fstReq) {
|
|
172
|
+
return store.startSavingObjNewVersion(objId, diff,
|
|
173
|
+
bytes, bytesLen, fstReq);
|
|
174
|
+
} else if (sndReq) {
|
|
175
|
+
return store.continueSavingObjNewVersion(objId,
|
|
176
|
+
bytes, bytesLen, sndReq);
|
|
177
|
+
} else {
|
|
178
|
+
throw new Error(`Missing both request options`);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function makeTransactionCanceller(): CancelTransaction {
|
|
184
|
+
return async (userId: string, objId: string, transactionId?: string) => {
|
|
185
|
+
const store = await getStore(userId);
|
|
186
|
+
await store.cancelTransaction(objId, transactionId);
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const factory: Factory = {
|
|
191
|
+
|
|
192
|
+
exists: async userId => {
|
|
193
|
+
try {
|
|
194
|
+
const store = await getStore(userId);
|
|
195
|
+
return true;
|
|
196
|
+
} catch (err) {
|
|
197
|
+
if (err !== SC.USER_UNKNOWN) { throw err; }
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
|
|
202
|
+
getSpaceQuota: async userId => {
|
|
203
|
+
const store = await getStore(userId);
|
|
204
|
+
return await store.getSpaceQuota();
|
|
205
|
+
},
|
|
206
|
+
|
|
207
|
+
getKeyDerivParams: async userId => {
|
|
208
|
+
const store = await getStore(userId);
|
|
209
|
+
return await store.getParam('key-deriv');
|
|
210
|
+
},
|
|
211
|
+
setKeyDerivParams: async (userId, keyParams) => {
|
|
212
|
+
const store = await getStore(userId);
|
|
213
|
+
return await store.setKeyDerivParams(keyParams, false);
|
|
214
|
+
},
|
|
215
|
+
|
|
216
|
+
getCurrentRootObj: makeCurrentObjGetter(true),
|
|
217
|
+
getCurrentObj: makeCurrentObjGetter(false),
|
|
218
|
+
|
|
219
|
+
getArchivedRootVersion: makeArchivedObjGetter(true),
|
|
220
|
+
getArchivedObjVersion: makeArchivedObjGetter(false),
|
|
221
|
+
|
|
222
|
+
saveNewRootVersion: makeObjSaver(true),
|
|
223
|
+
saveNewObjVersion: makeObjSaver(false),
|
|
224
|
+
|
|
225
|
+
cancelTransaction: makeTransactionCanceller(),
|
|
226
|
+
|
|
227
|
+
deleteCurrentObjVersion: async (userId, objId, version) => {
|
|
228
|
+
const store = await getStore(userId);
|
|
229
|
+
await store.deleteCurrentObjVer(objId, version);
|
|
230
|
+
},
|
|
231
|
+
|
|
232
|
+
archiveObjVersion: async (userId, objId, version) => {
|
|
233
|
+
const store = await getStore(userId);
|
|
234
|
+
await store.archiveCurrentObjVersion(objId, version);
|
|
235
|
+
},
|
|
236
|
+
|
|
237
|
+
getObjStatus: async (userId, objId) => {
|
|
238
|
+
const store = await getStore(userId);
|
|
239
|
+
return store.getObjStatus(objId);
|
|
240
|
+
},
|
|
241
|
+
|
|
242
|
+
deleteArchivedObjVersion: async (userId, objId, version) => {
|
|
243
|
+
const store = await getStore(userId);
|
|
244
|
+
await store.deleteArchivedObjVer(objId, version);
|
|
245
|
+
},
|
|
246
|
+
|
|
247
|
+
setStorageEventsSink(sink: EventsSink): void {
|
|
248
|
+
if (storageEventsSink) { throw new Error(
|
|
249
|
+
`Storage events sink is already set`); }
|
|
250
|
+
storageEventsSink = sink;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
};
|
|
254
|
+
Object.freeze(factory);
|
|
255
|
+
return factory;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2022, 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 { ArchiveObjCurrentVersion, MismatchedObjVerException, SC as storeSC } from '../../resources/users';
|
|
20
|
+
import { archiveObj as api, ERR_SC, HTTP_HEADER } from '../../../lib-common/service-api/3nstorage/owner';
|
|
21
|
+
import { Request } from '../../resources/sessions';
|
|
22
|
+
|
|
23
|
+
const SC = api.SC;
|
|
24
|
+
|
|
25
|
+
export function archiveCurrentObjVersion(
|
|
26
|
+
root: boolean, archiveObjVerFunc: ArchiveObjCurrentVersion
|
|
27
|
+
): RequestHandler {
|
|
28
|
+
if ('function' !== typeof archiveObjVerFunc) { throw new TypeError(
|
|
29
|
+
"Given argument 'archiveObjVerFunc' must be function, but is not."); }
|
|
30
|
+
|
|
31
|
+
return async (req: Request, res, next) => {
|
|
32
|
+
|
|
33
|
+
const userId = req.session.params.userId;
|
|
34
|
+
const objId: string = (root ? null as any : req.params.objId);
|
|
35
|
+
|
|
36
|
+
const version = parseInt(req.query.ver as any);
|
|
37
|
+
if (isNaN(version) || (version < 1)) {
|
|
38
|
+
res.status(ERR_SC.malformed).send("Bad query parameters");
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
await archiveObjVerFunc(userId, objId, version);
|
|
44
|
+
res.status(SC.okPost).send();
|
|
45
|
+
} catch (err) {
|
|
46
|
+
if ("string" !== typeof err) {
|
|
47
|
+
if ((err as MismatchedObjVerException).type === 'mismatched-obj-ver') {
|
|
48
|
+
const rep: api.MismatchedObjVerReply = {
|
|
49
|
+
error: "Current object version doesn't match assumed one.",
|
|
50
|
+
current_version: (err as MismatchedObjVerException).current_version
|
|
51
|
+
};
|
|
52
|
+
res.set(HTTP_HEADER.objVersion, `${(err as MismatchedObjVerException).current_version}`);
|
|
53
|
+
res.status(api.SC.mismatchedObjVer).json(rep);
|
|
54
|
+
} else {
|
|
55
|
+
next(err);
|
|
56
|
+
}
|
|
57
|
+
} else if (err === storeSC.OBJ_UNKNOWN) {
|
|
58
|
+
res.status(SC.unknownObj).send(root ?
|
|
59
|
+
`Root object is not set.` :
|
|
60
|
+
`Object ${objId} is unknown.`);
|
|
61
|
+
} else if (err === storeSC.USER_UNKNOWN) {
|
|
62
|
+
res.status(ERR_SC.server).send(
|
|
63
|
+
"Recipient disappeared from the system.");
|
|
64
|
+
req.session.close();
|
|
65
|
+
} else {
|
|
66
|
+
next(new Error("Unhandled storage error code: "+err));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2015 - 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 { CancelTransaction, SC as storeSC } from '../../resources/users';
|
|
20
|
+
import { cancelTransaction as api, ERR_SC } from '../../../lib-common/service-api/3nstorage/owner';
|
|
21
|
+
import { Request } from '../../resources/sessions';
|
|
22
|
+
|
|
23
|
+
export function cancelTransaction(
|
|
24
|
+
root: boolean, cancelTransFunc: CancelTransaction
|
|
25
|
+
): RequestHandler {
|
|
26
|
+
if ('function' !== typeof cancelTransFunc) { throw new TypeError(
|
|
27
|
+
"Given argument 'cancelTransFunc' 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
|
+
const transactionId: string = req.params.transactionId;
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
await cancelTransFunc(userId, objId, ((transactionId === '-') ? undefined : transactionId));
|
|
37
|
+
res.status(api.SC.ok).send();
|
|
38
|
+
} catch (err) {
|
|
39
|
+
if ("string" !== typeof err) {
|
|
40
|
+
next(err);
|
|
41
|
+
} else if ((err === storeSC.TRANSACTION_UNKNOWN)
|
|
42
|
+
|| (err === storeSC.OBJ_UNKNOWN)
|
|
43
|
+
|| (err === storeSC.OBJ_VER_UNKNOWN)) {
|
|
44
|
+
res.status(api.SC.missing).send(
|
|
45
|
+
"Unknown transaction or object.");
|
|
46
|
+
} else if (err === storeSC.USER_UNKNOWN) {
|
|
47
|
+
res.status(ERR_SC.server).send(
|
|
48
|
+
"Recipient disappeared from the system.");
|
|
49
|
+
req.session.close();
|
|
50
|
+
} else {
|
|
51
|
+
next(new Error("Unhandled storage error code: "+err));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2016, 2020, 2022, 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 { DeleteArchivedObjVersion, DeleteCurrentObjVersion, SC as storeSC } from '../../resources/users';
|
|
20
|
+
import { ERR_SC, currentObj as api } from '../../../lib-common/service-api/3nstorage/owner';
|
|
21
|
+
import { Request } from '../../resources/sessions';
|
|
22
|
+
import { assert } from '../../../lib-common/assert';
|
|
23
|
+
|
|
24
|
+
function deleteObj(
|
|
25
|
+
root: boolean, delCurrent: boolean,
|
|
26
|
+
deleteObjFunc: DeleteArchivedObjVersion|DeleteCurrentObjVersion
|
|
27
|
+
): RequestHandler {
|
|
28
|
+
if ('function' !== typeof deleteObjFunc) { throw new TypeError(
|
|
29
|
+
"Given argument 'deleteObjFunc' must be function, but is not."); }
|
|
30
|
+
if (delCurrent) {
|
|
31
|
+
assert(!root);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return async (req: Request, res, next) => {
|
|
35
|
+
|
|
36
|
+
const userId = req.session.params.userId;
|
|
37
|
+
const objId: string|null = (root ? null : req.params.objId);
|
|
38
|
+
|
|
39
|
+
const ver = parseInt(req.query.ver as string);
|
|
40
|
+
let version: number|undefined;
|
|
41
|
+
if (isNaN(ver)) {
|
|
42
|
+
if (delCurrent) {
|
|
43
|
+
version = undefined
|
|
44
|
+
} else {
|
|
45
|
+
res.status(ERR_SC.malformed).send("Bad query parameters");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
if (ver < 1) {
|
|
50
|
+
res.status(ERR_SC.malformed).send("Bad query parameters");
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
version = ver;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
if (delCurrent) {
|
|
58
|
+
await (deleteObjFunc as DeleteCurrentObjVersion)(
|
|
59
|
+
userId, objId!, version
|
|
60
|
+
);
|
|
61
|
+
} else {
|
|
62
|
+
await (deleteObjFunc as DeleteArchivedObjVersion)(
|
|
63
|
+
userId, objId, version!
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
res.status(api.SC.okDelete).send();
|
|
67
|
+
} catch (err) {
|
|
68
|
+
if ("string" !== typeof err) {
|
|
69
|
+
next(err);
|
|
70
|
+
} else if (err === storeSC.CONCURRENT_TRANSACTION) {
|
|
71
|
+
res.status(api.SC.concurrentTransaction).send(
|
|
72
|
+
`Object ${objId} is currently under a transaction.`);
|
|
73
|
+
} else if (err === storeSC.OBJ_UNKNOWN) {
|
|
74
|
+
res.status(api.SC.unknownObj).send(`Object ${objId} is unknown.`);
|
|
75
|
+
} else if (err === storeSC.OBJ_VER_UNKNOWN) {
|
|
76
|
+
res.status(api.SC.unknownObjVer).send(
|
|
77
|
+
`Object version ${version} is unknown.`);
|
|
78
|
+
} else if (err === storeSC.USER_UNKNOWN) {
|
|
79
|
+
res.status(ERR_SC.server).send(
|
|
80
|
+
"Recipient disappeared from the system.");
|
|
81
|
+
req.session.close();
|
|
82
|
+
} else {
|
|
83
|
+
next(new Error("Unhandled storage error code: "+err));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function deleteCurrentObjVer(
|
|
91
|
+
deleteObjFunc: DeleteCurrentObjVersion
|
|
92
|
+
): RequestHandler {
|
|
93
|
+
return deleteObj(false, true, deleteObjFunc);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function deleteArchivedObjVer(
|
|
97
|
+
root: boolean, deleteObjFunc: DeleteArchivedObjVersion
|
|
98
|
+
): RequestHandler {
|
|
99
|
+
return deleteObj(root, false, deleteObjFunc);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2017, 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 { GetArchivedObjVersion, SC as storeSC } from '../../resources/users';
|
|
20
|
+
import { GetObjQueryOpts, ERR_SC, HTTP_HEADER, BIN_TYPE, archivedObjVersion as api } from '../../../lib-common/service-api/3nstorage/owner';
|
|
21
|
+
import { Request } from '../../resources/sessions';
|
|
22
|
+
import { errWithCause } 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; ver: number
|
|
27
|
+
} {
|
|
28
|
+
// query fields are string or undefined, yet, type info helps the show
|
|
29
|
+
const query: GetObjQueryOpts = req.query;
|
|
30
|
+
|
|
31
|
+
const header = ((query.header as any) === 'true');
|
|
32
|
+
|
|
33
|
+
const ofs = (query.ofs ? parseInt(query.ofs as any) : 0);
|
|
34
|
+
if (isNaN(ofs) ||
|
|
35
|
+
(ofs < 0) ||
|
|
36
|
+
(header && (ofs > 0))) { return; }
|
|
37
|
+
|
|
38
|
+
const limit = (query.limit ? parseInt(query.limit as any) : undefined);
|
|
39
|
+
if (limit !== undefined) {
|
|
40
|
+
if (isNaN(limit) ||
|
|
41
|
+
(limit < 0) ||
|
|
42
|
+
(!header && (limit === 0))) { return; }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let ver = parseInt(query.ver as any);
|
|
46
|
+
if (isNaN(ver) || (ver < 1)) { return; }
|
|
47
|
+
|
|
48
|
+
return { header, limit, ofs, ver };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function getArchivedObjVersion(
|
|
52
|
+
root: boolean, getArchivedObjFunc: GetArchivedObjVersion
|
|
53
|
+
): RequestHandler {
|
|
54
|
+
if ('function' !== typeof getArchivedObjFunc) { throw new TypeError(
|
|
55
|
+
"Given argument 'getArchivedObjFunc' must be function, but is not."); }
|
|
56
|
+
|
|
57
|
+
return async (req: Request, res, next) => {
|
|
58
|
+
|
|
59
|
+
const userId = req.session.params.userId;
|
|
60
|
+
const objId: string = (root ? null as any : req.params.objId);
|
|
61
|
+
|
|
62
|
+
const opts = extractQueryOptions(req);
|
|
63
|
+
if (!opts) {
|
|
64
|
+
res.status(ERR_SC.malformed).send("Bad query parameters");
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
const reader = await getArchivedObjFunc(userId, objId, opts.ver,
|
|
70
|
+
opts.header, opts.ofs, opts.limit);
|
|
71
|
+
res.status(api.SC.okGet);
|
|
72
|
+
res.set(HTTP_HEADER.contentType, BIN_TYPE);
|
|
73
|
+
res.set(HTTP_HEADER.contentLength, `${reader.len}`);
|
|
74
|
+
if (opts.header) {
|
|
75
|
+
res.set(HTTP_HEADER.objHeaderLength, `${reader.headerLen}`);
|
|
76
|
+
}
|
|
77
|
+
res.set(HTTP_HEADER.objSegmentsLength, `${reader.segsLen}`);
|
|
78
|
+
if (reader.len > 0) {
|
|
79
|
+
try {
|
|
80
|
+
await reader.pipe!(res);
|
|
81
|
+
} catch (err) {
|
|
82
|
+
console.error(errWithCause(err, `Wasn't able to complete sending segments due to error in piping`));
|
|
83
|
+
} finally {
|
|
84
|
+
res.end();
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
res.send(EMPTY_BUFFER);
|
|
88
|
+
}
|
|
89
|
+
} catch (err) {
|
|
90
|
+
if ("string" !== typeof err) {
|
|
91
|
+
next(err);
|
|
92
|
+
} else if (err === storeSC.OBJ_UNKNOWN) {
|
|
93
|
+
res.status(api.SC.unknownObj).send(objId ?
|
|
94
|
+
`Object ${objId}is unknown.` : `Root object is not set`);
|
|
95
|
+
} else if (err === storeSC.OBJ_VER_UNKNOWN) {
|
|
96
|
+
res.status(api.SC.unknownObjVer).send(objId ?
|
|
97
|
+
`Object ${objId}, version ${opts.ver} is unknown.` :
|
|
98
|
+
`Root object version ${opts.ver} is not known.`);
|
|
99
|
+
} else if (err === storeSC.USER_UNKNOWN) {
|
|
100
|
+
res.status(ERR_SC.server).send(
|
|
101
|
+
`Recipient disappeared from the system.`);
|
|
102
|
+
req.session.close();
|
|
103
|
+
} else {
|
|
104
|
+
next(new Error(`Unhandled storage error code: ${err}`));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
Object.freeze(exports);
|