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