physicalvalidation 0.0.0-stage → 0.1.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 +137 -2
- package/dist/cli.js +93 -0
- package/package.json +55 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Halmos Labs
|
|
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,138 @@
|
|
|
1
|
-
#
|
|
1
|
+
# physicalvalidation
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Search [Physical Validation](https://physicalvalidation.com) for providers and capabilities, or send a request for a person to review. Nothing is sent to a provider automatically. The CLI does not run a model.
|
|
4
|
+
|
|
5
|
+
The npm package name is `physicalvalidation`. Version 0.1.0 is the first CLI. It is not on the registry until it is published. Publishing is a manual workflow.
|
|
6
|
+
|
|
7
|
+
Node.js 18 or newer is required.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx physicalvalidation --help
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Install and usage
|
|
14
|
+
|
|
15
|
+
There is nothing to install ahead of time. `npx`, `bunx`, and `pnpm dlx` run the package when it is on the registry:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npx physicalvalidation search "peptide bioanalysis" --country US
|
|
19
|
+
npx physicalvalidation company <id> --json
|
|
20
|
+
npx physicalvalidation services
|
|
21
|
+
npx physicalvalidation "GLP bioanalysis for a peptide, US site"
|
|
22
|
+
bunx physicalvalidation "Stability study for an mRNA-LNP, EU site"
|
|
23
|
+
pnpm dlx physicalvalidation "Peptide characterization, GMP, US"
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
From a checkout:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install
|
|
30
|
+
npm run build
|
|
31
|
+
node dist/cli.js search "peptide bioanalysis" --limit 5
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Search and lookup
|
|
35
|
+
|
|
36
|
+
Catalogue reads need no account. `--json` prints the API document. Commercial fields are left out of that printout.
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npx physicalvalidation search "analytical development" --country US --quality GLP
|
|
40
|
+
npx physicalvalidation search --service "Peptide synthesis" --facets
|
|
41
|
+
npx physicalvalidation company listed:org_example
|
|
42
|
+
npx physicalvalidation site <id> --json
|
|
43
|
+
npx physicalvalidation services
|
|
44
|
+
npx physicalvalidation techniques
|
|
45
|
+
npx physicalvalidation countries
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`capabilities` is another name for `services`. Company ids come from search and look like `listed:org_example`. Pass `--cursor` with `next_cursor` from a previous `--json` page.
|
|
49
|
+
|
|
50
|
+
## Sending a request
|
|
51
|
+
|
|
52
|
+
On a terminal the command shows the request, asks for an email, then beams it:
|
|
53
|
+
|
|
54
|
+
```text
|
|
55
|
+
┌ Physical Validation
|
|
56
|
+
│
|
|
57
|
+
│ GLP bioanalysis for a peptide, US site.
|
|
58
|
+
│
|
|
59
|
+
email: ada@lab.example
|
|
60
|
+
Beaming your request to Physical Validation...
|
|
61
|
+
Code sent.
|
|
62
|
+
code: 123456
|
|
63
|
+
|
|
64
|
+
✓ Received. A person at Physical Validation will review it. Nothing else happens automatically.
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The code is six digits, with up to five attempts. `Ctrl-C` cancels. The request text must be 1 to 4000 characters.
|
|
68
|
+
|
|
69
|
+
Another agent can pipe the request. When stdin is not a terminal, pass `--email` and `--code` as well:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
printf '%s\n' "Method transfer for a small molecule" \
|
|
73
|
+
| npx physicalvalidation --email ada@lab.example --code 123456
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Stdout is then only the received line. Errors go to stderr. To send text that starts with a command name, put it after `--`:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
npx physicalvalidation -- "search notes for the notebook"
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### What is sent
|
|
83
|
+
|
|
84
|
+
The CLI talks only to the public API, with no login:
|
|
85
|
+
|
|
86
|
+
1. `POST /api/v1/unvetted-requests` with JSON `{"text","email"}`. The response is `{"id","status":"code_sent"}`.
|
|
87
|
+
2. `POST /api/v1/unvetted-requests/{id}/verify` with JSON `{"code"}`. The response is `{"status":"received"}`.
|
|
88
|
+
|
|
89
|
+
Those two objects are the entire body. The command prints its own confirmation and does not print the raw response. The request is stored as an unvetted request for a person to review. Suppliers are not contacted.
|
|
90
|
+
|
|
91
|
+
The same machine waits 30 seconds between requests. When the API answers `429` with `Retry-After`, the command says how long to wait and remembers that wait, up to a day. The local file stores only the timestamp. It does not store the request text or the email. `PHYSICALVALIDATION_COOLDOWN_MS=0` turns the 30-second wait off. The server's own limits still apply.
|
|
92
|
+
|
|
93
|
+
## Options
|
|
94
|
+
|
|
95
|
+
| Flag | Meaning |
|
|
96
|
+
| --- | --- |
|
|
97
|
+
| `--api <url>` | API base URL. Default: `https://physicalvalidation.com/api/v1` |
|
|
98
|
+
| `--json` | Print search and lookup as JSON |
|
|
99
|
+
| `--email <email>` | Email address. Prompted on a terminal. Required otherwise. |
|
|
100
|
+
| `--code <digits>` | Six-digit code. Prompted on a terminal. Required otherwise. |
|
|
101
|
+
| `-h`, `--help` | Show help and examples |
|
|
102
|
+
| `-V`, `--version` | Show the version |
|
|
103
|
+
|
|
104
|
+
`PHYSICALVALIDATION_API` sets the same base URL. `--api` wins when both are set. `NO_COLOR` (any non-empty value) turns off color. Output is plain when stdout is not a terminal, too.
|
|
105
|
+
|
|
106
|
+
## Exit codes
|
|
107
|
+
|
|
108
|
+
| Code | Meaning |
|
|
109
|
+
| --- | --- |
|
|
110
|
+
| 0 | The search or lookup finished, or the request was received |
|
|
111
|
+
| 1 | Network problem, rate limit, expired code, or a rejected request |
|
|
112
|
+
| 2 | The command line or the typed email/code needs a fix |
|
|
113
|
+
| 130 | Cancelled |
|
|
114
|
+
|
|
115
|
+
## Privacy
|
|
116
|
+
|
|
117
|
+
Search and lookup are anonymous reads of the public catalogue. A request sends the text and the email address to Physical Validation so a confirmation code can be mailed and the request can be stored for review. The code from that email is sent back to confirm it. No account is created. The CLI does not call a model, does not crawl, and does not contact a provider. The API reference is [physicalvalidation.com/docs/api](https://physicalvalidation.com/docs/api), and the OpenAPI document is [physicalvalidation.com/api/v1/openapi.json](https://physicalvalidation.com/api/v1/openapi.json). Terms: [physicalvalidation.com/terms](https://physicalvalidation.com/terms).
|
|
118
|
+
|
|
119
|
+
## Development
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
npm install
|
|
123
|
+
npm test
|
|
124
|
+
npm run lint
|
|
125
|
+
npm run typecheck
|
|
126
|
+
npm run build
|
|
127
|
+
node dist/cli.js --help
|
|
128
|
+
npm run pack:dry
|
|
129
|
+
npm run bench
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
`npm test` runs unit tests and mocked HTTP tests. A live smoke test against `https://physicalvalidation.com/api/v1` stays skipped unless `PHYSICALVALIDATION_LIVE=1`. `npm run pack:dry` is `npm pack --dry-run`. The packed files are `dist/cli.js`, `README.md`, `LICENSE`, and `package.json`. CI runs lint, typecheck, build, test, and the pack dry run.
|
|
133
|
+
|
|
134
|
+
Publishing is a manual GitHub Actions workflow (`workflow_dispatch` only). It asks you to type the package version, then runs `npm publish --access public` with the `NPM_TOKEN` Actions secret. That works from a private repository. It does not run on push.
|
|
135
|
+
|
|
136
|
+
## License
|
|
137
|
+
|
|
138
|
+
[MIT](LICENSE). Copyright (c) 2026 Halmos Labs.
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{createInterface as lt}from"readline/promises";var s=class extends Error{exitCode;kind;retryAfterSeconds;constructor(t,r,n,i){super(t),this.name="CliError",this.exitCode=r,this.kind=n,i!==void 0&&(this.retryAfterSeconds=i)}};var U=/^unv_[0-9a-f]{32}$/,Se=1440*60,A=class{base;fetchImpl;version;timeoutMs;constructor(t){this.base=t.base.replace(/\/$/,""),this.fetchImpl=t.fetch,this.version=t.version,this.timeoutMs=t.timeoutMs??2e4}async create(t,r){let n=await this.send("POST","/unvetted-requests",{text:t,email:r},"create"),i=n.id,o=n.status;if(typeof i!="string"||!U.test(i)||o!=="code_sent")throw v();return{id:i,status:"code_sent"}}async verify(t,r){if(!U.test(t)||(await this.send("POST",`/unvetted-requests/${encodeURIComponent(t)}/verify`,{code:r},"verify")).status!=="received")throw v();return{status:"received"}}async search(t){return this.send("GET","/search",void 0,"read",Ae(t))}async company(t){return this.send("GET",`/companies/${encodeURIComponent(t)}`,void 0,"read")}async site(t){return this.send("GET",`/sites/${encodeURIComponent(t)}`,void 0,"read")}async services(){return this.send("GET","/services",void 0,"read")}async techniques(){return this.send("GET","/techniques",void 0,"read")}async countries(){return this.send("GET","/countries",void 0,"read")}async send(t,r,n,i,o){let a=o&&[...o.keys()].length>0?`${this.base}${r}?${o}`:`${this.base}${r}`,c;try{c=await this.fetchImpl(a,{method:t,redirect:"manual",credentials:"omit",headers:{accept:"application/json","user-agent":`physicalvalidation/${this.version}`,...n?{"content-type":"application/json"}:{}},body:n?JSON.stringify(n):void 0,signal:AbortSignal.timeout(this.timeoutMs)})}catch(f){throw qe(f)}if(c.status>=300&&c.status<400)throw new s("Physical Validation sent an unexpected redirect. Nothing else was sent.",1,"unexpected");let u=await Ie(c);if(c.status===429||$e(c.status,u))throw ke(c,u);if(!c.ok)throw Re(c.status,u,i);if(!k(u)||i==="read"&&!("data"in u))throw v();return u}};function Ae(e){let t=new URLSearchParams;return e.q&&t.set("q",e.q),w(t,"service",e.service),w(t,"type",e.type),w(t,"country",e.country),w(t,"region",e.region),w(t,"modality",e.modality),w(t,"quality",e.quality),w(t,"equipment",e.equipment),e.sort&&t.set("sort",e.sort),e.limit&&t.set("limit",e.limit),e.cursor&&t.set("cursor",e.cursor),e.facets&&t.set("facets","true"),t}function w(e,t,r){for(let n of r??[])e.append(t,n)}function v(){return new s("Physical Validation returned an unexpected response. Try again in a moment.",1,"unexpected")}function ke(e,t){let r=Pe(e.headers.get("retry-after")),n=P(t),i=Ee(r),o=n.toUpperCase()==="TOO_MANY_ATTEMPTS"?"Too many tries.":"Physical Validation is receiving too many requests right now.";return new s(`${o}${i}`,1,"rate_limit",r??60)}function Ee(e){return e===void 0?" Wait a minute and try again.":e<1?" Try again in a moment.":e===1?" Try again in 1 second.":` Try again in ${e} seconds.`}function Pe(e){let t=e?.trim()??"";if(!t)return;if(/^\d+$/.test(t))return D(Number(t));let r=Date.parse(t);if(!Number.isNaN(r))return D(Math.ceil((r-Date.now())/1e3))}function D(e){return Number.isFinite(e)?Math.min(Math.max(0,e),Se):0}function Re(e,t,r){let n=P(t),i=_e(t);if(e===410||n.toUpperCase()==="EXPIRED")return new s("That code has expired. Run the command again to request a new one.",1,"expired");if(e===409||n.toUpperCase()==="STALE_CURSOR")return new s("That page cursor is out of date. Search again without --cursor.",1,"rejected");if(e===503||n.toUpperCase()==="UNAVAILABLE")return new s("Physical Validation is not taking requests right now. Try again later.",1,"rejected");if(e===404){if(r==="read"){let c=V(i);return new s(c??"Nothing matched that id.",1,"rejected")}return new s(r==="verify"?"That code could not be matched. Run the command again to request a new one.":"Physical Validation is not ready to take that request yet. Try again later.",1,"rejected")}if(e===413)return new s("That request is too long.",2,"usage");if(r==="verify"&&(e===400||e===401||e===403||e===422||/code/i.test(n)))return new s("That code does not match.",1,"invalid_code");let o=V(i),a=e>=500?"Physical Validation had a problem on its side. Try again in a moment.":r==="read"?"Physical Validation did not accept that lookup.":"Physical Validation did not accept that request.";return new s(o?`${a} ${o}`:a,1,"rejected")}function $e(e,t){if(e===429)return!0;let r=P(t);return/^(rate_limited|too_many_requests|rate_limit|too_many_attempts)$/i.test(r)}function V(e){let t=e.replace(/\s+/g," ").trim();if(!(!t||t.length>180||t.includes("@")||Ne(t))&&!Ce(t))return t}function Ce(e){return!!(/price|pricing|\bcost\b|\bfees?\b|\$\s?\d|\b(?:usd|eur|gbp|aud|cad)\b/i.test(e)||/\.(?:ts|tsx|js|mjs|cjs):\d+/.test(e)||/\bat\s+\S+\s+\(/.test(e)||/\bstack\s*trace\b/i.test(e)||/node:internal/.test(e))}function P(e){let t=B(e);return typeof t?.code=="string"?t.code:""}function _e(e){let t=B(e);return typeof t?.message=="string"?t.message:k(e)&&typeof e.message=="string"?e.message:""}function B(e){if(k(e))return k(e.error)?e.error:e}function Ne(e){for(let t=0;t<e.length;t+=1)if(e.charCodeAt(t)<=31)return!0;return!1}async function Ie(e){let t;try{t=await e.text()}catch{return null}if(!t)return null;try{return JSON.parse(t)}catch{return null}}function qe(e){return e instanceof s?e:Le(e)?new s("Physical Validation took too long to respond. Try again in a moment.",1,"network"):new s("Could not reach Physical Validation. Check your connection and try again.",1,"network")}function Le(e){let t=Oe(e);if(t==="TimeoutError"||t==="AbortError")return!0;let r=Me(e);return r==="ETIMEDOUT"||r==="UND_ERR_CONNECT_TIMEOUT"||r==="ABORT_ERR"}function Oe(e){return e&&typeof e=="object"&&"name"in e&&typeof e.name=="string"?e.name:""}function Me(e){let t=new Set,r=n=>{if(!(!n||typeof n!="object"||t.has(n))){if(t.add(n),"code"in n&&typeof n.code=="string")return n.code;if("errors"in n&&Array.isArray(n.errors))for(let i of n.errors){let o=r(i);if(o)return o}if("cause"in n)return r(n.cause)}};return r(e)}function k(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}var je=/^(?:price|prices|pricing|cost|costs|fee|fees|budget|budgets|quote|quotes|currency)$/i,G=/\$\s?\d|\b\d[\d,.]*\s*(?:usd|eur|gbp|aud|cad)\b/i;function R(e){if(Array.isArray(e))return e.map(R).filter(r=>r!==void 0);if(!h(e))return typeof e=="string"&&G.test(e)?void 0:e;let t={};for(let[r,n]of Object.entries(e)){if(je.test(r))continue;let i=R(n);i!==void 0&&(t[r]=i)}return t}function Y(e){return`${JSON.stringify(R(e),null,2)}
|
|
3
|
+
`}function J(e){let t=y(e),r=b(t.data);if(r.length===0)return`No providers matched that search.
|
|
4
|
+
`;let n=[],i=Je(t);return i!==void 0&&n.push(`${i} ${i===1?"provider":"providers"}`,""),r.forEach((o,a)=>{n.push(`${a+1}. ${d(o.name)||"Provider"}`);let c=[d(o.providerType),d(o.level),Be(o)].filter(Te=>Te.length>0);c.length>0&&n.push(` ${c.join(" \xB7 ")}`);let u=d(o.id);u&&n.push(` ${u}`);let f=K(o.countries);f.length>0&&n.push(` ${f.join(", ")}`);let l=$(o.sites);l&&l!=="0"&&n.push(` ${l} ${l==="1"?"site":"sites"}`);let m=d(o.summary);m&&n.push(` ${m}`);let p=Fe(o.matched);p.length>0&&n.push(` ${p.join(", ")}`);let g=d(o.url);g&&n.push(` ${g}`),n.push("")}),Ve(n,t),typeof t.next_cursor=="string"&&t.next_cursor&&n.push("Another page is available. Run again with --json and pass next_cursor to --cursor."),`${n.join(`
|
|
5
|
+
`).replace(/\n+$/,"")}
|
|
6
|
+
`}function H(e){let t=y(y(e).data);return z(t,"company")}function W(e){let t=y(y(e).data);return z(t,"site")}function X(e,t){let r=b(y(e).data);if(r.length===0)return`Nothing is listed.
|
|
7
|
+
`;if(t==="countries"){let i=["code name sites"];for(let o of r){let a=d(o.code),c=d(o.name),u=$(o.count)||"0";(a||c)&&i.push(`${a.padEnd(5)}${c} ${u}`)}return`${i.join(`
|
|
8
|
+
`)}
|
|
9
|
+
`}return`${r.map(i=>{let o=d(i.slug),a=d(i.name);return o&&a?`${o} \u2014 ${a}`:o||a}).filter(i=>i.length>0).join(`
|
|
10
|
+
`)}
|
|
11
|
+
`}function z(e,t){let r=[];r.push(d(e.name)||(t==="company"?"Company":"Site"));let n=d(e.id);n&&r.push(n);let i=[d(e.providerType),d(e.level)].filter(f=>f.length>0);i.length>0&&r.push(i.join(" \xB7 "));let o=d(e.summary)||Ge(e.published);o&&r.push("",o);let a=K(e.websites);if(a.length>0&&r.push("",...a),t==="site"){let f=Ye(e.company);f&&r.push("",f);let l=F(e.location);l&&r.push(l)}else{let f=b(e.sites);if(f.length===0)r.push("","No sites are listed.");else{r.push("","Sites");for(let l of f.slice(0,20)){let m=d(l.name)||"Site",p=F(l.location);r.push(` ${p?`${p} \u2014 ${m}`:m}`)}f.length>20&&r.push(` ${f.length-20} more. Use --json for the full record.`)}}Ue(r,e.claims),De(r,e.unknowns);let c=d(e.url);c&&r.push("",c);let u=d(e.notice);return u&&r.push("",u),`${r.join(`
|
|
12
|
+
`)}
|
|
13
|
+
`}function Ue(e,t){let r=b(t);if(r.length!==0){e.push("","Claims");for(let n of r.slice(0,15)){let i=d(n.label);if(!i)continue;let o=d(n.scope);e.push(` ${o?`${i} (${o})`:i}`)}r.length>15&&e.push(` ${r.length-15} more. Use --json for the full record.`)}}function De(e,t){if(!Array.isArray(t)||t.length===0)return;let r=t.map(n=>typeof n=="string"?n.trim():h(n)?d(n.label)||d(n.name)||d(n.detail):"").filter(n=>n.length>0);r.length!==0&&e.push("","Unknown",...r.slice(0,10).map(n=>` ${n}`))}function Ve(e,t){let r=h(t.meta)?t.meta:void 0,n=r&&h(r.facets)?r.facets:void 0;if(!n)return;let i=[];for(let[o,a]of Object.entries(n)){let u=b(a).slice(0,8).map(f=>{let l=d(f.label)||d(f.value),m=$(f.count);return l?m?`${l} (${m})`:l:""}).filter(f=>f.length>0);u.length>0&&i.push(` ${o}: ${u.join(", ")}`)}i.length>0&&e.push("Filters",...i,"")}function Be(e){let t=d(e.match),r=d(e.matchedOn);return t&&r?`${t} match on ${r}`:t?`${t} match`:""}function Fe(e){let t=[];for(let r of b(e)){let n=d(r.label);if(n&&!t.includes(n)&&t.push(n),t.length===6)break}return t}function Ge(e){return h(e)?d(e.description):""}function Ye(e){return h(e)?d(e.name):""}function F(e){return h(e)?[d(e.city),d(e.region),d(e.country)||d(e.countryCode)].filter(t=>t.length>0).join(", "):""}function Je(e){if(!h(e.meta))return;let t=e.meta.total;return typeof t=="number"&&Number.isFinite(t)?t:void 0}function y(e){return h(e)?e:{}}function b(e){return Array.isArray(e)?e.filter(h):[]}function K(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&t.trim().length>0):[]}function d(e){if(typeof e!="string")return"";let t=e.trim();return!t||G.test(t)?"":t}function $(e){return typeof e=="number"&&Number.isFinite(e)?String(e):""}function h(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Q(e,t,r){let n=!!t.isTTY;return{color:n&&x(t,r),interactive:!!(e.isTTY&&t.isTTY),show:n,columns:t.columns&&t.columns>20?t.columns:80}}function x(e,t){return t.NO_COLOR||t.TERM==="dumb"?!1:!!e.isTTY}function He(e,t){let r=e%18,n="";for(let i=0;i<14;i+=1){let o=i<=r&&i>r-4;t?o?n+="\x1B[36m\u2501\x1B[0m":n+="\x1B[2m\xB7\x1B[0m":n+=o?"=":"."}return n}function T(e,t,r){if(!e.isTTY)return{stop(){}};let n=!1,i=0,o=()=>{e.write(`\r\x1B[2K${t} ${He(i,r)}`),i+=1};e.write("\x1B[?25l"),o();let a=setInterval(o,70);return a.unref(),{stop(c="clear"){n||(n=!0,clearInterval(a),c==="keep"?e.write(`\r\x1B[2K${t}
|
|
14
|
+
\x1B[?25h`):e.write("\r\x1B[2K\x1B[?25h"))}}}function Z(e,t){let r=We(e,Math.min(t.columns,78)-4);if(t.color){let n="\x1B[2m\u2502\x1B[0m",i=r.split(`
|
|
15
|
+
`).map(o=>`${n} ${o}`);return`
|
|
16
|
+
\x1B[1m\u250C Physical Validation\x1B[0m
|
|
17
|
+
${n}
|
|
18
|
+
${i.join(`
|
|
19
|
+
`)}
|
|
20
|
+
${n}
|
|
21
|
+
`}return`Physical Validation
|
|
22
|
+
|
|
23
|
+
Request:
|
|
24
|
+
${r}
|
|
25
|
+
|
|
26
|
+
`}function S(e,t){return t?`\x1B[31m${e}\x1B[0m
|
|
27
|
+
`:`${e}
|
|
28
|
+
`}function We(e,t){let r=Math.max(20,t),n=[];for(let i of e.split(`
|
|
29
|
+
`)){let o=i;if(o.length<=r){n.push(o);continue}for(;o.length>r;){let a=o.lastIndexOf(" ",r);a<=0&&(a=r),n.push(o.slice(0,a).trimEnd()),o=o.slice(a).trimStart()}n.push(o)}return n.join(`
|
|
30
|
+
`)}var Xe=/^(?:provider|archive|listed):[A-Za-z0-9_-]{1,120}$/;async function ee(e,t,r,n){e.command==="company"&&te(e.id),e.command==="site"&&ne(e.id);let i=e.command==="search"?"Searching Physical Validation...":"Loading from Physical Validation...",o=T(t.stdout,i,n.color);try{let a=await ze(e,r);return o.stop(),t.stdout.write(Ke(e,a)),0}catch(a){throw o.stop(),a}}async function ze(e,t){switch(e.command){case"search":return t.search({...e.query?{q:e.query}:{},service:e.service,type:e.type,country:e.country,region:e.region,modality:e.modality,quality:e.quality,equipment:e.equipment,...e.sort?{sort:e.sort}:{},...e.limit?{limit:e.limit}:{},...e.cursor?{cursor:e.cursor}:{},...e.facets?{facets:!0}:{}});case"company":return t.company(te(e.id));case"site":return t.site(ne(e.id));case"services":return t.services();case"techniques":return t.techniques();case"countries":return t.countries();default:throw new s("See --help for usage.",2,"usage")}}function Ke(e,t){if(e.json)return Y(t);if(e.command==="search")return J(t);if(e.command==="company")return H(t);if(e.command==="site")return W(t);if(e.command==="services"||e.command==="techniques"||e.command==="countries")return X(t,e.command);throw new s("See --help for usage.",2,"usage")}function te(e){if(!e||!Xe.test(e))throw new s("Pass a company id from search, such as listed:org_example.",2,"usage");return e}function ne(e){if(!e||e.length>200||e.includes("/")||e.includes("\\")||e.includes(".."))throw new s("Pass the site id from a company lookup.",2,"usage");if(e.includes("%")||e.includes("?")||e.includes("#")||/\s/.test(e))throw new s("Pass the site id from a company lookup.",2,"usage");return e}import{mkdirSync as Qe,readFileSync as Ze,writeFileSync as et}from"fs";import{tmpdir as tt}from"os";import{join as _}from"path";var C=3e4,re="cooldown.json";function N(e){let t=e.PHYSICALVALIDATION_COOLDOWN_MS;if(t===void 0||t.trim()===""||!/^\d+$/.test(t.trim()))return C;let r=Number(t.trim());return Number.isFinite(r)?r:C}function ie(e){let t=e.PHYSICALVALIDATION_STATE_DIR?.trim();return t||_(tt(),"physicalvalidation")}function oe(e,t=Date.now()){return Math.max(0,se(ie(e))-t)}function I(e,t,r=Date.now()){if(t>0)try{let n=ie(e),i=Math.max(se(n),r+t);Qe(n,{recursive:!0}),et(_(n,re),JSON.stringify({nextAt:i}),{mode:384})}catch{}}function se(e){try{let t=JSON.parse(Ze(_(e,re),"utf8"));return typeof t.nextAt=="number"&&Number.isFinite(t.nextAt)?t.nextAt:0}catch{return 0}}var q="https://physicalvalidation.com/api/v1",ae="Received. A person at Physical Validation will review it. Nothing else happens automatically.",ce="Beaming your request to Physical Validation...",ue="email: ",de="code: ";function L(e){return`physicalvalidation ${e}
|
|
31
|
+
|
|
32
|
+
Search providers and capabilities, or send a request for a person to review.
|
|
33
|
+
Nothing is sent to a provider automatically.
|
|
34
|
+
|
|
35
|
+
Usage:
|
|
36
|
+
physicalvalidation search [text] [filters]
|
|
37
|
+
physicalvalidation company <id>
|
|
38
|
+
physicalvalidation site <id>
|
|
39
|
+
physicalvalidation services
|
|
40
|
+
physicalvalidation techniques
|
|
41
|
+
physicalvalidation countries
|
|
42
|
+
physicalvalidation "<request>"
|
|
43
|
+
physicalvalidation --email <email> --code <digits> "<request>"
|
|
44
|
+
echo "<request>" | physicalvalidation --email <email> --code <digits>
|
|
45
|
+
|
|
46
|
+
Search filters:
|
|
47
|
+
--service <value> Repeatable. A value from \`services\` or the facets.
|
|
48
|
+
--type <value> CRO, CDMO, or Research institute. Repeatable.
|
|
49
|
+
--country <code> Two-letter country code, such as US. Repeatable.
|
|
50
|
+
--region <value> Repeatable.
|
|
51
|
+
--modality <value> Repeatable.
|
|
52
|
+
--quality <value> Such as GLP or GMP. Repeatable.
|
|
53
|
+
--equipment <value> Repeatable.
|
|
54
|
+
--sort <value> relevance (default), name, or completeness.
|
|
55
|
+
--limit <n> Page size from 1 to 50. Default 10.
|
|
56
|
+
--cursor <token> next_cursor from the previous page.
|
|
57
|
+
--facets Include filter counts.
|
|
58
|
+
--json Print the API JSON for search and lookup.
|
|
59
|
+
|
|
60
|
+
Request options:
|
|
61
|
+
--email <email> Prompted on a terminal. Required otherwise.
|
|
62
|
+
--code <digits> 6-digit code. Prompted on a terminal. Required otherwise.
|
|
63
|
+
|
|
64
|
+
Other:
|
|
65
|
+
--api <url> API base URL (default: ${q})
|
|
66
|
+
-h, --help Show this help
|
|
67
|
+
-V, --version Show the version
|
|
68
|
+
|
|
69
|
+
Environment:
|
|
70
|
+
PHYSICALVALIDATION_API API base URL (--api wins if both are set)
|
|
71
|
+
NO_COLOR Disable color
|
|
72
|
+
|
|
73
|
+
Examples:
|
|
74
|
+
npx physicalvalidation search "peptide bioanalysis" --country US
|
|
75
|
+
npx physicalvalidation company <id> --json
|
|
76
|
+
npx physicalvalidation services
|
|
77
|
+
npx physicalvalidation "GLP bioanalysis for a peptide, US site"
|
|
78
|
+
bunx physicalvalidation "Stability study for an mRNA-LNP, EU site"
|
|
79
|
+
pnpm dlx physicalvalidation "Peptide characterization, GMP, US"
|
|
80
|
+
|
|
81
|
+
On a terminal, a request shows the text, asks for an email, then asks for the
|
|
82
|
+
6-digit code from that email. Up to five code attempts are allowed. The only
|
|
83
|
+
data sent is the request text, that email, and that code. The CLI does not
|
|
84
|
+
run a model. A person at Physical Validation reviews the request.
|
|
85
|
+
`}var nt=new Set(["json","facets"]),le=new Set(["service","type","country","region","modality","quality","equipment"]),rt=new Set(["api","email","code","sort","limit","cursor"]),it=new Set(["search","company","site","services","capabilities","techniques","countries"]),ot=new Set(["relevance","name","completeness"]);function me(e){if(e.some(i=>i==="-h"||i==="--help"))return O({help:!0});if(e.some(i=>i==="-V"||i==="--version"))return O({version:!0});let t=O(),r=[],n=!1;for(let i=0;i<e.length;i+=1){let o=e[i];if(o===void 0)continue;if(o==="--"){r.length===0&&(n=!0),r.push(...e.slice(i+1));break}if(!o.startsWith("-")){r.push(o);continue}if(!o.startsWith("--"))throw new s(`Unknown option: ${o}. See --help for usage.`,2,"usage");let a=o.indexOf("="),c=a===-1?o:o.slice(0,a),u=c.slice(2),f=a===-1?void 0:o.slice(a+1);if(nt.has(u)){if(f!==void 0)throw new s(`--${u} does not take a value.`,2,"usage");u==="json"&&(t.json=!0),u==="facets"&&(t.facets=!0);continue}if(!le.has(u)&&!rt.has(u))throw new s(`Unknown option: ${c}. See --help for usage.`,2,"usage");let l=f;if(l===void 0){let m=e[i+1];if(m===void 0||m.startsWith("-")&&m!=="-")throw new s(`Missing value for --${u}.`,2,"usage");l=m,i+=1}st(t,u,l)}return ct(t,r,n),ut(t),t}function he(e){let t=(e??q).trim(),r;try{r=new URL(t)}catch{throw new s("Pass an http or https URL to --api.",2,"usage")}if(r.protocol!=="http:"&&r.protocol!=="https:")throw new s("Pass an http or https URL to --api.",2,"usage");if(r.username||r.password)throw new s("The API URL cannot include a username or password.",2,"usage");return r.hash="",r.search="",r.toString().replace(/\/$/,"")}function M(e){return e.length<=254&&/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}function j(e){return/^\d{6}$/.test(e)}function pe(e){let t="";for(let r=0;r<e.length;r+=1){let n=e.charCodeAt(r);if(n===27){r=ft(e,r);continue}n<=8||n===11||n===12||n>=14&&n<=31||n===127||(t+=e[r])}return t.trim()}function O(e={}){return{help:!1,version:!1,json:!1,facets:!1,command:"intake",service:[],type:[],country:[],region:[],modality:[],quality:[],equipment:[],...e}}function st(e,t,r){if(t==="api"&&(e.api=r),t==="email"&&(e.email=r),t==="code"&&(e.code=r),t==="sort"&&(e.sort=r),t==="limit"&&(e.limit=r),t==="cursor"&&(e.cursor=r),!le.has(t))return;let n=t==="country"||t==="type"?r.split(","):[r],i=at(e,t);for(let o of n){let a=o.trim();a&&i.push(a)}}function at(e,t){return t==="service"?e.service:t==="type"?e.type:t==="country"?e.country:t==="region"?e.region:t==="modality"?e.modality:t==="quality"?e.quality:e.equipment}function ct(e,t,r){let n=t[0];if(!r&&n&&it.has(n)){let i=t.slice(1),o=n==="capabilities"?"services":n;if(e.command=o,o==="search"){let a=i.join(" ").trim();a&&(e.query=a);return}if(o==="company"||o==="site"){if(i.length!==1)throw new s(o==="company"?"Pass one company id. See --help for usage.":"Pass one site id. See --help for usage.",2,"usage");e.id=i[0];return}if(i.length>0)throw new s(`${o} does not take extra text. See --help for usage.`,2,"usage");return}e.command="intake",t.length>0&&(e.text=t.join(" "))}function ut(e){if(e.help||e.version)return;let t=dt(e);if(e.command==="intake"&&e.json)throw new s("--json is for search and lookup. See --help for usage.",2,"usage");if(e.command!=="search"&&t)throw new s("Those options are for search. See --help for usage.",2,"usage");if(e.command!=="intake"&&(e.email!==void 0||e.code!==void 0))throw new s("--email and --code are only for sending a request. See --help for usage.",2,"usage");if(e.command!=="search")return;let r=e.query??"";if(r.length>500)throw new s(`Keep the search under ${500} characters.`,2,"usage");if(!r&&!t)throw new s("Pass the search text or a filter such as --country US. See --help for usage.",2,"usage");if(e.sort!==void 0){let n=e.sort.toLowerCase();if(!ot.has(n))throw new s("Pass relevance, name, or completeness to --sort.",2,"usage");e.sort=n}if(e.limit!==void 0&&(!/^\d+$/.test(e.limit)||Number(e.limit)<1||Number(e.limit)>50))throw new s("Pass a page size from 1 to 50 to --limit.",2,"usage");if(e.cursor!==void 0&&(e.cursor.length>4e3||/\s/.test(e.cursor)))throw new s("That page cursor is not valid. Search again without --cursor.",2,"usage");e.country=e.country.map(n=>{if(!/^[A-Za-z]{2}$/.test(n))throw new s("Country codes are two letters, such as US.",2,"usage");return n.toUpperCase()});for(let n of[...e.service,...e.type,...e.region,...e.modality,...e.quality,...e.equipment])if(n.length>200)throw new s("That filter is too long.",2,"usage")}function dt(e){return e.facets||e.sort!==void 0||e.limit!==void 0||e.cursor!==void 0||e.service.length>0||e.type.length>0||e.country.length>0||e.region.length>0||e.modality.length>0||e.quality.length>0||e.equipment.length>0}function ft(e,t){if(e[t+1]!=="[")return t;let r=t+2;for(;r<e.length;){let n=e.charCodeAt(r);if(n>=64&&n<=126)return r;r+=1}return e.length-1}var mt=350,ht=64*1024;async function we(e,t){let r="intake";try{if(e.length===0)return t.stdout.write(L(t.version)),0;let n=me(e);if(r=n.command,n.help)return t.stdout.write(L(t.version)),0;if(n.version)return t.stdout.write(`physicalvalidation ${t.version}
|
|
86
|
+
`),0;let i=Q(t.stdin,t.stdout,t.env),o=he(n.api??t.env.PHYSICALVALIDATION_API),a=new A({base:o,fetch:t.fetch,version:t.version});if(n.command!=="intake")return await ee(n,t,a,i);let c=await gt(n.text,t);pt(t.env);let u=yt(n.email,n.code,i.interactive);i.show&&t.stdout.write(Z(c,i));let f=u.email??await bt(t),l=Date.now(),m=T(t.stdout,ce,i.color),p;try{p=await a.create(c,f)}catch(g){throw m.stop(),g}if(I(t.env,N(t.env)),i.show){let g=mt-(Date.now()-l);g>0&&await vt(g)}return m.stop("keep"),i.show&&t.stdout.write(i.color?`\x1B[32mCode sent.\x1B[0m
|
|
87
|
+
`:`Code sent.
|
|
88
|
+
`),await xt(a,p.id,u.code,t,i),i.show&&t.stdout.write(`
|
|
89
|
+
`),i.color&&t.stdout.write("\x1B[32m\u2713\x1B[0m "),t.stdout.write(`${ae}
|
|
90
|
+
`),0}catch(n){r==="intake"&&n instanceof s&&n.kind==="rate_limit"&&n.retryAfterSeconds!==void 0&&I(t.env,Math.max(N(t.env),n.retryAfterSeconds*1e3));let i=n instanceof s?n:new s("Something went wrong. Try again in a moment.",1,"unexpected");return t.stderr.write(S(i.message,x(t.stderr,t.env))),i.exitCode}}function pt(e){let t=oe(e);if(t<=0)return;let r=Math.max(1,Math.ceil(t/1e3)),n=r===1?"second":"seconds";throw new s(`Wait ${r} ${n} before sending another request.`,1,"rate_limit")}async function gt(e,t){let r=e!==void 0?e:t.stdin.isTTY?void 0:await wt(t.stdin);if(r===void 0)throw new s("Pass the request text, or pipe it on stdin. See --help for usage.",2,"usage");let n=pe(r);if(!n)throw new s("The request text is empty.",2,"usage");if(n.length>4e3)throw new s(`The request is too long. Keep it under ${4e3} characters.`,2,"usage");return n}async function wt(e){let t=[],r=0;for await(let n of e){let i=Buffer.isBuffer(n)?n:Buffer.from(n);if(r+=i.length,r>ht)throw new s("The request is too long.",2,"usage");t.push(i)}return Buffer.concat(t).toString("utf8")}function yt(e,t,r){let n=e?.trim(),i=t?.trim();if(e!==void 0&&!M(n??""))throw new s("Enter a valid email address.",2,"usage");if(t!==void 0&&!j(i??""))throw new s("Enter the 6-digit code from the email.",2,"usage");if(!r){if(!n)throw new s("Pass --email when this is not a terminal. See --help for usage.",2,"usage");if(!i)throw new s("Pass --code when this is not a terminal. See --help for usage.",2,"usage")}return{...n?{email:n}:{},...i?{code:i}:{}}}async function bt(e){for(let t=0;t<5;t+=1){let r=(await ye(e,ue)).trim();if(M(r))return r;e.stderr.write(S("Enter a valid email address.",x(e.stderr,e.env)))}throw new s("Enter a valid email address.",2,"usage")}async function xt(e,t,r,n,i){let o=r,a=0,c=0;for(;a<5;){let u=o;if(o=void 0,!u){if(!i.interactive)throw new s("Pass --code when this is not a terminal. See --help for usage.",2,"usage");u=(await ye(n,de)).trim()}if(!j(u)){c+=1;let l="Enter the 6-digit code from the email.";if(!i.interactive||c>=5)throw new s(l,2,"usage");n.stderr.write(S(l,x(n.stderr,n.env)));continue}a+=1;let f=T(n.stdout,"Checking code...",i.color);try{await e.verify(t,u);return}catch(l){if(!(l instanceof s)||l.kind!=="invalid_code")throw l;if(!i.interactive||a>=5)throw new s(a>=5?"That code does not match. Too many tries. Run the command again to request a new code.":"That code does not match.",1,"invalid_code");let m=5-a;n.stderr.write(S(`That code does not match. ${m} ${m===1?"try":"tries"} left.`,x(n.stderr,n.env)))}finally{f.stop()}}throw new s("That code does not match. Too many tries. Run the command again to request a new code.",1,"invalid_code")}async function ye(e,t){if(e.ask)return e.ask(t);let r=lt({input:e.stdin,output:e.stdout});try{return await new Promise((n,i)=>{let o=!1,a=c=>{o||(o=!0,c())};r.once("SIGINT",()=>{a(()=>i(new s("Cancelled.",130,"cancelled")))}),r.question(t).then(c=>a(()=>n(c)),c=>a(()=>i(c)))})}finally{r.close()}}function vt(e){return new Promise(t=>{setTimeout(t,e)})}var be=Number.parseInt(process.versions.node.split(".")[0]??"",10);(!Number.isFinite(be)||be<18)&&(process.stderr.write(`physicalvalidation needs Node.js 18 or newer.
|
|
91
|
+
`),process.exit(1));process.on("SIGINT",()=>{process.stdout.isTTY&&process.stdout.write(`\x1B[?25h
|
|
92
|
+
`),process.exit(130)});var xe=()=>{process.stderr.write(`Something went wrong. Try again in a moment.
|
|
93
|
+
`),process.exit(1)};process.on("uncaughtException",xe);process.on("unhandledRejection",xe);var ve=await we(process.argv.slice(2),{stdin:process.stdin,stdout:process.stdout,stderr:process.stderr,env:process.env,fetch:globalThis.fetch,version:"0.1.0"});process.exitCode=ve;setImmediate(()=>{process.exit(ve)});
|
package/package.json
CHANGED
|
@@ -1,6 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "physicalvalidation",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Search Physical Validation providers and capabilities, and send a request for a person to review.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"physical-validation",
|
|
7
|
+
"cli",
|
|
8
|
+
"cro",
|
|
9
|
+
"cdmo",
|
|
10
|
+
"laboratory",
|
|
11
|
+
"sourcing",
|
|
12
|
+
"capabilities"
|
|
13
|
+
],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"bin": {
|
|
17
|
+
"physicalvalidation": "dist/cli.js"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md",
|
|
22
|
+
"LICENSE"
|
|
23
|
+
],
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=18"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/Halmoslabs/physicalvalidation.git"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://physicalvalidation.com",
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/Halmoslabs/physicalvalidation/issues"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsup && chmod +x dist/cli.js",
|
|
40
|
+
"typecheck": "tsc --noEmit",
|
|
41
|
+
"lint": "eslint .",
|
|
42
|
+
"test": "vitest run",
|
|
43
|
+
"prepublishOnly": "npm run build && npm test",
|
|
44
|
+
"prepack": "npm run build",
|
|
45
|
+
"pack:dry": "npm pack --dry-run",
|
|
46
|
+
"bench": "node scripts/bench-help.mjs"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@eslint/js": "^10.0.1",
|
|
50
|
+
"@types/node": "^26.6.6",
|
|
51
|
+
"eslint": "^10.14.0",
|
|
52
|
+
"tsup": "^9.0.0",
|
|
53
|
+
"typescript": "^6.0.3",
|
|
54
|
+
"vitest": "^5.0.5",
|
|
55
|
+
"typescript-eslint": "^8.72.1"
|
|
56
|
+
}
|
|
57
|
+
}
|