Nosto / nosto-react

BSD 3-Clause "New" or "Revised" License
1 stars 1 forks source link

Re: NostoClient interface missing from v2 package dist #94

Open Dashue opened 3 months ago

Dashue commented 3 months ago

Hello Nosto Dev Team!

As the title states we just upgraded to v2 and lost typing for our analytics code that records attributes.

Also both in v2 and v3 the .recordAttribution method returns an object rather than a representation of the actual object returned. For now we've added a return type ourselves as below, copied from the nosto lib.

interface Attribution {
  recordAttribution: (event: Event) => Attribution
  dumpData: () => EventTuple[]
  done: () => Promise<void>
}

 const VIEW_PRODUCT = "vp"
 const LIKE_PRODUCT = "lp"
 const DISLIKE_PRODUCT = "dp"
 const REMOVE_PRODUCT = "rp"
 const BOUGHT_PRODUCT = "bp"
 const VIEW_CATEGORY = "vc"
 const ORDER = "or"
 const INTERNAL_SEARCH = "is"
 const ADD_TO_CART = "cp"
 const EXTERNAL_CAMPAIGN = "ec"
 const EXTERNAL_SEARCH = "es"
 const GIVE_COUPON = "gc"
 const SOURCE = "src"
 const CART_POPUP_RECOMMENDATIONS = "cpr"
 const PAGE_LOAD = "pl"
 const CUSTOM_CAMPAIGN = "cc"
 const CONTENT_CAMPAIGN = "con"

const eventTypes = [
  VIEW_PRODUCT,
  LIKE_PRODUCT,
  DISLIKE_PRODUCT,
  REMOVE_PRODUCT,
  BOUGHT_PRODUCT,
  VIEW_CATEGORY,
  ORDER,
  INTERNAL_SEARCH,
  ADD_TO_CART,
  EXTERNAL_CAMPAIGN,
  EXTERNAL_SEARCH,
  GIVE_COUPON,
  SOURCE,
  CART_POPUP_RECOMMENDATIONS,
  PAGE_LOAD,
  CUSTOM_CAMPAIGN,
  CONTENT_CAMPAIGN,
] as const

type EventType = (typeof eventTypes)[number]

type EventRefType = (typeof refTypes)[number]

const TRIGGERED_MAIL = "email"
const EMAIL_WIDGET = "imgrec"
const ONSITE_RECOMMENDATIONS = "rec"
const API_RECOMMENDATIONS = "api"
const ONSITE_CAMPAIGNS = "oc"
const CATEGORY_MERCHANDISING = "cmp"
const ONSITE_SEARCH = "os"

const refTypes = [
  TRIGGERED_MAIL,
  EMAIL_WIDGET,
  ONSITE_RECOMMENDATIONS,
  API_RECOMMENDATIONS,
  ONSITE_CAMPAIGNS,
  CATEGORY_MERCHANDISING,
  ONSITE_SEARCH,
] as const

type EventTuple = [
  type: EventType,
  target?: string,
  ref?: string,
  refSrc?: string,
  targetFragment?: string,
  refType?: EventRefType
]

Many thanks

timowestnosto commented 1 month ago

Thanks for the bug report and apologies for the delayed answer. I'll adjust the type declarations accordingly.

timowestnosto commented 6 hours ago

@Dashue There is now a dedicated module for nostojs typing available. Does that satisfy your needs?