@zentry-org/sdk 0.0.1 → 1.0.2
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/README.md +3 -3
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.js +1 -1
- package/package.json +14 -1
package/README.md
CHANGED
|
@@ -568,9 +568,9 @@ Backend apps send:
|
|
|
568
568
|
|
|
569
569
|
Use:
|
|
570
570
|
|
|
571
|
-
- `@zentry/sdk/react` in the UI
|
|
572
|
-
- `@zentry/sdk/react-server` for server-side React helpers
|
|
573
|
-
- `@zentry/sdk/node` in the backend API
|
|
571
|
+
- `@zentry-org/sdk/react` in the UI
|
|
572
|
+
- `@zentry-org/sdk/react-server` for server-side React helpers
|
|
573
|
+
- `@zentry-org/sdk/node` in the backend API
|
|
574
574
|
|
|
575
575
|
The UI owns login and token capture.
|
|
576
576
|
|
package/dist/react/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Zentry Engine Core Pipeline Output
|
|
2
|
-
"use strict";var
|
|
2
|
+
"use strict";var D=Object.create;var m=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var G=Object.getPrototypeOf,Y=Object.prototype.hasOwnProperty;var $=(e,t)=>{for(var r in t)m(e,r,{get:t[r],enumerable:!0})},E=(e,t,r,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of U(t))!Y.call(e,s)&&s!==r&&m(e,s,{get:()=>t[s],enumerable:!(c=B(t,s))||c.enumerable});return e};var A=(e,t,r)=>(r=e!=null?D(G(e)):{},E(t||!e||!e.__esModule?m(r,"default",{value:e,enumerable:!0}):r,e)),z=e=>E(m({},"__esModule",{value:!0}),e);var re={};$(re,{Authenticated:()=>ee,LoginButton:()=>Q,LogoutButton:()=>W,RegisterButton:()=>J,UnAuthenticated:()=>te,ZentryProvider:()=>X,getServerSession:()=>oe,useZentry:()=>l,useZentryCallbackSync:()=>q});module.exports=z(re);var i=require("react"),v=A(require("axios"),1);var u="token",d="http://localhost:5000/api/v1",S="http://localhost:3000",p="X-Zentry-Org-ID";var o=require("zod"),Z=o.z.string().min(1),K=o.z.enum(["CREDENTIAL","OAUTH"]),j=o.z.enum(["LOCAL","GOOGLE"]),H=o.z.enum(["ADMIN","MEMBER"]),M=o.z.unknown(),F=o.z.object({id:o.z.uuid(),email:o.z.email(),firstName:o.z.string(),lastName:o.z.string(),emailVerified:o.z.boolean(),imageUrl:o.z.string().nullable(),createdAt:Z,updatedAt:Z}),V={status_code:o.z.number().int().nonnegative(),message:o.z.string()},g=e=>o.z.object({success:o.z.literal(!0),...V,data:e}),f=o.z.object({user:F,org:o.z.object({id:o.z.uuid(),name:o.z.string()}),membership:o.z.object({id:o.z.uuid(),role:H,isBanned:o.z.boolean(),permissions:M.nullable()}),account:o.z.object({id:o.z.uuid(),provider:j,providerType:K,accountId:o.z.string(),providerAvatarUrl:o.z.string().nullable()})});var I=require("react/jsx-runtime"),R=()=>{if(typeof window>"u")return null;let e=localStorage.getItem(u);return typeof e!="string"?(console.error("No active token found or token is not a string"),null):e},w=e=>{typeof window>"u"||localStorage.removeItem(e)},x=(0,i.createContext)(void 0);function X({children:e,env:t}){let[r,c]=(0,i.useState)(null),[s,y]=(0,i.useState)(!1),[T,_]=(0,i.useState)(!0),k=async()=>{let n=R();if(!n){_(!1),console.log("No active token found, skipping session sync");return}try{let C=await v.default.get(`${d}/auth/org/me`,{headers:{[p]:t.ZENTRY_ORG_ID,Authorization:`Bearer ${n}`}}),h=g(f).safeParse(C.data);if(!h.success)throw console.error("Invalid session data received from server:",h.error),new Error("Invalid session data received from Zentry server.");c(h.data.data),y(!0)}catch{w(u),c(null),y(!1)}finally{_(!1)}};(0,i.useEffect)(()=>{k().then(()=>{console.log("Session synced")}).catch(n=>{console.error("Error syncing session:",n)})},[]);let N=()=>{let n=new URL(`${S}/org/register`);n.searchParams.set("callbackUrl",t.ZENTRY_APP_CALLBACK_URL),n.searchParams.set("orgId",t.ZENTRY_ORG_ID),window.location.href=n.toString()},L=()=>{let n=new URL(`${S}/org/login`);n.searchParams.set("callbackUrl",t.ZENTRY_APP_CALLBACK_URL),n.searchParams.set("orgId",t.ZENTRY_ORG_ID),window.location.href=n.toString()},b=async()=>{try{let n=R();if(!n){console.error("No active token found, skipping logout");return}await v.default.post(`${d}/auth/org/logout`,{},{headers:{[p]:t.ZENTRY_ORG_ID,Authorization:`Bearer ${n}`}}),w(u),c(null),y(!1),window.location.reload()}catch(n){console.error("Error logging out:",n)}},O=()=>R();return(0,I.jsx)(x.Provider,{value:{isAuthenticated:s,isLoading:T,session:r,login:L,logout:b,register:N,getSessionToken:O},children:e})}function l(){let e=(0,i.useContext)(x);if(!e)throw new Error("useZentry must be nested within a ZentryProvider");return e}function q(){(0,i.useEffect)(()=>{if(typeof window>"u")return;let t=new URLSearchParams(window.location.search).get("token");if(t){localStorage.setItem(u,t);let r=window.location.pathname+window.location.hash;window.history.replaceState({},document.title,r),window.location.reload()}},[])}var de=require("react");var a=require("react/jsx-runtime"),J=({className:e="",label:t="Register"})=>{let{register:r}=l();return(0,a.jsx)("button",{onClick:r,className:e,children:t})};function Q({className:e="",label:t="Login"}){let{login:r}=l();return(0,a.jsx)("button",{onClick:r,className:e,children:t})}function W({className:e="",label:t="LogOut"}){let{logout:r}=l();return(0,a.jsx)("button",{onClick:async()=>{await r()},className:e,children:t})}var ee=({children:e})=>{let{isAuthenticated:t}=l();return t?(0,a.jsx)(a.Fragment,{children:e}):null},te=({children:e})=>{let{isAuthenticated:t}=l();return t?null:(0,a.jsx)(a.Fragment,{children:e})};var P=A(require("axios"),1);async function oe(e){try{let t={[p]:e.env.ZENTRY_ORG_ID};e.token&&(t.Authorization=`Bearer ${e.token}`),e.cookie&&(t.Cookie=e.cookie);let r=await P.default.get(`${d}/auth/org/me`,{headers:t}),s=g(f).safeParse(r.data);if(!s.success)throw console.error("Invalid session data received from server:",s.error),new Error("Invalid session data received from Zentry server.");return s.data.data}catch(t){return console.error({error:t,message:"Failed to get session"}),null}}0&&(module.exports={Authenticated,LoginButton,LogoutButton,RegisterButton,UnAuthenticated,ZentryProvider,getServerSession,useZentry,useZentryCallbackSync});
|
package/dist/react/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Zentry Engine Core Pipeline Output
|
|
2
|
-
import{a as b}from"../chunk-OMDRZCFK.js";import{a as s,b as u,c as d,d as
|
|
2
|
+
import{a as b}from"../chunk-OMDRZCFK.js";import{a as s,b as u,c as d,d as g,f as m,g as h}from"../chunk-SCUKQ3VA.js";import{createContext as x,useContext as I,useState as f,useEffect as P}from"react";import R from"axios";import{jsx as C}from"react/jsx-runtime";var p=()=>{if(typeof window>"u")return null;let e=localStorage.getItem(s);return typeof e!="string"?(console.error("No active token found or token is not a string"),null):e},w=e=>{typeof window>"u"||localStorage.removeItem(e)},S=x(void 0);function G({children:e,env:t}){let[n,a]=f(null),[_,c]=f(!1),[v,y]=f(!0),A=async()=>{let o=p();if(!o){y(!1),console.log("No active token found, skipping session sync");return}try{let T=await R.get(`${u}/auth/org/me`,{headers:{[g]:t.ZENTRY_ORG_ID,Authorization:`Bearer ${o}`}}),l=m(h).safeParse(T.data);if(!l.success)throw console.error("Invalid session data received from server:",l.error),new Error("Invalid session data received from Zentry server.");a(l.data.data),c(!0)}catch{w(s),a(null),c(!1)}finally{y(!1)}};P(()=>{A().then(()=>{console.log("Session synced")}).catch(o=>{console.error("Error syncing session:",o)})},[]);let k=()=>{let o=new URL(`${d}/org/register`);o.searchParams.set("callbackUrl",t.ZENTRY_APP_CALLBACK_URL),o.searchParams.set("orgId",t.ZENTRY_ORG_ID),window.location.href=o.toString()},E=()=>{let o=new URL(`${d}/org/login`);o.searchParams.set("callbackUrl",t.ZENTRY_APP_CALLBACK_URL),o.searchParams.set("orgId",t.ZENTRY_ORG_ID),window.location.href=o.toString()},L=async()=>{try{let o=p();if(!o){console.error("No active token found, skipping logout");return}await R.post(`${u}/auth/org/logout`,{},{headers:{[g]:t.ZENTRY_ORG_ID,Authorization:`Bearer ${o}`}}),w(s),a(null),c(!1),window.location.reload()}catch(o){console.error("Error logging out:",o)}},N=()=>p();return C(S.Provider,{value:{isAuthenticated:_,isLoading:v,session:n,login:E,logout:L,register:k,getSessionToken:N},children:e})}function r(){let e=I(S);if(!e)throw new Error("useZentry must be nested within a ZentryProvider");return e}function $(){P(()=>{if(typeof window>"u")return;let t=new URLSearchParams(window.location.search).get("token");if(t){localStorage.setItem(s,t);let n=window.location.pathname+window.location.hash;window.history.replaceState({},document.title,n),window.location.reload()}},[])}import"react";import{Fragment as Z,jsx as i}from"react/jsx-runtime";var J=({className:e="",label:t="Register"})=>{let{register:n}=r();return i("button",{onClick:n,className:e,children:t})};function M({className:e="",label:t="Login"}){let{login:n}=r();return i("button",{onClick:n,className:e,children:t})}function Q({className:e="",label:t="LogOut"}){let{logout:n}=r();return i("button",{onClick:async()=>{await n()},className:e,children:t})}var V=({children:e})=>{let{isAuthenticated:t}=r();return t?i(Z,{children:e}):null},W=({children:e})=>{let{isAuthenticated:t}=r();return t?null:i(Z,{children:e})};export{V as Authenticated,M as LoginButton,Q as LogoutButton,J as RegisterButton,W as UnAuthenticated,G as ZentryProvider,b as getServerSession,r as useZentry,$ as useZentryCallbackSync};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zentry-org/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -15,6 +15,19 @@
|
|
|
15
15
|
"url": "https://github.com/kavinda-100/zentry/issues"
|
|
16
16
|
},
|
|
17
17
|
"homepage": "https://github.com/kavinda-100/zentry#readme",
|
|
18
|
+
"keywords": [
|
|
19
|
+
"zentry",
|
|
20
|
+
"zentry-org",
|
|
21
|
+
"sdk",
|
|
22
|
+
"authentication",
|
|
23
|
+
"authorization",
|
|
24
|
+
"auth",
|
|
25
|
+
"auth-sdk",
|
|
26
|
+
"auth-provider",
|
|
27
|
+
"react",
|
|
28
|
+
"node",
|
|
29
|
+
"typescript"
|
|
30
|
+
],
|
|
18
31
|
"exports": {
|
|
19
32
|
"./react": {
|
|
20
33
|
"types": "./dist/react/index.d.ts",
|