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
35 changes: 17 additions & 18 deletions src/box-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,9 @@ class BoxCommand extends Command {
// Set up the command for bulk run
DEBUG.init('Preparing for bulk input');
this.isBulk = true;
// eslint-disable-next-line unicorn/prefer-structured-clone
originalArgs = _.cloneDeep(this.constructor.args);
// eslint-disable-next-line unicorn/prefer-structured-clone
originalFlags = _.cloneDeep(this.constructor.flags);
this.disableRequiredArgsAndFlags();
}
Expand Down Expand Up @@ -615,7 +617,7 @@ class BoxCommand extends Command {
let parsedData;
try {
let jsonFile = JSON.parse(fileContents);
parsedData = jsonFile.hasOwnProperty('entries')
parsedData = Object.hasOwn(jsonFile, 'entries')
? jsonFile.entries
: jsonFile;
} catch (error) {
Expand Down Expand Up @@ -651,10 +653,7 @@ class BoxCommand extends Command {
// Arrays can be one of two things: an array of values for a single key,
// or an array of grouped flags/args as objects
// First, check if everything in the array is either all object or all non-object
let types = value.reduce(
(acc, t) => acc.concat(typeof t),
[]
);
let types = value.map((t) => typeof t);
if (
types.some((t) => t !== 'object') &&
types.includes('object')
Expand Down Expand Up @@ -1196,11 +1195,10 @@ class BoxCommand extends Command {
if (Array.isArray(content)) {
// Format each object individually and then flatten in case this an array of arrays,
// which happens when a command that outputs a collection gets run in bulk
formattedOutputData = (
await Promise.all(
content.map((o) => this._formatOutputObject(o))
)
).flat();
const formattedOutputResults = await Promise.all(
content.map((o) => this._formatOutputObject(o))
);
formattedOutputData = formattedOutputResults.flat();
DEBUG.output(
'Formatted %d output entries for display',
content.length
Expand Down Expand Up @@ -1649,9 +1647,10 @@ class BoxCommand extends Command {
if (!fields) {
return output;
}
fields = REQUIRED_FIELDS.concat(
fields.split(',').filter((f) => !REQUIRED_FIELDS.includes(f))
);
fields = [
...REQUIRED_FIELDS,
...fields.split(',').filter((f) => !REQUIRED_FIELDS.includes(f)),
];
DEBUG.output('Filtering output with fields: %O', fields);
if (Array.isArray(output)) {
output = output.map((o) =>
Expand Down Expand Up @@ -1723,7 +1722,7 @@ class BoxCommand extends Command {
) {
let subKeys = this.getNestedKeys(object[key]);
subKeys = subKeys.map((x) => `${key}.${x}`);
keys = keys.concat(subKeys);
keys = [...keys, ...subKeys];
} else {
keys.push(key);
}
Expand Down Expand Up @@ -1757,10 +1756,10 @@ class BoxCommand extends Command {
);

// Successively apply the offsets to the current time
newDate = argPairs.reduce(
(d, args) => offsetDate(d, ...args),
new Date()
);
newDate = new Date();
for (const args of argPairs) {
newDate = offsetDate(newDate, ...args);
}
} else if (time === 'now') {
newDate = new Date();
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/collaborations/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CollaborationsUpdateCommand extends BoxCommand {
if (flags.status) {
parameters.body.status = flags.status;
}
if (flags.hasOwnProperty('can-view-path')) {
if (Object.hasOwn(flags, 'can-view-path')) {
parameters.body.can_view_path = flags['can-view-path'];
}
if (flags.role) {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/configure/environments/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class EnvironmentsAddCommand extends BoxCommand {
cacheTokens: true,
};

if (environmentsObject.environments.hasOwnProperty(environmentName)) {
if (Object.hasOwn(environmentsObject.environments, environmentName)) {
throw new BoxCLIError(
'There already is an environment with this name'
);
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 @@ -27,7 +27,7 @@ class EnvironmentsDeleteCommand extends BoxCommand {
name = answers.environment;
}

if (environmentsObject.environments.hasOwnProperty(name)) {
if (Object.hasOwn(environmentsObject.environments, name)) {
delete environmentsObject.environments[name];
if (environmentsObject.default === name) {
environmentsObject.default = '';
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 @@ -22,7 +22,7 @@ class EnvironmentsSetCurrentCommand extends BoxCommand {
name = answers.environment;
}

if (environmentsObject.environments.hasOwnProperty(name)) {
if (Object.hasOwn(environmentsObject.environments, name)) {
environmentsObject.default = name;
await this.updateEnvironments(environmentsObject);
this.info(`The ${name} environment has been set as the default`);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/configure/environments/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class EnvironmentsUpdateCommand extends BoxCommand {
environment.useDefaultAsUser = true;
}

if (flags.hasOwnProperty('cache-tokens')) {
if (Object.hasOwn(flags, 'cache-tokens')) {
environment.cacheTokens = flags['cache-tokens'];
}

Expand Down
6 changes: 3 additions & 3 deletions src/commands/configure/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ class ConfigureSettingsCommand extends BoxCommand {
}
settings.boxReportsFolderPath = reportsPath;
}
if (flags.hasOwnProperty('output-json')) {
if (Object.hasOwn(flags, 'output-json')) {
settings.outputJson = flags['output-json'];
}
if (flags.hasOwnProperty('enable-proxy')) {
if (Object.hasOwn(flags, 'enable-proxy')) {
settings.enableProxy = flags['enable-proxy'];
}
if (flags['proxy-url']) {
Expand All @@ -83,7 +83,7 @@ class ConfigureSettingsCommand extends BoxCommand {
if (flags['proxy-password']) {
settings.proxy.password = flags['proxy-password'];
}
if (flags.hasOwnProperty(['enable-analytics-client'])) {
if (Object.hasOwn(flags, 'enable-analytics-client')) {
settings.enableAnalyticsClient = flags['enable-analytics-client'];
}
if (flags['analytics-client-name']) {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/files/lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class FilesLockCommand extends BoxCommand {
if (flags.expires) {
options.expires_at = flags.expires;
}
if (flags.hasOwnProperty('prevent-download')) {
if (Object.hasOwn(flags, 'prevent-download')) {
options.is_download_prevented = flags['prevent-download'];
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/files/rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class FilesRenameCommand extends BoxCommand {
name: args.name,
};

if (flags.hasOwnProperty('description')) {
if (Object.hasOwn(flags, 'description')) {
options.description = flags.description;
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/files/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class FileUpdateCommand extends BoxCommand {
if (flags.name) {
updates.name = flags.name;
}
if (flags.hasOwnProperty('description')) {
if (Object.hasOwn(flags, 'description')) {
updates.description = flags.description;
}
if (flags.tags) {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/folders/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class FoldersDeleteCommand extends BoxCommand {
const { flags, args } = await this.parse(FoldersDeleteCommand);
let options = {};

if (flags.hasOwnProperty('recursive')) {
if (Object.hasOwn(flags, 'recursive')) {
options.recursive = flags.recursive;
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/folders/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class FoldersDownloadCommand extends BoxCommand {

this.outputPath = null;
this.maxDepth =
flags.hasOwnProperty('depth') && flags.depth >= 0
Object.hasOwn(flags, 'depth') && flags.depth >= 0
? flags.depth
: Number.POSITIVE_INFINITY;
this.overwrite = flags.overwrite;
Expand Down
12 changes: 6 additions & 6 deletions src/commands/folders/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,32 @@ class FoldersUpdateCommand extends BoxCommand {
if (flags.name) {
updates.name = flags.name;
}
if (flags.hasOwnProperty('can-non-owners-invite')) {
if (Object.hasOwn(flags, 'can-non-owners-invite')) {
updates.can_non_owners_invite = flags['can-non-owners-invite'];
}
if (flags.hasOwnProperty('can-non-owners-view-collaborators')) {
if (Object.hasOwn(flags, 'can-non-owners-view-collaborators')) {
updates.can_non_owners_view_collaborators =
flags['can-non-owners-view-collaborators'];
}
if (flags.hasOwnProperty('description')) {
if (Object.hasOwn(flags, 'description')) {
updates.description = flags.description;
}
if (flags['upload-email-access']) {
updates.folder_upload_email = {
access: flags['upload-email-access'],
};
}
if (flags.hasOwnProperty('restrict-collaboration')) {
if (Object.hasOwn(flags, 'restrict-collaboration')) {
updates.can_non_owners_invite = !flags['restrict-collaboration'];
}
if (flags.hasOwnProperty('restrict-to-enterprise')) {
if (Object.hasOwn(flags, 'restrict-to-enterprise')) {
updates.is_collaboration_restricted_to_enterprise =
flags['restrict-to-enterprise'];
}
if (flags.tags) {
updates.tags = flags.tags.split(',');
}
if (flags.hasOwnProperty('sync')) {
if (Object.hasOwn(flags, 'sync')) {
updates.sync_state = flags.sync ? 'synced' : 'not_synced';
}

Expand Down
8 changes: 4 additions & 4 deletions src/commands/groups/memberships/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ class GroupsAddMembershipCommand extends BoxCommand {
const { flags, args } = await this.parse(GroupsAddMembershipCommand);
let options = { configurable_permissions: {} };

if (flags.hasOwnProperty('can-run-reports')) {
if (Object.hasOwn(flags, 'can-run-reports')) {
options.configurable_permissions.can_run_reports =
flags['can-run-reports'];
}
if (flags.hasOwnProperty('can-instant-login')) {
if (Object.hasOwn(flags, 'can-instant-login')) {
options.configurable_permissions.can_instant_login =
flags['can-instant-login'];
}
if (flags.hasOwnProperty('can-create-accounts')) {
if (Object.hasOwn(flags, 'can-create-accounts')) {
options.configurable_permissions.can_create_accounts =
flags['can-create-accounts'];
}
if (flags.hasOwnProperty('can-edit-accounts')) {
if (Object.hasOwn(flags, 'can-edit-accounts')) {
options.configurable_permissions.can_edit_accounts =
flags['can-edit-accounts'];
}
Expand Down
8 changes: 4 additions & 4 deletions src/commands/groups/memberships/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ class GroupsUpdateMembershipCommand extends BoxCommand {
const { flags, args } = await this.parse(GroupsUpdateMembershipCommand);
let options = { configurable_permissions: {} };

if (flags.hasOwnProperty('can-run-reports')) {
if (Object.hasOwn(flags, 'can-run-reports')) {
options.configurable_permissions.can_run_reports =
flags['can-run-reports'];
}
if (flags.hasOwnProperty('can-instant-login')) {
if (Object.hasOwn(flags, 'can-instant-login')) {
options.configurable_permissions.can_instant_login =
flags['can-instant-login'];
}
if (flags.hasOwnProperty('can-create-accounts')) {
if (Object.hasOwn(flags, 'can-create-accounts')) {
options.configurable_permissions.can_create_accounts =
flags['can-create-accounts'];
}
if (flags.hasOwnProperty('can-edit-accounts')) {
if (Object.hasOwn(flags, 'can-edit-accounts')) {
options.configurable_permissions.can_edit_accounts =
flags['can-edit-accounts'];
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/integration-mappings/slack/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class IntegrationMappingsSlackCreateCommand extends BoxCommand {
'Either the --slack-workspace-id or --slack-org-id flag must be passed'
);
}
if (flags.hasOwnProperty('disable-access-management')) {
if (Object.hasOwn(flags, 'disable-access-management')) {
body.options = {
is_access_management_disabled:
flags['disable-access-management'],
Expand Down
2 changes: 1 addition & 1 deletion src/commands/integration-mappings/slack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class IntegrationMappingsSlackListCommand extends BoxCommand {
if (flags['box-item-id']) {
options.box_item_id = flags['box-item-id'];
}
if (flags.hasOwnProperty('manually-created')) {
if (Object.hasOwn(flags, 'manually-created')) {
options.is_manually_created = flags['manually-created'];
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/integration-mappings/slack/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class IntegrationMappingsSlackUpdateCommand extends BoxCommand {
type: 'folder',
};
}
if (flags.hasOwnProperty('disable-access-management')) {
if (Object.hasOwn(flags, 'disable-access-management')) {
body.options = {
is_access_management_disabled:
flags['disable-access-management'],
Expand Down
2 changes: 1 addition & 1 deletion src/commands/legal-hold-policies/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class LegalHoldPoliciesCreateCommand extends BoxCommand {
if (flags['filter-ended-at']) {
options.filter_ended_at = flags['filter-ended-at'];
}
if (flags.hasOwnProperty('ongoing')) {
if (Object.hasOwn(flags, 'ongoing')) {
options.is_ongoing = true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class OAuthLoginCommand extends BoxCommand {

if (this.flags.reauthorize) {
if (
!environmentsObject.environments.hasOwnProperty(this.flags.name)
!Object.hasOwn(environmentsObject.environments, this.flags.name)
) {
this.error(`The ${this.flags.name} environment does not exist`);
}
Expand Down
10 changes: 2 additions & 8 deletions src/commands/metadata-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,13 @@ class MetadataQueryCommand extends BoxCommand {
if (queryParameter) {
combinedQueryParameters = {
...combinedQueryParameters,
...queryParameter.reduce(
(accumulator, current) => ({ ...accumulator, ...current }),
{}
),
...Object.assign({}, ...queryParameter),
};
}
if (queryParameterArray) {
combinedQueryParameters = {
...combinedQueryParameters,
...queryParameterArray.reduce(
(accumulator, current) => ({ ...accumulator, ...current }),
{}
),
...Object.assign({}, ...queryParameterArray),
};
}

Expand Down
6 changes: 3 additions & 3 deletions src/commands/metadata-templates/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ function _parseFlags(preparsedArgv) {
}

// Add the last field if necessary and return
template.fields = template.fields
.concat(currentField)
.filter((op) => op !== null);
template.fields = [...template.fields, currentField].filter(
(op) => op !== null
);
return template;
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/metadata-templates/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ function _parseOperations(preparsedArgv) {
}

// Add the last field if necessary and return
return ops.concat(currentOp).filter((op) => op !== null);
return [...ops, currentOp].filter((op) => op !== null);
}

class MetadataTemplatesUpdateCommand extends BoxCommand {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ManualRequestCommand extends BoxCommand {
parameters.qs = querystring.parse(flags.query);
}

if (flags.hasOwnProperty('body') && flags.body !== '') {
if (Object.hasOwn(flags, 'body') && flags.body !== '') {
try {
parameters.body = JSON.parse(flags.body);
parameters.json = true;
Expand Down
4 changes: 2 additions & 2 deletions src/commands/retention-policies/assign.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class RetentionPoliciesAssignCommand extends BoxCommand {
let assignID = flags['assign-to-id'];
let options = {};

if (flags.hasOwnProperty('filter-field')) {
if (Object.hasOwn(flags, 'filter-field')) {
options.filter_fields = flags['filter-field'];
}
if (flags.hasOwnProperty('start-date-field')) {
if (Object.hasOwn(flags, 'start-date-field')) {
options.start_date_field = flags['start-date-field'];
}

Expand Down
Loading