@mcpher/gas-fakes 2.3.6 → 2.3.8
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 +2 -0
- package/appsscript.json +3 -3
- package/package.json +1 -1
- package/src/cli/setup.js +5 -5
- package/src/cli/utils.js +21 -0
- package/src/support/env-loader.js +32 -12
- package/src/support/sxauth.js +22 -0
package/README.md
CHANGED
|
@@ -188,6 +188,8 @@ As I mentioned earlier, to take this further, I'm going to need a lot of help to
|
|
|
188
188
|
- [github actions using dwd and wif](https://github.com/brucemcpherson/gas-fakes-actions-dwd)
|
|
189
189
|
- [ksuite as a back end](ksuite_poc.md)
|
|
190
190
|
- [msgraph as a back end](msgraph.md)
|
|
191
|
+
- [resurrecting scriptDb repo](https://github.com/brucemcpherson/scriptdb-redux)
|
|
192
|
+
- [Resurrecting ScriptDb – nosql database for Apps Script](https://ramblings.mcpher.com/resurrecting-scriptdb-nosql-database-for-apps-script/)
|
|
191
193
|
- [gas-fakes in serverless containers](https://docs.google.com/presentation/d/1JlXF9T--DD4ERHopyP3WyAMhjRCxxHblgCP5ynxaJ3k/edit?usp=sharing)
|
|
192
194
|
- [apps script - a lingua franca for workspace platforms](https://ramblings.mcpher.com/apps-script-a-lingua-franca/)
|
|
193
195
|
- [Apps Script: A ‘Lingua Franca’ for the Multi-Cloud Era](https://ramblings.mcpher.com/apps-script-with-ksuite/)
|
package/appsscript.json
CHANGED
|
@@ -3,17 +3,17 @@
|
|
|
3
3
|
"exceptionLogging": "STACKDRIVER",
|
|
4
4
|
"runtimeVersion": "V8",
|
|
5
5
|
"oauthScopes": [
|
|
6
|
+
"openid",
|
|
7
|
+
"https://www.googleapis.com/auth/userinfo.email",
|
|
6
8
|
"https://www.googleapis.com/auth/cloud-platform",
|
|
7
9
|
"https://www.googleapis.com/auth/drive",
|
|
8
10
|
"https://www.googleapis.com/auth/sqlservice",
|
|
9
11
|
"https://www.googleapis.com/auth/script.external_request",
|
|
10
12
|
"https://www.googleapis.com/auth/spreadsheets",
|
|
11
|
-
"https://www.googleapis.com/auth/userinfo.email",
|
|
12
13
|
"https://www.googleapis.com/auth/documents",
|
|
13
14
|
"https://www.googleapis.com/auth/presentations",
|
|
14
15
|
"https://www.googleapis.com/auth/forms",
|
|
15
16
|
"https://mail.google.com/",
|
|
16
|
-
"openid",
|
|
17
17
|
"https://www.googleapis.com/auth/calendar"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
@@ -99,4 +99,4 @@
|
|
|
99
99
|
}
|
|
100
100
|
]
|
|
101
101
|
}
|
|
102
|
-
}
|
|
102
|
+
}
|
package/package.json
CHANGED
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"name": "@mcpher/gas-fakes",
|
|
40
40
|
"author": "bruce mcpherson",
|
|
41
|
-
"version": "2.3.
|
|
41
|
+
"version": "2.3.8",
|
|
42
42
|
"license": "MIT",
|
|
43
43
|
"main": "main.js",
|
|
44
44
|
"description": "An implementation of the Google Workspace Apps Script runtime: Run native App Script Code on Node and Cloud Run",
|
package/src/cli/setup.js
CHANGED
|
@@ -5,7 +5,7 @@ import path from "path";
|
|
|
5
5
|
import os from "os";
|
|
6
6
|
import { randomUUID } from "node:crypto";
|
|
7
7
|
import { execSync } from "child_process";
|
|
8
|
-
import { checkForGcloudCli, runCommandSync } from "./utils.js";
|
|
8
|
+
import { checkForGcloudCli, runCommandSync, runCommandWithRetrySync } from "./utils.js";
|
|
9
9
|
import { getMsGraphToken, mapGasScopesToMsGraph } from "../support/msgraph/msauth.js";
|
|
10
10
|
|
|
11
11
|
// --- Utility Functions ---
|
|
@@ -65,7 +65,7 @@ async function findEnvFiles(dir) {
|
|
|
65
65
|
// --- Exported Command Implementations ---
|
|
66
66
|
|
|
67
67
|
export async function initializeConfiguration(options = {}) {
|
|
68
|
-
console.log("...gas-fakes init
|
|
68
|
+
console.log("...gas-fakes init starting");
|
|
69
69
|
let envPath;
|
|
70
70
|
|
|
71
71
|
// need to figure out which env file we are operating on
|
|
@@ -794,9 +794,9 @@ export async function authenticateUser(options = {}) {
|
|
|
794
794
|
}
|
|
795
795
|
|
|
796
796
|
console.log("...applying IAM permissions");
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
797
|
+
runCommandWithRetrySync(`gcloud projects add-iam-policy-binding "${projectId}" --member="serviceAccount:${sa_email}" --role="roles/editor" --quiet`, true);
|
|
798
|
+
runCommandWithRetrySync(`gcloud iam service-accounts add-iam-policy-binding "${sa_email}" --member="serviceAccount:${sa_email}" --role="roles/iam.serviceAccountTokenCreator" --quiet`, true);
|
|
799
|
+
runCommandWithRetrySync(`gcloud iam service-accounts add-iam-policy-binding "${sa_email}" --member="user:${current_user}" --role="roles/iam.serviceAccountTokenCreator" --quiet`, true);
|
|
800
800
|
|
|
801
801
|
const saUniqueId = execSync(`gcloud iam service-accounts describe "${sa_email}" --format="value(uniqueId)"`, { shell: true }).toString().trim();
|
|
802
802
|
console.log(`\n\x1b[1;33m*************************************************************************************************`);
|
package/src/cli/utils.js
CHANGED
|
@@ -99,6 +99,27 @@ export function runCommandSync(command, silent = false) {
|
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Helper function to run a shell command sync with retries (useful for GCP eventual consistency).
|
|
104
|
+
*/
|
|
105
|
+
export function runCommandWithRetrySync(command, silent = false, retries = 5, delay = 5000) {
|
|
106
|
+
for (let i = 0; i <= retries; i++) {
|
|
107
|
+
try {
|
|
108
|
+
execSync(command, { stdio: silent ? "ignore" : "inherit", shell: true });
|
|
109
|
+
return;
|
|
110
|
+
} catch (error) {
|
|
111
|
+
if (i < retries) {
|
|
112
|
+
console.log(`...command failed, retrying in ${delay / 1000}s (${i + 1}/${retries})...`);
|
|
113
|
+
const start = Date.now();
|
|
114
|
+
while (Date.now() - start < delay);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
console.error(`\nError executing command after ${retries} retries: ${command}`);
|
|
118
|
+
process.exit(1);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
102
123
|
/**
|
|
103
124
|
* Parses sandbox-related CLI options into a structured config object.
|
|
104
125
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import dotenv from 'dotenv';
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
|
-
import { join, dirname } from 'node:path';
|
|
3
|
+
import { join, dirname, resolve } from 'node:path';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Conditionally loads environment variables from a .env file.
|
|
@@ -11,27 +11,47 @@ import { join, dirname } from 'node:path';
|
|
|
11
11
|
* Otherwise, it attempts to load a .env file from the directory where the
|
|
12
12
|
* main script is located. If not found, it falls back to the default
|
|
13
13
|
* dotenv behavior (searching the current working directory).
|
|
14
|
+
*
|
|
15
|
+
* It also checks process.argv in case the user mistakenly passed --env-file
|
|
16
|
+
* after the script name.
|
|
14
17
|
*/
|
|
15
18
|
|
|
16
|
-
// Check if node was run with --env-file
|
|
19
|
+
// Check if node was run with --env-file natively
|
|
17
20
|
const hasEnvFileFlag = process.execArgv.some(arg => arg.startsWith('--env-file'));
|
|
18
21
|
|
|
19
22
|
if (!hasEnvFileFlag) {
|
|
20
23
|
// Suppress dotenv logs/tips
|
|
21
24
|
process.env.DOTENV_CONFIG_NO_TIP = 'true';
|
|
22
25
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
// Check if --env-file was passed as a script argument
|
|
27
|
+
let customEnvPath = null;
|
|
28
|
+
const argvEnvFileIdx = process.argv.findIndex(arg => arg === '--env-file');
|
|
29
|
+
|
|
30
|
+
if (argvEnvFileIdx !== -1 && process.argv.length > argvEnvFileIdx + 1) {
|
|
31
|
+
customEnvPath = resolve(process.cwd(), process.argv[argvEnvFileIdx + 1]);
|
|
32
|
+
} else {
|
|
33
|
+
const argvEnvFileMatch = process.argv.find(arg => arg.startsWith('--env-file='));
|
|
34
|
+
if (argvEnvFileMatch) {
|
|
35
|
+
customEnvPath = resolve(process.cwd(), argvEnvFileMatch.split('=')[1]);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (customEnvPath && existsSync(customEnvPath)) {
|
|
40
|
+
dotenv.config({ path: customEnvPath, override: false, quiet: true });
|
|
41
|
+
} else {
|
|
42
|
+
const mainScript = process.argv[1];
|
|
43
|
+
if (mainScript) {
|
|
44
|
+
// Try to find .env in the same directory as the main entry point script
|
|
45
|
+
const envPath = join(dirname(mainScript), '.env');
|
|
46
|
+
if (existsSync(envPath)) {
|
|
47
|
+
dotenv.config({ path: envPath, override: false, quiet: true });
|
|
48
|
+
} else {
|
|
49
|
+
// Fallback to default dotenv behavior (CWD)
|
|
50
|
+
dotenv.config({ override: false, quiet: true });
|
|
51
|
+
}
|
|
29
52
|
} else {
|
|
30
|
-
// Fallback
|
|
53
|
+
// Fallback if mainScript is not available (e.g. REPL)
|
|
31
54
|
dotenv.config({ override: false, quiet: true });
|
|
32
55
|
}
|
|
33
|
-
} else {
|
|
34
|
-
// Fallback if mainScript is not available (e.g. REPL)
|
|
35
|
-
dotenv.config({ override: false, quiet: true });
|
|
36
56
|
}
|
|
37
57
|
}
|
package/src/support/sxauth.js
CHANGED
|
@@ -67,6 +67,8 @@ export const sxInit = async ({ manifestPath, claspPath, settingsPath, cachePath,
|
|
|
67
67
|
if (!_loggedSummary) {
|
|
68
68
|
syncLog(`...appsscript.json missing or missing scopes. Emulating manifest using scopes from .env file`);
|
|
69
69
|
}
|
|
70
|
+
} else if (!_loggedSummary) {
|
|
71
|
+
syncWarn(`...Warning: No appsscript.json found and .env file missing or no DEFAULT_SCOPES/EXTRA_SCOPES defined in .env. Downstream API calls may fail with 'insufficient authentication scopes'.`);
|
|
70
72
|
}
|
|
71
73
|
}
|
|
72
74
|
|
|
@@ -97,6 +99,26 @@ export const sxInit = async ({ manifestPath, claspPath, settingsPath, cachePath,
|
|
|
97
99
|
mandatoryScopes.forEach(scope => scopeSet.add(scope))
|
|
98
100
|
const finalScopes = Array.from(scopeSet)
|
|
99
101
|
|
|
102
|
+
// Check for file-type scopes that also require Drive scope
|
|
103
|
+
const hasWorkspaceFileScope = finalScopes.some(s =>
|
|
104
|
+
s.includes('auth/spreadsheets') ||
|
|
105
|
+
s.includes('auth/documents') ||
|
|
106
|
+
s.includes('auth/presentations') ||
|
|
107
|
+
s.includes('auth/forms')
|
|
108
|
+
);
|
|
109
|
+
const hasDriveScope = finalScopes.some(s => s.includes('auth/drive'));
|
|
110
|
+
|
|
111
|
+
if (hasWorkspaceFileScope && !hasDriveScope && !_loggedSummary) {
|
|
112
|
+
const envScopesStr = (process.env.DEFAULT_SCOPES || "") + "," + (process.env.EXTRA_SCOPES || "");
|
|
113
|
+
const envHasDrive = envScopesStr.includes("auth/drive");
|
|
114
|
+
|
|
115
|
+
if (envHasDrive) {
|
|
116
|
+
syncWarn(`...Warning: A Workspace file scope (e.g., spreadsheets) was requested, but the Drive scope is missing from your appsscript.json. Your .env file permits Drive access, so please add "https://www.googleapis.com/auth/drive" to your appsscript.json.`);
|
|
117
|
+
} else {
|
|
118
|
+
syncWarn(`...Warning: A Workspace file scope (e.g., spreadsheets) was requested, but the Drive scope is missing. Please add "https://www.googleapis.com/auth/drive" to your appsscript.json and .env file (EXTRA_SCOPES), then re-run 'gas-fakes auth' to re-authenticate.`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
100
122
|
await Auth.setAuth(finalScopes);
|
|
101
123
|
|
|
102
124
|
const [activeInfo, effectiveInfo] = await Promise.all([
|