@php-wasm/web-service-worker 2.0.15 → 2.0.16

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.
Files changed (3) hide show
  1. package/index.cjs +1 -1
  2. package/index.js +1 -1
  3. package/package.json +3 -3
package/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@php-wasm/scopes"),R=25e3;let g=0;function m(e,t,...s){const r=u();return e.postMessage({...t,requestId:r},...s),r}function u(){return++g}function h(e,t,s=R){return new Promise((r,c)=>{const o=a=>{a.data.type==="response"&&a.data.requestId===t&&(e.removeEventListener("message",o),clearTimeout(l),r(a.data.response))},l=setTimeout(()=>{c(new Error("Request timed out")),e.removeEventListener("message",o)},s);e.addEventListener("message",o)})}function w(e,t){return{type:"response",requestId:e,response:t}}async function E(e){let t=new URL(e.request.url);if(!d.isURLScoped(t))try{const n=new URL(e.request.referrer);t=d.setURLScope(t,d.getURLScope(n))}catch{}const s=e.request.headers.get("content-type"),r=e.request.method==="POST"?new Uint8Array(await e.request.clone().arrayBuffer()):void 0,c={};for(const n of e.request.headers.entries())c[n[0]]=n[1];let o;try{const n={method:"request",args:[{body:r,url:t.toString(),method:e.request.method,headers:{...c,Host:t.host,"User-agent":self.navigator.userAgent,"Content-type":s}}]},p=d.getURLScope(t);if(p===null)throw new Error(`The URL ${t.toString()} is not scoped. This should not happen.`);const f=await y(n,p);o=await h(self,f),delete o.headers["x-frame-options"]}catch(n){throw console.error(n,{url:t.toString()}),n}if(o.httpStatusCode>=300&&o.httpStatusCode<=399&&o.headers.location)return Response.redirect(o.headers.location[0],o.httpStatusCode);const a=[101,103,204,205,304].includes(o.httpStatusCode)?null:o.bytes;return new Response(a,{headers:o.headers,status:o.httpStatusCode})}async function y(e,t){const s=u();for(const r of await self.clients.matchAll({includeUncontrolled:!0}))r.postMessage({...e,scope:t,requestId:s});return s}async function i(e,t){const s=["GET","HEAD"].includes(e.method)||"body"in t?void 0:await e.blob();return new Request(t.url||e.url,{body:s,method:e.method,headers:e.headers,referrer:e.referrer,referrerPolicy:e.referrerPolicy,mode:e.mode==="navigate"?"same-origin":e.mode,credentials:e.credentials,cache:e.cache,redirect:e.redirect,integrity:e.integrity,...t})}async function S(e){if(!e.body)return[e,e];const[t,s]=e.body.tee();return[await i(e,{body:t,duplex:"half"}),await i(e,{body:s,duplex:"half"})]}function b(e){const t={};return e.headers.forEach((s,r)=>{t[r]=s}),t}exports.awaitReply=h;exports.broadcastMessageExpectReply=y;exports.cloneRequest=i;exports.convertFetchEventToPHPRequest=E;exports.getNextRequestId=u;exports.getRequestHeaders=b;exports.postMessageExpectReply=m;exports.responseTo=w;exports.teeRequest=S;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@php-wasm/scopes"),R=25e3;let g=0;function m(e,t,...s){const r=u();return e.postMessage({...t,requestId:r},...s),r}function u(){return++g}function h(e,t,s=R){return new Promise((r,c)=>{const o=a=>{a.data.type==="response"&&a.data.requestId===t&&(e.removeEventListener("message",o),clearTimeout(l),r(a.data.response))},l=setTimeout(()=>{c(new Error("Request timed out")),e.removeEventListener("message",o)},s);e.addEventListener("message",o)})}function w(e,t){return{type:"response",requestId:e,response:t}}async function E(e){let t=new URL(e.request.url);if(!d.isURLScoped(t))try{const n=new URL(e.request.referrer);t=d.setURLScope(t,d.getURLScope(n))}catch{}const s=e.request.headers.get("content-type"),r=e.request.method==="POST"?new Uint8Array(await e.request.clone().arrayBuffer()):void 0,c={};for(const n of e.request.headers.entries())c[n[0]]=n[1];let o;try{const n={method:"request",args:[{body:r,url:t.toString(),method:e.request.method,headers:{...c,Host:t.host,"User-agent":self.navigator.userAgent,"Content-type":s}}]},p=d.getURLScope(t);if(p===null)throw new Error(`The URL ${t.toString()} is not scoped. This should not happen.`);const f=await y(n,p);o=await h(self,f),delete o.headers["x-frame-options"]}catch(n){throw console.error(n,{url:t.toString()}),n}if(o.httpStatusCode>=300&&o.httpStatusCode<=399&&o.headers.location)return Response.redirect(new URL(o.headers.location[0],t.toString()),o.httpStatusCode);const a=[101,103,204,205,304].includes(o.httpStatusCode)?null:o.bytes;return new Response(a,{headers:o.headers,status:o.httpStatusCode})}async function y(e,t){const s=u();for(const r of await self.clients.matchAll({includeUncontrolled:!0}))r.postMessage({...e,scope:t,requestId:s});return s}async function i(e,t){const s=["GET","HEAD"].includes(e.method)||"body"in t?void 0:await e.blob();return new Request(t.url||e.url,{body:s,method:e.method,headers:e.headers,referrer:e.referrer,referrerPolicy:e.referrerPolicy,mode:e.mode==="navigate"?"same-origin":e.mode,credentials:e.credentials,cache:e.cache,redirect:e.redirect,integrity:e.integrity,...t})}async function S(e){if(!e.body)return[e,e];const[t,s]=e.body.tee();return[await i(e,{body:t,duplex:"half"}),await i(e,{body:s,duplex:"half"})]}function b(e){const t={};return e.headers.forEach((s,r)=>{t[r]=s}),t}exports.awaitReply=h;exports.broadcastMessageExpectReply=y;exports.cloneRequest=i;exports.convertFetchEventToPHPRequest=E;exports.getNextRequestId=u;exports.getRequestHeaders=b;exports.postMessageExpectReply=m;exports.responseTo=w;exports.teeRequest=S;
package/index.js CHANGED
@@ -73,7 +73,7 @@ async function U(e) {
73
73
  }
