authhero 4.2.0 → 4.4.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 CHANGED
@@ -78,7 +78,7 @@ ${t.join(`
78
78
  `,i=0;for(;i<n.length;)i+64<=n.length?r+=n.substr(i,64)+`\r
79
79
  `:r+=n.substr(i)+`\r
80
80
  `,i+=64;return r+=`-----END ${e} KEY-----\r
81
- `,r}async function F$(e){const t=await e.publicKey.export(),n=await crypto.subtle.exportKey("jwk",t),r=JSON.stringify(n,Object.keys(n).sort()),s=new TextEncoder().encode(r);return Nd(await lb(s))}const H$=1e3*60*60*24,V$=new o.OpenAPIHono().openapi(o.createRoute({tags:["keys"],method:"get",path:"/signing",request:{headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:keys","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.array(Ad)}},description:"List of keys"}}}),async e=>{const{signingKeys:t}=await e.env.data.keys.list({q:"type:jwt_signing"}),n=t.filter(r=>"cert"in r).map(r=>r);return e.json(n)}).openapi(o.createRoute({tags:["keys"],method:"get",path:"/signing/{kid}",request:{headers:o.z.object({"tenant-id":o.z.string().optional()}),params:o.z.object({kid:o.z.string()})},security:[{Bearer:["read:keys","auth:read"]}],responses:{200:{content:{"application/json":{schema:Ad}},description:"The requested key"}}}),async e=>{const{kid:t}=e.req.valid("param"),{signingKeys:n}=await e.env.data.keys.list({q:"type:jwt_signing"}),r=n.find(i=>i.kid===t);if(!r)throw new C(404,{message:"Key not found"});return e.json(r)}).openapi(o.createRoute({tags:["keys"],method:"post",path:"/signing/rotate",request:{headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["create:keys","auth:write"]}],responses:{201:{description:"Status"}}}),async e=>{const{signingKeys:t}=await e.env.data.keys.list({q:"type:jwt_signing"});for await(const r of t)await e.env.data.keys.update(r.kid,{revoked_at:new Date(Date.now()+H$).toISOString()});const n=await Dc({name:`CN=${e.env.ORGANIZATION_NAME}`});return await e.env.data.keys.create({...n,type:"jwt_signing"}),e.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().optional()}),params:o.z.object({kid:o.z.string()})},security:[{Bearer:["update:keys","auth:write"]}],responses:{201:{description:"Status"}}}),async e=>{const{kid:t}=e.req.valid("param");if(!await e.env.data.keys.update(t,{revoked_at:new Date().toISOString()}))throw new C(404,{message:"Key not found"});const r=await Dc({name:`CN=${e.env.ORGANIZATION_NAME}`});return await e.env.data.keys.create({...r,type:"jwt_signing"}),e.text("OK")}),K$=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().optional()})},security:[{Bearer:["read:users","auth:read"]}],responses:{200:{content:{"tenant/json":{schema:o.z.array(_f)}},description:"List of users"}}}),async e=>{const{email:t}=e.req.valid("query"),r=(await Pf(e.env.data.users,e.var.tenant_id,t)).filter(i=>!i.linked_to);return e.json(r)}),G$=wt.extend({clients:o.z.array(br)}),km=o.z.object({enabled_connections:o.z.array(o.z.object({connection_id:o.z.string(),connection:Nt.optional()}))}),W$=o.z.array(o.z.string()),J$=new o.OpenAPIHono().openapi(o.createRoute({tags:["clients"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:clients","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([G$,o.z.array(br)])}},description:"List of clients"}}}),async e=>{const t=e.var.tenant_id,{page:n,per_page:r,include_totals:i,sort:s,q:a}=e.req.valid("query"),u=(await e.env.data.clients.list(t,{page:n,per_page:r,include_totals:i,sort:ct(s),q:a})).clients;return i?e.json({clients:u,start:0,limit:10,length:u.length}):e.json(u)}).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().optional()})},security:[{Bearer:["read:clients","auth:read"]}],responses:{200:{content:{"application/json":{schema:br}},description:"A client"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),r=await e.env.data.clients.get(t,n);if(!r)throw new C(404);return e.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().optional()})},security:[{Bearer:["delete:clients","auth:write"]}],responses:{200:{description:"Status"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param");if(!await e.env.data.clients.remove(t,n))throw new C(404,{message:"Client not found"});return e.text("OK")}).openapi(o.createRoute({tags:["clients"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Ma.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["update:clients","auth:write"]}],responses:{200:{content:{"application/json":{schema:br}},description:"The updated client"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),i=e.req.valid("json");await e.env.data.clients.update(t,n,i);const s=await e.env.data.clients.get(t,n);if(!s)throw new C(404,{message:"Client not found"});return e.json(s)}).openapi(o.createRoute({tags:["clients"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Ma.shape)}}},headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["create:clients","auth:write"]}],responses:{201:{content:{"application/json":{schema:o.z.object(br.shape)}},description:"A client"}}}),async e=>{const t=e.var.tenant_id,n=e.req.valid("json"),r={...n,client_secret:n.client_secret||Ne()},i=await e.env.data.clients.create(t,r);return e.json(i,{status:201})}).openapi(o.createRoute({tags:["clients"],method:"get",path:"/{id}/connections",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:clients","auth:read"]}],responses:{200:{content:{"application/json":{schema:km}},description:"List of connections enabled for this client"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),r=await e.env.data.clients.get(t,n);if(!r)throw new C(404,{message:"Client not found"});const i=r.connections&&r.connections.length>0;let s;if(i)s=await Promise.all(r.connections.map(async a=>{const c=await e.env.data.connections.get(t,a);return{connection_id:a,connection:c||void 0}}));else{const{connections:a}=await e.env.data.connections.list(t,{});s=a.filter(c=>c.id).map(c=>({connection_id:c.id,connection:c}))}return e.json({enabled_connections:s})}).openapi(o.createRoute({tags:["clients"],method:"patch",path:"/{id}/connections",request:{body:{content:{"application/json":{schema:W$}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["update:clients","auth:write"]}],responses:{200:{content:{"application/json":{schema:km}},description:"Updated list of connections for this client"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),r=e.req.valid("json");if(!await e.env.data.clients.get(t,n))throw new C(404,{message:"Client not found"});const s=[];for(const c of r)await e.env.data.connections.get(t,c)&&s.push(c);await e.env.data.clients.update(t,n,{connections:s});const a=await Promise.all(s.map(async c=>{const u=await e.env.data.connections.get(t,c);return{connection_id:c,connection:u||void 0}}));return e.json({enabled_connections:a})}),X$=new o.OpenAPIHono().openapi(o.createRoute({tags:["tenants","settings"],method:"get",path:"/settings",request:{headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:tenants","auth:read"]}],responses:{200:{content:{"application/json":{schema:Ha}},description:"Current tenant settings"}}}),async e=>{const t=await e.env.data.tenants.get(e.var.tenant_id);if(!t)throw new C(404,{message:"Tenant not found"});return e.json(t)}).openapi(o.createRoute({tags:["tenants","settings"],method:"patch",path:"/settings",request:{headers:o.z.object({"tenant-id":o.z.string().optional()}),body:{content:{"application/json":{schema:o.z.object(wf.shape).partial()}}}},security:[{Bearer:["update:tenants","auth:write"]}],responses:{200:{content:{"application/json":{schema:Ha}},description:"Updated tenant settings"}}}),async e=>{const t=e.req.valid("json"),{id:n,...r}=t,i=await e.env.data.tenants.get(e.var.tenant_id);if(!i)throw new C(404,{message:"Tenant not found"});const s=Ed(i,r);await e.env.data.tenants.update(e.var.tenant_id,s);const a=await e.env.data.tenants.get(e.var.tenant_id);if(!a)throw new C(500,{message:"Failed to retrieve updated tenant"});return e.json(a)}),Z$=wt.extend({logs:o.z.array(Ka)}),Y$=new o.OpenAPIHono().openapi(o.createRoute({tags:["logs"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:logs","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(Ka),Z$])}},description:"List of log rows"}}}),async e=>{const{page:t,per_page:n,include_totals:r,sort:i,q:s}=e.req.valid("query"),a=await e.env.data.logs.list(e.var.tenant_id,{page:t,per_page:n,include_totals:r,sort:ct(i),q:s});return r?e.json(a):e.json(a.logs)}).openapi(o.createRoute({tags:["logs"],method:"get",path:"/{id}",request:{headers:o.z.object({"tenant-id":o.z.string().optional()}),params:o.z.object({id:o.z.string()})},security:[{Bearer:["read:logs","auth:read"]}],responses:{200:{content:{"application/json":{schema:Ka}},description:"A log entry"}}}),async e=>{const{id:t}=e.req.valid("param"),n=await e.env.data.logs.get(e.var.tenant_id,t);if(!n)throw new C(404);return e.json(n)}),Q$=17,ek={organization:"org_",connection:"con_",action:"act_",hook:"h_",rule:"rul_",resource_server:"api_",guardian_factor:"gfa_",invite:"inv_",flow:"af_"};function Gu(e){const r=ab("0123456789abcdefghijklmnopqrstuvwxyz",Q$)();return`${ek[e]}${r}`}function tk(){return Gu("organization")}function nk(){return Gu("connection")}function rk(){return Gu("hook")}function ik(){return Gu("invite")}const ok=wt.extend({hooks:o.z.array(_i)}),sk=new o.OpenAPIHono().openapi(o.createRoute({tags:["hooks"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:hooks","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(_i),ok])}},description:"List of hooks"}}}),async e=>{const{page:t,per_page:n,include_totals:r,sort:i,q:s}=e.req.valid("query"),a=await e.env.data.hooks.list(e.var.tenant_id,{page:t,per_page:n,include_totals:r,sort:ct(i),q:s});return r?e.json(a):e.json(a.hooks)}).openapi(o.createRoute({tags:["hooks"],method:"post",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string().optional()}),body:{content:{"application/json":{schema:wa}}}},security:[{Bearer:["create:hooks","auth:write"]}],responses:{201:{content:{"application/json":{schema:_i}},description:"The created hook"}}}),async e=>{const t=e.req.valid("json"),n={...t,hook_id:t.hook_id||rk()},r=await e.env.data.hooks.create(e.var.tenant_id,n);return e.json(r,{status:201})}).openapi(o.createRoute({tags:["hooks"],method:"patch",path:"/{hook_id}",request:{headers:o.z.object({"tenant-id":o.z.string().optional()}),params:o.z.object({hook_id:o.z.string()}),body:{content:{"application/json":{schema:o.z.union([wa.options[0].omit({hook_id:!0}).partial(),wa.options[1].omit({hook_id:!0}).partial()])}}}},security:[{Bearer:["update:hooks","auth:write"]}],responses:{200:{content:{"application/json":{schema:_i}},description:"The updated hook"},404:{description:"Hook not found"}}}),async e=>{const{hook_id:t}=e.req.valid("param"),n=e.req.valid("json");await e.env.data.hooks.update(e.var.tenant_id,t,n);const r=await e.env.data.hooks.get(e.var.tenant_id,t);if(!r)throw new C(404,{message:"Hook not found"});return e.json(r)}).openapi(o.createRoute({tags:["hooks"],method:"get",path:"/{hook_id}",request:{headers:o.z.object({"tenant-id":o.z.string().optional()}),params:o.z.object({hook_id:o.z.string()})},security:[{Bearer:["read:hooks","auth:read"]}],responses:{200:{content:{"application/json":{schema:_i}},description:"A hook"},404:{description:"Hook not found"}}}),async e=>{const{hook_id:t}=e.req.valid("param"),n=await e.env.data.hooks.get(e.var.tenant_id,t);if(!n)throw new C(404,{message:"Hook not found"});return e.json(n)}).openapi(o.createRoute({tags:["hooks"],method:"delete",path:"/{hook_id}",request:{headers:o.z.object({"tenant-id":o.z.string().optional()}),params:o.z.object({hook_id:o.z.string()})},security:[{Bearer:["delete:hooks","auth:write"]}],responses:{200:{description:"A hook"}}}),async e=>{const{hook_id:t}=e.req.valid("param");if(!await e.env.data.hooks.remove(e.var.tenant_id,t))throw new C(404,{message:"Hook not found"});return e.text("OK")});o.z.object({start:o.z.number(),limit:o.z.number(),length:o.z.number()});Vc.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 ak=wt.extend({connections:o.z.array(Nt)}),ck=o.z.object({enabled_clients:o.z.array(o.z.object({client_id:o.z.string(),name:o.z.string()}))}),uk=o.z.array(o.z.object({client_id:o.z.string(),status:o.z.boolean()})),lk=new o.OpenAPIHono().openapi(o.createRoute({tags:["connections"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:connections","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(Nt),ak])}},description:"List of connectionss"}}}),async e=>{const{page:t,per_page:n,include_totals:r=!1,sort:i,q:s}=e.req.valid("query"),a=await e.env.data.connections.list(e.var.tenant_id,{page:t,per_page:n,include_totals:r,sort:ct(i),q:s});return r?e.json(a):e.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().optional()})},security:[{Bearer:["read:connections","auth:read"]}],responses:{200:{content:{"application/json":{schema:Nt}},description:"A connection"}}}),async e=>{const{id:t}=e.req.valid("param"),n=await e.env.data.connections.get(e.var.tenant_id,t);if(!n)throw new C(404);return e.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().optional()})},security:[{Bearer:["delete:connections","auth:write"]}],responses:{200:{description:"Status"}}}),async e=>{const{id:t}=e.req.valid("param"),n=e.var.tenant_id;if(!await e.env.data.connections.remove(n,t))throw new C(404,{message:"Connection not found"});return e.text("OK")}).openapi(o.createRoute({tags:["connections"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Fa.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["update:connections","auth:write"]}],responses:{200:{content:{"application/json":{schema:Nt}},description:"The updated connection"}}}),async e=>{const{id:t}=e.req.valid("param"),n=e.req.valid("json"),r=e.var.tenant_id;if(!await e.env.data.connections.update(r,t,n))throw new C(404,{message:"Connection not found"});const s=await e.env.data.connections.get(r,t);if(!s)throw new C(404,{message:"Connection not found"});return e.json(s)}).openapi(o.createRoute({tags:["connections"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Fa.shape)}}},headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["create:connections","auth:write"]}],responses:{201:{content:{"application/json":{schema:Nt}},description:"A connection"}}}),async e=>{const t=e.req.valid("json"),n=e.var.tenant_id,r=t.id||nk(),i=await e.env.data.connections.create(n,{...t,id:r});return e.json(i,{status:201})}).openapi(o.createRoute({tags:["connections"],method:"get",path:"/{id}/clients",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:connections","auth:read"]}],responses:{200:{content:{"application/json":{schema:ck}},description:"List of clients enabled for this connection"}}}),async e=>{const{id:t}=e.req.valid("param");if(!await e.env.data.connections.get(e.var.tenant_id,t))throw new C(404,{message:"Connection not found"});const{clients:r}=await e.env.data.clients.list(e.var.tenant_id,{per_page:1e3}),i=r.filter(s=>s.connections?.includes(t)).map(s=>({client_id:s.client_id,name:s.name}));return e.json({enabled_clients:i})}).openapi(o.createRoute({tags:["connections"],method:"patch",path:"/{id}/clients",request:{body:{content:{"application/json":{schema:uk}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["update:connections","auth:write"]}],responses:{200:{description:"Clients updated successfully"}}}),async e=>{const{id:t}=e.req.valid("param"),n=e.req.valid("json");if(!await e.env.data.connections.get(e.var.tenant_id,t))throw new C(404,{message:"Connection not found"});for(const i of n){const s=await e.env.data.clients.get(e.var.tenant_id,i.client_id);if(!s)continue;const a=s.connections||[];i.status?a.includes(t)||await e.env.data.clients.update(e.var.tenant_id,i.client_id,{connections:[...a,t]}):a.includes(t)&&await e.env.data.clients.update(e.var.tenant_id,i.client_id,{connections:a.filter(c=>c!==t)})}return e.text("OK")}),dk=new o.OpenAPIHono().openapi(o.createRoute({tags:["prompts"],method:"get",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:prompts","auth:read"]}],responses:{200:{content:{"application/json":{schema:xa}},description:"Branding settings"}}}),async e=>{const t=await e.env.data.promptSettings.get(e.var.tenant_id);return t?e.json(t):e.json(xa.parse({}))}).openapi(o.createRoute({tags:["prompts"],method:"patch",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string().optional()}),body:{content:{"application/json":{schema:o.z.object(xa.shape).partial()}}}},security:[{Bearer:["update:prompts","auth:write"]}],responses:{200:{description:"Prompts settings"}}}),async e=>{const t=e.req.valid("json"),n=await e.env.data.promptSettings.get(e.var.tenant_id);return Object.assign(n,t),await e.env.data.promptSettings.set(e.var.tenant_id,n),e.json(n)});let Sm=!1;function N0(e){e.use(async(t,n)=>(Sm||(e.openAPIRegistry.registerComponent("securitySchemes","Bearer",{type:"oauth2",scheme:"bearer",flows:{implicit:{authorizationUrl:`${t.env.AUTH_URL}/authorize`,scopes:{openid:"Basic user information",email:"User email",profile:"User profile information"}}}}),Sm=!0),await n()))}var pk=(e,t,n={})=>{let r=`${e}=${t}`;if(e.startsWith("__Secure-")&&!n.secure)throw new Error("__Secure- Cookie must have Secure attributes");if(e.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},El=(e,t,n)=>(t=encodeURIComponent(t),pk(e,t,n)),fk=(e,t,n)=>{let r;return n?.prefix==="secure"?r=El("__Secure-"+e,t,{path:"/",...n,secure:!0}):n?.prefix==="host"?r=El("__Host-"+e,t,{...n,path:"/",secure:!0,domain:void 0}):r=El(e,t,{path:"/",...n}),r},zm=(e,t,n,r)=>{const i=fk(t,n,r);e.header("Set-Cookie",i,{append:!0})},Tw=e=>Ow(e.replace(/_|-/g,t=>({_:"/","-":"+"})[t]??t)),Ow=e=>{const t=atob(e),n=new Uint8Array(new ArrayBuffer(t.length)),r=t.length/2;for(let i=0,s=t.length-1;i<=r;i++,s--)n[i]=t.charCodeAt(i),n[s]=t.charCodeAt(s);return n},Pw=(e=>(e.HS256="HS256",e.HS384="HS384",e.HS512="HS512",e.RS256="RS256",e.RS384="RS384",e.RS512="RS512",e.PS256="PS256",e.PS384="PS384",e.PS512="PS512",e.ES256="ES256",e.ES384="ES384",e.ES512="ES512",e.EdDSA="EdDSA",e))(Pw||{}),hk=class extends Error{constructor(e){super(`${e} is not an implemented algorithm`),this.name="JwtAlgorithmNotImplemented"}},Rw=class extends Error{constructor(e){super(`invalid JWT token: ${e}`),this.name="JwtTokenInvalid"}},gk=class extends Error{constructor(e){super(`token (${e}) is being used before it's valid`),this.name="JwtTokenNotBefore"}},mk=class extends Error{constructor(e){super(`token (${e}) expired`),this.name="JwtTokenExpired"}},_k=class extends Error{constructor(e,t){super(`Invalid "iat" claim, must be a valid number lower than "${e}" (iat: "${t}")`),this.name="JwtTokenIssuedAt"}},Cl=class extends Error{constructor(e,t){super(`expected issuer "${e}", got ${t?`"${t}"`:"none"} `),this.name="JwtTokenIssuer"}},yk=class extends Error{constructor(e){super(`jwt header is invalid: ${JSON.stringify(e)}`),this.name="JwtHeaderInvalid"}},bk=class extends Error{constructor(e){super(`token(${e}) signature mismatched`),this.name="JwtTokenSignatureMismatched"}},wk=class extends Error{constructor(e){super(`required "aud" in jwt payload: ${JSON.stringify(e)}`),this.name="JwtPayloadRequiresAud"}},vk=class extends Error{constructor(e,t){super(`expected audience "${Array.isArray(e)?e.join(", "):e}", got "${t}"`),this.name="JwtTokenAudience"}},Bc=(e=>(e.Encrypt="encrypt",e.Decrypt="decrypt",e.Sign="sign",e.Verify="verify",e.DeriveKey="deriveKey",e.DeriveBits="deriveBits",e.WrapKey="wrapKey",e.UnwrapKey="unwrapKey",e))(Bc||{}),Lw=new TextEncoder,xk=new TextDecoder;async function $k(e,t,n,r){const i=Sk(t),s=await kk(e,i);return await crypto.subtle.verify(i,s,n,r)}function Am(e){return Ow(e.replace(/-+(BEGIN|END).*/g,"").replace(/\s/g,""))}async function kk(e,t){if(!crypto.subtle||!crypto.subtle.importKey)throw new Error("`crypto.subtle.importKey` is undefined. JWT auth middleware requires it.");if(zk(e)){if(e.type==="public"||e.type==="secret")return e;e=await Em(e)}if(typeof e=="string"&&e.includes("PRIVATE")){const r=await crypto.subtle.importKey("pkcs8",Am(e),t,!0,[Bc.Sign]);e=await Em(r)}const n=[Bc.Verify];return typeof e=="object"?await crypto.subtle.importKey("jwk",e,t,!1,n):e.includes("PUBLIC")?await crypto.subtle.importKey("spki",Am(e),t,!1,n):await crypto.subtle.importKey("raw",Lw.encode(e),t,!1,n)}async function Em(e){if(e.type!=="private")throw new Error(`unexpected key type: ${e.type}`);if(!e.extractable)throw new Error("unexpected private key is unextractable");const t=await crypto.subtle.exportKey("jwk",e),{kty:n}=t,{alg:r,e:i,n:s}=t,{crv:a,x:c,y:u}=t;return{kty:n,alg:r,e:i,n:s,crv:a,x:c,y:u,key_ops:[Bc.Verify]}}function Sk(e){switch(e){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 hk(e)}}function zk(e){return cb()==="node"&&crypto.webcrypto?e instanceof crypto.webcrypto.CryptoKey:e instanceof CryptoKey}var Cm=e=>JSON.parse(xk.decode(Tw(e)));function Ak(e){if(typeof e=="object"&&e!==null){const t=e;return"alg"in t&&Object.values(Pw).includes(t.alg)&&(!("typ"in t)||t.typ==="JWT")}return!1}var Ek=async(e,t,n)=>{const{alg:r="HS256",iss:i,nbf:s=!0,exp:a=!0,iat:c=!0,aud:u}=typeof n=="string"?{alg:n}:n||{},l=e.split(".");if(l.length!==3)throw new Rw(e);const{header:d,payload:f}=Dw(e);if(!Ak(d))throw new yk(d);const p=Date.now()/1e3|0;if(s&&f.nbf&&f.nbf>p)throw new gk(e);if(a&&f.exp&&f.exp<=p)throw new mk(e);if(c&&f.iat&&p<f.iat)throw new _k(p,f.iat);if(i){if(!f.iss)throw new Cl(i,null);if(typeof i=="string"&&f.iss!==i)throw new Cl(i,f.iss);if(i instanceof RegExp&&!i.test(f.iss))throw new Cl(i,f.iss)}if(u){if(!f.aud)throw new wk(f);if(!(Array.isArray(f.aud)?f.aud:[f.aud]).some(m=>u instanceof RegExp?u.test(m):typeof u=="string"?m===u:Array.isArray(u)&&u.includes(m)))throw new vk(u,f.aud)}const h=e.substring(0,e.lastIndexOf("."));if(!await $k(t,r,Tw(l[2]),Lw.encode(h)))throw new bk(e);return f},Dw=e=>{try{const[t,n]=e.split("."),r=Cm(t),i=Cm(n);return{header:r,payload:i}}catch{throw new Rw(e)}},Bw={verify:Ek,decode:Dw},Ck=Bw.verify,Ik=Bw.decode;async function ef(e){const{signingKeys:t}=await e.keys.list({q:"type:jwt_signing"});return await Promise.all(t.map(async r=>{const s=await new Ku(r.cert).publicKey.export(),a=await crypto.subtle.exportKey("jwk",s);return zf.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())});const Nk="urn:authhero:management";async function jk(e){if(e.JWKS_URL&&e.JWKS_SERVICE){const t=await e.JWKS_SERVICE.fetch(e.JWKS_URL);return t.ok?(await t.json()).keys:(console.warn(`JWKS fetch failed with status ${t.status}, falling back to database`),await ef(e.data))}return await ef(e.data)}async function Tk(e,t){try{const{header:n}=Ik(t),i=(await jk(e.env)).find(c=>c.kid===n.kid);if(!i)throw new Z(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 Ck(t,s,"RS256")}catch(n){throw n instanceof C?n:new Z(403,{message:"Invalid JWT signature"})}}function Ok(e){return e.replace(/:([a-zA-Z_][a-zA-Z0-9_]*)/g,"{$1}")}function Wu(e){return async(t,n)=>{const r=t.req.matchedRoutes.find(u=>u.method.toUpperCase()===t.req.method&&u.path!=="/*");if(!r)return await n();const i=Ok(r.path),s="/api/v2",a=i.startsWith(s)?i.slice(s.length)||"/":i,c=e.openAPIRegistry.definitions.find(u=>"route"in u&&u.route.path===a&&u.route.method.toUpperCase()===t.req.method.toUpperCase());if(c&&"route"in c){const u=c.route.security?.[0]?.Bearer;if(u===void 0)return await n();const l=t.req.header("authorization")||"",[d,f]=l.split(" ");if(d?.toLowerCase()!=="bearer"||!f)throw new Z(401,{message:"Missing bearer token"});try{const p=await Tk(t,f);t.set("user_id",p.sub),t.set("user",p),p.org_name&&t.set("org_name",p.org_name),p.org_id&&t.set("organization_id",p.org_id),!t.var.tenant_id&&p.tenant_id&&t.set("tenant_id",p.tenant_id);const h=Array.isArray(p.permissions)?p.permissions:[],g=typeof p.scope=="string"?p.scope.split(" "):Array.isArray(p.scope)?p.scope:[];if(u.length&&!(u.some(y=>h.includes(y))||u.some(y=>g.includes(y))))throw new Z(403,{message:"Unauthorized"})}catch(p){throw p instanceof C?p:new Z(403,{message:"Invalid token"})}}return await n()}}const Pk=new o.OpenAPIHono().openapi(o.createRoute({tags:["emails"],method:"get",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:emails","auth:read"]}],responses:{200:{content:{"application/json":{schema:$a}},description:"Email provider"}}}),async e=>{const t=await e.env.data.emailProviders.get(e.var.tenant_id);if(!t)throw new C(404,{message:"Email provider not found"});return e.json(t)}).openapi(o.createRoute({tags:["emails"],method:"post",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string().optional()}),body:{content:{"application/json":{schema:o.z.object($a.shape)}}}},security:[{Bearer:["create:emails","auth:write"]}],responses:{200:{description:"Branding settings"}}}),async e=>{const t=e.req.valid("json");return await e.env.data.emailProviders.create(e.var.tenant_id,t),e.text("OK",{status:201})}).openapi(o.createRoute({tags:["emails"],method:"patch",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string().optional()}),body:{content:{"application/json":{schema:o.z.object($a.shape).partial()}}}},security:[{Bearer:["update:emails","auth:write"]}],responses:{200:{description:"Branding settings"}}}),async e=>{const t=e.req.valid("json");return await e.env.data.emailProviders.update(e.var.tenant_id,t),e.text("OK")}),Rk=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().optional()})},security:[{Bearer:["read:sessions","auth:read"]}],responses:{200:{content:{"application/json":{schema:Jc}},description:"A session"}}}),async e=>{const{id:t}=e.req.valid("param"),n=await e.env.data.sessions.get(e.var.tenant_id,t);if(!n)throw new C(404);return e.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().optional()})},security:[{Bearer:["delete:sessions","auth:write"]}],responses:{200:{description:"Status"}}}),async e=>{const{id:t}=e.req.valid("param");if(!await e.env.data.sessions.remove(e.var.tenant_id,t))throw new C(404,{message:"Session not found"});return e.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().optional()})},security:[{Bearer:["update:sessions","auth:write"]}],responses:{202:{description:"Sesssion deletion status"}}}),async e=>{const{id:t}=e.req.valid("param");if(!await e.env.data.sessions.update(e.var.tenant_id,t,{revoked_at:new Date().toDateString()}))throw new C(404,{message:"Session not found"});return e.text("Session deletion request accepted.",{status:202})}),Lk=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().optional()})},security:[{Bearer:["read:refresh_tokens","auth:read"]}],responses:{200:{content:{"application/json":{schema:Ef}},description:"A session"}}}),async e=>{const{id:t}=e.req.valid("param"),n=await e.env.data.refreshTokens.get(e.var.tenant_id,t);if(!n)throw new C(404);return e.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().optional()})},security:[{Bearer:["delete:refresh_tokens","auth:write"]}],responses:{200:{description:"Status"}}}),async e=>{const{id:t}=e.req.valid("param");if(!await e.env.data.refreshTokens.remove(e.var.tenant_id,t))throw new C(404,{message:"Session not found"});return e.text("OK")}),Dk=new o.OpenAPIHono().openapi(o.createRoute({tags:["custom-domains"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:custom_domains","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.array(Vn)}},description:"List of custom domains"}}}),async e=>{const t=await e.env.data.customDomains.list(e.var.tenant_id);return e.json(t)}).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().optional()})},security:[{Bearer:["read:custom_domains","auth:read"]}],responses:{200:{content:{"application/json":{schema:Vn}},description:"A customDomain"}}}),async e=>{const{id:t}=e.req.valid("param"),n=await e.env.data.customDomains.get(e.var.tenant_id,t);if(!n)throw new C(404);return e.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().optional()})},security:[{Bearer:["delete:custom_domains","auth:write"]}],responses:{200:{description:"Status"}}}),async e=>{const{id:t}=e.req.valid("param");if(!await e.env.data.customDomains.remove(e.var.tenant_id,t))throw new C(404,{message:"Custom domain not found"});return e.text("OK")}).openapi(o.createRoute({tags:["custom-domains"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Vn.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["update:custom_domains","auth:write"]}],responses:{200:{content:{"application/json":{schema:Vn}},description:"The updated custom domain"}}}),async e=>{const{id:t}=e.req.valid("param"),n=e.req.valid("json");if(!await e.env.data.customDomains.update(e.var.tenant_id,t,n))throw new C(404);const i=await e.env.data.customDomains.get(e.var.tenant_id,t);if(!i)throw new C(404);return e.json(i)}).openapi(o.createRoute({tags:["custom-domains"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(vf.shape)}}},headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["create:custom_domains","auth:write"]}],responses:{201:{content:{"application/json":{schema:Vn}},description:"The created custom domain"}}}),async e=>{const t=e.req.valid("json"),n=await e.env.data.customDomains.create(e.var.tenant_id,t);return e.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().optional()})},security:[{Bearer:["update:custom_domains","auth:write"]}],responses:{200:{content:{"application/json":{schema:Vn}},description:"The custom domain"}}}),async()=>{throw new C(501,{message:"Not implemented"})});function Ws(e,t){const n={};for(const[r,i]of Object.entries(t)){if(i==null)continue;const s={};for(const[a,c]of Object.entries(i))typeof c=="function"?s[a]=async(...u)=>{const l=performance.now();try{const d=await c(...u),p=performance.now()-l,h=e.res.headers.get("Server-Timing")||"",g=h?`${h}, ${r}-${a};dur=${p.toFixed(2)}`:`${r}-${a};dur=${p.toFixed(2)}`;return e.res.headers.set("Server-Timing",g),d}catch(d){const p=performance.now()-l,h=e.res.headers.get("Server-Timing")||"",g=h?`${h}, ${r}-${a}-error;dur=${p.toFixed(2)}`:`${r}-${a}-error;dur=${p.toFixed(2)}`;throw e.res.headers.set("Server-Timing",g),d}}:s[a]=c;n[r]=s}return n}async function so(e,t){const n=e.var.user;if(n?.tenant_id)return e.set("tenant_id",n.tenant_id),await t();const r=e.req.header("tenant-id");if(r)return e.set("tenant_id",r),await t();const i=e.req.header("x-forwarded-host");if(i){const a=await e.env.data.customDomains.getByDomain(i);if(a)return e.set("tenant_id",a.tenant_id),e.set("custom_domain",i),e.set("host",i),await t()}const s=e.req.header("host");if(s){e.set("host",s);const a=s.split(".");if(a.length>1&&typeof a[0]=="string"){const c=a[0];await e.env.data.tenants.get(c)&&e.set("tenant_id",c)}}else e.set("host",new URL(nu(e.env)).host);if(!e.var.tenant_id){const{tenants:a}=await e.env.data.tenants.list({per_page:2});a.length===1&&a[0]&&e.set("tenant_id",a[0].id)}return await t()}const Bk=o.z.object({name:o.z.string(),version:o.z.string(),env:o.z.object({node:o.z.string().optional()}).optional()});function Uk(e){if(e)try{let t=e;try{t=atob(e)}catch{}try{const n=JSON.parse(t);return Bk.parse(n)}catch{}}catch{return}}const ao=async(e,t)=>{const n=e.req.query("auth0Client")?.slice(0,255),i=(e.req.header("x-forwarded-host")&&e.req.header("x-forwarded-for")?e.req.header("x-forwarded-for")?.split(",")[0]?.trim():e.req.header("cf-connecting-ip")||e.req.header("x-real-ip"))?.slice(0,45),s=e.req.header("user-agent")?.slice(0,512),a=e.req.header("cf-ipcountry")?.slice(0,2),c=n?Uk(n):void 0;c&&e.set("auth0_client",c),i&&e.set("ip",i),s&&e.set("useragent",s),a&&e.set("countryCode",a),await t()};function Mk(e,t,n,r){try{const i=`${e}:${t}:${JSON.stringify(n)}`;return r?`${r}:${i}`:i}catch{const s=`${e}:${t}:${Date.now()}-${Math.random()}`;return r?`${r}:${s}`:s}}function Js(e,t){const{cache:n,defaultTtl:r,customTtls:i={},excludeMethods:s=[],cacheEntities:a=[],keyPrefix:c}=t,u=new Set(s),l=a.length===0,d=new Set(a),f={};for(const[p,h]of Object.entries(e)){if(h==null)continue;const g=l||d.has(p),y={};for(const[w,m]of Object.entries(h))if(typeof m=="function"){if(!g){y[w]=m;continue}const x=`${p}:${w}`;if(u.has(x)){y[w]=m;continue}const $=i[x]??r,k=["create","update","remove","delete","set","used"].includes(w);y[w]=async(...v)=>{if(k)return await m.apply(h,v);const z=Mk(p,w,v,c),A=await n.get(z);if(A!==null)if(A&&typeof A=="object"&&"isCachedNull"in A){const R=A;return R.isCachedNull?null:R.value}else return A;const N=await m.apply(h,v);if($>=0)if(N!==null)await n.set(z,N,$);else{const R={value:null,isCachedNull:!0};await n.set(z,R,$)}return N}}else y[w]=m;f[p]=y}return f}function la(e){if(!e)return;const t=e.filter(n=>n!==void 0);if(t.length!==0)return t.length===1?t[0]:{beforeCreate:Uc(t.map(n=>n.beforeCreate),(n,r)=>[n,r],(n,r)=>[n[0],r]),afterCreate:bi(t.map(n=>n.afterCreate)),beforeUpdate:Uc(t.map(n=>n.beforeUpdate),(n,r,i)=>[n,r,i],(n,r)=>[n[0],n[1],r]),afterUpdate:bi(t.map(n=>n.afterUpdate)),beforeDelete:bi(t.map(n=>n.beforeDelete)),afterDelete:bi(t.map(n=>n.afterDelete))}}function Uc(e,t,n){const r=e.filter(i=>i!==void 0);if(r.length!==0)return r.length===1?r[0]:async(...i)=>{let s=t(...i),a=s[s.length-1];for(const c of r)a=await c(...s),s=n(s,a);return a}}function bi(e){const t=e.filter(n=>n!==void 0);if(t.length!==0)return t.length===1?t[0]:async(...n)=>{for(const r of t)await r(...n)}}function qk(e){if(!e)return;const t=e.filter(n=>n!==void 0);if(t.length!==0)return t.length===1?t[0]:{beforeAssign:Uc(t.map(n=>n.beforeAssign),(n,r,i)=>[n,r,i],(n,r)=>[n[0],n[1],r]),afterAssign:bi(t.map(n=>n.afterAssign)),beforeRemove:Uc(t.map(n=>n.beforeRemove),(n,r,i)=>[n,r,i],(n,r)=>[n[0],n[1],r]),afterRemove:bi(t.map(n=>n.afterRemove))}}function Il(e,t,n){return t?{...e,create:async(r,i)=>{let s=i;t.beforeCreate&&(s=await t.beforeCreate(n,i));const a=await e.create(r,s);return t.afterCreate&&await t.afterCreate(n,a),a},update:async(r,i,s)=>{let a=s;t.beforeUpdate&&(a=await t.beforeUpdate(n,i,s));const c=await e.update(r,i,a);if(t.afterUpdate){let u;typeof c=="boolean"?u=await e.get(r,i):u=c,u&&await t.afterUpdate(n,i,u)}return c},remove:async(r,i)=>{t.beforeDelete&&await t.beforeDelete(n,i);const s=await e.remove(r,i);return t.afterDelete&&s&&await t.afterDelete(n,i),s}}:e}function Fk(e,t,n){return t?{...e,assign:async(r,i,s)=>{let a=s;t.beforeAssign&&(a=await t.beforeAssign(n,i,s));const c=await e.assign(r,i,a);return t.afterAssign&&c&&await t.afterAssign(n,i,a),c},remove:async(r,i,s)=>{let a=s;t.beforeRemove&&(a=await t.beforeRemove(n,i,s));const c=await e.remove(r,i,a);return t.afterRemove&&c&&await t.afterRemove(n,i,a),c}}:e}function Hk(e,t,n){return t?{...e,create:async r=>{let i=r;t.beforeCreate&&(i=await t.beforeCreate(n,r));const s=await e.create(i);return t.afterCreate&&await t.afterCreate(n,s),s},update:async(r,i)=>{let s=i;if(t.beforeUpdate&&(s=await t.beforeUpdate(n,r,i)),await e.update(r,s),t.afterUpdate){const a=await e.get(r);a&&await t.afterUpdate(n,r,a)}},remove:async r=>{t.beforeDelete&&await t.beforeDelete(n,r);const i=await e.remove(r);return t.afterDelete&&i&&await t.afterDelete(n,r),i}}:e}function Uw(e,t){const{tenantId:n,entityHooks:r}=t;if(!r)return e;const i={connections:la(r.connections),roles:la(r.roles),resourceServers:la(r.resourceServers),rolePermissions:qk(r.rolePermissions),tenants:la(r.tenants)},s={tenantId:n,adapters:e};return{...e,connections:Il(e.connections,i.connections,s),roles:Il(e.roles,i.roles,s),resourceServers:Il(e.resourceServers,i.resourceServers,s),rolePermissions:Fk(e.rolePermissions,i.rolePermissions,s),tenants:Hk(e.tenants,i.tenants,s)}}class Vk{constructor(t={}){this.config=t;const n=t.cleanupIntervalMs;n&&n>0&&(this.cleanupTimer=setInterval(()=>{this.cleanupExpired()},n))}cache=new Map;accessOrder=new Map;accessCounter=0;cleanupTimer;async get(t){const n=this.cache.get(t);return n?n.expiresAt&&n.expiresAt<new Date?(this.cache.delete(t),this.accessOrder.delete(t),null):(this.accessOrder.set(t,++this.accessCounter),n.value):null}async set(t,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(t)&&this.evictLeastRecentlyUsed();const u={value:n,expiresAt:i};this.cache.set(t,u),this.accessOrder.set(t,++this.accessCounter)}async delete(t){const n=this.cache.has(t);return this.cache.delete(t),this.accessOrder.delete(t),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 t=new Date,n=[];for(const[r,i]of this.cache.entries())i.expiresAt&&i.expiresAt<t&&n.push(r);for(const r of n)this.cache.delete(r),this.accessOrder.delete(r)}evictLeastRecentlyUsed(){let t=null,n=1/0;for(const[r,i]of this.accessOrder.entries())i<n&&(n=i,t=r);t&&(this.cache.delete(t),this.accessOrder.delete(t))}destroy(){this.cleanupTimer&&(clearInterval(this.cleanupTimer),this.cleanupTimer=void 0)}}function co(e={}){return new Vk(e)}const Kk=wt.extend({forms:o.z.array(mi)}),Gk=new o.OpenAPIHono().openapi(o.createRoute({tags:["forms"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:forms","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(mi),Kk])}},description:"List of forms"}}}),async e=>{const t=e.var.tenant_id,{page:n,per_page:r,include_totals:i=!1,sort:s,q:a}=e.req.valid("query"),c=await e.env.data.forms.list(t,{page:n,per_page:r,include_totals:i,sort:ct(s),q:a});return i?e.json(c):e.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().optional()})},security:[{Bearer:["read:forms","auth:read"]}],responses:{200:{content:{"application/json":{schema:mi}},description:"A form"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),r=await e.env.data.forms.get(t,n);if(!r)throw new C(404);return e.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().optional()})},security:[{Bearer:["delete:forms","auth:write"]}],responses:{200:{description:"Status"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param");if(!await e.env.data.forms.remove(t,n))throw new C(404,{message:"Form not found"});return e.text("OK")}).openapi(o.createRoute({tags:["forms"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Va.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["update:forms","auth:write"]}],responses:{200:{content:{"application/json":{schema:mi}},description:"The updated form"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),r=e.req.valid("json");if(!await e.env.data.forms.update(t,n,r))throw new C(404,{message:"Form not found"});const s=await e.env.data.forms.get(t,n);if(!s)throw new C(404,{message:"Form not found"});return e.json(s)}).openapi(o.createRoute({tags:["forms"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Va.shape)}}},headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["create:forms","auth:write"]}],responses:{201:{content:{"application/json":{schema:mi}},description:"A form"}}}),async e=>{const t=e.var.tenant_id,n=e.req.valid("json"),r=await e.env.data.forms.create(t,n);return e.json(r,{status:201})}),Wk=wt.extend({flows:o.z.array(gi)}),Jk=new o.OpenAPIHono().openapi(o.createRoute({tags:["flows"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:flows","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(gi),Wk])}},description:"List of flows"}}}),async e=>{const t=e.var.tenant_id,{page:n,per_page:r,include_totals:i=!1,sort:s,q:a}=e.req.valid("query"),c=await e.env.data.flows.list(t,{page:n,per_page:r,include_totals:i,sort:ct(s),q:a});return i?e.json(c):e.json(c.flows)}).openapi(o.createRoute({tags:["flows"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:flows","auth:read"]}],responses:{200:{content:{"application/json":{schema:gi}},description:"A flow"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),r=await e.env.data.flows.get(t,n);if(!r)throw new C(404);return e.json(r)}).openapi(o.createRoute({tags:["flows"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["delete:flows","auth:write"]}],responses:{200:{description:"Status"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param");if(!await e.env.data.flows.remove(t,n))throw new C(404,{message:"Flow not found"});return e.text("OK")}).openapi(o.createRoute({tags:["flows"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Ba.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["update:flows","auth:write"]}],responses:{200:{content:{"application/json":{schema:gi}},description:"The updated flow"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),r=e.req.valid("json"),i=await e.env.data.flows.update(t,n,r);if(!i)throw new C(404,{message:"Flow not found"});return e.json(i)}).openapi(o.createRoute({tags:["flows"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Ba.shape)}}},headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["create:flows","auth:write"]}],responses:{201:{content:{"application/json":{schema:gi}},description:"The created flow"}}}),async e=>{const t=e.var.tenant_id,n=e.req.valid("json"),r=await e.env.data.flows.create(t,n);return e.json(r,{status:201})}),Xk=wt.extend({roles:o.z.array(xr)}),Zk=new o.OpenAPIHono().openapi(o.createRoute({tags:["roles"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:roles","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(xr),Xk])}},description:"List of roles"}}}),async e=>{const{page:t,per_page:n,include_totals:r,sort:i,q:s}=e.req.valid("query"),a=e.var.tenant_id;if(!a)throw new C(400,{message:"tenant-id header is required"});const c=await e.env.data.roles.list(a,{page:t,per_page:n,include_totals:r,sort:ct(i),q:s});return r?e.json(c):e.json(c.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().optional()})},security:[{Bearer:["read:roles","auth:read"]}],responses:{200:{content:{"application/json":{schema:xr}},description:"A role"}}}),async e=>{const{id:t}=e.req.valid("param"),n=e.var.tenant_id;if(!n)throw new C(400,{message:"tenant-id header is required"});const r=await e.env.data.roles.get(n,t);if(!r)throw new C(404);return e.json(r)}).openapi(o.createRoute({tags:["roles"],method:"post",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string().optional()}),body:{content:{"application/json":{schema:Wa}}}},security:[{Bearer:["create:roles","auth:write"]}],responses:{201:{content:{"application/json":{schema:xr}},description:"Role created"}}}),async e=>{const t=e.req.valid("json"),n=e.var.tenant_id;if(!n)throw new C(400,{message:"tenant-id header is required"});const r=await e.env.data.roles.create(n,t);return e.json(r,{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().optional()}),body:{content:{"application/json":{schema:Wa.partial()}}}},security:[{Bearer:["update:roles","auth:write"]}],responses:{200:{content:{"application/json":{schema:xr}},description:"Updated role"}}}),async e=>{const{id:t}=e.req.valid("param"),n=e.req.valid("json"),r=e.var.tenant_id;if(!r)throw new C(400,{message:"tenant-id header is required"});if(!await e.env.data.roles.update(r,t,n))throw new C(404);const s=await e.env.data.roles.get(r,t);return e.json(s)}).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().optional()})},security:[{Bearer:["delete:roles","auth:write"]}],responses:{200:{description:"Status"}}}),async e=>{const{id:t}=e.req.valid("param"),n=e.var.tenant_id;if(!n)throw new C(400,{message:"tenant-id header is required"});if(!await e.env.data.roles.remove(n,t))throw new C(404);return e.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().optional()}),query:Qe},security:[{Bearer:["read:roles","auth:read"]}],responses:{200:{content:{"application/json":{schema:My}},description:"Role permissions"}}}),async e=>{const{id:t}=e.req.valid("param"),{page:n,per_page:r,sort:i,q:s}=e.req.valid("query"),a=e.var.tenant_id;if(!a)throw new C(400,{message:"tenant-id header is required"});if(!await e.env.data.roles.get(a,t))throw new C(404,{message:"Role not found"});const u=await e.env.data.rolePermissions.list(a,t,{page:n,per_page:r,include_totals:!1,sort:ct(i),q:s});return e.json(u)}).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().optional()}),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:["update:roles","auth:write"]}],responses:{201:{description:"Permissions assigned to role"}}}),async e=>{const{id:t}=e.req.valid("param"),{permissions:n}=e.req.valid("json"),r=e.var.tenant_id;if(!r)throw new C(400,{message:"tenant-id header is required"});if(!await e.env.data.roles.get(r,t))throw new C(404,{message:"Role not found"});const s=n.map(c=>({role_id:t,resource_server_identifier:c.resource_server_identifier,permission_name:c.permission_name}));if(!await e.env.data.rolePermissions.assign(r,t,s))throw new C(500,{message:"Failed to assign permissions to role"});return e.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().optional()}),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:["update:roles","auth:write"]}],responses:{200:{description:"Permissions removed from role"}}}),async e=>{const{id:t}=e.req.valid("param"),{permissions:n}=e.req.valid("json"),r=e.var.tenant_id;if(!r)throw new C(400,{message:"tenant-id header is required"});if(!await e.env.data.roles.get(r,t))throw new C(404,{message:"Role not found"});if(!await e.env.data.rolePermissions.remove(r,t,n))throw new C(500,{message:"Failed to remove permissions from role"});return e.json({message:"Permissions removed successfully"})}),Yk=wt.extend({resource_servers:o.z.array(vr)}),Qk=new o.OpenAPIHono().openapi(o.createRoute({tags:["resource-servers"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:resource_servers","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(vr),Yk])}},description:"List of resource servers"}}}),async e=>{const t=e.var.tenant_id,{page:n,per_page:r,include_totals:i=!1,sort:s,q:a}=e.req.valid("query"),c=await e.env.data.resourceServers.list(t,{page:n,per_page:r,include_totals:i,sort:ct(s),q:a});return i?e.json(c):e.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().optional()})},security:[{Bearer:["read:resource_servers","auth:read"]}],responses:{200:{content:{"application/json":{schema:vr}},description:"A resource server"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),r=await e.env.data.resourceServers.get(t,n);if(!r)throw new C(404);return e.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().optional()})},security:[{Bearer:["delete:resource_servers","auth:write"]}],responses:{200:{description:"Status"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),r=await e.env.data.resourceServers.get(t,n);if(!r)throw new C(404,{message:"Resource server not found"});if(r.is_system)throw new C(403,{message:"System entities cannot be deleted"});return await e.env.data.resourceServers.remove(t,n),e.text("OK")}).openapi(o.createRoute({tags:["resource-servers"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Ga.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["update:resource_servers","auth:write"]}],responses:{200:{content:{"application/json":{schema:vr}},description:"The updated resource server"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),r=e.req.valid("json"),i=await e.env.data.resourceServers.get(t,n);if(!i)throw new C(404,{message:"Resource server not found"});if(i.is_system)throw new C(403,{message:"System entities cannot be modified"});await e.env.data.resourceServers.update(t,n,r);const s=await e.env.data.resourceServers.get(t,n);if(!s)throw new C(404,{message:"Resource server not found"});return e.json(s)}).openapi(o.createRoute({tags:["resource-servers"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Ga.shape)}}},headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["create:resource_servers","auth:write"]}],responses:{201:{content:{"application/json":{schema:vr}},description:"A resource server"}}}),async e=>{const t=e.var.tenant_id,n=e.req.valid("json"),r=await e.env.data.resourceServers.create(t,n);return e.json(r,{status:201})}),e9=o.z.object({per_page:o.z.string().min(1).optional().default("50").transform(e=>parseInt(e,10)).openapi({description:"Number of results per page. Defaults to 50."}),page:o.z.string().min(0).optional().default("0").transform(e=>parseInt(e,10)).openapi({description:"Page index of the results to return. First page is 0."}),include_totals:o.z.string().optional().default("false").transform(e=>e==="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(e=>e?parseInt(e,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(e=>e==="true"?!0:e==="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."})}),t9=wt.extend({client_grants:o.z.array(wr)}),n9=new o.OpenAPIHono().openapi(o.createRoute({tags:["client-grants"],method:"get",path:"/",request:{query:e9,headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:client_grants","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(wr),t9])}},description:"List of client grants"}}}),async e=>{const t=e.var.tenant_id,{page:n,per_page:r,include_totals:i=!1,from:s,take:a,audience:c,client_id:u,allow_any_organization:l,subject_type:d}=e.req.valid("query"),f=[];u&&f.push(`client_id:"${u}"`),c&&f.push(`audience:"${c}"`),l!==void 0&&f.push(`allow_any_organization:${l}`),d&&f.push(`subject_type:"${d}"`),s&&f.push(`id:>${s}`);const p=f.length>0?f.join(" AND "):void 0,h=a??r,g=await e.env.data.clientGrants.list(t,{page:n,per_page:h,include_totals:i,q:p});return i?e.json(g):e.json(g.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().optional()})},security:[{Bearer:["read:client_grants","auth:read"]}],responses:{200:{content:{"application/json":{schema:wr}},description:"A client grant"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),r=await e.env.data.clientGrants.get(t,n);if(!r)throw new C(404,{message:"Client grant not found"});return e.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().optional()})},security:[{Bearer:["delete:client_grants","auth:write"]}],responses:{200:{description:"Status"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param");if(!await e.env.data.clientGrants.remove(t,n))throw new C(404,{message:"Client grant not found"});return e.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(qa.shape).partial()}}},headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["update:client_grants","auth:write"]}],responses:{200:{content:{"application/json":{schema:wr}},description:"The updated client grant"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),r=e.req.valid("json");if(!await e.env.data.clientGrants.get(t,n))throw new C(404,{message:"Client grant not found"});if(!await e.env.data.clientGrants.update(t,n,r))throw new C(500,{message:"Failed to update client grant"});const a=await e.env.data.clientGrants.get(t,n);if(!a)throw new C(404,{message:"Client grant not found"});return e.json(a)}).openapi(o.createRoute({tags:["client-grants"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(qa.shape)}}},headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["create:client_grants","auth:write"]}],responses:{201:{content:{"application/json":{schema:wr}},description:"A client grant"}}}),async e=>{const t=e.var.tenant_id,n=e.req.valid("json"),r=await e.env.data.clientGrants.create(t,n);return e.json(r,{status:201})}),r9=o.z.object({page:o.z.string().optional().default("0").transform(e=>parseInt(e,10)).openapi({description:"Page index of the results to return. First page is 0."}),per_page:o.z.string().optional().default("50").transform(e=>parseInt(e,10)).openapi({description:"Number of results per page. Defaults to 50."}),include_totals:o.z.string().optional().default("false").transform(e=>e==="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(e=>e==="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."})}),i9=o.z.object({invitations:o.z.array(Mo),start:o.z.number(),limit:o.z.number(),length:o.z.number()}),o9=Sf.omit({organization_id:!0,invitation_url:!0}),s9=wt.extend({organizations:o.z.array(Kn)}),j0=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"})}),a9=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(j0).openapi({description:"Array of organization members"})}),c9=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(j0).openapi({description:"Array of organization members"})}),u9=o.z.object({members:o.z.array(o.z.string()).openapi({description:"Array of user IDs to add to the organization"})}),l9=o.z.object({members:o.z.array(o.z.string()).openapi({description:"Array of user IDs to remove from the organization"})}),d9=new o.OpenAPIHono().openapi(o.createRoute({tags:["organizations"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:organizations","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([s9,o.z.array(Kn)])}},description:"List of organizations"}}}),async e=>{const t=e.var.tenant_id,{page:n,per_page:r,include_totals:i,sort:s,q:a,from:c,take:u}=e.req.valid("query"),l=await e.env.data.organizations.list(t,{page:n,per_page:r,include_totals:i,sort:ct(s),q:a,from:c,take:u});return i?e.json(l):e.json(l.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().optional()})},security:[{Bearer:["read:organizations","auth:read"]}],responses:{200:{content:{"application/json":{schema:Kn}},description:"An organization"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),r=await e.env.data.organizations.get(t,n);if(!r)throw new C(404,{message:"Organization not found"});return e.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().optional()})},security:[{Bearer:["delete:organizations","auth:write"]}],responses:{200:{description:"Organization deleted successfully"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param");if(!await e.env.data.organizations.remove(t,n))throw new C(404,{message:"Organization not found"});return e.text("OK")}).openapi(o.createRoute({tags:["organizations"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:Xa.partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["update:organizations","auth:write"]}],responses:{200:{content:{"application/json":{schema:Kn}},description:"The updated organization"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),r=e.req.valid("json");if(!await e.env.data.organizations.update(t,n,r))throw new C(404,{message:"Organization not found"});const s=await e.env.data.organizations.get(t,n);if(!s)throw new C(404,{message:"Organization not found"});return e.json(s)}).openapi(o.createRoute({tags:["organizations"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:Xa}}},headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["create:organizations","auth:write"]}],responses:{201:{content:{"application/json":{schema:Kn}},description:"The created organization"}}}),async e=>{const t=e.var.tenant_id,n=e.req.valid("json"),r={...n,id:n.id||tk()},i=await e.env.data.organizations.create(t,r);return e.json(i,{status:201})}).openapi(o.createRoute({tags:["organizations"],method:"get",path:"/{id}/members",request:{params:o.z.object({id:o.z.string()}),query:Qe,headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:organizations","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(j0),a9,c9])}},description:"List of organization members"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),{page:r,per_page:i,include_totals:s,sort:a}=e.req.valid("query");if(!await e.env.data.organizations.get(t,n))throw new C(404,{message:"Organization not found"});const u=await e.env.data.userOrganizations.list(t,{page:r,per_page:i,include_totals:s,sort:ct(a),q:`organization_id:${n}`}),l=[];for(const d of u.userOrganizations){const f=await e.env.data.users.get(t,d.user_id);f&&l.push({user_id:f.user_id,email:f.email||void 0,roles:[]})}return s?e.json({start:u.start,limit:u.limit,total:u.length,members:l}):e.json(l)}).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().optional()}),body:{content:{"application/json":{schema:u9}}}},security:[{Bearer:["update:organizations","auth:write"]}],responses:{204:{description:"Members added successfully"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),{members:r}=e.req.valid("json");if(!await e.env.data.organizations.get(t,n))throw new C(404,{message:"Organization not found"});for(const s of r)(await e.env.data.userOrganizations.list(t,{q:`user_id:${s}`,per_page:1})).userOrganizations.some(u=>u.organization_id===n)||await e.env.data.userOrganizations.create(t,{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().optional()}),body:{content:{"application/json":{schema:l9}}}},security:[{Bearer:["update:organizations","auth:write"]}],responses:{200:{description:"Members removed successfully"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),{members:r}=e.req.valid("json");for(const i of r){const a=(await e.env.data.userOrganizations.list(t,{q:`user_id:${i}`,per_page:100})).userOrganizations.find(c=>c.organization_id===n);a&&await e.env.data.userOrganizations.remove(t,a.id)}return e.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().optional()}),query:Qe},security:[{Bearer:["read:organizations","auth:read"]}],responses:{200:{content:{"application/json":{schema:Ja}},description:"User roles in organization"}}}),async e=>{const t=e.var.tenant_id,{id:n,user_id:r}=e.req.valid("param");if(!await e.env.data.organizations.get(t,n))throw new C(404,{message:"Organization not found"});if(!await e.env.data.users.get(t,r))throw new C(404,{message:"User not found"});const a=await e.env.data.userRoles.list(t,r,void 0,n);return e.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().optional()}),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:["update:organizations","auth:write"]}],responses:{201:{description:"Roles assigned successfully"}}}),async e=>{const t=e.var.tenant_id,{id:n,user_id:r}=e.req.valid("param"),{roles:i}=e.req.valid("json");if(!await e.env.data.organizations.get(t,n))throw new C(404,{message:"Organization not found"});if(!await e.env.data.users.get(t,r))throw new C(404,{message:"User not found"});for(const c of i){if(!await e.env.data.roles.get(t,c))throw new C(400,{message:`Role ${c} not found`});if(!await e.env.data.userRoles.create(t,r,c,n))throw new C(500,{message:`Failed to assign role ${c} to user`})}return e.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().optional()}),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:["update:organizations","auth:write"]}],responses:{200:{description:"Roles removed successfully"}}}),async e=>{const t=e.var.tenant_id,{id:n,user_id:r}=e.req.valid("param"),{roles:i}=e.req.valid("json");if(!await e.env.data.organizations.get(t,n))throw new C(404,{message:"Organization not found"});if(!await e.env.data.users.get(t,r))throw new C(404,{message:"User not found"});for(const c of i)if(!await e.env.data.userRoles.remove(t,r,c,n))throw new C(500,{message:`Failed to remove role ${c} from user`});return e.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().optional()}),query:Qe},security:[{Bearer:["read:organizations","auth:read"]}],responses:{200:{content:{"application/json":{schema:Ja}},description:"List of roles available in organization"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),{page:r,per_page:i,sort:s,q:a}=e.req.valid("query");if(!await e.env.data.organizations.get(t,n))throw new C(404,{message:"Organization not found"});const u=await e.env.data.roles.list(t,{page:r,per_page:i,sort:ct(s),q:a});return e.json(u.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:r9,headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:organizations","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(Mo),i9])}},description:"List of organization invitations"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),{page:r,per_page:i,include_totals:s,fields:a,include_fields:c,sort:u}=e.req.valid("query");if(!await e.env.data.organizations.get(t,n))throw new C(404,{message:"Organization not found"});let f=(await e.env.data.invites.list(t,{page:r,per_page:i})).invites.filter(p=>p.organization_id===n);if(u){const p=ct(u);if(p){const{sort_by:h,sort_order:g}=p;f.sort((y,w)=>{const m=y[h],x=w[h];if(m===void 0||x===void 0||m===x)return 0;const $=m<x?-1:1;return g==="asc"?$:-$})}}if(a){const p=a.split(",").map(h=>h.trim());f=f.map(h=>{const g={};for(const y of Object.keys(h))(c?p.includes(y):!p.includes(y))&&(g[y]=h[y]);return g})}return s?e.json({invitations:f,start:r*i,limit:i,length:f.length}):e.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().optional()})},security:[{Bearer:["read:organizations","auth:read"]}],responses:{200:{content:{"application/json":{schema:Mo}},description:"An invitation"},404:{description:"Invitation not found"}}}),async e=>{const t=e.var.tenant_id,{id:n,invitation_id:r}=e.req.valid("param"),i=await e.env.data.invites.get(t,r);if(!i||i.organization_id!==n)throw new C(404,{message:"Invitation not found"});return e.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:o9}}},headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["update:organizations","auth:write"]}],responses:{201:{content:{"application/json":{schema:Mo}},description:"The created invitation"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),r=e.req.valid("json");if(!await e.env.data.organizations.get(t,n))throw new C(404,{message:"Organization not found"});const a=`https://invite.placeholder/${ik()}`,c={...r,organization_id:n,invitation_url:a},u=await e.env.data.invites.create(t,c);return e.json(u,{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().optional()})},security:[{Bearer:["update:organizations","auth:write"]}],responses:{204:{description:"Invitation deleted successfully"},404:{description:"Invitation not found"}}}),async e=>{const t=e.var.tenant_id,{id:n,invitation_id:r}=e.req.valid("param"),i=await e.env.data.invites.get(t,r);if(!i||i.organization_id!==n)throw new C(404,{message:"Invitation not found"});if(!await e.env.data.invites.remove(t,r))throw new C(404,{message:"Invitation not found"});return e.body(null,{status:204})}),p9=new o.OpenAPIHono().openapi(o.createRoute({tags:["stats"],method:"get",path:"/daily",request:{query:o.z.object({from:o.z.string().optional().openapi({description:"Optional first day of the date range (inclusive) in YYYYMMDD format",example:"20251120"}),to:o.z.string().optional().openapi({description:"Optional last day of the date range (inclusive) in YYYYMMDD format",example:"20251219"})}),headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:stats","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.array(Yy)}},description:"Daily statistics including logins, signups, and leaked passwords"}}}),async e=>{const{from:t,to:n}=e.req.valid("query");if(!e.env.data.stats)throw new C(501,{message:"Stats adapter not configured"});const r=await e.env.data.stats.getDaily(e.var.tenant_id,{from:t,to:n});return e.json(r)}).openapi(o.createRoute({tags:["stats"],method:"get",path:"/active-users",request:{headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:stats","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.number().openapi({description:"Number of active users in the last 30 days",example:1234})}},description:"Number of active users in the last 30 days"}}}),async e=>{if(!e.env.data.stats)throw new C(501,{message:"Stats adapter not configured"});const t=await e.env.data.stats.getActiveUsers(e.var.tenant_id);return e.json(t)});function f9(e){const t=new o.OpenAPIHono;t.use(U_({origin:r=>r&&e.allowedOrigins?.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})),N0(t),t.use(async(r,i)=>{const s=Vi(r,e.dataAdapter),a=co({defaultTtlSeconds:0,maxEntries:100,cleanupIntervalMs:0}),c=Js(s,{defaultTtl:0,cacheEntities:["tenants","connections","clients","legacyClients","branding","themes","promptSettings","forms"],cache:a});return r.env.data=Ws(r,c),r.env.entityHooks=e.entityHooks,i()}),t.use(ao).use(so).use(Wu(t)).use(async(r,i)=>(e.entityHooks&&r.var.tenant_id&&(r.env.data=Uw(r.env.data,{tenantId:r.var.tenant_id,entityHooks:e.entityHooks})),i()));const n=t.route("/branding",D4).route("/custom-domains",Dk).route("/email/providers",Pk).route("/users",H8).route("/keys",V$).route("/users-by-email",K$).route("/clients",J$).route("/client-grants",n9).route("/tenants",X$).route("/logs",Y$).route("/hooks",sk).route("/connections",lk).route("/prompts",dk).route("/sessions",Rk).route("/refresh_tokens",Lk).route("/forms",Gk).route("/flows",Jk).route("/roles",Zk).route("/resource-servers",Qk).route("/organizations",d9).route("/stats",p9);if(e.managementApiExtensions)for(const r of e.managementApiExtensions)n.route(r.path,r.router);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 h9(e,t){Object.keys(t).forEach(n=>{const r=t[n];r!=null&&r.length&&e.searchParams.set(n,r)})}function Rn(e){if(e)return`${e.name}/${e.version}${e.env?.node?` (env: node/${e.env.node})`:""}`}async function uo(e,t){const n=await e.data.legacyClients.get(t);if(!n)throw new Z(403,{message:"Client not found"});let r=n;if(e.DEFAULT_CLIENT_ID||e.DEFAULT_TENANT_ID){const i=e.DEFAULT_CLIENT_ID?await e.data.legacyClients.get(e.DEFAULT_CLIENT_ID):void 0,s=await e.data.connections.list(n.tenant.id),a=e.DEFAULT_TENANT_ID?await e.data.connections.list(e.DEFAULT_TENANT_ID):{connections:[]},c=s.connections.map(u=>{const l=a.connections?.find(f=>f.name===u.name);if(!l?.options)return u;const d=Nt.parse({...l||{},...u});return d.options=wi.parse({...l.options||{},...u.options}),d}).filter(u=>u);r={...n,web_origins:[...i?.web_origins||[],...n.web_origins||[]],allowed_logout_urls:[...i?.allowed_logout_urls||[],...n.allowed_logout_urls||[]],callbacks:[...i?.callbacks||[],...n.callbacks||[]],connections:c,tenant:{...i?.tenant||{},...n.tenant}}}return{...r,web_origins:[...r.web_origins||[],`${nt(e)}login`],allowed_logout_urls:[...r.allowed_logout_urls||[],e.ISSUER],callbacks:[...r.callbacks||[],`${nt(e)}info`]}}function Pt(e,t){const n=e.var.tenant_id;if(!n){e.set("tenant_id",t);return}if(n!==t)throw new C(403,{message:"Tenant mismatch"})}async function Im(e,t,n,r){if(!r.state)throw new Z(400,{message:"State not found"});const i=t.connections.find(u=>u.name===n);if(!i)throw e.set("client_id",t.client_id),await _e(e,t.tenant.id,{type:he.FAILED_LOGIN,description:"Connection not found"}),new Z(403,{message:"Connection Not Found"});let s=await e.env.data.loginSessions.get(t.tenant.id,r.state);if(!s){const u=e.get("ip"),l=e.get("useragent"),d=e.get("auth0_client");s=await e.env.data.loginSessions.create(t.tenant.id,{expires_at:new Date(Date.now()+Cr*1e3).toISOString(),authParams:r,csrf_token:Ne(),ip:u,useragent:l,auth0Client:Rn(d)})}const c=await Fb(e,i.strategy).getRedirect(e,i);return await e.env.data.codes.create(t.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()+y6*1e3).toISOString()}),new Response(null,{status:302,headers:{location:c.redirectUrl}})}async function Nm(e,{code:t,state:n}){const{env:r}=e,i=await r.data.codes.get(e.var.tenant_id||"",n,"oauth2_state");if(!i||!i.connection_id)throw new Z(403,{message:"State not found"});const s=await r.data.loginSessions.get(e.var.tenant_id||"",i.login_id);if(!s)throw new Z(403,{message:"Session not found"});if(s.authorization_url){const g=new URL(s.authorization_url).hostname,y=e.var.host||"";if(g!==y&&g){const w=new URL(`https://${g}/callback`);return w.searchParams.set("state",n),w.searchParams.set("code",t),new Response("Redirecting",{status:307,headers:{location:w.toString()}})}}const a=await uo(r,s.authParams.client_id);e.set("client_id",a.client_id),Pt(e,a.tenant.id);const c=a.connections.find(g=>g.id===i.connection_id);if(!c)throw await _e(e,a.tenant.id,{type:he.FAILED_LOGIN,description:"Connection not found"}),new Z(403,{message:"Connection not found"});if(e.set("connection",c.name),!s.authParams.redirect_uri)throw await _e(e,a.tenant.id,{type:he.FAILED_LOGIN,description:"Redirect URI not defined"}),new Z(403,{message:"Redirect URI not defined"});const l=await Fb(e,c.strategy).validateAuthorizationCodeAndGetUser(e,c,t,i.code_verifier),{sub:d,...f}=l;e.set("user_id",d);const p=l.email?.toLocaleLowerCase()||`${c.name}.${d}@${new URL(e.env.ISSUER).hostname}`;e.set("username",p);const h=await eu(e,{client:a,username:p,provider:c.strategy,connection:c.name,userId:d,profileData:f,isSocial:!0,ip:e.var.ip});return rn(e,{client:a,authParams:s.authParams,loginSession:s,user:h,authStrategy:{strategy:c.strategy,strategy_type:"social"}})}async function da(e,t,n,r,i,s){const a=await e.env.data.codes.get(e.var.tenant_id||"",t,"oauth2_state");if(!a)throw new C(400,{message:"State not found"});const c=await e.env.data.loginSessions.get(e.var.tenant_id,a.login_id);if(!c)throw new C(400,{message:"Login not found"});const{redirect_uri:u}=c.authParams;if(!u)throw new C(400,{message:"Redirect uri not found"});_e(e,e.var.tenant_id,{type:he.FAILED_LOGIN,description:`Failed connection login: ${i} ${n}, ${r}`});const l=new URL(u);return h9(l,{error:n,error_description:r,error_reason:s,error_code:i,state:c.authParams.state}),e.redirect(`${nt(e.env)}login/identifier?state=${c.id}&error=${n}`)}const g9=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 e=>{const{state:t,code:n,error:r,error_description:i,error_code:s,error_reason:a}=e.req.valid("query");if(r)return da(e,t,r,i,s,a);if(!n)throw new C(400,{message:"Code is required"});try{const c=await Nm(e,{code:n,state:t});if(!(c instanceof Response))throw new C(500,{message:"Internal server error"});return c}catch(c){if(c instanceof Z&&c.status===400){const u=await e.env.data.codes.get(e.var.tenant_id||"",t,"oauth2_state");if(u&&await e.env.data.loginSessions.get(e.var.tenant_id,u.login_id)){let d="access_denied";try{d=JSON.parse(c.message).message||d}catch{d=c.message||d}return da(e,t,"access_denied",d)}}throw 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 e=>{const{state:t,code:n,error:r,error_description:i,error_code:s,error_reason:a}=e.req.valid("form");if(r)return da(e,t,r,i,s,a);if(!n)throw new C(400,{message:"Code is required"});try{const c=await Nm(e,{code:n,state:t});if(!(c instanceof Response))throw new C(500,{message:"Internal server error"});return c}catch(c){if(c instanceof Z&&c.status===400){const u=await e.env.data.codes.get(e.var.tenant_id||"",t,"oauth2_state");if(u&&await e.env.data.loginSessions.get(e.var.tenant_id,u.login_id)){let d="access_denied";try{d=JSON.parse(c.message).message||d}catch{d=c.message||d}return da(e,t,"access_denied",d)}}throw c}});function T0(e,t=[],n={}){try{const r=new URL(e);return t.some(i=>{try{return m9(r,new URL(i),n)}catch{return!1}})}catch{return!1}}function m9(e,t,n={}){if(e.protocol!==t.protocol)return!1;if(n.allowPathWildcards&&t.pathname.includes("*")){const r=t.pathname.replace(/\*/g,".*").replace(/\//g,"\\/");if(!new RegExp(`^${r}$`).test(e.pathname))return!1}else if(e.pathname!==t.pathname)return!1;if(n.allowSubDomainWildcards&&t.hostname.startsWith("*.")&&t.hostname.split(".").length>2&&["http:","https:"].includes(t.protocol)){const r=t.hostname.split(".").slice(1).join(".");return e.hostname===r||e.hostname.endsWith("."+r)}return e.hostname===t.hostname}const _9=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 e=>{const{client_id:t,returnTo:n}=e.req.valid("query"),r=await e.env.data.legacyClients.get(t);if(!r)return e.text("OK");const i=await e.env.data.legacyClients.get("DEFAULT_CLIENT");e.set("client_id",t),Pt(e,r.tenant.id);const s=n||e.req.header("referer");if(!s)return e.text("OK");if(!T0(s,[...r.allowed_logout_urls||[],...i?.allowed_logout_urls||[]],{allowPathWildcards:!0,allowSubDomainWildcards:!0}))throw new C(400,{message:"Invalid redirect uri"});const a=e.req.header("cookie");if(a){const c=Ei(r.tenant.id,a);if(c){const u=await e.env.data.sessions.get(r.tenant.id,c);if(u){const l=await e.env.data.users.get(r.tenant.id,u.user_id);l&&(e.set("user_id",l.user_id),e.set("connection",l.connection));const d=await e.env.data.refreshTokens.list(r.tenant.id,{q:`session_id=${c}`,page:0,per_page:100,include_totals:!1});await Promise.all(d.refresh_tokens.map(f=>e.env.data.refreshTokens.remove(r.tenant.id,f.id))),await e.env.data.sessions.update(r.tenant.id,c,{revoked_at:new Date().toISOString()})}}}return _e(e,r.tenant.id,{type:he.SUCCESS_LOGOUT,description:"User successfully logged out"}),new Response("Redirecting",{status:302,headers:{"set-cookie":gb(r.tenant.id,e.req.header("host")),location:s}})}),jm=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()}),y9=new o.OpenAPIHono().openapi(o.createRoute({tags:["oauth2"],method:"get",path:"/",request:{},security:[{Bearer:["openid"]}],responses:{200:{content:{"application/json":{schema:jm}},description:"Userinfo"}}}),async e=>{if(!e.var.user)throw new C(404,{message:"User not found"});const t=e.var.user.tenant_id||e.var.tenant_id;if(!t)throw new C(400,{message:"Unable to determine tenant"});const n=await e.env.data.users.get(t,e.var.user.sub);if(!n)throw new C(404,{message:"User not found"});const r=jm.parse({...n,sub:n.user_id}),i=e.env.hooks?.onFetchUserInfo;if(i){const s={};return await i({ctx:e,user:n,tenant_id:t,scopes:e.var.scope?.split(" ")||[]},{setCustomClaim:(a,c)=>{s[a]=c}}),e.json({...r,...s})}return e.json(r)}),b9=new o.OpenAPIHono().openapi(o.createRoute({tags:["well known"],method:"get",path:"/jwks.json",request:{},responses:{200:{content:{"application/json":{schema:$y}},description:"List of tenants"}}}),async e=>{const t=await ef(e.env.data);return e.json({keys:t},{headers:{"access-control-allow-origin":"*","access-control-allow-method":"GET","cache-control":`public, max-age=${ia}, stale-while-revalidate=${ia*2}, stale-if-error=86400`}})}).openapi(o.createRoute({tags:["well known"],method:"get",path:"/openid-configuration",request:{},responses:{200:{content:{"application/json":{schema:zd}},description:"List of tenants"}}}),async e=>{const t=zd.parse({issuer:nu(e.env),authorization_endpoint:`${Te(e.env)}authorize`,token_endpoint:`${Te(e.env)}oauth/token`,device_authorization_endpoint:`${Te(e.env)}oauth/device/code`,userinfo_endpoint:`${Te(e.env)}userinfo`,mfa_challenge_endpoint:`${Te(e.env)}mfa/challenge`,jwks_uri:`${Te(e.env)}.well-known/jwks.json`,registration_endpoint:`${Te(e.env)}oidc/register`,revocation_endpoint:`${Te(e.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 e.json(t,{headers:{"access-control-allow-origin":"*","access-control-allow-method":"GET","cache-control":`public, max-age=${ia}, stale-while-revalidate=${ia*2}, stale-if-error=86400`}})});function Xo(e,t){if(!e||!t||e.length!==t.length)return!1;let n=0;for(let r=0;r<e.length;r++)n|=e.charCodeAt(r)^t.charCodeAt(r);return n===0}const Mw=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(),organization:o.z.string().optional()});async function w9(e,t){const n=await e.env.data.legacyClients.get(t.client_id);if(!n)throw new Z(403,{message:"Invalid client credentials"});if(n.client_secret&&!Xo(n.client_secret,t.client_secret))throw new Z(403,{message:"Invalid client credentials"});let r;if(t.organization){const s=await e.env.data.organizations.get(n.tenant.id,t.organization);if(!s)throw new Z(400,{error:"invalid_request",error_description:`Organization '${t.organization}' not found`});r={id:s.id,name:s.name}}const i={client_id:n.client_id,scope:t.scope,audience:t.audience||n.tenant.default_audience,organization:t.organization};return{client:n,authParams:i,organization:r}}const v9=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(e=>"client_secret"in e&&!("code_verifier"in e)||!("client_secret"in e)&&"code_verifier"in e,{message:"Must provide either client_secret (standard flow) or code_verifier/code_verifier_mode (PKCE flow), but not both"});async function x9(e,t){const n=await e.env.data.legacyClients.get(t.client_id);if(!n)throw new Z(403,{message:"Client not found"});const r=await e.env.data.codes.get(n.tenant.id,t.code,"authorization_code");if(!r||!r.user_id)throw _e(e,n.tenant.id,{type:he.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN,description:"Invalid client credentials"}),new Z(403,{message:"Invalid client credentials"});if(new Date(r.expires_at)<new Date)throw _e(e,n.tenant.id,{type:he.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN,description:"Code expired",userId:r.user_id}),new Z(403,{message:"Code expired"});if(r.used_at)throw _e(e,n.tenant.id,{type:he.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN,description:"Invalid authorization code",userId:r.user_id}),new Z(403,{error:"invalid_grant",error_description:"Invalid authorization code"});const i=await e.env.data.loginSessions.get(n.tenant.id,r.login_id);if(!i)throw new Z(403,{message:"Invalid login"});if(t.organization&&i.authParams.organization&&t.organization!==i.authParams.organization)throw new Z(400,{error:"invalid_request",error_description:"Organization parameter does not match login session organization"});if("client_secret"in t){const u=await e.env.data.legacyClients.get("DEFAULT_CLIENT");if(!Xo(n.client_secret,t.client_secret)&&!Xo(u?.client_secret,t.client_secret))throw _e(e,n.tenant.id,{type:he.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN,description:"Invalid client credentials",userId:r.user_id}),new Z(403,{message:"Invalid client credentials"})}else if(r.code_challenge&&r.code_challenge_method&&t.code_verifier){const u=await g6(t.code_verifier,r.code_challenge_method);if(!Xo(u,r.code_challenge))throw _e(e,n.tenant.id,{type:he.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN,description:"Invalid client credentials",userId:r.user_id}),new Z(403,{message:"Invalid client credentials"})}if(r.redirect_uri&&r.redirect_uri!==t.redirect_uri)throw _e(e,n.tenant.id,{type:he.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN,description:"Invalid redirect uri",userId:r.user_id}),new Z(403,{message:"Invalid redirect uri"});const s=await e.env.data.users.get(n.tenant.id,r.user_id);if(!s)throw new Z(403,{message:"User not found"});await e.env.data.codes.used(n.tenant.id,t.code);let a;i.session_id&&i.authParams.scope?.split(" ").includes("offline_access")&&(a=await xb(e,{user:s,client:n,session_id:i.session_id,scope:i.authParams.scope,audience:i.authParams.audience}));let c;if(i.authParams.organization){const u=await e.env.data.organizations.get(n.tenant.id,i.authParams.organization);u?c={id:u.id,name:u.name}:c={id:i.authParams.organization,name:"Unknown"}}return{user:s,client:n,loginSession:i,session_id:i.session_id,refresh_token:a?.id,organization:c,authParams:{...i.authParams,state:r.state,nonce:r.nonce,response_mode:hn.WEB_MESSAGE,client_id:n.client_id,scope:i.authParams.scope,audience:i.authParams.audience}}}function Tm(e,t){const n=e.var.log;n?e.set("log",`${n}
81
+ `,r}async function F$(e){const t=await e.publicKey.export(),n=await crypto.subtle.exportKey("jwk",t),r=JSON.stringify(n,Object.keys(n).sort()),s=new TextEncoder().encode(r);return Nd(await lb(s))}const H$=1e3*60*60*24,V$=new o.OpenAPIHono().openapi(o.createRoute({tags:["keys"],method:"get",path:"/signing",request:{headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:keys","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.array(Ad)}},description:"List of keys"}}}),async e=>{const{signingKeys:t}=await e.env.data.keys.list({q:"type:jwt_signing"}),n=t.filter(r=>"cert"in r).map(r=>r);return e.json(n)}).openapi(o.createRoute({tags:["keys"],method:"get",path:"/signing/{kid}",request:{headers:o.z.object({"tenant-id":o.z.string().optional()}),params:o.z.object({kid:o.z.string()})},security:[{Bearer:["read:keys","auth:read"]}],responses:{200:{content:{"application/json":{schema:Ad}},description:"The requested key"}}}),async e=>{const{kid:t}=e.req.valid("param"),{signingKeys:n}=await e.env.data.keys.list({q:"type:jwt_signing"}),r=n.find(i=>i.kid===t);if(!r)throw new C(404,{message:"Key not found"});return e.json(r)}).openapi(o.createRoute({tags:["keys"],method:"post",path:"/signing/rotate",request:{headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["create:keys","auth:write"]}],responses:{201:{description:"Status"}}}),async e=>{const{signingKeys:t}=await e.env.data.keys.list({q:"type:jwt_signing"});for await(const r of t)await e.env.data.keys.update(r.kid,{revoked_at:new Date(Date.now()+H$).toISOString()});const n=await Dc({name:`CN=${e.env.ORGANIZATION_NAME}`});return await e.env.data.keys.create({...n,type:"jwt_signing"}),e.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().optional()}),params:o.z.object({kid:o.z.string()})},security:[{Bearer:["update:keys","auth:write"]}],responses:{201:{description:"Status"}}}),async e=>{const{kid:t}=e.req.valid("param");if(!await e.env.data.keys.update(t,{revoked_at:new Date().toISOString()}))throw new C(404,{message:"Key not found"});const r=await Dc({name:`CN=${e.env.ORGANIZATION_NAME}`});return await e.env.data.keys.create({...r,type:"jwt_signing"}),e.text("OK")}),K$=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().optional()})},security:[{Bearer:["read:users","auth:read"]}],responses:{200:{content:{"tenant/json":{schema:o.z.array(_f)}},description:"List of users"}}}),async e=>{const{email:t}=e.req.valid("query"),r=(await Pf(e.env.data.users,e.var.tenant_id,t)).filter(i=>!i.linked_to);return e.json(r)}),G$=wt.extend({clients:o.z.array(br)}),km=o.z.object({enabled_connections:o.z.array(o.z.object({connection_id:o.z.string(),connection:Nt.optional()}))}),W$=o.z.array(o.z.string()),J$=new o.OpenAPIHono().openapi(o.createRoute({tags:["clients"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:clients","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([G$,o.z.array(br)])}},description:"List of clients"}}}),async e=>{const t=e.var.tenant_id,{page:n,per_page:r,include_totals:i,sort:s,q:a}=e.req.valid("query"),u=(await e.env.data.clients.list(t,{page:n,per_page:r,include_totals:i,sort:ct(s),q:a})).clients;return i?e.json({clients:u,start:0,limit:10,length:u.length}):e.json(u)}).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().optional()})},security:[{Bearer:["read:clients","auth:read"]}],responses:{200:{content:{"application/json":{schema:br}},description:"A client"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),r=await e.env.data.clients.get(t,n);if(!r)throw new C(404);return e.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().optional()})},security:[{Bearer:["delete:clients","auth:write"]}],responses:{200:{description:"Status"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param");if(!await e.env.data.clients.remove(t,n))throw new C(404,{message:"Client not found"});return e.text("OK")}).openapi(o.createRoute({tags:["clients"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Ma.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["update:clients","auth:write"]}],responses:{200:{content:{"application/json":{schema:br}},description:"The updated client"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),i=e.req.valid("json");await e.env.data.clients.update(t,n,i);const s=await e.env.data.clients.get(t,n);if(!s)throw new C(404,{message:"Client not found"});return e.json(s)}).openapi(o.createRoute({tags:["clients"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Ma.shape)}}},headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["create:clients","auth:write"]}],responses:{201:{content:{"application/json":{schema:o.z.object(br.shape)}},description:"A client"}}}),async e=>{const t=e.var.tenant_id,n=e.req.valid("json"),r={...n,client_secret:n.client_secret||Ne()},i=await e.env.data.clients.create(t,r);return e.json(i,{status:201})}).openapi(o.createRoute({tags:["clients"],method:"get",path:"/{id}/connections",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:clients","auth:read"]}],responses:{200:{content:{"application/json":{schema:km}},description:"List of connections enabled for this client"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),r=await e.env.data.clients.get(t,n);if(!r)throw new C(404,{message:"Client not found"});const i=r.connections&&r.connections.length>0;let s;if(i)s=await Promise.all(r.connections.map(async a=>{const c=await e.env.data.connections.get(t,a);return{connection_id:a,connection:c||void 0}}));else{const{connections:a}=await e.env.data.connections.list(t,{});s=a.filter(c=>c.id).map(c=>({connection_id:c.id,connection:c}))}return e.json({enabled_connections:s})}).openapi(o.createRoute({tags:["clients"],method:"patch",path:"/{id}/connections",request:{body:{content:{"application/json":{schema:W$}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["update:clients","auth:write"]}],responses:{200:{content:{"application/json":{schema:km}},description:"Updated list of connections for this client"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),r=e.req.valid("json");if(!await e.env.data.clients.get(t,n))throw new C(404,{message:"Client not found"});const s=[];for(const c of r)await e.env.data.connections.get(t,c)&&s.push(c);await e.env.data.clients.update(t,n,{connections:s});const a=await Promise.all(s.map(async c=>{const u=await e.env.data.connections.get(t,c);return{connection_id:c,connection:u||void 0}}));return e.json({enabled_connections:a})}),X$=new o.OpenAPIHono().openapi(o.createRoute({tags:["tenants","settings"],method:"get",path:"/settings",request:{headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:tenants","auth:read"]}],responses:{200:{content:{"application/json":{schema:Ha}},description:"Current tenant settings"}}}),async e=>{const t=await e.env.data.tenants.get(e.var.tenant_id);if(!t)throw new C(404,{message:"Tenant not found"});return e.json(t)}).openapi(o.createRoute({tags:["tenants","settings"],method:"patch",path:"/settings",request:{headers:o.z.object({"tenant-id":o.z.string().optional()}),body:{content:{"application/json":{schema:o.z.object(wf.shape).partial()}}}},security:[{Bearer:["update:tenants","auth:write"]}],responses:{200:{content:{"application/json":{schema:Ha}},description:"Updated tenant settings"}}}),async e=>{const t=e.req.valid("json"),{id:n,...r}=t,i=await e.env.data.tenants.get(e.var.tenant_id);if(!i)throw new C(404,{message:"Tenant not found"});const s=Ed(i,r);await e.env.data.tenants.update(e.var.tenant_id,s);const a=await e.env.data.tenants.get(e.var.tenant_id);if(!a)throw new C(500,{message:"Failed to retrieve updated tenant"});return e.json(a)}),Z$=wt.extend({logs:o.z.array(Ka)}),Y$=new o.OpenAPIHono().openapi(o.createRoute({tags:["logs"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:logs","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(Ka),Z$])}},description:"List of log rows"}}}),async e=>{const{page:t,per_page:n,include_totals:r,sort:i,q:s}=e.req.valid("query"),a=await e.env.data.logs.list(e.var.tenant_id,{page:t,per_page:n,include_totals:r,sort:ct(i),q:s});return r?e.json(a):e.json(a.logs)}).openapi(o.createRoute({tags:["logs"],method:"get",path:"/{id}",request:{headers:o.z.object({"tenant-id":o.z.string().optional()}),params:o.z.object({id:o.z.string()})},security:[{Bearer:["read:logs","auth:read"]}],responses:{200:{content:{"application/json":{schema:Ka}},description:"A log entry"}}}),async e=>{const{id:t}=e.req.valid("param"),n=await e.env.data.logs.get(e.var.tenant_id,t);if(!n)throw new C(404);return e.json(n)}),Q$=17,ek={organization:"org_",connection:"con_",action:"act_",hook:"h_",rule:"rul_",resource_server:"api_",guardian_factor:"gfa_",invite:"inv_",flow:"af_"};function Gu(e){const r=ab("0123456789abcdefghijklmnopqrstuvwxyz",Q$)();return`${ek[e]}${r}`}function tk(){return Gu("organization")}function nk(){return Gu("connection")}function rk(){return Gu("hook")}function ik(){return Gu("invite")}const ok=wt.extend({hooks:o.z.array(_i)}),sk=new o.OpenAPIHono().openapi(o.createRoute({tags:["hooks"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:hooks","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(_i),ok])}},description:"List of hooks"}}}),async e=>{const{page:t,per_page:n,include_totals:r,sort:i,q:s}=e.req.valid("query"),a=await e.env.data.hooks.list(e.var.tenant_id,{page:t,per_page:n,include_totals:r,sort:ct(i),q:s});return r?e.json(a):e.json(a.hooks)}).openapi(o.createRoute({tags:["hooks"],method:"post",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string().optional()}),body:{content:{"application/json":{schema:wa}}}},security:[{Bearer:["create:hooks","auth:write"]}],responses:{201:{content:{"application/json":{schema:_i}},description:"The created hook"}}}),async e=>{const t=e.req.valid("json"),n={...t,hook_id:t.hook_id||rk()},r=await e.env.data.hooks.create(e.var.tenant_id,n);return e.json(r,{status:201})}).openapi(o.createRoute({tags:["hooks"],method:"patch",path:"/{hook_id}",request:{headers:o.z.object({"tenant-id":o.z.string().optional()}),params:o.z.object({hook_id:o.z.string()}),body:{content:{"application/json":{schema:o.z.union([wa.options[0].omit({hook_id:!0}).partial(),wa.options[1].omit({hook_id:!0}).partial()])}}}},security:[{Bearer:["update:hooks","auth:write"]}],responses:{200:{content:{"application/json":{schema:_i}},description:"The updated hook"},404:{description:"Hook not found"}}}),async e=>{const{hook_id:t}=e.req.valid("param"),n=e.req.valid("json");await e.env.data.hooks.update(e.var.tenant_id,t,n);const r=await e.env.data.hooks.get(e.var.tenant_id,t);if(!r)throw new C(404,{message:"Hook not found"});return e.json(r)}).openapi(o.createRoute({tags:["hooks"],method:"get",path:"/{hook_id}",request:{headers:o.z.object({"tenant-id":o.z.string().optional()}),params:o.z.object({hook_id:o.z.string()})},security:[{Bearer:["read:hooks","auth:read"]}],responses:{200:{content:{"application/json":{schema:_i}},description:"A hook"},404:{description:"Hook not found"}}}),async e=>{const{hook_id:t}=e.req.valid("param"),n=await e.env.data.hooks.get(e.var.tenant_id,t);if(!n)throw new C(404,{message:"Hook not found"});return e.json(n)}).openapi(o.createRoute({tags:["hooks"],method:"delete",path:"/{hook_id}",request:{headers:o.z.object({"tenant-id":o.z.string().optional()}),params:o.z.object({hook_id:o.z.string()})},security:[{Bearer:["delete:hooks","auth:write"]}],responses:{200:{description:"A hook"}}}),async e=>{const{hook_id:t}=e.req.valid("param");if(!await e.env.data.hooks.remove(e.var.tenant_id,t))throw new C(404,{message:"Hook not found"});return e.text("OK")});o.z.object({start:o.z.number(),limit:o.z.number(),length:o.z.number()});Vc.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 ak=wt.extend({connections:o.z.array(Nt)}),ck=o.z.object({enabled_clients:o.z.array(o.z.object({client_id:o.z.string(),name:o.z.string()}))}),uk=o.z.array(o.z.object({client_id:o.z.string(),status:o.z.boolean()})),lk=new o.OpenAPIHono().openapi(o.createRoute({tags:["connections"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:connections","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(Nt),ak])}},description:"List of connectionss"}}}),async e=>{const{page:t,per_page:n,include_totals:r=!1,sort:i,q:s}=e.req.valid("query"),a=await e.env.data.connections.list(e.var.tenant_id,{page:t,per_page:n,include_totals:r,sort:ct(i),q:s});return r?e.json(a):e.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().optional()})},security:[{Bearer:["read:connections","auth:read"]}],responses:{200:{content:{"application/json":{schema:Nt}},description:"A connection"}}}),async e=>{const{id:t}=e.req.valid("param"),n=await e.env.data.connections.get(e.var.tenant_id,t);if(!n)throw new C(404);return e.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().optional()})},security:[{Bearer:["delete:connections","auth:write"]}],responses:{200:{description:"Status"}}}),async e=>{const{id:t}=e.req.valid("param"),n=e.var.tenant_id;if(!await e.env.data.connections.remove(n,t))throw new C(404,{message:"Connection not found"});return e.text("OK")}).openapi(o.createRoute({tags:["connections"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Fa.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["update:connections","auth:write"]}],responses:{200:{content:{"application/json":{schema:Nt}},description:"The updated connection"}}}),async e=>{const{id:t}=e.req.valid("param"),n=e.req.valid("json"),r=e.var.tenant_id;if(!await e.env.data.connections.update(r,t,n))throw new C(404,{message:"Connection not found"});const s=await e.env.data.connections.get(r,t);if(!s)throw new C(404,{message:"Connection not found"});return e.json(s)}).openapi(o.createRoute({tags:["connections"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Fa.shape)}}},headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["create:connections","auth:write"]}],responses:{201:{content:{"application/json":{schema:Nt}},description:"A connection"}}}),async e=>{const t=e.req.valid("json"),n=e.var.tenant_id,r=t.id||nk(),i=await e.env.data.connections.create(n,{...t,id:r});return e.json(i,{status:201})}).openapi(o.createRoute({tags:["connections"],method:"get",path:"/{id}/clients",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:connections","auth:read"]}],responses:{200:{content:{"application/json":{schema:ck}},description:"List of clients enabled for this connection"}}}),async e=>{const{id:t}=e.req.valid("param");if(!await e.env.data.connections.get(e.var.tenant_id,t))throw new C(404,{message:"Connection not found"});const{clients:r}=await e.env.data.clients.list(e.var.tenant_id,{per_page:1e3}),i=r.filter(s=>s.connections?.includes(t)).map(s=>({client_id:s.client_id,name:s.name}));return e.json({enabled_clients:i})}).openapi(o.createRoute({tags:["connections"],method:"patch",path:"/{id}/clients",request:{body:{content:{"application/json":{schema:uk}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["update:connections","auth:write"]}],responses:{200:{description:"Clients updated successfully"}}}),async e=>{const{id:t}=e.req.valid("param"),n=e.req.valid("json");if(!await e.env.data.connections.get(e.var.tenant_id,t))throw new C(404,{message:"Connection not found"});for(const i of n){const s=await e.env.data.clients.get(e.var.tenant_id,i.client_id);if(!s)continue;const a=s.connections||[];i.status?a.includes(t)||await e.env.data.clients.update(e.var.tenant_id,i.client_id,{connections:[...a,t]}):a.includes(t)&&await e.env.data.clients.update(e.var.tenant_id,i.client_id,{connections:a.filter(c=>c!==t)})}return e.text("OK")}),dk=new o.OpenAPIHono().openapi(o.createRoute({tags:["prompts"],method:"get",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:prompts","auth:read"]}],responses:{200:{content:{"application/json":{schema:xa}},description:"Branding settings"}}}),async e=>{const t=await e.env.data.promptSettings.get(e.var.tenant_id);return t?e.json(t):e.json(xa.parse({}))}).openapi(o.createRoute({tags:["prompts"],method:"patch",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string().optional()}),body:{content:{"application/json":{schema:o.z.object(xa.shape).partial()}}}},security:[{Bearer:["update:prompts","auth:write"]}],responses:{200:{description:"Prompts settings"}}}),async e=>{const t=e.req.valid("json"),n=await e.env.data.promptSettings.get(e.var.tenant_id);return Object.assign(n,t),await e.env.data.promptSettings.set(e.var.tenant_id,n),e.json(n)});let Sm=!1;function N0(e){e.use(async(t,n)=>(Sm||(e.openAPIRegistry.registerComponent("securitySchemes","Bearer",{type:"oauth2",scheme:"bearer",flows:{implicit:{authorizationUrl:`${t.env.AUTH_URL}/authorize`,scopes:{openid:"Basic user information",email:"User email",profile:"User profile information"}}}}),Sm=!0),await n()))}var pk=(e,t,n={})=>{let r=`${e}=${t}`;if(e.startsWith("__Secure-")&&!n.secure)throw new Error("__Secure- Cookie must have Secure attributes");if(e.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},El=(e,t,n)=>(t=encodeURIComponent(t),pk(e,t,n)),fk=(e,t,n)=>{let r;return n?.prefix==="secure"?r=El("__Secure-"+e,t,{path:"/",...n,secure:!0}):n?.prefix==="host"?r=El("__Host-"+e,t,{...n,path:"/",secure:!0,domain:void 0}):r=El(e,t,{path:"/",...n}),r},zm=(e,t,n,r)=>{const i=fk(t,n,r);e.header("Set-Cookie",i,{append:!0})},Tw=e=>Ow(e.replace(/_|-/g,t=>({_:"/","-":"+"})[t]??t)),Ow=e=>{const t=atob(e),n=new Uint8Array(new ArrayBuffer(t.length)),r=t.length/2;for(let i=0,s=t.length-1;i<=r;i++,s--)n[i]=t.charCodeAt(i),n[s]=t.charCodeAt(s);return n},Pw=(e=>(e.HS256="HS256",e.HS384="HS384",e.HS512="HS512",e.RS256="RS256",e.RS384="RS384",e.RS512="RS512",e.PS256="PS256",e.PS384="PS384",e.PS512="PS512",e.ES256="ES256",e.ES384="ES384",e.ES512="ES512",e.EdDSA="EdDSA",e))(Pw||{}),hk=class extends Error{constructor(e){super(`${e} is not an implemented algorithm`),this.name="JwtAlgorithmNotImplemented"}},Rw=class extends Error{constructor(e){super(`invalid JWT token: ${e}`),this.name="JwtTokenInvalid"}},gk=class extends Error{constructor(e){super(`token (${e}) is being used before it's valid`),this.name="JwtTokenNotBefore"}},mk=class extends Error{constructor(e){super(`token (${e}) expired`),this.name="JwtTokenExpired"}},_k=class extends Error{constructor(e,t){super(`Invalid "iat" claim, must be a valid number lower than "${e}" (iat: "${t}")`),this.name="JwtTokenIssuedAt"}},Cl=class extends Error{constructor(e,t){super(`expected issuer "${e}", got ${t?`"${t}"`:"none"} `),this.name="JwtTokenIssuer"}},yk=class extends Error{constructor(e){super(`jwt header is invalid: ${JSON.stringify(e)}`),this.name="JwtHeaderInvalid"}},bk=class extends Error{constructor(e){super(`token(${e}) signature mismatched`),this.name="JwtTokenSignatureMismatched"}},wk=class extends Error{constructor(e){super(`required "aud" in jwt payload: ${JSON.stringify(e)}`),this.name="JwtPayloadRequiresAud"}},vk=class extends Error{constructor(e,t){super(`expected audience "${Array.isArray(e)?e.join(", "):e}", got "${t}"`),this.name="JwtTokenAudience"}},Bc=(e=>(e.Encrypt="encrypt",e.Decrypt="decrypt",e.Sign="sign",e.Verify="verify",e.DeriveKey="deriveKey",e.DeriveBits="deriveBits",e.WrapKey="wrapKey",e.UnwrapKey="unwrapKey",e))(Bc||{}),Lw=new TextEncoder,xk=new TextDecoder;async function $k(e,t,n,r){const i=Sk(t),s=await kk(e,i);return await crypto.subtle.verify(i,s,n,r)}function Am(e){return Ow(e.replace(/-+(BEGIN|END).*/g,"").replace(/\s/g,""))}async function kk(e,t){if(!crypto.subtle||!crypto.subtle.importKey)throw new Error("`crypto.subtle.importKey` is undefined. JWT auth middleware requires it.");if(zk(e)){if(e.type==="public"||e.type==="secret")return e;e=await Em(e)}if(typeof e=="string"&&e.includes("PRIVATE")){const r=await crypto.subtle.importKey("pkcs8",Am(e),t,!0,[Bc.Sign]);e=await Em(r)}const n=[Bc.Verify];return typeof e=="object"?await crypto.subtle.importKey("jwk",e,t,!1,n):e.includes("PUBLIC")?await crypto.subtle.importKey("spki",Am(e),t,!1,n):await crypto.subtle.importKey("raw",Lw.encode(e),t,!1,n)}async function Em(e){if(e.type!=="private")throw new Error(`unexpected key type: ${e.type}`);if(!e.extractable)throw new Error("unexpected private key is unextractable");const t=await crypto.subtle.exportKey("jwk",e),{kty:n}=t,{alg:r,e:i,n:s}=t,{crv:a,x:c,y:u}=t;return{kty:n,alg:r,e:i,n:s,crv:a,x:c,y:u,key_ops:[Bc.Verify]}}function Sk(e){switch(e){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 hk(e)}}function zk(e){return cb()==="node"&&crypto.webcrypto?e instanceof crypto.webcrypto.CryptoKey:e instanceof CryptoKey}var Cm=e=>JSON.parse(xk.decode(Tw(e)));function Ak(e){if(typeof e=="object"&&e!==null){const t=e;return"alg"in t&&Object.values(Pw).includes(t.alg)&&(!("typ"in t)||t.typ==="JWT")}return!1}var Ek=async(e,t,n)=>{const{alg:r="HS256",iss:i,nbf:s=!0,exp:a=!0,iat:c=!0,aud:u}=typeof n=="string"?{alg:n}:n||{},l=e.split(".");if(l.length!==3)throw new Rw(e);const{header:d,payload:f}=Dw(e);if(!Ak(d))throw new yk(d);const p=Date.now()/1e3|0;if(s&&f.nbf&&f.nbf>p)throw new gk(e);if(a&&f.exp&&f.exp<=p)throw new mk(e);if(c&&f.iat&&p<f.iat)throw new _k(p,f.iat);if(i){if(!f.iss)throw new Cl(i,null);if(typeof i=="string"&&f.iss!==i)throw new Cl(i,f.iss);if(i instanceof RegExp&&!i.test(f.iss))throw new Cl(i,f.iss)}if(u){if(!f.aud)throw new wk(f);if(!(Array.isArray(f.aud)?f.aud:[f.aud]).some(m=>u instanceof RegExp?u.test(m):typeof u=="string"?m===u:Array.isArray(u)&&u.includes(m)))throw new vk(u,f.aud)}const h=e.substring(0,e.lastIndexOf("."));if(!await $k(t,r,Tw(l[2]),Lw.encode(h)))throw new bk(e);return f},Dw=e=>{try{const[t,n]=e.split("."),r=Cm(t),i=Cm(n);return{header:r,payload:i}}catch{throw new Rw(e)}},Bw={verify:Ek,decode:Dw},Ck=Bw.verify,Ik=Bw.decode;async function ef(e){const{signingKeys:t}=await e.keys.list({q:"type:jwt_signing"});return await Promise.all(t.map(async r=>{const s=await new Ku(r.cert).publicKey.export(),a=await crypto.subtle.exportKey("jwk",s);return zf.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())});const Nk="urn:authhero:management";async function jk(e){if(e.JWKS_URL&&e.JWKS_SERVICE){const t=await e.JWKS_SERVICE.fetch(e.JWKS_URL);return t.ok?(await t.json()).keys:(console.warn(`JWKS fetch failed with status ${t.status}, falling back to database`),await ef(e.data))}return await ef(e.data)}async function Tk(e,t){try{const{header:n}=Ik(t),i=(await jk(e.env)).find(c=>c.kid===n.kid);if(!i)throw new Z(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 Ck(t,s,"RS256")}catch(n){throw n instanceof C?n:new Z(403,{message:"Invalid JWT signature"})}}function Ok(e){return e.replace(/:([a-zA-Z_][a-zA-Z0-9_]*)/g,"{$1}")}function Wu(e){return async(t,n)=>{const r=t.req.matchedRoutes.find(u=>u.method.toUpperCase()===t.req.method&&u.path!=="/*");if(!r)return await n();const i=Ok(r.path),s="/api/v2",a=i.startsWith(s)?i.slice(s.length)||"/":i,c=e.openAPIRegistry.definitions.find(u=>"route"in u&&u.route.path===a&&u.route.method.toUpperCase()===t.req.method.toUpperCase());if(c&&"route"in c){const u=c.route.security?.[0]?.Bearer;if(u===void 0)return await n();const l=t.req.header("authorization")||"",[d,f]=l.split(" ");if(d?.toLowerCase()!=="bearer"||!f)throw new Z(401,{message:"Missing bearer token"});try{const p=await Tk(t,f);t.set("user_id",p.sub),t.set("user",p),p.org_name&&t.set("org_name",p.org_name),p.org_id&&t.set("organization_id",p.org_id),!t.var.tenant_id&&p.tenant_id&&t.set("tenant_id",p.tenant_id);const h=Array.isArray(p.permissions)?p.permissions:[],g=typeof p.scope=="string"?p.scope.split(" "):Array.isArray(p.scope)?p.scope:[];if(u.length&&!(u.some(y=>h.includes(y))||u.some(y=>g.includes(y))))throw new Z(403,{message:"Unauthorized"})}catch(p){throw p instanceof C?p:new Z(403,{message:"Invalid token"})}}return await n()}}const Pk=new o.OpenAPIHono().openapi(o.createRoute({tags:["emails"],method:"get",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:emails","auth:read"]}],responses:{200:{content:{"application/json":{schema:$a}},description:"Email provider"}}}),async e=>{const t=await e.env.data.emailProviders.get(e.var.tenant_id);if(!t)throw new C(404,{message:"Email provider not found"});return e.json(t)}).openapi(o.createRoute({tags:["emails"],method:"post",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string().optional()}),body:{content:{"application/json":{schema:o.z.object($a.shape)}}}},security:[{Bearer:["create:emails","auth:write"]}],responses:{200:{description:"Branding settings"}}}),async e=>{const t=e.req.valid("json");return await e.env.data.emailProviders.create(e.var.tenant_id,t),e.text("OK",{status:201})}).openapi(o.createRoute({tags:["emails"],method:"patch",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string().optional()}),body:{content:{"application/json":{schema:o.z.object($a.shape).partial()}}}},security:[{Bearer:["update:emails","auth:write"]}],responses:{200:{description:"Branding settings"}}}),async e=>{const t=e.req.valid("json");return await e.env.data.emailProviders.update(e.var.tenant_id,t),e.text("OK")}),Rk=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().optional()})},security:[{Bearer:["read:sessions","auth:read"]}],responses:{200:{content:{"application/json":{schema:Jc}},description:"A session"}}}),async e=>{const{id:t}=e.req.valid("param"),n=await e.env.data.sessions.get(e.var.tenant_id,t);if(!n)throw new C(404);return e.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().optional()})},security:[{Bearer:["delete:sessions","auth:write"]}],responses:{200:{description:"Status"}}}),async e=>{const{id:t}=e.req.valid("param");if(!await e.env.data.sessions.remove(e.var.tenant_id,t))throw new C(404,{message:"Session not found"});return e.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().optional()})},security:[{Bearer:["update:sessions","auth:write"]}],responses:{202:{description:"Sesssion deletion status"}}}),async e=>{const{id:t}=e.req.valid("param");if(!await e.env.data.sessions.update(e.var.tenant_id,t,{revoked_at:new Date().toDateString()}))throw new C(404,{message:"Session not found"});return e.text("Session deletion request accepted.",{status:202})}),Lk=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().optional()})},security:[{Bearer:["read:refresh_tokens","auth:read"]}],responses:{200:{content:{"application/json":{schema:Ef}},description:"A session"}}}),async e=>{const{id:t}=e.req.valid("param"),n=await e.env.data.refreshTokens.get(e.var.tenant_id,t);if(!n)throw new C(404);return e.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().optional()})},security:[{Bearer:["delete:refresh_tokens","auth:write"]}],responses:{200:{description:"Status"}}}),async e=>{const{id:t}=e.req.valid("param");if(!await e.env.data.refreshTokens.remove(e.var.tenant_id,t))throw new C(404,{message:"Session not found"});return e.text("OK")}),Dk=new o.OpenAPIHono().openapi(o.createRoute({tags:["custom-domains"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:custom_domains","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.array(Vn)}},description:"List of custom domains"}}}),async e=>{const t=await e.env.data.customDomains.list(e.var.tenant_id);return e.json(t)}).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().optional()})},security:[{Bearer:["read:custom_domains","auth:read"]}],responses:{200:{content:{"application/json":{schema:Vn}},description:"A customDomain"}}}),async e=>{const{id:t}=e.req.valid("param"),n=await e.env.data.customDomains.get(e.var.tenant_id,t);if(!n)throw new C(404);return e.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().optional()})},security:[{Bearer:["delete:custom_domains","auth:write"]}],responses:{200:{description:"Status"}}}),async e=>{const{id:t}=e.req.valid("param");if(!await e.env.data.customDomains.remove(e.var.tenant_id,t))throw new C(404,{message:"Custom domain not found"});return e.text("OK")}).openapi(o.createRoute({tags:["custom-domains"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Vn.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["update:custom_domains","auth:write"]}],responses:{200:{content:{"application/json":{schema:Vn}},description:"The updated custom domain"}}}),async e=>{const{id:t}=e.req.valid("param"),n=e.req.valid("json");if(!await e.env.data.customDomains.update(e.var.tenant_id,t,n))throw new C(404);const i=await e.env.data.customDomains.get(e.var.tenant_id,t);if(!i)throw new C(404);return e.json(i)}).openapi(o.createRoute({tags:["custom-domains"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(vf.shape)}}},headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["create:custom_domains","auth:write"]}],responses:{201:{content:{"application/json":{schema:Vn}},description:"The created custom domain"}}}),async e=>{const t=e.req.valid("json"),n=await e.env.data.customDomains.create(e.var.tenant_id,t);return e.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().optional()})},security:[{Bearer:["update:custom_domains","auth:write"]}],responses:{200:{content:{"application/json":{schema:Vn}},description:"The custom domain"}}}),async()=>{throw new C(501,{message:"Not implemented"})});function Ws(e,t){const n={};for(const[r,i]of Object.entries(t)){if(i==null)continue;const s={};for(const[a,c]of Object.entries(i))typeof c=="function"?s[a]=async(...u)=>{const l=performance.now();try{const d=await c(...u),p=performance.now()-l,h=e.res.headers.get("Server-Timing")||"",g=h?`${h}, ${r}-${a};dur=${p.toFixed(2)}`:`${r}-${a};dur=${p.toFixed(2)}`;return e.res.headers.set("Server-Timing",g),d}catch(d){const p=performance.now()-l,h=e.res.headers.get("Server-Timing")||"",g=h?`${h}, ${r}-${a}-error;dur=${p.toFixed(2)}`:`${r}-${a}-error;dur=${p.toFixed(2)}`;throw e.res.headers.set("Server-Timing",g),d}}:s[a]=c;n[r]=s}return n}async function so(e,t){const n=e.var.user;if(n?.tenant_id)return e.set("tenant_id",n.tenant_id),await t();const r=e.req.header("tenant-id");if(r)return e.set("tenant_id",r),await t();const i=e.req.header("x-forwarded-host");if(i){const a=await e.env.data.customDomains.getByDomain(i);if(a)return e.set("tenant_id",a.tenant_id),e.set("custom_domain",i),e.set("host",i),await t()}const s=e.req.header("host");if(s){e.set("host",s);const a=s.split(".");if(a.length>1&&typeof a[0]=="string"){const c=a[0];await e.env.data.tenants.get(c)&&e.set("tenant_id",c)}}else e.set("host",new URL(nu(e.env)).host);if(!e.var.tenant_id){const{tenants:a}=await e.env.data.tenants.list({per_page:2});a.length===1&&a[0]&&e.set("tenant_id",a[0].id)}return await t()}const Bk=o.z.object({name:o.z.string(),version:o.z.string(),env:o.z.object({node:o.z.string().optional()}).optional()});function Uk(e){if(e)try{let t=e;try{t=atob(e)}catch{}try{const n=JSON.parse(t);return Bk.parse(n)}catch{}}catch{return}}const ao=async(e,t)=>{const n=e.req.query("auth0Client")?.slice(0,255),i=(e.req.header("x-forwarded-host")&&e.req.header("x-forwarded-for")?e.req.header("x-forwarded-for")?.split(",")[0]?.trim():e.req.header("cf-connecting-ip")||e.req.header("x-real-ip"))?.slice(0,45),s=e.req.header("user-agent")?.slice(0,512),a=e.req.header("cf-ipcountry")?.slice(0,2),c=n?Uk(n):void 0;c&&e.set("auth0_client",c),i&&e.set("ip",i),s&&e.set("useragent",s),a&&e.set("countryCode",a),await t()};function Mk(e,t,n,r){try{const i=`${e}:${t}:${JSON.stringify(n)}`;return r?`${r}:${i}`:i}catch{const s=`${e}:${t}:${Date.now()}-${Math.random()}`;return r?`${r}:${s}`:s}}function Js(e,t){const{cache:n,defaultTtl:r,customTtls:i={},excludeMethods:s=[],cacheEntities:a=[],keyPrefix:c}=t,u=new Set(s),l=a.length===0,d=new Set(a),f={};for(const[p,h]of Object.entries(e)){if(h==null)continue;const g=l||d.has(p),y={};for(const[w,m]of Object.entries(h))if(typeof m=="function"){if(!g){y[w]=m;continue}const x=`${p}:${w}`;if(u.has(x)){y[w]=m;continue}const $=i[x]??r,k=["create","update","remove","delete","set","used"].includes(w);y[w]=async(...v)=>{if(k)return await m.apply(h,v);const z=Mk(p,w,v,c),A=await n.get(z);if(A!==null)if(A&&typeof A=="object"&&"isCachedNull"in A){const R=A;return R.isCachedNull?null:R.value}else return A;const N=await m.apply(h,v);if($>=0)if(N!==null)await n.set(z,N,$);else{const R={value:null,isCachedNull:!0};await n.set(z,R,$)}return N}}else y[w]=m;f[p]=y}return f}function la(e){if(!e)return;const t=e.filter(n=>n!==void 0);if(t.length!==0)return t.length===1?t[0]:{beforeCreate:Uc(t.map(n=>n.beforeCreate),(n,r)=>[n,r],(n,r)=>[n[0],r]),afterCreate:bi(t.map(n=>n.afterCreate)),beforeUpdate:Uc(t.map(n=>n.beforeUpdate),(n,r,i)=>[n,r,i],(n,r)=>[n[0],n[1],r]),afterUpdate:bi(t.map(n=>n.afterUpdate)),beforeDelete:bi(t.map(n=>n.beforeDelete)),afterDelete:bi(t.map(n=>n.afterDelete))}}function Uc(e,t,n){const r=e.filter(i=>i!==void 0);if(r.length!==0)return r.length===1?r[0]:async(...i)=>{let s=t(...i),a=s[s.length-1];for(const c of r)a=await c(...s),s=n(s,a);return a}}function bi(e){const t=e.filter(n=>n!==void 0);if(t.length!==0)return t.length===1?t[0]:async(...n)=>{for(const r of t)await r(...n)}}function qk(e){if(!e)return;const t=e.filter(n=>n!==void 0);if(t.length!==0)return t.length===1?t[0]:{beforeAssign:Uc(t.map(n=>n.beforeAssign),(n,r,i)=>[n,r,i],(n,r)=>[n[0],n[1],r]),afterAssign:bi(t.map(n=>n.afterAssign)),beforeRemove:Uc(t.map(n=>n.beforeRemove),(n,r,i)=>[n,r,i],(n,r)=>[n[0],n[1],r]),afterRemove:bi(t.map(n=>n.afterRemove))}}function Il(e,t,n){return t?{...e,create:async(r,i)=>{let s=i;t.beforeCreate&&(s=await t.beforeCreate(n,i));const a=await e.create(r,s);return t.afterCreate&&await t.afterCreate(n,a),a},update:async(r,i,s)=>{let a=s;t.beforeUpdate&&(a=await t.beforeUpdate(n,i,s));const c=await e.update(r,i,a);if(t.afterUpdate){let u;typeof c=="boolean"?u=await e.get(r,i):u=c,u&&await t.afterUpdate(n,i,u)}return c},remove:async(r,i)=>{t.beforeDelete&&await t.beforeDelete(n,i);const s=await e.remove(r,i);return t.afterDelete&&s&&await t.afterDelete(n,i),s}}:e}function Fk(e,t,n){return t?{...e,assign:async(r,i,s)=>{let a=s;t.beforeAssign&&(a=await t.beforeAssign(n,i,s));const c=await e.assign(r,i,a);return t.afterAssign&&c&&await t.afterAssign(n,i,a),c},remove:async(r,i,s)=>{let a=s;t.beforeRemove&&(a=await t.beforeRemove(n,i,s));const c=await e.remove(r,i,a);return t.afterRemove&&c&&await t.afterRemove(n,i,a),c}}:e}function Hk(e,t,n){return t?{...e,create:async r=>{let i=r;t.beforeCreate&&(i=await t.beforeCreate(n,r));const s=await e.create(i);return t.afterCreate&&await t.afterCreate(n,s),s},update:async(r,i)=>{let s=i;if(t.beforeUpdate&&(s=await t.beforeUpdate(n,r,i)),await e.update(r,s),t.afterUpdate){const a=await e.get(r);a&&await t.afterUpdate(n,r,a)}},remove:async r=>{t.beforeDelete&&await t.beforeDelete(n,r);const i=await e.remove(r);return t.afterDelete&&i&&await t.afterDelete(n,r),i}}:e}function Uw(e,t){const{tenantId:n,entityHooks:r}=t;if(!r)return e;const i={connections:la(r.connections),roles:la(r.roles),resourceServers:la(r.resourceServers),rolePermissions:qk(r.rolePermissions),tenants:la(r.tenants)},s={tenantId:n,adapters:e};return{...e,connections:Il(e.connections,i.connections,s),roles:Il(e.roles,i.roles,s),resourceServers:Il(e.resourceServers,i.resourceServers,s),rolePermissions:Fk(e.rolePermissions,i.rolePermissions,s),tenants:Hk(e.tenants,i.tenants,s)}}class Vk{constructor(t={}){this.config=t;const n=t.cleanupIntervalMs;n&&n>0&&(this.cleanupTimer=setInterval(()=>{this.cleanupExpired()},n))}cache=new Map;accessOrder=new Map;accessCounter=0;cleanupTimer;async get(t){const n=this.cache.get(t);return n?n.expiresAt&&n.expiresAt<new Date?(this.cache.delete(t),this.accessOrder.delete(t),null):(this.accessOrder.set(t,++this.accessCounter),n.value):null}async set(t,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(t)&&this.evictLeastRecentlyUsed();const u={value:n,expiresAt:i};this.cache.set(t,u),this.accessOrder.set(t,++this.accessCounter)}async delete(t){const n=this.cache.has(t);return this.cache.delete(t),this.accessOrder.delete(t),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 t=new Date,n=[];for(const[r,i]of this.cache.entries())i.expiresAt&&i.expiresAt<t&&n.push(r);for(const r of n)this.cache.delete(r),this.accessOrder.delete(r)}evictLeastRecentlyUsed(){let t=null,n=1/0;for(const[r,i]of this.accessOrder.entries())i<n&&(n=i,t=r);t&&(this.cache.delete(t),this.accessOrder.delete(t))}destroy(){this.cleanupTimer&&(clearInterval(this.cleanupTimer),this.cleanupTimer=void 0)}}function co(e={}){return new Vk(e)}const Kk=wt.extend({forms:o.z.array(mi)}),Gk=new o.OpenAPIHono().openapi(o.createRoute({tags:["forms"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:forms","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(mi),Kk])}},description:"List of forms"}}}),async e=>{const t=e.var.tenant_id,{page:n,per_page:r,include_totals:i=!1,sort:s,q:a}=e.req.valid("query"),c=await e.env.data.forms.list(t,{page:n,per_page:r,include_totals:i,sort:ct(s),q:a});return i?e.json(c):e.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().optional()})},security:[{Bearer:["read:forms","auth:read"]}],responses:{200:{content:{"application/json":{schema:mi}},description:"A form"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),r=await e.env.data.forms.get(t,n);if(!r)throw new C(404);return e.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().optional()})},security:[{Bearer:["delete:forms","auth:write"]}],responses:{200:{description:"Status"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param");if(!await e.env.data.forms.remove(t,n))throw new C(404,{message:"Form not found"});return e.text("OK")}).openapi(o.createRoute({tags:["forms"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Va.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["update:forms","auth:write"]}],responses:{200:{content:{"application/json":{schema:mi}},description:"The updated form"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),r=e.req.valid("json");if(!await e.env.data.forms.update(t,n,r))throw new C(404,{message:"Form not found"});const s=await e.env.data.forms.get(t,n);if(!s)throw new C(404,{message:"Form not found"});return e.json(s)}).openapi(o.createRoute({tags:["forms"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Va.shape)}}},headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["create:forms","auth:write"]}],responses:{201:{content:{"application/json":{schema:mi}},description:"A form"}}}),async e=>{const t=e.var.tenant_id,n=e.req.valid("json"),r=await e.env.data.forms.create(t,n);return e.json(r,{status:201})}),Wk=wt.extend({flows:o.z.array(gi)}),Jk=new o.OpenAPIHono().openapi(o.createRoute({tags:["flows"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:flows","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(gi),Wk])}},description:"List of flows"}}}),async e=>{const t=e.var.tenant_id,{page:n,per_page:r,include_totals:i=!1,sort:s,q:a}=e.req.valid("query"),c=await e.env.data.flows.list(t,{page:n,per_page:r,include_totals:i,sort:ct(s),q:a});return i?e.json(c):e.json(c.flows)}).openapi(o.createRoute({tags:["flows"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:flows","auth:read"]}],responses:{200:{content:{"application/json":{schema:gi}},description:"A flow"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),r=await e.env.data.flows.get(t,n);if(!r)throw new C(404);return e.json(r)}).openapi(o.createRoute({tags:["flows"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["delete:flows","auth:write"]}],responses:{200:{description:"Status"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param");if(!await e.env.data.flows.remove(t,n))throw new C(404,{message:"Flow not found"});return e.text("OK")}).openapi(o.createRoute({tags:["flows"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Ba.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["update:flows","auth:write"]}],responses:{200:{content:{"application/json":{schema:gi}},description:"The updated flow"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),r=e.req.valid("json"),i=await e.env.data.flows.update(t,n,r);if(!i)throw new C(404,{message:"Flow not found"});return e.json(i)}).openapi(o.createRoute({tags:["flows"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Ba.shape)}}},headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["create:flows","auth:write"]}],responses:{201:{content:{"application/json":{schema:gi}},description:"The created flow"}}}),async e=>{const t=e.var.tenant_id,n=e.req.valid("json"),r=await e.env.data.flows.create(t,n);return e.json(r,{status:201})}),Xk=wt.extend({roles:o.z.array(xr)}),Zk=new o.OpenAPIHono().openapi(o.createRoute({tags:["roles"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:roles","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(xr),Xk])}},description:"List of roles"}}}),async e=>{const{page:t,per_page:n,include_totals:r,sort:i,q:s}=e.req.valid("query"),a=e.var.tenant_id;if(!a)throw new C(400,{message:"tenant-id header is required"});const c=await e.env.data.roles.list(a,{page:t,per_page:n,include_totals:r,sort:ct(i),q:s});return r?e.json(c):e.json(c.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().optional()})},security:[{Bearer:["read:roles","auth:read"]}],responses:{200:{content:{"application/json":{schema:xr}},description:"A role"}}}),async e=>{const{id:t}=e.req.valid("param"),n=e.var.tenant_id;if(!n)throw new C(400,{message:"tenant-id header is required"});const r=await e.env.data.roles.get(n,t);if(!r)throw new C(404);return e.json(r)}).openapi(o.createRoute({tags:["roles"],method:"post",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string().optional()}),body:{content:{"application/json":{schema:Wa}}}},security:[{Bearer:["create:roles","auth:write"]}],responses:{201:{content:{"application/json":{schema:xr}},description:"Role created"}}}),async e=>{const t=e.req.valid("json"),n=e.var.tenant_id;if(!n)throw new C(400,{message:"tenant-id header is required"});const r=await e.env.data.roles.create(n,t);return e.json(r,{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().optional()}),body:{content:{"application/json":{schema:Wa.partial()}}}},security:[{Bearer:["update:roles","auth:write"]}],responses:{200:{content:{"application/json":{schema:xr}},description:"Updated role"}}}),async e=>{const{id:t}=e.req.valid("param"),n=e.req.valid("json"),r=e.var.tenant_id;if(!r)throw new C(400,{message:"tenant-id header is required"});if(!await e.env.data.roles.update(r,t,n))throw new C(404);const s=await e.env.data.roles.get(r,t);return e.json(s)}).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().optional()})},security:[{Bearer:["delete:roles","auth:write"]}],responses:{200:{description:"Status"}}}),async e=>{const{id:t}=e.req.valid("param"),n=e.var.tenant_id;if(!n)throw new C(400,{message:"tenant-id header is required"});if(!await e.env.data.roles.remove(n,t))throw new C(404);return e.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().optional()}),query:Qe},security:[{Bearer:["read:roles","auth:read"]}],responses:{200:{content:{"application/json":{schema:My}},description:"Role permissions"}}}),async e=>{const{id:t}=e.req.valid("param"),{page:n,per_page:r,sort:i,q:s}=e.req.valid("query"),a=e.var.tenant_id;if(!a)throw new C(400,{message:"tenant-id header is required"});if(!await e.env.data.roles.get(a,t))throw new C(404,{message:"Role not found"});const u=await e.env.data.rolePermissions.list(a,t,{page:n,per_page:r,include_totals:!1,sort:ct(i),q:s});return e.json(u)}).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().optional()}),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:["update:roles","auth:write"]}],responses:{201:{description:"Permissions assigned to role"}}}),async e=>{const{id:t}=e.req.valid("param"),{permissions:n}=e.req.valid("json"),r=e.var.tenant_id;if(!r)throw new C(400,{message:"tenant-id header is required"});if(!await e.env.data.roles.get(r,t))throw new C(404,{message:"Role not found"});const s=n.map(c=>({role_id:t,resource_server_identifier:c.resource_server_identifier,permission_name:c.permission_name}));if(!await e.env.data.rolePermissions.assign(r,t,s))throw new C(500,{message:"Failed to assign permissions to role"});return e.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().optional()}),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:["update:roles","auth:write"]}],responses:{200:{description:"Permissions removed from role"}}}),async e=>{const{id:t}=e.req.valid("param"),{permissions:n}=e.req.valid("json"),r=e.var.tenant_id;if(!r)throw new C(400,{message:"tenant-id header is required"});if(!await e.env.data.roles.get(r,t))throw new C(404,{message:"Role not found"});if(!await e.env.data.rolePermissions.remove(r,t,n))throw new C(500,{message:"Failed to remove permissions from role"});return e.json({message:"Permissions removed successfully"})}),Yk=wt.extend({resource_servers:o.z.array(vr)}),Qk=new o.OpenAPIHono().openapi(o.createRoute({tags:["resource-servers"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:resource_servers","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(vr),Yk])}},description:"List of resource servers"}}}),async e=>{const t=e.var.tenant_id,{page:n,per_page:r,include_totals:i=!1,sort:s,q:a}=e.req.valid("query"),c=await e.env.data.resourceServers.list(t,{page:n,per_page:r,include_totals:i,sort:ct(s),q:a});return i?e.json(c):e.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().optional()})},security:[{Bearer:["read:resource_servers","auth:read"]}],responses:{200:{content:{"application/json":{schema:vr}},description:"A resource server"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),r=await e.env.data.resourceServers.get(t,n);if(!r)throw new C(404);return e.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().optional()})},security:[{Bearer:["delete:resource_servers","auth:write"]}],responses:{200:{description:"Status"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),r=await e.env.data.resourceServers.get(t,n);if(!r)throw new C(404,{message:"Resource server not found"});if(r.is_system)throw new C(403,{message:"System entities cannot be deleted"});return await e.env.data.resourceServers.remove(t,n),e.text("OK")}).openapi(o.createRoute({tags:["resource-servers"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Ga.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["update:resource_servers","auth:write"]}],responses:{200:{content:{"application/json":{schema:vr}},description:"The updated resource server"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),r=e.req.valid("json"),i=await e.env.data.resourceServers.get(t,n);if(!i)throw new C(404,{message:"Resource server not found"});if(i.is_system)throw new C(403,{message:"System entities cannot be modified"});await e.env.data.resourceServers.update(t,n,r);const s=await e.env.data.resourceServers.get(t,n);if(!s)throw new C(404,{message:"Resource server not found"});return e.json(s)}).openapi(o.createRoute({tags:["resource-servers"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Ga.shape)}}},headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["create:resource_servers","auth:write"]}],responses:{201:{content:{"application/json":{schema:vr}},description:"A resource server"}}}),async e=>{const t=e.var.tenant_id,n=e.req.valid("json"),r=await e.env.data.resourceServers.create(t,n);return e.json(r,{status:201})}),e9=o.z.object({per_page:o.z.string().min(1).optional().default("50").transform(e=>parseInt(e,10)).openapi({description:"Number of results per page. Defaults to 50."}),page:o.z.string().min(0).optional().default("0").transform(e=>parseInt(e,10)).openapi({description:"Page index of the results to return. First page is 0."}),include_totals:o.z.string().optional().default("false").transform(e=>e==="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(e=>e?parseInt(e,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(e=>e==="true"?!0:e==="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."})}),t9=wt.extend({client_grants:o.z.array(wr)}),n9=new o.OpenAPIHono().openapi(o.createRoute({tags:["client-grants"],method:"get",path:"/",request:{query:e9,headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:client_grants","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(wr),t9])}},description:"List of client grants"}}}),async e=>{const t=e.var.tenant_id,{page:n,per_page:r,include_totals:i=!1,from:s,take:a,audience:c,client_id:u,allow_any_organization:l,subject_type:d}=e.req.valid("query"),f=[];u&&f.push(`client_id:"${u}"`),c&&f.push(`audience:"${c}"`),l!==void 0&&f.push(`allow_any_organization:${l}`),d&&f.push(`subject_type:"${d}"`),s&&f.push(`id:>${s}`);const p=f.length>0?f.join(" AND "):void 0,h=a??r,g=await e.env.data.clientGrants.list(t,{page:n,per_page:h,include_totals:i,q:p});return i?e.json(g):e.json(g.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().optional()})},security:[{Bearer:["read:client_grants","auth:read"]}],responses:{200:{content:{"application/json":{schema:wr}},description:"A client grant"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),r=await e.env.data.clientGrants.get(t,n);if(!r)throw new C(404,{message:"Client grant not found"});return e.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().optional()})},security:[{Bearer:["delete:client_grants","auth:write"]}],responses:{200:{description:"Status"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param");if(!await e.env.data.clientGrants.remove(t,n))throw new C(404,{message:"Client grant not found"});return e.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(qa.shape).partial()}}},headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["update:client_grants","auth:write"]}],responses:{200:{content:{"application/json":{schema:wr}},description:"The updated client grant"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),r=e.req.valid("json");if(!await e.env.data.clientGrants.get(t,n))throw new C(404,{message:"Client grant not found"});if(!await e.env.data.clientGrants.update(t,n,r))throw new C(500,{message:"Failed to update client grant"});const a=await e.env.data.clientGrants.get(t,n);if(!a)throw new C(404,{message:"Client grant not found"});return e.json(a)}).openapi(o.createRoute({tags:["client-grants"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(qa.shape)}}},headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["create:client_grants","auth:write"]}],responses:{201:{content:{"application/json":{schema:wr}},description:"A client grant"}}}),async e=>{const t=e.var.tenant_id,n=e.req.valid("json"),r=await e.env.data.clientGrants.create(t,n);return e.json(r,{status:201})}),r9=o.z.object({page:o.z.string().optional().default("0").transform(e=>parseInt(e,10)).openapi({description:"Page index of the results to return. First page is 0."}),per_page:o.z.string().optional().default("50").transform(e=>parseInt(e,10)).openapi({description:"Number of results per page. Defaults to 50."}),include_totals:o.z.string().optional().default("false").transform(e=>e==="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(e=>e==="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."})}),i9=o.z.object({invitations:o.z.array(Mo),start:o.z.number(),limit:o.z.number(),length:o.z.number()}),o9=Sf.omit({organization_id:!0,invitation_url:!0}),s9=wt.extend({organizations:o.z.array(Kn)}),j0=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"})}),a9=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(j0).openapi({description:"Array of organization members"})}),c9=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(j0).openapi({description:"Array of organization members"})}),u9=o.z.object({members:o.z.array(o.z.string()).openapi({description:"Array of user IDs to add to the organization"})}),l9=o.z.object({members:o.z.array(o.z.string()).openapi({description:"Array of user IDs to remove from the organization"})}),d9=new o.OpenAPIHono().openapi(o.createRoute({tags:["organizations"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:organizations","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([s9,o.z.array(Kn)])}},description:"List of organizations"}}}),async e=>{const t=e.var.tenant_id,{page:n,per_page:r,include_totals:i,sort:s,q:a,from:c,take:u}=e.req.valid("query"),l=await e.env.data.organizations.list(t,{page:n,per_page:r,include_totals:i,sort:ct(s),q:a,from:c,take:u});return i?e.json(l):e.json(l.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().optional()})},security:[{Bearer:["read:organizations","auth:read"]}],responses:{200:{content:{"application/json":{schema:Kn}},description:"An organization"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),r=await e.env.data.organizations.get(t,n);if(!r)throw new C(404,{message:"Organization not found"});return e.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().optional()})},security:[{Bearer:["delete:organizations","auth:write"]}],responses:{200:{description:"Organization deleted successfully"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param");if(!await e.env.data.organizations.remove(t,n))throw new C(404,{message:"Organization not found"});return e.text("OK")}).openapi(o.createRoute({tags:["organizations"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:Xa.partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["update:organizations","auth:write"]}],responses:{200:{content:{"application/json":{schema:Kn}},description:"The updated organization"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),r=e.req.valid("json");if(!await e.env.data.organizations.update(t,n,r))throw new C(404,{message:"Organization not found"});const s=await e.env.data.organizations.get(t,n);if(!s)throw new C(404,{message:"Organization not found"});return e.json(s)}).openapi(o.createRoute({tags:["organizations"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:Xa}}},headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["create:organizations","auth:write"]}],responses:{201:{content:{"application/json":{schema:Kn}},description:"The created organization"}}}),async e=>{const t=e.var.tenant_id,n=e.req.valid("json"),r={...n,id:n.id||tk()},i=await e.env.data.organizations.create(t,r);return e.json(i,{status:201})}).openapi(o.createRoute({tags:["organizations"],method:"get",path:"/{id}/members",request:{params:o.z.object({id:o.z.string()}),query:Qe,headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:organizations","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(j0),a9,c9])}},description:"List of organization members"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),{page:r,per_page:i,include_totals:s,sort:a}=e.req.valid("query");if(!await e.env.data.organizations.get(t,n))throw new C(404,{message:"Organization not found"});const u=await e.env.data.userOrganizations.list(t,{page:r,per_page:i,include_totals:s,sort:ct(a),q:`organization_id:${n}`}),l=[];for(const d of u.userOrganizations){const f=await e.env.data.users.get(t,d.user_id);f&&l.push({user_id:f.user_id,email:f.email||void 0,roles:[]})}return s?e.json({start:u.start,limit:u.limit,total:u.length,members:l}):e.json(l)}).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().optional()}),body:{content:{"application/json":{schema:u9}}}},security:[{Bearer:["update:organizations","auth:write"]}],responses:{204:{description:"Members added successfully"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),{members:r}=e.req.valid("json");if(!await e.env.data.organizations.get(t,n))throw new C(404,{message:"Organization not found"});for(const s of r)(await e.env.data.userOrganizations.list(t,{q:`user_id:${s}`,per_page:1})).userOrganizations.some(u=>u.organization_id===n)||await e.env.data.userOrganizations.create(t,{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().optional()}),body:{content:{"application/json":{schema:l9}}}},security:[{Bearer:["update:organizations","auth:write"]}],responses:{200:{description:"Members removed successfully"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),{members:r}=e.req.valid("json");for(const i of r){const a=(await e.env.data.userOrganizations.list(t,{q:`user_id:${i}`,per_page:100})).userOrganizations.find(c=>c.organization_id===n);a&&await e.env.data.userOrganizations.remove(t,a.id)}return e.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().optional()}),query:Qe},security:[{Bearer:["read:organizations","auth:read"]}],responses:{200:{content:{"application/json":{schema:Ja}},description:"User roles in organization"}}}),async e=>{const t=e.var.tenant_id,{id:n,user_id:r}=e.req.valid("param");if(!await e.env.data.organizations.get(t,n))throw new C(404,{message:"Organization not found"});if(!await e.env.data.users.get(t,r))throw new C(404,{message:"User not found"});const a=await e.env.data.userRoles.list(t,r,void 0,n);return e.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().optional()}),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:["update:organizations","auth:write"]}],responses:{201:{description:"Roles assigned successfully"}}}),async e=>{const t=e.var.tenant_id,{id:n,user_id:r}=e.req.valid("param"),{roles:i}=e.req.valid("json");if(!await e.env.data.organizations.get(t,n))throw new C(404,{message:"Organization not found"});if(!await e.env.data.users.get(t,r))throw new C(404,{message:"User not found"});for(const c of i){if(!await e.env.data.roles.get(t,c))throw new C(400,{message:`Role ${c} not found`});if(!await e.env.data.userRoles.create(t,r,c,n))throw new C(500,{message:`Failed to assign role ${c} to user`})}return e.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().optional()}),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:["update:organizations","auth:write"]}],responses:{200:{description:"Roles removed successfully"}}}),async e=>{const t=e.var.tenant_id,{id:n,user_id:r}=e.req.valid("param"),{roles:i}=e.req.valid("json");if(!await e.env.data.organizations.get(t,n))throw new C(404,{message:"Organization not found"});if(!await e.env.data.users.get(t,r))throw new C(404,{message:"User not found"});for(const c of i)if(!await e.env.data.userRoles.remove(t,r,c,n))throw new C(500,{message:`Failed to remove role ${c} from user`});return e.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().optional()}),query:Qe},security:[{Bearer:["read:organizations","auth:read"]}],responses:{200:{content:{"application/json":{schema:Ja}},description:"List of roles available in organization"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),{page:r,per_page:i,sort:s,q:a}=e.req.valid("query");if(!await e.env.data.organizations.get(t,n))throw new C(404,{message:"Organization not found"});const u=await e.env.data.roles.list(t,{page:r,per_page:i,sort:ct(s),q:a});return e.json(u.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:r9,headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:organizations","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(Mo),i9])}},description:"List of organization invitations"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),{page:r,per_page:i,include_totals:s,fields:a,include_fields:c,sort:u}=e.req.valid("query");if(!await e.env.data.organizations.get(t,n))throw new C(404,{message:"Organization not found"});let f=(await e.env.data.invites.list(t,{page:r,per_page:i})).invites.filter(p=>p.organization_id===n);if(u){const p=ct(u);if(p){const{sort_by:h,sort_order:g}=p;f.sort((y,w)=>{const m=y[h],x=w[h];if(m===void 0||x===void 0||m===x)return 0;const $=m<x?-1:1;return g==="asc"?$:-$})}}if(a){const p=a.split(",").map(h=>h.trim());f=f.map(h=>{const g={};for(const y of Object.keys(h))(c?p.includes(y):!p.includes(y))&&(g[y]=h[y]);return g})}return s?e.json({invitations:f,start:r*i,limit:i,length:f.length}):e.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().optional()})},security:[{Bearer:["read:organizations","auth:read"]}],responses:{200:{content:{"application/json":{schema:Mo}},description:"An invitation"},404:{description:"Invitation not found"}}}),async e=>{const t=e.var.tenant_id,{id:n,invitation_id:r}=e.req.valid("param"),i=await e.env.data.invites.get(t,r);if(!i||i.organization_id!==n)throw new C(404,{message:"Invitation not found"});return e.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:o9}}},headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["update:organizations","auth:write"]}],responses:{201:{content:{"application/json":{schema:Mo}},description:"The created invitation"}}}),async e=>{const t=e.var.tenant_id,{id:n}=e.req.valid("param"),r=e.req.valid("json");if(!await e.env.data.organizations.get(t,n))throw new C(404,{message:"Organization not found"});const a=`https://invite.placeholder/${ik()}`,c={...r,organization_id:n,invitation_url:a},u=await e.env.data.invites.create(t,c);return e.json(u,{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().optional()})},security:[{Bearer:["update:organizations","auth:write"]}],responses:{204:{description:"Invitation deleted successfully"},404:{description:"Invitation not found"}}}),async e=>{const t=e.var.tenant_id,{id:n,invitation_id:r}=e.req.valid("param"),i=await e.env.data.invites.get(t,r);if(!i||i.organization_id!==n)throw new C(404,{message:"Invitation not found"});if(!await e.env.data.invites.remove(t,r))throw new C(404,{message:"Invitation not found"});return e.body(null,{status:204})}),p9=new o.OpenAPIHono().openapi(o.createRoute({tags:["stats"],method:"get",path:"/daily",request:{query:o.z.object({from:o.z.string().optional().openapi({description:"Optional first day of the date range (inclusive) in YYYYMMDD format",example:"20251120"}),to:o.z.string().optional().openapi({description:"Optional last day of the date range (inclusive) in YYYYMMDD format",example:"20251219"})}),headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:stats","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.array(Yy)}},description:"Daily statistics including logins, signups, and leaked passwords"}}}),async e=>{const{from:t,to:n}=e.req.valid("query");if(!e.env.data.stats)throw new C(501,{message:"Stats adapter not configured"});const r=await e.env.data.stats.getDaily(e.var.tenant_id,{from:t,to:n});return e.json(r)}).openapi(o.createRoute({tags:["stats"],method:"get",path:"/active-users",request:{headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["read:stats","auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.number().openapi({description:"Number of active users in the last 30 days",example:1234})}},description:"Number of active users in the last 30 days"}}}),async e=>{if(!e.env.data.stats)throw new C(501,{message:"Stats adapter not configured"});const t=await e.env.data.stats.getActiveUsers(e.var.tenant_id);return e.json(t)});function f9(e){const t=new o.OpenAPIHono;t.use(U_({origin:r=>r&&e.allowedOrigins?.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})),N0(t),t.use(async(r,i)=>{const s=Vi(r,e.dataAdapter),a=co({defaultTtlSeconds:0,maxEntries:100,cleanupIntervalMs:0}),c=Js(s,{defaultTtl:0,cacheEntities:["tenants","connections","clients","legacyClients","branding","themes","promptSettings","forms"],cache:a});return r.env.data=Ws(r,c),r.env.entityHooks=e.entityHooks,i()}),t.use(ao).use(so).use(Wu(t)).use(async(r,i)=>(e.entityHooks&&r.var.tenant_id&&(r.env.data=Uw(r.env.data,{tenantId:r.var.tenant_id,entityHooks:e.entityHooks})),i()));const n=t.route("/branding",D4).route("/custom-domains",Dk).route("/email/providers",Pk).route("/users",H8).route("/keys",V$).route("/users-by-email",K$).route("/clients",J$).route("/client-grants",n9).route("/tenants",X$).route("/logs",Y$).route("/hooks",sk).route("/connections",lk).route("/prompts",dk).route("/sessions",Rk).route("/refresh_tokens",Lk).route("/forms",Gk).route("/flows",Jk).route("/roles",Zk).route("/resource-servers",Qk).route("/organizations",d9).route("/stats",p9);if(e.managementApiExtensions)for(const r of e.managementApiExtensions)n.route(r.path,r.router);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 h9(e,t){Object.keys(t).forEach(n=>{const r=t[n];r!=null&&r.length&&e.searchParams.set(n,r)})}function Rn(e){if(e)return`${e.name}/${e.version}${e.env?.node?` (env: node/${e.env.node})`:""}`}async function uo(e,t){const n=await e.data.legacyClients.get(t);if(!n)throw new Z(403,{message:"Client not found"});let r=n;if(e.DEFAULT_CLIENT_ID||e.DEFAULT_TENANT_ID){const i=e.DEFAULT_CLIENT_ID?await e.data.legacyClients.get(e.DEFAULT_CLIENT_ID):void 0,s=await e.data.connections.list(n.tenant.id),a=e.DEFAULT_TENANT_ID?await e.data.connections.list(e.DEFAULT_TENANT_ID):{connections:[]},c=s.connections.map(u=>{const l=a.connections?.find(f=>f.name===u.name);if(!l?.options)return u;const d=Nt.parse({...l||{},...u});return d.options=wi.parse({...l.options||{},...u.options}),d}).filter(u=>u);r={...n,web_origins:[...i?.web_origins||[],...n.web_origins||[]],allowed_logout_urls:[...i?.allowed_logout_urls||[],...n.allowed_logout_urls||[]],callbacks:[...i?.callbacks||[],...n.callbacks||[]],connections:c,tenant:{...i?.tenant||{},...n.tenant}}}return{...r,web_origins:[...r.web_origins||[],`${nt(e)}login`],allowed_logout_urls:[...r.allowed_logout_urls||[],e.ISSUER],callbacks:[...r.callbacks||[],`${nt(e)}info`]}}function Pt(e,t){const n=e.var.tenant_id;if(!n){e.set("tenant_id",t);return}if(n!==t)throw new C(403,{message:"Tenant mismatch"})}async function Im(e,t,n,r){if(!r.state)throw new Z(400,{message:"State not found"});const i=t.connections.find(u=>u.name===n);if(!i)throw e.set("client_id",t.client_id),await _e(e,t.tenant.id,{type:he.FAILED_LOGIN,description:"Connection not found"}),new Z(403,{message:"Connection Not Found"});let s=await e.env.data.loginSessions.get(t.tenant.id,r.state);if(!s){const u=e.get("ip"),l=e.get("useragent"),d=e.get("auth0_client");s=await e.env.data.loginSessions.create(t.tenant.id,{expires_at:new Date(Date.now()+Cr*1e3).toISOString(),authParams:r,csrf_token:Ne(),ip:u,useragent:l,auth0Client:Rn(d)})}const c=await Fb(e,i.strategy).getRedirect(e,i);return await e.env.data.codes.create(t.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()+y6*1e3).toISOString()}),new Response(null,{status:302,headers:{location:c.redirectUrl}})}async function Nm(e,{code:t,state:n}){const{env:r}=e,i=await r.data.codes.get(e.var.tenant_id||"",n,"oauth2_state");if(!i||!i.connection_id)throw new Z(403,{message:"State not found"});const s=await r.data.loginSessions.get(e.var.tenant_id||"",i.login_id);if(!s)throw new Z(403,{message:"Session not found"});if(s.authorization_url){const g=new URL(s.authorization_url).hostname,y=e.var.host||"";if(g!==y&&g){const w=new URL(`https://${g}/callback`);return w.searchParams.set("state",n),w.searchParams.set("code",t),new Response("Redirecting",{status:307,headers:{location:w.toString()}})}}const a=await uo(r,s.authParams.client_id);e.set("client_id",a.client_id),Pt(e,a.tenant.id);const c=a.connections.find(g=>g.id===i.connection_id);if(!c)throw await _e(e,a.tenant.id,{type:he.FAILED_LOGIN,description:"Connection not found"}),new Z(403,{message:"Connection not found"});if(e.set("connection",c.name),!s.authParams.redirect_uri)throw await _e(e,a.tenant.id,{type:he.FAILED_LOGIN,description:"Redirect URI not defined"}),new Z(403,{message:"Redirect URI not defined"});const l=await Fb(e,c.strategy).validateAuthorizationCodeAndGetUser(e,c,t,i.code_verifier),{sub:d,...f}=l;e.set("user_id",d);const p=l.email?.toLocaleLowerCase()||`${c.name}.${d}@${new URL(e.env.ISSUER).hostname}`;e.set("username",p);const h=await eu(e,{client:a,username:p,provider:c.strategy,connection:c.name,userId:d,profileData:f,isSocial:!0,ip:e.var.ip});return rn(e,{client:a,authParams:s.authParams,loginSession:s,user:h,authStrategy:{strategy:c.strategy,strategy_type:"social"}})}async function da(e,t,n,r,i,s){const a=await e.env.data.codes.get(e.var.tenant_id||"",t,"oauth2_state");if(!a)throw new C(400,{message:"State not found"});const c=await e.env.data.loginSessions.get(e.var.tenant_id,a.login_id);if(!c)throw new C(400,{message:"Login not found"});const{redirect_uri:u}=c.authParams;if(!u)throw new C(400,{message:"Redirect uri not found"});_e(e,e.var.tenant_id,{type:he.FAILED_LOGIN,description:`Failed connection login: ${i} ${n}, ${r}`});const l=new URL(u);return h9(l,{error:n,error_description:r,error_reason:s,error_code:i,state:c.authParams.state}),e.redirect(`${nt(e.env)}login/identifier?state=${c.id}&error=${n}`)}const g9=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 e=>{const{state:t,code:n,error:r,error_description:i,error_code:s,error_reason:a}=e.req.valid("query");if(r)return da(e,t,r,i,s,a);if(!n)throw new C(400,{message:"Code is required"});try{const c=await Nm(e,{code:n,state:t});if(!(c instanceof Response))throw new C(500,{message:"Internal server error"});return c}catch(c){if(c instanceof Z&&c.status===400){const u=await e.env.data.codes.get(e.var.tenant_id||"",t,"oauth2_state");if(u&&await e.env.data.loginSessions.get(e.var.tenant_id,u.login_id)){let d="access_denied";try{d=JSON.parse(c.message).message||d}catch{d=c.message||d}return da(e,t,"access_denied",d)}}throw 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 e=>{const{state:t,code:n,error:r,error_description:i,error_code:s,error_reason:a}=e.req.valid("form");if(r)return da(e,t,r,i,s,a);if(!n)throw new C(400,{message:"Code is required"});try{const c=await Nm(e,{code:n,state:t});if(!(c instanceof Response))throw new C(500,{message:"Internal server error"});return c}catch(c){if(c instanceof Z&&c.status===400){const u=await e.env.data.codes.get(e.var.tenant_id||"",t,"oauth2_state");if(u&&await e.env.data.loginSessions.get(e.var.tenant_id,u.login_id)){let d="access_denied";try{d=JSON.parse(c.message).message||d}catch{d=c.message||d}return da(e,t,"access_denied",d)}}throw c}});function T0(e,t=[],n={}){try{const r=new URL(e);return t.some(i=>{try{return m9(r,new URL(i),n)}catch{return!1}})}catch{return!1}}function m9(e,t,n={}){if(e.protocol!==t.protocol)return!1;if(n.allowPathWildcards&&t.pathname.includes("*")){const r=t.pathname.replace(/\*/g,".*").replace(/\//g,"\\/");if(!new RegExp(`^${r}$`).test(e.pathname))return!1}else if(e.pathname!==t.pathname)return!1;if(n.allowSubDomainWildcards&&t.hostname.startsWith("*.")&&t.hostname.split(".").length>2&&["http:","https:"].includes(t.protocol)){const r=t.hostname.split(".").slice(1).join(".");return e.hostname===r||e.hostname.endsWith("."+r)}return e.hostname===t.hostname}const _9=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 e=>{const{client_id:t,returnTo:n}=e.req.valid("query"),r=await e.env.data.legacyClients.get(t);if(!r)return e.text("OK");const i=await e.env.data.legacyClients.get("DEFAULT_CLIENT");e.set("client_id",t),Pt(e,r.tenant.id);const s=n||e.req.header("referer");if(!s)return e.text("OK");if(!T0(s,[...r.allowed_logout_urls||[],...i?.allowed_logout_urls||[]],{allowPathWildcards:!0,allowSubDomainWildcards:!0}))throw new C(400,{message:"Invalid redirect uri"});const a=e.req.header("cookie");if(a){const c=Ei(r.tenant.id,a);if(c){const u=await e.env.data.sessions.get(r.tenant.id,c);if(u){const l=await e.env.data.users.get(r.tenant.id,u.user_id);l&&(e.set("user_id",l.user_id),e.set("connection",l.connection));const d=await e.env.data.refreshTokens.list(r.tenant.id,{q:`session_id=${c}`,page:0,per_page:100,include_totals:!1});await Promise.all(d.refresh_tokens.map(f=>e.env.data.refreshTokens.remove(r.tenant.id,f.id))),await e.env.data.sessions.update(r.tenant.id,c,{revoked_at:new Date().toISOString()})}}}return _e(e,r.tenant.id,{type:he.SUCCESS_LOGOUT,description:"User successfully logged out"}),new Response("Redirecting",{status:302,headers:{"set-cookie":gb(r.tenant.id,e.req.header("host")),location:s}})}),jm=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()}),y9=new o.OpenAPIHono().openapi(o.createRoute({tags:["oauth2"],method:"get",path:"/",request:{},security:[{Bearer:["openid"]}],responses:{200:{content:{"application/json":{schema:jm}},description:"Userinfo"}}}),async e=>{if(!e.var.user)throw new C(404,{message:"User not found"});const t=e.var.user.tenant_id||e.var.tenant_id;if(!t)throw new C(400,{message:"Unable to determine tenant"});const n=await e.env.data.users.get(t,e.var.user.sub);if(!n)throw new C(404,{message:"User not found"});const r=jm.parse({...n,sub:n.user_id}),i=e.env.hooks?.onFetchUserInfo;if(i){const s={},c=e.var.user?.scope?.split(" ")||[];return await i({ctx:e,user:n,tenant_id:t,scopes:c},{setCustomClaim:(u,l)=>{s[u]=l}}),e.json({...r,...s})}return e.json(r)}),b9=new o.OpenAPIHono().openapi(o.createRoute({tags:["well known"],method:"get",path:"/jwks.json",request:{},responses:{200:{content:{"application/json":{schema:$y}},description:"List of tenants"}}}),async e=>{const t=await ef(e.env.data);return e.json({keys:t},{headers:{"access-control-allow-origin":"*","access-control-allow-method":"GET","cache-control":`public, max-age=${ia}, stale-while-revalidate=${ia*2}, stale-if-error=86400`}})}).openapi(o.createRoute({tags:["well known"],method:"get",path:"/openid-configuration",request:{},responses:{200:{content:{"application/json":{schema:zd}},description:"List of tenants"}}}),async e=>{const t=zd.parse({issuer:nu(e.env),authorization_endpoint:`${Te(e.env)}authorize`,token_endpoint:`${Te(e.env)}oauth/token`,device_authorization_endpoint:`${Te(e.env)}oauth/device/code`,userinfo_endpoint:`${Te(e.env)}userinfo`,mfa_challenge_endpoint:`${Te(e.env)}mfa/challenge`,jwks_uri:`${Te(e.env)}.well-known/jwks.json`,registration_endpoint:`${Te(e.env)}oidc/register`,revocation_endpoint:`${Te(e.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 e.json(t,{headers:{"access-control-allow-origin":"*","access-control-allow-method":"GET","cache-control":`public, max-age=${ia}, stale-while-revalidate=${ia*2}, stale-if-error=86400`}})});function Xo(e,t){if(!e||!t||e.length!==t.length)return!1;let n=0;for(let r=0;r<e.length;r++)n|=e.charCodeAt(r)^t.charCodeAt(r);return n===0}const Mw=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(),organization:o.z.string().optional()});async function w9(e,t){const n=await e.env.data.legacyClients.get(t.client_id);if(!n)throw new Z(403,{message:"Invalid client credentials"});if(n.client_secret&&!Xo(n.client_secret,t.client_secret))throw new Z(403,{message:"Invalid client credentials"});let r;if(t.organization){const s=await e.env.data.organizations.get(n.tenant.id,t.organization);if(!s)throw new Z(400,{error:"invalid_request",error_description:`Organization '${t.organization}' not found`});r={id:s.id,name:s.name}}const i={client_id:n.client_id,scope:t.scope,audience:t.audience||n.tenant.default_audience,organization:t.organization};return{client:n,authParams:i,organization:r}}const v9=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(e=>"client_secret"in e&&!("code_verifier"in e)||!("client_secret"in e)&&"code_verifier"in e,{message:"Must provide either client_secret (standard flow) or code_verifier/code_verifier_mode (PKCE flow), but not both"});async function x9(e,t){const n=await e.env.data.legacyClients.get(t.client_id);if(!n)throw new Z(403,{message:"Client not found"});const r=await e.env.data.codes.get(n.tenant.id,t.code,"authorization_code");if(!r||!r.user_id)throw _e(e,n.tenant.id,{type:he.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN,description:"Invalid client credentials"}),new Z(403,{message:"Invalid client credentials"});if(new Date(r.expires_at)<new Date)throw _e(e,n.tenant.id,{type:he.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN,description:"Code expired",userId:r.user_id}),new Z(403,{message:"Code expired"});if(r.used_at)throw _e(e,n.tenant.id,{type:he.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN,description:"Invalid authorization code",userId:r.user_id}),new Z(403,{error:"invalid_grant",error_description:"Invalid authorization code"});const i=await e.env.data.loginSessions.get(n.tenant.id,r.login_id);if(!i)throw new Z(403,{message:"Invalid login"});if(t.organization&&i.authParams.organization&&t.organization!==i.authParams.organization)throw new Z(400,{error:"invalid_request",error_description:"Organization parameter does not match login session organization"});if("client_secret"in t){const u=await e.env.data.legacyClients.get("DEFAULT_CLIENT");if(!Xo(n.client_secret,t.client_secret)&&!Xo(u?.client_secret,t.client_secret))throw _e(e,n.tenant.id,{type:he.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN,description:"Invalid client credentials",userId:r.user_id}),new Z(403,{message:"Invalid client credentials"})}else if(r.code_challenge&&r.code_challenge_method&&t.code_verifier){const u=await g6(t.code_verifier,r.code_challenge_method);if(!Xo(u,r.code_challenge))throw _e(e,n.tenant.id,{type:he.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN,description:"Invalid client credentials",userId:r.user_id}),new Z(403,{message:"Invalid client credentials"})}if(r.redirect_uri&&r.redirect_uri!==t.redirect_uri)throw _e(e,n.tenant.id,{type:he.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN,description:"Invalid redirect uri",userId:r.user_id}),new Z(403,{message:"Invalid redirect uri"});const s=await e.env.data.users.get(n.tenant.id,r.user_id);if(!s)throw new Z(403,{message:"User not found"});await e.env.data.codes.used(n.tenant.id,t.code);let a;i.session_id&&i.authParams.scope?.split(" ").includes("offline_access")&&(a=await xb(e,{user:s,client:n,session_id:i.session_id,scope:i.authParams.scope,audience:i.authParams.audience}));let c;if(i.authParams.organization){const u=await e.env.data.organizations.get(n.tenant.id,i.authParams.organization);u?c={id:u.id,name:u.name}:c={id:i.authParams.organization,name:"Unknown"}}return{user:s,client:n,loginSession:i,session_id:i.session_id,refresh_token:a?.id,organization:c,authParams:{...i.authParams,state:r.state,nonce:r.nonce,response_mode:hn.WEB_MESSAGE,client_id:n.client_id,scope:i.authParams.scope,audience:i.authParams.audience}}}function Tm(e,t){const n=e.var.log;n?e.set("log",`${n}
82
82
  ${t}`):e.set("log",t)}const $9=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(),client_secret:o.z.string().optional()});async function k9(e,t){const n=await e.env.data.legacyClients.get(t.client_id);if(!n)throw new Z(403,{message:"Client not found"});if(t.client_secret&&n.client_secret&&!Xo(n.client_secret,t.client_secret))throw new Z(403,{error:"invalid_client",error_description:"Client authentication failed"});const r=await e.env.data.refreshTokens.get(n.tenant.id,t.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 Tm(e,`Refresh token has expired: ${t.refresh_token}`),new Z(400,{error:"invalid_grant",error_description:"Refresh token has expired"})}else throw Tm(e,`Invalid refresh token: ${t.refresh_token}`),new Z(400,{error:"invalid_grant",error_description:"Invalid refresh token"});const i=await e.env.data.users.get(n.tenant.id,r.user_id);if(!i)throw new Z(403,{message:"User not found"});e.set("user_id",i.user_id);const s=r.resource_servers[0];if(r.idle_expires_at){const a=new Date(Date.now()+2592e6);await e.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:e.req.header["x-real-ip"]||"",last_user_agent:e.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?.audience,scope:s?.scopes,response_mode:hn.WEB_MESSAGE}}}const S9={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,[["(?:(?:241|349)0\\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])|[34]\\d\\d)|91(?:(?:[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}|(?:2(?:[0-26-9]\\d|3[0-8]|4[02-9]|5[0135-9])|3(?:[0-3589]\\d|4[0-578]|6[1-9]|7[0-35-9])|7(?:[013-57-9]\\d|2[0-8])|8(?:55|6[0-8]|[78]\\d|9[02-9]))\\d{6}",[9]],["4(?:79[01]|83[0-36-9]|95[0-3])\\d{5}|4(?:[0-36]\\d|4[047-9]|[58][0-24-9]|7[02-8]|9[0-47-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|44)\\d{6}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[024-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|8)\\d{7}",[8,10],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["8"]],["(\\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","[178]\\d{7}|[2-8]\\d{6}",[7,8],[["(\\d)(\\d{3})(\\d{3})","$1 $2 $3",["[2-6]|7[246]|8[2-4]"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["1[67]|[78]"]]]],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|5[07]|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-36-9]|95[0-3])\\d{5}|4(?:[0-36]\\d|4[047-9]|[58][0-24-9]|7[02-8]|9[0-47-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{3})(\\d{3})(\\d{3})","$1 $2 $3",["60|809"]],["(\\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(?:10|[2-9])"]],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["3[2-5]|[47]|5[1-3578]|6[13-57]|8(?:0[1-8]|[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]|9[14]"]],["(\\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-36-9]|95[0-3])\\d{5}|4(?:[0-36]\\d|4[047-9]|[58][0-24-9]|7[02-8]|9[0-47-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]|3[13])"],"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|180020",0,0,0,[["(?:1(?:1(?:3(?:[0-58]\\d\\d|73[0-5])|4(?:(?:[0-5]\\d|70)\\d|69[7-9])|(?:(?:5[0-26-9]|[78][0-49])\\d|6(?:[0-4]\\d|5[01]))\\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|180020","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-589]\\d{7}",[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|180020","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|8(?:28[235-7]|3))|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])\\d|8(?:[14-6]\\d|2[0-79]))|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",["16|[6-9]"],"0$1",1],["(\\d{4})(\\d{2,4})(\\d{4})","$1 $2 $3",["18[06]","18[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,11}|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",["[03]"]]],0,0,0,0,0,0,[["0(?:669[0-79]\\d{1,6}|831\\d{2,8})|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[2356]|[6-8][1-5])|9(?:[0159]\\d|[238][1-5]|4[12]|6[1-8]|7[1-6]))\\d{2,7}"],["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|180020","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|427|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",["[47]"],"0$1"]],"0"],JP:["81","010","00[1-9]\\d{6,14}|[25-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",["3|4(?:2[09]|7[01])|6[1-9]","3|4(?:2(?:0|9[02-69])|7(?:0[019]|1))|6[1-9]"],"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",["[25-9]"],"0$1"]],"0",0,"(000[2569]\\d{4,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,"33622|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-6]|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","(?:[2457]\\d|33|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|78|90)\\d{6}",[8],[["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["[2679]|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(?:[19]|2[2-46-9]|3[3-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(?:(?:18|4[0679]|5[03])\\d|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]))\\d{5}"],["(?:6(?:[0-79]\\d|8[0-247-9])|7(?:[016-8]\\d|2[0-8]|5[0-5]))\\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]|[67]\\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",["[67]"],"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,0,[["336(?:[013-9]\\d|2[013-9])\\d{5}|(?:3(?:0[12]|4[1-35-79]|5[1-3]|65|8[1-58]|9[0145])|4(?:01|1[1356]|2[13467]|7[1-5]|8[1-7]|9[1-689])|8(?:1[1-8]|2[01]|3[13-6]|4[0-8]|5[15-7]|6[0-35-79]|7[1-37-9]))\\d{7}",[10]],["9\\d{9}",[10]],["8(?:0[04]|108\\d{3})\\d{7}"],["80[39]\\d{7}",[10]],["808\\d{7}",[10]]],"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","(?:[15]\\d|800|92)\\d{7}",[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{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]|[6-8]\\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","[25-7]\\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",["[25-7]"]],["(\\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-359]\\d{8}|[1-5]\\d{7}",[8,9],[["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[1-4]|5[1-3]"],"0$1",1],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[59]"],"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|30|[689]\\d|77)\\d{6}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[236-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|66)\\d{7}",[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",["\\d"]]],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)\\d{4}|(?:2742|305[3-9])\\d{6}|(?:472|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[013-79]|3[0-24679]|4[167]|5[0-3]|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-57-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-269])|7(?:0[1-46-8]|1[2-9]|2[04-8]|3[0-247]|4[0378]|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-3589]|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}|2\\d{3,4}|(?:[49]\\d|80)\\d{5}",[4,5,6,7,8,9,10,11,12,13],[["(\\d{4,5})","$1",["21"]],["(\\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 z9(e,t){var n=Array.prototype.slice.call(t);return n.push(S9),e.apply(this,n)}function Om(e,t){e=e.split("-"),t=t.split("-");for(var n=e[0].split("."),r=t[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 e[1]&&t[1]?e[1]>t[1]?1:e[1]<t[1]?-1:0:!e[1]&&t[1]?1:e[1]&&!t[1]?-1:0}var A9={}.constructor;function zi(e){return e!=null&&e.constructor===A9}function qi(e){"@babel/helpers - typeof";return qi=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},qi(e)}function Ju(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function E9(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,C9(r.key),r)}}function Xu(e,t,n){return t&&E9(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function C9(e){var t=I9(e,"string");return qi(t)=="symbol"?t:t+""}function I9(e,t){if(qi(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(qi(r)!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}var N9="1.2.0",j9="1.7.35",Pm=" ext. ",T9=/^\d+$/,pt=(function(){function e(t){Ju(this,e),qw(t),this.metadata=t,Fw.call(this,t)}return Xu(e,[{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&&T9.test(n)&&(r=n,n=null),n&&n!=="001"){if(!this.hasCountry(n))throw new Error("Unknown country: ".concat(n));this.numberingPlan=new Rm(this.getCountryMetadata(n),this)}else if(r){if(!this.hasCallingCode(r))throw new Error("Unknown calling code: ".concat(r));this.numberingPlan=new Rm(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}}])})(),Rm=(function(){function e(t,n){Ju(this,e),this.globalMetadataObject=n,this.metadata=t,Fw.call(this,n.metadata)}return Xu(e,[{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 O9(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()&&Lm(this.types(),n))return new R9(Lm(this.types(),n),this)}},{key:"ext",value:function(){return this.v1||this.v2?Pm:this.metadata[13]||Pm}}])})(),O9=(function(){function e(t,n){Ju(this,e),this._format=t,this.metadata=n}return Xu(e,[{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()&&!P9.test(this.nationalPrefixFormattingRule()))}},{key:"internationalFormat",value:function(){return this._format[5]||this.format()}}])})(),P9=/^\(?\$1\)?$/,R9=(function(){function e(t,n){Ju(this,e),this.type=t,this.metadata=n}return Xu(e,[{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()}}])})();function Lm(e,t){switch(t){case"FIXED_LINE":return e[0];case"MOBILE":return e[1];case"TOLL_FREE":return e[2];case"PREMIUM_RATE":return e[3];case"PERSONAL_NUMBER":return e[4];case"VOICEMAIL":return e[5];case"UAN":return e[6];case"PAGER":return e[7];case"VOIP":return e[8];case"SHARED_COST":return e[9]}}function qw(e){if(!e)throw new Error("[libphonenumber-js] `metadata` argument not passed. Check your arguments.");if(!zi(e)||!zi(e.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(zi(e)?"an object of shape: { "+Object.keys(e).join(", ")+" }":"a "+L9(e)+": "+e,"."))}var L9=function(t){return qi(t)};function O0(e,t){if(t=new pt(t),t.hasCountry(e))return t.selectNumberingPlan(e).countryCallingCode();throw new Error("Unknown country: ".concat(e))}function D9(e,t){return t.countries.hasOwnProperty(e)}function Fw(e){var t=e.version;typeof t=="number"?(this.v1=t===1,this.v2=t===2,this.v3=t===3,this.v4=t===4):t?Om(t,N9)===-1?this.v2=!0:Om(t,j9)===-1?this.v3=!0:this.v4=!0:this.v1=!0}function P0(e,t,n){return B9(e,t,void 0,n)}function B9(e,t,n,r){t&&(r=new pt(r.metadata),r.selectNumberingPlan(t));var i=r.type(n),s=i&&i.possibleLengths()||r.possibleLengths();if(!s)return"IS_POSSIBLE";var a=e.length,c=s[0];return c===a?"IS_POSSIBLE":c>a?"TOO_SHORT":s[s.length-1]<a?"TOO_LONG":s.indexOf(a,1)>=0?"IS_POSSIBLE":"INVALID_LENGTH"}function U9(e,t,n){if(t===void 0&&(t={}),n=new pt(n),t.v2){if(!e.countryCallingCode)throw new Error("Invalid phone number object passed");n.selectNumberingPlan(e.countryCallingCode)}else{if(!e.phone)return!1;if(e.country){if(!n.hasCountry(e.country))throw new Error("Unknown country: ".concat(e.country));n.selectNumberingPlan(e.country)}else{if(!e.countryCallingCode)throw new Error("Invalid phone number object passed");n.selectNumberingPlan(e.countryCallingCode)}}if(n.possibleLengths())return Hw(e.phone||e.nationalNumber,e.country,n);if(e.countryCallingCode&&n.isNonGeographicCallingCode(e.countryCallingCode))return!0;throw new Error('Missing "possibleLengths" in metadata. Perhaps the metadata has been generated before v1.0.18.')}function Hw(e,t,n){return P0(e,t,n)==="IS_POSSIBLE"}function Ln(e,t){return e=e||"",new RegExp("^(?:"+t+")$").test(e)}function M9(e,t){var n=typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=q9(e))||t){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
83
83
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function q9(e,t){if(e){if(typeof e=="string")return Dm(e,t);var n={}.toString.call(e).slice(8,-1);return n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set"?Array.from(e):n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Dm(e,t):void 0}}function Dm(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var F9=["MOBILE","PREMIUM_RATE","TOLL_FREE","SHARED_COST","VOIP","PERSONAL_NUMBER","PAGER","UAN","VOICEMAIL"];function R0(e,t,n){if(t=t||{},!(!e.country&&!e.countryCallingCode)){n=new pt(n),n.selectNumberingPlan(e.country,e.countryCallingCode);var r=t.v2?e.nationalNumber:e.phone;if(Ln(r,n.nationalNumberPattern())){if(Nl(r,"FIXED_LINE",n))return n.type("MOBILE")&&n.type("MOBILE").pattern()===""||!n.type("MOBILE")||Nl(r,"MOBILE",n)?"FIXED_LINE_OR_MOBILE":"FIXED_LINE";for(var i=M9(F9),s;!(s=i()).done;){var a=s.value;if(Nl(r,a,n))return a}}}}function Nl(e,t,n){return t=n.type(t),!t||!t.pattern()||t.possibleLengths()&&t.possibleLengths().indexOf(e.length)<0?!1:Ln(e,t.pattern())}function H9(e,t,n){if(t=t||{},n=new pt(n),n.selectNumberingPlan(e.country,e.countryCallingCode),n.hasTypes())return R0(e,t,n.metadata)!==void 0;var r=t.v2?e.nationalNumber:e.phone;return Ln(r,n.nationalNumberPattern())}function V9(e,t,n){var r=new pt(n),i=r.getCountryCodesForCallingCode(e);return i?i.filter(function(s){return K9(t,s,n)}):[]}function K9(e,t,n){var r=new pt(n);return r.selectNumberingPlan(t),r.numberingPlan.possibleLengths().indexOf(e.length)>=0}var L0=2,G9=17,W9=3,on="0-90-9٠-٩۰-۹",J9="-‐-―−ー-",X9="//",Z9="..",Y9="  ­​⁠ ",Q9="()()[]\\[\\]",eS="~⁓∼~",Mc="".concat(J9).concat(X9).concat(Z9).concat(Y9).concat(Q9).concat(eS),D0="++",tS=new RegExp("(["+on+"])");function nS(e,t,n,r){if(t){var i=new pt(r);i.selectNumberingPlan(t,n);var s=new RegExp(i.IDDPrefix());if(e.search(s)===0){e=e.slice(e.match(s)[0].length);var a=e.match(tS);if(!(a&&a[1]!=null&&a[1].length>0&&a[1]==="0"))return e}}}function rS(e,t){if(e&&t.numberingPlan.nationalPrefixForParsing()){var n=new RegExp("^(?:"+t.numberingPlan.nationalPrefixForParsing()+")"),r=n.exec(e);if(r){var i,s,a=r.length-1,c=a>0&&r[a];if(t.nationalPrefixTransformRule()&&c)i=e.replace(n,t.nationalPrefixTransformRule()),a>1&&(s=r[1]);else{var u=r[0];i=e.slice(u.length),c&&(s=r[1])}var l;if(c){var d=e.indexOf(r[1]),f=e.slice(0,d);f===t.numberingPlan.nationalPrefix()&&(l=t.numberingPlan.nationalPrefix())}else l=r[0];return{nationalNumber:i,nationalPrefix:l,carrierCode:s}}}return{nationalNumber:e}}function iS(e,t){var n=typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=oS(e))||t){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
84
84
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function oS(e,t){if(e){if(typeof e=="string")return Bm(e,t);var n={}.toString.call(e).slice(8,-1);return n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set"?Array.from(e):n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Bm(e,t):void 0}}function Bm(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function sS(e,t){var n=t.countries,r=t.metadata;r=new pt(r);for(var i=iS(n),s;!(s=i()).done;){var a=s.value;if(r.selectNumberingPlan(a),r.leadingDigits()){if(e&&e.search(r.leadingDigits())===0)return a}else if(R0({phone:e,country:a},void 0,r.metadata))return a}}function Vw(e,t){var n=t.nationalNumber,r=t.metadata,i=r.getCountryCodesForCallingCode(e);if(i)return i.length===1?i[0]:sS(n,{countries:i,metadata:r.metadata})}function tf(e,t,n){var r=rS(e,n),i=r.carrierCode,s=r.nationalNumber;if(s!==e){if(!aS(e,s,n))return{nationalNumber:e};if(n.numberingPlan.possibleLengths()&&(t||(t=Vw(n.numberingPlan.callingCode(),{nationalNumber:s,metadata:n})),!cS(s,t,n)))return{nationalNumber:e}}return{nationalNumber:s,carrierCode:i}}function aS(e,t,n){return!(Ln(e,n.nationalNumberPattern())&&!Ln(t,n.nationalNumberPattern()))}function cS(e,t,n){switch(P0(e,t,n)){case"TOO_SHORT":case"INVALID_LENGTH":return!1;default:return!0}}function uS(e,t,n,r,i){var s=n?O0(n,i):r;if(e.indexOf(s)===0){i=new pt(i),i.selectNumberingPlan(n,s);var a=e.slice(s.length),c=tf(a,t,i),u=c.nationalNumber,l=tf(e,t,i),d=l.nationalNumber;if(!Ln(d,i.nationalNumberPattern())&&Ln(u,i.nationalNumberPattern())||P0(d,t,i)==="TOO_LONG")return{countryCallingCode:s,number:a}}return{number:e}}function Kw(e,t,n,r,i){if(!e)return{};var s;if(e[0]!=="+"){var a=nS(e,n,r,i);if(a&&a!==e)s=!0,e="+"+a;else{if(n||r){var c=uS(e,t,n,r,i),u=c.countryCallingCode,l=c.number;if(u)return{countryCallingCodeSource:"FROM_NUMBER_WITHOUT_PLUS_SIGN",countryCallingCode:u,number:l}}return{number:e}}}if(e[1]==="0")return{};i=new pt(i);for(var d=2;d-1<=W9&&d<=e.length;){var f=e.slice(1,d);if(i.hasCallingCode(f))return i.selectNumberingPlan(f),{countryCallingCodeSource:s?"FROM_NUMBER_WITH_IDD":"FROM_NUMBER_WITH_PLUS_SIGN",countryCallingCode:f,number:e.slice(d)};d++}return{}}function lS(e){return e.replace(new RegExp("[".concat(Mc,"]+"),"g")," ").trim()}var dS=/(\$\d)/;function pS(e,t,n){var r=n.useInternationalFormat,i=n.withNationalPrefix,s=e.replace(new RegExp(t.pattern()),r?t.internationalFormat():i&&t.nationalPrefixFormattingRule()?t.format().replace(dS,t.nationalPrefixFormattingRule()):t.format());return r?lS(s):s}var fS=/^[\d]+(?:[~\u2053\u223C\uFF5E][\d]+)?$/;function hS(e,t,n){var r=new pt(n);if(r.selectNumberingPlan(e,t),r.defaultIDDPrefix())return r.defaultIDDPrefix();if(fS.test(r.IDDPrefix()))return r.IDDPrefix()}var gS=";ext=",oi=function(t){return"([".concat(on,"]{1,").concat(t,"})")};function Gw(e){var t="20",n="15",r="9",i="6",s="[  \\t,]*",a="[:\\..]?[  \\t,-]*",c="#?",u="(?:e?xt(?:ensi(?:ó?|ó))?n?|e?xtn?|доб|anexo)",l="(?:[xx##~~]|int|int)",d="[- ]+",f="[  \\t]*",p="(?:,{2}|;)",h=gS+oi(t),g=s+u+a+oi(t)+c,y=s+l+a+oi(r)+c,w=d+oi(i)+"#",m=f+p+a+oi(n)+c,x=f+"(?:,)+"+a+oi(r)+c;return h+"|"+g+"|"+y+"|"+w+"|"+m+"|"+x}var mS="["+on+"]{"+L0+"}",_S="["+D0+"]{0,1}(?:["+Mc+"]*["+on+"]){3,}["+Mc+on+"]*",yS=new RegExp("^["+D0+"]{0,1}(?:["+Mc+"]*["+on+"]){1,2}$","i"),bS=_S+"(?:"+Gw()+")?",wS=new RegExp("^"+mS+"$|^"+bS+"$","i");function vS(e){return e.length>=L0&&wS.test(e)}function xS(e){return yS.test(e)}function $S(e){var t=e.number,n=e.ext;if(!t)return"";if(t[0]!=="+")throw new Error('"formatRFC3966()" expects "number" to be in E.164 format.');return"tel:".concat(t).concat(n?";ext="+n:"")}var Um={formatExtension:function(t,n,r){return"".concat(t).concat(r.ext()).concat(n)}};function kS(e,t,n,r){if(n?n=AS({},Um,n):n=Um,r=new pt(r),e.country&&e.country!=="001"){if(!r.hasCountry(e.country))throw new Error("Unknown country: ".concat(e.country));r.selectNumberingPlan(e.country)}else if(e.countryCallingCode)r.selectNumberingPlan(e.countryCallingCode);else return e.phone||"";var i=r.countryCallingCode(),s=n.v2?e.nationalNumber:e.phone,a;switch(t){case"NATIONAL":return s?(a=qc(s,e.carrierCode,"NATIONAL",r,n),jl(a,e.ext,r,n.formatExtension)):"";case"INTERNATIONAL":return s?(a=qc(s,null,"INTERNATIONAL",r,n),a="+".concat(i," ").concat(a),jl(a,e.ext,r,n.formatExtension)):"+".concat(i);case"E.164":return"+".concat(i).concat(s);case"RFC3966":return $S({number:"+".concat(i).concat(s),ext:e.ext});case"IDD":if(!n.fromCountry)return;var c=zS(s,e.carrierCode,i,n.fromCountry,r);return jl(c,e.ext,r,n.formatExtension);default:throw new Error('Unknown "format" argument passed to "formatNumber()": "'.concat(t,'"'))}}function qc(e,t,n,r,i){var s=SS(r.formats(),e);return s?pS(e,s,{useInternationalFormat:n==="INTERNATIONAL",withNationalPrefix:!(s.nationalPrefixIsOptionalWhenFormattingInNationalFormat()&&i&&i.nationalPrefix===!1)}):e}function SS(e,t){return ES(e,function(n){if(n.leadingDigitsPatterns().length>0){var r=n.leadingDigitsPatterns()[n.leadingDigitsPatterns().length-1];if(t.search(r)!==0)return!1}return Ln(t,n.pattern())})}function jl(e,t,n,r){return t?r(e,t,n):e}function zS(e,t,n,r,i){var s=O0(r,i.metadata);if(s===n){var a=qc(e,t,"NATIONAL",i);return n==="1"?n+" "+a:a}var c=hS(r,void 0,i.metadata);if(c)return"".concat(c," ").concat(n," ").concat(qc(e,null,"INTERNATIONAL",i))}function AS(){for(var e=1,t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];for(;e<n.length;){if(n[e])for(var i in n[e])n[0][i]=n[e][i];e++}return n[0]}function ES(e,t){for(var n=0;n<e.length;){if(t(e[n]))return e[n];n++}}function ms(e){"@babel/helpers - typeof";return ms=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},ms(e)}function Mm(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),n.push.apply(n,r)}return n}function qm(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?Mm(Object(n),!0).forEach(function(r){CS(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Mm(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function CS(e,t,n){return(t=Ww(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function IS(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function NS(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,Ww(r.key),r)}}function jS(e,t,n){return t&&NS(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function Ww(e){var t=TS(e,"string");return ms(t)=="symbol"?t:t+""}function TS(e,t){if(ms(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(ms(r)!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}var OS=(function(){function e(t,n,r){if(IS(this,e),!t)throw new TypeError("First argument is required");if(typeof t!="string")throw new TypeError("First argument must be a string");if(t[0]==="+"&&!n)throw new TypeError("`metadata` argument not passed");if(zi(n)&&zi(n.countries)){r=n;var i=t;if(!LS.test(i))throw new Error('Invalid `number` argument passed: must consist of a "+" followed by digits');var s=Kw(i,void 0,void 0,void 0,r),a=s.countryCallingCode,c=s.number;if(n=c,t=a,!n)throw new Error("Invalid `number` argument passed: too short")}if(!n)throw new TypeError("`nationalNumber` argument is required");if(typeof n!="string")throw new TypeError("`nationalNumber` argument must be a string");qw(r);var u=RS(t,r),l=u.country,d=u.countryCallingCode;this.country=l,this.countryCallingCode=d,this.nationalNumber=n,this.number="+"+this.countryCallingCode+this.nationalNumber,this.getMetadata=function(){return r}}return jS(e,[{key:"setExt",value:function(n){this.ext=n}},{key:"getPossibleCountries",value:function(){return this.country?[this.country]:V9(this.countryCallingCode,this.nationalNumber,this.getMetadata())}},{key:"isPossible",value:function(){return U9(this,{v2:!0},this.getMetadata())}},{key:"isValid",value:function(){return H9(this,{v2:!0},this.getMetadata())}},{key:"isNonGeographic",value:function(){var n=new pt(this.getMetadata());return n.isNonGeographicCallingCode(this.countryCallingCode)}},{key:"isEqual",value:function(n){return this.number===n.number&&this.ext===n.ext}},{key:"getType",value:function(){return R0(this,{v2:!0},this.getMetadata())}},{key:"format",value:function(n,r){return kS(this,n,r?qm(qm({},r),{},{v2:!0}):{v2:!0},this.getMetadata())}},{key:"formatNational",value:function(n){return this.format("NATIONAL",n)}},{key:"formatInternational",value:function(n){return this.format("INTERNATIONAL",n)}},{key:"getURI",value:function(n){return this.format("RFC3966",n)}}])})(),PS=function(t){return/^[A-Z]{2}$/.test(t)};function RS(e,t){var n,r,i=new pt(t);return PS(e)?(n=e,i.selectNumberingPlan(n),r=i.countryCallingCode()):r=e,{country:n,countryCallingCode:r}}var LS=/^\+\d+$/;function nf(e){"@babel/helpers - typeof";return nf=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},nf(e)}function DS(e,t,n){return Object.defineProperty(e,"prototype",{writable:!1}),e}function BS(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function US(e,t,n){return t=ys(t),MS(e,B0()?Reflect.construct(t,n||[],ys(e).constructor):t.apply(e,n))}function MS(e,t){if(t&&(nf(t)=="object"||typeof t=="function"))return t;if(t!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return qS(e)}function qS(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function FS(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&_s(e,t)}function rf(e){var t=typeof Map=="function"?new Map:void 0;return rf=function(r){if(r===null||!VS(r))return r;if(typeof r!="function")throw new TypeError("Super expression must either be null or a function");if(t!==void 0){if(t.has(r))return t.get(r);t.set(r,i)}function i(){return HS(r,arguments,ys(this).constructor)}return i.prototype=Object.create(r.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),_s(i,r)},rf(e)}function HS(e,t,n){if(B0())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,t);var i=new(e.bind.apply(e,r));return n&&_s(i,n.prototype),i}function B0(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(B0=function(){return!!e})()}function VS(e){try{return Function.toString.call(e).indexOf("[native code]")!==-1}catch{return typeof e=="function"}}function _s(e,t){return _s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(n,r){return n.__proto__=r,n},_s(e,t)}function ys(e){return ys=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},ys(e)}var An=(function(e){function t(n){var r;return BS(this,t),r=US(this,t,[n]),Object.setPrototypeOf(r,t.prototype),r.name=r.constructor.name,r}return FS(t,e),DS(t)})(rf(Error)),Fm=new RegExp("(?:"+Gw()+")$","i");function KS(e){var t=e.search(Fm);if(t<0)return{};for(var n=e.slice(0,t),r=e.match(Fm),i=1;i<r.length;){if(r[i])return{number:n,ext:r[i]};i++}}var GS={0:"0",1:"1",2:"2",3:"3",4:"4",5:"5",6:"6",7:"7",8:"8",9:"9","0":"0","1":"1","2":"2","3":"3","4":"4","5":"5","6":"6","7":"7","8":"8","9":"9","٠":"0","١":"1","٢":"2","٣":"3","٤":"4","٥":"5","٦":"6","٧":"7","٨":"8","٩":"9","۰":"0","۱":"1","۲":"2","۳":"3","۴":"4","۵":"5","۶":"6","۷":"7","۸":"8","۹":"9"};function WS(e){return GS[e]}function JS(e,t){var n=typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=XS(e))||t){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.