@donotdev/oauth 0.0.3 → 0.0.5

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.
@@ -1 +1 @@
1
- "use client";import{jsx as o}from"react/jsx-runtime";import{Alert as b,Stack as O,Grid as N}from"@donotdev/components";import{useTranslation as w,getEnabledOAuthPartners as P}from"@donotdev/core";import{withOAuthFallback as $}from"./OAuthFallback";import{OAuthPartnerButton as S}from"./OAuthPartnerButton";const x=({providers:a=P(),purpose:c="api-access",containerClassName:n="",providerClassName:d="",variant:E="outline",layout:e="vertical",showLabels:u=!0,ariaLabel:h,id:m,fullWidth:p=!0,onSuccess:v,onError:f})=>{const{t}=w("dndev"),s=m||`oauth-providers-${Math.random().toString(36).slice(2,9)}`;if(a.length===0)return o(b,{title:t("oauth.noProviders","No OAuth Providers"),description:t("oauth.noProvidersMessage","No OAuth providers are currently enabled. Check your environment configuration.")});const g=()=>{const i=a.map((r,A)=>o(S,{partnerId:r,purpose:c,className:`${d} ${p?"dndev-w-full":""}`,tabIndex:A===0?0:void 0,id:`${s}-${r}-button`,onSuccess:v,onOAuthError:f,children:u?`${r.charAt(0).toUpperCase()+r.slice(1)}`:null},r));return e==="grid"?o(N,{cols:{base:1,sm:2,md:3},gap:"medium",className:n,children:i}):o(O,{direction:e==="horizontal"?"row":"column",wrap:e==="horizontal"?"wrap":void 0,align:e==="horizontal"?"center":"stretch",gap:"medium",className:n,children:i})};return o("div",{className:"dndev-mx-auto",id:s,role:"region","aria-label":h||t("oauth.aria.connectionOptions","Service connection options"),children:g()})},l=$(x,{message:"OAuth connections are not configured",showConnectButton:!0});var C=l;export{l as MultipleOAuthProviders,C as default};
1
+ "use client";import{jsx as r}from"react/jsx-runtime";import{Alert as A,Stack as O,Grid as P}from"@donotdev/components";import{useTranslation as b,getEnabledOAuthPartners as w}from"@donotdev/core";import{withOAuthFallback as x}from"./OAuthFallback";import{OAuthPartnerButton as $}from"./OAuthPartnerButton";const N=({providers:n=w(),purpose:a="api-access",containerClassName:i="",providerClassName:u="",variant:S="outline",layout:t="vertical",showLabels:l=!0,ariaLabel:d,id:m,fullWidth:h=!0,onSuccess:p,onError:v})=>{const{t:o}=b("oauth"),s=m||`oauth-providers-${Math.random().toString(36).slice(2,9)}`;if(n.length===0)return r(A,{title:o("noProviders","No OAuth Providers"),description:o("noProvidersMessage","No OAuth providers are currently enabled. Check your environment configuration.")});const f=()=>{const c=n.map((e,g)=>r($,{partnerId:e,purpose:a,className:`${u} ${h?"dndev-w-full":""}`,tabIndex:g===0?0:void 0,id:`${s}-${e}-button`,onSuccess:p,onOAuthError:v,children:l?`${e.charAt(0).toUpperCase()+e.slice(1)}`:null},e));return t==="grid"?r(P,{cols:{base:1,sm:2,md:3},gap:"medium",className:i,children:c}):r(O,{direction:t==="horizontal"?"row":"column",wrap:t==="horizontal"?"wrap":void 0,align:t==="horizontal"?"center":"stretch",gap:"medium",className:i,children:c})};return r("div",{className:"dndev-mx-auto",id:s,role:"region","aria-label":d||o("aria.connectionOptions","Service connection options"),children:f()})},M=x(N,{message:"OAuth connections are not configured",showConnectButton:!0});var E=M;export{M as MultipleOAuthProviders,E as default};
@@ -1 +1 @@
1
- import{jsx as e,jsxs as c}from"react/jsx-runtime";import{Dialog as p,BUTTON_VARIANT as d}from"@donotdev/components";import{useTranslation as l,getEnabledOAuthPartners as h}from"@donotdev/core";import{MultipleOAuthProviders as u}from"./MultipleOAuthProviders";function v({open:r,onOpenChange:t,purpose:a="api-access",title:i,description:s}){const{t:o}=l("dndev"),n=h();return e(p,{open:r,onOpenChange:t,title:i||o("oauth.connectServices","Connect Services"),description:s||o("oauth.chooseService","Choose which services to connect for enhanced functionality"),children:e("div",{style:{padding:"var(--gap-md)"},children:n.length>0?e(u,{providers:n,purpose:a,layout:"vertical",variant:d.OUTLINE,showLabels:!0}):c("div",{style:{paddingTop:"var(--gap-lg)",paddingBottom:"var(--gap-lg)",color:"var(--muted-foreground)"},children:[e("p",{children:o("oauth.noProvidersEnabled","No OAuth providers are currently enabled")}),e("p",{style:{marginTop:"var(--gap-sm)",fontSize:"var(--font-size-sm)"},children:o("oauth.checkConfiguration","Check your environment configuration")})]})})})}export{v as OAuthConnectionModal};
1
+ import{jsx as e,jsxs as c}from"react/jsx-runtime";import{Dialog as d,BUTTON_VARIANT as l}from"@donotdev/components";import{useTranslation as p,getEnabledOAuthPartners as h}from"@donotdev/core";import{MultipleOAuthProviders as u}from"./MultipleOAuthProviders";function y({open:n,onOpenChange:t,purpose:i="api-access",title:a,description:s}){const{t:o}=p("oauth"),r=h();return e(d,{open:n,onOpenChange:t,title:a||o("connectServices","Connect Services"),description:s||o("oauth.chooseService","Choose which services to connect for enhanced functionality"),children:e("div",{style:{padding:"var(--gap-md)"},children:r.length>0?e(u,{providers:r,purpose:i,layout:"vertical",variant:l.OUTLINE,showLabels:!0}):c("div",{style:{paddingTop:"var(--gap-lg)",paddingBottom:"var(--gap-lg)",color:"var(--muted-foreground)"},children:[e("p",{children:o("oauth.noProvidersEnabled","No OAuth providers are currently enabled")}),e("p",{style:{marginTop:"var(--gap-sm)",fontSize:"var(--font-size-sm)"},children:o("oauth.checkConfiguration","Check your environment configuration")})]})})})}export{y as OAuthConnectionModal};
@@ -1 +1 @@
1
- import{jsx as o}from"react/jsx-runtime";import{FeatureFallback as n,withFeatureFallback as s}from"@donotdev/components";import{isFeatureAvailable as u,FRAMEWORK_FEATURES as i}from"@donotdev/core";function r({message:t="OAuth connections are not available",showConnectButton:e=!1,className:a=""}){return o(n,{featureName:"OAuth Connections",message:t,icon:"\u{1F517}",showActionButton:e,actionButtonText:"Connect (Unavailable)",className:a,helpText:"This feature requires OAuth to be configured."})}function c(t,e){return s(t,"OAuth Connections",()=>u(i.OAUTH),{message:e?.message,showActionButton:e?.showConnectButton,actionButtonText:"Connect (Unavailable)",icon:"\u{1F517}",helpText:"This feature requires OAuth to be configured."})}export{r as OAuthFallback,c as withOAuthFallback};
1
+ import{jsx as o}from"react/jsx-runtime";import{FeatureFallback as a,withFeatureFallback as u}from"@donotdev/components";import{isFeatureAvailable as i,FRAMEWORK_FEATURES as r}from"@donotdev/core";function h({message:e="OAuth connections are not available",showConnectButton:t=!1,className:n=""}){return o(a,{featureName:"OAuth Connections",message:e,icon:"\u{1F517}",showActionButton:t,actionButtonText:"Connect (Unavailable)",className:n,helpText:"This feature requires OAuth to be configured."})}function A(e,t){return u(e,"OAuth Connections",()=>i(r.OAUTH),{message:t?.message,showActionButton:t?.showConnectButton,actionButtonText:"Connect (Unavailable)",icon:"\u{1F517}",helpText:"This feature requires OAuth to be configured."})}export{h as OAuthFallback,A as withOAuthFallback};
@@ -1 +1 @@
1
- import{jsx as b}from"react/jsx-runtime";import{useOAuth as e}from"../useOAuth";function f({partnerId:n,purpose:t="api-access",onSuccess:c,onOAuthError:o,className:a="",children:i,disabled:d=!1,...u}){const p=e("isConnected"),l=e("connect"),h=e("disconnect"),s=e("status")==="initializing",m=e("error"),r=p(n);return b("button",{onClick:async()=>{try{r?await h(n):(await l(n,t),c?.({partnerId:n,purpose:t}))}catch(C){o?.(C)}},disabled:d||s,className:a,title:m||void 0,...u,children:i||(s?`Connecting to ${n}...`:r?`Disconnect ${n}`:`Connect ${n}`)})}export{f as OAuthPartnerButton};
1
+ import{jsx as m}from"react/jsx-runtime";import{useOAuth as n}from"../useOAuth";function b({partnerId:t,purpose:o="api-access",onSuccess:i,onOAuthError:a,className:r="",children:c,disabled:u=!1,...l}){const f=n("isConnected"),C=n("connect"),d=n("disconnect"),e=n("status")==="initializing",g=n("error"),s=f(t);return m("button",{onClick:async()=>{try{s?await d(t):(await C(t,o),i?.({partnerId:t,purpose:o}))}catch(h){a?.(h)}},disabled:u||e,className:r,title:g||void 0,...l,children:c||(e?`Connecting to ${t}...`:s?`Disconnect ${t}`:`Connect ${t}`)})}export{b as OAuthPartnerButton};
@@ -1 +1 @@
1
- import{OAUTH_PARTNERS as i,getOAuthRedirectUrl as u,getPlatformEnvVar as e}from"@donotdev/core";function s(t){if(!i[t])return!1;const r=e("OAUTH_PARTNERS");return r?r.split(",").map(n=>n.trim()).includes(t):!1}function a(t){const r=`${t.toUpperCase()}_CLIENT_ID`;return e(r)||null}function o(t){return u()}export{a as getOAuthClientId,o as getOAuthRedirectUri,s as isOAuthPartnerEnabled};
1
+ import{OAUTH_PARTNERS as i,getOAuthRedirectUrl as u,getPlatformEnvVar as r}from"@donotdev/core";function s(t){if(!i[t])return!1;const e=r("OAUTH_PARTNERS");return e?e.split(",").map(n=>n.trim()).includes(t):!1}function l(t){const e=`${t.toUpperCase()}_CLIENT_ID`;return r(e)||null}function p(t){return u()}export{l as getOAuthClientId,p as getOAuthRedirectUri,s as isOAuthPartnerEnabled};
@@ -1 +1 @@
1
- import*as e from"valibot";const i=e.object({provider:e.string(),purpose:e.picklist(["authentication","api-access"]),code:e.pipe(e.string(),e.minLength(1,"Authorization code is required")),redirectUri:e.pipe(e.string(),e.url("Valid redirect URI is required")),codeVerifier:e.optional(e.string()),state:e.optional(e.string()),instance:e.optional(e.pipe(e.string(),e.url()))}),r=e.object({provider:e.string(),refreshToken:e.pipe(e.string(),e.minLength(1,"Refresh token is required")),redirectUri:e.pipe(e.string(),e.url("Valid redirect URI is required"))}),t=e.object({provider:e.string(),purpose:e.picklist(["authentication","api-access"])}),s=e.object({provider:e.string(),purpose:e.picklist(["authentication","api-access"])});export{t as connectionRequestSchema,s as disconnectionRequestSchema,i as exchangeTokenSchema,r as refreshTokenSchema};
1
+ import*as e from"valibot";const i=e.object({provider:e.string(),purpose:e.picklist(["authentication","api-access"]),code:e.pipe(e.string(),e.minLength(1,"Authorization code is required")),redirectUri:e.pipe(e.string(),e.url("Valid redirect URI is required")),codeVerifier:e.optional(e.string()),state:e.optional(e.string()),instance:e.optional(e.pipe(e.string(),e.url()))}),r=e.object({provider:e.string(),refreshToken:e.pipe(e.string(),e.minLength(1,"Refresh token is required")),redirectUri:e.pipe(e.string(),e.url("Valid redirect URI is required"))}),t=e.object({provider:e.string(),purpose:e.picklist(["authentication","api-access"])}),o=e.object({provider:e.string(),purpose:e.picklist(["authentication","api-access"])});export{t as connectionRequestSchema,o as disconnectionRequestSchema,i as exchangeTokenSchema,r as refreshTokenSchema};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{useOAuth as t}from"./useOAuth";import{MultipleOAuthProviders as a,OAuthConnectionModal as u,OAuthFallback as o,OAuthPartnerButton as r}from"./components";export{a as MultipleOAuthProviders,u as OAuthConnectionModal,o as OAuthFallback,r as OAuthPartnerButton,t as useOAuth};
1
+ import{useOAuth as r}from"./useOAuth";import{MultipleOAuthProviders as e,OAuthConnectionModal as h,OAuthFallback as l,OAuthPartnerButton as n}from"./components";export{e as MultipleOAuthProviders,h as OAuthConnectionModal,l as OAuthFallback,n as OAuthPartnerButton,r as useOAuth};
@@ -1 +1 @@
1
- import{createDoNotDevStore as i,FEATURE_STATUS as p}from"@donotdev/core";const a=i({name:"oauth-store",createStore:(r,n)=>({status:p.READY,loading:!1,error:null,partners:{},setStatus:e=>r({status:e}),setLoading:e=>r({loading:e}),setError:e=>r({error:e}),setPartnerConnecting:(e,t)=>r(s=>({partners:{...s.partners,[e]:{...s.partners[e],isConnecting:t,error:t?null:s.partners[e]?.error}}})),setPartnerConnected:(e,t,s)=>r(o=>({partners:{...o.partners,[e]:{isConnected:!0,isConnecting:!1,credentials:t,error:null,lastConnected:new Date().toISOString(),purpose:s}}})),setPartnerDisconnected:e=>r(t=>({partners:{...t.partners,[e]:{isConnected:!1,isConnecting:!1,credentials:null,error:null,lastConnected:t.partners[e]?.lastConnected}}})),setPartnerError:(e,t)=>r(s=>({partners:{...s.partners,[e]:{...s.partners[e],isConnecting:!1,error:t}}})),isConnected:e=>n().partners[e]?.isConnected||!1,getCredentials:e=>n().partners[e]?.credentials||null,getConnectedPartners:()=>{const e=n();return Object.entries(e.partners).filter(([t,s])=>s.isConnected).map(([t])=>t)},getPartnerState:e=>n().partners[e]||null}),persistOptions:{name:"dndev-oauth-store",partialize:r=>({partners:r.partners})}}),u=()=>a(r=>r.loading),c=()=>a(r=>r.error),l=()=>a(r=>r.partners),d=r=>a(n=>n.getPartnerState(r)),C=r=>a(n=>n.isConnected(r)),g=r=>a(n=>n.getCredentials(r));export{C as useOAuthConnected,g as useOAuthCredentials,c as useOAuthError,u as useOAuthLoading,d as useOAuthPartner,l as useOAuthPartners,a as useOAuthStore};
1
+ import{createDoNotDevStore as c,FEATURE_STATUS as i}from"@donotdev/core";const o=c({name:"oauth-store",createStore:(t,n)=>({status:i.READY,loading:!1,error:null,partners:{},setStatus:e=>t({status:e}),setLoading:e=>t({loading:e}),setError:e=>t({error:e}),setPartnerConnecting:(e,r)=>t(s=>({partners:{...s.partners,[e]:{...s.partners[e],isConnecting:r,error:r?null:s.partners[e]?.error}}})),setPartnerConnected:(e,r,s)=>t(a=>({partners:{...a.partners,[e]:{isConnected:!0,isConnecting:!1,credentials:r,error:null,lastConnected:new Date().toISOString(),purpose:s}}})),setPartnerDisconnected:e=>t(r=>({partners:{...r.partners,[e]:{isConnected:!1,isConnecting:!1,credentials:null,error:null,lastConnected:r.partners[e]?.lastConnected}}})),setPartnerError:(e,r)=>t(s=>({partners:{...s.partners,[e]:{...s.partners[e],isConnecting:!1,error:r}}})),isConnected:e=>n().partners[e]?.isConnected||!1,getCredentials:e=>n().partners[e]?.credentials||null,getConnectedPartners:()=>{const e=n();return Object.entries(e.partners).filter(([r,s])=>s.isConnected).map(([r])=>r)},getPartnerState:e=>n().partners[e]||null}),persistOptions:{name:"dndev-oauth-store",partialize:t=>({partners:t.partners})}}),u=()=>o(t=>t.loading),p=()=>o(t=>t.error),d=()=>o(t=>t.partners),C=t=>o(n=>n.getPartnerState(t)),g=t=>o(n=>n.isConnected(t)),A=t=>o(n=>n.getCredentials(t));export{g as useOAuthConnected,A as useOAuthCredentials,p as useOAuthError,u as useOAuthLoading,C as useOAuthPartner,d as useOAuthPartners,o as useOAuthStore};