Comparing version
@@ -1,7 +0,9 @@ | ||
import { QueueFaxParams, QueueFaxResponse } from './types'; | ||
import { QueueFaxResponse } from './types'; | ||
/** | ||
* Submits a fax to the SRFax QUEUE_FAX API | ||
* @param {QueueFaxParams} params The raw parameters for enqueueing a fax | ||
* @param {any} params The raw parameters for enqueueing a fax. | ||
* These should be a combination of {QueueFaxParams} and | ||
* any pairs of file names and contents. | ||
* @returns {Promise<QueueFaxResponse>} | ||
*/ | ||
export declare function queueFax(params: QueueFaxParams): Promise<QueueFaxResponse>; | ||
export declare function queueFax(params: any): Promise<QueueFaxResponse>; |
@@ -0,1 +1,5 @@ | ||
export interface QueueFaxFileContents { | ||
name: string; | ||
content: string; | ||
} | ||
export interface QueueFaxParams { | ||
@@ -19,4 +23,2 @@ action: 'Queue_Fax'; | ||
sCPComments?: string; | ||
sFileName_1?: string; | ||
sFileContent_1?: string; | ||
sNotifyURL?: string; | ||
@@ -23,0 +25,0 @@ sQueueFaxDate?: string; |
@@ -1,2 +0,2 @@ | ||
import { QueueFaxParams, QueueFaxResponse } from '../api/types'; | ||
import { QueueFaxFileContents, QueueFaxParams, QueueFaxResponse } from '../api/types'; | ||
declare abstract class SRFaxRequest<T> { | ||
@@ -7,5 +7,6 @@ abstract submit(): Promise<T>; | ||
private params; | ||
constructor(params: QueueFaxParams); | ||
private files; | ||
constructor(params: QueueFaxParams, files?: QueueFaxFileContents[]); | ||
submit(): Promise<QueueFaxResponse>; | ||
} | ||
export {}; |
@@ -25,4 +25,3 @@ import { QueueFaxRequest } from '../request/request'; | ||
private CPSubject?; | ||
private fileName?; | ||
private fileContent?; | ||
private files?; | ||
private notifyURL?; | ||
@@ -46,5 +45,3 @@ private queueFaxDate?; | ||
setCoverPageComments(comments: string): QueueFaxRequestBuilder; | ||
setFileName(fileName: string): QueueFaxRequestBuilder; | ||
setFileContent(fileContent: string): QueueFaxRequestBuilder; | ||
setFile(filePath: string): QueueFaxRequestBuilder; | ||
addFile(name: string, content: string): QueueFaxRequestBuilder; | ||
setNotifyURL(url: string): QueueFaxRequestBuilder; | ||
@@ -51,0 +48,0 @@ setQueueFaxDate(date: string): QueueFaxRequestBuilder; |
@@ -8,4 +8,2 @@ 'use strict'; | ||
var axios = _interopDefault(require('axios')); | ||
var path = _interopDefault(require('path')); | ||
var fs = _interopDefault(require('fs')); | ||
@@ -60,2 +58,20 @@ /** | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function _inheritsLoose(subClass, superClass) { | ||
@@ -833,3 +849,5 @@ subClass.prototype = Object.create(superClass.prototype); | ||
* Submits a fax to the SRFax QUEUE_FAX API | ||
* @param {QueueFaxParams} params The raw parameters for enqueueing a fax | ||
* @param {any} params The raw parameters for enqueueing a fax. | ||
* These should be a combination of {QueueFaxParams} and | ||
* any pairs of file names and contents. | ||
* @returns {Promise<QueueFaxResponse>} | ||
@@ -874,3 +892,3 @@ */ | ||
function QueueFaxRequest(params) { | ||
function QueueFaxRequest(params, files) { | ||
var _this; | ||
@@ -880,2 +898,3 @@ | ||
_this.params = params; | ||
_this.files = files || []; | ||
return _this; | ||
@@ -888,2 +907,3 @@ } | ||
var _submit = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() { | ||
var fileParams, i; | ||
return runtime_1.wrap(function _callee$(_context) { | ||
@@ -893,5 +913,14 @@ while (1) { | ||
case 0: | ||
return _context.abrupt("return", queueFax(this.params)); | ||
fileParams = {}; | ||
case 1: | ||
if (this.files && this.files.length > 0) { | ||
for (i = 0; i < this.files.length; i++) { | ||
fileParams["sFileName_" + i] = this.files[i].name; | ||
fileParams["sFileContent_" + i] = this.files[i].content; | ||
} | ||
} | ||
return _context.abrupt("return", queueFax(_extends({}, this.params, fileParams))); | ||
case 3: | ||
case "end": | ||
@@ -924,3 +953,7 @@ return _context.stop(); | ||
function QueueFaxRequestBuilder(accessId, accessPwd) { | ||
return _RequestBuilder.call(this, accessId, accessPwd, 'Queue_Fax') || this; | ||
var _this; | ||
_this = _RequestBuilder.call(this, accessId, accessPwd, 'Queue_Fax') || this; | ||
_this.files = []; | ||
return _this; | ||
} | ||
@@ -1026,17 +1059,10 @@ | ||
_proto.setFileName = function setFileName(fileName) { | ||
this.fileName = fileName; | ||
return this; | ||
}; | ||
_proto.addFile = function addFile(name, content) { | ||
if (!this.files) { | ||
this.files = []; | ||
} | ||
_proto.setFileContent = function setFileContent(fileContent) { | ||
this.fileContent = fileContent; | ||
return this; | ||
}; | ||
_proto.setFile = function setFile(filePath) { | ||
this.fileName = path.basename(filePath); | ||
this.fileContent = fs.readFileSync(filePath, { | ||
encoding: 'base64', | ||
flag: 'r' | ||
this.files.push({ | ||
name: name, | ||
content: content | ||
}); | ||
@@ -1080,3 +1106,3 @@ return this; | ||
return new QueueFaxRequest({ | ||
var params = { | ||
action: 'Queue_Fax', | ||
@@ -1099,8 +1125,7 @@ access_id: this.accessId, | ||
sCPComments: this.CPComments, | ||
sFileName_1: this.fileName, | ||
sFileContent_1: this.fileContent, | ||
sNotifyURL: this.notifyURL, | ||
sQueueFaxDate: this.queueFaxDate, | ||
sQueueFaxTime: this.queueFaxTime | ||
}); | ||
}; | ||
return new QueueFaxRequest(params, this.files); | ||
}; | ||
@@ -1107,0 +1132,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e=t(require("axios")),r=t(require("path")),n=t(require("fs"));function o(){return e.create({baseURL:"https://www.srfax.com/SRF_SecWebSvc.php"})}function i(t,e,r,n,o,i,a){try{var s=t[i](a),u=s.value}catch(t){return void r(t)}s.done?e(u):Promise.resolve(u).then(n,o)}function a(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var a=t.apply(e,r);function s(t){i(a,n,o,s,u,"next",t)}function u(t){i(a,n,o,s,u,"throw",t)}s(void 0)}))}}function s(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,(Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var u,c=(function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function u(t,e,r,n){var o=Object.create((e&&e.prototype instanceof f?e:f).prototype),i=new C(n||[]);return o._invoke=function(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var s=w(a,r);if(s){if(s===h)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=c(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===h)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(t,r,i),o}function c(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var h={};function f(){}function l(){}function p(){}var d={};d[o]=function(){return this};var m=Object.getPrototypeOf,v=m&&m(m(P([])));v&&v!==e&&r.call(v,o)&&(d=v);var y=p.prototype=f.prototype=Object.create(d);function g(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function x(t,e){var n;this._invoke=function(o,i){function a(){return new e((function(n,a){!function n(o,i,a,s){var u=c(t[o],t,i);if("throw"!==u.type){var h=u.arg,f=h.value;return f&&"object"==typeof f&&r.call(f,"__await")?e.resolve(f.__await).then((function(t){n("next",t,a,s)}),(function(t){n("throw",t,a,s)})):e.resolve(f).then((function(t){h.value=t,a(h)}),(function(t){return n("throw",t,a,s)}))}s(u.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function w(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,w(t,e),"throw"===e.method))return h;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return h}var n=c(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,h;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,h):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,h)}function F(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function b(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function C(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(F,this),this.reset(!0)}function P(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return i.next=i}}return{next:L}}function L(){return{value:void 0,done:!0}}return l.prototype=y.constructor=p,p.constructor=l,l.displayName=s(p,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===l||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,s(t,a,"GeneratorFunction")),t.prototype=Object.create(y),t},t.awrap=function(t){return{__await:t}},g(x.prototype),x.prototype[i]=function(){return this},t.AsyncIterator=x,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new x(u(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},g(y),s(y,a,"Generator"),y[o]=function(){return this},y.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=P,C.prototype={constructor:C,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(b),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var s=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(s&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,h):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),h},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),b(r),h}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;b(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:P(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),h}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}}(u={exports:{}}),u.exports);function h(t){return f.apply(this,arguments)}function f(){return(f=a(c.mark((function t(e){var r;return c.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=o(),t.next=3,r.post("",e);case 3:return t.abrupt("return",t.sent.data);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}var l=function(t){function e(e){var r;return(r=t.call(this)||this).params=e,r}return s(e,t),e.prototype.submit=function(){var t=a(c.mark((function t(){return c.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",h(this.params));case 1:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),e}((function(){})),p=function(t){function e(e,r){return t.call(this,e,r,"Queue_Fax")||this}s(e,t);var o=e.prototype;return o.setCallerId=function(t){return this.callerId=t,this},o.setSenderEmail=function(t){return this.senderEmail=t,this},o.setFaxType=function(t){switch(t){case"single":this.faxType="SINGLE";break;case"broadcast":this.faxType="BROADCAST"}return this},o.setToFaxNumber=function(t){return this.toFaxNumber=t,this},o.setResponseFormat=function(t){switch(t){case"json":this.responseFormat="JSON";break;case"xml":this.responseFormat="XML"}return this},o.setAccountCode=function(t){return this.accountCode=t,this},o.setRetries=function(t){if(t<0||t>6)throw new Error("invalid number of retries");return this.retries=t,this},o.setCoverPage=function(t){return this.coverPage=t,this},o.setFaxFromHeader=function(t){if(t.length>50)throw new Error("From header too long");return this.faxFromHeader=t,this},o.setCoverPageFromName=function(t){return this.CPFromName=t,this},o.setCoverPageToName=function(t){return this.CPToName=t,this},o.setCoverPageSubject=function(t){return this.CPSubject=t,this},o.setCoverPageOrg=function(t){return this.CPOrganization=t,this},o.setCoverPageComments=function(t){return this.CPComments=t,this},o.setFileName=function(t){return this.fileName=t,this},o.setFileContent=function(t){return this.fileContent=t,this},o.setFile=function(t){return this.fileName=r.basename(t),this.fileContent=n.readFileSync(t,{encoding:"base64",flag:"r"}),this},o.setNotifyURL=function(t){return this.notifyURL=t,this},o.setQueueFaxDate=function(t){return this.queueFaxDate=t,this},o.setQueueFaxTime=function(t){return this.queueFaxTime=t,this},o.setQueueFaxDateTime=function(t){if(t<new Date)throw new Error("Queue date must be in the future");var e=t.getMonth()>9?""+t.getMonth():"0"+t.getMonth(),r=t.getDate()>9?""+t.getDate():"0"+t.getDate();this.queueFaxDate=t.getFullYear()+"-"+e+"-"+r;var n=t.getHours()>9?""+t.getHours():"0"+t.getHours(),o=t.getMinutes()>9?""+t.getMinutes():"0"+t.getMinutes();return this.queueFaxTime=n+":"+o,this},o.build=function(){if(void 0===this.callerId||!this.senderEmail||!this.toFaxNumber||!this.faxType)throw new Error("missing required attribute");return new l({action:"Queue_Fax",access_id:this.accessId,access_pwd:this.accessPwd,sCallerID:this.callerId,sSenderEmail:this.senderEmail,sToFaxNumber:this.toFaxNumber,sFaxType:this.faxType,sResponseFormat:this.responseFormat,sAccountCode:this.accountCode,sRetries:this.retries,sCoverPage:this.coverPage,sFaxFromHeader:this.faxFromHeader,sCPFromName:this.CPFromName,sCPToName:this.CPToName,sCPOrganization:this.CPOrganization,sCPSubject:this.CPSubject,sCPComments:this.CPComments,sFileName_1:this.fileName,sFileContent_1:this.fileContent,sNotifyURL:this.notifyURL,sQueueFaxDate:this.queueFaxDate,sQueueFaxTime:this.queueFaxTime})},e}((function(t,e,r){this.action=r,this.accessId=t,this.accessPwd=e}));exports.QueueFaxRequest=l,exports.QueueFaxRequestBuilder=p,exports.getClient=o,exports.queueFax=h; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e=(t=require("axios"))&&"object"==typeof t&&"default"in t?t.default:t;function r(){return e.create({baseURL:"https://www.srfax.com/SRF_SecWebSvc.php"})}function n(t,e,r,n,o,i,a){try{var s=t[i](a),u=s.value}catch(t){return void r(t)}s.done?e(u):Promise.resolve(u).then(n,o)}function o(t){return function(){var e=this,r=arguments;return new Promise((function(o,i){var a=t.apply(e,r);function s(t){n(a,o,i,s,u,"next",t)}function u(t){n(a,o,i,s,u,"throw",t)}s(void 0)}))}}function i(){return(i=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function a(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,(Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var s,u=(function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function u(t,e,r,n){var o=Object.create((e&&e.prototype instanceof f?e:f).prototype),i=new P(n||[]);return o._invoke=function(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var s=w(a,r);if(s){if(s===h)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=c(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===h)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(t,r,i),o}function c(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var h={};function f(){}function l(){}function p(){}var d={};d[o]=function(){return this};var v=Object.getPrototypeOf,m=v&&v(v(C([])));m&&m!==e&&r.call(m,o)&&(d=m);var y=p.prototype=f.prototype=Object.create(d);function g(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function x(t,e){var n;this._invoke=function(o,i){function a(){return new e((function(n,a){!function n(o,i,a,s){var u=c(t[o],t,i);if("throw"!==u.type){var h=u.arg,f=h.value;return f&&"object"==typeof f&&r.call(f,"__await")?e.resolve(f.__await).then((function(t){n("next",t,a,s)}),(function(t){n("throw",t,a,s)})):e.resolve(f).then((function(t){h.value=t,a(h)}),(function(t){return n("throw",t,a,s)}))}s(u.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function w(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,w(t,e),"throw"===e.method))return h;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return h}var n=c(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,h;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,h):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,h)}function F(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function b(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function P(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(F,this),this.reset(!0)}function C(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return i.next=i}}return{next:L}}function L(){return{value:void 0,done:!0}}return l.prototype=y.constructor=p,p.constructor=l,l.displayName=s(p,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===l||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,s(t,a,"GeneratorFunction")),t.prototype=Object.create(y),t},t.awrap=function(t){return{__await:t}},g(x.prototype),x.prototype[i]=function(){return this},t.AsyncIterator=x,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new x(u(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},g(y),s(y,a,"Generator"),y[o]=function(){return this},y.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=C,P.prototype={constructor:P,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(b),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var s=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(s&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,h):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),h},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),b(r),h}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;b(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:C(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),h}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}}(s={exports:{}}),s.exports);function c(t){return h.apply(this,arguments)}function h(){return(h=o(u.mark((function t(e){var n;return u.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=r(),t.next=3,n.post("",e);case 3:return t.abrupt("return",t.sent.data);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}var f=function(t){function e(e,r){var n;return(n=t.call(this)||this).params=e,n.files=r||[],n}return a(e,t),e.prototype.submit=function(){var t=o(u.mark((function t(){var e,r;return u.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(e={},this.files&&this.files.length>0)for(r=0;r<this.files.length;r++)e["sFileName_"+r]=this.files[r].name,e["sFileContent_"+r]=this.files[r].content;return t.abrupt("return",c(i({},this.params,e)));case 3:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),e}((function(){})),l=function(t){function e(e,r){var n;return(n=t.call(this,e,r,"Queue_Fax")||this).files=[],n}a(e,t);var r=e.prototype;return r.setCallerId=function(t){return this.callerId=t,this},r.setSenderEmail=function(t){return this.senderEmail=t,this},r.setFaxType=function(t){switch(t){case"single":this.faxType="SINGLE";break;case"broadcast":this.faxType="BROADCAST"}return this},r.setToFaxNumber=function(t){return this.toFaxNumber=t,this},r.setResponseFormat=function(t){switch(t){case"json":this.responseFormat="JSON";break;case"xml":this.responseFormat="XML"}return this},r.setAccountCode=function(t){return this.accountCode=t,this},r.setRetries=function(t){if(t<0||t>6)throw new Error("invalid number of retries");return this.retries=t,this},r.setCoverPage=function(t){return this.coverPage=t,this},r.setFaxFromHeader=function(t){if(t.length>50)throw new Error("From header too long");return this.faxFromHeader=t,this},r.setCoverPageFromName=function(t){return this.CPFromName=t,this},r.setCoverPageToName=function(t){return this.CPToName=t,this},r.setCoverPageSubject=function(t){return this.CPSubject=t,this},r.setCoverPageOrg=function(t){return this.CPOrganization=t,this},r.setCoverPageComments=function(t){return this.CPComments=t,this},r.addFile=function(t,e){return this.files||(this.files=[]),this.files.push({name:t,content:e}),this},r.setNotifyURL=function(t){return this.notifyURL=t,this},r.setQueueFaxDate=function(t){return this.queueFaxDate=t,this},r.setQueueFaxTime=function(t){return this.queueFaxTime=t,this},r.setQueueFaxDateTime=function(t){if(t<new Date)throw new Error("Queue date must be in the future");var e=t.getMonth()>9?""+t.getMonth():"0"+t.getMonth(),r=t.getDate()>9?""+t.getDate():"0"+t.getDate();this.queueFaxDate=t.getFullYear()+"-"+e+"-"+r;var n=t.getHours()>9?""+t.getHours():"0"+t.getHours(),o=t.getMinutes()>9?""+t.getMinutes():"0"+t.getMinutes();return this.queueFaxTime=n+":"+o,this},r.build=function(){if(void 0===this.callerId||!this.senderEmail||!this.toFaxNumber||!this.faxType)throw new Error("missing required attribute");return new f({action:"Queue_Fax",access_id:this.accessId,access_pwd:this.accessPwd,sCallerID:this.callerId,sSenderEmail:this.senderEmail,sToFaxNumber:this.toFaxNumber,sFaxType:this.faxType,sResponseFormat:this.responseFormat,sAccountCode:this.accountCode,sRetries:this.retries,sCoverPage:this.coverPage,sFaxFromHeader:this.faxFromHeader,sCPFromName:this.CPFromName,sCPToName:this.CPToName,sCPOrganization:this.CPOrganization,sCPSubject:this.CPSubject,sCPComments:this.CPComments,sNotifyURL:this.notifyURL,sQueueFaxDate:this.queueFaxDate,sQueueFaxTime:this.queueFaxTime},this.files)},e}((function(t,e,r){this.action=r,this.accessId=t,this.accessPwd=e}));exports.QueueFaxRequest=f,exports.QueueFaxRequestBuilder=l,exports.getClient=r,exports.queueFax=c; | ||
//# sourceMappingURL=srfax-node.cjs.production.min.js.map |
import axios from 'axios'; | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
@@ -53,2 +51,20 @@ /** | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function _inheritsLoose(subClass, superClass) { | ||
@@ -826,3 +842,5 @@ subClass.prototype = Object.create(superClass.prototype); | ||
* Submits a fax to the SRFax QUEUE_FAX API | ||
* @param {QueueFaxParams} params The raw parameters for enqueueing a fax | ||
* @param {any} params The raw parameters for enqueueing a fax. | ||
* These should be a combination of {QueueFaxParams} and | ||
* any pairs of file names and contents. | ||
* @returns {Promise<QueueFaxResponse>} | ||
@@ -867,3 +885,3 @@ */ | ||
function QueueFaxRequest(params) { | ||
function QueueFaxRequest(params, files) { | ||
var _this; | ||
@@ -873,2 +891,3 @@ | ||
_this.params = params; | ||
_this.files = files || []; | ||
return _this; | ||
@@ -881,2 +900,3 @@ } | ||
var _submit = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() { | ||
var fileParams, i; | ||
return runtime_1.wrap(function _callee$(_context) { | ||
@@ -886,5 +906,14 @@ while (1) { | ||
case 0: | ||
return _context.abrupt("return", queueFax(this.params)); | ||
fileParams = {}; | ||
case 1: | ||
if (this.files && this.files.length > 0) { | ||
for (i = 0; i < this.files.length; i++) { | ||
fileParams["sFileName_" + i] = this.files[i].name; | ||
fileParams["sFileContent_" + i] = this.files[i].content; | ||
} | ||
} | ||
return _context.abrupt("return", queueFax(_extends({}, this.params, fileParams))); | ||
case 3: | ||
case "end": | ||
@@ -917,3 +946,7 @@ return _context.stop(); | ||
function QueueFaxRequestBuilder(accessId, accessPwd) { | ||
return _RequestBuilder.call(this, accessId, accessPwd, 'Queue_Fax') || this; | ||
var _this; | ||
_this = _RequestBuilder.call(this, accessId, accessPwd, 'Queue_Fax') || this; | ||
_this.files = []; | ||
return _this; | ||
} | ||
@@ -1019,17 +1052,10 @@ | ||
_proto.setFileName = function setFileName(fileName) { | ||
this.fileName = fileName; | ||
return this; | ||
}; | ||
_proto.addFile = function addFile(name, content) { | ||
if (!this.files) { | ||
this.files = []; | ||
} | ||
_proto.setFileContent = function setFileContent(fileContent) { | ||
this.fileContent = fileContent; | ||
return this; | ||
}; | ||
_proto.setFile = function setFile(filePath) { | ||
this.fileName = path.basename(filePath); | ||
this.fileContent = fs.readFileSync(filePath, { | ||
encoding: 'base64', | ||
flag: 'r' | ||
this.files.push({ | ||
name: name, | ||
content: content | ||
}); | ||
@@ -1073,3 +1099,3 @@ return this; | ||
return new QueueFaxRequest({ | ||
var params = { | ||
action: 'Queue_Fax', | ||
@@ -1092,8 +1118,7 @@ access_id: this.accessId, | ||
sCPComments: this.CPComments, | ||
sFileName_1: this.fileName, | ||
sFileContent_1: this.fileContent, | ||
sNotifyURL: this.notifyURL, | ||
sQueueFaxDate: this.queueFaxDate, | ||
sQueueFaxTime: this.queueFaxTime | ||
}); | ||
}; | ||
return new QueueFaxRequest(params, this.files); | ||
}; | ||
@@ -1100,0 +1125,0 @@ |
{ | ||
"version": "0.1.4", | ||
"version": "1.0.0", | ||
"license": "MIT", | ||
@@ -4,0 +4,0 @@ "main": "dist/index.js", |
@@ -1,2 +0,2 @@ | ||
import { QueueFaxParams, QueueFaxResponse } from './types'; | ||
import { QueueFaxResponse } from './types'; | ||
import { getClient } from './client'; | ||
@@ -6,8 +6,8 @@ | ||
* Submits a fax to the SRFax QUEUE_FAX API | ||
* @param {QueueFaxParams} params The raw parameters for enqueueing a fax | ||
* @param {any} params The raw parameters for enqueueing a fax. | ||
* These should be a combination of {QueueFaxParams} and | ||
* any pairs of file names and contents. | ||
* @returns {Promise<QueueFaxResponse>} | ||
*/ | ||
export async function queueFax( | ||
params: QueueFaxParams | ||
): Promise<QueueFaxResponse> { | ||
export async function queueFax(params: any): Promise<QueueFaxResponse> { | ||
const client = getClient(); | ||
@@ -14,0 +14,0 @@ const { data } = await client.post<QueueFaxResponse>('', params); |
@@ -0,1 +1,6 @@ | ||
export interface QueueFaxFileContents { | ||
name: string; | ||
content: string; | ||
} | ||
export interface QueueFaxParams { | ||
@@ -19,4 +24,2 @@ action: 'Queue_Fax'; | ||
sCPComments?: string; | ||
sFileName_1?: string; | ||
sFileContent_1?: string; | ||
sNotifyURL?: string; | ||
@@ -23,0 +26,0 @@ sQueueFaxDate?: string; |
import { queueFax } from '../api'; | ||
import { QueueFaxParams, QueueFaxResponse } from '../api/types'; | ||
import { | ||
QueueFaxFileContents, | ||
QueueFaxParams, | ||
QueueFaxResponse, | ||
} from '../api/types'; | ||
@@ -10,11 +14,21 @@ abstract class SRFaxRequest<T> { | ||
private params: QueueFaxParams; | ||
private files: QueueFaxFileContents[]; | ||
constructor(params: QueueFaxParams) { | ||
constructor(params: QueueFaxParams, files?: QueueFaxFileContents[]) { | ||
super(); | ||
this.params = params; | ||
this.files = files || []; | ||
} | ||
async submit(): Promise<QueueFaxResponse> { | ||
return queueFax(this.params); | ||
const fileParams: any = {}; | ||
if (this.files && this.files.length > 0) { | ||
for (let i = 0; i < this.files.length; i++) { | ||
fileParams[`sFileName_${i}`] = this.files[i].name; | ||
fileParams[`sFileContent_${i}`] = this.files[i].content; | ||
} | ||
} | ||
return queueFax({ ...this.params, ...fileParams }); | ||
} | ||
} |
import { QueueFaxRequest } from '../request/request'; | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import { QueueFaxFileContents, QueueFaxParams } from '../api'; | ||
abstract class RequestBuilder<T> { | ||
@@ -38,4 +37,3 @@ protected action: string; | ||
private CPSubject?: string; | ||
private fileName?: string; | ||
private fileContent?: string; | ||
private files?: QueueFaxFileContents[]; | ||
private notifyURL?: string; | ||
@@ -47,2 +45,3 @@ private queueFaxDate?: string; | ||
super(accessId, accessPwd, 'Queue_Fax'); | ||
this.files = []; | ||
} | ||
@@ -140,21 +139,10 @@ | ||
setFileName(fileName: string): QueueFaxRequestBuilder { | ||
this.fileName = fileName; | ||
addFile(name: string, content: string): QueueFaxRequestBuilder { | ||
if (!this.files) { | ||
this.files = []; | ||
} | ||
this.files.push({ name, content }); | ||
return this; | ||
} | ||
setFileContent(fileContent: string): QueueFaxRequestBuilder { | ||
this.fileContent = fileContent; | ||
return this; | ||
} | ||
setFile(filePath: string): QueueFaxRequestBuilder { | ||
this.fileName = path.basename(filePath); | ||
this.fileContent = fs.readFileSync(filePath, { | ||
encoding: 'base64', | ||
flag: 'r', | ||
}); | ||
return this; | ||
} | ||
setNotifyURL(url: string): QueueFaxRequestBuilder { | ||
@@ -203,3 +191,3 @@ this.notifyURL = url; | ||
return new QueueFaxRequest({ | ||
const params: QueueFaxParams = { | ||
action: 'Queue_Fax', | ||
@@ -222,9 +210,9 @@ access_id: this.accessId, | ||
sCPComments: this.CPComments, | ||
sFileName_1: this.fileName, | ||
sFileContent_1: this.fileContent, | ||
sNotifyURL: this.notifyURL, | ||
sQueueFaxDate: this.queueFaxDate, | ||
sQueueFaxTime: this.queueFaxTime, | ||
}); | ||
}; | ||
return new QueueFaxRequest(params, this.files); | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
261007
1.08%2346
1.96%2
-33.33%3
-50%