@sap-ux/adp-tooling 0.7.4 → 0.8.1

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.
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Checks if the input is a non-empty string.
3
+ *
4
+ * @param input - input to check
5
+ * @returns true if the input is a non-empty string
6
+ */
7
+ export declare function isNotEmptyString(input: string | undefined): boolean;
8
+ /**
9
+ * Checks if the input is a valid SAP client.
10
+ *
11
+ * @param input - input to check
12
+ * @returns true if the input is a valid SAP client
13
+ */
14
+ export declare function isValidSapClient(input: string | undefined): boolean;
15
+ //# sourceMappingURL=helper.d.ts.map
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isValidSapClient = exports.isNotEmptyString = void 0;
4
+ /**
5
+ * Checks if the input is a non-empty string.
6
+ *
7
+ * @param input - input to check
8
+ * @returns true if the input is a non-empty string
9
+ */
10
+ function isNotEmptyString(input) {
11
+ return typeof input === 'string' && input.trim().length > 0;
12
+ }
13
+ exports.isNotEmptyString = isNotEmptyString;
14
+ /**
15
+ * Checks if the input is a valid SAP client.
16
+ *
17
+ * @param input - input to check
18
+ * @returns true if the input is a valid SAP client
19
+ */
20
+ function isValidSapClient(input) {
21
+ return !input || (input.length < 4 && !!new RegExp(/^\d*$/).exec(input));
22
+ }
23
+ exports.isValidSapClient = isValidSapClient;
24
+ //# sourceMappingURL=helper.js.map
@@ -1,12 +1,14 @@
1
1
  import type { AdpWriterConfig } from '../types';
