@sap-ux/deploy-tooling 0.9.4 → 0.9.6

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,11 +1,4 @@
1
- import type { AbapDeployConfig, AbapTarget, UrlAbapTarget } from '../types';
2
- /**
3
- * Check if it is a url or destination target.
4
- *
5
- * @param target target configuration
6
- * @returns true is it is a UrlAbapTarget
7
- */
8
- export declare function isUrlTarget(target: AbapTarget): target is UrlAbapTarget;
1
+ import type { AbapDeployConfig } from '../types';
9
2
  /**
10
3
  * Clones the given config and removes secrets so that it can be printed to a log file.
11
4
  *
@@ -1,17 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateConfig = exports.replaceEnvVariables = exports.getConfigForLogging = exports.isUrlTarget = void 0;
3
+ exports.validateConfig = exports.replaceEnvVariables = exports.getConfigForLogging = void 0;
4
4
  const btp_utils_1 = require("@sap-ux/btp-utils");
5
- /**
6
- * Check if it is a url or destination target.
7
- *
8
- * @param target target configuration
9
- * @returns true is it is a UrlAbapTarget
10
- */
11
- function isUrlTarget(target) {
12
- return target.url !== undefined;
13
- }
14
- exports.isUrlTarget = isUrlTarget;
5
+ const system_access_1 = require("@sap-ux/system-access");
15
6
  /**
16
7
  * Clones the given config and removes secrets so that it can be printed to a log file.
17
8
  *
@@ -61,7 +52,7 @@ function throwConfigMissingError(property) {
61
52
  * @returns reference to the given target config
62
53
  */
