@upshiftfinance/cli 0.0.0-stage → 0.1.2

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.
Files changed (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +185 -2
  3. package/lib/bin.d.ts +2 -0
  4. package/lib/bin.js +19 -0
  5. package/lib/commands/chain.d.ts +2 -0
  6. package/lib/commands/chain.js +42 -0
  7. package/lib/commands/config.d.ts +2 -0
  8. package/lib/commands/config.js +107 -0
  9. package/lib/commands/docs.d.ts +2 -0
  10. package/lib/commands/docs.js +407 -0
  11. package/lib/commands/init.d.ts +2 -0
  12. package/lib/commands/init.js +124 -0
  13. package/lib/commands/login.d.ts +2 -0
  14. package/lib/commands/login.js +57 -0
  15. package/lib/commands/ops.d.ts +2 -0
  16. package/lib/commands/ops.js +149 -0
  17. package/lib/commands/points.d.ts +2 -0
  18. package/lib/commands/points.js +52 -0
  19. package/lib/commands/profile.d.ts +2 -0
  20. package/lib/commands/profile.js +82 -0
  21. package/lib/commands/rpc.d.ts +11 -0
  22. package/lib/commands/rpc.js +93 -0
  23. package/lib/commands/skill.d.ts +2 -0
  24. package/lib/commands/skill.js +83 -0
  25. package/lib/commands/user.d.ts +2 -0
  26. package/lib/commands/user.js +93 -0
  27. package/lib/commands/vault.d.ts +2 -0
  28. package/lib/commands/vault.js +326 -0
  29. package/lib/commands/whoami.d.ts +2 -0
  30. package/lib/commands/whoami.js +45 -0
  31. package/lib/index.d.ts +2 -0
  32. package/lib/index.js +9 -0
  33. package/lib/lib/flags.d.ts +14 -0
  34. package/lib/lib/flags.js +46 -0
  35. package/lib/lib/output.d.ts +7 -0
  36. package/lib/lib/output.js +218 -0
  37. package/lib/lib/prompts.d.ts +24 -0
  38. package/lib/lib/prompts.js +51 -0
  39. package/lib/lib/resolve-vault.d.ts +10 -0
  40. package/lib/lib/resolve-vault.js +137 -0
  41. package/lib/lib/version.d.ts +2 -0
  42. package/lib/lib/version.js +27 -0
  43. package/lib/lib/watch.d.ts +4 -0
  44. package/lib/lib/watch.js +38 -0
  45. package/lib/main.d.ts +3 -0
  46. package/lib/main.js +55 -0
  47. package/lib/notify-update.d.ts +1 -0
  48. package/lib/notify-update.js +38 -0
  49. package/package.json +66 -3
  50. package/skills/upshift.md +212 -0
@@ -0,0 +1,407 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerDocs = registerDocs;
4
+ const zod_1 = require("zod");
5
+ const flags_1 = require("../lib/flags");
6
+ const output_1 = require("../lib/output");
7
+ const DOC_SITES = {
8
+ august: 'https://docs.augustdigital.io',
9
+ upshift: 'https://docs.upshift.finance',
10
+ };
11
+ const DOC_INDEX = [
12
+ {
13
+ site: 'august',
14
+ path: '/',
15
+ title: 'Upshift Institutional Overview',
16
+ keywords: ['overview', 'introduction', 'getting started', 'august'],
17
+ },
18
+ {
19
+ site: 'august',
20
+ path: '/protocol-overview',
21
+ title: 'Protocol Overview',
22
+ keywords: [
23
+ 'protocol',
24
+ 'overview',
25
+ 'architecture',
26
+ 'loans',
27
+ 'lending',
28
+ 'pools',
29
+ 'subaccounts',
30
+ 'risk engine',
31
+ ],
32
+ },
33
+ {
34
+ site: 'august',
35
+ path: '/using-august/twap',
36
+ title: 'TWAP',
37
+ keywords: ['twap', 'time-weighted', 'trading'],
38
+ },
39
+ {
40
+ site: 'august',
41
+ path: '/smart-contracts/risks-and-audits',
42
+ title: 'Risks and Audits',
43
+ keywords: ['risks', 'audits', 'security', 'smart contracts'],
44
+ },
45
+ {
46
+ site: 'august',
47
+ path: '/smart-contracts/contract-addresses',
48
+ title: 'Contract Addresses',
49
+ keywords: ['contract', 'addresses', 'deployed', 'onchain'],
50
+ },
51
+ {
52
+ site: 'august',
53
+ path: '/developers/api-reference',
54
+ title: 'API Reference',
55
+ keywords: ['api', 'reference', 'rest', 'http', 'endpoint'],
56
+ },
57
+ {
58
+ site: 'august',
59
+ path: '/developers/typescript-sdk',
60
+ title: 'TypeScript SDK Overview',
61
+ keywords: ['typescript', 'sdk', 'javascript', 'npm', 'install'],
62
+ },
63
+ {
64
+ site: 'august',
65
+ path: '/developers/javascript-sdk',
66
+ title: 'JavaScript SDK',
67
+ keywords: ['javascript', 'sdk', 'browser', 'node'],
68
+ },
69
+ {
70
+ site: 'august',
71
+ path: '/developers/code-examples',
72
+ title: 'Code Examples',
73
+ keywords: ['examples', 'code', 'tutorial', 'quickstart'],
74
+ },
75
+ {
76
+ site: 'august',
77
+ path: '/developers/code-examples/evm-actions',
78
+ title: 'EVM Actions',
79
+ keywords: ['evm', 'deposit', 'withdraw', 'approve', 'actions'],
80
+ },
81
+ {
82
+ site: 'august',
83
+ path: '/developers/code-examples/solana-actions',
84
+ title: 'Solana Actions',
85
+ keywords: ['solana', 'deposit', 'withdraw', 'actions'],
86
+ },
87
+ {
88
+ site: 'august',
89
+ path: '/developers/code-examples/stellar-actions',
90
+ title: 'Stellar Actions',
91
+ keywords: ['stellar', 'deposit', 'withdraw', 'soroban'],
92
+ },
93
+ {
94
+ site: 'august',
95
+ path: '/developers/changelog',
96
+ title: 'SDK Changelog',
97
+ keywords: ['changelog', 'updates', 'versions', 'release'],
98
+ },
99
+ {
100
+ site: 'august',
101
+ path: '/developers/cli',
102
+ title: 'CLI Reference',
103
+ keywords: ['cli', 'command', 'terminal', 'august'],
104
+ },
105
+ {
106
+ site: 'august',
107
+ path: '/developers/mcp',
108
+ title: 'MCP Server Reference',
109
+ keywords: ['mcp', 'model context protocol', 'claude', 'ai'],
110
+ },
111
+ {
112
+ site: 'upshift',
113
+ path: '/',
114
+ title: 'Upshift Overview',
115
+ keywords: ['overview', 'introduction', 'getting started', 'upshift'],
116
+ },
117
+ {
118
+ site: 'upshift',
119
+ path: '/faq',
120
+ title: 'FAQ',
121
+ keywords: ['faq', 'questions', 'help'],
122
+ },
123
+ {
124
+ site: 'upshift',
125
+ path: '/core-products/coreusdc-the-meta-vault',
126
+ title: 'coreUSDC Meta Vault',
127
+ keywords: ['coreusdc', 'usdc', 'meta vault', 'yield'],
128
+ },
129
+ {
130
+ site: 'upshift',
131
+ path: '/core-products/upusdc-institutional-lending',
132
+ title: 'upUSDC Institutional Lending',
133
+ keywords: ['upusdc', 'usdc', 'institutional', 'lending'],
134
+ },
135
+ {
136
+ site: 'upshift',
137
+ path: '/product-types/upshift-lend',
138
+ title: 'Upshift Lend',
139
+ keywords: ['lend', 'lending', 'product'],
140
+ },
141
+ {
142
+ site: 'upshift',
143
+ path: '/product-types/upshift-defi-yield',
144
+ title: 'DeFi Yield',
145
+ keywords: ['defi', 'yield', 'strategies'],
146
+ },
147
+ {
148
+ site: 'upshift',
149
+ path: '/product-types/upshift-vault-as-a-service-vaas',
150
+ title: 'Vault as a Service (VaaS)',
151
+ keywords: ['vaas', 'vault as a service', 'partner'],
152
+ },
153
+ {
154
+ site: 'upshift',
155
+ path: '/product-types/upshift-rwa-clear',
156
+ title: 'RWA Clear Overview',
157
+ keywords: ['rwa', 'real world assets', 'clear'],
158
+ },
159
+ {
160
+ site: 'upshift',
161
+ path: '/product-types/synergies-between-upshift-and-august-digital',
162
+ title: 'Upshift Synergies',
163
+ keywords: ['synergies', 'august', 'relationship'],
164
+ },
165
+ {
166
+ site: 'upshift',
167
+ path: '/upshift-vault-curation/upshift-for-curators',
168
+ title: 'Upshift for Curators',
169
+ keywords: ['curator', 'curation', 'vault manager'],
170
+ },
171
+ {
172
+ site: 'upshift',
173
+ path: '/upshift-vault-curation/accounting-fees-and-fund-flows',
174
+ title: 'Accounting, Fees & Fund Flows',
175
+ keywords: ['accounting', 'fees', 'fund flows', 'management fee'],
176
+ },
177
+ {
178
+ site: 'upshift',
179
+ path: '/upshift-vault-curation/risk-framework-and-emergency',
180
+ title: 'Risk Framework & Emergency',
181
+ keywords: ['risk', 'framework', 'emergency', 'guardian'],
182
+ },
183
+ {
184
+ site: 'upshift',
185
+ path: '/vault-architecture/vault-accounting-mechanics',
186
+ title: 'Vault Accounting Mechanics',
187
+ keywords: [
188
+ 'accounting',
189
+ 'mechanics',
190
+ 'shares',
191
+ 'nav',
192
+ 'yield',
193
+ 'exchange rate',
194
+ ],
195
+ },
196
+ {
197
+ site: 'upshift',
198
+ path: '/vault-architecture/single-asset-vaults',
199
+ title: 'Single Asset Vaults',
200
+ keywords: ['single asset', 'vault', 'architecture'],
201
+ },
202
+ {
203
+ site: 'upshift',
204
+ path: '/vault-architecture/multi-asset-vaults',
205
+ title: 'Multi Asset Vaults',
206
+ keywords: ['multi asset', 'vault', 'basket'],
207
+ },
208
+ {
209
+ site: 'upshift',
210
+ path: '/vault-architecture/risk-management-framework',
211
+ title: 'Risk Management Framework',
212
+ keywords: ['risk', 'management', 'framework'],
213
+ },
214
+ {
215
+ site: 'upshift',
216
+ path: '/vault-architecture/solana-vaults',
217
+ title: 'Solana Vaults',
218
+ keywords: ['solana', 'vault', 'spl'],
219
+ },
220
+ {
221
+ site: 'upshift',
222
+ path: '/vault-architecture/stellar-vaults',
223
+ title: 'Stellar Vaults',
224
+ keywords: ['stellar', 'vault', 'soroban'],
225
+ },
226
+ {
227
+ site: 'upshift',
228
+ path: '/vault-architecture/upshift-hypercore-relayer',
229
+ title: 'Hypercore Relayer',
230
+ keywords: ['hypercore', 'relayer', 'hyperliquid'],
231
+ },
232
+ {
233
+ site: 'upshift',
234
+ path: '/developer-docs/smart-contract-audits',
235
+ title: 'Smart Contract Audits',
236
+ keywords: ['audits', 'security', 'smart contracts'],
237
+ },
238
+ {
239
+ site: 'upshift',
240
+ path: '/developer-docs/api-reference',
241
+ title: 'API Reference',
242
+ keywords: ['api', 'reference', 'rest', 'endpoint'],
243
+ },
244
+ {
245
+ site: 'upshift',
246
+ path: '/developer-docs/api-reference/vaults',
247
+ title: 'API Reference — Vaults',
248
+ keywords: ['api', 'vaults', 'tvl', 'apy'],
249
+ },
250
+ {
251
+ site: 'upshift',
252
+ path: '/developer-docs/api-reference/points',
253
+ title: 'API Reference — Points',
254
+ keywords: ['api', 'points', 'leaderboard', 'rewards'],
255
+ },
256
+ {
257
+ site: 'upshift',
258
+ path: '/developer-docs/code-and-app-examples',
259
+ title: 'Code & App Examples',
260
+ keywords: ['examples', 'code', 'tutorial', 'integration'],
261
+ },
262
+ {
263
+ site: 'upshift',
264
+ path: '/developer-docs/universal-adapter',
265
+ title: 'Universal Adapter',
266
+ keywords: ['universal', 'adapter', 'multi-chain'],
267
+ },
268
+ {
269
+ site: 'upshift',
270
+ path: '/developer-docs/vault-contract-interface',
271
+ title: 'Vault Contract Interface',
272
+ keywords: ['vault', 'contract', 'interface', 'abi'],
273
+ },
274
+ {
275
+ site: 'upshift',
276
+ path: '/resources/deployed-contracts',
277
+ title: 'Deployed Contracts',
278
+ keywords: ['contracts', 'deployed', 'addresses'],
279
+ },
280
+ ];
281
+ const DocsPageSchema = zod_1.z.object({
282
+ site: zod_1.z.string(),
283
+ path: zod_1.z.string(),
284
+ title: zod_1.z.string(),
285
+ url: zod_1.z.string(),
286
+ });
287
+ const DocsListSchema = zod_1.z.object({
288
+ pages: zod_1.z.array(DocsPageSchema),
289
+ total: zod_1.z.number(),
290
+ });
291
+ const DocsFetchSchema = zod_1.z.object({
292
+ site: zod_1.z.string(),
293
+ path: zod_1.z.string(),
294
+ url: zod_1.z.string(),
295
+ title: zod_1.z.string(),
296
+ wordCount: zod_1.z.number(),
297
+ });
298
+ const DocsSearchSchema = zod_1.z.object({
299
+ query: zod_1.z.string(),
300
+ results: zod_1.z.array(zod_1.z.object({
301
+ site: zod_1.z.string(),
302
+ path: zod_1.z.string(),
303
+ title: zod_1.z.string(),
304
+ url: zod_1.z.string(),
305
+ score: zod_1.z.number(),
306
+ })),
307
+ });
308
+ function score(page, query) {
309
+ const q = query.toLowerCase();
310
+ const words = q.split(/\s+/).filter(Boolean);
311
+ let s = 0;
312
+ for (const word of words) {
313
+ if (page.title.toLowerCase().includes(word))
314
+ s += 3;
315
+ if (page.path.toLowerCase().includes(word))
316
+ s += 2;
317
+ if (page.keywords.some((k) => k.includes(word)))
318
+ s += 1;
319
+ }
320
+ return s;
321
+ }
322
+ async function fetchAndStrip(site, path) {
323
+ const base = DOC_SITES[site];
324
+ const cleanPath = path.startsWith('/') ? path : `/${path}`;
325
+ const url = `${base}${cleanPath}`;
326
+ const res = await fetch(url, {
327
+ headers: { 'User-Agent': 'upshift-cli/1.0', Accept: 'text/html,*/*' },
328
+ signal: AbortSignal.timeout(12_000),
329
+ redirect: 'follow',
330
+ });
331
+ if (!res.ok)
332
+ throw new Error(`HTTP ${res.status} from ${url}`);
333
+ const html = await res.text();
334
+ const titleMatch = html.match(/<title\b[^>]*>([\s\S]*?)<\/title>/i);
335
+ const title = titleMatch
336
+ ? titleMatch[1].replace(/<[^>]+>/g, '').trim()
337
+ : cleanPath;
338
+ const text = html
339
+ .replace(/<[^>]+>/g, ' ')
340
+ .replace(/\s+/g, ' ')
341
+ .trim();
342
+ return { title, wordCount: text.split(/\s+/).length, url };
343
+ }
344
+ function registerDocs(program) {
345
+ const docs = program
346
+ .command('docs')
347
+ .description('Browse Upshift documentation');
348
+ docs
349
+ .command('list')
350
+ .description('List all available documentation pages')
351
+ .option('--site <site>', 'Filter by site: august, upshift, or all (default: all)', 'all')
352
+ .action(async function () {
353
+ const flags = (0, flags_1.readGlobalFlags)(this);
354
+ const opts = this.opts();
355
+ const siteFilter = opts.site === 'all' ? undefined : opts.site;
356
+ await (0, output_1.runCommand)('docs.list', DocsListSchema, flags, async () => {
357
+ const pages = DOC_INDEX.filter((p) => !siteFilter || p.site === siteFilter).map((p) => ({
358
+ site: p.site,
359
+ path: p.path,
360
+ title: p.title,
361
+ url: `${DOC_SITES[p.site]}${p.path}`,
362
+ }));
363
+ return { pages, total: pages.length };
364
+ });
365
+ });
366
+ docs
367
+ .command('search <query>')
368
+ .description('Find documentation pages matching a keyword query')
369
+ .option('--site <site>', 'Filter by site: august, upshift, or all (default: all)', 'all')
370
+ .option('--limit <n>', 'Max results to return (default: 5)', '5')
371
+ .action(async function (query) {
372
+ const flags = (0, flags_1.readGlobalFlags)(this);
373
+ const opts = this.opts();
374
+ const siteFilter = opts.site === 'all' ? undefined : opts.site;
375
+ const limit = Math.min(Math.max(1, parseInt(opts.limit, 10) || 5), 20);
376
+ await (0, output_1.runCommand)('docs.search', DocsSearchSchema, flags, async () => {
377
+ const candidates = DOC_INDEX.filter((p) => !siteFilter || p.site === siteFilter);
378
+ const results = candidates
379
+ .map((p) => ({ ...p, score: score(p, query) }))
380
+ .filter((x) => x.score > 0)
381
+ .sort((a, b) => b.score - a.score)
382
+ .slice(0, limit)
383
+ .map((p) => ({
384
+ site: p.site,
385
+ path: p.path,
386
+ title: p.title,
387
+ url: `${DOC_SITES[p.site]}${p.path}`,
388
+ score: p.score,
389
+ }));
390
+ return { query, results };
391
+ });
392
+ });
393
+ docs
394
+ .command('open <site> <path>')
395
+ .description('Verify a documentation page exists and print its URL')
396
+ .action(async function (site, path) {
397
+ const flags = (0, flags_1.readGlobalFlags)(this);
398
+ if (site !== 'august' && site !== 'upshift') {
399
+ throw new Error(`Unknown site "${site}". Use "august" or "upshift".`);
400
+ }
401
+ await (0, output_1.runCommand)('docs.open', DocsFetchSchema, flags, async () => {
402
+ const { title, wordCount, url } = await fetchAndStrip(site, path);
403
+ return { site, path, url, title, wordCount };
404
+ });
405
+ });
406
+ }
407
+ //# sourceMappingURL=docs.js.map
@@ -0,0 +1,2 @@
1
+ import type { Command } from 'commander';
2
+ export declare function registerInit(program: Command): void;
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerInit = registerInit;
4
+ const config_1 = require("@upshiftfinance/config");
5
+ const flags_1 = require("../lib/flags");
6
+ const output_1 = require("../lib/output");
7
+ const prompts_1 = require("../lib/prompts");
8
+ const zod_1 = require("zod");
9
+ const InitOutput = zod_1.z.object({
10
+ configDir: zod_1.z.string(),
11
+ configWritten: zod_1.z.boolean(),
12
+ keystoreWritten: zod_1.z.boolean(),
13
+ });
14
+ const CHAIN_CHOICES = [
15
+ { name: 'Ethereum (1)', value: 1 },
16
+ { name: 'Base (8453)', value: 8453 },
17
+ { name: 'Arbitrum One (42161)', value: 42161 },
18
+ { name: 'Optimism (10)', value: 10 },
19
+ { name: 'Polygon (137)', value: 137 },
20
+ { name: 'Avalanche (43114)', value: 43114 },
21
+ { name: 'BNB Smart Chain (56)', value: 56 },
22
+ { name: 'HyperEVM (999)', value: 999 },
23
+ ];
24
+ async function runInit(flags) {
25
+ (0, config_1.ensureConfigDir)();
26
+ if (!flags.force && ((0, config_1.configExists)() || (0, config_1.keystoreExists)())) {
27
+ if (flags.json) {
28
+ throw new Error(`Config already exists at ${(0, config_1.activeConfigDir)()}. Re-run with --force to overwrite.`);
29
+ }
30
+ const overwrite = await (0, prompts_1.promptConfirm)({
31
+ message: `Config already exists at ${(0, config_1.activeConfigDir)()}. Overwrite?`,
32
+ default: false,
33
+ });
34
+ if (!overwrite) {
35
+ (0, prompts_1.tell)('Aborted.');
36
+ return InitOutput.parse({
37
+ configDir: (0, config_1.activeConfigDir)(),
38
+ configWritten: false,
39
+ keystoreWritten: false,
40
+ });
41
+ }
42
+ }
43
+ (0, prompts_1.banner)("Let's set up Upshift");
44
+ (0, prompts_1.tell)("We'll save your config to " +
45
+ (0, config_1.activeConfigDir)() +
46
+ '. You can re-run `upshift init` at any time.\n');
47
+ const wantsKey = await (0, prompts_1.promptConfirm)({
48
+ message: 'Do you have an Upshift API key?',
49
+ default: false,
50
+ });
51
+ let keystoreWritten = false;
52
+ if (wantsKey) {
53
+ const apiKey = await (0, prompts_1.promptText)({
54
+ message: 'Paste it here:',
55
+ required: true,
56
+ });
57
+ const passphrase = await (0, prompts_1.promptPassphrase)({
58
+ message: 'Choose a passphrase to encrypt it:',
59
+ confirmMessage: 'Confirm:',
60
+ });
61
+ const ks = await config_1.Keystore.create(passphrase);
62
+ ks.set('upshift', apiKey);
63
+ await ks.save();
64
+ keystoreWritten = true;
65
+ }
66
+ else {
67
+ (0, prompts_1.tell)('Public read commands still work without a key. Run `upshift init` again later if you get one.');
68
+ }
69
+ const chainId = await (0, prompts_1.promptSelect)({
70
+ message: 'Default chain:',
71
+ choices: CHAIN_CHOICES.map((c) => ({
72
+ name: c.name,
73
+ value: String(c.value),
74
+ })),
75
+ default: '1',
76
+ });
77
+ const wantsRpc = await (0, prompts_1.promptConfirm)({
78
+ message: `Add a custom RPC URL for chain ${chainId}?`,
79
+ default: false,
80
+ });
81
+ const rpcs = {};
82
+ if (wantsRpc) {
83
+ rpcs[chainId] = await (0, prompts_1.promptText)({ message: 'RPC URL:', required: true });
84
+ }
85
+ const telemetry = await (0, prompts_1.promptConfirm)({
86
+ message: 'Send anonymous usage metrics (version + command name)? Toggle anytime with `upshift config set telemetry true|false`.',
87
+ default: false,
88
+ });
89
+ (0, config_1.saveConfig)({
90
+ defaultChainId: Number(chainId),
91
+ rpcs,
92
+ telemetry,
93
+ });
94
+ (0, prompts_1.banner)('Done');
95
+ (0, prompts_1.tell)([
96
+ ` config ${(0, config_1.activeConfigDir)()}`,
97
+ ` default chain ${chainId}, profile "default"`,
98
+ keystoreWritten
99
+ ? ' keystore encrypted (run `upshift login` to unlock)'
100
+ : ' keystore (none)',
101
+ '',
102
+ 'Next:',
103
+ ' upshift whoami',
104
+ ' upshift chain list',
105
+ ` upshift vault tvl <address> --chain ${chainId}`,
106
+ ].join('\n'));
107
+ return InitOutput.parse({
108
+ configDir: (0, config_1.activeConfigDir)(),
109
+ configWritten: true,
110
+ keystoreWritten,
111
+ });
112
+ }
113
+ function registerInit(program) {
114
+ program
115
+ .command('init')
116
+ .description('Set up ~/.upshift and (optionally) store an API key')
117
+ .option('--force', 'overwrite an existing config without prompting')
118
+ .action(async function () {
119
+ const opts = this.opts();
120
+ const flags = (0, flags_1.readGlobalFlags)(this);
121
+ await (0, output_1.runCommand)('init', InitOutput, flags, () => runInit({ ...flags, force: opts.force }));
122
+ });
123
+ }
124
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1,2 @@
1
+ import type { Command } from 'commander';
2
+ export declare function registerLogin(program: Command): void;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerLogin = registerLogin;
4
+ const zod_1 = require("zod");
5
+ const config_1 = require("@upshiftfinance/config");
6
+ const flags_1 = require("../lib/flags");
7
+ const output_1 = require("../lib/output");
8
+ const prompts_1 = require("../lib/prompts");
9
+ const LoginOutput = zod_1.z.object({
10
+ ok: zod_1.z.boolean(),
11
+ expiresAt: zod_1.z.string().datetime().optional(),
12
+ ttlSec: zod_1.z.number().int().positive().optional(),
13
+ });
14
+ const LogoutOutput = zod_1.z.object({ ok: zod_1.z.boolean() });
15
+ function registerLogin(program) {
16
+ program
17
+ .command('login')
18
+ .description('Unlock the keystore for this shell session')
19
+ .action(async function () {
20
+ const flags = (0, flags_1.readGlobalFlags)(this);
21
+ await (0, output_1.runCommand)('login', LoginOutput, flags, async () => {
22
+ if (!(0, config_1.keystoreExists)()) {
23
+ throw new Error('No keystore. Run `upshift init` first.');
24
+ }
25
+ const passphrase = process.env.UPSHIFT_PASSPHRASE ||
26
+ (await (0, prompts_1.promptPassphrase)({ message: 'Passphrase:' }));
27
+ const ks = await config_1.Keystore.unlock(passphrase);
28
+ const apiKey = ks.get('upshift');
29
+ if (!apiKey) {
30
+ throw new Error('Keystore is empty. Run `upshift init --force` to add an API key.');
31
+ }
32
+ const cfg = (0, config_1.loadConfig)();
33
+ const session = (0, config_1.writeSession)({ apiKey }, cfg.auth.sessionTtlSec);
34
+ if (!flags.json) {
35
+ (0, prompts_1.tell)(`Session valid until ${new Date(session.expiresAt).toISOString()}.`);
36
+ }
37
+ return {
38
+ ok: true,
39
+ expiresAt: new Date(session.expiresAt).toISOString(),
40
+ ttlSec: cfg.auth.sessionTtlSec,
41
+ };
42
+ });
43
+ });
44
+ program
45
+ .command('logout')
46
+ .description('Clear the cached session')
47
+ .action(async function () {
48
+ const flags = (0, flags_1.readGlobalFlags)(this);
49
+ await (0, output_1.runCommand)('logout', LogoutOutput, flags, async () => {
50
+ (0, config_1.clearSession)();
51
+ if (!flags.json)
52
+ (0, prompts_1.tell)('Logged out.');
53
+ return { ok: true };
54
+ });
55
+ });
56
+ }
57
+ //# sourceMappingURL=login.js.map
@@ -0,0 +1,2 @@
1
+ import type { Command } from 'commander';
2
+ export declare function registerOps(program: Command): void;