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

reified-client-api

v0.5.6

Published

A Typescript ZAFClient wrapper for Zendesk app development.

Downloads

671

Readme

Reified Client API

re·i·fy

/ˈrēəˌfī/ verb formal make (something abstract) more concrete or real "these instincts are, in humans, reified as verbal constructs"

A typescript API to help Zendesk app developers with creating type-safe projects.

Features

No more typos - the full ZAFClient API is available via type-safe paths to the objects, events, or actions you wish to access.

No more passing in the string you just gave the ZAFClient to get the actual object.

// Old syntax
const ticketObject = (await client.get("ticket"))["ticket"]

// New syntax
const ticketObject = await client.get(Support.TicketSidebar.Objects.ticket)

The API is broken up first by Zendesk API, then by app location, then by path type (Event, Object, Action).

Getting an object

const ticket = await client.get(Support.TicketSidebar.Objects.ticket) // Returns object of type Ticket
console.log(ticket.assignee)
/*
{
    user: { /* user object */ },
    group: { /* group object */ }
}
*/

Handling an event

client.on(Core.Events.app.registered, (appData: any) => {
    // do stuff
})

Invoking an action

client.invoke(Support.TicketSidebar.Actions.ticketFields(2).enable)

Getting custom fields

The custom_field path is only available for a few zendesk objects, such as ticket or user.

  • Ensure non-null assertions are enabled by your linter or IDE
  • Place the assertion after custom_field before the invokation
  • The custom_field callable object will return a type of unknown by default. You must specify the type via a type parameter or by casting.
const customUserField = await client.get(Support.UserSidebar.Objects.user.custom_field!<string>("CustomFieldID"))
// or
const customUserField = await client.get(Support.UserSidebar.Objects.user.custom_field!("CustomFieldID")) as string

Indexable objects and properties

You can get individual elements of indexable objects and properties via their callable object paths and passing in either an integer or string. Refer to the ZAFClient api for which to use. Most indexables can take either an integer index or a string ID.

const firstGroupNameOfSecondCommentAuthor = await client.get(Support.TicketSidebar.Objects.ticket.comments(2).author.groups(1).name)

Getting multiple objects at once

The API also supports the "bulk" get function, though you will need to index into the returned object to get the actual object.

Conveniently, you can use the _path property to get the underlying string value which is passed to the client. Putting it all together would look like this.

const objsToGet = [
    Support.TicketSidebar.Objects.ticket.comment,
    Support.Common.Objects.currentUser
]

const returnedObj = await client.get(objsToGet) // type: { [key: string]: any }

// Comment and User interfaces are available for import, along with many others
const commentObj = returnedObj[objsToGet[0]._path] as Comment
const userObj = returnedObj[objsToGet[1]._path] as User 

Usage

If you don't have a typescript project set up, see this scaffold for a Zendesk app written in Typescript

  1. In your existing typescript project, run
npm i reified-client-api
  1. You should now declare ZAFClient as a known const in your app's entrypoint.
declare const ZAFClient: any;
  1. Finally, initialize the ReifiedClient by passing in the client instance
const client = new ReifiedClient(ZAFClient.init())

Development

Since types are only implemented for the Support and Core APIs, there is still work to be done to implement the other APIs.

  • [x] Apps Core API
    • [x] ZAF Client API
    • [x] Core Apps API
  • [x] Apps Support API
    • [x] All Locations
    • [x] Ticket and New Ticket Sidebar
    • [x] Organization Sidebar
    • [x] User Sidebar
    • [x] Top Bar
    • [x] Navbar
    • [x] Modal
    • [x] Ticket Editor
    • [x] Background
  • [ ] Apps Chat API
    • [ ] All Locations
    • [ ] Chat Sidebar
    • [ ] Background
  • [ ] Apps Sell API
    • [ ] All Locations
    • [ ] Background
    • [ ] Company Sidebar
    • [ ] Deal Sidebar
    • [ ] Lead Sidebar
    • [ ] Person Sidebar
    • [ ] Top Bar
    • [ ] Call Log Editor
    • [ ] Modal
    • [ ] Note Editor
    • [ ] Visit Composer

Types representing actual Zendesk objects or functions which are returned from or passed to API calls are kept in lib/zendesk_types. The actual API, along with the helper types and functions that make it work, are simply in lib/ and currently contains the Core and Support APIs.

Contribution

Contributions of any kind (additional API support, polish to existing APIs, test files) are welcome.

Disclaimer

This is not an official Inductive Automation product and is not affiliated with, supported by, maintained by, or otherwise associated with Inductive Automation in any way. This software is provided as-is with no warranty.