63
54
  function validateTarget(target) {
64
- if (isUrlTarget(target)) {
55
+ if ((0, system_access_1.isUrlTarget)(target)) {
65
56
  if (target.client) {
66
57
  target.client = (target.client + '').padStart(3, '0');
67
58
  }
@@ -2,19 +2,7 @@
2
2
  /// <reference types="node" />
3
3
  import type { AbapServiceProvider } from '@sap-ux/axios-extension';
4
4
  import type { Logger } from '@sap-ux/logger';
5
- import type { BackendSystem } from '@sap-ux/store';
6
- import type { AbapDeployConfig, UrlAbapTarget } from '../types';
7
- type BasicAuth = Required<Pick<BackendSystem, 'username' | 'password'>>;
8
- type ServiceAuth = Required<Pick<BackendSystem, 'serviceKeys' | 'name'>> & {
9
- refreshToken?: string;
10
- };
11
- /**
12
- * Check the secure storage if it has credentials for the given target.
13
- *
14
- * @param target - ABAP target
15
- * @returns {*} {(Promise<T | undefined>)} - Credentials
16
- */
17
- export declare function getCredentials<T extends BasicAuth | ServiceAuth | undefined>(target: UrlAbapTarget): Promise<T | undefined>;
5
+ import type { AbapDeployConfig } from '../types';
18
6
  /**
19
7
  * Creates a new transport request using adt service.
20
8
  *
@@ -40,5 +28,4 @@ export declare function deploy(archive: Buffer, config: AbapDeployConfig, logger
40
28
  * @param logger - reference to the logger instance
41
29
  */
42
30
  export declare function undeploy(config: AbapDeployConfig, logger: Logger): Promise<void>;
43
- export {};
44
31
  //# sourceMappingURL=deploy.d.ts.map
@@ -9,151 +9,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.undeploy = exports.deploy = exports.createTransportRequest = exports.getCredentials = void 0;
12
+ exports.undeploy = exports.deploy = exports.createTransportRequest = void 0;
13
13
  const axios_extension_1 = require("@sap-ux/axios-extension");
14
- const btp_utils_1 = require("@sap-ux/btp-utils");
15
- const store_1 = require("@sap-ux/store");
16
14
  const fs_1 = require("fs");
17
15
  const config_1 = require("./config");
18
16
  const prompt_1 = require("./prompt");
17
+ const system_access_1 = require("@sap-ux/system-access");
19
18
  const deploymentCommands = { tryUndeploy, tryDeploy };
20
- /**
21
- * Check the secure storage if it has credentials for the given target.
22
- *
23
- * @param target - ABAP target
24
- * @returns {*} {(Promise<T | undefined>)} - Credentials
25
- */
26
- function getCredentials(target) {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- if (!(0, btp_utils_1.isAppStudio)()) {
29
- const systemService = yield (0, store_1.getService)({ entityName: 'system' });
30
- let system = yield systemService.read(new store_1.BackendSystemKey({ url: target.url, client: target.client }));
31
- if (!system && target.client) {
32
- // check if there are credentials for the default client
33
- system = yield systemService.read(new store_1.BackendSystemKey({ url: target.url }));
34
- }
35
- return system;
36
- }
37
- else {
38
- return undefined;
39
- }
40
- });
41
- }
42
- exports.getCredentials = getCredentials;
43
- /**
44
- * Enhance axios options and create a service provider instance for an ABAP Cloud system.
45
- *
46
- * @param options - predefined axios options
47
- * @param target - url target configuration
48
- * @param noPrompt - only if not truthy prompt for anything
49
- * @param logger - reference to the logger instance
50
- * @returns {*} {(Promise<AbapServiceProvider>)} - ABAP Service Provider
51
- */
52
- function createAbapCloudServiceProvider(options, target, noPrompt, logger) {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- const providerConfig = Object.assign(Object.assign({}, options), { environment: axios_extension_1.AbapCloudEnvironment.Standalone, service: target.serviceKey });
55
- if (!target.serviceKey) {
56
- const storedOpts = yield getCredentials(target);
57
- if (logger && storedOpts) {
58
- providerConfig.service = storedOpts.serviceKeys;
59
- providerConfig.refreshToken = storedOpts.refreshToken;
60
- logger.info(`Using system [${storedOpts.name}] from System store`);
61
- }
62
- if (!storedOpts && !noPrompt) {
63
- providerConfig.service = yield (0, prompt_1.promptServiceKeys)();
64
- }
65
- }
66
- if (providerConfig.service) {
67
- return (0, axios_extension_1.createForAbapOnCloud)(providerConfig);
68
- }
69
- else {
70
- throw new Error('Service keys required for deployment to an ABAP Cloud environment.');
71
- }
72
- });
73
- }
74
- /**
75
- * Checks if credentials are of basic auth type.
76
- *
77
- * @param authOpts credential options
78
- * @returns boolean
79
- */
80
- function isBasicAuth(authOpts) {
81
- return !!authOpts && authOpts.password !== undefined;
82
- }
83
- /**
84
- * Enhance axios options and create a service provider instance for an on-premise ABAP system.
85
- *
86
- * @param options - predefined axios options
87
- * @param target - url target configuration
88
- * @returns {*} {(Promise<AbapServiceProvider>)}
89
- */
90
- function createAbapServiceProvider(options, target) {
91
- return __awaiter(this, void 0, void 0, function* () {
92
- options.baseURL = target.url;
93
- if (target.client) {
94
- options.params['sap-client'] = target.client;
95
- }
96
- if (!options.auth) {
97
- const storedOpts = yield getCredentials(target);
98
- if (isBasicAuth(storedOpts)) {
99
- options.auth = {
100
- username: storedOpts.username,
101
- password: storedOpts.password
102
- };
103
- }
104
- if (storedOpts === null || storedOpts === void 0 ? void 0 : storedOpts.serviceKeys) {
105
- throw new Error('This is an ABAP Cloud system, please add the --cloud arg to ensure the correct deployment flow.');
106
- }
107
- }
108
- return (0, axios_extension_1.createForAbap)(options);
109
- });
110
- }
111
- /**
112
- * Create an instance of an AbapServiceProvider connected to the given target configuration.
113
- *
114
- * @param config - deployment configuration
115
- * @param logger - optional reference to the logger instance
116
- * @returns service instance
117
- */
118
- function getAbapServiceProvider(config, logger) {
119
- var _a, _b, _c;
120
- return __awaiter(this, void 0, void 0, function* () {
121
- let provider;
122
- const options = {};
123
- if (config.strictSsl === false) {
124
- options.ignoreCertErrors = true;
125
- }
126
- if ((_a = config.credentials) === null || _a === void 0 ? void 0 : _a.password) {
127
- options.auth = {
128
- username: (_b = config.credentials) === null || _b === void 0 ? void 0 : _b.username,
129
- password: (_c = config.credentials) === null || _c === void 0 ? void 0 : _c.password
130
- };
131
- }
132
- options.params = config.target.params || {};
133
- // Destination only supported on Business Application studio
134
- if ((0, btp_utils_1.isAppStudio)() && config.target.destination) {
135
- // Need additional properties to determine the type of destination we are dealing with
136
- const destinations = yield (0, btp_utils_1.listDestinations)();
137
- const destination = destinations === null || destinations === void 0 ? void 0 : destinations[config.target.destination];
138
- if (!destination) {
139
- throw new Error(`Destination ${config.target.destination} not found on subaccount`);
140
- }
141
- provider = (0, axios_extension_1.createForDestination)(options, destination);
142
- }
143
- else if ((0, config_1.isUrlTarget)(config.target)) {
144
- if (config.target.cloud) {
145
- provider = yield createAbapCloudServiceProvider(options, config.target, config.retry, logger);
146
- }
147
- else {
148
- provider = yield createAbapServiceProvider(options, config.target);
149
- }
150
- }
151
- else {
152
- throw new Error('Unable to handle the configuration in the current environment.');
153
- }
154
- return provider;
155
- });
156
- }
157
19
  /**
158
20
  * Handle exceptions thrown, in some cases we to retry them.
159
21
  *
@@ -220,7 +82,7 @@ function handle401Error(command, provider, config, logger, archive) {
220
82
  logger.info('Please maintain correct credentials to avoid seeing this error\n\t(see help: https://www.npmjs.com/package/@sap/ux-ui5-tooling#setting-environment-variables-in-a-env-file)');
221
83
  logger.info('Please enter your credentials.');
222
84
  const service = getUi5AbapRepositoryService(provider, config, logger);
223
- const credentials = yield (0, prompt_1.promptCredentials)((_a = service.defaults.auth) === null || _a === void 0 ? void 0 : _a.username);
85
+ const credentials = yield (0, system_access_1.getCredentialsWithPrompts)((_a = service.defaults.auth) === null || _a === void 0 ? void 0 : _a.username);
224
86
  if (Object.keys(credentials).length) {
225
87
  if (config.target.serviceKey) {
226
88
  config.target.serviceKey.uaa.username = credentials.username;
@@ -290,7 +152,10 @@ function createTransportRequest(config, logger, provider) {
290
152
  var _a;
291
153
  return __awaiter(this, void 0, void 0, function* () {
292
154
  if (!provider) {
293
- provider = yield getAbapServiceProvider(config, logger);
155
+ provider = yield (0, system_access_1.createAbapServiceProvider)(config.target, {
156
+ auth: config.credentials,
157
+ ignoreCertErrors: !config.strictSsl
158
+ }, !!config.target.scp, logger);
294
159
  }
295
160
  const adtService = yield provider.getAdtService(axios_extension_1.TransportRequestService);
296
161
  const transportRequest = yield (adtService === null || adtService === void 0 ? void 0 : adtService.createTransportRequest({
@@ -316,7 +181,10 @@ exports.createTransportRequest = createTransportRequest;
316
181
  */
