├── images └── demo.gif ├── appsscript.json ├── .codeclimate.yml ├── LICENCE ├── README.md └── ManifestsApp.js /images/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanaikech/ManifestsApp/HEAD/images/demo.gif -------------------------------------------------------------------------------- /appsscript.json: -------------------------------------------------------------------------------- 1 | { 2 | "timeZone": "Asia/Tokyo", 3 | "dependencies": { 4 | "libraries": [{ 5 | "userSymbol": "ProjectApp2", 6 | "libraryId": "11qqgrTfCEydqwIF8RRrSZOrdq-KNsIDnUpnYefX5KobaMMArVSlXUqwS", 7 | "version": "1", 8 | "developmentMode": true 9 | }] 10 | }, 11 | "exceptionLogging": "STACKDRIVER" 12 | } 13 | -------------------------------------------------------------------------------- /.codeclimate.yml: -------------------------------------------------------------------------------- 1 | --- 2 | engines: 3 | duplication: 4 | enabled: true 5 | config: 6 | languages: 7 | - ruby 8 | - javascript 9 | - python 10 | - php 11 | eslint: 12 | enabled: true 13 | fixme: 14 | enabled: true 15 | ratings: 16 | paths: 17 | - "**.inc" 18 | - "**.js" 19 | - "**.jsx" 20 | - "**.module" 21 | - "**.php" 22 | - "**.py" 23 | - "**.rb" 24 | exclude_paths: 25 | - "tests/" 26 | - "spec/" 27 | - "**/vendor/" 28 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2017 Kanshi TANAIKE 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ManifestsApp 2 | 3 | 4 | [![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENCE) 5 | 6 | 7 | 8 | # Overview 9 | 10 | **This is a Manifests library for Google Apps Scripts. This library can be used for the projects of both standalone script type and container-bound script type.** 11 | 12 | # Demo 13 | 14 | ![](images/demo.gif) 15 | 16 | In this demonstration, all scripts in a project are retrieved using `getProjectBlob()`. 17 | 18 | 19 | 20 | # Description 21 | 22 | By recent update of Google, [Manifests](https://developers.google.com/apps-script/concepts/manifests) was added to Google Apps Script Project. At the moment I saw the detail, I thought that this Manifests will blow a new wind for a lot of GAS developers. So I created this. If this was useful for you, I'm glad. 23 | 24 | And also, by recent update of Google, [Google Apps Script API](https://developers.google.com/apps-script/api/reference/rest/) was updated. By this, users got to be able to be easily to manage the GAS projects. For this, I created [ProjectApp2](https://github.com/tanaikech/ProjectApp2). This is also reflected to this library. 25 | 26 | # Before installing this library 27 | 28 | **IMPORTANT: Please check this.** 29 | 30 | At April 8, 2019, the specification of Google Apps Script Project was changed. By this, when new GAS project is created after April 8, 2019, in order to use Google API (Google Apps Script API and Drive API which can be used by ggsrun.), the GAS project is required to link to Cloud Platform Project. When you use the GAS project created after April 8, 2019, at first, **please do [this flow](https://gist.github.com/tanaikech/e945c10917fac34a9d5d58cad768832c)**. 31 | 32 | After the GAS project was linked to Cloud Platform Project by above flow, please do "Basic setting flow" at the next section. 33 | 34 | - [Ref1: Default Cloud Platform projects](https://developers.google.com/apps-script/guides/cloud-platform-projects#default_cloud_platform_projects) 35 | - [Ref2: Linking Cloud Platform Project to Google Apps Script Project](https://gist.github.com/tanaikech/e945c10917fac34a9d5d58cad768832c) 36 | 37 | # Library's project key 38 | 39 | ``` 40 | 1g0_wywpigtU_xA01D5IrRuBuDD5unieYl7nVXQR8DM_An0eUnB0NcTcx 41 | ``` 42 | 43 | 44 | 45 | # How to install 46 | 47 | 1. [Install ManifestsApp library](https://developers.google.com/apps-script/guides/libraries). 48 | - Library's project key is **`1g0_wywpigtU_xA01D5IrRuBuDD5unieYl7nVXQR8DM_An0eUnB0NcTcx`**. 49 | 1. Enable Drive API and Apps Script API at API console 50 | - On Cloud Platform project 51 | - View API console 52 | - At Getting started, click Enable APIs and get credentials like keys. 53 | - At left side, click Library. 54 | - At Search for APIs & services, input **Drive API**. And click Google Drive API. 55 | - Click Enable button. 56 | - If it has already been enabled, please don't turn off. 57 | - At left side, click Library. 58 | - At Search for APIs & services, input **Apps script**. And click Google Apps Script API. 59 | - Click Enable button. 60 | - If it has already been enabled, please don't turn off. 61 | 1. **Also here [https://script.google.com/home/usersettings](https://script.google.com/home/usersettings) has to be enabled. Please turn ON.** 62 | 63 | Installing is done! You can use ManifestsApp. 64 | 65 | [In the case of an error related to scopes, please check here.](#qa) 66 | 67 | ### How to enable APIs directly 68 | 69 | If you know project ID of the script that you use, you can directly access to the page to enable API using your browser. 70 | 71 | - For Drive API 72 | - `https://console.cloud.google.com/apis/api/drive.googleapis.com/?project=### project ID ###` 73 | - For Apps Script API 74 | - `https://console.cloud.google.com/apis/library/script.googleapis.com/?project=### project ID ###` 75 | 76 | ## About scopes 77 | 78 | About the install of scopes used at this library, users are not required to install scopes. Because this library can automatically install the required scopes to the project which installed this library. The detail information about this can be seen at [here](https://gist.github.com/tanaikech/23ddf599a4155b66f1029978bba8153b). 79 | 80 | --- 81 | 82 | 83 | 84 | # Usage 85 | 86 | Methods that ManifestsApp has are as follows. 87 | 88 | | Methods | Return | Descriptions | 89 | | :-------------------------------------------------------------- | :------- | :------------------------------------------------------------------------------------------------------------------------------ | 90 | | getManifestsRaw() | Object | Retrieve Raw Manifests data. | 91 | | setManifestsByRaw(manifests) | Object | Set Manifests by raw data with overwrite. | 92 | | getTimezone() | String | Retrieve Timezone. | 93 | | setTimezone(timeZone) | Object | Set Timezone with overwrite. | 94 | | getOauthScopes() | String[] | Retrieve OauthScopes. | 95 | | setOauthScopes(oauthScopes) | Object | Set OauthScopes with overwrite. | 96 | | getAdvancedServices() | Object | Retrieve AdvancedServices. | 97 | | enableAdvancedService(userSymbol, serviceId, version) | Object | Enable AdvancedServices. | 98 | | disableAdvancedService(serviceId) | Object | Disable AdvancedService. | 99 | | getLibraries() | Object | Retrieve Libraries. | 100 | | installLibrary(userSymbol, libraryId, version, developmentMode) | Object | Install Library. | 101 | | uninstallLibrary(userSymbol) | Object | Uninstall Library. | 102 | | getExceptionLogging() | String | Retrieve ExceptionLogging. | 103 | | setExceptionLogging(value) | Object | Set ExceptionLogging with overwrite. | 104 | | getWebapp() | Object | Retrieve Web App information. | 105 | | setWebapp(access, executeAs) | Object | Set Web App with overwrite. | 106 | | getUrlFetchWhitelist() | String[] | Retrieve UrlFetchWhitelist. | 107 | | setUrlFetchWhitelist(urlFetchWhitelist) | Object | Set UrlFetchWhitelist with overwrite. | 108 | | getGmail() | Object | Retrieve Gmail. | 109 | | setGmail(resources) | Object | Set Gmail with overwrite. | 110 | | getSheets() | Object | Retrieve Sheets. | 111 | | setSheets(resources) | Object | Set Sheets with overwrite. [Ref.](https://developers.google.com/apps-script/guides/sheets/macros#manifest_structure_for_macros) | 112 | | getRuntimeVersion() | Object | Retrieve Runtime version. | 113 | | setRuntimeVersion(value) | Object | Set resources which is string like 'STABLE', 'V8', 'DEPRECATED_ES5'. | 114 | 115 | You can also see the documents at the following URL. 116 | 117 | [https://script.google.com/macros/library/versions/d/1g0_wywpigtU_xA01D5IrRuBuDD5unieYl7nVXQR8DM_An0eUnB0NcTcx](https://script.google.com/macros/library/versions/d/1g0_wywpigtU_xA01D5IrRuBuDD5unieYl7nVXQR8DM_An0eUnB0NcTcx) 118 | 119 | And you can see the detail structure for each parameters at the following URL. 120 | 121 | [https://developers.google.com/apps-script/concepts/manifests](https://developers.google.com/apps-script/concepts/manifests) 122 | 123 | ## Samples 124 | 125 | When you want to retrieve Manifests as raw data (JSON), you can use scripts like below. 126 | 127 | ```javascript 128 | var ma = ManifestsApp.setProjectId(projectId); // Retrieve the instance 129 | var r = ma.getManifestsRaw(); 130 | Logger.log(r); 131 | ``` 132 | 133 | or 134 | 135 | ```javascript 136 | var r = ManifestsApp.setProjectId(projectId).getManifestsRaw(); 137 | Logger.log(r); 138 | ``` 139 | 140 | # Library used at ManifestsApp 141 | 142 | In order to manage Manifests, it is required to access GAS projects. For this, at first, I created [ProjectApp](https://github.com/tanaikech/ProjectApp). ManifestsApp has already used ProjectApp. So you are not necessary to install ProjectApp. 143 | 144 | --- 145 | 146 | 147 | 148 | # Q & A 149 | 150 | ## Q1: In the case of an error related to scopes 151 | 152 | Please confirm as follows. 153 | 154 | ### Confirmation: 1 155 | 156 | - About the scope 157 | - When you see the Scopes of project installed this library (**On script editor -> File -> Project properties -> Scopes**), if there are following scopes, the reason of error is not scopes. 158 | - `https://www.googleapis.com/auth/script.external_request` 159 | - `https://www.googleapis.com/auth/script.projects` 160 | 161 | ### Confirmation: 2 162 | 163 | If you cannot see above scopes at **On script editor -> File -> Project properties -> Scopes**, please do the following setting. 164 | 165 | - [Set scopes at Manifests](https://developers.google.com/apps-script/concepts/manifests) 166 | - On script editor 167 | - View -> Show manifest file 168 | - Add **"oauthScopes"** to "appsscript.json". After you installed the library and added the scopes to the default "appsscript.json", it becomes as follows. This timeZone is my current time zone. Of course, you can install the library by directly modifying "appsscript.json". 169 | 170 | ```json 171 | { 172 | "timeZone": "Asia/Tokyo", 173 | "dependencies": { 174 | "libraries": [ 175 | { 176 | "userSymbol": "ManifestsApp", 177 | "libraryId": "1g0_wywpigtU_xA01D5IrRuBuDD5unieYl7nVXQR8DM_An0eUnB0NcTcx", 178 | "version": "1", 179 | "developmentMode": true 180 | } 181 | ] 182 | }, 183 | "exceptionLogging": "STACKDRIVER", 184 | "oauthScopes": [ 185 | "https://www.googleapis.com/auth/script.external_request", 186 | "https://www.googleapis.com/auth/script.projects" 187 | ] 188 | } 189 | ``` 190 | 191 | ## Q2: In the case of error "Requested entity was not found." 192 | 193 | When you set Manifests using some values, if the following error occurs, 194 | 195 | ``` 196 | {"error":{"code":404,"message":"Requested entity was not found.","status":"NOT_FOUND"}} 197 | ``` 198 | 199 | Please confirm the values again. For example, when a library with no existing ID is installed, the error occurs. 200 | 201 | # Acknowledgements 202 | 203 | This application was featured by [mhawksey](https://github.com/mhawksey). Thank you so much. 204 | 205 | - The featured page is [here](https://mashe.hawksey.info/2017/11/everything-you-always-wanted-to-know-about-google-apps-script-manifest-files-but-were-afraid-to-ask/) 206 | 207 | 208 | 209 | # Licence 210 | 211 | [MIT](LICENCE) 212 | 213 | 214 | 215 | # Author 216 | 217 | [Tanaike](https://tanaikech.github.io/about/) 218 | 219 | If you have any questions and commissions for me, feel free to tell me. 220 | 221 | 222 | 223 | # Update History 224 | 225 | - v1.0.0 (November 9, 2017) 226 | 227 | Initial release. 228 | 229 | - v1.0.1 (November 23, 2017) 230 | 231 | - Added error messages. 232 | - Modified README.md 233 | - It reported that scopes used at this library can automatically install. 234 | - The detail information about this can be seen at [here](https://gist.github.com/tanaikech/23ddf599a4155b66f1029978bba8153b). 235 | 236 | - v1.0.2 (January 29, 2018) 237 | 238 | - [ProjectApp2](https://github.com/tanaikech/ProjectApp2) is published, and got to be able to use both standalone script type and container-bound script type. 239 | - By this, this library also got to be able to be used for the both projects. 240 | - For this update, please enable Apps Script API. 241 | - Please check ["How to install"](#HowToInstall). 242 | 243 | - v1.0.3 (July 11, 2018) 244 | 245 | - By Google's update, ["sheets" was added to manifests](https://developers.google.com/apps-script/guides/sheets/macros#manifest_structure_for_macros) for installing the configuration of Macro. By this, this library was updated. 246 | - You can see the added methods (getSheets(), setSheets()) at [Usage](#Usage). 247 | - If you set "sheets", please put the value of "sheets" as the resource like below sample. 248 | - `{"macros": [{"menuName": "QuickRowSum", "functionName": "calculateRowSum"}]}` 249 | - Don't put `{"sheets": {"macros": [{"menuName": "QuickRowSum", "functionName": "calculateRowSum"}]}}` 250 | 251 | - v1.0.4 (February 12, 2020) 252 | 253 | - "runtimeVersion" got to be able to be got and set. Now, 'STABLE', 'V8', 'DEPRECATED_ES5' can be used as the value of "runtimeVersion". For example, you can enable V8 with the following script. 254 | 255 | ```javascript 256 | var r = ManifestsApp.setProjectId(projectId).setRuntimeVersion("V8"); 257 | Logger.log(r); 258 | ``` 259 | 260 | - As one important point, when "STABLE" and "DEPRECATED_ES5" are used for the Google Apps Script project created before 2020 as the value of "runtimeVersion", the error of `Syntax error: Illegal character.` occurs. So please be careful this. This has been reported at [the issuetracker](https://issuetracker.google.com/issues/149341213). 261 | 262 | [TOP](#top) 263 | -------------------------------------------------------------------------------- /ManifestsApp.js: -------------------------------------------------------------------------------- 1 | /** 2 | * GitHub https://github.com/tanaikech/ManifestsApp
3 | * @param {String} Project ID 4 | * @return {ManifestsApp} 5 | */ 6 | function setProjectId(id) { 7 | this.projectId = id; 8 | return this 9 | } 10 | 11 | /** 12 | * Retrieve Raw Manifests data.
13 | * @return {Object} Return whole Manifests as a raw data. (JSON object) 14 | */ 15 | function getManifestsRaw() { 16 | return new ManifestsApp(this.projectId).getManifestsRaw(); 17 | } 18 | 19 | /** 20 | * Set Manifests by raw data.
21 | * @param {Object} manifests Whole raw manifests (JSON object) 22 | * @return {Object} Return project information. 23 | */ 24 | function setManifestsByRaw(manifests) { 25 | return new ManifestsApp(this.projectId).setManifestsByRaw(manifests); 26 | } 27 | 28 | /** 29 | * Retrieve Timezone.
30 | * @return {String} Return Timezone 31 | */ 32 | function getTimezone() { 33 | return new ManifestsApp(this.projectId).getTimezone(); 34 | } 35 | 36 | /** 37 | * Set Timezone.
38 | * @param {String} timeZone Timezone 39 | * @return {Object} Return project information. 40 | */ 41 | function setTimezone(timeZone) { 42 | return new ManifestsApp(this.projectId).setTimezone(timeZone); 43 | } 44 | 45 | /** 46 | * Retrieve OauthScopes.
47 | * @return {String[]} Return OauthScopes. 48 | */ 49 | function getOauthScopes() { 50 | return new ManifestsApp(this.projectId).getOauthScopes(); 51 | } 52 | 53 | /** 54 | * Set OauthScopes.
55 | * @param {String[]} oauthScopes OauthScopes 56 | * @return {Object} Return project information. 57 | */ 58 | function setOauthScopes(oauthScopes) { 59 | return new ManifestsApp(this.projectId).setOauthScopes(oauthScopes); 60 | } 61 | 62 | /** 63 | * Retrieve AdvancedServices.
64 | * @return {Object} Return AdvancedServices as JSON. 65 | */ 66 | function getAdvancedServices() { 67 | return new ManifestsApp(this.projectId).getAdvancedServices(); 68 | } 69 | 70 | /** 71 | * Enable AdvancedServices.
72 | * @param {String} userSymbol userSymbol 73 | * @param {String} serviceId serviceId 74 | * @param {String} version version 75 | * @return {Object} Return project information. 76 | */ 77 | function enableAdvancedService(userSymbol, serviceId, version) { 78 | return new ManifestsApp(this.projectId).enableAdvancedService(userSymbol, serviceId, version); 79 | } 80 | 81 | /** 82 | * Disable AdvancedService.
83 | * @param {String} serviceId serviceId that you want to disable. 84 | * @return {Object} Return project information. 85 | */ 86 | function disableAdvancedService(serviceId) { 87 | return new ManifestsApp(this.projectId).disableAdvancedService(serviceId); 88 | } 89 | 90 | /** 91 | * Retrieve Libraries.
92 | * @return {Object} Return Libraries as JSON. 93 | */ 94 | function getLibraries() { 95 | return new ManifestsApp(this.projectId).getLibraries(); 96 | } 97 | 98 | /** 99 | * Install Library.
100 | * @param {String} userSymbol userSymbol 101 | * @param {String} libraryId libraryId 102 | * @param {String} version version 103 | * @param {Boolean} developmentMode developmentMode 104 | * @return {Object} Return project information. 105 | */ 106 | function installLibrary(userSymbol, libraryId, version, developmentMode) { 107 | return new ManifestsApp(this.projectId).installLibrary(userSymbol, libraryId, version, developmentMode); 108 | } 109 | 110 | /** 111 | * Uninstall Library.
112 | * @param {String} userSymbol userSymbol that you want to uninstall. 113 | * @return {Object} Return project information. 114 | */ 115 | function uninstallLibrary(userSymbol) { 116 | return new ManifestsApp(this.projectId).uninstallLibrary(userSymbol); 117 | } 118 | 119 | /** 120 | * Retrieve ExceptionLogging.
121 | * @return {String} Return ExceptionLogging. 122 | */ 123 | function getExceptionLogging() { 124 | return new ManifestsApp(this.projectId).getExceptionLogging(); 125 | } 126 | 127 | /** 128 | * Set ExceptionLogging.
129 | * @param {String} value value 130 | * @return {Object} Return project information. 131 | */ 132 | function setExceptionLogging(value) { 133 | return new ManifestsApp(this.projectId).setExceptionLogging(value); 134 | } 135 | 136 | /** 137 | * Retrieve Web App information.
138 | * @return {Object} Return Web App information as JSON. 139 | */ 140 | function getWebapp() { 141 | return new ManifestsApp(this.projectId).getWebapp(); 142 | } 143 | 144 | /** 145 | * Set Web App.
146 | * @param {String} access access 147 | * @param {String} executeAs executeAs 148 | * @return {Object} Return project information. 149 | */ 150 | function setWebapp(access, executeAs) { 151 | return new ManifestsApp(this.projectId).setWebapp(access, executeAs); 152 | } 153 | 154 | /** 155 | * Retrieve UrlFetchWhitelist.
156 | * @return {Object} Return UrlFetchWhitelist as an array. 157 | */ 158 | function getUrlFetchWhitelist() { 159 | return new ManifestsApp(this.projectId).getUrlFetchWhitelist(); 160 | } 161 | 162 | /** 163 | * Set UrlFetchWhitelist.
164 | * @param {Object} urlFetchWhitelist urlFetchWhitelist which is 1 dimensional array. 165 | * @return {Object} Return project information. 166 | */ 167 | function setUrlFetchWhitelist(urlFetchWhitelist) { 168 | return new ManifestsApp(this.projectId).setUrlFetchWhitelist(urlFetchWhitelist); 169 | } 170 | 171 | /** 172 | * Retrieve Gmail.
173 | * @return {Object} Return Gmail as JSON. 174 | */ 175 | function getGmail() { 176 | return new ManifestsApp(this.projectId).getGmail(); 177 | } 178 | 179 | /** 180 | * Set Gmail.
181 | * @param {Object} resources resources which is JSON. 182 | * @return {Object} Return project information. 183 | */ 184 | function setGmail(resources) { 185 | return new ManifestsApp(this.projectId).setGmail(resources); 186 | } 187 | 188 | /** 189 | * Retrieve Sheets.
190 | * @return {Object} Return Sheets as JSON. 191 | */ 192 | function getSheets() { 193 | return new ManifestsApp(this.projectId).getSheets(); 194 | } 195 | 196 | /** 197 | * Set Sheets.
198 | * @param {Object} resources resources which is JSON. 199 | * @return {Object} Return project information. 200 | */ 201 | function setSheets(resources) { 202 | return new ManifestsApp(this.projectId).setSheets(resources); 203 | } 204 | 205 | /** 206 | * Retrieve Runtime version.
207 | * @return {Object} Return Runtime version as string. 208 | */ 209 | function getRuntimeVersion() { 210 | return new ManifestsApp(this.projectId).getRuntimeVersion(); 211 | } 212 | 213 | /** 214 | * Set Runtime version.
215 | * @param {String} value value which is string like 'STABLE', 'V8', 'DEPRECATED_ES5'. 216 | * @return {Object} Return project information. 217 | */ 218 | function setRuntimeVersion(value) { 219 | return new ManifestsApp(this.projectId).setRuntimeVersion(value); 220 | } 221 | ; 222 | (function(r) { 223 | var ManifestsApp; 224 | ManifestsApp = (function() { 225 | var getSrc, makeBlob; 226 | 227 | ManifestsApp.name = "ManifestsApp"; 228 | 229 | function ManifestsApp(p_) { 230 | if (p_ == null) { 231 | throw new Error("No project ID."); 232 | } 233 | this.projectId = p_; 234 | this.reference = "https://developers.google.com/apps-script/concepts/manifests"; 235 | } 236 | 237 | ManifestsApp.prototype.getManifestsRaw = function() { 238 | var e, j, len, raw, rawManifects, ref; 239 | raw = ProjectApp2.getProjectRaw(this.projectId); 240 | rawManifects = {}; 241 | ref = raw.files; 242 | for (j = 0, len = ref.length; j < len; j++) { 243 | e = ref[j]; 244 | if (e.name === "appsscript") { 245 | rawManifects = e; 246 | } 247 | } 248 | return rawManifects; 249 | }; 250 | 251 | ManifestsApp.prototype.setManifestsByRaw = function(manifests_) { 252 | if (manifests_ == null) { 253 | throw new Error("No JSON manifests. Reference is " + this.reference); 254 | } 255 | return ProjectApp2.updateProjectByBlob(this.projectId, makeBlob.call(this, manifests_)); 256 | }; 257 | 258 | ManifestsApp.prototype.getTimezone = function() { 259 | var src; 260 | src = getSrc.call(this); 261 | return src.timeZone; 262 | }; 263 | 264 | ManifestsApp.prototype.setTimezone = function(timeZone_) { 265 | var src; 266 | if (timeZone_ == null) { 267 | throw new Error("No timeZone. Reference is " + this.reference); 268 | } 269 | src = getSrc.call(this); 270 | src.timeZone = timeZone_; 271 | return ProjectApp2.updateProjectByBlob(this.projectId, makeBlob.call(this, src)); 272 | }; 273 | 274 | ManifestsApp.prototype.getOauthScopes = function() { 275 | var src; 276 | src = getSrc.call(this); 277 | return src.oauthScopes; 278 | }; 279 | 280 | ManifestsApp.prototype.setOauthScopes = function(oauthScopes_) { 281 | var src; 282 | if (oauthScopes_ == null) { 283 | throw new Error("No oauthScopes. Reference is " + this.reference); 284 | } 285 | if (!Array.isArray(oauthScopes_)) { 286 | throw new Error("'oauthScopes' has to be an array. Reference is " + this.reference); 287 | } 288 | src = getSrc.call(this); 289 | src.oauthScopes = oauthScopes_; 290 | return ProjectApp2.updateProjectByBlob(this.projectId, makeBlob.call(this, src)); 291 | }; 292 | 293 | ManifestsApp.prototype.getAdvancedServices = function() { 294 | var src; 295 | src = getSrc.call(this); 296 | return src.dependencies.enabledAdvancedServices; 297 | }; 298 | 299 | ManifestsApp.prototype.enableAdvancedService = function(userSymbol_, serviceId_, version_) { 300 | var current, e, j, len, src; 301 | if (userSymbol_ == null) { 302 | throw new Error("No userSymbol. Reference is " + this.reference); 303 | } 304 | if (serviceId_ == null) { 305 | throw new Error("No serviceId. Reference is " + this.reference); 306 | } 307 | if (version_ == null) { 308 | throw new Error("No version. Reference is " + this.reference); 309 | } 310 | src = getSrc.call(this); 311 | current = src.dependencies.enabledAdvancedServices; 312 | if (current != null) { 313 | for (j = 0, len = current.length; j < len; j++) { 314 | e = current[j]; 315 | if (e.userSymbol === userSymbol_ && e.serviceId === serviceId_ && e.version === version_) { 316 | throw new Error("Service with " + userSymbol_ + ", " + serviceId_ + " and " + version_ + " has already been enabled."); 317 | } 318 | } 319 | } else { 320 | src.dependencies.enabledAdvancedServices = []; 321 | } 322 | src.dependencies.enabledAdvancedServices.push({ 323 | userSymbol: userSymbol_, 324 | serviceId: serviceId_, 325 | version: version_ 326 | }); 327 | return ProjectApp2.updateProjectByBlob(this.projectId, makeBlob.call(this, src)); 328 | }; 329 | 330 | ManifestsApp.prototype.disableAdvancedService = function(serviceId_) { 331 | var current, dis, e, i, j, len, src; 332 | if (serviceId_ == null) { 333 | throw new Error("No serviceId. Reference is " + this.reference); 334 | } 335 | src = getSrc.call(this); 336 | current = JSON.parse(JSON.stringify(src.dependencies.enabledAdvancedServices)); 337 | dis = false; 338 | if (current != null) { 339 | for (i = j = 0, len = current.length; j < len; i = ++j) { 340 | e = current[i]; 341 | if (e.serviceId === serviceId_) { 342 | src.dependencies.enabledAdvancedServices.splice(i, 1); 343 | if (src.dependencies.enabledAdvancedServices.length === 0) { 344 | delete src.dependencies["enabledAdvancedServices"]; 345 | } 346 | dis = true; 347 | break; 348 | } 349 | } 350 | if (!dis) { 351 | throw new Error("Service of " + serviceId_ + " is not enabled yet."); 352 | } 353 | } else { 354 | throw new Error("No enabled services."); 355 | } 356 | return ProjectApp2.updateProjectByBlob(this.projectId, makeBlob.call(this, src)); 357 | }; 358 | 359 | ManifestsApp.prototype.getLibraries = function() { 360 | var src; 361 | src = getSrc.call(this); 362 | return src.dependencies.libraries; 363 | }; 364 | 365 | ManifestsApp.prototype.installLibrary = function(userSymbol_, libraryId_, version_, developmentMode_) { 366 | var current, e, j, len, src; 367 | if (userSymbol_ == null) { 368 | throw new Error("No userSymbol. Reference is " + this.reference); 369 | } 370 | if (libraryId_ == null) { 371 | throw new Error("No libraryId. Reference is " + this.reference); 372 | } 373 | if (version_ == null) { 374 | throw new Error("No version. Reference is " + this.reference); 375 | } 376 | if (developmentMode_ != null) { 377 | developmentMode_; 378 | } else { 379 | true; 380 | } 381 | src = getSrc.call(this); 382 | current = src.dependencies.libraries; 383 | if (current != null) { 384 | for (j = 0, len = current.length; j < len; j++) { 385 | e = current[j]; 386 | if (e.userSymbol === userSymbol_) { 387 | throw new Error("Library with " + userSymbol_ + ", " + libraryId_ + " and " + version_ + " has already been installed."); 388 | } 389 | } 390 | } else { 391 | src.dependencies.libraries = []; 392 | } 393 | src.dependencies.libraries.push({ 394 | userSymbol: userSymbol_, 395 | libraryId: libraryId_, 396 | version: version_, 397 | developmentMode: developmentMode_ 398 | }); 399 | return ProjectApp2.updateProjectByBlob(this.projectId, makeBlob.call(this, src)); 400 | }; 401 | 402 | ManifestsApp.prototype.uninstallLibrary = function(userSymbol_) { 403 | var current, dis, e, i, j, len, src; 404 | if (userSymbol_ == null) { 405 | throw new Error("No userSymbol. Reference is " + this.reference); 406 | } 407 | src = getSrc.call(this); 408 | current = JSON.parse(JSON.stringify(src.dependencies.libraries)); 409 | dis = false; 410 | if (current != null) { 411 | for (i = j = 0, len = current.length; j < len; i = ++j) { 412 | e = current[i]; 413 | if (e.userSymbol === userSymbol_) { 414 | src.dependencies.libraries.splice(i, 1); 415 | if (src.dependencies.libraries.length === 0) { 416 | delete src.dependencies["libraries"]; 417 | } 418 | dis = true; 419 | break; 420 | } 421 | } 422 | if (!dis) { 423 | throw new Error("Library of " + userSymbol_ + " is not installed yet."); 424 | } 425 | } else { 426 | throw new Error("No installed libraries."); 427 | } 428 | return ProjectApp2.updateProjectByBlob(this.projectId, makeBlob.call(this, src)); 429 | }; 430 | 431 | ManifestsApp.prototype.getExceptionLogging = function() { 432 | var src; 433 | src = getSrc.call(this); 434 | return src.exceptionLogging; 435 | }; 436 | 437 | ManifestsApp.prototype.setExceptionLogging = function(value_) { 438 | var src; 439 | if (value_ == null) { 440 | throw new Error("No value. Reference is " + this.reference); 441 | } 442 | src = getSrc.call(this); 443 | src.exceptionLogging = value_; 444 | return ProjectApp2.updateProjectByBlob(this.projectId, makeBlob.call(this, src)); 445 | }; 446 | 447 | ManifestsApp.prototype.getWebapp = function() { 448 | var src; 449 | src = getSrc.call(this); 450 | return src.webapp; 451 | }; 452 | 453 | ManifestsApp.prototype.setWebapp = function(access_, executeAs_) { 454 | var src; 455 | if (access_ == null) { 456 | throw new Error("No access. Reference is " + this.reference); 457 | } 458 | if (executeAs_ == null) { 459 | throw new Error("No executeAs. Reference is " + this.reference); 460 | } 461 | src = getSrc.call(this); 462 | if (!src.webapp) { 463 | src.webapp = {}; 464 | } 465 | src.webapp.access = access_; 466 | src.webapp.executeAs = executeAs_; 467 | return ProjectApp2.updateProjectByBlob(this.projectId, makeBlob.call(this, src)); 468 | }; 469 | 470 | ManifestsApp.prototype.getUrlFetchWhitelist = function() { 471 | var src; 472 | src = getSrc.call(this); 473 | return src.urlFetchWhitelist; 474 | }; 475 | 476 | ManifestsApp.prototype.setUrlFetchWhitelist = function(urlFetchWhitelist_) { 477 | var src; 478 | if (urlFetchWhitelist_ == null) { 479 | throw new Error("No urlFetchWhitelist. Reference is " + this.reference); 480 | } 481 | if (!Array.isArray(urlFetchWhitelist_)) { 482 | throw new Error("'urlFetchWhitelist' has to be an array. Reference is " + this.reference); 483 | } 484 | src = getSrc.call(this); 485 | src.urlFetchWhitelist = urlFetchWhitelist_; 486 | return ProjectApp2.updateProjectByBlob(this.projectId, makeBlob.call(this, src)); 487 | }; 488 | 489 | ManifestsApp.prototype.getGmail = function() { 490 | var src; 491 | src = getSrc.call(this); 492 | return src.gmail; 493 | }; 494 | 495 | ManifestsApp.prototype.setGmail = function(resources_) { 496 | var src; 497 | if (resources_ == null) { 498 | throw new Error("No resources. Reference is " + this.reference); 499 | } 500 | if (typeof resources_ !== "object") { 501 | throw new Error("'resources' has to be a nested object. Reference is " + this.reference); 502 | } 503 | src = getSrc.call(this); 504 | src.gmail = resources_; 505 | return ProjectApp2.updateProjectByBlob(this.projectId, makeBlob.call(this, src)); 506 | }; 507 | 508 | ManifestsApp.prototype.getSheets = function() { 509 | var src; 510 | src = getSrc.call(this); 511 | return src.sheets; 512 | }; 513 | 514 | ManifestsApp.prototype.setSheets = function(resources_) { 515 | var src; 516 | if (resources_ == null) { 517 | throw new Error("No resources. Reference is " + this.reference); 518 | } 519 | if (typeof resources_ !== "object") { 520 | throw new Error("'resources' has to be a nested object. Reference is " + this.reference); 521 | } 522 | src = getSrc.call(this); 523 | src.sheets = resources_; 524 | return ProjectApp2.updateProjectByBlob(this.projectId, makeBlob.call(this, src)); 525 | }; 526 | 527 | ManifestsApp.prototype.getRuntimeVersion = function() { 528 | var src; 529 | src = getSrc.call(this); 530 | return src.runtimeVersion; 531 | }; 532 | 533 | ManifestsApp.prototype.setRuntimeVersion = function(resources_) { 534 | var src; 535 | if (resources_ == null) { 536 | throw new Error("No resources. Reference is " + this.reference); 537 | } 538 | if (typeof resources_ !== "string") { 539 | throw new Error("'resources' has to be a string like 'STABLE', 'V8', 'DEPRECATED_ES5'. Reference is " + this.reference); 540 | } 541 | src = getSrc.call(this); 542 | resources_ = resources_.toUpperCase(); 543 | src.runtimeVersion = resources_; 544 | return ProjectApp2.updateProjectByBlob(this.projectId, makeBlob.call(this, src)); 545 | }; 546 | 547 | makeBlob = function(raw_) { 548 | return Utilities.newBlob(JSON.stringify(raw_, null, " ")).setName("appsscript.json"); 549 | }; 550 | 551 | getSrc = function() { 552 | var e; 553 | try { 554 | return JSON.parse((this.getManifestsRaw(this.projectId)).source); 555 | } catch (error) { 556 | e = error; 557 | if (~e.toString().indexOf("Unexpected token")) { 558 | throw new Error("Cannot find Manifest file. Please show Manifest file at the project you want to access. (On the script editor, View -> Show manifest file)"); 559 | } 560 | } 561 | }; 562 | 563 | return ManifestsApp; 564 | 565 | })(); 566 | return r.ManifestsApp = ManifestsApp; 567 | })(this); 568 | --------------------------------------------------------------------------------