@sap/async-xsjs 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/LICENSE +37 -0
  3. package/README.md +445 -0
  4. package/differences.md +162 -0
  5. package/docs/$.Application.html +262 -0
  6. package/docs/$.Session.html +674 -0
  7. package/docs/$.db.CallableStatement.html +2524 -0
  8. package/docs/$.db.Connection.html +511 -0
  9. package/docs/$.db.ParameterMetaData.html +805 -0
  10. package/docs/$.db.PreparedStatement.html +1796 -0
  11. package/docs/$.db.ResultSet.html +1308 -0
  12. package/docs/$.db.ResultSetMetaData.html +800 -0
  13. package/docs/$.db.SQLException.html +259 -0
  14. package/docs/$.db.html +773 -0
  15. package/docs/$.hdb.ColumnMetadata.html +438 -0
  16. package/docs/$.hdb.Connection.html +663 -0
  17. package/docs/$.hdb.ProcedureResult.html +280 -0
  18. package/docs/$.hdb.ResultSet.html +324 -0
  19. package/docs/$.hdb.ResultSetIterator.html +315 -0
  20. package/docs/$.hdb.ResultSetMetaData.html +259 -0
  21. package/docs/$.hdb.SQLException.html +259 -0
  22. package/docs/$.hdb.html +557 -0
  23. package/docs/$.html +471 -0
  24. package/docs/$.jobs.Job.html +783 -0
  25. package/docs/$.jobs.JobLog.html +380 -0
  26. package/docs/$.jobs.JobSchedules.html +852 -0
  27. package/docs/$.jobs.html +238 -0
  28. package/docs/$.net.Destination.html +304 -0
  29. package/docs/$.net.Mail.Part.html +510 -0
  30. package/docs/$.net.Mail.html +504 -0
  31. package/docs/$.net.SMTPConnection.html +347 -0
  32. package/docs/$.net.html +749 -0
  33. package/docs/$.net.http.Client.html +562 -0
  34. package/docs/$.net.http.Destination.html +237 -0
  35. package/docs/$.net.http.Request.html +567 -0
  36. package/docs/$.net.http.html +292 -0
  37. package/docs/$.security.AntiVirus.html +361 -0
  38. package/docs/$.security.Store.html +636 -0
  39. package/docs/$.security.crypto.html +414 -0
  40. package/docs/$.security.html +247 -0
  41. package/docs/$.security.x509.html +373 -0
  42. package/docs/$.text.analysis.Session.html +983 -0
  43. package/docs/$.text.analysis.html +242 -0
  44. package/docs/$.text.html +246 -0
  45. package/docs/$.text.mining.Session.html +2018 -0
  46. package/docs/$.text.mining.html +242 -0
  47. package/docs/$.trace.html +525 -0
  48. package/docs/$.util.SAXParser.html +955 -0
  49. package/docs/$.util.Zip.html +474 -0
  50. package/docs/$.util.codec.html +414 -0
  51. package/docs/$.util.compression.html +357 -0
  52. package/docs/$.util.html +325 -0
  53. package/docs/$.util.sql.html +290 -0
  54. package/docs/$.web.Body.html +333 -0
  55. package/docs/$.web.EntityList.html +296 -0
  56. package/docs/$.web.TupelList.html +496 -0
  57. package/docs/$.web.WebEntityRequest.html +393 -0
  58. package/docs/$.web.WebEntityResponse.html +392 -0
  59. package/docs/$.web.WebRequest.html +560 -0
  60. package/docs/$.web.WebResponse.html +609 -0
  61. package/docs/$.web.html +246 -0
  62. package/docs/Copyright-SAP.html +39 -0
  63. package/docs/Disclaimer-SAP.html +55 -0
  64. package/docs/index.html +232 -0
  65. package/docs/styles/jsdoc-default.css +382 -0
  66. package/lib/AppConfig.js +36 -0
  67. package/lib/AuditLogger.js +41 -0
  68. package/lib/cacert.js +26 -0
  69. package/lib/ctypes.js +153 -0
  70. package/lib/destinations/dest-provider.js +57 -0
  71. package/lib/index.js +235 -0
  72. package/lib/jobs/Action.js +40 -0
  73. package/lib/jobs/Job.js +100 -0
  74. package/lib/jobs/JobManager.js +150 -0
  75. package/lib/jobs/JobsRuntime.js +133 -0
  76. package/lib/jobs/SqlScriptJobRunner.js +36 -0
  77. package/lib/jobs/XsjsJobRunner.js +78 -0
  78. package/lib/jobs/index.js +11 -0
  79. package/lib/logging.js +16 -0
  80. package/lib/middleware.js +125 -0
  81. package/lib/odata/ODataService.js +125 -0
  82. package/lib/odata/index.js +7 -0
  83. package/lib/odata/service-factory.js +26 -0
  84. package/lib/passport-noauth.js +17 -0
  85. package/lib/routes.js +115 -0
  86. package/lib/runtime.js +740 -0
  87. package/lib/sandbox.js +40 -0
  88. package/lib/utils/XsJsFunctionRunner.js +57 -0
  89. package/lib/utils/XsJsLibFunctionRunner.js +57 -0
  90. package/lib/utils/buffer-utils.js +77 -0
  91. package/lib/utils/compression-utils.js +14 -0
  92. package/lib/utils/date-utils.js +104 -0
  93. package/lib/utils/errors/HttpError.js +20 -0
  94. package/lib/utils/errors/wrap-app-error.js +18 -0
  95. package/lib/utils/index.js +17 -0
  96. package/lib/utils/xs-function-runner.js +51 -0
  97. package/lib/utils/xs-types.js +21 -0
  98. package/lib/utils/xspath.js +36 -0
  99. package/lib/utils/xsstack.js +28 -0
  100. package/lib/views/error.html +28 -0
  101. package/lib/xsjs/Application.js +28 -0
  102. package/lib/xsjs/Locale.js +53 -0
  103. package/lib/xsjs/Session.js +31 -0
  104. package/lib/xsjs/constants.js +71 -0
  105. package/lib/xsjs/db/common/DbBase.js +85 -0
  106. package/lib/xsjs/db/common/DbOptions.js +163 -0
  107. package/lib/xsjs/db/common/arguments-validation.js +102 -0
  108. package/lib/xsjs/db/common/connection.js +12 -0
  109. package/lib/xsjs/db/common/enums.js +93 -0
  110. package/lib/xsjs/db/common/execute-batch.js +38 -0
  111. package/lib/xsjs/db/common/parse-time.js +139 -0
  112. package/lib/xsjs/db/dbapi/CallableStatement.js +192 -0
  113. package/lib/xsjs/db/dbapi/Connection.js +78 -0
  114. package/lib/xsjs/db/dbapi/DB.js +39 -0
  115. package/lib/xsjs/db/dbapi/ParameterMetaData.js +118 -0
  116. package/lib/xsjs/db/dbapi/PreparedStatement.js +78 -0
  117. package/lib/xsjs/db/dbapi/ResultSet.js +220 -0
  118. package/lib/xsjs/db/dbapi/ResultSetMetaData.js +116 -0
  119. package/lib/xsjs/db/dbapi/Statement.js +514 -0
  120. package/lib/xsjs/db/dbapi/conversions.js +113 -0
  121. package/lib/xsjs/db/dbapi/fetch-rows.js +32 -0
  122. package/lib/xsjs/db/hdbapi/Connection.js +525 -0
  123. package/lib/xsjs/db/hdbapi/HDB.js +32 -0
  124. package/lib/xsjs/db/hdbapi/ResultSetIterator.js +40 -0
  125. package/lib/xsjs/db/hdbapi/convert.js +77 -0
  126. package/lib/xsjs/db/hdbapi/table-string-parser.js +52 -0
  127. package/lib/xsjs/db/index.js +4 -0
  128. package/lib/xsjs/index.js +13 -0
  129. package/lib/xsjs/jobs/Job.js +228 -0
  130. package/lib/xsjs/jobs/Jobs.js +11 -0
  131. package/lib/xsjs/jobs/Logs.js +127 -0
  132. package/lib/xsjs/jobs/Schedule.js +110 -0
  133. package/lib/xsjs/jobs/Schedules.js +108 -0
  134. package/lib/xsjs/net/Destination.js +43 -0
  135. package/lib/xsjs/net/http/Client.js +220 -0
  136. package/lib/xsjs/net/http/HTTP.js +72 -0
  137. package/lib/xsjs/net/index.js +5 -0
  138. package/lib/xsjs/net/smtp/Mail.js +38 -0
  139. package/lib/xsjs/net/smtp/Part.js +30 -0
  140. package/lib/xsjs/net/smtp/SMTPConnection.js +39 -0
  141. package/lib/xsjs/net/smtp/index.js +18 -0
  142. package/lib/xsjs/net/smtp/nodemailer-util.js +77 -0
  143. package/lib/xsjs/require.js +39 -0
  144. package/lib/xsjs/security/AntiVirus.js +31 -0
  145. package/lib/xsjs/security/Store.js +119 -0
  146. package/lib/xsjs/security/crypto.js +23 -0
  147. package/lib/xsjs/security/index.js +5 -0
  148. package/lib/xsjs/security/x509.js +12 -0
  149. package/lib/xsjs/text/analysis/Session.js +128 -0
  150. package/lib/xsjs/text/index.js +30 -0
  151. package/lib/xsjs/text/mining/Session.js +82 -0
  152. package/lib/xsjs/trace/trace.js +41 -0
  153. package/lib/xsjs/util/SAXParser.js +174 -0
  154. package/lib/xsjs/util/Zip.js +220 -0
  155. package/lib/xsjs/util/codec.js +33 -0
  156. package/lib/xsjs/util/compression.js +24 -0
  157. package/lib/xsjs/util/index.js +22 -0
  158. package/lib/xsjs/web/BasicWebEntity.js +41 -0
  159. package/lib/xsjs/web/EntityList.js +11 -0
  160. package/lib/xsjs/web/TupelLists/CookiesTupelList.js +47 -0
  161. package/lib/xsjs/web/TupelLists/HeadersTupelList.js +55 -0
  162. package/lib/xsjs/web/TupelLists/ParametersTupelList.js +83 -0
  163. package/lib/xsjs/web/TupelLists/TupelListBase.js +45 -0
  164. package/lib/xsjs/web/WebBody.js +135 -0
  165. package/lib/xsjs/web/WebEntityRequest.js +40 -0
  166. package/lib/xsjs/web/WebEntityResponse.js +26 -0
  167. package/lib/xsjs/web/WebRequest.js +209 -0
  168. package/lib/xsjs/web/WebResponse.js +183 -0
  169. package/lib/xsjs/web/index.js +4 -0
  170. package/lib/xsjs/web/utils/HeadersParser.js +53 -0
  171. package/lib/xsjs/web/utils/HttpRequestParser.js +93 -0
  172. package/lib/xsjs/web/utils/MultipartParser.js +163 -0
  173. package/lib/xsjs/web/utils/MultipartResponseBuilder.js +73 -0
  174. package/lib/xsjs/web/utils/SetCookieParser.js +32 -0
  175. package/lib/xsjslib/TextBundleWrapper.js +46 -0
  176. package/lib/xsjslib/index.js +11 -0
  177. package/npm-shrinkwrap.json +11540 -0
  178. package/package.json +84 -0
