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

@planningcenter/api-client

v2.4.1

Published

A Planning Center JavaScript API client that will make you smile

Downloads

9,624

Readme

Planning Center API Client

Description

A javascript library that provides a client for interacting with Planning Center's Graph API as well as helper methods for transforming request and response data.

View the classic README here.

Installation

yarn add @planningcenter/api-client

API Client

General Usage

import { Client } from "@planningcenter/api-client"
const client = new Client({ app: "services", version: "2018-11-01" })

client.get({
  url: '/plans',
  data: {
    fields: {
      Plan: ['dates', 'series', 'title'],
    },
  }
})

Client request methods will return a promise. When the promise is resolved, you'll be left with a transformed response (see below).

Get

When making a request, the client will enforce the use of sparse fieldsets which requires the fields key.

client.get({
  url: '/plans',
  data: {
    where: { title: 'Plan Title' },
    include: ['series'],
    order: 'created_at',
    fields: {
      Plan: ['dates', 'series', 'title'],
      Series: ['title', 'artwork_for_dashboard']
    },
  }
})

🚨 NOTE: When including records you also need to define the relation in fields. See the usage of 'series' above.

Pagination

The default value of perPage is 100. You can adjust this value in the data attribute:

client.get({
  url: '/plans',
  data: {
    perPage: 25,
    fields: {
      Plan: ['title'],
    },
  }
})

If you need to return all results from a collection, instead of only the first page of results, you can include the walk: true attribute inside the data attribute:

client.get({
  url: '/plans',
  data: {
    walk: true,
    fields: {
      Plan: ['title'],
    },
  }
})

This can be used in combination with perPage to make many smaller requests for a large collection of data.

Patch

client.patch({
  url: `/series/${seriesId}`,
  data: {
    fields: { Series: 'title,artwork_for_dashboard' },
    data: { type: 'Series', attributes: { name: 'New Series Name' }
  }
})

Post

client.post({
  url: '/series',
  data: {
    fields: { Series: 'title,artwork_for_dashboard' },
    data: {
      type: 'Series',
      attributes: { name: 'New Series Name' },
      relationships: {
        plan: {
          data: { type: 'Plan', id }
        }
      }
    }
  }
})

Delete

client.delete({ url: `/series/${seriesId}` })

Helper Functions

The Client class will automatically transform request and response data, but helpers for transforming data are also available to be used manually.

transformRequestData

Takes an object with camelCase request parameters and transforms to a more api friendly format.

Input

import { transformRequestData } from "@planningcenter/api-client"

transformRequestData({
  fields: { Song: ["title", "arrangements"], Arrangement: ["name"] },
  include: "arrangements",
  where: { title: "I Like Bugs" },
})

Output

{
  "fields[Song]": "title,arrangements",
  "fields[Arrangement]": "name",
  include: "arrangements",
  per_page: 100,
  "where[title]": "I Like Bugs",
}

transformResponse

Takes an JSON API spec-adhering response and transforms it to a more appropriate format for JavaScript.

Input

import { transformResponse } from "@planningcenter/api-client"

transformResponse({
  "data": {
    "type": "Person",
    "id": "123",
    "attributes": {
      "first_name": "Marvin",
      "last_name": "Gaye"
    },
    "relationships": {
      "top_song": {
        "data": {
          "type": "Song",
          "id": "456"
        }
      },
      "instruments": {
        "data": [{
          "type": "Instrument",
          "id": "789"
        }]
      }
    },
    "links": { ... }
  },
  "included": [
    {
      "type": "Instrument",
      "id": "789",
      "attributes": {
        "name": "Piano"
      }
    }
  ],
  "meta": {
    "parent": {
      "id": "1",
      "type": "Organization"
    }
  }
})

Output

{
  data: {
    // string IDs are parsed into integers
    id: 123,
    type: "Person",

    // all keys are camel-cased
    firstName: "Marvin",
    lastName: "Gaye",

    // belongs to relationships are given a singular foreign key property
    topSongId: 456,
    topSongType: "Song",

    // relationships not also `included` are given a property with a null value
    topSong: null,

    // has many relationships are given a plural foreign key property
    instrumentIds: [789],

    // included records are gathered via relationships & placed in a collection:
    instruments: [
      { id: 789, type: "Instrument", name: "Piano" },
    ],

    links: {}
  },
  // response meta is available in case you need it
  meta: { parent: { id: "1", type: "Organization" } }
}

Contributing

Pull requests are welcome and encouraged! See the contributing guidelines for more information.