Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sms77-client

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sms77-client - npm Package Compare versions

Comparing version 2.4.2 to 2.5.0

dist/constants/byEndpoint/analytics.d.ts

8

dist/BaseClient.d.ts

@@ -1,7 +0,5 @@

import { Endpoint } from './constants/enums/Endpoint';
import { Endpoint } from './constants/Endpoint';
import { AnyObject } from './types';
declare const METHODS: readonly ["get", "post"];
export declare type Response<R> = R | string;
export declare type Method = (typeof METHODS)[number];
export declare type MethodArgs = [Endpoint, AnyObject | undefined | null];
declare type Response<R> = R | string;
declare type MethodArgs = [Endpoint, AnyObject | undefined | null];
export declare type MethodCall = <R>(...a: MethodArgs) => Promise<Response<R>>;

@@ -8,0 +6,0 @@ interface HttpMethods {

@@ -1,2 +0,2 @@

import { Contact, PricingResponseJson, StatusResponseJson, VoiceResponseJson } from '../types';
import { Contact, PricingResponseJson, StatusResponseJson } from '../types';
export default class TextTransformer {

@@ -6,3 +6,2 @@ static contacts(csv: string): Contact[];

static status(text: string): StatusResponseJson;
static voice(text: string): VoiceResponseJson;
}

@@ -38,3 +38,4 @@ "use strict";

TextTransformer.contacts = function (csv) {
return Util_1["default"].csvToArray(csv, false).map(function (_a) {
return Util_1["default"].csvToArray(csv, false)
.map(function (_a) {
var _b = __read(_a, 3), id = _b[0], nick = _b[1], number = _b[2];

@@ -100,12 +101,4 @@ return ({

};
TextTransformer.voice = function (text) {
var _a = __read(Util_1["default"].splitByLine(text), 3), code = _a[0], id = _a[1], cost = _a[2];
return {
code: Number.parseInt(code),
cost: Number.parseFloat(cost),
id: Number.parseInt(id)
};
};
return TextTransformer;
}());
exports["default"] = TextTransformer;

@@ -12,3 +12,7 @@ "use strict";

Util.toNumberedBool = function (value) {
return 'boolean' === typeof value ? value ? 1 : 0 : value;
return typeof value === 'boolean'
? value
? 1
: 0
: value;
};

@@ -15,0 +19,0 @@ Util.splitByLine = function (str) {

@@ -84,4 +84,4 @@ (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){

exports.BaseClient = void 0;
var ERROR_CODES_1 = require("./constants/ERROR_CODES");
var Util_1 = __importDefault(require("./lib/Util"));
var ErrorCode_1 = require("./constants/ErrorCode");
var METHODS = ['get', 'post'];

@@ -209,4 +209,4 @@ var BaseClient = /** @class */ (function () {

}
if (apiCode && ERROR_CODES_1.ERROR_CODES.has(apiCode)) {
throw new Error(apiCode + ": " + ERROR_CODES_1.ERROR_CODES.get(apiCode));
if (apiCode && apiCode in ErrorCode_1.ErrorCode) {
throw new Error(apiCode + ": " + ErrorCode_1.ErrorCode[apiCode]);
}

@@ -223,3 +223,3 @@ return [2 /*return*/, body];

},{"./constants/ERROR_CODES":4,"./lib/Util":9}],3:[function(require,module,exports){
},{"./constants/ErrorCode":5,"./lib/Util":9}],3:[function(require,module,exports){
"use strict";

@@ -309,7 +309,7 @@ var __extends = (this && this.__extends) || (function () {

exports.__esModule = true;
var SUCCESS_CODES_1 = require("./constants/SUCCESS_CODES");
var BaseClient_1 = require("./BaseClient");
var Endpoint_1 = require("./constants/enums/Endpoint");
var Endpoint_1 = require("./constants/Endpoint");
var TextTransformer_1 = __importDefault(require("./lib/TextTransformer"));
var ContactsAction_1 = require("./constants/enums/ContactsAction");
var ContactsAction_1 = require("./constants/byEndpoint/contacts/ContactsAction");
var ContactsResponseCode_1 = require("./constants/byEndpoint/contacts/ContactsResponseCode");
__exportStar(require("./types"), exports);

@@ -340,3 +340,3 @@ var Sms77Client = /** @class */ (function (_super) {

args = [Endpoint_1.Endpoint.Contacts, p];
method = p.action === ContactsAction_1.ContactsAction.Del ? this.post : this.get;
method = p.action === ContactsAction_1.ContactsAction.Delete ? this.post : this.get;
return [4 /*yield*/, method.apply(void 0, __spread(args))];

@@ -355,3 +355,4 @@ case 1:

if (typeof res === 'object') {
if (SUCCESS_CODES_1.SUCCESS_CODES.has(Number.parseInt(res["return"]))) {
if (Object.values(ContactsResponseCode_1.ContactsResponseCode)
.includes(Number.parseInt(res["return"]))) {
if (res.id) {

@@ -418,13 +419,8 @@ return [2 /*return*/, Number.parseInt(res.id)];

}); };
_this.voice = function (p) { return __awaiter(_this, void 0, void 0, function () {
var res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.post(Endpoint_1.Endpoint.Voice, p)];
case 1:
res = _a.sent();
return [2 /*return*/, p._json ? TextTransformer_1["default"].voice(res) : res];
}
});
}); };
_this.voice = function (p) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.post(Endpoint_1.Endpoint.Voice, p)];
case 1: return [2 /*return*/, _a.sent()];
}
}); }); };
return _this;

@@ -436,29 +432,20 @@ }

},{"./BaseClient":2,"./constants/SUCCESS_CODES":5,"./constants/enums/ContactsAction":6,"./constants/enums/Endpoint":7,"./lib/TextTransformer":8,"./types":10}],4:[function(require,module,exports){
},{"./BaseClient":2,"./constants/Endpoint":4,"./constants/byEndpoint/contacts/ContactsAction":6,"./constants/byEndpoint/contacts/ContactsResponseCode":7,"./lib/TextTransformer":8,"./types":13}],4:[function(require,module,exports){
"use strict";
exports.__esModule = true;
exports.ERROR_CODES = void 0;
exports.ERROR_CODES = new Map([
[201, 'Country code invalid.'],
[202, 'Recipient number invalid.'],
[300, 'Authentication missing.'],
[301, 'Parameter to missing.'],
[304, 'Parameter type missing.'],
[305, 'Parameter text missing.'],
[306, 'Sender invalid.'],
[307, 'Parameter url missing.'],
[400, 'Invalid type.'],
[401, 'Parameter text too long.'],
[402, 'Reload lock.'],
[500, 'Not enough credits.'],
[600, 'Carrier failed.'],
[700, 'Unknown error.'],
[801, 'Logo file missing.'],
[802, 'Logo file not existent.'],
[803, 'Ring tone missing.'],
[900, 'Wrong API key!'],
[901, 'Wrong message ID.'],
[902, 'API deactivated.'],
[903, 'IP not allowed.'],
]);
exports.Endpoint = void 0;
var Endpoint;
(function (Endpoint) {
Endpoint["Analytics"] = "analytics";
Endpoint["Balance"] = "balance";
Endpoint["Contacts"] = "contacts";
Endpoint["Hooks"] = "hooks";
Endpoint["Lookup"] = "lookup";
Endpoint["Journal"] = "journal";
Endpoint["Pricing"] = "pricing";
Endpoint["Sms"] = "sms";
Endpoint["Status"] = "status";
Endpoint["ValidateForVoice"] = "validate_for_voice";
Endpoint["Voice"] = "voice";
})(Endpoint = exports.Endpoint || (exports.Endpoint = {}));

@@ -468,7 +455,27 @@ },{}],5:[function(require,module,exports){

exports.__esModule = true;
exports.SUCCESS_CODES = void 0;
exports.SUCCESS_CODES = new Map([
[151, 'Contacts updated/created/deleted with CSV response.'],
[152, 'Contacts updated/created/deleted with JSON response.'],
]);
exports.ErrorCode = void 0;
var ErrorCode;
(function (ErrorCode) {
ErrorCode[ErrorCode["InvalidCountryCode"] = 201] = "InvalidCountryCode";
ErrorCode[ErrorCode["InvalidRecipientNumber"] = 202] = "InvalidRecipientNumber";
ErrorCode[ErrorCode["MissingAuthentication"] = 300] = "MissingAuthentication";
ErrorCode[ErrorCode["MissingParameterTo"] = 301] = "MissingParameterTo";
ErrorCode[ErrorCode["MissingParameterType"] = 304] = "MissingParameterType";
ErrorCode[ErrorCode["MissingParameterText"] = 305] = "MissingParameterText";
ErrorCode[ErrorCode["InvalidSender"] = 306] = "InvalidSender";
ErrorCode[ErrorCode["MissingParameterUrl"] = 307] = "MissingParameterUrl";
ErrorCode[ErrorCode["InvalidType"] = 400] = "InvalidType";
ErrorCode[ErrorCode["ParameterLongExceedsCharLimit"] = 401] = "ParameterLongExceedsCharLimit";
ErrorCode[ErrorCode["PreventedByReloadLock"] = 402] = "PreventedByReloadLock";
ErrorCode[ErrorCode["InsufficientCredits"] = 500] = "InsufficientCredits";
ErrorCode[ErrorCode["CarrierFailed"] = 600] = "CarrierFailed";
ErrorCode[ErrorCode["UnknownError"] = 700] = "UnknownError";
ErrorCode[ErrorCode["MissingLogoFile"] = 801] = "MissingLogoFile";
ErrorCode[ErrorCode["NonExistingLogoFile"] = 802] = "NonExistingLogoFile";
ErrorCode[ErrorCode["MissingRingTone"] = 803] = "MissingRingTone";
ErrorCode[ErrorCode["InvalidApiKey"] = 900] = "InvalidApiKey";
ErrorCode[ErrorCode["InvalidMessageId"] = 901] = "InvalidMessageId";
ErrorCode[ErrorCode["DeactivatedApi"] = 902] = "DeactivatedApi";
ErrorCode[ErrorCode["DisallowedIp"] = 903] = "DisallowedIp";
})(ErrorCode = exports.ErrorCode || (exports.ErrorCode = {}));

@@ -481,3 +488,3 @@ },{}],6:[function(require,module,exports){

(function (ContactsAction) {
ContactsAction["Del"] = "del";
ContactsAction["Delete"] = "del";
ContactsAction["Read"] = "read";

@@ -490,17 +497,8 @@ ContactsAction["Write"] = "write";

exports.__esModule = true;
exports.Endpoint = void 0;
var Endpoint;
(function (Endpoint) {
Endpoint["Analytics"] = "analytics";
Endpoint["Balance"] = "balance";
Endpoint["Contacts"] = "contacts";
Endpoint["Hooks"] = "hooks";
Endpoint["Lookup"] = "lookup";
Endpoint["Journal"] = "journal";
Endpoint["Pricing"] = "pricing";
Endpoint["Sms"] = "sms";
Endpoint["Status"] = "status";
Endpoint["ValidateForVoice"] = "validate_for_voice";
Endpoint["Voice"] = "voice";
})(Endpoint = exports.Endpoint || (exports.Endpoint = {}));
exports.ContactsResponseCode = void 0;
var ContactsResponseCode;
(function (ContactsResponseCode) {
ContactsResponseCode[ContactsResponseCode["Error"] = 151] = "Error";
ContactsResponseCode[ContactsResponseCode["Success"] = 152] = "Success";
})(ContactsResponseCode = exports.ContactsResponseCode || (exports.ContactsResponseCode = {}));

@@ -545,3 +543,4 @@ },{}],8:[function(require,module,exports){

TextTransformer.contacts = function (csv) {
return Util_1["default"].csvToArray(csv, false).map(function (_a) {
return Util_1["default"].csvToArray(csv, false)
.map(function (_a) {
var _b = __read(_a, 3), id = _b[0], nick = _b[1], number = _b[2];

@@ -607,10 +606,2 @@ return ({

};
TextTransformer.voice = function (text) {
var _a = __read(Util_1["default"].splitByLine(text), 3), code = _a[0], id = _a[1], cost = _a[2];
return {
code: Number.parseInt(code),
cost: Number.parseFloat(cost),
id: Number.parseInt(id)
};
};
return TextTransformer;

@@ -632,3 +623,7 @@ }());

Util.toNumberedBool = function (value) {
return 'boolean' === typeof value ? value ? 1 : 0 : value;
return typeof value === 'boolean'
? value
? 1
: 0
: value;
};

@@ -668,3 +663,45 @@ Util.splitByLine = function (str) {

},{}]},{},[1])(1)
},{}],11:[function(require,module,exports){
arguments[4][10][0].apply(exports,arguments)
},{"dup":10}],12:[function(require,module,exports){
arguments[4][10][0].apply(exports,arguments)
},{"dup":10}],13:[function(require,module,exports){
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
exports.__esModule = true;
__exportStar(require("./analytics"), exports);
__exportStar(require("./contacts"), exports);
__exportStar(require("./hooks"), exports);
__exportStar(require("./journal"), exports);
__exportStar(require("./lookup"), exports);
__exportStar(require("./pricing"), exports);
__exportStar(require("./sms"), exports);
__exportStar(require("./status"), exports);
__exportStar(require("./validateForVoice"), exports);
__exportStar(require("./voice"), exports);
},{"./analytics":10,"./contacts":11,"./hooks":12,"./journal":14,"./lookup":15,"./pricing":16,"./sms":17,"./status":18,"./validateForVoice":19,"./voice":20}],14:[function(require,module,exports){
arguments[4][10][0].apply(exports,arguments)
},{"dup":10}],15:[function(require,module,exports){
arguments[4][10][0].apply(exports,arguments)
},{"dup":10}],16:[function(require,module,exports){
arguments[4][10][0].apply(exports,arguments)
},{"dup":10}],17:[function(require,module,exports){
arguments[4][10][0].apply(exports,arguments)
},{"dup":10}],18:[function(require,module,exports){
arguments[4][10][0].apply(exports,arguments)
},{"dup":10}],19:[function(require,module,exports){
arguments[4][10][0].apply(exports,arguments)
},{"dup":10}],20:[function(require,module,exports){
arguments[4][10][0].apply(exports,arguments)
},{"dup":10}]},{},[1])(1)
});
import { SmsParams } from '../../types';
export declare const DEFAULT_PATTERN: RegExp;
export declare const DELAY_DATE_FORMAT = "yyyy-mm-dd hh:ii";
export declare const DELAY_PATTERN: RegExp;
export declare const LABEL_PATTERN: RegExp;
export declare const FOREIGN_ID_MAX_LENGTH = 64;
export declare const FOREIGN_ID_PATTERN: RegExp;
export declare const FROM_ALLOWED_SPECIAL_CHARS: string[];
export declare const FROM_ALPHANUMERIC_MAX = 11;
export declare const FROM_NUMERIC_MAX = 16;
export declare const FROM_ALLOWED_SPECIAL_CHARS: string[];
export declare const LABEL_MAX_LENGTH = 100;
export declare const LABEL_PATTERN: RegExp;
export declare const TEXT_MAX_LENGTH = 1520;
export declare const TTL_MIN = 300000;
export declare const TTL_MAX = 86400000;
export declare const TTL_MAX: number;
export declare const TTL_MIN = 1;
declare const _default: (params: SmsParams) => void;
export default _default;
export declare const foreign_id: (foreignId: SmsParams['foreign_id']) => void;
export declare const from: (from: SmsParams['from']) => void;

