@fluid-app/fluid-cli 0.1.656 → 0.1.658
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/bin/fluid.mjs +2 -2
- package/dist/bin/fluid.mjs.map +1 -1
- package/dist/{hook-r99vp1GM.mjs → hook-B6o5hxNW.mjs} +34 -4
- package/dist/hook-B6o5hxNW.mjs.map +1 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/dist/hook-r99vp1GM.mjs.map +0 -1
|
@@ -106,7 +106,7 @@ function filterCatalog(entries, root, prefix) {
|
|
|
106
106
|
}
|
|
107
107
|
//#endregion
|
|
108
108
|
//#region package.json
|
|
109
|
-
var version = "0.1.
|
|
109
|
+
var version = "0.1.658";
|
|
110
110
|
//#endregion
|
|
111
111
|
//#region src/auth/client-headers.ts
|
|
112
112
|
const CLIENT_HEADERS = {
|
|
@@ -249,8 +249,9 @@ function createApiError(template, details) {
|
|
|
249
249
|
*/
|
|
250
250
|
async function validateToken(token, options = {}) {
|
|
251
251
|
const { signal, cleanup } = makeSignal();
|
|
252
|
+
const apiBase = options.baseUrl ?? getFluidApiBase();
|
|
252
253
|
try {
|
|
253
|
-
const response = await fetch(`${
|
|
254
|
+
const response = await fetch(`${apiBase}/api/company/v1/companies/me`, {
|
|
254
255
|
method: "GET",
|
|
255
256
|
headers: {
|
|
256
257
|
...CLIENT_HEADERS,
|
|
@@ -263,7 +264,8 @@ async function validateToken(token, options = {}) {
|
|
|
263
264
|
if (!name) return failure(createApiError(FLUID_API_ERROR.API_UNREACHABLE, "Unexpected response shape from /companies/me"));
|
|
264
265
|
return success({ name });
|
|
265
266
|
}
|
|
266
|
-
if (response.status ===
|
|
267
|
+
if (response.status === 403) return await staffCompanyFromMe(token, apiBase, signal);
|
|
268
|
+
if (response.status === 401) return failure(createApiError(FLUID_API_ERROR.INVALID_TOKEN, `HTTP ${response.status}: Check that your token is valid and non-expired.`));
|
|
267
269
|
const body = await response.text();
|
|
268
270
|
return failure(createApiError(FLUID_API_ERROR.API_UNREACHABLE, `HTTP ${response.status}: ${body}`));
|
|
269
271
|
} catch (err) {
|
|
@@ -273,6 +275,34 @@ async function validateToken(token, options = {}) {
|
|
|
273
275
|
cleanup();
|
|
274
276
|
}
|
|
275
277
|
}
|
|
278
|
+
/** The roles a CLI login may hold, as `/api/me` names them. */
|
|
279
|
+
const STAFF_ROLES = new Set(["admin", "rep"]);
|
|
280
|
+
/**
|
|
281
|
+
* The company of an admin's or a rep's login, from `/api/me`. A token it
|
|
282
|
+
* refuses, or one that belongs to a customer, is invalid for the CLI; any
|
|
283
|
+
* other failure, or an answer with no company name, leaves the API
|
|
284
|
+
* unreachable, as `/companies/me` does.
|
|
285
|
+
*/
|
|
286
|
+
async function staffCompanyFromMe(token, apiBase, signal) {
|
|
287
|
+
const response = await fetch(`${apiBase}/api/me`, {
|
|
288
|
+
method: "GET",
|
|
289
|
+
headers: {
|
|
290
|
+
...CLIENT_HEADERS,
|
|
291
|
+
Authorization: `Bearer ${token}`
|
|
292
|
+
},
|
|
293
|
+
signal
|
|
294
|
+
});
|
|
295
|
+
if (response.status === 401 || response.status === 403) return failure(createApiError(FLUID_API_ERROR.INVALID_TOKEN, `HTTP ${response.status}: Check that your token is valid and non-expired.`));
|
|
296
|
+
if (!response.ok) {
|
|
297
|
+
const body = await response.text();
|
|
298
|
+
return failure(createApiError(FLUID_API_ERROR.API_UNREACHABLE, `HTTP ${response.status} from /api/me: ${body}`));
|
|
299
|
+
}
|
|
300
|
+
const data = await response.json();
|
|
301
|
+
if (typeof data?.role !== "string" || !STAFF_ROLES.has(data.role)) return failure(createApiError(FLUID_API_ERROR.INVALID_TOKEN, "This login is not an admin's or a rep's, so it cannot be used with the CLI."));
|
|
302
|
+
const name = data.company?.name;
|
|
303
|
+
if (typeof name !== "string" || name === "") return failure(createApiError(FLUID_API_ERROR.API_UNREACHABLE, "Unexpected response shape from /api/me"));
|
|
304
|
+
return success({ name });
|
|
305
|
+
}
|
|
276
306
|
/**
|
|
277
307
|
* Send a multi-factor authentication code to the given email address.
|
|
278
308
|
* The API answers 201 whether or not the address can sign in
|
|
@@ -3921,4 +3951,4 @@ function exitOnInputsError(error, io = processIo) {
|
|
|
3921
3951
|
//#endregion
|
|
3922
3952
|
export { isError as $, identityToken as A, isIdentityProfile as B, readConfig as C, getConfigDir as D, isStrictConfig as E, signInWithBrowser as F, getFluidApiBase as G, SIGNUP_ERROR as H, signOutIdentity as I, signup as J, redeemIdentityLink as K, resolveIdentityUrl as L, primeIdentityProfile as M, profileAccessToken as N, getConfigFilePath as O, sessionFacts as P, getErrorMessage$1 as Q, createFetchClient as R, findProjectConfig as S, writeConfig as T, confirmMfa as U, FLUID_API_ERROR as V, fetchUserCompanies as W, validateToken as X, switchCompany as Y, failure as Z, getAuthToken as _, INPUTS_UNDECLARED_CODE as a, success as at, listProfileNames as b, inputsModeActive as c, unwrap as ct, setActiveSnapshot as d, rootCommand as dt, isFailure as et, inInternalRead as f, visibleOptions as ft, getActiveProfile as g, declareInputs as h, describeCommand as ht, INPUTS_MODE_ENV as i, mapResult as it, isRoleNotGrantedError as j, describeIdentityError as k, registerInputsHook as l, unwrapOr as lt, withInternalReadsAsync as m, walkCommands as mt, INPUTS_MISMATCH_CODE as n, isSuccess as nt, INPUTS_UNDECLARED_EXIT as o, tryCatch as ot, withInternalReads as p, visibleSubcommands as pt, sendMfa as q, INPUTS_MISMATCH_EXIT as r, mapError as rt, exitOnInputsError as s, tryCatchAsync as st, INPUTS_EXPECT_ENV as t, isNodeError as tt, createInputsReader as u, filterCatalog as ut, getAuthTokenAsync as v, updateConfig as w, resolveCredentialSource as x, getRoleAuthTokenAsync as y, createDefaultConfig as z };
|
|
3923
3953
|
|
|
3924
|
-
//# sourceMappingURL=hook-
|
|
3954
|
+
//# sourceMappingURL=hook-B6o5hxNW.mjs.map
|