Skip to content

Built for people who want to own their automations. Join the waitlist for an invite.

Package listing

@kody/trello

src/index.ts

84 lines · 2.6 KB · TypeScript
import { parseAction } from './types.ts'
import { accounts } from './accounts.ts'
import { request } from './request.ts'
import { getViewer } from './viewer.ts'
import { createBoard, getBoard, listBoards, updateBoard } from './boards.ts'
import { createList, getList, listLists, updateList } from './lists.ts'
import { createCard, getCard, listCards, updateCard } from './cards.ts'
import { addComment, listComments } from './comments.ts'
import { smokeTest } from './smoke-test.ts'
import {
	API_KEY_SETUP_URL,
	DEFAULT_API_KEY_SECRET,
	DEFAULT_INTEGRATION_NAME,
	DEFAULT_TOKEN_SECRET,
	OAUTH_CONNECT_URL,
	TOKEN_SETUP_URL,
	TRELLO_API_BASE_URL,
	TRELLO_AUTHORIZE_PAGE_URL,
	TRELLO_CALLBACK_URL,
	TRELLO_REQUIRED_HOSTS,
	TRELLO_SCOPES,
} from './setup.ts'

export {
	API_KEY_SETUP_URL,
	DEFAULT_API_KEY_SECRET,
	DEFAULT_INTEGRATION_NAME,
	DEFAULT_TOKEN_SECRET,
	OAUTH_CONNECT_URL,
	TOKEN_SETUP_URL,
	TRELLO_API_BASE_URL,
	TRELLO_AUTHORIZE_PAGE_URL,
	TRELLO_CALLBACK_URL,
	TRELLO_REQUIRED_HOSTS,
	TRELLO_SCOPES,
}
export { TrelloApiError } from './client.ts'
export { mutationPreview } from './setup.ts'
export { accounts } from './accounts.ts'
export { request } from './request.ts'
export { getViewer } from './viewer.ts'
export { boardSummary, createBoard, getBoard, listBoards, updateBoard } from './boards.ts'
export { createList, getList, listLists, listSummary, updateList } from './lists.ts'
export { cardSummary, createCard, getCard, listCards, updateCard } from './cards.ts'
export { addComment, commentSummary, listComments } from './comments.ts'
export { smokeTest } from './smoke-test.ts'

const actions = {
	'smoke-test': smokeTest,
	accounts,
	viewer: getViewer,
	request,
	'list-boards': listBoards,
	'get-board': getBoard,
	'create-board': createBoard,
	'update-board': updateBoard,
	'list-lists': listLists,
	'get-list': getList,
	'create-list': createList,
	'update-list': updateList,
	'list-cards': listCards,
	'get-card': getCard,
	'create-card': createCard,
	'update-card': updateCard,
	'list-comments': listComments,
	'add-comment': addComment,
} as const

export type TrelloAction = keyof typeof actions

const actionNames = Object.keys(actions) as Array<TrelloAction>

/**
 * Root dispatcher for Trello helpers. Defaults to the read-only smoke test.
 * Mutations require `confirm: true` or `dryRun: true`.
 * @example
 * import trello from 'kody:@kody/trello'
 * const result = await trello({ action: 'smoke-test' })
 */
export default async function trello(input: Record<string, unknown> = {}) {
	const action = parseAction(input.action, actionNames, 'smoke-test', 'Trello')
	const handler = actions[action]
	return await handler(input as never)
}