@nathapp/nestjs-storage 2.1.5 → 3.0.0-rc.4

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.
Files changed (59) hide show
  1. package/README.md +129 -9
  2. package/dist/module/storage.module.js.map +1 -1
  3. package/dist/providers/azure-blob-storage.d.ts +22 -0
  4. package/dist/providers/azure-blob-storage.js +169 -0
  5. package/dist/providers/azure-blob-storage.js.map +1 -0
  6. package/dist/providers/base-storage.d.ts +3 -5
  7. package/dist/providers/base-storage.js +4 -1
  8. package/dist/providers/base-storage.js.map +1 -1
  9. package/dist/providers/dropbox-storage.d.ts +3 -5
  10. package/dist/providers/dropbox-storage.js +84 -151
  11. package/dist/providers/dropbox-storage.js.map +1 -1
  12. package/dist/providers/gcs-storage.d.ts +22 -0
  13. package/dist/providers/gcs-storage.js +132 -0
  14. package/dist/providers/gcs-storage.js.map +1 -0
  15. package/dist/providers/gdrive-storage.d.ts +3 -5
  16. package/dist/providers/gdrive-storage.js +109 -192
  17. package/dist/providers/gdrive-storage.js.map +1 -1
  18. package/dist/providers/index.d.ts +2 -0
  19. package/dist/providers/index.js +2 -0
  20. package/dist/providers/index.js.map +1 -1
  21. package/dist/providers/local-storage.d.ts +5 -6
  22. package/dist/providers/local-storage.js +68 -128
  23. package/dist/providers/local-storage.js.map +1 -1
  24. package/dist/providers/oss-storage.d.ts +1 -1
  25. package/dist/providers/oss-storage.js +10 -4
  26. package/dist/providers/oss-storage.js.map +1 -1
  27. package/dist/providers/provider-factory.js +8 -0
  28. package/dist/providers/provider-factory.js.map +1 -1
  29. package/dist/providers/s3-base-storage.d.ts +7 -10
  30. package/dist/providers/s3-base-storage.js +50 -95
  31. package/dist/providers/s3-base-storage.js.map +1 -1
  32. package/dist/service/storage-service.d.ts +3 -0
  33. package/dist/service/storage-service.js +25 -4
  34. package/dist/service/storage-service.js.map +1 -1
  35. package/dist/types/capabilities.d.ts +15 -0
  36. package/dist/types/capabilities.js +3 -0
  37. package/dist/types/capabilities.js.map +1 -0
  38. package/dist/types/clients.d.ts +216 -0
  39. package/dist/types/clients.js +3 -0
  40. package/dist/types/clients.js.map +1 -0
  41. package/dist/types/index.d.ts +1 -0
  42. package/dist/types/index.js +1 -0
  43. package/dist/types/index.js.map +1 -1
  44. package/dist/types/options.d.ts +28 -2
  45. package/dist/types/options.js +2 -0
  46. package/dist/types/options.js.map +1 -1
  47. package/dist/types/storage.d.ts +7 -2
  48. package/dist/util/imageUtils.js +9 -3
  49. package/dist/util/imageUtils.js.map +1 -1
  50. package/docs/20260215-fix-plan-storage.md +66 -0
  51. package/docs/20260215-implementation-report.md +33 -0
  52. package/docs/20260215-plan-storage-providers.md +207 -0
  53. package/docs/20260215-review-storage-postfix.md +278 -0
  54. package/docs/20260215-review-storage.md +284 -0
  55. package/docs/20260216-plan-storage-a-minus.md +41 -0
  56. package/docs/20260216-review-storage-postfix2.md +102 -0
  57. package/docs/gdrive-security.md +222 -0
  58. package/docs/provider-capabilities.md +448 -0
  59. package/package.json +8 -3
