trm-client 4.4.1 → 4.6.0

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.
package/README.md CHANGED
@@ -56,3 +56,5 @@ Make sure to open an issue first.
56
56
  Contributions will be merged upon approval.
57
57
 
58
58
  [Click here](https://docs.trmregistry.com/#/CONTRIBUTING) for the full list of TRM contribution guidelines.
59
+
60
+ [<img src="https://trmregistry.com/public/contributors?image=true">](https://docs.trmregistry.com/#/?id=contributors)
package/changelog.txt CHANGED
@@ -8,6 +8,20 @@ Legend
8
8
  + : added
9
9
  - : removed
10
10
 
11
+ 2025-05-08 v4.6.0
12
+ -------------------
13
+
14
+ ! trm-core ^6.8.0
15
+ * saprouter in alias
16
+
17
+ 2025-05-08 v4.5.0
18
+ -------------------
19
+
20
+ ! trm-core ^6.7.0
21
+ ! error handling
22
+ * alias command/saprouter alias save
23
+ * fix connection validators
24
+
11
25
  2025-04-28 v4.4.1
12
26
  -------------------
13
27
 
@@ -27,6 +27,7 @@ const _create = () => __awaiter(void 0, void 0, void 0, function* () {
27
27
  });
28
28
  });
29
29
  const _view = (alias) => {
30
+ const client = alias.login.client;
30
31
  const lang = alias.login.lang;
31
32
  const user = alias.login.user;
32
33
  const hasPassword = alias.login.passwd ? true : false;
@@ -83,6 +84,12 @@ const _view = (alias) => {
83
84
  else {
84
85
  trm_commons_1.Logger.warning(`Logon language: Unknown`);
85
86
  }
87
+ if (client) {
88
+ trm_commons_1.Logger.info(`Logon client: ${client}`);
89
+ }
90
+ else {
91
+ trm_commons_1.Logger.warning(`Logon client: Unknown`);
92
+ }
86
93
  if (user) {
87
94
  trm_commons_1.Logger.info(`Logon user: ${user}`);
88
95
  }
@@ -90,7 +97,7 @@ const _view = (alias) => {
90
97
  trm_commons_1.Logger.warning(`Logon user: Unknown`);
91
98
  }
92
99
  if (hasPassword) {
93
- trm_commons_1.Logger.info(`Logon password: Saved`);
100
+ trm_commons_1.Logger.info(`Logon password: SAVED IN PLAIN TEXT`);
94
101
  }
95
102
  else {
96
103
  trm_commons_1.Logger.warning(`Logon password: Unknown`);
@@ -138,7 +145,8 @@ const _edit = (alias) => __awaiter(void 0, void 0, void 0, function* () {
138
145
  }, {
139
146
  lang: connectionArgs.lang,
140
147
  passwd: connectionArgs.passwd,
141
- user: connectionArgs.user
148
+ user: connectionArgs.user,
149
+ client: connectionArgs.client
142
150
  });
143
151
  }
144
152
  yield updatedAlias.getConnection().connect();
@@ -174,7 +182,8 @@ const _edit = (alias) => __awaiter(void 0, void 0, void 0, function* () {
174
182
  }, {
175
183
  lang: alias.login.lang,
176
184
  passwd: alias.login.passwd,
177
- user: alias.login.user
185
+ user: alias.login.user,
186
+ client: alias.login.client
178
187
  });
179
188
  }
180
189
  }
