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

@surix/client

v0.9.1

Published

Surix API Client

Downloads

2

Readme

Surix Core Client

Usage

const { Client } = require('@surix/client');

// OR

import { Client } from '@surix/client';

Or on the browser:

<script src="https://cdn.jsdelivr.net/npm/@surix/client@[version]/dist/client.min.js"></script>
<!-- Replace version with an actual version number -->

Create Client instance:

const client = new Client({ 
  keyId: 'key id provided by surix',
  keySecret: 'key secret provided by surix'
  });

Or on the browser:

const client = new Surix.Client({
  keyId: 'key id provided by surix',
  keySecret: 'key secret provided by surix'
});

Note: keyId and keySecret are provided in the surix dashboard, under account settings.

Select project to work with:

const project = client.project('projectId');

Entities

project.entities.create(entity: Entity)

Creates a given entity

const entity = {
  data: {
    name: 'My Awesome Name'
  },
  tags: []
}

const savedEntity = await project.entities.create(entity)

console.log(savedEntity.get('name'))

Note: Before the entity is created, it is expanded (using expandEntity function in @surix/data-helpers) to a raw entity that includes the types information using the type of the values provided in the data field. The entity above would be converted to:

{
  data: {
    name: {
      type: 'text',
      value: 'My Awesome Name'
    }
  },
  tags: []
}

Dates are expanded as text for now and will correctly be expanded to datetime in future versions of @surix/data-helpers. Arrays are not supported for now.

project.entities.update(entity: Entity)

Updates an entity partially. I.e adds onto the already existing entity identified by the _id field.

const entity = {
  _id: 'someid',
  data: {
    phone: '0712345678'
  },
  tags: ['tag']
}

const updatedEntity = await project.entities.update(entity);

Dates created with the Date() function are expanded as text. and those created with new Date() are correctly expanded to datetime.

project.entities.put(entity: Entity)

Updates an entity by completely replacing its data.

const entity = {
  _id: 'someid', // The id of the entity to be updated
  data: {
    name: 'My name'
  }
}

const changedEntity = await project.entities.put(entity);

project.entities.get(id: string)

Fetches an entity by ID.

const entity = await project.entities.get('entityId');
console.log(entity.tags);
console.log(entity.get('address.city'));

project.entities.query(query?: object)

Query entities in the project.

const entities = await project.entities.query({
  limit: 10,
  tags: ['posts'],
  query: {
    read: false
  }
});

entities.forEach((entity) => {
  console.log(entity.get('contents'));
});

The query object is optional:

const entities = await project.entities.query();

entities.forEach((entity) => {
  console.log(entity.get('contents'));
});

project.entities.delete(id: string)

Deletes an entity entirely.

const entityId = 'someid';
const deletedEntity = await project.entities.delete(entityId);

console.log(deletedEntity.get('name') + ' was deleted');

project.entities.deleteMany(ids: EntityIds)

Deletes a bunch of entities identified by the provided ids.

const entitiesIds = ['someid1', 'someid2'];

const response = await project.entities.deleteMany(entitiesIds);
console.log(response.deleted); // Number of deleted entities

project.entities.addTags(entityId: string, tags: string | string[])

Adds tags to an entity identified by the entityId provided

const entityId = 'someid';
const entity = await project.entities.addTags(entityId, 'new-tag'); // A single tag

const entity = await project.entities.addTags(entityId, ['new-tag', 'another-tag']); // Multiple tags

// Returns the updated entity

project.entities.removeTags(entityId: string, tags: string | string[])

Removes tags from the entity identified by the entityId provided

const entityId = 'someid';
const entity = await project.entities.removeTags(entityId, 'new-tag'); // A single tag

const entity = await project.entities.removeTags(entityId, ['new-tag', 'another-tag']); // Multiple tags

// Returns the updated entity

Files

project.files.get(id: string)

Fetches a file by ID.

const file = await project.files.get('fileId');
console.log(file.downloadUrl);

project.files.list()

Fetches all files in the project.

const files = await project.files.list();
files.forEach((file) => console.log(file.downloadUrl));

Tags

project.tags.list()

Fetches all tags in project.

const tags = await project.tags.list();
tags.forEach((tag) => console.log(tag.name));

project.tags.rename(oldName: string, newName: string)

Renames a tag from oldName to newName

const tag = await project.tags.rename('oldName', 'newName');
console.log(tag.name) // Should be newName