Skip to content

christyharagan/segment-tsd-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Segment TSD Generator

Overview

Segment's Protocols enable users to creating tracking plans and then govern all events that are sent to Segment to ensure they conform to this tracking plan. This project creates TypeScript definition files from these to give developers strongly typed access to Segment's various JavaScript/TypeScript APIs and SDKs.

Comparison to TypeWriter

Segment already has an open-source library called TypeWriter that does something similar (although it also supports the iOS and Android SDKs; however on the JavaScript/TypeScript front, it is specifically used for Analytics JS). TypeWriter takes a different approach to this project. TypeWriter creates helper functions, where-as this project merely creates TypeScript definitions that fit over the "vanilla" calls of e.g. the Analytics JS SDK.

Reasons to use TypeWriter

  • You want typing definitions for the iOS and Android SDKS
  • You want to use convenience methods for Analytics JS rather than make calls against the raw API

Reasons to use Segment TSD Generator

Install

Install via NPM:

npm i --save segment-tsd-generator

or Yarn:

yarn install segment-tsd-generator

Example Usage

import {getTrackingPlan} from 'segment-typescript-api/cjs/config-api'
import generator from 'segment-tsd-generator'
import * as fs from 'fs'

let WORKSPACE_TOKEN = '123'
let WORKSPACE_SLUG = 'my-workspace'

getTrackingPlan(WORKSPACE_TOKEN, WORKSPACE_SLUG, 'My Tracking Plan').then(generator).then(tsd=>{
  fs.writeFile('my_tracking_plan.d.ts', tsd, 'utf8', (err) => {
    if (err) {
      console.err(err)
    } else {
      // Do awesome stuff with you definition file
    }
  })
})

About

Generate .d.ts files from Segment Protocol Tracking Plans

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published