UNPKG

@passageidentity/passage-node

Version:

Passkey Complete for Node.js - Integrate into your Node.js API or service to enable a completely passwordless standalone auth solution with Passage by 1Password

2 lines (1 loc) 24.6 kB
"use strict";var b=Object.defineProperty,me=Object.defineProperties,ye=Object.getOwnPropertyDescriptor,he=Object.getOwnPropertyDescriptors,Se=Object.getOwnPropertyNames,v=Object.getOwnPropertySymbols;var V=Object.prototype.hasOwnProperty,Te=Object.prototype.propertyIsEnumerable;var H=(e,r,n)=>r in e?b(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n,l=(e,r)=>{for(var n in r||(r={}))V.call(r,n)&&H(e,n,r[n]);if(v)for(var n of v(r))Te.call(r,n)&&H(e,n,r[n]);return e},y=(e,r)=>me(e,he(r));var Ue=(e,r)=>{for(var n in r)b(e,n,{get:r[n],enumerable:!0})},Ae=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of Se(r))!V.call(e,i)&&i!==n&&b(e,i,{get:()=>r[i],enumerable:!(t=ye(r,i))||t.enumerable});return e};var Oe=e=>Ae(b({},"__esModule",{value:!0}),e);var o=(e,r,n)=>new Promise((t,i)=>{var s=d=>{try{a(n.next(d))}catch(O){i(O)}},c=d=>{try{a(n.throw(d))}catch(O){i(O)}},a=d=>d.done?t(d.value):Promise.resolve(d.value).then(s,c);a((n=n.apply(e,r)).next())});var tr={};Ue(tr,{Auth:()=>I,MagicLinkChannel:()=>k,MagicLinkLanguage:()=>z,MagicLinkType:()=>K,Passage:()=>A,PassageError:()=>w,User:()=>L,UserStatus:()=>ne,WebAuthnType:()=>ee,default:()=>nr});module.exports=Oe(tr);var U=require("jose");var xe="https://api.passage.id/v1".replace(/\/+$/,""),x=class{constructor(r={}){this.configuration=r}set config(r){this.configuration=r}get basePath(){return this.configuration.basePath!=null?this.configuration.basePath:xe}get fetchApi(){return this.configuration.fetchApi}get middleware(){return this.configuration.middleware||[]}get queryParamsStringify(){return this.configuration.queryParamsStringify||G}get username(){return this.configuration.username}get password(){return this.configuration.password}get apiKey(){let r=this.configuration.apiKey;if(r)return typeof r=="function"?r:()=>r}get accessToken(){let r=this.configuration.accessToken;if(r)return typeof r=="function"?r:()=>o(this,null,function*(){return r})}get headers(){return this.configuration.headers}get credentials(){return this.configuration.credentials}},ke=new x,R=class R{constructor(r=ke){this.configuration=r;this.fetchApi=(r,n)=>o(this,null,function*(){let t={url:r,init:n};for(let s of this.middleware)s.pre&&(t=(yield s.pre(l({fetch:this.fetchApi},t)))||t);let i;try{i=yield(this.configuration.fetchApi||fetch)(t.url,t.init)}catch(s){for(let c of this.middleware)c.onError&&(i=(yield c.onError({fetch:this.fetchApi,url:t.url,init:t.init,error:s,response:i?i.clone():void 0}))||i);if(i===void 0)throw s instanceof Error?new F(s,"The request failed and the interceptors did not return an alternative response"):s}for(let s of this.middleware)s.post&&(i=(yield s.post({fetch:this.fetchApi,url:t.url,init:t.init,response:i.clone()}))||i);return i});this.middleware=r.middleware}withMiddleware(...r){let n=this.clone();return n.middleware=n.middleware.concat(...r),n}withPreMiddleware(...r){let n=r.map(t=>({pre:t}));return this.withMiddleware(...n)}withPostMiddleware(...r){let n=r.map(t=>({post:t}));return this.withMiddleware(...n)}isJsonMime(r){return r?R.jsonRegex.test(r):!1}request(r,n){return o(this,null,function*(){let{url:t,init:i}=yield this.createFetchParams(r,n),s=yield this.fetchApi(t,i);if(s&&s.status>=200&&s.status<300)return s;throw new m(s,"Response returned an error code")})}createFetchParams(r,n){return o(this,null,function*(){let t=this.configuration.basePath+r.path;r.query!==void 0&&Object.keys(r.query).length!==0&&(t+="?"+this.configuration.queryParamsStringify(r.query));let i=Object.assign({},this.configuration.headers,r.headers);Object.keys(i).forEach(W=>i[W]===void 0?delete i[W]:{});let s=typeof n=="function"?n:()=>o(this,null,function*(){return n}),c={method:r.method,headers:i,body:r.body,credentials:this.configuration.credentials},a=l(l({},c),yield s({init:c,context:r})),d;Ie(a.body)||a.body instanceof URLSearchParams||we(a.body)?d=a.body:this.isJsonMime(i["Content-Type"])?d=JSON.stringify(a.body):d=a.body;let O=y(l({},a),{body:d});return{url:t,init:O}})}clone(){let r=this.constructor,n=new r(this.configuration);return n.middleware=this.middleware.slice(),n}};R.jsonRegex=new RegExp("^(:?application/json|[^;/ ]+/[^;/ ]+[+]json)[ ]*(:?;.*)?$","i");var f=R;function we(e){return typeof Blob!="undefined"&&e instanceof Blob}function Ie(e){return typeof FormData!="undefined"&&e instanceof FormData}var m=class extends Error{constructor(n,t){super(t);this.response=n;this.name="ResponseError"}},F=class extends Error{constructor(n,t){super(t);this.cause=n;this.name="FetchError"}},p=class extends Error{constructor(n,t){super(t);this.field=n;this.name="RequiredError"}};function G(e,r=""){return Object.keys(e).map(n=>B(n,e[n],r)).filter(n=>n.length>0).join("&")}function B(e,r,n=""){let t=n+(n.length?`[${e}]`:e);if(r instanceof Array){let i=r.map(s=>encodeURIComponent(String(s))).join(`&${encodeURIComponent(t)}=`);return`${encodeURIComponent(t)}=${i}`}if(r instanceof Set){let i=Array.from(r);return B(e,i,n)}return r instanceof Date?`${encodeURIComponent(t)}=${encodeURIComponent(r.toISOString())}`:r instanceof Object?G(r,t):`${encodeURIComponent(t)}=${encodeURIComponent(String(r))}`}var u=class{constructor(r,n=t=>t){this.raw=r;this.transformer=n}value(){return o(this,null,function*(){return this.transformer(yield this.raw.json())})}},g=class{constructor(r){this.raw=r}value(){return o(this,null,function*(){})}};function $(e){return Le(e,!1)}function Le(e,r){return e==null?e:{providerId:e.provider_id,createdAt:new Date(e.created_at),lastLoginAt:new Date(e.last_login_at),providerIdentifier:e.provider_identifier}}var k={Email:"email",Phone:"phone"};var z={De:"de",En:"en",Es:"es",It:"it",Pl:"pl",Pt:"pt",Zh:"zh"};var K={Login:"login",VerifyIdentifier:"verify_identifier"};function q(e){return be(e,!1)}function be(e,r){return e}function Q(e){return Me(e,!1)}function Me(e,r=!1){return e==null?e:{channel:e.channel,email:e.email,language:e.language,magic_link_path:e.magicLinkPath,phone:e.phone,redirect_url:e.redirectUrl,send:e.send,ttl:e.ttl,type:e.type,user_id:e.userId}}function Y(e){return Ee(e,!1)}function Ee(e,r=!1){return e==null?e:{email:e.email,phone:e.phone,user_metadata:e.userMetadata}}function Z(e){return Ne(e,!1)}function Ne(e,r){return e==null?e:{providerId:e.provider_id,createdAt:new Date(e.created_at),lastLoginAt:new Date(e.last_login_at),providerIdentifier:e.provider_identifier}}function X(e){return Ce(e,!1)}function Ce(e,r){return e==null?e:{providerId:e.provider_id,createdAt:new Date(e.created_at),lastLoginAt:new Date(e.last_login_at),providerIdentifier:e.provider_identifier}}function h(e){return Je(e,!1)}function Je(e,r){return e==null?e:{href:e.href}}function j(e){return _e(e,!1)}function _e(e,r){return e==null?e:{light:e.light,dark:e.dark}}var ee={Passkey:"passkey",SecurityKey:"security_key",Platform:"platform"};function E(e){return Pe(e,!1)}function Pe(e,r){return e}function N(e){return Fe(e,!1)}function Fe(e,r){return e==null?e:{createdAt:new Date(e.created_at),credId:e.cred_id,friendlyName:e.friendly_name,id:e.id,lastLoginAt:new Date(e.last_login_at),type:E(e.type),updatedAt:new Date(e.updated_at),usageCount:e.usage_count,icons:j(e.icons)}}function re(e){return We(e,!1)}function We(e,r){return e==null?e:{devices:e.devices.map(N)}}var ne={Active:"active",Inactive:"inactive",Pending:"pending"};function C(e){return ve(e,!1)}function ve(e,r){return e}function te(e){return Ve(e,!1)}function Ve(e,r){return e==null?e:{createdAt:new Date(e.created_at),email:e.email,emailVerified:e.email_verified,externalId:e.external_id,id:e.id,lastLoginAt:new Date(e.last_login_at),loginCount:e.login_count,phone:e.phone,phoneVerified:e.phone_verified,status:C(e.status),updatedAt:new Date(e.updated_at),userMetadata:e.user_metadata}}function ie(e){return Ge(e,!1)}function Ge(e,r){return e==null?e:{first:h(e.first),last:h(e.last),next:h(e.next),previous:h(e.previous),self:h(e.self)}}function oe(e){return Be(e,!1)}function Be(e,r){return e==null?e:{links:ie(e._links),createdBefore:e.created_before,limit:e.limit,page:e.page,totalUsers:e.total_users,users:e.users.map(te)}}function se(e){return $e(e,!1)}function $e(e,r){return e==null?e:{activated:e.activated,appId:e.app_id,id:e.id,identifier:e.identifier,redirectUrl:e.redirect_url,secret:e.secret,ttl:e.ttl,type:q(e.type),url:e.url,userId:e.user_id}}function ae(e){return ze(e,!1)}function ze(e,r){return e==null?e:{magicLink:se(e.magic_link)}}function ce(e){return Ke(e,!1)}function Ke(e,r){return e}function pe(e){return Qe(e,!1)}function Qe(e,r){return e}function de(e){return Ye(e,!1)}function Ye(e,r){return e}function ue(e){return Ze(e,!1)}function Ze(e,r){return e==null?e:{createdAt:new Date(e.created_at),completedAt:e.completed_at==null?null:new Date(e.completed_at),id:e.id,ipAddr:e.ip_addr,status:de(e.status),type:e.type,userAgent:e.user_agent,userAgentDisplay:e.user_agent_display,action:pe(e.action),socialLoginType:ce(e.social_login_type)}}function fe(e){return Xe(e,!1)}function Xe(e,r){return e==null?e:{apple:e.apple==null?void 0:$(e.apple),github:e.github==null?void 0:Z(e.github),google:e.google==null?void 0:X(e.google)}}function le(e){return je(e,!1)}function je(e,r){return e==null?e:{createdAt:new Date(e.created_at),email:e.email,emailVerified:e.email_verified,externalId:e.external_id,id:e.id,lastLoginAt:new Date(e.last_login_at),loginCount:e.login_count,phone:e.phone,phoneVerified:e.phone_verified,recentEvents:e.recent_events.map(ue),socialConnections:fe(e.social_connections),status:C(e.status),updatedAt:new Date(e.updated_at),userMetadata:e.user_metadata,webauthn:e.webauthn,webauthnDevices:e.webauthn_devices.map(N),webauthnTypes:e.webauthn_types.map(E)}}function ge(e){return er(e,!1)}function er(e,r=!1){return e==null?e:{email:e.email,phone:e.phone,user_metadata:e.userMetadata}}function S(e){return rr(e,!1)}function rr(e,r){return e==null?e:{user:le(e.user)}}var J=class extends f{createMagicLinkRaw(r,n){return o(this,null,function*(){if(r.appId==null)throw new p("appId",'Required parameter "appId" was null or undefined when calling createMagicLink().');if(r.createMagicLinkRequest==null)throw new p("createMagicLinkRequest",'Required parameter "createMagicLinkRequest" was null or undefined when calling createMagicLink().');let t={},i={};if(i["Content-Type"]="application/json",this.configuration&&this.configuration.accessToken){let c=this.configuration.accessToken,a=yield c("bearerAuth",[]);a&&(i.Authorization=`Bearer ${a}`)}let s=yield this.request({path:"/apps/{app_id}/magic-links".replace("{app_id}",encodeURIComponent(String(r.appId))),method:"POST",headers:i,query:t,body:Q(r.createMagicLinkRequest)},n);return new u(s,c=>ae(c))})}createMagicLink(r,n){return o(this,null,function*(){return yield(yield this.createMagicLinkRaw(r,n)).value()})}};var _=class extends f{revokeUserRefreshTokensRaw(r,n){return o(this,null,function*(){if(r.appId==null)throw new p("appId",'Required parameter "appId" was null or undefined when calling revokeUserRefreshTokens().');if(r.userId==null)throw new p("userId",'Required parameter "userId" was null or undefined when calling revokeUserRefreshTokens().');let t={},i={};if(this.configuration&&this.configuration.accessToken){let c=this.configuration.accessToken,a=yield c("bearerAuth",[]);a&&(i.Authorization=`Bearer ${a}`)}let s=yield this.request({path:"/apps/{app_id}/users/{user_id}/tokens".replace("{app_id}",encodeURIComponent(String(r.appId))).replace("{user_id}",encodeURIComponent(String(r.userId))),method:"DELETE",headers:i,query:t},n);return new g(s)})}revokeUserRefreshTokens(r,n){return o(this,null,function*(){yield this.revokeUserRefreshTokensRaw(r,n)})}};var P=class extends f{deleteUserDevicesRaw(r,n){return o(this,null,function*(){if(r.appId==null)throw new p("appId",'Required parameter "appId" was null or undefined when calling deleteUserDevices().');if(r.userId==null)throw new p("userId",'Required parameter "userId" was null or undefined when calling deleteUserDevices().');if(r.deviceId==null)throw new p("deviceId",'Required parameter "deviceId" was null or undefined when calling deleteUserDevices().');let t={},i={};if(this.configuration&&this.configuration.accessToken){let c=this.configuration.accessToken,a=yield c("bearerAuth",[]);a&&(i.Authorization=`Bearer ${a}`)}let s=yield this.request({path:"/apps/{app_id}/users/{user_id}/devices/{device_id}".replace("{app_id}",encodeURIComponent(String(r.appId))).replace("{user_id}",encodeURIComponent(String(r.userId))).replace("{device_id}",encodeURIComponent(String(r.deviceId))),method:"DELETE",headers:i,query:t},n);return new g(s)})}deleteUserDevices(r,n){return o(this,null,function*(){yield this.deleteUserDevicesRaw(r,n)})}listUserDevicesRaw(r,n){return o(this,null,function*(){if(r.appId==null)throw new p("appId",'Required parameter "appId" was null or undefined when calling listUserDevices().');if(r.userId==null)throw new p("userId",'Required parameter "userId" was null or undefined when calling listUserDevices().');let t={},i={};if(this.configuration&&this.configuration.accessToken){let c=this.configuration.accessToken,a=yield c("bearerAuth",[]);a&&(i.Authorization=`Bearer ${a}`)}let s=yield this.request({path:"/apps/{app_id}/users/{user_id}/devices".replace("{app_id}",encodeURIComponent(String(r.appId))).replace("{user_id}",encodeURIComponent(String(r.userId))),method:"GET",headers:i,query:t},n);return new u(s,c=>re(c))})}listUserDevices(r,n){return o(this,null,function*(){return yield(yield this.listUserDevicesRaw(r,n)).value()})}};var D=class extends f{activateUserRaw(r,n){return o(this,null,function*(){if(r.appId==null)throw new p("appId",'Required parameter "appId" was null or undefined when calling activateUser().');if(r.userId==null)throw new p("userId",'Required parameter "userId" was null or undefined when calling activateUser().');let t={},i={};if(this.configuration&&this.configuration.accessToken){let c=this.configuration.accessToken,a=yield c("bearerAuth",[]);a&&(i.Authorization=`Bearer ${a}`)}let s=yield this.request({path:"/apps/{app_id}/users/{user_id}/activate".replace("{app_id}",encodeURIComponent(String(r.appId))).replace("{user_id}",encodeURIComponent(String(r.userId))),method:"PATCH",headers:i,query:t},n);return new u(s,c=>S(c))})}activateUser(r,n){return o(this,null,function*(){return yield(yield this.activateUserRaw(r,n)).value()})}createUserRaw(r,n){return o(this,null,function*(){if(r.appId==null)throw new p("appId",'Required parameter "appId" was null or undefined when calling createUser().');if(r.createUserArgs==null)throw new p("createUserArgs",'Required parameter "createUserArgs" was null or undefined when calling createUser().');let t={},i={};if(i["Content-Type"]="application/json",this.configuration&&this.configuration.accessToken){let c=this.configuration.accessToken,a=yield c("bearerAuth",[]);a&&(i.Authorization=`Bearer ${a}`)}let s=yield this.request({path:"/apps/{app_id}/users".replace("{app_id}",encodeURIComponent(String(r.appId))),method:"POST",headers:i,query:t,body:Y(r.createUserArgs)},n);return new u(s,c=>S(c))})}createUser(r,n){return o(this,null,function*(){return yield(yield this.createUserRaw(r,n)).value()})}deactivateUserRaw(r,n){return o(this,null,function*(){if(r.appId==null)throw new p("appId",'Required parameter "appId" was null or undefined when calling deactivateUser().');if(r.userId==null)throw new p("userId",'Required parameter "userId" was null or undefined when calling deactivateUser().');let t={},i={};if(this.configuration&&this.configuration.accessToken){let c=this.configuration.accessToken,a=yield c("bearerAuth",[]);a&&(i.Authorization=`Bearer ${a}`)}let s=yield this.request({path:"/apps/{app_id}/users/{user_id}/deactivate".replace("{app_id}",encodeURIComponent(String(r.appId))).replace("{user_id}",encodeURIComponent(String(r.userId))),method:"PATCH",headers:i,query:t},n);return new u(s,c=>S(c))})}deactivateUser(r,n){return o(this,null,function*(){return yield(yield this.deactivateUserRaw(r,n)).value()})}deleteUserRaw(r,n){return o(this,null,function*(){if(r.appId==null)throw new p("appId",'Required parameter "appId" was null or undefined when calling deleteUser().');if(r.userId==null)throw new p("userId",'Required parameter "userId" was null or undefined when calling deleteUser().');let t={},i={};if(this.configuration&&this.configuration.accessToken){let c=this.configuration.accessToken,a=yield c("bearerAuth",[]);a&&(i.Authorization=`Bearer ${a}`)}let s=yield this.request({path:"/apps/{app_id}/users/{user_id}".replace("{app_id}",encodeURIComponent(String(r.appId))).replace("{user_id}",encodeURIComponent(String(r.userId))),method:"DELETE",headers:i,query:t},n);return new g(s)})}deleteUser(r,n){return o(this,null,function*(){yield this.deleteUserRaw(r,n)})}getUserRaw(r,n){return o(this,null,function*(){if(r.appId==null)throw new p("appId",'Required parameter "appId" was null or undefined when calling getUser().');if(r.userId==null)throw new p("userId",'Required parameter "userId" was null or undefined when calling getUser().');let t={},i={};if(this.configuration&&this.configuration.accessToken){let c=this.configuration.accessToken,a=yield c("bearerAuth",[]);a&&(i.Authorization=`Bearer ${a}`)}let s=yield this.request({path:"/apps/{app_id}/users/{user_id}".replace("{app_id}",encodeURIComponent(String(r.appId))).replace("{user_id}",encodeURIComponent(String(r.userId))),method:"GET",headers:i,query:t},n);return new u(s,c=>S(c))})}getUser(r,n){return o(this,null,function*(){return yield(yield this.getUserRaw(r,n)).value()})}listPaginatedUsersRaw(r,n){return o(this,null,function*(){if(r.appId==null)throw new p("appId",'Required parameter "appId" was null or undefined when calling listPaginatedUsers().');let t={};r.page!=null&&(t.page=r.page),r.limit!=null&&(t.limit=r.limit),r.createdBefore!=null&&(t.created_before=r.createdBefore),r.orderBy!=null&&(t.order_by=r.orderBy),r.identifier!=null&&(t.identifier=r.identifier),r.id!=null&&(t.id=r.id),r.loginCount!=null&&(t.login_count=r.loginCount),r.status!=null&&(t.status=r.status),r.createdAt!=null&&(t.created_at=r.createdAt),r.updatedAt!=null&&(t.updated_at=r.updatedAt),r.lastLoginAt!=null&&(t.last_login_at=r.lastLoginAt);let i={};if(this.configuration&&this.configuration.accessToken){let c=this.configuration.accessToken,a=yield c("bearerAuth",[]);a&&(i.Authorization=`Bearer ${a}`)}let s=yield this.request({path:"/apps/{app_id}/users".replace("{app_id}",encodeURIComponent(String(r.appId))),method:"GET",headers:i,query:t},n);return new u(s,c=>oe(c))})}listPaginatedUsers(r,n){return o(this,null,function*(){return yield(yield this.listPaginatedUsersRaw(r,n)).value()})}updateUserRaw(r,n){return o(this,null,function*(){if(r.appId==null)throw new p("appId",'Required parameter "appId" was null or undefined when calling updateUser().');if(r.userId==null)throw new p("userId",'Required parameter "userId" was null or undefined when calling updateUser().');if(r.updateUserArgs==null)throw new p("updateUserArgs",'Required parameter "updateUserArgs" was null or undefined when calling updateUser().');let t={},i={};if(i["Content-Type"]="application/json",this.configuration&&this.configuration.accessToken){let c=this.configuration.accessToken,a=yield c("bearerAuth",[]);a&&(i.Authorization=`Bearer ${a}`)}let s=yield this.request({path:"/apps/{app_id}/users/{user_id}".replace("{app_id}",encodeURIComponent(String(r.appId))).replace("{user_id}",encodeURIComponent(String(r.userId))),method:"PATCH",headers:i,query:t,body:ge(r.updateUserArgs)},n);return new u(s,c=>S(c))})}updateUser(r,n){return o(this,null,function*(){return yield(yield this.updateUserRaw(r,n)).value()})}};var w=class e extends Error{constructor(n,t,i){super();this.name="PassageError";this.message=n,this.errorCode=t,this.statusCode=i.response.status}static fromResponseError(n){return o(this,null,function*(){let t=yield n.response.json();return new e(t.error,t.code,n)})}};var T=class{constructor(r){this.config=r}parseError(r){return o(this,null,function*(){if(r instanceof m)throw yield w.fromResponseError(r);return r})}};var I=class extends T{constructor(r){super(r),this.jwks=(0,U.createRemoteJWKSet)(new URL(`https://auth.passage.id/v1/apps/${this.config.appId}/.well-known/jwks.json`),{cacheMaxAge:1e3*60*60*24}),this.magicLinksApi=new J(this.config.apiConfiguration)}validateJwt(r){return o(this,null,function*(){if(!r)throw new Error("jwt is required.");let{kid:n}=(0,U.decodeProtectedHeader)(r);if(!n)throw new Error("kid missing in jwt header.");let{payload:{sub:t}}=yield(0,U.jwtVerify)(r,this.jwks,{audience:[this.config.appId]});if(!t)throw new Error("sub missing in jwt claims.");return t})}createMagicLink(r,n){return o(this,null,function*(){try{let{language:t,magicLinkPath:i,redirectUrl:s,ttl:c}=n!=null?n:{},a;return"userId"in r?a=r.channel:"email"in r?a=k.Email:a=k.Phone,(yield this.magicLinksApi.createMagicLink({appId:this.config.appId,createMagicLinkRequest:y(l({},r),{channel:a,language:t,magicLinkPath:i,redirectUrl:s,ttl:c})})).magicLink}catch(t){throw yield this.parseError(t)}})}};var L=class extends T{constructor(r){super(r),this.usersApi=new D(this.config.apiConfiguration),this.userDevicesApi=new P(this.config.apiConfiguration),this.tokensApi=new _(this.config.apiConfiguration)}get(r){return o(this,null,function*(){if(!r)throw new Error("userId is required.");try{return(yield this.usersApi.getUser({userId:r,appId:this.config.appId})).user}catch(n){throw yield this.parseError(n)}})}getByIdentifier(r){return o(this,null,function*(){if(!r)throw new Error("identifier is required.");try{let t=(yield this.usersApi.listPaginatedUsers({appId:this.config.appId,limit:1,identifier:r.toLowerCase()})).users;if(!t.length)throw new m(new Response('{"code":"user_not_found","error":"User not found."}',{status:404}));return this.get(t[0].id)}catch(n){throw yield this.parseError(n)}})}activate(r){return o(this,null,function*(){if(!r)throw new Error("userId is required.");try{return(yield this.usersApi.activateUser({userId:r,appId:this.config.appId})).user}catch(n){throw yield this.parseError(n)}})}deactivate(r){return o(this,null,function*(){if(!r)throw new Error("userId is required.");try{return(yield this.usersApi.deactivateUser({userId:r,appId:this.config.appId})).user}catch(n){throw yield this.parseError(n)}})}update(r,n){return o(this,null,function*(){if(!r)throw new Error("userId is required.");try{return(yield this.usersApi.updateUser({userId:r,appId:this.config.appId,updateUserArgs:n})).user}catch(t){throw yield this.parseError(t)}})}create(r){return o(this,null,function*(){if(!r.email&&!r.phone)throw new Error("At least one of args.email or args.phone is required.");try{return(yield this.usersApi.createUser({appId:this.config.appId,createUserArgs:r})).user}catch(n){throw yield this.parseError(n)}})}delete(r){return o(this,null,function*(){if(!r)throw new Error("userId is required.");try{yield this.usersApi.deleteUser({userId:r,appId:this.config.appId})}catch(n){throw yield this.parseError(n)}})}listDevices(r){return o(this,null,function*(){if(!r)throw new Error("userId is required.");try{return(yield this.userDevicesApi.listUserDevices({userId:r,appId:this.config.appId})).devices}catch(n){throw yield this.parseError(n)}})}revokeDevice(r,n){return o(this,null,function*(){if(!r)throw new Error("userId is required.");if(!n)throw new Error("deviceId is required.");try{yield this.userDevicesApi.deleteUserDevices({userId:r,deviceId:n,appId:this.config.appId})}catch(t){throw yield this.parseError(t)}})}revokeRefreshTokens(r){return o(this,null,function*(){if(!r)throw new Error("userId is required.");try{yield this.tokensApi.revokeUserRefreshTokens({userId:r,appId:this.config.appId})}catch(n){throw yield this.parseError(n)}})}};var A=class{constructor(r){if(!r.appId)throw new Error("A Passage App ID is required. Please include {appId: YOUR_APP_ID, apiKey: YOUR_API_KEY}.");if(!r.apiKey)throw new Error("A Passage API Key is required. Please include {appId: YOUR_APP_ID, apiKey: YOUR_API_KEY}.");let n={appId:r.appId,apiConfiguration:this.configureApi({accessToken:r.apiKey,fetchApi:r.fetchApi})};this.user=new L(n),this.auth=new I(n)}configureApi(r){var i,s;let n=(i=r==null?void 0:r.fetchApi)!=null?i:fetch;return new x({accessToken:r==null?void 0:r.accessToken,fetchApi:n,headers:y(l({},r==null?void 0:r.headers),{Authorization:`Bearer ${r==null?void 0:r.accessToken}`,"Passage-Version":`passage-node ${(s=process.env.npm_package_version)!=null?s:"v0.0.0"}`}),middleware:[]})}};var nr=A;0&&(module.exports={Auth,MagicLinkChannel,MagicLinkLanguage,MagicLinkType,Passage,PassageError,User,UserStatus,WebAuthnType});