sms77-client
Advanced tools
Comparing version 2.8.0 to 2.9.0
@@ -14,7 +14,7 @@ import { Endpoint } from './constants/Endpoint'; | ||
protected debug: boolean; | ||
static readonly BASE_URL = "https://gateway.sms77.io/api"; | ||
constructor(apiKey: string, sentWith?: string, debug?: boolean); | ||
get: <R>(a_0: Endpoint, a_1: AnyObject | null | undefined) => Promise<Response<R>>; | ||
post: <R>(a_0: Endpoint, a_1: AnyObject | null | undefined) => Promise<Response<R>>; | ||
private assertIs; | ||
static readonly BASE_URL = "https://gateway.sms77.io/api"; | ||
constructor(apiKey: string, sentWith?: string, debug?: boolean); | ||
private request; | ||
@@ -21,0 +21,0 @@ private normalizePayload; |
@@ -86,3 +86,6 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Sms77Client = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ | ||
var ErrorCode_1 = require("./constants/ErrorCode"); | ||
var METHODS = ['get', 'post']; | ||
var METHODS = [ | ||
'get', | ||
'post' | ||
]; | ||
var BaseClient = /** @class */ (function () { | ||
@@ -117,3 +120,6 @@ function BaseClient(apiKey, sentWith, debug) { | ||
var _b = __read(_a, 2), k = _b[0], v = _b[1]; | ||
return [k, Util_1["default"].toNumberedBool(v)]; | ||
return [ | ||
k, | ||
Util_1["default"].toNumberedBool(v) | ||
]; | ||
})); }; | ||
@@ -156,3 +162,3 @@ this.assertIs(this); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url, opts, entries, params_1, res, body, apiCode, parsed; | ||
var url, opts, entries, params_1, res, body, apiCode, type, parsed; | ||
return __generator(this, function (_d) { | ||
@@ -175,6 +181,20 @@ switch (_d.label) { | ||
var _b = __read(_a, 2), k = _b[0], v = _b[1]; | ||
return params_1.set(k, v); | ||
if (Array.isArray(v)) { | ||
v.forEach(function (i, n) { | ||
// is likely SmsFile | ||
if (typeof i === 'object' && 'contents' in i && 'name' in i) { | ||
var prepend = "files[" + n + "]"; | ||
params_1.set(prepend + "[contents]", i.contents); | ||
params_1.set(prepend + "[name]", i.name); | ||
} | ||
else { | ||
params_1.append(k, i); | ||
} | ||
}); | ||
} | ||
else { | ||
params_1.set(k, v); | ||
} | ||
})); | ||
'get' === method | ||
? url += "?" + params_1.toString() : opts.body = params_1; | ||
'get' === method ? url += "?" + params_1.toString() : opts.body = params_1; | ||
} | ||
@@ -187,2 +207,3 @@ return [4 /*yield*/, fetch(url, opts)]; | ||
body = _d.sent(); | ||
apiCode = null; | ||
if (typeof body === 'string') { | ||
@@ -192,6 +213,7 @@ try { | ||
} | ||
catch (e) { } | ||
finally { | ||
} | ||
} | ||
apiCode = null; | ||
if (typeof body === 'string' || typeof body === 'number') { | ||
type = typeof body; | ||
if (type === 'string' || type === 'number') { | ||
parsed = Number.parseFloat("" + body); | ||
@@ -337,30 +359,25 @@ if (Number.isInteger(parsed)) { | ||
_this.contacts = function (p) { return __awaiter(_this, void 0, void 0, function () { | ||
var args, method, res, type, isCSV, isCode; | ||
var args, method, res; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
args = [Endpoint_1.Endpoint.Contacts, p]; | ||
method = p.action === ContactsAction_1.ContactsAction.Delete ? this.post : this.get; | ||
args = [ | ||
Endpoint_1.Endpoint.Contacts, | ||
p | ||
]; | ||
method = ContactsAction_1.ContactsAction.Delete === p.action ? this.post : this.get; | ||
return [4 /*yield*/, method.apply(void 0, __spread(args))]; | ||
case 1: | ||
res = _a.sent(); | ||
type = typeof res; | ||
isCSV = type === 'string'; | ||
isCode = type === 'number'; | ||
if (isCSV || isCode) { | ||
if (Array.isArray(res)) { | ||
return [2 /*return*/, res]; | ||
} | ||
else if (Array.isArray(res)) { | ||
return [2 /*return*/, res]; | ||
} | ||
if (typeof res === 'object') { | ||
if (Object.values(ContactsResponseCode_1.ContactsResponseCode) | ||
.includes(Number.parseInt(res["return"]))) { | ||
if (res.id) { | ||
return [2 /*return*/, Number.parseInt(res.id)]; | ||
} | ||
else if (p.id) { | ||
return [2 /*return*/, p.id]; | ||
} | ||
if (typeof res === 'object' && | ||
Object.values(ContactsResponseCode_1.ContactsResponseCode).includes(Number.parseInt(res["return"]))) { | ||
if (res.id) { | ||
return [2 /*return*/, Number.parseInt(res.id)]; | ||
} | ||
if (undefined !== p.id) { | ||
return [2 /*return*/, p.id]; | ||
} | ||
} | ||
@@ -367,0 +384,0 @@ return [2 /*return*/, res]; |
@@ -8,2 +8,6 @@ import { SMS_DEBUG_VALUES, SMS_ENCODINGS, SMS_SIGNATURE_POSITIONS, SMS_TYPES } from '../constants/byEndpoint/sms'; | ||
}; | ||
export declare type SmsFile = { | ||
contents: string; | ||
name: string; | ||
}; | ||
export declare type SmsMessage = { | ||
@@ -31,2 +35,3 @@ encoding: typeof SMS_ENCODINGS[number]; | ||
details?: boolean; | ||
files?: SmsFile[]; | ||
flash?: boolean; | ||
@@ -33,0 +38,0 @@ foreign_id?: string; |
@@ -20,5 +20,5 @@ { | ||
"node-fetch": "^2.6.1", | ||
"ts-jest": "^26.5.1", | ||
"ts-jest": "^26.5.4", | ||
"tsify": "^5.0.2", | ||
"typescript": "^4.1.5", | ||
"typescript": "^4.2.3", | ||
"uuid": "^8.3.2" | ||
@@ -64,4 +64,4 @@ }, | ||
"types": "dist/Sms77Client.d.ts", | ||
"version": "2.8.0", | ||
"version": "2.9.0", | ||
"homepage": "https://github.com/sms77io/js-client" | ||
} |
![Sms77.io Logo](https://www.sms77.io/wp-content/uploads/2019/07/sms77-Logo-400x79.png "Sms77.io Logo") | ||
# JavaScript API Client for the Sms77.io SMS Gateway | ||
# Official JavaScript API Client for the Sms77.io SMS Gateway | ||
## Installation | ||
**This library relies on the global fetch API. | ||
To use this library with Node.js, [node-fetch](https://github.com/node-fetch/node-fetch) is required.** | ||
**This library relies on the global fetch API. To use this library with | ||
Node.js, [node-fetch](https://github.com/node-fetch/node-fetch) is required.** | ||
For compatibility with Node.js versions < 12, please also install the [globalThis polyfill](https://github.com/es-shims/globalThis). | ||
For compatibility with Node.js versions < 12, please also install | ||
the [globalThis polyfill](https://github.com/es-shims/globalThis). | ||
@@ -39,4 +40,4 @@ ### Installation using NPM | ||
.balance() | ||
.then((balance) => console.log(`My balance is: ${balance}`)) | ||
.catch((error) => console.error(`Error while fetching: ${balance}`)); | ||
.then(balance => console.log(`Current balance: ${balance}`)) | ||
.catch(console.error); | ||
``` | ||
@@ -54,4 +55,6 @@ | ||
## Support | ||
### Support | ||
Need help? Feel free to send us an <a href='mailto: support@sms77.io'>email</a>. | ||
Need help? Feel free to [contact us](https://www.sms77.io/en/company/contact/). | ||
[![MIT](https://img.shields.io/badge/License-MIT-teal.svg)](./LICENSE) |
81444
1961
58