@microsoft/teamsfx 0.4.1-alpha.e5227bb6.0 → 0.4.1-alpha.e71f8e6a.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/dist/index.esm2017.js +16 -158
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +10 -2
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +16 -179
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +10 -2
- package/dist/index.node.cjs.js.map +1 -1
- package/package.json +2 -3
package/dist/index.esm5.js
CHANGED
|
@@ -3,7 +3,6 @@ import jwt_decode from 'jwt-decode';
|
|
|
3
3
|
import * as microsoftTeams from '@microsoft/teams-js';
|
|
4
4
|
import axios from 'axios';
|
|
5
5
|
import { Client } from '@microsoft/microsoft-graph-client';
|
|
6
|
-
import { ManagedIdentityCredential } from '@azure/identity';
|
|
7
6
|
|
|
8
7
|
// Copyright (c) Microsoft Corporation.
|
|
9
8
|
/**
|
|
@@ -176,7 +175,7 @@ function getLogLevel() {
|
|
|
176
175
|
return internalLogger.level;
|
|
177
176
|
}
|
|
178
177
|
var InternalLogger = /** @class */ (function () {
|
|
179
|
-
function InternalLogger() {
|
|
178
|
+
function InternalLogger(name, logLevel) {
|
|
180
179
|
this.level = undefined;
|
|
181
180
|
this.defaultLogger = {
|
|
182
181
|
verbose: console.debug,
|
|
@@ -184,6 +183,8 @@ var InternalLogger = /** @class */ (function () {
|
|
|
184
183
|
warn: console.warn,
|
|
185
184
|
error: console.error,
|
|
186
185
|
};
|
|
186
|
+
this.name = name;
|
|
187
|
+
this.level = logLevel;
|
|
187
188
|
}
|
|
188
189
|
InternalLogger.prototype.error = function (message) {
|
|
189
190
|
this.log(LogLevel.Error, function (x) { return x.error; }, message);
|
|
@@ -202,7 +203,13 @@ var InternalLogger = /** @class */ (function () {
|
|
|
202
203
|
return;
|
|
203
204
|
}
|
|
204
205
|
var timestamp = new Date().toUTCString();
|
|
205
|
-
var logHeader
|
|
206
|
+
var logHeader;
|
|
207
|
+
if (this.name) {
|
|
208
|
+
logHeader = "[" + timestamp + "] : @microsoft/teamsfx - " + this.name + " : " + LogLevel[logLevel] + " - ";
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
logHeader = "[" + timestamp + "] : @microsoft/teamsfx : " + LogLevel[logLevel] + " - ";
|
|
212
|
+
}
|
|
206
213
|
var logMessage = "" + logHeader + message;
|
|
207
214
|
if (this.level !== undefined && this.level <= logLevel) {
|
|
208
215
|
if (this.customLogger) {
|
|
@@ -1259,201 +1266,31 @@ function createMicrosoftGraphClient(credential, scopes) {
|
|
|
1259
1266
|
return graphClient;
|
|
1260
1267
|
}
|
|
1261
1268
|
|
|
1262
|
-
// Copyright (c) Microsoft Corporation.
|
|
1263
1269
|
/**
|
|
1264
|
-
*
|
|
1270
|
+
* Generate connection configuration consumed by tedious.
|
|
1265
1271
|
* @remarks
|
|
1266
1272
|
* Only works in in server side.
|
|
1267
|
-
*
|
|
1268
1273
|
* @beta
|
|
1269
|
-
*
|
|
1270
1274
|
*/
|
|
1271
1275
|
var DefaultTediousConnectionConfiguration = /** @class */ (function () {
|
|
1272
1276
|
function DefaultTediousConnectionConfiguration() {
|
|
1273
|
-
|
|
1274
|
-
* MSSQL default scope
|
|
1275
|
-
* https://docs.microsoft.com/en-us/azure/app-service/app-service-web-tutorial-connect-msi
|
|
1276
|
-
*/
|
|
1277
|
-
this.defaultSQLScope = "https://database.windows.net/";
|
|
1277
|
+
throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "DefaultTediousConnectionConfiguration"), ErrorCode.RuntimeNotSupported);
|
|
1278
1278
|
}
|
|
1279
1279
|
/**
|
|
1280
1280
|
* Generate connection configuration consumed by tedious.
|
|
1281
|
-
*
|
|
1282
|
-
*
|
|
1283
|
-
*
|
|
1284
|
-
* @throws {@link ErrorCode|InvalidConfiguration} when SQL config resource configuration is invalid.
|
|
1285
|
-
* @throws {@link ErrorCode|InternalError} when get user MSI token failed or MSI token is invalid.
|
|
1286
|
-
* @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
|
|
1287
|
-
*
|
|
1281
|
+
* @remarks
|
|
1282
|
+
* Only works in in server side.
|
|
1288
1283
|
* @beta
|
|
1289
1284
|
*/
|
|
1290
1285
|
DefaultTediousConnectionConfiguration.prototype.getConfig = function () {
|
|
1291
1286
|
return __awaiter(this, void 0, void 0, function () {
|
|
1292
|
-
var configuration, errMsg, configWithUPS, configWithToken, error_1;
|
|
1293
1287
|
return __generator(this, function (_a) {
|
|
1294
|
-
|
|
1295
|
-
case 0:
|
|
1296
|
-
internalLogger.info("Get SQL configuration");
|
|
1297
|
-
configuration = getResourceConfiguration(ResourceType.SQL);
|
|
1298
|
-
if (!configuration) {
|
|
1299
|
-
errMsg = "SQL resource configuration not exist";
|
|
1300
|
-
internalLogger.error(errMsg);
|
|
1301
|
-
throw new ErrorWithCode(errMsg, ErrorCode.InvalidConfiguration);
|
|
1302
|
-
}
|
|
1303
|
-
try {
|
|
1304
|
-
this.isSQLConfigurationValid(configuration);
|
|
1305
|
-
}
|
|
1306
|
-
catch (err) {
|
|
1307
|
-
throw err;
|
|
1308
|
-
}
|
|
1309
|
-
if (!this.isMsiAuthentication()) {
|
|
1310
|
-
configWithUPS = this.generateDefaultConfig(configuration);
|
|
1311
|
-
internalLogger.verbose("SQL configuration with username and password generated");
|
|
1312
|
-
return [2 /*return*/, configWithUPS];
|
|
1313
|
-
}
|
|
1314
|
-
_a.label = 1;
|
|
1315
|
-
case 1:
|
|
1316
|
-
_a.trys.push([1, 3, , 4]);
|
|
1317
|
-
return [4 /*yield*/, this.generateTokenConfig(configuration)];
|
|
1318
|
-
case 2:
|
|
1319
|
-
configWithToken = _a.sent();
|
|
1320
|
-
internalLogger.verbose("SQL configuration with MSI token generated");
|
|
1321
|
-
return [2 /*return*/, configWithToken];
|
|
1322
|
-
case 3:
|
|
1323
|
-
error_1 = _a.sent();
|
|
1324
|
-
throw error_1;
|
|
1325
|
-
case 4: return [2 /*return*/];
|
|
1326
|
-
}
|
|
1327
|
-
});
|
|
1328
|
-
});
|
|
1329
|
-
};
|
|
1330
|
-
/**
|
|
1331
|
-
* Check SQL use MSI identity or username and password.
|
|
1332
|
-
*
|
|
1333
|
-
* @returns false - login with SQL MSI identity, true - login with username and password.
|
|
1334
|
-
* @internal
|
|
1335
|
-
*/
|
|
1336
|
-
DefaultTediousConnectionConfiguration.prototype.isMsiAuthentication = function () {
|
|
1337
|
-
internalLogger.verbose("Check connection config using MSI access token or username and password");
|
|
1338
|
-
var configuration = getResourceConfiguration(ResourceType.SQL);
|
|
1339
|
-
if ((configuration === null || configuration === void 0 ? void 0 : configuration.sqlUsername) != null && (configuration === null || configuration === void 0 ? void 0 : configuration.sqlPassword) != null) {
|
|
1340
|
-
internalLogger.verbose("Login with username and password");
|
|
1341
|
-
return false;
|
|
1342
|
-
}
|
|
1343
|
-
internalLogger.verbose("Login with MSI identity");
|
|
1344
|
-
return true;
|
|
1345
|
-
};
|
|
1346
|
-
/**
|
|
1347
|
-
* check configuration is an available configurations.
|
|
1348
|
-
* @param { SqlConfiguration } sqlConfig
|
|
1349
|
-
*
|
|
1350
|
-
* @returns true - SQL configuration has a valid SQL endpoints, SQL username with password or identity ID.
|
|
1351
|
-
* false - configuration is not valid.
|
|
1352
|
-
* @internal
|
|
1353
|
-
*/
|
|
1354
|
-
DefaultTediousConnectionConfiguration.prototype.isSQLConfigurationValid = function (sqlConfig) {
|
|
1355
|
-
internalLogger.verbose("Check SQL configuration if valid");
|
|
1356
|
-
if (!sqlConfig.sqlServerEndpoint) {
|
|
1357
|
-
internalLogger.error("SQL configuration is not valid without SQL server endpoint exist");
|
|
1358
|
-
throw new ErrorWithCode("SQL configuration error without SQL server endpoint exist", ErrorCode.InvalidConfiguration);
|
|
1359
|
-
}
|
|
1360
|
-
if (!(sqlConfig.sqlUsername && sqlConfig.sqlPassword) && !sqlConfig.sqlIdentityId) {
|
|
1361
|
-
var errMsg = "SQL configuration is not valid without " + (sqlConfig.sqlIdentityId ? "" : "identity id ") + " " + (sqlConfig.sqlUsername ? "" : "SQL username ") + " " + (sqlConfig.sqlPassword ? "" : "SQL password") + " exist";
|
|
1362
|
-
internalLogger.error(errMsg);
|
|
1363
|
-
throw new ErrorWithCode(errMsg, ErrorCode.InvalidConfiguration);
|
|
1364
|
-
}
|
|
1365
|
-
internalLogger.verbose("SQL configuration is valid");
|
|
1366
|
-
};
|
|
1367
|
-
/**
|
|
1368
|
-
* Generate tedious connection configuration with default authentication type.
|
|
1369
|
-
*
|
|
1370
|
-
* @param { SqlConfiguration } SQL configuration with username and password.
|
|
1371
|
-
*
|
|
1372
|
-
* @returns Tedious connection configuration with username and password.
|
|
1373
|
-
* @internal
|
|
1374
|
-
*/
|
|
1375
|
-
DefaultTediousConnectionConfiguration.prototype.generateDefaultConfig = function (sqlConfig) {
|
|
1376
|
-
internalLogger.verbose("SQL server " + sqlConfig.sqlServerEndpoint + ", user name " + sqlConfig.sqlUsername + ", database name " + sqlConfig.sqlDatabaseName);
|
|
1377
|
-
var config = {
|
|
1378
|
-
server: sqlConfig.sqlServerEndpoint,
|
|
1379
|
-
authentication: {
|
|
1380
|
-
type: TediousAuthenticationType.default,
|
|
1381
|
-
options: {
|
|
1382
|
-
userName: sqlConfig.sqlUsername,
|
|
1383
|
-
password: sqlConfig.sqlPassword,
|
|
1384
|
-
},
|
|
1385
|
-
},
|
|
1386
|
-
options: {
|
|
1387
|
-
database: sqlConfig.sqlDatabaseName,
|
|
1388
|
-
encrypt: true,
|
|
1389
|
-
},
|
|
1390
|
-
};
|
|
1391
|
-
return config;
|
|
1392
|
-
};
|
|
1393
|
-
/**
|
|
1394
|
-
* Generate tedious connection configuration with azure-active-directory-access-token authentication type.
|
|
1395
|
-
*
|
|
1396
|
-
* @param { SqlConfiguration } SQL configuration with AAD access token.
|
|
1397
|
-
*
|
|
1398
|
-
* @returns Tedious connection configuration with access token.
|
|
1399
|
-
* @internal
|
|
1400
|
-
*/
|
|
1401
|
-
DefaultTediousConnectionConfiguration.prototype.generateTokenConfig = function (sqlConfig) {
|
|
1402
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1403
|
-
var token, credential, errMsg, config;
|
|
1404
|
-
return __generator(this, function (_a) {
|
|
1405
|
-
switch (_a.label) {
|
|
1406
|
-
case 0:
|
|
1407
|
-
internalLogger.verbose("Generate tedious config with MSI token");
|
|
1408
|
-
_a.label = 1;
|
|
1409
|
-
case 1:
|
|
1410
|
-
_a.trys.push([1, 3, , 4]);
|
|
1411
|
-
credential = new ManagedIdentityCredential(sqlConfig.sqlIdentityId);
|
|
1412
|
-
return [4 /*yield*/, credential.getToken(this.defaultSQLScope)];
|
|
1413
|
-
case 2:
|
|
1414
|
-
token = _a.sent();
|
|
1415
|
-
return [3 /*break*/, 4];
|
|
1416
|
-
case 3:
|
|
1417
|
-
_a.sent();
|
|
1418
|
-
errMsg = "Get user MSI token failed";
|
|
1419
|
-
internalLogger.error(errMsg);
|
|
1420
|
-
throw new ErrorWithCode(errMsg, ErrorCode.InternalError);
|
|
1421
|
-
case 4:
|
|
1422
|
-
if (token) {
|
|
1423
|
-
config = {
|
|
1424
|
-
server: sqlConfig.sqlServerEndpoint,
|
|
1425
|
-
authentication: {
|
|
1426
|
-
type: TediousAuthenticationType.MSI,
|
|
1427
|
-
options: {
|
|
1428
|
-
token: token.token,
|
|
1429
|
-
},
|
|
1430
|
-
},
|
|
1431
|
-
options: {
|
|
1432
|
-
database: sqlConfig.sqlDatabaseName,
|
|
1433
|
-
encrypt: true,
|
|
1434
|
-
},
|
|
1435
|
-
};
|
|
1436
|
-
internalLogger.verbose("Generate token configuration success, server endpoint is " + sqlConfig.sqlServerEndpoint + ", database name is " + sqlConfig.sqlDatabaseName);
|
|
1437
|
-
return [2 /*return*/, config];
|
|
1438
|
-
}
|
|
1439
|
-
internalLogger.error("Generate token configuration, server endpoint is " + sqlConfig.sqlServerEndpoint + ", MSI token is not valid");
|
|
1440
|
-
throw new ErrorWithCode("MSI token is not valid", ErrorCode.InternalError);
|
|
1441
|
-
}
|
|
1288
|
+
throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "DefaultTediousConnectionConfiguration"), ErrorCode.RuntimeNotSupported);
|
|
1442
1289
|
});
|
|
1443
1290
|
});
|
|
1444
1291
|
};
|
|
1445
1292
|
return DefaultTediousConnectionConfiguration;
|
|
1446
|
-
}());
|
|
1447
|
-
/**
|
|
1448
|
-
* tedious connection config authentication type.
|
|
1449
|
-
* https://tediousjs.github.io/tedious/api-connection.html
|
|
1450
|
-
* @internal
|
|
1451
|
-
*/
|
|
1452
|
-
var TediousAuthenticationType;
|
|
1453
|
-
(function (TediousAuthenticationType) {
|
|
1454
|
-
TediousAuthenticationType["default"] = "default";
|
|
1455
|
-
TediousAuthenticationType["MSI"] = "azure-active-directory-access-token";
|
|
1456
|
-
})(TediousAuthenticationType || (TediousAuthenticationType = {}));
|
|
1293
|
+
}());
|
|
1457
1294
|
|
|
1458
1295
|
// Copyright (c) Microsoft Corporation.
|
|
1459
1296
|
/**
|