registry.js
function Registry(opts) {
  var defaultOptions = {
    resourceCapabilitiesEndPoint:
      'http://www.cadc-ccda.hia-iha.nrc-cnrc.gc.ca/reg/resource-caps'
  }

  var options = opts || {}
  this.axiosConfig = {
    method: 'get',
    withCredentials: true,
    crossDomain: true
  }

  this.resourceCapabilitiesURL = URL.parse(
    options.resourceCapabilitiesEndPoint ||
      defaultOptions.resourceCapabilitiesEndPoint
  )

  /**
   * @param {URL} URI of the resource to obtain a service URL for.
   * @param {{}} callback Function to callback.  Optional, and defaults to a Promise.
   * @returns {Promise}
   */
  this.capabilityURLs = async function(callback) {
    var aConf = Object.assign(
      { url: this.resourceCapabilitiesURL.href },
      this.axiosConfig
    )
    var p = axios(aConf)

    if (callback) {
      p.then(callback)
    } else {
      return p
    }
  }

  /**
   * Obtain a service URL endpoint for the given resource and standard IDs
   *
   * @param {String|URL} resourceURI   The Resource URI to lookup.
   * @param {String|URL}   The Standard ID URI to lookup.
   * @param {boolean} secureFlag  Whether to look for HTTPS access URLs.  Requires client certificate.
   * @param {{}} callback      Optional function to callback.
   * @returns {Promise}
   */
  this.serviceURL = async function(
    resourceURI,
    standardURI,
    secureFlag,
    callback
  ) {
    var aConf = Object.assign({}, this.axiosConfig)
    return this.capabilityURLs().then(function(results) {
      var properties = new PropertiesReader().read(results.data)
      var capabilitiesURL = properties.get(resourceURI)

      if (capabilitiesURL) {
        aConf.url = capabilitiesURL
        return axios(aConf).then(function(capResults) {
          var doc = new DOMParser().parseFromString(capResults.data)

          var capabilityFields = doc.documentElement.getElementsByTagName(
            'capability'
          )

          for (var i = 0, cfl = capabilityFields.length; i < cfl; i++) {
            var next = capabilityFields[i]

            if (next.getAttribute('standardID') === standardURI) {
              var interfaces = next.getElementsByTagName('interface')

              for (var j = 0, il = interfaces.length; j < il; j++) {
                var nextInterface = interfaces[j]
                var securityMethods = nextInterface.getElementsByTagName(
                  'securityMethod'
                )
                if (
                  (secureFlag === false && securityMethods.length === 0) ||
                  (secureFlag === true &&
                    securityMethods.length > 0 &&
                    securityMethods[0].getAttribute('standardID') ===
                      'ivo://ivoa.net/sso#tls-with-certificate')
                ) {
                  // Actual URL value.
                  var accessURLElements = nextInterface.getElementsByTagName(
                    'accessURL'
                  )
                  return accessURLElements.length > 0
                    ? accessURLElements[0].childNodes[0].nodeValue
                    : null
                }
              }
            }
          }

          throw 'No service URL found'
        })
      } else {
        throw `No service entry found for ${resourceURI}`
      }
    })
  }
}
function Registry(opts) {
  var defaultOptions = {
    resourceCapabilitiesEndPoint:
      'http://www.cadc-ccda.hia-iha.nrc-cnrc.gc.ca/reg/resource-caps'
  }

  var options = opts || {}
  this.axiosConfig = {
    method: 'get',
    withCredentials: true,
    crossDomain: true
  }

  this.resourceCapabilitiesURL = URL.parse(
    options.resourceCapabilitiesEndPoint ||
      defaultOptions.resourceCapabilitiesEndPoint
  )

  /**
   * @param {URL} URI of the resource to obtain a service URL for.
   * @param {{}} callback Function to callback.  Optional, and defaults to a Promise.
   * @returns {Promise}
   */
  this.capabilityURLs = async function(callback) {
    var aConf = Object.assign(
      { url: this.resourceCapabilitiesURL.href },
      this.axiosConfig
    )
    var p = axios(aConf)

    if (callback) {
      p.then(callback)
    } else {
      return p
    }
  }

  /**
   * Obtain a service URL endpoint for the given resource and standard IDs
   *
   * @param {String|URL} resourceURI   The Resource URI to lookup.
   * @param {String|URL}   The Standard ID URI to lookup.
   * @param {boolean} secureFlag  Whether to look for HTTPS access URLs.  Requires client certificate.
   * @param {{}} callback      Optional function to callback.
   * @returns {Promise}
   */
  this.serviceURL = async function(
    resourceURI,
    standardURI,
    secureFlag,
    callback
  ) {
    var aConf = Object.assign({}, this.axiosConfig)
    return this.capabilityURLs().then(function(results) {
      var properties = new PropertiesReader().read(results.data)
      var capabilitiesURL = properties.get(resourceURI)

      if (capabilitiesURL) {
        aConf.url = capabilitiesURL
        return axios(aConf).then(function(capResults) {
          var doc = new DOMParser().parseFromString(capResults.data)

          var capabilityFields = doc.documentElement.getElementsByTagName(
            'capability'
          )

          for (var i = 0, cfl = capabilityFields.length; i < cfl; i++) {
            var next = capabilityFields[i]

            if (next.getAttribute('standardID') === standardURI) {
              var interfaces = next.getElementsByTagName('interface')

              for (var j = 0, il = interfaces.length; j < il; j++) {
                var nextInterface = interfaces[j]
                var securityMethods = nextInterface.getElementsByTagName(
                  'securityMethod'
                )
                if (
                  (secureFlag === false && securityMethods.length === 0) ||
                  (secureFlag === true &&
                    securityMethods.length > 0 &&
                    securityMethods[0].getAttribute('standardID') ===
                      'ivo://ivoa.net/sso#tls-with-certificate')
                ) {
                  // Actual URL value.
                  var accessURLElements = nextInterface.getElementsByTagName(
                    'accessURL'
                  )
                  return accessURLElements.length > 0
                    ? accessURLElements[0].childNodes[0].nodeValue
                    : null
                }
              }
            }
          }

          throw 'No service URL found'
        })
      } else {
        throw `No service entry found for ${resourceURI}`
      }
    })
  }
}
function Registry ( opts ) { var defaultOptions = { resourceCapabilitiesEndPoint : 'http://www.cadc-ccda.hia-iha.nrc-cnrc.gc.ca/reg/resource-caps' } var options = opts || { } this . axiosConfig = { method : 'get' , withCredentials : true , crossDomain : true } this . resourceCapabilitiesURL = URL . parse ( options . resourceCapabilitiesEndPoint || defaultOptions . resourceCapabilitiesEndPoint ) /**
   * @param {URL} URI of the resource to obtain a service URL for.
   * @param {{}} callback Function to callback.  Optional, and defaults to a Promise.
   * @returns {Promise}
   */ this . capabilityURLs = async function ( callback ) { var aConf = Object . assign ( { url : this . resourceCapabilitiesURL . href } , this . axiosConfig ) var p = axios ( aConf ) if ( callback ) { p . then ( callback ) } else { return p } } /**
   * Obtain a service URL endpoint for the given resource and standard IDs
   *
   * @param {String|URL} resourceURI   The Resource URI to lookup.
   * @param {String|URL}   The Standard ID URI to lookup.
   * @param {boolean} secureFlag  Whether to look for HTTPS access URLs.  Requires client certificate.
   * @param {{}} callback      Optional function to callback.
   * @returns {Promise}
   */ this . serviceURL = async function ( resourceURI , standardURI , secureFlag , callback ) { var aConf = Object . assign ( { } , this . axiosConfig ) return this . capabilityURLs ( ) . then ( function ( results ) { var properties = new PropertiesReader ( ) . read ( results . data ) var capabilitiesURL = properties . get ( resourceURI ) if ( capabilitiesURL ) { aConf . url = capabilitiesURL return axios ( aConf ) . then ( function ( capResults ) { var doc = new DOMParser ( ) . parseFromString ( capResults . data ) var capabilityFields = doc . documentElement . getElementsByTagName ( 'capability' ) for ( var i = 0 , cfl = capabilityFields . length ; i < cfl ; i ++ ) { var next = capabilityFields [ i ] if ( next . getAttribute ( 'standardID' ) === standardURI ) { var interfaces = next . getElementsByTagName ( 'interface' ) for ( var j = 0 , il = interfaces . length ; j < il ; j ++ ) { var nextInterface = interfaces [ j ] var securityMethods = nextInterface . getElementsByTagName ( 'securityMethod' ) if ( ( secureFlag === false && securityMethods . length === 0 ) || ( secureFlag === true && securityMethods . length > 0 && securityMethods [ 0 ] . getAttribute ( 'standardID' ) === 'ivo://ivoa.net/sso#tls-with-certificate' ) ) { // Actual URL value. var accessURLElements = nextInterface . getElementsByTagName ( 'accessURL' ) return accessURLElements . length > 0 ? accessURLElements [ 0 ] . childNodes [ 0 ] . nodeValue : null } } } } throw 'No service URL found' } ) } else { throw ` ${ resourceURI } ` } } ) } }
Registry client constructor.

This client ALWAYS uses the JWT authorization.

@param {{}} opts
@constructor
Registry client constructor .