Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions LICENSE-THIRD-PARTY.txt
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

-----------

The following npm package may be included in this product:
The following npm packages may be included in this product:

- statuses@2.0.1
- statuses@2.0.2

This package contains the following license:
These packages each contain the following license:

The MIT License (MIT)

Expand Down Expand Up @@ -371,11 +372,12 @@ THE SOFTWARE.

-----------

The following npm package may be included in this product:
The following npm packages may be included in this product:

- http-errors@2.0.0
- http-errors@2.0.1

This package contains the following license:
These packages each contain the following license:

The MIT License (MIT)

Expand Down Expand Up @@ -1931,7 +1933,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

The following npm packages may be included in this product:

- body-parser@1.20.3
- body-parser@1.20.4
- type-is@1.6.18

These packages each contain the following license:
Expand Down Expand Up @@ -2813,7 +2815,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

The following npm packages may be included in this product:

- @cypress/request@3.0.9
- @cypress/request@3.0.10
- aws-sign2@0.7.0
- forever-agent@0.6.1
- tunnel-agent@0.6.0
Expand Down Expand Up @@ -3136,12 +3138,11 @@ Apache-2.0

-----------

The following npm packages may be included in this product:
The following npm package may be included in this product:

- qs@6.13.0
- qs@6.14.0
- qs@6.14.2

These packages each contain the following license:
This package contains the following license:

BSD 3-Clause License

Expand Down Expand Up @@ -4147,7 +4148,7 @@ OTHER DEALINGS IN THE SOFTWARE.

The following npm package may be included in this product:

- basic-ftp@5.0.5
- basic-ftp@5.2.0

This package contains the following license:

Expand Down Expand Up @@ -4858,7 +4859,7 @@ IN THE SOFTWARE.

The following npm package may be included in this product:

- lodash@4.17.21
- lodash@4.17.23

This package contains the following license:

Expand Down Expand Up @@ -6719,7 +6720,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The following npm package may be included in this product:

- diff@4.0.2
- diff@4.0.4

This package contains the following license:

Expand Down Expand Up @@ -6906,8 +6907,8 @@ IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

The following npm packages may be included in this product:

- minimatch@5.1.6
- minimatch@9.0.5
- minimatch@5.1.9
- minimatch@9.0.9

These packages each contain the following license:

Expand Down Expand Up @@ -7057,7 +7058,7 @@ The following npm packages may be included in this product:
- ini@1.3.8
- isexe@2.0.0
- json-stringify-safe@5.0.1
- minimatch@3.1.2
- minimatch@3.1.5
- mute-stream@0.0.8
- mute-stream@2.0.0
- once@1.4.0
Expand Down Expand Up @@ -7445,7 +7446,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

The following npm package may be included in this product:

- raw-body@2.5.2
- raw-body@2.5.3

This package contains the following license:

Expand Down Expand Up @@ -8113,7 +8114,7 @@ THE SOFTWARE.

The following npm package may be included in this product:

- ajv@6.12.6
- ajv@6.14.0

This package contains the following license:

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"nyc": "^17.1.0",
"oclif": "^4.22.38",
"prettier": "^3.6.2",
"signal-exit": "^4.1.0",
"sinon": "^19.0.2",
"standard-version": "^9.5.0",
"typescript": "^5.7.2"
Expand Down
2 changes: 1 addition & 1 deletion src/box-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const BoxCLIError = require('./cli-error');
const CLITokenCache = require('./token-cache');
const utils = require('./util');
const pkg = require('../package.json');
const inquirer = require('inquirer');
const inquirer = require('./inquirer');
const { stringifyStream } = require('@discoveryjs/json-ext');
const progress = require('cli-progress');
let keytar = null;
Expand Down
4 changes: 3 additions & 1 deletion src/commands/ai/ask.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ AiAskCommand.flags = {
try {
return JSON.parse(input);
} catch (error) {
throw new Error(`Error parsing AI agent JSON: ${error.message}`);
throw new Error(
`Error parsing AI agent JSON: ${error.message}`
);
}
},
}),
Expand Down
4 changes: 3 additions & 1 deletion src/commands/ai/extract-structured.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ AiExtractStructuredCommand.flags = {
try {
return JSON.parse(input);
} catch (error) {
throw new Error(`Error parsing AI agent JSON: ${error.message}`);
throw new Error(
`Error parsing AI agent JSON: ${error.message}`
);
}
},
}),
Expand Down
4 changes: 3 additions & 1 deletion src/commands/ai/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ AiExtractCommand.flags = {
try {
return JSON.parse(input);
} catch (error) {
throw new Error(`Error parsing AI agent JSON: ${error.message}`);
throw new Error(
`Error parsing AI agent JSON: ${error.message}`
);
}
},
}),
Expand Down
2 changes: 1 addition & 1 deletion src/commands/configure/environments/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const { Args } = require('@oclif/core');
const BoxCommand = require('../../../box-command');
const BoxCLIError = require('../../../cli-error');
const inquirer = require('inquirer');
const inquirer = require('../../../inquirer');

