Skip to content

Commit

Permalink
feat: Add support for Integration Mappings API (#472)
Browse files Browse the repository at this point in the history
  • Loading branch information
arjankowski authored Jun 2, 2023
1 parent 9f5efff commit bbf2548
Show file tree
Hide file tree
Showing 12 changed files with 627 additions and 59 deletions.
123 changes: 65 additions & 58 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@oclif/plugin-help": "^2.2.1",
"@oclif/plugin-not-found": "^1.2.0",
"archiver": "^3.0.0",
"box-node-sdk": "^3.0.0",
"box-node-sdk": "^3.1.0",
"chalk": "^2.4.1",
"cli-progress": "^2.1.0",
"csv": "^3.1.0",
Expand Down
76 changes: 76 additions & 0 deletions src/commands/integration-mappings/slack/create.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
'use strict';

const BoxCommand = require('../../../box-command');
const BoxCLIError = require('../../../cli-error');
const { flags } = require('@oclif/command');

class IntegrationMappingsSlackCreateCommand extends BoxCommand {
async run() {
const { flags, args } = this.parse(IntegrationMappingsSlackCreateCommand);
let body = {};
body.box_item = {
type: 'folder',
id: args.boxItemID
};
body.partner_item = {
type: 'channel',
id: args.channelID
};
if (flags['slack-workspace-id']) {
body.partner_item.slack_workspace_id = flags['slack-workspace-id'];
} else if (flags['slack-org-id']) {
body.partner_item.slack_org_id = flags['slack-org-id'];
} else {
throw new BoxCLIError('Either the --slack-workspace-id or --slack-org-id flag must be passed');
}
if (flags.hasOwnProperty('disable-access-management')) {
body.options = {
is_access_management_disabled: flags['disable-access-management']
};
}

let integrationMapping = await this.client.integrationMappings.createSlackIntegrationMapping(body);
await this.output(integrationMapping);
}
}

IntegrationMappingsSlackCreateCommand.description = 'Create Slack integration mapping';
IntegrationMappingsSlackCreateCommand.examples = [
'box integration-mappings:slack:create 123 AB89X56Y --slack-org-id 789',
'box integration-mappings:slack:create 123 AB89X56Y --slack-workspace-id 999 --disable-access-management'
];
IntegrationMappingsSlackCreateCommand._endpoint = 'post_integration_mappings_slack';

IntegrationMappingsSlackCreateCommand.flags = {
...BoxCommand.flags,
'slack-workspace-id': flags.string({
description: 'ID of the Slack workspace with which the item would be associated',
exclusive: ['slack-org-id']
}),
'slack-org-id': flags.string({
description: 'ID of the Slack organization with which the item would be associated',
exclusive: ['slack-workspace-id']
}),
'disable-access-management': flags.boolean({
description: 'Indicates whether or not channel member access to the underlying box item should be automatically managed. ' +
'Depending on type of channel, access is managed through creating collaborations or shared links.',
allowNo: true
})
};

IntegrationMappingsSlackCreateCommand.args = [
{
name: 'boxItemID',
required: true,
hidden: false,
description: 'ID of the mapped folder'
},
{
name: 'channelID',
required: true,
hidden: false,
description: 'ID of the mapped Slack channel'
}
];

module.exports = IntegrationMappingsSlackCreateCommand;
31 changes: 31 additions & 0 deletions src/commands/integration-mappings/slack/delete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

const BoxCommand = require('../../../box-command');

class IntegrationMappingsSlackDeleteCommand extends BoxCommand {
async run() {
const { args } = this.parse(IntegrationMappingsSlackDeleteCommand);

await this.client.integrationMappings.deleteSlackIntegrationMappingById({ integration_mapping_id: args.id });
this.info(`Deleted Slack integration mapping ${args.id}`);
}
}

IntegrationMappingsSlackDeleteCommand.description = 'Delete Slack integration mapping';
IntegrationMappingsSlackDeleteCommand.examples = ['box integration-mappings:slack:delete 123'];
IntegrationMappingsSlackDeleteCommand._endpoint = 'delete_integration_mappings_slack_id';

IntegrationMappingsSlackDeleteCommand.flags = {
...BoxCommand.flags
};

IntegrationMappingsSlackDeleteCommand.args = [
{
name: 'id',
required: true,
hidden: false,
description: 'ID of the integration mapping',
}
];

module.exports = IntegrationMappingsSlackDeleteCommand;
Loading

0 comments on commit bbf2548

Please sign in to comment.