How to use enigma - 10 common examples

To help you get started, we’ve selected a few enigma examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / enigma.js / enigma.js-tests.ts View on Github external
import * as enigma from "enigma.js";
// import enigma = require("enigma.js");

const config: enigmaJS.IConfig = {
            url: "http://127.0.0.1:4848/",
            schema: {}
        };
enigma.create(config).open().then((global) => {
    console.log("connect fine");
});
github qlik-oss / core-get-started / hello-world / app.js View on Github external
/* eslint no-console:0 */
const enigmaConfig = require('./enigma-config');
const enigma = require('enigma.js');

console.log('Connecting to QIX Engine');

enigma.create(enigmaConfig).open().then((qix) => {
  console.log('Connection established');
  return qix.engineVersion();
})
.then((version) => {
  console.log(`Hello, I am QIX Engine! I am running version: ${version.qComponentVersion}`);
  process.exit(0);
})
.catch((err) => {
  console.log(`Error when connecting to QIX Engine: ${err.message}`);
  process.exit(1);
});
github qlik-oss / enigma.js / examples / interceptors / retry-aborted / retry-aborted.js View on Github external
const schema = require('enigma.js/schemas/12.20.0.json');

// How many consecutive times we should retry before failing, try lowering this
// to see how it behaves when you reach MAX_RETRIES:
const MAX_RETRIES = 3;
// We auto-generate a table with one million entries to make sure we can reproduce
// aborted requests:
const qlikScript = `
TempTable:
Load
RecNo() as ID,
Rand() as Value
AutoGenerate 1000000
`;

