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

@deskpro/app-sdk

v4.1.2

Published

Deskpro Apps SDK

Downloads

13,291

Readme

Deskpro Apps SDK

Deskpro Apps SDK provides a client for communicating with the Deskpro system, React UI components as well as basic styles and utilities for use in simple apps and widgets.

Installation

Install the SDK via pnpm or npm:

pnpm add @deskpro/app-sdk

OR

npm install @deskpro/app-sdk

Basic Usage

When communicating with the Deskpro system, an app or widget must register "listeners" for key events:

  • onReady - when an app is loaded, but is not necessarily shown to the user
  • onShow - the app has been revealed to the user
  • onChange - the data (context) being passed to the app from Deskpro has changed

To register a listener you'll need to first import and create a Deskpro client, register the listener(s) and then lastly run the client:

import { createClient } from "@deskpro/app-sdk";

const client = createClient();

client.onReady((context) => {
  // do something when the app is ready
});

client.onShow((context) => {
  // do something when the app is shown to the user
});

client.onChange((context) => {
  // do something when the "context" data has changed
});

client.run();

As an aside, it's always best to "run" the client after the page is loaded, the easiest way to do this is to register the client.run() call as a window.onload method:

import { createClient } from "@deskpro/app-sdk";

const client = createClient();

window.onload = () => client.run();

// ...

To make fetch requests via the app proxy, and therefore gain access to app settings, we've provided a utility that wraps the native fetch function in the browser:

import { createClient, proxyFetch } from "@deskpro/app-sdk";

const client = createClient();

window.onload = () => client.run();

proxyFetch(client).then((dpFetch) => {
  // Use dpFetch() just like you would use fetch() natively.
  dpFetch("https://example.com/api/things?api_key=__key__").then((res) => {
    // ...
  });
});

Notice that the proxy will replace placeholders with the format __<setting>__. In this example, __key__ will be replaced with the app backend setting key. Proxy setting placeholders may be placed in the URL, headers or body of the request.

You can also control aspects of Deskpro itself, like the app title and icon badge count. To do this, use the client again to set these properties:

import { createClient } from "@deskpro/app-sdk";

const client = createClient();

window.onload = () => client.run();

client.setTitle("My New Title");
client.setBadgeCount(42);

UI Components

The Apps SDK exports several Deskpro UI components and is supported by a published Storybook story of each.

All app UI components reside in src/ui/components and usually consist of three files each:

  • Component file, e.g. Button.tsx that exports or compounds the component
  • Story file, e.g. Button.stories.tsx that contains the story for the component
  • Index file

To start developing UI components, run Storybook with:

pnpm start

When you're ready to build, run the standard build process for this library:

pnpm build

Note: UI components are not bundled, instead they're available in the ESM and CJS module builds.

Tests

To run the SDK test suite, execute the following:

pnpm test

OR

npm run test