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

mints-js-sdk

v0.0.4

Published

Mints SDK for JavaScript

Downloads

18

Readme

Mints JS SDK

This SDK allows you to interact with CXF instances

Installing

You can install this SDK via npm:

npm install mints-js-sdk

Basic usage (Client-side)

To use the SDK on the client side, you can import the 'mints-js-sdk' module and grab the following objects:

import { mintsUser, mintsPublic, mintsContact } from 'mints-js-sdk';

You can then make use of the methods available on each of the objects. Example:

mintsPublic.getStoryVersions(null, false)
    .then(data => {
        console.log('mints_public', data)
    }
);

Important: In order to use the SDK methods, you must have initialized the server-side proxy.

Basic usage (Server-side)

Requirements

  • Node.js
  • Express.js
  • Babel

Installing Dependencies

npm install express
npm install @babel/core @babel/node @babel/preset-env

Initialization

Make sure you have the following environment variables on your server:

  • CXF_HOST
  • CXF_API_KEY

Middleware

You need to create middleware to be able to synchronize session cookies with the SDK. Here's how:

import { cookies } from 'mints-js-sdk';

const syncCookiesMiddleware = (req, res, next) => {
  const cookiesToSync = req.cookies;
  cookies.set(cookiesToSync);
  next();
};

export default syncCookiesMiddleware;

Now in your route file, you can import the middleware and use it on the routes you need:

import express from 'express';
import syncCookiesMiddleware from './middleware/syncCookiesMiddleware';

const router = express.Router();

router.get('/some-route', syncCookiesMiddleware, (req, res) => {
  // Logic here
});

export default router;

Or you can use it in your main file to run it on all paths:

import express from 'express';
import syncCookiesMiddleware from './middleware/syncCookiesMiddleware';

const app = express();

app.use(syncCookiesMiddleware);

// Routes here

app.listen(3000, () => {
  console.log('Server running on port 3000');
});

Uso

To make use of the server-side SDK, you can import the following objects:

  • mintsUser: To interact with user methods
  • mintsPublic: To interact with public methods
  • mintsContact: To interact with contact methods
  • cookies: To synchronize session cookies (only available on the server side)
  • userAuthHelper: To access authentication methods such as login and logout (only available on the server side)
  • contactAuthHelper: To access contact authentication methods (only available on the server side)

Example for logging in with a user and contact on the server:

import { userAuthHelper, contactAuthHelper, cookies } from 'mints-js-sdk';

// Here add your logic for keeping cookies synchronized across middleware

// Endpoint to log in the user
app.get('/set-user', (req, res) => {
    let response = userAuthHelper.mintsUserLogin('[email protected]', 'password', res);
    response.then(resp => res.json(resp)); // { response: true }
});

// Endpoint to log in the contact
app.get('/set-contact', (req, res) => {
    let response = contactAuthHelper.mintsContactLogin('[email protected]', 'password', res);
    response.then(resp => res.json(resp)); // { response: true }
});