Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@clerk/backend

Package Overview
Dependencies
Maintainers
9
Versions
2255
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@clerk/backend - npm Package Compare versions

Comparing version 0.4.3-staging.1 to 0.4.3

dist/types/api/factory.test.d.ts

8

dist/esm/index.js

@@ -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 w="/organizations",ge=class extends c{async getOrganizationList(e){return this.request({method:"GET",path:w,queryParams:e})}async createOrganization(e){return this.request({method:"POST",path:w,bodyParams:e})}async getOrganization(e){let r="organizationId"in e?e.organizationId:e.slug;return this.requireId(r),this.request({method:"GET",path:o(w,r)})}async updateOrganization(e,r){return this.requireId(e),this.request({method:"PATCH",path:o(w,e),bodyParams:r})}async updateOrganizationMetadata(e,r){return this.requireId(e),this.request({method:"PATCH",path:o(w,e,"metadata"),bodyParams:r})}async deleteOrganization(e){return this.request({method:"DELETE",path:o(w,e)})}async getOrganizationMembershipList(e){let{organizationId:r,limit:n,offset:i}=e;return this.requireId(r),this.request({method:"GET",path:o(w,r,"memberships"),queryParams:{limit:n,offset:i}})}async createOrganizationMembership(e){let{organizationId:r,userId:n,role:i}=e;return this.requireId(r),this.request({method:"POST",path:o(w,r,"memberships"),bodyParams:{userId:n,role:i}})}async updateOrganizationMembership(e){let{organizationId:r,userId:n,role:i}=e;return this.requireId(r),this.request({method:"PATCH",path:o(w,r,"memberships",n),bodyParams:{role:i}})}async updateOrganizationMembershipMetadata(e){let{organizationId:r,userId:n,publicMetadata:i,privateMetadata:s}=e;return this.request({method:"PATCH",path:o(w,r,"memberships",n,"metadata"),bodyParams:{publicMetadata:i,privateMetadata:s}})}async deleteOrganizationMembership(e){let{organizationId:r,userId:n}=e;return this.requireId(r),this.request({method:"DELETE",path:o(w,r,"memberships",n)})}async getPendingOrganizationInvitationList(e){let{organizationId:r,limit:n,offset:i}=e;return this.requireId(r),this.request({method:"GET",path:o(w,r,"invitations","pending"),queryParams:{limit:n,offset:i}})}async createOrganizationInvitation(e){let{organizationId:r,...n}=e;return this.requireId(r),this.request({method:"POST",path:o(w,r,"invitations"),bodyParams:{...n}})}async revokeOrganizationInvitation(e){let{organizationId:r,invitationId:n,requestingUserId:i}=e;return this.requireId(r),this.request({method:"POST",path:o(w,r,"invitations",n,"revoke"),bodyParams:{requestingUserId:i}})}};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,n)=>(this.requireId(r),this.request({method:"POST",path:o(re,r,"verify"),bodyParams:{token:n}}));this.getToken=async(r,n)=>(this.requireId(r),(await this.request({method:"POST",path:o(re,r,"tokens",n||"")})).jwt)}};var Be="/sign_in_tokens",Oe=class extends c{async createSignInToken(e){return this.request({method:"POST",path:Be,bodyParams:e})}async revokeSignInToken(e){return this.requireId(e),this.request({method:"POST",path:o(Be,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:n,offset:i}=e;return this.requireId(r),this.request({method:"GET",path:o(J,r,"organization_memberships"),queryParams:{limit:n,offset:i}})}};import Ft from"deepmerge";import Xe from"snakecase-keys";var v="https://api.clerk.dev",R="v1",Ge="@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),Wt={crypto:zt,fetch:Mt},N=Wt;var W=class{constructor(e,r,n,i,s){this.id=e;this.identifier=r;this.createdAt=n;this.updatedAt=i;this.invitationId=s}static fromJSON(e){return new W(e.id,e.identifier,e.created_at,e.updated_at,e.invitation_id)}};var E=class{constructor(e,r,n,i,s,a,d,p,g){this.id=e;this.clientId=r;this.userId=n;this.status=i;this.lastActiveAt=s;this.expireAt=a;this.abandonAt=d;this.createdAt=p;this.updatedAt=g}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 j=class{constructor(e,r,n,i,s,a,d,p){this.id=e;this.sessionIds=r;this.sessions=n;this.signInId=i;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=>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,n,i){this.object=e;this.id=r;this.slug=n;this.deleted=i}static fromJSON(e){return new L(e.object,e.id||null,e.slug||null,e.deleted)}};var F=class{constructor(e,r,n,i,s,a,d){this.id=e;this.fromEmailName=r;this.emailAddressId=n;this.toEmailAddress=i;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 T=class{constructor(e,r,n=null,i=null,s=null,a=null){this.status=e;this.strategy=r;this.externalVerificationRedirectURL=n;this.attempts=i;this.expireAt=s;this.nonce=a}static fromJSON(e){return new T(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,n,i){this.id=e;this.emailAddress=r;this.verification=n;this.linkedTo=i}static fromJSON(e){return new q(e.id,e.email_address,e.verification&&T.fromJSON(e.verification),e.linked_to.map(r=>U.fromJSON(r)))}};var D=class{constructor(e,r,n,i,s,a,d,p,g,y,h={},S,m){this.id=e;this.provider=r;this.identificationId=n;this.externalId=i;this.approvedScopes=s;this.emailAddress=a;this.firstName=d;this.lastName=p;this.picture=g;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&&T.fromJSON(e.verification))}};var V=class{constructor(e,r,n,i,s,a){this.id=e;this.emailAddress=r;this.publicMetadata=n;this.createdAt=i;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 He=(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))(He||{});var B=class{constructor(e,r,n={},i,s,a){this.provider=e;this.token=r;this.publicMetadata=n;this.label=i;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,n,i,s,a,d={},p={}){this.id=e;this.name=r;this.slug=n;this.logoUrl=i;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,n,i,s,a,d){this.id=e;this.emailAddress=r;this.role=n;this.organizationId=i;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,n={},i={},s,a,d,p){this.id=e;this.role=r;this.publicMetadata=n;this.privateMetadata=i;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,n,i,s){this.identifier=e;this.firstName=r;this.lastName=n;this.profileImageUrl=i;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,n,i,s,a){this.id=e;this.phoneNumber=r;this.reservedForSecondFactor=n;this.defaultSecondFactor=i;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&&T.fromJSON(e.verification),e.linked_to.map(r=>U.fromJSON(r)))}};var H=class{constructor(e,r,n,i){this.id=e;this.url=r;this.createdAt=n;this.updatedAt=i}static fromJSON(e){return new H(e.id,e.url,e.created_at,e.updated_at)}};var Y=class{constructor(e,r,n,i,s,a){this.id=e;this.userId=r;this.token=n;this.status=i;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,n,i,s,a){this.id=e;this.fromPhoneNumber=r;this.toPhoneNumber=n;this.message=i;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,n){this.id=e;this.web3Wallet=r;this.verification=n}static fromJSON(e){return new Z(e.id,e.web3_wallet,e.verification&&T.fromJSON(e.verification))}};var ee=class{constructor(e,r,n,i,s,a,d,p,g,y,h,S,m,f,O,k,_,I,P,A={},x={},b={},u=[],Te=[],Ve=[],mr=[]){this.id=e;this.passwordEnabled=r;this.totpEnabled=n;this.backupCodeEnabled=i;this.twoFactorEnabled=s;this.banned=a;this.createdAt=d;this.updatedAt=p;this.profileImageUrl=g;this.gender=y;this.birthday=h;this.primaryEmailAddressId=S;this.primaryPhoneNumberId=m;this.primaryWeb3WalletId=f;this.lastSignInAt=O;this.externalId=k;this.username=_;this.firstName=I;this.lastName=P;this.publicMetadata=A;this.privateMetadata=x;this.unsafeMetadata=b;this.emailAddresses=u;this.phoneNumbers=Te;this.web3Wallets=Ve;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 Ye(t){return Array.isArray(t)?t.map(e=>ve(e)):jt(t)?t.data.map(e=>ve(e)):ve(t)}function jt(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 W.fromJSON(t);case"client":return j.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:n,status:i,statusText:s}=await t(...e);if(n===null)return r;throw new ie(s||"",{data:n,status:i||""})};function Qe(t){return Dt(async r=>{let{apiKey:n,secretKey:i,apiUrl:s=v,apiVersion:a=R,userAgent:d=Ge,httpOptions:p={}}=t,{path:g,method:y,queryParams:h,headerParams:S,bodyParams:m}=r,f=i||n;if(!f)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,g),k=new URL(O);if(h){let x=Xe({...h});for(let[b,u]of Object.entries(x))u&&[u].flat().forEach(Te=>k.searchParams.append(b,Te))}let _={Authorization:`Bearer ${f}`,"Content-Type":"application/json","Clerk-Backend-SDK":d,...S},P=y!=="GET"&&m&&Object.keys(m).length>0?{body:JSON.stringify(Xe(m,{deep:!1}))}:null,A;try{A=await N.fetch(k.href,Ft(p,{method:y,headers:_,...P}));let b=await(_&&_["Content-Type"]==="application/json"?A.json():A.text());if(!A.ok)throw b;return{data:Ye(b),errors:null}}catch(x){return x instanceof Error?{data:null,errors:[{code:"unexpected_error",message:x.message||"Unexpected error"}]}:{data:null,errors:Vt(x),status:A==null?void 0:A.status,statusText:A==null?void 0:A.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){var e,r;return{code:t.code,message:t.message,longMessage:t.long_message,meta:{paramName:(e=t==null?void 0:t.meta)==null?void 0:e.param_name,sessionId:(r=t==null?void 0:t.meta)==null?void 0:r.session_id}}}var ie=class extends Error{constructor(r,{data:n,status:i}){super(r);Object.setPrototypeOf(this,ie.prototype),this.clerkError=!0,this.message=r,this.status=i,this.errors=n}};function te(t){let e=Qe(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 et=t=>()=>{let e={...t};return e.apiKey=(e.apiKey||"").substring(0,7),e.jwtKey=(e.jwtKey||"").substring(0,7),{...e}};function tt(t,e,r){let{act:n,sid:i,org_id:s,org_role:a,org_slug:d,sub:p}=t,{apiKey:g,secretKey:y,apiUrl:h,apiVersion:S,token:m,session:f,user:O,organization:k}=e,{sessions:_}=te({apiKey:g,secretKey:y,apiUrl:h,apiVersion:S}),I=Gt({sessionId:i,sessionToken:m,fetcher:(...P)=>_.getToken(...P)});return{actor:n,sessionClaims:t,sessionId:i,session:f,userId:p,user:O,orgId:s,orgRole:a,orgSlug:d,organization:k,getToken:I,debug:et(r)}}function rt(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:et(t)}}function Ze(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 Ze(e),Ze(r),{...t,user:e,organization:r}}var Gt=t=>{let{fetcher:e,sessionToken:r,sessionId:n}=t||{};return async(i={})=>n?i.template?e(n,i.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(n){if(e>=r)throw n;return await $t(2**e*100),se(t,e+1)}}function Ie(t){return t.startsWith("test_")||t.startsWith("sk_test_")}function nt(t){return t.startsWith("live_")||t.startsWith("sk_live_")}function it(t){return t.endsWith(".lclstage.dev")||t.endsWith(".stgstage.dev")||t.endsWith(".clerkstage.dev")||t.endsWith(".accountsstage.dev")}var st="pk_live_",Yt="pk_test_";function oe(t){if(t=t||"",!Xt(t))return null;let e=t.startsWith(st)?"production":"development",r=ot(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(st)||t.startsWith(Yt),r=ot(t.split("_")[2]||"").endsWith("$");return e&&r}var ot=t=>typeof atob!="undefined"&&typeof atob=="function"?atob(t):typeof Buffer!="undefined"?new Buffer(t,"base64").toString():t;var l=class extends Error{constructor({action:r,message:n,reason:i}){super(n);Object.setPrototypeOf(this,l.prototype),this.reason=i,this.message=n,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:n,publishableKey:i}=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 Be="/sign_in_tokens",Oe=class extends c{async createSignInToken(e){return this.request({method:"POST",path:Be,bodyParams:e})}async revokeSignInToken(e){return this.requireId(e),this.request({method:"POST",path:o(Be,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 Xe from"snakecase-keys";var v="https://api.clerk.dev",R="v1",Ge="@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),Wt={crypto:zt,fetch:Mt},N=Wt;var W=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 W(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,g){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=g}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 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=>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,g,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=g;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 He=(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))(He||{});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,g,y,h,S,m,f,O,k,_,I,w,T={},P={},b={},u=[],Te=[],Ve=[],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=g;this.gender=y;this.birthday=h;this.primaryEmailAddressId=S;this.primaryPhoneNumberId=m;this.primaryWeb3WalletId=f;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=Ve;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 Ye(t){return Array.isArray(t)?t.map(e=>ve(e)):jt(t)?t.data.map(e=>ve(e)):ve(t)}function jt(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 W.fromJSON(t);case"client":return j.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 Qe(t){return Dt(async r=>{let{apiKey:i,secretKey:n,apiUrl:s=v,apiVersion:a=R,userAgent:d=Ge,httpOptions:p={}}=t,{path:g,method:y,queryParams:h,headerParams:S,bodyParams:m}=r,f=n||i;if(!f)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,g),k=new URL(O);if(h){let P=Xe({...h});for(let[b,u]of Object.entries(P))u&&[u].flat().forEach(Te=>k.searchParams.append(b,Te))}let _={Authorization:`Bearer ${f}`,"Content-Type":"application/json","Clerk-Backend-SDK":d,...S},w=y!=="GET"&&m&&Object.keys(m).length>0?{body:JSON.stringify(Xe(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:Ye(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=Qe(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 et=t=>()=>{let e={...t};return e.apiKey=(e.apiKey||"").substring(0,7),e.jwtKey=(e.jwtKey||"").substring(0,7),{...e}};function tt(t,e,r){let{act:i,sid:n,org_id:s,org_role:a,org_slug:d,sub:p}=t,{apiKey:g,secretKey:y,apiUrl:h,apiVersion:S,token:m,session:f,user:O,organization:k}=e,{sessions:_}=te({apiKey:g,secretKey:y,apiUrl:h,apiVersion:S}),I=Gt({sessionId:n,sessionToken:m,fetcher:(...w)=>_.getToken(...w)});return{actor:i,sessionClaims:t,sessionId:n,session:f,userId:p,user:O,orgId:s,orgRole:a,orgSlug:d,organization:k,getToken:I,debug:et(r)}}function rt(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:et(t)}}function Ze(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 Ze(e),Ze(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 nt(t){return t.startsWith("live_")||t.startsWith("sk_live_")}function it(t){return t.endsWith(".lclstage.dev")||t.endsWith(".stgstage.dev")||t.endsWith(".clerkstage.dev")||t.endsWith(".accountsstage.dev")}var st="pk_live_",Yt="pk_test_";function oe(t){if(t=t||"",!Xt(t))return null;let e=t.startsWith(st)?"production":"development",r=ot(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(st)||t.startsWith(Yt),r=ot(t.split("_")[2]||"").endsWith("$");return e&&r}var ot=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>

@@ -45,5 +45,5 @@ <meta charset="UTF-8" />

const script = document.createElement('script');
${i?`script.setAttribute('data-clerk-publishable-key', '${i}');`:`script.setAttribute('data-clerk-frontend-api', '${r}');`}
${n?`script.setAttribute('data-clerk-publishable-key', '${n}');`:`script.setAttribute('data-clerk-frontend-api', '${r}');`}
script.async = true;
script.src = '${Qt(r,n)}';
script.src = '${Qt(r,i)}';
script.crossOrigin = 'anonymous';

@@ -55,3 +55,3 @@ script.addEventListener('load', startClerk);

</body>
`}async function at(t){var n;t.frontendApi=t.frontendApi||((n=oe(t.publishableKey))==null?void 0:n.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){var a;t.frontendApi=t.frontendApi||((a=oe(t.publishableKey))==null?void 0:a.frontendApi)||"";let{apiUrl:e,frontendApi:r,pkgVersion:n,publishableKey:i}=t,s=new URL(e);return s.pathname=o(s.pathname,R,"/public/interstitial"),s.searchParams.append("clerk_js_version",lt(r,n)),i?s.searchParams.append("publishable_key",i):s.searchParams.append("frontend_api",r),s.href}var lt=(t,e)=>!e&&it(t)?"staging":e?e.includes("next")?"next":e.split(".")[0]||"latest":"latest",Qt=(t,e)=>{let r=lt(t,e);return`https://${t}/npm/@clerk/clerk-js@${r}/dist/clerk.browser.js`};var ut=(i=>(i.SignedIn="signed-in",i.SignedOut="signed-out",i.Interstitial="interstitial",i.Unknown="unknown",i))(ut||{});async function qe(t,e){let{apiKey:r,secretKey:n,apiUrl:i,apiVersion:s,cookieToken:a,frontendApi:d,publishableKey:p,headerToken:g,loadSession:y,loadUser:h,loadOrganization:S}=t,{sid:m,org_id:f,sub:O}=e,{sessions:k,users:_,organizations:I}=te({apiKey:r,secretKey:n,apiUrl:i,apiVersion:s}),[P,A,x]=await Promise.all([y?k.getSession(m):Promise.resolve(void 0),h?_.getUser(O):Promise.resolve(void 0),S&&f?I.getOrganization({organizationId:f}):Promise.resolve(void 0)]),Ve=tt(e,{apiKey:r,apiUrl:i,apiVersion:s,token:a||g||"",session:P,user:A,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:()=>Ve}}function C(t,e,r=""){let{frontendApi:n,publishableKey:i}=t;return{status:"signed-out",reason:e,message:r,frontendApi:n,publishableKey:i,isSignedIn:!1,isInterstitial:!1,isUnknown:!1,toAuth:()=>rt({...t,status:"signed-out",reason:e,message:r})}}function M(t,e,r=""){let{frontendApi:n,publishableKey:i}=t;return{status:"interstitial",reason:e,message:r,frontendApi:n,publishableKey:i,isSignedIn:!1,isInterstitial:!0,isUnknown:!1,toAuth:()=>null}}function dt(t,e,r=""){let{frontendApi:n,publishableKey:i}=t;return{status:"unknown",reason:e,message:r,frontendApi:n,publishableKey:i,isSignedIn:!1,isInterstitial:!1,isUnknown:!0,toAuth:()=>null}}function ze({originURL:t,host:e,forwardedHost:r,forwardedPort:n,forwardedProto:i}){if(i&&i!==t.protocol)return!0;let s=Zt(r||e);return s.port=n||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,je={RS256:"SHA-256",RS384:"SHA-384",RS512:"SHA-512",ES256:"SHA-256",ES384:"SHA-384",ES512:"SHA-512"},Me="RSASSA-PKCS1-v1_5",We="ECDSA",tr={RS256:Me,RS384:Me,RS512:Me,ES256:We,ES384:We,ES512:We},rr=Object.keys(je);async function nr(t,e){let{header:r,signature:n,raw:i}=t,a=new TextEncoder().encode([i.header,i.payload].join(".")),d=await N.crypto.subtle.importKey("jwk",e,{name:tr[r.alg],hash:je[r.alg]},!1,["verify"]);return N.crypto.subtle.verify("RSASSA-PKCS1-v1_5",d,n,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,n,i]=e,s=new TextDecoder,a=JSON.parse(s.decode(Ke.parse(r,{loose:!0}))),d=JSON.parse(s.decode(Ke.parse(n,{loose:!0}))),p=Ke.parse(i,{loose:!0});return{header:a,payload:d,signature:p,raw:{header:r,payload:n,signature:i,text:t}}}async function ct(t,{audience:e,authorizedParties:r,clockSkewInSeconds:n=er,issuer:i,key:s}){let a=Le(t),{header:d,payload:p}=a,{typ:g,alg:y}=d;if(typeof g!="undefined"&&g!=="JWT")throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-invalid",message:`Invalid JWT type ${JSON.stringify(g)}. Expected "JWT".`});if(!je[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:f,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 i=="function"&&!i(f))throw new l({reason:"token-invalid-issuer",message:"Failed JWT issuer resolver. Make sure that the resolver returns a truthy value."});if(typeof i=="string"&&f&&f!==i)throw new l({reason:"token-invalid-issuer",message:`Invalid JWT issuer claim (iss) ${JSON.stringify(a.payload.iss)}. Expected "${i}".`});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()-n)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()+n)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()+n)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 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(!x)throw new l({reason:"token-invalid-signature",message:"JWT signature is invalid."});return p}var Pe={},mt=0;function xe(t){return Pe[t]}function gt(t,e=1e3*60*60){Pe[t.kid]=t,mt=Date.now(),e>=0&&setTimeout(()=>{t?delete Pe[t.kid]:Pe={}},e)}var pt="local",sr="-----BEGIN PUBLIC KEY-----",or="-----END PUBLIC KEY-----",ar="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA",lr="IDAQAB";function ft(t){if(!xe(pt)){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,"_");gt({kid:"local",kty:"RSA",alg:"RS256",n:e,e:"AQAB"},-1)}return xe(pt)}async function yt({apiKey:t,secretKey:e,apiUrl:r,apiVersion:n,issuer:i,kid:s,jwksCacheTtlInMs:a=1e3*60*60,skipJwksCache:d}){let p=!xe(s)&&cr();if(d||p){let y,h=e||t||"";if(r)y=()=>dr(r,h,n);else if(i)y=()=>ur(i);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=>gt(m,a))}let g=xe(s);if(!g)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 g}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=v,e,r=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 n=new URL(t);n.pathname=o(n.pathname,r,"/jwks");let i=await N.fetch(n.href,{headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"}});if(!i.ok)throw new l({action:"Contact support@clerk.dev",message:`Error loading Clerk JWKS from ${n.href} with code=${i.status}`,reason:"jwk-remote-failed-to-load"});return i.json()}function cr(){return Date.now()-mt>=300*1e3}async function ht(t,e){let{apiKey:r,secretKey:n,apiUrl:i,apiVersion:s,authorizedParties:a,clockSkewInSeconds:d,issuer:p,jwksCacheTtlInMs:g,jwtKey:y,skipJwksCache:h}=e,{header:S}=Le(t),{kid:m}=S,f;if(y)f=ft(y);else if(r||n)f=await yt(r?{apiUrl:i,apiKey:r,apiVersion:s,kid:m,jwksCacheTtlInMs:g,skipJwksCache:h}:{apiUrl:i,secretKey:n,apiVersion:s,kid:m,jwksCacheTtlInMs:g,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 ct(t,{authorizedParties:a,clockSkewInSeconds:d,key:f,issuer:p})}var bt=async t=>{let{apiKey:e,secretKey:r,userAgent:n}=t;if(Ie(r||e)&&!(n!=null&&n.startsWith("Mozilla/")))return C(t,"header-missing-non-browser")},St=async t=>{let{origin:e,host:r,forwardedHost:n,forwardedPort:i,forwardedProto:s}=t;if(e&&ze({originURL:new URL(e),host:r,forwardedHost:n,forwardedPort:i,forwardedProto:s}))return C(t,"header-missing-cors")},Ot=async t=>{let{apiKey:e,secretKey:r,clientUat:n}=t;if(Ie(r||e)&&!n)return M(t,"uat-missing")},kt=async t=>{let{apiKey:e,secretKey:r,referrer:n,host:i,forwardedHost:s,forwardedPort:a,forwardedProto:d}=t,p=n&&ze({originURL:new URL(n),host:i,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:n,cookieToken:i}=t;if(nt(r||e)&&!n&&!i)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,n=await xt(t,e),i=await qe(t,n),a=i.toAuth().sessionClaims.iat<Number.parseInt(r);return!r||a?M(t,"cookie-outdated"):i};async function Fe(t,e){for(let r of e){let n=await r(t);if(n)return n}return C(t,"unexpected-error")}async function xt(t,e){return ht(e,{...t,issuer:n=>n.startsWith("https://clerk.")||n.includes(".clerk.accounts")})}async function Tt(t){var i;t.frontendApi=t.frontendApi||((i=oe(t.publishableKey))==null?void 0:i.frontendApi)||"",t.apiUrl=t.apiUrl||v,t.apiVersion=t.apiVersion||R;async function e(){try{return await Fe(t,[wt])}catch(s){return n(s,"header")}}async function r(){try{return await Fe(t,[bt,St,Ot,kt,_t,It,At,Pt])}catch(s){return n(s,"cookie")}}function n(s,a){return s instanceof l?(s.tokenCarrier=a,["token-expired","token-not-active-yet"].includes(s.reason)?a==="header"?dt(t,s.reason,s.getFullMessage()):M(t,s.reason,s.getFullMessage()):C(t,s.reason,s.getFullMessage())):C(t,"unexpected-error",s.message)}return t.headerToken?e():r()}var De=t=>{let{frontendApi:e,isSignedIn:r,isInterstitial:n,reason:i,message:s,publishableKey:a}=t;return{frontendApi:e,isSignedIn:r,isInterstitial:n,reason:i,message:s,publishableKey:a}};function Jt(t){let{apiClient:e}=t,{apiKey:r="",secretKey:n="",jwtKey:i="",apiUrl:s=v,apiVersion:a=R,frontendApi:d="",publishableKey:p=""}=t.options;return{authenticateRequest:({apiKey:f,secretKey:O,frontendApi:k,publishableKey:_,jwtKey:I,...P})=>Tt({...P,apiKey:f||r,secretKey:O||n,apiUrl:s,apiVersion:a,frontendApi:k||d,publishableKey:_||p,jwtKey:I||i}),localInterstitial:Ue,remotePublicInterstitial:({frontendApi:f,publishableKey:O,...k})=>at({...k,apiUrl:s,frontendApi:f||d,publishableKey:O||p}),remotePrivateInterstitial:()=>e.interstitial.getInterstitial(),remotePublicInterstitialUrl:Ae,debugRequestState:De}}function js(t){let e={...t},r=te(e),n=Jt({options:e,apiClient:r});return{...r,...n,__unstable_options:e}}export{W as AllowlistIdentifier,ut as AuthStatus,js as Clerk,j as Client,L as DeletedObject,F as Email,q as EmailAddress,D as ExternalAccount,U as IdentificationLink,V as Invitation,B as OauthAccessToken,He 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,T as Verification,qt as constants,Jt as createAuthenticateRequest,De as debugRequestState,Le as decodeJwt,Ye as deserialize,nr as hasValidSignature,Ue as loadInterstitialFromLocal,Ze as prunePrivateMetadata,Mi as sanitizeAuthObject,tt as signedInAuthObject,rt as signedOutAuthObject,ct as verifyJwt,ht as verifyToken};
`}async function at(t){t.frontendApi=t.frontendApi||oe(t.publishableKey)?.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=t.frontendApi||oe(t.publishableKey)?.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",lt(r,i)),n?s.searchParams.append("publishable_key",n):s.searchParams.append("frontend_api",r),s.href}var lt=(t,e)=>!e&&it(t)?"staging":e?e.includes("next")?"next":e.split(".")[0]||"latest":"latest",Qt=(t,e)=>{let r=lt(t,e);return`https://${t}/npm/@clerk/clerk-js@${r}/dist/clerk.browser.js`};var ut=(n=>(n.SignedIn="signed-in",n.SignedOut="signed-out",n.Interstitial="interstitial",n.Unknown="unknown",n))(ut||{});async function qe(t,e){let{apiKey:r,secretKey:i,apiUrl:n,apiVersion:s,cookieToken:a,frontendApi:d,publishableKey:p,headerToken:g,loadSession:y,loadUser:h,loadOrganization:S}=t,{sid:m,org_id:f,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&&f?I.getOrganization({organizationId:f}):Promise.resolve(void 0)]),Ve=tt(e,{apiKey:r,apiUrl:n,apiVersion:s,token:a||g||"",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:()=>Ve}}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:()=>rt({...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 dt(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,je={RS256:"SHA-256",RS384:"SHA-384",RS512:"SHA-512",ES256:"SHA-256",ES384:"SHA-384",ES512:"SHA-512"},Me="RSASSA-PKCS1-v1_5",We="ECDSA",tr={RS256:Me,RS384:Me,RS512:Me,ES256:We,ES384:We,ES512:We},rr=Object.keys(je);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:je[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 ct(t,{audience:e,authorizedParties:r,clockSkewInSeconds:i=er,issuer:n,key:s}){let a=Le(t),{header:d,payload:p}=a,{typ:g,alg:y}=d;if(typeof g<"u"&&g!=="JWT")throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-invalid",message:`Invalid JWT type ${JSON.stringify(g)}. Expected "JWT".`});if(!je[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:f,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(f))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"&&f&&f!==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={},mt=0;function xe(t){return Pe[t]}function gt(t,e=1e3*60*60){Pe[t.kid]=t,mt=Date.now(),e>=0&&setTimeout(()=>{t?delete Pe[t.kid]:Pe={}},e)}var pt="local",sr="-----BEGIN PUBLIC KEY-----",or="-----END PUBLIC KEY-----",ar="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA",lr="IDAQAB";function ft(t){if(!xe(pt)){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,"_");gt({kid:"local",kty:"RSA",alg:"RS256",n:e,e:"AQAB"},-1)}return xe(pt)}async function yt({apiKey:t,secretKey:e,apiUrl:r,apiVersion:i,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(r)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=>gt(m,a))}let g=xe(s);if(!g)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 g}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=v,e,r=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()-mt>=300*1e3}async function ht(t,e){let{apiKey:r,secretKey:i,apiUrl:n,apiVersion:s,authorizedParties:a,clockSkewInSeconds:d,issuer:p,jwksCacheTtlInMs:g,jwtKey:y,skipJwksCache:h}=e,{header:S}=Le(t),{kid:m}=S,f;if(y)f=ft(y);else if(r||i)f=await yt(r?{apiUrl:n,apiKey:r,apiVersion:s,kid:m,jwksCacheTtlInMs:g,skipJwksCache:h}:{apiUrl:n,secretKey:i,apiVersion:s,kid:m,jwksCacheTtlInMs:g,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 ct(t,{authorizedParties:a,clockSkewInSeconds:d,key:f,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(nt(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 Fe(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=t.frontendApi||oe(t.publishableKey)?.frontendApi||"",t.apiUrl=t.apiUrl||v,t.apiVersion=t.apiVersion||R;async function e(){try{return await Fe(t,[wt])}catch(n){return i(n,"header")}}async function r(){try{return await Fe(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"?dt(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 De=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:f,secretKey:O,frontendApi:k,publishableKey:_,jwtKey:I,...w})=>Tt({...w,apiKey:f||r,secretKey:O||i,apiUrl:s,apiVersion:a,frontendApi:k||d,publishableKey:_||p,jwtKey:I||n}),localInterstitial:Ue,remotePublicInterstitial:({frontendApi:f,publishableKey:O,...k})=>at({...k,apiUrl:s,frontendApi:f||d,publishableKey:O||p}),remotePrivateInterstitial:()=>e.interstitial.getInterstitial(),remotePublicInterstitialUrl:Ae,debugRequestState:De}}function js(t){let e={...t},r=te(e),i=Jt({options:e,apiClient:r});return{...r,...i,__unstable_options:e}}export{W as AllowlistIdentifier,ut as AuthStatus,js as Clerk,j as Client,L as DeletedObject,F as Email,q as EmailAddress,D as ExternalAccount,U as IdentificationLink,V as Invitation,B as OauthAccessToken,He 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,De as debugRequestState,Le as decodeJwt,Ye as deserialize,nr as hasValidSignature,Ue as loadInterstitialFromLocal,Ze as prunePrivateMetadata,Mi as sanitizeAuthObject,tt as signedInAuthObject,rt as signedOutAuthObject,ct 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 Wt=Object.getOwnPropertyNames;var jt=Object.getPrototypeOf,Lt=Object.prototype.hasOwnProperty;var Ft=(t,e)=>{for(var r in e)ae(t,r,{get:e[r],enumerable:!0})},it=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Wt(e))!Lt.call(t,i)&&i!==r&&ae(t,i,{get:()=>e[i],enumerable:!(n=Mt(e,i))||n.enumerable});return t};var le=(t,e,r)=>(r=t!=null?Kt(jt(t)):{},it(e||!t||!t.__esModule?ae(r,"default",{value:t,enumerable:!0}):r,t)),Dt=t=>it(ae({},"__esModule",{value:!0}),t);var wr={};Ft(wr,{AllowlistIdentifier:()=>M,AuthStatus:()=>Ge,Clerk:()=>Ar,Client:()=>W,DeletedObject:()=>j,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:()=>P,constants:()=>lt,createAuthenticateRequest:()=>rt,debugRequestState:()=>ve,decodeJwt:()=>Re,deserialize:()=>je,hasValidSignature:()=>kt,loadInterstitialFromLocal:()=>Te,prunePrivateMetadata:()=>Fe,sanitizeAuthObject:()=>ir,signedInAuthObject:()=>De,signedOutAuthObject:()=>Ve,verifyJwt:()=>Ze,verifyToken:()=>et});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 w="/organizations",ye=class extends c{async getOrganizationList(e){return this.request({method:"GET",path:w,queryParams:e})}async createOrganization(e){return this.request({method:"POST",path:w,bodyParams:e})}async getOrganization(e){let r="organizationId"in e?e.organizationId:e.slug;return this.requireId(r),this.request({method:"GET",path:o(w,r)})}async updateOrganization(e,r){return this.requireId(e),this.request({method:"PATCH",path:o(w,e),bodyParams:r})}async updateOrganizationMetadata(e,r){return this.requireId(e),this.request({method:"PATCH",path:o(w,e,"metadata"),bodyParams:r})}async deleteOrganization(e){return this.request({method:"DELETE",path:o(w,e)})}async getOrganizationMembershipList(e){let{organizationId:r,limit:n,offset:i}=e;return this.requireId(r),this.request({method:"GET",path:o(w,r,"memberships"),queryParams:{limit:n,offset:i}})}async createOrganizationMembership(e){let{organizationId:r,userId:n,role:i}=e;return this.requireId(r),this.request({method:"POST",path:o(w,r,"memberships"),bodyParams:{userId:n,role:i}})}async updateOrganizationMembership(e){let{organizationId:r,userId:n,role:i}=e;return this.requireId(r),this.request({method:"PATCH",path:o(w,r,"memberships",n),bodyParams:{role:i}})}async updateOrganizationMembershipMetadata(e){let{organizationId:r,userId:n,publicMetadata:i,privateMetadata:s}=e;return this.request({method:"PATCH",path:o(w,r,"memberships",n,"metadata"),bodyParams:{publicMetadata:i,privateMetadata:s}})}async deleteOrganizationMembership(e){let{organizationId:r,userId:n}=e;return this.requireId(r),this.request({method:"DELETE",path:o(w,r,"memberships",n)})}async getPendingOrganizationInvitationList(e){let{organizationId:r,limit:n,offset:i}=e;return this.requireId(r),this.request({method:"GET",path:o(w,r,"invitations","pending"),queryParams:{limit:n,offset:i}})}async createOrganizationInvitation(e){let{organizationId:r,...n}=e;return this.requireId(r),this.request({method:"POST",path:o(w,r,"invitations"),bodyParams:{...n}})}async revokeOrganizationInvitation(e){let{organizationId:r,invitationId:n,requestingUserId:i}=e;return this.requireId(r),this.request({method:"POST",path:o(w,r,"invitations",n,"revoke"),bodyParams:{requestingUserId:i}})}};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,n)=>(this.requireId(r),this.request({method:"POST",path:o(ne,r,"verify"),bodyParams:{token:n}}));this.getToken=async(r,n)=>(this.requireId(r),(await this.request({method:"POST",path:o(ne,r,"tokens",n||"")})).jwt)}};var st="/sign_in_tokens",_e=class extends c{async createSignInToken(e){return this.request({method:"POST",path:st,bodyParams:e})}async revokeSignInToken(e){return this.requireId(e),this.request({method:"POST",path:o(st,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:n,offset:i}=e;return this.requireId(r),this.request({method:"GET",path:o(J,r,"organization_memberships"),queryParams:{limit:n,offset:i}})}};var ct=le(require("deepmerge")),Le=le(require("snakecase-keys"));var K="https://api.clerk.dev",R="v1",ot="@clerk/backend";var $t={AuthStatus:"__clerkAuthStatus"},Ht={Session:"__session",ClientUat:"__client_uat"},at={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:at.AuthStatus},lt={Attributes:$t,Cookies:Ht,Headers:at,SearchParams:Yt};var ut=le(require("#crypto")),dt=le(require("#fetch")),Xt=dt.default.bind(globalThis),Qt={crypto:ut.default,fetch:Xt},N=Qt;var M=class{constructor(e,r,n,i,s){this.id=e;this.identifier=r;this.createdAt=n;this.updatedAt=i;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,n,i,s,a,d,p,g){this.id=e;this.clientId=r;this.userId=n;this.status=i;this.lastActiveAt=s;this.expireAt=a;this.abandonAt=d;this.createdAt=p;this.updatedAt=g}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 W=class{constructor(e,r,n,i,s,a,d,p){this.id=e;this.sessionIds=r;this.sessions=n;this.signInId=i;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=>C.fromJSON(r)),e.sign_in_id,e.sign_up_id,e.last_active_session_id,e.created_at,e.updated_at)}};var j=class{constructor(e,r,n,i){this.object=e;this.id=r;this.slug=n;this.deleted=i}static fromJSON(e){return new j(e.object,e.id||null,e.slug||null,e.deleted)}};var L=class{constructor(e,r,n,i,s,a,d){this.id=e;this.fromEmailName=r;this.emailAddressId=n;this.toEmailAddress=i;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 P=class{constructor(e,r,n=null,i=null,s=null,a=null){this.status=e;this.strategy=r;this.externalVerificationRedirectURL=n;this.attempts=i;this.expireAt=s;this.nonce=a}static fromJSON(e){return new P(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,n,i){this.id=e;this.emailAddress=r;this.verification=n;this.linkedTo=i}static fromJSON(e){return new E(e.id,e.email_address,e.verification&&P.fromJSON(e.verification),e.linked_to.map(r=>v.fromJSON(r)))}};var F=class{constructor(e,r,n,i,s,a,d,p,g,y,h={},S,m){this.id=e;this.provider=r;this.identificationId=n;this.externalId=i;this.approvedScopes=s;this.emailAddress=a;this.firstName=d;this.lastName=p;this.picture=g;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&&P.fromJSON(e.verification))}};var D=class{constructor(e,r,n,i,s,a){this.id=e;this.emailAddress=r;this.publicMetadata=n;this.createdAt=i;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,n={},i,s,a){this.provider=e;this.token=r;this.publicMetadata=n;this.label=i;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,n,i,s,a,d={},p={}){this.id=e;this.name=r;this.slug=n;this.logoUrl=i;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,n,i,s,a,d){this.id=e;this.emailAddress=r;this.role=n;this.organizationId=i;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,n={},i={},s,a,d,p){this.id=e;this.role=r;this.publicMetadata=n;this.privateMetadata=i;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,n,i,s){this.identifier=e;this.firstName=r;this.lastName=n;this.profileImageUrl=i;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,n,i,s,a){this.id=e;this.phoneNumber=r;this.reservedForSecondFactor=n;this.defaultSecondFactor=i;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&&P.fromJSON(e.verification),e.linked_to.map(r=>v.fromJSON(r)))}};var $=class{constructor(e,r,n,i){this.id=e;this.url=r;this.createdAt=n;this.updatedAt=i}static fromJSON(e){return new $(e.id,e.url,e.created_at,e.updated_at)}};var H=class{constructor(e,r,n,i,s,a){this.id=e;this.userId=r;this.token=n;this.status=i;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,n,i,s,a){this.id=e;this.fromPhoneNumber=r;this.toPhoneNumber=n;this.message=i;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,n){this.id=e;this.web3Wallet=r;this.verification=n}static fromJSON(e){return new te(e.id,e.web3_wallet,e.verification&&P.fromJSON(e.verification))}};var Q=class{constructor(e,r,n,i,s,a,d,p,g,y,h,S,m,f,O,k,_,I,x,A={},T={},b={},u=[],Ee=[],nt=[],Pr=[]){this.id=e;this.passwordEnabled=r;this.totpEnabled=n;this.backupCodeEnabled=i;this.twoFactorEnabled=s;this.banned=a;this.createdAt=d;this.updatedAt=p;this.profileImageUrl=g;this.gender=y;this.birthday=h;this.primaryEmailAddressId=S;this.primaryPhoneNumberId=m;this.primaryWeb3WalletId=f;this.lastSignInAt=O;this.externalId=k;this.username=_;this.firstName=I;this.lastName=x;this.publicMetadata=A;this.privateMetadata=T;this.unsafeMetadata=b;this.emailAddresses=u;this.phoneNumbers=Ee;this.web3Wallets=nt;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 je(t){return Array.isArray(t)?t.map(e=>We(e)):Zt(t)?t.data.map(e=>We(e)):We(t)}function Zt(t){return t.data!==void 0}function er(t){return t.total_count}function We(t){if(typeof t!="string"&&"object"in t&&"deleted"in t)return j.fromJSON(t);switch(t.object){case"allowlist_identifier":return M.fromJSON(t);case"client":return W.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:n,status:i,statusText:s}=await t(...e);if(n===null)return r;throw new ie(s||"",{data:n,status:i||""})};function pt(t){return tr(async r=>{let{apiKey:n,secretKey:i,apiUrl:s=K,apiVersion:a=R,userAgent:d=ot,httpOptions:p={}}=t,{path:g,method:y,queryParams:h,headerParams:S,bodyParams:m}=r,f=i||n;if(!f)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,g),k=new URL(O);if(h){let T=(0,Le.default)({...h});for(let[b,u]of Object.entries(T))u&&[u].flat().forEach(Ee=>k.searchParams.append(b,Ee))}let _={Authorization:`Bearer ${f}`,"Content-Type":"application/json","Clerk-Backend-SDK":d,...S},x=y!=="GET"&&m&&Object.keys(m).length>0?{body:JSON.stringify((0,Le.default)(m,{deep:!1}))}:null,A;try{A=await N.fetch(k.href,(0,ct.default)(p,{method:y,headers:_,...x}));let b=await(_&&_["Content-Type"]==="application/json"?A.json():A.text());if(!A.ok)throw b;return{data:je(b),errors:null}}catch(T){return T instanceof Error?{data:null,errors:[{code:"unexpected_error",message:T.message||"Unexpected error"}]}:{data:null,errors:rr(T),status:A==null?void 0:A.status,statusText:A==null?void 0:A.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){var e,r;return{code:t.code,message:t.message,longMessage:t.long_message,meta:{paramName:(e=t==null?void 0:t.meta)==null?void 0:e.param_name,sessionId:(r=t==null?void 0:t.meta)==null?void 0:r.session_id}}}var ie=class extends Error{constructor(r,{data:n,status:i}){super(r);Object.setPrototypeOf(this,ie.prototype),this.clerkError=!0,this.message=r,this.status=i,this.errors=n}};function re(t){let e=pt(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 mt=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:n,sid:i,org_id:s,org_role:a,org_slug:d,sub:p}=t,{apiKey:g,secretKey:y,apiUrl:h,apiVersion:S,token:m,session:f,user:O,organization:k}=e,{sessions:_}=re({apiKey:g,secretKey:y,apiUrl:h,apiVersion:S}),I=sr({sessionId:i,sessionToken:m,fetcher:(...x)=>_.getToken(...x)});return{actor:n,sessionClaims:t,sessionId:i,session:f,userId:p,user:O,orgId:s,orgRole:a,orgSlug:d,organization:k,getToken:I,debug:mt(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:mt(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:n}=t||{};return async(i={})=>n?i.template?e(n,i.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(n){if(e>=r)throw n;return await or(2**e*100),se(t,e+1)}}function we(t){return t.startsWith("test_")||t.startsWith("sk_test_")}function gt(t){return t.startsWith("live_")||t.startsWith("sk_live_")}function ft(t){return t.endsWith(".lclstage.dev")||t.endsWith(".stgstage.dev")||t.endsWith(".clerkstage.dev")||t.endsWith(".accountsstage.dev")}var yt="pk_live_",lr="pk_test_";function oe(t){if(t=t||"",!ur(t))return null;let e=t.startsWith(yt)?"production":"development",r=ht(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(yt)||t.startsWith(lr),r=ht(t.split("_")[2]||"").endsWith("$");return e&&r}var ht=t=>typeof atob!="undefined"&&typeof atob=="function"?atob(t):typeof Buffer!="undefined"?new Buffer(t,"base64").toString():t;var l=class extends Error{constructor({action:r,message:n,reason:i}){super(n);Object.setPrototypeOf(this,l.prototype),this.reason=i,this.message=n,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:n,publishableKey:i}=t;return`
"use strict";var Kt=Object.create;var ae=Object.defineProperty;var Mt=Object.getOwnPropertyDescriptor;var Wt=Object.getOwnPropertyNames;var jt=Object.getPrototypeOf,Lt=Object.prototype.hasOwnProperty;var Ft=(t,e)=>{for(var r in e)ae(t,r,{get:e[r],enumerable:!0})},it=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Wt(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(jt(t)):{},it(e||!t||!t.__esModule?ae(r,"default",{value:t,enumerable:!0}):r,t)),Dt=t=>it(ae({},"__esModule",{value:!0}),t);var wr={};Ft(wr,{AllowlistIdentifier:()=>M,AuthStatus:()=>Ge,Clerk:()=>Ar,Client:()=>W,DeletedObject:()=>j,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:()=>lt,createAuthenticateRequest:()=>rt,debugRequestState:()=>ve,decodeJwt:()=>Re,deserialize:()=>je,hasValidSignature:()=>kt,loadInterstitialFromLocal:()=>Te,prunePrivateMetadata:()=>Fe,sanitizeAuthObject:()=>ir,signedInAuthObject:()=>De,signedOutAuthObject:()=>Ve,verifyJwt:()=>Ze,verifyToken:()=>et});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 st="/sign_in_tokens",_e=class extends c{async createSignInToken(e){return this.request({method:"POST",path:st,bodyParams:e})}async revokeSignInToken(e){return this.requireId(e),this.request({method:"POST",path:o(st,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 ct=le(require("deepmerge")),Le=le(require("snakecase-keys"));var K="https://api.clerk.dev",R="v1",ot="@clerk/backend";var $t={AuthStatus:"__clerkAuthStatus"},Ht={Session:"__session",ClientUat:"__client_uat"},at={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:at.AuthStatus},lt={Attributes:$t,Cookies:Ht,Headers:at,SearchParams:Yt};var ut=le(require("#crypto")),dt=le(require("#fetch")),Xt=dt.default.bind(globalThis),Qt={crypto:ut.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,g){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=g}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 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=>C.fromJSON(r)),e.sign_in_id,e.sign_up_id,e.last_active_session_id,e.created_at,e.updated_at)}};var j=class{constructor(e,r,i,n){this.object=e;this.id=r;this.slug=i;this.deleted=n}static fromJSON(e){return new j(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,g,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=g;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,g,y,h,S,m,f,O,k,_,I,P,T={},x={},b={},u=[],Ee=[],nt=[],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=g;this.gender=y;this.birthday=h;this.primaryEmailAddressId=S;this.primaryPhoneNumberId=m;this.primaryWeb3WalletId=f;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=nt;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 je(t){return Array.isArray(t)?t.map(e=>We(e)):Zt(t)?t.data.map(e=>We(e)):We(t)}function Zt(t){return t.data!==void 0}function er(t){return t.total_count}function We(t){if(typeof t!="string"&&"object"in t&&"deleted"in t)return j.fromJSON(t);switch(t.object){case"allowlist_identifier":return M.fromJSON(t);case"client":return W.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 pt(t){return tr(async r=>{let{apiKey:i,secretKey:n,apiUrl:s=K,apiVersion:a=R,userAgent:d=ot,httpOptions:p={}}=t,{path:g,method:y,queryParams:h,headerParams:S,bodyParams:m}=r,f=n||i;if(!f)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,g),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 ${f}`,"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,ct.default)(p,{method:y,headers:_,...P}));let b=await(_&&_["Content-Type"]==="application/json"?T.json():T.text());if(!T.ok)throw b;return{data:je(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=pt(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 mt=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:g,secretKey:y,apiUrl:h,apiVersion:S,token:m,session:f,user:O,organization:k}=e,{sessions:_}=re({apiKey:g,secretKey:y,apiUrl:h,apiVersion:S}),I=sr({sessionId:n,sessionToken:m,fetcher:(...P)=>_.getToken(...P)});return{actor:i,sessionClaims:t,sessionId:n,session:f,userId:p,user:O,orgId:s,orgRole:a,orgSlug:d,organization:k,getToken:I,debug:mt(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:mt(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 gt(t){return t.startsWith("live_")||t.startsWith("sk_live_")}function ft(t){return t.endsWith(".lclstage.dev")||t.endsWith(".stgstage.dev")||t.endsWith(".clerkstage.dev")||t.endsWith(".accountsstage.dev")}var yt="pk_live_",lr="pk_test_";function oe(t){if(t=t||"",!ur(t))return null;let e=t.startsWith(yt)?"production":"development",r=ht(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(yt)||t.startsWith(lr),r=ht(t.split("_")[2]||"").endsWith("$");return e&&r}var ht=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>

@@ -45,5 +45,5 @@ <meta charset="UTF-8" />

const script = document.createElement('script');
${i?`script.setAttribute('data-clerk-publishable-key', '${i}');`:`script.setAttribute('data-clerk-frontend-api', '${r}');`}
${n?`script.setAttribute('data-clerk-publishable-key', '${n}');`:`script.setAttribute('data-clerk-frontend-api', '${r}');`}
script.async = true;
script.src = '${dr(r,n)}';
script.src = '${dr(r,i)}';
script.crossOrigin = 'anonymous';

@@ -55,3 +55,3 @@ script.addEventListener('load', startClerk);

</body>
`}async function bt(t){var n;t.frontendApi=t.frontendApi||((n=oe(t.publishableKey))==null?void 0:n.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){var a;t.frontendApi=t.frontendApi||((a=oe(t.publishableKey))==null?void 0:a.frontendApi)||"";let{apiUrl:e,frontendApi:r,pkgVersion:n,publishableKey:i}=t,s=new URL(e);return s.pathname=o(s.pathname,R,"/public/interstitial"),s.searchParams.append("clerk_js_version",St(r,n)),i?s.searchParams.append("publishable_key",i):s.searchParams.append("frontend_api",r),s.href}var St=(t,e)=>!e&&ft(t)?"staging":e?e.includes("next")?"next":e.split(".")[0]||"latest":"latest",dr=(t,e)=>{let r=St(t,e);return`https://${t}/npm/@clerk/clerk-js@${r}/dist/clerk.browser.js`};var Ge=(i=>(i.SignedIn="signed-in",i.SignedOut="signed-out",i.Interstitial="interstitial",i.Unknown="unknown",i))(Ge||{});async function $e(t,e){let{apiKey:r,secretKey:n,apiUrl:i,apiVersion:s,cookieToken:a,frontendApi:d,publishableKey:p,headerToken:g,loadSession:y,loadUser:h,loadOrganization:S}=t,{sid:m,org_id:f,sub:O}=e,{sessions:k,users:_,organizations:I}=re({apiKey:r,secretKey:n,apiUrl:i,apiVersion:s}),[x,A,T]=await Promise.all([y?k.getSession(m):Promise.resolve(void 0),h?_.getUser(O):Promise.resolve(void 0),S&&f?I.getOrganization({organizationId:f}):Promise.resolve(void 0)]),nt=De(e,{apiKey:r,apiUrl:i,apiVersion:s,token:a||g||"",session:x,user:A,organization:T},{...t,status:"signed-in"});return{status:"signed-in",reason:null,message:null,frontendApi:d,publishableKey:p,isSignedIn:!0,isInterstitial:!1,isUnknown:!1,toAuth:()=>nt}}function z(t,e,r=""){let{frontendApi:n,publishableKey:i}=t;return{status:"signed-out",reason:e,message:r,frontendApi:n,publishableKey:i,isSignedIn:!1,isInterstitial:!1,isUnknown:!1,toAuth:()=>Ve({...t,status:"signed-out",reason:e,message:r})}}function Z(t,e,r=""){let{frontendApi:n,publishableKey:i}=t;return{status:"interstitial",reason:e,message:r,frontendApi:n,publishableKey:i,isSignedIn:!1,isInterstitial:!0,isUnknown:!1,toAuth:()=>null}}function Ot(t,e,r=""){let{frontendApi:n,publishableKey:i}=t;return{status:"unknown",reason:e,message:r,frontendApi:n,publishableKey:i,isSignedIn:!1,isInterstitial:!1,isUnknown:!0,toAuth:()=>null}}function He({originURL:t,host:e,forwardedHost:r,forwardedPort:n,forwardedProto:i}){if(i&&i!==t.protocol)return!0;let s=cr(r||e);return s.port=n||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 kt(t,e){let{header:r,signature:n,raw:i}=t,a=new TextEncoder().encode([i.header,i.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,n,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,n,i]=e,s=new TextDecoder,a=JSON.parse(s.decode(Je.base64url.parse(r,{loose:!0}))),d=JSON.parse(s.decode(Je.base64url.parse(n,{loose:!0}))),p=Je.base64url.parse(i,{loose:!0});return{header:a,payload:d,signature:p,raw:{header:r,payload:n,signature:i,text:t}}}async function Ze(t,{audience:e,authorizedParties:r,clockSkewInSeconds:n=pr,issuer:i,key:s}){let a=Re(t),{header:d,payload:p}=a,{typ:g,alg:y}=d;if(typeof g!="undefined"&&g!=="JWT")throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-invalid",message:`Invalid JWT type ${JSON.stringify(g)}. 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:f,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 i=="function"&&!i(f))throw new l({reason:"token-invalid-issuer",message:"Failed JWT issuer resolver. Make sure that the resolver returns a truthy value."});if(typeof i=="string"&&f&&f!==i)throw new l({reason:"token-invalid-issuer",message:`Invalid JWT issuer claim (iss) ${JSON.stringify(a.payload.iss)}. Expected "${i}".`});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()),x=new Date(0);if(x.setUTCSeconds(k),x.getTime()<=I.getTime()-n)throw new l({reason:"token-expired",message:`JWT is expired. Expiry date: ${x}, 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()+n)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()+n)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 T;try{T=await kt(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(!T)throw new l({reason:"token-invalid-signature",message:"JWT signature is invalid."});return p}var Ne={},It=0;function Ce(t){return Ne[t]}function At(t,e=1e3*60*60){Ne[t.kid]=t,It=Date.now(),e>=0&&setTimeout(()=>{t?delete Ne[t.kid]:Ne={}},e)}var _t="local",yr="-----BEGIN PUBLIC KEY-----",hr="-----END PUBLIC KEY-----",br="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA",Sr="IDAQAB";function wt(t){if(!Ce(_t)){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,"_");At({kid:"local",kty:"RSA",alg:"RS256",n:e,e:"AQAB"},-1)}return Ce(_t)}async function Pt({apiKey:t,secretKey:e,apiUrl:r,apiVersion:n,issuer:i,kid:s,jwksCacheTtlInMs:a=1e3*60*60,skipJwksCache:d}){let p=!Ce(s)&&_r();if(d||p){let y,h=e||t||"";if(r)y=()=>kr(r,h,n);else if(i)y=()=>Or(i);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=>At(m,a))}let g=Ce(s);if(!g)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 g}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=K,e,r=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 n=new URL(t);n.pathname=o(n.pathname,r,"/jwks");let i=await N.fetch(n.href,{headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"}});if(!i.ok)throw new l({action:"Contact support@clerk.dev",message:`Error loading Clerk JWKS from ${n.href} with code=${i.status}`,reason:"jwk-remote-failed-to-load"});return i.json()}function _r(){return Date.now()-It>=300*1e3}async function et(t,e){let{apiKey:r,secretKey:n,apiUrl:i,apiVersion:s,authorizedParties:a,clockSkewInSeconds:d,issuer:p,jwksCacheTtlInMs:g,jwtKey:y,skipJwksCache:h}=e,{header:S}=Re(t),{kid:m}=S,f;if(y)f=wt(y);else if(r||n)f=await Pt(r?{apiUrl:i,apiKey:r,apiVersion:s,kid:m,jwksCacheTtlInMs:g,skipJwksCache:h}:{apiUrl:i,secretKey:n,apiVersion:s,kid:m,jwksCacheTtlInMs:g,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:f,issuer:p})}var xt=async t=>{let{apiKey:e,secretKey:r,userAgent:n}=t;if(we(r||e)&&!(n!=null&&n.startsWith("Mozilla/")))return z(t,"header-missing-non-browser")},Tt=async t=>{let{origin:e,host:r,forwardedHost:n,forwardedPort:i,forwardedProto:s}=t;if(e&&He({originURL:new URL(e),host:r,forwardedHost:n,forwardedPort:i,forwardedProto:s}))return z(t,"header-missing-cors")},Jt=async t=>{let{apiKey:e,secretKey:r,clientUat:n}=t;if(we(r||e)&&!n)return Z(t,"uat-missing")},Rt=async t=>{let{apiKey:e,secretKey:r,referrer:n,host:i,forwardedHost:s,forwardedPort:a,forwardedProto:d}=t,p=n&&He({originURL:new URL(n),host:i,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:n,cookieToken:i}=t;if(gt(r||e)&&!n&&!i)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,n=await qt(t,e),i=await $e(t,n),a=i.toAuth().sessionClaims.iat<Number.parseInt(r);return!r||a?Z(t,"cookie-outdated"):i};async function tt(t,e){for(let r of e){let n=await r(t);if(n)return n}return z(t,"unexpected-error")}async function qt(t,e){return et(e,{...t,issuer:n=>n.startsWith("https://clerk.")||n.includes(".clerk.accounts")})}async function zt(t){var i;t.frontendApi=t.frontendApi||((i=oe(t.publishableKey))==null?void 0:i.frontendApi)||"",t.apiUrl=t.apiUrl||K,t.apiVersion=t.apiVersion||R;async function e(){try{return await tt(t,[Et])}catch(s){return n(s,"header")}}async function r(){try{return await tt(t,[xt,Tt,Jt,Rt,Nt,Ct,vt,Ut])}catch(s){return n(s,"cookie")}}function n(s,a){return s instanceof l?(s.tokenCarrier=a,["token-expired","token-not-active-yet"].includes(s.reason)?a==="header"?Ot(t,s.reason,s.getFullMessage()):Z(t,s.reason,s.getFullMessage()):z(t,s.reason,s.getFullMessage())):z(t,"unexpected-error",s.message)}return t.headerToken?e():r()}var ve=t=>{let{frontendApi:e,isSignedIn:r,isInterstitial:n,reason:i,message:s,publishableKey:a}=t;return{frontendApi:e,isSignedIn:r,isInterstitial:n,reason:i,message:s,publishableKey:a}};function rt(t){let{apiClient:e}=t,{apiKey:r="",secretKey:n="",jwtKey:i="",apiUrl:s=K,apiVersion:a=R,frontendApi:d="",publishableKey:p=""}=t.options;return{authenticateRequest:({apiKey:f,secretKey:O,frontendApi:k,publishableKey:_,jwtKey:I,...x})=>zt({...x,apiKey:f||r,secretKey:O||n,apiUrl:s,apiVersion:a,frontendApi:k||d,publishableKey:_||p,jwtKey:I||i}),localInterstitial:Te,remotePublicInterstitial:({frontendApi:f,publishableKey:O,...k})=>bt({...k,apiUrl:s,frontendApi:f||d,publishableKey:O||p}),remotePrivateInterstitial:()=>e.interstitial.getInterstitial(),remotePublicInterstitialUrl:Pe,debugRequestState:ve}}function Ar(t){let e={...t},r=re(e),n=rt({options:e,apiClient:r});return{...r,...n,__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 bt(t){t.frontendApi=t.frontendApi||oe(t.publishableKey)?.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=t.frontendApi||oe(t.publishableKey)?.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",St(r,i)),n?s.searchParams.append("publishable_key",n):s.searchParams.append("frontend_api",r),s.href}var St=(t,e)=>!e&&ft(t)?"staging":e?e.includes("next")?"next":e.split(".")[0]||"latest":"latest",dr=(t,e)=>{let r=St(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:g,loadSession:y,loadUser:h,loadOrganization:S}=t,{sid:m,org_id:f,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&&f?I.getOrganization({organizationId:f}):Promise.resolve(void 0)]),nt=De(e,{apiKey:r,apiUrl:n,apiVersion:s,token:a||g||"",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:()=>nt}}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 Ot(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 kt(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:g,alg:y}=d;if(typeof g<"u"&&g!=="JWT")throw new l({action:"Make sure that this is a valid Clerk generate JWT.",reason:"token-invalid",message:`Invalid JWT type ${JSON.stringify(g)}. 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:f,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(f))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"&&f&&f!==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 kt(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={},It=0;function Ce(t){return Ne[t]}function At(t,e=1e3*60*60){Ne[t.kid]=t,It=Date.now(),e>=0&&setTimeout(()=>{t?delete Ne[t.kid]:Ne={}},e)}var _t="local",yr="-----BEGIN PUBLIC KEY-----",hr="-----END PUBLIC KEY-----",br="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA",Sr="IDAQAB";function wt(t){if(!Ce(_t)){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,"_");At({kid:"local",kty:"RSA",alg:"RS256",n:e,e:"AQAB"},-1)}return Ce(_t)}async function Pt({apiKey:t,secretKey:e,apiUrl:r,apiVersion:i,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(r)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=>At(m,a))}let g=Ce(s);if(!g)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 g}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=K,e,r=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()-It>=300*1e3}async function et(t,e){let{apiKey:r,secretKey:i,apiUrl:n,apiVersion:s,authorizedParties:a,clockSkewInSeconds:d,issuer:p,jwksCacheTtlInMs:g,jwtKey:y,skipJwksCache:h}=e,{header:S}=Re(t),{kid:m}=S,f;if(y)f=wt(y);else if(r||i)f=await Pt(r?{apiUrl:n,apiKey:r,apiVersion:s,kid:m,jwksCacheTtlInMs:g,skipJwksCache:h}:{apiUrl:n,secretKey:i,apiVersion:s,kid:m,jwksCacheTtlInMs:g,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:f,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(gt(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 tt(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 et(e,{...t,issuer:i=>i.startsWith("https://clerk.")||i.includes(".clerk.accounts")})}async function zt(t){t.frontendApi=t.frontendApi||oe(t.publishableKey)?.frontendApi||"",t.apiUrl=t.apiUrl||K,t.apiVersion=t.apiVersion||R;async function e(){try{return await tt(t,[Et])}catch(n){return i(n,"header")}}async function r(){try{return await tt(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"?Ot(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 rt(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:f,secretKey:O,frontendApi:k,publishableKey:_,jwtKey:I,...P})=>zt({...P,apiKey:f||r,secretKey:O||i,apiUrl:s,apiVersion:a,frontendApi:k||d,publishableKey:_||p,jwtKey:I||n}),localInterstitial:Te,remotePublicInterstitial:({frontendApi:f,publishableKey:O,...k})=>bt({...k,apiUrl:s,frontendApi:f||d,publishableKey:O||p}),remotePrivateInterstitial:()=>e.interstitial.getInterstitial(),remotePublicInterstitialUrl:Pe,debugRequestState:ve}}function Ar(t){let e={...t},r=re(e),i=rt({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

@@ -1,14 +0,2 @@

let fetch;
try {
// Pre-node14 runtimes do not support the node: prefix
// this package uses internally, and they throw.
// This package is preferred as it does not polyfill the native fetch
// if it's supported by the runtime
// https://github.com/node-fetch/node-fetch/issues/1367
fetch = require('node-fetch-native');
} catch (e) {
// Otherwise, we will fall back to this lib
fetch = require('node-fetch');
}
const fetch = require('node-fetch-native');
module.exports = fetch;
{
"name": "@clerk/backend",
"version": "0.4.3-staging.1",
"version": "0.4.3",
"license": "MIT",

@@ -31,3 +31,2 @@ "description": "Clerk Backend SDK - REST Client for Backend API & JWT verification utilities",

"deepmerge": "4.2.2",
"node-fetch": "2.6.8",
"node-fetch-native": "1.0.1",

@@ -79,3 +78,3 @@ "rfc4648": "1.5.2",

},
"gitHead": "6e042c89ab18d00e50a66a23409df9c59583ba69"
"gitHead": "67f4db21c10cf0c6527ee5c02d3aca90b4ccee70"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc