@mcpher/gas-fakes 2.3.7 → 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 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/package.json CHANGED
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "name": "@mcpher/gas-fakes",
40
40
  "author": "bruce mcpherson",
41
- "version": "2.3.7",
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
@@ -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 v2.2.4 starting");
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
@@ -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
- const mainScript = process.argv[1];
24
- if (mainScript) {
25
- // Try to find .env in the same directory as the main entry point script
26
- const envPath = join(dirname(mainScript), '.env');
27
- if (existsSync(envPath)) {
28
- dotenv.config({ path: envPath, override: false, quiet: true });
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 to default dotenv behavior (CWD)
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
  }
@@ -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([