@sentry/junior-github 0.81.0 → 0.82.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/permissions.js DELETED
@@ -1,77 +0,0 @@
1
- const LEVELS = new Set(["read", "write", "admin"]);
2
- // GitHub documents these installation-token permission fields as write-only.
3
- const WRITE_ONLY_PERMISSIONS = new Set(["profile", "workflows"]);
4
-
5
- function isLevel(value) {
6
- return LEVELS.has(value);
7
- }
8
-
9
- function normalizeScope(rawScope) {
10
- return String(rawScope).trim().replace(/-/g, "_");
11
- }
12
-
13
- /** Validate configured GitHub App permissions before using them in grants. */
14
- export function normalizePermissions(permissions) {
15
- if (permissions === undefined) {
16
- return undefined;
17
- }
18
-
19
- const entries = Object.entries(permissions);
20
- if (entries.length === 0) {
21
- throw new Error(
22
- "githubPlugin appPermissions must contain at least one permission when provided.",
23
- );
24
- }
25
-
26
- const request = {};
27
- for (const [rawScope, rawLevel] of entries) {
28
- const normalizedScope = normalizeScope(rawScope);
29
- if (!normalizedScope) {
30
- throw new Error(
31
- "githubPlugin appPermissions contains an empty permission name.",
32
- );
33
- }
34
- if (!/^[a-z][a-z0-9_]*$/.test(normalizedScope)) {
35
- throw new Error(
36
- `githubPlugin appPermissions contains invalid permission "${rawScope}".`,
37
- );
38
- }
39
- if (!isLevel(rawLevel)) {
40
- throw new Error(
41
- `githubPlugin appPermissions.${rawScope} must be "read", "write", or "admin".`,
42
- );
43
- }
44
- request[normalizedScope] = rawLevel;
45
- }
46
- return request;
47
- }
48
-
49
- /** Build the read-only installation-token permission body. */
50
- export function readGrantPermissions(permissions) {
51
- const readOnly = { metadata: "read" };
52
- for (const [scope, level] of Object.entries(permissions ?? {})) {
53
- if (!isLevel(level)) {
54
- throw new Error(
55
- `GitHub permission "${scope}" returned invalid level "${String(level)}".`,
56
- );
57
- }
58
- if (!WRITE_ONLY_PERMISSIONS.has(scope)) {
59
- readOnly[scope] = "read";
60
- }
61
- }
62
- return readOnly;
63
- }
64
-
65
- /** Expose configured permissions as plugin capabilities for host policy checks. */
66
- export function permissionCapabilities(permissions) {
67
- if (permissions === undefined) {
68
- return undefined;
69
- }
70
-
71
- return Object.entries(permissions)
72
- .map(([normalizedScope, rawLevel]) => {
73
- const scope = normalizedScope.replace(/_/g, "-");
74
- return `github.${scope}.${rawLevel}`;
75
- })
76
- .sort();
77
- }