@notation/factory-github 0.5.1 → 0.5.3
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/implementations/connection.ts +5 -1
- package/lib/app.ts +13 -0
- package/lib/permissions.ts +21 -1
- package/package.json +3 -3
- package/resources/app.ts +2 -17
|
@@ -7,12 +7,15 @@ import {
|
|
|
7
7
|
import { webhookPath } from "@notation/factory/router";
|
|
8
8
|
import * as v from "valibot";
|
|
9
9
|
import { appName } from "../lib/app-name.ts";
|
|
10
|
+
import { permissionsSchema } from "../lib/permissions.ts";
|
|
10
11
|
import { App, type AppInstance } from "../resources/app.ts";
|
|
11
12
|
import { CHANNEL_SECRETS, CHANNEL_VALUES } from "../router/index.ts";
|
|
12
13
|
import { ConnectionRef } from "./connection-ref.ts";
|
|
13
14
|
|
|
14
15
|
const connectionConfig = v.object({
|
|
15
16
|
org: v.optional(v.string()),
|
|
17
|
+
/** Permissions the App holds on top of its fixed set. An outpost's policies can only ask for permissions the App holds. */
|
|
18
|
+
permissions: v.optional(permissionsSchema),
|
|
16
19
|
});
|
|
17
20
|
export type ConnectionConfig = v.InferInput<typeof connectionConfig>;
|
|
18
21
|
|
|
@@ -33,7 +36,7 @@ export class Connection
|
|
|
33
36
|
readonly app: AppInstance;
|
|
34
37
|
|
|
35
38
|
constructor(id: string, { router, ...config }: ConnectionOptions) {
|
|
36
|
-
const { org } = v.parse(connectionConfig, config);
|
|
39
|
+
const { org, permissions } = v.parse(connectionConfig, config);
|
|
37
40
|
super("github/Connection", id, config);
|
|
38
41
|
this.name = id;
|
|
39
42
|
this.router = router;
|
|
@@ -62,6 +65,7 @@ export class Connection
|
|
|
62
65
|
statuses: "read",
|
|
63
66
|
},
|
|
64
67
|
});
|
|
68
|
+
if (permissions) this.app.contribute({ permissions });
|
|
65
69
|
router.channel({
|
|
66
70
|
connection: key,
|
|
67
71
|
module: fileURLToPath(new URL("../router/index.ts", import.meta.url)),
|
package/lib/app.ts
CHANGED
|
@@ -172,6 +172,19 @@ export const appSlug = async (id: string): Promise<string> => {
|
|
|
172
172
|
return slug;
|
|
173
173
|
};
|
|
174
174
|
|
|
175
|
+
/**
|
|
176
|
+
* The App's owner, and whether the App is public. Only the owner can install a
|
|
177
|
+
* private App. GitHub only shows a private App to a request that's signed in.
|
|
178
|
+
*/
|
|
179
|
+
export const appVisibility = async (slug: string): Promise<{ owner: string; public: boolean }> => {
|
|
180
|
+
const path = `/apps/${encodeURIComponent(slug)}`;
|
|
181
|
+
const app = await github<{ owner: { login: string } }>("GET", path, await ghToken());
|
|
182
|
+
const anonymous = await fetch(`${GITHUB_API}${path}`, {
|
|
183
|
+
headers: { accept: "application/vnd.github+json", "user-agent": "notation-factory" },
|
|
184
|
+
});
|
|
185
|
+
return { owner: app.owner.login, public: anonymous.ok };
|
|
186
|
+
};
|
|
187
|
+
|
|
175
188
|
/** Reads the App by its id, which fails if the App is gone. The lookup needs your gh login or GH_TOKEN. */
|
|
176
189
|
export const readApp = async (key: { id: string }): Promise<{ id: string; clientId: string }> => {
|
|
177
190
|
const slug = await appSlug(key.id);
|
package/lib/permissions.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { DeepPartial } from "@notation/resource";
|
|
2
|
+
import * as v from "valibot";
|
|
2
3
|
|
|
3
4
|
export type Permission = "read" | "write";
|
|
4
5
|
export type Permissions = Partial<
|
|
@@ -11,10 +12,29 @@ export type Permissions = Partial<
|
|
|
11
12
|
| "issues"
|
|
12
13
|
| "metadata"
|
|
13
14
|
| "pull_requests"
|
|
14
|
-
| "statuses"
|
|
15
|
+
| "statuses"
|
|
16
|
+
| "workflows",
|
|
15
17
|
Permission
|
|
16
18
|
>
|
|
17
19
|
>;
|
|
20
|
+
|
|
21
|
+
const permission = v.picklist(["read", "write"]);
|
|
22
|
+
|
|
23
|
+
export const permissionsSchema = v.partial(
|
|
24
|
+
v.object({
|
|
25
|
+
actions: permission,
|
|
26
|
+
actions_variables: permission,
|
|
27
|
+
checks: permission,
|
|
28
|
+
contents: permission,
|
|
29
|
+
deployments: permission,
|
|
30
|
+
issues: permission,
|
|
31
|
+
metadata: permission,
|
|
32
|
+
pull_requests: permission,
|
|
33
|
+
statuses: permission,
|
|
34
|
+
workflows: permission,
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
37
|
+
|
|
18
38
|
export type GithubEvent =
|
|
19
39
|
| "issues"
|
|
20
40
|
| "issue_comment"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@notation/factory-github",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"author": "Daniel Grant",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"valibot": "^1.1.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@notation/factory": "^0.5.
|
|
35
|
+
"@notation/factory": "^0.5.3"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@notation/factory": "0.5.
|
|
38
|
+
"@notation/factory": "0.5.3"
|
|
39
39
|
}
|
|
40
40
|
}
|
package/resources/app.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
type GithubEvent,
|
|
11
11
|
highestPermissions,
|
|
12
12
|
type Permissions,
|
|
13
|
+
permissionsSchema,
|
|
13
14
|
union,
|
|
14
15
|
} from "../lib/permissions.ts";
|
|
15
16
|
|
|
@@ -39,22 +40,6 @@ const githubEvent = v.picklist([
|
|
|
39
40
|
"pull_request_review_comment",
|
|
40
41
|
] satisfies GithubEvent[]);
|
|
41
42
|
|
|
42
|
-
const permission = v.picklist(["read", "write"]);
|
|
43
|
-
|
|
44
|
-
const permissions = v.partial(
|
|
45
|
-
v.object({
|
|
46
|
-
actions: permission,
|
|
47
|
-
actions_variables: permission,
|
|
48
|
-
checks: permission,
|
|
49
|
-
contents: permission,
|
|
50
|
-
deployments: permission,
|
|
51
|
-
issues: permission,
|
|
52
|
-
metadata: permission,
|
|
53
|
-
pull_requests: permission,
|
|
54
|
-
statuses: permission,
|
|
55
|
-
}),
|
|
56
|
-
);
|
|
57
|
-
|
|
58
43
|
export const App = defineResource<AppApi>({
|
|
59
44
|
type: "github/apps/App",
|
|
60
45
|
provider: "@notation/factory-github",
|
|
@@ -87,7 +72,7 @@ export const App = defineResource<AppApi>({
|
|
|
87
72
|
permissions: {
|
|
88
73
|
propertyType: "param",
|
|
89
74
|
presence: "optional",
|
|
90
|
-
value:
|
|
75
|
+
value: permissionsSchema,
|
|
91
76
|
collect: highestPermissions,
|
|
92
77
|
},
|
|
93
78
|
id: {
|