codecard-cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +94 -0
- package/dist/commands/alerts.d.ts +2 -0
- package/dist/commands/alerts.js +44 -0
- package/dist/commands/auth/login.d.ts +2 -0
- package/dist/commands/auth/login.js +43 -0
- package/dist/commands/auth/logout.d.ts +2 -0
- package/dist/commands/auth/logout.js +20 -0
- package/dist/commands/auth/whoami.d.ts +2 -0
- package/dist/commands/auth/whoami.js +32 -0
- package/dist/commands/balance.d.ts +2 -0
- package/dist/commands/balance.js +35 -0
- package/dist/commands/card/freeze.d.ts +3 -0
- package/dist/commands/card/freeze.js +68 -0
- package/dist/commands/card/list.d.ts +2 -0
- package/dist/commands/card/list.js +44 -0
- package/dist/commands/pnl.d.ts +2 -0
- package/dist/commands/pnl.js +57 -0
- package/dist/commands/project/create.d.ts +2 -0
- package/dist/commands/project/create.js +36 -0
- package/dist/commands/project/list.d.ts +2 -0
- package/dist/commands/project/list.js +42 -0
- package/dist/commands/rewards.d.ts +2 -0
- package/dist/commands/rewards.js +61 -0
- package/dist/commands/spend.d.ts +2 -0
- package/dist/commands/spend.js +116 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +52 -0
- package/dist/lib/api-client.d.ts +23 -0
- package/dist/lib/api-client.js +113 -0
- package/dist/lib/config.d.ts +16 -0
- package/dist/lib/config.js +40 -0
- package/dist/lib/output.d.ts +20 -0
- package/dist/lib/output.js +69 -0
- package/dist/lib/update-check.d.ts +1 -0
- package/dist/lib/update-check.js +74 -0
- package/dist/mcp-server.d.ts +2 -0
- package/dist/mcp-server.js +133 -0
- package/dist/shared/alert.d.ts +24 -0
- package/dist/shared/alert.js +2 -0
- package/dist/shared/alerts.d.ts +3 -0
- package/dist/shared/alerts.js +103 -0
- package/dist/shared/card.d.ts +12 -0
- package/dist/shared/card.js +2 -0
- package/dist/shared/cards.d.ts +2 -0
- package/dist/shared/cards.js +60 -0
- package/dist/shared/common.d.ts +21 -0
- package/dist/shared/common.js +2 -0
- package/dist/shared/filters.d.ts +8 -0
- package/dist/shared/filters.js +59 -0
- package/dist/shared/formatters.d.ts +7 -0
- package/dist/shared/formatters.js +44 -0
- package/dist/shared/index.d.ts +15 -0
- package/dist/shared/index.js +43 -0
- package/dist/shared/project.d.ts +24 -0
- package/dist/shared/project.js +2 -0
- package/dist/shared/projects.d.ts +3 -0
- package/dist/shared/projects.js +104 -0
- package/dist/shared/reward.d.ts +26 -0
- package/dist/shared/reward.js +2 -0
- package/dist/shared/rewards.d.ts +4 -0
- package/dist/shared/rewards.js +25 -0
- package/dist/shared/transaction.d.ts +36 -0
- package/dist/shared/transaction.js +2 -0
- package/dist/shared/transactions.d.ts +2 -0
- package/dist/shared/transactions.js +34 -0
- package/dist/shared/user.d.ts +12 -0
- package/dist/shared/user.js +2 -0
- package/dist/shared/users.d.ts +3 -0
- package/dist/shared/users.js +15 -0
- package/package.json +41 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.spendCommand = void 0;
|
|
40
|
+
const commander_1 = require("commander");
|
|
41
|
+
const ora_1 = __importDefault(require("ora"));
|
|
42
|
+
const config_1 = require("../lib/config");
|
|
43
|
+
const api_client_1 = require("../lib/api-client");
|
|
44
|
+
const output_1 = require("../lib/output");
|
|
45
|
+
const shared_1 = require("../shared");
|
|
46
|
+
const categoryColors = {
|
|
47
|
+
"ai-apis": output_1.accent,
|
|
48
|
+
"cloud-infra": output_1.blue,
|
|
49
|
+
"dev-tools": output_1.purple,
|
|
50
|
+
"other": output_1.orange,
|
|
51
|
+
};
|
|
52
|
+
const categoryLabels = {
|
|
53
|
+
"ai-apis": "AI Model APIs",
|
|
54
|
+
"cloud-infra": "Cloud & Infra",
|
|
55
|
+
"dev-tools": "Dev Tools",
|
|
56
|
+
"other": "Other",
|
|
57
|
+
};
|
|
58
|
+
exports.spendCommand = new commander_1.Command("spend")
|
|
59
|
+
.description("View spend breakdown")
|
|
60
|
+
.option("-p, --project <name>", "Filter by project name")
|
|
61
|
+
.option("--json", "Output as JSON")
|
|
62
|
+
.action(async (opts) => {
|
|
63
|
+
if (!(0, config_1.isAuthenticated)()) {
|
|
64
|
+
(0, output_1.printError)("Not authenticated. Run " + (0, output_1.accent)("code auth login") + " first.");
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const spinner = (0, ora_1.default)({ text: "Fetching spend data...", color: "green" }).start();
|
|
68
|
+
// If project filter, need to resolve name -> id
|
|
69
|
+
let projectId;
|
|
70
|
+
if (opts.project) {
|
|
71
|
+
const { mockProjects } = await Promise.resolve().then(() => __importStar(require("../shared")));
|
|
72
|
+
const proj = mockProjects.find((p) => p.name === opts.project);
|
|
73
|
+
if (proj)
|
|
74
|
+
projectId = proj.id;
|
|
75
|
+
}
|
|
76
|
+
const breakdown = await (0, api_client_1.getSpendBreakdown)(projectId);
|
|
77
|
+
spinner.stop();
|
|
78
|
+
if (opts.json) {
|
|
79
|
+
(0, output_1.printJson)(breakdown);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const title = opts.project ? `Spend — ${opts.project}` : "Spend Overview";
|
|
83
|
+
(0, output_1.printHeader)(title);
|
|
84
|
+
console.log();
|
|
85
|
+
console.log((0, output_1.muted)(" Total spend ") + (0, output_1.accent)((0, shared_1.currency)(breakdown.totalSpend)));
|
|
86
|
+
console.log();
|
|
87
|
+
// By category
|
|
88
|
+
console.log((0, output_1.dim)(" By Category"));
|
|
89
|
+
const catTable = (0, output_1.createTable)(["Category", "Amount", "%"]);
|
|
90
|
+
for (const c of breakdown.byCategory) {
|
|
91
|
+
const colorFn = categoryColors[c.category] || output_1.muted;
|
|
92
|
+
catTable.push([
|
|
93
|
+
colorFn(categoryLabels[c.category] || c.category),
|
|
94
|
+
(0, shared_1.currency)(c.amount),
|
|
95
|
+
(0, output_1.dim)(c.percentage.toFixed(1) + "%"),
|
|
96
|
+
]);
|
|
97
|
+
}
|
|
98
|
+
console.log(catTable.toString());
|
|
99
|
+
// By provider
|
|
100
|
+
console.log((0, output_1.dim)(" By Provider"));
|
|
101
|
+
const provTable = (0, output_1.createTable)(["Provider", "Amount", "%"]);
|
|
102
|
+
for (const p of breakdown.byProvider.slice(0, 8)) {
|
|
103
|
+
provTable.push([(0, output_1.muted)(p.provider), (0, shared_1.currency)(p.amount), (0, output_1.dim)(p.percentage.toFixed(1) + "%")]);
|
|
104
|
+
}
|
|
105
|
+
console.log(provTable.toString());
|
|
106
|
+
// By project (only if no project filter)
|
|
107
|
+
if (!opts.project && breakdown.byProject.length > 1) {
|
|
108
|
+
console.log((0, output_1.dim)(" By Project"));
|
|
109
|
+
const projTable = (0, output_1.createTable)(["Project", "Amount"]);
|
|
110
|
+
for (const p of breakdown.byProject) {
|
|
111
|
+
projTable.push([(0, output_1.accent)(p.projectName), (0, shared_1.currency)(p.amount)]);
|
|
112
|
+
}
|
|
113
|
+
console.log(projTable.toString());
|
|
114
|
+
}
|
|
115
|
+
console.log();
|
|
116
|
+
});
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const login_1 = require("./commands/auth/login");
|
|
6
|
+
const logout_1 = require("./commands/auth/logout");
|
|
7
|
+
const whoami_1 = require("./commands/auth/whoami");
|
|
8
|
+
const create_1 = require("./commands/project/create");
|
|
9
|
+
const list_1 = require("./commands/project/list");
|
|
10
|
+
const list_2 = require("./commands/card/list");
|
|
11
|
+
const freeze_1 = require("./commands/card/freeze");
|
|
12
|
+
const spend_1 = require("./commands/spend");
|
|
13
|
+
const balance_1 = require("./commands/balance");
|
|
14
|
+
const rewards_1 = require("./commands/rewards");
|
|
15
|
+
const alerts_1 = require("./commands/alerts");
|
|
16
|
+
const pnl_1 = require("./commands/pnl");
|
|
17
|
+
const update_check_1 = require("./lib/update-check");
|
|
18
|
+
const program = new commander_1.Command();
|
|
19
|
+
program
|
|
20
|
+
.name("codecard")
|
|
21
|
+
.description("code_ — The financial stack for AI-native builders")
|
|
22
|
+
.version("0.1.0");
|
|
23
|
+
// Auth commands
|
|
24
|
+
const auth = program.command("auth").description("Authentication");
|
|
25
|
+
auth.addCommand(login_1.loginCommand);
|
|
26
|
+
auth.addCommand(logout_1.logoutCommand);
|
|
27
|
+
auth.addCommand(whoami_1.whoamiCommand);
|
|
28
|
+
// Project commands
|
|
29
|
+
const project = program.command("project").description("Project management");
|
|
30
|
+
project.addCommand(create_1.projectCreateCommand);
|
|
31
|
+
project.addCommand(list_1.projectListCommand);
|
|
32
|
+
// Card commands
|
|
33
|
+
const card = program.command("card").description("Virtual card management");
|
|
34
|
+
card.addCommand(list_2.cardListCommand);
|
|
35
|
+
card.addCommand(freeze_1.cardFreezeCommand);
|
|
36
|
+
card.addCommand(freeze_1.cardUnfreezeCommand);
|
|
37
|
+
// Top-level commands
|
|
38
|
+
program.addCommand(spend_1.spendCommand);
|
|
39
|
+
program.addCommand(balance_1.balanceCommand);
|
|
40
|
+
program.addCommand(rewards_1.rewardsCommand);
|
|
41
|
+
program.addCommand(alerts_1.alertsCommand);
|
|
42
|
+
program.addCommand(pnl_1.pnlCommand);
|
|
43
|
+
// MCP server command
|
|
44
|
+
program
|
|
45
|
+
.command("mcp")
|
|
46
|
+
.description("Start MCP server for AI agent integration (stdio transport)")
|
|
47
|
+
.action(() => {
|
|
48
|
+
require("./mcp-server");
|
|
49
|
+
});
|
|
50
|
+
// Check for updates in background (non-blocking)
|
|
51
|
+
(0, update_check_1.checkForUpdate)("0.1.0");
|
|
52
|
+
program.parse();
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Project, VirtualCard, ProjectPnl, SpendBreakdown, RewardBalance, RewardTier, RewardHistory, AlertRule, AlertEvent } from "../shared";
|
|
2
|
+
export declare function getProjects(): Promise<Project[]>;
|
|
3
|
+
export declare function getProjectPnl(projectId: string): Promise<ProjectPnl | null>;
|
|
4
|
+
export declare function createProject(name: string, description: string, budget: number): Promise<Project>;
|
|
5
|
+
export declare function getCards(): Promise<VirtualCard[]>;
|
|
6
|
+
export declare function freezeCard(cardId: string): Promise<VirtualCard | null>;
|
|
7
|
+
export declare function unfreezeCard(cardId: string): Promise<VirtualCard | null>;
|
|
8
|
+
export declare function getSpendBreakdown(projectId?: string): Promise<SpendBreakdown>;
|
|
9
|
+
export declare function getBalance(): Promise<{
|
|
10
|
+
available: number;
|
|
11
|
+
pending: number;
|
|
12
|
+
creditLimit: number;
|
|
13
|
+
creditUsed: number;
|
|
14
|
+
}>;
|
|
15
|
+
export declare function getRewards(): Promise<{
|
|
16
|
+
balance: RewardBalance;
|
|
17
|
+
tiers: RewardTier[];
|
|
18
|
+
history: RewardHistory[];
|
|
19
|
+
}>;
|
|
20
|
+
export declare function getAlerts(): Promise<{
|
|
21
|
+
rules: AlertRule[];
|
|
22
|
+
events: AlertEvent[];
|
|
23
|
+
}>;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getProjects = getProjects;
|
|
4
|
+
exports.getProjectPnl = getProjectPnl;
|
|
5
|
+
exports.createProject = createProject;
|
|
6
|
+
exports.getCards = getCards;
|
|
7
|
+
exports.freezeCard = freezeCard;
|
|
8
|
+
exports.unfreezeCard = unfreezeCard;
|
|
9
|
+
exports.getSpendBreakdown = getSpendBreakdown;
|
|
10
|
+
exports.getBalance = getBalance;
|
|
11
|
+
exports.getRewards = getRewards;
|
|
12
|
+
exports.getAlerts = getAlerts;
|
|
13
|
+
const shared_1 = require("../shared");
|
|
14
|
+
const output_1 = require("./output");
|
|
15
|
+
// Mutable copies for mutations within session
|
|
16
|
+
const projects = [...shared_1.mockProjects];
|
|
17
|
+
const cards = [...shared_1.mockCards.map((c) => ({ ...c }))];
|
|
18
|
+
async function fakeLatency() {
|
|
19
|
+
await (0, output_1.delay)(200 + Math.random() * 400);
|
|
20
|
+
}
|
|
21
|
+
// Projects
|
|
22
|
+
async function getProjects() {
|
|
23
|
+
await fakeLatency();
|
|
24
|
+
return projects;
|
|
25
|
+
}
|
|
26
|
+
async function getProjectPnl(projectId) {
|
|
27
|
+
await fakeLatency();
|
|
28
|
+
return shared_1.mockProjectPnls.find((p) => p.projectId === projectId) || null;
|
|
29
|
+
}
|
|
30
|
+
async function createProject(name, description, budget) {
|
|
31
|
+
await fakeLatency();
|
|
32
|
+
const id = `proj_${String(projects.length + 1).padStart(3, "0")}`;
|
|
33
|
+
const cardId = `card_${String(cards.length + 1).padStart(3, "0")}`;
|
|
34
|
+
const last4 = String(Math.floor(1000 + Math.random() * 9000));
|
|
35
|
+
const colors = ["#b8f036", "#5b8cff", "#a07cff", "#3ee8c8", "#ff5f8f", "#ffa044"];
|
|
36
|
+
const project = {
|
|
37
|
+
id,
|
|
38
|
+
name,
|
|
39
|
+
description,
|
|
40
|
+
status: "active",
|
|
41
|
+
color: colors[projects.length % colors.length],
|
|
42
|
+
cardId,
|
|
43
|
+
monthlyBudget: budget,
|
|
44
|
+
createdAt: new Date().toISOString(),
|
|
45
|
+
};
|
|
46
|
+
const card = {
|
|
47
|
+
id: cardId,
|
|
48
|
+
projectId: id,
|
|
49
|
+
last4,
|
|
50
|
+
cardHolder: "SARAH CHEN",
|
|
51
|
+
status: "active",
|
|
52
|
+
dailyLimit: Math.round(budget / 10),
|
|
53
|
+
monthlyLimit: budget,
|
|
54
|
+
currentMonthSpend: 0,
|
|
55
|
+
createdAt: new Date().toISOString(),
|
|
56
|
+
};
|
|
57
|
+
projects.push(project);
|
|
58
|
+
cards.push(card);
|
|
59
|
+
return project;
|
|
60
|
+
}
|
|
61
|
+
// Cards
|
|
62
|
+
async function getCards() {
|
|
63
|
+
await fakeLatency();
|
|
64
|
+
return cards;
|
|
65
|
+
}
|
|
66
|
+
async function freezeCard(cardId) {
|
|
67
|
+
await fakeLatency();
|
|
68
|
+
const card = cards.find((c) => c.id === cardId);
|
|
69
|
+
if (!card)
|
|
70
|
+
return null;
|
|
71
|
+
card.status = "frozen";
|
|
72
|
+
return card;
|
|
73
|
+
}
|
|
74
|
+
async function unfreezeCard(cardId) {
|
|
75
|
+
await fakeLatency();
|
|
76
|
+
const card = cards.find((c) => c.id === cardId);
|
|
77
|
+
if (!card)
|
|
78
|
+
return null;
|
|
79
|
+
card.status = "active";
|
|
80
|
+
return card;
|
|
81
|
+
}
|
|
82
|
+
// Spend
|
|
83
|
+
async function getSpendBreakdown(projectId) {
|
|
84
|
+
await fakeLatency();
|
|
85
|
+
const txns = projectId
|
|
86
|
+
? shared_1.mockTransactions.filter((t) => t.projectId === projectId)
|
|
87
|
+
: shared_1.mockTransactions;
|
|
88
|
+
return (0, shared_1.buildSpendBreakdown)(txns, projects);
|
|
89
|
+
}
|
|
90
|
+
// Balance
|
|
91
|
+
async function getBalance() {
|
|
92
|
+
await fakeLatency();
|
|
93
|
+
return {
|
|
94
|
+
available: 12400,
|
|
95
|
+
pending: 340,
|
|
96
|
+
creditLimit: 25000,
|
|
97
|
+
creditUsed: 7890,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
// Rewards
|
|
101
|
+
async function getRewards() {
|
|
102
|
+
await fakeLatency();
|
|
103
|
+
return {
|
|
104
|
+
balance: shared_1.mockRewardBalance,
|
|
105
|
+
tiers: shared_1.mockRewardTiers,
|
|
106
|
+
history: shared_1.mockRewardHistory,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
// Alerts
|
|
110
|
+
async function getAlerts() {
|
|
111
|
+
await fakeLatency();
|
|
112
|
+
return { rules: shared_1.mockAlertRules, events: shared_1.mockAlertEvents };
|
|
113
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import Conf from "conf";
|
|
2
|
+
interface ConfigSchema {
|
|
3
|
+
token: string | null;
|
|
4
|
+
email: string | null;
|
|
5
|
+
name: string | null;
|
|
6
|
+
}
|
|
7
|
+
declare const config: Conf<ConfigSchema>;
|
|
8
|
+
export declare function isAuthenticated(): boolean;
|
|
9
|
+
export declare function getAuth(): {
|
|
10
|
+
email: string;
|
|
11
|
+
name: string;
|
|
12
|
+
token: string;
|
|
13
|
+
} | null;
|
|
14
|
+
export declare function setAuth(email: string, name: string, token: string): void;
|
|
15
|
+
export declare function clearAuth(): void;
|
|
16
|
+
export default config;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isAuthenticated = isAuthenticated;
|
|
7
|
+
exports.getAuth = getAuth;
|
|
8
|
+
exports.setAuth = setAuth;
|
|
9
|
+
exports.clearAuth = clearAuth;
|
|
10
|
+
const conf_1 = __importDefault(require("conf"));
|
|
11
|
+
const config = new conf_1.default({
|
|
12
|
+
projectName: "codecard-cli",
|
|
13
|
+
defaults: {
|
|
14
|
+
token: null,
|
|
15
|
+
email: null,
|
|
16
|
+
name: null,
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
function isAuthenticated() {
|
|
20
|
+
return config.get("token") !== null;
|
|
21
|
+
}
|
|
22
|
+
function getAuth() {
|
|
23
|
+
const token = config.get("token");
|
|
24
|
+
const email = config.get("email");
|
|
25
|
+
const name = config.get("name");
|
|
26
|
+
if (!token || !email || !name)
|
|
27
|
+
return null;
|
|
28
|
+
return { token, email, name };
|
|
29
|
+
}
|
|
30
|
+
function setAuth(email, name, token) {
|
|
31
|
+
config.set("token", token);
|
|
32
|
+
config.set("email", email);
|
|
33
|
+
config.set("name", name);
|
|
34
|
+
}
|
|
35
|
+
function clearAuth() {
|
|
36
|
+
config.set("token", null);
|
|
37
|
+
config.set("email", null);
|
|
38
|
+
config.set("name", null);
|
|
39
|
+
}
|
|
40
|
+
exports.default = config;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import Table from "cli-table3";
|
|
3
|
+
export declare const accent: chalk.Chalk;
|
|
4
|
+
export declare const muted: chalk.Chalk;
|
|
5
|
+
export declare const dim: chalk.Chalk;
|
|
6
|
+
export declare const pink: chalk.Chalk;
|
|
7
|
+
export declare const blue: chalk.Chalk;
|
|
8
|
+
export declare const purple: chalk.Chalk;
|
|
9
|
+
export declare const cyan: chalk.Chalk;
|
|
10
|
+
export declare const orange: chalk.Chalk;
|
|
11
|
+
export declare function printHeader(text: string): void;
|
|
12
|
+
export declare function printSuccess(text: string): void;
|
|
13
|
+
export declare function printError(text: string): void;
|
|
14
|
+
export declare function printWarning(text: string): void;
|
|
15
|
+
export declare function printInfo(text: string): void;
|
|
16
|
+
export declare function printRow(label: string, value: string): void;
|
|
17
|
+
export declare function createTable(headers: string[]): Table.Table;
|
|
18
|
+
export declare function printJson(data: unknown): void;
|
|
19
|
+
export declare function printJsonError(error: string): void;
|
|
20
|
+
export declare function delay(ms: number): Promise<void>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.orange = exports.cyan = exports.purple = exports.blue = exports.pink = exports.dim = exports.muted = exports.accent = void 0;
|
|
7
|
+
exports.printHeader = printHeader;
|
|
8
|
+
exports.printSuccess = printSuccess;
|
|
9
|
+
exports.printError = printError;
|
|
10
|
+
exports.printWarning = printWarning;
|
|
11
|
+
exports.printInfo = printInfo;
|
|
12
|
+
exports.printRow = printRow;
|
|
13
|
+
exports.createTable = createTable;
|
|
14
|
+
exports.printJson = printJson;
|
|
15
|
+
exports.printJsonError = printJsonError;
|
|
16
|
+
exports.delay = delay;
|
|
17
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
18
|
+
const cli_table3_1 = __importDefault(require("cli-table3"));
|
|
19
|
+
exports.accent = chalk_1.default.hex("#b8f036");
|
|
20
|
+
exports.muted = chalk_1.default.hex("#9490a8");
|
|
21
|
+
exports.dim = chalk_1.default.hex("#5e5a72");
|
|
22
|
+
exports.pink = chalk_1.default.hex("#ff5f8f");
|
|
23
|
+
exports.blue = chalk_1.default.hex("#5b8cff");
|
|
24
|
+
exports.purple = chalk_1.default.hex("#a07cff");
|
|
25
|
+
exports.cyan = chalk_1.default.hex("#3ee8c8");
|
|
26
|
+
exports.orange = chalk_1.default.hex("#ffa044");
|
|
27
|
+
function printHeader(text) {
|
|
28
|
+
console.log();
|
|
29
|
+
console.log(exports.accent.bold(" code_") + (0, exports.dim)(" │ ") + chalk_1.default.white(text));
|
|
30
|
+
console.log((0, exports.dim)(" " + "─".repeat(50)));
|
|
31
|
+
}
|
|
32
|
+
function printSuccess(text) {
|
|
33
|
+
console.log((0, exports.accent)(" ✓ ") + text);
|
|
34
|
+
}
|
|
35
|
+
function printError(text) {
|
|
36
|
+
console.log((0, exports.pink)(" ✗ ") + text);
|
|
37
|
+
process.exitCode = 1;
|
|
38
|
+
}
|
|
39
|
+
function printWarning(text) {
|
|
40
|
+
console.log((0, exports.orange)(" ⚠ ") + text);
|
|
41
|
+
}
|
|
42
|
+
function printInfo(text) {
|
|
43
|
+
console.log((0, exports.blue)(" ℹ ") + text);
|
|
44
|
+
}
|
|
45
|
+
function printRow(label, value) {
|
|
46
|
+
console.log((0, exports.muted)(" " + label.padEnd(22)) + chalk_1.default.white(value));
|
|
47
|
+
}
|
|
48
|
+
function createTable(headers) {
|
|
49
|
+
return new cli_table3_1.default({
|
|
50
|
+
head: headers.map((h) => (0, exports.dim)(h)),
|
|
51
|
+
chars: {
|
|
52
|
+
top: "", "top-mid": "", "top-left": "", "top-right": "",
|
|
53
|
+
bottom: "", "bottom-mid": "", "bottom-left": "", "bottom-right": "",
|
|
54
|
+
left: " ", "left-mid": "", mid: "─", "mid-mid": "─",
|
|
55
|
+
right: "", "right-mid": "", middle: (0, exports.dim)(" │ "),
|
|
56
|
+
},
|
|
57
|
+
style: { "padding-left": 1, "padding-right": 1, head: [], border: [] },
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function printJson(data) {
|
|
61
|
+
console.log(JSON.stringify(data, null, 2));
|
|
62
|
+
}
|
|
63
|
+
function printJsonError(error) {
|
|
64
|
+
console.log(JSON.stringify({ success: false, error }, null, 2));
|
|
65
|
+
process.exitCode = 1;
|
|
66
|
+
}
|
|
67
|
+
function delay(ms) {
|
|
68
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
69
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function checkForUpdate(currentVersion: string): Promise<void>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.checkForUpdate = checkForUpdate;
|
|
40
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
41
|
+
const output_1 = require("./output");
|
|
42
|
+
const PACKAGE_NAME = "codecard-cli";
|
|
43
|
+
const CHECK_INTERVAL = 24 * 60 * 60 * 1000; // 24 hours
|
|
44
|
+
async function checkForUpdate(currentVersion) {
|
|
45
|
+
try {
|
|
46
|
+
// Check if we should check (throttle to once per day)
|
|
47
|
+
const Conf = (await Promise.resolve().then(() => __importStar(require("conf")))).default;
|
|
48
|
+
const config = new Conf({ projectName: "codecard-cli-update" });
|
|
49
|
+
const lastCheck = config.get("lastUpdateCheck", 0);
|
|
50
|
+
if (Date.now() - lastCheck < CHECK_INTERVAL)
|
|
51
|
+
return;
|
|
52
|
+
config.set("lastUpdateCheck", Date.now());
|
|
53
|
+
// Fetch latest version from npm
|
|
54
|
+
const controller = new AbortController();
|
|
55
|
+
const timeout = setTimeout(() => controller.abort(), 3000);
|
|
56
|
+
const res = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}/latest`, { signal: controller.signal });
|
|
57
|
+
clearTimeout(timeout);
|
|
58
|
+
if (!res.ok)
|
|
59
|
+
return;
|
|
60
|
+
const data = (await res.json());
|
|
61
|
+
const latest = data.version;
|
|
62
|
+
if (latest && latest !== currentVersion) {
|
|
63
|
+
console.log();
|
|
64
|
+
console.log((0, output_1.dim)(" ┌─────────────────────────────────────────┐"));
|
|
65
|
+
console.log((0, output_1.dim)(" │") + " Update available: " + (0, output_1.dim)(currentVersion) + " → " + (0, output_1.accent)(latest) + (0, output_1.dim)(" │"));
|
|
66
|
+
console.log((0, output_1.dim)(" │") + " Run " + chalk_1.default.white(`npm i -g ${PACKAGE_NAME}`) + " to update" + (0, output_1.dim)(" │"));
|
|
67
|
+
console.log((0, output_1.dim)(" └���────────────────────────────────────────┘"));
|
|
68
|
+
console.log();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// Silently fail — never block the CLI for update checks
|
|
73
|
+
}
|
|
74
|
+
}
|