@pnp/cli-microsoft365 6.10.0-beta.6bf4ff9 → 6.10.0-beta.9aa530d

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.
Files changed (72) hide show
  1. package/dist/m365/booking/commands/business/business-get.js +14 -15
  2. package/dist/m365/search/commands/externalconnection/externalconnection-remove.js +35 -34
  3. package/dist/m365/spfx/commands/project/project-externalize/rules/DynamicRule.js +59 -51
  4. package/dist/m365/spo/commands/folder/folder-remove.js +30 -28
  5. package/dist/m365/spo/commands/list/list-roleassignment-add.js +9 -47
  6. package/dist/m365/spo/commands/tenant/tenant-appcatalog-add.js +12 -15
  7. package/dist/m365/spo/commands/tenant/tenant-applicationcustomizer-set.js +80 -2
  8. package/dist/m365/spo/commands/tenant/tenant-recyclebinitem-remove.js +48 -48
  9. package/dist/m365/teams/commands/chat/chat-get.js +4 -4
  10. package/dist/m365/teams/commands/chat/chat-message-send.js +4 -4
  11. package/dist/utils/spo.js +74 -0
  12. package/docs/docs/cmd/spo/site/site-add.mdx +35 -0
  13. package/docs/docs/cmd/spo/site/site-appcatalog-add.mdx +5 -1
  14. package/docs/docs/cmd/spo/site/site-appcatalog-list.mdx +14 -0
  15. package/docs/docs/cmd/spo/site/site-appcatalog-remove.mdx +4 -0
  16. package/docs/docs/cmd/spo/site/site-apppermission-add.mdx +68 -0
  17. package/docs/docs/cmd/spo/site/site-apppermission-get.mdx +55 -0
  18. package/docs/docs/cmd/spo/site/site-apppermission-list.mdx +55 -0
  19. package/docs/docs/cmd/spo/site/site-apppermission-remove.mdx +4 -0
  20. package/docs/docs/cmd/spo/site/site-apppermission-set.mdx +66 -0
  21. package/docs/docs/cmd/spo/site/site-chrome-set.mdx +4 -0
  22. package/docs/docs/cmd/spo/site/site-ensure.mdx +70 -0
  23. package/docs/docs/cmd/spo/site/site-get.mdx +179 -0
  24. package/docs/docs/cmd/spo/site/site-groupify.mdx +54 -0
  25. package/docs/docs/cmd/spo/site/site-hubsite-connect.mdx +4 -0
  26. package/docs/docs/cmd/spo/site/site-hubsite-disconnect.mdx +4 -0
  27. package/docs/docs/cmd/spo/site/site-hubsite-theme-sync.mdx +5 -1
  28. package/docs/docs/cmd/spo/site/site-inplacerecordsmanagement-set.mdx +4 -0
  29. package/docs/docs/cmd/spo/site/site-list.mdx +303 -0
  30. package/docs/docs/cmd/spo/site/site-recyclebinitem-list.mdx +80 -0
  31. package/docs/docs/cmd/spo/site/site-recyclebinitem-restore.mdx +4 -0
  32. package/docs/docs/cmd/spo/site/site-remove.mdx +4 -0
  33. package/docs/docs/cmd/spo/site/site-rename.mdx +92 -0
  34. package/docs/docs/cmd/spo/site/site-set.mdx +4 -0
  35. package/docs/docs/cmd/spo/sitedesign/sitedesign-add.mdx +116 -0
  36. package/docs/docs/cmd/spo/sitedesign/sitedesign-apply.mdx +125 -0
  37. package/docs/docs/cmd/spo/sitedesign/sitedesign-get.mdx +117 -0
  38. package/docs/docs/cmd/spo/sitedesign/sitedesign-list.mdx +94 -0
  39. package/docs/docs/cmd/spo/sitedesign/sitedesign-remove.mdx +4 -0
  40. package/docs/docs/cmd/spo/sitedesign/sitedesign-rights-grant.mdx +4 -0
  41. package/docs/docs/cmd/spo/sitedesign/sitedesign-rights-list.mdx +54 -0
  42. package/docs/docs/cmd/spo/sitedesign/sitedesign-rights-revoke.mdx +4 -0
  43. package/docs/docs/cmd/spo/sitedesign/sitedesign-run-list.mdx +66 -0
  44. package/docs/docs/cmd/spo/sitedesign/sitedesign-run-status-get.mdx +65 -0
  45. package/docs/docs/cmd/spo/sitedesign/sitedesign-set.mdx +117 -0
  46. package/docs/docs/cmd/spo/sitedesign/sitedesign-task-get.mdx +61 -0
  47. package/docs/docs/cmd/spo/sitedesign/sitedesign-task-list.mdx +60 -0
  48. package/docs/docs/cmd/spo/sitedesign/sitedesign-task-remove.mdx +4 -0
  49. package/docs/docs/cmd/spo/sitescript/sitescript-add.mdx +75 -0
  50. package/docs/docs/cmd/spo/sitescript/sitescript-get.mdx +62 -0
  51. package/docs/docs/cmd/spo/sitescript/sitescript-list.mdx +60 -0
  52. package/docs/docs/cmd/spo/sitescript/sitescript-remove.mdx +4 -0
  53. package/docs/docs/cmd/spo/sitescript/sitescript-set.mdx +63 -0
  54. package/docs/docs/cmd/spo/storageentity/storageentity-get.mdx +53 -0
  55. package/docs/docs/cmd/spo/storageentity/storageentity-list.mdx +54 -0
  56. package/docs/docs/cmd/spo/storageentity/storageentity-remove.mdx +4 -0
  57. package/docs/docs/cmd/spo/storageentity/storageentity-set.mdx +4 -0
  58. package/docs/docs/cmd/spo/tenant/tenant-appcatalog-add.mdx +4 -0
  59. package/docs/docs/cmd/spo/tenant/tenant-appcatalogurl-get.mdx +35 -0
  60. package/docs/docs/cmd/spo/tenant/tenant-applicationcustomizer-set.mdx +12 -3
  61. package/docs/docs/cmd/spo/tenant/tenant-recyclebinitem-list.mdx +67 -0
  62. package/docs/docs/cmd/spo/tenant/tenant-recyclebinitem-remove.mdx +4 -0
  63. package/docs/docs/cmd/spo/tenant/tenant-recyclebinitem-restore.mdx +50 -0
  64. package/docs/docs/cmd/spo/tenant/tenant-settings-list.mdx +729 -0
  65. package/docs/docs/cmd/spo/tenant/tenant-settings-set.mdx +5 -0
  66. package/docs/docs/cmd/spo/theme/theme-apply.mdx +35 -0
  67. package/docs/docs/cmd/spo/theme/theme-get.mdx +74 -0
  68. package/docs/docs/cmd/spo/theme/theme-list.mdx +52 -0
  69. package/docs/docs/cmd/spo/theme/theme-remove.mdx +4 -0
  70. package/docs/docs/cmd/spo/theme/theme-set.mdx +4 -0
  71. package/npm-shrinkwrap.json +212 -212
  72. package/package.json +10 -10
