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

springcm-node-sdk

v1.7.2

Published

SpringCM REST API SDK for Node.js

Downloads

12

Readme

SpringCM Node.js REST API SDK

NPM

Build Status Coverage Status dependencies Status devDependencies Status

This SDK currently provides a limited feature set, as it was created and is developed primarily for internal IT work at Stria.

Accessing the REST API requires you create an API user in your SpringCM account and assign a client ID to that user in the REST API section of Account Preferences. Once set, you can use the API by providing the client ID and corresponding secret. The client ID and client secret are provided by SpringCM's support staff on request. For more information, visit this webpage.

Examples

Below are a few usage examples. Be sure to check the tests folder for more examples.

SpringCM Client

Connect

Before you can interact with your SpringCM account, you need to connect via the SpringCM client.

const SpringCM = require('springcm-node-sdk');

// Create a new client
var springCm = new SpringCM({
  clientId: 'your_client_id',
  clientSecret: 'your_client_secret',
  dataCenter: 'uatna11' // na11, na21, etc.
});

springCm.connect((err) => {
  // You are now connected
});

Disconnect

Once you are done using the SpringCM client, you should close the connection, especially if your program is going to close immediately. Closing the connection ensures all queued requests and operations are completed.

Comments shown below are only applicable when execution reaches that line, i.e. comment #3 occurs after #2.

// 1) Queue up 10 requests then immediately call close()
springCm.close(() => {
  // 3) All requests are complete. You can exit the program safely.
});

// 2) Requests can no longer be submitted. Most operations will return an error.

Folders

Root folder

springCm.getRootFolder((err, root) => {
  // root represents the top level folder of your account
});

Subfolders

springCm.getRootFolder((err, root) => {
  springCm.getSubfolders(root, (err, folders) => {
    // folders is an array of all folders under the top level /
    // e.g. Trash and Other Sources
  });
});

Get folder by path

springCm.getFolder('/HR/Employee Files', (err, folder) => {
  // folder is an object referencing the /HR/Employee Files/ folder in SpringCM
});

Get folder by UID

If you'll know the UID of a folder beforehand, you can reference it by this UID.

springCm.getFolder('758afbfa-1f18-e812-9d16-3ca24a1e3f40', (err, folder) => {
  // folder is an object referencing the folder with the above UID
});

Subfolder pages

If you have a folder with a large number of subfolders, you may want to use paging. To do so, pass an options object as the second argument instead of the callback.

springCm.getSubfolders(parent, {
  offset: 0,
  limit: 20
}, (err, folders) => {
  // folders is an array of the first (no more than) 20 subfolders
});

Create a folder

You can create a new folder, or retrieve an existing folder by setting the exclusive option. By default, all folder creation is exclusive, meaning the operation will fail if the folder already exists. Note that this only applies to the base folder, i.e. creating /Contracts/ACME, Inc with exclusive set to true will succeed even if /Contracts already exists.

// Creates only if the folder doesn't exist by default
springCm.createFolder('/Contracts/PseudoTech, LLC', (err, folder) => {
  // ...
});

// Get the folder if it already exists
springCm.createFolder('/Contracts/ACME, Inc', { exclusive: false }, (err, folder) => {
  // ...
});

Upload document to a folder

springCm.getFolder('/Deliveries/Contracts', (err, folder) => {
  springCm.uploadDocument(folder, fs.createReadStream('ACME, Inc 2018.pdf'), (err, doc) => {
    // ...
  });
});

Documents

Get document by path

springCm.getDocument('/Contracts/ACME, Inc 01-01-2010.pdf', (err, doc) => {
  // doc is an object representing the contract document
});

Get document by UID

springCm.getDocument('127bd4e1-368e-1878-9651-ed101cabfdff', (err, doc) => {
  // doc is an object representing the referenced document
});

Download document

springCm.downloadDocument('127bd4e1-368e-1878-9651-ed101cabfdff', fs.createWriteStream('./Downloaded.pdf'), (err) => {
  // You can also download by path
});

// or

springCm.getDocument('/Contracts/ACME, Inc - Signed.pdf', (err, doc) => {
  springCm.downloadDocument(doc, fs.createWriteStream('./Signed.pdf'), (err) => {
    // ...
  });
});

Delete document

springCm.deleteDocument('/Contracts/ACME, Inc - Old.pdf', (err) => {
  // doc is now in the Trash folder
});

Move document

You can reference the source document and target folder by path, UID, or with an existing object of the corresponding type, e.g.

springCm.moveDocument('/Contracts/ACME, Inc.pdf', '/New Contracts/ACME, Inc/', (err) => {
  // ...
});

springCm.moveDocument('96803885-47f6-4361-9747-1d5962b3b7a4', '/Board Minutes', (err) => {
  // ...
});

springCm.getDocument('96803885-47f6-4361-9747-1d5962b3b7a4', (err, doc) => {
  springCm.moveDocument(doc, '/Trash', (err) => {
    // ...
  });
});

Query CSV data

springCm.csvLookup('/Admin/Customer Data.csv', {
  'Customer Name': 'ACME, Inc.'
}, (err, rows) => {
  // ...
});