gas-client is a client-side utility library designed for Google Apps Script projects, providing a modern, promise-based interface for calling server-side Apps Script functions. It acts as a user-friendly wrapper around the native `google.script.run` API, abstracting away callback-based error and success handling in favor of standard JavaScript Promises and async/await syntax. The current stable version is 1.2.1, with minor releases and patches occurring as needed to address compatibility and improvements. A key differentiator is its ability to provide consistent access to `google.script.host` functions (like `close()` or `setHeight()`) in both production Apps Script environments and local development setups. It is specifically designed to integrate seamlessly with local development servers, such as those used in React Google Apps Script projects, by allowing explicit configuration of allowed development domains. This enables a more streamlined and conventional client-side development workflow for Apps Script.
npm install gas-clientVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to initialize `GASClient`, call a server-side Apps Script function using promises or async/await, optionally configure it for local development, and utilize `scriptHostFunctions`.
Review your codebase for compatibility, especially if you had custom type declarations or relied on previous internal structures. Update client-side code to leverage the officially supported TypeScript types and new API patterns introduced in `v1.0.0`.
Ensure that the `allowedDevelopmentDomains` property in your `GASClient` configuration exactly matches the full `https://localhost:PORT` URL of your local development server. This config is ignored in production.
Upgrade to `gas-client@1.2.1` or newer. This version includes optional chaining (`?.`) when accessing `google.script.host.editor`, mitigating the error in web app contexts.
Always use `.then((response) => {...}).catch((error) => {...})` or `try { const response = await serverFunctions.myFunction(); } catch (error) {...}` to ensure proper error handling and response processing.Ensure `serverFunctions` is properly destructured from a `new GASClient()` instance: `const { serverFunctions } = new GASClient(config); serverFunctions.someServerFunction();`Set `allowedDevelopmentDomains` in your `GASClient` constructor options to the exact `https://localhost:PORT` URL of your running development server (e.g., `{ allowedDevelopmentDomains: 'https://localhost:3000' }`).Always attach a `.catch()` handler to your promise chain (e.g., `serverFunctions.myFunc().then(...).catch(err => console.error(err))`) or wrap `await` calls in `try...catch` blocks (`try { await serverFunctions.myFunc(); } catch (err) { console.error(err); }`) to handle potential errors.No dependency data recorded yet.