@@ -56,26 +56,25 @@ class BookingBusinessGetCommand extends GraphCommand_1.default {
56
56
  });
57
57
  }
58
58
  getBusinessId(options) {
59
- if (options.id) {
60
- return Promise.resolve(options.id);
61
- }
62
- const requestOptions = {
63
- url: `${this.resource}/v1.0/solutions/bookingBusinesses`,
64
- headers: {
65
- accept: 'application/json;odata.metadata=none'
66
- },
67
- responseType: 'json'
68
- };
69
- return request_1.default
70
- .get(requestOptions)
71
- .then((response) => {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ if (options.id) {
61
+ return options.id;
62
+ }
63
+ const requestOptions = {
64
+ url: `${this.resource}/v1.0/solutions/bookingBusinesses`,
65
+ headers: {
66
+ accept: 'application/json;odata.metadata=none'
67
+ },
68
+ responseType: 'json'
69
+ };
70
+ const response = yield request_1.default.get(requestOptions);
72
71
  const name = options.name;
73
72
  const bookingBusinesses = response.value.filter(val => { var _a; return ((_a = val.displayName) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase()) === name.toLocaleLowerCase(); });
74
73
  if (!bookingBusinesses.length) {
75
- return Promise.reject(`The specified business with name ${options.name} does not exist.`);
74
+ throw `The specified business with name ${options.name} does not exist.`;
76
75
  }
77
76
  if (bookingBusinesses.length > 1) {
78
- return Promise.reject(`Multiple businesses with name ${options.name} found. Please disambiguate: ${bookingBusinesses.map(x => x.id).join(', ')}`);
77
+ throw `Multiple businesses with name ${options.name} found. Please disambiguate: ${bookingBusinesses.map(x => x.id).join(', ')}`;
79
78
  }
80
79
  return bookingBusinesses[0].id;
81
80
  });
@@ -35,48 +35,31 @@ class SearchExternalConnectionRemoveCommand extends GraphCommand_1.default {
35
35
  __classPrivateFieldGet(this, _SearchExternalConnectionRemoveCommand_instances, "m", _SearchExternalConnectionRemoveCommand_initOptionSets).call(this);
36
36
  }
37
37
  getExternalConnectionId(args) {
38
- if (args.options.id) {
39
- return Promise.resolve(args.options.id);
40
- }
41
- const requestOptions = {
42
- url: `${this.resource}/v1.0/external/connections?$filter=name eq '${formatting_1.formatting.encodeQueryParameter(args.options.name)}'&$select=id`,
43
- headers: {
44
- accept: 'application/json;odata.metadata=none'
45
- },
46
- responseType: 'json'
47
- };
48
- return request_1.default
49
- .get(requestOptions)
50
- .then((res) => {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ if (args.options.id) {
40
+ return args.options.id;
41
+ }
42
+ const requestOptions = {
43
+ url: `${this.resource}/v1.0/external/connections?$filter=name eq '${formatting_1.formatting.encodeQueryParameter(args.options.name)}'&$select=id`,
44
+ headers: {
45
+ accept: 'application/json;odata.metadata=none'
46
+ },
47
+ responseType: 'json'
48
+ };
49
+ const res = yield request_1.default.get(requestOptions);
51
50
  if (res.value.length === 1) {
52
- return Promise.resolve(res.value[0].id);
51
+ return res.value[0].id;
53
52
  }
54
53
  if (res.value.length === 0) {
55
- return Promise.reject(`The specified connection does not exist in Microsoft Search`);
54
+ throw `The specified connection does not exist in Microsoft Search`;
56
55
  }
57
- return Promise.reject(`Multiple external connections with name ${args.options.name} found. Please disambiguate (IDs): ${res.value.map(x => x.id).join(', ')}`);
56
+ throw `Multiple external connections with name ${args.options.name} found. Please disambiguate (IDs): ${res.value.map(x => x.id).join(', ')}`;
58
57
  });
59
58
  }
60
59
  commandAction(logger, args) {
61
60
  return __awaiter(this, void 0, void 0, function* () {
62
- const removeExternalConnection = () => __awaiter(this, void 0, void 0, function* () {
63
- try {
64
- const externalConnectionId = yield this.getExternalConnectionId(args);
65
- const requestOptions = {
66
- url: `${this.resource}/v1.0/external/connections/${formatting_1.formatting.encodeQueryParameter(externalConnectionId)}`,
67
- headers: {
68
- accept: 'application/json;odata.metadata=none'
69
- },
70
- responseType: 'json'
71
- };
72
- yield request_1.default.delete(requestOptions);
73
- }
74
- catch (err) {
75
- this.handleRejectedODataJsonPromise(err);
76
- }
77
- });
78
61
  if (args.options.confirm) {
79
- yield removeExternalConnection();
62
+ yield this.removeExternalConnection(args);
80
63
  }
81
64
  else {
82
65
  const result = yield Cli_1.Cli.prompt({
@@ -86,11 +69,29 @@ class SearchExternalConnectionRemoveCommand extends GraphCommand_1.default {
86
69
  message: `Are you sure you want to remove the external connection '${args.options.id || args.options.name}'?`
87
70
  });
88
71
  if (result.continue) {
89
- yield removeExternalConnection();
72
+ yield this.removeExternalConnection(args);
90
73
  }
91
74
  }
92
75
  });
93
76
  }
77
+ removeExternalConnection(args) {
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ try {
80
+ const externalConnectionId = yield this.getExternalConnectionId(args);
81
+ const requestOptions = {
82
+ url: `${this.resource}/v1.0/external/connections/${formatting_1.formatting.encodeQueryParameter(externalConnectionId)}`,
83
+ headers: {
84
+ accept: 'application/json;odata.metadata=none'
85
+ },
86
+ responseType: 'json'
87
+ };
88
+ yield request_1.default.delete(requestOptions);
89
+ }
90
+ catch (err) {
91
+ this.handleRejectedODataJsonPromise(err);
92
+ }
93
+ });
94
+ }
94
95
  }
