humanbehavior-js 0.3.4 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +0 -52
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +1 -52
- package/dist/esm/index.js.map +1 -1
- package/dist/index.min.js +2 -2
- package/dist/index.min.js.map +1 -1
- package/dist/types/index.d.ts +2 -23
- package/package.json +1 -1
- package/src/index.ts +0 -3
- package/src/server.ts +0 -63
package/dist/cjs/index.js
CHANGED
|
@@ -5942,57 +5942,6 @@ if (isBrowser) {
|
|
|
5942
5942
|
window.HumanBehaviorTracker = HumanBehaviorTracker;
|
|
5943
5943
|
}
|
|
5944
5944
|
|
|
5945
|
-
/**
|
|
5946
|
-
* Server-side utilities for HumanBehavior SDK
|
|
5947
|
-
*/
|
|
5948
|
-
/**
|
|
5949
|
-
* Identify user from server-side (NextAuth, Firebase, etc.)
|
|
5950
|
-
* Use this in your auth events to track users immediately on sign-in
|
|
5951
|
-
*/
|
|
5952
|
-
function identifyUser(userId, // Separate userId parameter (should be stable unique identifier)
|
|
5953
|
-
userData, apiKey) {
|
|
5954
|
-
return __awaiter$1(this, void 0, void 0, function* () {
|
|
5955
|
-
try {
|
|
5956
|
-
const response = yield fetch('https://ingest.humanbehavior.co/api/ingestion/user', {
|
|
5957
|
-
method: 'POST',
|
|
5958
|
-
headers: {
|
|
5959
|
-
'Content-Type': 'application/json',
|
|
5960
|
-
'Authorization': `Bearer ${apiKey}`
|
|
5961
|
-
},
|
|
5962
|
-
body: JSON.stringify({
|
|
5963
|
-
userId: userId, // Use stable unique identifier
|
|
5964
|
-
userAttributes: userData, // Email and other data go here
|
|
5965
|
-
sessionId: 'server-side-identification', // Dummy sessionId for server-side requests
|
|
5966
|
-
posthogName: userData.email || userData.name || null // Update posthogName with email
|
|
5967
|
-
})
|
|
5968
|
-
});
|
|
5969
|
-
if (!response.ok) {
|
|
5970
|
-
const errorText = yield response.text();
|
|
5971
|
-
return {
|
|
5972
|
-
success: false,
|
|
5973
|
-
error: `Failed to identify user: ${response.status} ${response.statusText} - ${errorText}`
|
|
5974
|
-
};
|
|
5975
|
-
}
|
|
5976
|
-
const result = yield response.json();
|
|
5977
|
-
// If server found existing user, return the actual userId
|
|
5978
|
-
if (result.actualUserId && result.actualUserId !== userId) {
|
|
5979
|
-
console.log(`🔄 Server found existing user: ${result.actualUserId} (sent: ${userId})`);
|
|
5980
|
-
return {
|
|
5981
|
-
success: true,
|
|
5982
|
-
actualUserId: result.actualUserId
|
|
5983
|
-
};
|
|
5984
|
-
}
|
|
5985
|
-
return { success: true };
|
|
5986
|
-
}
|
|
5987
|
-
catch (error) {
|
|
5988
|
-
return {
|
|
5989
|
-
success: false,
|
|
5990
|
-
error: error instanceof Error ? error.message : 'Unknown error'
|
|
5991
|
-
};
|
|
5992
|
-
}
|
|
5993
|
-
});
|
|
5994
|
-
}
|
|
5995
|
-
|
|
5996
5945
|
/**
|
|
5997
5946
|
* Main entry point for the HumanBehavior SDK
|
|
5998
5947
|
*/
|
|
@@ -6006,7 +5955,6 @@ exports.HumanBehaviorTracker = HumanBehaviorTracker;
|
|
|
6006
5955
|
exports.MAX_CHUNK_SIZE_BYTES = MAX_CHUNK_SIZE_BYTES;
|
|
6007
5956
|
exports.RedactionManager = RedactionManager;
|
|
6008
5957
|
exports.default = HumanBehaviorTracker;
|
|
6009
|
-
exports.identifyUser = identifyUser;
|
|
6010
5958
|
exports.isChunkSizeExceeded = isChunkSizeExceeded;
|
|
6011
5959
|
exports.logDebug = logDebug;
|
|
6012
5960
|
exports.logError = logError;
|