nemar-cli 0.9.15-dev.2255 → 0.9.15-dev.2265
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/index.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -102,7 +102,7 @@ ${u.dim(`eta: ${e.eta}`)}`:"";process.stderr.write(`${t}
|
|
|
102
102
|
${r} ${e.message}
|
|
103
103
|
${n}${i}
|
|
104
104
|
${t}
|
|
105
|
-
`)}var Rz=!1;var sw=A(()=>{He()});var Oz;var Fz=A(()=>{Oz={name:"nemar-cli",version:"0.9.15-dev.2255",description:"CLI for NEMAR (Neuroelectromagnetic Data Archive and Tools Resource) dataset management",type:"module",main:"dist/index.js",bin:{nemar:"dist/index.js"},scripts:{dev:"bun run src/index.ts",build:"bun build src/index.ts --outdir dist --target bun --minify && sed '1s|#!/usr/bin/env node|#!/usr/bin/env bun|' dist/index.js > dist/index.js.tmp && mv dist/index.js.tmp dist/index.js",test:"bun test",lint:"biome check src/","lint:fix":"biome check --fix src/",format:"biome format --write src/",typecheck:"tsc --noEmit && tsc --noEmit -p backend",prepublishOnly:"bun run build",prepare:"husky",postinstall:"bun scripts/postinstall-check.mjs",deploy:"wrangler deploy",preview:"wrangler dev"},keywords:["nemar","bids","neuroimaging","eeg","emg","datalad","cli"],author:"NEMAR Team",license:"CC-BY-NC-ND-4.0",repository:{type:"git",url:"git+https://github.com/nemarOrg/nemar-cli.git"},bugs:{url:"https://github.com/nemarOrg/nemar-cli/issues"},homepage:"https://docs.nemar.org",engines:{bun:">=1.0.0"},files:["dist","scripts/postinstall-check.mjs","scripts/recover-datasets.json","scripts/withdrawn-datasets.json","README.md","LICENSE"],dependencies:{chalk:"^5.3.0",commander:"^12.1.0",conf:"^13.0.1","fuse.js":"^7.1.0",inquirer:"^9.2.15",ora:"^8.0.1",zod:"^3.23.8"},"lint-staged":{"src/**/*.{ts,tsx}":["biome check --fix"],"backend/src/**/*.{ts,tsx}":["biome check --fix"]},devDependencies:{"@biomejs/biome":"1.9.4","@types/bcryptjs":"^3.0.0","@types/bun":"latest","@types/inquirer":"^9.0.7",ajv:"^8.20.0","ajv-formats":"^3.0.1",bcryptjs:"^3.0.3",husky:"^9.1.7","lint-staged":"^16.3.2",typescript:"^5.5.4",wrangler:"^4.70.0",yaml:"^2.8.4"}}});var To;var k0=A(()=>{Fz();To=Oz.version});function U(e){if(e instanceof Error)return e.message;return String(e)}var j,No;var er=A(()=>{j=class j extends Error{statusCode;details;step;constructor(e,t,r,n){super(t);this.statusCode=e;this.details=r;this.step=n;this.name="ApiError"}};No=class No extends j{mode;eta;constructor(e,t,r,n){super(503,t,n);this.mode=e;this.eta=r;this.name="MaintenanceError"}}});function Az(){if(process.env.TEST_API_URL)return process.env.TEST_API_URL;if(aw)return ow;return ht().apiUrl||ow}async function P(e,t={},r=!1,n){let i=`${Az()}${e}`,s={"Content-Type":"application/json","X-CLI-Version":To,...t.headers};if(r){let c=ht();if(!c.apiKey&&r===!0)throw new j(401,"Not authenticated. Run 'nemar auth login' first.");if(c.apiKey)s.Authorization=`Bearer ${c.apiKey}`}let o;try{o=await fetch(i,{...t,headers:s})}catch(c){throw new j(0,`Network error: Could not connect to ${Az()}`,{originalError:c instanceof Error?c.message:String(c)})}let a;try{a=await o.json()}catch{throw new j(o.status,`Invalid response from server (status ${o.status})`)}if(!o.ok){if(o.status===503&&(a.mode==="read-only"||a.mode==="full")){let c=typeof a.message==="string"?a.message:"NEMAR is in maintenance mode. Please retry shortly.",l=typeof a.eta==="string"?a.eta:null,d=new No(a.mode,c,l,a.details);throw A0(d),d}throw new j(o.status,a.error||a.message||"Request failed",a.details,typeof a.step==="string"?a.step:void 0)}if(n){let c=n.safeParse(a);if(!c.success)throw new j(o.status,`Response for ${e} did not match the expected NEMAR contract`,{issues:c.error.issues});return c.data}return a}var ow="https://nemar-api-dev.sccn-org.workers.dev",aw;var Ns=A(()=>{Ts();sw();k0();er();aw=ow.includes("workers.dev")});async function kz(e,t){let r=new URLSearchParams;if(e)r.set("status",e);if(t)r.set("role",t);let n=r.toString()?`?${r.toString()}`:"";return P(`/admin/users${n}`,{},!0)}async function Pz(e){return P(`/admin/approve/${e}`,{method:"POST"},!0)}async function Iz(e){return P(`/admin/approve/by-id/${e}`,{method:"POST"},!0)}async function Tz(e){return P(`/admin/revoke/${e}`,{method:"POST"},!0)}async function Nz(e,t){return P(`/admin/users/${e}/role`,{method:"POST",body:JSON.stringify({role:t})},!0)}async function cw(e,t){return P(`/admin/datasets/${e}/visibility`,{method:"PATCH",body:JSON.stringify({visibility:t})},!0)}async function jz(e){return P(`/datasets/${e}/publish`,{method:"POST"},!0)}async function qz(e){return P(`/admin/datasets/${e}/ci`,{},!0)}async function Ai(e){return P(`/admin/datasets/${e}/ci`,{method:"POST"},!0)}async function uw(e){return P(`/admin/datasets/${e}/ci/validate`,{method:"POST"},!0)}async function lw(e){return P(`/admin/datasets/${e}/ci/sync`,{method:"POST"},!0)}async function Mz(e,t){return P(`/admin/datasets/${e}/doi/concept`,{method:"POST",body:JSON.stringify(t)},!0)}async function Dd(e){return P(`/admin/datasets/${e}/doi`,{},!0)}async function dw(e,t){return P(`/admin/datasets/${e}/doi/update`,{method:"POST",body:JSON.stringify(t)},!0)}async function Bz(e,t){return P(`/admin/datasets/${e}/withdraw`,{method:"POST",body:JSON.stringify({reason:t.reason,dry_run:t.dryRun})},!0)}async function Lz(e,t){return P(`/admin/datasets/${e}/restore`,{method:"POST",body:JSON.stringify({dry_run:t.dryRun})},!0)}async function Uz(e){return P(`/admin/datasets/${e}/reset`,{method:"POST"},!0)}async function Vz(e,t=!1){return P(`/admin/datasets/${e}`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({force:t})},!0)}async function zz(e){return P("/admin/datasets/bulk-delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dataset_ids:e})},!0)}async function Hz(e){return P("/admin/datasets/import",{method:"POST",body:JSON.stringify(e)},!0)}async function Wz(e){return P("/admin/datasets/exemplar",{method:"POST",body:JSON.stringify(e)},!0)}async function Gz(e){return P(`/admin/datasets/${e}/exemplar/remint-dois`,{method:"POST"},!0)}async function fw(e,t){let r=new URLSearchParams;if(e)r.set("status",e);if(t!==void 0)r.set("blocklisted",t?"1":"0");let n=r.toString();return P(`/admin/imports${n?`?${n}`:""}`,{},!0)}async function Kz(e){return P(`/admin/imports/${e}/rollback`,{method:"POST"},!0)}async function Yz(e){return P(`/admin/imports/${e}/retry`,{method:"POST"},!0)}async function pw(e){return P(`/admin/imports/${e}/verify`,{method:"POST"},!0)}async function Jz(e){return P("/admin/imports/dispatch-cooldown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dataset_ids:e})},!0)}async function jc(e,t){return P(`/admin/datasets/${e}/reindex`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t??{})},!0)}async function Xz(e,t){return P("/admin/datasets/reindex/bulk",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filter:e,...t??{}})},!0)}async function Qz(e){let t=e?.limit??15;return P(`/admin/datasets/hed-sweep?limit=${encodeURIComponent(String(t))}`,{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function Zz(){return P("/admin/datasets/hed-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function eH(e){let t=e?.limit??50;return P(`/admin/datasets/recording-stats-sweep?limit=${encodeURIComponent(String(t))}`,{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function tH(){return P("/admin/datasets/recording-stats-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function rH(e){let t=e?.limit??15;return P(`/admin/datasets/signal-defaults-sweep?limit=${encodeURIComponent(String(t))}`,{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function nH(){return P("/admin/datasets/signal-defaults-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function iH(e){let t=e?.limit??15,r=new URLSearchParams({limit:String(t)});if(e?.olderThan!=null)r.set("older-than",String(e.olderThan));if(e?.before!=null)r.set("before",e.before);return P(`/admin/datasets/data-integrity-sweep?${r.toString()}`,{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function sH(){return P("/admin/datasets/data-integrity-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function oH(e,t){let r=t?.write?"":"?dry_run=1";return P(`/admin/datasets/${e}/availability-report${r}`,{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function aH(e){let t=e?.limit??30,r=new URLSearchParams({limit:String(t)});if(e?.missingOnly)r.set("missing-only","1");return P(`/admin/datasets/availability-report-sweep?${r.toString()}`,{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function cH(){return P("/admin/datasets/availability-report-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function uH(e){let t=new URLSearchParams;if(e?.prefix)t.set("prefix",e.prefix);if(e?.visibility)t.set("visibility",e.visibility);if(e?.limit)t.set("limit",String(e.limit));let r=t.toString()?`?${t.toString()}`:"";return P(`/admin/fleet/drift${r}`,{},!0)}async function qc(e,t){return P(`/admin/datasets/${e}/enforce`,{method:"POST",body:JSON.stringify({dry_run:t})},!0)}async function lH(e){return P("/admin/datasets/enforce/bulk",{method:"POST",body:JSON.stringify({prefix:e.prefix,visibility:e.visibility,limit:e.limit,dry_run:e.dryRun})},!0)}async function dH(e,t=!1){return P(`/admin/datasets/${e}/revalidate${t?"?force=true":""}`,{method:"POST"},!0)}async function fH(e){let t=e?`?user=${encodeURIComponent(e)}`:"";return P(`/admin/email-preferences${t}`,{},!0)}async function pH(e,t){let r=t?`?user=${encodeURIComponent(t)}`:"";return P(`/admin/email-preferences${r}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)},!0)}async function mw(e){return P("/admin/notify",{method:"POST",body:JSON.stringify(e)},!0)}async function mH(){return P("/admin/summary/coverage",{},!0)}async function hH(e,t,r){return P("/admin/manifest/dispatch",{method:"POST",body:JSON.stringify({dataset_id:e,version:t,skip_canary:r?.skipCanary??!1})},!0)}async function hw(e){return P("/admin/doctor/scan",{method:"POST",body:JSON.stringify({...e?.check&&{check:e.check},...e?.datasetId&&{dataset_id:e.datasetId}})},!0)}async function gw(e){return P("/admin/doctor/fix",{method:"POST",body:JSON.stringify({check:e.check,...e.datasetId&&{dataset_id:e.datasetId},...e.dryRun&&{dry_run:!0}})},!0)}async function gH(){return P("/admin/zarr-catalog/publish",{method:"POST"},!0)}async function yH(e){let t=new URLSearchParams;if(e?.limit!=null)t.set("limit",String(e.limit));let r=t.toString()?`?${t.toString()}`:"";return P(`/admin/datasets/zarr-fidelity-sweep${r}`,{method:"POST",headers:{"Content-Type":"application/json"}},!0)}var Mc=A(()=>{Ns()});async function ri(e,t){return P(`/datasets/${e}/upload-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:t})},!0)}async function yw(e,t){return P(`/datasets/${e}/download-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:t})},!0)}async function xH(e){return P(`/admin/datasets/${e}/files`,{},!0)}async function bH(e){let t,r=0,n=[],i=!0;while(i){let s=await P(`/admin/datasets/${e}/s3-lock`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({continuation_token:t})},!0);if(r+=s.locked,s.failed?.length)n.push(...s.failed);if(i=s.hasMore,t=s.continuation_token,i&&!t)throw new j(500,"S3 lock paginated response missing continuation_token; aborting to avoid infinite loop")}return{locked:r,failed:n}}var Bc=A(()=>{Ns();er()});function oTe(e){return e.startsWith("v")?e:`v${e}`}var iTe,sTe,vH,wQe;var xw=A(()=>{Ic();iTe=/^v?\d+\.\d+\.\d+(?:-(?:rc|alpha|beta)\d*)?$/,sTe=/^v\d+\.\d+\.\d+(?:-(?:rc|alpha|beta)\d*)?$/;vH=S.string().regex(iTe,"must be a semver version, optionally v-prefixed").transform(oTe),wQe=S.string().regex(sTe,"must be the canonical v-prefixed tag (vX.Y.Z)")});var aTe,cTe,_H;var wH=A(()=>{Ic();aTe=S.object({id:S.number().int(),username:S.string().nullable(),email:S.string(),github_username:S.string().nullable(),role:S.string(),orcid:S.string().nullable().optional(),created_at:S.string().optional(),approved_at:S.string().nullable().optional(),dataset_count:S.number().int().optional(),sandbox_completed:S.boolean().optional(),sandbox_completed_at:S.string().nullable().optional(),sandbox_dataset_id:S.string().nullable().optional()}).passthrough(),cTe=S.object({prefix:S.string(),created_at:S.string(),last_used_at:S.string().nullable()}).passthrough().nullable(),_H=S.object({user:aTe,token:cTe.optional()}).passthrough()});function EH(e,t){if(e.zarr_index_url!=null&&e.zarr_status!=="ready")t.addIssue({code:S.ZodIssueCode.custom,message:"zarr_index_url must be null/absent unless zarr_status is 'ready'",path:["zarr_index_url"]})}function SH(e,t){if(e.zarr_verified_at!=null&&e.zarr_verify_status==null)t.addIssue({code:S.ZodIssueCode.custom,message:"zarr_verified_at must be null/absent unless zarr_verify_status is non-null",path:["zarr_verified_at"]})}var uTe="0.4.0",bw,Lc,DH,lTe,dTe,fTe,$H,RQe,CH,FQe,ki,pTe,P0,OQe;var vw=A(()=>{Ic();xw();bw=S.enum(["openneuro","nemar","gin","other"]),Lc=S.union([S.literal(0),S.literal(1)]).nullable(),DH=S.object({dataset_id:S.string(),id:S.string().optional(),name:S.string(),description:S.string().nullable().optional(),status:S.string(),visibility:S.string(),concept_doi:S.string().nullable().optional(),doi:S.string().nullable().optional(),created_at:S.string(),updated_at:S.string().optional(),owner_username:S.string().nullable().optional(),source:S.string().nullable().optional(),modalities:S.string().optional(),participants:S.number().int().nonnegative(),tasks:S.string().optional(),authors:S.string().optional(),license:S.string().optional(),file_size:S.number().nonnegative(),file_size_formatted:S.string().optional(),total_files:S.number().nonnegative().nullable().optional(),num_citations:S.number().int().nonnegative().optional(),n_channels:S.number().int().nullable().optional(),electrode_system:S.string().nullable().optional(),has_hed:Lc.optional(),hed_version:S.string().nullable().optional(),data_complete:Lc.optional(),bytes_present:S.number().nonnegative().nullable().optional(),latest_version:vH.nullable().optional(),subject_count:S.number().int().nullable().optional(),file_size_bytes:S.number().nullable().optional(),sessions_count:S.number().int().nullable().optional(),age_min:S.number().nullable().optional(),age_max:S.number().nullable().optional(),bids_version:S.string().nullable().optional(),zarr_status:S.enum(["pending","ready","failed"]).nullable().optional(),zarr_store_count:S.number().int().nullable().optional(),zarr_converted_at:S.string().nullable().optional(),zarr_source_commit:S.string().nullable().optional(),zarr_errors:S.number().int().nullable().optional(),zarr_failure_count:S.number().int().nullable().optional(),zarr_deterministic:Lc.optional(),zarr_failed_at:S.string().nullable().optional(),zarr_index_url:S.string().nullable().optional(),zarr_verify_status:S.enum(["verified","failed","unverifiable"]).nullable().optional(),zarr_verified_at:S.string().nullable().optional(),total_recording_duration:S.number().nullable().optional(),recording_duration_min:S.number().nullable().optional(),recording_duration_max:S.number().nullable().optional(),recording_count:S.number().int().nullable().optional(),recordings_unavailable:S.number().int().nullable().optional(),channel_count_min:S.number().int().nullable().optional(),channel_count_max:S.number().int().nullable().optional(),sampling_frequency:S.number().nullable().optional(),power_line_frequency:S.number().nullable().optional(),eeg_reference:S.string().nullable().optional(),placement_scheme:S.string().nullable().optional()}).passthrough();lTe=DH.superRefine((e,t)=>{EH(e,t),SH(e,t)}),dTe=DH.extend({file_size:S.number().nonnegative().nullable(),file_size_formatted:S.string().nullable().optional(),modalities:S.string().nullable().optional(),tasks:S.string().nullable().optional(),authors:S.string().nullable().optional(),license:S.string().nullable().optional(),owner_github:S.string().nullable().optional(),attestation_deposit_type:S.enum(["owner","redistribution"]).nullable().optional(),attestation_key_status:S.enum(["destroyed","retained"]).nullable().optional(),attestation_deidentified:Lc.optional(),attestation_no_duplicate:Lc.optional(),attestation_upstream_source:S.string().nullable().optional(),attestation_accepted_at:S.string().nullable().optional(),zarr_data_failures:S.object({count:S.number().int().nonnegative(),detail_ref:S.string(),compacted_by:S.string().optional(),pending:S.number().int().nonnegative().optional(),discovered:S.number().int().nonnegative().optional(),events_upload_failed:S.literal(!0).optional(),manifest_upload_failed:S.literal(!0).optional()}).passthrough().nullable().optional()}).passthrough().superRefine((e,t)=>{EH(e,t),SH(e,t)}),fTe=S.object({id:S.string(),name:S.string(),modalities:S.string().nullable().optional(),participants:S.number().int().nullable().optional(),doi:S.string().nullable().optional(),tasks:S.string().nullable().optional(),authors:S.string().nullable().optional(),has_hed:Lc.optional(),score:S.number().optional(),snippet:S.string().optional()}).passthrough(),$H=S.record(S.string(),S.number().int().nonnegative()),RQe=S.object({datasets:S.array(lTe),count:S.number().int().nonnegative(),total_count:S.number().int().nonnegative().optional(),limit:S.number().int().optional(),offset:S.number().int().optional(),excluded_unknown:S.number().int().nonnegative().optional(),excluded_unknown_by_facet:$H.optional()}).passthrough(),CH=S.object({results:S.array(fTe),count:S.number().int().nonnegative(),returned:S.number().int().nonnegative().optional(),offset:S.number().int().nonnegative().optional(),limit:S.number().int().optional(),candidate_ceiling:S.number().int().optional(),truncated:S.boolean().optional(),method:S.enum(["exact_id","text","text_fallback","semantic","unavailable"]).optional(),min_score:S.number().optional(),warning:S.string().optional(),excluded_unknown:S.number().int().nonnegative().optional(),excluded_unknown_by_facet:$H.optional()}).passthrough(),FQe=S.object({dataset:dTe}).passthrough(),ki=S.object({value:S.string(),count:S.number().int().nonnegative()}),pTe=S.object({values:S.array(ki),distinct_total:S.number().int().nonnegative(),truncated:S.boolean()}),P0=S.object({"electrode-system":S.array(ki).optional(),source:S.array(ki).optional(),zarr:S.array(ki).optional(),powerline:S.array(ki).optional(),"bids-version":S.array(ki).optional(),"hed-version":S.array(ki).optional(),license:S.array(ki).optional(),modality:S.array(ki).optional(),task:pTe.optional(),warning:S.string().optional()}).passthrough(),OQe=S.object({schema_version:S.literal(uTe),doc_type:S.literal("dataset"),dataset_id:S.string().regex(/^[a-z]{2}\d+$/,"neuroschema dataset_id pattern"),name:S.string(),source:bw,recording_modality:S.array(S.string()).min(1),description:S.string().nullable().optional(),bids_version:S.string().nullable().optional(),license:S.string().nullable().optional()}).passthrough()});var I0=A(()=>{xw();wH();vw()});async function N0(e){return P(`/datasets/${e}/ci/status`,{},!0)}async function RH(e){return P(`/datasets/${e}/manifest`,{},!0)}async function j0(e,t){return P(`/datasets/${e}/manifest/${t}`,{},!0)}function FH(e){let t=e;if(!t.status)t.status="active";else if(!["active","archived","deleted"].includes(t.status))throw Error(`Invalid dataset status: ${t.status}`);if(!t.visibility)t.visibility="private";else if(!["public","private"].includes(t.visibility))throw Error(`Invalid dataset visibility: ${t.visibility}`);return t}async function Uc(e={}){let t=new URLSearchParams;if(e.mine)t.set("mine","true");if(e.search)t.set("search",e.search);if(e.modality)t.set("modality",e.modality);if(e.author)t.set("author",e.author);if(e.task)t.set("task",e.task);if(e.license)t.set("license",e.license);if(e.hasDoi)t.set("has_doi","true");if(e.hasHed)t.set("has_hed","1");if(e.hasZarr)t.set("has_zarr","1");if(e.hasZarrVerified)t.set("has_zarr_verified","1");if(e.dataComplete)t.set("data_complete","1");if(e.recent)t.set("recent",String(e.recent));if(e.sort)t.set("sort",e.sort);if(e.limit!=null)t.set("limit",String(e.limit));if(e.offset!=null)t.set("offset",String(e.offset));if(e.owner)t.set("owner",e.owner);if(e.facets)for(let[i,s]of Object.entries(e.facets))t.set(i,s);if(e.includeUnknown)t.set("include_unknown","1");let r=t.toString()?`?${t.toString()}`:"",n=await P(`/datasets${r}`,{},e.mine?!0:"optional");return n.datasets=n.datasets.map(FH),n}async function OH(e){return P(`/datasets/resolve/${e}`,{},"optional")}async function AH(){return P("/datasets/facets",{signal:AbortSignal.timeout(5000)},"optional",P0)}async function kH(e,t={}){let r=new URLSearchParams({q:e});if(t.modality)r.set("modality",t.modality);if(t.limit)r.set("limit",String(t.limit));if(t.hasHed)r.set("has_hed","1");if(t.hasZarr)r.set("has_zarr","1");if(t.hasZarrVerified)r.set("has_zarr_verified","1");if(t.author)r.set("author",t.author);if(t.task)r.set("task",t.task);if(t.license)r.set("license",t.license);if(t.hasDoi)r.set("has_doi","true");if(t.dataComplete)r.set("data_complete","1");if(t.recent)r.set("recent",String(t.recent));if(t.facets)for(let[i,s]of Object.entries(t.facets))r.set(i,s);if(t.includeUnknown)r.set("include_unknown","1");return await P(`/datasets/search?${r.toString()}`,{},"optional",CH)}async function gt(e){let t=await P(`/datasets/${e}`,{},"optional");return FH(t.dataset)}async function PH(e){return P(`/datasets/${e}/versions`,{},!0)}async function q0(e){return P("/datasets",{method:"POST",body:JSON.stringify(e)},!0)}async function M0(e){return P(`/datasets/${e}/finalize`,{method:"POST"},!0)}async function _w(e){return P(`/datasets/${e}/request-access`,{method:"POST"},!0)}async function IH(e,t){let r=t?`?status=${t}`:"";return P(`/datasets/${e}/access-requests${r}`,{},!0)}async function TH(e,t){return P(`/datasets/${e}/access-requests/${t}/approve`,{method:"POST"},!0)}async function NH(e,t){return P(`/datasets/${e}/access-requests/${t}/deny`,{method:"POST"},!0)}async function jH(e,t){return P(`/datasets/${e}/invite`,{method:"POST",body:JSON.stringify({username:t})},!0)}async function qH(e){return P(`/datasets/${e}/collaborators`,{},!0)}async function MH(e,t){return P(`/admin/datasets/${e}/enrichment`,{method:"POST",body:JSON.stringify(t)},!0)}var T0;var js=A(()=>{I0();Ns();T0=/^\d{4}-\d{4}-\d{4}-\d{3}[\dX]$/});var Vc;var zH=A(()=>{Vc=["ci_check","enrichment_check","s3_public_read","repo_public","tag_protect","doi_create","update_metadata","update_readme","create_tag","create_release","upload_to_zenodo","publish_doi","version_doi","s3_lock","sync_nemar","notify_user"]});async function zc(e){return P(`/datasets/${e}/publish/request`,{method:"POST"},!0)}async function WH(e){return P(`/datasets/${e}/publish/status`,{},!0)}async function GH(e){return P(`/datasets/${e}/publish/resend`,{method:"POST"},!0)}async function KH(e){let t=e?`?status=${e}`:"";return P(`/admin/publish/requests${t}`,{},!0)}async function YH(e,t){return P(`/admin/publish/${e}/deny`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:t})},!0)}function mTe(e,t=[]){if(e){let r=Vc.indexOf(e);if(r>=0)return r+1}return Math.min(t.length+1,Vc.length)}function hTe(e){if(!(e instanceof j))return!1;if(e.statusCode===0)return!0;if(e.statusCode===429)return!0;if(e.statusCode>=500&&e.statusCode<600)return!0;if(e.statusCode===403&&/repository has been locked/i.test(e.message))return!0;return!1}async function Hc(e,t=!1,r=!1,n=!1,i,s){let c,l,d=0,f=!1,m,p=t,g=[],y;function x(v,_,E,C){if(!s)return;s({step:v,stepIndex:mTe(v,_),stepTotal:Vc.length,s3LockLocked:E,s3LockTotal:C,s3LockResumed:v==="s3_lock"&&f?!0:void 0})}for(let v=1;v<=5;v++)try{let _,E=!0;do{if(_=await P(`/admin/publish/${e}/approve`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({resume:E?p:!0,sandbox:r,s3_lock_continuation_token:c,s3_lock_total:l,skip_ci_check:n})},!0),E=!1,_.step_results)g.push(..._.step_results);if(_.s3_lock_total!==void 0)l=_.s3_lock_total;if(_.s3_lock_batch_count!==void 0)d+=_.s3_lock_batch_count;let C=_.step??_.step_results?.[_.step_results.length-1]?.step;if(C&&(C!==m||C==="s3_lock"))x(C,_.steps_completed??[],C==="s3_lock"?d:void 0,C==="s3_lock"?l:void 0),m=C;if(_.hasMore&&_.s3_lock_continuation_token!==void 0)c=_.s3_lock_continuation_token;else break}while(_.hasMore);if(g.length>0)_.step_results=HH(g);return _}catch(_){if(y=_,v===5||!hTe(_)){if(_ instanceof j&&g.length>0)_.stepResults=HH(g);throw _}let C=_;if(i?.({attempt:v,maxAttempts:5,delayMs:1e4,step:C.step,error:C.message}),await new Promise((w)=>setTimeout(w,1e4)),p=!0,c!==void 0)f=!0}throw y}function HH(e){let t=new Map;for(let r of e)t.set(r.step,r);return Array.from(t.values())}var Ed=A(()=>{zH();Ns();er()});function QH(e){Ew=e}function Sw(){return Ew}function Sd(e){if(Ew)process.stderr.write(`${e}
|
|
105
|
+
`)}var Rz=!1;var sw=A(()=>{He()});var Oz;var Fz=A(()=>{Oz={name:"nemar-cli",version:"0.9.15-dev.2265",description:"CLI for NEMAR (Neuroelectromagnetic Data Archive and Tools Resource) dataset management",type:"module",main:"dist/index.js",bin:{nemar:"dist/index.js"},scripts:{dev:"bun run src/index.ts",build:"bun build src/index.ts --outdir dist --target bun --minify && sed '1s|#!/usr/bin/env node|#!/usr/bin/env bun|' dist/index.js > dist/index.js.tmp && mv dist/index.js.tmp dist/index.js",test:"bun test",lint:"biome check src/","lint:fix":"biome check --fix src/",format:"biome format --write src/",typecheck:"tsc --noEmit && tsc --noEmit -p backend",prepublishOnly:"bun run build",prepare:"husky",postinstall:"bun scripts/postinstall-check.mjs",deploy:"wrangler deploy",preview:"wrangler dev"},keywords:["nemar","bids","neuroimaging","eeg","emg","datalad","cli"],author:"NEMAR Team",license:"CC-BY-NC-ND-4.0",repository:{type:"git",url:"git+https://github.com/nemarOrg/nemar-cli.git"},bugs:{url:"https://github.com/nemarOrg/nemar-cli/issues"},homepage:"https://docs.nemar.org",engines:{bun:">=1.0.0"},files:["dist","scripts/postinstall-check.mjs","scripts/recover-datasets.json","scripts/withdrawn-datasets.json","README.md","LICENSE"],dependencies:{chalk:"^5.3.0",commander:"^12.1.0",conf:"^13.0.1","fuse.js":"^7.1.0",inquirer:"^9.2.15",ora:"^8.0.1",zod:"^3.23.8"},"lint-staged":{"src/**/*.{ts,tsx}":["biome check --fix"],"backend/src/**/*.{ts,tsx}":["biome check --fix"]},devDependencies:{"@biomejs/biome":"1.9.4","@types/bcryptjs":"^3.0.0","@types/bun":"latest","@types/inquirer":"^9.0.7",ajv:"^8.20.0","ajv-formats":"^3.0.1",bcryptjs:"^3.0.3",husky:"^9.1.7","lint-staged":"^16.3.2",typescript:"^5.5.4",wrangler:"^4.70.0",yaml:"^2.8.4"}}});var To;var k0=A(()=>{Fz();To=Oz.version});function U(e){if(e instanceof Error)return e.message;return String(e)}var j,No;var er=A(()=>{j=class j extends Error{statusCode;details;step;constructor(e,t,r,n){super(t);this.statusCode=e;this.details=r;this.step=n;this.name="ApiError"}};No=class No extends j{mode;eta;constructor(e,t,r,n){super(503,t,n);this.mode=e;this.eta=r;this.name="MaintenanceError"}}});function Az(){if(process.env.TEST_API_URL)return process.env.TEST_API_URL;if(aw)return ow;return ht().apiUrl||ow}async function P(e,t={},r=!1,n){let i=`${Az()}${e}`,s={"Content-Type":"application/json","X-CLI-Version":To,...t.headers};if(r){let c=ht();if(!c.apiKey&&r===!0)throw new j(401,"Not authenticated. Run 'nemar auth login' first.");if(c.apiKey)s.Authorization=`Bearer ${c.apiKey}`}let o;try{o=await fetch(i,{...t,headers:s})}catch(c){throw new j(0,`Network error: Could not connect to ${Az()}`,{originalError:c instanceof Error?c.message:String(c)})}let a;try{a=await o.json()}catch{throw new j(o.status,`Invalid response from server (status ${o.status})`)}if(!o.ok){if(o.status===503&&(a.mode==="read-only"||a.mode==="full")){let c=typeof a.message==="string"?a.message:"NEMAR is in maintenance mode. Please retry shortly.",l=typeof a.eta==="string"?a.eta:null,d=new No(a.mode,c,l,a.details);throw A0(d),d}throw new j(o.status,a.error||a.message||"Request failed",a.details,typeof a.step==="string"?a.step:void 0)}if(n){let c=n.safeParse(a);if(!c.success)throw new j(o.status,`Response for ${e} did not match the expected NEMAR contract`,{issues:c.error.issues});return c.data}return a}var ow="https://nemar-api-dev.sccn-org.workers.dev",aw;var Ns=A(()=>{Ts();sw();k0();er();aw=ow.includes("workers.dev")});async function kz(e,t){let r=new URLSearchParams;if(e)r.set("status",e);if(t)r.set("role",t);let n=r.toString()?`?${r.toString()}`:"";return P(`/admin/users${n}`,{},!0)}async function Pz(e){return P(`/admin/approve/${e}`,{method:"POST"},!0)}async function Iz(e){return P(`/admin/approve/by-id/${e}`,{method:"POST"},!0)}async function Tz(e){return P(`/admin/revoke/${e}`,{method:"POST"},!0)}async function Nz(e,t){return P(`/admin/users/${e}/role`,{method:"POST",body:JSON.stringify({role:t})},!0)}async function cw(e,t){return P(`/admin/datasets/${e}/visibility`,{method:"PATCH",body:JSON.stringify({visibility:t})},!0)}async function jz(e){return P(`/datasets/${e}/publish`,{method:"POST"},!0)}async function qz(e){return P(`/admin/datasets/${e}/ci`,{},!0)}async function Ai(e){return P(`/admin/datasets/${e}/ci`,{method:"POST"},!0)}async function uw(e){return P(`/admin/datasets/${e}/ci/validate`,{method:"POST"},!0)}async function lw(e){return P(`/admin/datasets/${e}/ci/sync`,{method:"POST"},!0)}async function Mz(e,t){return P(`/admin/datasets/${e}/doi/concept`,{method:"POST",body:JSON.stringify(t)},!0)}async function Dd(e){return P(`/admin/datasets/${e}/doi`,{},!0)}async function dw(e,t){return P(`/admin/datasets/${e}/doi/update`,{method:"POST",body:JSON.stringify(t)},!0)}async function Bz(e,t){return P(`/admin/datasets/${e}/withdraw`,{method:"POST",body:JSON.stringify({reason:t.reason,dry_run:t.dryRun})},!0)}async function Lz(e,t){return P(`/admin/datasets/${e}/restore`,{method:"POST",body:JSON.stringify({dry_run:t.dryRun})},!0)}async function Uz(e){return P(`/admin/datasets/${e}/reset`,{method:"POST"},!0)}async function Vz(e,t=!1){return P(`/admin/datasets/${e}`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({force:t})},!0)}async function zz(e){return P("/admin/datasets/bulk-delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dataset_ids:e})},!0)}async function Hz(e){return P("/admin/datasets/import",{method:"POST",body:JSON.stringify(e)},!0)}async function Wz(e){return P("/admin/datasets/exemplar",{method:"POST",body:JSON.stringify(e)},!0)}async function Gz(e){return P(`/admin/datasets/${e}/exemplar/remint-dois`,{method:"POST"},!0)}async function fw(e,t){let r=new URLSearchParams;if(e)r.set("status",e);if(t!==void 0)r.set("blocklisted",t?"1":"0");let n=r.toString();return P(`/admin/imports${n?`?${n}`:""}`,{},!0)}async function Kz(e){return P(`/admin/imports/${e}/rollback`,{method:"POST"},!0)}async function Yz(e){return P(`/admin/imports/${e}/retry`,{method:"POST"},!0)}async function pw(e){return P(`/admin/imports/${e}/verify`,{method:"POST"},!0)}async function Jz(e){return P("/admin/imports/dispatch-cooldown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dataset_ids:e})},!0)}async function jc(e,t){return P(`/admin/datasets/${e}/reindex`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t??{})},!0)}async function Xz(e,t){return P("/admin/datasets/reindex/bulk",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filter:e,...t??{}})},!0)}async function Qz(e){let t=e?.limit??15;return P(`/admin/datasets/hed-sweep?limit=${encodeURIComponent(String(t))}`,{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function Zz(){return P("/admin/datasets/hed-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function eH(e){let t=e?.limit??50;return P(`/admin/datasets/recording-stats-sweep?limit=${encodeURIComponent(String(t))}`,{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function tH(){return P("/admin/datasets/recording-stats-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function rH(e){let t=e?.limit??15;return P(`/admin/datasets/signal-defaults-sweep?limit=${encodeURIComponent(String(t))}`,{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function nH(){return P("/admin/datasets/signal-defaults-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function iH(e){let t=e?.limit??15,r=new URLSearchParams({limit:String(t)});if(e?.olderThan!=null)r.set("older-than",String(e.olderThan));if(e?.before!=null)r.set("before",e.before);return P(`/admin/datasets/data-integrity-sweep?${r.toString()}`,{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function sH(){return P("/admin/datasets/data-integrity-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function oH(e,t){let r=t?.write?"":"?dry_run=1";return P(`/admin/datasets/${e}/availability-report${r}`,{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function aH(e){let t=e?.limit??30,r=new URLSearchParams({limit:String(t)});if(e?.missingOnly)r.set("missing-only","1");return P(`/admin/datasets/availability-report-sweep?${r.toString()}`,{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function cH(){return P("/admin/datasets/availability-report-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function uH(e){let t=new URLSearchParams;if(e?.prefix)t.set("prefix",e.prefix);if(e?.visibility)t.set("visibility",e.visibility);if(e?.limit)t.set("limit",String(e.limit));let r=t.toString()?`?${t.toString()}`:"";return P(`/admin/fleet/drift${r}`,{},!0)}async function qc(e,t){return P(`/admin/datasets/${e}/enforce`,{method:"POST",body:JSON.stringify({dry_run:t})},!0)}async function lH(e){return P("/admin/datasets/enforce/bulk",{method:"POST",body:JSON.stringify({prefix:e.prefix,visibility:e.visibility,limit:e.limit,dry_run:e.dryRun})},!0)}async function dH(e,t=!1){return P(`/admin/datasets/${e}/revalidate${t?"?force=true":""}`,{method:"POST"},!0)}async function fH(e){let t=e?`?user=${encodeURIComponent(e)}`:"";return P(`/admin/email-preferences${t}`,{},!0)}async function pH(e,t){let r=t?`?user=${encodeURIComponent(t)}`:"";return P(`/admin/email-preferences${r}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)},!0)}async function mw(e){return P("/admin/notify",{method:"POST",body:JSON.stringify(e)},!0)}async function mH(){return P("/admin/summary/coverage",{},!0)}async function hH(e,t,r){return P("/admin/manifest/dispatch",{method:"POST",body:JSON.stringify({dataset_id:e,version:t,skip_canary:r?.skipCanary??!1})},!0)}async function hw(e){return P("/admin/doctor/scan",{method:"POST",body:JSON.stringify({...e?.check&&{check:e.check},...e?.datasetId&&{dataset_id:e.datasetId}})},!0)}async function gw(e){return P("/admin/doctor/fix",{method:"POST",body:JSON.stringify({check:e.check,...e.datasetId&&{dataset_id:e.datasetId},...e.dryRun&&{dry_run:!0}})},!0)}async function gH(){return P("/admin/zarr-catalog/publish",{method:"POST"},!0)}async function yH(e){let t=new URLSearchParams;if(e?.limit!=null)t.set("limit",String(e.limit));let r=t.toString()?`?${t.toString()}`:"";return P(`/admin/datasets/zarr-fidelity-sweep${r}`,{method:"POST",headers:{"Content-Type":"application/json"}},!0)}var Mc=A(()=>{Ns()});async function ri(e,t){return P(`/datasets/${e}/upload-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:t})},!0)}async function yw(e,t){return P(`/datasets/${e}/download-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:t})},!0)}async function xH(e){return P(`/admin/datasets/${e}/files`,{},!0)}async function bH(e){let t,r=0,n=[],i=!0;while(i){let s=await P(`/admin/datasets/${e}/s3-lock`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({continuation_token:t})},!0);if(r+=s.locked,s.failed?.length)n.push(...s.failed);if(i=s.hasMore,t=s.continuation_token,i&&!t)throw new j(500,"S3 lock paginated response missing continuation_token; aborting to avoid infinite loop")}return{locked:r,failed:n}}var Bc=A(()=>{Ns();er()});function oTe(e){return e.startsWith("v")?e:`v${e}`}var iTe,sTe,vH,wQe;var xw=A(()=>{Ic();iTe=/^v?\d+\.\d+\.\d+(?:-(?:rc|alpha|beta)\d*)?$/,sTe=/^v\d+\.\d+\.\d+(?:-(?:rc|alpha|beta)\d*)?$/;vH=S.string().regex(iTe,"must be a semver version, optionally v-prefixed").transform(oTe),wQe=S.string().regex(sTe,"must be the canonical v-prefixed tag (vX.Y.Z)")});var aTe,cTe,_H;var wH=A(()=>{Ic();aTe=S.object({id:S.number().int(),username:S.string().nullable(),email:S.string(),github_username:S.string().nullable(),role:S.string(),orcid:S.string().nullable().optional(),created_at:S.string().optional(),approved_at:S.string().nullable().optional(),dataset_count:S.number().int().optional(),sandbox_completed:S.boolean().optional(),sandbox_completed_at:S.string().nullable().optional(),sandbox_dataset_id:S.string().nullable().optional()}).passthrough(),cTe=S.object({prefix:S.string(),created_at:S.string(),last_used_at:S.string().nullable()}).passthrough().nullable(),_H=S.object({user:aTe,token:cTe.optional()}).passthrough()});function EH(e,t){if(e.zarr_index_url!=null&&e.zarr_status!=="ready")t.addIssue({code:S.ZodIssueCode.custom,message:"zarr_index_url must be null/absent unless zarr_status is 'ready'",path:["zarr_index_url"]})}function SH(e,t){if(e.zarr_verified_at!=null&&e.zarr_verify_status==null)t.addIssue({code:S.ZodIssueCode.custom,message:"zarr_verified_at must be null/absent unless zarr_verify_status is non-null",path:["zarr_verified_at"]})}var uTe="0.4.0",bw,Lc,DH,lTe,dTe,fTe,$H,RQe,CH,FQe,ki,pTe,P0,OQe;var vw=A(()=>{Ic();xw();bw=S.enum(["openneuro","nemar","gin","other"]),Lc=S.union([S.literal(0),S.literal(1)]).nullable(),DH=S.object({dataset_id:S.string(),id:S.string().optional(),name:S.string(),description:S.string().nullable().optional(),status:S.string(),visibility:S.string(),concept_doi:S.string().nullable().optional(),doi:S.string().nullable().optional(),created_at:S.string(),updated_at:S.string().optional(),owner_username:S.string().nullable().optional(),source:S.string().nullable().optional(),modalities:S.string().optional(),participants:S.number().int().nonnegative(),tasks:S.string().optional(),authors:S.string().optional(),license:S.string().optional(),file_size:S.number().nonnegative(),file_size_formatted:S.string().optional(),total_files:S.number().nonnegative().nullable().optional(),num_citations:S.number().int().nonnegative().optional(),n_channels:S.number().int().nullable().optional(),electrode_system:S.string().nullable().optional(),has_hed:Lc.optional(),hed_version:S.string().nullable().optional(),data_complete:Lc.optional(),bytes_present:S.number().nonnegative().nullable().optional(),latest_version:vH.nullable().optional(),subject_count:S.number().int().nullable().optional(),file_size_bytes:S.number().nullable().optional(),sessions_count:S.number().int().nullable().optional(),age_min:S.number().nullable().optional(),age_max:S.number().nullable().optional(),bids_version:S.string().nullable().optional(),zarr_status:S.enum(["pending","ready","failed"]).nullable().optional(),zarr_store_count:S.number().int().nullable().optional(),zarr_converted_at:S.string().nullable().optional(),zarr_source_commit:S.string().nullable().optional(),zarr_errors:S.number().int().nullable().optional(),zarr_failure_count:S.number().int().nullable().optional(),zarr_deterministic:Lc.optional(),zarr_failed_at:S.string().nullable().optional(),zarr_index_url:S.string().nullable().optional(),zarr_verify_status:S.enum(["verified","failed","unverifiable"]).nullable().optional(),zarr_verified_at:S.string().nullable().optional(),total_recording_duration:S.number().nullable().optional(),recording_duration_min:S.number().nullable().optional(),recording_duration_max:S.number().nullable().optional(),recording_count:S.number().int().nullable().optional(),recordings_unavailable:S.number().int().nullable().optional(),channel_count_min:S.number().int().nullable().optional(),channel_count_max:S.number().int().nullable().optional(),sampling_frequency:S.number().nullable().optional(),power_line_frequency:S.number().nullable().optional(),eeg_reference:S.string().nullable().optional(),placement_scheme:S.string().nullable().optional()}).passthrough();lTe=DH.superRefine((e,t)=>{EH(e,t),SH(e,t)}),dTe=DH.extend({file_size:S.number().nonnegative().nullable(),file_size_formatted:S.string().nullable().optional(),modalities:S.string().nullable().optional(),tasks:S.string().nullable().optional(),authors:S.string().nullable().optional(),license:S.string().nullable().optional(),owner_github:S.string().nullable().optional(),attestation_deposit_type:S.enum(["owner","redistribution"]).nullable().optional(),attestation_key_status:S.enum(["destroyed","retained"]).nullable().optional(),attestation_deidentified:Lc.optional(),attestation_no_duplicate:Lc.optional(),attestation_upstream_source:S.string().nullable().optional(),attestation_accepted_at:S.string().nullable().optional(),zarr_data_failures:S.object({count:S.number().int().nonnegative(),detail_ref:S.string(),compacted_by:S.string().optional(),pending:S.number().int().nonnegative().optional(),discovered:S.number().int().nonnegative().optional(),events_upload_failed:S.literal(!0).optional(),manifest_upload_failed:S.literal(!0).optional()}).passthrough().nullable().optional()}).passthrough().superRefine((e,t)=>{EH(e,t),SH(e,t)}),fTe=S.object({id:S.string(),name:S.string(),modalities:S.string().nullable().optional(),participants:S.number().int().nullable().optional(),doi:S.string().nullable().optional(),tasks:S.string().nullable().optional(),authors:S.string().nullable().optional(),has_hed:Lc.optional(),score:S.number().optional(),snippet:S.string().optional()}).passthrough(),$H=S.record(S.string(),S.number().int().nonnegative()),RQe=S.object({datasets:S.array(lTe),count:S.number().int().nonnegative(),total_count:S.number().int().nonnegative().optional(),limit:S.number().int().optional(),offset:S.number().int().optional(),excluded_unknown:S.number().int().nonnegative().optional(),excluded_unknown_by_facet:$H.optional()}).passthrough(),CH=S.object({results:S.array(fTe),count:S.number().int().nonnegative(),returned:S.number().int().nonnegative().optional(),offset:S.number().int().nonnegative().optional(),limit:S.number().int().optional(),candidate_ceiling:S.number().int().optional(),truncated:S.boolean().optional(),method:S.enum(["exact_id","text","text_fallback","semantic","unavailable"]).optional(),min_score:S.number().optional(),warning:S.string().optional(),excluded_unknown:S.number().int().nonnegative().optional(),excluded_unknown_by_facet:$H.optional()}).passthrough(),FQe=S.object({dataset:dTe}).passthrough(),ki=S.object({value:S.string(),count:S.number().int().nonnegative()}),pTe=S.object({values:S.array(ki),distinct_total:S.number().int().nonnegative(),truncated:S.boolean()}),P0=S.object({"electrode-system":S.array(ki).optional(),source:S.array(ki).optional(),zarr:S.array(ki).optional(),powerline:S.array(ki).optional(),"bids-version":S.array(ki).optional(),"hed-version":S.array(ki).optional(),license:S.array(ki).optional(),modality:S.array(ki).optional(),task:pTe.optional(),warning:S.string().optional()}).passthrough(),OQe=S.object({schema_version:S.literal(uTe),doc_type:S.literal("dataset"),dataset_id:S.string().regex(/^[a-z]{2}\d+$/,"neuroschema dataset_id pattern"),name:S.string(),source:bw,recording_modality:S.array(S.string()).min(1),description:S.string().nullable().optional(),bids_version:S.string().nullable().optional(),license:S.string().nullable().optional()}).passthrough()});var I0=A(()=>{xw();wH();vw()});async function N0(e){return P(`/datasets/${e}/ci/status`,{},!0)}async function RH(e){return P(`/datasets/${e}/manifest`,{},!0)}async function j0(e,t){return P(`/datasets/${e}/manifest/${t}`,{},!0)}function FH(e){let t=e;if(!t.status)t.status="active";else if(!["active","archived","deleted"].includes(t.status))throw Error(`Invalid dataset status: ${t.status}`);if(!t.visibility)t.visibility="private";else if(!["public","private"].includes(t.visibility))throw Error(`Invalid dataset visibility: ${t.visibility}`);return t}async function Uc(e={}){let t=new URLSearchParams;if(e.mine)t.set("mine","true");if(e.search)t.set("search",e.search);if(e.modality)t.set("modality",e.modality);if(e.author)t.set("author",e.author);if(e.task)t.set("task",e.task);if(e.license)t.set("license",e.license);if(e.hasDoi)t.set("has_doi","true");if(e.hasHed)t.set("has_hed","1");if(e.hasZarr)t.set("has_zarr","1");if(e.hasZarrVerified)t.set("has_zarr_verified","1");if(e.dataComplete)t.set("data_complete","1");if(e.recent)t.set("recent",String(e.recent));if(e.sort)t.set("sort",e.sort);if(e.limit!=null)t.set("limit",String(e.limit));if(e.offset!=null)t.set("offset",String(e.offset));if(e.owner)t.set("owner",e.owner);if(e.facets)for(let[i,s]of Object.entries(e.facets))t.set(i,s);if(e.includeUnknown)t.set("include_unknown","1");let r=t.toString()?`?${t.toString()}`:"",n=await P(`/datasets${r}`,{},e.mine?!0:"optional");return n.datasets=n.datasets.map(FH),n}async function OH(e){return P(`/datasets/resolve/${e}`,{},"optional")}async function AH(){return P("/datasets/facets",{signal:AbortSignal.timeout(5000)},"optional",P0)}async function kH(e,t={}){let r=new URLSearchParams({q:e});if(t.modality)r.set("modality",t.modality);if(t.limit)r.set("limit",String(t.limit));if(t.hasHed)r.set("has_hed","1");if(t.hasZarr)r.set("has_zarr","1");if(t.hasZarrVerified)r.set("has_zarr_verified","1");if(t.author)r.set("author",t.author);if(t.task)r.set("task",t.task);if(t.license)r.set("license",t.license);if(t.hasDoi)r.set("has_doi","true");if(t.dataComplete)r.set("data_complete","1");if(t.recent)r.set("recent",String(t.recent));if(t.facets)for(let[i,s]of Object.entries(t.facets))r.set(i,s);if(t.includeUnknown)r.set("include_unknown","1");return await P(`/datasets/search?${r.toString()}`,{},"optional",CH)}async function gt(e){let t=await P(`/datasets/${e}`,{},"optional");return FH(t.dataset)}async function PH(e){return P(`/datasets/${e}/versions`,{},!0)}async function q0(e){return P("/datasets",{method:"POST",body:JSON.stringify(e)},!0)}async function M0(e){return P(`/datasets/${e}/finalize`,{method:"POST"},!0)}async function _w(e){return P(`/datasets/${e}/request-access`,{method:"POST"},!0)}async function IH(e,t){let r=t?`?status=${t}`:"";return P(`/datasets/${e}/access-requests${r}`,{},!0)}async function TH(e,t){return P(`/datasets/${e}/access-requests/${t}/approve`,{method:"POST"},!0)}async function NH(e,t){return P(`/datasets/${e}/access-requests/${t}/deny`,{method:"POST"},!0)}async function jH(e,t){return P(`/datasets/${e}/invite`,{method:"POST",body:JSON.stringify({username:t})},!0)}async function qH(e){return P(`/datasets/${e}/collaborators`,{},!0)}async function MH(e,t){return P(`/admin/datasets/${e}/enrichment`,{method:"POST",body:JSON.stringify(t)},!0)}var T0;var js=A(()=>{I0();Ns();T0=/^\d{4}-\d{4}-\d{4}-\d{3}[\dX]$/});var Vc;var zH=A(()=>{Vc=["ci_check","enrichment_check","s3_public_read","repo_public","tag_protect","doi_create","update_metadata","update_readme","create_tag","create_release","upload_to_zenodo","publish_doi","version_doi","s3_lock","sync_nemar","notify_user"]});async function zc(e){return P(`/datasets/${e}/publish/request`,{method:"POST"},!0)}async function WH(e){return P(`/datasets/${e}/publish/status`,{},!0)}async function GH(e){return P(`/datasets/${e}/publish/resend`,{method:"POST"},!0)}async function KH(e){let t=e?`?status=${e}`:"";return P(`/admin/publish/requests${t}`,{},!0)}async function YH(e,t){return P(`/admin/publish/${e}/deny`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:t})},!0)}function mTe(e,t=[]){if(e){let r=Vc.indexOf(e);if(r>=0)return r+1}return Math.min(t.length+1,Vc.length)}function hTe(e){if(!(e instanceof j))return!1;if(e.statusCode===0)return!0;if(e.statusCode===429)return!0;if(e.statusCode>=500&&e.statusCode<600)return!0;if(e.statusCode===403&&/repository has been locked/i.test(e.message))return!0;return!1}async function Hc(e,t=!1,r=!1,n=!1,i,s){let c,l,d=0,f=!1,m,p=t,g=[],y;function x(v,_,E,C){if(!s)return;s({step:v,stepIndex:mTe(v,_),stepTotal:Vc.length,s3LockLocked:E,s3LockTotal:C,s3LockResumed:v==="s3_lock"&&f?!0:void 0})}for(let v=1;v<=5;v++)try{let _,E=!0;do{if(_=await P(`/admin/publish/${e}/approve`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({resume:E?p:!0,sandbox:r,s3_lock_continuation_token:c,s3_lock_total:l,skip_ci_check:n})},!0),E=!1,_.step_results)g.push(..._.step_results);if(_.s3_lock_total!==void 0)l=_.s3_lock_total;if(_.s3_lock_batch_count!==void 0)d+=_.s3_lock_batch_count;let C=_.step??_.step_results?.[_.step_results.length-1]?.step;if(C&&(C!==m||C==="s3_lock"))x(C,_.steps_completed??[],C==="s3_lock"?d:void 0,C==="s3_lock"?l:void 0),m=C;if(_.hasMore&&_.s3_lock_continuation_token!==void 0)c=_.s3_lock_continuation_token;else break}while(_.hasMore);if(g.length>0)_.step_results=HH(g);return _}catch(_){if(y=_,v===5||!hTe(_)){if(_ instanceof j&&g.length>0)_.stepResults=HH(g);throw _}let C=_;if(i?.({attempt:v,maxAttempts:5,delayMs:1e4,step:C.step,error:C.message}),await new Promise((w)=>setTimeout(w,1e4)),p=!0,c!==void 0)f=!0}throw y}function HH(e){let t=new Map;for(let r of e)t.set(r.step,r);return Array.from(t.values())}var Ed=A(()=>{zH();Ns();er()});function QH(e){Ew=e}function Sw(){return Ew}function Sd(e){if(Ew)process.stderr.write(`${e}
|
|
106
106
|
`)}var Ew=!1;var ZH={};qi(ZH,{runCommand:()=>F});var{spawn:gTe}=globalThis.Bun;async function F(e,t={}){let r={...process.env,GIT_TERMINAL_PROMPT:"0",...t.env};for(let l of t.unsetEnv??[])delete r[l];let n=gTe({cmd:e,cwd:t.cwd,stdout:"pipe",stderr:"pipe",env:r}),i=!1,s;if(t.timeout)s=setTimeout(()=>{i=!0,n.kill()},t.timeout);if(Sw()){let l=t.cwd?` (cwd=${t.cwd})`:"";Sd(u.dim(`$ ${e.join(" ")}${l}`))}let o=await new Response(n.stdout).text(),a=await new Response(n.stderr).text(),c=await n.exited;if(s)clearTimeout(s);if(Sw()){if(o.trim())Sd(u.dim(o.trimEnd()));if(a.trim())Sd(u.yellow(a.trimEnd()));Sd(u.dim(`(exit ${c})`))}if(i)return{stdout:o,stderr:a||`Command timed out after ${Math.round(t.timeout/1000)}s`,exitCode:c??1};return{stdout:o,stderr:a,exitCode:c}}var Ut=A(()=>{He()});async function yTe(){try{let{exitCode:e,stderr:t}=await F(["ssh","-T","-o","BatchMode=yes","-o","ConnectTimeout=5","git@github.com"]),r=t.includes("successfully authenticated");if(!r)console.warn("SSH test to github.com failed:",{exitCode:e,stderr:t.trim().slice(0,500)});return{works:r,error:r?void 0:t.trim().slice(0,500)}}catch(e){let t=e instanceof Error?e.message:String(e);return console.warn("SSH test exception:",t),{works:!1,error:t}}}async function $d(){try{let{stdout:e,exitCode:t,stderr:r}=await F(["gh","auth","token"]);if(t!==0)return console.warn("gh CLI returned non-zero exit code:",t),console.warn("stderr:",r),{token:null,error:`gh auth token failed: ${r.trim()||"unknown error"}`};if(!e.trim())return console.warn("gh auth token returned empty output"),{token:null,error:"gh CLI returned empty token"};return{token:e.trim()}}catch(e){let t=e instanceof Error?e.message:String(e);if(console.error("Failed to get GitHub token from gh CLI:",t),t.includes("ENOENT")||t.includes("not found"))return{token:null,error:"gh CLI not installed (command not found)"};return{token:null,error:`gh CLI error: ${t}`}}}async function B0(e){try{let{stdout:t,exitCode:r,stderr:n}=await F(["gh","api","user","--jq",".login"]);if(r!==0){if(n.includes("not logged in")||n.includes("auth login"))return{authenticated:!1,error:"gh CLI not authenticated. Run 'gh auth login' to authenticate."};return{authenticated:!1,error:`gh CLI error: ${n.trim()||"unknown error"}`}}let i=t.trim();if(!i)return{authenticated:!1,error:"gh CLI returned empty username"};if(e){let s=i.toLowerCase()===e.toLowerCase();return{authenticated:!0,username:i,matches:s,error:s?void 0:`gh CLI authenticated as '${i}', expected '${e}'`}}return{authenticated:!0,username:i}}catch(t){let r=t instanceof Error?t.message:String(t);if(r.includes("ENOENT")||r.includes("not found"))return{authenticated:!1,error:"gh CLI not installed. Install from https://cli.github.com/"};return{authenticated:!1,error:`Failed to verify gh CLI: ${r}`}}}async function L0(e){if(!/^[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+$/.test(e))return{accepted:!1,error:`Invalid repository format: ${e}`};let{stdout:t,exitCode:r,stderr:n}=await F(["gh","api","/user/repository_invitations"]);if(r!==0){if(n.includes("not logged in")||n.includes("auth login"))return{accepted:!1,error:"gh CLI not authenticated. Run 'gh auth login' to authenticate."};if(n.includes("API rate limit")||n.includes("403"))return{accepted:!1,error:"GitHub API rate limit exceeded. Please try again in a few minutes."};if(n.includes("ENOENT")||n.includes("not found"))return{accepted:!1,error:"gh CLI not installed. Install from https://cli.github.com/"};return{accepted:!1,error:`Failed to list invitations: ${n.trim()||"unknown error"}`}}let i=null;try{i=JSON.parse(t||"[]").find((l)=>l.repository.full_name===e)?.id??null}catch(a){let c=a instanceof Error?a.message:String(a);return console.error("Failed to parse GitHub invitations response:",c),console.error(" Raw response (first 500 chars):",(t||"").slice(0,500)),{accepted:!1,error:`Failed to parse GitHub API response: ${c}`}}if(!i){let{exitCode:a}=await F(["gh","api",`/repos/${e}`,"--silent"]);if(a===0)return{accepted:!0,alreadyCollaborator:!0};return{accepted:!1,error:`No pending invitation found for ${e}. You may need to accept it manually via GitHub.`}}let{exitCode:s,stderr:o}=await F(["gh","api","--method","PATCH",`/user/repository_invitations/${i}`]);if(s!==0)return{accepted:!1,error:`Failed to accept invitation: ${o.trim()||"unknown error"}`};return{accepted:!0}}async function ni(e,t,r="origin"){let n=t;if(process.env.GH_TOKEN&&t.startsWith("git@github.com:")){let i=process.env.GH_TOKEN.trim();if(!i||/\s/.test(i))return{success:!1,error:"GH_TOKEN environment variable is set but appears malformed (empty or contains whitespace)"};n=`https://github.com/${t.replace("git@github.com:","")}`,await F(["git","config","credential.https://github.com.helper",`!printf 'username=x-access-token\\npassword=${i}'`],{cwd:e})}else if(t.startsWith("git@github.com:")){let i=t.replace("git@github.com:",""),s=await $d();if(s.token)n=`https://github.com/${i}`,await F(["git","config","credential.https://github.com.helper",`!printf 'username=x-access-token\\npassword=${s.token}'`],{cwd:e});else{let o=await yTe();if(o.works)n=t;else return{success:!1,error:`GitHub authentication not configured.
|
|
107
107
|
|
|
108
108
|
gh CLI failed: ${s.error||"could not get token"}
|
package/package.json
CHANGED