@@ -14,0 +19,0 @@ export declare const label: (label: SmsParams['label']) => void;

@@ -17,16 +17,21 @@ "use strict";

exports.__esModule = true;
exports.delay = exports.ttl = exports.to = exports.text = exports.label = exports.from = exports.TTL_MAX = exports.TTL_MIN = exports.TEXT_MAX_LENGTH = exports.FROM_ALLOWED_SPECIAL_CHARS = exports.FROM_NUMERIC_MAX = exports.FROM_ALPHANUMERIC_MAX = exports.LABEL_PATTERN = exports.DELAY_PATTERN = exports.DELAY_DATE_FORMAT = void 0;
exports.delay = exports.ttl = exports.to = exports.text = exports.label = exports.from = exports.foreign_id = exports.TTL_MIN = exports.TTL_MAX = exports.TEXT_MAX_LENGTH = exports.LABEL_PATTERN = exports.LABEL_MAX_LENGTH = exports.FROM_NUMERIC_MAX = exports.FROM_ALPHANUMERIC_MAX = exports.FROM_ALLOWED_SPECIAL_CHARS = exports.FOREIGN_ID_PATTERN = exports.FOREIGN_ID_MAX_LENGTH = exports.DELAY_PATTERN = exports.DELAY_DATE_FORMAT = exports.DEFAULT_PATTERN = void 0;
var isValid_1 = __importDefault(require("date-fns/isValid"));
var Util_1 = __importDefault(require("../../lib/Util"));
exports.DEFAULT_PATTERN = /[0-9a-z-@_.]/i;
exports.DELAY_DATE_FORMAT = 'yyyy-mm-dd hh:ii';
exports.DELAY_PATTERN = /^([0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/;
exports.LABEL_PATTERN = /[0-9a-z-@_.]/i;
exports.FOREIGN_ID_MAX_LENGTH = 64;
exports.FOREIGN_ID_PATTERN = exports.DEFAULT_PATTERN;
exports.FROM_ALLOWED_SPECIAL_CHARS = ['/', ' ', '.', '-', '@', '_', '!', '(', ')', '+', '$', ',', '&',];
exports.FROM_ALPHANUMERIC_MAX = 11;
exports.FROM_NUMERIC_MAX = 16;
exports.FROM_ALLOWED_SPECIAL_CHARS = ['/', ' ', '.', '-', '@', '_', '!', '(', ')', '+', '$', ',', '&',];
exports.LABEL_MAX_LENGTH = 100;
exports.LABEL_PATTERN = exports.DEFAULT_PATTERN;
exports.TEXT_MAX_LENGTH = 1520;
exports.TTL_MIN = 300000;
exports.TTL_MAX = 86400000;
exports.TTL_MAX = Number.MAX_SAFE_INTEGER;
exports.TTL_MIN = 1;
exports["default"] = (function (params) {
exports.delay(params.delay);
exports.foreign_id(params.foreign_id);
exports.from(params.from);

@@ -38,2 +43,14 @@ exports.label(params.label);

});
var foreign_id = function (foreignId) {
if (!foreignId) {
return;
}
if (foreignId.match(exports.FOREIGN_ID_PATTERN)) {
throw new Error("foreign_id must match the regex pattern " + exports.FOREIGN_ID_PATTERN + ".");
}
if (exports.FOREIGN_ID_MAX_LENGTH < foreignId.length) {
throw new Error("The foreign_id cannot be longer than " + exports.FOREIGN_ID_MAX_LENGTH + " characters.");
}
};
exports.foreign_id = foreign_id;
var from = function (from) {

@@ -69,3 +86,2 @@ var e_1, _a;

var label = function (label) {
//TODO: max length?! there must be one.
if (!label) {

@@ -77,2 +93,5 @@ return;

}
if (exports.LABEL_MAX_LENGTH < label.length) {
throw new Error("The label cannot be longer than " + exports.LABEL_MAX_LENGTH + " characters.");
}
};

@@ -79,0 +98,0 @@ exports.label = label;

@@ -9,3 +9,3 @@ {

"@types/node": "^12.12.6",
"@types/node-fetch": "^2.5.7",
"@types/node-fetch": "^2.5.8",
"@types/globalthis": "^1.0.1",

@@ -19,4 +19,4 @@ "@types/uuid": "^8.3.0",

"tsify": "^5.0.2",
"typescript": "^4.1.2",
"uuid": "^8.3.1"
"typescript": "^4.1.3",
"uuid": "^8.3.2"
},

@@ -56,4 +56,4 @@ "files": [

"types": "dist/Sms77Client.d.ts",
"version": "2.4.2",
"version": "2.5.0",
"homepage": "https://github.com/sms77io/js-client"
}

@@ -9,6 +9,4 @@ ![Sms77.io Logo](https://www.sms77.io/wp-content/uploads/2019/07/sms77-Logo-400x79.png "Sms77.io Logo")

**Yarn** ```yarn add sms77-client node-fetch```
**NPM** ```npm install sms77-client node-fetch``` **Yarn** ```yarn add sms77-client node-fetch```
**NPM** ```npm install sms77-client node-fetch```
**Browser**

@@ -25,6 +23,19 @@ ```html

new Client('MY_SUPER_SECRET_SMS77_IO_API_KEY!')
new Sms77Client('MY_SUPER_SECRET_SMS77_IO_API_KEY!')
.balance()
.then(balance => console.log(`My balance is: ${balance}`))
.catch(error => console.error(`Error while fetching: ${balance}`));
```
```
#### Tests
1. ```git clone https://github.com/sms77io/js-client```
2. ```cd js-client && npm install```
3. ```SMS77_API_KEY=InsertSms77ApiKey npm run test```
Set ```SMS77_LIVE_TEST=1``` for live tests performing actual http requests.
Set ```SMS77_DEBUG=1``` for details printed to stdout.
##### Support
Need help? Feel free to send us an <a href='mailto: support@sms77.io'>email</a>.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc