@pnp/cli-microsoft365 10.8.0-beta.7160233 → 10.8.0-beta.a1c69a6

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.
@@ -43,6 +43,9 @@ class SpoListGetCommand extends SpoCommand {
43
43
  const listServerRelativeUrl = urlUtil.getServerRelativePath(args.options.webUrl, args.options.url);
44
44
  requestUrl += `GetList('${formatting.encodeQueryParameter(listServerRelativeUrl)}')`;
45
45
  }
46
+ else if (args.options.default) {
47
+ requestUrl += `DefaultDocumentLibrary`;
48
+ }
46
49
  const fieldsProperties = this.formatSelectProperties(args.options.properties, args.options.withPermissions);
47
50
  const queryParams = [];
48
51
  if (fieldsProperties.selectProperties.length > 0) {
@@ -113,11 +116,12 @@ class SpoListGetCommand extends SpoCommand {
113
116
  _SpoListGetCommand_instances = new WeakSet(), _SpoListGetCommand_initTelemetry = function _SpoListGetCommand_initTelemetry() {
114
117
  this.telemetry.push((args) => {
115
118
  Object.assign(this.telemetryProperties, {
116
- id: (!(!args.options.id)).toString(),
117
- title: (!(!args.options.title)).toString(),
118
- url: (!(!args.options.url)).toString(),
119
- properties: (!(!args.options.properties)).toString(),
120
- withPermissions: typeof args.options.withPermissions !== 'undefined'
119
+ id: typeof args.options.id !== 'undefined',
120
+ title: typeof args.options.title !== 'undefined',
121
+ url: typeof args.options.url !== 'undefined',
122
+ properties: typeof args.options.properties !== 'undefined',
123
+ withPermissions: !!args.options.withPermissions,
124
+ default: !!args.options.default
121
125
  });
122
126
  });
123
127
  }, _SpoListGetCommand_initOptions = function _SpoListGetCommand_initOptions() {
@@ -129,6 +133,8 @@ _SpoListGetCommand_instances = new WeakSet(), _SpoListGetCommand_initTelemetry =
129
133
  option: '-t, --title [title]'
130
134
  }, {
131
135
  option: '--url [url]'
136
+ }, {
137
+ option: '--default'
132
138
  }, {
133
139
  option: '-p, --properties [properties]'
134
140
  }, {
@@ -148,7 +154,7 @@ _SpoListGetCommand_instances = new WeakSet(), _SpoListGetCommand_initTelemetry =
148
154
  return true;
149
155
  });
150
156
  }, _SpoListGetCommand_initOptionSets = function _SpoListGetCommand_initOptionSets() {
151
- this.optionSets.push({ options: ['id', 'title', 'url'] });
157
+ this.optionSets.push({ options: ['id', 'title', 'url', 'default'] });
152
158
  };
153
159
  export default new SpoListGetCommand();
154
160
  //# sourceMappingURL=list-get.js.map
