vesal
Version:
Armaghan Vesal SMS API client for JS/TS/ESM/Node.js
3 lines (2 loc) • 6.43 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 s="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!==s){if(s.has(t))return s.get(t);s.set(t,o)}function o(){return function(t,r,o){if(e())return Reflect.construct.apply(null,arguments);var s=[null];s.push.apply(s,r);var i=new(t.bind.apply(t,s));return o&&n(i,o.prototype),i}(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 s;function i(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,s,c=function(e){function t(e){if(!s.references)throw new a(void 0,"The server didn't respond correctly");return s}var r=i(function(){return Promise.resolve(o.json()).then(function(e){s=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=i(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 s=Array.isArray(n)||Array.isArray(o);if(s){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 i=t({destinations:r},s?{originators:o}:{originator:o},s?{contents:n}:{content:n});return Promise.resolve(this.Api(s?"ManyToMany":"OneToMany","POST",i)).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,s;return t&&Object.keys(f).includes(""+t)?(o=u(t),s=t):(o=r||"Unknown Vesal error",s=void 0),(n=e.call(this,o)||this).status=void 0,n.message=o,n.status=s,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(f).includes(""+e)?f[e]:""}var f=((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);exports.GetStatusText=u,exports.Vesal=c,exports.VesalError=a,exports.default=c,exports.messageStates={0:"پیامک در صف ارسال قرار دارد",1:"ارسال شده",2:"پیامک به موبایل گیرنده تحویل شده است",3:"پیامک به موبایل گیرنده تحویل نشده است",4:"وضعیت نامشخص",5:"پیامک توسط وب سرویس به شرکت ارمغان راه طلایی رسیده است",6:"پیام از سمت اپراتور لغو شده است",7:"پیام از سمت اپراتور منقضی شده است",8:"پیام از سمت اپراتور reject شده است"},exports.vesalErrors=f;
//# sourceMappingURL=vesal.cjs.map