-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add categories and tasks commands #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4f8e490
feat(cli): add category and task commands
gentamura b2e393b
feat: add category and task create commands
gentamura 7afd53e
docs: clarify supabase publishable key usage
gentamura 181df4b
fix: narrow loopback server address
gentamura b241874
Merge branch 'main' into feat/categories-tasks
gentamura 5b08b95
refactor(cli): align category and task commands with api
gentamura 9b4a03b
feat(auth): provide authenticated token helper
gentamura 28bb5b5
chore(env): enforce Supabase config at startup
gentamura c3efaa0
feat(auth): route CLI auth via Listee API
gentamura 6fcd9d0
refactor(auth): adopt camelCase token payload
gentamura bd6abd2
fix(auth): accept empty success bodies
gentamura e6392ee
fix(cli): validate ids before API calls
gentamura File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| SUPABASE_URL= | ||
| SUPABASE_PUBLISHABLE_KEY= | ||
| LISTEE_API_URL= | ||
| # LISTEE_CLI_KEYCHAIN_SERVICE=listee-cli | ||
| # LISTEE_API_AUTH_BEARER_MODE=user-id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| import type { Command } from "commander"; | ||
| import { | ||
| createCategory, | ||
| getCategory, | ||
| listCategories, | ||
| } from "../services/category-api.js"; | ||
|
|
||
| const ensurePositiveInteger = (value: string): number => { | ||
| if (!/^\d+$/.test(value)) { | ||
| throw new Error("Limit must be a positive integer."); | ||
| } | ||
| const parsed = Number.parseInt(value, 10); | ||
| if (!Number.isFinite(parsed) || parsed <= 0) { | ||
| throw new Error("Limit must be a positive integer."); | ||
| } | ||
| return parsed; | ||
| }; | ||
|
|
||
| const ensureNonEmptyString = (value: string, label: string): string => { | ||
| const trimmed = value.trim(); | ||
| if (trimmed.length === 0) { | ||
| throw new Error(`${label} must not be empty.`); | ||
| } | ||
| return trimmed; | ||
| }; | ||
|
|
||
| const execute = <T extends unknown[]>(task: (...args: T) => Promise<void>) => { | ||
| return async (...args: T): Promise<void> => { | ||
| try { | ||
| await task(...args); | ||
| } catch (error) { | ||
| if (error instanceof Error) { | ||
| console.error(`Error: ${error.message}`); | ||
| } else { | ||
| console.error("Unknown error occurred."); | ||
| } | ||
| process.exitCode = 1; | ||
| } | ||
| }; | ||
| }; | ||
|
|
||
| const printCategories = ( | ||
| items: readonly { | ||
| readonly id: string; | ||
| readonly name: string; | ||
| readonly kind: string; | ||
| }[], | ||
| ): void => { | ||
| if (items.length === 0) { | ||
| console.log("No categories found."); | ||
| return; | ||
| } | ||
|
|
||
| console.log("Categories:"); | ||
| for (const item of items) { | ||
| console.log(` • ${item.name} (${item.id}) [${item.kind}]`); | ||
| } | ||
| }; | ||
|
|
||
| const printCategoryDetails = (category: { | ||
| readonly name: string; | ||
| readonly id: string; | ||
| readonly kind: string; | ||
| readonly createdBy: string; | ||
| readonly updatedBy: string; | ||
| readonly createdAt: string; | ||
| readonly updatedAt: string; | ||
| }): void => { | ||
| console.log(`Name: ${category.name}`); | ||
| console.log(`ID: ${category.id}`); | ||
| console.log(`Kind: ${category.kind}`); | ||
| console.log(`Created By: ${category.createdBy}`); | ||
| console.log(`Updated By: ${category.updatedBy}`); | ||
| console.log(`Created At: ${category.createdAt}`); | ||
| console.log(`Updated At: ${category.updatedAt}`); | ||
| }; | ||
|
|
||
| export const registerCategoryCommand = (program: Command): void => { | ||
| const categories = program | ||
| .command("categories") | ||
| .description("Inspect Listee categories via the API."); | ||
|
|
||
| categories | ||
| .command("list") | ||
| .description("List categories for the authenticated user.") | ||
| .option("--email <email>", "Account email to use when fetching categories") | ||
| .option("--limit <limit>", "Maximum number of categories to fetch") | ||
| .option("--cursor <cursor>", "Cursor returned by a previous list operation") | ||
| .action( | ||
| execute( | ||
| async (options: { | ||
| readonly email?: string; | ||
| readonly limit?: string; | ||
| readonly cursor?: string; | ||
| }) => { | ||
| const limit = | ||
| options.limit === undefined | ||
| ? undefined | ||
| : ensurePositiveInteger(options.limit); | ||
| const result = await listCategories({ | ||
| email: options.email, | ||
| limit, | ||
| cursor: options.cursor ?? null, | ||
| }); | ||
| printCategories(result.data); | ||
| if (result.meta.hasMore) { | ||
| const cursorValue = result.meta.nextCursor ?? ""; | ||
| console.log( | ||
| "More categories available. Use --cursor", | ||
| cursorValue, | ||
| "to continue.", | ||
| ); | ||
| } | ||
| }, | ||
| ), | ||
| ); | ||
|
|
||
| categories | ||
| .command("show <categoryId>") | ||
| .description("Show details for a specific category.") | ||
| .option( | ||
| "--email <email>", | ||
| "Account email to use when fetching the category", | ||
| ) | ||
| .action( | ||
| execute( | ||
| async (categoryId: string, options: { readonly email?: string }) => { | ||
| const response = await getCategory({ | ||
| email: options.email, | ||
| categoryId, | ||
| }); | ||
| printCategoryDetails(response.data); | ||
| }, | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| ), | ||
| ); | ||
|
|
||
| categories | ||
| .command("create") | ||
| .description("Create a new category for the authenticated user.") | ||
| .requiredOption("--name <name>", "Name of the category to create") | ||
| .option( | ||
| "--email <email>", | ||
| "Account email to use when creating the category", | ||
| ) | ||
| .action( | ||
| execute( | ||
| async (options: { readonly name: string; readonly email?: string }) => { | ||
| const name = ensureNonEmptyString(options.name, "Name"); | ||
| const category = await createCategory({ | ||
| email: options.email, | ||
| name, | ||
| }); | ||
| console.log("Category created."); | ||
| printCategoryDetails(category); | ||
| }, | ||
| ), | ||
| ); | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.