@xnestjs/storage 1.5.2 → 1.5.3

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.
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getConnectionOptions = getConnectionOptions;
4
+ const tslib_1 = require("tslib");
5
+ const node_process_1 = tslib_1.__importDefault(require("node:process"));
6
+ const objects_1 = require("@jsopen/objects");
7
+ const putil_varhelpers_1 = require("putil-varhelpers");
8
+ function getConnectionOptions(moduleOptions, prefix = 'STORAGE_') {
9
+ const options = (0, objects_1.clone)(moduleOptions);
10
+ const env = node_process_1.default.env;
11
+ options.provider = options.provider || env[prefix + 'PROVIDER'];
12
+ if (!options.provider)
13
+ throw new Error(`You must provide a Storage provider or "${prefix + 'PROVIDER'}" env variable`);
14
+ if (options.provider === 's3') {
15
+ options.s3 = options.s3 || {};
16
+ options.s3.endPoint = options.s3.endPoint ?? env[prefix + 'S3_ENDPOINT'];
17
+ options.s3.accessKey = options.s3.secretKey ?? env[prefix + 'S3_ACCESS_KEY'];
18
+ options.s3.secretKey = options.s3.secretKey ?? env[prefix + 'S3_SECRET_KEY'];
19
+ options.s3.useSSL = options.s3.useSSL ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'S3_SSL']);
20
+ options.s3.port = options.s3.port ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'S3_PORT']);
21
+ options.s3.sessionToken = options.s3.sessionToken ?? env[prefix + 'S3_SESSION_TOKEN'];
22
+ options.s3.partSize = options.s3.partSize ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'S3_PART_SIZE']);
23
+ options.s3.pathStyle = options.s3.pathStyle ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'S3_PATH_STYLE']);
24
+ options.s3.s3AccelerateEndpoint = options.s3.s3AccelerateEndpoint ?? env[prefix + 'S3_ACC_ENDPOINT'];
25
+ }
26
+ else
27
+ throw new Error(`Unknown Storage provider (${options.provider})`);
28
+ return options;
29
+ }
package/cjs/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./constants.js"), exports);
5
+ tslib_1.__exportStar(require("./get-connection-options.js"), exports);
5
6
  tslib_1.__exportStar(require("./services/storage-bucket.js"), exports);
6
7
  tslib_1.__exportStar(require("./services/storage-connection.js"), exports);
7
8
  tslib_1.__exportStar(require("./storage.module.js"), exports);
@@ -3,12 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StorageCoreModule = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const node_assert_1 = tslib_1.__importDefault(require("node:assert"));
6
- const node_process_1 = tslib_1.__importDefault(require("node:process"));
7
- const objects_1 = require("@jsopen/objects");
8
6
  const common_1 = require("@nestjs/common");
9
7
  const crypto_1 = tslib_1.__importDefault(require("crypto"));
10
- const putil_varhelpers_1 = require("putil-varhelpers");
11
8
  const constants_js_1 = require("./constants.js");
9
+ const get_connection_options_js_1 = require("./get-connection-options.js");
12
10
  const s3_storage_connection_js_1 = require("./providers/s3-storage-connection.js");
13
11
  const storage_connection_js_1 = require("./services/storage-connection.js");
14
12
  const CLIENT_TOKEN = Symbol('CLIENT_TOKEN');
