@urun-sh/react 0.1.18 → 0.1.20
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 +4 -0
- package/README.md +14 -11
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/next-workos.d.mts +8 -0
- package/dist/next-workos.d.ts +8 -0
- package/dist/next-workos.js +1 -0
- package/dist/next-workos.mjs +1 -0
- package/package.json +19 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.20
|
|
4
|
+
|
|
5
|
+
- Pass the live auth token provider through `useApp()` so session creation can recover from stale WorkOS tokens.
|
|
6
|
+
|
|
3
7
|
## 0.1.17
|
|
4
8
|
|
|
5
9
|
- Make the WorkOS Next.js AuthKit import statically discoverable so Next.js bundles the token bridge in production apps.
|
package/README.md
CHANGED
|
@@ -13,6 +13,7 @@ npm install @urun-sh/react @urun-sh/core
|
|
|
13
13
|
```tsx
|
|
14
14
|
import '@urun-sh/react/styles.css'
|
|
15
15
|
import { UrunProvider, useApp } from '@urun-sh/react'
|
|
16
|
+
import { UrunWorkOSProvider } from '@urun-sh/react/workos'
|
|
16
17
|
import { useEffect, useRef } from 'react'
|
|
17
18
|
|
|
18
19
|
function VideoPlayer() {
|
|
@@ -36,14 +37,16 @@ function VideoPlayer() {
|
|
|
36
37
|
|
|
37
38
|
export default function App() {
|
|
38
39
|
return (
|
|
39
|
-
<
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
<UrunWorkOSProvider clientId="client_...">
|
|
41
|
+
<UrunProvider
|
|
42
|
+
baseUrl="https://urun.sh"
|
|
43
|
+
orgId="your-org-id"
|
|
44
|
+
authProvider="workos"
|
|
45
|
+
appId="my-app"
|
|
46
|
+
>
|
|
47
|
+
<VideoPlayer />
|
|
48
|
+
</UrunProvider>
|
|
49
|
+
</UrunWorkOSProvider>
|
|
47
50
|
)
|
|
48
51
|
}
|
|
49
52
|
```
|
|
@@ -54,9 +57,9 @@ export default function App() {
|
|
|
54
57
|
|
|
55
58
|
Browser clients authenticate with an organization ID plus a user/session JWT. During urun setup, the organization is provisioned with an auth provider configuration, such as a WorkOS client ID mapped to a JWKS URL.
|
|
56
59
|
|
|
57
|
-
When `authProvider="workos"`, `UrunProvider`
|
|
60
|
+
When `authProvider="workos"`, wrap `UrunProvider` in an auth bridge that supplies short-lived access tokens. For pure React WorkOS apps, import `UrunWorkOSProvider` from `@urun-sh/react/workos`. For Next.js WorkOS apps, import `UrunWorkOSProvider` from `@urun-sh/react/next-workos`.
|
|
58
61
|
|
|
59
|
-
|
|
62
|
+
For other auth providers, use `UrunAuthProvider` with a `getAccessToken` function, or `UrunJwtProvider` for a static JWT in tests. urun validates JWTs server-side against the JWKS configured for the organization. Do not pass server API keys or long-lived secrets to browser clients.
|
|
60
63
|
|
|
61
64
|
## API
|
|
62
65
|
|
|
@@ -77,4 +80,4 @@ import '@urun-sh/react/styles.css'
|
|
|
77
80
|
|
|
78
81
|
## Peer dependencies
|
|
79
82
|
|
|
80
|
-
`@urun-sh/react` supports React 18 and 19 and expects `@urun-sh/core` of the same release line.
|
|
83
|
+
`@urun-sh/react` supports React 18 and 19 and expects `@urun-sh/core` of the same release line. WorkOS React and Next.js integrations are optional peers used only by `@urun-sh/react/workos` and `@urun-sh/react/next-workos`.
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var L=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var Re=Object.getOwnPropertyNames;var Te=Object.prototype.hasOwnProperty;var Ee=(r,e)=>{for(var t in e)L(r,t,{get:e[t],enumerable:!0})},we=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Re(e))!Te.call(r,o)&&o!==t&&L(r,o,{get:()=>e[o],enumerable:!(n=Ue(e,o))||n.enumerable});return r};var be=r=>we(L({},"__esModule",{value:!0}),r);var Ne={};Ee(Ne,{ComponentRenderer:()=>ae,ImageFrame:()=>ge,ImageFrameSchema:()=>le,MetricsPanel:()=>ve,MetricsPanelSchema:()=>he,ProgressCard:()=>ce,ProgressCardSchema:()=>ue,StatusBadge:()=>de,StatusBadgeSchema:()=>pe,TextStream:()=>fe,TextStreamSchema:()=>me,UrunAuthProvider:()=>D,UrunErrorBoundary:()=>l,UrunJwtProvider:()=>Y,UrunProvider:()=>re,authMode:()=>y,registerComponent:()=>se,urunPublicEnv:()=>i,useApp:()=>ne,useImageFrame:()=>$,useMetricsPanel:()=>H,useProgressCard:()=>F,useStatusBadge:()=>j,useTextStream:()=>z,useUrunAuth:()=>b,usesWorkOSAuth:()=>G});module.exports=be(Ne);var h=require("react");var Z=require("react"),x=require("react/jsx-runtime"),l=class extends Z.Component{constructor(e){super(e),this.state={error:null}}static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){console.error("[urun] Error caught by UrunErrorBoundary:",e,t)}render(){if(this.state.error){let{fallback:e}=this.props;return typeof e=="function"?e(this.state.error):e||(0,x.jsxs)("div",{role:"status","aria-live":"polite",style:{padding:"16px",border:"1px solid rgba(17, 24, 39, 0.12)",borderRadius:"8px",background:"#ffffff",color:"#111827",fontFamily:'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',maxWidth:"360px"},children:[(0,x.jsx)("p",{style:{margin:0,fontWeight:600},children:"Connection interrupted"}),(0,x.jsx)("p",{style:{margin:"6px 0 0",color:"#4b5563"},children:"Reconnecting automatically."})]})}return this.props.children}};var q=require("react"),w=(0,q.createContext)(null);function c(r){return r&&r.trim()?r.trim():void 0}function i(r){switch(r){case"NEXT_PUBLIC_AUTH_MODE":return c(typeof process<"u"?process.env?.NEXT_PUBLIC_AUTH_MODE:void 0);case"NEXT_PUBLIC_AUTH_ENABLED":return c(typeof process<"u"?process.env?.NEXT_PUBLIC_AUTH_ENABLED:void 0);case"NEXT_PUBLIC_SESSION_AUTH_PROVIDER":return c(typeof process<"u"?process.env?.NEXT_PUBLIC_SESSION_AUTH_PROVIDER:void 0);case"NEXT_PUBLIC_SESSION_TOKEN":return c(typeof process<"u"?process.env?.NEXT_PUBLIC_SESSION_TOKEN:void 0);case"NEXT_PUBLIC_URUN_JWT":return c(typeof process<"u"?process.env?.NEXT_PUBLIC_URUN_JWT:void 0);case"VERCEL_ENV":return c(typeof process<"u"?process.env?.VERCEL_ENV:void 0);default:return c(typeof process<"u"?process.env?.[r]:void 0)}}function y(){let r=i("NEXT_PUBLIC_AUTH_MODE")?.toLowerCase();return r==="jwt"||r==="customer-jwt"||r==="test-jwt"?"jwt":r==="workos"||i("VERCEL_ENV")==="production"?"workos":i("NEXT_PUBLIC_AUTH_ENABLED")==="false"?"jwt":"workos"}function G(){return y()==="workos"}var g=require("react"),ee=require("react/jsx-runtime"),Q=(0,g.createContext)(null);function D({getAccessToken:r,children:e}){let t=(0,g.useMemo)(()=>({getAccessToken:r}),[r]);return(0,ee.jsx)(Q.Provider,{value:t,children:e})}var Y=D;function b(){return(0,g.useContext)(Q)}var k=require("react/jsx-runtime");function re({baseUrl:r,orgId:e,appId:t,jwt:n,authProvider:o,fallback:s,children:m}){let[E,P]=(0,h.useState)(),f=b(),Se=i("NEXT_PUBLIC_SESSION_TOKEN")??i("NEXT_PUBLIC_URUN_JWT"),J=y(),I=J==="workos"&&!n,M=n??(J==="jwt"?Se:void 0)??E,W=o??i("NEXT_PUBLIC_SESSION_AUTH_PROVIDER"),Pe=I&&!M,xe=(0,h.useMemo)(()=>({appId:t,baseUrl:r,orgId:e,jwt:M,authProvider:W}),[t,r,W,M,e]);return(0,h.useEffect)(()=>{if(!I||!f)return;let B=!1,ye=f;async function K(){try{let Ce=await ye.getAccessToken();B||P(Ce??void 0)}catch{B||P(void 0)}}K();let _e=window.setInterval(()=>{K()},6e4);return()=>{B=!0,window.clearInterval(_e)}},[f,I]),(0,k.jsx)(l,{fallback:s,children:Pe?(0,k.jsx)("div",{role:"status","aria-live":"polite",children:"Signing in..."}):(0,k.jsx)(w.Provider,{value:xe,children:m})})}var a=require("react"),te=require("@urun-sh/core");function ke(r,e){return`${r}:${JSON.stringify(e??{})}`}var O=class{constructor(e,t){this._doc=e;this._notify=t;this._unsubscribeChange=this._doc.on("change",()=>this._notify())}_doc;_notify;_unsubscribeChange;get(e,t){return this._doc.get(e,t)}set(e){this._doc.set(e),this._notify()}on(e,t){return this._doc.on(e,n=>t(n))}dispose(){this._unsubscribeChange()}},V=class{constructor(e,t){this._stream=e;this._notify=t;this._unsubscribeTrack=this._stream.on("track",()=>this._notify())}_stream;_notify;_unsubscribeTrack;get track(){return this._stream.track}attach(e){return this._stream.attach(e)}detach(){return this._stream.detach()}seek(e){return this._stream.seek(e)}on(e,t){return this._stream.on(e,t)}dispose(){this._unsubscribeTrack()}},X=class{constructor(e,t){this._session=e;this._notify=t}_session;_notify;_docs=new Map;_streams=new Map;get id(){return this._session.id}doc(e){let t=this._docs.get(e);return t||(t=new O(this._session.doc(e),this._notify),this._docs.set(e,t)),t}stream(e){let t=this._streams.get(e);return t||(t=new V(this._session.stream(e),this._notify),this._streams.set(e,t)),t}disconnect(){for(let e of this._docs.values())e.dispose();for(let e of this._streams.values())e.dispose();this._docs.clear(),this._streams.clear(),this._session.disconnect(),this._notify()}};function ne(){let r=(0,a.useContext)(w);if(!r)throw new Error("useApp must be used within <UrunProvider>");if(!r.appId)throw new Error('useApp requires <UrunProvider appId="...">');let[,e]=(0,a.useReducer)(o=>o+1,0),t=(0,a.useRef)(new Map),n=(0,a.useMemo)(()=>(0,te.App)(r.appId,{baseUrl:r.baseUrl,orgId:r.orgId,jwt:r.jwt,authProvider:r.authProvider}),[r.appId,r.baseUrl,r.orgId,r.jwt,r.authProvider]);return(0,a.useMemo)(()=>new Proxy({},{get(o,s){if(typeof s=="string")return m=>{let E=ke(s,m),P=t.current.get(E);if(P)return P;let f=new X(n[s](m),e);return t.current.set(E,f),f}}}),[n])}var oe=new Map;function se(r,e,t){if(!t||typeof t.safeParse!="function")throw new Error(`registerComponent("${r}"): schema must be a valid Zod schema`);oe.set(r,{component:e,schema:t})}function ie(r,e){let t=oe.get(r);if(!t)return{error:`Unknown component: "${r}"`};let n=t.schema.safeParse(e);return n.success?{Component:t.component,validatedProps:n.data}:{error:`Validation failed for "${r}": ${n.error.message}`}}var p=require("react/jsx-runtime");function ae({name:r,props:e,fallback:t}){let n=ie(r,e);if(n.error)return console.warn(`[urun] ComponentRenderer: ${n.error}`),t?(0,p.jsx)(p.Fragment,{children:t}):(0,p.jsx)("div",{className:"urun-component-error",role:"alert",children:(0,p.jsx)("span",{className:"urun-component-error-text",children:n.error})});let o=n.Component;return(0,p.jsx)(o,{...n.validatedProps})}var v=require("zod"),d=require("react/jsx-runtime"),ue=v.z.object({step:v.z.number().min(0),total:v.z.number().min(1),label:v.z.string().optional(),variant:v.z.enum(["default","success","error"]).default("default")});function F(r){let{step:e,total:t,label:n,variant:o="default"}=r,s=Math.min(e/t*100,100),m=e>=t;return{step:e,total:t,label:n,variant:o,percentage:s,isComplete:m}}function ce(r){let{step:e,total:t,label:n,variant:o,percentage:s}=F(r);return(0,d.jsxs)("div",{className:"urun-progress-card","data-variant":o,children:[n&&(0,d.jsx)("div",{className:"urun-progress-label",children:n}),(0,d.jsx)("div",{className:"urun-progress-bar",children:(0,d.jsx)("div",{className:"urun-progress-fill",style:{width:`${s}%`}})}),(0,d.jsxs)("div",{className:"urun-progress-text",children:[e,"/",t]})]})}var A=require("zod"),_=require("react/jsx-runtime"),pe=A.z.object({state:A.z.enum(["thinking","generating","idle","error"]),message:A.z.string().optional()}),Ae={thinking:"Thinking...",generating:"Generating...",idle:"Idle",error:"Error"};function j(r){let{state:e,message:t}=r,n=e==="thinking"||e==="generating",o=t??Ae[e]??e;return{state:e,message:o,isActive:n}}function de(r){let{state:e,message:t,isActive:n}=j(r);return(0,_.jsxs)("span",{className:"urun-status-badge","data-state":e,children:[(0,_.jsx)("span",{className:`urun-status-indicator${n?" urun-status-pulse":""}`}),(0,_.jsx)("span",{className:"urun-status-message",children:t})]})}var C=require("react"),N=require("zod"),U=require("react/jsx-runtime"),me=N.z.object({text:N.z.string(),streaming:N.z.boolean().default(!1)});function z(r){let{text:e,streaming:t=!1}=r,n=e.length===0;return{text:e,streaming:t,isEmpty:n}}function fe(r){let{text:e,streaming:t}=z(r),n=(0,C.useRef)(null),o=(0,C.useRef)(0);return(0,C.useEffect)(()=>{let s=n.current;s&&e.length!==o.current&&(s.textContent=e,o.current=e.length)},[e]),(0,U.jsxs)("div",{className:"urun-text-stream",children:[(0,U.jsx)("span",{ref:n,className:"urun-text-content"}),t&&(0,U.jsx)("span",{className:"urun-text-cursor"})]})}var R=require("zod"),T=require("react/jsx-runtime"),le=R.z.object({src:R.z.string().url(),alt:R.z.string().optional(),caption:R.z.string().optional()});function $(r){let{src:e,alt:t,caption:n}=r;return{src:e,alt:t??"",caption:n}}function ge(r){let{src:e,alt:t,caption:n}=$(r);return(0,T.jsxs)("figure",{className:"urun-image-frame",children:[(0,T.jsx)("img",{className:"urun-image",src:e,alt:t}),n&&(0,T.jsx)("figcaption",{className:"urun-image-caption",children:n})]})}var u=require("zod"),S=require("react/jsx-runtime"),he=u.z.object({metrics:u.z.array(u.z.object({label:u.z.string(),value:u.z.union([u.z.string(),u.z.number()]),unit:u.z.string().optional()}))});function H(r){return{metrics:r.metrics.map(t=>({...t,displayValue:t.unit?`${t.value} ${t.unit}`:String(t.value)}))}}function ve(r){let{metrics:e}=H(r);return(0,S.jsx)("div",{className:"urun-metrics-panel",children:e.map((t,n)=>(0,S.jsxs)("div",{className:"urun-metric-card",children:[(0,S.jsx)("div",{className:"urun-metric-label",children:t.label}),(0,S.jsx)("div",{className:"urun-metric-value",children:t.displayValue})]},n))})}0&&(module.exports={ComponentRenderer,ImageFrame,ImageFrameSchema,MetricsPanel,MetricsPanelSchema,ProgressCard,ProgressCardSchema,StatusBadge,StatusBadgeSchema,TextStream,TextStreamSchema,UrunAuthProvider,UrunErrorBoundary,UrunJwtProvider,UrunProvider,authMode,registerComponent,urunPublicEnv,useApp,useImageFrame,useMetricsPanel,useProgressCard,useStatusBadge,useTextStream,useUrunAuth,usesWorkOSAuth});
|
|
1
|
+
"use strict";var L=Object.defineProperty;var Te=Object.getOwnPropertyDescriptor;var Ue=Object.getOwnPropertyNames;var Re=Object.prototype.hasOwnProperty;var Ee=(r,e)=>{for(var t in e)L(r,t,{get:e[t],enumerable:!0})},ke=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Ue(e))!Re.call(r,o)&&o!==t&&L(r,o,{get:()=>e[o],enumerable:!(n=Te(e,o))||n.enumerable});return r};var Ae=r=>ke(L({},"__esModule",{value:!0}),r);var Ne={};Ee(Ne,{ComponentRenderer:()=>ae,ImageFrame:()=>ge,ImageFrameSchema:()=>le,MetricsPanel:()=>he,MetricsPanelSchema:()=>ve,ProgressCard:()=>ue,ProgressCardSchema:()=>ce,StatusBadge:()=>de,StatusBadgeSchema:()=>pe,TextStream:()=>fe,TextStreamSchema:()=>me,UrunAuthProvider:()=>D,UrunErrorBoundary:()=>l,UrunJwtProvider:()=>Y,UrunProvider:()=>re,authMode:()=>_,registerComponent:()=>se,urunPublicEnv:()=>i,useApp:()=>ne,useImageFrame:()=>$,useMetricsPanel:()=>H,useProgressCard:()=>F,useStatusBadge:()=>j,useTextStream:()=>z,useUrunAuth:()=>w,usesWorkOSAuth:()=>G});module.exports=Ae(Ne);var v=require("react");var Z=require("react"),y=require("react/jsx-runtime"),l=class extends Z.Component{constructor(e){super(e),this.state={error:null}}static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){console.error("[urun] Error caught by UrunErrorBoundary:",e,t)}render(){if(this.state.error){let{fallback:e}=this.props;return typeof e=="function"?e(this.state.error):e||(0,y.jsxs)("div",{role:"status","aria-live":"polite",style:{padding:"16px",border:"1px solid rgba(17, 24, 39, 0.12)",borderRadius:"8px",background:"#ffffff",color:"#111827",fontFamily:'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',maxWidth:"360px"},children:[(0,y.jsx)("p",{style:{margin:0,fontWeight:600},children:"Connection interrupted"}),(0,y.jsx)("p",{style:{margin:"6px 0 0",color:"#4b5563"},children:"Reconnecting automatically."})]})}return this.props.children}};var q=require("react"),A=(0,q.createContext)(null);function p(r){return r&&r.trim()?r.trim():void 0}function i(r){switch(r){case"NEXT_PUBLIC_AUTH_MODE":return p(typeof process<"u"?process.env?.NEXT_PUBLIC_AUTH_MODE:void 0);case"NEXT_PUBLIC_AUTH_ENABLED":return p(typeof process<"u"?process.env?.NEXT_PUBLIC_AUTH_ENABLED:void 0);case"NEXT_PUBLIC_SESSION_AUTH_PROVIDER":return p(typeof process<"u"?process.env?.NEXT_PUBLIC_SESSION_AUTH_PROVIDER:void 0);case"NEXT_PUBLIC_SESSION_TOKEN":return p(typeof process<"u"?process.env?.NEXT_PUBLIC_SESSION_TOKEN:void 0);case"NEXT_PUBLIC_URUN_JWT":return p(typeof process<"u"?process.env?.NEXT_PUBLIC_URUN_JWT:void 0);case"VERCEL_ENV":return p(typeof process<"u"?process.env?.VERCEL_ENV:void 0);default:return p(typeof process<"u"?process.env?.[r]:void 0)}}function _(){let r=i("NEXT_PUBLIC_AUTH_MODE")?.toLowerCase();return r==="jwt"||r==="customer-jwt"||r==="test-jwt"?"jwt":r==="workos"||i("VERCEL_ENV")==="production"?"workos":i("NEXT_PUBLIC_AUTH_ENABLED")==="false"?"jwt":"workos"}function G(){return _()==="workos"}var g=require("react"),ee=require("react/jsx-runtime"),Q=(0,g.createContext)(null);function D({getAccessToken:r,children:e}){let t=(0,g.useMemo)(()=>({getAccessToken:r}),[r]);return(0,ee.jsx)(Q.Provider,{value:t,children:e})}var Y=D;function w(){return(0,g.useContext)(Q)}var b=require("react/jsx-runtime");function re({baseUrl:r,orgId:e,appId:t,jwt:n,authProvider:o,fallback:s,children:f}){let[k,S]=(0,v.useState)(),u=w(),Pe=i("NEXT_PUBLIC_SESSION_TOKEN")??i("NEXT_PUBLIC_URUN_JWT"),J=_(),x=J==="workos"&&!n,M=n??(J==="jwt"?Pe:void 0)??k,W=o??i("NEXT_PUBLIC_SESSION_AUTH_PROVIDER"),Se=x&&!M,xe=(0,v.useMemo)(()=>({appId:t,baseUrl:r,orgId:e,jwt:M,getAccessToken:x?u?.getAccessToken:void 0,authProvider:W}),[t,u,r,W,M,e,x]);return(0,v.useEffect)(()=>{if(!x||!u)return;let B=!1,ye=u;async function K(){try{let Ce=await ye.getAccessToken();B||S(Ce??void 0)}catch{B||S(void 0)}}K();let _e=window.setInterval(()=>{K()},6e4);return()=>{B=!0,window.clearInterval(_e)}},[u,x]),(0,b.jsx)(l,{fallback:s,children:Se?(0,b.jsx)("div",{role:"status","aria-live":"polite",children:"Signing in..."}):(0,b.jsx)(A.Provider,{value:xe,children:f})})}var a=require("react"),te=require("@urun-sh/core");function we(r,e){return`${r}:${JSON.stringify(e??{})}`}var O=class{constructor(e,t){this._doc=e;this._notify=t;this._unsubscribeChange=this._doc.on("change",()=>this._notify())}_doc;_notify;_unsubscribeChange;get(e,t){return this._doc.get(e,t)}set(e){this._doc.set(e),this._notify()}on(e,t){return this._doc.on(e,n=>t(n))}dispose(){this._unsubscribeChange()}},V=class{constructor(e,t){this._stream=e;this._notify=t;this._unsubscribeTrack=this._stream.on("track",()=>this._notify())}_stream;_notify;_unsubscribeTrack;get track(){return this._stream.track}attach(e){return this._stream.attach(e)}detach(){return this._stream.detach()}seek(e){return this._stream.seek(e)}on(e,t){return this._stream.on(e,t)}dispose(){this._unsubscribeTrack()}},X=class{constructor(e,t){this._session=e;this._notify=t}_session;_notify;_docs=new Map;_streams=new Map;get id(){return this._session.id}doc(e){let t=this._docs.get(e);return t||(t=new O(this._session.doc(e),this._notify),this._docs.set(e,t)),t}stream(e){let t=this._streams.get(e);return t||(t=new V(this._session.stream(e),this._notify),this._streams.set(e,t)),t}disconnect(){for(let e of this._docs.values())e.dispose();for(let e of this._streams.values())e.dispose();this._docs.clear(),this._streams.clear(),this._session.disconnect(),this._notify()}};function ne(){let r=(0,a.useContext)(A);if(!r)throw new Error("useApp must be used within <UrunProvider>");if(!r.appId)throw new Error('useApp requires <UrunProvider appId="...">');let[,e]=(0,a.useReducer)(o=>o+1,0),t=(0,a.useRef)(new Map),n=(0,a.useMemo)(()=>(0,te.App)(r.appId,{baseUrl:r.baseUrl,orgId:r.orgId,jwt:r.jwt,getAccessToken:r.getAccessToken,authProvider:r.authProvider}),[r.appId,r.baseUrl,r.orgId,r.jwt,r.getAccessToken,r.authProvider]);return(0,a.useMemo)(()=>new Proxy({},{get(o,s){if(typeof s=="string")return f=>{let k=we(s,f),S=t.current.get(k);if(S)return S;let u=new X(n[s](f),e);return t.current.set(k,u),u}}}),[n])}var oe=new Map;function se(r,e,t){if(!t||typeof t.safeParse!="function")throw new Error(`registerComponent("${r}"): schema must be a valid Zod schema`);oe.set(r,{component:e,schema:t})}function ie(r,e){let t=oe.get(r);if(!t)return{error:`Unknown component: "${r}"`};let n=t.schema.safeParse(e);return n.success?{Component:t.component,validatedProps:n.data}:{error:`Validation failed for "${r}": ${n.error.message}`}}var d=require("react/jsx-runtime");function ae({name:r,props:e,fallback:t}){let n=ie(r,e);if(n.error)return console.warn(`[urun] ComponentRenderer: ${n.error}`),t?(0,d.jsx)(d.Fragment,{children:t}):(0,d.jsx)("div",{className:"urun-component-error",role:"alert",children:(0,d.jsx)("span",{className:"urun-component-error-text",children:n.error})});let o=n.Component;return(0,d.jsx)(o,{...n.validatedProps})}var h=require("zod"),m=require("react/jsx-runtime"),ce=h.z.object({step:h.z.number().min(0),total:h.z.number().min(1),label:h.z.string().optional(),variant:h.z.enum(["default","success","error"]).default("default")});function F(r){let{step:e,total:t,label:n,variant:o="default"}=r,s=Math.min(e/t*100,100),f=e>=t;return{step:e,total:t,label:n,variant:o,percentage:s,isComplete:f}}function ue(r){let{step:e,total:t,label:n,variant:o,percentage:s}=F(r);return(0,m.jsxs)("div",{className:"urun-progress-card","data-variant":o,children:[n&&(0,m.jsx)("div",{className:"urun-progress-label",children:n}),(0,m.jsx)("div",{className:"urun-progress-bar",children:(0,m.jsx)("div",{className:"urun-progress-fill",style:{width:`${s}%`}})}),(0,m.jsxs)("div",{className:"urun-progress-text",children:[e,"/",t]})]})}var N=require("zod"),C=require("react/jsx-runtime"),pe=N.z.object({state:N.z.enum(["thinking","generating","idle","error"]),message:N.z.string().optional()}),be={thinking:"Thinking...",generating:"Generating...",idle:"Idle",error:"Error"};function j(r){let{state:e,message:t}=r,n=e==="thinking"||e==="generating",o=t??be[e]??e;return{state:e,message:o,isActive:n}}function de(r){let{state:e,message:t,isActive:n}=j(r);return(0,C.jsxs)("span",{className:"urun-status-badge","data-state":e,children:[(0,C.jsx)("span",{className:`urun-status-indicator${n?" urun-status-pulse":""}`}),(0,C.jsx)("span",{className:"urun-status-message",children:t})]})}var T=require("react"),I=require("zod"),U=require("react/jsx-runtime"),me=I.z.object({text:I.z.string(),streaming:I.z.boolean().default(!1)});function z(r){let{text:e,streaming:t=!1}=r,n=e.length===0;return{text:e,streaming:t,isEmpty:n}}function fe(r){let{text:e,streaming:t}=z(r),n=(0,T.useRef)(null),o=(0,T.useRef)(0);return(0,T.useEffect)(()=>{let s=n.current;s&&e.length!==o.current&&(s.textContent=e,o.current=e.length)},[e]),(0,U.jsxs)("div",{className:"urun-text-stream",children:[(0,U.jsx)("span",{ref:n,className:"urun-text-content"}),t&&(0,U.jsx)("span",{className:"urun-text-cursor"})]})}var R=require("zod"),E=require("react/jsx-runtime"),le=R.z.object({src:R.z.string().url(),alt:R.z.string().optional(),caption:R.z.string().optional()});function $(r){let{src:e,alt:t,caption:n}=r;return{src:e,alt:t??"",caption:n}}function ge(r){let{src:e,alt:t,caption:n}=$(r);return(0,E.jsxs)("figure",{className:"urun-image-frame",children:[(0,E.jsx)("img",{className:"urun-image",src:e,alt:t}),n&&(0,E.jsx)("figcaption",{className:"urun-image-caption",children:n})]})}var c=require("zod"),P=require("react/jsx-runtime"),ve=c.z.object({metrics:c.z.array(c.z.object({label:c.z.string(),value:c.z.union([c.z.string(),c.z.number()]),unit:c.z.string().optional()}))});function H(r){return{metrics:r.metrics.map(t=>({...t,displayValue:t.unit?`${t.value} ${t.unit}`:String(t.value)}))}}function he(r){let{metrics:e}=H(r);return(0,P.jsx)("div",{className:"urun-metrics-panel",children:e.map((t,n)=>(0,P.jsxs)("div",{className:"urun-metric-card",children:[(0,P.jsx)("div",{className:"urun-metric-label",children:t.label}),(0,P.jsx)("div",{className:"urun-metric-value",children:t.displayValue})]},n))})}0&&(module.exports={ComponentRenderer,ImageFrame,ImageFrameSchema,MetricsPanel,MetricsPanelSchema,ProgressCard,ProgressCardSchema,StatusBadge,StatusBadgeSchema,TextStream,TextStreamSchema,UrunAuthProvider,UrunErrorBoundary,UrunJwtProvider,UrunProvider,authMode,registerComponent,urunPublicEnv,useApp,useImageFrame,useMetricsPanel,useProgressCard,useStatusBadge,useTextStream,useUrunAuth,usesWorkOSAuth});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as ee,b as re,c as x}from"./chunk-OAFPMVUO.mjs";import{useEffect as ie,useMemo as ae,useState as ce}from"react";import{Component as te}from"react";import{jsx as B,jsxs as ne}from"react/jsx-runtime";var
|
|
1
|
+
import{a as ee,b as re,c as x}from"./chunk-OAFPMVUO.mjs";import{useEffect as ie,useMemo as ae,useState as ce}from"react";import{Component as te}from"react";import{jsx as B,jsxs as ne}from"react/jsx-runtime";var f=class extends te{constructor(e){super(e),this.state={error:null}}static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){console.error("[urun] Error caught by UrunErrorBoundary:",e,t)}render(){if(this.state.error){let{fallback:e}=this.props;return typeof e=="function"?e(this.state.error):e||ne("div",{role:"status","aria-live":"polite",style:{padding:"16px",border:"1px solid rgba(17, 24, 39, 0.12)",borderRadius:"8px",background:"#ffffff",color:"#111827",fontFamily:'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',maxWidth:"360px"},children:[B("p",{style:{margin:0,fontWeight:600},children:"Connection interrupted"}),B("p",{style:{margin:"6px 0 0",color:"#4b5563"},children:"Reconnecting automatically."})]})}return this.props.children}};import{createContext as oe}from"react";var v=oe(null);function u(r){return r&&r.trim()?r.trim():void 0}function a(r){switch(r){case"NEXT_PUBLIC_AUTH_MODE":return u(typeof process<"u"?process.env?.NEXT_PUBLIC_AUTH_MODE:void 0);case"NEXT_PUBLIC_AUTH_ENABLED":return u(typeof process<"u"?process.env?.NEXT_PUBLIC_AUTH_ENABLED:void 0);case"NEXT_PUBLIC_SESSION_AUTH_PROVIDER":return u(typeof process<"u"?process.env?.NEXT_PUBLIC_SESSION_AUTH_PROVIDER:void 0);case"NEXT_PUBLIC_SESSION_TOKEN":return u(typeof process<"u"?process.env?.NEXT_PUBLIC_SESSION_TOKEN:void 0);case"NEXT_PUBLIC_URUN_JWT":return u(typeof process<"u"?process.env?.NEXT_PUBLIC_URUN_JWT:void 0);case"VERCEL_ENV":return u(typeof process<"u"?process.env?.VERCEL_ENV:void 0);default:return u(typeof process<"u"?process.env?.[r]:void 0)}}function h(){let r=a("NEXT_PUBLIC_AUTH_MODE")?.toLowerCase();return r==="jwt"||r==="customer-jwt"||r==="test-jwt"?"jwt":r==="workos"||a("VERCEL_ENV")==="production"?"workos":a("NEXT_PUBLIC_AUTH_ENABLED")==="false"?"jwt":"workos"}function se(){return h()==="workos"}import{jsx as C}from"react/jsx-runtime";function ue({baseUrl:r,orgId:e,appId:t,jwt:n,authProvider:o,fallback:s,children:p}){let[l,d]=ce(),i=x(),K=a("NEXT_PUBLIC_SESSION_TOKEN")??a("NEXT_PUBLIC_URUN_JWT"),A=h(),m=A==="workos"&&!n,y=n??(A==="jwt"?K:void 0)??l,N=o??a("NEXT_PUBLIC_SESSION_AUTH_PROVIDER"),Z=m&&!y,q=ae(()=>({appId:t,baseUrl:r,orgId:e,jwt:y,getAccessToken:m?i?.getAccessToken:void 0,authProvider:N}),[t,i,r,N,y,e,m]);return ie(()=>{if(!m||!i)return;let _=!1,G=i;async function I(){try{let Y=await G.getAccessToken();_||d(Y??void 0)}catch{_||d(void 0)}}I();let Q=window.setInterval(()=>{I()},6e4);return()=>{_=!0,window.clearInterval(Q)}},[i,m]),C(f,{fallback:s,children:Z?C("div",{role:"status","aria-live":"polite",children:"Signing in..."}):C(v.Provider,{value:q,children:p})})}import{useContext as pe,useMemo as M,useReducer as de,useRef as me}from"react";import{App as fe}from"@urun-sh/core";function ge(r,e){return`${r}:${JSON.stringify(e??{})}`}var T=class{constructor(e,t){this._doc=e;this._notify=t;this._unsubscribeChange=this._doc.on("change",()=>this._notify())}_doc;_notify;_unsubscribeChange;get(e,t){return this._doc.get(e,t)}set(e){this._doc.set(e),this._notify()}on(e,t){return this._doc.on(e,n=>t(n))}dispose(){this._unsubscribeChange()}},E=class{constructor(e,t){this._stream=e;this._notify=t;this._unsubscribeTrack=this._stream.on("track",()=>this._notify())}_stream;_notify;_unsubscribeTrack;get track(){return this._stream.track}attach(e){return this._stream.attach(e)}detach(){return this._stream.detach()}seek(e){return this._stream.seek(e)}on(e,t){return this._stream.on(e,t)}dispose(){this._unsubscribeTrack()}},R=class{constructor(e,t){this._session=e;this._notify=t}_session;_notify;_docs=new Map;_streams=new Map;get id(){return this._session.id}doc(e){let t=this._docs.get(e);return t||(t=new T(this._session.doc(e),this._notify),this._docs.set(e,t)),t}stream(e){let t=this._streams.get(e);return t||(t=new E(this._session.stream(e),this._notify),this._streams.set(e,t)),t}disconnect(){for(let e of this._docs.values())e.dispose();for(let e of this._streams.values())e.dispose();this._docs.clear(),this._streams.clear(),this._session.disconnect(),this._notify()}};function le(){let r=pe(v);if(!r)throw new Error("useApp must be used within <UrunProvider>");if(!r.appId)throw new Error('useApp requires <UrunProvider appId="...">');let[,e]=de(o=>o+1,0),t=me(new Map),n=M(()=>fe(r.appId,{baseUrl:r.baseUrl,orgId:r.orgId,jwt:r.jwt,getAccessToken:r.getAccessToken,authProvider:r.authProvider}),[r.appId,r.baseUrl,r.orgId,r.jwt,r.getAccessToken,r.authProvider]);return M(()=>new Proxy({},{get(o,s){if(typeof s=="string")return p=>{let l=ge(s,p),d=t.current.get(l);if(d)return d;let i=new R(n[s](p),e);return t.current.set(l,i),i}}}),[n])}var L=new Map;function ve(r,e,t){if(!t||typeof t.safeParse!="function")throw new Error(`registerComponent("${r}"): schema must be a valid Zod schema`);L.set(r,{component:e,schema:t})}function D(r,e){let t=L.get(r);if(!t)return{error:`Unknown component: "${r}"`};let n=t.schema.safeParse(e);return n.success?{Component:t.component,validatedProps:n.data}:{error:`Validation failed for "${r}": ${n.error.message}`}}import{Fragment as Se,jsx as S}from"react/jsx-runtime";function he({name:r,props:e,fallback:t}){let n=D(r,e);if(n.error)return console.warn(`[urun] ComponentRenderer: ${n.error}`),t?S(Se,{children:t}):S("div",{className:"urun-component-error",role:"alert",children:S("span",{className:"urun-component-error-text",children:n.error})});let o=n.Component;return S(o,{...n.validatedProps})}import{z as g}from"zod";import{jsx as U,jsxs as O}from"react/jsx-runtime";var Pe=g.object({step:g.number().min(0),total:g.number().min(1),label:g.string().optional(),variant:g.enum(["default","success","error"]).default("default")});function V(r){let{step:e,total:t,label:n,variant:o="default"}=r,s=Math.min(e/t*100,100),p=e>=t;return{step:e,total:t,label:n,variant:o,percentage:s,isComplete:p}}function ye(r){let{step:e,total:t,label:n,variant:o,percentage:s}=V(r);return O("div",{className:"urun-progress-card","data-variant":o,children:[n&&U("div",{className:"urun-progress-label",children:n}),U("div",{className:"urun-progress-bar",children:U("div",{className:"urun-progress-fill",style:{width:`${s}%`}})}),O("div",{className:"urun-progress-text",children:[e,"/",t]})]})}import{z as k}from"zod";import{jsx as X,jsxs as Te}from"react/jsx-runtime";var _e=k.object({state:k.enum(["thinking","generating","idle","error"]),message:k.string().optional()}),xe={thinking:"Thinking...",generating:"Generating...",idle:"Idle",error:"Error"};function F(r){let{state:e,message:t}=r,n=e==="thinking"||e==="generating",o=t??xe[e]??e;return{state:e,message:o,isActive:n}}function Ce(r){let{state:e,message:t,isActive:n}=F(r);return Te("span",{className:"urun-status-badge","data-state":e,children:[X("span",{className:`urun-status-indicator${n?" urun-status-pulse":""}`}),X("span",{className:"urun-status-message",children:t})]})}import{useRef as j,useEffect as Ee}from"react";import{z as b}from"zod";import{jsx as z,jsxs as ke}from"react/jsx-runtime";var Re=b.object({text:b.string(),streaming:b.boolean().default(!1)});function $(r){let{text:e,streaming:t=!1}=r,n=e.length===0;return{text:e,streaming:t,isEmpty:n}}function Ue(r){let{text:e,streaming:t}=$(r),n=j(null),o=j(0);return Ee(()=>{let s=n.current;s&&e.length!==o.current&&(s.textContent=e,o.current=e.length)},[e]),ke("div",{className:"urun-text-stream",children:[z("span",{ref:n,className:"urun-text-content"}),t&&z("span",{className:"urun-text-cursor"})]})}import{z as P}from"zod";import{jsx as H,jsxs as Ae}from"react/jsx-runtime";var be=P.object({src:P.string().url(),alt:P.string().optional(),caption:P.string().optional()});function J(r){let{src:e,alt:t,caption:n}=r;return{src:e,alt:t??"",caption:n}}function we(r){let{src:e,alt:t,caption:n}=J(r);return Ae("figure",{className:"urun-image-frame",children:[H("img",{className:"urun-image",src:e,alt:t}),n&&H("figcaption",{className:"urun-image-caption",children:n})]})}import{z as c}from"zod";import{jsx as w,jsxs as Be}from"react/jsx-runtime";var Ne=c.object({metrics:c.array(c.object({label:c.string(),value:c.union([c.string(),c.number()]),unit:c.string().optional()}))});function W(r){return{metrics:r.metrics.map(t=>({...t,displayValue:t.unit?`${t.value} ${t.unit}`:String(t.value)}))}}function Ie(r){let{metrics:e}=W(r);return w("div",{className:"urun-metrics-panel",children:e.map((t,n)=>Be("div",{className:"urun-metric-card",children:[w("div",{className:"urun-metric-label",children:t.label}),w("div",{className:"urun-metric-value",children:t.displayValue})]},n))})}export{he as ComponentRenderer,we as ImageFrame,be as ImageFrameSchema,Ie as MetricsPanel,Ne as MetricsPanelSchema,ye as ProgressCard,Pe as ProgressCardSchema,Ce as StatusBadge,_e as StatusBadgeSchema,Ue as TextStream,Re as TextStreamSchema,ee as UrunAuthProvider,f as UrunErrorBoundary,re as UrunJwtProvider,ue as UrunProvider,h as authMode,ve as registerComponent,a as urunPublicEnv,le as useApp,J as useImageFrame,W as useMetricsPanel,V as useProgressCard,F as useStatusBadge,$ as useTextStream,x as useUrunAuth,se as usesWorkOSAuth};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ComponentProps } from 'react';
|
|
3
|
+
import { AuthKitProvider } from '@workos-inc/authkit-nextjs/components';
|
|
4
|
+
|
|
5
|
+
type WorkOSAuthKitProviderProps = ComponentProps<typeof AuthKitProvider>;
|
|
6
|
+
declare function UrunWorkOSProvider({ children, ...props }: WorkOSAuthKitProviderProps): react_jsx_runtime.JSX.Element;
|
|
7
|
+
|
|
8
|
+
export { UrunWorkOSProvider };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ComponentProps } from 'react';
|
|
3
|
+
import { AuthKitProvider } from '@workos-inc/authkit-nextjs/components';
|
|
4
|
+
|
|
5
|
+
type WorkOSAuthKitProviderProps = ComponentProps<typeof AuthKitProvider>;
|
|
6
|
+
declare function UrunWorkOSProvider({ children, ...props }: WorkOSAuthKitProviderProps): react_jsx_runtime.JSX.Element;
|
|
7
|
+
|
|
8
|
+
export { UrunWorkOSProvider };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var s=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var k=(r,e)=>{for(var o in e)s(r,o,{get:e[o],enumerable:!0})},U=(r,e,o,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of v(e))!h.call(r,t)&&t!==o&&s(r,t,{get:()=>e[t],enumerable:!(i=P(e,t))||i.enumerable});return r};var l=r=>U(s({},"__esModule",{value:!0}),r);var f={};k(f,{UrunWorkOSProvider:()=>T});module.exports=l(f);var p=require("react"),c=require("@workos-inc/authkit-nextjs/components");var n=require("react"),d=require("react/jsx-runtime"),a=(0,n.createContext)(null);function A({getAccessToken:r,children:e}){let o=(0,n.useMemo)(()=>({getAccessToken:r}),[r]);return(0,d.jsx)(a.Provider,{value:o,children:e})}var u=require("react/jsx-runtime");function x({children:r}){let e=(0,c.useAccessToken)(),o=(0,p.useCallback)(()=>e.getAccessToken(),[e]);return(0,u.jsx)(A,{getAccessToken:o,children:r})}function T({children:r,...e}){return(0,u.jsx)(c.AuthKitProvider,{...e,children:(0,u.jsx)(x,{children:r})})}0&&(module.exports={UrunWorkOSProvider});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as t}from"./chunk-OAFPMVUO.mjs";import{useCallback as i}from"react";import{AuthKitProvider as c,useAccessToken as s}from"@workos-inc/authkit-nextjs/components";import{jsx as e}from"react/jsx-runtime";function u({children:r}){let o=s(),n=i(()=>o.getAccessToken(),[o]);return e(t,{getAccessToken:n,children:r})}function A({children:r,...o}){return e(c,{...o,children:e(u,{children:r})})}export{A as UrunWorkOSProvider};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@urun-sh/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20",
|
|
4
4
|
"description": "React bindings for the urun TypeScript SDK",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -30,6 +30,11 @@
|
|
|
30
30
|
"import": "./dist/workos.mjs",
|
|
31
31
|
"require": "./dist/workos.js"
|
|
32
32
|
},
|
|
33
|
+
"./next-workos": {
|
|
34
|
+
"types": "./dist/next-workos.d.ts",
|
|
35
|
+
"import": "./dist/next-workos.mjs",
|
|
36
|
+
"require": "./dist/next-workos.js"
|
|
37
|
+
},
|
|
33
38
|
"./styles.css": "./dist/styles.css",
|
|
34
39
|
"./package.json": "./package.json"
|
|
35
40
|
},
|
|
@@ -41,8 +46,10 @@
|
|
|
41
46
|
},
|
|
42
47
|
"peerDependencies": {
|
|
43
48
|
"react": "^18.2.0 || ^19.0.0",
|
|
44
|
-
"@urun-sh/core": "^0.1.
|
|
45
|
-
"@workos-inc/authkit-react": "^0.15.0 || ^0.16.0"
|
|
49
|
+
"@urun-sh/core": "^0.1.20",
|
|
50
|
+
"@workos-inc/authkit-react": "^0.15.0 || ^0.16.0",
|
|
51
|
+
"@workos-inc/authkit-nextjs": "^3.0.0",
|
|
52
|
+
"next": "^15.0.0 || ^16.0.0"
|
|
46
53
|
},
|
|
47
54
|
"dependencies": {
|
|
48
55
|
"zustand": "^5.0.0",
|
|
@@ -60,7 +67,9 @@
|
|
|
60
67
|
"react": "^19.2.6",
|
|
61
68
|
"react-dom": "^19.2.6",
|
|
62
69
|
"@urun-sh/core": "workspace:*",
|
|
63
|
-
"@workos-inc/authkit-react": "^0.16.1"
|
|
70
|
+
"@workos-inc/authkit-react": "^0.16.1",
|
|
71
|
+
"@workos-inc/authkit-nextjs": "^3.0.0",
|
|
72
|
+
"next": "16.2.6"
|
|
64
73
|
},
|
|
65
74
|
"files": [
|
|
66
75
|
"dist",
|
|
@@ -88,6 +97,12 @@
|
|
|
88
97
|
"peerDependenciesMeta": {
|
|
89
98
|
"@workos-inc/authkit-react": {
|
|
90
99
|
"optional": true
|
|
100
|
+
},
|
|
101
|
+
"@workos-inc/authkit-nextjs": {
|
|
102
|
+
"optional": true
|
|
103
|
+
},
|
|
104
|
+
"next": {
|
|
105
|
+
"optional": true
|
|
91
106
|
}
|
|
92
107
|
}
|
|
93
108
|
}
|