@microsoft/teamsfx 0.6.3-alpha.ffd3f8bc7.0 → 0.7.0-beta.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.md +28 -0
- package/LICENSE +21 -21
- package/NOTICE.txt +9242 -0
- package/dist/index.esm2017.js +153 -123
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +105 -14
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +148 -114
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +107 -13
- package/dist/index.node.cjs.js.map +1 -1
- package/package.json +5 -5
- package/types/teamsfx.d.ts +1316 -1253
package/dist/index.esm5.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __awaiter } from 'tslib';
|
|
2
2
|
import jwt_decode from 'jwt-decode';
|
|
3
|
-
import
|
|
3
|
+
import { app, authentication } from '@microsoft/teams-js';
|
|
4
4
|
import { PublicClientApplication } from '@azure/msal-browser';
|
|
5
5
|
import { Client } from '@microsoft/microsoft-graph-client';
|
|
6
6
|
import axios from 'axios';
|
|
@@ -96,6 +96,8 @@ ErrorMessage.BasicCredentialAlreadyExists = "Basic credential already exists!";
|
|
|
96
96
|
// InvalidParameter Error
|
|
97
97
|
ErrorMessage.EmptyParameter = "Parameter {0} is empty";
|
|
98
98
|
ErrorMessage.DuplicateHttpsOptionProperty = "Axios HTTPS agent already defined value for property {0}";
|
|
99
|
+
ErrorMessage.DuplicateApiKeyInHeader = "The request already defined api key in request header with name {0}.";
|
|
100
|
+
ErrorMessage.DuplicateApiKeyInQueryParam = "The request already defined api key in query parameter with name {0}.";
|
|
99
101
|
/**
|
|
100
102
|
* Error class with code and message thrown by the SDK.
|
|
101
103
|
*
|
|
@@ -552,51 +554,48 @@ class TeamsUserCredential {
|
|
|
552
554
|
if (!this.initialized) {
|
|
553
555
|
yield this.init();
|
|
554
556
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
});
|
|
598
|
-
});
|
|
599
|
-
});
|
|
557
|
+
yield app.initialize();
|
|
558
|
+
let result;
|
|
559
|
+
try {
|
|
560
|
+
const params = {
|
|
561
|
+
url: `${this.config.initiateLoginEndpoint}?clientId=${this.config.clientId}&scope=${encodeURI(scopesStr)}&loginHint=${this.loginHint}`,
|
|
562
|
+
width: loginPageWidth,
|
|
563
|
+
height: loginPageHeight,
|
|
564
|
+
};
|
|
565
|
+
result = yield authentication.authenticate(params);
|
|
566
|
+
if (!result) {
|
|
567
|
+
const errorMsg = "Get empty authentication result from MSAL";
|
|
568
|
+
internalLogger.error(errorMsg);
|
|
569
|
+
throw new ErrorWithCode(errorMsg, ErrorCode.InternalError);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
catch (err) {
|
|
573
|
+
const errorMsg = `Consent failed for the scope ${scopesStr} with error: ${err.message}`;
|
|
574
|
+
internalLogger.error(errorMsg);
|
|
575
|
+
throw new ErrorWithCode(errorMsg, ErrorCode.ConsentFailed);
|
|
576
|
+
}
|
|
577
|
+
let resultJson = {};
|
|
578
|
+
try {
|
|
579
|
+
resultJson = JSON.parse(result);
|
|
580
|
+
}
|
|
581
|
+
catch (error) {
|
|
582
|
+
// If can not parse result as Json, will throw error.
|
|
583
|
+
const failedToParseResult = "Failed to parse response to Json.";
|
|
584
|
+
internalLogger.error(failedToParseResult);
|
|
585
|
+
throw new ErrorWithCode(failedToParseResult, ErrorCode.InvalidResponse);
|
|
586
|
+
}
|
|
587
|
+
// If code exists in result, user may using previous auth-start and auth-end page.
|
|
588
|
+
if (resultJson.code) {
|
|
589
|
+
const helpLink = "https://aka.ms/teamsfx-auth-code-flow";
|
|
590
|
+
const usingPreviousAuthPage = "Found auth code in response. Auth code is not support for current version of SDK. " +
|
|
591
|
+
`Please refer to the help link for how to fix the issue: ${helpLink}.`;
|
|
592
|
+
internalLogger.error(usingPreviousAuthPage);
|
|
593
|
+
throw new ErrorWithCode(usingPreviousAuthPage, ErrorCode.InvalidResponse);
|
|
594
|
+
}
|
|
595
|
+
// If sessionStorage exists in result, set the values in current session storage.
|
|
596
|
+
if (resultJson.sessionStorage) {
|
|
597
|
+
this.setSessionStorage(resultJson.sessionStorage);
|
|
598
|
+
}
|
|
600
599
|
});
|
|
601
600
|
}
|
|
602
601
|
/**
|
|
@@ -737,52 +736,41 @@ class TeamsUserCredential {
|
|
|
737
736
|
* @returns SSO token
|
|
738
737
|
*/
|
|
739
738
|
getSSOToken() {
|
|
740
|
-
return
|
|
739
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
741
740
|
if (this.ssoToken) {
|
|
742
741
|
if (this.ssoToken.expiresOnTimestamp - Date.now() > tokenRefreshTimeSpanInMillisecond) {
|
|
743
742
|
internalLogger.verbose("Get SSO token from memory cache");
|
|
744
|
-
|
|
745
|
-
return;
|
|
743
|
+
return this.ssoToken;
|
|
746
744
|
}
|
|
747
745
|
}
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
const errorMsg = "Get empty SSO token from Teams";
|
|
754
|
-
internalLogger.error(errorMsg);
|
|
755
|
-
reject(new ErrorWithCode(errorMsg, ErrorCode.InternalError));
|
|
756
|
-
return;
|
|
757
|
-
}
|
|
758
|
-
const tokenObject = parseJwt(token);
|
|
759
|
-
if (tokenObject.ver !== "1.0" && tokenObject.ver !== "2.0") {
|
|
760
|
-
const errorMsg = "SSO token is not valid with an unknown version: " + tokenObject.ver;
|
|
761
|
-
internalLogger.error(errorMsg);
|
|
762
|
-
reject(new ErrorWithCode(errorMsg, ErrorCode.InternalError));
|
|
763
|
-
return;
|
|
764
|
-
}
|
|
765
|
-
const ssoToken = {
|
|
766
|
-
token,
|
|
767
|
-
expiresOnTimestamp: tokenObject.exp * 1000,
|
|
768
|
-
};
|
|
769
|
-
this.ssoToken = ssoToken;
|
|
770
|
-
resolve(ssoToken);
|
|
771
|
-
},
|
|
772
|
-
failureCallback: (errMessage) => {
|
|
773
|
-
const errorMsg = "Get SSO token failed with error: " + errMessage;
|
|
774
|
-
internalLogger.error(errorMsg);
|
|
775
|
-
reject(new ErrorWithCode(errorMsg, ErrorCode.InternalError));
|
|
776
|
-
},
|
|
777
|
-
resources: [],
|
|
778
|
-
});
|
|
779
|
-
});
|
|
746
|
+
const params = {};
|
|
747
|
+
let token;
|
|
748
|
+
try {
|
|
749
|
+
yield app.initialize();
|
|
750
|
+
token = yield authentication.getAuthToken(params);
|
|
780
751
|
}
|
|
781
|
-
|
|
782
|
-
const errorMsg = "
|
|
752
|
+
catch (err) {
|
|
753
|
+
const errorMsg = "Get SSO token failed with error: " + err.message;
|
|
754
|
+
internalLogger.error(errorMsg);
|
|
755
|
+
throw new ErrorWithCode(errorMsg, ErrorCode.InternalError);
|
|
756
|
+
}
|
|
757
|
+
if (!token) {
|
|
758
|
+
const errorMsg = "Get empty SSO token from Teams";
|
|
783
759
|
internalLogger.error(errorMsg);
|
|
784
|
-
|
|
760
|
+
throw new ErrorWithCode(errorMsg, ErrorCode.InternalError);
|
|
785
761
|
}
|
|
762
|
+
const tokenObject = parseJwt(token);
|
|
763
|
+
if (tokenObject.ver !== "1.0" && tokenObject.ver !== "2.0") {
|
|
764
|
+
const errorMsg = "SSO token is not valid with an unknown version: " + tokenObject.ver;
|
|
765
|
+
internalLogger.error(errorMsg);
|
|
766
|
+
throw new ErrorWithCode(errorMsg, ErrorCode.InternalError);
|
|
767
|
+
}
|
|
768
|
+
const ssoToken = {
|
|
769
|
+
token,
|
|
770
|
+
expiresOnTimestamp: tokenObject.exp * 1000,
|
|
771
|
+
};
|
|
772
|
+
this.ssoToken = ssoToken;
|
|
773
|
+
return ssoToken;
|
|
786
774
|
});
|
|
787
775
|
}
|
|
788
776
|
/**
|
|
@@ -1122,7 +1110,7 @@ function createApiClient(apiEndpoint, authProvider) {
|
|
|
1122
1110
|
*/
|
|
1123
1111
|
class BearerTokenAuthProvider {
|
|
1124
1112
|
/**
|
|
1125
|
-
* @param getToken Function that returns the content of bearer token used in http request
|
|
1113
|
+
* @param { () => Promise<string> } getToken - Function that returns the content of bearer token used in http request
|
|
1126
1114
|
*
|
|
1127
1115
|
* @beta
|
|
1128
1116
|
*/
|
|
@@ -1132,7 +1120,7 @@ class BearerTokenAuthProvider {
|
|
|
1132
1120
|
/**
|
|
1133
1121
|
* Adds authentication info to http requests
|
|
1134
1122
|
*
|
|
1135
|
-
* @param config - Contains all the request information and can be updated to include extra authentication info.
|
|
1123
|
+
* @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
|
|
1136
1124
|
* Refer https://axios-http.com/docs/req_config for detailed document.
|
|
1137
1125
|
*
|
|
1138
1126
|
* @returns Updated axios request config.
|
|
@@ -1165,50 +1153,94 @@ class BearerTokenAuthProvider {
|
|
|
1165
1153
|
class BasicAuthProvider {
|
|
1166
1154
|
/**
|
|
1167
1155
|
*
|
|
1168
|
-
* @param userName - Username used in basic auth
|
|
1169
|
-
* @param password - Password used in basic auth
|
|
1156
|
+
* @param { string } userName - Username used in basic auth
|
|
1157
|
+
* @param { string } password - Password used in basic auth
|
|
1158
|
+
*
|
|
1159
|
+
* @throws {@link ErrorCode|InvalidParameter} - when username or password is empty.
|
|
1160
|
+
* @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
|
|
1170
1161
|
*
|
|
1171
1162
|
* @beta
|
|
1172
1163
|
*/
|
|
1173
1164
|
constructor(userName, password) {
|
|
1174
|
-
|
|
1175
|
-
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "username"), ErrorCode.InvalidParameter);
|
|
1176
|
-
}
|
|
1177
|
-
if (!password) {
|
|
1178
|
-
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "password"), ErrorCode.InvalidParameter);
|
|
1179
|
-
}
|
|
1180
|
-
this.userName = userName;
|
|
1181
|
-
this.password = password;
|
|
1165
|
+
throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "BasicAuthProvider"), ErrorCode.RuntimeNotSupported);
|
|
1182
1166
|
}
|
|
1183
1167
|
/**
|
|
1184
1168
|
* Adds authentication info to http requests
|
|
1185
1169
|
*
|
|
1186
|
-
* @param config - Contains all the request information and can be updated to include extra authentication info.
|
|
1170
|
+
* @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
|
|
1187
1171
|
* Refer https://axios-http.com/docs/req_config for detailed document.
|
|
1188
1172
|
*
|
|
1189
1173
|
* @returns Updated axios request config.
|
|
1190
1174
|
*
|
|
1191
1175
|
* @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when Authorization header or auth property already exists in request configuration.
|
|
1176
|
+
* @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
|
|
1192
1177
|
*
|
|
1193
1178
|
* @beta
|
|
1194
1179
|
*/
|
|
1195
1180
|
AddAuthenticationInfo(config) {
|
|
1196
1181
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1197
|
-
|
|
1198
|
-
throw new ErrorWithCode(ErrorMessage.AuthorizationHeaderAlreadyExists, ErrorCode.AuthorizationInfoAlreadyExists);
|
|
1199
|
-
}
|
|
1200
|
-
if (config.auth) {
|
|
1201
|
-
throw new ErrorWithCode(ErrorMessage.BasicCredentialAlreadyExists, ErrorCode.AuthorizationInfoAlreadyExists);
|
|
1202
|
-
}
|
|
1203
|
-
config.auth = {
|
|
1204
|
-
username: this.userName,
|
|
1205
|
-
password: this.password,
|
|
1206
|
-
};
|
|
1207
|
-
return config;
|
|
1182
|
+
throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "BasicAuthProvider"), ErrorCode.RuntimeNotSupported);
|
|
1208
1183
|
});
|
|
1209
1184
|
}
|
|
1210
1185
|
}
|
|
1211
1186
|
|
|
1187
|
+
// Copyright (c) Microsoft Corporation.
|
|
1188
|
+
/**
|
|
1189
|
+
* Provider that handles API Key authentication
|
|
1190
|
+
*
|
|
1191
|
+
* @beta
|
|
1192
|
+
*/
|
|
1193
|
+
class ApiKeyProvider {
|
|
1194
|
+
/**
|
|
1195
|
+
*
|
|
1196
|
+
* @param { string } keyName - The name of request header or query parameter that specifies API Key
|
|
1197
|
+
* @param { string } keyValue - The value of API Key
|
|
1198
|
+
* @param { ApiKeyLocation } keyLocation - The location of API Key: request header or query parameter.
|
|
1199
|
+
*
|
|
1200
|
+
* @throws {@link ErrorCode|InvalidParameter} - when key name or key value is empty.
|
|
1201
|
+
* @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
|
|
1202
|
+
*
|
|
1203
|
+
* @beta
|
|
1204
|
+
*/
|
|
1205
|
+
constructor(keyName, keyValue, keyLocation) {
|
|
1206
|
+
throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "ApiKeyProvider"), ErrorCode.RuntimeNotSupported);
|
|
1207
|
+
}
|
|
1208
|
+
/**
|
|
1209
|
+
* Adds authentication info to http requests
|
|
1210
|
+
*
|
|
1211
|
+
* @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
|
|
1212
|
+
* Refer https://axios-http.com/docs/req_config for detailed document.
|
|
1213
|
+
*
|
|
1214
|
+
* @returns Updated axios request config.
|
|
1215
|
+
*
|
|
1216
|
+
* @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when API key already exists in request header or url query parameter.
|
|
1217
|
+
* @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
|
|
1218
|
+
*
|
|
1219
|
+
* @beta
|
|
1220
|
+
*/
|
|
1221
|
+
AddAuthenticationInfo(config) {
|
|
1222
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1223
|
+
throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "ApiKeyProvider"), ErrorCode.RuntimeNotSupported);
|
|
1224
|
+
});
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
/**
|
|
1228
|
+
* Define available location for API Key location
|
|
1229
|
+
*
|
|
1230
|
+
* @beta
|
|
1231
|
+
*/
|
|
1232
|
+
var ApiKeyLocation;
|
|
1233
|
+
(function (ApiKeyLocation) {
|
|
1234
|
+
/**
|
|
1235
|
+
* The API Key is placed in request header
|
|
1236
|
+
*/
|
|
1237
|
+
ApiKeyLocation[ApiKeyLocation["Header"] = 0] = "Header";
|
|
1238
|
+
/**
|
|
1239
|
+
* The API Key is placed in query parameter
|
|
1240
|
+
*/
|
|
1241
|
+
ApiKeyLocation[ApiKeyLocation["QueryParams"] = 1] = "QueryParams";
|
|
1242
|
+
})(ApiKeyLocation || (ApiKeyLocation = {}));
|
|
1243
|
+
|
|
1212
1244
|
// Copyright (c) Microsoft Corporation.
|
|
1213
1245
|
/**
|
|
1214
1246
|
* Provider that handles Certificate authentication
|
|
@@ -1234,6 +1266,7 @@ class CertificateAuthProvider {
|
|
|
1234
1266
|
* @returns Updated axios request config.
|
|
1235
1267
|
*
|
|
1236
1268
|
* @throws {@link ErrorCode|InvalidParameter} - when custom httpsAgent in the request has duplicate properties with certOption provided in constructor.
|
|
1269
|
+
* @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
|
|
1237
1270
|
*
|
|
1238
1271
|
* @beta
|
|
1239
1272
|
*/
|
|
@@ -1248,29 +1281,30 @@ class CertificateAuthProvider {
|
|
|
1248
1281
|
*
|
|
1249
1282
|
* @param { string | Buffer } cert - The cert chain in PEM format
|
|
1250
1283
|
* @param { string | Buffer } key - The private key for the cert chain
|
|
1251
|
-
* @param { string
|
|
1252
|
-
* @param { string? | Buffer? } ca - Overrides the trusted CA certificates
|
|
1284
|
+
* @param { {passphrase?: string; ca?: string | Buffer} } options - Optional settings when create the cert options.
|
|
1253
1285
|
*
|
|
1254
1286
|
* @returns Instance of SecureContextOptions
|
|
1255
1287
|
*
|
|
1256
1288
|
* @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
|
|
1289
|
+
* @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
|
|
1257
1290
|
*
|
|
1258
1291
|
*/
|
|
1259
|
-
function createPemCertOption(cert, key,
|
|
1292
|
+
function createPemCertOption(cert, key, options) {
|
|
1260
1293
|
throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "createPemCertOption"), ErrorCode.RuntimeNotSupported);
|
|
1261
1294
|
}
|
|
1262
1295
|
/**
|
|
1263
1296
|
* Helper to create SecureContextOptions from PFX format cert
|
|
1264
1297
|
*
|
|
1265
1298
|
* @param { string | Buffer } pfx - The content of .pfx file
|
|
1266
|
-
* @param { string
|
|
1299
|
+
* @param { {passphrase?: string} } options - Optional settings when create the cert options.
|
|
1267
1300
|
*
|
|
1268
1301
|
* @returns Instance of SecureContextOptions
|
|
1269
1302
|
*
|
|
1270
1303
|
* @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
|
|
1304
|
+
* @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
|
|
1271
1305
|
*
|
|
1272
1306
|
*/
|
|
1273
|
-
function createPfxCertOption(pfx,
|
|
1307
|
+
function createPfxCertOption(pfx, options) {
|
|
1274
1308
|
throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "createPfxCertOption"), ErrorCode.RuntimeNotSupported);
|
|
1275
1309
|
}
|
|
1276
1310
|
|
|
@@ -1804,5 +1838,5 @@ class CommandBot {
|
|
|
1804
1838
|
}
|
|
1805
1839
|
}
|
|
1806
1840
|
|
|
1807
|
-
export { AppCredential, BasicAuthProvider, BearerTokenAuthProvider, CertificateAuthProvider, Channel, CommandBot, ConversationBot, ErrorCode, ErrorWithCode, IdentityType, LogLevel, Member, MsGraphAuthProvider, NotificationBot, OnBehalfOfUserCredential, TeamsBotInstallation, TeamsBotSsoPrompt, TeamsFx, TeamsUserCredential, createApiClient, createMicrosoftGraphClient, createPemCertOption, createPfxCertOption, getLogLevel, getTediousConnectionConfig, sendAdaptiveCard, sendMessage, setLogFunction, setLogLevel, setLogger };
|
|
1841
|
+
export { ApiKeyLocation, ApiKeyProvider, AppCredential, BasicAuthProvider, BearerTokenAuthProvider, CertificateAuthProvider, Channel, CommandBot, ConversationBot, ErrorCode, ErrorWithCode, IdentityType, LogLevel, Member, MsGraphAuthProvider, NotificationBot, OnBehalfOfUserCredential, TeamsBotInstallation, TeamsBotSsoPrompt, TeamsFx, TeamsUserCredential, createApiClient, createMicrosoftGraphClient, createPemCertOption, createPfxCertOption, getLogLevel, getTediousConnectionConfig, sendAdaptiveCard, sendMessage, setLogFunction, setLogLevel, setLogger };
|
|
1808
1842
|
//# sourceMappingURL=index.esm5.js.map
|