class EnvironmentsDeleteCommand extends BoxCommand {
async run() {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/configure/environments/set-current.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const { Args } = require('@oclif/core');
const BoxCommand = require('../../../box-command');
const inquirer = require('inquirer');
const inquirer = require('../../../inquirer');

class EnvironmentsSetCurrentCommand extends BoxCommand {
async run() {
Expand Down
29 changes: 23 additions & 6 deletions src/commands/files/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@ const { Flags, Args } = require('@oclif/core');
const fs = require('node:fs');
const path = require('node:path');
const BoxCLIError = require('../../cli-error');
const { createReadStream, uploadFile, uploadNewFileVersion } = require('../../modules/upload');
const {
createReadStream,
uploadFile,
uploadNewFileVersion,
} = require('../../modules/upload');
const DEBUG = require('../../debug');

class FilesUploadCommand extends BoxCommand {
async run() {
const { flags, args } = await this.parse(FilesUploadCommand);
if (!fs.existsSync(args.path)) {
throw new BoxCLIError(`File not found: ${args.path}. Please check the file path and try again.`);
throw new BoxCLIError(
`File not found: ${args.path}. Please check the file path and try again.`
);
}
let size = fs.statSync(args.path).size;
let folderID = flags['parent-id'];
Expand Down Expand Up @@ -41,8 +47,16 @@ class FilesUploadCommand extends BoxCommand {
const { statusCode, response } = error;
const body = response?.body;

if (!flags.overwrite || statusCode !== 409 || body?.code !== 'item_name_in_use') {
if (!flags.overwrite && statusCode === 409 && body?.code === 'item_name_in_use') {
if (
!flags.overwrite ||
statusCode !== 409 ||
body?.code !== 'item_name_in_use'
) {
if (
!flags.overwrite &&
statusCode === 409 &&
body?.code === 'item_name_in_use'
) {
throw new BoxCLIError(
'A file with the same name already exists in the destination folder. Use --overwrite to replace it with a new version.',
error
Expand All @@ -62,7 +76,9 @@ class FilesUploadCommand extends BoxCommand {
);
}

DEBUG.output(`File already exists in folder; uploading as new version of file ${existingFileID}`);
DEBUG.output(
`File already exists in folder; uploading as new version of file ${existingFileID}`
);

// Re-create the stream since the first attempt consumed it
const versionStream = createReadStream(args.path);
Expand All @@ -79,7 +95,8 @@ class FilesUploadCommand extends BoxCommand {
}
}

FilesUploadCommand.description = 'Upload a file to a folder. Use --overwrite to automatically replace an existing file with the same name by uploading a new version';
FilesUploadCommand.description =
'Upload a file to a folder. Use --overwrite to automatically replace an existing file with the same name by uploading a new version';
FilesUploadCommand.examples = [
'box files:upload /path/to/file.pdf --parent-id 22222',
'box files:upload /path/to/file.pdf --parent-id 22222 --overwrite',
Expand Down
5 changes: 4 additions & 1 deletion src/commands/files/versions/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
const BoxCommand = require('../../../box-command');
const { Flags, Args } = require('@oclif/core');
const fs = require('node:fs');
const { createReadStream, uploadNewFileVersion } = require('../../../modules/upload');
const {
createReadStream,
uploadNewFileVersion,
} = require('../../../modules/upload');

class FilesUploadVersionsCommand extends BoxCommand {
async run() {
Expand Down
7 changes: 5 additions & 2 deletions src/commands/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const CLITokenCache = require('../token-cache');
const package_ = require('../../package.json');
const chalk = require('chalk');
const express = require('express');
const inquirer = require('inquirer');
const inquirer = require('../inquirer');
const path = require('node:path');
const ora = require('ora');
const http = require('node:http');
Expand Down Expand Up @@ -89,7 +89,10 @@ async function promptForAuthMethod(inquirerModule) {
trimmedChoice.length > CLIENT_ID_MIN_LENGTH &&
trimmedChoice.length < CLIENT_ID_MAX_LENGTH
) {
return promptForPlatformAppCredentials(inquirerModule, trimmedChoice);
return promptForPlatformAppCredentials(
inquirerModule,
trimmedChoice
);
}

// Invalid input — repeat the prompt
Expand Down
2 changes: 1 addition & 1 deletion src/commands/logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const BoxCommand = require('../box-command');
const BoxSDK = require('box-node-sdk').default;
const CLITokenCache = require('../token-cache');
const chalk = require('chalk');
const inquirer = require('inquirer');
const inquirer = require('../inquirer');
const pkg = require('../../package.json');
const { Flags } = require('@oclif/core');

Expand Down
4 changes: 1 addition & 3 deletions src/commands/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ class SearchCommand extends BoxCommand {
'Run: box search --help for all available filters.',
].join(os.EOL);

throw new BoxCLIError(
missingQueryMessage
);
throw new BoxCLIError(missingQueryMessage);
}

if (flags.all && (flags.limit || flags['max-items'])) {
Expand Down
39 changes: 39 additions & 0 deletions src/inquirer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';

// restore-cursor@3 (used by inquirer@8) calls require('signal-exit') as a
// function, but signal-exit@4 exports an object with an onExit() method.
//
// Locally, npm nests signal-exit@3 under restore-cursor, so both versions
// coexist. In the standalone Windows build produced by oclif pack:win, module
// resolution ends up pointing restore-cursor to top-level signal-exit@4
// (effectively like a flattened/deduped node_modules layout), which causes
// "signalExit is not a function" on Windows.
//
// Node's lookup order for require('signal-exit') from restore-cursor is:
// 1) restore-cursor/node_modules/signal-exit
// 2) parent node_modules/signal-exit
// If step (1) is absent in the packaged layout, step (2) resolves to v4.
//
// This started surfacing after dependency-tree changes included in v4.5.0
// (notably commit 4f4254d), where top-level signal-exit moved to 4.1.0.
//
// This shim wraps the v4 object export as a callable function before inquirer
// (and its restore-cursor dependency) is loaded.

const SIGNAL_EXIT_ID = 'signal-exit';
const signalExit = require(SIGNAL_EXIT_ID);

if (
typeof signalExit !== 'function' &&
typeof signalExit.onExit === 'function'
) {
const compatSignalExit = (...args) => signalExit.onExit(...args);
Object.assign(compatSignalExit, signalExit);

const resolvedPath = require.resolve(SIGNAL_EXIT_ID);
if (require.cache[resolvedPath]) {
require.cache[resolvedPath].exports = compatSignalExit;
}
}

module.exports = require('inquirer');
21 changes: 10 additions & 11 deletions src/modules/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,18 @@ function runChunkedUpload(uploader, size) {
uploader.on('chunkUploaded', (chunk) => {
bytesUploaded += chunk.part.size;
progressBar.update(bytesUploaded, {
speed: Math.floor(
bytesUploaded / (Date.now() - startTime) / 1000
),
speed: Math.floor(bytesUploaded / (Date.now() - startTime) / 1000),
});
});
return uploader.start();
}

async function uploadFile(client, { folderID, name, stream, size, fileAttributes }) {
async function uploadFile(
client,
{ folderID, name, stream, size, fileAttributes }
) {
if (size < CHUNKED_UPLOAD_FILE_SIZE) {
return client.files.uploadFile(
folderID,
name,
stream,
fileAttributes
);
return client.files.uploadFile(folderID, name, stream, fileAttributes);
}
const uploader = await client.files.getChunkedUploader(
folderID,
Expand All @@ -52,7 +48,10 @@ async function uploadFile(client, { folderID, name, stream, size, fileAttributes
return runChunkedUpload(uploader, size);
}

async function uploadNewFileVersion(client, { fileID, stream, size, fileAttributes }) {
async function uploadNewFileVersion(
client,
{ fileID, stream, size, fileAttributes }
) {
if (size < CHUNKED_UPLOAD_FILE_SIZE) {
return client.files.uploadNewFileVersion(
fileID,
Expand Down
Loading
Loading