toolpass-client 0.11.2 → 0.12.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.
- package/README.md +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +7 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -48,6 +48,7 @@ Without a wrapper:
|
|
|
48
48
|
```ts
|
|
49
49
|
const d = await tp.check("dana@example.com", "jira-main", "DELETE_ISSUES", "issue:PAY-123");
|
|
50
50
|
d.decision, d.reason; // "deny", "denied: ..."
|
|
51
|
+
d.identity; // the account the email resolved to (a GitHub login), "" if none
|
|
51
52
|
await tp.require(...); // rejects with PermissionDenied unless allow
|
|
52
53
|
```
|
|
53
54
|
|
package/dist/index.d.ts
CHANGED
|
@@ -38,13 +38,15 @@ export type DecisionValue = typeof ALLOW | typeof DENY | typeof UNKNOWN;
|
|
|
38
38
|
* `decision` is `allow`, `deny` or `unknown`. `reason` is `"<code>: <text>"`
|
|
39
39
|
* as toolpass sent it, or `"client_error: ..."` when the request never
|
|
40
40
|
* produced a usable answer. `status` is the HTTP status, 0 when no response
|
|
41
|
-
* arrived.
|
|
41
|
+
* arrived. `identity` is the account the user's email resolved to in the
|
|
42
|
+
* system (a GitHub login), "" when none was resolved.
|
|
42
43
|
*/
|
|
43
44
|
export declare class Decision {
|
|
44
45
|
readonly decision: DecisionValue;
|
|
45
46
|
readonly reason: string;
|
|
46
47
|
readonly status: number;
|
|
47
|
-
|
|
48
|
+
readonly identity: string;
|
|
49
|
+
constructor(decision: DecisionValue, reason: string, status?: number, identity?: string);
|
|
48
50
|
/** True only for a positive `allow`. `unknown` is not allowed. */
|
|
49
51
|
get allowed(): boolean;
|
|
50
52
|
/** The machine-readable code in front of the colon, e.g. `user_not_found`. */
|
package/dist/index.js
CHANGED
|
@@ -38,16 +38,19 @@ export const UNKNOWN = "unknown";
|
|
|
38
38
|
* `decision` is `allow`, `deny` or `unknown`. `reason` is `"<code>: <text>"`
|
|
39
39
|
* as toolpass sent it, or `"client_error: ..."` when the request never
|
|
40
40
|
* produced a usable answer. `status` is the HTTP status, 0 when no response
|
|
41
|
-
* arrived.
|
|
41
|
+
* arrived. `identity` is the account the user's email resolved to in the
|
|
42
|
+
* system (a GitHub login), "" when none was resolved.
|
|
42
43
|
*/
|
|
43
44
|
export class Decision {
|
|
44
45
|
decision;
|
|
45
46
|
reason;
|
|
46
47
|
status;
|
|
47
|
-
|
|
48
|
+
identity;
|
|
49
|
+
constructor(decision, reason, status = 200, identity = "") {
|
|
48
50
|
this.decision = decision;
|
|
49
51
|
this.reason = reason;
|
|
50
52
|
this.status = status;
|
|
53
|
+
this.identity = identity;
|
|
51
54
|
Object.freeze(this);
|
|
52
55
|
}
|
|
53
56
|
/** True only for a positive `allow`. `unknown` is not allowed. */
|
|
@@ -251,7 +254,7 @@ function parse(status, raw) {
|
|
|
251
254
|
if (typeof data !== "object" || data === null || !("decision" in data)) {
|
|
252
255
|
return new Decision(UNKNOWN, `client_error: unexpected response (HTTP ${status})`, status);
|
|
253
256
|
}
|
|
254
|
-
const { decision, reason } = data;
|
|
257
|
+
const { decision, reason, identity } = data;
|
|
255
258
|
if (decision !== ALLOW && decision !== DENY && decision !== UNKNOWN) {
|
|
256
259
|
return new Decision(UNKNOWN, `client_error: unexpected decision ${JSON.stringify(decision)}`, status);
|
|
257
260
|
}
|
|
@@ -259,7 +262,7 @@ function parse(status, raw) {
|
|
|
259
262
|
// toolpass never allows with a non-200 status; do not trust a proxy that does.
|
|
260
263
|
return new Decision(UNKNOWN, `client_error: allow with HTTP ${status}`, status);
|
|
261
264
|
}
|
|
262
|
-
return new Decision(decision, reason === undefined ? "" : String(reason), status);
|
|
265
|
+
return new Decision(decision, reason === undefined ? "" : String(reason), status, typeof identity === "string" ? identity : "");
|
|
263
266
|
}
|
|
264
267
|
/**
|
|
265
268
|
* Resolve a user or groups source now.
|