@noldova/git.github.protocol 0.0.0-stage → 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Noldova
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,7 @@
1
- # Temporary Holding Version
1
+ # @noldova/git.github.protocol
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ What the GitHub module's parts share: `GitHubNames`, the module's id, Noldova's GitHub app's client id, the sign-in's, the reads' and the pull request's method names, the sign-in's event, the agent tools' names and the page where the person manages the app's access; and `IGitHubAccess`, the `git-github.access` service through which another module's runtime part reads the signed-in token, answered as a `GitHubAccessGrant` with the account's login or a `GitHubAccessRefusal` saying why there is none.
4
+
5
+ Both parts of [`@noldova/git.github`](https://github.com/noldova-com/git/tree/main/src/noldova.git.github) import it by its name, and the module pins it at its own version.
6
+ [documents/ARCHITECTURE.md](https://github.com/noldova-com/git/blob/main/documents/ARCHITECTURE.md) says how the parts talk, and the [README](https://github.com/noldova-com/git#readme) how to build and test it.
7
+ It is licensed under the [MIT License](https://github.com/noldova-com/git/blob/main/LICENSE).
package/package.json CHANGED
@@ -1,6 +1,36 @@
1
1
  {
2
2
  "name": "@noldova/git.github.protocol",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.1",
4
+ "description": "What the GitHub module's parts share: GitHubNames, the module's id, method, event, tool and service names, and the IGitHubAccess service through which another module reads the signed-in token as a GitHubAccessGrant, or why not as a GitHubAccessRefusal.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/noldova-com/git.git",
10
+ "directory": "src/noldova.git.github.protocol"
11
+ },
12
+ "homepage": "https://github.com/noldova-com/git#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/noldova-com/git/issues"
15
+ },
16
+ "exports": {
17
+ ".": {
18
+ "types": "./src/api/index.d.ts",
19
+ "default": "./src/api/index.js"
20
+ },
21
+ "./package.json": "./package.json"
22
+ },
23
+ "files": [
24
+ "src/**/*.js",
25
+ "src/**/*.js.map",
26
+ "src/**/*.d.ts"
27
+ ],
28
+ "publishConfig": {
29
+ "access": "public",
30
+ "registry": "https://registry.npmjs.org/"
31
+ },
32
+ "dependencies": {
33
+ "@noldova/git.hosting.protocol": "0.0.1"
34
+ },
35
+ "gitHead": "9edb99d8feb37b29af7995d8b4717514fb242e5c"
36
+ }
@@ -0,0 +1,237 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ /**
10
+ * The names the GitHub module's parts share.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { GitHubNames } from "@noldova/git.github.protocol";
15
+ *
16
+ * console.log(GitHubNames.moduleId);
17
+ * ```
18
+ */
19
+ export declare class GitHubNames {
20
+ /**
21
+ * The module's id, as its module.json declares it.
22
+ */
23
+ public static readonly moduleId: string;
24
+
25
+ /**
26
+ * The public client id of Noldova's OAuth app on GitHub, which the device sign-in names; the app has no client secret.
27
+ */
28
+ public static readonly clientId: string;
29
+
30
+ /**
31
+ * The method that answers the sign-in as `HostSignIn` JSON from `@noldova/git.hosting.protocol`.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * import type { IWindowPartContext } from "@noldova/desktop.window";
36
+ * import { GitHubNames } from "@noldova/git.github.protocol";
37
+ * import { HostSignIn } from "@noldova/git.hosting.protocol";
38
+ *
39
+ * export async function readSignInAsync(context: IWindowPartContext): Promise<HostSignIn> {
40
+ * return HostSignIn.fromJson(await context.requestAsync(GitHubNames.readSignInMethod, null));
41
+ * }
42
+ * ```
43
+ */
44
+ public static readonly readSignInMethod: string;
45
+
46
+ /**
47
+ * The method that starts a device sign-in and answers the sign-in, which then waits with its code; a sign-in that already waits or is signed
48
+ * in stays as it is.
49
+ */
50
+ public static readonly startSignInMethod: string;
51
+
52
+ /**
53
+ * The method that stops a sign-in that waits and answers the sign-in, signed out with no failure; it changes nothing otherwise.
54
+ */
55
+ public static readonly cancelSignInMethod: string;
56
+
57
+ /**
58
+ * The method that stops a sign-in that waits, forgets the kept token on this computer and answers the sign-in, signed out.
59
+ */
60
+ public static readonly signOutMethod: string;
61
+
62
+ /**
63
+ * The method that takes a `HostReference` as JSON and answers the pull request or issue as `HostItem` JSON, or null when signed out, when the
64
+ * reference's host isn't `github.com`, or when GitHub can't show it (404); answers are cached, fresh for 60 seconds and then revalidated
65
+ * with `If-None-Match`, and a 401 signs out with `Revoked` and fails with `Unauthorized`.
66
+ */
67
+ public static readonly readReferenceMethod: string;
68
+
69
+ /**
70
+ * The method that takes a `BranchQuery` as JSON, with the repository's path as `owner/repository`, and answers `BranchPullRequest` JSON: the
71
+ * branch's newest pull request in that repository, with the check runs of the query's head commit, or of the pull request's head when it is
72
+ * null; it answers no pull request when signed out or when the branch has none.
73
+ */
74
+ public static readonly readBranchPullRequestMethod: string;
75
+
76
+ /**
77
+ * The method that takes a `PullRequestDraft` as JSON, opens the pull request on GitHub and answers it as `HostItem` JSON; it fails with
78
+ * `Unauthorized` for any caller but the app's main process acting for a window and when signed out, with `Conflict` when GitHub refuses
79
+ * the pull request (422), such as when one is already open for the branch, and with `InvalidParams` for a repository not on `github.com`.
80
+ */
81
+ public static readonly createPullRequestMethod: string;
82
+
83
+ /**
84
+ * `git-github.access`: the service the GitHub runtime part publishes as an `IGitHubAccess`, through which another module's runtime part,
85
+ * such as an app's for GitHub's own MCP server, reads the signed-in token.
86
+ */
87
+ public static readonly accessService: string;
88
+
89
+ /**
90
+ * The event that carries the sign-in as `HostSignIn` JSON each time it changes.
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * import type { IWindowPartContext } from "@noldova/desktop.window";
95
+ * import { GitHubNames } from "@noldova/git.github.protocol";
96
+ *
97
+ * export function followSignIn(context: IWindowPartContext): () => void {
98
+ * return context.onEvent(GitHubNames.signInChangedEvent, t => console.log(t));
99
+ * }
100
+ * ```
101
+ */
102
+ public static readonly signInChangedEvent: string;
103
+
104
+ /**
105
+ * `git_github_read`: the agent tool that reads an issue or pull request on github.com by `owner`, `repository` and `number`, and answers
106
+ * its `HostItem` JSON as untrusted text from `https://github.com`; it fails as `Unavailable` with the module code `git-github.signedOut`
107
+ * when signed out and `git-github.notFound` when GitHub has no such item the account can see.
108
+ */
109
+ public static readonly readTool: string;
110
+
111
+ /**
112
+ * `git_github_pr_checks`: the agent tool that reads, for the branch checked out in the repository of the session's `git.folder`, its newest
113
+ * pull request on github.com and the check runs of its HEAD commit, and answers the `BranchPullRequest` JSON as untrusted text from
114
+ * `https://github.com`.
115
+ */
116
+ public static readonly prChecksTool: string;
117
+
118
+ /**
119
+ * `git_github_pr_create`: the agent tool that opens a pull request on github.com from the branch checked out in the repository of the
120
+ * session's `git.folder` into `base`, with `title`, `body` and `draft`, after the person allows the permission request
121
+ * `git-github.createPullRequest` for that repository, and answers the opened pull request's `HostItem` JSON.
122
+ */
123
+ public static readonly prCreateTool: string;
124
+
125
+ /**
126
+ * GitHub's page where the person reviews or revokes the access they gave Noldova's OAuth app.
127
+ */
128
+ public static readonly manageAccessUrl: string;
129
+ }
130
+
131
+ /**
132
+ * The answer of `IGitHubAccess.accessAsync` while signed in: the token the sign-in holds and the account's login.
133
+ * It holds no `reason`, so a module that takes only types from this package tells it from a `GitHubAccessRefusal` by `"token" in answer`.
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * import { GitHubAccessGrant } from "@noldova/git.github.protocol";
138
+ *
139
+ * export function grantOf(token: string): GitHubAccessGrant {
140
+ * return new GitHubAccessGrant(token, "example-user");
141
+ * }
142
+ * ```
143
+ */
144
+ export declare class GitHubAccessGrant {
145
+ /**
146
+ * The signed-in token, passed only to GitHub and never logged or shown.
147
+ */
148
+ public readonly token: string;
149
+
150
+ /**
151
+ * The signed-in account's login.
152
+ */
153
+ public readonly login: string;
154
+
155
+ /**
156
+ * Holds a token with its account's login.
157
+ *
158
+ * @param token The signed-in token.
159
+ * @param login The signed-in account's login.
160
+ *
161
+ * @example
162
+ * ```ts
163
+ * import { GitHubAccessGrant } from "@noldova/git.github.protocol";
164
+ *
165
+ * export function loginOf(token: string): string {
166
+ * return new GitHubAccessGrant(token, "example-user").login;
167
+ * }
168
+ * ```
169
+ */
170
+ public constructor(token: string, login: string);
171
+ }
172
+
173
+ /**
174
+ * The answer of `IGitHubAccess.accessAsync` when there is no token: a sentence saying why, for the person.
175
+ * It holds no `token`, so `"token" in answer` is false for it.
176
+ *
177
+ * @example
178
+ * ```ts
179
+ * import { GitHubAccessRefusal } from "@noldova/git.github.protocol";
180
+ *
181
+ * export function refusalOf(reason: string): GitHubAccessRefusal {
182
+ * return new GitHubAccessRefusal(reason);
183
+ * }
184
+ * ```
185
+ */
186
+ export declare class GitHubAccessRefusal {
187
+ /**
188
+ * Why there is no token: signed out, the kept sign-in unreadable, or a sign-in still waiting for its code.
189
+ */
190
+ public readonly reason: string;
191
+
192
+ /**
193
+ * Holds why there is no token.
194
+ *
195
+ * @param reason The sentence that says why.
196
+ *
197
+ * @example
198
+ * ```ts
199
+ * import { GitHubAccessRefusal } from "@noldova/git.github.protocol";
200
+ *
201
+ * export function signedOutReason(): string {
202
+ * return new GitHubAccessRefusal("Sign in to GitHub in Settings, GitHub.").reason;
203
+ * }
204
+ * ```
205
+ */
206
+ public constructor(reason: string);
207
+ }
208
+
209
+ /**
210
+ * The GitHub sign-in's token for another module's runtime part, published as `git-github.access`. It
211
+ * answers the token the sign-in holds with the account's login, or why there is none: signed out, the kept sign-in unreadable, or a sign-in
212
+ * still waiting for its code; only a module that names `git-github` as a dependency or an optional dependency can find it.
213
+ * The token is never logged or shown; a module that reads it passes it only to GitHub, keeps it in memory only for that request, and reads it
214
+ * again for the next one, so signing out stops the next request. A module that names `git-github` as an optional dependency finds it with
215
+ * `context.findService` and a guard of its own, since it takes only types from this package.
216
+ *
217
+ * @example
218
+ * ```ts
219
+ * import type { IRuntimePartContext } from "@noldova/desktop.runtime";
220
+ * import { GitHubNames, type IGitHubAccess } from "@noldova/git.github.protocol";
221
+ *
222
+ * const isAccess = (t: object): t is IGitHubAccess => "accessAsync" in t && typeof t.accessAsync === "function";
223
+ *
224
+ * export async function readTokenAsync(context: IRuntimePartContext, signal: AbortSignal): Promise<string | null> {
225
+ * const answer = await context.findService(GitHubNames.accessService, isAccess)?.accessAsync(signal);
226
+ * return answer !== undefined && "token" in answer ? answer.token : null;
227
+ * }
228
+ * ```
229
+ */
230
+ export interface IGitHubAccess {
231
+ /**
232
+ * Answers the held token and the account's login as a `GitHubAccessGrant`, or why there is none as a `GitHubAccessRefusal`.
233
+ *
234
+ * @param signal Withdraws the call: an aborted signal rejects with its reason.
235
+ */
236
+ accessAsync(signal: AbortSignal): Promise<GitHubAccessGrant | GitHubAccessRefusal>;
237
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export { GitHubAccessGrant } from "../models/github-access-grant.js";
9
+ export { GitHubAccessRefusal } from "../models/github-access-refusal.js";
10
+ export { GitHubNames } from "../models/github-names.js";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export {};
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export class GitHubAccessGrant {
9
+ token;
10
+ login;
11
+ constructor(token, login) {
12
+ this.token = token;
13
+ this.login = login;
14
+ }
15
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export class GitHubAccessRefusal {
9
+ reason;
10
+ constructor(reason) {
11
+ this.reason = reason;
12
+ }
13
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import { HostingNames } from "@noldova/git.hosting.protocol";
9
+ import { Resources } from "../resources.js";
10
+ export class GitHubNames {
11
+ static moduleId = "git-github";
12
+ static clientId = "Ov23liRKBcNQMxG9PGar";
13
+ static readSignInMethod = HostingNames.nameOf(GitHubNames.moduleId, HostingNames.readSignInMethod);
14
+ static startSignInMethod = HostingNames.nameOf(GitHubNames.moduleId, HostingNames.startSignInMethod);
15
+ static cancelSignInMethod = HostingNames.nameOf(GitHubNames.moduleId, HostingNames.cancelSignInMethod);
16
+ static signOutMethod = HostingNames.nameOf(GitHubNames.moduleId, HostingNames.signOutMethod);
17
+ static readReferenceMethod = HostingNames.nameOf(GitHubNames.moduleId, HostingNames.readReferenceMethod);
18
+ static readBranchPullRequestMethod = HostingNames.nameOf(GitHubNames.moduleId, HostingNames.readBranchPullRequestMethod);
19
+ static createPullRequestMethod = HostingNames.nameOf(GitHubNames.moduleId, HostingNames.createPullRequestMethod);
20
+ static accessService = HostingNames.nameOf(GitHubNames.moduleId, Resources.accessMember);
21
+ static signInChangedEvent = HostingNames.nameOf(GitHubNames.moduleId, HostingNames.signInChangedEvent);
22
+ static readTool = "git_github_read";
23
+ static prChecksTool = "git_github_pr_checks";
24
+ static prCreateTool = "git_github_pr_create";
25
+ static manageAccessUrl = Resources.formatManageAccessUrl(GitHubNames.clientId);
26
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export class Resources {
9
+ static accessMember = "access";
10
+ static formatManageAccessUrl(clientId) {
11
+ return `https://github.com/settings/connections/applications/${clientId}`;
12
+ }
13
+ }