PageSourceSearch

https://netfocus-reimagine-website.lovable.app/assets/APIKeys-SMqUNaka.js

js netfocus-reimagine-website.lovable.app collected 2026-10-03 03:35:03 UTC 8,215 bytes, 13 lines download raw bytes

1import{m as z,r as g,i as U,s as w,j as e,B as p,C as b,a as C,b as P,a1 as _,c as I,I as K,Y as F}from"./index-DwD5y2V5.js";import{B as q}from"./badge-tGAspnuj.js";import{P as V}from"./ProtectedRoute-CWczz8ol.js";import{P as G}from"./plus-CPoFmkL1.js";import{t as l,c as J,e as Q,g as T,d as E,f as D,a as W}from"./en-US-DWrl2lTx.js";import{e as Z,d as $}from"./endOfMonth-DIWrT0r0.js";import{T as ee}from"./trash-2-DaWULBFJ.js";/**
2 * @license lucide-react v0.462.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const te=z("Copy",[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]);function M(s,n){const a=l(s),o=l(n),t=a.getTime()-o.getTime();return t<0?-1:t>0?1:t}function se(s){return J(s,Date.now())}function ae(s){return n=>{const o=(s?Math[s]:Math.trunc)(n);return o===0?0:o}}function re(s,n){return+l(s)-+l(n)}function ne(s){const n=l(s);return n.setHours(23,59,59,999),n}function ie(s){const n=l(s);return+ne(n)==+Z(n)}function ce(s,n){const a=l(s),o=l(n),t=M(a,o),x=Math.abs($(a,o));let d;if(x<1)d=0;else{a.getMonth()===1&&a.getDate()>27&&a.setDate(30),a.setMonth(a.getMonth()-t*x);let r=M(a,o)===-t;ie(l(s))&&x===1&&M(s,o)===1&&(r=!1),d=t*(x-Number(r))}return d===0?0:d}function oe(s,n,a){const o=re(s,n)/1e3;return ae(a==null?void 0:a.roundingMethod)(o)}function le(s,n,a){const o=W(),t=(a==null?void 0:a.locale)??o.locale??Q,x=2520,d=M(s,n);if(isNaN(d))throw new RangeError("Invalid time value");const r=Object.assign({},a,{addSuffix:a==null?void 0:a.addSuffix,comparison:d});let m,y;d>0?(m=l(n),y=l(s)):(m=l(s),y=l(n));const j=oe(y,m),N=(T(y)-T(m))/1e3,i=Math.round((j-N)/60);let f;if(i<2)return a!=null&&a.includeSeconds?j<5?t.formatDistance("lessThanXSeconds",5,r):j<10?t.formatDistance("lessThanXSeconds",10,r):j<20?t.formatDistance("lessThanXSeconds",20,r):j<40?t.formatDistance("halfAMinute",0,r):j<60?t.formatDistance("lessThanXMinutes",1,r):t.formatDistance("xMinutes",1,r):i===0?t.formatDistance("lessThanXMinutes",1,r):t.formatDistance("xMinutes",i,r);if(i<45)return t.formatDistance("xMinutes",i,r);if(i<90)return t.formatDistance("aboutXHours",1,r);if(i<E){const h=Math.round(i/60);return t.formatDistance("aboutXHours",h,r)}else{if(i<x)return t.formatDistance("xDays",1,r);if(i<D){const h=Math.round(i/E);return t.formatDistance("xDays",h,r)}else if(i<D*2)return f=Math.round(i/D),t.formatDistance("aboutXMonths",f,r)}if(f=ce(y,m),f<12){const h=Math.round(i/D);return t.formatDistance("xMonths",h,r)}else{const h=f%12,v=Math.trunc(f/12);return h<3?t.formatDistance("aboutXYears",v,r):h<9?t.formatDistance("overXYears",v,r):t.formatDistance("almostXYears",v+1,r)}}function O(s,n){return le(s,se(s),n)}function je(){const[s,n]=g.useState([]),[a,o]=g.useState(!0),[t,x]=g.useState(!1),[d,r]=g.useState(""),[m,y]=g.useState(null),[j,N]=g.useState(!1),{toast:i}=U();g.useEffect(()=>{f()},[]);const f=async()=>{try{const{data:c,error:u}=await w.from("api_keys").select("*").order("created_at",{ascending:!1});if(u)throw u;n(c||[])}catch(c){i({title:"Error",description:c.message,variant:"destructive"})}finally{o(!1)}},h=async()=>{var c;if(!d.trim()){i({title:"Error",description:"Please enter a name for the API key",variant:"destructive"});return}x(!0);try{const{data:u,error:k}=await w.rpc("generate_api_key");if(k)throw k;const A=u,H=A.substring(0,8)+"...",R=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(A)),Y=Array.from(new Uint8Array(R)).map(L=>L.toString(16).padStart(2,"0")).join(""),{data:B}=await w.auth.getUser(),{error:S}=await w.from("api_keys").insert({name:d,key_hash:Y,key_prefix:H,created_by:(c=B.user)==null?void 0:c.id});if(S)throw S;y(A),r(""),N(!1),await f(),i({title:"Success",description:"API key created successfully"})}catch(u){i({title:"Error",description:u.message,variant:"destructive"})}finally{x(!1)}},v=c=>{navigator.clipboard.writeText(c),i({title:"Copied",description:"API key copied to clipboard"})},X=async c=>{try{const{error:u}=await w.from("api_keys").delete().eq("id",c);if(u)throw u;await f(),i({title:"Success",description:"API key deleted successfully"})}catch(u){i({title:"Error",description:u.message,variant:"destructive"})}};return a?e.jsx("div",{className:"flex justify-center items-center min-h-screen",children:"Loading..."}):e.jsx(V,{children:e.jsx("div",{className:"container mx-auto py-8 px-4",children:e.jsxs("div",{className:"max-w-4xl mx-auto",children:[e.jsxs("div",{className:"flex justify-between items-center mb-8",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold",children:"API Keys"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:"Manage API keys for automated blog posting"})]}),e.jsxs(p,{onClick:()=>N(!0),children:[e.jsx(G,{className:"w-4 h-4 mr-2"}),"Create API Key"]})]}),m&&e.jsxs(b,{className:"mb-6 border-green-200 bg-green-50",children:[e.jsxs(C,{children:[e.jsx(P,{className:"text-green-800",children:"New API Key Created"}),e.jsx(_,{className:"text-green-600",children:"Copy this key now - it won't be shown again!"})]}),e.jsxs(I,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(K,{value:m,readOnly:!0,className:"font-mono text-sm"}),e.jsx(p,{size:"sm",onClick:()=>v(m),variant:"outline",children:e.jsx(te,{className:"w-4 h-4"})})]}),e.jsx(p,{className:"mt-4",onClick:()=>y(null),variant:"outline",children:"I've saved the key"})]})]}),j&&!m&&e.jsxs(b,{className:"mb-6",children:[e.jsxs(C,{children:[e.jsx(P,{children:"Create New API Key"}),e.jsx(_,{children:"Enter a name to identify this API key"})]}),e.jsx(I,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(F,{htmlFor:"keyName",children:"API Key Name"}),e.jsx(K,{id:"keyName",value:d,onChange:c=>
6r(c.target.value),placeholder:"e.g., String Automation"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(p,{onClick:h,disabled:t,children:t?"Creating...":"Create API Key"}),e.jsx(p,{variant:"outline",onClick:()=>N(!1),children:"Cancel"})]})]})})]}),e.jsx("div",{className:"space-y-4",children:s.length===0?e.jsx(b,{children:e.jsx(I,{className:"text-center py-8",children:e.jsx("p",{className:"text-muted-foreground",children:"No API keys created yet"})})}):s.map(c=>e.jsx(b,{children:e.jsx(I,{className:"p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"font-semibold",children:c.name}),e.jsx(q,{variant:c.is_active?"default":"secondary",children:c.is_active?"Active":"Inactive"})]}),e.jsx("p",{className:"text-sm font-mono text-muted-foreground",children:c.key_prefix}),e.jsxs("div",{className:"text-xs text-muted-foreground space-y-1",children:[e.jsxs("p",{children:["Created ",O(new Date(c.created_at))," ago"]}),c.last_used_at&&e.jsxs("p",{children:["Last used ",O(new Date(c.last_used_at))," ago"]})]})]}),e.jsx(p,{variant:"destructive",size:"sm",onClick:()=>X(c.id),children:e.jsx(ee,{className:"w-4 h-4"})})]})})},c.id))}),e.jsxs(b,{className:"mt-8",children:[e.jsxs(C,{children:[e.jsx(P,{children:"API Usage"}),e.jsx(_,{children:"How to use your API key to post blogs automatically"})]}),e.jsx(I,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium mb-2",children:"Endpoint"}),e.jsxs("code",{className:"bg-muted p-2 rounded text-sm block",children:["POST ",window.location.origin,"/functions/v1/create-blog-post"]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium mb-2",children:"Headers"}),e.jsx("pre",{className:"bg-muted p-2 rounded text-sm",children:`Authorization: Bearer YOUR_API_KEY
7Content-Type: application/json`})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium mb-2",children:"Request Body"}),e.jsx("pre",{className:"bg-muted p-2 rounded text-sm",children:`{
8  "title": "Your Blog Title",
9  "content": "Your blog content here...",
10  "excerpt": "Brief description",
11  "category_id": "uuid-of-category",
12  "status": "published"
13}`})]})]})})]})]})})})}export{je as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.