@splitbee/core
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -39,3 +39,12 @@ export interface RequestContext { | ||
} | ||
declare type Requests = PageViewRequest | EventRequest | IdentifyRequest; | ||
interface EndRequest extends GenericRequest { | ||
path: '/end'; | ||
body: { | ||
requestId: string; | ||
data: { | ||
duration: number; | ||
}; | ||
}; | ||
} | ||
declare type Requests = PageViewRequest | EventRequest | IdentifyRequest | EndRequest; | ||
export declare type Response = { | ||
@@ -42,0 +51,0 @@ uid: string; |
@@ -138,2 +138,20 @@ 'use strict'; | ||
} | ||
}, | ||
end: function (_ref4) { | ||
var requestId = _ref4.requestId, | ||
data = _ref4.data, | ||
context = _ref4.context; | ||
try { | ||
return Promise.resolve(splitbeeRequest({ | ||
path: '/end', | ||
context: context, | ||
body: { | ||
requestId: requestId, | ||
data: data | ||
} | ||
})); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
} | ||
@@ -140,0 +158,0 @@ }; |
@@ -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("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,u=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:u})}))}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)}}}; | ||
"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("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,u=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:u})}))}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)}}}; | ||
//# sourceMappingURL=core.cjs.production.min.js.map |
@@ -134,2 +134,20 @@ function _extends() { | ||
} | ||
}, | ||
end: function (_ref4) { | ||
var requestId = _ref4.requestId, | ||
data = _ref4.data, | ||
context = _ref4.context; | ||
try { | ||
return Promise.resolve(splitbeeRequest({ | ||
path: '/end', | ||
context: context, | ||
body: { | ||
requestId: requestId, | ||
data: data | ||
} | ||
})); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
} | ||
@@ -136,0 +154,0 @@ }; |
@@ -22,3 +22,10 @@ import { RequestContext, JSONType, EventOptions } from './api'; | ||
}) => Promise<import("./api").Response | undefined>; | ||
end: ({ requestId, data, context, }: { | ||
requestId: string; | ||
data: { | ||
duration: number; | ||
}; | ||
context: RequestContext; | ||
}) => Promise<import("./api").Response | undefined>; | ||
}; | ||
export { RequestContext, JSONType }; |
{ | ||
"name": "@splitbee/core", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -42,4 +42,14 @@ export interface RequestContext { | ||
type Requests = PageViewRequest | EventRequest | IdentifyRequest; | ||
interface EndRequest extends GenericRequest { | ||
path: '/end'; | ||
body: { | ||
requestId: string; | ||
data: { | ||
duration: number; | ||
}; | ||
}; | ||
} | ||
type Requests = PageViewRequest | EventRequest | IdentifyRequest | EndRequest; | ||
export type Response = { | ||
@@ -46,0 +56,0 @@ uid: string; |
@@ -58,4 +58,25 @@ import { splitbeeRequest, RequestContext, JSONType, EventOptions } from './api'; | ||
}, | ||
end: async ({ | ||
requestId, | ||
data, | ||
context, | ||
}: { | ||
requestId: string; | ||
data: { | ||
duration: number; | ||
}; | ||
context: RequestContext; | ||
}) => { | ||
return await splitbeeRequest({ | ||
path: '/end', | ||
context, | ||
body: { | ||
requestId, | ||
data, | ||
}, | ||
}); | ||
}, | ||
}; | ||
export { RequestContext, JSONType }; |
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
107346
536