mbkbucket 2.1.0 → 3.0.0

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,7 +1,7 @@
1
1
  import { createRequire } from "module";
2
2
  import dotenv from "dotenv";
3
3
  import { parseAndValidateMbkbucketVar, parseAndValidateBucketConnection } from "./validation.js";
4
- import { createLogger } from "../debug.js";
4
+ import { createLogger } from "../utils/logger.js";
5
5
 
6
6
  dotenv.config();
7
7
  const debugConfig = createLogger('config');
@@ -99,28 +99,35 @@ function validateBucketConnection() {
99
99
  }
100
100
 
101
101
  try {
102
- const bucketConfig = parseAndValidateBucketConnection(process.env.BucketConnection);
103
- const bucketNames = Object.keys(bucketConfig || {});
102
+ parseAndValidateBucketConnection(process.env.BucketConnection);
103
+ debugConfig('BucketConnection configuration validated successfully');
104
+ } catch (error) {
105
+ throw new Error(`[mbkbucket] BucketConnection validation failed:\n - ${error.message}`);
106
+ }
107
+ }
104
108
 
105
- debugConfig('BucketConnection validated (%s bucket(s): %s)', bucketNames.length, bucketNames.join(', '));
106
- return bucketConfig;
109
+ // Validate all configuration at startup
110
+ function validateAllConfiguration() {
111
+ try {
112
+ validateConfiguration();
113
+ validateBucketConnection();
114
+ debugConfig('All configurations validated successfully');
115
+ return true;
107
116
  } catch (error) {
108
- console.error(`[mbkbucket] ❌ BucketConnection validation failed: ${error.message}`);
109
- console.error(`[mbkbucket] Current value (excerpt): ${process.env.BucketConnection.slice(0, 200)}...`);
110
- console.error(`[mbkbucket] Correct format example:`);
111
- console.error(`[mbkbucket] BucketConnection={"r2":{"BUCKET_NAME":"my-bucket","ACCESS_KEY_ID":"key","SECRET_ACCESS_KEY":"secret","ENDPOINT":"https://endpoint.com"}}`);
112
- console.error(`[mbkbucket] ⚠️ Note: Inner objects should NOT be quoted as strings!`);
113
- throw new Error(`[mbkbucket] Invalid BucketConnection configuration`);
117
+ console.error(error.message);
118
+ return false;
114
119
  }
115
120
  }
116
121
 
117
- // Parse and validate mbkbucketVar once
118
122
  const mbkbucketVar = validateConfiguration();
119
- debugConfig('mbkbucketVar configuration: %O', mbkbucketVar);
120
-
121
- // Validate BucketConnection
122
- validateBucketConnection();
123
123
 
124
- export { packageJson, appVersion, getLatestVersion, checkVersion };
125
- export { mbkbucketVar };
126
- export { parseAndValidateMbkbucketVar, parseAndValidateBucketConnection };
124
+ export {
125
+ packageJson,
126
+ appVersion,
127
+ mbkbucketVar,
128
+ checkVersion,
129
+ getLatestVersion,
130
+ validateConfiguration,
131
+ validateBucketConnection,
132
+ validateAllConfiguration
133
+ };