@openpanel/sdk
Advanced tools
+1
-1
@@ -1,1 +0,1 @@ | ||
| "use strict";var d=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var h=(i,e)=>{for(var r in e)d(i,r,{get:e[r],enumerable:!0})},f=(i,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of y(e))!p.call(i,t)&&t!==r&&d(i,t,{get:()=>e[t],enumerable:!(s=u(e,t))||s.enumerable});return i};var I=i=>f(d({},"__esModule",{value:!0}),i);var g={};h(g,{OpenPanel:()=>l});module.exports=I(g);var o=class{constructor(e){this.baseUrl=e.baseUrl,this.headers={"Content-Type":"application/json",...e.defaultHeaders},this.maxRetries=e.maxRetries??3,this.initialRetryDelay=e.initialRetryDelay??500}async resolveHeaders(){let e={};for(let[r,s]of Object.entries(this.headers)){let t=await s;t!==null&&(e[r]=t)}return e}addHeader(e,r){this.headers[e]=r}async post(e,r,s,t){try{let n=await fetch(e,{method:"POST",headers:await this.resolveHeaders(),body:r?JSON.stringify(r??{}):void 0,keepalive:!0,...s});if(n.status===401)return null;if(n.status!==200&&n.status!==202)throw new Error(`HTTP error! status: ${n.status}`);let a=await n.text();return a?JSON.parse(a):null}catch(n){if(t<this.maxRetries){let a=this.initialRetryDelay*2**t;return await new Promise(c=>setTimeout(c,a)),this.post(e,r,s,t+1)}return console.error("Max retries reached:",n),null}}async fetch(e,r,s={}){let t=`${this.baseUrl}${e}`;return this.post(t,r,s,0)}};var l=class{constructor(e){this.options=e;this.queue=[];let r={"openpanel-client-id":e.clientId};e.clientSecret&&(r["openpanel-client-secret"]=e.clientSecret),r["openpanel-sdk-name"]=e.sdk||"node",r["openpanel-sdk-version"]=e.sdkVersion||"1.1.0",this.api=new o({baseUrl:e.apiUrl||"https://api.openpanel.dev",defaultHeaders:r})}init(){}ready(){this.options.waitForProfile=!1,this.flush()}shouldQueue(e){return!!(e.type==="replay"&&!this.sessionId||this.options.waitForProfile&&!this.profileId)}async send(e){if(this.options.disabled||this.options.filter&&!this.options.filter(e))return Promise.resolve();if(this.shouldQueue(e))return this.queue.push(e),Promise.resolve();let r=await this.api.fetch("/track",e,{keepalive:e.type!=="replay"});this.deviceId=r?.deviceId;let s=!!this.sessionId;return this.sessionId=r?.sessionId,!s&&this.sessionId&&this.flush(),r}setGlobalProperties(e){this.global={...this.global,...e}}async track(e,r){return this.log("track event",e,r),this.send({type:"track",payload:{name:e,profileId:r?.profileId??this.profileId,properties:{...this.global??{},...r??{}}}})}async identify(e){if(this.log("identify user",e),e.profileId&&(this.profileId=e.profileId,this.flush()),Object.keys(e).length>1)return this.send({type:"identify",payload:{...e,properties:{...this.global,...e.properties}}})}async alias(e){}async increment(e){return this.send({type:"increment",payload:e})}async decrement(e){return this.send({type:"decrement",payload:e})}async revenue(e,r){let s=r?.deviceId;return delete r?.deviceId,this.track("revenue",{...r??{},...s?{__deviceId:s}:{},__revenue:e})}getDeviceId(){return this.deviceId??""}getSessionId(){return this.sessionId??""}fetchDeviceId(){return Promise.resolve(this.deviceId??"")}clear(){this.profileId=void 0,this.deviceId=void 0,this.sessionId=void 0}flush(){let e=[];for(let r of this.queue){if(this.shouldQueue(r)){e.push(r);continue}let s=r.type==="replay"?r.payload:{...r.payload,profileId:"profileId"in r.payload?r.payload.profileId??this.profileId:this.profileId};this.send({...r,payload:s})}this.queue=e}log(...e){this.options.debug&&console.log("[OpenPanel.dev]",...e)}};0&&(module.exports={OpenPanel}); | ||
| "use strict";var d=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var y=(s,e)=>{for(var t in e)d(s,t,{get:e[t],enumerable:!0})},f=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of p(e))!h.call(s,i)&&i!==t&&d(s,i,{get:()=>e[i],enumerable:!(r=u(e,i))||r.enumerable});return s};var I=s=>f(d({},"__esModule",{value:!0}),s);var g={};y(g,{OpenPanel:()=>l});module.exports=I(g);var o=class{constructor(e){this.baseUrl=e.baseUrl,this.headers={"Content-Type":"application/json",...e.defaultHeaders},this.maxRetries=e.maxRetries??3,this.initialRetryDelay=e.initialRetryDelay??500}async resolveHeaders(){let e={};for(let[t,r]of Object.entries(this.headers)){let i=await r;i!==null&&(e[t]=i)}return e}addHeader(e,t){this.headers[e]=t}async post(e,t,r,i){try{let n=await fetch(e,{method:"POST",headers:await this.resolveHeaders(),body:t?JSON.stringify(t??{}):void 0,keepalive:!0,...r});if(n.status===401)return null;if(n.status!==200&&n.status!==202)throw new Error(`HTTP error! status: ${n.status}`);let a=await n.text();return a?JSON.parse(a):null}catch(n){if(i<this.maxRetries){let a=this.initialRetryDelay*2**i;return await new Promise(c=>setTimeout(c,a)),this.post(e,t,r,i+1)}return console.error("Max retries reached:",n),null}}async fetch(e,t,r={}){let i=`${this.baseUrl}${e}`;return this.post(i,t,r,0)}};var l=class{constructor(e){this.queue=[];this.options=e;let t={"openpanel-client-id":e.clientId};e.clientSecret&&(t["openpanel-client-secret"]=e.clientSecret),t["openpanel-sdk-name"]=e.sdk||"node",t["openpanel-sdk-version"]=e.sdkVersion||"1.2.0",this.api=new o({baseUrl:e.apiUrl||"https://api.openpanel.dev",defaultHeaders:t})}init(){}ready(){this.options.disabled=!1,this.options.waitForProfile=!1,this.flush()}shouldQueue(e){return!!(this.options.disabled||this.options.waitForProfile&&!this.profileId||e.type==="replay"&&!this.sessionId)}addQueue(e){e.type==="track"&&(e.payload.properties={...e.payload.properties??{},__timestamp:new Date().toISOString()}),this.queue.push(e)}async send(e){if(this.options.filter&&!this.options.filter(e))return Promise.resolve();if(this.shouldQueue(e))return this.addQueue(e),Promise.resolve();let t=await this.api.fetch("/track",e,{keepalive:e.type!=="replay"});this.deviceId=t?.deviceId;let r=!!this.sessionId;return this.sessionId=t?.sessionId,!r&&this.sessionId&&this.flush(),t}setGlobalProperties(e){this.global={...this.global,...e}}track(e,t){return this.log("track event",e,t),this.send({type:"track",payload:{name:e,profileId:t?.profileId??this.profileId,properties:{...this.global??{},...t??{}}}})}identify(e){if(this.log("identify user",e),e.profileId&&(this.profileId=e.profileId,this.flush()),Object.keys(e).length>1)return this.send({type:"identify",payload:{...e,properties:{...this.global,...e.properties}}})}alias(e){}increment(e){return this.send({type:"increment",payload:e})}decrement(e){return this.send({type:"decrement",payload:e})}revenue(e,t){let r=t?.deviceId;return delete t?.deviceId,this.track("revenue",{...t??{},...r?{__deviceId:r}:{},__revenue:e})}getDeviceId(){return this.deviceId??""}getSessionId(){return this.sessionId??""}fetchDeviceId(){return Promise.resolve(this.deviceId??"")}clear(){this.profileId=void 0,this.deviceId=void 0,this.sessionId=void 0}flush(){let e=[];for(let t of this.queue){if(this.shouldQueue(t)){e.push(t);continue}let r=t.type==="replay"?t.payload:{...t.payload,profileId:"profileId"in t.payload?t.payload.profileId??this.profileId:this.profileId};this.send({...t,payload:r})}this.queue=e}log(...e){this.options.debug&&console.log("[OpenPanel.dev]",...e)}};0&&(module.exports={OpenPanel}); |
+15
-7
@@ -25,7 +25,9 @@ import { ITrackHandlerPayload, IIdentifyPayload, IAliasPayload, IIncrementPayload, IDecrementPayload } from '@openpanel/validation'; | ||
| type TrackProperties = { | ||
| /** biome-ignore-all lint/style/noExportedImports: lazy */ | ||
| interface TrackProperties { | ||
| [key: string]: unknown; | ||
| profileId?: string; | ||
| }; | ||
| type OpenPanelOptions = { | ||
| } | ||
| interface OpenPanelOptions { | ||
| clientId: string; | ||
@@ -36,10 +38,15 @@ clientSecret?: string; | ||
| sdkVersion?: string; | ||
| /** | ||
| * @deprecated Queue events until `identify()` is called with a profileId. | ||
| * For manual queue control use `disabled: true` + `ready()` instead. | ||
| */ | ||
| waitForProfile?: boolean; | ||
| filter?: (payload: ITrackHandlerPayload) => boolean; | ||
| /** When true, events are queued until `ready()` is called (same as waitForProfile). */ | ||
| disabled?: boolean; | ||
| debug?: boolean; | ||
| }; | ||
| } | ||
| declare class OpenPanel { | ||
| api: Api; | ||
| options: OpenPanelOptions; | ||
| api: Api; | ||
| profileId?: string; | ||
@@ -54,2 +61,3 @@ deviceId?: string; | ||
| private shouldQueue; | ||
| addQueue(payload: ITrackHandlerPayload): void; | ||
| send(payload: ITrackHandlerPayload): Promise<void | { | ||
@@ -67,7 +75,7 @@ deviceId: string; | ||
| sessionId: string; | ||
| } | null>; | ||
| } | null> | undefined; | ||
| /** | ||
| * @deprecated This method is deprecated and will be removed in a future version. | ||
| */ | ||
| alias(payload: IAliasPayload): Promise<void>; | ||
| alias(_payload: IAliasPayload): void; | ||
| increment(payload: IIncrementPayload): Promise<void | { | ||
@@ -74,0 +82,0 @@ deviceId: string; |
+15
-7
@@ -25,7 +25,9 @@ import { ITrackHandlerPayload, IIdentifyPayload, IAliasPayload, IIncrementPayload, IDecrementPayload } from '@openpanel/validation'; | ||
| type TrackProperties = { | ||
| /** biome-ignore-all lint/style/noExportedImports: lazy */ | ||
| interface TrackProperties { | ||
| [key: string]: unknown; | ||
| profileId?: string; | ||
| }; | ||
| type OpenPanelOptions = { | ||
| } | ||
| interface OpenPanelOptions { | ||
| clientId: string; | ||
@@ -36,10 +38,15 @@ clientSecret?: string; | ||
| sdkVersion?: string; | ||
| /** | ||
| * @deprecated Queue events until `identify()` is called with a profileId. | ||
| * For manual queue control use `disabled: true` + `ready()` instead. | ||
| */ | ||
| waitForProfile?: boolean; | ||
| filter?: (payload: ITrackHandlerPayload) => boolean; | ||
| /** When true, events are queued until `ready()` is called (same as waitForProfile). */ | ||
| disabled?: boolean; | ||
| debug?: boolean; | ||
| }; | ||
| } | ||
| declare class OpenPanel { | ||
| api: Api; | ||
| options: OpenPanelOptions; | ||
| api: Api; | ||
| profileId?: string; | ||
@@ -54,2 +61,3 @@ deviceId?: string; | ||
| private shouldQueue; | ||
| addQueue(payload: ITrackHandlerPayload): void; | ||
| send(payload: ITrackHandlerPayload): Promise<void | { | ||
@@ -67,7 +75,7 @@ deviceId: string; | ||
| sessionId: string; | ||
| } | null>; | ||
| } | null> | undefined; | ||
| /** | ||
| * @deprecated This method is deprecated and will be removed in a future version. | ||
| */ | ||
| alias(payload: IAliasPayload): Promise<void>; | ||
| alias(_payload: IAliasPayload): void; | ||
| increment(payload: IIncrementPayload): Promise<void | { | ||
@@ -74,0 +82,0 @@ deviceId: string; |
+1
-1
@@ -1,1 +0,1 @@ | ||
| var a=class{constructor(e){this.baseUrl=e.baseUrl,this.headers={"Content-Type":"application/json",...e.defaultHeaders},this.maxRetries=e.maxRetries??3,this.initialRetryDelay=e.initialRetryDelay??500}async resolveHeaders(){let e={};for(let[r,s]of Object.entries(this.headers)){let t=await s;t!==null&&(e[r]=t)}return e}addHeader(e,r){this.headers[e]=r}async post(e,r,s,t){try{let i=await fetch(e,{method:"POST",headers:await this.resolveHeaders(),body:r?JSON.stringify(r??{}):void 0,keepalive:!0,...s});if(i.status===401)return null;if(i.status!==200&&i.status!==202)throw new Error(`HTTP error! status: ${i.status}`);let n=await i.text();return n?JSON.parse(n):null}catch(i){if(t<this.maxRetries){let n=this.initialRetryDelay*2**t;return await new Promise(l=>setTimeout(l,n)),this.post(e,r,s,t+1)}return console.error("Max retries reached:",i),null}}async fetch(e,r,s={}){let t=`${this.baseUrl}${e}`;return this.post(t,r,s,0)}};var o=class{constructor(e){this.options=e;this.queue=[];let r={"openpanel-client-id":e.clientId};e.clientSecret&&(r["openpanel-client-secret"]=e.clientSecret),r["openpanel-sdk-name"]=e.sdk||"node",r["openpanel-sdk-version"]=e.sdkVersion||"1.1.0",this.api=new a({baseUrl:e.apiUrl||"https://api.openpanel.dev",defaultHeaders:r})}init(){}ready(){this.options.waitForProfile=!1,this.flush()}shouldQueue(e){return!!(e.type==="replay"&&!this.sessionId||this.options.waitForProfile&&!this.profileId)}async send(e){if(this.options.disabled||this.options.filter&&!this.options.filter(e))return Promise.resolve();if(this.shouldQueue(e))return this.queue.push(e),Promise.resolve();let r=await this.api.fetch("/track",e,{keepalive:e.type!=="replay"});this.deviceId=r?.deviceId;let s=!!this.sessionId;return this.sessionId=r?.sessionId,!s&&this.sessionId&&this.flush(),r}setGlobalProperties(e){this.global={...this.global,...e}}async track(e,r){return this.log("track event",e,r),this.send({type:"track",payload:{name:e,profileId:r?.profileId??this.profileId,properties:{...this.global??{},...r??{}}}})}async identify(e){if(this.log("identify user",e),e.profileId&&(this.profileId=e.profileId,this.flush()),Object.keys(e).length>1)return this.send({type:"identify",payload:{...e,properties:{...this.global,...e.properties}}})}async alias(e){}async increment(e){return this.send({type:"increment",payload:e})}async decrement(e){return this.send({type:"decrement",payload:e})}async revenue(e,r){let s=r?.deviceId;return delete r?.deviceId,this.track("revenue",{...r??{},...s?{__deviceId:s}:{},__revenue:e})}getDeviceId(){return this.deviceId??""}getSessionId(){return this.sessionId??""}fetchDeviceId(){return Promise.resolve(this.deviceId??"")}clear(){this.profileId=void 0,this.deviceId=void 0,this.sessionId=void 0}flush(){let e=[];for(let r of this.queue){if(this.shouldQueue(r)){e.push(r);continue}let s=r.type==="replay"?r.payload:{...r.payload,profileId:"profileId"in r.payload?r.payload.profileId??this.profileId:this.profileId};this.send({...r,payload:s})}this.queue=e}log(...e){this.options.debug&&console.log("[OpenPanel.dev]",...e)}};export{o as OpenPanel}; | ||
| var a=class{constructor(e){this.baseUrl=e.baseUrl,this.headers={"Content-Type":"application/json",...e.defaultHeaders},this.maxRetries=e.maxRetries??3,this.initialRetryDelay=e.initialRetryDelay??500}async resolveHeaders(){let e={};for(let[t,r]of Object.entries(this.headers)){let i=await r;i!==null&&(e[t]=i)}return e}addHeader(e,t){this.headers[e]=t}async post(e,t,r,i){try{let s=await fetch(e,{method:"POST",headers:await this.resolveHeaders(),body:t?JSON.stringify(t??{}):void 0,keepalive:!0,...r});if(s.status===401)return null;if(s.status!==200&&s.status!==202)throw new Error(`HTTP error! status: ${s.status}`);let n=await s.text();return n?JSON.parse(n):null}catch(s){if(i<this.maxRetries){let n=this.initialRetryDelay*2**i;return await new Promise(l=>setTimeout(l,n)),this.post(e,t,r,i+1)}return console.error("Max retries reached:",s),null}}async fetch(e,t,r={}){let i=`${this.baseUrl}${e}`;return this.post(i,t,r,0)}};var o=class{constructor(e){this.queue=[];this.options=e;let t={"openpanel-client-id":e.clientId};e.clientSecret&&(t["openpanel-client-secret"]=e.clientSecret),t["openpanel-sdk-name"]=e.sdk||"node",t["openpanel-sdk-version"]=e.sdkVersion||"1.2.0",this.api=new a({baseUrl:e.apiUrl||"https://api.openpanel.dev",defaultHeaders:t})}init(){}ready(){this.options.disabled=!1,this.options.waitForProfile=!1,this.flush()}shouldQueue(e){return!!(this.options.disabled||this.options.waitForProfile&&!this.profileId||e.type==="replay"&&!this.sessionId)}addQueue(e){e.type==="track"&&(e.payload.properties={...e.payload.properties??{},__timestamp:new Date().toISOString()}),this.queue.push(e)}async send(e){if(this.options.filter&&!this.options.filter(e))return Promise.resolve();if(this.shouldQueue(e))return this.addQueue(e),Promise.resolve();let t=await this.api.fetch("/track",e,{keepalive:e.type!=="replay"});this.deviceId=t?.deviceId;let r=!!this.sessionId;return this.sessionId=t?.sessionId,!r&&this.sessionId&&this.flush(),t}setGlobalProperties(e){this.global={...this.global,...e}}track(e,t){return this.log("track event",e,t),this.send({type:"track",payload:{name:e,profileId:t?.profileId??this.profileId,properties:{...this.global??{},...t??{}}}})}identify(e){if(this.log("identify user",e),e.profileId&&(this.profileId=e.profileId,this.flush()),Object.keys(e).length>1)return this.send({type:"identify",payload:{...e,properties:{...this.global,...e.properties}}})}alias(e){}increment(e){return this.send({type:"increment",payload:e})}decrement(e){return this.send({type:"decrement",payload:e})}revenue(e,t){let r=t?.deviceId;return delete t?.deviceId,this.track("revenue",{...t??{},...r?{__deviceId:r}:{},__revenue:e})}getDeviceId(){return this.deviceId??""}getSessionId(){return this.sessionId??""}fetchDeviceId(){return Promise.resolve(this.deviceId??"")}clear(){this.profileId=void 0,this.deviceId=void 0,this.sessionId=void 0}flush(){let e=[];for(let t of this.queue){if(this.shouldQueue(t)){e.push(t);continue}let r=t.type==="replay"?t.payload:{...t.payload,profileId:"profileId"in t.payload?t.payload.profileId??this.profileId:this.profileId};this.send({...t,payload:r})}this.queue=e}log(...e){this.options.debug&&console.log("[OpenPanel.dev]",...e)}};export{o as OpenPanel}; |
+1
-1
| { | ||
| "name": "@openpanel/sdk", | ||
| "version": "1.1.0", | ||
| "version": "1.2.0", | ||
| "module": "./dist/index.js", | ||
@@ -5,0 +5,0 @@ "config": { |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
17348
6.19%126
7.69%