@altertable/altertable-react 0.3.0 → 0.5.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present Altertable
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.d.mts CHANGED
@@ -1,19 +1,32 @@
1
+ import { Altertable } from '@altertable/altertable-js';
2
+ import React, { ReactNode } from 'react';
3
+
4
+ interface AltertableProviderProps {
5
+ client: Altertable;
6
+ children: ReactNode;
7
+ }
8
+ declare function AltertableProvider({ client, children, }: AltertableProviderProps): React.JSX.Element;
9
+
10
+ type FunnelName = string;
1
11
  type FunnelStep = {
2
- name: string;
3
- properties: any;
12
+ name: FunnelName;
13
+ properties?: Record<string, any>;
4
14
  };
5
- type FunnelStepNames<T extends readonly FunnelStep[]> = T[number]['name'];
6
- type FunnelStepProperties<T extends readonly FunnelStep[], N extends FunnelStepNames<T>> = Extract<T[number], {
15
+ type FunnelStepName<T extends readonly FunnelStep[]> = T[number]['name'];
16
+ type FunnelStepProperties<T extends readonly FunnelStep[], N extends FunnelStepName<T>> = Extract<T[number], {
7
17
  name: N;
8
18
  }>['properties'];
9
- type FunnelMapping = Record<string, readonly FunnelStep[]>;
19
+ type FunnelMapping = Record<FunnelName, readonly FunnelStep[]>;
10
20
 
11
- declare const useAltertable: <T extends FunnelMapping>() => {
21
+ declare function useAltertable<T extends FunnelMapping>(): {
22
+ configure: any;
23
+ getTrackingConsent: any;
24
+ identify: any;
25
+ track: <Steps extends T[keyof T] = T[keyof T]>(eventName: FunnelStepName<Steps>, properties?: FunnelStepProperties<Steps, typeof eventName>) => void;
26
+ updateTraits: any;
12
27
  useFunnel: <FunnelName extends keyof T>(_funnelName: FunnelName) => {
13
- track: <Step extends FunnelStepNames<T[FunnelName]>>(step: Step, properties: FunnelStepProperties<T[FunnelName], Step>) => void;
28
+ track: (eventName: FunnelStepName<T[FunnelName]>, properties?: FunnelStepProperties<T[FunnelName], FunnelStepName<T[FunnelName]>>) => void;
14
29
  };
15
- identify: (userId: string) => void;
16
- track: <Step extends FunnelStepNames<T[keyof T]>>(step: Step, properties: FunnelStepProperties<T[keyof T], Step>) => void;
17
30
  };
18
31
 
19
- export { type FunnelMapping, type FunnelStep, type FunnelStepNames, type FunnelStepProperties, useAltertable };
32
+ export { AltertableProvider, type FunnelMapping, type FunnelStep, type FunnelStepName, type FunnelStepProperties, useAltertable };
package/dist/index.d.ts CHANGED
@@ -1,19 +1,32 @@
1
+ import { Altertable } from '@altertable/altertable-js';
2
+ import React, { ReactNode } from 'react';
3
+
4
+ interface AltertableProviderProps {
5
+ client: Altertable;
6
+ children: ReactNode;
7
+ }
8
+ declare function AltertableProvider({ client, children, }: AltertableProviderProps): React.JSX.Element;
9
+
10
+ type FunnelName = string;
1
11
  type FunnelStep = {
2
- name: string;
3
- properties: any;
12
+ name: FunnelName;
13
+ properties?: Record<string, any>;
4
14
  };
5
- type FunnelStepNames<T extends readonly FunnelStep[]> = T[number]['name'];
6
- type FunnelStepProperties<T extends readonly FunnelStep[], N extends FunnelStepNames<T>> = Extract<T[number], {
15
+ type FunnelStepName<T extends readonly FunnelStep[]> = T[number]['name'];
16
+ type FunnelStepProperties<T extends readonly FunnelStep[], N extends FunnelStepName<T>> = Extract<T[number], {
7
17
  name: N;
8
18
  }>['properties'];
9
- type FunnelMapping = Record<string, readonly FunnelStep[]>;
19
+ type FunnelMapping = Record<FunnelName, readonly FunnelStep[]>;
10
20
 
11
- declare const useAltertable: <T extends FunnelMapping>() => {
21
+ declare function useAltertable<T extends FunnelMapping>(): {
22
+ configure: any;
23
+ getTrackingConsent: any;
24
+ identify: any;
25
+ track: <Steps extends T[keyof T] = T[keyof T]>(eventName: FunnelStepName<Steps>, properties?: FunnelStepProperties<Steps, typeof eventName>) => void;
26
+ updateTraits: any;
12
27
  useFunnel: <FunnelName extends keyof T>(_funnelName: FunnelName) => {
13
- track: <Step extends FunnelStepNames<T[FunnelName]>>(step: Step, properties: FunnelStepProperties<T[FunnelName], Step>) => void;
28
+ track: (eventName: FunnelStepName<T[FunnelName]>, properties?: FunnelStepProperties<T[FunnelName], FunnelStepName<T[FunnelName]>>) => void;
14
29
  };
15
- identify: (userId: string) => void;
16
- track: <Step extends FunnelStepNames<T[keyof T]>>(step: Step, properties: FunnelStepProperties<T[keyof T], Step>) => void;
17
30
  };
18
31
 
19
- export { type FunnelMapping, type FunnelStep, type FunnelStepNames, type FunnelStepProperties, useAltertable };
32
+ export { AltertableProvider, type FunnelMapping, type FunnelStep, type FunnelStepName, type FunnelStepProperties, useAltertable };
package/dist/index.js CHANGED
@@ -1,69 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/index.ts
20
- var index_exports = {};
21
- __export(index_exports, {
22
- useAltertable: () => useAltertable
23
- });
24
- module.exports = __toCommonJS(index_exports);
25
-
26
- // src/useAltertable.ts
27
- var import_react = require("react");
28
- var PROPERTY_LIB = "$lib";
29
- var PROPERTY_LIB_VERSION = "$lib_version";
30
- var useAltertable = () => {
31
- const instance = window.Altertable;
32
- const makeTrack = () => {
33
- return (step, properties) => {
34
- try {
35
- instance.track(step, {
36
- ...properties,
37
- // The React library needs to override the lib properties coming from
38
- // the core library
39
- [PROPERTY_LIB]: "@altertable/altertable-react",
40
- [PROPERTY_LIB_VERSION]: "0.3.0"
41
- });
42
- } catch (error) {
43
- console.error("Failed to track event", error);
44
- }
45
- };
46
- };
47
- const useFunnel = (0, import_react.useCallback)(
48
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
49
- (_funnelName) => {
50
- const track2 = (0, import_react.useCallback)(makeTrack(), []);
51
- return { track: track2 };
52
- },
53
- []
54
- );
55
- const track = (0, import_react.useCallback)(makeTrack(), []);
56
- const identify = (0, import_react.useCallback)((userId) => {
57
- try {
58
- instance.identify(userId);
59
- } catch (error) {
60
- console.error("Failed to identify user", error);
61
- }
62
- }, []);
63
- return {
64
- useFunnel,
65
- identify,
66
- track
67
- };
68
- };
1
+ /*! @altertable/altertable-react 0.5.0 | MIT License | Altertable | https://github.com/altertable-ai/altertable-js */
2
+ var x=Object.create;var i=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var T=Object.getPrototypeOf,A=Object.prototype.hasOwnProperty;var N=(e,t)=>{for(var r in t)i(e,r,{get:t[r],enumerable:!0})},s=(e,t,r,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of _(t))!A.call(e,n)&&n!==r&&i(e,n,{get:()=>t[n],enumerable:!(l=P(t,n))||l.enumerable});return e};var R=(e,t,r)=>(r=e!=null?x(T(e)):{},s(t||!e||!e.__esModule?i(r,"default",{value:e,enumerable:!0}):r,e)),y=e=>s(i({},"__esModule",{value:!0}),e);var C={};N(C,{AltertableProvider:()=>m,useAltertable:()=>d});module.exports=y(C);var u=require("@altertable/altertable-js"),o=R(require("react")),p=(0,o.createContext)(u.altertable);p.displayName="AltertableContext";function m({client:e,children:t}){return o.default.createElement(p.Provider,{value:e},t)}function b(){return(0,o.useContext)(p)}var a=require("react");var c="$lib",f="$lib_version";function d(){let e=b(),t=(0,a.useCallback)((l,n={})=>{e.track(l,{...n,[c]:"@altertable/altertable-react",[f]:"0.5.0"})},[e]),r=(0,a.useCallback)(l=>({track:t}),[t]);return(0,a.useMemo)(()=>({configure:e.configure.bind(e),getTrackingConsent:e.getTrackingConsent.bind(e),identify:e.identify.bind(e),track:t,updateTraits:e.updateTraits.bind(e),useFunnel:r}),[e,t,r])}
69
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/useAltertable.ts"],"sourcesContent":["export * from './useAltertable';\nexport type * from './types';\n","import { useCallback } from 'react';\nimport { FunnelMapping, FunnelStepNames, FunnelStepProperties } from './types';\nimport type { Altertable } from '@altertable/altertable-js';\n\nconst PROPERTY_LIB = '$lib';\nconst PROPERTY_LIB_VERSION = '$lib_version';\n\nexport const useAltertable = <T extends FunnelMapping>() => {\n const instance = window.Altertable as Altertable;\n\n const makeTrack = <Steps extends T[keyof T] = T[keyof T]>() => {\n return <Step extends FunnelStepNames<Steps>>(\n step: Step,\n properties: FunnelStepProperties<Steps, Step>\n ) => {\n try {\n instance.track(step, {\n ...properties,\n // The React library needs to override the lib properties coming from\n // the core library\n [PROPERTY_LIB]: __LIB__,\n [PROPERTY_LIB_VERSION]: __LIB_VERSION__,\n });\n } catch (error) {\n console.error('Failed to track event', error);\n }\n };\n };\n\n const useFunnel = useCallback(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n <FunnelName extends keyof T>(_funnelName: FunnelName) => {\n const track = useCallback(makeTrack<T[FunnelName]>(), []);\n return { track };\n },\n []\n );\n\n const track = useCallback(makeTrack(), []);\n\n const identify = useCallback((userId: string) => {\n try {\n instance.identify(userId);\n } catch (error) {\n console.error('Failed to identify user', error);\n }\n }, []);\n\n return {\n useFunnel,\n identify,\n track,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA4B;AAI5B,IAAM,eAAe;AACrB,IAAM,uBAAuB;AAEtB,IAAM,gBAAgB,MAA+B;AAC1D,QAAM,WAAW,OAAO;AAExB,QAAM,YAAY,MAA6C;AAC7D,WAAO,CACL,MACA,eACG;AACH,UAAI;AACF,iBAAS,MAAM,MAAM;AAAA,UACnB,GAAG;AAAA;AAAA;AAAA,UAGH,CAAC,YAAY,GAAG;AAAA,UAChB,CAAC,oBAAoB,GAAG;AAAA,QAC1B,CAAC;AAAA,MACH,SAAS,OAAO;AACd,gBAAQ,MAAM,yBAAyB,KAAK;AAAA,MAC9C;AAAA,IACF;AAAA,EACF;AAEA,QAAM,gBAAY;AAAA;AAAA,IAEhB,CAA6B,gBAA4B;AACvD,YAAMA,aAAQ,0BAAY,UAAyB,GAAG,CAAC,CAAC;AACxD,aAAO,EAAE,OAAAA,OAAM;AAAA,IACjB;AAAA,IACA,CAAC;AAAA,EACH;AAEA,QAAM,YAAQ,0BAAY,UAAU,GAAG,CAAC,CAAC;AAEzC,QAAM,eAAW,0BAAY,CAAC,WAAmB;AAC/C,QAAI;AACF,eAAS,SAAS,MAAM;AAAA,IAC1B,SAAS,OAAO;AACd,cAAQ,MAAM,2BAA2B,KAAK;AAAA,IAChD;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["track"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/AltertableProvider.tsx","../src/useAltertable.ts","../src/constants.ts"],"sourcesContent":["export { AltertableProvider } from './AltertableProvider';\nexport type * from './types';\nexport { useAltertable } from './useAltertable';\n","import { type Altertable, altertable } from '@altertable/altertable-js';\nimport React, { createContext, type ReactNode, useContext } from 'react';\n\nconst AltertableContext = createContext<Altertable>(altertable);\nAltertableContext.displayName = 'AltertableContext';\n\ninterface AltertableProviderProps {\n client: Altertable;\n children: ReactNode;\n}\n\nexport function AltertableProvider({\n client,\n children,\n}: AltertableProviderProps) {\n return (\n <AltertableContext.Provider value={client}>\n {children}\n </AltertableContext.Provider>\n );\n}\n\nexport function useAltertableContext() {\n return useContext(AltertableContext);\n}\n","import { useCallback, useMemo } from 'react';\n\nimport { useAltertableContext } from './AltertableProvider';\nimport { PROPERTY_LIB, PROPERTY_LIB_VERSION } from './constants';\nimport { FunnelMapping, FunnelStepName, FunnelStepProperties } from './types';\n\nexport function useAltertable<T extends FunnelMapping>() {\n const altertable = useAltertableContext();\n\n const track = useCallback(\n <Steps extends T[keyof T] = T[keyof T]>(\n eventName: FunnelStepName<Steps>,\n properties: FunnelStepProperties<Steps, typeof eventName> = {}\n ) => {\n altertable.track(eventName, {\n ...properties,\n // The React library needs to override the lib properties coming from\n // the core library\n [PROPERTY_LIB]: __LIB__,\n [PROPERTY_LIB_VERSION]: __LIB_VERSION__,\n });\n },\n [altertable]\n );\n\n const useFunnel = useCallback(\n <FunnelName extends keyof T>(_funnelName: FunnelName) => ({\n track: track<T[FunnelName]>,\n }),\n [track]\n );\n\n return useMemo(\n () => ({\n configure: altertable.configure.bind(altertable),\n getTrackingConsent: altertable.getTrackingConsent.bind(altertable),\n identify: altertable.identify.bind(altertable),\n track,\n updateTraits: altertable.updateTraits.bind(altertable),\n useFunnel,\n }),\n [altertable, track, useFunnel]\n );\n}\n","export const PROPERTY_LIB = '$lib';\nexport const PROPERTY_LIB_VERSION = '$lib_version';\n"],"mappings":";6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,EAAA,kBAAAC,IAAA,eAAAC,EAAAJ,GCAA,IAAAK,EAA4C,qCAC5CC,EAAiE,oBAE3DC,KAAoB,iBAA0B,YAAU,EAC9DA,EAAkB,YAAc,oBAOzB,SAASC,EAAmB,CACjC,OAAAC,EACA,SAAAC,CACF,EAA4B,CAC1B,OACE,EAAAC,QAAA,cAACJ,EAAkB,SAAlB,CAA2B,MAAOE,GAChCC,CACH,CAEJ,CAEO,SAASE,GAAuB,CACrC,SAAO,cAAWL,CAAiB,CACrC,CCxBA,IAAAM,EAAqC,iBCA9B,IAAMC,EAAe,OACfC,EAAuB,eDK7B,SAASC,GAAyC,CACvD,IAAMC,EAAaC,EAAqB,EAElCC,KAAQ,eACZ,CACEC,EACAC,EAA4D,CAAC,IAC1D,CACHJ,EAAW,MAAMG,EAAW,CAC1B,GAAGC,EAGH,CAACC,CAAY,EAAG,+BAChB,CAACC,CAAoB,EAAG,OAC1B,CAAC,CACH,EACA,CAACN,CAAU,CACb,EAEMO,KAAY,eACaC,IAA6B,CACxD,MAAON,CACT,GACA,CAACA,CAAK,CACR,EAEA,SAAO,WACL,KAAO,CACL,UAAWF,EAAW,UAAU,KAAKA,CAAU,EAC/C,mBAAoBA,EAAW,mBAAmB,KAAKA,CAAU,EACjE,SAAUA,EAAW,SAAS,KAAKA,CAAU,EAC7C,MAAAE,EACA,aAAcF,EAAW,aAAa,KAAKA,CAAU,EACrD,UAAAO,CACF,GACA,CAACP,EAAYE,EAAOK,CAAS,CAC/B,CACF","names":["index_exports","__export","AltertableProvider","useAltertable","__toCommonJS","import_altertable_js","import_react","AltertableContext","AltertableProvider","client","children","React","useAltertableContext","import_react","PROPERTY_LIB","PROPERTY_LIB_VERSION","useAltertable","altertable","useAltertableContext","track","eventName","properties","PROPERTY_LIB","PROPERTY_LIB_VERSION","useFunnel","_funnelName"]}
package/dist/index.mjs CHANGED
@@ -1,47 +1,3 @@
1
- // src/useAltertable.ts
2
- import { useCallback } from "react";
3
- var PROPERTY_LIB = "$lib";
4
- var PROPERTY_LIB_VERSION = "$lib_version";
5
- var useAltertable = () => {
6
- const instance = window.Altertable;
7
- const makeTrack = () => {
8
- return (step, properties) => {
9
- try {
10
- instance.track(step, {
11
- ...properties,
12
- // The React library needs to override the lib properties coming from
13
- // the core library
14
- [PROPERTY_LIB]: "@altertable/altertable-react",
15
- [PROPERTY_LIB_VERSION]: "0.3.0"
16
- });
17
- } catch (error) {
18
- console.error("Failed to track event", error);
19
- }
20
- };
21
- };
22
- const useFunnel = useCallback(
23
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
24
- (_funnelName) => {
25
- const track2 = useCallback(makeTrack(), []);
26
- return { track: track2 };
27
- },
28
- []
29
- );
30
- const track = useCallback(makeTrack(), []);
31
- const identify = useCallback((userId) => {
32
- try {
33
- instance.identify(userId);
34
- } catch (error) {
35
- console.error("Failed to identify user", error);
36
- }
37
- }, []);
38
- return {
39
- useFunnel,
40
- identify,
41
- track
42
- };
43
- };
44
- export {
45
- useAltertable
46
- };
1
+ /*! @altertable/altertable-react 0.5.0 | MIT License | Altertable | https://github.com/altertable-ai/altertable-js */
2
+ import{altertable as u}from"@altertable/altertable-js";import m,{createContext as b,useContext as c}from"react";var r=b(u);r.displayName="AltertableContext";function f({client:e,children:t}){return m.createElement(r.Provider,{value:e},t)}function l(){return c(r)}import{useCallback as p,useMemo as d}from"react";var a="$lib",i="$lib_version";function x(){let e=l(),t=p((o,s={})=>{e.track(o,{...s,[a]:"@altertable/altertable-react",[i]:"0.5.0"})},[e]),n=p(o=>({track:t}),[t]);return d(()=>({configure:e.configure.bind(e),getTrackingConsent:e.getTrackingConsent.bind(e),identify:e.identify.bind(e),track:t,updateTraits:e.updateTraits.bind(e),useFunnel:n}),[e,t,n])}export{f as AltertableProvider,x as useAltertable};
47
3
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/useAltertable.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { FunnelMapping, FunnelStepNames, FunnelStepProperties } from './types';\nimport type { Altertable } from '@altertable/altertable-js';\n\nconst PROPERTY_LIB = '$lib';\nconst PROPERTY_LIB_VERSION = '$lib_version';\n\nexport const useAltertable = <T extends FunnelMapping>() => {\n const instance = window.Altertable as Altertable;\n\n const makeTrack = <Steps extends T[keyof T] = T[keyof T]>() => {\n return <Step extends FunnelStepNames<Steps>>(\n step: Step,\n properties: FunnelStepProperties<Steps, Step>\n ) => {\n try {\n instance.track(step, {\n ...properties,\n // The React library needs to override the lib properties coming from\n // the core library\n [PROPERTY_LIB]: __LIB__,\n [PROPERTY_LIB_VERSION]: __LIB_VERSION__,\n });\n } catch (error) {\n console.error('Failed to track event', error);\n }\n };\n };\n\n const useFunnel = useCallback(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n <FunnelName extends keyof T>(_funnelName: FunnelName) => {\n const track = useCallback(makeTrack<T[FunnelName]>(), []);\n return { track };\n },\n []\n );\n\n const track = useCallback(makeTrack(), []);\n\n const identify = useCallback((userId: string) => {\n try {\n instance.identify(userId);\n } catch (error) {\n console.error('Failed to identify user', error);\n }\n }, []);\n\n return {\n useFunnel,\n identify,\n track,\n };\n};\n"],"mappings":";AAAA,SAAS,mBAAmB;AAI5B,IAAM,eAAe;AACrB,IAAM,uBAAuB;AAEtB,IAAM,gBAAgB,MAA+B;AAC1D,QAAM,WAAW,OAAO;AAExB,QAAM,YAAY,MAA6C;AAC7D,WAAO,CACL,MACA,eACG;AACH,UAAI;AACF,iBAAS,MAAM,MAAM;AAAA,UACnB,GAAG;AAAA;AAAA;AAAA,UAGH,CAAC,YAAY,GAAG;AAAA,UAChB,CAAC,oBAAoB,GAAG;AAAA,QAC1B,CAAC;AAAA,MACH,SAAS,OAAO;AACd,gBAAQ,MAAM,yBAAyB,KAAK;AAAA,MAC9C;AAAA,IACF;AAAA,EACF;AAEA,QAAM,YAAY;AAAA;AAAA,IAEhB,CAA6B,gBAA4B;AACvD,YAAMA,SAAQ,YAAY,UAAyB,GAAG,CAAC,CAAC;AACxD,aAAO,EAAE,OAAAA,OAAM;AAAA,IACjB;AAAA,IACA,CAAC;AAAA,EACH;AAEA,QAAM,QAAQ,YAAY,UAAU,GAAG,CAAC,CAAC;AAEzC,QAAM,WAAW,YAAY,CAAC,WAAmB;AAC/C,QAAI;AACF,eAAS,SAAS,MAAM;AAAA,IAC1B,SAAS,OAAO;AACd,cAAQ,MAAM,2BAA2B,KAAK;AAAA,IAChD;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["track"]}
1
+ {"version":3,"sources":["../src/AltertableProvider.tsx","../src/useAltertable.ts","../src/constants.ts"],"sourcesContent":["import { type Altertable, altertable } from '@altertable/altertable-js';\nimport React, { createContext, type ReactNode, useContext } from 'react';\n\nconst AltertableContext = createContext<Altertable>(altertable);\nAltertableContext.displayName = 'AltertableContext';\n\ninterface AltertableProviderProps {\n client: Altertable;\n children: ReactNode;\n}\n\nexport function AltertableProvider({\n client,\n children,\n}: AltertableProviderProps) {\n return (\n <AltertableContext.Provider value={client}>\n {children}\n </AltertableContext.Provider>\n );\n}\n\nexport function useAltertableContext() {\n return useContext(AltertableContext);\n}\n","import { useCallback, useMemo } from 'react';\n\nimport { useAltertableContext } from './AltertableProvider';\nimport { PROPERTY_LIB, PROPERTY_LIB_VERSION } from './constants';\nimport { FunnelMapping, FunnelStepName, FunnelStepProperties } from './types';\n\nexport function useAltertable<T extends FunnelMapping>() {\n const altertable = useAltertableContext();\n\n const track = useCallback(\n <Steps extends T[keyof T] = T[keyof T]>(\n eventName: FunnelStepName<Steps>,\n properties: FunnelStepProperties<Steps, typeof eventName> = {}\n ) => {\n altertable.track(eventName, {\n ...properties,\n // The React library needs to override the lib properties coming from\n // the core library\n [PROPERTY_LIB]: __LIB__,\n [PROPERTY_LIB_VERSION]: __LIB_VERSION__,\n });\n },\n [altertable]\n );\n\n const useFunnel = useCallback(\n <FunnelName extends keyof T>(_funnelName: FunnelName) => ({\n track: track<T[FunnelName]>,\n }),\n [track]\n );\n\n return useMemo(\n () => ({\n configure: altertable.configure.bind(altertable),\n getTrackingConsent: altertable.getTrackingConsent.bind(altertable),\n identify: altertable.identify.bind(altertable),\n track,\n updateTraits: altertable.updateTraits.bind(altertable),\n useFunnel,\n }),\n [altertable, track, useFunnel]\n );\n}\n","export const PROPERTY_LIB = '$lib';\nexport const PROPERTY_LIB_VERSION = '$lib_version';\n"],"mappings":";AAAA,OAA0B,cAAAA,MAAkB,4BAC5C,OAAOC,GAAS,iBAAAC,EAA+B,cAAAC,MAAkB,QAEjE,IAAMC,EAAoBF,EAA0BF,CAAU,EAC9DI,EAAkB,YAAc,oBAOzB,SAASC,EAAmB,CACjC,OAAAC,EACA,SAAAC,CACF,EAA4B,CAC1B,OACEN,EAAA,cAACG,EAAkB,SAAlB,CAA2B,MAAOE,GAChCC,CACH,CAEJ,CAEO,SAASC,GAAuB,CACrC,OAAOL,EAAWC,CAAiB,CACrC,CCxBA,OAAS,eAAAK,EAAa,WAAAC,MAAe,QCA9B,IAAMC,EAAe,OACfC,EAAuB,eDK7B,SAASC,GAAyC,CACvD,IAAMC,EAAaC,EAAqB,EAElCC,EAAQC,EACZ,CACEC,EACAC,EAA4D,CAAC,IAC1D,CACHL,EAAW,MAAMI,EAAW,CAC1B,GAAGC,EAGH,CAACC,CAAY,EAAG,+BAChB,CAACC,CAAoB,EAAG,OAC1B,CAAC,CACH,EACA,CAACP,CAAU,CACb,EAEMQ,EAAYL,EACaM,IAA6B,CACxD,MAAOP,CACT,GACA,CAACA,CAAK,CACR,EAEA,OAAOQ,EACL,KAAO,CACL,UAAWV,EAAW,UAAU,KAAKA,CAAU,EAC/C,mBAAoBA,EAAW,mBAAmB,KAAKA,CAAU,EACjE,SAAUA,EAAW,SAAS,KAAKA,CAAU,EAC7C,MAAAE,EACA,aAAcF,EAAW,aAAa,KAAKA,CAAU,EACrD,UAAAQ,CACF,GACA,CAACR,EAAYE,EAAOM,CAAS,CAC/B,CACF","names":["altertable","React","createContext","useContext","AltertableContext","AltertableProvider","client","children","useAltertableContext","useCallback","useMemo","PROPERTY_LIB","PROPERTY_LIB_VERSION","useAltertable","altertable","useAltertableContext","track","useCallback","eventName","properties","PROPERTY_LIB","PROPERTY_LIB_VERSION","useFunnel","_funnelName","useMemo"]}
package/package.json CHANGED
@@ -1,65 +1,46 @@
1
1
  {
2
2
  "name": "@altertable/altertable-react",
3
- "version": "0.3.0",
4
3
  "description": "React SDK to capture and send events to Altertable.",
5
- "main": "dist/index.js",
6
- "private": false,
7
- "module": "dist/index.mjs",
8
- "browser": "dist/index.global.js",
9
- "typings": "dist/index.d.ts",
4
+ "version": "0.5.0",
5
+ "license": "MIT",
6
+ "homepage": "https://github.com/altertable-ai/altertable-js",
7
+ "repository": "altertable-ai/altertable-js",
8
+ "author": {
9
+ "name": "Altertable",
10
+ "url": "https://altertable.ai"
11
+ },
10
12
  "keywords": [
11
13
  "analytics",
12
14
  "track",
13
- "react",
14
15
  "altertable"
15
16
  ],
16
- "scripts": {
17
- "dev": "rollup -c --configPlugin typescript --watch",
18
- "clean": "rm -rf dist",
19
- "lint": "eslint src --ext ts",
20
- "build": "tsup",
21
- "test": "vitest --environment=jsdom --watch=false",
22
- "test:watch": "vitest --environment=jsdom"
23
- },
24
17
  "files": [
25
18
  "dist"
26
19
  ],
27
- "repository": {
28
- "type": "git",
29
- "url": "git+https://github.com/altertable-ai/altertable-js"
20
+ "sideEffects": false,
21
+ "main": "dist/index.js",
22
+ "module": "dist/index.mjs",
23
+ "typings": "dist/index.d.ts",
24
+ "scripts": {
25
+ "dev": "tsup --watch --env.mode development",
26
+ "build": "tsup --env.mode production",
27
+ "clean": "rm -rf dist",
28
+ "typecheck": "tsc --noEmit",
29
+ "lint": "eslint src --ext ts",
30
+ "lint:fix": "bun run lint --fix",
31
+ "test": "vitest",
32
+ "test:watch": "vitest --watch"
30
33
  },
31
- "author": "Altertable AI Team",
32
- "license": "MIT",
33
- "homepage": "https://github.com/altertable-ai/altertable-js#readme",
34
34
  "peerDependencies": {
35
- "react": "^16.0 || ^17.0 || ^18.0 || ^19.0"
35
+ "react": "^16.8 || ^17.0 || ^18.0 || ^19.0"
36
36
  },
37
37
  "dependencies": {
38
- "@altertable/altertable-js": "^0.3.0"
38
+ "@altertable/altertable-js": "^0.5.0"
39
39
  },
40
40
  "devDependencies": {
41
- "@testing-library/dom": "^10.4.0",
42
- "@testing-library/react": "^16.2.0",
43
- "@types/node": "^22.13.0",
41
+ "@testing-library/react": "^16.3.0",
44
42
  "@types/react": "^19.0.8",
45
- "@typescript-eslint/eslint-plugin": "^8.22.0",
46
- "@typescript-eslint/parser": "^8.22.0",
47
- "eslint": "^8.57.0",
48
- "eslint-config-love": "^84.0.0",
49
- "eslint-config-prettier": "^10.0.1",
50
- "eslint-plugin-import": "^2.29.1",
51
- "eslint-plugin-n": "^17.15.1",
52
- "eslint-plugin-prettier": "^5.2.1",
53
- "eslint-plugin-promise": "^7.2.1",
54
- "jsdom": "^26.0.0",
55
- "lint-staged": "^15.2.2",
56
- "prettier": "3.5.0",
57
43
  "react": "^19.0.0",
58
- "react-dom": "^19.0.0",
59
- "ts-node": "^10.9.2",
60
- "tslib": "^2.6.2",
61
- "tsup": "^8.3.6",
62
- "typescript": "^5.7.3",
63
- "vitest": "^3.0.4"
44
+ "react-dom": "^19.0.0"
64
45
  }
65
46
  }