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

ninoxjs

v1.4.5

Published

a simple and fast wrapper for the Ninox API, allows executing and querying with NXScript and the REST API

Downloads

14

Readme

‘npm version’ ‘downloads over month’

ninoxjs

🤔 What is this?

This is a lightweight JS library for the Ninox REST API. This allows you to easily use the REST API in your JavaScript app without needing to look up your library ids and team ids or handle data encoding.

💡 What can I use it for?

I personally used this library to write endpoints for the following services:

  • server for app payment and license management
  • data analysis tools to analyse trends in data
  • employee dashboards
  • ticket systems
  • and more

I'm excited to see what you are going to create with these tools. If you have any questions, please contact me at ✉️ [email protected]


Can I help? Submit your pull request with a detailed explaination or create a discussion beforehand.


🚀 Install

npm install ninoxjs --save
const ninox = require('ninoxjs');
//or
import ninox from 'ninoxjs';

🧑‍🏫 Usage

ninox.auth(options : NinoxOptions) must be called once before using the API.

import ninox from 'ninoxjs';

ninox.auth({
    uri: "https://api.ninoxdb.de", //optional
    version: "1", //optional
    authKey: "xxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxxxxx",
    team: "YOUR_TEAM_NAME",
    database: "YOUR_DATABASE_NAME",
}).then(() => {
	console.log("Auth successful");

	ninox.getRecords('YOUR_TABLE_NAME').then(records => {
		console.log(records);
	})
}).catch(err => {
    console.log("Failed to connect to Ninox Cloud", err);
});

Types

NinoxRecord

/**
 * @typedef {Object} NinoxRecord
 * @property {number} id - The id of the record
 * @property {number} sequence - The sequence of the record
 * @property {string} createdAt - The date the record was created
 * @property {string} createdBy - The user that created the record
 * @property {string} modifiedAt - The date the record was updated
 * @property {string} modifiedBy - The user that updated the record
 * @property {Object} fields - The content of the record
 **/

Example:

 {
   id: 6,
   sequence: 97,
   createdAt: '2022-06-28T19:35:01',
   createdBy: 'xxx',
   modifiedAt: '2022-07-02T12:34:39',
   modifiedBy: 'xxx',
   fields: {
       "Name": "My Deliverable",
       "Description": "This is a deliverable",
   },
  }

NinoxOptions

/**
* @typedef {Object} NinoxOptions
* @property {string} teamName - The name of the team to use
* @property {string} databaseName - The name of the database to use
* @property {string} authKey - The auth key for the API, can be found or created in the user account settings page of the ninox app
*/

Example:

{
    uri: "https://api.ninoxdb.de", //optional
    version: "1", //optional
    authKey: "xxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxxxxx",
    team: "YOUR_TEAM_NAME",
    database: "YOUR_DATABASE_NAME",
}

🔦 Available methods

getRecords(tableName : String, filters : Object, extractFields? : String[], excludeFields? : String[]) : Promise<NinoxRecord[]>

Retrieves all NinoxRecords from the Table that match the filters.

Filters are always exact matches, use ninox.query to search with greater than, less than and other parameters.

Usage:

ninox.getRecords(
	'YOUR_TABLE_NAME', // Table name
    {
        "First Name": 'John', 
        Age : 21,
        "Last Name": 'Doe'
    },
    ['name', 'age'] // Fields to extract, leave undefined to extract all fields
);

// or
ninox.getRecords(
	'YOUR_TABLE_NAME', // Table name
	{
		"First Name": 'John',
		Age : 21,
		"Last Name": 'Doe'
	},
    [], //extract all fields
	['Phone'] // but exclude the field Phone
);


// returns all NinoxRecords
await ninox.getRecords('YOUR_TABLE_NAME').then(records => {
    console.log(records);
})

getRecord(tableName : String, id : Number, extractFields? : String[], excludeFields? : String[]) : Promise<NinoxRecord>

Returns a NinoxRecord from a table by id

Usage:


//returns a NinoxRecord with id 123 and trims the data to just the Age field
ninox.getRecord("YOUR_TABLE_NAME", 123, ['Age']).then(function(record) {
        console.log(record);
    }
)

//returns a NinoxRecord with id 123 and all fields
ninox.getRecord("YOUR_TABLE_NAME", 123).then(function(record) {
        console.log(record);
    }
)

saveRecords(tableName : String, records : NinoxRecord[]) : Promise<Boolean>

Saves NinoxRecords to a table in the database, omitting the id will create a new NinoxRecord, with the id will update the NinoxRecord

Usage:


//updates a NinoxRecord with id 1 with the data in the fields object
ninox.saveRecords("YOUR_TABLE_NAME", [{
	id: "1",
	fields: {
		field1: "value1",
		field2: "value2"
	},
}]);

//creates a NinoxRecord with the data in the fields object
ninox.saveRecords("YOUR_TABLE_NAME", [{
	fields: {
		field3: "value3",
		field4: "value4"
	},
}]);

deleteRecord(tableName : String, id : Number) : Promise<Boolean>

Deletes NinoxRecords from a table in the database.

Usage:

ninox.deleteRecord("YOUR_TABLE_NAME", 123).then(function(record) {
        console.log(record);
    }
)

deleteRecords(tableName : String, ids : Number[]) : Promise<Boolean>

Deletes all NinoxRecords from a table in the database.

Usage:

ninox.deleteRecords("YOUR_TABLE_NAME", [123, 124, 125]).then(function(record) {
        console.log(record);
    }
)

query(tableName : String, query : String) : Promise<Number|String|Array>

Allows you to query the database directly with a NX-Script.

Note: This acts the same as a Formula, you can not write data.

Usage:

let name = "John"
let age = 21;
n.query(
`let list := (select YOUR_TABLE_NAME['First Name'="${name}" and Age >= ${age}]);
 for l in list do
 {
    "age": l.Age,
    "name": l.'First Name'
 }
 end;
`).then(function(result) {
    console.log(result) // > [{age: 21, name: "John"}]
}).catch(function(err) {
	console.log(err);
});

exec(query : String) : Promise<Number|String|Array>

Allows you to execute NX-Script directly on the database.

Usage:

let name = "John"
let age = 21;
n.query(
`let t := first(select YOUR_TABLE_NAME['First Name'="${name}" and Age >= ${age}]);
t.Title := "New Title";
t.Title;
`).then(function(result) {
	console.log(result); // > New Title
}).catch(function(err) {
	console.log(err);
});

Note: This acts the same as a Button. Careful with this one, you can write data.

getFile() : Promise<String>

Returns the contents of a file from the database.

Usage:

const RECORD_ID = 123;
const FILE_NAME = "image.png";
ninox.getFile("YOUR_TABLE_NAME", RECORD_ID, FILE_NAME).then(function(file) {
    if (file){
        console.log("success");
    }
}).catch(function(err) {
    console.log(err);
});