@microsoft/teamsfx 0.6.2-rc.0 → 0.6.3-alpha.633d9d21e.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.
@@ -2,6 +2,7 @@ import jwt_decode from 'jwt-decode';
2
2
  import * as microsoftTeams from '@microsoft/teams-js';
3
3
  import { PublicClientApplication } from '@azure/msal-browser';
4
4
  import { Client } from '@microsoft/microsoft-graph-client';
5
+ import axios from 'axios';
5
6
 
6
7
  // Copyright (c) Microsoft Corporation.
7
8
  // Licensed under the MIT license.
@@ -84,6 +85,9 @@ ErrorMessage.FailToAcquireTokenOnBehalfOfUser = "Failed to acquire access token
84
85
  ErrorMessage.OnlyMSTeamsChannelSupported = "{0} is only supported in MS Teams Channel";
85
86
  // IdentityTypeNotSupported Error
86
87
  ErrorMessage.IdentityTypeNotSupported = "{0} identity is not supported in {1}";
88
+ // InvalidParameter Error
89
+ ErrorMessage.EmptyParameter = "Parameter {0} is empty";
90
+ ErrorMessage.DuplicateHttpsOptionProperty = "Axios HTTPS agent already defined value for property {0}";
87
91
  /**
88
92
  * Error class with code and message thrown by the SDK.
89
93
  *
@@ -1054,6 +1058,132 @@ class TeamsBotSsoPrompt {
1054
1058
  }
1055
1059
  }
1056
1060
 
1061
+ // Copyright (c) Microsoft Corporation.
1062
+ /**
1063
+ * Initializes new Axios instance with specific auth provider
1064
+ *
1065
+ * @param apiEndpoint - Base url of the API
1066
+ * @param authProvider - Auth provider that injects authentication info to each request
1067
+ * @returns axios instance configured with specfic auth provider
1068
+ *
1069
+ * @example
1070
+ * ```typescript
1071
+ * const client = createApiClient("https://my-api-endpoint-base-url", new BasicAuthProvider("xxx","xxx"));
1072
+ * ```
1073
+ *
1074
+ * @beta
1075
+ */
1076
+ function createApiClient(apiEndpoint, authProvider) {
1077
+ // Add a request interceptor
1078
+ const instance = axios.create({
1079
+ baseURL: apiEndpoint,
1080
+ });
1081
+ instance.interceptors.request.use(async function (config) {
1082
+ return await authProvider.AddAuthenticationInfo(config);
1083
+ });
1084
+ return instance;
1085
+ }
1086
+
1087
+ // Copyright (c) Microsoft Corporation.
1088
+ // Licensed under the MIT license.
1089
+ /**
1090
+ * Provider that handles Bearer Token authentication
1091
+ *
1092
+ * @beta
1093
+ */
1094
+ class BearerTokenAuthProvider {
1095
+ /**
1096
+ * @param getToken Function that returns the content of bearer token used in http request
1097
+ *
1098
+ * @beta
1099
+ */
1100
+ constructor(getToken) {
1101
+ this.getToken = getToken;
1102
+ }
1103
+ /**
1104
+ * Adds authentication info to http requests
1105
+ *
1106
+ * @param config - Contains all the request information and can be updated to include extra authentication info.
1107
+ * Refer https://axios-http.com/docs/req_config for detailed document.
1108
+ *
1109
+ * @beta
1110
+ */
1111
+ async AddAuthenticationInfo(config) {
1112
+ const token = await this.getToken();
1113
+ if (!config.headers) {
1114
+ config.headers = {};
1115
+ }
1116
+ if (config.headers["Authorization"]) {
1117
+ throw new Error("Authorization header already exists!");
1118
+ }
1119
+ config.headers["Authorization"] = `Bearer ${token}`;
1120
+ return config;
1121
+ }
1122
+ }
1123
+
1124
+ // Copyright (c) Microsoft Corporation.
1125
+ /**
1126
+ * Provider that handles Certificate authentication
1127
+ *
1128
+ * @beta
1129
+ */
1130
+ class CertificateAuthProvider {
1131
+ /**
1132
+ *
1133
+ * @param { SecureContextOptions } certOption - information about the cert used in http requests
1134
+ *
1135
+ * @beta
1136
+ */
1137
+ constructor(certOption) {
1138
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "CertificateAuthProvider"), ErrorCode.RuntimeNotSupported);
1139
+ }
1140
+ /**
1141
+ * Adds authentication info to http requests.
1142
+ *
1143
+ * @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
1144
+ * Refer https://axios-http.com/docs/req_config for detailed document.
1145
+ *
1146
+ * @returns Updated axios request config.
1147
+ *
1148
+ * @throws {@link ErrorCode|InvalidParameter} - when custom httpsAgent in the request has duplicate properties with certOption provided in constructor.
1149
+ *
1150
+ * @beta
1151
+ */
1152
+ async AddAuthenticationInfo(config) {
1153
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "CertificateAuthProvider"), ErrorCode.RuntimeNotSupported);
1154
+ }
1155
+ }
1156
+ /**
1157
+ * Helper to create SecureContextOptions from PEM format cert
1158
+ *
1159
+ * @param { string | Buffer } cert - The cert chain in PEM format
1160
+ * @param { string | Buffer } key - The private key for the cert chain
1161
+ * @param { string? } passphrase - The passphrase for private key
1162
+ * @param { string? | Buffer? } ca - Overrides the trusted CA certificates
1163
+ *
1164
+ * @returns Instance of SecureContextOptions
1165
+ *
1166
+ * @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
1167
+ *
1168
+ */
1169
+ function createPemCertOption(cert, key, passphrase, ca) {
1170
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "createPemCertOption"), ErrorCode.RuntimeNotSupported);
1171
+ }
1172
+ /**
1173
+ * Helper to create SecureContextOptions from PFX format cert
1174
+ *
1175
+ * @param { string | Buffer } pfx - The content of .pfx file
1176
+ * @param { string? } passphrase - Optional. The passphrase of .pfx file
1177
+ *
1178
+ * @returns Instance of SecureContextOptions
1179
+ *
1180
+ * @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
1181
+ *
1182
+ */
1183
+ function createPfxCertOption(pfx, passphrase) {
1184
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "createPfxCertOption"), ErrorCode.RuntimeNotSupported);
1185
+ }
1186
+
1057
1187
  // Copyright (c) Microsoft Corporation.