@@ -0,0 +1,130 @@
1
+ import request from '../../../../request.js';
2
+ import { formatting } from '../../../../utils/formatting.js';
3
+ import { spp } from '../../../../utils/spp.js';
4
+ import { urlUtil } from '../../../../utils/urlUtil.js';
5
+ import { validation } from '../../../../utils/validation.js';
6
+ import SpoCommand from '../../../base/SpoCommand.js';
7
+ import commands from '../../commands.js';
8
+ import { z } from 'zod';
9
+ import { globalOptionsZod } from '../../../../Command.js';
10
+ import { zod } from '../../../../utils/zod.js';
11
+ const options = globalOptionsZod
12
+ .extend({
13
+ contentCenterUrl: zod.alias('c', z.string()
14
+ .refine(url => validation.isValidSharePointUrl(url) === true, url => ({
15
+ message: `'${url}' is not a valid SharePoint Online site URL.`
16
+ }))),
17
+ webUrl: zod.alias('u', z.string()
18
+ .refine(url => validation.isValidSharePointUrl(url) === true, url => ({
19
+ message: `'${url}' is not a valid SharePoint Online site URL.`
20
+ }))),
21
+ id: zod.alias('i', z.string()
22
+ .refine(id => validation.isValidGuid(id) === true, id => ({
23
+ message: `${id} is not a valid GUID.`
24
+ })).optional()),
25
+ title: zod.alias('t', z.string()).optional(),
26
+ listTitle: z.string().optional(),
27
+ listId: z.string()
28
+ .refine(listId => validation.isValidGuid(listId) === true, listId => ({
29
+ message: `${listId} is not a valid GUID.`
30
+ })).optional(),
31
+ listUrl: z.string().optional(),
32
+ viewOption: z.enum(['NewViewAsDefault', 'DoNotChangeDefault', 'TileViewAsDefault']).optional()
33
+ })
34
+ .strict();
35
+ class SppModelApplyCommand extends SpoCommand {
36
+ get name() {
37
+ return commands.MODEL_APPLY;
38
+ }
39
+ get description() {
40
+ return 'Applies (or syncs) a trained document understanding model to a document library';
41
+ }
42
+ get schema() {
43
+ return options;
44
+ }
45
+ getRefinedSchema(schema) {
46
+ return schema
47
+ .refine(options => [options.id, options.title].filter(x => x !== undefined).length === 1, {
48
+ message: `Specify exactly one of the following options: 'id' or 'title'.`
49
+ })
50
+ .refine(options => [options.listTitle, options.listId, options.listUrl].filter(x => x !== undefined).length === 1, {
51
+ message: `Specify exactly one of the following options: 'listTitle', 'listId' or 'listUrl'.`
52
+ });
53
+ }
54
+ async commandAction(logger, args) {
55
+ try {
56
+ const contentCenterUrl = urlUtil.removeTrailingSlashes(args.options.contentCenterUrl);
57
+ await spp.assertSiteIsContentCenter(contentCenterUrl, logger, this.verbose);
58
+ let model = null;
59
+ if (args.options.title) {
60
+ model = await spp.getModelByTitle(contentCenterUrl, args.options.title, logger, this.verbose);
61
+ }
62
+ else {
63
+ model = await spp.getModelById(contentCenterUrl, args.options.id, logger, this.verbose);
64
+ }
65
+ if (this.verbose) {
66
+ await logger.log(`Retrieving list information...`);
67
+ }
68
+ const listInstance = await this.getListInfo(args.options.webUrl, args.options.listId, args.options.listTitle, args.options.listUrl);
69
+ if (listInstance.BaseType !== 1) {
70
+ throw `The specified list is not a document library.`;
71
+ }
72
+ if (this.verbose) {
73
+ await logger.log(`Applying model '${model.ModelName}' to document library '${listInstance.RootFolder.ServerRelativeUrl}'...`);
74
+ }
75
+ const requestOptions = {
76
+ url: `${contentCenterUrl}/_api/machinelearning/publications`,
77
+ headers: {
78
+ accept: 'application/json;odata=nometadata',
79
+ 'Content-Type': 'application/json;odata=verbose'
80
+ },
81
+ responseType: 'json',
82
+ data: {
83
+ __metadata: { type: 'Microsoft.Office.Server.ContentCenter.SPMachineLearningPublicationsEntityData' },
84
+ Publications: {
85
+ results: [
86
+ {
87
+ ModelUniqueId: model.UniqueId,
88
+ TargetSiteUrl: args.options.webUrl,
89
+ TargetWebServerRelativeUrl: urlUtil.getServerRelativeSiteUrl(args.options.webUrl),
90
+ TargetLibraryServerRelativeUrl: listInstance.RootFolder.ServerRelativeUrl,
91
+ ViewOption: args.options.viewOption ?? "NewViewAsDefault"
92
+ }
93
+ ]
94
+ }
95
+ }
96
+ };
97
+ const result = await request.post(requestOptions);
98
+ const resultDetails = result.Details;
99
+ if (resultDetails && resultDetails[0]?.ErrorMessage) {
100
+ throw resultDetails[0].ErrorMessage;
101
+ }
102
+ }
103
+ catch (err) {
104
+ this.handleRejectedODataJsonPromise(err);
105
+ }
106
+ }
107
+ getListInfo(webUrl, listId, listTitle, listUrl) {
108
+ let requestUrl = `${webUrl}/_api/web`;
109
+ if (listId) {
110
+ requestUrl += `/lists(guid'${formatting.encodeQueryParameter(listId)}')`;
111
+ }
112
+ else if (listTitle) {
113
+ requestUrl += `/lists/getByTitle('${formatting.encodeQueryParameter(listTitle)}')`;
114
+ }
115
+ else if (listUrl) {
116
+ const listServerRelativeUrl = urlUtil.getServerRelativePath(webUrl, listUrl);
117
+ requestUrl += `/GetList('${formatting.encodeQueryParameter(listServerRelativeUrl)}')`;
118
+ }
119
+ const requestOptions = {
120
+ url: `${requestUrl}?$select=BaseType,RootFolder/ServerRelativeUrl&$expand=RootFolder`,
121
+ headers: {
122
+ accept: 'application/json;odata=nometadata'
123
+ },
124
+ responseType: 'json'
125
+ };
126
+ return request.get(requestOptions);
127
+ }
128
+ }
129
+ export default new SppModelApplyCommand();
130
+ //# sourceMappingURL=model-apply.js.map
@@ -4,8 +4,6 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
4
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
6
  var _SppModelGetCommand_instances, _SppModelGetCommand_initTelemetry, _SppModelGetCommand_initOptions, _SppModelGetCommand_initValidators, _SppModelGetCommand_initOptionSets, _SppModelGetCommand_initTypes;
