@pnp/cli-microsoft365 6.11.0-beta.259c884 → 6.11.0-beta.2d03676

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.
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.workflow = void 0;
4
+ exports.workflow = {
5
+ name: "Deploy Solution {{ name }}",
6
+ on: {
7
+ push: {
8
+ branches: [
9
+ "main"
10
+ ]
11
+ }
12
+ },
13
+ jobs: {
14
+ "build-and-deploy": {
15
+ "runs-on": "ubuntu-latest",
16
+ steps: [
17
+ {
18
+ name: "Checkout",
19
+ uses: "actions/checkout@v3.5.3"
20
+ },
21
+ {
22
+ name: "Use Node.js 16.x",
23
+ uses: "actions/setup-node@v3.7.0",
24
+ with: {
25
+ "node-version": "16.x"
26
+ }
27
+ },
28
+ {
29
+ name: "Run npm ci",
30
+ run: "npm ci"
31
+ },
32
+ {
33
+ name: "Bundle & Package",
34
+ run: "gulp bundle --ship\ngulp package-solution --ship\n"
35
+ },
36
+ {
37
+ name: "CLI for Microsoft 365 Login",
38
+ uses: "pnp/action-cli-login@v2.2.2",
39
+ with: {
40
+ "CERTIFICATE_ENCODED": "${{ secrets.CERTIFICATE_ENCODED }}",
41
+ "CERTIFICATE_PASSWORD": "${{ secrets.CERTIFICATE_PASSWORD }}",
42
+ "APP_ID": "${{ secrets.APP_ID }}"
43
+ }
44
+ },
45
+ {
46
+ name: "CLI for Microsoft 365 Deploy App",
47
+ uses: "pnp/action-cli-deploy@v3.0.1",
48
+ with: {
49
+ "APP_FILE_PATH": "sharepoint/solution/{{ solutionName }}.sppkg",
50
+ "SKIP_FEATURE_DEPLOYMENT": false,
51
+ "OVERWRITE": false
52
+ }
53
+ }
54
+ ]
55
+ }
56
+ }
57
+ };
58
+ //# sourceMappingURL=DeployWorkflow.js.map
@@ -0,0 +1,171 @@
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
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
14
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
+ };
16
+ var _SpfxProjectGithubWorkflowAddCommand_instances, _SpfxProjectGithubWorkflowAddCommand_initTelemetry, _SpfxProjectGithubWorkflowAddCommand_initOptions, _SpfxProjectGithubWorkflowAddCommand_initValidators;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ const fs = require("fs");
19
+ const path = require("path");
20
+ const yaml = require("yaml");
21
+ const Command_1 = require("../../../../Command");
22
+ const fsUtil_1 = require("../../../../utils/fsUtil");
23
+ const validation_1 = require("../../../../utils/validation");
24
+ const commands_1 = require("../../commands");
25
+ const DeployWorkflow_1 = require("./DeployWorkflow");
26
+ const base_project_command_1 = require("./base-project-command");
27
+ class SpfxProjectGithubWorkflowAddCommand extends base_project_command_1.BaseProjectCommand {
28
+ get name() {
29
+ return commands_1.default.PROJECT_GITHUB_WORKFLOW_ADD;
30
+ }
31
+ get description() {
32
+ return 'Adds a GitHub workflow for a SharePoint Framework project.';
33
+ }
34
+ constructor() {
35
+ super();
36
+ _SpfxProjectGithubWorkflowAddCommand_instances.add(this);
37
+ __classPrivateFieldGet(this, _SpfxProjectGithubWorkflowAddCommand_instances, "m", _SpfxProjectGithubWorkflowAddCommand_initTelemetry).call(this);
38
+ __classPrivateFieldGet(this, _SpfxProjectGithubWorkflowAddCommand_instances, "m", _SpfxProjectGithubWorkflowAddCommand_initOptions).call(this);
39
+ __classPrivateFieldGet(this, _SpfxProjectGithubWorkflowAddCommand_instances, "m", _SpfxProjectGithubWorkflowAddCommand_initValidators).call(this);
40
+ }
41
+ commandAction(logger, args) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ this.projectRootPath = this.getProjectRoot(process.cwd());
44
+ if (this.projectRootPath === null) {
45
+ throw new Command_1.CommandError(`Couldn't find project root folder`, SpfxProjectGithubWorkflowAddCommand.ERROR_NO_PROJECT_ROOT_FOLDER);
46
+ }
47
+ const solutionPackageJsonFile = path.join(this.projectRootPath, 'package.json');
48
+ const packageJson = fs.readFileSync(solutionPackageJsonFile, 'utf-8');
49
+ const solutionName = JSON.parse(packageJson).name;
50
+ if (this.debug) {
51
+ logger.logToStderr(`Adding GitHub workflow in the current SPFx project`);
52
+ }
53
+ try {
54
+ this.updateWorkflow(solutionName, DeployWorkflow_1.workflow, args.options);
55
+ this.saveWorkflow(DeployWorkflow_1.workflow);
56
+ }
57
+ catch (error) {
58
+ throw new Command_1.CommandError(error);
59
+ }
60
+ });
61
+ }
62
+ saveWorkflow(workflow) {
63
+ const githubPath = path.join(this.projectRootPath, '.github');
64
+ fsUtil_1.fsUtil.ensureDirectory(githubPath);
65
+ const workflowPath = path.join(githubPath, 'workflows');
66
+ fsUtil_1.fsUtil.ensureDirectory(workflowPath);
67
+ const workflowFile = path.join(workflowPath, 'deploy-spfx-solution.yml');
68
+ fs.writeFileSync(path.resolve(workflowFile), yaml.stringify(workflow), 'utf-8');
69
+ }
70
+ updateWorkflow(solutionName, workflow, options) {
71
+ var _a;
72
+ workflow.name = workflow.name.replace('{{ name }}', (_a = options.name) !== null && _a !== void 0 ? _a : solutionName);
73
+ if (options.branchName) {
74
+ workflow.on.push.branches[0] = options.branchName;
75
+ }
76
+ if (options.manuallyTrigger) {
77
+ // eslint-disable-next-line camelcase
78
+ workflow.on.workflow_dispatch = null;
79
+ }
80
+ if (options.skipFeatureDeployment) {
81
+ this.getDeployAction(workflow).with.SKIP_FEATURE_DEPLOYMENT = true;
82
+ }
83
+ if (options.overwrite) {
84
+ this.getDeployAction(workflow).with.OVERWRITE = true;
85
+ }
86
+ if (options.loginMethod === 'user') {
87
+ const loginAction = this.getLoginAction(workflow);
88
+ loginAction.with = {
89
+ ADMIN_USERNAME: '${{ secrets.ADMIN_USERNAME }}',
90
+ ADMIN_PASSWORD: '${{ secrets.ADMIN_PASSWORD }}'
91
+ };
92
+ }
93
+ if (options.scope === 'sitecollection') {
94
+ const deployAction = this.getDeployAction(workflow);
95
+ deployAction.with.SCOPE = 'sitecollection';
96
+ deployAction.with.SITE_COLLECTION_URL = options.siteUrl;
97
+ }
98
+ if (solutionName) {
99
+ const deployAction = this.getDeployAction(workflow);
100
+ deployAction.with.APP_FILE_PATH = deployAction.with.APP_FILE_PATH.replace('{{ solutionName }}', solutionName);
101
+ }
102
+ }
103
+ getLoginAction(workflow) {
104
+ const steps = this.getWorkFlowSteps(workflow);
105
+ return steps.find(step => step.uses && step.uses.indexOf('action-cli-login') >= 0);
106
+ }
107
+ getDeployAction(workflow) {
108
+ const steps = this.getWorkFlowSteps(workflow);
109
+ return steps.find(step => step.uses && step.uses.indexOf('action-cli-deploy') >= 0);
110
+ }
111
+ getWorkFlowSteps(workflow) {
112
+ return workflow.jobs['build-and-deploy'].steps;
113
+ }
114
+ }
115
+ _SpfxProjectGithubWorkflowAddCommand_instances = new WeakSet(), _SpfxProjectGithubWorkflowAddCommand_initTelemetry = function _SpfxProjectGithubWorkflowAddCommand_initTelemetry() {
116
+ this.telemetry.push((args) => {
117
+ Object.assign(this.telemetryProperties, {
118
+ name: typeof args.options.name !== 'undefined',
119
+ branchName: typeof args.options.branchName !== 'undefined',
120
+ manuallyTrigger: !!args.options.manuallyTrigger,
121
+ loginMethod: typeof args.options.loginMethod !== 'undefined',
122
+ scope: typeof args.options.scope !== 'undefined',
123
+ skipFeatureDeployment: !!args.options.skipFeatureDeployment,
124
+ overwrite: !!args.options.overwrite
125
+ });
126
+ });
127
+ }, _SpfxProjectGithubWorkflowAddCommand_initOptions = function _SpfxProjectGithubWorkflowAddCommand_initOptions() {
128
+ this.options.unshift({
129
+ option: '-n, --name [name]'
130
+ }, {
131
+ option: '-b, --branchName [branchName]'
132
+ }, {
133
+ option: '-m, --manuallyTrigger'
134
+ }, {
135
+ option: '-l, --loginMethod [loginMethod]',
136
+ autocomplete: SpfxProjectGithubWorkflowAddCommand.loginMethod
137
+ }, {
138
+ option: '-s, --scope [scope]',
139
+ autocomplete: SpfxProjectGithubWorkflowAddCommand.scope
140
+ }, {
141
+ option: '-u, --siteUrl [siteUrl]'
142
+ }, {
143
+ option: '--skipFeatureDeployment'
144
+ }, {
145
+ option: '--overwrite'
146
+ });
147
+ }, _SpfxProjectGithubWorkflowAddCommand_initValidators = function _SpfxProjectGithubWorkflowAddCommand_initValidators() {
148
+ this.validators.push((args) => __awaiter(this, void 0, void 0, function* () {
149
+ if (args.options.scope && args.options.scope === 'sitecollection') {
150
+ if (!args.options.siteUrl) {
151
+ return `siteUrl option has to be defined when scope set to ${args.options.scope}`;
152
+ }
153
+ const isValidSharePointUrl = validation_1.validation.isValidSharePointUrl(args.options.siteUrl);
154
+ if (isValidSharePointUrl !== true) {
155
+ return isValidSharePointUrl;
156
+ }
157
+ }
158
+ if (args.options.loginMethod && SpfxProjectGithubWorkflowAddCommand.loginMethod.indexOf(args.options.loginMethod) < 0) {
159
+ return `${args.options.loginMethod} is not a valid login method. Allowed values are ${SpfxProjectGithubWorkflowAddCommand.loginMethod.join(', ')}`;
160
+ }
161
+ if (args.options.scope && SpfxProjectGithubWorkflowAddCommand.scope.indexOf(args.options.scope) < 0) {
162
+ return `${args.options.scope} is not a valid scope. Allowed values are ${SpfxProjectGithubWorkflowAddCommand.scope.join(', ')}`;
163
+ }
164
+ return true;
165
+ }));
166
+ };
167
+ SpfxProjectGithubWorkflowAddCommand.loginMethod = ['application', 'user'];
168
+ SpfxProjectGithubWorkflowAddCommand.scope = ['tenant', 'sitecollection'];
169
+ SpfxProjectGithubWorkflowAddCommand.ERROR_NO_PROJECT_ROOT_FOLDER = 1;
170
+ module.exports = new SpfxProjectGithubWorkflowAddCommand();
171
+ //# sourceMappingURL=project-github-workflow-add.js.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=project-github-workflow-model.js.map
@@ -6,6 +6,7 @@ exports.default = {
6
6
  PACKAGE_GENERATE: `${prefix} package generate`,
7
7
  PROJECT_DOCTOR: `${prefix} project doctor`,
8
8
  PROJECT_EXTERNALIZE: `${prefix} project externalize`,
9
+ PROJECT_GITHUB_WORKFLOW_ADD: `${prefix} project github workflow add`,
9
10
  PROJECT_PERMISSIONS_GRANT: `${prefix} project permissions grant`,
10
11
  PROJECT_RENAME: `${prefix} project rename`,
11
12
  PROJECT_UPGRADE: `${prefix} project upgrade`
@@ -40,38 +40,8 @@ class SpoServicePrincipalSetCommand extends SpoCommand_1.default {
40
40
  }
41
41
  commandAction(logger, args) {
42
42
  return __awaiter(this, void 0, void 0, function* () {
43
- const toggleServicePrincipal = () => __awaiter(this, void 0, void 0, function* () {
44
- try {
45
- const spoAdminUrl = yield spo_1.spo.getSpoAdminUrl(logger, this.debug);
46
- const reqDigest = yield spo_1.spo.getRequestDigest(spoAdminUrl);
47
- if (this.verbose) {
48
- logger.logToStderr(`${(args.options.enabled ? 'Enabling' : 'Disabling')} service principal...`);
49
- }
50
- const requestOptions = {
51
- url: `${spoAdminUrl}/_vti_bin/client.svc/ProcessQuery`,
52
- headers: {
53
- 'X-RequestDigest': reqDigest.FormDigestValue
54
- },
55
- 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="28" ObjectPathId="27" /><SetProperty Id="29" ObjectPathId="27" Name="AccountEnabled"><Parameter Type="Boolean">${args.options.enabled}</Parameter></SetProperty><Method Name="Update" Id="30" ObjectPathId="27" /><Query Id="31" ObjectPathId="27"><Query SelectAllProperties="true"><Properties><Property Name="AccountEnabled" ScalarProperty="true" /></Properties></Query></Query></Actions><ObjectPaths><Constructor Id="27" TypeId="{104e8f06-1e00-4675-99c6-1b9b504ed8d8}" /></ObjectPaths></Request>`
56
- };
57
- const res = yield request_1.default.post(requestOptions);
58
- const json = JSON.parse(res);
59
- const response = json[0];
60
- if (response.ErrorInfo) {
61
- throw response.ErrorInfo.ErrorMessage;
62
- }
63
- else {
64
- const output = json[json.length - 1];
65
- delete output._ObjectType_;
66
- logger.log(output);
67
- }
68
- }
69
- catch (err) {
70
- this.handleRejectedPromise(err);
71
- }
72
- });
73
43
  if (args.options.confirm) {
74
- yield toggleServicePrincipal();
44
+ yield this.toggleServicePrincipal(logger, args);
75
45
  }
76
46
  else {
77
47
  const result = yield Cli_1.Cli.prompt({
@@ -81,11 +51,41 @@ class SpoServicePrincipalSetCommand extends SpoCommand_1.default {
81
51
  message: `Are you sure you want to ${args.options.enabled ? 'enable' : 'disable'} the service principal?`
82
52
  });
83
53
  if (result.continue) {
84
- yield toggleServicePrincipal();
54
+ yield this.toggleServicePrincipal(logger, args);
85
55
  }
86
56
  }
87
57
  });
88
58
  }
59
+ toggleServicePrincipal(logger, args) {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ try {
62
+ const spoAdminUrl = yield spo_1.spo.getSpoAdminUrl(logger, this.debug);
63
+ const reqDigest = yield spo_1.spo.getRequestDigest(spoAdminUrl);
64
+ if (this.verbose) {
65
+ logger.logToStderr(`${(args.options.enabled ? 'Enabling' : 'Disabling')} service principal...`);
66
+ }
67
+ const requestOptions = {
68
+ url: `${spoAdminUrl}/_vti_bin/client.svc/ProcessQuery`,
69
+ headers: {
70
+ 'X-RequestDigest': reqDigest.FormDigestValue
71
+ },
72
+ 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="28" ObjectPathId="27" /><SetProperty Id="29" ObjectPathId="27" Name="AccountEnabled"><Parameter Type="Boolean">${args.options.enabled}</Parameter></SetProperty><Method Name="Update" Id="30" ObjectPathId="27" /><Query Id="31" ObjectPathId="27"><Query SelectAllProperties="true"><Properties><Property Name="AccountEnabled" ScalarProperty="true" /></Properties></Query></Query></Actions><ObjectPaths><Constructor Id="27" TypeId="{104e8f06-1e00-4675-99c6-1b9b504ed8d8}" /></ObjectPaths></Request>`
73
+ };
74
+ const response = yield request_1.default.post(requestOptions);
75
+ const json = JSON.parse(response);
76
+ const responseContent = json[0];
77
+ if (responseContent.ErrorInfo) {
78
+ throw responseContent.ErrorInfo.ErrorMessage;
79
+ }
80
+ const output = json[json.length - 1];
81
+ delete output._ObjectType_;
82
+ logger.log(output);
83
+ }
84
+ catch (err) {
85
+ this.handleRejectedPromise(err);
86
+ }
87
+ });
88
+ }
89
89
  }
90
90
  _SpoServicePrincipalSetCommand_instances = new WeakSet(), _SpoServicePrincipalSetCommand_initTelemetry = function _SpoServicePrincipalSetCommand_initTelemetry() {
91
91
  this.telemetry.push((args) => {
@@ -141,18 +141,16 @@ class SpoSiteAddCommand extends SpoCommand_1.default {
141
141
  requestOptions.data.request.Owner = args.options.owners;
142
142
  }
143
143
  }
144
- const res = yield request_1.default.post(requestOptions);
144
+ const response = yield request_1.default.post(requestOptions);
145
145
  if (isTeamSite) {
146
- if (res.ErrorMessage !== null) {
147
- throw res.ErrorMessage;
148
- }
149
- else {
150
- logger.log(res.SiteUrl);
146
+ if (response.ErrorMessage !== null) {
147
+ throw response.ErrorMessage;
151
148
  }
149
+ logger.log(response.SiteUrl);
152
150
  }
153
151
  else {
154
- if (res.SiteStatus === 2) {
155
- logger.log(res.SiteUrl);
152
+ if (response.SiteStatus === 2) {
153
+ logger.log(response.SiteUrl);
156
154
  }
157
155
  else {
158
156
  throw 'An error has occurred while creating the site';
@@ -171,7 +169,7 @@ class SpoSiteAddCommand extends SpoCommand_1.default {
171
169
  this.context = yield spo_1.spo.ensureFormDigest(this.spoAdminUrl, logger, this.context, this.debug);
172
170
  let exists;
173
171
  if (args.options.removeDeletedSite) {
174
- exists = yield this.siteExistsInTheRecycleBin(args.options.url, logger);
172
+ exists = yield this.siteExists(args.options.url, logger);
175
173
  }
176
174
  else {
177
175
  // assume site doesn't exist
@@ -205,153 +203,18 @@ class SpoSiteAddCommand extends SpoCommand_1.default {
205
203
  },
206
204
  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="4" ObjectPathId="3" /><ObjectPath Id="6" ObjectPathId="5" /><Query Id="7" ObjectPathId="3"><Query SelectAllProperties="true"><Properties /></Query></Query><Query Id="8" ObjectPathId="5"><Query SelectAllProperties="false"><Properties><Property Name="IsComplete" ScalarProperty="true" /><Property Name="PollingInterval" ScalarProperty="true" /></Properties></Query></Query></Actions><ObjectPaths><Constructor Id="3" TypeId="{268004ae-ef6b-4e9b-8425-127220d84719}" /><Method Id="5" ParentId="3" Name="CreateSite"><Parameters><Parameter TypeId="{11f84fff-b8cf-47b6-8b50-34e692656606}"><Property Name="CompatibilityLevel" Type="Int32">0</Property><Property Name="Lcid" Type="UInt32">${lcid}</Property><Property Name="Owner" Type="String">${formatting_1.formatting.escapeXml(args.options.owners)}</Property><Property Name="StorageMaximumLevel" Type="Int64">${storageQuota}</Property><Property Name="StorageWarningLevel" Type="Int64">${storageQuotaWarningLevel}</Property><Property Name="Template" Type="String">${formatting_1.formatting.escapeXml(webTemplate)}</Property><Property Name="TimeZoneId" Type="Int32">${args.options.timeZone}</Property><Property Name="Title" Type="String">${formatting_1.formatting.escapeXml(args.options.title)}</Property><Property Name="Url" Type="String">${formatting_1.formatting.escapeXml(args.options.url)}</Property><Property Name="UserCodeMaximumLevel" Type="Double">${resourceQuota}</Property><Property Name="UserCodeWarningLevel" Type="Double">${resourceQuotaWarningLevel}</Property></Parameter></Parameters></Method></ObjectPaths></Request>`
207
205
  };
208
- const res = yield request_1.default.post(requestOptions);
209
- yield new Promise((resolve, reject) => {
210
- const json = JSON.parse(res);
211
- const response = json[0];
212
- if (response.ErrorInfo) {
213
- reject(response.ErrorInfo.ErrorMessage);
214
- }
215
- else {
216
- const operation = json[json.length - 1];
217
- const isComplete = operation.IsComplete;
218
- if (!args.options.wait || isComplete) {
219
- resolve();
220
- return;
221
- }
222
- setTimeout(() => {
223
- spo_1.spo.waitUntilFinished({
224
- operationId: JSON.stringify(operation._ObjectIdentity_),
225
- siteUrl: this.spoAdminUrl,
226
- resolve,
227
- reject,
228
- logger,
229
- currentContext: this.context,
230
- verbose: this.verbose,
231
- debug: this.debug
232
- });
233
- }, operation.PollingInterval);
234
- }
235
- });
236
- }
237
- catch (err) {
238
- this.handleRejectedPromise(err);
239
- }
240
- });
241
- }
242
- siteExistsInTheRecycleBin(url, logger) {
243
- return new Promise((resolve, reject) => {
244
- spo_1.spo
245
- .ensureFormDigest(this.spoAdminUrl, logger, this.context, this.debug)
246
- .then((res) => {
247
- this.context = res;
248
- if (this.verbose) {
249
- logger.logToStderr(`Checking if the site ${url} exists...`);
250
- }
251
- const requestOptions = {
252
- url: `${this.spoAdminUrl}/_vti_bin/client.svc/ProcessQuery`,
253
- headers: {
254
- 'X-RequestDigest': this.context.FormDigestValue
255
- },
256
- 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="197" ObjectPathId="196" /><ObjectPath Id="199" ObjectPathId="198" /><Query Id="200" ObjectPathId="198"><Query SelectAllProperties="true"><Properties /></Query></Query></Actions><ObjectPaths><Constructor Id="196" TypeId="{268004ae-ef6b-4e9b-8425-127220d84719}" /><Method Id="198" ParentId="196" Name="GetSitePropertiesByUrl"><Parameters><Parameter Type="String">${formatting_1.formatting.escapeXml(url)}</Parameter><Parameter Type="Boolean">false</Parameter></Parameters></Method></ObjectPaths></Request>`
257
- };
258
- return request_1.default.post(requestOptions);
259
- })
260
- .then((res) => {
261
- const json = JSON.parse(res);
262
- const response = json[0];
263
- if (response.ErrorInfo) {
264
- if (response.ErrorInfo.ErrorTypeName === 'Microsoft.Online.SharePoint.Common.SpoNoSiteException') {
265
- return Promise.resolve(false);
266
- }
267
- else {
268
- return Promise.reject(response.ErrorInfo.ErrorMessage);
269
- }
270
- }
271
- else {
272
- const site = json[json.length - 1];
273
- if (site.Status === 'Recycled') {
274
- return Promise.reject(true);
275
- }
276
- else {
277
- return Promise.resolve(false);
278
- }
279
- }
280
- })
281
- .then(() => {
282
- if (this.verbose) {
283
- logger.logToStderr(`Site doesn't exist. Checking if the site ${url} exists in the recycle bin...`);
206
+ const response = yield request_1.default.post(requestOptions);
207
+ const json = JSON.parse(response);
208
+ const responseContent = json[0];
209
+ if (responseContent.ErrorInfo) {
210
+ throw responseContent.ErrorInfo.ErrorMessage;
284
211
  }
285
- const requestOptions = {
286
- url: `${this.spoAdminUrl}/_vti_bin/client.svc/ProcessQuery`,
287
- headers: {
288
- 'X-RequestDigest': this.context.FormDigestValue
289
- },
290
- 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="181" ObjectPathId="180" /><Query Id="182" ObjectPathId="180"><Query SelectAllProperties="true"><Properties /></Query></Query></Actions><ObjectPaths><Method Id="180" ParentId="175" Name="GetDeletedSitePropertiesByUrl"><Parameters><Parameter Type="String">${formatting_1.formatting.escapeXml(url)}</Parameter></Parameters></Method><Constructor Id="175" TypeId="{268004ae-ef6b-4e9b-8425-127220d84719}" /></ObjectPaths></Request>`
291
- };
292
- return request_1.default.post(requestOptions);
293
- })
294
- .then((res) => {
295
- const json = JSON.parse(res);
296
- const response = json[0];
297
- if (response.ErrorInfo) {
298
- if (response.ErrorInfo.ErrorTypeName === 'Microsoft.SharePoint.Client.UnknownError') {
299
- resolve(false);
300
- }
301
- else {
302
- reject(response.ErrorInfo.ErrorMessage);
303
- }
212
+ const operation = json[json.length - 1];
213
+ const isComplete = operation.IsComplete;
214
+ if (!args.options.wait || isComplete) {
215
+ return;
304
216
  }
305
- else {
306
- const site = json[json.length - 1];
307
- if (site.Status === 'Recycled') {
308
- resolve(true);
309
- }
310
- else {
311
- resolve(false);
312
- }
313
- }
314
- }, (error) => {
315
- if (typeof error === 'boolean') {
316
- resolve(error);
317
- }
318
- else {
319
- reject(error);
320
- }
321
- });
322
- });
323
- }
324
- deleteSiteFromTheRecycleBin(url, wait, logger) {
325
- return new Promise((resolve, reject) => {
326
- spo_1.spo
327
- .ensureFormDigest(this.spoAdminUrl, logger, this.context, this.debug)
328
- .then((res) => {
329
- this.context = res;
330
- if (this.verbose) {
331
- logger.logToStderr(`Deleting site ${url} from the recycle bin...`);
332
- }
333
- const requestOptions = {
334
- url: `${this.spoAdminUrl}/_vti_bin/client.svc/ProcessQuery`,
335
- headers: {
336
- 'X-RequestDigest': this.context.FormDigestValue
337
- },
338
- 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="185" ObjectPathId="184" /><Query Id="186" ObjectPathId="184"><Query SelectAllProperties="false"><Properties><Property Name="IsComplete" ScalarProperty="true" /><Property Name="PollingInterval" ScalarProperty="true" /></Properties></Query></Query></Actions><ObjectPaths><Method Id="184" ParentId="175" Name="RemoveDeletedSite"><Parameters><Parameter Type="String">${formatting_1.formatting.escapeXml(url)}</Parameter></Parameters></Method><Constructor Id="175" TypeId="{268004ae-ef6b-4e9b-8425-127220d84719}" /></ObjectPaths></Request>`
339
- };
340
- return request_1.default.post(requestOptions);
341
- })
342
- .then((res) => {
343
- const json = JSON.parse(res);
344
- const response = json[0];
345
- if (response.ErrorInfo) {
346
- reject(response.ErrorInfo.ErrorMessage);
347
- }
348
- else {
349
- const operation = json[json.length - 1];
350
- const isComplete = operation.IsComplete;
351
- if (!wait || isComplete) {
352
- resolve();
353
- return;
354
- }
217
+ yield new Promise((resolve, reject) => {
355
218
  setTimeout(() => {
356
219
  spo_1.spo.waitUntilFinished({
357
220
  operationId: JSON.stringify(operation._ObjectIdentity_),
@@ -364,7 +227,103 @@ class SpoSiteAddCommand extends SpoCommand_1.default {
364
227
  debug: this.debug
365
228
  });
366
229
  }, operation.PollingInterval);
230
+ });
231
+ }
232
+ catch (err) {
233
+ this.handleRejectedPromise(err);
234
+ }
235
+ });
236
+ }
237
+ siteExists(url, logger) {
238
+ return __awaiter(this, void 0, void 0, function* () {
239
+ this.context = yield spo_1.spo.ensureFormDigest(this.spoAdminUrl, logger, this.context, this.debug);
240
+ if (this.verbose) {
241
+ logger.logToStderr(`Checking if the site ${url} exists...`);
242
+ }
243
+ const requestOptions = {
244
+ url: `${this.spoAdminUrl}/_vti_bin/client.svc/ProcessQuery`,
245
+ headers: {
246
+ 'X-RequestDigest': this.context.FormDigestValue
247
+ },
248
+ 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="197" ObjectPathId="196" /><ObjectPath Id="199" ObjectPathId="198" /><Query Id="200" ObjectPathId="198"><Query SelectAllProperties="true"><Properties /></Query></Query></Actions><ObjectPaths><Constructor Id="196" TypeId="{268004ae-ef6b-4e9b-8425-127220d84719}" /><Method Id="198" ParentId="196" Name="GetSitePropertiesByUrl"><Parameters><Parameter Type="String">${formatting_1.formatting.escapeXml(url)}</Parameter><Parameter Type="Boolean">false</Parameter></Parameters></Method></ObjectPaths></Request>`
249
+ };
250
+ const response = yield request_1.default.post(requestOptions);
251
+ const json = JSON.parse(response);
252
+ const responseContent = json[0];
253
+ if (responseContent.ErrorInfo) {
254
+ if (responseContent.ErrorInfo.ErrorTypeName === 'Microsoft.Online.SharePoint.Common.SpoNoSiteException') {
255
+ return yield this.siteExistsInTheRecycleBin(url, logger);
367
256
  }
257
+ throw responseContent.ErrorInfo.ErrorMessage;
258
+ }
259
+ else {
260
+ const site = json[json.length - 1];
261
+ return site.Status === 'Recycled';
262
+ }
263
+ });
264
+ }
265
+ siteExistsInTheRecycleBin(url, logger) {
266
+ return __awaiter(this, void 0, void 0, function* () {
267
+ if (this.verbose) {
268
+ logger.logToStderr(`Site doesn't exist. Checking if the site ${url} exists in the recycle bin...`);
269
+ }
270
+ const requestOptions = {
271
+ url: `${this.spoAdminUrl}/_vti_bin/client.svc/ProcessQuery`,
272
+ headers: {
273
+ 'X-RequestDigest': this.context.FormDigestValue
274
+ },
275
+ 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="181" ObjectPathId="180" /><Query Id="182" ObjectPathId="180"><Query SelectAllProperties="true"><Properties /></Query></Query></Actions><ObjectPaths><Method Id="180" ParentId="175" Name="GetDeletedSitePropertiesByUrl"><Parameters><Parameter Type="String">${formatting_1.formatting.escapeXml(url)}</Parameter></Parameters></Method><Constructor Id="175" TypeId="{268004ae-ef6b-4e9b-8425-127220d84719}" /></ObjectPaths></Request>`
276
+ };
277
+ const res = yield request_1.default.post(requestOptions);
278
+ const json = JSON.parse(res);
279
+ const response = json[0];
280
+ if (response.ErrorInfo) {
281
+ if (response.ErrorInfo.ErrorTypeName === 'Microsoft.SharePoint.Client.UnknownError') {
282
+ return false;
283
+ }
284
+ throw response.ErrorInfo.ErrorMessage;
285
+ }
286
+ const site = json[json.length - 1];
287
+ return site.Status === 'Recycled';
288
+ });
289
+ }
290
+ deleteSiteFromTheRecycleBin(url, wait, logger) {
291
+ return __awaiter(this, void 0, void 0, function* () {
292
+ this.context = yield spo_1.spo.ensureFormDigest(this.spoAdminUrl, logger, this.context, this.debug);
293
+ if (this.verbose) {
294
+ logger.logToStderr(`Deleting site ${url} from the recycle bin...`);
295
+ }
296
+ const requestOptions = {
297
+ url: `${this.spoAdminUrl}/_vti_bin/client.svc/ProcessQuery`,
298
+ headers: {
299
+ 'X-RequestDigest': this.context.FormDigestValue
300
+ },
301
+ 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="185" ObjectPathId="184" /><Query Id="186" ObjectPathId="184"><Query SelectAllProperties="false"><Properties><Property Name="IsComplete" ScalarProperty="true" /><Property Name="PollingInterval" ScalarProperty="true" /></Properties></Query></Query></Actions><ObjectPaths><Method Id="184" ParentId="175" Name="RemoveDeletedSite"><Parameters><Parameter Type="String">${formatting_1.formatting.escapeXml(url)}</Parameter></Parameters></Method><Constructor Id="175" TypeId="{268004ae-ef6b-4e9b-8425-127220d84719}" /></ObjectPaths></Request>`
302
+ };
303
+ const response = yield request_1.default.post(requestOptions);
304
+ const json = JSON.parse(response);
305
+ const responseContent = json[0];
306
+ if (responseContent.ErrorInfo) {
307
+ throw responseContent.ErrorInfo.ErrorMessage;
308
+ }
309
+ const operation = json[json.length - 1];
310
+ const isComplete = operation.IsComplete;
311
+ if (!wait || isComplete) {
312
+ return;
313
+ }
314
+ yield new Promise((resolve, reject) => {
315
+ setTimeout(() => {
316
+ spo_1.spo.waitUntilFinished({
317
+ operationId: JSON.stringify(operation._ObjectIdentity_),
318
+ siteUrl: this.spoAdminUrl,
319
+ resolve,
320
+ reject,
321
+ logger,
322
+ currentContext: this.context,
323
+ verbose: this.verbose,
324
+ debug: this.debug
325
+ });
326
+ }, operation.PollingInterval);
368
327
  });
369
328
  });
370
329
  }