Skip to content

miyaji255/gas-fetch-polyfill

 
 

Repository files navigation

gas-fetch-polyfill

This is a polyfill for the fetch API on Google Apps Script. This polyfill is forked from github/fetch and modified to work on Google Apps Script.

The compitability of fetch-google-apps-script-ponyfill is not good enough for me, so I created this polyfill.

Installation

npm install gas-fetch-polyfill

Usage

import 'gas-fetch-polyfill';

await fetch('https://example.com');

You can also use this as a ponyfill.

import { fetch } from 'gas-fetch-polyfill/ponyfill';

await fetch('https://example.com');

Example

This polyfill makes it possible to use Hono Client on Google Apps Script.

import 'gas-fetch-polyfill';
import { hc } from 'hono/client';
import type { AppType } from './server';

export const client = hc<AppType>(
  'https://example.com',
  { fetch }
);

Why gas-fetch-polyfill is bundled?

Most libraries are not bundled with their dependencies, but gas-fetch-polyfill is bundled with its dependencies. This is because the dependencies of gas-fetch-polyfill (abort-controller and event-target-shim) are not supported exports and module fields in package.json.

I bundled this so that there is no need to do any special configuration.

Compatibilities

Request

Status Remarks
Request() constructor
Request.prototype.body ReadableStream is not supported on GAS
Request.prototype.bodyUsed
Request.prototype.cache
Request.prototype.credentials
Request.prototype.destination
Request.prototype.headers
Request.prototype.integrity
Request.prototype.isHistoryNavigation
Request.prototype.keepalive
Request.prototype.method Normalize to lowercase
Request.prototype.mode
Request.prototype.redirect
Request.prototype.referrer
Request.prototype.referrerPolicy
Request.prototype.signal
Request.prototype.url
Request.prototype.arrayBuffer()
Request.prototype.blob() ⚠️ Retuning GAS Blob
Request.prototype.bytes()
Request.prototype.clone()
Request.prototype.formData()
Request.prototype.json()
Request.prototype.text()

Response

Status Remarks
Response() constructor
Response.error() type is "error"
Response.json()
Response.redirect()
Response.prototype.body ReadableStream is not supported on GAS
Response.prototype.bodyUsed
Response.prototype.headers
Reponse.prototype.ok
Response.prototype.redirected
Response.prototype.status
Response.prototype.statusText
Response.prototype.type ⚠️ Always be "default"
Response.prototype.url
Response.prototype.arrayBuffer()
Response.prototype.blob() ⚠️ Retuning GAS Blob
Response.prototype.bytes()
Response.prototype.clone()
Response.prototype.formData()
Response.prototype.json()
Response.prototype.text()

Headers

Status Remarks
Headers() constructor
[Symbol.iterator]
Headers.prototype.append()
Headers.prototype.delete()
Headers.prototype.entries()
Headers.prototype.forEach()
Headers.prototype.get()
Headers.prototype.getSetCookie()
Headers.prototype.has()
Iteration combines duplicate header names
Iteration is lexicographically sorted
Headers.prototype.keys()
Headers.prototype.set()
Headers.prototype.values()

URL

Status Remarks
URL() constructor
URL.parse()
URL.canParse()
URL.createObjectURL()
URL.revokeObjectURL()
URL.prototype.hash
URL.prototype.host
URL.prototype.hostname
URL.prototype.href
URL.prototype.origin
URL.prototype.password
URL.prototype.pathname
URL.prototype.port
URL.prototype.protocol
URL.prototype.search
URL.prototype.searchParams
URL.prototype.username
URL.prototype.toJSON()
URL.prototype.toString()

URLSearchParams

Status Remarks
URLSearchParams() constructor
URLSearchParams.prototype.size
URLSearchParams.prototype.append()
URLSearchParams.prototype.delete()
URLSearchParams.prototype.entries()
URLSearchParams.prototype.forEach()
URLSearchParams.prototype.get()
URLSearchParams.prototype.getAll()
URLSearchParams.prototype.has()
URLSearchParams.prototype.keys()
URLSearchParams.prototype.set()
URLSearchParams.prototype.sort()
URLSearchParams.prototype.values()
URLSearchParams.prototype.toString()

AbortController AbortController and AbortSignal are implemented using the mysticatea/abort-controller.

Status Remarks
AbortController() constructor
AbortController.prototype.signal
AbortController.prototype.abort()

AbortSignal

Status Remarks
AbortSignal.abort()
AbortSignal.any()
AbortSignal.timeout()
AbortSignal.prototype.aborted
AbortSignal.prototype.reason
AbortSignal.prototype.onabort
AbortSignal.prototype.addEventListener()
AbortSignal.prototype.removeEventListener()
AbortSignal.prototype.dispatchEvent()
AbortSignal.prototype.throwIfAborted()

License

MIT

src/fetch.ts is based on github/fetch and is licensed under MIT.

The bundled code includes abort-controller and event-target-shim. They are licensed under MIT.

About

A fetch polyfill for Google Apps Script.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 100.0%