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

@stackadapt/pa-typescript-sdk

v0.2.0

Published

StackAdapt's new Public API SDK allows you to use all of the functionality of the existing [GQL Public API](https://docs.stackadapt.com/) with built-in workflows, types and general endpoints that provide you similar flexibility. Additionally, all of Stack

Downloads

342

Readme

@stackadapt/pa-typescript-sdk

StackAdapt's new Public API SDK allows you to use all of the functionality of the existing GQL Public API with built-in workflows, types and general endpoints that provide you similar flexibility. Additionally, all of StackAdapt's GQL types and Schema are also available to be exported in this SDK, giving you access to all the data you need to build powerful integrations.

Table of Contents

Prerequisites

Ensure that you have the following versions installed.

  • Node: v18.12.1 and above
  • Npm: v8.19.2 and above
  • Nvm: v0.38.0 and above

Installation

You can install @stackadapt/pa-typescript-sdk using npm.

npm install @stackadapt/pa-typescript-sdk

GQL API Documentation

This SDK is built on top of StackAdapt's GQL Public API. We are continuously working on adding more documentation for the SDK to provide users with a better understanding of its usage. In the meantime, for more information, please refer to the following GQL documentations:

Example Usage

Initializing

// Importing library
import { initStackAdaptSDK } from "@stackadapt/pa-typescript-sdk";

// Can use 'SANDBOX' or 'PRODUCTION'
// You only need to initialize it once in your codebase
initStackAdaptSDK({
  token: MY_TOKEN,
  env: "SANDBOX",
});

General Endpoint

import {
  initStackAdaptSDK,
  generalEndpoint,
  UserError, // Part of StackAdapt's GQL types
} from "@stackadapt/pa-typescript-sdk";

initStackAdaptSDK({
  token: MY_TOKEN,
  env: "SANDBOX",
});

const getAdvertisers = async (first: number) => {
  type Result = { advertisers: { nodes: { id: number }[] } };
  const result = await generalEndpoint<Result>({
    query:
      "query Advertisers($firsts: Int!){ advertisers(first: $firsts) { nodes {id } } }",
    variables: { firsts: first },
  });
  return result;
};

const createAdvertiser = async (name: string) => {
  type Result = {
    createAdvertiser: {
      advertiser: { id: string; name: string };
      userErrors: UserError[];
    };
  };
  const results = await generalEndpoint<Result>({
    query:
      "mutation createNewAdvertiser($input: AdvertiserInput!){ createAdvertiser(input: $input){ advertiser { id name } userErrors { message path }  } }",
    variables: { input: { name: name } },
  });
  return results;
};

Create Creatives using URLs

import {
  initStackAdaptSDK,
  createCreativeByURL,
  ResourceType,
} from "@stackadapt/pa-typescript-sdk";

initStackAdaptSDK({
  token: MY_TOKEN,
  env: "SANDBOX",
});

const result = await createCreativeByURL({
  resourceType: ResourceType.Image,
  url: "https://dxt983tp420wz.cloudfront.net/images/other/careers_engineering_jack_yiu@2x-3e20599c3982ae946ba4037f72874416.jpg",
  fragment: "{ id ...on ImageCreative{ s3Url } }", // GQL fragment of UploadedCreative type, defaults to { id }. More information on what fields are available https://docs.stackadapt.com/graphql/reference#definition-UploadedCreative
});

Create Creatives using Local Files

The localPath parameter should support both absolute and relative paths, assuming the asset exists at the specified path.

import {
  initStackAdaptSDK,
  createCreativeByLocalFile,
  ResourceType,
} from "@stackadapt/pa-typescript-sdk";

initStackAdaptSDK({
  token: MY_TOKEN,
  env: "SANDBOX",
});

const result = await createCreativeByLocalFile({
  resourceType: ResourceType.Image,
  localPath: "./resources/assets/IMAGE_JPEG_300x300.jpeg",
  fragment: "{ id ...on ImageCreative{ s3Url } }", // GQL fragment of UploadedCreative type, defaults to { id }. More information on what fields are available https://docs.stackadapt.com/graphql/reference#definition-UploadedCreative
});

Use The Latest Schema

This SDK uses the latest StackAdapt Public API Schema which is updated weekly.

import {
  StackadaptSchema // Exports as GraphQLSchema type
} from "@stackadapt/pa-typescript-sdk";

Insights Reporting

import {
  initStackAdaptSDK,
  // Current Exposed Insights Reporting
  getDomainsReport,
  getGeographicReport,
  DateRangeInput,
  InsightReportingFilters,
  Pagination
} from "@stackadapt/pa-typescript-sdk";

initStackAdaptSDK({
  token: MY_TOKEN,
  env: "SANDBOX",
});

const filters: InsightReportingFilters = { advertiserIds: [1] };

const pagination: Pagination = {
  first: 1,
};

const date: DateRangeInput = {
  from: "2021-01-01",
  to: "2024-12-31",
};

// Domain Insight Reporting
const domainReportResult = await getDomainReport({
  filters: filters,
  pagination: pagination,
  date: date
});

// Geographical Insight Reporting
const geoReportResult = await getGeographicReport({
  filters: filters,
  pagination: pagination,
  date: date
});