nemar-cli 0.9.14-dev.2230 → 0.9.14-dev.2231
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 Sz=!1;var nD=A(()=>{He()});var Cz;var $z=A(()=>{Cz={name:"nemar-cli",version:"0.9.14-dev.2230",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","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 Om=A(()=>{$z();To=Cz.version});function V(e){if(e instanceof Error)return e.message;return String(e)}var q,No;var er=A(()=>{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"}};No=class No extends q{mode;eta;constructor(e,t,r,n){super(503,t,n);this.mode=e;this.eta=r;this.name="MaintenanceError"}}});function Fz(){if(process.env.TEST_API_URL)return process.env.TEST_API_URL;if(sD)return iD;return ht().apiUrl||iD}async function P(e,t={},r=!1,n){let i=`${Fz()}${e}`,s={"Content-Type":"application/json","X-CLI-Version":To,...t.headers};if(r){let c=ht();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 ${Fz()}`,{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.",l=typeof a.eta==="string"?a.eta:null,d=new No(a.mode,c,l,a.details);throw Rm(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 iD="https://nemar-api-dev.sccn-org.workers.dev",sD;var Ns=A(()=>{Ts();nD();Om();er();sD=iD.includes("workers.dev")});async function Rz(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 Oz(e){return P(`/admin/approve/${e}`,{method:"POST"},!0)}async function Az(e){return P(`/admin/approve/by-id/${e}`,{method:"POST"},!0)}async function kz(e){return P(`/admin/revoke/${e}`,{method:"POST"},!0)}async function Pz(e,t){return P(`/admin/users/${e}/role`,{method:"POST",body:JSON.stringify({role:t})},!0)}async function oD(e,t){return P(`/admin/datasets/${e}/visibility`,{method:"PATCH",body:JSON.stringify({visibility:t})},!0)}async function Iz(e){return P(`/datasets/${e}/publish`,{method:"POST"},!0)}async function Tz(e){return P(`/admin/datasets/${e}/ci`,{},!0)}async function Ai(e){return P(`/admin/datasets/${e}/ci`,{method:"POST"},!0)}async function aD(e){return P(`/admin/datasets/${e}/ci/validate`,{method:"POST"},!0)}async function cD(e){return P(`/admin/datasets/${e}/ci/sync`,{method:"POST"},!0)}async function Nz(e,t){return P(`/admin/datasets/${e}/doi/concept`,{method:"POST",body:JSON.stringify(t)},!0)}async function _d(e){return P(`/admin/datasets/${e}/doi`,{},!0)}async function uD(e,t){return P(`/admin/datasets/${e}/doi/update`,{method:"POST",body:JSON.stringify(t)},!0)}async function qz(e,t){return P(`/admin/datasets/${e}/withdraw`,{method:"POST",body:JSON.stringify({reason:t.reason,dry_run:t.dryRun})},!0)}async function jz(e,t){return P(`/admin/datasets/${e}/restore`,{method:"POST",body:JSON.stringify({dry_run:t.dryRun})},!0)}async function Mz(e){return P(`/admin/datasets/${e}/reset`,{method:"POST"},!0)}async function Bz(e,t=!1){return P(`/admin/datasets/${e}`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({force:t})},!0)}async function Lz(e){return P("/admin/datasets/bulk-delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dataset_ids:e})},!0)}async function Uz(e){return P("/admin/datasets/import",{method:"POST",body:JSON.stringify(e)},!0)}async function Vz(e){return P("/admin/datasets/exemplar",{method:"POST",body:JSON.stringify(e)},!0)}async function zz(e){return P(`/admin/datasets/${e}/exemplar/remint-dois`,{method:"POST"},!0)}async function lD(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 Hz(e){return P(`/admin/imports/${e}/rollback`,{method:"POST"},!0)}async function Wz(e){return P(`/admin/imports/${e}/retry`,{method:"POST"},!0)}async function dD(e){return P(`/admin/imports/${e}/verify`,{method:"POST"},!0)}async function Gz(e){return P("/admin/imports/dispatch-cooldown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dataset_ids:e})},!0)}async function qc(e,t){return P(`/admin/datasets/${e}/reindex`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t??{})},!0)}async function Kz(e,t){return P("/admin/datasets/reindex/bulk",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filter:e,...t??{}})},!0)}async function Yz(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 Jz(){return P("/admin/datasets/hed-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function Xz(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 Qz(){return P("/admin/datasets/data-integrity-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function Zz(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 eH(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 tH(){return P("/admin/datasets/availability-report-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function rH(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 jc(e,t){return P(`/admin/datasets/${e}/enforce`,{method:"POST",body:JSON.stringify({dry_run:t})},!0)}async function nH(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 iH(e,t=!1){return P(`/admin/datasets/${e}/revalidate${t?"?force=true":""}`,{method:"POST"},!0)}async function sH(e){let t=e?`?user=${encodeURIComponent(e)}`:"";return P(`/admin/email-preferences${t}`,{},!0)}async function oH(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 fD(e){return P("/admin/notify",{method:"POST",body:JSON.stringify(e)},!0)}async function aH(){return P("/admin/summary/coverage",{},!0)}async function cH(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 pD(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 mD(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 uH(){return P("/admin/zarr-catalog/publish",{method:"POST"},!0)}async function lH(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 ti(e,t){return P(`/datasets/${e}/upload-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:t})},!0)}async function hD(e,t){return P(`/datasets/${e}/download-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:t})},!0)}async function dH(e){return P(`/admin/datasets/${e}/files`,{},!0)}async function fH(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 Bc=A(()=>{Ns();er()});function ZIe(e){return e.startsWith("v")?e:`v${e}`}var XIe,QIe,pH,mQe;var gD=A(()=>{Ic();XIe=/^v?\d+\.\d+\.\d+(?:-(?:rc|alpha|beta)\d*)?$/,QIe=/^v\d+\.\d+\.\d+(?:-(?:rc|alpha|beta)\d*)?$/;pH=E.string().regex(XIe,"must be a semver version, optionally v-prefixed").transform(ZIe),mQe=E.string().regex(QIe,"must be the canonical v-prefixed tag (vX.Y.Z)")});var eTe,tTe,mH;var hH=A(()=>{Ic();eTe=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(),tTe=E.object({prefix:E.string(),created_at:E.string(),last_used_at:E.string().nullable()}).passthrough().nullable(),mH=E.object({user:eTe,token:tTe.optional()}).passthrough()});function yH(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 xH(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 rTe="0.4.0",yD,Lc,gH,nTe,iTe,sTe,bH,vQe,vH,_Qe,ki,oTe,Am,DQe;var xD=A(()=>{Ic();gD();yD=E.enum(["openneuro","nemar","gin","other"]),Lc=E.union([E.literal(0),E.literal(1)]).nullable(),gH=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:Lc.optional(),hed_version:E.string().nullable().optional(),data_complete:Lc.optional(),bytes_present:E.number().nonnegative().nullable().optional(),latest_version:pH.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:Lc.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();nTe=gH.superRefine((e,t)=>{yH(e,t),xH(e,t)}),iTe=gH.extend({file_size:E.number().nonnegative().nullable(),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:Lc.optional(),attestation_no_duplicate:Lc.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)=>{yH(e,t),xH(e,t)}),sTe=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:Lc.optional(),score:E.number().optional(),snippet:E.string().optional()}).passthrough(),bH=E.record(E.string(),E.number().int().nonnegative()),vQe=E.object({datasets:E.array(nTe),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:bH.optional()}).passthrough(),vH=E.object({results:E.array(sTe),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:bH.optional()}).passthrough(),_Qe=E.object({dataset:iTe}).passthrough(),ki=E.object({value:E.string(),count:E.number().int().nonnegative()}),oTe=E.object({values:E.array(ki),distinct_total:E.number().int().nonnegative(),truncated:E.boolean()}),Am=E.object({"electrode-system":E.array(ki).optional(),source:E.array(ki).optional(),zarr:E.array(ki).optional(),powerline:E.array(ki).optional(),"bids-version":E.array(ki).optional(),"hed-version":E.array(ki).optional(),license:E.array(ki).optional(),modality:E.array(ki).optional(),task:oTe.optional(),warning:E.string().optional()}).passthrough(),DQe=E.object({schema_version:E.literal(rTe),doc_type:E.literal("dataset"),dataset_id:E.string().regex(/^[a-z]{2}\d+$/,"neuroschema dataset_id pattern"),name:E.string(),source:yD,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 km=A(()=>{gD();hH();xD()});async function Im(e){return P(`/datasets/${e}/ci/status`,{},!0)}async function _H(e){return P(`/datasets/${e}/manifest`,{},!0)}async function Tm(e,t){return P(`/datasets/${e}/manifest/${t}`,{},!0)}function DH(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(DH),n}async function wH(e){return P(`/datasets/resolve/${e}`,{},"optional")}async function EH(){return P("/datasets/facets",{signal:AbortSignal.timeout(5000)},"optional",Am)}async function SH(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",vH)}async function gt(e){let t=await P(`/datasets/${e}`,{},"optional");return DH(t.dataset)}async function $H(e){return P(`/datasets/${e}/versions`,{},!0)}async function Nm(e){return P("/datasets",{method:"POST",body:JSON.stringify(e)},!0)}async function qm(e){return P(`/datasets/${e}/finalize`,{method:"POST"},!0)}async function bD(e){return P(`/datasets/${e}/request-access`,{method:"POST"},!0)}async function CH(e,t){let r=t?`?status=${t}`:"";return P(`/datasets/${e}/access-requests${r}`,{},!0)}async function FH(e,t){return P(`/datasets/${e}/access-requests/${t}/approve`,{method:"POST"},!0)}async function RH(e,t){return P(`/datasets/${e}/access-requests/${t}/deny`,{method:"POST"},!0)}async function OH(e,t){return P(`/datasets/${e}/invite`,{method:"POST",body:JSON.stringify({username:t})},!0)}async function AH(e){return P(`/datasets/${e}/collaborators`,{},!0)}async function kH(e,t){return P(`/admin/datasets/${e}/enrichment`,{method:"POST",body:JSON.stringify(t)},!0)}var Pm;var qs=A(()=>{km();Ns();Pm=/^\d{4}-\d{4}-\d{4}-\d{3}[\dX]$/});var Vc;var qH=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 MH(e){return P(`/datasets/${e}/publish/status`,{},!0)}async function BH(e){return P(`/datasets/${e}/publish/resend`,{method:"POST"},!0)}async function LH(e){let t=e?`?status=${e}`:"";return P(`/admin/publish/requests${t}`,{},!0)}async function UH(e,t){return P(`/admin/publish/${e}/deny`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:t})},!0)}function aTe(e,t=[]){if(e){let r=Vc.indexOf(e);if(r>=0)return r+1}return Math.min(t.length+1,Vc.length)}function cTe(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 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,_,S,C){if(!s)return;s({step:v,stepIndex:aTe(v,_),stepTotal:Vc.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:l,skip_ci_check:n})},!0),S=!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=jH(g);return _}catch(_){if(y=_,v===5||!cTe(_)){if(_ instanceof q&&g.length>0)_.stepResults=jH(g);throw _}let C=_;if(i?.({attempt:v,maxAttempts:5,delayMs:1e4,step:C.step,error:C.message}),await new Promise((D)=>setTimeout(D,1e4)),p=!0,c!==void 0)f=!0}throw y}function jH(e){let t=new Map;for(let r of e)t.set(r.step,r);return Array.from(t.values())}var Dd=A(()=>{qH();Ns();er()});function HH(e){DD=e}function wD(){return DD}function wd(e){if(DD)process.stderr.write(`${e}
|
|
105
|
+
`)}var Sz=!1;var nD=A(()=>{He()});var Cz;var $z=A(()=>{Cz={name:"nemar-cli",version:"0.9.14-dev.2231",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","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 Om=A(()=>{$z();To=Cz.version});function V(e){if(e instanceof Error)return e.message;return String(e)}var q,No;var er=A(()=>{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"}};No=class No extends q{mode;eta;constructor(e,t,r,n){super(503,t,n);this.mode=e;this.eta=r;this.name="MaintenanceError"}}});function Fz(){if(process.env.TEST_API_URL)return process.env.TEST_API_URL;if(sD)return iD;return ht().apiUrl||iD}async function P(e,t={},r=!1,n){let i=`${Fz()}${e}`,s={"Content-Type":"application/json","X-CLI-Version":To,...t.headers};if(r){let c=ht();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 ${Fz()}`,{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.",l=typeof a.eta==="string"?a.eta:null,d=new No(a.mode,c,l,a.details);throw Rm(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 iD="https://nemar-api-dev.sccn-org.workers.dev",sD;var Ns=A(()=>{Ts();nD();Om();er();sD=iD.includes("workers.dev")});async function Rz(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 Oz(e){return P(`/admin/approve/${e}`,{method:"POST"},!0)}async function Az(e){return P(`/admin/approve/by-id/${e}`,{method:"POST"},!0)}async function kz(e){return P(`/admin/revoke/${e}`,{method:"POST"},!0)}async function Pz(e,t){return P(`/admin/users/${e}/role`,{method:"POST",body:JSON.stringify({role:t})},!0)}async function oD(e,t){return P(`/admin/datasets/${e}/visibility`,{method:"PATCH",body:JSON.stringify({visibility:t})},!0)}async function Iz(e){return P(`/datasets/${e}/publish`,{method:"POST"},!0)}async function Tz(e){return P(`/admin/datasets/${e}/ci`,{},!0)}async function Ai(e){return P(`/admin/datasets/${e}/ci`,{method:"POST"},!0)}async function aD(e){return P(`/admin/datasets/${e}/ci/validate`,{method:"POST"},!0)}async function cD(e){return P(`/admin/datasets/${e}/ci/sync`,{method:"POST"},!0)}async function Nz(e,t){return P(`/admin/datasets/${e}/doi/concept`,{method:"POST",body:JSON.stringify(t)},!0)}async function _d(e){return P(`/admin/datasets/${e}/doi`,{},!0)}async function uD(e,t){return P(`/admin/datasets/${e}/doi/update`,{method:"POST",body:JSON.stringify(t)},!0)}async function qz(e,t){return P(`/admin/datasets/${e}/withdraw`,{method:"POST",body:JSON.stringify({reason:t.reason,dry_run:t.dryRun})},!0)}async function jz(e,t){return P(`/admin/datasets/${e}/restore`,{method:"POST",body:JSON.stringify({dry_run:t.dryRun})},!0)}async function Mz(e){return P(`/admin/datasets/${e}/reset`,{method:"POST"},!0)}async function Bz(e,t=!1){return P(`/admin/datasets/${e}`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({force:t})},!0)}async function Lz(e){return P("/admin/datasets/bulk-delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dataset_ids:e})},!0)}async function Uz(e){return P("/admin/datasets/import",{method:"POST",body:JSON.stringify(e)},!0)}async function Vz(e){return P("/admin/datasets/exemplar",{method:"POST",body:JSON.stringify(e)},!0)}async function zz(e){return P(`/admin/datasets/${e}/exemplar/remint-dois`,{method:"POST"},!0)}async function lD(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 Hz(e){return P(`/admin/imports/${e}/rollback`,{method:"POST"},!0)}async function Wz(e){return P(`/admin/imports/${e}/retry`,{method:"POST"},!0)}async function dD(e){return P(`/admin/imports/${e}/verify`,{method:"POST"},!0)}async function Gz(e){return P("/admin/imports/dispatch-cooldown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dataset_ids:e})},!0)}async function qc(e,t){return P(`/admin/datasets/${e}/reindex`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t??{})},!0)}async function Kz(e,t){return P("/admin/datasets/reindex/bulk",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filter:e,...t??{}})},!0)}async function Yz(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 Jz(){return P("/admin/datasets/hed-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function Xz(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 Qz(){return P("/admin/datasets/data-integrity-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function Zz(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 eH(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 tH(){return P("/admin/datasets/availability-report-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function rH(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 jc(e,t){return P(`/admin/datasets/${e}/enforce`,{method:"POST",body:JSON.stringify({dry_run:t})},!0)}async function nH(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 iH(e,t=!1){return P(`/admin/datasets/${e}/revalidate${t?"?force=true":""}`,{method:"POST"},!0)}async function sH(e){let t=e?`?user=${encodeURIComponent(e)}`:"";return P(`/admin/email-preferences${t}`,{},!0)}async function oH(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 fD(e){return P("/admin/notify",{method:"POST",body:JSON.stringify(e)},!0)}async function aH(){return P("/admin/summary/coverage",{},!0)}async function cH(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 pD(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 mD(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 uH(){return P("/admin/zarr-catalog/publish",{method:"POST"},!0)}async function lH(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 ti(e,t){return P(`/datasets/${e}/upload-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:t})},!0)}async function hD(e,t){return P(`/datasets/${e}/download-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:t})},!0)}async function dH(e){return P(`/admin/datasets/${e}/files`,{},!0)}async function fH(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 Bc=A(()=>{Ns();er()});function ZIe(e){return e.startsWith("v")?e:`v${e}`}var XIe,QIe,pH,mQe;var gD=A(()=>{Ic();XIe=/^v?\d+\.\d+\.\d+(?:-(?:rc|alpha|beta)\d*)?$/,QIe=/^v\d+\.\d+\.\d+(?:-(?:rc|alpha|beta)\d*)?$/;pH=E.string().regex(XIe,"must be a semver version, optionally v-prefixed").transform(ZIe),mQe=E.string().regex(QIe,"must be the canonical v-prefixed tag (vX.Y.Z)")});var eTe,tTe,mH;var hH=A(()=>{Ic();eTe=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(),tTe=E.object({prefix:E.string(),created_at:E.string(),last_used_at:E.string().nullable()}).passthrough().nullable(),mH=E.object({user:eTe,token:tTe.optional()}).passthrough()});function yH(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 xH(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 rTe="0.4.0",yD,Lc,gH,nTe,iTe,sTe,bH,vQe,vH,_Qe,ki,oTe,Am,DQe;var xD=A(()=>{Ic();gD();yD=E.enum(["openneuro","nemar","gin","other"]),Lc=E.union([E.literal(0),E.literal(1)]).nullable(),gH=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:Lc.optional(),hed_version:E.string().nullable().optional(),data_complete:Lc.optional(),bytes_present:E.number().nonnegative().nullable().optional(),latest_version:pH.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:Lc.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();nTe=gH.superRefine((e,t)=>{yH(e,t),xH(e,t)}),iTe=gH.extend({file_size:E.number().nonnegative().nullable(),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:Lc.optional(),attestation_no_duplicate:Lc.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)=>{yH(e,t),xH(e,t)}),sTe=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:Lc.optional(),score:E.number().optional(),snippet:E.string().optional()}).passthrough(),bH=E.record(E.string(),E.number().int().nonnegative()),vQe=E.object({datasets:E.array(nTe),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:bH.optional()}).passthrough(),vH=E.object({results:E.array(sTe),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:bH.optional()}).passthrough(),_Qe=E.object({dataset:iTe}).passthrough(),ki=E.object({value:E.string(),count:E.number().int().nonnegative()}),oTe=E.object({values:E.array(ki),distinct_total:E.number().int().nonnegative(),truncated:E.boolean()}),Am=E.object({"electrode-system":E.array(ki).optional(),source:E.array(ki).optional(),zarr:E.array(ki).optional(),powerline:E.array(ki).optional(),"bids-version":E.array(ki).optional(),"hed-version":E.array(ki).optional(),license:E.array(ki).optional(),modality:E.array(ki).optional(),task:oTe.optional(),warning:E.string().optional()}).passthrough(),DQe=E.object({schema_version:E.literal(rTe),doc_type:E.literal("dataset"),dataset_id:E.string().regex(/^[a-z]{2}\d+$/,"neuroschema dataset_id pattern"),name:E.string(),source:yD,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 km=A(()=>{gD();hH();xD()});async function Im(e){return P(`/datasets/${e}/ci/status`,{},!0)}async function _H(e){return P(`/datasets/${e}/manifest`,{},!0)}async function Tm(e,t){return P(`/datasets/${e}/manifest/${t}`,{},!0)}function DH(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(DH),n}async function wH(e){return P(`/datasets/resolve/${e}`,{},"optional")}async function EH(){return P("/datasets/facets",{signal:AbortSignal.timeout(5000)},"optional",Am)}async function SH(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",vH)}async function gt(e){let t=await P(`/datasets/${e}`,{},"optional");return DH(t.dataset)}async function $H(e){return P(`/datasets/${e}/versions`,{},!0)}async function Nm(e){return P("/datasets",{method:"POST",body:JSON.stringify(e)},!0)}async function qm(e){return P(`/datasets/${e}/finalize`,{method:"POST"},!0)}async function bD(e){return P(`/datasets/${e}/request-access`,{method:"POST"},!0)}async function CH(e,t){let r=t?`?status=${t}`:"";return P(`/datasets/${e}/access-requests${r}`,{},!0)}async function FH(e,t){return P(`/datasets/${e}/access-requests/${t}/approve`,{method:"POST"},!0)}async function RH(e,t){return P(`/datasets/${e}/access-requests/${t}/deny`,{method:"POST"},!0)}async function OH(e,t){return P(`/datasets/${e}/invite`,{method:"POST",body:JSON.stringify({username:t})},!0)}async function AH(e){return P(`/datasets/${e}/collaborators`,{},!0)}async function kH(e,t){return P(`/admin/datasets/${e}/enrichment`,{method:"POST",body:JSON.stringify(t)},!0)}var Pm;var qs=A(()=>{km();Ns();Pm=/^\d{4}-\d{4}-\d{4}-\d{3}[\dX]$/});var Vc;var qH=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 MH(e){return P(`/datasets/${e}/publish/status`,{},!0)}async function BH(e){return P(`/datasets/${e}/publish/resend`,{method:"POST"},!0)}async function LH(e){let t=e?`?status=${e}`:"";return P(`/admin/publish/requests${t}`,{},!0)}async function UH(e,t){return P(`/admin/publish/${e}/deny`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:t})},!0)}function aTe(e,t=[]){if(e){let r=Vc.indexOf(e);if(r>=0)return r+1}return Math.min(t.length+1,Vc.length)}function cTe(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 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,_,S,C){if(!s)return;s({step:v,stepIndex:aTe(v,_),stepTotal:Vc.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:l,skip_ci_check:n})},!0),S=!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=jH(g);return _}catch(_){if(y=_,v===5||!cTe(_)){if(_ instanceof q&&g.length>0)_.stepResults=jH(g);throw _}let C=_;if(i?.({attempt:v,maxAttempts:5,delayMs:1e4,step:C.step,error:C.message}),await new Promise((D)=>setTimeout(D,1e4)),p=!0,c!==void 0)f=!0}throw y}function jH(e){let t=new Map;for(let r of e)t.set(r.step,r);return Array.from(t.values())}var Dd=A(()=>{qH();Ns();er()});function HH(e){DD=e}function wD(){return DD}function wd(e){if(DD)process.stderr.write(`${e}
|
|
106
106
|
`)}var DD=!1;var WH={};ji(WH,{runCommand:()=>R});var{spawn:uTe}=globalThis.Bun;async function R(e,t={}){let r={...process.env,GIT_TERMINAL_PROMPT:"0",...t.env};for(let l of t.unsetEnv??[])delete r[l];let n=uTe({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(wD()){let l=t.cwd?` (cwd=${t.cwd})`:"";wd(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(wD()){if(o.trim())wd(u.dim(o.trimEnd()));if(a.trim())wd(u.yellow(a.trimEnd()));wd(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 lTe(){try{let{exitCode:e,stderr:t}=await R(["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 Ed(){try{let{stdout:e,exitCode:t,stderr:r}=await R(["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 jm(e){try{let{stdout:t,exitCode:r,stderr:n}=await R(["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 Mm(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 R(["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 R(["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 R(["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 ri(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 R(["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 Ed();if(s.token)n=`https://github.com/${i}`,await R(["git","config","credential.https://github.com.helper",`!printf 'username=x-access-token\\npassword=${s.token}'`],{cwd:e});else{let o=await lTe();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