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