@faces-sh/cli 0.0.0-stage → 1.0.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 +158 -2
- package/bin/dev.js +5 -0
- package/bin/run.js +5 -0
- package/dist/base.d.ts +26 -0
- package/dist/base.js +181 -0
- package/dist/benchmark.d.ts +21 -0
- package/dist/benchmark.js +95 -0
- package/dist/billing.d.ts +17 -0
- package/dist/billing.js +101 -0
- package/dist/catalog.d.ts +35 -0
- package/dist/catalog.js +242 -0
- package/dist/client.d.ts +98 -0
- package/dist/client.js +590 -0
- package/dist/commands/account/preferences.d.ts +20 -0
- package/dist/commands/account/preferences.js +190 -0
- package/dist/commands/account/state.d.ts +11 -0
- package/dist/commands/account/state.js +24 -0
- package/dist/commands/auth/connect.d.ts +17 -0
- package/dist/commands/auth/connect.js +190 -0
- package/dist/commands/auth/connections.d.ts +12 -0
- package/dist/commands/auth/connections.js +40 -0
- package/dist/commands/auth/disconnect.d.ts +15 -0
- package/dist/commands/auth/disconnect.js +49 -0
- package/dist/commands/auth/login.d.ts +13 -0
- package/dist/commands/auth/login.js +42 -0
- package/dist/commands/auth/logout.d.ts +11 -0
- package/dist/commands/auth/logout.js +14 -0
- package/dist/commands/auth/refresh.d.ts +11 -0
- package/dist/commands/auth/refresh.js +30 -0
- package/dist/commands/auth/register.d.ts +15 -0
- package/dist/commands/auth/register.js +98 -0
- package/dist/commands/auth/whoami.d.ts +11 -0
- package/dist/commands/auth/whoami.js +108 -0
- package/dist/commands/benchmark/get.d.ts +16 -0
- package/dist/commands/benchmark/get.js +42 -0
- package/dist/commands/benchmark/list.d.ts +13 -0
- package/dist/commands/benchmark/list.js +47 -0
- package/dist/commands/benchmark/start.d.ts +22 -0
- package/dist/commands/benchmark/start.js +80 -0
- package/dist/commands/billing/balance.d.ts +11 -0
- package/dist/commands/billing/balance.js +27 -0
- package/dist/commands/billing/card/default.d.ts +15 -0
- package/dist/commands/billing/card/default.js +33 -0
- package/dist/commands/billing/card/remove.d.ts +16 -0
- package/dist/commands/billing/card/remove.js +41 -0
- package/dist/commands/billing/card-setup.d.ts +13 -0
- package/dist/commands/billing/card-setup.js +41 -0
- package/dist/commands/billing/cards.d.ts +11 -0
- package/dist/commands/billing/cards.js +34 -0
- package/dist/commands/billing/llm-costs.d.ts +14 -0
- package/dist/commands/billing/llm-costs.js +95 -0
- package/dist/commands/billing/subscription/activate.d.ts +14 -0
- package/dist/commands/billing/subscription/activate.js +91 -0
- package/dist/commands/billing/subscription/cancel.d.ts +12 -0
- package/dist/commands/billing/subscription/cancel.js +54 -0
- package/dist/commands/billing/subscription/index.d.ts +11 -0
- package/dist/commands/billing/subscription/index.js +46 -0
- package/dist/commands/billing/subscription/plan.d.ts +16 -0
- package/dist/commands/billing/subscription/plan.js +86 -0
- package/dist/commands/billing/topup.d.ts +16 -0
- package/dist/commands/billing/topup.js +60 -0
- package/dist/commands/billing/usage.d.ts +15 -0
- package/dist/commands/billing/usage.js +68 -0
- package/dist/commands/catalog/backup.d.ts +11 -0
- package/dist/commands/catalog/backup.js +169 -0
- package/dist/commands/catalog/doctor.d.ts +14 -0
- package/dist/commands/catalog/doctor.js +303 -0
- package/dist/commands/catalog/list.d.ts +11 -0
- package/dist/commands/catalog/list.js +39 -0
- package/dist/commands/catalog/restore.d.ts +17 -0
- package/dist/commands/catalog/restore.js +259 -0
- package/dist/commands/causes.d.ts +27 -0
- package/dist/commands/causes.js +135 -0
- package/dist/commands/chat/chat.d.ts +42 -0
- package/dist/commands/chat/chat.js +363 -0
- package/dist/commands/chat/messages.d.ts +26 -0
- package/dist/commands/chat/messages.js +139 -0
- package/dist/commands/chat/responses.d.ts +27 -0
- package/dist/commands/chat/responses.js +150 -0
- package/dist/commands/chat/thread.d.ts +43 -0
- package/dist/commands/chat/thread.js +458 -0
- package/dist/commands/compile/all.d.ts +14 -0
- package/dist/commands/compile/all.js +186 -0
- package/dist/commands/compile/doc/create.d.ts +19 -0
- package/dist/commands/compile/doc/create.js +58 -0
- package/dist/commands/compile/doc/delete.d.ts +15 -0
- package/dist/commands/compile/doc/delete.js +33 -0
- package/dist/commands/compile/doc/edit.d.ts +19 -0
- package/dist/commands/compile/doc/edit.js +59 -0
- package/dist/commands/compile/doc/get.d.ts +15 -0
- package/dist/commands/compile/doc/get.js +43 -0
- package/dist/commands/compile/doc/index.d.ts +24 -0
- package/dist/commands/compile/doc/index.js +211 -0
- package/dist/commands/compile/doc/list.d.ts +15 -0
- package/dist/commands/compile/doc/list.js +46 -0
- package/dist/commands/compile/doc/make.d.ts +17 -0
- package/dist/commands/compile/doc/make.js +95 -0
- package/dist/commands/compile/doc/pause.d.ts +17 -0
- package/dist/commands/compile/doc/pause.js +74 -0
- package/dist/commands/compile/doc/reset.d.ts +15 -0
- package/dist/commands/compile/doc/reset.js +33 -0
- package/dist/commands/compile/import.d.ts +20 -0
- package/dist/commands/compile/import.js +138 -0
- package/dist/commands/compile/stats.d.ts +11 -0
- package/dist/commands/compile/stats.js +75 -0
- package/dist/commands/compile/status.d.ts +17 -0
- package/dist/commands/compile/status.js +110 -0
- package/dist/commands/compile/thread/create.d.ts +16 -0
- package/dist/commands/compile/thread/create.js +42 -0
- package/dist/commands/compile/thread/delete.d.ts +15 -0
- package/dist/commands/compile/thread/delete.js +33 -0
- package/dist/commands/compile/thread/edit.d.ts +19 -0
- package/dist/commands/compile/thread/edit.js +120 -0
- package/dist/commands/compile/thread/get.d.ts +15 -0
- package/dist/commands/compile/thread/get.js +48 -0
- package/dist/commands/compile/thread/list.d.ts +14 -0
- package/dist/commands/compile/thread/list.js +38 -0
- package/dist/commands/compile/thread/make.d.ts +17 -0
- package/dist/commands/compile/thread/make.js +87 -0
- package/dist/commands/compile/thread/message.d.ts +16 -0
- package/dist/commands/compile/thread/message.js +43 -0
- package/dist/commands/compile/thread/pause.d.ts +17 -0
- package/dist/commands/compile/thread/pause.js +75 -0
- package/dist/commands/compile/thread/replace.d.ts +27 -0
- package/dist/commands/compile/thread/replace.js +114 -0
- package/dist/commands/compile/thread/reset.d.ts +15 -0
- package/dist/commands/compile/thread/reset.js +33 -0
- package/dist/commands/compile/upload.d.ts +21 -0
- package/dist/commands/compile/upload.js +162 -0
- package/dist/commands/config/clear.d.ts +12 -0
- package/dist/commands/config/clear.js +17 -0
- package/dist/commands/config/set.d.ts +15 -0
- package/dist/commands/config/set.js +43 -0
- package/dist/commands/config/show.d.ts +11 -0
- package/dist/commands/config/show.js +19 -0
- package/dist/commands/decide.d.ts +35 -0
- package/dist/commands/decide.js +242 -0
- package/dist/commands/face/attributes.d.ts +11 -0
- package/dist/commands/face/attributes.js +44 -0
- package/dist/commands/face/avatar/delete.d.ts +15 -0
- package/dist/commands/face/avatar/delete.js +38 -0
- package/dist/commands/face/avatar/get.d.ts +20 -0
- package/dist/commands/face/avatar/get.js +100 -0
- package/dist/commands/face/avatar/list.d.ts +14 -0
- package/dist/commands/face/avatar/list.js +56 -0
- package/dist/commands/face/avatar/make.d.ts +16 -0
- package/dist/commands/face/avatar/make.js +64 -0
- package/dist/commands/face/avatar/upload.d.ts +15 -0
- package/dist/commands/face/avatar/upload.js +67 -0
- package/dist/commands/face/create.d.ts +23 -0
- package/dist/commands/face/create.js +122 -0
- package/dist/commands/face/delete.d.ts +15 -0
- package/dist/commands/face/delete.js +39 -0
- package/dist/commands/face/diff.d.ts +12 -0
- package/dist/commands/face/diff.js +50 -0
- package/dist/commands/face/edit.d.ts +25 -0
- package/dist/commands/face/edit.js +155 -0
- package/dist/commands/face/get.d.ts +16 -0
- package/dist/commands/face/get.js +145 -0
- package/dist/commands/face/groups.d.ts +15 -0
- package/dist/commands/face/groups.js +34 -0
- package/dist/commands/face/list.d.ts +23 -0
- package/dist/commands/face/list.js +168 -0
- package/dist/commands/face/lock.d.ts +15 -0
- package/dist/commands/face/lock.js +35 -0
- package/dist/commands/face/neighbors.d.ts +16 -0
- package/dist/commands/face/neighbors.js +63 -0
- package/dist/commands/face/publish.d.ts +16 -0
- package/dist/commands/face/publish.js +42 -0
- package/dist/commands/face/share.d.ts +22 -0
- package/dist/commands/face/share.js +103 -0
- package/dist/commands/face/sources.d.ts +21 -0
- package/dist/commands/face/sources.js +169 -0
- package/dist/commands/face/stats.d.ts +12 -0
- package/dist/commands/face/stats.js +46 -0
- package/dist/commands/face/tag/add.d.ts +15 -0
- package/dist/commands/face/tag/add.js +40 -0
- package/dist/commands/face/tag/all.d.ts +11 -0
- package/dist/commands/face/tag/all.js +31 -0
- package/dist/commands/face/tag/list.d.ts +14 -0
- package/dist/commands/face/tag/list.js +36 -0
- package/dist/commands/face/tag/remove.d.ts +16 -0
- package/dist/commands/face/tag/remove.js +44 -0
- package/dist/commands/face/tag/set.d.ts +15 -0
- package/dist/commands/face/tag/set.js +40 -0
- package/dist/commands/face/unlock.d.ts +15 -0
- package/dist/commands/face/unlock.js +35 -0
- package/dist/commands/face/unpublish.d.ts +14 -0
- package/dist/commands/face/unpublish.js +31 -0
- package/dist/commands/face/unshare.d.ts +18 -0
- package/dist/commands/face/unshare.js +66 -0
- package/dist/commands/fidelity/get.d.ts +15 -0
- package/dist/commands/fidelity/get.js +42 -0
- package/dist/commands/fidelity/pick.d.ts +19 -0
- package/dist/commands/fidelity/pick.js +70 -0
- package/dist/commands/fidelity/run.d.ts +20 -0
- package/dist/commands/fidelity/run.js +99 -0
- package/dist/commands/fidelity/save-thread.d.ts +15 -0
- package/dist/commands/fidelity/save-thread.js +35 -0
- package/dist/commands/fidelity/start.d.ts +17 -0
- package/dist/commands/fidelity/start.js +56 -0
- package/dist/commands/fidelity/turn.d.ts +17 -0
- package/dist/commands/fidelity/turn.js +48 -0
- package/dist/commands/group/add.d.ts +16 -0
- package/dist/commands/group/add.js +83 -0
- package/dist/commands/group/create.d.ts +16 -0
- package/dist/commands/group/create.js +68 -0
- package/dist/commands/group/delete.d.ts +15 -0
- package/dist/commands/group/delete.js +39 -0
- package/dist/commands/group/edit.d.ts +18 -0
- package/dist/commands/group/edit.js +75 -0
- package/dist/commands/group/get.d.ts +14 -0
- package/dist/commands/group/get.js +29 -0
- package/dist/commands/group/list.d.ts +11 -0
- package/dist/commands/group/list.js +39 -0
- package/dist/commands/group/members.d.ts +15 -0
- package/dist/commands/group/members.js +68 -0
- package/dist/commands/group/remove.d.ts +15 -0
- package/dist/commands/group/remove.js +55 -0
- package/dist/commands/group/tag/add.d.ts +15 -0
- package/dist/commands/group/tag/add.js +30 -0
- package/dist/commands/group/tag/list.d.ts +14 -0
- package/dist/commands/group/tag/list.js +36 -0
- package/dist/commands/group/tag/remove.d.ts +15 -0
- package/dist/commands/group/tag/remove.js +30 -0
- package/dist/commands/group/tag/set.d.ts +15 -0
- package/dist/commands/group/tag/set.js +30 -0
- package/dist/commands/keys/create.d.ts +17 -0
- package/dist/commands/keys/create.js +72 -0
- package/dist/commands/keys/list.d.ts +11 -0
- package/dist/commands/keys/list.js +24 -0
- package/dist/commands/keys/revoke.d.ts +15 -0
- package/dist/commands/keys/revoke.js +49 -0
- package/dist/commands/keys/update.d.ts +17 -0
- package/dist/commands/keys/update.js +41 -0
- package/dist/commands/models/list.d.ts +15 -0
- package/dist/commands/models/list.js +98 -0
- package/dist/commands/session/close.d.ts +16 -0
- package/dist/commands/session/close.js +36 -0
- package/dist/commands/session/compact.d.ts +15 -0
- package/dist/commands/session/compact.js +58 -0
- package/dist/commands/session/create.d.ts +15 -0
- package/dist/commands/session/create.js +45 -0
- package/dist/commands/session/get.d.ts +15 -0
- package/dist/commands/session/get.js +34 -0
- package/dist/commands/style/delete.d.ts +19 -0
- package/dist/commands/style/delete.js +92 -0
- package/dist/commands/style/make.d.ts +28 -0
- package/dist/commands/style/make.js +298 -0
- package/dist/commands/style/revert.d.ts +17 -0
- package/dist/commands/style/revert.js +66 -0
- package/dist/commands/style/status.d.ts +20 -0
- package/dist/commands/style/status.js +109 -0
- package/dist/commands/style/upload.d.ts +19 -0
- package/dist/commands/style/upload.js +100 -0
- package/dist/commands/style/versions.d.ts +15 -0
- package/dist/commands/style/versions.js +104 -0
- package/dist/commands/user/follow.d.ts +14 -0
- package/dist/commands/user/follow.js +38 -0
- package/dist/commands/user/followers.d.ts +14 -0
- package/dist/commands/user/followers.js +50 -0
- package/dist/commands/user/following.d.ts +14 -0
- package/dist/commands/user/following.js +50 -0
- package/dist/commands/user/get.d.ts +14 -0
- package/dist/commands/user/get.js +49 -0
- package/dist/commands/user/unfollow.d.ts +14 -0
- package/dist/commands/user/unfollow.js +38 -0
- package/dist/config.d.ts +32 -0
- package/dist/config.js +139 -0
- package/dist/decisions.d.ts +42 -0
- package/dist/decisions.js +262 -0
- package/dist/fidelity.d.ts +50 -0
- package/dist/fidelity.js +92 -0
- package/dist/group-catalog.d.ts +22 -0
- package/dist/group-catalog.js +133 -0
- package/dist/paths.d.ts +1 -0
- package/dist/paths.js +8 -0
- package/dist/poll.d.ts +26 -0
- package/dist/poll.js +75 -0
- package/dist/routing.d.ts +15 -0
- package/dist/routing.js +135 -0
- package/dist/session.d.ts +14 -0
- package/dist/session.js +18 -0
- package/dist/style.d.ts +46 -0
- package/dist/style.js +285 -0
- package/dist/utils.d.ts +149 -0
- package/dist/utils.js +865 -0
- package/oclif.manifest.json +11070 -0
- package/package.json +127 -4
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
import { FacesAPIError } from '../../client.js';
|
|
3
|
+
import { resolveBaseUrl, saveCredentials } from '../../config.js';
|
|
4
|
+
export default class AuthRefresh extends BaseCommand {
|
|
5
|
+
static description = 'Exchange current JWT for a fresh one';
|
|
6
|
+
static flags = {
|
|
7
|
+
...BaseCommand.baseFlags,
|
|
8
|
+
};
|
|
9
|
+
async run() {
|
|
10
|
+
const { flags } = await this.parse(AuthRefresh);
|
|
11
|
+
const client = this.makeClient(flags);
|
|
12
|
+
let data;
|
|
13
|
+
try {
|
|
14
|
+
data = (await client.post('/auth/refresh', { requireJwt: true }));
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
if (err instanceof FacesAPIError)
|
|
18
|
+
this.error(`Refresh failed (${err.statusCode}): ${err.message}`);
|
|
19
|
+
throw err;
|
|
20
|
+
}
|
|
21
|
+
const token = (data.access_token ?? data.token);
|
|
22
|
+
if (token) {
|
|
23
|
+
saveCredentials({ token }, resolveBaseUrl(flags['base-url']));
|
|
24
|
+
this.log('Token refreshed and saved.');
|
|
25
|
+
}
|
|
26
|
+
if (!this.jsonEnabled())
|
|
27
|
+
this.printHuman(data);
|
|
28
|
+
return data;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
export default class AuthRegister extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static flags: {
|
|
5
|
+
email: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
6
|
+
password: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
username: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
plan: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
13
|
+
};
|
|
14
|
+
run(): Promise<unknown>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import { BaseCommand } from '../../base.js';
|
|
3
|
+
import { FacesAPIError, FacesClient } from '../../client.js';
|
|
4
|
+
import { saveCredentials, resolveBaseUrl } from '../../config.js';
|
|
5
|
+
export default class AuthRegister extends BaseCommand {
|
|
6
|
+
static description = 'Create a new Faces account';
|
|
7
|
+
static flags = {
|
|
8
|
+
...BaseCommand.baseFlags,
|
|
9
|
+
email: Flags.string({ description: 'Email address', required: true }),
|
|
10
|
+
password: Flags.string({
|
|
11
|
+
description: 'Password, with at least one digit. Leave it out to be asked for it, without it showing as you type',
|
|
12
|
+
}),
|
|
13
|
+
username: Flags.string({
|
|
14
|
+
description: 'Username: 1-32 characters, starting with a lowercase letter, then lowercase letters, numbers or underscores (no dashes)',
|
|
15
|
+
required: true,
|
|
16
|
+
}),
|
|
17
|
+
plan: Flags.string({
|
|
18
|
+
description: 'Plan to subscribe to: "free" ($5 activation, then pay as you go), "connect" ($17/mo) or "pro" ' +
|
|
19
|
+
'($49/mo), neither with an activation fee',
|
|
20
|
+
options: ['free', 'connect', 'pro'],
|
|
21
|
+
default: 'free',
|
|
22
|
+
}),
|
|
23
|
+
};
|
|
24
|
+
async run() {
|
|
25
|
+
const { flags } = await this.parse(AuthRegister);
|
|
26
|
+
if (!/^[a-z][a-z0-9_]{0,31}$/.test(flags.username)) {
|
|
27
|
+
this.error('--username must be 1-32 characters, start with a lowercase letter, and use only lowercase letters, numbers or underscores (no dashes).');
|
|
28
|
+
}
|
|
29
|
+
const password = await this.secretOrPrompt(flags.password, 'password', 'Password');
|
|
30
|
+
if (!/\d/.test(password))
|
|
31
|
+
this.error('The password must contain at least one digit.');
|
|
32
|
+
const baseUrl = resolveBaseUrl(flags['base-url']);
|
|
33
|
+
const client = new FacesClient(baseUrl);
|
|
34
|
+
const payload = {
|
|
35
|
+
email: flags.email,
|
|
36
|
+
password,
|
|
37
|
+
username: flags.username,
|
|
38
|
+
source: 'cli',
|
|
39
|
+
};
|
|
40
|
+
let data;
|
|
41
|
+
try {
|
|
42
|
+
data = (await client.postNoAuth('/auth/register-email', payload));
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
if (err instanceof FacesAPIError) {
|
|
46
|
+
this.error(`Registration failed (${err.statusCode}): ${err.message}`);
|
|
47
|
+
}
|
|
48
|
+
throw err;
|
|
49
|
+
}
|
|
50
|
+
const inner = (data.data ?? data);
|
|
51
|
+
const token = (inner.access_token ?? inner.token);
|
|
52
|
+
if (token)
|
|
53
|
+
saveCredentials({ token }, baseUrl);
|
|
54
|
+
const result = {
|
|
55
|
+
status: 'registered',
|
|
56
|
+
user_id: inner.user_id,
|
|
57
|
+
};
|
|
58
|
+
if (token) {
|
|
59
|
+
const authedClient = new FacesClient(baseUrl, token);
|
|
60
|
+
if (flags.plan === 'connect' || flags.plan === 'pro') {
|
|
61
|
+
try {
|
|
62
|
+
const checkoutResp = await authedClient.post(`/v1/billing/checkout?plan=${flags.plan}&source=cli`);
|
|
63
|
+
result.checkout_url = checkoutResp.checkout_url;
|
|
64
|
+
result.plan = flags.plan;
|
|
65
|
+
result.amount = flags.plan === 'pro' ? '$49/mo' : '$17/mo';
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
if (err instanceof FacesAPIError) {
|
|
69
|
+
result.checkout_error = `Failed to get ${flags.plan === 'pro' ? 'Pro' : 'Connect'} checkout URL: ${err.message}`;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
if (inner.activation_checkout_url) {
|
|
75
|
+
result.checkout_url = inner.activation_checkout_url;
|
|
76
|
+
result.plan = 'free';
|
|
77
|
+
result.amount = '$5 (added as API credits)';
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
try {
|
|
81
|
+
const activate = await authedClient.post('/v1/billing/activate');
|
|
82
|
+
result.checkout_url = activate.checkout_url;
|
|
83
|
+
result.plan = 'free';
|
|
84
|
+
result.amount = '$5 (added as API credits)';
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
if (err instanceof FacesAPIError) {
|
|
88
|
+
result.checkout_error = `Failed to get activation URL: ${err.message}`;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (!this.jsonEnabled())
|
|
95
|
+
this.printHuman(result);
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
export default class AuthWhoami extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static flags: {
|
|
5
|
+
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
6
|
+
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
9
|
+
};
|
|
10
|
+
run(): Promise<unknown>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
import { FacesClient, FacesAPIError } from '../../client.js';
|
|
3
|
+
import { resolveBaseUrl, resolveCredentials } from '../../config.js';
|
|
4
|
+
export default class AuthWhoami extends BaseCommand {
|
|
5
|
+
static description = 'Print current user profile and auth diagnostic';
|
|
6
|
+
static flags = {
|
|
7
|
+
...BaseCommand.baseFlags,
|
|
8
|
+
};
|
|
9
|
+
async run() {
|
|
10
|
+
const { flags } = await this.parse(AuthWhoami);
|
|
11
|
+
const baseUrl = resolveBaseUrl(flags['base-url']);
|
|
12
|
+
const { token, apiKey, withheld, keySaved } = resolveCredentials(flags, baseUrl);
|
|
13
|
+
const json = this.jsonEnabled();
|
|
14
|
+
const diag = {
|
|
15
|
+
base_url: baseUrl,
|
|
16
|
+
jwt_configured: Boolean(token),
|
|
17
|
+
api_key_configured: Boolean(apiKey),
|
|
18
|
+
api_key_prefix: apiKey ? apiKey.slice(0, 12) + '...' : null,
|
|
19
|
+
};
|
|
20
|
+
if (!apiKey && !token) {
|
|
21
|
+
diag.authenticated = false;
|
|
22
|
+
diag.error = withheld ?? 'No credentials configured (no API key, no JWT)';
|
|
23
|
+
if (!json) {
|
|
24
|
+
this.log('Auth diagnostic:');
|
|
25
|
+
this.log(` base_url: ${baseUrl}`);
|
|
26
|
+
this.log(` jwt: not configured`);
|
|
27
|
+
this.log(` api_key: not configured`);
|
|
28
|
+
this.log(` status: not authenticated`);
|
|
29
|
+
if (withheld)
|
|
30
|
+
this.log(` note: ${withheld}`);
|
|
31
|
+
}
|
|
32
|
+
if (json)
|
|
33
|
+
process.stdout.write(JSON.stringify(diag, null, 2) + '\n');
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
let apiKeyResult = null;
|
|
37
|
+
let jwtResult = null;
|
|
38
|
+
if (apiKey) {
|
|
39
|
+
const client = new FacesClient(baseUrl, undefined, apiKey);
|
|
40
|
+
try {
|
|
41
|
+
const data = await client.get('/auth/me');
|
|
42
|
+
apiKeyResult = { ok: true, data: (data.data ?? data) };
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
const msg = err instanceof FacesAPIError ? `${err.statusCode}: ${err.message}` : String(err);
|
|
46
|
+
apiKeyResult = { ok: false, error: msg };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (token) {
|
|
50
|
+
if (!apiKeyResult?.ok) {
|
|
51
|
+
const client = new FacesClient(baseUrl, token, undefined);
|
|
52
|
+
try {
|
|
53
|
+
const data = await client.get('/auth/me');
|
|
54
|
+
jwtResult = { ok: true, data: (data.data ?? data) };
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
const msg = err instanceof FacesAPIError ? `${err.statusCode}: ${err.message}` : String(err);
|
|
58
|
+
jwtResult = { ok: false, error: msg };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const keyFailed = Boolean(apiKey) && !apiKeyResult?.ok;
|
|
63
|
+
const fallsBack = keyFailed && keySaved && Boolean(jwtResult?.ok);
|
|
64
|
+
const winner = apiKeyResult?.ok ? apiKeyResult : (!apiKey || fallsBack) && jwtResult?.ok ? jwtResult : null;
|
|
65
|
+
const winnerMethod = apiKeyResult?.ok ? 'api_key' : winner ? 'jwt' : null;
|
|
66
|
+
if (fallsBack)
|
|
67
|
+
diag.warning = 'The saved API key is refused, so commands fall back to the saved login. Remove the key with: faces config:set api_key ""';
|
|
68
|
+
diag.authenticated = Boolean(winner);
|
|
69
|
+
diag.auth_method = winnerMethod;
|
|
70
|
+
if (apiKeyResult)
|
|
71
|
+
diag.api_key_status = apiKeyResult.ok ? 'valid' : apiKeyResult.error;
|
|
72
|
+
if (jwtResult)
|
|
73
|
+
diag.jwt_status = jwtResult.ok ? 'valid' : jwtResult.error;
|
|
74
|
+
if (winner?.data) {
|
|
75
|
+
diag.user_id = winner.data.user_id;
|
|
76
|
+
diag.username = winner.data.username;
|
|
77
|
+
diag.email = winner.data.email;
|
|
78
|
+
diag.name = winner.data.name;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
diag.error = 'All credentials failed';
|
|
82
|
+
}
|
|
83
|
+
if (!json) {
|
|
84
|
+
const jwtLine = !token ? 'not configured' : jwtResult ? (jwtResult.ok ? 'valid' : `failed (${jwtResult.error})`) : 'not checked (the API key works)';
|
|
85
|
+
this.log('Auth diagnostic:');
|
|
86
|
+
this.log(` base_url: ${baseUrl}`);
|
|
87
|
+
this.log(` jwt: ${jwtLine}`);
|
|
88
|
+
this.log(` api_key: ${apiKey ? (apiKeyResult?.ok ? `valid (${diag.api_key_prefix})` : `failed (${apiKeyResult?.error})`) : 'not configured'}`);
|
|
89
|
+
this.log(` auth_method: ${winnerMethod ?? 'none'}`);
|
|
90
|
+
this.log(` status: ${winner ? 'authenticated' : 'failed'}`);
|
|
91
|
+
if (diag.warning)
|
|
92
|
+
this.log(` warning: ${diag.warning}`);
|
|
93
|
+
if (winner?.data) {
|
|
94
|
+
this.log('');
|
|
95
|
+
this.log(` user_id: ${winner.data.user_id}`);
|
|
96
|
+
this.log(` username: ${winner.data.username}`);
|
|
97
|
+
this.log(` email: ${winner.data.email}`);
|
|
98
|
+
this.log(` name: ${winner.data.name}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (!diag.authenticated) {
|
|
102
|
+
if (json)
|
|
103
|
+
process.stdout.write(JSON.stringify(diag, null, 2) + '\n');
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}
|
|
106
|
+
return diag;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
export default class BenchmarkGet extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static flags: {
|
|
6
|
+
wait: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
7
|
+
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
11
|
+
};
|
|
12
|
+
static args: {
|
|
13
|
+
run_id: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
14
|
+
};
|
|
15
|
+
run(): Promise<unknown>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import { BaseCommand } from '../../base.js';
|
|
3
|
+
import { FacesAPIError } from '../../client.js';
|
|
4
|
+
import { BENCHMARK_RUNS, benchmarkError, followRun, runLines } from '../../benchmark.js';
|
|
5
|
+
import { seg } from '../../utils.js';
|
|
6
|
+
export default class BenchmarkGet extends BaseCommand {
|
|
7
|
+
static description = 'Read a benchmark run: its status, its progress and, once done, the result: which won, the gap and ' +
|
|
8
|
+
'its 95% interval, and the same by length and by medium.';
|
|
9
|
+
static examples = ['<%= config.bin %> <%= command.id %> <run>', '<%= config.bin %> <%= command.id %> <run> --wait'];
|
|
10
|
+
static flags = {
|
|
11
|
+
...BaseCommand.baseFlags,
|
|
12
|
+
wait: Flags.boolean({ description: 'Wait for the run to finish', default: false }),
|
|
13
|
+
};
|
|
14
|
+
static args = {
|
|
15
|
+
run_id: Args.string({ description: 'Benchmark run id', required: true }),
|
|
16
|
+
};
|
|
17
|
+
async run() {
|
|
18
|
+
const { args, flags } = await this.parse(BenchmarkGet);
|
|
19
|
+
const client = this.makeClient(flags);
|
|
20
|
+
let run;
|
|
21
|
+
try {
|
|
22
|
+
run = flags.wait
|
|
23
|
+
? await followRun(client, args.run_id, (line) => this.jsonEnabled() || process.stderr.write(` ${line}\n`))
|
|
24
|
+
: (await client.get(`${BENCHMARK_RUNS}/${seg(args.run_id)}`));
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
if (err instanceof FacesAPIError) {
|
|
28
|
+
if (err.statusCode === 404)
|
|
29
|
+
this.error(`No benchmark run '${args.run_id}'. List yours with: faces benchmark:list`);
|
|
30
|
+
this.error(benchmarkError(err));
|
|
31
|
+
}
|
|
32
|
+
throw err;
|
|
33
|
+
}
|
|
34
|
+
if (run.status === 'failed')
|
|
35
|
+
process.exitCode = 1;
|
|
36
|
+
if (this.jsonEnabled())
|
|
37
|
+
return run;
|
|
38
|
+
for (const line of runLines(run))
|
|
39
|
+
this.log(line);
|
|
40
|
+
return run;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
export default class BenchmarkList extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static flags: {
|
|
5
|
+
face: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
6
|
+
limit: import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
11
|
+
};
|
|
12
|
+
run(): Promise<unknown>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import { BaseCommand } from '../../base.js';
|
|
3
|
+
import { FacesAPIError } from '../../client.js';
|
|
4
|
+
import { BENCHMARK_RUNS, benchmarkError } from '../../benchmark.js';
|
|
5
|
+
import { table } from '../../utils.js';
|
|
6
|
+
export default class BenchmarkList extends BaseCommand {
|
|
7
|
+
static description = 'List your benchmark runs, newest first.';
|
|
8
|
+
static flags = {
|
|
9
|
+
...BaseCommand.baseFlags,
|
|
10
|
+
face: Flags.string({ description: 'Only runs on this face' }),
|
|
11
|
+
limit: Flags.integer({ description: 'How many to list (1-100, default: 20)', default: 20, min: 1, max: 100 }),
|
|
12
|
+
};
|
|
13
|
+
async run() {
|
|
14
|
+
const { flags } = await this.parse(BenchmarkList);
|
|
15
|
+
const client = this.makeClient(flags);
|
|
16
|
+
const params = new URLSearchParams({ limit: String(flags.limit) });
|
|
17
|
+
if (flags.face)
|
|
18
|
+
params.set('self_face', flags.face);
|
|
19
|
+
let data;
|
|
20
|
+
try {
|
|
21
|
+
data = (await client.get(`${BENCHMARK_RUNS}?${params}`));
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
if (err instanceof FacesAPIError)
|
|
25
|
+
this.error(benchmarkError(err));
|
|
26
|
+
throw err;
|
|
27
|
+
}
|
|
28
|
+
if (this.jsonEnabled())
|
|
29
|
+
return data;
|
|
30
|
+
const runs = data.runs ?? [];
|
|
31
|
+
if (runs.length === 0) {
|
|
32
|
+
this.log(`No benchmark runs${flags.face ? ` on '${flags.face}'` : ''}. Price one with: faces benchmark:start <alias> --dry-run`);
|
|
33
|
+
return data;
|
|
34
|
+
}
|
|
35
|
+
const rows = runs.map((r) => [
|
|
36
|
+
r.run_id,
|
|
37
|
+
r.self_face ?? '-',
|
|
38
|
+
r.reference_model ?? '-',
|
|
39
|
+
r.status ?? '-',
|
|
40
|
+
String(r.result?.winner ?? '-'),
|
|
41
|
+
String(r.created_at ?? '').slice(0, 10) || '-',
|
|
42
|
+
]);
|
|
43
|
+
for (const line of table(['RUN', 'FACE', 'REFERENCE', 'STATUS', 'WINNER', 'STARTED'], rows))
|
|
44
|
+
this.log(line);
|
|
45
|
+
return data;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
export default class BenchmarkStart extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static flags: {
|
|
6
|
+
model: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
'reference-model': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
rounds: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
seed: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
'max-spend': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
'dry-run': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
12
|
+
wait: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
13
|
+
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
|
+
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
15
|
+
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
16
|
+
toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
17
|
+
};
|
|
18
|
+
static args: {
|
|
19
|
+
alias: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
20
|
+
};
|
|
21
|
+
run(): Promise<unknown>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import { BaseCommand } from '../../base.js';
|
|
3
|
+
import { FacesAPIError } from '../../client.js';
|
|
4
|
+
import { BENCHMARK_RUNS, benchmarkError, followRun, runLines } from '../../benchmark.js';
|
|
5
|
+
import { usd } from '../../utils.js';
|
|
6
|
+
export default class BenchmarkStart extends BaseCommand {
|
|
7
|
+
static description = 'Benchmark a face you own against a reference model, on the face\'s own material: over many rounds, ' +
|
|
8
|
+
'which sounds more like the person, by how much, and how sure. The face needs something compiled and ' +
|
|
9
|
+
'a built style. Paid from credits; on Connect or Pro with ChatGPT linked, calls to Codex-eligible models ' +
|
|
10
|
+
'run on the ChatGPT plan. See the price first with --dry-run, and cap a run with --max-spend.';
|
|
11
|
+
static examples = [
|
|
12
|
+
'<%= config.bin %> <%= command.id %> alice --dry-run',
|
|
13
|
+
'<%= config.bin %> <%= command.id %> alice --rounds 50 --max-spend 5 --wait',
|
|
14
|
+
];
|
|
15
|
+
static flags = {
|
|
16
|
+
...BaseCommand.baseFlags,
|
|
17
|
+
model: Flags.string({ description: 'The model the face answers with (default: chosen by the server; the run reports which)' }),
|
|
18
|
+
'reference-model': Flags.string({ description: 'The model to compare the face against (default: one of OpenAI\'s; the run reports which)' }),
|
|
19
|
+
rounds: Flags.integer({ description: 'How many rounds to run (1-300, default: 100)', min: 1, max: 300 }),
|
|
20
|
+
seed: Flags.integer({ description: 'Draw the same rounds as an earlier run, so the two compare. Omit for a fresh draw.' }),
|
|
21
|
+
'max-spend': Flags.string({ description: 'A hard ceiling in USD. When it is reached the run stops and reports what it scored.' }),
|
|
22
|
+
'dry-run': Flags.boolean({ description: 'Print the estimated price without starting anything', default: false }),
|
|
23
|
+
wait: Flags.boolean({ description: 'Wait for the run to finish and print the result', default: false }),
|
|
24
|
+
};
|
|
25
|
+
static args = {
|
|
26
|
+
alias: Args.string({ description: 'Alias of a face you own', required: true }),
|
|
27
|
+
};
|
|
28
|
+
async run() {
|
|
29
|
+
const { args, flags } = await this.parse(BenchmarkStart);
|
|
30
|
+
const client = this.makeClient(flags);
|
|
31
|
+
const body = { self_face: args.alias };
|
|
32
|
+
if (flags.model)
|
|
33
|
+
body.model = flags.model;
|
|
34
|
+
if (flags['reference-model'])
|
|
35
|
+
body.reference_model = flags['reference-model'];
|
|
36
|
+
if (flags.rounds !== undefined)
|
|
37
|
+
body.rounds = flags.rounds;
|
|
38
|
+
if (flags.seed !== undefined)
|
|
39
|
+
body.seed = flags.seed;
|
|
40
|
+
if (flags['max-spend'] !== undefined) {
|
|
41
|
+
const cap = Number(flags['max-spend']);
|
|
42
|
+
if (!Number.isFinite(cap) || cap <= 0)
|
|
43
|
+
this.error(`--max-spend is an amount in USD above 0 (got "${flags['max-spend']}").`);
|
|
44
|
+
body.max_spend_usd = cap;
|
|
45
|
+
}
|
|
46
|
+
if (flags['dry-run'])
|
|
47
|
+
body.dry_run = true;
|
|
48
|
+
let data;
|
|
49
|
+
try {
|
|
50
|
+
data = (await client.post(BENCHMARK_RUNS, { body }));
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
if (err instanceof FacesAPIError)
|
|
54
|
+
this.error(benchmarkError(err, args.alias));
|
|
55
|
+
throw err;
|
|
56
|
+
}
|
|
57
|
+
if (flags['dry-run']) {
|
|
58
|
+
if (this.jsonEnabled())
|
|
59
|
+
return data;
|
|
60
|
+
this.log(`About ${usd(data.estimated_usd)} for ${data.rounds} rounds on '${args.alias}', from credits.`);
|
|
61
|
+
if (data.note)
|
|
62
|
+
this.log(String(data.note));
|
|
63
|
+
return data;
|
|
64
|
+
}
|
|
65
|
+
const id = String(data.run_id);
|
|
66
|
+
if (!flags.wait) {
|
|
67
|
+
if (this.jsonEnabled())
|
|
68
|
+
return data;
|
|
69
|
+
this.log(`Started benchmark ${id}.`);
|
|
70
|
+
this.log(`Follow it with: faces benchmark:get ${id} --wait`);
|
|
71
|
+
return data;
|
|
72
|
+
}
|
|
73
|
+
const run = await followRun(client, id, (line) => this.jsonEnabled() || process.stderr.write(` ${line}\n`));
|
|
74
|
+
if (this.jsonEnabled())
|
|
75
|
+
return run;
|
|
76
|
+
for (const line of runLines(run))
|
|
77
|
+
this.log(line);
|
|
78
|
+
return run;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
export default class BillingBalance extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static flags: {
|
|
5
|
+
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
6
|
+
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
9
|
+
};
|
|
10
|
+
run(): Promise<unknown>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
import { FacesAPIError } from '../../client.js';
|
|
3
|
+
import { usd } from '../../utils.js';
|
|
4
|
+
export default class BillingBalance extends BaseCommand {
|
|
5
|
+
static description = 'Show credit balance and payment method status';
|
|
6
|
+
static flags = {
|
|
7
|
+
...BaseCommand.baseFlags,
|
|
8
|
+
};
|
|
9
|
+
async run() {
|
|
10
|
+
const { flags } = await this.parse(BillingBalance);
|
|
11
|
+
const client = this.makeClient(flags);
|
|
12
|
+
let data;
|
|
13
|
+
try {
|
|
14
|
+
data = await client.get('/v1/billing/balance');
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
if (err instanceof FacesAPIError)
|
|
18
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}`);
|
|
19
|
+
throw err;
|
|
20
|
+
}
|
|
21
|
+
if (!this.jsonEnabled()) {
|
|
22
|
+
const d = data;
|
|
23
|
+
this.printHuman({ ...d, balance_usd: typeof d.balance_usd === 'number' ? usd(d.balance_usd) : d.balance_usd });
|
|
24
|
+
}
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseCommand } from '../../../base.js';
|
|
2
|
+
export default class BillingCardDefault extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static flags: {
|
|
6
|
+
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
10
|
+
};
|
|
11
|
+
static args: {
|
|
12
|
+
card_id: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
13
|
+
};
|
|
14
|
+
run(): Promise<unknown>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Args } from '@oclif/core';
|
|
2
|
+
import { BaseCommand } from '../../../base.js';
|
|
3
|
+
import { FacesAPIError } from '../../../client.js';
|
|
4
|
+
import { seg } from '../../../utils.js';
|
|
5
|
+
export default class BillingCardDefault extends BaseCommand {
|
|
6
|
+
static description = 'Make a saved card the default: the next renewal, and any top-up that names no card, charges it';
|
|
7
|
+
static examples = ['<%= config.bin %> <%= command.id %> pm_EXAMPLE'];
|
|
8
|
+
static flags = {
|
|
9
|
+
...BaseCommand.baseFlags,
|
|
10
|
+
};
|
|
11
|
+
static args = {
|
|
12
|
+
card_id: Args.string({ description: 'Card id (pm_...), from faces billing:cards', required: true }),
|
|
13
|
+
};
|
|
14
|
+
async run() {
|
|
15
|
+
const { args, flags } = await this.parse(BillingCardDefault);
|
|
16
|
+
const client = this.makeClient(flags);
|
|
17
|
+
let data;
|
|
18
|
+
try {
|
|
19
|
+
data = await client.post(`/v1/billing/payment-methods/${seg(args.card_id)}/default`);
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
if (err instanceof FacesAPIError) {
|
|
23
|
+
if (err.statusCode === 404)
|
|
24
|
+
this.error(`HTTP 404: ${err.message}\nList your cards with: faces billing:cards`);
|
|
25
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}`);
|
|
26
|
+
}
|
|
27
|
+
throw err;
|
|
28
|
+
}
|
|
29
|
+
if (!this.jsonEnabled())
|
|
30
|
+
this.log(`${args.card_id} is now the default card.`);
|
|
31
|
+
return data;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BaseCommand } from '../../../base.js';
|
|
2
|
+
export default class BillingCardRemove extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static flags: {
|
|
6
|
+
yes: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
7
|
+
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
11
|
+
};
|
|
12
|
+
static args: {
|
|
13
|
+
card_id: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
14
|
+
};
|
|
15
|
+
run(): Promise<unknown>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import { BaseCommand } from '../../../base.js';
|
|
3
|
+
import { FacesAPIError } from '../../../client.js';
|
|
4
|
+
import { seg } from '../../../utils.js';
|
|
5
|
+
export default class BillingCardRemove extends BaseCommand {
|
|
6
|
+
static description = 'Remove a saved card. Removing the default makes the newest other card the default. The last card ' +
|
|
7
|
+
'cannot be removed while a paid subscription renews on it.';
|
|
8
|
+
static examples = ['<%= config.bin %> <%= command.id %> pm_EXAMPLE --yes'];
|
|
9
|
+
static flags = {
|
|
10
|
+
...BaseCommand.baseFlags,
|
|
11
|
+
yes: Flags.boolean({ description: 'Skip confirmation', default: false }),
|
|
12
|
+
};
|
|
13
|
+
static args = {
|
|
14
|
+
card_id: Args.string({ description: 'Card id (pm_...), from faces billing:cards', required: true }),
|
|
15
|
+
};
|
|
16
|
+
async run() {
|
|
17
|
+
const { args, flags } = await this.parse(BillingCardRemove);
|
|
18
|
+
const client = this.makeClient(flags);
|
|
19
|
+
await this.confirmOrRefuse(`Remove card ${args.card_id}?`, flags.yes);
|
|
20
|
+
let data;
|
|
21
|
+
try {
|
|
22
|
+
data = await client.delete(`/v1/billing/payment-methods/${seg(args.card_id)}`);
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
if (err instanceof FacesAPIError) {
|
|
26
|
+
if (err.statusCode === 404)
|
|
27
|
+
this.error(`HTTP 404: ${err.message}\nList your cards with: faces billing:cards`);
|
|
28
|
+
if (err.statusCode === 409) {
|
|
29
|
+
this.error(`HTTP 409: ${err.message}\n` +
|
|
30
|
+
'Add another card first (faces billing:card-setup), or cancel the subscription ' +
|
|
31
|
+
'(faces billing:subscription:cancel).');
|
|
32
|
+
}
|
|
33
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}`);
|
|
34
|
+
}
|
|
35
|
+
throw err;
|
|
36
|
+
}
|
|
37
|
+
if (!this.jsonEnabled())
|
|
38
|
+
this.log(`Removed ${args.card_id}. See what is left with: faces billing:cards`);
|
|
39
|
+
return data;
|
|
40
|
+
}
|
|
41
|
+
}
|