nemar-cli 0.8.10-dev.748 → 0.8.10-dev.753

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 +2 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -95,7 +95,7 @@ ${W.dim(`eta: ${D.eta}`)}`:"";process.stderr.write(`${F}
95
95
  ${$} ${D.message}
96
96
  ${J}${Q}
97
97
  ${F}
98
- `)}var Hf=!1;var UW=P(()=>{yD()});var Kf;var qf=P(()=>{Kf={name:"nemar-cli",version:"0.8.10-dev.748",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",prepublishOnly:"bun run build","docs:generate":"bun run scripts/generate-docs.ts","docs:serve":"mkdocs serve","docs:build":"mkdocs build",prepare:"husky",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://nemar-cli.pages.dev",engines:{bun:">=1.0.0"},files:["dist","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",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 x4;var iJ=P(()=>{qf();x4=Kf.version});function T0(D){if(D instanceof Error)return D.message;return String(D)}function zf(){if(process.env.TEST_API_URL)return process.env.TEST_API_URL;if(AW)return LW;return QD().apiUrl||LW}async function h(D,F={},$=!1){let J=`${zf()}${D}`,Q={"Content-Type":"application/json","X-CLI-Version":x4,...F.headers};if($){let X=QD();if(!X.apiKey&&$===!0)throw new p(401,"Not authenticated. Run 'nemar auth login' first.");if(X.apiKey)Q.Authorization=`Bearer ${X.apiKey}`}let Y;try{Y=await fetch(J,{...F,headers:Q})}catch(X){throw new p(0,`Network error: Could not connect to ${zf()}`,{originalError:X instanceof Error?X.message:String(X)})}let B;try{B=await Y.json()}catch{throw new p(Y.status,`Invalid response from server (status ${Y.status})`)}if(!Y.ok){if(Y.status===503&&(B.mode==="read-only"||B.mode==="full")){let X=typeof B.message==="string"?B.message:"NEMAR is in maintenance mode. Please retry shortly.",G=typeof B.eta==="string"?B.eta:null,H=new oJ(B.mode,X,G,B.details);throw nJ(H),H}throw new p(Y.status,B.error||B.message||"Request failed",B.details,typeof B.step==="string"?B.step:void 0)}return B}async function Vf(D){return h(`/auth/check-username?username=${encodeURIComponent(D)}`)}async function Zf(D){return h(`/auth/check-github?username=${encodeURIComponent(D)}`)}async function Uf(D){return h("/auth/signup",{method:"POST",body:JSON.stringify(D)})}async function Lf(D){return h("/auth/login",{method:"POST",body:JSON.stringify({api_key:D})})}async function Af(D){return h("/auth/resend-verification",{method:"POST",body:JSON.stringify({email:D})})}async function Mf(D,F){return h("/auth/retrieve-key",{method:"POST",body:JSON.stringify({email:D,password:F})})}async function Nf(D){return h("/auth/request-key-regeneration",{method:"POST",body:JSON.stringify({email:D})})}async function sJ(){return h("/users/me",{},!0)}async function Cf(D,F){let $=new URLSearchParams;if(D)$.set("status",D);if(F)$.set("role",F);let J=$.toString()?`?${$.toString()}`:"";return h(`/admin/users${J}`,{},!0)}async function Rf(D){return h(`/admin/approve/${D}`,{method:"POST"},!0)}async function Of(D){return h(`/admin/revoke/${D}`,{method:"POST"},!0)}async function Tf(D,F){return h(`/admin/users/${D}/role`,{method:"POST",body:JSON.stringify({role:F})},!0)}async function MW(D,F){return h(`/admin/datasets/${D}/visibility`,{method:"PATCH",body:JSON.stringify({visibility:F})},!0)}async function wf(D){return h(`/datasets/${D}/publish`,{method:"POST"},!0)}async function jf(D){return h(`/admin/datasets/${D}/ci`,{},!0)}async function _4(D){return h(`/admin/datasets/${D}/ci`,{method:"POST"},!0)}async function NW(D){return h(`/admin/datasets/${D}/ci/sync`,{method:"POST"},!0)}async function Pf(D){return h(`/datasets/${D}/ci/status`,{},!0)}async function If(D){return h(`/datasets/${D}/manifest`,{},!0)}async function rJ(D,F){return h(`/datasets/${D}/manifest/${F}`,{},!0)}function Sf(D){let F=D;if(!F.status)F.status="active";else if(!["active","archived","deleted"].includes(F.status))throw Error(`Invalid dataset status: ${F.status}`);if(!F.visibility)F.visibility="private";else if(!["public","private"].includes(F.visibility))throw Error(`Invalid dataset visibility: ${F.visibility}`);return F}async function P9(D={}){let F=new URLSearchParams;if(D.mine)F.set("mine","true");if(D.search)F.set("search",D.search);if(D.modality)F.set("modality",D.modality);if(D.author)F.set("author",D.author);if(D.task)F.set("task",D.task);if(D.hasDoi)F.set("has_doi","true");if(D.recent)F.set("recent",String(D.recent));if(D.sort)F.set("sort",D.sort);if(D.limit!=null)F.set("limit",String(D.limit));if(D.offset!=null)F.set("offset",String(D.offset));if(D.owner)F.set("owner",D.owner);let $=F.toString()?`?${F.toString()}`:"",J=await h(`/datasets${$}`,{},D.mine?!0:"optional");return J.datasets=J.datasets.map(Sf),J}async function kf(D){return h(`/datasets/resolve/${D}`,{},"optional")}async function vf(D,F={}){let $=new URLSearchParams({q:D});if(F.modality)$.set("modality",F.modality);if(F.limit)$.set("limit",String(F.limit));return h(`/datasets/search?${$.toString()}`,{},"optional")}async function bD(D){let F=await h(`/datasets/${D}`,{},"optional");return Sf(F.dataset)}async function yf(D){return h(`/datasets/${D}/versions`,{},!0)}async function tJ(D){return h("/datasets",{method:"POST",body:JSON.stringify(D)},!0)}async function eJ(D){return h(`/datasets/${D}/finalize`,{method:"POST"},!0)}async function C8(D,F){return h(`/datasets/${D}/upload-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:F})},!0)}async function DQ(D,F){return h(`/datasets/${D}/download-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:F})},!0)}async function xf(D,F){return h(`/admin/datasets/${D}/doi/concept`,{method:"POST",body:JSON.stringify(F)},!0)}async function I9(D){return h(`/admin/datasets/${D}/doi`,{},!0)}async function CW(D,F){return h(`/admin/datasets/${D}/doi/update`,{method:"POST",body:JSON.stringify(F)},!0)}async function RW(D){return h(`/datasets/${D}/request-access`,{method:"POST"},!0)}async function _f(D,F){return h(`/datasets/${D}/invite`,{method:"POST",body:JSON.stringify({username:F})},!0)}async function ff(D){return h(`/datasets/${D}/collaborators`,{},!0)}async function gf(D){return h("/sandbox/complete",{method:"POST",body:JSON.stringify({dataset_id:D})},!0)}async function hf(){return h("/sandbox/reset",{method:"POST"},!0)}async function bf(){return h("/sandbox/status",{},!0)}async function FQ(D){return h(`/datasets/${D}/publish/request`,{method:"POST"},!0)}async function uf(D){return h(`/datasets/${D}/publish/status`,{},!0)}async function mf(D){return h(`/datasets/${D}/publish/resend`,{method:"POST"},!0)}async function lf(D){let F=D?`?status=${D}`:"";return h(`/admin/publish/requests${F}`,{},!0)}async function pf(D,F){return h(`/admin/publish/${D}/deny`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:F})},!0)}function mz0(D){if(!(D instanceof p))return!1;if(D.statusCode===0)return!0;if(D.statusCode===429)return!0;if(D.statusCode>=500&&D.statusCode<600)return!0;if(D.statusCode===403&&/repository has been locked/i.test(D.message))return!0;return!1}async function $Q(D,F=!1,$=!1,J=!1,Q){let X,G=F,H=[],q;for(let K=1;K<=5;K++)try{let V,E=!0;do{if(V=await h(`/admin/publish/${D}/approve`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({resume:E?G:!0,sandbox:$,s3_lock_continuation_token:X,skip_ci_check:J})},!0),E=!1,V.step_results)H.push(...V.step_results);if(V.hasMore&&V.s3_lock_continuation_token!==void 0)X=V.s3_lock_continuation_token;else break}while(V.hasMore);if(H.length>0)V.step_results=Ef(H);return V}catch(V){if(q=V,K===5||!mz0(V)){if(V instanceof p&&H.length>0)V.stepResults=Ef(H);throw V}let Z=V;Q?.({attempt:K,maxAttempts:5,delayMs:1e4,step:Z.step,error:Z.message}),await new Promise((L)=>setTimeout(L,1e4)),G=!0}throw q}function Ef(D){let F=new Map;for(let $ of D)F.set($.step,$);return Array.from(F.values())}async function df(D,F){return h(`/admin/datasets/${D}/enrichment`,{method:"POST",body:JSON.stringify(F)},!0)}async function cf(D){return h(`/admin/datasets/${D}/files`,{},!0)}async function nf(D){let F,$=0,J=[],Q=!0;while(Q){let Y=await h(`/admin/datasets/${D}/s3-lock`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({continuation_token:F})},!0);if($+=Y.locked,Y.failed?.length)J.push(...Y.failed);if(Q=Y.hasMore,F=Y.continuation_token,Q&&!F)throw new p(500,"S3 lock paginated response missing continuation_token; aborting to avoid infinite loop")}return{locked:$,failed:J}}async function af(D){return h(`/admin/datasets/${D}/reset`,{method:"POST"},!0)}async function of(D,F=!1){return h(`/admin/datasets/${D}`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({force:F})},!0)}async function sf(D){return h("/admin/datasets/bulk-delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dataset_ids:D})},!0)}async function rf(D){return h("/admin/datasets/import",{method:"POST",body:JSON.stringify(D)},!0)}async function tf(D){return h(`/admin/datasets/${D}/sync`,{method:"POST"},!0)}async function ef(){return h("/admin/sync/status",{},!0)}async function Dg(D,F){return h(`/admin/datasets/${D}/reindex`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(F??{})},!0)}async function Fg(D,F){return h("/admin/datasets/reindex/bulk",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filter:D,...F??{}})},!0)}async function $g(){return h("/admin/email-preferences",{},!0)}async function Jg(D){return h("/admin/email-preferences",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(D)},!0)}async function Qg(){return h("/notices",{},"optional")}async function Yg(){return h("/admin/notices",{},!0)}async function Bg(D){return h("/admin/notices",{method:"POST",body:JSON.stringify(D)},!0)}async function Xg(D){return h(`/admin/notices/${D}`,{method:"DELETE"},!0)}async function OW(D){return h("/admin/notify",{method:"POST",body:JSON.stringify(D)},!0)}var LW="https://nemar-api-dev.sccn-org.workers.dev",aJ,p,oJ,AW;var n8=P(()=>{y4();UW();iJ();aJ=/^\d{4}-\d{4}-\d{4}-\d{3}[\dX]$/;p=class p extends Error{statusCode;details;step;constructor(D,F,$,J){super(F);this.statusCode=D;this.details=$;this.step=J;this.name="ApiError"}};oJ=class oJ extends p{mode;eta;constructor(D,F,$,J){super(503,F,J);this.mode=D;this.eta=$;this.name="MaintenanceError"}};AW=LW.includes("workers.dev")});function Wg(D){TW=D}function wW(){return TW}function S9(D){if(TW)process.stderr.write(`${D}
98
+ `)}var Hf=!1;var UW=P(()=>{yD()});var Kf;var qf=P(()=>{Kf={name:"nemar-cli",version:"0.8.10-dev.753",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",prepublishOnly:"bun run build","docs:generate":"bun run scripts/generate-docs.ts","docs:serve":"mkdocs serve","docs:build":"mkdocs build",prepare:"husky",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://nemar-cli.pages.dev",engines:{bun:">=1.0.0"},files:["dist","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",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 x4;var iJ=P(()=>{qf();x4=Kf.version});function T0(D){if(D instanceof Error)return D.message;return String(D)}function zf(){if(process.env.TEST_API_URL)return process.env.TEST_API_URL;if(AW)return LW;return QD().apiUrl||LW}async function h(D,F={},$=!1){let J=`${zf()}${D}`,Q={"Content-Type":"application/json","X-CLI-Version":x4,...F.headers};if($){let X=QD();if(!X.apiKey&&$===!0)throw new p(401,"Not authenticated. Run 'nemar auth login' first.");if(X.apiKey)Q.Authorization=`Bearer ${X.apiKey}`}let Y;try{Y=await fetch(J,{...F,headers:Q})}catch(X){throw new p(0,`Network error: Could not connect to ${zf()}`,{originalError:X instanceof Error?X.message:String(X)})}let B;try{B=await Y.json()}catch{throw new p(Y.status,`Invalid response from server (status ${Y.status})`)}if(!Y.ok){if(Y.status===503&&(B.mode==="read-only"||B.mode==="full")){let X=typeof B.message==="string"?B.message:"NEMAR is in maintenance mode. Please retry shortly.",G=typeof B.eta==="string"?B.eta:null,H=new oJ(B.mode,X,G,B.details);throw nJ(H),H}throw new p(Y.status,B.error||B.message||"Request failed",B.details,typeof B.step==="string"?B.step:void 0)}return B}async function Vf(D){return h(`/auth/check-username?username=${encodeURIComponent(D)}`)}async function Zf(D){return h(`/auth/check-github?username=${encodeURIComponent(D)}`)}async function Uf(D){return h("/auth/signup",{method:"POST",body:JSON.stringify(D)})}async function Lf(D){return h("/auth/login",{method:"POST",body:JSON.stringify({api_key:D})})}async function Af(D){return h("/auth/resend-verification",{method:"POST",body:JSON.stringify({email:D})})}async function Mf(D,F){return h("/auth/retrieve-key",{method:"POST",body:JSON.stringify({email:D,password:F})})}async function Nf(D){return h("/auth/request-key-regeneration",{method:"POST",body:JSON.stringify({email:D})})}async function sJ(){return h("/users/me",{},!0)}async function Cf(D,F){let $=new URLSearchParams;if(D)$.set("status",D);if(F)$.set("role",F);let J=$.toString()?`?${$.toString()}`:"";return h(`/admin/users${J}`,{},!0)}async function Rf(D){return h(`/admin/approve/${D}`,{method:"POST"},!0)}async function Of(D){return h(`/admin/revoke/${D}`,{method:"POST"},!0)}async function Tf(D,F){return h(`/admin/users/${D}/role`,{method:"POST",body:JSON.stringify({role:F})},!0)}async function MW(D,F){return h(`/admin/datasets/${D}/visibility`,{method:"PATCH",body:JSON.stringify({visibility:F})},!0)}async function wf(D){return h(`/datasets/${D}/publish`,{method:"POST"},!0)}async function jf(D){return h(`/admin/datasets/${D}/ci`,{},!0)}async function _4(D){return h(`/admin/datasets/${D}/ci`,{method:"POST"},!0)}async function NW(D){return h(`/admin/datasets/${D}/ci/sync`,{method:"POST"},!0)}async function Pf(D){return h(`/datasets/${D}/ci/status`,{},!0)}async function If(D){return h(`/datasets/${D}/manifest`,{},!0)}async function rJ(D,F){return h(`/datasets/${D}/manifest/${F}`,{},!0)}function Sf(D){let F=D;if(!F.status)F.status="active";else if(!["active","archived","deleted"].includes(F.status))throw Error(`Invalid dataset status: ${F.status}`);if(!F.visibility)F.visibility="private";else if(!["public","private"].includes(F.visibility))throw Error(`Invalid dataset visibility: ${F.visibility}`);return F}async function P9(D={}){let F=new URLSearchParams;if(D.mine)F.set("mine","true");if(D.search)F.set("search",D.search);if(D.modality)F.set("modality",D.modality);if(D.author)F.set("author",D.author);if(D.task)F.set("task",D.task);if(D.hasDoi)F.set("has_doi","true");if(D.recent)F.set("recent",String(D.recent));if(D.sort)F.set("sort",D.sort);if(D.limit!=null)F.set("limit",String(D.limit));if(D.offset!=null)F.set("offset",String(D.offset));if(D.owner)F.set("owner",D.owner);let $=F.toString()?`?${F.toString()}`:"",J=await h(`/datasets${$}`,{},D.mine?!0:"optional");return J.datasets=J.datasets.map(Sf),J}async function kf(D){return h(`/datasets/resolve/${D}`,{},"optional")}async function vf(D,F={}){let $=new URLSearchParams({q:D});if(F.modality)$.set("modality",F.modality);if(F.limit)$.set("limit",String(F.limit));return h(`/datasets/search?${$.toString()}`,{},"optional")}async function bD(D){let F=await h(`/datasets/${D}`,{},"optional");return Sf(F.dataset)}async function yf(D){return h(`/datasets/${D}/versions`,{},!0)}async function tJ(D){return h("/datasets",{method:"POST",body:JSON.stringify(D)},!0)}async function eJ(D){return h(`/datasets/${D}/finalize`,{method:"POST"},!0)}async function C8(D,F){return h(`/datasets/${D}/upload-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:F})},!0)}async function DQ(D,F){return h(`/datasets/${D}/download-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:F})},!0)}async function xf(D,F){return h(`/admin/datasets/${D}/doi/concept`,{method:"POST",body:JSON.stringify(F)},!0)}async function I9(D){return h(`/admin/datasets/${D}/doi`,{},!0)}async function CW(D,F){return h(`/admin/datasets/${D}/doi/update`,{method:"POST",body:JSON.stringify(F)},!0)}async function RW(D){return h(`/datasets/${D}/request-access`,{method:"POST"},!0)}async function _f(D,F){return h(`/datasets/${D}/invite`,{method:"POST",body:JSON.stringify({username:F})},!0)}async function ff(D){return h(`/datasets/${D}/collaborators`,{},!0)}async function gf(D){return h("/sandbox/complete",{method:"POST",body:JSON.stringify({dataset_id:D})},!0)}async function hf(){return h("/sandbox/reset",{method:"POST"},!0)}async function bf(){return h("/sandbox/status",{},!0)}async function FQ(D){return h(`/datasets/${D}/publish/request`,{method:"POST"},!0)}async function uf(D){return h(`/datasets/${D}/publish/status`,{},!0)}async function mf(D){return h(`/datasets/${D}/publish/resend`,{method:"POST"},!0)}async function lf(D){let F=D?`?status=${D}`:"";return h(`/admin/publish/requests${F}`,{},!0)}async function pf(D,F){return h(`/admin/publish/${D}/deny`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:F})},!0)}function mz0(D){if(!(D instanceof p))return!1;if(D.statusCode===0)return!0;if(D.statusCode===429)return!0;if(D.statusCode>=500&&D.statusCode<600)return!0;if(D.statusCode===403&&/repository has been locked/i.test(D.message))return!0;return!1}async function $Q(D,F=!1,$=!1,J=!1,Q){let X,G=F,H=[],q;for(let K=1;K<=5;K++)try{let V,E=!0;do{if(V=await h(`/admin/publish/${D}/approve`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({resume:E?G:!0,sandbox:$,s3_lock_continuation_token:X,skip_ci_check:J})},!0),E=!1,V.step_results)H.push(...V.step_results);if(V.hasMore&&V.s3_lock_continuation_token!==void 0)X=V.s3_lock_continuation_token;else break}while(V.hasMore);if(H.length>0)V.step_results=Ef(H);return V}catch(V){if(q=V,K===5||!mz0(V)){if(V instanceof p&&H.length>0)V.stepResults=Ef(H);throw V}let Z=V;Q?.({attempt:K,maxAttempts:5,delayMs:1e4,step:Z.step,error:Z.message}),await new Promise((L)=>setTimeout(L,1e4)),G=!0}throw q}function Ef(D){let F=new Map;for(let $ of D)F.set($.step,$);return Array.from(F.values())}async function df(D,F){return h(`/admin/datasets/${D}/enrichment`,{method:"POST",body:JSON.stringify(F)},!0)}async function cf(D){return h(`/admin/datasets/${D}/files`,{},!0)}async function nf(D){let F,$=0,J=[],Q=!0;while(Q){let Y=await h(`/admin/datasets/${D}/s3-lock`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({continuation_token:F})},!0);if($+=Y.locked,Y.failed?.length)J.push(...Y.failed);if(Q=Y.hasMore,F=Y.continuation_token,Q&&!F)throw new p(500,"S3 lock paginated response missing continuation_token; aborting to avoid infinite loop")}return{locked:$,failed:J}}async function af(D){return h(`/admin/datasets/${D}/reset`,{method:"POST"},!0)}async function of(D,F=!1){return h(`/admin/datasets/${D}`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({force:F})},!0)}async function sf(D){return h("/admin/datasets/bulk-delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dataset_ids:D})},!0)}async function rf(D){return h("/admin/datasets/import",{method:"POST",body:JSON.stringify(D)},!0)}async function tf(D){return h(`/admin/datasets/${D}/sync`,{method:"POST"},!0)}async function ef(){return h("/admin/sync/status",{},!0)}async function Dg(D,F){return h(`/admin/datasets/${D}/reindex`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(F??{})},!0)}async function Fg(D,F){return h("/admin/datasets/reindex/bulk",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filter:D,...F??{}})},!0)}async function $g(){return h("/admin/email-preferences",{},!0)}async function Jg(D){return h("/admin/email-preferences",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(D)},!0)}async function Qg(){return h("/notices",{},"optional")}async function Yg(){return h("/admin/notices",{},!0)}async function Bg(D){return h("/admin/notices",{method:"POST",body:JSON.stringify(D)},!0)}async function Xg(D){return h(`/admin/notices/${D}`,{method:"DELETE"},!0)}async function OW(D){return h("/admin/notify",{method:"POST",body:JSON.stringify(D)},!0)}var LW="https://nemar-api-dev.sccn-org.workers.dev",aJ,p,oJ,AW;var n8=P(()=>{y4();UW();iJ();aJ=/^\d{4}-\d{4}-\d{4}-\d{3}[\dX]$/;p=class p extends Error{statusCode;details;step;constructor(D,F,$,J){super(F);this.statusCode=D;this.details=$;this.step=J;this.name="ApiError"}};oJ=class oJ extends p{mode;eta;constructor(D,F,$,J){super(503,F,J);this.mode=D;this.eta=$;this.name="MaintenanceError"}};AW=LW.includes("workers.dev")});function Wg(D){TW=D}function wW(){return TW}function S9(D){if(TW)process.stderr.write(`${D}
99
99
  `)}var TW=!1;function XD(D){if(D===0)return"0 B";let F=["B","KB","MB","GB","TB"],$=Math.min(Math.floor(Math.log(D)/Math.log(1024)),F.length-1);return`${(D/1024**$).toFixed($===0?0:1)} ${F[$]}`}function Hg(D){return`${XD(D)}/s`}function lz0(D){if(D<60)return`${Math.round(D)}s`;if(D<3600)return`${Math.floor(D/60)}m ${Math.round(D%60)}s`;return`${Math.floor(D/3600)}h ${Math.floor(D%3600/60)}m`}function pz0(D,F=20){let $=Math.round(D/100*F),J=F-$;return`[${"=".repeat($)}${" ".repeat(J)}]`}class JQ{filesCompleted=0;filesTotal;bytesTotal=0;inFlight=new Map;currentFile="";startTime;lastUpdateTime;lastBytesTransferred=0;totalBytesTransferred=0;speedSamples=[];lastRenderedLine="";constructor(D=0,F=0){this.filesTotal=D,this.bytesTotal=F,this.startTime=Date.now(),this.lastUpdateTime=this.startTime}inFlightBytes(){let D=0;for(let F of this.inFlight.values())D+=F.transferred;return D}processLine(D){let F=D.file??D.action?.file;if(D.ok===!0||D.success===!0){this.filesCompleted++;let $=F??this.currentFile,J=$?this.inFlight.get($):void 0,Q=J?J.total||J.transferred:0;if(this.totalBytesTransferred+=Q,$)this.inFlight.delete($);this.render();return}if(D["byte-progress"]!==void 0){let $=F??this.currentFile;if(!$)return;this.currentFile=$;let J=this.inFlight.get($)??{transferred:0,total:0};if(J.transferred=D["byte-progress"]??J.transferred,D["total-size"]!==void 0)J.total=D["total-size"];this.inFlight.set($,J);let Q=Date.now(),Y=(Q-this.lastUpdateTime)/1000;if(Y>0.5){let B=this.totalBytesTransferred+this.inFlightBytes(),G=(B-this.lastBytesTransferred)/Y;if(G>0){if(this.speedSamples.push(G),this.speedSamples.length>5)this.speedSamples.shift()}this.lastBytesTransferred=B,this.lastUpdateTime=Q}this.render()}}incrementFilesCompleted(){this.filesCompleted++}setFilesTotal(D){this.filesTotal=D}setBytesTotal(D){this.bytesTotal=D}getPercent(){let D=this.totalBytesTransferred+this.inFlightBytes();if(this.bytesTotal>0)return Math.min(100,Math.round(D/this.bytesTotal*100));if(this.filesTotal>0)return Math.min(100,Math.round(this.filesCompleted/this.filesTotal*100));return null}getProgress(){return{filesCompleted:this.filesCompleted,filesTotal:this.filesTotal,bytesTransferred:this.totalBytesTransferred+this.inFlightBytes(),bytesTotal:this.bytesTotal,currentFile:this.currentFile||void 0}}render(){let D=this.speedSamples.length>0?this.speedSamples.reduce((B,X)=>B+X,0)/this.speedSamples.length:0,F=this.totalBytesTransferred+this.inFlightBytes(),$=0,J=!1;if(this.bytesTotal>0)$=Math.min(100,Math.round(F/this.bytesTotal*100)),J=!0;else if(this.filesTotal>0)$=Math.min(100,Math.round(this.filesCompleted/this.filesTotal*100)),J=!0;let Q=this.filesTotal>0?`${this.filesCompleted}/${this.filesTotal} files`:`${this.filesCompleted} files`,Y;if(J)Y=`${pz0($)} ${$}% ${Q}`;else Y=Q;if(F>0){let B=this.bytesTotal>0?`${XD(F)}/${XD(this.bytesTotal)}`:XD(F);Y+=` | ${B}`}if(D>0)Y+=` | ${Hg(D)}`;if(D>0){let B=0;if(this.bytesTotal>0)B=Math.max(0,this.bytesTotal-F);else for(let X of this.inFlight.values())if(X.total>X.transferred)B+=X.total-X.transferred;if(B>0){let X=B/D;if(X>0)Y+=` | ETA ${lz0(X)}`}}if(Y!==this.lastRenderedLine)process.stderr.write(`\r${W.cyan(Y)}${" ".repeat(10)}`),this.lastRenderedLine=Y}finish(D){let F=(Date.now()-this.startTime)/1000;if(process.stderr.write(`\r${" ".repeat(this.lastRenderedLine.length+15)}\r`),D>0){let $=F>0?`${Hg(this.totalBytesTransferred/F)}`:"",J=[`${D} file${D!==1?"s":""} downloaded`,this.totalBytesTransferred>0?XD(this.totalBytesTransferred):"",$].filter(Boolean).join(" | ");process.stderr.write(`${W.green(J)}
100
100
  `)}}}var jW=P(()=>{yD()});var Rg={};d4(Rg,{verifyGitHubAuth:()=>v9,toS3Credentials:()=>CD,switchBranch:()=>ez0,setKeyPresent:()=>Cg,selectAnnexS3Remote:()=>_W,saveDataset:()=>a8,runCommand:()=>I,resolveUpstreamRef:()=>pW,readRemoteHeadDatasetVersion:()=>lW,readLocalDatasetVersion:()=>mW,pushToGitHub:()=>a1,pushBranch:()=>jF,markInheritedOpenNeuroRemotesIgnored:()=>xW,listDatasetVersions:()=>gW,isWorkingTreeDirty:()=>dW,isGitAnnexDataset:()=>O1,isDataladDataset:()=>QE0,initOrEnableSpecialRemote:()=>Ag,initDataset:()=>d6,gitMergeFastForward:()=>nW,gitFetchOrigin:()=>cW,gitAnnexAdd:()=>c6,getVersionCommit:()=>hW,getRemoteUuid:()=>sW,getLocalDatasetInfo:()=>fW,getKeyHashDirs:()=>$E0,getKeyHashDir:()=>Ng,getDatasetStats:()=>sz0,getDatasetIdFromRemote:()=>s8,getDatasetData:()=>BQ,getCurrentBranch:()=>o8,getAnnexWhereisAll:()=>oW,getAnnexS3Remotes:()=>x9,formatBytes:()=>XD,ensureLocalMainBranch:()=>_9,ensureGitAnnexInitialized:()=>vW,enableS3Remote:()=>g4,dropUnusedAnnexObjects:()=>iW,dropFiles:()=>yW,createRevertBranch:()=>bW,createDataladDataset:()=>JE0,countPendingDownload:()=>YQ,copyToAnnexRemote:()=>O8,configureS3Remote:()=>R8,configureLargefiles:()=>f4,configureGitHubRemote:()=>i8,commitRevert:()=>uW,collectFileManifest:()=>aW,cloneDataset:()=>o1,clearAnnexCredentials:()=>kD,checkPrerequisites:()=>k9,checkGitHubSSH:()=>Vg,checkGitAnnexInstalled:()=>kW,checkDownloadPrerequisites:()=>wF,checkAWSCredentials:()=>iz0,batchSetKeysPresent:()=>rW,annexRemoteExists:()=>Lg,acceptGitHubInvitation:()=>y9,NEMAR_S3_REMOTE_NAME:()=>QQ,ANNEX_REMOTE_EXISTS_RE:()=>Ug});import{existsSync as IW,readFileSync as dz0,statSync as cz0}from"fs";import{join as SW}from"path";var{spawn:Eg}=globalThis.Bun;async function I(D,F={}){let $=Eg({cmd:D,cwd:F.cwd,stdout:"pipe",stderr:"pipe",env:{...process.env,GIT_TERMINAL_PROMPT:"0",...F.env}}),J=!1,Q;if(F.timeout)Q=setTimeout(()=>{J=!0,$.kill()},F.timeout);if(wW()){let G=F.cwd?` (cwd=${F.cwd})`:"";S9(W.dim(`$ ${D.join(" ")}${G}`))}let Y=await new Response($.stdout).text(),B=await new Response($.stderr).text(),X=await $.exited;if(Q)clearTimeout(Q);if(wW()){if(Y.trim())S9(W.dim(Y.trimEnd()));if(B.trim())S9(W.yellow(B.trimEnd()));S9(W.dim(`(exit ${X})`))}if(J)return{stdout:Y,stderr:B||`Command timed out after ${Math.round(F.timeout/1000)}s`,exitCode:X??1};return{stdout:Y,stderr:B,exitCode:X}}function qg(D){return D.split(".").map((F)=>{let $=Number.parseInt(F.replace(/[^0-9]/g,""),10);return Number.isNaN($)?0:$})}function nz0(D,F){let $=qg(D),J=qg(F);for(let Q=0;Q<Math.max($.length,J.length);Q++){let Y=$[Q]||0,B=J[Q]||0;if(Y>B)return!0;if(Y<B)return!1}return!0}async function kW(){try{let{stdout:F,exitCode:$,stderr:J}=await I(["git-annex","version"]);if($!==0)return console.warn("git-annex version returned non-zero exit code:",$),console.warn("stderr:",J),{installed:!1,minVersion:"10.0",error:`Version check failed: ${J.trim()}`};let Q=F.match(/version:\s*(\d+\.\d+)/),Y=Q?Q[1]:void 0;if(!Y)console.warn("Could not parse git-annex version from output:",F);return{installed:!0,version:Y,minVersion:"10.0",compatible:Y?nz0(Y,"10.0"):void 0}}catch(F){let $=F instanceof Error?F.message:String(F);if($.includes("ENOENT")||$.includes("not found"))return console.info("git-annex not found in PATH"),{installed:!1,minVersion:"10.0"};return console.error("Error checking git-annex installation:",$),{installed:!1,minVersion:"10.0",error:$}}}async function Vg(){if(process.env.GH_TOKEN)return{accessible:!0,username:"token-auth",useHttps:!0};try{let{stdout:D,stderr:F}=await I(["ssh","-T","-o","BatchMode=yes","-o","StrictHostKeyChecking=accept-new","-o","ConnectTimeout=10","git@github.com"]),$=D+F,J=$.match(/Hi ([^!]+)!/);if(J)return{accessible:!0,username:J[1]};if($.includes("Permission denied"))return{accessible:!1};return{accessible:$.includes("successfully authenticated")}}catch(D){let F=D instanceof Error?D.message:String(D);if(F.includes("ENOENT")||F.includes("not found"))console.info("SSH command not found");else console.error("Error checking GitHub SSH access:",F);return{accessible:!1}}}async function iz0(){if(process.env.AWS_ACCESS_KEY_ID&&process.env.AWS_SECRET_ACCESS_KEY)return{configured:!0,source:"environment"};try{let{stdout:D,exitCode:F}=await I(["aws","configure","get","aws_access_key_id"]);if(F===0&&D.trim())return{configured:!0,source:"aws-cli"}}catch(D){let F=D instanceof Error?D.message:String(D);if(F.includes("ENOENT")||F.includes("not found"))console.info("AWS CLI not found in PATH");else console.error("Error checking AWS credentials:",F)}return{configured:!1}}function Zg(){let D=process.platform;if(D==="darwin")return"brew install git-annex";if(D==="linux")return"apt install git-annex (Debian/Ubuntu)";return"See https://git-annex.branchable.com/install/"}async function k9(){let[D,F]=await Promise.all([kW(),Vg()]),$=[];if(!D.installed)$.push(`git-annex is not installed. Install: ${Zg()}`);else if(D.compatible===!1)$.push(`git-annex version ${D.version} is too old. Required: >= ${D.minVersion}`);if(!F.accessible){if(!(await Mg()).token)$.push("GitHub authentication not configured. Run 'gh auth login' to authenticate.")}return{gitAnnex:D,githubSSH:F,allPassed:$.length===0,errors:$}}async function O1(D){if(!IW(SW(D,".git")))return!1;try{let{exitCode:F}=await I(["git","annex","info"],{cwd:D});return F===0}catch(F){let $=F instanceof Error?F.message:String(F);if(!$.includes("ENOENT")&&!$.includes("not found"))console.error(`Error checking if ${D} is a git-annex dataset:`,$);return!1}}async function d6(D,F={}){if(!F.force&&await O1(D))return{success:!0};try{let $={};if(F.author)$.GIT_AUTHOR_NAME=F.author.name,$.GIT_AUTHOR_EMAIL=F.author.email,$.GIT_COMMITTER_NAME=F.author.name,$.GIT_COMMITTER_EMAIL=F.author.email;let{stderr:J,exitCode:Q}=await I(["git","init","-b","main",D],{...Object.keys($).length>0?{env:$}:{}});if(Q!==0)return{success:!1,error:J.trim()||"Failed to initialize git repository"};let Y=Object.keys($).length>0?{env:$}:{},{stderr:B,exitCode:X}=await I(["git","annex","init"],{cwd:D,...Y});if(X!==0)return{success:!1,error:B.trim()||"Failed to initialize git-annex"};let{stderr:G,exitCode:H}=await I(["git","commit","--allow-empty","-m","Initialize dataset"],{cwd:D,...Y});if(H!==0)return{success:!1,error:G.trim()||"Failed to create initial commit"};let{stderr:q,exitCode:K}=await I(["git","annex","adjust","--unlock"],{cwd:D,...Y});if(K!==0)return{success:!1,error:q.trim()||"Failed to switch to unlocked mode"};return{success:!0}}catch($){return{success:!1,error:$.message}}}async function vW(D){try{let{exitCode:F,stderr:$}=await I(["git","annex","info"],{cwd:D});if(F===0)return{success:!0};if($.includes("First run: git-annex init")){let{stderr:J,exitCode:Q}=await I(["git","annex","init"],{cwd:D});if(Q!==0)return{success:!1,error:J.trim()||"Failed to initialize git-annex"};return{success:!0}}return{success:!1,error:$.trim()||"Failed to check git-annex status"}}catch(F){return{success:!1,error:F.message}}}async function f4(D,F){let $=["*.edf","*.bdf","*.set","*.fif","*.vhdr","*.eeg","*.cnt","*.fdt"],J=["*.tsv","*.json","*.md","*.txt","*.yml","*.yaml","README*","LICENSE*","CHANGES*",".bidsignore",".gitignore"],Q=$.map((G)=>`include=${G}`).join(" or "),Y=J.map((G)=>`exclude=${G}`).join(" and "),B=`(${Q} or largerthan=100kb) and ${Y}`,X=F||B;try{let{stderr:G,exitCode:H}=await I(["git","annex","config","--set","annex.largefiles",X],{cwd:D});if(H!==0)return{success:!1,error:G.trim()||"Failed to configure largefiles"};return{success:!0}}catch(G){return{success:!1,error:G.message}}}async function c6(D,F="."){try{let{stderr:$,exitCode:J}=await I(["git","annex","add",F],{cwd:D});if(J!==0)return{success:!1,error:$.trim()||"Failed to add files to git-annex"};return{success:!0}}catch($){return{success:!1,error:$.message}}}function CD(D){return{accessKeyId:D.access_key_id,secretAccessKey:D.secret_access_key,sessionToken:D.session_token}}function PW(D){let F=[/^\(merging .* into .*\.\.\.\)$/,/^\(recording state in git\.\.\.\)$/,/^\(scanning for /,/^\(checking /];return D.split(`
101
101
  `).filter(($)=>{let J=$.trim();if(!J)return!1;if(J.includes("setting annex-ignore"))return!1;if(F.some((Q)=>Q.test(J)))return!1;return!0}).join(`
@@ -126,7 +126,7 @@ Fix one of these:
126
126
  `)}async function ZE0(D,F,$){let J=await I(["bash","-c",`curl -sfL '${D}' | aws s3 cp - '${F}' --region '${$}'`],{});if(J.exitCode!==0)return{success:!1,error:J.stderr.trim()};return{success:!0}}async function UE0(D,F,$,J){let Q=0,Y=[];for(let B=0;B<D.length;B+=$){let X=D.slice(B,B+$),G=await Promise.allSettled(X.map(async(H)=>{let q=await ZE0(H.sourceUrl,H.destUri,F);if(!q.success)throw Error(q.error||"Unknown S3 copy error");return H.key}));for(let H=0;H<G.length;H++){let q=G[H];if(q.status==="fulfilled")Q++;else Y.push({key:X[H].key,error:q.reason?.message||"Unknown error"})}J?.(Q,D.length,X[X.length-1].key)}return{copied:Q,failed:Y}}async function LE0(D,F={}){let $=qE0(D),J=F.workDir||BE0(f9(WE0(),`nemar-import-${$}-`)),Q=f9(J,$);console.log(W.cyan(`
127
127
  Importing OpenNeuro dataset ${D} -> ${$}
128
128
  `)),console.log(W.dim(`Working directory: ${J}`));let Y=C("Cloning OpenNeuro dataset...").start(),B=`https://github.com/${HE0}/${D}.git`,X=await o1(B,Q);if(!X.success)Y.fail(`Failed to clone: ${X.error}`),process.exit(1);if(Y.succeed(`Cloned ${D}`),!await _9(Q,{yes:!0}))console.error(W.red("Cannot proceed with import: branch must be named 'main'.")),process.exit(1);let H=KE0(Q),q=H.Name||D,K=EE0(H);if(console.log(W.dim(` Dataset: ${q}`)),K)console.log(W.dim(` OpenNeuro DOI: ${K}`));let V=C("Creating NEMAR dataset record...").start();try{let g=await rf({dataset_id:$,name:q,description:`Imported from OpenNeuro ${D}`,source:"openneuro",source_id:D});V.succeed(`Created ${g.dataset_id} (${g.github_repo})`)}catch(g){let N0=g instanceof Error?g.message:String(g);if(N0.includes("already exists")||N0.includes("409"))V.warn(`Dataset ${$} already exists, continuing...`);else V.fail(`Failed to create dataset: ${N0}`),process.exit(1)}let E=C("Deploying CI workflows...").start();try{await _4($),E.succeed("CI workflows deployed (BIDS validation, LLM enrichment, archive generation)")}catch(g){let N0=g instanceof Error?g.message:String(g);E.warn(`CI deployment failed (non-fatal): ${N0}`),console.log(W.dim(` Workflows can be deployed later with: nemar admin ci add ${$}`))}let Z=new Map;if(!F.skipData){let g=C("Mapping annexed files from OpenNeuro S3...").start(),N0=await I(["git","annex","enableremote","s3-PUBLIC"],{cwd:Q});if(N0.exitCode!==0)g.fail(`Failed to enable s3-PUBLIC remote: ${N0.stderr.trim()}`),process.exit(1);if(Z=await oW(Q),Z.size===0)g.warn("No annexed files found, skipping data copy");else g.succeed(`Found ${Z.size} annexed files`)}await xW(Q,(g,N0)=>{console.log(W.yellow(` Warning: could not mark ${g} as annex-ignore (${N0}). Future pushes may try to upload to ${g}; run 'git config remote.${g}.annex-ignore true' manually.`))});let L=C("Configuring NEMAR remote...").start(),A=await I(["git","remote","remove","origin"],{cwd:Q});if(A.exitCode!==0&&!A.stderr.includes("No such remote"))L.fail(`Failed to remove OpenNeuro remote: ${A.stderr.trim()}`),process.exit(1);let M=`git@github.com:nemarDatasets/${$}.git`,R=await i8(Q,M,"origin");if(!R.success)L.fail(`Failed to configure remote: ${R.error}`),process.exit(1);if(L.succeed("Configured NEMAR remote"),!F.skipData&&Z.size>0){let g=C("Setting up NEMAR S3 remote...").start(),N0=zE0(),N=await R8(Q,{name:"nemar-s3",bucket:Og,prefix:`${$}/objects`,region:Tg},N0);if(!N.success)g.fail(`Failed to configure S3 remote: ${N.error}`),process.exit(1);let n=await sW(Q,"nemar-s3");if(!n)g.fail("Failed to get NEMAR S3 remote UUID"),process.exit(1);g.succeed("Configured NEMAR S3 remote");let l=C("Preparing S3-to-S3 copy...").start(),C0=[],m0=[];for(let[GD,G1]of Z){if(!G1.startsWith("http")){m0.push(GD);continue}let Jb=`s3://${Og}/${$}/objects/${GD}`;C0.push({key:GD,sourceUrl:G1,destUri:Jb})}if(m0.length>0)console.log(W.yellow(` Skipped ${m0.length} keys (no source URL)`));l.succeed(`Prepared ${C0.length} files for S3-to-S3 copy`);let $D=C(`Copying ${C0.length} files to NEMAR S3...`).start(),z0=await UE0(C0,Tg,8,(GD,G1)=>{$D.text=`Copying files to NEMAR S3... ${GD}/${G1}`});if(z0.failed.length>0){console.error(W.red(`
129
- Failed to copy ${z0.failed.length} files:`));for(let GD of z0.failed.slice(0,5))console.error(W.red(` ${GD.key}: ${GD.error}`));if(z0.failed.length>5)console.error(W.red(` ... and ${z0.failed.length-5} more`));$D.fail(`${z0.failed.length} of ${C0.length} files failed to copy. Re-run to retry.`),process.exit(1)}$D.succeed(`Copied ${z0.copied} files to NEMAR S3`);let OD=C("Registering files in git-annex...").start(),tD=new Set(z0.failed.map((GD)=>GD.key)),o6=C0.filter((GD)=>!tD.has(GD.key)).map((GD)=>GD.key),vF=await rW(Q,o6,n);if(vF.failed>0)console.log(W.yellow(` ${vF.failed} keys failed to register (non-fatal)`));OD.succeed(`Registered ${vF.success} files in git-annex`)}let T=C("Seeding metadata...").start();try{VE0(Q,$,D,H,K)}catch(g){T.fail(`Failed to seed metadata: ${g instanceof Error?g.message:String(g)}`),process.exit(1)}let k=await I(["git","add",".nemar/metadata.json"],{cwd:Q});if(k.exitCode!==0)T.fail(`Failed to stage metadata: ${k.stderr.trim()}`),process.exit(1);let O=await I(["git","commit","-m",`Add NEMAR metadata (imported from OpenNeuro ${D})`],{cwd:Q});if(O.exitCode!==0&&!O.stdout.includes("nothing to commit"))T.fail(`Failed to commit metadata: ${O.stderr.trim()}`),process.exit(1);T.succeed("Seeded .nemar/metadata.json");let j=C("Pushing to nemarDatasets...").start(),y=await I(["git","pull","--rebase","origin","main"],{cwd:Q});if(y.exitCode!==0&&!y.stderr.includes("up to date"))j.fail(`Failed to pull remote changes: ${y.stderr.trim()}`),process.exit(1);let d=await a1(Q,"origin");if(!d.success)j.fail(`Failed to push: ${d.error}`),process.exit(1);j.succeed("Pushed to nemarDatasets");let L0=C("Requesting publication...").start();try{await FQ($),L0.succeed("Publication requested")}catch(g){let N0=g instanceof Error?g.message:String(g);L0.fail(`Failed to request publication: ${N0}`),process.exit(1)}let D0=C("Approving publication...").start(),E0=10,Y0=!1;for(let g=1;g<=E0;g++)try{await $Q($,g>1,!1,!1),Y0=!0;break}catch(N0){let N=N0 instanceof Error?N0.message:String(N0);if(g<E0)D0.text=`Approving publication... (attempt ${g+1}/${E0})`,await new Promise((n)=>setTimeout(n,3000));else D0.fail(`Failed to approve publication after ${E0} attempts: ${N}`),process.exit(1)}if(Y0)D0.succeed("Publication approved");console.log(W.green(`
129
+ Failed to copy ${z0.failed.length} files:`));for(let GD of z0.failed.slice(0,5))console.error(W.red(` ${GD.key}: ${GD.error}`));if(z0.failed.length>5)console.error(W.red(` ... and ${z0.failed.length-5} more`));$D.fail(`${z0.failed.length} of ${C0.length} files failed to copy. Re-run to retry.`),process.exit(1)}$D.succeed(`Copied ${z0.copied} files to NEMAR S3`);let OD=C("Registering files in git-annex...").start(),tD=new Set(z0.failed.map((GD)=>GD.key)),o6=C0.filter((GD)=>!tD.has(GD.key)).map((GD)=>GD.key),vF=await rW(Q,o6,n);if(vF.failed>0)console.log(W.yellow(` ${vF.failed} keys failed to register (non-fatal)`));OD.succeed(`Registered ${vF.success} files in git-annex`)}let T=C("Seeding metadata...").start();try{VE0(Q,$,D,H,K)}catch(g){T.fail(`Failed to seed metadata: ${g instanceof Error?g.message:String(g)}`),process.exit(1)}let k=await I(["git","add",".nemar/metadata.json"],{cwd:Q});if(k.exitCode!==0)T.fail(`Failed to stage metadata: ${k.stderr.trim()}`),process.exit(1);let O=await I(["git","commit","-m",`Add NEMAR metadata (imported from OpenNeuro ${D})`],{cwd:Q});if(O.exitCode!==0&&!O.stdout.includes("nothing to commit"))T.fail(`Failed to commit metadata: ${O.stderr.trim()}`),process.exit(1);T.succeed("Seeded .nemar/metadata.json");let j=C("Pushing to nemarDatasets...").start(),y=await I(["git","pull","--rebase","origin","main"],{cwd:Q});if(y.exitCode!==0&&!y.stderr.includes("up to date"))j.fail(`Failed to pull remote changes: ${y.stderr.trim()}`),process.exit(1);let d=await a1(Q,"origin");if(!d.success)j.fail(`Failed to push: ${d.error}`),process.exit(1);j.succeed("Pushed to nemarDatasets");let L0=C("Requesting publication...").start();try{await FQ($),L0.succeed("Publication requested")}catch(g){let N0=g instanceof Error?g.message:String(g);L0.fail(`Failed to request publication: ${N0}`),process.exit(1)}let D0=C("Approving publication...").start(),E0=10,Y0=!1;for(let g=1;g<=E0;g++)try{await $Q($,g>1,!1,!0),Y0=!0;break}catch(N0){let N=N0 instanceof Error?N0.message:String(N0);if(g<E0)D0.text=`Approving publication... (attempt ${g+1}/${E0})`,await new Promise((n)=>setTimeout(n,3000));else D0.fail(`Failed to approve publication after ${E0} attempts: ${N}`),process.exit(1)}if(Y0)D0.succeed("Publication approved");console.log(W.green(`
130
130
  Import and publish complete: ${D} -> ${$}`)),console.log(W.dim(` GitHub: https://github.com/nemarDatasets/${$}`)),console.log(W.dim(` Working dir: ${Q}`))}var HE0="OpenNeuroDatasets",Og="nemar",Tg="us-east-2";var Pg=P(()=>{yD();c3();n8();n6()});var yg={};d4(yg,{runE2ETest:()=>TE0});import{cpSync as AE0,existsSync as FH,mkdirSync as ME0,mkdtempSync as Ig,readFileSync as NE0,rmSync as tW,writeFileSync as eW}from"fs";import{tmpdir as Sg}from"os";import{join as r8,resolve as DH}from"path";var{spawn:CE0}=globalThis.Bun;function vD(D,...F){if(D.verbose)console.log(" ",...F)}async function vg(D,F){let $=performance.now();try{return await F(),{name:D,passed:!0,duration_ms:Math.round(performance.now()-$)}}catch(J){let Q=J instanceof Error?J.message:String(J);return{name:D,passed:!1,duration_ms:Math.round(performance.now()-$),error:Q}}}async function RE0(D){let F=[];for(let{name:$,fn:J}of D){let Q=await vg($,J);if(F.push(Q),!Q.passed)break}return F}async function PF(D,F={}){let $=CE0({cmd:D,cwd:F.cwd,stdout:"pipe",stderr:"pipe",env:{...process.env,...F.env}}),J=await new Response($.stdout).text(),Q=await new Response($.stderr).text(),Y=await $.exited;return{stdout:J,stderr:Q,exitCode:Y}}function B1(D,F){if(!D.success)throw Error(`${F}: ${D.error}`)}function kg(D){if(!D.creds)throw Error("credentials not yet fetched");return D.creds}function OE0(){let D=[DH(__dirname,"../../test/fixtures/bids-minimal"),DH(__dirname,"../test/fixtures/bids-minimal"),DH(process.cwd(),"test/fixtures/bids-minimal")];for(let F of D)if(FH(F))return F;throw Error("Could not find test/fixtures/bids-minimal. Run from the nemar-cli root directory.")}async function TE0(D){let F=D.verbose??!1,$=performance.now(),J=Ig(r8(Sg(),"nemar-e2e-upload-")),Q=Ig(r8(Sg(),"nemar-e2e-clone-")),Y={uploadDir:J,cloneDir:Q,verbose:F},B=[];if(!D.skipReset)B.push({name:"Reset nm099999",fn:async()=>{let G=await af(h4);if(vD(Y,`S3 objects deleted: ${G.steps.s3_deleted}`),vD(Y,`GitHub recreated: ${G.steps.github_recreated}`),vD(Y,`D1 cleaned: ${G.steps.d1_cleaned}`),!G.success){let H=[];if(!G.steps.github_recreated)H.push("GitHub");if(!G.steps.d1_cleaned)H.push("D1");throw Error(`Reset partially failed: ${H.join(", ")}`)}}});B.push({name:"Prepare upload",fn:async()=>{let G=OE0();AE0(G,J,{recursive:!0});for(let H of[".git",".nemar",".gitattributes"]){let q=r8(J,H);if(FH(q)){let K=await PF(["chmod","-R","u+w",q]);if(K.exitCode!==0)console.warn(`chmod failed for ${q} (exit ${K.exitCode}): ${K.stderr}`);tW(q,{recursive:!0,force:!0})}}vD(Y,`Copied fixtures to ${J}`)}},{name:"Init git + annex",fn:async()=>{B1(await d6(J,{force:!0}),"initDataset"),B1(await f4(J),"configureLargefiles"),vD(Y,"Git + git-annex initialized")}},{name:"Configure remotes",fn:async()=>{Y.creds=await C8(h4),vD(Y,`S3 prefix: ${Y.creds.s3.prefix}`),B1(await R8(J,{name:"nemar-s3",bucket:Y.creds.s3.bucket,prefix:`${h4}/objects`,region:Y.creds.s3.region,publicUrl:`https://${Y.creds.s3.bucket}.s3.${Y.creds.s3.region}.amazonaws.com/${h4}/objects`},CD(Y.creds.credentials)),"configureS3Remote");let G=`git@github.com:nemarDatasets/${h4}.git`;B1(await i8(J,G),"configureGitHubRemote"),vD(Y,"S3 + GitHub remotes configured")}},{name:"Upload to S3",fn:async()=>{B1(await c6(J),"gitAnnexAdd"),B1(await a8(J,"Initial BIDS dataset"),"saveDataset");let G=await O8(J,"nemar-s3",4,CD(kg(Y).credentials));B1(G,"copyToAnnexRemote"),vD(Y,`Files copied to S3: ${G.filesCopied}`),await kD(J)}},{name:"Push to GitHub",fn:async()=>{let G=await a1(J);if(B1(G,"pushToGitHub"),G.warning)vD(Y,`Warning: ${G.warning}`);vD(Y,"Pushed to GitHub (main + git-annex branches)")}},{name:"Clone fresh",fn:async()=>{let G=`git@github.com:nemarDatasets/${h4}.git`;B1(await o1(G,Q),"cloneDataset");let H=await g4(Q,"nemar-s3");if(!H.success)throw Error(`enableS3Remote: ${H.error}`);vD(Y,`Clone at ${Q}, S3 remote enabled: ${H.enabled}`)}},{name:"Download + verify",fn:async()=>{let G=CD(kg(Y).credentials),H={AWS_ACCESS_KEY_ID:G.accessKeyId,AWS_SECRET_ACCESS_KEY:G.secretAccessKey};if(G.sessionToken)H.AWS_SESSION_TOKEN=G.sessionToken;let{stdout:q,stderr:K,exitCode:V}=await PF(["git","annex","get","."],{cwd:Q,env:H});if(V!==0)throw Error(`getDatasetData: ${K.trim()}`);let E=q.match(/^get .+ ok$/gm);vD(Y,`Files downloaded: ${E?E.length:0}`);let Z=r8(Q,"sub-01/eeg/sub-01_task-rest_eeg.edf");if(!FH(Z))throw Error("EDF file not found after download");let{size:L}=Bun.file(Z);if(L<512)throw Error(`EDF file too small: ${L} bytes`);vD(Y,`EDF file verified: ${L} bytes`)}},{name:"Update cycle",fn:async()=>{let G=r8(Q,"sub-02/eeg");ME0(G,{recursive:!0});let H=Buffer.alloc(1024);H.write("0".padEnd(8),0,"ascii"),eW(r8(G,"sub-02_task-rest_eeg.edf"),H),eW(r8(G,"sub-02_task-rest_eeg.json"),JSON.stringify({TaskName:"rest",SamplingFrequency:256}));let q=NE0(r8(Q,"participants.tsv"),"utf-8");eW(r8(Q,"participants.tsv"),`${q.trimEnd()}
131
131
  sub-02 30 F
132
132
  `);let K=`e2e-update-${Date.now()}`,{exitCode:V}=await PF(["git","checkout","-b",K],{cwd:Q});if(V!==0)throw Error("Failed to create update branch");B1(await c6(Q),"gitAnnexAdd (update)"),B1(await a8(Q,"Add sub-02"),"saveDataset (update)"),Y.creds=await C8(h4);let E=await O8(Q,"nemar-s3",4,CD(Y.creds.credentials));B1(E,"copyToAnnexRemote (update)"),vD(Y,`Update files copied to S3: ${E.filesCopied}`),await kD(Q);let Z=await a1(Q,"origin",K);B1(Z,"pushToGitHub (update branch)");let{exitCode:L,stderr:A}=await PF(["git","push","origin","git-annex"],{cwd:Q});if(L!==0)throw Error(`Failed to push git-annex branch: ${A.trim()}`);vD(Y,`Update pushed to branch: ${K}`)}});let X=await RE0(B);if(!D.skipCleanup&&X.every((G)=>G.passed))X.push(await vg("Cleanup",async()=>{await PF(["chmod","-R","u+w",J]),await PF(["chmod","-R","u+w",Q]),tW(J,{recursive:!0,force:!0}),tW(Q,{recursive:!0,force:!0}),vD(Y,"Temp directories cleaned up")}));return wE0(X,$,J,Q,D.skipCleanup)}function wE0(D,F,$,J,Q){let Y={passed:D.every((B)=>B.passed),steps:D,total_duration_ms:Math.round(performance.now()-F)};if(Q)Y.upload_dir=$,Y.clone_dir=J;return Y}var __dirname="/home/runner/work/nemar-cli/nemar-cli/src/lib",h4="nm099999";var xg=P(()=>{n8();n6()});var Ph,gk0;var Ih=P(()=>{Ph=["IsCitedBy","Cites","IsSupplementTo","IsSupplementedBy","IsContinuedBy","Continues","IsDescribedBy","Describes","HasMetadata","IsMetadataFor","HasVersion","IsVersionOf","IsNewVersionOf","IsPreviousVersionOf","IsPartOf","HasPart","IsReferencedBy","References","IsDocumentedBy","Documents","IsCompiledBy","Compiles","IsVariantFormOf","IsOriginalFormOf","IsIdenticalTo","IsCollectedBy","Collects","IsRequiredBy","Requires","IsObsoletedBy","Obsoletes","IsDerivedFrom","IsSourceOf","IsReviewedBy","Reviews","IsPublishedIn","HasTranslation","IsTranslationOf"],gk0=new Set(Ph)});function wH(D){return D.replace(/^(doi:|https?:\/\/(dx\.)?doi\.org\/)/i,"").trim()}function Sh(D){let F=D.split(",").map(($)=>$.trim());if(F.length>=2)return{name:D,familyName:F[0],givenName:F.slice(1).join(", ")};return{name:D}}var kh=P(()=>{Ih()});var uh={};d4(uh,{queryDataCiteDoi:()=>gh,queryCrossrefDoi:()=>hh,mergeOrcidDiscoveries:()=>wV0,matchCreatorsToAuthors:()=>bh,extractDoisFromRelatedIdentifiers:()=>RV0,extractDoisFromBids:()=>_h,discoverOrcidsFromReferencedDois:()=>jV0});function _h(D){let F=[],$=new Set,J=(Q,Y)=>{let B=wH(Q).trim();if(xh.test(B)&&!$.has(B))$.add(B),F.push({doi:B,source:Y})};if(Array.isArray(D.SourceDatasets))for(let Q of D.SourceDatasets){if(!Q||typeof Q!=="object")continue;let Y=Q;if(typeof Y.DOI==="string")J(Y.DOI,"SourceDatasets");else if(typeof Y.URL==="string"){let B=Y.URL.match(/(?:doi\.org\/|doi:)(10\.\d{4,}\/.+)/);if(B)J(B[1],"SourceDatasets")}}if(Array.isArray(D.ReferencesAndLinks))for(let Q of D.ReferencesAndLinks){if(typeof Q!=="string"||!Q)continue;let Y=Q.match(/(?:doi\.org\/|^)(10\.\d{4,}\/[^\s]+)/);if(Y)J(Y[1],"ReferencesAndLinks")}if(typeof D.HowToAcknowledge==="string"){let Y=D.HowToAcknowledge.matchAll(/(?:doi\.org\/|(?<=\s|^))(10\.\d{4,}\/[^\s,)]+)/g);for(let B of Y)J(B[1].replace(/[.;:]+$/,""),"HowToAcknowledge")}return F}function RV0(D,F){let $=[];for(let J of D){if(!J||typeof J.identifier!=="string")continue;if(J.identifier_type!=="DOI")continue;let Q=wH(J.identifier).trim();if(xh.test(Q)&&!F.has(Q))F.add(Q),$.push({doi:Q,source:"RelatedIdentifiers"})}return $}function fh(D,F,$){let J=$ instanceof Error?$.message:String($);if(J.includes("AbortError")||J.includes("timeout")||J.includes("fetch"))console.warn(`[orcid-discovery] ${D} query failed for ${F}: ${J}`);else console.error(`[orcid-discovery] Unexpected error querying ${D} for ${F}:`,$)}async function gh(D){try{let F=await fetch(`${OV0}/${encodeURIComponent(D)}`,{headers:{Accept:"application/vnd.datacite.datacite+json"},signal:AbortSignal.timeout(1e4)});if(!F.ok){if(F.status!==404)console.warn(`[orcid-discovery] DataCite returned HTTP ${F.status} for ${D}`);return null}let $=await F.json();return{doi:D,creators:Array.isArray($.creators)?$.creators:[]}}catch(F){return fh("DataCite",D,F),null}}async function hh(D){try{let F=await fetch(`https://api.crossref.org/works/${encodeURIComponent(D)}`,{headers:{Accept:"application/json","User-Agent":"NEMAR/1.0 (https://nemar.org; mailto:nemar@ucsd.edu)"},signal:AbortSignal.timeout(1e4)});if(!F.ok){if(F.status!==404)console.warn(`[orcid-discovery] Crossref returned HTTP ${F.status} for ${D}`);return null}let J=(await F.json()).message?.author;if(!Array.isArray(J)||J.length===0)return null;let Q=J.map((Y)=>{let B=[];if(Y.ORCID)B.push({nameIdentifier:Y.ORCID,nameIdentifierScheme:"ORCID"});return{name:Y.family&&Y.given?`${Y.family}, ${Y.given}`:Y.name||Y.family||"",givenName:Y.given,familyName:Y.family,nameIdentifiers:B,affiliation:(Y.affiliation||[]).filter((X)=>X.name)}}).filter((Y)=>Y.name.trim()!=="");return{doi:D,creators:Q}}catch(F){return fh("Crossref",D,F),null}}async function TV0(D){let F=await gh(D),$=await hh(D);if(!F)return $;if(!$)return F;for(let J of F.creators){if(J.nameIdentifiers?.some((X)=>X.nameIdentifierScheme==="ORCID")||!J.familyName)continue;let B=$.creators.find((X)=>X.familyName&&T1(X.familyName)===T1(J.familyName))?.nameIdentifiers?.find((X)=>X.nameIdentifierScheme==="ORCID");if(B)J.nameIdentifiers=[...J.nameIdentifiers??[],B]}return F}function T1(D){return D.normalize("NFD").replace(/\p{Diacritic}/gu,"").replace(/\./g,"").toLowerCase().trim()}function vh(D){if(!D)return"";return T1(D).charAt(0)}function bh(D,F){let $=[],J=new Set,Q=new Set,Y=F.map((B)=>({original:B,parsed:Sh(B)}));for(let B=0;B<D.length;B++){if(Q.has(B))continue;let X=D[B],G=T1(X.name);for(let H of Y){if(J.has(H.original))continue;if(T1(H.original)===G){$.push({bidsAuthor:H.original,matchedCreator:X,confidence:"exact"}),J.add(H.original),Q.add(B);break}if(H.parsed.familyName&&H.parsed.givenName){if(T1(`${H.parsed.givenName} ${H.parsed.familyName}`)===G){$.push({bidsAuthor:H.original,matchedCreator:X,confidence:"exact"}),J.add(H.original),Q.add(B);break}}if(X.givenName&&X.familyName){let q=T1(`${X.givenName} ${X.familyName}`);if(T1(H.original)===q){$.push({bidsAuthor:H.original,matchedCreator:X,confidence:"exact"}),J.add(H.original),Q.add(B);break}}}}for(let B=0;B<D.length;B++){if(Q.has(B))continue;let X=D[B];if(!X.familyName)continue;let G=T1(X.familyName),H=vh(X.givenName);for(let q of Y){if(J.has(q.original))continue;if(!q.parsed.familyName)continue;if(T1(q.parsed.familyName)!==G)continue;let V=vh(q.parsed.givenName);if(V&&H&&V===H){$.push({bidsAuthor:q.original,matchedCreator:X,confidence:"high"}),J.add(q.original),Q.add(B);break}}}for(let B=0;B<D.length;B++){if(Q.has(B))continue;let X=D[B];if(!X.familyName)continue;let G=T1(X.familyName);for(let H of Y){if(J.has(H.original))continue;if(!H.parsed.familyName)continue;if(T1(H.parsed.familyName)===G){$.push({bidsAuthor:H.original,matchedCreator:X,confidence:"medium"}),J.add(H.original),Q.add(B);break}}}return $}function wV0(D,F){let $={...D};for(let[J,Q]of Object.entries(F))$[J]={...$[J],orcid:Q.orcid,affiliations:Q.affiliations??$[J]?.affiliations};return $}async function jV0(D,F,$){let J=_h(D);if($?.length)J.push(...$);if(J.length===0)return{discoveries:{},unresolvedDois:[],totalDoisQueried:0};let Q=Array.isArray(D.Authors)?D.Authors.filter((q)=>typeof q==="string"):[];if(Q.length===0)return{discoveries:{},unresolvedDois:[],totalDoisQueried:J.length};let Y=new Set;if(F){for(let[q,K]of Object.entries(F))if(K.orcid)Y.add(q)}let B=Q.filter((q)=>!Y.has(q));if(B.length===0)return{discoveries:{},unresolvedDois:[],totalDoisQueried:J.length};let X=[],G=new Map;for(let q=0;q<J.length;q+=yh){let K=J.slice(q,q+yh),V=await Promise.all(K.map((E)=>TV0(E.doi)));for(let E=0;E<K.length;E++)if(V[E])G.set(K[E].doi,V[E]?.creators??[]);else X.push(K[E].doi)}let H={};for(let[q,K]of G){let V=K.filter((Z)=>Z.nameIdentifiers?.some((L)=>L.nameIdentifierScheme==="ORCID"));if(V.length===0)continue;let E=bh(V,B);for(let Z of E){if(H[Z.bidsAuthor])continue;let L=Z.matchedCreator.nameIdentifiers.find((R)=>R.nameIdentifierScheme==="ORCID");if(!L)continue;let A=L.nameIdentifier.replace(/^https?:\/\/orcid\.org\//i,"").trim();if(!CV0.test(A))continue;let M=Z.matchedCreator.affiliation?.filter((R)=>R.name).map((R)=>({name:R.name,...R.affiliationIdentifier&&{identifier:R.affiliationIdentifier},...R.affiliationIdentifierScheme&&{scheme:R.affiliationIdentifierScheme}}));H[Z.bidsAuthor]={orcid:A,affiliations:M?.length?M:void 0,sourceDoi:q,confidence:Z.confidence}}}return{discoveries:H,unresolvedDois:X,totalDoisQueried:J.length}}var xh,CV0,OV0="https://api.datacite.org/application/vnd.datacite.datacite+json",yh=5;var mh=P(()=>{kh();xh=/^10\.\d{4,}\/[^\s]+$/,CV0=/^\d{4}-\d{4}-\d{4}-[\dX]{4}$/});yD();var $q=s(Fq(),1),{program:TZ0,createCommand:wZ0,createArgument:jZ0,createOption:PZ0,CommanderError:IZ0,InvalidArgumentError:SZ0,InvalidOptionArgumentError:kZ0,Command:i0,Argument:vZ0,Option:yZ0,Help:xZ0}=$q.default;var Qq=process.argv.includes("--help-all");if(process.argv.includes("--no-color"))W.level=0;var Jq=process.argv.indexOf("--help-all");if(Jq!==-1)process.argv[Jq]="--help";var fF=i0.prototype.addHelpText,Yq=`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nemar-cli",
3
- "version": "0.8.10-dev.748",
3
+ "version": "0.8.10-dev.753",
4
4
  "description": "CLI for NEMAR (Neuroelectromagnetic Data Archive and Tools Resource) dataset management",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",