@mcpher/gas-fakes 1.0.22 → 1.0.23

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
@@ -328,7 +328,6 @@ const getParentsIterator = ({
328
328
  - [oddities](oddities.md) - a collection of oddities uncovered during this project
329
329
  - [gemini](gemini.md) - some reflections and experiences on using gemini to help code large projects
330
330
  - [named colors](named-colors.md) - colors supported by Apps Script
331
- - [setup env](setup-env.md) - ([credit Eric Shapiro] - additional info on contents of .env file
332
331
  - [this file](README.md)
333
332
  - [named colors](named-colors.md)
334
333
  - [sandbox](sandbox.md)
package/README.md CHANGED
@@ -151,11 +151,32 @@ If you have used Logging to cloud, you can get a link to the log data like this.
151
151
 
152
152
  ```javascript
153
153
  console.log ('....example cloud log link for this session',Logger.__cloudLogLink)
154
- ````
154
+ ```
155
155
 
156
156
  It contains a cloud logging query that will display any logging done in this session - the filter is based on the scriptId (from gasfakes.json), the projectId and userId (from Auth), as well as the start and end time of the session.
157
157
 
158
+ #### A note on .env location
159
+
160
+ Optionally you can set the initial Logging environment in your .env file. By default it assumes you want to log to the console only.
161
+ If you want to set an initial LOG_DESTINATION using that .env file, you have to let gas-fakes know where to find it. Let's assume it's in the same folder as your main script.
162
+ ```env
163
+ node --env-file=.env yourapp.js
164
+ ```
165
+ Some developers prefer to use [dotenv](https://www.npmjs.com/package/dotenv) to set the path of the .env file
166
+ ```javascript
167
+ import dotenv from 'dotenv'
168
+ dotenv.config({ path: '/custom/path/to/.env' })
169
+ ```
170
+ Alternatively, instead of putting it in an env file, you can export it in your shell environment.
171
+ ```sh
172
+ export LOG_DESTINATION="BOTH"
173
+ ```
174
+ Finally, another approach is to set it dynamically at the beginning of your app.
175
+ ```javascript
176
+ Logger.__logDestination="BOTH"
177
+ ```
158
178
 
179
+ Do whichever one suits you best.
159
180
 
160
181
  ### Pushing files to GAS
161
182
 
@@ -186,7 +207,6 @@ As I mentioned earlier, to take this further, I'm going to need a lot of help to
186
207
  - [oddities](oddities.md) - a collection of oddities uncovered during this project
187
208
  - [gemini](gemini.md) - some reflections and experiences on using gemini to help code large projects
188
209
  - [named colors](named-colors.md) - colors supported by Apps Script
189
- - [setup env](setup-env.md) - ([credit Eric Shapiro] - additional info on contents of .env file
190
210
  - [this file](README.md)
191
211
  - [named colors](named-colors.md)
192
212
  - [sandbox](sandbox.md)
@@ -56,7 +56,7 @@ const tli = () => {
56
56
  deleteTempFile(id)
57
57
 
58
58
  }
59
- tli()
59
+ // tli()
60
60
 
61
61
  const tx2 = () => {
62
62
  let doc = DocumentApp.create("abc")
@@ -0,0 +1,7 @@
1
+ import '../../main.js';
2
+ console.log(process.env.LOG_DESTINATION)
3
+ Logger.__logDestination="BOTH"
4
+ console.log(Logger.__destination)
5
+ console.log (Logger.__cloudLogLink)
6
+
7
+
package/package.json CHANGED
@@ -21,53 +21,54 @@
21
21
  "sleep-synchronously": "^2.0.0",
22
22
  "subsume": "^4.0.0",
23
23
  "to-readable-stream": "^4.0.0",
24
- "unzipper": "^0.12.3"
24
+ "unzipper": "^0.12.3",
25
+ "yoctocolors": "^2.1.2"
25
26
  },
26
27
  "type": "module",
27
28
  "scripts": {
28
- "test": "cp mainlocal.js main.js && node --env-file=.env ./test/test.js",
29
- "testdrive": "cp mainlocal.js main.js && node --env-file=.env ./test/testdrive.js execute",
30
- "testsheetsdatavalidations": "cp mainlocal.js main.js && node --env-file=.env ./test/testsheetsdatavalidations.js execute",
31
- "testsheetspermissions": "cp mainlocal.js main.js && node --env-file=.env ./test/testsheetspermissions.js execute",
32
- "testsheetsvalues": "cp mainlocal.js main.js && node --env-file=.env ./test/testsheetsvalues.js execute",
33
- "testsheets": "cp mainlocal.js main.js && node --env-file=.env ./test/testsheets.js execute",
34
- "testfetch": "cp mainlocal.js main.js && node --env-file=.env ./test/testfetch.js execute",
35
- "testsession": "cp mainlocal.js main.js && node --env-file=.env ./test/testsession.js execute",
36
- "testutilities": "cp mainlocal.js main.js && node --env-file=.env ./test/testutilities.js execute",
37
- "teststores": "cp mainlocal.js main.js && node --env-file=.env ./test/teststores.js execute",
38
- "testscriptapp": "cp mainlocal.js main.js && node --env-file=.env ./test/testscriptapp.js execute",
39
- "testfiddler": "cp mainlocal.js main.js && node --env-file=.env ./test/testfiddler.js execute",
40
- "testenums": "cp mainlocal.js main.js && node --env-file=.env ./test/testenums.js execute",
41
- "testsheetssets": "cp mainlocal.js main.js && node --env-file=.env ./test/testsheetssets.js execute",
42
- "testsheetsvui": "cp mainlocal.js main.js && node --env-file=.env ./test/testsheetsvui.js execute",
43
- "testsheetsdeveloper": "cp mainlocal.js main.js && node --env-file=.env ./test/testsheetsdeveloper.js execute",
44
- "testsheetsexotics": "cp mainlocal.js main.js && node --env-file=.env ./test/testsheetsexotics.js execute",
45
- "testsheetsdata": "cp mainlocal.js main.js && node --env-file=.env ./test/testsheetsdata.js execute",
46
- "testdocsadv": "cp mainlocal.js main.js && node --env-file=.env ./test/testdocsadv.js execute",
47
- "testslidesadv": "cp mainlocal.js main.js && node --env-file=.env ./test/testslidesadv.js execute",
48
- "testform": "cp mainlocal.js main.js && node --env-file=.env ./test/testform.js execute",
49
- "testformsadv": "cp mainlocal.js main.js && node --env-file=.env ./test/testformsadv.js execute",
50
- "testdocs": "cp mainlocal.js main.js && node --env-file=.env ./test/testdocs.js execute",
51
- "testslides": "cp mainlocal.js main.js && node --env-file=.env ./test/testslides.js execute",
52
- "testdocsnext": "cp mainlocal.js main.js && node --env-file=.env ./test/testdocsnext.js execute",
53
- "testsheetstext": "cp mainlocal.js main.js && node --env-file=.env ./test/testsheetstext.js execute",
54
- "testsheetsrange": "cp mainlocal.js main.js && node --env-file=.env ./test/testsheetsrange.js execute",
55
- "testdocslistitems": "cp mainlocal.js main.js && node --env-file=.env ./test/testdocslistitems.js execute",
56
- "testdocsall": "cp mainlocal.js main.js && node --env-file=.env ./test/testdocsall.js",
57
- "testdocsheaders": "cp mainlocal.js main.js && node --env-file=.env ./test/testdocsheaders.js execute",
58
- "testdocsfooters": "cp mainlocal.js main.js && node --env-file=.env ./test/testdocsfooters.js execute",
59
- "testdocsfootnotes": "cp mainlocal.js main.js && node --env-file=.env ./test/testdocsfootnotes.js execute",
60
- "testdocsimages": "cp mainlocal.js main.js && node --env-file=.env ./test/testdocsimages.js execute",
61
- "testdocsstyles": "cp mainlocal.js main.js && node --env-file=.env ./test/testdocsstyles.js execute",
62
- "testsandbox": "cp mainlocal.js main.js && node --env-file=.env ./test/testsandbox.js execute",
63
- "testgmail": "cp mainlocal.js main.js && node --env-file=.env ./test/testgmail.js execute",
64
- "testlogger": "cp mainlocal.js main.js && node --env-file=.env ./test/testlogger.js execute",
65
- "pub": "cp mainlocal.js main.js && npm publish --access public"
29
+ "test": "cp mainlocal.js main.js && node ./test/test.js",
30
+ "testdrive": "cp mainlocal.js main.js && node ./test/testdrive.js execute",
31
+ "testsheetsdatavalidations": "cp mainlocal.js main.js && node ./test/testsheetsdatavalidations.js execute",
32
+ "testsheetspermissions": "cp mainlocal.js main.js && node ./test/testsheetspermissions.js execute",
33
+ "testsheetsvalues": "cp mainlocal.js main.js && node ./test/testsheetsvalues.js execute",
34
+ "testsheets": "cp mainlocal.js main.js && node ./test/testsheets.js execute",
35
+ "testfetch": "cp mainlocal.js main.js && node ./test/testfetch.js execute",
36
+ "testsession": "cp mainlocal.js main.js && node ./test/testsession.js execute",
37
+ "testutilities": "cp mainlocal.js main.js && node ./test/testutilities.js execute",
38
+ "teststores": "cp mainlocal.js main.js && node ./test/teststores.js execute",
39
+ "testscriptapp": "cp mainlocal.js main.js && node ./test/testscriptapp.js execute",
40
+ "testfiddler": "cp mainlocal.js main.js && node ./test/testfiddler.js execute",
41
+ "testenums": "cp mainlocal.js main.js && node ./test/testenums.js execute",
42
+ "testsheetssets": "cp mainlocal.js main.js && node ./test/testsheetssets.js execute",
43
+ "testsheetsvui": "cp mainlocal.js main.js && node ./test/testsheetsvui.js execute",
44
+ "testsheetsdeveloper": "cp mainlocal.js main.js && node ./test/testsheetsdeveloper.js execute",
45
+ "testsheetsexotics": "cp mainlocal.js main.js && node ./test/testsheetsexotics.js execute",
46
+ "testsheetsdata": "cp mainlocal.js main.js && node ./test/testsheetsdata.js execute",
47
+ "testdocsadv": "cp mainlocal.js main.js && node ./test/testdocsadv.js execute",
48
+ "testslidesadv": "cp mainlocal.js main.js && node ./test/testslidesadv.js execute",
49
+ "testform": "cp mainlocal.js main.js && node ./test/testform.js execute",
50
+ "testformsadv": "cp mainlocal.js main.js && node ./test/testformsadv.js execute",
51
+ "testdocs": "cp mainlocal.js main.js && node ./test/testdocs.js execute",
52
+ "testslides": "cp mainlocal.js main.js && node ./test/testslides.js execute",
53
+ "testdocsnext": "cp mainlocal.js main.js && node ./test/testdocsnext.js execute",
54
+ "testsheetstext": "cp mainlocal.js main.js && node ./test/testsheetstext.js execute",
55
+ "testsheetsrange": "cp mainlocal.js main.js && node ./test/testsheetsrange.js execute",
56
+ "testdocslistitems": "cp mainlocal.js main.js && node ./test/testdocslistitems.js execute",
57
+ "testdocsall": "cp mainlocal.js main.js && node ./test/testdocsall.js",
58
+ "testdocsheaders": "cp mainlocal.js main.js && node ./test/testdocsheaders.js execute",
59
+ "testdocsfooters": "cp mainlocal.js main.js && node ./test/testdocsfooters.js execute",
60
+ "testdocsfootnotes": "cp mainlocal.js main.js && node ./test/testdocsfootnotes.js execute",
61
+ "testdocsimages": "cp mainlocal.js main.js && node ./test/testdocsimages.js execute",
62
+ "testdocsstyles": "cp mainlocal.js main.js && node ./test/testdocsstyles.js execute",
63
+ "testsandbox": "cp mainlocal.js main.js && node ./test/testsandbox.js execute",
64
+ "testgmail": "cp mainlocal.js main.js && node ./test/testgmail.js execute",
65
+ "testlogger": "cp mainlocal.js main.js && node ./test/testlogger.js execute",
66
+ "pub": "cp mainlocal.js main.js && npm publish --access public"
66
67
  },
67
68
  "name": "@mcpher/gas-fakes",
68
- "version": "1.0.22",
69
+ "version": "1.0.23",
69
70
  "license": "MIT",
70
- "main": "main.js",
71
+ "main": "main.js && node ",
71
72
  "description": "A proof of concept implementation of Apps Script Environment on Node",
72
73
  "repository": "github:brucemcpherson/gas-fakes",
73
74
  "homepage": "https://ramblings.mcpher.com/a-proof-of-concept-implementation-of-apps-script-environment-on-node/"
package/src/index.js CHANGED
@@ -1,4 +1,9 @@
1
+ import colors from 'yoctocolors'
1
2
  import './services/scriptapp/app.js'
3
+
4
+ import {default as pf } from '../package.json' with { type: 'json' };
5
+ console.log (`You are using ${colors.blueBright(pf.name)} package version ${colors.greenBright(pf.version)}`)
6
+ ScriptApp.__gasFakesVersion = pf.version
2
7
  import './services/driveapp/app.js'
3
8
  import './services/logger/app.js'
4
9
  import './services/urlfetchapp/app.js'
@@ -16,7 +21,3 @@ import './services/documentapp/app.js'
16
21
  import './services/advforms/app.js'
17
22
  import './services/formapp/app.js'
18
23
  import './services/slidesapp/app.js'
19
-
20
- // force initilialization of scriptApp - which is always needed
21
- // scriptapp will always be fake here
22
- ScriptApp.isFake
@@ -25,7 +25,6 @@ export class FakeLogger {
25
25
  this.__destination = (process.env.LOG_DESTINATION || 'CONSOLE').toUpperCase();
26
26
  this.__startedLoggingAt = new Date()
27
27
  this.__cloudLogLink = 'No cloud logging enabled - use Logger.__logDestination = "CLOUD" or "BOTH" to enable'
28
-
29
28
  if (['CLOUD','BOTH'].includes(this.__destination)) {
30
29
  writeToCloudOrConsole("...Initializing cloud logging", this)
31
30
  }
@@ -88,6 +87,8 @@ export class FakeLogger {
88
87
  if (['CONSOLE', 'CLOUD', 'BOTH', 'NONE'].includes(destination.toUpperCase())) {
89
88
  this.__destination = destination.toUpperCase();
90
89
  }
90
+ // we need to send a logger message to initialize and test
91
+ this.log (`...setting destination to ${this.__destination}`)
91
92
  return this;
92
93
  }
93
94
 
package/togas.bash CHANGED
@@ -24,41 +24,10 @@ cp ${SOURCE}/test*.js ${TARGET}/test
24
24
 
25
25
 
26
26
  # find all the copied files and comment/fixes out import and export statements
27
- # note - this simple version naively expects that to be on 1 line
28
- # version below only works on linux - the perl version should work on both mac and linux
29
- #find "${TARGET}" -name "${EXT}" -type f -exec perl -i -pe 'if (/^import\b/) { $in_import=1 } if ($in_import) { s/^/\/\//; if (/['\''"][^'\''"]*['\''"];?\s*$/) { $in_import=0 } }' {} +
30
- # sed -i 's/^import\s\s*/\/\/import /g' $(find "${TARGET}" -name "${EXT}" -type f)
31
- #sed -i 's/^\s*export\s\s*//g' $(find "${TARGET}" -name "${EXT}" -type f)
32
-
33
-
34
- # Perl works consistently across platforms
27
+ # Perl should work across platforms
35
28
  find "${TARGET}" -name "${EXT}" -type f -exec perl -i -pe 's/^\s*export\s\s*//g' {} \;
36
29
  find "${TARGET}" -name "${EXT}" -type f -exec perl -i -pe 'if (/^import\b/) { $in_import=1 } if ($in_import) { s/^/\/\//; if (/['\''"][^'\''"]*['\''"];?\s*$/) { $in_import=0 } }' {} +
37
- # sed -i 's/^import\s\s*/\/\/import /g' $(find "${TARGET}" -name "${EXT}" -type f)
38
- # replace all process.env.VAR_NAME occurrences with actual value
39
- # process.env is not usable in apps script
40
- #for var in $(grep -oP 'process\.env\.\K\w+' "${TARGET}/test/testinit.js"); do
41
-
42
- # Use macos + linux version
43
- vars=($(grep -oE 'process\.env\.\w+' "${TARGET}/test/testinit.js" | sed 's/process\.env\.//'))
44
-
45
- for var in "${vars[@]}"; do
46
-
47
- value=$(printenv "$var") # Get the environment variable value
48
-
49
- # Escape characters for sed, e.g. \n becomes \\n, & becomes \&
50
- value=$(printf '%q' "$value")
51
-
52
- # Check if the value contains non-numeric characters (treat as a string)
53
- if [[ "$value" =~ [^0-9] ]]; then
54
- value="\"$value\"" # Add double quotes
55
- fi
56
30
 
57
- # Replace process.env.VARIABLE_NAME with the actual value
58
- #sed -i "s|process.env.$var|$value|g" ${TARGET}/test/testinit.js
59
- #macos + linux
60
- sed -i "" "s|process.env.$var|$value|g" "${TARGET}/test/testinit.js"
61
- done
62
31
 
63
32
  # now go to the target and push and open if required
64
33
  if [ "$CLASP" = true ] ; then
package/setup.sh DELETED
@@ -1,147 +0,0 @@
1
- #!/bin/bash
2
-
3
- # --- 1. Collect Phase ---
4
- echo "Welcome to the gas-fakes project setup."
5
- echo "This script will guide you through creating your .env file for testing."
6
- echo "Please provide the following configuration values."
7
- echo "Some values are required for the test suite to run correctly."
8
- echo
9
-
10
- # --- Required values ---
11
- read -p "Enter your GCP Project ID: " gcp_project_id
12
- if [ -z "$gcp_project_id" ]; then
13
- echo "Error: GCP Project ID is required." >&2
14
- exit 1
15
- fi
16
-
17
- read -p "Enter a Drive File ID you have read access to (for testing ADC): " drive_test_file_id
18
- if [ -z "$drive_test_file_id" ]; then
19
- echo "Error: Drive File ID is required." >&2
20
- exit 1
21
- fi
22
-
23
- read -p "Enter a test Drive Folder Name you have write access to: " test_folder_name
24
- if [ -z "$test_folder_name" ]; then
25
- echo "Error: Test Folder Name is required." >&2
26
- exit 1
27
- fi
28
-
29
- read -p "Enter the ID of that test Drive Folder: " test_folder_id
30
- if [ -z "$test_folder_id" ]; then
31
- echo "Error: Test Folder ID is required." >&2
32
- exit 1
33
- fi
34
-
35
- # --- Optional values with defaults ---
36
- read -p "Enter the number of files in that folder [0]: " test_folder_files
37
- test_folder_files=${test_folder_files:-0}
38
-
39
- read -p "Enter a viewer email for permission tests [viewer@mcpher.com]: " scratch_viewer
40
- scratch_viewer=${scratch_viewer:-"viewer@mcpher.com"}
41
-
42
- read -p "Enter an editor email for permission tests [editor@mcpher.com]: " scratch_editor
43
- scratch_editor=${scratch_editor:-"editor@mcpher.com"}
44
-
45
- read -p "Enter a second viewer email [viewer2@mcpher.com]: " scratch_b_viewer
46
- scratch_b_viewer=${scratch_b_viewer:-"viewer2@mcpher.com"}
47
-
48
- read -p "Enter a second editor email [editor2@mcpher.com]: " scratch_b_editor
49
- scratch_b_editor=${scratch_b_editor:-"editor2@mcpher.com"}
50
-
51
- read -p "Enter min PDFs in root for tests [20]: " min_root_pdfs
52
- min_root_pdfs=${min_root_pdfs:-20}
53
-
54
- read -p "Enter min PDFs total for tests [400]: " min_pdfs
55
- min_pdfs=${min_pdfs:-400}
56
-
57
- read -p "Enter min folders in root for tests [5]: " min_folders_root
58
- min_folders_root=${min_folders_root:-5}
59
-
60
-
61
- # --- 2. Confirm Phase ---
62
- echo
63
- echo "The following configuration will be written to .env:"
64
- echo "================================================="
65
- echo "# User-specific values"
66
- echo "GCP_PROJECT_ID=${gcp_project_id}"
67
- echo "DRIVE_TEST_FILE_ID=${drive_test_file_id}"
68
- echo "TEST_FOLDER_NAME=\"${test_folder_name}\""
69
- echo "TEST_FOLDER_ID=${test_folder_id}"
70
- echo "TEST_FOLDER_FILES=${test_folder_files}"
71
- echo "SCRATCH_VIEWER=${scratch_viewer}"
72
- echo "SCRATCH_EDITOR=${scratch_editor}"
73
- echo "SCRATCH_B_VIEWER=${scratch_b_viewer}"
74
- echo "SCRATCH_B_EDITOR=${scratch_b_editor}"
75
- echo "MIN_ROOT_PDFS=${min_root_pdfs}"
76
- echo "MIN_PDFS=${min_pdfs}"
77
- echo "MIN_FOLDERS_ROOT=${min_folders_root}"
78
- echo
79
- echo "# Shared and static values will also be included."
80
- echo "================================================="
81
- echo
82
-
83
- read -p "Proceed with creating the .env file? (y/N) " confirm
84
- if [[ ! "$confirm" =~ ^[yY](es)?$ ]]; then
85
- echo "Setup aborted. No file was written."
86
- exit 0
87
- fi
88
-
89
-
90
- # --- 3. Commit Phase ---
91
- ENV_FILE=".env"
92
- TEMP_ENV_FILE="${ENV_FILE}.tmp"
93
-
94
- # Using a heredoc to write the complete file content.
95
- cat > "$TEMP_ENV_FILE" << EOL
96
- # Auto-generated by setup.sh on $(date)
97
-
98
- # --- User-specific values ---
99
- # Required for authentication and core tests
100
- GCP_PROJECT_ID="${gcp_project_id}"
101
- DRIVE_TEST_FILE_ID="${drive_test_file_id}"
102
-
103
- # Required for file/folder manipulation tests
104
- TEST_FOLDER_NAME="${test_folder_name}"
105
- TEST_FOLDER_ID="${test_folder_id}"
106
- TEST_FOLDER_FILES=${test_folder_files}
107
-
108
- # For permission tests
109
- SCRATCH_VIEWER="${scratch_viewer}"
110
- SCRATCH_EDITOR="${scratch_editor}"
111
- SCRATCH_B_VIEWER="${scratch_b_viewer}"
112
- SCRATCH_B_EDITOR="${scratch_b_editor}"
113
-
114
- # For iterator/search tests (adjust to your Drive content)
115
- MIN_ROOT_PDFS=${min_root_pdfs}
116
- MIN_PDFS=${min_pdfs}
117
- MIN_FOLDERS_ROOT=${min_folders_root}
118
-
119
- # --- Static auth config ---
120
- # we'll use the default config for application default credentials
121
- # probably dont need to change these
122
- AC=default
123
- DEFAULT_SCOPES="https://www.googleapis.com/auth/userinfo.email,openid,https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/sqlservice.login"
124
- EXTRA_SCOPES=",https://www.googleapis.com/auth/drive,https://www.googleapis.com/auth/spreadsheets"
125
-
126
- # --- Shared test file fixtures (read-only) ---
127
- TEST_BORDERS_ID=1hRGdrYHEPixXTuQLeL3Z0qGRZVs_8ojMIm6D4KrCh1o
128
- TEST_AIRPORTS_ID=1h9IGIShgVBVUrUjjawk5MaCEQte_7t32XeEP1Z5jXKQ
129
- TEXT_FILE_NAME="fake.txt"
130
- TEXT_FILE_ID=1142Vn7W-pGl5nWLpUSkpOB82JDiz9R6p
131
- TEXT_FILE_TYPE="text/plain"
132
- TEXT_FILE_CONTENT="foo is not bar"
133
- TEST_SHEET_ID=1DlKpVVYCrCPNfRbGsz6N_K3oPTgdC9gQIKi0aNb42uI
134
- TEST_SHEET_NAME="sharedlibraries"
135
- PDF_ID=17t4ep9Jt6jRyDx0KlxMhHQNGZ3whg6GS
136
-
137
- # --- Test behavior ---
138
- # Set to 0 to preserve test files for debugging
139
- CLEAN=1
140
- EOL
141
-
142
- # Atomically rename the temp file to the final .env file.
143
- mv "$TEMP_ENV_FILE" "$ENV_FILE"
144
-
145
- echo
146
- echo "✅ The .env file has been created successfully."
147
- echo "You can now run 'npm install && npm test' to run the test suite."