@@ -1 +1 @@
1
- {"version":3,"file":"s3-base-storage.js","sourceRoot":"","sources":["../../lib/providers/s3-base-storage.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;AAG7C,8EAAqE;AAGrE,MAAa,aAAc,SAAQ,0BAAW;IAM5C,YAAY,EACV,QAAQ,EACR,OAAO,GAIR;QACC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAChB,MAAM,GAAG,GAAG,IAAA,+BAAW,EAAC,SAAS,EAAE,aAAa,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;QACjF,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,CAAC,EAAE,CAAC;YACxB,GAAG,OAAO;YACV,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,MAAM;YAChC,gBAAgB,EAAE,IAAI;SACvB,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM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AAS,CAAC;YACT,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,GAAG,EAAE,MAAM;YACX,KAAK,EAAE,KAAK;SACb,CAAC;aACD,gBAAgB,EAAE,CAAC;QAEtB,OAAO;YACL,MAAM;YACN,OAAO;SACR,CAAC;IACJ,CAAC;IAEO,SAAS,CACf,MAAc,EACd,IAAmB;QAEnB,OAAO;YACL,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC;YAC1C,QAAQ,EAAE,IAAI,CAAC,WAAW,IAAI,IAAI;YAClC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC;YAC9B,UAAU,EAAE,IAAI,CAAC,YAAY,IAAI,IAAI,IAAI,EAAE;SAC5C,CAAC;IACJ,CAAC;CACF;AApJD,sCAoJC"}
@@ -18,4 +18,7 @@ export declare class StorageService {
18
18
  resolveClientUploadCallback(payload: ClientUploadCallbackPayload, options?: ClientUploadCallbackOptions): Promise<import("../types").ClientUploadCallbackResult>;
19
19
  preprocessImage(sourceFileId: string, targetFileId: string, options: PreprocessImageOptions): Promise<PreprocessImageResult>;
20
20
  getProvider(): import("../types").Provider;
21
+ private supportsStreaming;
22
+ private supportsClientUpload;
23
+ private supportsImageProcessing;
21
24
  }
@@ -47,20 +47,41 @@ let StorageService = class StorageService {
47
47
  return this.storageProvider.getSignedUrl(fileId, expires);
48
48
  }
49
49
  streamFile(fileId, range) {
50
- return this.storageProvider.streamFile(fileId, range);
50
+ if (this.supportsStreaming(this.storageProvider)) {
51
+ return this.storageProvider.streamFile(fileId, range);
52
+ }
53
+ throw new Error(`Provider ${this.storageProvider.storageProvider} does not support streaming`);
51
54
  }
52
55
  getClientUploadCredential(option) {
53
- return this.storageProvider.getClientUploadCredential(option);
56
+ if (this.supportsClientUpload(this.storageProvider)) {
57
+ return this.storageProvider.getClientUploadCredential(option);
58
+ }
59
+ throw new Error(`Provider ${this.storageProvider.storageProvider} does not support client upload`);
54
60
  }
55
61
  resolveClientUploadCallback(payload, options) {
56
- return this.storageProvider.resolveClientUploadCallback(payload, options);
62
+ if (this.supportsClientUpload(this.storageProvider)) {
63
+ return this.storageProvider.resolveClientUploadCallback(payload, options);
64
+ }
65
+ throw new Error(`Provider ${this.storageProvider.storageProvider} does not support client upload`);
57
66
  }
58
67
  preprocessImage(sourceFileId, targetFileId, options) {
59
- return this.storageProvider.preprocessImage(sourceFileId, targetFileId, options);
68
+ if (this.supportsImageProcessing(this.storageProvider)) {
69
+ return this.storageProvider.preprocessImage(sourceFileId, targetFileId, options);
70
+ }
71
+ throw new Error(`Provider ${this.storageProvider.storageProvider} does not support image preprocessing`);
60
72
  }
61
73
  getProvider() {
62
74
  return this.storageProvider.storageProvider;
63
75
  }
76
+ supportsStreaming(provider) {
77
+ return 'streamFile' in provider && typeof provider.streamFile === 'function';
78
+ }
79
+ supportsClientUpload(provider) {
80
+ return 'getClientUploadCredential' in provider && typeof provider.getClientUploadCredential === 'function';
81
+ }
82
+ supportsImageProcessing(provider) {
83
+ return 'preprocessImage' in provider && typeof provider.preprocessImage === 'function';
84
+ }
64
85
  };
65
86
  exports.StorageService = StorageService;
