@k-msg/template 0.30.0 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1,4 @@
1
+ var{defineProperty:ce,getOwnPropertyNames:Mt,getOwnPropertyDescriptor:Ot}=Object,Nt=Object.prototype.hasOwnProperty;function Lt(e){return this[e]}var Dt=(e)=>{var t=(Ae??=new WeakMap).get(e),r;if(t)return t;if(t=ce({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function"){for(var n of Mt(e))if(!Nt.call(t,n))ce(t,n,{get:Lt.bind(e,n),enumerable:!(r=Ot(e,n))||r.enumerable})}return Ae.set(e,t),t},Ae;var Ft=(e)=>e;function Ut(e,t){this[e]=Ft.bind(null,t)}var Vt=(e,t)=>{for(var r in t)ce(e,r,{get:t[r],enumerable:!0,configurable:!0,set:Ut.bind(t,r)})};var Nr={};Vt(Nr,{ButtonParser:()=>b,TemplateCategory:()=>oe,TemplateLifecycleService:()=>ke,TemplatePersonalizer:()=>se,TemplateStatus:()=>ie,TemplateType:()=>we,TemplateValidator:()=>w,TemplateVariableUtils:()=>Ct,VariableParser:()=>T,defaultTemplatePersonalizer:()=>V,interpolate:()=>Ze,parseTemplateButtons:()=>Pe,validateTemplatePayload:()=>G});module.exports=Dt(Nr);function Ze(e,t){if(!e)return"";if(!t)return e;return e.replace(/#\{([^}]+)\}/g,(r,n)=>{let o=t[n];if(o===void 0||o===null)return r;return String(o)})}class b{static validateButtons(e){let t=[];if(e.length>5)t.push("Maximum 5 buttons are allowed");for(let r=0;r<e.length;r++){let n=e[r],o=r+1;if(!n.name||n.name.trim().length===0)t.push(`Button ${o}: name is required`);else if(n.name.length>14)t.push(`Button ${o}: name cannot exceed 14 characters`);b.validateButtonByType(n,o,t)}return{isValid:t.length===0,errors:t}}static validateButtonByType(e,t,r){switch(e.type){case"WL":b.validateWebLinkButton(e,t,r);break;case"AL":b.validateAppLinkButton(e,t,r);break;case"DS":b.validateDeliveryButton(e,t,r);break;case"BK":b.validateBotKeywordButton(e,t,r);break;case"MD":b.validateMessageDeliveryButton(e,t,r);break;default:r.push(`Button ${t}: invalid button type '${e.type}'`)}}static validateWebLinkButton(e,t,r){if(!e.linkMobile&&!e.linkPc)r.push(`Button ${t}: web link button must have at least mobile or PC link`);if(e.linkMobile&&!b.isValidUrl(e.linkMobile))r.push(`Button ${t}: invalid mobile link URL`);if(e.linkPc&&!b.isValidUrl(e.linkPc))r.push(`Button ${t}: invalid PC link URL`)}static validateAppLinkButton(e,t,r){if(!(e.linkIos||e.linkAndroid||e.schemeIos||e.schemeAndroid))r.push(`Button ${t}: app link button must have at least one app link or scheme`);if(e.linkIos&&!b.isValidUrl(e.linkIos))r.push(`Button ${t}: invalid iOS link URL`);if(e.linkAndroid&&!b.isValidUrl(e.linkAndroid))r.push(`Button ${t}: invalid Android link URL`)}static validateDeliveryButton(e,t,r){}static validateBotKeywordButton(e,t,r){}static validateMessageDeliveryButton(e,t,r){}static isValidUrl(e){try{return new URL(e),!0}catch{return!1}}static serializeButtons(e){let t=e.map((r)=>({name:r.name,type:r.type,url_mobile:r.linkMobile,url_pc:r.linkPc,url_ios:r.linkIos,url_android:r.linkAndroid,scheme_ios:r.schemeIos,scheme_android:r.schemeAndroid}));return JSON.stringify(t)}static deserializeButtons(e){try{return JSON.parse(e).map((r)=>({name:r.name,type:r.type,linkMobile:r.url_mobile,linkPc:r.url_pc,linkIos:r.url_ios,linkAndroid:r.url_android,schemeIos:r.scheme_ios,schemeAndroid:r.scheme_android}))}catch(t){throw Error(`Failed to parse buttons JSON: ${t}`)}}}function pe(e){let t=Object.values(e).filter((n)=>typeof n==="number");return Object.entries(e).filter(([n,o])=>t.indexOf(+n)===-1).map(([n,o])=>o)}function Ce(e,t){if(typeof t==="bigint")return t.toString();return t}class Se{constructor(e){this._getter=e,this._value=void 0}get value(){let e=this._getter;if(e!==void 0)this._value=e(),this._getter=void 0;return this._value}}function Ie(e){return new Se(e)}function Me(e){return e===null||e===void 0}function Oe(e){let t=e.startsWith("^")?1:0,r=e.endsWith("$")?e.length-1:e.length;return e.slice(t,r)}function Ne(e,t,r){Object.defineProperty(e,t,{value:r,writable:!0,enumerable:!0,configurable:!0})}var de="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function Le(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var De=new Set(["string","number","symbol"]);function fe(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function X(e,t,r){let n=new e._zod.constr(t??e._zod.def);if(!t||r?.parent)n._zod.parent=e;return n}function v(e){let t=e;if(!t)return{};if(typeof t==="string")return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}if(delete t.message,typeof t.error==="string")return{...t,error:()=>t.error};return t}function Fe(e){return Object.keys(e).filter((t)=>e[t]._zod.optin!==void 0&&e[t]._zod.optout==="optional")}function C(e,t=0){if(e.aborted===!0)return!0;for(let r=t;r<e.issues.length;r++)if(e.issues[r]?.continue!==!0)return!0;return!1}function Ue(e,t=0){if(e.aborted===!0)return!0;for(let r=t;r<e.issues.length;r++)if(e.issues[r]?.continue===!1)return!0;return!1}function J(e,t){return t.map((r)=>{var n;return(n=r).path??(n.path=[]),r.path.unshift(e),r})}function j(e){return typeof e==="string"?e:e?.message}function me(e,t,r){var n;for(let o=t;o<e.length;o++)(n=e[o]).schema??(n.schema=r)}function L(e,t,r){var n;let o=e.inst?._zod?.traits;if(o?.has("$ZodType"))if(o.has("$ZodCheck"))(n=e).schema??(n.schema=e.inst);else e.schema=e.inst;let i=e.schema!==e.inst?e.schema?._zod.def?.error:void 0,u=e.message?e.message:j(e.inst?._zod.def?.error?.(e))??j(i?.(e))??j(t?.error?.(e))??j(r.customError?.(e))??j(r.localeError?.(e))??"Invalid input",s={};for(let a of Object.keys(e)){if(a==="inst"||a==="schema"||a==="continue"||a==="input"||a==="__proto__")continue;s[a]=e[a]}if(s.path??(s.path=[]),s.message=u,t?.reportInput)s.input=e.input;return s}var Bt=/[\uD800-\uDBFF]/;function Ve(e){let t=e.length;if(!Bt.test(e))return t;let r=t;for(let n=0;n<t-1;n++)if((e.charCodeAt(n)&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320)r--,n++;return r}function Be(e){if(Array.isArray(e))return"array";if(typeof e==="string")return"string";return"unknown"}function je(e,t){for(let r in t){let n=Object.getOwnPropertyDescriptor(t,r);if(n.get)Object.defineProperty(e,r,{...n,enumerable:!1});else jt(e,r,n.value)}}function M(e,t,r,n=!0){return Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:n,value:r}),r}function he(e,t,r){return M(e,t,r,!1)}function jt(e,t,r){Object.defineProperty(e,t,{configurable:!0,get(){return this==null?r:M(this,t,r.bind(this))},set(n){M(this,t,n)}})}function Kt(e,t){let r=Object.getPrototypeOf(e);return t in r?void 0:r}var le,Z=!1,qt={configurable:!0,get(){Z=!0;return}};function D(e,t,r){let n=Object.getPrototypeOf(e._zod);if(t in n&&le!==e._zod){le=void 0;return}le=e._zod,Object.defineProperty(n,t,{configurable:!0,get(){Object.defineProperty(this,t,qt);let o=Z;Z=!1;try{let i=r(this);if(Z)delete this[t];else Object.defineProperty(this,t,{configurable:!0,writable:!0,value:i});return Z=Z||o,i}catch(i){throw delete this[t],Z=Z||o,i}},set(o){Object.defineProperty(this,t,{configurable:!0,writable:!0,value:o})}})}function Ke(e,t,r,n){let o=Kt(e,t);if(!o)return;Object.defineProperty(o,t,{configurable:!0,get(){let i={configurable:!0,writable:!0,enumerable:n,value:void 0};return Object.defineProperty(this,t,i),i.value=r(this),Object.defineProperty(this,t,i),i.value},set(i){Object.defineProperty(this,t,{configurable:!0,writable:!0,enumerable:n,value:i})}})}var qe;var ge={value:void 0,enumerable:!1},We="captureStackTrace"in Error?Error:null;function Wt(e){let t=We;if(t){let r=t.stackTraceLimit;if(typeof r==="number"){try{t.stackTraceLimit=0}catch{return We=null,new e}try{return new e}finally{t.stackTraceLimit=r}}}return new e}function f(e,t,r,n){let o={};function i(d){this.def=d,this.constr=p,this.traits=new Set}i.prototype=o;let u=r,s=u&&new WeakSet;function a(d,h){if(!d._zod){ge.value=new i(h);try{Object.defineProperty(d,"_zod",ge)}finally{ge.value=void 0}}else if(d._zod.traits.has(e))return;if(d._zod.traits.add(e),t(d,h),s){let y=Object.getPrototypeOf(d),z=d._zod.constr.prototype,m=y;while(m&&m!==z)m=Object.getPrototypeOf(m);let N=m??y;if(!s.has(N))s.add(N),je(N,u)}let g=p.prototype;for(let y in g){if(!Object.prototype.hasOwnProperty.call(g,y))continue;if(!(y in d))d[y]=g[y].bind(d)}}let c=n?.Parent??Object;class l extends c{}Object.defineProperty(l,"name",{value:e});function p(d){let h=n?.Parent?Wt(l):this;a(h,d);let g=h._zod.deferred;if(g){for(let z of g)z();h._zod.deferred=void 0}let y=globalThis.__zod_globalConfig?.postProcessor;if(y)y(h);return h}return Object.defineProperty(p,"init",{value:a}),Object.defineProperty(p,Symbol.hasInstance,{value:(d)=>{if(n?.Parent&&d instanceof n.Parent)return!0;return d?._zod?.traits?.has(e)}}),Object.defineProperty(p,"name",{value:e}),p}class S extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}(qe=globalThis).__zod_globalConfig??(qe.__zod_globalConfig={});var K=globalThis.__zod_globalConfig;function F(e){if(e)Object.assign(K,e);return K}function Ht(){let e=this._zod;return e.message??(e.message=JSON.stringify(e.def,Ce,2)),e.message}function Yt(e){this._zod.message=e}var Gt={get:Ht,set:Yt,enumerable:!0,configurable:!0},_e={value:void 0,enumerable:!1},He=new WeakSet([Object.prototype,Error.prototype]),Ye=(e,t)=>{e.name="$ZodError",_e.value=t,Object.defineProperty(e,"issues",_e),_e.value=void 0,Object.defineProperty(e,"message",Gt);let r=Object.getPrototypeOf(e);if(!He.has(r))He.add(r),Object.defineProperty(r,"toString",{configurable:!0,enumerable:!1,get(){let n=()=>this.message;return Object.defineProperty(this,"toString",{value:n,configurable:!0,writable:!0}),n},set(n){Object.defineProperty(this,"toString",{value:n,configurable:!0,writable:!0})}})},Br=f("$ZodError",Ye),q=f("$ZodError",Ye,void 0,{Parent:Error});var Jt=(e)=>{let t=(r,n,o,i)=>{let u=o?{...o,async:!1}:{async:!1},s=r._zod.run({value:n,issues:[]},u);if(s instanceof Promise)throw new S;if(s.issues.length){let a=new(i?.Err??e)(s.issues.map((c)=>L(c,u,F())));throw de(a,i?.callee??t),a}return s.value};return t},be=Jt(q),Qt=(e)=>{let t=async(r,n,o,i)=>{let u=o?{...o,async:!0}:{async:!0},s=r._zod.run({value:n,issues:[]},u);if(s instanceof Promise)s=await s;if(s.issues.length){let a=new(i?.Err??e)(s.issues.map((c)=>L(c,u,F())));throw de(a,i?.callee??t),a}return s.value};return t},xe=Qt(q),er=(e)=>(t,r,n)=>{let o=n?{...n,async:!1}:{async:!1},i=t._zod.run({value:r,issues:[]},o);if(i instanceof Promise)throw new S;return i.issues.length?Ge(e,i.issues,o):{success:!0,data:i.value}},ve=er(q);function Ge(e,t,r){let n;return{success:!1,get error(){if(!n)n=new e(t.map((o)=>L(o,r,F()))),t=void 0,r=void 0;return n},set error(o){n=o,t=void 0,r=void 0}}}var tr=(e)=>async(t,r,n)=>{let o=n?{...n,async:!0}:{async:!0},i=t._zod.run({value:r,issues:[]},o);if(i instanceof Promise)i=await i;return i.issues.length?Ge(e,i.issues,o):{success:!0,data:i.value}},$e=tr(q);var Xe=/^https?$/;var Je=/^[\s\S]{0,}$/;var Qe=/^-?\d+(?:\.\d+)?$/,et=/^(?:true|false)$/i;var U=f("$ZodCheck",(e,t)=>{var r;e._zod??(e._zod={}),e._zod.def=t,(r=e._zod).onattach??(r.onattach=[])});var rr=(e)=>{let t=e.value;return!Me(t)&&t.length!==void 0},rt={number:"number",bigint:"bigint",object:"date"};var nt=f("$ZodCheckGreaterThan",(e,t)=>{U.init(e,t);let r=rt[typeof t.value];e._zod.check=(n)=>{if(t.inclusive?n.value>=t.value:n.value>t.value)return;n.issues.push({origin:rt[typeof n.value]??r,code:"too_small",minimum:typeof t.value==="object"?t.value.getTime():t.value,input:n.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}});var ot=f("$ZodCheckMinLength",(e,t)=>{var r;U.init(e,t),(r=e._zod.def).when??(r.when=rr),e._zod.check=(n)=>{let o=n.value,i=o.length;if((typeof o==="string"&&i>=t.minimum&&i<t.minimum*2?Ve(o):i)>=t.minimum)return;let s=Be(o);n.issues.push({origin:s,code:"too_small",minimum:t.minimum,inclusive:!0,input:o,inst:e,continue:!t.abort})}});var it=f("$ZodCheckStringFormat",(e,t)=>{var r,n;if(U.init(e,t),t.pattern)(r=e._zod).check??(r.check=(o)=>{if(t.pattern.lastIndex=0,t.pattern.test(o.value))return;o.issues.push({origin:"string",code:"invalid_format",format:t.format,input:o.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})});else(n=e._zod).check??(n.check=()=>{})});var ut={major:4,minor:6,patch:5};var P=f("$ZodType",(e,t)=>{var r;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=ut;let n=e._zod.def.checks,o=e._zod.traits.has("$ZodCheck")?[e,...n??[]]:n?.length?[...n]:[];for(let i of o)for(let u of i._zod.onattach)u(e);if(o.length===0)(r=e._zod).deferred??(r.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let i=(s,a,c)=>{if(s.memo)return s;let l=C(s),p;for(let d of a){if(d._zod.def.when){if(Ue(s))continue;if(!d._zod.def.when(s))continue}else if(l)continue;let h=s.issues.length,g=d._zod.check(s);if(g instanceof Promise&&c?.async===!1)throw new S;if(p||g instanceof Promise)p=(p??Promise.resolve()).then(async()=>{if(await g,s.issues.length===h)return;if(me(s.issues,h,e),!l)l=C(s,h)});else{if(s.issues.length===h)continue;if(me(s.issues,h,e),!l)l=C(s,h)}}if(p)return p.then(()=>s);return s},u=(s,a,c)=>{if(C(s))return s.aborted=!0,s;let l=i(a,o,c);if(l instanceof Promise){if(c.async===!1)throw new S;return l.then((p)=>e._zod.parse(p,c))}return e._zod.parse(l,c)};e._zod.run=(s,a)=>{if(a.skipChecks)return e._zod.parse(s,a);if(a.direction==="backward"){let l=e._zod.parse({value:s.value,issues:[]},{...a,skipChecks:!0});if(l instanceof Promise)return l.then((p)=>u(p,s,a));return u(l,s,a)}let c=e._zod.parse(s,a);if(c instanceof Promise){if(a.async===!1)throw new S;return c.then((l)=>i(l,o,a))}return i(c,o,a)}}},{get "~standard"(){return he(this,"~standard",ir(this))},set "~standard"(e){M(this,"~standard",e)}}),pt=(e,t)=>e.issues.length?{issues:e.issues.map((r)=>L(r,t,F()))}:{value:e.value};async function or(e,t){let r={async:!0};return pt(await e._zod.run({value:t,issues:[]},r),r)}function ir(e){return{validate:(t)=>{let r={async:!1};try{let n=e._zod.run({value:t,issues:[]},r);if(!(n instanceof Promise))return pt(n,r)}catch(n){}return or(e,t)},vendor:"zod",version:1}}var Ee=f("$ZodString",(e,t)=>{P.init(e,t),e._zod.pattern=t.pattern??Je,e._zod.parse=(r,n)=>{if(t.coerce)try{r.value=String(r.value)}catch(o){}if(typeof r.value==="string")return r;return r.issues.push({expected:"string",code:"invalid_type",input:r.value,inst:e}),r}}),ze=f("$ZodStringFormat",(e,t)=>{it.init(e,t),Ee.init(e,t)});var dt=1,Q=2;function sr(e){try{if(typeof URL<"u"&&typeof URL.canParse==="function")return URL.canParse(e);return new URL(e),!0}catch{return!1}}function ur(e,t){if(!("normalize"in t)&&!("hostname"in t)&&!("protocol"in t))return sr(e)||Q;return ar(e,t)}function ar(e,t){if(!t.normalize&&t.protocol?.source===Xe.source&&!/^https?:\/\//i.test(e))return dt;try{if(typeof URL<"u"){let r=URL;if(typeof r.parse==="function")return r.parse(e)??Q}return new URL(e)}catch{return Q}}var cr=/[\t\n\r]/g;function at(e){return e.replace(cr,"")}function lr(e,t){return t.lastIndex=0,t.test(e.hostname)}function pr(e,t){return t.lastIndex=0,t.test(e.protocol.endsWith(":")?e.protocol.slice(0,-1):e.protocol)}var ft=f("$ZodURL",(e,t)=>{ze.init(e,t),e._zod.check=(r)=>{try{let n=r.value.trim(),o=ur(n,t);if(o===dt){r.issues.push({code:"invalid_format",format:"url",note:"Invalid URL format",input:r.value,inst:e,continue:!t.abort});return}if(o===Q){r.issues.push({code:"invalid_format",format:"url",input:r.value,inst:e,continue:!t.abort});return}if(o===!0){r.value=at(n);return}if(t.hostname&&!lr(o,t.hostname))r.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:t.hostname.source,input:r.value,inst:e,continue:!t.abort});if(t.protocol&&!pr(o,t.protocol))r.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:r.value,inst:e,continue:!t.abort});r.value=t.normalize?o.href:at(n);return}catch(n){r.issues.push({code:"invalid_format",format:"url",input:r.value,inst:e,continue:!t.abort})}}});var mt=f("$ZodNumber",(e,t)=>{P.init(e,t),e._zod.pattern=Qe,e._zod.parse=(r,n)=>{if(t.coerce)try{r.value=Number(r.value)}catch(u){}let o=r.value;if(typeof o==="number"&&!Number.isNaN(o)&&Number.isFinite(o))return r;let i=typeof o==="number"?Number.isNaN(o)?"NaN":!Number.isFinite(o)?String(o):void 0:void 0;return r.issues.push({expected:"number",code:"invalid_type",input:o,inst:e,...i?{received:i}:{}}),r}});var ht=f("$ZodBoolean",(e,t)=>{P.init(e,t),e._zod.pattern=et,e._zod.parse=(r,n)=>{if(t.coerce)try{r.value=Boolean(r.value)}catch(i){}let o=r.value;if(typeof o==="boolean")return r;return r.issues.push({expected:"boolean",code:"invalid_type",input:o,inst:e}),r}});var gt=f("$ZodDate",(e,t)=>{P.init(e,t),e._zod.parse=(r,n)=>{if(t.coerce)try{r.value=new Date(r.value)}catch(s){}let o=r.value,i=o instanceof Date;if(i&&!Number.isNaN(o.getTime()))return r;return r.issues.push({expected:"date",code:"invalid_type",input:o,...i?{received:"Invalid Date"}:{},inst:e}),r}});function ct(e,t,r){if(e.issues.length)t.issues.push(...J(r,e.issues));t.value[r]=e.value}var yt=f("$ZodArray",(e,t)=>{P.init(e,t);let r=K.memoizer;r?.attach(e),e._zod.parse=(n,o)=>{let i=n.value;if(!Array.isArray(i))return n.issues.push({expected:"array",code:"invalid_type",input:i,inst:e}),n;n.value=r?r.alloc(e,n,Array(i.length),o):Array(i.length);let u=[],s=o?.abortEarly;for(let a=0;a<i.length;a++){let c=i[a],l=t.element._zod.run({value:c,issues:[]},o);if(l instanceof Promise)u.push(l.then((p)=>ct(p,n,a)));else if(ct(l,n,a),s&&l.issues.length!==0&&C(l))break}if(u.length)return Promise.all(u).then(()=>n);return n}});function ee(e,t,r,n,o,i){let u=r in n,s=i==="optional";if(!u&&s&&o==="optional")return;if(e.issues.length){if(o!==void 0&&s&&!u)return;t.issues.push(...J(r,e.issues))}if(!u&&o===void 0){if(!e.issues.length)t.issues.push({code:"invalid_type",expected:"nonoptional",input:void 0,path:[r]});return}if(e.value===void 0){if(u||o==="defaulted"&&!s)t.value[r]=void 0}else t.value[r]=e.value}var dr=[];function fr(e){let t=Object.keys(e.shape),r=Object.getOwnPropertySymbols(e.shape),n=r.length?r:dr,o=n.length?[...t,...n]:t;for(let u of o)if(!e.shape?.[u]?._zod?.traits?.has("$ZodType"))throw Error(`Invalid element at key "${String(u)}": expected a Zod schema`);let i=Fe(e.shape);return{...e,allKeys:o,symbolKeys:n,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(i)}}function mr(e,t,r,n,o,i,u){let s=[],a=o.keySet,c=o.catchall._zod,l=c.def.type,{optin:p,optout:d}=c,h=0;for(let g in t){if(u&&r.issues.length!==h){if(C(r,h))break;h=r.issues.length}if(a.has(g))continue;if(g==="__proto__"){if(l==="never")s.push(g);continue}if(l==="never"){s.push(g);continue}let y=c.run({value:t[g],issues:[]},n);if(y instanceof Promise)e.push(y.then((z)=>ee(z,r,g,t,p,d)));else ee(y,r,g,t,p,d)}if(s.length)r.issues.push({code:"unrecognized_keys",keys:s,input:t,inst:i,continue:!0});if(!e.length)return r;return Promise.all(e).then(()=>r)}var _t=f("$ZodObject",(e,t)=>{P.init(e,t);let r=Object.getOwnPropertyDescriptor(t,"shape"),n=r?.get?r.get.raw:t.shape??{};if(n){let c=()=>{let l={...n};return Object.defineProperty(t,"shape",{value:l}),c.raw=l,l};c.raw=n,Object.defineProperty(t,"shape",{get:c})}let o=Ie(()=>fr(t));D(e,"propValues",(c)=>{let l=c.def.shape,p={};for(let d in l){let h=l[d]._zod;if(h.values){if(!Object.prototype.hasOwnProperty.call(p,d))Ne(p,d,new Set);for(let g of h.values)p[d].add(g);if(h.optin!==void 0)p[d].add(void 0)}}return p});let i=Le,u=t.catchall,s,a=K.memoizer;a?.attach(e),e._zod.parse=(c,l)=>{s??(s=o.value);let p=c.value;if(!i(p))return c.issues.push({expected:"object",code:"invalid_type",input:p,inst:e}),c;c.value=a?a.alloc(e,c,{},l):{};let d=[],h=s.shape,g=l?.abortEarly,y=c.issues.length;for(let z of s.allKeys){if(g&&c.issues.length!==y){if(C(c,y))break;y=c.issues.length}if(z==="__proto__")continue;let m=h[z],N=m._zod.optin,Te=m._zod.optout,ae=m._zod.run({value:p[z],issues:[]},l);if(ae instanceof Promise)d.push(ae.then((It)=>ee(It,c,z,p,N,Te)));else ee(ae,c,z,p,N,Te)}if(!u)return d.length?Promise.all(d).then(()=>c):c;return mr(d,p,c,l,o.value,e,g===!0)}});var bt=f("$ZodEnum",(e,t)=>{P.init(e,t);let r=pe(t.entries),n=new Set(r);e._zod.values=n,D(e,"pattern",(o)=>{let i=pe(o.def.entries).filter((u)=>De.has(typeof u));return new RegExp(i.length?`^(${i.map((u)=>fe(u.toString())).join("|")})$`:"^[^\\s\\S]$")}),e._zod.parse=(o,i)=>{let u=o.value;if(n.has(u))return o;return o.issues.push({code:"invalid_value",values:r,input:u,inst:e}),o}});function lt(e,t){return e.value=t.issues.length?void 0:t.value,e}var xt=f("$ZodOptional",(e,t)=>{P.init(e,t),D(e,"optin",(r)=>r.def.innerType._zod.optin==="defaulted"?"defaulted":"optional"),e._zod.optout="optional",D(e,"values",(r)=>{let n=r.def.innerType._zod.values;return n?new Set([...n,void 0]):void 0}),D(e,"pattern",(r)=>{let n=r.def.innerType._zod.pattern;return n?new RegExp(`^(${Oe(n.source)})?$`):void 0}),e._zod.parse=(r,n)=>{if(r.value===void 0){if(t.innerType._zod.optin!=="defaulted")return r;let o=t.innerType._zod.run({value:r.value,issues:[]},n);if(o instanceof Promise)return o.then((i)=>lt(r,i));return lt(r,o)}return t.innerType._zod.run(r,n)}});function vt(e){if(e.checks)e.checks=[...e.checks];return e}function $t(e,t){return new e(vt({type:"string",...v(t)}))}function Et(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...v(t)})}function zt(e,t){return new e(vt({type:"number",checks:[],...v(t)}))}function wt(e,t){return new e({type:"boolean",...v(t)})}function Rt(e,t){return new e({type:"date",...v(t)})}function W(e,t){return new nt({check:"greater_than",...v(t),value:e,inclusive:!0})}function H(e,t){return new ot({check:"min_length",...v(t),minimum:e})}var I=f("ZodMiniType",(e,t)=>{if(!e._zod)throw Error("Uninitialized schema in ZodMiniType.");P.init(e,t),e.def=t,e.type=t.type},{get with(){return this.check},set with(e){M(this,"with",e)},parse(e,t){return be(this,e,t,{callee:this.parse})},parseAsync(e,t){return xe(this,e,t,{callee:this.parseAsync})},safeParse(e,t){return ve(this,e,t)},safeParseAsync(e,t){return $e(this,e,t)},check(...e){let t=this.def;return this.clone({...t,checks:[...t.checks??[],...e.map((r)=>typeof r==="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]},{parent:!0})},clone(e,t){return X(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},apply(e,...t){return t.length===0?e(this):e(this,...t)}}),Pt=f("ZodMiniString",(e,t)=>{Ee.init(e,t),I.init(e,t)});function E(e){return $t(Pt,e)}var yr=f("ZodMiniStringFormat",(e,t)=>{ze.init(e,t),Pt.init(e,t)});var _r=f("ZodMiniURL",(e,t)=>{ft.init(e,t),yr.init(e,t)});function te(e){return Et(_r,e)}var br=f("ZodMiniNumber",(e,t)=>{mt.init(e,t),I.init(e,t)});function re(e){return zt(br,e)}var xr=f("ZodMiniBoolean",(e,t)=>{ht.init(e,t),I.init(e,t)});function vr(e){return wt(xr,e)}var $r=f("ZodMiniDate",(e,t)=>{gt.init(e,t),I.init(e,t)});function ne(e){return Rt($r,e)}var Er=f("ZodMiniArray",(e,t)=>{yt.init(e,t),I.init(e,t)});function kt(e,t){return new Er({type:"array",element:e,...v(t)})}var zr=f("ZodMiniObject",(e,t)=>{_t.init(e,t),I.init(e,t),Ke(e,"shape",(r)=>r._zod.def.shape,!1)});function Y(e,t){let r={type:"object",shape:e??{},...v(t)};return new zr(r)}var Tt=f("ZodMiniEnum",(e,t)=>{bt.init(e,t),I.init(e,t),e.options=[...e._zod.values]});function At(e,t){let r=Array.isArray(e)?Object.fromEntries(e.map((n)=>[n,n])):e;return new Tt({type:"enum",entries:r,...v(t)})}function Zt(e,t){return new Tt({type:"enum",entries:e,...v(t)})}var wr=f("ZodMiniOptional",(e,t)=>{xt.init(e,t),I.init(e,t)});function x(e){return new wr({type:"optional",innerType:e})}var we;((i)=>{i.ALIMTALK="ALIMTALK";i.SMS="SMS";i.LMS="LMS";i.MMS="MMS";i.RCS="RCS"})(we||={});var oe;((s)=>{s.AUTHENTICATION="AUTHENTICATION";s.NOTIFICATION="NOTIFICATION";s.PROMOTION="PROMOTION";s.INFORMATION="INFORMATION";s.RESERVATION="RESERVATION";s.SHIPPING="SHIPPING";s.PAYMENT="PAYMENT"})(oe||={});var ie;((i)=>{i.DRAFT="DRAFT";i.PENDING="PENDING";i.APPROVED="APPROVED";i.REJECTED="REJECTED";i.DISABLED="DISABLED"})(ie||={});var kr=Y({sent:re().check(W(0)),delivered:re().check(W(0)),failed:re().check(W(0))}),Tr=Y({createdAt:ne(),updatedAt:ne(),approvedAt:x(ne()),rejectedAt:x(ne()),rejectionReason:x(E()),usage:kr}),Ar=Y({name:E().check(H(1)),type:At(["string","number","date","custom"]),required:vr(),maxLength:x(re()),format:x(E()),description:x(E()),example:x(E())}),Zr=Y({type:At(["WL","AL","DS","BK","MD"]),name:E().check(H(1)),linkMobile:x(te()),linkPc:x(te()),linkIos:x(te()),linkAndroid:x(te()),schemeIos:x(E()),schemeAndroid:x(E())}),tu=Y({id:E(),code:E(),name:E().check(H(1)),content:E().check(H(1)),variables:x(kt(Ar)),buttons:x(kt(Zr)),category:Zt(oe),status:Zt(ie),provider:E(),metadata:Tr});class T{static VARIABLE_PATTERN=/#{([^}]+)}/g;static extractVariables(e){let t=[],r=e.matchAll(T.VARIABLE_PATTERN);for(let n of r){let o=n[1].trim();if(o&&!t.includes(o))t.push(o)}return t}static replaceVariables(e,t){return e.replace(T.VARIABLE_PATTERN,(r,n)=>{let o=t[n.trim()];if(o===void 0||o===null)return r;if(o instanceof Date)return o.toISOString();return String(o)})}static validateVariables(e,t){let r=[];for(let n of e){let o=t[n.name];if(n.required&&(o===void 0||o===null)){r.push(`Required variable '${n.name}' is missing`);continue}if(o===void 0||o===null)continue;if(!T.validateVariableType(o,n.type))r.push(`Variable '${n.name}' has invalid type. Expected: ${n.type}`);if(n.maxLength&&String(o).length>n.maxLength)r.push(`Variable '${n.name}' exceeds maximum length of ${n.maxLength}`);if(n.format&&!new RegExp(n.format).test(String(o)))r.push(`Variable '${n.name}' does not match required format: ${n.format}`)}return{isValid:r.length===0,errors:r}}static validateVariableType(e,t){switch(t){case"string":return typeof e==="string";case"number":return typeof e==="number"&&!isNaN(e);case"date":return e instanceof Date||!isNaN(Date.parse(e));case"custom":return!0;default:return!1}}static validateTemplateVariables(e,t){let r=T.extractVariables(e),n=t.map((i)=>i.name),o=[];for(let i of r)if(!n.includes(i))o.push(`Variable '${i}' is used in template but not defined`);for(let i of t)if(i.required&&!r.includes(i.name))o.push(`Required variable '${i.name}' is defined but not used in template`);return{isValid:o.length===0,errors:o}}}class w{static validate(e){let t=[],r=[];w.validateBasicFields(e,t),w.validateContent(e,t,r);let n=T.validateTemplateVariables(e.content,e.variables||[]);if(t.push(...n.errors),e.buttons&&e.buttons.length>0){let o=b.validateButtons(e.buttons);t.push(...o.errors)}return w.validateByCategory(e,t,r),{isValid:t.length===0,errors:t,warnings:r}}static validateBasicFields(e,t){if(!e.name||e.name.trim().length===0)t.push("Template name is required");if(!e.code||e.code.trim().length===0)t.push("Template code is required");if(!e.provider||e.provider.trim().length===0)t.push("Provider is required")}static validateContent(e,t,r){if(!e.content||e.content.trim().length===0){t.push("Template content is required");return}let n=e.content;if(n.length>1000)t.push("Template content cannot exceed 1000 characters");if(w.containsProhibitedCharacters(n))t.push("Template content contains prohibited characters");if((n.match(/\n/g)||[]).length>20)r.push("Template content has many line breaks, which may affect readability");w.validateUrlsInContent(n,r)}static containsProhibitedCharacters(e){return/[<>]/.test(e)}static validateUrlsInContent(e,t){let r=/https?:\/\/[^\s]+/g,n=e.match(r)||[];for(let o of n)try{new URL(o)}catch{t.push(`Invalid URL found in content: ${o}`)}}static validateByCategory(e,t,r){switch(e.category){case"AUTHENTICATION":w.validateAuthenticationTemplate(e,t,r);break;case"PROMOTION":w.validatePromotionTemplate(e,t,r);break;case"PAYMENT":w.validatePaymentTemplate(e,t,r);break;case"INFORMATION":case"NOTIFICATION":case"RESERVATION":case"SHIPPING":break}}static validateAuthenticationTemplate(e,t,r){if(!(e.variables||[]).some((o)=>o.name.includes("인증")||o.name.includes("코드")||o.name.includes("번호")))r.push("Authentication template should include an authentication code variable");if(e.buttons&&e.buttons.length>0)r.push("Authentication templates typically should not have buttons")}static validatePromotionTemplate(e,t,r){if(!e.buttons||e.buttons.length===0)r.push("Promotion templates typically should have action buttons")}static validatePaymentTemplate(e,t,r){if(!(e.variables||[]).some((o)=>o.name.includes("금액")||o.name.includes("가격")||o.name.includes("원")))r.push("Payment template should include an amount variable")}static quickValidate(e){let t=[];if(!e.name)t.push("Name is required");if(!e.content)t.push("Content is required");if(!e.category)t.push("Category is required");if(!e.provider)t.push("Provider is required");return{isValid:t.length===0,errors:t,warnings:[]}}}class se{options;defaultOptions={variablePattern:/#\{([^}]+)\}/g,allowUndefined:!1,undefinedReplacement:"",caseSensitive:!0,enableFormatting:!0,enableConditionals:!0,enableLoops:!0,maxRecursionDepth:10,timeZone:"Asia/Seoul"};constructor(e={}){this.options=e;this.options={...this.defaultOptions,...e}}replace(e,t){let r=Date.now(),n=e.length,o={content:e,variables:[],missingVariables:[],errors:[],metadata:{originalLength:n,finalLength:0,variableCount:0,replacementTime:0}};try{if(this.options.enableConditionals)o.content=this.processConditionals(o.content,t,o);if(this.options.enableLoops)o.content=this.processLoops(o.content,t,o);if(o.content=this.replaceSimpleVariables(o.content,t,o),this.hasVariables(o.content))o.content=this.replaceRecursive(o.content,t,o,0)}catch(i){o.errors.push({type:"syntax_error",message:i instanceof Error?i.message:"Unknown error"})}return o.metadata.finalLength=o.content.length,o.metadata.variableCount=o.variables.length,o.metadata.replacementTime=Date.now()-r,o}extractVariables(e){let t=new Set,r=new RegExp(this.options.variablePattern),n=r.exec(e);while(n!==null){let o=this.parseVariableName(n[1]);t.add(o),n=r.exec(e)}if(this.options.enableConditionals)this.extractConditionals(e).forEach((i)=>{if(this.extractVariablesFromExpression(i.condition).forEach((a)=>{t.add(a)}),this.extractVariables(i.content).forEach((a)=>{t.add(a)}),i.elseContent)this.extractVariables(i.elseContent).forEach((c)=>{t.add(c)})});if(this.options.enableLoops)this.extractLoops(e).forEach((i)=>{t.add(i.array),this.extractVariables(i.content).forEach((s)=>{t.add(s)})});return Array.from(t)}validate(e,t){let r=this.extractVariables(e),n=Object.keys(t),o=r.filter((u)=>{let s=this.options.caseSensitive?u:u.toLowerCase();return!n.some((a)=>(this.options.caseSensitive?a:a.toLowerCase())===s)}),i=o.map((u)=>({type:"missing_variable",message:`Missing required variable: ${u}`,variable:u}));return{isValid:o.length===0,missingVariables:o,errors:i}}preview(e,t){let r=this.replace(e,t),n={},o=new RegExp(this.options.variablePattern),i=o.exec(e);while(i!==null){let s=this.parseVariableName(i[1]),a=this.getVariableValue(s,t);if(!n[s])n[s]={value:String(a),positions:[]};n[s].positions.push({start:i.index,end:i.index+i[0].length}),i=o.exec(e)}let u=Object.entries(n).map(([s,a])=>({variable:s,value:a.value,positions:a.positions}));return{originalContent:e,previewContent:r.content,variableHighlights:u}}replaceSimpleVariables(e,t,r){let n=new RegExp(this.options.variablePattern,"g");return e.replace(n,(o,i,u)=>{try{let s=this.parseVariableName(i),a=this.getVariableValue(s,t);if(a===void 0||a===null){if(!this.options.allowUndefined)r.missingVariables.push(s),r.errors.push({type:"missing_variable",message:`Variable '${s}' is not defined`,variable:s,position:{start:u,end:u+o.length}});return this.options.undefinedReplacement}let c=this.options.enableFormatting?this.formatValue(a,i):String(a);return r.variables.push({name:s,value:a,formatted:c,type:this.getValueType(a),position:{start:u,end:u+o.length}}),c}catch(s){return r.errors.push({type:"format_error",message:s instanceof Error?s.message:"Format error",variable:i,position:{start:u,end:u+o.length}}),o}})}replaceRecursive(e,t,r,n){if(n>=this.options.maxRecursionDepth)return r.errors.push({type:"recursion_limit",message:`Maximum recursion depth (${this.options.maxRecursionDepth}) exceeded`}),e;let o=this.replaceSimpleVariables(e,t,r);if(this.hasVariables(o)&&o!==e)return this.replaceRecursive(o,t,r,n+1);return o}processConditionals(e,t,r){let n=this.extractConditionals(e),o=e;return n.forEach((i)=>{try{let s=this.evaluateCondition(i.condition,t)?i.content:i.elseContent||"",a=this.buildConditionalPattern(i);o=o.replace(a,s)}catch(u){r.errors.push({type:"syntax_error",message:`Error in conditional: ${u instanceof Error?u.message:"Unknown error"}`})}}),o}processLoops(e,t,r){let n=this.extractLoops(e),o=e;return n.forEach((i)=>{try{let u=this.getVariableValue(i.array,t);if(!Array.isArray(u)){r.errors.push({type:"syntax_error",message:`Loop variable '${i.array}' is not an array`});return}let s="";u.forEach((c,l)=>{let p={...t,[i.variable]:c,[`${i.variable}_index`]:l,[`${i.variable}_first`]:l===0,[`${i.variable}_last`]:l===u.length-1},d=this.replaceSimpleVariables(i.content,p,r);s+=d});let a=this.buildLoopPattern(i);o=o.replace(a,s)}catch(u){r.errors.push({type:"syntax_error",message:`Error in loop: ${u instanceof Error?u.message:"Unknown error"}`})}}),o}parseVariableName(e){return e.split("|")[0].trim()}getVariableValue(e,t){let r=e.split("."),n=t;for(let o of r){if(n===null||n===void 0)return;if(this.options.caseSensitive)n=n[o];else{let i=Object.keys(n).find((u)=>u.toLowerCase()===o.toLowerCase());n=i?n[i]:void 0}}return n}formatValue(e,t){if(!this.options.enableFormatting)return String(e);let r=t.split("|");if(r.length<2)return String(e);let n=r[1].trim();try{switch(n){case"upper":return String(e).toUpperCase();case"lower":return String(e).toLowerCase();case"capitalize":return String(e).charAt(0).toUpperCase()+String(e).slice(1).toLowerCase();case"number":return Number(e).toLocaleString();case"currency":return new Intl.NumberFormat("ko-KR",{style:"currency",currency:"KRW"}).format(Number(e));case"date":return new Date(e).toLocaleDateString("ko-KR",{timeZone:this.options.timeZone});case"datetime":return new Date(e).toLocaleString("ko-KR",{timeZone:this.options.timeZone});case"time":return new Date(e).toLocaleTimeString("ko-KR",{timeZone:this.options.timeZone});default:if(n.startsWith("date:")){let o=n.substring(5);return this.formatDate(new Date(e),o)}if(n.startsWith("number:")){let o=parseInt(n.substring(7),10);return Number(e).toFixed(o)}return String(e)}}catch(o){return String(e)}}formatDate(e,t){let r=new Intl.DateTimeFormat("en-US",{timeZone:this.options.timeZone,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hourCycle:"h23"}).formatToParts(e),n=(l)=>r.find((p)=>p.type===l)?.value??"",o=n("year"),i=n("month"),u=n("day"),s=n("hour"),a=n("minute"),c=n("second");return t.replace("YYYY",String(o)).replace("MM",i).replace("DD",u).replace("HH",s).replace("mm",a).replace("ss",c)}getValueType(e){if(e===void 0||e===null)return"undefined";if(typeof e==="string")return"string";if(typeof e==="number")return"number";if(typeof e==="boolean")return"boolean";if(e instanceof Date)return"date";if(Array.isArray(e))return"array";if(typeof e==="object")return"object";return"string"}hasVariables(e){return this.options.variablePattern?.test(e)??!1}extractConditionals(e){let t=/\{\{if\s+([^}]+)\}\}(.*?)\{\{\/if\}\}/gs,r=[],n=t.exec(e);while(n!==null){let o=n[1].trim(),i=n[2],u=/^(.*?)\{\{else\}\}(.*)$/s,s=i.match(u);if(s)r.push({condition:o,content:s[1],elseContent:s[2]});else r.push({condition:o,content:i});n=t.exec(e)}return r}extractLoops(e){let t=/\{\{for\s+(\w+)\s+in\s+(\w+)\}\}(.*?)\{\{\/for\}\}/gs,r=[],n=t.exec(e);while(n!==null)r.push({variable:n[1],array:n[2],content:n[3]}),n=t.exec(e);return r}extractVariablesFromExpression(e){let t=new Set,r=/\b([a-zA-Z_][a-zA-Z0-9_]*(?:\.[a-zA-Z_][a-zA-Z0-9_]*)*)\b/g,n=r.exec(e);while(n!==null)t.add(n[1]),n=r.exec(e);return Array.from(t)}evaluateCondition(e,t){try{let r=e.trim();if(r.startsWith("!")){let o=r.substring(1).trim();return!this.getVariableValue(o,t)}if(r.includes("===")){let[o,i]=r.split("===").map((a)=>a.trim()),u=this.getVariableValue(o,t),s=i.startsWith('"')||i.startsWith("'")?i.slice(1,-1):this.getVariableValue(i,t);return u===s}if(r.includes("!==")){let[o,i]=r.split("!==").map((a)=>a.trim()),u=this.getVariableValue(o,t),s=i.startsWith('"')||i.startsWith("'")?i.slice(1,-1):this.getVariableValue(i,t);return u!==s}let n=this.getVariableValue(r,t);return Boolean(n)}catch(r){return!1}}buildConditionalPattern(e){let t=e.condition.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),r=e.elseContent?".*?\\{\\{else\\}\\}.*?":".*?";return new RegExp(`\\{\\{if\\s+${t}\\}\\}${r}\\{\\{/if\\}\\}`,"gs")}buildLoopPattern(e){let t=e.variable.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),r=e.array.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`\\{\\{for\\s+${t}\\s+in\\s+${r}\\}\\}.*?\\{\\{/for\\}\\}`,"gs")}}var V=new se({variablePattern:/#\{([^}]+)\}/g,allowUndefined:!1,undefinedReplacement:"",caseSensitive:!1,enableFormatting:!0,enableConditionals:!0,enableLoops:!0,maxRecursionDepth:5}),Ct={extractVariables:(e)=>V.extractVariables(e),replace:(e,t)=>V.replace(e,t).content,validate:(e,t)=>V.validate(e,t).isValid,personalize:(e,t)=>t.map((r)=>{let n=V.replace(e,r.variables);return{phoneNumber:r.phoneNumber,content:n.content,errors:n.errors.length>0?n.errors.map((o)=>o.message):void 0}})};var ue;((m)=>{m.INVALID_REQUEST="INVALID_REQUEST";m.AUTHENTICATION_FAILED="AUTHENTICATION_FAILED";m.INSUFFICIENT_BALANCE="INSUFFICIENT_BALANCE";m.TEMPLATE_NOT_FOUND="TEMPLATE_NOT_FOUND";m.RATE_LIMIT_EXCEEDED="RATE_LIMIT_EXCEEDED";m.NETWORK_ERROR="NETWORK_ERROR";m.NETWORK_TIMEOUT="NETWORK_TIMEOUT";m.NETWORK_SERVICE_UNAVAILABLE="NETWORK_SERVICE_UNAVAILABLE";m.REQUEST_ABORTED="REQUEST_ABORTED";m.PROVIDER_ERROR="PROVIDER_ERROR";m.MESSAGE_SEND_FAILED="MESSAGE_SEND_FAILED";m.CRYPTO_CONFIG_ERROR="CRYPTO_CONFIG_ERROR";m.CRYPTO_ENCRYPT_FAILED="CRYPTO_ENCRYPT_FAILED";m.CRYPTO_DECRYPT_FAILED="CRYPTO_DECRYPT_FAILED";m.CRYPTO_HASH_FAILED="CRYPTO_HASH_FAILED";m.CRYPTO_POLICY_VIOLATION="CRYPTO_POLICY_VIOLATION";m.UNKNOWN_ERROR="UNKNOWN_ERROR"})(ue||={});var Cr={["INVALID_REQUEST"]:{ko:"잘못된 요청입니다",en:"Invalid request"},["AUTHENTICATION_FAILED"]:{ko:"인증에 실패했습니다",en:"Authentication failed"},["INSUFFICIENT_BALANCE"]:{ko:"잔액이 부족합니다",en:"Insufficient balance"},["TEMPLATE_NOT_FOUND"]:{ko:"템플릿을 찾을 수 없습니다",en:"Template not found"},["RATE_LIMIT_EXCEEDED"]:{ko:"요청 한도를 초과했습니다",en:"Rate limit exceeded"},["NETWORK_ERROR"]:{ko:"네트워크 오류가 발생했습니다",en:"Network error"},["NETWORK_TIMEOUT"]:{ko:"네트워크 요청 시간이 초과되었습니다",en:"Network timeout"},["NETWORK_SERVICE_UNAVAILABLE"]:{ko:"서비스를 일시적으로 사용할 수 없습니다",en:"Service temporarily unavailable"},["REQUEST_ABORTED"]:{ko:"요청이 취소되었습니다",en:"Request aborted"},["PROVIDER_ERROR"]:{ko:"제공자 오류가 발생했습니다",en:"Provider error"},["MESSAGE_SEND_FAILED"]:{ko:"메시지 전송에 실패했습니다",en:"Message send failed"},["CRYPTO_CONFIG_ERROR"]:{ko:"암호화 설정 오류가 발생했습니다",en:"Crypto configuration error"},["CRYPTO_ENCRYPT_FAILED"]:{ko:"암호화에 실패했습니다",en:"Encryption failed"},["CRYPTO_DECRYPT_FAILED"]:{ko:"복호화에 실패했습니다",en:"Decryption failed"},["CRYPTO_HASH_FAILED"]:{ko:"해시 생성에 실패했습니다",en:"Hash generation failed"},["CRYPTO_POLICY_VIOLATION"]:{ko:"암호화 정책 위반이 발생했습니다",en:"Crypto policy violation"},["UNKNOWN_ERROR"]:{ko:"알 수 없는 오류가 발생했습니다",en:"Unknown error"}},au=new Set(Object.values(ue));var Re=(e)=>{if(typeof e!=="number"||Number.isNaN(e)||!Number.isFinite(e))return;return Math.trunc(e)};class k extends Error{code;details;providerErrorCode;providerErrorText;httpStatus;requestId;retryAfterMs;attempt;causeChain;constructor(e,t,r,n={}){super(t);if(this.name="KMsgError",this.code=e,this.details=r,this.providerErrorCode=n.providerErrorCode,this.providerErrorText=n.providerErrorText,this.httpStatus=Re(n.httpStatus),this.requestId=typeof n.requestId==="string"?n.requestId:void 0,this.retryAfterMs=Re(n.retryAfterMs),this.attempt=Re(n.attempt),Array.isArray(n.causeChain))this.causeChain=n.causeChain;else if(n.causeChain!==void 0)this.causeChain=[n.causeChain];let o=Error.captureStackTrace;if(o)o(this,k)}getLocalizedMessage(e="ko"){let t=Cr[this.code];if(t?.[e])return t[e];return this.message}toJSON(){return{name:this.name,code:this.code,message:this.message,details:this.details,providerErrorCode:this.providerErrorCode,providerErrorText:this.providerErrorText,httpStatus:this.httpStatus,requestId:this.requestId,retryAfterMs:this.retryAfterMs,attempt:this.attempt,causeChain:this.causeChain}}}var A=(e)=>({isSuccess:!0,isFailure:!1,value:e}),_=(e)=>({isSuccess:!1,isFailure:!0,error:e});var Sr=new Set(["WL","AL","DS","BK","MD"]);function R(e){return new k("INVALID_REQUEST",e)}function St(e){if(!e||typeof e!=="object"||Array.isArray(e))return;return e}function Ir(e){try{return A(JSON.parse(e))}catch(t){return _(R(`Invalid JSON for buttons: ${t instanceof Error?t.message:String(t)}`))}}function B(e,t,r){for(let n of t){if(!(n in e))continue;let o=e[n];if(o===null||o===void 0||o==="")return A(void 0);if(typeof o!=="string")return _(R(`buttons.${r} must be a string`));return A(o)}return A(void 0)}function Mr(e,t){let r=St(e);if(!r)return _(R(`buttons[${t}] must be an object with type/name`));let n=r.type;if(typeof n!=="string"||!Sr.has(n))return _(R(`buttons[${t}].type must be one of WL, AL, DS, BK, MD`));let o=n,i=r.name;if(typeof i!=="string"||i.trim().length===0)return _(R(`buttons[${t}].name is required`));let u=B(r,["linkMobile","url_mobile","urlMobile"],"linkMobile");if(u.isFailure)return u;let s=B(r,["linkPc","url_pc","urlPc"],"linkPc");if(s.isFailure)return s;let a=B(r,["linkIos","url_ios","urlIos"],"linkIos");if(a.isFailure)return a;let c=B(r,["linkAndroid","url_android","urlAndroid"],"linkAndroid");if(c.isFailure)return c;let l=B(r,["schemeIos","scheme_ios"],"schemeIos");if(l.isFailure)return l;let p=B(r,["schemeAndroid","scheme_android"],"schemeAndroid");if(p.isFailure)return p;return A({type:o,name:i,...u.value?{linkMobile:u.value}:{},...s.value?{linkPc:s.value}:{},...a.value?{linkIos:a.value}:{},...c.value?{linkAndroid:c.value}:{},...l.value?{schemeIos:l.value}:{},...p.value?{schemeAndroid:p.value}:{}})}function Pe(e){if(e===void 0||e===null)return A(void 0);let t=e;if(typeof t==="string"){let i=Ir(t);if(i.isFailure)return i;t=i.value}let r=St(t);if(r&&Array.isArray(r.button))t=r.button;if(!Array.isArray(t))return _(R("buttons must be a JSON array"));let n=[];for(let[i,u]of t.entries()){let s=Mr(u,i);if(s.isFailure)return s;n.push(s.value)}let o=b.validateButtons(n);if(!o.isValid)return _(R(`Invalid template buttons: ${o.errors.join(", ")}`));return A(n)}function G(e,t={}){let r=t.requireName??!0,n=t.requireContent??!0,o={};if(e.name===void 0||e.name===null){if(r)return _(R("name is required"))}else if(typeof e.name!=="string"||e.name.trim().length===0)return _(R(r?"name is required":"name must be a non-empty string"));else o.name=e.name.trim();if(e.content===void 0||e.content===null){if(n)return _(R("content is required"))}else if(typeof e.content!=="string"||e.content.trim().length===0)return _(R(n?"content is required":"content must be a non-empty string"));else o.content=e.content;let i=Pe(e.buttons);if(i.isFailure)return i;if(i.value!==void 0)o.buttons=i.value;return A(o)}function Or(e,t){if(t)return t;let r=e;if(typeof r.requestTemplateInspection==="function")return{requestTemplateInspection:r.requestTemplateInspection.bind(e)};return}class ke{provider;inspectionProvider;constructor(e,t){this.provider=e;this.inspectionProvider=Or(e,t)}async create(e,t){let r=G(e,{requireName:!0,requireContent:!0});if(r.isFailure)return r;let n={...e,...r.value.name?{name:r.value.name}:{},...r.value.content?{content:r.value.content}:{},...r.value.buttons!==void 0?{buttons:r.value.buttons}:{}};return this.provider.createTemplate(n,t)}async update(e,t,r){if(!e||e.trim().length===0)return _(new k("INVALID_REQUEST","Template code is required"));let n=G(t,{requireName:!1,requireContent:!1});if(n.isFailure)return n;let o={...t,...n.value.name!==void 0?{name:n.value.name}:{},...n.value.content!==void 0?{content:n.value.content}:{},...n.value.buttons!==void 0?{buttons:n.value.buttons}:{}};return this.provider.updateTemplate(e,o,r)}async delete(e,t){if(!e||e.trim().length===0)return _(new k("INVALID_REQUEST","Template code is required"));return this.provider.deleteTemplate(e,t)}async get(e,t){if(!e||e.trim().length===0)return _(new k("INVALID_REQUEST","Template code is required"));return this.provider.getTemplate(e,t)}async list(e,t){return this.provider.listTemplates(e,t)}async requestInspection(e,t){if(!e||e.trim().length===0)return _(new k("INVALID_REQUEST","Template code is required"));if(!this.inspectionProvider)return _(new k("INVALID_REQUEST","Template inspection is not supported by this provider"));return this.inspectionProvider.requestTemplateInspection(e,t)}}
2
+
3
+ //# debugId=D24507F98A24552C64756E2164756E21
4
+ //# sourceMappingURL=index.cjs.map