@@ -17,7 +15,7 @@ class StorageCoreModule {
17
15
  * Configures and returns a dynamic module
18
16
  */
19
17
  static forRoot(moduleOptions) {
20
- const connectionOptions = this._readConnectionOptions(moduleOptions.useValue || {}, moduleOptions.envPrefix);
18
+ const connectionOptions = (0, get_connection_options_js_1.getConnectionOptions)(moduleOptions.useValue || {}, moduleOptions.envPrefix);
21
19
  return this._createDynamicModule(moduleOptions, {
22
20
  global: moduleOptions.global,
23
21
  providers: [
@@ -41,34 +39,12 @@ class StorageCoreModule {
41
39
  inject: asyncOptions.inject,
42
40
  useFactory: async (...args) => {
43
41
  const opts = await asyncOptions.useFactory(...args);
44
- return this._readConnectionOptions(opts, asyncOptions.envPrefix);
42
+ return (0, get_connection_options_js_1.getConnectionOptions)(opts, asyncOptions.envPrefix);
45
43
  },
46
44
  },
47
45
  ],
48
46
  });
49
47
  }
50
- static _readConnectionOptions(moduleOptions, prefix = 'STORAGE_') {
51
- const options = (0, objects_1.clone)(moduleOptions);
52
- const env = node_process_1.default.env;
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`);
56
- if (options.provider === 's3') {
57
- options.s3 = options.s3 || {};
58
- options.s3.endPoint = options.s3.endPoint ?? env[prefix + 'S3_ENDPOINT'];
59
- options.s3.accessKey = options.s3.secretKey ?? env[prefix + 'S3_ACCESS_KEY'];
60
- options.s3.secretKey = options.s3.secretKey ?? env[prefix + 'S3_SECRET_KEY'];
61
- options.s3.useSSL = options.s3.useSSL ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'S3_SSL']);
62
- options.s3.port = options.s3.port ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'S3_PORT']);
63
- options.s3.sessionToken = options.s3.sessionToken ?? env[prefix + 'S3_SESSION_TOKEN'];
64
- options.s3.partSize = options.s3.partSize ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'S3_PART_SIZE']);
65
- options.s3.pathStyle = options.s3.pathStyle ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'S3_PATH_STYLE']);
66
- options.s3.s3AccelerateEndpoint = options.s3.s3AccelerateEndpoint ?? env[prefix + 'S3_ACC_ENDPOINT'];
67
- }
68
- else
69
- throw new Error(`Unknown Storage provider (${options.provider})`);
70
- return options;
71
- }
72
48
  static _createDynamicModule(opts, metadata) {
73
49
  const token = opts.token ?? storage_connection_js_1.StorageConnection;
74
50
  const providers = [
@@ -0,0 +1,25 @@
1
+ import process from 'node:process';
2
+ import { clone } from '@jsopen/objects';
3
+ import { toBoolean, toInt } from 'putil-varhelpers';
4
+ export function getConnectionOptions(moduleOptions, prefix = 'STORAGE_') {
5
+ const options = clone(moduleOptions);
6
+ const env = process.env;
7
+ options.provider = options.provider || env[prefix + 'PROVIDER'];
8
+ if (!options.provider)
9
+ throw new Error(`You must provide a Storage provider or "${prefix + 'PROVIDER'}" env variable`);
10
+ if (options.provider === 's3') {
11
+ options.s3 = options.s3 || {};
12
+ options.s3.endPoint = options.s3.endPoint ?? env[prefix + 'S3_ENDPOINT'];
13
+ options.s3.accessKey = options.s3.secretKey ?? env[prefix + 'S3_ACCESS_KEY'];
14
+ options.s3.secretKey = options.s3.secretKey ?? env[prefix + 'S3_SECRET_KEY'];
15
+ options.s3.useSSL = options.s3.useSSL ?? toBoolean(env[prefix + 'S3_SSL']);
16
+ options.s3.port = options.s3.port ?? toInt(env[prefix + 'S3_PORT']);
17
+ options.s3.sessionToken = options.s3.sessionToken ?? env[prefix + 'S3_SESSION_TOKEN'];
18
+ options.s3.partSize = options.s3.partSize ?? toInt(env[prefix + 'S3_PART_SIZE']);
19
+ options.s3.pathStyle = options.s3.pathStyle ?? toBoolean(env[prefix + 'S3_PATH_STYLE']);
20
+ options.s3.s3AccelerateEndpoint = options.s3.s3AccelerateEndpoint ?? env[prefix + 'S3_ACC_ENDPOINT'];
21
+ }
22
+ else
23
+ throw new Error(`Unknown Storage provider (${options.provider})`);
24
+ return options;
25
+ }
package/esm/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './constants.js';
2
+ export * from './get-connection-options.js';
2
3
  export * from './services/storage-bucket.js';
3
4
  export * from './services/storage-connection.js';
4
5
  export * from './storage.module.js';
@@ -1,10 +1,8 @@
1
1
  import assert from 'node:assert';
2
- import process from 'node:process';
3
- import { clone } from '@jsopen/objects';
4
2
  import { Logger } from '@nestjs/common';
5
3
  import crypto from 'crypto';
6
- import { toBoolean, toInt } from 'putil-varhelpers';
7
4
  import { STORAGE_MODULE_ID, STORAGE_OPTIONS } from './constants.js';
5
+ import { getConnectionOptions } from './get-connection-options.js';
8
6
  import { S3StorageConnection } from './providers/s3-storage-connection.js';
9
7
  import { StorageConnection } from './services/storage-connection.js';
10
8
  const CLIENT_TOKEN = Symbol('CLIENT_TOKEN');
@@ -13,7 +11,7 @@ export class StorageCoreModule {
13
11
  * Configures and returns a dynamic module
14
12
  */
15
13
  static forRoot(moduleOptions) {
16
- const connectionOptions = this._readConnectionOptions(moduleOptions.useValue || {}, moduleOptions.envPrefix);
14
+ const connectionOptions = getConnectionOptions(moduleOptions.useValue || {}, moduleOptions.envPrefix);
17
15
  return this._createDynamicModule(moduleOptions, {
18
16
  global: moduleOptions.global,
19
17
  providers: [
@@ -37,34 +35,12 @@ export class StorageCoreModule {
37
35
  inject: asyncOptions.inject,
38
36
  useFactory: async (...args) => {
39
37
  const opts = await asyncOptions.useFactory(...args);
40
- return this._readConnectionOptions(opts, asyncOptions.envPrefix);
38
+ return getConnectionOptions(opts, asyncOptions.envPrefix);
41
39
  },
42
40
  },
43
41
  ],
44
42
  });
45
43
  }
46
- static _readConnectionOptions(moduleOptions, prefix = 'STORAGE_') {
47
- const options = clone(moduleOptions);
48
- const env = process.env;
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`);
52
- if (options.provider === 's3') {
53
- options.s3 = options.s3 || {};
54
- options.s3.endPoint = options.s3.endPoint ?? env[prefix + 'S3_ENDPOINT'];
55
- options.s3.accessKey = options.s3.secretKey ?? env[prefix + 'S3_ACCESS_KEY'];
56
- options.s3.secretKey = options.s3.secretKey ?? env[prefix + 'S3_SECRET_KEY'];
57
- options.s3.useSSL = options.s3.useSSL ?? toBoolean(env[prefix + 'S3_SSL']);
58
- options.s3.port = options.s3.port ?? toInt(env[prefix + 'S3_PORT']);
59
- options.s3.sessionToken = options.s3.sessionToken ?? env[prefix + 'S3_SESSION_TOKEN'];
60
- options.s3.partSize = options.s3.partSize ?? toInt(env[prefix + 'S3_PART_SIZE']);
61
- options.s3.pathStyle = options.s3.pathStyle ?? toBoolean(env[prefix + 'S3_PATH_STYLE']);
62
- options.s3.s3AccelerateEndpoint = options.s3.s3AccelerateEndpoint ?? env[prefix + 'S3_ACC_ENDPOINT'];
63
- }
64
- else
65
- throw new Error(`Unknown Storage provider (${options.provider})`);
66
- return options;
67
- }
68
44
  static _createDynamicModule(opts, metadata) {
69
45
  const token = opts.token ?? StorageConnection;
70
46
  const providers = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xnestjs/storage",
3
- "version": "1.5.2",
3
+ "version": "1.5.3",
4
4
  "description": "NestJS extension library for Storage solutions (S3,GS)",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -0,0 +1,2 @@
1
+ import type { StorageOptions } from './types.js';
2
+ export declare function getConnectionOptions(moduleOptions: Partial<StorageOptions>, prefix?: string): StorageOptions;
package/types/index.d.cts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './constants.js';
2
+ export * from './get-connection-options.js';
2
3
  export * from './services/storage-bucket.js';
3
4
  export * from './services/storage-connection.js';
4
5
  export * from './storage.module.js';
package/types/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './constants.js';
2
+ export * from './get-connection-options.js';
2
3
  export * from './services/storage-bucket.js';
3
4
  export * from './services/storage-connection.js';
4
5
  export * from './storage.module.js';
@@ -9,6 +9,5 @@ export declare class StorageCoreModule {
9
9
  * Configures and returns an async dynamic module
10
10
  */
11
11
  static forRootAsync(asyncOptions: StorageModuleAsyncOptions): DynamicModule;
12
- private static _readConnectionOptions;
13
12
  private static _createDynamicModule;
14
13
  }