diff --git a/docs/docs/cmd/spo/sitescript/sitescript-get.mdx b/docs/docs/cmd/spo/sitescript/sitescript-get.mdx index 7fcb07f2341..27f51cfa6c3 100644 --- a/docs/docs/cmd/spo/sitescript/sitescript-get.mdx +++ b/docs/docs/cmd/spo/sitescript/sitescript-get.mdx @@ -17,6 +17,9 @@ m365 spo sitescript get [options] ```md definition-list `-i, --id ` : Site script ID + +`-c, --content` +: Specify to only retrieve the content of the site script. ``` @@ -33,8 +36,16 @@ Get information about the site script with ID _2c1ba4c4-cd9b-4417-832f-92a34bc34 m365 spo sitescript get --id 2c1ba4c4-cd9b-4417-832f-92a34bc34b2a ``` +Returns the site script contents: + +```sh +m365 spo sitescript get --id 2c1ba4c4-cd9b-4417-832f-92a34bc34b2a --content +``` + ## Response +### Standard response + @@ -67,7 +78,8 @@ m365 spo sitescript get --id 2c1ba4c4-cd9b-4417-832f-92a34bc34b2a ```csv - + Content,Id,IsSiteScriptPackage,Title,Version + "{\"$schema\":\"https://developer.microsoft.com/json-schemas/sp/site-design-script-actions.schema.json\",\"actions\":[{\"verb\":\"activateSPFeature\",\"name\":\"SiteNotebook feature\",\"title\":\"SiteNotebook feature\",\"featureId\":\"f151bb39-7c3b-414f-bb36-6bf18872052f\",\"scope\":\"web\"}],\"bindata\":{},\"version\":1}",43d4ffa0-c7ee-4a97-91d7-db27e5b62de5,,Contoso,1 ``` @@ -93,6 +105,64 @@ m365 spo sitescript get --id 2c1ba4c4-cd9b-4417-832f-92a34bc34b2a +### `content` response + +When we make use of the option `content` the response will differ. + + + + + ```json + { + "$schema": "https://developer.microsoft.com/json-schemas/sp/site-design-script-actions.schema.json", + "actions": [ + { + "verb":"activateSPFeature", + "name": "SiteNotebook feature", + "title": "SiteNotebook feature", + "featureId": "f151bb39-7c3b-414f-bb36-6bf18872052f", + "scope": "web" + } + ], + "bindata":{}, + "version":1 + } + ``` + + + + + ```text + $schema : https://developer.microsoft.com/json-schemas/sp/site-design-script-actions.schema.json + actions : [{"verb":"createSPList","listName":"Customer Tracking","templateType":100,"subactions":[{"verb":"setDescription","description":"List of Customers and Orders"},{"verb":"addSPField","fieldType":"Text","displayName":"Customer Name","isRequired":false,"addToDefaultView":true},{"verb":"addSPField","fieldType":"Number","displayName":"Requisition Total","addToDefaultView":true,"isRequired":true},{"verb":"addSPField","fieldType":"User","displayName":"Contact","addToDefaultView":true,"isRequired":true},{"verb":"addSPField","fieldType":"Note","displayName":"Meeting Notes","isRequired":false}]}] + version : 1 + ``` + + + + + ```csv + $schema,version + https://developer.microsoft.com/json-schemas/sp/site-design-script-actions.schema.json,1 + ``` + + + + + ```md + # spo sitescript get --id "43d4ffa0-c7ee-4a97-91d7-db27e5b62de5" --content "true" + + Date: 2023-06-22 + + Property | Value + ---------|------- + $schema | https://developer.microsoft.com/json-schemas/sp/site-design-script-actions.schema.json + version | 1 + ``` + + + + ## More information - SharePoint site design and site script overview: [https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/site-design-overview](https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/site-design-overview) diff --git a/src/m365/spo/commands/sitescript/sitescript-get.spec.ts b/src/m365/spo/commands/sitescript/sitescript-get.spec.ts index 57161423449..be1584cc665 100644 --- a/src/m365/spo/commands/sitescript/sitescript-get.spec.ts +++ b/src/m365/spo/commands/sitescript/sitescript-get.spec.ts @@ -101,7 +101,7 @@ describe(commands.SITESCRIPT_GET, () => { }); await command.action(logger, { options: { id: '0f27a016-d277-4bb4-b3c3-b5b040c9559b' } }); - assert(loggerLogSpy.calledWith({ + assert(loggerLogSpy.calledOnceWithExactly({ "Content": JSON.stringify({ "$schema": "schema.json", "actions": [ @@ -149,7 +149,7 @@ describe(commands.SITESCRIPT_GET, () => { }); await command.action(logger, { options: { debug: true, id: '0f27a016-d277-4bb4-b3c3-b5b040c9559b' } }); - assert(loggerLogSpy.calledWith({ + assert(loggerLogSpy.calledOnceWithExactly({ "Content": JSON.stringify({ "$schema": "schema.json", "actions": [ @@ -168,6 +168,48 @@ describe(commands.SITESCRIPT_GET, () => { })); }); + it('gets the specified site script contentss', async () => { + sinon.stub(request, 'post').callsFake(async (opts) => { + if ((opts.url as string).indexOf(`/_api/Microsoft.Sharepoint.Utilities.WebTemplateExtensions.SiteScriptUtility.GetSiteScriptMetadata`) > -1 && + JSON.stringify(opts.data) === JSON.stringify({ + id: '0f27a016-d277-4bb4-b3c3-b5b040c9559b' + })) { + return { + "Content": JSON.stringify({ + "$schema": "schema.json", + "actions": [ + { + "verb": "applyTheme", + "themeName": "Contoso Theme" + } + ], + "bindata": {}, + "version": 1 + }), + "Description": "My contoso script", + "Id": "0f27a016-d277-4bb4-b3c3-b5b040c9559b", + "Title": "Contoso", + "Version": 1 + }; + } + + throw 'Invalid request'; + }); + + await command.action(logger, { options: { id: '0f27a016-d277-4bb4-b3c3-b5b040c9559b', content: true } }); + assert(loggerLogSpy.calledOnceWithExactly({ + "$schema": "schema.json", + "actions": [ + { + "verb": "applyTheme", + "themeName": "Contoso Theme" + } + ], + "bindata": {}, + "version": 1 + })); + }); + it('correctly handles error when site script not found', async () => { sinon.stub(request, 'post').rejects({ error: { 'odata.error': { message: { value: 'File Not Found.' } } } }); diff --git a/src/m365/spo/commands/sitescript/sitescript-get.ts b/src/m365/spo/commands/sitescript/sitescript-get.ts index 7f02d0f7eb6..17b6a2e77a0 100644 --- a/src/m365/spo/commands/sitescript/sitescript-get.ts +++ b/src/m365/spo/commands/sitescript/sitescript-get.ts @@ -12,6 +12,7 @@ interface CommandArgs { interface Options extends GlobalOptions { id: string; + content?: boolean; } class SpoSiteScriptGetCommand extends SpoCommand { @@ -34,6 +35,9 @@ class SpoSiteScriptGetCommand extends SpoCommand { this.options.unshift( { option: '-i, --id ' + }, + { + option: '-c, --content' } ); } @@ -65,8 +69,13 @@ class SpoSiteScriptGetCommand extends SpoCommand { responseType: 'json' }; - const res: any = await request.post(requestOptions); - await logger.log(res); + const response: any = await request.post(requestOptions); + + if (args.options.content === true) { + return await logger.log(JSON.parse(response.Content)); + } + + await logger.log(response); } catch (err: any) { this.handleRejectedODataJsonPromise(err);