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

@planet-a/affinity-node

v0.0.2-test.5

Published

API wrapper for the affinity.co API

Downloads

1,719

Readme

Test, Lint & Deploy NPM Version affinity-node

Node module for the Affinity CRM.

Supports both V1 and V2 of the Affinity API.

This module is incomplete for V1; not all API endpoints are implemented. It is in active development and the API might change without notice. Contributions welcome.

Usage

import { Affinity } from '@planet-a/affinity-node/v1'

const { user } = await new Affinity(YOUR_API_KEY).auth.whoAmI()
console.log(`Hello ${user.firstName}`)

Have a look at the autogenerated docs for examples, etc.

API completeness

V1

V2

V2 is generated via OpenAPITools/openapi-generator.

The command:

nix develop --command deno task generate-v2-client

will generate an OpenAPI client for Node in Typescript.

Sample usage:

import { AuthApi, createConfiguration } from '@planet-a/affinity-node/v2'

const config = createConfiguration({
    authMethods: {
        bearerAuth: {
            tokenProvider: {
                getToken: async () => Promise.resolve('API_KEY'),
            },
        },
    },
})
const authApi = new ObjectAuthApi(config)
const { tenant } = await authApi.getV2AuthWhoami()
console.log(tenant.name)

An up-to-date OpenAPI spec can be downloaded from here. Drop it into ./openapi before you run the command above (remove the old version beforehand).

Paging

This module comes with a pagination helper for the V2 API. Sample usage:

import { CompaniesApi, helpers } from '@planet-a/affinity-node/v2'
const { paginator: { paginated } } = helpers

const companiesApi = new CompaniesApi(config)

for await (
    const page of paginated(
        companiesApi.getV2Companies.bind(companiesApi),
    )({
        limit: 10,
    })
) {
    // Fetch 10 companies at a time, print, repeat
    console.log(page)
}

Similar projects

Development

Note on deno: This repository is using Deno heavily for anything dev-related. The resulting node package is meant to be agnostic of the runtime used, so there shouldn't be any deno-specific references. For the tests, etc. Deno-specific APIs, libraries and imports may be used.

  1. Install nix
  2. Run nix develop
  3. Run any deno task, e.g. deno task test

Hint: you can do a live run via API_KEY=<your-api-key> deno task snapshot-update to update snapshots from your actual Affinity instance during development.

⚠️ Make sure you do not commit any unsanitized data.

Direnv

This repo is direnv-enabled. If you have Nix and direnv on your system, you can ignore any nix develop --command prefixes and just work in the folder as if you were inside the nix flake environment. This is the recommended way, as it greatly simplifies the handling of dev tasks and pre-commit checks.

Commands

Build the library

  1. nix develop --command deno task build

Run tests with coverage

  1. nix develop --command deno task test:coverage

Format code

  1. nix develop --command deno task format

Lint code

  1. nix develop --command deno task lint

Generate documentation

  1. nix develop --command deno task docs
  2. open ./docs/index.html

Style

  • File names are snake_case
  • Symbols are camelCase
  • Symbols inherited from the Affinity API documentation, such as path and query parameters adopt the API documentation style, snake_case
  • Enum values are SNAKE_UPPERCASE

Commits

This repo follows the conventional commits format. Run nix develop --command cz commit after staging some changes to be guided through the process if you're unfamiliar with it.

Pre commit hooks

Pre-commit hooks are managed by Nix. Once you run your commit, it will analyze the changes and run required hooks.