@lessly/sdk-app 63.2.3 → 63.2.4

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.
@@ -16,5 +16,12 @@ import type { Operation } from './types.js';
16
16
  * to read it from, and `level:undefined` in front of a user is worse than saying less. It is a
17
17
  * DEGRADATION, not an equal input — an App whose every gate holds an `Operation` never reaches for
18
18
  * it, and that is the normal shape, not an omission.
19
+ *
20
+ * It never throws and never renders the words `undefined` or `null`. A render helper that crashes
21
+ * takes a whole screen with it, so the input is checked at runtime rather than trusted from the
22
+ * type: an object with a usable key but no usable level degrades to the key-only sentence, and
23
+ * anything with no usable key at all falls back to "Not available for your role." — plus one
24
+ * `console.warn` outside production, because the caller has a bug worth seeing. The public type
25
+ * stays `Operation | string`; the widening is internal, and passing anything else is still wrong.
19
26
  */
20
27
  export declare function accessReason(op: Operation | string): string;
package/dist/index.cjs CHANGED
@@ -11263,8 +11263,30 @@ function createLesslyApp(opts) {
11263
11263
  }
11264
11264
 
11265
11265
  // src/runtime/access-reason.ts
11266
+ var LEVELS2 = ["read", "write", "admin"];
11267
+ var isNonEmptyString = (value) => typeof value === "string" && value.trim() !== "";
11268
+ var isLevel = (value) => typeof value === "string" && LEVELS2.includes(value);
11269
+ function warnDegenerate(input) {
11270
+ if (typeof process !== "undefined" && process.env?.NODE_ENV !== "production") {
11271
+ console.warn("accessReason: degenerate input", input);
11272
+ }
11273
+ }
11266
11274
  function accessReason(op) {
11267
- return typeof op === "string" ? `Requires access to ${op}. Ask an admin of this product.` : `Requires level:${op.level} (${op.operationKey}). Ask an admin of this product.`;
11275
+ if (isNonEmptyString(op)) {
11276
+ return `Requires access to ${op}. Ask an admin of this product.`;
11277
+ }
11278
+ if (op !== null && (typeof op === "object" || typeof op === "function")) {
11279
+ const { operationKey, level } = op;
11280
+ if (isNonEmptyString(operationKey)) {
11281
+ if (isLevel(level)) {
11282
+ return `Requires level:${level} (${operationKey}). Ask an admin of this product.`;
11283
+ }
11284
+ warnDegenerate(op);
11285
+ return `Requires access to ${operationKey}. Ask an admin of this product.`;
11286
+ }
11287
+ }
11288
+ warnDegenerate(op);
11289
+ return "Not available for your role. Ask an admin of this product.";
11268
11290
  }
11269
11291
 
11270
11292
  // src/runtime/operations.ts