qlik-oss / enigma.js

JavaScript library for consuming Qlik's Associative Engine.
MIT License
209 stars 82 forks source link

enigma.connect not a function #158

Closed QHose closed 7 years ago

QHose commented 7 years ago

when I try to follow the examples, please specify you have to ensure you are authenticated first, this is currently not in the prereqs. Also I noticed 2 kind of examples with connect and create... (v2)

const enigma = require('enigma.js');
const path = require('path');
const WebSocket = require('ws');
const bluebird = require('bluebird');
const QIXSchema = senseConfig.QIXSchema;

const config = {
            QIXSchema,
            url: 'ws://localhost:4747/app/' + appId,
            createSocket(url) {
                return new WebSocket(url, {
                    ca: engineConfig.ca,
                    key: engineConfig.key,
                    cert: engineConfig.cert,
                    headers: {
                        'X-Qlik-User': `UserDirectory=${process.env.USERDOMAIN};UserId=${process.env.USERNAME}`,
                    }
                });
            },
            Promise: bluebird,
            listeners: {
                'traffic:*': (dir, data) => console.log(dir, data),
            },
        };
        console.log('Connecting to Engine');
        enigma.connect(config).then((qix) => {
            console.log('Connected');

gives me [TypeError: enigma.connect is not a function]

using example https://github.com/qlik-oss/enigma.js/blob/master/examples/list-apps/index.js

See also my other issue, the docs have different config object refs to the QIXSchema definition. the code below also does not work.

const config = {
            schema: QIXSchema,
            session: {
                route: 'app/engineData',
                host: 'localhost',
                port: 4747,
            },
            createSocket(url) {
                return new WebSocket(url, {
                    ca: engineConfig.ca,
                    key: engineConfig.key,
                    cert: engineConfig.cert,
                    headers: {
                        'X-Qlik-User': `UserDirectory=${process.env.USERDOMAIN};UserId=${process.env.USERNAME}`,
                    }
                });
            },
            listeners: {
                'traffic:*': (dir, data) => console.log(dir, data),
            },
        };

        console.log('Connecting to Engine');
        return await enigma.connect(config).then((qix) => {
            console.log('Connected');
            return qix.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 qix service: ${err}`);
            process.exit(1);
        });
marcusoffesson commented 7 years ago

There is no enigma.connect() method. Instead, a session is created using enigma.create() followed by session.open().

Note that the examples are outdated and incomplete. For v2 we plan on writing these examples. In particular, the list-apps example will be replaced by #128. Stay tuned!