Sha256: 7f4c39f5452fee9521cb1646811504a940b3cbb550204e85466ae3e29b906f45

Contents?: true

Size: 1.43 KB

Versions: 20

Compression:

Stored size: 1.43 KB

Contents

// @ts-check

const { request: httpRequest } = require('http');
const { request: httpsRequest } = require('https');
const { baseURL, apiKey, exists } = require('./settings');

/** @typedef {import('./types').AppMapListItem} AppMapListItem */

/**
 * Lists AppMaps in a mapset.
 *
 * @param {number} mapset
 * @returns {Promise<AppMapListItem[]>}
 */
const listAppMaps = async (mapset) => {
  if (!exists) {
    throw new Error(`AppMap client is not configured`);
  }

  return new Promise((resolve, reject) => {
    const listAppMapsURL = new URL([baseURL, 'api/appmaps'].join('/'));
    listAppMapsURL.searchParams.append('mapsets[]', mapset.toString());
    const requestFunction =
      listAppMapsURL.protocol === 'https:' ? httpsRequest : httpRequest;
    const req = requestFunction(
      listAppMapsURL,
      {
        headers: {
          Authorization: `Bearer ${apiKey}`,
          Accept: 'application/json',
        },
      },
      // eslint-disable-next-line consistent-return
      (res) => {
        if (res.statusCode >= 300) {
          return reject(res.statusCode);
        }
        let data = '';
        res.setEncoding('utf8');
        res.on('data', (chunk) => {
          data += chunk;
        });
        res.on('end', () => {
          resolve(JSON.parse(data));
        });
      }
    );

    req.on('error', (e) => {
      reject(e);
    });

    // Write data to request body
    req.end();
  });
};

module.exports = listAppMaps;

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
appmap-0.72.2 ./node_modules/@appland/appmap/src/appland/listAppMaps.js
appmap-0.72.1 ./node_modules/@appland/appmap/src/appland/listAppMaps.js
appmap-0.72.0 ./node_modules/@appland/appmap/src/appland/listAppMaps.js
appmap-0.71.0 ./node_modules/@appland/appmap/src/appland/listAppMaps.js
appmap-0.70.2 ./node_modules/@appland/appmap/src/appland/listAppMaps.js
appmap-0.70.1 ./node_modules/@appland/appmap/src/appland/listAppMaps.js
appmap-0.70.0 ./node_modules/@appland/appmap/src/appland/listAppMaps.js
appmap-0.69.0 ./node_modules/@appland/appmap/src/appland/listAppMaps.js
appmap-0.68.2 ./node_modules/@appland/appmap/src/appland/listAppMaps.js
appmap-0.68.1 ./node_modules/@appland/appmap/src/appland/listAppMaps.js
appmap-0.68.0 ./node_modules/@appland/appmap/src/appland/listAppMaps.js
appmap-0.67.1 ./node_modules/@appland/appmap/src/appland/listAppMaps.js
appmap-0.67.0 ./node_modules/@appland/appmap/src/appland/listAppMaps.js
appmap-0.66.2 ./node_modules/@appland/appmap/src/appland/listAppMaps.js
appmap-0.66.1 ./node_modules/@appland/appmap/src/appland/listAppMaps.js
appmap-0.66.0 ./node_modules/@appland/appmap/src/appland/listAppMaps.js
appmap-0.65.1 ./node_modules/@appland/appmap/src/appland/listAppMaps.js
appmap-0.65.0 ./node_modules/@appland/appmap/src/appland/listAppMaps.js
appmap-0.64.0 ./node_modules/@appland/appmap/src/appland/listAppMaps.js
appmap-0.63.0 ./node_modules/@appland/appmap/src/appland/listAppMaps.js