npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

microgen-v3-sdk

v0.17.1

Published

Microgen SDK

Downloads

202

Readme

Microgen SDK

This is the Official Node JS and Browser client/library for Microgen API. Visit https://microgen.id. More information about the product and see documentation at http://docs.microgen.id for more technical details.

API Documentation

Please check Microgen API Reference.

Installation

Node.js

To install microgen in a node project:

npm install --save microgen-v3-sdk

Usage

Configure package with your account's API key obtained from your Microgen Dashboard.

const { MicrogenClient } = require('microgen-v3-sdk');

const microgen = new MicrogenClient({
  apiKey: '*******************',
});

Authentication

Use microgen auth services for manage your user.

Register

const { user, token, error } = await microgen.auth.register({
  firstName: 'Ega',
  lastName: 'Radiegtya',
  email: '[email protected]',
  password: 'password',
});

Login

const { user, token, error } = await microgen.auth.login({
  email: '[email protected]',
  password: 'password',
});

Login with Google

const { user, token, error } = await microgen.auth.loginWithGoogle({
  token: '*******************',
});

Login with Facebook

const { user, token, error } = await microgen.auth.loginWithFacebook({
  token: '*******************',
});

Login with Regol QR

const { content, error } = await microgen.auth.loginWithRegolQR({
  deviceId: 'B2C3-D4E5-F6G7-8901',
  deviceModel: 'SurfacePro8',
  deviceName: 'User Surface Pro 8',
  deviceOs: 'Windows',
  deviceVersion: '11.0.22000.100',
  platformName: 'desktop',
});

User

const { user, error } = await microgen.auth.user();
// Get user with filter:
// lookup
const { user, error } = await microgen
  .auth
  .user({ filterKey: filterValue, ... });

Update

const { user, error } = await microgen.auth.update({ firstName: 'Ega' });

Logout

const { user, token, error } = await microgen.auth.logout();

Database

Create

const { data, error } = await microgen.service('posts').create({
  name: 'Post 1',
  notes: 'Hello microgen',
});

Create Many

const { data, error } = await microgen.service('posts').createMany([
  {
    name: 'Post 1',
    notes: 'Hello microgen',
  },
  {
    name: 'Post 2',
    notes: 'Hello world',
  },
]);

Get

const { data, error } = await microgen
  .service('posts')
  .getById('605a251d7b8678bf6811k3b1');
// Get record with filters:
// select
// lookup
const { data, error } = await microgen
  .service('posts')
  .getById('605a251d7b8678bf6811k3b1', { filterKey: filterValue, ... });

Update

const { data, error } = await microgen
  .service('posts')
  .updateById('605a251d7b8678bf6811k3b1', {
    notes: 'Hello world',
  });

Update Many

const { data, error } = await microgen.service('posts').updateMany([
  {
    _id: '605a251d7b8678bf6811k3b1',
    notes: 'Hello world',
  },
  {
    _id: '605a251d7b8678bf6811k3b2',
    notes: 'Hello microgen',
  },
]);

Delete

const { data, error } = await microgen
  .service('posts')
  .deleteById('605a251d7b8678bf6811k3b1');

Delete Many

const { data, error } = await microgen
  .service('posts')
  .deleteMany(['605a251d7b8678bf6811k3b1', '605a251d7b8678bf6811k3b2']);

Link

const { data, error } = await microgen
  .service('posts')
  .link('605a251d7b8678bf6811k3b1', {
    categories: '61d26e8e2adb12b85c33029c',
  });

Unlink

const { data, error } = await microgen
  .service('posts')
  .unlink('605a251d7b8678bf6811k3b1', {
    categories: '61d26e8e2adb12b85c33029c',
  });

Find

const { data, error } = await microgen.service('posts').find();
// sort
// 1 = ascending
// -1 = descending
const { data, error } = await microgen
  .service('posts')
  .find({ sort: [{ name: 1 }] });
// skip
const { data, error } = await microgen.service('posts').find({ skip: 10 });
// limit
const { data, error } = await microgen.service('posts').find({ limit: 10 });
// select
const { data, error } = await microgen
  .service('posts')
  .find({ select: ['name'] });
// lookup into multiple link to record fields
const { data, error } = await microgen
  .service('posts')
  .find({ lookup: ['categories'] });
// lookup into all link to record fields
const { data, error } = await microgen.service('posts').find({ lookup: '*' });
// lookup into all link to record fields but only show the ids
const { data, error } = await microgen
  .service('posts')
  .find({ lookup: { _id: '*' } });
// lookup into all link to record fields and show all data
const { data, error } = await microgen
  .service('posts')
  .find({ lookup: { '*': '*' } });
// where
const { data, error } = await microgen
  .service('posts')
  .find({ where: { name: 'Ega' } });
// not equal
const { data, error } = await microgen
  .service('posts')
  .find({ where: { name: { $ne: 'Ega' } } });
// contains
const { data, error } = await microgen
  .service('posts')
  .find({ where: { name: { $contains: 'Ega' } } });
// not contains
const { data, error } = await microgen
  .service('posts')
  .find({ where: { name: { $notContains: 'Ega' } } });
// include
const { data, error } = await microgen
  .service('posts')
  .find({ where: { name: { $in: ['Ega'] } } });
// not include
const { data, error } = await microgen
  .service('posts')
  .find({ where: { name: { $nin: ['Ega'] } } });
// less then
const { data, error } = await microgen
  .service('posts')
  .find({ where: { total: { $lt: 10 } } });
// less then equal
const { data, error } = await microgen
  .service('posts')
  .find({ where: { total: { $lte: 10 } } });
// greater then
const { data, error } = await microgen
  .service('posts')
  .find({ where: { total: { $gt: 10 } } });
// greater then equal
const { data, error } = await microgen
  .service('posts')
  .find({ where: { total: { $gte: 10 } } });

Count

// count all records
const { data, error } = await microgen.service('posts').count();
// count with filters
const { data, error } = await microgen
  .service('posts')
  .count({ filterKey: filterValue, ... });

Storage

Upload

// from client
const file = event.target.files[0];
const { data, error } = await microgen.storage.upload(file);
// from server
const file = req.files[0];
const { data, error } = await microgen.storage.upload(
  file.buffer,
  file.originalname,
);

Realtime

Event

  • *
  • CREATE_RECORD
  • UPDATE_RECORD
  • DELETE_RECORD
  • LINK_RECORD
  • UNLINK_RECORD

Get tableId by Table Name

const { tableId, error } = await microgen.realtime.getTableId('posts');

Subscribe

microgen.realtime.subscribe(tableId, { event: '*' }, (message) => {
  if (message.error) {
    console.log(message.error);
    return;
  }

  console.log(message.event, message.payload);
});

Unsubscribe

microgen.realtime.unsubscribe(tableId);

Field

Find

const { data, error } = await microgen.service('posts').field.find();

Get

const { data, error } = await microgen
  .service('posts')
  .field.getById('605a251d7b8678bf6811k3b1');