spec-3nweb-server 1.8.5 → 1.8.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitlab-ci-linux.yml +50 -0
- package/.gitlab-ci-mac.yml +29 -0
- package/.gitlab-ci-windows.yml +29 -0
- package/.gitlab-ci.yml +63 -0
- package/build/3nstorage/resources/store.d.ts +2 -2
- package/build/3nstorage/resources/store.js +1 -1
- package/build/3nstorage/resources/users.d.ts +3 -3
- package/build/3nstorage/resources/users.js +1 -1
- package/build/3nstorage/resources/utils.d.ts +6 -0
- package/build/3nstorage/resources/utils.js +41 -0
- package/build/3nstorage/routes/owner/archive-obj-version.js +8 -10
- package/build/3nstorage/routes/owner/cancel-trans.js +5 -4
- package/build/3nstorage/routes/owner/delete-obj.js +7 -8
- package/build/3nstorage/routes/owner/get-archived-obj-ver.js +11 -13
- package/build/3nstorage/routes/owner/get-current-obj.js +7 -6
- package/build/3nstorage/routes/owner/get-obj-status.js +8 -8
- package/build/3nstorage/routes/owner/put-current-obj.js +25 -55
- package/build/3nstorage/routes/owner/session-params.js +2 -0
- package/build/asmail/resources/utils.d.ts +6 -0
- package/build/asmail/resources/utils.js +36 -0
- package/build/asmail/routes/delivery/finalize-delivery.js +3 -2
- package/build/asmail/routes/delivery/pre-flight.js +9 -26
- package/build/asmail/routes/delivery/provide-recipient-pubkey.js +4 -3
- package/build/asmail/routes/delivery/put-metadata.js +13 -21
- package/build/asmail/routes/delivery/put-obj.js +19 -25
- package/build/asmail/routes/delivery/restart-session.d.ts +4 -8
- package/build/asmail/routes/delivery/restart-session.js +10 -23
- package/build/asmail/routes/delivery/sender-authorization.js +5 -5
- package/build/asmail/routes/delivery/start-session.js +9 -24
- package/build/asmail/routes/retrieval/get-message-meta.js +4 -7
- package/build/asmail/routes/retrieval/get-message-obj.js +10 -7
- package/build/asmail/routes/retrieval/list-messages.js +4 -4
- package/build/asmail/routes/retrieval/remove-message.js +3 -2
- package/build/mock/tls-options.js +46 -44
- package/build/tests/admin-proto/signup.d.ts +1 -0
- package/build/tests/admin-proto/signup.js +235 -0
- package/build/tests/jasmine.d.ts +1 -0
- package/build/tests/jasmine.js +32 -0
- package/build/tests/libs-for-tests/3nstorage.d.ts +22 -0
- package/build/tests/libs-for-tests/3nstorage.js +123 -0
- package/build/tests/libs-for-tests/asmail.d.ts +22 -0
- package/build/tests/libs-for-tests/asmail.js +179 -0
- package/build/tests/libs-for-tests/assert.d.ts +1 -0
- package/build/tests/libs-for-tests/assert.js +26 -0
- package/build/tests/libs-for-tests/async-jasmine.d.ts +7 -0
- package/build/tests/libs-for-tests/async-jasmine.js +77 -0
- package/build/tests/libs-for-tests/bytes-equal.d.ts +1 -0
- package/build/tests/libs-for-tests/bytes-equal.js +34 -0
- package/build/tests/libs-for-tests/json-copy.d.ts +1 -0
- package/build/tests/libs-for-tests/json-copy.js +45 -0
- package/build/tests/libs-for-tests/json-equal.d.ts +4 -0
- package/build/tests/libs-for-tests/json-equal.js +67 -0
- package/build/tests/libs-for-tests/mailerid.d.ts +13 -0
- package/build/tests/libs-for-tests/mailerid.js +114 -0
- package/build/tests/libs-for-tests/pkl.d.ts +28 -0
- package/build/tests/libs-for-tests/pkl.js +89 -0
- package/build/tests/libs-for-tests/server-components/3nstorage.d.ts +20 -0
- package/build/tests/libs-for-tests/server-components/3nstorage.js +200 -0
- package/build/tests/libs-for-tests/server-components/admin.d.ts +6 -0
- package/build/tests/libs-for-tests/server-components/admin.js +43 -0
- package/build/tests/libs-for-tests/server-components/asmail.d.ts +16 -0
- package/build/tests/libs-for-tests/server-components/asmail.js +143 -0
- package/build/tests/libs-for-tests/server-components/component.d.ts +13 -0
- package/build/tests/libs-for-tests/server-components/component.js +77 -0
- package/build/tests/libs-for-tests/server-components/mailerid.d.ts +10 -0
- package/build/tests/libs-for-tests/server-components/mailerid.js +103 -0
- package/build/tests/libs-for-tests/server-runner.d.ts +15 -0
- package/build/tests/libs-for-tests/server-runner.js +69 -0
- package/build/tests/libs-for-tests/spec-assembly.d.ts +6 -0
- package/build/tests/libs-for-tests/spec-assembly.js +55 -0
- package/build/tests/libs-for-tests/ws-utils.d.ts +3 -0
- package/build/tests/libs-for-tests/ws-utils.js +59 -0
- package/build/tests/libs-for-tests/xhr-utils.d.ts +61 -0
- package/build/tests/libs-for-tests/xhr-utils.js +154 -0
- package/build/tests/protocols/3nstorage/owner/specs/archive-obj-ver.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/archive-obj-ver.js +84 -0
- package/build/tests/protocols/3nstorage/owner/specs/archive-root-ver.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/archive-root-ver.js +78 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-archive-obj-ver.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-archive-obj-ver.js +83 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-archive-root-ver.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-archive-root-ver.js +77 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-obj.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-obj.js +75 -0
- package/build/tests/protocols/3nstorage/owner/specs/events.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/events.js +91 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-current-obj.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-current-obj.js +269 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-current-root.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-current-root.js +262 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-obj-status.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-obj-status.js +79 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-root-status.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-root-status.js +72 -0
- package/build/tests/protocols/3nstorage/owner/specs/put-current-obj.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/put-current-obj.js +287 -0
- package/build/tests/protocols/3nstorage/owner/specs/put-current-root.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/put-current-root.js +274 -0
- package/build/tests/protocols/3nstorage/owner/specs/trans-cancel-root.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/trans-cancel-root.js +73 -0
- package/build/tests/protocols/3nstorage/owner/specs/trans-cancel.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/trans-cancel.js +72 -0
- package/build/tests/protocols/3nstorage/owner/test-utils.d.ts +14 -0
- package/build/tests/protocols/3nstorage/owner/test-utils.js +54 -0
- package/build/tests/protocols/3nstorage/owner.d.ts +1 -0
- package/build/tests/protocols/3nstorage/owner.js +138 -0
- package/build/tests/protocols/asmail/config.d.ts +1 -0
- package/build/tests/protocols/asmail/config.js +117 -0
- package/build/tests/protocols/asmail/delivery/specs/finalize-delivery.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/finalize-delivery.js +60 -0
- package/build/tests/protocols/asmail/delivery/specs/provide-recipient-pubkey.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/provide-recipient-pubkey.js +68 -0
- package/build/tests/protocols/asmail/delivery/specs/put-metadata.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/put-metadata.js +83 -0
- package/build/tests/protocols/asmail/delivery/specs/put-obj.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/put-obj.js +123 -0
- package/build/tests/protocols/asmail/delivery/specs/restart-session.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/restart-session.js +79 -0
- package/build/tests/protocols/asmail/delivery/specs/start-session.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/start-session.js +64 -0
- package/build/tests/protocols/asmail/delivery/test-utils.d.ts +16 -0
- package/build/tests/protocols/asmail/delivery/test-utils.js +46 -0
- package/build/tests/protocols/asmail/delivery.d.ts +1 -0
- package/build/tests/protocols/asmail/delivery.js +46 -0
- package/build/tests/protocols/asmail/retrieval/specs/events.d.ts +2 -0
- package/build/tests/protocols/asmail/retrieval/specs/events.js +62 -0
- package/build/tests/protocols/asmail/retrieval/specs/get-message-meta.d.ts +2 -0
- package/build/tests/protocols/asmail/retrieval/specs/get-message-meta.js +70 -0
- package/build/tests/protocols/asmail/retrieval/specs/get-message-obj.d.ts +2 -0
- package/build/tests/protocols/asmail/retrieval/specs/get-message-obj.js +166 -0
- package/build/tests/protocols/asmail/retrieval/specs/list-messages.d.ts +2 -0
- package/build/tests/protocols/asmail/retrieval/specs/list-messages.js +96 -0
- package/build/tests/protocols/asmail/retrieval/specs/remove-message.d.ts +2 -0
- package/build/tests/protocols/asmail/retrieval/specs/remove-message.js +66 -0
- package/build/tests/protocols/asmail/retrieval/test-utils.d.ts +17 -0
- package/build/tests/protocols/asmail/retrieval/test-utils.js +46 -0
- package/build/tests/protocols/asmail/retrieval.d.ts +1 -0
- package/build/tests/protocols/asmail/retrieval.js +92 -0
- package/build/tests/protocols/mailerid.d.ts +1 -0
- package/build/tests/protocols/mailerid.js +210 -0
- package/build/tests/shared-checks/check-mid-login.d.ts +2 -0
- package/build/tests/shared-checks/check-mid-login.js +131 -0
- package/build/tests/shared-checks/requests.d.ts +20 -0
- package/build/tests/shared-checks/requests.js +123 -0
- package/package.json +1 -1
- package/packing/create-deb.sh +57 -0
- package/packing/deb/lib/systemd/system/3nweb.service +11 -0
- package/packing/deb/postinst +44 -0
- package/packing/deb/usr/share/doc/3nweb-server/conf-for-postinstall.yaml +19 -0
- package/packing/deb/usr/share/doc/3nweb-server/copyright +22 -0
- package/publish-task.sh +10 -0
- package/push-to-github.sh +105 -0
- package/ts-code/3nstorage/3nstorage-app.ts +99 -0
- package/ts-code/3nstorage/owner.ts +178 -0
- package/ts-code/3nstorage/resources/sessions.ts +37 -0
- package/ts-code/3nstorage/resources/store.ts +896 -0
- package/ts-code/3nstorage/resources/users.ts +258 -0
- package/ts-code/3nstorage/resources/utils.ts +45 -0
- package/ts-code/3nstorage/routes/owner/archive-obj-version.ts +71 -0
- package/ts-code/3nstorage/routes/owner/cancel-trans.ts +60 -0
- package/ts-code/3nstorage/routes/owner/delete-obj.ts +99 -0
- package/ts-code/3nstorage/routes/owner/get-archived-obj-ver.ts +109 -0
- package/ts-code/3nstorage/routes/owner/get-current-obj.ts +124 -0
- package/ts-code/3nstorage/routes/owner/get-obj-status.ts +55 -0
- package/ts-code/3nstorage/routes/owner/param-getter.ts +51 -0
- package/ts-code/3nstorage/routes/owner/param-setter.ts +50 -0
- package/ts-code/3nstorage/routes/owner/put-current-obj.ts +257 -0
- package/ts-code/3nstorage/routes/owner/session-params.ts +50 -0
- package/ts-code/3nstorage/shared.ts +43 -0
- package/ts-code/asmail/asmail-app.ts +91 -0
- package/ts-code/asmail/config.ts +96 -0
- package/ts-code/asmail/delivery.ts +94 -0
- package/ts-code/asmail/resources/delivery-sessions.ts +118 -0
- package/ts-code/asmail/resources/inbox.ts +696 -0
- package/ts-code/asmail/resources/recipients.ts +495 -0
- package/ts-code/asmail/resources/sessions.ts +37 -0
- package/ts-code/asmail/resources/utils.ts +41 -0
- package/ts-code/asmail/retrieval.ts +96 -0
- package/ts-code/asmail/routes/config/param-getter.ts +49 -0
- package/ts-code/asmail/routes/config/param-setter.ts +49 -0
- package/ts-code/asmail/routes/delivery/finalize-delivery.ts +51 -0
- package/ts-code/asmail/routes/delivery/pre-flight.ts +118 -0
- package/ts-code/asmail/routes/delivery/provide-recipient-pubkey.ts +58 -0
- package/ts-code/asmail/routes/delivery/put-metadata.ts +85 -0
- package/ts-code/asmail/routes/delivery/put-obj.ts +152 -0
- package/ts-code/asmail/routes/delivery/restart-session.ts +117 -0
- package/ts-code/asmail/routes/delivery/sender-authorization.ts +81 -0
- package/ts-code/asmail/routes/delivery/start-session.ts +136 -0
- package/ts-code/asmail/routes/retrieval/get-message-meta.ts +50 -0
- package/ts-code/asmail/routes/retrieval/get-message-obj.ts +106 -0
- package/ts-code/asmail/routes/retrieval/list-messages.ts +68 -0
- package/ts-code/asmail/routes/retrieval/remove-message.ts +48 -0
- package/ts-code/cli/index.ts +82 -0
- package/ts-code/cli/run-cmd.ts +81 -0
- package/ts-code/cli/show-sample-config.ts +78 -0
- package/ts-code/cli/signup-cmd.ts +229 -0
- package/ts-code/cli/user-cmd.ts +68 -0
- package/ts-code/cli/utils.ts +105 -0
- package/ts-code/config/default-confs.ts +22 -0
- package/ts-code/config/from-yaml.ts +35 -0
- package/ts-code/config/letsencrypt.ts +77 -0
- package/ts-code/config/signup.ts +137 -0
- package/ts-code/lib-common/admin-api/signup.ts +120 -0
- package/ts-code/lib-common/assert.ts +22 -0
- package/ts-code/lib-common/async-fs-node.ts +656 -0
- package/ts-code/lib-common/buffer-utils.ts +124 -0
- package/ts-code/lib-common/byte-streaming/common.ts +166 -0
- package/ts-code/lib-common/bytes-equal.ts +25 -0
- package/ts-code/lib-common/canonical-address.ts +92 -0
- package/ts-code/lib-common/exceptions/error.ts +44 -0
- package/ts-code/lib-common/exceptions/file.ts +84 -0
- package/ts-code/lib-common/exceptions/http.ts +69 -0
- package/ts-code/lib-common/ipc/generic-ipc.ts +750 -0
- package/ts-code/lib-common/ipc/ws-ipc.ts +117 -0
- package/ts-code/lib-common/json-equal.ts +55 -0
- package/ts-code/lib-common/json-utils.ts +130 -0
- package/ts-code/lib-common/jwkeys.ts +246 -0
- package/ts-code/lib-common/map-of-sets.ts +60 -0
- package/ts-code/lib-common/mid-sigs-NaCl-Ed.ts +677 -0
- package/ts-code/lib-common/objs-on-disk/file-layout.ts +480 -0
- package/ts-code/lib-common/objs-on-disk/obj-file.ts +325 -0
- package/ts-code/lib-common/objs-on-disk/utils.ts +201 -0
- package/ts-code/lib-common/objs-on-disk/v1-obj-file-format.ts +329 -0
- package/ts-code/lib-common/processes.ts +501 -0
- package/ts-code/lib-common/random-node.ts +79 -0
- package/ts-code/lib-common/service-api/3nstorage/owner.ts +559 -0
- package/ts-code/lib-common/service-api/3nstorage/root-route.ts +22 -0
- package/ts-code/lib-common/service-api/asmail/config.ts +144 -0
- package/ts-code/lib-common/service-api/asmail/delivery.ts +250 -0
- package/ts-code/lib-common/service-api/asmail/retrieval.ts +238 -0
- package/ts-code/lib-common/service-api/asmail/root-route.ts +22 -0
- package/ts-code/lib-common/service-api/ipc-api.ts +44 -0
- package/ts-code/lib-common/service-api/locker.ts +44 -0
- package/ts-code/lib-common/service-api/mailer-id/login.ts +80 -0
- package/ts-code/lib-common/service-api/mailer-id/provisioning.ts +64 -0
- package/ts-code/lib-common/service-api/mailer-id/root-route.ts +25 -0
- package/ts-code/lib-common/service-api/pub-key-login.ts +75 -0
- package/ts-code/lib-common/service-api/web-socket-base.ts +87 -0
- package/ts-code/lib-common/session-encryptor.ts +54 -0
- package/ts-code/lib-common/time-window-cache.ts +74 -0
- package/ts-code/lib-common/transferable.d.ts +30 -0
- package/ts-code/lib-server/conf-util.ts +35 -0
- package/ts-code/lib-server/mid-access.ts +45 -0
- package/ts-code/lib-server/middleware/body-parsers.ts +248 -0
- package/ts-code/lib-server/middleware/error-handler.ts +79 -0
- package/ts-code/lib-server/pkl-access.ts +46 -0
- package/ts-code/lib-server/resources/dns.ts +151 -0
- package/ts-code/lib-server/resources/mailerid-authorizer.ts +115 -0
- package/ts-code/lib-server/resources/mem-backed-sessions-factory.ts +132 -0
- package/ts-code/lib-server/resources/server-data-folders.ts +160 -0
- package/ts-code/lib-server/resources/server-key-for-pkl-challenge.ts +41 -0
- package/ts-code/lib-server/resources/sessions.ts +232 -0
- package/ts-code/lib-server/resources/user-files.ts +147 -0
- package/ts-code/lib-server/routes/pub-key-login/complete-exchange.ts +63 -0
- package/ts-code/lib-server/routes/pub-key-login/start-exchange.ts +189 -0
- package/ts-code/lib-server/routes/sessions/close.ts +27 -0
- package/ts-code/lib-server/routes/sessions/mid-auth.ts +77 -0
- package/ts-code/lib-server/routes/sessions/start.ts +116 -0
- package/ts-code/lib-server/web-sockets/app.ts +339 -0
- package/ts-code/lib-server/web-sockets/server-events.ts +63 -0
- package/ts-code/lib.ts +29 -0
- package/ts-code/locker/locker-app.ts +60 -0
- package/ts-code/locker/resources/lockers.ts +17 -0
- package/ts-code/locker/resources/sessions.ts +37 -0
- package/ts-code/locker/routes/create-locker.ts +47 -0
- package/ts-code/mailerId/mailerId-app.ts +107 -0
- package/ts-code/mailerId/resources/certifier.ts +181 -0
- package/ts-code/mailerId/resources/sessions.ts +44 -0
- package/ts-code/mailerId/resources/users.ts +88 -0
- package/ts-code/mailerId/routes/certify.ts +68 -0
- package/ts-code/main.ts +304 -0
- package/ts-code/mock/dns.ts +106 -0
- package/ts-code/mock/mock-as-child-proc.ts +130 -0
- package/ts-code/mock/node-child-ipc.ts +69 -0
- package/ts-code/mock/run-in-proc.ts +111 -0
- package/ts-code/mock/tls-options.ts +73 -0
- package/ts-code/services.ts +138 -0
- package/ts-code/signup/resources/users.ts +429 -0
- package/ts-code/signup/routes/add.ts +65 -0
- package/ts-code/signup/routes/get-available-addresses.ts +49 -0
- package/ts-code/signup/routes/get-available-domains.ts +45 -0
- package/ts-code/signup/signup-app.ts +54 -0
- package/ts-code/signup/signup-tokens.ts +148 -0
- package/ts-code/tests/admin-proto/signup.ts +277 -0
- package/ts-code/tests/jasmine.ts +37 -0
- package/ts-code/tests/libs-for-tests/3nstorage.ts +144 -0
- package/ts-code/tests/libs-for-tests/asmail.ts +220 -0
- package/ts-code/tests/libs-for-tests/assert.ts +22 -0
- package/ts-code/tests/libs-for-tests/async-jasmine.ts +89 -0
- package/ts-code/tests/libs-for-tests/bytes-equal.ts +25 -0
- package/ts-code/tests/libs-for-tests/json-copy.ts +38 -0
- package/ts-code/tests/libs-for-tests/json-equal.ts +55 -0
- package/ts-code/tests/libs-for-tests/mailerid.ts +123 -0
- package/ts-code/tests/libs-for-tests/pkl.ts +127 -0
- package/ts-code/tests/libs-for-tests/server-components/3nstorage.ts +206 -0
- package/ts-code/tests/libs-for-tests/server-components/admin.ts +49 -0
- package/ts-code/tests/libs-for-tests/server-components/asmail.ts +152 -0
- package/ts-code/tests/libs-for-tests/server-components/component.ts +90 -0
- package/ts-code/tests/libs-for-tests/server-components/mailerid.ts +114 -0
- package/ts-code/tests/libs-for-tests/server-runner.ts +82 -0
- package/ts-code/tests/libs-for-tests/spec-assembly.ts +60 -0
- package/ts-code/tests/libs-for-tests/ws-utils.ts +61 -0
- package/ts-code/tests/libs-for-tests/xhr-utils.ts +179 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/archive-obj-ver.ts +100 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/archive-root-ver.ts +91 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/delete-archive-obj-ver.ts +99 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/delete-archive-root-ver.ts +90 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/delete-obj.ts +84 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/events.ts +125 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/get-current-obj.ts +298 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/get-current-root.ts +290 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/get-obj-status.ts +88 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/get-root-status.ts +80 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/put-current-obj.ts +366 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/put-current-root.ts +329 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/trans-cancel-root.ts +86 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/trans-cancel.ts +86 -0
- package/ts-code/tests/protocols/3nstorage/owner/test-utils.ts +72 -0
- package/ts-code/tests/protocols/3nstorage/owner.ts +198 -0
- package/ts-code/tests/protocols/asmail/config.ts +172 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/finalize-delivery.ts +69 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/provide-recipient-pubkey.ts +88 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/put-metadata.ts +102 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/put-obj.ts +156 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/restart-session.ts +97 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/start-session.ts +79 -0
- package/ts-code/tests/protocols/asmail/delivery/test-utils.ts +64 -0
- package/ts-code/tests/protocols/asmail/delivery.ts +56 -0
- package/ts-code/tests/protocols/asmail/retrieval/specs/events.ts +78 -0
- package/ts-code/tests/protocols/asmail/retrieval/specs/get-message-meta.ts +80 -0
- package/ts-code/tests/protocols/asmail/retrieval/specs/get-message-obj.ts +197 -0
- package/ts-code/tests/protocols/asmail/retrieval/specs/list-messages.ts +110 -0
- package/ts-code/tests/protocols/asmail/retrieval/specs/remove-message.ts +74 -0
- package/ts-code/tests/protocols/asmail/retrieval/test-utils.ts +60 -0
- package/ts-code/tests/protocols/asmail/retrieval.ts +115 -0
- package/ts-code/tests/protocols/mailerid.ts +271 -0
- package/ts-code/tests/shared-checks/check-mid-login.ts +164 -0
- package/ts-code/tests/shared-checks/requests.ts +135 -0
- package/ts-code/tsconfig.json +11 -0
- package/ts-code/web3n.d.ts +1068 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (C) 2016, 2020 3NSoft Inc.
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
7
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
8
|
+
version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful, but
|
|
11
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
+
See the GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License along with
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.Component = void 0;
|
|
20
|
+
const server_runner_1 = require("../server-runner");
|
|
21
|
+
const async_fs_node_1 = require("../../../lib-common/async-fs-node");
|
|
22
|
+
const services_1 = require("../../../services");
|
|
23
|
+
const dns_1 = require("../../../mock/dns");
|
|
24
|
+
const dns = require("dns");
|
|
25
|
+
const app_1 = require("../../../lib-server/web-sockets/app");
|
|
26
|
+
const path_1 = require("path");
|
|
27
|
+
const signup_tokens_1 = require("../../../signup/signup-tokens");
|
|
28
|
+
const DEFAULT_SERVICE_PORT = 8088;
|
|
29
|
+
const DEFAULT_DATA_FOLDER = (0, path_1.join)(__dirname, '/../../../../test-data');
|
|
30
|
+
class Component extends server_runner_1.ServerRunner {
|
|
31
|
+
constructor(conf, signupDomains, servicePort = DEFAULT_SERVICE_PORT, dataFolder = DEFAULT_DATA_FOLDER) {
|
|
32
|
+
super(servicePort);
|
|
33
|
+
this.conf = conf;
|
|
34
|
+
this.signupDomains = signupDomains;
|
|
35
|
+
this.dataFolder = dataFolder;
|
|
36
|
+
this.conf.rootFolder = this.dataFolder;
|
|
37
|
+
this.conf.signup.noTokenFile = (0, path_1.join)(this.dataFolder, 'no-tokens-signup.json');
|
|
38
|
+
if (this.conf.mailerId) {
|
|
39
|
+
const certs = this.conf.mailerId.certs;
|
|
40
|
+
this.conf.mailerId.certs = (0, path_1.join)(this.dataFolder, (certs ? certs : 'mid-certs.json'));
|
|
41
|
+
}
|
|
42
|
+
const urlWithoutProto = this.url.substring(this.url.indexOf('://') + 3);
|
|
43
|
+
this.dns = new dns_1.DNSMock(urlWithoutProto + 'mailerid/');
|
|
44
|
+
}
|
|
45
|
+
async prepToRun() {
|
|
46
|
+
// prepare data folders
|
|
47
|
+
try {
|
|
48
|
+
await (0, async_fs_node_1.mkdir)(this.dataFolder);
|
|
49
|
+
// write to-tokens signup file
|
|
50
|
+
const noTokenCtx = (0, signup_tokens_1.makeMultiDomainSignupCtx)(this.signupDomains);
|
|
51
|
+
await (0, async_fs_node_1.writeFile)(this.conf.signup.noTokenFile, JSON.stringify(noTokenCtx), { encoding: 'utf8' });
|
|
52
|
+
}
|
|
53
|
+
catch (exc) {
|
|
54
|
+
if (!exc.alreadyExists) {
|
|
55
|
+
throw exc;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// inject dns mock
|
|
59
|
+
dns.resolveTxt = this.dns.resolveTxt;
|
|
60
|
+
// setup servers
|
|
61
|
+
const app = new app_1.AppWithWSs();
|
|
62
|
+
app.use((0, services_1.accountsApp)(this.conf));
|
|
63
|
+
app.use((0, services_1.servicesApp)(this.conf));
|
|
64
|
+
return app;
|
|
65
|
+
}
|
|
66
|
+
async clean() {
|
|
67
|
+
await (0, async_fs_node_1.rmDirWithContent)(this.dataFolder).catch((exc) => {
|
|
68
|
+
if (!exc.notFound) {
|
|
69
|
+
throw exc;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.Component = Component;
|
|
75
|
+
Object.freeze(Component.prototype);
|
|
76
|
+
Object.freeze(Component);
|
|
77
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Component } from './component';
|
|
2
|
+
import { User } from '../pkl';
|
|
3
|
+
export declare function addUserIn(rootServerUrl: string, userId: string): Promise<User>;
|
|
4
|
+
export declare class MailerIdComponent extends Component {
|
|
5
|
+
midServiceDomain: string;
|
|
6
|
+
constructor(signupDomains: string[], midServiceDomain: string);
|
|
7
|
+
addUser(userId: string): Promise<User>;
|
|
8
|
+
get midUrl(): string;
|
|
9
|
+
getProvUrl(): Promise<string>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (C) 2016, 2020 3NSoft Inc.
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
7
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
8
|
+
version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful, but
|
|
11
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
+
See the GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License along with
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.MailerIdComponent = exports.addUserIn = void 0;
|
|
20
|
+
const component_1 = require("./component");
|
|
21
|
+
const url_1 = require("url");
|
|
22
|
+
const xhr_utils_1 = require("../xhr-utils");
|
|
23
|
+
const signup = require("../../../lib-common/admin-api/signup");
|
|
24
|
+
const random = require("../../../lib-common/random-node");
|
|
25
|
+
const ecma_nacl_1 = require("ecma-nacl");
|
|
26
|
+
const jwkeys_1 = require("../../../lib-common/jwkeys");
|
|
27
|
+
const buffer_utils_1 = require("../../../lib-common/buffer-utils");
|
|
28
|
+
const mailerid_1 = require("../mailerid");
|
|
29
|
+
async function addUserIn(rootServerUrl, userId) {
|
|
30
|
+
let reqOpts = {
|
|
31
|
+
url: (0, url_1.resolve)((0, url_1.resolve)(rootServerUrl, 'signup/'), signup.addUser.URL_END),
|
|
32
|
+
method: 'POST'
|
|
33
|
+
};
|
|
34
|
+
let user = {
|
|
35
|
+
id: userId,
|
|
36
|
+
loginDefaultSKey: await random.bytes(ecma_nacl_1.box.KEY_LENGTH),
|
|
37
|
+
loginLabeledSKey: {
|
|
38
|
+
k: await random.bytes(ecma_nacl_1.box.KEY_LENGTH),
|
|
39
|
+
kid: await random.stringOfB64Chars(12)
|
|
40
|
+
},
|
|
41
|
+
midUrl: undefined,
|
|
42
|
+
storageOwnerUrl: undefined
|
|
43
|
+
};
|
|
44
|
+
let req = {
|
|
45
|
+
userId: user.id,
|
|
46
|
+
storage: {
|
|
47
|
+
kdParams: {}
|
|
48
|
+
},
|
|
49
|
+
mailerId: {
|
|
50
|
+
defaultPKey: {
|
|
51
|
+
pkey: {
|
|
52
|
+
alg: ecma_nacl_1.box.JWK_ALG_NAME,
|
|
53
|
+
kid: '_',
|
|
54
|
+
use: jwkeys_1.use.MID_PKLOGIN,
|
|
55
|
+
k: buffer_utils_1.base64.pack(ecma_nacl_1.box.generate_pubkey(user.loginDefaultSKey))
|
|
56
|
+
},
|
|
57
|
+
kdParams: {}
|
|
58
|
+
},
|
|
59
|
+
otherPKeys: [{
|
|
60
|
+
alg: ecma_nacl_1.box.JWK_ALG_NAME,
|
|
61
|
+
kid: user.loginLabeledSKey.kid,
|
|
62
|
+
use: jwkeys_1.use.MID_PKLOGIN,
|
|
63
|
+
k: buffer_utils_1.base64.pack(ecma_nacl_1.box.generate_pubkey(user.loginLabeledSKey.k))
|
|
64
|
+
}]
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
let rep = await (0, xhr_utils_1.doJsonRequest)(reqOpts, req);
|
|
68
|
+
if (rep.status !== signup.addUser.SC.ok) {
|
|
69
|
+
throw new Error(`Fail to add user ${userId}`);
|
|
70
|
+
}
|
|
71
|
+
return user;
|
|
72
|
+
}
|
|
73
|
+
exports.addUserIn = addUserIn;
|
|
74
|
+
class MailerIdComponent extends component_1.Component {
|
|
75
|
+
constructor(signupDomains, midServiceDomain) {
|
|
76
|
+
super({
|
|
77
|
+
rootFolder: null,
|
|
78
|
+
domain: midServiceDomain,
|
|
79
|
+
signup: {},
|
|
80
|
+
enabledServices: {
|
|
81
|
+
mailerId: true
|
|
82
|
+
},
|
|
83
|
+
mailerId: {
|
|
84
|
+
certs: null
|
|
85
|
+
}
|
|
86
|
+
}, signupDomains);
|
|
87
|
+
this.midServiceDomain = midServiceDomain;
|
|
88
|
+
Object.seal(this);
|
|
89
|
+
}
|
|
90
|
+
addUser(userId) {
|
|
91
|
+
return addUserIn(this.url, userId);
|
|
92
|
+
}
|
|
93
|
+
get midUrl() {
|
|
94
|
+
return (0, url_1.resolve)(this.url, 'mailerid/');
|
|
95
|
+
}
|
|
96
|
+
getProvUrl() {
|
|
97
|
+
return (0, mailerid_1.getProvPath)(this.midUrl);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.MailerIdComponent = MailerIdComponent;
|
|
101
|
+
Object.freeze(MailerIdComponent.prototype);
|
|
102
|
+
Object.freeze(MailerIdComponent);
|
|
103
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AppWithWSs } from '../../lib-server/web-sockets/app';
|
|
2
|
+
export type ServerState = 'stopped' | 'starting' | 'running' | 'stopping';
|
|
3
|
+
export declare abstract class ServerRunner {
|
|
4
|
+
protected servicePort: number;
|
|
5
|
+
protected state: ServerState;
|
|
6
|
+
protected app: AppWithWSs;
|
|
7
|
+
constructor(servicePort: number);
|
|
8
|
+
abstract prepToRun(): Promise<AppWithWSs>;
|
|
9
|
+
abstract clean(): Promise<void>;
|
|
10
|
+
isRunning(): boolean;
|
|
11
|
+
start(): Promise<void>;
|
|
12
|
+
stop(doCleanup?: boolean): Promise<void>;
|
|
13
|
+
restart(): Promise<void>;
|
|
14
|
+
protected get url(): string;
|
|
15
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (C) 2016 3NSoft Inc.
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
7
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
8
|
+
version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful, but
|
|
11
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
+
See the GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License along with
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.ServerRunner = void 0;
|
|
20
|
+
const https = require("https");
|
|
21
|
+
const tls_options_1 = require("../../mock/tls-options");
|
|
22
|
+
const processes_1 = require("../../lib-common/processes");
|
|
23
|
+
// allow client test calls to trust above self-signed cert
|
|
24
|
+
https.globalAgent.options.ca = tls_options_1.sslOpts.cert;
|
|
25
|
+
class ServerRunner {
|
|
26
|
+
constructor(servicePort) {
|
|
27
|
+
this.servicePort = servicePort;
|
|
28
|
+
this.state = 'stopped';
|
|
29
|
+
this.app = undefined;
|
|
30
|
+
}
|
|
31
|
+
isRunning() {
|
|
32
|
+
return (this.state === 'running');
|
|
33
|
+
}
|
|
34
|
+
async start() {
|
|
35
|
+
if (this.state !== 'stopped') {
|
|
36
|
+
throw new Error(`Home server is already in ${this.state} state.`);
|
|
37
|
+
}
|
|
38
|
+
this.state = 'starting';
|
|
39
|
+
this.app = await this.prepToRun();
|
|
40
|
+
await this.app.start(tls_options_1.sslOpts, this.servicePort);
|
|
41
|
+
await (0, processes_1.sleep)(100);
|
|
42
|
+
this.state = 'running';
|
|
43
|
+
}
|
|
44
|
+
async stop(doCleanup = true) {
|
|
45
|
+
if (this.state !== 'running') {
|
|
46
|
+
throw new Error(`Home server is in ${this.state} state instead of running state`);
|
|
47
|
+
}
|
|
48
|
+
this.state = 'stopping';
|
|
49
|
+
await this.app.stop();
|
|
50
|
+
this.app = undefined;
|
|
51
|
+
if (doCleanup) {
|
|
52
|
+
await this.clean();
|
|
53
|
+
}
|
|
54
|
+
this.state = 'stopped';
|
|
55
|
+
}
|
|
56
|
+
async restart() {
|
|
57
|
+
if (this.isRunning()) {
|
|
58
|
+
await this.stop(false);
|
|
59
|
+
}
|
|
60
|
+
await this.start();
|
|
61
|
+
}
|
|
62
|
+
get url() {
|
|
63
|
+
return `https://localhost:${this.servicePort}/`;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.ServerRunner = ServerRunner;
|
|
67
|
+
Object.freeze(ServerRunner.prototype);
|
|
68
|
+
Object.freeze(ServerRunner);
|
|
69
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (C) 2016 3NSoft Inc.
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
7
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
8
|
+
version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful, but
|
|
11
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
+
See the GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License along with
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.addSpecsFrom = void 0;
|
|
20
|
+
const path_1 = require("path");
|
|
21
|
+
const fs_1 = require("fs");
|
|
22
|
+
function setupSpecs(specs, setup) {
|
|
23
|
+
if (!specs.definition) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (specs.focused) {
|
|
27
|
+
fdescribe(specs.description, specs.definition(setup));
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
describe(specs.description, specs.definition(setup));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function addSpecsFrom(specsFolder, setup) {
|
|
34
|
+
for (let fName of (0, fs_1.readdirSync)(specsFolder)) {
|
|
35
|
+
if (!fName.endsWith('.js')) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
let modPath = (0, path_1.join)(specsFolder, fName);
|
|
39
|
+
let specs = require(modPath).specs;
|
|
40
|
+
if (!specs) {
|
|
41
|
+
console.error(`Module ${fName} is not exposing specs objects with tests`);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (Array.isArray(specs)) {
|
|
45
|
+
for (let s of specs) {
|
|
46
|
+
setupSpecs(s, setup);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
setupSpecs(specs, setup);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.addSpecsFrom = addSpecsFrom;
|
|
55
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (C) 2017, 2019 3NSoft Inc.
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
7
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
8
|
+
version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful, but
|
|
11
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
+
See the GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License along with
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.openSocket = void 0;
|
|
20
|
+
const WebSocket = require("ws");
|
|
21
|
+
const xhr_utils_1 = require("./xhr-utils");
|
|
22
|
+
const processes_1 = require("../../lib-common/processes");
|
|
23
|
+
const http_1 = require("../../lib-common/exceptions/http");
|
|
24
|
+
const https_1 = require("https");
|
|
25
|
+
function openSocket(url, sessionId) {
|
|
26
|
+
if (!url.startsWith('wss://')) {
|
|
27
|
+
throw new Error(`Url protocol must be wss`);
|
|
28
|
+
}
|
|
29
|
+
const headers = {};
|
|
30
|
+
headers[xhr_utils_1.SESSION_ID_HEADER] = sessionId;
|
|
31
|
+
const ws = new WebSocket(url, { headers, agent: https_1.globalAgent });
|
|
32
|
+
const opening = (0, processes_1.defer)();
|
|
33
|
+
const initOnError = err => opening.reject((0, http_1.makeConnectionException)(url, undefined, `Cannot open websocket connection due to error: ${err.message}`));
|
|
34
|
+
const onNonOkReply = (req, res) => {
|
|
35
|
+
const errReply = {
|
|
36
|
+
url,
|
|
37
|
+
method: 'GET',
|
|
38
|
+
status: res.statusCode,
|
|
39
|
+
data: undefined
|
|
40
|
+
};
|
|
41
|
+
opening.resolve(errReply);
|
|
42
|
+
};
|
|
43
|
+
ws.on('error', initOnError);
|
|
44
|
+
ws.on('unexpected-response', onNonOkReply);
|
|
45
|
+
ws.once('open', () => {
|
|
46
|
+
const okReply = {
|
|
47
|
+
url,
|
|
48
|
+
method: 'GET',
|
|
49
|
+
status: 200,
|
|
50
|
+
data: ws
|
|
51
|
+
};
|
|
52
|
+
opening.resolve(okReply);
|
|
53
|
+
ws.removeListener('error', initOnError);
|
|
54
|
+
ws.removeListener('unexpected-response', onNonOkReply);
|
|
55
|
+
});
|
|
56
|
+
return opening.promise;
|
|
57
|
+
}
|
|
58
|
+
exports.openSocket = openSocket;
|
|
59
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { HTTPException } from '../../lib-common/exceptions/http';
|
|
2
|
+
export declare const SESSION_ID_HEADER = "X-Session-Id";
|
|
3
|
+
export interface Reply<T> {
|
|
4
|
+
url: string;
|
|
5
|
+
method: string;
|
|
6
|
+
status: number;
|
|
7
|
+
data: T;
|
|
8
|
+
headers?: Headers;
|
|
9
|
+
}
|
|
10
|
+
export interface RequestOpts {
|
|
11
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
12
|
+
url?: string;
|
|
13
|
+
path?: string;
|
|
14
|
+
responseType?: 'json' | 'arraybuffer';
|
|
15
|
+
sessionId?: string;
|
|
16
|
+
responseHeaders?: string[];
|
|
17
|
+
}
|
|
18
|
+
export interface Headers {
|
|
19
|
+
get(name: string): string | undefined;
|
|
20
|
+
}
|
|
21
|
+
export declare function request<T>(contentType: string | undefined, opts: RequestOpts): {
|
|
22
|
+
xhr: XMLHttpRequest;
|
|
23
|
+
promise: Promise<Reply<T>>;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* This assembles XMLHttpRequest with 'Content-Type: application/json' and
|
|
27
|
+
* sends given json.
|
|
28
|
+
* @param opts
|
|
29
|
+
* @param json
|
|
30
|
+
* @return a promise, resolvable to reply object
|
|
31
|
+
*/
|
|
32
|
+
export declare function doJsonRequest<T>(opts: RequestOpts, json: any): Promise<Reply<T>>;
|
|
33
|
+
/**
|
|
34
|
+
* This assembles XMLHttpRequest with 'Content-Type: application/octet-stream'
|
|
35
|
+
* and sends given bytes.
|
|
36
|
+
* @param opts
|
|
37
|
+
* @param bytes
|
|
38
|
+
* @return a promise, resolvable to reply object
|
|
39
|
+
*/
|
|
40
|
+
export declare function doBinaryRequest<T>(opts: RequestOpts, bytes: Uint8Array | Uint8Array[]): Promise<Reply<T>>;
|
|
41
|
+
/**
|
|
42
|
+
* This assembles XMLHttpRequest with 'Content-Type: text/plain'
|
|
43
|
+
* and sends given text
|
|
44
|
+
* @param opts
|
|
45
|
+
* @param txt
|
|
46
|
+
* @return a promise, resolvable to reply object
|
|
47
|
+
*/
|
|
48
|
+
export declare function doTextRequest<T>(opts: RequestOpts, txt: string): Promise<Reply<T>>;
|
|
49
|
+
/**
|
|
50
|
+
* This assembles XMLHttpRequest without 'Content-Type'.
|
|
51
|
+
* @param opts
|
|
52
|
+
* @return a promise, resolvable to reply object
|
|
53
|
+
*/
|
|
54
|
+
export declare function doBodylessRequest<T>(opts: RequestOpts): Promise<Reply<T>>;
|
|
55
|
+
/**
|
|
56
|
+
* @param rep
|
|
57
|
+
* @param errMsg
|
|
58
|
+
* @return http exception based on given reply, with an optional message
|
|
59
|
+
*/
|
|
60
|
+
export declare function makeException(rep: Reply<any>, errMsg?: string): HTTPException;
|
|
61
|
+
export declare function extractIntHeader(rep: Reply<any>, headerName: string): number;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (C) 2015 - 2017, 2025 3NSoft Inc.
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
7
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
8
|
+
version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful, but
|
|
11
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
+
See the GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License along with
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.extractIntHeader = exports.makeException = exports.doBodylessRequest = exports.doTextRequest = exports.doBinaryRequest = exports.doJsonRequest = exports.request = exports.SESSION_ID_HEADER = void 0;
|
|
20
|
+
const http_1 = require("../../lib-common/exceptions/http");
|
|
21
|
+
const common_1 = require("../../lib-common/byte-streaming/common");
|
|
22
|
+
const xhr2 = require('xhr2');
|
|
23
|
+
exports.SESSION_ID_HEADER = "X-Session-Id";
|
|
24
|
+
function makeHeadersInstanceFrom(xhr, selectHeaders) {
|
|
25
|
+
const m = new Map();
|
|
26
|
+
for (const h of selectHeaders) {
|
|
27
|
+
if (typeof h !== 'string') {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const value = xhr.getResponseHeader(h);
|
|
31
|
+
if (typeof value !== 'string') {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
m.set(h.toLowerCase(), value);
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
get(name) {
|
|
38
|
+
return m.get(name.toLowerCase());
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function request(contentType, opts) {
|
|
43
|
+
const xhr = new xhr2();
|
|
44
|
+
const promise = new Promise((resolve, reject) => {
|
|
45
|
+
xhr.open(opts.method, opts.url);
|
|
46
|
+
xhr.onload = () => {
|
|
47
|
+
let data = xhr.response;
|
|
48
|
+
if ((opts.responseType === 'arraybuffer') &&
|
|
49
|
+
(data instanceof ArrayBuffer)) {
|
|
50
|
+
data = new Uint8Array(data);
|
|
51
|
+
}
|
|
52
|
+
const rep = {
|
|
53
|
+
url: opts.url,
|
|
54
|
+
method: opts.method,
|
|
55
|
+
status: xhr.status,
|
|
56
|
+
data: data
|
|
57
|
+
};
|
|
58
|
+
if (Array.isArray(opts.responseHeaders)) {
|
|
59
|
+
rep.headers = makeHeadersInstanceFrom(xhr, opts.responseHeaders);
|
|
60
|
+
}
|
|
61
|
+
resolve(rep);
|
|
62
|
+
};
|
|
63
|
+
xhr.onerror = ev => reject((0, http_1.makeConnectionException)(opts.url, opts.method, 'Cannot connect', ev));
|
|
64
|
+
if (contentType) {
|
|
65
|
+
xhr.setRequestHeader('Content-Type', contentType);
|
|
66
|
+
}
|
|
67
|
+
if (opts.sessionId) {
|
|
68
|
+
xhr.setRequestHeader(exports.SESSION_ID_HEADER, opts.sessionId);
|
|
69
|
+
}
|
|
70
|
+
if (opts.responseType) {
|
|
71
|
+
xhr.responseType = opts.responseType;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return { xhr, promise };
|
|
75
|
+
}
|
|
76
|
+
exports.request = request;
|
|
77
|
+
/**
|
|
78
|
+
* This assembles XMLHttpRequest with 'Content-Type: application/json' and
|
|
79
|
+
* sends given json.
|
|
80
|
+
* @param opts
|
|
81
|
+
* @param json
|
|
82
|
+
* @return a promise, resolvable to reply object
|
|
83
|
+
*/
|
|
84
|
+
function doJsonRequest(opts, json) {
|
|
85
|
+
const req = request('application/json', opts);
|
|
86
|
+
const body = ((json === undefined) ? '' : JSON.stringify(json));
|
|
87
|
+
req.xhr.send(body);
|
|
88
|
+
return req.promise;
|
|
89
|
+
}
|
|
90
|
+
exports.doJsonRequest = doJsonRequest;
|
|
91
|
+
/**
|
|
92
|
+
* This assembles XMLHttpRequest with 'Content-Type: application/octet-stream'
|
|
93
|
+
* and sends given bytes.
|
|
94
|
+
* @param opts
|
|
95
|
+
* @param bytes
|
|
96
|
+
* @return a promise, resolvable to reply object
|
|
97
|
+
*/
|
|
98
|
+
function doBinaryRequest(opts, bytes) {
|
|
99
|
+
const req = request('application/octet-stream', opts);
|
|
100
|
+
if (Array.isArray(bytes)) {
|
|
101
|
+
const fifo = new common_1.BytesFIFOBuffer();
|
|
102
|
+
for (const arr of bytes) {
|
|
103
|
+
fifo.push(arr);
|
|
104
|
+
}
|
|
105
|
+
req.xhr.send(fifo.getBytes(undefined));
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
req.xhr.send(bytes);
|
|
109
|
+
}
|
|
110
|
+
return req.promise;
|
|
111
|
+
}
|
|
112
|
+
exports.doBinaryRequest = doBinaryRequest;
|
|
113
|
+
/**
|
|
114
|
+
* This assembles XMLHttpRequest with 'Content-Type: text/plain'
|
|
115
|
+
* and sends given text
|
|
116
|
+
* @param opts
|
|
117
|
+
* @param txt
|
|
118
|
+
* @return a promise, resolvable to reply object
|
|
119
|
+
*/
|
|
120
|
+
function doTextRequest(opts, txt) {
|
|
121
|
+
const req = request('text/plain', opts);
|
|
122
|
+
req.xhr.send(txt);
|
|
123
|
+
return req.promise;
|
|
124
|
+
}
|
|
125
|
+
exports.doTextRequest = doTextRequest;
|
|
126
|
+
/**
|
|
127
|
+
* This assembles XMLHttpRequest without 'Content-Type'.
|
|
128
|
+
* @param opts
|
|
129
|
+
* @return a promise, resolvable to reply object
|
|
130
|
+
*/
|
|
131
|
+
function doBodylessRequest(opts) {
|
|
132
|
+
const req = request(undefined, opts);
|
|
133
|
+
req.xhr.send();
|
|
134
|
+
return req.promise;
|
|
135
|
+
}
|
|
136
|
+
exports.doBodylessRequest = doBodylessRequest;
|
|
137
|
+
/**
|
|
138
|
+
* @param rep
|
|
139
|
+
* @param errMsg
|
|
140
|
+
* @return http exception based on given reply, with an optional message
|
|
141
|
+
*/
|
|
142
|
+
function makeException(rep, errMsg) {
|
|
143
|
+
return (0, http_1.makeHTTPException)(rep.url, rep.method, rep.status, errMsg);
|
|
144
|
+
}
|
|
145
|
+
exports.makeException = makeException;
|
|
146
|
+
function extractIntHeader(rep, headerName) {
|
|
147
|
+
const intHeader = parseInt(rep.headers.get(headerName));
|
|
148
|
+
if (isNaN(intHeader)) {
|
|
149
|
+
throw makeException(rep, `Malformed response: header ${headerName} is missing or malformed`);
|
|
150
|
+
}
|
|
151
|
+
return intHeader;
|
|
152
|
+
}
|
|
153
|
+
exports.extractIntHeader = extractIntHeader;
|
|
154
|
+
Object.freeze(exports);
|