@ideal-postcodes/cli 1.0.0 → 1.0.1
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/cli.cjs
CHANGED
|
@@ -15,7 +15,7 @@ Link expires at ${C.expires_at}. This terminal will resume automatically.
|
|
|
15
15
|
`),a&&(h=$.spinner(),h.start("Waiting for signup completion"));let _=Date.now(),v=_;for(;;){if(f)throw new c("interrupted","Signup interrupted. Re-run `idpc auth signup` to resume.");if(Date.now()-_>=s)throw new c("timeout",`Signup polling timed out after ${Math.round(s/1e3)}s.`);let K=await Lt(o,C.cli_token);if(K.status==="expired")throw new c("signup_expired","Signup link expired. Please re-run `idpc auth signup`.");if(K.status==="ready"){h?.stop("Signup complete");let N=M({api_key:K.data.test_api_key,user_token:K.data.user_token});m({success:!0,config_path:N,email:k.email,user_id:K.data.user_id},{json:n}),a&&$.outro(`Signed in as ${k.email}`);return}if(!a&&n){let N=Date.now();N-v>=3e4&&(v=N,process.stderr.write(`${JSON.stringify({event:"waiting",elapsed_sec:Math.round((N-_)/1e3)})}
|
|
16
16
|
`))}try{await Ht(r,d.signal)}catch{}}}catch(k){if(h?.stop("Signup did not complete",1),k instanceof c){U({code:k.code,message:k.message,details:k.details},{json:n,exitCode:Mt(k.code)});return}u(k,{json:n})}finally{process.off("SIGINT",w)}},_e=new we.Command("signup").description("Create a new Ideal Postcodes account and store its test API key").option("--email <email>","Account holder email").option("--name <name>","Account holder full name").option("--org-name <name>","Organisation name").option("--org-address-line-one <line>","Organisation address line 1").option("--org-address-line-two <line>","Organisation address line 2").option("--org-address-line-three <line>","Organisation address line 3").option("--org-post-town <town>","Organisation post town").option("--org-postcode <postcode>","Organisation postcode").option("--org-country-code <iso2>","Organisation country code (ISO 3166-1 alpha-2)").action(async(e,t)=>{let{globals:o,json:n}=l(t),r=o.baseUrl??W;await Jt(e,{baseUrl:r,json:n})});var Ce=require("commander");var be=new Ce.Command("whoami").description("Show resolved credentials and verify the API key").action(async(e,t)=>{let{globals:o,json:n}=l(t),r=G(o.apiKey),s=A(o.userToken),i={api_key:r?{source:r.source,preview:r.value.slice(0,6)+"\u2026"}:null,user_token:s?{source:s.source,preview:s.value.slice(0,6)+"\u2026"}:null};if(!r){m({...i,live:!1},{json:n});return}try{let{available:a}=await O(g(o));m({...i,live:!0,available:a},{json:n})}catch(a){u(a,{json:n})}});var xe=new ve.Command("auth").description("Manage Ideal Postcodes credentials").addCommand(ye).addCommand(ke).addCommand(_e).addCommand(be);var Ue=require("commander");var Se=require("fs");var Ft=async()=>await new Promise((e,t)=>{let o="";process.stdin.setEncoding("utf-8"),process.stdin.on("data",n=>{o+=n}),process.stdin.on("end",()=>e(o)),process.stdin.on("error",t)}),Ee=e=>e.split(/\r?\n/).map(t=>t.trim()).filter(Boolean),I=async(e,t)=>{if(t.file)return Ee((0,Se.readFileSync)(t.file,"utf-8"));if(t.stdin)return Ee(await Ft());if(!e)throw new c("missing_argument","Provide a query, --file <path>, or --stdin.");return[e]};var Pe=require("fs");var Te=require("fast-csv"),Bt=e=>e==null?"":String(e),Re=e=>e.map(Bt),Ae=async(e,t)=>(0,Te.writeToString)([Re(e),...t.map(Re)],{rowDelimiter:`\r
|
|
17
17
|
`,includeEndRowDelimiter:!0});var Yt=new Set(["auth_failed","forbidden"]),Vt=e=>e instanceof c?{code:e.code,message:e.message}:{code:"unexpected_error",message:e instanceof Error?e.message:String(e)},q=async(e,t,o)=>{if(!o.batchMode){let r=await t(e[0]);m({query:e[0],response:r},{json:o.json});return}let n=[];for(let r of e)try{n.push({query:r,response:await t(r)})}catch(s){if(s instanceof c&&Yt.has(s.code))throw s;n.push({query:r,error:Vt(s)})}if(!o.json){let r=n.map(i=>"error"in i?o.errorRow(i.query,i.error.message):o.toRow(i.query,i.response)),s=await Ae(o.headers,r);o.out?((0,Pe.writeFileSync)(o.out,s,"utf-8"),process.stderr.write(`Wrote ${r.length} rows to ${o.out}
|
|
18
|
-
`)):process.stdout.write(s);return}m(n.length===1?n[0]:{count:n.length,results:n},{json:o.json})};var Z=["query","status","full_address","confidence","fit","line_1","line_2","line_3","post_town","postcode","postcode_match","premise_match","thoroughfare_match","locality_match","post_town_match","organisation_match","latitude","longitude","uprn","udprn","id","language","country_iso","country_iso_2","organisation_name","department_name","po_box","premise","building_name","building_number","sub_building_name","county"],H=(e,t)=>typeof e=="number"&&Number.isFinite(e)?Number(e.toFixed(t)):e,Wt=e=>e==null?"":String(e),Qt=e=>[e.line_1,e.line_2,e.line_3,e.post_town,e.postcode].filter(t=>typeof t=="string"&&t.length>0).join(", "),Xt=()=>Array(Z.length).fill(""),ee=(e,t)=>{let o=Xt();return o[0]=e,o[1]=`Error: ${t}`,o},Oe=(e,t)=>{let o=t?.match;return!t||!o?ee(e,"No match"):[e,"Success",Qt(o),H(t.confidence,2),H(t.fit,2),o.line_1,o.line_2,o.line_3,o.post_town,o.postcode,t.postcode_match,t.premise_match,t.thoroughfare_match,t.locality_match,t.post_town_match,t.organisation_match,H(o.latitude,6),H(o.longitude,6),Wt(o.uprn),o.udprn,o.id,o.language,o.country_iso,o.country_iso_2,o.organisation_name,o.department_name,o.po_box,o.premise,o.building_name,o.building_number,o.sub_building_name,o.county]};var $e=new Ue.Command("cleanse").description("Cleanse one or more addresses (POST /cleanse/addresses)").argument("[query]","Address string to cleanse").option("-f, --file <path>","Read one address per line from a file").option("--stdin","Read one address per line from stdin").option("-o, --out <path>","Write CSV output to a file (batch mode only)").option("--context <iso>","ISO country hint (e.g. GBR, USA)").action(async(e,t,o)=>{let{globals:n,json:r}=l(o);try{let s=g(n),i=await I(e,t),a=!!t.file||!!t.stdin;await q(i,async d=>(await p("/cleanse/addresses",{auth:s,method:"POST",query:{context:t.context,tags:"cli"},body:{query:d}})).data,{json:r,batchMode:a,out:t.out,headers:Z,toRow:(d,f)=>Oe(d,f?.result),errorRow:ee})}catch(s){u(s,{json:r})}});var Ke=require("commander"),y=x(require("picocolors"),1);var qe="@ideal-postcodes/cli";var De="1.0.
|
|
18
|
+
`)):process.stdout.write(s);return}m(n.length===1?n[0]:{count:n.length,results:n},{json:o.json})};var Z=["query","status","full_address","confidence","fit","line_1","line_2","line_3","post_town","postcode","postcode_match","premise_match","thoroughfare_match","locality_match","post_town_match","organisation_match","latitude","longitude","uprn","udprn","id","language","country_iso","country_iso_2","organisation_name","department_name","po_box","premise","building_name","building_number","sub_building_name","county"],H=(e,t)=>typeof e=="number"&&Number.isFinite(e)?Number(e.toFixed(t)):e,Wt=e=>e==null?"":String(e),Qt=e=>[e.line_1,e.line_2,e.line_3,e.post_town,e.postcode].filter(t=>typeof t=="string"&&t.length>0).join(", "),Xt=()=>Array(Z.length).fill(""),ee=(e,t)=>{let o=Xt();return o[0]=e,o[1]=`Error: ${t}`,o},Oe=(e,t)=>{let o=t?.match;return!t||!o?ee(e,"No match"):[e,"Success",Qt(o),H(t.confidence,2),H(t.fit,2),o.line_1,o.line_2,o.line_3,o.post_town,o.postcode,t.postcode_match,t.premise_match,t.thoroughfare_match,t.locality_match,t.post_town_match,t.organisation_match,H(o.latitude,6),H(o.longitude,6),Wt(o.uprn),o.udprn,o.id,o.language,o.country_iso,o.country_iso_2,o.organisation_name,o.department_name,o.po_box,o.premise,o.building_name,o.building_number,o.sub_building_name,o.county]};var $e=new Ue.Command("cleanse").description("Cleanse one or more addresses (POST /cleanse/addresses)").argument("[query]","Address string to cleanse").option("-f, --file <path>","Read one address per line from a file").option("--stdin","Read one address per line from stdin").option("-o, --out <path>","Write CSV output to a file (batch mode only)").option("--context <iso>","ISO country hint (e.g. GBR, USA)").action(async(e,t,o)=>{let{globals:n,json:r}=l(o);try{let s=g(n),i=await I(e,t),a=!!t.file||!!t.stdin;await q(i,async d=>(await p("/cleanse/addresses",{auth:s,method:"POST",query:{context:t.context,tags:"cli"},body:{query:d}})).data,{json:r,batchMode:a,out:t.out,headers:Z,toRow:(d,f)=>Oe(d,f?.result),errorRow:ee})}catch(s){u(s,{json:r})}});var Ke=require("commander"),y=x(require("picocolors"),1);var qe="@ideal-postcodes/cli";var De="1.0.1";var J=qe,F=De;var je=e=>e instanceof Error?e.message:String(e),zt=e=>{let t=[];return e.lookups_remaining===0&&t.push("No lookups remaining \u2014 top up the key balance"),e.daily_limit.limit!==null&&e.daily_limit.consumed>=e.daily_limit.limit&&t.push(`Daily limit reached (${e.daily_limit.consumed}/${e.daily_limit.limit})`),e.monthly_limit.limit!==null&&e.monthly_limit.consumed>=e.monthly_limit.limit&&t.push(`Monthly limit reached (${e.monthly_limit.consumed}/${e.monthly_limit.limit})`),e.allowed_urls.length>0&&t.push(`Allowed URLs are set (${e.allowed_urls.length}); the CLI sends no Origin, so the key always reports unusable here. This is expected \u2014 the key still works from its permitted URLs.`),t.length===0&&t.push("Key reports unusable but no balance, limit, or allowed-URL cause was found."),t},Zt=e=>{let t=[];t.push(y.default.bold(`${e.cli.name} v${e.cli.version}`)),t.push(` ${y.default.dim("node")} ${e.runtime.node} (${e.runtime.platform}/${e.runtime.arch})`),t.push(` ${y.default.dim("config")} ${e.config.path}`);let o=n=>n?`${y.default.green("\u2713")} ${n.source}`:y.default.gray("not set");if(t.push(` ${y.default.dim("api key")} ${o(e.credentials.api_key)}`),t.push(` ${y.default.dim("token")} ${o(e.credentials.user_token)}`),e.connectivity.reachable===null)return t.push(` ${y.default.dim("api")} ${y.default.gray("skipped (no api key)")}`),t.join(`
|
|
19
19
|
`);if(e.connectivity.reachable===!1)return t.push(` ${y.default.dim("api")} ${y.default.red("\u2717")} ${e.connectivity.error??"unreachable"}`),t.join(`
|
|
20
20
|
`);e.key.available===!0?t.push(` ${y.default.dim("key")} ${y.default.green("\u2713 usable")}`):t.push(` ${y.default.dim("key")} ${y.default.red("\u2717 not usable")}`),e.key.lookups_remaining!==void 0&&t.push(` ${y.default.dim("balance")} ${e.key.lookups_remaining} lookups remaining`);for(let n of e.key.diagnosis)t.push(` ${y.default.red("\u2717")} ${n}`);for(let n of e.key.warnings)t.push(` ${y.default.yellow("!")} ${n}`);return t.join(`
|
|
21
21
|
`)},Ne=new Ke.Command("doctor").description("Print environment info, verify connectivity, and check key usability").action(async(e,t)=>{let{globals:o,json:n}=l(t),r=G(o.apiKey),s=A(o.userToken),i=null,a,d=null,f,w=[],h=[];if(r)try{let C=await O({apiKey:r.value});if(i=!0,d=C.available,s)try{let _=await me({apiKey:r.value,userToken:s.value});f=_.lookups_remaining;let v=_.notifications.balance_threshold;_.lookups_remaining>0&&v!==null&&_.lookups_remaining<=v&&h.push(`Low balance: ${_.lookups_remaining} lookups remaining (threshold ${v})`),d||w.push(...zt(_))}catch(_){let v=`Could not read key details (user token rejected?): ${je(_)}`;d?h.push(v):w.push(v)}else h.push("No user token set \u2014 run `idpc auth login` with a user token to check balance, limits, and full key status.")}catch(C){i=!1,a=je(C)}let k={cli:{name:J,version:F},runtime:{node:process.version,platform:process.platform,arch:process.arch},config:{path:S()},credentials:{api_key:r?{source:r.source}:null,user_token:s?{source:s.source}:null},connectivity:{reachable:i,error:a},key:{available:d,lookups_remaining:f,diagnosis:w,warnings:h}};m(k,{json:n,human:Zt})});var Ge=require("commander");var te=["query","status","result","deliverable","disposable","free","role","catchall","suggestions"],eo=()=>Array(te.length).fill(""),oe=(e,t)=>{let o=eo();return o[0]=e,o[1]=`Error: ${t}`,o},Le=(e,t)=>t?[e,"Success",t.result,t.deliverable,t.disposable,t.free,t.role,t.catchall,(t.suggestions??[]).join("; ")]:oe(e,"No result");var Me=new Ge.Command("email").description("Validate one or more email addresses (GET /emails)").argument("[query]","Email address to validate").option("-f, --file <path>","Read one email per line from a file").option("--stdin","Read one email per line from stdin").option("-o, --out <path>","Write CSV output to a file (batch mode only)").action(async(e,t,o)=>{let{globals:n,json:r}=l(o);try{let s=g(n),i=await I(e,t),a=!!t.file||!!t.stdin;await q(i,async d=>(await p("/emails",{auth:s,method:"GET",query:{query:d,tags:"cli"}})).data,{json:r,batchMode:a,out:t.out,headers:te,toRow:(d,f)=>Le(d,f?.result),errorRow:oe})}catch(s){u(s,{json:r})}});var He=require("commander"),B=x(require("picocolors"),1);var to=e=>e.count===0?B.default.gray("no suggestions"):e.suggestions.map((t,o)=>` ${B.default.dim(String(o+1).padStart(2))} ${t.suggestion} ${B.default.dim(t.id)}`).join(`
|
package/package.json
CHANGED
|
@@ -165,3 +165,7 @@ idpc keys details
|
|
|
165
165
|
# Add an allowed URL
|
|
166
166
|
idpc keys configs update web --allowed-urls https://example.com,https://www.example.com
|
|
167
167
|
```
|
|
168
|
+
|
|
169
|
+
## Full documentation
|
|
170
|
+
|
|
171
|
+
The full Ideal Postcodes documentation — every guide, API reference, and integration — is available as a single file at [llms.txt](https://docs.ideal-postcodes.co.uk/llms.txt). Point your agent there for anything this skill doesn't cover.
|