@sap-ux/deploy-tooling 0.14.47 → 0.15.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.
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.checkForCredentials = exports.showAdditionalInfoForOnPrem = exports.formatSummary = exports.validateBeforeDeploy = exports.summaryMessage = exports.SummaryStatus = void 0;
13
4
  const axios_extension_1 = require("@sap-ux/axios-extension");
@@ -42,29 +33,26 @@ let cachedDestinationsList = {};
42
33
  * @param logger Logger used by deploy tooling
43
34
  * @returns Validation result and a summary report of identified issues.
44
35
  */
45
- function validateBeforeDeploy(config, provider, logger) {
46
- var _a, _b, _c, _d, _e, _f, _g;
47
- return __awaiter(this, void 0, void 0, function* () {
48
- const output = {
49
- summary: [],
50
- result: true
51
- };
52
- const input = {
53
- appName: (_a = config.app.name) !== null && _a !== void 0 ? _a : '',
54
- description: (_b = config.app.description) !== null && _b !== void 0 ? _b : '',
55
- package: (_c = config.app.package) !== null && _c !== void 0 ? _c : '',
56
- transport: (_d = config.app.transport) !== null && _d !== void 0 ? _d : '',
57
- client: (_e = config.target.client) !== null && _e !== void 0 ? _e : '',
58
- url: (_f = config.target.url) !== null && _f !== void 0 ? _f : '',
59
- destination: (_g = config.target.destination) !== null && _g !== void 0 ? _g : ''
60
- };
61
- // output is passed by reference and status updated during the internal pipeline below.
62
- yield validateInputTextFormat(input, output, provider, logger);
63
- convertInputsForAdtValidations(input, output);
64
- yield validatePackageWithAdt(input, output, provider, logger);
65
- yield validateTransportRequestWithAdt(input, output, provider, logger);
66
- return output;
67
- });
36
+ async function validateBeforeDeploy(config, provider, logger) {
37
+ const output = {
38
+ summary: [],
39
+ result: true
40
+ };
41
+ const input = {
42
+ appName: config.app.name ?? '',
43
+ description: config.app.description ?? '',
44
+ package: config.app.package ?? '',
45
+ transport: config.app.transport ?? '',
46
+ client: config.target.client ?? '',
47
+ url: config.target.url ?? '',
48
+ destination: config.target.destination ?? ''
49
+ };
50
+ // output is passed by reference and status updated during the internal pipeline below.
51
+ await validateInputTextFormat(input, output, provider, logger);
52
+ convertInputsForAdtValidations(input, output);
53
+ await validatePackageWithAdt(input, output, provider, logger);
54
+ await validateTransportRequestWithAdt(input, output, provider, logger);
55
+ return output;
68
56
  }
69
57
  exports.validateBeforeDeploy = validateBeforeDeploy;
70
58
  /**
@@ -130,33 +118,31 @@ function convertInputsForAdtValidations(input, output) {
130
118
  * @param provider AbapServiceProvider
131
119
  * @param logger Logger from the calling context
132
120
  */
133
- function validateInputTextFormat(input, output, provider, logger) {
134
- return __awaiter(this, void 0, void 0, function* () {
135
- // Prepare backend info for validation
136
- const prefix = yield getSystemPrefix(output, provider, logger);
137
- // A sequence of client-side validations. No early termination of detecting invalid inputs.
138
- // Setting output.result to false if any of the checks is invalid.
139
- // Add individual error messages into output.summary array if validation failed.
140
- let result = (0, project_input_validator_1.validateAppName)(input.appName, prefix);
141
- processInputValidationResult(result, output);
142
- result = (0, project_input_validator_1.validateAppDescription)(input.description);
143
- processInputValidationResult(result, output);
144
- result = (0, project_input_validator_1.validateTransportRequestNumber)(input.transport, input.package);
145
- processInputValidationResult(result, output);
146
- result = (0, project_input_validator_1.validatePackage)(input.package);
147
- processInputValidationResult(result, output);
148
- result = (0, project_input_validator_1.validateClient)(input.client);
149
- processInputValidationResult(result, output);
150
- result = validateUrlForOnPremTargetOnly(input.destination, input.url);
151
- processInputValidationResult(result, output);
152
- // If all the text validation passed, only show the following success message.
153
- if (output.result) {
154
- output.summary.push({
155
- message: exports.summaryMessage.allClientCheckPass,
156
- status: SummaryStatus.Valid
157
- });
158
- }
159
- });
121
+ async function validateInputTextFormat(input, output, provider, logger) {
122
+ // Prepare backend info for validation
123
+ const prefix = await getSystemPrefix(output, provider, logger);
124
+ // A sequence of client-side validations. No early termination of detecting invalid inputs.
125
+ // Setting output.result to false if any of the checks is invalid.
126
+ // Add individual error messages into output.summary array if validation failed.
127
+ let result = (0, project_input_validator_1.validateAppName)(input.appName, prefix);
128
+ processInputValidationResult(result, output);
129
+ result = (0, project_input_validator_1.validateAppDescription)(input.description);
130
+ processInputValidationResult(result, output);
131
+ result = (0, project_input_validator_1.validateTransportRequestNumber)(input.transport, input.package);
132
+ processInputValidationResult(result, output);
133
+ result = (0, project_input_validator_1.validatePackage)(input.package);
134
+ processInputValidationResult(result, output);
135
+ result = (0, project_input_validator_1.validateClient)(input.client);
136
+ processInputValidationResult(result, output);
137
+ result = validateUrlForOnPremTargetOnly(input.destination, input.url);
138
+ processInputValidationResult(result, output);
139
+ // If all the text validation passed, only show the following success message.
140
+ if (output.result) {
141
+ output.summary.push({
142
+ message: exports.summaryMessage.allClientCheckPass,
143
+ status: SummaryStatus.Valid
144
+ });
145
+ }
160
146
  }
161
147
  /**
162
148
  * A wrapper of validateUrl(). It uses same logic in system-access module's createAbapServiceProvider()
@@ -187,32 +173,30 @@ function validateUrlForOnPremTargetOnly(destination, url) {
187
173
  * @param logger Logger from the calling context
188
174
  * @returns System specific development prefix constraint for Fiori app name
189
175
  */
190
- function getSystemPrefix(output, provider, logger) {
191
- return __awaiter(this, void 0, void 0, function* () {
192
- try {
193
- const adtService = yield provider.getAdtService(axios_extension_1.AtoService);
194
- if (!adtService) {
195
- output.summary.push({
196
- message: `${exports.summaryMessage.adtServiceUndefined} for AtoService`,
197
- status: SummaryStatus.Unknown
198
- });
199
- output.result = false;
200
- return undefined;
201
- }
202
- const atoSettings = yield adtService.getAtoInfo();
203
- return atoSettings === null || atoSettings === void 0 ? void 0 : atoSettings.developmentPrefix;
204
- }
205
- catch (e) {
206
- logger.error(e.message);
207
- logger.debug(e);
176
+ async function getSystemPrefix(output, provider, logger) {
177
+ try {
178
+ const adtService = await provider.getAdtService(axios_extension_1.AtoService);
179
+ if (!adtService) {
208
180
  output.summary.push({
209
- message: exports.summaryMessage.atoAdtAccessError,
181
+ message: `${exports.summaryMessage.adtServiceUndefined} for AtoService`,
210
182
  status: SummaryStatus.Unknown
211
183
  });
212
184
  output.result = false;
213
185
  return undefined;
214
186
  }
215
- });
187
+ const atoSettings = await adtService.getAtoInfo();
188
+ return atoSettings?.developmentPrefix;
189
+ }
190
+ catch (e) {
191
+ logger.error(e.message);
192
+ logger.debug(e);
193
+ output.summary.push({
194
+ message: exports.summaryMessage.atoAdtAccessError,
195
+ status: SummaryStatus.Unknown
196
+ });
197
+ output.result = false;
198
+ return undefined;
199
+ }
216
200
  }
217
201
  /**
218
202
  * Helper function to proces input validation result. Avoids sonarqube warning about
@@ -242,49 +226,47 @@ function processInputValidationResult(validationResult, output) {
242
226
  * @param provider AbapServiceProvider
243
227
  * @param logger Logger from the calling context
244
228
  */
245
- function validatePackageWithAdt(input, output, provider, logger) {
246
- return __awaiter(this, void 0, void 0, function* () {
247
- if (output.result === false) {
229
+ async function validatePackageWithAdt(input, output, provider, logger) {
230
+ if (output.result === false) {
231
+ return;
232
+ }
233
+ // ADT expects input package
234
+ const inputPackage = input.package;
235
+ try {
236
+ const adtService = await provider.getAdtService(axios_extension_1.ListPackageService);
237
+ if (!adtService) {
238
+ output.summary.push({
239
+ message: `${exports.summaryMessage.adtServiceUndefined} for ListPackageService`,
240
+ status: SummaryStatus.Unknown
241
+ });
242
+ output.result = false;
248
243
  return;
249
244
  }
250
- // ADT expects input package
251
- const inputPackage = input.package;
252
- try {
253
- const adtService = yield provider.getAdtService(axios_extension_1.ListPackageService);
254
- if (!adtService) {
255
- output.summary.push({
256
- message: `${exports.summaryMessage.adtServiceUndefined} for ListPackageService`,
257
- status: SummaryStatus.Unknown
258
- });
259
- output.result = false;
260
- return;
261
- }
262
- const packages = yield adtService.listPackages({ phrase: inputPackage });
263
- const isValidPackage = packages.findIndex((packageName) => packageName === inputPackage) >= 0;
264
- if (isValidPackage) {
265
- output.summary.push({
266
- message: exports.summaryMessage.packageCheckPass,
267
- status: SummaryStatus.Valid
268
- });
269
- }
270
- else {
271
- output.summary.push({
272
- message: exports.summaryMessage.packageNotFound,
273
- status: SummaryStatus.Invalid
274
- });
275
- output.result = false;
276
- }
245
+ const packages = await adtService.listPackages({ phrase: inputPackage });
246
+ const isValidPackage = packages.findIndex((packageName) => packageName === inputPackage) >= 0;
247
+ if (isValidPackage) {
248
+ output.summary.push({
249
+ message: exports.summaryMessage.packageCheckPass,
250
+ status: SummaryStatus.Valid
251
+ });
277
252
  }
278
- catch (e) {
279
- logger.error(e.message);
280
- logger.debug(e);
253
+ else {
281
254
  output.summary.push({
282
- message: exports.summaryMessage.pacakgeAdtAccessError,
283
- status: SummaryStatus.Unknown
255
+ message: exports.summaryMessage.packageNotFound,
256
+ status: SummaryStatus.Invalid
284
257
  });
285
258
  output.result = false;
286
259
  }
287
- });
260
+ }
261
+ catch (e) {
262
+ logger.error(e.message);
263
+ logger.debug(e);
264
+ output.summary.push({
265
+ message: exports.summaryMessage.pacakgeAdtAccessError,
266
+ status: SummaryStatus.Unknown
267
+ });
268
+ output.result = false;
269
+ }
288
270
  }
289
271
  /**
290
272
  * Query ADT backend service to verify input transport request.
@@ -294,59 +276,57 @@ function validatePackageWithAdt(input, output, provider, logger) {
294
276
  * @param provider AbapServiceProvider
295
277
  * @param logger Logger from the calling context
296
278
  */
297
- function validateTransportRequestWithAdt(input, output, provider, logger) {
298
- return __awaiter(this, void 0, void 0, function* () {
299
- if (output.result === false) {
279
+ async function validateTransportRequestWithAdt(input, output, provider, logger) {
280
+ if (output.result === false) {
281
+ return;
282
+ }
283
+ try {
284
+ const adtService = await provider.getAdtService(axios_extension_1.TransportChecksService);
285
+ if (!adtService) {
286
+ output.summary.push({
287
+ message: `${exports.summaryMessage.adtServiceUndefined} for TransportChecksService`,
288
+ status: SummaryStatus.Unknown
289
+ });
290
+ output.result = false;
300
291
  return;
301
292
  }
302
- try {
303
- const adtService = yield provider.getAdtService(axios_extension_1.TransportChecksService);
304
- if (!adtService) {
305
- output.summary.push({
306
- message: `${exports.summaryMessage.adtServiceUndefined} for TransportChecksService`,
307
- status: SummaryStatus.Unknown
308
- });
309
- output.result = false;
310
- return;
311
- }
312
- const trList = yield adtService.getTransportRequests(input.package, input.appName);
313
- const isValidTrList = trList.findIndex((tr) => tr.transportNumber === input.transport) >= 0;
314
- if (isValidTrList) {
315
- output.summary.push({
316
- message: exports.summaryMessage.transportCheckPass,
317
- status: SummaryStatus.Valid
318
- });
319
- }
320
- else {
321
- output.summary.push({
322
- message: exports.summaryMessage.transportNotFound,
323
- status: SummaryStatus.Invalid
324
- });
325
- output.result = false;
326
- }
293
+ const trList = await adtService.getTransportRequests(input.package, input.appName);
294
+ const isValidTrList = trList.findIndex((tr) => tr.transportNumber === input.transport) >= 0;
295
+ if (isValidTrList) {
296
+ output.summary.push({
297
+ message: exports.summaryMessage.transportCheckPass,
298
+ status: SummaryStatus.Valid
299
+ });
300
+ }
301
+ else {
302
+ output.summary.push({
303
+ message: exports.summaryMessage.transportNotFound,
304
+ status: SummaryStatus.Invalid
305
+ });
306
+ output.result = false;
307
+ }
308
+ }
309
+ catch (e) {
310
+ // TransportChecksService.getTransportRequests() API is used to provide valid
311
+ // transport request list. If input packge is local package, no transport request
312
+ // is returned and LocalPackageError is thrown as exception.
313
+ // LocalPackageError is acceptable for validation purpose here.
314
+ if (e.message === axios_extension_1.TransportChecksService.LocalPackageError) {
315
+ output.summary.push({
316
+ message: exports.summaryMessage.transportNotRequired,
317
+ status: SummaryStatus.Valid
318
+ });
327
319
  }
328
- catch (e) {
329
- // TransportChecksService.getTransportRequests() API is used to provide valid
330
- // transport request list. If input packge is local package, no transport request
331
- // is returned and LocalPackageError is thrown as exception.
332
- // LocalPackageError is acceptable for validation purpose here.
333
- if (e.message === axios_extension_1.TransportChecksService.LocalPackageError) {
334
- output.summary.push({
335
- message: exports.summaryMessage.transportNotRequired,
336
- status: SummaryStatus.Valid
337
- });
338
- }
339
- else {
340
- logger.error(e.message);
341
- logger.debug(e);
342
- output.summary.push({
343
- message: exports.summaryMessage.transportAdtAccessError,
344
- status: SummaryStatus.Unknown
345
- });
346
- output.result = false;
347
- }
320
+ else {
321
+ logger.error(e.message);
322
+ logger.debug(e);
323
+ output.summary.push({
324
+ message: exports.summaryMessage.transportAdtAccessError,
325
+ status: SummaryStatus.Unknown
326
+ });
327
+ output.result = false;
348
328
  }
349
- });
329
+ }
350
330
  }
351
331
  /**
352
332
  * Returns true if specified destination is on-premise and if environment is App Studio
@@ -355,15 +335,13 @@ function validateTransportRequestWithAdt(input, output, provider, logger) {
355
335
  * @param destination Identifier for destination to be checked.
356
336
  * @returns Promise boolean.
357
337
  */
358
- function showAdditionalInfoForOnPrem(destination) {
359
- return __awaiter(this, void 0, void 0, function* () {
360
- let showInfo = false;
361
- if ((0, btp_utils_1.isAppStudio)() && destination) {
362
- const destinations = yield (0, btp_utils_1.listDestinations)();
363
- showInfo = (0, btp_utils_1.isOnPremiseDestination)(destinations[destination]);
364
- }
365
- return showInfo;
366
- });
338
+ async function showAdditionalInfoForOnPrem(destination) {
339
+ let showInfo = false;
340
+ if ((0, btp_utils_1.isAppStudio)() && destination) {
341
+ const destinations = await (0, btp_utils_1.listDestinations)();
342
+ showInfo = (0, btp_utils_1.isOnPremiseDestination)(destinations[destination]);
343
+ }
344
+ return showInfo;
367
345
  }
368
346
  exports.showAdditionalInfoForOnPrem = showAdditionalInfoForOnPrem;
369
347
  /**
@@ -373,18 +351,16 @@ exports.showAdditionalInfoForOnPrem = showAdditionalInfoForOnPrem;
373
351
  * @param logger Logger from the calling context.
374
352
  * @returns Promise boolean.
375
353
  */
376
- function checkForCredentials(destination, logger) {
377
- return __awaiter(this, void 0, void 0, function* () {
378
- let check = true;
379
- if (destination && (0, btp_utils_1.isAppStudio)()) {
380
- const destinations = yield getDestinations();
381
- if (destinations[destination].Authentication === btp_utils_1.Authentication.SAML_ASSERTION) {
382
- logger.warn(`The SAP BTP destination is misconfigured, please check you have the appropriate trusts and permissions enabled.`);
383
- check = false;
384
- }
354
+ async function checkForCredentials(destination, logger) {
355
+ let check = true;
356
+ if (destination && (0, btp_utils_1.isAppStudio)()) {
357
+ const destinations = await getDestinations();
358
+ if (destinations[destination].Authentication === btp_utils_1.Authentication.SAML_ASSERTION) {
359
+ logger.warn(`The SAP BTP destination is misconfigured, please check you have the appropriate trusts and permissions enabled.`);
360
+ check = false;
385
361
  }
386
- return check;
387
- });
362
+ }
363
+ return check;
388
364
  }
389
365
  exports.checkForCredentials = checkForCredentials;
390
366
  /**
@@ -392,12 +368,10 @@ exports.checkForCredentials = checkForCredentials;
392
368
  *
393
369
  * @returns Array of Destination objects
394
370
  */
395
- function getDestinations() {
396
- return __awaiter(this, void 0, void 0, function* () {
397
- if (Object.keys(cachedDestinationsList).length === 0) {
398
- cachedDestinationsList = yield (0, btp_utils_1.listDestinations)();
399
- }
400
- return cachedDestinationsList;
401
- });
371
+ async function getDestinations() {
372
+ if (Object.keys(cachedDestinationsList).length === 0) {
373
+ cachedDestinationsList = await (0, btp_utils_1.listDestinations)();
374
+ }
375
+ return cachedDestinationsList;
402
376
  }
403
377
  //# sourceMappingURL=validate.js.map
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -46,21 +37,19 @@ function getArchiveFromPath(logger, path) {
46
37
  * @param rejectUnauthorized - strict SSL handling or not
47
38
  * @returns Buffer containing the zip file
48
39
  */
49
- function fetchArchiveFromUrl(logger, url, rejectUnauthorized) {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- try {
52
- logger.info(`Fetching archive from ${url}.`);
53
- const response = yield axios_1.default.get(url, {
54
- httpsAgent: new https_1.Agent({ rejectUnauthorized }),
55
- responseType: 'arraybuffer'
56
- });
57
- logger.info(`Archive fetched from ${url}.`);
58
- return response.data;
59
- }
60
- catch (error) {
61
- throw new Error(`The archive url you provided could not be reached. Please ensure the URL is accessible and does not require authentication. ${error}`);
62
- }
63
- });
40
+ async function fetchArchiveFromUrl(logger, url, rejectUnauthorized) {
41
+ try {
42
+ logger.info(`Fetching archive from ${url}.`);
43
+ const response = await axios_1.default.get(url, {
44
+ httpsAgent: new https_1.Agent({ rejectUnauthorized }),
45
+ responseType: 'arraybuffer'
46
+ });
47
+ logger.info(`Archive fetched from ${url}.`);
48
+ return response.data;
49
+ }
50
+ catch (error) {
51
+ throw new Error(`The archive url you provided could not be reached. Please ensure the URL is accessible and does not require authentication. ${error}`);
52
+ }
64
53
  }
65
54
  /**
66
55
  * Create a zipped file containing all files in the given folder.
@@ -91,19 +80,16 @@ function createArchiveFromFolder(logger, path) {
91
80
  * @param options - options provided via CLI
92
81
  * @returns Buffer containing the zip file
93
82
  */
94
- function getArchive(logger, options) {
95
- var _a;
96
- return __awaiter(this, void 0, void 0, function* () {
97
- if (options.archivePath) {
98
- return getArchiveFromPath(logger, options.archivePath);
99
- }
100
- else if (options.archiveUrl) {
101
- return fetchArchiveFromUrl(logger, options.archiveUrl, options.strictSsl);
102
- }
103
- else {
104
- return createArchiveFromFolder(logger, (_a = options.archiveFolder) !== null && _a !== void 0 ? _a : process.cwd());
105
- }
106
- });
83
+ async function getArchive(logger, options) {
84
+ if (options.archivePath) {
85
+ return getArchiveFromPath(logger, options.archivePath);
86
+ }
87
+ else if (options.archiveUrl) {
88
+ return fetchArchiveFromUrl(logger, options.archiveUrl, options.strictSsl);
89
+ }
90
+ else {
91
+ return createArchiveFromFolder(logger, options.archiveFolder ?? process.cwd());
92
+ }
107
93
  }
108
94
  exports.getArchive = getArchive;
109
95
  //# sourceMappingURL=archive.js.map