@@ -0,0 +1,220 @@
1
+ 'use strict';
2
+
3
+ var util = require('util');
4
+ var qs = require('querystring');
5
+ var requestLib = require('request');
6
+ var _ = require('lodash');
7
+ var SAPPassport = require('@sap/e2e-trace').Passport;
8
+ var WebResponse = require('../../web/WebResponse');
9
+ var MultipartResponseBuilder = require('../../web/utils/MultipartResponseBuilder');
10
+ var contentTypeParser = require('content-type');
11
+
12
+ var methodMapping = {
13
+ // -1: 'INVALID',
14
+ 0: 'OPTIONS',
15
+ 1: 'GET',
16
+ 2: 'HEAD',
17
+ 3: 'POST',
18
+ 4: 'PUT',
19
+ 5: 'DELETE',
20
+ 6: 'TRACE',
21
+ 7: 'CONNECT',
22
+ 8: 'PATCH'
23
+ };
24
+
25
+ function Client(sapPassport) {
26
+ if (!(this instanceof Client)) {
27
+ return new Client(sapPassport);
28
+ }
29
+ this._response = null;
30
+ this._sapPassport = sapPassport;
31
+ }
32
+
33
+ Client.prototype.getResponse = async function () {
34
+ if (!this._response) {
35
+ throw new Error('Make an HTTP request before trying to get the response');
36
+ }
37
+ if (util.types.isPromise(this._response)) {
38
+ this._response = new WebResponse(await this._response);
39
+ }
40
+ return this._response;
41
+ };
42
+
43
+ Client.prototype.request = function (arg0, arg1, proxyOpt) {
44
+ this._response = null;
45
+ var options = {
46
+ headers: {},
47
+ timeout: 10000
48
+ };
49
+ if (this._sapPassport) {
50
+ var passport = new SAPPassport(this._sapPassport);
51
+ passport.update({
52
+ connectionID: '00000000000000000000000000000000',
53
+ connectionCounter: 0
54
+ });
55
+ options.headers[SAPPassport.HEADER_NAME] = passport.serialize();
56
+ }
57
+ if (_.isNumber(arg0)) {
58
+ processWebMethodAndUrl(options, arg0, arg1, proxyOpt);
59
+ } else if (_.isString(arg1)) {
60
+ processWebRequestAndUrl(options, arg0, arg1, proxyOpt);
61
+ } else {
62
+ processWebRequestAndDestination(options, arg0, arg1);
63
+ }
64
+
65
+ if (this._timeoutInMilliseconds) {
66
+ options.timeout = this._timeoutInMilliseconds;
67
+ }
68
+ this._response = new Promise ((resolve, reject) => {
69
+ requestLib(options, function(err, response) {
70
+ if (err) {
71
+ reject(err);
72
+ return;
73
+ }
74
+ resolve(response);
75
+ });
76
+ });
77
+ return this;
78
+ };
79
+
80
+ Client.prototype.setTimeout = function (timeout) {
81
+ this._timeoutInMilliseconds = timeout * 1000;
82
+ };
83
+
84
+ Client.prototype.close = function () {
85
+ };
86
+
87
+ Client.prototype.setTrustStore = function () {
88
+ throw new Error('Feature not supported!');
89
+ };
90
+
91
+ function processWebMethodAndUrl(options, webMethod, url, proxyOpt) {
92
+ options.url = url;
93
+ options.method = methodMapping[webMethod];
94
+ setProxy(options, proxyOpt);
95
+ }
96
+
97
+ function processWebRequestAndUrl(options, webRequest, url, proxyOpt) {
98
+ options.url = url;
99
+ useDataFromWebRequest(options, webRequest);
100
+ setProxy(options, proxyOpt);
101
+ }
102
+
103
+ function processWebRequestAndDestination(options, webRequest, destination) {
104
+ options.url = (destination.useSSL === true ? 'https://' : 'http://') + destination.host + ':' + destination.port;
105
+ if (destination.timeout) {
106
+ options.timeout = destination.timeout;
107
+ }
108
+ addPathPrefix(options, destination);
109
+ useDataFromWebRequest(options, webRequest);
110
+ setProxyFromDestination(options, destination);
111
+ setBasicAuthFromDestination(options, destination);
112
+ }
113
+
114
+ function useDataFromWebRequest(options, webRequest) {
115
+ options.method = methodMapping[webRequest.method];
116
+ addPath(options, webRequest);
117
+ addRequestParameters(options, webRequest);
118
+ handleEntities(options, webRequest);
119
+ addHeaders(options, webRequest);
120
+ addCookies(options, webRequest);
121
+ addBody(options, webRequest);
122
+ }
123
+
124
+ function handleEntities(options, webRequest) {
125
+ let multiPartHeader = webRequest.headers.get('content-type');
126
+ if (webRequest.entities.length > 0 && multiPartHeader && multiPartHeader.indexOf('multipart') > -1) {
127
+ let boundary = '';
128
+ if (multiPartHeader.indexOf('boundary') > -1) {
129
+ boundary = contentTypeParser.parse(multiPartHeader).parameters.boundary;
130
+ } else {
131
+ boundary = MultipartResponseBuilder.generateBoundary();
132
+ let multiPartHeaderWithBoundary = `${multiPartHeader};boundary=${boundary}`;
133
+ webRequest.headers.set('content-type', multiPartHeaderWithBoundary);
134
+ }
135
+
136
+ if (multiPartHeader.indexOf('related') > -1) {
137
+ options.multipart = [];
138
+ webRequest.entities.forEach(entity => {
139
+ options.multipart.push({
140
+ 'content-type': entity.contentType,
141
+ body: entity.body._content
142
+ });
143
+ });
144
+ } else {
145
+ throw new Error('Multipart/form-data and Multi-part/mixed are not supported!');
146
+ }
147
+ }
148
+ }
149
+
150
+ function addPath(options, webRequest) {
151
+ if (webRequest.path) {
152
+ if (options.url.charAt(options.url.length - 1) !== '/' && webRequest.path.charAt(0) !== '/') {
153
+ options.url += '/';
154
+ }
155
+ options.url += webRequest.path;
156
+ }
157
+ }
158
+
159
+ function addRequestParameters(options, webRequest) {
160
+ if (webRequest.parameters.length > 0) {
161
+ if (options.url.indexOf('?') !== -1) {
162
+ options.url += '&';
163
+ } else {
164
+ options.url += '?';
165
+ }
166
+ options.url += qs.encode(webRequest.parameters.reduce(function (p, n) { p[n.name] = n.value; return p; }, {}));
167
+ }
168
+ }
169
+
170
+ function addHeaders(options, webRequest) {
171
+ webRequest.headers.forEach(function (header) {
172
+ options.headers[header.name] = header.value;
173
+ });
174
+ }
175
+
176
+ function addCookies(options, webRequest) {
177
+ options.headers.Cookie = webRequest.cookies.map(function (cookie) {
178
+ return cookie.name + '=' + cookie.value;
179
+ }).join('; ');
180
+ }
181
+
182
+ function addBody(options, webRequest) {
183
+ if (options.method === 'POST' || options.method === 'PUT' || options.method === 'PATCH') {
184
+ options.body = webRequest.body._content;
185
+ options.json = false;
186
+ }
187
+ }
188
+
189
+ function setProxy(options, proxyOpt) {
190
+ if (proxyOpt) {
191
+ options.proxy = proxyOpt;
192
+ }
193
+ }
194
+
195
+ function addPathPrefix(options, destination) {
196
+ if (destination.pathPrefix) {
197
+ if (destination.pathPrefix.charAt(0) !== '/') {
198
+ options.url += '/';
199
+ }
200
+ options.url += destination.pathPrefix;
201
+ }
202
+ }
203
+
204
+ function setProxyFromDestination(options, destination) {
205
+ if (destination.useProxy === true) {
206
+ return options.proxy = 'http://' + destination.proxyHost + ':' + destination.proxyPort;
207
+ }
208
+ // explicitly disable proxy
209
+ if (destination.useProxy === false) {
210
+ options.proxy = null;
211
+ }
212
+ }
213
+
214
+ function setBasicAuthFromDestination(options, destination) {
215
+ if (destination.authType === 'basic') {
216
+ options.auth = { user: destination.username, pass: destination.password };
217
+ }
218
+ }
219
+
220
+ module.exports = Client;
@@ -0,0 +1,72 @@
1
+ 'use strict';
2
+
3
+ var VError = require('verror');
4
+ var Client = require('./Client');
5
+ var Destination = require('../Destination');
6
+ var WebRequest = require('../../web/WebRequest');
7
+ var utils = require('../../../utils');
8
+ var constants = require('../../constants');
9
+ var httpStatusCodes = constants.httpStatusCodes;
10
+ var webTypes = constants.webTypes;
11
+
12
+ module.exports = HTTP;
13
+
14
+ function HTTP(dtDestinations, getDestinationFunction, sapPassport) {
15
+ if (!dtDestinations || (typeof dtDestinations !== 'object')) {
16
+ throw new TypeError('Design time destinations container object should be provided');
17
+ }
18
+
19
+ if (getDestinationFunction && (typeof getDestinationFunction !== 'function')) {
20
+ throw new TypeError('Destination provider is mandatory and should be a function');
21
+ }
22
+
23
+ this.readDestination = async function (packagename, objectname) {
24
+ var destinationName = utils.toXSObjectId(packagename, objectname);
25
+ if (!destinationName) {
26
+ throw new TypeError('Valid destination packagename or objectname should be provided');
27
+ }
28
+
29
+ var dtDestination = dtDestinations[destinationName];
30
+ var destination = (isAsync(getDestinationFunction)) ?
31
+ await getDestinationFunctionPromise(packagename, objectname, dtDestination, getDestinationFunction) :
32
+ getDestinationFunction(packagename, objectname, dtDestination);
33
+
34
+ if (!destination) {
35
+ throw new VError('Destination not found (package: "%s", objectname: "%s")', packagename, objectname);
36
+ }
37
+ return new Destination(destination);
38
+ };
39
+ this.Client = Client.bind(null, sapPassport);
40
+ }
41
+
42
+ HTTP.prototype.Request = WebRequest;
43
+ HTTP.prototype.Destination = Destination;
44
+
45
+ Object.keys(httpStatusCodes).forEach(function (key) {
46
+ Object.defineProperty(HTTP.prototype, key, {
47
+ value: httpStatusCodes[key],
48
+ enumerable: true
49
+ });
50
+ });
51
+
52
+ Object.keys(webTypes).forEach(function (key) {
53
+ Object.defineProperty(HTTP.prototype, key, {
54
+ value: webTypes[key],
55
+ enumerable: true
56
+ });
57
+ });
58
+
59
+ function isAsync(getDestinationFunction) {
60
+ return (getDestinationFunction.length > 3);
61
+ }
62
+
63
+ function getDestinationFunctionPromise (packagename, objectname, dtDestination, getDestinationFunction) {
64
+ return new Promise ((resolve, reject) => {
65
+ getDestinationFunction(packagename, objectname, dtDestination, function (err, result) {
66
+ if (err) {
67
+ return reject (err);
68
+ }
69
+ resolve(result);
70
+ });
71
+ });
72
+ }
@@ -0,0 +1,5 @@
1
+ 'use strict';
2
+
3
+ exports.HTTP = require('./http/HTTP');
4
+ exports.createMail = require('./smtp').createMail;
5
+ exports.createSMTPConnection = require('./smtp').createSMTPConnection;
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ var nodemailer = require('nodemailer');
4
+ var toNodemailerMail = require('./nodemailer-util').toNodemailerMail;
5
+ var assert = require('assert');
6
+
7
+ module.exports = Mail;
8
+
9
+ function Mail(settings, mailObjectOpt) {
10
+ assert(settings && settings.host && settings.port, 'Invalid smtp settings. Host and port are mandatory.');
11
+ this._settings = settings;
12
+ this.bcc = mailObjectOpt && mailObjectOpt.bcc || [];
13
+ this.cc = mailObjectOpt && mailObjectOpt.cc || [];
14
+ this.parts = mailObjectOpt && mailObjectOpt.parts || [];
15
+ this.sender = mailObjectOpt && mailObjectOpt.sender || {};
16
+ this.subject = mailObjectOpt && mailObjectOpt.subject || '';
17
+ this.to = mailObjectOpt && mailObjectOpt.to || [];
18
+ }
19
+
20
+ Mail.prototype.send = async function () {
21
+ var nodeMail = toNodemailerMail(this);
22
+ var transporter = nodemailer.createTransport({
23
+ host: this._settings.host,
24
+ port: parseInt(this._settings.port, 10),
25
+ ignoreTLS: this._settings.ignoreTLS,
26
+ secure: this._settings.secure,
27
+ connectionTimeout: this._settings.connectionTimeout || 60000,
28
+ authMethod: this._settings.authMethod,
29
+ auth: this._settings.auth
30
+ });
31
+ var info;
32
+ try {
33
+ info = await transporter.sendMail(nodeMail);
34
+ } finally {
35
+ transporter.close();
36
+ }
37
+ return { finalReply: info.response, messageId: info.messageId };
38
+ };
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+ module.exports = Part;
3
+
4
+ function Part(partObjectOpt) {
5
+ this.alternative = partObjectOpt && partObjectOpt.alternative || '';
6
+ this.alternativeContentType = partObjectOpt && partObjectOpt.alternativeContentType || '';
7
+ this.contentId = partObjectOpt && partObjectOpt.contentId || '';
8
+ this.contentType = partObjectOpt && partObjectOpt.contentType || '';
9
+ this.data = partObjectOpt && partObjectOpt.data || '';
10
+ this.encoding = partObjectOpt && partObjectOpt.encoding || '';
11
+ this.fileName = partObjectOpt && partObjectOpt.fileName || '';
12
+ this.fileNameEncoding = partObjectOpt && partObjectOpt.fileNameEncoding || 'UTF-8';
13
+ this.text = partObjectOpt && partObjectOpt.text || '';
14
+ this.type = partObjectOpt && partObjectOpt.type || Part.prototype.TYPE_TEXT;
15
+ }
16
+
17
+ Object.defineProperties(Part, {
18
+ TYPE_TEXT: {
19
+ value: 'text',
20
+ enumerable: true
21
+ },
22
+ TYPE_ATTACHMENT: {
23
+ value: 'attachment',
24
+ enumerable: true
25
+ },
26
+ TYPE_INLINE: {
27
+ value: 'inline',
28
+ enumerable: true
29
+ }
30
+ });
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ var assert = require('assert');
4
+ var nodemailer = require('nodemailer');
5
+ var toNodemailerMail = require('./nodemailer-util').toNodemailerMail;
6
+
7
+ module.exports = SMTPConnection;
8
+
9
+ function SMTPConnection(settings) {
10
+ assert(settings && settings.host && settings.port, 'Invalid smtp settings. Host and port are mandatory.');
11
+ this._transporter = nodemailer.createTransport({
12
+ pool: true,
13
+ host: settings.host,
14
+ port: parseInt(settings.port, 10),
15
+ ignoreTLS: settings.ignoreTLS,
16
+ secure: settings.secure,
17
+ connectionTimeout: settings.connectionTimeout || 60000,
18
+ authMethod: settings.authMethod,
19
+ auth: settings.auth,
20
+ maxConnections: 1
21
+ });
22
+ this._isClosed = true;
23
+ }
24
+
25
+ SMTPConnection.prototype.send = async function (mail) {
26
+ var nodeMail = toNodemailerMail(mail);
27
+ var info = await this._transporter.sendMail(nodeMail);
28
+ this._isClosed = false;
29
+ return { finalReply: info.response, messageId: info.messageId };
30
+ };
31
+
32
+ SMTPConnection.prototype.close = function () {
33
+ this._transporter.close();
34
+ this._isClosed = true;
35
+ };
36
+
37
+ SMTPConnection.prototype.isClosed = function () {
38
+ return this._isClosed;
39
+ };
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+ var Mail = require('./Mail');
3
+ var Part = require('./Part');
4
+ var SMTPConnection = require('./SMTPConnection');
5
+
6
+ exports.createMail = function (settings) {
7
+ var mail = function(mailObjectOpt) {
8
+ return new Mail(settings, mailObjectOpt);
9
+ };
10
+ Object.defineProperty(mail, 'Part', {value: Part});
11
+ return mail;
12
+ };
13
+
14
+ exports.createSMTPConnection = function (settings) {
15
+ return function() {
16
+ return new SMTPConnection(settings);
17
+ };
18
+ };
@@ -0,0 +1,77 @@
1
+ 'use strict';
2
+
3
+ var assert = require('assert');
4
+ var Part = require('./Part');
5
+ var util = require('util');
6
+ var buffUtils = require('../../../utils/buffer-utils');
7
+
8
+ function getDataAsStringAndEncoding(data) {
9
+ var partDataAsString = '';
10
+ var encoding = null;
11
+ if (data) {
12
+ if (typeof data === 'string') {
13
+ partDataAsString = data;
14
+ } else {
15
+ partDataAsString = buffUtils.toBuffer(data).toString('base64');
16
+ encoding = 'base64';
17
+ }
18
+ }
19
+ return { data: partDataAsString, encoding: encoding };
20
+ }
21
+
22
+ function getAttachment(part, isInline) {
23
+ var partDataAsStringAndEncoding = getDataAsStringAndEncoding(part.data);
24
+ var attachment = {
25
+ filename: part.fileName || '',
26
+ content: partDataAsStringAndEncoding.data || '',
27
+ contentType: part.contentType || '',
28
+ encoding: partDataAsStringAndEncoding.encoding
29
+ };
30
+ if (isInline) {
31
+ attachment.cid = part.contentId || '';
32
+ attachment.contentDisposition = 'inline';
33
+ }
34
+ return attachment;
35
+ }
36
+
37
+ exports.toNodemailerMail = function (mail) {
38
+ assert(mail.constructor.name === 'Mail', 'Not a mail object: ' + mail);
39
+ assert(mail.sender, 'Mail.send(): missing sender');
40
+ assert(mail.to || mail.cc || mail.bcc, 'Mail.send(): missing recipients');
41
+ var mailOptions = {
42
+ from: mail.sender,
43
+ to: mail.to,
44
+ cc: mail.cc,
45
+ bcc: mail.bcc,
46
+ subject: mail.subject || '',
47
+ attachments: [],
48
+ alternatives: [],
49
+ html: ''
50
+ };
51
+
52
+ if (mail.parts && util.isArray(mail.parts)) {
53
+ mail.parts.forEach(function (part) {
54
+ if (part.type === Part.TYPE_TEXT) {
55
+ var alternatives = [];
56
+ if (part.contentType === 'text/html') {
57
+ mailOptions.html = part.text;
58
+ } else {
59
+ mailOptions.text = part.text;
60
+ }
61
+ if (part.alternative) {
62
+ alternatives.push({ content: part.alternative, contentType: part.alternativeContentType || 'text/plain' });
63
+ }
64
+ if (alternatives) {
65
+ mailOptions.alternatives = alternatives;
66
+ }
67
+ } else if (part.type === Part.TYPE_ATTACHMENT) {
68
+ mailOptions.attachments.push(getAttachment(part, false));
69
+ } else if (part.type === Part.TYPE_INLINE) {
70
+ mailOptions.attachments.push(getAttachment(part, true));
71
+ } else {
72
+ throw new Error('Part.type cannot be: ' + part.type);
73
+ }
74
+ });
75
+ }
76
+ return mailOptions;
77
+ };
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ var _ = require('lodash');
4
+ var path = require('path');
5
+ var assert = require('assert');
6
+ var utils = require('../utils');
7
+
8
+ module.exports = function xsjsRequire(packagename, rootDirs) {
9
+ assert(_.isString(packagename), 'packagename must be a string');
10
+
11
+ var xsjsDir = path.parse(utils.getCallingXsjs(rootDirs)).dir;
12
+ var isLocalFile = ['./', '/', '../'].some(function(prefix) {
13
+ return _.startsWith(packagename, prefix);
14
+ });
15
+ if (isLocalFile) { // We are requiring a file on the system
16
+ return require(path.resolve(xsjsDir, packagename));
17
+ }
18
+
19
+ var nodeCache = require.cache[__filename];
20
+ var oldLookupPaths = nodeCache.paths;
21
+ var newLookupPaths = [];
22
+ var systemRoot = path.parse(xsjsDir).root;
23
+ for (;;) {
24
+ if (path.basename(xsjsDir) !== 'node_modules') {
25
+ newLookupPaths.push(path.join(xsjsDir, 'node_modules'));
26
+ if (xsjsDir === systemRoot) {
27
+ break;
28
+ }
29
+ }
30
+ xsjsDir = path.resolve(xsjsDir, '..');
31
+ }
32
+
33
+ nodeCache.paths = newLookupPaths;
34
+ try {
35
+ return require(packagename);
36
+ } finally {
37
+ nodeCache.paths = oldLookupPaths;
38
+ }
39
+ };
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ var vsi = require('@sap/node-vsi');
4
+ var buffUtils = require('../../utils/buffer-utils');
5
+
6
+ module.exports = AntiVirus;
7
+
8
+ function AntiVirus(profile) {
9
+ var vsiProfile = vsi.vsiProfile;
10
+ profile = typeof profile !== 'undefined' ? profile : '';
11
+ this.av = new vsiProfile(profile);
12
+ if (this.av.getLastError() !== '') {
13
+ this.isAvAvailable = false;
14
+ return;
15
+ }
16
+ this.isAvAvailable = true;
17
+ }
18
+
19
+ AntiVirus.prototype.isAvailable = function() {
20
+ return this.isAvAvailable;
21
+ };
22
+
23
+ AntiVirus.prototype.scan = function(data, name) {
24
+ data = buffUtils.getData(data).toString('binary');
25
+ name = name || 'binary';
26
+ var rc = this.av.scanBytes(name, data, data.length);
27
+ if (rc !== 0) {
28
+ throw new Error(this.av.getLastError());
29
+ }
30
+ return true;
31
+ };
@@ -0,0 +1,119 @@
1
+ 'use strict';
2
+
3
+ var assert = require('assert');
4
+ var connection = require('../db/common/connection');
5
+ var dbStream = require('@sap/hana-client/extension/Stream');
6
+
7
+ exports.createStore = createStore;
8
+
9
+ function createStore(dbReqOptions) {
10
+ var openConnections = new Set();
11
+
12
+ var storeConstructor = function (secureStoreFile) {
13
+ return dbReqOptions.getInstanceOptionsPromise()
14
+ .then((hanaOptions) => {
15
+ return connection.connect(hanaOptions);
16
+ })
17
+ .then((client) => {
18
+ openConnections.add(client);
19
+ return new Store(client, secureStoreFile);
20
+ });
21
+ };
22
+
23
+ storeConstructor._closeAllConnections = function () {
24
+ for (var client of openConnections) {
25
+ client.close(function () { }); // ignoring an error here;
26
+ }
27
+ openConnections.clear();
28
+ };
29
+
30
+ return storeConstructor;
31
+ }
32
+
33
+ function Store(client, secureStoreFile) {
34
+ this._client = client;
35
+ this._secureStoreFile = secureStoreFile;
36
+ }
37
+
38
+ Store.prototype.read = async function (parameter) {
39
+ checkParameterHasName(parameter, 'read');
40
+ return await read.call(this, parameter, false);
41
+ };
42
+
43
+ Store.prototype.readForUser = async function (parameter) {
44
+ checkParameterHasName(parameter, 'readForUser');
45
+ return await read.call(this, parameter, true);
46
+ };
47
+
48
+ async function read(parameter, isForUser) {
49
+ var result = await callProc(this._client, 'CALL "SYS"."USER_SECURESTORE_RETRIEVE"(?, ?, ?, ?)', {
50
+ STORE_NAME: this._secureStoreFile,
51
+ FOR_XS_APPLICATIONUSER: isForUser,
52
+ KEY: parameter.name
53
+ });
54
+ return result && result.VALUE ? result.VALUE.toString('utf8') : null;
55
+ }
56
+
57
+ Store.prototype.remove = async function (parameter) {
58
+ checkParameterHasName(parameter, 'remove');
59
+ await remove.call(this, parameter, false);
60
+ };
61
+
62
+ Store.prototype.removeForUser = async function (parameter) {
63
+ checkParameterHasName(parameter, 'removeForUser');
64
+ await remove.call(this, parameter, true);
65
+ };
66
+
67
+ async function remove(parameter, isForUser) {
68
+ await callProc(this._client, 'CALL "SYS"."USER_SECURESTORE_DELETE"(?, ?, ?)', {
69
+ STORE_NAME: this._secureStoreFile,
70
+ FOR_XS_APPLICATIONUSER: isForUser,
71
+ KEY: parameter.name
72
+ });
73
+ }
74
+
75
+ Store.prototype.store = async function (parameter) {
76
+ checkWriteParameter(parameter, 'store');
77
+ await store.call(this, parameter, false);
78
+ };
79
+
80
+ Store.prototype.storeForUser = async function (parameter) {
81
+ checkWriteParameter(parameter, 'storeForUser');
82
+ await store.call(this, parameter, true);
83
+ };
84
+
85
+ async function store(parameter, isForUser) {
86
+ await callProc(this._client, 'CALL "SYS"."USER_SECURESTORE_INSERT"(?, ?, ?, ?)', {
87
+ STORE_NAME: this._secureStoreFile,
88
+ FOR_XS_APPLICATIONUSER: isForUser,
89
+ KEY: parameter.name,
90
+ VALUE: Buffer.from(parameter.value, 'utf8')
91
+ });
92
+ }
93
+
94
+ function checkWriteParameter(parameter, functionName) {
95
+ checkParameterHasName(parameter, functionName);
96
+ assert(typeof parameter.value === 'string', 'Store.' + functionName + ' should be called with object containing property value - string!');
97
+ }
98
+
99
+ function checkParameterHasName(parameter, functionName) {
100
+ assert(parameter && typeof parameter === 'object', 'Store.' + functionName + ' called with invalid parameter');
101
+ assert(parameter.name && typeof parameter.name === 'string', 'Store.' + functionName + ' should be called with object containing property name - non empty string!');
102
+ }
103
+
104
+ function callProc(client, sql, params) {
105
+ var stmt = dbStream.createProcStatement(client, sql);
106
+ return new Promise((resolve, reject) => {
107
+ stmt.exec(params, function(){
108
+ var err = arguments[0];
109
+ if (err) {
110
+ stmt.drop();
111
+ reject(err);
112
+ }
113
+ else {
114
+ stmt.drop();
115
+ resolve(arguments[1]);
116
+ }
117
+ });
118
+ });
119
+ }