@dgcode/html-service
v0.1.25
Published
mocked class for google apps script's HtmlService and google.script api
Downloads
4
Readme
@dgcode/html-service
mocked class for google apps script's HtmlService and google.script api
Install
$ npm install @dgcode/html-service
Usage
@dgcode/html-service serves two purposes (which can be used independently):
- provide a non-functional class (merely useable as type definition) for Google Apps Script's server-side HtmlService API;
- provide a semi-functional wrapper for Google Apps Script's client-side google.script API.
HtmlService
To get started:
import { HtmlService } from '@dgcode/html-service'
This exposes an object with methods that mirror Google's HtmlService API without any real implementation - when run in Node.
The main purpose of this object is to provide type completion in your favorite IDE, and to seamlessly resolve to the actual HtmlService
instance from Google when bundling and publishing your code to Google Apps Script with gscript.
google.script
To get started:
import { google } from '@dgcode/html-service';
The google
object provides the 4 major APIs from Google's client-side tools:
Note that the google
variable imported here is completely separate from the global google
object when you run your script in an Apps Script HTML file. The imported google
object will try to mirror as many methods as possible from the global object and execute them when available.
tl;dr: Always import { google } ...
from this library and let it handle the tasks for you, regardless of the development environment.
google.script.run
To run a method defined in your server-side code, you can use the helper function .call
as below:
| With @dgcode/html-service
| The native ("Google") way |
|------------------------------------------------------|-----------------------------------------------|
| google.script.run.call('someMethod', ...arguments)
| google.script.run.someMethod(...arguments)
|
For example, if a global foo(number)
function was implemented on the server-side, then the client-side script would look like:
import { google } from '@dgcode/html-service';
google.script.run
.withSuccessHandler(res => {...})
.withFailureHandler(err => {...})
.call('foo', 5);
License
MIT