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
30 changes: 30 additions & 0 deletions src/cli/manage/listWidgets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Command } from 'commander';

import getWidgets from '../../services/widgets/getList';

export default function widgets() {
const cmd = new Command('list')
.description('Manage BigCommerce widgets');

handleWidgets(cmd as Command);
handleWidgetsTemplates(cmd as Command);

return cmd;
}

function handleWidgets(cmd: Command) {
cmd.command('widgets')
.description('List all widgets with their IDs from BigCommerce')
.action(async () => {
await getWidgets('widgets');
});
}

function handleWidgetsTemplates(cmd: Command) {
cmd.command('widget-templates')
.description('List all widget templates with their IDs from BigCommerce')
.action(async () => {
await getWidgets('widget-templates');
});

}
34 changes: 34 additions & 0 deletions src/services/widgets/getList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import axios from 'axios';

// Replace with your actual BigCommerce store hash and access token
import AUTH_CONFIG from '../auth/authConfig';

const BASE_URL = `${AUTH_CONFIG.apiPath}/content/`;

type ObjectType = 'widgets' | 'widget-templates'

async function getAll(wType: ObjectType) {
try {
const response = await axios.get(BASE_URL + wType, {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'X-Auth-Client': AUTH_CONFIG.authId,
'X-Auth-Token': AUTH_CONFIG.authToken,
},
});
const widgets = response.data.data;
if (!widgets || widgets.length === 0) {
console.log('No widgets found.');
return;
}
console.log('Widget List:');
console.table(widgets.map((widget: any) => ({ uuid: widget.uuid, name: widget.name })))
} catch (error: any) {
console.error('Error fetching widgets:', error.response?.data || error.message);
}
}



export default getAll;