update wrangler config and source maps
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"version": 3,
|
||||
"sources": ["WebStorage.ts"],
|
||||
"sources": ["../static_src/WebStorage.ts"],
|
||||
"sourcesContent": ["/**\n * @callback fetch\n * @param {RequestInfo} resource\n * @param {RequestInit} options\n * @returns {Promise<Response>}\n */\n\nexport default class WebStorage {\n\n #origin = new URL(import.meta.url).origin\n #auth_provider: import('@twurple/auth').AuthProvider = null;\n #cache: Cache = null\n #fetch: typeof globalThis.fetch = null\n\n /**\n * Creates a fetch request wrapper that returns cached responses when the server can't be reached.\n * When only a path is provided, the origin defaults to the same origin this module was loaded from.\n * When the origin matches this script, authorization headers are added automatically.\n * You can also use this for GET requests to any orgigin, but other methods may have unknown behavior.\n * @param {import('@twurple/auth').AuthProvider} auth_provider used to add the authentication header to requests for web storage\n * @param {fetch} fetch defaults to `globalThis.fetch`, allows you to further customize fetch behavior via chaining, for example with `fetch-retry`\n */\n constructor(auth_provider: import('@twurple/auth').AuthProvider, fetch: typeof globalThis.fetch = (resource,options)=>{return globalThis.fetch(resource,options)}) {\n this.#fetch = fetch\n this.#auth_provider = auth_provider\n auth_provider.getAccessTokenForUser(undefined)\n .then(token => caches.open(token.userId + '/' + auth_provider.clientId))\n .then(cache => this.#cache = cache)\n }\n\n /**\n * \n * @param {String | URL} resource \n * @param {RequestInit} options \n */\n async fetch(resource: string | URL, options: RequestInit={}) {\n resource = new URL(resource, this.#origin)\n if (resource.origin == this.#origin) {\n const token = await this.#auth_provider.getAccessTokenForUser(undefined)\n if (!options.headers) {\n options.headers = {}\n }\n options.headers['authorization'] = 'OAuth ' + token.accessToken\n }\n if ('method' in options) {\n switch (options.method) {\n case 'PUT':\n case 'POST': {\n const response = await this.#fetch(resource, options)\n if (!response.ok) {\n return response\n }\n const blob = await new Request(resource, options).blob()\n this.#cache.put(resource, new Response(blob))\n return response\n }\n case 'DELETE': {\n const response = await this.#fetch(resource, options)\n if (!response.ok) {\n return response\n }\n this.#cache.delete(resource)\n return response\n }\n }\n }\n return this.#fetch(resource, options)\n .then(async response => {\n if (response.status >= 500) {\n throw new Error(response.statusText + '\\n' + await response.text())\n }\n this.#cache.put(resource, response.clone())\n return response\n }).catch(error => {\n console.warn(error)\n return this.#cache.match(resource)\n }\n )\n }\n}"],
|
||||
"mappings": "2UAAA,IAAAA,EAAAC,EAAAC,EAAAC,EAOqBC,EAArB,KAAgC,CAe5B,YAAYC,EAAqDC,EAAiC,CAACC,EAASC,IAAkB,WAAW,MAAMD,EAASC,CAAO,EAAI,CAbnKC,EAAA,KAAAT,EAAU,IAAI,IAAI,YAAY,GAAG,EAAE,QACnCS,EAAA,KAAAR,EAAuD,MACvDQ,EAAA,KAAAP,EAAgB,MAChBO,EAAA,KAAAN,EAAkC,MAW9BO,EAAA,KAAKP,EAASG,GACdI,EAAA,KAAKT,EAAiBI,GACtBA,EAAc,sBAAsB,MAAS,EACxC,KAAKM,GAAS,OAAO,KAAKA,EAAM,OAAS,IAAMN,EAAc,QAAQ,CAAC,EACtE,KAAKO,GAASF,EAAA,KAAKR,EAASU,EAAK,CAC1C,CAOA,MAAM,MAAML,EAAwBC,EAAqB,CAAC,EAAG,CAEzD,GADAD,EAAW,IAAI,IAAIA,EAAUM,EAAA,KAAKb,EAAO,EACrCO,EAAS,QAAUM,EAAA,KAAKb,GAAS,CACjC,IAAMW,EAAQ,MAAME,EAAA,KAAKZ,GAAe,sBAAsB,MAAS,EAClEO,EAAQ,UACTA,EAAQ,QAAU,CAAC,GAEvBA,EAAQ,QAAQ,cAAmB,SAAWG,EAAM,WACxD,CACA,GAAI,WAAYH,EACZ,OAAQA,EAAQ,OAAQ,CACpB,IAAK,MACL,IAAK,OAAQ,CACT,IAAMM,EAAW,MAAMD,EAAA,KAAKV,GAAL,UAAYI,EAAUC,GAC7C,GAAI,CAACM,EAAS,GACV,OAAOA,EAEX,IAAMC,EAAO,MAAM,IAAI,QAAQR,EAAUC,CAAO,EAAE,KAAK,EACvD,OAAAK,EAAA,KAAKX,GAAO,IAAIK,EAAU,IAAI,SAASQ,CAAI,CAAC,EACrCD,CACX,CACA,IAAK,SAAU,CACX,IAAMA,EAAW,MAAMD,EAAA,KAAKV,GAAL,UAAYI,EAAUC,GAC7C,OAAKM,EAAS,IAGdD,EAAA,KAAKX,GAAO,OAAOK,CAAQ,EACpBO,CACX,CACJ,CAEJ,OAAOD,EAAA,KAAKV,GAAL,UAAYI,EAAUC,GACxB,KAAK,MAAMM,GAAY,CACpB,GAAIA,EAAS,QAAU,IACnB,MAAM,IAAI,MAAMA,EAAS,WAAa;AAAA,EAAO,MAAMA,EAAS,KAAK,CAAC,EAEtE,OAAAD,EAAA,KAAKX,GAAO,IAAIK,EAAUO,EAAS,MAAM,CAAC,EACnCA,CACX,CAAC,EAAE,MAAME,IACL,QAAQ,KAAKA,CAAK,EACXH,EAAA,KAAKX,GAAO,MAAMK,CAAQ,EAEzC,CACJ,CACJ,EAtEIP,EAAA,YACAC,EAAA,YACAC,EAAA,YACAC,EAAA",
|
||||
"names": ["_origin", "_auth_provider", "_cache", "_fetch", "WebStorage", "auth_provider", "fetch", "resource", "options", "__privateAdd", "__privateSet", "token", "cache", "__privateGet", "response", "blob", "error"]
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user