cohere-js
Advanced tools
Comparing version 1.0.12 to 1.0.13
@@ -13,2 +13,21 @@ const hookInputSetter = (target, key) => { | ||
let hooked = false; | ||
const hookSegment = () => { | ||
if (window.analytics && !hooked) { | ||
hooked = true; | ||
const origIdentify = window.analytics.identify.bind(window.analytics); | ||
window.analytics.identify = (...args) => { | ||
const userId = args[0]; | ||
// Ignore anonymous users | ||
if (typeof userId === "string") { | ||
const traits = typeof args[1] === "object" ? args[1] : {}; | ||
// Rename name to displayName | ||
const { name: displayName, ...rest } = traits; | ||
window.Cohere.identify(userId, { displayName, ...rest }); | ||
} | ||
origIdentify(...args); | ||
}; | ||
} | ||
}; | ||
const disableLoad = typeof window === "undefined" || | ||
@@ -33,3 +52,7 @@ !window.document || | ||
const noopModule = { | ||
init: noop, | ||
init: (_, options) => { | ||
if (options === null || options === void 0 ? void 0 : options.segmentIntegration) { | ||
hookSegment(); | ||
} | ||
}, | ||
identify: noop, | ||
@@ -47,5 +70,6 @@ stop: noop, | ||
Cohere.invoked = true; | ||
Cohere.snippet = "0.4"; | ||
Cohere.snippet = "0.5"; | ||
Cohere.valhook = true; | ||
Cohere.methods = bridgedMethods; | ||
Cohere.hookSegment = hookSegment; | ||
Cohere.methods.forEach((method) => { | ||
@@ -52,0 +76,0 @@ Cohere[method] = (...args) => { |
@@ -15,2 +15,21 @@ 'use strict'; | ||
let hooked = false; | ||
const hookSegment = () => { | ||
if (window.analytics && !hooked) { | ||
hooked = true; | ||
const origIdentify = window.analytics.identify.bind(window.analytics); | ||
window.analytics.identify = (...args) => { | ||
const userId = args[0]; | ||
// Ignore anonymous users | ||
if (typeof userId === "string") { | ||
const traits = typeof args[1] === "object" ? args[1] : {}; | ||
// Rename name to displayName | ||
const { name: displayName, ...rest } = traits; | ||
window.Cohere.identify(userId, { displayName, ...rest }); | ||
} | ||
origIdentify(...args); | ||
}; | ||
} | ||
}; | ||
const disableLoad = typeof window === "undefined" || | ||
@@ -35,3 +54,7 @@ !window.document || | ||
const noopModule = { | ||
init: noop, | ||
init: (_, options) => { | ||
if (options === null || options === void 0 ? void 0 : options.segmentIntegration) { | ||
hookSegment(); | ||
} | ||
}, | ||
identify: noop, | ||
@@ -49,5 +72,6 @@ stop: noop, | ||
Cohere.invoked = true; | ||
Cohere.snippet = "0.4"; | ||
Cohere.snippet = "0.5"; | ||
Cohere.valhook = true; | ||
Cohere.methods = bridgedMethods; | ||
Cohere.hookSegment = hookSegment; | ||
Cohere.methods.forEach((method) => { | ||
@@ -54,0 +78,0 @@ Cohere[method] = (...args) => { |
{ | ||
"name": "cohere-js", | ||
"version": "1.0.12", | ||
"version": "1.0.13", | ||
"description": "Cohere.so JS SDK", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -6,4 +6,9 @@ declare type UserAttrs = { | ||
}; | ||
declare type InitOptions = { | ||
disableRecording?: boolean; | ||
segmentIntegration?: boolean; | ||
childIframe?: boolean; | ||
}; | ||
declare type CohereExports = { | ||
init: (apiKey: string) => void; | ||
init: (apiKey: string, options?: InitOptions) => void; | ||
identify: (userId: string, attrs?: UserAttrs) => void; | ||
@@ -10,0 +15,0 @@ stop: () => void; |
7521
7
200