@pnp/cli-microsoft365 5.2.0-beta.0f1c454 → 5.2.0-beta.119724d

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/.eslintrc.js CHANGED
@@ -37,6 +37,7 @@ const dictionary = [
37
37
  'list',
38
38
  'management',
39
39
  'member',
40
+ 'membership',
40
41
  'messaging',
41
42
  'news',
42
43
  'oauth2',
package/dist/cli/Cli.js CHANGED
@@ -586,23 +586,7 @@ class Cli {
586
586
  helpFilePath = path.join(...pathChunks);
587
587
  if (fs.existsSync(helpFilePath)) {
588
588
  Cli.log();
589
- // because of prism, loading markshell slows down CLI a lot
590
- // let's lazy-load it only when it's needed (help was requested)
591
- const markshell = require('markshell');
592
- const chalk = require('chalk');
593
- const theme = markshell.getTheme();
594
- const admonitionStyles = theme.admonitions.getStyles();
595
- admonitionStyles.indent.beforeIndent = 0;
596
- admonitionStyles.indent.titleIndent = 3;
597
- admonitionStyles.indent.afterIndent = 0;
598
- theme.admonitions.setStyles(admonitionStyles);
599
- theme.indents.definitionList = 2;
600
- theme.headline = chalk.white;
601
- theme.inlineCode = chalk.cyan;
602
- theme.sourceCodeTheme = 'solarizelight';
603
- theme.includePath = path.join(this.commandsFolder, '..', '..', 'docs');
604
- markshell.setTheme(theme);
605
- Cli.log(markshell.toRawContent(helpFilePath));
589
+ Cli.log(utils_1.md.md2plain(fs.readFileSync(helpFilePath, 'utf8'), path.join(this.commandsFolder, '..', '..', 'docs')));
606
590
  }
607
591
  }
608
592
  printAvailableCommands() {
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const config_1 = require("../../../../config");
4
3
  const request_1 = require("../../../../request");
5
4
  const utils_1 = require("../../../../utils");
6
5
  const SpoCommand_1 = require("../../../base/SpoCommand");
@@ -18,58 +17,25 @@ class SpoTenantRecycleBinItemRestoreCommand extends SpoCommand_1.default {
18
17
  return telemetryProps;
19
18
  }
20
19
  commandAction(logger, args, cb) {
21
- this.dots = '';
22
20
  utils_1.spo
23
21
  .getSpoAdminUrl(logger, this.debug)
24
22
  .then((adminUrl) => {
25
- this.spoAdminUrl = adminUrl;
26
- return utils_1.spo.ensureFormDigest(this.spoAdminUrl, logger, this.context, this.debug);
27
- })
28
- .then((res) => {
29
- this.context = res;
30
- if (this.verbose) {
31
- logger.logToStderr(`Restoring deleted site collection ${args.options.url}...`);
32
- }
33
23
  const requestOptions = {
34
- url: `${this.spoAdminUrl}/_vti_bin/client.svc/ProcessQuery`,
24
+ url: `${adminUrl}/_api/SPOInternalUseOnly.Tenant/RestoreDeletedSite`,
35
25
  headers: {
36
- 'X-RequestDigest': this.context.FormDigestValue
26
+ accept: 'application/json;odata=nometadata',
27
+ 'content-type': 'application/json;charset=utf-8'
37
28
  },
38
- data: `<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="${config_1.default.applicationName}" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009"><Actions><ObjectPath Id="2" ObjectPathId="1" /><ObjectPath Id="4" ObjectPathId="3" /><Query Id="5" ObjectPathId="3"><Query SelectAllProperties="false"><Properties><Property Name="PollingInterval" ScalarProperty="true" /><Property Name="IsComplete" ScalarProperty="true" /></Properties></Query></Query></Actions><ObjectPaths><Constructor Id="1" TypeId="{268004ae-ef6b-4e9b-8425-127220d84719}" /><Method Id="3" ParentId="1" Name="RestoreDeletedSite"><Parameters><Parameter Type="String">${utils_1.formatting.escapeXml(args.options.url)}</Parameter></Parameters></Method></ObjectPaths></Request>`
29
+ data: {
30
+ siteUrl: args.options.url
31
+ }
39
32
  };
40
33
  return request_1.default.post(requestOptions);
41
34
  })
42
- .then((res) => {
43
- return new Promise((resolve, reject) => {
44
- const json = JSON.parse(res);
45
- const response = json[0];
46
- if (response.ErrorInfo) {
47
- reject(response.ErrorInfo.ErrorMessage);
48
- }
49
- else {
50
- const operation = json[json.length - 1];
51
- const isComplete = operation.IsComplete;
52
- if (!args.options.wait || isComplete) {
53
- resolve();
54
- return;
55
- }
56
- setTimeout(() => {
57
- utils_1.spo.waitUntilFinished({
58
- operationId: JSON.stringify(operation._ObjectIdentity_),
59
- siteUrl: this.spoAdminUrl,
60
- resolve,
61
- reject,
62
- logger,
63
- currentContext: this.context,
64
- dots: this.dots,
65
- debug: this.debug,
66
- verbose: this.verbose
67
- });
68
- }, operation.PollingInterval);
69
- }
70
- });
71
- })
72
- .then(_ => cb(), (err) => this.handleRejectedPromise(err, logger, cb));
35
+ .then(res => {
36
+ logger.log(JSON.parse(res));
37
+ cb();
38
+ }, (err) => this.handleRejectedODataJsonPromise(err, logger, cb));
73
39
  }
74
40
  options() {
75
41
  const options = [
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("../../../../utils");
4
+ const GraphCommand_1 = require("../../../base/GraphCommand");
5
+ const commands_1 = require("../../commands");
6
+ const request_1 = require("../../../../request");
7
+ class TeamsChannelMembershipListCommand extends GraphCommand_1.default {
8
+ constructor() {
9
+ super(...arguments);
10
+ this.teamId = '';
11
+ }
12
+ get name() {
13
+ return commands_1.default.CHANNEL_MEMBERSHIP_LIST;
14
+ }
15
+ get description() {
16
+ return 'Lists memberships in the specified Microsoft Teams team channel';
17
+ }
18
+ defaultProperties() {
19
+ return ['id', 'roles', 'displayName', 'userId', 'email'];
20
+ }
21
+ getTelemetryProperties(args) {
22
+ const telemetryProps = super.getTelemetryProperties(args);
23
+ telemetryProps.teamId = typeof args.options.teamId !== 'undefined';
24
+ telemetryProps.teamName = typeof args.options.teamName !== 'undefined';
25
+ telemetryProps.channelId = typeof args.options.channelId !== 'undefined';
26
+ telemetryProps.channelName = typeof args.options.channelName !== 'undefined';
27
+ telemetryProps.role = typeof args.options.role;
28
+ return telemetryProps;
29
+ }
30
+ commandAction(logger, args, cb) {
31
+ this
32
+ .getTeamId(args)
33
+ .then((teamId) => {
34
+ this.teamId = teamId;
35
+ return this.getChannelId(args);
36
+ })
37
+ .then((channelId) => {
38
+ const endpoint = `${this.resource}/v1.0/teams/${this.teamId}/channels/${channelId}/members`;
39
+ return utils_1.odata.getAllItems(endpoint, logger);
40
+ })
41
+ .then((memberships) => {
42
+ if (args.options.role) {
43
+ if (args.options.role === 'member') {
44
+ // Members have no role value
45
+ memberships = memberships.filter(i => i.roles.length === 0);
46
+ }
47
+ else {
48
+ memberships = memberships.filter(i => i.roles.indexOf(args.options.role) !== -1);
49
+ }
50
+ }
51
+ logger.log(memberships);
52
+ cb();
53
+ }, (err) => this.handleRejectedODataJsonPromise(err, logger, cb));
54
+ }
55
+ getTeamId(args) {
56
+ if (args.options.teamId) {
57
+ return Promise.resolve(args.options.teamId);
58
+ }
59
+ const requestOptions = {
60
+ url: `${this.resource}/v1.0/groups?$filter=displayName eq '${encodeURIComponent(args.options.teamName)}'`,
61
+ headers: {
62
+ accept: 'application/json;odata.metadata=none'
63
+ },
64
+ responseType: 'json'
65
+ };
66
+ return request_1.default
67
+ .get(requestOptions)
68
+ .then(response => {
69
+ const groupItem = response.value[0];
70
+ if (!groupItem) {
71
+ return Promise.reject(`The specified team does not exist in the Microsoft Teams`);
72
+ }
73
+ if (groupItem.resourceProvisioningOptions.indexOf('Team') === -1) {
74
+ return Promise.reject(`The specified team does not exist in the Microsoft Teams`);
75
+ }
76
+ if (response.value.length > 1) {
77
+ return Promise.reject(`Multiple Microsoft Teams teams with name ${args.options.teamName} found: ${response.value.map(x => x.id)}`);
78
+ }
79
+ return Promise.resolve(groupItem.id);
80
+ });
81
+ }
82
+ getChannelId(args) {
83
+ if (args.options.channelId) {
84
+ return Promise.resolve(args.options.channelId);
85
+ }
86
+ const channelRequestOptions = {
87
+ url: `${this.resource}/v1.0/teams/${encodeURIComponent(this.teamId)}/channels?$filter=displayName eq '${encodeURIComponent(args.options.channelName)}'`,
88
+ headers: {
89
+ accept: 'application/json;odata.metadata=none'
90
+ },
91
+ responseType: 'json'
92
+ };
93
+ return request_1.default
94
+ .get(channelRequestOptions)
95
+ .then(response => {
96
+ const channelItem = response.value[0];
97
+ if (!channelItem) {
98
+ return Promise.reject(`The specified channel does not exist in the Microsoft Teams team`);
99
+ }
100
+ return Promise.resolve(channelItem.id);
101
+ });
102
+ }
103
+ options() {
104
+ const options = [
105
+ {
106
+ option: '--teamId [teamId]'
107
+ },
108
+ {
109
+ option: '--teamName [teamName]'
110
+ },
111
+ {
112
+ option: '--channelId [channelId]'
113
+ },
114
+ {
115
+ option: '--channelName [channelName]'
116
+ },
117
+ {
118
+ option: '-r, --role [role]',
119
+ autocomplete: ['owner', 'member', 'guest']
120
+ }
121
+ ];
122
+ const parentOptions = super.options();
123
+ return options.concat(parentOptions);
124
+ }
125
+ validate(args) {
126
+ if (args.options.teamId && args.options.teamName) {
127
+ return 'Specify either teamId or teamName, but not both';
128
+ }
129
+ if (!args.options.teamId && !args.options.teamName) {
130
+ return 'Specify teamId or teamName, one is required';
131
+ }
132
+ if (args.options.teamId && !utils_1.validation.isValidGuid(args.options.teamId)) {
133
+ return `${args.options.teamId} is not a valid GUID`;
134
+ }
135
+ if (args.options.channelId && args.options.channelName) {
136
+ return 'Specify either channelId or channelName, but not both';
137
+ }
138
+ if (!args.options.channelId && !args.options.channelName) {
139
+ return 'Specify channelId or channelName, one is required';
140
+ }
141
+ if (args.options.role) {
142
+ if (['owner', 'member', 'guest'].indexOf(args.options.role) === -1) {
143
+ return `${args.options.role} is not a valid role value. Allowed values owner|member|guest`;
144
+ }
145
+ }
146
+ return true;
147
+ }
148
+ }
149
+ module.exports = new TeamsChannelMembershipListCommand();
150
+ //# sourceMappingURL=channel-membership-list.js.map
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const Auth_1 = require("../../../../Auth");
13
+ const os = require("os");
14
+ const request_1 = require("../../../../request");
15
+ const GraphCommand_1 = require("../../../base/GraphCommand");
16
+ const commands_1 = require("../../commands");
17
+ const validation_1 = require("../../../../utils/validation");
18
+ const accessToken_1 = require("../../../../utils/accessToken");
19
+ const chatUtil_1 = require("./chatUtil");
20
+ class TeamsChatGetCommand extends GraphCommand_1.default {
21
+ get name() {
22
+ return commands_1.default.CHAT_GET;
23
+ }
24
+ get description() {
25
+ return 'Get a Microsoft Teams chat conversation by id, participants or chat name.';
26
+ }
27
+ getTelemetryProperties(args) {
28
+ const telemetryProps = super.getTelemetryProperties(args);
29
+ telemetryProps.id = typeof args.options.id !== 'undefined';
30
+ telemetryProps.participants = typeof args.options.participants !== 'undefined';
31
+ telemetryProps.name = typeof args.options.name !== 'undefined';
32
+ return telemetryProps;
33
+ }
34
+ commandAction(logger, args, cb) {
35
+ this
36
+ .getChatId(logger, args)
37
+ .then(chatId => this.getChatDetailsById(chatId))
38
+ .then((chat) => {
39
+ logger.log(chat);
40
+ cb();
41
+ }, (err) => this.handleRejectedODataJsonPromise(err, logger, cb));
42
+ }
43
+ options() {
44
+ const options = [
45
+ {
46
+ option: '-i, --id [id]'
47
+ },
48
+ {
49
+ option: '-p, --participants [participants]'
50
+ },
51
+ {
52
+ option: '-n, --name [name]'
53
+ }
54
+ ];
55
+ const parentOptions = super.options();
56
+ return options.concat(parentOptions);
57
+ }
58
+ validate(args) {
59
+ if (!args.options.id && !args.options.participants && !args.options.name) {
60
+ return 'Specify id or participants or name, one is required.';
61
+ }
62
+ let nrOfMutuallyExclusiveOptionsInUse = 0;
63
+ if (args.options.id) {
64
+ nrOfMutuallyExclusiveOptionsInUse++;
65
+ }
66
+ if (args.options.participants) {
67
+ nrOfMutuallyExclusiveOptionsInUse++;
68
+ }
69
+ if (args.options.name) {
70
+ nrOfMutuallyExclusiveOptionsInUse++;
71
+ }
72
+ if (nrOfMutuallyExclusiveOptionsInUse > 1) {
73
+ return 'Specify either id or participants or name, but not multiple.';
74
+ }
75
+ if (args.options.id && !validation_1.validation.isValidTeamsChatId(args.options.id)) {
76
+ return `${args.options.id} is not a valid Teams ChatId.`;
77
+ }
78
+ if (args.options.participants) {
79
+ const participants = chatUtil_1.chatUtil.convertParticipantStringToArray(args.options.participants);
80
+ if (!participants || participants.length === 0 || participants.some(e => !validation_1.validation.isValidUserPrincipalName(e))) {
81
+ return `${args.options.participants} contains one or more invalid email addresses.`;
82
+ }
83
+ }
84
+ return true;
85
+ }
86
+ getChatId(logger, args) {
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ if (args.options.id) {
89
+ return args.options.id;
90
+ }
91
+ return args.options.participants
92
+ ? this.getChatIdByParticipants(args.options.participants, logger)
93
+ : this.getChatIdByName(args.options.name, logger);
94
+ });
95
+ }
96
+ getChatDetailsById(id) {
97
+ return __awaiter(this, void 0, void 0, function* () {
98
+ const requestOptions = {
99
+ url: `${this.resource}/v1.0/chats/${encodeURIComponent(id)}`,
100
+ headers: {
101
+ accept: 'application/json;odata.metadata=none'
102
+ },
103
+ responseType: 'json'
104
+ };
105
+ return request_1.default.get(requestOptions);
106
+ });
107
+ }
108
+ getChatIdByParticipants(participantsString, logger) {
109
+ return __awaiter(this, void 0, void 0, function* () {
110
+ const participants = chatUtil_1.chatUtil.convertParticipantStringToArray(participantsString);
111
+ const currentUserEmail = accessToken_1.accessToken.getUserNameFromAccessToken(Auth_1.default.service.accessTokens[this.resource].accessToken).toLowerCase();
112
+ const existingChats = yield chatUtil_1.chatUtil.findExistingChatsByParticipants([currentUserEmail, ...participants], logger);
113
+ if (!existingChats || existingChats.length === 0) {
114
+ throw new Error('No chat conversation was found with these participants.');
115
+ }
116
+ if (existingChats.length === 1) {
117
+ return existingChats[0].id;
118
+ }
119
+ const disambiguationText = existingChats.map(c => {
120
+ return `- ${c.id}${c.topic && ' - '}${c.topic} - ${c.createdDateTime && new Date(c.createdDateTime).toLocaleString()}`;
121
+ }).join(os.EOL);
122
+ throw new Error(`Multiple chat conversations with these participants found. Please disambiguate:${os.EOL}${disambiguationText}`);
123
+ });
124
+ }
125
+ getChatIdByName(name, logger) {
126
+ return __awaiter(this, void 0, void 0, function* () {
127
+ const existingChats = yield chatUtil_1.chatUtil.findExistingGroupChatsByName(name, logger);
128
+ if (!existingChats || existingChats.length === 0) {
129
+ throw new Error('No chat conversation was found with this name.');
130
+ }
131
+ if (existingChats.length === 1) {
132
+ return existingChats[0].id;
133
+ }
134
+ const disambiguationText = existingChats.map(c => {
135
+ const memberstring = c.members.map(m => m.email).join(', ');
136
+ return `- ${c.id} - ${c.createdDateTime && new Date(c.createdDateTime).toLocaleString()} - ${memberstring}`;
137
+ }).join(os.EOL);
138
+ throw new Error(`Multiple chat conversations with this name found. Please disambiguate:${os.EOL}${disambiguationText}`);
139
+ });
140
+ }
141
+ }
142
+ module.exports = new TeamsChatGetCommand();
143
+ //# sourceMappingURL=chat-get.js.map
@@ -15,6 +15,7 @@ const request_1 = require("../../../../request");
15
15
  const utils_1 = require("../../../../utils");
16
16
  const GraphCommand_1 = require("../../../base/GraphCommand");
17
17
  const commands_1 = require("../../commands");
18
+ const chatUtil_1 = require("./chatUtil");
18
19
  class TeamsChatMessageSendCommand extends GraphCommand_1.default {
19
20
  get name() {
20
21
  return commands_1.default.CHAT_MESSAGE_SEND;
@@ -79,7 +80,7 @@ class TeamsChatMessageSendCommand extends GraphCommand_1.default {
79
80
  return `${args.options.chatId} is not a valid Teams ChatId.`;
80
81
  }
81
82
  if (args.options.userEmails) {
82
- const userEmails = this.convertCommaSeparatedListToArray(args.options.userEmails);
83
+ const userEmails = chatUtil_1.chatUtil.convertParticipantStringToArray(args.options.userEmails);
83
84
  if (!userEmails || userEmails.length === 0 || userEmails.some(e => !utils_1.validation.isValidUserPrincipalName(e))) {
84
85
  return `${args.options.userEmails} contains one or more invalid email addresses.`;
85
86
  }
@@ -98,9 +99,9 @@ class TeamsChatMessageSendCommand extends GraphCommand_1.default {
98
99
  }
99
100
  ensureChatIdByUserEmails(userEmailsOption, logger) {
100
101
  return __awaiter(this, void 0, void 0, function* () {
101
- const userEmails = this.convertCommaSeparatedListToArray(userEmailsOption);
102
+ const userEmails = chatUtil_1.chatUtil.convertParticipantStringToArray(userEmailsOption);
102
103
  const currentUserEmail = utils_1.accessToken.getUserNameFromAccessToken(Auth_1.default.service.accessTokens[this.resource].accessToken).toLowerCase();
103
- const existingChats = yield this.findExistingGroupChatsByMembers([currentUserEmail, ...userEmails], logger);
104
+ const existingChats = yield chatUtil_1.chatUtil.findExistingChatsByParticipants([currentUserEmail, ...userEmails], logger);
104
105
  if (!existingChats || existingChats.length === 0) {
105
106
  const chat = yield this.createConversation([currentUserEmail, ...userEmails]);
106
107
  return chat.id;
@@ -116,7 +117,7 @@ class TeamsChatMessageSendCommand extends GraphCommand_1.default {
116
117
  }
117
118
  getChatIdByName(chatName, logger) {
118
119
  return __awaiter(this, void 0, void 0, function* () {
119
- const existingChats = yield this.findExistingGroupChatsByName(chatName, logger);
120
+ const existingChats = yield chatUtil_1.chatUtil.findExistingGroupChatsByName(chatName, logger);
120
121
  if (!existingChats || existingChats.length === 0) {
121
122
  throw new Error('No chat conversation was found with this name.');
122
123
  }
@@ -186,32 +187,6 @@ class TeamsChatMessageSendCommand extends GraphCommand_1.default {
186
187
  yield request_1.default.post(requestOptions);
187
188
  });
188
189
  }
189
- findExistingGroupChatsByMembers(expectedMemberEmails, logger) {
190
- return __awaiter(this, void 0, void 0, function* () {
191
- const endpoint = `${this.resource}/v1.0/chats?$filter=chatType eq 'group'&$expand=members&$select=id,topic,createdDateTime,members`;
192
- const foundChats = [];
193
- const chats = yield utils_1.odata.getAllItems(endpoint, logger);
194
- for (const chat of chats) {
195
- const chatMembers = chat.members;
196
- if (chatMembers.length === expectedMemberEmails.length) {
197
- const chatMemberEmails = chatMembers.map(member => { var _a; return (_a = member.email) === null || _a === void 0 ? void 0 : _a.toLowerCase(); });
198
- if (expectedMemberEmails.every(email => chatMemberEmails.some(memberEmail => memberEmail === email))) {
199
- foundChats.push(chat);
200
- }
201
- }
202
- }
203
- return foundChats;
204
- });
205
- }
206
- findExistingGroupChatsByName(name, logger) {
207
- return __awaiter(this, void 0, void 0, function* () {
208
- const endpoint = `${this.resource}/v1.0/chats?$filter=topic eq '${encodeURIComponent(name)}'&$expand=members&$select=id,topic,createdDateTime,chatType`;
209
- return utils_1.odata.getAllItems(endpoint, logger);
210
- });
211
- }
212
- convertCommaSeparatedListToArray(userEmailsString) {
213
- return userEmailsString.toLowerCase().replace(/\s/g, '').split(',').filter(e => e && e !== '');
214
- }
215
190
  }
216
191
  module.exports = new TeamsChatMessageSendCommand();
217
192
  //# sourceMappingURL=chat-message-send.js.map
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.chatUtil = void 0;
13
+ const odata_1 = require("../../../../utils/odata");
14
+ exports.chatUtil = {
15
+ /**
16
+ * Finds existing Microsoft Teams chats by participants, using the Microsoft Graph
17
+ * @param expectedMemberEmails a string array of participant emailaddresses
18
+ * @param logger a logger to pipe into the graph request odata helper.
19
+ */
20
+ findExistingChatsByParticipants(expectedMemberEmails, logger) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ const chatType = expectedMemberEmails.length === 2 ? 'oneOnOne' : 'group';
23
+ const endpoint = `https://graph.microsoft.com/v1.0/chats?$filter=chatType eq '${chatType}'&$expand=members&$select=id,topic,createdDateTime,members`;
24
+ const foundChats = [];
25
+ const chats = yield odata_1.odata.getAllItems(endpoint, logger);
26
+ for (const chat of chats) {
27
+ const chatMembers = chat.members;
28
+ if (chatMembers.length === expectedMemberEmails.length) {
29
+ const chatMemberEmails = chatMembers.map(member => { var _a; return (_a = member.email) === null || _a === void 0 ? void 0 : _a.toLowerCase(); });
30
+ if (expectedMemberEmails.every(email => chatMemberEmails.some(memberEmail => memberEmail === email))) {
31
+ foundChats.push(chat);
32
+ }
33
+ }
34
+ }
35
+ return foundChats;
36
+ });
37
+ },
38
+ /**
39
+ * Finds existing Microsoft Teams chats by name, using the Microsoft Graph
40
+ * @param name the name of the chat conversation to find
41
+ * @param logger a logger to pipe into the graph request odata helper.
42
+ */
43
+ findExistingGroupChatsByName(name, logger) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ const endpoint = `https://graph.microsoft.com/v1.0/chats?$filter=topic eq '${encodeURIComponent(name).replace("'", "''")}'&$expand=members&$select=id,topic,createdDateTime,chatType`;
46
+ return odata_1.odata.getAllItems(endpoint, logger);
47
+ });
48
+ },
49
+ /**
50
+ * Converts a comma or space separated string into an array.
51
+ * @param value the string to convert
52
+ */
53
+ convertParticipantStringToArray(value) {
54
+ if (value.indexOf(',') === -1) {
55
+ return value.trim().toLowerCase().split(' ').filter(e => e && e !== '');
56
+ }
57
+ else {
58
+ return value.trim().toLowerCase().split(',').filter(e => e && e !== '');
59
+ }
60
+ }
61
+ };
62
+ //# sourceMappingURL=chatUtil.js.map
@@ -11,8 +11,10 @@ exports.default = {
11
11
  CHANNEL_ADD: `${prefix} channel add`,
12
12
  CHANNEL_GET: `${prefix} channel get`,
13
13
  CHANNEL_LIST: `${prefix} channel list`,
14
+ CHANNEL_MEMBERSHIP_LIST: `${prefix} channel membership list`,
14
15
  CHANNEL_REMOVE: `${prefix} channel remove`,
15
16
  CHANNEL_SET: `${prefix} channel set`,
17
+ CHAT_GET: `${prefix} chat get`,
16
18
  CHAT_LIST: `${prefix} chat list`,
17
19
  CHAT_MEMBER_LIST: `${prefix} chat member list`,
18
20
  CHAT_MESSAGE_LIST: `${prefix} chat message list`,
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./accessToken"), exports);
18
18
  __exportStar(require("./formatting"), exports);
19
19
  __exportStar(require("./fsUtil"), exports);
20
+ __exportStar(require("./md"), exports);
20
21
  __exportStar(require("./odata"), exports);
21
22
  __exportStar(require("./packageManager"), exports);
22
23
  __exportStar(require("./sinonUtil"), exports);
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.md = void 0;
4
+ const fs = require("fs");
5
+ const os_1 = require("os");
6
+ const path = require("path");
7
+ function convertTitle(md) {
8
+ return md.replace(/^#\s+(.*)/gm, (match, title) => {
9
+ return title.toLocaleUpperCase() + os_1.EOL + Array(title.length + 1).join('=');
10
+ });
11
+ }
12
+ function convertHeadings(md) {
13
+ return md.replace(/^(#+)\s+(.*)/gm, (match, level, content) => {
14
+ return `${os_1.EOL}${content.toLocaleUpperCase()}`;
15
+ });
16
+ }
17
+ function convertAdmonitions(md) {
18
+ const regex = new RegExp('^!!!\\s(.*)' + os_1.EOL + '\\s+', 'gm');
19
+ return md.replace(regex, (match, content) => {
20
+ return content.toLocaleUpperCase() + os_1.EOL + os_1.EOL;
21
+ });
22
+ }
23
+ function includeContent(md, rootFolder) {
24
+ return md.replace(/^--8<-- "([^"]+)"/gm, (match, filePath) => {
25
+ return fs.readFileSync(path.join(rootFolder, filePath), 'utf8');
26
+ });
27
+ }
28
+ function convertDd(md) {
29
+ return md.replace(/^:\s(.*)/gm, (match, content) => {
30
+ return ` ${content}`;
31
+ });
32
+ }
33
+ function convertHyperlinks(md) {
34
+ return md.replace(/\[([^\]]+)\]\(([^\)]+)\)/gm, (match, label, url) => {
35
+ // if the link is the same as the content, return just the link
36
+ if (label === url) {
37
+ return url;
38
+ }
39
+ // if the link is relative, remove it because there's no way to open it
40
+ // from the terminal anyway. In the future, we could convert it to the
41
+ // actual link of the docs.
42
+ if (!url.startsWith('http:') && !url.startsWith('https:')) {
43
+ return label;
44
+ }
45
+ return `${label} (${url})`;
46
+ });
47
+ }
48
+ function convertCodeFences(md) {
49
+ const regex = new RegExp('^```.*?' + os_1.EOL + '(.*?)```' + os_1.EOL, 'gms');
50
+ return md.replace(regex, (match, code) => {
51
+ return ` ${code}${os_1.EOL}`;
52
+ });
53
+ }
54
+ function removeInlineMarkup(md) {
55
+ // from https://stackoverflow.com/a/70064453
56
+ return md.replace(/(?<marks>[`]|\*{1,3}|_{1,3}|~{2})(?<inmarks>.*?)\1/g, '$<inmarks>$<link_text>');
57
+ }
58
+ function removeTooManyEmptyLines(md) {
59
+ const regex = new RegExp('(' + os_1.EOL + '){4,}', 'g');
60
+ return md.replace(regex, Array(4).join(os_1.EOL));
61
+ }
62
+ const convertFunctions = [
63
+ convertTitle,
64
+ convertHeadings,
65
+ convertAdmonitions,
66
+ convertDd,
67
+ convertHyperlinks,
68
+ convertCodeFences,
69
+ removeInlineMarkup,
70
+ removeTooManyEmptyLines
71
+ ];
72
+ exports.md = {
73
+ md2plain(md, rootFolderDocs) {
74
+ md = includeContent(md, rootFolderDocs);
75
+ convertFunctions.forEach(convert => {
76
+ md = convert(md);
77
+ });
78
+ return md;
79
+ }
80
+ };
81
+ //# sourceMappingURL=md.js.map