@krest/sdk-web 0.0.0-stage → 0.1.0
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 +1 -0
- package/dist/index.d.cts +49 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.js +1 -0
- package/dist/krest.global.js +1 -0
- package/package.json +33 -3
- package/README.md +0 -3
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var a=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var p=(o,e)=>{for(var t in e)a(o,t,{get:e[t],enumerable:!0})},h=(o,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of l(e))!c.call(o,n)&&n!==t&&a(o,n,{get:()=>e[n],enumerable:!(i=d(e,n))||i.enumerable});return o};var f=o=>h(a({},"__esModule",{value:!0}),o);var w={};p(w,{default:()=>g,krest:()=>u});module.exports=f(w);var s=class{constructor(){this.config=null;this.queue=[];this.timer=null;this.spaHooked=!1;this.lastPath=""}init(e){if(!(typeof window>"u")){if(!e.publicKey||!e.endpoint)throw new Error("@krest/sdk-web: publicKey and endpoint are required");e.respectDnt&&navigator.doNotTrack==="1"||(this.config={autoTrackPageviews:!0,respectDnt:!1,flushIntervalMs:1500,...e,endpoint:e.endpoint.replace(/\/+$/,"")},this.config.autoTrackPageviews&&(this.trackPageview(),this.hookSpaNavigation()),window.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.flush(!0)}),window.addEventListener("pagehide",()=>this.flush(!0)))}}trackPageview(e){if(typeof window>"u"||!this.config)return;let t=e||window.location.pathname||"/";if(t===this.lastPath&&!e)return;this.lastPath=t;let i=new URLSearchParams(window.location.search),n;if(document.referrer)try{let r=new URL(document.referrer);r.hostname!==window.location.hostname&&(n=r.hostname)}catch{}this.enqueue({eventType:"pageview",path:t,referrerDomain:n,utmSource:i.get("utm_source")||void 0,utmMedium:i.get("utm_medium")||void 0,utmCampaign:i.get("utm_campaign")||void 0})}trackEvent(e,t){typeof window>"u"||!this.config||this.enqueue({eventType:"custom",eventName:e,path:window.location.pathname||"/",properties:t})}trackWalletConnect(e){typeof window>"u"||!this.config||this.enqueue({eventType:"wallet_connect",eventName:"wallet_connect",path:window.location.pathname||"/",walletName:e.walletName,network:e.network||"mainnet"})}trackTx(e){typeof window>"u"||!this.config||this.enqueue({eventType:"tx_funnel",eventName:`tx_${e.stage}`,path:window.location.pathname||"/",txStage:e.stage,network:e.network||"mainnet",contractId:e.contractId,properties:e.properties})}flush(e=!1){if(!this.config||this.queue.length===0)return;this.timer&&(clearTimeout(this.timer),this.timer=null);let t=this.queue.splice(0,20),i=`${this.config.endpoint}/v1/ingest/web`,n=JSON.stringify({publicKey:this.config.publicKey,events:t});if(e&&typeof navigator.sendBeacon=="function"){let r=new Blob([n],{type:"application/json"});if(navigator.sendBeacon(i,r))return}fetch(i,{method:"POST",headers:{"Content-Type":"application/json","x-krest-key":this.config.publicKey},body:n,keepalive:!0,mode:"cors"}).catch(()=>{})}enqueue(e){if(this.queue.push(e),this.queue.length>=20){this.flush(!1);return}this.timer||(this.timer=setTimeout(()=>this.flush(!1),this.config?.flushIntervalMs??1500))}hookSpaNavigation(){if(this.spaHooked||typeof window>"u")return;this.spaHooked=!0;let e=history.pushState.bind(history);history.pushState=(...t)=>{e(...t),this.trackPageview()},window.addEventListener("popstate",()=>{this.trackPageview()})}},u=new s,g=u;0&&(module.exports={krest});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
type StellarNetwork = "mainnet" | "testnet" | "futurenet" | "standalone";
|
|
2
|
+
type TxStage = "initiated" | "signed" | "submitted" | "confirmed" | "failed";
|
|
3
|
+
interface KrestConfig {
|
|
4
|
+
publicKey: string;
|
|
5
|
+
endpoint: string;
|
|
6
|
+
autoTrackPageviews?: boolean;
|
|
7
|
+
respectDnt?: boolean;
|
|
8
|
+
flushIntervalMs?: number;
|
|
9
|
+
}
|
|
10
|
+
interface WebEventPayload {
|
|
11
|
+
eventType: "pageview" | "custom" | "wallet_connect" | "tx_funnel";
|
|
12
|
+
eventName?: string;
|
|
13
|
+
path: string;
|
|
14
|
+
referrerDomain?: string;
|
|
15
|
+
utmSource?: string;
|
|
16
|
+
utmMedium?: string;
|
|
17
|
+
utmCampaign?: string;
|
|
18
|
+
walletName?: string;
|
|
19
|
+
network?: StellarNetwork;
|
|
20
|
+
txStage?: TxStage;
|
|
21
|
+
contractId?: string;
|
|
22
|
+
properties?: Record<string, string | number | boolean>;
|
|
23
|
+
}
|
|
24
|
+
declare class KrestClient {
|
|
25
|
+
private config;
|
|
26
|
+
private queue;
|
|
27
|
+
private timer;
|
|
28
|
+
private spaHooked;
|
|
29
|
+
private lastPath;
|
|
30
|
+
init(config: KrestConfig): void;
|
|
31
|
+
trackPageview(customPath?: string): void;
|
|
32
|
+
trackEvent(eventName: string, properties?: Record<string, string | number | boolean>): void;
|
|
33
|
+
trackWalletConnect(params: {
|
|
34
|
+
walletName: string;
|
|
35
|
+
network?: StellarNetwork;
|
|
36
|
+
}): void;
|
|
37
|
+
trackTx(params: {
|
|
38
|
+
stage: TxStage;
|
|
39
|
+
network?: StellarNetwork;
|
|
40
|
+
contractId?: string;
|
|
41
|
+
properties?: Record<string, string | number | boolean>;
|
|
42
|
+
}): void;
|
|
43
|
+
flush(useBeacon?: boolean): void;
|
|
44
|
+
private enqueue;
|
|
45
|
+
private hookSpaNavigation;
|
|
46
|
+
}
|
|
47
|
+
declare const krest: KrestClient;
|
|
48
|
+
|
|
49
|
+
export { type KrestConfig, type StellarNetwork, type TxStage, type WebEventPayload, krest as default, krest };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
type StellarNetwork = "mainnet" | "testnet" | "futurenet" | "standalone";
|
|
2
|
+
type TxStage = "initiated" | "signed" | "submitted" | "confirmed" | "failed";
|
|
3
|
+
interface KrestConfig {
|
|
4
|
+
publicKey: string;
|
|
5
|
+
endpoint: string;
|
|
6
|
+
autoTrackPageviews?: boolean;
|
|
7
|
+
respectDnt?: boolean;
|
|
8
|
+
flushIntervalMs?: number;
|
|
9
|
+
}
|
|
10
|
+
interface WebEventPayload {
|
|
11
|
+
eventType: "pageview" | "custom" | "wallet_connect" | "tx_funnel";
|
|
12
|
+
eventName?: string;
|
|
13
|
+
path: string;
|
|
14
|
+
referrerDomain?: string;
|
|
15
|
+
utmSource?: string;
|
|
16
|
+
utmMedium?: string;
|
|
17
|
+
utmCampaign?: string;
|
|
18
|
+
walletName?: string;
|
|
19
|
+
network?: StellarNetwork;
|
|
20
|
+
txStage?: TxStage;
|
|
21
|
+
contractId?: string;
|
|
22
|
+
properties?: Record<string, string | number | boolean>;
|
|
23
|
+
}
|
|
24
|
+
declare class KrestClient {
|
|
25
|
+
private config;
|
|
26
|
+
private queue;
|
|
27
|
+
private timer;
|
|
28
|
+
private spaHooked;
|
|
29
|
+
private lastPath;
|
|
30
|
+
init(config: KrestConfig): void;
|
|
31
|
+
trackPageview(customPath?: string): void;
|
|
32
|
+
trackEvent(eventName: string, properties?: Record<string, string | number | boolean>): void;
|
|
33
|
+
trackWalletConnect(params: {
|
|
34
|
+
walletName: string;
|
|
35
|
+
network?: StellarNetwork;
|
|
36
|
+
}): void;
|
|
37
|
+
trackTx(params: {
|
|
38
|
+
stage: TxStage;
|
|
39
|
+
network?: StellarNetwork;
|
|
40
|
+
contractId?: string;
|
|
41
|
+
properties?: Record<string, string | number | boolean>;
|
|
42
|
+
}): void;
|
|
43
|
+
flush(useBeacon?: boolean): void;
|
|
44
|
+
private enqueue;
|
|
45
|
+
private hookSpaNavigation;
|
|
46
|
+
}
|
|
47
|
+
declare const krest: KrestClient;
|
|
48
|
+
|
|
49
|
+
export { type KrestConfig, type StellarNetwork, type TxStage, type WebEventPayload, krest as default, krest };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var r=class{constructor(){this.config=null;this.queue=[];this.timer=null;this.spaHooked=!1;this.lastPath=""}init(e){if(!(typeof window>"u")){if(!e.publicKey||!e.endpoint)throw new Error("@krest/sdk-web: publicKey and endpoint are required");e.respectDnt&&navigator.doNotTrack==="1"||(this.config={autoTrackPageviews:!0,respectDnt:!1,flushIntervalMs:1500,...e,endpoint:e.endpoint.replace(/\/+$/,"")},this.config.autoTrackPageviews&&(this.trackPageview(),this.hookSpaNavigation()),window.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.flush(!0)}),window.addEventListener("pagehide",()=>this.flush(!0)))}}trackPageview(e){if(typeof window>"u"||!this.config)return;let t=e||window.location.pathname||"/";if(t===this.lastPath&&!e)return;this.lastPath=t;let n=new URLSearchParams(window.location.search),i;if(document.referrer)try{let o=new URL(document.referrer);o.hostname!==window.location.hostname&&(i=o.hostname)}catch{}this.enqueue({eventType:"pageview",path:t,referrerDomain:i,utmSource:n.get("utm_source")||void 0,utmMedium:n.get("utm_medium")||void 0,utmCampaign:n.get("utm_campaign")||void 0})}trackEvent(e,t){typeof window>"u"||!this.config||this.enqueue({eventType:"custom",eventName:e,path:window.location.pathname||"/",properties:t})}trackWalletConnect(e){typeof window>"u"||!this.config||this.enqueue({eventType:"wallet_connect",eventName:"wallet_connect",path:window.location.pathname||"/",walletName:e.walletName,network:e.network||"mainnet"})}trackTx(e){typeof window>"u"||!this.config||this.enqueue({eventType:"tx_funnel",eventName:`tx_${e.stage}`,path:window.location.pathname||"/",txStage:e.stage,network:e.network||"mainnet",contractId:e.contractId,properties:e.properties})}flush(e=!1){if(!this.config||this.queue.length===0)return;this.timer&&(clearTimeout(this.timer),this.timer=null);let t=this.queue.splice(0,20),n=`${this.config.endpoint}/v1/ingest/web`,i=JSON.stringify({publicKey:this.config.publicKey,events:t});if(e&&typeof navigator.sendBeacon=="function"){let o=new Blob([i],{type:"application/json"});if(navigator.sendBeacon(n,o))return}fetch(n,{method:"POST",headers:{"Content-Type":"application/json","x-krest-key":this.config.publicKey},body:i,keepalive:!0,mode:"cors"}).catch(()=>{})}enqueue(e){if(this.queue.push(e),this.queue.length>=20){this.flush(!1);return}this.timer||(this.timer=setTimeout(()=>this.flush(!1),this.config?.flushIntervalMs??1500))}hookSpaNavigation(){if(this.spaHooked||typeof window>"u")return;this.spaHooked=!0;let e=history.pushState.bind(history);history.pushState=(...t)=>{e(...t),this.trackPageview()},window.addEventListener("popstate",()=>{this.trackPageview()})}},a=new r,d=a;export{d as default,a as krest};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var KrestAnalytics=(()=>{var s=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var p=(i,e)=>{for(var n in e)s(i,n,{get:e[n],enumerable:!0})},f=(i,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of d(e))!l.call(i,t)&&t!==n&&s(i,t,{get:()=>e[t],enumerable:!(r=c(e,t))||r.enumerable});return i};var h=i=>f(s({},"__esModule",{value:!0}),i);var g={};p(g,{krest:()=>a});var u=class{constructor(){this.config=null;this.queue=[];this.timer=null;this.spaHooked=!1;this.lastPath=""}init(e){if(!(typeof window>"u")){if(!e.publicKey||!e.endpoint)throw new Error("@krest/sdk-web: publicKey and endpoint are required");e.respectDnt&&navigator.doNotTrack==="1"||(this.config={autoTrackPageviews:!0,respectDnt:!1,flushIntervalMs:1500,...e,endpoint:e.endpoint.replace(/\/+$/,"")},this.config.autoTrackPageviews&&(this.trackPageview(),this.hookSpaNavigation()),window.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.flush(!0)}),window.addEventListener("pagehide",()=>this.flush(!0)))}}trackPageview(e){if(typeof window>"u"||!this.config)return;let n=e||window.location.pathname||"/";if(n===this.lastPath&&!e)return;this.lastPath=n;let r=new URLSearchParams(window.location.search),t;if(document.referrer)try{let o=new URL(document.referrer);o.hostname!==window.location.hostname&&(t=o.hostname)}catch{}this.enqueue({eventType:"pageview",path:n,referrerDomain:t,utmSource:r.get("utm_source")||void 0,utmMedium:r.get("utm_medium")||void 0,utmCampaign:r.get("utm_campaign")||void 0})}trackEvent(e,n){typeof window>"u"||!this.config||this.enqueue({eventType:"custom",eventName:e,path:window.location.pathname||"/",properties:n})}trackWalletConnect(e){typeof window>"u"||!this.config||this.enqueue({eventType:"wallet_connect",eventName:"wallet_connect",path:window.location.pathname||"/",walletName:e.walletName,network:e.network||"mainnet"})}trackTx(e){typeof window>"u"||!this.config||this.enqueue({eventType:"tx_funnel",eventName:`tx_${e.stage}`,path:window.location.pathname||"/",txStage:e.stage,network:e.network||"mainnet",contractId:e.contractId,properties:e.properties})}flush(e=!1){if(!this.config||this.queue.length===0)return;this.timer&&(clearTimeout(this.timer),this.timer=null);let n=this.queue.splice(0,20),r=`${this.config.endpoint}/v1/ingest/web`,t=JSON.stringify({publicKey:this.config.publicKey,events:n});if(e&&typeof navigator.sendBeacon=="function"){let o=new Blob([t],{type:"application/json"});if(navigator.sendBeacon(r,o))return}fetch(r,{method:"POST",headers:{"Content-Type":"application/json","x-krest-key":this.config.publicKey},body:t,keepalive:!0,mode:"cors"}).catch(()=>{})}enqueue(e){if(this.queue.push(e),this.queue.length>=20){this.flush(!1);return}this.timer||(this.timer=setTimeout(()=>this.flush(!1),this.config?.flushIntervalMs??1500))}hookSpaNavigation(){if(this.spaHooked||typeof window>"u")return;this.spaHooked=!0;let e=history.pushState.bind(history);history.pushState=(...n)=>{e(...n),this.trackPageview()},window.addEventListener("popstate",()=>{this.trackPageview()})}},a=new u;if(typeof document<"u"){let i=document.currentScript||document.querySelector("script[data-krest-key]");if(i){let e=i.getAttribute("data-krest-key"),n=i.getAttribute("data-krest-endpoint"),r=i.getAttribute("data-krest-dnt")==="true",t=n||"";if(!t&&i.src)try{t=new URL(i.src).origin}catch{t=""}e&&t&&(a.init({publicKey:e,endpoint:t,respectDnt:r}),window.krest=a)}}return h(g);})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krest/sdk-web",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Privacy-first Web and Stellar dApp analytics SDK",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/KELLON-RWA/Krest.git",
|
|
9
|
+
"directory": "packages/sdk-web"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "./dist/index.cjs",
|
|
16
|
+
"module": "./dist/index.mjs",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.mjs",
|
|
22
|
+
"require": "./dist/index.cjs"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"tsup": "^8.4.0",
|
|
30
|
+
"typescript": "^5.8.2"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsup",
|
|
34
|
+
"typecheck": "tsc --noEmit"
|
|
35
|
+
}
|
|
6
36
|
}
|
package/README.md
DELETED