@fluid-app/fluid-cli 0.1.345 → 0.1.347

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.
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { A as sendMfa, C as isIdentityProfile, D as fetchUserCompanies, E as confirmMfa, J as rootCommand, M as switchCompany, N as validateToken, O as getFluidApiBase, X as visibleSubcommands, Y as visibleOptions, Z as walkCommands, _ as sessionFacts, a as resolveCredentialSource, b as resolveIdentityUrl, c as updateConfig, d as getConfigDir, h as primeIdentityProfile, j as signup, k as redeemIdentityLink, l as writeConfig, m as identityToken, n as getAuthToken, p as describeIdentityError, q as filterCatalog, s as readConfig, t as getActiveProfile, u as isStrictConfig, v as signInWithBrowser, w as FLUID_API_ERROR, y as signOutIdentity } from "../token-CJxacCS4.mjs";
2
+ import { A as sendMfa, C as isIdentityProfile, D as fetchUserCompanies, E as confirmMfa, J as rootCommand, M as switchCompany, N as validateToken, O as getFluidApiBase, X as visibleSubcommands, Y as visibleOptions, Z as walkCommands, _ as sessionFacts, a as resolveCredentialSource, b as resolveIdentityUrl, c as updateConfig, d as getConfigDir, h as primeIdentityProfile, j as signup, k as redeemIdentityLink, l as writeConfig, m as identityToken, n as getAuthToken, p as describeIdentityError, q as filterCatalog, s as readConfig, t as getActiveProfile, u as isStrictConfig, v as signInWithBrowser, w as FLUID_API_ERROR, y as signOutIdentity } from "../token-DgwRaKgP.mjs";
3
3
  import { createRequire } from "node:module";
4
4
  import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
5
5
  import { fileURLToPath, pathToFileURL } from "node:url";
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { A as sendMfa, B as mapError, C as isIdentityProfile, D as fetchUserCompanies, E as confirmMfa, F as getErrorMessage, G as unwrap, H as success, I as isError, K as unwrapOr, L as isFailure, M as switchCompany, N as validateToken, O as getFluidApiBase, P as failure, Q as describeCommand, R as isNodeError, S as createDefaultConfig, T as SIGNUP_ERROR, U as tryCatch, V as mapResult, W as tryCatchAsync, Z as walkCommands, a as resolveCredentialSource, c as updateConfig, d as getConfigDir, f as getConfigFilePath, g as profileAccessToken, i as listProfileNames, j as signup, l as writeConfig, n as getAuthToken, o as findProjectConfig, r as getAuthTokenAsync, s as readConfig, t as getActiveProfile, u as isStrictConfig, x as createFetchClient, z as isSuccess } from "./token-CJxacCS4.mjs";
1
+ import { A as sendMfa, B as mapError, C as isIdentityProfile, D as fetchUserCompanies, E as confirmMfa, F as getErrorMessage, G as unwrap, H as success, I as isError, K as unwrapOr, L as isFailure, M as switchCompany, N as validateToken, O as getFluidApiBase, P as failure, Q as describeCommand, R as isNodeError, S as createDefaultConfig, T as SIGNUP_ERROR, U as tryCatch, V as mapResult, W as tryCatchAsync, Z as walkCommands, a as resolveCredentialSource, c as updateConfig, d as getConfigDir, f as getConfigFilePath, g as profileAccessToken, i as listProfileNames, j as signup, l as writeConfig, n as getAuthToken, o as findProjectConfig, r as getAuthTokenAsync, s as readConfig, t as getActiveProfile, u as isStrictConfig, x as createFetchClient, z as isSuccess } from "./token-DgwRaKgP.mjs";
2
2
  import { Command } from "commander";
3
3
  import prompts from "prompts";
4
4
  //#region src/domain/output.ts
