@clerk/backend
Advanced tools
Comparing version 0.5.1-staging.0 to 0.5.1-staging.1
@@ -1,2 +0,2 @@ | ||
var c=class{constructor(e){this.request=e}requireId(e){if(!e)throw new Error("A valid resource ID is required.")}};var Je="/",Rt=new RegExp(Je+"{1,}","g");function o(...t){return t.filter(e=>e).join(Je).replace(Rt,Je)}var Re="/allowlist_identifiers",ae=class extends c{async getAllowlistIdentifierList(){return this.request({method:"GET",path:Re})}async createAllowlistIdentifier(e){return this.request({method:"POST",path:Re,bodyParams:e})}async deleteAllowlistIdentifier(e){return this.requireId(e),this.request({method:"DELETE",path:o(Re,e)})}};var Ne="/clients",le=class extends c{async getClientList(){return this.request({method:"GET",path:Ne})}async getClient(e){return this.requireId(e),this.request({method:"GET",path:o(Ne,e)})}verifyClient(e){return this.request({method:"POST",path:o(Ne,"verify"),bodyParams:{token:e}})}};var ue="/email_addresses",de=class extends c{async getEmailAddress(e){return this.requireId(e),this.request({method:"GET",path:o(ue,e)})}async createEmailAddress(e){return this.request({method:"POST",path:ue,bodyParams:e})}async updateEmailAddress(e,r={}){return this.requireId(e),this.request({method:"PATCH",path:o(ue,e),bodyParams:r})}async deleteEmailAddress(e){return this.requireId(e),this.request({method:"DELETE",path:o(ue,e)})}};var Nt="/emails",ce=class extends c{async createEmail(e){return this.request({method:"POST",path:Nt,bodyParams:e})}};var pe=class extends c{async getInterstitial(){return this.request({path:"internal/interstitial",method:"GET",headerParams:{"Content-Type":"text/html"}})}};var Ce="/invitations",me=class extends c{async getInvitationList(){return this.request({method:"GET",path:Ce})}async createInvitation(e){return this.request({method:"POST",path:Ce,bodyParams:e})}async revokeInvitation(e){return this.requireId(e),this.request({method:"POST",path:o(Ce,e,"revoke")})}};var A="/organizations",ge=class extends c{async getOrganizationList(e){return this.request({method:"GET",path:A,queryParams:e})}async createOrganization(e){return this.request({method:"POST",path:A,bodyParams:e})}async getOrganization(e){let r="organizationId"in e?e.organizationId:e.slug;return this.requireId(r),this.request({method:"GET",path:o(A,r)})}async updateOrganization(e,r){return this.requireId(e),this.request({method:"PATCH",path:o(A,e),bodyParams:r})}async updateOrganizationMetadata(e,r){return this.requireId(e),this.request({method:"PATCH",path:o(A,e,"metadata"),bodyParams:r})}async deleteOrganization(e){return this.request({method:"DELETE",path:o(A,e)})}async getOrganizationMembershipList(e){let{organizationId:r,limit:i,offset:n}=e;return this.requireId(r),this.request({method:"GET",path:o(A,r,"memberships"),queryParams:{limit:i,offset:n}})}async createOrganizationMembership(e){let{organizationId:r,userId:i,role:n}=e;return this.requireId(r),this.request({method:"POST",path:o(A,r,"memberships"),bodyParams:{userId:i,role:n}})}async updateOrganizationMembership(e){let{organizationId:r,userId:i,role:n}=e;return this.requireId(r),this.request({method:"PATCH",path:o(A,r,"memberships",i),bodyParams:{role:n}})}async updateOrganizationMembershipMetadata(e){let{organizationId:r,userId:i,publicMetadata:n,privateMetadata:s}=e;return this.request({method:"PATCH",path:o(A,r,"memberships",i,"metadata"),bodyParams:{publicMetadata:n,privateMetadata:s}})}async deleteOrganizationMembership(e){let{organizationId:r,userId:i}=e;return this.requireId(r),this.request({method:"DELETE",path:o(A,r,"memberships",i)})}async getPendingOrganizationInvitationList(e){let{organizationId:r,limit:i,offset:n}=e;return this.requireId(r),this.request({method:"GET",path:o(A,r,"invitations","pending"),queryParams:{limit:i,offset:n}})}async createOrganizationInvitation(e){let{organizationId:r,...i}=e;return this.requireId(r),this.request({method:"POST",path:o(A,r,"invitations"),bodyParams:{...i}})}async revokeOrganizationInvitation(e){let{organizationId:r,invitationId:i,requestingUserId:n}=e;return this.requireId(r),this.request({method:"POST",path:o(A,r,"invitations",i,"revoke"),bodyParams:{requestingUserId:n}})}};var fe="/phone_numbers",ye=class extends c{async getPhoneNumber(e){return this.requireId(e),this.request({method:"GET",path:o(fe,e)})}async createPhoneNumber(e){return this.request({method:"POST",path:fe,bodyParams:e})}async updatePhoneNumber(e,r={}){return this.requireId(e),this.request({method:"PATCH",path:o(fe,e),bodyParams:r})}async deletePhoneNumber(e){return this.requireId(e),this.request({method:"DELETE",path:o(fe,e)})}};var he="/redirect_urls",be=class extends c{async getRedirectUrlList(){return this.request({method:"GET",path:he})}async getRedirectUrl(e){return this.requireId(e),this.request({method:"GET",path:o(he,e)})}async createRedirectUrl(e){return this.request({method:"POST",path:he,bodyParams:e})}async deleteRedirectUrl(e){return this.requireId(e),this.request({method:"DELETE",path:o(he,e)})}};var re="/sessions",Se=class extends c{constructor(){super(...arguments);this.getSessionList=async r=>this.request({method:"GET",path:re,queryParams:r});this.getSession=async r=>(this.requireId(r),this.request({method:"GET",path:o(re,r)}));this.revokeSession=async r=>(this.requireId(r),this.request({method:"POST",path:o(re,r,"revoke")}));this.verifySession=async(r,i)=>(this.requireId(r),this.request({method:"POST",path:o(re,r,"verify"),bodyParams:{token:i}}));this.getToken=async(r,i)=>(this.requireId(r),(await this.request({method:"POST",path:o(re,r,"tokens",i||"")})).jwt)}};var Ge="/sign_in_tokens",Oe=class extends c{async createSignInToken(e){return this.request({method:"POST",path:Ge,bodyParams:e})}async revokeSignInToken(e){return this.requireId(e),this.request({method:"POST",path:o(Ge,e,"revoke")})}};var Ct="/sms_messages",ke=class extends c{async createSMSMessage(e){return this.request({method:"POST",path:Ct,bodyParams:e})}};var J="/users",_e=class extends c{async getUserList(e={}){return this.request({method:"GET",path:J,queryParams:e})}async getUser(e){return this.requireId(e),this.request({method:"GET",path:o(J,e)})}async createUser(e){return this.request({method:"POST",path:J,bodyParams:e})}async updateUser(e,r={}){return this.requireId(e),this.request({method:"PATCH",path:o(J,e),bodyParams:r})}async updateUserMetadata(e,r){return this.requireId(e),this.request({method:"PATCH",path:o(J,e,"metadata"),bodyParams:r})}async deleteUser(e){return this.requireId(e),this.request({method:"DELETE",path:o(J,e)})}async getCount(e={}){return this.request({method:"GET",path:o(J,"count"),queryParams:e})}async getUserOauthAccessToken(e,r){return this.requireId(e),this.request({method:"GET",path:o(J,e,"oauth_access_tokens",r)})}async disableUserMFA(e){return this.requireId(e),this.request({method:"DELETE",path:o(J,e,"mfa")})}async getOrganizationMembershipList(e){let{userId:r,limit:i,offset:n}=e;return this.requireId(r),this.request({method:"GET",path:o(J,r,"organization_memberships"),queryParams:{limit:i,offset:n}})}};import Ft from"deepmerge";import Qe from"snakecase-keys";var v="https://api.clerk.dev",R="v1",$e="@clerk/backend";var vt={AuthStatus:"__clerkAuthStatus"},Et={Session:"__session",ClientUat:"__client_uat"},He={AuthStatus:"x-clerk-auth-status",AuthReason:"x-clerk-auth-reason",AuthMessage:"x-clerk-auth-message",Authorization:"authorization",ForwardedPort:"x-forwarded-port",ForwardedHost:"x-forwarded-host",Referrer:"referer",UserAgent:"user-agent",Origin:"origin",Host:"host"},Ut={AuthStatus:He.AuthStatus},qt={Attributes:vt,Cookies:Et,Headers:He,SearchParams:Ut};import zt from"#crypto";import Kt from"#fetch";var Mt=Kt.bind(globalThis),jt={crypto:zt,fetch:Mt},N=jt;var j=class{constructor(e,r,i,n,s){this.id=e;this.identifier=r;this.createdAt=i;this.updatedAt=n;this.invitationId=s}static fromJSON(e){return new j(e.id,e.identifier,e.created_at,e.updated_at,e.invitation_id)}};var E=class{constructor(e,r,i,n,s,a,d,p,f){this.id=e;this.clientId=r;this.userId=i;this.status=n;this.lastActiveAt=s;this.expireAt=a;this.abandonAt=d;this.createdAt=p;this.updatedAt=f}static fromJSON(e){return new E(e.id,e.client_id,e.user_id,e.status,e.last_active_at,e.expire_at,e.abandon_at,e.created_at,e.updated_at)}};var W=class{constructor(e,r,i,n,s,a,d,p){this.id=e;this.sessionIds=r;this.sessions=i;this.signInId=n;this.signUpId=s;this.lastActiveSessionId=a;this.createdAt=d;this.updatedAt=p}static fromJSON(e){return new W(e.id,e.session_ids,e.sessions.map(r=>E.fromJSON(r)),e.sign_in_id,e.sign_up_id,e.last_active_session_id,e.created_at,e.updated_at)}};var L=class{constructor(e,r,i,n){this.object=e;this.id=r;this.slug=i;this.deleted=n}static fromJSON(e){return new L(e.object,e.id||null,e.slug||null,e.deleted)}};var F=class{constructor(e,r,i,n,s,a,d){this.id=e;this.fromEmailName=r;this.emailAddressId=i;this.toEmailAddress=n;this.subject=s;this.body=a;this.status=d}static fromJSON(e){return new F(e.id,e.from_email_name,e.email_address_id,e.to_email_address,e.subject,e.body,e.status)}};var U=class{constructor(e,r){this.id=e;this.type=r}static fromJSON(e){return new U(e.id,e.type)}};var x=class{constructor(e,r,i=null,n=null,s=null,a=null){this.status=e;this.strategy=r;this.externalVerificationRedirectURL=i;this.attempts=n;this.expireAt=s;this.nonce=a}static fromJSON(e){return new x(e.status,e.strategy,e.external_verification_redirect_url?new URL(e.external_verification_redirect_url):null,e.attempts,e.expire_at,e.nonce)}};var q=class{constructor(e,r,i,n){this.id=e;this.emailAddress=r;this.verification=i;this.linkedTo=n}static fromJSON(e){return new q(e.id,e.email_address,e.verification&&x.fromJSON(e.verification),e.linked_to.map(r=>U.fromJSON(r)))}};var D=class{constructor(e,r,i,n,s,a,d,p,f,y,h={},S,m){this.id=e;this.provider=r;this.identificationId=i;this.externalId=n;this.approvedScopes=s;this.emailAddress=a;this.firstName=d;this.lastName=p;this.picture=f;this.username=y;this.publicMetadata=h;this.label=S;this.verification=m}static fromJSON(e){return new D(e.id,e.provider,e.identification_id,e.provider_user_id,e.approved_scopes,e.email_address,e.first_name,e.last_name,e.avatar_url,e.username,e.public_metadata,e.label,e.verification&&x.fromJSON(e.verification))}};var V=class{constructor(e,r,i,n,s,a){this.id=e;this.emailAddress=r;this.publicMetadata=i;this.createdAt=n;this.updatedAt=s;this.revoked=a}static fromJSON(e){return new V(e.id,e.email_address,e.public_metadata,e.created_at,e.updated_at,e.revoked)}};var Ye=(u=>(u.AllowlistIdentifier="allowlist_identifier",u.Client="client",u.Email="email",u.EmailAddress="email_address",u.ExternalAccount="external_account",u.FacebookAccount="facebook_account",u.GoogleAccount="google_account",u.Invitation="invitation",u.OauthAccessToken="oauth_access_token",u.Organization="organization",u.OrganizationInvitation="organization_invitation",u.OrganizationMembership="organization_membership",u.PhoneNumber="phone_number",u.RedirectUrl="redirect_url",u.Session="session",u.SignInAttempt="sign_in_attempt",u.SignInToken="sign_in_token",u.SignUpAttempt="sign_up_attempt",u.SmsMessage="sms_message",u.User="user",u.Web3Wallet="web3_wallet",u.Token="token",u.TotalCount="total_count",u))(Ye||{});var B=class{constructor(e,r,i={},n,s,a){this.provider=e;this.token=r;this.publicMetadata=i;this.label=n;this.scopes=s;this.tokenSecret=a}static fromJSON(e){return new B(e.provider,e.token,e.public_metadata,e.label,e.scopes,e.token_secret)}};var z=class{constructor(e,r,i,n,s,a,d={},p={}){this.id=e;this.name=r;this.slug=i;this.logoUrl=n;this.createdAt=s;this.updatedAt=a;this.publicMetadata=d;this.privateMetadata=p}static fromJSON(e){return new z(e.id,e.name,e.slug,e.logo_url,e.created_at,e.updated_at,e.public_metadata,e.private_metadata)}};var G=class{constructor(e,r,i,n,s,a,d){this.id=e;this.emailAddress=r;this.role=i;this.organizationId=n;this.createdAt=s;this.updatedAt=a;this.status=d}static fromJSON(e){return new G(e.id,e.email_address,e.role,e.organization_id,e.created_at,e.updated_at,e.status)}};var $=class{constructor(e,r,i={},n={},s,a,d,p){this.id=e;this.role=r;this.publicMetadata=i;this.privateMetadata=n;this.createdAt=s;this.updatedAt=a;this.organization=d;this.publicUserData=p}static fromJSON(e){return new $(e.id,e.role,e.public_metadata,e.private_metadata,e.created_at,e.updated_at,z.fromJSON(e.organization),ne.fromJSON(e.public_user_data))}},ne=class{constructor(e,r,i,n,s){this.identifier=e;this.firstName=r;this.lastName=i;this.profileImageUrl=n;this.userId=s}static fromJSON(e){return new ne(e.identifier,e.first_name,e.last_name,e.profile_image_url,e.user_id)}};var K=class{constructor(e,r,i,n,s,a){this.id=e;this.phoneNumber=r;this.reservedForSecondFactor=i;this.defaultSecondFactor=n;this.verification=s;this.linkedTo=a}static fromJSON(e){return new K(e.id,e.phone_number,e.reserved_for_second_factor,e.default_second_factor,e.verification&&x.fromJSON(e.verification),e.linked_to.map(r=>U.fromJSON(r)))}};var H=class{constructor(e,r,i,n){this.id=e;this.url=r;this.createdAt=i;this.updatedAt=n}static fromJSON(e){return new H(e.id,e.url,e.created_at,e.updated_at)}};var Y=class{constructor(e,r,i,n,s,a){this.id=e;this.userId=r;this.token=i;this.status=n;this.createdAt=s;this.updatedAt=a}static fromJSON(e){return new Y(e.id,e.user_id,e.token,e.status,e.created_at,e.updated_at)}};var X=class{constructor(e,r,i,n,s,a){this.id=e;this.fromPhoneNumber=r;this.toPhoneNumber=i;this.message=n;this.status=s;this.phoneNumberId=a}static fromJSON(e){return new X(e.id,e.from_phone_number,e.to_phone_number,e.message,e.status,e.phone_number_id)}};var Q=class{constructor(e){this.jwt=e}static fromJSON(e){return new Q(e.jwt)}};var Z=class{constructor(e,r,i){this.id=e;this.web3Wallet=r;this.verification=i}static fromJSON(e){return new Z(e.id,e.web3_wallet,e.verification&&x.fromJSON(e.verification))}};var ee=class{constructor(e,r,i,n,s,a,d,p,f,y,h,S,m,g,O,k,_,I,w,T={},P={},b={},u=[],Te=[],Be=[],mr=[]){this.id=e;this.passwordEnabled=r;this.totpEnabled=i;this.backupCodeEnabled=n;this.twoFactorEnabled=s;this.banned=a;this.createdAt=d;this.updatedAt=p;this.profileImageUrl=f;this.gender=y;this.birthday=h;this.primaryEmailAddressId=S;this.primaryPhoneNumberId=m;this.primaryWeb3WalletId=g;this.lastSignInAt=O;this.externalId=k;this.username=_;this.firstName=I;this.lastName=w;this.publicMetadata=T;this.privateMetadata=P;this.unsafeMetadata=b;this.emailAddresses=u;this.phoneNumbers=Te;this.web3Wallets=Be;this.externalAccounts=mr}static fromJSON(e){return new ee(e.id,e.password_enabled,e.totp_enabled,e.backup_code_enabled,e.two_factor_enabled,e.banned,e.created_at,e.updated_at,e.profile_image_url,e.gender,e.birthday,e.primary_email_address_id,e.primary_phone_number_id,e.primary_web3_wallet_id,e.last_sign_in_at,e.external_id,e.username,e.first_name,e.last_name,e.public_metadata,e.private_metadata,e.unsafe_metadata,(e.email_addresses||[]).map(r=>q.fromJSON(r)),(e.phone_numbers||[]).map(r=>K.fromJSON(r)),(e.web3_wallets||[]).map(r=>Z.fromJSON(r)),(e.external_accounts||[]).map(r=>D.fromJSON(r)))}};function Xe(t){return Array.isArray(t)?t.map(e=>ve(e)):Wt(t)?t.data.map(e=>ve(e)):ve(t)}function Wt(t){return t.data!==void 0}function Lt(t){return t.total_count}function ve(t){if(typeof t!="string"&&"object"in t&&"deleted"in t)return L.fromJSON(t);switch(t.object){case"allowlist_identifier":return j.fromJSON(t);case"client":return W.fromJSON(t);case"email_address":return q.fromJSON(t);case"email":return F.fromJSON(t);case"invitation":return V.fromJSON(t);case"oauth_access_token":return B.fromJSON(t);case"organization":return z.fromJSON(t);case"organization_invitation":return G.fromJSON(t);case"organization_membership":return $.fromJSON(t);case"phone_number":return K.fromJSON(t);case"redirect_url":return H.fromJSON(t);case"sign_in_token":return Y.fromJSON(t);case"session":return E.fromJSON(t);case"sms_message":return X.fromJSON(t);case"token":return Q.fromJSON(t);case"total_count":return Lt(t);case"user":return ee.fromJSON(t);default:return t}}var Dt=t=>async(...e)=>{let{data:r,errors:i,status:n,statusText:s}=await t(...e);if(i===null)return r;throw new ie(s||"",{data:i,status:n||""})};function Ze(t){return Dt(async r=>{let{apiKey:i,secretKey:n,apiUrl:s=v,apiVersion:a=R,userAgent:d=$e,httpOptions:p={}}=t,{path:f,method:y,queryParams:h,headerParams:S,bodyParams:m}=r,g=n||i;if(!g)throw Error("Missing Clerk Secret Key or API Key. Go to https://dashboard.clerk.dev and get your key for your instance.");let O=o(s,a,f),k=new URL(O);if(h){let P=Qe({...h});for(let[b,u]of Object.entries(P))u&&[u].flat().forEach(Te=>k.searchParams.append(b,Te))}let _={Authorization:`Bearer ${g}`,"Content-Type":"application/json","Clerk-Backend-SDK":d,...S},w=y!=="GET"&&m&&Object.keys(m).length>0?{body:JSON.stringify(Qe(m,{deep:!1}))}:null,T;try{T=await N.fetch(k.href,Ft(p,{method:y,headers:_,...w}));let b=await(_&&_["Content-Type"]==="application/json"?T.json():T.text());if(!T.ok)throw b;return{data:Xe(b),errors:null}}catch(P){return P instanceof Error?{data:null,errors:[{code:"unexpected_error",message:P.message||"Unexpected error"}]}:{data:null,errors:Vt(P),status:T?.status,statusText:T?.statusText}}})}function Vt(t){if(!!t&&typeof t=="object"&&"errors"in t){let e=t.errors;return e.length>0?e.map(Bt):[]}return[]}function Bt(t){return{code:t.code,message:t.message,longMessage:t.long_message,meta:{paramName:t?.meta?.param_name,sessionId:t?.meta?.session_id}}}var ie=class extends Error{constructor(r,{data:i,status:n}){super(r);Object.setPrototypeOf(this,ie.prototype),this.clerkError=!0,this.message=r,this.status=n,this.errors=i}};function te(t){let e=Ze(t);return{allowlistIdentifiers:new ae(e),clients:new le(e),emailAddresses:new de(e),emails:new ce(e),interstitial:new pe(e),invitations:new me(e),organizations:new ge(e),phoneNumbers:new ye(e),redirectUrls:new be(e),sessions:new Se(e),signInTokens:new Oe(e),smsMessages:new ke(e),users:new _e(e)}}var tt=t=>()=>{let e={...t};return e.apiKey=(e.apiKey||"").substring(0,7),e.jwtKey=(e.jwtKey||"").substring(0,7),{...e}};function rt(t,e,r){let{act:i,sid:n,org_id:s,org_role:a,org_slug:d,sub:p}=t,{apiKey:f,secretKey:y,apiUrl:h,apiVersion:S,token:m,session:g,user:O,organization:k}=e,{sessions:_}=te({apiKey:f,secretKey:y,apiUrl:h,apiVersion:S}),I=Gt({sessionId:n,sessionToken:m,fetcher:(...w)=>_.getToken(...w)});return{actor:i,sessionClaims:t,sessionId:n,session:g,userId:p,user:O,orgId:s,orgRole:a,orgSlug:d,organization:k,getToken:I,debug:tt(r)}}function nt(t){return{sessionClaims:null,sessionId:null,session:null,userId:null,user:null,actor:null,orgId:null,orgRole:null,orgSlug:null,organization:null,getToken:()=>Promise.resolve(null),debug:tt(t)}}function et(t){return t&&(delete t.privateMetadata,delete t.private_metadata),t}function Mi(t){let e=t.user?{...t.user}:t.user,r=t.organization?{...t.organization}:t.organization;return et(e),et(r),{...t,user:e,organization:r}}var Gt=t=>{let{fetcher:e,sessionToken:r,sessionId:i}=t||{};return async(n={})=>i?n.template?e(i,n.template):r:null};function $t(t){return new Promise(e=>setTimeout(e,t))}var Ht=5;async function se(t,e=1,r=Ht){try{return await t()}catch(i){if(e>=r)throw i;return await $t(2**e*100),se(t,e+1)}}function Ie(t){return t.startsWith("test_")||t.startsWith("sk_test_")}function it(t){return t.startsWith("live_")||t.startsWith("sk_live_")}function st(t){return t.endsWith(".lclstage.dev")||t.endsWith(".stgstage.dev")||t.endsWith(".clerkstage.dev")||t.endsWith(".accountsstage.dev")}var ot="pk_live_",Yt="pk_test_";function oe(t){if(t=t||"",!Xt(t))return null;let e=t.startsWith(ot)?"production":"development",r=at(t.split("_")[2]);return r.endsWith("$")?(r=r.slice(0,-1),{instanceType:e,frontendApi:r}):null}function Xt(t){t=t||"";let e=t.startsWith(ot)||t.startsWith(Yt),r=at(t.split("_")[2]||"").endsWith("$");return e&&r}var at=t=>typeof atob<"u"&&typeof atob=="function"?atob(t):typeof Buffer<"u"?new Buffer(t,"base64").toString():t;var l=class extends Error{constructor({action:r,message:i,reason:n}){super(i);Object.setPrototypeOf(this,l.prototype),this.reason=n,this.message=i,this.action=r}getFullMessage(){return`${[this.message,this.action].filter(r=>r).join(" ")} (reason=${this.reason}, token-carrier=${this.tokenCarrier})`}};function Ue(t){let{debugData:e,frontendApi:r,pkgVersion:i,publishableKey:n}=t;return` | ||
var c=class{constructor(e){this.request=e}requireId(e){if(!e)throw new Error("A valid resource ID is required.")}};var Je="/",Rt=new RegExp(Je+"{1,}","g");function o(...t){return t.filter(e=>e).join(Je).replace(Rt,Je)}var Re="/allowlist_identifiers",ae=class extends c{async getAllowlistIdentifierList(){return this.request({method:"GET",path:Re})}async createAllowlistIdentifier(e){return this.request({method:"POST",path:Re,bodyParams:e})}async deleteAllowlistIdentifier(e){return this.requireId(e),this.request({method:"DELETE",path:o(Re,e)})}};var Ne="/clients",le=class extends c{async getClientList(){return this.request({method:"GET",path:Ne})}async getClient(e){return this.requireId(e),this.request({method:"GET",path:o(Ne,e)})}verifyClient(e){return this.request({method:"POST",path:o(Ne,"verify"),bodyParams:{token:e}})}};var ue="/email_addresses",de=class extends c{async getEmailAddress(e){return this.requireId(e),this.request({method:"GET",path:o(ue,e)})}async createEmailAddress(e){return this.request({method:"POST",path:ue,bodyParams:e})}async updateEmailAddress(e,r={}){return this.requireId(e),this.request({method:"PATCH",path:o(ue,e),bodyParams:r})}async deleteEmailAddress(e){return this.requireId(e),this.request({method:"DELETE",path:o(ue,e)})}};var Nt="/emails",ce=class extends c{async createEmail(e){return this.request({method:"POST",path:Nt,bodyParams:e})}};var pe=class extends c{async getInterstitial(){return this.request({path:"internal/interstitial",method:"GET",headerParams:{"Content-Type":"text/html"}})}};var Ce="/invitations",me=class extends c{async getInvitationList(){return this.request({method:"GET",path:Ce})}async createInvitation(e){return this.request({method:"POST",path:Ce,bodyParams:e})}async revokeInvitation(e){return this.requireId(e),this.request({method:"POST",path:o(Ce,e,"revoke")})}};var A="/organizations",ge=class extends c{async getOrganizationList(e){return this.request({method:"GET",path:A,queryParams:e})}async createOrganization(e){return this.request({method:"POST",path:A,bodyParams:e})}async getOrganization(e){let r="organizationId"in e?e.organizationId:e.slug;return this.requireId(r),this.request({method:"GET",path:o(A,r)})}async updateOrganization(e,r){return this.requireId(e),this.request({method:"PATCH",path:o(A,e),bodyParams:r})}async updateOrganizationMetadata(e,r){return this.requireId(e),this.request({method:"PATCH",path:o(A,e,"metadata"),bodyParams:r})}async deleteOrganization(e){return this.request({method:"DELETE",path:o(A,e)})}async getOrganizationMembershipList(e){let{organizationId:r,limit:i,offset:n}=e;return this.requireId(r),this.request({method:"GET",path:o(A,r,"memberships"),queryParams:{limit:i,offset:n}})}async createOrganizationMembership(e){let{organizationId:r,userId:i,role:n}=e;return this.requireId(r),this.request({method:"POST",path:o(A,r,"memberships"),bodyParams:{userId:i,role:n}})}async updateOrganizationMembership(e){let{organizationId:r,userId:i,role:n}=e;return this.requireId(r),this.request({method:"PATCH",path:o(A,r,"memberships",i),bodyParams:{role:n}})}async updateOrganizationMembershipMetadata(e){let{organizationId:r,userId:i,publicMetadata:n,privateMetadata:s}=e;return this.request({method:"PATCH",path:o(A,r,"memberships",i,"metadata"),bodyParams:{publicMetadata:n,privateMetadata:s}})}async deleteOrganizationMembership(e){let{organizationId:r,userId:i}=e;return this.requireId(r),this.request({method:"DELETE",path:o(A,r,"memberships",i)})}async getPendingOrganizationInvitationList(e){let{organizationId:r,limit:i,offset:n}=e;return this.requireId(r),this.request({method:"GET",path:o(A,r,"invitations","pending"),queryParams:{limit:i,offset:n}})}async createOrganizationInvitation(e){let{organizationId:r,...i}=e;return this.requireId(r),this.request({method:"POST",path:o(A,r,"invitations"),bodyParams:{...i}})}async revokeOrganizationInvitation(e){let{organizationId:r,invitationId:i,requestingUserId:n}=e;return this.requireId(r),this.request({method:"POST",path:o(A,r,"invitations",i,"revoke"),bodyParams:{requestingUserId:n}})}};var fe="/phone_numbers",ye=class extends c{async getPhoneNumber(e){return this.requireId(e),this.request({method:"GET",path:o(fe,e)})}async createPhoneNumber(e){return this.request({method:"POST",path:fe,bodyParams:e})}async updatePhoneNumber(e,r={}){return this.requireId(e),this.request({method:"PATCH",path:o(fe,e),bodyParams:r})}async deletePhoneNumber(e){return this.requireId(e),this.request({method:"DELETE",path:o(fe,e)})}};var he="/redirect_urls",be=class extends c{async getRedirectUrlList(){return this.request({method:"GET",path:he})}async getRedirectUrl(e){return this.requireId(e),this.request({method:"GET",path:o(he,e)})}async createRedirectUrl(e){return this.request({method:"POST",path:he,bodyParams:e})}async deleteRedirectUrl(e){return this.requireId(e),this.request({method:"DELETE",path:o(he,e)})}};var re="/sessions",Se=class extends c{constructor(){super(...arguments);this.getSessionList=async r=>this.request({method:"GET",path:re,queryParams:r});this.getSession=async r=>(this.requireId(r),this.request({method:"GET",path:o(re,r)}));this.revokeSession=async r=>(this.requireId(r),this.request({method:"POST",path:o(re,r,"revoke")}));this.verifySession=async(r,i)=>(this.requireId(r),this.request({method:"POST",path:o(re,r,"verify"),bodyParams:{token:i}}));this.getToken=async(r,i)=>(this.requireId(r),(await this.request({method:"POST",path:o(re,r,"tokens",i||"")})).jwt)}};var Ge="/sign_in_tokens",Oe=class extends c{async createSignInToken(e){return this.request({method:"POST",path:Ge,bodyParams:e})}async revokeSignInToken(e){return this.requireId(e),this.request({method:"POST",path:o(Ge,e,"revoke")})}};var Ct="/sms_messages",ke=class extends c{async createSMSMessage(e){return this.request({method:"POST",path:Ct,bodyParams:e})}};var J="/users",_e=class extends c{async getUserList(e={}){return this.request({method:"GET",path:J,queryParams:e})}async getUser(e){return this.requireId(e),this.request({method:"GET",path:o(J,e)})}async createUser(e){return this.request({method:"POST",path:J,bodyParams:e})}async updateUser(e,r={}){return this.requireId(e),this.request({method:"PATCH",path:o(J,e),bodyParams:r})}async updateUserMetadata(e,r){return this.requireId(e),this.request({method:"PATCH",path:o(J,e,"metadata"),bodyParams:r})}async deleteUser(e){return this.requireId(e),this.request({method:"DELETE",path:o(J,e)})}async getCount(e={}){return this.request({method:"GET",path:o(J,"count"),queryParams:e})}async getUserOauthAccessToken(e,r){return this.requireId(e),this.request({method:"GET",path:o(J,e,"oauth_access_tokens",r)})}async disableUserMFA(e){return this.requireId(e),this.request({method:"DELETE",path:o(J,e,"mfa")})}async getOrganizationMembershipList(e){let{userId:r,limit:i,offset:n}=e;return this.requireId(r),this.request({method:"GET",path:o(J,r,"organization_memberships"),queryParams:{limit:i,offset:n}})}};import Ft from"deepmerge";import Qe from"snakecase-keys";var v="https://api.clerk.dev",R="v1",He="@clerk/backend";var vt={AuthStatus:"__clerkAuthStatus"},Et={Session:"__session",ClientUat:"__client_uat"},$e={AuthStatus:"x-clerk-auth-status",AuthReason:"x-clerk-auth-reason",AuthMessage:"x-clerk-auth-message",Authorization:"authorization",ForwardedPort:"x-forwarded-port",ForwardedHost:"x-forwarded-host",Referrer:"referer",UserAgent:"user-agent",Origin:"origin",Host:"host"},Ut={AuthStatus:$e.AuthStatus},qt={Attributes:vt,Cookies:Et,Headers:$e,SearchParams:Ut};import zt from"#crypto";import Kt from"#fetch";var Mt=Kt.bind(globalThis),jt={crypto:zt,fetch:Mt},N=jt;var j=class{constructor(e,r,i,n,s){this.id=e;this.identifier=r;this.createdAt=i;this.updatedAt=n;this.invitationId=s}static fromJSON(e){return new j(e.id,e.identifier,e.created_at,e.updated_at,e.invitation_id)}};var E=class{constructor(e,r,i,n,s,a,d,p,f){this.id=e;this.clientId=r;this.userId=i;this.status=n;this.lastActiveAt=s;this.expireAt=a;this.abandonAt=d;this.createdAt=p;this.updatedAt=f}static fromJSON(e){return new E(e.id,e.client_id,e.user_id,e.status,e.last_active_at,e.expire_at,e.abandon_at,e.created_at,e.updated_at)}};var W=class{constructor(e,r,i,n,s,a,d,p){this.id=e;this.sessionIds=r;this.sessions=i;this.signInId=n;this.signUpId=s;this.lastActiveSessionId=a;this.createdAt=d;this.updatedAt=p}static fromJSON(e){return new W(e.id,e.session_ids,e.sessions.map(r=>E.fromJSON(r)),e.sign_in_id,e.sign_up_id,e.last_active_session_id,e.created_at,e.updated_at)}};var L=class{constructor(e,r,i,n){this.object=e;this.id=r;this.slug=i;this.deleted=n}static fromJSON(e){return new L(e.object,e.id||null,e.slug||null,e.deleted)}};var F=class{constructor(e,r,i,n,s,a,d){this.id=e;this.fromEmailName=r;this.emailAddressId=i;this.toEmailAddress=n;this.subject=s;this.body=a;this.status=d}static fromJSON(e){return new F(e.id,e.from_email_name,e.email_address_id,e.to_email_address,e.subject,e.body,e.status)}};var U=class{constructor(e,r){this.id=e;this.type=r}static fromJSON(e){return new U(e.id,e.type)}};var x=class{constructor(e,r,i=null,n=null,s=null,a=null){this.status=e;this.strategy=r;this.externalVerificationRedirectURL=i;this.attempts=n;this.expireAt=s;this.nonce=a}static fromJSON(e){return new x(e.status,e.strategy,e.external_verification_redirect_url?new URL(e.external_verification_redirect_url):null,e.attempts,e.expire_at,e.nonce)}};var q=class{constructor(e,r,i,n){this.id=e;this.emailAddress=r;this.verification=i;this.linkedTo=n}static fromJSON(e){return new q(e.id,e.email_address,e.verification&&x.fromJSON(e.verification),e.linked_to.map(r=>U.fromJSON(r)))}};var D=class{constructor(e,r,i,n,s,a,d,p,f,y,h={},S,m){this.id=e;this.provider=r;this.identificationId=i;this.externalId=n;this.approvedScopes=s;this.emailAddress=a;this.firstName=d;this.lastName=p;this.picture=f;this.username=y;this.publicMetadata=h;this.label=S;this.verification=m}static fromJSON(e){return new D(e.id,e.provider,e.identification_id,e.provider_user_id,e.approved_scopes,e.email_address,e.first_name,e.last_name,e.avatar_url,e.username,e.public_metadata,e.label,e.verification&&x.fromJSON(e.verification))}};var V=class{constructor(e,r,i,n,s,a){this.id=e;this.emailAddress=r;this.publicMetadata=i;this.createdAt=n;this.updatedAt=s;this.revoked=a}static fromJSON(e){return new V(e.id,e.email_address,e.public_metadata,e.created_at,e.updated_at,e.revoked)}};var Ye=(u=>(u.AllowlistIdentifier="allowlist_identifier",u.Client="client",u.Email="email",u.EmailAddress="email_address",u.ExternalAccount="external_account",u.FacebookAccount="facebook_account",u.GoogleAccount="google_account",u.Invitation="invitation",u.OauthAccessToken="oauth_access_token",u.Organization="organization",u.OrganizationInvitation="organization_invitation",u.OrganizationMembership="organization_membership",u.PhoneNumber="phone_number",u.RedirectUrl="redirect_url",u.Session="session",u.SignInAttempt="sign_in_attempt",u.SignInToken="sign_in_token",u.SignUpAttempt="sign_up_attempt",u.SmsMessage="sms_message",u.User="user",u.Web3Wallet="web3_wallet",u.Token="token",u.TotalCount="total_count",u))(Ye||{});var B=class{constructor(e,r,i={},n,s,a){this.provider=e;this.token=r;this.publicMetadata=i;this.label=n;this.scopes=s;this.tokenSecret=a}static fromJSON(e){return new B(e.provider,e.token,e.public_metadata,e.label,e.scopes,e.token_secret)}};var z=class{constructor(e,r,i,n,s,a,d={},p={}){this.id=e;this.name=r;this.slug=i;this.logoUrl=n;this.createdAt=s;this.updatedAt=a;this.publicMetadata=d;this.privateMetadata=p}static fromJSON(e){return new z(e.id,e.name,e.slug,e.logo_url,e.created_at,e.updated_at,e.public_metadata,e.private_metadata)}};var G=class{constructor(e,r,i,n,s,a,d){this.id=e;this.emailAddress=r;this.role=i;this.organizationId=n;this.createdAt=s;this.updatedAt=a;this.status=d}static fromJSON(e){return new G(e.id,e.email_address,e.role,e.organization_id,e.created_at,e.updated_at,e.status)}};var H=class{constructor(e,r,i={},n={},s,a,d,p){this.id=e;this.role=r;this.publicMetadata=i;this.privateMetadata=n;this.createdAt=s;this.updatedAt=a;this.organization=d;this.publicUserData=p}static fromJSON(e){return new H(e.id,e.role,e.public_metadata,e.private_metadata,e.created_at,e.updated_at,z.fromJSON(e.organization),ne.fromJSON(e.public_user_data))}},ne=class{constructor(e,r,i,n,s){this.identifier=e;this.firstName=r;this.lastName=i;this.profileImageUrl=n;this.userId=s}static fromJSON(e){return new ne(e.identifier,e.first_name,e.last_name,e.profile_image_url,e.user_id)}};var K=class{constructor(e,r,i,n,s,a){this.id=e;this.phoneNumber=r;this.reservedForSecondFactor=i;this.defaultSecondFactor=n;this.verification=s;this.linkedTo=a}static fromJSON(e){return new K(e.id,e.phone_number,e.reserved_for_second_factor,e.default_second_factor,e.verification&&x.fromJSON(e.verification),e.linked_to.map(r=>U.fromJSON(r)))}};var $=class{constructor(e,r,i,n){this.id=e;this.url=r;this.createdAt=i;this.updatedAt=n}static fromJSON(e){return new $(e.id,e.url,e.created_at,e.updated_at)}};var Y=class{constructor(e,r,i,n,s,a){this.id=e;this.userId=r;this.token=i;this.status=n;this.createdAt=s;this.updatedAt=a}static fromJSON(e){return new Y(e.id,e.user_id,e.token,e.status,e.created_at,e.updated_at)}};var X=class{constructor(e,r,i,n,s,a){this.id=e;this.fromPhoneNumber=r;this.toPhoneNumber=i;this.message=n;this.status=s;this.phoneNumberId=a}static fromJSON(e){return new X(e.id,e.from_phone_number,e.to_phone_number,e.message,e.status,e.phone_number_id)}};var Q=class{constructor(e){this.jwt=e}static fromJSON(e){return new Q(e.jwt)}};var Z=class{constructor(e,r,i){this.id=e;this.web3Wallet=r;this.verification=i}static fromJSON(e){return new Z(e.id,e.web3_wallet,e.verification&&x.fromJSON(e.verification))}};var ee=class{constructor(e,r,i,n,s,a,d,p,f,y,h,S,m,g,O,k,_,I,w,T={},P={},b={},u=[],Te=[],Be=[],mr=[]){this.id=e;this.passwordEnabled=r;this.totpEnabled=i;this.backupCodeEnabled=n;this.twoFactorEnabled=s;this.banned=a;this.createdAt=d;this.updatedAt=p;this.profileImageUrl=f;this.gender=y;this.birthday=h;this.primaryEmailAddressId=S;this.primaryPhoneNumberId=m;this.primaryWeb3WalletId=g;this.lastSignInAt=O;this.externalId=k;this.username=_;this.firstName=I;this.lastName=w;this.publicMetadata=T;this.privateMetadata=P;this.unsafeMetadata=b;this.emailAddresses=u;this.phoneNumbers=Te;this.web3Wallets=Be;this.externalAccounts=mr}static fromJSON(e){return new ee(e.id,e.password_enabled,e.totp_enabled,e.backup_code_enabled,e.two_factor_enabled,e.banned,e.created_at,e.updated_at,e.profile_image_url,e.gender,e.birthday,e.primary_email_address_id,e.primary_phone_number_id,e.primary_web3_wallet_id,e.last_sign_in_at,e.external_id,e.username,e.first_name,e.last_name,e.public_metadata,e.private_metadata,e.unsafe_metadata,(e.email_addresses||[]).map(r=>q.fromJSON(r)),(e.phone_numbers||[]).map(r=>K.fromJSON(r)),(e.web3_wallets||[]).map(r=>Z.fromJSON(r)),(e.external_accounts||[]).map(r=>D.fromJSON(r)))}};function Xe(t){return Array.isArray(t)?t.map(e=>ve(e)):Wt(t)?t.data.map(e=>ve(e)):ve(t)}function Wt(t){return t.data!==void 0}function Lt(t){return t.total_count}function ve(t){if(typeof t!="string"&&"object"in t&&"deleted"in t)return L.fromJSON(t);switch(t.object){case"allowlist_identifier":return j.fromJSON(t);case"client":return W.fromJSON(t);case"email_address":return q.fromJSON(t);case"email":return F.fromJSON(t);case"invitation":return V.fromJSON(t);case"oauth_access_token":return B.fromJSON(t);case"organization":return z.fromJSON(t);case"organization_invitation":return G.fromJSON(t);case"organization_membership":return H.fromJSON(t);case"phone_number":return K.fromJSON(t);case"redirect_url":return $.fromJSON(t);case"sign_in_token":return Y.fromJSON(t);case"session":return E.fromJSON(t);case"sms_message":return X.fromJSON(t);case"token":return Q.fromJSON(t);case"total_count":return Lt(t);case"user":return ee.fromJSON(t);default:return t}}var Dt=t=>async(...e)=>{let{data:r,errors:i,status:n,statusText:s}=await t(...e);if(i===null)return r;throw new ie(s||"",{data:i,status:n||""})};function Ze(t){return Dt(async r=>{let{apiKey:i,secretKey:n,apiUrl:s=v,apiVersion:a=R,userAgent:d=He,httpOptions:p={}}=t,{path:f,method:y,queryParams:h,headerParams:S,bodyParams:m}=r,g=n||i;if(!g)throw Error("Missing Clerk Secret Key or API Key. Go to https://dashboard.clerk.dev and get your key for your instance.");let O=o(s,a,f),k=new URL(O);if(h){let P=Qe({...h});for(let[b,u]of Object.entries(P))u&&[u].flat().forEach(Te=>k.searchParams.append(b,Te))}let _={Authorization:`Bearer ${g}`,"Content-Type":"application/json","Clerk-Backend-SDK":d,...S},w=y!=="GET"&&m&&Object.keys(m).length>0?{body:JSON.stringify(Qe(m,{deep:!1}))}:null,T;try{T=await N.fetch(k.href,Ft(p,{method:y,headers:_,...w}));let b=await(_&&_["Content-Type"]==="application/json"?T.json():T.text());if(!T.ok)throw b;return{data:Xe(b),errors:null}}catch(P){return P instanceof Error?{data:null,errors:[{code:"unexpected_error",message:P.message||"Unexpected error"}]}:{data:null,errors:Vt(P),status:T?.status,statusText:T?.statusText}}})}function Vt(t){if(!!t&&typeof t=="object"&&"errors"in t){let e=t.errors;return e.length>0?e.map(Bt):[]}return[]}function Bt(t){return{code:t.code,message:t.message,longMessage:t.long_message,meta:{paramName:t?.meta?.param_name,sessionId:t?.meta?.session_id}}}var ie=class extends Error{constructor(r,{data:i,status:n}){super(r);Object.setPrototypeOf(this,ie.prototype),this.clerkError=!0,this.message=r,this.status=n,this.errors=i}};function te(t){let e=Ze(t);return{allowlistIdentifiers:new ae(e),clients:new le(e),emailAddresses:new de(e),emails:new ce(e),interstitial:new pe(e),invitations:new me(e),organizations:new ge(e),phoneNumbers:new ye(e),redirectUrls:new be(e),sessions:new Se(e),signInTokens:new Oe(e),smsMessages:new ke(e),users:new _e(e)}}var tt=t=>()=>{let e={...t};return e.apiKey=(e.apiKey||"").substring(0,7),e.jwtKey=(e.jwtKey||"").substring(0,7),{...e}};function rt(t,e,r){let{act:i,sid:n,org_id:s,org_role:a,org_slug:d,sub:p}=t,{apiKey:f,secretKey:y,apiUrl:h,apiVersion:S,token:m,session:g,user:O,organization:k}=e,{sessions:_}=te({apiKey:f,secretKey:y,apiUrl:h,apiVersion:S}),I=Gt({sessionId:n,sessionToken:m,fetcher:(...w)=>_.getToken(...w)});return{actor:i,sessionClaims:t,sessionId:n,session:g,userId:p,user:O,orgId:s,orgRole:a,orgSlug:d,organization:k,getToken:I,debug:tt(r)}}function nt(t){return{sessionClaims:null,sessionId:null,session:null,userId:null,user:null,actor:null,orgId:null,orgRole:null,orgSlug:null,organization:null,getToken:()=>Promise.resolve(null),debug:tt(t)}}function et(t){return t&&(delete t.privateMetadata,delete t.private_metadata),t}function Mi(t){let e=t.user?{...t.user}:t.user,r=t.organization?{...t.organization}:t.organization;return et(e),et(r),{...t,user:e,organization:r}}var Gt=t=>{let{fetcher:e,sessionToken:r,sessionId:i}=t||{};return async(n={})=>i?n.template?e(i,n.template):r:null};function Ht(t){return new Promise(e=>setTimeout(e,t))}var $t=5;async function se(t,e=1,r=$t){try{return await t()}catch(i){if(e>=r)throw i;return await Ht(2**e*100),se(t,e+1)}}function Ie(t){return t.startsWith("test_")||t.startsWith("sk_test_")}function it(t){return t.startsWith("live_")||t.startsWith("sk_live_")}function st(t){return t.endsWith(".lclstage.dev")||t.endsWith(".stgstage.dev")||t.endsWith(".clerkstage.dev")||t.endsWith(".accountsstage.dev")}var ot="pk_live_",Yt="pk_test_";function oe(t){if(t=t||"",!Xt(t))return null;let e=t.startsWith(ot)?"production":"development",r=at(t.split("_")[2]);return r.endsWith("$")?(r=r.slice(0,-1),{instanceType:e,frontendApi:r}):null}function Xt(t){t=t||"";let e=t.startsWith(ot)||t.startsWith(Yt),r=at(t.split("_")[2]||"").endsWith("$");return e&&r}var at=t=>typeof atob<"u"&&typeof atob=="function"?atob(t):typeof Buffer<"u"?new Buffer(t,"base64").toString():t;var l=class extends Error{constructor({action:r,message:i,reason:n}){super(i);Object.setPrototypeOf(this,l.prototype),this.reason=n,this.message=i,this.action=r}getFullMessage(){return`${[this.message,this.action].filter(r=>r).join(" ")} (reason=${this.reason}, token-carrier=${this.tokenCarrier})`}};function Ue(t){let{debugData:e,frontendApi:r,pkgVersion:i,publishableKey:n}=t;return` | ||
<head> | ||
@@ -54,3 +54,3 @@ <meta charset="UTF-8" /> | ||
</body> | ||
`}async function lt(t){t.frontendApi=oe(t.publishableKey)?.frontendApi||t.frontendApi||"";let e=Ae(t),r=await se(()=>N.fetch(Ae(t)));if(!r.ok)throw new l({action:"Contact support@clerk.dev",message:`Error loading Clerk Interstitial from ${e} with code=${r.status}`,reason:"interstitial-remote-failed-to-load"});return r.text()}function Ae(t){t.frontendApi=oe(t.publishableKey)?.frontendApi||t.frontendApi||"";let{apiUrl:e,frontendApi:r,pkgVersion:i,publishableKey:n}=t,s=new URL(e);return s.pathname=o(s.pathname,R,"/public/interstitial"),s.searchParams.append("clerk_js_version",ut(r,i)),n?s.searchParams.append("publishable_key",n):s.searchParams.append("frontend_api",r),s.href}var ut=(t,e)=>!e&&st(t)?"staging":e?e.includes("next")?"next":e.split(".")[0]||"latest":"latest",Qt=(t,e)=>{let r=ut(t,e);return`https://${t}/npm/@clerk/clerk-js@${r}/dist/clerk.browser.js`};var dt=(n=>(n.SignedIn="signed-in",n.SignedOut="signed-out",n.Interstitial="interstitial",n.Unknown="unknown",n))(dt||{});async function qe(t,e){let{apiKey:r,secretKey:i,apiUrl:n,apiVersion:s,cookieToken:a,frontendApi:d,publishableKey:p,headerToken:f,loadSession:y,loadUser:h,loadOrganization:S}=t,{sid:m,org_id:g,sub:O}=e,{sessions:k,users:_,organizations:I}=te({apiKey:r,secretKey:i,apiUrl:n,apiVersion:s}),[w,T,P]=await Promise.all([y?k.getSession(m):Promise.resolve(void 0),h?_.getUser(O):Promise.resolve(void 0),S&&g?I.getOrganization({organizationId:g}):Promise.resolve(void 0)]),Be=rt(e,{apiKey:r,apiUrl:n,apiVersion:s,token:a||f||"",session:w,user:T,organization:P},{...t,status:"signed-in"});return{status:"signed-in",reason:null,message:null,frontendApi:d,publishableKey:p,isSignedIn:!0,isInterstitial:!1,isUnknown:!1,toAuth:()=>Be}}function C(t,e,r=""){let{frontendApi:i,publishableKey:n}=t;return{status:"signed-out",reason:e,message:r,frontendApi:i,publishableKey:n,isSignedIn:!1,isInterstitial:!1,isUnknown:!1,toAuth:()=>nt({...t,status:"signed-out",reason:e,message:r})}}function M(t,e,r=""){let{frontendApi:i,publishableKey:n}=t;return{status:"interstitial",reason:e,message:r,frontendApi:i,publishableKey:n,isSignedIn:!1,isInterstitial:!0,isUnknown:!1,toAuth:()=>null}}function ct(t,e,r=""){let{frontendApi:i,publishableKey:n}=t;return{status:"unknown",reason:e,message:r,frontendApi:i,publishableKey:n,isSignedIn:!1,isInterstitial:!1,isUnknown:!0,toAuth:()=>null}}function ze({originURL:t,host:e,forwardedHost:r,forwardedPort:i,forwardedProto:n}){if(n&&n!==t.protocol)return!0;let s=Zt(r||e);return s.port=i||s.port,s.port!==t.port||s.hostname!==t.hostname}function Zt(t){return new URL(`https://${t}`)}import{base64url as Ke}from"rfc4648";var er=2*1e3,We={RS256:"SHA-256",RS384:"SHA-384",RS512:"SHA-512",ES256:"SHA-256",ES384:"SHA-384",ES512:"SHA-512"},Me="RSASSA-PKCS1-v1_5",je="ECDSA",tr={RS256:Me,RS384:Me,RS512:Me,ES256:je,ES384:je,ES512:je},rr=Object.keys(We);async function nr(t,e){let{header:r,signature:i,raw:n}=t,a=new TextEncoder().encode([n.header,n.payload].join(".")),d=await N.crypto.subtle.importKey("jwk",e,{name:tr[r.alg],hash:We[r.alg]},!1,["verify"]);return N.crypto.subtle.verify("RSASSA-PKCS1-v1_5",d,i,a)}function Le(t){let e=(t||"").toString().split(".");if(e.length!==3)throw new l({reason:"token-invalid",message:"Invalid JWT form. A JWT consists of three parts separated by dots."});let[r,i,n]=e,s=new TextDecoder,a=JSON.parse(s.decode(Ke.parse(r,{loose:!0}))),d=JSON.parse(s.decode(Ke.parse(i,{loose:!0}))),p=Ke.parse(n,{loose:!0});return{header:a,payload:d,signature:p,raw:{header:r,payload:i,signature:n,text:t}}}async function pt(t,{audience:e,authorizedParties:r,clockSkewInSeconds:i=er,issuer:n,key:s}){let a=Le(t),{header:d,payload:p}=a,{typ:f,alg:y}=d;if(typeof f<"u"&&f!=="JWT")throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-invalid",message:`Invalid JWT type ${JSON.stringify(f)}. Expected "JWT".`});if(!We[y])throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-invalid-algorithm",message:`Invalid JWT algorithm ${JSON.stringify(y)}. Supported: ${rr}.`});let{azp:h,sub:S,aud:m,iss:g,iat:O,exp:k,nbf:_}=p;if(typeof S!="string")throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-verification-failed",message:`Subject claim (sub) is required and must be a string. Received ${JSON.stringify(S)}.`});if(typeof m=="string"){if(m!==e)throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-verification-failed",message:`Invalid JWT audience claim (aud) ${JSON.stringify(m)}. Expected "${e}".`})}else if(Array.isArray(m)&&m.length>0&&m.every(b=>typeof b=="string")&&!m.includes(e))throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-verification-failed",message:`Invalid JWT audience claim array (aud) ${JSON.stringify(m)}. Does not include "${e}".`});if(h&&r&&r.length>0&&!r.includes(h))throw new l({reason:"token-invalid-authorized-parties",message:`Invalid JWT Authorized party claim (azp) ${JSON.stringify(h)}. Expected "${r}".`});if(typeof n=="function"&&!n(g))throw new l({reason:"token-invalid-issuer",message:"Failed JWT issuer resolver. Make sure that the resolver returns a truthy value."});if(typeof n=="string"&&g&&g!==n)throw new l({reason:"token-invalid-issuer",message:`Invalid JWT issuer claim (iss) ${JSON.stringify(a.payload.iss)}. Expected "${n}".`});if(typeof k!="number")throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-verification-failed",message:`Invalid JWT expiry date claim (exp) ${JSON.stringify(k)}. Expected number.`});let I=new Date(Date.now()),w=new Date(0);if(w.setUTCSeconds(k),w.getTime()<=I.getTime()-i)throw new l({reason:"token-expired",message:`JWT is expired. Expiry date: ${w}, Current date: ${I}.`});if(_!==void 0){if(typeof _!="number")throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-verification-failed",message:`Invalid JWT not before date claim (nbf) ${JSON.stringify(_)}. Expected number.`});let b=new Date(0);if(b.setUTCSeconds(_),b.getTime()>I.getTime()+i)throw new l({reason:"token-not-active-yet",message:`JWT cannot be used prior to not before date claim (nbf). Not before date: ${b}; Current date: ${I};`})}if(O!==void 0){if(typeof O!="number")throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-verification-failed",message:`Invalid JWT issued at date claim (iat) ${JSON.stringify(O)}. Expected number.`});let b=new Date(0);if(b.setUTCSeconds(O),b.getTime()>I.getTime()+i)throw new l({reason:"token-not-active-yet",message:`JWT issued at date claim (iat) is in the future. Issued at date: ${b}; Current date: ${I};`})}let P;try{P=await nr(a,s)}catch(b){throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-verification-failed",message:`Error verifying JWT signature. ${b}`})}if(!P)throw new l({reason:"token-invalid-signature",message:"JWT signature is invalid."});return p}var Pe={},gt=0;function xe(t){return Pe[t]}function ft(t,e=1e3*60*60){Pe[t.kid]=t,gt=Date.now(),e>=0&&setTimeout(()=>{t?delete Pe[t.kid]:Pe={}},e)}var mt="local",sr="-----BEGIN PUBLIC KEY-----",or="-----END PUBLIC KEY-----",ar="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA",lr="IDAQAB";function yt(t){if(!xe(mt)){if(!t)throw new l({action:"Set the CLERK_JWT_KEY environment variable.",message:"Missing local JWK.",reason:"jwk-local-missing"});let e=t.replace(/(\r\n|\n|\r)/gm,"").replace(sr,"").replace(or,"").replace(ar,"").replace(lr,"").replace(/\+/g,"-").replace(/\//g,"_");ft({kid:"local",kty:"RSA",alg:"RS256",n:e,e:"AQAB"},-1)}return xe(mt)}async function Fe({apiKey:t,secretKey:e,apiUrl:r=v,apiVersion:i=R,issuer:n,kid:s,jwksCacheTtlInMs:a=1e3*60*60,skipJwksCache:d}){let p=!xe(s)&&cr();if(d||p){let y,h=e||t;if(h)y=()=>dr(r,h,i);else if(n)y=()=>ur(n);else throw new l({action:"Contact support@clerk.dev",message:"Failed to load JWKS from Clerk Backend or Frontend API.",reason:"jwk-remote-failed-to-load"});let{keys:S}=await se(y);if(!S||!S.length)throw new l({action:"Contact support@clerk.dev",message:"The JWKS endpoint did not contain any signing keys. Contact support@clerk.dev.",reason:"jwk-remote-failed-to-load"});S.forEach(m=>ft(m,a))}let f=xe(s);if(!f)throw new l({action:"Contact support@clerk.dev",message:`Unable to find a signing key in JWKS that matches kid='${s}'.`,reason:"jwk-remote-missing"});return f}async function ur(t){let e=new URL(t);e.pathname=o(e.pathname,".well-known/jwks.json");let r=await N.fetch(e.href);if(!r.ok)throw new l({action:"Contact support@clerk.dev",message:`Error loading Clerk JWKS from ${e.href} with code=${r.status}`,reason:"jwk-remote-failed-to-load"});return r.json()}async function dr(t,e,r){if(!e)throw new l({action:"Set the CLERK_SECRET_KEY or CLERK_API_KEY environment variable.",message:"Missing Clerk Secret Key or API Key. Go to https://dashboard.clerk.dev and get your key for your instance.",reason:"jwk-remote-failed-to-load"});let i=new URL(t);i.pathname=o(i.pathname,r,"/jwks");let n=await N.fetch(i.href,{headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"}});if(!n.ok)throw new l({action:"Contact support@clerk.dev",message:`Error loading Clerk JWKS from ${i.href} with code=${n.status}`,reason:"jwk-remote-failed-to-load"});return n.json()}function cr(){return Date.now()-gt>=300*1e3}async function ht(t,e){let{apiKey:r,secretKey:i,apiUrl:n,apiVersion:s,authorizedParties:a,clockSkewInSeconds:d,issuer:p,jwksCacheTtlInMs:f,jwtKey:y,skipJwksCache:h}=e,{header:S}=Le(t),{kid:m}=S,g;if(y)g=yt(y);else if(typeof p=="string")g=await Fe({issuer:p,kid:m,jwksCacheTtlInMs:f,skipJwksCache:h});else if(r||i)g=await Fe({apiKey:r,secretKey:i,apiUrl:n,apiVersion:s,kid:m,jwksCacheTtlInMs:f,skipJwksCache:h});else throw new l({action:"Set the CLERK_JWT_KEY environment variable.",message:"Failed to resolve JWK during verification.",reason:"jwk-failed-to-resolve"});return await pt(t,{authorizedParties:a,clockSkewInSeconds:d,key:g,issuer:p})}var bt=async t=>{let{apiKey:e,secretKey:r,userAgent:i}=t;if(Ie(r||e)&&!i?.startsWith("Mozilla/"))return C(t,"header-missing-non-browser")},St=async t=>{let{origin:e,host:r,forwardedHost:i,forwardedPort:n,forwardedProto:s}=t;if(e&&ze({originURL:new URL(e),host:r,forwardedHost:i,forwardedPort:n,forwardedProto:s}))return C(t,"header-missing-cors")},Ot=async t=>{let{apiKey:e,secretKey:r,clientUat:i}=t;if(Ie(r||e)&&!i)return M(t,"uat-missing")},kt=async t=>{let{apiKey:e,secretKey:r,referrer:i,host:n,forwardedHost:s,forwardedPort:a,forwardedProto:d}=t,p=i&&ze({originURL:new URL(i),host:n,forwardedHost:s,forwardedPort:a,forwardedProto:d});if(Ie(r||e)&&p)return M(t,"cross-origin-referrer")},_t=async t=>{let{apiKey:e,secretKey:r,clientUat:i,cookieToken:n}=t;if(it(r||e)&&!i&&!n)return C(t,"cookie-and-uat-missing")},It=async t=>{let{clientUat:e}=t;if(e==="0")return C(t,"standard-signed-out")},At=async t=>{let{clientUat:e,cookieToken:r}=t;if(e&&!r)return M(t,"cookie-missing")},wt=async t=>{let{headerToken:e}=t,r=await xt(t,e);return await qe(t,r)},Pt=async t=>{let{cookieToken:e,clientUat:r}=t,i=await xt(t,e),n=await qe(t,i),a=n.toAuth().sessionClaims.iat<Number.parseInt(r);return!r||a?M(t,"cookie-outdated"):n};async function De(t,e){for(let r of e){let i=await r(t);if(i)return i}return C(t,"unexpected-error")}async function xt(t,e){return ht(e,{...t,issuer:i=>i.startsWith("https://clerk.")||i.includes(".clerk.accounts")})}async function Tt(t){t.frontendApi=oe(t.publishableKey)?.frontendApi||t.frontendApi||"",t.apiUrl=t.apiUrl||v,t.apiVersion=t.apiVersion||R;async function e(){try{return await De(t,[wt])}catch(n){return i(n,"header")}}async function r(){try{return await De(t,[bt,St,Ot,kt,_t,It,At,Pt])}catch(n){return i(n,"cookie")}}function i(n,s){return n instanceof l?(n.tokenCarrier=s,["token-expired","token-not-active-yet"].includes(n.reason)?s==="header"?ct(t,n.reason,n.getFullMessage()):M(t,n.reason,n.getFullMessage()):C(t,n.reason,n.getFullMessage())):C(t,"unexpected-error",n.message)}return t.headerToken?e():r()}var Ve=t=>{let{frontendApi:e,isSignedIn:r,isInterstitial:i,reason:n,message:s,publishableKey:a}=t;return{frontendApi:e,isSignedIn:r,isInterstitial:i,reason:n,message:s,publishableKey:a}};function Jt(t){let{apiClient:e}=t,{apiKey:r="",secretKey:i="",jwtKey:n="",apiUrl:s=v,apiVersion:a=R,frontendApi:d="",publishableKey:p=""}=t.options;return{authenticateRequest:({apiKey:g,secretKey:O,frontendApi:k,publishableKey:_,jwtKey:I,...w})=>Tt({...w,apiKey:g||r,secretKey:O||i,apiUrl:s,apiVersion:a,frontendApi:k||d,publishableKey:_||p,jwtKey:I||n}),localInterstitial:Ue,remotePublicInterstitial:({frontendApi:g,publishableKey:O,...k})=>lt({...k,apiUrl:s,frontendApi:g||d,publishableKey:O||p}),remotePrivateInterstitial:()=>e.interstitial.getInterstitial(),remotePublicInterstitialUrl:Ae,debugRequestState:Ve}}function Ds(t){let e={...t},r=te(e),i=Jt({options:e,apiClient:r});return{...r,...i,__unstable_options:e}}export{j as AllowlistIdentifier,dt as AuthStatus,Ds as Clerk,W as Client,L as DeletedObject,F as Email,q as EmailAddress,D as ExternalAccount,U as IdentificationLink,V as Invitation,B as OauthAccessToken,Ye as ObjectType,z as Organization,G as OrganizationInvitation,$ as OrganizationMembership,ne as OrganizationMembershipPublicUserData,K as PhoneNumber,H as RedirectUrl,X as SMSMessage,E as Session,Y as SignInToken,Q as Token,ee as User,x as Verification,qt as constants,Jt as createAuthenticateRequest,Ve as debugRequestState,Le as decodeJwt,Xe as deserialize,nr as hasValidSignature,Ue as loadInterstitialFromLocal,et as prunePrivateMetadata,Mi as sanitizeAuthObject,rt as signedInAuthObject,nt as signedOutAuthObject,pt as verifyJwt,ht as verifyToken}; | ||
`}async function lt(t){t.frontendApi=oe(t.publishableKey)?.frontendApi||t.frontendApi||"";let e=Ae(t),r=await se(()=>N.fetch(Ae(t)));if(!r.ok)throw new l({action:"Contact support@clerk.dev",message:`Error loading Clerk Interstitial from ${e} with code=${r.status}`,reason:"interstitial-remote-failed-to-load"});return r.text()}function Ae(t){t.frontendApi=oe(t.publishableKey)?.frontendApi||t.frontendApi||"";let{apiUrl:e,frontendApi:r,pkgVersion:i,publishableKey:n}=t,s=new URL(e);return s.pathname=o(s.pathname,R,"/public/interstitial"),s.searchParams.append("clerk_js_version",ut(r,i)),n?s.searchParams.append("publishable_key",n):s.searchParams.append("frontend_api",r),s.href}var ut=(t,e)=>!e&&st(t)?"staging":e?e.includes("next")?"next":e.split(".")[0]||"latest":"latest",Qt=(t,e)=>{let r=ut(t,e);return`https://${t}/npm/@clerk/clerk-js@${r}/dist/clerk.browser.js`};var dt=(n=>(n.SignedIn="signed-in",n.SignedOut="signed-out",n.Interstitial="interstitial",n.Unknown="unknown",n))(dt||{});async function qe(t,e){let{apiKey:r,secretKey:i,apiUrl:n,apiVersion:s,cookieToken:a,frontendApi:d,publishableKey:p,headerToken:f,loadSession:y,loadUser:h,loadOrganization:S}=t,{sid:m,org_id:g,sub:O}=e,{sessions:k,users:_,organizations:I}=te({apiKey:r,secretKey:i,apiUrl:n,apiVersion:s}),[w,T,P]=await Promise.all([y?k.getSession(m):Promise.resolve(void 0),h?_.getUser(O):Promise.resolve(void 0),S&&g?I.getOrganization({organizationId:g}):Promise.resolve(void 0)]),Be=rt(e,{apiKey:r,apiUrl:n,apiVersion:s,token:a||f||"",session:w,user:T,organization:P},{...t,status:"signed-in"});return{status:"signed-in",reason:null,message:null,frontendApi:d,publishableKey:p,isSignedIn:!0,isInterstitial:!1,isUnknown:!1,toAuth:()=>Be}}function C(t,e,r=""){let{frontendApi:i,publishableKey:n}=t;return{status:"signed-out",reason:e,message:r,frontendApi:i,publishableKey:n,isSignedIn:!1,isInterstitial:!1,isUnknown:!1,toAuth:()=>nt({...t,status:"signed-out",reason:e,message:r})}}function M(t,e,r=""){let{frontendApi:i,publishableKey:n}=t;return{status:"interstitial",reason:e,message:r,frontendApi:i,publishableKey:n,isSignedIn:!1,isInterstitial:!0,isUnknown:!1,toAuth:()=>null}}function ct(t,e,r=""){let{frontendApi:i,publishableKey:n}=t;return{status:"unknown",reason:e,message:r,frontendApi:i,publishableKey:n,isSignedIn:!1,isInterstitial:!1,isUnknown:!0,toAuth:()=>null}}function ze({originURL:t,host:e,forwardedHost:r,forwardedPort:i,forwardedProto:n}){if(n&&n!==t.protocol)return!0;let s=Zt(r||e);return s.port=i||s.port,s.port!==t.port||s.hostname!==t.hostname}function Zt(t){return new URL(`https://${t}`)}import{base64url as Ke}from"rfc4648";var er=2*1e3,We={RS256:"SHA-256",RS384:"SHA-384",RS512:"SHA-512",ES256:"SHA-256",ES384:"SHA-384",ES512:"SHA-512"},Me="RSASSA-PKCS1-v1_5",je="ECDSA",tr={RS256:Me,RS384:Me,RS512:Me,ES256:je,ES384:je,ES512:je},rr=Object.keys(We);async function nr(t,e){let{header:r,signature:i,raw:n}=t,a=new TextEncoder().encode([n.header,n.payload].join(".")),d=await N.crypto.subtle.importKey("jwk",e,{name:tr[r.alg],hash:We[r.alg]},!1,["verify"]);return N.crypto.subtle.verify("RSASSA-PKCS1-v1_5",d,i,a)}function Le(t){let e=(t||"").toString().split(".");if(e.length!==3)throw new l({reason:"token-invalid",message:"Invalid JWT form. A JWT consists of three parts separated by dots."});let[r,i,n]=e,s=new TextDecoder,a=JSON.parse(s.decode(Ke.parse(r,{loose:!0}))),d=JSON.parse(s.decode(Ke.parse(i,{loose:!0}))),p=Ke.parse(n,{loose:!0});return{header:a,payload:d,signature:p,raw:{header:r,payload:i,signature:n,text:t}}}async function pt(t,{audience:e,authorizedParties:r,clockSkewInSeconds:i=er,issuer:n,key:s}){let a=Le(t),{header:d,payload:p}=a,{typ:f,alg:y}=d;if(typeof f<"u"&&f!=="JWT")throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-invalid",message:`Invalid JWT type ${JSON.stringify(f)}. Expected "JWT".`});if(!We[y])throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-invalid-algorithm",message:`Invalid JWT algorithm ${JSON.stringify(y)}. Supported: ${rr}.`});let{azp:h,sub:S,aud:m,iss:g,iat:O,exp:k,nbf:_}=p;if(typeof S!="string")throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-verification-failed",message:`Subject claim (sub) is required and must be a string. Received ${JSON.stringify(S)}.`});if(typeof m=="string"){if(m!==e)throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-verification-failed",message:`Invalid JWT audience claim (aud) ${JSON.stringify(m)}. Expected "${e}".`})}else if(Array.isArray(m)&&m.length>0&&m.every(b=>typeof b=="string")&&!m.includes(e))throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-verification-failed",message:`Invalid JWT audience claim array (aud) ${JSON.stringify(m)}. Does not include "${e}".`});if(h&&r&&r.length>0&&!r.includes(h))throw new l({reason:"token-invalid-authorized-parties",message:`Invalid JWT Authorized party claim (azp) ${JSON.stringify(h)}. Expected "${r}".`});if(typeof n=="function"&&!n(g))throw new l({reason:"token-invalid-issuer",message:"Failed JWT issuer resolver. Make sure that the resolver returns a truthy value."});if(typeof n=="string"&&g&&g!==n)throw new l({reason:"token-invalid-issuer",message:`Invalid JWT issuer claim (iss) ${JSON.stringify(a.payload.iss)}. Expected "${n}".`});if(typeof k!="number")throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-verification-failed",message:`Invalid JWT expiry date claim (exp) ${JSON.stringify(k)}. Expected number.`});let I=new Date(Date.now()),w=new Date(0);if(w.setUTCSeconds(k),w.getTime()<=I.getTime()-i)throw new l({reason:"token-expired",message:`JWT is expired. Expiry date: ${w}, Current date: ${I}.`});if(_!==void 0){if(typeof _!="number")throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-verification-failed",message:`Invalid JWT not before date claim (nbf) ${JSON.stringify(_)}. Expected number.`});let b=new Date(0);if(b.setUTCSeconds(_),b.getTime()>I.getTime()+i)throw new l({reason:"token-not-active-yet",message:`JWT cannot be used prior to not before date claim (nbf). Not before date: ${b}; Current date: ${I};`})}if(O!==void 0){if(typeof O!="number")throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-verification-failed",message:`Invalid JWT issued at date claim (iat) ${JSON.stringify(O)}. Expected number.`});let b=new Date(0);if(b.setUTCSeconds(O),b.getTime()>I.getTime()+i)throw new l({reason:"token-not-active-yet",message:`JWT issued at date claim (iat) is in the future. Issued at date: ${b}; Current date: ${I};`})}let P;try{P=await nr(a,s)}catch(b){throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-verification-failed",message:`Error verifying JWT signature. ${b}`})}if(!P)throw new l({reason:"token-invalid-signature",message:"JWT signature is invalid."});return p}var Pe={},gt=0;function xe(t){return Pe[t]}function ft(t,e=1e3*60*60){Pe[t.kid]=t,gt=Date.now(),e>=0&&setTimeout(()=>{t?delete Pe[t.kid]:Pe={}},e)}var mt="local",sr="-----BEGIN PUBLIC KEY-----",or="-----END PUBLIC KEY-----",ar="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA",lr="IDAQAB";function yt(t){if(!xe(mt)){if(!t)throw new l({action:"Set the CLERK_JWT_KEY environment variable.",message:"Missing local JWK.",reason:"jwk-local-missing"});let e=t.replace(/(\r\n|\n|\r)/gm,"").replace(sr,"").replace(or,"").replace(ar,"").replace(lr,"").replace(/\+/g,"-").replace(/\//g,"_");ft({kid:"local",kty:"RSA",alg:"RS256",n:e,e:"AQAB"},-1)}return xe(mt)}async function Fe({apiKey:t,secretKey:e,apiUrl:r=v,apiVersion:i=R,issuer:n,kid:s,jwksCacheTtlInMs:a=1e3*60*60,skipJwksCache:d}){let p=!xe(s)&&cr();if(d||p){let y,h=e||t;if(h)y=()=>dr(r,h,i);else if(n)y=()=>ur(n);else throw new l({action:"Contact support@clerk.dev",message:"Failed to load JWKS from Clerk Backend or Frontend API.",reason:"jwk-remote-failed-to-load"});let{keys:S}=await se(y);if(!S||!S.length)throw new l({action:"Contact support@clerk.dev",message:"The JWKS endpoint did not contain any signing keys. Contact support@clerk.dev.",reason:"jwk-remote-failed-to-load"});S.forEach(m=>ft(m,a))}let f=xe(s);if(!f)throw new l({action:"Contact support@clerk.dev",message:`Unable to find a signing key in JWKS that matches kid='${s}'.`,reason:"jwk-remote-missing"});return f}async function ur(t){let e=new URL(t);e.pathname=o(e.pathname,".well-known/jwks.json");let r=await N.fetch(e.href);if(!r.ok)throw new l({action:"Contact support@clerk.dev",message:`Error loading Clerk JWKS from ${e.href} with code=${r.status}`,reason:"jwk-remote-failed-to-load"});return r.json()}async function dr(t,e,r){if(!e)throw new l({action:"Set the CLERK_SECRET_KEY or CLERK_API_KEY environment variable.",message:"Missing Clerk Secret Key or API Key. Go to https://dashboard.clerk.dev and get your key for your instance.",reason:"jwk-remote-failed-to-load"});let i=new URL(t);i.pathname=o(i.pathname,r,"/jwks");let n=await N.fetch(i.href,{headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"}});if(!n.ok)throw new l({action:"Contact support@clerk.dev",message:`Error loading Clerk JWKS from ${i.href} with code=${n.status}`,reason:"jwk-remote-failed-to-load"});return n.json()}function cr(){return Date.now()-gt>=300*1e3}async function ht(t,e){let{apiKey:r,secretKey:i,apiUrl:n,apiVersion:s,authorizedParties:a,clockSkewInSeconds:d,issuer:p,jwksCacheTtlInMs:f,jwtKey:y,skipJwksCache:h}=e,{header:S}=Le(t),{kid:m}=S,g;if(y)g=yt(y);else if(typeof p=="string")g=await Fe({issuer:p,kid:m,jwksCacheTtlInMs:f,skipJwksCache:h});else if(r||i)g=await Fe({apiKey:r,secretKey:i,apiUrl:n,apiVersion:s,kid:m,jwksCacheTtlInMs:f,skipJwksCache:h});else throw new l({action:"Set the CLERK_JWT_KEY environment variable.",message:"Failed to resolve JWK during verification.",reason:"jwk-failed-to-resolve"});return await pt(t,{authorizedParties:a,clockSkewInSeconds:d,key:g,issuer:p})}var bt=async t=>{let{apiKey:e,secretKey:r,userAgent:i}=t;if(Ie(r||e)&&!i?.startsWith("Mozilla/"))return C(t,"header-missing-non-browser")},St=async t=>{let{origin:e,host:r,forwardedHost:i,forwardedPort:n,forwardedProto:s}=t;if(e&&ze({originURL:new URL(e),host:r,forwardedHost:i,forwardedPort:n,forwardedProto:s}))return C(t,"header-missing-cors")},Ot=async t=>{let{apiKey:e,secretKey:r,clientUat:i}=t;if(Ie(r||e)&&!i)return M(t,"uat-missing")},kt=async t=>{let{apiKey:e,secretKey:r,referrer:i,host:n,forwardedHost:s,forwardedPort:a,forwardedProto:d}=t,p=i&&ze({originURL:new URL(i),host:n,forwardedHost:s,forwardedPort:a,forwardedProto:d});if(Ie(r||e)&&p)return M(t,"cross-origin-referrer")},_t=async t=>{let{apiKey:e,secretKey:r,clientUat:i,cookieToken:n}=t;if(it(r||e)&&!i&&!n)return C(t,"cookie-and-uat-missing")},It=async t=>{let{clientUat:e}=t;if(e==="0")return C(t,"standard-signed-out")},At=async t=>{let{clientUat:e,cookieToken:r}=t;if(e&&!r)return M(t,"cookie-missing")},wt=async t=>{let{headerToken:e}=t,r=await xt(t,e);return await qe(t,r)},Pt=async t=>{let{cookieToken:e,clientUat:r}=t,i=await xt(t,e),n=await qe(t,i),a=n.toAuth().sessionClaims.iat<Number.parseInt(r);return!r||a?M(t,"cookie-outdated"):n};async function De(t,e){for(let r of e){let i=await r(t);if(i)return i}return C(t,"unexpected-error")}async function xt(t,e){return ht(e,{...t,issuer:i=>i.startsWith("https://clerk.")||i.includes(".clerk.accounts")})}async function Tt(t){t.frontendApi=oe(t.publishableKey)?.frontendApi||t.frontendApi||"",t.apiUrl=t.apiUrl||v,t.apiVersion=t.apiVersion||R;async function e(){try{return await De(t,[wt])}catch(n){return i(n,"header")}}async function r(){try{return await De(t,[bt,St,Ot,kt,_t,It,At,Pt])}catch(n){return i(n,"cookie")}}function i(n,s){return n instanceof l?(n.tokenCarrier=s,["token-expired","token-not-active-yet"].includes(n.reason)?s==="header"?ct(t,n.reason,n.getFullMessage()):M(t,n.reason,n.getFullMessage()):C(t,n.reason,n.getFullMessage())):C(t,"unexpected-error",n.message)}return t.headerToken?e():r()}var Ve=t=>{let{frontendApi:e,isSignedIn:r,isInterstitial:i,reason:n,message:s,publishableKey:a}=t;return{frontendApi:e,isSignedIn:r,isInterstitial:i,reason:n,message:s,publishableKey:a}};function Jt(t){let{apiClient:e}=t,{apiKey:r="",secretKey:i="",jwtKey:n="",apiUrl:s=v,apiVersion:a=R,frontendApi:d="",publishableKey:p=""}=t.options;return{authenticateRequest:({apiKey:g,secretKey:O,frontendApi:k,publishableKey:_,jwtKey:I,...w})=>Tt({...w,apiKey:g||r,secretKey:O||i,apiUrl:s,apiVersion:a,frontendApi:k||d,publishableKey:_||p,jwtKey:I||n}),localInterstitial:Ue,remotePublicInterstitial:({frontendApi:g,publishableKey:O,...k})=>lt({...k,apiUrl:s,frontendApi:g||d,publishableKey:O||p}),remotePrivateInterstitial:()=>e.interstitial.getInterstitial(),remotePublicInterstitialUrl:Ae,debugRequestState:Ve}}function Ds(t){let e={...t},r=te(e),i=Jt({options:e,apiClient:r});return{...r,...i,__unstable_options:e}}export{j as AllowlistIdentifier,dt as AuthStatus,Ds as Clerk,W as Client,L as DeletedObject,F as Email,q as EmailAddress,D as ExternalAccount,U as IdentificationLink,V as Invitation,B as OauthAccessToken,Ye as ObjectType,z as Organization,G as OrganizationInvitation,H as OrganizationMembership,ne as OrganizationMembershipPublicUserData,K as PhoneNumber,$ as RedirectUrl,X as SMSMessage,E as Session,Y as SignInToken,Q as Token,ee as User,x as Verification,qt as constants,Jt as createAuthenticateRequest,Ve as debugRequestState,Le as decodeJwt,Xe as deserialize,nr as hasValidSignature,Ue as loadInterstitialFromLocal,et as prunePrivateMetadata,Mi as sanitizeAuthObject,rt as signedInAuthObject,nt as signedOutAuthObject,pt as verifyJwt,ht as verifyToken}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";var Kt=Object.create;var ae=Object.defineProperty;var Mt=Object.getOwnPropertyDescriptor;var jt=Object.getOwnPropertyNames;var Wt=Object.getPrototypeOf,Lt=Object.prototype.hasOwnProperty;var Ft=(t,e)=>{for(var r in e)ae(t,r,{get:e[r],enumerable:!0})},st=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of jt(e))!Lt.call(t,n)&&n!==r&&ae(t,n,{get:()=>e[n],enumerable:!(i=Mt(e,n))||i.enumerable});return t};var le=(t,e,r)=>(r=t!=null?Kt(Wt(t)):{},st(e||!t||!t.__esModule?ae(r,"default",{value:t,enumerable:!0}):r,t)),Dt=t=>st(ae({},"__esModule",{value:!0}),t);var wr={};Ft(wr,{AllowlistIdentifier:()=>M,AuthStatus:()=>Ge,Clerk:()=>Ar,Client:()=>j,DeletedObject:()=>W,Email:()=>L,EmailAddress:()=>E,ExternalAccount:()=>F,IdentificationLink:()=>v,Invitation:()=>D,OauthAccessToken:()=>V,ObjectType:()=>Me,Organization:()=>U,OrganizationInvitation:()=>B,OrganizationMembership:()=>G,OrganizationMembershipPublicUserData:()=>ee,PhoneNumber:()=>q,RedirectUrl:()=>$,SMSMessage:()=>Y,Session:()=>C,SignInToken:()=>H,Token:()=>X,User:()=>Q,Verification:()=>w,constants:()=>ut,createAuthenticateRequest:()=>nt,debugRequestState:()=>ve,decodeJwt:()=>Re,deserialize:()=>We,hasValidSignature:()=>_t,loadInterstitialFromLocal:()=>Te,prunePrivateMetadata:()=>Fe,sanitizeAuthObject:()=>ir,signedInAuthObject:()=>De,signedOutAuthObject:()=>Ve,verifyJwt:()=>Ze,verifyToken:()=>tt});module.exports=Dt(wr);var c=class{constructor(e){this.request=e}requireId(e){if(!e)throw new Error("A valid resource ID is required.")}};var Ue="/",Vt=new RegExp(Ue+"{1,}","g");function o(...t){return t.filter(e=>e).join(Ue).replace(Vt,Ue)}var qe="/allowlist_identifiers",ue=class extends c{async getAllowlistIdentifierList(){return this.request({method:"GET",path:qe})}async createAllowlistIdentifier(e){return this.request({method:"POST",path:qe,bodyParams:e})}async deleteAllowlistIdentifier(e){return this.requireId(e),this.request({method:"DELETE",path:o(qe,e)})}};var ze="/clients",de=class extends c{async getClientList(){return this.request({method:"GET",path:ze})}async getClient(e){return this.requireId(e),this.request({method:"GET",path:o(ze,e)})}verifyClient(e){return this.request({method:"POST",path:o(ze,"verify"),bodyParams:{token:e}})}};var ce="/email_addresses",pe=class extends c{async getEmailAddress(e){return this.requireId(e),this.request({method:"GET",path:o(ce,e)})}async createEmailAddress(e){return this.request({method:"POST",path:ce,bodyParams:e})}async updateEmailAddress(e,r={}){return this.requireId(e),this.request({method:"PATCH",path:o(ce,e),bodyParams:r})}async deleteEmailAddress(e){return this.requireId(e),this.request({method:"DELETE",path:o(ce,e)})}};var Bt="/emails",me=class extends c{async createEmail(e){return this.request({method:"POST",path:Bt,bodyParams:e})}};var ge=class extends c{async getInterstitial(){return this.request({path:"internal/interstitial",method:"GET",headerParams:{"Content-Type":"text/html"}})}};var Ke="/invitations",fe=class extends c{async getInvitationList(){return this.request({method:"GET",path:Ke})}async createInvitation(e){return this.request({method:"POST",path:Ke,bodyParams:e})}async revokeInvitation(e){return this.requireId(e),this.request({method:"POST",path:o(Ke,e,"revoke")})}};var A="/organizations",ye=class extends c{async getOrganizationList(e){return this.request({method:"GET",path:A,queryParams:e})}async createOrganization(e){return this.request({method:"POST",path:A,bodyParams:e})}async getOrganization(e){let r="organizationId"in e?e.organizationId:e.slug;return this.requireId(r),this.request({method:"GET",path:o(A,r)})}async updateOrganization(e,r){return this.requireId(e),this.request({method:"PATCH",path:o(A,e),bodyParams:r})}async updateOrganizationMetadata(e,r){return this.requireId(e),this.request({method:"PATCH",path:o(A,e,"metadata"),bodyParams:r})}async deleteOrganization(e){return this.request({method:"DELETE",path:o(A,e)})}async getOrganizationMembershipList(e){let{organizationId:r,limit:i,offset:n}=e;return this.requireId(r),this.request({method:"GET",path:o(A,r,"memberships"),queryParams:{limit:i,offset:n}})}async createOrganizationMembership(e){let{organizationId:r,userId:i,role:n}=e;return this.requireId(r),this.request({method:"POST",path:o(A,r,"memberships"),bodyParams:{userId:i,role:n}})}async updateOrganizationMembership(e){let{organizationId:r,userId:i,role:n}=e;return this.requireId(r),this.request({method:"PATCH",path:o(A,r,"memberships",i),bodyParams:{role:n}})}async updateOrganizationMembershipMetadata(e){let{organizationId:r,userId:i,publicMetadata:n,privateMetadata:s}=e;return this.request({method:"PATCH",path:o(A,r,"memberships",i,"metadata"),bodyParams:{publicMetadata:n,privateMetadata:s}})}async deleteOrganizationMembership(e){let{organizationId:r,userId:i}=e;return this.requireId(r),this.request({method:"DELETE",path:o(A,r,"memberships",i)})}async getPendingOrganizationInvitationList(e){let{organizationId:r,limit:i,offset:n}=e;return this.requireId(r),this.request({method:"GET",path:o(A,r,"invitations","pending"),queryParams:{limit:i,offset:n}})}async createOrganizationInvitation(e){let{organizationId:r,...i}=e;return this.requireId(r),this.request({method:"POST",path:o(A,r,"invitations"),bodyParams:{...i}})}async revokeOrganizationInvitation(e){let{organizationId:r,invitationId:i,requestingUserId:n}=e;return this.requireId(r),this.request({method:"POST",path:o(A,r,"invitations",i,"revoke"),bodyParams:{requestingUserId:n}})}};var he="/phone_numbers",be=class extends c{async getPhoneNumber(e){return this.requireId(e),this.request({method:"GET",path:o(he,e)})}async createPhoneNumber(e){return this.request({method:"POST",path:he,bodyParams:e})}async updatePhoneNumber(e,r={}){return this.requireId(e),this.request({method:"PATCH",path:o(he,e),bodyParams:r})}async deletePhoneNumber(e){return this.requireId(e),this.request({method:"DELETE",path:o(he,e)})}};var Se="/redirect_urls",Oe=class extends c{async getRedirectUrlList(){return this.request({method:"GET",path:Se})}async getRedirectUrl(e){return this.requireId(e),this.request({method:"GET",path:o(Se,e)})}async createRedirectUrl(e){return this.request({method:"POST",path:Se,bodyParams:e})}async deleteRedirectUrl(e){return this.requireId(e),this.request({method:"DELETE",path:o(Se,e)})}};var ne="/sessions",ke=class extends c{constructor(){super(...arguments);this.getSessionList=async r=>this.request({method:"GET",path:ne,queryParams:r});this.getSession=async r=>(this.requireId(r),this.request({method:"GET",path:o(ne,r)}));this.revokeSession=async r=>(this.requireId(r),this.request({method:"POST",path:o(ne,r,"revoke")}));this.verifySession=async(r,i)=>(this.requireId(r),this.request({method:"POST",path:o(ne,r,"verify"),bodyParams:{token:i}}));this.getToken=async(r,i)=>(this.requireId(r),(await this.request({method:"POST",path:o(ne,r,"tokens",i||"")})).jwt)}};var ot="/sign_in_tokens",_e=class extends c{async createSignInToken(e){return this.request({method:"POST",path:ot,bodyParams:e})}async revokeSignInToken(e){return this.requireId(e),this.request({method:"POST",path:o(ot,e,"revoke")})}};var Gt="/sms_messages",Ie=class extends c{async createSMSMessage(e){return this.request({method:"POST",path:Gt,bodyParams:e})}};var J="/users",Ae=class extends c{async getUserList(e={}){return this.request({method:"GET",path:J,queryParams:e})}async getUser(e){return this.requireId(e),this.request({method:"GET",path:o(J,e)})}async createUser(e){return this.request({method:"POST",path:J,bodyParams:e})}async updateUser(e,r={}){return this.requireId(e),this.request({method:"PATCH",path:o(J,e),bodyParams:r})}async updateUserMetadata(e,r){return this.requireId(e),this.request({method:"PATCH",path:o(J,e,"metadata"),bodyParams:r})}async deleteUser(e){return this.requireId(e),this.request({method:"DELETE",path:o(J,e)})}async getCount(e={}){return this.request({method:"GET",path:o(J,"count"),queryParams:e})}async getUserOauthAccessToken(e,r){return this.requireId(e),this.request({method:"GET",path:o(J,e,"oauth_access_tokens",r)})}async disableUserMFA(e){return this.requireId(e),this.request({method:"DELETE",path:o(J,e,"mfa")})}async getOrganizationMembershipList(e){let{userId:r,limit:i,offset:n}=e;return this.requireId(r),this.request({method:"GET",path:o(J,r,"organization_memberships"),queryParams:{limit:i,offset:n}})}};var pt=le(require("deepmerge")),Le=le(require("snakecase-keys"));var K="https://api.clerk.dev",R="v1",at="@clerk/backend";var $t={AuthStatus:"__clerkAuthStatus"},Ht={Session:"__session",ClientUat:"__client_uat"},lt={AuthStatus:"x-clerk-auth-status",AuthReason:"x-clerk-auth-reason",AuthMessage:"x-clerk-auth-message",Authorization:"authorization",ForwardedPort:"x-forwarded-port",ForwardedHost:"x-forwarded-host",Referrer:"referer",UserAgent:"user-agent",Origin:"origin",Host:"host"},Yt={AuthStatus:lt.AuthStatus},ut={Attributes:$t,Cookies:Ht,Headers:lt,SearchParams:Yt};var dt=le(require("#crypto")),ct=le(require("#fetch")),Xt=ct.default.bind(globalThis),Qt={crypto:dt.default,fetch:Xt},N=Qt;var M=class{constructor(e,r,i,n,s){this.id=e;this.identifier=r;this.createdAt=i;this.updatedAt=n;this.invitationId=s}static fromJSON(e){return new M(e.id,e.identifier,e.created_at,e.updated_at,e.invitation_id)}};var C=class{constructor(e,r,i,n,s,a,d,p,f){this.id=e;this.clientId=r;this.userId=i;this.status=n;this.lastActiveAt=s;this.expireAt=a;this.abandonAt=d;this.createdAt=p;this.updatedAt=f}static fromJSON(e){return new C(e.id,e.client_id,e.user_id,e.status,e.last_active_at,e.expire_at,e.abandon_at,e.created_at,e.updated_at)}};var j=class{constructor(e,r,i,n,s,a,d,p){this.id=e;this.sessionIds=r;this.sessions=i;this.signInId=n;this.signUpId=s;this.lastActiveSessionId=a;this.createdAt=d;this.updatedAt=p}static fromJSON(e){return new j(e.id,e.session_ids,e.sessions.map(r=>C.fromJSON(r)),e.sign_in_id,e.sign_up_id,e.last_active_session_id,e.created_at,e.updated_at)}};var W=class{constructor(e,r,i,n){this.object=e;this.id=r;this.slug=i;this.deleted=n}static fromJSON(e){return new W(e.object,e.id||null,e.slug||null,e.deleted)}};var L=class{constructor(e,r,i,n,s,a,d){this.id=e;this.fromEmailName=r;this.emailAddressId=i;this.toEmailAddress=n;this.subject=s;this.body=a;this.status=d}static fromJSON(e){return new L(e.id,e.from_email_name,e.email_address_id,e.to_email_address,e.subject,e.body,e.status)}};var v=class{constructor(e,r){this.id=e;this.type=r}static fromJSON(e){return new v(e.id,e.type)}};var w=class{constructor(e,r,i=null,n=null,s=null,a=null){this.status=e;this.strategy=r;this.externalVerificationRedirectURL=i;this.attempts=n;this.expireAt=s;this.nonce=a}static fromJSON(e){return new w(e.status,e.strategy,e.external_verification_redirect_url?new URL(e.external_verification_redirect_url):null,e.attempts,e.expire_at,e.nonce)}};var E=class{constructor(e,r,i,n){this.id=e;this.emailAddress=r;this.verification=i;this.linkedTo=n}static fromJSON(e){return new E(e.id,e.email_address,e.verification&&w.fromJSON(e.verification),e.linked_to.map(r=>v.fromJSON(r)))}};var F=class{constructor(e,r,i,n,s,a,d,p,f,y,h={},S,m){this.id=e;this.provider=r;this.identificationId=i;this.externalId=n;this.approvedScopes=s;this.emailAddress=a;this.firstName=d;this.lastName=p;this.picture=f;this.username=y;this.publicMetadata=h;this.label=S;this.verification=m}static fromJSON(e){return new F(e.id,e.provider,e.identification_id,e.provider_user_id,e.approved_scopes,e.email_address,e.first_name,e.last_name,e.avatar_url,e.username,e.public_metadata,e.label,e.verification&&w.fromJSON(e.verification))}};var D=class{constructor(e,r,i,n,s,a){this.id=e;this.emailAddress=r;this.publicMetadata=i;this.createdAt=n;this.updatedAt=s;this.revoked=a}static fromJSON(e){return new D(e.id,e.email_address,e.public_metadata,e.created_at,e.updated_at,e.revoked)}};var Me=(u=>(u.AllowlistIdentifier="allowlist_identifier",u.Client="client",u.Email="email",u.EmailAddress="email_address",u.ExternalAccount="external_account",u.FacebookAccount="facebook_account",u.GoogleAccount="google_account",u.Invitation="invitation",u.OauthAccessToken="oauth_access_token",u.Organization="organization",u.OrganizationInvitation="organization_invitation",u.OrganizationMembership="organization_membership",u.PhoneNumber="phone_number",u.RedirectUrl="redirect_url",u.Session="session",u.SignInAttempt="sign_in_attempt",u.SignInToken="sign_in_token",u.SignUpAttempt="sign_up_attempt",u.SmsMessage="sms_message",u.User="user",u.Web3Wallet="web3_wallet",u.Token="token",u.TotalCount="total_count",u))(Me||{});var V=class{constructor(e,r,i={},n,s,a){this.provider=e;this.token=r;this.publicMetadata=i;this.label=n;this.scopes=s;this.tokenSecret=a}static fromJSON(e){return new V(e.provider,e.token,e.public_metadata,e.label,e.scopes,e.token_secret)}};var U=class{constructor(e,r,i,n,s,a,d={},p={}){this.id=e;this.name=r;this.slug=i;this.logoUrl=n;this.createdAt=s;this.updatedAt=a;this.publicMetadata=d;this.privateMetadata=p}static fromJSON(e){return new U(e.id,e.name,e.slug,e.logo_url,e.created_at,e.updated_at,e.public_metadata,e.private_metadata)}};var B=class{constructor(e,r,i,n,s,a,d){this.id=e;this.emailAddress=r;this.role=i;this.organizationId=n;this.createdAt=s;this.updatedAt=a;this.status=d}static fromJSON(e){return new B(e.id,e.email_address,e.role,e.organization_id,e.created_at,e.updated_at,e.status)}};var G=class{constructor(e,r,i={},n={},s,a,d,p){this.id=e;this.role=r;this.publicMetadata=i;this.privateMetadata=n;this.createdAt=s;this.updatedAt=a;this.organization=d;this.publicUserData=p}static fromJSON(e){return new G(e.id,e.role,e.public_metadata,e.private_metadata,e.created_at,e.updated_at,U.fromJSON(e.organization),ee.fromJSON(e.public_user_data))}},ee=class{constructor(e,r,i,n,s){this.identifier=e;this.firstName=r;this.lastName=i;this.profileImageUrl=n;this.userId=s}static fromJSON(e){return new ee(e.identifier,e.first_name,e.last_name,e.profile_image_url,e.user_id)}};var q=class{constructor(e,r,i,n,s,a){this.id=e;this.phoneNumber=r;this.reservedForSecondFactor=i;this.defaultSecondFactor=n;this.verification=s;this.linkedTo=a}static fromJSON(e){return new q(e.id,e.phone_number,e.reserved_for_second_factor,e.default_second_factor,e.verification&&w.fromJSON(e.verification),e.linked_to.map(r=>v.fromJSON(r)))}};var $=class{constructor(e,r,i,n){this.id=e;this.url=r;this.createdAt=i;this.updatedAt=n}static fromJSON(e){return new $(e.id,e.url,e.created_at,e.updated_at)}};var H=class{constructor(e,r,i,n,s,a){this.id=e;this.userId=r;this.token=i;this.status=n;this.createdAt=s;this.updatedAt=a}static fromJSON(e){return new H(e.id,e.user_id,e.token,e.status,e.created_at,e.updated_at)}};var Y=class{constructor(e,r,i,n,s,a){this.id=e;this.fromPhoneNumber=r;this.toPhoneNumber=i;this.message=n;this.status=s;this.phoneNumberId=a}static fromJSON(e){return new Y(e.id,e.from_phone_number,e.to_phone_number,e.message,e.status,e.phone_number_id)}};var X=class{constructor(e){this.jwt=e}static fromJSON(e){return new X(e.jwt)}};var te=class{constructor(e,r,i){this.id=e;this.web3Wallet=r;this.verification=i}static fromJSON(e){return new te(e.id,e.web3_wallet,e.verification&&w.fromJSON(e.verification))}};var Q=class{constructor(e,r,i,n,s,a,d,p,f,y,h,S,m,g,O,k,_,I,P,T={},x={},b={},u=[],Ee=[],it=[],Pr=[]){this.id=e;this.passwordEnabled=r;this.totpEnabled=i;this.backupCodeEnabled=n;this.twoFactorEnabled=s;this.banned=a;this.createdAt=d;this.updatedAt=p;this.profileImageUrl=f;this.gender=y;this.birthday=h;this.primaryEmailAddressId=S;this.primaryPhoneNumberId=m;this.primaryWeb3WalletId=g;this.lastSignInAt=O;this.externalId=k;this.username=_;this.firstName=I;this.lastName=P;this.publicMetadata=T;this.privateMetadata=x;this.unsafeMetadata=b;this.emailAddresses=u;this.phoneNumbers=Ee;this.web3Wallets=it;this.externalAccounts=Pr}static fromJSON(e){return new Q(e.id,e.password_enabled,e.totp_enabled,e.backup_code_enabled,e.two_factor_enabled,e.banned,e.created_at,e.updated_at,e.profile_image_url,e.gender,e.birthday,e.primary_email_address_id,e.primary_phone_number_id,e.primary_web3_wallet_id,e.last_sign_in_at,e.external_id,e.username,e.first_name,e.last_name,e.public_metadata,e.private_metadata,e.unsafe_metadata,(e.email_addresses||[]).map(r=>E.fromJSON(r)),(e.phone_numbers||[]).map(r=>q.fromJSON(r)),(e.web3_wallets||[]).map(r=>te.fromJSON(r)),(e.external_accounts||[]).map(r=>F.fromJSON(r)))}};function We(t){return Array.isArray(t)?t.map(e=>je(e)):Zt(t)?t.data.map(e=>je(e)):je(t)}function Zt(t){return t.data!==void 0}function er(t){return t.total_count}function je(t){if(typeof t!="string"&&"object"in t&&"deleted"in t)return W.fromJSON(t);switch(t.object){case"allowlist_identifier":return M.fromJSON(t);case"client":return j.fromJSON(t);case"email_address":return E.fromJSON(t);case"email":return L.fromJSON(t);case"invitation":return D.fromJSON(t);case"oauth_access_token":return V.fromJSON(t);case"organization":return U.fromJSON(t);case"organization_invitation":return B.fromJSON(t);case"organization_membership":return G.fromJSON(t);case"phone_number":return q.fromJSON(t);case"redirect_url":return $.fromJSON(t);case"sign_in_token":return H.fromJSON(t);case"session":return C.fromJSON(t);case"sms_message":return Y.fromJSON(t);case"token":return X.fromJSON(t);case"total_count":return er(t);case"user":return Q.fromJSON(t);default:return t}}var tr=t=>async(...e)=>{let{data:r,errors:i,status:n,statusText:s}=await t(...e);if(i===null)return r;throw new ie(s||"",{data:i,status:n||""})};function mt(t){return tr(async r=>{let{apiKey:i,secretKey:n,apiUrl:s=K,apiVersion:a=R,userAgent:d=at,httpOptions:p={}}=t,{path:f,method:y,queryParams:h,headerParams:S,bodyParams:m}=r,g=n||i;if(!g)throw Error("Missing Clerk Secret Key or API Key. Go to https://dashboard.clerk.dev and get your key for your instance.");let O=o(s,a,f),k=new URL(O);if(h){let x=(0,Le.default)({...h});for(let[b,u]of Object.entries(x))u&&[u].flat().forEach(Ee=>k.searchParams.append(b,Ee))}let _={Authorization:`Bearer ${g}`,"Content-Type":"application/json","Clerk-Backend-SDK":d,...S},P=y!=="GET"&&m&&Object.keys(m).length>0?{body:JSON.stringify((0,Le.default)(m,{deep:!1}))}:null,T;try{T=await N.fetch(k.href,(0,pt.default)(p,{method:y,headers:_,...P}));let b=await(_&&_["Content-Type"]==="application/json"?T.json():T.text());if(!T.ok)throw b;return{data:We(b),errors:null}}catch(x){return x instanceof Error?{data:null,errors:[{code:"unexpected_error",message:x.message||"Unexpected error"}]}:{data:null,errors:rr(x),status:T?.status,statusText:T?.statusText}}})}function rr(t){if(!!t&&typeof t=="object"&&"errors"in t){let e=t.errors;return e.length>0?e.map(nr):[]}return[]}function nr(t){return{code:t.code,message:t.message,longMessage:t.long_message,meta:{paramName:t?.meta?.param_name,sessionId:t?.meta?.session_id}}}var ie=class extends Error{constructor(r,{data:i,status:n}){super(r);Object.setPrototypeOf(this,ie.prototype),this.clerkError=!0,this.message=r,this.status=n,this.errors=i}};function re(t){let e=mt(t);return{allowlistIdentifiers:new ue(e),clients:new de(e),emailAddresses:new pe(e),emails:new me(e),interstitial:new ge(e),invitations:new fe(e),organizations:new ye(e),phoneNumbers:new be(e),redirectUrls:new Oe(e),sessions:new ke(e),signInTokens:new _e(e),smsMessages:new Ie(e),users:new Ae(e)}}var gt=t=>()=>{let e={...t};return e.apiKey=(e.apiKey||"").substring(0,7),e.jwtKey=(e.jwtKey||"").substring(0,7),{...e}};function De(t,e,r){let{act:i,sid:n,org_id:s,org_role:a,org_slug:d,sub:p}=t,{apiKey:f,secretKey:y,apiUrl:h,apiVersion:S,token:m,session:g,user:O,organization:k}=e,{sessions:_}=re({apiKey:f,secretKey:y,apiUrl:h,apiVersion:S}),I=sr({sessionId:n,sessionToken:m,fetcher:(...P)=>_.getToken(...P)});return{actor:i,sessionClaims:t,sessionId:n,session:g,userId:p,user:O,orgId:s,orgRole:a,orgSlug:d,organization:k,getToken:I,debug:gt(r)}}function Ve(t){return{sessionClaims:null,sessionId:null,session:null,userId:null,user:null,actor:null,orgId:null,orgRole:null,orgSlug:null,organization:null,getToken:()=>Promise.resolve(null),debug:gt(t)}}function Fe(t){return t&&(delete t.privateMetadata,delete t.private_metadata),t}function ir(t){let e=t.user?{...t.user}:t.user,r=t.organization?{...t.organization}:t.organization;return Fe(e),Fe(r),{...t,user:e,organization:r}}var sr=t=>{let{fetcher:e,sessionToken:r,sessionId:i}=t||{};return async(n={})=>i?n.template?e(i,n.template):r:null};function or(t){return new Promise(e=>setTimeout(e,t))}var ar=5;async function se(t,e=1,r=ar){try{return await t()}catch(i){if(e>=r)throw i;return await or(2**e*100),se(t,e+1)}}function we(t){return t.startsWith("test_")||t.startsWith("sk_test_")}function ft(t){return t.startsWith("live_")||t.startsWith("sk_live_")}function yt(t){return t.endsWith(".lclstage.dev")||t.endsWith(".stgstage.dev")||t.endsWith(".clerkstage.dev")||t.endsWith(".accountsstage.dev")}var ht="pk_live_",lr="pk_test_";function oe(t){if(t=t||"",!ur(t))return null;let e=t.startsWith(ht)?"production":"development",r=bt(t.split("_")[2]);return r.endsWith("$")?(r=r.slice(0,-1),{instanceType:e,frontendApi:r}):null}function ur(t){t=t||"";let e=t.startsWith(ht)||t.startsWith(lr),r=bt(t.split("_")[2]||"").endsWith("$");return e&&r}var bt=t=>typeof atob<"u"&&typeof atob=="function"?atob(t):typeof Buffer<"u"?new Buffer(t,"base64").toString():t;var l=class extends Error{constructor({action:r,message:i,reason:n}){super(i);Object.setPrototypeOf(this,l.prototype),this.reason=n,this.message=i,this.action=r}getFullMessage(){return`${[this.message,this.action].filter(r=>r).join(" ")} (reason=${this.reason}, token-carrier=${this.tokenCarrier})`}};function Te(t){let{debugData:e,frontendApi:r,pkgVersion:i,publishableKey:n}=t;return` | ||
"use strict";var Kt=Object.create;var ae=Object.defineProperty;var Mt=Object.getOwnPropertyDescriptor;var jt=Object.getOwnPropertyNames;var Wt=Object.getPrototypeOf,Lt=Object.prototype.hasOwnProperty;var Ft=(t,e)=>{for(var r in e)ae(t,r,{get:e[r],enumerable:!0})},st=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of jt(e))!Lt.call(t,n)&&n!==r&&ae(t,n,{get:()=>e[n],enumerable:!(i=Mt(e,n))||i.enumerable});return t};var le=(t,e,r)=>(r=t!=null?Kt(Wt(t)):{},st(e||!t||!t.__esModule?ae(r,"default",{value:t,enumerable:!0}):r,t)),Dt=t=>st(ae({},"__esModule",{value:!0}),t);var wr={};Ft(wr,{AllowlistIdentifier:()=>M,AuthStatus:()=>Ge,Clerk:()=>Ar,Client:()=>j,DeletedObject:()=>W,Email:()=>L,EmailAddress:()=>E,ExternalAccount:()=>F,IdentificationLink:()=>v,Invitation:()=>D,OauthAccessToken:()=>V,ObjectType:()=>Me,Organization:()=>U,OrganizationInvitation:()=>B,OrganizationMembership:()=>G,OrganizationMembershipPublicUserData:()=>ee,PhoneNumber:()=>q,RedirectUrl:()=>H,SMSMessage:()=>Y,Session:()=>C,SignInToken:()=>$,Token:()=>X,User:()=>Q,Verification:()=>w,constants:()=>ut,createAuthenticateRequest:()=>nt,debugRequestState:()=>ve,decodeJwt:()=>Re,deserialize:()=>We,hasValidSignature:()=>_t,loadInterstitialFromLocal:()=>Te,prunePrivateMetadata:()=>Fe,sanitizeAuthObject:()=>ir,signedInAuthObject:()=>De,signedOutAuthObject:()=>Ve,verifyJwt:()=>Ze,verifyToken:()=>tt});module.exports=Dt(wr);var c=class{constructor(e){this.request=e}requireId(e){if(!e)throw new Error("A valid resource ID is required.")}};var Ue="/",Vt=new RegExp(Ue+"{1,}","g");function o(...t){return t.filter(e=>e).join(Ue).replace(Vt,Ue)}var qe="/allowlist_identifiers",ue=class extends c{async getAllowlistIdentifierList(){return this.request({method:"GET",path:qe})}async createAllowlistIdentifier(e){return this.request({method:"POST",path:qe,bodyParams:e})}async deleteAllowlistIdentifier(e){return this.requireId(e),this.request({method:"DELETE",path:o(qe,e)})}};var ze="/clients",de=class extends c{async getClientList(){return this.request({method:"GET",path:ze})}async getClient(e){return this.requireId(e),this.request({method:"GET",path:o(ze,e)})}verifyClient(e){return this.request({method:"POST",path:o(ze,"verify"),bodyParams:{token:e}})}};var ce="/email_addresses",pe=class extends c{async getEmailAddress(e){return this.requireId(e),this.request({method:"GET",path:o(ce,e)})}async createEmailAddress(e){return this.request({method:"POST",path:ce,bodyParams:e})}async updateEmailAddress(e,r={}){return this.requireId(e),this.request({method:"PATCH",path:o(ce,e),bodyParams:r})}async deleteEmailAddress(e){return this.requireId(e),this.request({method:"DELETE",path:o(ce,e)})}};var Bt="/emails",me=class extends c{async createEmail(e){return this.request({method:"POST",path:Bt,bodyParams:e})}};var ge=class extends c{async getInterstitial(){return this.request({path:"internal/interstitial",method:"GET",headerParams:{"Content-Type":"text/html"}})}};var Ke="/invitations",fe=class extends c{async getInvitationList(){return this.request({method:"GET",path:Ke})}async createInvitation(e){return this.request({method:"POST",path:Ke,bodyParams:e})}async revokeInvitation(e){return this.requireId(e),this.request({method:"POST",path:o(Ke,e,"revoke")})}};var A="/organizations",ye=class extends c{async getOrganizationList(e){return this.request({method:"GET",path:A,queryParams:e})}async createOrganization(e){return this.request({method:"POST",path:A,bodyParams:e})}async getOrganization(e){let r="organizationId"in e?e.organizationId:e.slug;return this.requireId(r),this.request({method:"GET",path:o(A,r)})}async updateOrganization(e,r){return this.requireId(e),this.request({method:"PATCH",path:o(A,e),bodyParams:r})}async updateOrganizationMetadata(e,r){return this.requireId(e),this.request({method:"PATCH",path:o(A,e,"metadata"),bodyParams:r})}async deleteOrganization(e){return this.request({method:"DELETE",path:o(A,e)})}async getOrganizationMembershipList(e){let{organizationId:r,limit:i,offset:n}=e;return this.requireId(r),this.request({method:"GET",path:o(A,r,"memberships"),queryParams:{limit:i,offset:n}})}async createOrganizationMembership(e){let{organizationId:r,userId:i,role:n}=e;return this.requireId(r),this.request({method:"POST",path:o(A,r,"memberships"),bodyParams:{userId:i,role:n}})}async updateOrganizationMembership(e){let{organizationId:r,userId:i,role:n}=e;return this.requireId(r),this.request({method:"PATCH",path:o(A,r,"memberships",i),bodyParams:{role:n}})}async updateOrganizationMembershipMetadata(e){let{organizationId:r,userId:i,publicMetadata:n,privateMetadata:s}=e;return this.request({method:"PATCH",path:o(A,r,"memberships",i,"metadata"),bodyParams:{publicMetadata:n,privateMetadata:s}})}async deleteOrganizationMembership(e){let{organizationId:r,userId:i}=e;return this.requireId(r),this.request({method:"DELETE",path:o(A,r,"memberships",i)})}async getPendingOrganizationInvitationList(e){let{organizationId:r,limit:i,offset:n}=e;return this.requireId(r),this.request({method:"GET",path:o(A,r,"invitations","pending"),queryParams:{limit:i,offset:n}})}async createOrganizationInvitation(e){let{organizationId:r,...i}=e;return this.requireId(r),this.request({method:"POST",path:o(A,r,"invitations"),bodyParams:{...i}})}async revokeOrganizationInvitation(e){let{organizationId:r,invitationId:i,requestingUserId:n}=e;return this.requireId(r),this.request({method:"POST",path:o(A,r,"invitations",i,"revoke"),bodyParams:{requestingUserId:n}})}};var he="/phone_numbers",be=class extends c{async getPhoneNumber(e){return this.requireId(e),this.request({method:"GET",path:o(he,e)})}async createPhoneNumber(e){return this.request({method:"POST",path:he,bodyParams:e})}async updatePhoneNumber(e,r={}){return this.requireId(e),this.request({method:"PATCH",path:o(he,e),bodyParams:r})}async deletePhoneNumber(e){return this.requireId(e),this.request({method:"DELETE",path:o(he,e)})}};var Se="/redirect_urls",Oe=class extends c{async getRedirectUrlList(){return this.request({method:"GET",path:Se})}async getRedirectUrl(e){return this.requireId(e),this.request({method:"GET",path:o(Se,e)})}async createRedirectUrl(e){return this.request({method:"POST",path:Se,bodyParams:e})}async deleteRedirectUrl(e){return this.requireId(e),this.request({method:"DELETE",path:o(Se,e)})}};var ne="/sessions",ke=class extends c{constructor(){super(...arguments);this.getSessionList=async r=>this.request({method:"GET",path:ne,queryParams:r});this.getSession=async r=>(this.requireId(r),this.request({method:"GET",path:o(ne,r)}));this.revokeSession=async r=>(this.requireId(r),this.request({method:"POST",path:o(ne,r,"revoke")}));this.verifySession=async(r,i)=>(this.requireId(r),this.request({method:"POST",path:o(ne,r,"verify"),bodyParams:{token:i}}));this.getToken=async(r,i)=>(this.requireId(r),(await this.request({method:"POST",path:o(ne,r,"tokens",i||"")})).jwt)}};var ot="/sign_in_tokens",_e=class extends c{async createSignInToken(e){return this.request({method:"POST",path:ot,bodyParams:e})}async revokeSignInToken(e){return this.requireId(e),this.request({method:"POST",path:o(ot,e,"revoke")})}};var Gt="/sms_messages",Ie=class extends c{async createSMSMessage(e){return this.request({method:"POST",path:Gt,bodyParams:e})}};var J="/users",Ae=class extends c{async getUserList(e={}){return this.request({method:"GET",path:J,queryParams:e})}async getUser(e){return this.requireId(e),this.request({method:"GET",path:o(J,e)})}async createUser(e){return this.request({method:"POST",path:J,bodyParams:e})}async updateUser(e,r={}){return this.requireId(e),this.request({method:"PATCH",path:o(J,e),bodyParams:r})}async updateUserMetadata(e,r){return this.requireId(e),this.request({method:"PATCH",path:o(J,e,"metadata"),bodyParams:r})}async deleteUser(e){return this.requireId(e),this.request({method:"DELETE",path:o(J,e)})}async getCount(e={}){return this.request({method:"GET",path:o(J,"count"),queryParams:e})}async getUserOauthAccessToken(e,r){return this.requireId(e),this.request({method:"GET",path:o(J,e,"oauth_access_tokens",r)})}async disableUserMFA(e){return this.requireId(e),this.request({method:"DELETE",path:o(J,e,"mfa")})}async getOrganizationMembershipList(e){let{userId:r,limit:i,offset:n}=e;return this.requireId(r),this.request({method:"GET",path:o(J,r,"organization_memberships"),queryParams:{limit:i,offset:n}})}};var pt=le(require("deepmerge")),Le=le(require("snakecase-keys"));var K="https://api.clerk.dev",R="v1",at="@clerk/backend";var Ht={AuthStatus:"__clerkAuthStatus"},$t={Session:"__session",ClientUat:"__client_uat"},lt={AuthStatus:"x-clerk-auth-status",AuthReason:"x-clerk-auth-reason",AuthMessage:"x-clerk-auth-message",Authorization:"authorization",ForwardedPort:"x-forwarded-port",ForwardedHost:"x-forwarded-host",Referrer:"referer",UserAgent:"user-agent",Origin:"origin",Host:"host"},Yt={AuthStatus:lt.AuthStatus},ut={Attributes:Ht,Cookies:$t,Headers:lt,SearchParams:Yt};var dt=le(require("#crypto")),ct=le(require("#fetch")),Xt=ct.default.bind(globalThis),Qt={crypto:dt.default,fetch:Xt},N=Qt;var M=class{constructor(e,r,i,n,s){this.id=e;this.identifier=r;this.createdAt=i;this.updatedAt=n;this.invitationId=s}static fromJSON(e){return new M(e.id,e.identifier,e.created_at,e.updated_at,e.invitation_id)}};var C=class{constructor(e,r,i,n,s,a,d,p,f){this.id=e;this.clientId=r;this.userId=i;this.status=n;this.lastActiveAt=s;this.expireAt=a;this.abandonAt=d;this.createdAt=p;this.updatedAt=f}static fromJSON(e){return new C(e.id,e.client_id,e.user_id,e.status,e.last_active_at,e.expire_at,e.abandon_at,e.created_at,e.updated_at)}};var j=class{constructor(e,r,i,n,s,a,d,p){this.id=e;this.sessionIds=r;this.sessions=i;this.signInId=n;this.signUpId=s;this.lastActiveSessionId=a;this.createdAt=d;this.updatedAt=p}static fromJSON(e){return new j(e.id,e.session_ids,e.sessions.map(r=>C.fromJSON(r)),e.sign_in_id,e.sign_up_id,e.last_active_session_id,e.created_at,e.updated_at)}};var W=class{constructor(e,r,i,n){this.object=e;this.id=r;this.slug=i;this.deleted=n}static fromJSON(e){return new W(e.object,e.id||null,e.slug||null,e.deleted)}};var L=class{constructor(e,r,i,n,s,a,d){this.id=e;this.fromEmailName=r;this.emailAddressId=i;this.toEmailAddress=n;this.subject=s;this.body=a;this.status=d}static fromJSON(e){return new L(e.id,e.from_email_name,e.email_address_id,e.to_email_address,e.subject,e.body,e.status)}};var v=class{constructor(e,r){this.id=e;this.type=r}static fromJSON(e){return new v(e.id,e.type)}};var w=class{constructor(e,r,i=null,n=null,s=null,a=null){this.status=e;this.strategy=r;this.externalVerificationRedirectURL=i;this.attempts=n;this.expireAt=s;this.nonce=a}static fromJSON(e){return new w(e.status,e.strategy,e.external_verification_redirect_url?new URL(e.external_verification_redirect_url):null,e.attempts,e.expire_at,e.nonce)}};var E=class{constructor(e,r,i,n){this.id=e;this.emailAddress=r;this.verification=i;this.linkedTo=n}static fromJSON(e){return new E(e.id,e.email_address,e.verification&&w.fromJSON(e.verification),e.linked_to.map(r=>v.fromJSON(r)))}};var F=class{constructor(e,r,i,n,s,a,d,p,f,y,h={},S,m){this.id=e;this.provider=r;this.identificationId=i;this.externalId=n;this.approvedScopes=s;this.emailAddress=a;this.firstName=d;this.lastName=p;this.picture=f;this.username=y;this.publicMetadata=h;this.label=S;this.verification=m}static fromJSON(e){return new F(e.id,e.provider,e.identification_id,e.provider_user_id,e.approved_scopes,e.email_address,e.first_name,e.last_name,e.avatar_url,e.username,e.public_metadata,e.label,e.verification&&w.fromJSON(e.verification))}};var D=class{constructor(e,r,i,n,s,a){this.id=e;this.emailAddress=r;this.publicMetadata=i;this.createdAt=n;this.updatedAt=s;this.revoked=a}static fromJSON(e){return new D(e.id,e.email_address,e.public_metadata,e.created_at,e.updated_at,e.revoked)}};var Me=(u=>(u.AllowlistIdentifier="allowlist_identifier",u.Client="client",u.Email="email",u.EmailAddress="email_address",u.ExternalAccount="external_account",u.FacebookAccount="facebook_account",u.GoogleAccount="google_account",u.Invitation="invitation",u.OauthAccessToken="oauth_access_token",u.Organization="organization",u.OrganizationInvitation="organization_invitation",u.OrganizationMembership="organization_membership",u.PhoneNumber="phone_number",u.RedirectUrl="redirect_url",u.Session="session",u.SignInAttempt="sign_in_attempt",u.SignInToken="sign_in_token",u.SignUpAttempt="sign_up_attempt",u.SmsMessage="sms_message",u.User="user",u.Web3Wallet="web3_wallet",u.Token="token",u.TotalCount="total_count",u))(Me||{});var V=class{constructor(e,r,i={},n,s,a){this.provider=e;this.token=r;this.publicMetadata=i;this.label=n;this.scopes=s;this.tokenSecret=a}static fromJSON(e){return new V(e.provider,e.token,e.public_metadata,e.label,e.scopes,e.token_secret)}};var U=class{constructor(e,r,i,n,s,a,d={},p={}){this.id=e;this.name=r;this.slug=i;this.logoUrl=n;this.createdAt=s;this.updatedAt=a;this.publicMetadata=d;this.privateMetadata=p}static fromJSON(e){return new U(e.id,e.name,e.slug,e.logo_url,e.created_at,e.updated_at,e.public_metadata,e.private_metadata)}};var B=class{constructor(e,r,i,n,s,a,d){this.id=e;this.emailAddress=r;this.role=i;this.organizationId=n;this.createdAt=s;this.updatedAt=a;this.status=d}static fromJSON(e){return new B(e.id,e.email_address,e.role,e.organization_id,e.created_at,e.updated_at,e.status)}};var G=class{constructor(e,r,i={},n={},s,a,d,p){this.id=e;this.role=r;this.publicMetadata=i;this.privateMetadata=n;this.createdAt=s;this.updatedAt=a;this.organization=d;this.publicUserData=p}static fromJSON(e){return new G(e.id,e.role,e.public_metadata,e.private_metadata,e.created_at,e.updated_at,U.fromJSON(e.organization),ee.fromJSON(e.public_user_data))}},ee=class{constructor(e,r,i,n,s){this.identifier=e;this.firstName=r;this.lastName=i;this.profileImageUrl=n;this.userId=s}static fromJSON(e){return new ee(e.identifier,e.first_name,e.last_name,e.profile_image_url,e.user_id)}};var q=class{constructor(e,r,i,n,s,a){this.id=e;this.phoneNumber=r;this.reservedForSecondFactor=i;this.defaultSecondFactor=n;this.verification=s;this.linkedTo=a}static fromJSON(e){return new q(e.id,e.phone_number,e.reserved_for_second_factor,e.default_second_factor,e.verification&&w.fromJSON(e.verification),e.linked_to.map(r=>v.fromJSON(r)))}};var H=class{constructor(e,r,i,n){this.id=e;this.url=r;this.createdAt=i;this.updatedAt=n}static fromJSON(e){return new H(e.id,e.url,e.created_at,e.updated_at)}};var $=class{constructor(e,r,i,n,s,a){this.id=e;this.userId=r;this.token=i;this.status=n;this.createdAt=s;this.updatedAt=a}static fromJSON(e){return new $(e.id,e.user_id,e.token,e.status,e.created_at,e.updated_at)}};var Y=class{constructor(e,r,i,n,s,a){this.id=e;this.fromPhoneNumber=r;this.toPhoneNumber=i;this.message=n;this.status=s;this.phoneNumberId=a}static fromJSON(e){return new Y(e.id,e.from_phone_number,e.to_phone_number,e.message,e.status,e.phone_number_id)}};var X=class{constructor(e){this.jwt=e}static fromJSON(e){return new X(e.jwt)}};var te=class{constructor(e,r,i){this.id=e;this.web3Wallet=r;this.verification=i}static fromJSON(e){return new te(e.id,e.web3_wallet,e.verification&&w.fromJSON(e.verification))}};var Q=class{constructor(e,r,i,n,s,a,d,p,f,y,h,S,m,g,O,k,_,I,P,T={},x={},b={},u=[],Ee=[],it=[],Pr=[]){this.id=e;this.passwordEnabled=r;this.totpEnabled=i;this.backupCodeEnabled=n;this.twoFactorEnabled=s;this.banned=a;this.createdAt=d;this.updatedAt=p;this.profileImageUrl=f;this.gender=y;this.birthday=h;this.primaryEmailAddressId=S;this.primaryPhoneNumberId=m;this.primaryWeb3WalletId=g;this.lastSignInAt=O;this.externalId=k;this.username=_;this.firstName=I;this.lastName=P;this.publicMetadata=T;this.privateMetadata=x;this.unsafeMetadata=b;this.emailAddresses=u;this.phoneNumbers=Ee;this.web3Wallets=it;this.externalAccounts=Pr}static fromJSON(e){return new Q(e.id,e.password_enabled,e.totp_enabled,e.backup_code_enabled,e.two_factor_enabled,e.banned,e.created_at,e.updated_at,e.profile_image_url,e.gender,e.birthday,e.primary_email_address_id,e.primary_phone_number_id,e.primary_web3_wallet_id,e.last_sign_in_at,e.external_id,e.username,e.first_name,e.last_name,e.public_metadata,e.private_metadata,e.unsafe_metadata,(e.email_addresses||[]).map(r=>E.fromJSON(r)),(e.phone_numbers||[]).map(r=>q.fromJSON(r)),(e.web3_wallets||[]).map(r=>te.fromJSON(r)),(e.external_accounts||[]).map(r=>F.fromJSON(r)))}};function We(t){return Array.isArray(t)?t.map(e=>je(e)):Zt(t)?t.data.map(e=>je(e)):je(t)}function Zt(t){return t.data!==void 0}function er(t){return t.total_count}function je(t){if(typeof t!="string"&&"object"in t&&"deleted"in t)return W.fromJSON(t);switch(t.object){case"allowlist_identifier":return M.fromJSON(t);case"client":return j.fromJSON(t);case"email_address":return E.fromJSON(t);case"email":return L.fromJSON(t);case"invitation":return D.fromJSON(t);case"oauth_access_token":return V.fromJSON(t);case"organization":return U.fromJSON(t);case"organization_invitation":return B.fromJSON(t);case"organization_membership":return G.fromJSON(t);case"phone_number":return q.fromJSON(t);case"redirect_url":return H.fromJSON(t);case"sign_in_token":return $.fromJSON(t);case"session":return C.fromJSON(t);case"sms_message":return Y.fromJSON(t);case"token":return X.fromJSON(t);case"total_count":return er(t);case"user":return Q.fromJSON(t);default:return t}}var tr=t=>async(...e)=>{let{data:r,errors:i,status:n,statusText:s}=await t(...e);if(i===null)return r;throw new ie(s||"",{data:i,status:n||""})};function mt(t){return tr(async r=>{let{apiKey:i,secretKey:n,apiUrl:s=K,apiVersion:a=R,userAgent:d=at,httpOptions:p={}}=t,{path:f,method:y,queryParams:h,headerParams:S,bodyParams:m}=r,g=n||i;if(!g)throw Error("Missing Clerk Secret Key or API Key. Go to https://dashboard.clerk.dev and get your key for your instance.");let O=o(s,a,f),k=new URL(O);if(h){let x=(0,Le.default)({...h});for(let[b,u]of Object.entries(x))u&&[u].flat().forEach(Ee=>k.searchParams.append(b,Ee))}let _={Authorization:`Bearer ${g}`,"Content-Type":"application/json","Clerk-Backend-SDK":d,...S},P=y!=="GET"&&m&&Object.keys(m).length>0?{body:JSON.stringify((0,Le.default)(m,{deep:!1}))}:null,T;try{T=await N.fetch(k.href,(0,pt.default)(p,{method:y,headers:_,...P}));let b=await(_&&_["Content-Type"]==="application/json"?T.json():T.text());if(!T.ok)throw b;return{data:We(b),errors:null}}catch(x){return x instanceof Error?{data:null,errors:[{code:"unexpected_error",message:x.message||"Unexpected error"}]}:{data:null,errors:rr(x),status:T?.status,statusText:T?.statusText}}})}function rr(t){if(!!t&&typeof t=="object"&&"errors"in t){let e=t.errors;return e.length>0?e.map(nr):[]}return[]}function nr(t){return{code:t.code,message:t.message,longMessage:t.long_message,meta:{paramName:t?.meta?.param_name,sessionId:t?.meta?.session_id}}}var ie=class extends Error{constructor(r,{data:i,status:n}){super(r);Object.setPrototypeOf(this,ie.prototype),this.clerkError=!0,this.message=r,this.status=n,this.errors=i}};function re(t){let e=mt(t);return{allowlistIdentifiers:new ue(e),clients:new de(e),emailAddresses:new pe(e),emails:new me(e),interstitial:new ge(e),invitations:new fe(e),organizations:new ye(e),phoneNumbers:new be(e),redirectUrls:new Oe(e),sessions:new ke(e),signInTokens:new _e(e),smsMessages:new Ie(e),users:new Ae(e)}}var gt=t=>()=>{let e={...t};return e.apiKey=(e.apiKey||"").substring(0,7),e.jwtKey=(e.jwtKey||"").substring(0,7),{...e}};function De(t,e,r){let{act:i,sid:n,org_id:s,org_role:a,org_slug:d,sub:p}=t,{apiKey:f,secretKey:y,apiUrl:h,apiVersion:S,token:m,session:g,user:O,organization:k}=e,{sessions:_}=re({apiKey:f,secretKey:y,apiUrl:h,apiVersion:S}),I=sr({sessionId:n,sessionToken:m,fetcher:(...P)=>_.getToken(...P)});return{actor:i,sessionClaims:t,sessionId:n,session:g,userId:p,user:O,orgId:s,orgRole:a,orgSlug:d,organization:k,getToken:I,debug:gt(r)}}function Ve(t){return{sessionClaims:null,sessionId:null,session:null,userId:null,user:null,actor:null,orgId:null,orgRole:null,orgSlug:null,organization:null,getToken:()=>Promise.resolve(null),debug:gt(t)}}function Fe(t){return t&&(delete t.privateMetadata,delete t.private_metadata),t}function ir(t){let e=t.user?{...t.user}:t.user,r=t.organization?{...t.organization}:t.organization;return Fe(e),Fe(r),{...t,user:e,organization:r}}var sr=t=>{let{fetcher:e,sessionToken:r,sessionId:i}=t||{};return async(n={})=>i?n.template?e(i,n.template):r:null};function or(t){return new Promise(e=>setTimeout(e,t))}var ar=5;async function se(t,e=1,r=ar){try{return await t()}catch(i){if(e>=r)throw i;return await or(2**e*100),se(t,e+1)}}function we(t){return t.startsWith("test_")||t.startsWith("sk_test_")}function ft(t){return t.startsWith("live_")||t.startsWith("sk_live_")}function yt(t){return t.endsWith(".lclstage.dev")||t.endsWith(".stgstage.dev")||t.endsWith(".clerkstage.dev")||t.endsWith(".accountsstage.dev")}var ht="pk_live_",lr="pk_test_";function oe(t){if(t=t||"",!ur(t))return null;let e=t.startsWith(ht)?"production":"development",r=bt(t.split("_")[2]);return r.endsWith("$")?(r=r.slice(0,-1),{instanceType:e,frontendApi:r}):null}function ur(t){t=t||"";let e=t.startsWith(ht)||t.startsWith(lr),r=bt(t.split("_")[2]||"").endsWith("$");return e&&r}var bt=t=>typeof atob<"u"&&typeof atob=="function"?atob(t):typeof Buffer<"u"?new Buffer(t,"base64").toString():t;var l=class extends Error{constructor({action:r,message:i,reason:n}){super(i);Object.setPrototypeOf(this,l.prototype),this.reason=n,this.message=i,this.action=r}getFullMessage(){return`${[this.message,this.action].filter(r=>r).join(" ")} (reason=${this.reason}, token-carrier=${this.tokenCarrier})`}};function Te(t){let{debugData:e,frontendApi:r,pkgVersion:i,publishableKey:n}=t;return` | ||
<head> | ||
@@ -54,3 +54,3 @@ <meta charset="UTF-8" /> | ||
</body> | ||
`}async function St(t){t.frontendApi=oe(t.publishableKey)?.frontendApi||t.frontendApi||"";let e=Pe(t),r=await se(()=>N.fetch(Pe(t)));if(!r.ok)throw new l({action:"Contact support@clerk.dev",message:`Error loading Clerk Interstitial from ${e} with code=${r.status}`,reason:"interstitial-remote-failed-to-load"});return r.text()}function Pe(t){t.frontendApi=oe(t.publishableKey)?.frontendApi||t.frontendApi||"";let{apiUrl:e,frontendApi:r,pkgVersion:i,publishableKey:n}=t,s=new URL(e);return s.pathname=o(s.pathname,R,"/public/interstitial"),s.searchParams.append("clerk_js_version",Ot(r,i)),n?s.searchParams.append("publishable_key",n):s.searchParams.append("frontend_api",r),s.href}var Ot=(t,e)=>!e&&yt(t)?"staging":e?e.includes("next")?"next":e.split(".")[0]||"latest":"latest",dr=(t,e)=>{let r=Ot(t,e);return`https://${t}/npm/@clerk/clerk-js@${r}/dist/clerk.browser.js`};var Ge=(n=>(n.SignedIn="signed-in",n.SignedOut="signed-out",n.Interstitial="interstitial",n.Unknown="unknown",n))(Ge||{});async function $e(t,e){let{apiKey:r,secretKey:i,apiUrl:n,apiVersion:s,cookieToken:a,frontendApi:d,publishableKey:p,headerToken:f,loadSession:y,loadUser:h,loadOrganization:S}=t,{sid:m,org_id:g,sub:O}=e,{sessions:k,users:_,organizations:I}=re({apiKey:r,secretKey:i,apiUrl:n,apiVersion:s}),[P,T,x]=await Promise.all([y?k.getSession(m):Promise.resolve(void 0),h?_.getUser(O):Promise.resolve(void 0),S&&g?I.getOrganization({organizationId:g}):Promise.resolve(void 0)]),it=De(e,{apiKey:r,apiUrl:n,apiVersion:s,token:a||f||"",session:P,user:T,organization:x},{...t,status:"signed-in"});return{status:"signed-in",reason:null,message:null,frontendApi:d,publishableKey:p,isSignedIn:!0,isInterstitial:!1,isUnknown:!1,toAuth:()=>it}}function z(t,e,r=""){let{frontendApi:i,publishableKey:n}=t;return{status:"signed-out",reason:e,message:r,frontendApi:i,publishableKey:n,isSignedIn:!1,isInterstitial:!1,isUnknown:!1,toAuth:()=>Ve({...t,status:"signed-out",reason:e,message:r})}}function Z(t,e,r=""){let{frontendApi:i,publishableKey:n}=t;return{status:"interstitial",reason:e,message:r,frontendApi:i,publishableKey:n,isSignedIn:!1,isInterstitial:!0,isUnknown:!1,toAuth:()=>null}}function kt(t,e,r=""){let{frontendApi:i,publishableKey:n}=t;return{status:"unknown",reason:e,message:r,frontendApi:i,publishableKey:n,isSignedIn:!1,isInterstitial:!1,isUnknown:!0,toAuth:()=>null}}function He({originURL:t,host:e,forwardedHost:r,forwardedPort:i,forwardedProto:n}){if(n&&n!==t.protocol)return!0;let s=cr(r||e);return s.port=i||s.port,s.port!==t.port||s.hostname!==t.hostname}function cr(t){return new URL(`https://${t}`)}var Je=require("rfc4648");var pr=2*1e3,Qe={RS256:"SHA-256",RS384:"SHA-384",RS512:"SHA-512",ES256:"SHA-256",ES384:"SHA-384",ES512:"SHA-512"},Ye="RSASSA-PKCS1-v1_5",Xe="ECDSA",mr={RS256:Ye,RS384:Ye,RS512:Ye,ES256:Xe,ES384:Xe,ES512:Xe},gr=Object.keys(Qe);async function _t(t,e){let{header:r,signature:i,raw:n}=t,a=new TextEncoder().encode([n.header,n.payload].join(".")),d=await N.crypto.subtle.importKey("jwk",e,{name:mr[r.alg],hash:Qe[r.alg]},!1,["verify"]);return N.crypto.subtle.verify("RSASSA-PKCS1-v1_5",d,i,a)}function Re(t){let e=(t||"").toString().split(".");if(e.length!==3)throw new l({reason:"token-invalid",message:"Invalid JWT form. A JWT consists of three parts separated by dots."});let[r,i,n]=e,s=new TextDecoder,a=JSON.parse(s.decode(Je.base64url.parse(r,{loose:!0}))),d=JSON.parse(s.decode(Je.base64url.parse(i,{loose:!0}))),p=Je.base64url.parse(n,{loose:!0});return{header:a,payload:d,signature:p,raw:{header:r,payload:i,signature:n,text:t}}}async function Ze(t,{audience:e,authorizedParties:r,clockSkewInSeconds:i=pr,issuer:n,key:s}){let a=Re(t),{header:d,payload:p}=a,{typ:f,alg:y}=d;if(typeof f<"u"&&f!=="JWT")throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-invalid",message:`Invalid JWT type ${JSON.stringify(f)}. Expected "JWT".`});if(!Qe[y])throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-invalid-algorithm",message:`Invalid JWT algorithm ${JSON.stringify(y)}. Supported: ${gr}.`});let{azp:h,sub:S,aud:m,iss:g,iat:O,exp:k,nbf:_}=p;if(typeof S!="string")throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-verification-failed",message:`Subject claim (sub) is required and must be a string. Received ${JSON.stringify(S)}.`});if(typeof m=="string"){if(m!==e)throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-verification-failed",message:`Invalid JWT audience claim (aud) ${JSON.stringify(m)}. Expected "${e}".`})}else if(Array.isArray(m)&&m.length>0&&m.every(b=>typeof b=="string")&&!m.includes(e))throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-verification-failed",message:`Invalid JWT audience claim array (aud) ${JSON.stringify(m)}. Does not include "${e}".`});if(h&&r&&r.length>0&&!r.includes(h))throw new l({reason:"token-invalid-authorized-parties",message:`Invalid JWT Authorized party claim (azp) ${JSON.stringify(h)}. Expected "${r}".`});if(typeof n=="function"&&!n(g))throw new l({reason:"token-invalid-issuer",message:"Failed JWT issuer resolver. Make sure that the resolver returns a truthy value."});if(typeof n=="string"&&g&&g!==n)throw new l({reason:"token-invalid-issuer",message:`Invalid JWT issuer claim (iss) ${JSON.stringify(a.payload.iss)}. Expected "${n}".`});if(typeof k!="number")throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-verification-failed",message:`Invalid JWT expiry date claim (exp) ${JSON.stringify(k)}. Expected number.`});let I=new Date(Date.now()),P=new Date(0);if(P.setUTCSeconds(k),P.getTime()<=I.getTime()-i)throw new l({reason:"token-expired",message:`JWT is expired. Expiry date: ${P}, Current date: ${I}.`});if(_!==void 0){if(typeof _!="number")throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-verification-failed",message:`Invalid JWT not before date claim (nbf) ${JSON.stringify(_)}. Expected number.`});let b=new Date(0);if(b.setUTCSeconds(_),b.getTime()>I.getTime()+i)throw new l({reason:"token-not-active-yet",message:`JWT cannot be used prior to not before date claim (nbf). Not before date: ${b}; Current date: ${I};`})}if(O!==void 0){if(typeof O!="number")throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-verification-failed",message:`Invalid JWT issued at date claim (iat) ${JSON.stringify(O)}. Expected number.`});let b=new Date(0);if(b.setUTCSeconds(O),b.getTime()>I.getTime()+i)throw new l({reason:"token-not-active-yet",message:`JWT issued at date claim (iat) is in the future. Issued at date: ${b}; Current date: ${I};`})}let x;try{x=await _t(a,s)}catch(b){throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-verification-failed",message:`Error verifying JWT signature. ${b}`})}if(!x)throw new l({reason:"token-invalid-signature",message:"JWT signature is invalid."});return p}var Ne={},At=0;function Ce(t){return Ne[t]}function wt(t,e=1e3*60*60){Ne[t.kid]=t,At=Date.now(),e>=0&&setTimeout(()=>{t?delete Ne[t.kid]:Ne={}},e)}var It="local",yr="-----BEGIN PUBLIC KEY-----",hr="-----END PUBLIC KEY-----",br="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA",Sr="IDAQAB";function Pt(t){if(!Ce(It)){if(!t)throw new l({action:"Set the CLERK_JWT_KEY environment variable.",message:"Missing local JWK.",reason:"jwk-local-missing"});let e=t.replace(/(\r\n|\n|\r)/gm,"").replace(yr,"").replace(hr,"").replace(br,"").replace(Sr,"").replace(/\+/g,"-").replace(/\//g,"_");wt({kid:"local",kty:"RSA",alg:"RS256",n:e,e:"AQAB"},-1)}return Ce(It)}async function et({apiKey:t,secretKey:e,apiUrl:r=K,apiVersion:i=R,issuer:n,kid:s,jwksCacheTtlInMs:a=1e3*60*60,skipJwksCache:d}){let p=!Ce(s)&&_r();if(d||p){let y,h=e||t;if(h)y=()=>kr(r,h,i);else if(n)y=()=>Or(n);else throw new l({action:"Contact support@clerk.dev",message:"Failed to load JWKS from Clerk Backend or Frontend API.",reason:"jwk-remote-failed-to-load"});let{keys:S}=await se(y);if(!S||!S.length)throw new l({action:"Contact support@clerk.dev",message:"The JWKS endpoint did not contain any signing keys. Contact support@clerk.dev.",reason:"jwk-remote-failed-to-load"});S.forEach(m=>wt(m,a))}let f=Ce(s);if(!f)throw new l({action:"Contact support@clerk.dev",message:`Unable to find a signing key in JWKS that matches kid='${s}'.`,reason:"jwk-remote-missing"});return f}async function Or(t){let e=new URL(t);e.pathname=o(e.pathname,".well-known/jwks.json");let r=await N.fetch(e.href);if(!r.ok)throw new l({action:"Contact support@clerk.dev",message:`Error loading Clerk JWKS from ${e.href} with code=${r.status}`,reason:"jwk-remote-failed-to-load"});return r.json()}async function kr(t,e,r){if(!e)throw new l({action:"Set the CLERK_SECRET_KEY or CLERK_API_KEY environment variable.",message:"Missing Clerk Secret Key or API Key. Go to https://dashboard.clerk.dev and get your key for your instance.",reason:"jwk-remote-failed-to-load"});let i=new URL(t);i.pathname=o(i.pathname,r,"/jwks");let n=await N.fetch(i.href,{headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"}});if(!n.ok)throw new l({action:"Contact support@clerk.dev",message:`Error loading Clerk JWKS from ${i.href} with code=${n.status}`,reason:"jwk-remote-failed-to-load"});return n.json()}function _r(){return Date.now()-At>=300*1e3}async function tt(t,e){let{apiKey:r,secretKey:i,apiUrl:n,apiVersion:s,authorizedParties:a,clockSkewInSeconds:d,issuer:p,jwksCacheTtlInMs:f,jwtKey:y,skipJwksCache:h}=e,{header:S}=Re(t),{kid:m}=S,g;if(y)g=Pt(y);else if(typeof p=="string")g=await et({issuer:p,kid:m,jwksCacheTtlInMs:f,skipJwksCache:h});else if(r||i)g=await et({apiKey:r,secretKey:i,apiUrl:n,apiVersion:s,kid:m,jwksCacheTtlInMs:f,skipJwksCache:h});else throw new l({action:"Set the CLERK_JWT_KEY environment variable.",message:"Failed to resolve JWK during verification.",reason:"jwk-failed-to-resolve"});return await Ze(t,{authorizedParties:a,clockSkewInSeconds:d,key:g,issuer:p})}var xt=async t=>{let{apiKey:e,secretKey:r,userAgent:i}=t;if(we(r||e)&&!i?.startsWith("Mozilla/"))return z(t,"header-missing-non-browser")},Tt=async t=>{let{origin:e,host:r,forwardedHost:i,forwardedPort:n,forwardedProto:s}=t;if(e&&He({originURL:new URL(e),host:r,forwardedHost:i,forwardedPort:n,forwardedProto:s}))return z(t,"header-missing-cors")},Jt=async t=>{let{apiKey:e,secretKey:r,clientUat:i}=t;if(we(r||e)&&!i)return Z(t,"uat-missing")},Rt=async t=>{let{apiKey:e,secretKey:r,referrer:i,host:n,forwardedHost:s,forwardedPort:a,forwardedProto:d}=t,p=i&&He({originURL:new URL(i),host:n,forwardedHost:s,forwardedPort:a,forwardedProto:d});if(we(r||e)&&p)return Z(t,"cross-origin-referrer")},Nt=async t=>{let{apiKey:e,secretKey:r,clientUat:i,cookieToken:n}=t;if(ft(r||e)&&!i&&!n)return z(t,"cookie-and-uat-missing")},Ct=async t=>{let{clientUat:e}=t;if(e==="0")return z(t,"standard-signed-out")},vt=async t=>{let{clientUat:e,cookieToken:r}=t;if(e&&!r)return Z(t,"cookie-missing")},Et=async t=>{let{headerToken:e}=t,r=await qt(t,e);return await $e(t,r)},Ut=async t=>{let{cookieToken:e,clientUat:r}=t,i=await qt(t,e),n=await $e(t,i),a=n.toAuth().sessionClaims.iat<Number.parseInt(r);return!r||a?Z(t,"cookie-outdated"):n};async function rt(t,e){for(let r of e){let i=await r(t);if(i)return i}return z(t,"unexpected-error")}async function qt(t,e){return tt(e,{...t,issuer:i=>i.startsWith("https://clerk.")||i.includes(".clerk.accounts")})}async function zt(t){t.frontendApi=oe(t.publishableKey)?.frontendApi||t.frontendApi||"",t.apiUrl=t.apiUrl||K,t.apiVersion=t.apiVersion||R;async function e(){try{return await rt(t,[Et])}catch(n){return i(n,"header")}}async function r(){try{return await rt(t,[xt,Tt,Jt,Rt,Nt,Ct,vt,Ut])}catch(n){return i(n,"cookie")}}function i(n,s){return n instanceof l?(n.tokenCarrier=s,["token-expired","token-not-active-yet"].includes(n.reason)?s==="header"?kt(t,n.reason,n.getFullMessage()):Z(t,n.reason,n.getFullMessage()):z(t,n.reason,n.getFullMessage())):z(t,"unexpected-error",n.message)}return t.headerToken?e():r()}var ve=t=>{let{frontendApi:e,isSignedIn:r,isInterstitial:i,reason:n,message:s,publishableKey:a}=t;return{frontendApi:e,isSignedIn:r,isInterstitial:i,reason:n,message:s,publishableKey:a}};function nt(t){let{apiClient:e}=t,{apiKey:r="",secretKey:i="",jwtKey:n="",apiUrl:s=K,apiVersion:a=R,frontendApi:d="",publishableKey:p=""}=t.options;return{authenticateRequest:({apiKey:g,secretKey:O,frontendApi:k,publishableKey:_,jwtKey:I,...P})=>zt({...P,apiKey:g||r,secretKey:O||i,apiUrl:s,apiVersion:a,frontendApi:k||d,publishableKey:_||p,jwtKey:I||n}),localInterstitial:Te,remotePublicInterstitial:({frontendApi:g,publishableKey:O,...k})=>St({...k,apiUrl:s,frontendApi:g||d,publishableKey:O||p}),remotePrivateInterstitial:()=>e.interstitial.getInterstitial(),remotePublicInterstitialUrl:Pe,debugRequestState:ve}}function Ar(t){let e={...t},r=re(e),i=nt({options:e,apiClient:r});return{...r,...i,__unstable_options:e}}0&&(module.exports={AllowlistIdentifier,AuthStatus,Clerk,Client,DeletedObject,Email,EmailAddress,ExternalAccount,IdentificationLink,Invitation,OauthAccessToken,ObjectType,Organization,OrganizationInvitation,OrganizationMembership,OrganizationMembershipPublicUserData,PhoneNumber,RedirectUrl,SMSMessage,Session,SignInToken,Token,User,Verification,constants,createAuthenticateRequest,debugRequestState,decodeJwt,deserialize,hasValidSignature,loadInterstitialFromLocal,prunePrivateMetadata,sanitizeAuthObject,signedInAuthObject,signedOutAuthObject,verifyJwt,verifyToken}); | ||
`}async function St(t){t.frontendApi=oe(t.publishableKey)?.frontendApi||t.frontendApi||"";let e=Pe(t),r=await se(()=>N.fetch(Pe(t)));if(!r.ok)throw new l({action:"Contact support@clerk.dev",message:`Error loading Clerk Interstitial from ${e} with code=${r.status}`,reason:"interstitial-remote-failed-to-load"});return r.text()}function Pe(t){t.frontendApi=oe(t.publishableKey)?.frontendApi||t.frontendApi||"";let{apiUrl:e,frontendApi:r,pkgVersion:i,publishableKey:n}=t,s=new URL(e);return s.pathname=o(s.pathname,R,"/public/interstitial"),s.searchParams.append("clerk_js_version",Ot(r,i)),n?s.searchParams.append("publishable_key",n):s.searchParams.append("frontend_api",r),s.href}var Ot=(t,e)=>!e&&yt(t)?"staging":e?e.includes("next")?"next":e.split(".")[0]||"latest":"latest",dr=(t,e)=>{let r=Ot(t,e);return`https://${t}/npm/@clerk/clerk-js@${r}/dist/clerk.browser.js`};var Ge=(n=>(n.SignedIn="signed-in",n.SignedOut="signed-out",n.Interstitial="interstitial",n.Unknown="unknown",n))(Ge||{});async function He(t,e){let{apiKey:r,secretKey:i,apiUrl:n,apiVersion:s,cookieToken:a,frontendApi:d,publishableKey:p,headerToken:f,loadSession:y,loadUser:h,loadOrganization:S}=t,{sid:m,org_id:g,sub:O}=e,{sessions:k,users:_,organizations:I}=re({apiKey:r,secretKey:i,apiUrl:n,apiVersion:s}),[P,T,x]=await Promise.all([y?k.getSession(m):Promise.resolve(void 0),h?_.getUser(O):Promise.resolve(void 0),S&&g?I.getOrganization({organizationId:g}):Promise.resolve(void 0)]),it=De(e,{apiKey:r,apiUrl:n,apiVersion:s,token:a||f||"",session:P,user:T,organization:x},{...t,status:"signed-in"});return{status:"signed-in",reason:null,message:null,frontendApi:d,publishableKey:p,isSignedIn:!0,isInterstitial:!1,isUnknown:!1,toAuth:()=>it}}function z(t,e,r=""){let{frontendApi:i,publishableKey:n}=t;return{status:"signed-out",reason:e,message:r,frontendApi:i,publishableKey:n,isSignedIn:!1,isInterstitial:!1,isUnknown:!1,toAuth:()=>Ve({...t,status:"signed-out",reason:e,message:r})}}function Z(t,e,r=""){let{frontendApi:i,publishableKey:n}=t;return{status:"interstitial",reason:e,message:r,frontendApi:i,publishableKey:n,isSignedIn:!1,isInterstitial:!0,isUnknown:!1,toAuth:()=>null}}function kt(t,e,r=""){let{frontendApi:i,publishableKey:n}=t;return{status:"unknown",reason:e,message:r,frontendApi:i,publishableKey:n,isSignedIn:!1,isInterstitial:!1,isUnknown:!0,toAuth:()=>null}}function $e({originURL:t,host:e,forwardedHost:r,forwardedPort:i,forwardedProto:n}){if(n&&n!==t.protocol)return!0;let s=cr(r||e);return s.port=i||s.port,s.port!==t.port||s.hostname!==t.hostname}function cr(t){return new URL(`https://${t}`)}var Je=require("rfc4648");var pr=2*1e3,Qe={RS256:"SHA-256",RS384:"SHA-384",RS512:"SHA-512",ES256:"SHA-256",ES384:"SHA-384",ES512:"SHA-512"},Ye="RSASSA-PKCS1-v1_5",Xe="ECDSA",mr={RS256:Ye,RS384:Ye,RS512:Ye,ES256:Xe,ES384:Xe,ES512:Xe},gr=Object.keys(Qe);async function _t(t,e){let{header:r,signature:i,raw:n}=t,a=new TextEncoder().encode([n.header,n.payload].join(".")),d=await N.crypto.subtle.importKey("jwk",e,{name:mr[r.alg],hash:Qe[r.alg]},!1,["verify"]);return N.crypto.subtle.verify("RSASSA-PKCS1-v1_5",d,i,a)}function Re(t){let e=(t||"").toString().split(".");if(e.length!==3)throw new l({reason:"token-invalid",message:"Invalid JWT form. A JWT consists of three parts separated by dots."});let[r,i,n]=e,s=new TextDecoder,a=JSON.parse(s.decode(Je.base64url.parse(r,{loose:!0}))),d=JSON.parse(s.decode(Je.base64url.parse(i,{loose:!0}))),p=Je.base64url.parse(n,{loose:!0});return{header:a,payload:d,signature:p,raw:{header:r,payload:i,signature:n,text:t}}}async function Ze(t,{audience:e,authorizedParties:r,clockSkewInSeconds:i=pr,issuer:n,key:s}){let a=Re(t),{header:d,payload:p}=a,{typ:f,alg:y}=d;if(typeof f<"u"&&f!=="JWT")throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-invalid",message:`Invalid JWT type ${JSON.stringify(f)}. Expected "JWT".`});if(!Qe[y])throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-invalid-algorithm",message:`Invalid JWT algorithm ${JSON.stringify(y)}. Supported: ${gr}.`});let{azp:h,sub:S,aud:m,iss:g,iat:O,exp:k,nbf:_}=p;if(typeof S!="string")throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-verification-failed",message:`Subject claim (sub) is required and must be a string. Received ${JSON.stringify(S)}.`});if(typeof m=="string"){if(m!==e)throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-verification-failed",message:`Invalid JWT audience claim (aud) ${JSON.stringify(m)}. Expected "${e}".`})}else if(Array.isArray(m)&&m.length>0&&m.every(b=>typeof b=="string")&&!m.includes(e))throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-verification-failed",message:`Invalid JWT audience claim array (aud) ${JSON.stringify(m)}. Does not include "${e}".`});if(h&&r&&r.length>0&&!r.includes(h))throw new l({reason:"token-invalid-authorized-parties",message:`Invalid JWT Authorized party claim (azp) ${JSON.stringify(h)}. Expected "${r}".`});if(typeof n=="function"&&!n(g))throw new l({reason:"token-invalid-issuer",message:"Failed JWT issuer resolver. Make sure that the resolver returns a truthy value."});if(typeof n=="string"&&g&&g!==n)throw new l({reason:"token-invalid-issuer",message:`Invalid JWT issuer claim (iss) ${JSON.stringify(a.payload.iss)}. Expected "${n}".`});if(typeof k!="number")throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-verification-failed",message:`Invalid JWT expiry date claim (exp) ${JSON.stringify(k)}. Expected number.`});let I=new Date(Date.now()),P=new Date(0);if(P.setUTCSeconds(k),P.getTime()<=I.getTime()-i)throw new l({reason:"token-expired",message:`JWT is expired. Expiry date: ${P}, Current date: ${I}.`});if(_!==void 0){if(typeof _!="number")throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-verification-failed",message:`Invalid JWT not before date claim (nbf) ${JSON.stringify(_)}. Expected number.`});let b=new Date(0);if(b.setUTCSeconds(_),b.getTime()>I.getTime()+i)throw new l({reason:"token-not-active-yet",message:`JWT cannot be used prior to not before date claim (nbf). Not before date: ${b}; Current date: ${I};`})}if(O!==void 0){if(typeof O!="number")throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-verification-failed",message:`Invalid JWT issued at date claim (iat) ${JSON.stringify(O)}. Expected number.`});let b=new Date(0);if(b.setUTCSeconds(O),b.getTime()>I.getTime()+i)throw new l({reason:"token-not-active-yet",message:`JWT issued at date claim (iat) is in the future. Issued at date: ${b}; Current date: ${I};`})}let x;try{x=await _t(a,s)}catch(b){throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-verification-failed",message:`Error verifying JWT signature. ${b}`})}if(!x)throw new l({reason:"token-invalid-signature",message:"JWT signature is invalid."});return p}var Ne={},At=0;function Ce(t){return Ne[t]}function wt(t,e=1e3*60*60){Ne[t.kid]=t,At=Date.now(),e>=0&&setTimeout(()=>{t?delete Ne[t.kid]:Ne={}},e)}var It="local",yr="-----BEGIN PUBLIC KEY-----",hr="-----END PUBLIC KEY-----",br="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA",Sr="IDAQAB";function Pt(t){if(!Ce(It)){if(!t)throw new l({action:"Set the CLERK_JWT_KEY environment variable.",message:"Missing local JWK.",reason:"jwk-local-missing"});let e=t.replace(/(\r\n|\n|\r)/gm,"").replace(yr,"").replace(hr,"").replace(br,"").replace(Sr,"").replace(/\+/g,"-").replace(/\//g,"_");wt({kid:"local",kty:"RSA",alg:"RS256",n:e,e:"AQAB"},-1)}return Ce(It)}async function et({apiKey:t,secretKey:e,apiUrl:r=K,apiVersion:i=R,issuer:n,kid:s,jwksCacheTtlInMs:a=1e3*60*60,skipJwksCache:d}){let p=!Ce(s)&&_r();if(d||p){let y,h=e||t;if(h)y=()=>kr(r,h,i);else if(n)y=()=>Or(n);else throw new l({action:"Contact support@clerk.dev",message:"Failed to load JWKS from Clerk Backend or Frontend API.",reason:"jwk-remote-failed-to-load"});let{keys:S}=await se(y);if(!S||!S.length)throw new l({action:"Contact support@clerk.dev",message:"The JWKS endpoint did not contain any signing keys. Contact support@clerk.dev.",reason:"jwk-remote-failed-to-load"});S.forEach(m=>wt(m,a))}let f=Ce(s);if(!f)throw new l({action:"Contact support@clerk.dev",message:`Unable to find a signing key in JWKS that matches kid='${s}'.`,reason:"jwk-remote-missing"});return f}async function Or(t){let e=new URL(t);e.pathname=o(e.pathname,".well-known/jwks.json");let r=await N.fetch(e.href);if(!r.ok)throw new l({action:"Contact support@clerk.dev",message:`Error loading Clerk JWKS from ${e.href} with code=${r.status}`,reason:"jwk-remote-failed-to-load"});return r.json()}async function kr(t,e,r){if(!e)throw new l({action:"Set the CLERK_SECRET_KEY or CLERK_API_KEY environment variable.",message:"Missing Clerk Secret Key or API Key. Go to https://dashboard.clerk.dev and get your key for your instance.",reason:"jwk-remote-failed-to-load"});let i=new URL(t);i.pathname=o(i.pathname,r,"/jwks");let n=await N.fetch(i.href,{headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"}});if(!n.ok)throw new l({action:"Contact support@clerk.dev",message:`Error loading Clerk JWKS from ${i.href} with code=${n.status}`,reason:"jwk-remote-failed-to-load"});return n.json()}function _r(){return Date.now()-At>=300*1e3}async function tt(t,e){let{apiKey:r,secretKey:i,apiUrl:n,apiVersion:s,authorizedParties:a,clockSkewInSeconds:d,issuer:p,jwksCacheTtlInMs:f,jwtKey:y,skipJwksCache:h}=e,{header:S}=Re(t),{kid:m}=S,g;if(y)g=Pt(y);else if(typeof p=="string")g=await et({issuer:p,kid:m,jwksCacheTtlInMs:f,skipJwksCache:h});else if(r||i)g=await et({apiKey:r,secretKey:i,apiUrl:n,apiVersion:s,kid:m,jwksCacheTtlInMs:f,skipJwksCache:h});else throw new l({action:"Set the CLERK_JWT_KEY environment variable.",message:"Failed to resolve JWK during verification.",reason:"jwk-failed-to-resolve"});return await Ze(t,{authorizedParties:a,clockSkewInSeconds:d,key:g,issuer:p})}var xt=async t=>{let{apiKey:e,secretKey:r,userAgent:i}=t;if(we(r||e)&&!i?.startsWith("Mozilla/"))return z(t,"header-missing-non-browser")},Tt=async t=>{let{origin:e,host:r,forwardedHost:i,forwardedPort:n,forwardedProto:s}=t;if(e&&$e({originURL:new URL(e),host:r,forwardedHost:i,forwardedPort:n,forwardedProto:s}))return z(t,"header-missing-cors")},Jt=async t=>{let{apiKey:e,secretKey:r,clientUat:i}=t;if(we(r||e)&&!i)return Z(t,"uat-missing")},Rt=async t=>{let{apiKey:e,secretKey:r,referrer:i,host:n,forwardedHost:s,forwardedPort:a,forwardedProto:d}=t,p=i&&$e({originURL:new URL(i),host:n,forwardedHost:s,forwardedPort:a,forwardedProto:d});if(we(r||e)&&p)return Z(t,"cross-origin-referrer")},Nt=async t=>{let{apiKey:e,secretKey:r,clientUat:i,cookieToken:n}=t;if(ft(r||e)&&!i&&!n)return z(t,"cookie-and-uat-missing")},Ct=async t=>{let{clientUat:e}=t;if(e==="0")return z(t,"standard-signed-out")},vt=async t=>{let{clientUat:e,cookieToken:r}=t;if(e&&!r)return Z(t,"cookie-missing")},Et=async t=>{let{headerToken:e}=t,r=await qt(t,e);return await He(t,r)},Ut=async t=>{let{cookieToken:e,clientUat:r}=t,i=await qt(t,e),n=await He(t,i),a=n.toAuth().sessionClaims.iat<Number.parseInt(r);return!r||a?Z(t,"cookie-outdated"):n};async function rt(t,e){for(let r of e){let i=await r(t);if(i)return i}return z(t,"unexpected-error")}async function qt(t,e){return tt(e,{...t,issuer:i=>i.startsWith("https://clerk.")||i.includes(".clerk.accounts")})}async function zt(t){t.frontendApi=oe(t.publishableKey)?.frontendApi||t.frontendApi||"",t.apiUrl=t.apiUrl||K,t.apiVersion=t.apiVersion||R;async function e(){try{return await rt(t,[Et])}catch(n){return i(n,"header")}}async function r(){try{return await rt(t,[xt,Tt,Jt,Rt,Nt,Ct,vt,Ut])}catch(n){return i(n,"cookie")}}function i(n,s){return n instanceof l?(n.tokenCarrier=s,["token-expired","token-not-active-yet"].includes(n.reason)?s==="header"?kt(t,n.reason,n.getFullMessage()):Z(t,n.reason,n.getFullMessage()):z(t,n.reason,n.getFullMessage())):z(t,"unexpected-error",n.message)}return t.headerToken?e():r()}var ve=t=>{let{frontendApi:e,isSignedIn:r,isInterstitial:i,reason:n,message:s,publishableKey:a}=t;return{frontendApi:e,isSignedIn:r,isInterstitial:i,reason:n,message:s,publishableKey:a}};function nt(t){let{apiClient:e}=t,{apiKey:r="",secretKey:i="",jwtKey:n="",apiUrl:s=K,apiVersion:a=R,frontendApi:d="",publishableKey:p=""}=t.options;return{authenticateRequest:({apiKey:g,secretKey:O,frontendApi:k,publishableKey:_,jwtKey:I,...P})=>zt({...P,apiKey:g||r,secretKey:O||i,apiUrl:s,apiVersion:a,frontendApi:k||d,publishableKey:_||p,jwtKey:I||n}),localInterstitial:Te,remotePublicInterstitial:({frontendApi:g,publishableKey:O,...k})=>St({...k,apiUrl:s,frontendApi:g||d,publishableKey:O||p}),remotePrivateInterstitial:()=>e.interstitial.getInterstitial(),remotePublicInterstitialUrl:Pe,debugRequestState:ve}}function Ar(t){let e={...t},r=re(e),i=nt({options:e,apiClient:r});return{...r,...i,__unstable_options:e}}0&&(module.exports={AllowlistIdentifier,AuthStatus,Clerk,Client,DeletedObject,Email,EmailAddress,ExternalAccount,IdentificationLink,Invitation,OauthAccessToken,ObjectType,Organization,OrganizationInvitation,OrganizationMembership,OrganizationMembershipPublicUserData,PhoneNumber,RedirectUrl,SMSMessage,Session,SignInToken,Token,User,Verification,constants,createAuthenticateRequest,debugRequestState,decodeJwt,deserialize,hasValidSignature,loadInterstitialFromLocal,prunePrivateMetadata,sanitizeAuthObject,signedInAuthObject,signedOutAuthObject,verifyJwt,verifyToken}); | ||
//# sourceMappingURL=index.js.map |
@@ -22,2 +22,7 @@ import type { OAuthProvider } from '@clerk/types'; | ||
}; | ||
type PasswordHasher = 'argon2i' | 'argon2id' | 'bcrypt' | 'md5' | 'pbkdf2_sha256_django' | 'pbkdf2_sha1' | 'scrypt_firebase'; | ||
type UserPasswordHashingParams = { | ||
passwordDigest: string; | ||
passwordHasher: PasswordHasher; | ||
}; | ||
type CreateUserParams = { | ||
@@ -35,3 +40,3 @@ externalId?: string; | ||
backupCodes?: string[]; | ||
} & UserMetadataParams; | ||
} & UserMetadataParams & (UserPasswordHashingParams | {}); | ||
interface UpdateUserParams extends UserMetadataParams { | ||
@@ -38,0 +43,0 @@ firstName?: string; |
{ | ||
"name": "@clerk/backend", | ||
"version": "0.5.1-staging.0", | ||
"version": "0.5.1-staging.1", | ||
"license": "MIT", | ||
@@ -66,2 +66,3 @@ "description": "Clerk Backend SDK - REST Client for Backend API & JWT verification utilities", | ||
}, | ||
"homepage": "https://clerk.dev/", | ||
"repository": { | ||
@@ -74,7 +75,6 @@ "type": "git", | ||
}, | ||
"homepage": "https://clerk.dev/", | ||
"engines": { | ||
"node": ">=14" | ||
}, | ||
"gitHead": "fb53cbe969a37ddf713ce478f9e57b591f763fe6" | ||
"gitHead": "2b0cd66dc5be3f55e22abf11724fd1f4792fb105" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
515658
140
1768