How to use kuzzle-sdk - 10 common examples

To help you get started, we’ve selected a few kuzzle-sdk 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 kuzzleio / sdk-javascript / doc / 6 / getting-started / webpack / snippets / init-kuzzle.js View on Github external
// load the Kuzzle SDK module
/* snippet:start:1 */
import { Kuzzle, WebSocket } from 'kuzzle-sdk';
/* snippet:end */

// instantiate a Kuzzle client
/* snippet:start:2 */
const kuzzle = new Kuzzle(new WebSocket('kuzzle'));
/* snippet:end */

// add a listener to detect any connection problems
/* snippet:start:3 */
kuzzle.on('networkError', error => {
  console.error(`Network Error: ${error}`);
});
/* snippet:end */

/* snippet:start:4 */
const run = async () => {
  try {
    // Connect to Kuzzle server
    await kuzzle.connect();

    // Create an index
github kuzzleio / sdk-javascript / doc / 6 / protocols / http / constructor / snippets / constructor.js View on Github external
'nyc-open-data-plugin/driver': {
    enroll: { verb: 'POST', url: '/_plugin/nyc-open-data-plugin/drivers' },
    remove: { verb: 'DELETE', url: '/_plugin/nyc-open-data-plugin/drivers/:driverId' }
  }
};

const options = {
  customRoutes,
  sslConnection: false
};

// Instantiates the Http protocol
const httpProtocol = new Http('kuzzle', options);

// Use it with Kuzzle
const kuzzle = new Kuzzle(httpProtocol);
github kuzzleio / sdk-javascript / doc / 6 / protocols / http / constructor / snippets / constructor.js View on Github external
} = require('kuzzle-sdk');

const customRoutes = {
  'nyc-open-data-plugin/driver': {
    enroll: { verb: 'POST', url: '/_plugin/nyc-open-data-plugin/drivers' },
    remove: { verb: 'DELETE', url: '/_plugin/nyc-open-data-plugin/drivers/:driverId' }
  }
};

const options = {
  customRoutes,
  sslConnection: false
};

// Instantiates the Http protocol
const httpProtocol = new Http('kuzzle', options);

// Use it with Kuzzle
const kuzzle = new Kuzzle(httpProtocol);
github kuzzleio / kuzzle / features-sdk / support / hooks.js View on Github external
BeforeAll(({ timeout: 10 * 1000 }), async function () {
  const world = new World({});

  console.log(`Start tests with ${world.protocol.toLocaleUpperCase()} protocol.`);

  world.sdk = new Kuzzle(getProtocol(world));

  await world.sdk.connect();

  console.log('Loading default securities..');

  await world.sdk.query({
    controller: 'admin',
    action: 'loadSecurities',
    body: testSecurities,
    refresh: 'wait_for'
  });

  world.sdk.disconnect();
});
github kuzzleio / kuzzle / lib / core / plugins / context.js View on Github external
Reflect.defineProperty(this.accessors, 'strategies', {
        enumerable: true,
        get: () => {
          return {
            add: curryAddStrategy(kuzzle, pluginName),
            remove: curryRemoveStrategy(kuzzle, pluginName)
          };
        }
      });

      Reflect.defineProperty(this.accessors, 'trigger', {
        enumerable: true,
        get: () => curryTrigger(kuzzle, pluginName)
      });

      const kuzzleSdk = new KuzzleSDK(new FunnelProtocol(kuzzle.funnel));

      const throwNotAvailable = name => () => {
        contextError.throw('unavailable_realtime', name);
      };

      const getPluginSdk = sdk => ({
        query: sdk.query.bind(sdk),
        auth: sdk.auth,
        bulk: sdk.bulk,
        collection: sdk.collection,
        document: sdk.document,
        index: sdk.index,
        ms: sdk.ms,
        realtime: Object.assign(sdk.realtime, {
          subscribe: throwNotAvailable('realtime:subscribe'),
          unsubscribe: throwNotAvailable('realtime:unsubscribe')
github kuzzleio / kuzzle / bin / commands / sendAction.js View on Github external
const config = {
    host: options.host || 'localhost',
    port: options.port || 7512
  };

  if (options.username && options.password) {
    config.login = {
      strategy: 'local',
      credentials: {
        username: options.username,
        password: options.password
      }
    };
  }

  const kuzzle = new Kuzzle(new WebSocket(config.host, { port: config.port }));

  return kuzzle.connect()
    .then(() => {
      if (config.login) {
        return kuzzle.auth.login(config.login.strategy, config.login.credentials);
      }
    })
    .then(() => kuzzle.query(query));
}
github kuzzleio / kuzzle / features-sdk / support / world.js View on Github external
_getSdk () {
    let protocol;

    switch (this.protocol) {
      case 'http':
        protocol = new Http(this.host, { port: this.port });
        break;
      case 'websocket':
        protocol = new WebSocket(this.host, { port: this.port });
        break;
      default:
        throw new Error(`Unknown protocol "${this.protocol}".`);
    }

    return new Kuzzle(protocol);
  }
}
github kuzzleio / kuzzle / lib / core / plugins / context.js View on Github external
pluginSdk.as = user => {
            if (!(user instanceof User)) {
              contextError.throw('invalid_user');
            }

            return getPluginSdk(
              new KuzzleSDK(new FunnelProtocol(kuzzle.funnel, user)));
          };
github kuzzleio / kuzzle / features-sdk / support / hooks.js View on Github external
Before(({ timeout: 10 * 1000 }), async function () {
  this.sdk = new Kuzzle(getProtocol(this));

  await this.sdk.connect();
  await this.sdk.auth.login(
    'local',
    { username: 'test-admin', password: 'password' });

  await this.sdk.query({
    controller: 'admin',
    action: 'resetDatabase',
    refresh: 'wait_for'
  });
});
github kuzzleio / kuzzle / features-sdk / support / world.js View on Github external
_getSdk () {
    let protocol;

    switch (this.protocol) {
      case 'http':
        protocol = new Http(this.host, { port: this.port });
        break;
      case 'websocket':
        protocol = new WebSocket(this.host, { port: this.port });
        break;
      default:
        throw new Error(`Unknown protocol "${this.protocol}".`);
    }

    return new Kuzzle(protocol);
  }
}

kuzzle-sdk

Official Javascript SDK for Kuzzle

Apache-2.0
Latest version published 2 months ago

Package Health Score

72 / 100
Full package analysis