mbkbucket 3.3.2 → 3.5.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.
package/LICENSE CHANGED
@@ -1,165 +1,21 @@
1
- GNU LESSER GENERAL PUBLIC LICENSE
2
- Version 3, 29 June 2007
3
-
4
- Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
- Everyone is permitted to copy and distribute verbatim copies
6
- of this license document, but changing it is not allowed.
7
-
8
-
9
- This version of the GNU Lesser General Public License incorporates
10
- the terms and conditions of version 3 of the GNU General Public
11
- License, supplemented by the additional permissions listed below.
12
-
13
- 0. Additional Definitions.
14
-
15
- As used herein, "this License" refers to version 3 of the GNU Lesser
16
- General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
- General Public License.
18
-
19
- "The Library" refers to a covered work governed by this License,
20
- other than an Application or a Combined Work as defined below.
21
-
22
- An "Application" is any work that makes use of an interface provided
23
- by the Library, but which is not otherwise based on the Library.
24
- Defining a subclass of a class defined by the Library is deemed a mode
25
- of using an interface provided by the Library.
26
-
27
- A "Combined Work" is a work produced by combining or linking an
28
- Application with the Library. The particular version of the Library
29
- with which the Combined Work was made is also called the "Linked
30
- Version".
31
-
32
- The "Minimal Corresponding Source" for a Combined Work means the
33
- Corresponding Source for the Combined Work, excluding any source code
34
- for portions of the Combined Work that, considered in isolation, are
35
- based on the Application, and not on the Linked Version.
36
-
37
- The "Corresponding Application Code" for a Combined Work means the
38
- object code and/or source code for the Application, including any data
39
- and utility programs needed for reproducing the Combined Work from the
40
- Application, but excluding the System Libraries of the Combined Work.
41
-
42
- 1. Exception to Section 3 of the GNU GPL.
43
-
44
- You may convey a covered work under sections 3 and 4 of this License
45
- without being bound by section 3 of the GNU GPL.
46
-
47
- 2. Conveying Modified Versions.
48
-
49
- If you modify a copy of the Library, and, in your modifications, a
50
- facility refers to a function or data to be supplied by an Application
51
- that uses the facility (other than as an argument passed when the
52
- facility is invoked), then you may convey a copy of the modified
53
- version:
54
-
55
- a) under this License, provided that you make a good faith effort to
56
- ensure that, in the event an Application does not supply the
57
- function or data, the facility still operates, and performs
58
- whatever part of its purpose remains meaningful, or
59
-
60
- b) under the GNU GPL, with none of the additional permissions of
61
- this License applicable to that copy.
62
-
63
- 3. Object Code Incorporating Material from Library Header Files.
64
-
65
- The object code form of an Application may incorporate material from
66
- a header file that is part of the Library. You may convey such object
67
- code under terms of your choice, provided that, if the incorporated
68
- material is not limited to numerical parameters, data structure
69
- layouts and accessors, or small macros, inline functions and templates
70
- (ten or fewer lines in length), you do both of the following:
71
-
72
- a) Give prominent notice with each copy of the object code that the
73
- Library is used in it and that the Library and its use are
74
- covered by this License.
75
-
76
- b) Accompany the object code with a copy of the GNU GPL and this license
77
- document.
78
-
79
- 4. Combined Works.
80
-
81
- You may convey a Combined Work under terms of your choice that,
82
- taken together, effectively do not restrict modification of the
83
- portions of the Library contained in the Combined Work and reverse
84
- engineering for debugging such modifications, if you also do each of
85
- the following:
86
-
87
- a) Give prominent notice with each copy of the Combined Work that
88
- the Library is used in it and that the Library and its use are
89
- covered by this License.
90
-
91
- b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
- document.
93
-
94
- c) For a Combined Work that displays copyright notices during
95
- execution, include the copyright notice for the Library among
96
- these notices, as well as a reference directing the user to the
97
- copies of the GNU GPL and this license document.
98
-
99
- d) Do one of the following:
100
-
101
- 0) Convey the Minimal Corresponding Source under the terms of this
102
- License, and the Corresponding Application Code in a form
103
- suitable for, and under terms that permit, the user to
104
- recombine or relink the Application with a modified version of
105
- the Linked Version to produce a modified Combined Work, in the
106
- manner specified by section 6 of the GNU GPL for conveying
107
- Corresponding Source.
108
-
109
- 1) Use a suitable shared library mechanism for linking with the
110
- Library. A suitable mechanism is one that (a) uses at run time
111
- a copy of the Library already present on the user's computer
112
- system, and (b) will operate properly with a modified version
113
- of the Library that is interface-compatible with the Linked
114
- Version.
115
-
116
- e) Provide Installation Information, but only if you would otherwise
117
- be required to provide such information under section 6 of the
118
- GNU GPL, and only to the extent that such information is
119
- necessary to install and execute a modified version of the
120
- Combined Work produced by recombining or relinking the
121
- Application with a modified version of the Linked Version. (If
122
- you use option 4d0, the Installation Information must accompany
123
- the Minimal Corresponding Source and Corresponding Application
124
- Code. If you use option 4d1, you must provide the Installation
125
- Information in the manner specified by section 6 of the GNU GPL
126
- for conveying Corresponding Source.)
127
-
128
- 5. Combined Libraries.
129
-
130
- You may place library facilities that are a work based on the
131
- Library side by side in a single library together with other library
132
- facilities that are not Applications and are not covered by this
133
- License, and convey such a combined library under terms of your
134
- choice, if you do both of the following:
135
-
136
- a) Accompany the combined library with a copy of the same work based
137
- on the Library, uncombined with any other library facilities,
138
- conveyed under the terms of this License.
139
-
140
- b) Give prominent notice with the combined library that part of it
141
- is a work based on the Library, and explaining where to find the
142
- accompanying uncombined form of the same work.
143
-
144
- 6. Revised Versions of the GNU Lesser General Public License.
145
-
146
- The Free Software Foundation may publish revised and/or new versions
147
- of the GNU Lesser General Public License from time to time. Such new
148
- versions will be similar in spirit to the present version, but may
149
- differ in detail to address new problems or concerns.
150
-
151
- Each version is given a distinguishing version number. If the
152
- Library as you received it specifies that a certain numbered version
153
- of the GNU Lesser General Public License "or any later version"
154
- applies to it, you have the option of following the terms and
155
- conditions either of that published version or of any later version
156
- published by the Free Software Foundation. If the Library as you
157
- received it does not specify a version number of the GNU Lesser
158
- General Public License, you may choose any version of the GNU Lesser
159
- General Public License ever published by the Free Software Foundation.
160
-
161
- If the Library as you received it specifies that a proxy can decide
162
- whether future versions of the GNU Lesser General Public License shall
163
- apply, that proxy's public statement of acceptance of any version is
164
- permanent authorization for you to choose that version for the
165
- Library.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Muhammad Bin Khalid
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  [![Version](https://img.shields.io/npm/v/mbkbucket.svg)](https://www.npmjs.com/package/mbkbucket)
6
6
  [![Downloads](https://img.shields.io/npm/dm/mbkbucket.svg)](https://www.npmjs.com/package/mbkbucket)
7
- [![License](https://img.shields.io/badge/License-LGPL--3.0-blue.svg)](LICENSE)
7
+ [![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
8
8
  [![Node.js](https://img.shields.io/badge/node-%3E%3D14.0.0-brightgreen.svg)](https://nodejs.org/)
9
9
  [![Publish Status](https://github.com/MIbnEKhalid/mbkbucket/actions/workflows/publish.yml/badge.svg)](https://github.com/MIbnEKhalid/mbkbucket/actions/workflows/publish.yml)
10
10
 
@@ -37,14 +37,7 @@ npm install mbkbucket
37
37
  ### As a Library
38
38
 
39
39
  ```js
40
- import {
41
- uploadFile,
42
- downloadFile,
43
- listfiles,
44
- deleteFile,
45
- deleteFolder,
46
- getFileMetadata,
47
- generateSignedUrl,
40
+ import { uploadFile, downloadFile, listfiles, deleteFile, deleteFolder, getFileMetadata, generateSignedUrl,
48
41
  bucket, // Express router
49
42
  packageJson // Package metadata
50
43
  } from 'mbkbucket';
@@ -82,7 +75,7 @@ mbkbucket.listen(3004, () => {
82
75
  ```
83
76
 
84
77
  The Express app includes:
85
- - **`/mbkbucket`** — Admin dashboard (SuperAdmin only)
78
+ - **`/mbkbucket`** — Admin dashboard (superadmin only)
86
79
  - **`/mbkbucket/api/*`** — REST API for file operations
87
80
  - **`/mbkbucket/p_view/:key(*)`** — Public file view
88
81
  - **`/mbkbucket/info`** — Health & config info
@@ -225,23 +218,23 @@ All functions are exported from the package root. Full TypeScript declarations i
225
218
 
226
219
  | Route | Auth | Description |
227
220
  |---|---|---|
228
- | `GET /mbkbucket` | SuperAdmin | Admin dashboard |
221
+ | `GET /mbkbucket` | superadmin | Admin dashboard |
229
222
  | `GET /mbkbucket/info` | Any | Health check & config info |
230
223
  | `GET /mbkbucket/p_view/:key(*)` | Public | Public file viewer |
231
- | `POST /mbkbucket/api/list` | SuperAdmin | List files (JSON) |
232
- | `POST /mbkbucket/api/upload` | SuperAdmin | Upload file(s) |
233
- | `POST /mbkbucket/api/delete` | SuperAdmin | Delete file(s) |
234
- | `POST /mbkbucket/api/delete-folder` | SuperAdmin | Delete folder |
235
- | `POST /mbkbucket/api/create-folder` | SuperAdmin | Create folder marker |
236
- | `POST /mbkbucket/api/rename` | SuperAdmin | Rename/move a file |
237
- | `GET /mbkbucket/api/download/:key(*)` | SuperAdmin | Download a file |
238
- | `GET /mbkbucket/api/metadata/:key(*)` | SuperAdmin | Get file metadata |
239
- | `POST /mbkbucket/api/multipart/init` | SuperAdmin | Init multipart upload |
240
- | `POST /mbkbucket/api/multipart/part` | SuperAdmin | Upload multipart chunk |
241
- | `POST /mbkbucket/api/multipart/complete` | SuperAdmin | Complete multipart |
242
- | `POST /mbkbucket/api/multipart/abort` | SuperAdmin | Abort multipart |
243
- | `GET /mbkbucket/api/multipart/list` | SuperAdmin | List incomplete uploads |
244
- | `POST /mbkbucket/api/multipart/cleanup` | SuperAdmin | Clean up stale uploads |
224
+ | `POST /mbkbucket/api/list` | superadmin | List files (JSON) |
225
+ | `POST /mbkbucket/api/upload` | superadmin | Upload file(s) |
226
+ | `POST /mbkbucket/api/delete` | superadmin | Delete file(s) |
227
+ | `POST /mbkbucket/api/delete-folder` | superadmin | Delete folder |
228
+ | `POST /mbkbucket/api/create-folder` | superadmin | Create folder marker |
229
+ | `POST /mbkbucket/api/rename` | superadmin | Rename/move a file |
230
+ | `GET /mbkbucket/api/download/:key(*)` | superadmin | Download a file |
231
+ | `GET /mbkbucket/api/metadata/:key(*)` | superadmin | Get file metadata |
232
+ | `POST /mbkbucket/api/multipart/init` | superadmin | Init multipart upload |
233
+ | `POST /mbkbucket/api/multipart/part` | superadmin | Upload multipart chunk |
234
+ | `POST /mbkbucket/api/multipart/complete` | superadmin | Complete multipart |
235
+ | `POST /mbkbucket/api/multipart/abort` | superadmin | Abort multipart |
236
+ | `GET /mbkbucket/api/multipart/list` | superadmin | List incomplete uploads |
237
+ | `POST /mbkbucket/api/multipart/cleanup` | superadmin | Clean up stale uploads |
245
238
 
246
239
  ### Views
247
240
 
@@ -347,4 +340,12 @@ Part of [MBK Tech](https://mbktech.org/)
347
340
 
348
341
  ## License
349
342
 
350
- Licensed under the LGPL-3.0-only License. See [LICENSE](LICENSE) for details.
343
+ Licensed under the MIT License. See [LICENSE](LICENSE) for details.
344
+
345
+
346
+ <!--
347
+ * MBKBucket
348
+ * Copyright (c) 2026 Muhammad Bin Khalid, MBKTech.org and contributors
349
+ * Licensed under the MIT License.
350
+ * Source: https://github.com/MIbnEKhalid/mbkbucket
351
+ -->
package/index.js CHANGED
@@ -1,3 +1,10 @@
1
+ /**
2
+ * MBKBucket
3
+ * Copyright (c) 2026 Muhammad Bin Khalid, MBKTech.org and contributors
4
+ * Licensed under the MIT License.
5
+ * Source: https://github.com/MIbnEKhalid/mbkbucket
6
+ */
7
+
1
8
  import dotenv from "dotenv";
2
9
  import { createApp } from "./lib/src/app.js";
3
10
  import { checkVersion } from "./lib/src/config/index.js";
package/lib/cli.js CHANGED
@@ -1,5 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ /**
4
+ * MBKBucket
5
+ * Copyright (c) 2026 Muhammad Bin Khalid, MBKTech.org and contributors
6
+ * Licensed under the MIT License.
7
+ * Source: https://github.com/MIbnEKhalid/mbkbucket
8
+ */
9
+
3
10
  /**
4
11
  * mbkbucket CLI — Manage S3/R2 buckets from the command line.
5
12
  */
@@ -133,39 +140,39 @@ function promptLine() {
133
140
 
134
141
  async function cmdLogin() {
135
142
  const storedCfg = readConfig();
136
- let serverUrl = findFlag('server') || storedCfg.serverUrl;
143
+ let server_url = findFlag('server') || storedCfg.server_url;
137
144
 
138
- if (!serverUrl || typeof serverUrl !== 'string') {
139
- console.error('❌ --server <url> is required for login.\n Example: mbkbucket login --server https://myapp.example.com\n\n💡 Tip: Set it once with:\n mbkbucket config set serverUrl https://your-server.com\n Then just run: mbkbucket login');
145
+ if (!server_url || typeof server_url !== 'string') {
146
+ console.error('❌ --server <url> is required for login.\n Example: mbkbucket login --server https://myapp.example.com\n\n💡 Tip: Set it once with:\n mbkbucket config set server_url https://your-server.com\n Then just run: mbkbucket login');
140
147
  process.exit(1);
141
148
  }
142
149
 
143
- const profileKey = findFlag('profile-key') || storedCfg.profileKey;
144
- updateConfig({ serverUrl });
150
+ const profile_key = findFlag('profile-key') || storedCfg.profile_key;
151
+ updateConfig({ server_url });
145
152
 
146
153
  try {
147
154
  const result = await deviceFlowLogin({
148
- serverUrl,
149
- profileKey: typeof profileKey === 'string' ? profileKey : undefined,
155
+ server_url,
156
+ profile_key: typeof profile_key === 'string' ? profile_key : undefined,
150
157
  });
151
158
 
152
159
  updateConfig({
153
160
  token: result.token,
154
- tokenPrefix: result.tokenPrefix,
161
+ token_prefix: result.token_prefix,
155
162
  username: result.username,
156
- serverUrl,
163
+ server_url,
157
164
  profile: result.profile || null,
158
- loggedInAt: nowIso(),
165
+ logged_in_at: nowIso(),
159
166
  });
160
167
 
161
168
  console.log('\n✅ Credentials saved. You are now logged in.\n Run "mbkbucket whoami" to verify.');
162
169
  } catch (err) {
163
170
  const msg = err.message || '';
164
171
  console.error(`❌ Login failed: ${msg}`);
165
- if (msg.includes('profileKey') || msg.includes('profileId')) {
172
+ if (msg.includes('profile_key') || msg.includes('profile_id')) {
166
173
  console.error('\n💡 An API token profile is required. Create one in mbkauthe admin panel and pass --profile-key.');
167
174
  } else if (msg.includes('fetch') || msg.includes('ECONNREFUSED') || msg.includes('ENOTFOUND')) {
168
- console.error(`\n💡 Could not reach server "${serverUrl}". Verify it is running and CLI_AUTH_ENABLED=true.`);
175
+ console.error(`\n💡 Could not reach server "${server_url}". Verify it is running and CLI_AUTH_ENABLED=true.`);
169
176
  }
170
177
  process.exit(1);
171
178
  }
@@ -182,10 +189,10 @@ function cmdWhoami() {
182
189
  if (!isLoggedIn()) return console.log('ℹ️ Not logged in. Run "mbkbucket login --server <url>" to authenticate.');
183
190
  const cfg = readConfig();
184
191
  console.log(`✅ Logged in as: ${cfg.username}`);
185
- console.log(` Server: ${cfg.serverUrl}`);
186
- console.log(` Token: ${cfg.tokenPrefix}...`);
192
+ console.log(` Server: ${cfg.server_url}`);
193
+ console.log(` Token: ${cfg.token_prefix}...`);
187
194
  if (cfg.profile) console.log(` Profile: ${cfg.profile.name} (scope: ${cfg.profile.scope || 'full'})`);
188
- console.log(` Since: ${formatDate(cfg.loggedInAt)}`);
195
+ console.log(` Since: ${formatDate(cfg.logged_in_at)}`);
189
196
  }
190
197
 
191
198
  async function cmdList() {
@@ -462,14 +469,14 @@ async function cmdSignedUrl() {
462
469
  // ---------------------------------------------------------------------------
463
470
  const DEMO_CONFIG = {
464
471
  token: 'mbk_demo_token_replace_with_real_one_from_login',
465
- tokenPrefix: 'mbk_demo',
472
+ token_prefix: 'mbk_demo',
466
473
  username: 'demo-user',
467
- serverUrl: 'https://your-app.example.com',
468
- profile: { name: 'Default CLI Profile', scope: 'read-write', allowedApps: ['mbkbucket'] },
469
- loggedInAt: nowIso(),
474
+ server_url: 'https://your-app.example.com',
475
+ profile: { name: 'Default CLI Profile', scope: 'read-write', allowed_apps: ['mbkbucket'] },
476
+ logged_in_at: nowIso(),
470
477
  };
471
478
 
472
- const VALID_CONFIG_KEYS = ['token', 'tokenPrefix', 'username', 'serverUrl', 'profile', 'profileKey', 'loggedInAt'];
479
+ const VALID_CONFIG_KEYS = ['token', 'token_prefix', 'username', 'server_url', 'profile', 'profile_key', 'logged_in_at'];
473
480
 
474
481
  async function cmdConfig() {
475
482
  const [sub, key, value] = cmdArgs;
@@ -1,3 +1,10 @@
1
+ /**
2
+ * MBKBucket
3
+ * Copyright (c) 2026 Muhammad Bin Khalid, MBKTech.org and contributors
4
+ * Licensed under the MIT License.
5
+ * Source: https://github.com/MIbnEKhalid/mbkbucket
6
+ */
7
+
1
8
  /**
2
9
  * MBKBucket File Manager - UI & Client Logic
3
10
  */
@@ -1,3 +1,10 @@
1
+ <!--
2
+ * MBKBucket
3
+ * Copyright (c) 2026 Muhammad Bin Khalid, MBKTech.org and contributors
4
+ * Licensed under the MIT License.
5
+ * Source: https://github.com/MIbnEKhalid/mbkbucket
6
+ -->
7
+
1
8
  <!DOCTYPE html>
2
9
  <html lang="en">
3
10
  <head>
@@ -1,3 +1,10 @@
1
+ /**
2
+ * MBKBucket
3
+ * Copyright (c) 2026 Muhammad Bin Khalid, MBKTech.org and contributors
4
+ * Licensed under the MIT License.
5
+ * Source: https://github.com/MIbnEKhalid/mbkbucket
6
+ */
7
+
1
8
  /**
2
9
  * mbkbucket-helper.js v1.2.0
3
10
  * ─────────────────────────────────────────────────────────────────────────────
package/lib/src/app.js CHANGED
@@ -1,3 +1,10 @@
1
+ /**
2
+ * MBKBucket
3
+ * Copyright (c) 2026 Muhammad Bin Khalid, MBKTech.org and contributors
4
+ * Licensed under the MIT License.
5
+ * Source: https://github.com/MIbnEKhalid/mbkbucket
6
+ */
7
+
1
8
  import express from "express";
2
9
  import path from "path";
3
10
  import fs from "fs";
@@ -52,8 +52,8 @@ export function updateConfig(partial) {
52
52
  }
53
53
 
54
54
  export function isLoggedIn() {
55
- const { token, serverUrl } = readConfig();
56
- return Boolean(token && serverUrl);
55
+ const { token, server_url } = readConfig();
56
+ return Boolean(token && server_url);
57
57
  }
58
58
 
59
59
  export function getStoredToken() {
@@ -61,11 +61,11 @@ export function getStoredToken() {
61
61
  }
62
62
 
63
63
  export function getStoredServerUrl() {
64
- return readConfig().serverUrl || null;
64
+ return readConfig().server_url || null;
65
65
  }
66
66
 
67
- export async function deviceFlowLogin({ serverUrl, profileKey }) {
68
- const baseUrl = String(serverUrl).replace(/\/+$/, '');
67
+ export async function deviceFlowLogin({ server_url, profile_key }) {
68
+ const baseUrl = String(server_url).replace(/\/+$/, '');
69
69
  console.log(`🔑 Requesting device login from ${baseUrl} ...`);
70
70
 
71
71
  let deviceResp;
@@ -74,8 +74,8 @@ export async function deviceFlowLogin({ serverUrl, profileKey }) {
74
74
  method: 'POST',
75
75
  headers: { 'Content-Type': 'application/json' },
76
76
  body: JSON.stringify({
77
- clientName: `mbkbucket-cli-${os.hostname()}`,
78
- ...(profileKey && { profileKey }),
77
+ client_name: `mbkbucket-cli-${os.hostname()}`,
78
+ ...(profile_key && { profile_key }),
79
79
  }),
80
80
  });
81
81
  deviceResp = await res.json();
@@ -87,19 +87,24 @@ export async function deviceFlowLogin({ serverUrl, profileKey }) {
87
87
  throw err;
88
88
  }
89
89
 
90
- const { verificationUrl, userCode, deviceCode, expiresIn, interval, profile } = deviceResp;
90
+ const verification_url = deviceResp.verification_url;
91
+ const user_code = deviceResp.user_code;
92
+ const device_code = deviceResp.device_code;
93
+ const expires_in = deviceResp.expires_in;
94
+ const interval = deviceResp.interval;
95
+ const profile = deviceResp.profile;
91
96
 
92
97
  console.log('\n┌─────────────────────────────────────────────────────────┐');
93
98
  console.log('│ │');
94
99
  console.log('│ 🌐 Open this URL in your browser to approve: │');
95
- console.log(`│ ${verificationUrl.padEnd(53)}│`);
100
+ console.log(`│ ${(verification_url || '').padEnd(53)}│`);
96
101
  console.log('│ │');
97
- console.log(`│ 🔢 Or enter this code: ${userCode.padEnd(30)}│`);
102
+ console.log(`│ 🔢 Or enter this code: ${(user_code || '').padEnd(30)}│`);
98
103
  console.log('│ │');
99
104
  console.log('└─────────────────────────────────────────────────────────┘\n');
100
105
 
101
106
  if (profile) console.log(` Profile: ${profile.name} (scope: ${profile.scope || 'full'})`);
102
- console.log(` Waiting for approval (expires in ${Math.floor(expiresIn / 60)} minutes)...\n`);
107
+ console.log(` Waiting for approval (expires in ${Math.floor((expires_in || 900) / 60)} minutes)...\n`);
103
108
 
104
109
  const pollInterval = (interval || 5) * 1000;
105
110
  const deadline = Date.now() + MAX_POLL_TIME_MS;
@@ -113,17 +118,18 @@ export async function deviceFlowLogin({ serverUrl, profileKey }) {
113
118
  const pollRes = await fetch(`${baseUrl}/api/cli/device/token`, {
114
119
  method: 'POST',
115
120
  headers: { 'Content-Type': 'application/json' },
116
- body: JSON.stringify({ deviceCode }),
121
+ body: JSON.stringify({ device_code }),
117
122
  });
118
123
 
119
124
  const pollBody = await pollRes.json();
120
125
 
121
126
  if (pollBody.status === 'approved' && pollBody.success) {
127
+ const token_prefix = pollBody.token_prefix || '';
122
128
  console.log(`✅ Login approved! Welcome, ${pollBody.username}.`);
123
- console.log(` Token prefix: ${pollBody.tokenPrefix}...`);
129
+ console.log(` Token prefix: ${token_prefix}...`);
124
130
  return {
125
131
  token: pollBody.token,
126
- tokenPrefix: pollBody.tokenPrefix,
132
+ token_prefix: token_prefix,
127
133
  username: pollBody.username,
128
134
  profile: profile || null,
129
135
  };
@@ -1,3 +1,10 @@
1
+ /**
2
+ * MBKBucket
3
+ * Copyright (c) 2026 Muhammad Bin Khalid, MBKTech.org and contributors
4
+ * Licensed under the MIT License.
5
+ * Source: https://github.com/MIbnEKhalid/mbkbucket
6
+ */
7
+
1
8
  import { createRequire } from "module";
2
9
  import dotenv from "dotenv";
3
10
  import { parseAndValidateMbkbucketVar, parseAndValidateBucketConnection } from "./validation.js";
@@ -102,7 +109,4 @@ export function validateAllConfiguration() {
102
109
 
103
110
  export const mbkbucketVar = validateConfiguration();
104
111
 
105
- export {
106
- packageJson,
107
- appVersion
108
- };
112
+ export { packageJson, appVersion };
@@ -1,11 +1,26 @@
1
1
  import { createLogger } from "#logger";
2
+ import { isJsonRequest, sendError, sanitizeErrorDetails } from "mbkauthe";
2
3
 
3
4
  const debugServer = createLogger('server');
4
5
 
5
6
  const BASE_ERROR_DATA = { layout: false, pagename: "Home", page: "/" };
6
7
 
7
- export function notFoundHandler(req, res) {
8
+ export function notFoundHandler(req, res, next) {
9
+ const url = req.originalUrl || req.url || '';
10
+ if (!url.startsWith('/mbkbucket') && typeof next === 'function') {
11
+ return next();
12
+ }
13
+
8
14
  debugServer("Path not found: %s %s", req.method, req.url);
15
+
16
+ if (isJsonRequest(req)) {
17
+ return sendError(res, "The requested API route was not found.", {
18
+ statusCode: 404,
19
+ code: "ROUTE_NOT_FOUND",
20
+ req,
21
+ });
22
+ }
23
+
9
24
  return res.status(404).render("Error/dError.handlebars", {
10
25
  ...BASE_ERROR_DATA,
11
26
  code: 404,
@@ -14,13 +29,26 @@ export function notFoundHandler(req, res) {
14
29
  });
15
30
  }
16
31
 
17
- export function globalErrorHandler(err, _req, res, _next) {
18
- console.error(`[mbkbucket] ${err.stack}`);
19
- return res.status(500).render("Error/dError.handlebars", {
32
+ export function globalErrorHandler(err, req, res, _next) {
33
+ console.error(`[mbkbucket] ${err.stack || err}`);
34
+
35
+ const statusCode = Number(err.status || err.statusCode || 500);
36
+
37
+ if (isJsonRequest(req)) {
38
+ return sendError(res, err, {
39
+ statusCode,
40
+ req,
41
+ details: process.env.NODE_ENV !== 'production' ? err.stack : undefined,
42
+ });
43
+ }
44
+
45
+ const sanitizedDetails = err.message ? sanitizeErrorDetails(err.message) : undefined;
46
+
47
+ return res.status(statusCode).render("Error/dError.handlebars", {
20
48
  ...BASE_ERROR_DATA,
21
- code: 500,
22
- error: "Internal app Error",
23
- message: "An unexpected error occurred on the app.",
24
- details: err.message,
49
+ code: statusCode,
50
+ error: statusCode >= 500 ? "Internal app Error" : (err.name || "Client Error"),
51
+ message: err.message || "An unexpected error occurred on the app.",
52
+ ...(sanitizedDetails ? { details: sanitizedDetails } : {}),
25
53
  });
26
54
  }
@@ -21,7 +21,7 @@ const uploadChunkMiddleware = (req, res, next) => {
21
21
  });
22
22
  };
23
23
 
24
- const adminAuth = sessRole('SuperAdmin');
24
+ const adminAuth = sessRole('superadmin');
25
25
 
26
26
  router.use(requireBucketApi);
27
27
 
@@ -1,3 +1,10 @@
1
+ /**
2
+ * MBKBucket
3
+ * Copyright (c) 2026 Muhammad Bin Khalid, MBKTech.org and contributors
4
+ * Licensed under the MIT License.
5
+ * Source: https://github.com/MIbnEKhalid/mbkbucket
6
+ */
7
+
1
8
  import express from "express";
2
9
  import { sessRole } from "mbkauthe";
3
10
  import { bucketResolver } from "../middleware/bucket-resolver.js";
@@ -8,7 +15,7 @@ import apiRoutes from "./api.routes.js";
8
15
 
9
16
  const router = express.Router();
10
17
 
11
- router.get('/mbkbucket', sessRole('SuperAdmin'), renderBucketDashboard);
18
+ router.get('/mbkbucket', sessRole('superadmin'), renderBucketDashboard);
12
19
  router.use('/mbkbucket', bucketResolver, infoRoutes, viewRoutes, apiRoutes);
13
20
 
14
21
  export default router;
@@ -7,7 +7,7 @@ import { pviewSecurity } from "../middleware/security.js";
7
7
  import { viewFile, playerPage, publicView } from "../controllers/view.controller.js";
8
8
 
9
9
  const router = express.Router();
10
- const adminAuth = sessRole('SuperAdmin');
10
+ const adminAuth = sessRole('superadmin');
11
11
 
12
12
  router.use(requireBucketView);
13
13
  router.get('/player/*key', adminAuth, playerPage);
@@ -36,7 +36,16 @@ export function classifyViewError(error, fallbackMessage = 'Request failed') {
36
36
 
37
37
  export function sendApiError(res, error, fallbackMessage = 'Request failed') {
38
38
  const { status, code, message } = classifyApiError(error, fallbackMessage);
39
- return res.status(status).json({ success: false, code, error: message });
39
+ return res.status(status).json({
40
+ success: false,
41
+ code,
42
+ error: {
43
+ code,
44
+ message,
45
+ },
46
+ message,
47
+ timestamp: new Date().toISOString(),
48
+ });
40
49
  }
41
50
 
42
51
  export function sendViewError(res, error, fallbackMessage = 'Request failed') {
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "mbkbucket",
3
- "version": "3.3.2",
3
+ "version": "3.5.0",
4
4
  "description": "Flexible S3/R2 bucket management — library, Express router, and CLI for mbktech.org applications. Provides upload, download, listing, multipart utilities, signed URLs, and a command-line interface with built-in configuration validation and health checks",
5
5
  "author": "Muhammad Bin Khalid",
6
6
  "homepage": "https://github.com/MIbnEKhalid/mbkbucket#readme",
7
- "license": "LGPL-3.0-only",
7
+ "license": "MIT",
8
8
  "main": "index.js",
9
9
  "type": "module",
10
10
  "types": "index.d.ts",
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "scripts": {
15
15
  "dev": "cross-env NODE_ENV=dev nodemon index.js",
16
- "test": "node --test"
16
+ "test": "vitest run"
17
17
  },
18
18
  "imports": {
19
19
  "#helpers": "./lib/src/utils/helpers.js",
@@ -28,13 +28,16 @@
28
28
  "express": "^5.1.0",
29
29
  "express-handlebars": "^8.0.3",
30
30
  "express-rate-limit": "^7.5.0",
31
- "mbkauthe": "^5.3.6",
31
+ "mbkauthe": "^5.7.0",
32
32
  "multer": "^2.0.2",
33
33
  "pg": "^8.16.3"
34
34
  },
35
35
  "devDependencies": {
36
+ "@types/supertest": "^7.2.1",
36
37
  "cross-env": "^7.0.3",
37
- "nodemon": "^3.1.14"
38
+ "nodemon": "^3.1.14",
39
+ "supertest": "^7.2.2",
40
+ "vitest": "^4.1.11"
38
41
  },
39
42
  "overrides": {
40
43
  "csurf": {
@@ -77,4 +80,4 @@
77
80
  "file-upload",
78
81
  "file-download"
79
82
  ]
80
- }
83
+ }
@@ -1,3 +1,10 @@
1
+ <!--
2
+ * MBKBucket
3
+ * Copyright (c) 2026 Muhammad Bin Khalid, MBKTech.org and contributors
4
+ * Licensed under the MIT License.
5
+ * Source: https://github.com/MIbnEKhalid/mbkbucket
6
+ -->
7
+
1
8
  <!DOCTYPE html>
2
9
  <html lang="en">
3
10
 
@@ -1,3 +1,10 @@
1
+ <!--
2
+ * MBKBucket
3
+ * Copyright (c) 2026 Muhammad Bin Khalid, MBKTech.org and contributors
4
+ * Licensed under the MIT License.
5
+ * Source: https://github.com/MIbnEKhalid/mbkbucket
6
+ -->
7
+
1
8
  <!DOCTYPE html>
2
9
  <html lang="en">
3
10