@authhero/kysely-adapter 0.2.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/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/kysely-adapter.cjs +5 -0
- package/dist/kysely-adapter.iife.js +5 -0
- package/dist/kysely-adapter.mjs +5936 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 authhero
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";var Ut=Object.defineProperty;var Mt=(n,e,t)=>e in n?Ut(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var nt=(n,e,t)=>Mt(n,typeof e!="symbol"?e+"":e,t);var Ae=class extends Error{constructor(e=500,t){super(t==null?void 0:t.message,{cause:t==null?void 0:t.cause});nt(this,"res");nt(this,"status");this.res=t==null?void 0:t.res,this.status=e}getResponse(){return this.res?new Response(this.res.body,{status:this.status,headers:this.res.headers}):new Response(this.message,{status:this.status})}};function Lt(n){return async(e,t)=>{const{identities:a,...r}=t,i={...r,created_at:new Date().toISOString(),updated_at:new Date().toISOString(),tenant_id:e,email_verified:t.email_verified?1:0,is_social:t.is_social?1:0};try{await n.insertInto("users").values(i).execute()}catch(o){throw o.code==="SQLITE_CONSTRAINT_UNIQUE"||o.message.includes("AlreadyExists")?new Ae(409,{message:"User already exists"}):(console.log(o.message),new Ae(500,{message:`${o.code}, ${o.message}`}))}return{...i,email:i.email||"",email_verified:i.email_verified===1,is_social:i.is_social===1}}}function U(n){const e={...n};for(const t in e)e[t]===null?delete e[t]:typeof e[t]=="object"&&(Array.isArray(e[t])?e[t]=e[t].map(U):e[t]=U(e[t]));return e}function qt(n,e){var t={};for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&e.indexOf(a)<0&&(t[a]=n[a]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,a=Object.getOwnPropertySymbols(n);r<a.length;r++)e.indexOf(a[r])<0&&Object.prototype.propertyIsEnumerable.call(n,a[r])&&(t[a[r]]=n[a[r]]);return t}function zt(n,e){var t;return((t=n==null?void 0:n._def)===null||t===void 0?void 0:t.typeName)===e}function je(n,e){const t=n.ZodType.prototype[e];n.ZodType.prototype[e]=function(...a){const r=t.apply(this,a);return r._def.openapi=this._def.openapi,r}}function Bt(n){if(typeof n.ZodType.prototype.openapi<"u")return;n.ZodType.prototype.openapi=function(r,i){var o,c,f,_,y,C;const R=typeof r=="string"?i:r,Y=R??{},{param:M}=Y,B=qt(Y,["param"]),ce=Object.assign(Object.assign({},(o=this._def.openapi)===null||o===void 0?void 0:o._internal),typeof r=="string"?{refId:r}:void 0),de=Object.assign(Object.assign(Object.assign({},(c=this._def.openapi)===null||c===void 0?void 0:c.metadata),B),!((_=(f=this._def.openapi)===null||f===void 0?void 0:f.metadata)===null||_===void 0)&&_.param||M?{param:Object.assign(Object.assign({},(C=(y=this._def.openapi)===null||y===void 0?void 0:y.metadata)===null||C===void 0?void 0:C.param),M)}:void 0),te=new this.constructor(Object.assign(Object.assign({},this._def),{openapi:Object.assign(Object.assign({},Object.keys(ce).length>0?{_internal:ce}:void 0),Object.keys(de).length>0?{metadata:de}:void 0)}));if(zt(this,"ZodObject")){const ue=this.extend;te.extend=function(...le){var z,L,X,ge,me,fe;const x=ue.apply(this,le);return x._def.openapi={_internal:{extendedFrom:!((L=(z=this._def.openapi)===null||z===void 0?void 0:z._internal)===null||L===void 0)&&L.refId?{refId:(ge=(X=this._def.openapi)===null||X===void 0?void 0:X._internal)===null||ge===void 0?void 0:ge.refId,schema:this}:(me=this._def.openapi)===null||me===void 0?void 0:me._internal.extendedFrom},metadata:(fe=x._def.openapi)===null||fe===void 0?void 0:fe.metadata},x}}return te},je(n,"optional"),je(n,"nullable"),je(n,"default"),je(n,"transform"),je(n,"refine");const e=n.ZodObject.prototype.deepPartial;n.ZodObject.prototype.deepPartial=function(){const r=this._def.shape(),i=e.apply(this),o=i._def.shape();return Object.entries(o).forEach(([c,f])=>{var _,y;f._def.openapi=(y=(_=r[c])===null||_===void 0?void 0:_._def)===null||y===void 0?void 0:y.openapi}),i._def.openapi=void 0,i};const t=n.ZodObject.prototype.pick;n.ZodObject.prototype.pick=function(...r){const i=t.apply(this,r);return i._def.openapi=void 0,i};const a=n.ZodObject.prototype.omit;n.ZodObject.prototype.omit=function(...r){const i=a.apply(this,r);return i._def.openapi=void 0,i}}new Set(".\\+*[^]$()");var E;(function(n){n.assertEqual=r=>r;function e(r){}n.assertIs=e;function t(r){throw new Error}n.assertNever=t,n.arrayToEnum=r=>{const i={};for(const o of r)i[o]=o;return i},n.getValidEnumValues=r=>{const i=n.objectKeys(r).filter(c=>typeof r[r[c]]!="number"),o={};for(const c of i)o[c]=r[c];return n.objectValues(o)},n.objectValues=r=>n.objectKeys(r).map(function(i){return r[i]}),n.objectKeys=typeof Object.keys=="function"?r=>Object.keys(r):r=>{const i=[];for(const o in r)Object.prototype.hasOwnProperty.call(r,o)&&i.push(o);return i},n.find=(r,i)=>{for(const o of r)if(i(o))return o},n.isInteger=typeof Number.isInteger=="function"?r=>Number.isInteger(r):r=>typeof r=="number"&&isFinite(r)&&Math.floor(r)===r;function a(r,i=" | "){return r.map(o=>typeof o=="string"?`'${o}'`:o).join(i)}n.joinValues=a,n.jsonStringifyReplacer=(r,i)=>typeof i=="bigint"?i.toString():i})(E||(E={}));var st;(function(n){n.mergeShapes=(e,t)=>({...e,...t})})(st||(st={}));const v=E.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),ae=n=>{switch(typeof n){case"undefined":return v.undefined;case"string":return v.string;case"number":return isNaN(n)?v.nan:v.number;case"boolean":return v.boolean;case"function":return v.function;case"bigint":return v.bigint;case"symbol":return v.symbol;case"object":return Array.isArray(n)?v.array:n===null?v.null:n.then&&typeof n.then=="function"&&n.catch&&typeof n.catch=="function"?v.promise:typeof Map<"u"&&n instanceof Map?v.map:typeof Set<"u"&&n instanceof Set?v.set:typeof Date<"u"&&n instanceof Date?v.date:v.object;default:return v.unknown}},g=E.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]),Vt=n=>JSON.stringify(n,null,2).replace(/"([^"]+)":/g,"$1:");class q extends Error{constructor(e){super(),this.issues=[],this.addIssue=a=>{this.issues=[...this.issues,a]},this.addIssues=(a=[])=>{this.issues=[...this.issues,...a]};const t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}get errors(){return this.issues}format(e){const t=e||function(i){return i.message},a={_errors:[]},r=i=>{for(const o of i.issues)if(o.code==="invalid_union")o.unionErrors.map(r);else if(o.code==="invalid_return_type")r(o.returnTypeError);else if(o.code==="invalid_arguments")r(o.argumentsError);else if(o.path.length===0)a._errors.push(t(o));else{let c=a,f=0;for(;f<o.path.length;){const _=o.path[f];f===o.path.length-1?(c[_]=c[_]||{_errors:[]},c[_]._errors.push(t(o))):c[_]=c[_]||{_errors:[]},c=c[_],f++}}};return r(this),a}static assert(e){if(!(e instanceof q))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,E.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=t=>t.message){const t={},a=[];for(const r of this.issues)r.path.length>0?(t[r.path[0]]=t[r.path[0]]||[],t[r.path[0]].push(e(r))):a.push(e(r));return{formErrors:a,fieldErrors:t}}get formErrors(){return this.flatten()}}q.create=n=>new q(n);const we=(n,e)=>{let t;switch(n.code){case g.invalid_type:n.received===v.undefined?t="Required":t=`Expected ${n.expected}, received ${n.received}`;break;case g.invalid_literal:t=`Invalid literal value, expected ${JSON.stringify(n.expected,E.jsonStringifyReplacer)}`;break;case g.unrecognized_keys:t=`Unrecognized key(s) in object: ${E.joinValues(n.keys,", ")}`;break;case g.invalid_union:t="Invalid input";break;case g.invalid_union_discriminator:t=`Invalid discriminator value. Expected ${E.joinValues(n.options)}`;break;case g.invalid_enum_value:t=`Invalid enum value. Expected ${E.joinValues(n.options)}, received '${n.received}'`;break;case g.invalid_arguments:t="Invalid function arguments";break;case g.invalid_return_type:t="Invalid function return type";break;case g.invalid_date:t="Invalid date";break;case g.invalid_string:typeof n.validation=="object"?"includes"in n.validation?(t=`Invalid input: must include "${n.validation.includes}"`,typeof n.validation.position=="number"&&(t=`${t} at one or more positions greater than or equal to ${n.validation.position}`)):"startsWith"in n.validation?t=`Invalid input: must start with "${n.validation.startsWith}"`:"endsWith"in n.validation?t=`Invalid input: must end with "${n.validation.endsWith}"`:E.assertNever(n.validation):n.validation!=="regex"?t=`Invalid ${n.validation}`:t="Invalid";break;case g.too_small:n.type==="array"?t=`Array must contain ${n.exact?"exactly":n.inclusive?"at least":"more than"} ${n.minimum} element(s)`:n.type==="string"?t=`String must contain ${n.exact?"exactly":n.inclusive?"at least":"over"} ${n.minimum} character(s)`:n.type==="number"?t=`Number must be ${n.exact?"exactly equal to ":n.inclusive?"greater than or equal to ":"greater than "}${n.minimum}`:n.type==="date"?t=`Date must be ${n.exact?"exactly equal to ":n.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(n.minimum))}`:t="Invalid input";break;case g.too_big:n.type==="array"?t=`Array must contain ${n.exact?"exactly":n.inclusive?"at most":"less than"} ${n.maximum} element(s)`:n.type==="string"?t=`String must contain ${n.exact?"exactly":n.inclusive?"at most":"under"} ${n.maximum} character(s)`:n.type==="number"?t=`Number must be ${n.exact?"exactly":n.inclusive?"less than or equal to":"less than"} ${n.maximum}`:n.type==="bigint"?t=`BigInt must be ${n.exact?"exactly":n.inclusive?"less than or equal to":"less than"} ${n.maximum}`:n.type==="date"?t=`Date must be ${n.exact?"exactly":n.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(n.maximum))}`:t="Invalid input";break;case g.custom:t="Invalid input";break;case g.invalid_intersection_types:t="Intersection results could not be merged";break;case g.not_multiple_of:t=`Number must be a multiple of ${n.multipleOf}`;break;case g.not_finite:t="Number must be finite";break;default:t=e.defaultError,E.assertNever(n)}return{message:t}};let bt=we;function Kt(n){bt=n}function We(){return bt}const Qe=n=>{const{data:e,path:t,errorMaps:a,issueData:r}=n,i=[...t,...r.path||[]],o={...r,path:i};if(r.message!==void 0)return{...r,path:i,message:r.message};let c="";const f=a.filter(_=>!!_).slice().reverse();for(const _ of f)c=_(o,{data:e,defaultError:c}).message;return{...r,path:i,message:c}},Wt=[];function b(n,e){const t=We(),a=Qe({issueData:e,data:n.data,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,t,t===we?void 0:we].filter(r=>!!r)});n.common.issues.push(a)}class D{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,t){const a=[];for(const r of t){if(r.status==="aborted")return O;r.status==="dirty"&&e.dirty(),a.push(r.value)}return{status:e.value,value:a}}static async mergeObjectAsync(e,t){const a=[];for(const r of t){const i=await r.key,o=await r.value;a.push({key:i,value:o})}return D.mergeObjectSync(e,a)}static mergeObjectSync(e,t){const a={};for(const r of t){const{key:i,value:o}=r;if(i.status==="aborted"||o.status==="aborted")return O;i.status==="dirty"&&e.dirty(),o.status==="dirty"&&e.dirty(),i.value!=="__proto__"&&(typeof o.value<"u"||r.alwaysSet)&&(a[i.value]=o.value)}return{status:e.value,value:a}}}const O=Object.freeze({status:"aborted"}),He=n=>({status:"dirty",value:n}),P=n=>({status:"valid",value:n}),it=n=>n.status==="aborted",ot=n=>n.status==="dirty",Ce=n=>n.status==="valid",Se=n=>typeof Promise<"u"&&n instanceof Promise;function Ge(n,e,t,a){if(typeof e=="function"?n!==e||!a:!e.has(n))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e.get(n)}function vt(n,e,t,a,r){if(typeof e=="function"?n!==e||!r:!e.has(n))throw new TypeError("Cannot write private member to an object whose class did not declare it");return e.set(n,t),t}var w;(function(n){n.errToObj=e=>typeof e=="string"?{message:e}:e||{},n.toString=e=>typeof e=="string"?e:e==null?void 0:e.message})(w||(w={}));var Ze,Ee;class G{constructor(e,t,a,r){this._cachedPath=[],this.parent=e,this.data=t,this._path=a,this._key=r}get path(){return this._cachedPath.length||(this._key instanceof Array?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const _t=(n,e)=>{if(Ce(e))return{success:!0,data:e.value};if(!n.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const t=new q(n.common.issues);return this._error=t,this._error}}};function I(n){if(!n)return{};const{errorMap:e,invalid_type_error:t,required_error:a,description:r}=n;if(e&&(t||a))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:r}:{errorMap:(i,o)=>{var c,f;const{message:_}=n;return i.code==="invalid_enum_value"?{message:_??o.defaultError}:typeof o.data>"u"?{message:(c=_??a)!==null&&c!==void 0?c:o.defaultError}:i.code!=="invalid_type"?{message:o.defaultError}:{message:(f=_??t)!==null&&f!==void 0?f:o.defaultError}},description:r}}class j{constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this)}get description(){return this._def.description}_getType(e){return ae(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:ae(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new D,ctx:{common:e.parent.common,data:e.data,parsedType:ae(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(Se(t))throw new Error("Synchronous parse encountered promise.");return t}_parseAsync(e){const t=this._parse(e);return Promise.resolve(t)}parse(e,t){const a=this.safeParse(e,t);if(a.success)return a.data;throw a.error}safeParse(e,t){var a;const r={common:{issues:[],async:(a=t==null?void 0:t.async)!==null&&a!==void 0?a:!1,contextualErrorMap:t==null?void 0:t.errorMap},path:(t==null?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:ae(e)},i=this._parseSync({data:e,path:r.path,parent:r});return _t(r,i)}async parseAsync(e,t){const a=await this.safeParseAsync(e,t);if(a.success)return a.data;throw a.error}async safeParseAsync(e,t){const a={common:{issues:[],contextualErrorMap:t==null?void 0:t.errorMap,async:!0},path:(t==null?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:ae(e)},r=this._parse({data:e,path:a.path,parent:a}),i=await(Se(r)?r:Promise.resolve(r));return _t(a,i)}refine(e,t){const a=r=>typeof t=="string"||typeof t>"u"?{message:t}:typeof t=="function"?t(r):t;return this._refinement((r,i)=>{const o=e(r),c=()=>i.addIssue({code:g.custom,...a(r)});return typeof Promise<"u"&&o instanceof Promise?o.then(f=>f?!0:(c(),!1)):o?!0:(c(),!1)})}refinement(e,t){return this._refinement((a,r)=>e(a)?!0:(r.addIssue(typeof t=="function"?t(a,r):t),!1))}_refinement(e){return new Q({schema:this,typeName:T.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}optional(){return H.create(this,this._def)}nullable(){return oe.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return W.create(this,this._def)}promise(){return Te.create(this,this._def)}or(e){return Re.create([this,e],this._def)}and(e){return De.create(this,e,this._def)}transform(e){return new Q({...I(this._def),schema:this,typeName:T.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t=typeof e=="function"?e:()=>e;return new qe({...I(this._def),innerType:this,defaultValue:t,typeName:T.ZodDefault})}brand(){return new dt({typeName:T.ZodBranded,type:this,...I(this._def)})}catch(e){const t=typeof e=="function"?e:()=>e;return new ze({...I(this._def),innerType:this,catchValue:t,typeName:T.ZodCatch})}describe(e){const t=this.constructor;return new t({...this._def,description:e})}pipe(e){return Ve.create(this,e)}readonly(){return Be.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const Qt=/^c[^\s-]{8,}$/i,Ht=/^[0-9a-z]+$/,Gt=/^[0-9A-HJKMNP-TV-Z]{26}$/,Jt=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,Yt=/^[a-z0-9_-]{21}$/i,Xt=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,en=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,tn="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let at;const nn=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,an=/^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,rn=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,wt="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",sn=new RegExp(`^${wt}$`);function kt(n){let e="([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d";return n.precision?e=`${e}\\.\\d{${n.precision}}`:n.precision==null&&(e=`${e}(\\.\\d+)?`),e}function on(n){return new RegExp(`^${kt(n)}$`)}function Tt(n){let e=`${wt}T${kt(n)}`;const t=[];return t.push(n.local?"Z?":"Z"),n.offset&&t.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${t.join("|")})`,new RegExp(`^${e}$`)}function cn(n,e){return!!((e==="v4"||!e)&&nn.test(n)||(e==="v6"||!e)&&an.test(n))}class K extends j{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==v.string){const r=this._getOrReturnCtx(e);return b(r,{code:g.invalid_type,expected:v.string,received:r.parsedType}),O}const t=new D;let a;for(const r of this._def.checks)if(r.kind==="min")e.data.length<r.value&&(a=this._getOrReturnCtx(e,a),b(a,{code:g.too_small,minimum:r.value,type:"string",inclusive:!0,exact:!1,message:r.message}),t.dirty());else if(r.kind==="max")e.data.length>r.value&&(a=this._getOrReturnCtx(e,a),b(a,{code:g.too_big,maximum:r.value,type:"string",inclusive:!0,exact:!1,message:r.message}),t.dirty());else if(r.kind==="length"){const i=e.data.length>r.value,o=e.data.length<r.value;(i||o)&&(a=this._getOrReturnCtx(e,a),i?b(a,{code:g.too_big,maximum:r.value,type:"string",inclusive:!0,exact:!0,message:r.message}):o&&b(a,{code:g.too_small,minimum:r.value,type:"string",inclusive:!0,exact:!0,message:r.message}),t.dirty())}else if(r.kind==="email")en.test(e.data)||(a=this._getOrReturnCtx(e,a),b(a,{validation:"email",code:g.invalid_string,message:r.message}),t.dirty());else if(r.kind==="emoji")at||(at=new RegExp(tn,"u")),at.test(e.data)||(a=this._getOrReturnCtx(e,a),b(a,{validation:"emoji",code:g.invalid_string,message:r.message}),t.dirty());else if(r.kind==="uuid")Jt.test(e.data)||(a=this._getOrReturnCtx(e,a),b(a,{validation:"uuid",code:g.invalid_string,message:r.message}),t.dirty());else if(r.kind==="nanoid")Yt.test(e.data)||(a=this._getOrReturnCtx(e,a),b(a,{validation:"nanoid",code:g.invalid_string,message:r.message}),t.dirty());else if(r.kind==="cuid")Qt.test(e.data)||(a=this._getOrReturnCtx(e,a),b(a,{validation:"cuid",code:g.invalid_string,message:r.message}),t.dirty());else if(r.kind==="cuid2")Ht.test(e.data)||(a=this._getOrReturnCtx(e,a),b(a,{validation:"cuid2",code:g.invalid_string,message:r.message}),t.dirty());else if(r.kind==="ulid")Gt.test(e.data)||(a=this._getOrReturnCtx(e,a),b(a,{validation:"ulid",code:g.invalid_string,message:r.message}),t.dirty());else if(r.kind==="url")try{new URL(e.data)}catch{a=this._getOrReturnCtx(e,a),b(a,{validation:"url",code:g.invalid_string,message:r.message}),t.dirty()}else r.kind==="regex"?(r.regex.lastIndex=0,r.regex.test(e.data)||(a=this._getOrReturnCtx(e,a),b(a,{validation:"regex",code:g.invalid_string,message:r.message}),t.dirty())):r.kind==="trim"?e.data=e.data.trim():r.kind==="includes"?e.data.includes(r.value,r.position)||(a=this._getOrReturnCtx(e,a),b(a,{code:g.invalid_string,validation:{includes:r.value,position:r.position},message:r.message}),t.dirty()):r.kind==="toLowerCase"?e.data=e.data.toLowerCase():r.kind==="toUpperCase"?e.data=e.data.toUpperCase():r.kind==="startsWith"?e.data.startsWith(r.value)||(a=this._getOrReturnCtx(e,a),b(a,{code:g.invalid_string,validation:{startsWith:r.value},message:r.message}),t.dirty()):r.kind==="endsWith"?e.data.endsWith(r.value)||(a=this._getOrReturnCtx(e,a),b(a,{code:g.invalid_string,validation:{endsWith:r.value},message:r.message}),t.dirty()):r.kind==="datetime"?Tt(r).test(e.data)||(a=this._getOrReturnCtx(e,a),b(a,{code:g.invalid_string,validation:"datetime",message:r.message}),t.dirty()):r.kind==="date"?sn.test(e.data)||(a=this._getOrReturnCtx(e,a),b(a,{code:g.invalid_string,validation:"date",message:r.message}),t.dirty()):r.kind==="time"?on(r).test(e.data)||(a=this._getOrReturnCtx(e,a),b(a,{code:g.invalid_string,validation:"time",message:r.message}),t.dirty()):r.kind==="duration"?Xt.test(e.data)||(a=this._getOrReturnCtx(e,a),b(a,{validation:"duration",code:g.invalid_string,message:r.message}),t.dirty()):r.kind==="ip"?cn(e.data,r.version)||(a=this._getOrReturnCtx(e,a),b(a,{validation:"ip",code:g.invalid_string,message:r.message}),t.dirty()):r.kind==="base64"?rn.test(e.data)||(a=this._getOrReturnCtx(e,a),b(a,{validation:"base64",code:g.invalid_string,message:r.message}),t.dirty()):E.assertNever(r);return{status:t.value,value:e.data}}_regex(e,t,a){return this.refinement(r=>e.test(r),{validation:t,code:g.invalid_string,...w.errToObj(a)})}_addCheck(e){return new K({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...w.errToObj(e)})}url(e){return this._addCheck({kind:"url",...w.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...w.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...w.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...w.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...w.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...w.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...w.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...w.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...w.errToObj(e)})}datetime(e){var t,a;return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,offset:(t=e==null?void 0:e.offset)!==null&&t!==void 0?t:!1,local:(a=e==null?void 0:e.local)!==null&&a!==void 0?a:!1,...w.errToObj(e==null?void 0:e.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,...w.errToObj(e==null?void 0:e.message)})}duration(e){return this._addCheck({kind:"duration",...w.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...w.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t==null?void 0:t.position,...w.errToObj(t==null?void 0:t.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...w.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...w.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...w.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...w.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...w.errToObj(t)})}nonempty(e){return this.min(1,w.errToObj(e))}trim(){return new K({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new K({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new K({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get minLength(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}K.create=n=>{var e;return new K({checks:[],typeName:T.ZodString,coerce:(e=n==null?void 0:n.coerce)!==null&&e!==void 0?e:!1,...I(n)})};function dn(n,e){const t=(n.toString().split(".")[1]||"").length,a=(e.toString().split(".")[1]||"").length,r=t>a?t:a,i=parseInt(n.toFixed(r).replace(".","")),o=parseInt(e.toFixed(r).replace(".",""));return i%o/Math.pow(10,r)}class re extends j{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==v.number){const r=this._getOrReturnCtx(e);return b(r,{code:g.invalid_type,expected:v.number,received:r.parsedType}),O}let t;const a=new D;for(const r of this._def.checks)r.kind==="int"?E.isInteger(e.data)||(t=this._getOrReturnCtx(e,t),b(t,{code:g.invalid_type,expected:"integer",received:"float",message:r.message}),a.dirty()):r.kind==="min"?(r.inclusive?e.data<r.value:e.data<=r.value)&&(t=this._getOrReturnCtx(e,t),b(t,{code:g.too_small,minimum:r.value,type:"number",inclusive:r.inclusive,exact:!1,message:r.message}),a.dirty()):r.kind==="max"?(r.inclusive?e.data>r.value:e.data>=r.value)&&(t=this._getOrReturnCtx(e,t),b(t,{code:g.too_big,maximum:r.value,type:"number",inclusive:r.inclusive,exact:!1,message:r.message}),a.dirty()):r.kind==="multipleOf"?dn(e.data,r.value)!==0&&(t=this._getOrReturnCtx(e,t),b(t,{code:g.not_multiple_of,multipleOf:r.value,message:r.message}),a.dirty()):r.kind==="finite"?Number.isFinite(e.data)||(t=this._getOrReturnCtx(e,t),b(t,{code:g.not_finite,message:r.message}),a.dirty()):E.assertNever(r);return{status:a.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,w.toString(t))}gt(e,t){return this.setLimit("min",e,!1,w.toString(t))}lte(e,t){return this.setLimit("max",e,!0,w.toString(t))}lt(e,t){return this.setLimit("max",e,!1,w.toString(t))}setLimit(e,t,a,r){return new re({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:a,message:w.toString(r)}]})}_addCheck(e){return new re({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:w.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:w.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:w.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:w.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:w.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:w.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:w.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:w.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:w.toString(e)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&E.isInteger(e.value))}get isFinite(){let e=null,t=null;for(const a of this._def.checks){if(a.kind==="finite"||a.kind==="int"||a.kind==="multipleOf")return!0;a.kind==="min"?(t===null||a.value>t)&&(t=a.value):a.kind==="max"&&(e===null||a.value<e)&&(e=a.value)}return Number.isFinite(t)&&Number.isFinite(e)}}re.create=n=>new re({checks:[],typeName:T.ZodNumber,coerce:(n==null?void 0:n.coerce)||!1,...I(n)});class se extends j{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce&&(e.data=BigInt(e.data)),this._getType(e)!==v.bigint){const r=this._getOrReturnCtx(e);return b(r,{code:g.invalid_type,expected:v.bigint,received:r.parsedType}),O}let t;const a=new D;for(const r of this._def.checks)r.kind==="min"?(r.inclusive?e.data<r.value:e.data<=r.value)&&(t=this._getOrReturnCtx(e,t),b(t,{code:g.too_small,type:"bigint",minimum:r.value,inclusive:r.inclusive,message:r.message}),a.dirty()):r.kind==="max"?(r.inclusive?e.data>r.value:e.data>=r.value)&&(t=this._getOrReturnCtx(e,t),b(t,{code:g.too_big,type:"bigint",maximum:r.value,inclusive:r.inclusive,message:r.message}),a.dirty()):r.kind==="multipleOf"?e.data%r.value!==BigInt(0)&&(t=this._getOrReturnCtx(e,t),b(t,{code:g.not_multiple_of,multipleOf:r.value,message:r.message}),a.dirty()):E.assertNever(r);return{status:a.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,w.toString(t))}gt(e,t){return this.setLimit("min",e,!1,w.toString(t))}lte(e,t){return this.setLimit("max",e,!0,w.toString(t))}lt(e,t){return this.setLimit("max",e,!1,w.toString(t))}setLimit(e,t,a,r){return new se({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:a,message:w.toString(r)}]})}_addCheck(e){return new se({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:w.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:w.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:w.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:w.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:w.toString(t)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}se.create=n=>{var e;return new se({checks:[],typeName:T.ZodBigInt,coerce:(e=n==null?void 0:n.coerce)!==null&&e!==void 0?e:!1,...I(n)})};class Fe extends j{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==v.boolean){const t=this._getOrReturnCtx(e);return b(t,{code:g.invalid_type,expected:v.boolean,received:t.parsedType}),O}return P(e.data)}}Fe.create=n=>new Fe({typeName:T.ZodBoolean,coerce:(n==null?void 0:n.coerce)||!1,...I(n)});class xe extends j{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==v.date){const r=this._getOrReturnCtx(e);return b(r,{code:g.invalid_type,expected:v.date,received:r.parsedType}),O}if(isNaN(e.data.getTime())){const r=this._getOrReturnCtx(e);return b(r,{code:g.invalid_date}),O}const t=new D;let a;for(const r of this._def.checks)r.kind==="min"?e.data.getTime()<r.value&&(a=this._getOrReturnCtx(e,a),b(a,{code:g.too_small,message:r.message,inclusive:!0,exact:!1,minimum:r.value,type:"date"}),t.dirty()):r.kind==="max"?e.data.getTime()>r.value&&(a=this._getOrReturnCtx(e,a),b(a,{code:g.too_big,message:r.message,inclusive:!0,exact:!1,maximum:r.value,type:"date"}),t.dirty()):E.assertNever(r);return{status:t.value,value:new Date(e.data.getTime())}}_addCheck(e){return new xe({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:w.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:w.toString(t)})}get minDate(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e!=null?new Date(e):null}}xe.create=n=>new xe({checks:[],coerce:(n==null?void 0:n.coerce)||!1,typeName:T.ZodDate,...I(n)});class Je extends j{_parse(e){if(this._getType(e)!==v.symbol){const t=this._getOrReturnCtx(e);return b(t,{code:g.invalid_type,expected:v.symbol,received:t.parsedType}),O}return P(e.data)}}Je.create=n=>new Je({typeName:T.ZodSymbol,...I(n)});class Ne extends j{_parse(e){if(this._getType(e)!==v.undefined){const t=this._getOrReturnCtx(e);return b(t,{code:g.invalid_type,expected:v.undefined,received:t.parsedType}),O}return P(e.data)}}Ne.create=n=>new Ne({typeName:T.ZodUndefined,...I(n)});class $e extends j{_parse(e){if(this._getType(e)!==v.null){const t=this._getOrReturnCtx(e);return b(t,{code:g.invalid_type,expected:v.null,received:t.parsedType}),O}return P(e.data)}}$e.create=n=>new $e({typeName:T.ZodNull,...I(n)});class ke extends j{constructor(){super(...arguments),this._any=!0}_parse(e){return P(e.data)}}ke.create=n=>new ke({typeName:T.ZodAny,...I(n)});class pe extends j{constructor(){super(...arguments),this._unknown=!0}_parse(e){return P(e.data)}}pe.create=n=>new pe({typeName:T.ZodUnknown,...I(n)});class ee extends j{_parse(e){const t=this._getOrReturnCtx(e);return b(t,{code:g.invalid_type,expected:v.never,received:t.parsedType}),O}}ee.create=n=>new ee({typeName:T.ZodNever,...I(n)});class Ye extends j{_parse(e){if(this._getType(e)!==v.undefined){const t=this._getOrReturnCtx(e);return b(t,{code:g.invalid_type,expected:v.void,received:t.parsedType}),O}return P(e.data)}}Ye.create=n=>new Ye({typeName:T.ZodVoid,...I(n)});class W extends j{_parse(e){const{ctx:t,status:a}=this._processInputParams(e),r=this._def;if(t.parsedType!==v.array)return b(t,{code:g.invalid_type,expected:v.array,received:t.parsedType}),O;if(r.exactLength!==null){const o=t.data.length>r.exactLength.value,c=t.data.length<r.exactLength.value;(o||c)&&(b(t,{code:o?g.too_big:g.too_small,minimum:c?r.exactLength.value:void 0,maximum:o?r.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:r.exactLength.message}),a.dirty())}if(r.minLength!==null&&t.data.length<r.minLength.value&&(b(t,{code:g.too_small,minimum:r.minLength.value,type:"array",inclusive:!0,exact:!1,message:r.minLength.message}),a.dirty()),r.maxLength!==null&&t.data.length>r.maxLength.value&&(b(t,{code:g.too_big,maximum:r.maxLength.value,type:"array",inclusive:!0,exact:!1,message:r.maxLength.message}),a.dirty()),t.common.async)return Promise.all([...t.data].map((o,c)=>r.type._parseAsync(new G(t,o,t.path,c)))).then(o=>D.mergeArray(a,o));const i=[...t.data].map((o,c)=>r.type._parseSync(new G(t,o,t.path,c)));return D.mergeArray(a,i)}get element(){return this._def.type}min(e,t){return new W({...this._def,minLength:{value:e,message:w.toString(t)}})}max(e,t){return new W({...this._def,maxLength:{value:e,message:w.toString(t)}})}length(e,t){return new W({...this._def,exactLength:{value:e,message:w.toString(t)}})}nonempty(e){return this.min(1,e)}}W.create=(n,e)=>new W({type:n,minLength:null,maxLength:null,exactLength:null,typeName:T.ZodArray,...I(e)});function be(n){if(n instanceof F){const e={};for(const t in n.shape){const a=n.shape[t];e[t]=H.create(be(a))}return new F({...n._def,shape:()=>e})}else return n instanceof W?new W({...n._def,type:be(n.element)}):n instanceof H?H.create(be(n.unwrap())):n instanceof oe?oe.create(be(n.unwrap())):n instanceof J?J.create(n.items.map(e=>be(e))):n}class F extends j{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const e=this._def.shape(),t=E.objectKeys(e);return this._cached={shape:e,keys:t}}_parse(e){if(this._getType(e)!==v.object){const f=this._getOrReturnCtx(e);return b(f,{code:g.invalid_type,expected:v.object,received:f.parsedType}),O}const{status:t,ctx:a}=this._processInputParams(e),{shape:r,keys:i}=this._getCached(),o=[];if(!(this._def.catchall instanceof ee&&this._def.unknownKeys==="strip"))for(const f in a.data)i.includes(f)||o.push(f);const c=[];for(const f of i){const _=r[f],y=a.data[f];c.push({key:{status:"valid",value:f},value:_._parse(new G(a,y,a.path,f)),alwaysSet:f in a.data})}if(this._def.catchall instanceof ee){const f=this._def.unknownKeys;if(f==="passthrough")for(const _ of o)c.push({key:{status:"valid",value:_},value:{status:"valid",value:a.data[_]}});else if(f==="strict")o.length>0&&(b(a,{code:g.unrecognized_keys,keys:o}),t.dirty());else if(f!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const f=this._def.catchall;for(const _ of o){const y=a.data[_];c.push({key:{status:"valid",value:_},value:f._parse(new G(a,y,a.path,_)),alwaysSet:_ in a.data})}}return a.common.async?Promise.resolve().then(async()=>{const f=[];for(const _ of c){const y=await _.key,C=await _.value;f.push({key:y,value:C,alwaysSet:_.alwaysSet})}return f}).then(f=>D.mergeObjectSync(t,f)):D.mergeObjectSync(t,c)}get shape(){return this._def.shape()}strict(e){return w.errToObj,new F({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(t,a)=>{var r,i,o,c;const f=(o=(i=(r=this._def).errorMap)===null||i===void 0?void 0:i.call(r,t,a).message)!==null&&o!==void 0?o:a.defaultError;return t.code==="unrecognized_keys"?{message:(c=w.errToObj(e).message)!==null&&c!==void 0?c:f}:{message:f}}}:{}})}strip(){return new F({...this._def,unknownKeys:"strip"})}passthrough(){return new F({...this._def,unknownKeys:"passthrough"})}extend(e){return new F({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new F({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:T.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new F({...this._def,catchall:e})}pick(e){const t={};return E.objectKeys(e).forEach(a=>{e[a]&&this.shape[a]&&(t[a]=this.shape[a])}),new F({...this._def,shape:()=>t})}omit(e){const t={};return E.objectKeys(this.shape).forEach(a=>{e[a]||(t[a]=this.shape[a])}),new F({...this._def,shape:()=>t})}deepPartial(){return be(this)}partial(e){const t={};return E.objectKeys(this.shape).forEach(a=>{const r=this.shape[a];e&&!e[a]?t[a]=r:t[a]=r.optional()}),new F({...this._def,shape:()=>t})}required(e){const t={};return E.objectKeys(this.shape).forEach(a=>{if(e&&!e[a])t[a]=this.shape[a];else{let r=this.shape[a];for(;r instanceof H;)r=r._def.innerType;t[a]=r}}),new F({...this._def,shape:()=>t})}keyof(){return Ot(E.objectKeys(this.shape))}}F.create=(n,e)=>new F({shape:()=>n,unknownKeys:"strip",catchall:ee.create(),typeName:T.ZodObject,...I(e)});F.strictCreate=(n,e)=>new F({shape:()=>n,unknownKeys:"strict",catchall:ee.create(),typeName:T.ZodObject,...I(e)});F.lazycreate=(n,e)=>new F({shape:n,unknownKeys:"strip",catchall:ee.create(),typeName:T.ZodObject,...I(e)});class Re extends j{_parse(e){const{ctx:t}=this._processInputParams(e),a=this._def.options;function r(i){for(const c of i)if(c.result.status==="valid")return c.result;for(const c of i)if(c.result.status==="dirty")return t.common.issues.push(...c.ctx.common.issues),c.result;const o=i.map(c=>new q(c.ctx.common.issues));return b(t,{code:g.invalid_union,unionErrors:o}),O}if(t.common.async)return Promise.all(a.map(async i=>{const o={...t,common:{...t.common,issues:[]},parent:null};return{result:await i._parseAsync({data:t.data,path:t.path,parent:o}),ctx:o}})).then(r);{let i;const o=[];for(const f of a){const _={...t,common:{...t.common,issues:[]},parent:null},y=f._parseSync({data:t.data,path:t.path,parent:_});if(y.status==="valid")return y;y.status==="dirty"&&!i&&(i={result:y,ctx:_}),_.common.issues.length&&o.push(_.common.issues)}if(i)return t.common.issues.push(...i.ctx.common.issues),i.result;const c=o.map(f=>new q(f));return b(t,{code:g.invalid_union,unionErrors:c}),O}}get options(){return this._def.options}}Re.create=(n,e)=>new Re({options:n,typeName:T.ZodUnion,...I(e)});const ne=n=>n instanceof Ue?ne(n.schema):n instanceof Q?ne(n.innerType()):n instanceof Me?[n.value]:n instanceof ie?n.options:n instanceof Le?E.objectValues(n.enum):n instanceof qe?ne(n._def.innerType):n instanceof Ne?[void 0]:n instanceof $e?[null]:n instanceof H?[void 0,...ne(n.unwrap())]:n instanceof oe?[null,...ne(n.unwrap())]:n instanceof dt||n instanceof Be?ne(n.unwrap()):n instanceof ze?ne(n._def.innerType):[];class tt extends j{_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==v.object)return b(t,{code:g.invalid_type,expected:v.object,received:t.parsedType}),O;const a=this.discriminator,r=t.data[a],i=this.optionsMap.get(r);return i?t.common.async?i._parseAsync({data:t.data,path:t.path,parent:t}):i._parseSync({data:t.data,path:t.path,parent:t}):(b(t,{code:g.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[a]}),O)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,t,a){const r=new Map;for(const i of t){const o=ne(i.shape[e]);if(!o.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(const c of o){if(r.has(c))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(c)}`);r.set(c,i)}}return new tt({typeName:T.ZodDiscriminatedUnion,discriminator:e,options:t,optionsMap:r,...I(a)})}}function ct(n,e){const t=ae(n),a=ae(e);if(n===e)return{valid:!0,data:n};if(t===v.object&&a===v.object){const r=E.objectKeys(e),i=E.objectKeys(n).filter(c=>r.indexOf(c)!==-1),o={...n,...e};for(const c of i){const f=ct(n[c],e[c]);if(!f.valid)return{valid:!1};o[c]=f.data}return{valid:!0,data:o}}else if(t===v.array&&a===v.array){if(n.length!==e.length)return{valid:!1};const r=[];for(let i=0;i<n.length;i++){const o=n[i],c=e[i],f=ct(o,c);if(!f.valid)return{valid:!1};r.push(f.data)}return{valid:!0,data:r}}else return t===v.date&&a===v.date&&+n==+e?{valid:!0,data:n}:{valid:!1}}class De extends j{_parse(e){const{status:t,ctx:a}=this._processInputParams(e),r=(i,o)=>{if(it(i)||it(o))return O;const c=ct(i.value,o.value);return c.valid?((ot(i)||ot(o))&&t.dirty(),{status:t.value,value:c.data}):(b(a,{code:g.invalid_intersection_types}),O)};return a.common.async?Promise.all([this._def.left._parseAsync({data:a.data,path:a.path,parent:a}),this._def.right._parseAsync({data:a.data,path:a.path,parent:a})]).then(([i,o])=>r(i,o)):r(this._def.left._parseSync({data:a.data,path:a.path,parent:a}),this._def.right._parseSync({data:a.data,path:a.path,parent:a}))}}De.create=(n,e,t)=>new De({left:n,right:e,typeName:T.ZodIntersection,...I(t)});class J extends j{_parse(e){const{status:t,ctx:a}=this._processInputParams(e);if(a.parsedType!==v.array)return b(a,{code:g.invalid_type,expected:v.array,received:a.parsedType}),O;if(a.data.length<this._def.items.length)return b(a,{code:g.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),O;!this._def.rest&&a.data.length>this._def.items.length&&(b(a,{code:g.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());const r=[...a.data].map((i,o)=>{const c=this._def.items[o]||this._def.rest;return c?c._parse(new G(a,i,a.path,o)):null}).filter(i=>!!i);return a.common.async?Promise.all(r).then(i=>D.mergeArray(t,i)):D.mergeArray(t,r)}get items(){return this._def.items}rest(e){return new J({...this._def,rest:e})}}J.create=(n,e)=>{if(!Array.isArray(n))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new J({items:n,typeName:T.ZodTuple,rest:null,...I(e)})};class Pe extends j{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:a}=this._processInputParams(e);if(a.parsedType!==v.object)return b(a,{code:g.invalid_type,expected:v.object,received:a.parsedType}),O;const r=[],i=this._def.keyType,o=this._def.valueType;for(const c in a.data)r.push({key:i._parse(new G(a,c,a.path,c)),value:o._parse(new G(a,a.data[c],a.path,c)),alwaysSet:c in a.data});return a.common.async?D.mergeObjectAsync(t,r):D.mergeObjectSync(t,r)}get element(){return this._def.valueType}static create(e,t,a){return t instanceof j?new Pe({keyType:e,valueType:t,typeName:T.ZodRecord,...I(a)}):new Pe({keyType:K.create(),valueType:e,typeName:T.ZodRecord,...I(t)})}}class Xe extends j{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:a}=this._processInputParams(e);if(a.parsedType!==v.map)return b(a,{code:g.invalid_type,expected:v.map,received:a.parsedType}),O;const r=this._def.keyType,i=this._def.valueType,o=[...a.data.entries()].map(([c,f],_)=>({key:r._parse(new G(a,c,a.path,[_,"key"])),value:i._parse(new G(a,f,a.path,[_,"value"]))}));if(a.common.async){const c=new Map;return Promise.resolve().then(async()=>{for(const f of o){const _=await f.key,y=await f.value;if(_.status==="aborted"||y.status==="aborted")return O;(_.status==="dirty"||y.status==="dirty")&&t.dirty(),c.set(_.value,y.value)}return{status:t.value,value:c}})}else{const c=new Map;for(const f of o){const _=f.key,y=f.value;if(_.status==="aborted"||y.status==="aborted")return O;(_.status==="dirty"||y.status==="dirty")&&t.dirty(),c.set(_.value,y.value)}return{status:t.value,value:c}}}}Xe.create=(n,e,t)=>new Xe({valueType:e,keyType:n,typeName:T.ZodMap,...I(t)});class he extends j{_parse(e){const{status:t,ctx:a}=this._processInputParams(e);if(a.parsedType!==v.set)return b(a,{code:g.invalid_type,expected:v.set,received:a.parsedType}),O;const r=this._def;r.minSize!==null&&a.data.size<r.minSize.value&&(b(a,{code:g.too_small,minimum:r.minSize.value,type:"set",inclusive:!0,exact:!1,message:r.minSize.message}),t.dirty()),r.maxSize!==null&&a.data.size>r.maxSize.value&&(b(a,{code:g.too_big,maximum:r.maxSize.value,type:"set",inclusive:!0,exact:!1,message:r.maxSize.message}),t.dirty());const i=this._def.valueType;function o(f){const _=new Set;for(const y of f){if(y.status==="aborted")return O;y.status==="dirty"&&t.dirty(),_.add(y.value)}return{status:t.value,value:_}}const c=[...a.data.values()].map((f,_)=>i._parse(new G(a,f,a.path,_)));return a.common.async?Promise.all(c).then(f=>o(f)):o(c)}min(e,t){return new he({...this._def,minSize:{value:e,message:w.toString(t)}})}max(e,t){return new he({...this._def,maxSize:{value:e,message:w.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}he.create=(n,e)=>new he({valueType:n,minSize:null,maxSize:null,typeName:T.ZodSet,...I(e)});class ve extends j{constructor(){super(...arguments),this.validate=this.implement}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==v.function)return b(t,{code:g.invalid_type,expected:v.function,received:t.parsedType}),O;function a(c,f){return Qe({data:c,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,We(),we].filter(_=>!!_),issueData:{code:g.invalid_arguments,argumentsError:f}})}function r(c,f){return Qe({data:c,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,We(),we].filter(_=>!!_),issueData:{code:g.invalid_return_type,returnTypeError:f}})}const i={errorMap:t.common.contextualErrorMap},o=t.data;if(this._def.returns instanceof Te){const c=this;return P(async function(...f){const _=new q([]),y=await c._def.args.parseAsync(f,i).catch(R=>{throw _.addIssue(a(f,R)),_}),C=await Reflect.apply(o,this,y);return await c._def.returns._def.type.parseAsync(C,i).catch(R=>{throw _.addIssue(r(C,R)),_})})}else{const c=this;return P(function(...f){const _=c._def.args.safeParse(f,i);if(!_.success)throw new q([a(f,_.error)]);const y=Reflect.apply(o,this,_.data),C=c._def.returns.safeParse(y,i);if(!C.success)throw new q([r(y,C.error)]);return C.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new ve({...this._def,args:J.create(e).rest(pe.create())})}returns(e){return new ve({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,t,a){return new ve({args:e||J.create([]).rest(pe.create()),returns:t||pe.create(),typeName:T.ZodFunction,...I(a)})}}class Ue extends j{get schema(){return this._def.getter()}_parse(e){const{ctx:t}=this._processInputParams(e);return this._def.getter()._parse({data:t.data,path:t.path,parent:t})}}Ue.create=(n,e)=>new Ue({getter:n,typeName:T.ZodLazy,...I(e)});class Me extends j{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return b(t,{received:t.data,code:g.invalid_literal,expected:this._def.value}),O}return{status:"valid",value:e.data}}get value(){return this._def.value}}Me.create=(n,e)=>new Me({value:n,typeName:T.ZodLiteral,...I(e)});function Ot(n,e){return new ie({values:n,typeName:T.ZodEnum,...I(e)})}class ie extends j{constructor(){super(...arguments),Ze.set(this,void 0)}_parse(e){if(typeof e.data!="string"){const t=this._getOrReturnCtx(e),a=this._def.values;return b(t,{expected:E.joinValues(a),received:t.parsedType,code:g.invalid_type}),O}if(Ge(this,Ze)||vt(this,Ze,new Set(this._def.values)),!Ge(this,Ze).has(e.data)){const t=this._getOrReturnCtx(e),a=this._def.values;return b(t,{received:t.data,code:g.invalid_enum_value,options:a}),O}return P(e.data)}get options(){return this._def.values}get enum(){const e={};for(const t of this._def.values)e[t]=t;return e}get Values(){const e={};for(const t of this._def.values)e[t]=t;return e}get Enum(){const e={};for(const t of this._def.values)e[t]=t;return e}extract(e,t=this._def){return ie.create(e,{...this._def,...t})}exclude(e,t=this._def){return ie.create(this.options.filter(a=>!e.includes(a)),{...this._def,...t})}}Ze=new WeakMap;ie.create=Ot;class Le extends j{constructor(){super(...arguments),Ee.set(this,void 0)}_parse(e){const t=E.getValidEnumValues(this._def.values),a=this._getOrReturnCtx(e);if(a.parsedType!==v.string&&a.parsedType!==v.number){const r=E.objectValues(t);return b(a,{expected:E.joinValues(r),received:a.parsedType,code:g.invalid_type}),O}if(Ge(this,Ee)||vt(this,Ee,new Set(E.getValidEnumValues(this._def.values))),!Ge(this,Ee).has(e.data)){const r=E.objectValues(t);return b(a,{received:a.data,code:g.invalid_enum_value,options:r}),O}return P(e.data)}get enum(){return this._def.values}}Ee=new WeakMap;Le.create=(n,e)=>new Le({values:n,typeName:T.ZodNativeEnum,...I(e)});class Te extends j{unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==v.promise&&t.common.async===!1)return b(t,{code:g.invalid_type,expected:v.promise,received:t.parsedType}),O;const a=t.parsedType===v.promise?t.data:Promise.resolve(t.data);return P(a.then(r=>this._def.type.parseAsync(r,{path:t.path,errorMap:t.common.contextualErrorMap})))}}Te.create=(n,e)=>new Te({type:n,typeName:T.ZodPromise,...I(e)});class Q extends j{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===T.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:t,ctx:a}=this._processInputParams(e),r=this._def.effect||null,i={addIssue:o=>{b(a,o),o.fatal?t.abort():t.dirty()},get path(){return a.path}};if(i.addIssue=i.addIssue.bind(i),r.type==="preprocess"){const o=r.transform(a.data,i);if(a.common.async)return Promise.resolve(o).then(async c=>{if(t.value==="aborted")return O;const f=await this._def.schema._parseAsync({data:c,path:a.path,parent:a});return f.status==="aborted"?O:f.status==="dirty"||t.value==="dirty"?He(f.value):f});{if(t.value==="aborted")return O;const c=this._def.schema._parseSync({data:o,path:a.path,parent:a});return c.status==="aborted"?O:c.status==="dirty"||t.value==="dirty"?He(c.value):c}}if(r.type==="refinement"){const o=c=>{const f=r.refinement(c,i);if(a.common.async)return Promise.resolve(f);if(f instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return c};if(a.common.async===!1){const c=this._def.schema._parseSync({data:a.data,path:a.path,parent:a});return c.status==="aborted"?O:(c.status==="dirty"&&t.dirty(),o(c.value),{status:t.value,value:c.value})}else return this._def.schema._parseAsync({data:a.data,path:a.path,parent:a}).then(c=>c.status==="aborted"?O:(c.status==="dirty"&&t.dirty(),o(c.value).then(()=>({status:t.value,value:c.value}))))}if(r.type==="transform")if(a.common.async===!1){const o=this._def.schema._parseSync({data:a.data,path:a.path,parent:a});if(!Ce(o))return o;const c=r.transform(o.value,i);if(c instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:c}}else return this._def.schema._parseAsync({data:a.data,path:a.path,parent:a}).then(o=>Ce(o)?Promise.resolve(r.transform(o.value,i)).then(c=>({status:t.value,value:c})):o);E.assertNever(r)}}Q.create=(n,e,t)=>new Q({schema:n,typeName:T.ZodEffects,effect:e,...I(t)});Q.createWithPreprocess=(n,e,t)=>new Q({schema:e,effect:{type:"preprocess",transform:n},typeName:T.ZodEffects,...I(t)});class H extends j{_parse(e){return this._getType(e)===v.undefined?P(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}H.create=(n,e)=>new H({innerType:n,typeName:T.ZodOptional,...I(e)});class oe extends j{_parse(e){return this._getType(e)===v.null?P(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}oe.create=(n,e)=>new oe({innerType:n,typeName:T.ZodNullable,...I(e)});class qe extends j{_parse(e){const{ctx:t}=this._processInputParams(e);let a=t.data;return t.parsedType===v.undefined&&(a=this._def.defaultValue()),this._def.innerType._parse({data:a,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}qe.create=(n,e)=>new qe({innerType:n,typeName:T.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...I(e)});class ze extends j{_parse(e){const{ctx:t}=this._processInputParams(e),a={...t,common:{...t.common,issues:[]}},r=this._def.innerType._parse({data:a.data,path:a.path,parent:{...a}});return Se(r)?r.then(i=>({status:"valid",value:i.status==="valid"?i.value:this._def.catchValue({get error(){return new q(a.common.issues)},input:a.data})})):{status:"valid",value:r.status==="valid"?r.value:this._def.catchValue({get error(){return new q(a.common.issues)},input:a.data})}}removeCatch(){return this._def.innerType}}ze.create=(n,e)=>new ze({innerType:n,typeName:T.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...I(e)});class et extends j{_parse(e){if(this._getType(e)!==v.nan){const t=this._getOrReturnCtx(e);return b(t,{code:g.invalid_type,expected:v.nan,received:t.parsedType}),O}return{status:"valid",value:e.data}}}et.create=n=>new et({typeName:T.ZodNaN,...I(n)});const un=Symbol("zod_brand");class dt extends j{_parse(e){const{ctx:t}=this._processInputParams(e),a=t.data;return this._def.type._parse({data:a,path:t.path,parent:t})}unwrap(){return this._def.type}}class Ve extends j{_parse(e){const{status:t,ctx:a}=this._processInputParams(e);if(a.common.async)return(async()=>{const r=await this._def.in._parseAsync({data:a.data,path:a.path,parent:a});return r.status==="aborted"?O:r.status==="dirty"?(t.dirty(),He(r.value)):this._def.out._parseAsync({data:r.value,path:a.path,parent:a})})();{const r=this._def.in._parseSync({data:a.data,path:a.path,parent:a});return r.status==="aborted"?O:r.status==="dirty"?(t.dirty(),{status:"dirty",value:r.value}):this._def.out._parseSync({data:r.value,path:a.path,parent:a})}}static create(e,t){return new Ve({in:e,out:t,typeName:T.ZodPipeline})}}class Be extends j{_parse(e){const t=this._def.innerType._parse(e),a=r=>(Ce(r)&&(r.value=Object.freeze(r.value)),r);return Se(t)?t.then(r=>a(r)):a(t)}unwrap(){return this._def.innerType}}Be.create=(n,e)=>new Be({innerType:n,typeName:T.ZodReadonly,...I(e)});function It(n,e={},t){return n?ke.create().superRefine((a,r)=>{var i,o;if(!n(a)){const c=typeof e=="function"?e(a):typeof e=="string"?{message:e}:e,f=(o=(i=c.fatal)!==null&&i!==void 0?i:t)!==null&&o!==void 0?o:!0,_=typeof c=="string"?{message:c}:c;r.addIssue({code:"custom",..._,fatal:f})}}):ke.create()}const ln={object:F.lazycreate};var T;(function(n){n.ZodString="ZodString",n.ZodNumber="ZodNumber",n.ZodNaN="ZodNaN",n.ZodBigInt="ZodBigInt",n.ZodBoolean="ZodBoolean",n.ZodDate="ZodDate",n.ZodSymbol="ZodSymbol",n.ZodUndefined="ZodUndefined",n.ZodNull="ZodNull",n.ZodAny="ZodAny",n.ZodUnknown="ZodUnknown",n.ZodNever="ZodNever",n.ZodVoid="ZodVoid",n.ZodArray="ZodArray",n.ZodObject="ZodObject",n.ZodUnion="ZodUnion",n.ZodDiscriminatedUnion="ZodDiscriminatedUnion",n.ZodIntersection="ZodIntersection",n.ZodTuple="ZodTuple",n.ZodRecord="ZodRecord",n.ZodMap="ZodMap",n.ZodSet="ZodSet",n.ZodFunction="ZodFunction",n.ZodLazy="ZodLazy",n.ZodLiteral="ZodLiteral",n.ZodEnum="ZodEnum",n.ZodEffects="ZodEffects",n.ZodNativeEnum="ZodNativeEnum",n.ZodOptional="ZodOptional",n.ZodNullable="ZodNullable",n.ZodDefault="ZodDefault",n.ZodCatch="ZodCatch",n.ZodPromise="ZodPromise",n.ZodBranded="ZodBranded",n.ZodPipeline="ZodPipeline",n.ZodReadonly="ZodReadonly"})(T||(T={}));const fn=(n,e={message:`Input not instance of ${n.name}`})=>It(t=>t instanceof n,e),jt=K.create,Zt=re.create,pn=et.create,xn=se.create,Et=Fe.create,hn=xe.create,_n=Je.create,gn=Ne.create,mn=$e.create,yn=ke.create,bn=pe.create,vn=ee.create,wn=Ye.create,kn=W.create,Tn=F.create,On=F.strictCreate,In=Re.create,jn=tt.create,Zn=De.create,En=J.create,An=Pe.create,Cn=Xe.create,Sn=he.create,Fn=ve.create,Nn=Ue.create,$n=Me.create,Rn=ie.create,Dn=Le.create,Pn=Te.create,gt=Q.create,Un=H.create,Mn=oe.create,Ln=Q.createWithPreprocess,qn=Ve.create,zn=()=>jt().optional(),Bn=()=>Zt().optional(),Vn=()=>Et().optional(),Kn={string:n=>K.create({...n,coerce:!0}),number:n=>re.create({...n,coerce:!0}),boolean:n=>Fe.create({...n,coerce:!0}),bigint:n=>se.create({...n,coerce:!0}),date:n=>xe.create({...n,coerce:!0})},Wn=O;var s=Object.freeze({__proto__:null,defaultErrorMap:we,setErrorMap:Kt,getErrorMap:We,makeIssue:Qe,EMPTY_PATH:Wt,addIssueToContext:b,ParseStatus:D,INVALID:O,DIRTY:He,OK:P,isAborted:it,isDirty:ot,isValid:Ce,isAsync:Se,get util(){return E},get objectUtil(){return st},ZodParsedType:v,getParsedType:ae,ZodType:j,datetimeRegex:Tt,ZodString:K,ZodNumber:re,ZodBigInt:se,ZodBoolean:Fe,ZodDate:xe,ZodSymbol:Je,ZodUndefined:Ne,ZodNull:$e,ZodAny:ke,ZodUnknown:pe,ZodNever:ee,ZodVoid:Ye,ZodArray:W,ZodObject:F,ZodUnion:Re,ZodDiscriminatedUnion:tt,ZodIntersection:De,ZodTuple:J,ZodRecord:Pe,ZodMap:Xe,ZodSet:he,ZodFunction:ve,ZodLazy:Ue,ZodLiteral:Me,ZodEnum:ie,ZodNativeEnum:Le,ZodPromise:Te,ZodEffects:Q,ZodTransformer:Q,ZodOptional:H,ZodNullable:oe,ZodDefault:qe,ZodCatch:ze,ZodNaN:et,BRAND:un,ZodBranded:dt,ZodPipeline:Ve,ZodReadonly:Be,custom:It,Schema:j,ZodSchema:j,late:ln,get ZodFirstPartyTypeKind(){return T},coerce:Kn,any:yn,array:kn,bigint:xn,boolean:Et,date:hn,discriminatedUnion:jn,effect:gt,enum:Rn,function:Fn,instanceof:fn,intersection:Zn,lazy:Nn,literal:$n,map:Cn,nan:pn,nativeEnum:Dn,never:vn,null:mn,nullable:Mn,number:Zt,object:Tn,oboolean:Vn,onumber:Bn,optional:Un,ostring:zn,pipeline:qn,preprocess:Ln,promise:Pn,record:An,set:Sn,strictObject:On,string:jt,symbol:_n,transformer:gt,tuple:En,undefined:gn,union:In,unknown:bn,void:wn,NEVER:Wn,ZodIssueCode:g,quotelessJson:Vt,ZodError:q});Bt(s);s.object({start:s.number(),limit:s.number(),length:s.number()});const ut=s.object({created_at:s.string(),updated_at:s.string()}),Qn=s.object({email:s.string().optional(),email_verified:s.boolean().optional(),name:s.string().optional(),username:s.string().optional(),given_name:s.string().optional(),phone_number:s.string().optional(),phone_verified:s.boolean().optional(),family_name:s.string().optional()}).catchall(s.any()),Hn=s.object({connection:s.string(),user_id:s.string(),provider:s.string(),isSocial:s.boolean(),access_token:s.string().optional(),access_token_secret:s.string().optional(),refresh_token:s.string().optional(),profileData:Qn.optional()}),At=s.object({email:s.string().optional(),username:s.string().optional(),given_name:s.string().optional(),family_name:s.string().optional(),nickname:s.string().optional(),name:s.string().optional(),picture:s.string().optional(),locale:s.string().optional(),linked_to:s.string().optional(),profileData:s.string().optional(),user_id:s.string().optional()}),Gn=At.extend({email_verified:s.boolean().default(!1),verify_email:s.boolean().optional(),last_ip:s.string().optional(),last_login:s.string().optional(),user_id:s.string().optional(),provider:s.string().default("email"),connection:s.string().default("email")});Gn.extend(ut.shape).extend({user_id:s.string(),email:s.string(),is_social:s.boolean(),login_count:s.number(),identities:s.array(Hn).optional()});At.extend({email:s.string(),login_count:s.number(),multifactor:s.array(s.string()).optional(),last_ip:s.string().optional(),last_login:s.string().optional(),user_id:s.string()}).catchall(s.any());const Jn=s.enum(["sapi","ssa","fsa","ss","ssa","fs","s","f","fp","slo","scoa","fcoa","seccft","cls","seacft","serft"]),Yn=s.object({name:s.string(),version:s.string(),env:s.object({node:s.string().optional()}).optional()});s.object({type:Jn,date:s.string(),description:s.string().optional(),log_id:s.string().optional(),_id:s.string().optional(),ip:s.string(),user_agent:s.string(),details:s.any().optional(),isMobile:s.boolean(),user_id:s.string().optional(),user_name:s.string().optional(),connection:s.string().optional(),connection_id:s.string().optional(),client_id:s.string().optional(),client_name:s.string().optional(),audience:s.string().optional(),scope:s.array(s.string()).optional(),strategy:s.string().optional(),strategy_type:s.string().optional(),hostname:s.string().optional(),auth0_client:Yn.optional()});const Xn=s.object({id:s.string(),name:s.string(),allowed_web_origins:s.string().transform(n=>n===null?"":n).default(""),allowed_callback_urls:s.string().transform(n=>n===null?"":n).default(""),allowed_logout_urls:s.string().transform(n=>n===null?"":n).default(""),email_validation:s.enum(["enabled","disabled","enforced"]).default("enforced"),client_secret:s.string().default(""),disable_sign_ups:s.boolean().default(!1)});s.object({created_at:s.string().transform(n=>n===null?"":n),updated_at:s.string().transform(n=>n===null?"":n)}).extend(Xn.shape);var Ct=(n=>(n.TOKEN="token",n.TOKEN_ID_TOKEN="token id_token",n.CODE="code",n))(Ct||{}),St=(n=>(n.QUERY="query",n.FRAGMENT="fragment",n.FORM_POST="form_post",n.WEB_MESSAGE="web_message",n))(St||{}),Ft=(n=>(n.S265="S256",n.plain="plain",n))(Ft||{});const lt=s.object({client_id:s.string(),vendor_id:s.string().optional(),response_type:s.nativeEnum(Ct).optional(),response_mode:s.nativeEnum(St).optional(),redirect_uri:s.string().optional(),audience:s.string().optional(),state:s.string().optional(),nonce:s.string().optional(),scope:s.string().optional(),code_challenge_method:s.nativeEnum(Ft).optional(),code_challenge:s.string().optional(),username:s.string().optional()}),ea=s.object({authParams:lt,code:s.string(),user_id:s.string(),created_at:s.string(),expires_at:s.string(),used_at:s.string().optional()});s.object({...ea.shape,created_at:s.string()});s.object({colors:s.object({primary:s.string(),page_background:s.object({type:s.string().optional(),start:s.string().optional(),end:s.string().optional(),angle_deg:s.number().optional()}).optional()}).optional(),logo_url:s.string().optional(),favicon_url:s.string().optional(),font:s.object({url:s.string()}).optional()});const ta=s.object({id:s.string().optional(),name:s.string(),client_id:s.string().optional(),client_secret:s.string().optional(),authorization_endpoint:s.string().optional(),response_type:s.custom().optional(),response_mode:s.custom().optional(),private_key:s.string().optional(),kid:s.string().optional(),team_id:s.string().optional(),token_endpoint:s.string().optional(),token_exchange_basic_auth:s.boolean().optional(),userinfo_endpoint:s.string().optional(),scope:s.string().optional()}),ft=s.object({id:s.string(),created_at:s.string().transform(n=>n===null?"":n),updated_at:s.string().transform(n=>n===null?"":n)}).extend(ta.shape),na=s.object({domain:s.string(),dkim_private_key:s.string().optional(),dkim_public_key:s.string().optional(),email_api_key:s.string().optional(),email_service:s.union([s.literal("mailgun"),s.literal("mailchannels")]).optional()}),Nt=s.object({id:s.string(),name:s.string(),domains:s.array(na),allowed_callback_urls:s.array(s.string()),allowed_logout_urls:s.array(s.string()),allowed_web_origins:s.array(s.string()),email_validation:s.union([s.literal("enabled"),s.literal("disabled"),s.literal("enforced")]),tenant_id:s.string(),client_secret:s.string(),disable_sign_ups:s.boolean(),tenant:s.object({name:s.string(),audience:s.string().optional(),logo:s.string().optional(),primary_color:s.string().optional(),secondary_color:s.string().optional(),sender_email:s.string(),sender_name:s.string(),support_url:s.string().optional(),language:s.string().length(2).optional()})});Nt.extend({connections:s.array(ft)});Nt.extend({connections:s.array(ft.partial())});const aa=s.object({domain:s.string(),dkim_private_key:s.string().optional(),dkim_public_key:s.string().optional(),email_api_key:s.string().optional(),email_service:s.enum(["mailgun","mailchannels"])});ut.extend({...aa.shape,id:s.string()});const ra=s.object({trigger_id:s.enum(["post-user-registration","post-user-login"]),enabled:s.boolean().default(!1),url:s.string(),hook_id:s.string().optional()});ra.extend({...ut.shape,hook_id:s.string()});const sa=s.object({alg:s.string(),e:s.string(),kid:s.string(),kty:s.string(),n:s.string(),use:s.string().optional()});s.object({keys:s.array(sa)});s.object({issuer:s.string(),authorization_endpoint:s.string(),token_endpoint:s.string(),device_authorization_endpoint:s.string(),userinfo_endpoint:s.string(),mfa_challenge_endpoint:s.string(),jwks_uri:s.string(),registration_endpoint:s.string(),revocation_endpoint:s.string(),scopes_supported:s.array(s.string()),response_types_supported:s.array(s.string()),code_challenge_methods_supported:s.array(s.string()),response_modes_supported:s.array(s.string()),subject_types_supported:s.array(s.string()),id_token_signing_alg_values_supported:s.array(s.string()),token_endpoint_auth_methods_supported:s.array(s.string()),claims_supported:s.array(s.string()),request_uri_parameter_supported:s.boolean(),request_parameter_supported:s.boolean(),token_endpoint_auth_signing_alg_values_supported:s.array(s.string())});const ia=s.object({id:s.string(),email:s.string(),code:s.string(),ip:s.string().optional(),send:s.enum(["code","link"]),authParams:lt,expires_at:s.string(),used_at:s.string().optional(),user_id:s.string().optional()});s.object({created_at:s.string(),...ia.shape});const oa=s.object({session_id:s.string(),client_id:s.string(),expires_at:s.string(),used_at:s.string(),deleted_at:s.string().optional(),user_id:s.string()});s.object({created_at:s.string(),...oa.shape});s.object({private_key:s.string(),public_key:s.string(),kid:s.string(),created_at:s.string(),revoked_at:s.string().optional()});s.object({kid:s.string().openapi({description:"The key id of the signing key"}),cert:s.string().openapi({description:"The public certificate of the signing key"}),fingerprint:s.string().openapi({description:"The cert fingerprint"}),thumbprint:s.string().openapi({description:"The cert thumbprint"}),pkcs7:s.string().optional().openapi({description:"The public certificate of the signing key in pkcs7 format"}),current:s.boolean().optional().openapi({description:"True if the key is the current key"}),next:s.boolean().optional().openapi({description:"True if the key is the next key"}),previous:s.boolean().optional().openapi({description:"True if the key is the previous key"}),current_since:s.string().optional().openapi({description:"The date and time when the key became the current key"}),current_until:s.string().optional().openapi({description:"The date and time when the current key was rotated"}),revoked:s.boolean().optional().openapi({description:"True if the key is revoked"}),revoked_at:s.string().optional().openapi({description:"The date and time when the key was revoked"})});const ca=s.object({name:s.string(),audience:s.string(),sender_email:s.string().email(),sender_name:s.string(),support_url:s.string().url().optional(),logo:s.string().url().optional(),primary_color:s.string().optional(),secondary_color:s.string().optional(),language:s.string().optional()});ca.extend({created_at:s.string().transform(n=>n===null?"":n),updated_at:s.string().transform(n=>n===null?"":n)});s.object({logoUrl:s.string(),loginBackgroundImage:s.string().nullish(),style:s.object({primaryColor:s.string(),buttonTextColor:s.string(),primaryHoverColor:s.string()}),supportEmail:s.string().nullable(),supportUrl:s.string().nullable(),name:s.string(),showGreyishBackground:s.boolean().optional(),termsAndConditionsUrl:s.string().nullable(),companyName:s.string().optional(),checkoutHideSocial:s.boolean().optional(),siteUrl:s.string().nullable(),manageSubscriptionsUrl:s.string().optional()});var $t=(n=>(n.RefreshToken="refresh_token",n.AuthorizationCode="authorization_code",n.ClientCredential="client_credentials",n.Passwordless="passwordless",n.Password="password",n))($t||{});const pt=s.nativeEnum($t);s.object({grant_type:pt.refine(n=>n==="authorization_code"),code:s.string(),client_secret:s.string(),client_id:s.string()});s.object({grant_type:pt.refine(n=>n==="authorization_code"),code:s.string(),code_verifier:s.string(),client_id:s.string().optional(),redirect_uri:s.string()});s.object({grant_type:pt.refine(n=>n==="client_credentials"),scope:s.string().optional(),client_secret:s.string(),client_id:s.string(),audience:s.string().optional()});s.object({access_token:s.string(),id_token:s.string().optional(),scope:s.string().optional(),state:s.string().optional(),refresh_token:s.string().optional(),token_type:s.string(),expires_in:s.number()});s.object({code:s.string(),state:s.string().optional()});const da=s.object({id:s.string(),expires_at:s.string(),auth0Client:s.string().optional(),authParams:lt});s.object({...da.shape,created_at:s.string(),updated_at:s.string()});function xt(n){const[e,t]=n.split("|");if(!e||!t)throw new Error(`Invalid user_id: ${n}`);return{connection:e,id:t}}function Rt(n){let e={};try{e=JSON.parse(n.profileData||"{}")}catch(t){console.error("Error parsing profileData",t)}return{connection:n.connection,provider:n.provider,user_id:xt(n.user_id).id,isSocial:!!n.is_social,profileData:{email:n.email,email_verified:!!n.email_verified,...e}}}function ua(n){return async(e,t)=>{const[a,r]=await Promise.all([n.selectFrom("users").where("users.tenant_id","=",e).where("users.user_id","=",t).selectAll().executeTakeFirst(),n.selectFrom("users").where("users.tenant_id","=",e).where("users.linked_to","=",t).selectAll().execute()]);if(!a)return null;const{tenant_id:i,...o}=a,c={...o,email:a.email||"",email_verified:a.email_verified===1,is_social:a.is_social===1,identities:[{connection:a.connection,provider:a.provider,user_id:xt(a.user_id).id,isSocial:!!a.is_social},...r.map(Rt)]};return U(c)}}function Oe(n,e,t,a){return t.split(/\s+/).map(i=>i.replace("=",":")).map(i=>{let o=i.startsWith("-"),c,f,_;return i.startsWith("-_exists_:")?(c=i.substring(10),_=!0,o=!0):i.startsWith("_exists_:")?(c=i.substring(9),_=!0,o=!1):i.includes(":")?(o=i.startsWith("-"),[c,f]=o?i.substring(1).split(":"):i.split(":"),_=!1):(c=null,f=i,_=!1),{key:c,value:f,isNegation:o,isExistsQuery:_}}).forEach(({key:i,value:o,isNegation:c,isExistsQuery:f})=>{if(i)f?c?e=e.where(i,"is",null):e=e.where(i,"is not",null):c?e=e.where(i,"!=",o):e=e.where(i,"=",o);else{const{ref:_}=n.dynamic;e=e.where(y=>y.or(a.map(C=>y(_(C),"like",`%${o}%`))))}}),e}function _e(n){return typeof n=="string"?parseInt(n,10):typeof n=="bigint"?Number(n):n}function la(n){return async(e,t)=>{let a=n.selectFrom("users").where("users.tenant_id","=",e);if(t.q&&(a=Oe(n,a,t.q,["email","name"])),t.sort&&t.sort.sort_by){const{ref:y}=n.dynamic;a=a.orderBy(y(t.sort.sort_by),t.sort.sort_order)}const i=await a.offset(t.page*t.per_page).limit(t.per_page).selectAll().execute(),o=i.map(y=>y.user_id),c=o.length?await n.selectFrom("users").selectAll().where("users.tenant_id","=",e).where("users.linked_to","in",o).execute():[],f=i.map(y=>{const C=c.filter(R=>R.linked_to===y.user_id);return U({...y,email_verified:y.email_verified===1,is_social:y.is_social===1,identities:[{connection:y.connection,provider:y.provider,user_id:xt(y.user_id).id,isSocial:!!y.is_social},...C.map(Rt)]})}),{count:_}=await a.select(y=>y.fn.countAll().as("count")).executeTakeFirstOrThrow();return{users:f,start:t.page*t.per_page,limit:t.per_page,length:_e(_)}}}function fa(n){return async(e,t)=>(await n.deleteFrom("users").where("users.tenant_id","=",e).where("users.linked_to","=",t).execute(),(await n.deleteFrom("users").where("users.tenant_id","=",e).where("users.user_id","=",t).execute()).length===1)}function pa(n){if(n.email_verified!==void 0)return n.email_verified?1:0}function xa(n){return async(e,t,a)=>{const r={...a,email_verified:pa(a),updated_at:new Date().toISOString()};return(await n.updateTable("users").set(r).where("users.tenant_id","=",e).where("users.user_id","=",t).execute()).length===1}}function ha(n){return async(e,t,a,r)=>{const i={linked_to:null};return(await n.updateTable("users").set(i).where("users.tenant_id","=",e).where("users.user_id","=",`${a}|${r}`).where("users.linked_to","=",`${t}`).execute()).length===1}}function _a(n){return{create:Lt(n),remove:fa(n),get:ua(n),list:la(n),update:xa(n),unlink:ha(n)}}const ga="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Ke=(n=21)=>{let e="",t=crypto.getRandomValues(new Uint8Array(n));for(;n--;)e+=ga[t[n]&63];return e};function ma(n){return async e=>{const t={id:e.id||Ke(),created_at:new Date().toISOString(),updated_at:new Date().toISOString(),...e};return await n.insertInto("tenants").values(t).execute(),t}}function ya(n){return async e=>{const t=await n.selectFrom("tenants").where("tenants.id","=",e).selectAll().executeTakeFirst();return t?U(t):null}}function ba(n){return async e=>{let t=n.selectFrom("tenants");if(e.sort&&e.sort.sort_by){const{ref:c}=n.dynamic;t=t.orderBy(c(e.sort.sort_by),e.sort.sort_order)}e.q&&(t=t.where(c=>c.or([c("name","like",`%${e.q}%`)])));const r=await t.offset(e.page*e.per_page).limit(e.per_page).selectAll().execute();if(!e.include_totals)return{tenants:r};const{count:i}=await t.select(c=>c.fn.countAll().as("count")).executeTakeFirstOrThrow(),o=_e(i);return{tenants:r.map(U),start:(e.page-1)*e.per_page,limit:e.per_page,length:o}}}function va(n){return async(e,t)=>{const a={...t,id:e,updated_at:new Date().toISOString()};await n.updateTable("tenants").set(a).where("id","=",e).execute()}}function wa(n){return async e=>(await n.deleteFrom("tenants").where("tenants.id","=",e).execute()).length===1}function ka(n){return{create:ma(n),get:ya(n),list:ba(n),update:va(n),remove:wa(n)}}function mt(n){return n?JSON.stringify(n):void 0}const Ta=1024;function Oa(n){return async(e,t)=>{var r,i;const a={id:Ke(),...t,user_agent:t.user_agent.slice(0,Ta)};return await n.insertInto("logs").values({...a,isMobile:t.isMobile?1:0,tenant_id:e,scope:(r=t.scope)==null?void 0:r.join(","),auth0_client:mt(t.auth0_client),details:(i=mt(t.details))==null?void 0:i.substring(0,8192)}).execute(),a}}function yt(n){if(!n)return"";try{return JSON.parse(n)}catch{return n}}function Dt(n){return{...n,client_id:n.client_id,client_name:"",auth0_client:yt(n.auth0_client),details:yt(n.details),isMobile:!!n.isMobile,scope:n.scope?n.scope.split(","):void 0,log_id:n.id,_id:n.id}}function Ia(n){return async(e,t)=>{let a=n.selectFrom("logs").where("logs.tenant_id","=",e);t.q&&(a=Oe(n,a,t.q,["user_id","ip"]));let r=a;if(t.sort&&t.sort.sort_by){const{ref:c}=n.dynamic;r=r.orderBy(c(t.sort.sort_by),t.sort.sort_order)}r=r.offset(t.page*t.per_page).limit(t.per_page);const i=await r.selectAll().execute(),{count:o}=await a.select(c=>c.fn.countAll().as("count")).executeTakeFirstOrThrow();return{logs:i.map(Dt),start:t.page*t.per_page,limit:t.per_page,length:_e(o)}}}function ja(n){return async(e,t)=>{const a=await n.selectFrom("logs").where("logs.tenant_id","=",e).where("logs.id","=",t).selectAll().executeTakeFirst();return a?Dt(a):null}}function Za(n){return{create:Oa(n),list:Ia(n),get:ja(n)}}function Ea(n){return async(e,t)=>{const a=await n.selectFrom("sessions").where("sessions.tenant_id","=",e).where("sessions.id","=",t).where("sessions.deleted_at","is",null).selectAll().executeTakeFirst();return a?{session_id:a.id,user_id:a.user_id,client_id:a.client_id,created_at:a.created_at,expires_at:a.expires_at,used_at:a.used_at}:null}}function Aa(n){return async(e,t)=>{const a={user_id:t.user_id,client_id:t.client_id,created_at:new Date().toISOString(),expires_at:new Date().toISOString(),used_at:t.used_at};return await n.insertInto("sessions").values({...a,tenant_id:e,id:t.session_id}).execute(),{...t,...a}}}function Ca(n){return async(e,t)=>!!(await n.updateTable("sessions").set({deleted_at:new Date().toISOString()}).where("tenant_id","=",e).where("sessions.id","=",t).where("sessions.deleted_at","is",null).execute()).length}function Sa(n){return async(e,t,a)=>!!(await n.updateTable("sessions").set(a).where("tenant_id","=",e).where("sessions.id","=",t).where("sessions.deleted_at","is",null).execute()).length}function Fa(n){return async(e,t)=>{let a=n.selectFrom("sessions").where("sessions.tenant_id","=",e);t.q&&(a=Oe(n,a,t.q,["user_id","id"]));let r=a;if(t.sort&&t.sort.sort_by){const{ref:f}=n.dynamic;r=r.orderBy(f(t.sort.sort_by),t.sort.sort_order)}r=r.offset(t.page*t.per_page).limit(t.per_page);const i=await r.selectAll().execute(),{count:o}=await a.select(f=>f.fn.countAll().as("count")).executeTakeFirstOrThrow(),c=_e(o);return{sessions:i.map(f=>{const{id:_,...y}=f;return{session_id:_,...y}}),start:t.page*t.per_page,limit:t.per_page,length:c}}}function Na(n){return{create:Aa(n),get:Ea(n),list:Fa(n),remove:Ca(n),update:Sa(n)}}function $a(n){return async(e,t)=>{const a=await n.selectFrom("tickets").where("tickets.tenant_id","=",e).where("tickets.id","=",t).where("tickets.used_at","is",null).selectAll().executeTakeFirst();if(!a)return null;const{nonce:r,state:i,scope:o,response_type:c,response_mode:f,redirect_uri:_,...y}=a;return{...y,authParams:{nonce:r,state:i,scope:o,response_type:c,response_mode:f,redirect_uri:_},created_at:new Date(a.created_at),expires_at:new Date(a.expires_at),used_at:a.used_at?new Date(a.used_at):void 0}}}function Ra(n){return async e=>{const{authParams:t,...a}=e,r={...a,...t,created_at:e.created_at.toISOString(),expires_at:e.expires_at.toISOString(),used_at:e.used_at?e.used_at.toISOString():void 0};await n.insertInto("tickets").values(r).execute()}}function Da(n){return async(e,t)=>{await n.updateTable("tickets").set({used_at:new Date().toISOString()}).where("tickets.tenant_id","=",e).where("tickets.id","=",t).execute()}}function Pa(n){return{create:Ra(n),get:$a(n),remove:Da(n)}}function Ua(n){return async(e,t)=>{const a=new Date().toISOString();return(await n.selectFrom("otps").where("otps.tenant_id","=",e).where("otps.email","=",t).where("otps.expires_at",">",a).where("otps.used_at","is",null).selectAll().execute()).map(i=>{const{nonce:o,state:c,scope:f,response_type:_,redirect_uri:y,client_id:C,...R}=i;return{...R,client_id:C,authParams:{client_id:C,nonce:o,state:c,scope:f,response_type:_,redirect_uri:y},created_at:i.created_at,expires_at:i.expires_at}})}}function Ma(n){return async(e,t)=>{const{authParams:a,...r}=t;await n.insertInto("otps").values({...r,...a,created_at:new Date().toISOString(),tenant_id:e,send:t.send==="code"?"code":"link"}).execute()}}function La(n){return async(e,t)=>(await n.updateTable("otps").set({used_at:new Date().toISOString()}).where("otps.tenant_id","=",e).where("otps.id","=",t).execute()).length>0}function qa(n){return{create:Ma(n),list:Ua(n),remove:La(n)}}var za=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ba(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}function Va(n){if(n.__esModule)return n;var e=n.default;if(typeof e=="function"){var t=function a(){return this instanceof a?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};t.prototype=e.prototype}else t={};return Object.defineProperty(t,"__esModule",{value:!0}),Object.keys(n).forEach(function(a){var r=Object.getOwnPropertyDescriptor(n,a);Object.defineProperty(t,a,r.get?r:{enumerable:!0,get:function(){return n[a]}})}),t}function Ka(n){throw new Error('Could not dynamically require "'+n+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var Pt={exports:{}};const Wa={},Qa=Object.freeze(Object.defineProperty({__proto__:null,default:Wa},Symbol.toStringTag,{value:"Module"})),Ha=Va(Qa);(function(n){/**
|
|
2
|
+
* @license bcrypt.js (c) 2013 Daniel Wirtz <dcode@dcode.io>
|
|
3
|
+
* Released under the Apache License, Version 2.0
|
|
4
|
+
* see: https://github.com/dcodeIO/bcrypt.js for details
|
|
5
|
+
*/(function(e,t){typeof Ka=="function"&&n&&n.exports?n.exports=t():(e.dcodeIO=e.dcodeIO||{}).bcrypt=t()})(za,function(){var e={},t=null;function a(x){if(n&&n.exports)try{return Ha.randomBytes(x)}catch{}try{var p;return(self.crypto||self.msCrypto).getRandomValues(p=new Uint32Array(x)),Array.prototype.slice.call(p)}catch{}if(!t)throw Error("Neither WebCryptoAPI nor a crypto module is available. Use bcrypt.setRandomFallback to set an alternative");return t(x)}var r=!1;try{a(1),r=!0}catch{}t=null,e.setRandomFallback=function(x){t=x},e.genSaltSync=function(x,p){if(x=x||B,typeof x!="number")throw Error("Illegal arguments: "+typeof x+", "+typeof p);x<4?x=4:x>31&&(x=31);var l=[];return l.push("$2a$"),x<10&&l.push("0"),l.push(x.toString()),l.push("$"),l.push(C(a(M),M)),l.join("")},e.genSalt=function(x,p,l){if(typeof p=="function"&&(l=p,p=void 0),typeof x=="function"&&(l=x,x=void 0),typeof x>"u")x=B;else if(typeof x!="number")throw Error("illegal arguments: "+typeof x);function u(d){o(function(){try{d(null,e.genSaltSync(x))}catch(h){d(h)}})}if(l){if(typeof l!="function")throw Error("Illegal callback: "+typeof l);u(l)}else return new Promise(function(d,h){u(function(m,Z){if(m){h(m);return}d(Z)})})},e.hashSync=function(x,p){if(typeof p>"u"&&(p=B),typeof p=="number"&&(p=e.genSaltSync(p)),typeof x!="string"||typeof p!="string")throw Error("Illegal arguments: "+typeof x+", "+typeof p);return fe(x,p)},e.hash=function(x,p,l,u){function d(h){typeof x=="string"&&typeof p=="number"?e.genSalt(p,function(m,Z){fe(x,Z,h,u)}):typeof x=="string"&&typeof p=="string"?fe(x,p,h,u):o(h.bind(this,Error("Illegal arguments: "+typeof x+", "+typeof p)))}if(l){if(typeof l!="function")throw Error("Illegal callback: "+typeof l);d(l)}else return new Promise(function(h,m){d(function(Z,k){if(Z){m(Z);return}h(k)})})};function i(x,p){for(var l=0,u=0,d=0,h=x.length;d<h;++d)x.charCodeAt(d)===p.charCodeAt(d)?++l:++u;return l<0?!1:u===0}e.compareSync=function(x,p){if(typeof x!="string"||typeof p!="string")throw Error("Illegal arguments: "+typeof x+", "+typeof p);return p.length!==60?!1:i(e.hashSync(x,p.substr(0,p.length-31)),p)},e.compare=function(x,p,l,u){function d(h){if(typeof x!="string"||typeof p!="string"){o(h.bind(this,Error("Illegal arguments: "+typeof x+", "+typeof p)));return}if(p.length!==60){o(h.bind(this,null,!1));return}e.hash(x,p.substr(0,29),function(m,Z){m?h(m):h(null,i(Z,p))},u)}if(l){if(typeof l!="function")throw Error("Illegal callback: "+typeof l);d(l)}else return new Promise(function(h,m){d(function(Z,k){if(Z){m(Z);return}h(k)})})},e.getRounds=function(x){if(typeof x!="string")throw Error("Illegal arguments: "+typeof x);return parseInt(x.split("$")[2],10)},e.getSalt=function(x){if(typeof x!="string")throw Error("Illegal arguments: "+typeof x);if(x.length!==60)throw Error("Illegal hash length: "+x.length+" != 60");return x.substring(0,29)};var o=typeof process<"u"&&process&&typeof process.nextTick=="function"?typeof setImmediate=="function"?setImmediate:process.nextTick:setTimeout;function c(x){var p=[],l=0;return Y.encodeUTF16toUTF8(function(){return l>=x.length?null:x.charCodeAt(l++)},function(u){p.push(u)}),p}var f="./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split(""),_=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,54,55,56,57,58,59,60,61,62,63,-1,-1,-1,-1,-1,-1,-1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,-1,-1,-1,-1,-1,-1,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,-1,-1,-1,-1,-1],y=String.fromCharCode;function C(x,p){var l=0,u=[],d,h;if(p<=0||p>x.length)throw Error("Illegal len: "+p);for(;l<p;){if(d=x[l++]&255,u.push(f[d>>2&63]),d=(d&3)<<4,l>=p){u.push(f[d&63]);break}if(h=x[l++]&255,d|=h>>4&15,u.push(f[d&63]),d=(h&15)<<2,l>=p){u.push(f[d&63]);break}h=x[l++]&255,d|=h>>6&3,u.push(f[d&63]),u.push(f[h&63])}return u.join("")}function R(x,p){var l=0,u=x.length,d=0,h=[],m,Z,k,A,S,N;if(p<=0)throw Error("Illegal len: "+p);for(;l<u-1&&d<p&&(N=x.charCodeAt(l++),m=N<_.length?_[N]:-1,N=x.charCodeAt(l++),Z=N<_.length?_[N]:-1,!(m==-1||Z==-1||(S=m<<2>>>0,S|=(Z&48)>>4,h.push(y(S)),++d>=p||l>=u)||(N=x.charCodeAt(l++),k=N<_.length?_[N]:-1,k==-1)||(S=(Z&15)<<4>>>0,S|=(k&60)>>2,h.push(y(S)),++d>=p||l>=u)));)N=x.charCodeAt(l++),A=N<_.length?_[N]:-1,S=(k&3)<<6>>>0,S|=A,h.push(y(S)),++d;var V=[];for(l=0;l<d;l++)V.push(h[l].charCodeAt(0));return V}var Y=function(){var x={};return x.MAX_CODEPOINT=1114111,x.encodeUTF8=function(p,l){var u=null;for(typeof p=="number"&&(u=p,p=function(){return null});u!==null||(u=p())!==null;)u<128?l(u&127):u<2048?(l(u>>6&31|192),l(u&63|128)):u<65536?(l(u>>12&15|224),l(u>>6&63|128),l(u&63|128)):(l(u>>18&7|240),l(u>>12&63|128),l(u>>6&63|128),l(u&63|128)),u=null},x.decodeUTF8=function(p,l){for(var u,d,h,m,Z=function(k){k=k.slice(0,k.indexOf(null));var A=Error(k.toString());throw A.name="TruncatedError",A.bytes=k,A};(u=p())!==null;)if(!(u&128))l(u);else if((u&224)===192)(d=p())===null&&Z([u,d]),l((u&31)<<6|d&63);else if((u&240)===224)((d=p())===null||(h=p())===null)&&Z([u,d,h]),l((u&15)<<12|(d&63)<<6|h&63);else if((u&248)===240)((d=p())===null||(h=p())===null||(m=p())===null)&&Z([u,d,h,m]),l((u&7)<<18|(d&63)<<12|(h&63)<<6|m&63);else throw RangeError("Illegal starting byte: "+u)},x.UTF16toUTF8=function(p,l){for(var u,d=null;(u=d!==null?d:p())!==null;){if(u>=55296&&u<=57343&&(d=p())!==null&&d>=56320&&d<=57343){l((u-55296)*1024+d-56320+65536),d=null;continue}l(u)}d!==null&&l(d)},x.UTF8toUTF16=function(p,l){var u=null;for(typeof p=="number"&&(u=p,p=function(){return null});u!==null||(u=p())!==null;)u<=65535?l(u):(u-=65536,l((u>>10)+55296),l(u%1024+56320)),u=null},x.encodeUTF16toUTF8=function(p,l){x.UTF16toUTF8(p,function(u){x.encodeUTF8(u,l)})},x.decodeUTF8toUTF16=function(p,l){x.decodeUTF8(p,function(u){x.UTF8toUTF16(u,l)})},x.calculateCodePoint=function(p){return p<128?1:p<2048?2:p<65536?3:4},x.calculateUTF8=function(p){for(var l,u=0;(l=p())!==null;)u+=x.calculateCodePoint(l);return u},x.calculateUTF16asUTF8=function(p){var l=0,u=0;return x.UTF16toUTF8(p,function(d){++l,u+=x.calculateCodePoint(d)}),[l,u]},x}();Date.now=Date.now||function(){return+new Date};var M=16,B=10,ce=16,de=100,te=[608135816,2242054355,320440878,57701188,2752067618,698298832,137296536,3964562569,1160258022,953160567,3193202383,887688300,3232508343,3380367581,1065670069,3041331479,2450970073,2306472731],ue=[3509652390,2564797868,805139163,3491422135,3101798381,1780907670,3128725573,4046225305,614570311,3012652279,134345442,2240740374,1667834072,1901547113,2757295779,4103290238,227898511,1921955416,1904987480,2182433518,2069144605,3260701109,2620446009,720527379,3318853667,677414384,3393288472,3101374703,2390351024,1614419982,1822297739,2954791486,3608508353,3174124327,2024746970,1432378464,3864339955,2857741204,1464375394,1676153920,1439316330,715854006,3033291828,289532110,2706671279,2087905683,3018724369,1668267050,732546397,1947742710,3462151702,2609353502,2950085171,1814351708,2050118529,680887927,999245976,1800124847,3300911131,1713906067,1641548236,4213287313,1216130144,1575780402,4018429277,3917837745,3693486850,3949271944,596196993,3549867205,258830323,2213823033,772490370,2760122372,1774776394,2652871518,566650946,4142492826,1728879713,2882767088,1783734482,3629395816,2517608232,2874225571,1861159788,326777828,3124490320,2130389656,2716951837,967770486,1724537150,2185432712,2364442137,1164943284,2105845187,998989502,3765401048,2244026483,1075463327,1455516326,1322494562,910128902,469688178,1117454909,936433444,3490320968,3675253459,1240580251,122909385,2157517691,634681816,4142456567,3825094682,3061402683,2540495037,79693498,3249098678,1084186820,1583128258,426386531,1761308591,1047286709,322548459,995290223,1845252383,2603652396,3431023940,2942221577,3202600964,3727903485,1712269319,422464435,3234572375,1170764815,3523960633,3117677531,1434042557,442511882,3600875718,1076654713,1738483198,4213154764,2393238008,3677496056,1014306527,4251020053,793779912,2902807211,842905082,4246964064,1395751752,1040244610,2656851899,3396308128,445077038,3742853595,3577915638,679411651,2892444358,2354009459,1767581616,3150600392,3791627101,3102740896,284835224,4246832056,1258075500,768725851,2589189241,3069724005,3532540348,1274779536,3789419226,2764799539,1660621633,3471099624,4011903706,913787905,3497959166,737222580,2514213453,2928710040,3937242737,1804850592,3499020752,2949064160,2386320175,2390070455,2415321851,4061277028,2290661394,2416832540,1336762016,1754252060,3520065937,3014181293,791618072,3188594551,3933548030,2332172193,3852520463,3043980520,413987798,3465142937,3030929376,4245938359,2093235073,3534596313,375366246,2157278981,2479649556,555357303,3870105701,2008414854,3344188149,4221384143,3956125452,2067696032,3594591187,2921233993,2428461,544322398,577241275,1471733935,610547355,4027169054,1432588573,1507829418,2025931657,3646575487,545086370,48609733,2200306550,1653985193,298326376,1316178497,3007786442,2064951626,458293330,2589141269,3591329599,3164325604,727753846,2179363840,146436021,1461446943,4069977195,705550613,3059967265,3887724982,4281599278,3313849956,1404054877,2845806497,146425753,1854211946,1266315497,3048417604,3681880366,3289982499,290971e4,1235738493,2632868024,2414719590,3970600049,1771706367,1449415276,3266420449,422970021,1963543593,2690192192,3826793022,1062508698,1531092325,1804592342,2583117782,2714934279,4024971509,1294809318,4028980673,1289560198,2221992742,1669523910,35572830,157838143,1052438473,1016535060,1802137761,1753167236,1386275462,3080475397,2857371447,1040679964,2145300060,2390574316,1461121720,2956646967,4031777805,4028374788,33600511,2920084762,1018524850,629373528,3691585981,3515945977,2091462646,2486323059,586499841,988145025,935516892,3367335476,2599673255,2839830854,265290510,3972581182,2759138881,3795373465,1005194799,847297441,406762289,1314163512,1332590856,1866599683,4127851711,750260880,613907577,1450815602,3165620655,3734664991,3650291728,3012275730,3704569646,1427272223,778793252,1343938022,2676280711,2052605720,1946737175,3164576444,3914038668,3967478842,3682934266,1661551462,3294938066,4011595847,840292616,3712170807,616741398,312560963,711312465,1351876610,322626781,1910503582,271666773,2175563734,1594956187,70604529,3617834859,1007753275,1495573769,4069517037,2549218298,2663038764,504708206,2263041392,3941167025,2249088522,1514023603,1998579484,1312622330,694541497,2582060303,2151582166,1382467621,776784248,2618340202,3323268794,2497899128,2784771155,503983604,4076293799,907881277,423175695,432175456,1378068232,4145222326,3954048622,3938656102,3820766613,2793130115,2977904593,26017576,3274890735,3194772133,1700274565,1756076034,4006520079,3677328699,720338349,1533947780,354530856,688349552,3973924725,1637815568,332179504,3949051286,53804574,2852348879,3044236432,1282449977,3583942155,3416972820,4006381244,1617046695,2628476075,3002303598,1686838959,431878346,2686675385,1700445008,1080580658,1009431731,832498133,3223435511,2605976345,2271191193,2516031870,1648197032,4164389018,2548247927,300782431,375919233,238389289,3353747414,2531188641,2019080857,1475708069,455242339,2609103871,448939670,3451063019,1395535956,2413381860,1841049896,1491858159,885456874,4264095073,4001119347,1565136089,3898914787,1108368660,540939232,1173283510,2745871338,3681308437,4207628240,3343053890,4016749493,1699691293,1103962373,3625875870,2256883143,3830138730,1031889488,3479347698,1535977030,4236805024,3251091107,2132092099,1774941330,1199868427,1452454533,157007616,2904115357,342012276,595725824,1480756522,206960106,497939518,591360097,863170706,2375253569,3596610801,1814182875,2094937945,3421402208,1082520231,3463918190,2785509508,435703966,3908032597,1641649973,2842273706,3305899714,1510255612,2148256476,2655287854,3276092548,4258621189,236887753,3681803219,274041037,1734335097,3815195456,3317970021,1899903192,1026095262,4050517792,356393447,2410691914,3873677099,3682840055,3913112168,2491498743,4132185628,2489919796,1091903735,1979897079,3170134830,3567386728,3557303409,857797738,1136121015,1342202287,507115054,2535736646,337727348,3213592640,1301675037,2528481711,1895095763,1721773893,3216771564,62756741,2142006736,835421444,2531993523,1442658625,3659876326,2882144922,676362277,1392781812,170690266,3921047035,1759253602,3611846912,1745797284,664899054,1329594018,3901205900,3045908486,2062866102,2865634940,3543621612,3464012697,1080764994,553557557,3656615353,3996768171,991055499,499776247,1265440854,648242737,3940784050,980351604,3713745714,1749149687,3396870395,4211799374,3640570775,1161844396,3125318951,1431517754,545492359,4268468663,3499529547,1437099964,2702547544,3433638243,2581715763,2787789398,1060185593,1593081372,2418618748,4260947970,69676912,2159744348,86519011,2512459080,3838209314,1220612927,3339683548,133810670,1090789135,1078426020,1569222167,845107691,3583754449,4072456591,1091646820,628848692,1613405280,3757631651,526609435,236106946,48312990,2942717905,3402727701,1797494240,859738849,992217954,4005476642,2243076622,3870952857,3732016268,765654824,3490871365,2511836413,1685915746,3888969200,1414112111,2273134842,3281911079,4080962846,172450625,2569994100,980381355,4109958455,2819808352,2716589560,2568741196,3681446669,3329971472,1835478071,660984891,3704678404,4045999559,3422617507,3040415634,1762651403,1719377915,3470491036,2693910283,3642056355,3138596744,1364962596,2073328063,1983633131,926494387,3423689081,2150032023,4096667949,1749200295,3328846651,309677260,2016342300,1779581495,3079819751,111262694,1274766160,443224088,298511866,1025883608,3806446537,1145181785,168956806,3641502830,3584813610,1689216846,3666258015,3200248200,1692713982,2646376535,4042768518,1618508792,1610833997,3523052358,4130873264,2001055236,3610705100,2202168115,4028541809,2961195399,1006657119,2006996926,3186142756,1430667929,3210227297,1314452623,4074634658,4101304120,2273951170,1399257539,3367210612,3027628629,1190975929,2062231137,2333990788,2221543033,2438960610,1181637006,548689776,2362791313,3372408396,3104550113,3145860560,296247880,1970579870,3078560182,3769228297,1714227617,3291629107,3898220290,166772364,1251581989,493813264,448347421,195405023,2709975567,677966185,3703036547,1463355134,2715995803,1338867538,1343315457,2802222074,2684532164,233230375,2599980071,2000651841,3277868038,1638401717,4028070440,3237316320,6314154,819756386,300326615,590932579,1405279636,3267499572,3150704214,2428286686,3959192993,3461946742,1862657033,1266418056,963775037,2089974820,2263052895,1917689273,448879540,3550394620,3981727096,150775221,3627908307,1303187396,508620638,2975983352,2726630617,1817252668,1876281319,1457606340,908771278,3720792119,3617206836,2455994898,1729034894,1080033504,976866871,3556439503,2881648439,1522871579,1555064734,1336096578,3548522304,2579274686,3574697629,3205460757,3593280638,3338716283,3079412587,564236357,2993598910,1781952180,1464380207,3163844217,3332601554,1699332808,1393555694,1183702653,3581086237,1288719814,691649499,2847557200,2895455976,3193889540,2717570544,1781354906,1676643554,2592534050,3230253752,1126444790,2770207658,2633158820,2210423226,2615765581,2414155088,3127139286,673620729,2805611233,1269405062,4015350505,3341807571,4149409754,1057255273,2012875353,2162469141,2276492801,2601117357,993977747,3918593370,2654263191,753973209,36408145,2530585658,25011837,3520020182,2088578344,530523599,2918365339,1524020338,1518925132,3760827505,3759777254,1202760957,3985898139,3906192525,674977740,4174734889,2031300136,2019492241,3983892565,4153806404,3822280332,352677332,2297720250,60907813,90501309,3286998549,1016092578,2535922412,2839152426,457141659,509813237,4120667899,652014361,1966332200,2975202805,55981186,2327461051,676427537,3255491064,2882294119,3433927263,1307055953,942726286,933058658,2468411793,3933900994,4215176142,1361170020,2001714738,2830558078,3274259782,1222529897,1679025792,2729314320,3714953764,1770335741,151462246,3013232138,1682292957,1483529935,471910574,1539241949,458788160,3436315007,1807016891,3718408830,978976581,1043663428,3165965781,1927990952,4200891579,2372276910,3208408903,3533431907,1412390302,2931980059,4132332400,1947078029,3881505623,4168226417,2941484381,1077988104,1320477388,886195818,18198404,3786409e3,2509781533,112762804,3463356488,1866414978,891333506,18488651,661792760,1628790961,3885187036,3141171499,876946877,2693282273,1372485963,791857591,2686433993,3759982718,3167212022,3472953795,2716379847,445679433,3561995674,3504004811,3574258232,54117162,3331405415,2381918588,3769707343,4154350007,1140177722,4074052095,668550556,3214352940,367459370,261225585,2610173221,4209349473,3468074219,3265815641,314222801,3066103646,3808782860,282218597,3406013506,3773591054,379116347,1285071038,846784868,2669647154,3771962079,3550491691,2305946142,453669953,1268987020,3317592352,3279303384,3744833421,2610507566,3859509063,266596637,3847019092,517658769,3462560207,3443424879,370717030,4247526661,2224018117,4143653529,4112773975,2788324899,2477274417,1456262402,2901442914,1517677493,1846949527,2295493580,3734397586,2176403920,1280348187,1908823572,3871786941,846861322,1172426758,3287448474,3383383037,1655181056,3139813346,901632758,1897031941,2986607138,3066810236,3447102507,1393639104,373351379,950779232,625454576,3124240540,4148612726,2007998917,544563296,2244738638,2330496472,2058025392,1291430526,424198748,50039436,29584100,3605783033,2429876329,2791104160,1057563949,3255363231,3075367218,3463963227,1469046755,985887462],le=[1332899944,1700884034,1701343084,1684370003,1668446532,1869963892];function z(x,p,l,u){var d,h=x[p],m=x[p+1];return h^=l[0],d=u[h>>>24],d+=u[256|h>>16&255],d^=u[512|h>>8&255],d+=u[768|h&255],m^=d^l[1],d=u[m>>>24],d+=u[256|m>>16&255],d^=u[512|m>>8&255],d+=u[768|m&255],h^=d^l[2],d=u[h>>>24],d+=u[256|h>>16&255],d^=u[512|h>>8&255],d+=u[768|h&255],m^=d^l[3],d=u[m>>>24],d+=u[256|m>>16&255],d^=u[512|m>>8&255],d+=u[768|m&255],h^=d^l[4],d=u[h>>>24],d+=u[256|h>>16&255],d^=u[512|h>>8&255],d+=u[768|h&255],m^=d^l[5],d=u[m>>>24],d+=u[256|m>>16&255],d^=u[512|m>>8&255],d+=u[768|m&255],h^=d^l[6],d=u[h>>>24],d+=u[256|h>>16&255],d^=u[512|h>>8&255],d+=u[768|h&255],m^=d^l[7],d=u[m>>>24],d+=u[256|m>>16&255],d^=u[512|m>>8&255],d+=u[768|m&255],h^=d^l[8],d=u[h>>>24],d+=u[256|h>>16&255],d^=u[512|h>>8&255],d+=u[768|h&255],m^=d^l[9],d=u[m>>>24],d+=u[256|m>>16&255],d^=u[512|m>>8&255],d+=u[768|m&255],h^=d^l[10],d=u[h>>>24],d+=u[256|h>>16&255],d^=u[512|h>>8&255],d+=u[768|h&255],m^=d^l[11],d=u[m>>>24],d+=u[256|m>>16&255],d^=u[512|m>>8&255],d+=u[768|m&255],h^=d^l[12],d=u[h>>>24],d+=u[256|h>>16&255],d^=u[512|h>>8&255],d+=u[768|h&255],m^=d^l[13],d=u[m>>>24],d+=u[256|m>>16&255],d^=u[512|m>>8&255],d+=u[768|m&255],h^=d^l[14],d=u[h>>>24],d+=u[256|h>>16&255],d^=u[512|h>>8&255],d+=u[768|h&255],m^=d^l[15],d=u[m>>>24],d+=u[256|m>>16&255],d^=u[512|m>>8&255],d+=u[768|m&255],h^=d^l[16],x[p]=m^l[ce+1],x[p+1]=h,x}function L(x,p){for(var l=0,u=0;l<4;++l)u=u<<8|x[p]&255,p=(p+1)%x.length;return{key:u,offp:p}}function X(x,p,l){for(var u=0,d=[0,0],h=p.length,m=l.length,Z,k=0;k<h;k++)Z=L(x,u),u=Z.offp,p[k]=p[k]^Z.key;for(k=0;k<h;k+=2)d=z(d,0,p,l),p[k]=d[0],p[k+1]=d[1];for(k=0;k<m;k+=2)d=z(d,0,p,l),l[k]=d[0],l[k+1]=d[1]}function ge(x,p,l,u){for(var d=0,h=[0,0],m=l.length,Z=u.length,k,A=0;A<m;A++)k=L(p,d),d=k.offp,l[A]=l[A]^k.key;for(d=0,A=0;A<m;A+=2)k=L(x,d),d=k.offp,h[0]^=k.key,k=L(x,d),d=k.offp,h[1]^=k.key,h=z(h,0,l,u),l[A]=h[0],l[A+1]=h[1];for(A=0;A<Z;A+=2)k=L(x,d),d=k.offp,h[0]^=k.key,k=L(x,d),d=k.offp,h[1]^=k.key,h=z(h,0,l,u),u[A]=h[0],u[A+1]=h[1]}function me(x,p,l,u,d){var h=le.slice(),m=h.length,Z;if(l<4||l>31)if(Z=Error("Illegal number of rounds (4-31): "+l),u){o(u.bind(this,Z));return}else throw Z;if(p.length!==M)if(Z=Error("Illegal salt length: "+p.length+" != "+M),u){o(u.bind(this,Z));return}else throw Z;l=1<<l>>>0;var k,A,S=0,N;Int32Array?(k=new Int32Array(te),A=new Int32Array(ue)):(k=te.slice(),A=ue.slice()),ge(p,x,k,A);function V(){if(d&&d(S/l),S<l)for(var ye=Date.now();S<l&&(S=S+1,X(x,k,A),X(p,k,A),!(Date.now()-ye>de)););else{for(S=0;S<64;S++)for(N=0;N<m>>1;N++)z(h,N<<1,k,A);var $=[];for(S=0;S<m;S++)$.push((h[S]>>24&255)>>>0),$.push((h[S]>>16&255)>>>0),$.push((h[S]>>8&255)>>>0),$.push((h[S]&255)>>>0);if(u){u(null,$);return}else return $}u&&o(V)}if(typeof u<"u")V();else for(var Ie;;)if(typeof(Ie=V())<"u")return Ie||[]}function fe(x,p,l,u){var d;if(typeof x!="string"||typeof p!="string")if(d=Error("Invalid string / salt: Not a string"),l){o(l.bind(this,d));return}else throw d;var h,m;if(p.charAt(0)!=="$"||p.charAt(1)!=="2")if(d=Error("Invalid salt version: "+p.substring(0,2)),l){o(l.bind(this,d));return}else throw d;if(p.charAt(2)==="$")h="\0",m=3;else{if(h=p.charAt(2),h!=="a"&&h!=="b"&&h!=="y"||p.charAt(3)!=="$")if(d=Error("Invalid salt revision: "+p.substring(2,4)),l){o(l.bind(this,d));return}else throw d;m=4}if(p.charAt(m+2)>"$")if(d=Error("Missing salt rounds"),l){o(l.bind(this,d));return}else throw d;var Z=parseInt(p.substring(m,m+1),10)*10,k=parseInt(p.substring(m+1,m+2),10),A=Z+k,S=p.substring(m+3,m+25);x+=h>="a"?"\0":"";var N=c(x),V=R(S,M);function Ie(ye){var $=[];return $.push("$2"),h>="a"&&$.push(h),$.push("$"),A<10&&$.push("0"),$.push(A.toString()),$.push("$"),$.push(C(V,V.length)),$.push(C(ye,le.length*4-1)),$.join("")}if(typeof l>"u")return Ie(me(N,V,A));me(N,V,A,function(ye,$){ye?l(ye,null):l(null,Ie($))},u)}return e.encodeBase64=C,e.decodeBase64=R,e})})(Pt);var Ga=Pt.exports;const ht=Ba(Ga);function Ja(n){return async(e,t)=>{const a=await n.selectFrom("passwords").where("passwords.tenant_id","=",e).where("passwords.user_id","=",t.user_id).selectAll().executeTakeFirst();return a?ht.compareSync(t.password,a.password)?{valid:!0,message:""}:{valid:!1,message:"Incorrect password"}:{valid:!1,message:"No password exists"}}}function Ya(n){return async(e,t)=>{const a=ht.hashSync(t.password,10);await n.insertInto("passwords").values({tenant_id:e,user_id:t.user_id,password:a,created_at:new Date().toISOString(),updated_at:new Date().toISOString()}).execute()}}function Xa(n){return async(e,t)=>{const a=ht.hashSync(t.password,10);return(await n.updateTable("passwords").set({password:a,updated_at:new Date().toISOString()}).where("tenant_id","=",e).where("user_id","=",t.user_id).execute()).length===1}}function er(n){return{create:Ya(n),update:Xa(n),validate:Ja(n)}}function tr(n){return async(e,t)=>{const a=new Date().toISOString();return(await n.selectFrom("codes").where("codes.tenant_id","=",e).where("codes.user_id","=",t).where("codes.used_at","is",null).where("codes.expires_at",">",a).selectAll().execute()).map(i=>{const{tenant_id:o,...c}=i;return c})}}function nr(n){return async(e,t)=>{await n.insertInto("codes").values({...t,tenant_id:e}).execute()}}function ar(n){return{create:nr(n),list:tr(n)}}function rr(n){return async e=>{const t=new Date().toISOString(),a=await n.selectFrom("universal_login_sessions").where("universal_login_sessions.expires_at",">",t).where("universal_login_sessions.id","=",e).selectAll().executeTakeFirst();if(!a)return null;const{response_type:r,response_mode:i,redirect_uri:o,audience:c,state:f,nonce:_,scope:y,code_challenge_method:C,code_challenge:R,username:Y,vendor_id:M,...B}=a;return{...B,authParams:{client_id:B.client_id,vendor_id:M,response_type:r,response_mode:i,redirect_uri:o,audience:c,state:f,nonce:_,scope:y,code_challenge_method:C,code_challenge:R,username:Y}}}}function sr(n){return async(e,t)=>{const{authParams:a,...r}=t,i={created_at:new Date().toISOString(),updated_at:new Date().toISOString()};return await n.insertInto("universal_login_sessions").values({...a,...r,...i,tenant_id:e}).execute(),{...t,...i}}}function ir(n){return async(e,t,a)=>{const{authParams:r,...i}=a;return(await n.updateTable("universal_login_sessions").set({...r,...i}).where("id","=",t).where("tenant_id","=",e).execute()).length===1}}function or(n){return{create:sr(n),get:rr(n),update:ir(n)}}function cr(n){return async(e,t)=>{const a={created_at:new Date().toISOString(),updated_at:new Date().toISOString(),...t,disable_sign_ups:t.disable_sign_ups?1:0};return await n.insertInto("applications").values({...a,tenant_id:e}).execute(),a}}function dr(n){return async e=>({applications:await n.selectFrom("applications").where("applications.tenant_id","=",e).selectAll().execute()})}function ur(n){return async(e,t)=>{const a=await n.selectFrom("applications").where("applications.tenant_id","=",e).where("applications.id","=",t).selectAll().executeTakeFirst();return a?(a.disable_sign_ups=!!a.disable_sign_ups,U(a)):null}}function lr(n){return async(e,t)=>(await n.deleteFrom("applications").where("applications.tenant_id","=",e).where("applications.id","=",t).executeTakeFirst()).numDeletedRows>0}function fr(n){return async(e,t,a)=>{const r={...a,updated_at:new Date().toISOString()};return await n.updateTable("connections").set(r).where("connections.id","=",t).where("connections.tenant_id","=",e).execute(),!0}}function pr(n){return{create:cr(n),list:dr(n),get:ur(n),remove:lr(n),update:fr(n)}}function xr(n){return async(e,t)=>{const a={id:Ke(),...t,created_at:new Date().toISOString(),updated_at:new Date().toISOString()};return await n.insertInto("connections").values({...a,tenant_id:e}).execute(),a}}function hr(n){return async(e,t)=>{let a=n.selectFrom("connections").where("connections.tenant_id","=",e);t.q&&(a=Oe(n,a,t.q,["user_id","ip"]));const i=await a.offset(t.page*t.per_page).limit(t.per_page).selectAll().execute(),{count:o}=await a.select(c=>c.fn.countAll().as("count")).executeTakeFirstOrThrow();return{connections:i.map(U),start:t.page*t.per_page,limit:t.per_page,length:_e(o)}}}function _r(n){return async(e,t)=>(await n.deleteFrom("connections").where("connections.tenant_id","=",e).where("connections.id","=",t).executeTakeFirst()).numDeletedRows>0}function gr(n){return async(e,t)=>{const a=await n.selectFrom("connections").where("connections.tenant_id","=",e).where("connections.id","=",t).selectAll().executeTakeFirst();return a?U(a):null}}function mr(n){return async(e,t,a)=>{const r={...a,updated_at:new Date().toISOString()};return await n.updateTable("connections").set(r).where("connections.id","=",t).where("connections.tenant_id","=",e).execute(),!0}}function yr(n){return{create:xr(n),get:gr(n),list:hr(n),remove:_r(n),update:mr(n)}}function rt(n){return n!=null&&n.length?n.split(",").map(e=>e.trim()):[]}function br(n){return{get:async e=>{const t=await n.selectFrom("applications").selectAll().where("id","=",e).executeTakeFirst();if(!t)throw new Ae(404,{message:"Client not found"});const a=await n.selectFrom("tenants").selectAll().where("id","=",t.tenant_id).executeTakeFirst();if(!a)throw new Ae(404,{message:"Tenant not found"});const r=await n.selectFrom("connections").where("tenant_id","=",t.tenant_id).selectAll().execute(),i=await n.selectFrom("domains").where("tenant_id","=",t.tenant_id).selectAll().execute();return{id:t.id,name:t.name,connections:r.map(c=>ft.parse(U(c))),domains:i,tenant_id:a.id,allowed_callback_urls:rt(t.allowed_callback_urls),allowed_logout_urls:rt(t.allowed_logout_urls),allowed_web_origins:rt(t.allowed_web_origins),email_validation:t.email_validation,client_secret:t.client_secret,tenant:U(a),disable_sign_ups:!!t.disable_sign_ups}}}}function vr(n){return async()=>await n.selectFrom("keys").where("revoked_at","is",null).selectAll().execute()}function wr(n){return async e=>{await n.insertInto("keys").values(e).execute()}}function kr(n){return async(e,t)=>!!(await n.updateTable("keys").set({revoked_at:t.toISOString()}).where("kid","=",e).execute()).length}function Tr(n){return{create:wr(n),list:vr(n),revoke:kr(n)}}function Or(n){return async(e,t)=>{const a={created_at:new Date().toISOString(),updated_at:new Date().toISOString(),tenant_id:e,id:Ke(),...t};return await n.insertInto("domains").values(a).execute(),a}}function Ir(n){return async(e,t)=>{let a=n.selectFrom("domains").where("domains.tenant_id","=",e);t.q&&(a=Oe(n,a,t.q,["user_id","ip"]));const i=await a.offset(t.page*t.per_page).limit(t.per_page).selectAll().execute(),{count:o}=await a.select(c=>c.fn.countAll().as("count")).executeTakeFirstOrThrow();return{domains:i,start:t.page*t.per_page,limit:t.per_page,length:_e(o)}}}function jr(n){return{create:Or(n),list:Ir(n)}}function Zr(n){return async e=>{const[t]=await n.selectFrom("branding").where("branding.tenant_id","=",e).selectAll().execute();if(!t)return null;const{tenant_id:a,colors_primary:r,colors_page_background_type:i,colors_page_background_start:o,colors_page_background_end:c,colors_page_background_angle_dev:f,font_url:_,...y}=t;return U({...y,colors:{primary:r,page_background:{type:i,start:o,end:c,angle_deg:f}},font:_?{url:_}:void 0})}}function Er(n){return async(e,t)=>{var o,c,f,_,y,C,R,Y,M,B,ce,de,te,ue,le,z,L,X;const{colors:a,font:r,...i}=t;try{await n.insertInto("branding").values({...i,colors_primary:a==null?void 0:a.primary,colors_page_background_type:(c=(o=t.colors)==null?void 0:o.page_background)==null?void 0:c.type,colors_page_background_start:(_=(f=t.colors)==null?void 0:f.page_background)==null?void 0:_.start,colors_page_background_end:(C=(y=t.colors)==null?void 0:y.page_background)==null?void 0:C.end,colors_page_background_angle_dev:(Y=(R=t.colors)==null?void 0:R.page_background)==null?void 0:Y.angle_deg,font_url:(M=t.font)==null?void 0:M.url,tenant_id:e}).execute()}catch{await n.updateTable("branding").set({...i,colors_primary:a==null?void 0:a.primary,colors_page_background_type:(ce=(B=t.colors)==null?void 0:B.page_background)==null?void 0:ce.type,colors_page_background_start:(te=(de=t.colors)==null?void 0:de.page_background)==null?void 0:te.start,colors_page_background_end:(le=(ue=t.colors)==null?void 0:ue.page_background)==null?void 0:le.end,colors_page_background_angle_dev:(L=(z=t.colors)==null?void 0:z.page_background)==null?void 0:L.angle_deg,font_url:(X=t.font)==null?void 0:X.url}).where("tenant_id","=",e).execute()}}}function Ar(n){return{get:Zr(n),set:Er(n)}}function Cr(n){return async(e,t)=>{const a=await n.selectFrom("authentication_codes").where("tenant_id","=",e).where("code","=",t).selectAll().executeTakeFirst();if(!a)throw new Ae(403,{message:"Code not found or expired"});const{state:r,nonce:i,scope:o,client_id:c,response_type:f,response_mode:_,...y}=a;return{...y,authParams:{state:r,nonce:i,scope:o,client_id:c,response_type:f,response_mode:_}}}}function Sr(n){return async(e,t)=>{const{authParams:a,...r}=t;await n.insertInto("authentication_codes").values({...r,...a,tenant_id:e}).execute()}}function Fr(n){return{create:Sr(n),get:Cr(n)}}function Nr(n){return async(e,t)=>{let a=n.selectFrom("hooks").where("hooks.tenant_id","=",e);t.q&&(a=Oe(n,a,t.q,["url"]));const i=await a.offset(t.page*t.per_page).limit(t.per_page).selectAll().execute(),{count:o}=await a.select(f=>f.fn.countAll().as("count")).executeTakeFirstOrThrow();return{hooks:i.map(f=>{const{tenant_id:_,enabled:y,...C}=f;return U({...C,enabled:!!y})}),start:t.page*t.per_page,limit:t.per_page,length:_e(o)}}}function $r(n){return async(e,t)=>{const a=await n.selectFrom("hooks").where("hooks.tenant_id","=",e).where("hooks.hook_id","=",t).selectAll().executeTakeFirst();return a?(a.enabled=!!a.enabled,U(a)):null}}function Rr(n){return async(e,t)=>(await n.deleteFrom("hooks").where("hooks.tenant_id","=",e).where("hooks.hook_id","=",t).executeTakeFirst()).numDeletedRows>0}function Dr(n){return async(e,t)=>{const a={hook_id:Ke(),...t,created_at:new Date().toISOString(),updated_at:new Date().toISOString()};return await n.insertInto("hooks").values({...a,tenant_id:e}).execute(),a}}function Pr(n){return async(e,t,a)=>{const r={...a,updated_at:new Date().toISOString()};return await n.updateTable("hooks").set(r).where("hooks.hook_id","=",t).where("hooks.tenant_id","=",e).execute(),!0}}function Ur(n){return{create:Dr(n),get:$r(n),list:Nr(n),update:Pr(n),remove:Rr(n)}}function Mr(n){return{applications:pr(n),authenticationCodes:Fr(n),branding:Ar(n),clients:br(n),keys:Tr(n),users:_a(n),sessions:Na(n),tenants:ka(n),tickets:Pa(n),universalLoginSessions:or(n),OTP:qa(n),logs:Za(n),passwords:er(n),codes:ar(n),connections:yr(n),domains:jr(n),hooks:Ur(n)}}module.exports=Mr;
|