@mcpher/gas-fakes 1.0.20 → 1.0.21
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 +57 -18
- package/gprompts/{gas-inventory.mjs → gas-inventory.js} +25 -13
- package/gprompts/gas-inventory.json +116 -20
- package/gprompts/inventory-list.json +1 -1
- package/gprompts/package-lock.json +234 -0
- package/gprompts/package.json +1 -0
- package/package.json +3 -1
- package/src/index.js +2 -1
- package/src/services/advdocs/app.js +4 -23
- package/src/services/advdrive/app.js +6 -28
- package/src/services/advforms/app.js +6 -25
- package/src/services/advgmail/app.js +6 -26
- package/src/services/advsheets/app.js +6 -26
- package/src/services/advslides/app.js +6 -28
- package/src/services/common/lazyloader.js +22 -0
- package/src/services/documentapp/app.js +8 -42
- package/src/services/documentapp/appenderhelpers.js +2 -2
- package/src/services/documentapp/fakeparagraph.js +1 -1
- package/src/services/driveapp/app.js +6 -28
- package/src/services/formapp/app.js +5 -40
- package/src/services/gmailapp/app.js +7 -40
- package/src/services/logger/app.js +8 -0
- package/src/services/logger/fakelogger.js +162 -0
- package/src/services/scriptapp/app.js +7 -1
- package/src/services/scriptapp/behavior.js +1 -1
- package/src/services/session/app.js +10 -0
- package/src/services/slidesapp/app.js +5 -40
- package/src/services/spreadsheetapp/app.js +6 -50
- package/src/services/spreadsheetapp/fakesheet.js +3 -4
- package/src/services/stores/app.js +0 -1
- package/src/services/urlfetchapp/app.js +0 -1
- package/src/services/utilities/app.js +6 -20
- package/src/support/proxies.js +16 -0
- package/src/support/syncit.js +2 -2
- package/src/services/base/app.js +0 -33
- /package/src/services/{base → session}/fakesession.js +0 -0
package/gprompts/package.json
CHANGED
package/package.json
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
"node": ">=20.11.0"
|
|
4
4
|
},
|
|
5
5
|
"dependencies": {
|
|
6
|
+
"@google-cloud/logging": "^11.2.1",
|
|
6
7
|
"@mcpher/fake-gasenum": "^1.0.2",
|
|
7
8
|
"@mcpher/unit": "^1.1.11",
|
|
8
9
|
"@sindresorhus/is": "^7.0.1",
|
|
@@ -59,10 +60,11 @@
|
|
|
59
60
|
"testdocsstyles": "cp mainlocal.js main.js && node --env-file=.env ./test/testdocsstyles.js execute",
|
|
60
61
|
"testsandbox": "cp mainlocal.js main.js && node --env-file=.env ./test/testsandbox.js execute",
|
|
61
62
|
"testgmail": "cp mainlocal.js main.js && node --env-file=.env ./test/testgmail.js execute",
|
|
63
|
+
"testlogger": "cp mainlocal.js main.js && node --env-file=.env ./test/testlogger.js execute",
|
|
62
64
|
"pub": "cp mainlocal.js main.js && npm publish --access public"
|
|
63
65
|
},
|
|
64
66
|
"name": "@mcpher/gas-fakes",
|
|
65
|
-
"version": "1.0.
|
|
67
|
+
"version": "1.0.21",
|
|
66
68
|
"license": "MIT",
|
|
67
69
|
"main": "main.js",
|
|
68
70
|
"description": "A proof of concept implementation of Apps Script Environment on Node",
|
package/src/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import './services/scriptapp/app.js'
|
|
2
2
|
import './services/driveapp/app.js'
|
|
3
|
+
import './services/logger/app.js'
|
|
3
4
|
import './services/urlfetchapp/app.js'
|
|
4
5
|
import './services/utilities/app.js'
|
|
5
6
|
import './services/spreadsheetapp/app.js'
|
|
6
7
|
import './services/stores/app.js'
|
|
7
8
|
import './services/gmailapp/app.js'
|
|
8
|
-
import './services/
|
|
9
|
+
import './services/session/app.js'
|
|
9
10
|
import './services/advdrive/app.js'
|
|
10
11
|
import './services/advsheets/app.js'
|
|
11
12
|
import './services/advdocs/app.js'
|
|
@@ -5,28 +5,9 @@
|
|
|
5
5
|
* We do this by using a proxy, intercepting calls to the
|
|
6
6
|
* initial sigleton and diverting them to a completed one
|
|
7
7
|
*/
|
|
8
|
-
import { newFakeAdvDocs } from './fakeadvdocs.js'
|
|
9
|
-
import {
|
|
8
|
+
import { newFakeAdvDocs as maker } from './fakeadvdocs.js'
|
|
9
|
+
import { lazyLoaderApp } from '../common/lazyloader.js'
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
let _app = null;
|
|
12
|
+
_app = lazyLoaderApp(_app, 'Docs', maker)
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
* adds to global space to mimic Apps Script behavior
|
|
16
|
-
*/
|
|
17
|
-
const name = "Docs"
|
|
18
|
-
if (typeof globalThis[name] === typeof undefined) {
|
|
19
|
-
|
|
20
|
-
const getApp = () => {
|
|
21
|
-
// if it hasne been intialized yet then do that
|
|
22
|
-
if (!_app) {
|
|
23
|
-
console.log('...activating proxy for', name)
|
|
24
|
-
_app = newFakeAdvDocs()
|
|
25
|
-
}
|
|
26
|
-
// this is the actual driveApp we'll return from the proxy
|
|
27
|
-
return _app
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
Proxies.registerProxy(name, getApp)
|
|
31
|
-
|
|
32
|
-
}
|
|
@@ -1,32 +1,10 @@
|
|
|
1
|
-
// fake Apps Script DriveApp
|
|
2
|
-
/**
|
|
3
|
-
* the idea here is to create a global entry for the singleton
|
|
4
|
-
* before we actually have everything we need to create it.
|
|
5
|
-
* We do this by using a proxy, intercepting calls to the
|
|
6
|
-
* initial sigleton and diverting them to a completed one
|
|
7
|
-
*/
|
|
8
|
-
import { newFakeAdvDrive} from './fakeadvdrive.js'
|
|
9
|
-
import { Proxies } from '../../support/proxies.js'
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
let _app = null
|
|
13
1
|
|
|
14
2
|
/**
|
|
15
|
-
*
|
|
3
|
+
* the idea here is to create an empty global entry for the singleton
|
|
4
|
+
* but only load it when it is actually used.
|
|
16
5
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const getApp = () => {
|
|
21
|
-
// if it hasne been intialized yet then do that
|
|
22
|
-
if (!_app) {
|
|
23
|
-
console.log ('...activating proxy for', name)
|
|
24
|
-
_app = newFakeAdvDrive()
|
|
25
|
-
}
|
|
26
|
-
// this is the actual driveApp we'll return from the proxy
|
|
27
|
-
return _app
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
Proxies.registerProxy (name, getApp)
|
|
6
|
+
import { newFakeAdvDrive as maker} from './fakeadvdrive.js'
|
|
7
|
+
import { lazyLoaderApp } from '../common/lazyloader.js'
|
|
31
8
|
|
|
32
|
-
|
|
9
|
+
let _app = null;
|
|
10
|
+
_app = lazyLoaderApp(_app, 'Drive', maker)
|
|
@@ -1,31 +1,12 @@
|
|
|
1
1
|
|
|
2
|
-
/**
|
|
3
|
-
* NOTE - Although Apps Script doesnt yet have a Forms advanced service
|
|
4
|
-
* we're going to funnel everything through here as if there was one.
|
|
5
|
-
*
|
|
6
|
-
*/
|
|
7
|
-
import { newFakeAdvForms } from './fakeadvforms.js'
|
|
8
|
-
import { Proxies } from '../../support/proxies.js'
|
|
9
|
-
|
|
10
|
-
// This will eventually hold a proxy for Formsapp
|
|
11
|
-
let _app = null
|
|
12
2
|
|
|
13
3
|
/**
|
|
14
|
-
*
|
|
4
|
+
* the idea here is to create an empty global entry for the singleton
|
|
5
|
+
* but only load it when it is actually used.
|
|
15
6
|
*/
|
|
16
|
-
const name = "Forms"
|
|
17
|
-
if (typeof globalThis[name] === typeof undefined) {
|
|
18
|
-
|
|
19
|
-
const getApp = () => {
|
|
20
|
-
// if it hasne been intialized yet then do that
|
|
21
|
-
if (!_app) {
|
|
22
|
-
console.log('...activating proxy for', name)
|
|
23
|
-
_app = newFakeAdvForms()
|
|
24
|
-
}
|
|
25
|
-
// this is the actual formsapp we'll return from the proxy
|
|
26
|
-
return _app
|
|
27
|
-
}
|
|
28
7
|
|
|
29
|
-
|
|
8
|
+
import { newFakeAdvForms as maker} from './fakeadvforms.js'
|
|
9
|
+
import { lazyLoaderApp } from '../common/lazyloader.js'
|
|
30
10
|
|
|
31
|
-
|
|
11
|
+
let _app = null;
|
|
12
|
+
_app = lazyLoaderApp(_app, 'Forms', maker)
|
|
@@ -1,31 +1,11 @@
|
|
|
1
1
|
|
|
2
|
-
/**
|
|
3
|
-
* the idea here is to create a global entry for the singleton
|
|
4
|
-
* before we actually have everything we need to create it.
|
|
5
|
-
* We do this by using a proxy, intercepting calls to the
|
|
6
|
-
* initial sigleton and diverting them to a completed one
|
|
7
|
-
*/
|
|
8
|
-
import { newFakeAdvGmail } from './fakeadvgmail.js'
|
|
9
|
-
import { Proxies } from '../../support/proxies.js'
|
|
10
|
-
|
|
11
|
-
// This will eventually hold a proxy for DriveApp
|
|
12
|
-
let _app = null
|
|
13
2
|
|
|
14
3
|
/**
|
|
15
|
-
*
|
|
4
|
+
* the idea here is to create an empty global entry for the singleton
|
|
5
|
+
* but only load it when it is actually used.
|
|
16
6
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const getApp = () => {
|
|
21
|
-
// if it hasnt been intialized yet then do that
|
|
22
|
-
if (!_app) {
|
|
23
|
-
console.log('...activating proxy for', name)
|
|
24
|
-
_app = newFakeAdvGmail()
|
|
25
|
-
}
|
|
26
|
-
return _app
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
Proxies.registerProxy(name, getApp)
|
|
7
|
+
import { newFakeAdvGmail as maker} from './fakeadvgmail.js'
|
|
8
|
+
import { lazyLoaderApp } from '../common/lazyloader.js'
|
|
30
9
|
|
|
31
|
-
|
|
10
|
+
let _app = null;
|
|
11
|
+
_app = lazyLoaderApp(_app, 'Gmail', maker)
|
|
@@ -1,32 +1,12 @@
|
|
|
1
1
|
|
|
2
|
-
/**
|
|
3
|
-
* the idea here is to create a global entry for the singleton
|
|
4
|
-
* before we actually have everything we need to create it.
|
|
5
|
-
* We do this by using a proxy, intercepting calls to the
|
|
6
|
-
* initial sigleton and diverting them to a completed one
|
|
7
|
-
*/
|
|
8
|
-
import { newFakeAdvSheets } from './fakeadvsheets.js'
|
|
9
|
-
import { Proxies } from '../../support/proxies.js'
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
let _app = null
|
|
13
2
|
|
|
14
3
|
/**
|
|
15
|
-
*
|
|
4
|
+
* the idea here is to create an empty global entry for the singleton
|
|
5
|
+
* but only load it when it is actually used.
|
|
16
6
|
*/
|
|
17
|
-
const name = "Sheets"
|
|
18
|
-
if (typeof globalThis[name] === typeof undefined) {
|
|
19
|
-
|
|
20
|
-
const getApp = () => {
|
|
21
|
-
// if it hasne been intialized yet then do that
|
|
22
|
-
if (!_app) {
|
|
23
|
-
console.log('...activating proxy for', name)
|
|
24
|
-
_app = newFakeAdvSheets()
|
|
25
|
-
}
|
|
26
|
-
// this is the actual driveApp we'll return from the proxy
|
|
27
|
-
return _app
|
|
28
|
-
}
|
|
29
7
|
|
|
30
|
-
|
|
8
|
+
import { newFakeAdvSheets as maker} from './fakeadvsheets.js'
|
|
9
|
+
import { lazyLoaderApp } from '../common/lazyloader.js'
|
|
31
10
|
|
|
32
|
-
|
|
11
|
+
let _app = null;
|
|
12
|
+
_app = lazyLoaderApp(_app, 'Sheets', maker)
|
|
@@ -1,32 +1,10 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
|
-
* the idea here is to create
|
|
4
|
-
*
|
|
5
|
-
* We do this by using a proxy, intercepting calls to the
|
|
6
|
-
* initial sigleton and diverting them to a completed one
|
|
3
|
+
* the idea here is to create an empty global entry for the singleton
|
|
4
|
+
* but only load it when it is actually used.
|
|
7
5
|
*/
|
|
8
|
-
import { newFakeAdvSlides } from './fakeadvslides.js'
|
|
9
|
-
import {
|
|
6
|
+
import { newFakeAdvSlides as maker } from './fakeadvslides.js'
|
|
7
|
+
import { lazyLoaderApp } from '../common/lazyloader.js'
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* adds to global space to mimic Apps Script behavior
|
|
16
|
-
*/
|
|
17
|
-
const name = "Slides"
|
|
18
|
-
if (typeof globalThis[name] === typeof undefined) {
|
|
19
|
-
|
|
20
|
-
const getApp = () => {
|
|
21
|
-
// if it hasne been intialized yet then do that
|
|
22
|
-
if (!_app) {
|
|
23
|
-
console.log('...activating proxy for', name)
|
|
24
|
-
_app = newFakeAdvSlides()
|
|
25
|
-
}
|
|
26
|
-
// this is the actual driveApp we'll return from the proxy
|
|
27
|
-
return _app
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
Proxies.registerProxy(name, getApp)
|
|
31
|
-
|
|
32
|
-
}
|
|
9
|
+
let _app = null;
|
|
10
|
+
_app = lazyLoaderApp(_app, 'Slides', maker)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Proxies } from '../../support/proxies.js';
|
|
2
|
+
|
|
3
|
+
export const lazyLoaderApp = (app, name, maker) => {
|
|
4
|
+
|
|
5
|
+
if (typeof globalThis[name] === typeof undefined) {
|
|
6
|
+
|
|
7
|
+
const getApp = () => {
|
|
8
|
+
|
|
9
|
+
// if it hasne been intialized yet then do that
|
|
10
|
+
if (!app) {
|
|
11
|
+
//console.log ('...loading', name)
|
|
12
|
+
app = maker()
|
|
13
|
+
}
|
|
14
|
+
// this is the actual driveApp we'll return from the proxy
|
|
15
|
+
return app
|
|
16
|
+
}
|
|
17
|
+
//console.log ('...registering', name)
|
|
18
|
+
Proxies.registerProxy(name, getApp)
|
|
19
|
+
|
|
20
|
+
}
|
|
21
|
+
return app
|
|
22
|
+
}
|
|
@@ -1,47 +1,13 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
|
-
* the idea here is to create
|
|
3
|
-
*
|
|
4
|
-
* We do this by using a proxy, intercepting calls to the
|
|
5
|
-
* initial sigleton and diverting them to a completed one.
|
|
6
|
-
* We also need to make sure all element types are registered.
|
|
4
|
+
* the idea here is to create an empty global entry for the singleton
|
|
5
|
+
* but only load it when it is actually used.
|
|
7
6
|
*/
|
|
8
|
-
|
|
9
|
-
import {
|
|
7
|
+
|
|
8
|
+
import { lazyLoaderApp } from '../common/lazyloader.js'
|
|
9
|
+
import { newFakeDocumentApp as maker } from './fakedocumentapp.js';
|
|
10
10
|
import './elements.js'; // This ensures all element types register themselves before DocumentApp is used.
|
|
11
11
|
|
|
12
12
|
let _app = null;
|
|
13
|
-
|
|
14
|
-
const name = 'DocumentApp';
|
|
15
|
-
const serviceName = 'DocumentApp';
|
|
16
|
-
|
|
17
|
-
if (typeof globalThis[name] === typeof undefined) {
|
|
18
|
-
// By importing this, we ensure all element types register themselves.
|
|
19
|
-
const getApp = () => {
|
|
20
|
-
if (!_app) {
|
|
21
|
-
const realApp = newFakeDocumentApp();
|
|
22
|
-
|
|
23
|
-
_app = new Proxy(realApp, {
|
|
24
|
-
get(target, prop, receiver) {
|
|
25
|
-
if (prop === 'toString') {
|
|
26
|
-
return () => name;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const serviceBehavior = ScriptApp.__behavior.sandboxService[serviceName];
|
|
30
|
-
|
|
31
|
-
if (!serviceBehavior.enabled) {
|
|
32
|
-
throw new Error(`${name} service is disabled by sandbox settings.`);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const allowedMethods = serviceBehavior.methods;
|
|
36
|
-
if (allowedMethods && typeof target[prop] === 'function' && !allowedMethods.includes(prop)) {
|
|
37
|
-
throw new Error(`Method ${name}.${prop} is not allowed by sandbox settings.`);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return Reflect.get(...arguments);
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
return _app;
|
|
45
|
-
};
|
|
46
|
-
Proxies.registerProxy(name, getApp);
|
|
47
|
-
}
|
|
13
|
+
_app = lazyLoaderApp(_app, 'DocumentApp', maker)
|
|
@@ -121,7 +121,7 @@ const calculateInsertionPointsAndInitialRequests = (self, childIndex, isAppend,
|
|
|
121
121
|
if (isParaInsert) {
|
|
122
122
|
// Inserting into an existing paragraph. No newlines needed.
|
|
123
123
|
if (childIndex < 0 || childIndex > children.length) {
|
|
124
|
-
throw new Error(`Child index (${childIndex}) must be
|
|
124
|
+
throw new Error(`Child index (${childIndex}) must be less than or equal to the number of child elements (${children.length}).`);
|
|
125
125
|
}
|
|
126
126
|
if (children.length === 0 || childIndex === children.length) {
|
|
127
127
|
// Inserting into an empty paragraph or at the end.
|
|
@@ -137,7 +137,7 @@ const calculateInsertionPointsAndInitialRequests = (self, childIndex, isAppend,
|
|
|
137
137
|
} else {
|
|
138
138
|
// It's an insert operation, creating a new element in a Body/Header/etc.
|
|
139
139
|
if (childIndex < 0 || childIndex > children.length) {
|
|
140
|
-
throw new Error(`Child index (${childIndex}) must be
|
|
140
|
+
throw new Error(`Child index (${childIndex}) must be less than or equal to the number of child elements (${children.length}).`);
|
|
141
141
|
}
|
|
142
142
|
// Handle the case where we are inserting at the end (which is like an append).
|
|
143
143
|
if (childIndex === children.length) {
|
|
@@ -70,7 +70,7 @@ export class FakeParagraph extends FakeContainerElement {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
if (childIndex < 0 || childIndex > children.length) {
|
|
73
|
-
throw new Error(`Child index (${childIndex}) must be
|
|
73
|
+
throw new Error(`Child index (${childIndex}) must be less than or equal to the number of child elements (${children.length}).`);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
// Determine the character index for insertion.
|
|
@@ -1,32 +1,10 @@
|
|
|
1
|
-
// fake Apps Script DriveApp
|
|
2
1
|
/**
|
|
3
|
-
* the idea here is to create
|
|
4
|
-
*
|
|
5
|
-
* We do this by using a proxy, intercepting calls to the
|
|
6
|
-
* initial sigleton and diverting them to a completed one
|
|
2
|
+
* the idea here is to create an empty global entry for the singleton
|
|
3
|
+
* but only load it when it is actually used.
|
|
7
4
|
*/
|
|
8
|
-
import { newFakeDriveApp } from './fakedrive.js'
|
|
9
|
-
import { Proxies } from '../../support/proxies.js'
|
|
10
5
|
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
import { lazyLoaderApp } from '../common/lazyloader.js'
|
|
7
|
+
import { newFakeDriveApp as maker } from './fakedrive.js'
|
|
13
8
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
*/
|
|
17
|
-
const name = "DriveApp"
|
|
18
|
-
if (typeof globalThis[name] === typeof undefined) {
|
|
19
|
-
|
|
20
|
-
const getApp = () => {
|
|
21
|
-
// if it hasne been intialized yet then do that
|
|
22
|
-
if (!_app) {
|
|
23
|
-
console.log('...activating proxy for', name)
|
|
24
|
-
_app = newFakeDriveApp()
|
|
25
|
-
}
|
|
26
|
-
// this is the actual driveApp we'll return from the proxy
|
|
27
|
-
return _app
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
Proxies.registerProxy(name, getApp)
|
|
31
|
-
|
|
32
|
-
}
|
|
9
|
+
let _app = null;
|
|
10
|
+
_app = lazyLoaderApp(_app, 'DriveApp', maker)
|
|
@@ -1,44 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* the idea here is to create
|
|
3
|
-
*
|
|
4
|
-
* We do this by using a proxy, intercepting calls to the
|
|
5
|
-
* initial singleton and diverting them to a completed one
|
|
2
|
+
* the idea here is to create an empty global entry for the singleton
|
|
3
|
+
* but only load it when it is actually used.
|
|
6
4
|
*/
|
|
7
|
-
import { newFakeFormApp } from './fakeformapp.js';
|
|
8
|
-
import {
|
|
5
|
+
import { newFakeFormApp as maker} from './fakeformapp.js';
|
|
6
|
+
import { lazyLoaderApp } from '../common/lazyloader.js'
|
|
9
7
|
|
|
10
8
|
let _app = null;
|
|
11
|
-
|
|
12
|
-
const name = 'FormApp';
|
|
13
|
-
const serviceName = 'FormApp';
|
|
14
|
-
|
|
15
|
-
if (typeof globalThis[name] === typeof undefined) {
|
|
16
|
-
const getApp = () => {
|
|
17
|
-
if (!_app) {
|
|
18
|
-
const realApp = newFakeFormApp();
|
|
19
|
-
|
|
20
|
-
_app = new Proxy(realApp, {
|
|
21
|
-
get(target, prop, receiver) {
|
|
22
|
-
if (prop === 'toString') {
|
|
23
|
-
return () => name;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const serviceBehavior = ScriptApp.__behavior.sandboxService[serviceName];
|
|
27
|
-
|
|
28
|
-
if (!serviceBehavior.enabled) {
|
|
29
|
-
throw new Error(`${name} service is disabled by sandbox settings.`);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const allowedMethods = serviceBehavior.methods;
|
|
33
|
-
if (allowedMethods && typeof target[prop] === 'function' && !allowedMethods.includes(prop)) {
|
|
34
|
-
throw new Error(`Method ${name}.${prop} is not allowed by sandbox settings.`);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return Reflect.get(target, prop, receiver);
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
return _app;
|
|
42
|
-
};
|
|
43
|
-
Proxies.registerProxy(name, getApp);
|
|
44
|
-
}
|
|
9
|
+
_app = lazyLoaderApp(_app, 'FormApp', maker)
|
|
@@ -1,44 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
|
-
* the idea here is to create
|
|
3
|
-
*
|
|
4
|
-
* We do this by using a proxy, intercepting calls to the
|
|
5
|
-
* initial singleton and diverting them to a completed one
|
|
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
6
|
*/
|
|
7
|
-
import { newFakeGmailApp } from './fakegmailapp.js';
|
|
8
|
-
import {
|
|
7
|
+
import { newFakeGmailApp as maker } from './fakegmailapp.js';
|
|
8
|
+
import { lazyLoaderApp } from '../common/lazyloader.js'
|
|
9
9
|
|
|
10
10
|
let _app = null;
|
|
11
|
-
|
|
12
|
-
const name = 'GmailApp';
|
|
13
|
-
const serviceName = 'GmailApp';
|
|
14
|
-
|
|
15
|
-
if (typeof globalThis[name] === typeof undefined) {
|
|
16
|
-
const getApp = () => {
|
|
17
|
-
if (!_app) {
|
|
18
|
-
const realApp = newFakeGmailApp();
|
|
19
|
-
|
|
20
|
-
_app = new Proxy(realApp, {
|
|
21
|
-
get(target, prop, receiver) {
|
|
22
|
-
if (prop === 'toString') {
|
|
23
|
-
return () => name;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const serviceBehavior = ScriptApp.__behavior.sandboxService[serviceName];
|
|
27
|
-
|
|
28
|
-
if (serviceBehavior && !serviceBehavior.enabled) {
|
|
29
|
-
throw new Error(`${name} service is disabled by sandbox settings.`);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const allowedMethods = serviceBehavior?.methods;
|
|
33
|
-
if (allowedMethods && typeof target[prop] === 'function' && !allowedMethods.includes(prop)) {
|
|
34
|
-
throw new Error(`Method ${name}.${prop} is not allowed by sandbox settings.`);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return Reflect.get(target, prop, receiver);
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
return _app;
|
|
42
|
-
};
|
|
43
|
-
Proxies.registerProxy(name, getApp);
|
|
44
|
-
}
|
|
11
|
+
_app = lazyLoaderApp(_app, 'GmailApp', maker)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* the idea here is to create an empty global entry for the singleton
|
|
3
|
+
* but only load it when it is actually used.
|
|
4
|
+
*/
|
|
5
|
+
import { lazyLoaderApp } from '../common/lazyloader.js'
|
|
6
|
+
import { newFakeLogger as maker } from './fakelogger.js';
|
|
7
|
+
let _app = null;
|
|
8
|
+
_app = lazyLoaderApp(_app, 'Logger', maker)
|