74
74
  if (o.httpStatusCode >= 300 && o.httpStatusCode <= 399 && o.headers.location)
75
75
  return Response.redirect(
76
- o.headers.location[0],
76
+ new URL(o.headers.location[0], t.toString()),
77
77
  o.httpStatusCode
78
78
  );
79
79
  const a = [101, 103, 204, 205, 304].includes(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/web-service-worker",
3
- "version": "2.0.15",
3
+ "version": "2.0.16",
4
4
  "description": "PHP.wasm – service worker utils",
5
5
  "repository": {
6
6
  "type": "git",
@@ -31,7 +31,7 @@
31
31
  "main": "./index.cjs",
32
32
  "module": "./index.js",
33
33
  "license": "GPL-2.0-or-later",
34
- "gitHead": "f3f73a4fc48bbe3ae099da4c1418d2f125d16d0a",
34
+ "gitHead": "3587b829420250e2de23d2643151da75c0ccdbec",
35
35
  "engines": {
36
36
  "node": ">=20.18.3",
37
37
  "npm": ">=10.1.0"
@@ -44,7 +44,7 @@
44
44
  "ws": "^8.18.0"
45
45
  },
46
46
  "dependencies": {
47
- "@php-wasm/scopes": "2.0.15"
47
+ "@php-wasm/scopes": "2.0.16"
48
48
  },
49
49
  "optionalDependencies": {
50
50
  "fs-ext": "2.1.1"