authhero 0.256.0 → 0.257.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/authhero.cjs +1 -1
- package/dist/authhero.mjs +1 -1
- package/dist/stats.html +1 -1
- package/package.json +3 -3
package/dist/authhero.cjs
CHANGED
|
@@ -189,7 +189,7 @@ PERFORMANCE OF THIS SOFTWARE.
|
|
|
189
189
|
`,i=0;for(;i<n.length;)i+64<=n.length?r+=n.substr(i,64)+`\r
|
|
190
190
|
`:r+=n.substr(i)+`\r
|
|
191
191
|
`,i+=64;return r+=`-----END ${t} KEY-----\r
|
|
192
|
-
`,r}async function m$(t){const e=await t.publicKey.export(),n=await crypto.subtle.exportKey("jwk",e),r=JSON.stringify(n,Object.keys(n).sort()),s=new TextEncoder().encode(r);return El(await _m(s))}const _$=1e3*60*60*24,y$=new o.OpenAPIHono().openapi(o.createRoute({tags:["keys"],method:"get",path:"/signing",request:{headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.array(Sl)}},description:"List of keys"}}}),async t=>{const{signingKeys:e}=await t.env.data.keys.list({q:"type:jwt_signing"}),n=e.filter(r=>"cert"in r).map(r=>r);return t.json(n)}).openapi(o.createRoute({tags:["keys"],method:"get",path:"/signing/{kid}",request:{headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({kid:o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Sl}},description:"The requested key"}}}),async t=>{const{kid:e}=t.req.valid("param"),{signingKeys:n}=await t.env.data.keys.list({q:"type:jwt_signing"}),r=n.find(i=>i.kid===e);if(!r)throw new b(404,{message:"Key not found"});return t.json(r)}).openapi(o.createRoute({tags:["keys"],method:"post",path:"/signing/rotate",request:{headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{description:"Status"}}}),async t=>{const{signingKeys:e}=await t.env.data.keys.list({q:"type:jwt_signing"});for await(const r of e)await t.env.data.keys.update(r.kid,{revoked_at:new Date(Date.now()+_$).toISOString()});const n=await Xd({name:`CN=${t.env.ORGANIZATION_NAME}`});return await t.env.data.keys.create({...n,type:"jwt_signing"}),t.text("OK",{status:201})}).openapi(o.createRoute({tags:["keys"],method:"put",path:"/signing/{kid}/revoke",request:{headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({kid:o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{description:"Status"}}}),async t=>{const{kid:e}=t.req.valid("param");if(!await t.env.data.keys.update(e,{revoked_at:new Date().toISOString()}))throw new b(404,{message:"Key not found"});const r=await Xd({name:`CN=${t.env.ORGANIZATION_NAME}`});return await t.env.data.keys.create({...r,type:"jwt_signing"}),t.text("OK")}),w$=new o.OpenAPIHono().openapi(o.createRoute({tags:["users"],method:"get",path:"/",request:{query:o.z.object({email:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"tenant/json":{schema:o.z.array(gu)}},description:"List of users"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{email:n}=t.req.valid("query"),i=(await Eu(t.env.data.users,e,n)).filter(s=>!s.linked_to);return t.json(i)}),v$=xt.extend({clients:o.z.array(or)}),b$=new o.OpenAPIHono().openapi(o.createRoute({tags:["clients"],method:"get",path:"/",request:{query:Ye,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([v$,o.z.array(or)])}},description:"List of clients"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{page:n,per_page:r,include_totals:i,sort:s,q:a}=t.req.valid("query"),l=(await t.env.data.clients.list(e,{page:n,per_page:r,include_totals:i,sort:pt(s),q:a})).clients;return i?t.json({clients:l,start:0,limit:10,length:l.length}):t.json(l)}).openapi(o.createRoute({tags:["clients"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:or}},description:"A client"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=await t.env.data.clients.get(e,n);if(!r)throw new b(404);return t.json(r)}).openapi(o.createRoute({tags:["clients"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param");if(!await t.env.data.clients.remove(e,n))throw new b(404,{message:"Client not found"});return t.text("OK")}).openapi(o.createRoute({tags:["clients"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Ts.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:or}},description:"The updated client"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),i=t.req.valid("json");await t.env.data.clients.update(e,n,i);const s=await t.env.data.clients.get(e,n);if(!s)throw new b(404,{message:"Client not found"});return t.json(s)}).openapi(o.createRoute({tags:["clients"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Ts.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:o.z.object(or.shape)}},description:"A client"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r={...n,client_secret:n.client_secret||Ce()},i=await t.env.data.clients.create(e,r);return t.json(i,{status:201})});o.z.object({start:o.z.number(),limit:o.z.number(),length:o.z.number()});Oa.extend({email:o.z.string(),login_count:o.z.number(),multifactor:o.z.array(o.z.string()).optional(),last_ip:o.z.string().optional(),last_login:o.z.string().optional(),user_id:o.z.string()}).catchall(o.z.any());const $$=xt.extend({tenants:o.z.array(Ln)}),k$=new o.OpenAPIHono().openapi(o.createRoute({tags:["tenants","settings"],method:"get",path:"/settings",request:{headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Ln}},description:"Current tenant settings"}}}),async t=>{const e=await t.env.data.tenants.get(t.var.tenant_id);if(!e)throw new b(404,{message:"Tenant not found"});return t.json(e)}).openapi(o.createRoute({tags:["tenants","settings"],method:"patch",path:"/settings",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object(Ki.shape).partial()}}}},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Ln}},description:"Updated tenant settings"}}}),async t=>{const e=t.req.valid("json"),{id:n,...r}=e,i=await t.env.data.tenants.get(t.var.tenant_id);if(!i)throw new b(404,{message:"Tenant not found"});const s=zl(i,r);await t.env.data.tenants.update(t.var.tenant_id,s);const a=await t.env.data.tenants.get(t.var.tenant_id);if(!a)throw new b(500,{message:"Failed to retrieve updated tenant"});return t.json(a)}).openapi(o.createRoute({tags:["tenants"],method:"get",path:"/",request:{query:Ye},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"tenant/json":{schema:o.z.union([o.z.array(Ln),$$])}},description:"List of tenants"}}}),async t=>{const{page:e,per_page:n,include_totals:r,sort:i,q:s}=t.req.valid("query"),a=await t.env.data.tenants.list({page:e,per_page:n,include_totals:r,sort:pt(i),q:s});return r?t.json(a):t.json(a.tenants)}).openapi(o.createRoute({tags:["tenants"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"tenant/json":{schema:Ln}},description:"A tenant"}}}),async t=>{const{id:e}=t.req.valid("param"),n=await t.env.data.tenants.get(e);if(!n)throw new b(404);return t.json(n)}).openapi(o.createRoute({tags:["tenants"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{id:e}=t.req.valid("param");return await t.env.data.tenants.remove(e),t.text("OK")}).openapi(o.createRoute({tags:["tenants"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Ki.shape).partial()}}},params:o.z.object({id:o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{id:e}=t.req.valid("param"),n=t.req.valid("json");return await t.env.data.tenants.update(e,n),t.text("OK")}).openapi(o.createRoute({tags:["tenants"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Ki.shape)}}}},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"tenant/json":{schema:Ln}},description:"An tenant"}}}),async t=>{const e=t.req.valid("json"),n=await t.env.data.tenants.create(e);return t.json(n,{status:201})}),x$=xt.extend({logs:o.z.array(Ls)}),S$=new o.OpenAPIHono().openapi(o.createRoute({tags:["logs"],method:"get",path:"/",request:{query:Ye,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(Ls),x$])}},description:"List of log rows"}}}),async t=>{const{page:e,per_page:n,include_totals:r,sort:i,q:s}=t.req.valid("query"),a=await t.env.data.logs.list(t.var.tenant_id,{page:e,per_page:n,include_totals:r,sort:pt(i),q:s});return r?t.json(a):t.json(a.logs)}).openapi(o.createRoute({tags:["logs"],method:"get",path:"/{id}",request:{headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({id:o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Ls}},description:"A log entry"}}}),async t=>{const{id:e}=t.req.valid("param"),n=await t.env.data.logs.get(t.var.tenant_id,e);if(!n)throw new b(404);return t.json(n)}),z$=17,A$={organization:"org_",connection:"con_",action:"act_",hook:"h_",rule:"rul_",resource_server:"api_",guardian_factor:"gfa_",invite:"inv_"};function Tc(t){const r=mm("0123456789abcdefghijklmnopqrstuvwxyz",z$)();return`${A$[t]}${r}`}function E$(){return Tc("organization")}function C$(){return Tc("connection")}function N$(){return Tc("hook")}function I$(){return Tc("invite")}const j$=xt.extend({hooks:o.z.array(Vr)}),O$=new o.OpenAPIHono().openapi(o.createRoute({tags:["hooks"],method:"get",path:"/",request:{query:Ye,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(Vr),j$])}},description:"List of hooks"}}}),async t=>{const{page:e,per_page:n,include_totals:r,sort:i,q:s}=t.req.valid("query"),a=await t.env.data.hooks.list(t.var.tenant_id,{page:e,per_page:n,include_totals:r,sort:pt(i),q:s});return r?t.json(a):t.json(a.hooks)}).openapi(o.createRoute({tags:["hooks"],method:"post",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:ds}}}},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Vr}},description:"The created hook"}}}),async t=>{const e=t.req.valid("json"),n={...e,hook_id:e.hook_id||N$()},r=await t.env.data.hooks.create(t.var.tenant_id,n);return t.json(r,{status:201})}).openapi(o.createRoute({tags:["hooks"],method:"patch",path:"/{hook_id}",request:{headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({hook_id:o.z.string()}),body:{content:{"application/json":{schema:o.z.union([ds.options[0].omit({hook_id:!0}).partial(),ds.options[1].omit({hook_id:!0}).partial()])}}}},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Vr}},description:"The updated hook"},404:{description:"Hook not found"}}}),async t=>{const{hook_id:e}=t.req.valid("param"),n=t.req.valid("json");await t.env.data.hooks.update(t.var.tenant_id,e,n);const r=await t.env.data.hooks.get(t.var.tenant_id,e);if(!r)throw new b(404,{message:"Hook not found"});return t.json(r)}).openapi(o.createRoute({tags:["hooks"],method:"get",path:"/{hook_id}",request:{headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({hook_id:o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Vr}},description:"A hook"},404:{description:"Hook not found"}}}),async t=>{const{hook_id:e}=t.req.valid("param"),n=await t.env.data.hooks.get(t.var.tenant_id,e);if(!n)throw new b(404,{message:"Hook not found"});return t.json(n)}).openapi(o.createRoute({tags:["hooks"],method:"delete",path:"/{hook_id}",request:{headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({hook_id:o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{description:"A hook"}}}),async t=>{const{hook_id:e}=t.req.valid("param");if(!await t.env.data.hooks.remove(t.var.tenant_id,e))throw new b(404,{message:"Hook not found"});return t.text("OK")}),T$=xt.extend({connections:o.z.array(Vt)}),P$=new o.OpenAPIHono().openapi(o.createRoute({tags:["connections"],method:"get",path:"/",request:{query:Ye,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(Vt),T$])}},description:"List of connectionss"}}}),async t=>{const{page:e,per_page:n,include_totals:r=!1,sort:i,q:s}=t.req.valid("query"),a=await t.env.data.connections.list(t.var.tenant_id,{page:e,per_page:n,include_totals:r,sort:pt(i),q:s});return r?t.json(a):t.json(a.connections)}).openapi(o.createRoute({tags:["connections"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Vt}},description:"A connection"}}}),async t=>{const{id:e}=t.req.valid("param"),n=await t.env.data.connections.get(t.var.tenant_id,e);if(!n)throw new b(404);return t.json(n)}).openapi(o.createRoute({tags:["connections"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{id:e}=t.req.valid("param");if(!await t.env.data.connections.remove(t.var.tenant_id,e))throw new b(404,{message:"Connection not found"});return t.text("OK")}).openapi(o.createRoute({tags:["connections"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Rs.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Vt}},description:"The updated connection"}}}),async t=>{const{id:e}=t.req.valid("param"),n=t.req.valid("json");if(!await t.env.data.connections.update(t.var.tenant_id,e,n))throw new b(404,{message:"Connection not found"});const i=await t.env.data.connections.get(t.var.tenant_id,e);if(!i)throw new b(404,{message:"Connection not found"});return t.json(i)}).openapi(o.createRoute({tags:["connections"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Rs.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Vt}},description:"A connection"}}}),async t=>{const e=t.req.valid("json"),n={...e,id:e.id||C$()},r=await t.env.data.connections.create(t.var.tenant_id,n);return t.json(r,{status:201})}),R$=new o.OpenAPIHono().openapi(o.createRoute({tags:["prompts"],method:"get",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:ps}},description:"Branding settings"}}}),async t=>{const e=await t.env.data.promptSettings.get(t.var.tenant_id);return e?t.json(e):t.json(ps.parse({}))}).openapi(o.createRoute({tags:["prompts"],method:"patch",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object(ps.shape).partial()}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Prompts settings"}}}),async t=>{const e=t.req.valid("json"),n=await t.env.data.promptSettings.get(t.var.tenant_id);return Object.assign(n,e),await t.env.data.promptSettings.set(t.var.tenant_id,n),t.json(n)});let Wh=!1;function yp(t){t.use(async(e,n)=>(Wh||(t.openAPIRegistry.registerComponent("securitySchemes","Bearer",{type:"oauth2",scheme:"bearer",flows:{implicit:{authorizationUrl:`${e.env.AUTH_URL}/authorize`,scopes:{openid:"Basic user information",email:"User email",profile:"User profile information"}}}}),Wh=!0),await n()))}var B$=(t,e)=>{try{return e(t)}catch{return t.replace(/(?:%[0-9A-Fa-f]{2})+/g,n=>{try{return e(n)}catch{return n}})}},L$=decodeURIComponent,U$=/^[\w!#$%&'*.^`|~+-]+$/,D$=/^[ !#-:<-[\]-~]*$/,M$=(t,e)=>{if(t.indexOf(e)===-1)return{};const n=t.trim().split(";"),r={};for(let i of n){i=i.trim();const s=i.indexOf("=");if(s===-1)continue;const a=i.substring(0,s).trim();if(e!==a||!U$.test(a))continue;let c=i.substring(s+1).trim();if(c.startsWith('"')&&c.endsWith('"')&&(c=c.slice(1,-1)),D$.test(c)){r[a]=c.indexOf("%")!==-1?B$(c,L$):c;break}}return r},F$=(t,e,n={})=>{let r=`${t}=${e}`;if(t.startsWith("__Secure-")&&!n.secure)throw new Error("__Secure- Cookie must have Secure attributes");if(t.startsWith("__Host-")){if(!n.secure)throw new Error("__Host- Cookie must have Secure attributes");if(n.path!=="/")throw new Error('__Host- Cookie must have Path attributes with "/"');if(n.domain)throw new Error("__Host- Cookie must not have Domain attributes")}if(n&&typeof n.maxAge=="number"&&n.maxAge>=0){if(n.maxAge>3456e4)throw new Error("Cookies Max-Age SHOULD NOT be greater than 400 days (34560000 seconds) in duration.");r+=`; Max-Age=${n.maxAge|0}`}if(n.domain&&n.prefix!=="host"&&(r+=`; Domain=${n.domain}`),n.path&&(r+=`; Path=${n.path}`),n.expires){if(n.expires.getTime()-Date.now()>3456e7)throw new Error("Cookies Expires SHOULD NOT be greater than 400 days (34560000 seconds) in the future.");r+=`; Expires=${n.expires.toUTCString()}`}if(n.httpOnly&&(r+="; HttpOnly"),n.secure&&(r+="; Secure"),n.sameSite&&(r+=`; SameSite=${n.sameSite.charAt(0).toUpperCase()+n.sameSite.slice(1)}`),n.priority&&(r+=`; Priority=${n.priority.charAt(0).toUpperCase()+n.priority.slice(1)}`),n.partitioned){if(!n.secure)throw new Error("Partitioned Cookie must have Secure attributes");r+="; Partitioned"}return r},al=(t,e,n)=>(e=encodeURIComponent(e),F$(t,e,n)),q$=(t,e,n)=>{const r=t.req.raw.headers.get("Cookie");{if(!r)return;let i=e;return M$(r,i)[i]}},H$=(t,e,n)=>{let r;return(n==null?void 0:n.prefix)==="secure"?r=al("__Secure-"+t,e,{path:"/",...n,secure:!0}):(n==null?void 0:n.prefix)==="host"?r=al("__Host-"+t,e,{...n,path:"/",secure:!0,domain:void 0}):r=al(t,e,{path:"/",...n}),r},Jh=(t,e,n,r)=>{const i=H$(e,n,r);t.header("Set-Cookie",i,{append:!0})},Ay=t=>Cy(t.replace(/_|-/g,e=>({_:"/","-":"+"})[e]??e)),Ey=t=>V$(t).replace(/\/|\+/g,e=>({"/":"_","+":"-"})[e]??e),V$=t=>{let e="";const n=new Uint8Array(t);for(let r=0,i=n.length;r<i;r++)e+=String.fromCharCode(n[r]);return btoa(e)},Cy=t=>{const e=atob(t),n=new Uint8Array(new ArrayBuffer(e.length)),r=e.length/2;for(let i=0,s=e.length-1;i<=r;i++,s--)n[i]=e.charCodeAt(i),n[s]=e.charCodeAt(s);return n},Ny=(t=>(t.HS256="HS256",t.HS384="HS384",t.HS512="HS512",t.RS256="RS256",t.RS384="RS384",t.RS512="RS512",t.PS256="PS256",t.PS384="PS384",t.PS512="PS512",t.ES256="ES256",t.ES384="ES384",t.ES512="ES512",t.EdDSA="EdDSA",t))(Ny||{}),K$=class extends Error{constructor(t){super(`${t} is not an implemented algorithm`),this.name="JwtAlgorithmNotImplemented"}},Pc=class extends Error{constructor(t){super(`invalid JWT token: ${t}`),this.name="JwtTokenInvalid"}},G$=class extends Error{constructor(t){super(`token (${t}) is being used before it's valid`),this.name="JwtTokenNotBefore"}},W$=class extends Error{constructor(t){super(`token (${t}) expired`),this.name="JwtTokenExpired"}},J$=class extends Error{constructor(t,e){super(`Invalid "iat" claim, must be a valid number lower than "${t}" (iat: "${e}")`),this.name="JwtTokenIssuedAt"}},cl=class extends Error{constructor(t,e){super(`expected issuer "${t}", got ${e?`"${e}"`:"none"} `),this.name="JwtTokenIssuer"}},Iy=class extends Error{constructor(t){super(`jwt header is invalid: ${JSON.stringify(t)}`),this.name="JwtHeaderInvalid"}},X$=class extends Error{constructor(t){super(`required "kid" in jwt header: ${JSON.stringify(t)}`),this.name="JwtHeaderRequiresKid"}},Z$=class extends Error{constructor(t){super(`token(${t}) signature mismatched`),this.name="JwtTokenSignatureMismatched"}},_o=(t=>(t.Encrypt="encrypt",t.Decrypt="decrypt",t.Sign="sign",t.Verify="verify",t.DeriveKey="deriveKey",t.DeriveBits="deriveBits",t.WrapKey="wrapKey",t.UnwrapKey="unwrapKey",t))(_o||{}),qo=new TextEncoder,Y$=new TextDecoder;async function Q$(t,e,n){const r=jy(e),i=await t4(t,r);return await crypto.subtle.sign(r,i,n)}async function e4(t,e,n,r){const i=jy(e),s=await n4(t,i);return await crypto.subtle.verify(i,s,n,r)}function Zd(t){return Cy(t.replace(/-+(BEGIN|END).*/g,"").replace(/\s/g,""))}async function t4(t,e){if(!crypto.subtle||!crypto.subtle.importKey)throw new Error("`crypto.subtle.importKey` is undefined. JWT auth middleware requires it.");if(Oy(t)){if(t.type!=="private"&&t.type!=="secret")throw new Error(`unexpected key type: CryptoKey.type is ${t.type}, expected private or secret`);return t}const n=[_o.Sign];return typeof t=="object"?await crypto.subtle.importKey("jwk",t,e,!1,n):t.includes("PRIVATE")?await crypto.subtle.importKey("pkcs8",Zd(t),e,!1,n):await crypto.subtle.importKey("raw",qo.encode(t),e,!1,n)}async function n4(t,e){if(!crypto.subtle||!crypto.subtle.importKey)throw new Error("`crypto.subtle.importKey` is undefined. JWT auth middleware requires it.");if(Oy(t)){if(t.type==="public"||t.type==="secret")return t;t=await Xh(t)}if(typeof t=="string"&&t.includes("PRIVATE")){const r=await crypto.subtle.importKey("pkcs8",Zd(t),e,!0,[_o.Sign]);t=await Xh(r)}const n=[_o.Verify];return typeof t=="object"?await crypto.subtle.importKey("jwk",t,e,!1,n):t.includes("PUBLIC")?await crypto.subtle.importKey("spki",Zd(t),e,!1,n):await crypto.subtle.importKey("raw",qo.encode(t),e,!1,n)}async function Xh(t){if(t.type!=="private")throw new Error(`unexpected key type: ${t.type}`);if(!t.extractable)throw new Error("unexpected private key is unextractable");const e=await crypto.subtle.exportKey("jwk",t),{kty:n}=e,{alg:r,e:i,n:s}=e,{crv:a,x:c,y:l}=e;return{kty:n,alg:r,e:i,n:s,crv:a,x:c,y:l,key_ops:[_o.Verify]}}function jy(t){switch(t){case"HS256":return{name:"HMAC",hash:{name:"SHA-256"}};case"HS384":return{name:"HMAC",hash:{name:"SHA-384"}};case"HS512":return{name:"HMAC",hash:{name:"SHA-512"}};case"RS256":return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case"RS384":return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case"RS512":return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case"PS256":return{name:"RSA-PSS",hash:{name:"SHA-256"},saltLength:32};case"PS384":return{name:"RSA-PSS",hash:{name:"SHA-384"},saltLength:48};case"PS512":return{name:"RSA-PSS",hash:{name:"SHA-512"},saltLength:64};case"ES256":return{name:"ECDSA",hash:{name:"SHA-256"},namedCurve:"P-256"};case"ES384":return{name:"ECDSA",hash:{name:"SHA-384"},namedCurve:"P-384"};case"ES512":return{name:"ECDSA",hash:{name:"SHA-512"},namedCurve:"P-521"};case"EdDSA":return{name:"Ed25519",namedCurve:"Ed25519"};default:throw new K$(t)}}function Oy(t){return Rm()==="node"&&crypto.webcrypto?t instanceof crypto.webcrypto.CryptoKey:t instanceof CryptoKey}var ll=t=>Ey(qo.encode(JSON.stringify(t)).buffer).replace(/=/g,""),r4=t=>Ey(t).replace(/=/g,""),Yd=t=>JSON.parse(Y$.decode(Ay(t)));function Ty(t){if(typeof t=="object"&&t!==null){const e=t;return"alg"in e&&Object.values(Ny).includes(e.alg)&&(!("typ"in e)||e.typ==="JWT")}return!1}var i4=async(t,e,n="HS256")=>{const r=ll(t);let i;typeof e=="object"&&"alg"in e?(n=e.alg,i=ll({alg:n,typ:"JWT",kid:e.kid})):i=ll({alg:n,typ:"JWT"});const s=`${i}.${r}`,a=await Q$(e,n,qo.encode(s)),c=r4(a);return`${s}.${c}`},Py=async(t,e,n)=>{const r=typeof n=="string"?{alg:n}:n||{},i={alg:r.alg??"HS256",iss:r.iss,nbf:r.nbf??!0,exp:r.exp??!0,iat:r.iat??!0},s=t.split(".");if(s.length!==3)throw new Pc(t);const{header:a,payload:c}=Ry(t);if(!Ty(a))throw new Iy(a);const l=Date.now()/1e3|0;if(i.nbf&&c.nbf&&c.nbf>l)throw new G$(t);if(i.exp&&c.exp&&c.exp<=l)throw new W$(t);if(i.iat&&c.iat&&l<c.iat)throw new J$(l,c.iat);if(i.iss){if(!c.iss)throw new cl(i.iss,null);if(typeof i.iss=="string"&&c.iss!==i.iss)throw new cl(i.iss,c.iss);if(i.iss instanceof RegExp&&!i.iss.test(c.iss))throw new cl(i.iss,c.iss)}const d=t.substring(0,t.lastIndexOf("."));if(!await e4(e,i.alg,Ay(s[2]),qo.encode(d)))throw new Z$(t);return c},o4=async(t,e,n)=>{const r=e.verification||{},i=s4(t);if(!Ty(i))throw new Iy(i);if(!i.kid)throw new X$(i);if(e.jwks_uri){const a=await fetch(e.jwks_uri,n);if(!a.ok)throw new Error(`failed to fetch JWKS from ${e.jwks_uri}`);const c=await a.json();if(!c.keys)throw new Error('invalid JWKS response. "keys" field is missing');if(!Array.isArray(c.keys))throw new Error('invalid JWKS response. "keys" field is not an array');e.keys?e.keys.push(...c.keys):e.keys=c.keys}else if(!e.keys)throw new Error('verifyWithJwks requires options for either "keys" or "jwks_uri" or both');const s=e.keys.find(a=>a.kid===i.kid);if(!s)throw new Pc(t);return await Py(t,s,{alg:s.alg||i.alg,...r})},Ry=t=>{try{const[e,n]=t.split("."),r=Yd(e),i=Yd(n);return{header:r,payload:i}}catch{throw new Pc(t)}},s4=t=>{try{const[e]=t.split(".");return Yd(e)}catch{throw new Pc(t)}},By={sign:i4,verify:Py,decode:Ry,verifyWithJwks:o4},a4={Stringify:1,BeforeStream:2,Stream:3},Xt=(t,e)=>{const n=new String(t);return n.isEscaped=!0,n.callbacks=e,n},c4=/[&<>'"]/,Ly=async(t,e)=>{let n="";e||(e=[]);const r=await Promise.all(t);for(let i=r.length-1;n+=r[i],i--,!(i<0);i--){let s=r[i];typeof s=="object"&&e.push(...s.callbacks||[]);const a=s.isEscaped;if(s=await(typeof s=="object"?s.toString():s),typeof s=="object"&&e.push(...s.callbacks||[]),s.isEscaped??a)n+=s;else{const c=[n];Vn(s,c),n=c[0]}}return Xt(n,e)},Vn=(t,e)=>{const n=t.search(c4);if(n===-1){e[0]+=t;return}let r,i,s=0;for(i=n;i<t.length;i++){switch(t.charCodeAt(i)){case 34:r=""";break;case 39:r="'";break;case 38:r="&";break;case 60:r="<";break;case 62:r=">";break;default:continue}e[0]+=t.substring(s,i)+r,s=i+1}e[0]+=t.substring(s,i)},Uy=t=>{const e=t.callbacks;if(!(e!=null&&e.length))return t;const n=[t],r={};return e.forEach(i=>i({phase:a4.Stringify,buffer:n,context:r})),n[0]},l4=By.verify,d4=By.decode;async function Qd(t){const{signingKeys:e}=await t.keys.list({q:"type:jwt_signing"});return await Promise.all(e.map(async r=>{const s=await new Oc(r.cert).publicKey.export(),a=await crypto.subtle.exportKey("jwk",s);return vu.parse({...a,kid:r.kid})}))}o.z.object({alg:o.z.literal("RS256"),kty:o.z.literal("RSA"),use:o.z.literal("sig"),n:o.z.string(),e:o.z.string(),kid:o.z.string(),x5t:o.z.string(),x5c:o.z.array(o.z.string())});async function u4(t){if(t.JWKS_URL&&t.JWKS_SERVICE){const e=await t.JWKS_SERVICE.fetch(t.JWKS_URL);return e.ok?(await e.json()).keys:(console.warn(`JWKS fetch failed with status ${e.status}, falling back to database`),await Qd(t.data))}return await Qd(t.data)}async function p4(t,e){try{const{header:n}=d4(e),i=(await u4(t.env)).find(c=>c.kid===n.kid);if(!i)throw new b(401,{message:"No matching kid found"});const s=await crypto.subtle.importKey("jwk",i,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},!1,["verify"]);return await l4(e,s,"RS256")}catch(n){throw n instanceof b?n:new b(403,{message:"Invalid JWT signature"})}}function f4(t){return t.replace(/:([a-zA-Z_][a-zA-Z0-9_]*)/g,"{$1}")}function h4(t,e){return e.startsWith(t)?e:t+e}function wp(t){return async(e,n)=>{var c,l,d;const r=e.req.matchedRoutes.find(u=>u.method.toUpperCase()===e.req.method&&u.path!=="/*");if(!r)return await n();const i=f4(r.path),s="basePath"in r&&typeof r.basePath=="string"?r.basePath:"",a=t.openAPIRegistry.definitions.find(u=>"route"in u&&h4(s,u.route.path)===i&&u.route.method.toUpperCase()===e.req.method.toUpperCase());if(a&&"route"in a){const u=(l=(c=a.route.security)==null?void 0:c[0])==null?void 0:l.Bearer;if(!(u!=null&&u.length))return await n();const f=e.req.header("authorization")||"",[h,m]=f.split(" ");if((h==null?void 0:h.toLowerCase())!=="bearer"||!m)throw new b(401,{message:"Missing bearer token"});try{const y=await p4(e,m);e.set("user_id",y.sub),e.set("user",y);const v=y.permissions||[],$=((d=y.scope)==null?void 0:d.split(" "))||[];if(u.length&&!(u.some(A=>v.includes(A))||u.some(A=>$.includes(A))))throw new b(403,{message:"Unauthorized"})}catch(y){throw y instanceof b?y:new b(403,{message:"Invalid token"})}}return await n()}}const g4=new o.OpenAPIHono().openapi(o.createRoute({tags:["emails"],method:"get",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:fs}},description:"Email provider"}}}),async t=>{const e=await t.env.data.emailProviders.get(t.var.tenant_id);if(!e)throw new b(404,{message:"Email provider not found"});return t.json(e)}).openapi(o.createRoute({tags:["emails"],method:"post",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object(fs.shape)}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Branding settings"}}}),async t=>{const e=t.req.valid("json");return await t.env.data.emailProviders.create(t.var.tenant_id,e),t.text("OK",{status:201})}).openapi(o.createRoute({tags:["emails"],method:"patch",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object(fs.shape).partial()}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Branding settings"}}}),async t=>{const e=t.req.valid("json");return await t.env.data.emailProviders.update(t.var.tenant_id,e),t.text("OK")}),m4=new o.OpenAPIHono().openapi(o.createRoute({tags:["sessions"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Ba}},description:"A session"}}}),async t=>{const{id:e}=t.req.valid("param"),n=await t.env.data.sessions.get(t.var.tenant_id,e);if(!n)throw new b(404);return t.json(n)}).openapi(o.createRoute({tags:["sessions"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{id:e}=t.req.valid("param");if(!await t.env.data.sessions.remove(t.var.tenant_id,e))throw new b(404,{message:"Session not found"});return t.text("OK")}).openapi(o.createRoute({tags:["sessions"],method:"post",path:"/{id}/revoke",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{202:{description:"Sesssion deletion status"}}}),async t=>{const{id:e}=t.req.valid("param");if(!await t.env.data.sessions.update(t.var.tenant_id,e,{revoked_at:new Date().toDateString()}))throw new b(404,{message:"Session not found"});return t.text("Session deletion request accepted.",{status:202})}),_4=new o.OpenAPIHono().openapi(o.createRoute({tags:["refresh_tokens"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:$u}},description:"A session"}}}),async t=>{const{id:e}=t.req.valid("param"),n=await t.env.data.refreshTokens.get(t.var.tenant_id,e);if(!n)throw new b(404);return t.json(n)}).openapi(o.createRoute({tags:["refresh_tokens"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{id:e}=t.req.valid("param");if(!await t.env.data.refreshTokens.remove(t.var.tenant_id,e))throw new b(404,{message:"Session not found"});return t.text("OK")}),y4=new o.OpenAPIHono().openapi(o.createRoute({tags:["custom-domains"],method:"get",path:"/",request:{query:Ye,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.array(Bn)}},description:"List of custom domains"}}}),async t=>{const e=await t.env.data.customDomains.list(t.var.tenant_id);return t.json(e)}).openapi(o.createRoute({tags:["custom-domains"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Bn}},description:"A customDomain"}}}),async t=>{const{id:e}=t.req.valid("param"),n=await t.env.data.customDomains.get(t.var.tenant_id,e);if(!n)throw new b(404);return t.json(n)}).openapi(o.createRoute({tags:["custom-domains"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{id:e}=t.req.valid("param");if(!await t.env.data.customDomains.remove(t.var.tenant_id,e))throw new b(404,{message:"Custom domain not found"});return t.text("OK")}).openapi(o.createRoute({tags:["custom-domains"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Bn.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Bn}},description:"The updated custom domain"}}}),async t=>{const{id:e}=t.req.valid("param"),n=t.req.valid("json");if(!await t.env.data.customDomains.update(t.var.tenant_id,e,n))throw new b(404);const i=await t.env.data.customDomains.get(t.var.tenant_id,e);if(!i)throw new b(404);return t.json(i)}).openapi(o.createRoute({tags:["custom-domains"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(yu.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Bn}},description:"The created custom domain"}}}),async t=>{const e=t.req.valid("json"),n=await t.env.data.customDomains.create(t.var.tenant_id,e);return t.json(n,{status:201})}).openapi(o.createRoute({tags:["custom-domains"],method:"post",path:"/{id}/verify",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Bn}},description:"The custom domain"}}}),async()=>{throw new b(501,{message:"Not implemented"})});function Rc(t,e){const n={};for(const[r,i]of Object.entries(e)){const s={};for(const[a,c]of Object.entries(i))typeof c=="function"?s[a]=async(...l)=>{const d=performance.now();try{const u=await c(...l),h=performance.now()-d,m=t.res.headers.get("Server-Timing")||"",y=m?`${m}, ${r}-${a};dur=${h.toFixed(2)}`:`${r}-${a};dur=${h.toFixed(2)}`;return t.res.headers.set("Server-Timing",y),u}catch(u){const h=performance.now()-d,m=t.res.headers.get("Server-Timing")||"",y=m?`${m}, ${r}-${a}-error;dur=${h.toFixed(2)}`:`${r}-${a}-error;dur=${h.toFixed(2)}`;throw t.res.headers.set("Server-Timing",y),u}}:s[a]=c;n[r]=s}return n}function Bc(t){return t.ISSUER}function ot(t){return t.UNIVERSAL_LOGIN_URL||`${t.ISSUER}u/`}function qe(t){return t.OAUTH_API_URL||t.ISSUER}async function Lc(t,e){const n=t.req.header("x-forwarded-host");if(n){const i=await t.env.data.customDomains.getByDomain(n);if(i)return t.set("tenant_id",i.tenant_id),t.set("custom_domain",n),t.set("host",n),await e()}const r=t.req.header("host");if(r){t.set("host",r);const i=r.split(".");if(i.length>1&&typeof i[0]=="string"){const s=i[0];await t.env.data.tenants.get(s)&&t.set("tenant_id",s)}}else t.set("host",new URL(Bc(t.env)).host);if(!t.var.tenant_id){const i=t.req.header("tenant-id");i&&t.set("tenant_id",i)}return await e()}const w4=o.z.object({name:o.z.string(),version:o.z.string(),env:o.z.object({node:o.z.string().optional()}).optional()});function v4(t){if(t)try{let e=t;try{e=atob(t)}catch{}try{const n=JSON.parse(e);return w4.parse(n)}catch{}}catch{return}}const Uc=async(t,e)=>{var l,d,u,f;const n=(l=t.req.query("auth0Client"))==null?void 0:l.slice(0,255),i=(d=(()=>{var h;if(t.req.header("x-forwarded-host")&&t.req.header("x-forwarded-for")){const m=t.req.header("x-forwarded-for");return(h=m==null?void 0:m.split(",")[0])==null?void 0:h.trim()}return t.req.header("cf-connecting-ip")||t.req.header("x-real-ip")})())==null?void 0:d.slice(0,45),s=(u=t.req.header("user-agent"))==null?void 0:u.slice(0,512),a=(f=t.req.header("cf-ipcountry"))==null?void 0:f.slice(0,2),c=n?v4(n):void 0;c&&t.set("auth0_client",c),i&&t.set("ip",i),s&&t.set("useragent",s),a&&t.set("countryCode",a),await e()};function b4(t,e,n,r){try{const i=`${t}:${e}:${JSON.stringify(n)}`;return r?`${r}:${i}`:i}catch{const s=`${t}:${e}:${Date.now()}-${Math.random()}`;return r?`${r}:${s}`:s}}function Dc(t,e){const{cache:n,defaultTtl:r,customTtls:i={},excludeMethods:s=[],cacheEntities:a=[],keyPrefix:c}=e,l=new Set(s),d=a.length===0,u=new Set(a),f={};for(const[h,m]of Object.entries(t)){const y=d||u.has(h),v={};for(const[$,A]of Object.entries(m))if(typeof A=="function"){if(!y){v[$]=A;continue}const O=`${h}:${$}`;if(l.has(O)){v[$]=A;continue}const U=i[O]??r,T=["create","update","remove","delete","set","used"].includes($);v[$]=async(...R)=>{if(T)return await A.apply(m,R);const W=b4(h,$,R,c),te=await n.get(W);if(te!==null)if(te&&typeof te=="object"&&"isCachedNull"in te){const K=te;return K.isCachedNull?null:K.value}else return te;const Q=await A.apply(m,R);if(U>=0)if(Q!==null)await n.set(W,Q,U);else{const K={value:null,isCachedNull:!0};await n.set(W,K,U)}return Q}}else v[$]=A;f[h]=v}return f}class $4{constructor(e={}){se(this,"cache",new Map);se(this,"accessOrder",new Map);se(this,"accessCounter",0);se(this,"cleanupTimer");this.config=e;const n=e.cleanupIntervalMs;n&&n>0&&(this.cleanupTimer=setInterval(()=>{this.cleanupExpired()},n))}async get(e){const n=this.cache.get(e);return n?n.expiresAt&&n.expiresAt<new Date?(this.cache.delete(e),this.accessOrder.delete(e),null):(this.accessOrder.set(e,++this.accessCounter),n.value):null}async set(e,n,r){let i;const s=r??this.config.defaultTtlSeconds,a=s!==void 0,c=a?Math.max(0,s):0;a&&(i=new Date(Date.now()+(c>0?c*1e3:-1))),this.config.maxEntries&&this.cache.size>=this.config.maxEntries&&!this.cache.has(e)&&this.evictLeastRecentlyUsed();const l={value:n,expiresAt:i};this.cache.set(e,l),this.accessOrder.set(e,++this.accessCounter)}async delete(e){const n=this.cache.has(e);return this.cache.delete(e),this.accessOrder.delete(e),n}async clear(){this.cache.clear(),this.accessOrder.clear(),this.accessCounter=0}getStats(){return{size:this.cache.size,maxEntries:this.config.maxEntries,defaultTtlSeconds:this.config.defaultTtlSeconds}}cleanupExpired(){const e=new Date,n=[];for(const[r,i]of this.cache.entries())i.expiresAt&&i.expiresAt<e&&n.push(r);for(const r of n)this.cache.delete(r),this.accessOrder.delete(r)}evictLeastRecentlyUsed(){let e=null,n=1/0;for(const[r,i]of this.accessOrder.entries())i<n&&(n=i,e=r);e&&(this.cache.delete(e),this.accessOrder.delete(e))}destroy(){this.cleanupTimer&&(clearInterval(this.cleanupTimer),this.cleanupTimer=void 0)}}function Ho(t={}){return new $4(t)}const k4=xt.extend({forms:o.z.array(Hr)}),x4=new o.OpenAPIHono().openapi(o.createRoute({tags:["forms"],method:"get",path:"/",request:{query:Ye,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(Hr),k4])}},description:"List of forms"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{page:n,per_page:r,include_totals:i=!1,sort:s,q:a}=t.req.valid("query"),c=await t.env.data.forms.list(e,{page:n,per_page:r,include_totals:i,sort:pt(s),q:a});return i?t.json(c):t.json(c.forms)}).openapi(o.createRoute({tags:["forms"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Hr}},description:"A form"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=await t.env.data.forms.get(e,n);if(!r)throw new b(404);return t.json(r)}).openapi(o.createRoute({tags:["forms"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param");if(!await t.env.data.forms.remove(e,n))throw new b(404,{message:"Form not found"});return t.text("OK")}).openapi(o.createRoute({tags:["forms"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Bs.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Hr}},description:"The updated form"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=t.req.valid("json");if(!await t.env.data.forms.update(e,n,r))throw new b(404,{message:"Form not found"});const s=await t.env.data.forms.get(e,n);if(!s)throw new b(404,{message:"Form not found"});return t.json(s)}).openapi(o.createRoute({tags:["forms"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Bs.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Hr}},description:"A form"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r=await t.env.data.forms.create(e,n);return t.json(r,{status:201})}),S4=xt.extend({roles:o.z.array(cr)}),z4=new o.OpenAPIHono().openapi(o.createRoute({tags:["roles"],method:"get",path:"/",request:{query:Ye,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(cr),S4])}},description:"List of roles"}}}),async t=>{const{page:e,per_page:n,include_totals:r,sort:i,q:s}=t.req.valid("query"),a=await t.env.data.roles.list(t.var.tenant_id,{page:e,per_page:n,include_totals:r,sort:pt(i),q:s});return r?t.json(a):t.json(a.roles)}).openapi(o.createRoute({tags:["roles"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:cr}},description:"A role"}}}),async t=>{const{id:e}=t.req.valid("param"),n=await t.env.data.roles.get(t.var.tenant_id,e);if(!n)throw new b(404);return t.json(n)}).openapi(o.createRoute({tags:["roles"],method:"post",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:Ds}}}},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:cr}},description:"Role created"}}}),async t=>{const e=t.req.valid("json"),n=await t.env.data.roles.create(t.var.tenant_id,e);return t.json(n,{status:201})}).openapi(o.createRoute({tags:["roles"],method:"patch",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:Ds.partial()}}}},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:cr}},description:"Updated role"}}}),async t=>{const{id:e}=t.req.valid("param"),n=t.req.valid("json");if(!await t.env.data.roles.update(t.var.tenant_id,e,n))throw new b(404);const i=await t.env.data.roles.get(t.var.tenant_id,e);return t.json(i)}).openapi(o.createRoute({tags:["roles"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{id:e}=t.req.valid("param");if(!await t.env.data.roles.remove(t.var.tenant_id,e))throw new b(404);return t.text("OK")}).openapi(o.createRoute({tags:["roles"],method:"get",path:"/{id}/permissions",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),query:Ye},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:rm}},description:"Role permissions"}}}),async t=>{const{id:e}=t.req.valid("param"),{page:n,per_page:r,sort:i,q:s}=t.req.valid("query");if(!await t.env.data.roles.get(t.var.tenant_id,e))throw new b(404,{message:"Role not found"});const c=await t.env.data.rolePermissions.list(t.var.tenant_id,e,{page:n,per_page:r,include_totals:!1,sort:pt(i),q:s});return t.json(c)}).openapi(o.createRoute({tags:["roles"],method:"post",path:"/{id}/permissions",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object({permissions:o.z.array(o.z.object({permission_name:o.z.string(),resource_server_identifier:o.z.string()}))})}}}},security:[{Bearer:["auth:write"]}],responses:{201:{description:"Permissions assigned to role"}}}),async t=>{const{id:e}=t.req.valid("param"),{permissions:n}=t.req.valid("json");if(!await t.env.data.roles.get(t.var.tenant_id,e))throw new b(404,{message:"Role not found"});if(!await t.env.data.rolePermissions.assign(t.var.tenant_id,e,n.map(s=>({role_id:e,resource_server_identifier:s.resource_server_identifier,permission_name:s.permission_name}))))throw new b(500,{message:"Failed to assign permissions to role"});return t.json({message:"Permissions assigned successfully"},{status:201})}).openapi(o.createRoute({tags:["roles"],method:"delete",path:"/{id}/permissions",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object({permissions:o.z.array(o.z.object({permission_name:o.z.string(),resource_server_identifier:o.z.string()}))})}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Permissions removed from role"}}}),async t=>{const{id:e}=t.req.valid("param"),{permissions:n}=t.req.valid("json");if(!await t.env.data.roles.get(t.var.tenant_id,e))throw new b(404,{message:"Role not found"});if(!await t.env.data.rolePermissions.remove(t.var.tenant_id,e,n))throw new b(500,{message:"Failed to remove permissions from role"});return t.json({message:"Permissions removed successfully"})}),A4=xt.extend({resource_servers:o.z.array(ar)}),E4=new o.OpenAPIHono().openapi(o.createRoute({tags:["resource-servers"],method:"get",path:"/",request:{query:Ye,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(ar),A4])}},description:"List of resource servers"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{page:n,per_page:r,include_totals:i=!1,sort:s,q:a}=t.req.valid("query"),c=await t.env.data.resourceServers.list(e,{page:n,per_page:r,include_totals:i,sort:pt(s),q:a});return i?t.json(c):t.json(c.resource_servers)}).openapi(o.createRoute({tags:["resource-servers"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:ar}},description:"A resource server"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=await t.env.data.resourceServers.get(e,n);if(!r)throw new b(404);return t.json(r)}).openapi(o.createRoute({tags:["resource-servers"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param");if(!await t.env.data.resourceServers.remove(e,n))throw new b(404,{message:"Resource server not found"});return t.text("OK")}).openapi(o.createRoute({tags:["resource-servers"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Us.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:ar}},description:"The updated resource server"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=t.req.valid("json");if(!await t.env.data.resourceServers.update(e,n,r))throw new b(404,{message:"Resource server not found"});const s=await t.env.data.resourceServers.get(e,n);if(!s)throw new b(404,{message:"Resource server not found"});return t.json(s)}).openapi(o.createRoute({tags:["resource-servers"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Us.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:ar}},description:"A resource server"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r=await t.env.data.resourceServers.create(e,n);return t.json(r,{status:201})}),C4=o.z.object({per_page:o.z.string().min(1).optional().default("50").transform(t=>parseInt(t,10)).openapi({description:"Number of results per page. Defaults to 50."}),page:o.z.string().min(0).optional().default("0").transform(t=>parseInt(t,10)).openapi({description:"Page index of the results to return. First page is 0."}),include_totals:o.z.string().optional().default("false").transform(t=>t==="true").openapi({description:"Return results inside an object that contains the total result count (true) or as a direct array of results (false, default)."}),from:o.z.string().optional().openapi({description:"Optional Id from which to start selection."}),take:o.z.string().min(1).optional().transform(t=>t?parseInt(t,10):void 0).openapi({description:"Number of results per page. Defaults to 50."}),audience:o.z.string().optional().openapi({description:"Optional filter on audience."}),client_id:o.z.string().optional().openapi({description:"Optional filter on client_id."}),allow_any_organization:o.z.string().optional().transform(t=>t==="true"?!0:t==="false"?!1:void 0).openapi({description:"Optional filter on allow_any_organization."}),subject_type:o.z.enum(["client","user"]).optional().openapi({description:"EA The type of application access the client grant allows. Use of this field is subject to the applicable Free Trial terms in Okta's Master Subscription Agreement."})}),N4=xt.extend({client_grants:o.z.array(sr)}),I4=new o.OpenAPIHono().openapi(o.createRoute({tags:["client-grants"],method:"get",path:"/",request:{query:C4,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(sr),N4])}},description:"List of client grants"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{page:n,per_page:r,include_totals:i=!1,from:s,take:a,audience:c,client_id:l,allow_any_organization:d,subject_type:u}=t.req.valid("query"),f=[];l&&f.push(`client_id:"${l}"`),c&&f.push(`audience:"${c}"`),d!==void 0&&f.push(`allow_any_organization:${d}`),u&&f.push(`subject_type:"${u}"`),s&&f.push(`id:>${s}`);const h=f.length>0?f.join(" AND "):void 0,m=a??r,y=await t.env.data.clientGrants.list(e,{page:n,per_page:m,include_totals:i,q:h});return i?t.json(y):t.json(y.client_grants)}).openapi(o.createRoute({tags:["client-grants"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:sr}},description:"A client grant"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=await t.env.data.clientGrants.get(e,n);if(!r)throw new b(404,{message:"Client grant not found"});return t.json(r)}).openapi(o.createRoute({tags:["client-grants"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param");if(!await t.env.data.clientGrants.remove(e,n))throw new b(404,{message:"Client grant not found"});return t.text("OK")}).openapi(o.createRoute({tags:["client-grants"],method:"patch",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),body:{content:{"application/json":{schema:o.z.object(Ps.shape).partial()}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:sr}},description:"The updated client grant"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=t.req.valid("json");if(!await t.env.data.clientGrants.get(e,n))throw new b(404,{message:"Client grant not found"});if(!await t.env.data.clientGrants.update(e,n,r))throw new b(500,{message:"Failed to update client grant"});const a=await t.env.data.clientGrants.get(e,n);if(!a)throw new b(404,{message:"Client grant not found"});return t.json(a)}).openapi(o.createRoute({tags:["client-grants"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Ps.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:sr}},description:"A client grant"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r=await t.env.data.clientGrants.create(e,n);return t.json(r,{status:201})}),j4=o.z.object({page:o.z.string().optional().default("0").transform(t=>parseInt(t,10)).openapi({description:"Page index of the results to return. First page is 0."}),per_page:o.z.string().optional().default("50").transform(t=>parseInt(t,10)).openapi({description:"Number of results per page. Defaults to 50."}),include_totals:o.z.string().optional().default("false").transform(t=>t==="true").openapi({description:"When true, return results inside an object that also contains the start and limit. When false (default), a direct array of results is returned."}),fields:o.z.string().optional().openapi({description:"Comma-separated list of fields to include or exclude (based on value provided for include_fields) in the result. Leave empty to retrieve all fields."}),include_fields:o.z.string().optional().default("true").transform(t=>t==="true").openapi({description:"Whether specified fields are to be included (true) or excluded (false). Defaults to true."}),sort:o.z.string().optional().default("created_at:-1").openapi({description:"Field to sort by. Use field:order where order is 1 for ascending and -1 for descending. Defaults to created_at:-1."})}),O4=o.z.object({invitations:o.z.array(Gi),start:o.z.number(),limit:o.z.number(),length:o.z.number()}),T4=wu.omit({organization_id:!0,invitation_url:!0}),P4=xt.extend({organizations:o.z.array(Un)}),vp=o.z.object({user_id:o.z.string().openapi({description:"ID of this user"}),email:o.z.string().email().optional().openapi({description:"Email address of this user",format:"email"}),roles:o.z.array(o.z.object({})).default([]).openapi({description:"Array of roles assigned to this user in the organization"})}),R4=o.z.object({start:o.z.number().openapi({description:"Start index of the current page"}),limit:o.z.number().openapi({description:"Number of items per page"}),total:o.z.number().openapi({description:"Total number of members"}),members:o.z.array(vp).openapi({description:"Array of organization members"})}),B4=o.z.object({next:o.z.string().optional().openapi({description:"Checkpoint ID to be used to retrieve the next set of results"}),members:o.z.array(vp).openapi({description:"Array of organization members"})}),L4=o.z.object({members:o.z.array(o.z.string()).openapi({description:"Array of user IDs to add to the organization"})}),U4=o.z.object({members:o.z.array(o.z.string()).openapi({description:"Array of user IDs to remove from the organization"})}),D4=new o.OpenAPIHono().openapi(o.createRoute({tags:["organizations"],method:"get",path:"/",request:{query:Ye,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([P4,o.z.array(Un)])}},description:"List of organizations"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{page:n,per_page:r,include_totals:i,sort:s,q:a}=t.req.valid("query"),c=await t.env.data.organizations.list(e,{page:n,per_page:r,include_totals:i,sort:pt(s),q:a});return i?t.json(c):t.json(c.organizations)}).openapi(o.createRoute({tags:["organizations"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Un}},description:"An organization"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=await t.env.data.organizations.get(e,n);if(!r)throw new b(404,{message:"Organization not found"});return t.json(r)}).openapi(o.createRoute({tags:["organizations"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Organization deleted successfully"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param");if(!await t.env.data.organizations.remove(e,n))throw new b(404,{message:"Organization not found"});return t.text("OK")}).openapi(o.createRoute({tags:["organizations"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:Fs.partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Un}},description:"The updated organization"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=t.req.valid("json");if(!await t.env.data.organizations.update(e,n,r))throw new b(404,{message:"Organization not found"});const s=await t.env.data.organizations.get(e,n);if(!s)throw new b(404,{message:"Organization not found"});return t.json(s)}).openapi(o.createRoute({tags:["organizations"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:Fs}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Un}},description:"The created organization"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r={...n,id:n.id||E$()},i=await t.env.data.organizations.create(e,r);return t.json(i,{status:201})}).openapi(o.createRoute({tags:["organizations"],method:"get",path:"/{id}/members",request:{params:o.z.object({id:o.z.string()}),query:Ye,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(vp),R4,B4])}},description:"List of organization members"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),{page:r,per_page:i,include_totals:s,sort:a}=t.req.valid("query");if(!await t.env.data.organizations.get(e,n))throw new b(404,{message:"Organization not found"});const l=await t.env.data.userOrganizations.list(e,{page:r,per_page:i,include_totals:s,sort:pt(a),q:`organization_id:${n}`}),d=[];for(const u of l.userOrganizations){const f=await t.env.data.users.get(e,u.user_id);f&&d.push({user_id:f.user_id,email:f.email||void 0,roles:[]})}return s?t.json({start:l.start,limit:l.limit,total:l.length,members:d}):t.json(d)}).openapi(o.createRoute({tags:["organizations"],method:"post",path:"/{id}/members",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:L4}}}},security:[{Bearer:["auth:write"]}],responses:{204:{description:"Members added successfully"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),{members:r}=t.req.valid("json");if(!await t.env.data.organizations.get(e,n))throw new b(404,{message:"Organization not found"});for(const s of r)(await t.env.data.userOrganizations.list(e,{q:`user_id:${s}`,per_page:1})).userOrganizations.some(l=>l.organization_id===n)||await t.env.data.userOrganizations.create(e,{user_id:s,organization_id:n});return new Response(null,{status:204})}).openapi(o.createRoute({tags:["organizations"],method:"delete",path:"/{id}/members",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:U4}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Members removed successfully"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),{members:r}=t.req.valid("json");for(const i of r){const a=(await t.env.data.userOrganizations.list(e,{q:`user_id:${i}`,per_page:100})).userOrganizations.find(c=>c.organization_id===n);a&&await t.env.data.userOrganizations.remove(e,a.id)}return t.json({message:"Members removed successfully"})}).openapi(o.createRoute({tags:["organizations"],method:"get",path:"/{id}/members/{user_id}/roles",request:{params:o.z.object({id:o.z.string(),user_id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),query:Ye},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Ms}},description:"User roles in organization"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n,user_id:r}=t.req.valid("param");if(!await t.env.data.organizations.get(e,n))throw new b(404,{message:"Organization not found"});if(!await t.env.data.users.get(e,r))throw new b(404,{message:"User not found"});const a=await t.env.data.userRoles.list(e,r,void 0,n);return t.json(a)}).openapi(o.createRoute({tags:["organizations"],method:"post",path:"/{id}/members/{user_id}/roles",request:{params:o.z.object({id:o.z.string(),user_id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object({roles:o.z.array(o.z.string()).openapi({description:"List of role IDs to associate with the user"})})}}}},security:[{Bearer:["auth:write"]}],responses:{201:{description:"Roles assigned successfully"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n,user_id:r}=t.req.valid("param"),{roles:i}=t.req.valid("json");if(!await t.env.data.organizations.get(e,n))throw new b(404,{message:"Organization not found"});if(!await t.env.data.users.get(e,r))throw new b(404,{message:"User not found"});for(const c of i){if(!await t.env.data.roles.get(e,c))throw new b(400,{message:`Role ${c} not found`});if(!await t.env.data.userRoles.create(e,r,c,n))throw new b(500,{message:`Failed to assign role ${c} to user`})}return t.json({message:"Roles assigned successfully"},{status:201})}).openapi(o.createRoute({tags:["organizations"],method:"delete",path:"/{id}/members/{user_id}/roles",request:{params:o.z.object({id:o.z.string(),user_id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object({roles:o.z.array(o.z.string()).openapi({description:"List of role IDs to remove from the user"})})}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Roles removed successfully"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n,user_id:r}=t.req.valid("param"),{roles:i}=t.req.valid("json");if(!await t.env.data.organizations.get(e,n))throw new b(404,{message:"Organization not found"});if(!await t.env.data.users.get(e,r))throw new b(404,{message:"User not found"});for(const c of i)if(!await t.env.data.userRoles.remove(e,r,c,n))throw new b(500,{message:`Failed to remove role ${c} from user`});return t.json({message:"Roles removed successfully"})}).openapi(o.createRoute({tags:["organizations"],method:"get",path:"/{id}/roles",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),query:Ye},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Ms}},description:"List of roles available in organization"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),{page:r,per_page:i,sort:s,q:a}=t.req.valid("query");if(!await t.env.data.organizations.get(e,n))throw new b(404,{message:"Organization not found"});const l=await t.env.data.roles.list(e,{page:r,per_page:i,sort:pt(s),q:a});return t.json(l.roles)}).openapi(o.createRoute({tags:["organizations"],method:"get",path:"/{id}/invitations",request:{params:o.z.object({id:o.z.string().openapi({description:"Organization ID",param:{name:"id",in:"path"}})}),query:j4,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(Gi),O4])}},description:"List of organization invitations"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),{page:r,per_page:i,include_totals:s,fields:a,include_fields:c,sort:l}=t.req.valid("query");if(!await t.env.data.organizations.get(e,n))throw new b(404,{message:"Organization not found"});let f=(await t.env.data.invites.list(e,{page:r,per_page:i})).invites.filter(h=>h.organization_id===n);if(l){const h=pt(l);if(h){const{sort_by:m,sort_order:y}=h;f.sort((v,$)=>{const A=v[m],O=$[m];if(A===void 0||O===void 0||A===O)return 0;const U=A<O?-1:1;return y==="asc"?U:-U})}}if(a){const h=a.split(",").map(m=>m.trim());f=f.map(m=>{const y={};for(const v of Object.keys(m))(c?h.includes(v):!h.includes(v))&&(y[v]=m[v]);return y})}return s?t.json({invitations:f,start:r*i,limit:i,length:f.length}):t.json(f)}).openapi(o.createRoute({tags:["organizations"],method:"get",path:"/{id}/invitations/{invitation_id}",request:{params:o.z.object({id:o.z.string().openapi({description:"Organization ID",param:{name:"id",in:"path"}}),invitation_id:o.z.string().openapi({description:"Invitation ID",param:{name:"invitation_id",in:"path"}})}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Gi}},description:"An invitation"},404:{description:"Invitation not found"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n,invitation_id:r}=t.req.valid("param"),i=await t.env.data.invites.get(e,r);if(!i||i.organization_id!==n)throw new b(404,{message:"Invitation not found"});return t.json(i)}).openapi(o.createRoute({tags:["organizations"],method:"post",path:"/{id}/invitations",request:{params:o.z.object({id:o.z.string().openapi({description:"Organization ID",param:{name:"id",in:"path"}})}),body:{content:{"application/json":{schema:T4}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Gi}},description:"The created invitation"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=t.req.valid("json");if(!await t.env.data.organizations.get(e,n))throw new b(404,{message:"Organization not found"});const a=`https://invite.placeholder/${I$()}`,c={...r,organization_id:n,invitation_url:a},l=await t.env.data.invites.create(e,c);return t.json(l,{status:201})}).openapi(o.createRoute({tags:["organizations"],method:"delete",path:"/{id}/invitations/{invitation_id}",request:{params:o.z.object({id:o.z.string().openapi({description:"Organization ID",param:{name:"id",in:"path"}}),invitation_id:o.z.string().openapi({description:"Invitation ID",param:{name:"invitation_id",in:"path"}})}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{204:{description:"Invitation deleted successfully"},404:{description:"Invitation not found"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n,invitation_id:r}=t.req.valid("param"),i=await t.env.data.invites.get(e,r);if(!i||i.organization_id!==n)throw new b(404,{message:"Invitation not found"});if(!await t.env.data.invites.remove(e,r))throw new b(404,{message:"Invitation not found"});return t.body(null,{status:204})});function M4(t){const e=new o.OpenAPIHono;e.use(g0({origin:r=>{var i;return r&&(i=t.allowedOrigins)!=null&&i.includes(r)?r:""},allowHeaders:["Tenant-Id","Content-Type","Content-Range","Auth0-Client","Authorization","Range","Upgrade-Insecure-Requests"],allowMethods:["POST","PUT","GET","DELETE","PATCH","OPTIONS"],exposeHeaders:["Content-Length","Content-Range"],maxAge:600,credentials:!0})),yp(e),e.use(async(r,i)=>{const s=xo(r,t.dataAdapter),a=Ho({defaultTtlSeconds:0,maxEntries:100,cleanupIntervalMs:0}),c=Dc(s,{defaultTtl:0,cacheEntities:["tenants","connections","clients","legacyClients","branding","themes","promptSettings","forms"],cache:a});return r.env.data=Rc(r,c),i()}),e.use(Uc).use(Lc).use(wp(e));const n=e.route("/branding",tv).route("/custom-domains",y4).route("/email/providers",g4).route("/users",vb).route("/keys",y$).route("/users-by-email",w$).route("/clients",b$).route("/client-grants",I4).route("/tenants",k$).route("/logs",S$).route("/hooks",O$).route("/connections",P$).route("/prompts",R$).route("/sessions",m4).route("/refresh_tokens",_4).route("/forms",x4).route("/roles",z4).route("/resource-servers",E4).route("/organizations",D4);return n.doc("/spec",{openapi:"3.0.0",info:{version:"1.0.0",title:"Management API"},servers:[{url:"/api/v2",description:"API V2"}],security:[{oauth2:["openid","email","profile"]}]}),n}function F4(t,e){Object.keys(e).forEach(n=>{const r=e[n];r!=null&&r.length&&t.searchParams.set(n,r)})}function Cn(t){var e;if(t)return`${t.name}/${t.version}${(e=t.env)!=null&&e.node?` (env: node/${t.env.node})`:""}`}var q4=(t,...e)=>{const n=[""];for(let r=0,i=t.length-1;r<i;r++){n[0]+=t[r];const s=Array.isArray(e[r])?e[r].flat(1/0):[e[r]];for(let a=0,c=s.length;a<c;a++){const l=s[a];if(typeof l=="string")Vn(l,n);else if(typeof l=="number")n[0]+=l;else{if(typeof l=="boolean"||l===null||l===void 0)continue;if(typeof l=="object"&&l.isEscaped)if(l.callbacks)n.unshift("",l);else{const d=l.toString();d instanceof Promise?n.unshift("",d):n[0]+=d}else l instanceof Promise?n.unshift("",l):Vn(l.toString(),n)}}}return n[0]+=t.at(-1),n.length===1?"callbacks"in n?Xt(Uy(Xt(n[0],n.callbacks))):Xt(n[0]):Ly(n,n.callbacks)},bp=Symbol("RENDERER"),eu=Symbol("ERROR_HANDLER"),Be=Symbol("STASH"),Dy=Symbol("INTERNAL"),H4=Symbol("MEMO"),za=Symbol("PERMALINK"),Zh=t=>(t[Dy]=!0,t),My=t=>({value:e,children:n})=>{if(!n)return;const r={children:[{tag:Zh(()=>{t.push(e)}),props:{}}]};Array.isArray(n)?r.children.push(...n.flat()):r.children.push(n),r.children.push({tag:Zh(()=>{t.pop()}),props:{}});const i={tag:"",props:r,type:""};return i[eu]=s=>{throw t.pop(),s},i},Fy=t=>{const e=[t],n=My(e);return n.values=e,n.Provider=n,gi.push(n),n},gi=[],qy=t=>{const e=[t],n=r=>{e.push(r.value);let i;try{i=r.children?(Array.isArray(r.children)?new Gy("",{},r.children):r.children).toString():""}finally{e.pop()}return i instanceof Promise?i.then(s=>Xt(s,s.callbacks)):Xt(i)};return n.values=e,n.Provider=n,n[bp]=My(e),gi.push(n),n},ji=t=>t.values.at(-1),ws={title:[],script:["src"],style:["data-href"],link:["href"],meta:["name","httpEquiv","charset","itemProp"]},tu={},vs="data-precedence",Vo=t=>Array.isArray(t)?t:[t],Yh=new WeakMap,Qh=(t,e,n,r)=>({buffer:i,context:s})=>{if(!i)return;const a=Yh.get(s)||{};Yh.set(s,a);const c=a[t]||(a[t]=[]);let l=!1;const d=ws[t];if(d.length>0){e:for(const[,u]of c)for(const f of d)if(((u==null?void 0:u[f])??null)===(n==null?void 0:n[f])){l=!0;break e}}if(l?i[0]=i[0].replaceAll(e,""):d.length>0?c.push([e,n,r]):c.unshift([e,n,r]),i[0].indexOf("</head>")!==-1){let u;if(r===void 0)u=c.map(([f])=>f);else{const f=[];u=c.map(([h,,m])=>{let y=f.indexOf(m);return y===-1&&(f.push(m),y=f.length-1),[h,y]}).sort((h,m)=>h[1]-m[1]).map(([h])=>h)}u.forEach(f=>{i[0]=i[0].replaceAll(f,"")}),i[0]=i[0].replace(/(?=<\/head>)/,u.join(""))}},Ko=(t,e,n)=>Xt(new Zt(t,n,Vo(e??[])).toString()),Go=(t,e,n,r)=>{if("itemProp"in n)return Ko(t,e,n);let{precedence:i,blocking:s,...a}=n;i=r?i??"":void 0,r&&(a[vs]=i);const c=new Zt(t,a,Vo(e||[])).toString();return c instanceof Promise?c.then(l=>Xt(c,[...l.callbacks||[],Qh(t,l,a,i)])):Xt(c,[Qh(t,c,a,i)])},V4=({children:t,...e})=>{const n=$p();if(n){const r=ji(n);if(r==="svg"||r==="head")return new Zt("title",e,Vo(t??[]))}return Go("title",t,e,!1)},K4=({children:t,...e})=>{const n=$p();return["src","async"].some(r=>!e[r])||n&&ji(n)==="head"?Ko("script",t,e):Go("script",t,e,!1)},G4=({children:t,...e})=>["href","precedence"].every(n=>n in e)?(e["data-href"]=e.href,delete e.href,Go("style",t,e,!0)):Ko("style",t,e),W4=({children:t,...e})=>["onLoad","onError"].some(n=>n in e)||e.rel==="stylesheet"&&(!("precedence"in e)||"disabled"in e)?Ko("link",t,e):Go("link",t,e,"precedence"in e),J4=({children:t,...e})=>{const n=$p();return n&&ji(n)==="head"?Ko("meta",t,e):Go("meta",t,e,!1)},Hy=(t,{children:e,...n})=>new Zt(t,n,Vo(e??[])),X4=t=>(typeof t.action=="function"&&(t.action=za in t.action?t.action[za]:void 0),Hy("form",t)),Vy=(t,e)=>(typeof e.formAction=="function"&&(e.formAction=za in e.formAction?e.formAction[za]:void 0),Hy(t,e)),Z4=t=>Vy("input",t),Y4=t=>Vy("button",t);const dl=Object.freeze(Object.defineProperty({__proto__:null,button:Y4,form:X4,input:Z4,link:W4,meta:J4,script:K4,style:G4,title:V4},Symbol.toStringTag,{value:"Module"}));var Q4=new Map([["className","class"],["htmlFor","for"],["crossOrigin","crossorigin"],["httpEquiv","http-equiv"],["itemProp","itemprop"],["fetchPriority","fetchpriority"],["noModule","nomodule"],["formAction","formaction"]]),Aa=t=>Q4.get(t)||t,Ky=(t,e)=>{for(const[n,r]of Object.entries(t)){const i=n[0]==="-"||!/[A-Z]/.test(n)?n:n.replace(/[A-Z]/g,s=>`-${s.toLowerCase()}`);e(i,r==null?null:typeof r=="number"?i.match(/^(?:a|border-im|column(?:-c|s)|flex(?:$|-[^b])|grid-(?:ar|[^a])|font-w|li|or|sca|st|ta|wido|z)|ty$/)?`${r}`:`${r}px`:r)}},yo=void 0,$p=()=>yo,ek=t=>/[A-Z]/.test(t)&&t.match(/^(?:al|basel|clip(?:Path|Rule)$|co|do|fill|fl|fo|gl|let|lig|i|marker[EMS]|o|pai|pointe|sh|st[or]|text[^L]|tr|u|ve|w)/)?t.replace(/([A-Z])/g,"-$1").toLowerCase():t,tk=["area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],nk=["allowfullscreen","async","autofocus","autoplay","checked","controls","default","defer","disabled","download","formnovalidate","hidden","inert","ismap","itemscope","loop","multiple","muted","nomodule","novalidate","open","playsinline","readonly","required","reversed","selected"],kp=(t,e)=>{for(let n=0,r=t.length;n<r;n++){const i=t[n];if(typeof i=="string")Vn(i,e);else{if(typeof i=="boolean"||i===null||i===void 0)continue;i instanceof Zt?i.toStringToBuffer(e):typeof i=="number"||i.isEscaped?e[0]+=i:i instanceof Promise?e.unshift("",i):kp(i,e)}}},Zt=class{constructor(t,e,n){se(this,"tag");se(this,"props");se(this,"key");se(this,"children");se(this,"isEscaped",!0);se(this,"localContexts");this.tag=t,this.props=e,this.children=n}get type(){return this.tag}get ref(){return this.props.ref||null}toString(){var e,n;const t=[""];(e=this.localContexts)==null||e.forEach(([r,i])=>{r.values.push(i)});try{this.toStringToBuffer(t)}finally{(n=this.localContexts)==null||n.forEach(([r])=>{r.values.pop()})}return t.length===1?"callbacks"in t?Uy(Xt(t[0],t.callbacks)).toString():t[0]:Ly(t,t.callbacks)}toStringToBuffer(t){const e=this.tag,n=this.props;let{children:r}=this;t[0]+=`<${e}`;const i=yo&&ji(yo)==="svg"?s=>ek(Aa(s)):s=>Aa(s);for(let[s,a]of Object.entries(n))if(s=i(s),s!=="children"){if(s==="style"&&typeof a=="object"){let c="";Ky(a,(l,d)=>{d!=null&&(c+=`${c?";":""}${l}:${d}`)}),t[0]+=' style="',Vn(c,t),t[0]+='"'}else if(typeof a=="string")t[0]+=` ${s}="`,Vn(a,t),t[0]+='"';else if(a!=null)if(typeof a=="number"||a.isEscaped)t[0]+=` ${s}="${a}"`;else if(typeof a=="boolean"&&nk.includes(s))a&&(t[0]+=` ${s}=""`);else if(s==="dangerouslySetInnerHTML"){if(r.length>0)throw new Error("Can only set one of `children` or `props.dangerouslySetInnerHTML`.");r=[Xt(a.__html)]}else if(a instanceof Promise)t[0]+=` ${s}="`,t.unshift('"',a);else if(typeof a=="function"){if(!s.startsWith("on")&&s!=="ref")throw new Error(`Invalid prop '${s}' of type 'function' supplied to '${e}'.`)}else t[0]+=` ${s}="`,Vn(a.toString(),t),t[0]+='"'}if(tk.includes(e)&&r.length===0){t[0]+="/>";return}t[0]+=">",kp(r,t),t[0]+=`</${e}>`}},ul=class extends Zt{toStringToBuffer(t){const{children:e}=this,n=this.tag.call(null,{...this.props,children:e.length<=1?e[0]:e});if(!(typeof n=="boolean"||n==null))if(n instanceof Promise)if(gi.length===0)t.unshift("",n);else{const r=gi.map(i=>[i,i.values.at(-1)]);t.unshift("",n.then(i=>(i instanceof Zt&&(i.localContexts=r),i)))}else n instanceof Zt?n.toStringToBuffer(t):typeof n=="number"||n.isEscaped?(t[0]+=n,n.callbacks&&(t.callbacks||(t.callbacks=[]),t.callbacks.push(...n.callbacks))):Vn(n,t)}},Gy=class extends Zt{toStringToBuffer(t){kp(this.children,t)}},rk=(t,e,...n)=>{e??(e={}),n.length&&(e.children=n.length===1?n[0]:n);const r=e.key;delete e.key;const i=bs(t,e,n);return i.key=r,i},eg=!1,bs=(t,e,n)=>{if(!eg){for(const r in tu)dl[r][bp]=tu[r];eg=!0}return typeof t=="function"?new ul(t,e,n):dl[t]?new ul(dl[t],e,n):t==="svg"||t==="head"?(yo||(yo=qy("")),new Zt(t,e,[new ul(yo,{value:t},n)])):new Zt(t,e,n)},Mc=({children:t})=>new Gy("",{children:t},Array.isArray(t)?t:t?[t]:[]),ik=(t,e,...n)=>{let r;if(n.length>0)r=n;else{const i=t.props.children;r=Array.isArray(i)?i:[i]}return rk(t.tag,{...t.props,...e},...r)};function p(t,e,n){let r;if(!e||!("children"in e))r=bs(t,e,[]);else{const i=e.children;r=Array.isArray(i)?bs(t,e,i):bs(t,e,[i])}return r.key=n,r}var tg;(function(t){t[t.Include=0]="Include",t[t.None=1]="None"})(tg||(tg={}));var ng;(function(t){t[t.Required=0]="Required",t[t.Ignore=1]="Ignore"})(ng||(ng={}));function ok(t){return Jy(t,sk,wo.Include)}function Wy(t){return Jy(t,ak,wo.None)}function Jy(t,e,n){let r="";for(let i=0;i<t.byteLength;i+=3){let s=0,a=0;for(let c=0;c<3&&i+c<t.byteLength;c++)s=s<<8|t[i+c],a+=8;for(let c=0;c<4;c++)a>=6?(r+=e[s>>a-6&63],a-=6):a>0?(r+=e[s<<6-a&63],a=0):n===wo.Include&&(r+="=")}return r}const sk="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",ak="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";var wo;(function(t){t[t.Include=0]="Include",t[t.None=1]="None"})(wo||(wo={}));var rg;(function(t){t[t.Required=0]="Required",t[t.Ignore=1]="Ignore"})(rg||(rg={}));class ck{uint8(e,n){if(e.byteLength<n+1)throw new TypeError("Insufficient bytes");return e[n]}uint16(e,n){if(e.byteLength<n+2)throw new TypeError("Insufficient bytes");return e[n]<<8|e[n+1]}uint32(e,n){if(e.byteLength<n+4)throw new TypeError("Insufficient bytes");let r=0;for(let i=0;i<4;i++)r|=e[n+i]<<24-i*8;return r}uint64(e,n){if(e.byteLength<n+8)throw new TypeError("Insufficient bytes");let r=0n;for(let i=0;i<8;i++)r|=BigInt(e[n+i])<<BigInt(56-i*8);return r}putUint8(e,n,r){if(e.length<r+1)throw new TypeError("Not enough space");if(n<0||n>255)throw new TypeError("Invalid uint8 value");e[r]=n}putUint16(e,n,r){if(e.length<r+2)throw new TypeError("Not enough space");if(n<0||n>65535)throw new TypeError("Invalid uint16 value");e[r]=n>>8,e[r+1]=n&255}putUint32(e,n,r){if(e.length<r+4)throw new TypeError("Not enough space");if(n<0||n>4294967295)throw new TypeError("Invalid uint32 value");for(let i=0;i<4;i++)e[r+i]=n>>(3-i)*8&255}putUint64(e,n,r){if(e.length<r+8)throw new TypeError("Not enough space");if(n<0||n>18446744073709551615n)throw new TypeError("Invalid uint64 value");for(let i=0;i<8;i++)e[r+i]=Number(n>>BigInt((7-i)*8)&0xffn)}}const ig=new ck;function sn(t,e){return(t<<32-e|t>>>e)>>>0}function lk(t){const e=new dk;return e.update(t),e.digest()}class dk{constructor(){se(this,"blockSize",64);se(this,"size",32);se(this,"blocks",new Uint8Array(64));se(this,"currentBlockSize",0);se(this,"H",new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]));se(this,"l",0n);se(this,"w",new Uint32Array(64))}update(e){if(this.l+=BigInt(e.byteLength)*8n,this.currentBlockSize+e.byteLength<64){this.blocks.set(e,this.currentBlockSize),this.currentBlockSize+=e.byteLength;return}let n=0;if(this.currentBlockSize>0){const r=e.slice(0,64-this.currentBlockSize);this.blocks.set(r,this.currentBlockSize),this.process(),n+=r.byteLength,this.currentBlockSize=0}for(;n+64<=e.byteLength;){const r=e.slice(n,n+64);this.blocks.set(r),this.process(),n+=64}if(e.byteLength-n>0){const r=e.slice(n);this.blocks.set(r),this.currentBlockSize=r.byteLength}}digest(){this.blocks[this.currentBlockSize]=128,this.currentBlockSize+=1,64-this.currentBlockSize<8&&(this.blocks.fill(0,this.currentBlockSize),this.process(),this.currentBlockSize=0),this.blocks.fill(0,this.currentBlockSize),ig.putUint64(this.blocks,this.l,this.blockSize-8),this.process();const e=new Uint8Array(32);for(let n=0;n<8;n++)ig.putUint32(e,this.H[n],n*4);return e}process(){for(let d=0;d<16;d++)this.w[d]=(this.blocks[d*4]<<24|this.blocks[d*4+1]<<16|this.blocks[d*4+2]<<8|this.blocks[d*4+3])>>>0;for(let d=16;d<64;d++){const u=(sn(this.w[d-2],17)^sn(this.w[d-2],19)^this.w[d-2]>>>10)>>>0,f=(sn(this.w[d-15],7)^sn(this.w[d-15],18)^this.w[d-15]>>>3)>>>0;this.w[d]=u+this.w[d-7]+f+this.w[d-16]|0}let e=this.H[0],n=this.H[1],r=this.H[2],i=this.H[3],s=this.H[4],a=this.H[5],c=this.H[6],l=this.H[7];for(let d=0;d<64;d++){const u=(sn(s,6)^sn(s,11)^sn(s,25))>>>0,f=(s&a^~s&c)>>>0,h=l+u+f+uk[d]+this.w[d]|0,m=(sn(e,2)^sn(e,13)^sn(e,22))>>>0,y=(e&n^e&r^n&r)>>>0,v=m+y|0;l=c,c=a,a=s,s=i+h|0,i=r,r=n,n=e,e=h+v|0}this.H[0]=e+this.H[0]|0,this.H[1]=n+this.H[1]|0,this.H[2]=r+this.H[2]|0,this.H[3]=i+this.H[3]|0,this.H[4]=s+this.H[4]|0,this.H[5]=a+this.H[5]|0,this.H[6]=c+this.H[6]|0,this.H[7]=l+this.H[7]|0}}const uk=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);new BigUint64Array([0x428a2f98d728ae22n,0x7137449123ef65cdn,0xb5c0fbcfec4d3b2fn,0xe9b5dba58189dbbcn,0x3956c25bf348b538n,0x59f111f1b605d019n,0x923f82a4af194f9bn,0xab1c5ed5da6d8118n,0xd807aa98a3030242n,0x12835b0145706fben,0x243185be4ee4b28cn,0x550c7dc3d5ffb4e2n,0x72be5d74f27b896fn,0x80deb1fe3b1696b1n,0x9bdc06a725c71235n,0xc19bf174cf692694n,0xe49b69c19ef14ad2n,0xefbe4786384f25e3n,0x0fc19dc68b8cd5b5n,0x240ca1cc77ac9c65n,0x2de92c6f592b0275n,0x4a7484aa6ea6e483n,0x5cb0a9dcbd41fbd4n,0x76f988da831153b5n,0x983e5152ee66dfabn,0xa831c66d2db43210n,0xb00327c898fb213fn,0xbf597fc7beef0ee4n,0xc6e00bf33da88fc2n,0xd5a79147930aa725n,0x06ca6351e003826fn,0x142929670a0e6e70n,0x27b70a8546d22ffcn,0x2e1b21385c26c926n,0x4d2c6dfc5ac42aedn,0x53380d139d95b3dfn,0x650a73548baf63den,0x766a0abb3c77b2a8n,0x81c2c92e47edaee6n,0x92722c851482353bn,0xa2bfe8a14cf10364n,0xa81a664bbc423001n,0xc24b8b70d0f89791n,0xc76c51a30654be30n,0xd192e819d6ef5218n,0xd69906245565a910n,0xf40e35855771202an,0x106aa07032bbd1b8n,0x19a4c116b8d2d0c8n,0x1e376c085141ab53n,0x2748774cdf8eeb99n,0x34b0bcb5e19b48a8n,0x391c0cb3c5c95a63n,0x4ed8aa4ae3418acbn,0x5b9cca4f7763e373n,0x682e6ff3d6b2b8a3n,0x748f82ee5defb2fcn,0x78a5636f43172f60n,0x84c87814a1f0ab72n,0x8cc702081a6439ecn,0x90befffa23631e28n,0xa4506cebde82bde9n,0xbef9a3f7b2c67915n,0xc67178f2e372532bn,0xca273eceea26619cn,0xd186b8c721c0c207n,0xeada7dd6cde0eb1en,0xf57d4f7fee6ed178n,0x06f067aa72176fban,0x0a637dc5a2c898a6n,0x113f9804bef90daen,0x1b710b35131c471bn,0x28db77f523047d84n,0x32caab7b40c72493n,0x3c9ebe0a15c9bebcn,0x431d67c49c100d4cn,0x4cc5d4becb3e42b6n,0x597f299cfc657e2an,0x5fcb6fab3ad6faecn,0x6c44198c4a475817n]);class Xy{constructor(e){se(this,"data");this.data=e}tokenType(){if("token_type"in this.data&&typeof this.data.token_type=="string")return this.data.token_type;throw new Error("Missing or invalid 'token_type' field")}accessToken(){if("access_token"in this.data&&typeof this.data.access_token=="string")return this.data.access_token;throw new Error("Missing or invalid 'access_token' field")}accessTokenExpiresInSeconds(){if("expires_in"in this.data&&typeof this.data.expires_in=="number")return this.data.expires_in;throw new Error("Missing or invalid 'expires_in' field")}accessTokenExpiresAt(){return new Date(Date.now()+this.accessTokenExpiresInSeconds()*1e3)}hasRefreshToken(){return"refresh_token"in this.data&&typeof this.data.refresh_token=="string"}refreshToken(){if("refresh_token"in this.data&&typeof this.data.refresh_token=="string")return this.data.refresh_token;throw new Error("Missing or invalid 'refresh_token' field")}hasScopes(){return"scope"in this.data&&typeof this.data.scope=="string"}scopes(){if("scope"in this.data&&typeof this.data.scope=="string")return this.data.scope.split(" ");throw new Error("Missing or invalid 'scope' field")}idToken(){if("id_token"in this.data&&typeof this.data.id_token=="string")return this.data.id_token;throw new Error("Missing or invalid field 'id_token'")}}function pk(t){const e=lk(new TextEncoder().encode(t));return Wy(e)}function Zy(){const t=new Uint8Array(32);return crypto.getRandomValues(t),Wy(t)}function fk(t,e){if(e.length!==1)throw new TypeError("Invalid character string");let n=0;for(;n<t.length&&t[n]===e;)n++;return t.slice(n)}function og(t,e){if(e.length!==1)throw new TypeError("Invalid character string");let n=t.length;for(;n>0&&t[n-1]===e;)n--;return t.slice(0,n)}function sg(t,...e){let n=og(t,"/");for(const r of e)n=og(n,"/")+"/"+fk(r,"/");return n}function gr(t,e){const n=new TextEncoder().encode(e.toString()),r=new Request(t,{method:"POST",body:n});return r.headers.set("Content-Type","application/x-www-form-urlencoded"),r.headers.set("Accept","application/json"),r.headers.set("User-Agent","arctic"),r.headers.set("Content-Length",n.byteLength.toString()),r}function eo(t,e){const n=new TextEncoder().encode(`${t}:${e}`);return ok(n)}async function Ea(t){let e;try{e=await fetch(t)}catch(n){throw new Sp(n)}if(e.status===400||e.status===401){let n;try{n=await e.json()}catch{throw new Zr(e.status)}if(typeof n!="object"||n===null)throw new Kn(e.status,n);let r;try{r=xp(n)}catch{throw new Kn(e.status,n)}throw r}if(e.status===200){let n;try{n=await e.json()}catch{throw new Zr(e.status)}if(typeof n!="object"||n===null)throw new Kn(e.status,n);return new Xy(n)}throw e.body!==null&&await e.body.cancel(),new Zr(e.status)}async function hk(t){let e;try{e=await fetch(t)}catch(n){throw new Sp(n)}if(e.status===400||e.status===401){let n;try{n=await e.json()}catch{throw new Kn(e.status,null)}if(typeof n!="object"||n===null)throw new Kn(e.status,n);let r;try{r=xp(n)}catch{throw new Kn(e.status,n)}throw r}if(e.status===200){e.body!==null&&await e.body.cancel();return}throw e.body!==null&&await e.body.cancel(),new Zr(e.status)}function xp(t){let e;if("error"in t&&typeof t.error=="string")e=t.error;else throw new Error("Invalid error response");let n=null,r=null,i=null;if("error_description"in t){if(typeof t.error_description!="string")throw new Error("Invalid data");n=t.error_description}if("error_uri"in t){if(typeof t.error_uri!="string")throw new Error("Invalid data");r=t.error_uri}if("state"in t){if(typeof t.state!="string")throw new Error("Invalid data");i=t.state}return new gk(e,n,r,i)}class Sp extends Error{constructor(e){super("Failed to send request",{cause:e})}}class gk extends Error{constructor(n,r,i,s){super(`OAuth request error: ${n}`);se(this,"code");se(this,"description");se(this,"uri");se(this,"state");this.code=n,this.description=r,this.uri=i,this.state=s}}class Zr extends Error{constructor(n){super("Unexpected error response");se(this,"status");this.status=n}}class Kn extends Error{constructor(n,r){super("Unexpected error response body");se(this,"status");se(this,"data");this.status=n,this.data=r}}class Fc{constructor(e,n,r){se(this,"clientId");se(this,"clientPassword");se(this,"redirectURI");this.clientId=e,this.clientPassword=n,this.redirectURI=r}createAuthorizationURL(e,n,r){const i=new URL(e);return i.searchParams.set("response_type","code"),i.searchParams.set("client_id",this.clientId),this.redirectURI!==null&&i.searchParams.set("redirect_uri",this.redirectURI),i.searchParams.set("state",n),r.length>0&&i.searchParams.set("scope",r.join(" ")),i}createAuthorizationURLWithPKCE(e,n,r,i,s){const a=new URL(e);if(a.searchParams.set("response_type","code"),a.searchParams.set("client_id",this.clientId),this.redirectURI!==null&&a.searchParams.set("redirect_uri",this.redirectURI),a.searchParams.set("state",n),r===mi.S256){const c=pk(i);a.searchParams.set("code_challenge_method","S256"),a.searchParams.set("code_challenge",c)}else r===mi.Plain&&(a.searchParams.set("code_challenge_method","plain"),a.searchParams.set("code_challenge",i));return s.length>0&&a.searchParams.set("scope",s.join(" ")),a}async validateAuthorizationCode(e,n,r){const i=new URLSearchParams;i.set("grant_type","authorization_code"),i.set("code",n),this.redirectURI!==null&&i.set("redirect_uri",this.redirectURI),r!==null&&i.set("code_verifier",r),this.clientPassword===null&&i.set("client_id",this.clientId);const s=gr(e,i);if(this.clientPassword!==null){const c=eo(this.clientId,this.clientPassword);s.headers.set("Authorization",`Basic ${c}`)}return await Ea(s)}async refreshAccessToken(e,n,r){const i=new URLSearchParams;i.set("grant_type","refresh_token"),i.set("refresh_token",n),this.clientPassword===null&&i.set("client_id",this.clientId),r.length>0&&i.set("scope",r.join(" "));const s=gr(e,i);if(this.clientPassword!==null){const c=eo(this.clientId,this.clientPassword);s.headers.set("Authorization",`Basic ${c}`)}return await Ea(s)}async revokeToken(e,n){const r=new URLSearchParams;r.set("token",n),this.clientPassword===null&&r.set("client_id",this.clientId);const i=gr(e,r);if(this.clientPassword!==null){const s=eo(this.clientId,this.clientPassword);i.headers.set("Authorization",`Basic ${s}`)}await hk(i)}}var mi;(function(t){t[t.S256=0]="S256",t[t.Plain=1]="Plain"})(mi||(mi={}));var ag;(function(t){t[t.Include=0]="Include",t[t.None=1]="None"})(ag||(ag={}));var cg;(function(t){t[t.Required=0]="Required",t[t.Ignore=1]="Ignore"})(cg||(cg={}));function to(t){return mk(t,_k,Ca.None)}function mk(t,e,n){let r="";for(let i=0;i<t.byteLength;i+=3){let s=0,a=0;for(let c=0;c<3&&i+c<t.byteLength;c++)s=s<<8|t[i+c],a+=8;for(let c=0;c<4;c++)a>=6?(r+=e[s>>a-6&63],a-=6):a>0?(r+=e[s<<6-a&63],a=0):n===Ca.Include&&(r+="=")}return r}const _k="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";var Ca;(function(t){t[t.Include=0]="Include",t[t.None=1]="None"})(Ca||(Ca={}));var lg;(function(t){t[t.Required=0]="Required",t[t.Ignore=1]="Ignore"})(lg||(lg={}));function yk(t,e,n){const r=to(new TextEncoder().encode(t)),i=to(new TextEncoder().encode(e)),s=to(n);return r+"."+i+"."+s}function wk(t,e){const n=to(new TextEncoder().encode(t)),r=to(new TextEncoder().encode(e)),i=n+"."+r;return new TextEncoder().encode(i)}const vk="https://appleid.apple.com/auth/authorize",bk="https://appleid.apple.com/auth/token";class Yy{constructor(e,n,r,i,s){se(this,"clientId");se(this,"teamId");se(this,"keyId");se(this,"pkcs8PrivateKey");se(this,"redirectURI");this.clientId=e,this.teamId=n,this.keyId=r,this.pkcs8PrivateKey=i,this.redirectURI=s}createAuthorizationURL(e,n){const r=new URL(vk);return r.searchParams.set("response_type","code"),r.searchParams.set("client_id",this.clientId),r.searchParams.set("state",e),n.length>0&&r.searchParams.set("scope",n.join(" ")),r.searchParams.set("redirect_uri",this.redirectURI),r}async validateAuthorizationCode(e){const n=new URLSearchParams;n.set("grant_type","authorization_code"),n.set("code",e),n.set("redirect_uri",this.redirectURI),n.set("client_id",this.clientId);const r=await this.createClientSecret();n.set("client_secret",r);const i=gr(bk,n);return await Ea(i)}async createClientSecret(){const e=await crypto.subtle.importKey("pkcs8",this.pkcs8PrivateKey,{name:"ECDSA",namedCurve:"P-256"},!1,["sign"]),n=Math.floor(Date.now()/1e3),r=JSON.stringify({typ:"JWT",alg:"ES256",kid:this.keyId}),i=JSON.stringify({iss:this.teamId,exp:n+5*60,aud:["https://appleid.apple.com"],sub:this.clientId,iat:n}),s=new Uint8Array(await crypto.subtle.sign({name:"ECDSA",hash:"SHA-256"},e,wk(r,i)));return yk(r,i,s)}}const $k="https://www.facebook.com/v16.0/dialog/oauth",kk="https://graph.facebook.com/v16.0/oauth/access_token";class Qy{constructor(e,n,r){se(this,"clientId");se(this,"clientSecret");se(this,"redirectURI");this.clientId=e,this.clientSecret=n,this.redirectURI=r}createAuthorizationURL(e,n){const r=new URL($k);return r.searchParams.set("response_type","code"),r.searchParams.set("client_id",this.clientId),r.searchParams.set("state",e),n.length>0&&r.searchParams.set("scope",n.join(" ")),r.searchParams.set("redirect_uri",this.redirectURI),r}async validateAuthorizationCode(e){const n=new URLSearchParams;n.set("grant_type","authorization_code"),n.set("code",e),n.set("redirect_uri",this.redirectURI),n.set("client_id",this.clientId),n.set("client_secret",this.clientSecret);const r=gr(kk,n);return await Ea(r)}}const xk="https://github.com/login/oauth/authorize",dg="https://github.com/login/oauth/access_token";class e1{constructor(e,n,r){se(this,"clientId");se(this,"clientSecret");se(this,"redirectURI");this.clientId=e,this.clientSecret=n,this.redirectURI=r}createAuthorizationURL(e,n){const r=new URL(xk);return r.searchParams.set("response_type","code"),r.searchParams.set("client_id",this.clientId),r.searchParams.set("state",e),n.length>0&&r.searchParams.set("scope",n.join(" ")),this.redirectURI!==null&&r.searchParams.set("redirect_uri",this.redirectURI),r}async validateAuthorizationCode(e){const n=new URLSearchParams;n.set("grant_type","authorization_code"),n.set("code",e),this.redirectURI!==null&&n.set("redirect_uri",this.redirectURI);const r=gr(dg,n),i=eo(this.clientId,this.clientSecret);return r.headers.set("Authorization",`Basic ${i}`),await ug(r)}async refreshAccessToken(e){const n=new URLSearchParams;n.set("grant_type","refresh_token"),n.set("refresh_token",e);const r=gr(dg,n),i=eo(this.clientId,this.clientSecret);return r.headers.set("Authorization",`Basic ${i}`),await ug(r)}}async function ug(t){let e;try{e=await fetch(t)}catch(i){throw new Sp(i)}if(e.status!==200)throw e.body!==null&&await e.body.cancel(),new Zr(e.status);let n;try{n=await e.json()}catch{throw new Zr(e.status)}if(typeof n!="object"||n===null)throw new Kn(e.status,n);if("error"in n&&typeof n.error=="string"){let i;try{i=xp(n)}catch{throw new Kn(e.status,n)}throw i}return new Xy(n)}const Sk="https://accounts.google.com/o/oauth2/v2/auth",pg="https://oauth2.googleapis.com/token",zk="https://oauth2.googleapis.com/revoke";let t1=class{constructor(e,n,r){se(this,"client");this.client=new Fc(e,n,r)}createAuthorizationURL(e,n,r){return this.client.createAuthorizationURLWithPKCE(Sk,e,mi.S256,n,r)}async validateAuthorizationCode(e,n){return await this.client.validateAuthorizationCode(pg,e,n)}async refreshAccessToken(e){return await this.client.refreshAccessToken(pg,e,[])}async revokeToken(e){await this.client.revokeToken(zk,e)}};class n1{constructor(e,n,r,i){se(this,"authorizationEndpoint");se(this,"tokenEndpoint");se(this,"client");this.authorizationEndpoint=sg("https://login.microsoftonline.com",e,"/oauth2/v2.0/authorize"),this.tokenEndpoint=sg("https://login.microsoftonline.com",e,"/oauth2/v2.0/token"),this.client=new Fc(n,r,i)}createAuthorizationURL(e,n,r){return this.client.createAuthorizationURLWithPKCE(this.authorizationEndpoint,e,mi.S256,n,r)}async validateAuthorizationCode(e,n){return await this.client.validateAuthorizationCode(this.tokenEndpoint,e,n)}async refreshAccessToken(e,n){return await this.client.refreshAccessToken(this.tokenEndpoint,e,n)}}const Wo=o.z.object({iss:o.z.string().url(),sub:o.z.string(),aud:o.z.string(),exp:o.z.number(),email:o.z.string().optional(),given_name:o.z.string().optional(),family_name:o.z.string().optional(),name:o.z.string().optional(),iat:o.z.number(),auth_time:o.z.number().optional(),nonce:o.z.string().optional(),acr:o.z.string().optional(),amr:o.z.array(o.z.string()).optional(),azp:o.z.string().optional(),at_hash:o.z.string().optional(),c_hash:o.z.string().optional()}).passthrough();Wo.omit({iat:!0,auth_time:!0,nonce:!0,acr:!0,amr:!0,azp:!0,at_hash:!0,c_hash:!0});const Ak="Apple",Ek=({className:t=""})=>p("svg",{width:"45",height:"45",viewBox:"0 0 45 45",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:t,children:[p("path",{d:"M45 0H0V45H45V0Z",fill:"white"}),p("path",{d:"M23.5344 10.3846C25.5313 10.3846 28.0344 9.01144 29.525 7.18055C30.875 5.5213 31.8594 3.20407 31.8594 0.886839C31.8594 0.572154 31.8313 0.25747 31.775 0C29.5531 0.0858233 26.8813 1.51621 25.2781 3.43293C24.0125 4.89193 22.8594 7.18055 22.8594 9.52638C22.8594 9.86968 22.9156 10.213 22.9438 10.3274C23.0844 10.356 23.3094 10.3846 23.5344 10.3846ZM16.5031 45C19.2313 45 20.4406 43.1405 23.8438 43.1405C27.3031 43.1405 28.0625 44.9428 31.1 44.9428C34.0813 44.9428 36.0781 42.1392 37.9625 39.3929C40.0719 36.246 40.9438 33.1564 41 33.0134C40.8031 32.9561 35.0938 30.5817 35.0938 23.9161C35.0938 18.1373 39.5938 15.534 39.8469 15.3338C36.8656 10.9854 32.3375 10.8709 31.1 10.8709C27.7531 10.8709 25.025 12.9307 23.3094 12.9307C21.4531 12.9307 19.0063 10.9854 16.1094 10.9854C10.5969 10.9854 5 15.6198 5 24.3738C5 29.8093 7.08125 35.5594 9.64063 39.2784C11.8344 42.4253 13.7469 45 16.5031 45Z",fill:"black"})]});function r1(t){const{options:e}=t;if(!e||!e.client_id||!e.team_id||!e.kid||!e.app_secret)throw new Error("Missing required Apple authentication parameters");const n=Buffer.from(e.app_secret,"utf-8"),r=n.toString().replace(/-----BEGIN PRIVATE KEY-----|-----END PRIVATE KEY-----|\s/g,""),i=Uint8Array.from(Buffer.from(r,"base64"));return n.fill(0),{options:e,keyArray:i}}async function Ck(t,e){var d,u;const{options:n,keyArray:r}=r1(e),i=`${qe(t.env)}callback`,s=new Yy(n.client_id,n.team_id,n.kid,r,i),a=Ce(),c=await s.createAuthorizationURL(a,((d=n.scope)==null?void 0:d.split(" "))||["name","email"]);return(((u=n.scope)==null?void 0:u.split(" "))||["name","email"]).some(f=>["email","name"].includes(f))&&c.searchParams.set("response_mode","form_post"),{redirectUrl:c.href,code:a}}async function Nk(t,e,n){const{options:r,keyArray:i}=r1(e),a=await new Yy(r.client_id,r.team_id,r.kid,i,`${qe(t.env)}callback`).validateAuthorizationCode(n),c=Ua(a.idToken());if(!c)throw new Error("Invalid ID token");const l=Wo.parse(c.payload);return{sub:l.sub,email:l.email,given_name:l.given_name,family_name:l.family_name,name:l.name,picture:l.picture,locale:l.locale}}const i1=Object.freeze(Object.defineProperty({__proto__:null,displayName:Ak,getRedirect:Ck,logo:Ek,validateAuthorizationCodeAndGetUser:Nk},Symbol.toStringTag,{value:"Module"})),Ik="Facebook",jk=({className:t=""})=>p("svg",{width:"45",height:"45",viewBox:"0 0 45 45",xmlns:"http://www.w3.org/2000/svg",className:t,children:[p("path",{d:"M45 22.5C45 10.0736 34.9264 0 22.5 0C10.0736 0 0 10.0736 0 22.5C0 33.7031 8.23242 42.9785 19.0039 44.6953V28.9746H13.2861V22.5H19.0039V17.5391C19.0039 11.8945 22.3828 8.75977 27.5391 8.75977C29.9658 8.75977 32.5049 9.19922 32.5049 9.19922V14.7656H29.7012C26.9414 14.7656 26.0156 16.4824 26.0156 18.2432V22.5H32.2412L31.2012 28.9746H26.0156V44.6953C36.7871 42.9785 45 33.7031 45 22.5Z",fill:"#1877F2"}),p("path",{d:"M31.2012 28.9746L32.2412 22.5H26.0156V18.2432C26.0156 16.4824 26.9414 14.7656 29.7012 14.7656H32.5049V9.19922C32.5049 9.19922 29.9658 8.75977 27.5391 8.75977C22.3828 8.75977 19.0039 11.8945 19.0039 17.5391V22.5H13.2861V28.9746H19.0039V44.6953C20.1562 44.8984 21.3203 45 22.5 45C23.6797 45 24.8438 44.8984 26.0156 44.6953V28.9746H31.2012Z",fill:"white"})]});async function Ok(t,e){var c;const{options:n}=e;if(!(n!=null&&n.client_id)||!n.client_secret)throw new Error("Missing required authentication parameters");const r=`${qe(t.env)}callback`,i=new Qy(n.client_id,n.client_secret,r),s=Ce();return{redirectUrl:i.createAuthorizationURL(s,((c=n.scope)==null?void 0:c.split(" "))||["email"]).href,code:s}}async function Tk(t,e,n){const{options:r}=e;if(!(r!=null&&r.client_id)||!r.client_secret)throw new Error("Missing required authentication parameters");const s=await new Qy(r.client_id,r.client_secret,`${qe(t.env)}callback`).validateAuthorizationCode(n),a=await fetch("https://graph.facebook.com/v22.0/me?fields=id,email,name",{headers:{Authorization:`Bearer ${s.accessToken()}`}});if(!a.ok)throw new Error("Failed to fetch user info");const c=await a.json();return t.set("log",`Userinfo: ${JSON.stringify(c)}`),{sub:c.id,email:c.email,name:c.name}}const o1=Object.freeze(Object.defineProperty({__proto__:null,displayName:Ik,getRedirect:Ok,logo:jk,validateAuthorizationCodeAndGetUser:Tk},Symbol.toStringTag,{value:"Module"})),Pk="Google",Rk=({className:t=""})=>p("svg",{width:"45",height:"45",viewBox:"0 0 45 45",xmlns:"http://www.w3.org/2000/svg",className:t,children:[p("path",{d:"M44.1035 23.0123C44.1054 21.4791 43.9758 19.9486 43.716 18.4375H22.498V27.1028H34.6507C34.4021 28.4868 33.8757 29.8061 33.1034 30.9812C32.3311 32.1562 31.3289 33.1628 30.1571 33.9401V39.5649H37.41C41.6567 35.6494 44.1035 29.859 44.1035 23.0123Z",fill:"#4285F4"}),p("path",{d:"M22.4982 44.9997C28.5698 44.9997 33.6821 43.0061 37.4101 39.5687L30.1573 33.9439C28.1386 35.3126 25.5387 36.0938 22.4982 36.0938C16.6296 36.0938 11.6485 32.1377 9.86736 26.8066H2.39575V32.6033C4.26839 36.3297 7.13989 39.4622 10.6896 41.6512C14.2394 43.8402 18.3277 44.9995 22.4982 44.9997Z",fill:"#34A853"}),p("path",{d:"M9.86737 26.8073C8.92572 24.0138 8.92572 20.9886 9.86737 18.1951V12.3984H2.39576C0.820432 15.5332 0 18.9929 0 22.5012C0 26.0095 0.820432 29.4692 2.39576 32.604L9.86737 26.8073Z",fill:"#FBBC04"}),p("path",{d:"M22.4982 8.90741C25.7068 8.85499 28.8071 10.0673 31.1291 12.2823L37.5507 5.86064C33.4788 2.03602 28.0843 -0.0637686 22.4982 0.00147616C18.3277 0.00166623 14.2394 1.16098 10.6896 3.34999C7.13989 5.539 4.26839 8.67155 2.39575 12.3979L9.86736 18.1946C11.6485 12.8635 16.6296 8.90741 22.4982 8.90741Z",fill:"#EA4335"})]});async function Bk(t,e){var l;const{options:n}=e;if(!(n!=null&&n.client_id)||!n.client_secret)throw new Error("Missing required Google authentication parameters");const r=`${qe(t.env)}callback`,i=new t1(n.client_id,n.client_secret,r),s=Ce(),a=Zy();return{redirectUrl:i.createAuthorizationURL(s,a,((l=n.scope)==null?void 0:l.split(" "))??["email","profile"]).href,code:s,codeVerifier:a}}async function Lk(t,e,n,r){const{options:i}=e;if(!(i!=null&&i.client_id)||!i.client_secret||!r)throw new Error("Missing required authentication parameters");const a=await new t1(i.client_id,i.client_secret,`${qe(t.env)}callback`).validateAuthorizationCode(n,r),c=Ua(a.idToken());if(!c)throw new Error("Invalid ID token");const l=Wo.parse(c.payload);return{sub:l.sub,email:l.email,given_name:l.given_name,family_name:l.family_name,name:l.name,picture:l.picture,locale:l.locale}}const s1=Object.freeze(Object.defineProperty({__proto__:null,displayName:Pk,getRedirect:Bk,logo:Rk,validateAuthorizationCodeAndGetUser:Lk},Symbol.toStringTag,{value:"Module"})),Uk="Vipps",Dk=({className:t=""})=>p("svg",{version:"1.1",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 48 48",width:"45",height:"45",className:t,children:[p("path",{fill:"#FF5B24",d:"M3.5,8h41c1.9,0,3.5,1.6,3.5,3.5v25c0,1.9-1.6,3.5-3.5,3.5h-41C1.6,40,0,38.4,0,36.5v-25C0,9.6,1.6,8,3.5,8z"}),p("path",{fillRule:"evenodd",clipRule:"evenodd",fill:"#FFFFFF",d:`M27.9,20.3c1.4,0,2.6-1,2.6-2.5h0c0-1.5-1.2-2.5-2.6-2.5c-1.4,0-2.6,1-2.6,2.5C25.3,19.2,26.5,20.3,27.9,20.3z
|
|
192
|
+
`,r}async function m$(t){const e=await t.publicKey.export(),n=await crypto.subtle.exportKey("jwk",e),r=JSON.stringify(n,Object.keys(n).sort()),s=new TextEncoder().encode(r);return El(await _m(s))}const _$=1e3*60*60*24,y$=new o.OpenAPIHono().openapi(o.createRoute({tags:["keys"],method:"get",path:"/signing",request:{headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.array(Sl)}},description:"List of keys"}}}),async t=>{const{signingKeys:e}=await t.env.data.keys.list({q:"type:jwt_signing"}),n=e.filter(r=>"cert"in r).map(r=>r);return t.json(n)}).openapi(o.createRoute({tags:["keys"],method:"get",path:"/signing/{kid}",request:{headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({kid:o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Sl}},description:"The requested key"}}}),async t=>{const{kid:e}=t.req.valid("param"),{signingKeys:n}=await t.env.data.keys.list({q:"type:jwt_signing"}),r=n.find(i=>i.kid===e);if(!r)throw new b(404,{message:"Key not found"});return t.json(r)}).openapi(o.createRoute({tags:["keys"],method:"post",path:"/signing/rotate",request:{headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{description:"Status"}}}),async t=>{const{signingKeys:e}=await t.env.data.keys.list({q:"type:jwt_signing"});for await(const r of e)await t.env.data.keys.update(r.kid,{revoked_at:new Date(Date.now()+_$).toISOString()});const n=await Xd({name:`CN=${t.env.ORGANIZATION_NAME}`});return await t.env.data.keys.create({...n,type:"jwt_signing"}),t.text("OK",{status:201})}).openapi(o.createRoute({tags:["keys"],method:"put",path:"/signing/{kid}/revoke",request:{headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({kid:o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{description:"Status"}}}),async t=>{const{kid:e}=t.req.valid("param");if(!await t.env.data.keys.update(e,{revoked_at:new Date().toISOString()}))throw new b(404,{message:"Key not found"});const r=await Xd({name:`CN=${t.env.ORGANIZATION_NAME}`});return await t.env.data.keys.create({...r,type:"jwt_signing"}),t.text("OK")}),w$=new o.OpenAPIHono().openapi(o.createRoute({tags:["users"],method:"get",path:"/",request:{query:o.z.object({email:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"tenant/json":{schema:o.z.array(gu)}},description:"List of users"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{email:n}=t.req.valid("query"),i=(await Eu(t.env.data.users,e,n)).filter(s=>!s.linked_to);return t.json(i)}),v$=xt.extend({clients:o.z.array(or)}),b$=new o.OpenAPIHono().openapi(o.createRoute({tags:["clients"],method:"get",path:"/",request:{query:Ye,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([v$,o.z.array(or)])}},description:"List of clients"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{page:n,per_page:r,include_totals:i,sort:s,q:a}=t.req.valid("query"),l=(await t.env.data.clients.list(e,{page:n,per_page:r,include_totals:i,sort:pt(s),q:a})).clients;return i?t.json({clients:l,start:0,limit:10,length:l.length}):t.json(l)}).openapi(o.createRoute({tags:["clients"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:or}},description:"A client"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=await t.env.data.clients.get(e,n);if(!r)throw new b(404);return t.json(r)}).openapi(o.createRoute({tags:["clients"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param");if(!await t.env.data.clients.remove(e,n))throw new b(404,{message:"Client not found"});return t.text("OK")}).openapi(o.createRoute({tags:["clients"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Ts.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:or}},description:"The updated client"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),i=t.req.valid("json");await t.env.data.clients.update(e,n,i);const s=await t.env.data.clients.get(e,n);if(!s)throw new b(404,{message:"Client not found"});return t.json(s)}).openapi(o.createRoute({tags:["clients"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Ts.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:o.z.object(or.shape)}},description:"A client"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r={...n,client_secret:n.client_secret||Ce()},i=await t.env.data.clients.create(e,r);return t.json(i,{status:201})});o.z.object({start:o.z.number(),limit:o.z.number(),length:o.z.number()});Oa.extend({email:o.z.string(),login_count:o.z.number(),multifactor:o.z.array(o.z.string()).optional(),last_ip:o.z.string().optional(),last_login:o.z.string().optional(),user_id:o.z.string()}).catchall(o.z.any());const $$=xt.extend({tenants:o.z.array(Ln)}),k$=new o.OpenAPIHono().openapi(o.createRoute({tags:["tenants","settings"],method:"get",path:"/settings",request:{headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Ln}},description:"Current tenant settings"}}}),async t=>{const e=await t.env.data.tenants.get(t.var.tenant_id);if(!e)throw new b(404,{message:"Tenant not found"});return t.json(e)}).openapi(o.createRoute({tags:["tenants","settings"],method:"patch",path:"/settings",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object(Ki.shape).partial()}}}},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Ln}},description:"Updated tenant settings"}}}),async t=>{const e=t.req.valid("json"),{id:n,...r}=e,i=await t.env.data.tenants.get(t.var.tenant_id);if(!i)throw new b(404,{message:"Tenant not found"});const s=zl(i,r);await t.env.data.tenants.update(t.var.tenant_id,s);const a=await t.env.data.tenants.get(t.var.tenant_id);if(!a)throw new b(500,{message:"Failed to retrieve updated tenant"});return t.json(a)}).openapi(o.createRoute({tags:["tenants"],method:"get",path:"/",request:{query:Ye},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"tenant/json":{schema:o.z.union([o.z.array(Ln),$$])}},description:"List of tenants"}}}),async t=>{const{page:e,per_page:n,include_totals:r,sort:i,q:s}=t.req.valid("query"),a=await t.env.data.tenants.list({page:e,per_page:n,include_totals:r,sort:pt(i),q:s});return r?t.json(a):t.json(a.tenants)}).openapi(o.createRoute({tags:["tenants"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"tenant/json":{schema:Ln}},description:"A tenant"}}}),async t=>{const{id:e}=t.req.valid("param"),n=await t.env.data.tenants.get(e);if(!n)throw new b(404);return t.json(n)}).openapi(o.createRoute({tags:["tenants"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{id:e}=t.req.valid("param");return await t.env.data.tenants.remove(e),t.text("OK")}).openapi(o.createRoute({tags:["tenants"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Ki.shape).partial()}}},params:o.z.object({id:o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{id:e}=t.req.valid("param"),n=t.req.valid("json");return await t.env.data.tenants.update(e,n),t.text("OK")}).openapi(o.createRoute({tags:["tenants"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Ki.shape)}}}},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"tenant/json":{schema:Ln}},description:"An tenant"}}}),async t=>{const e=t.req.valid("json"),n=await t.env.data.tenants.create(e);return t.json(n,{status:201})}),x$=xt.extend({logs:o.z.array(Ls)}),S$=new o.OpenAPIHono().openapi(o.createRoute({tags:["logs"],method:"get",path:"/",request:{query:Ye,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(Ls),x$])}},description:"List of log rows"}}}),async t=>{const{page:e,per_page:n,include_totals:r,sort:i,q:s}=t.req.valid("query"),a=await t.env.data.logs.list(t.var.tenant_id,{page:e,per_page:n,include_totals:r,sort:pt(i),q:s});return r?t.json(a):t.json(a.logs)}).openapi(o.createRoute({tags:["logs"],method:"get",path:"/{id}",request:{headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({id:o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Ls}},description:"A log entry"}}}),async t=>{const{id:e}=t.req.valid("param"),n=await t.env.data.logs.get(t.var.tenant_id,e);if(!n)throw new b(404);return t.json(n)}),z$=17,A$={organization:"org_",connection:"con_",action:"act_",hook:"h_",rule:"rul_",resource_server:"api_",guardian_factor:"gfa_",invite:"inv_"};function Tc(t){const r=mm("0123456789abcdefghijklmnopqrstuvwxyz",z$)();return`${A$[t]}${r}`}function E$(){return Tc("organization")}function C$(){return Tc("connection")}function N$(){return Tc("hook")}function I$(){return Tc("invite")}const j$=xt.extend({hooks:o.z.array(Vr)}),O$=new o.OpenAPIHono().openapi(o.createRoute({tags:["hooks"],method:"get",path:"/",request:{query:Ye,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(Vr),j$])}},description:"List of hooks"}}}),async t=>{const{page:e,per_page:n,include_totals:r,sort:i,q:s}=t.req.valid("query"),a=await t.env.data.hooks.list(t.var.tenant_id,{page:e,per_page:n,include_totals:r,sort:pt(i),q:s});return r?t.json(a):t.json(a.hooks)}).openapi(o.createRoute({tags:["hooks"],method:"post",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:ds}}}},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Vr}},description:"The created hook"}}}),async t=>{const e=t.req.valid("json"),n={...e,hook_id:e.hook_id||N$()},r=await t.env.data.hooks.create(t.var.tenant_id,n);return t.json(r,{status:201})}).openapi(o.createRoute({tags:["hooks"],method:"patch",path:"/{hook_id}",request:{headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({hook_id:o.z.string()}),body:{content:{"application/json":{schema:o.z.union([ds.options[0].omit({hook_id:!0}).partial(),ds.options[1].omit({hook_id:!0}).partial()])}}}},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Vr}},description:"The updated hook"},404:{description:"Hook not found"}}}),async t=>{const{hook_id:e}=t.req.valid("param"),n=t.req.valid("json");await t.env.data.hooks.update(t.var.tenant_id,e,n);const r=await t.env.data.hooks.get(t.var.tenant_id,e);if(!r)throw new b(404,{message:"Hook not found"});return t.json(r)}).openapi(o.createRoute({tags:["hooks"],method:"get",path:"/{hook_id}",request:{headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({hook_id:o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Vr}},description:"A hook"},404:{description:"Hook not found"}}}),async t=>{const{hook_id:e}=t.req.valid("param"),n=await t.env.data.hooks.get(t.var.tenant_id,e);if(!n)throw new b(404,{message:"Hook not found"});return t.json(n)}).openapi(o.createRoute({tags:["hooks"],method:"delete",path:"/{hook_id}",request:{headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({hook_id:o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{description:"A hook"}}}),async t=>{const{hook_id:e}=t.req.valid("param");if(!await t.env.data.hooks.remove(t.var.tenant_id,e))throw new b(404,{message:"Hook not found"});return t.text("OK")}),T$=xt.extend({connections:o.z.array(Vt)}),P$=new o.OpenAPIHono().openapi(o.createRoute({tags:["connections"],method:"get",path:"/",request:{query:Ye,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(Vt),T$])}},description:"List of connectionss"}}}),async t=>{const{page:e,per_page:n,include_totals:r=!1,sort:i,q:s}=t.req.valid("query"),a=await t.env.data.connections.list(t.var.tenant_id,{page:e,per_page:n,include_totals:r,sort:pt(i),q:s});return r?t.json(a):t.json(a.connections)}).openapi(o.createRoute({tags:["connections"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Vt}},description:"A connection"}}}),async t=>{const{id:e}=t.req.valid("param"),n=await t.env.data.connections.get(t.var.tenant_id,e);if(!n)throw new b(404);return t.json(n)}).openapi(o.createRoute({tags:["connections"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{id:e}=t.req.valid("param");if(!await t.env.data.connections.remove(t.var.tenant_id,e))throw new b(404,{message:"Connection not found"});return t.text("OK")}).openapi(o.createRoute({tags:["connections"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Rs.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Vt}},description:"The updated connection"}}}),async t=>{const{id:e}=t.req.valid("param"),n=t.req.valid("json");if(!await t.env.data.connections.update(t.var.tenant_id,e,n))throw new b(404,{message:"Connection not found"});const i=await t.env.data.connections.get(t.var.tenant_id,e);if(!i)throw new b(404,{message:"Connection not found"});return t.json(i)}).openapi(o.createRoute({tags:["connections"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Rs.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Vt}},description:"A connection"}}}),async t=>{const e=t.req.valid("json"),n={...e,id:e.id||C$()},r=await t.env.data.connections.create(t.var.tenant_id,n);return t.json(r,{status:201})}),R$=new o.OpenAPIHono().openapi(o.createRoute({tags:["prompts"],method:"get",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:ps}},description:"Branding settings"}}}),async t=>{const e=await t.env.data.promptSettings.get(t.var.tenant_id);return e?t.json(e):t.json(ps.parse({}))}).openapi(o.createRoute({tags:["prompts"],method:"patch",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object(ps.shape).partial()}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Prompts settings"}}}),async t=>{const e=t.req.valid("json"),n=await t.env.data.promptSettings.get(t.var.tenant_id);return Object.assign(n,e),await t.env.data.promptSettings.set(t.var.tenant_id,n),t.json(n)});let Wh=!1;function yp(t){t.use(async(e,n)=>(Wh||(t.openAPIRegistry.registerComponent("securitySchemes","Bearer",{type:"oauth2",scheme:"bearer",flows:{implicit:{authorizationUrl:`${e.env.AUTH_URL}/authorize`,scopes:{openid:"Basic user information",email:"User email",profile:"User profile information"}}}}),Wh=!0),await n()))}var B$=(t,e)=>{try{return e(t)}catch{return t.replace(/(?:%[0-9A-Fa-f]{2})+/g,n=>{try{return e(n)}catch{return n}})}},L$=decodeURIComponent,U$=/^[\w!#$%&'*.^`|~+-]+$/,D$=/^[ !#-:<-[\]-~]*$/,M$=(t,e)=>{if(t.indexOf(e)===-1)return{};const n=t.trim().split(";"),r={};for(let i of n){i=i.trim();const s=i.indexOf("=");if(s===-1)continue;const a=i.substring(0,s).trim();if(e!==a||!U$.test(a))continue;let c=i.substring(s+1).trim();if(c.startsWith('"')&&c.endsWith('"')&&(c=c.slice(1,-1)),D$.test(c)){r[a]=c.indexOf("%")!==-1?B$(c,L$):c;break}}return r},F$=(t,e,n={})=>{let r=`${t}=${e}`;if(t.startsWith("__Secure-")&&!n.secure)throw new Error("__Secure- Cookie must have Secure attributes");if(t.startsWith("__Host-")){if(!n.secure)throw new Error("__Host- Cookie must have Secure attributes");if(n.path!=="/")throw new Error('__Host- Cookie must have Path attributes with "/"');if(n.domain)throw new Error("__Host- Cookie must not have Domain attributes")}if(n&&typeof n.maxAge=="number"&&n.maxAge>=0){if(n.maxAge>3456e4)throw new Error("Cookies Max-Age SHOULD NOT be greater than 400 days (34560000 seconds) in duration.");r+=`; Max-Age=${n.maxAge|0}`}if(n.domain&&n.prefix!=="host"&&(r+=`; Domain=${n.domain}`),n.path&&(r+=`; Path=${n.path}`),n.expires){if(n.expires.getTime()-Date.now()>3456e7)throw new Error("Cookies Expires SHOULD NOT be greater than 400 days (34560000 seconds) in the future.");r+=`; Expires=${n.expires.toUTCString()}`}if(n.httpOnly&&(r+="; HttpOnly"),n.secure&&(r+="; Secure"),n.sameSite&&(r+=`; SameSite=${n.sameSite.charAt(0).toUpperCase()+n.sameSite.slice(1)}`),n.priority&&(r+=`; Priority=${n.priority.charAt(0).toUpperCase()+n.priority.slice(1)}`),n.partitioned){if(!n.secure)throw new Error("Partitioned Cookie must have Secure attributes");r+="; Partitioned"}return r},al=(t,e,n)=>(e=encodeURIComponent(e),F$(t,e,n)),q$=(t,e,n)=>{const r=t.req.raw.headers.get("Cookie");{if(!r)return;let i=e;return M$(r,i)[i]}},H$=(t,e,n)=>{let r;return(n==null?void 0:n.prefix)==="secure"?r=al("__Secure-"+t,e,{path:"/",...n,secure:!0}):(n==null?void 0:n.prefix)==="host"?r=al("__Host-"+t,e,{...n,path:"/",secure:!0,domain:void 0}):r=al(t,e,{path:"/",...n}),r},Jh=(t,e,n,r)=>{const i=H$(e,n,r);t.header("Set-Cookie",i,{append:!0})},Ay=t=>Cy(t.replace(/_|-/g,e=>({_:"/","-":"+"})[e]??e)),Ey=t=>V$(t).replace(/\/|\+/g,e=>({"/":"_","+":"-"})[e]??e),V$=t=>{let e="";const n=new Uint8Array(t);for(let r=0,i=n.length;r<i;r++)e+=String.fromCharCode(n[r]);return btoa(e)},Cy=t=>{const e=atob(t),n=new Uint8Array(new ArrayBuffer(e.length)),r=e.length/2;for(let i=0,s=e.length-1;i<=r;i++,s--)n[i]=e.charCodeAt(i),n[s]=e.charCodeAt(s);return n},Ny=(t=>(t.HS256="HS256",t.HS384="HS384",t.HS512="HS512",t.RS256="RS256",t.RS384="RS384",t.RS512="RS512",t.PS256="PS256",t.PS384="PS384",t.PS512="PS512",t.ES256="ES256",t.ES384="ES384",t.ES512="ES512",t.EdDSA="EdDSA",t))(Ny||{}),K$=class extends Error{constructor(t){super(`${t} is not an implemented algorithm`),this.name="JwtAlgorithmNotImplemented"}},Pc=class extends Error{constructor(t){super(`invalid JWT token: ${t}`),this.name="JwtTokenInvalid"}},G$=class extends Error{constructor(t){super(`token (${t}) is being used before it's valid`),this.name="JwtTokenNotBefore"}},W$=class extends Error{constructor(t){super(`token (${t}) expired`),this.name="JwtTokenExpired"}},J$=class extends Error{constructor(t,e){super(`Invalid "iat" claim, must be a valid number lower than "${t}" (iat: "${e}")`),this.name="JwtTokenIssuedAt"}},cl=class extends Error{constructor(t,e){super(`expected issuer "${t}", got ${e?`"${e}"`:"none"} `),this.name="JwtTokenIssuer"}},Iy=class extends Error{constructor(t){super(`jwt header is invalid: ${JSON.stringify(t)}`),this.name="JwtHeaderInvalid"}},X$=class extends Error{constructor(t){super(`required "kid" in jwt header: ${JSON.stringify(t)}`),this.name="JwtHeaderRequiresKid"}},Z$=class extends Error{constructor(t){super(`token(${t}) signature mismatched`),this.name="JwtTokenSignatureMismatched"}},_o=(t=>(t.Encrypt="encrypt",t.Decrypt="decrypt",t.Sign="sign",t.Verify="verify",t.DeriveKey="deriveKey",t.DeriveBits="deriveBits",t.WrapKey="wrapKey",t.UnwrapKey="unwrapKey",t))(_o||{}),qo=new TextEncoder,Y$=new TextDecoder;async function Q$(t,e,n){const r=jy(e),i=await t4(t,r);return await crypto.subtle.sign(r,i,n)}async function e4(t,e,n,r){const i=jy(e),s=await n4(t,i);return await crypto.subtle.verify(i,s,n,r)}function Zd(t){return Cy(t.replace(/-+(BEGIN|END).*/g,"").replace(/\s/g,""))}async function t4(t,e){if(!crypto.subtle||!crypto.subtle.importKey)throw new Error("`crypto.subtle.importKey` is undefined. JWT auth middleware requires it.");if(Oy(t)){if(t.type!=="private"&&t.type!=="secret")throw new Error(`unexpected key type: CryptoKey.type is ${t.type}, expected private or secret`);return t}const n=[_o.Sign];return typeof t=="object"?await crypto.subtle.importKey("jwk",t,e,!1,n):t.includes("PRIVATE")?await crypto.subtle.importKey("pkcs8",Zd(t),e,!1,n):await crypto.subtle.importKey("raw",qo.encode(t),e,!1,n)}async function n4(t,e){if(!crypto.subtle||!crypto.subtle.importKey)throw new Error("`crypto.subtle.importKey` is undefined. JWT auth middleware requires it.");if(Oy(t)){if(t.type==="public"||t.type==="secret")return t;t=await Xh(t)}if(typeof t=="string"&&t.includes("PRIVATE")){const r=await crypto.subtle.importKey("pkcs8",Zd(t),e,!0,[_o.Sign]);t=await Xh(r)}const n=[_o.Verify];return typeof t=="object"?await crypto.subtle.importKey("jwk",t,e,!1,n):t.includes("PUBLIC")?await crypto.subtle.importKey("spki",Zd(t),e,!1,n):await crypto.subtle.importKey("raw",qo.encode(t),e,!1,n)}async function Xh(t){if(t.type!=="private")throw new Error(`unexpected key type: ${t.type}`);if(!t.extractable)throw new Error("unexpected private key is unextractable");const e=await crypto.subtle.exportKey("jwk",t),{kty:n}=e,{alg:r,e:i,n:s}=e,{crv:a,x:c,y:l}=e;return{kty:n,alg:r,e:i,n:s,crv:a,x:c,y:l,key_ops:[_o.Verify]}}function jy(t){switch(t){case"HS256":return{name:"HMAC",hash:{name:"SHA-256"}};case"HS384":return{name:"HMAC",hash:{name:"SHA-384"}};case"HS512":return{name:"HMAC",hash:{name:"SHA-512"}};case"RS256":return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case"RS384":return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case"RS512":return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case"PS256":return{name:"RSA-PSS",hash:{name:"SHA-256"},saltLength:32};case"PS384":return{name:"RSA-PSS",hash:{name:"SHA-384"},saltLength:48};case"PS512":return{name:"RSA-PSS",hash:{name:"SHA-512"},saltLength:64};case"ES256":return{name:"ECDSA",hash:{name:"SHA-256"},namedCurve:"P-256"};case"ES384":return{name:"ECDSA",hash:{name:"SHA-384"},namedCurve:"P-384"};case"ES512":return{name:"ECDSA",hash:{name:"SHA-512"},namedCurve:"P-521"};case"EdDSA":return{name:"Ed25519",namedCurve:"Ed25519"};default:throw new K$(t)}}function Oy(t){return Rm()==="node"&&crypto.webcrypto?t instanceof crypto.webcrypto.CryptoKey:t instanceof CryptoKey}var ll=t=>Ey(qo.encode(JSON.stringify(t)).buffer).replace(/=/g,""),r4=t=>Ey(t).replace(/=/g,""),Yd=t=>JSON.parse(Y$.decode(Ay(t)));function Ty(t){if(typeof t=="object"&&t!==null){const e=t;return"alg"in e&&Object.values(Ny).includes(e.alg)&&(!("typ"in e)||e.typ==="JWT")}return!1}var i4=async(t,e,n="HS256")=>{const r=ll(t);let i;typeof e=="object"&&"alg"in e?(n=e.alg,i=ll({alg:n,typ:"JWT",kid:e.kid})):i=ll({alg:n,typ:"JWT"});const s=`${i}.${r}`,a=await Q$(e,n,qo.encode(s)),c=r4(a);return`${s}.${c}`},Py=async(t,e,n)=>{const r=typeof n=="string"?{alg:n}:n||{},i={alg:r.alg??"HS256",iss:r.iss,nbf:r.nbf??!0,exp:r.exp??!0,iat:r.iat??!0},s=t.split(".");if(s.length!==3)throw new Pc(t);const{header:a,payload:c}=Ry(t);if(!Ty(a))throw new Iy(a);const l=Date.now()/1e3|0;if(i.nbf&&c.nbf&&c.nbf>l)throw new G$(t);if(i.exp&&c.exp&&c.exp<=l)throw new W$(t);if(i.iat&&c.iat&&l<c.iat)throw new J$(l,c.iat);if(i.iss){if(!c.iss)throw new cl(i.iss,null);if(typeof i.iss=="string"&&c.iss!==i.iss)throw new cl(i.iss,c.iss);if(i.iss instanceof RegExp&&!i.iss.test(c.iss))throw new cl(i.iss,c.iss)}const d=t.substring(0,t.lastIndexOf("."));if(!await e4(e,i.alg,Ay(s[2]),qo.encode(d)))throw new Z$(t);return c},o4=async(t,e,n)=>{const r=e.verification||{},i=s4(t);if(!Ty(i))throw new Iy(i);if(!i.kid)throw new X$(i);if(e.jwks_uri){const a=await fetch(e.jwks_uri,n);if(!a.ok)throw new Error(`failed to fetch JWKS from ${e.jwks_uri}`);const c=await a.json();if(!c.keys)throw new Error('invalid JWKS response. "keys" field is missing');if(!Array.isArray(c.keys))throw new Error('invalid JWKS response. "keys" field is not an array');e.keys?e.keys.push(...c.keys):e.keys=c.keys}else if(!e.keys)throw new Error('verifyWithJwks requires options for either "keys" or "jwks_uri" or both');const s=e.keys.find(a=>a.kid===i.kid);if(!s)throw new Pc(t);return await Py(t,s,{alg:s.alg||i.alg,...r})},Ry=t=>{try{const[e,n]=t.split("."),r=Yd(e),i=Yd(n);return{header:r,payload:i}}catch{throw new Pc(t)}},s4=t=>{try{const[e]=t.split(".");return Yd(e)}catch{throw new Pc(t)}},By={sign:i4,verify:Py,decode:Ry,verifyWithJwks:o4},a4={Stringify:1,BeforeStream:2,Stream:3},Xt=(t,e)=>{const n=new String(t);return n.isEscaped=!0,n.callbacks=e,n},c4=/[&<>'"]/,Ly=async(t,e)=>{let n="";e||(e=[]);const r=await Promise.all(t);for(let i=r.length-1;n+=r[i],i--,!(i<0);i--){let s=r[i];typeof s=="object"&&e.push(...s.callbacks||[]);const a=s.isEscaped;if(s=await(typeof s=="object"?s.toString():s),typeof s=="object"&&e.push(...s.callbacks||[]),s.isEscaped??a)n+=s;else{const c=[n];Vn(s,c),n=c[0]}}return Xt(n,e)},Vn=(t,e)=>{const n=t.search(c4);if(n===-1){e[0]+=t;return}let r,i,s=0;for(i=n;i<t.length;i++){switch(t.charCodeAt(i)){case 34:r=""";break;case 39:r="'";break;case 38:r="&";break;case 60:r="<";break;case 62:r=">";break;default:continue}e[0]+=t.substring(s,i)+r,s=i+1}e[0]+=t.substring(s,i)},Uy=t=>{const e=t.callbacks;if(!(e!=null&&e.length))return t;const n=[t],r={};return e.forEach(i=>i({phase:a4.Stringify,buffer:n,context:r})),n[0]},l4=By.verify,d4=By.decode;async function Qd(t){const{signingKeys:e}=await t.keys.list({q:"type:jwt_signing"});return await Promise.all(e.map(async r=>{const s=await new Oc(r.cert).publicKey.export(),a=await crypto.subtle.exportKey("jwk",s);return vu.parse({...a,kid:r.kid})}))}o.z.object({alg:o.z.literal("RS256"),kty:o.z.literal("RSA"),use:o.z.literal("sig"),n:o.z.string(),e:o.z.string(),kid:o.z.string(),x5t:o.z.string(),x5c:o.z.array(o.z.string())});async function u4(t){if(t.JWKS_URL&&t.JWKS_SERVICE){const e=await t.JWKS_SERVICE.fetch(t.JWKS_URL);return e.ok?(await e.json()).keys:(console.warn(`JWKS fetch failed with status ${e.status}, falling back to database`),await Qd(t.data))}return await Qd(t.data)}async function p4(t,e){try{const{header:n}=d4(e),i=(await u4(t.env)).find(c=>c.kid===n.kid);if(!i)throw new b(401,{message:"No matching kid found"});const s=await crypto.subtle.importKey("jwk",i,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},!1,["verify"]);return await l4(e,s,"RS256")}catch(n){throw n instanceof b?n:new b(403,{message:"Invalid JWT signature"})}}function f4(t){return t.replace(/:([a-zA-Z_][a-zA-Z0-9_]*)/g,"{$1}")}function h4(t,e){return e.startsWith(t)?e:t+e}function wp(t){return async(e,n)=>{var c,l,d;const r=e.req.matchedRoutes.find(u=>u.method.toUpperCase()===e.req.method&&u.path!=="/*");if(!r)return await n();const i=f4(r.path),s="basePath"in r&&typeof r.basePath=="string"?r.basePath:"",a=t.openAPIRegistry.definitions.find(u=>"route"in u&&h4(s,u.route.path)===i&&u.route.method.toUpperCase()===e.req.method.toUpperCase());if(a&&"route"in a){const u=(l=(c=a.route.security)==null?void 0:c[0])==null?void 0:l.Bearer;if(!(u!=null&&u.length))return await n();const f=e.req.header("authorization")||"",[h,m]=f.split(" ");if((h==null?void 0:h.toLowerCase())!=="bearer"||!m)throw new b(401,{message:"Missing bearer token"});try{const y=await p4(e,m);e.set("user_id",y.sub),e.set("user",y),!e.var.tenant_id&&y.tenant_id&&e.set("tenant_id",y.tenant_id);const v=y.permissions||[],$=((d=y.scope)==null?void 0:d.split(" "))||[];if(u.length&&!(u.some(A=>v.includes(A))||u.some(A=>$.includes(A))))throw new b(403,{message:"Unauthorized"})}catch(y){throw y instanceof b?y:new b(403,{message:"Invalid token"})}}return await n()}}const g4=new o.OpenAPIHono().openapi(o.createRoute({tags:["emails"],method:"get",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:fs}},description:"Email provider"}}}),async t=>{const e=await t.env.data.emailProviders.get(t.var.tenant_id);if(!e)throw new b(404,{message:"Email provider not found"});return t.json(e)}).openapi(o.createRoute({tags:["emails"],method:"post",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object(fs.shape)}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Branding settings"}}}),async t=>{const e=t.req.valid("json");return await t.env.data.emailProviders.create(t.var.tenant_id,e),t.text("OK",{status:201})}).openapi(o.createRoute({tags:["emails"],method:"patch",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object(fs.shape).partial()}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Branding settings"}}}),async t=>{const e=t.req.valid("json");return await t.env.data.emailProviders.update(t.var.tenant_id,e),t.text("OK")}),m4=new o.OpenAPIHono().openapi(o.createRoute({tags:["sessions"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Ba}},description:"A session"}}}),async t=>{const{id:e}=t.req.valid("param"),n=await t.env.data.sessions.get(t.var.tenant_id,e);if(!n)throw new b(404);return t.json(n)}).openapi(o.createRoute({tags:["sessions"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{id:e}=t.req.valid("param");if(!await t.env.data.sessions.remove(t.var.tenant_id,e))throw new b(404,{message:"Session not found"});return t.text("OK")}).openapi(o.createRoute({tags:["sessions"],method:"post",path:"/{id}/revoke",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{202:{description:"Sesssion deletion status"}}}),async t=>{const{id:e}=t.req.valid("param");if(!await t.env.data.sessions.update(t.var.tenant_id,e,{revoked_at:new Date().toDateString()}))throw new b(404,{message:"Session not found"});return t.text("Session deletion request accepted.",{status:202})}),_4=new o.OpenAPIHono().openapi(o.createRoute({tags:["refresh_tokens"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:$u}},description:"A session"}}}),async t=>{const{id:e}=t.req.valid("param"),n=await t.env.data.refreshTokens.get(t.var.tenant_id,e);if(!n)throw new b(404);return t.json(n)}).openapi(o.createRoute({tags:["refresh_tokens"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{id:e}=t.req.valid("param");if(!await t.env.data.refreshTokens.remove(t.var.tenant_id,e))throw new b(404,{message:"Session not found"});return t.text("OK")}),y4=new o.OpenAPIHono().openapi(o.createRoute({tags:["custom-domains"],method:"get",path:"/",request:{query:Ye,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.array(Bn)}},description:"List of custom domains"}}}),async t=>{const e=await t.env.data.customDomains.list(t.var.tenant_id);return t.json(e)}).openapi(o.createRoute({tags:["custom-domains"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Bn}},description:"A customDomain"}}}),async t=>{const{id:e}=t.req.valid("param"),n=await t.env.data.customDomains.get(t.var.tenant_id,e);if(!n)throw new b(404);return t.json(n)}).openapi(o.createRoute({tags:["custom-domains"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{id:e}=t.req.valid("param");if(!await t.env.data.customDomains.remove(t.var.tenant_id,e))throw new b(404,{message:"Custom domain not found"});return t.text("OK")}).openapi(o.createRoute({tags:["custom-domains"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Bn.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Bn}},description:"The updated custom domain"}}}),async t=>{const{id:e}=t.req.valid("param"),n=t.req.valid("json");if(!await t.env.data.customDomains.update(t.var.tenant_id,e,n))throw new b(404);const i=await t.env.data.customDomains.get(t.var.tenant_id,e);if(!i)throw new b(404);return t.json(i)}).openapi(o.createRoute({tags:["custom-domains"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(yu.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Bn}},description:"The created custom domain"}}}),async t=>{const e=t.req.valid("json"),n=await t.env.data.customDomains.create(t.var.tenant_id,e);return t.json(n,{status:201})}).openapi(o.createRoute({tags:["custom-domains"],method:"post",path:"/{id}/verify",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Bn}},description:"The custom domain"}}}),async()=>{throw new b(501,{message:"Not implemented"})});function Rc(t,e){const n={};for(const[r,i]of Object.entries(e)){const s={};for(const[a,c]of Object.entries(i))typeof c=="function"?s[a]=async(...l)=>{const d=performance.now();try{const u=await c(...l),h=performance.now()-d,m=t.res.headers.get("Server-Timing")||"",y=m?`${m}, ${r}-${a};dur=${h.toFixed(2)}`:`${r}-${a};dur=${h.toFixed(2)}`;return t.res.headers.set("Server-Timing",y),u}catch(u){const h=performance.now()-d,m=t.res.headers.get("Server-Timing")||"",y=m?`${m}, ${r}-${a}-error;dur=${h.toFixed(2)}`:`${r}-${a}-error;dur=${h.toFixed(2)}`;throw t.res.headers.set("Server-Timing",y),u}}:s[a]=c;n[r]=s}return n}function Bc(t){return t.ISSUER}function ot(t){return t.UNIVERSAL_LOGIN_URL||`${t.ISSUER}u/`}function qe(t){return t.OAUTH_API_URL||t.ISSUER}async function Lc(t,e){const n=t.req.header("x-forwarded-host");if(n){const i=await t.env.data.customDomains.getByDomain(n);if(i)return t.set("tenant_id",i.tenant_id),t.set("custom_domain",n),t.set("host",n),await e()}const r=t.req.header("host");if(r){t.set("host",r);const i=r.split(".");if(i.length>1&&typeof i[0]=="string"){const s=i[0];await t.env.data.tenants.get(s)&&t.set("tenant_id",s)}}else t.set("host",new URL(Bc(t.env)).host);if(!t.var.tenant_id){const i=t.req.header("tenant-id");i&&t.set("tenant_id",i)}return await e()}const w4=o.z.object({name:o.z.string(),version:o.z.string(),env:o.z.object({node:o.z.string().optional()}).optional()});function v4(t){if(t)try{let e=t;try{e=atob(t)}catch{}try{const n=JSON.parse(e);return w4.parse(n)}catch{}}catch{return}}const Uc=async(t,e)=>{var l,d,u,f;const n=(l=t.req.query("auth0Client"))==null?void 0:l.slice(0,255),i=(d=(()=>{var h;if(t.req.header("x-forwarded-host")&&t.req.header("x-forwarded-for")){const m=t.req.header("x-forwarded-for");return(h=m==null?void 0:m.split(",")[0])==null?void 0:h.trim()}return t.req.header("cf-connecting-ip")||t.req.header("x-real-ip")})())==null?void 0:d.slice(0,45),s=(u=t.req.header("user-agent"))==null?void 0:u.slice(0,512),a=(f=t.req.header("cf-ipcountry"))==null?void 0:f.slice(0,2),c=n?v4(n):void 0;c&&t.set("auth0_client",c),i&&t.set("ip",i),s&&t.set("useragent",s),a&&t.set("countryCode",a),await e()};function b4(t,e,n,r){try{const i=`${t}:${e}:${JSON.stringify(n)}`;return r?`${r}:${i}`:i}catch{const s=`${t}:${e}:${Date.now()}-${Math.random()}`;return r?`${r}:${s}`:s}}function Dc(t,e){const{cache:n,defaultTtl:r,customTtls:i={},excludeMethods:s=[],cacheEntities:a=[],keyPrefix:c}=e,l=new Set(s),d=a.length===0,u=new Set(a),f={};for(const[h,m]of Object.entries(t)){const y=d||u.has(h),v={};for(const[$,A]of Object.entries(m))if(typeof A=="function"){if(!y){v[$]=A;continue}const O=`${h}:${$}`;if(l.has(O)){v[$]=A;continue}const U=i[O]??r,T=["create","update","remove","delete","set","used"].includes($);v[$]=async(...R)=>{if(T)return await A.apply(m,R);const W=b4(h,$,R,c),te=await n.get(W);if(te!==null)if(te&&typeof te=="object"&&"isCachedNull"in te){const K=te;return K.isCachedNull?null:K.value}else return te;const Q=await A.apply(m,R);if(U>=0)if(Q!==null)await n.set(W,Q,U);else{const K={value:null,isCachedNull:!0};await n.set(W,K,U)}return Q}}else v[$]=A;f[h]=v}return f}class $4{constructor(e={}){se(this,"cache",new Map);se(this,"accessOrder",new Map);se(this,"accessCounter",0);se(this,"cleanupTimer");this.config=e;const n=e.cleanupIntervalMs;n&&n>0&&(this.cleanupTimer=setInterval(()=>{this.cleanupExpired()},n))}async get(e){const n=this.cache.get(e);return n?n.expiresAt&&n.expiresAt<new Date?(this.cache.delete(e),this.accessOrder.delete(e),null):(this.accessOrder.set(e,++this.accessCounter),n.value):null}async set(e,n,r){let i;const s=r??this.config.defaultTtlSeconds,a=s!==void 0,c=a?Math.max(0,s):0;a&&(i=new Date(Date.now()+(c>0?c*1e3:-1))),this.config.maxEntries&&this.cache.size>=this.config.maxEntries&&!this.cache.has(e)&&this.evictLeastRecentlyUsed();const l={value:n,expiresAt:i};this.cache.set(e,l),this.accessOrder.set(e,++this.accessCounter)}async delete(e){const n=this.cache.has(e);return this.cache.delete(e),this.accessOrder.delete(e),n}async clear(){this.cache.clear(),this.accessOrder.clear(),this.accessCounter=0}getStats(){return{size:this.cache.size,maxEntries:this.config.maxEntries,defaultTtlSeconds:this.config.defaultTtlSeconds}}cleanupExpired(){const e=new Date,n=[];for(const[r,i]of this.cache.entries())i.expiresAt&&i.expiresAt<e&&n.push(r);for(const r of n)this.cache.delete(r),this.accessOrder.delete(r)}evictLeastRecentlyUsed(){let e=null,n=1/0;for(const[r,i]of this.accessOrder.entries())i<n&&(n=i,e=r);e&&(this.cache.delete(e),this.accessOrder.delete(e))}destroy(){this.cleanupTimer&&(clearInterval(this.cleanupTimer),this.cleanupTimer=void 0)}}function Ho(t={}){return new $4(t)}const k4=xt.extend({forms:o.z.array(Hr)}),x4=new o.OpenAPIHono().openapi(o.createRoute({tags:["forms"],method:"get",path:"/",request:{query:Ye,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(Hr),k4])}},description:"List of forms"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{page:n,per_page:r,include_totals:i=!1,sort:s,q:a}=t.req.valid("query"),c=await t.env.data.forms.list(e,{page:n,per_page:r,include_totals:i,sort:pt(s),q:a});return i?t.json(c):t.json(c.forms)}).openapi(o.createRoute({tags:["forms"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Hr}},description:"A form"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=await t.env.data.forms.get(e,n);if(!r)throw new b(404);return t.json(r)}).openapi(o.createRoute({tags:["forms"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param");if(!await t.env.data.forms.remove(e,n))throw new b(404,{message:"Form not found"});return t.text("OK")}).openapi(o.createRoute({tags:["forms"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Bs.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Hr}},description:"The updated form"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=t.req.valid("json");if(!await t.env.data.forms.update(e,n,r))throw new b(404,{message:"Form not found"});const s=await t.env.data.forms.get(e,n);if(!s)throw new b(404,{message:"Form not found"});return t.json(s)}).openapi(o.createRoute({tags:["forms"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Bs.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Hr}},description:"A form"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r=await t.env.data.forms.create(e,n);return t.json(r,{status:201})}),S4=xt.extend({roles:o.z.array(cr)}),z4=new o.OpenAPIHono().openapi(o.createRoute({tags:["roles"],method:"get",path:"/",request:{query:Ye,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(cr),S4])}},description:"List of roles"}}}),async t=>{const{page:e,per_page:n,include_totals:r,sort:i,q:s}=t.req.valid("query"),a=await t.env.data.roles.list(t.var.tenant_id,{page:e,per_page:n,include_totals:r,sort:pt(i),q:s});return r?t.json(a):t.json(a.roles)}).openapi(o.createRoute({tags:["roles"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:cr}},description:"A role"}}}),async t=>{const{id:e}=t.req.valid("param"),n=await t.env.data.roles.get(t.var.tenant_id,e);if(!n)throw new b(404);return t.json(n)}).openapi(o.createRoute({tags:["roles"],method:"post",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:Ds}}}},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:cr}},description:"Role created"}}}),async t=>{const e=t.req.valid("json"),n=await t.env.data.roles.create(t.var.tenant_id,e);return t.json(n,{status:201})}).openapi(o.createRoute({tags:["roles"],method:"patch",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:Ds.partial()}}}},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:cr}},description:"Updated role"}}}),async t=>{const{id:e}=t.req.valid("param"),n=t.req.valid("json");if(!await t.env.data.roles.update(t.var.tenant_id,e,n))throw new b(404);const i=await t.env.data.roles.get(t.var.tenant_id,e);return t.json(i)}).openapi(o.createRoute({tags:["roles"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{id:e}=t.req.valid("param");if(!await t.env.data.roles.remove(t.var.tenant_id,e))throw new b(404);return t.text("OK")}).openapi(o.createRoute({tags:["roles"],method:"get",path:"/{id}/permissions",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),query:Ye},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:rm}},description:"Role permissions"}}}),async t=>{const{id:e}=t.req.valid("param"),{page:n,per_page:r,sort:i,q:s}=t.req.valid("query");if(!await t.env.data.roles.get(t.var.tenant_id,e))throw new b(404,{message:"Role not found"});const c=await t.env.data.rolePermissions.list(t.var.tenant_id,e,{page:n,per_page:r,include_totals:!1,sort:pt(i),q:s});return t.json(c)}).openapi(o.createRoute({tags:["roles"],method:"post",path:"/{id}/permissions",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object({permissions:o.z.array(o.z.object({permission_name:o.z.string(),resource_server_identifier:o.z.string()}))})}}}},security:[{Bearer:["auth:write"]}],responses:{201:{description:"Permissions assigned to role"}}}),async t=>{const{id:e}=t.req.valid("param"),{permissions:n}=t.req.valid("json");if(!await t.env.data.roles.get(t.var.tenant_id,e))throw new b(404,{message:"Role not found"});if(!await t.env.data.rolePermissions.assign(t.var.tenant_id,e,n.map(s=>({role_id:e,resource_server_identifier:s.resource_server_identifier,permission_name:s.permission_name}))))throw new b(500,{message:"Failed to assign permissions to role"});return t.json({message:"Permissions assigned successfully"},{status:201})}).openapi(o.createRoute({tags:["roles"],method:"delete",path:"/{id}/permissions",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object({permissions:o.z.array(o.z.object({permission_name:o.z.string(),resource_server_identifier:o.z.string()}))})}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Permissions removed from role"}}}),async t=>{const{id:e}=t.req.valid("param"),{permissions:n}=t.req.valid("json");if(!await t.env.data.roles.get(t.var.tenant_id,e))throw new b(404,{message:"Role not found"});if(!await t.env.data.rolePermissions.remove(t.var.tenant_id,e,n))throw new b(500,{message:"Failed to remove permissions from role"});return t.json({message:"Permissions removed successfully"})}),A4=xt.extend({resource_servers:o.z.array(ar)}),E4=new o.OpenAPIHono().openapi(o.createRoute({tags:["resource-servers"],method:"get",path:"/",request:{query:Ye,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(ar),A4])}},description:"List of resource servers"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{page:n,per_page:r,include_totals:i=!1,sort:s,q:a}=t.req.valid("query"),c=await t.env.data.resourceServers.list(e,{page:n,per_page:r,include_totals:i,sort:pt(s),q:a});return i?t.json(c):t.json(c.resource_servers)}).openapi(o.createRoute({tags:["resource-servers"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:ar}},description:"A resource server"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=await t.env.data.resourceServers.get(e,n);if(!r)throw new b(404);return t.json(r)}).openapi(o.createRoute({tags:["resource-servers"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param");if(!await t.env.data.resourceServers.remove(e,n))throw new b(404,{message:"Resource server not found"});return t.text("OK")}).openapi(o.createRoute({tags:["resource-servers"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Us.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:ar}},description:"The updated resource server"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=t.req.valid("json");if(!await t.env.data.resourceServers.update(e,n,r))throw new b(404,{message:"Resource server not found"});const s=await t.env.data.resourceServers.get(e,n);if(!s)throw new b(404,{message:"Resource server not found"});return t.json(s)}).openapi(o.createRoute({tags:["resource-servers"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Us.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:ar}},description:"A resource server"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r=await t.env.data.resourceServers.create(e,n);return t.json(r,{status:201})}),C4=o.z.object({per_page:o.z.string().min(1).optional().default("50").transform(t=>parseInt(t,10)).openapi({description:"Number of results per page. Defaults to 50."}),page:o.z.string().min(0).optional().default("0").transform(t=>parseInt(t,10)).openapi({description:"Page index of the results to return. First page is 0."}),include_totals:o.z.string().optional().default("false").transform(t=>t==="true").openapi({description:"Return results inside an object that contains the total result count (true) or as a direct array of results (false, default)."}),from:o.z.string().optional().openapi({description:"Optional Id from which to start selection."}),take:o.z.string().min(1).optional().transform(t=>t?parseInt(t,10):void 0).openapi({description:"Number of results per page. Defaults to 50."}),audience:o.z.string().optional().openapi({description:"Optional filter on audience."}),client_id:o.z.string().optional().openapi({description:"Optional filter on client_id."}),allow_any_organization:o.z.string().optional().transform(t=>t==="true"?!0:t==="false"?!1:void 0).openapi({description:"Optional filter on allow_any_organization."}),subject_type:o.z.enum(["client","user"]).optional().openapi({description:"EA The type of application access the client grant allows. Use of this field is subject to the applicable Free Trial terms in Okta's Master Subscription Agreement."})}),N4=xt.extend({client_grants:o.z.array(sr)}),I4=new o.OpenAPIHono().openapi(o.createRoute({tags:["client-grants"],method:"get",path:"/",request:{query:C4,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(sr),N4])}},description:"List of client grants"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{page:n,per_page:r,include_totals:i=!1,from:s,take:a,audience:c,client_id:l,allow_any_organization:d,subject_type:u}=t.req.valid("query"),f=[];l&&f.push(`client_id:"${l}"`),c&&f.push(`audience:"${c}"`),d!==void 0&&f.push(`allow_any_organization:${d}`),u&&f.push(`subject_type:"${u}"`),s&&f.push(`id:>${s}`);const h=f.length>0?f.join(" AND "):void 0,m=a??r,y=await t.env.data.clientGrants.list(e,{page:n,per_page:m,include_totals:i,q:h});return i?t.json(y):t.json(y.client_grants)}).openapi(o.createRoute({tags:["client-grants"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:sr}},description:"A client grant"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=await t.env.data.clientGrants.get(e,n);if(!r)throw new b(404,{message:"Client grant not found"});return t.json(r)}).openapi(o.createRoute({tags:["client-grants"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param");if(!await t.env.data.clientGrants.remove(e,n))throw new b(404,{message:"Client grant not found"});return t.text("OK")}).openapi(o.createRoute({tags:["client-grants"],method:"patch",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),body:{content:{"application/json":{schema:o.z.object(Ps.shape).partial()}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:sr}},description:"The updated client grant"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=t.req.valid("json");if(!await t.env.data.clientGrants.get(e,n))throw new b(404,{message:"Client grant not found"});if(!await t.env.data.clientGrants.update(e,n,r))throw new b(500,{message:"Failed to update client grant"});const a=await t.env.data.clientGrants.get(e,n);if(!a)throw new b(404,{message:"Client grant not found"});return t.json(a)}).openapi(o.createRoute({tags:["client-grants"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Ps.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:sr}},description:"A client grant"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r=await t.env.data.clientGrants.create(e,n);return t.json(r,{status:201})}),j4=o.z.object({page:o.z.string().optional().default("0").transform(t=>parseInt(t,10)).openapi({description:"Page index of the results to return. First page is 0."}),per_page:o.z.string().optional().default("50").transform(t=>parseInt(t,10)).openapi({description:"Number of results per page. Defaults to 50."}),include_totals:o.z.string().optional().default("false").transform(t=>t==="true").openapi({description:"When true, return results inside an object that also contains the start and limit. When false (default), a direct array of results is returned."}),fields:o.z.string().optional().openapi({description:"Comma-separated list of fields to include or exclude (based on value provided for include_fields) in the result. Leave empty to retrieve all fields."}),include_fields:o.z.string().optional().default("true").transform(t=>t==="true").openapi({description:"Whether specified fields are to be included (true) or excluded (false). Defaults to true."}),sort:o.z.string().optional().default("created_at:-1").openapi({description:"Field to sort by. Use field:order where order is 1 for ascending and -1 for descending. Defaults to created_at:-1."})}),O4=o.z.object({invitations:o.z.array(Gi),start:o.z.number(),limit:o.z.number(),length:o.z.number()}),T4=wu.omit({organization_id:!0,invitation_url:!0}),P4=xt.extend({organizations:o.z.array(Un)}),vp=o.z.object({user_id:o.z.string().openapi({description:"ID of this user"}),email:o.z.string().email().optional().openapi({description:"Email address of this user",format:"email"}),roles:o.z.array(o.z.object({})).default([]).openapi({description:"Array of roles assigned to this user in the organization"})}),R4=o.z.object({start:o.z.number().openapi({description:"Start index of the current page"}),limit:o.z.number().openapi({description:"Number of items per page"}),total:o.z.number().openapi({description:"Total number of members"}),members:o.z.array(vp).openapi({description:"Array of organization members"})}),B4=o.z.object({next:o.z.string().optional().openapi({description:"Checkpoint ID to be used to retrieve the next set of results"}),members:o.z.array(vp).openapi({description:"Array of organization members"})}),L4=o.z.object({members:o.z.array(o.z.string()).openapi({description:"Array of user IDs to add to the organization"})}),U4=o.z.object({members:o.z.array(o.z.string()).openapi({description:"Array of user IDs to remove from the organization"})}),D4=new o.OpenAPIHono().openapi(o.createRoute({tags:["organizations"],method:"get",path:"/",request:{query:Ye,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([P4,o.z.array(Un)])}},description:"List of organizations"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{page:n,per_page:r,include_totals:i,sort:s,q:a}=t.req.valid("query"),c=await t.env.data.organizations.list(e,{page:n,per_page:r,include_totals:i,sort:pt(s),q:a});return i?t.json(c):t.json(c.organizations)}).openapi(o.createRoute({tags:["organizations"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Un}},description:"An organization"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=await t.env.data.organizations.get(e,n);if(!r)throw new b(404,{message:"Organization not found"});return t.json(r)}).openapi(o.createRoute({tags:["organizations"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Organization deleted successfully"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param");if(!await t.env.data.organizations.remove(e,n))throw new b(404,{message:"Organization not found"});return t.text("OK")}).openapi(o.createRoute({tags:["organizations"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:Fs.partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Un}},description:"The updated organization"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=t.req.valid("json");if(!await t.env.data.organizations.update(e,n,r))throw new b(404,{message:"Organization not found"});const s=await t.env.data.organizations.get(e,n);if(!s)throw new b(404,{message:"Organization not found"});return t.json(s)}).openapi(o.createRoute({tags:["organizations"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:Fs}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Un}},description:"The created organization"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r={...n,id:n.id||E$()},i=await t.env.data.organizations.create(e,r);return t.json(i,{status:201})}).openapi(o.createRoute({tags:["organizations"],method:"get",path:"/{id}/members",request:{params:o.z.object({id:o.z.string()}),query:Ye,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(vp),R4,B4])}},description:"List of organization members"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),{page:r,per_page:i,include_totals:s,sort:a}=t.req.valid("query");if(!await t.env.data.organizations.get(e,n))throw new b(404,{message:"Organization not found"});const l=await t.env.data.userOrganizations.list(e,{page:r,per_page:i,include_totals:s,sort:pt(a),q:`organization_id:${n}`}),d=[];for(const u of l.userOrganizations){const f=await t.env.data.users.get(e,u.user_id);f&&d.push({user_id:f.user_id,email:f.email||void 0,roles:[]})}return s?t.json({start:l.start,limit:l.limit,total:l.length,members:d}):t.json(d)}).openapi(o.createRoute({tags:["organizations"],method:"post",path:"/{id}/members",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:L4}}}},security:[{Bearer:["auth:write"]}],responses:{204:{description:"Members added successfully"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),{members:r}=t.req.valid("json");if(!await t.env.data.organizations.get(e,n))throw new b(404,{message:"Organization not found"});for(const s of r)(await t.env.data.userOrganizations.list(e,{q:`user_id:${s}`,per_page:1})).userOrganizations.some(l=>l.organization_id===n)||await t.env.data.userOrganizations.create(e,{user_id:s,organization_id:n});return new Response(null,{status:204})}).openapi(o.createRoute({tags:["organizations"],method:"delete",path:"/{id}/members",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:U4}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Members removed successfully"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),{members:r}=t.req.valid("json");for(const i of r){const a=(await t.env.data.userOrganizations.list(e,{q:`user_id:${i}`,per_page:100})).userOrganizations.find(c=>c.organization_id===n);a&&await t.env.data.userOrganizations.remove(e,a.id)}return t.json({message:"Members removed successfully"})}).openapi(o.createRoute({tags:["organizations"],method:"get",path:"/{id}/members/{user_id}/roles",request:{params:o.z.object({id:o.z.string(),user_id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),query:Ye},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Ms}},description:"User roles in organization"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n,user_id:r}=t.req.valid("param");if(!await t.env.data.organizations.get(e,n))throw new b(404,{message:"Organization not found"});if(!await t.env.data.users.get(e,r))throw new b(404,{message:"User not found"});const a=await t.env.data.userRoles.list(e,r,void 0,n);return t.json(a)}).openapi(o.createRoute({tags:["organizations"],method:"post",path:"/{id}/members/{user_id}/roles",request:{params:o.z.object({id:o.z.string(),user_id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object({roles:o.z.array(o.z.string()).openapi({description:"List of role IDs to associate with the user"})})}}}},security:[{Bearer:["auth:write"]}],responses:{201:{description:"Roles assigned successfully"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n,user_id:r}=t.req.valid("param"),{roles:i}=t.req.valid("json");if(!await t.env.data.organizations.get(e,n))throw new b(404,{message:"Organization not found"});if(!await t.env.data.users.get(e,r))throw new b(404,{message:"User not found"});for(const c of i){if(!await t.env.data.roles.get(e,c))throw new b(400,{message:`Role ${c} not found`});if(!await t.env.data.userRoles.create(e,r,c,n))throw new b(500,{message:`Failed to assign role ${c} to user`})}return t.json({message:"Roles assigned successfully"},{status:201})}).openapi(o.createRoute({tags:["organizations"],method:"delete",path:"/{id}/members/{user_id}/roles",request:{params:o.z.object({id:o.z.string(),user_id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object({roles:o.z.array(o.z.string()).openapi({description:"List of role IDs to remove from the user"})})}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Roles removed successfully"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n,user_id:r}=t.req.valid("param"),{roles:i}=t.req.valid("json");if(!await t.env.data.organizations.get(e,n))throw new b(404,{message:"Organization not found"});if(!await t.env.data.users.get(e,r))throw new b(404,{message:"User not found"});for(const c of i)if(!await t.env.data.userRoles.remove(e,r,c,n))throw new b(500,{message:`Failed to remove role ${c} from user`});return t.json({message:"Roles removed successfully"})}).openapi(o.createRoute({tags:["organizations"],method:"get",path:"/{id}/roles",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),query:Ye},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Ms}},description:"List of roles available in organization"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),{page:r,per_page:i,sort:s,q:a}=t.req.valid("query");if(!await t.env.data.organizations.get(e,n))throw new b(404,{message:"Organization not found"});const l=await t.env.data.roles.list(e,{page:r,per_page:i,sort:pt(s),q:a});return t.json(l.roles)}).openapi(o.createRoute({tags:["organizations"],method:"get",path:"/{id}/invitations",request:{params:o.z.object({id:o.z.string().openapi({description:"Organization ID",param:{name:"id",in:"path"}})}),query:j4,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(Gi),O4])}},description:"List of organization invitations"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),{page:r,per_page:i,include_totals:s,fields:a,include_fields:c,sort:l}=t.req.valid("query");if(!await t.env.data.organizations.get(e,n))throw new b(404,{message:"Organization not found"});let f=(await t.env.data.invites.list(e,{page:r,per_page:i})).invites.filter(h=>h.organization_id===n);if(l){const h=pt(l);if(h){const{sort_by:m,sort_order:y}=h;f.sort((v,$)=>{const A=v[m],O=$[m];if(A===void 0||O===void 0||A===O)return 0;const U=A<O?-1:1;return y==="asc"?U:-U})}}if(a){const h=a.split(",").map(m=>m.trim());f=f.map(m=>{const y={};for(const v of Object.keys(m))(c?h.includes(v):!h.includes(v))&&(y[v]=m[v]);return y})}return s?t.json({invitations:f,start:r*i,limit:i,length:f.length}):t.json(f)}).openapi(o.createRoute({tags:["organizations"],method:"get",path:"/{id}/invitations/{invitation_id}",request:{params:o.z.object({id:o.z.string().openapi({description:"Organization ID",param:{name:"id",in:"path"}}),invitation_id:o.z.string().openapi({description:"Invitation ID",param:{name:"invitation_id",in:"path"}})}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Gi}},description:"An invitation"},404:{description:"Invitation not found"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n,invitation_id:r}=t.req.valid("param"),i=await t.env.data.invites.get(e,r);if(!i||i.organization_id!==n)throw new b(404,{message:"Invitation not found"});return t.json(i)}).openapi(o.createRoute({tags:["organizations"],method:"post",path:"/{id}/invitations",request:{params:o.z.object({id:o.z.string().openapi({description:"Organization ID",param:{name:"id",in:"path"}})}),body:{content:{"application/json":{schema:T4}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Gi}},description:"The created invitation"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=t.req.valid("json");if(!await t.env.data.organizations.get(e,n))throw new b(404,{message:"Organization not found"});const a=`https://invite.placeholder/${I$()}`,c={...r,organization_id:n,invitation_url:a},l=await t.env.data.invites.create(e,c);return t.json(l,{status:201})}).openapi(o.createRoute({tags:["organizations"],method:"delete",path:"/{id}/invitations/{invitation_id}",request:{params:o.z.object({id:o.z.string().openapi({description:"Organization ID",param:{name:"id",in:"path"}}),invitation_id:o.z.string().openapi({description:"Invitation ID",param:{name:"invitation_id",in:"path"}})}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{204:{description:"Invitation deleted successfully"},404:{description:"Invitation not found"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n,invitation_id:r}=t.req.valid("param"),i=await t.env.data.invites.get(e,r);if(!i||i.organization_id!==n)throw new b(404,{message:"Invitation not found"});if(!await t.env.data.invites.remove(e,r))throw new b(404,{message:"Invitation not found"});return t.body(null,{status:204})});function M4(t){const e=new o.OpenAPIHono;e.use(g0({origin:r=>{var i;return r&&(i=t.allowedOrigins)!=null&&i.includes(r)?r:""},allowHeaders:["Tenant-Id","Content-Type","Content-Range","Auth0-Client","Authorization","Range","Upgrade-Insecure-Requests"],allowMethods:["POST","PUT","GET","DELETE","PATCH","OPTIONS"],exposeHeaders:["Content-Length","Content-Range"],maxAge:600,credentials:!0})),yp(e),e.use(async(r,i)=>{const s=xo(r,t.dataAdapter),a=Ho({defaultTtlSeconds:0,maxEntries:100,cleanupIntervalMs:0}),c=Dc(s,{defaultTtl:0,cacheEntities:["tenants","connections","clients","legacyClients","branding","themes","promptSettings","forms"],cache:a});return r.env.data=Rc(r,c),i()}),e.use(Uc).use(Lc).use(wp(e));const n=e.route("/branding",tv).route("/custom-domains",y4).route("/email/providers",g4).route("/users",vb).route("/keys",y$).route("/users-by-email",w$).route("/clients",b$).route("/client-grants",I4).route("/tenants",k$).route("/logs",S$).route("/hooks",O$).route("/connections",P$).route("/prompts",R$).route("/sessions",m4).route("/refresh_tokens",_4).route("/forms",x4).route("/roles",z4).route("/resource-servers",E4).route("/organizations",D4);return n.doc("/spec",{openapi:"3.0.0",info:{version:"1.0.0",title:"Management API"},servers:[{url:"/api/v2",description:"API V2"}],security:[{oauth2:["openid","email","profile"]}]}),n}function F4(t,e){Object.keys(e).forEach(n=>{const r=e[n];r!=null&&r.length&&t.searchParams.set(n,r)})}function Cn(t){var e;if(t)return`${t.name}/${t.version}${(e=t.env)!=null&&e.node?` (env: node/${t.env.node})`:""}`}var q4=(t,...e)=>{const n=[""];for(let r=0,i=t.length-1;r<i;r++){n[0]+=t[r];const s=Array.isArray(e[r])?e[r].flat(1/0):[e[r]];for(let a=0,c=s.length;a<c;a++){const l=s[a];if(typeof l=="string")Vn(l,n);else if(typeof l=="number")n[0]+=l;else{if(typeof l=="boolean"||l===null||l===void 0)continue;if(typeof l=="object"&&l.isEscaped)if(l.callbacks)n.unshift("",l);else{const d=l.toString();d instanceof Promise?n.unshift("",d):n[0]+=d}else l instanceof Promise?n.unshift("",l):Vn(l.toString(),n)}}}return n[0]+=t.at(-1),n.length===1?"callbacks"in n?Xt(Uy(Xt(n[0],n.callbacks))):Xt(n[0]):Ly(n,n.callbacks)},bp=Symbol("RENDERER"),eu=Symbol("ERROR_HANDLER"),Be=Symbol("STASH"),Dy=Symbol("INTERNAL"),H4=Symbol("MEMO"),za=Symbol("PERMALINK"),Zh=t=>(t[Dy]=!0,t),My=t=>({value:e,children:n})=>{if(!n)return;const r={children:[{tag:Zh(()=>{t.push(e)}),props:{}}]};Array.isArray(n)?r.children.push(...n.flat()):r.children.push(n),r.children.push({tag:Zh(()=>{t.pop()}),props:{}});const i={tag:"",props:r,type:""};return i[eu]=s=>{throw t.pop(),s},i},Fy=t=>{const e=[t],n=My(e);return n.values=e,n.Provider=n,gi.push(n),n},gi=[],qy=t=>{const e=[t],n=r=>{e.push(r.value);let i;try{i=r.children?(Array.isArray(r.children)?new Gy("",{},r.children):r.children).toString():""}finally{e.pop()}return i instanceof Promise?i.then(s=>Xt(s,s.callbacks)):Xt(i)};return n.values=e,n.Provider=n,n[bp]=My(e),gi.push(n),n},ji=t=>t.values.at(-1),ws={title:[],script:["src"],style:["data-href"],link:["href"],meta:["name","httpEquiv","charset","itemProp"]},tu={},vs="data-precedence",Vo=t=>Array.isArray(t)?t:[t],Yh=new WeakMap,Qh=(t,e,n,r)=>({buffer:i,context:s})=>{if(!i)return;const a=Yh.get(s)||{};Yh.set(s,a);const c=a[t]||(a[t]=[]);let l=!1;const d=ws[t];if(d.length>0){e:for(const[,u]of c)for(const f of d)if(((u==null?void 0:u[f])??null)===(n==null?void 0:n[f])){l=!0;break e}}if(l?i[0]=i[0].replaceAll(e,""):d.length>0?c.push([e,n,r]):c.unshift([e,n,r]),i[0].indexOf("</head>")!==-1){let u;if(r===void 0)u=c.map(([f])=>f);else{const f=[];u=c.map(([h,,m])=>{let y=f.indexOf(m);return y===-1&&(f.push(m),y=f.length-1),[h,y]}).sort((h,m)=>h[1]-m[1]).map(([h])=>h)}u.forEach(f=>{i[0]=i[0].replaceAll(f,"")}),i[0]=i[0].replace(/(?=<\/head>)/,u.join(""))}},Ko=(t,e,n)=>Xt(new Zt(t,n,Vo(e??[])).toString()),Go=(t,e,n,r)=>{if("itemProp"in n)return Ko(t,e,n);let{precedence:i,blocking:s,...a}=n;i=r?i??"":void 0,r&&(a[vs]=i);const c=new Zt(t,a,Vo(e||[])).toString();return c instanceof Promise?c.then(l=>Xt(c,[...l.callbacks||[],Qh(t,l,a,i)])):Xt(c,[Qh(t,c,a,i)])},V4=({children:t,...e})=>{const n=$p();if(n){const r=ji(n);if(r==="svg"||r==="head")return new Zt("title",e,Vo(t??[]))}return Go("title",t,e,!1)},K4=({children:t,...e})=>{const n=$p();return["src","async"].some(r=>!e[r])||n&&ji(n)==="head"?Ko("script",t,e):Go("script",t,e,!1)},G4=({children:t,...e})=>["href","precedence"].every(n=>n in e)?(e["data-href"]=e.href,delete e.href,Go("style",t,e,!0)):Ko("style",t,e),W4=({children:t,...e})=>["onLoad","onError"].some(n=>n in e)||e.rel==="stylesheet"&&(!("precedence"in e)||"disabled"in e)?Ko("link",t,e):Go("link",t,e,"precedence"in e),J4=({children:t,...e})=>{const n=$p();return n&&ji(n)==="head"?Ko("meta",t,e):Go("meta",t,e,!1)},Hy=(t,{children:e,...n})=>new Zt(t,n,Vo(e??[])),X4=t=>(typeof t.action=="function"&&(t.action=za in t.action?t.action[za]:void 0),Hy("form",t)),Vy=(t,e)=>(typeof e.formAction=="function"&&(e.formAction=za in e.formAction?e.formAction[za]:void 0),Hy(t,e)),Z4=t=>Vy("input",t),Y4=t=>Vy("button",t);const dl=Object.freeze(Object.defineProperty({__proto__:null,button:Y4,form:X4,input:Z4,link:W4,meta:J4,script:K4,style:G4,title:V4},Symbol.toStringTag,{value:"Module"}));var Q4=new Map([["className","class"],["htmlFor","for"],["crossOrigin","crossorigin"],["httpEquiv","http-equiv"],["itemProp","itemprop"],["fetchPriority","fetchpriority"],["noModule","nomodule"],["formAction","formaction"]]),Aa=t=>Q4.get(t)||t,Ky=(t,e)=>{for(const[n,r]of Object.entries(t)){const i=n[0]==="-"||!/[A-Z]/.test(n)?n:n.replace(/[A-Z]/g,s=>`-${s.toLowerCase()}`);e(i,r==null?null:typeof r=="number"?i.match(/^(?:a|border-im|column(?:-c|s)|flex(?:$|-[^b])|grid-(?:ar|[^a])|font-w|li|or|sca|st|ta|wido|z)|ty$/)?`${r}`:`${r}px`:r)}},yo=void 0,$p=()=>yo,ek=t=>/[A-Z]/.test(t)&&t.match(/^(?:al|basel|clip(?:Path|Rule)$|co|do|fill|fl|fo|gl|let|lig|i|marker[EMS]|o|pai|pointe|sh|st[or]|text[^L]|tr|u|ve|w)/)?t.replace(/([A-Z])/g,"-$1").toLowerCase():t,tk=["area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],nk=["allowfullscreen","async","autofocus","autoplay","checked","controls","default","defer","disabled","download","formnovalidate","hidden","inert","ismap","itemscope","loop","multiple","muted","nomodule","novalidate","open","playsinline","readonly","required","reversed","selected"],kp=(t,e)=>{for(let n=0,r=t.length;n<r;n++){const i=t[n];if(typeof i=="string")Vn(i,e);else{if(typeof i=="boolean"||i===null||i===void 0)continue;i instanceof Zt?i.toStringToBuffer(e):typeof i=="number"||i.isEscaped?e[0]+=i:i instanceof Promise?e.unshift("",i):kp(i,e)}}},Zt=class{constructor(t,e,n){se(this,"tag");se(this,"props");se(this,"key");se(this,"children");se(this,"isEscaped",!0);se(this,"localContexts");this.tag=t,this.props=e,this.children=n}get type(){return this.tag}get ref(){return this.props.ref||null}toString(){var e,n;const t=[""];(e=this.localContexts)==null||e.forEach(([r,i])=>{r.values.push(i)});try{this.toStringToBuffer(t)}finally{(n=this.localContexts)==null||n.forEach(([r])=>{r.values.pop()})}return t.length===1?"callbacks"in t?Uy(Xt(t[0],t.callbacks)).toString():t[0]:Ly(t,t.callbacks)}toStringToBuffer(t){const e=this.tag,n=this.props;let{children:r}=this;t[0]+=`<${e}`;const i=yo&&ji(yo)==="svg"?s=>ek(Aa(s)):s=>Aa(s);for(let[s,a]of Object.entries(n))if(s=i(s),s!=="children"){if(s==="style"&&typeof a=="object"){let c="";Ky(a,(l,d)=>{d!=null&&(c+=`${c?";":""}${l}:${d}`)}),t[0]+=' style="',Vn(c,t),t[0]+='"'}else if(typeof a=="string")t[0]+=` ${s}="`,Vn(a,t),t[0]+='"';else if(a!=null)if(typeof a=="number"||a.isEscaped)t[0]+=` ${s}="${a}"`;else if(typeof a=="boolean"&&nk.includes(s))a&&(t[0]+=` ${s}=""`);else if(s==="dangerouslySetInnerHTML"){if(r.length>0)throw new Error("Can only set one of `children` or `props.dangerouslySetInnerHTML`.");r=[Xt(a.__html)]}else if(a instanceof Promise)t[0]+=` ${s}="`,t.unshift('"',a);else if(typeof a=="function"){if(!s.startsWith("on")&&s!=="ref")throw new Error(`Invalid prop '${s}' of type 'function' supplied to '${e}'.`)}else t[0]+=` ${s}="`,Vn(a.toString(),t),t[0]+='"'}if(tk.includes(e)&&r.length===0){t[0]+="/>";return}t[0]+=">",kp(r,t),t[0]+=`</${e}>`}},ul=class extends Zt{toStringToBuffer(t){const{children:e}=this,n=this.tag.call(null,{...this.props,children:e.length<=1?e[0]:e});if(!(typeof n=="boolean"||n==null))if(n instanceof Promise)if(gi.length===0)t.unshift("",n);else{const r=gi.map(i=>[i,i.values.at(-1)]);t.unshift("",n.then(i=>(i instanceof Zt&&(i.localContexts=r),i)))}else n instanceof Zt?n.toStringToBuffer(t):typeof n=="number"||n.isEscaped?(t[0]+=n,n.callbacks&&(t.callbacks||(t.callbacks=[]),t.callbacks.push(...n.callbacks))):Vn(n,t)}},Gy=class extends Zt{toStringToBuffer(t){kp(this.children,t)}},rk=(t,e,...n)=>{e??(e={}),n.length&&(e.children=n.length===1?n[0]:n);const r=e.key;delete e.key;const i=bs(t,e,n);return i.key=r,i},eg=!1,bs=(t,e,n)=>{if(!eg){for(const r in tu)dl[r][bp]=tu[r];eg=!0}return typeof t=="function"?new ul(t,e,n):dl[t]?new ul(dl[t],e,n):t==="svg"||t==="head"?(yo||(yo=qy("")),new Zt(t,e,[new ul(yo,{value:t},n)])):new Zt(t,e,n)},Mc=({children:t})=>new Gy("",{children:t},Array.isArray(t)?t:t?[t]:[]),ik=(t,e,...n)=>{let r;if(n.length>0)r=n;else{const i=t.props.children;r=Array.isArray(i)?i:[i]}return rk(t.tag,{...t.props,...e},...r)};function p(t,e,n){let r;if(!e||!("children"in e))r=bs(t,e,[]);else{const i=e.children;r=Array.isArray(i)?bs(t,e,i):bs(t,e,[i])}return r.key=n,r}var tg;(function(t){t[t.Include=0]="Include",t[t.None=1]="None"})(tg||(tg={}));var ng;(function(t){t[t.Required=0]="Required",t[t.Ignore=1]="Ignore"})(ng||(ng={}));function ok(t){return Jy(t,sk,wo.Include)}function Wy(t){return Jy(t,ak,wo.None)}function Jy(t,e,n){let r="";for(let i=0;i<t.byteLength;i+=3){let s=0,a=0;for(let c=0;c<3&&i+c<t.byteLength;c++)s=s<<8|t[i+c],a+=8;for(let c=0;c<4;c++)a>=6?(r+=e[s>>a-6&63],a-=6):a>0?(r+=e[s<<6-a&63],a=0):n===wo.Include&&(r+="=")}return r}const sk="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",ak="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";var wo;(function(t){t[t.Include=0]="Include",t[t.None=1]="None"})(wo||(wo={}));var rg;(function(t){t[t.Required=0]="Required",t[t.Ignore=1]="Ignore"})(rg||(rg={}));class ck{uint8(e,n){if(e.byteLength<n+1)throw new TypeError("Insufficient bytes");return e[n]}uint16(e,n){if(e.byteLength<n+2)throw new TypeError("Insufficient bytes");return e[n]<<8|e[n+1]}uint32(e,n){if(e.byteLength<n+4)throw new TypeError("Insufficient bytes");let r=0;for(let i=0;i<4;i++)r|=e[n+i]<<24-i*8;return r}uint64(e,n){if(e.byteLength<n+8)throw new TypeError("Insufficient bytes");let r=0n;for(let i=0;i<8;i++)r|=BigInt(e[n+i])<<BigInt(56-i*8);return r}putUint8(e,n,r){if(e.length<r+1)throw new TypeError("Not enough space");if(n<0||n>255)throw new TypeError("Invalid uint8 value");e[r]=n}putUint16(e,n,r){if(e.length<r+2)throw new TypeError("Not enough space");if(n<0||n>65535)throw new TypeError("Invalid uint16 value");e[r]=n>>8,e[r+1]=n&255}putUint32(e,n,r){if(e.length<r+4)throw new TypeError("Not enough space");if(n<0||n>4294967295)throw new TypeError("Invalid uint32 value");for(let i=0;i<4;i++)e[r+i]=n>>(3-i)*8&255}putUint64(e,n,r){if(e.length<r+8)throw new TypeError("Not enough space");if(n<0||n>18446744073709551615n)throw new TypeError("Invalid uint64 value");for(let i=0;i<8;i++)e[r+i]=Number(n>>BigInt((7-i)*8)&0xffn)}}const ig=new ck;function sn(t,e){return(t<<32-e|t>>>e)>>>0}function lk(t){const e=new dk;return e.update(t),e.digest()}class dk{constructor(){se(this,"blockSize",64);se(this,"size",32);se(this,"blocks",new Uint8Array(64));se(this,"currentBlockSize",0);se(this,"H",new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]));se(this,"l",0n);se(this,"w",new Uint32Array(64))}update(e){if(this.l+=BigInt(e.byteLength)*8n,this.currentBlockSize+e.byteLength<64){this.blocks.set(e,this.currentBlockSize),this.currentBlockSize+=e.byteLength;return}let n=0;if(this.currentBlockSize>0){const r=e.slice(0,64-this.currentBlockSize);this.blocks.set(r,this.currentBlockSize),this.process(),n+=r.byteLength,this.currentBlockSize=0}for(;n+64<=e.byteLength;){const r=e.slice(n,n+64);this.blocks.set(r),this.process(),n+=64}if(e.byteLength-n>0){const r=e.slice(n);this.blocks.set(r),this.currentBlockSize=r.byteLength}}digest(){this.blocks[this.currentBlockSize]=128,this.currentBlockSize+=1,64-this.currentBlockSize<8&&(this.blocks.fill(0,this.currentBlockSize),this.process(),this.currentBlockSize=0),this.blocks.fill(0,this.currentBlockSize),ig.putUint64(this.blocks,this.l,this.blockSize-8),this.process();const e=new Uint8Array(32);for(let n=0;n<8;n++)ig.putUint32(e,this.H[n],n*4);return e}process(){for(let d=0;d<16;d++)this.w[d]=(this.blocks[d*4]<<24|this.blocks[d*4+1]<<16|this.blocks[d*4+2]<<8|this.blocks[d*4+3])>>>0;for(let d=16;d<64;d++){const u=(sn(this.w[d-2],17)^sn(this.w[d-2],19)^this.w[d-2]>>>10)>>>0,f=(sn(this.w[d-15],7)^sn(this.w[d-15],18)^this.w[d-15]>>>3)>>>0;this.w[d]=u+this.w[d-7]+f+this.w[d-16]|0}let e=this.H[0],n=this.H[1],r=this.H[2],i=this.H[3],s=this.H[4],a=this.H[5],c=this.H[6],l=this.H[7];for(let d=0;d<64;d++){const u=(sn(s,6)^sn(s,11)^sn(s,25))>>>0,f=(s&a^~s&c)>>>0,h=l+u+f+uk[d]+this.w[d]|0,m=(sn(e,2)^sn(e,13)^sn(e,22))>>>0,y=(e&n^e&r^n&r)>>>0,v=m+y|0;l=c,c=a,a=s,s=i+h|0,i=r,r=n,n=e,e=h+v|0}this.H[0]=e+this.H[0]|0,this.H[1]=n+this.H[1]|0,this.H[2]=r+this.H[2]|0,this.H[3]=i+this.H[3]|0,this.H[4]=s+this.H[4]|0,this.H[5]=a+this.H[5]|0,this.H[6]=c+this.H[6]|0,this.H[7]=l+this.H[7]|0}}const uk=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);new BigUint64Array([0x428a2f98d728ae22n,0x7137449123ef65cdn,0xb5c0fbcfec4d3b2fn,0xe9b5dba58189dbbcn,0x3956c25bf348b538n,0x59f111f1b605d019n,0x923f82a4af194f9bn,0xab1c5ed5da6d8118n,0xd807aa98a3030242n,0x12835b0145706fben,0x243185be4ee4b28cn,0x550c7dc3d5ffb4e2n,0x72be5d74f27b896fn,0x80deb1fe3b1696b1n,0x9bdc06a725c71235n,0xc19bf174cf692694n,0xe49b69c19ef14ad2n,0xefbe4786384f25e3n,0x0fc19dc68b8cd5b5n,0x240ca1cc77ac9c65n,0x2de92c6f592b0275n,0x4a7484aa6ea6e483n,0x5cb0a9dcbd41fbd4n,0x76f988da831153b5n,0x983e5152ee66dfabn,0xa831c66d2db43210n,0xb00327c898fb213fn,0xbf597fc7beef0ee4n,0xc6e00bf33da88fc2n,0xd5a79147930aa725n,0x06ca6351e003826fn,0x142929670a0e6e70n,0x27b70a8546d22ffcn,0x2e1b21385c26c926n,0x4d2c6dfc5ac42aedn,0x53380d139d95b3dfn,0x650a73548baf63den,0x766a0abb3c77b2a8n,0x81c2c92e47edaee6n,0x92722c851482353bn,0xa2bfe8a14cf10364n,0xa81a664bbc423001n,0xc24b8b70d0f89791n,0xc76c51a30654be30n,0xd192e819d6ef5218n,0xd69906245565a910n,0xf40e35855771202an,0x106aa07032bbd1b8n,0x19a4c116b8d2d0c8n,0x1e376c085141ab53n,0x2748774cdf8eeb99n,0x34b0bcb5e19b48a8n,0x391c0cb3c5c95a63n,0x4ed8aa4ae3418acbn,0x5b9cca4f7763e373n,0x682e6ff3d6b2b8a3n,0x748f82ee5defb2fcn,0x78a5636f43172f60n,0x84c87814a1f0ab72n,0x8cc702081a6439ecn,0x90befffa23631e28n,0xa4506cebde82bde9n,0xbef9a3f7b2c67915n,0xc67178f2e372532bn,0xca273eceea26619cn,0xd186b8c721c0c207n,0xeada7dd6cde0eb1en,0xf57d4f7fee6ed178n,0x06f067aa72176fban,0x0a637dc5a2c898a6n,0x113f9804bef90daen,0x1b710b35131c471bn,0x28db77f523047d84n,0x32caab7b40c72493n,0x3c9ebe0a15c9bebcn,0x431d67c49c100d4cn,0x4cc5d4becb3e42b6n,0x597f299cfc657e2an,0x5fcb6fab3ad6faecn,0x6c44198c4a475817n]);class Xy{constructor(e){se(this,"data");this.data=e}tokenType(){if("token_type"in this.data&&typeof this.data.token_type=="string")return this.data.token_type;throw new Error("Missing or invalid 'token_type' field")}accessToken(){if("access_token"in this.data&&typeof this.data.access_token=="string")return this.data.access_token;throw new Error("Missing or invalid 'access_token' field")}accessTokenExpiresInSeconds(){if("expires_in"in this.data&&typeof this.data.expires_in=="number")return this.data.expires_in;throw new Error("Missing or invalid 'expires_in' field")}accessTokenExpiresAt(){return new Date(Date.now()+this.accessTokenExpiresInSeconds()*1e3)}hasRefreshToken(){return"refresh_token"in this.data&&typeof this.data.refresh_token=="string"}refreshToken(){if("refresh_token"in this.data&&typeof this.data.refresh_token=="string")return this.data.refresh_token;throw new Error("Missing or invalid 'refresh_token' field")}hasScopes(){return"scope"in this.data&&typeof this.data.scope=="string"}scopes(){if("scope"in this.data&&typeof this.data.scope=="string")return this.data.scope.split(" ");throw new Error("Missing or invalid 'scope' field")}idToken(){if("id_token"in this.data&&typeof this.data.id_token=="string")return this.data.id_token;throw new Error("Missing or invalid field 'id_token'")}}function pk(t){const e=lk(new TextEncoder().encode(t));return Wy(e)}function Zy(){const t=new Uint8Array(32);return crypto.getRandomValues(t),Wy(t)}function fk(t,e){if(e.length!==1)throw new TypeError("Invalid character string");let n=0;for(;n<t.length&&t[n]===e;)n++;return t.slice(n)}function og(t,e){if(e.length!==1)throw new TypeError("Invalid character string");let n=t.length;for(;n>0&&t[n-1]===e;)n--;return t.slice(0,n)}function sg(t,...e){let n=og(t,"/");for(const r of e)n=og(n,"/")+"/"+fk(r,"/");return n}function gr(t,e){const n=new TextEncoder().encode(e.toString()),r=new Request(t,{method:"POST",body:n});return r.headers.set("Content-Type","application/x-www-form-urlencoded"),r.headers.set("Accept","application/json"),r.headers.set("User-Agent","arctic"),r.headers.set("Content-Length",n.byteLength.toString()),r}function eo(t,e){const n=new TextEncoder().encode(`${t}:${e}`);return ok(n)}async function Ea(t){let e;try{e=await fetch(t)}catch(n){throw new Sp(n)}if(e.status===400||e.status===401){let n;try{n=await e.json()}catch{throw new Zr(e.status)}if(typeof n!="object"||n===null)throw new Kn(e.status,n);let r;try{r=xp(n)}catch{throw new Kn(e.status,n)}throw r}if(e.status===200){let n;try{n=await e.json()}catch{throw new Zr(e.status)}if(typeof n!="object"||n===null)throw new Kn(e.status,n);return new Xy(n)}throw e.body!==null&&await e.body.cancel(),new Zr(e.status)}async function hk(t){let e;try{e=await fetch(t)}catch(n){throw new Sp(n)}if(e.status===400||e.status===401){let n;try{n=await e.json()}catch{throw new Kn(e.status,null)}if(typeof n!="object"||n===null)throw new Kn(e.status,n);let r;try{r=xp(n)}catch{throw new Kn(e.status,n)}throw r}if(e.status===200){e.body!==null&&await e.body.cancel();return}throw e.body!==null&&await e.body.cancel(),new Zr(e.status)}function xp(t){let e;if("error"in t&&typeof t.error=="string")e=t.error;else throw new Error("Invalid error response");let n=null,r=null,i=null;if("error_description"in t){if(typeof t.error_description!="string")throw new Error("Invalid data");n=t.error_description}if("error_uri"in t){if(typeof t.error_uri!="string")throw new Error("Invalid data");r=t.error_uri}if("state"in t){if(typeof t.state!="string")throw new Error("Invalid data");i=t.state}return new gk(e,n,r,i)}class Sp extends Error{constructor(e){super("Failed to send request",{cause:e})}}class gk extends Error{constructor(n,r,i,s){super(`OAuth request error: ${n}`);se(this,"code");se(this,"description");se(this,"uri");se(this,"state");this.code=n,this.description=r,this.uri=i,this.state=s}}class Zr extends Error{constructor(n){super("Unexpected error response");se(this,"status");this.status=n}}class Kn extends Error{constructor(n,r){super("Unexpected error response body");se(this,"status");se(this,"data");this.status=n,this.data=r}}class Fc{constructor(e,n,r){se(this,"clientId");se(this,"clientPassword");se(this,"redirectURI");this.clientId=e,this.clientPassword=n,this.redirectURI=r}createAuthorizationURL(e,n,r){const i=new URL(e);return i.searchParams.set("response_type","code"),i.searchParams.set("client_id",this.clientId),this.redirectURI!==null&&i.searchParams.set("redirect_uri",this.redirectURI),i.searchParams.set("state",n),r.length>0&&i.searchParams.set("scope",r.join(" ")),i}createAuthorizationURLWithPKCE(e,n,r,i,s){const a=new URL(e);if(a.searchParams.set("response_type","code"),a.searchParams.set("client_id",this.clientId),this.redirectURI!==null&&a.searchParams.set("redirect_uri",this.redirectURI),a.searchParams.set("state",n),r===mi.S256){const c=pk(i);a.searchParams.set("code_challenge_method","S256"),a.searchParams.set("code_challenge",c)}else r===mi.Plain&&(a.searchParams.set("code_challenge_method","plain"),a.searchParams.set("code_challenge",i));return s.length>0&&a.searchParams.set("scope",s.join(" ")),a}async validateAuthorizationCode(e,n,r){const i=new URLSearchParams;i.set("grant_type","authorization_code"),i.set("code",n),this.redirectURI!==null&&i.set("redirect_uri",this.redirectURI),r!==null&&i.set("code_verifier",r),this.clientPassword===null&&i.set("client_id",this.clientId);const s=gr(e,i);if(this.clientPassword!==null){const c=eo(this.clientId,this.clientPassword);s.headers.set("Authorization",`Basic ${c}`)}return await Ea(s)}async refreshAccessToken(e,n,r){const i=new URLSearchParams;i.set("grant_type","refresh_token"),i.set("refresh_token",n),this.clientPassword===null&&i.set("client_id",this.clientId),r.length>0&&i.set("scope",r.join(" "));const s=gr(e,i);if(this.clientPassword!==null){const c=eo(this.clientId,this.clientPassword);s.headers.set("Authorization",`Basic ${c}`)}return await Ea(s)}async revokeToken(e,n){const r=new URLSearchParams;r.set("token",n),this.clientPassword===null&&r.set("client_id",this.clientId);const i=gr(e,r);if(this.clientPassword!==null){const s=eo(this.clientId,this.clientPassword);i.headers.set("Authorization",`Basic ${s}`)}await hk(i)}}var mi;(function(t){t[t.S256=0]="S256",t[t.Plain=1]="Plain"})(mi||(mi={}));var ag;(function(t){t[t.Include=0]="Include",t[t.None=1]="None"})(ag||(ag={}));var cg;(function(t){t[t.Required=0]="Required",t[t.Ignore=1]="Ignore"})(cg||(cg={}));function to(t){return mk(t,_k,Ca.None)}function mk(t,e,n){let r="";for(let i=0;i<t.byteLength;i+=3){let s=0,a=0;for(let c=0;c<3&&i+c<t.byteLength;c++)s=s<<8|t[i+c],a+=8;for(let c=0;c<4;c++)a>=6?(r+=e[s>>a-6&63],a-=6):a>0?(r+=e[s<<6-a&63],a=0):n===Ca.Include&&(r+="=")}return r}const _k="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";var Ca;(function(t){t[t.Include=0]="Include",t[t.None=1]="None"})(Ca||(Ca={}));var lg;(function(t){t[t.Required=0]="Required",t[t.Ignore=1]="Ignore"})(lg||(lg={}));function yk(t,e,n){const r=to(new TextEncoder().encode(t)),i=to(new TextEncoder().encode(e)),s=to(n);return r+"."+i+"."+s}function wk(t,e){const n=to(new TextEncoder().encode(t)),r=to(new TextEncoder().encode(e)),i=n+"."+r;return new TextEncoder().encode(i)}const vk="https://appleid.apple.com/auth/authorize",bk="https://appleid.apple.com/auth/token";class Yy{constructor(e,n,r,i,s){se(this,"clientId");se(this,"teamId");se(this,"keyId");se(this,"pkcs8PrivateKey");se(this,"redirectURI");this.clientId=e,this.teamId=n,this.keyId=r,this.pkcs8PrivateKey=i,this.redirectURI=s}createAuthorizationURL(e,n){const r=new URL(vk);return r.searchParams.set("response_type","code"),r.searchParams.set("client_id",this.clientId),r.searchParams.set("state",e),n.length>0&&r.searchParams.set("scope",n.join(" ")),r.searchParams.set("redirect_uri",this.redirectURI),r}async validateAuthorizationCode(e){const n=new URLSearchParams;n.set("grant_type","authorization_code"),n.set("code",e),n.set("redirect_uri",this.redirectURI),n.set("client_id",this.clientId);const r=await this.createClientSecret();n.set("client_secret",r);const i=gr(bk,n);return await Ea(i)}async createClientSecret(){const e=await crypto.subtle.importKey("pkcs8",this.pkcs8PrivateKey,{name:"ECDSA",namedCurve:"P-256"},!1,["sign"]),n=Math.floor(Date.now()/1e3),r=JSON.stringify({typ:"JWT",alg:"ES256",kid:this.keyId}),i=JSON.stringify({iss:this.teamId,exp:n+5*60,aud:["https://appleid.apple.com"],sub:this.clientId,iat:n}),s=new Uint8Array(await crypto.subtle.sign({name:"ECDSA",hash:"SHA-256"},e,wk(r,i)));return yk(r,i,s)}}const $k="https://www.facebook.com/v16.0/dialog/oauth",kk="https://graph.facebook.com/v16.0/oauth/access_token";class Qy{constructor(e,n,r){se(this,"clientId");se(this,"clientSecret");se(this,"redirectURI");this.clientId=e,this.clientSecret=n,this.redirectURI=r}createAuthorizationURL(e,n){const r=new URL($k);return r.searchParams.set("response_type","code"),r.searchParams.set("client_id",this.clientId),r.searchParams.set("state",e),n.length>0&&r.searchParams.set("scope",n.join(" ")),r.searchParams.set("redirect_uri",this.redirectURI),r}async validateAuthorizationCode(e){const n=new URLSearchParams;n.set("grant_type","authorization_code"),n.set("code",e),n.set("redirect_uri",this.redirectURI),n.set("client_id",this.clientId),n.set("client_secret",this.clientSecret);const r=gr(kk,n);return await Ea(r)}}const xk="https://github.com/login/oauth/authorize",dg="https://github.com/login/oauth/access_token";class e1{constructor(e,n,r){se(this,"clientId");se(this,"clientSecret");se(this,"redirectURI");this.clientId=e,this.clientSecret=n,this.redirectURI=r}createAuthorizationURL(e,n){const r=new URL(xk);return r.searchParams.set("response_type","code"),r.searchParams.set("client_id",this.clientId),r.searchParams.set("state",e),n.length>0&&r.searchParams.set("scope",n.join(" ")),this.redirectURI!==null&&r.searchParams.set("redirect_uri",this.redirectURI),r}async validateAuthorizationCode(e){const n=new URLSearchParams;n.set("grant_type","authorization_code"),n.set("code",e),this.redirectURI!==null&&n.set("redirect_uri",this.redirectURI);const r=gr(dg,n),i=eo(this.clientId,this.clientSecret);return r.headers.set("Authorization",`Basic ${i}`),await ug(r)}async refreshAccessToken(e){const n=new URLSearchParams;n.set("grant_type","refresh_token"),n.set("refresh_token",e);const r=gr(dg,n),i=eo(this.clientId,this.clientSecret);return r.headers.set("Authorization",`Basic ${i}`),await ug(r)}}async function ug(t){let e;try{e=await fetch(t)}catch(i){throw new Sp(i)}if(e.status!==200)throw e.body!==null&&await e.body.cancel(),new Zr(e.status);let n;try{n=await e.json()}catch{throw new Zr(e.status)}if(typeof n!="object"||n===null)throw new Kn(e.status,n);if("error"in n&&typeof n.error=="string"){let i;try{i=xp(n)}catch{throw new Kn(e.status,n)}throw i}return new Xy(n)}const Sk="https://accounts.google.com/o/oauth2/v2/auth",pg="https://oauth2.googleapis.com/token",zk="https://oauth2.googleapis.com/revoke";let t1=class{constructor(e,n,r){se(this,"client");this.client=new Fc(e,n,r)}createAuthorizationURL(e,n,r){return this.client.createAuthorizationURLWithPKCE(Sk,e,mi.S256,n,r)}async validateAuthorizationCode(e,n){return await this.client.validateAuthorizationCode(pg,e,n)}async refreshAccessToken(e){return await this.client.refreshAccessToken(pg,e,[])}async revokeToken(e){await this.client.revokeToken(zk,e)}};class n1{constructor(e,n,r,i){se(this,"authorizationEndpoint");se(this,"tokenEndpoint");se(this,"client");this.authorizationEndpoint=sg("https://login.microsoftonline.com",e,"/oauth2/v2.0/authorize"),this.tokenEndpoint=sg("https://login.microsoftonline.com",e,"/oauth2/v2.0/token"),this.client=new Fc(n,r,i)}createAuthorizationURL(e,n,r){return this.client.createAuthorizationURLWithPKCE(this.authorizationEndpoint,e,mi.S256,n,r)}async validateAuthorizationCode(e,n){return await this.client.validateAuthorizationCode(this.tokenEndpoint,e,n)}async refreshAccessToken(e,n){return await this.client.refreshAccessToken(this.tokenEndpoint,e,n)}}const Wo=o.z.object({iss:o.z.string().url(),sub:o.z.string(),aud:o.z.string(),exp:o.z.number(),email:o.z.string().optional(),given_name:o.z.string().optional(),family_name:o.z.string().optional(),name:o.z.string().optional(),iat:o.z.number(),auth_time:o.z.number().optional(),nonce:o.z.string().optional(),acr:o.z.string().optional(),amr:o.z.array(o.z.string()).optional(),azp:o.z.string().optional(),at_hash:o.z.string().optional(),c_hash:o.z.string().optional()}).passthrough();Wo.omit({iat:!0,auth_time:!0,nonce:!0,acr:!0,amr:!0,azp:!0,at_hash:!0,c_hash:!0});const Ak="Apple",Ek=({className:t=""})=>p("svg",{width:"45",height:"45",viewBox:"0 0 45 45",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:t,children:[p("path",{d:"M45 0H0V45H45V0Z",fill:"white"}),p("path",{d:"M23.5344 10.3846C25.5313 10.3846 28.0344 9.01144 29.525 7.18055C30.875 5.5213 31.8594 3.20407 31.8594 0.886839C31.8594 0.572154 31.8313 0.25747 31.775 0C29.5531 0.0858233 26.8813 1.51621 25.2781 3.43293C24.0125 4.89193 22.8594 7.18055 22.8594 9.52638C22.8594 9.86968 22.9156 10.213 22.9438 10.3274C23.0844 10.356 23.3094 10.3846 23.5344 10.3846ZM16.5031 45C19.2313 45 20.4406 43.1405 23.8438 43.1405C27.3031 43.1405 28.0625 44.9428 31.1 44.9428C34.0813 44.9428 36.0781 42.1392 37.9625 39.3929C40.0719 36.246 40.9438 33.1564 41 33.0134C40.8031 32.9561 35.0938 30.5817 35.0938 23.9161C35.0938 18.1373 39.5938 15.534 39.8469 15.3338C36.8656 10.9854 32.3375 10.8709 31.1 10.8709C27.7531 10.8709 25.025 12.9307 23.3094 12.9307C21.4531 12.9307 19.0063 10.9854 16.1094 10.9854C10.5969 10.9854 5 15.6198 5 24.3738C5 29.8093 7.08125 35.5594 9.64063 39.2784C11.8344 42.4253 13.7469 45 16.5031 45Z",fill:"black"})]});function r1(t){const{options:e}=t;if(!e||!e.client_id||!e.team_id||!e.kid||!e.app_secret)throw new Error("Missing required Apple authentication parameters");const n=Buffer.from(e.app_secret,"utf-8"),r=n.toString().replace(/-----BEGIN PRIVATE KEY-----|-----END PRIVATE KEY-----|\s/g,""),i=Uint8Array.from(Buffer.from(r,"base64"));return n.fill(0),{options:e,keyArray:i}}async function Ck(t,e){var d,u;const{options:n,keyArray:r}=r1(e),i=`${qe(t.env)}callback`,s=new Yy(n.client_id,n.team_id,n.kid,r,i),a=Ce(),c=await s.createAuthorizationURL(a,((d=n.scope)==null?void 0:d.split(" "))||["name","email"]);return(((u=n.scope)==null?void 0:u.split(" "))||["name","email"]).some(f=>["email","name"].includes(f))&&c.searchParams.set("response_mode","form_post"),{redirectUrl:c.href,code:a}}async function Nk(t,e,n){const{options:r,keyArray:i}=r1(e),a=await new Yy(r.client_id,r.team_id,r.kid,i,`${qe(t.env)}callback`).validateAuthorizationCode(n),c=Ua(a.idToken());if(!c)throw new Error("Invalid ID token");const l=Wo.parse(c.payload);return{sub:l.sub,email:l.email,given_name:l.given_name,family_name:l.family_name,name:l.name,picture:l.picture,locale:l.locale}}const i1=Object.freeze(Object.defineProperty({__proto__:null,displayName:Ak,getRedirect:Ck,logo:Ek,validateAuthorizationCodeAndGetUser:Nk},Symbol.toStringTag,{value:"Module"})),Ik="Facebook",jk=({className:t=""})=>p("svg",{width:"45",height:"45",viewBox:"0 0 45 45",xmlns:"http://www.w3.org/2000/svg",className:t,children:[p("path",{d:"M45 22.5C45 10.0736 34.9264 0 22.5 0C10.0736 0 0 10.0736 0 22.5C0 33.7031 8.23242 42.9785 19.0039 44.6953V28.9746H13.2861V22.5H19.0039V17.5391C19.0039 11.8945 22.3828 8.75977 27.5391 8.75977C29.9658 8.75977 32.5049 9.19922 32.5049 9.19922V14.7656H29.7012C26.9414 14.7656 26.0156 16.4824 26.0156 18.2432V22.5H32.2412L31.2012 28.9746H26.0156V44.6953C36.7871 42.9785 45 33.7031 45 22.5Z",fill:"#1877F2"}),p("path",{d:"M31.2012 28.9746L32.2412 22.5H26.0156V18.2432C26.0156 16.4824 26.9414 14.7656 29.7012 14.7656H32.5049V9.19922C32.5049 9.19922 29.9658 8.75977 27.5391 8.75977C22.3828 8.75977 19.0039 11.8945 19.0039 17.5391V22.5H13.2861V28.9746H19.0039V44.6953C20.1562 44.8984 21.3203 45 22.5 45C23.6797 45 24.8438 44.8984 26.0156 44.6953V28.9746H31.2012Z",fill:"white"})]});async function Ok(t,e){var c;const{options:n}=e;if(!(n!=null&&n.client_id)||!n.client_secret)throw new Error("Missing required authentication parameters");const r=`${qe(t.env)}callback`,i=new Qy(n.client_id,n.client_secret,r),s=Ce();return{redirectUrl:i.createAuthorizationURL(s,((c=n.scope)==null?void 0:c.split(" "))||["email"]).href,code:s}}async function Tk(t,e,n){const{options:r}=e;if(!(r!=null&&r.client_id)||!r.client_secret)throw new Error("Missing required authentication parameters");const s=await new Qy(r.client_id,r.client_secret,`${qe(t.env)}callback`).validateAuthorizationCode(n),a=await fetch("https://graph.facebook.com/v22.0/me?fields=id,email,name",{headers:{Authorization:`Bearer ${s.accessToken()}`}});if(!a.ok)throw new Error("Failed to fetch user info");const c=await a.json();return t.set("log",`Userinfo: ${JSON.stringify(c)}`),{sub:c.id,email:c.email,name:c.name}}const o1=Object.freeze(Object.defineProperty({__proto__:null,displayName:Ik,getRedirect:Ok,logo:jk,validateAuthorizationCodeAndGetUser:Tk},Symbol.toStringTag,{value:"Module"})),Pk="Google",Rk=({className:t=""})=>p("svg",{width:"45",height:"45",viewBox:"0 0 45 45",xmlns:"http://www.w3.org/2000/svg",className:t,children:[p("path",{d:"M44.1035 23.0123C44.1054 21.4791 43.9758 19.9486 43.716 18.4375H22.498V27.1028H34.6507C34.4021 28.4868 33.8757 29.8061 33.1034 30.9812C32.3311 32.1562 31.3289 33.1628 30.1571 33.9401V39.5649H37.41C41.6567 35.6494 44.1035 29.859 44.1035 23.0123Z",fill:"#4285F4"}),p("path",{d:"M22.4982 44.9997C28.5698 44.9997 33.6821 43.0061 37.4101 39.5687L30.1573 33.9439C28.1386 35.3126 25.5387 36.0938 22.4982 36.0938C16.6296 36.0938 11.6485 32.1377 9.86736 26.8066H2.39575V32.6033C4.26839 36.3297 7.13989 39.4622 10.6896 41.6512C14.2394 43.8402 18.3277 44.9995 22.4982 44.9997Z",fill:"#34A853"}),p("path",{d:"M9.86737 26.8073C8.92572 24.0138 8.92572 20.9886 9.86737 18.1951V12.3984H2.39576C0.820432 15.5332 0 18.9929 0 22.5012C0 26.0095 0.820432 29.4692 2.39576 32.604L9.86737 26.8073Z",fill:"#FBBC04"}),p("path",{d:"M22.4982 8.90741C25.7068 8.85499 28.8071 10.0673 31.1291 12.2823L37.5507 5.86064C33.4788 2.03602 28.0843 -0.0637686 22.4982 0.00147616C18.3277 0.00166623 14.2394 1.16098 10.6896 3.34999C7.13989 5.539 4.26839 8.67155 2.39575 12.3979L9.86736 18.1946C11.6485 12.8635 16.6296 8.90741 22.4982 8.90741Z",fill:"#EA4335"})]});async function Bk(t,e){var l;const{options:n}=e;if(!(n!=null&&n.client_id)||!n.client_secret)throw new Error("Missing required Google authentication parameters");const r=`${qe(t.env)}callback`,i=new t1(n.client_id,n.client_secret,r),s=Ce(),a=Zy();return{redirectUrl:i.createAuthorizationURL(s,a,((l=n.scope)==null?void 0:l.split(" "))??["email","profile"]).href,code:s,codeVerifier:a}}async function Lk(t,e,n,r){const{options:i}=e;if(!(i!=null&&i.client_id)||!i.client_secret||!r)throw new Error("Missing required authentication parameters");const a=await new t1(i.client_id,i.client_secret,`${qe(t.env)}callback`).validateAuthorizationCode(n,r),c=Ua(a.idToken());if(!c)throw new Error("Invalid ID token");const l=Wo.parse(c.payload);return{sub:l.sub,email:l.email,given_name:l.given_name,family_name:l.family_name,name:l.name,picture:l.picture,locale:l.locale}}const s1=Object.freeze(Object.defineProperty({__proto__:null,displayName:Pk,getRedirect:Bk,logo:Rk,validateAuthorizationCodeAndGetUser:Lk},Symbol.toStringTag,{value:"Module"})),Uk="Vipps",Dk=({className:t=""})=>p("svg",{version:"1.1",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 48 48",width:"45",height:"45",className:t,children:[p("path",{fill:"#FF5B24",d:"M3.5,8h41c1.9,0,3.5,1.6,3.5,3.5v25c0,1.9-1.6,3.5-3.5,3.5h-41C1.6,40,0,38.4,0,36.5v-25C0,9.6,1.6,8,3.5,8z"}),p("path",{fillRule:"evenodd",clipRule:"evenodd",fill:"#FFFFFF",d:`M27.9,20.3c1.4,0,2.6-1,2.6-2.5h0c0-1.5-1.2-2.5-2.6-2.5c-1.4,0-2.6,1-2.6,2.5C25.3,19.2,26.5,20.3,27.9,20.3z
|
|
193
193
|
M31.2,24.4c-1.7,2.2-3.5,3.8-6.7,3.8h0c-3.2,0-5.8-2-7.7-4.8c-0.8-1.2-2-1.4-2.9-0.8c-0.8,0.6-1,1.8-0.3,2.9
|
|
194
194
|
c2.7,4.1,6.5,6.6,10.9,6.6c4,0,7.2-2,9.6-5.2c0.9-1.2,0.9-2.5,0-3.1C33.3,22.9,32.1,23.2,31.2,24.4z`})]});async function Mk(t,e){var a;const{options:n}=e;if(!(n!=null&&n.client_id)||!n.client_secret)throw new Error("Missing required authentication parameters");const r=new Fc(n.client_id,n.client_secret,`${qe(t.env)}callback`),i=Ce(),s=r.createAuthorizationURL("https://api.vipps.no/access-management-1.0/access/oauth2/auth",i,((a=n.scope)==null?void 0:a.split(" "))||["openid","email","phoneNumber","name","address","birthDate"]);return s.searchParams.set("response_type","code"),s.searchParams.set("response_mode","query"),{redirectUrl:s.href,code:i}}async function Fk(t,e,n){const{options:r}=e;if(!(r!=null&&r.client_id)||!r.client_secret)throw new Error("Missing required authentication parameters");const s=await new Fc(r.client_id,r.client_secret,`${qe(t.env)}callback`).validateAuthorizationCode("https://api.vipps.no/access-management-1.0/access/oauth2/token",n,null),a=Ua(s.idToken());if(!a)throw new Error("Invalid ID token");const c=Wo.parse(a.payload);if(typeof c.msn!="string")throw new Error("msn not available in id token");const l=await fetch("https://api.vipps.no/vipps-userinfo-api/userinfo",{headers:{Authorization:`Bearer ${s.accessToken()}`,"Merchant-Serial-Number":c.msn}});if(!l.ok)throw new b(400,{message:"Failed to get user from vipps"});return await l.json()}const a1=Object.freeze(Object.defineProperty({__proto__:null,displayName:Uk,getRedirect:Mk,logo:Dk,validateAuthorizationCodeAndGetUser:Fk},Symbol.toStringTag,{value:"Module"})),qk="GitHub",Hk=({className:t=""})=>p("svg",{width:"45",height:"45",viewBox:"0 0 45 45",xmlns:"http://www.w3.org/2000/svg",className:t,children:p("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M22.5 0C10.074 0 0 10.335 0 23.077C0 33.266 6.444 41.895 15.39 44.955C16.515 45.165 16.935 44.46 16.935 43.857C16.935 43.32 16.92 41.865 16.905 39.99C10.65 41.355 9.33 36.99 9.33 36.99C8.31 34.32 6.825 33.615 6.825 33.615C4.77 32.205 6.975 32.235 6.975 32.235C9.24 32.385 10.425 34.59 10.425 34.59C12.45 38.13 15.75 37.125 17.01 36.555C17.22 35.07 17.82 34.065 18.48 33.51C13.455 32.94 8.19 30.93 8.19 22.035C8.19 19.5 9.075 17.43 10.47 15.81C10.23 15.24 9.435 12.87 10.695 9.66C10.695 9.66 12.585 9.045 16.875 12.06C18.675 11.565 20.595 11.31 22.5 11.31C24.405 11.31 26.325 11.565 28.125 12.06C32.415 9.045 34.305 9.66 34.305 9.66C35.565 12.87 34.77 15.24 34.53 15.81C35.925 17.43 36.81 19.5 36.81 22.035C36.81 30.96 31.53 32.925 26.49 33.48C27.33 34.2 28.095 35.625 28.095 37.815C28.095 40.95 28.065 43.47 28.065 43.857C28.065 44.46 28.485 45.18 29.625 44.955C38.571 41.88 45 33.252 45 23.077C45 10.335 34.926 0 22.5 0Z",fill:"currentColor"})});async function Vk(t,e){var c;const{options:n}=e;if(!(n!=null&&n.client_id)||!n.client_secret)throw new Error("Missing required GitHub authentication parameters");const r=`${qe(t.env)}callback`,i=new e1(n.client_id,n.client_secret,r),s=Ce();return{redirectUrl:i.createAuthorizationURL(s,((c=n.scope)==null?void 0:c.split(" "))||["user:email"]).href,code:s}}async function Kk(t,e,n){var u,f;const{options:r}=e;if(!(r!=null&&r.client_id)||!r.client_secret)throw new Error("Missing required authentication parameters");const s=await new e1(r.client_id,r.client_secret,`${qe(t.env)}callback`).validateAuthorizationCode(n),a=await fetch("https://api.github.com/user",{headers:{Authorization:`Bearer ${s.accessToken()}`,"User-Agent":"AuthHero"}});if(!a.ok)throw new Error("Failed to fetch user info");const c=await a.json(),l=await fetch("https://api.github.com/user/emails",{headers:{Authorization:`Bearer ${s.accessToken()}`,"User-Agent":"AuthHero"}});let d=c.email;if(l.ok){const h=await l.json(),m=h.find(y=>y.primary&&y.verified)||h.find(y=>y.verified);m&&(d=m.email)}return t.set("log",`GitHub user: ${JSON.stringify(c)}`),{sub:c.id.toString(),email:d,name:c.name,given_name:(u=c.name)==null?void 0:u.split(" ")[0],family_name:(f=c.name)==null?void 0:f.split(" ").slice(1).join(" "),picture:c.avatar_url}}const c1=Object.freeze(Object.defineProperty({__proto__:null,displayName:qk,getRedirect:Vk,logo:Hk,validateAuthorizationCodeAndGetUser:Kk},Symbol.toStringTag,{value:"Module"})),Gk="Microsoft",Wk=({className:t=""})=>p("svg",{width:"45",height:"45",viewBox:"0 0 45 45",xmlns:"http://www.w3.org/2000/svg",className:t,children:[p("path",{fill:"#F25022",d:"M0 0H21.43V21.43H0V0Z"}),p("path",{fill:"#7FBA00",d:"M23.57 0H45V21.43H23.57V0Z"}),p("path",{fill:"#00A4EF",d:"M0 23.57H21.43V45H0V23.57Z"}),p("path",{fill:"#FFB900",d:"M23.57 23.57H45V45H23.57V23.57Z"})]});async function Jk(t,e){var d;const{options:n}=e;if(!(n!=null&&n.client_id)||!n.client_secret)throw new Error("Missing required Microsoft authentication parameters");const r=`${qe(t.env)}callback`,i=n.realms||"common",s=new n1(i,n.client_id,n.client_secret,r),a=Ce(),c=Zy();return{redirectUrl:s.createAuthorizationURL(a,c,((d=n.scope)==null?void 0:d.split(" "))||["openid","profile","email"]).href,code:a,codeVerifier:c}}async function Xk(t,e,n,r){const{options:i}=e;if(!(i!=null&&i.client_id)||!i.client_secret||!r)throw new Error("Missing required authentication parameters");const s=i.realms||"common",c=await new n1(s,i.client_id,i.client_secret,`${qe(t.env)}callback`).validateAuthorizationCode(n,r),l=Ua(c.idToken());if(!l)throw new Error("Invalid ID token");const d=Wo.parse(l.payload);return t.set("log",`Microsoft user: ${JSON.stringify(d)}`),{sub:d.sub,email:d.email,given_name:d.given_name,family_name:d.family_name,name:d.name,picture:d.picture}}const l1=Object.freeze(Object.defineProperty({__proto__:null,displayName:Gk,getRedirect:Jk,logo:Wk,validateAuthorizationCodeAndGetUser:Xk},Symbol.toStringTag,{value:"Module"}));function d1(t,e){const n=t.env.STRATEGIES||{},i={apple:i1,facebook:o1,"google-oauth2":s1,vipps:a1,github:c1,microsoft:l1,...n}[e];if(!i)throw new Error(`Strategy ${e} not found`);return i}function u1(t){return{apple:i1,facebook:o1,"google-oauth2":s1,vipps:a1,github:c1,microsoft:l1}[t]}async function Oi(t,e){const n=await t.data.legacyClients.get(e);if(!n)throw new b(403,{message:"Client not found"});let r=n;if(t.DEFAULT_CLIENT_ID||t.DEFAULT_TENANT_ID){const i=t.DEFAULT_CLIENT_ID?await t.data.legacyClients.get(t.DEFAULT_CLIENT_ID):void 0,s=await t.data.connections.list(n.tenant.id),a=t.DEFAULT_TENANT_ID?await t.data.connections.list(t.DEFAULT_TENANT_ID):{connections:[]},c=s.connections.map(l=>{var f;const d=(f=a.connections)==null?void 0:f.find(h=>h.name===l.name);if(!(d!=null&&d.options))return l;const u=Vt.parse({...d||{},...l});return u.options=Gr.passthrough().parse({...d.options||{},...l.options}),u}).filter(l=>l);r={...n,web_origins:[...(i==null?void 0:i.web_origins)||[],...n.web_origins||[]],allowed_logout_urls:[...(i==null?void 0:i.allowed_logout_urls)||[],...n.allowed_logout_urls||[]],callbacks:[...(i==null?void 0:i.callbacks)||[],...n.callbacks||[]],connections:c,tenant:{...(i==null?void 0:i.tenant)||{},...n.tenant}}}return{...r,web_origins:[...r.web_origins||[],`${ot(t)}login`],allowed_logout_urls:[...r.allowed_logout_urls||[],t.ISSUER],callbacks:[...r.callbacks||[],`${ot(t)}info`]}}async function fg(t,e,n,r){if(!r.state)throw new b(400,{message:"State not found"});const i=e.connections.find(l=>l.name===n);if(!i){t.set("client_id",e.client_id);const l=ve(t,{type:me.FAILED_LOGIN,description:"Connection not found"});throw we(t,t.env.data.logs.create(e.tenant.id,l)),new b(403,{message:"Connection Not Found"})}let s=await t.env.data.loginSessions.get(e.tenant.id,r.state);if(!s){const l=t.get("ip"),d=t.get("useragent"),u=t.get("auth0_client");s=await t.env.data.loginSessions.create(e.tenant.id,{expires_at:new Date(Date.now()+mr*1e3).toISOString(),authParams:r,csrf_token:Ce(),ip:l,useragent:d,auth0Client:Cn(u)})}const c=await d1(t,i.strategy).getRedirect(t,i);return await t.env.data.codes.create(e.tenant.id,{login_id:s.id,code_id:c.code,code_type:"oauth2_state",connection_id:i.id,code_verifier:c.codeVerifier,expires_at:new Date(Date.now()+xv*1e3).toISOString()}),new Response(null,{status:302,headers:{location:c.redirectUrl}})}async function hg(t,{code:e,state:n}){var y;const{env:r}=t,i=await r.data.codes.get(t.var.tenant_id||"",n,"oauth2_state");if(!i||!i.connection_id)throw new b(403,{message:"State not found"});const s=await r.data.loginSessions.get(t.var.tenant_id||"",i.login_id);if(!s)throw new b(403,{message:"Session not found"});if(s.authorization_url){const v=new URL(s.authorization_url).hostname,$=t.var.host||"";if(v!==$&&v){const A=new URL(`https://${v}/callback`);return A.searchParams.set("state",n),A.searchParams.set("code",e),new Response("Redirecting",{status:307,headers:{location:A.toString()}})}}const a=await Oi(r,s.authParams.client_id);t.set("client_id",a.client_id),t.set("tenant_id",a.tenant.id);const c=a.connections.find(v=>v.id===i.connection_id);if(!c){const v=ve(t,{type:me.FAILED_LOGIN,description:"Connection not found"});throw we(t,r.data.logs.create(a.tenant.id,v)),new b(403,{message:"Connection not found"})}if(t.set("connection",c.name),!s.authParams.redirect_uri){const v=ve(t,{type:me.FAILED_LOGIN,description:"Redirect URI not defined"});throw we(t,r.data.logs.create(a.tenant.id,v)),new b(403,{message:"Redirect URI not defined"})}const d=await d1(t,c.strategy).validateAuthorizationCodeAndGetUser(t,c,e,i.code_verifier),{sub:u,...f}=d;t.set("user_id",u);const h=((y=d.email)==null?void 0:y.toLocaleLowerCase())||`${c.name}.${u}@${new URL(t.env.ISSUER).hostname}`;t.set("username",h);const m=await qa(t,{client:a,username:h,provider:c.strategy,connection:c.name,userId:u,profileData:f,isSocial:!0,ip:t.var.ip});return dn(t,{client:a,authParams:s.authParams,loginSession:s,user:m,strategy:c.strategy})}async function gg(t,e,n,r,i,s){const a=await t.env.data.codes.get(t.var.tenant_id||"",e,"oauth2_state");if(!a)throw new b(400,{message:"State not found"});const c=await t.env.data.loginSessions.get(t.var.tenant_id,a.login_id);if(!c)throw new b(400,{message:"Login not found"});const{redirect_uri:l}=c.authParams;if(!l)throw new b(400,{message:"Redirect uri not found"});const d=ve(t,{type:me.FAILED_LOGIN,description:`Failed connection login: ${i} ${n}, ${r}`});we(t,t.env.data.logs.create(t.var.tenant_id,d));const u=new URL(l);return F4(u,{error:n,error_description:r,error_reason:s,error_code:i,state:c.authParams.state}),t.redirect(`${ot(t.env)}login/identifier?state=${c.id}&error=${n}`)}const Zk=new o.OpenAPIHono().openapi(o.createRoute({tags:["oauth2"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string(),code:o.z.string().optional(),scope:o.z.string().optional(),hd:o.z.string().optional(),error:o.z.string().optional(),error_description:o.z.string().optional(),error_code:o.z.string().optional(),error_reason:o.z.string().optional()})},responses:{302:{description:"Redirect to the client's redirect uri"},400:{description:"Bad Request",content:{"application/json":{schema:o.z.object({message:o.z.string()})}}},500:{description:"Internal Server Error",content:{"application/json":{schema:o.z.object({message:o.z.string()})}}}}}),async t=>{const{state:e,code:n,error:r,error_description:i,error_code:s,error_reason:a}=t.req.valid("query");if(r)return gg(t,e,r,i,s,a);if(!n)throw new b(400,{message:"Code is required"});const c=await hg(t,{code:n,state:e});if(!(c instanceof Response))throw new b(500,{message:"Internal server error"});return c}).openapi(o.createRoute({tags:["oauth2"],method:"post",path:"/",request:{body:{content:{"application/x-www-form-urlencoded":{schema:o.z.object({state:o.z.string(),code:o.z.string().optional(),scope:o.z.string().optional(),hd:o.z.string().optional(),error:o.z.string().optional(),error_description:o.z.string().optional(),error_code:o.z.string().optional(),error_reason:o.z.string().optional()})}}}},responses:{302:{description:"Redirect to the client's redirect uri"},400:{description:"Bad Request",content:{"application/json":{schema:o.z.object({message:o.z.string()})}}},500:{description:"Internal Server Error",content:{"application/json":{schema:o.z.object({message:o.z.string()})}}}}}),async t=>{const{state:e,code:n,error:r,error_description:i,error_code:s,error_reason:a}=t.req.valid("form");if(r)return gg(t,e,r,i,s,a);if(!n)throw new b(400,{message:"Code is required"});const c=await hg(t,{code:n,state:e});if(!(c instanceof Response))throw new b(500,{message:"Internal server error"});return c});function zp(t,e=[],n={}){try{const r=new URL(t);return e.some(i=>{try{return Yk(r,new URL(i),n)}catch{return!1}})}catch{return!1}}function Yk(t,e,n={}){if(t.protocol!==e.protocol)return!1;if(n.allowPathWildcards&&e.pathname.includes("*")){const r=e.pathname.replace(/\*/g,".*").replace(/\//g,"\\/");if(!new RegExp(`^${r}$`).test(t.pathname))return!1}else if(t.pathname!==e.pathname)return!1;if(n.allowSubDomainWildcards&&e.hostname.startsWith("*.")&&e.hostname.split(".").length>2&&["http:","https:"].includes(e.protocol)){const r=e.hostname.split(".").slice(1).join(".");return t.hostname===r||t.hostname.endsWith("."+r)}return t.hostname===e.hostname}const Qk=new o.OpenAPIHono().openapi(o.createRoute({tags:["oauth2"],method:"get",path:"/",request:{query:o.z.object({client_id:o.z.string(),returnTo:o.z.string().optional()}),header:o.z.object({cookie:o.z.string().optional()})},responses:{302:{description:"Log the user out"}}}),async t=>{const{client_id:e,returnTo:n}=t.req.valid("query"),r=await t.env.data.legacyClients.get(e);if(!r)return t.text("OK");const i=await t.env.data.legacyClients.get("DEFAULT_CLIENT");t.set("client_id",e),t.set("tenant_id",r.tenant.id);const s=n||t.req.header("referer");if(!s)return t.text("OK");if(!zp(s,[...r.allowed_logout_urls||[],...(i==null?void 0:i.allowed_logout_urls)||[]],{allowPathWildcards:!0,allowSubDomainWildcards:!0}))throw new b(400,{message:"Invalid redirect uri"});const a=t.req.header("cookie");if(a){const l=ti(r.tenant.id,a);if(l){const d=await t.env.data.sessions.get(r.tenant.id,l);if(d){const u=await t.env.data.users.get(r.tenant.id,d.user_id);u&&(t.set("user_id",u.user_id),t.set("connection",u.connection));const f=await t.env.data.refreshTokens.list(r.tenant.id,{q:`session_id=${l}`,page:0,per_page:100,include_totals:!1});await Promise.all(f.refresh_tokens.map(h=>t.env.data.refreshTokens.remove(r.tenant.id,h.id))),await t.env.data.sessions.update(r.tenant.id,l,{revoked_at:new Date().toISOString()})}}}const c=ve(t,{type:me.SUCCESS_LOGOUT,description:"User successfully logged out"});return we(t,t.env.data.logs.create(r.tenant.id,c)),new Response("Redirecting",{status:302,headers:{"set-cookie":Cv(r.tenant.id,t.req.header("host")),location:s}})}),mg=o.z.object({sub:o.z.string(),email:o.z.string().optional(),family_name:o.z.string().optional(),given_name:o.z.string().optional(),email_verified:o.z.boolean()}),e5=new o.OpenAPIHono().openapi(o.createRoute({tags:["oauth2"],method:"get",path:"/",request:{},security:[{Bearer:["openid"]}],responses:{200:{content:{"application/json":{schema:mg}},description:"Userinfo"}}}),async t=>{if(!t.var.user)throw new b(404,{message:"User not found"});const e=await t.env.data.users.get(t.var.user.tenant_id,t.var.user.sub);if(!e)throw new b(404,{message:"User not found"});return t.json(mg.parse({...e,sub:e.user_id}))}),t5=new o.OpenAPIHono().openapi(o.createRoute({tags:["well known"],method:"get",path:"/jwks.json",request:{},responses:{200:{content:{"application/json":{schema:D0}},description:"List of tenants"}}}),async t=>{const e=await Qd(t.env.data);return t.json({keys:e},{headers:{"access-control-allow-origin":"*","access-control-allow-method":"GET","cache-control":`public, max-age=${rs}, stale-while-revalidate=${rs*2}, stale-if-error=86400`}})}).openapi(o.createRoute({tags:["well known"],method:"get",path:"/openid-configuration",request:{},responses:{200:{content:{"application/json":{schema:xl}},description:"List of tenants"}}}),async t=>{const e=xl.parse({issuer:Bc(t.env),authorization_endpoint:`${qe(t.env)}authorize`,token_endpoint:`${qe(t.env)}oauth/token`,device_authorization_endpoint:`${qe(t.env)}oauth/device/code`,userinfo_endpoint:`${qe(t.env)}userinfo`,mfa_challenge_endpoint:`${qe(t.env)}mfa/challenge`,jwks_uri:`${qe(t.env)}.well-known/jwks.json`,registration_endpoint:`${qe(t.env)}oidc/register`,revocation_endpoint:`${qe(t.env)}oauth/revoke`,scopes_supported:["openid","profile","offline_access","name","given_name","family_name","nickname","email","email_verified","picture","created_at","identities","phone","address"],response_types_supported:["code","token","id_token","code token","code id_token","token id_token","code token id_token"],code_challenge_methods_supported:["S256","plain"],response_modes_supported:["query","fragment","form_post"],subject_types_supported:["public"],id_token_signing_alg_values_supported:["RS256"],token_endpoint_auth_methods_supported:["client_secret_basic","client_secret_post"],claims_supported:["aud","auth_time","created_at","email","email_verified","exp","family_name","given_name","iat","identities","iss","name","nickname","phone_number","picture","sub"],request_uri_parameter_supported:!1,request_parameter_supported:!1,token_endpoint_auth_signing_alg_values_supported:["RS256","RS384","PS256"]});return t.json(e,{headers:{"access-control-allow-origin":"*","access-control-allow-method":"GET","cache-control":`public, max-age=${rs}, stale-while-revalidate=${rs*2}, stale-if-error=86400`}})});function $s(t,e){if(!t||!e||t.length!==e.length)return!1;let n=0;for(let r=0;r<t.length;r++)n|=t.charCodeAt(r)^e.charCodeAt(r);return n===0}const p1=o.z.object({grant_type:o.z.literal("client_credentials"),scope:o.z.string().optional(),client_secret:o.z.string(),client_id:o.z.string(),audience:o.z.string().optional()});async function n5(t,e){const n=await t.env.data.legacyClients.get(e.client_id);if(!n)throw new b(403,{message:"Invalid client credentials"});if(n.client_secret&&!$s(n.client_secret,e.client_secret))throw new b(403,{message:"Invalid client credentials"});const r={client_id:n.client_id,scope:e.scope,audience:e.audience};return{client:n,authParams:r}}const r5=o.z.object({grant_type:o.z.literal("authorization_code"),client_id:o.z.string(),code:o.z.string(),redirect_uri:o.z.string().optional(),client_secret:o.z.string().optional(),code_verifier:o.z.string().optional(),organization:o.z.string().optional()}).refine(t=>"client_secret"in t&&!("code_verifier"in t)||!("client_secret"in t)&&"code_verifier"in t,{message:"Must provide either client_secret (standard flow) or code_verifier/code_verifier_mode (PKCE flow), but not both"});async function i5(t,e){var l;const n=await t.env.data.legacyClients.get(e.client_id);if(!n)throw new b(403,{message:"Client not found"});const r=await t.env.data.codes.get(n.tenant.id,e.code,"authorization_code");if(!r||!r.user_id){const d=ve(t,{type:me.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN,description:"Invalid client credentials"});throw we(t,t.env.data.logs.create(n.tenant.id,d)),new b(403,{message:"Invalid client credentials"})}else if(new Date(r.expires_at)<new Date){const d=ve(t,{type:me.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN,description:"Code expired",userId:r.user_id});throw we(t,t.env.data.logs.create(n.tenant.id,d)),new b(403,{message:"Code expired"})}else if(r.used_at){const d=ve(t,{type:me.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN,description:"Invalid authorization code",userId:r.user_id});throw we(t,t.env.data.logs.create(n.tenant.id,d)),new ni(403,{error:"invalid_grant",error_description:"Invalid authorization code"})}const i=await t.env.data.loginSessions.get(n.tenant.id,r.login_id);if(!i)throw new b(403,{message:"Invalid login"});if(e.organization&&i.authParams.organization&&e.organization!==i.authParams.organization)throw new ni(400,{error:"invalid_request",error_description:"Organization parameter does not match login session organization"});if("client_secret"in e){const d=await t.env.data.legacyClients.get("DEFAULT_CLIENT");if(!$s(n.client_secret,e.client_secret)&&!$s(d==null?void 0:d.client_secret,e.client_secret)){const u=ve(t,{type:me.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN,description:"Invalid client credentials",userId:r.user_id});throw we(t,t.env.data.logs.create(n.tenant.id,u)),new b(403,{message:"Invalid client credentials"})}}else if(r.code_challenge&&r.code_challenge_method&&e.code_verifier){const d=await bv(e.code_verifier,r.code_challenge_method);if(!$s(d,r.code_challenge)){const u=ve(t,{type:me.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN,description:"Invalid client credentials",userId:r.user_id});throw we(t,t.env.data.logs.create(n.tenant.id,u)),new b(403,{message:"Invalid client credentials"})}}if(r.redirect_uri&&r.redirect_uri!==e.redirect_uri){const d=ve(t,{type:me.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN,description:"Invalid redirect uri",userId:r.user_id});throw we(t,t.env.data.logs.create(n.tenant.id,d)),new b(403,{message:"Invalid redirect uri"})}const s=await t.env.data.users.get(n.tenant.id,r.user_id);if(!s)throw new b(403,{message:"User not found"});await t.env.data.codes.used(n.tenant.id,e.code);let a;i.session_id&&((l=i.authParams.scope)!=null&&l.split(" ").includes("offline_access"))&&(a=await Tm(t,{user:s,client:n,session_id:i.session_id,scope:i.authParams.scope,audience:i.authParams.audience}));let c;if(i.authParams.organization){const d=await t.env.data.organizations.get(n.tenant.id,i.authParams.organization);d?c={id:d.id,name:d.name}:c={id:i.authParams.organization,name:"Unknown"}}return{user:s,client:n,loginSession:i,session_id:i.session_id,refresh_token:a==null?void 0:a.id,organization:c,authParams:{...i.authParams,state:r.state,nonce:r.nonce,response_mode:Gt.WEB_MESSAGE,client_id:n.client_id,scope:i.authParams.scope,audience:i.authParams.audience}}}const o5=o.z.object({grant_type:o.z.literal("refresh_token"),client_id:o.z.string(),redirect_uri:o.z.string().optional(),refresh_token:o.z.string()});async function s5(t,e){const n=await t.env.data.legacyClients.get(e.client_id);if(!n)throw new b(403,{message:"Client not found"});const r=await t.env.data.refreshTokens.get(n.tenant.id,e.refresh_token);if(r){if(r.expires_at&&new Date(r.expires_at)<new Date||r.idle_expires_at&&new Date(r.idle_expires_at)<new Date)throw new b(403,{message:JSON.stringify({error:"invalid_grant",error_description:"Refresh token has expired"})})}else throw new b(403,{message:JSON.stringify({error:"invalid_grant",error_description:"Invalid refresh token"})});const i=await t.env.data.users.get(n.tenant.id,r.user_id);if(!i)throw new b(403,{message:"User not found"});const s=r.resource_servers[0];if(r.idle_expires_at){const a=new Date(Date.now()+2592e6);await t.env.data.refreshTokens.update(n.tenant.id,r.id,{idle_expires_at:a.toISOString(),last_exchanged_at:new Date().toISOString(),device:{...r.device,last_ip:t.req.header["x-real-ip"]||"",last_user_agent:t.req.header["user-agent"]||""}})}return{user:i,client:n,refresh_token:r.id,session_id:r.session_id,authParams:{client_id:n.client_id,audience:s==null?void 0:s.audience,scope:s==null?void 0:s.scopes,response_mode:Gt.WEB_MESSAGE}}}const a5={version:4,country_calling_codes:{1:["US","AG","AI","AS","BB","BM","BS","CA","DM","DO","GD","GU","JM","KN","KY","LC","MP","MS","PR","SX","TC","TT","VC","VG","VI"],7:["RU","KZ"],20:["EG"],27:["ZA"],30:["GR"],31:["NL"],32:["BE"],33:["FR"],34:["ES"],36:["HU"],39:["IT","VA"],40:["RO"],41:["CH"],43:["AT"],44:["GB","GG","IM","JE"],45:["DK"],46:["SE"],47:["NO","SJ"],48:["PL"],49:["DE"],51:["PE"],52:["MX"],53:["CU"],54:["AR"],55:["BR"],56:["CL"],57:["CO"],58:["VE"],60:["MY"],61:["AU","CC","CX"],62:["ID"],63:["PH"],64:["NZ"],65:["SG"],66:["TH"],81:["JP"],82:["KR"],84:["VN"],86:["CN"],90:["TR"],91:["IN"],92:["PK"],93:["AF"],94:["LK"],95:["MM"],98:["IR"],211:["SS"],212:["MA","EH"],213:["DZ"],216:["TN"],218:["LY"],220:["GM"],221:["SN"],222:["MR"],223:["ML"],224:["GN"],225:["CI"],226:["BF"],227:["NE"],228:["TG"],229:["BJ"],230:["MU"],231:["LR"],232:["SL"],233:["GH"],234:["NG"],235:["TD"],236:["CF"],237:["CM"],238:["CV"],239:["ST"],240:["GQ"],241:["GA"],242:["CG"],243:["CD"],244:["AO"],245:["GW"],246:["IO"],247:["AC"],248:["SC"],249:["SD"],250:["RW"],251:["ET"],252:["SO"],253:["DJ"],254:["KE"],255:["TZ"],256:["UG"],257:["BI"],258:["MZ"],260:["ZM"],261:["MG"],262:["RE","YT"],263:["ZW"],264:["NA"],265:["MW"],266:["LS"],267:["BW"],268:["SZ"],269:["KM"],290:["SH","TA"],291:["ER"],297:["AW"],298:["FO"],299:["GL"],350:["GI"],351:["PT"],352:["LU"],353:["IE"],354:["IS"],355:["AL"],356:["MT"],357:["CY"],358:["FI","AX"],359:["BG"],370:["LT"],371:["LV"],372:["EE"],373:["MD"],374:["AM"],375:["BY"],376:["AD"],377:["MC"],378:["SM"],380:["UA"],381:["RS"],382:["ME"],383:["XK"],385:["HR"],386:["SI"],387:["BA"],389:["MK"],420:["CZ"],421:["SK"],423:["LI"],500:["FK"],501:["BZ"],502:["GT"],503:["SV"],504:["HN"],505:["NI"],506:["CR"],507:["PA"],508:["PM"],509:["HT"],590:["GP","BL","MF"],591:["BO"],592:["GY"],593:["EC"],594:["GF"],595:["PY"],596:["MQ"],597:["SR"],598:["UY"],599:["CW","BQ"],670:["TL"],672:["NF"],673:["BN"],674:["NR"],675:["PG"],676:["TO"],677:["SB"],678:["VU"],679:["FJ"],680:["PW"],681:["WF"],682:["CK"],683:["NU"],685:["WS"],686:["KI"],687:["NC"],688:["TV"],689:["PF"],690:["TK"],691:["FM"],692:["MH"],850:["KP"],852:["HK"],853:["MO"],855:["KH"],856:["LA"],880:["BD"],886:["TW"],960:["MV"],961:["LB"],962:["JO"],963:["SY"],964:["IQ"],965:["KW"],966:["SA"],967:["YE"],968:["OM"],970:["PS"],971:["AE"],972:["IL"],973:["BH"],974:["QA"],975:["BT"],976:["MN"],977:["NP"],992:["TJ"],993:["TM"],994:["AZ"],995:["GE"],996:["KG"],998:["UZ"]},countries:{AC:["247","00","(?:[01589]\\d|[46])\\d{4}",[5,6]],AD:["376","00","(?:1|6\\d)\\d{7}|[135-9]\\d{5}",[6,8,9],[["(\\d{3})(\\d{3})","$1 $2",["[135-9]"]],["(\\d{4})(\\d{4})","$1 $2",["1"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["6"]]]],AE:["971","00","(?:[4-7]\\d|9[0-689])\\d{7}|800\\d{2,9}|[2-4679]\\d{7}",[5,6,7,8,9,10,11,12],[["(\\d{3})(\\d{2,9})","$1 $2",["60|8"]],["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["[236]|[479][2-8]"],"0$1"],["(\\d{3})(\\d)(\\d{5})","$1 $2 $3",["[479]"]],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["5"],"0$1"]],"0"],AF:["93","00","[2-7]\\d{8}",[9],[["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[2-7]"],"0$1"]],"0"],AG:["1","011","(?:268|[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"([457]\\d{6})$|1","268$1",0,"268"],AI:["1","011","(?:264|[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"([2457]\\d{6})$|1","264$1",0,"264"],AL:["355","00","(?:700\\d\\d|900)\\d{3}|8\\d{5,7}|(?:[2-5]|6\\d)\\d{7}",[6,7,8,9],[["(\\d{3})(\\d{3,4})","$1 $2",["80|9"],"0$1"],["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["4[2-6]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["[2358][2-5]|4"],"0$1"],["(\\d{3})(\\d{5})","$1 $2",["[23578]"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["6"],"0$1"]],"0"],AM:["374","00","(?:[1-489]\\d|55|60|77)\\d{6}",[8],[["(\\d{3})(\\d{2})(\\d{3})","$1 $2 $3",["[89]0"],"0 $1"],["(\\d{3})(\\d{5})","$1 $2",["2|3[12]"],"(0$1)"],["(\\d{2})(\\d{6})","$1 $2",["1|47"],"(0$1)"],["(\\d{2})(\\d{6})","$1 $2",["[3-9]"],"0$1"]],"0"],AO:["244","00","[29]\\d{8}",[9],[["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[29]"]]]],AR:["54","00","(?:11|[89]\\d\\d)\\d{8}|[2368]\\d{9}",[10,11],[["(\\d{4})(\\d{2})(\\d{4})","$1 $2-$3",["2(?:2[024-9]|3[0-59]|47|6[245]|9[02-8])|3(?:3[28]|4[03-9]|5[2-46-8]|7[1-578]|8[2-9])","2(?:[23]02|6(?:[25]|4[6-8])|9(?:[02356]|4[02568]|72|8[23]))|3(?:3[28]|4(?:[04679]|3[5-8]|5[4-68]|8[2379])|5(?:[2467]|3[237]|8[2-5])|7[1-578]|8(?:[2469]|3[2578]|5[4-8]|7[36-8]|8[5-8]))|2(?:2[24-9]|3[1-59]|47)","2(?:[23]02|6(?:[25]|4(?:64|[78]))|9(?:[02356]|4(?:[0268]|5[2-6])|72|8[23]))|3(?:3[28]|4(?:[04679]|3[78]|5(?:4[46]|8)|8[2379])|5(?:[2467]|3[237]|8[23])|7[1-578]|8(?:[2469]|3[278]|5[56][46]|86[3-6]))|2(?:2[24-9]|3[1-59]|47)|38(?:[58][78]|7[378])|3(?:4[35][56]|58[45]|8(?:[38]5|54|76))[4-6]","2(?:[23]02|6(?:[25]|4(?:64|[78]))|9(?:[02356]|4(?:[0268]|5[2-6])|72|8[23]))|3(?:3[28]|4(?:[04679]|3(?:5(?:4[0-25689]|[56])|[78])|58|8[2379])|5(?:[2467]|3[237]|8(?:[23]|4(?:[45]|60)|5(?:4[0-39]|5|64)))|7[1-578]|8(?:[2469]|3[278]|54(?:4|5[13-7]|6[89])|86[3-6]))|2(?:2[24-9]|3[1-59]|47)|38(?:[58][78]|7[378])|3(?:454|85[56])[46]|3(?:4(?:36|5[56])|8(?:[38]5|76))[4-6]"],"0$1",1],["(\\d{2})(\\d{4})(\\d{4})","$1 $2-$3",["1"],"0$1",1],["(\\d{3})(\\d{3})(\\d{4})","$1-$2-$3",["[68]"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2-$3",["[23]"],"0$1",1],["(\\d)(\\d{4})(\\d{2})(\\d{4})","$2 15-$3-$4",["9(?:2[2-469]|3[3-578])","9(?:2(?:2[024-9]|3[0-59]|47|6[245]|9[02-8])|3(?:3[28]|4[03-9]|5[2-46-8]|7[1-578]|8[2-9]))","9(?:2(?:[23]02|6(?:[25]|4[6-8])|9(?:[02356]|4[02568]|72|8[23]))|3(?:3[28]|4(?:[04679]|3[5-8]|5[4-68]|8[2379])|5(?:[2467]|3[237]|8[2-5])|7[1-578]|8(?:[2469]|3[2578]|5[4-8]|7[36-8]|8[5-8])))|92(?:2[24-9]|3[1-59]|47)","9(?:2(?:[23]02|6(?:[25]|4(?:64|[78]))|9(?:[02356]|4(?:[0268]|5[2-6])|72|8[23]))|3(?:3[28]|4(?:[04679]|3[78]|5(?:4[46]|8)|8[2379])|5(?:[2467]|3[237]|8[23])|7[1-578]|8(?:[2469]|3[278]|5(?:[56][46]|[78])|7[378]|8(?:6[3-6]|[78]))))|92(?:2[24-9]|3[1-59]|47)|93(?:4[35][56]|58[45]|8(?:[38]5|54|76))[4-6]","9(?:2(?:[23]02|6(?:[25]|4(?:64|[78]))|9(?:[02356]|4(?:[0268]|5[2-6])|72|8[23]))|3(?:3[28]|4(?:[04679]|3(?:5(?:4[0-25689]|[56])|[78])|5(?:4[46]|8)|8[2379])|5(?:[2467]|3[237]|8(?:[23]|4(?:[45]|60)|5(?:4[0-39]|5|64)))|7[1-578]|8(?:[2469]|3[278]|5(?:4(?:4|5[13-7]|6[89])|[56][46]|[78])|7[378]|8(?:6[3-6]|[78]))))|92(?:2[24-9]|3[1-59]|47)|93(?:4(?:36|5[56])|8(?:[38]5|76))[4-6]"],"0$1",0,"$1 $2 $3-$4"],["(\\d)(\\d{2})(\\d{4})(\\d{4})","$2 15-$3-$4",["91"],"0$1",0,"$1 $2 $3-$4"],["(\\d{3})(\\d{3})(\\d{5})","$1-$2-$3",["8"],"0$1"],["(\\d)(\\d{3})(\\d{3})(\\d{4})","$2 15-$3-$4",["9"],"0$1",0,"$1 $2 $3-$4"]],"0",0,"0?(?:(11|2(?:2(?:02?|[13]|2[13-79]|4[1-6]|5[2457]|6[124-8]|7[1-4]|8[13-6]|9[1267])|3(?:02?|1[467]|2[03-6]|3[13-8]|[49][2-6]|5[2-8]|[67])|4(?:7[3-578]|9)|6(?:[0136]|2[24-6]|4[6-8]?|5[15-8])|80|9(?:0[1-3]|[19]|2\\d|3[1-6]|4[02568]?|5[2-4]|6[2-46]|72?|8[23]?))|3(?:3(?:2[79]|6|8[2578])|4(?:0[0-24-9]|[12]|3[5-8]?|4[24-7]|5[4-68]?|6[02-9]|7[126]|8[2379]?|9[1-36-8])|5(?:1|2[1245]|3[237]?|4[1-46-9]|6[2-4]|7[1-6]|8[2-5]?)|6[24]|7(?:[069]|1[1568]|2[15]|3[145]|4[13]|5[14-8]|7[2-57]|8[126])|8(?:[01]|2[15-7]|3[2578]?|4[13-6]|5[4-8]?|6[1-357-9]|7[36-8]?|8[5-8]?|9[124])))15)?","9$1"],AS:["1","011","(?:[58]\\d\\d|684|900)\\d{7}",[10],0,"1",0,"([267]\\d{6})$|1","684$1",0,"684"],AT:["43","00","1\\d{3,12}|2\\d{6,12}|43(?:(?:0\\d|5[02-9])\\d{3,9}|2\\d{4,5}|[3467]\\d{4}|8\\d{4,6}|9\\d{4,7})|5\\d{4,12}|8\\d{7,12}|9\\d{8,12}|(?:[367]\\d|4[0-24-9])\\d{4,11}",[4,5,6,7,8,9,10,11,12,13],[["(\\d)(\\d{3,12})","$1 $2",["1(?:11|[2-9])"],"0$1"],["(\\d{3})(\\d{2})","$1 $2",["517"],"0$1"],["(\\d{2})(\\d{3,5})","$1 $2",["5[079]"],"0$1"],["(\\d{3})(\\d{3,10})","$1 $2",["(?:31|4)6|51|6(?:48|5[0-3579]|[6-9])|7(?:20|32|8)|[89]","(?:31|4)6|51|6(?:485|5[0-3579]|[6-9])|7(?:20|32|8)|[89]"],"0$1"],["(\\d{4})(\\d{3,9})","$1 $2",["[2-467]|5[2-6]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["5"],"0$1"],["(\\d{2})(\\d{4})(\\d{4,7})","$1 $2 $3",["5"],"0$1"]],"0"],AU:["61","001[14-689]|14(?:1[14]|34|4[17]|[56]6|7[47]|88)0011","1(?:[0-79]\\d{7}(?:\\d(?:\\d{2})?)?|8[0-24-9]\\d{7})|[2-478]\\d{8}|1\\d{4,7}",[5,6,7,8,9,10,12],[["(\\d{2})(\\d{3,4})","$1 $2",["16"],"0$1"],["(\\d{2})(\\d{3})(\\d{2,4})","$1 $2 $3",["16"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["14|4"],"0$1"],["(\\d)(\\d{4})(\\d{4})","$1 $2 $3",["[2378]"],"(0$1)"],["(\\d{4})(\\d{3})(\\d{3})","$1 $2 $3",["1(?:30|[89])"]]],"0",0,"(183[12])|0",0,0,0,[["(?:(?:(?:2(?:[0-26-9]\\d|3[0-8]|4[02-9]|5[0135-9])|7(?:[013-57-9]\\d|2[0-8]))\\d|3(?:(?:[0-3589]\\d|6[1-9]|7[0-35-9])\\d|4(?:[0-578]\\d|90)))\\d\\d|8(?:51(?:0(?:0[03-9]|[12479]\\d|3[2-9]|5[0-8]|6[1-9]|8[0-7])|1(?:[0235689]\\d|1[0-69]|4[0-589]|7[0-47-9])|2(?:0[0-79]|[18][13579]|2[14-9]|3[0-46-9]|[4-6]\\d|7[89]|9[0-4])|3\\d\\d)|(?:6[0-8]|[78]\\d)\\d{3}|9(?:[02-9]\\d{3}|1(?:(?:[0-58]\\d|6[0135-9])\\d|7(?:0[0-24-9]|[1-9]\\d)|9(?:[0-46-9]\\d|5[0-79])))))\\d{3}",[9]],["4(?:79[01]|83[0-389]|94[0-4])\\d{5}|4(?:[0-36]\\d|4[047-9]|5[0-25-9]|7[02-8]|8[0-24-9]|9[0-37-9])\\d{6}",[9]],["180(?:0\\d{3}|2)\\d{3}",[7,10]],["190[0-26]\\d{6}",[10]],0,0,0,["163\\d{2,6}",[5,6,7,8,9]],["14(?:5(?:1[0458]|[23][458])|71\\d)\\d{4}",[9]],["13(?:00\\d{6}(?:\\d{2})?|45[0-4]\\d{3})|13\\d{4}",[6,8,10,12]]],"0011"],AW:["297","00","(?:[25-79]\\d\\d|800)\\d{4}",[7],[["(\\d{3})(\\d{4})","$1 $2",["[25-9]"]]]],AX:["358","00|99(?:[01469]|5(?:[14]1|3[23]|5[59]|77|88|9[09]))","2\\d{4,9}|35\\d{4,5}|(?:60\\d\\d|800)\\d{4,6}|7\\d{5,11}|(?:[14]\\d|3[0-46-9]|50)\\d{4,8}",[5,6,7,8,9,10,11,12],0,"0",0,0,0,0,"18",0,"00"],AZ:["994","00","365\\d{6}|(?:[124579]\\d|60|88)\\d{7}",[9],[["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["90"],"0$1"],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["1[28]|2|365|46","1[28]|2|365[45]|46","1[28]|2|365(?:4|5[02])|46"],"(0$1)"],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[13-9]"],"0$1"]],"0"],BA:["387","00","6\\d{8}|(?:[35689]\\d|49|70)\\d{6}",[8,9],[["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["6[1-3]|[7-9]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3})","$1 $2-$3",["[3-5]|6[56]"],"0$1"],["(\\d{2})(\\d{2})(\\d{2})(\\d{3})","$1 $2 $3 $4",["6"],"0$1"]],"0"],BB:["1","011","(?:246|[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"([2-9]\\d{6})$|1","246$1",0,"246"],BD:["880","00","[1-469]\\d{9}|8[0-79]\\d{7,8}|[2-79]\\d{8}|[2-9]\\d{7}|[3-9]\\d{6}|[57-9]\\d{5}",[6,7,8,9,10],[["(\\d{2})(\\d{4,6})","$1-$2",["31[5-8]|[459]1"],"0$1"],["(\\d{3})(\\d{3,7})","$1-$2",["3(?:[67]|8[013-9])|4(?:6[168]|7|[89][18])|5(?:6[128]|9)|6(?:[15]|28|4[14])|7[2-589]|8(?:0[014-9]|[12])|9[358]|(?:3[2-5]|4[235]|5[2-578]|6[0389]|76|8[3-7]|9[24])1|(?:44|66)[01346-9]"],"0$1"],["(\\d{4})(\\d{3,6})","$1-$2",["[13-9]|2[23]"],"0$1"],["(\\d)(\\d{7,8})","$1-$2",["2"],"0$1"]],"0"],BE:["32","00","4\\d{8}|[1-9]\\d{7}",[8,9],[["(\\d{3})(\\d{2})(\\d{3})","$1 $2 $3",["(?:80|9)0"],"0$1"],["(\\d)(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[239]|4[23]"],"0$1"],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[15-8]"],"0$1"],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["4"],"0$1"]],"0"],BF:["226","00","[025-7]\\d{7}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[025-7]"]]]],BG:["359","00","00800\\d{7}|[2-7]\\d{6,7}|[89]\\d{6,8}|2\\d{5}",[6,7,8,9,12],[["(\\d)(\\d)(\\d{2})(\\d{2})","$1 $2 $3 $4",["2"],"0$1"],["(\\d{3})(\\d{4})","$1 $2",["43[1-6]|70[1-9]"],"0$1"],["(\\d)(\\d{3})(\\d{3,4})","$1 $2 $3",["2"],"0$1"],["(\\d{2})(\\d{3})(\\d{2,3})","$1 $2 $3",["[356]|4[124-7]|7[1-9]|8[1-6]|9[1-7]"],"0$1"],["(\\d{3})(\\d{2})(\\d{3})","$1 $2 $3",["(?:70|8)0"],"0$1"],["(\\d{3})(\\d{3})(\\d{2})","$1 $2 $3",["43[1-7]|7"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[48]|9[08]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["9"],"0$1"]],"0"],BH:["973","00","[136-9]\\d{7}",[8],[["(\\d{4})(\\d{4})","$1 $2",["[13679]|8[02-4679]"]]]],BI:["257","00","(?:[267]\\d|31)\\d{6}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[2367]"]]]],BJ:["229","00","(?:01\\d|[24-689])\\d{7}",[8,10],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[24-689]"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4 $5",["0"]]]],BL:["590","00","(?:590\\d|7090)\\d{5}|(?:69|80|9\\d)\\d{7}",[9],0,"0",0,0,0,0,0,[["590(?:2[7-9]|3[3-7]|5[12]|87)\\d{4}"],["(?:69(?:0\\d\\d|1(?:2[2-9]|3[0-5])|4(?:0[89]|1[2-6]|9\\d)|6(?:1[016-9]|5[0-4]|[67]\\d))|7090[0-4])\\d{4}"],["80[0-5]\\d{6}"],0,0,0,0,0,["9(?:(?:39[5-7]|76[018])\\d|475[0-6])\\d{4}"]]],BM:["1","011","(?:441|[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"([2-9]\\d{6})$|1","441$1",0,"441"],BN:["673","00","[2-578]\\d{6}",[7],[["(\\d{3})(\\d{4})","$1 $2",["[2-578]"]]]],BO:["591","00(?:1\\d)?","8001\\d{5}|(?:[2-467]\\d|50)\\d{6}",[8,9],[["(\\d)(\\d{7})","$1 $2",["[235]|4[46]"]],["(\\d{8})","$1",["[67]"]],["(\\d{3})(\\d{2})(\\d{4})","$1 $2 $3",["8"]]],"0",0,"0(1\\d)?"],BQ:["599","00","(?:[34]1|7\\d)\\d{5}",[7],0,0,0,0,0,0,"[347]"],BR:["55","00(?:1[245]|2[1-35]|31|4[13]|[56]5|99)","[1-467]\\d{9,10}|55[0-46-9]\\d{8}|[34]\\d{7}|55\\d{7,8}|(?:5[0-46-9]|[89]\\d)\\d{7,9}",[8,9,10,11],[["(\\d{4})(\\d{4})","$1-$2",["300|4(?:0[02]|37|86)","300|4(?:0(?:0|20)|370|864)"]],["(\\d{3})(\\d{2,3})(\\d{4})","$1 $2 $3",["(?:[358]|90)0"],"0$1"],["(\\d{2})(\\d{4})(\\d{4})","$1 $2-$3",["(?:[14689][1-9]|2[12478]|3[1-578]|5[13-5]|7[13-579])[2-57]"],"($1)"],["(\\d{2})(\\d{5})(\\d{4})","$1 $2-$3",["[16][1-9]|[2-57-9]"],"($1)"]],"0",0,"(?:0|90)(?:(1[245]|2[1-35]|31|4[13]|[56]5|99)(\\d{10,11}))?","$2"],BS:["1","011","(?:242|[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"([3-8]\\d{6})$|1","242$1",0,"242"],BT:["975","00","[17]\\d{7}|[2-8]\\d{6}",[7,8],[["(\\d)(\\d{3})(\\d{3})","$1 $2 $3",["[2-68]|7[246]"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["1[67]|7"]]]],BW:["267","00","(?:0800|(?:[37]|800)\\d)\\d{6}|(?:[2-6]\\d|90)\\d{5}",[7,8,10],[["(\\d{2})(\\d{5})","$1 $2",["90"]],["(\\d{3})(\\d{4})","$1 $2",["[24-6]|3[15-9]"]],["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["[37]"]],["(\\d{4})(\\d{3})(\\d{3})","$1 $2 $3",["0"]],["(\\d{3})(\\d{4})(\\d{3})","$1 $2 $3",["8"]]]],BY:["375","810","(?:[12]\\d|33|44|902)\\d{7}|8(?:0[0-79]\\d{5,7}|[1-7]\\d{9})|8(?:1[0-489]|[5-79]\\d)\\d{7}|8[1-79]\\d{6,7}|8[0-79]\\d{5}|8\\d{5}",[6,7,8,9,10,11],[["(\\d{3})(\\d{3})","$1 $2",["800"],"8 $1"],["(\\d{3})(\\d{2})(\\d{2,4})","$1 $2 $3",["800"],"8 $1"],["(\\d{4})(\\d{2})(\\d{3})","$1 $2-$3",["1(?:5[169]|6[3-5]|7[179])|2(?:1[35]|2[34]|3[3-5])","1(?:5[169]|6(?:3[1-3]|4|5[125])|7(?:1[3-9]|7[0-24-6]|9[2-7]))|2(?:1[35]|2[34]|3[3-5])"],"8 0$1"],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2-$3-$4",["1(?:[56]|7[467])|2[1-3]"],"8 0$1"],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2-$3-$4",["[1-4]"],"8 0$1"],["(\\d{3})(\\d{3,4})(\\d{4})","$1 $2 $3",["[89]"],"8 $1"]],"8",0,"0|80?",0,0,0,0,"8~10"],BZ:["501","00","(?:0800\\d|[2-8])\\d{6}",[7,11],[["(\\d{3})(\\d{4})","$1-$2",["[2-8]"]],["(\\d)(\\d{3})(\\d{4})(\\d{3})","$1-$2-$3-$4",["0"]]]],CA:["1","011","[2-9]\\d{9}|3\\d{6}",[7,10],0,"1",0,0,0,0,0,[["(?:2(?:04|[23]6|[48]9|50|63)|3(?:06|43|54|6[578]|82)|4(?:03|1[68]|[26]8|3[178]|50|74)|5(?:06|1[49]|48|79|8[147])|6(?:04|[18]3|39|47|72)|7(?:0[59]|42|53|78|8[02])|8(?:[06]7|19|25|7[39])|9(?:0[25]|42))[2-9]\\d{6}",[10]],["",[10]],["8(?:00|33|44|55|66|77|88)[2-9]\\d{6}",[10]],["900[2-9]\\d{6}",[10]],["52(?:3(?:[2-46-9][02-9]\\d|5(?:[02-46-9]\\d|5[0-46-9]))|4(?:[2-478][02-9]\\d|5(?:[034]\\d|2[024-9]|5[0-46-9])|6(?:0[1-9]|[2-9]\\d)|9(?:[05-9]\\d|2[0-5]|49)))\\d{4}|52[34][2-9]1[02-9]\\d{4}|(?:5(?:2[125-9]|33|44|66|77|88)|6(?:22|33))[2-9]\\d{6}",[10]],0,["310\\d{4}",[7]],0,["600[2-9]\\d{6}",[10]]]],CC:["61","001[14-689]|14(?:1[14]|34|4[17]|[56]6|7[47]|88)0011","1(?:[0-79]\\d{8}(?:\\d{2})?|8[0-24-9]\\d{7})|[148]\\d{8}|1\\d{5,7}",[6,7,8,9,10,12],0,"0",0,"([59]\\d{7})$|0","8$1",0,0,[["8(?:51(?:0(?:02|31|60|89)|1(?:18|76)|223)|91(?:0(?:1[0-2]|29)|1(?:[28]2|50|79)|2(?:10|64)|3(?:[06]8|22)|4[29]8|62\\d|70[23]|959))\\d{3}",[9]],["4(?:79[01]|83[0-389]|94[0-4])\\d{5}|4(?:[0-36]\\d|4[047-9]|5[0-25-9]|7[02-8]|8[0-24-9]|9[0-37-9])\\d{6}",[9]],["180(?:0\\d{3}|2)\\d{3}",[7,10]],["190[0-26]\\d{6}",[10]],0,0,0,0,["14(?:5(?:1[0458]|[23][458])|71\\d)\\d{4}",[9]],["13(?:00\\d{6}(?:\\d{2})?|45[0-4]\\d{3})|13\\d{4}",[6,8,10,12]]],"0011"],CD:["243","00","(?:(?:[189]|5\\d)\\d|2)\\d{7}|[1-68]\\d{6}",[7,8,9,10],[["(\\d{2})(\\d{2})(\\d{3})","$1 $2 $3",["88"],"0$1"],["(\\d{2})(\\d{5})","$1 $2",["[1-6]"],"0$1"],["(\\d{2})(\\d{2})(\\d{4})","$1 $2 $3",["2"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["1"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[89]"],"0$1"],["(\\d{2})(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3 $4",["5"],"0$1"]],"0"],CF:["236","00","(?:[27]\\d{3}|8776)\\d{4}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[278]"]]]],CG:["242","00","222\\d{6}|(?:0\\d|80)\\d{7}",[9],[["(\\d)(\\d{4})(\\d{4})","$1 $2 $3",["8"]],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[02]"]]]],CH:["41","00","8\\d{11}|[2-9]\\d{8}",[9,12],[["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["8[047]|90"],"0$1"],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[2-79]|81"],"0$1"],["(\\d{3})(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4 $5",["8"],"0$1"]],"0"],CI:["225","00","[02]\\d{9}",[10],[["(\\d{2})(\\d{2})(\\d)(\\d{5})","$1 $2 $3 $4",["2"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{4})","$1 $2 $3 $4",["0"]]]],CK:["682","00","[2-578]\\d{4}",[5],[["(\\d{2})(\\d{3})","$1 $2",["[2-578]"]]]],CL:["56","(?:0|1(?:1[0-69]|2[02-5]|5[13-58]|69|7[0167]|8[018]))0","12300\\d{6}|6\\d{9,10}|[2-9]\\d{8}",[9,10,11],[["(\\d{5})(\\d{4})","$1 $2",["219","2196"],"($1)"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["44"]],["(\\d)(\\d{4})(\\d{4})","$1 $2 $3",["2[1-36]"],"($1)"],["(\\d)(\\d{4})(\\d{4})","$1 $2 $3",["9[2-9]"]],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["3[2-5]|[47]|5[1-3578]|6[13-57]|8(?:0[1-9]|[1-9])"],"($1)"],["(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["60|8"]],["(\\d{4})(\\d{3})(\\d{4})","$1 $2 $3",["1"]],["(\\d{3})(\\d{3})(\\d{2})(\\d{3})","$1 $2 $3 $4",["60"]]]],CM:["237","00","[26]\\d{8}|88\\d{6,7}",[8,9],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["88"]],["(\\d)(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4 $5",["[26]|88"]]]],CN:["86","00|1(?:[12]\\d|79)\\d\\d00","(?:(?:1[03-689]|2\\d)\\d\\d|6)\\d{8}|1\\d{10}|[126]\\d{6}(?:\\d(?:\\d{2})?)?|86\\d{5,6}|(?:[3-579]\\d|8[0-57-9])\\d{5,9}",[7,8,9,10,11,12],[["(\\d{2})(\\d{5,6})","$1 $2",["(?:10|2[0-57-9])[19]|3(?:[157]|35|49|9[1-68])|4(?:1[124-9]|2[179]|6[47-9]|7|8[23])|5(?:[1357]|2[37]|4[36]|6[1-46]|80)|6(?:3[1-5]|6[0238]|9[12])|7(?:01|[1579]|2[248]|3[014-9]|4[3-6]|6[023689])|8(?:07|1[236-8]|2[5-7]|[37]|8[36-8]|9[1-8])|9(?:0[1-3689]|1[1-79]|3|4[13]|5[1-5]|7[0-79]|9[0-35-9])|(?:4[35]|59|85)[1-9]","(?:10|2[0-57-9])(?:1[02]|9[56])|8078|(?:3(?:[157]\\d|35|49|9[1-68])|4(?:1[124-9]|2[179]|[35][1-9]|6[47-9]|7\\d|8[23])|5(?:[1357]\\d|2[37]|4[36]|6[1-46]|80|9[1-9])|6(?:3[1-5]|6[0238]|9[12])|7(?:01|[1579]\\d|2[248]|3[014-9]|4[3-6]|6[023689])|8(?:1[236-8]|2[5-7]|[37]\\d|5[1-9]|8[36-8]|9[1-8])|9(?:0[1-3689]|1[1-79]|3\\d|4[13]|5[1-5]|7[0-79]|9[0-35-9]))1","10(?:1(?:0|23)|9[56])|2[0-57-9](?:1(?:00|23)|9[56])|80781|(?:3(?:[157]\\d|35|49|9[1-68])|4(?:1[124-9]|2[179]|[35][1-9]|6[47-9]|7\\d|8[23])|5(?:[1357]\\d|2[37]|4[36]|6[1-46]|80|9[1-9])|6(?:3[1-5]|6[0238]|9[12])|7(?:01|[1579]\\d|2[248]|3[014-9]|4[3-6]|6[023689])|8(?:1[236-8]|2[5-7]|[37]\\d|5[1-9]|8[36-8]|9[1-8])|9(?:0[1-3689]|1[1-79]|3\\d|4[13]|5[1-5]|7[0-79]|9[0-35-9]))12","10(?:1(?:0|23)|9[56])|2[0-57-9](?:1(?:00|23)|9[56])|807812|(?:3(?:[157]\\d|35|49|9[1-68])|4(?:1[124-9]|2[179]|[35][1-9]|6[47-9]|7\\d|8[23])|5(?:[1357]\\d|2[37]|4[36]|6[1-46]|80|9[1-9])|6(?:3[1-5]|6[0238]|9[12])|7(?:01|[1579]\\d|2[248]|3[014-9]|4[3-6]|6[023689])|8(?:1[236-8]|2[5-7]|[37]\\d|5[1-9]|8[36-8]|9[1-8])|9(?:0[1-3689]|1[1-79]|3\\d|4[13]|5[1-5]|7[0-79]|9[0-35-9]))123","10(?:1(?:0|23)|9[56])|2[0-57-9](?:1(?:00|23)|9[56])|(?:3(?:[157]\\d|35|49|9[1-68])|4(?:1[124-9]|2[179]|[35][1-9]|6[47-9]|7\\d|8[23])|5(?:[1357]\\d|2[37]|4[36]|6[1-46]|80|9[1-9])|6(?:3[1-5]|6[0238]|9[12])|7(?:01|[1579]\\d|2[248]|3[014-9]|4[3-6]|6[023689])|8(?:078|1[236-8]|2[5-7]|[37]\\d|5[1-9]|8[36-8]|9[1-8])|9(?:0[1-3689]|1[1-79]|3\\d|4[13]|5[1-5]|7[0-79]|9[0-35-9]))123"],"0$1"],["(\\d{3})(\\d{5,6})","$1 $2",["3(?:[157]|35|49|9[1-68])|4(?:[17]|2[179]|6[47-9]|8[23])|5(?:[1357]|2[37]|4[36]|6[1-46]|80)|6(?:3[1-5]|6[0238]|9[12])|7(?:01|[1579]|2[248]|3[014-9]|4[3-6]|6[023689])|8(?:1[236-8]|2[5-7]|[37]|8[36-8]|9[1-8])|9(?:0[1-3689]|1[1-79]|[379]|4[13]|5[1-5])|(?:4[35]|59|85)[1-9]","(?:3(?:[157]\\d|35|49|9[1-68])|4(?:[17]\\d|2[179]|[35][1-9]|6[47-9]|8[23])|5(?:[1357]\\d|2[37]|4[36]|6[1-46]|80|9[1-9])|6(?:3[1-5]|6[0238]|9[12])|7(?:01|[1579]\\d|2[248]|3[014-9]|4[3-6]|6[023689])|8(?:1[236-8]|2[5-7]|[37]\\d|5[1-9]|8[36-8]|9[1-8])|9(?:0[1-3689]|1[1-79]|[379]\\d|4[13]|5[1-5]))[19]","85[23](?:10|95)|(?:3(?:[157]\\d|35|49|9[1-68])|4(?:[17]\\d|2[179]|[35][1-9]|6[47-9]|8[23])|5(?:[1357]\\d|2[37]|4[36]|6[1-46]|80|9[1-9])|6(?:3[1-5]|6[0238]|9[12])|7(?:01|[1579]\\d|2[248]|3[014-9]|4[3-6]|6[023689])|8(?:1[236-8]|2[5-7]|[37]\\d|5[14-9]|8[36-8]|9[1-8])|9(?:0[1-3689]|1[1-79]|[379]\\d|4[13]|5[1-5]))(?:10|9[56])","85[23](?:100|95)|(?:3(?:[157]\\d|35|49|9[1-68])|4(?:[17]\\d|2[179]|[35][1-9]|6[47-9]|8[23])|5(?:[1357]\\d|2[37]|4[36]|6[1-46]|80|9[1-9])|6(?:3[1-5]|6[0238]|9[12])|7(?:01|[1579]\\d|2[248]|3[014-9]|4[3-6]|6[023689])|8(?:1[236-8]|2[5-7]|[37]\\d|5[14-9]|8[36-8]|9[1-8])|9(?:0[1-3689]|1[1-79]|[379]\\d|4[13]|5[1-5]))(?:100|9[56])"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["(?:4|80)0"]],["(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3",["10|2(?:[02-57-9]|1[1-9])","10|2(?:[02-57-9]|1[1-9])","10[0-79]|2(?:[02-57-9]|1[1-79])|(?:10|21)8(?:0[1-9]|[1-9])"],"0$1",1],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["3(?:[3-59]|7[02-68])|4(?:[26-8]|3[3-9]|5[2-9])|5(?:3[03-9]|[468]|7[028]|9[2-46-9])|6|7(?:[0-247]|3[04-9]|5[0-4689]|6[2368])|8(?:[1-358]|9[1-7])|9(?:[013479]|5[1-5])|(?:[34]1|55|79|87)[02-9]"],"0$1",1],["(\\d{3})(\\d{7,8})","$1 $2",["9"]],["(\\d{4})(\\d{3})(\\d{4})","$1 $2 $3",["80"],"0$1",1],["(\\d{3})(\\d{4})(\\d{4})","$1 $2 $3",["[3-578]"],"0$1",1],["(\\d{3})(\\d{4})(\\d{4})","$1 $2 $3",["1[3-9]"]],["(\\d{2})(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3 $4",["[12]"],"0$1",1]],"0",0,"(1(?:[12]\\d|79)\\d\\d)|0",0,0,0,0,"00"],CO:["57","00(?:4(?:[14]4|56)|[579])","(?:46|60\\d\\d)\\d{6}|(?:1\\d|[39])\\d{9}",[8,10,11],[["(\\d{4})(\\d{4})","$1 $2",["46"]],["(\\d{3})(\\d{7})","$1 $2",["6|90"],"($1)"],["(\\d{3})(\\d{7})","$1 $2",["3[0-357]|91"]],["(\\d)(\\d{3})(\\d{7})","$1-$2-$3",["1"],"0$1",0,"$1 $2 $3"]],"0",0,"0([3579]|4(?:[14]4|56))?"],CR:["506","00","(?:8\\d|90)\\d{8}|(?:[24-8]\\d{3}|3005)\\d{4}",[8,10],[["(\\d{4})(\\d{4})","$1 $2",["[2-7]|8[3-9]"]],["(\\d{3})(\\d{3})(\\d{4})","$1-$2-$3",["[89]"]]],0,0,"(19(?:0[0-2468]|1[09]|20|66|77|99))"],CU:["53","119","(?:[2-7]|8\\d\\d)\\d{7}|[2-47]\\d{6}|[34]\\d{5}",[6,7,8,10],[["(\\d{2})(\\d{4,6})","$1 $2",["2[1-4]|[34]"],"(0$1)"],["(\\d)(\\d{6,7})","$1 $2",["7"],"(0$1)"],["(\\d)(\\d{7})","$1 $2",["[56]"],"0$1"],["(\\d{3})(\\d{7})","$1 $2",["8"],"0$1"]],"0"],CV:["238","0","(?:[2-59]\\d\\d|800)\\d{4}",[7],[["(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3",["[2-589]"]]]],CW:["599","00","(?:[34]1|60|(?:7|9\\d)\\d)\\d{5}",[7,8],[["(\\d{3})(\\d{4})","$1 $2",["[3467]"]],["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["9[4-8]"]]],0,0,0,0,0,"[69]"],CX:["61","001[14-689]|14(?:1[14]|34|4[17]|[56]6|7[47]|88)0011","1(?:[0-79]\\d{8}(?:\\d{2})?|8[0-24-9]\\d{7})|[148]\\d{8}|1\\d{5,7}",[6,7,8,9,10,12],0,"0",0,"([59]\\d{7})$|0","8$1",0,0,[["8(?:51(?:0(?:01|30|59|88)|1(?:17|46|75)|2(?:22|35))|91(?:00[6-9]|1(?:[28]1|49|78)|2(?:09|63)|3(?:12|26|75)|4(?:56|97)|64\\d|7(?:0[01]|1[0-2])|958))\\d{3}",[9]],["4(?:79[01]|83[0-389]|94[0-4])\\d{5}|4(?:[0-36]\\d|4[047-9]|5[0-25-9]|7[02-8]|8[0-24-9]|9[0-37-9])\\d{6}",[9]],["180(?:0\\d{3}|2)\\d{3}",[7,10]],["190[0-26]\\d{6}",[10]],0,0,0,0,["14(?:5(?:1[0458]|[23][458])|71\\d)\\d{4}",[9]],["13(?:00\\d{6}(?:\\d{2})?|45[0-4]\\d{3})|13\\d{4}",[6,8,10,12]]],"0011"],CY:["357","00","(?:[279]\\d|[58]0)\\d{6}",[8],[["(\\d{2})(\\d{6})","$1 $2",["[257-9]"]]]],CZ:["420","00","(?:[2-578]\\d|60)\\d{7}|9\\d{8,11}",[9,10,11,12],[["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[2-8]|9[015-7]"]],["(\\d{2})(\\d{3})(\\d{3})(\\d{2})","$1 $2 $3 $4",["96"]],["(\\d{2})(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3 $4",["9"]],["(\\d{3})(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3 $4",["9"]]]],DE:["49","00","[2579]\\d{5,14}|49(?:[34]0|69|8\\d)\\d\\d?|49(?:37|49|60|7[089]|9\\d)\\d{1,3}|49(?:2[024-9]|3[2-689]|7[1-7])\\d{1,8}|(?:1|[368]\\d|4[0-8])\\d{3,13}|49(?:[015]\\d|2[13]|31|[46][1-8])\\d{1,9}",[4,5,6,7,8,9,10,11,12,13,14,15],[["(\\d{2})(\\d{3,13})","$1 $2",["3[02]|40|[68]9"],"0$1"],["(\\d{3})(\\d{3,12})","$1 $2",["2(?:0[1-389]|1[124]|2[18]|3[14])|3(?:[35-9][15]|4[015])|906|(?:2[4-9]|4[2-9]|[579][1-9]|[68][1-8])1","2(?:0[1-389]|12[0-8])|3(?:[35-9][15]|4[015])|906|2(?:[13][14]|2[18])|(?:2[4-9]|4[2-9]|[579][1-9]|[68][1-8])1"],"0$1"],["(\\d{4})(\\d{2,11})","$1 $2",["[24-6]|3(?:[3569][02-46-9]|4[2-4679]|7[2-467]|8[2-46-8])|70[2-8]|8(?:0[2-9]|[1-8])|90[7-9]|[79][1-9]","[24-6]|3(?:3(?:0[1-467]|2[127-9]|3[124578]|7[1257-9]|8[1256]|9[145])|4(?:2[135]|4[13578]|9[1346])|5(?:0[14]|2[1-3589]|6[1-4]|7[13468]|8[13568])|6(?:2[1-489]|3[124-6]|6[13]|7[12579]|8[1-356]|9[135])|7(?:2[1-7]|4[145]|6[1-5]|7[1-4])|8(?:21|3[1468]|6|7[1467]|8[136])|9(?:0[12479]|2[1358]|4[134679]|6[1-9]|7[136]|8[147]|9[1468]))|70[2-8]|8(?:0[2-9]|[1-8])|90[7-9]|[79][1-9]|3[68]4[1347]|3(?:47|60)[1356]|3(?:3[46]|46|5[49])[1246]|3[4579]3[1357]"],"0$1"],["(\\d{3})(\\d{4})","$1 $2",["138"],"0$1"],["(\\d{5})(\\d{2,10})","$1 $2",["3"],"0$1"],["(\\d{3})(\\d{5,11})","$1 $2",["181"],"0$1"],["(\\d{3})(\\d)(\\d{4,10})","$1 $2 $3",["1(?:3|80)|9"],"0$1"],["(\\d{3})(\\d{7,8})","$1 $2",["1[67]"],"0$1"],["(\\d{3})(\\d{7,12})","$1 $2",["8"],"0$1"],["(\\d{5})(\\d{6})","$1 $2",["185","1850","18500"],"0$1"],["(\\d{3})(\\d{4})(\\d{4})","$1 $2 $3",["7"],"0$1"],["(\\d{4})(\\d{7})","$1 $2",["18[68]"],"0$1"],["(\\d{4})(\\d{7})","$1 $2",["15[1279]"],"0$1"],["(\\d{5})(\\d{6})","$1 $2",["15[03568]","15(?:[0568]|31)"],"0$1"],["(\\d{3})(\\d{8})","$1 $2",["18"],"0$1"],["(\\d{3})(\\d{2})(\\d{7,8})","$1 $2 $3",["1(?:6[023]|7)"],"0$1"],["(\\d{4})(\\d{2})(\\d{7})","$1 $2 $3",["15[279]"],"0$1"],["(\\d{3})(\\d{2})(\\d{8})","$1 $2 $3",["15"],"0$1"]],"0"],DJ:["253","00","(?:2\\d|77)\\d{6}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[27]"]]]],DK:["45","00","[2-9]\\d{7}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[2-9]"]]]],DM:["1","011","(?:[58]\\d\\d|767|900)\\d{7}",[10],0,"1",0,"([2-7]\\d{6})$|1","767$1",0,"767"],DO:["1","011","(?:[58]\\d\\d|900)\\d{7}",[10],0,"1",0,0,0,0,"8001|8[024]9"],DZ:["213","00","(?:[1-4]|[5-79]\\d|80)\\d{7}",[8,9],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[1-4]"],"0$1"],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["9"],"0$1"],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[5-8]"],"0$1"]],"0"],EC:["593","00","1\\d{9,10}|(?:[2-7]|9\\d)\\d{7}",[8,9,10,11],[["(\\d)(\\d{3})(\\d{4})","$1 $2-$3",["[2-7]"],"(0$1)",0,"$1-$2-$3"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["9"],"0$1"],["(\\d{4})(\\d{3})(\\d{3,4})","$1 $2 $3",["1"]]],"0"],EE:["372","00","8\\d{9}|[4578]\\d{7}|(?:[3-8]\\d|90)\\d{5}",[7,8,10],[["(\\d{3})(\\d{4})","$1 $2",["[369]|4[3-8]|5(?:[0-2]|5[0-478]|6[45])|7[1-9]|88","[369]|4[3-8]|5(?:[02]|1(?:[0-8]|95)|5[0-478]|6(?:4[0-4]|5[1-589]))|7[1-9]|88"]],["(\\d{4})(\\d{3,4})","$1 $2",["[45]|8(?:00|[1-49])","[45]|8(?:00[1-9]|[1-49])"]],["(\\d{2})(\\d{2})(\\d{4})","$1 $2 $3",["7"]],["(\\d{4})(\\d{3})(\\d{3})","$1 $2 $3",["8"]]]],EG:["20","00","[189]\\d{8,9}|[24-6]\\d{8}|[135]\\d{7}",[8,9,10],[["(\\d)(\\d{7,8})","$1 $2",["[23]"],"0$1"],["(\\d{2})(\\d{6,7})","$1 $2",["1[35]|[4-6]|8[2468]|9[235-7]"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["[89]"],"0$1"],["(\\d{2})(\\d{8})","$1 $2",["1"],"0$1"]],"0"],EH:["212","00","[5-8]\\d{8}",[9],0,"0",0,0,0,0,"528[89]"],ER:["291","00","[178]\\d{6}",[7],[["(\\d)(\\d{3})(\\d{3})","$1 $2 $3",["[178]"],"0$1"]],"0"],ES:["34","00","[5-9]\\d{8}",[9],[["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[89]00"]],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[5-9]"]]]],ET:["251","00","(?:11|[2-579]\\d)\\d{7}",[9],[["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[1-579]"],"0$1"]],"0"],FI:["358","00|99(?:[01469]|5(?:[14]1|3[23]|5[59]|77|88|9[09]))","[1-35689]\\d{4}|7\\d{10,11}|(?:[124-7]\\d|3[0-46-9])\\d{8}|[1-9]\\d{5,8}",[5,6,7,8,9,10,11,12],[["(\\d{5})","$1",["20[2-59]"],"0$1"],["(\\d{3})(\\d{3,7})","$1 $2",["(?:[1-3]0|[68])0|70[07-9]"],"0$1"],["(\\d{2})(\\d{4,8})","$1 $2",["[14]|2[09]|50|7[135]"],"0$1"],["(\\d{2})(\\d{6,10})","$1 $2",["7"],"0$1"],["(\\d)(\\d{4,9})","$1 $2",["(?:19|[2568])[1-8]|3(?:0[1-9]|[1-9])|9"],"0$1"]],"0",0,0,0,0,"1[03-79]|[2-9]",0,"00"],FJ:["679","0(?:0|52)","45\\d{5}|(?:0800\\d|[235-9])\\d{6}",[7,11],[["(\\d{3})(\\d{4})","$1 $2",["[235-9]|45"]],["(\\d{4})(\\d{3})(\\d{4})","$1 $2 $3",["0"]]],0,0,0,0,0,0,0,"00"],FK:["500","00","[2-7]\\d{4}",[5]],FM:["691","00","(?:[39]\\d\\d|820)\\d{4}",[7],[["(\\d{3})(\\d{4})","$1 $2",["[389]"]]]],FO:["298","00","[2-9]\\d{5}",[6],[["(\\d{6})","$1",["[2-9]"]]],0,0,"(10(?:01|[12]0|88))"],FR:["33","00","[1-9]\\d{8}",[9],[["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["8"],"0 $1"],["(\\d)(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4 $5",["[1-79]"],"0$1"]],"0"],GA:["241","00","(?:[067]\\d|11)\\d{6}|[2-7]\\d{6}",[7,8],[["(\\d)(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[2-7]"],"0$1"],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["0"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["11|[67]"],"0$1"]],0,0,"0(11\\d{6}|60\\d{6}|61\\d{6}|6[256]\\d{6}|7[467]\\d{6})","$1"],GB:["44","00","[1-357-9]\\d{9}|[18]\\d{8}|8\\d{6}",[7,9,10],[["(\\d{3})(\\d{4})","$1 $2",["800","8001","80011","800111","8001111"],"0$1"],["(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3",["845","8454","84546","845464"],"0$1"],["(\\d{3})(\\d{6})","$1 $2",["800"],"0$1"],["(\\d{5})(\\d{4,5})","$1 $2",["1(?:38|5[23]|69|76|94)","1(?:(?:38|69)7|5(?:24|39)|768|946)","1(?:3873|5(?:242|39[4-6])|(?:697|768)[347]|9467)"],"0$1"],["(\\d{4})(\\d{5,6})","$1 $2",["1(?:[2-69][02-9]|[78])"],"0$1"],["(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3",["[25]|7(?:0|6[02-9])","[25]|7(?:0|6(?:[03-9]|2[356]))"],"0$1"],["(\\d{4})(\\d{6})","$1 $2",["7"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["[1389]"],"0$1"]],"0",0,0,0,0,0,[["(?:1(?:1(?:3(?:[0-58]\\d\\d|73[0-35])|4(?:(?:[0-5]\\d|70)\\d|69[7-9])|(?:(?:5[0-26-9]|[78][0-49])\\d|6(?:[0-4]\\d|50))\\d)|(?:2(?:(?:0[024-9]|2[3-9]|3[3-79]|4[1-689]|[58][02-9]|6[0-47-9]|7[013-9]|9\\d)\\d|1(?:[0-7]\\d|8[0-3]))|(?:3(?:0\\d|1[0-8]|[25][02-9]|3[02-579]|[468][0-46-9]|7[1-35-79]|9[2-578])|4(?:0[03-9]|[137]\\d|[28][02-57-9]|4[02-69]|5[0-8]|[69][0-79])|5(?:0[1-35-9]|[16]\\d|2[024-9]|3[015689]|4[02-9]|5[03-9]|7[0-35-9]|8[0-468]|9[0-57-9])|6(?:0[034689]|1\\d|2[0-35689]|[38][013-9]|4[1-467]|5[0-69]|6[13-9]|7[0-8]|9[0-24578])|7(?:0[0246-9]|2\\d|3[0236-8]|4[03-9]|5[0-46-9]|6[013-9]|7[0-35-9]|8[024-9]|9[02-9])|8(?:0[35-9]|2[1-57-9]|3[02-578]|4[0-578]|5[124-9]|6[2-69]|7\\d|8[02-9]|9[02569])|9(?:0[02-589]|[18]\\d|2[02-689]|3[1-57-9]|4[2-9]|5[0-579]|6[2-47-9]|7[0-24578]|9[2-57]))\\d)\\d)|2(?:0[013478]|3[0189]|4[017]|8[0-46-9]|9[0-2])\\d{3})\\d{4}|1(?:2(?:0(?:46[1-4]|87[2-9])|545[1-79]|76(?:2\\d|3[1-8]|6[1-6])|9(?:7(?:2[0-4]|3[2-5])|8(?:2[2-8]|7[0-47-9]|8[3-5])))|3(?:6(?:38[2-5]|47[23])|8(?:47[04-9]|64[0157-9]))|4(?:044[1-7]|20(?:2[23]|8\\d)|6(?:0(?:30|5[2-57]|6[1-8]|7[2-8])|140)|8(?:052|87[1-3]))|5(?:2(?:4(?:3[2-79]|6\\d)|76\\d)|6(?:26[06-9]|686))|6(?:06(?:4\\d|7[4-79])|295[5-7]|35[34]\\d|47(?:24|61)|59(?:5[08]|6[67]|74)|9(?:55[0-4]|77[23]))|7(?:26(?:6[13-9]|7[0-7])|(?:442|688)\\d|50(?:2[0-3]|[3-68]2|76))|8(?:27[56]\\d|37(?:5[2-5]|8[239])|843[2-58])|9(?:0(?:0(?:6[1-8]|85)|52\\d)|3583|4(?:66[1-8]|9(?:2[01]|81))|63(?:23|3[1-4])|9561))\\d{3}",[9,10]],["7(?:457[0-57-9]|700[01]|911[028])\\d{5}|7(?:[1-3]\\d\\d|4(?:[0-46-9]\\d|5[0-689])|5(?:0[0-8]|[13-9]\\d|2[0-35-9])|7(?:0[1-9]|[1-7]\\d|8[02-9]|9[0-689])|8(?:[014-9]\\d|[23][0-8])|9(?:[024-9]\\d|1[02-9]|3[0-689]))\\d{6}",[10]],["80[08]\\d{7}|800\\d{6}|8001111"],["(?:8(?:4[2-5]|7[0-3])|9(?:[01]\\d|8[2-49]))\\d{7}|845464\\d",[7,10]],["70\\d{8}",[10]],0,["(?:3[0347]|55)\\d{8}",[10]],["76(?:464|652)\\d{5}|76(?:0[0-28]|2[356]|34|4[01347]|5[49]|6[0-369]|77|8[14]|9[139])\\d{6}",[10]],["56\\d{8}",[10]]],0," x"],GD:["1","011","(?:473|[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"([2-9]\\d{6})$|1","473$1",0,"473"],GE:["995","00","(?:[3-57]\\d\\d|800)\\d{6}",[9],[["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["70"],"0$1"],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["32"],"0$1"],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[57]"]],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[348]"],"0$1"]],"0"],GF:["594","00","(?:[56]94\\d|7093)\\d{5}|(?:80|9\\d)\\d{7}",[9],[["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[5-7]|9[47]"],"0$1"],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[89]"],"0$1"]],"0"],GG:["44","00","(?:1481|[357-9]\\d{3})\\d{6}|8\\d{6}(?:\\d{2})?",[7,9,10],0,"0",0,"([25-9]\\d{5})$|0","1481$1",0,0,[["1481[25-9]\\d{5}",[10]],["7(?:(?:781|839)\\d|911[17])\\d{5}",[10]],["80[08]\\d{7}|800\\d{6}|8001111"],["(?:8(?:4[2-5]|7[0-3])|9(?:[01]\\d|8[0-3]))\\d{7}|845464\\d",[7,10]],["70\\d{8}",[10]],0,["(?:3[0347]|55)\\d{8}",[10]],["76(?:464|652)\\d{5}|76(?:0[0-28]|2[356]|34|4[01347]|5[49]|6[0-369]|77|8[14]|9[139])\\d{6}",[10]],["56\\d{8}",[10]]]],GH:["233","00","(?:[235]\\d{3}|800)\\d{5}",[8,9],[["(\\d{3})(\\d{5})","$1 $2",["8"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[235]"],"0$1"]],"0"],GI:["350","00","(?:[25]\\d|60)\\d{6}",[8],[["(\\d{3})(\\d{5})","$1 $2",["2"]]]],GL:["299","00","(?:19|[2-689]\\d|70)\\d{4}",[6],[["(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3",["19|[2-9]"]]]],GM:["220","00","[2-9]\\d{6}",[7],[["(\\d{3})(\\d{4})","$1 $2",["[2-9]"]]]],GN:["224","00","722\\d{6}|(?:3|6\\d)\\d{7}",[8,9],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["3"]],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[67]"]]]],GP:["590","00","(?:590\\d|7090)\\d{5}|(?:69|80|9\\d)\\d{7}",[9],[["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[5-79]"],"0$1"],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["8"],"0$1"]],"0",0,0,0,0,0,[["590(?:0[1-68]|[14][0-24-9]|2[0-68]|3[1-9]|5[3-579]|[68][0-689]|7[08]|9\\d)\\d{4}"],["(?:69(?:0\\d\\d|1(?:2[2-9]|3[0-5])|4(?:0[89]|1[2-6]|9\\d)|6(?:1[016-9]|5[0-4]|[67]\\d))|7090[0-4])\\d{4}"],["80[0-5]\\d{6}"],0,0,0,0,0,["9(?:(?:39[5-7]|76[018])\\d|475[0-6])\\d{4}"]]],GQ:["240","00","222\\d{6}|(?:3\\d|55|[89]0)\\d{7}",[9],[["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[235]"]],["(\\d{3})(\\d{6})","$1 $2",["[89]"]]]],GR:["30","00","5005000\\d{3}|8\\d{9,11}|(?:[269]\\d|70)\\d{8}",[10,11,12],[["(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3",["21|7"]],["(\\d{4})(\\d{6})","$1 $2",["2(?:2|3[2-57-9]|4[2-469]|5[2-59]|6[2-9]|7[2-69]|8[2-49])|5"]],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["[2689]"]],["(\\d{3})(\\d{3,4})(\\d{5})","$1 $2 $3",["8"]]]],GT:["502","00","80\\d{6}|(?:1\\d{3}|[2-7])\\d{7}",[8,11],[["(\\d{4})(\\d{4})","$1 $2",["[2-8]"]],["(\\d{4})(\\d{3})(\\d{4})","$1 $2 $3",["1"]]]],GU:["1","011","(?:[58]\\d\\d|671|900)\\d{7}",[10],0,"1",0,"([2-9]\\d{6})$|1","671$1",0,"671"],GW:["245","00","[49]\\d{8}|4\\d{6}",[7,9],[["(\\d{3})(\\d{4})","$1 $2",["40"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[49]"]]]],GY:["592","001","(?:[2-8]\\d{3}|9008)\\d{3}",[7],[["(\\d{3})(\\d{4})","$1 $2",["[2-9]"]]]],HK:["852","00(?:30|5[09]|[126-9]?)","8[0-46-9]\\d{6,7}|9\\d{4,7}|(?:[2-7]|9\\d{3})\\d{7}",[5,6,7,8,9,11],[["(\\d{3})(\\d{2,5})","$1 $2",["900","9003"]],["(\\d{4})(\\d{4})","$1 $2",["[2-7]|8[1-4]|9(?:0[1-9]|[1-8])"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["8"]],["(\\d{3})(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3 $4",["9"]]],0,0,0,0,0,0,0,"00"],HN:["504","00","8\\d{10}|[237-9]\\d{7}",[8,11],[["(\\d{4})(\\d{4})","$1-$2",["[237-9]"]]]],HR:["385","00","[2-69]\\d{8}|80\\d{5,7}|[1-79]\\d{7}|6\\d{6}",[7,8,9],[["(\\d{2})(\\d{2})(\\d{3})","$1 $2 $3",["6[01]"],"0$1"],["(\\d{3})(\\d{2})(\\d{2,3})","$1 $2 $3",["8"],"0$1"],["(\\d)(\\d{4})(\\d{3})","$1 $2 $3",["1"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["6|7[245]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["9"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[2-57]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["8"],"0$1"]],"0"],HT:["509","00","(?:[2-489]\\d|55)\\d{6}",[8],[["(\\d{2})(\\d{2})(\\d{4})","$1 $2 $3",["[2-589]"]]]],HU:["36","00","[235-7]\\d{8}|[1-9]\\d{7}",[8,9],[["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["1"],"(06 $1)"],["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["[27][2-9]|3[2-7]|4[24-9]|5[2-79]|6|8[2-57-9]|9[2-69]"],"(06 $1)"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[2-9]"],"06 $1"]],"06"],ID:["62","00[89]","00[1-9]\\d{9,14}|(?:[1-36]|8\\d{5})\\d{6}|00\\d{9}|[1-9]\\d{8,10}|[2-9]\\d{7}",[7,8,9,10,11,12,13,14,15,16,17],[["(\\d)(\\d{3})(\\d{3})","$1 $2 $3",["15"]],["(\\d{2})(\\d{5,9})","$1 $2",["2[124]|[36]1"],"(0$1)"],["(\\d{3})(\\d{5,7})","$1 $2",["800"],"0$1"],["(\\d{3})(\\d{5,8})","$1 $2",["[2-79]"],"(0$1)"],["(\\d{3})(\\d{3,4})(\\d{3})","$1-$2-$3",["8[1-35-9]"],"0$1"],["(\\d{3})(\\d{6,8})","$1 $2",["1"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["804"],"0$1"],["(\\d{3})(\\d)(\\d{3})(\\d{3})","$1 $2 $3 $4",["80"],"0$1"],["(\\d{3})(\\d{4})(\\d{4,5})","$1-$2-$3",["8"],"0$1"]],"0"],IE:["353","00","(?:1\\d|[2569])\\d{6,8}|4\\d{6,9}|7\\d{8}|8\\d{8,9}",[7,8,9,10],[["(\\d{2})(\\d{5})","$1 $2",["2[24-9]|47|58|6[237-9]|9[35-9]"],"(0$1)"],["(\\d{3})(\\d{5})","$1 $2",["[45]0"],"(0$1)"],["(\\d)(\\d{3,4})(\\d{4})","$1 $2 $3",["1"],"(0$1)"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[2569]|4[1-69]|7[14]"],"(0$1)"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["70"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["81"],"(0$1)"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[78]"],"0$1"],["(\\d{4})(\\d{3})(\\d{3})","$1 $2 $3",["1"]],["(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3",["4"],"(0$1)"],["(\\d{2})(\\d)(\\d{3})(\\d{4})","$1 $2 $3 $4",["8"],"0$1"]],"0"],IL:["972","0(?:0|1[2-9])","1\\d{6}(?:\\d{3,5})?|[57]\\d{8}|[1-489]\\d{7}",[7,8,9,10,11,12],[["(\\d{4})(\\d{3})","$1-$2",["125"]],["(\\d{4})(\\d{2})(\\d{2})","$1-$2-$3",["121"]],["(\\d)(\\d{3})(\\d{4})","$1-$2-$3",["[2-489]"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1-$2-$3",["[57]"],"0$1"],["(\\d{4})(\\d{3})(\\d{3})","$1-$2-$3",["12"]],["(\\d{4})(\\d{6})","$1-$2",["159"]],["(\\d)(\\d{3})(\\d{3})(\\d{3})","$1-$2-$3-$4",["1[7-9]"]],["(\\d{3})(\\d{1,2})(\\d{3})(\\d{4})","$1-$2 $3-$4",["15"]]],"0"],IM:["44","00","1624\\d{6}|(?:[3578]\\d|90)\\d{8}",[10],0,"0",0,"([25-8]\\d{5})$|0","1624$1",0,"74576|(?:16|7[56])24"],IN:["91","00","(?:000800|[2-9]\\d\\d)\\d{7}|1\\d{7,12}",[8,9,10,11,12,13],[["(\\d{8})","$1",["5(?:0|2[23]|3[03]|[67]1|88)","5(?:0|2(?:21|3)|3(?:0|3[23])|616|717|888)","5(?:0|2(?:21|3)|3(?:0|3[23])|616|717|8888)"],0,1],["(\\d{4})(\\d{4,5})","$1 $2",["180","1800"],0,1],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["140"],0,1],["(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3",["11|2[02]|33|4[04]|79[1-7]|80[2-46]","11|2[02]|33|4[04]|79(?:[1-6]|7[19])|80(?:[2-4]|6[0-589])","11|2[02]|33|4[04]|79(?:[124-6]|3(?:[02-9]|1[0-24-9])|7(?:1|9[1-6]))|80(?:[2-4]|6[0-589])"],"0$1",1],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["1(?:2[0-249]|3[0-25]|4[145]|[68]|7[1257])|2(?:1[257]|3[013]|4[01]|5[0137]|6[0158]|78|8[1568])|3(?:26|4[1-3]|5[34]|6[01489]|7[02-46]|8[159])|4(?:1[36]|2[1-47]|5[12]|6[0-26-9]|7[0-24-9]|8[013-57]|9[014-7])|5(?:1[025]|22|[36][25]|4[28]|5[12]|[78]1)|6(?:12|[2-4]1|5[17]|6[13]|80)|7(?:12|3[134]|4[47]|61|88)|8(?:16|2[014]|3[126]|6[136]|7[078]|8[34]|91)|(?:43|59|75)[15]|(?:1[59]|29|67|72)[14]","1(?:2[0-24]|3[0-25]|4[145]|[59][14]|6[1-9]|7[1257]|8[1-57-9])|2(?:1[257]|3[013]|4[01]|5[0137]|6[058]|78|8[1568]|9[14])|3(?:26|4[1-3]|5[34]|6[01489]|7[02-46]|8[159])|4(?:1[36]|2[1-47]|3[15]|5[12]|6[0-26-9]|7[0-24-9]|8[013-57]|9[014-7])|5(?:1[025]|22|[36][25]|4[28]|[578]1|9[15])|674|7(?:(?:2[14]|3[34]|5[15])[2-6]|61[346]|88[0-8])|8(?:70[2-6]|84[235-7]|91[3-7])|(?:1(?:29|60|8[06])|261|552|6(?:12|[2-47]1|5[17]|6[13]|80)|7(?:12|31|4[47])|8(?:16|2[014]|3[126]|6[136]|7[78]|83))[2-7]","1(?:2[0-24]|3[0-25]|4[145]|[59][14]|6[1-9]|7[1257]|8[1-57-9])|2(?:1[257]|3[013]|4[01]|5[0137]|6[058]|78|8[1568]|9[14])|3(?:26|4[1-3]|5[34]|6[01489]|7[02-46]|8[159])|4(?:1[36]|2[1-47]|3[15]|5[12]|6[0-26-9]|7[0-24-9]|8[013-57]|9[014-7])|5(?:1[025]|22|[36][25]|4[28]|[578]1|9[15])|6(?:12(?:[2-6]|7[0-8])|74[2-7])|7(?:(?:2[14]|5[15])[2-6]|3171|61[346]|88(?:[2-7]|82))|8(?:70[2-6]|84(?:[2356]|7[19])|91(?:[3-6]|7[19]))|73[134][2-6]|(?:74[47]|8(?:16|2[014]|3[126]|6[136]|7[78]|83))(?:[2-6]|7[19])|(?:1(?:29|60|8[06])|261|552|6(?:[2-4]1|5[17]|6[13]|7(?:1|4[0189])|80)|7(?:12|88[01]))[2-7]"],"0$1",1],["(\\d{4})(\\d{3})(\\d{3})","$1 $2 $3",["1(?:[2-479]|5[0235-9])|[2-5]|6(?:1[1358]|2[2457-9]|3[2-5]|4[235-7]|5[2-689]|6[24578]|7[235689]|8[1-6])|7(?:1[013-9]|28|3[129]|4[1-35689]|5[29]|6[02-5]|70)|807","1(?:[2-479]|5[0235-9])|[2-5]|6(?:1[1358]|2(?:[2457]|84|95)|3(?:[2-4]|55)|4[235-7]|5[2-689]|6[24578]|7[235689]|8[1-6])|7(?:1(?:[013-8]|9[6-9])|28[6-8]|3(?:17|2[0-49]|9[2-57])|4(?:1[2-4]|[29][0-7]|3[0-8]|[56]|8[0-24-7])|5(?:2[1-3]|9[0-6])|6(?:0[5689]|2[5-9]|3[02-8]|4|5[0-367])|70[13-7])|807[19]","1(?:[2-479]|5(?:[0236-9]|5[013-9]))|[2-5]|6(?:2(?:84|95)|355|83)|73179|807(?:1|9[1-3])|(?:1552|6(?:1[1358]|2[2457]|3[2-4]|4[235-7]|5[2-689]|6[24578]|7[235689]|8[124-6])\\d|7(?:1(?:[013-8]\\d|9[6-9])|28[6-8]|3(?:2[0-49]|9[2-57])|4(?:1[2-4]|[29][0-7]|3[0-8]|[56]\\d|8[0-24-7])|5(?:2[1-3]|9[0-6])|6(?:0[5689]|2[5-9]|3[02-8]|4\\d|5[0-367])|70[13-7]))[2-7]"],"0$1",1],["(\\d{5})(\\d{5})","$1 $2",["[6-9]"],"0$1",1],["(\\d{4})(\\d{2,4})(\\d{4})","$1 $2 $3",["1(?:6|8[06])","1(?:6|8[06]0)"],0,1],["(\\d{4})(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3 $4",["18"],0,1]],"0"],IO:["246","00","3\\d{6}",[7],[["(\\d{3})(\\d{4})","$1 $2",["3"]]]],IQ:["964","00","(?:1|7\\d\\d)\\d{7}|[2-6]\\d{7,8}",[8,9,10],[["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["1"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[2-6]"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["7"],"0$1"]],"0"],IR:["98","00","[1-9]\\d{9}|(?:[1-8]\\d\\d|9)\\d{3,4}",[4,5,6,7,10],[["(\\d{4,5})","$1",["96"],"0$1"],["(\\d{2})(\\d{4,5})","$1 $2",["(?:1[137]|2[13-68]|3[1458]|4[145]|5[1468]|6[16]|7[1467]|8[13467])[12689]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["9"],"0$1"],["(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3",["[1-8]"],"0$1"]],"0"],IS:["354","00|1(?:0(?:01|[12]0)|100)","(?:38\\d|[4-9])\\d{6}",[7,9],[["(\\d{3})(\\d{4})","$1 $2",["[4-9]"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["3"]]],0,0,0,0,0,0,0,"00"],IT:["39","00","0\\d{5,10}|1\\d{8,10}|3(?:[0-8]\\d{7,10}|9\\d{7,8})|(?:43|55|70)\\d{8}|8\\d{5}(?:\\d{2,4})?",[6,7,8,9,10,11,12],[["(\\d{2})(\\d{4,6})","$1 $2",["0[26]"]],["(\\d{3})(\\d{3,6})","$1 $2",["0[13-57-9][0159]|8(?:03|4[17]|9[2-5])","0[13-57-9][0159]|8(?:03|4[17]|9(?:2|3[04]|[45][0-4]))"]],["(\\d{4})(\\d{2,6})","$1 $2",["0(?:[13-579][2-46-8]|8[236-8])"]],["(\\d{4})(\\d{4})","$1 $2",["894"]],["(\\d{2})(\\d{3,4})(\\d{4})","$1 $2 $3",["0[26]|5"]],["(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["1(?:44|[679])|[378]|43"]],["(\\d{3})(\\d{3,4})(\\d{4})","$1 $2 $3",["0[13-57-9][0159]|14"]],["(\\d{2})(\\d{4})(\\d{5})","$1 $2 $3",["0[26]"]],["(\\d{4})(\\d{3})(\\d{4})","$1 $2 $3",["0"]],["(\\d{3})(\\d{4})(\\d{4,5})","$1 $2 $3",["3"]]],0,0,0,0,0,0,[["0669[0-79]\\d{1,6}|0(?:1(?:[0159]\\d|[27][1-5]|31|4[1-4]|6[1356]|8[2-57])|2\\d\\d|3(?:[0159]\\d|2[1-4]|3[12]|[48][1-6]|6[2-59]|7[1-7])|4(?:[0159]\\d|[23][1-9]|4[245]|6[1-5]|7[1-4]|81)|5(?:[0159]\\d|2[1-5]|3[2-6]|4[1-79]|6[4-6]|7[1-578]|8[3-8])|6(?:[0-57-9]\\d|6[0-8])|7(?:[0159]\\d|2[12]|3[1-7]|4[2-46]|6[13569]|7[13-6]|8[1-59])|8(?:[0159]\\d|2[3-578]|3[1-356]|[6-8][1-5])|9(?:[0159]\\d|[238][1-5]|4[12]|6[1-8]|7[1-6]))\\d{2,7}",[6,7,8,9,10,11]],["3[2-9]\\d{7,8}|(?:31|43)\\d{8}",[9,10]],["80(?:0\\d{3}|3)\\d{3}",[6,9]],["(?:0878\\d{3}|89(?:2\\d|3[04]|4(?:[0-4]|[5-9]\\d\\d)|5[0-4]))\\d\\d|(?:1(?:44|6[346])|89(?:38|5[5-9]|9))\\d{6}",[6,8,9,10]],["1(?:78\\d|99)\\d{6}",[9,10]],["3[2-8]\\d{9,10}",[11,12]],0,0,["55\\d{8}",[10]],["84(?:[08]\\d{3}|[17])\\d{3}",[6,9]]]],JE:["44","00","1534\\d{6}|(?:[3578]\\d|90)\\d{8}",[10],0,"0",0,"([0-24-8]\\d{5})$|0","1534$1",0,0,[["1534[0-24-8]\\d{5}"],["7(?:(?:(?:50|82)9|937)\\d|7(?:00[378]|97\\d))\\d{5}"],["80(?:07(?:35|81)|8901)\\d{4}"],["(?:8(?:4(?:4(?:4(?:05|42|69)|703)|5(?:041|800))|7(?:0002|1206))|90(?:066[59]|1810|71(?:07|55)))\\d{4}"],["701511\\d{4}"],0,["(?:3(?:0(?:07(?:35|81)|8901)|3\\d{4}|4(?:4(?:4(?:05|42|69)|703)|5(?:041|800))|7(?:0002|1206))|55\\d{4})\\d{4}"],["76(?:464|652)\\d{5}|76(?:0[0-28]|2[356]|34|4[01347]|5[49]|6[0-369]|77|8[14]|9[139])\\d{6}"],["56\\d{8}"]]],JM:["1","011","(?:[58]\\d\\d|658|900)\\d{7}",[10],0,"1",0,0,0,0,"658|876"],JO:["962","00","(?:(?:[2689]|7\\d)\\d|32|53)\\d{6}",[8,9],[["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["[2356]|87"],"(0$1)"],["(\\d{3})(\\d{5,6})","$1 $2",["[89]"],"0$1"],["(\\d{2})(\\d{7})","$1 $2",["70"],"0$1"],["(\\d)(\\d{4})(\\d{4})","$1 $2 $3",["7"],"0$1"]],"0"],JP:["81","010","00[1-9]\\d{6,14}|[257-9]\\d{9}|(?:00|[1-9]\\d\\d)\\d{6}",[8,9,10,11,12,13,14,15,16,17],[["(\\d{3})(\\d{3})(\\d{3})","$1-$2-$3",["(?:12|57|99)0"],"0$1"],["(\\d{4})(\\d)(\\d{4})","$1-$2-$3",["1(?:26|3[79]|4[56]|5[4-68]|6[3-5])|499|5(?:76|97)|746|8(?:3[89]|47|51)|9(?:80|9[16])","1(?:267|3(?:7[247]|9[278])|466|5(?:47|58|64)|6(?:3[245]|48|5[4-68]))|499[2468]|5(?:76|97)9|7468|8(?:3(?:8[7-9]|96)|477|51[2-9])|9(?:802|9(?:1[23]|69))|1(?:45|58)[67]","1(?:267|3(?:7[247]|9[278])|466|5(?:47|58|64)|6(?:3[245]|48|5[4-68]))|499[2468]|5(?:769|979[2-69])|7468|8(?:3(?:8[7-9]|96[2457-9])|477|51[2-9])|9(?:802|9(?:1[23]|69))|1(?:45|58)[67]"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1-$2-$3",["60"],"0$1"],["(\\d)(\\d{4})(\\d{4})","$1-$2-$3",["[36]|4(?:2[09]|7[01])","[36]|4(?:2(?:0|9[02-69])|7(?:0[019]|1))"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1-$2-$3",["1(?:1|5[45]|77|88|9[69])|2(?:2[1-37]|3[0-269]|4[59]|5|6[24]|7[1-358]|8[1369]|9[0-38])|4(?:[28][1-9]|3[0-57]|[45]|6[248]|7[2-579]|9[29])|5(?:2|3[0459]|4[0-369]|5[29]|8[02389]|9[0-389])|7(?:2[02-46-9]|34|[58]|6[0249]|7[57]|9[2-6])|8(?:2[124589]|3[26-9]|49|51|6|7[0-468]|8[68]|9[019])|9(?:[23][1-9]|4[15]|5[138]|6[1-3]|7[156]|8[189]|9[1-489])","1(?:1|5(?:4[018]|5[017])|77|88|9[69])|2(?:2(?:[127]|3[014-9])|3[0-269]|4[59]|5(?:[1-3]|5[0-69]|9[19])|62|7(?:[1-35]|8[0189])|8(?:[16]|3[0134]|9[0-5])|9(?:[028]|17))|4(?:2(?:[13-79]|8[014-6])|3[0-57]|[45]|6[248]|7[2-47]|8[1-9]|9[29])|5(?:2|3(?:[045]|9[0-8])|4[0-369]|5[29]|8[02389]|9[0-3])|7(?:2[02-46-9]|34|[58]|6[0249]|7[57]|9(?:[23]|4[0-59]|5[01569]|6[0167]))|8(?:2(?:[1258]|4[0-39]|9[0-2469])|3(?:[29]|60)|49|51|6(?:[0-24]|36|5[0-3589]|7[23]|9[01459])|7[0-468]|8[68])|9(?:[23][1-9]|4[15]|5[138]|6[1-3]|7[156]|8[189]|9(?:[1289]|3[34]|4[0178]))|(?:264|837)[016-9]|2(?:57|93)[015-9]|(?:25[0468]|422|838)[01]|(?:47[59]|59[89]|8(?:6[68]|9))[019]","1(?:1|5(?:4[018]|5[017])|77|88|9[69])|2(?:2[127]|3[0-269]|4[59]|5(?:[1-3]|5[0-69]|9(?:17|99))|6(?:2|4[016-9])|7(?:[1-35]|8[0189])|8(?:[16]|3[0134]|9[0-5])|9(?:[028]|17))|4(?:2(?:[13-79]|8[014-6])|3[0-57]|[45]|6[248]|7[2-47]|9[29])|5(?:2|3(?:[045]|9(?:[0-58]|6[4-9]|7[0-35689]))|4[0-369]|5[29]|8[02389]|9[0-3])|7(?:2[02-46-9]|34|[58]|6[0249]|7[57]|9(?:[23]|4[0-59]|5[01569]|6[0167]))|8(?:2(?:[1258]|4[0-39]|9[0169])|3(?:[29]|60|7(?:[017-9]|6[6-8]))|49|51|6(?:[0-24]|36[2-57-9]|5(?:[0-389]|5[23])|6(?:[01]|9[178])|7(?:2[2-468]|3[78])|9[0145])|7[0-468]|8[68])|9(?:4[15]|5[138]|7[156]|8[189]|9(?:[1289]|3(?:31|4[357])|4[0178]))|(?:8294|96)[1-3]|2(?:57|93)[015-9]|(?:223|8699)[014-9]|(?:25[0468]|422|838)[01]|(?:48|8292|9[23])[1-9]|(?:47[59]|59[89]|8(?:68|9))[019]"],"0$1"],["(\\d{3})(\\d{2})(\\d{4})","$1-$2-$3",["[14]|[289][2-9]|5[3-9]|7[2-4679]"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1-$2-$3",["800"],"0$1"],["(\\d{2})(\\d{4})(\\d{4})","$1-$2-$3",["[257-9]"],"0$1"]],"0",0,"(000[259]\\d{6})$|(?:(?:003768)0?)|0","$1"],KE:["254","000","(?:[17]\\d\\d|900)\\d{6}|(?:2|80)0\\d{6,7}|[4-6]\\d{6,8}",[7,8,9,10],[["(\\d{2})(\\d{5,7})","$1 $2",["[24-6]"],"0$1"],["(\\d{3})(\\d{6})","$1 $2",["[17]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["[89]"],"0$1"]],"0"],KG:["996","00","8\\d{9}|[235-9]\\d{8}",[9,10],[["(\\d{4})(\\d{5})","$1 $2",["3(?:1[346]|[24-79])"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[235-79]|88"],"0$1"],["(\\d{3})(\\d{3})(\\d)(\\d{2,3})","$1 $2 $3 $4",["8"],"0$1"]],"0"],KH:["855","00[14-9]","1\\d{9}|[1-9]\\d{7,8}",[8,9,10],[["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[1-9]"],"0$1"],["(\\d{4})(\\d{3})(\\d{3})","$1 $2 $3",["1"]]],"0"],KI:["686","00","(?:[37]\\d|6[0-79])\\d{6}|(?:[2-48]\\d|50)\\d{3}",[5,8],0,"0"],KM:["269","00","[3478]\\d{6}",[7],[["(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3",["[3478]"]]]],KN:["1","011","(?:[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"([2-7]\\d{6})$|1","869$1",0,"869"],KP:["850","00|99","85\\d{6}|(?:19\\d|[2-7])\\d{7}",[8,10],[["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["8"],"0$1"],["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["[2-7]"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["1"],"0$1"]],"0"],KR:["82","00(?:[125689]|3(?:[46]5|91)|7(?:00|27|3|55|6[126]))","00[1-9]\\d{8,11}|(?:[12]|5\\d{3})\\d{7}|[13-6]\\d{9}|(?:[1-6]\\d|80)\\d{7}|[3-6]\\d{4,5}|(?:00|7)0\\d{8}",[5,6,8,9,10,11,12,13,14],[["(\\d{2})(\\d{3,4})","$1-$2",["(?:3[1-3]|[46][1-4]|5[1-5])1"],"0$1"],["(\\d{4})(\\d{4})","$1-$2",["1"]],["(\\d)(\\d{3,4})(\\d{4})","$1-$2-$3",["2"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1-$2-$3",["[36]0|8"],"0$1"],["(\\d{2})(\\d{3,4})(\\d{4})","$1-$2-$3",["[1346]|5[1-5]"],"0$1"],["(\\d{2})(\\d{4})(\\d{4})","$1-$2-$3",["[57]"],"0$1"],["(\\d{2})(\\d{5})(\\d{4})","$1-$2-$3",["5"],"0$1"]],"0",0,"0(8(?:[1-46-8]|5\\d\\d))?"],KW:["965","00","18\\d{5}|(?:[2569]\\d|41)\\d{6}",[7,8],[["(\\d{4})(\\d{3,4})","$1 $2",["[169]|2(?:[235]|4[1-35-9])|52"]],["(\\d{3})(\\d{5})","$1 $2",["[245]"]]]],KY:["1","011","(?:345|[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"([2-9]\\d{6})$|1","345$1",0,"345"],KZ:["7","810","(?:33622|8\\d{8})\\d{5}|[78]\\d{9}",[10,14],0,"8",0,0,0,0,"33|7",0,"8~10"],LA:["856","00","[23]\\d{9}|3\\d{8}|(?:[235-8]\\d|41)\\d{6}",[8,9,10],[["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["2[13]|3[14]|[4-8]"],"0$1"],["(\\d{2})(\\d{2})(\\d{2})(\\d{3})","$1 $2 $3 $4",["3"],"0$1"],["(\\d{2})(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3 $4",["[23]"],"0$1"]],"0"],LB:["961","00","[27-9]\\d{7}|[13-9]\\d{6}",[7,8],[["(\\d)(\\d{3})(\\d{3})","$1 $2 $3",["[13-69]|7(?:[2-57]|62|8[0-7]|9[04-9])|8[02-9]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["[27-9]"]]],"0"],LC:["1","011","(?:[58]\\d\\d|758|900)\\d{7}",[10],0,"1",0,"([2-8]\\d{6})$|1","758$1",0,"758"],LI:["423","00","[68]\\d{8}|(?:[2378]\\d|90)\\d{5}",[7,9],[["(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3",["[2379]|8(?:0[09]|7)","[2379]|8(?:0(?:02|9)|7)"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["8"]],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["69"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["6"]]],"0",0,"(1001)|0"],LK:["94","00","[1-9]\\d{8}",[9],[["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["7"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[1-689]"],"0$1"]],"0"],LR:["231","00","(?:[245]\\d|33|77|88)\\d{7}|(?:2\\d|[4-6])\\d{6}",[7,8,9],[["(\\d)(\\d{3})(\\d{3})","$1 $2 $3",["4[67]|[56]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["2"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[2-578]"],"0$1"]],"0"],LS:["266","00","(?:[256]\\d\\d|800)\\d{5}",[8],[["(\\d{4})(\\d{4})","$1 $2",["[2568]"]]]],LT:["370","00","(?:[3469]\\d|52|[78]0)\\d{6}",[8],[["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["52[0-7]"],"(0-$1)",1],["(\\d{3})(\\d{2})(\\d{3})","$1 $2 $3",["[7-9]"],"0 $1",1],["(\\d{2})(\\d{6})","$1 $2",["37|4(?:[15]|6[1-8])"],"(0-$1)",1],["(\\d{3})(\\d{5})","$1 $2",["[3-6]"],"(0-$1)",1]],"0",0,"[08]"],LU:["352","00","35[013-9]\\d{4,8}|6\\d{8}|35\\d{2,4}|(?:[2457-9]\\d|3[0-46-9])\\d{2,9}",[4,5,6,7,8,9,10,11],[["(\\d{2})(\\d{3})","$1 $2",["2(?:0[2-689]|[2-9])|[3-57]|8(?:0[2-9]|[13-9])|9(?:0[89]|[2-579])"]],["(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3",["2(?:0[2-689]|[2-9])|[3-57]|8(?:0[2-9]|[13-9])|9(?:0[89]|[2-579])"]],["(\\d{2})(\\d{2})(\\d{3})","$1 $2 $3",["20[2-689]"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{1,2})","$1 $2 $3 $4",["2(?:[0367]|4[3-8])"]],["(\\d{3})(\\d{2})(\\d{3})","$1 $2 $3",["80[01]|90[015]"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{3})","$1 $2 $3 $4",["20"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["6"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{1,2})","$1 $2 $3 $4 $5",["2(?:[0367]|4[3-8])"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{1,5})","$1 $2 $3 $4",["[3-57]|8[13-9]|9(?:0[89]|[2-579])|(?:2|80)[2-9]"]]],0,0,"(15(?:0[06]|1[12]|[35]5|4[04]|6[26]|77|88|99)\\d)"],LV:["371","00","(?:[268]\\d|90)\\d{6}",[8],[["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["[269]|8[01]"]]]],LY:["218","00","[2-9]\\d{8}",[9],[["(\\d{2})(\\d{7})","$1-$2",["[2-9]"],"0$1"]],"0"],MA:["212","00","[5-8]\\d{8}",[9],[["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["5[45]"],"0$1"],["(\\d{4})(\\d{5})","$1-$2",["5(?:2[2-46-9]|3[3-9]|9)|8(?:0[89]|92)"],"0$1"],["(\\d{2})(\\d{7})","$1-$2",["8"],"0$1"],["(\\d{3})(\\d{6})","$1-$2",["[5-7]"],"0$1"]],"0",0,0,0,0,0,[["5(?:2(?:[0-25-79]\\d|3[1-578]|4[02-46-8]|8[0235-7])|3(?:[0-47]\\d|5[02-9]|6[02-8]|8[014-9]|9[3-9])|(?:4[067]|5[03])\\d)\\d{5}"],["(?:6(?:[0-79]\\d|8[0-247-9])|7(?:[0167]\\d|2[0-467]|5[0-3]|8[0-7]))\\d{6}"],["80[0-7]\\d{6}"],["89\\d{7}"],0,0,0,0,["(?:592(?:4[0-2]|93)|80[89]\\d\\d)\\d{4}"]]],MC:["377","00","(?:[3489]|6\\d)\\d{7}",[8,9],[["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["4"],"0$1"],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[389]"]],["(\\d)(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4 $5",["6"],"0$1"]],"0"],MD:["373","00","(?:[235-7]\\d|[89]0)\\d{6}",[8],[["(\\d{3})(\\d{5})","$1 $2",["[89]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["22|3"],"0$1"],["(\\d{3})(\\d{2})(\\d{3})","$1 $2 $3",["[25-7]"],"0$1"]],"0"],ME:["382","00","(?:20|[3-79]\\d)\\d{6}|80\\d{6,7}",[8,9],[["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[2-9]"],"0$1"]],"0"],MF:["590","00","(?:590\\d|7090)\\d{5}|(?:69|80|9\\d)\\d{7}",[9],0,"0",0,0,0,0,0,[["590(?:0[079]|[14]3|[27][79]|3[03-7]|5[0-268]|87)\\d{4}"],["(?:69(?:0\\d\\d|1(?:2[2-9]|3[0-5])|4(?:0[89]|1[2-6]|9\\d)|6(?:1[016-9]|5[0-4]|[67]\\d))|7090[0-4])\\d{4}"],["80[0-5]\\d{6}"],0,0,0,0,0,["9(?:(?:39[5-7]|76[018])\\d|475[0-6])\\d{4}"]]],MG:["261","00","[23]\\d{8}",[9],[["(\\d{2})(\\d{2})(\\d{3})(\\d{2})","$1 $2 $3 $4",["[23]"],"0$1"]],"0",0,"([24-9]\\d{6})$|0","20$1"],MH:["692","011","329\\d{4}|(?:[256]\\d|45)\\d{5}",[7],[["(\\d{3})(\\d{4})","$1-$2",["[2-6]"]]],"1"],MK:["389","00","[2-578]\\d{7}",[8],[["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["2|34[47]|4(?:[37]7|5[47]|64)"],"0$1"],["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["[347]"],"0$1"],["(\\d{3})(\\d)(\\d{2})(\\d{2})","$1 $2 $3 $4",["[58]"],"0$1"]],"0"],ML:["223","00","[24-9]\\d{7}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[24-9]"]]]],MM:["95","00","1\\d{5,7}|95\\d{6}|(?:[4-7]|9[0-46-9])\\d{6,8}|(?:2|8\\d)\\d{5,8}",[6,7,8,9,10],[["(\\d)(\\d{2})(\\d{3})","$1 $2 $3",["16|2"],"0$1"],["(\\d{2})(\\d{2})(\\d{3})","$1 $2 $3",["4(?:[2-46]|5[3-5])|5|6(?:[1-689]|7[235-7])|7(?:[0-4]|5[2-7])|8[1-5]|(?:60|86)[23]"],"0$1"],["(\\d)(\\d{3})(\\d{3,4})","$1 $2 $3",["[12]|452|678|86","[12]|452|6788|86"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[4-7]|8[1-35]"],"0$1"],["(\\d)(\\d{3})(\\d{4,6})","$1 $2 $3",["9(?:2[0-4]|[35-9]|4[137-9])"],"0$1"],["(\\d)(\\d{4})(\\d{4})","$1 $2 $3",["2"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["8"],"0$1"],["(\\d)(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3 $4",["92"],"0$1"],["(\\d)(\\d{5})(\\d{4})","$1 $2 $3",["9"],"0$1"]],"0"],MN:["976","001","[12]\\d{7,9}|[5-9]\\d{7}",[8,9,10],[["(\\d{2})(\\d{2})(\\d{4})","$1 $2 $3",["[12]1"],"0$1"],["(\\d{4})(\\d{4})","$1 $2",["[5-9]"]],["(\\d{3})(\\d{5,6})","$1 $2",["[12]2[1-3]"],"0$1"],["(\\d{4})(\\d{5,6})","$1 $2",["[12](?:27|3[2-8]|4[2-68]|5[1-4689])","[12](?:27|3[2-8]|4[2-68]|5[1-4689])[0-3]"],"0$1"],["(\\d{5})(\\d{4,5})","$1 $2",["[12]"],"0$1"]],"0"],MO:["853","00","0800\\d{3}|(?:28|[68]\\d)\\d{6}",[7,8],[["(\\d{4})(\\d{3})","$1 $2",["0"]],["(\\d{4})(\\d{4})","$1 $2",["[268]"]]]],MP:["1","011","[58]\\d{9}|(?:67|90)0\\d{7}",[10],0,"1",0,"([2-9]\\d{6})$|1","670$1",0,"670"],MQ:["596","00","(?:596\\d|7091)\\d{5}|(?:69|[89]\\d)\\d{7}",[9],[["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[5-79]|8(?:0[6-9]|[36])"],"0$1"],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["8"],"0$1"]],"0"],MR:["222","00","(?:[2-4]\\d\\d|800)\\d{5}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[2-48]"]]]],MS:["1","011","(?:[58]\\d\\d|664|900)\\d{7}",[10],0,"1",0,"([34]\\d{6})$|1","664$1",0,"664"],MT:["356","00","3550\\d{4}|(?:[2579]\\d\\d|800)\\d{5}",[8],[["(\\d{4})(\\d{4})","$1 $2",["[2357-9]"]]]],MU:["230","0(?:0|[24-7]0|3[03])","(?:[57]|8\\d\\d)\\d{7}|[2-468]\\d{6}",[7,8,10],[["(\\d{3})(\\d{4})","$1 $2",["[2-46]|8[013]"]],["(\\d{4})(\\d{4})","$1 $2",["[57]"]],["(\\d{5})(\\d{5})","$1 $2",["8"]]],0,0,0,0,0,0,0,"020"],MV:["960","0(?:0|19)","(?:800|9[0-57-9]\\d)\\d{7}|[34679]\\d{6}",[7,10],[["(\\d{3})(\\d{4})","$1-$2",["[34679]"]],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["[89]"]]],0,0,0,0,0,0,0,"00"],MW:["265","00","(?:[1289]\\d|31|77)\\d{7}|1\\d{6}",[7,9],[["(\\d)(\\d{3})(\\d{3})","$1 $2 $3",["1[2-9]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["2"],"0$1"],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[137-9]"],"0$1"]],"0"],MX:["52","0[09]","[2-9]\\d{9}",[10],[["(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3",["33|5[56]|81"]],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["[2-9]"]]],0,0,0,0,0,0,0,"00"],MY:["60","00","1\\d{8,9}|(?:3\\d|[4-9])\\d{7}",[8,9,10],[["(\\d)(\\d{3})(\\d{4})","$1-$2 $3",["[4-79]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1-$2 $3",["1(?:[02469]|[378][1-9]|53)|8","1(?:[02469]|[37][1-9]|53|8(?:[1-46-9]|5[7-9]))|8"],"0$1"],["(\\d)(\\d{4})(\\d{4})","$1-$2 $3",["3"],"0$1"],["(\\d)(\\d{3})(\\d{2})(\\d{4})","$1-$2-$3-$4",["1(?:[367]|80)"]],["(\\d{3})(\\d{3})(\\d{4})","$1-$2 $3",["15"],"0$1"],["(\\d{2})(\\d{4})(\\d{4})","$1-$2 $3",["1"],"0$1"]],"0"],MZ:["258","00","(?:2|8\\d)\\d{7}",[8,9],[["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["2|8[2-79]"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["8"]]]],NA:["264","00","[68]\\d{7,8}",[8,9],[["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["88"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["6"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["87"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["8"],"0$1"]],"0"],NC:["687","00","(?:050|[2-57-9]\\d\\d)\\d{3}",[6],[["(\\d{2})(\\d{2})(\\d{2})","$1.$2.$3",["[02-57-9]"]]]],NE:["227","00","[027-9]\\d{7}",[8],[["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["08"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[089]|2[013]|7[0467]"]]]],NF:["672","00","[13]\\d{5}",[6],[["(\\d{2})(\\d{4})","$1 $2",["1[0-3]"]],["(\\d)(\\d{5})","$1 $2",["[13]"]]],0,0,"([0-258]\\d{4})$","3$1"],NG:["234","009","(?:20|9\\d)\\d{8}|[78]\\d{9,13}",[10,11,12,13,14],[["(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["[7-9]"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["20[129]"],"0$1"],["(\\d{4})(\\d{2})(\\d{4})","$1 $2 $3",["2"],"0$1"],["(\\d{3})(\\d{4})(\\d{4,5})","$1 $2 $3",["[78]"],"0$1"],["(\\d{3})(\\d{5})(\\d{5,6})","$1 $2 $3",["[78]"],"0$1"]],"0"],NI:["505","00","(?:1800|[25-8]\\d{3})\\d{4}",[8],[["(\\d{4})(\\d{4})","$1 $2",["[125-8]"]]]],NL:["31","00","(?:[124-7]\\d\\d|3(?:[02-9]\\d|1[0-8]))\\d{6}|8\\d{6,9}|9\\d{6,10}|1\\d{4,5}",[5,6,7,8,9,10,11],[["(\\d{3})(\\d{4,7})","$1 $2",["[89]0"],"0$1"],["(\\d{2})(\\d{7})","$1 $2",["66"],"0$1"],["(\\d)(\\d{8})","$1 $2",["6"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["1[16-8]|2[259]|3[124]|4[17-9]|5[124679]"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[1-578]|91"],"0$1"],["(\\d{3})(\\d{3})(\\d{5})","$1 $2 $3",["9"],"0$1"]],"0"],NO:["47","00","(?:0|[2-9]\\d{3})\\d{4}",[5,8],[["(\\d{3})(\\d{2})(\\d{3})","$1 $2 $3",["8"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[2-79]"]]],0,0,0,0,0,"[02-689]|7[0-8]"],NP:["977","00","(?:1\\d|9)\\d{9}|[1-9]\\d{7}",[8,10,11],[["(\\d)(\\d{7})","$1-$2",["1[2-6]"],"0$1"],["(\\d{2})(\\d{6})","$1-$2",["1[01]|[2-8]|9(?:[1-59]|[67][2-6])"],"0$1"],["(\\d{3})(\\d{7})","$1-$2",["9"]]],"0"],NR:["674","00","(?:222|444|(?:55|8\\d)\\d|666|777|999)\\d{4}",[7],[["(\\d{3})(\\d{4})","$1 $2",["[24-9]"]]]],NU:["683","00","(?:[4-7]|888\\d)\\d{3}",[4,7],[["(\\d{3})(\\d{4})","$1 $2",["8"]]]],NZ:["64","0(?:0|161)","[1289]\\d{9}|50\\d{5}(?:\\d{2,3})?|[27-9]\\d{7,8}|(?:[34]\\d|6[0-35-9])\\d{6}|8\\d{4,6}",[5,6,7,8,9,10],[["(\\d{2})(\\d{3,8})","$1 $2",["8[1-79]"],"0$1"],["(\\d{3})(\\d{2})(\\d{2,3})","$1 $2 $3",["50[036-8]|8|90","50(?:[0367]|88)|8|90"],"0$1"],["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["24|[346]|7[2-57-9]|9[2-9]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["2(?:10|74)|[589]"],"0$1"],["(\\d{2})(\\d{3,4})(\\d{4})","$1 $2 $3",["1|2[028]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,5})","$1 $2 $3",["2(?:[169]|7[0-35-9])|7"],"0$1"]],"0",0,0,0,0,0,0,"00"],OM:["968","00","(?:1505|[279]\\d{3}|500)\\d{4}|800\\d{5,6}",[7,8,9],[["(\\d{3})(\\d{4,6})","$1 $2",["[58]"]],["(\\d{2})(\\d{6})","$1 $2",["2"]],["(\\d{4})(\\d{4})","$1 $2",["[179]"]]]],PA:["507","00","(?:00800|8\\d{3})\\d{6}|[68]\\d{7}|[1-57-9]\\d{6}",[7,8,10,11],[["(\\d{3})(\\d{4})","$1-$2",["[1-57-9]"]],["(\\d{4})(\\d{4})","$1-$2",["[68]"]],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["8"]]]],PE:["51","00|19(?:1[124]|77|90)00","(?:[14-8]|9\\d)\\d{7}",[8,9],[["(\\d{3})(\\d{5})","$1 $2",["80"],"(0$1)"],["(\\d)(\\d{7})","$1 $2",["1"],"(0$1)"],["(\\d{2})(\\d{6})","$1 $2",["[4-8]"],"(0$1)"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["9"]]],"0",0,0,0,0,0,0,"00"," Anexo "],PF:["689","00","4\\d{5}(?:\\d{2})?|8\\d{7,8}",[6,8,9],[["(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3",["44"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["4|8[7-9]"]],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["8"]]]],PG:["675","00|140[1-3]","(?:180|[78]\\d{3})\\d{4}|(?:[2-589]\\d|64)\\d{5}",[7,8],[["(\\d{3})(\\d{4})","$1 $2",["18|[2-69]|85"]],["(\\d{4})(\\d{4})","$1 $2",["[78]"]]],0,0,0,0,0,0,0,"00"],PH:["63","00","(?:[2-7]|9\\d)\\d{8}|2\\d{5}|(?:1800|8)\\d{7,9}",[6,8,9,10,11,12,13],[["(\\d)(\\d{5})","$1 $2",["2"],"(0$1)"],["(\\d{4})(\\d{4,6})","$1 $2",["3(?:23|39|46)|4(?:2[3-6]|[35]9|4[26]|76)|544|88[245]|(?:52|64|86)2","3(?:230|397|461)|4(?:2(?:35|[46]4|51)|396|4(?:22|63)|59[347]|76[15])|5(?:221|446)|642[23]|8(?:622|8(?:[24]2|5[13]))"],"(0$1)"],["(\\d{5})(\\d{4})","$1 $2",["346|4(?:27|9[35])|883","3469|4(?:279|9(?:30|56))|8834"],"(0$1)"],["(\\d)(\\d{4})(\\d{4})","$1 $2 $3",["2"],"(0$1)"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[3-7]|8[2-8]"],"(0$1)"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["[89]"],"0$1"],["(\\d{4})(\\d{3})(\\d{4})","$1 $2 $3",["1"]],["(\\d{4})(\\d{1,2})(\\d{3})(\\d{4})","$1 $2 $3 $4",["1"]]],"0"],PK:["92","00","122\\d{6}|[24-8]\\d{10,11}|9(?:[013-9]\\d{8,10}|2(?:[01]\\d\\d|2(?:[06-8]\\d|1[01]))\\d{7})|(?:[2-8]\\d{3}|92(?:[0-7]\\d|8[1-9]))\\d{6}|[24-9]\\d{8}|[89]\\d{7}",[8,9,10,11,12],[["(\\d{3})(\\d{3})(\\d{2,7})","$1 $2 $3",["[89]0"],"0$1"],["(\\d{4})(\\d{5})","$1 $2",["1"]],["(\\d{3})(\\d{6,7})","$1 $2",["2(?:3[2358]|4[2-4]|9[2-8])|45[3479]|54[2-467]|60[468]|72[236]|8(?:2[2-689]|3[23578]|4[3478]|5[2356])|9(?:2[2-8]|3[27-9]|4[2-6]|6[3569]|9[25-8])","9(?:2[3-8]|98)|(?:2(?:3[2358]|4[2-4]|9[2-8])|45[3479]|54[2-467]|60[468]|72[236]|8(?:2[2-689]|3[23578]|4[3478]|5[2356])|9(?:22|3[27-9]|4[2-6]|6[3569]|9[25-7]))[2-9]"],"(0$1)"],["(\\d{2})(\\d{7,8})","$1 $2",["(?:2[125]|4[0-246-9]|5[1-35-7]|6[1-8]|7[14]|8[16]|91)[2-9]"],"(0$1)"],["(\\d{5})(\\d{5})","$1 $2",["58"],"(0$1)"],["(\\d{3})(\\d{7})","$1 $2",["3"],"0$1"],["(\\d{2})(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3 $4",["2[125]|4[0-246-9]|5[1-35-7]|6[1-8]|7[14]|8[16]|91"],"(0$1)"],["(\\d{3})(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3 $4",["[24-9]"],"(0$1)"]],"0"],PL:["48","00","(?:6|8\\d\\d)\\d{7}|[1-9]\\d{6}(?:\\d{2})?|[26]\\d{5}",[6,7,8,9,10],[["(\\d{5})","$1",["19"]],["(\\d{3})(\\d{3})","$1 $2",["11|20|64"]],["(\\d{2})(\\d{2})(\\d{3})","$1 $2 $3",["(?:1[2-8]|2[2-69]|3[2-4]|4[1-468]|5[24-689]|6[1-3578]|7[14-7]|8[1-79]|9[145])1","(?:1[2-8]|2[2-69]|3[2-4]|4[1-468]|5[24-689]|6[1-3578]|7[14-7]|8[1-79]|9[145])19"]],["(\\d{3})(\\d{2})(\\d{2,3})","$1 $2 $3",["64"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["21|39|45|5[0137]|6[0469]|7[02389]|8(?:0[14]|8)"]],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["1[2-8]|[2-7]|8[1-79]|9[145]"]],["(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["8"]]]],PM:["508","00","[45]\\d{5}|(?:708|8\\d\\d)\\d{6}",[6,9],[["(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3",["[45]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["7"]],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["8"],"0$1"]],"0"],PR:["1","011","(?:[589]\\d\\d|787)\\d{7}",[10],0,"1",0,0,0,0,"787|939"],PS:["970","00","[2489]2\\d{6}|(?:1\\d|5)\\d{8}",[8,9,10],[["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["[2489]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["5"],"0$1"],["(\\d{4})(\\d{3})(\\d{3})","$1 $2 $3",["1"]]],"0"],PT:["351","00","1693\\d{5}|(?:[26-9]\\d|30)\\d{7}",[9],[["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["2[12]"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["16|[236-9]"]]]],PW:["680","01[12]","(?:[24-8]\\d\\d|345|900)\\d{4}",[7],[["(\\d{3})(\\d{4})","$1 $2",["[2-9]"]]]],PY:["595","00","59\\d{4,6}|9\\d{5,10}|(?:[2-46-8]\\d|5[0-8])\\d{4,7}",[6,7,8,9,10,11],[["(\\d{3})(\\d{3,6})","$1 $2",["[2-9]0"],"0$1"],["(\\d{2})(\\d{5})","$1 $2",["[26]1|3[289]|4[1246-8]|7[1-3]|8[1-36]"],"(0$1)"],["(\\d{3})(\\d{4,5})","$1 $2",["2[279]|3[13-5]|4[359]|5|6(?:[34]|7[1-46-8])|7[46-8]|85"],"(0$1)"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["2[14-68]|3[26-9]|4[1246-8]|6(?:1|75)|7[1-35]|8[1-36]"],"(0$1)"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["87"]],["(\\d{3})(\\d{6})","$1 $2",["9(?:[5-79]|8[1-7])"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[2-8]"],"0$1"],["(\\d{4})(\\d{3})(\\d{4})","$1 $2 $3",["9"]]],"0"],QA:["974","00","800\\d{4}|(?:2|800)\\d{6}|(?:0080|[3-7])\\d{7}",[7,8,9,11],[["(\\d{3})(\\d{4})","$1 $2",["2[136]|8"]],["(\\d{4})(\\d{4})","$1 $2",["[3-7]"]]]],RE:["262","00","709\\d{6}|(?:26|[689]\\d)\\d{7}",[9],[["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[26-9]"],"0$1"]],"0",0,0,0,0,0,[["26(?:2\\d\\d|3(?:0\\d|1[0-6]))\\d{4}"],["(?:69(?:2\\d\\d|3(?:[06][0-6]|1[0-3]|2[0-2]|3[0-39]|4\\d|5[0-5]|7[0-37]|8[0-8]|9[0-479]))|7092[0-3])\\d{4}"],["80\\d{7}"],["89[1-37-9]\\d{6}"],0,0,0,0,["9(?:399[0-3]|479[0-6]|76(?:2[278]|3[0-37]))\\d{4}"],["8(?:1[019]|2[0156]|84|90)\\d{6}"]]],RO:["40","00","(?:[236-8]\\d|90)\\d{7}|[23]\\d{5}",[6,9],[["(\\d{3})(\\d{3})","$1 $2",["2[3-6]","2[3-6]\\d9"],"0$1"],["(\\d{2})(\\d{4})","$1 $2",["219|31"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[23]1"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[236-9]"],"0$1"]],"0",0,0,0,0,0,0,0," int "],RS:["381","00","38[02-9]\\d{6,9}|6\\d{7,9}|90\\d{4,8}|38\\d{5,6}|(?:7\\d\\d|800)\\d{3,9}|(?:[12]\\d|3[0-79])\\d{5,10}",[6,7,8,9,10,11,12],[["(\\d{3})(\\d{3,9})","$1 $2",["(?:2[389]|39)0|[7-9]"],"0$1"],["(\\d{2})(\\d{5,10})","$1 $2",["[1-36]"],"0$1"]],"0"],RU:["7","810","8\\d{13}|[347-9]\\d{9}",[10,14],[["(\\d{4})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["7(?:1[0-8]|2[1-9])","7(?:1(?:[0-356]2|4[29]|7|8[27])|2(?:1[23]|[2-9]2))","7(?:1(?:[0-356]2|4[29]|7|8[27])|2(?:13[03-69]|62[013-9]))|72[1-57-9]2"],"8 ($1)",1],["(\\d{5})(\\d)(\\d{2})(\\d{2})","$1 $2 $3 $4",["7(?:1[0-68]|2[1-9])","7(?:1(?:[06][3-6]|[18]|2[35]|[3-5][3-5])|2(?:[13][3-5]|[24-689]|7[457]))","7(?:1(?:0(?:[356]|4[023])|[18]|2(?:3[013-9]|5)|3[45]|43[013-79]|5(?:3[1-8]|4[1-7]|5)|6(?:3[0-35-9]|[4-6]))|2(?:1(?:3[178]|[45])|[24-689]|3[35]|7[457]))|7(?:14|23)4[0-8]|71(?:33|45)[1-79]"],"8 ($1)",1],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["7"],"8 ($1)",1],["(\\d{3})(\\d{3})(\\d{2})(\\d{2})","$1 $2-$3-$4",["[349]|8(?:[02-7]|1[1-8])"],"8 ($1)",1],["(\\d{4})(\\d{4})(\\d{3})(\\d{3})","$1 $2 $3 $4",["8"],"8 ($1)"]],"8",0,0,0,0,"3[04-689]|[489]",0,"8~10"],RW:["250","00","(?:06|[27]\\d\\d|[89]00)\\d{6}",[8,9],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["0"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["2"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[7-9]"],"0$1"]],"0"],SA:["966","00","92\\d{7}|(?:[15]|8\\d)\\d{8}",[9,10],[["(\\d{4})(\\d{5})","$1 $2",["9"]],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["1"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["5"],"0$1"],["(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["81"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["8"]]],"0"],SB:["677","0[01]","[6-9]\\d{6}|[1-6]\\d{4}",[5,7],[["(\\d{2})(\\d{5})","$1 $2",["6[89]|7|8[4-9]|9(?:[1-8]|9[0-8])"]]]],SC:["248","010|0[0-2]","(?:[2489]\\d|64)\\d{5}",[7],[["(\\d)(\\d{3})(\\d{3})","$1 $2 $3",["[246]|9[57]"]]],0,0,0,0,0,0,0,"00"],SD:["249","00","[19]\\d{8}",[9],[["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[19]"],"0$1"]],"0"],SE:["46","00","(?:[26]\\d\\d|9)\\d{9}|[1-9]\\d{8}|[1-689]\\d{7}|[1-4689]\\d{6}|2\\d{5}",[6,7,8,9,10,12],[["(\\d{2})(\\d{2,3})(\\d{2})","$1-$2 $3",["20"],"0$1",0,"$1 $2 $3"],["(\\d{3})(\\d{4})","$1-$2",["9(?:00|39|44|9)"],"0$1",0,"$1 $2"],["(\\d{2})(\\d{3})(\\d{2})","$1-$2 $3",["[12][136]|3[356]|4[0246]|6[03]|90[1-9]"],"0$1",0,"$1 $2 $3"],["(\\d)(\\d{2,3})(\\d{2})(\\d{2})","$1-$2 $3 $4",["8"],"0$1",0,"$1 $2 $3 $4"],["(\\d{3})(\\d{2,3})(\\d{2})","$1-$2 $3",["1[2457]|2(?:[247-9]|5[0138])|3[0247-9]|4[1357-9]|5[0-35-9]|6(?:[125689]|4[02-57]|7[0-2])|9(?:[125-8]|3[02-5]|4[0-3])"],"0$1",0,"$1 $2 $3"],["(\\d{3})(\\d{2,3})(\\d{3})","$1-$2 $3",["9(?:00|39|44)"],"0$1",0,"$1 $2 $3"],["(\\d{2})(\\d{2,3})(\\d{2})(\\d{2})","$1-$2 $3 $4",["1[13689]|2[0136]|3[1356]|4[0246]|54|6[03]|90[1-9]"],"0$1",0,"$1 $2 $3 $4"],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1-$2 $3 $4",["10|7"],"0$1",0,"$1 $2 $3 $4"],["(\\d)(\\d{3})(\\d{3})(\\d{2})","$1-$2 $3 $4",["8"],"0$1",0,"$1 $2 $3 $4"],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1-$2 $3 $4",["[13-5]|2(?:[247-9]|5[0138])|6(?:[124-689]|7[0-2])|9(?:[125-8]|3[02-5]|4[0-3])"],"0$1",0,"$1 $2 $3 $4"],["(\\d{3})(\\d{2})(\\d{2})(\\d{3})","$1-$2 $3 $4",["9"],"0$1",0,"$1 $2 $3 $4"],["(\\d{3})(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1-$2 $3 $4 $5",["[26]"],"0$1",0,"$1 $2 $3 $4 $5"]],"0"],SG:["65","0[0-3]\\d","(?:(?:1\\d|8)\\d\\d|7000)\\d{7}|[3689]\\d{7}",[8,10,11],[["(\\d{4})(\\d{4})","$1 $2",["[369]|8(?:0[1-9]|[1-9])"]],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["8"]],["(\\d{4})(\\d{4})(\\d{3})","$1 $2 $3",["7"]],["(\\d{4})(\\d{3})(\\d{4})","$1 $2 $3",["1"]]]],SH:["290","00","(?:[256]\\d|8)\\d{3}",[4,5],0,0,0,0,0,0,"[256]"],SI:["386","00|10(?:22|66|88|99)","[1-7]\\d{7}|8\\d{4,7}|90\\d{4,6}",[5,6,7,8],[["(\\d{2})(\\d{3,6})","$1 $2",["8[09]|9"],"0$1"],["(\\d{3})(\\d{5})","$1 $2",["59|8"],"0$1"],["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["[37][01]|4[0139]|51|6"],"0$1"],["(\\d)(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[1-57]"],"(0$1)"]],"0",0,0,0,0,0,0,"00"],SJ:["47","00","0\\d{4}|(?:[489]\\d|79)\\d{6}",[5,8],0,0,0,0,0,0,"79"],SK:["421","00","[2-689]\\d{8}|[2-59]\\d{6}|[2-5]\\d{5}",[6,7,9],[["(\\d)(\\d{2})(\\d{3,4})","$1 $2 $3",["21"],"0$1"],["(\\d{2})(\\d{2})(\\d{2,3})","$1 $2 $3",["[3-5][1-8]1","[3-5][1-8]1[67]"],"0$1"],["(\\d)(\\d{3})(\\d{3})(\\d{2})","$1/$2 $3 $4",["2"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[689]"],"0$1"],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1/$2 $3 $4",["[3-5]"],"0$1"]],"0"],SL:["232","00","(?:[237-9]\\d|66)\\d{6}",[8],[["(\\d{2})(\\d{6})","$1 $2",["[236-9]"],"(0$1)"]],"0"],SM:["378","00","(?:0549|[5-7]\\d)\\d{6}",[8,10],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[5-7]"]],["(\\d{4})(\\d{6})","$1 $2",["0"]]],0,0,"([89]\\d{5})$","0549$1"],SN:["221","00","(?:[378]\\d|93)\\d{7}",[9],[["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["8"]],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[379]"]]]],SO:["252","00","[346-9]\\d{8}|[12679]\\d{7}|[1-5]\\d{6}|[1348]\\d{5}",[6,7,8,9],[["(\\d{2})(\\d{4})","$1 $2",["8[125]"]],["(\\d{6})","$1",["[134]"]],["(\\d)(\\d{6})","$1 $2",["[15]|2[0-79]|3[0-46-8]|4[0-7]"]],["(\\d)(\\d{7})","$1 $2",["(?:2|90)4|[67]"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[348]|64|79|90"]],["(\\d{2})(\\d{5,7})","$1 $2",["1|28|6[0-35-9]|7[67]|9[2-9]"]]],"0"],SR:["597","00","(?:[2-5]|68|[78]\\d|90)\\d{5}",[6,7],[["(\\d{2})(\\d{2})(\\d{2})","$1-$2-$3",["56"]],["(\\d{3})(\\d{3})","$1-$2",["[2-5]"]],["(\\d{3})(\\d{4})","$1-$2",["[6-9]"]]]],SS:["211","00","[19]\\d{8}",[9],[["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[19]"],"0$1"]],"0"],ST:["239","00","(?:22|9\\d)\\d{5}",[7],[["(\\d{3})(\\d{4})","$1 $2",["[29]"]]]],SV:["503","00","[267]\\d{7}|(?:80\\d|900)\\d{4}(?:\\d{4})?",[7,8,11],[["(\\d{3})(\\d{4})","$1 $2",["[89]"]],["(\\d{4})(\\d{4})","$1 $2",["[267]"]],["(\\d{3})(\\d{4})(\\d{4})","$1 $2 $3",["[89]"]]]],SX:["1","011","7215\\d{6}|(?:[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"(5\\d{6})$|1","721$1",0,"721"],SY:["963","00","[1-39]\\d{8}|[1-5]\\d{7}",[8,9],[["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[1-5]"],"0$1",1],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["9"],"0$1",1]],"0"],SZ:["268","00","0800\\d{4}|(?:[237]\\d|900)\\d{6}",[8,9],[["(\\d{4})(\\d{4})","$1 $2",["[0237]"]],["(\\d{5})(\\d{4})","$1 $2",["9"]]]],TA:["290","00","8\\d{3}",[4],0,0,0,0,0,0,"8"],TC:["1","011","(?:[58]\\d\\d|649|900)\\d{7}",[10],0,"1",0,"([2-479]\\d{6})$|1","649$1",0,"649"],TD:["235","00|16","(?:22|[689]\\d|77)\\d{6}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[26-9]"]]],0,0,0,0,0,0,0,"00"],TG:["228","00","[279]\\d{7}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[279]"]]]],TH:["66","00[1-9]","(?:001800|[2-57]|[689]\\d)\\d{7}|1\\d{7,9}",[8,9,10,13],[["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["2"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[13-9]"],"0$1"],["(\\d{4})(\\d{3})(\\d{3})","$1 $2 $3",["1"]]],"0"],TJ:["992","810","[0-57-9]\\d{8}",[9],[["(\\d{6})(\\d)(\\d{2})","$1 $2 $3",["331","3317"]],["(\\d{3})(\\d{2})(\\d{4})","$1 $2 $3",["44[02-479]|[34]7"]],["(\\d{4})(\\d)(\\d{4})","$1 $2 $3",["3(?:[1245]|3[12])"]],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[0-57-9]"]]],0,0,0,0,0,0,0,"8~10"],TK:["690","00","[2-47]\\d{3,6}",[4,5,6,7]],TL:["670","00","7\\d{7}|(?:[2-47]\\d|[89]0)\\d{5}",[7,8],[["(\\d{3})(\\d{4})","$1 $2",["[2-489]|70"]],["(\\d{4})(\\d{4})","$1 $2",["7"]]]],TM:["993","810","(?:[1-6]\\d|71)\\d{6}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2-$3-$4",["12"],"(8 $1)"],["(\\d{3})(\\d)(\\d{2})(\\d{2})","$1 $2-$3-$4",["[1-5]"],"(8 $1)"],["(\\d{2})(\\d{6})","$1 $2",["[67]"],"8 $1"]],"8",0,0,0,0,0,0,"8~10"],TN:["216","00","[2-57-9]\\d{7}",[8],[["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["[2-57-9]"]]]],TO:["676","00","(?:0800|(?:[5-8]\\d\\d|999)\\d)\\d{3}|[2-8]\\d{4}",[5,7],[["(\\d{2})(\\d{3})","$1-$2",["[2-4]|50|6[09]|7[0-24-69]|8[05]"]],["(\\d{4})(\\d{3})","$1 $2",["0"]],["(\\d{3})(\\d{4})","$1 $2",["[5-9]"]]]],TR:["90","00","4\\d{6}|8\\d{11,12}|(?:[2-58]\\d\\d|900)\\d{7}",[7,10,12,13],[["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["512|8[01589]|90"],"0$1",1],["(\\d{3})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["5(?:[0-59]|61)","5(?:[0-59]|61[06])","5(?:[0-59]|61[06]1)"],"0$1",1],["(\\d{3})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[24][1-8]|3[1-9]"],"(0$1)",1],["(\\d{3})(\\d{3})(\\d{6,7})","$1 $2 $3",["80"],"0$1",1]],"0"],TT:["1","011","(?:[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"([2-46-8]\\d{6})$|1","868$1",0,"868"],TV:["688","00","(?:2|7\\d\\d|90)\\d{4}",[5,6,7],[["(\\d{2})(\\d{3})","$1 $2",["2"]],["(\\d{2})(\\d{4})","$1 $2",["90"]],["(\\d{2})(\\d{5})","$1 $2",["7"]]]],TW:["886","0(?:0[25-79]|19)","[2-689]\\d{8}|7\\d{9,10}|[2-8]\\d{7}|2\\d{6}",[7,8,9,10,11],[["(\\d{2})(\\d)(\\d{4})","$1 $2 $3",["202"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[258]0"],"0$1"],["(\\d)(\\d{3,4})(\\d{4})","$1 $2 $3",["[23568]|4(?:0[02-48]|[1-47-9])|7[1-9]","[23568]|4(?:0[2-48]|[1-47-9])|(?:400|7)[1-9]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[49]"],"0$1"],["(\\d{2})(\\d{4})(\\d{4,5})","$1 $2 $3",["7"],"0$1"]],"0",0,0,0,0,0,0,0,"#"],TZ:["255","00[056]","(?:[25-8]\\d|41|90)\\d{7}",[9],[["(\\d{3})(\\d{2})(\\d{4})","$1 $2 $3",["[89]"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[24]"],"0$1"],["(\\d{2})(\\d{7})","$1 $2",["5"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[67]"],"0$1"]],"0"],UA:["380","00","[89]\\d{9}|[3-9]\\d{8}",[9,10],[["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["6[12][29]|(?:3[1-8]|4[136-8]|5[12457]|6[49])2|(?:56|65)[24]","6[12][29]|(?:35|4[1378]|5[12457]|6[49])2|(?:56|65)[24]|(?:3[1-46-8]|46)2[013-9]"],"0$1"],["(\\d{4})(\\d{5})","$1 $2",["3[1-8]|4(?:[1367]|[45][6-9]|8[4-6])|5(?:[1-5]|6[0135689]|7[4-6])|6(?:[12][3-7]|[459])","3[1-8]|4(?:[1367]|[45][6-9]|8[4-6])|5(?:[1-5]|6(?:[015689]|3[02389])|7[4-6])|6(?:[12][3-7]|[459])"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[3-7]|89|9[1-9]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["[89]"],"0$1"]],"0",0,0,0,0,0,0,"0~0"],UG:["256","00[057]","800\\d{6}|(?:[29]0|[347]\\d)\\d{7}",[9],[["(\\d{4})(\\d{5})","$1 $2",["202","2024"],"0$1"],["(\\d{3})(\\d{6})","$1 $2",["[27-9]|4(?:6[45]|[7-9])"],"0$1"],["(\\d{2})(\\d{7})","$1 $2",["[34]"],"0$1"]],"0"],US:["1","011","[2-9]\\d{9}|3\\d{6}",[10],[["(\\d{3})(\\d{4})","$1-$2",["310"],0,1],["(\\d{3})(\\d{3})(\\d{4})","($1) $2-$3",["[2-9]"],0,1,"$1-$2-$3"]],"1",0,0,0,0,0,[["(?:3052(?:0[0-8]|[1-9]\\d)|5056(?:[0-35-9]\\d|4[0-468]))\\d{4}|(?:2742|305[3-9]|472[247-9]|505[2-57-9]|983[2-47-9])\\d{6}|(?:2(?:0[1-35-9]|1[02-9]|2[03-57-9]|3[1459]|4[08]|5[1-46]|6[0279]|7[0269]|8[13])|3(?:0[1-47-9]|1[02-9]|2[0135-79]|3[0-24679]|4[167]|5[0-2]|6[01349]|8[056])|4(?:0[124-9]|1[02-579]|2[3-5]|3[0245]|4[023578]|58|6[349]|7[0589]|8[04])|5(?:0[1-47-9]|1[0235-8]|20|3[0149]|4[01]|5[179]|6[1-47]|7[0-5]|8[0256])|6(?:0[1-35-9]|1[024-9]|2[03689]|3[016]|4[0156]|5[01679]|6[0-279]|78|8[0-29])|7(?:0[1-46-8]|1[2-9]|2[04-8]|3[0-247]|4[037]|5[47]|6[02359]|7[0-59]|8[156])|8(?:0[1-68]|1[02-8]|2[0168]|3[0-2589]|4[03578]|5[046-9]|6[02-5]|7[028])|9(?:0[1346-9]|1[02-9]|2[0589]|3[0146-8]|4[01357-9]|5[12469]|7[0-389]|8[04-69]))[2-9]\\d{6}"],[""],["8(?:00|33|44|55|66|77|88)[2-9]\\d{6}"],["900[2-9]\\d{6}"],["52(?:3(?:[2-46-9][02-9]\\d|5(?:[02-46-9]\\d|5[0-46-9]))|4(?:[2-478][02-9]\\d|5(?:[034]\\d|2[024-9]|5[0-46-9])|6(?:0[1-9]|[2-9]\\d)|9(?:[05-9]\\d|2[0-5]|49)))\\d{4}|52[34][2-9]1[02-9]\\d{4}|5(?:00|2[125-9]|33|44|66|77|88)[2-9]\\d{6}"],0,0,0,["305209\\d{4}"]]],UY:["598","0(?:0|1[3-9]\\d)","0004\\d{2,9}|[1249]\\d{7}|(?:[49]\\d|80)\\d{5}",[6,7,8,9,10,11,12,13],[["(\\d{3})(\\d{3,4})","$1 $2",["0"]],["(\\d{3})(\\d{4})","$1 $2",["[49]0|8"],"0$1"],["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["9"],"0$1"],["(\\d{4})(\\d{4})","$1 $2",["[124]"]],["(\\d{3})(\\d{3})(\\d{2,4})","$1 $2 $3",["0"]],["(\\d{3})(\\d{3})(\\d{3})(\\d{2,4})","$1 $2 $3 $4",["0"]]],"0",0,0,0,0,0,0,"00"," int. "],UZ:["998","00","(?:20|33|[5-9]\\d)\\d{7}",[9],[["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[235-9]"]]]],VA:["39","00","0\\d{5,10}|3[0-8]\\d{7,10}|55\\d{8}|8\\d{5}(?:\\d{2,4})?|(?:1\\d|39)\\d{7,8}",[6,7,8,9,10,11,12],0,0,0,0,0,0,"06698"],VC:["1","011","(?:[58]\\d\\d|784|900)\\d{7}",[10],0,"1",0,"([2-7]\\d{6})$|1","784$1",0,"784"],VE:["58","00","[68]00\\d{7}|(?:[24]\\d|[59]0)\\d{8}",[10],[["(\\d{3})(\\d{7})","$1-$2",["[24-689]"],"0$1"]],"0"],VG:["1","011","(?:284|[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"([2-578]\\d{6})$|1","284$1",0,"284"],VI:["1","011","[58]\\d{9}|(?:34|90)0\\d{7}",[10],0,"1",0,"([2-9]\\d{6})$|1","340$1",0,"340"],VN:["84","00","[12]\\d{9}|[135-9]\\d{8}|[16]\\d{7}|[16-8]\\d{6}",[7,8,9,10],[["(\\d{2})(\\d{5})","$1 $2",["80"],"0$1",1],["(\\d{4})(\\d{4,6})","$1 $2",["1"],0,1],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["6"],"0$1",1],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[357-9]"],"0$1",1],["(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3",["2[48]"],"0$1",1],["(\\d{3})(\\d{4})(\\d{3})","$1 $2 $3",["2"],"0$1",1]],"0"],VU:["678","00","[57-9]\\d{6}|(?:[238]\\d|48)\\d{3}",[5,7],[["(\\d{3})(\\d{4})","$1 $2",["[57-9]"]]]],WF:["681","00","(?:40|72|8\\d{4})\\d{4}|[89]\\d{5}",[6,9],[["(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3",["[47-9]"]],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["8"]]]],WS:["685","0","(?:[2-6]|8\\d{5})\\d{4}|[78]\\d{6}|[68]\\d{5}",[5,6,7,10],[["(\\d{5})","$1",["[2-5]|6[1-9]"]],["(\\d{3})(\\d{3,7})","$1 $2",["[68]"]],["(\\d{2})(\\d{5})","$1 $2",["7"]]]],XK:["383","00","2\\d{7,8}|3\\d{7,11}|(?:4\\d\\d|[89]00)\\d{5}",[8,9,10,11,12],[["(\\d{3})(\\d{5})","$1 $2",["[89]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["[2-4]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["2|39"],"0$1"],["(\\d{2})(\\d{7,10})","$1 $2",["3"],"0$1"]],"0"],YE:["967","00","(?:1|7\\d)\\d{7}|[1-7]\\d{6}",[7,8,9],[["(\\d)(\\d{3})(\\d{3,4})","$1 $2 $3",["[1-6]|7(?:[24-6]|8[0-7])"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["7"],"0$1"]],"0"],YT:["262","00","7093\\d{5}|(?:80|9\\d)\\d{7}|(?:26|63)9\\d{6}",[9],0,"0",0,0,0,0,0,[["269(?:0[0-467]|15|5[0-4]|6\\d|[78]0)\\d{4}"],["(?:639(?:0[0-79]|1[019]|[267]\\d|3[09]|40|5[05-9]|9[04-79])|7093[5-7])\\d{4}"],["80\\d{7}"],0,0,0,0,0,["9(?:(?:39|47)8[01]|769\\d)\\d{4}"]]],ZA:["27","00","[1-79]\\d{8}|8\\d{4,9}",[5,6,7,8,9,10],[["(\\d{2})(\\d{3,4})","$1 $2",["8[1-4]"],"0$1"],["(\\d{2})(\\d{3})(\\d{2,3})","$1 $2 $3",["8[1-4]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["860"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[1-9]"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["8"],"0$1"]],"0"],ZM:["260","00","800\\d{6}|(?:21|[579]\\d|63)\\d{7}",[9],[["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[28]"],"0$1"],["(\\d{2})(\\d{7})","$1 $2",["[579]"],"0$1"]],"0"],ZW:["263","00","2(?:[0-57-9]\\d{6,8}|6[0-24-9]\\d{6,7})|[38]\\d{9}|[35-8]\\d{8}|[3-6]\\d{7}|[1-689]\\d{6}|[1-3569]\\d{5}|[1356]\\d{4}",[5,6,7,8,9,10],[["(\\d{3})(\\d{3,5})","$1 $2",["2(?:0[45]|2[278]|[49]8)|3(?:[09]8|17)|6(?:[29]8|37|75)|[23][78]|(?:33|5[15]|6[68])[78]"],"0$1"],["(\\d)(\\d{3})(\\d{2,4})","$1 $2 $3",["[49]"],"0$1"],["(\\d{3})(\\d{4})","$1 $2",["80"],"0$1"],["(\\d{2})(\\d{7})","$1 $2",["24|8[13-59]|(?:2[05-79]|39|5[45]|6[15-8])2","2(?:02[014]|4|[56]20|[79]2)|392|5(?:42|525)|6(?:[16-8]21|52[013])|8[13-59]"],"(0$1)"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["7"],"0$1"],["(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["2(?:1[39]|2[0157]|[378]|[56][14])|3(?:12|29)","2(?:1[39]|2[0157]|[378]|[56][14])|3(?:123|29)"],"0$1"],["(\\d{4})(\\d{6})","$1 $2",["8"],"0$1"],["(\\d{2})(\\d{3,5})","$1 $2",["1|2(?:0[0-36-9]|12|29|[56])|3(?:1[0-689]|[24-6])|5(?:[0236-9]|1[2-4])|6(?:[013-59]|7[0-46-9])|(?:33|55|6[68])[0-69]|(?:29|3[09]|62)[0-79]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["29[013-9]|39|54"],"0$1"],["(\\d{4})(\\d{3,5})","$1 $2",["(?:25|54)8","258|5483"],"0$1"]],"0"]},nonGeographic:{800:["800",0,"(?:00|[1-9]\\d)\\d{6}",[8],[["(\\d{4})(\\d{4})","$1 $2",["\\d"]]],0,0,0,0,0,0,[0,0,["(?:00|[1-9]\\d)\\d{6}"]]],808:["808",0,"[1-9]\\d{7}",[8],[["(\\d{4})(\\d{4})","$1 $2",["[1-9]"]]],0,0,0,0,0,0,[0,0,0,0,0,0,0,0,0,["[1-9]\\d{7}"]]],870:["870",0,"7\\d{11}|[235-7]\\d{8}",[9,12],[["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[235-7]"]]],0,0,0,0,0,0,[0,["(?:[356]|774[45])\\d{8}|7[6-8]\\d{7}"],0,0,0,0,0,0,["2\\d{8}",[9]]]],878:["878",0,"10\\d{10}",[12],[["(\\d{2})(\\d{5})(\\d{5})","$1 $2 $3",["1"]]],0,0,0,0,0,0,[0,0,0,0,0,0,0,0,["10\\d{10}"]]],881:["881",0,"6\\d{9}|[0-36-9]\\d{8}",[9,10],[["(\\d)(\\d{3})(\\d{5})","$1 $2 $3",["[0-37-9]"]],["(\\d)(\\d{3})(\\d{5,6})","$1 $2 $3",["6"]]],0,0,0,0,0,0,[0,["6\\d{9}|[0-36-9]\\d{8}"]]],882:["882",0,"[13]\\d{6}(?:\\d{2,5})?|[19]\\d{7}|(?:[25]\\d\\d|4)\\d{7}(?:\\d{2})?",[7,8,9,10,11,12],[["(\\d{2})(\\d{5})","$1 $2",["16|342"]],["(\\d{2})(\\d{6})","$1 $2",["49"]],["(\\d{2})(\\d{2})(\\d{4})","$1 $2 $3",["1[36]|9"]],["(\\d{2})(\\d{4})(\\d{3})","$1 $2 $3",["3[23]"]],["(\\d{2})(\\d{3,4})(\\d{4})","$1 $2 $3",["16"]],["(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3",["10|23|3(?:[15]|4[57])|4|51"]],["(\\d{3})(\\d{4})(\\d{4})","$1 $2 $3",["34"]],["(\\d{2})(\\d{4,5})(\\d{5})","$1 $2 $3",["[1-35]"]]],0,0,0,0,0,0,[0,["342\\d{4}|(?:337|49)\\d{6}|(?:3(?:2|47|7\\d{3})|50\\d{3})\\d{7}",[7,8,9,10,12]],0,0,0,["348[57]\\d{7}",[11]],0,0,["1(?:3(?:0[0347]|[13][0139]|2[035]|4[013568]|6[0459]|7[06]|8[15-8]|9[0689])\\d{4}|6\\d{5,10})|(?:345\\d|9[89])\\d{6}|(?:10|2(?:3|85\\d)|3(?:[15]|[69]\\d\\d)|4[15-8]|51)\\d{8}"]]],883:["883",0,"(?:[1-4]\\d|51)\\d{6,10}",[8,9,10,11,12],[["(\\d{3})(\\d{3})(\\d{2,8})","$1 $2 $3",["[14]|2[24-689]|3[02-689]|51[24-9]"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["510"]],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["21"]],["(\\d{4})(\\d{4})(\\d{4})","$1 $2 $3",["51[13]"]],["(\\d{3})(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3 $4",["[235]"]]],0,0,0,0,0,0,[0,0,0,0,0,0,0,0,["(?:2(?:00\\d\\d|10)|(?:370[1-9]|51\\d0)\\d)\\d{7}|51(?:00\\d{5}|[24-9]0\\d{4,7})|(?:1[0-79]|2[24-689]|3[02-689]|4[0-4])0\\d{5,9}"]]],888:["888",0,"\\d{11}",[11],[["(\\d{3})(\\d{3})(\\d{5})","$1 $2 $3"]],0,0,0,0,0,0,[0,0,0,0,0,0,["\\d{11}"]]],979:["979",0,"[1359]\\d{8}",[9],[["(\\d)(\\d{4})(\\d{4})","$1 $2 $3",["[1359]"]]],0,0,0,0,0,0,[0,0,0,["[1359]\\d{8}"]]]}};function c5(t,e){var n=Array.prototype.slice.call(e);return n.push(a5),t.apply(this,n)}function _g(t,e){t=t.split("-"),e=e.split("-");for(var n=t[0].split("."),r=e[0].split("."),i=0;i<3;i++){var s=Number(n[i]),a=Number(r[i]);if(s>a)return 1;if(a>s)return-1;if(!isNaN(s)&&isNaN(a))return 1;if(isNaN(s)&&!isNaN(a))return-1}return t[1]&&e[1]?t[1]>e[1]?1:t[1]<e[1]?-1:0:!t[1]&&e[1]?1:t[1]&&!e[1]?-1:0}var l5={}.constructor;function Yr(t){return t!=null&&t.constructor===l5}function nu(t){"@babel/helpers - typeof";return nu=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},nu(t)}function qc(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function d5(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function Hc(t,e,n){return e&&d5(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t}var u5="1.2.0",p5="1.7.35",yg=" ext. ",f5=/^\d+$/,wt=function(){function t(e){qc(this,t),f1(e),this.metadata=e,h1.call(this,e)}return Hc(t,[{key:"getCountries",value:function(){return Object.keys(this.metadata.countries).filter(function(n){return n!=="001"})}},{key:"getCountryMetadata",value:function(n){return this.metadata.countries[n]}},{key:"nonGeographic",value:function(){if(!(this.v1||this.v2||this.v3))return this.metadata.nonGeographic||this.metadata.nonGeographical}},{key:"hasCountry",value:function(n){return this.getCountryMetadata(n)!==void 0}},{key:"hasCallingCode",value:function(n){if(this.getCountryCodesForCallingCode(n))return!0;if(this.nonGeographic()){if(this.nonGeographic()[n])return!0}else{var r=this.countryCallingCodes()[n];if(r&&r.length===1&&r[0]==="001")return!0}}},{key:"isNonGeographicCallingCode",value:function(n){return this.nonGeographic()?!!this.nonGeographic()[n]:!this.getCountryCodesForCallingCode(n)}},{key:"country",value:function(n){return this.selectNumberingPlan(n)}},{key:"selectNumberingPlan",value:function(n,r){if(n&&f5.test(n)&&(r=n,n=null),n&&n!=="001"){if(!this.hasCountry(n))throw new Error("Unknown country: ".concat(n));this.numberingPlan=new wg(this.getCountryMetadata(n),this)}else if(r){if(!this.hasCallingCode(r))throw new Error("Unknown calling code: ".concat(r));this.numberingPlan=new wg(this.getNumberingPlanMetadata(r),this)}else this.numberingPlan=void 0;return this}},{key:"getCountryCodesForCallingCode",value:function(n){var r=this.countryCallingCodes()[n];if(r)return r.length===1&&r[0].length===3?void 0:r}},{key:"getCountryCodeForCallingCode",value:function(n){var r=this.getCountryCodesForCallingCode(n);if(r)return r[0]}},{key:"getNumberingPlanMetadata",value:function(n){var r=this.getCountryCodeForCallingCode(n);if(r)return this.getCountryMetadata(r);if(this.nonGeographic()){var i=this.nonGeographic()[n];if(i)return i}else{var s=this.countryCallingCodes()[n];if(s&&s.length===1&&s[0]==="001")return this.metadata.countries["001"]}}},{key:"countryCallingCode",value:function(){return this.numberingPlan.callingCode()}},{key:"IDDPrefix",value:function(){return this.numberingPlan.IDDPrefix()}},{key:"defaultIDDPrefix",value:function(){return this.numberingPlan.defaultIDDPrefix()}},{key:"nationalNumberPattern",value:function(){return this.numberingPlan.nationalNumberPattern()}},{key:"possibleLengths",value:function(){return this.numberingPlan.possibleLengths()}},{key:"formats",value:function(){return this.numberingPlan.formats()}},{key:"nationalPrefixForParsing",value:function(){return this.numberingPlan.nationalPrefixForParsing()}},{key:"nationalPrefixTransformRule",value:function(){return this.numberingPlan.nationalPrefixTransformRule()}},{key:"leadingDigits",value:function(){return this.numberingPlan.leadingDigits()}},{key:"hasTypes",value:function(){return this.numberingPlan.hasTypes()}},{key:"type",value:function(n){return this.numberingPlan.type(n)}},{key:"ext",value:function(){return this.numberingPlan.ext()}},{key:"countryCallingCodes",value:function(){return this.v1?this.metadata.country_phone_code_to_countries:this.metadata.country_calling_codes}},{key:"chooseCountryByCountryCallingCode",value:function(n){return this.selectNumberingPlan(n)}},{key:"hasSelectedNumberingPlan",value:function(){return this.numberingPlan!==void 0}}]),t}(),wg=function(){function t(e,n){qc(this,t),this.globalMetadataObject=n,this.metadata=e,h1.call(this,n.metadata)}return Hc(t,[{key:"callingCode",value:function(){return this.metadata[0]}},{key:"getDefaultCountryMetadataForRegion",value:function(){return this.globalMetadataObject.getNumberingPlanMetadata(this.callingCode())}},{key:"IDDPrefix",value:function(){if(!(this.v1||this.v2))return this.metadata[1]}},{key:"defaultIDDPrefix",value:function(){if(!(this.v1||this.v2))return this.metadata[12]}},{key:"nationalNumberPattern",value:function(){return this.v1||this.v2?this.metadata[1]:this.metadata[2]}},{key:"possibleLengths",value:function(){if(!this.v1)return this.metadata[this.v2?2:3]}},{key:"_getFormats",value:function(n){return n[this.v1?2:this.v2?3:4]}},{key:"formats",value:function(){var n=this,r=this._getFormats(this.metadata)||this._getFormats(this.getDefaultCountryMetadataForRegion())||[];return r.map(function(i){return new h5(i,n)})}},{key:"nationalPrefix",value:function(){return this.metadata[this.v1?3:this.v2?4:5]}},{key:"_getNationalPrefixFormattingRule",value:function(n){return n[this.v1?4:this.v2?5:6]}},{key:"nationalPrefixFormattingRule",value:function(){return this._getNationalPrefixFormattingRule(this.metadata)||this._getNationalPrefixFormattingRule(this.getDefaultCountryMetadataForRegion())}},{key:"_nationalPrefixForParsing",value:function(){return this.metadata[this.v1?5:this.v2?6:7]}},{key:"nationalPrefixForParsing",value:function(){return this._nationalPrefixForParsing()||this.nationalPrefix()}},{key:"nationalPrefixTransformRule",value:function(){return this.metadata[this.v1?6:this.v2?7:8]}},{key:"_getNationalPrefixIsOptionalWhenFormatting",value:function(){return!!this.metadata[this.v1?7:this.v2?8:9]}},{key:"nationalPrefixIsOptionalWhenFormattingInNationalFormat",value:function(){return this._getNationalPrefixIsOptionalWhenFormatting(this.metadata)||this._getNationalPrefixIsOptionalWhenFormatting(this.getDefaultCountryMetadataForRegion())}},{key:"leadingDigits",value:function(){return this.metadata[this.v1?8:this.v2?9:10]}},{key:"types",value:function(){return this.metadata[this.v1?9:this.v2?10:11]}},{key:"hasTypes",value:function(){return this.types()&&this.types().length===0?!1:!!this.types()}},{key:"type",value:function(n){if(this.hasTypes()&&vg(this.types(),n))return new m5(vg(this.types(),n),this)}},{key:"ext",value:function(){return this.v1||this.v2?yg:this.metadata[13]||yg}}]),t}(),h5=function(){function t(e,n){qc(this,t),this._format=e,this.metadata=n}return Hc(t,[{key:"pattern",value:function(){return this._format[0]}},{key:"format",value:function(){return this._format[1]}},{key:"leadingDigitsPatterns",value:function(){return this._format[2]||[]}},{key:"nationalPrefixFormattingRule",value:function(){return this._format[3]||this.metadata.nationalPrefixFormattingRule()}},{key:"nationalPrefixIsOptionalWhenFormattingInNationalFormat",value:function(){return!!this._format[4]||this.metadata.nationalPrefixIsOptionalWhenFormattingInNationalFormat()}},{key:"nationalPrefixIsMandatoryWhenFormattingInNationalFormat",value:function(){return this.usesNationalPrefix()&&!this.nationalPrefixIsOptionalWhenFormattingInNationalFormat()}},{key:"usesNationalPrefix",value:function(){return!!(this.nationalPrefixFormattingRule()&&!g5.test(this.nationalPrefixFormattingRule()))}},{key:"internationalFormat",value:function(){return this._format[5]||this.format()}}]),t}(),g5=/^\(?\$1\)?$/,m5=function(){function t(e,n){qc(this,t),this.type=e,this.metadata=n}return Hc(t,[{key:"pattern",value:function(){return this.metadata.v1?this.type:this.type[0]}},{key:"possibleLengths",value:function(){if(!this.metadata.v1)return this.type[1]||this.metadata.possibleLengths()}}]),t}();function vg(t,e){switch(e){case"FIXED_LINE":return t[0];case"MOBILE":return t[1];case"TOLL_FREE":return t[2];case"PREMIUM_RATE":return t[3];case"PERSONAL_NUMBER":return t[4];case"VOICEMAIL":return t[5];case"UAN":return t[6];case"PAGER":return t[7];case"VOIP":return t[8];case"SHARED_COST":return t[9]}}function f1(t){if(!t)throw new Error("[libphonenumber-js] `metadata` argument not passed. Check your arguments.");if(!Yr(t)||!Yr(t.countries))throw new Error("[libphonenumber-js] `metadata` argument was passed but it's not a valid metadata. Must be an object having `.countries` child object property. Got ".concat(Yr(t)?"an object of shape: { "+Object.keys(t).join(", ")+" }":"a "+_5(t)+": "+t,"."))}var _5=function(e){return nu(e)};function Ap(t,e){if(e=new wt(e),e.hasCountry(t))return e.country(t).countryCallingCode();throw new Error("Unknown country: ".concat(t))}function y5(t,e){return e.countries.hasOwnProperty(t)}function h1(t){var e=t.version;typeof e=="number"?(this.v1=e===1,this.v2=e===2,this.v3=e===3,this.v4=e===4):e?_g(e,u5)===-1?this.v2=!0:_g(e,p5)===-1?this.v3=!0:this.v4=!0:this.v1=!0}function Ep(t,e){return w5(t,void 0,e)}function w5(t,e,n){var r=n.type(e),i=r&&r.possibleLengths()||n.possibleLengths();if(!i)return"IS_POSSIBLE";var s=t.length,a=i[0];return a===s?"IS_POSSIBLE":a>s?"TOO_SHORT":i[i.length-1]<s?"TOO_LONG":i.indexOf(s,1)>=0?"IS_POSSIBLE":"INVALID_LENGTH"}function v5(t,e,n){if(e===void 0&&(e={}),n=new wt(n),e.v2){if(!t.countryCallingCode)throw new Error("Invalid phone number object passed");n.selectNumberingPlan(t.countryCallingCode)}else{if(!t.phone)return!1;if(t.country){if(!n.hasCountry(t.country))throw new Error("Unknown country: ".concat(t.country));n.country(t.country)}else{if(!t.countryCallingCode)throw new Error("Invalid phone number object passed");n.selectNumberingPlan(t.countryCallingCode)}}if(n.possibleLengths())return g1(t.phone||t.nationalNumber,n);if(t.countryCallingCode&&n.isNonGeographicCallingCode(t.countryCallingCode))return!0;throw new Error('Missing "possibleLengths" in metadata. Perhaps the metadata has been generated before v1.0.18.')}function g1(t,e){switch(Ep(t,e)){case"IS_POSSIBLE":return!0;default:return!1}}function Nn(t,e){return t=t||"",new RegExp("^(?:"+e+")$").test(t)}function b5(t,e){var n=typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=$5(t))||e){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
|
195
195
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function $5(t,e){if(t){if(typeof t=="string")return bg(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);if(n==="Object"&&t.constructor&&(n=t.constructor.name),n==="Map"||n==="Set")return Array.from(t);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return bg(t,e)}}function bg(t,e){(e==null||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var k5=["MOBILE","PREMIUM_RATE","TOLL_FREE","SHARED_COST","VOIP","PERSONAL_NUMBER","PAGER","UAN","VOICEMAIL"];function Cp(t,e,n){if(e=e||{},!(!t.country&&!t.countryCallingCode)){n=new wt(n),n.selectNumberingPlan(t.country,t.countryCallingCode);var r=e.v2?t.nationalNumber:t.phone;if(Nn(r,n.nationalNumberPattern())){if(pl(r,"FIXED_LINE",n))return n.type("MOBILE")&&n.type("MOBILE").pattern()===""||!n.type("MOBILE")||pl(r,"MOBILE",n)?"FIXED_LINE_OR_MOBILE":"FIXED_LINE";for(var i=b5(k5),s;!(s=i()).done;){var a=s.value;if(pl(r,a,n))return a}}}}function pl(t,e,n){return e=n.type(e),!e||!e.pattern()||e.possibleLengths()&&e.possibleLengths().indexOf(t.length)<0?!1:Nn(t,e.pattern())}function x5(t,e,n){if(e=e||{},n=new wt(n),n.selectNumberingPlan(t.country,t.countryCallingCode),n.hasTypes())return Cp(t,e,n.metadata)!==void 0;var r=e.v2?t.nationalNumber:t.phone;return Nn(r,n.nationalNumberPattern())}function S5(t,e,n){var r=new wt(n),i=r.getCountryCodesForCallingCode(t);return i?i.filter(function(s){return z5(e,s,n)}):[]}function z5(t,e,n){var r=new wt(n);return r.selectNumberingPlan(e),r.numberingPlan.possibleLengths().indexOf(t.length)>=0}var Np=2,A5=17,E5=3,Qt="0-90-9٠-٩۰-۹",C5="-‐-―−ー-",N5="//",I5="..",j5=" ",O5="()()[]\\[\\]",T5="~⁓∼~",Na="".concat(C5).concat(N5).concat(I5).concat(j5).concat(O5).concat(T5),Ip="++",P5=new RegExp("(["+Qt+"])");function R5(t,e,n,r){if(e){var i=new wt(r);i.selectNumberingPlan(e,n);var s=new RegExp(i.IDDPrefix());if(t.search(s)===0){t=t.slice(t.match(s)[0].length);var a=t.match(P5);if(!(a&&a[1]!=null&&a[1].length>0&&a[1]==="0"))return t}}}function B5(t,e){if(t&&e.numberingPlan.nationalPrefixForParsing()){var n=new RegExp("^(?:"+e.numberingPlan.nationalPrefixForParsing()+")"),r=n.exec(t);if(r){var i,s,a=r.length-1,c=a>0&&r[a];if(e.nationalPrefixTransformRule()&&c)i=t.replace(n,e.nationalPrefixTransformRule()),a>1&&(s=r[1]);else{var l=r[0];i=t.slice(l.length),c&&(s=r[1])}var d;if(c){var u=t.indexOf(r[1]),f=t.slice(0,u);f===e.numberingPlan.nationalPrefix()&&(d=e.numberingPlan.nationalPrefix())}else d=r[0];return{nationalNumber:i,nationalPrefix:d,carrierCode:s}}}return{nationalNumber:t}}function ru(t,e){var n=B5(t,e),r=n.carrierCode,i=n.nationalNumber;if(i!==t){if(!L5(t,i,e))return{nationalNumber:t};if(e.possibleLengths()&&!U5(i,e))return{nationalNumber:t}}return{nationalNumber:i,carrierCode:r}}function L5(t,e,n){return!(Nn(t,n.nationalNumberPattern())&&!Nn(e,n.nationalNumberPattern()))}function U5(t,e){switch(Ep(t,e)){case"TOO_SHORT":case"INVALID_LENGTH":return!1;default:return!0}}function D5(t,e,n,r){var i=e?Ap(e,r):n;if(t.indexOf(i)===0){r=new wt(r),r.selectNumberingPlan(e,n);var s=t.slice(i.length),a=ru(s,r),c=a.nationalNumber,l=ru(t,r),d=l.nationalNumber;if(!Nn(d,r.nationalNumberPattern())&&Nn(c,r.nationalNumberPattern())||Ep(d,r)==="TOO_LONG")return{countryCallingCode:i,number:s}}return{number:t}}function m1(t,e,n,r){if(!t)return{};var i;if(t[0]!=="+"){var s=R5(t,e,n,r);if(s&&s!==t)i=!0,t="+"+s;else{if(e||n){var a=D5(t,e,n,r),c=a.countryCallingCode,l=a.number;if(c)return{countryCallingCodeSource:"FROM_NUMBER_WITHOUT_PLUS_SIGN",countryCallingCode:c,number:l}}return{number:t}}}if(t[1]==="0")return{};r=new wt(r);for(var d=2;d-1<=E5&&d<=t.length;){var u=t.slice(1,d);if(r.hasCallingCode(u))return r.selectNumberingPlan(u),{countryCallingCodeSource:i?"FROM_NUMBER_WITH_IDD":"FROM_NUMBER_WITH_PLUS_SIGN",countryCallingCode:u,number:t.slice(d)};d++}return{}}function M5(t){return t.replace(new RegExp("[".concat(Na,"]+"),"g")," ").trim()}var F5=/(\$\d)/;function q5(t,e,n){var r=n.useInternationalFormat,i=n.withNationalPrefix,s=t.replace(new RegExp(e.pattern()),r?e.internationalFormat():i&&e.nationalPrefixFormattingRule()?e.format().replace(F5,e.nationalPrefixFormattingRule()):e.format());return r?M5(s):s}var H5=/^[\d]+(?:[~\u2053\u223C\uFF5E][\d]+)?$/;function V5(t,e,n){var r=new wt(n);if(r.selectNumberingPlan(t,e),r.defaultIDDPrefix())return r.defaultIDDPrefix();if(H5.test(r.IDDPrefix()))return r.IDDPrefix()}var K5=";ext=",Dr=function(e){return"([".concat(Qt,"]{1,").concat(e,"})")};function _1(t){var e="20",n="15",r="9",i="6",s="[ \\t,]*",a="[:\\..]?[ \\t,-]*",c="#?",l="(?:e?xt(?:ensi(?:ó?|ó))?n?|e?xtn?|доб|anexo)",d="(?:[xx##~~]|int|int)",u="[- ]+",f="[ \\t]*",h="(?:,{2}|;)",m=K5+Dr(e),y=s+l+a+Dr(e)+c,v=s+d+a+Dr(r)+c,$=u+Dr(i)+"#",A=f+h+a+Dr(n)+c,O=f+"(?:,)+"+a+Dr(r)+c;return m+"|"+y+"|"+v+"|"+$+"|"+A+"|"+O}var G5="["+Qt+"]{"+Np+"}",W5="["+Ip+"]{0,1}(?:["+Na+"]*["+Qt+"]){3,}["+Na+Qt+"]*",J5=new RegExp("^["+Ip+"]{0,1}(?:["+Na+"]*["+Qt+"]){1,2}$","i"),X5=W5+"(?:"+_1()+")?",Z5=new RegExp("^"+G5+"$|^"+X5+"$","i");function Y5(t){return t.length>=Np&&Z5.test(t)}function Q5(t){return J5.test(t)}function e6(t){var e=t.number,n=t.ext;if(!e)return"";if(e[0]!=="+")throw new Error('"formatRFC3966()" expects "number" to be in E.164 format.');return"tel:".concat(e).concat(n?";ext="+n:"")}function t6(t,e){var n=typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=n6(t))||e){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|