66
87
  exports.StorageService = StorageService = __decorate([
@@ -1 +1 @@
1
- {"version":3,"file":"storage-service.js","sourceRoot":"","sources":["../../lib/service/storage-service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,4DAAwD;AAIjD,IAAM,cAAc,GAApB,MAAM,cAAc;IACzB,YAA6B,eAA4B;QAA5B,oBAAe,GAAf,eAAe,CAAa;IAAG,CAAC;IAE7D,OAAO,CAAC,IAAY,EAAE,IAAY;QAChC,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAClD,CAAC;IAED,eAAe,CAAC,MAAc;QAC5B,OAAO,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,M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AAC,eAAe,CAAC,2BAA2B,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC5E,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,YAAY,IAAI,CAAC,eAAe,CAAC,eAAe,iCAAiC,CAAC,CAAC;IACrG,CAAC;IAED,eAAe,CAAC,YAAoB,EAAE,YAAoB,EAAE,OAA+B;QACzF,IAAI,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC;YACvD,OAAO,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,YAAY,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;QACnF,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,YAAY,IAAI,CAAC,eAAe,CAAC,eAAe,uCAAuC,CAAC,CAAC;IAC3G,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC;IAC9C,CAAC;IAEO,iBAAiB,CAAC,QAAqB;QAC7C,OAAO,YAAY,IAAI,QAAQ,IAAI,OAAQ,QAAgB,CAAC,UAAU,KAAK,UAAU,CAAC;IACxF,CAAC;IAEO,oBAAoB,CAAC,QAAqB;QAChD,OAAO,2BAA2B,IAAI,QAAQ,IAAI,OAAQ,QAAgB,CAAC,yBAAyB,KAAK,UAAU,CAAC;IACtH,CAAC;IAEO,uBAAuB,CAAC,QAAqB;QACnD,OAAO,iBAAiB,IAAI,QAAQ,IAAI,OAAQ,QAAgB,CAAC,eAAe,KAAK,UAAU,CAAC;IAClG,CAAC;CACF,CAAA;AAtFY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAU,GAAE;qCAEmC,0BAAW;GAD9C,cAAc,CAsF1B"}
@@ -0,0 +1,15 @@
1
+ import { ClientCredentialOptions, ClientUploadCallbackOptions, ClientUploadCallbackPayload, ClientUploadCallbackResult, PartialStream, PreprocessImageOptions, PreprocessImageResult } from './storage';
2
+ export interface ISignedUrlCapable {
3
+ getSignedUrl(fileId: string, expires?: number): Promise<string>;
4
+ getObjectUrl(fileId: string): Promise<string>;
5
+ }
6
+ export interface IClientUploadCapable {
7
+ getClientUploadCredential(option: ClientCredentialOptions): Promise<any>;
8
+ resolveClientUploadCallback(payload: ClientUploadCallbackPayload, options?: ClientUploadCallbackOptions): Promise<ClientUploadCallbackResult>;
9
+ }
10
+ export interface IImageProcessingCapable {
11
+ preprocessImage(sourceFileId: string, targetFileId: string, options: PreprocessImageOptions): Promise<PreprocessImageResult>;
12
+ }
13
+ export interface IStreamCapable {
14
+ streamFile(fileId: string, range: string): Promise<PartialStream>;
15
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=capabilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../../lib/types/capabilities.ts"],"names":[],"mappings":""}
@@ -0,0 +1,216 @@
1
+ export interface IS3Client {
2
+ putObject(params: {
3
+ Bucket: string;
4
+ Key: string;
5
+ Body: Buffer;
6
+ }): {
7
+ promise: () => Promise<unknown>;
8
+ };
9
+ deleteObject(params: {
10
+ Bucket: string;
11
+ Key: string;
12
+ }): {
13
+ promise: () => Promise<unknown>;
14
+ };
15
+ headObject(params: {
16
+ Bucket: string;
17
+ Key: string;
18
+ }): {
19
+ promise: () => Promise<IS3HeadObjectResult>;
20
+ };
21
+ copyObject(params: {
22
+ Bucket: string;
23
+ CopySource: string;
24
+ Key: string;
25
+ }): {
26
+ promise: () => Promise<unknown>;
27
+ };
28
+ getObject(params: {
29
+ Bucket: string;
30
+ Key: string;
31
+ Range?: string;
32
+ }): {
33
+ promise: () => Promise<IS3GetObjectResult>;
34
+ createReadStream: () => NodeJS.ReadableStream;
35
+ };
36
+ listObjectsV2(params: {
37
+ Bucket: string;
38
+ Prefix: string;
39
+ }): {
40
+ promise: () => Promise<IS3ListObjectsResult>;
41
+ };
42
+ getSignedUrlPromise(operation: string, params: {
43
+ Bucket: string;
44
+ Key: string;
45
+ Expires: number;
46
+ }): Promise<string>;
47
+ }
48
+ export interface IS3HeadObjectResult {
49
+ ContentLength?: number;
50
+ ContentType?: string;
51
+ LastModified?: Date;
52
+ }
53
+ export interface IS3GetObjectResult {
54
+ Body?: Buffer | string | NodeJS.ReadableStream;
55
+ }
56
+ export interface IS3ObjectMeta {
57
+ Key?: string;
58
+ Size?: number;
59
+ ContentLength?: number;
60
+ ContentType?: string;
61
+ LastModified?: Date;
62
+ }
63
+ export interface IS3ListObjectsResult {
64
+ Contents?: IS3ObjectMeta[];
65
+ }
66
+ export interface IOssClient {
67
+ put(key: string, data: Buffer): Promise<IOssResult>;
68
+ delete(key: string): Promise<unknown>;
69
+ get(key: string): Promise<IOssGetResult>;
70
+ copy(targetKey: string, sourceKey: string): Promise<unknown>;
71
+ listV2(params: {
72
+ prefix: string;
73
+ }, options: Record<string, unknown>): Promise<IOssListResult>;
74
+ generateObjectUrl(key: string, baseUrl?: string): string;
75
+ signatureUrl(key: string, options: {
76
+ expires: number;
77
+ }): string;
78
+ getStream(key: string, options: {
79
+ headers: Record<string, string | number>;
80
+ }): Promise<IOssStreamResult>;
81
+ calculatePostSignature(policy: {
82
+ expiration: string;
83
+ conditions: unknown[];
84
+ }): {
85
+ policy: string;
86
+ Signature: string;
87
+ OSSAccessKeyId: string;
88
+ };
89
+ processObjectSave(sourceKey: string, targetKey: string, process: string, targetBucket?: string): Promise<IOssProcessResult>;
90
+ }
91
+ export interface IOssResult {
92
+ name: string;
93
+ res: {
94
+ status: number;
95
+ statusMessage?: string;
96
+ headers: Record<string, string>;
97
+ };
98
+ }
99
+ export interface IOssGetResult {
100
+ content: NodeJS.ReadableStream;
101
+ res: {
102
+ headers: {
103
+ 'content-length'?: string;
104
+ 'content-type'?: string;
105
+ date?: string;
106
+ };
107
+ };
108
+ }
109
+ export interface IOssObjectMeta {
110
+ name: string;
111
+ size?: number;
112
+ lastModified?: Date;
113
+ }
114
+ export interface IOssListResult {
115
+ objects: IOssObjectMeta[];
116
+ }
117
+ export interface IOssStreamResult {
118
+ stream: NodeJS.ReadableStream;
119
+ }
120
+ export interface IOssProcessResult {
121
+ res: {
122
+ status: number;
123
+ statusMessage?: string;
124
+ };
125
+ }
126
+ export interface IGDriveClient {
127
+ files: {
128
+ create(params: {
129
+ resource?: {
130
+ name: string;
131
+ mimeType?: string;
132
+ parents?: string[];
133
+ };
134
+ media?: {
135
+ mimeType: string;
136
+ body: Buffer | NodeJS.ReadableStream;
137
+ };
138
+ fields?: string;
139
+ }): Promise<IGDriveResponse>;
140
+ delete(params: {
141
+ fileId: string;
142
+ supportsAllDrives?: boolean;
143
+ }): Promise<unknown>;
144
+ get(params: {
145
+ fileId: string;
146
+ alt?: string;
147
+ supportsAllDrives?: boolean;
148
+ fields?: string;
149
+ }, options: {
150
+ responseType: 'stream';
151
+ headers?: Record<string, string>;
152
+ }): Promise<IGDriveStreamResponse>;
153
+ get(params: {
154
+ fileId: string;
155
+ alt?: string;
156
+ supportsAllDrives?: boolean;
157
+ fields?: string;
158
+ }, options?: {
159
+ responseType?: string;
160
+ headers?: Record<string, string>;
161
+ }): Promise<IGDriveResponse>;
162
+ update(params: {
163
+ fileId: string;
164
+ supportsAllDrives?: boolean;
165
+ addParents?: string;
166
+ removeParents?: string;
167
+ requestBody?: {
168
+ name: string;
169
+ };
170
+ fields?: string;
171
+ }): Promise<IGDriveResponse>;
172
+ list(params: {
173
+ q?: string;
174
+ fields?: string;
175
+ supportsAllDrives?: boolean;
176
+ pageToken?: string;
177
+ spaces?: string;
178
+ orderBy?: string;
179
+ pageSize?: number;
180
+ }): Promise<IGDriveListResponse>;
181
+ };
182
+ }
183
+ export interface IGDriveFile {
184
+ id?: string;
185
+ name?: string;
186
+ size?: string;
187
+ parents?: string[];
188
+ modifiedTime?: string;
189
+ mimeType?: string;
190
+ webContentLink?: string;
191
+ contentHints?: {
192
+ thumbnail?: unknown;
193
+ };
194
+ videoMediaMetadata?: unknown;
195
+ thumbnailLink?: string;
196
+ explicitlyTrashed?: boolean;
197
+ }
198
+ export interface IGDriveResponse {
199
+ data: IGDriveFile;
200
+ headers?: Record<string, string>;
201
+ }
202
+ export interface IGDriveStreamResponse {
203
+ data: NodeJS.ReadableStream;
204
+ headers: Record<string, string>;
205
+ }
206
+ export interface IGDriveListResponse {
207
+ data: {
208
+ files?: IGDriveFile[];
209
+ nextPageToken?: string;
210
+ };
211
+ }
212
+ export interface IHttpRequest {
213
+ headers: Record<string, string>;
214
+ body?: unknown;
215
+ url?: string;
216
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=clients.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clients.js","sourceRoot":"","sources":["../../lib/types/clients.ts"],"names":[],"mappings":""}
@@ -1,2 +1,3 @@
1
1
  export * from './options';
2
2
  export * from './storage';
3
+ export * from './clients';
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./options"), exports);
18
18
  __exportStar(require("./storage"), exports);
19
+ __exportStar(require("./clients"), exports);
19
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,4CAA0B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,4CAA0B;AAC1B,4CAA0B"}
@@ -1,5 +1,5 @@
1
1
  import { JwtOptions } from "@nathapp/auth";
2
- export type StorageOption = LocalStorageOption | NFSStorageOption | OssStorageOption | S3StorageOption | R2StorageOption | GDriveStorageOption | DropboxStorageOption;
2
+ export type StorageOption = LocalStorageOption | NFSStorageOption | OssStorageOption | S3StorageOption | R2StorageOption | GDriveStorageOption | DropboxStorageOption | AzureBlobStorageOption | GCSStorageOption;
3
3
  export declare enum Provider {
4
4
  LOCAL = "LOCAL",
5
5
  NFS = "NFS",
@@ -7,7 +7,9 @@ export declare enum Provider {
7
7
  R2 = "R2",
8
8
  GDRIVE = "GDRIVE",
9
9
  DROPBOX = "DROPBOX",
10
- OSS = "OSS"
10
+ OSS = "OSS",
11
+ AZURE_BLOB = "AZURE_BLOB",
12
+ GCS = "GCS"
11
13
  }
12
14
  export type LocalStorageOption = {
13
15
  provider: Provider.LOCAL;
@@ -71,3 +73,27 @@ export type DropboxStorageOption = {
71
73
  refreshToken: string;
72
74
  };
73
75
  };
76
+ export type AzureBlobOptions = {
77
+ connectionString?: string;
78
+ accountName?: string;
79
+ accountKey?: string;
80
+ containerName: string;
81
+ sasToken?: string;
82
+ };
83
+ export type AzureBlobStorageOption = {
84
+ provider: Provider.AZURE_BLOB;
85
+ options: AzureBlobOptions;
86
+ };
87
+ export type GCSOptions = {
88
+ projectId?: string;
89
+ keyFilename?: string;
90
+ credentials?: {
91
+ client_email: string;
92
+ private_key: string;
93
+ };
94
+ bucketName: string;
95
+ };
96
+ export type GCSStorageOption = {
97
+ provider: Provider.GCS;
98
+ options: GCSOptions;
99
+ };
@@ -10,5 +10,7 @@ var Provider;
10
10
  Provider["GDRIVE"] = "GDRIVE";
11
11
  Provider["DROPBOX"] = "DROPBOX";
12
12
  Provider["OSS"] = "OSS";
13
+ Provider["AZURE_BLOB"] = "AZURE_BLOB";
14
+ Provider["GCS"] = "GCS";
13
15
  })(Provider || (exports.Provider = Provider = {}));
14
16
  //# sourceMappingURL=options.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"options.js","sourceRoot":"","sources":["../../lib/types/options.ts"],"names":[],"mappings":";;;AAWA,IAAY,QAQX;AARD,WAAY,QAAQ;IAClB,2BAAe,CAAA;IACf,uBAAW,CAAA;IACX,qBAAS,CAAA;IACT,qBAAS,CAAA;IACT,6BAAiB,CAAA;IACjB,+BAAmB,CAAA;IACnB,uBAAW,CAAA;AACb,CAAC,EARW,QAAQ,wBAAR,QAAQ,QAQnB"}
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["../../lib/types/options.ts"],"names":[],"mappings":";;;AAaA,IAAY,QAUX;AAVD,WAAY,QAAQ;IAClB,2BAAe,CAAA;IACf,uBAAW,CAAA;IACX,qBAAS,CAAA;IACT,qBAAS,CAAA;IACT,6BAAiB,CAAA;IACjB,+BAAmB,CAAA;IACnB,uBAAW,CAAA;IACX,qCAAyB,CAAA;IACzB,uBAAW,CAAA;AACb,CAAC,EAVW,QAAQ,wBAAR,QAAQ,QAUnB"}
@@ -34,8 +34,13 @@ export interface ClientOSSCredentialOptions {
34
34
  replaceOrigin?: boolean;
35
35
  }
36
36
  export interface ClientOssUploadCallbackPayload {
37
- headers?: any;
38
- payload: any;
37
+ headers?: Record<string, string>;
38
+ payload: {
39
+ filename?: string;
40
+ mimeType?: string;
41
+ size?: number;
42
+ [key: string]: unknown;
43
+ };
39
44
  url?: string;
40
45
  }
41
46
  export interface ClientUploadCallbackResult {
@@ -24,14 +24,20 @@ const compressImageBuffer = async (buffer, options) => {
24
24
  const image = sharp(buffer);
25
25
  const meta = await image.metadata();
26
26
  const { format } = meta;
27
+ const allowedFormats = ['jpeg', 'png', 'webp'];
28
+ if (!format || !allowedFormats.includes(format)) {
29
+ throw new Error(`Unsupported image format: ${format}. Allowed formats: ${allowedFormats.join(', ')}`);
30
+ }
27
31
  if (width || height) {
28
32
  if (checkResize) {
29
- if ((width && meta.width && meta.width > width) || (height && meta.height && meta.height > height)) {
30
- image.resize(width, height, resizeOptions);
33
+ const shouldResizeWidth = width && meta.width && meta.width > width;
34
+ const shouldResizeHeight = height && meta.height && meta.height > height;
35
+ if (shouldResizeWidth || shouldResizeHeight) {
36
+ image.resize(width || undefined, height || undefined, resizeOptions);
31
37
  }
32
38
  }
33
39
  else {
34
- image.resize(width, height, resizeOptions);
40
+ image.resize(width || undefined, height || undefined, resizeOptions);
35
41
  }
36
42
  }
37
43
  return image.toFormat(format, config[format]).toBuffer();
@@ -1 +1 @@
1
- {"version":3,"file":"imageUtils.js","sourceRoot":"","sources":["../../lib/util/imageUtils.ts"],"names":[],"mappings":";;;AAAA,+BAA+B;AAElB,QAAA,wBAAwB,GAAG;IACtC,IAAI,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;IACrB,GAAG,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE;IACrB,IAAI,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;CACtB,CAAA;AAcM,MAAM,gBAAgB,GAAG,CAAC,QAAgB,EAAU,EAAE;IAC3D,OAAO,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC;AACzC,CAAC,CAAA;AAFY,QAAA,gBAAgB,oBAE5B;AAEM,MAAM,sBAAsB,GAAG,CAAC,QAAgB,EAAU,EAAE;IACjE,MAAM,SAAS,GAAG,IAAA,wBAAgB,EAAC,QAAQ,CAAC,CAAC;IAC7C,IAAI,SAAS,KAAK,KAAK,EAAE,CAAC;QACxB,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAA;AANY,QAAA,sBAAsB,0BAMlC;AAEM,MAAM,mBAAmB,GAAG,KAAK,EAAE,MAAc,EAAE,OAA8B,EAAmB,EAAE;IAC3G,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAG,gCAAwB,EAAE,aAAa,EAAE,WAAW,GAAG,IAAI,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IAC9G,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5B,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,QAAQ,EAAE,CAAA;IACnC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;IACvB,IAAI,KAAK,IAAI,MAAM,EAAE,CAAC;QACpB,IAAG,WAAW,EAAE,CAAC;YACf,I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KAAK,IAAI,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;YACpE,MAAM,kBAAkB,GAAG,MAAM,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;YAEzE,IAAI,iBAAiB,IAAI,kBAAkB,EAAE,CAAC;gBAC5C,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,SAAS,EAAE,MAAM,IAAI,SAAS,EAAE,aAAa,CAAC,CAAC;YACvE,CAAC;QACH,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,SAAS,EAAE,MAAM,IAAI,SAAS,EAAE,aAAa,CAAC,CAAC;QACvE,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;AAC3D,CAAC,CAAA;AA3BY,QAAA,mBAAmB,uBA2B/B;AAGM,MAAM,sBAAsB,GAAG,KAAK,EAAE,MAAc,EAAE,OAA8B,EAAmB,EAAE;IAC9G,IAAI,CAAC;QACH,MAAM,gBAAgB,GAAG,MAAM,IAAA,2BAAmB,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACpE,IAAI,gBAAgB,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;YACpD,OAAO,gBAAgB,CAAC;QAC1B,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,MAAM,CAAC;IAChB,CAAC;AACH,CAAC,CAAA;AAVY,QAAA,sBAAsB,0BAUlC"}
@@ -0,0 +1,66 @@
1
+ # Fix Plan: @nathapp/nestjs-storage
2
+
3
+ **Date:** 2026-02-15
4
+ **Branch:** `feat/monorepo-enterprise-upgrade`
5
+ **Target:** Upgrade from Grade C (65/100) to Grade B+ (minimum 80/100)
6
+ **SECURITY CRITICAL:** Contains CVE-level path traversal vulnerability
7
+
8
+ ## Phase 0: Security Hotfixes (CRITICAL - DO NOT SKIP)
9
+ - [ ] **SEC-1 (Critical):** Add path traversal protection to `LocalStorage`
10
+ - Implementation: Add `validatePath()` private method that uses `path.resolve` and checks `startsWith(this.root)`
11
+ - Apply to all methods: `putFile`, `getFileOrFolder`, `deleteFileOrFolder`, `moveFileOrFolder`, `renameFileOrFolder`, `createFolder`, `readFile`, `readFolder`, `streamFile`
12
+ - [ ] **SEC-2 (Critical):** Remove unused AWS import from `lib/types/storage.ts:1`
13
+ - Delete: `import { bool } from "aws-sdk/clients/signer";`
14
+
15
+ ## Phase 1: Reliability & Type Safety (P0)
16
+ - [ ] **BUG-1 (Critical):** Fix S3 `readFile` return type mismatch
17
+ - Implementation: Convert `data.Body` to proper `Readable` stream using `stream.Readable.from()` or check if already a stream
18
+ - Add unit test to verify stream behavior
19
+ - [ ] **MEM-1 (Critical):** Add error handlers to all file streams
20
+ - Locations: `LocalStorage.readFile`, `LocalStorage.streamFile`, `S3BaseStorage.streamFile`
21
+ - Pattern: `stream.on('error', reject)` before resolving
22
+
23
+ ## Phase 2: Modernization & Code Quality (P1)
24
+ - [ ] **PERF-1 (Medium):** Replace callback-style fs with `fs.promises` in `LocalStorage`
25
+ - Convert all methods to `async/await` pattern
26
+ - Remove unnecessary `new Promise` wrappers
27
+ - Methods: `createFolder`, `deleteFileOrFolder`, `getFileOrFolder`, `putFile`, `readFile`, `readFolder`, `renameFileOrFolder`
28
+ - [ ] **TYPE-1 (Medium):** Define interfaces for storage provider SDKs
29
+ - Create `lib/types/provider-interfaces.ts`
30
+ - Define `IS3Client`, `IOSSClient`, `IGDriveClient` interfaces with minimal required methods
31
+ - Replace `any` with these interfaces in provider classes
32
+ - [ ] **BUG-2 (Medium):** Add format validation to `compressImageBuffer`
33
+ - Allow-list: `['jpeg', 'png', 'webp', 'tiff', 'bmp', 'gif']`
34
+ - Throw error for unsupported formats
35
+ - [ ] **ENH-1 (Medium):** Document unsupported methods
36
+ - Add JSDoc `@throws {Error} Method not supported by this provider` to all unimplemented methods
37
+ - Create provider capability matrix in README.md
38
+
39
+ ## Phase 3: Bug Fixes & Polish (P2)
40
+ - [ ] **BUG-3 (Low):** Fix image resize condition logic in `imageUtils.ts:37`
41
+ - Implementation: Validate both width and height are set before calling resize, or handle each dimension independently
42
+ - [ ] **BUG-4 (Low):** Add security warning JSDoc to GDrive refresh token handling
43
+ - Add: `@security Store refreshToken in environment variables, never log`
44
+
45
+ ## Breaking Changes Gate
46
+ **STOP:** Before executing Phase 1, confirm with William that `BUG-1` (S3 readFile stream fix) is acceptable.
47
+ - Current behavior: May return Buffer in some cases
48
+ - New behavior: Always returns proper Readable stream
49
+ - Migration: Consumers using `.toString()` on the result need to use stream events instead
50
+
51
+ ## Verification Plan
52
+ - [ ] **Unit Tests:** Add tests for path traversal protection (expect throws for `../../../etc/passwd`)
53
+ - [ ] **Integration:** Verify S3 stream behavior with real AWS SDK
54
+ - [ ] **Security Scan:** Run `npm audit` after fixing dependencies
55
+ - [ ] **Coverage Target:** Increase from <10% to minimum 40%
56
+
57
+ ## Out of Scope (Deferred to v3.1 or v4)
58
+ - Enabling TypeScript strict mode (requires extensive refactoring)
59
+ - Full test suite for all providers (requires mocking strategy)
60
+ - Stream backpressure handling (ENH-4)
61
+ - OSS signature timing attack hardening (SEC-3) - acceptable risk for v3.0
62
+
63
+ ## Critical Notes
64
+ 1. **SEC-1 is a CVE-level vulnerability** - must be fixed before any production deployment
65
+ 2. **Phase 0 should be hotfixed immediately** even if other phases are delayed
66
+ 3. **BUG-1 is technically breaking** but fixes incorrect behavior - mark as BREAKING CHANGE in changelog
@@ -0,0 +1,33 @@
1
+ # Subagent Report
2
+
3
+ I have completed the task to standardize storage providers and add Azure Blob Storage and Google Cloud Storage (GCS) support to `@nathapp/nestjs-storage`.
4
+
5
+ ## Accomplishments
6
+
7
+ 1. **Capability Interfaces**: Created `lib/types/capabilities.ts` with `ISignedUrlCapable`, `IStreamCapable`, `IClientUploadCapable`, `IImageProcessingCapable`.
8
+ 2. **BaseStorage Refactor**: Refactored `BaseStorage` to remove optional methods and enforce capability checks.
9
+ 3. **Provider Standardization**:
10
+ * **LocalStorage**: Converted to `async/await` (fs.promises), implemented `IStreamCapable`.
11
+ * **S3BaseStorage**: Converted to full `async/await`, implemented `IStreamCapable`.
12
+ * **GDriveStorage**: Converted to `async/await`, implemented `IStreamCapable`.
13
+ * **DropboxStorage**: Converted to `async/await` (using `fetch`), implemented `IStreamCapable`.
14
+ 4. **New Providers**:
15
+ * **Azure Blob Storage**: Implemented in `lib/providers/azure-blob-storage.ts` using `@azure/storage-blob`.
16
+ * **Google Cloud Storage**: Implemented in `lib/providers/gcs-storage.ts` using `@google-cloud/storage`.
17
+ 5. **Integration**:
18
+ * Updated `Provider` enum and options in `lib/types/options.ts`.
19
+ * Updated `ProviderFactory` and `index` exports.
20
+ * Updated `StorageService` to use capability checks.
21
+ * Added optional peer dependencies in `package.json`.
22
+ 6. **Tests**: Added unit tests for Azure and GCS providers (`test/azure-blob-storage.spec.ts`, `test/gcs-storage.spec.ts`).
23
+ 7. **Documentation**: Updated `README.md` with supported providers, S3-compatible guide, and capability matrix.
24
+
25
+ ## Verification
26
+ - `npm run build` passes successfully.
27
+ - `npm test` passes (including new unit tests).
28
+
29
+ ## Breaking Changes
30
+ - `BaseStorage` no longer has `preprocessImage`, `getClientUploadCredential`, or `resolveClientUploadCallback`. Consumers must use capability checks (e.g., `BaseStorage.supportsSignedUrl(provider)`).
31
+ - All providers now return standard Promises (no callbacks).
32
+
33
+ The package is ready for use.