trm-client 4.10.0 → 5.0.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/changelog.txt +10 -0
- package/dist/commands/alias.js +12 -125
- package/dist/commands/arguments/ConnectArguments.d.ts +1 -2
- package/dist/commands/compare.js +5 -46
- package/dist/commands/content.js +2 -3
- package/dist/commands/createAlias.js +14 -44
- package/dist/commands/import.js +2 -3
- package/dist/commands/install.js +2 -3
- package/dist/commands/prompts/connect.d.ts +2 -1
- package/dist/commands/prompts/connect.js +82 -201
- package/dist/commands/settings.js +3 -3
- package/dist/systemAlias/SystemAlias.d.ts +9 -9
- package/dist/systemAlias/SystemAlias.js +67 -102
- package/dist/systemAlias/SystemAliasData.d.ts +2 -5
- package/dist/utils/Context.d.ts +14 -0
- package/dist/{settings/Settings.js → utils/Context.js} +51 -21
- package/dist/utils/NoConnection.d.ts +1 -0
- package/dist/utils/NoConnection.js +1 -0
- package/dist/utils/executeCommand.js +15 -2
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.js +2 -1
- package/dist/utils/registerCommand.js +4 -4
- package/package.json +4 -4
- package/dist/settings/Settings.d.ts +0 -11
- package/dist/settings/index.d.ts +0 -2
- package/dist/settings/index.js +0 -18
- package/dist/utils/getSystemConnector.d.ts +0 -9
- package/dist/utils/getSystemConnector.js +0 -32
- /package/dist/{settings → utils}/SettingsData.d.ts +0 -0
- /package/dist/{settings → utils}/SettingsData.js +0 -0
|
@@ -8,14 +8,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
exports.connect = connect;
|
|
16
13
|
const systemAlias_1 = require("../../systemAlias");
|
|
17
14
|
const utils_1 = require("../../utils");
|
|
18
|
-
const normalize_url_1 = __importDefault(require("@esm2cjs/normalize-url"));
|
|
19
15
|
const trm_commons_1 = require("trm-commons");
|
|
20
16
|
const languageList = [
|
|
21
17
|
{ value: 'AR', name: 'AR (Arabic)' },
|
|
@@ -58,8 +54,6 @@ const languageList = [
|
|
|
58
54
|
{ value: 'UK', name: 'UK (Ukrainian)' },
|
|
59
55
|
{ value: 'VI', name: 'VI (Vietnamese)' }
|
|
60
56
|
];
|
|
61
|
-
const _createAliasIfNotExists = () => {
|
|
62
|
-
};
|
|
63
57
|
function connect(commandArgs_1) {
|
|
64
58
|
return __awaiter(this, arguments, void 0, function* (commandArgs, createAliasIfNotExist = true, addNoConnection) {
|
|
65
59
|
const noSystemAlias = commandArgs.noSystemAlias ? true : false;
|
|
@@ -85,16 +79,15 @@ function connect(commandArgs_1) {
|
|
|
85
79
|
});
|
|
86
80
|
}
|
|
87
81
|
aInputType.push({
|
|
88
|
-
value:
|
|
82
|
+
value: null, name: 'Manual input'
|
|
89
83
|
});
|
|
90
84
|
if (aSapLogonConnections.length > 0) {
|
|
91
85
|
aInputType.push({
|
|
92
86
|
value: 'logon', name: 'SAP Logon Connection (Uses node-rfc)'
|
|
93
87
|
});
|
|
94
88
|
}
|
|
95
|
-
var result;
|
|
96
89
|
var inputType;
|
|
97
|
-
if (!commandArgs.
|
|
90
|
+
if (!commandArgs.type) {
|
|
98
91
|
const inq1 = yield trm_commons_1.Inquirer.prompt({
|
|
99
92
|
type: `list`,
|
|
100
93
|
name: `inputType`,
|
|
@@ -103,29 +96,26 @@ function connect(commandArgs_1) {
|
|
|
103
96
|
});
|
|
104
97
|
inputType = inq1.inputType;
|
|
105
98
|
}
|
|
106
|
-
else {
|
|
107
|
-
inputType = 'input';
|
|
108
|
-
}
|
|
109
99
|
if (inputType === 'none') {
|
|
110
|
-
return
|
|
111
|
-
connection: new utils_1.NoConnection()
|
|
112
|
-
};
|
|
100
|
+
return null;
|
|
113
101
|
}
|
|
114
102
|
else if (inputType === 'alias') {
|
|
115
|
-
const inq2 = yield trm_commons_1.Inquirer.prompt({
|
|
103
|
+
const inq2 = (yield trm_commons_1.Inquirer.prompt({
|
|
116
104
|
type: `list`,
|
|
117
|
-
name: `
|
|
105
|
+
name: `alias`,
|
|
118
106
|
message: `Select alias`,
|
|
119
107
|
choices: aAlias.map(o => {
|
|
120
108
|
return {
|
|
121
|
-
value: o
|
|
109
|
+
value: o, name: o.alias
|
|
122
110
|
};
|
|
123
111
|
})
|
|
124
|
-
});
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
112
|
+
})).alias;
|
|
113
|
+
const connection = utils_1.Context.getInstance().connections.find(o => o.name === inq2.type);
|
|
114
|
+
if (!connection) {
|
|
115
|
+
throw new Error(`Unknown connection type "${inq2.type}" in alias "${inq2.name}"`);
|
|
116
|
+
}
|
|
117
|
+
connection.setData(inq2.data);
|
|
118
|
+
return connection;
|
|
129
119
|
}
|
|
130
120
|
else {
|
|
131
121
|
if (inputType === 'logon') {
|
|
@@ -144,193 +134,84 @@ function connect(commandArgs_1) {
|
|
|
144
134
|
commandArgs.dest = logonConnection.dest;
|
|
145
135
|
commandArgs.sysnr = logonConnection.sysnr;
|
|
146
136
|
commandArgs.saprouter = logonConnection.saprouter;
|
|
147
|
-
type =
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
type = commandArgs.type;
|
|
137
|
+
type = 'RFC';
|
|
151
138
|
}
|
|
152
|
-
|
|
139
|
+
if (!type || force) {
|
|
140
|
+
type = (yield trm_commons_1.Inquirer.prompt({
|
|
153
141
|
type: `list`,
|
|
154
142
|
name: `type`,
|
|
155
143
|
message: `Connection type`,
|
|
156
|
-
choices:
|
|
157
|
-
|
|
158
|
-
name:
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
return hash.type === 'RFC' && ((commandArgs.ashost ? false : true) || force);
|
|
189
|
-
}
|
|
190
|
-
}, {
|
|
191
|
-
type: `input`,
|
|
192
|
-
name: `dest`,
|
|
193
|
-
message: `System ID`,
|
|
194
|
-
default: commandArgs.dest,
|
|
195
|
-
when: (hash) => {
|
|
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
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}, {
|
|
207
|
-
type: `input`,
|
|
208
|
-
name: `sysnr`,
|
|
209
|
-
message: `Instance number`,
|
|
210
|
-
default: commandArgs.sysnr,
|
|
211
|
-
when: (hash) => {
|
|
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`;
|
|
144
|
+
choices: utils_1.Context.getInstance().connections.map(o => {
|
|
145
|
+
return {
|
|
146
|
+
name: o.description,
|
|
147
|
+
value: o.name
|
|
148
|
+
};
|
|
149
|
+
})
|
|
150
|
+
})).type;
|
|
151
|
+
}
|
|
152
|
+
const connectionType = utils_1.Context.getInstance().connections.find(o => o.name === type);
|
|
153
|
+
if (!connectionType) {
|
|
154
|
+
throw new Error(`Invalid connection type "${type}"`);
|
|
155
|
+
}
|
|
156
|
+
if (connectionType.onConnectionData) {
|
|
157
|
+
yield connectionType.onConnectionData(force, commandArgs);
|
|
158
|
+
}
|
|
159
|
+
if (connectionType.loginData) {
|
|
160
|
+
commandArgs = Object.assign(Object.assign({}, commandArgs), (yield trm_commons_1.Inquirer.prompt([
|
|
161
|
+
{
|
|
162
|
+
type: `input`,
|
|
163
|
+
name: `client`,
|
|
164
|
+
message: `Logon Client`,
|
|
165
|
+
default: commandArgs.client,
|
|
166
|
+
when: (hash) => {
|
|
167
|
+
return (commandArgs.client ? false : true) || force;
|
|
168
|
+
},
|
|
169
|
+
validate: (val) => {
|
|
170
|
+
if (val && /^\d{3}$/.test(val)) {
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
return `Invalid input: expected length 3, only numbers allowed`;
|
|
175
|
+
}
|
|
220
176
|
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
return hash.type === 'RFC' && ((commandArgs.saprouter ? false : true) || force);
|
|
229
|
-
}
|
|
230
|
-
}, {
|
|
231
|
-
type: `input`,
|
|
232
|
-
name: `client`,
|
|
233
|
-
message: `Logon Client`,
|
|
234
|
-
default: commandArgs.client,
|
|
235
|
-
when: (hash) => {
|
|
236
|
-
return (commandArgs.client ? false : true) || force;
|
|
237
|
-
},
|
|
238
|
-
validate: (val) => {
|
|
239
|
-
if (val && /^\d{3}$/.test(val)) {
|
|
240
|
-
return true;
|
|
177
|
+
}, {
|
|
178
|
+
type: `input`,
|
|
179
|
+
name: `user`,
|
|
180
|
+
message: `Logon User`,
|
|
181
|
+
default: commandArgs.user,
|
|
182
|
+
when: (hash) => {
|
|
183
|
+
return (commandArgs.user ? false : true) || force;
|
|
241
184
|
}
|
|
242
|
-
|
|
243
|
-
|
|
185
|
+
}, {
|
|
186
|
+
type: `password`,
|
|
187
|
+
name: `passwd`,
|
|
188
|
+
message: `Logon Password`,
|
|
189
|
+
default: commandArgs.passwd,
|
|
190
|
+
when: (hash) => {
|
|
191
|
+
return (commandArgs.passwd ? false : true) || force;
|
|
244
192
|
}
|
|
193
|
+
}, {
|
|
194
|
+
type: `list`,
|
|
195
|
+
name: `lang`,
|
|
196
|
+
message: `Logon Language`,
|
|
197
|
+
default: commandArgs.lang || 'EN',
|
|
198
|
+
when: (hash) => {
|
|
199
|
+
return (commandArgs.lang ? false : true) || force;
|
|
200
|
+
},
|
|
201
|
+
validate: (input) => {
|
|
202
|
+
return languageList.includes(input.trim().toUpperCase());
|
|
203
|
+
},
|
|
204
|
+
choices: languageList
|
|
245
205
|
}
|
|
246
|
-
|
|
247
|
-
type: `input`,
|
|
248
|
-
name: `user`,
|
|
249
|
-
message: `Logon User`,
|
|
250
|
-
default: commandArgs.user,
|
|
251
|
-
when: (hash) => {
|
|
252
|
-
return (commandArgs.user ? false : true) || force;
|
|
253
|
-
}
|
|
254
|
-
}, {
|
|
255
|
-
type: `password`,
|
|
256
|
-
name: `passwd`,
|
|
257
|
-
message: `Logon Password`,
|
|
258
|
-
default: commandArgs.passwd,
|
|
259
|
-
when: (hash) => {
|
|
260
|
-
return (commandArgs.passwd ? false : true) || force;
|
|
261
|
-
}
|
|
262
|
-
}, {
|
|
263
|
-
type: `list`,
|
|
264
|
-
name: `lang`,
|
|
265
|
-
message: `Logon Language`,
|
|
266
|
-
default: commandArgs.lang || 'EN',
|
|
267
|
-
when: (hash) => {
|
|
268
|
-
return (commandArgs.lang ? false : true) || force;
|
|
269
|
-
},
|
|
270
|
-
validate: (input) => {
|
|
271
|
-
return languageList.includes(input.trim().toUpperCase());
|
|
272
|
-
},
|
|
273
|
-
choices: languageList
|
|
274
|
-
}]);
|
|
275
|
-
}
|
|
276
|
-
result.type = result.type || type;
|
|
277
|
-
result.user = result.user || commandArgs.user;
|
|
278
|
-
result.passwd = result.passwd || commandArgs.passwd;
|
|
279
|
-
result.lang = result.lang || commandArgs.lang;
|
|
280
|
-
result.user = result.user.toUpperCase();
|
|
281
|
-
result.lang = result.lang.toUpperCase();
|
|
282
|
-
if (result.type === utils_1.SystemConnectorType.RFC) {
|
|
283
|
-
result.ashost = result.ashost || commandArgs.ashost;
|
|
284
|
-
result.dest = result.dest || commandArgs.dest;
|
|
285
|
-
result.saprouter = result.saprouter || commandArgs.saprouter;
|
|
286
|
-
result.sysnr = result.sysnr || commandArgs.sysnr;
|
|
287
|
-
result.client = result.client || commandArgs.client;
|
|
288
|
-
result.noSystemAlias = commandArgs.noSystemAlias;
|
|
289
|
-
result.dest = result.dest.toUpperCase();
|
|
290
|
-
result.connection = (0, utils_1.getSystemConnector)(utils_1.SystemConnectorType.RFC, {
|
|
291
|
-
connection: {
|
|
292
|
-
dest: result.dest,
|
|
293
|
-
ashost: result.ashost,
|
|
294
|
-
sysnr: result.sysnr,
|
|
295
|
-
saprouter: result.saprouter
|
|
296
|
-
},
|
|
297
|
-
login: {
|
|
298
|
-
user: result.user,
|
|
299
|
-
passwd: result.passwd,
|
|
300
|
-
lang: result.lang,
|
|
301
|
-
client: result.client
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
else if (result.type === utils_1.SystemConnectorType.REST) {
|
|
306
|
-
result.endpoint = result.endpoint || commandArgs.endpoint;
|
|
307
|
-
result.forwardRfcDest = result.forwardRfcDest || commandArgs.forwardRfcDest;
|
|
308
|
-
result.client = result.client || commandArgs.client;
|
|
309
|
-
if (result.forwardRfcDest) {
|
|
310
|
-
result.forwardRfcDest = result.forwardRfcDest.toUpperCase();
|
|
206
|
+
])));
|
|
311
207
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
},
|
|
320
|
-
login: {
|
|
321
|
-
user: result.user,
|
|
322
|
-
passwd: result.passwd,
|
|
323
|
-
lang: result.lang,
|
|
324
|
-
client: result.client
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
else {
|
|
329
|
-
throw new Error(`Unknown connection type "${result.type}".`);
|
|
330
|
-
}
|
|
331
|
-
if (createAliasIfNotExist) {
|
|
332
|
-
yield systemAlias_1.SystemAlias.createIfNotExists(result);
|
|
208
|
+
if (connectionType.onAfterLoginData) {
|
|
209
|
+
yield connectionType.onAfterLoginData(force, commandArgs);
|
|
210
|
+
}
|
|
211
|
+
if (createAliasIfNotExist) {
|
|
212
|
+
yield systemAlias_1.SystemAlias.createIfNotExists(connectionType);
|
|
213
|
+
}
|
|
214
|
+
return connectionType;
|
|
333
215
|
}
|
|
334
|
-
return result;
|
|
335
216
|
});
|
|
336
217
|
}
|
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.settings = settings;
|
|
13
|
-
const
|
|
13
|
+
const utils_1 = require("../utils");
|
|
14
14
|
const trm_commons_1 = require("trm-commons");
|
|
15
15
|
function settings(commandArgs) {
|
|
16
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -22,9 +22,9 @@ function settings(commandArgs) {
|
|
|
22
22
|
}
|
|
23
23
|
const key = aSplit[0];
|
|
24
24
|
const value = aSplit[1];
|
|
25
|
-
|
|
25
|
+
utils_1.Context.getInstance().setSetting(key, value);
|
|
26
26
|
}
|
|
27
|
-
const settingsData =
|
|
27
|
+
const settingsData = utils_1.Context.getInstance().settings;
|
|
28
28
|
Object.keys(settingsData).forEach(k => {
|
|
29
29
|
trm_commons_1.Logger.log(`${k}: ${settingsData[k]}`);
|
|
30
30
|
});
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { SystemConnectorType } from "../utils";
|
|
2
1
|
import { SystemAliasData } from "./SystemAliasData";
|
|
3
|
-
import { ISystemConnector
|
|
4
|
-
import {
|
|
2
|
+
import { ISystemConnector } from "trm-core";
|
|
3
|
+
import { IConnect } from "trm-commons";
|
|
5
4
|
export declare class SystemAlias {
|
|
6
|
-
type:
|
|
7
|
-
private
|
|
8
|
-
|
|
9
|
-
constructor(type: SystemConnectorType, _connection: RFCConnection | RESTConnection, _login: Login);
|
|
5
|
+
type: string;
|
|
6
|
+
private _data;
|
|
7
|
+
constructor(type: string, _data: any);
|
|
10
8
|
getConnection(): ISystemConnector;
|
|
11
9
|
private static generateFile;
|
|
12
10
|
private static getSystemAliasFilePath;
|
|
13
11
|
static getAll(): SystemAliasData[];
|
|
14
12
|
static get(name: string): SystemAlias;
|
|
15
|
-
static create(name: string, type:
|
|
13
|
+
static create(name: string, type: string, data: any): SystemAlias;
|
|
16
14
|
static delete(name: string): void;
|
|
17
|
-
static
|
|
15
|
+
private static deepEqual;
|
|
16
|
+
static compare(a: SystemAlias, b: SystemAlias): boolean;
|
|
17
|
+
static createIfNotExists(connection: IConnect): Promise<void>;
|
|
18
18
|
}
|
|
@@ -53,16 +53,17 @@ const ini = __importStar(require("ini"));
|
|
|
53
53
|
const trm_commons_1 = require("trm-commons");
|
|
54
54
|
const SYSTEM_FILE_NAME = "systems.ini";
|
|
55
55
|
class SystemAlias {
|
|
56
|
-
constructor(type,
|
|
56
|
+
constructor(type, _data) {
|
|
57
57
|
this.type = type;
|
|
58
|
-
this.
|
|
59
|
-
this._login = _login;
|
|
58
|
+
this._data = _data;
|
|
60
59
|
}
|
|
61
60
|
getConnection() {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
61
|
+
const connection = utils_1.Context.getInstance().connections.find(o => o.name === this.type);
|
|
62
|
+
if (!connection) {
|
|
63
|
+
throw new Error(`Unknown connection type "${this.type}". Possible values are ${utils_1.Context.getInstance().connections.map(k => k.name).join(', ')}.`);
|
|
64
|
+
}
|
|
65
|
+
connection.setData(this._data);
|
|
66
|
+
return connection.getSystemConnector();
|
|
66
67
|
}
|
|
67
68
|
static generateFile(content, filePath) {
|
|
68
69
|
if (!filePath) {
|
|
@@ -70,31 +71,10 @@ class SystemAlias {
|
|
|
70
71
|
}
|
|
71
72
|
var oContent = {};
|
|
72
73
|
content.forEach(o => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
ashost: o.connection.ashost,
|
|
78
|
-
sysnr: o.connection.sysnr,
|
|
79
|
-
client: o.login.client,
|
|
80
|
-
user: o.login.user,
|
|
81
|
-
passwd: o.login.passwd,
|
|
82
|
-
lang: o.login.lang
|
|
83
|
-
};
|
|
84
|
-
if (o.connection.saprouter) {
|
|
85
|
-
oContent[o.alias].saprouter = o.connection.saprouter;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
else if (o.type === utils_1.SystemConnectorType.REST) {
|
|
89
|
-
oContent[o.alias] = {
|
|
90
|
-
type: o.type,
|
|
91
|
-
endpoint: o.connection.endpoint,
|
|
92
|
-
rfcdest: o.connection.rfcdest || 'NONE',
|
|
93
|
-
client: o.login.client,
|
|
94
|
-
user: o.login.user,
|
|
95
|
-
passwd: o.login.passwd,
|
|
96
|
-
lang: o.login.lang
|
|
97
|
-
};
|
|
74
|
+
const connection = utils_1.Context.getInstance().connections.find(k => k.name === o.type);
|
|
75
|
+
if (connection) {
|
|
76
|
+
oContent[o.alias] = o.data;
|
|
77
|
+
oContent[o.alias].type = o.type;
|
|
98
78
|
}
|
|
99
79
|
});
|
|
100
80
|
fs.writeFileSync(filePath, ini.encode(oContent), { encoding: 'utf8', flag: 'w' });
|
|
@@ -112,38 +92,16 @@ class SystemAlias {
|
|
|
112
92
|
const sIni = fs.readFileSync(filePath).toString();
|
|
113
93
|
const oIni = ini.decode(sIni);
|
|
114
94
|
Object.keys(oIni).forEach(sAlias => {
|
|
115
|
-
if (
|
|
116
|
-
|
|
117
|
-
alias: sAlias,
|
|
118
|
-
type: utils_1.SystemConnectorType.RFC,
|
|
119
|
-
connection: {
|
|
120
|
-
dest: oIni[sAlias].dest,
|
|
121
|
-
ashost: oIni[sAlias].ashost,
|
|
122
|
-
sysnr: oIni[sAlias].sysnr,
|
|
123
|
-
saprouter: oIni[sAlias].saprouter
|
|
124
|
-
},
|
|
125
|
-
login: {
|
|
126
|
-
client: oIni[sAlias].client,
|
|
127
|
-
user: oIni[sAlias].user,
|
|
128
|
-
passwd: oIni[sAlias].passwd,
|
|
129
|
-
lang: oIni[sAlias].lang
|
|
130
|
-
}
|
|
131
|
-
});
|
|
95
|
+
if (!oIni[sAlias].type) {
|
|
96
|
+
oIni[sAlias].type = 'RFC';
|
|
132
97
|
}
|
|
133
|
-
|
|
98
|
+
const connection = utils_1.Context.getInstance().connections.find(o => o.name === oIni[sAlias].type);
|
|
99
|
+
if (connection) {
|
|
100
|
+
connection.setData(oIni[sAlias]);
|
|
134
101
|
aAlias.push({
|
|
135
102
|
alias: sAlias,
|
|
136
|
-
type:
|
|
137
|
-
|
|
138
|
-
endpoint: oIni[sAlias].endpoint,
|
|
139
|
-
rfcdest: oIni[sAlias].rfcdest || 'NONE'
|
|
140
|
-
},
|
|
141
|
-
login: {
|
|
142
|
-
user: oIni[sAlias].user,
|
|
143
|
-
passwd: oIni[sAlias].passwd,
|
|
144
|
-
lang: oIni[sAlias].lang,
|
|
145
|
-
client: oIni[sAlias].client
|
|
146
|
-
}
|
|
103
|
+
type: oIni[sAlias].type,
|
|
104
|
+
data: connection.getData()
|
|
147
105
|
});
|
|
148
106
|
}
|
|
149
107
|
});
|
|
@@ -153,13 +111,13 @@ class SystemAlias {
|
|
|
153
111
|
const aAlias = this.getAll();
|
|
154
112
|
const alias = aAlias.find(o => o.alias.trim().toUpperCase() === name.trim().toUpperCase());
|
|
155
113
|
if (alias) {
|
|
156
|
-
return new SystemAlias(alias.type, alias
|
|
114
|
+
return new SystemAlias(alias.type, alias);
|
|
157
115
|
}
|
|
158
116
|
else {
|
|
159
117
|
throw new Error(`System alias "${name}" not found.`);
|
|
160
118
|
}
|
|
161
119
|
}
|
|
162
|
-
static create(name, type,
|
|
120
|
+
static create(name, type, data) {
|
|
163
121
|
if (!name) {
|
|
164
122
|
throw new Error(`Invalid alias name.`);
|
|
165
123
|
}
|
|
@@ -172,55 +130,62 @@ class SystemAlias {
|
|
|
172
130
|
aAlias.push({
|
|
173
131
|
alias: name,
|
|
174
132
|
type,
|
|
175
|
-
|
|
176
|
-
login
|
|
133
|
+
data
|
|
177
134
|
});
|
|
178
135
|
this.generateFile(aAlias);
|
|
179
136
|
}
|
|
180
|
-
return new SystemAlias(type,
|
|
137
|
+
return new SystemAlias(type, data);
|
|
181
138
|
}
|
|
182
139
|
static delete(name) {
|
|
183
140
|
var aAlias = this.getAll();
|
|
184
141
|
aAlias = aAlias.filter(o => o.alias.trim().toUpperCase() !== name.trim().toUpperCase());
|
|
185
142
|
this.generateFile(aAlias);
|
|
186
143
|
}
|
|
187
|
-
static
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
if (
|
|
192
|
-
|
|
193
|
-
if (o.type === utils_1.SystemConnectorType.RFC || !o.type) {
|
|
194
|
-
const rfcConn = o.connection;
|
|
195
|
-
if (rfcConn.dest === connArgs.dest &&
|
|
196
|
-
rfcConn.ashost === connArgs.ashost &&
|
|
197
|
-
rfcConn.sysnr === connArgs.sysnr &&
|
|
198
|
-
rfcConn.saprouter === connArgs.saprouter &&
|
|
199
|
-
o.login.client === connArgs.client &&
|
|
200
|
-
o.login.lang === connArgs.lang &&
|
|
201
|
-
o.login.user === connArgs.user &&
|
|
202
|
-
o.login.passwd === connArgs.passwd) {
|
|
203
|
-
return o;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
});
|
|
144
|
+
static deepEqual(a, b) {
|
|
145
|
+
if (a === b)
|
|
146
|
+
return true;
|
|
147
|
+
if (a && b && typeof a === "object" && typeof b === "object") {
|
|
148
|
+
if (a instanceof Date && b instanceof Date) {
|
|
149
|
+
return a.getTime() === b.getTime();
|
|
207
150
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
151
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
152
|
+
if (a.length !== b.length)
|
|
153
|
+
return false;
|
|
154
|
+
for (let i = 0; i < a.length; i++) {
|
|
155
|
+
if (!this.deepEqual(a[i], b[i]))
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
if (a.constructor !== b.constructor)
|
|
161
|
+
return false;
|
|
162
|
+
const keysA = Object.keys(a);
|
|
163
|
+
const keysB = Object.keys(b);
|
|
164
|
+
if (keysA.length !== keysB.length)
|
|
165
|
+
return false;
|
|
166
|
+
for (const key of keysA) {
|
|
167
|
+
if (!Object.prototype.hasOwnProperty.call(b, key))
|
|
168
|
+
return false;
|
|
169
|
+
if (!this.deepEqual(a[key], b[key]))
|
|
170
|
+
return false;
|
|
222
171
|
}
|
|
223
|
-
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
static compare(a, b) {
|
|
177
|
+
if (a.type === b.type) {
|
|
178
|
+
return this.deepEqual(a._data, b._data);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
static createIfNotExists(connection) {
|
|
185
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
186
|
+
const aAlias = this.getAll();
|
|
187
|
+
const parsedData = connection.getData();
|
|
188
|
+
if (!aAlias.find(o => this.deepEqual(o, parsedData))) {
|
|
224
189
|
const aliasName = (yield trm_commons_1.Inquirer.prompt([{
|
|
225
190
|
name: 'create',
|
|
226
191
|
message: 'Create new alias for connection?',
|
|
@@ -235,7 +200,7 @@ class SystemAlias {
|
|
|
235
200
|
}
|
|
236
201
|
}])).alias;
|
|
237
202
|
if (aliasName) {
|
|
238
|
-
this.create(aliasName,
|
|
203
|
+
this.create(aliasName, connection.name, parsedData);
|
|
239
204
|
}
|
|
240
205
|
}
|
|
241
206
|
});
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { Login, RESTConnection, RFCConnection } from "trm-core";
|
|
2
|
-
import { SystemConnectorType } from "../utils";
|
|
3
1
|
export type SystemAliasData = {
|
|
4
2
|
alias: string;
|
|
5
|
-
type:
|
|
6
|
-
|
|
7
|
-
login: Login;
|
|
3
|
+
type: string;
|
|
4
|
+
data: any;
|
|
8
5
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SettingsData } from "./";
|
|
2
|
+
import { IConnect } from "trm-commons";
|
|
3
|
+
export declare class Context {
|
|
4
|
+
private static _instance;
|
|
5
|
+
settings: SettingsData;
|
|
6
|
+
connections: IConnect[];
|
|
7
|
+
constructor();
|
|
8
|
+
load(): Promise<void>;
|
|
9
|
+
setSetting(key: string, value: string): void;
|
|
10
|
+
private getSettingsFilePath;
|
|
11
|
+
private getSettings;
|
|
12
|
+
private generateSettingsFile;
|
|
13
|
+
static getInstance(): Context;
|
|
14
|
+
}
|