@splitbee/core
Advanced tools
Comparing version 0.2.3 to 0.2.4
@@ -69,3 +69,4 @@ export declare type Device = { | ||
}; | ||
export declare const setEndpoint: (endpoint: string) => string; | ||
export declare const splitbeeRequest: ({ path, context, body, }: Requests) => Promise<Response | undefined>; | ||
export {}; |
@@ -41,2 +41,6 @@ 'use strict'; | ||
var ENDPOINT = "https://hive.splitbee.io"; | ||
var setEndpoint = function setEndpoint(endpoint) { | ||
return ENDPOINT = endpoint; | ||
}; | ||
var splitbeeRequest = function splitbeeRequest(_ref) { | ||
@@ -47,3 +51,3 @@ var path = _ref.path, | ||
return Promise.resolve(_catch(function () { | ||
return Promise.resolve(fetch((process.env.SPLITBEE_CUSTOM_API || "https://hive.splitbee.io") + path, { | ||
return Promise.resolve(fetch(ENDPOINT + path, { | ||
method: 'POST', | ||
@@ -162,2 +166,3 @@ headers: _extends({}, (context === null || context === void 0 ? void 0 : context.userId) && context.userId !== '' && { | ||
exports.analytics = analytics; | ||
exports.setEndpoint = setEndpoint; | ||
//# sourceMappingURL=core.cjs.development.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(){return(e=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e}).apply(this,arguments)}Object.defineProperty(exports,"__esModule",{value:!0}),"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var t=function(t){var r=t.path,o=t.context,n=t.body;return Promise.resolve(function(e,t){try{var r=e()}catch(e){return}return r&&r.then?r.then(void 0,(function(){})):r}((function(){return Promise.resolve(fetch((process.env.SPLITBEE_CUSTOM_API||"https://hive.splitbee.io")+r,{method:"POST",headers:e({},(null==o?void 0:o.userId)&&""!==o.userId&&{userId:o.userId},(null==o?void 0:o.uid)&&{uid:o.uid},(null==o?void 0:o.projectId)&&{sbp:o.projectId},(null==o?void 0:o.userAgent)&&{"user-agent":o.userAgent}),body:JSON.stringify(n)})).then((function(e){function t(){return{uid:e.headers.get("uid")}}var r=function(){if(void 0!==typeof process.env&&200!==e.status)return Promise.resolve(e.json()).then((function(e){console.log("Splitbee Error: ",e)}))}();return r&&r.then?r.then(t):t()}))})))};exports.analytics={track:function(e){var r=e.event,o=e.data,n=e.context,i=e.options;try{return Promise.resolve(t({path:"/t",context:n,body:{event:r,data:o,options:i}}))}catch(e){return Promise.reject(e)}},page:function(r){var o=r.page,n=r.data,i=r.context,s=r.options;try{return Promise.resolve(t({path:"/i",context:i,body:e({page:o},(null==n?void 0:n.referrer)&&{referrer:n.referrer},(null==n?void 0:n.requestId)&&{requestId:n.requestId},{options:s})}))}catch(e){return Promise.reject(e)}},identify:function(e){var r=e.userData,o=e.context;try{return Promise.resolve(t({path:"/user",context:o,body:r}))}catch(e){return Promise.reject(e)}},end:function(e){var r=e.requestId,o=e.data,n=e.context;try{return Promise.resolve(t({path:"/end",context:n,body:{requestId:r,data:o}}))}catch(e){return Promise.reject(e)}}}; | ||
"use strict";function e(){return(e=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e}).apply(this,arguments)}Object.defineProperty(exports,"__esModule",{value:!0}),"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var t="https://hive.splitbee.io",r=function(r){var o=r.path,n=r.context,i=r.body;return Promise.resolve(function(e,t){try{var r=e()}catch(e){return}return r&&r.then?r.then(void 0,(function(){})):r}((function(){return Promise.resolve(fetch(t+o,{method:"POST",headers:e({},(null==n?void 0:n.userId)&&""!==n.userId&&{userId:n.userId},(null==n?void 0:n.uid)&&{uid:n.uid},(null==n?void 0:n.projectId)&&{sbp:n.projectId},(null==n?void 0:n.userAgent)&&{"user-agent":n.userAgent}),body:JSON.stringify(i)})).then((function(e){function t(){return{uid:e.headers.get("uid")}}var r=function(){if(void 0!==typeof process.env&&200!==e.status)return Promise.resolve(e.json()).then((function(e){console.log("Splitbee Error: ",e)}))}();return r&&r.then?r.then(t):t()}))})))};exports.analytics={track:function(e){var t=e.event,o=e.data,n=e.context,i=e.options;try{return Promise.resolve(r({path:"/t",context:n,body:{event:t,data:o,options:i}}))}catch(e){return Promise.reject(e)}},page:function(t){var o=t.page,n=t.data,i=t.context,u=t.options;try{return Promise.resolve(r({path:"/i",context:i,body:e({page:o},(null==n?void 0:n.referrer)&&{referrer:n.referrer},(null==n?void 0:n.requestId)&&{requestId:n.requestId},{options:u})}))}catch(e){return Promise.reject(e)}},identify:function(e){var t=e.userData,o=e.context;try{return Promise.resolve(r({path:"/user",context:o,body:t}))}catch(e){return Promise.reject(e)}},end:function(e){var t=e.requestId,o=e.data,n=e.context;try{return Promise.resolve(r({path:"/end",context:n,body:{requestId:t,data:o}}))}catch(e){return Promise.reject(e)}}},exports.setEndpoint=function(e){return t=e}; | ||
//# sourceMappingURL=core.cjs.production.min.js.map |
@@ -37,2 +37,6 @@ function _extends() { | ||
var ENDPOINT = "https://hive.splitbee.io"; | ||
var setEndpoint = function setEndpoint(endpoint) { | ||
return ENDPOINT = endpoint; | ||
}; | ||
var splitbeeRequest = function splitbeeRequest(_ref) { | ||
@@ -43,3 +47,3 @@ var path = _ref.path, | ||
return Promise.resolve(_catch(function () { | ||
return Promise.resolve(fetch((process.env.SPLITBEE_CUSTOM_API || "https://hive.splitbee.io") + path, { | ||
return Promise.resolve(fetch(ENDPOINT + path, { | ||
method: 'POST', | ||
@@ -157,3 +161,3 @@ headers: _extends({}, (context === null || context === void 0 ? void 0 : context.userId) && context.userId !== '' && { | ||
export { analytics }; | ||
export { analytics, setEndpoint }; | ||
//# sourceMappingURL=core.esm.js.map |
@@ -1,2 +0,2 @@ | ||
import { RequestContext, JSONType, EventOptions } from './api'; | ||
import { RequestContext, JSONType, EventOptions, setEndpoint } from './api'; | ||
export declare const analytics: { | ||
@@ -30,2 +30,2 @@ track: ({ event, data, context, options, }: { | ||
}; | ||
export { RequestContext, JSONType }; | ||
export { RequestContext, JSONType, setEndpoint }; |
{ | ||
"name": "@splitbee/core", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -92,2 +92,6 @@ export type Device = { | ||
let ENDPOINT = `https://hive.splitbee.io`; | ||
export const setEndpoint = (endpoint: string) => (ENDPOINT = endpoint); | ||
export const splitbeeRequest = async ({ | ||
@@ -99,17 +103,14 @@ path, | ||
try { | ||
const res = await fetch( | ||
(process.env.SPLITBEE_CUSTOM_API || `https://hive.splitbee.io`) + path, | ||
{ | ||
method: 'POST', | ||
headers: { | ||
...(context?.userId && | ||
context.userId !== '' && { userId: context.userId }), | ||
...(context?.uid && { uid: context.uid }), | ||
...(context?.projectId && { sbp: context.projectId }), | ||
...(context?.userAgent && { 'user-agent': context.userAgent }), | ||
// ...(event.context.page && { origin: event.context.page.url }), | ||
}, | ||
body: JSON.stringify(body), | ||
} | ||
); | ||
const res = await fetch(ENDPOINT + path, { | ||
method: 'POST', | ||
headers: { | ||
...(context?.userId && | ||
context.userId !== '' && { userId: context.userId }), | ||
...(context?.uid && { uid: context.uid }), | ||
...(context?.projectId && { sbp: context.projectId }), | ||
...(context?.userAgent && { 'user-agent': context.userAgent }), | ||
// ...(event.context.page && { origin: event.context.page.url }), | ||
}, | ||
body: JSON.stringify(body), | ||
}); | ||
@@ -116,0 +117,0 @@ if (typeof process.env !== undefined && res.status !== 200) { |
@@ -1,2 +0,8 @@ | ||
import { splitbeeRequest, RequestContext, JSONType, EventOptions } from './api'; | ||
import { | ||
splitbeeRequest, | ||
RequestContext, | ||
JSONType, | ||
EventOptions, | ||
setEndpoint, | ||
} from './api'; | ||
@@ -81,2 +87,2 @@ export const analytics = { | ||
export { RequestContext, JSONType }; | ||
export { RequestContext, JSONType, setEndpoint }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
111634
603