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