@mcpher/gas-fakes 1.2.10 → 1.2.11

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.RU.md CHANGED
@@ -331,3 +331,31 @@ const getParentsIterator = ({
331
331
  - [this file](README.md)
332
332
  - [named colors](named-colors.md)
333
333
  - [sandbox](sandbox.md)
334
+
335
+ ## <img src="./logo.png" alt="gas-fakes logo" width="50" align="top"> Further Reading
336
+
337
+ - [getting started](GETTING_STARTED.md) - how to handle authentication for restricted scopes.
338
+ - [readme](README.md)
339
+ - [initial idea and thoughts](https://ramblings.mcpher.com/a-proof-of-concept-implementation-of-apps-script-environment-on-node/)
340
+ - [Inside the volatile world of a Google Document](https://ramblings.mcpher.com/inside-the-volatile-world-of-a-google-document/)
341
+ - [Apps Script Services on Node – using apps script libraries](https://ramblings.mcpher.com/apps-script-services-on-node-using-apps-script-libraries/)
342
+ - [Apps Script environment on Node – more services](https://ramblings.mcpher.com/apps-script-environment-on-node-more-services/)
343
+ - [Turning async into synch on Node using workers](https://ramblings.mcpher.com/turning-async-into-synch-on-node-using-workers/)
344
+ - [All about Apps Script Enums and how to fake them](https://ramblings.mcpher.com/all-about-apps-script-enums-and-how-to-fake-them/)
345
+ - [Russian version](README.RU.md) ([credit Alex Ivanov](https://github.com/oshliaer)) - needs updating
346
+ - [colaborators](collaborators.md) - additional information for collaborators
347
+ - [oddities](oddities.md) - a collection of oddities uncovered during this project
348
+ - [gemini](gemini-observations.md) - some reflections and experiences on using gemini to help code large projects
349
+ - [named colors](named-colors.md)
350
+ - [sandbox](sandbox.md)
351
+ - [named range identity](named-range-identity.md)
352
+ - [adc and restricted scopes](https://ramblings.mcpher.com/how-to-allow-access-to-sensitive-scopes-with-application-default-credentials/)
353
+ - [push test pull](pull-test-push.md)
354
+ - [gas fakes cli](gas-fakes-cli.md)
355
+ - [sharing cache and properties between gas-fakes and live apps script](https://ramblings.mcpher.com/sharing-cache-and-properties-between-gas-fakes-and-live-apps-script/)
356
+ - [gas-fakes-cli now has built in mcp server and gemini extension](https://ramblings.mcpher.com/gas-fakes-cli-now-has-built-in-mcp-server-and-gemini-extension/)
357
+ - [gas-fakes CLI: Run apps script code directly from your terminal](https://ramblings.mcpher.com/gas-fakes-cli-run-apps-script-code-directly-from-your-terminal/)
358
+ - [How to allow access to sensitive scopes with Application Default Credentials](https://ramblings.mcpher.com/how-to-allow-access-to-sensitive-scopes-with-application-default-credentials/)
359
+ - [Supercharge Your Google Apps Script Caching with GasFlexCache](https://ramblings.mcpher.com/supercharge-your-google-apps-script-caching-with-gasflexcache/)
360
+ - [Fake-Sandbox for Google Apps Script: Granular controls.](https://ramblings.mcpher.com/fake-sandbox-for-google-apps-script-granular-controls/)
361
+ - [A Fake-Sandbox for Google Apps Script: Securely Executing Code Generated by Gemini CLI](https://ramblings.mcpher.com/gas-fakes-sandbox/)
package/README.md CHANGED
@@ -150,6 +150,7 @@ For inspiration on pushing modified files to the IDE, see the togas.sh bash scri
150
150
  ## Help
151
151
 
152
152
  As I mentioned earlier, to take this further, I'm going to need a lot of help to extend the methods and services supported - so if you feel this would be useful to you, and would like to collaborate, please ping me on bruce@mcpher.com and we'll talk.
153
+
153
154
  ## <img src="./logo.png" alt="gas-fakes logo" width="50" align="top"> Further Reading
154
155
 
155
156
  - [getting started](GETTING_STARTED.md) - how to handle authentication for restricted scopes.
@@ -163,11 +164,17 @@ As I mentioned earlier, to take this further, I'm going to need a lot of help to
163
164
  - [Russian version](README.RU.md) ([credit Alex Ivanov](https://github.com/oshliaer)) - needs updating
164
165
  - [colaborators](collaborators.md) - additional information for collaborators
165
166
  - [oddities](oddities.md) - a collection of oddities uncovered during this project
166
- - [gemini](gemini.md) - some reflections and experiences on using gemini to help code large projects
167
+ - [gemini](gemini-observations.md) - some reflections and experiences on using gemini to help code large projects
167
168
  - [named colors](named-colors.md)
168
169
  - [sandbox](sandbox.md)
169
170
  - [named range identity](named-range-identity.md)
170
171
  - [adc and restricted scopes](https://ramblings.mcpher.com/how-to-allow-access-to-sensitive-scopes-with-application-default-credentials/)
171
172
  - [push test pull](pull-test-push.md)
172
173
  - [gas fakes cli](gas-fakes-cli.md)
173
- - [sharing cache and properties between gas-fakes and live apps script](https://ramblings.mcpher.com/sharing-cache-and-properties-between-gas-fakes-and-live-apps-script/)
174
+ - [sharing cache and properties between gas-fakes and live apps script](https://ramblings.mcpher.com/sharing-cache-and-properties-between-gas-fakes-and-live-apps-script/)
175
+ - [gas-fakes-cli now has built in mcp server and gemini extension](https://ramblings.mcpher.com/gas-fakes-cli-now-has-built-in-mcp-server-and-gemini-extension/)
176
+ - [gas-fakes CLI: Run apps script code directly from your terminal](https://ramblings.mcpher.com/gas-fakes-cli-run-apps-script-code-directly-from-your-terminal/)
177
+ - [How to allow access to sensitive scopes with Application Default Credentials](https://ramblings.mcpher.com/how-to-allow-access-to-sensitive-scopes-with-application-default-credentials/)
178
+ - [Supercharge Your Google Apps Script Caching with GasFlexCache](https://ramblings.mcpher.com/supercharge-your-google-apps-script-caching-with-gasflexcache/)
179
+ - [Fake-Sandbox for Google Apps Script: Granular controls.](https://ramblings.mcpher.com/fake-sandbox-for-google-apps-script-granular-controls/)
180
+ - [A Fake-Sandbox for Google Apps Script: Securely Executing Code Generated by Gemini CLI](https://ramblings.mcpher.com/gas-fakes-sandbox/)
package/exgcp.sh CHANGED
@@ -18,6 +18,8 @@ fi
18
18
 
19
19
  # Read the GCP_PROJECT_ID, remove quotes, and handle potential carriage returns
20
20
  GCP_PROJECT_ID_VALUE=$(grep -E '^GCP_PROJECT_ID=' "$ENV_FILE" | cut -d '=' -f2 | tr -d '"\r')
21
+ GEMINI_API_KEY_VALUE=$(grep -E '^GEMINI_API_KEY=' "$ENV_FILE" | cut -d '=' -f2 | tr -d '"\r')
22
+ GEMINI_MODEL_VALUE=$(grep -E '^GEMINI_MODEL=' "$ENV_FILE" | cut -d '=' -f2 | tr -d '"\r')
21
23
 
22
24
  # Check if a value was extracted
23
25
  if [ -z "$GCP_PROJECT_ID_VALUE" ]; then
@@ -25,7 +27,21 @@ if [ -z "$GCP_PROJECT_ID_VALUE" ]; then
25
27
  return 1
26
28
  fi
27
29
 
30
+ if [ -z "GEMINI_API_KEY_VALUE" ]; then
31
+ echo "GEMINI_API_KEY not found or is empty in $ENV_FILE."
32
+ else
33
+ echo "exported: GEMINI_API_KEY"
34
+ export GEMINI_API_KEY="$GEMINI_API_KEY_VALUE"
35
+ fi
36
+
37
+ if [ -z "GEMINI_MODEL_VALUE" ]; then
38
+ echo "GEMINI_MODEL not found or is empty in $ENV_FILE."
39
+ else
40
+ echo "exported: GEMINI_MODEL=$GEMINI_MODEL_VALUE"
41
+ export GEMINI_MODEL="$GEMINI_MODEL_VALUE"
42
+ fi
43
+
28
44
  # Export the variable for the current session
29
45
  export GOOGLE_CLOUD_PROJECT="$GCP_PROJECT_ID_VALUE"
30
46
 
31
- echo "Successfully exported: GOOGLE_CLOUD_PROJECT=$GOOGLE_CLOUD_PROJECT"
47
+ echo "exported: GOOGLE_CLOUD_PROJECT=$GOOGLE_CLOUD_PROJECT"
package/gas-fakes.js CHANGED
@@ -12,13 +12,13 @@ import { Command } from "commander";
12
12
  import dotenv from "dotenv";
13
13
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
14
14
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
15
- import { z } from "zod";
15
+ import { z, ZodCatch } from "zod";
16
16
 
17
17
  // -----------------------------------------------------------------------------
18
18
  // CONSTANTS & UTILITIES
19
19
  // -----------------------------------------------------------------------------
20
20
 
21
- const VERSION = "0.0.5";
21
+ const VERSION = "0.0.6";
22
22
  const MCP_VERSION = "0.0.3";
23
23
  const execAsync = promisify(exec);
24
24
 
@@ -170,8 +170,15 @@ function generateExecutionScript({ scriptText, useSandbox, sandboxConfig }) {
170
170
  * @param {object} options The processed CLI options.
171
171
  */
172
172
  async function executeGasScript(options) {
173
- const { filename, script, display, gfSettings, useSandbox, sandboxConfig } =
174
- options;
173
+ const {
174
+ filename,
175
+ script,
176
+ display,
177
+ gfSettings,
178
+ useSandbox,
179
+ sandboxConfig,
180
+ args,
181
+ } = options;
175
182
 
176
183
  const scriptText = filename ? fs.readFileSync(filename, "utf8") : script;
177
184
 
@@ -194,8 +201,13 @@ async function executeGasScript(options) {
194
201
  configurable: true,
195
202
  });
196
203
 
197
- const gasFunction = new Function(mainScript);
198
- await gasFunction();
204
+ if (args) {
205
+ const gasFunction = new Function("args", mainScript);
206
+ await gasFunction(args);
207
+ } else {
208
+ const gasFunction = new Function(mainScript);
209
+ await gasFunction();
210
+ }
199
211
  }
200
212
 
201
213
  // -----------------------------------------------------------------------------
@@ -428,6 +440,11 @@ async function main() {
428
440
  "Display the generated script before execution.",
429
441
  false
430
442
  )
443
+ .option(
444
+ "-a, --args <string>",
445
+ `Arguments for the function of Google Apps Script. Provide it as a JSON string. The name of the argument is "args" as a fixed name. For example, when the function of GAS is \`function sample(args) { script }\`, you can provide the arguments like \`-a '{"key": "value"}'\`.`,
446
+ null
447
+ )
431
448
  .action(async (options) => {
432
449
  if (Object.keys(options).length === 0) {
433
450
  program.help();
@@ -455,6 +472,16 @@ async function main() {
455
472
  const sandboxConfig = buildSandboxConfig(options);
456
473
  const useSandbox = !!options.sandbox || !!sandboxConfig;
457
474
 
475
+ let args = null;
476
+ if (options.args) {
477
+ try {
478
+ args = JSON.parse(options.args);
479
+ } catch (err) {
480
+ console.error("Error: Invalid JSON provided to --args option.");
481
+ process.exit(1);
482
+ }
483
+ }
484
+
458
485
  await executeGasScript({
459
486
  filename,
460
487
  script,
@@ -462,6 +489,7 @@ async function main() {
462
489
  useSandbox,
463
490
  sandboxConfig,
464
491
  gfSettings: settingsPath,
492
+ args,
465
493
  });
466
494
  });
467
495
 
package/package.json CHANGED
@@ -30,11 +30,14 @@
30
30
  },
31
31
  "type": "module",
32
32
  "scripts": {
33
- "pub": "npm publish --access public"
33
+ "pub": "npm publish --access public",
34
+ "includes": "node ./doccreation/include-docs.js",
35
+ "progress": "cd ./doccreation && bash pipeline.sh",
36
+ "docs": "npm run includes && npm run progress"
34
37
  },
35
38
  "name": "@mcpher/gas-fakes",
36
39
  "author": "bruce mcpherson",
37
- "version": "1.2.10",
40
+ "version": "1.2.11",
38
41
  "license": "MIT",
39
42
  "main": "main.js",
40
43
  "description": "A proof of concept implementation of Apps Script Environment on Node",
package/src/index.js CHANGED
@@ -22,5 +22,6 @@ import './services/advforms/app.js'
22
22
  import './services/formapp/app.js'
23
23
  import './services/slidesapp/app.js'
24
24
  import './services/mimetype/app.js'
25
+ import './services/lock/app.js'
25
26
  // should be last
26
27
  import './services/stores/app.js'
@@ -0,0 +1,11 @@
1
+
2
+
3
+ /**
4
+ * the idea here is to create an empty global entry for the singleton
5
+ * but only load it when it is actually used.
6
+ */
7
+ import { newFakeLockService as maker } from './fakelockservice.js';
8
+ import { lazyLoaderApp } from '../common/lazyloader.js'
9
+
10
+ let _app = null;
11
+ _app = lazyLoaderApp(_app, 'LockService', maker)
@@ -0,0 +1,65 @@
1
+ import { Proxies } from '../../support/proxies.js';
2
+
3
+
4
+ /**
5
+ * the lock service us meaningless here as we are running on node single threaded
6
+ * in apps script this would lock shared code that was being shared by multiple scripts
7
+ * so this is all provided for compatibility only
8
+ */
9
+ class FakeLock {
10
+ constructor(domain) {
11
+ this.__fakeObjectType = 'Lock';
12
+ this.__domain = domain
13
+ this.__locked = false;
14
+ }
15
+
16
+ /**
17
+ * Returns true if the lock was acquired.
18
+ * @returns {boolean}
19
+ */
20
+ hasLock() {
21
+ return this.__locked;
22
+ }
23
+
24
+ /**
25
+ * Releases the lock.
26
+ */
27
+ releaseLock() {
28
+ this.__locked = false;
29
+ }
30
+
31
+ /**
32
+ * Attempts to acquire the lock.
33
+ * @param {number} timeoutInMillis
34
+ * @returns {boolean}
35
+ */
36
+ tryLock(timeoutInMillis) {
37
+ if (this.hasLock()) {
38
+ return true;
39
+ }
40
+ // In a single-threaded fake, we can't wait. We fail only if timeout is negative.
41
+ if (timeoutInMillis < 0) {
42
+ return false;
43
+ }
44
+ this.__locked = true;
45
+ return true;
46
+ }
47
+
48
+ /**
49
+ * Attempts to acquire the lock, throwing an exception on timeout.
50
+ * @param {number} timeoutInMillis
51
+ */
52
+ waitLock(timeoutInMillis) {
53
+ if (this.hasLock()) {
54
+ return; // Already acquired, no need to wait
55
+ }
56
+ // In a single-threaded fake, we can't wait. We fail only if timeout is negative.
57
+ if (timeoutInMillis < 0) {
58
+ throw new Error(`Lock timeout: another process was holding the lock for too long.`);
59
+ }
60
+ this.__locked = true;
61
+ }
62
+ }
63
+
64
+
65
+ export const newFakeLock = (...args) => Proxies.guard(new FakeLock(...args));
@@ -0,0 +1,37 @@
1
+ import { Proxies } from '../../support/proxies.js';
2
+ import { newFakeLock } from './fakelock.js';
3
+
4
+ /**
5
+ * domains of lock supported
6
+ * @enum {string}
7
+ */
8
+ const LockDomain = Object.freeze({
9
+ SCRIPT: 'SCRIPT',
10
+ USER: 'USER',
11
+ DOCUMENT: 'DOCUMENT'
12
+ })
13
+ /**
14
+ * the lock service us meaningless here as we are running on node single threaded
15
+ * in apps script this would lock shared code that was being shared by multiple scripts
16
+ * so this is all provided for compatibility only
17
+ */
18
+ class FakeLockService {
19
+ constructor() {
20
+ this.__fakeObjectType = 'LockService';
21
+ }
22
+ getDocumentLock () {
23
+ // Per documentation, this should return null if not in the context of a document.
24
+ if (ScriptApp.__documentId) {
25
+ return newFakeLock(LockDomain.DOCUMENT);
26
+ }
27
+ return null;
28
+ }
29
+ getUserLock () {
30
+ return newFakeLock(LockDomain.USER)
31
+ }
32
+ getScriptLock () {
33
+ return newFakeLock(LockDomain.SCRIPT)
34
+ }
35
+ }
36
+
37
+ export const newFakeLockService = (...args) => Proxies.guard(new FakeLockService(...args));