@@ -188,35 +197,38 @@ const _delete = (alias) => __awaiter(void 0, void 0, void 0, function* () {
188
197
  function alias(commandArgs) {
189
198
  return __awaiter(this, void 0, void 0, function* () {
190
199
  const aAlias = systemAlias_1.SystemAlias.getAll();
191
- var aliasPick;
192
- if (commandArgs.systemAlias) {
193
- if (!aAlias.find(o => o.alias === commandArgs.systemAlias)) {
194
- trm_commons_1.Logger.warning(`Alias "${commandArgs.systemAlias}" not found.`);
200
+ var aliasPick = '';
201
+ var inq1Choices = [];
202
+ if (commandArgs.alias) {
203
+ if (!aAlias.find(o => o.alias === commandArgs.alias)) {
204
+ trm_commons_1.Logger.warning(`Alias "${commandArgs.alias}" not found.`);
205
+ inq1Choices.push({
206
+ name: `Create alias`,
207
+ value: `create`
208
+ });
195
209
  }
196
210
  else {
197
- aliasPick = commandArgs.systemAlias;
211
+ aliasPick = commandArgs.alias;
198
212
  }
199
213
  }
214
+ inq1Choices = inq1Choices.concat([{
215
+ name: aliasPick ? `View "${aliasPick}"` : `View alias`,
216
+ value: `pick_view`
217
+ }, {
218
+ name: aliasPick ? `Check "${aliasPick}" connection` : `Check alias connection`,
219
+ value: `pick_check`
220
+ }, {
221
+ name: aliasPick ? `Edit "${aliasPick}"` : `Edit alias`,
222
+ value: `pick_edit`
223
+ }, {
224
+ name: aliasPick ? `Delete "${aliasPick}"` : `Delete alias`,
225
+ value: `pick_delete`
226
+ }]);
200
227
  const inq1 = yield trm_commons_1.Inquirer.prompt({
201
228
  name: `action`,
202
229
  message: `Action`,
203
230
  type: `list`,
204
- choices: [{
205
- name: `Create alias`,
206
- value: `create`
207
- }, {
208
- name: `View alias`,
209
- value: `pick_view`
210
- }, {
211
- name: `Check alias connection`,
212
- value: `pick_check`
213
- }, {
214
- name: `Edit alias`,
215
- value: `pick_edit`
216
- }, {
217
- name: `Delete alias`,
218
- value: `pick_delete`
219
- }]
231
+ choices: inq1Choices
220
232
  });
221
233
  if (inq1.action.startsWith(`pick_`) && !aliasPick) {
222
234
  const inq2 = yield trm_commons_1.Inquirer.prompt({
@@ -1,3 +1,3 @@
1
1
  export type AliasArguments = {
2
- systemAlias: string;
2
+ alias?: string;
3
3
  };
@@ -20,6 +20,7 @@ function createAlias(commandArgs) {
20
20
  noSystemAlias: true,
21
21
  force: true
22
22
  }, false);
23
+ trm_commons_1.Logger.loading(`Connecting to "${commandArgs.alias}"...`);
23
24
  var alias;
24
25
  if (connectionArgs.type === utils_1.SystemConnectorType.RFC) {
25
26
  alias = systemAlias_1.SystemAlias.create(commandArgs.alias, connectionArgs.type, {
@@ -41,7 +42,8 @@ function createAlias(commandArgs) {
41
42
  }, {
42
43
  lang: connectionArgs.lang,
43
44
  passwd: connectionArgs.passwd,
44
- user: connectionArgs.user
45
+ user: connectionArgs.user,
46
+ client: connectionArgs.client
45
47
  });
46
48
  }
47
49
  if (alias) {
@@ -174,7 +174,7 @@ function connect(commandArgs, createAliasIfNotExist = true, addNoConnection) {
174
174
  type: `input`,
175
175
  name: `forwardRfcDest`,
176
176
  message: `Forward RFC Destination`,
177
- default: commandArgs.forwardRfcDest,
177
+ default: commandArgs.forwardRfcDest || 'NONE',
178
178
  when: (hash) => {
179
179
  return hash.type === 'REST' && (commandArgs.forwardRfcDest || force);
180
180
  }
@@ -194,6 +194,14 @@ function connect(commandArgs, createAliasIfNotExist = true, addNoConnection) {
194
194
  default: commandArgs.dest,
195
195
  when: (hash) => {
196
196
  return hash.type === 'RFC' && ((commandArgs.dest ? false : true) || force);
197
+ },
198
+ validate: (val) => {
199
+ if (val && /^\w{3}$/.test(val)) {
200
+ return true;
201
+ }
202
+ else {
203
+ return `Invalid input: expected length 3, only letters allowed`;
204
+ }
197
205
  }
198
206
  }, {
199
207
  type: `input`,
@@ -202,6 +210,14 @@ function connect(commandArgs, createAliasIfNotExist = true, addNoConnection) {
202
210
  default: commandArgs.sysnr,
203
211
  when: (hash) => {
204
212
  return hash.type === 'RFC' && ((commandArgs.sysnr ? false : true) || force);
213
+ },
214
+ validate: (val) => {
215
+ if (val && /^\d{2}$/.test(val)) {
216
+ return true;
217
+ }
218
+ else {
219
+ return `Invalid input: expected length 2, only numbers allowed`;
220
+ }
205
221
  }
206
222
  }, {
207
223
  type: `input`,
@@ -217,7 +233,15 @@ function connect(commandArgs, createAliasIfNotExist = true, addNoConnection) {
217
233
  message: `Logon Client`,
218
234
  default: commandArgs.client,
219
235
  when: (hash) => {
220
- return (hash.type === 'RFC' || inputType === 'logon') && ((commandArgs.client ? false : true) || force);
236
+ return (commandArgs.client ? false : true) || force;
237
+ },
238
+ validate: (val) => {
239
+ if (val && /^\d{3}$/.test(val)) {
240
+ return true;
241
+ }
242
+ else {
243
+ return `Invalid input: expected length 3, only numbers allowed`;
244
+ }
221
245
  }
222
246
  }, {
223
247
  type: `input`,
@@ -281,6 +305,7 @@ function connect(commandArgs, createAliasIfNotExist = true, addNoConnection) {
281
305
  else if (result.type === utils_1.SystemConnectorType.REST) {
282
306
  result.endpoint = result.endpoint || commandArgs.endpoint;
283
307
  result.forwardRfcDest = result.forwardRfcDest || commandArgs.forwardRfcDest;
308
+ result.client = result.client || commandArgs.client;
284
309
  if (result.forwardRfcDest) {
285
310
  result.forwardRfcDest = result.forwardRfcDest.toUpperCase();
286
311
  }
@@ -295,7 +320,8 @@ function connect(commandArgs, createAliasIfNotExist = true, addNoConnection) {
295
320
  login: {
296
321
  user: result.user,
297
322
  passwd: result.passwd,
298
- lang: result.lang
323
+ lang: result.lang,
324
+ client: result.client
299
325
  }
300
326
  });
301
327
  }
package/dist/index.js CHANGED
@@ -11,15 +11,12 @@ program
11
11
  .version((0, utils_1.getClientVersion)(), `-cv, --clientVersion`, `Client version.`);
12
12
  const createAlias = program.command(`createAlias <alias>`)
13
13
  .description(`Create a new system alias.`);
14
- (0, utils_1.registerCommand)(createAlias, {
15
- noSystemAlias: true,
16
- });
14
+ (0, utils_1.registerCommand)(createAlias);
17
15
  const deleteAlias = program.command(`deleteAlias <alias>`)
18
16
  .description(`Delete a system alias.`);
19
17
  (0, utils_1.registerCommand)(deleteAlias);
20
- const manageAliases = program.command(`alias`)
21
- .description(`List and manage aliases.`)
22
- .option(`-a, --systemAlias <systemAlias>`, `System Alias.`);
18
+ const manageAliases = program.command(`alias [alias]`)
19
+ .description(`List and manage aliases.`);
23
20
  (0, utils_1.registerCommand)(manageAliases);
24
21
  const addRegistry = program.command(`addRegistry <registryName>`)
25
22
  .description(`Add a new registry.`)
@@ -71,12 +71,16 @@ class SystemAlias {
71
71
  passwd: o.login.passwd,
72
72
  lang: o.login.lang
73
73
  };
74
+ if (o.connection.saprouter) {
75
+ oContent[o.alias].saprouter = o.connection.saprouter;
76
+ }
74
77
  }
75
78
  else if (o.type === utils_1.SystemConnectorType.REST) {
76
79
  oContent[o.alias] = {
77
80
  type: o.type,
78
81
  endpoint: o.connection.endpoint,
79
82
  rfcdest: o.connection.rfcdest || 'NONE',
83
+ client: o.login.client,
80
84
  user: o.login.user,
81
85
  passwd: o.login.passwd,
82
86
  lang: o.login.lang
@@ -127,7 +131,8 @@ class SystemAlias {
127
131
  login: {
128
132
  user: oIni[sAlias].user,
129
133
  passwd: oIni[sAlias].passwd,
130
- lang: oIni[sAlias].lang
134
+ lang: oIni[sAlias].lang,
135
+ client: oIni[sAlias].client
131
136
  }
132
137
  });
133
138
  }
@@ -72,4 +72,5 @@ export declare class NoConnection implements ISystemConnector {
72
72
  getAbapgitSource: () => Promise<any>;
73
73
  executePostActivity: () => Promise<any>;
74
74
  readClassDescriptions: () => Promise<any>;
75
+ regenProg: () => Promise<any>;
75
76
  }
@@ -97,6 +97,7 @@ class NoConnection {
97
97
  this.getAbapgitSource = () => __awaiter(this, void 0, void 0, function* () { return this._throw(); });
98
98
  this.executePostActivity = () => __awaiter(this, void 0, void 0, function* () { return this._throw(); });
99
99
  this.readClassDescriptions = () => __awaiter(this, void 0, void 0, function* () { return this._throw(); });
100
+ this.regenProg = () => __awaiter(this, void 0, void 0, function* () { return this._throw(); });
100
101
  }
101
102
  _throw() {
102
103
  throw new Error(`No connection to SAP server.`);
@@ -88,21 +88,6 @@ function executeCommand(args) {
88
88
  const registryAuthBlacklist = args.registryAuthBlacklist;
89
89
  const ignoreRegistryUnreachable = args.ignoreRegistryUnreachable;
90
90
  yield (0, checkCliUpdate_1.checkCliUpdate)(true);
91
- if (requiresConnection) {
92
- var system;
93
- if (args.systemAlias) {
94
- system = systemAlias_1.SystemAlias.get(args.systemAlias).getConnection();
95
- }
96
- else {
97
- const skipCreateAlias = ['createAlias', 'deleteAlias', 'alias'];
98
- system = (yield commands.connect(args, !skipCreateAlias.includes(args.command), args.addNoConnection)).connection;
99
- }
100
- yield system.connect();
101
- trm_core_1.SystemConnector.systemConnector = system;
102
- if (requiresTrmDependencies) {
103
- yield (0, checkTrmDependencies_1.checkTrmDependencies)(args);
104
- }
105
- }
106
91
  if (requiresRegistry) {
107
92
  var registryAlias;
108
93
  var registry;
@@ -155,6 +140,21 @@ function executeCommand(args) {
155
140
  }
156
141
  });
157
142
  }
143
+ if (requiresConnection) {
144
+ var system;
145
+ if (args.systemAlias) {
146
+ system = systemAlias_1.SystemAlias.get(args.systemAlias).getConnection();
147
+ }
148
+ else {
149
+ const skipCreateAlias = ['createAlias', 'deleteAlias', 'alias'];
150
+ system = (yield commands.connect(args, !skipCreateAlias.includes(args.command), args.addNoConnection)).connection;
151
+ }
152
+ yield system.connect();
153
+ trm_core_1.SystemConnector.systemConnector = system;
154
+ if (requiresTrmDependencies) {
155
+ yield (0, checkTrmDependencies_1.checkTrmDependencies)(args);
156
+ }
157
+ }
158
158
  var commandFn = args.command;
159
159
  if (!commands[commandFn]) {
160
160
  commandFn = `_${commandFn}`;
@@ -16,8 +16,10 @@ exports.logError = void 0;
16
16
  const trm_core_1 = require("trm-core");
17
17
  const util_1 = require("util");
18
18
  const chalk_1 = __importDefault(require("chalk"));
19
- const node_html_parser_1 = require("node-html-parser");
20
19
  const trm_commons_1 = require("trm-commons");
20
+ const _getUnauthorizedError = () => {
21
+ return `User "${trm_core_1.SystemConnector.getLogonUser()}" is not authorized to execute TRM RFC functions. Follow this guide https://docs.trmregistry.com/#/server/docs/setup?id=user-authorization-maintenance.`;
22
+ };
21
23
  function logError(err) {
22
24
  return __awaiter(this, void 0, void 0, function* () {
23
25
  var originalException;
@@ -35,6 +37,7 @@ function logError(err) {
35
37
  var sError = (originalException.message || 'Unknown error.').trim();
36
38
  var aError = [];
37
39
  if (originalException.name === 'ExitPromptError') {
40
+ trm_commons_1.Logger.log(`User exited prompt: ${originalException.message}`, true);
38
41
  return;
39
42
  }
40
43
  else if (originalException.name === 'TrmRegistryError') {
@@ -43,30 +46,38 @@ function logError(err) {
43
46
  }
44
47
  }
45
48
  else if (originalException.name === 'TrmRFCClient') {
46
- if (originalException.rfcError && originalException.rfcError) {
47
- sError = `${chalk_1.default.black.bgRed(originalException.rfcError.key)} ${sError}`;
48
- if (originalException.rfcError.key === "TRM_RFC_UNAUTHORIZED") {
49
- aError.push(chalk_1.default.black.bgRed(`\nUser "${trm_core_1.SystemConnector.getLogonUser()}" is not authorized to execute TRM RFC functions. Follow this guide https://docs.trmregistry.com/#/server/docs/setup?id=user-authorization-maintenance.`));
49
+ const rfcClientError = originalException;
50
+ if (rfcClientError.rfcError && rfcClientError.rfcError.key) {
51
+ if (rfcClientError.rfcError.key[0] === 'Z') {
52
+ trm_commons_1.Logger.error(`${rfcClientError.rfcError.key} ${sError}`, true);
53
+ }
54
+ else {
55
+ sError = `${chalk_1.default.black.bgRed(rfcClientError.rfcError.key)} ${sError}`;
56
+ if (rfcClientError.rfcError.key === "TRM_RFC_UNAUTHORIZED") {
57
+ sError = chalk_1.default.black.bgRed(`${chalk_1.default.black.bgRed(rfcClientError.rfcError.key)} ${_getUnauthorizedError()}`);
58
+ }
50
59
  }
51
60
  }
52
61
  }
53
- else if (originalException.name === 'TrmRestServerError') {
54
- if (sError[0] === '<') {
55
- try {
56
- sError = (0, node_html_parser_1.parse)(sError).querySelector('title').innerText;
62
+ else if (originalException.name === 'TrmRESTClient') {
63
+ const restClientError = originalException;
64
+ if (restClientError.restError) {
65
+ if (restClientError.restError.status === 401) {
66
+ aError.push(chalk_1.default.black.bgRed(`${chalk_1.default.black.bgRed(restClientError.restError.status)} ${_getUnauthorizedError()}`));
57
67
  }
58
- catch (e) { }
59
- }
60
- if (originalException.status) {
61
- if (originalException.status === 404) {
62
- aError.push(`Service cannot be reached (Check if trm-rest is installed and activated correctly).`);
68
+ else if (restClientError.restError.status === 404) {
69
+ aError.push(`${chalk_1.default.black.bgRed(restClientError.restError.status)} Service cannot be reached (Check if trm-rest is installed and activated correctly).`);
63
70
  }
64
- sError = `${chalk_1.default.black.bgRed(originalException.status)} ${sError}`;
71
+ sError = `${chalk_1.default.black.bgRed(restClientError.restError.status)} ${sError}`;
65
72
  }
66
73
  }
67
- aError.push(sError);
74
+ if (sError) {
75
+ trm_commons_1.Logger.error(sError);
76
+ }
68
77
  aError.forEach(message => {
69
- trm_commons_1.Logger.error(message);
78
+ if (message) {
79
+ trm_commons_1.Logger.error(message);
80
+ }
70
81
  });
71
82
  });
72
83
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trm-client",
3
- "version": "4.4.1",
3
+ "version": "4.6.0",
4
4
  "description": "TRM (Transport Request Manager) Client",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -43,10 +43,9 @@
43
43
  "get-latest-version": "^5.1.0",
44
44
  "get-root-path": "^2.0.2",
45
45
  "ini": "^4.1.1",
46
- "node-html-parser": "^6.1.13",
47
46
  "semver": "^7.5.4",
48
47
  "trm-commons": "^1.0.0",
49
- "trm-core": "^6.5.0",
48
+ "trm-core": "^6.8.0",
50
49
  "trm-registry-types": "^1.2.0",
51
50
  "xml2js": "^0.6.2"
52
51
  },