@altertable/data-app-worker 0.0.0-stage → 0.72.0
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.
- package/LICENSE +21 -0
- package/README.md +38 -2
- package/dist/index.js +109 -0
- package/dist/index.js.map +12 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/trusted-parent.d.ts +1 -0
- package/package.json +48 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Altertable
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,39 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @altertable/data-app-worker
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Self-contained sandbox Worker for serving Altertable data apps.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```fish
|
|
8
|
+
bun add @altertable/data-app-worker
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
Resolve the installed Worker asset and read it for your deployment tooling:
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import { readFile } from 'node:fs/promises';
|
|
17
|
+
|
|
18
|
+
const workerScript = await readFile(
|
|
19
|
+
new URL(import.meta.resolve('@altertable/data-app-worker')),
|
|
20
|
+
'utf8'
|
|
21
|
+
);
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Upload `workerScript` as the deployment's main module. Configure the string
|
|
25
|
+
bindings `DOMAIN_NAME` (runtime domain) and `PARENT_ORIGINS` (trusted host origins),
|
|
26
|
+
plus your deployment's domains and routes.
|
|
27
|
+
|
|
28
|
+
The published JavaScript includes the bootstrap and HTML with no runtime imports.
|
|
29
|
+
The deployed Worker requires no React or Bun. Data queries go through the host's
|
|
30
|
+
authorized message router.
|
|
31
|
+
|
|
32
|
+
## Documentation
|
|
33
|
+
|
|
34
|
+
See the [Worker guide](https://github.com/altertable-ai/data-app/blob/main/docs/worker.md)
|
|
35
|
+
for deployment, bindings, and origin rules.
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
[MIT](LICENSE)
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// packages/data-app-embed/dist/chunks/index-aqzf4zgk.js
|
|
2
|
+
var PAGE_CSP2 = "default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; img-src data: blob:; connect-src 'none'; form-action 'none'; base-uri 'none'";
|
|
3
|
+
var inlineBootstrap = '(()=>{function pe(e){return e===null||typeof e==="string"||typeof e==="boolean"||typeof e==="number"&&Number.isFinite(e)}function G(e){return!!e&&typeof e==="object"&&!Array.isArray(e)&&Object.values(e).every(pe)}var Ee=Symbol("data-app.dimensionSource");var H=Symbol.for("@altertable/data-app/MessageRoutingError");class I extends Error{code;requestId;[H]=!0;static[Symbol.hasInstance](e){return e instanceof Error&&e[H]===!0}constructor(e,n,t,r){super(n,r);this.code=e,this.requestId=t,this.name="MessageRoutingError"}}function fe(e){return e}function C(e){return{operations:e,input(n){if(!n||typeof n!=="object")throw Error("Invalid query.");let t=n;if(typeof t.operation!=="string"||!t.operation||t.operation.length>256||t.operation.includes("/"))throw Error("Invalid operation.");let r=e&&Object.hasOwn(e,t.operation)?e[t.operation]:void 0;if(e&&!r)throw Error("Unknown operation.");return{operation:t.operation,input:r?r.input(t.input):t.input}},output(n){if(!n||typeof n!=="object")throw Error("Invalid data response.");let t=n;if(!Number.isInteger(t.status)||t.status<100||t.status>599||!t.body||typeof t.body!=="object"||Array.isArray(t.body))throw Error("Invalid data response.");let r=t.body;if(t.status<200||t.status>=300){let o=r.error;throw new I(typeof o?.code==="string"?o.code:"request_failed",typeof o?.message==="string"?o.message:"Could not load data.",typeof o?.requestId==="string"?o.requestId:void 0)}if(!("data"in r)||typeof r.requestId!=="string"||typeof r.queriedAt!=="string"||!Array.isArray(r.queryIds)||!r.queryIds.every((o)=>typeof o==="string"))throw Error("Invalid data envelope.");if(r.queries!==void 0&&(!Array.isArray(r.queries)||!r.queries.every((o)=>o&&typeof o==="object"&&typeof o.name==="string"&&typeof o.statement==="string"&&(o.params===void 0||G(o.params))&&(o.queryId===void 0||typeof o.queryId==="string"))))throw Error("Invalid query evidence.");return{status:t.status,body:r}}}}var V=fe({input(e){if(!e||typeof e!=="object")throw Error("Invalid SQL query.");let n=e;if(typeof n.statement!=="string"||!n.statement.trim()||typeof n.limit!=="number"||!Number.isSafeInteger(n.limit)||n.limit<1||n.params!==void 0&&!G(n.params))throw Error("Invalid SQL query.");return{statement:n.statement,limit:n.limit,...n.params===void 0?{}:{params:n.params}}},output(e,n){if(!e||typeof e!=="object")throw Error("Invalid query result.");let t=e;if(!Array.isArray(t.columns)||!t.columns.every((r)=>r&&typeof r.name==="string"&&(r.type===void 0||typeof r.type==="string"))||!Array.isArray(t.rows)||t.rows.length>n.limit||!t.rows.every((r)=>Array.isArray(r)&&r.length===t.columns.length)||t.queryId!==void 0&&typeof t.queryId!=="string")throw Error("Invalid query result.");return{columns:t.columns,rows:t.rows,...t.queryId===void 0?{}:{queryId:t.queryId}}}});function N(){if(typeof crypto.randomUUID==="function")return crypto.randomUUID();let e=crypto.getRandomValues(new Uint8Array(16));e[6]=e[6]&15|64,e[8]=e[8]&63|128;let n=Array.from(e,(t)=>t.toString(16).padStart(2,"0"));return[n.slice(0,4),n.slice(4,6),n.slice(6,8),n.slice(8,10),n.slice(10)].map((t)=>t.join("")).join("-")}var X=Symbol.for("@altertable/data-app/DataAppError");class A extends Error{code;requestId;[X]=!0;static[Symbol.hasInstance](e){return e instanceof Error&&e[X]===!0}constructor(e,n,t){super(e);this.code=n,this.requestId=t,this.name="DataAppError"}}function me(e){if(!e||typeof e!=="object")return!1;let n=e;return(n.method==="log"||n.method==="info"||n.method==="warn"||n.method==="error")&&Array.isArray(n.args)&&n.args.length<=128}var K="altertable:data-app";var te=128,re=60000;function T(e){return typeof e==="string"&&/^[a-zA-Z0-9_-]{1,128}$/.test(e)}function b({wire:e,from:n,session:t,parse:r}){return{wire:e,from:n,session:t,parse:r}}function M(e){if(!T(e.id))throw Error("Invalid request ID.");return e.id}function P(e,n){let t=e[n];if(typeof t!=="string")throw Error(`Invalid ${n}.`);return t}function _(){return{}}var w={channel:K,version:1,events:{connect:b({wire:"bridge:connect",from:"host",session:"none",parse:_}),ready:b({wire:"bridge:ready",from:"app",session:"none",parse:_}),initialize:b({wire:"bridge:initialize",from:"host",session:"establish",parse:(e)=>({state:e.state})}),request:b({wire:"bridge:request",from:"app",session:"current",parse:(e)=>{let n=P(e,"route");if(!n||n.length>256)throw Error("Invalid message route.");return{id:M(e),route:n,payload:e.payload}}}),result:b({wire:"bridge:result",from:"host",session:"current",parse:(e)=>{if(!Object.hasOwn(e,"response"))throw Error("Missing response.");return{id:M(e),response:e.response}}}),error:b({wire:"bridge:error",from:"host",session:"current",parse:(e)=>{if(e.requestId!==void 0&&typeof e.requestId!=="string")throw Error("Invalid requestId.");return{id:M(e),code:P(e,"code"),message:P(e,"message"),...e.requestId===void 0?{}:{requestId:e.requestId}}}}),cancel:b({wire:"bridge:cancel",from:"app",session:"current",parse:(e)=>({id:M(e)})}),disconnect:b({wire:"bridge:disconnect",from:"app",session:"current",parse:_}),scriptLoad:b({wire:"script:load",from:"host",session:"current",parse:(e)=>({javascript:P(e,"javascript")})}),stateUpdate:b({wire:"state:update",from:"host",session:"current",parse:(e)=>({state:e.state})}),runtimeLog:b({wire:"runtime:log",from:"app",session:"current",parse:(e)=>{if(!me(e.payload))throw Error("Invalid log entry.");return{payload:e.payload}}}),runtimeReady:b({wire:"runtime:ready",from:"app",session:"current",parse:_}),runtimeError:b({wire:"runtime:error",from:"app",session:"current",parse:_})}};function ee(e){let n={type:e.type};if("id"in e)n.id=e.id;if(e.type==="bridge:request"){n.route=e.route;let t=e.payload;if(e.route==="data:query"&&t&&typeof t==="object"&&"operation"in t&&typeof t.operation==="string")n.operation=t.operation.slice(0,256)}if(e.type==="bridge:error")n.error={code:e.code,message:e.message,...e.requestId===void 0?{}:{requestId:e.requestId}};return n}var z=new Map;for(let e of Object.keys(w.events)){let n=w.events[e].wire;if(z.has(n))throw Error(`Duplicate bridge event: ${n}`);z.set(n,e)}function oe(e){return z.get(e)}function ie(e){if(!e||typeof e!=="object")return;let n=e;if(n.channel!==K||n.version!==w.version||typeof n.type!=="string"||typeof n.documentId!=="string"||!n.documentId||n.documentId.length>128||n.sessionId!==void 0&&!T(n.sessionId)||n.token!==void 0&&typeof n.token!=="string")return;return n}function se(e,n){try{return{channel:K,version:w.version,documentId:e.documentId,...e.sessionId===void 0?{}:{sessionId:e.sessionId},...e.token===void 0?{}:{token:e.token},type:n.wire,...n.parse(e)}}catch{return}}function ye(e){let n=ie(e);if(!n)return;let t=oe(n.type);if(!t)return;let r=w.events[t];if(r.session!=="none"&&n.sessionId===void 0)return;return se(n,r)}function ae({role:e,origin:n,source:t,opaque:r,context:o,post:a,diagnostic:p,invalidRequest:u,handlers:f}){let l=!1;function s(y,c){p?.({direction:"drop",reason:y,...typeof c==="string"?{type:c.slice(0,64)}:{}})}function g(y,c){if(l)throw Error("The bridge endpoint has closed.");let d=w.events[y],m=o(),q=ye({...c,channel:w.channel,version:w.version,type:d.wire,documentId:y==="connect"?"host":m.documentId,sessionId:m.sessionId,token:r?m.token:void 0});if(!q||r&&!T(m.token))throw Error("The bridge is not ready to send this event.");if(p?.({direction:"send",...ee(q)}),l)return;a(q)}function k(y){let c=t();if(l||!c||y.origin!==n||y.source!==c)return;let d=ie(y.data);if(!d){let S=y.data;if(S&&typeof S==="object"&&"channel"in S&&S.channel===w.channel)s("invalid_envelope","type"in S?S.type:void 0);return}let m=o(),q=e==="app"&&d.type===w.events.connect.wire;if(r&&(q?!T(d.token):!m.token||d.token!==m.token))return s("token_mismatch",d.type);let j=oe(d.type);if(!j)return s("unexpected_type",d.type);let D=w.events[j];if(D.from===e)return s("unexpected_type",d.type);if(D.session==="establish"){if(d.documentId!==m.documentId||d.sessionId===void 0)return s("session_mismatch",d.type)}else if(D.session==="current"){if(!m.sessionId||d.sessionId!==m.sessionId||d.documentId!==m.documentId)return s("session_mismatch",d.type)}let O=se(d,D);if(!O){if(s("invalid_payload",d.type),e==="host"&&j==="request"&&T(d.id))u?.(d.id);return}if(p?.({direction:"receive",...ee(O)}),l)return;let x=f[j];x(O)}return{send:g,receive:k,dispose(){l=!0}}}function de(e,n){return{async request(t,r,{signal:o}={}){if(o?.throwIfAborted(),!Object.hasOwn(e,t))throw new I("unknown_route","Unknown message route.");let a=e[t],p;try{p=a.input(r)}catch{throw new I("invalid_payload","Invalid message payload.")}let u=await n({route:t,payload:p},o);o?.throwIfAborted();try{return a.output(u,p)}catch(f){if(f instanceof I)throw f;throw new I("invalid_response","Invalid message response.")}}}}function he(e,n){function t(o){if(o.length===1&&typeof o[0]==="function"){let a=o[0]();return Array.isArray(a)?a:[a]}return o.map((a)=>typeof a==="function"?a():a)}function r(o,a){if(!e())return;try{n({method:o,args:t(a)})}catch{}}return{log:(...o)=>r("log",o),info:(...o)=>r("info",o),warn:(...o)=>r("warn",o),error:(...o)=>r("error",o)}}var be={send:"Sending message to parent",receive:"Received message from parent",drop:"Ignored message from parent"};function ge(e,{direction:n,...t}){if(t.type==="runtime:log")return;e.log(be[n],t)}function we(e){if(e instanceof Error)return{name:e.name,message:e.message,...e.stack?{stack:e.stack}:{}};return{message:String(e)}}function ne(e){if(e instanceof I)throw new A(e.message,e.code,e.requestId);throw e}function J({parentOrigin:e,window:n=window,timeoutMs:t=re,mode:r="url",loadScript:o}){if(new URL(e).origin!==e)throw Error("Expected an exact parent origin.");let a=N(),p,u,f=!1,l=new Map,s,g=new Set,k=he(()=>!f&&!!u&&!!s&&typeof s==="object"&&("logging"in s)&&s.logging===!0,(i)=>c("runtimeLog",{payload:i})),y=ae({role:"app",origin:e,source:()=>n.parent,opaque:r==="bundle",context:()=>({documentId:a,sessionId:u,token:p}),post(i){n.parent.postMessage(i,e)},diagnostic:(i)=>ge(k,i),handlers:{connect(i){if(r==="bundle")p=i.token;c("ready",{})},initialize(i){if(u&&u!==i.sessionId){if(l.size)k.warn("Preview reconnected; rejecting pending requests",{count:l.size});for(let E of l.values())E.reject(new A("The preview reconnected. Retry the request.","bridge_reset"))}let h=!u;if(u=i.sessionId,m(i.state),h)for(let E of l.values())E.start();if(f)return;if(r==="url")c("runtimeReady",{})},stateUpdate(i){m(i.state)},scriptLoad(i){if(r==="bundle")o?.(i.javascript)},result(i){l.get(i.id)?.resolve(i.response)},error(i){l.get(i.id)?.reject(new I(i.code,i.message,i.requestId))}}}),{send:c,receive:d}=y;function m(i){s=i;for(let h of g)h(i)}n.addEventListener("message",d);function q(i,h){return new Promise((E,v)=>{if(f)return v(new A("The preview has closed.","bridge_closed"));if(h?.aborted)return v(h.reason);if(l.size>=te)return v(new A("Too many pending data requests.","bridge_busy"));let R=N(),U=!1;function L(){clearTimeout(le),h?.removeEventListener("abort",Y),l.delete(R)}function Y(){if(U)c("cancel",{id:R});L(),v(h?.reason)}let le=setTimeout(()=>{if(k.warn("Message request timed out",{id:R,route:i.route,timeoutMs:t,sent:U}),U)c("cancel",{id:R});L(),v(new A(u?"The data request timed out.":"The preview shell is unavailable. Reload the preview.",u?"timeout":"bridge_unavailable"))},t),W={start(){if(U)return;try{c("request",{id:R,route:i.route,payload:i.payload}),U=!0}catch{L(),v(new A("The message payload could not be sent.","invalid_payload"))}},resolve(Q){L(),E(Q)},reject(Q){L(),v(Q)}};if(l.set(R,W),h?.addEventListener("abort",Y,{once:!0}),u)W.start();else if(r==="url"||p)c("ready",{})})}let j=de({"data:query":C(),"data:sql":V},q);function D(i,h,E){return j.request("data:query",{operation:i,input:h},{signal:E}).catch(ne)}function O(){if(u)c("disconnect",{});u=void 0;for(let i of l.values())i.reject(new A("The preview has closed.","bridge_closed"))}function x(i){if(i.persisted&&(r==="url"||p))c("ready",{})}function S(){if(f)return;O(),f=!0,y.dispose(),n.removeEventListener("message",d),n.removeEventListener("pagehide",O),n.removeEventListener("pageshow",x),g.clear()}if(n.addEventListener("pagehide",O),n.addEventListener("pageshow",x),r==="url")c("ready",{});return{logger:k,request:q,transport:D,lakehouse:{queryAll(i,{limit:h,signal:E,params:v}){return j.request("data:sql",{statement:i,limit:h,...v===void 0?{}:{params:v}},{signal:E}).catch(ne)}},dispose:S,mode:r,snapshot(){return s},subscribe(i){return g.add(i),()=>{g.delete(i)}},ready(){if(!f&&u)c("runtimeReady",{})},fail(i){if(f||!u)return;if(i!==void 0)k.error(()=>["Data app failed",we(i)]);c("runtimeError",{})}}}var F=Symbol.for("altertable.localFrameBridge"),B=Symbol.for("altertable.installedTransport");function Z(e,n=window){let t=n;if(t[B])throw Error("A data app transport is already installed.");return t[F]=e,t[B]=e,()=>{if(t[F]===e)delete t[F];if(t[B]===e)delete t[B];e.dispose()}}var je=Symbol("data-app.facetSource");var Be=C();function ue({parentOrigin:e,window:n=window}){let t,r,o=`altertable-data-app-${N()}.js`,a=J({parentOrigin:e,window:n,mode:"bundle",loadScript(s){if(t!==void 0){if(s!==t)a.fail(Error("This frame already evaluated a different app script."));else if(r)a.fail(r.cause);else a.ready();return}t=s;try{let g=n.document.createElement("script");if(g.textContent=`${s}\n//# sourceURL=${o}`,n.document.body.append(g),!r)a.ready()}catch(g){p(g)}}});function p(s){r={cause:s},a.fail(s)}function u(s){if(s.filename===o)p(s.error??s.message)}function f(s){if(s.reason instanceof Error&&s.reason.stack?.includes(o))p(s.reason)}n.addEventListener("error",u),n.addEventListener("unhandledrejection",f);let l=Z(a,n);return()=>{n.removeEventListener("error",u),n.removeEventListener("unhandledrejection",f),l()}}var ce=document.currentScript?.dataset.parentOrigin;if(!ce)throw Error("Missing trusted parent origin.");ue({parentOrigin:ce});})();\n'.replace(/<\/script/gi, (match) => `<\\${match.slice(1)}`);
|
|
4
|
+
function runtimeHtml2(parentOrigin) {
|
|
5
|
+
const attribute = parentOrigin.replaceAll("&", "&").replaceAll('"', """).replaceAll("<", "<").replaceAll(">", ">").replaceAll("'", "'");
|
|
6
|
+
return `<!doctype html>
|
|
7
|
+
<html>
|
|
8
|
+
<head>
|
|
9
|
+
<meta charset="utf-8">
|
|
10
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
11
|
+
<meta http-equiv="Content-Security-Policy" content="${PAGE_CSP2}">
|
|
12
|
+
</head>
|
|
13
|
+
<body>
|
|
14
|
+
<div id="root"></div>
|
|
15
|
+
<script data-parent-origin="${attribute}">${inlineBootstrap}</script>
|
|
16
|
+
</body>
|
|
17
|
+
</html>
|
|
18
|
+
`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// packages/data-app-worker/src/trusted-parent.ts
|
|
22
|
+
function exactOrigin(value) {
|
|
23
|
+
const url = new URL(value);
|
|
24
|
+
if (!/^https?:$/.test(url.protocol) || url.origin !== value) {
|
|
25
|
+
throw new Error("Expected an exact HTTP(S) parent origin.");
|
|
26
|
+
}
|
|
27
|
+
return url;
|
|
28
|
+
}
|
|
29
|
+
function trustedParent(config, searchParams) {
|
|
30
|
+
if (typeof config !== "string" || !config.trim()) {
|
|
31
|
+
throw new Error("Missing trusted parent origins.");
|
|
32
|
+
}
|
|
33
|
+
const allowed = config.trim().split(/\s+/).map((value) => {
|
|
34
|
+
const wildcard = value.startsWith("https://*.");
|
|
35
|
+
const url = exactOrigin(wildcard ? value.replace("*.", "") : value);
|
|
36
|
+
if (url.hostname.includes("*") || wildcard && url.port) {
|
|
37
|
+
throw new Error("Invalid parent origin pattern.");
|
|
38
|
+
}
|
|
39
|
+
return { value, url, wildcard };
|
|
40
|
+
});
|
|
41
|
+
const requested = searchParams.getAll("__altertable_parent");
|
|
42
|
+
if (!requested.length) {
|
|
43
|
+
const fallback = allowed.find((origin) => !origin.wildcard);
|
|
44
|
+
if (!fallback)
|
|
45
|
+
throw new Error("An exact default parent origin is required.");
|
|
46
|
+
return fallback.value;
|
|
47
|
+
}
|
|
48
|
+
if (requested.length !== 1)
|
|
49
|
+
return null;
|
|
50
|
+
let url;
|
|
51
|
+
try {
|
|
52
|
+
url = exactOrigin(requested[0]);
|
|
53
|
+
} catch {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
const permitted = allowed.some((origin) => {
|
|
57
|
+
if (!origin.wildcard)
|
|
58
|
+
return origin.value === requested[0];
|
|
59
|
+
if (url.protocol !== "https:" || url.port)
|
|
60
|
+
return false;
|
|
61
|
+
const suffix = `.${origin.url.hostname}`;
|
|
62
|
+
return url.hostname.endsWith(suffix) && /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/.test(url.hostname.slice(0, -suffix.length));
|
|
63
|
+
});
|
|
64
|
+
return permitted ? requested[0] : null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// packages/data-app-worker/src/index.ts
|
|
68
|
+
var TOKEN_RE = /^(?=.{1,63}$)[a-z0-9]+(?:-+[a-z0-9]+)+$/;
|
|
69
|
+
function isPreviewHost(hostname, domainName) {
|
|
70
|
+
const suffix = `.${domainName}`;
|
|
71
|
+
return hostname.endsWith(suffix) && TOKEN_RE.test(hostname.slice(0, -suffix.length));
|
|
72
|
+
}
|
|
73
|
+
var worker = {
|
|
74
|
+
runtimeHtml: runtimeHtml2,
|
|
75
|
+
fetch(request, env) {
|
|
76
|
+
const url = new URL(request.url);
|
|
77
|
+
if (!isPreviewHost(url.hostname, env.DOMAIN_NAME) || url.pathname !== "/") {
|
|
78
|
+
return new Response(null, { status: 404 });
|
|
79
|
+
}
|
|
80
|
+
if (request.method !== "GET" && request.method !== "HEAD") {
|
|
81
|
+
return new Response(null, {
|
|
82
|
+
status: 405,
|
|
83
|
+
headers: { Allow: "GET, HEAD" }
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
let parent;
|
|
87
|
+
try {
|
|
88
|
+
parent = trustedParent(env.PARENT_ORIGINS, url.searchParams);
|
|
89
|
+
} catch {
|
|
90
|
+
return new Response(null, { status: 503 });
|
|
91
|
+
}
|
|
92
|
+
if (!parent)
|
|
93
|
+
return new Response(null, { status: 403 });
|
|
94
|
+
return new Response(request.method === "HEAD" ? null : runtimeHtml2(parent), {
|
|
95
|
+
headers: {
|
|
96
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
97
|
+
"Content-Security-Policy": `${PAGE_CSP2}; frame-ancestors ${env.PARENT_ORIGINS.trim().split(/\s+/).join(" ")}`,
|
|
98
|
+
"X-Content-Type-Options": "nosniff",
|
|
99
|
+
"Referrer-Policy": "no-referrer"
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
var src_default = worker;
|
|
105
|
+
export {
|
|
106
|
+
src_default as default
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
//# debugId=4F85DA2EE5A6A0B064756E2164756E21
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../data-app-embed/dist/chunks/index-aqzf4zgk.js", "../src/trusted-parent.ts", "../src/index.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"// packages/data-app-embed/src/runtime-html.ts\nvar PAGE_CSP2 = \"default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; img-src data: blob:; connect-src 'none'; form-action 'none'; base-uri 'none'\";\nvar inlineBootstrap = '(()=>{function pe(e){return e===null||typeof e===\"string\"||typeof e===\"boolean\"||typeof e===\"number\"&&Number.isFinite(e)}function G(e){return!!e&&typeof e===\"object\"&&!Array.isArray(e)&&Object.values(e).every(pe)}var Ee=Symbol(\"data-app.dimensionSource\");var H=Symbol.for(\"@altertable/data-app/MessageRoutingError\");class I extends Error{code;requestId;[H]=!0;static[Symbol.hasInstance](e){return e instanceof Error&&e[H]===!0}constructor(e,n,t,r){super(n,r);this.code=e,this.requestId=t,this.name=\"MessageRoutingError\"}}function fe(e){return e}function C(e){return{operations:e,input(n){if(!n||typeof n!==\"object\")throw Error(\"Invalid query.\");let t=n;if(typeof t.operation!==\"string\"||!t.operation||t.operation.length>256||t.operation.includes(\"/\"))throw Error(\"Invalid operation.\");let r=e&&Object.hasOwn(e,t.operation)?e[t.operation]:void 0;if(e&&!r)throw Error(\"Unknown operation.\");return{operation:t.operation,input:r?r.input(t.input):t.input}},output(n){if(!n||typeof n!==\"object\")throw Error(\"Invalid data response.\");let t=n;if(!Number.isInteger(t.status)||t.status<100||t.status>599||!t.body||typeof t.body!==\"object\"||Array.isArray(t.body))throw Error(\"Invalid data response.\");let r=t.body;if(t.status<200||t.status>=300){let o=r.error;throw new I(typeof o?.code===\"string\"?o.code:\"request_failed\",typeof o?.message===\"string\"?o.message:\"Could not load data.\",typeof o?.requestId===\"string\"?o.requestId:void 0)}if(!(\"data\"in r)||typeof r.requestId!==\"string\"||typeof r.queriedAt!==\"string\"||!Array.isArray(r.queryIds)||!r.queryIds.every((o)=>typeof o===\"string\"))throw Error(\"Invalid data envelope.\");if(r.queries!==void 0&&(!Array.isArray(r.queries)||!r.queries.every((o)=>o&&typeof o===\"object\"&&typeof o.name===\"string\"&&typeof o.statement===\"string\"&&(o.params===void 0||G(o.params))&&(o.queryId===void 0||typeof o.queryId===\"string\"))))throw Error(\"Invalid query evidence.\");return{status:t.status,body:r}}}}var V=fe({input(e){if(!e||typeof e!==\"object\")throw Error(\"Invalid SQL query.\");let n=e;if(typeof n.statement!==\"string\"||!n.statement.trim()||typeof n.limit!==\"number\"||!Number.isSafeInteger(n.limit)||n.limit<1||n.params!==void 0&&!G(n.params))throw Error(\"Invalid SQL query.\");return{statement:n.statement,limit:n.limit,...n.params===void 0?{}:{params:n.params}}},output(e,n){if(!e||typeof e!==\"object\")throw Error(\"Invalid query result.\");let t=e;if(!Array.isArray(t.columns)||!t.columns.every((r)=>r&&typeof r.name===\"string\"&&(r.type===void 0||typeof r.type===\"string\"))||!Array.isArray(t.rows)||t.rows.length>n.limit||!t.rows.every((r)=>Array.isArray(r)&&r.length===t.columns.length)||t.queryId!==void 0&&typeof t.queryId!==\"string\")throw Error(\"Invalid query result.\");return{columns:t.columns,rows:t.rows,...t.queryId===void 0?{}:{queryId:t.queryId}}}});function N(){if(typeof crypto.randomUUID===\"function\")return crypto.randomUUID();let e=crypto.getRandomValues(new Uint8Array(16));e[6]=e[6]&15|64,e[8]=e[8]&63|128;let n=Array.from(e,(t)=>t.toString(16).padStart(2,\"0\"));return[n.slice(0,4),n.slice(4,6),n.slice(6,8),n.slice(8,10),n.slice(10)].map((t)=>t.join(\"\")).join(\"-\")}var X=Symbol.for(\"@altertable/data-app/DataAppError\");class A extends Error{code;requestId;[X]=!0;static[Symbol.hasInstance](e){return e instanceof Error&&e[X]===!0}constructor(e,n,t){super(e);this.code=n,this.requestId=t,this.name=\"DataAppError\"}}function me(e){if(!e||typeof e!==\"object\")return!1;let n=e;return(n.method===\"log\"||n.method===\"info\"||n.method===\"warn\"||n.method===\"error\")&&Array.isArray(n.args)&&n.args.length<=128}var K=\"altertable:data-app\";var te=128,re=60000;function T(e){return typeof e===\"string\"&&/^[a-zA-Z0-9_-]{1,128}$/.test(e)}function b({wire:e,from:n,session:t,parse:r}){return{wire:e,from:n,session:t,parse:r}}function M(e){if(!T(e.id))throw Error(\"Invalid request ID.\");return e.id}function P(e,n){let t=e[n];if(typeof t!==\"string\")throw Error(`Invalid ${n}.`);return t}function _(){return{}}var w={channel:K,version:1,events:{connect:b({wire:\"bridge:connect\",from:\"host\",session:\"none\",parse:_}),ready:b({wire:\"bridge:ready\",from:\"app\",session:\"none\",parse:_}),initialize:b({wire:\"bridge:initialize\",from:\"host\",session:\"establish\",parse:(e)=>({state:e.state})}),request:b({wire:\"bridge:request\",from:\"app\",session:\"current\",parse:(e)=>{let n=P(e,\"route\");if(!n||n.length>256)throw Error(\"Invalid message route.\");return{id:M(e),route:n,payload:e.payload}}}),result:b({wire:\"bridge:result\",from:\"host\",session:\"current\",parse:(e)=>{if(!Object.hasOwn(e,\"response\"))throw Error(\"Missing response.\");return{id:M(e),response:e.response}}}),error:b({wire:\"bridge:error\",from:\"host\",session:\"current\",parse:(e)=>{if(e.requestId!==void 0&&typeof e.requestId!==\"string\")throw Error(\"Invalid requestId.\");return{id:M(e),code:P(e,\"code\"),message:P(e,\"message\"),...e.requestId===void 0?{}:{requestId:e.requestId}}}}),cancel:b({wire:\"bridge:cancel\",from:\"app\",session:\"current\",parse:(e)=>({id:M(e)})}),disconnect:b({wire:\"bridge:disconnect\",from:\"app\",session:\"current\",parse:_}),scriptLoad:b({wire:\"script:load\",from:\"host\",session:\"current\",parse:(e)=>({javascript:P(e,\"javascript\")})}),stateUpdate:b({wire:\"state:update\",from:\"host\",session:\"current\",parse:(e)=>({state:e.state})}),runtimeLog:b({wire:\"runtime:log\",from:\"app\",session:\"current\",parse:(e)=>{if(!me(e.payload))throw Error(\"Invalid log entry.\");return{payload:e.payload}}}),runtimeReady:b({wire:\"runtime:ready\",from:\"app\",session:\"current\",parse:_}),runtimeError:b({wire:\"runtime:error\",from:\"app\",session:\"current\",parse:_})}};function ee(e){let n={type:e.type};if(\"id\"in e)n.id=e.id;if(e.type===\"bridge:request\"){n.route=e.route;let t=e.payload;if(e.route===\"data:query\"&&t&&typeof t===\"object\"&&\"operation\"in t&&typeof t.operation===\"string\")n.operation=t.operation.slice(0,256)}if(e.type===\"bridge:error\")n.error={code:e.code,message:e.message,...e.requestId===void 0?{}:{requestId:e.requestId}};return n}var z=new Map;for(let e of Object.keys(w.events)){let n=w.events[e].wire;if(z.has(n))throw Error(`Duplicate bridge event: ${n}`);z.set(n,e)}function oe(e){return z.get(e)}function ie(e){if(!e||typeof e!==\"object\")return;let n=e;if(n.channel!==K||n.version!==w.version||typeof n.type!==\"string\"||typeof n.documentId!==\"string\"||!n.documentId||n.documentId.length>128||n.sessionId!==void 0&&!T(n.sessionId)||n.token!==void 0&&typeof n.token!==\"string\")return;return n}function se(e,n){try{return{channel:K,version:w.version,documentId:e.documentId,...e.sessionId===void 0?{}:{sessionId:e.sessionId},...e.token===void 0?{}:{token:e.token},type:n.wire,...n.parse(e)}}catch{return}}function ye(e){let n=ie(e);if(!n)return;let t=oe(n.type);if(!t)return;let r=w.events[t];if(r.session!==\"none\"&&n.sessionId===void 0)return;return se(n,r)}function ae({role:e,origin:n,source:t,opaque:r,context:o,post:a,diagnostic:p,invalidRequest:u,handlers:f}){let l=!1;function s(y,c){p?.({direction:\"drop\",reason:y,...typeof c===\"string\"?{type:c.slice(0,64)}:{}})}function g(y,c){if(l)throw Error(\"The bridge endpoint has closed.\");let d=w.events[y],m=o(),q=ye({...c,channel:w.channel,version:w.version,type:d.wire,documentId:y===\"connect\"?\"host\":m.documentId,sessionId:m.sessionId,token:r?m.token:void 0});if(!q||r&&!T(m.token))throw Error(\"The bridge is not ready to send this event.\");if(p?.({direction:\"send\",...ee(q)}),l)return;a(q)}function k(y){let c=t();if(l||!c||y.origin!==n||y.source!==c)return;let d=ie(y.data);if(!d){let S=y.data;if(S&&typeof S===\"object\"&&\"channel\"in S&&S.channel===w.channel)s(\"invalid_envelope\",\"type\"in S?S.type:void 0);return}let m=o(),q=e===\"app\"&&d.type===w.events.connect.wire;if(r&&(q?!T(d.token):!m.token||d.token!==m.token))return s(\"token_mismatch\",d.type);let j=oe(d.type);if(!j)return s(\"unexpected_type\",d.type);let D=w.events[j];if(D.from===e)return s(\"unexpected_type\",d.type);if(D.session===\"establish\"){if(d.documentId!==m.documentId||d.sessionId===void 0)return s(\"session_mismatch\",d.type)}else if(D.session===\"current\"){if(!m.sessionId||d.sessionId!==m.sessionId||d.documentId!==m.documentId)return s(\"session_mismatch\",d.type)}let O=se(d,D);if(!O){if(s(\"invalid_payload\",d.type),e===\"host\"&&j===\"request\"&&T(d.id))u?.(d.id);return}if(p?.({direction:\"receive\",...ee(O)}),l)return;let x=f[j];x(O)}return{send:g,receive:k,dispose(){l=!0}}}function de(e,n){return{async request(t,r,{signal:o}={}){if(o?.throwIfAborted(),!Object.hasOwn(e,t))throw new I(\"unknown_route\",\"Unknown message route.\");let a=e[t],p;try{p=a.input(r)}catch{throw new I(\"invalid_payload\",\"Invalid message payload.\")}let u=await n({route:t,payload:p},o);o?.throwIfAborted();try{return a.output(u,p)}catch(f){if(f instanceof I)throw f;throw new I(\"invalid_response\",\"Invalid message response.\")}}}}function he(e,n){function t(o){if(o.length===1&&typeof o[0]===\"function\"){let a=o[0]();return Array.isArray(a)?a:[a]}return o.map((a)=>typeof a===\"function\"?a():a)}function r(o,a){if(!e())return;try{n({method:o,args:t(a)})}catch{}}return{log:(...o)=>r(\"log\",o),info:(...o)=>r(\"info\",o),warn:(...o)=>r(\"warn\",o),error:(...o)=>r(\"error\",o)}}var be={send:\"Sending message to parent\",receive:\"Received message from parent\",drop:\"Ignored message from parent\"};function ge(e,{direction:n,...t}){if(t.type===\"runtime:log\")return;e.log(be[n],t)}function we(e){if(e instanceof Error)return{name:e.name,message:e.message,...e.stack?{stack:e.stack}:{}};return{message:String(e)}}function ne(e){if(e instanceof I)throw new A(e.message,e.code,e.requestId);throw e}function J({parentOrigin:e,window:n=window,timeoutMs:t=re,mode:r=\"url\",loadScript:o}){if(new URL(e).origin!==e)throw Error(\"Expected an exact parent origin.\");let a=N(),p,u,f=!1,l=new Map,s,g=new Set,k=he(()=>!f&&!!u&&!!s&&typeof s===\"object\"&&(\"logging\"in s)&&s.logging===!0,(i)=>c(\"runtimeLog\",{payload:i})),y=ae({role:\"app\",origin:e,source:()=>n.parent,opaque:r===\"bundle\",context:()=>({documentId:a,sessionId:u,token:p}),post(i){n.parent.postMessage(i,e)},diagnostic:(i)=>ge(k,i),handlers:{connect(i){if(r===\"bundle\")p=i.token;c(\"ready\",{})},initialize(i){if(u&&u!==i.sessionId){if(l.size)k.warn(\"Preview reconnected; rejecting pending requests\",{count:l.size});for(let E of l.values())E.reject(new A(\"The preview reconnected. Retry the request.\",\"bridge_reset\"))}let h=!u;if(u=i.sessionId,m(i.state),h)for(let E of l.values())E.start();if(f)return;if(r===\"url\")c(\"runtimeReady\",{})},stateUpdate(i){m(i.state)},scriptLoad(i){if(r===\"bundle\")o?.(i.javascript)},result(i){l.get(i.id)?.resolve(i.response)},error(i){l.get(i.id)?.reject(new I(i.code,i.message,i.requestId))}}}),{send:c,receive:d}=y;function m(i){s=i;for(let h of g)h(i)}n.addEventListener(\"message\",d);function q(i,h){return new Promise((E,v)=>{if(f)return v(new A(\"The preview has closed.\",\"bridge_closed\"));if(h?.aborted)return v(h.reason);if(l.size>=te)return v(new A(\"Too many pending data requests.\",\"bridge_busy\"));let R=N(),U=!1;function L(){clearTimeout(le),h?.removeEventListener(\"abort\",Y),l.delete(R)}function Y(){if(U)c(\"cancel\",{id:R});L(),v(h?.reason)}let le=setTimeout(()=>{if(k.warn(\"Message request timed out\",{id:R,route:i.route,timeoutMs:t,sent:U}),U)c(\"cancel\",{id:R});L(),v(new A(u?\"The data request timed out.\":\"The preview shell is unavailable. Reload the preview.\",u?\"timeout\":\"bridge_unavailable\"))},t),W={start(){if(U)return;try{c(\"request\",{id:R,route:i.route,payload:i.payload}),U=!0}catch{L(),v(new A(\"The message payload could not be sent.\",\"invalid_payload\"))}},resolve(Q){L(),E(Q)},reject(Q){L(),v(Q)}};if(l.set(R,W),h?.addEventListener(\"abort\",Y,{once:!0}),u)W.start();else if(r===\"url\"||p)c(\"ready\",{})})}let j=de({\"data:query\":C(),\"data:sql\":V},q);function D(i,h,E){return j.request(\"data:query\",{operation:i,input:h},{signal:E}).catch(ne)}function O(){if(u)c(\"disconnect\",{});u=void 0;for(let i of l.values())i.reject(new A(\"The preview has closed.\",\"bridge_closed\"))}function x(i){if(i.persisted&&(r===\"url\"||p))c(\"ready\",{})}function S(){if(f)return;O(),f=!0,y.dispose(),n.removeEventListener(\"message\",d),n.removeEventListener(\"pagehide\",O),n.removeEventListener(\"pageshow\",x),g.clear()}if(n.addEventListener(\"pagehide\",O),n.addEventListener(\"pageshow\",x),r===\"url\")c(\"ready\",{});return{logger:k,request:q,transport:D,lakehouse:{queryAll(i,{limit:h,signal:E,params:v}){return j.request(\"data:sql\",{statement:i,limit:h,...v===void 0?{}:{params:v}},{signal:E}).catch(ne)}},dispose:S,mode:r,snapshot(){return s},subscribe(i){return g.add(i),()=>{g.delete(i)}},ready(){if(!f&&u)c(\"runtimeReady\",{})},fail(i){if(f||!u)return;if(i!==void 0)k.error(()=>[\"Data app failed\",we(i)]);c(\"runtimeError\",{})}}}var F=Symbol.for(\"altertable.localFrameBridge\"),B=Symbol.for(\"altertable.installedTransport\");function Z(e,n=window){let t=n;if(t[B])throw Error(\"A data app transport is already installed.\");return t[F]=e,t[B]=e,()=>{if(t[F]===e)delete t[F];if(t[B]===e)delete t[B];e.dispose()}}var je=Symbol(\"data-app.facetSource\");var Be=C();function ue({parentOrigin:e,window:n=window}){let t,r,o=`altertable-data-app-${N()}.js`,a=J({parentOrigin:e,window:n,mode:\"bundle\",loadScript(s){if(t!==void 0){if(s!==t)a.fail(Error(\"This frame already evaluated a different app script.\"));else if(r)a.fail(r.cause);else a.ready();return}t=s;try{let g=n.document.createElement(\"script\");if(g.textContent=`${s}\\n//# sourceURL=${o}`,n.document.body.append(g),!r)a.ready()}catch(g){p(g)}}});function p(s){r={cause:s},a.fail(s)}function u(s){if(s.filename===o)p(s.error??s.message)}function f(s){if(s.reason instanceof Error&&s.reason.stack?.includes(o))p(s.reason)}n.addEventListener(\"error\",u),n.addEventListener(\"unhandledrejection\",f);let l=Z(a,n);return()=>{n.removeEventListener(\"error\",u),n.removeEventListener(\"unhandledrejection\",f),l()}}var ce=document.currentScript?.dataset.parentOrigin;if(!ce)throw Error(\"Missing trusted parent origin.\");ue({parentOrigin:ce});})();\\n'.replace(/<\\/script/gi, (match) => `<\\\\${match.slice(1)}`);\nfunction runtimeHtml2(parentOrigin) {\n const attribute = parentOrigin.replaceAll(\"&\", \"&\").replaceAll('\"', \""\").replaceAll(\"<\", \"<\").replaceAll(\">\", \">\").replaceAll(\"'\", \"'\");\n return `<!doctype html>\n<html>\n <head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n <meta http-equiv=\"Content-Security-Policy\" content=\"${PAGE_CSP2}\">\n </head>\n <body>\n <div id=\"root\"></div>\n <script data-parent-origin=\"${attribute}\">${inlineBootstrap}</script>\n </body>\n</html>\n`;\n}\n\nexport { PAGE_CSP2, runtimeHtml2 };\n\n//# debugId=96DD2A8647500A6964756E2164756E21\n",
|
|
6
|
+
"function exactOrigin(value: string) {\n const url = new URL(value);\n if (!/^https?:$/.test(url.protocol) || url.origin !== value) {\n throw new Error('Expected an exact HTTP(S) parent origin.');\n }\n\n return url;\n}\n\n// Selection can only choose an origin approved by deployment configuration.\nexport function trustedParent(config: string, searchParams: URLSearchParams) {\n if (typeof config !== 'string' || !config.trim()) {\n throw new Error('Missing trusted parent origins.');\n }\n const allowed = config\n .trim()\n .split(/\\s+/)\n .map(value => {\n const wildcard = value.startsWith('https://*.');\n const url = exactOrigin(wildcard ? value.replace('*.', '') : value);\n if (url.hostname.includes('*') || (wildcard && url.port)) {\n throw new Error('Invalid parent origin pattern.');\n }\n\n return { value, url, wildcard };\n });\n const requested = searchParams.getAll('__altertable_parent');\n if (!requested.length) {\n const fallback = allowed.find(origin => !origin.wildcard);\n if (!fallback)\n throw new Error('An exact default parent origin is required.');\n\n return fallback.value;\n }\n if (requested.length !== 1) return null;\n let url: URL;\n try {\n url = exactOrigin(requested[0]!);\n } catch {\n return null;\n }\n const permitted = allowed.some(origin => {\n if (!origin.wildcard) return origin.value === requested[0];\n if (url.protocol !== 'https:' || url.port) return false;\n const suffix = `.${origin.url.hostname}`;\n\n return (\n url.hostname.endsWith(suffix) &&\n /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/.test(\n url.hostname.slice(0, -suffix.length)\n )\n );\n });\n\n return permitted ? requested[0]! : null;\n}\n",
|
|
7
|
+
"import { PAGE_CSP, runtimeHtml } from '@altertable/data-app-embed/runtime';\nimport { trustedParent } from './trusted-parent.ts';\n\ninterface WorkerBindings {\n DOMAIN_NAME: string;\n PARENT_ORIGINS: string;\n}\n\n// Hosts own the label format (e.g. `<prefix>-<base36 id>` or legacy `<prefix>-app-<n>`); accept any hyphenated DNS label.\nconst TOKEN_RE = /^(?=.{1,63}$)[a-z0-9]+(?:-+[a-z0-9]+)+$/;\nfunction isPreviewHost(hostname: string, domainName: string) {\n const suffix = `.${domainName}`;\n\n return (\n hostname.endsWith(suffix) &&\n TOKEN_RE.test(hostname.slice(0, -suffix.length))\n );\n}\n\nconst worker: {\n runtimeHtml(parentOrigin: string): string;\n fetch(request: Request, env: WorkerBindings): Response;\n} = {\n runtimeHtml,\n fetch(request: Request, env: WorkerBindings) {\n const url = new URL(request.url);\n if (!isPreviewHost(url.hostname, env.DOMAIN_NAME) || url.pathname !== '/') {\n return new Response(null, { status: 404 });\n }\n if (request.method !== 'GET' && request.method !== 'HEAD') {\n return new Response(null, {\n status: 405,\n headers: { Allow: 'GET, HEAD' },\n });\n }\n let parent: string | null;\n try {\n parent = trustedParent(env.PARENT_ORIGINS, url.searchParams);\n } catch {\n return new Response(null, { status: 503 });\n }\n if (!parent) return new Response(null, { status: 403 });\n\n return new Response(\n request.method === 'HEAD' ? null : runtimeHtml(parent),\n {\n headers: {\n 'Content-Type': 'text/html; charset=utf-8',\n 'Content-Security-Policy': `${PAGE_CSP}; frame-ancestors ${env.PARENT_ORIGINS.trim().split(/\\s+/).join(' ')}`,\n 'X-Content-Type-Options': 'nosniff',\n 'Referrer-Policy': 'no-referrer',\n },\n }\n );\n },\n};\n\nexport default worker;\n"
|
|
8
|
+
],
|
|
9
|
+
"mappings": "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",
|
|
10
|
+
"debugId": "4F85DA2EE5A6A0B064756E2164756E21",
|
|
11
|
+
"names": []
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function trustedParent(config: string, searchParams: URLSearchParams): string | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@altertable/data-app-worker",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.72.0",
|
|
4
|
+
"description": "Self-contained sandbox Worker for serving Altertable data apps.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"altertable",
|
|
7
|
+
"analytics",
|
|
8
|
+
"data-app",
|
|
9
|
+
"react",
|
|
10
|
+
"typescript"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/altertable-ai/data-app",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/altertable-ai/data-app/issues"
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"author": {
|
|
18
|
+
"name": "Altertable",
|
|
19
|
+
"url": "https://altertable.ai"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/altertable-ai/data-app.git",
|
|
24
|
+
"directory": "packages/data-app-worker"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"README.md",
|
|
29
|
+
"LICENSE"
|
|
30
|
+
],
|
|
31
|
+
"type": "module",
|
|
32
|
+
"sideEffects": false,
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"types": "./dist/types/index.d.ts",
|
|
36
|
+
"import": "./dist/index.js",
|
|
37
|
+
"default": "./dist/index.js"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public",
|
|
42
|
+
"registry": "https://registry.npmjs.org"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "bun ../../scripts/build.ts data-app-worker"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@altertable/data-app-embed": "0.72.0"
|
|
49
|
+
}
|
|
50
|
+
}
|