@google/clasp 3.1.0 → 3.1.3
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.
- package/README.md +14 -0
- package/build/src/auth/auth.js +1 -1
- package/build/src/auth/localhost_auth_code_flow.js +2 -1
- package/build/src/auth/serverless_auth_code_flow.js +4 -2
- package/build/src/commands/login.js +2 -1
- package/build/src/commands/validate.js +39 -0
- package/docs/run.md +2 -2
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Clasp
|
|
2
2
|
|
|
3
|
+
Note: This is not an officially support Google product.
|
|
4
|
+
|
|
3
5
|

|
|
4
6
|
<a href="https://coveralls.io/github/google/clasp?branch=master"><img src="https://coveralls.io/repos/github/google/clasp/badge.svg?branch=master" alt="Coverage Status"></a>
|
|
5
7
|
<a href="https://www.npmjs.com/package/@google/clasp"><img src="https://img.shields.io/npm/v/@google/clasp.svg" alt="npm Version"></a>
|
|
@@ -64,6 +66,18 @@ Then enable the Google Apps Script API: https://script.google.com/home/usersetti
|
|
|
64
66
|
|
|
65
67
|

|
|
66
68
|
|
|
69
|
+
### Installing as a Gemini CLI Extension
|
|
70
|
+
|
|
71
|
+
You can install clasp as an Gemini CLI extensions using the following command:
|
|
72
|
+
|
|
73
|
+
```sh
|
|
74
|
+
gemini extensions install https://github.com/google/clasp
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
This makes clasp available as an MCP server in Gemini CLI.
|
|
78
|
+
|
|
79
|
+
Make sure to enable the Google Apps Script API (as explained above) and perform a `clasp login` (with your specific login parameters) before you use the extension.
|
|
80
|
+
|
|
67
81
|
## Commands
|
|
68
82
|
|
|
69
83
|
The following command provide basic Apps Script project management.
|
package/build/src/auth/auth.js
CHANGED
|
@@ -135,7 +135,7 @@ export async function authorize(options) {
|
|
|
135
135
|
}
|
|
136
136
|
else {
|
|
137
137
|
debug('Starting auth with local server flow');
|
|
138
|
-
flow = new LocalServerAuthorizationCodeFlow(options.oauth2Client);
|
|
138
|
+
flow = new LocalServerAuthorizationCodeFlow(options.oauth2Client, options.redirectPort);
|
|
139
139
|
}
|
|
140
140
|
const client = await flow.authorize(options.scopes);
|
|
141
141
|
await saveOauthClientCredentials(options.store, options.userKey, client);
|
|
@@ -26,9 +26,10 @@ import { AuthorizationCodeFlow, parseAuthResponseUrl } from './auth_code_flow.js
|
|
|
26
26
|
* authorization code.
|
|
27
27
|
*/
|
|
28
28
|
export class LocalServerAuthorizationCodeFlow extends AuthorizationCodeFlow {
|
|
29
|
-
constructor(oauth2client) {
|
|
29
|
+
constructor(oauth2client, port) {
|
|
30
30
|
super(oauth2client);
|
|
31
31
|
this.port = 0;
|
|
32
|
+
this.port = port;
|
|
32
33
|
}
|
|
33
34
|
/**
|
|
34
35
|
* Starts a local HTTP server and returns its address as the redirect URI.
|
|
@@ -44,12 +44,14 @@ export class ServerlessAuthorizationCodeFlow extends AuthorizationCodeFlow {
|
|
|
44
44
|
* @throws {Error} If the pasted URL contains an error or no code.
|
|
45
45
|
*/
|
|
46
46
|
async promptAndReturnCode(authorizationUrl) {
|
|
47
|
-
const
|
|
47
|
+
const urlMessage = intl.formatMessage({ id: "7EHKbR", defaultMessage: [{ type: 0, value: "\uD83D\uDD11 Authorize clasp by visiting this url: " }, { type: 1, value: "url" }] }, {
|
|
48
48
|
url: authorizationUrl,
|
|
49
49
|
});
|
|
50
|
+
console.log(urlMessage);
|
|
51
|
+
const promptMessage = intl.formatMessage({ id: "xADuBP", defaultMessage: [{ type: 0, value: "After authorizing, copy the URL from your browser and paste it here:" }] });
|
|
50
52
|
const answer = await inquirer.prompt([
|
|
51
53
|
{
|
|
52
|
-
message:
|
|
54
|
+
message: promptMessage,
|
|
53
55
|
name: 'url',
|
|
54
56
|
type: 'input',
|
|
55
57
|
},
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
import { Command } from 'commander';
|
|
19
19
|
import { authorize, getUnauthorizedOuth2Client, getUserInfo } from '../auth/auth.js';
|
|
20
20
|
import { intl } from '../intl.js';
|
|
21
|
+
import { validateOptionInt } from './validate.js';
|
|
21
22
|
const DEFAULT_SCOPES = [
|
|
22
23
|
// Default to clasp scopes
|
|
23
24
|
'https://www.googleapis.com/auth/script.deployments', // Apps Script deployments
|
|
@@ -36,7 +37,7 @@ export const command = new Command('login')
|
|
|
36
37
|
.option('--no-localhost', 'Do not run a local server, manually enter code instead')
|
|
37
38
|
.option('--creds <file>', 'Relative path to OAuth client secret file (from GCP).')
|
|
38
39
|
.option('--use-project-scopes', 'Use the scopes from the current project manifest. Used only when authorizing access for the run command.')
|
|
39
|
-
.option('--redirect-port <port>', 'Specify a custom port for the redirect URL.')
|
|
40
|
+
.option('--redirect-port <port>', 'Specify a custom port for the redirect URL.', val => validateOptionInt(val, 0, 65535))
|
|
40
41
|
.action(async function () {
|
|
41
42
|
var _a;
|
|
42
43
|
const options = this.optsWithGlobals();
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Copyright 2025 Google LLC
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
// This module provides validatition functions for commandline options and arguments
|
|
15
|
+
import { InvalidOptionArgumentError } from 'commander';
|
|
16
|
+
/**
|
|
17
|
+
* Validates if the value is an integer.
|
|
18
|
+
* If the startInclusive and endInclusive parameters are provided, additional check against the bounds
|
|
19
|
+
*
|
|
20
|
+
* @returns {number} The valid integer value.
|
|
21
|
+
* @throws {InvalidOptionArgumentError} If value is not an integer or out of bounds.
|
|
22
|
+
*/
|
|
23
|
+
export const validateOptionInt = (val, startInclusive, endInclusive) => {
|
|
24
|
+
let errorMsg = '';
|
|
25
|
+
// Commander already handles the case where the option was provided with no argument
|
|
26
|
+
if (val) {
|
|
27
|
+
if (!Number.isInteger(Number(val))) {
|
|
28
|
+
errorMsg = `'${val}' is not a valid integer.`;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
if (startInclusive != null && endInclusive != null && (val < startInclusive || val > endInclusive)) {
|
|
32
|
+
errorMsg = `'${val}' should be >= ${startInclusive} and <= ${endInclusive}.`;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (errorMsg)
|
|
36
|
+
throw new InvalidOptionArgumentError(errorMsg);
|
|
37
|
+
}
|
|
38
|
+
return val;
|
|
39
|
+
};
|
package/docs/run.md
CHANGED
|
@@ -67,7 +67,7 @@ After setup, you can remotely execute Apps Script functions from `clasp`:
|
|
|
67
67
|
|
|
68
68
|
If you get an "Script API executable not published/deployed." error, deploy your script as an API Executable:
|
|
69
69
|
|
|
70
|
-
- Run `clasp open`
|
|
70
|
+
- Run `clasp open-script`
|
|
71
71
|
- Click `Deploy > New deployment`
|
|
72
72
|
- Select type ⚙ > API Executable
|
|
73
73
|
- Type a `Description`
|
|
@@ -79,7 +79,7 @@ Many Apps Script functions require special OAuth Scopes (Gmail, Drive, etc.).
|
|
|
79
79
|
|
|
80
80
|
To run functions that use these scopes, you must add the scopes to your Apps Script manifest and `clasp login` again.
|
|
81
81
|
|
|
82
|
-
- `clasp open`
|
|
82
|
+
- `clasp open-script`
|
|
83
83
|
- `File > Project Properties > Scopes`
|
|
84
84
|
- Add these [scopes to your `appsscript.json`](https://developers.google.com/apps-script/concepts/scopes#set-explicit).
|
|
85
85
|
- Log in again: `clasp login --user <name> --use-project-scopes --creds creds.json`. This will add these scopes to your credentials.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@google/clasp",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.3",
|
|
4
4
|
"description": "Develop Apps Script Projects locally",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./build/src/index.js",
|
|
@@ -102,6 +102,7 @@
|
|
|
102
102
|
"c8": "^10.1.3",
|
|
103
103
|
"chai": "^5.2.0",
|
|
104
104
|
"chai-as-promised": "^8.0.1",
|
|
105
|
+
"esmock": "^2.7.3",
|
|
105
106
|
"mocha": "^11.2.2",
|
|
106
107
|
"mock-fs": "^5.5.0",
|
|
107
108
|
"nock": "^14.0.4",
|