npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jsxnat

v1.1.1

Published

An isomorphic XNAT API Wrapper for JavaScript

Downloads

9

Readme

Open in Gitpod

JsXnat

JsXnat provides a higher-level JavaScript wrapper around XNAT's rest API. This library tries to be isomporphic, so most of the functionality works in both Node.js and Broswer environments.

Install

JsXnat is available from npm or unpkg.

npm install jsxnat
yarn add jsxnat
<script src="https://unpkg.com/jsxnat/dist/web/jsxnat.umd.js"></script>

API Documentation

API documentation is hosted on github pages, and is generated from JSDoc

Usage

Authentication Method

There are 3 authentication methods available.

  1. noAuth This is used when the web app that uses this library is packaged into the XNAT plugin and it is launched in the same context of the XNAT node that it points to. In this case, seprate authentication is not needed. e.g., new JsXnat('noAuth', '/');
  2. password Username and password provided is used for the XNAT authentication. Each XNAT Rest API call is independent and run in the different session. e.g., new JsXnat('password', 'http://localhost:8080', { username: 'username', password: 'password' });
  3. token Username and password provided is used for the XNAT authentication. Before the first XNAT method call, an alias token is created and this will be used in every subsequent XNAT rest API call. The token creation and recreation after expiration is internally managed. e.g., new JsXnat('token', 'http://localhost:8080', { username: 'username', password: 'password' });

Output

The output format of XNAT rest API call (via corresponding wrapper class method) is JSON by default.

...
const projectApi = jsXnat.getProjectApi();
      projectApi
        .getProjects()
        .then((res) => {
          console.log(res.ResultSet.Result);
        })

[ { pi_firstname: '', secondary_ID: 'Subj_001', pi_lastname: '', name: 'Sample Project', description: '', ID: 'Subj_001', URI: '/data/projects/Subj_001' }, ... ]

Import

Node.js with the CommonJS module system

const JsXnat = require('jsxnat');

Node.js with the ES6 module system

import JsXnat from 'jsxnat';

Browser or Electron with the ES6 module system (with a build tool)

import JsXnat from 'jsxnat/web/jsxnat.js';

Browser or Electron with HTML

<script src="https://unpkg.com/[email protected]/dist/web/jsxnat.umd.js"></script>

Sample Usage

var jsXnat = new JsXnat('password', 'http://localhost:8080', { username: 'username', password: 'password' });
const projectApi = jsXnat.getProjectApi();
projectApi.getProjects().then(res => {
  console.log(res);
}).catch(err => {
  console.log(err);
});

Library Structure

JsXnat is the main class for accessing all the sub classes and the API methods in them. There are more than 200 APIs defined in the XNAT, so I created the following sub structure for you to easily navigate the APIs you want. The stucture almost resembles the structure of [XNAT REST API Directory] (https://wiki.xnat.org/display/XAPI/XNAT+REST+API+Directory) but there are some difference.

Some REST APIs have mutiple methods defined in the differnt sub-classes for users to easily find them.)

There are three categories: XNAT Administration, XNAT Data Management, Plugins

  1. XNAT Administration

    • APIS for XNAT administrators
    • two level object should be retrieved to use a method. e.g., Take a getSiteWideConfig as an example.
    const jsXnat = new JsXnat(...);
    const siteAdmin = jsXnat.getSiteAdmin();
    const siteConfigApi = siteAdmin.getSiteConfigApi();
    siteConfigApi.getSiteConfig()
  2. XNAT Data Management

    • APIs for Data Management (Projects, Subject, Experiment, Scans, etc.)
    • Just one level object should be retirieved to use a method e.g., Take a getExperimentsInProject as an example.
    const jsXnat = new JsXnat(...);
    const experimentApi = jsXnat.getExperimentApi();
    experimentApi.getExperimentsInProject(projectId);
  3. Plugins (To be added in the future)

    • APIs for 3rd party plugins
└── JsXnat
    ├── XnatAdmin
    │   ├── SiteAdmin
    │   │   ├── SiteWideConfig (jsXnat.getSiteAdmin().getSiteConfigApi())
    │   │   ├── Preference
    │   │   └── DataTypeSchema
    │   ├── SystemAdmin
    │   │   ├── Archive
    │   │   ├── Notification
    │   │   └── Task
    │   ├── UserAdmin
    │   │   ├── UserMgmt (TBD)
    │   │   ├── UserResource (TBD)
    │   │   ├── ProjectUserAccess (TBD)
    │   │   └── ProjectAccessRequest (TBD)
    │   ├── UserAuth
    │   │   ├── UserSessionMgmt (TBD)
    │   │   ├── UserAuthService
    │   │   └── UserAliasToken
    │   ├── PluginAdmin
    │   │   └── Plugin
    │   ├── UiConfig
    │   │   ├── UiSpawner
    │   │   ├── UiTheme
    │   ├── DicomConfig
    │   │   ├── DicomScp
    │   │   └── Anonymization
    │   └── OtherService
    │   │   ├── FileMover
    │   │   ├── Email
    │   │   ├── Audit
    │   │   └── CatalogRefresh
    ├── XnatDataMgmt
    │   ├── Project (jsXnat.getProjectApi())
    │   ├── Subject (jsXnat.getSubjectApi())
    │   ├── Experiment (jsXnat.getExperimentApi())
    │   ├── Scan (jsXnat.getProjectApi())
    │   ├── ImageAssessor (jsXnat.ImageAssessorApi())
    │   ├── Resource
    │   ├── Archive
    │   ├── Search
    │   ├── DataProcessing
    │   ├── Automation
    │   ├── Prearchive
    │   └── Workflow
    └──  Plugins

User Alias Token

CORS

To use the JsXnat in the client side (e.g., browser), you should configure your XNAT tomcat sevrer and Spring Security to allow your XNAT to support the Cross Origin Resource Request (CORS).

License

MIT