@ultimat3/policy 31.35.0 → 31.36.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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/errors.ts +10 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/policy",
3
- "version": "31.35.0",
3
+ "version": "31.36.0",
4
4
  "description": "The one authz rule, evaluated identically in every surface",
5
5
  "keywords": [
6
6
  "ultimate",
@@ -42,6 +42,6 @@
42
42
  "test": "bun test"
43
43
  },
44
44
  "dependencies": {
45
- "@ultimat3/core": "31.35.0"
45
+ "@ultimat3/core": "31.36.0"
46
46
  }
47
47
  }
package/src/errors.ts CHANGED
@@ -159,7 +159,7 @@ export const policyMissing = (subject: string): PolicyError =>
159
159
  new PolicyError({
160
160
  code: 'X_POLICY_MISSING',
161
161
  cause: `${subject} has no policy; an action without a policy is a build error, not a public endpoint`,
162
- fix: `add policy: can('<resource>:<verb>') to ${subject}, or allow('public') to say so explicitly`,
162
+ fix: `policy: can('<resource>:<verb>') // on ${subject} — or policy: allow('public') to say so explicitly`,
163
163
  });
164
164
 
165
165
  /**
@@ -182,6 +182,10 @@ export const roleRedefined = (role: string, first: string, second: string): Poli
182
182
  * failure moves from this throw to a page that renders empty. Only the generated `policy.test.ts`
183
183
  * caught it. A typo is by far the likelier of the two readings, so it leads.
184
184
  */
185
+ /** A permission as a JS string literal to paste: single-quoted, unless the name holds one. */
186
+ const jsString = (value: string): string =>
187
+ value.includes("'") ? JSON.stringify(value) : `'${value}'`;
188
+
185
189
  export const permissionUnknown = (permission: string, known: readonly string[]): PolicyError => {
186
190
  const nearest = nearestName(permission, known);
187
191
  return new PolicyError({
@@ -191,8 +195,8 @@ export const permissionUnknown = (permission: string, known: readonly string[]):
191
195
  cause: `"${permission}" is not in the permission set (${known.length} known)`,
192
196
  fix:
193
197
  nearest === undefined
194
- ? `add '${permission}' to definePermissions([...]) if it is genuinely new — otherwise x policy list --json shows the ${known.length} already declared`
195
- : `use '${nearest}', the nearest declared permission — or add '${permission}' to definePermissions([...]) if it is genuinely new`,
198
+ ? `definePermissions([${jsString(permission)}]) // if it is genuinely new: a second call merges — otherwise x policy list --json shows the ${known.length} already declared`
199
+ : `can(${jsString(nearest)}) // the nearest declared permission, wherever ${jsString(permission)} is written — or, if it is genuinely new: definePermissions([${jsString(permission)}])`,
196
200
  });
197
201
  };
198
202
 
@@ -224,8 +228,8 @@ export const emptyClauseList = (combinator: 'and' | 'or'): PolicyError =>
224
228
  : 'or() was built with no clauses, so it denies every actor and names no clause that could have allowed one',
225
229
  fix:
226
230
  combinator === 'and'
227
- ? "write allow('public') if every caller may act — otherwise pass the clauses the list was meant to hold: and(can('<resource>:<verb>'), …)"
228
- : "write deny('<why nobody may act>') if nobody may act — otherwise pass the clauses the list was meant to hold: or(can('<resource>:<verb>'), …)",
231
+ ? "allow('public') // if every caller may act — otherwise pass the clauses the list was meant to hold: and(can('<resource>:<verb>'), …)"
232
+ : "deny('<why nobody may act>') // if nobody may act — otherwise pass the clauses the list was meant to hold: or(can('<resource>:<verb>'), …)",
229
233
  });
230
234
 
231
235
  /**
@@ -244,7 +248,7 @@ export const surfaceUnknown = (surface: unknown, known: readonly string[]): Poli
244
248
  new PolicyError({
245
249
  code: 'X_POLICY_SURFACE_UNKNOWN',
246
250
  cause: `enforce() was handed surface ${renderCauseValue(surface)}, which no policy adapter answers to`,
247
- fix: `pass one of ${known.join(', ')} — e.g. enforce('${known[0] ?? 'http'}', policy, args)`,
251
+ fix: `enforce('${known[0] ?? 'http'}', policy, args) // the surface is one of ${known.join(', ')}`,
248
252
  });
249
253
 
250
254
  /**