@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,52 @@
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ parse: parseTableString,
5
+ adaptForHdbext: adaptForHdbext
6
+ };
7
+
8
+ function parseTableString(str) {
9
+ var regex = /^\s*(?:(?:("(?:[^"]|"")*")|([^"][^\s.]*))\s*\.{1})?\s*(?:("(?:[^"]|"")*")|([^"][^\s.]*))\s*$/;
10
+ var result = regex.exec(str);
11
+
12
+ if (result === null) {
13
+ return null;
14
+ }
15
+
16
+ return {
17
+ schema: {
18
+ escaped: result[1],
19
+ unescaped: result[2]
20
+ },
21
+ table: {
22
+ escaped: result[3],
23
+ unescaped: result[4]
24
+ }
25
+ };
26
+ }
27
+
28
+ function adaptForHdbext(parsed) {
29
+ var adapted = {};
30
+
31
+ ['schema', 'table'].forEach(function (identifier) {
32
+ if (parsed[identifier].escaped) {
33
+ // hdbext escapes the schema and table names.
34
+ // If we have received them escaped, then we should unescape them
35
+ // so that these identifiers do not get escaped twice.
36
+ adapted[identifier] = unescape(parsed[identifier].escaped);
37
+ } else if (parsed[identifier].unescaped) {
38
+ // In XSC if we pass an unescaped identifier, it is treated as upper case name.
39
+ // We need to manually convert it to upper case
40
+ // before hdbext escapes the identifier.
41
+ adapted[identifier] = parsed[identifier].unescaped.toUpperCase();
42
+ }
43
+ });
44
+
45
+ return adapted;
46
+ }
47
+
48
+ function unescape(identifier) {
49
+ identifier = identifier.substring(1, identifier.length - 1);
50
+ identifier = identifier.replace(/""/g, '"');
51
+ return identifier;
52
+ }
@@ -0,0 +1,4 @@
1
+ 'use strict';
2
+
3
+ exports.DB = require('./dbapi/DB');
4
+ exports.HDB = require('./hdbapi/HDB');
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ exports.Jobs = require('./jobs/Jobs');
4
+ exports.Application = require('./Application');
5
+ exports.Session = require('./Session');
6
+ exports.db = require('./db');
7
+ exports.net = require('./net');
8
+ exports.web = require('./web');
9
+ exports.security = require('./security');
10
+ exports.trace = require('./trace/trace');
11
+ exports.util = require('./util');
12
+ exports.require = require('./require');
13
+ exports.text = require('./text');
@@ -0,0 +1,228 @@
1
+ 'use strict';
2
+
3
+ var path = require('path');
4
+ var util = require('util');
5
+ var utils = require('../../utils');
6
+ var jobsClient = require('@sap/jobs-client');
7
+
8
+ var Schedules = require('./Schedules');
9
+ var Schedule = require('./Schedule');
10
+
11
+ module.exports = Job;
12
+
13
+ function Job(runtime, constructJob) {
14
+ var self = this;
15
+ this._scheduler = createScheduler(runtime);
16
+
17
+ this.schedules = {};
18
+ if (!constructJob.uri) {
19
+ throw new Error('Job: uri string parameter required');
20
+ }
21
+ var jobPath = resolveJobURI(runtime, constructJob.uri);
22
+ var jobName = runtime.getJobName(jobPath);
23
+ return new Promise ((resolve, reject) => {
24
+ self._scheduler.fetchJob({ name: jobName, displaySchedules: true }, function(err, job) {
25
+ if (err) { return reject(err);}
26
+ if (!job._id) {
27
+ reject('Scheduler response missing _id property');
28
+ }
29
+ if (!job.schedules) {
30
+ reject('Scheduler response missing schedules property');
31
+ }
32
+ self._jobId = job._id;
33
+ self.active = job.active;
34
+ var jobSchedules = job.schedules;
35
+ var id = [];
36
+ var schedulesObject = new Schedules(self._scheduler, self._jobId);
37
+ var schedulePromises = jobSchedules.map((jobSchedule) => {
38
+ if (!jobSchedule.scheduleId) {
39
+ reject('Scheduler response missing scheduleId property');
40
+ }
41
+ var description = jobSchedule.description;
42
+ var data = jobSchedule.data;
43
+ var cron = jobSchedule.cron;
44
+ var active = jobSchedule.active;
45
+ var scheduleId = jobSchedule.scheduleId;
46
+ id.push(jobSchedule.scheduleId);
47
+ return new Schedule(self._scheduler,
48
+ description, data, cron, active, self._jobId, scheduleId);
49
+ });
50
+ Promise.all(schedulePromises).then((resolvedSchedules) => {
51
+ var currentScheduleId;
52
+ for (var k = 0; k < resolvedSchedules.length; k++) {
53
+ var resolvedSchedule = resolvedSchedules[k];
54
+ currentScheduleId = id[k];
55
+ schedulesObject[currentScheduleId] = resolvedSchedule;
56
+ }
57
+ self.schedules = schedulesObject;
58
+ resolve(self);
59
+ });
60
+ });
61
+ });
62
+ }
63
+
64
+ Object.defineProperty(Job.prototype, 'deactivate', {
65
+ enumerable : false,
66
+ value : deactivate
67
+ });
68
+ Object.defineProperty(Job.prototype, 'activate', {
69
+ enumerable : false,
70
+ value : activate
71
+ });
72
+ Object.defineProperty(Job.prototype, 'configure', {
73
+ enumerable : false,
74
+ value : configure
75
+ });
76
+
77
+
78
+ function resolveJobURI(runtime, uri) {
79
+ if (!/\.xsjob$/.test(uri)) {
80
+ throw new Error('URI ' + uri + ' should reference a xsjob');
81
+ }
82
+ var jobPath;
83
+ if (uri[0] === '/') {
84
+ jobPath = uri;
85
+ } else {
86
+ // uri is relative to calling xsjs
87
+ var callingXsjs = utils.getCallingXsjsRelativePath(runtime.get('rootDirs'));
88
+ var dir = path.dirname(callingXsjs);
89
+ jobPath = path.normalize('/' + dir + '/' + uri).replace(/\\/g, '/');
90
+ }
91
+ if (!(jobPath in runtime.xsjobs)) {
92
+ throw new Error('Could not find job ' + jobPath);
93
+ }
94
+ return jobPath;
95
+ }
96
+
97
+ function createScheduler(runtime) {
98
+ var jobs = runtime.get('jobs');
99
+ return new jobsClient.Scheduler({
100
+ baseURL: jobs.url,
101
+ timeout: jobs.timeout,
102
+ user: jobs.user,
103
+ password: jobs.password
104
+ });
105
+ }
106
+
107
+ async function configure(config) {
108
+ if (typeof config !== 'object') {
109
+ throw new Error('Job.configure: takes exactly one parameter object');
110
+ }
111
+ var user = config.user;
112
+ var password = config.password;
113
+ var status = config.status;
114
+ var startTime = config.start_time;
115
+ var endTime = config.end_time;
116
+ if (!config.hasOwnProperty('user')) {
117
+ throw new Error('Job.configure: user string parameter required');
118
+ }
119
+ if (!config.hasOwnProperty('password')) {
120
+ throw new Error('Job.configure: password string parameter required');
121
+ }
122
+ if (!config.hasOwnProperty('locale')) {
123
+ throw new Error('Job.configure: locale string parameter required');
124
+ }
125
+ if (!config.hasOwnProperty('status')) {
126
+ throw new Error('Job.configure: status boolean parameter required');
127
+ }
128
+ if (!config.hasOwnProperty('start_time')) {
129
+ throw new Error('Job.configure: startTime object parameter required');
130
+ }
131
+ if (!config.hasOwnProperty('end_time')) {
132
+ throw new Error('Job.configure: endTime object parameter required');
133
+ }
134
+
135
+ // for now we accept only Date objects until we implement date parsing compatible to XS1
136
+ if (!util.isDate(startTime)) {
137
+ throw new Error('Job.configure: startTime object parameter required');
138
+ }
139
+ if (!util.isDate(endTime)) {
140
+ throw new Error('Job.configure: endTime object parameter required');
141
+ }
142
+
143
+ var st = convertTime(startTime, 'startTime');
144
+ var et = convertTime(endTime, 'endTime');
145
+
146
+ await updateJobPromise(this._scheduler, {
147
+ jobId: this._jobId,
148
+ job: {
149
+ user: user,
150
+ password: password,
151
+ active: status
152
+ }
153
+ });
154
+
155
+ for (var scheduleKey in this.schedules) {
156
+ if (scheduleKey === '_jobId') {
157
+ continue;
158
+ }
159
+ await updateJobSchedulePromise(this._scheduler, {
160
+ jobId: this._jobId,
161
+ scheduleId: scheduleKey,
162
+ schedule: {
163
+ startTime: st,
164
+ endTime: et
165
+ }
166
+ });
167
+ }
168
+ }
169
+
170
+ function convertTime(time, propName) {
171
+ if (time === null) {
172
+ return null;
173
+ }
174
+ if (util.isDate(time)) {
175
+ return {
176
+ date: time.toISOString()
177
+ };
178
+ }
179
+ throw new Error('Job.configure: Invalid ' + propName + ' date');
180
+ }
181
+
182
+ async function _activate(job, credentials, active) {
183
+ if (typeof credentials !== 'object') {
184
+ throw new Error('Only one parameter object is required');
185
+ }
186
+ if (!credentials.user) {
187
+ throw new Error('User string parameter required');
188
+ }
189
+
190
+ if (!credentials.password) {
191
+ throw new Error('Password string parameter required');
192
+ }
193
+
194
+ await updateJobPromise (job._scheduler, {
195
+ jobId: job._jobId,
196
+ job: {
197
+ user: credentials.user,
198
+ password: credentials.password,
199
+ active: active
200
+ }
201
+ });
202
+ }
203
+
204
+ async function activate(credentials) {
205
+ await _activate(this, credentials, true);
206
+ }
207
+
208
+ async function deactivate(credentials) {
209
+ await _activate(this, credentials, false);
210
+ }
211
+
212
+ function updateJobPromise(scheduler, req) {
213
+ return new Promise ((resolve, reject) => {
214
+ scheduler.updateJob(req, function(err, result) {
215
+ if (err) { return reject(err);}
216
+ resolve(result);
217
+ });
218
+ });
219
+ }
220
+
221
+ function updateJobSchedulePromise(scheduler, req) {
222
+ return new Promise ((resolve, reject) => {
223
+ scheduler.updateJobSchedule(req, function(err, result) {
224
+ if (err) { return reject(err);}
225
+ resolve(result);
226
+ });
227
+ });
228
+ }
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ var Job = require('./Job');
4
+ module.exports = Jobs;
5
+
6
+ // $.jobs
7
+ function Jobs(runtime) {
8
+ this.Job = function (constructJob) {
9
+ return new Job(runtime, constructJob);
10
+ };
11
+ }
@@ -0,0 +1,127 @@
1
+ 'use strict';
2
+
3
+ var assert = require('assert');
4
+ var moment = require('moment');
5
+
6
+ module.exports = Logs;
7
+
8
+ function Logs(scheduler, scheduleId, jobId) {
9
+ assert(scheduler, 'Missing scheduler');
10
+ assert(scheduleId, ' Missing scheduleId');
11
+ assert(jobId, 'Missing jobId');
12
+
13
+ Object.defineProperty(this, 'scheduleId', {
14
+ enumerable: false,
15
+ value: scheduleId
16
+ });
17
+ Object.defineProperty(this, 'jobId', {
18
+ enumerable: false,
19
+ value: jobId
20
+ });
21
+ var self = this;
22
+ return new Promise ((resolve) => {
23
+ fetchJobSchedulePromise(scheduler, {
24
+ jobId: self.jobId,
25
+ scheduleId: self.scheduleId,
26
+ displayLogs: true
27
+ })
28
+ .then((body) => {
29
+ var resolvedLogs = body.logs.map(function (jlog) {
30
+ var host = null;
31
+ var port = null;
32
+ var status = normalizeRunStatus(jlog.runStatus, jlog.runState);
33
+ return new JobLogObject(
34
+ jlog.scheduleTimestamp,
35
+ status,
36
+ status === 'ERROR' ? jlog.runText : null,
37
+ jlog.executionTimestamp,
38
+ jlog.completionTimestamp,
39
+ host,
40
+ port,
41
+ jlog.action,
42
+ jlog.user,
43
+ jlog.locale);
44
+ });
45
+ self.jobLog = resolvedLogs;
46
+ // self.jobLogs = resolvedLogs;
47
+ resolve(self);
48
+ });
49
+ });
50
+ }
51
+
52
+ function getTimeValue(value) {
53
+ if (value !== null && typeof value !== 'undefined') {
54
+ return moment(value, moment.ISO_8601).toDate();
55
+ }
56
+ return null;
57
+ }
58
+
59
+ function JobLogObject(plannedTime, status, errorMessage, startedAt, finishedAt, host, port, action, user, locale) {
60
+ Object.defineProperty(this, 'planned_time', {
61
+ enumerable: true,
62
+ value: getTimeValue(plannedTime),
63
+ writable: false
64
+ });
65
+ Object.defineProperty(this, 'status', {
66
+ enumerable: true,
67
+ value: status,
68
+ writable: false
69
+ });
70
+ Object.defineProperty(this, 'error_message', {
71
+ enumerable: true,
72
+ value: errorMessage,
73
+ writable: false
74
+ });
75
+ Object.defineProperty(this, 'started_at', {
76
+ enumerable: true,
77
+ value: getTimeValue(startedAt),
78
+ writable: false
79
+ });
80
+ Object.defineProperty(this, 'finished_at', {
81
+ enumerable: true,
82
+ value: getTimeValue(finishedAt),
83
+ writable: false
84
+ });
85
+ Object.defineProperty(this, 'host', {
86
+ enumerable: true,
87
+ value: host,
88
+ writable: false
89
+ });
90
+ Object.defineProperty(this, 'port', {
91
+ enumerable: true,
92
+ value: port,
93
+ writable: false
94
+ });
95
+ Object.defineProperty(this, 'action', {
96
+ enumerable: true,
97
+ value: action,
98
+ writable: false
99
+ });
100
+ Object.defineProperty(this, 'user', {
101
+ enumerable: true,
102
+ value: user,
103
+ writable: false
104
+ });
105
+ Object.defineProperty(this, 'locale', {
106
+ enumerable: true,
107
+ value: locale,
108
+ writable: false
109
+ });
110
+ }
111
+
112
+ function normalizeRunStatus(status, state) {
113
+ switch (status) {
114
+ case 'RUNNING': return 'RUNNING';
115
+ case 'COMPLETED': return state === 'REQUEST_ERROR' ? 'ERROR' : state;
116
+ default: return state;
117
+ }
118
+ }
119
+
120
+ function fetchJobSchedulePromise(scheduler, req) {
121
+ return new Promise ((resolve, reject) => {
122
+ scheduler.fetchJobSchedule(req, function (err, result) {
123
+ if (err) { return reject(err);}
124
+ resolve(result);
125
+ });
126
+ });
127
+ }
@@ -0,0 +1,110 @@
1
+ 'use strict';
2
+
3
+ var assert = require('assert');
4
+
5
+ var Logs = require('./Logs');
6
+
7
+ module.exports = Schedule;
8
+
9
+ function Schedule(scheduler, description, parameter, xscron, active, jobId, scheduleId) {
10
+ assert(scheduler, 'Missing scheduler');
11
+ assert(scheduleId, ' Missing scheduleId');
12
+ assert(jobId, 'Missing jobId');
13
+ var self = this;
14
+
15
+ Object.defineProperty(this, 'description', {
16
+ enumerable: true,
17
+ get: function () {
18
+ return description;
19
+ },
20
+ set: async function (value) {
21
+ if (typeof value !== 'string') {
22
+ throw new Error('Incorrect type for "description"');
23
+ }
24
+ await updateJobSchedulePromise(scheduler, {
25
+ jobId: jobId,
26
+ scheduleId: scheduleId,
27
+ schedule: {
28
+ description: value
29
+ }
30
+ });
31
+ description = value;
32
+ }
33
+ });
34
+ Object.defineProperty(this, 'active', {
35
+ enumerable: true,
36
+ get: function () {
37
+ return active;
38
+ },
39
+ set: async (value) => {
40
+ if (typeof value !== 'boolean') {
41
+ throw new Error('Incorrect type for "Active"');
42
+ }
43
+ await updateJobSchedulePromise(scheduler, {
44
+ jobId: jobId,
45
+ scheduleId: scheduleId,
46
+ schedule: {
47
+ active: value
48
+ }
49
+ });
50
+ active = value;
51
+ }
52
+ });
53
+
54
+ Object.defineProperty(this, 'parameter', {
55
+ enumerable: true,
56
+ get: function () {
57
+ return parameter;
58
+ },
59
+ set: async (value) => {
60
+ if (typeof value !== 'string' && typeof value !== 'object') {
61
+ throw new Error('Incorrect type for "parameter"');
62
+ }
63
+ await updateJobSchedulePromise(scheduler, {
64
+ jobId: jobId,
65
+ scheduleId: scheduleId,
66
+ schedule: {
67
+ data: (typeof value === 'string') ? JSON.parse(value) : value
68
+ }
69
+ });
70
+ parameter = value;
71
+ }
72
+ });
73
+ Object.defineProperty(this, 'xscron', {
74
+ enumerable: true,
75
+ get: function () {
76
+ return xscron;
77
+ },
78
+ set: async function (value) {
79
+ if (typeof value !== 'string') {
80
+ throw new Error('Incorrect type for "xscron"');
81
+ }
82
+ await updateJobSchedulePromise(scheduler, {
83
+ jobId: jobId,
84
+ scheduleId: scheduleId,
85
+ schedule: {
86
+ cron: value
87
+ }
88
+ });
89
+ xscron = value;
90
+ }
91
+ });
92
+
93
+ return new Promise((resolve, reject) => {
94
+ var logsPromise = new Logs(scheduler, scheduleId, jobId);
95
+ logsPromise.then((logs) => {
96
+ self.logs = logs;
97
+ resolve(self);
98
+ }).catch((err) => {
99
+ reject(err); });
100
+ });
101
+ }
102
+
103
+ function updateJobSchedulePromise(scheduler, req) {
104
+ return new Promise ((resolve, reject) => {
105
+ scheduler.updateJobSchedule(req, function(err, result) {
106
+ if (err) { return reject(err);}
107
+ resolve(result);
108
+ });
109
+ });
110
+ }
@@ -0,0 +1,108 @@
1
+ 'use strict';
2
+
3
+ var assert = require('assert');
4
+ var Schedule = require('./Schedule');
5
+
6
+ module.exports = Schedules;
7
+
8
+ // internal properties are non-enumerable so they are not mixed with schedule ids
9
+
10
+ function Schedules(scheduler, jobId) {
11
+ assert(scheduler, 'Missing scheduler');
12
+ assert(jobId, 'Missing jobId');
13
+
14
+ Object.defineProperty(this, '_scheduler', {
15
+ enumerable: false,
16
+ writable: false,
17
+ value: scheduler
18
+ });
19
+ Object.defineProperty(this, '_jobId', {
20
+ enumerable: false,
21
+ writable: false,
22
+ value: jobId
23
+ });
24
+ }
25
+
26
+ Object.defineProperty(Schedules.prototype, 'delete', {
27
+ enumerable: false,
28
+ value: deleteSchedule
29
+ });
30
+ Object.defineProperty(Schedules.prototype, 'add', {
31
+ enumerable: false,
32
+ value: addSchedule
33
+ });
34
+
35
+ async function deleteSchedule(params) {
36
+ if (params.id) {
37
+ var scheduleId = params.id;
38
+ if (!this.hasOwnProperty(scheduleId)) {
39
+ throw new Error('Schedule ID not found');
40
+ }
41
+ await deleteJobSchedulePromise(this._scheduler, {
42
+ jobId: this._jobId,
43
+ scheduleId: scheduleId
44
+ });
45
+ delete this[scheduleId];
46
+ return true;
47
+ } else {
48
+ throw new Error('"id" is mandatory');
49
+ }
50
+ }
51
+
52
+ async function addSchedule(parameters) {
53
+ var description = parameters.description;
54
+ var xscron = parameters.xscron;
55
+ var parameter = parameters.parameter;
56
+
57
+ var body = {};
58
+ if (parameter) {
59
+ if (typeof parameter === 'string') {
60
+ parameter = JSON.parse(parameter);
61
+ } else if (typeof parameter !== 'object') {
62
+ throw new Error('Wrong input type for "parameter"');
63
+ }
64
+ body.data = parameter;
65
+ }
66
+ if (!xscron) {
67
+ throw new Error('"xscron" is mandatory');
68
+ } else if (typeof xscron !== 'string') {
69
+ throw new Error('Wrong input type for "xscron"');
70
+ } else {
71
+ body.cron = xscron;
72
+ }
73
+ if (description) {
74
+ if (typeof description !== 'string') {
75
+ throw new Error('Wrong input type for "description"');
76
+ } else {
77
+ body.description = description;
78
+ }
79
+ }
80
+
81
+ var reply = await createJobSchedulePromise(this._scheduler, {
82
+ jobId: this._jobId,
83
+ schedule: body
84
+ });
85
+
86
+ var nscheduleId = reply.scheduleId ;
87
+ this[nscheduleId] = await new Schedule(this._scheduler, reply.description, reply.data,
88
+ reply.cron, reply.active, this._jobId, nscheduleId);
89
+ return nscheduleId;
90
+ }
91
+
92
+ function deleteJobSchedulePromise(scheduler, req) {
93
+ return new Promise ((resolve, reject) => {
94
+ scheduler.deleteJobSchedule(req, function(err){
95
+ if (err) { return reject(err);}
96
+ resolve();
97
+ });
98
+ });
99
+ }
100
+
101
+ function createJobSchedulePromise(scheduler, req) {
102
+ return new Promise((resolve, reject) => {
103
+ scheduler.createJobSchedule(req, function(err, result){
104
+ if (err) { return reject(err);}
105
+ resolve(result);
106
+ });
107
+ });
108
+ }
@@ -0,0 +1,43 @@
1
+ 'use strict';
2
+
3
+ // http://help.sap.com/saphelp_hanaplatform/helpdata/en/6e/fe500d91ee462c85cce7609646e17a/content.htm?frameset=/en/34/29fc63a1de4cd6876ea211dc86ee54/frameset.htm&current_toc=/en/34/29fc63a1de4cd6876ea211dc86ee54/plain.htm&node_id=82&fullscreen=true
4
+ var _ = require('lodash');
5
+
6
+ module.exports = Destination;
7
+
8
+ /**
9
+ * According to SPS10 documentation here is a list of properties destinations can have:
10
+ *
11
+ * host = "download.finance.yahoo.com";
12
+ * port = 80;
13
+ * //All of the following keywords are optional
14
+ * description = "";
15
+ * useSSL = false;
16
+ * sslAuth = client;
17
+ * sslHostCheck = true;
18
+ * pathPrefix = "/d/quotes.csv?f=a";
19
+ * authType = none;
20
+ * samlProvider = "";
21
+ * samlACS = "header";
22
+ * samlAttributes = "";
23
+ * samlNameId = ["email"];
24
+ * proxyType = none;
25
+ * proxyHost = ""; //in-line comments are allowed
26
+ * proxyPort = 0;
27
+ * timeout = 0;
28
+ * remoteSID = "Q7E";
29
+ * remoteClient = "007";
30
+ * oAuthAppConfigPackage = "sap.hana.test";
31
+ * oAuthAppConfig = "abapTest";
32
+ *
33
+ * @param options
34
+ */
35
+
36
+ function Destination(options) {
37
+ this.host = '';
38
+ this.port = 80;
39
+ this.description = '';
40
+ this.timeout = 10000;
41
+
42
+ _.extend(this, options);
43
+ }