@zhin.js/adapter-telegram 1.0.58 → 1.0.59

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.59
4
+
5
+ ### Patch Changes
6
+
7
+ - abc75a4: fix: 优化,客户端构建优化
8
+ - Updated dependencies [abc75a4]
9
+ - @zhin.js/console@2.0.14
10
+
3
11
  ## 1.0.58
4
12
 
5
13
  ### Patch Changes
package/dist/index.js ADDED
@@ -0,0 +1,32 @@
1
+ import{useEffect as Ue,useState as r,useCallback as Oe}from"react";var oe="zhin_api_token";function xe(){return localStorage.getItem(oe)}async function g(o,l){let f=xe(),i=new Headers(l?.headers);f&&i.set("Authorization",`Bearer ${f}`);let p=await fetch(o,{...l,headers:i});return p.status===401&&(localStorage.removeItem(oe),window.dispatchEvent(new CustomEvent("zhin:auth-required"))),p}import{forwardRef as ke,createElement as we}from"react";var G=(...o)=>o.filter((l,f,i)=>!!l&&l.trim()!==""&&i.indexOf(l)===f).join(" ").trim();var ue=o=>o.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();var de=o=>o.replace(/^([A-Z])|[\s-_]+(\w)/g,(l,f,i)=>i?i.toUpperCase():f.toLowerCase());var z=o=>{let l=de(o);return l.charAt(0).toUpperCase()+l.slice(1)};import{forwardRef as Se,createElement as fe}from"react";var W={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};var le=o=>{for(let l in o)if(l.startsWith("aria-")||l==="role"||l==="title")return!0;return!1};import{createContext as Ce,useContext as he,useMemo as Qe,createElement as Je}from"react";var ge=Ce({});var se=()=>he(ge);var re=Se(({color:o,size:l,strokeWidth:f,absoluteStrokeWidth:i,className:p="",children:s,iconNode:x,...k},q)=>{let{size:C=24,strokeWidth:n=2,absoluteStrokeWidth:V=!1,color:m="currentColor",className:E=""}=se()??{},w=i??V?Number(f??n)*24/Number(l??C):f??n;return fe("svg",{ref:q,...W,width:l??C??W.width,height:l??C??W.height,stroke:o??m,strokeWidth:w,className:G("lucide",E,p),...!s&&!le(k)&&{"aria-hidden":"true"},...k},[...x.map(([v,U])=>fe(v,U)),...Array.isArray(s)?s:[s]])});var u=(o,l)=>{let f=ke(({className:i,...p},s)=>we(re,{ref:s,iconNode:l,className:G(`lucide-${ue(z(o))}`,`lucide-${o}`,i),...p}));return f.displayName=z(o),f};var Pe=[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"M18 17V9",key:"2bz60n"}],["path",{d:"M13 17V5",key:"1frdt8"}],["path",{d:"M8 17v-3",key:"17ska0"}]],I=u("chart-column",Pe);var Ae=[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]],A=u("link-2",Ae);var Be=[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],L=u("loader-circle",Be);var Me=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],B=u("plus",Me);var Fe=[["path",{d:"M18.36 6.64A9 9 0 0 1 20.77 15",key:"dxknvb"}],["path",{d:"M6.16 6.16a9 9 0 1 0 12.68 12.68",key:"1x7qb5"}],["path",{d:"M12 2v4",key:"3427ic"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],M=u("power-off",Fe);var De=[["path",{d:"M12 2v10",key:"mnfbl"}],["path",{d:"M18.4 6.6a9 9 0 1 1-12.77.04",key:"obofu9"}]],F=u("power",De);var ye=[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]],D=u("refresh-cw",ye);var Re=[["rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2",key:"ngkwjq"}],["rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2",key:"iecqi9"}],["line",{x1:"6",x2:"6.01",y1:"6",y2:"6",key:"16zg32"}],["line",{x1:"6",x2:"6.01",y1:"18",y2:"18",key:"nzw8ys"}]],y=u("server",Re);var Te=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],R=u("shield-check",Te);var be=[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}],["path",{d:"M5 12.859a10 10 0 0 1 5.17-2.69",key:"1dl1wf"}],["path",{d:"M19 12.859a10 10 0 0 0-2.007-1.523",key:"4k23kn"}],["path",{d:"M2 8.82a15 15 0 0 1 4.177-2.643",key:"1grhjp"}],["path",{d:"M22 8.82a15 15 0 0 0-11.288-3.764",key:"z3jwby"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],T=u("wifi-off",be);var qe=[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M2 8.82a15 15 0 0 1 20 0",key:"dnpr2z"}],["path",{d:"M5 12.859a10 10 0 0 1 14 0",key:"1x1e6c"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}]],b=u("wifi",qe);var ve=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],S=u("x",ve);import{Fragment as He,jsx as a,jsxs as t}from"react/jsx-runtime";function X(){let[o,l]=r([]),[f,i]=r(!0),[p,s]=r(""),[x,k]=r("overview"),[q,C]=r({}),[n,V]=r(""),[m,E]=r(""),[w,v]=r(""),[U,K]=r([]),[Z,Q]=r(!1),[O,ie]=r(""),[h,N]=r(["",""]),[J,ce]=r(!0),[_,ne]=r(!1),[j,$]=r(""),[Y,ee]=r(!1),H=Oe(async()=>{i(!0),s("");try{let d=await(await g("/api/telegram/bots")).json();d.success?l(d.data):s(d.error||"\u83B7\u53D6\u6570\u636E\u5931\u8D25")}catch{s("\u65E0\u6CD5\u8FDE\u63A5\u670D\u52A1\u5668")}finally{i(!1)}},[]);Ue(()=>{H()},[H]);let pe=async(e,d)=>{C(c=>({...c,[e]:!0}));try{let c=d?"disconnect":"connect",te=await(await g(`/api/telegram/bots/${encodeURIComponent(e)}/${c}`,{method:"POST"})).json();te.success||s(te.error||"\u64CD\u4F5C\u5931\u8D25"),await H()}catch{s("\u64CD\u4F5C\u5931\u8D25")}finally{C(c=>({...c,[e]:!1}))}},me=async()=>{if(!(!n||!m)){v("");try{let d=await(await g(`/api/telegram/bots/${encodeURIComponent(n)}/invite`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({chat_id:m})})).json();d.success&&d.data?.invite_link?v(d.data.invite_link):s(d.error||"\u521B\u5EFA\u5931\u8D25")}catch{s("\u521B\u5EFA\u9080\u8BF7\u94FE\u63A5\u5931\u8D25")}}},Le=async()=>{if(!(!n||!m)){Q(!0),K([]);try{let d=await(await g(`/api/telegram/bots/${encodeURIComponent(n)}/admins?chat_id=${encodeURIComponent(m)}`)).json();d.success&&Array.isArray(d.data)?K(d.data):s(d.error||"\u83B7\u53D6\u7BA1\u7406\u5458\u5931\u8D25")}catch{s("\u83B7\u53D6\u7BA1\u7406\u5458\u5931\u8D25")}finally{Q(!1)}}},Ie=async()=>{if(!n||!m||!O)return;let e=h.filter(d=>d.trim());if(e.length<2){s("\u81F3\u5C11\u9700\u8981 2 \u4E2A\u9009\u9879");return}ee(!0),$("");try{let c=await(await g(`/api/telegram/bots/${encodeURIComponent(n)}/poll`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({chat_id:m,question:O,options:e,is_anonymous:J,allows_multiple:_})})).json();c.success?$(`\u6295\u7968\u5DF2\u53D1\u9001 (ID: ${c.data?.message_id??"\u672A\u77E5"})`):s(c.error||"\u53D1\u9001\u5931\u8D25")}catch{s("\u53D1\u9001\u6295\u7968\u5931\u8D25")}finally{ee(!1)}},ae=o.filter(e=>e.connected);return t("div",{className:"p-6 max-w-5xl mx-auto",children:[t("div",{className:"flex items-center justify-between mb-6",children:[t("h1",{className:"text-2xl font-bold flex items-center gap-2",children:[a(y,{className:"w-6 h-6"})," Telegram \u673A\u5668\u4EBA"]}),t("button",{onClick:H,disabled:f,className:"flex items-center gap-1 px-3 py-1.5 rounded bg-sky-500 text-white hover:bg-sky-600 disabled:opacity-50 text-sm",children:[a(D,{className:`w-4 h-4 ${f?"animate-spin":""}`})," \u5237\u65B0"]})]}),p&&t("div",{className:"mb-4 p-3 bg-red-50 text-red-600 rounded border border-red-200 flex items-center justify-between",children:[a("span",{children:p}),a("button",{onClick:()=>s(""),className:"text-red-400 hover:text-red-600",children:a(S,{className:"w-4 h-4"})})]}),t("div",{className:"flex gap-1 mb-6 border-b",children:[a("button",{onClick:()=>k("overview"),className:`px-4 py-2 text-sm font-medium border-b-2 transition-colors ${x==="overview"?"border-sky-500 text-sky-600":"border-transparent text-gray-500 hover:text-gray-700"}`,children:"\u6982\u89C8"}),a("button",{onClick:()=>k("actions"),className:`px-4 py-2 text-sm font-medium border-b-2 transition-colors ${x==="actions"?"border-sky-500 text-sky-600":"border-transparent text-gray-500 hover:text-gray-700"}`,children:"\u5FEB\u6377\u64CD\u4F5C"})]}),x==="overview"&&t(He,{children:[!f&&!o.length&&!p&&a("div",{className:"text-center text-gray-500 py-12",children:"\u6682\u65E0 Telegram \u673A\u5668\u4EBA\u5B9E\u4F8B"}),a("div",{className:"grid gap-4 md:grid-cols-2",children:o.map(e=>t("div",{className:"border rounded-lg p-4 bg-card shadow-sm",children:[t("div",{className:"flex items-center justify-between mb-3",children:[a("span",{className:"font-medium text-lg",children:e.name}),e.connected?t("span",{className:"flex items-center gap-1 text-green-600 text-sm",children:[a(b,{className:"w-4 h-4"})," \u5728\u7EBF"]}):t("span",{className:"flex items-center gap-1 text-gray-400 text-sm",children:[a(T,{className:"w-4 h-4"})," \u79BB\u7EBF"]})]}),e.botInfo&&t("div",{className:"text-sm text-gray-500 mb-2",children:["@",e.botInfo.username," (",e.botInfo.firstName,")"]}),a("div",{className:"text-sm text-gray-600 mb-3",children:t("div",{className:"flex justify-between",children:[a("span",{children:"\u6A21\u5F0F"}),a("span",{className:"font-mono",children:e.mode})]})}),t("button",{onClick:()=>pe(e.name,e.connected),disabled:q[e.name],className:`flex items-center gap-1 px-3 py-1.5 rounded text-sm text-white ${e.connected?"bg-red-500 hover:bg-red-600":"bg-green-500 hover:bg-green-600"} disabled:opacity-50`,children:[q[e.name]?a(L,{className:"w-3.5 h-3.5 animate-spin"}):e.connected?a(M,{className:"w-3.5 h-3.5"}):a(F,{className:"w-3.5 h-3.5"}),e.connected?"\u65AD\u5F00":"\u8FDE\u63A5"]})]},e.name))})]}),x==="actions"&&t("div",{className:"space-y-6",children:[t("div",{className:"flex flex-wrap items-end gap-3",children:[t("div",{children:[a("label",{className:"block text-xs text-gray-500 mb-1",children:"\u673A\u5668\u4EBA"}),t("select",{value:n,onChange:e=>V(e.target.value),className:"border rounded px-2 py-1.5 text-sm min-w-[140px]",children:[a("option",{value:"",children:"--"}),ae.map(e=>a("option",{value:e.name,children:e.name},e.name))]})]}),t("div",{children:[a("label",{className:"block text-xs text-gray-500 mb-1",children:"Chat ID"}),a("input",{value:m,onChange:e=>E(e.target.value),placeholder:"-100xxxxxxxxxx",className:"border rounded px-2 py-1.5 text-sm w-[180px]"})]})]}),!ae.length&&a("div",{className:"text-center text-gray-500 py-4",children:"\u6682\u65E0\u5728\u7EBF\u673A\u5668\u4EBA"}),n&&m&&t("div",{className:"grid gap-4 md:grid-cols-2",children:[t("div",{className:"border rounded-lg p-4 bg-card shadow-sm",children:[t("h3",{className:"font-medium flex items-center gap-2 mb-3",children:[a(A,{className:"w-4 h-4 text-sky-500"})," \u521B\u5EFA\u9080\u8BF7\u94FE\u63A5"]}),a("button",{onClick:me,className:"px-3 py-1.5 rounded bg-sky-500 text-white text-sm hover:bg-sky-600",children:"\u751F\u6210\u94FE\u63A5"}),w&&a("div",{className:"mt-2 p-2 bg-gray-50 rounded text-sm break-all",children:a("a",{href:w,target:"_blank",rel:"noreferrer",className:"text-sky-600 hover:underline",children:w})})]}),t("div",{className:"border rounded-lg p-4 bg-card shadow-sm",children:[t("h3",{className:"font-medium flex items-center gap-2 mb-3",children:[a(R,{className:"w-4 h-4 text-sky-500"})," \u7BA1\u7406\u5458\u5217\u8868"]}),t("button",{onClick:Le,disabled:Z,className:"px-3 py-1.5 rounded bg-sky-500 text-white text-sm hover:bg-sky-600 disabled:opacity-50 flex items-center gap-1",children:[Z&&a(L,{className:"w-3.5 h-3.5 animate-spin"})," \u67E5\u8BE2"]}),U.length>0&&a("div",{className:"mt-2 space-y-1",children:U.map(e=>t("div",{className:"flex items-center justify-between text-sm py-1 border-b last:border-0",children:[t("span",{children:[e.first_name," ",e.username?`(@${e.username})`:""]}),a("span",{className:"text-xs text-gray-400",children:e.status})]},e.user_id))})]}),t("div",{className:"border rounded-lg p-4 bg-card shadow-sm md:col-span-2",children:[t("h3",{className:"font-medium flex items-center gap-2 mb-3",children:[a(I,{className:"w-4 h-4 text-sky-500"})," \u53D1\u8D77\u6295\u7968"]}),t("div",{className:"space-y-2",children:[a("input",{value:O,onChange:e=>ie(e.target.value),placeholder:"\u6295\u7968\u95EE\u9898",className:"border rounded px-2 py-1.5 text-sm w-full"}),h.map((e,d)=>t("div",{className:"flex items-center gap-2",children:[a("input",{value:e,onChange:c=>{let P=[...h];P[d]=c.target.value,N(P)},placeholder:`\u9009\u9879 ${d+1}`,className:"border rounded px-2 py-1.5 text-sm flex-1"}),h.length>2&&a("button",{onClick:()=>N(h.filter((c,P)=>P!==d)),className:"text-gray-400 hover:text-red-500",children:a(S,{className:"w-4 h-4"})})]},d)),t("button",{onClick:()=>N([...h,""]),className:"flex items-center gap-1 text-sm text-sky-500 hover:text-sky-600",children:[a(B,{className:"w-3.5 h-3.5"})," \u6DFB\u52A0\u9009\u9879"]}),t("div",{className:"flex items-center gap-4 text-sm text-gray-600",children:[t("label",{className:"flex items-center gap-1",children:[a("input",{type:"checkbox",checked:J,onChange:e=>ce(e.target.checked)})," \u533F\u540D"]}),t("label",{className:"flex items-center gap-1",children:[a("input",{type:"checkbox",checked:_,onChange:e=>ne(e.target.checked)})," \u591A\u9009"]})]}),t("button",{onClick:Ie,disabled:Y||!O,className:"px-3 py-1.5 rounded bg-sky-500 text-white text-sm hover:bg-sky-600 disabled:opacity-50 flex items-center gap-1",children:[Y&&a(L,{className:"w-3.5 h-3.5 animate-spin"})," \u53D1\u9001\u6295\u7968"]}),j&&a("div",{className:"text-sm text-green-600",children:j})]})]})]})]})]})}function $a(o){o.addRoute({path:"/console/telegram",name:"Telegram",element:o.React.createElement(X,{hostReact:o.React})}),o.addTool({id:"telegram",name:"Telegram",path:"/console/telegram"})}export{$a as register};
2
+ /*! Bundled license information:
3
+
4
+ lucide-react/dist/esm/shared/src/utils/mergeClasses.mjs:
5
+ lucide-react/dist/esm/shared/src/utils/toKebabCase.mjs:
6
+ lucide-react/dist/esm/shared/src/utils/toCamelCase.mjs:
7
+ lucide-react/dist/esm/shared/src/utils/toPascalCase.mjs:
8
+ lucide-react/dist/esm/defaultAttributes.mjs:
9
+ lucide-react/dist/esm/shared/src/utils/hasA11yProp.mjs:
10
+ lucide-react/dist/esm/context.mjs:
11
+ lucide-react/dist/esm/Icon.mjs:
12
+ lucide-react/dist/esm/createLucideIcon.mjs:
13
+ lucide-react/dist/esm/icons/chart-column.mjs:
14
+ lucide-react/dist/esm/icons/link-2.mjs:
15
+ lucide-react/dist/esm/icons/loader-circle.mjs:
16
+ lucide-react/dist/esm/icons/plus.mjs:
17
+ lucide-react/dist/esm/icons/power-off.mjs:
18
+ lucide-react/dist/esm/icons/power.mjs:
19
+ lucide-react/dist/esm/icons/refresh-cw.mjs:
20
+ lucide-react/dist/esm/icons/server.mjs:
21
+ lucide-react/dist/esm/icons/shield-check.mjs:
22
+ lucide-react/dist/esm/icons/wifi-off.mjs:
23
+ lucide-react/dist/esm/icons/wifi.mjs:
24
+ lucide-react/dist/esm/icons/x.mjs:
25
+ lucide-react/dist/esm/lucide-react.mjs:
26
+ (**
27
+ * @license lucide-react v1.11.0 - ISC
28
+ *
29
+ * This source code is licensed under the ISC license.
30
+ * See the LICENSE file in the root directory of this source tree.
31
+ *)
32
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhin.js/adapter-telegram",
3
- "version": "1.0.58",
3
+ "version": "1.0.59",
4
4
  "description": "Zhin.js adapter for Telegram",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -40,12 +40,13 @@
40
40
  "@types/react-dom": "^19.2.1",
41
41
  "lucide-react": "^1.11.0",
42
42
  "typescript": "^6.0.3",
43
- "@zhin.js/console": "2.0.13",
44
- "zhin.js": "1.0.72"
43
+ "@zhin.js/cli": "1.0.68",
44
+ "zhin.js": "1.0.72",
45
+ "@zhin.js/console": "2.0.14"
45
46
  },
46
47
  "peerDependencies": {
47
48
  "@zhin.js/client": "1.0.18",
48
- "@zhin.js/console": "2.0.13",
49
+ "@zhin.js/console": "2.0.14",
49
50
  "@zhin.js/http": "1.0.65",
50
51
  "@zhin.js/logger": "0.1.54",
51
52
  "zhin.js": "1.0.72"
@@ -76,7 +77,7 @@
76
77
  "registry": "https://registry.npmjs.org"
77
78
  },
78
79
  "scripts": {
79
- "build": "tsc && node ../../../scripts/build-console-client-if-present.mjs",
80
+ "build": "zhin build",
80
81
  "clean": "rimraf lib dist",
81
82
  "build:node": "tsc"
82
83
  }