const session = enigma.create({
  schema,
  url: 'ws://localhost:9076/app/engineData',
  createSocket: (url) => new WebSocket(url),
  responseInterceptors: [{
    // We only want to handle failed responses from QIX Engine:
    onRejected: function retryAbortedError(sessionReference, request, error) {
      console.log('Request: Rejected', error);
      // We only want to handle aborted QIX errors:
      if (error.code === schema.enums.LocalizedErrorCode.LOCERR_GENERIC_ABORTED) {
        // We keep track of how many consecutive times we have tried to do this call:
        request.tries = (request.tries || 0) + 1;
        console.log(`Request: Retry #${request.tries}`);
        // We do not want to get stuck in an infinite loop here if something has gone
        // awry, so we only retry until we have reached MAX_RETRIES:
        if (request.tries <= MAX_RETRIES) {
          return request.retry();
github qlik-oss / enigma.js / examples / mixins / complex / complex.js View on Github external
}
        return result;
      };
      if (!this.myMixin.pending) {
        this.myMixin.numberOfCallsToEngine += 1;
        console.log(`Mixin: Calling QIX Engine: ${this.myMixin.numberOfCallsToEngine}`);
        this.myMixin.pending = base().then(clearPending).catch(clearPending);
      } else {
        console.log('Mixin: Return from cache');
      }
      return this.myMixin.pending;
    },
  },
};

const session = enigma.create({
  schema,
  mixins: [mixin],
  url: 'ws://localhost:9076/app/engineData',
  createSocket: (url) => new WebSocket(url),
});

// Uncomment to see the websocket traffic:
// session.on('traffic:*', (direction, data) => console.log(`Traffic (${direction}):`, data));

session.open()
  .then((global) => global.createSessionApp())
  .then((doc) => doc.createObject({ qInfo: { qType: 'custom-type' } }))
  .then((object) => {
    object.getLayout();
    object.getLayout();
    return object.getLayout()
github qlik-oss / enigma.js / examples / basics / documents / qrs.js View on Github external
const openFirstApp = (apps) => {
  if (!apps.length) {
    console.log('No apps available, make sure your userDirectory and userId configuration is correct both in the script and in QMC attribute mapping.');
    // eslint-disable-next-line no-restricted-globals
    return Promise.reject(new Error('No available apps'));
  }
  console.log('Available apps for this user:', apps.map((app) => `${app.id} (${app.name})`).join(', '));
  const firstAppId = apps[0].id;
  return enigma.create({
    schema,
    // We use the configured proxyPrefix here to make sure Sense uses the correct
    // authentication:
    url: `wss://${senseHost}/${proxyPrefix}/app/${firstAppId}`,
    // Please notice the requestOptions parameter when creating the websocket:
    createSocket: (url) => new WebSocket(url, requestOptions),
  }).open().then((global) => global.openDoc(firstAppId)).then((app) => {
    console.log(`Opened app ${app.id}`);
    app.session.close();
  });
};
github qlik-demo-team / qdt-components / src / qDoc.js View on Github external
const qDoc = async (config) => {
  const myConfig = config;
  // Make it work for Qlik Core scaling https://github.com/qlik-oss/core-scaling
  // qlikcore/engine:12.248.0
  if (myConfig.core) {
    myConfig.subpath = (myConfig.prefix) ? `${myConfig.prefix}/app` : 'app';
    myConfig.route = `doc/${myConfig.appId}`;
  }
  const url = SenseUtilities.buildUrl(myConfig);
  const session = enigma.create({ schema, url, responseInterceptors });
  const global = await session.open();
  if (myConfig.core) {
    return global.getActiveDoc();
  }

  return global.openDoc(myConfig.appId);
};
github qlik-oss / enigma.js / examples / authentication / sense-using-certificates / certificates.js View on Github external
const appId = 'engineData';

// The Sense Enterprise-configured user directory for the user you want to identify
// as:
const userDirectory = 'your-sense-user-directory';

// The user to use when creating the session:
const userId = 'your-sense-user';

// Path to a local folder containing the Sense Enterprise exported certificates:
const certificatesPath = './';

// Helper function to read the contents of the certificate files:
const readCert = (filename) => fs.readFileSync(path.resolve(__dirname, certificatesPath, filename));

const session = enigma.create({
  schema,
  url: `wss://${engineHost}:${enginePort}/app/${appId}`,
  // Notice the non-standard second parameter here, this is how you pass in
  // additional configuration to the 'ws' npm library, if you use a different
  // library you may configure this differently:
  createSocket: (url) => new WebSocket(url, {
    ca: [readCert('root.pem')],
    key: readCert('client_key.pem'),
    cert: readCert('client.pem'),
    headers: {
      'X-Qlik-User': `UserDirectory=${encodeURIComponent(userDirectory)}; UserId=${encodeURIComponent(userId)}`,
    },
  }),
});

session.open().then((global) => {
github qlik-oss / enigma.js / examples / mixins / simple / simple.js View on Github external
/**
    * Overriding the createObject function.
    * @param {Function} base This is the original function that is being overridden.
    * @param {*} params The parameter list. When parameters are passed by name, enigma.js
    *                     will add default values for parameters not supplied by the caller.
    * @returns {Promise} A promise that when resolved contains the newly created
    *                    object, or rejected if object couldn't be created.
    */
    createObject(base, ...params) {
      console.log('Creating object with params:', params);
      return base(...params);
    },
  },
};

const session = enigma.create({
  schema,
  mixins: [docMixin],
  url: 'ws://localhost:9076/app/engineData',
  createSocket: (url) => new WebSocket(url),
});

session.open()
  .then((global) => global.createSessionApp())
  .then((doc) => doc.tweet().then(() => doc.createObject({ qInfo: { qType: 'custom-type' } })))
  .then((object) => console.log(`Created object with type ${object.genericType} and id ${object.id}`))
  .catch((error) => {
    console.log('Something went wrong:', error);
    process.exit(1);
  })
  .then(() => session.close());
github qlik-oss / enigma.js / examples / list-apps / index.js View on Github external
const readCert = filename => fs.readFileSync(path.resolve(certificateDir, filename));

const config = {
  schema,
  url: 'wss://localhost:4747/app/engineData',
  createSocket: url => new WebSocket(url, {
    ca: [readCert('root.pem')],
    key: readCert('client_key.pem'),
    cert: readCert('client.pem'),
    headers: {
      'X-Qlik-User': `UserDirectory=${process.env.USERDOMAIN};UserId=${process.env.USERNAME}`,
    },
  }),
};

const session = enigma.create(config);
session.on('traffic:*', (dir, data) => console.log(dir, data));

console.log('Connecting to Engine');

session.open().then((global) => {
  console.log('Connected');
  return global.getDocList().then((docList) => {
    const docs = docList.map(doc => `${doc.qDocName} - ${doc.qDocId}`).join('\n');
    console.log('--- Your server has the following apps ---');
    console.log(docs);
  });
}).catch((err) => {
  console.log(`Error when connecting to Engine: ${err}`);
  process.exit(1);
});
github qlik-oss / halyard.js / examples / local-data.js View on Github external
const enigma = require('enigma.js');

const enigmaMixin = require('../dist/halyard-enigma-mixin.js');
enigmaConfig.mixins = enigmaMixin;

const Halyard = require('../dist/halyard.js');

const filePath = path.join(__dirname, './data/airports.csv');

const halyard = new Halyard();

const table = new Halyard.Table(filePath, { name: 'Airports', fields: [{ src: 'rowID', name: 'Id' }, { src: 'Country', name: 'Country' }], delimiter: ',' });

halyard.addTable(table);

enigma.create(enigmaConfig).open().then((qix) => {
  const appName = `Local-Data-${Date.now()}`;

  qix.createAppUsingHalyard(appName, halyard).then((result) => {
    console.log(`App created and reloaded - ${appName}.qvf`);
    process.exit(1);
  });
});

enigma

Implementation of an enigma machine

MIT
Latest version published 10 years ago

Package Health Score

45 / 100
Full package analysis

Popular enigma functions