1058
1188
  // Licensed under the MIT license.
1059
1189
  /**
@@ -1170,5 +1300,403 @@ class TeamsFx {
1170
1300
  }
1171
1301
  }
1172
1302
 
1173
- export { AppCredential, ErrorCode, ErrorWithCode, IdentityType, LogLevel, MsGraphAuthProvider, OnBehalfOfUserCredential, TeamsBotSsoPrompt, TeamsFx, TeamsUserCredential, createMicrosoftGraphClient, getLogLevel, getTediousConnectionConfig, setLogFunction, setLogLevel, setLogger };
1303
+ // Copyright (c) Microsoft Corporation.
1304
+ /**
1305
+ * Provide utilities for bot conversation, including:
1306
+ * - handle command and response.
1307
+ * - send notification to varies targets (e.g., member, group, channel).
1308
+ *
1309
+ * @remarks
1310
+ * Only work on server side.
1311
+ *
1312
+ * @beta
1313
+ */
1314
+ class ConversationBot {
1315
+ /**
1316
+ * Creates new instance of the `ConversationBot`.
1317
+ *
1318
+ * @param options - initialize options
1319
+ *
1320
+ * @remarks
1321
+ * Only work on server side.
1322
+ *
1323
+ * @beta
1324
+ */
1325
+ constructor(options) {
1326
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "ConversationBot"), ErrorCode.RuntimeNotSupported);
1327
+ }
1328
+ /**
1329
+ * The request handler to integrate with web request.
1330
+ *
1331
+ * @param req - an Express or Restify style request object.
1332
+ * @param res - an Express or Restify style response object.
1333
+ * @param logic - the additional function to handle bot context.
1334
+ *
1335
+ * @remarks
1336
+ * Only work on server side.
1337
+ *
1338
+ * @beta
1339
+ */
1340
+ async requestHandler(req, res, logic) {
1341
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "ConversationBot"), ErrorCode.RuntimeNotSupported);
1342
+ }
1343
+ }
1344
+
1345
+ // Copyright (c) Microsoft Corporation.
1346
+ /**
1347
+ * Send a plain text message to a notification target.
1348
+ *
1349
+ * @remarks
1350
+ * Only work on server side.
1351
+ *
1352
+ * @param target - the notification target.
1353
+ * @param text - the plain text message.
1354
+ * @returns A `Promise` representing the asynchronous operation.
1355
+ *
1356
+ * @beta
1357
+ */
1358
+ function sendMessage(target, text) {
1359
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "sendMessage"), ErrorCode.RuntimeNotSupported);
1360
+ }
1361
+ /**
1362
+ * Send an adaptive card message to a notification target.
1363
+ *
1364
+ * @remarks
1365
+ * Only work on server side.
1366
+ *
1367
+ * @param target - the notification target.
1368
+ * @param card - the adaptive card raw JSON.
1369
+ * @returns A `Promise` representing the asynchronous operation.
1370
+ *
1371
+ * @beta
1372
+ */
1373
+ function sendAdaptiveCard(target, card) {
1374
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "sendAdaptiveCard"), ErrorCode.RuntimeNotSupported);
1375
+ }
1376
+ /**
1377
+ * A {@link NotificationTarget} that represents a team channel.
1378
+ *
1379
+ * @remarks
1380
+ * Only work on server side.
1381
+ *
1382
+ * It's recommended to get channels from {@link TeamsBotInstallation.channels()}.
1383
+ *
1384
+ * @beta
1385
+ */
1386
+ class Channel {
1387
+ /**
1388
+ * Constuctor.
1389
+ *
1390
+ * @remarks
1391
+ * Only work on server side.
1392
+ *
1393
+ * It's recommended to get channels from {@link TeamsBotInstallation.channels()}, instead of using this constructor.
1394
+ *
1395
+ * @param parent - The parent {@link TeamsBotInstallation} where this channel is created from.
1396
+ * @param info - Detailed channel information.
1397
+ *
1398
+ * @beta
1399
+ */
1400
+ constructor(parent, info) {
1401
+ /**
1402
+ * Notification target type. For channel it's always "Channel".
1403
+ *
1404
+ * @remarks
1405
+ * Only work on server side.
1406
+ *
1407
+ * @beta
1408
+ */
1409
+ this.type = "Channel";
1410
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "Channel"), ErrorCode.RuntimeNotSupported);
1411
+ }
1412
+ /**
1413
+ * Send a plain text message.
1414
+ *
1415
+ * @remarks
1416
+ * Only work on server side.
1417
+ *
1418
+ * @param text - the plain text message.
1419
+ * @returns A `Promise` representing the asynchronous operation.
1420
+ *
1421
+ * @beta
1422
+ */
1423
+ sendMessage(text) {
1424
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "Channel"), ErrorCode.RuntimeNotSupported);
1425
+ }
1426
+ /**
1427
+ * Send an adaptive card message.
1428
+ *
1429
+ * @remarks
1430
+ * Only work on server side.
1431
+ *
1432
+ * @param card - the adaptive card raw JSON.
1433
+ * @returns A `Promise` representing the asynchronous operation.
1434
+ *
1435
+ * @beta
1436
+ */
1437
+ async sendAdaptiveCard(card) {
1438
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "Channel"), ErrorCode.RuntimeNotSupported);
1439
+ }
1440
+ }
1441
+ /**
1442
+ * A {@link NotificationTarget} that represents a team member.
1443
+ *
1444
+ * @remarks
1445
+ * Only work on server side.
1446
+ *
1447
+ * It's recommended to get members from {@link TeamsBotInstallation.members()}.
1448
+ *
1449
+ * @beta
1450
+ */
1451
+ class Member {
1452
+ /**
1453
+ * Constuctor.
1454
+ *
1455
+ * @remarks
1456
+ * Only work on server side.
1457
+ *
1458
+ * It's recommended to get members from {@link TeamsBotInstallation.members()}, instead of using this constructor.
1459
+ *
1460
+ * @param parent - The parent {@link TeamsBotInstallation} where this member is created from.
1461
+ * @param account - Detailed member account information.
1462
+ *
1463
+ * @beta
1464
+ */
1465
+ constructor(parent, account) {
1466
+ /**
1467
+ * Notification target type. For member it's always "Person".
1468
+ *
1469
+ * @remarks
1470
+ * Only work on server side.
1471
+ *
1472
+ * @beta
1473
+ */
1474
+ this.type = "Person";
1475
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "Member"), ErrorCode.RuntimeNotSupported);
1476
+ }
1477
+ /**
1478
+ * Send a plain text message.
1479
+ *
1480
+ * @remarks
1481
+ * Only work on server side.
1482
+ *
1483
+ * @param text - the plain text message.
1484
+ * @returns A `Promise` representing the asynchronous operation.
1485
+ *
1486
+ * @beta
1487
+ */
1488
+ sendMessage(text) {
1489
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "Member"), ErrorCode.RuntimeNotSupported);
1490
+ }
1491
+ /**
1492
+ * Send an adaptive card message.
1493
+ *
1494
+ * @remarks
1495
+ * Only work on server side.
1496
+ *
1497
+ * @param card - the adaptive card raw JSON.
1498
+ * @returns A `Promise` representing the asynchronous operation.
1499
+ *
1500
+ * @beta
1501
+ */
1502
+ async sendAdaptiveCard(card) {
1503
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "Member"), ErrorCode.RuntimeNotSupported);
1504
+ }
1505
+ }
1506
+ /**
1507
+ * A {@link NotificationTarget} that represents a bot installation. Teams Bot could be installed into
1508
+ * - Personal chat
1509
+ * - Group chat
1510
+ * - Team (by default the `General` channel)
1511
+ *
1512
+ * @remarks
1513
+ * Only work on server side.
1514
+ *
1515
+ * It's recommended to get bot installations from {@link ConversationBot.installations()}.
1516
+ *
1517
+ * @beta
1518
+ */
1519
+ class TeamsBotInstallation {
1520
+ /**
1521
+ * Constructor
1522
+ *
1523
+ * @remarks
1524
+ * Only work on server side.
1525
+ *
1526
+ * It's recommended to get bot installations from {@link ConversationBot.installations()}, instead of using this constructor.
1527
+ *
1528
+ * @param adapter - the bound `BotFrameworkAdapter`.
1529
+ * @param conversationReference - the bound `ConversationReference`.
1530
+ *
1531
+ * @beta
1532
+ */
1533
+ constructor(adapter, conversationReference) {
1534
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "TeamsBotInstallation"), ErrorCode.RuntimeNotSupported);
1535
+ }
1536
+ /**
1537
+ * Send a plain text message.
1538
+ *
1539
+ * @remarks
1540
+ * Only work on server side.
1541
+ *
1542
+ * @param text - the plain text message.
1543
+ * @returns A `Promise` representing the asynchronous operation.
1544
+ *
1545
+ * @beta
1546
+ */
1547
+ sendMessage(text) {
1548
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "TeamsBotInstallation"), ErrorCode.RuntimeNotSupported);
1549
+ }
1550
+ /**
1551
+ * Send an adaptive card message.
1552
+ *
1553
+ * @remarks
1554
+ * Only work on server side.
1555
+ *
1556
+ * @param card - the adaptive card raw JSON.
1557
+ * @returns A `Promise` representing the asynchronous operation.
1558
+ *
1559
+ * @beta
1560
+ */
1561
+ sendAdaptiveCard(card) {
1562
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "TeamsBotInstallation"), ErrorCode.RuntimeNotSupported);
1563
+ }
1564
+ /**
1565
+ * Get channels from this bot installation.
1566
+ *
1567
+ * @remarks
1568
+ * Only work on server side.
1569
+ *
1570
+ * @returns an array of channels if bot is installed into a team, otherwise returns an empty array.
1571
+ *
1572
+ * @beta
1573
+ */
1574
+ async channels() {
1575
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "TeamsBotInstallation"), ErrorCode.RuntimeNotSupported);
1576
+ }
1577
+ /**
1578
+ * Get members from this bot installation.
1579
+ *
1580
+ * @remarks
1581
+ * Only work on server side.
1582
+ *
1583
+ * @returns an array of members from where the bot is installed.
1584
+ *
1585
+ * @beta
1586
+ */
1587
+ async members() {
1588
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "TeamsBotInstallation"), ErrorCode.RuntimeNotSupported);
1589
+ }
1590
+ }
1591
+ /**
1592
+ * Provide static utilities for bot notification.
1593
+ *
1594
+ * @remarks
1595
+ * Only work on server side.
1596
+ *
1597
+ * @example
1598
+ * Here's an example on how to send notification via Teams Bot.
1599
+ * ```typescript
1600
+ * // initialize (it's recommended to be called before handling any bot message)
1601
+ * const notificationBot = new NotificationBot(adapter);
1602
+ *
1603
+ * // get all bot installations and send message
1604
+ * for (const target of await notificationBot.installations()) {
1605
+ * await target.sendMessage("Hello Notification");
1606
+ * }
1607
+ *
1608
+ * // alternative - send message to all members
1609
+ * for (const target of await notificationBot.installations()) {
1610
+ * for (const member of await target.members()) {
1611
+ * await member.sendMessage("Hello Notification");
1612
+ * }
1613
+ * }
1614
+ * ```
1615
+ *
1616
+ * @beta
1617
+ */
1618
+ class NotificationBot {
1619
+ /**
1620
+ * constructor of the notification bot.
1621
+ *
1622
+ * @remarks
1623
+ * Only work on server side.
1624
+ *
1625
+ * To ensure accuracy, it's recommended to initialize before handling any message.
1626
+ *
1627
+ * @param adapter - the bound `BotFrameworkAdapter`
1628
+ * @param options - initialize options
1629
+ *
1630
+ * @beta
1631
+ */
1632
+ constructor(adapter, options) {
1633
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "NotificationBot"), ErrorCode.RuntimeNotSupported);
1634
+ }
1635
+ /**
1636
+ * Get all targets where the bot is installed.
1637
+ *
1638
+ * @remarks
1639
+ * Only work on server side.
1640
+ *
1641
+ * The result is retrieving from the persisted storage.
1642
+ *
1643
+ * @returns - an array of {@link TeamsBotInstallation}.
1644
+ *
1645
+ * @beta
1646
+ */
1647
+ static async installations() {
1648
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "NotificationBot"), ErrorCode.RuntimeNotSupported);
1649
+ }
1650
+ }
1651
+
1652
+ // Copyright (c) Microsoft Corporation.
1653
+ /**
1654
+ * A command bot for receiving commands and sending responses in Teams.
1655
+ *
1656
+ * @remarks
1657
+ * Only work on server side.
1658
+ *
1659
+ * @beta
1660
+ */
1661
+ class CommandBot {
1662
+ /**
1663
+ * Creates a new instance of the `CommandBot`.
1664
+ *
1665
+ * @param adapter The bound `BotFrameworkAdapter`.
1666
+ * @param commands The commands to registered with the command bot. Each command should implement the interface {@link TeamsFxBotCommandHandler} so that it can be correctly handled by this command bot.
1667
+ *
1668
+ * @beta
1669
+ */
1670
+ constructor(adapter, commands) {
1671
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "CommandBot"), ErrorCode.RuntimeNotSupported);
1672
+ }
1673
+ /**
1674
+ * Registers a command into the command bot.
1675
+ *
1676
+ * @param command The command to registered.
1677
+ *
1678
+ * @remarks
1679
+ * Only work on server side.
1680
+ *
1681
+ * @beta
1682
+ */
1683
+ registerCommand(command) {
1684
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "CommandBot"), ErrorCode.RuntimeNotSupported);
1685
+ }
1686
+ /**
1687
+ * Registers commands into the command bot.
1688
+ *
1689
+ * @param commands The command to registered.
1690
+ *
1691
+ * @remarks
1692
+ * Only work on server side.
1693
+ *
1694
+ * @beta
1695
+ */
1696
+ registerCommands(commands) {
1697
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "CommandnBot"), ErrorCode.RuntimeNotSupported);
1698
+ }
1699
+ }
1700
+
1701
+ export { AppCredential, 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 };
1174
1702
  //# sourceMappingURL=index.esm2017.js.map