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

zn-resource

v0.6.1

Published

Helper for using zengine resources on backend plugins (unofficial)

Downloads

9

Readme

zn-resource

Handle Zengine API resources in Zengine backend services (unofficial and experimental).

Install

$ npm install zn-resource

Use

// Require the built-in ZnHttp (notice the path depends on where you are)
var ZnHttp = require('../../lib/zn-http.js');

// Inject ZnHttp into zn-resource and ask for the resource service you want
var znRecordService = require('zn-resource')({ resource: 'record', ZnHttp: ZnHttp });
var znFormService = require('zn-resource')({ resource: 'form', ZnHttp: ZnHttp });
var znActivityService = require('zn-resource')({ resource: 'activity', ZnHttp: ZnHttp });
var znMemberService = require('zn-resource')({ resource: 'member', ZnHttp: ZnHttp });

For each of those services, you should be able to perform regular operations plus extra things, depending on the service. The interfaces are similar:

  • get one resource with get passing an id
  • query resources with query passing a request object – the service will be smart enough to figure out what goes on the endpoint and what goes as query params
  • save a resource with save passing resource data – if data has no id, it will create a new resource, otherwise it will update the existing resource

Records

Get record:


  var compositeId = {
    id: 40
    formId: 5
  };

  // GET /forms/5/records/40
  znRecordService.get(compositeId).then(function(record) {
    // record.id === 40
    // record.formId === 5 (set by the service for convenience)
  });

Query records (paginated):


  var request = {
    formId: 5
    field123: 'apples'
  };

  // GET /forms/5/records?field123=apples
  znRecordService.query(request).then(function(response) {
    // response.totalCount
    // response.data
  });

Create record:


  var recordData = {
    formId: 5,
    field123: 'apples'
  };

  // POST /forms/5/records
  znRecordService.save(recordData).then(function(record) {

  });

Update record:


  var recordData = {
    id: 40,
    formId: 5,
    field123: 'apples'
  };

  // PUT /forms/5/records/40
  znRecordService.save(recordData).then(function(record) {

  });

Find by field value:


  var request = {
    formId: 5,
    fieldId: 123,
    value: 'apples'
  };

  // GET /forms/5/records?field123=apples&limit=1
  znRecordService.findByFieldValue(request).then(function(record) {
    // record or null
  });

Forms

Similar to record service but you get an instance of ZnForm instead, which means you not only get form data but you can also call methods.


  // GET /forms/5
  znFormService.get(5).then(function(form) {
    // form instanceof ZnForm === true
    // form.id === 5
    // form.getEmailValidatedFields()
  });

Query forms


  var request = {
    workspace: {
      id: 18
    }
  };
  
  // GET /forms?workspace.id=18&attributes=id,name&related=fields,folders
  znFormService.query(request).then(function(response) {
    // response.data is array of ZnForms
  });

Workspace Membership

Pseudo-resource concerning the current user and a workspace.


  var workspaceId = 18;
  znMemberService.get(workspaceId).then(function(membership) {
    // membership.userId (via /users/me)
    // membership.isOwner (boolean)
    // membership.isAdmin (true, if owner or admin)
    // membership.isMember (true, if member of any kind)
  });

Testing

To test your backend service without doing actual requests to Zengine, you can use zn-resource-fake.