@lynq/hono 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 +21 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.mjs +1 -0
- package/package.json +67 -0
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.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { MCPServer } from '@lynq/lynq';
|
|
2
|
+
import { PagesConfig } from '@lynq/lynq/pages';
|
|
3
|
+
export { PagesConfig } from '@lynq/lynq/pages';
|
|
4
|
+
import { Hono } from 'hono';
|
|
5
|
+
|
|
6
|
+
interface MountOptions {
|
|
7
|
+
/** Route path. Default: "/mcp" */
|
|
8
|
+
path?: string;
|
|
9
|
+
/** Allowed hostnames for DNS rebinding protection. Default: localhost variants. */
|
|
10
|
+
allowedHosts?: string[];
|
|
11
|
+
/** Enable default pages for specified auth/payment providers. */
|
|
12
|
+
pages?: PagesConfig;
|
|
13
|
+
/** URL prefix for pages routes. Default: "/lynq" */
|
|
14
|
+
pagesPrefix?: string;
|
|
15
|
+
}
|
|
16
|
+
declare function mountLynq(app: Hono, server: MCPServer, options?: MountOptions): void;
|
|
17
|
+
|
|
18
|
+
export { type MountOptions, mountLynq };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {LOCALHOST_HOSTS,validateHost}from'@lynq/lynq/helpers';import {successPage,errorPage,cryptoPaymentPage}from'@lynq/lynq/pages';function S(n,r,i){let a=i?.path??"/mcp",s=r.http(),e=i?.allowedHosts??[...LOCALHOST_HOSTS];n.use(a,async(t,o)=>validateHost(t.req.header("host")??null,e)?o():t.json({jsonrpc:"2.0",error:{code:-32e3,message:"Forbidden"},id:null},403)),n.all(a,t=>s(t.req.raw)),i?.pages&&q(n,r,i);}async function m(n,r,i,a){if(i===true)return {status:500,html:errorPage("GitHub pages require { clientId, clientSecret } configuration")};if(!r.code||!r.state)return {status:400,html:errorPage("Missing code or state parameter")};try{let{handleCallback:s}=await import('@lynq/github'),e={clientId:i.clientId,clientSecret:i.clientSecret};i.sessionKey&&(e.sessionKey=i.sessionKey);let t=await s(n,{code:r.code,state:r.state},e);return t.success?{status:302,redirect:`${a}/auth/success`}:{status:500,html:errorPage(t.error??"Authentication failed")}}catch(s){return {status:500,html:errorPage(s instanceof Error?s.message:String(s))}}}async function y(n,r,i,a,s){if(i===true)return {status:500,html:errorPage("Google pages require { clientId, clientSecret } configuration")};if(!r.code||!r.state)return {status:400,html:errorPage("Missing code or state parameter")};try{let{handleCallback:e}=await import('@lynq/google'),t={clientId:i.clientId,clientSecret:i.clientSecret,redirectUri:s};i.sessionKey&&(t.sessionKey=i.sessionKey);let o=await e(n,{code:r.code,state:r.state},t);return o.success?{status:302,redirect:`${a}/auth/success`}:{status:500,html:errorPage(o.error??"Authentication failed")}}catch(e){return {status:500,html:errorPage(e instanceof Error?e.message:String(e))}}}async function h(n,r,i,a){if(i===true)return {status:500,html:errorPage("Stripe pages require { secretKey } configuration")};if(r.cancelled==="true")return {status:200,html:errorPage("Payment was cancelled")};if(!r.session_id||!r.state)return {status:400,html:errorPage("Missing session_id or state parameter")};try{let{handleCallback:s}=await import('@lynq/stripe'),e={secretKey:i.secretKey};i.sessionKey&&(e.sessionKey=i.sessionKey);let t=await s(n,{checkoutSessionId:r.session_id,state:r.state},e);return t.success?{status:302,redirect:`${a}/payment/success`}:{status:500,html:errorPage(t.error??"Payment verification failed")}}catch(s){return {status:500,html:errorPage(s instanceof Error?s.message:String(s))}}}function P(n,r){return !n.recipient||!n.amount||!n.state?{status:400,html:errorPage("Missing required payment parameters")}:{status:200,html:cryptoPaymentPage({recipient:n.recipient,amount:n.amount,token:n.token??"USDC",network:n.network??"base",state:n.state,callbackUrl:r})}}async function C(n,r,i){if(!r.txHash||!r.state||!r.recipient||!r.amount)return {status:400,json:{success:false,error:"Missing txHash, state, recipient, or amount"}};try{let{handleCallback:a}=await import('@lynq/crypto'),s={recipient:r.recipient,amount:Number(r.amount)};i!==!0&&(i.rpcUrl&&(s.rpcUrl=i.rpcUrl),i.sessionKey&&(s.sessionKey=i.sessionKey));let e=await a(n,{txHash:r.txHash,state:r.state},s);return {status:e.success?200:500,json:e}}catch(a){return {status:500,json:{success:false,error:a instanceof Error?a.message:String(a)}}}}function q(n,r,i){let a=i.pagesPrefix??"/lynq",s=i.pages;if(s.github&&typeof s.github!="string"?n.get(`${a}/auth/github/callback`,async e=>{let t=await m(r,{code:e.req.query("code"),state:e.req.query("state")},s.github,a);return t.redirect?e.redirect(t.redirect):e.html(t.html??"",t.status)}):typeof s.github=="string"&&n.get(`${a}/auth/github/callback`,e=>{let t=new URL(s.github,e.req.url),o=e.req.query();for(let[c,l]of Object.entries(o))t.searchParams.set(c,l);return e.redirect(t.toString())}),s.google&&typeof s.google!="string"?n.get(`${a}/auth/google/callback`,async e=>{let o=`${new URL(e.req.url).origin}${a}/auth/google/callback`,c=await y(r,{code:e.req.query("code"),state:e.req.query("state")},s.google,a,o);return c.redirect?e.redirect(c.redirect):e.html(c.html??"",c.status)}):typeof s.google=="string"&&n.get(`${a}/auth/google/callback`,e=>{let t=new URL(s.google,e.req.url),o=e.req.query();for(let[c,l]of Object.entries(o))t.searchParams.set(c,l);return e.redirect(t.toString())}),s.stripe&&typeof s.stripe!="string"?n.get(`${a}/payment/stripe/callback`,async e=>{let t=await h(r,{session_id:e.req.query("session_id"),cancelled:e.req.query("cancelled"),state:e.req.query("state")},s.stripe,a);return t.redirect?e.redirect(t.redirect):e.html(t.html??"",t.status)}):typeof s.stripe=="string"&&n.get(`${a}/payment/stripe/callback`,e=>{let t=new URL(s.stripe,e.req.url),o=e.req.query();for(let[c,l]of Object.entries(o))t.searchParams.set(c,l);return e.redirect(t.toString())}),s.crypto&&typeof s.crypto!="string"){let e=s.crypto;n.get(`${a}/payment/crypto`,async t=>{let o=`${new URL(t.req.url).origin}${a}/payment/crypto/callback`,c=P({recipient:t.req.query("recipient"),amount:t.req.query("amount"),token:t.req.query("token"),network:t.req.query("network"),state:t.req.query("state")},o);return t.html(c.html??"",c.status)}),n.post(`${a}/payment/crypto/callback`,async t=>{let o=await t.req.json(),c=await C(r,o,e);return t.json(c.json,c.status)});}else typeof s.crypto=="string"&&n.get(`${a}/payment/crypto`,e=>{let t=new URL(s.crypto,e.req.url),o=e.req.query();for(let[c,l]of Object.entries(o))t.searchParams.set(c,l);return e.redirect(t.toString())});n.get(`${a}/auth/success`,e=>e.html(successPage("Authentication"))),n.get(`${a}/payment/success`,e=>e.html(successPage("Payment")));}export{S as mountLynq};
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lynq/hono",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Hono adapter 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
|
+
"peerDependencies": {
|
|
20
|
+
"hono": "^4.0.0",
|
|
21
|
+
"@lynq/github": "^0.1.0",
|
|
22
|
+
"@lynq/google": "^0.1.0",
|
|
23
|
+
"@lynq/stripe": "^0.1.0",
|
|
24
|
+
"@lynq/crypto": "^0.1.0"
|
|
25
|
+
},
|
|
26
|
+
"peerDependenciesMeta": {
|
|
27
|
+
"@lynq/github": {
|
|
28
|
+
"optional": true
|
|
29
|
+
},
|
|
30
|
+
"@lynq/google": {
|
|
31
|
+
"optional": true
|
|
32
|
+
},
|
|
33
|
+
"@lynq/stripe": {
|
|
34
|
+
"optional": true
|
|
35
|
+
},
|
|
36
|
+
"@lynq/crypto": {
|
|
37
|
+
"optional": true
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"hono": "^4.12.5",
|
|
42
|
+
"tsup": "^8.0.0",
|
|
43
|
+
"typescript": "^5.6.0",
|
|
44
|
+
"vitest": "^2.0.0",
|
|
45
|
+
"@lynq/google": "^0.1.0",
|
|
46
|
+
"@lynq/stripe": "^0.1.0",
|
|
47
|
+
"@lynq/crypto": "^0.1.0",
|
|
48
|
+
"@lynq/github": "^0.1.0"
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
53
|
+
"repository": {
|
|
54
|
+
"type": "git",
|
|
55
|
+
"url": "https://github.com/hogekai/lynq",
|
|
56
|
+
"directory": "packages/hono"
|
|
57
|
+
},
|
|
58
|
+
"license": "MIT",
|
|
59
|
+
"engines": {
|
|
60
|
+
"node": ">=18"
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"build": "tsup",
|
|
64
|
+
"test": "vitest run",
|
|
65
|
+
"typecheck": "tsc --noEmit"
|
|
66
|
+
}
|
|
67
|
+
}
|