@faable/faable 1.5.31 → 1.5.33

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/dist/api/auth.js CHANGED
@@ -13,5 +13,14 @@ async function getDeviceToken(device_code) {
13
13
  const res = await api.post(`/oauth/token`, { device_code, client_id: CLIENT_ID, grant_type: "urn:ietf:params:oauth:grant-type:device_code" });
14
14
  return res.data;
15
15
  }
16
+ // Validate a device-flow access token against the Faable Auth server. The token
17
+ // is issued by the auth server, so it must be introspected there — NOT against
18
+ // the deploy API (api.faable.com), which has no /me route and would 404.
19
+ async function getMe(access_token) {
20
+ const res = await api.get(`/me`, {
21
+ headers: { Authorization: `Bearer ${access_token}` },
22
+ });
23
+ return res.data;
24
+ }
16
25
 
17
- export { getDeviceCode, getDeviceToken };
26
+ export { getDeviceCode, getDeviceToken, getMe };
@@ -29,6 +29,10 @@ const deploy = {
29
29
  const workdir = args.workdir || process.cwd();
30
30
  const ctx = await context();
31
31
  const { api } = ctx;
32
+ if (!api) {
33
+ log.error("❌ Not logged in. Run 'faable login' first.");
34
+ process.exit(1);
35
+ }
32
36
  // Resolve runtime
33
37
  const { runtime } = await runtime_detection(workdir);
34
38
  // app_id resolution (the user never has to look one up):
@@ -61,6 +61,10 @@ const link = {
61
61
  }
62
62
  }
63
63
  const { api } = await context();
64
+ if (!api) {
65
+ log.error("❌ Not logged in. Run 'faable login' first.");
66
+ process.exit(1);
67
+ }
64
68
  log.info("Checking local git repository...");
65
69
  const gitUrl = await getGitRemoteUrl(workdir);
66
70
  const apps = await api.list();
@@ -1,7 +1,6 @@
1
1
  import { FaableApi } from '../../api/FaableApi.js';
2
- import { getDeviceCode, getDeviceToken } from '../../api/auth.js';
2
+ import { getDeviceCode, getDeviceToken, getMe } from '../../api/auth.js';
3
3
  import { CredentialsStore } from '../../lib/CredentialsStore.js';
4
- import { bearer_strategy } from '../../api/strategies/bearer.strategy.js';
5
4
  import open from 'open';
6
5
  import ora from 'ora';
7
6
  import { log } from '../../log.js';
@@ -123,11 +122,9 @@ const login = {
123
122
  const { access_token } = await getDeviceToken(device_code);
124
123
  if (access_token) {
125
124
  spinner.stop();
126
- const tempApi = FaableApi.create({
127
- auth: { token: access_token },
128
- authStrategy: bearer_strategy,
129
- });
130
- const me = await tempApi.getMe();
125
+ // Validate the freshly issued token against the Auth server (it
126
+ // issued the token). The deploy API has no /me route.
127
+ const me = await getMe(access_token);
131
128
  await store.saveCredentials({ token: access_token, email: me.email });
132
129
  log.info(`✅ Successfully logged in as ${me.email}`);
133
130
  return;
@@ -1,17 +1,29 @@
1
1
  import { log } from '../../log.js';
2
- import { context } from '../../api/context.js';
2
+ import { getMe } from '../../api/auth.js';
3
+ import { CredentialsStore } from '../../lib/CredentialsStore.js';
3
4
 
4
5
  const whoami = {
5
6
  command: "whoami",
6
7
  describe: "Display the current logged in user",
7
8
  handler: async () => {
8
- const { api } = await context();
9
- if (!api) {
9
+ const store = new CredentialsStore();
10
+ const config = await store.loadCredentials();
11
+ // Bearer token from the environment (CI) or a local `faable login`.
12
+ const token = process.env.FAABLE_TOKEN || config?.token;
13
+ if (!token) {
14
+ // API-key sessions can't be introspected at the auth server's /me; fall
15
+ // back to the email captured at login time.
16
+ if (config?.apikey && config.email) {
17
+ log.info(`Logged in as: ${config.email} (API key)`);
18
+ return;
19
+ }
10
20
  log.error("❌ Not logged in. Run 'faable login' first.");
11
21
  process.exit(1);
12
22
  }
13
23
  try {
14
- const me = await api.getMe();
24
+ // Validate against the Auth server (it issued the token); the deploy API
25
+ // has no /me route.
26
+ const me = await getMe(token);
15
27
  log.info(`Logged in as: ${me.email}`);
16
28
  }
17
29
  catch {
package/dist/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import yargs from 'yargs';
2
2
  import { hideBin } from 'yargs/helpers';
3
3
  import { deploy } from './commands/deploy/index.js';
4
- import { init } from './commands/init/index.js';
5
4
  import { link } from './commands/link/index.js';
6
5
  import { login } from './commands/login/index.js';
7
6
  import { logout } from './commands/logout/index.js';
@@ -34,7 +33,6 @@ yg.scriptName('faable')
34
33
  .command(login)
35
34
  .command(logout)
36
35
  .command(whoami)
37
- .command(init)
38
36
  .command(link)
39
37
  .demandCommand(1)
40
38
  .help()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faable/faable",
3
- "version": "1.5.31",
3
+ "version": "1.5.33",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "author": "Marc Pomar <marc@faable.com>",
@@ -1,35 +0,0 @@
1
- import prompts from 'prompts';
2
- import { CredentialsStore } from '../../lib/CredentialsStore.js';
3
-
4
- const init = {
5
- command: 'init',
6
- describe: 'Initialize Faable with API Key',
7
- builder: yargs => {
8
- return yargs.showHelpOnFail(false);
9
- },
10
- handler: async () => {
11
- const store = new CredentialsStore();
12
- const creds = await store.loadCredentials();
13
- if (creds?.apikey) {
14
- const { overwrite } = await prompts({
15
- type: 'confirm',
16
- name: 'overwrite',
17
- message: 'An API key already exists. Do you want to overwrite it?',
18
- initial: false
19
- });
20
- if (!overwrite) {
21
- return;
22
- }
23
- }
24
- const { apikey } = await prompts([
25
- {
26
- type: 'text',
27
- name: 'apikey',
28
- message: 'What is your Faable ApiKey?'
29
- }
30
- ]);
31
- await store.saveCredentials({ apikey });
32
- }
33
- };
34
-
35
- export { init };