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

pipedrive-typed-orm

v0.0.33

Published

This project provides a simplified method for managing custom fields in Pipedrive. It enables you to define your custom fields in a TypeScript schema and then push these changes to Pipedrive. This approach encourages the use of the Pipedrive sandbox envir

Downloads

15

Readme

Pipedrive Typed ORM

This project provides a simplified method for managing custom fields in Pipedrive. It enables you to define your custom fields in a TypeScript schema and then push these changes to Pipedrive. This approach encourages the use of the Pipedrive sandbox environment as a staging area for making changes.

We recommend a workflow where you first define your schema in typescript. Then, push these changes to the Pipedrive sandbox URL for testing. Once you've confirmed everything works as expected, you can push the changes to the production URL.

Additionally, this project includes a client that allows you to make POST requests to send data, such as leads, to Pipedrive in a type-safe manner. This eliminates the need to deal with randomly generated IDs, making your posts more readable and type-safe.

before:

const response = await(
  await fetch(
    `https://api.pipedrive.com/v1/lead?api_token=${process.env.PIPEDRIVE_KEY}`,
    {
      method: "POST",
      body: JSON.stringify({
        "859d31b30d784df404a530f1d3e2d4e5d9f328f8": [194, 196],
        "8aa23ca40129abb365dcf2c6173adcb6641c65a5": 191,
        person_id: 1256,
        title: "Title lead",
      }),
      headers: {
        "Content-Type": "application/json",
      },
    }
  ).json()
);

With the client

const result = await client.postLead({
  title: "Title lead",
  person_id: 1256,
  custom_fields: {
    "Car make": "bmw" /* Type safe */,
    "Kms interested": ["10000", "20000"] /* Type safe  */,
  },
});

Getting started

Defining the schema

You export your schema from a typescript file.

/* schema/schema.ts */
import { Schema } from "pipedrive-typed-orm";

export const carDealershipSchema = {
  lead: {
    Campaign: {
      field_type: "text",
    },
    "Car make": {
      field_type: "enum",
      options: ["bmw", "seat", "ferrari"],
    },
    "Kms interested": {
      field_type: "set",
      options: ["10000", "15000", "20000"],
    },
  },
  person: {
    City: {
      field_type: "text",
    },
  },
} as const satisfies Schema;

Setting the environment variables

The environment variables that need to be set are:

    SCHEMA_PATH=path/to/schema.ts

Pushing the schema to pipedrive

    bunx pipedrive-typed-orm push-schema

Using the client

import { schema } from "path/to/schema.ts";

const client = createPipedriveOrmClient<typeof schema>();

const result = await client.postLead({
  title: "Title lead",
  person_id: 1256,
  custom_fields: {
    "Car make": "bmw" /* Type safe */,
    "Kms interested": ["10000", "20000"] /* Type safe  */,
  },
});

Type Utilities

import { PropertiesFromSchema } from "pipedrive-typed-orm";

const Properties = PropertiesFromSchema<CustomSchema>;

const Lead = Properties["lead"];
/* {
  title: string,
  ...
  custom_properties: {
    ...
  }
} */

Roadmap

Pushing Schema

  • [x] FEATURE - Implementing almost all field_types (text, phone, double, date, monetary, enum, set)
  • [ ] OPTIMIZATION - Make deletions in bulk
  • [ ] FEATURE - Schema diff option (no pushing to pipedrive)
  • [ ] FEATURE - Schema pull from pipedrive

Client

  • [x] FEATURE - Posting leads
  • [x] FEATURE - Posting persons
  • [ ] FEATURE - Posting deals
  • [ ] FEATURE - Posting organizations
  • [ ] FEATURE - Posting pipelines
  • [ ] FEATURE - Implement Get request
  • [ ] REFACTOR - createClient shouldnt work with env variables

Caveats

  • The labels of the fields ARE the keys of the schema object. This means that the labels must be unique within each property.
  • Setting a field required only work for type safety purposes. Since pipedrive doesn't allow for setting this option from the api.
  • Making any post will do two api calls. One for getting the custom fields and the other to send the post.