@lynq/github 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 hogekai
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.
@@ -0,0 +1,52 @@
1
+ import { ToolContext, ToolMiddleware, MCPServer } from '@lynq/lynq';
2
+
3
+ interface GitHubOptions {
4
+ /** Middleware name. Default: "github" */
5
+ name?: string;
6
+ /** GitHub OAuth App client ID. */
7
+ clientId: string;
8
+ /** GitHub OAuth App client secret. */
9
+ clientSecret: string;
10
+ /** OAuth callback URL (your server's callback endpoint). */
11
+ redirectUri: string;
12
+ /** GitHub OAuth scopes. Default: [] */
13
+ scopes?: string[];
14
+ /** Session key for user data. Default: "user" */
15
+ sessionKey?: string;
16
+ /** Message shown to the user. Default: "Please sign in with GitHub to continue." */
17
+ message?: string;
18
+ /** Timeout in ms. Default: 300000 */
19
+ timeout?: number;
20
+ /** Custom skip condition. Takes priority over sessionKey check. */
21
+ skipIf?: (c: ToolContext) => boolean | Promise<boolean>;
22
+ /** Called after authentication completes successfully, before next(). */
23
+ onComplete?: (c: ToolContext) => void | Promise<void>;
24
+ }
25
+ /** @deprecated Use `GitHubOptions` instead. */
26
+ type GitHubOAuthOptions = GitHubOptions;
27
+ declare function github(options: GitHubOptions): ToolMiddleware;
28
+ /** @deprecated Use `github()` from `@lynq/github` instead. */
29
+ declare const githubOAuth: typeof github;
30
+ interface HandleCallbackOptions {
31
+ clientId: string;
32
+ clientSecret: string;
33
+ /** Session key for user data. Default: "user" */
34
+ sessionKey?: string;
35
+ }
36
+ /** @deprecated Use `HandleCallbackOptions` instead. */
37
+ type HandleGitHubCallbackOptions = HandleCallbackOptions;
38
+ /**
39
+ * Handle GitHub OAuth callback. Call from your HTTP callback route.
40
+ * Exchanges code for token, fetches user info, stores in session, and completes elicitation.
41
+ */
42
+ declare function handleCallback(server: MCPServer, params: {
43
+ code: string;
44
+ state: string;
45
+ }, options: HandleCallbackOptions): Promise<{
46
+ success: boolean;
47
+ error?: string;
48
+ }>;
49
+ /** @deprecated Use `handleCallback()` from `@lynq/github` instead. */
50
+ declare const handleGitHubCallback: typeof handleCallback;
51
+
52
+ export { type GitHubOAuthOptions, type GitHubOptions, type HandleCallbackOptions, type HandleGitHubCallbackOptions, github, githubOAuth, handleCallback, handleGitHubCallback };
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ import {verifyState,signState}from'@lynq/lynq/helpers';import {oauth}from'@lynq/lynq/oauth';function m(e){let s=e.scopes??[],t={name:e.name??"github",sessionKey:e.sessionKey??"user",message:e.message??"Please sign in with GitHub to continue.",buildUrl({sessionId:c,elicitationId:i}){let n=new URLSearchParams({client_id:e.clientId,redirect_uri:e.redirectUri,state:signState(c,i,e.clientSecret)});return s.length>0&&n.set("scope",s.join(" ")),`https://github.com/login/oauth/authorize?${n}`}};return e.timeout!==void 0&&(t.timeout=e.timeout),e.skipIf&&(t.skipIf=e.skipIf),e.onComplete&&(t.onComplete=e.onComplete),oauth(t)}var y=m;async function f(e,s,t){let c=t.sessionKey??"user",i=verifyState(s.state,t.clientSecret);if(!i)return {success:false,error:"Invalid state parameter"};let{sessionId:n,elicitationId:l}=i;try{let r=await(await fetch("https://github.com/login/oauth/access_token",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({client_id:t.clientId,client_secret:t.clientSecret,code:s.code})})).json();if(!r.access_token)return {success:!1,error:r.error_description??r.error??"Token exchange failed"};let u=await(await fetch("https://api.github.com/user",{headers:{Authorization:`Bearer ${r.access_token}`}})).json(),a=e.session(n);return a.set(c,u),a.set("accessToken",r.access_token),e.completeElicitation(l),{success:!0}}catch(o){return {success:false,error:o instanceof Error?o.message:String(o)}}}var C=f;
2
+ export{m as github,y as githubOAuth,f as handleCallback,C as handleGitHubCallback};
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@lynq/github",
3
+ "version": "0.1.0",
4
+ "description": "GitHub OAuth provider for lynq MCP framework.",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.mjs"
11
+ }
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "dependencies": {
17
+ "@lynq/lynq": "^0.8.0"
18
+ },
19
+ "devDependencies": {
20
+ "tsup": "^8.0.0",
21
+ "typescript": "^5.6.0",
22
+ "vitest": "^2.0.0",
23
+ "zod": "^3.24.0"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://github.com/hogekai/lynq",
31
+ "directory": "packages/github"
32
+ },
33
+ "license": "MIT",
34
+ "engines": {
35
+ "node": ">=18"
36
+ },
37
+ "scripts": {
38
+ "build": "tsup",
39
+ "test": "vitest run",
40
+ "typecheck": "tsc --noEmit"
41
+ }
42
+ }