vesal
Version:
Armaghan Vesal SMS API client for JS/TS/ESM/Node.js
3 lines (2 loc) • 6.42 kB
JavaScript
function e(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(e=function(){return!!t})()}function t(){return t=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},t.apply(this,arguments)}function r(e){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},r(e)}function n(e,t){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},n(e,t)}function o(t){var i="function"==typeof Map?new Map:void 0;return o=function(t){if(null===t||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==i){if(i.has(t))return i.get(t);i.set(t,o)}function o(){return function(t,r,o){if(e())return Reflect.construct.apply(null,arguments);var i=[null];i.push.apply(i,r);var s=new(t.bind.apply(t,i));return o&&n(s,o.prototype),s}(t,arguments,r(this).constructor)}return o.prototype=Object.create(t.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),n(o,t)},o(t)}var i;function s(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var c=/*#__PURE__*/function(){function e(e,t,r){return this.apiUrl="http://vesal.armaghan.net:8080/rest",this.username=void 0,this.password=void 0,this.from=void 0,this.username=e||"",this.password=t,this.from=r,this}var r=e.prototype;return r.Api=function(e,r,n){void 0===r&&(r="POST");try{var o,i,c=function(e){function t(e){if(!i.references)throw new a(void 0,"The server didn't respond correctly");return i}var r=s(function(){return Promise.resolve(o.json()).then(function(e){i=e})},function(){throw new a(void 0,"The server didn't respond correctly")});return r&&r.then?r.then(t):t()},u=this;n=t({},n,{username:u.username,password:u.password});var f=s(function(){return Promise.resolve(fetch(u.apiUrl+"/"+e,{headers:{Accept:"application/json","Content-Type":"application/json"},method:r,body:n&&JSON.stringify(n)})).then(function(e){o=e})},function(){throw new a(void 0,"Server connection failed")});return Promise.resolve(f&&f.then?f.then(c):c())}catch(e){return Promise.reject(e)}},r.Send=function(e){var r=e.recipients,n=e.messages,o=e.from;try{if(!r||!n)throw new a(void 0,"recipients and messages should not be empty");"string"==typeof r&&(r=[r]),o||(o=this.from);var i=Array.isArray(n)||Array.isArray(o);if(i){if(!r.length)throw new a(void 0,"recipients and messages should have the same length");if(Array.isArray(n)&&!n.length)throw new a(void 0,"recipients and messages should have the same length");if("string"==typeof n&&(n=Array(r.length).fill(n)),"string"==typeof o&&(o=Array(r.length).fill(o)),r.length!==n.length||r.length!==o.length)throw new a(void 0,"recipients and messages should have the same length")}var s=t({destinations:r},i?{originators:o}:{originator:o},i?{contents:n}:{content:n});return Promise.resolve(this.Api(i?"ManyToMany":"OneToMany","POST",s)).then(function(e){var r,n=0,o=0;return null==(r=e.references)||r.map(function(e){e?n++:o++}),t({},e,{references:e.references||[],count:{success:n,fail:o}})})}catch(e){return Promise.reject(e)}},r.GetMessageStatus=function(e){try{return Promise.resolve(this.Api("messageState","POST",{referenceids:e}))}catch(e){return Promise.reject(e)}},r.GetReceivedMessages=function(){try{return Promise.resolve(this.Api("pullReceivedMessages"))}catch(e){return Promise.reject(e)}},r.GetReceivedMessagesCount=function(){try{return Promise.resolve(this.Api("receivedMessageCount"))}catch(e){return Promise.reject(e)}},r.GetUserInfo=function(){try{return Promise.resolve(this.Api("userInfo"))}catch(e){return Promise.reject(e)}},e}(),a=/*#__PURE__*/function(e){var t,r;function o(t,r){var n,o,i;return t&&Object.keys(h).includes(""+t)?(o=u(t),i=t):(o=r||"Unknown Vesal error",i=void 0),(n=e.call(this,o)||this).status=void 0,n.message=o,n.status=i,n}return r=e,(t=o).prototype=Object.create(r.prototype),t.prototype.constructor=t,n(t,r),o}(/*#__PURE__*/o(Error));function u(e){return 0===e?"success":Object.keys(h).includes(""+e)?h[e]:""}var f={0:"پیامک در صف ارسال قرار دارد",1:"ارسال شده",2:"پیامک به موبایل گیرنده تحویل شده است",3:"پیامک به موبایل گیرنده تحویل نشده است",4:"وضعیت نامشخص",5:"پیامک توسط وب سرویس به شرکت ارمغان راه طلایی رسیده است",6:"پیام از سمت اپراتور لغو شده است",7:"پیام از سمت اپراتور منقضی شده است",8:"پیام از سمت اپراتور reject شده است"},h=((i={0:"عملیات با موفقیت انجام شد"})[-100]="refrenceId مورد نظر یافت نشد",i[-101]="احراز هویت کاربر موفقیت آمیز نبود",i[-102]="نام کاربری یافت نشد",i[-103]="شماره originator اشتباه یا در بازه شماره های کاربر نیست",i[-104]="اعتبار کم است",i[-105]="فرمت درخواست اشتباه است",i[-106]="تعداد refrenceId ها بیش از 1000 عدد است",i[-107]="شماره گیرنده پیامک اشتباه است",i[-109]="تاریخ انقضای حساب کاربری فرارسیده است",i[-110]="درخواست از ip مجاز کاربر ارسال نشده است",i[-111]="شماره گیرنده در بلک لیست قرار دارد",i[-112]="حساب مشتری فعال نیست",i[-115]="فرمت UDH اشتباه است",i[-117]="مقدار mclass وارد شده اشتباه است",i[-118]="شماره پورت وارد شده صحیح نیست",i[-119]="کاربر به سرویس مورد نظر دسترسی ندارد",i[-120]="پیام ارسال شده دارای هیچ شماره معتبری نیست",i[-200]="خطای داخلی در پایگاه داده رخ داده است",i[-201]="خطای نامشخص داخل پایگاه داده",i[-137]="پیام نباید حاوی کلمات غیرمجاز می باشد",i);export{u as GetStatusText,c as Vesal,a as VesalError,c as default,f as messageStates,h as vesalErrors};
//# sourceMappingURL=vesal.mjs.map