plugeen 0.0.15 → 0.0.17
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/index.cjs +6 -6
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -6
- package/dist/plugeen.global.js +2 -2
- package/package.json +5 -2
package/dist/index.cjs
CHANGED
|
@@ -517,12 +517,12 @@ function initLogsModule(http, logger) {
|
|
|
517
517
|
// src/index.ts
|
|
518
518
|
function createPlugeen(apiKey, options) {
|
|
519
519
|
const resolved = {
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
520
|
+
...options,
|
|
521
|
+
apiUrl: options.apiUrl ?? "https://www.plugeen.app",
|
|
522
|
+
debug: options.debug ?? false,
|
|
523
|
+
analytics: options.analytics ?? false,
|
|
524
|
+
webVitals: options.webVitals ?? false,
|
|
525
|
+
errors: options.errors ?? false
|
|
526
526
|
};
|
|
527
527
|
const logger = createLogger(resolved.debug);
|
|
528
528
|
if (!apiKey) {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
declare function tryCatch<T>(promise: Promise<T>): Promise<[T, null] | [null, Error]>;
|
|
2
|
+
|
|
1
3
|
declare const modules: readonly ["webVitals", "analytics", "errors"];
|
|
2
4
|
|
|
3
5
|
type IdentitySchema = {
|
|
@@ -84,8 +86,6 @@ declare global {
|
|
|
84
86
|
}
|
|
85
87
|
}
|
|
86
88
|
|
|
87
|
-
declare function tryCatch<T>(promise: Promise<T>): Promise<[T, null] | [null, Error]>;
|
|
88
|
-
|
|
89
89
|
declare function createPlugeen(apiKey: string, options: Partial<SdkOptions>): Plugeen;
|
|
90
90
|
|
|
91
91
|
export { type AnalyticsSchema, type EventsModule, type EventsSchema, type FeatureFlagsModule, type FeatureFlagsSchema, type IdentitiesModule, type IdentitySchema, type LogsModule, type LogsSchema, type MetricName, type Plugeen, type SdkOptions, type TrackFn, type TupleResponse, type WebVitalsSchema, createPlugeen, tryCatch, webVitalsMetrics };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
declare function tryCatch<T>(promise: Promise<T>): Promise<[T, null] | [null, Error]>;
|
|
2
|
+
|
|
1
3
|
declare const modules: readonly ["webVitals", "analytics", "errors"];
|
|
2
4
|
|
|
3
5
|
type IdentitySchema = {
|
|
@@ -84,8 +86,6 @@ declare global {
|
|
|
84
86
|
}
|
|
85
87
|
}
|
|
86
88
|
|
|
87
|
-
declare function tryCatch<T>(promise: Promise<T>): Promise<[T, null] | [null, Error]>;
|
|
88
|
-
|
|
89
89
|
declare function createPlugeen(apiKey: string, options: Partial<SdkOptions>): Plugeen;
|
|
90
90
|
|
|
91
91
|
export { type AnalyticsSchema, type EventsModule, type EventsSchema, type FeatureFlagsModule, type FeatureFlagsSchema, type IdentitiesModule, type IdentitySchema, type LogsModule, type LogsSchema, type MetricName, type Plugeen, type SdkOptions, type TrackFn, type TupleResponse, type WebVitalsSchema, createPlugeen, tryCatch, webVitalsMetrics };
|
package/dist/index.js
CHANGED
|
@@ -515,12 +515,12 @@ function initLogsModule(http, logger) {
|
|
|
515
515
|
// src/index.ts
|
|
516
516
|
function createPlugeen(apiKey, options) {
|
|
517
517
|
const resolved = {
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
518
|
+
...options,
|
|
519
|
+
apiUrl: options.apiUrl ?? "https://www.plugeen.app",
|
|
520
|
+
debug: options.debug ?? false,
|
|
521
|
+
analytics: options.analytics ?? false,
|
|
522
|
+
webVitals: options.webVitals ?? false,
|
|
523
|
+
errors: options.errors ?? false
|
|
524
524
|
};
|
|
525
525
|
const logger = createLogger(resolved.debug);
|
|
526
526
|
if (!apiKey) {
|
package/dist/plugeen.global.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* plugeen v0.
|
|
2
|
-
"use strict";var plugeen=(()=>{function b(){if(typeof document>"u")return null;let
|
|
1
|
+
/* plugeen v0.0.17 | https://plugeen.app */
|
|
2
|
+
"use strict";var plugeen=(()=>{function b(){if(typeof document>"u")return null;let t=document.currentScript;if(!t){let o=document.getElementsByTagName("script");for(let i of Array.from(o))if(i.src&&(i.src.includes("/plugeen.global")||i.src.includes("/plugeen."))){t=i;break}}if(!t)return null;let e={},r=t.getAttribute("data-api-key")??void 0;e.apiUrl=t.getAttribute("data-api-url")??void 0,e.service=t.getAttribute("data-service")??void 0,e.analytics=t.getAttribute("data-analytics")==="true",e.webVitals=t.getAttribute("data-web-vitals")==="true",e.errors=t.getAttribute("data-errors")==="true";let n=t.getAttribute("data-debug");return n!==null&&(e.debug=n==="true"||n===""),Object.fromEntries(Object.entries({...e,apiKey:r}).filter(([o,i])=>i!=null&&i!==""))}function h(t){return t?{log:(...e)=>console.log("[plugeen]",...e),warn:(...e)=>console.warn("[plugeen]",...e),error:(...e)=>console.error("[plugeen]",...e)}:{log:()=>{},warn:()=>{},error:()=>{}}}function g(){if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID();if(typeof crypto<"u"&&typeof crypto.getRandomValues=="function"){let t=new Uint8Array(16);crypto.getRandomValues(t),t[6]=t[6]&15|64,t[8]=t[8]&63|128;let e=Array.from(t).map(r=>r.toString(16).padStart(2,"0")).join("");return`${e.slice(0,8)}-${e.slice(8,12)}-${e.slice(12,16)}-${e.slice(16,20)}-${e.slice(20)}`}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let e=Math.floor(Math.random()*16);return(t==="x"?e:e&3|8).toString(16)})}var f="plugeen_anon_id",m="plugeen_session_id",d="plugeen_session_ts";var P=18e5,c={};function E(){try{let t=localStorage.getItem(f);return t||(t=`anon_${g()}`,localStorage.setItem(f,t)),t}catch{return c[f]||(c[f]=`anon_${g()}`),c[f]}}function I(t){try{localStorage.setItem(f,t)}catch{c[f]=t}}function y(){try{let t=sessionStorage.getItem(m),e=sessionStorage.getItem(d);if(t&&e&&Date.now()-parseInt(e,10)<P)return sessionStorage.setItem(d,String(Date.now())),t;sessionStorage.removeItem(m),sessionStorage.removeItem(d);let r=`sess_${g()}`;return sessionStorage.setItem(m,r),sessionStorage.setItem(d,String(Date.now())),r}catch{let t=c[m],e=c[d];if(t&&e&&Date.now()-parseInt(e,10)<P)return c[d]=String(Date.now()),t;let r=`sess_${g()}`;return c[m]=r,c[d]=String(Date.now()),r}}var k=t=>new Promise(e=>setTimeout(e,t)),w=class{constructor(e,r){this.baseUrl=e;this.apiKey=r}headers(e){let r={Authorization:`Bearer ${this.apiKey}`,"x-identity-id":E(),"x-session-id":y()};return e!=="GET"&&(r["Content-Type"]="application/json"),r}async request(e,{retries:r=0,method:n,body:o,searchParams:i},s=0){let l=i?`?${new URLSearchParams(i).toString()}`:"",u=`${this.baseUrl}${e}${l}`;try{let a=await fetch(u,{method:n,headers:this.headers(n),credentials:"omit",body:o?JSON.stringify(o):void 0});if(a.status===401||a.status===404)throw await a.json().catch(()=>null)||new Error(String(a.status));if((a.status>=500||a.status===429)&&r>0)return await k((1+s)*1e3),this.request(e,{body:o,retries:r-1,method:n},s+1);if(a.status>=200&&a.status<300)return(await a.json().catch(()=>{throw new Error("Failed to parse json")})).data;throw new Error("Error")}catch(a){if(a instanceof TypeError&&r>0)return await k(1e3),this.get(e,{retries:r-1});throw a}}async post(e,r,n){return this.request(e,{...n,retries:n?.retries??0,body:r,method:"POST"})}async get(e,r){return this.request(e,{...r,retries:r?.retries??0,method:"GET"})}beacon(e,r){if(typeof navigator>"u"||!navigator.sendBeacon)return!1;try{let n=new Blob([JSON.stringify(r)],{type:"application/json"});return navigator.sendBeacon(`${this.baseUrl}${e}`,n)}catch{return!1}}};function T(t,e){if(typeof window>"u")return;e.log("Analytics module started");let r=Date.now(),n=0,o=window.location.href,i=()=>{n++,t.post("/v1/analytics",{event:"page_view",url:window.location.href,title:document.title,sessionId:y(),referrer:document.referrer||void 0,screenWidth:window.innerWidth,screenHeight:window.innerHeight})},s=(a=!1)=>{let p={event:"page_exit",url:window.location.href,title:document.title,sessionId:y(),referrer:document.referrer||void 0,screenWidth:window.innerWidth,screenHeight:window.innerHeight,metadata:{timeOnPage:Math.round((Date.now()-r)/1e3),pageCount:n}};a?t.beacon("/v1/analytics",p):t.post("/v1/analytics",p)},l=()=>{window.location.href!==o&&(s(),r=Date.now(),o=window.location.href,i())},u=a=>{let p=history[a].bind(history);history[a]=(...V)=>{p(...V),l()}};u("pushState"),u("replaceState"),window.addEventListener("popstate",l),window.addEventListener("beforeunload",()=>s(!0)),document.addEventListener("visibilitychange",()=>document.visibilityState==="hidden"&&s(!0)),i()}var H=["chrome-extension://","moz-extension://","safari-extension://","edge-extension://"];function v(t){if(!t)return!1;let e=t.toLowerCase();return H.some(r=>e.includes(r))}function M(t,e){typeof window>"u"||(e.log("Errors module started"),window.addEventListener("error",r=>{v(r.filename)||v(r.error?.stack)||r.error===null&&r.message==="Script error."||t.post("/v1/logs",{message:r.message||"Unknown Error",level:"error",url:window.location.href,source:"client",metadata:{stack:r.error?.stack,type:r.error?.name}})}),window.addEventListener("unhandledrejection",r=>{let{reason:n}=r;if(v(n?.stack))return;let o="Unknown Error",i;n instanceof Error?(o=n.message,i=n.stack):typeof n=="string"?o=n:n!==null&&typeof n=="object"&&"message"in n&&(o=String(n.message)),t.post("/v1/logs",{message:o,url:window.location.href,source:"client",level:"error",metadata:{stack:i,type:"UnhandledRejection"}})}))}function x(){return performance.getEntriesByType("navigation")[0]?.activationStart??0}function R(){let t=performance.getEntriesByType("navigation")[0];if(t&&t.responseStart>0&&t.responseStart<performance.now())return t}function S(t,e,r){try{if(!PerformanceObserver.supportedEntryTypes.includes(t))return;let n=new PerformanceObserver(o=>{Promise.resolve().then(()=>e(o.getEntries()))});return n.observe({type:t,buffered:!0,...r??{}}),n}catch{return}}function D(t){let e=new Set;S("paint",r=>{for(let n of r)if(n.name==="first-contentful-paint"&&!e.has("first-contentful-paint")){e.add("first-contentful-paint");let o=Math.max(n.startTime-x(),0);t("first-contentful-paint",Math.round(o))}})}function N(t){let e=!1,r=S("largest-contentful-paint",o=>{if(e)return;let i=o[o.length-1];if(i){let s=Math.max(i.startTime-x(),0);t("largest-contentful-paint",Math.round(s))}});if(!r)return;let n=()=>{if(e)return;e=!0;let o=r.takeRecords();if(o.length>0){let i=o[o.length-1],s=Math.max(i.startTime-x(),0);t("largest-contentful-paint",Math.round(s))}r.disconnect()};for(let o of["keydown","click","visibilitychange"])addEventListener(o,n,{capture:!0,once:!0})}function j(t){let e=0,r=[],n=0;S("layout-shift",o=>{for(let i of o){let s=i;if(s.hadRecentInput)continue;let l=r[r.length-1],u=r[0];if(r.length>0&&l&&u&&s.startTime-l.startTime<1e3&&s.startTime-u.startTime<5e3?(e+=s.value,r.push(s)):(e=s.value,r=[s]),e>n){n=e;let a=Math.round(n*1e4)/1e4;t("cumulative-layout-shift",a)}}})}function $(t){let e=R();if(!e)return;let r=Math.max(e.responseStart-x(),0);t("time-to-first-byte",Math.round(r))}function W(t){let e=new Map,r=0;S("event",n=>{for(let o of n){let i=o;if(!i.interactionId)continue;let s=e.get(i.interactionId)??0;i.duration>s&&(e.set(i.interactionId,i.duration),i.duration>r&&(r=i.duration,t("interaction-to-next-paint",Math.round(i.duration))))}},{durationThreshold:40})}function B(t){if(typeof requestAnimationFrame>"u")return;let e=0,r=2e3,n=performance.now(),o=()=>{e++,performance.now()-n<r?requestAnimationFrame(o):t("frames-per-second",Math.round(e/r*1e3))};document.readyState==="complete"?requestAnimationFrame(o):window.addEventListener("load",()=>requestAnimationFrame(o),{once:!0})}function L(){if(!(typeof window<"u")||!(typeof PerformanceObserver<"u"))return[];let r=new Map;return D((n,o)=>r.set(n,o)),N((n,o)=>r.set(n,o)),j((n,o)=>r.set(n,o)),$((n,o)=>r.set(n,o)),W((n,o)=>r.set(n,o)),B((n,o)=>r.set(n,o)),Array.from(r).map(([n,o])=>({name:n,value:o}))}function O(t,e){e.log("Web Vitals module started"),t.post("/v1/web-vitals",{url:window.location.href,metrics:L()})}function C(t,e){return e.log("Identities module started"),{async identify(r,n){let o=await t.post("/v1/identities",{...n,id:r});return I(r),o}}}function _(t,e){return e.log("Events module started"),{track:(r,n={})=>t.post("/v1/events",{name:r,data:n,source:"sdk"})}}function F(t,e){return e.log("Feature Flags module started"),{get:r=>t.get("/v1/feature-flags",{searchParams:{key:r}})}}function U(t,e){return e.log("Logs module started"),{send:r=>t.post("/v1/logs",r)}}function A(t,e){let r={...e,apiUrl:e.apiUrl??"https://www.plugeen.app",debug:e.debug??!1,analytics:e.analytics??!1,webVitals:e.webVitals??!1,errors:e.errors??!1},n=h(r.debug);if(!t)throw new TypeError("[plugeen] data-api-key is required");let o=new w(r.apiUrl,t),i={track:_(o,n).track,identify:C(o,n).identify,featureFlags:F(o,n),logs:U(o,n)};return typeof window<"u"&&(r.analytics&&T(o,n),r.webVitals&&O(o,n),r.errors&&M(o,n)),n.log(`Running on ${typeof window>"u"?"server":"client"} side`),i}function q(){let t=b(),e=h(!!t?.debug);if(t){if(!t.apiKey)return e.warn("Data-api-key is required.")}else return e.warn("Failed to start script");e.log("Started");let r=A(t.apiKey,t);return window.plugeen=r,r}window.plugeen||q();})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "plugeen",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"main": "./dist/index.cjs",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"devDependencies": {
|
|
@@ -27,7 +27,10 @@
|
|
|
27
27
|
"build": "tsup",
|
|
28
28
|
"dev": "concurrently 'tsup --watch' 'bun --watch ./src/demo/index.ts'",
|
|
29
29
|
"biome": "biome check",
|
|
30
|
-
"typecheck": "tsc --project tsconfig.json --noEmit"
|
|
30
|
+
"typecheck": "tsc --project tsconfig.json --noEmit",
|
|
31
|
+
"publish:patch": "npm version patch && bun run build && npm publish",
|
|
32
|
+
"publish:minor": "npm version minor && bun run build && npm publish",
|
|
33
|
+
"publish:major": "npm version major && bun run build && npm publish"
|
|
31
34
|
},
|
|
32
35
|
"type": "module",
|
|
33
36
|
"types": "./dist/index.d.ts",
|