eurobate-sms
Advanced tools
Comparing version 0.1.4 to 0.1.5
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.sendSMS = void 0; | ||
var axios_1 = require("axios"); | ||
@@ -4,0 +5,0 @@ function sendSMS(params) { |
import { IOEither } from "fp-ts/lib/IOEither"; | ||
import { EnonicError } from 'enonic-fp/lib/errors'; | ||
import { EurobateParams, EurobateResponse } from "./index"; | ||
export declare function json(str: string): IOEither<EnonicError, any>; | ||
export declare function sendSMS(params: EurobateParams): IOEither<EnonicError, EurobateResponse>; | ||
export declare function fromNullable<E>(e: E): <A>(a: A | null | undefined) => IOEither<E, A>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fromNullable = exports.sendSMS = void 0; | ||
var Either_1 = require("fp-ts/lib/Either"); | ||
var IOEither_1 = require("fp-ts/lib/IOEither"); | ||
var EI = require("fp-ts/lib/Either"); | ||
var pipeable_1 = require("fp-ts/lib/pipeable"); | ||
var http_1 = require("enonic-fp/lib/http"); | ||
function json(str) { | ||
return IOEither_1.fromEither(Either_1.parseJSON(str, function (reason) { return ({ | ||
errorKey: "BadGatewayError", | ||
cause: String(reason) | ||
}); })); | ||
} | ||
exports.json = json; | ||
function sendSMS(params) { | ||
var requestParams = { | ||
return pipeable_1.pipe(http_1.request({ | ||
url: 'https://api.eurobate.com/json_api.php', | ||
@@ -22,8 +17,22 @@ method: 'POST', | ||
readTimeout: 5000 | ||
}), IOEither_1.map(function (res) { return res.body; }), IOEither_1.chain(fromNullable(createBadGatewayError("No response body from Eurobate"))), IOEither_1.chain(function (body) { | ||
return IOEither_1.fromEither(Either_1.parseJSON(body, createBadGatewayError)); | ||
}), IOEither_1.filterOrElse(isEurobateResponse, createBadGatewayError)); | ||
} | ||
exports.sendSMS = sendSMS; | ||
function createBadGatewayError(reason) { | ||
return { | ||
errorKey: "BadGatewayError", | ||
cause: String(reason) | ||
}; | ||
return pipeable_1.pipe(http_1.request(requestParams), IOEither_1.chain(function (res) { return json(res.body); }), IOEither_1.filterOrElse(function (res) { return res.STATUS !== 'ERROR'; }, function (e) { return ({ | ||
errorKey: "BadGatewayError", | ||
cause: String(e) | ||
}); })); | ||
} | ||
exports.sendSMS = sendSMS; | ||
function isEurobateResponse(res) { | ||
return res !== undefined | ||
&& res !== null | ||
&& Array.isArray(res.messages) | ||
&& res.STATUS !== 'ERROR'; | ||
} | ||
function fromNullable(e) { | ||
return function (a) { return IOEither_1.fromEither(EI.fromNullable(e)(a)); }; | ||
} | ||
exports.fromNullable = fromNullable; |
import { EurobateParams, EurobateMessage, EurobateResponse, EurobateMessageResponse } from './eurobate'; | ||
import { sendSMS } from './axios'; | ||
import { sendSMS } from './enonic'; | ||
export { EurobateParams, EurobateMessage, EurobateResponse, EurobateMessageResponse, sendSMS }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var axios_1 = require("./axios"); | ||
exports.sendSMS = axios_1.sendSMS; | ||
exports.sendSMS = void 0; | ||
var enonic_1 = require("./enonic"); | ||
Object.defineProperty(exports, "sendSMS", { enumerable: true, get: function () { return enonic_1.sendSMS; } }); |
{ | ||
"name": "eurobate-sms", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "Wrapper around the Eurobate APIs for JavaScript and TypeScript", | ||
@@ -10,4 +10,6 @@ "main": "lib/index.js", | ||
"scripts": { | ||
"clean": "rimraf lib/* es6/*", | ||
"build": "npm run clean && tsc && tsc -p tsconfig.es6.json" | ||
"clean": "rimraf lib/* bin/*", | ||
"build": "npm run clean && tsc", | ||
"lint": "eslint --fix --ext .ts ./src", | ||
"prepublishOnly": "npm run lint && npm run build" | ||
}, | ||
@@ -20,11 +22,14 @@ "repository": { | ||
"dependencies": { | ||
"axios": "^0.19.0", | ||
"enonic-fp": "^0.2.7", | ||
"enonic-types": "^0.0.12", | ||
"fp-ts": "^2.1.1" | ||
"axios": "^0.19.2", | ||
"enonic-fp": "^0.2.46", | ||
"enonic-types": "^0.0.68", | ||
"fp-ts": "2.6.1" | ||
}, | ||
"devDependencies": { | ||
"rimraf": "^3.0.0", | ||
"typescript": "^3.6.4" | ||
"@typescript-eslint/eslint-plugin": "^3.4.0", | ||
"@typescript-eslint/parser": "^3.4.0", | ||
"eslint": "^7.3.1", | ||
"rimraf": "^3.0.2", | ||
"typescript": "^3.9.5" | ||
} | ||
} |
7460
5
13
92
+ Addedenonic-types@0.0.68(transitive)
+ Addedfp-ts@2.6.1(transitive)
- Removedenonic-types@0.0.12(transitive)
Updatedaxios@^0.19.2
Updatedenonic-fp@^0.2.46
Updatedenonic-types@^0.0.68
Updatedfp-ts@2.6.1