@asymmetric-effort/specifyjs 0.3.8 → 1.0.2
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/dist/esm/chunks/{chunk-H7ZJ2I3D.js → chunk-6IZ45RD4.js} +1 -1
- package/dist/esm/chunks/{chunk-4TF5WXQG.js → chunk-LCSK4XUC.js} +7 -1
- package/dist/esm/chunks/{chunk-45EBJMQH.js → chunk-MWYZOVHI.js} +1 -1
- package/dist/esm/chunks/{metrics-ELQJ4BZ7.js → metrics-J42I3W3C.js} +2 -2
- package/dist/esm/client/index.js +1 -1
- package/dist/esm/components-barrel.js +126 -3
- package/dist/esm/index.js +2 -2
- package/dist/esm/server/index.js +2 -1
- package/dist/esm/telemetry/index.js +3 -3
- package/dist/specifyjs-client.cjs.js +1 -1
- package/dist/specifyjs-client.esm.js +1 -1
- package/dist/specifyjs-components.cjs.js +4 -4
- package/dist/specifyjs-components.esm.js +126 -3
- package/dist/specifyjs-server.cjs.js +1 -1
- package/dist/specifyjs-server.esm.js +2 -1
- package/dist/specifyjs-telemetry.cjs.js +1 -1
- package/dist/specifyjs-telemetry.esm.js +3 -3
- package/dist/specifyjs.cjs.js +1 -1
- package/dist/specifyjs.esm.js +2 -2
- package/package.json +2 -2
|
@@ -27,9 +27,15 @@ function assertSecureUrl(url) {
|
|
|
27
27
|
if (parsed.protocol === "https:") {
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
const hostname = parsed.hostname.toLowerCase();
|
|
31
|
+
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]" || hostname === "0.0.0.0" || hostname.startsWith("127.")) {
|
|
31
32
|
return;
|
|
32
33
|
}
|
|
34
|
+
if (hostname.endsWith(".localhost")) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
`[SpecifyJS] SSRF protection: "${url}" uses a .localhost subdomain which resolves to the loopback interface. Use exact "localhost" instead.`
|
|
37
|
+
);
|
|
38
|
+
}
|
|
33
39
|
throw new Error(
|
|
34
40
|
`[SpecifyJS] Insecure URL rejected: "${url}". SpecifyJS enforces HTTPS-only for all network requests. Use https:// or a relative URL. Localhost URLs are allowed for development.`
|
|
35
41
|
);
|
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
exportToEndpoint,
|
|
5
5
|
formatOtlpMetrics,
|
|
6
6
|
formatOtlpTraces
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-6IZ45RD4.js";
|
|
8
|
+
import "./chunk-LCSK4XUC.js";
|
|
9
9
|
import "./chunk-FDNBPWUH.js";
|
|
10
10
|
export {
|
|
11
11
|
createMeterProvider,
|
package/dist/esm/client/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/* (c) 2025-2026 Asymmetric Effort, LLC. MIT LICENSE */
|
|
2
2
|
import {
|
|
3
3
|
createContext
|
|
4
|
-
} from "./chunks/chunk-
|
|
4
|
+
} from "./chunks/chunk-MWYZOVHI.js";
|
|
5
5
|
import "./chunks/chunk-7OC7LXZ7.js";
|
|
6
6
|
import "./chunks/chunk-SRUWIDIG.js";
|
|
7
7
|
import {
|
|
8
8
|
createElement
|
|
9
9
|
} from "./chunks/chunk-NKW7RJR3.js";
|
|
10
10
|
import "./chunks/chunk-UJTLBTMV.js";
|
|
11
|
-
import "./chunks/chunk-
|
|
11
|
+
import "./chunks/chunk-LCSK4XUC.js";
|
|
12
12
|
import {
|
|
13
13
|
useCallback,
|
|
14
14
|
useContext,
|
|
@@ -3755,6 +3755,128 @@ var BUTTON_META = {
|
|
|
3755
3755
|
undo: { label: "Undo", icon: "\u21A9", command: "undo" },
|
|
3756
3756
|
redo: { label: "Redo", icon: "\u21AA", command: "redo" }
|
|
3757
3757
|
};
|
|
3758
|
+
var ALLOWED_TAGS = /* @__PURE__ */ new Set([
|
|
3759
|
+
"p",
|
|
3760
|
+
"br",
|
|
3761
|
+
"b",
|
|
3762
|
+
"strong",
|
|
3763
|
+
"i",
|
|
3764
|
+
"em",
|
|
3765
|
+
"u",
|
|
3766
|
+
"s",
|
|
3767
|
+
"strike",
|
|
3768
|
+
"del",
|
|
3769
|
+
"sub",
|
|
3770
|
+
"sup",
|
|
3771
|
+
"h1",
|
|
3772
|
+
"h2",
|
|
3773
|
+
"h3",
|
|
3774
|
+
"h4",
|
|
3775
|
+
"h5",
|
|
3776
|
+
"h6",
|
|
3777
|
+
"ul",
|
|
3778
|
+
"ol",
|
|
3779
|
+
"li",
|
|
3780
|
+
"blockquote",
|
|
3781
|
+
"pre",
|
|
3782
|
+
"code",
|
|
3783
|
+
"a",
|
|
3784
|
+
"img",
|
|
3785
|
+
"span",
|
|
3786
|
+
"div",
|
|
3787
|
+
"table",
|
|
3788
|
+
"thead",
|
|
3789
|
+
"tbody",
|
|
3790
|
+
"tr",
|
|
3791
|
+
"th",
|
|
3792
|
+
"td",
|
|
3793
|
+
"hr",
|
|
3794
|
+
"abbr",
|
|
3795
|
+
"mark",
|
|
3796
|
+
"small",
|
|
3797
|
+
"figure",
|
|
3798
|
+
"figcaption"
|
|
3799
|
+
]);
|
|
3800
|
+
var ALLOWED_ATTRS = /* @__PURE__ */ new Set([
|
|
3801
|
+
"href",
|
|
3802
|
+
"src",
|
|
3803
|
+
"alt",
|
|
3804
|
+
"title",
|
|
3805
|
+
"width",
|
|
3806
|
+
"height",
|
|
3807
|
+
"class",
|
|
3808
|
+
"id",
|
|
3809
|
+
"style",
|
|
3810
|
+
"colspan",
|
|
3811
|
+
"rowspan",
|
|
3812
|
+
"scope",
|
|
3813
|
+
"target",
|
|
3814
|
+
"rel"
|
|
3815
|
+
]);
|
|
3816
|
+
var DANGEROUS_URL_PATTERN = /^\s*(javascript|vbscript|data\s*:(?!image\/))/i;
|
|
3817
|
+
function sanitizeRichText(html) {
|
|
3818
|
+
if (typeof document === "undefined") return "";
|
|
3819
|
+
const container = document.createElement("div");
|
|
3820
|
+
container.innerHTML = html;
|
|
3821
|
+
const stack = [];
|
|
3822
|
+
for (let i = container.childNodes.length - 1; i >= 0; i--) {
|
|
3823
|
+
stack.push(container.childNodes[i]);
|
|
3824
|
+
}
|
|
3825
|
+
while (stack.length > 0) {
|
|
3826
|
+
const node = stack.pop();
|
|
3827
|
+
if (node.nodeType === 3) continue;
|
|
3828
|
+
if (node.nodeType !== 1) {
|
|
3829
|
+
node.parentNode?.removeChild(node);
|
|
3830
|
+
continue;
|
|
3831
|
+
}
|
|
3832
|
+
const el = node;
|
|
3833
|
+
const tag = el.tagName.toLowerCase();
|
|
3834
|
+
if (!ALLOWED_TAGS.has(tag)) {
|
|
3835
|
+
const parent = el.parentNode;
|
|
3836
|
+
if (parent) {
|
|
3837
|
+
while (el.firstChild) {
|
|
3838
|
+
parent.insertBefore(el.firstChild, el);
|
|
3839
|
+
}
|
|
3840
|
+
let sibling = parent.firstChild;
|
|
3841
|
+
const promoted = [];
|
|
3842
|
+
while (sibling) {
|
|
3843
|
+
if (sibling !== el) promoted.push(sibling);
|
|
3844
|
+
sibling = sibling.nextSibling;
|
|
3845
|
+
}
|
|
3846
|
+
parent.removeChild(el);
|
|
3847
|
+
for (let i = promoted.length - 1; i >= 0; i--) {
|
|
3848
|
+
stack.push(promoted[i]);
|
|
3849
|
+
}
|
|
3850
|
+
}
|
|
3851
|
+
continue;
|
|
3852
|
+
}
|
|
3853
|
+
const attrs = el.attributes;
|
|
3854
|
+
const toRemove = [];
|
|
3855
|
+
for (let i = 0; i < attrs.length; i++) {
|
|
3856
|
+
const name = attrs[i].name.toLowerCase();
|
|
3857
|
+
if (name.startsWith("on")) {
|
|
3858
|
+
toRemove.push(attrs[i].name);
|
|
3859
|
+
} else if (!ALLOWED_ATTRS.has(name)) {
|
|
3860
|
+
toRemove.push(attrs[i].name);
|
|
3861
|
+
}
|
|
3862
|
+
}
|
|
3863
|
+
for (const name of toRemove) {
|
|
3864
|
+
el.removeAttribute(name);
|
|
3865
|
+
}
|
|
3866
|
+
const href = el.getAttribute("href");
|
|
3867
|
+
if (href && DANGEROUS_URL_PATTERN.test(href)) {
|
|
3868
|
+
el.removeAttribute("href");
|
|
3869
|
+
}
|
|
3870
|
+
const src = el.getAttribute("src");
|
|
3871
|
+
if (src && DANGEROUS_URL_PATTERN.test(src)) {
|
|
3872
|
+
el.removeAttribute("src");
|
|
3873
|
+
}
|
|
3874
|
+
for (let i = el.childNodes.length - 1; i >= 0; i--) {
|
|
3875
|
+
stack.push(el.childNodes[i]);
|
|
3876
|
+
}
|
|
3877
|
+
}
|
|
3878
|
+
return container.innerHTML;
|
|
3879
|
+
}
|
|
3758
3880
|
function TextEditor(props) {
|
|
3759
3881
|
const [focused, setFocused] = useState(false);
|
|
3760
3882
|
const editorRef = useRef(null);
|
|
@@ -3765,7 +3887,7 @@ function TextEditor(props) {
|
|
|
3765
3887
|
const es = props.editorStyle ?? {};
|
|
3766
3888
|
useEffect(() => {
|
|
3767
3889
|
if (editorRef.current && props.value !== void 0) {
|
|
3768
|
-
editorRef.current.innerHTML = props.value;
|
|
3890
|
+
editorRef.current.innerHTML = sanitizeRichText(props.value);
|
|
3769
3891
|
}
|
|
3770
3892
|
}, []);
|
|
3771
3893
|
const execCommand = useCallback(
|
|
@@ -3774,6 +3896,7 @@ function TextEditor(props) {
|
|
|
3774
3896
|
if (cmd === "createLink") {
|
|
3775
3897
|
const url = prompt("Enter URL:");
|
|
3776
3898
|
if (!url) return;
|
|
3899
|
+
if (/^(javascript|vbscript|data:text\/html)/i.test(url.trim())) return;
|
|
3777
3900
|
document.execCommand(cmd, false, url);
|
|
3778
3901
|
} else if (value && cmd === "formatBlock") {
|
|
3779
3902
|
document.execCommand(cmd, false, `<${value}>`);
|
package/dist/esm/index.js
CHANGED
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
useNavigate,
|
|
25
25
|
useParams,
|
|
26
26
|
useRouter
|
|
27
|
-
} from "./chunks/chunk-
|
|
27
|
+
} from "./chunks/chunk-MWYZOVHI.js";
|
|
28
28
|
import {
|
|
29
29
|
getComponentTypeTable,
|
|
30
30
|
resolveComponentId,
|
|
@@ -43,7 +43,7 @@ import "./chunks/chunk-UJTLBTMV.js";
|
|
|
43
43
|
import {
|
|
44
44
|
assertSecureUrl,
|
|
45
45
|
secureFetch
|
|
46
|
-
} from "./chunks/chunk-
|
|
46
|
+
} from "./chunks/chunk-LCSK4XUC.js";
|
|
47
47
|
import {
|
|
48
48
|
useCallback,
|
|
49
49
|
useContext,
|
package/dist/esm/server/index.js
CHANGED
|
@@ -163,7 +163,7 @@ function renderHostElement(tag, props, includeDataAttrs) {
|
|
|
163
163
|
const attrName = PROP_TO_ATTR[key] || key.toLowerCase();
|
|
164
164
|
if (!/^[a-zA-Z_][\w\-:.]*$/.test(attrName)) continue;
|
|
165
165
|
if (key === "style") {
|
|
166
|
-
html += ` style="${renderStyle(value)}"`;
|
|
166
|
+
html += ` style="${escapeHtml(renderStyle(value))}"`;
|
|
167
167
|
} else if (key === "value" || key === "checked" || key === "selected") {
|
|
168
168
|
if (value === true) {
|
|
169
169
|
html += ` ${attrName}`;
|
|
@@ -198,6 +198,7 @@ function renderStyle(style) {
|
|
|
198
198
|
const value = style[prop];
|
|
199
199
|
if (value == null) continue;
|
|
200
200
|
const cssProp = prop.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
|
|
201
|
+
if (!/^-{0,2}[a-zA-Z][a-zA-Z0-9-]*$/.test(cssProp)) continue;
|
|
201
202
|
let cssValue = typeof value === "number" && value !== 0 && !isUnitlessProp(prop) ? `${value}px` : String(value);
|
|
202
203
|
const normalizedCss = cssValue.replace(/\\([0-9a-fA-F]{1,6})\s?/g, (_m, hex) => String.fromCodePoint(parseInt(hex, 16))).replace(/\\/g, "").replace(/\/\*[\s\S]*?\*\//g, "");
|
|
203
204
|
if (/expression\s*\(|javascript\s*:|behavior\s*:|moz-binding|-o-link/i.test(normalizedCss)) {
|
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
exportToEndpoint,
|
|
5
5
|
formatOtlpMetrics,
|
|
6
6
|
formatOtlpTraces
|
|
7
|
-
} from "../chunks/chunk-
|
|
8
|
-
import "../chunks/chunk-
|
|
7
|
+
} from "../chunks/chunk-6IZ45RD4.js";
|
|
8
|
+
import "../chunks/chunk-LCSK4XUC.js";
|
|
9
9
|
import {
|
|
10
10
|
useEffect,
|
|
11
11
|
useRef
|
|
@@ -151,7 +151,7 @@ function createTracer(config) {
|
|
|
151
151
|
if (buffer.length === 0) return;
|
|
152
152
|
const toExport = buffer.splice(0, buffer.length);
|
|
153
153
|
if (config.endpoint) {
|
|
154
|
-
const { formatOtlpTraces: formatOtlpTraces2, exportToEndpoint: exportToEndpoint2 } = await import("../chunks/metrics-
|
|
154
|
+
const { formatOtlpTraces: formatOtlpTraces2, exportToEndpoint: exportToEndpoint2 } = await import("../chunks/metrics-J42I3W3C.js");
|
|
155
155
|
const body = formatOtlpTraces2(toExport, config.serviceName, config.serviceVersion);
|
|
156
156
|
await exportToEndpoint2(config.endpoint, config.headers ?? {}, body);
|
|
157
157
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* (c) 2025-2026 Asymmetric Effort, LLC. MIT LICENSE */
|
|
2
|
-
"use strict";var O=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.prototype.hasOwnProperty;var ne=(e,t)=>{for(var n in t)O(e,n,{get:t[n],enumerable:!0})},re=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ee(t))!te.call(e,r)&&r!==n&&O(e,r,{get:()=>t[r],enumerable:!(o=Y(t,r))||o.enumerable});return e};var oe=e=>re(O({},"__esModule",{value:!0}),e);var fe={};ne(fe,{RestError:()=>v,createGraphQLClient:()=>B,createGrpcWebClient:()=>j,createRestClient:()=>F,defineMessage:()=>N,gql:()=>_,useMutation:()=>K,useProto:()=>J,useQuery:()=>X,useRest:()=>W});module.exports=oe(fe);var H=null;function G(){if(H===null)throw new Error("Invalid hook call. Hooks can only be called inside the body of a function component.");return H}function w(e){return G().useState(e)}function q(e,t){return G().useEffect(e,t)}function k(e,t){return G().useCallback(e,t)}function x(e){return G().useRef(e)}function L(e){if(e.startsWith("//"))throw new Error(`[SpecifyJS] Protocol-relative URL rejected: "${e}". Use an explicit https:// prefix.`);if(e.startsWith("/")||e.startsWith("./")||e.startsWith("../"))return;if(e.startsWith("data:")){if(e.length>1024*1024)throw new Error("[SpecifyJS] secureFetch: data: URI exceeds 1MB limit");return}let t;try{t=new URL(e,typeof window<"u"?window.location.href:void 0)}catch{throw new Error(`[SpecifyJS] secureFetch: unable to validate URL "${e}". Provide a valid absolute HTTPS URL or a relative path.`)}if(t.protocol!=="https:"&&!(t.hostname==="localhost"||t.hostname==="127.0.0.1"||t.hostname==="[::1]"||t.hostname==="0.0.0.0"||t.hostname.startsWith("127.")))throw new Error(`[SpecifyJS] Insecure URL rejected: "${e}". SpecifyJS enforces HTTPS-only for all network requests. Use https:// or a relative URL. Localhost URLs are allowed for development.`)}var v=class extends Error{constructor(t,n,o,r,u){super(t),this.name="RestError",this.status=n,this.statusText=o,this.data=r,this.config=u}};function se(e){let t={};return e.forEach((n,o)=>{t[o]=n}),t}function ie(e,t){let n=e.endsWith("/")?e.slice(0,-1):e,o=t.startsWith("/")?t:"/"+t;return n+o}function F(e){let{baseURL:t,headers:n={},timeout:o,interceptors:r={}}=e,u=r.request??[],c=r.response??[],f=r.error??[];async function h(l,a,s,p){let i={url:ie(t,a),method:l,headers:{...n,...p?.headers??{}},body:s,signal:p?.signal,timeout:p?.timeout??o};s!=null&&!i.headers["Content-Type"]&&(i.headers["Content-Type"]="application/json");for(let R of u)i=await R(i);let g,d;if(i.timeout&&i.timeout>0&&(d=new AbortController,g=setTimeout(()=>{d.abort()},i.timeout),i.signal)){let R=i.signal;R.aborted?d.abort():R.addEventListener("abort",()=>{d.abort()})}let T=d?d.signal:i.signal,y={method:i.method,headers:i.headers,signal:T};s!=null&&(y.body=JSON.stringify(s));let m;try{L(i.url),m=await fetch(i.url,y)}catch(R){g!==void 0&&clearTimeout(g);let z=R instanceof DOMException&&R.name==="AbortError"?`Request timeout after ${i.timeout}ms`:R instanceof Error?R.message:"Network error",A=new v(z,0,"",null,i);for(let Z of f)A=await Z(A);throw A}g!==void 0&&clearTimeout(g);let E=m.headers.get("content-type")??"",b;if(E.includes("application/json"))b=await m.json();else{let R=await m.text();try{b=JSON.parse(R)}catch{b=R}}let C=se(m.headers);if(!m.ok){let R=new v(`Request failed with status ${m.status}`,m.status,m.statusText,b,i);for(let M of f)R=await M(R);throw R}let P={data:b,status:m.status,headers:C,ok:m.ok};for(let R of c)P=R(P);return P}return{get(l,a){return h("GET",l,void 0,a)},post(l,a,s){return h("POST",l,a,s)},put(l,a,s){return h("PUT",l,a,s)},patch(l,a,s){return h("PATCH",l,a,s)},delete(l,a){return h("DELETE",l,void 0,a)}}}function W(e,t,n){let o=n?.method??"GET",r=n?.body,u=n?.deps??[],c=n?.enabled??!0,[f,h]=w(null),[l,a]=w(c),[s,p]=w(null),i=x(null),g=x(!0),d=k(()=>{if(!c){a(!1);return}i.current&&i.current.abort();let y=new AbortController;i.current=y,a(!0),p(null);let m={signal:y.signal},E,b=o.toUpperCase();b==="POST"?E=e.post(t,r,m):b==="PUT"?E=e.put(t,r,m):b==="PATCH"?E=e.patch(t,r,m):b==="DELETE"?E=e.delete(t,m):E=e.get(t,m),E.then(C=>{g.current&&!y.signal.aborted&&(h(C.data),a(!1))}).catch(C=>{g.current&&!y.signal.aborted&&(p(C instanceof v?C:new v(C instanceof Error?C.message:"Unknown error",0,"",null,{url:t,method:b,headers:{}})),a(!1))})},[e,t,o,r,c,...u]);q(()=>(g.current=!0,d(),()=>{g.current=!1,i.current&&i.current.abort()}),[d]);let T=k(()=>{d()},[d]);return{data:f,loading:l,error:s,refetch:T}}function S(e){let t=[],n=e>>>0;for(;n>127;)t.push(n&127|128),n>>>=7;return t.push(n&127),t}function U(e,t){let n=0,o=0,r=t;for(;r<e.length;){let u=e[r];if(n|=(u&127)<<o,r++,(u&128)===0)return[n>>>0,r];if(o+=7,o>=35)throw new Error("Varint too long")}throw new Error("Unexpected end of data while decoding varint")}var I=0,Q=1,D=2;function ae(e){switch(e){case"int32":case"uint32":case"bool":case"enum":return I;case"float64":return Q;case"string":case"bytes":return D}}function V(e,t){return S(e<<3|t)}function $(e,t){switch(e){case"int32":return S(t|0);case"uint32":return S(t>>>0);case"bool":return S(t?1:0);case"enum":return S(t>>>0);case"float64":{let n=new ArrayBuffer(8);return new DataView(n).setFloat64(0,t,!0),Array.from(new Uint8Array(n))}case"string":{let n=new TextEncoder().encode(t);return[...S(n.length),...n]}case"bytes":{let n=t;return[...S(n.length),...n]}}}function ue(e,t,n,o){switch(t){case I:{let[r,u]=U(n,o);switch(e){case"bool":return[r!==0,u];case"int32":return[r|0,u];case"uint32":case"enum":return[r>>>0,u];default:return[r,u]}}case Q:{if(o+8>n.length)throw new Error("Unexpected end of data while decoding 64-bit value");let r=new ArrayBuffer(8),u=new Uint8Array(r);for(let f=0;f<8;f++)u[f]=n[o+f]??0;return[new DataView(r).getFloat64(0,!0),o+8]}case D:{let[r,u]=U(n,o);if(u+r>n.length)throw new Error("Unexpected end of data while decoding length-delimited value");let c=n.slice(u,u+r);return e==="string"?[new TextDecoder().decode(c),u+r]:[c,u+r]}default:throw new Error(`Unknown wire type: ${t}`)}}function N(e,t){let n=new Map;for(let[u,c]of Object.entries(t))n.set(c.tag,{fieldName:u,descriptor:c});function o(u){let c=[],f=u;for(let[h,l]of Object.entries(t)){let a=f[h];if(a==null)continue;let s=ae(l.type);if(l.repeated){let p=a;for(let i of p)c.push(...V(l.tag,s)),c.push(...$(l.type,i))}else c.push(...V(l.tag,s)),c.push(...$(l.type,a))}return new Uint8Array(c)}function r(u){let c={};for(let[h,l]of Object.entries(t))l.repeated&&(c[h]=[]);let f=0;for(;f<u.length;){let[h,l]=U(u,f),a=h>>>3,s=h&7;f=l;let p=n.get(a);if(!p){f=ce(s,u,f);continue}let[i,g]=ue(p.descriptor.type,s,u,f);f=g,p.descriptor.repeated?c[p.fieldName].push(i):c[p.fieldName]=i}return c}return{name:e,fields:t,encode:o,decode:r}}function ce(e,t,n){switch(e){case I:{let[,o]=U(t,n);return o}case Q:return n+8;case D:{let[o,r]=U(t,n);return r+o}default:throw new Error(`Cannot skip unknown wire type: ${e}`)}}function le(e,t=0){let n=new Uint8Array(5+e.length);return n[0]=t,new DataView(n.buffer,n.byteOffset,n.byteLength).setUint32(1,e.length,!1),n.set(e,5),n}function pe(e){if(e.length<5)throw new Error("gRPC-Web frame too short");let t=e[0]??0,o=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(1,!1);if(e.length<5+o)throw new Error("gRPC-Web frame data incomplete");let r=e.slice(5,5+o);return[t,r,5+o]}function j(e){let{baseURL:t,headers:n}=e;async function o(r,u,c,f,h){let l=c.encode(h),a=le(l),s=`${t.replace(/\/+$/,"")}/${r}/${u}`,p={"Content-Type":"application/grpc-web+proto",Accept:"application/grpc-web+proto","X-Grpc-Web":"1",...n};L(s);let i=await fetch(s,{method:"POST",headers:p,body:a.buffer});if(!i.ok)throw new Error(`gRPC-Web request failed: ${i.status} ${i.statusText}`);let g=new Uint8Array(await i.arrayBuffer()),d=0;for(;d<g.length;){let[T,y,m]=pe(g.subarray(d));if(d+=m,(T&128)===0)return f.decode(y)}throw new Error("No data frame found in gRPC-Web response")}return{unary:o}}function J(e,t,n,o,r,u,c){let[f,h]=w(null),[l,a]=w(!1),[s,p]=w(null),i=x(!0),g=x(u);g.current=u;let d=c?.enabled!==!1,T=k(()=>{d&&(a(!0),p(null),e.unary(t,n,o,r,g.current).then(y=>{i.current&&(h(y),a(!1))}).catch(y=>{i.current&&(p(y instanceof Error?y:new Error(String(y))),a(!1))}))},[e,t,n,o,r,d]);return q(()=>(i.current=!0,T(),()=>{i.current=!1}),[T]),{data:f,loading:l,error:s,refetch:T}}function _(e,...t){let n="";for(let o=0;o<e.length;o++)if(n+=e[o],o<t.length){let r=String(t[o]);if(/[{}():]/.test(r))throw new Error(`[SpecifyJS] gql: Interpolated value "${r}" contains GraphQL metacharacters ({, }, (, ), :). Use the variables parameter instead of string interpolation to prevent injection.`);n+=r}return n.replace(/\s+/g," ").trim()}function B(e){let{url:t,headers:n,credentials:o,cache:r=!1}=e,u=100,c=new Map;function f(a,s){return JSON.stringify({query:a,variables:s})}async function h(a,s){let p={"Content-Type":"application/json",...n},i=JSON.stringify({query:a,variables:s});L(t);let g=await fetch(t,{method:"POST",headers:p,credentials:o,body:i});if(!g.ok)throw new Error(`GraphQL request failed with status ${g.status}`);let d=await g.json();return{data:d.data??null,errors:d.errors??null,...d.extensions!==void 0?{extensions:d.extensions}:{}}}return{async query(a,s){if(r){let p=f(a,s),i=c.get(p);if(i)return i;let g=await h(a,s);if(c.size>=u){let d=c.keys().next().value;d!==void 0&&c.delete(d)}return c.set(p,g),g}return h(a,s)},async mutate(a,s){return h(a,s)},clearCache(){c.clear()},invalidate(a){for(let s of c.keys())try{JSON.parse(s).query===a&&c.delete(s)}catch{}}}}function X(e,t,n){let o=n?.variables,r=n?.deps,u=n?.enabled??!0,[c,f]=w(null),[h,l]=w(u),[a,s]=w(null),p=x(0),i=k(()=>{if(!u)return;let d=++p.current;l(!0),s(null),e.query(t,o).then(T=>{p.current===d&&(f(T.data),s(T.errors),l(!1))}).catch(T=>{p.current===d&&(s([{message:T instanceof Error?T.message:String(T)}]),l(!1))})},[e,t,o,u]),g=r?[i,...r]:[i];return q(()=>{i()},g),{data:c,loading:h,error:a,refetch:i}}function K(e,t){let[n,o]=w(null),[r,u]=w(!1),[c,f]=w(null),h=async a=>{u(!0),f(null);try{let s=await e.mutate(t,a);return o(s.data),f(s.errors),u(!1),s}catch(s){let p=[{message:s instanceof Error?s.message:String(s)}];return f(p),u(!1),{data:null,errors:p,extensions:void 0}}};return[k(((...a)=>h(a[0])),[e,t]),{data:n,loading:r,error:c}]}
|
|
2
|
+
"use strict";var O=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.prototype.hasOwnProperty;var ne=(e,t)=>{for(var n in t)O(e,n,{get:t[n],enumerable:!0})},re=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ee(t))!te.call(e,r)&&r!==n&&O(e,r,{get:()=>t[r],enumerable:!(o=Y(t,r))||o.enumerable});return e};var oe=e=>re(O({},"__esModule",{value:!0}),e);var fe={};ne(fe,{RestError:()=>v,createGraphQLClient:()=>B,createGrpcWebClient:()=>j,createRestClient:()=>F,defineMessage:()=>N,gql:()=>_,useMutation:()=>K,useProto:()=>J,useQuery:()=>X,useRest:()=>W});module.exports=oe(fe);var H=null;function G(){if(H===null)throw new Error("Invalid hook call. Hooks can only be called inside the body of a function component.");return H}function w(e){return G().useState(e)}function S(e,t){return G().useEffect(e,t)}function k(e,t){return G().useCallback(e,t)}function x(e){return G().useRef(e)}function L(e){if(e.startsWith("//"))throw new Error(`[SpecifyJS] Protocol-relative URL rejected: "${e}". Use an explicit https:// prefix.`);if(e.startsWith("/")||e.startsWith("./")||e.startsWith("../"))return;if(e.startsWith("data:")){if(e.length>1024*1024)throw new Error("[SpecifyJS] secureFetch: data: URI exceeds 1MB limit");return}let t;try{t=new URL(e,typeof window<"u"?window.location.href:void 0)}catch{throw new Error(`[SpecifyJS] secureFetch: unable to validate URL "${e}". Provide a valid absolute HTTPS URL or a relative path.`)}if(t.protocol==="https:")return;let n=t.hostname.toLowerCase();if(!(n==="localhost"||n==="127.0.0.1"||n==="[::1]"||n==="0.0.0.0"||n.startsWith("127.")))throw n.endsWith(".localhost")?new Error(`[SpecifyJS] SSRF protection: "${e}" uses a .localhost subdomain which resolves to the loopback interface. Use exact "localhost" instead.`):new Error(`[SpecifyJS] Insecure URL rejected: "${e}". SpecifyJS enforces HTTPS-only for all network requests. Use https:// or a relative URL. Localhost URLs are allowed for development.`)}var v=class extends Error{constructor(t,n,o,r,u){super(t),this.name="RestError",this.status=n,this.statusText=o,this.data=r,this.config=u}};function se(e){let t={};return e.forEach((n,o)=>{t[o]=n}),t}function ie(e,t){let n=e.endsWith("/")?e.slice(0,-1):e,o=t.startsWith("/")?t:"/"+t;return n+o}function F(e){let{baseURL:t,headers:n={},timeout:o,interceptors:r={}}=e,u=r.request??[],c=r.response??[],f=r.error??[];async function h(l,a,s,p){let i={url:ie(t,a),method:l,headers:{...n,...p?.headers??{}},body:s,signal:p?.signal,timeout:p?.timeout??o};s!=null&&!i.headers["Content-Type"]&&(i.headers["Content-Type"]="application/json");for(let R of u)i=await R(i);let g,d;if(i.timeout&&i.timeout>0&&(d=new AbortController,g=setTimeout(()=>{d.abort()},i.timeout),i.signal)){let R=i.signal;R.aborted?d.abort():R.addEventListener("abort",()=>{d.abort()})}let T=d?d.signal:i.signal,y={method:i.method,headers:i.headers,signal:T};s!=null&&(y.body=JSON.stringify(s));let m;try{L(i.url),m=await fetch(i.url,y)}catch(R){g!==void 0&&clearTimeout(g);let z=R instanceof DOMException&&R.name==="AbortError"?`Request timeout after ${i.timeout}ms`:R instanceof Error?R.message:"Network error",A=new v(z,0,"",null,i);for(let Z of f)A=await Z(A);throw A}g!==void 0&&clearTimeout(g);let E=m.headers.get("content-type")??"",b;if(E.includes("application/json"))b=await m.json();else{let R=await m.text();try{b=JSON.parse(R)}catch{b=R}}let C=se(m.headers);if(!m.ok){let R=new v(`Request failed with status ${m.status}`,m.status,m.statusText,b,i);for(let M of f)R=await M(R);throw R}let P={data:b,status:m.status,headers:C,ok:m.ok};for(let R of c)P=R(P);return P}return{get(l,a){return h("GET",l,void 0,a)},post(l,a,s){return h("POST",l,a,s)},put(l,a,s){return h("PUT",l,a,s)},patch(l,a,s){return h("PATCH",l,a,s)},delete(l,a){return h("DELETE",l,void 0,a)}}}function W(e,t,n){let o=n?.method??"GET",r=n?.body,u=n?.deps??[],c=n?.enabled??!0,[f,h]=w(null),[l,a]=w(c),[s,p]=w(null),i=x(null),g=x(!0),d=k(()=>{if(!c){a(!1);return}i.current&&i.current.abort();let y=new AbortController;i.current=y,a(!0),p(null);let m={signal:y.signal},E,b=o.toUpperCase();b==="POST"?E=e.post(t,r,m):b==="PUT"?E=e.put(t,r,m):b==="PATCH"?E=e.patch(t,r,m):b==="DELETE"?E=e.delete(t,m):E=e.get(t,m),E.then(C=>{g.current&&!y.signal.aborted&&(h(C.data),a(!1))}).catch(C=>{g.current&&!y.signal.aborted&&(p(C instanceof v?C:new v(C instanceof Error?C.message:"Unknown error",0,"",null,{url:t,method:b,headers:{}})),a(!1))})},[e,t,o,r,c,...u]);S(()=>(g.current=!0,d(),()=>{g.current=!1,i.current&&i.current.abort()}),[d]);let T=k(()=>{d()},[d]);return{data:f,loading:l,error:s,refetch:T}}function q(e){let t=[],n=e>>>0;for(;n>127;)t.push(n&127|128),n>>>=7;return t.push(n&127),t}function U(e,t){let n=0,o=0,r=t;for(;r<e.length;){let u=e[r];if(n|=(u&127)<<o,r++,(u&128)===0)return[n>>>0,r];if(o+=7,o>=35)throw new Error("Varint too long")}throw new Error("Unexpected end of data while decoding varint")}var I=0,Q=1,D=2;function ae(e){switch(e){case"int32":case"uint32":case"bool":case"enum":return I;case"float64":return Q;case"string":case"bytes":return D}}function $(e,t){return q(e<<3|t)}function V(e,t){switch(e){case"int32":return q(t|0);case"uint32":return q(t>>>0);case"bool":return q(t?1:0);case"enum":return q(t>>>0);case"float64":{let n=new ArrayBuffer(8);return new DataView(n).setFloat64(0,t,!0),Array.from(new Uint8Array(n))}case"string":{let n=new TextEncoder().encode(t);return[...q(n.length),...n]}case"bytes":{let n=t;return[...q(n.length),...n]}}}function ue(e,t,n,o){switch(t){case I:{let[r,u]=U(n,o);switch(e){case"bool":return[r!==0,u];case"int32":return[r|0,u];case"uint32":case"enum":return[r>>>0,u];default:return[r,u]}}case Q:{if(o+8>n.length)throw new Error("Unexpected end of data while decoding 64-bit value");let r=new ArrayBuffer(8),u=new Uint8Array(r);for(let f=0;f<8;f++)u[f]=n[o+f]??0;return[new DataView(r).getFloat64(0,!0),o+8]}case D:{let[r,u]=U(n,o);if(u+r>n.length)throw new Error("Unexpected end of data while decoding length-delimited value");let c=n.slice(u,u+r);return e==="string"?[new TextDecoder().decode(c),u+r]:[c,u+r]}default:throw new Error(`Unknown wire type: ${t}`)}}function N(e,t){let n=new Map;for(let[u,c]of Object.entries(t))n.set(c.tag,{fieldName:u,descriptor:c});function o(u){let c=[],f=u;for(let[h,l]of Object.entries(t)){let a=f[h];if(a==null)continue;let s=ae(l.type);if(l.repeated){let p=a;for(let i of p)c.push(...$(l.tag,s)),c.push(...V(l.type,i))}else c.push(...$(l.tag,s)),c.push(...V(l.type,a))}return new Uint8Array(c)}function r(u){let c={};for(let[h,l]of Object.entries(t))l.repeated&&(c[h]=[]);let f=0;for(;f<u.length;){let[h,l]=U(u,f),a=h>>>3,s=h&7;f=l;let p=n.get(a);if(!p){f=ce(s,u,f);continue}let[i,g]=ue(p.descriptor.type,s,u,f);f=g,p.descriptor.repeated?c[p.fieldName].push(i):c[p.fieldName]=i}return c}return{name:e,fields:t,encode:o,decode:r}}function ce(e,t,n){switch(e){case I:{let[,o]=U(t,n);return o}case Q:return n+8;case D:{let[o,r]=U(t,n);return r+o}default:throw new Error(`Cannot skip unknown wire type: ${e}`)}}function le(e,t=0){let n=new Uint8Array(5+e.length);return n[0]=t,new DataView(n.buffer,n.byteOffset,n.byteLength).setUint32(1,e.length,!1),n.set(e,5),n}function pe(e){if(e.length<5)throw new Error("gRPC-Web frame too short");let t=e[0]??0,o=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(1,!1);if(e.length<5+o)throw new Error("gRPC-Web frame data incomplete");let r=e.slice(5,5+o);return[t,r,5+o]}function j(e){let{baseURL:t,headers:n}=e;async function o(r,u,c,f,h){let l=c.encode(h),a=le(l),s=`${t.replace(/\/+$/,"")}/${r}/${u}`,p={"Content-Type":"application/grpc-web+proto",Accept:"application/grpc-web+proto","X-Grpc-Web":"1",...n};L(s);let i=await fetch(s,{method:"POST",headers:p,body:a.buffer});if(!i.ok)throw new Error(`gRPC-Web request failed: ${i.status} ${i.statusText}`);let g=new Uint8Array(await i.arrayBuffer()),d=0;for(;d<g.length;){let[T,y,m]=pe(g.subarray(d));if(d+=m,(T&128)===0)return f.decode(y)}throw new Error("No data frame found in gRPC-Web response")}return{unary:o}}function J(e,t,n,o,r,u,c){let[f,h]=w(null),[l,a]=w(!1),[s,p]=w(null),i=x(!0),g=x(u);g.current=u;let d=c?.enabled!==!1,T=k(()=>{d&&(a(!0),p(null),e.unary(t,n,o,r,g.current).then(y=>{i.current&&(h(y),a(!1))}).catch(y=>{i.current&&(p(y instanceof Error?y:new Error(String(y))),a(!1))}))},[e,t,n,o,r,d]);return S(()=>(i.current=!0,T(),()=>{i.current=!1}),[T]),{data:f,loading:l,error:s,refetch:T}}function _(e,...t){let n="";for(let o=0;o<e.length;o++)if(n+=e[o],o<t.length){let r=String(t[o]);if(/[{}():]/.test(r))throw new Error(`[SpecifyJS] gql: Interpolated value "${r}" contains GraphQL metacharacters ({, }, (, ), :). Use the variables parameter instead of string interpolation to prevent injection.`);n+=r}return n.replace(/\s+/g," ").trim()}function B(e){let{url:t,headers:n,credentials:o,cache:r=!1}=e,u=100,c=new Map;function f(a,s){return JSON.stringify({query:a,variables:s})}async function h(a,s){let p={"Content-Type":"application/json",...n},i=JSON.stringify({query:a,variables:s});L(t);let g=await fetch(t,{method:"POST",headers:p,credentials:o,body:i});if(!g.ok)throw new Error(`GraphQL request failed with status ${g.status}`);let d=await g.json();return{data:d.data??null,errors:d.errors??null,...d.extensions!==void 0?{extensions:d.extensions}:{}}}return{async query(a,s){if(r){let p=f(a,s),i=c.get(p);if(i)return i;let g=await h(a,s);if(c.size>=u){let d=c.keys().next().value;d!==void 0&&c.delete(d)}return c.set(p,g),g}return h(a,s)},async mutate(a,s){return h(a,s)},clearCache(){c.clear()},invalidate(a){for(let s of c.keys())try{JSON.parse(s).query===a&&c.delete(s)}catch{}}}}function X(e,t,n){let o=n?.variables,r=n?.deps,u=n?.enabled??!0,[c,f]=w(null),[h,l]=w(u),[a,s]=w(null),p=x(0),i=k(()=>{if(!u)return;let d=++p.current;l(!0),s(null),e.query(t,o).then(T=>{p.current===d&&(f(T.data),s(T.errors),l(!1))}).catch(T=>{p.current===d&&(s([{message:T instanceof Error?T.message:String(T)}]),l(!1))})},[e,t,o,u]),g=r?[i,...r]:[i];return S(()=>{i()},g),{data:c,loading:h,error:a,refetch:i}}function K(e,t){let[n,o]=w(null),[r,u]=w(!1),[c,f]=w(null),h=async a=>{u(!0),f(null);try{let s=await e.mutate(t,a);return o(s.data),f(s.errors),u(!1),s}catch(s){let p=[{message:s instanceof Error?s.message:String(s)}];return f(p),u(!1),{data:null,errors:p,extensions:void 0}}};return[k(((...a)=>h(a[0])),[e,t]),{data:n,loading:r,error:c}]}
|