@optima-chat/dev-skills 0.7.29 ā 0.7.32
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/.claude/commands/trace-user.md +293 -0
- package/.claude/skills/grant-balance/SKILL.md +102 -0
- package/.claude/skills/grant-subscription/SKILL.md +16 -14
- package/.claude/skills/query-db/SKILL.md +4 -2
- package/.codex/skills/grant-balance/SKILL.md +101 -0
- package/.codex/skills/grant-subscription/SKILL.md +1 -1
- package/AGENTS.md +2 -2
- package/bin/cli.js +2 -2
- package/bin/helpers/grant-balance.ts +95 -0
- package/bin/helpers/grant-subscription.ts +17 -12
- package/bin/helpers/query-db.ts +6 -1
- package/dist/bin/helpers/generate-test-token.js +0 -0
- package/dist/bin/helpers/grant-balance.js +91 -0
- package/dist/bin/helpers/grant-subscription.js +17 -12
- package/dist/bin/helpers/query-db.js +6 -1
- package/dist/bin/helpers/show-env.js +0 -0
- package/package.json +2 -2
- package/.claude/settings.local.json +0 -51
- package/.claude/skills/grant-credits/SKILL.md +0 -105
- package/.codex/skills/grant-credits/SKILL.md +0 -28
- package/bin/helpers/grant-credits.ts +0 -65
- package/dist/bin/helpers/grant-credits.js +0 -71
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const db_utils_1 = require("./db-utils");
|
|
5
|
-
function parseArgs(args) {
|
|
6
|
-
if (args.length === 0 || args[0] === '--help' || args[0] === '-h') {
|
|
7
|
-
console.log(`Usage: optima-grant-credits <email> --amount <n> [options]
|
|
8
|
-
|
|
9
|
-
Options:
|
|
10
|
-
--amount <n> Credits to grant (required)
|
|
11
|
-
--type <type> Credit type: bonus, referral (default: bonus)
|
|
12
|
-
--description <text> Description (optional)
|
|
13
|
-
--env <env> Environment: stage, prod (default: stage)
|
|
14
|
-
-h, --help Show this help`);
|
|
15
|
-
process.exit(0);
|
|
16
|
-
}
|
|
17
|
-
const email = args[0];
|
|
18
|
-
let amount = 0;
|
|
19
|
-
let type = 'bonus';
|
|
20
|
-
let description = null;
|
|
21
|
-
let env = 'stage';
|
|
22
|
-
for (let i = 1; i < args.length; i++) {
|
|
23
|
-
if (args[i] === '--amount' && args[i + 1]) {
|
|
24
|
-
amount = parseInt(args[++i], 10);
|
|
25
|
-
}
|
|
26
|
-
else if (args[i] === '--type' && args[i + 1]) {
|
|
27
|
-
type = args[++i];
|
|
28
|
-
}
|
|
29
|
-
else if (args[i] === '--description' && args[i + 1]) {
|
|
30
|
-
description = args[++i];
|
|
31
|
-
}
|
|
32
|
-
else if (args[i] === '--env' && args[i + 1]) {
|
|
33
|
-
env = args[++i];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
if (amount < 1) {
|
|
37
|
-
console.error('--amount is required and must be >= 1');
|
|
38
|
-
process.exit(1);
|
|
39
|
-
}
|
|
40
|
-
if (!['bonus', 'referral'].includes(type)) {
|
|
41
|
-
console.error(`Unknown type: ${type}. Available: bonus, referral`);
|
|
42
|
-
process.exit(1);
|
|
43
|
-
}
|
|
44
|
-
if (!['stage', 'prod'].includes(env)) {
|
|
45
|
-
console.error('Env must be stage or prod (billing DB not available in CI)');
|
|
46
|
-
process.exit(1);
|
|
47
|
-
}
|
|
48
|
-
return { email, amount, type, description, env };
|
|
49
|
-
}
|
|
50
|
-
async function main() {
|
|
51
|
-
const { email, amount, type, description, env } = parseArgs(process.argv.slice(2));
|
|
52
|
-
const infisicalConfig = (0, db_utils_1.getInfisicalConfig)();
|
|
53
|
-
const token = (0, db_utils_1.getInfisicalToken)(infisicalConfig);
|
|
54
|
-
console.log(`\nš Granting ${amount} ${type} credits to ${email} [${env.toUpperCase()}]\n`);
|
|
55
|
-
const userId = await (0, db_utils_1.resolveUserId)(email, env, infisicalConfig, token);
|
|
56
|
-
const billing = await (0, db_utils_1.connectBillingDB)(env, infisicalConfig, token);
|
|
57
|
-
const bq = billing.query;
|
|
58
|
-
const now = new Date().toISOString();
|
|
59
|
-
const safeUserId = (0, db_utils_1.escapeSQL)(userId);
|
|
60
|
-
const safeType = (0, db_utils_1.escapeSQL)(type);
|
|
61
|
-
const safeDesc = (0, db_utils_1.escapeSQL)(description || `Admin ${type} credit grant`);
|
|
62
|
-
console.log(`Inserting ${amount} ${type} credits...`);
|
|
63
|
-
const ledgerId = bq(`INSERT INTO credit_ledger (id, user_id, type, description, initial_amount, remaining, created_at) VALUES (concat('crd_${safeType}_', substr(md5(random()::text), 1, 16)), '${safeUserId}', '${safeType}', '${safeDesc}', ${amount}, ${amount}, '${now}') RETURNING id`);
|
|
64
|
-
console.log(`ā Credits granted (ledger ID: ${ledgerId})`);
|
|
65
|
-
const balance = bq(`SELECT COALESCE(SUM(remaining), 0) FROM credit_ledger WHERE user_id='${safeUserId}' AND remaining > 0 AND (expires_at IS NULL OR expires_at > NOW())`);
|
|
66
|
-
console.log(`\nā
Done! ${email} now has ${balance} total credits\n`);
|
|
67
|
-
}
|
|
68
|
-
main().catch(error => {
|
|
69
|
-
console.error('\nā Error:', error.message);
|
|
70
|
-
process.exit(1);
|
|
71
|
-
});
|