0.0.9 ā€¢ Published 1 year ago

typespot v0.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

TypeSpot šŸ’«

npm package Build Status Downloads Issues Code Coverage Commitizen Friendly Semantic Release

The missing type system for your HubSpot objects.

What?

This package generates explicit type files for all of your object types within your current portal, looking something like:

export type Company = {
    properties: {
        name: string
        some_custom_prop: 'cool' | 'cooler'
        // ... all default and custom props
    }
}

For convienience it also exports the full property definitions:

export const CompanyProperties = [
    {
        name: 'name',
        label: 'Name',
        description: 'Its a name!',
        // ...
    },
    
    // ...
]

Why?

When using @hubspot/api-client with TypeScript, the objects returned are practically black boxes:

class SimplePublicObject {
    properties: {
        [key: string]: string;
    };        
}

So, we have a hard time type checking when reading/writing to the API and we constantly have to reference the web portal. With this package we can develop faster and more confidently.

Usage

Install the package:

npm install typespot

Next, generate your files

npx ts-node typespot <YOUR_ACCESS_TOKEN>

You will see something like:

āœ… Created src/types/Company.ts
āœ… Created src/types/Contact.ts
āœ… Created src/types/Deal.ts
āœ… Created src/types/Product.ts
šŸŸ” 403 Forbidden when reading tickets. Did you forget to assign scopes?
šŸŸ” 403 Forbidden when reading quotes. Did you forget to assign scopes?

Alternatively, you may generate these files programatically:

import { TypeSpot } from 'typespot';
import { Client } from "@hubspot/api-client";

const client = new Client({accessToken: 'secret'})
new TypeSpot({ client }).write()

TODO

missing some object types in CRM
missing custom object in CRM
ALL other types are missing

License

MIT