95
96
  _SearchExternalConnectionRemoveCommand_instances = new WeakSet(), _SearchExternalConnectionRemoveCommand_initTelemetry = function _SearchExternalConnectionRemoveCommand_initTelemetry() {
96
97
  this.telemetry.push((args) => {
@@ -1,4 +1,13 @@
1
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
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.DynamicRule = void 0;
4
13
  const fs = require("fs");
@@ -12,36 +21,32 @@ class DynamicRule extends BasicDependencyRule_1.BasicDependencyRule {
12
21
  this.fileVariationSuffixes = ['.min', '.bundle', '-min', '.bundle.min'];
13
22
  }
14
23
  visit(project) {
15
- if (!project.packageJson ||
16
- !project.packageJson.dependencies) {
17
- return Promise.resolve({ entries: [], suggestions: [] });
18
- }
19
- const validPackageNames = Object.getOwnPropertyNames(project.packageJson.dependencies)
20
- .filter(x => this.restrictedNamespaces.map(y => x.indexOf(y) === -1).reduce((y, z) => y && z))
21
- .filter(x => this.restrictedModules.indexOf(x) === -1);
22
- return Promise
23
- .all(validPackageNames.map((x) => this.getExternalEntryForPackage(x, project)))
24
- .then((res) => {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ if (!project.packageJson || !project.packageJson.dependencies) {
26
+ return { entries: [], suggestions: [] };
27
+ }
28
+ const validPackageNames = Object.getOwnPropertyNames(project.packageJson.dependencies)
29
+ .filter(x => this.restrictedNamespaces.map(y => x.indexOf(y) === -1).reduce((y, z) => y && z))
30
+ .filter(x => this.restrictedModules.indexOf(x) === -1);
31
+ const res = yield Promise.all(validPackageNames.map((x) => this.getExternalEntryForPackage(x, project)));
25
32
  return {
26
- entries: res
27
- .filter(x => x !== undefined)
28
- .map(x => x),
33
+ entries: res.filter(x => x !== undefined),
29
34
  suggestions: []
30
35
  };
31
36
  });
32
37
  }
33
38
  getExternalEntryForPackage(packageName, project) {
34
- const version = project.packageJson.dependencies[packageName];
35
- const filesPaths = this.getFilePath(packageName).map(x => this.cleanFilePath(x));
36
- if (!version || filesPaths.length === 0) {
37
- return Promise.resolve(undefined);
38
- }
39
- const filesPathsVariations = filesPaths
40
- .map(x => this.fileVariationSuffixes.map(y => x.indexOf(y) === -1 ? x.replace('.js', `${y}.js`) : x))
41
- .reduce((x, y) => [...x, ...y]);
42
- const pathsAndVariations = [...filesPaths, ...filesPathsVariations];
43
- return Promise.all(pathsAndVariations.map(x => this.getExternalEntryForFilePath(x, packageName, version)))
44
- .then((externalizeEntryCandidates) => {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ const version = project.packageJson.dependencies[packageName];
41
+ const filesPaths = this.getFilePath(packageName).map(x => this.cleanFilePath(x));
42
+ if (!version || filesPaths.length === 0) {
43
+ return undefined;
44
+ }
45
+ const filesPathsVariations = filesPaths
46
+ .map(x => this.fileVariationSuffixes.map(y => x.indexOf(y) === -1 ? x.replace('.js', `${y}.js`) : x))
47
+ .reduce((x, y) => [...x, ...y]);
48
+ const pathsAndVariations = [...filesPaths, ...filesPathsVariations];
49
+ const externalizeEntryCandidates = yield Promise.all(pathsAndVariations.map(x => this.getExternalEntryForFilePath(x, packageName, version)));
45
50
  const dExternalizeEntryCandidates = externalizeEntryCandidates.filter(x => x !== undefined);
46
51
  const minifiedModule = dExternalizeEntryCandidates.find(x => !x.globalName && this.pathContainsMinifySuffix(x.path));
47
52
  const minifiedNonModule = dExternalizeEntryCandidates.find(x => x.globalName && this.pathContainsMinifySuffix(x.path));
@@ -57,31 +62,29 @@ class DynamicRule extends BasicDependencyRule_1.BasicDependencyRule {
57
62
  .filter(y => y > -1).length > 0;
58
63
  }
59
64
  getExternalEntryForFilePath(filePath, packageName, version) {
60
- const url = this.getFileUrl(packageName, version, filePath);
61
- return this
62
- .testUrl(url)
63
- .then((testResult) => {
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ const url = this.getFileUrl(packageName, version, filePath);
67
+ const testResult = yield this.testUrl(url);
64
68
  if (!testResult) {
65
- return Promise.resolve(undefined);
69
+ return undefined;
70
+ }
71
+ const moduleInfo = yield this.getModuleType(url);
72
+ if (moduleInfo.scriptType === 'CommonJs') {
73
+ return undefined; //browsers don't support those module types without an additional library
74
+ }
75
+ else if (moduleInfo.scriptType === 'ES2015' || moduleInfo.scriptType === 'AMD') {
76
+ return {
77
+ key: packageName,
78
+ path: url
79
+ };
80
+ }
81
+ else { //TODO for non-module and UMD we should technically add dependencies as well
82
+ return {
83
+ key: packageName,
84
+ path: url,
85
+ globalName: moduleInfo.exports && moduleInfo.exports.length > 0 ? moduleInfo.exports[0] : packageName // examples where this is not good https://unpkg.com/@pnp/polyfill-ie11@^1.0.2/dist/index.js https://unpkg.com/moment-timezone@^0.5.27/builds/moment-timezone-with-data.js
86
+ };
66
87
  }
67
- return this.getModuleType(url).then((moduleInfo) => {
68
- if (moduleInfo.scriptType === 'CommonJs') {
69
- return Promise.resolve(undefined); //browsers don't support those module types without an additional library
70
- }
71
- else if (moduleInfo.scriptType === 'ES2015' || moduleInfo.scriptType === 'AMD') {
72
- return {
73
- key: packageName,
74
- path: url
75
- };
76
- }
77
- else { //TODO for non-module and UMD we should technically add dependencies as well
78
- return {
79
- key: packageName,
80
- path: url,
81
- globalName: moduleInfo.exports && moduleInfo.exports.length > 0 ? moduleInfo.exports[0] : packageName // examples where this is not good https://unpkg.com/@pnp/polyfill-ie11@^1.0.2/dist/index.js https://unpkg.com/moment-timezone@^0.5.27/builds/moment-timezone-with-data.js
82
- };
83
- }
84
- });
85
88
  });
86
89
  }
87
90
  getModuleType(url) {
@@ -101,10 +104,15 @@ class DynamicRule extends BasicDependencyRule_1.BasicDependencyRule {
101
104
  return `https://unpkg.com/${packageName}@${version}/${filePath}`;
102
105
  }
103
106
  testUrl(url) {
104
- return request_1.default
105
- .head({ url: url, headers: { 'x-anonymous': 'true' } })
106
- .then(() => true)
107
- .catch(() => false);
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ try {
109
+ yield request_1.default.head({ url: url, headers: { 'x-anonymous': 'true' } });
110
+ return true;
111
+ }
112
+ catch (_a) {
113
+ return false;
114
+ }
115
+ });
108
116
  }
109
117
  getFilePath(packageName) {
110
118
  const packageJsonFilePath = `node_modules/${packageName}/package.json`;
@@ -38,34 +38,8 @@ class SpoFolderRemoveCommand extends SpoCommand_1.default {
38
38
  }
39
39
  commandAction(logger, args) {
40
40
  return __awaiter(this, void 0, void 0, function* () {
41
- const removeFolder = () => __awaiter(this, void 0, void 0, function* () {
42
- if (this.verbose) {
43
- logger.logToStderr(`Removing folder in site at ${args.options.webUrl}...`);
44
- }
45
- const serverRelativeUrl = urlUtil_1.urlUtil.getServerRelativePath(args.options.webUrl, args.options.url);
46
- let requestUrl = `${args.options.webUrl}/_api/web/GetFolderByServerRelativeUrl('${formatting_1.formatting.encodeQueryParameter(serverRelativeUrl)}')`;
47
- if (args.options.recycle) {
48
- requestUrl += `/recycle()`;
49
- }
50
- const requestOptions = {
51
- url: requestUrl,
52
- method: 'POST',
53
- headers: {
54
- 'X-HTTP-Method': 'DELETE',
55
- 'If-Match': '*',
56
- 'accept': 'application/json;odata=nometadata'
57
- },
58
- responseType: 'json'
59
- };
60
- try {
61
- yield request_1.default.post(requestOptions);
62
- }
63
- catch (err) {
64
- this.handleRejectedODataJsonPromise(err);
65
- }
66
- });
67
41
  if (args.options.confirm) {
68
- yield removeFolder();
42
+ yield this.removeFolder(logger, args.options);
69
43
  }
70
44
  else {
71
45
  const result = yield Cli_1.Cli.prompt({
@@ -75,11 +49,39 @@ class SpoFolderRemoveCommand extends SpoCommand_1.default {
75
49
  message: `Are you sure you want to ${args.options.recycle ? "recycle" : "remove"} the folder ${args.options.url} located in site ${args.options.webUrl}?`
76
50
  });
77
51
  if (result.continue) {
78
- yield removeFolder();
52
+ yield this.removeFolder(logger, args.options);
79
53
  }
80
54
  }
81
55
  });
82
56
  }
57
+ removeFolder(logger, options) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ if (this.verbose) {
60
+ logger.logToStderr(`Removing folder in site at ${options.webUrl}...`);
61
+ }
62
+ const serverRelativeUrl = urlUtil_1.urlUtil.getServerRelativePath(options.webUrl, options.url);
63
+ let requestUrl = `${options.webUrl}/_api/web/GetFolderByServerRelativeUrl('${formatting_1.formatting.encodeQueryParameter(serverRelativeUrl)}')`;
64
+ if (options.recycle) {
65
+ requestUrl += `/recycle()`;
66
+ }
67
+ const requestOptions = {
68
+ url: requestUrl,
69
+ method: 'POST',
70
+ headers: {
71
+ 'X-HTTP-Method': 'DELETE',
72
+ 'If-Match': '*',
73
+ 'accept': 'application/json;odata=nometadata'
74
+ },
75
+ responseType: 'json'
76
+ };
77
+ try {
78
+ yield request_1.default.post(requestOptions);
79
+ }
80
+ catch (err) {
81
+ this.handleRejectedODataJsonPromise(err);
82
+ }
83
+ });
84
+ }
83
85
  }
84
86
  _SpoFolderRemoveCommand_instances = new WeakSet(), _SpoFolderRemoveCommand_initTelemetry = function _SpoFolderRemoveCommand_initTelemetry() {
85
87
  this.telemetry.push((args) => {
@@ -15,16 +15,13 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
15
15
  };
16
16
  var _SpoListRoleAssignmentAddCommand_instances, _SpoListRoleAssignmentAddCommand_initTelemetry, _SpoListRoleAssignmentAddCommand_initOptions, _SpoListRoleAssignmentAddCommand_initValidators, _SpoListRoleAssignmentAddCommand_initOptionSets;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- const Cli_1 = require("../../../../cli/Cli");
19
18
  const request_1 = require("../../../../request");
20
19
  const formatting_1 = require("../../../../utils/formatting");
21
20
  const urlUtil_1 = require("../../../../utils/urlUtil");
22
21
  const validation_1 = require("../../../../utils/validation");
23
22
  const SpoCommand_1 = require("../../../base/SpoCommand");
24
23
  const commands_1 = require("../../commands");
25
- const SpoUserGetCommand = require("../user/user-get");
26
- const SpoGroupGetCommand = require("../group/group-get");
27
- const SpoRoleDefinitionListCommand = require("../roledefinition/roledefinition-list");
24
+ const spo_1 = require("../../../../utils/spo");
28
25
  class SpoListRoleAssignmentAddCommand extends SpoCommand_1.default {
29
26
  get name() {
30
27
  return commands_1.default.LIST_ROLEASSIGNMENT_ADD;
@@ -57,13 +54,15 @@ class SpoListRoleAssignmentAddCommand extends SpoCommand_1.default {
57
54
  const listServerRelativeUrl = urlUtil_1.urlUtil.getServerRelativePath(args.options.webUrl, args.options.listUrl);
58
55
  requestUrl += `GetList('${formatting_1.formatting.encodeQueryParameter(listServerRelativeUrl)}')/`;
59
56
  }
60
- args.options.roleDefinitionId = yield this.getRoleDefinitionId(args.options);
57
+ args.options.roleDefinitionId = yield this.getRoleDefinitionId(args.options, logger);
61
58
  if (args.options.upn) {
62
- args.options.principalId = yield this.getUserPrincipalId(args.options);
59
+ const user = yield spo_1.spo.getUserByEmail(args.options.webUrl, args.options.upn, logger, this.verbose);
60
+ args.options.principalId = user.Id;
63
61
  yield this.addRoleAssignment(requestUrl, logger, args.options);
64
62
  }
65
63
  else if (args.options.groupName) {
66
- args.options.principalId = yield this.getGroupPrincipalId(args.options);
64
+ const group = yield spo_1.spo.getGroupByName(args.options.webUrl, args.options.groupName, logger, this.verbose);
65
+ args.options.principalId = group.Id;
67
66
  yield this.addRoleAssignment(requestUrl, logger, args.options);
68
67
  }
69
68
  else {
@@ -89,50 +88,13 @@ class SpoListRoleAssignmentAddCommand extends SpoCommand_1.default {
89
88
  return request_1.default.post(requestOptions);
90
89
  });
91
90
  }
92
- getRoleDefinitionId(options) {
91
+ getRoleDefinitionId(options, logger) {
93
92
  return __awaiter(this, void 0, void 0, function* () {
94
93
  if (!options.roleDefinitionName) {
95
94
  return options.roleDefinitionId;
96
95
  }
97
- const roleDefinitionListCommandOptions = {
98
- webUrl: options.webUrl,
99
- output: 'json',
100
- debug: this.debug,
101
- verbose: this.verbose
102
- };
103
- const output = yield Cli_1.Cli.executeCommandWithOutput(SpoRoleDefinitionListCommand, { options: Object.assign(Object.assign({}, roleDefinitionListCommandOptions), { _: [] }) });
104
- const getRoleDefinitionListOutput = JSON.parse(output.stdout);
105
- const roleDefinitionId = getRoleDefinitionListOutput.find((role) => role.Name === options.roleDefinitionName).Id;
106
- return roleDefinitionId;
107
- });
108
- }
109
- getGroupPrincipalId(options) {
110
- return __awaiter(this, void 0, void 0, function* () {
111
- const groupGetCommandOptions = {
112
- webUrl: options.webUrl,
113
- name: options.groupName,
114
- output: 'json',
115
- debug: this.debug,
116
- verbose: this.verbose
117
- };
118
- const output = yield Cli_1.Cli.executeCommandWithOutput(SpoGroupGetCommand, { options: Object.assign(Object.assign({}, groupGetCommandOptions), { _: [] }) });
119
- const getGroupOutput = JSON.parse(output.stdout);
120
- return getGroupOutput.Id;
121
- });
122
- }
123
- getUserPrincipalId(options) {
124
- return __awaiter(this, void 0, void 0, function* () {
125
- const userGetCommandOptions = {
126
- webUrl: options.webUrl,
127
- email: options.upn,
128
- id: undefined,
129
- output: 'json',
130
- debug: this.debug,
131
- verbose: this.verbose
132
- };
133
- const output = yield Cli_1.Cli.executeCommandWithOutput(SpoUserGetCommand, { options: Object.assign(Object.assign({}, userGetCommandOptions), { _: [] }) });
134
- const getUserOutput = JSON.parse(output.stdout);
135
- return getUserOutput.Id;
96
+ const roleDefinition = yield spo_1.spo.getRoleDefinitionByName(options.webUrl, options.roleDefinitionName, logger, this.verbose);
97
+ return roleDefinition.Id;
136
98
  });
137
99
  }
138
100
  }
@@ -62,7 +62,8 @@ class SpoTenantAppCatalogAddCommand extends SpoCommand_1.default {
62
62
  });
63
63
  }
64
64
  ensureNoExistingSite(url, force, logger) {
65
- return new Promise((resolve, reject) => {
65
+ var _a, _b;
66
+ return __awaiter(this, void 0, void 0, function* () {
66
67
  if (this.verbose) {
67
68
  logger.logToStderr(`Checking if site ${url} exists...`);
68
69
  }
@@ -74,14 +75,13 @@ class SpoTenantAppCatalogAddCommand extends SpoCommand_1.default {
74
75
  _: []
75
76
  }
76
77
  };
77
- Cli_1.Cli
78
- .executeCommandWithOutput(spoSiteGetCommand, siteGetOptions)
79
- .then(() => {
78
+ try {
79
+ yield Cli_1.Cli.executeCommandWithOutput(spoSiteGetCommand, siteGetOptions);
80
80
  if (this.verbose) {
81
81
  logger.logToStderr(`Found site ${url}`);
82
82
  }
83
83
  if (!force) {
84
- return reject(new Command_1.CommandError(`Another site exists at ${url}`));
84
+ throw new Command_1.CommandError(`Another site exists at ${url}`);
85
85
  }
86
86
  if (this.verbose) {
87
87
  logger.logToStderr(`Deleting site ${url}...`);
@@ -94,20 +94,17 @@ class SpoTenantAppCatalogAddCommand extends SpoCommand_1.default {
94
94
  verbose: this.verbose,
95
95
  debug: this.debug
96
96
  };
97
- Cli_1.Cli
98
- .executeCommand(spoSiteRemoveCommand, { options: Object.assign(Object.assign({}, siteRemoveOptions), { _: [] }) })
99
- .then(() => resolve(), (err) => reject(err));
100
- }, (err) => {
101
- if (err.error.message !== 'File Not Found.' && err.error.message !== '404 FILE NOT FOUND') {
102
- // some other error occurred
103
- return reject(err.error);
97
+ yield Cli_1.Cli.executeCommand(spoSiteRemoveCommand, { options: Object.assign(Object.assign({}, siteRemoveOptions), { _: [] }) });
98
+ }
99
+ catch (err) {
100
+ if (((_a = err.error) === null || _a === void 0 ? void 0 : _a.message) !== 'File not Found' && ((_b = err.error) === null || _b === void 0 ? void 0 : _b.message) !== '404 FILE NOT FOUND') {
101
+ throw err.error || err;
104
102
  }
105
103
  if (this.verbose) {
106
104
  logger.logToStderr(`No site found at ${url}`);
107
105
  }
108
- // site not found. continue
109
- resolve();
110
- });
106
+ // Site not found. Continue
107
+ }
111
108
  });
112
109
  }
113
110
  createAppCatalog(options, logger) {
@@ -23,6 +23,8 @@ const validation_1 = require("../../../../utils/validation");
23
23
  const SpoCommand_1 = require("../../../base/SpoCommand");
24
24
  const commands_1 = require("../../commands");
25
25
  const os = require("os");
26
+ const Cli_1 = require("../../../../cli/Cli");
27
+ const spoListItemListCommand = require("../listitem/listitem-list");
26
28
  const request_1 = require("../../../../request");
27
29
  class SpoTenantApplicationCustomizerSetCommand extends SpoCommand_1.default {
28
30
  get name() {
@@ -46,6 +48,20 @@ class SpoTenantApplicationCustomizerSetCommand extends SpoCommand_1.default {
46
48
  if (!appCatalogUrl) {
47
49
  throw 'No app catalog URL found';
48
50
  }
51
+ if (args.options.newClientSideComponentId !== undefined) {
52
+ const componentManifest = yield this.getComponentManifest(appCatalogUrl, args.options.newClientSideComponentId, logger);
53
+ const clientComponentManifest = JSON.parse(componentManifest.ClientComponentManifest);
54
+ if (clientComponentManifest.extensionType !== "ApplicationCustomizer") {
55
+ throw `The extension type of this component is not of type 'ApplicationCustomizer' but of type '${clientComponentManifest.extensionType}'`;
56
+ }
57
+ const solution = yield this.getSolutionFromAppCatalog(appCatalogUrl, componentManifest.SolutionId, logger);
58
+ if (!solution.ContainsTenantWideExtension) {
59
+ throw `The solution does not contain an extension that can be deployed to all sites. Make sure that you've entered the correct component Id.`;
60
+ }
61
+ else if (!solution.SkipFeatureDeployment) {
62
+ throw 'The solution has not been deployed to all sites. Make sure to deploy this solution to all sites.';
63
+ }
64
+ }
49
65
  const listServerRelativeUrl = urlUtil_1.urlUtil.getServerRelativePath(appCatalogUrl, '/lists/TenantWideExtensions');
50
66
  const listItemId = yield this.getListItemId(appCatalogUrl, args.options, listServerRelativeUrl, logger);
51
67
  yield this.updateTenantWideExtension(appCatalogUrl, args.options, listServerRelativeUrl, listItemId, logger);
@@ -72,9 +88,59 @@ class SpoTenantApplicationCustomizerSetCommand extends SpoCommand_1.default {
72
88
  return listItemInstances[0].Id;
73
89
  });
74
90
  }
91
+ getComponentManifest(appCatalogUrl, clientSideComponentId, logger) {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ if (this.verbose) {
94
+ logger.logToStderr('Retrieving component manifest item from the ComponentManifests list on the app catalog site so that we get the solution id');
95
+ }
96
+ const camlQuery = `<View><ViewFields><FieldRef Name='ClientComponentId'></FieldRef><FieldRef Name='SolutionId'></FieldRef><FieldRef Name='ClientComponentManifest'></FieldRef></ViewFields><Query><Where><Eq><FieldRef Name='ClientComponentId' /><Value Type='Guid'>${clientSideComponentId}</Value></Eq></Where></Query></View>`;
97
+ const commandOptions = {
98
+ webUrl: appCatalogUrl,
99
+ listUrl: `${urlUtil_1.urlUtil.getServerRelativeSiteUrl(appCatalogUrl)}/Lists/ComponentManifests`,
100
+ camlQuery: camlQuery,
101
+ verbose: this.verbose,
102
+ debug: this.debug,
103
+ output: 'json'
104
+ };
105
+ const output = yield Cli_1.Cli.executeCommandWithOutput(spoListItemListCommand, { options: Object.assign(Object.assign({}, commandOptions), { _: [] }) });
106
+ if (this.verbose) {
107
+ logger.logToStderr(output.stderr);
108
+ }
109
+ const outputParsed = JSON.parse(output.stdout);
110
+ if (outputParsed.length === 0) {
111
+ throw 'No component found with the specified clientSideComponentId found in the component manifest list. Make sure that the application is added to the application catalog';
112
+ }
113
+ return outputParsed[0];
114
+ });
115
+ }
116
+ getSolutionFromAppCatalog(appCatalogUrl, solutionId, logger) {
117
+ return __awaiter(this, void 0, void 0, function* () {
118
+ if (this.verbose) {
119
+ logger.logToStderr(`Retrieving solution with id ${solutionId} from the application catalog`);
120
+ }
121
+ const camlQuery = `<View><ViewFields><FieldRef Name='SkipFeatureDeployment'></FieldRef><FieldRef Name='ContainsTenantWideExtension'></FieldRef></ViewFields><Query><Where><Eq><FieldRef Name='AppProductID' /><Value Type='Guid'>${solutionId}</Value></Eq></Where></Query></View>`;
122
+ const commandOptions = {
123
+ webUrl: appCatalogUrl,
124
+ listUrl: `${urlUtil_1.urlUtil.getServerRelativeSiteUrl(appCatalogUrl)}/AppCatalog`,
125
+ camlQuery: camlQuery,
126
+ verbose: this.verbose,
127
+ debug: this.debug,
128
+ output: 'json'
129
+ };
130
+ const output = yield Cli_1.Cli.executeCommandWithOutput(spoListItemListCommand, { options: Object.assign(Object.assign({}, commandOptions), { _: [] }) });
131
+ if (this.verbose) {
132
+ logger.logToStderr(output.stderr);
133
+ }
134
+ const outputParsed = JSON.parse(output.stdout);
135
+ if (outputParsed.length === 0) {
136
+ throw `No component found with the solution id ${solutionId}. Make sure that the solution is available in the app catalog`;
137
+ }
138
+ return outputParsed[0];
139
+ });
140
+ }
75
141
  updateTenantWideExtension(appCatalogUrl, options, listServerRelativeUrl, itemId, logger) {
76
142
  return __awaiter(this, void 0, void 0, function* () {
77
- const { title, id, clientSideComponentId, newTitle, clientSideComponentProperties, webTemplate } = options;
143
+ const { title, id, clientSideComponentId, newTitle, newClientSideComponentId, clientSideComponentProperties, webTemplate } = options;
78
144
  if (this.verbose) {
79
145
  logger.logToStderr(`Updating tenant-wide application customizer: "${title || id || clientSideComponentId}"...`);
80
146
  }
@@ -85,6 +151,12 @@ class SpoTenantApplicationCustomizerSetCommand extends SpoCommand_1.default {
85
151
  FieldValue: newTitle
86
152
  });
87
153
  }
154
+ if (newClientSideComponentId !== undefined) {
155
+ formValues.push({
156
+ FieldName: 'TenantWideExtensionComponentId',
157
+ FieldValue: newClientSideComponentId
158
+ });
159
+ }
88
160
  if (clientSideComponentProperties !== undefined) {
89
161
  formValues.push({
90
162
  FieldName: 'TenantWideExtensionComponentProperties',
@@ -118,6 +190,7 @@ _SpoTenantApplicationCustomizerSetCommand_instances = new WeakSet(), _SpoTenantA
118
190
  id: typeof args.options.id !== 'undefined',
119
191
  clientSideComponentId: typeof args.options.clientSideComponentId !== 'undefined',
120
192
  newTitle: typeof args.options.newTitle !== 'undefined',
193
+ newClientSideComponentId: typeof args.options.newClientSideComponentId !== 'undefined',
121
194
  clientSideComponentProperties: typeof args.options.clientSideComponentProperties !== 'undefined',
122
195
  webTemplate: typeof args.options.webTemplate !== 'undefined'
123
196
  });
@@ -131,6 +204,8 @@ _SpoTenantApplicationCustomizerSetCommand_instances = new WeakSet(), _SpoTenantA
131
204
  option: '-c, --clientSideComponentId [clientSideComponentId]'
132
205
  }, {
133
206
  option: '--newTitle [newTitle]'
207
+ }, {
208
+ option: '--newClientSideComponentId [newClientSideComponentId]'
134
209
  }, {
135
210
  option: '-p, --clientSideComponentProperties [clientSideComponentProperties]'
136
211
  }, {
@@ -144,7 +219,10 @@ _SpoTenantApplicationCustomizerSetCommand_instances = new WeakSet(), _SpoTenantA
144
219
  if (args.options.clientSideComponentId && !validation_1.validation.isValidGuid(args.options.clientSideComponentId)) {
145
220
  return `${args.options.clientSideComponentId} is not a valid GUID`;
146
221
  }
147
- if (!args.options.newTitle && !args.options.clientSideComponentProperties && !args.options.webTemplate) {
222
+ if (args.options.newClientSideComponentId && !validation_1.validation.isValidGuid(args.options.newClientSideComponentId)) {
223
+ return `${args.options.newClientSideComponentId} is not a valid GUID`;
224
+ }
225
+ if (!args.options.newTitle && !args.options.newClientSideComponentId && !args.options.clientSideComponentProperties && !args.options.webTemplate) {
148
226
  return `Please specify an option to be updated`;
149
227
  }
150
228
  return true;