diff --git a/package.json b/package.json index da2da89..ac4771a 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,10 @@ { "name": "smsc", - "version": "2.0.0", + "version": "2.0.1", "description": "Vodafone & SMSC.ru api", "type": "module", "main": "./src/index.js", + "types": "./types/index.d.ts", "exports": { ".": "./src/index.js" }, @@ -48,6 +49,7 @@ "node": ">=18.0.0" }, "files": [ - "src" + "src", + "types" ] } diff --git a/src/index.js b/src/index.js index e22a50e..b7ae297 100644 --- a/src/index.js +++ b/src/index.js @@ -3,7 +3,16 @@ import { isProd } from '@nitra/isenv' const charset = 'utf-8' -// Отправка CMC +/** + * Отправка CMC + * + * @param {String} phones + * @param {String} message + * @param {String} sender + * @param {Number} distributionId + * + * @return {Promise<{cnt: number?,error_code:number? }>} результат отправки + */ export const sendSms = async (phones, message, sender = null, distributionId = null) => { let data @@ -132,7 +141,12 @@ const masks = { 999: 'ru' } -// получить страну по коду оператора из телефона +/** + * Получить страну по коду оператора из телефона + * + * @param {String} phone + * @return {String} ua или ru + */ export const getCountry = phone => { const mask = phone.slice(-10, -7) if (mask && masks[mask]) { @@ -242,9 +256,8 @@ const sendFromSmsc = async (phones, message, sender) => { method: 'POST', body: params }) - const data = await response.json() - return data + return response.json() } catch (err) { console.error(err) return err diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..7f2f724 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,5 @@ +export function sendSms(phones: string, message: string, sender?: string, distributionId?: number): Promise<{ + cnt: number; + error_code: number | null; +}>; +export function getCountry(phone: string): string; diff --git a/types/keyv.d.ts b/types/keyv.d.ts new file mode 100644 index 0000000..130c22c --- /dev/null +++ b/types/keyv.d.ts @@ -0,0 +1 @@ +export const keyv: any;