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

@trycourier/client-graphql

v6.3.2

Published

Courier GraqphQl Client for usage in the browser.

Downloads

91,206

Readme

Courier Client GraphQl

Courier GraqphQl Client for usage in the browser.

Initialization

You can initialize each module with either an object containing:

{
  clientKey: string;
  userId: string;
  userSignature?: string,
}

Or alternately, you can use an issued authorization token.

{
  authorization: string;
}

You can also create the client separately and pass the client in:

import { createCourierClient } from "@trycourier/client-graphql";
const courierClient = createCourierClient({
  clientKey: "abc123",
  userId: "@me",
  userSignature: "SUPER_SECRET",
});
const messages = Messages({ client: courierClient })
const events = Events({ events: courierClient })
const events = Brands({ events: courierClient })

Messages

import { Inbox } from "@trycourier/client-graphql";

const inboxApi = Inbox({ authorization: "abc123" });

const getMessageCount = async (params?: {
  status?: "read" | "unread",
  from?: number,
  tags?: string[],
}) => {
  const messageCount = await inboxApi.getInboxMessages(params);
  return messageCount;
};
const getMessages = async (
  params?: {
    isRead?: boolean,
    from?: number,
    tags?: string[],
  },
  after?: string
) => {
  const { startCursor, messages } = await messagesApi.getMessages(params);
  return {
    startCursor,
    messages,
  };
};

Events

import { Events } from "@trycourier/client-graphql";
const eventsApi = Events({
  clientKey: "abc123",
  userId: "@me",
  userSignature: "SUPER_SECRET",
});
const trackEvent = async (trackingId: string) => {
  await eventsApi.trackEvent(trackingId);
};

Brands

import { Brands } from "@trycourier/client-graphql";
const brandsApi = Brands({
  clientKey: "abc123",
  userId: "@me",
  userSignature: "SUPER_SECRET",
});
const getBrand = async (brandId?: string) => {
  const myBrand = await brandsApi.getBrand(brandId);
  return myBrand;
};

Preferences

You can use our GraphQL endpoints to read and write advanced user preferences and see draft preferences. This API has getRecipientPreferences, getPreferencePage, getDraftPreferencePage, and updateRecipientPreferences methods. You can see the response payloads in action on User Preference Tester

import { Preferences } from "@trycourier/client-graphql";
const preferencesApi = Preferences({
  clientKey: "abc123",
  userId: "@me",
  userSignature: "SUPER_SECRET",
});
const getRecipientPreferences = async (tenantId?: string) => {
  const user_preferences = await preferencesApi.getRecipientPreferences(
    tenantId
  );
  return user_preferences;
};
const getPreferencePage = async (tenantId?: string) => {
  const page_with_defaults = await preferencesApi.getPreferencePage(tenantId);
  return page_with_defaults;
};
const getDraftPreferencePage = async (tenantId?: string) => {
  const draft_page_with_defaults = await preferencesApi.getDraftPreferencePage(
    tenantId
  );
  return draft_page_with_defaults;
};
const updateRecipientPreferences = async (
  payload: UpdateRecipientPreferencesPayload
) => {
  const update_preferences = await preferencesApi.updateRecipientPreferences(
    payload
  );
  return update_preferences;
};
interface UpdateRecipientPreferencesPayload {
  templateId: string;
  status: string;
  hasCustomRouting: boolean;
  routingPreferences: Array<string>;
  digestSchedule: string;
  tenantId?: string;
}

Banners

For one user

This will instantiate the client required to query the Courier GraphQL. getBanners will grab all banners for that user

import { Banner } from "@trycourier/client-graphql";
const bannerApi = Banner({
  clientKey: "abc123",
  userId: "@me",
  userSignature: "SUPER_SECRET", //optional
});
const getBanners = async (params?: IGetBannerParams) => {
  const myBanners = await bannerApi.getBanners(params);
  return myBanners;
};

Archive a banner

The following code will archive the selected banner for that user. After receiving and processing in Courier, getBanners will no longer return the banner. Archiving is an asynchronous process; there will be a slight delay before the banner is removed in the getBanners API call.

const config = {
  clientKey: "abc123",
  userId: "@me",
  userSignature: "SUPER_SECRET", //optional
}
const bannerApi = Banner(config);
const eventsApi = Events(config);

const getBanners = async (params?: IGetBannerParams) => {
  const myBanners = await bannerApi.getBanners(params);
  return myBanners;
};
const banners = await getBanner();
await eventsApi.trackEvent(
    banners.content.trackingIds.archiveTrackingId
);

Banner Params

interface IGetBannerParams {
  from?: number;
  limit?: number;
  locale?: string;
  tags?: string[];
  trackingIds?: boolean;
}

With JWT (Supports multiple users)

import { Banner } from "@trycourier/client-graphql";
const bannerApi = Banner({ authorization: "MY JWT TOKEN" });
const getBanners = async (params?: { tags?: string[], locale?: string }) => {
  const myBanners = await bannerApi.getBanners(params);
  return myBanners;
};