@google/clasp 3.1.1 → 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/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.
|
|
@@ -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/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",
|