@qrvey/object-storage 1.0.4-539 → 1.0.5-737

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/dist/cjs/index.js CHANGED
@@ -6,8 +6,7 @@ var clientS3 = require('@aws-sdk/client-s3');
6
6
  var credentialProviderNode = require('@aws-sdk/credential-provider-node');
7
7
  var s3RequestPresigner = require('@aws-sdk/s3-request-presigner');
8
8
  var libStorage = require('@aws-sdk/lib-storage');
9
- var http = require('http');
10
- var https = require('https');
9
+ var nodeHttpHandler = require('@smithy/node-http-handler');
11
10
 
12
11
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
13
12
 
@@ -142,8 +141,15 @@ var BlobStorageService = class {
142
141
  */
143
142
  constructor(containerName) {
144
143
  this.containerName = containerName;
144
+ let connectionString;
145
+ if (process.env.DATA_LAKE_BUCKET && process.env.DATA_LAKE_BUCKET === this.containerName) {
146
+ connectionString = process.env.AZURE_DATALAKE_CONNECTION_STRING;
147
+ }
148
+ if (!connectionString) {
149
+ connectionString = process.env.AZURE_STORAGE_CONNECTION_STRING;
150
+ }
145
151
  this.blobServiceClient = storageBlob.BlobServiceClient.fromConnectionString(
146
- process.env.AZURE_STORAGE_CONNECTION_STRING
152
+ connectionString
147
153
  );
148
154
  }
149
155
  /**
@@ -634,457 +640,9 @@ function s3ObjectToObjectResponse(s3Object) {
634
640
  lastModified: s3Object.LastModified
635
641
  };
636
642
  }
637
-
638
- // node_modules/@smithy/types/dist-es/auth/auth.js
639
- var HttpAuthLocation;
640
- (function(HttpAuthLocation2) {
641
- HttpAuthLocation2["HEADER"] = "header";
642
- HttpAuthLocation2["QUERY"] = "query";
643
- })(HttpAuthLocation || (HttpAuthLocation = {}));
644
-
645
- // node_modules/@smithy/types/dist-es/auth/HttpApiKeyAuth.js
646
- var HttpApiKeyAuthLocation;
647
- (function(HttpApiKeyAuthLocation2) {
648
- HttpApiKeyAuthLocation2["HEADER"] = "header";
649
- HttpApiKeyAuthLocation2["QUERY"] = "query";
650
- })(HttpApiKeyAuthLocation || (HttpApiKeyAuthLocation = {}));
651
-
652
- // node_modules/@smithy/types/dist-es/endpoint.js
653
- var EndpointURLScheme;
654
- (function(EndpointURLScheme2) {
655
- EndpointURLScheme2["HTTP"] = "http";
656
- EndpointURLScheme2["HTTPS"] = "https";
657
- })(EndpointURLScheme || (EndpointURLScheme = {}));
658
-
659
- // node_modules/@smithy/types/dist-es/extensions/checksum.js
660
- var AlgorithmId;
661
- (function(AlgorithmId2) {
662
- AlgorithmId2["MD5"] = "md5";
663
- AlgorithmId2["CRC32"] = "crc32";
664
- AlgorithmId2["CRC32C"] = "crc32c";
665
- AlgorithmId2["SHA1"] = "sha1";
666
- AlgorithmId2["SHA256"] = "sha256";
667
- })(AlgorithmId || (AlgorithmId = {}));
668
-
669
- // node_modules/@smithy/types/dist-es/http.js
670
- var FieldPosition;
671
- (function(FieldPosition2) {
672
- FieldPosition2[FieldPosition2["HEADER"] = 0] = "HEADER";
673
- FieldPosition2[FieldPosition2["TRAILER"] = 1] = "TRAILER";
674
- })(FieldPosition || (FieldPosition = {}));
675
-
676
- // node_modules/@smithy/types/dist-es/profile.js
677
- var IniSectionType;
678
- (function(IniSectionType2) {
679
- IniSectionType2["PROFILE"] = "profile";
680
- IniSectionType2["SSO_SESSION"] = "sso-session";
681
- IniSectionType2["SERVICES"] = "services";
682
- })(IniSectionType || (IniSectionType = {}));
683
-
684
- // node_modules/@smithy/types/dist-es/transfer.js
685
- var RequestHandlerProtocol;
686
- (function(RequestHandlerProtocol2) {
687
- RequestHandlerProtocol2["HTTP_0_9"] = "http/0.9";
688
- RequestHandlerProtocol2["HTTP_1_0"] = "http/1.0";
689
- RequestHandlerProtocol2["TDS_8_0"] = "tds/8.0";
690
- })(RequestHandlerProtocol || (RequestHandlerProtocol = {}));
691
-
692
- // node_modules/@smithy/protocol-http/dist-es/httpResponse.js
693
- var HttpResponse = class {
694
- constructor(options) {
695
- this.statusCode = options.statusCode;
696
- this.reason = options.reason;
697
- this.headers = options.headers || {};
698
- this.body = options.body;
699
- }
700
- static isInstance(response) {
701
- if (!response)
702
- return false;
703
- const resp = response;
704
- return typeof resp.statusCode === "number" && typeof resp.headers === "object";
705
- }
706
- };
707
-
708
- // node_modules/@smithy/util-uri-escape/dist-es/escape-uri.js
709
- var escapeUri = (uri) => encodeURIComponent(uri).replace(/[!'()*]/g, hexEncode);
710
- var hexEncode = (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`;
711
-
712
- // node_modules/@smithy/querystring-builder/dist-es/index.js
713
- function buildQueryString(query) {
714
- const parts = [];
715
- for (let key of Object.keys(query).sort()) {
716
- const value = query[key];
717
- key = escapeUri(key);
718
- if (Array.isArray(value)) {
719
- for (let i = 0, iLen = value.length; i < iLen; i++) {
720
- parts.push(`${key}=${escapeUri(value[i])}`);
721
- }
722
- } else {
723
- let qsEntry = key;
724
- if (value || typeof value === "string") {
725
- qsEntry += `=${escapeUri(value)}`;
726
- }
727
- parts.push(qsEntry);
728
- }
729
- }
730
- return parts.join("&");
731
- }
732
-
733
- // node_modules/@smithy/node-http-handler/dist-es/constants.js
734
- var NODEJS_TIMEOUT_ERROR_CODES = ["ECONNRESET", "EPIPE", "ETIMEDOUT"];
735
-
736
- // node_modules/@smithy/node-http-handler/dist-es/get-transformed-headers.js
737
- var getTransformedHeaders = (headers) => {
738
- const transformedHeaders = {};
739
- for (const name of Object.keys(headers)) {
740
- const headerValues = headers[name];
741
- transformedHeaders[name] = Array.isArray(headerValues) ? headerValues.join(",") : headerValues;
742
- }
743
- return transformedHeaders;
744
- };
745
-
746
- // node_modules/@smithy/node-http-handler/dist-es/timing.js
747
- var timing = {
748
- setTimeout: (cb, ms) => setTimeout(cb, ms),
749
- clearTimeout: (timeoutId) => clearTimeout(timeoutId)
750
- };
751
-
752
- // node_modules/@smithy/node-http-handler/dist-es/set-connection-timeout.js
753
- var DEFER_EVENT_LISTENER_TIME = 1e3;
754
- var setConnectionTimeout = (request, reject, timeoutInMs = 0) => {
755
- if (!timeoutInMs) {
756
- return -1;
757
- }
758
- const registerTimeout = (offset) => {
759
- const timeoutId = timing.setTimeout(() => {
760
- request.destroy();
761
- reject(Object.assign(new Error(`Socket timed out without establishing a connection within ${timeoutInMs} ms`), {
762
- name: "TimeoutError"
763
- }));
764
- }, timeoutInMs - offset);
765
- const doWithSocket = (socket) => {
766
- if (socket == null ? void 0 : socket.connecting) {
767
- socket.on("connect", () => {
768
- timing.clearTimeout(timeoutId);
769
- });
770
- } else {
771
- timing.clearTimeout(timeoutId);
772
- }
773
- };
774
- if (request.socket) {
775
- doWithSocket(request.socket);
776
- } else {
777
- request.on("socket", doWithSocket);
778
- }
779
- };
780
- if (timeoutInMs < 2e3) {
781
- registerTimeout(0);
782
- return 0;
783
- }
784
- return timing.setTimeout(registerTimeout.bind(null, DEFER_EVENT_LISTENER_TIME), DEFER_EVENT_LISTENER_TIME);
785
- };
786
-
787
- // node_modules/@smithy/node-http-handler/dist-es/set-socket-keep-alive.js
788
- var DEFER_EVENT_LISTENER_TIME2 = 3e3;
789
- var setSocketKeepAlive = (request, { keepAlive, keepAliveMsecs }, deferTimeMs = DEFER_EVENT_LISTENER_TIME2) => {
790
- if (keepAlive !== true) {
791
- return -1;
792
- }
793
- const registerListener = () => {
794
- if (request.socket) {
795
- request.socket.setKeepAlive(keepAlive, keepAliveMsecs || 0);
796
- } else {
797
- request.on("socket", (socket) => {
798
- socket.setKeepAlive(keepAlive, keepAliveMsecs || 0);
799
- });
800
- }
801
- };
802
- if (deferTimeMs === 0) {
803
- registerListener();
804
- return 0;
805
- }
806
- return timing.setTimeout(registerListener, deferTimeMs);
807
- };
808
-
809
- // node_modules/@smithy/node-http-handler/dist-es/set-socket-timeout.js
810
- var DEFER_EVENT_LISTENER_TIME3 = 3e3;
811
- var setSocketTimeout = (request, reject, timeoutInMs = DEFAULT_REQUEST_TIMEOUT) => {
812
- const registerTimeout = (offset) => {
813
- const timeout = timeoutInMs - offset;
814
- const onTimeout = () => {
815
- request.destroy();
816
- reject(Object.assign(new Error(`Connection timed out after ${timeoutInMs} ms`), { name: "TimeoutError" }));
817
- };
818
- if (request.socket) {
819
- request.socket.setTimeout(timeout, onTimeout);
820
- request.on("close", () => {
821
- var _a;
822
- return (_a = request.socket) == null ? void 0 : _a.removeListener("timeout", onTimeout);
823
- });
824
- } else {
825
- request.setTimeout(timeout, onTimeout);
826
- }
827
- };
828
- if (0 < timeoutInMs && timeoutInMs < 6e3) {
829
- registerTimeout(0);
830
- return 0;
831
- }
832
- return timing.setTimeout(registerTimeout.bind(null, timeoutInMs === 0 ? 0 : DEFER_EVENT_LISTENER_TIME3), DEFER_EVENT_LISTENER_TIME3);
833
- };
834
- var MIN_WAIT_TIME = 6e3;
835
- async function writeRequestBody(httpRequest, request, maxContinueTimeoutMs = MIN_WAIT_TIME) {
836
- var _a;
837
- const headers = (_a = request.headers) != null ? _a : {};
838
- const expect = headers["Expect"] || headers["expect"];
839
- let timeoutId = -1;
840
- let sendBody = true;
841
- if (expect === "100-continue") {
842
- sendBody = await Promise.race([
843
- new Promise((resolve) => {
844
- timeoutId = Number(timing.setTimeout(() => resolve(true), Math.max(MIN_WAIT_TIME, maxContinueTimeoutMs)));
845
- }),
846
- new Promise((resolve) => {
847
- httpRequest.on("continue", () => {
848
- timing.clearTimeout(timeoutId);
849
- resolve(true);
850
- });
851
- httpRequest.on("response", () => {
852
- timing.clearTimeout(timeoutId);
853
- resolve(false);
854
- });
855
- httpRequest.on("error", () => {
856
- timing.clearTimeout(timeoutId);
857
- resolve(false);
858
- });
859
- })
860
- ]);
861
- }
862
- if (sendBody) {
863
- writeBody(httpRequest, request.body);
864
- }
865
- }
866
- function writeBody(httpRequest, body) {
867
- if (body instanceof stream.Readable) {
868
- body.pipe(httpRequest);
869
- return;
870
- }
871
- if (body) {
872
- if (Buffer.isBuffer(body) || typeof body === "string") {
873
- httpRequest.end(body);
874
- return;
875
- }
876
- const uint8 = body;
877
- if (typeof uint8 === "object" && uint8.buffer && typeof uint8.byteOffset === "number" && typeof uint8.byteLength === "number") {
878
- httpRequest.end(Buffer.from(uint8.buffer, uint8.byteOffset, uint8.byteLength));
879
- return;
880
- }
881
- httpRequest.end(Buffer.from(body));
882
- return;
883
- }
884
- httpRequest.end();
885
- }
886
-
887
- // node_modules/@smithy/node-http-handler/dist-es/node-http-handler.js
888
- var DEFAULT_REQUEST_TIMEOUT = 0;
889
- var NodeHttpHandler = class _NodeHttpHandler {
890
- static create(instanceOrOptions) {
891
- if (typeof (instanceOrOptions == null ? void 0 : instanceOrOptions.handle) === "function") {
892
- return instanceOrOptions;
893
- }
894
- return new _NodeHttpHandler(instanceOrOptions);
895
- }
896
- static checkSocketUsage(agent, socketWarningTimestamp, logger = console) {
897
- var _a, _b, _c, _d, _e;
898
- const { sockets, requests, maxSockets } = agent;
899
- if (typeof maxSockets !== "number" || maxSockets === Infinity) {
900
- return socketWarningTimestamp;
901
- }
902
- const interval = 15e3;
903
- if (Date.now() - interval < socketWarningTimestamp) {
904
- return socketWarningTimestamp;
905
- }
906
- if (sockets && requests) {
907
- for (const origin in sockets) {
908
- const socketsInUse = (_b = (_a = sockets[origin]) == null ? void 0 : _a.length) != null ? _b : 0;
909
- const requestsEnqueued = (_d = (_c = requests[origin]) == null ? void 0 : _c.length) != null ? _d : 0;
910
- if (socketsInUse >= maxSockets && requestsEnqueued >= 2 * maxSockets) {
911
- (_e = logger == null ? void 0 : logger.warn) == null ? void 0 : _e.call(logger, `@smithy/node-http-handler:WARN - socket usage at capacity=${socketsInUse} and ${requestsEnqueued} additional requests are enqueued.
912
- See https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/node-configuring-maxsockets.html
913
- or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler config.`);
914
- return Date.now();
915
- }
916
- }
917
- }
918
- return socketWarningTimestamp;
919
- }
920
- constructor(options) {
921
- this.socketWarningTimestamp = 0;
922
- this.metadata = { handlerProtocol: "http/1.1" };
923
- this.configProvider = new Promise((resolve, reject) => {
924
- if (typeof options === "function") {
925
- options().then((_options) => {
926
- resolve(this.resolveDefaultConfig(_options));
927
- }).catch(reject);
928
- } else {
929
- resolve(this.resolveDefaultConfig(options));
930
- }
931
- });
932
- }
933
- resolveDefaultConfig(options) {
934
- const { requestTimeout, connectionTimeout, socketTimeout, socketAcquisitionWarningTimeout, httpAgent, httpsAgent } = options || {};
935
- const keepAlive = true;
936
- const maxSockets = 50;
937
- return {
938
- connectionTimeout,
939
- requestTimeout: requestTimeout != null ? requestTimeout : socketTimeout,
940
- socketAcquisitionWarningTimeout,
941
- httpAgent: (() => {
942
- if (httpAgent instanceof http.Agent || typeof (httpAgent == null ? void 0 : httpAgent.destroy) === "function") {
943
- return httpAgent;
944
- }
945
- return new http.Agent(__spreadValues({ keepAlive, maxSockets }, httpAgent));
946
- })(),
947
- httpsAgent: (() => {
948
- if (httpsAgent instanceof https.Agent || typeof (httpsAgent == null ? void 0 : httpsAgent.destroy) === "function") {
949
- return httpsAgent;
950
- }
951
- return new https.Agent(__spreadValues({ keepAlive, maxSockets }, httpsAgent));
952
- })(),
953
- logger: console
954
- };
955
- }
956
- destroy() {
957
- var _a, _b, _c, _d;
958
- (_b = (_a = this.config) == null ? void 0 : _a.httpAgent) == null ? void 0 : _b.destroy();
959
- (_d = (_c = this.config) == null ? void 0 : _c.httpsAgent) == null ? void 0 : _d.destroy();
960
- }
961
- async handle(request, { abortSignal, requestTimeout } = {}) {
962
- if (!this.config) {
963
- this.config = await this.configProvider;
964
- }
965
- return new Promise((_resolve, _reject) => {
966
- var _a, _b, _c, _d, _e, _f;
967
- let writeRequestBodyPromise = void 0;
968
- const timeouts = [];
969
- const resolve = async (arg) => {
970
- await writeRequestBodyPromise;
971
- timeouts.forEach(timing.clearTimeout);
972
- _resolve(arg);
973
- };
974
- const reject = async (arg) => {
975
- await writeRequestBodyPromise;
976
- timeouts.forEach(timing.clearTimeout);
977
- _reject(arg);
978
- };
979
- if (!this.config) {
980
- throw new Error("Node HTTP request handler config is not resolved");
981
- }
982
- if (abortSignal == null ? void 0 : abortSignal.aborted) {
983
- const abortError = new Error("Request aborted");
984
- abortError.name = "AbortError";
985
- reject(abortError);
986
- return;
987
- }
988
- const isSSL = request.protocol === "https:";
989
- const agent = isSSL ? this.config.httpsAgent : this.config.httpAgent;
990
- timeouts.push(timing.setTimeout(() => {
991
- this.socketWarningTimestamp = _NodeHttpHandler.checkSocketUsage(agent, this.socketWarningTimestamp, this.config.logger);
992
- }, (_c = this.config.socketAcquisitionWarningTimeout) != null ? _c : ((_a = this.config.requestTimeout) != null ? _a : 2e3) + ((_b = this.config.connectionTimeout) != null ? _b : 1e3)));
993
- const queryString = buildQueryString(request.query || {});
994
- let auth = void 0;
995
- if (request.username != null || request.password != null) {
996
- const username = (_d = request.username) != null ? _d : "";
997
- const password = (_e = request.password) != null ? _e : "";
998
- auth = `${username}:${password}`;
999
- }
1000
- let path = request.path;
1001
- if (queryString) {
1002
- path += `?${queryString}`;
1003
- }
1004
- if (request.fragment) {
1005
- path += `#${request.fragment}`;
1006
- }
1007
- let hostname = (_f = request.hostname) != null ? _f : "";
1008
- if (hostname[0] === "[" && hostname.endsWith("]")) {
1009
- hostname = request.hostname.slice(1, -1);
1010
- } else {
1011
- hostname = request.hostname;
1012
- }
1013
- const nodeHttpsOptions = {
1014
- headers: request.headers,
1015
- host: hostname,
1016
- method: request.method,
1017
- path,
1018
- port: request.port,
1019
- agent,
1020
- auth
1021
- };
1022
- const requestFunc = isSSL ? https.request : http.request;
1023
- const req = requestFunc(nodeHttpsOptions, (res) => {
1024
- const httpResponse = new HttpResponse({
1025
- statusCode: res.statusCode || -1,
1026
- reason: res.statusMessage,
1027
- headers: getTransformedHeaders(res.headers),
1028
- body: res
1029
- });
1030
- resolve({ response: httpResponse });
1031
- });
1032
- req.on("error", (err) => {
1033
- if (NODEJS_TIMEOUT_ERROR_CODES.includes(err.code)) {
1034
- reject(Object.assign(err, { name: "TimeoutError" }));
1035
- } else {
1036
- reject(err);
1037
- }
1038
- });
1039
- if (abortSignal) {
1040
- const onAbort = () => {
1041
- req.destroy();
1042
- const abortError = new Error("Request aborted");
1043
- abortError.name = "AbortError";
1044
- reject(abortError);
1045
- };
1046
- if (typeof abortSignal.addEventListener === "function") {
1047
- const signal = abortSignal;
1048
- signal.addEventListener("abort", onAbort, { once: true });
1049
- req.once("close", () => signal.removeEventListener("abort", onAbort));
1050
- } else {
1051
- abortSignal.onabort = onAbort;
1052
- }
1053
- }
1054
- const effectiveRequestTimeout = requestTimeout != null ? requestTimeout : this.config.requestTimeout;
1055
- timeouts.push(setConnectionTimeout(req, reject, this.config.connectionTimeout));
1056
- timeouts.push(setSocketTimeout(req, reject, effectiveRequestTimeout));
1057
- const httpAgent = nodeHttpsOptions.agent;
1058
- if (typeof httpAgent === "object" && "keepAlive" in httpAgent) {
1059
- timeouts.push(setSocketKeepAlive(req, {
1060
- keepAlive: httpAgent.keepAlive,
1061
- keepAliveMsecs: httpAgent.keepAliveMsecs
1062
- }));
1063
- }
1064
- writeRequestBodyPromise = writeRequestBody(req, request, effectiveRequestTimeout).catch((e) => {
1065
- timeouts.forEach(timing.clearTimeout);
1066
- return _reject(e);
1067
- });
1068
- });
1069
- }
1070
- updateHttpClientConfig(key, value) {
1071
- this.config = void 0;
1072
- this.configProvider = this.configProvider.then((config) => {
1073
- return __spreadProps(__spreadValues({}, config), {
1074
- [key]: value
1075
- });
1076
- });
1077
- }
1078
- httpHandlerConfigs() {
1079
- var _a;
1080
- return (_a = this.config) != null ? _a : {};
1081
- }
1082
- };
1083
-
1084
- // src/services/storage/s3/s3Storage.service.ts
1085
643
  var S3StorageService = class {
1086
644
  constructor(bucketName, options) {
1087
- this.httpHandler = new NodeHttpHandler({
645
+ this.httpHandler = new nodeHttpHandler.NodeHttpHandler({
1088
646
  socketTimeout: 6e5
1089
647
  });
1090
648
  this.s3Client = new clientS3.S3Client({