nemar-cli 0.9.16-dev.2287 → 0.9.16-dev.2290

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.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -102,7 +102,7 @@ ${l.dim(`eta: ${e.eta}`)}`:"";process.stderr.write(`${t}
102
102
  ${r} ${e.message}
103
103
  ${n}${i}
104
104
  ${t}
105
- `)}var OH=!1;var Lw=O(()=>{Ye()});var kH;var AH=O(()=>{kH={name:"nemar-cli",version:"0.9.16-dev.2287",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","generate-openapi":"bun run scripts/generate-openapi.ts",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",inquirer:"^9.2.15",ora:"^8.0.1",semver:"^7.8.5",zod:"^3.23.8"},"lint-staged":{"src/**/*.{ts,tsx}":["biome check --fix"],"backend/src/**/*.{ts,tsx}":["biome check --fix"]},devDependencies:{"@asteasolutions/zod-to-openapi":"^7.3.4","@biomejs/biome":"1.9.4","@types/bun":"latest","@types/inquirer":"^9.0.7","@types/semver":"^7.8.0",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 Yo;var Q0=O(()=>{AH();Yo=kH.version});function U(e){if(e instanceof Error)return e.message;return String(e)}var q,Jo;var ar=O(()=>{q=class q extends Error{statusCode;details;step;constructor(e,t,r,n){super(t);this.statusCode=e;this.details=r;this.step=n;this.name="ApiError"}};Jo=class Jo extends q{mode;eta;constructor(e,t,r,n){super(503,t,n);this.mode=e;this.eta=r;this.name="MaintenanceError"}}});function PH(){if(process.env.TEST_API_URL)return process.env.TEST_API_URL;if(Vw)return Uw;return bt().apiUrl||Uw}async function P(e,t={},r=!1,n){let i=`${PH()}${e}`,s={"Content-Type":"application/json","X-CLI-Version":Yo,...t.headers};if(r){let c=bt();if(!c.apiKey&&r===!0)throw new q(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 q(0,`Network error: Could not connect to ${PH()}`,{originalError:c instanceof Error?c.message:String(c)})}let a;try{a=await o.json()}catch{throw new q(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.",u=typeof a.eta==="string"?a.eta:null,d=new Jo(a.mode,c,u,a.details);throw X0(d),d}throw new q(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 q(o.status,`Response for ${e} did not match the expected NEMAR contract`,{issues:c.error.issues});return c.data}return a}var Uw="https://nemar-api-dev.sccn-org.workers.dev",Vw;var Ks=O(()=>{Ws();Lw();Q0();ar();Vw=Uw.includes("workers.dev")});async function IH(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 TH(e){return P(`/admin/approve/${e}`,{method:"POST"},!0)}async function NH(e){return P(`/admin/approve/by-id/${e}`,{method:"POST"},!0)}async function qH(e){return P(`/admin/revoke/${e}`,{method:"POST"},!0)}async function jH(e,t){return P(`/admin/users/${e}/role`,{method:"POST",body:JSON.stringify({role:t})},!0)}async function zw(e,t){return P(`/admin/datasets/${e}/visibility`,{method:"PATCH",body:JSON.stringify({visibility:t})},!0)}async function MH(e){return P(`/datasets/${e}/publish`,{method:"POST"},!0)}async function BH(e){return P(`/admin/datasets/${e}/ci`,{},!0)}async function Vi(e){return P(`/admin/datasets/${e}/ci`,{method:"POST"},!0)}async function Hw(e){return P(`/admin/datasets/${e}/ci/validate`,{method:"POST"},!0)}async function Gw(e){return P(`/admin/datasets/${e}/ci/sync`,{method:"POST"},!0)}async function LH(e,t){return P(`/admin/datasets/${e}/doi/concept`,{method:"POST",body:JSON.stringify(t)},!0)}async function qd(e){return P(`/admin/datasets/${e}/doi`,{},!0)}async function Ww(e,t){return P(`/admin/datasets/${e}/doi/update`,{method:"POST",body:JSON.stringify(t)},!0)}async function UH(e,t){return P(`/admin/datasets/${e}/withdraw`,{method:"POST",body:JSON.stringify({reason:t.reason,dry_run:t.dryRun})},!0)}async function VH(e,t){return P(`/admin/datasets/${e}/restore`,{method:"POST",body:JSON.stringify({dry_run:t.dryRun})},!0)}async function zH(e){return P(`/admin/datasets/${e}/reset`,{method:"POST"},!0)}async function HH(e,t=!1){return P(`/admin/datasets/${e}`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({force:t})},!0)}async function GH(e){return P("/admin/datasets/bulk-delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dataset_ids:e})},!0)}async function WH(e){return P("/admin/datasets/import",{method:"POST",body:JSON.stringify(e)},!0)}async function KH(e){return P("/admin/datasets/exemplar",{method:"POST",body:JSON.stringify(e)},!0)}async function YH(e){return P(`/admin/datasets/${e}/exemplar/remint-dois`,{method:"POST"},!0)}async function Kw(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 JH(e){return P(`/admin/imports/${e}/rollback`,{method:"POST"},!0)}async function XH(e){return P(`/admin/imports/${e}/retry`,{method:"POST"},!0)}async function Yw(e){return P(`/admin/imports/${e}/verify`,{method:"POST"},!0)}async function QH(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 ZH(e,t){return P("/admin/datasets/reindex/bulk",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filter:e,...t??{}})},!0)}async function eG(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 tG(){return P("/admin/datasets/hed-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function rG(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 nG(){return P("/admin/datasets/recording-stats-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function iG(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 sG(){return P("/admin/datasets/signal-defaults-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function oG(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 aG(){return P("/admin/datasets/data-integrity-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function cG(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 uG(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 lG(){return P("/admin/datasets/availability-report-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function dG(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 Xc(e,t){return P(`/admin/datasets/${e}/enforce`,{method:"POST",body:JSON.stringify({dry_run:t})},!0)}async function fG(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 pG(e,t=!1){return P(`/admin/datasets/${e}/revalidate${t?"?force=true":""}`,{method:"POST"},!0)}async function mG(e){let t=e?`?user=${encodeURIComponent(e)}`:"";return P(`/admin/email-preferences${t}`,{},!0)}async function hG(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 Jw(e){return P("/admin/notify",{method:"POST",body:JSON.stringify(e)},!0)}async function gG(){return P("/admin/summary/coverage",{},!0)}async function yG(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 Xw(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 Qw(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 xG(){return P("/admin/zarr-catalog/publish",{method:"POST"},!0)}async function bG(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 Qc=O(()=>{Ks()});async function pi(e,t){return P(`/datasets/${e}/upload-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:t})},!0)}async function Zw(e,t){return P(`/datasets/${e}/download-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:t})},!0)}async function vG(e){return P(`/admin/datasets/${e}/files`,{},!0)}async function _G(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 q(500,"S3 lock paginated response missing continuation_token; aborting to avoid infinite loop")}return{locked:r,failed:n}}var Zc=O(()=>{Ks();ar()});function XNe(e){return e.startsWith("v")?e:`v${e}`}var YNe,JNe,wG,vit;var eD=O(()=>{Wo();YNe=/^v?\d+\.\d+\.\d+(?:-(?:rc|alpha|beta)\d*)?$/,JNe=/^v\d+\.\d+\.\d+(?:-(?:rc|alpha|beta)\d*)?$/;wG=E.string().regex(YNe,"must be a semver version, optionally v-prefixed").transform(XNe),vit=E.string().regex(JNe,"must be the canonical v-prefixed tag (vX.Y.Z)")});var QNe,ZNe,DG;var EG=O(()=>{Wo();QNe=E.object({id:E.number().int(),username:E.string().nullable(),email:E.string(),github_username:E.string().nullable(),role:E.string(),orcid:E.string().nullable().optional(),created_at:E.string().optional(),approved_at:E.string().nullable().optional(),dataset_count:E.number().int().optional(),sandbox_completed:E.boolean().optional(),sandbox_completed_at:E.string().nullable().optional(),sandbox_dataset_id:E.string().nullable().optional()}).passthrough(),ZNe=E.object({prefix:E.string(),created_at:E.string(),last_used_at:E.string().nullable()}).passthrough().nullable(),DG=E.object({user:QNe,token:ZNe.optional()}).passthrough()});function $G(e,t){if(e.zarr_index_url!=null&&e.zarr_status!=="ready")t.addIssue({code:E.ZodIssueCode.custom,message:"zarr_index_url must be null/absent unless zarr_status is 'ready'",path:["zarr_index_url"]})}function CG(e,t){if(e.zarr_verified_at!=null&&e.zarr_verify_status==null)t.addIssue({code:E.ZodIssueCode.custom,message:"zarr_verified_at must be null/absent unless zarr_verify_status is non-null",path:["zarr_verified_at"]})}var e9e="0.4.0",tD,eu,SG,t9e,r9e,n9e,RG,$it,FG,Cit,zi,i9e,Z0,Rit;var rD=O(()=>{Wo();eD();tD=E.enum(["openneuro","nemar","gin","other"]),eu=E.union([E.literal(0),E.literal(1)]).nullable(),SG=E.object({dataset_id:E.string(),id:E.string().optional(),name:E.string(),description:E.string().nullable().optional(),status:E.string(),visibility:E.string(),concept_doi:E.string().nullable().optional(),doi:E.string().nullable().optional(),created_at:E.string(),updated_at:E.string().optional(),owner_username:E.string().nullable().optional(),source:E.string().nullable().optional(),modalities:E.string().optional(),participants:E.number().int().nonnegative(),tasks:E.string().optional(),authors:E.string().optional(),license:E.string().optional(),file_size:E.number().nonnegative(),file_size_formatted:E.string().optional(),total_files:E.number().nonnegative().nullable().optional(),num_citations:E.number().int().nonnegative().optional(),n_channels:E.number().int().nullable().optional(),electrode_system:E.string().nullable().optional(),has_hed:eu.optional(),hed_version:E.string().nullable().optional(),data_complete:eu.optional(),bytes_present:E.number().nonnegative().nullable().optional(),latest_version:wG.nullable().optional(),subject_count:E.number().int().nullable().optional(),file_size_bytes:E.number().nullable().optional(),sessions_count:E.number().int().nullable().optional(),age_min:E.number().nullable().optional(),age_max:E.number().nullable().optional(),bids_version:E.string().nullable().optional(),zarr_status:E.enum(["pending","ready","failed"]).nullable().optional(),zarr_store_count:E.number().int().nullable().optional(),zarr_converted_at:E.string().nullable().optional(),zarr_source_commit:E.string().nullable().optional(),zarr_errors:E.number().int().nullable().optional(),zarr_failure_count:E.number().int().nullable().optional(),zarr_deterministic:eu.optional(),zarr_failed_at:E.string().nullable().optional(),zarr_index_url:E.string().nullable().optional(),zarr_verify_status:E.enum(["verified","failed","unverifiable"]).nullable().optional(),zarr_verified_at:E.string().nullable().optional(),total_recording_duration:E.number().nullable().optional(),recording_duration_min:E.number().nullable().optional(),recording_duration_max:E.number().nullable().optional(),recording_count:E.number().int().nullable().optional(),recordings_unavailable:E.number().int().nullable().optional(),channel_count_min:E.number().int().nullable().optional(),channel_count_max:E.number().int().nullable().optional(),sampling_frequency:E.number().nullable().optional(),power_line_frequency:E.number().nullable().optional(),eeg_reference:E.string().nullable().optional(),placement_scheme:E.string().nullable().optional()}).passthrough();t9e=SG.superRefine((e,t)=>{$G(e,t),CG(e,t)}),r9e=SG.extend({file_size:E.number().nonnegative().nullable(),file_size_formatted:E.string().nullable().optional(),modalities:E.string().nullable().optional(),tasks:E.string().nullable().optional(),authors:E.string().nullable().optional(),license:E.string().nullable().optional(),owner_github:E.string().nullable().optional(),attestation_deposit_type:E.enum(["owner","redistribution"]).nullable().optional(),attestation_key_status:E.enum(["destroyed","retained"]).nullable().optional(),attestation_deidentified:eu.optional(),attestation_no_duplicate:eu.optional(),attestation_upstream_source:E.string().nullable().optional(),attestation_accepted_at:E.string().nullable().optional(),zarr_data_failures:E.object({count:E.number().int().nonnegative(),detail_ref:E.string(),compacted_by:E.string().optional(),pending:E.number().int().nonnegative().optional(),discovered:E.number().int().nonnegative().optional(),events_upload_failed:E.literal(!0).optional(),manifest_upload_failed:E.literal(!0).optional()}).passthrough().nullable().optional()}).passthrough().superRefine((e,t)=>{$G(e,t),CG(e,t)}),n9e=E.object({id:E.string(),name:E.string(),modalities:E.string().nullable().optional(),participants:E.number().int().nullable().optional(),doi:E.string().nullable().optional(),tasks:E.string().nullable().optional(),authors:E.string().nullable().optional(),has_hed:eu.optional(),score:E.number().optional(),snippet:E.string().optional()}).passthrough(),RG=E.record(E.string(),E.number().int().nonnegative()),$it=E.object({datasets:E.array(t9e),count:E.number().int().nonnegative(),total_count:E.number().int().nonnegative().optional(),limit:E.number().int().optional(),offset:E.number().int().optional(),excluded_unknown:E.number().int().nonnegative().optional(),excluded_unknown_by_facet:RG.optional()}).passthrough(),FG=E.object({results:E.array(n9e),count:E.number().int().nonnegative(),returned:E.number().int().nonnegative().optional(),offset:E.number().int().nonnegative().optional(),limit:E.number().int().optional(),candidate_ceiling:E.number().int().optional(),truncated:E.boolean().optional(),method:E.enum(["exact_id","text","text_fallback","semantic","unavailable"]).optional(),min_score:E.number().optional(),warning:E.string().optional(),excluded_unknown:E.number().int().nonnegative().optional(),excluded_unknown_by_facet:RG.optional()}).passthrough(),Cit=E.object({dataset:r9e}).passthrough(),zi=E.object({value:E.string(),count:E.number().int().nonnegative()}),i9e=E.object({values:E.array(zi),distinct_total:E.number().int().nonnegative(),truncated:E.boolean()}),Z0=E.object({"electrode-system":E.array(zi).optional(),source:E.array(zi).optional(),zarr:E.array(zi).optional(),powerline:E.array(zi).optional(),"bids-version":E.array(zi).optional(),"hed-version":E.array(zi).optional(),license:E.array(zi).optional(),modality:E.array(zi).optional(),task:i9e.optional(),warning:E.string().optional()}).passthrough(),Rit=E.object({schema_version:E.literal(e9e),doc_type:E.literal("dataset"),dataset_id:E.string().regex(/^[a-z]{2}\d+$/,"neuroschema dataset_id pattern"),name:E.string(),source:tD,recording_modality:E.array(E.string()).min(1),description:E.string().nullable().optional(),bids_version:E.string().nullable().optional(),license:E.string().nullable().optional()}).passthrough()});var eh=O(()=>{eD();EG();rD()});async function rh(e){return P(`/datasets/${e}/ci/status`,{},!0)}async function OG(e){return P(`/datasets/${e}/manifest`,{},!0)}async function nh(e,t){return P(`/datasets/${e}/manifest/${t}`,{},!0)}function AG(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 tu(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(AG),n}async function kG(e){return P(`/datasets/resolve/${e}`,{},"optional")}async function PG(){return P("/datasets/facets",{signal:AbortSignal.timeout(5000)},"optional",Z0)}async function IG(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",FG)}async function vt(e){let t=await P(`/datasets/${e}`,{},"optional");return AG(t.dataset)}async function TG(e){return P(`/datasets/${e}/versions`,{},!0)}async function ih(e){return P("/datasets",{method:"POST",body:JSON.stringify(e)},!0)}async function sh(e){return P(`/datasets/${e}/finalize`,{method:"POST"},!0)}async function nD(e){return P(`/datasets/${e}/request-access`,{method:"POST"},!0)}async function NG(e,t){let r=t?`?status=${t}`:"";return P(`/datasets/${e}/access-requests${r}`,{},!0)}async function qG(e,t){return P(`/datasets/${e}/access-requests/${t}/approve`,{method:"POST"},!0)}async function jG(e,t){return P(`/datasets/${e}/access-requests/${t}/deny`,{method:"POST"},!0)}async function MG(e,t){return P(`/datasets/${e}/invite`,{method:"POST",body:JSON.stringify({username:t})},!0)}async function BG(e){return P(`/datasets/${e}/collaborators`,{},!0)}async function LG(e,t){return P(`/admin/datasets/${e}/enrichment`,{method:"POST",body:JSON.stringify(t)},!0)}var th;var Ys=O(()=>{eh();Ks();th=/^\d{4}-\d{4}-\d{4}-\d{3}[\dX]$/});var ru;var GG=O(()=>{ru=["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 nu(e){return P(`/datasets/${e}/publish/request`,{method:"POST"},!0)}async function KG(e){return P(`/datasets/${e}/publish/status`,{},!0)}async function YG(e){return P(`/datasets/${e}/publish/resend`,{method:"POST"},!0)}async function JG(e){let t=e?`?status=${e}`:"";return P(`/admin/publish/requests${t}`,{},!0)}async function XG(e,t){return P(`/admin/publish/${e}/deny`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:t})},!0)}function s9e(e,t=[]){if(e){let r=ru.indexOf(e);if(r>=0)return r+1}return Math.min(t.length+1,ru.length)}function o9e(e){if(!(e instanceof q))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 iu(e,t=!1,r=!1,n=!1,i,s){let c,u,d=0,f=!1,m,p=t,g=[],y;function x(v,_,S,C){if(!s)return;s({step:v,stepIndex:s9e(v,_),stepTotal:ru.length,s3LockLocked:S,s3LockTotal:C,s3LockResumed:v==="s3_lock"&&f?!0:void 0})}for(let v=1;v<=5;v++)try{let _,S=!0;do{if(_=await P(`/admin/publish/${e}/approve`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({resume:S?p:!0,sandbox:r,s3_lock_continuation_token:c,s3_lock_total:u,skip_ci_check:n})},!0),S=!1,_.step_results)g.push(..._.step_results);if(_.s3_lock_total!==void 0)u=_.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"?u: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=WG(g);return _}catch(_){if(y=_,v===5||!o9e(_)){if(_ instanceof q&&g.length>0)_.stepResults=WG(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 WG(e){let t=new Map;for(let r of e)t.set(r.step,r);return Array.from(t.values())}var jd=O(()=>{GG();Ks();ar()});function eW(e){oD=e}function aD(){return oD}function Md(e){if(oD)process.stderr.write(`${e}
105
+ `)}var OH=!1;var Lw=O(()=>{Ye()});var kH;var AH=O(()=>{kH={name:"nemar-cli",version:"0.9.16-dev.2290",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","generate-openapi":"bun run scripts/generate-openapi.ts",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",inquirer:"^9.2.15",ora:"^8.0.1",semver:"^7.8.5",zod:"^3.23.8"},"lint-staged":{"src/**/*.{ts,tsx}":["biome check --fix"],"backend/src/**/*.{ts,tsx}":["biome check --fix"]},devDependencies:{"@asteasolutions/zod-to-openapi":"^7.3.4","@biomejs/biome":"1.9.4","@types/bun":"latest","@types/inquirer":"^9.0.7","@types/semver":"^7.8.0",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 Yo;var Q0=O(()=>{AH();Yo=kH.version});function U(e){if(e instanceof Error)return e.message;return String(e)}var q,Jo;var ar=O(()=>{q=class q extends Error{statusCode;details;step;constructor(e,t,r,n){super(t);this.statusCode=e;this.details=r;this.step=n;this.name="ApiError"}};Jo=class Jo extends q{mode;eta;constructor(e,t,r,n){super(503,t,n);this.mode=e;this.eta=r;this.name="MaintenanceError"}}});function PH(){if(process.env.TEST_API_URL)return process.env.TEST_API_URL;if(Vw)return Uw;return bt().apiUrl||Uw}async function P(e,t={},r=!1,n){let i=`${PH()}${e}`,s={"Content-Type":"application/json","X-CLI-Version":Yo,...t.headers};if(r){let c=bt();if(!c.apiKey&&r===!0)throw new q(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 q(0,`Network error: Could not connect to ${PH()}`,{originalError:c instanceof Error?c.message:String(c)})}let a;try{a=await o.json()}catch{throw new q(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.",u=typeof a.eta==="string"?a.eta:null,d=new Jo(a.mode,c,u,a.details);throw X0(d),d}throw new q(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 q(o.status,`Response for ${e} did not match the expected NEMAR contract`,{issues:c.error.issues});return c.data}return a}var Uw="https://nemar-api-dev.sccn-org.workers.dev",Vw;var Ks=O(()=>{Ws();Lw();Q0();ar();Vw=Uw.includes("workers.dev")});async function IH(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 TH(e){return P(`/admin/approve/${e}`,{method:"POST"},!0)}async function NH(e){return P(`/admin/approve/by-id/${e}`,{method:"POST"},!0)}async function qH(e){return P(`/admin/revoke/${e}`,{method:"POST"},!0)}async function jH(e,t){return P(`/admin/users/${e}/role`,{method:"POST",body:JSON.stringify({role:t})},!0)}async function zw(e,t){return P(`/admin/datasets/${e}/visibility`,{method:"PATCH",body:JSON.stringify({visibility:t})},!0)}async function MH(e){return P(`/datasets/${e}/publish`,{method:"POST"},!0)}async function BH(e){return P(`/admin/datasets/${e}/ci`,{},!0)}async function Vi(e){return P(`/admin/datasets/${e}/ci`,{method:"POST"},!0)}async function Hw(e){return P(`/admin/datasets/${e}/ci/validate`,{method:"POST"},!0)}async function Gw(e){return P(`/admin/datasets/${e}/ci/sync`,{method:"POST"},!0)}async function LH(e,t){return P(`/admin/datasets/${e}/doi/concept`,{method:"POST",body:JSON.stringify(t)},!0)}async function qd(e){return P(`/admin/datasets/${e}/doi`,{},!0)}async function Ww(e,t){return P(`/admin/datasets/${e}/doi/update`,{method:"POST",body:JSON.stringify(t)},!0)}async function UH(e,t){return P(`/admin/datasets/${e}/withdraw`,{method:"POST",body:JSON.stringify({reason:t.reason,dry_run:t.dryRun})},!0)}async function VH(e,t){return P(`/admin/datasets/${e}/restore`,{method:"POST",body:JSON.stringify({dry_run:t.dryRun})},!0)}async function zH(e){return P(`/admin/datasets/${e}/reset`,{method:"POST"},!0)}async function HH(e,t=!1){return P(`/admin/datasets/${e}`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({force:t})},!0)}async function GH(e){return P("/admin/datasets/bulk-delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dataset_ids:e})},!0)}async function WH(e){return P("/admin/datasets/import",{method:"POST",body:JSON.stringify(e)},!0)}async function KH(e){return P("/admin/datasets/exemplar",{method:"POST",body:JSON.stringify(e)},!0)}async function YH(e){return P(`/admin/datasets/${e}/exemplar/remint-dois`,{method:"POST"},!0)}async function Kw(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 JH(e){return P(`/admin/imports/${e}/rollback`,{method:"POST"},!0)}async function XH(e){return P(`/admin/imports/${e}/retry`,{method:"POST"},!0)}async function Yw(e){return P(`/admin/imports/${e}/verify`,{method:"POST"},!0)}async function QH(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 ZH(e,t){return P("/admin/datasets/reindex/bulk",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filter:e,...t??{}})},!0)}async function eG(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 tG(){return P("/admin/datasets/hed-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function rG(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 nG(){return P("/admin/datasets/recording-stats-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function iG(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 sG(){return P("/admin/datasets/signal-defaults-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function oG(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 aG(){return P("/admin/datasets/data-integrity-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function cG(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 uG(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 lG(){return P("/admin/datasets/availability-report-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function dG(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 Xc(e,t){return P(`/admin/datasets/${e}/enforce`,{method:"POST",body:JSON.stringify({dry_run:t})},!0)}async function fG(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 pG(e,t=!1){return P(`/admin/datasets/${e}/revalidate${t?"?force=true":""}`,{method:"POST"},!0)}async function mG(e){let t=e?`?user=${encodeURIComponent(e)}`:"";return P(`/admin/email-preferences${t}`,{},!0)}async function hG(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 Jw(e){return P("/admin/notify",{method:"POST",body:JSON.stringify(e)},!0)}async function gG(){return P("/admin/summary/coverage",{},!0)}async function yG(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 Xw(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 Qw(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 xG(){return P("/admin/zarr-catalog/publish",{method:"POST"},!0)}async function bG(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 Qc=O(()=>{Ks()});async function pi(e,t){return P(`/datasets/${e}/upload-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:t})},!0)}async function Zw(e,t){return P(`/datasets/${e}/download-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:t})},!0)}async function vG(e){return P(`/admin/datasets/${e}/files`,{},!0)}async function _G(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 q(500,"S3 lock paginated response missing continuation_token; aborting to avoid infinite loop")}return{locked:r,failed:n}}var Zc=O(()=>{Ks();ar()});function XNe(e){return e.startsWith("v")?e:`v${e}`}var YNe,JNe,wG,vit;var eD=O(()=>{Wo();YNe=/^v?\d+\.\d+\.\d+(?:-(?:rc|alpha|beta)\d*)?$/,JNe=/^v\d+\.\d+\.\d+(?:-(?:rc|alpha|beta)\d*)?$/;wG=E.string().regex(YNe,"must be a semver version, optionally v-prefixed").transform(XNe),vit=E.string().regex(JNe,"must be the canonical v-prefixed tag (vX.Y.Z)")});var QNe,ZNe,DG;var EG=O(()=>{Wo();QNe=E.object({id:E.number().int(),username:E.string().nullable(),email:E.string(),github_username:E.string().nullable(),role:E.string(),orcid:E.string().nullable().optional(),created_at:E.string().optional(),approved_at:E.string().nullable().optional(),dataset_count:E.number().int().optional(),sandbox_completed:E.boolean().optional(),sandbox_completed_at:E.string().nullable().optional(),sandbox_dataset_id:E.string().nullable().optional()}).passthrough(),ZNe=E.object({prefix:E.string(),created_at:E.string(),last_used_at:E.string().nullable()}).passthrough().nullable(),DG=E.object({user:QNe,token:ZNe.optional()}).passthrough()});function $G(e,t){if(e.zarr_index_url!=null&&e.zarr_status!=="ready")t.addIssue({code:E.ZodIssueCode.custom,message:"zarr_index_url must be null/absent unless zarr_status is 'ready'",path:["zarr_index_url"]})}function CG(e,t){if(e.zarr_verified_at!=null&&e.zarr_verify_status==null)t.addIssue({code:E.ZodIssueCode.custom,message:"zarr_verified_at must be null/absent unless zarr_verify_status is non-null",path:["zarr_verified_at"]})}var e9e="0.4.0",tD,eu,SG,t9e,r9e,n9e,RG,$it,FG,Cit,zi,i9e,Z0,Rit;var rD=O(()=>{Wo();eD();tD=E.enum(["openneuro","nemar","gin","other"]),eu=E.union([E.literal(0),E.literal(1)]).nullable(),SG=E.object({dataset_id:E.string(),id:E.string().optional(),name:E.string(),description:E.string().nullable().optional(),status:E.string(),visibility:E.string(),concept_doi:E.string().nullable().optional(),doi:E.string().nullable().optional(),created_at:E.string(),updated_at:E.string().optional(),owner_username:E.string().nullable().optional(),source:E.string().nullable().optional(),modalities:E.string().optional(),participants:E.number().int().nonnegative(),tasks:E.string().optional(),authors:E.string().optional(),license:E.string().optional(),file_size:E.number().nonnegative(),file_size_formatted:E.string().optional(),total_files:E.number().nonnegative().nullable().optional(),num_citations:E.number().int().nonnegative().optional(),n_channels:E.number().int().nullable().optional(),electrode_system:E.string().nullable().optional(),has_hed:eu.optional(),hed_version:E.string().nullable().optional(),data_complete:eu.optional(),bytes_present:E.number().nonnegative().nullable().optional(),latest_version:wG.nullable().optional(),subject_count:E.number().int().nullable().optional(),file_size_bytes:E.number().nullable().optional(),sessions_count:E.number().int().nullable().optional(),age_min:E.number().nullable().optional(),age_max:E.number().nullable().optional(),bids_version:E.string().nullable().optional(),zarr_status:E.enum(["pending","ready","failed"]).nullable().optional(),zarr_store_count:E.number().int().nullable().optional(),zarr_converted_at:E.string().nullable().optional(),zarr_source_commit:E.string().nullable().optional(),zarr_errors:E.number().int().nullable().optional(),zarr_failure_count:E.number().int().nullable().optional(),zarr_deterministic:eu.optional(),zarr_failed_at:E.string().nullable().optional(),zarr_index_url:E.string().nullable().optional(),zarr_verify_status:E.enum(["verified","failed","unverifiable"]).nullable().optional(),zarr_verified_at:E.string().nullable().optional(),total_recording_duration:E.number().nullable().optional(),recording_duration_min:E.number().nullable().optional(),recording_duration_max:E.number().nullable().optional(),recording_count:E.number().int().nullable().optional(),recordings_unavailable:E.number().int().nullable().optional(),channel_count_min:E.number().int().nullable().optional(),channel_count_max:E.number().int().nullable().optional(),sampling_frequency:E.number().nullable().optional(),power_line_frequency:E.number().nullable().optional(),eeg_reference:E.string().nullable().optional(),placement_scheme:E.string().nullable().optional()}).passthrough();t9e=SG.superRefine((e,t)=>{$G(e,t),CG(e,t)}),r9e=SG.extend({file_size:E.number().nonnegative().nullable(),file_size_formatted:E.string().nullable().optional(),modalities:E.string().nullable().optional(),tasks:E.string().nullable().optional(),authors:E.string().nullable().optional(),license:E.string().nullable().optional(),owner_github:E.string().nullable().optional(),attestation_deposit_type:E.enum(["owner","redistribution"]).nullable().optional(),attestation_key_status:E.enum(["destroyed","retained"]).nullable().optional(),attestation_deidentified:eu.optional(),attestation_no_duplicate:eu.optional(),attestation_upstream_source:E.string().nullable().optional(),attestation_accepted_at:E.string().nullable().optional(),zarr_data_failures:E.object({count:E.number().int().nonnegative(),detail_ref:E.string(),compacted_by:E.string().optional(),pending:E.number().int().nonnegative().optional(),discovered:E.number().int().nonnegative().optional(),events_upload_failed:E.literal(!0).optional(),manifest_upload_failed:E.literal(!0).optional()}).passthrough().nullable().optional()}).passthrough().superRefine((e,t)=>{$G(e,t),CG(e,t)}),n9e=E.object({id:E.string(),name:E.string(),modalities:E.string().nullable().optional(),participants:E.number().int().nullable().optional(),doi:E.string().nullable().optional(),tasks:E.string().nullable().optional(),authors:E.string().nullable().optional(),has_hed:eu.optional(),score:E.number().optional(),snippet:E.string().optional()}).passthrough(),RG=E.record(E.string(),E.number().int().nonnegative()),$it=E.object({datasets:E.array(t9e),count:E.number().int().nonnegative(),total_count:E.number().int().nonnegative().optional(),limit:E.number().int().optional(),offset:E.number().int().optional(),excluded_unknown:E.number().int().nonnegative().optional(),excluded_unknown_by_facet:RG.optional()}).passthrough(),FG=E.object({results:E.array(n9e),count:E.number().int().nonnegative(),returned:E.number().int().nonnegative().optional(),offset:E.number().int().nonnegative().optional(),limit:E.number().int().optional(),candidate_ceiling:E.number().int().optional(),truncated:E.boolean().optional(),method:E.enum(["exact_id","text","text_fallback","semantic","unavailable"]).optional(),min_score:E.number().optional(),warning:E.string().optional(),excluded_unknown:E.number().int().nonnegative().optional(),excluded_unknown_by_facet:RG.optional()}).passthrough(),Cit=E.object({dataset:r9e}).passthrough(),zi=E.object({value:E.string(),count:E.number().int().nonnegative()}),i9e=E.object({values:E.array(zi),distinct_total:E.number().int().nonnegative(),truncated:E.boolean()}),Z0=E.object({"electrode-system":E.array(zi).optional(),source:E.array(zi).optional(),zarr:E.array(zi).optional(),powerline:E.array(zi).optional(),"bids-version":E.array(zi).optional(),"hed-version":E.array(zi).optional(),license:E.array(zi).optional(),modality:E.array(zi).optional(),task:i9e.optional(),warning:E.string().optional()}).passthrough(),Rit=E.object({schema_version:E.literal(e9e),doc_type:E.literal("dataset"),dataset_id:E.string().regex(/^[a-z]{2}\d+$/,"neuroschema dataset_id pattern"),name:E.string(),source:tD,recording_modality:E.array(E.string()).min(1),description:E.string().nullable().optional(),bids_version:E.string().nullable().optional(),license:E.string().nullable().optional()}).passthrough()});var eh=O(()=>{eD();EG();rD()});async function rh(e){return P(`/datasets/${e}/ci/status`,{},!0)}async function OG(e){return P(`/datasets/${e}/manifest`,{},!0)}async function nh(e,t){return P(`/datasets/${e}/manifest/${t}`,{},!0)}function AG(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 tu(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(AG),n}async function kG(e){return P(`/datasets/resolve/${e}`,{},"optional")}async function PG(){return P("/datasets/facets",{signal:AbortSignal.timeout(5000)},"optional",Z0)}async function IG(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",FG)}async function vt(e){let t=await P(`/datasets/${e}`,{},"optional");return AG(t.dataset)}async function TG(e){return P(`/datasets/${e}/versions`,{},!0)}async function ih(e){return P("/datasets",{method:"POST",body:JSON.stringify(e)},!0)}async function sh(e){return P(`/datasets/${e}/finalize`,{method:"POST"},!0)}async function nD(e){return P(`/datasets/${e}/request-access`,{method:"POST"},!0)}async function NG(e,t){let r=t?`?status=${t}`:"";return P(`/datasets/${e}/access-requests${r}`,{},!0)}async function qG(e,t){return P(`/datasets/${e}/access-requests/${t}/approve`,{method:"POST"},!0)}async function jG(e,t){return P(`/datasets/${e}/access-requests/${t}/deny`,{method:"POST"},!0)}async function MG(e,t){return P(`/datasets/${e}/invite`,{method:"POST",body:JSON.stringify({username:t})},!0)}async function BG(e){return P(`/datasets/${e}/collaborators`,{},!0)}async function LG(e,t){return P(`/admin/datasets/${e}/enrichment`,{method:"POST",body:JSON.stringify(t)},!0)}var th;var Ys=O(()=>{eh();Ks();th=/^\d{4}-\d{4}-\d{4}-\d{3}[\dX]$/});var ru;var GG=O(()=>{ru=["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 nu(e){return P(`/datasets/${e}/publish/request`,{method:"POST"},!0)}async function KG(e){return P(`/datasets/${e}/publish/status`,{},!0)}async function YG(e){return P(`/datasets/${e}/publish/resend`,{method:"POST"},!0)}async function JG(e){let t=e?`?status=${e}`:"";return P(`/admin/publish/requests${t}`,{},!0)}async function XG(e,t){return P(`/admin/publish/${e}/deny`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:t})},!0)}function s9e(e,t=[]){if(e){let r=ru.indexOf(e);if(r>=0)return r+1}return Math.min(t.length+1,ru.length)}function o9e(e){if(!(e instanceof q))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 iu(e,t=!1,r=!1,n=!1,i,s){let c,u,d=0,f=!1,m,p=t,g=[],y;function x(v,_,S,C){if(!s)return;s({step:v,stepIndex:s9e(v,_),stepTotal:ru.length,s3LockLocked:S,s3LockTotal:C,s3LockResumed:v==="s3_lock"&&f?!0:void 0})}for(let v=1;v<=5;v++)try{let _,S=!0;do{if(_=await P(`/admin/publish/${e}/approve`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({resume:S?p:!0,sandbox:r,s3_lock_continuation_token:c,s3_lock_total:u,skip_ci_check:n})},!0),S=!1,_.step_results)g.push(..._.step_results);if(_.s3_lock_total!==void 0)u=_.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"?u: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=WG(g);return _}catch(_){if(y=_,v===5||!o9e(_)){if(_ instanceof q&&g.length>0)_.stepResults=WG(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 WG(e){let t=new Map;for(let r of e)t.set(r.step,r);return Array.from(t.values())}var jd=O(()=>{GG();Ks();ar()});function eW(e){oD=e}function aD(){return oD}function Md(e){if(oD)process.stderr.write(`${e}
106
106
  `)}var oD=!1;var tW={};Ji(tW,{runCommand:()=>F});var{spawn:a9e}=globalThis.Bun;async function F(e,t={}){let r={...process.env,GIT_TERMINAL_PROMPT:"0",...t.env};for(let u of t.unsetEnv??[])delete r[u];let n=a9e({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(aD()){let u=t.cwd?` (cwd=${t.cwd})`:"";Md(l.dim(`$ ${e.join(" ")}${u}`))}let o=await new Response(n.stdout).text(),a=await new Response(n.stderr).text(),c=await n.exited;if(s)clearTimeout(s);if(aD()){if(o.trim())Md(l.dim(o.trimEnd()));if(a.trim())Md(l.yellow(a.trimEnd()));Md(l.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 Yt=O(()=>{Ye()});async function c9e(){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 Bd(){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 oh(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 ah(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((u)=>u.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 mi(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 Bd();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 c9e();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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nemar-cli",
3
- "version": "0.9.16-dev.2287",
3
+ "version": "0.9.16-dev.2290",
4
4
  "description": "CLI for NEMAR (Neuroelectromagnetic Data Archive and Tools Resource) dataset management",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",