317
182
  function runCommand(command, config, logger, archive = Buffer.from('')) {
318
183
  return __awaiter(this, void 0, void 0, function* () {
319
- const provider = yield getAbapServiceProvider(config, logger);
184
+ const provider = yield (0, system_access_1.createAbapServiceProvider)(config.target, {
185
+ auth: config.credentials,
186
+ ignoreCertErrors: !config.strictSsl
187
+ }, !!config.target.scp, logger);
320
188
  logger.info(`Starting to ${command === "tryDeploy" /* TryCommands.Deploy */ ? 'deploy' : 'undeploy'}${config.test === true ? ' in test mode' : ''}.`);
321
189
  yield deploymentCommands[command](provider, config, logger, archive);
322
190
  });
@@ -1,5 +1,3 @@
1
- import type { ServiceInfo } from '@sap-ux/btp-utils';
2
- import prompts from 'prompts';
3
1
  /**
4
2
  * Prompt for confirmation.
5
3
  *
@@ -7,17 +5,4 @@ import prompts from 'prompts';
7
5
  * @returns true if confirmed, otherwise false
8
6
  */
9
7
  export declare function promptConfirmation(message: string): Promise<boolean>;
10
- /**
11
- * Prompt for username and password.
12
- *
13
- * @param username - optional username that is to be offered as default
14
- * @returns credentials object with username/password
15
- */
16
- export declare function promptCredentials(username?: string): Promise<prompts.Answers<"username" | "password">>;
17
- /**
18
- * Prompt for the location of the service keys.
19
- *
20
- * @returns credentials object with service keys
21
- */
22
- export declare function promptServiceKeys(): Promise<ServiceInfo>;
23
8
  //# sourceMappingURL=prompt.d.ts.map
@@ -12,8 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.promptServiceKeys = exports.promptCredentials = exports.promptConfirmation = void 0;
16
- const fs_1 = require("fs");
15
+ exports.promptConfirmation = void 0;
17
16
  const prompts_1 = __importDefault(require("prompts"));
18
17
  /**
19
18
  * Prompt for confirmation.
@@ -39,48 +38,4 @@ function promptConfirmation(message) {
39
38
  });
40
39
  }
41
40
  exports.promptConfirmation = promptConfirmation;
42
- /**
43
- * Prompt for username and password.
44
- *
45
- * @param username - optional username that is to be offered as default
46
- * @returns credentials object with username/password
47
- */
48
- function promptCredentials(username) {
49
- return __awaiter(this, void 0, void 0, function* () {
50
- const credentials = yield (0, prompts_1.default)([
51
- {
52
- type: 'text',
53
- name: 'username',
54
- initial: username,
55
- message: 'Username:'
56
- },
57
- {
58
- type: 'password',
59
- name: 'password',
60
- message: 'Password:'
61
- }
62
- ]);
63
- return credentials;
64
- });
65
- }
66
- exports.promptCredentials = promptCredentials;
67
- /**
68
- * Prompt for the location of the service keys.
69
- *
70
- * @returns credentials object with service keys
71
- */
72
- function promptServiceKeys() {
73
- return __awaiter(this, void 0, void 0, function* () {
74
- const { path } = yield (0, prompts_1.default)([
75
- {
76
- type: 'text',
77
- name: 'path',
78
- message: 'Please provide the service keys as file:',
79
- validate: (input) => (0, fs_1.existsSync)(input)
80
- }
81
- ]);
82
- return JSON.parse((0, fs_1.readFileSync)(path, 'utf-8'));
83
- });
84
- }
85
- exports.promptServiceKeys = promptServiceKeys;
86
41
  //# sourceMappingURL=prompt.js.map
@@ -138,7 +138,7 @@ function mergeTarget(baseTarget, options) {
138
138
  return {
139
139
  url: targetUrl,
140
140
  client: (_b = options.client) !== null && _b !== void 0 ? _b : baseTarget === null || baseTarget === void 0 ? void 0 : baseTarget.client,
141
- cloud: options.cloud !== undefined ? options.cloud : baseTarget === null || baseTarget === void 0 ? void 0 : baseTarget.cloud,
141
+ scp: options.cloud !== undefined ? options.cloud : baseTarget === null || baseTarget === void 0 ? void 0 : baseTarget.cloud,
142
142
  destination: (_c = options.destination) !== null && _c !== void 0 ? _c : baseTarget === null || baseTarget === void 0 ? void 0 : baseTarget.destination,
143
143
  serviceKey: getServiceKey(options, targetUrl),
144
144
  params: options.queryParams ? parseQueryParams(options.queryParams) : undefined,
@@ -1,18 +1,7 @@
1
- import type { AxiosRequestConfig, BspConfig, ServiceInfo } from '@sap-ux/axios-extension';
1
+ import type { AxiosRequestConfig, BspConfig } from '@sap-ux/axios-extension';
2
2
  import type { LogLevel } from '@sap-ux/logger';
3
+ import type { AbapTarget as BaseAbapTarget, DestinationAbapTarget, UrlAbapTarget } from '@sap-ux/system-access';
3
4
  export declare const NAME = "abap-deploy-task";
4
- export interface UrlAbapTarget {
5
- url: string;
6
- client?: string;
7
- service?: string;
8
- cloud?: boolean;
9
- serviceKey?: ServiceInfo;
10
- params?: AxiosRequestConfig['params'];
11
- }
12
- export interface DestinationAbapTarget {
13
- destination: string;
14
- }
15
- export type AbapTarget = (UrlAbapTarget & Partial<DestinationAbapTarget>) | (DestinationAbapTarget & Partial<UrlAbapTarget>);
16
5
  export interface CommonOptions {
17
6
  /**
18
7
  * Deploy with test mode true i.e. everything is sent to the backend but the backend only checks the inputs without a real deployment
@@ -55,20 +44,29 @@ export interface CommonOptions {
55
44
  */
56
45
  createTransport?: boolean;
57
46
  }
47
+ /**
48
+ * Enhancing the target with an optional service property allowing to use an alias for the deployment service.
49
+ */
50
+ export type AbapTarget = BaseAbapTarget & {
51
+ service?: string;
52
+ };
58
53
  export interface AbapDeployConfig extends CommonOptions {
59
54
  target: AbapTarget;
60
55
  app: BspConfig;
61
56
  credentials?: AxiosRequestConfig['auth'];
57
+ exclude?: string[];
62
58
  }
63
- export interface CliOptions extends Partial<BspConfig>, Partial<DestinationAbapTarget>, Pick<Partial<UrlAbapTarget>, Exclude<keyof UrlAbapTarget, 'serviceKey'>>, Partial<CommonOptions> {
59
+ export interface CliOptions extends Partial<BspConfig>, Partial<DestinationAbapTarget>, Pick<Partial<UrlAbapTarget>, Exclude<keyof UrlAbapTarget, 'serviceKey' | 'scp'>>, Partial<CommonOptions> {
64
60
  config?: string;
65
61
  archiveFolder?: string;
66
62
  archivePath?: string;
67
63
  archiveUrl?: string;
68
64
  cloudServiceKey?: string;
69
65
  queryParams?: string;
66
+ cloud?: boolean;
70
67
  cloudServiceEnv?: boolean;
71
68
  username?: string;
72
69
  password?: string;
70
+ service?: string;
73
71
  }
74
72
  //# sourceMappingURL=index.d.ts.map
@@ -8,7 +8,8 @@ import type { DuplexCollection } from '@ui5/fs';
8
8
  * @param logger - reference to the logger instance
9
9
  * @param workspace - reference to the UI5 tooling workspace object
10
10
  * @param projectName - project properties and configuration
11
+ * @param exclude - array of regex patterns used to exclude folders from archive
11
12
  * @returns {*} {Promise<Buffer>} - archive
12
13
  */
13
- export declare function createUi5Archive(logger: ToolsLogger, workspace: DuplexCollection, projectName: string): Promise<Buffer>;
14
+ export declare function createUi5Archive(logger: ToolsLogger, workspace: DuplexCollection, projectName: string, exclude?: string[]): Promise<Buffer>;
14
15
  //# sourceMappingURL=archive.d.ts.map
@@ -18,19 +18,22 @@ const base_1 = require("../base");
18
18
  * @param logger - reference to the logger instance
19
19
  * @param workspace - reference to the UI5 tooling workspace object
20
20
  * @param projectName - project properties and configuration
21
+ * @param exclude - array of regex patterns used to exclude folders from archive
21
22
  * @returns {*} {Promise<Buffer>} - archive
22
23
  */
23
- function createUi5Archive(logger, workspace, projectName) {
24
+ function createUi5Archive(logger, workspace, projectName, exclude = []) {
24
25
  return __awaiter(this, void 0, void 0, function* () {
25
26
  logger.info('Creating archive with UI5 build result.');
26
27
  const prefix = `/resources/${projectName}/`;
27
28
  const zip = new yazl_1.ZipFile();
28
29
  const resources = yield workspace.byGlob(`${prefix}**/*`);
29
30
  for (const resource of resources) {
30
- const path = resource.getPath().replace(prefix, '');
31
- logger.debug(`Adding ${path}`);
32
- const buffer = yield resource.getBuffer();
33
- zip.addBuffer(buffer, path);
31
+ if (!exclude.some((regex) => RegExp(regex, 'g').exec(resource.getPath()))) {
32
+ const path = resource.getPath().replace(prefix, '');
33
+ logger.debug(`Adding ${path}`);
34
+ const buffer = yield resource.getBuffer();
35
+ zip.addBuffer(buffer, path);
36
+ }
34
37
  }
35
38
  logger.info('Archive created.');
36
39
  return (0, base_1.createBuffer)(zip);
package/dist/ui5/index.js CHANGED
@@ -35,7 +35,7 @@ function task({ workspace, options }) {
35
35
  const config = (0, base_1.validateConfig)(options.configuration);
36
36
  (0, base_1.replaceEnvVariables)(config);
37
37
  // The calling client can use either the projectNamespace or projectName when creating the workspace, needs to match when creating the archive.
38
- const archive = yield (0, archive_1.createUi5Archive)(logger, workspace, (_e = options.projectNamespace) !== null && _e !== void 0 ? _e : options.projectName);
38
+ const archive = yield (0, archive_1.createUi5Archive)(logger, workspace, (_e = options.projectNamespace) !== null && _e !== void 0 ? _e : options.projectName, config.exclude);
39
39
  yield (0, base_1.deploy)(archive, config, logger);
40
40
  });
41
41
  }
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "bugs": {
10
10
  "url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Adeploy-tooling"
11
11
  },
12
- "version": "0.9.4",
12
+ "version": "0.9.6",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -34,12 +34,13 @@
34
34
  "@sap-ux/axios-extension": "1.4.1",
35
35
  "@sap-ux/btp-utils": "0.11.8",
36
36
  "@sap-ux/logger": "0.3.7",
37
- "@sap-ux/store": "0.3.12",
37
+ "@sap-ux/system-access": "0.2.0",
38
38
  "@sap-ux/ui5-config": "0.19.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/prompts": "2.0.14",
42
- "@types/yazl": "2.4.2"
42
+ "@types/yazl": "2.4.2",
43
+ "@sap-ux/store": "0.3.12"
43
44
  },
44
45
  "ui5": {
45
46
  "dependencies": []