solapi
Version:
SOLAPI SDK for Node.js(Server Side Only)
6 lines • 33.8 kB
JavaScript
'use strict';var effect=require('effect'),crypto=require('crypto'),dateFns=require('date-fns'),E=require('effect/Effect'),fs=require('fs'),url=require('url');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var E__namespace=/*#__PURE__*/_interopNamespace(E);var w=class extends effect.Data.TaggedError("InvalidDateError"){toString(){return `InvalidDateError: ${this.message}${this.originalValue?` (value: ${this.originalValue})`:""}`}},O=class extends effect.Data.TaggedError("ApiKeyError"){toString(){return `ApiKeyError: ${this.message}`}},I=class extends effect.Data.TaggedError("DefaultError"){toString(){return `${this.errorCode}: ${this.errorMessage}`}},N=class extends effect.Data.TaggedError("MessageNotReceivedError"){get message(){return `${this.totalCount}\uAC1C\uC758 \uBA54\uC2DC\uC9C0\uAC00 \uC811\uC218\uB418\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4. \uC790\uC138\uD55C \uC5D0\uB7EC \uBA54\uC2DC\uC9C0\uB294 \uD574\uB2F9 \uC5D0\uB7EC \uB0B4 failedMessageList\uB97C \uD655\uC778\uD574\uC8FC\uC138\uC694.`}toString(){return `MessageNotReceivedError: ${this.message}
Failed messages: ${this.failedMessageList.length}`}},G=class extends effect.Data.TaggedError("BadRequestError"){toString(){return `BadRequestError: ${this.message}${this.validationErrors?`
Validation errors: ${this.validationErrors.join(", ")}`:""}`}},q=class extends effect.Data.TaggedError("NetworkError"){toString(){return `NetworkError: ${this.method} ${this.url} \uC694\uCCAD \uC2E4\uD328 - ${this.cause}`}},L=class extends effect.Data.TaggedError("ApiError"){toString(){return `${this.errorCode}: ${this.errorMessage}`}};function Ze(t,e){let a=crypto.randomBytes(e),r="";for(let o=0;o<e;o++)r+=t[a[o]%t.length];return r}function Se(t,e=0){let{apiKey:a,apiSecret:r}=t;switch(e){case 0:default:let o=Ze("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",32),i=dateFns.formatISO(new Date),l=i+o;if(!a||!r||a===""||r==="")throw new O({message:"Invalid API Key Error"});let h=crypto.createHmac("sha256",r);h.update(l);let A=h.digest("hex");return `HMAC-SHA256 apiKey=${a}, date=${i}, salt=${o}, signature=${A}`}}var et=effect.Schema.Struct({buttonName:effect.Schema.String,buttonType:effect.Schema.Literal("WL"),linkMo:effect.Schema.String,linkPc:effect.Schema.optional(effect.Schema.NullOr(effect.Schema.String))}),tt=effect.Schema.Struct({buttonName:effect.Schema.String,buttonType:effect.Schema.Literal("AL"),linkAnd:effect.Schema.String,linkIos:effect.Schema.String}),at=effect.Schema.Struct({buttonName:effect.Schema.String,buttonType:effect.Schema.Literal("BK","MD","DS","BC","BT","AC")}),se=effect.Schema.Union(et,tt,at);var U=class extends effect.Data.TaggedError("VariableValidationError"){toString(){return `\uBCC0\uC218\uBA85 ${this.invalidVariables.map(a=>`\`${a}\``).join(", ")}\uC5D0 \uC810(.)\uC744 \uD3EC\uD568\uD560 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. \uC5B8\uB354\uC2A4\uCF54\uC5B4(_)\uB098 \uB2E4\uB978 \uBB38\uC790\uB97C \uC0AC\uC6A9\uD574\uC8FC\uC138\uC694.`}},ot=effect.Schema.Struct({targeting:effect.Schema.Literal("I","M","N")}),Ce=/^#\{.+}$/,rt=/\./,nt=t=>Ce.test(t)?t.slice(2,-1):t,it=t=>Ce.test(t)?t:`#{${t}}`,lt=t=>effect.pipe(Object.keys(t),effect.Array.map(nt),effect.Array.filter(e=>rt.test(e)),e=>e.length>0?effect.Effect.fail(new U({invalidVariables:e})):effect.Effect.succeed(t)),pt=t=>effect.pipe(lt(t),effect.Effect.map(e=>effect.pipe(Object.entries(e),effect.Array.map(([a,r])=>[it(a),r]),a=>Object.fromEntries(a)))),Ie=effect.Schema.Struct({pfId:effect.Schema.String,templateId:effect.Schema.optional(effect.Schema.String),variables:effect.Schema.optional(effect.Schema.Record({key:effect.Schema.String,value:effect.Schema.String}).pipe(effect.Schema.transform(effect.Schema.Record({key:effect.Schema.String,value:effect.Schema.String}),{decode:t=>Ke(pt(t)),encode:t=>t}))),disableSms:effect.Schema.optional(effect.Schema.Boolean),adFlag:effect.Schema.optional(effect.Schema.Boolean),imageId:effect.Schema.optional(effect.Schema.String),buttons:effect.Schema.optional(effect.Schema.Array(se)),bms:effect.Schema.optional(ot)});var ct=t=>t instanceof w||t instanceof O||t instanceof I||t instanceof N||t instanceof G||t instanceof q||t instanceof L||t instanceof U?t.toString():t instanceof Error?`${t.name}: ${t.message}`:String(t);var Ke=t=>{let e=effect.Effect.runSyncExit(t);return effect.Exit.match(e,{onFailure:a=>{let r=effect.Cause.failureOption(a);if(r._tag==="Some")throw oe(r.value);let o=effect.Cause.defects(a);if(o.length>0){let i=effect.Chunk.unsafeGet(o,0);throw i instanceof Error?i:new Error(`Uncaught defect: ${String(i)}`)}throw new Error(`Unhandled Exit: ${effect.Cause.pretty(a)}`)},onSuccess:a=>a})},qe=t=>effect.Effect.runPromiseExit(t).then(effect.Exit.match({onFailure:e=>{let a=effect.Cause.failureOption(e);if(a._tag==="Some")return Promise.reject(oe(a.value));let r=effect.Cause.defects(e);if(r.length>0){let o=effect.Chunk.unsafeGet(r,0);return o instanceof Error?Promise.reject(o):Promise.reject(new Error(`Uncaught defect: ${String(o)}`))}return Promise.reject(new Error(`Unhandled Exit: ${effect.Cause.pretty(e)}`))},onSuccess:e=>Promise.resolve(e)})),oe=t=>{if(t instanceof N){let o=new Error(t.message);return o.name="MessageNotReceivedError",Object.defineProperty(o,"failedMessageList",{value:t.failedMessageList,writable:false,enumerable:true,configurable:false}),Object.defineProperty(o,"totalCount",{value:t.totalCount,writable:false,enumerable:true,configurable:false}),delete o.stack,o}if(t instanceof L){let o=new Error(t.toString());return o.name="ApiError",Object.defineProperties(o,{errorCode:{value:t.errorCode,writable:false,enumerable:true},errorMessage:{value:t.errorMessage,writable:false,enumerable:true},httpStatus:{value:t.httpStatus,writable:false,enumerable:true},url:{value:t.url,writable:false,enumerable:true}}),delete o.stack,o}if(t instanceof I){let o=new Error(t.toString());return o.name="DefaultError",Object.defineProperties(o,{errorCode:{value:t.errorCode,writable:false,enumerable:true},errorMessage:{value:t.errorMessage,writable:false,enumerable:true},context:{value:t.context,writable:false,enumerable:true}}),delete o.stack,o}if(t instanceof q){let o=new Error(t.toString());return o.name="NetworkError",Object.defineProperties(o,{url:{value:t.url,writable:false,enumerable:true},method:{value:t.method,writable:false,enumerable:true},cause:{value:t.cause,writable:false,enumerable:true},isRetryable:{value:t.isRetryable??false,writable:false,enumerable:true}}),delete o.stack,o}if(t instanceof G){let o=new Error(t.message);return o.name="BadRequestError",Object.defineProperties(o,{validationErrors:{value:t.validationErrors,writable:false,enumerable:true}}),delete o.stack,o}if(t instanceof U){let o=new Error(t.toString());return o.name="VariableValidationError",Object.defineProperties(o,{invalidVariables:{value:t.invalidVariables,writable:false,enumerable:true}}),delete o.stack,o}if(t instanceof w){let o=new Error(t.toString());return o.name="InvalidDateError",Object.defineProperties(o,{originalValue:{value:t.originalValue,writable:false,enumerable:true}}),delete o.stack,o}if(t instanceof O){let o=new Error(t.toString());return o.name="ApiKeyError",delete o.stack,o}let a=ct(t),r=new Error(a);return r.name="FromSolapiError",delete r.stack,r};var Q=class extends effect.Data.TaggedError("RetryableError"){},ut=t=>effect.Effect.tryPromise({try:async()=>{let e=await t.text();return e?JSON.parse(e):{}},catch:e=>new I({errorCode:"ParseError",errorMessage:e.message,context:{responseStatus:t.status,responseUrl:t.url}})}),dt=t=>effect.pipe(effect.Effect.tryPromise({try:()=>t.json(),catch:e=>new I({errorCode:"ParseError",errorMessage:e.message,context:{responseStatus:t.status,responseUrl:t.url}})}),effect.Effect.flatMap(e=>effect.Effect.fail(new L({errorCode:e.errorCode,errorMessage:e.errorMessage,httpStatus:t.status,url:t.url})))),gt=t=>effect.pipe(effect.Effect.tryPromise({try:()=>t.text(),catch:e=>new I({errorCode:"ResponseReadError",errorMessage:e.message,context:{responseStatus:t.status,responseUrl:t.url}})}),effect.Effect.flatMap(e=>effect.Effect.fail(new I({errorCode:"UnknownError",errorMessage:e,context:{responseStatus:t.status,responseUrl:t.url}}))));async function Ae(t,e,a){let r=Se(t),o=effect.Effect.gen(function*(A){let B=yield*A(effect.Effect.try({try:()=>a?JSON.stringify(a):void 0,catch:f=>new I({errorCode:"JSONStringifyError",errorMessage:f.message,context:{data:a}})})),ke=yield*A(effect.Effect.tryPromise({try:()=>fetch(e.url,{headers:{Authorization:r,"Content-Type":"application/json"},body:B,method:e.method}),catch:f=>{if(f instanceof Error){let K=f.cause,ae=K&&typeof K=="object"&&"code"in K?String(K.code):"",_=(f.message+" "+ae).toLowerCase();return _.includes("aborted")||_.includes("refused")||_.includes("reset")||_.includes("econn")?new Q({error:f}):new q({url:e.url,method:e.method,cause:f.message,isRetryable:false})}return new q({url:e.url,method:e.method,cause:String(f),isRetryable:false})}}));return yield*A(effect.pipe(effect.Match.value(ke),effect.Match.when(f=>f.status===503,()=>effect.Effect.fail(new Q({error:"Service Unavailable"}))),effect.Match.when(f=>f.status>=400&&f.status<500,dt),effect.Match.when(f=>!f.ok,gt),effect.Match.orElse(ut)))}),i=3,l=effect.pipe(effect.Schedule.recurs(i),effect.Schedule.whileInput(A=>A instanceof Q)),h=effect.pipe(o,effect.Effect.retry(l),effect.Effect.catchTag("RetryableError",()=>effect.Effect.fail(new I({errorCode:"RequestFailedAfterRetryError",errorMessage:`Request failed after retry(count: ${i})`,context:{url:e.url,method:e.method,retryCount:i}}))));return qe(h)}var k=class{baseUrl="https://api.solapi.com";authInfo;constructor(e,a){this.authInfo={apiKey:e,apiSecret:a};}async request(e){let{httpMethod:a,url:r,body:o}=e,i={method:a,url:`${this.baseUrl}/${r}`};return Ae(this.authInfo,i,o)}};var z=class extends k{constructor(e,a){super(e,a);}async getBalance(){return this.request({httpMethod:"GET",url:"cash/v1/balance"})}};function T(t,e={}){if(!t||typeof t!="object")return "";if(Object.keys(t).length===0)return e.addQueryPrefix?"?":"";let a=(i,l)=>Array.isArray(l)?e.indices===false?l.map(h=>`${encodeURIComponent(i)}=${encodeURIComponent(String(h))}`):l.map((h,A)=>`${encodeURIComponent(i)}[${A}]=${encodeURIComponent(String(h))}`):l!=null?[`${encodeURIComponent(i)}=${encodeURIComponent(String(l))}`]:[],r=[];for(let[i,l]of Object.entries(t))r.push(...a(i,l));let o=r.join("&");return o?e.addQueryPrefix===false?o:`?${o}`:""}function g(t){return dateFns.formatISO(P(t))}function P(t){if(typeof t=="string"){t=dateFns.parseISO(t);let e="Invalid Date";if(t.toString()===e)throw new w({message:e,originalValue:typeof t=="string"?t:void 0})}return t}var re=class{type="DENIAL";senderNumber;startKey;limit;dateCreated;constructor(e){this.type="DENIAL",this.senderNumber=e.senderNumber,this.startKey=e.startKey,this.limit=e.limit,e.startDate!=null&&(this.dateCreated=Object.assign(this.dateCreated??{},{gte:g(e.startDate)})),e.endDate!=null&&(this.dateCreated=Object.assign(this.dateCreated??{},{lte:g(e.endDate)}));}};var ne=class{blockGroupId;useAll;senderNumber;name;status;startKey;limit;constructor(e){this.blockGroupId=e.blockGroupId,this.useAll=e.useAll,this.senderNumber=e.senderNumber,e.name!=null&&(typeof e.name=="string"?this.name={like:e.name}:this.name=e.name),this.status=e.status,this.startKey=e.startKey,this.limit=e.limit;}};var ie=class{blockNumberId;phoneNumber;blockGroupId;memo;startKey;limit;constructor(e){this.blockNumberId=e.blockNumberId,this.phoneNumber=e.phoneNumber,this.blockGroupId=e.blockGroupId,e.memo!=null&&(typeof e.memo=="string"?this.memo={like:e.memo}:this.memo=e.memo),this.startKey=e.startKey,this.limit=e.limit;}};var H=class extends k{constructor(e,a){super(e,a);}async getBlacks(e){let a={type:"DENIAL"};e&&(a=new re(e));let r=T(a,{indices:false,addQueryPrefix:true});return this.request({httpMethod:"GET",url:`iam/v1/black${r}`})}async getBlockGroups(e){let a={};e&&(a=new ne(e));let r=T(a,{indices:false,addQueryPrefix:true});return this.request({httpMethod:"GET",url:`iam/v1/block/groups${r}`})}async getBlockNumbers(e){let a={};e&&(a=new ie(e));let r=T(a,{indices:false,addQueryPrefix:true});return this.request({httpMethod:"GET",url:`iam/v1/block/numbers${r}`})}};effect.Schema.Struct({code:effect.Schema.String,name:effect.Schema.String});effect.Schema.Struct({channelId:effect.Schema.String,searchId:effect.Schema.String,accountId:effect.Schema.String,phoneNumber:effect.Schema.String,sharedAccountIds:effect.Schema.Array(effect.Schema.String),dateCreated:effect.Schema.optional(effect.Schema.Union(effect.Schema.String,effect.Schema.Date)),dateUpdated:effect.Schema.optional(effect.Schema.Union(effect.Schema.String,effect.Schema.Date))});var X=class{channelId;searchId;accountId;phoneNumber;sharedAccountIds;dateCreated;dateUpdated;constructor(e){this.channelId=e.channelId,this.searchId=e.searchId,this.accountId=e.accountId,this.phoneNumber=e.phoneNumber,this.sharedAccountIds=e.sharedAccountIds,e.dateCreated!=null&&(this.dateCreated=P(e.dateCreated)),e.dateUpdated!=null&&(this.dateUpdated=P(e.dateUpdated));}};var le=class{channelId;searchId;phoneNumber;categoryCode;startKey;limit;isMine;dateCreated;constructor(e){this.channelId=e.channelId,this.searchId=e.searchId,this.phoneNumber=e.phoneNumber,this.categoryCode=e.categoryCode,this.startKey=e.startKey,this.limit=e.limit,this.isMine=e.isMine,e.startDate!=null&&(this.dateCreated=Object.assign(this.dateCreated??{},{gte:g(e.startDate)})),e.endDate!=null&&(this.dateCreated=Object.assign(this.dateCreated??{},{lte:g(e.endDate)}));}};var J=class extends k{constructor(e,a){super(e,a);}async getKakaoChannelCategories(){return this.request({httpMethod:"GET",url:"kakao/v2/channels/categories"})}async getKakaoChannels(e){let a={};e&&(a=new le(e));let r=T(a,{indices:false,addQueryPrefix:true}),o=await this.request({httpMethod:"GET",url:`kakao/v2/channels${r}`}),i=[];for(let l of o.channelList)i.push(new X(l));return {limit:o.limit,nextKey:o.nextKey,startKey:o.startKey,channelList:i}}async getKakaoChannel(e){let a=await this.request({httpMethod:"GET",url:`kakao/v2/channels/${e}`});return new X(a)}async requestKakaoChannelToken(e){return this.request({httpMethod:"POST",url:"kakao/v2/channels/token",body:e})}async createKakaoChannel(e){return this.request({httpMethod:"POST",url:"kakao/v2/channels",body:e})}async removeKakaoChannel(e){return this.request({httpMethod:"DELETE",url:`kakao/v2/channels/${e}`})}};var ft=effect.Schema.Struct({name:effect.Schema.String,linkType:effect.Schema.Literal("WL"),linkMo:effect.Schema.String,linkPc:effect.Schema.optional(effect.Schema.String)}),kt=effect.Schema.Struct({name:effect.Schema.String,linkType:effect.Schema.Literal("AL"),linkAnd:effect.Schema.String,linkIos:effect.Schema.String}),St=effect.Schema.Struct({name:effect.Schema.String,linkType:effect.Schema.Literal("BK","BT","BC")}),Be=effect.Schema.Union(ft,kt,St);var Tt=effect.Schema.Literal("BA","EX","AD","MI"),Rt=effect.Schema.Literal("NONE","TEXT","IMAGE","ITEM_LIST"),bt=effect.Schema.Literal("CHANNEL","GROUP"),At=effect.Schema.Literal("PENDING","INSPECTING","APPROVED","REJECTED"),Mt=effect.Schema.Struct({isAdmin:effect.Schema.Boolean,memberId:effect.Schema.String,content:effect.Schema.NullOr(effect.Schema.String),dateCreated:effect.Schema.String}),Et=effect.Schema.Struct({title:effect.Schema.optional(effect.Schema.NullOr(effect.Schema.String)),description:effect.Schema.optional(effect.Schema.NullOr(effect.Schema.String)),imageId:effect.Schema.optional(effect.Schema.NullOr(effect.Schema.String))}),vt=effect.Schema.Struct({list:effect.Schema.Array(effect.Schema.Struct({title:effect.Schema.String,description:effect.Schema.String})),summary:effect.Schema.Struct({title:effect.Schema.optional(effect.Schema.NullOr(effect.Schema.String)),description:effect.Schema.optional(effect.Schema.NullOr(effect.Schema.String))})}),we=effect.Schema.Struct({name:effect.Schema.String,channelId:effect.Schema.optional(effect.Schema.NullOr(effect.Schema.String)),channelGroupId:effect.Schema.optional(effect.Schema.NullOr(effect.Schema.String)),content:effect.Schema.optional(effect.Schema.String),isHidden:effect.Schema.optional(effect.Schema.Boolean),messageType:Tt,emphasizeType:Rt,extra:effect.Schema.optional(effect.Schema.NullOr(effect.Schema.String)),ad:effect.Schema.optional(effect.Schema.NullOr(effect.Schema.String)),emphasizeTitle:effect.Schema.optional(effect.Schema.NullOr(effect.Schema.String)),emphasizeSubtitle:effect.Schema.optional(effect.Schema.NullOr(effect.Schema.String)),securityFlag:effect.Schema.Boolean,imageId:effect.Schema.optional(effect.Schema.NullOr(effect.Schema.String)),assignType:effect.Schema.optional(bt),buttons:effect.Schema.optional(effect.Schema.Array(se)),comments:effect.Schema.optional(effect.Schema.Array(Mt)),commentable:effect.Schema.optional(effect.Schema.Boolean),quickReplies:effect.Schema.optional(effect.Schema.Array(Be)),header:effect.Schema.optional(effect.Schema.NullOr(effect.Schema.String)),highlight:effect.Schema.optional(effect.Schema.NullOr(Et)),item:effect.Schema.optional(effect.Schema.NullOr(vt)),templateId:effect.Schema.String,code:effect.Schema.optional(effect.Schema.NullOr(effect.Schema.String)),status:At,variables:effect.Schema.optional(effect.Schema.Array(effect.Schema.Struct({name:effect.Schema.String}))),dateCreated:effect.Schema.optional(effect.Schema.Union(effect.Schema.DateFromString,effect.Schema.Date,effect.Schema.DateFromSelf)),dateUpdated:effect.Schema.optional(effect.Schema.Union(effect.Schema.DateFromString,effect.Schema.Date,effect.Schema.DateFromSelf))}),D=class{name;channelId;channelGroupId;content;isHidden;messageType;emphasizeType;extra;ad;emphasizeTitle;emphasizeSubtitle;securityFlag;imageId;assignType;buttons;quickReplies;header;highlight;item;templateId;commentable;comments;code;status;dateCreated;dateUpdated;constructor(e){this.channelId=e.channelId,this.channelGroupId=e.channelGroupId,this.name=e.name,this.content=e.content,this.ad=e.ad,this.assignType=e.assignType,this.buttons=e.buttons,this.templateId=e.templateId,this.header=e.header,this.item=e.item,this.highlight=e.highlight,this.securityFlag=e.securityFlag,this.isHidden=e.isHidden,this.messageType=e.messageType,this.emphasizeType=e.emphasizeType,this.extra=e.extra,this.emphasizeTitle=e.emphasizeTitle,this.emphasizeSubtitle=e.emphasizeSubtitle,this.imageId=e.imageId,this.quickReplies=e.quickReplies,this.comments=e.comments,this.commentable=e.commentable,this.code=e.code,this.status=e.status,"dateCreated"in e&&(this.dateCreated=P(e.dateCreated)),"dateUpdated"in e&&(this.dateUpdated=P(e.dateUpdated));}};var pe=class{channelId;isHidden;limit;name;startKey;status;templateId;dateCreated;constructor(e){this.channelId=e.channelId,this.isHidden=e.isHidden,this.templateId=e.templateId,e.name!=null&&(typeof e.name=="string"?this.name={like:e.name}:typeof e.name=="object"&&(this.name=e.name)),this.startKey=e.startKey,this.status=e.status,this.limit=e.limit,e.startDate!=null&&(this.dateCreated=Object.assign(this.dateCreated??{},{gte:g(e.startDate)})),e.endDate!=null&&(this.dateCreated=Object.assign(this.dateCreated??{},{lte:g(e.endDate)}));}};var Y=class extends k{constructor(e,a){super(e,a);}async getKakaoAlimtalkTemplateCategories(){return this.request({httpMethod:"GET",url:"kakao/v2/templates/categories"})}async createKakaoAlimtalkTemplate(e){let a=await this.request({httpMethod:"POST",url:"kakao/v2/templates",body:e});return new D(a)}async getKakaoAlimtalkTemplates(e){let a={};e&&(a=new pe(e));let r=T(a,{indices:false,addQueryPrefix:true}),o=await this.request({httpMethod:"GET",url:`kakao/v2/templates${r}`}),i=A=>effect.Schema.decodeUnknown(we)(A),h=await effect.pipe(effect.Effect.all(o.templateList.map(i)),effect.Effect.runPromise);return {limit:o.limit,nextKey:o.nextKey,startKey:o.startKey,templateList:h}}async getKakaoAlimtalkTemplate(e){let a=await this.request({httpMethod:"GET",url:`kakao/v2/templates/${e}`});return new D(a)}async cancelInspectionKakaoAlimtalkTemplate(e){let a=await this.request({httpMethod:"PUT",url:`kakao/v2/templates/${e}/inspection/cancel`});return new D(a)}async updateKakaoAlimtalkTemplate(e,a){let r=await this.request({httpMethod:"PUT",url:`kakao/v2/templates/${e}`,body:a});return new D(r)}async updateKakaoAlimtalkTemplateName(e,a){let r=await this.request({httpMethod:"PUT",url:`kakao/v2/templates/${e}/name`,body:{name:a}});return new D(r)}async removeKakaoAlimtalkTemplate(e){let a=await this.request({httpMethod:"DELETE",url:`kakao/v2/templates/${e}`});return new D(a)}};var ce=class{criteria;cond;value;startKey;limit;startDate;endDate;constructor(e){e.groupId&&(this.criteria="groupId",this.cond="eq",this.value=e.groupId),this.startKey=e.startKey,this.limit=e.limit,e.startDate&&(this.startDate=g(e.startDate)),e.endDate&&(this.endDate=g(e.endDate));}};var Ne={version:"5.5.3"};var me=`${process.platform} | ${process.version}`,ue=`nodejs/${Ne.version}`,de=effect.Schema.Struct({sdkVersion:effect.Schema.optional(effect.Schema.String).pipe(effect.Schema.withDecodingDefault(()=>ue),effect.Schema.withConstructorDefault(()=>ue)),osPlatform:effect.Schema.optional(effect.Schema.String).pipe(effect.Schema.withDecodingDefault(()=>me),effect.Schema.withConstructorDefault(()=>me)),appId:effect.Schema.optional(effect.Schema.String)}),Le=effect.Schema.Struct({scheduledDate:effect.Schema.optional(effect.Schema.Union(effect.Schema.DateFromSelf,effect.Schema.DateFromString).pipe(effect.Schema.transform(effect.Schema.String,{decode:t=>g(t),encode:t=>new Date(t)}))),allowDuplicates:effect.Schema.optional(effect.Schema.Boolean),appId:effect.Schema.optional(effect.Schema.String),showMessageList:effect.Schema.optional(effect.Schema.Boolean)});effect.Schema.Struct({allowDuplicates:effect.Schema.optional(effect.Schema.Boolean),agent:effect.Schema.optional(de)});var Gt=effect.Schema.Struct({buttonName:effect.Schema.String,buttonType:effect.Schema.String,linkMo:effect.Schema.optional(effect.Schema.String),linkPc:effect.Schema.optional(effect.Schema.String),linkAnd:effect.Schema.optional(effect.Schema.String),linkIos:effect.Schema.optional(effect.Schema.String)}),$e=effect.Schema.Struct({talkId:effect.Schema.String,templateId:effect.Schema.String,disableSms:effect.Schema.optional(effect.Schema.Boolean),variables:effect.Schema.optional(effect.Schema.Record({key:effect.Schema.String,value:effect.Schema.String})),buttons:effect.Schema.optional(effect.Schema.Array(Gt))});effect.Schema.Literal("WL","ML","MQ","MR","CA","CL","DL","MS");var xt=effect.Schema.Struct({buttonName:effect.Schema.String,buttonType:effect.Schema.Literal("WL"),link:effect.Schema.String}),Dt=effect.Schema.Struct({buttonName:effect.Schema.String,buttonType:effect.Schema.Literal("ML"),latitude:effect.Schema.String,longitude:effect.Schema.String}),qt=effect.Schema.Struct({buttonName:effect.Schema.String,buttonType:effect.Schema.Literal("MQ","MR","CA","CL","DL","MS"),link:effect.Schema.String}),Me=effect.Schema.Union(xt,Dt,qt);var Pt=effect.Schema.Struct({title:effect.Schema.String,description:effect.Schema.String,imaggeId:effect.Schema.optional(effect.Schema.String),buttons:effect.Schema.optional(effect.Schema.Array(Me))}),Bt=effect.Schema.Struct({brandId:effect.Schema.String,templateId:effect.Schema.optional(effect.Schema.String),copyAllowed:effect.Schema.optional(effect.Schema.Boolean),variables:effect.Schema.optional(effect.Schema.Record({key:effect.Schema.String,value:effect.Schema.String})),mmsType:effect.Schema.optional(effect.Schema.Literal("M3","S3","M4","S4","M5","S5","M6","S6")),commercialType:effect.Schema.optional(effect.Schema.Boolean),disableSms:effect.Schema.optional(effect.Schema.Boolean),additionalBody:effect.Schema.optional(Pt),buttons:effect.Schema.optional(effect.Schema.Array(Me))}),Ue=Bt;var Fe=effect.Schema.Struct({voiceType:effect.Schema.Literal("FEMALE","MALE"),headerMessage:effect.Schema.optional(effect.Schema.String),tailMessage:effect.Schema.optional(effect.Schema.String),replyRange:effect.Schema.optional(effect.Schema.Literal(1,2,3,4,5,6,7,8,9)),counselorNumber:effect.Schema.optional(effect.Schema.String)});var wt=effect.Schema.Literal("SMS","LMS","MMS","ATA","CTA","CTI","NSA","RCS_SMS","RCS_LMS","RCS_MMS","RCS_TPL","RCS_ITPL","RCS_LTPL","FAX","VOICE","BMS_TEXT","BMS_IMAGE","BMS_WIDE","BMS_WIDE_ITEM_LIST","BMS_CAROUSEL_FEED","BMS_PREMIUM_VIDEO","BMS_COMMERCE","BMS_CAROUSEL_COMMERCE"),je=effect.Schema.Struct({to:effect.Schema.Union(effect.Schema.String,effect.Schema.Array(effect.Schema.String)),from:effect.Schema.optional(effect.Schema.String),text:effect.Schema.optional(effect.Schema.String),imageId:effect.Schema.optional(effect.Schema.String),type:effect.Schema.optional(wt),subject:effect.Schema.optional(effect.Schema.String),autoTypeDetect:effect.Schema.optional(effect.Schema.Boolean),kakaoOptions:effect.Schema.optional(Ie),rcsOptions:effect.Schema.optional(Ue),country:effect.Schema.optional(effect.Schema.String),replacements:effect.Schema.optional(effect.Schema.Array(effect.Schema.Struct({}))),customFields:effect.Schema.optional(effect.Schema.Record({key:effect.Schema.String,value:effect.Schema.String})),naverOptions:effect.Schema.optional($e),faxOptions:effect.Schema.optional(effect.Schema.Struct({fileIds:effect.Schema.Array(effect.Schema.String)})),voiceOptions:effect.Schema.optional(Fe)});var Ot=t=>t.replace(/-/g,""),Ee=effect.Schema.String.pipe(effect.Schema.transform(effect.Schema.String,{decode:Ot,encode:t=>t}),effect.Schema.filter(t=>t.trim().length>0,{message:()=>"\uC804\uD654\uBC88\uD638\uB294 \uBE48 \uBB38\uC790\uC5F4\uC77C \uC218 \uC5C6\uC2B5\uB2C8\uB2E4."}),effect.Schema.filter(t=>/^[0-9]+$/.test(t),{message:()=>"\uC804\uD654\uBC88\uD638\uB294 \uC22B\uC790 \uBC0F \uD2B9\uC218\uBB38\uC790 - \uC678 \uBB38\uC790\uB97C \uD3EC\uD568\uD560 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4."})),Ve=t=>effect.Schema.Array(t).pipe(effect.Schema.filter(e=>e.length>0,{message:()=>"\uB370\uC774\uD130\uAC00 \uBC18\uB4DC\uC2DC 1\uAC74 \uC774\uC0C1 \uAE30\uC785\uB418\uC5B4 \uC788\uC5B4\uC57C \uD569\uB2C8\uB2E4."})),j=je.pipe(effect.Schema.omit("to","from"),effect.Schema.extend(effect.Schema.Struct({to:effect.Schema.Union(Ee,effect.Schema.Array(Ee)),from:effect.Schema.optional(Ee)}))),ge=effect.Schema.Union(j,Ve(j)),_e=effect.Schema.decodeSync(de)({}),We=effect.Schema.optional(de).pipe(effect.Schema.withDecodingDefault(()=>_e),effect.Schema.withConstructorDefault(()=>_e));effect.Schema.Struct({message:j,agent:We});var Qe=effect.Schema.Struct({allowDuplicates:effect.Schema.optional(effect.Schema.Boolean),agent:We,messages:Ve(j),scheduledDate:effect.Schema.optional(effect.Schema.Union(effect.Schema.DateFromSelf,effect.Schema.DateFromString)),showMessageList:effect.Schema.optional(effect.Schema.Boolean)});var Z=class extends k{constructor(e,a){super(e,a);}async createGroup(e=false,a,r){return this.request({httpMethod:"POST",url:"messages/v4/groups",body:{sdkVersion:ue,osPlatform:me,allowDuplicates:e,appId:a,customFields:r}}).then(o=>o.groupId)}async addMessagesToGroup(e,a){let r=effect.Schema.decodeUnknownSync(ge)(a),o={messages:Array.isArray(r)?r:[r]};return this.request({httpMethod:"PUT",url:`messages/v4/groups/${e}/messages`,body:o})}async sendGroup(e){return this.request({httpMethod:"POST",url:`messages/v4/groups/${e}/send`})}async reserveGroup(e,a){let r=dateFns.formatISO(a);return this.request({httpMethod:"POST",url:`messages/v4/groups/${e}/schedule`,body:{scheduledDate:r}})}async removeReservationToGroup(e){return this.request({httpMethod:"DELETE",url:`messages/v4/groups/${e}/schedule`})}async getGroups(e){let a={};e&&(a=new ce(e));let r=T(a,{indices:false,addQueryPrefix:true});return this.request({httpMethod:"GET",url:`messages/v4/groups${r}`})}async getGroup(e){return this.request({httpMethod:"GET",url:`messages/v4/groups/${e}`})}async getGroupMessages(e,a){let r=T(a,{indices:false,addQueryPrefix:true});return this.request({httpMethod:"GET",url:`messages/v4/groups/${e}/messages${r}`})}async removeGroupMessages(e,a){return this.request({httpMethod:"DELETE",url:`messages/v4/groups/${e}/messages`,body:{messageIds:a}})}async removeGroup(e){return this.request({httpMethod:"DELETE",url:`messages/v4/groups/${e}`})}};var he=class{startKey;limit;dateType="CREATED";messageId;messageIds;groupId;to;from;type;statusCode;startDate;endDate;constructor(e){this.startKey=e.startKey,this.limit=e.limit,e.dateType&&(this.dateType=e.dateType),e.startDate&&(this.startDate=g(e.startDate)),e.endDate&&(this.endDate=g(e.endDate)),this.messageId=e.messageId,this.messageIds=e.messageIds,this.groupId=e.groupId,this.to=e.to,this.from=e.from,this.type=e.type,this.statusCode=e.statusCode;}};var ye=class{startDate;endDate;masterAccountId;constructor(e){e.startDate&&(this.startDate=g(e.startDate)),e.endDate&&(this.endDate=g(e.endDate)),this.masterAccountId=e.masterAccountId;}};var ee=class extends k{constructor(e,a){super(e,a);}async sendOne(e,a){let o={message:effect.Schema.decodeUnknownSync(j)(e),...a?{agent:{appId:a}}:{}};return this.request({httpMethod:"POST",url:"messages/v4/send",body:o})}async send(e,a){let r=this.request.bind(this),o=E__namespace.gen(function*(l){let h=yield*l(E__namespace.try({try:()=>effect.Schema.decodeUnknownSync(ge)(e),catch:C=>new G({message:C instanceof Error?C.message:String(C)})})),A=Array.isArray(h)?h:[h];if(A.length===0)return yield*l(E__namespace.fail(new G({message:"\uB370\uC774\uD130\uAC00 \uBC18\uB4DC\uC2DC 1\uAC74 \uC774\uC0C1 \uAE30\uC785\uB418\uC5B4 \uC788\uC5B4\uC57C \uD569\uB2C8\uB2E4."})));let B=yield*l(E__namespace.try({try:()=>effect.Schema.decodeUnknownSync(Le)(a??{}),catch:C=>new G({message:C instanceof Error?C.message:String(C)})})),ke={messages:A,allowDuplicates:B.allowDuplicates,...B.appId?{agent:{appId:B.appId}}:{},scheduledDate:B.scheduledDate,showMessageList:B.showMessageList},f=yield*l(E__namespace.try({try:()=>effect.Schema.decodeSync(Qe)(ke),catch:C=>new G({message:C instanceof Error?C.message:String(C)})})),K=yield*l(E__namespace.promise(()=>r({httpMethod:"POST",url:"messages/v4/send-many/detail",body:f}))),{count:ae}=K.groupInfo;return K.failedMessageList.length>0&&ae.total===ae.registeredFailed?yield*l(E__namespace.fail(new N({failedMessageList:K.failedMessageList,totalCount:K.failedMessageList.length}))):K}),i=await E__namespace.runPromiseExit(o);return effect.Exit.match(i,{onFailure:l=>{let h=effect.Cause.failureOption(l);throw h._tag==="Some"?oe(h.value):new Error("Unknown error occurred")},onSuccess:l=>l})}async getMessages(e){let a={};e&&(a=new he(e));let r=T(a,{indices:false,addQueryPrefix:true});return this.request({httpMethod:"GET",url:`messages/v4/list${r}`})}async getStatistics(e){let a={};e&&(a=new ye(e));let r=T(a,{indices:false,addQueryPrefix:true});return this.request({httpMethod:"GET",url:`messages/v4/statistics${r}`})}};var _t=t=>{try{let e=new url.URL(t);return e.protocol==="http:"||e.protocol==="https:"}catch{return false}},Vt=t=>E__namespace.flatMap(E__namespace.tryPromise({try:()=>fetch(t),catch:e=>new Error(`\uB124\uD2B8\uC6CC\uD06C \uC624\uB958\uB85C URL(${t})\uC744(\uB97C) \uAC00\uC838\uC624\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4.
${e}`)}),e=>e.ok?E__namespace.tryPromise({try:()=>e.arrayBuffer(),catch:a=>new Error(`\uC751\uB2F5 body \uCC98\uB9AC \uC911 \uC624\uB958\uAC00 \uBC1C\uC0DD\uD588\uC2B5\uB2C8\uB2E4.
${a}`)}):E__namespace.fail(new Error(`URL(${t}) \uC694\uCCAD \uC2E4\uD328 \u2013 \uC0C1\uD0DC \uCF54\uB4DC: ${e.status} ${e.statusText}`))).pipe(E__namespace.map(e=>Buffer.from(e).toString("base64"))),Wt=t=>E__namespace.tryPromise({try:()=>fs.promises.readFile(t),catch:e=>new Error(`\uD30C\uC77C\uC744 \uC77D\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4: ${t}
${e}`)}).pipe(E__namespace.map(e=>e.toString("base64")));async function ve(t){let e=_t(t)?Vt(t):Wt(t);return E__namespace.runPromise(e)}var te=class extends k{constructor(e,a){super(e,a);}async uploadFile(e,a,r,o){let l={file:await ve(e),type:a,name:r,link:o};return this.request({httpMethod:"POST",url:"storage/v1/files",body:l})}};var ze=class{cashService;iamService;kakaoChannelService;kakaoTemplateService;groupService;messageService;storageService;getBalance;getBlacks;getBlockGroups;getBlockNumbers;getKakaoChannelCategories;getKakaoChannels;getKakaoChannel;requestKakaoChannelToken;createKakaoChannel;removeKakaoChannel;getKakaoAlimtalkTemplateCategories;createKakaoAlimtalkTemplate;getKakaoAlimtalkTemplates;getKakaoAlimtalkTemplate;cancelInspectionKakaoAlimtalkTemplate;updateKakaoAlimtalkTemplate;updateKakaoAlimtalkTemplateName;removeKakaoAlimtalkTemplate;createGroup;addMessagesToGroup;sendGroup;reserveGroup;removeReservationToGroup;getGroups;getGroup;getGroupMessages;removeGroupMessages;removeGroup;sendOne;send;getMessages;getStatistics;uploadFile;constructor(e,a){this.cashService=new z(e,a),this.iamService=new H(e,a),this.kakaoChannelService=new J(e,a),this.kakaoTemplateService=new Y(e,a),this.groupService=new Z(e,a),this.messageService=new ee(e,a),this.storageService=new te(e,a),this.bindServices([this.cashService,this.iamService,this.kakaoChannelService,this.kakaoTemplateService,this.groupService,this.messageService,this.storageService]);}bindServices(e){for(let a of e){let r=Object.getPrototypeOf(a),o=Object.getOwnPropertyNames(r).filter(i=>i!=="constructor"&&typeof r[i]=="function");for(let i of o){let l=i,h=a[i];this[l]=h.bind(a);}}}};exports.ApiError=L;exports.ApiKeyError=O;exports.BadRequestError=G;exports.DefaultError=I;exports.InvalidDateError=w;exports.MessageNotReceivedError=N;exports.NetworkError=q;exports.SolapiMessageService=ze;