klaviyo / klaviyo-node-sdk

Node SDK for developers to use Klaviyo's Public API
https://developers.klaviyo.com/
14 stars 2 forks source link

Typescript support #1

Closed maxsynnott closed 1 year ago

maxsynnott commented 2 years ago

Hello,

Do you intend to add Typescript support? I think it would be a mistake not to.

deldrid1 commented 2 years ago

Its yucky (looks like there are some gaps in Klaviyo's OpenAPI definition or there is an issue with the code generator), but I was able to get a minimal typescript client going with this (once I used find/replace to fix 90 TS compile errors, but I also was integrating into a lerna monorepo with newer version of TS, etc. so YMMV)

curl -X POST \
  https://generator3.swagger.io/api/generate \
  -H 'content-type: application/json' \
  -d '{
  "specURL" : "https://klaviyo-openapi.s3.amazonaws.com/spec.json",
  "lang" : "typescript-axios",
  "type" : "CLIENT",
  "codegenVersion" : "V3"
}' --output ~/Downloads/klaviyo.zip

The Typescript support is pretty basic, because all of the interesting bits of the request end up being JSON.stringifyied, but its better than nothing:

    import { TrackIdentifyApi } from '@faredrop/klayvio'

    const trackIdentify = new TrackIdentifyApi({
      apiKey: 'pk_1234...'
    })

    const response = await trackIdentify.identifyPost(JSON.stringify({
      "token": ".....",
      "properties": {
        "$email": "abraham.lincoln@klaviyo.com",
        "$first_name": "Abraham",
        "$last_name": "Lincoln",
        "$city": "Springfield",
        "$region": "Illinois"
      }
    }))

    console.log(`success === ${response.data === '1'}`);
steven-t-h commented 2 years ago

@deldrid1 do you have this published anywhere?

Ian-Montgomery-Klaviyo commented 1 year ago

A typescript SDK is in progress for our new apis. For now I suggest taking a look at the new node sdk and it's discussion about typescript (The objects for the new sdk are much more consistent)

Read our Migrating from V1/V2 to the new Klaviyo APIs and Comparison between v1/v2 and new APIs.

Ian-Montgomery-Klaviyo commented 1 year ago

Typescript is in open beta check it out here.