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

@targetprocess/tp-js-client

v1.5.1

Published

Client for access Targetprocess Api

Downloads

154

Readme

Javascript Targetprocess API client

Node.js compatibility

**Node.js 12 or higher is required.

JavaScript client for accessing Targetprocess API

Features

  • Allow to access api/v2/ endpoint with type-checkings between entities and it's selectors
  • Work with paginated results (pagination based on ordering by entities ID)
  • Handful shortcuts for where conditions

##Prerequirements

  1. dotnet 2.1 (for client-regeneration)

Quick start

To install:

npm install  @targetprocess/tp-js-client

Examples

Client creation

You can use httpClientFactory from tokiny library as a wrapper over you favorite fetch implementation. Also, it is strongly recommended to pass X-Client-ID and X-Correlation-ID headers to all request.

import { createTokenFactory, httpClientFactory } from '@targetprocess/tokiny'
import { TpClient } from '@targetprocess/tp-js-client'
import { fetch } from 'got-fetch'

const tokenFactory = createTokenFactory({
  authUrl: env.AUTH_SERVICE_URI,
  clientId: env.CLIENT_ID,
  clientSecret: env.CLIENT_SECRET
})

const fetchWithHeaders = (input: RequestInfo, init?: RequestInit) =>
    fetch(input, {
      ...init,
      headers: {
        ...init?.headers,
        'X-Correlation-ID': 'sample-operation-0000-33300-0003-34443',
        'X-Client-ID': 'tp-client-sample-test',
      },
    })

const scopes = 'tp'

const tpClient = new TpClient(
    `https://inteam3.tpondemand.net/`,
    httpClientFactory(scopes, tokenFactory, fetchWithHeaders as any)
)

readAll method

Can be used if you want to read all entities


type UserStory = {
    id: number
    name: string
    tasksCount: number
}

const users = await tpClient.readAll<UserStory>('userStories', {
    where: 'id==39528',
    select: {
        id: 'id',
        name: 'name',
        tasksCount: 'tasks.count',
    }
})

readPages method

Can be used if you want to read data paged. Please note, entities skipping during pagination will be made using where=(id > ...), not using `skip=...' parameter.

type UserStory = {
    id: number
    name: string
    tasksCount: number
}

for await (const page of this.readPages<UserStory>("userStories", {
    where: 'id==39528',
    select: {
        id: 'id',
        name: 'name',
        tasksCount: 'tasks.count',
    })) {
      // page will have type UserStory[]
    }

Selectors

Selectors will be checked during compile time. Following code:

type UserStory = {
    id: number
    name: string
    tasksCount: number
    assignedUser: string
}

const selector:Selector<UserStory> = {
    id: 'id',
    name: 'name',
    tasksCount: 'tasks.count'
    // forget to specify selector for assignedUser property
}

will produce an error during compile time: Property 'assignedUser' is missing in type '{ id: string; name: string; tasksCount: string; }' but required in type 'StructuredSelector<UserStory>'.

Other TP endpoints

Since client is mostly generated from api/tp.yaml swagger spec, all methods described in that spec could be also used:

const loggedUser = await tpClient.getLoggedUser();

Release notes

here