@xnestjs/storage 1.5.0 → 1.5.2
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.
|
@@ -51,18 +51,22 @@ class StorageCoreModule {
|
|
|
51
51
|
const options = (0, objects_1.clone)(moduleOptions);
|
|
52
52
|
const env = node_process_1.default.env;
|
|
53
53
|
options.provider = options.provider || env[prefix + 'PROVIDER'];
|
|
54
|
+
if (!options.provider)
|
|
55
|
+
throw new Error(`You must provide a Storage provider or "${prefix + 'PROVIDER'}" env variable`);
|
|
54
56
|
if (options.provider === 's3') {
|
|
55
57
|
options.s3 = options.s3 || {};
|
|
56
58
|
options.s3.endPoint = options.s3.endPoint ?? env[prefix + 'S3_ENDPOINT'];
|
|
59
|
+
options.s3.accessKey = options.s3.secretKey ?? env[prefix + 'S3_ACCESS_KEY'];
|
|
57
60
|
options.s3.secretKey = options.s3.secretKey ?? env[prefix + 'S3_SECRET_KEY'];
|
|
58
61
|
options.s3.useSSL = options.s3.useSSL ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'S3_SSL']);
|
|
59
62
|
options.s3.port = options.s3.port ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'S3_PORT']);
|
|
60
63
|
options.s3.sessionToken = options.s3.sessionToken ?? env[prefix + 'S3_SESSION_TOKEN'];
|
|
61
64
|
options.s3.partSize = options.s3.partSize ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'S3_PART_SIZE']);
|
|
62
65
|
options.s3.pathStyle = options.s3.pathStyle ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'S3_PATH_STYLE']);
|
|
63
|
-
options.s3.secretKey = options.s3.secretKey ?? env[prefix + 'S3_SECRET_KEY'];
|
|
64
66
|
options.s3.s3AccelerateEndpoint = options.s3.s3AccelerateEndpoint ?? env[prefix + 'S3_ACC_ENDPOINT'];
|
|
65
67
|
}
|
|
68
|
+
else
|
|
69
|
+
throw new Error(`Unknown Storage provider (${options.provider})`);
|
|
66
70
|
return options;
|
|
67
71
|
}
|
|
68
72
|
static _createDynamicModule(opts, metadata) {
|
|
@@ -73,10 +77,9 @@ class StorageCoreModule {
|
|
|
73
77
|
inject: [constants_js_1.STORAGE_OPTIONS],
|
|
74
78
|
useFactory: async (storageOptions) => {
|
|
75
79
|
if (storageOptions.provider === 's3') {
|
|
76
|
-
if (!storageOptions.s3)
|
|
77
|
-
throw new Error('You must provide S3 config');
|
|
78
80
|
return new s3_storage_connection_js_1.S3StorageConnection(storageOptions.s3);
|
|
79
81
|
}
|
|
82
|
+
/** istanbul ignore next */
|
|
80
83
|
throw new Error(`Unknown Storage provider (${storageOptions.provider})`);
|
|
81
84
|
},
|
|
82
85
|
},
|
package/cjs/storage.module.js
CHANGED
|
@@ -9,15 +9,13 @@ let StorageModule = StorageModule_1 = class StorageModule {
|
|
|
9
9
|
static forRoot(options) {
|
|
10
10
|
return {
|
|
11
11
|
module: StorageModule_1,
|
|
12
|
-
imports: [storage_core_module_js_1.StorageCoreModule.forRoot(options)],
|
|
13
|
-
global: options.global,
|
|
12
|
+
imports: [storage_core_module_js_1.StorageCoreModule.forRoot(options || {})],
|
|
14
13
|
};
|
|
15
14
|
}
|
|
16
15
|
static forRootAsync(options) {
|
|
17
16
|
return {
|
|
18
17
|
module: StorageModule_1,
|
|
19
18
|
imports: [storage_core_module_js_1.StorageCoreModule.forRootAsync(options)],
|
|
20
|
-
global: options.global,
|
|
21
19
|
};
|
|
22
20
|
}
|
|
23
21
|
};
|
|
@@ -47,18 +47,22 @@ export class StorageCoreModule {
|
|
|
47
47
|
const options = clone(moduleOptions);
|
|
48
48
|
const env = process.env;
|
|
49
49
|
options.provider = options.provider || env[prefix + 'PROVIDER'];
|
|
50
|
+
if (!options.provider)
|
|
51
|
+
throw new Error(`You must provide a Storage provider or "${prefix + 'PROVIDER'}" env variable`);
|
|
50
52
|
if (options.provider === 's3') {
|
|
51
53
|
options.s3 = options.s3 || {};
|
|
52
54
|
options.s3.endPoint = options.s3.endPoint ?? env[prefix + 'S3_ENDPOINT'];
|
|
55
|
+
options.s3.accessKey = options.s3.secretKey ?? env[prefix + 'S3_ACCESS_KEY'];
|
|
53
56
|
options.s3.secretKey = options.s3.secretKey ?? env[prefix + 'S3_SECRET_KEY'];
|
|
54
57
|
options.s3.useSSL = options.s3.useSSL ?? toBoolean(env[prefix + 'S3_SSL']);
|
|
55
58
|
options.s3.port = options.s3.port ?? toInt(env[prefix + 'S3_PORT']);
|
|
56
59
|
options.s3.sessionToken = options.s3.sessionToken ?? env[prefix + 'S3_SESSION_TOKEN'];
|
|
57
60
|
options.s3.partSize = options.s3.partSize ?? toInt(env[prefix + 'S3_PART_SIZE']);
|
|
58
61
|
options.s3.pathStyle = options.s3.pathStyle ?? toBoolean(env[prefix + 'S3_PATH_STYLE']);
|
|
59
|
-
options.s3.secretKey = options.s3.secretKey ?? env[prefix + 'S3_SECRET_KEY'];
|
|
60
62
|
options.s3.s3AccelerateEndpoint = options.s3.s3AccelerateEndpoint ?? env[prefix + 'S3_ACC_ENDPOINT'];
|
|
61
63
|
}
|
|
64
|
+
else
|
|
65
|
+
throw new Error(`Unknown Storage provider (${options.provider})`);
|
|
62
66
|
return options;
|
|
63
67
|
}
|
|
64
68
|
static _createDynamicModule(opts, metadata) {
|
|
@@ -69,10 +73,9 @@ export class StorageCoreModule {
|
|
|
69
73
|
inject: [STORAGE_OPTIONS],
|
|
70
74
|
useFactory: async (storageOptions) => {
|
|
71
75
|
if (storageOptions.provider === 's3') {
|
|
72
|
-
if (!storageOptions.s3)
|
|
73
|
-
throw new Error('You must provide S3 config');
|
|
74
76
|
return new S3StorageConnection(storageOptions.s3);
|
|
75
77
|
}
|
|
78
|
+
/** istanbul ignore next */
|
|
76
79
|
throw new Error(`Unknown Storage provider (${storageOptions.provider})`);
|
|
77
80
|
},
|
|
78
81
|
},
|
package/esm/storage.module.js
CHANGED
|
@@ -6,15 +6,13 @@ let StorageModule = StorageModule_1 = class StorageModule {
|
|
|
6
6
|
static forRoot(options) {
|
|
7
7
|
return {
|
|
8
8
|
module: StorageModule_1,
|
|
9
|
-
imports: [StorageCoreModule.forRoot(options)],
|
|
10
|
-
global: options.global,
|
|
9
|
+
imports: [StorageCoreModule.forRoot(options || {})],
|
|
11
10
|
};
|
|
12
11
|
}
|
|
13
12
|
static forRootAsync(options) {
|
|
14
13
|
return {
|
|
15
14
|
module: StorageModule_1,
|
|
16
15
|
imports: [StorageCoreModule.forRootAsync(options)],
|
|
17
|
-
global: options.global,
|
|
18
16
|
};
|
|
19
17
|
}
|
|
20
18
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DynamicModule } from '@nestjs/common';
|
|
2
2
|
import type { StorageModuleAsyncOptions, StorageModuleOptions } from './types.js';
|
|
3
3
|
export declare class StorageModule {
|
|
4
|
-
static forRoot(options
|
|
4
|
+
static forRoot(options?: StorageModuleOptions): DynamicModule;
|
|
5
5
|
static forRootAsync(options: StorageModuleAsyncOptions): DynamicModule;
|
|
6
6
|
}
|
package/types/types.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export interface S3StorageOptions {
|
|
|
14
14
|
}
|
|
15
15
|
export type StorageOptions = S3StorageOptions;
|
|
16
16
|
export interface StorageModuleOptions extends BaseModuleOptions {
|
|
17
|
-
useValue
|
|
17
|
+
useValue?: StorageOptions;
|
|
18
18
|
}
|
|
19
19
|
export interface StorageModuleAsyncOptions extends BaseModuleOptions, Pick<ModuleMetadata, 'imports'> {
|
|
20
20
|
useFactory?: (...args: any[]) => Promise<StorageOptions> | StorageOptions;
|