@microsoft/teamsfx 0.4.1-alpha.e2f93320.0 → 0.4.1-alpha.fcc60ca0.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 +2 -0
- package/dist/index.esm2017.js +19 -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 +19 -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) {
|
|
@@ -720,6 +727,8 @@ var TeamsUserCredential = /** @class */ (function () {
|
|
|
720
727
|
/**
|
|
721
728
|
* Get access token from credential.
|
|
722
729
|
*
|
|
730
|
+
* Important: Access tokens are stored in sessionStorage, read more here: https://aka.ms/teamsfx-session-storage-notice
|
|
731
|
+
*
|
|
723
732
|
* @example
|
|
724
733
|
* ```typescript
|
|
725
734
|
* await credential.getToken([]) // Get SSO token using empty string array
|
|
@@ -849,6 +858,7 @@ var TeamsUserCredential = /** @class */ (function () {
|
|
|
849
858
|
return [4 /*yield*/, this.getAccessTokenCacheKey(scopesStr)];
|
|
850
859
|
case 5:
|
|
851
860
|
key = _c.sent();
|
|
861
|
+
// Important: tokens are stored in sessionStorage, read more here: https://aka.ms/teamsfx-session-storage-notice
|
|
852
862
|
this.setTokenCache(key, {
|
|
853
863
|
token: tokenResult.access_token,
|
|
854
864
|
expiresOnTimestamp: tokenResult.expires_on,
|
|
@@ -1256,201 +1266,31 @@ function createMicrosoftGraphClient(credential, scopes) {
|
|
|
1256
1266
|
return graphClient;
|
|
1257
1267
|
}
|
|
1258
1268
|
|
|
1259
|
-
// Copyright (c) Microsoft Corporation.
|
|
1260
1269
|
/**
|
|
1261
|
-
*
|
|
1270
|
+
* Generate connection configuration consumed by tedious.
|
|
1262
1271
|
* @remarks
|
|
1263
1272
|
* Only works in in server side.
|
|
1264
|
-
*
|
|
1265
1273
|
* @beta
|
|
1266
|
-
*
|
|
1267
1274
|
*/
|
|
1268
1275
|
var DefaultTediousConnectionConfiguration = /** @class */ (function () {
|
|
1269
1276
|
function DefaultTediousConnectionConfiguration() {
|
|
1270
|
-
|
|
1271
|
-
* MSSQL default scope
|
|
1272
|
-
* https://docs.microsoft.com/en-us/azure/app-service/app-service-web-tutorial-connect-msi
|
|
1273
|
-
*/
|
|
1274
|
-
this.defaultSQLScope = "https://database.windows.net/";
|
|
1277
|
+
throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "DefaultTediousConnectionConfiguration"), ErrorCode.RuntimeNotSupported);
|
|
1275
1278
|
}
|
|
1276
1279
|
/**
|
|
1277
1280
|
* Generate connection configuration consumed by tedious.
|
|
1278
|
-
*
|
|
1279
|
-
*
|
|
1280
|
-
*
|
|
1281
|
-
* @throws {@link ErrorCode|InvalidConfiguration} when SQL config resource configuration is invalid.
|
|
1282
|
-
* @throws {@link ErrorCode|InternalError} when get user MSI token failed or MSI token is invalid.
|
|
1283
|
-
* @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
|
|
1284
|
-
*
|
|
1281
|
+
* @remarks
|
|
1282
|
+
* Only works in in server side.
|
|
1285
1283
|
* @beta
|
|
1286
1284
|
*/
|
|
1287
1285
|
DefaultTediousConnectionConfiguration.prototype.getConfig = function () {
|
|
1288
1286
|
return __awaiter(this, void 0, void 0, function () {
|
|
1289
|
-
var configuration, errMsg, configWithUPS, configWithToken, error_1;
|
|
1290
|
-
return __generator(this, function (_a) {
|
|
1291
|
-
switch (_a.label) {
|
|
1292
|
-
case 0:
|
|
1293
|
-
internalLogger.info("Get SQL configuration");
|
|
1294
|
-
configuration = getResourceConfiguration(ResourceType.SQL);
|
|
1295
|
-
if (!configuration) {
|
|
1296
|
-
errMsg = "SQL resource configuration not exist";
|
|
1297
|
-
internalLogger.error(errMsg);
|
|
1298
|
-
throw new ErrorWithCode(errMsg, ErrorCode.InvalidConfiguration);
|
|
1299
|
-
}
|
|
1300
|
-
try {
|
|
1301
|
-
this.isSQLConfigurationValid(configuration);
|
|
1302
|
-
}
|
|
1303
|
-
catch (err) {
|
|
1304
|
-
throw err;
|
|
1305
|
-
}
|
|
1306
|
-
if (!this.isMsiAuthentication()) {
|
|
1307
|
-
configWithUPS = this.generateDefaultConfig(configuration);
|
|
1308
|
-
internalLogger.verbose("SQL configuration with username and password generated");
|
|
1309
|
-
return [2 /*return*/, configWithUPS];
|
|
1310
|
-
}
|
|
1311
|
-
_a.label = 1;
|
|
1312
|
-
case 1:
|
|
1313
|
-
_a.trys.push([1, 3, , 4]);
|
|
1314
|
-
return [4 /*yield*/, this.generateTokenConfig(configuration)];
|
|
1315
|
-
case 2:
|
|
1316
|
-
configWithToken = _a.sent();
|
|
1317
|
-
internalLogger.verbose("SQL configuration with MSI token generated");
|
|
1318
|
-
return [2 /*return*/, configWithToken];
|
|
1319
|
-
case 3:
|
|
1320
|
-
error_1 = _a.sent();
|
|
1321
|
-
throw error_1;
|
|
1322
|
-
case 4: return [2 /*return*/];
|
|
1323
|
-
}
|
|
1324
|
-
});
|
|
1325
|
-
});
|
|
1326
|
-
};
|
|
1327
|
-
/**
|
|
1328
|
-
* Check SQL use MSI identity or username and password.
|
|
1329
|
-
*
|
|
1330
|
-
* @returns false - login with SQL MSI identity, true - login with username and password.
|
|
1331
|
-
* @internal
|
|
1332
|
-
*/
|
|
1333
|
-
DefaultTediousConnectionConfiguration.prototype.isMsiAuthentication = function () {
|
|
1334
|
-
internalLogger.verbose("Check connection config using MSI access token or username and password");
|
|
1335
|
-
var configuration = getResourceConfiguration(ResourceType.SQL);
|
|
1336
|
-
if ((configuration === null || configuration === void 0 ? void 0 : configuration.sqlUsername) != null && (configuration === null || configuration === void 0 ? void 0 : configuration.sqlPassword) != null) {
|
|
1337
|
-
internalLogger.verbose("Login with username and password");
|
|
1338
|
-
return false;
|
|
1339
|
-
}
|
|
1340
|
-
internalLogger.verbose("Login with MSI identity");
|
|
1341
|
-
return true;
|
|
1342
|
-
};
|
|
1343
|
-
/**
|
|
1344
|
-
* check configuration is an available configurations.
|
|
1345
|
-
* @param { SqlConfiguration } sqlConfig
|
|
1346
|
-
*
|
|
1347
|
-
* @returns true - SQL configuration has a valid SQL endpoints, SQL username with password or identity ID.
|
|
1348
|
-
* false - configuration is not valid.
|
|
1349
|
-
* @internal
|
|
1350
|
-
*/
|
|
1351
|
-
DefaultTediousConnectionConfiguration.prototype.isSQLConfigurationValid = function (sqlConfig) {
|
|
1352
|
-
internalLogger.verbose("Check SQL configuration if valid");
|
|
1353
|
-
if (!sqlConfig.sqlServerEndpoint) {
|
|
1354
|
-
internalLogger.error("SQL configuration is not valid without SQL server endpoint exist");
|
|
1355
|
-
throw new ErrorWithCode("SQL configuration error without SQL server endpoint exist", ErrorCode.InvalidConfiguration);
|
|
1356
|
-
}
|
|
1357
|
-
if (!(sqlConfig.sqlUsername && sqlConfig.sqlPassword) && !sqlConfig.sqlIdentityId) {
|
|
1358
|
-
var errMsg = "SQL configuration is not valid without " + (sqlConfig.sqlIdentityId ? "" : "identity id ") + " " + (sqlConfig.sqlUsername ? "" : "SQL username ") + " " + (sqlConfig.sqlPassword ? "" : "SQL password") + " exist";
|
|
1359
|
-
internalLogger.error(errMsg);
|
|
1360
|
-
throw new ErrorWithCode(errMsg, ErrorCode.InvalidConfiguration);
|
|
1361
|
-
}
|
|
1362
|
-
internalLogger.verbose("SQL configuration is valid");
|
|
1363
|
-
};
|
|
1364
|
-
/**
|
|
1365
|
-
* Generate tedious connection configuration with default authentication type.
|
|
1366
|
-
*
|
|
1367
|
-
* @param { SqlConfiguration } SQL configuration with username and password.
|
|
1368
|
-
*
|
|
1369
|
-
* @returns Tedious connection configuration with username and password.
|
|
1370
|
-
* @internal
|
|
1371
|
-
*/
|
|
1372
|
-
DefaultTediousConnectionConfiguration.prototype.generateDefaultConfig = function (sqlConfig) {
|
|
1373
|
-
internalLogger.verbose("SQL server " + sqlConfig.sqlServerEndpoint + ", user name " + sqlConfig.sqlUsername + ", database name " + sqlConfig.sqlDatabaseName);
|
|
1374
|
-
var config = {
|
|
1375
|
-
server: sqlConfig.sqlServerEndpoint,
|
|
1376
|
-
authentication: {
|
|
1377
|
-
type: TediousAuthenticationType.default,
|
|
1378
|
-
options: {
|
|
1379
|
-
userName: sqlConfig.sqlUsername,
|
|
1380
|
-
password: sqlConfig.sqlPassword,
|
|
1381
|
-
},
|
|
1382
|
-
},
|
|
1383
|
-
options: {
|
|
1384
|
-
database: sqlConfig.sqlDatabaseName,
|
|
1385
|
-
encrypt: true,
|
|
1386
|
-
},
|
|
1387
|
-
};
|
|
1388
|
-
return config;
|
|
1389
|
-
};
|
|
1390
|
-
/**
|
|
1391
|
-
* Generate tedious connection configuration with azure-active-directory-access-token authentication type.
|
|
1392
|
-
*
|
|
1393
|
-
* @param { SqlConfiguration } SQL configuration with AAD access token.
|
|
1394
|
-
*
|
|
1395
|
-
* @returns Tedious connection configuration with access token.
|
|
1396
|
-
* @internal
|
|
1397
|
-
*/
|
|
1398
|
-
DefaultTediousConnectionConfiguration.prototype.generateTokenConfig = function (sqlConfig) {
|
|
1399
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1400
|
-
var token, credential, errMsg, config;
|
|
1401
1287
|
return __generator(this, function (_a) {
|
|
1402
|
-
|
|
1403
|
-
case 0:
|
|
1404
|
-
internalLogger.verbose("Generate tedious config with MSI token");
|
|
1405
|
-
_a.label = 1;
|
|
1406
|
-
case 1:
|
|
1407
|
-
_a.trys.push([1, 3, , 4]);
|
|
1408
|
-
credential = new ManagedIdentityCredential(sqlConfig.sqlIdentityId);
|
|
1409
|
-
return [4 /*yield*/, credential.getToken(this.defaultSQLScope)];
|
|
1410
|
-
case 2:
|
|
1411
|
-
token = _a.sent();
|
|
1412
|
-
return [3 /*break*/, 4];
|
|
1413
|
-
case 3:
|
|
1414
|
-
_a.sent();
|
|
1415
|
-
errMsg = "Get user MSI token failed";
|
|
1416
|
-
internalLogger.error(errMsg);
|
|
1417
|
-
throw new ErrorWithCode(errMsg, ErrorCode.InternalError);
|
|
1418
|
-
case 4:
|
|
1419
|
-
if (token) {
|
|
1420
|
-
config = {
|
|
1421
|
-
server: sqlConfig.sqlServerEndpoint,
|
|
1422
|
-
authentication: {
|
|
1423
|
-
type: TediousAuthenticationType.MSI,
|
|
1424
|
-
options: {
|
|
1425
|
-
token: token.token,
|
|
1426
|
-
},
|
|
1427
|
-
},
|
|
1428
|
-
options: {
|
|
1429
|
-
database: sqlConfig.sqlDatabaseName,
|
|
1430
|
-
encrypt: true,
|
|
1431
|
-
},
|
|
1432
|
-
};
|
|
1433
|
-
internalLogger.verbose("Generate token configuration success, server endpoint is " + sqlConfig.sqlServerEndpoint + ", database name is " + sqlConfig.sqlDatabaseName);
|
|
1434
|
-
return [2 /*return*/, config];
|
|
1435
|
-
}
|
|
1436
|
-
internalLogger.error("Generate token configuration, server endpoint is " + sqlConfig.sqlServerEndpoint + ", MSI token is not valid");
|
|
1437
|
-
throw new ErrorWithCode("MSI token is not valid", ErrorCode.InternalError);
|
|
1438
|
-
}
|
|
1288
|
+
throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "DefaultTediousConnectionConfiguration"), ErrorCode.RuntimeNotSupported);
|
|
1439
1289
|
});
|
|
1440
1290
|
});
|
|
1441
1291
|
};
|
|
1442
1292
|
return DefaultTediousConnectionConfiguration;
|
|
1443
|
-
}());
|
|
1444
|
-
/**
|
|
1445
|
-
* tedious connection config authentication type.
|
|
1446
|
-
* https://tediousjs.github.io/tedious/api-connection.html
|
|
1447
|
-
* @internal
|
|
1448
|
-
*/
|
|
1449
|
-
var TediousAuthenticationType;
|
|
1450
|
-
(function (TediousAuthenticationType) {
|
|
1451
|
-
TediousAuthenticationType["default"] = "default";
|
|
1452
|
-
TediousAuthenticationType["MSI"] = "azure-active-directory-access-token";
|
|
1453
|
-
})(TediousAuthenticationType || (TediousAuthenticationType = {}));
|
|
1293
|
+
}());
|
|
1454
1294
|
|
|
1455
1295
|
// Copyright (c) Microsoft Corporation.
|
|
1456
1296
|
/**
|