7
- import request from '../../../../request.js';
8
- import { formatting } from '../../../../utils/formatting.js';
9
7
  import { odata } from '../../../../utils/odata.js';
10
8
  import { spp } from '../../../../utils/spp.js';
11
9
  import { urlUtil } from '../../../../utils/urlUtil.js';
@@ -30,34 +28,19 @@ class SppModelGetCommand extends SpoCommand {
30
28
  }
31
29
  async commandAction(logger, args) {
32
30
  try {
33
- if (this.verbose) {
34
- await logger.log(`Retrieving model information from ${args.options.siteUrl}...`);
35
- }
36
31
  const siteUrl = urlUtil.removeTrailingSlashes(args.options.siteUrl);
37
- await spp.assertSiteIsContentCenter(siteUrl);
38
- let requestUrl = `${siteUrl}/_api/machinelearning/models/`;
32
+ await spp.assertSiteIsContentCenter(siteUrl, logger, this.verbose);
33
+ let result = null;
39
34
  if (args.options.title) {
40
- let requestTitle = args.options.title.toLowerCase();
41
- if (!requestTitle.endsWith('.classifier')) {
42
- requestTitle += '.classifier';
43
- }
44
- requestUrl += `getbytitle('${formatting.encodeQueryParameter(requestTitle)}')`;
35
+ result = await spp.getModelByTitle(siteUrl, args.options.title, logger, this.verbose);
45
36
  }
46
37
  else {
47
- requestUrl += `getbyuniqueid('${args.options.id}')`;
48
- }
49
- const requestOptions = {
50
- url: requestUrl,
51
- headers: {
52
- accept: 'application/json;odata=nometadata'
53
- },
54
- responseType: 'json'
55
- };
56
- const result = await request.get(requestOptions);
57
- if (result['odata.null'] === true) {
58
- throw 'Model not found.';
38
+ result = await spp.getModelById(siteUrl, args.options.id, logger, this.verbose);
59
39
  }
60
40
  if (args.options.withPublications) {
41
+ if (this.verbose) {
42
+ await logger.log(`Retrieving publications for model...`);
43
+ }
61
44
  result.Publications = await odata.getAllItems(`${siteUrl}/_api/machinelearning/publications/getbymodeluniqueid('${result.UniqueId}')`);
62
45
  }
63
46
  await logger.log({
@@ -33,7 +33,7 @@ class SppModelListCommand extends SpoCommand {
33
33
  await logger.log(`Retrieving models from ${args.options.siteUrl}...`);
34
34
  }
35
35
  const siteUrl = urlUtil.removeTrailingSlashes(args.options.siteUrl);
36
- await spp.assertSiteIsContentCenter(siteUrl);
36
+ await spp.assertSiteIsContentCenter(siteUrl, logger, this.verbose);
37
37
  const result = await odata.getAllItems(`${siteUrl}/_api/machinelearning/models`);
38
38
  await logger.log(result);
39
39
  }
@@ -40,7 +40,7 @@ class SppModelRemoveCommand extends SpoCommand {
40
40
  await logger.log(`Removing model from ${args.options.siteUrl}...`);
41
41
  }
42
42
  const siteUrl = urlUtil.removeTrailingSlashes(args.options.siteUrl);
43
- await spp.assertSiteIsContentCenter(siteUrl);
43
+ await spp.assertSiteIsContentCenter(siteUrl, logger, this.verbose);
44
44
  let requestUrl = `${siteUrl}/_api/machinelearning/models/`;
45
45
  if (args.options.title) {
46
46
  let requestTitle = args.options.title.toLowerCase();
@@ -1,6 +1,7 @@
1
1
  const prefix = 'spp';
2
2
  export default {
3
3
  CONTENTCENTER_LIST: `${prefix} contentcenter list`,
4
+ MODEL_APPLY: `${prefix} model apply`,
4
5
  MODEL_GET: `${prefix} model get`,
5
6
  MODEL_LIST: `${prefix} model list`,
6
7
  MODEL_REMOVE: `${prefix} model remove`
package/dist/utils/spp.js CHANGED
@@ -1,11 +1,17 @@
1
1
  import request from '../request.js';
2
+ import { formatting } from './formatting.js';
2
3
  export const spp = {
3
4
  /**
4
5
  * Asserts whether the specified site is a content center
5
6
  * @param siteUrl The URL of the site to check
7
+ * @param logger Logger instance
8
+ * @param verbose Whether to log verbose messages
6
9
  * @throws error when site is not a content center.
7
10
  */
8
- async assertSiteIsContentCenter(siteUrl) {
11
+ async assertSiteIsContentCenter(siteUrl, logger, verbose) {
12
+ if (verbose) {
13
+ await logger.log(`Checking if '${siteUrl}' is a valid content center site...`);
14
+ }
9
15
  const requestOptions = {
10
16
  url: `${siteUrl}/_api/web?$select=WebTemplateConfiguration`,
11
17
  headers: {
@@ -17,6 +23,58 @@ export const spp = {
17
23
  if (response.WebTemplateConfiguration !== 'CONTENTCTR#0') {
18
24
  throw Error(`${siteUrl} is not a content site.`);
19
25
  }
26
+ },
27
+ /**
28
+ * Gets a SharePoint Premium model by title
29
+ * @param contentCenterUrl a content center site URL
30
+ * @param title model title
31
+ * @param logger Logger instance
32
+ * @param verbose Whether to log verbose messages
33
+ * @returns SharePoint Premium model
34
+ */
35
+ async getModelByTitle(contentCenterUrl, title, logger, verbose) {
36
+ if (verbose) {
37
+ await logger.log(`Retrieving model information...`);
38
+ }
39
+ let requestTitle = title.toLowerCase();
40
+ if (!requestTitle.endsWith('.classifier')) {
41
+ requestTitle += '.classifier';
42
+ }
43
+ const requestUrl = `${contentCenterUrl}/_api/machinelearning/models/getbytitle('${formatting.encodeQueryParameter(requestTitle)}')`;
44
+ const requestOptions = {
45
+ url: requestUrl,
46
+ headers: {
47
+ accept: 'application/json;odata=nometadata'
48
+ },
49
+ responseType: 'json'
50
+ };
51
+ const result = await request.get(requestOptions);
52
+ if (result['odata.null'] === true) {
53
+ throw Error(`Model '${title}' was not found.`);
54
+ }
55
+ return result;
56
+ },
57
+ /**
58
+ * Gets a SharePoint Premium model by unique id
59
+ * @param contentCenterUrl a content center site URL
60
+ * @param id model unique id
61
+ * @param logger Logger instance
62
+ * @param verbose Whether to log verbose messages
63
+ * @returns SharePoint Premium model
64
+ */
65
+ async getModelById(contentCenterUrl, id, logger, verbose) {
66
+ if (verbose) {
67
+ await logger.log(`Retrieving model information...`);
68
+ }
69
+ const requestUrl = `${contentCenterUrl}/_api/machinelearning/models/getbyuniqueid('${id}')`;
70
+ const requestOptions = {
71
+ url: requestUrl,
72
+ headers: {
73
+ accept: 'application/json;odata=nometadata'
74
+ },
75
+ responseType: 'json'
76
+ };
77
+ return await request.get(requestOptions);
20
78
  }
21
79
  };
22
80
  //# sourceMappingURL=spp.js.map
@@ -19,13 +19,16 @@ m365 spo list get [options]
19
19
  : URL of the site where the list to retrieve is located.
20
20
 
21
21
  `-i, --id [id]`
22
- : ID of the list to retrieve information for. Specify either `id`, `title`, or `url` but not multiple.
22
+ : ID of the list to retrieve information for. Specify either `id`, `title`,`url` or `default` but not multiple.
23
23
 
24
24
  `-t, --title [title]`
25
- : Title of the list to retrieve information for. Specify either `id`, `title`, or `url` but not multiple.
25
+ : Title of the list to retrieve information for. Specify either `id`, `title`,`url` or `default` but not multiple.
26
26
 
27
27
  `--url [url]`
28
- : Server- or site-relative URL of the list. Specify either `id`, `title`, or `url` but not multiple.
28
+ : Server- or site-relative URL of the list. Specify either `id`, `title`,`url` or `default` but not multiple.
29
+
30
+ `--default`
31
+ : Set to retrieve the default list from the site. Specify either `id`, `title`, `url`, or `default` but not multiple.
29
32
 
30
33
  `-p, --properties [properties]`
31
34
  : Comma-separated list of properties to retrieve from the list. Will retrieve all properties possible from default response, if not specified.
@@ -42,6 +45,12 @@ When the `properties` option includes values with a `/`, for example: `ListItemA
42
45
 
43
46
  ## Examples
44
47
 
48
+ Get the default document library located in the specified site.
49
+
50
+ ```sh
51
+ m365 spo list get --webUrl https://contoso.sharepoint.com/sites/project-x --default
52
+ ```
53
+
45
54
  Get information about a list with specified ID located in the specified site.
46
55
 
47
56
  ```sh
@@ -0,0 +1,79 @@
1
+ import Global from '/docs/cmd/_global.mdx';
2
+ import Tabs from '@theme/Tabs';
3
+ import TabItem from '@theme/TabItem';
4
+
5
+ # spp model apply
6
+
7
+ Applies (or syncs) a trained document understanding model to a document library
8
+
9
+ ## Usage
10
+
11
+ ```sh
12
+ m365 spp model apply [options]
13
+ ```
14
+
15
+ ## Options
16
+
17
+ ```md definition-list
18
+ `-u, --webUrl <webUrl>`
19
+ : The URL of the web where the library is located.
20
+
21
+ `-c, --contentCenterUrl <contentCenterUrl>`
22
+ : The URL of the content center site where model is located.
23
+
24
+ `-i, --id [id]`
25
+ : The unique ID of the model. Specify either `id` or `title` but not both.
26
+
27
+ `-t, --title [title]`
28
+ : The display name of the model. Specify either `id` or `title` but not both.
29
+
30
+ `--listTitle [listTitle]`
31
+ : The title of the document library to which the model will be applied. Specify either `listTitle`, `listId`, or `listUrl` but not multiple.
32
+
33
+ `--listId [listId]`
34
+ : The ID of the library to which the model will be applied. Specify either `listTitle`, `listId`, or `listUrl` but not multiple.
35
+
36
+ `--listUrl [listUrl]`
37
+ : Server or web-relative URL of the library to which the model will be applied. Specify either `listTitle`, `listId`, or `listUrl` but not multiple.
38
+
39
+ `--viewOption [viewOption]`
40
+ : Defines whether the model view should be set as the default view for the document library. Allowed values are: `NewViewAsDefault`, `DoNotChangeDefault`, `TileViewAsDefault`. The default value is `NewViewAsDefault`.
41
+ ```
42
+
43
+ <Global />
44
+
45
+ ## Examples
46
+
47
+ Applies a trained document understanding model using its unique ID to a document library, identified by its title.
48
+
49
+ ```sh
50
+ m365 spp model apply --webUrl "https://contoso.sharepoint.com" --contentCenterUrl "https://contoso.sharepoint.com/sites/ContentCenter" --id "7645e69d-21fb-4a24-a17a-9bdfa7cb63dc" --listTitle "Shared Documents"
51
+ ```
52
+
53
+ Applies a trained document understanding model using its display name to a document library, identified by its title.
54
+
55
+ ```sh
56
+ m365 spp model apply --webUrl "https://contoso.sharepoint.com" --contentCenterUrl "https://contoso.sharepoint.com/sites/ContentCenter" --title "ModelExample" --listTitle "Shared Documents"
57
+ ```
58
+
59
+ Applies a trained document understanding model using its display name to a document library, identified by its URL.
60
+
61
+ ```sh
62
+ m365 spp model apply --webUrl "https://contoso.sharepoint.com" --contentCenterUrl "https://contoso.sharepoint.com/sites/ContentCenter" --title "ModelExample" --listUrl "/Shared Documents"
63
+ ```
64
+
65
+ Applies a trained document understanding model using its display name to a document library, identified by its unique ID.
66
+
67
+ ```sh
68
+ m365 spp model apply --webUrl "https://contoso.sharepoint.com" --contentCenterUrl "https://contoso.sharepoint.com/sites/ContentCenter" --title "ModelExample" --listId "b4cfa0d9-b3d7-49ae-a0f0-f14ffdd005f7"
69
+ ```
70
+
71
+ Applies a trained document understanding model using its display name to a document library, identified by its unique ID. Without changing a default document library view.
72
+
73
+ ```sh
74
+ m365 spp model apply --webUrl "https://contoso.sharepoint.com" --contentCenterUrl "https://contoso.sharepoint.com/sites/ContentCenter" --title "ModelExample" --listId "b4cfa0d9-b3d7-49ae-a0f0-f14ffdd005f7" --viewOption "DoNotChangeDefault"
75
+ ```
76
+
77
+ ## Response
78
+
79
+ The command won't return a response on success.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pnp/cli-microsoft365",
3
- "version": "10.8.0-beta.7160233",
3
+ "version": "10.8.0-beta.a1c69a6",
4
4
  "description": "Manage Microsoft 365 and SharePoint Framework projects on any platform",
5
5
  "license": "MIT",
6
6
  "main": "./dist/api.js",
@@ -177,7 +177,7 @@
177
177
  "Levert, Sebastien <slevert@outlook.com>",
178
178
  "Lingstuyl, Martin <mlingstuyl@live.com>",
179
179
  "Macháček, Martin <machacek@edhouse.cz>",
180
- "Maestrini Tobias <tobias@bee365.ch>",
180
+ "Maestrini, Tobias <tobias.maestrini@gmail.com>",
181
181
  "Maillot, Michaël <battosaimykle@gmail.com>",
182
182
  "Mastykarz, Waldek <waldek@mastykarz.nl>",
183
183
  "McDonnell, Kevin <kevin@mcd79.com>",