@@ -608,12 +608,66 @@ function toApiErrorBody(value) {
608
608
  /**
609
609
  * The single unwrap rule, shared by every producer of `ApiError`.
610
610
  *
611
- * `??` rather than `||` so an explicitly empty `errors` (`""`, `0`, `false`)
612
- * is preserved instead of silently falling back to the whole envelope.
611
+ * Rails sends two error envelopes. `ControllerAction#error_response` puts the
612
+ * bag under `errors`; `Api::Response.error` puts it under `error.details`,
613
+ * beside `error.message`. Both unwrap to the bag, `errors` first.
614
+ *
615
+ * `!= null` rather than a truthiness check so an explicitly empty `errors`
616
+ * (`""`, `0`, `false`) is preserved instead of silently falling back to the
617
+ * whole envelope.
618
+ * `details` is taken whatever its value, `null` included, so data from an
619
+ * `Api::Response` error is never the envelope.
613
620
  */
614
621
  function toApiErrorData(body) {
615
622
  if (!body) return null;
616
- return body.errors ?? body;
623
+ if (body.errors != null) return body.errors;
624
+ const error = toApiErrorBody(body.error);
625
+ if (error && error.details !== void 0) return withErrorMessage(toFieldErrorDetails(error.details), error.message);
626
+ return body;
627
+ }
628
+ /**
629
+ * `Api::Response` errors carry diagnostics such as `{ type: "not_provisioned" }`
630
+ * or `{ violations: [{ type, description }] }` in `details` as readily as
631
+ * field errors, and sometimes both. A field error is a list of message
632
+ * strings, at any depth, so only those entries make up the bag; an `errors`
633
+ * wrapper inside `details` is unwrapped as the envelope's own is. Details with
634
+ * no field error unwrap to an empty bag. The diagnostics stay on
635
+ * `ApiError.body`.
636
+ */
637
+ function toFieldErrorDetails(details) {
638
+ if (details === null) return null;
639
+ const record = toApiErrorBody(details);
640
+ const bag = record && record.errors != null ? toApiErrorBody(record.errors) : record;
641
+ return (bag && pickFieldErrors(bag)) ?? {};
642
+ }
643
+ /**
644
+ * Telling a field error from a diagnostic list such as
645
+ * `{ missing_keys: ["coupons.create"] }` by its content cannot be exact, so
646
+ * the bag also carries `error.message` as `{ error: { message } }`, after the
647
+ * field errors. `parseApiErrors` and the inlined `fluidToast` copies render
648
+ * that nested form first and without a field prefix, so the server's message
649
+ * is never hidden by whatever reaches the bag.
650
+ */
651
+ function withErrorMessage(fieldErrors, message) {
652
+ if (typeof message !== "string" || message.trim().length === 0) return fieldErrors;
653
+ const bag = toApiErrorBody(fieldErrors) ?? {};
654
+ if ("error" in bag) return fieldErrors;
655
+ return {
656
+ ...bag,
657
+ error: { message }
658
+ };
659
+ }
660
+ function pickFieldErrors(record) {
661
+ const picked = {};
662
+ for (const [key, value] of Object.entries(record)) {
663
+ const nested = toApiErrorBody(value);
664
+ const fieldErrors = isMessageList(value) ? value : nested && pickFieldErrors(nested);
665
+ if (fieldErrors) picked[key] = fieldErrors;
666
+ }
667
+ return Object.keys(picked).length > 0 ? picked : void 0;
668
+ }
669
+ function isMessageList(value) {
670
+ return Array.isArray(value) && value.length > 0 && value.every((message) => typeof message === "string");
617
671
  }
618
672
  //#endregion
619
673
  //#region ../../platform/api-client-core/src/fetch-client.ts
@@ -3278,4 +3332,4 @@ function listProfileNames() {
3278
3332
  //#endregion
3279
3333
  export { sendMfa as A, mapError as B, isIdentityProfile as C, fetchUserCompanies as D, confirmMfa as E, getErrorMessage$1 as F, unwrap as G, success as H, isError as I, rootCommand as J, unwrapOr as K, isFailure as L, switchCompany as M, validateToken as N, getFluidApiBase as O, failure as P, describeCommand as Q, isNodeError as R, createDefaultConfig as S, SIGNUP_ERROR as T, tryCatch as U, mapResult as V, tryCatchAsync as W, visibleSubcommands as X, visibleOptions as Y, walkCommands as Z, sessionFacts as _, resolveCredentialSource as a, resolveIdentityUrl as b, updateConfig as c, getConfigDir as d, getConfigFilePath as f, profileAccessToken as g, primeIdentityProfile as h, listProfileNames as i, signup as j, redeemIdentityLink as k, writeConfig as l, identityToken as m, getAuthToken as n, findProjectConfig as o, describeIdentityError as p, filterCatalog as q, getAuthTokenAsync as r, readConfig as s, getActiveProfile as t, isStrictConfig as u, signInWithBrowser as v, FLUID_API_ERROR as w, createFetchClient as x, signOutIdentity as y, isSuccess as z };
3280
3334
 
3281
- //# sourceMappingURL=token-CJxacCS4.mjs.map
3335
+ //# sourceMappingURL=token-DgwRaKgP.mjs.map