2
- export declare const enum flexLayer {
3
- CUSTOMER_BASE = "CUSTOMER_BASE",
4
- VENDOR = "VENDOR"
5
- }
2
+ import type { AbapTarget } from '@sap-ux/system-access';
3
+ import type { Logger } from '@sap-ux/logger';
4
+ import type { UI5FlexLayer } from '@sap-ux/project-access';
5
+ import type { AppIndex } from '@sap-ux/axios-extension';
6
6
  export type PromptDefaults = {
7
7
  id?: string;
8
8
  reference?: string;
9
9
  url?: string;
10
+ client?: string;
11
+ ignoreCertErrors?: boolean;
10
12
  ft?: boolean;
11
13
  package?: string;
12
14
  transport?: string;
@@ -15,7 +17,20 @@ export type PromptDefaults = {
15
17
  * Prompt the user for the required properties for an adaptation project.
16
18
  *
17
19
  * @param defaults optional default values for the prompts
20
+ * @param logger optional logger instance
18
21
  * @returns a configuration for the adp writer
19
22
  */
20
- export declare function promptGeneratorInput(defaults?: PromptDefaults): Promise<AdpWriterConfig>;
23
+ export declare function promptGeneratorInput(defaults: PromptDefaults | undefined, logger: Logger): Promise<AdpWriterConfig>;
24
+ /**
25
+ * Prompt the user for the target system.
26
+ *
27
+ * @param defaults default values for the prompts
28
+ * @param logger logger instance
29
+ * @returns apps, layer, target url and client
30
+ */
31
+ export declare function promptTarget(defaults: PromptDefaults, logger: Logger): Promise<{
32
+ apps: AppIndex;
33
+ layer: UI5FlexLayer;
34
+ target: AbapTarget;
35
+ }>;
21
36
  //# sourceMappingURL=prompt.d.ts.map
@@ -12,41 +12,51 @@ 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.promptGeneratorInput = void 0;
15
+ exports.promptTarget = exports.promptGeneratorInput = void 0;
16
16
  const prompts_1 = __importDefault(require("prompts"));
17
+ const system_access_1 = require("@sap-ux/system-access");
18
+ const helper_1 = require("./helper");
17
19
  /**
18
20
  * Prompt the user for the required properties for an adaptation project.
19
21
  *
20
22
  * @param defaults optional default values for the prompts
23
+ * @param logger optional logger instance
21
24
  * @returns a configuration for the adp writer
22
25
  */
23
- function promptGeneratorInput(defaults = {}) {
26
+ function promptGeneratorInput(defaults, logger) {
24
27
  var _a;
25
28
  return __awaiter(this, void 0, void 0, function* () {
29
+ defaults = defaults !== null && defaults !== void 0 ? defaults : {};
30
+ const { target, apps, layer } = yield promptTarget(defaults, logger);
26
31
  const app = yield (0, prompts_1.default)([
27
32
  {
28
- type: 'select',
29
- choices: [
30
- { title: "CUSTOMER_BASE" /* flexLayer.CUSTOMER_BASE */, value: "CUSTOMER_BASE" /* flexLayer.CUSTOMER_BASE */ },
31
- { title: "VENDOR" /* flexLayer.VENDOR */, value: "VENDOR" /* flexLayer.VENDOR */ }
32
- ],
33
- name: 'layer',
34
- message: 'Flex layer:'
33
+ type: 'autocomplete',
34
+ name: 'reference',
35
+ message: 'Original application:',
36
+ initial: defaults.reference,
37
+ choices: apps.map((app) => {
38
+ var _a;
39
+ return ({
40
+ title: `${app['sap.app/title']} (${((_a = app['sap.fiori/registrationIds']) !== null && _a !== void 0 ? _a : []).join(',')})`,
41
+ value: app['sap.app/id']
42
+ });
43
+ }),
44
+ suggest: (input, choices) => Promise.resolve(choices.filter((i) => i.title.includes(input)))
35
45
  },
36
46
  {
37
47
  type: 'text',
38
48
  name: 'id',
39
- message: (_prev, values) => {
40
- if (values.layer === "CUSTOMER_BASE" /* flexLayer.CUSTOMER_BASE */) {
41
- return 'New adaptation id (CUSTOMER_BASE selected, customer prefix will be automatically added to the id):';
49
+ message: (_prev) => {
50
+ if (layer === 'CUSTOMER_BASE') {
51
+ return 'New adaptation id (prefix "customer" will be automatically added to the id):';
42
52
  }
43
53
  else {
44
54
  return 'New adaptation id:';
45
55
  }
46
56
  },
47
57
  initial: defaults.id,
48
- format: (input, values) => {
49
- if (values.layer === "CUSTOMER_BASE" /* flexLayer.CUSTOMER_BASE */ && !input.startsWith('customer.')) {
58
+ format: (input) => {
59
+ if (layer === 'CUSTOMER_BASE' && !input.startsWith('customer.')) {
50
60
  return `customer.${input}`;
51
61
  }
52
62
  else {
@@ -55,34 +65,12 @@ function promptGeneratorInput(defaults = {}) {
55
65
  },
56
66
  validate: (input) => (input === null || input === void 0 ? void 0 : input.length) > 0
57
67
  },
58
- {
59
- type: 'text',
60
- name: 'reference',
61
- message: 'Original application id:',
62
- initial: defaults.reference,
63
- validate: (input) => (input === null || input === void 0 ? void 0 : input.length) > 0
64
- },
65
68
  {
66
69
  type: 'text',
67
70
  name: 'title',
68
71
  message: 'Application title:'
69
72
  }
70
73
  ]);
71
- const target = yield (0, prompts_1.default)([
72
- {
73
- type: 'text',
74
- name: 'url',
75
- message: 'Target system url:',
76
- initial: defaults.url,
77
- validate: (input) => (input === null || input === void 0 ? void 0 : input.length) > 0
78
- },
79
- {
80
- type: 'text',
81
- name: 'client',
82
- message: 'Client (optional):',
83
- validate: (input) => (input ? input.length < 4 : true)
84
- }
85
- ]);
86
74
  const deploy = yield (0, prompts_1.default)([
87
75
  {
88
76
  type: 'text',
@@ -107,8 +95,93 @@ function promptGeneratorInput(defaults = {}) {
107
95
  validate: (input) => (input === null || input === void 0 ? void 0 : input.length) > 0
108
96
  }
109
97
  ]);
110
- return { app, target, options, deploy };
98
+ return {
99
+ app: Object.assign(Object.assign({}, app), { layer }),
100
+ target,
101
+ options,
102
+ deploy
103
+ };
111
104
  });
112
105
  }
113
106
  exports.promptGeneratorInput = promptGeneratorInput;
107
+ /**
108
+ * Prompt the user for the target system.
109
+ *
110
+ * @param defaults default values for the prompts
111
+ * @param logger logger instance
112
+ * @returns apps, layer, target url and client
113
+ */
114
+ function promptTarget(defaults, logger) {
115
+ return __awaiter(this, void 0, void 0, function* () {
116
+ let count = 0;
117
+ let target = { url: defaults.url, client: defaults.client };
118
+ while (count < 3) {
119
+ try {
120
+ count++;
121
+ target = yield (0, prompts_1.default)([
122
+ {
123
+ type: 'text',
124
+ name: 'url',
125
+ message: 'Target system url:',
126
+ initial: target.url,
127
+ validate: helper_1.isNotEmptyString,
128
+ format: (input) => input.trim()
129
+ },
130
+ {
131
+ type: 'text',
132
+ name: 'client',
133
+ message: 'Client (optional):',
134
+ initial: target.client,
135
+ validate: helper_1.isValidSapClient
136
+ }
137
+ ]);
138
+ const systemInfo = yield fetchSystemInformation(target, defaults.ignoreCertErrors, logger);
139
+ return Object.assign({ target }, systemInfo);
140
+ }
141
+ catch (error) {
142
+ logger.error('Error while fetching system information. Please check your input.');
143
+ logger.debug(error.message);
144
+ if (error.code === 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY') {
145
+ logger.error('If you are using a self-signed certificate, please use the --ignore-cert-errors flag.');
146
+ const confirm = yield (0, prompts_1.default)([
147
+ {
148
+ type: 'confirm',
149
+ name: 'ignoreCertErrors',
150
+ message: 'Do you want to ignore certificate errors?'
151
+ }
152
+ ]);
153
+ defaults.ignoreCertErrors = confirm.ignoreCertErrors;
154
+ }
155
+ }
156
+ }
157
+ throw new Error('Unable to fetch system information.');
158
+ });
159
+ }
160
+ exports.promptTarget = promptTarget;
161
+ /**
162
+ * Fetches the system information from the target system.
163
+ *
164
+ * @param target target system
165
+ * @param ignoreCertErrors ignore certificate errors
166
+ * @param logger logger instance
167
+ * @returns app index and layer
168
+ */
169
+ function fetchSystemInformation(target, ignoreCertErrors, logger) {
170
+ return __awaiter(this, void 0, void 0, function* () {
171
+ const provider = yield (0, system_access_1.createAbapServiceProvider)(target, {
172
+ ignoreCertErrors
173
+ }, true, logger);
174
+ logger.info('Fetching system information...');
175
+ const ato = yield provider.getAtoInfo();
176
+ const layer = ato.tenantType === 'SAP' ? 'VENDOR' : 'CUSTOMER_BASE';
177
+ logger.info(`Target layer: ${layer}`);
178
+ logger.info('Fetching list of available applications... (it can take a moment)');
179
+ const appIndex = provider.getAppIndex();
180
+ const apps = yield appIndex.search({
181
+ 'sap.ui/technology': 'UI5',
182
+ 'sap.app/type': 'application'
183
+ }, ['sap.app/id', 'sap.app/title', 'sap.fiori/registrationIds']);
184
+ return { apps, layer };
185
+ });
186
+ }
114
187
  //# sourceMappingURL=prompt.js.map
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%3Aadp-tooling"
11
11
  },
12
- "version": "0.7.4",
12
+ "version": "0.8.1",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -29,9 +29,9 @@
29
29
  "mem-fs-editor": "9.4.0",
30
30
  "prompts": "2.4.2",
31
31
  "adm-zip": "0.5.10",
32
- "@sap-ux/axios-extension": "1.8.1",
32
+ "@sap-ux/axios-extension": "1.9.0",
33
33
  "@sap-ux/logger": "0.4.0",
34
- "@sap-ux/system-access": "0.3.7",
34
+ "@sap-ux/system-access": "0.3.8",
35
35
  "@sap-ux/ui5-config": "0.21.0"
36
36
  },
37
37
  "devDependencies": {
@@ -46,7 +46,7 @@
46
46
  "nock": "13.4.0",
47
47
  "rimraf": "5.0.1",
48
48
  "supertest": "6.3.3",
49
- "@sap-ux/project-access": "1.16.2",
49
+ "@sap-ux/project-access": "1.17.0",
50
50
  "@sap-ux/store": "0.4.0"
51
51
  },
52
52
  "peerDependencies": {