@takentrade/takentrade-libs 1.0.7 → 1.0.9
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/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/storage/{cloudinary.storage.d.ts → cloudinary.config.d.ts} +3 -3
- package/dist/storage/cloudinary.config.js +22 -0
- package/dist/storage/index.d.ts +1 -1
- package/dist/storage/index.js +1 -1
- package/dist/storage/storage.interface.d.ts +11 -8
- package/dist/storage/storage.interface.js +0 -5
- package/dist/storage/storage.module.d.ts +1 -1
- package/dist/storage/storage.module.js +13 -3
- package/dist/storage/storage.service.d.ts +7 -6
- package/dist/storage/storage.service.js +6 -10
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -4
- package/dist/storage/cloudinary.storage.js +0 -20
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -22,5 +22,5 @@ __exportStar(require("./utils"), exports);
|
|
|
22
22
|
__exportStar(require("./rpc"), exports);
|
|
23
23
|
__exportStar(require("./prisma"), exports);
|
|
24
24
|
__exportStar(require("./auth"), exports);
|
|
25
|
-
__exportStar(require("./storage"), exports);
|
|
26
25
|
__exportStar(require("./notification"), exports);
|
|
26
|
+
__exportStar(require("./storage"), exports);
|
|
@@ -3,8 +3,8 @@ export declare class CloudinaryConfig {
|
|
|
3
3
|
private readonly configService;
|
|
4
4
|
constructor(configService: ConfigService);
|
|
5
5
|
createSharedConfiguration(): {
|
|
6
|
-
cloud_name: string
|
|
7
|
-
api_key: string
|
|
8
|
-
api_secret: string
|
|
6
|
+
cloud_name: string;
|
|
7
|
+
api_key: string;
|
|
8
|
+
api_secret: string;
|
|
9
9
|
};
|
|
10
10
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CloudinaryConfig = void 0;
|
|
4
|
+
const cloudinary_1 = require("cloudinary");
|
|
5
|
+
class CloudinaryConfig {
|
|
6
|
+
configService;
|
|
7
|
+
constructor(configService) {
|
|
8
|
+
this.configService = configService;
|
|
9
|
+
}
|
|
10
|
+
createSharedConfiguration() {
|
|
11
|
+
const cloud_name = this.configService.get('CLOUDINARY_CLOUD_NAME');
|
|
12
|
+
const api_key = this.configService.get('CLOUDINARY_API_KEY');
|
|
13
|
+
const api_secret = this.configService.get('CLOUDINARY_API_SECRET');
|
|
14
|
+
if (!cloud_name || !api_key || !api_secret) {
|
|
15
|
+
throw new Error('Cloudinary configuration is missing. Ensure CLOUDINARY_CLOUD_NAME, CLOUDINARY_API_KEY, and CLOUDINARY_API_SECRET are set in the environment variables.');
|
|
16
|
+
}
|
|
17
|
+
const config = { cloud_name, api_key, api_secret };
|
|
18
|
+
cloudinary_1.v2.config(config);
|
|
19
|
+
return config;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.CloudinaryConfig = CloudinaryConfig;
|
package/dist/storage/index.d.ts
CHANGED
package/dist/storage/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./cloudinary.
|
|
17
|
+
__exportStar(require("./cloudinary.config"), exports);
|
|
18
18
|
__exportStar(require("./storage.interface"), exports);
|
|
19
19
|
__exportStar(require("./storage.module"), exports);
|
|
20
20
|
__exportStar(require("./storage.service"), exports);
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*/
|
|
6
|
-
export interface IStorageService {
|
|
7
|
-
uploadFile(file: Express.Multer.File): Promise<UploadResponse>;
|
|
8
|
-
deleteFile(publicId: string): Promise<DeleteResponse>;
|
|
1
|
+
export interface FileUpload {
|
|
2
|
+
buffer: Buffer;
|
|
3
|
+
originalname?: string;
|
|
4
|
+
mimetype?: string;
|
|
9
5
|
}
|
|
10
6
|
export interface UploadResponse {
|
|
11
7
|
public_id: string;
|
|
@@ -18,3 +14,10 @@ export interface UploadResponse {
|
|
|
18
14
|
export interface DeleteResponse {
|
|
19
15
|
result: string;
|
|
20
16
|
}
|
|
17
|
+
export interface IStorageService {
|
|
18
|
+
uploadFile(file: FileUpload, options?: {
|
|
19
|
+
folder?: string;
|
|
20
|
+
tags?: string[];
|
|
21
|
+
}): Promise<UploadResponse>;
|
|
22
|
+
deleteFile(publicId: string): Promise<DeleteResponse>;
|
|
23
|
+
}
|
|
@@ -11,13 +11,23 @@ exports.StorageModule = void 0;
|
|
|
11
11
|
const common_1 = require("@nestjs/common");
|
|
12
12
|
const config_1 = require("@nestjs/config");
|
|
13
13
|
const storage_service_1 = require("./storage.service");
|
|
14
|
-
const
|
|
14
|
+
const cloudinary_config_1 = require("./cloudinary.config");
|
|
15
15
|
let StorageModule = StorageModule_1 = class StorageModule {
|
|
16
|
-
static
|
|
16
|
+
static forRoot() {
|
|
17
17
|
return {
|
|
18
18
|
module: StorageModule_1,
|
|
19
19
|
imports: [config_1.ConfigModule],
|
|
20
|
-
providers: [
|
|
20
|
+
providers: [
|
|
21
|
+
cloudinary_config_1.CloudinaryConfig,
|
|
22
|
+
{
|
|
23
|
+
provide: 'CLOUDINARY_CONFIG',
|
|
24
|
+
useFactory: (cloudinaryConfig) => {
|
|
25
|
+
return cloudinaryConfig.createSharedConfiguration();
|
|
26
|
+
},
|
|
27
|
+
inject: [cloudinary_config_1.CloudinaryConfig],
|
|
28
|
+
},
|
|
29
|
+
storage_service_1.StorageService,
|
|
30
|
+
],
|
|
21
31
|
exports: [storage_service_1.StorageService],
|
|
22
32
|
};
|
|
23
33
|
}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { IStorageService, UploadResponse, DeleteResponse } from './storage.interface';
|
|
2
|
-
import { CloudinaryConfig } from './cloudinary.storage';
|
|
1
|
+
import { IStorageService, UploadResponse, DeleteResponse, FileUpload } from './storage.interface';
|
|
3
2
|
export declare class StorageService implements IStorageService {
|
|
4
|
-
private cloudinaryConfig;
|
|
5
|
-
constructor(cloudinaryConfig: CloudinaryConfig);
|
|
6
3
|
/**
|
|
7
4
|
* Uploads a file to Cloudinary using a stream.
|
|
8
|
-
* @param file - The file to upload, provided as
|
|
5
|
+
* @param file - The file to upload, provided as a FileUpload object.
|
|
6
|
+
* @param options - Optional Cloudinary upload options (e.g., folder, tags).
|
|
9
7
|
* @returns A promise resolving to the upload response containing file details.
|
|
10
8
|
* @throws Error if the upload fails or no result is returned from Cloudinary.
|
|
11
9
|
*/
|
|
12
|
-
uploadFile(file:
|
|
10
|
+
uploadFile(file: FileUpload, options?: {
|
|
11
|
+
folder?: string;
|
|
12
|
+
tags?: string[];
|
|
13
|
+
}): Promise<UploadResponse>;
|
|
13
14
|
/**
|
|
14
15
|
* Deletes a file from Cloudinary using its public ID.
|
|
15
16
|
* @param publicId - The public ID of the file to delete.
|
|
@@ -10,22 +10,18 @@ exports.StorageService = void 0;
|
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
11
|
const cloudinary_1 = require("cloudinary");
|
|
12
12
|
let StorageService = class StorageService {
|
|
13
|
-
cloudinaryConfig;
|
|
14
|
-
constructor(cloudinaryConfig) {
|
|
15
|
-
this.cloudinaryConfig = cloudinaryConfig;
|
|
16
|
-
this.cloudinaryConfig.createSharedConfiguration();
|
|
17
|
-
}
|
|
18
13
|
/**
|
|
19
14
|
* Uploads a file to Cloudinary using a stream.
|
|
20
|
-
* @param file - The file to upload, provided as
|
|
15
|
+
* @param file - The file to upload, provided as a FileUpload object.
|
|
16
|
+
* @param options - Optional Cloudinary upload options (e.g., folder, tags).
|
|
21
17
|
* @returns A promise resolving to the upload response containing file details.
|
|
22
18
|
* @throws Error if the upload fails or no result is returned from Cloudinary.
|
|
23
19
|
*/
|
|
24
|
-
async uploadFile(file) {
|
|
20
|
+
async uploadFile(file, options) {
|
|
25
21
|
try {
|
|
26
22
|
const result = await new Promise((resolve, reject) => {
|
|
27
23
|
cloudinary_1.v2.uploader
|
|
28
|
-
.upload_stream({ resource_type: 'auto' }, (error, result) => {
|
|
24
|
+
.upload_stream({ resource_type: 'auto', ...options }, (error, result) => {
|
|
29
25
|
if (error)
|
|
30
26
|
return reject(error);
|
|
31
27
|
if (!result)
|
|
@@ -44,7 +40,7 @@ let StorageService = class StorageService {
|
|
|
44
40
|
};
|
|
45
41
|
}
|
|
46
42
|
catch (error) {
|
|
47
|
-
throw new Error(`Upload failed: ${error.message}`);
|
|
43
|
+
throw new Error(`Upload failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
48
44
|
}
|
|
49
45
|
}
|
|
50
46
|
/**
|
|
@@ -59,7 +55,7 @@ let StorageService = class StorageService {
|
|
|
59
55
|
return { result: result.result };
|
|
60
56
|
}
|
|
61
57
|
catch (error) {
|
|
62
|
-
throw new Error(`Deletion failed: ${error.message}`);
|
|
58
|
+
throw new Error(`Deletion failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
63
59
|
}
|
|
64
60
|
}
|
|
65
61
|
};
|