@clonus/react-bindings 1.0.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 +21 -0
- package/README.md +191 -0
- package/dist/__tests__/clonus_provider.test.d.ts +2 -0
- package/dist/__tests__/clonus_provider.test.d.ts.map +1 -0
- package/dist/__tests__/setup.d.ts +2 -0
- package/dist/__tests__/setup.d.ts.map +1 -0
- package/dist/__tests__/use_clonus_client.test.d.ts +2 -0
- package/dist/__tests__/use_clonus_client.test.d.ts.map +1 -0
- package/dist/clonus_context.d.ts +8 -0
- package/dist/clonus_context.d.ts.map +1 -0
- package/dist/clonus_provider.d.ts +19 -0
- package/dist/clonus_provider.d.ts.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +160 -0
- package/dist/index.mjs.map +1 -0
- package/dist/noop_clonus_client.d.ts +6 -0
- package/dist/noop_clonus_client.d.ts.map +1 -0
- package/dist/use_client_async_init.d.ts +6 -0
- package/dist/use_client_async_init.d.ts.map +1 -0
- package/dist/use_clonus_client.d.ts +13 -0
- package/dist/use_clonus_client.d.ts.map +1 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Clonus
|
|
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/README.md
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# @clonus/react-bindings
|
|
2
|
+
|
|
3
|
+
React bindings for the Clonus Analytics SDK. This package provides React components and hooks to easily integrate Clonus analytics into your React applications.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @clonus/react-bindings
|
|
9
|
+
# or
|
|
10
|
+
yarn add @clonus/react-bindings
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @clonus/react-bindings
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### Basic Setup with ClonusProvider
|
|
18
|
+
|
|
19
|
+
Wrap your application with the `ClonusProvider` component:
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { ClonusProvider } from '@clonus/react-bindings';
|
|
23
|
+
|
|
24
|
+
function App() {
|
|
25
|
+
return (
|
|
26
|
+
<ClonusProvider
|
|
27
|
+
key="your-api-key"
|
|
28
|
+
user={{
|
|
29
|
+
email: 'user@example.com',
|
|
30
|
+
userID: 'user-123',
|
|
31
|
+
properties: { plan: 'premium' }
|
|
32
|
+
}}
|
|
33
|
+
options={{
|
|
34
|
+
autocapture: { page: true, click: true }
|
|
35
|
+
}}
|
|
36
|
+
>
|
|
37
|
+
<div>Your App Content</div>
|
|
38
|
+
</ClonusProvider>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### With Loading Component
|
|
44
|
+
|
|
45
|
+
You can display a loading component while the client initializes:
|
|
46
|
+
|
|
47
|
+
```tsx
|
|
48
|
+
<ClonusProvider
|
|
49
|
+
key="your-api-key"
|
|
50
|
+
user={{ email: 'user@example.com' }}
|
|
51
|
+
loadingComponent={<div>Loading analytics...</div>}
|
|
52
|
+
>
|
|
53
|
+
<YourApp />
|
|
54
|
+
</ClonusProvider>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Using the Hook
|
|
58
|
+
|
|
59
|
+
Use the `useClonusClient` hook to access the client and send events:
|
|
60
|
+
|
|
61
|
+
```tsx
|
|
62
|
+
import { useClonusClient } from '@clonus/react-bindings';
|
|
63
|
+
|
|
64
|
+
function MyComponent() {
|
|
65
|
+
const { client, send, isLoading } = useClonusClient();
|
|
66
|
+
|
|
67
|
+
const handleClick = () => {
|
|
68
|
+
send('Button Clicked', {
|
|
69
|
+
buttonName: 'Subscribe',
|
|
70
|
+
location: 'header'
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
if (isLoading) {
|
|
75
|
+
return <div>Loading...</div>;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<button onClick={handleClick}>
|
|
80
|
+
Subscribe
|
|
81
|
+
</button>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Advanced: Using Your Own Client Instance
|
|
87
|
+
|
|
88
|
+
You can also pass a pre-configured client instance:
|
|
89
|
+
|
|
90
|
+
```tsx
|
|
91
|
+
import { ClonusClient } from '@clonus/js-client';
|
|
92
|
+
import { ClonusProvider } from '@clonus/react-bindings';
|
|
93
|
+
|
|
94
|
+
const client = new ClonusClient('your-api-key', {
|
|
95
|
+
email: 'user@example.com'
|
|
96
|
+
}, {
|
|
97
|
+
autocapture: { page: true, click: false }
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
function App() {
|
|
101
|
+
return (
|
|
102
|
+
<ClonusProvider client={client}>
|
|
103
|
+
<YourApp />
|
|
104
|
+
</ClonusProvider>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## API Reference
|
|
110
|
+
|
|
111
|
+
### ClonusProvider
|
|
112
|
+
|
|
113
|
+
The main provider component that initializes and manages the Clonus client.
|
|
114
|
+
|
|
115
|
+
#### Props
|
|
116
|
+
|
|
117
|
+
**Configuration-based (recommended):**
|
|
118
|
+
- `key` (string, required): Your Clonus API key
|
|
119
|
+
- `user` (ClonusUser, required): User information
|
|
120
|
+
- `email` (string, required): User's email address
|
|
121
|
+
- `userID` (string, optional): User's unique identifier
|
|
122
|
+
- `properties` (object, optional): Additional user properties
|
|
123
|
+
- `options` (ClonusOptions, optional): SDK configuration options
|
|
124
|
+
- `autocapture.page` (boolean): Enable page view tracking (default: true)
|
|
125
|
+
- `autocapture.click` (boolean): Enable click tracking (default: true)
|
|
126
|
+
- `flush.interval` (number): Event flush interval in ms (default: 10000)
|
|
127
|
+
- `flush.threshold` (number): Event batch size threshold (default: 50)
|
|
128
|
+
- `session.duration` (number): Session duration in ms (default: 1800000)
|
|
129
|
+
- `session.storage` (boolean): Enable session storage (default: true)
|
|
130
|
+
- `children` (ReactNode): Your application components
|
|
131
|
+
- `loadingComponent` (ReactNode, optional): Component to show while initializing
|
|
132
|
+
|
|
133
|
+
**Client-based:**
|
|
134
|
+
- `client` (ClonusClient, required): Pre-configured Clonus client instance
|
|
135
|
+
- `children` (ReactNode): Your application components
|
|
136
|
+
- `loadingComponent` (ReactNode, optional): Component to show while initializing
|
|
137
|
+
|
|
138
|
+
### useClonusClient
|
|
139
|
+
|
|
140
|
+
Hook to access the Clonus client and send events.
|
|
141
|
+
|
|
142
|
+
#### Returns
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
{
|
|
146
|
+
client: ClonusClient; // The Clonus client instance
|
|
147
|
+
send: (event: string, properties?: Record<string, unknown>) => void; // Send an event
|
|
148
|
+
isLoading: boolean; // Whether the client is still initializing
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
#### Example
|
|
153
|
+
|
|
154
|
+
```tsx
|
|
155
|
+
const { client, send, isLoading } = useClonusClient();
|
|
156
|
+
|
|
157
|
+
// Send a custom event
|
|
158
|
+
send('Purchase Completed', {
|
|
159
|
+
amount: 99.99,
|
|
160
|
+
currency: 'USD',
|
|
161
|
+
productId: 'prod-123'
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// Access the full client
|
|
165
|
+
const userEmail = client.getUser().getEmail();
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## TypeScript Support
|
|
169
|
+
|
|
170
|
+
This package is written in TypeScript and includes full type definitions. All types are exported for your convenience:
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
import type {
|
|
174
|
+
ClonusProviderProps,
|
|
175
|
+
ClonusContextValue,
|
|
176
|
+
ClonusUser,
|
|
177
|
+
ClonusOptions,
|
|
178
|
+
ClonusClient
|
|
179
|
+
} from '@clonus/react-bindings';
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Best Practices
|
|
183
|
+
|
|
184
|
+
1. **Place ClonusProvider high in your component tree** - Typically at the root of your application
|
|
185
|
+
2. **Initialize once** - The provider handles client initialization and cleanup automatically
|
|
186
|
+
3. **Use the hook for events** - The `useClonusClient` hook provides optimized event tracking
|
|
187
|
+
4. **Handle loading states** - Use the `isLoading` flag or `loadingComponent` prop for better UX
|
|
188
|
+
|
|
189
|
+
## License
|
|
190
|
+
|
|
191
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clonus_provider.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/clonus_provider.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/__tests__/setup.ts"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use_clonus_client.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/use_clonus_client.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ClonusClient } from '@clonus/js-client';
|
|
2
|
+
export interface ClonusContextValue {
|
|
3
|
+
readonly renderVersion: number;
|
|
4
|
+
readonly client: ClonusClient;
|
|
5
|
+
readonly isLoading: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare const ClonusContext: import("react").Context<ClonusContextValue>;
|
|
8
|
+
//# sourceMappingURL=clonus_context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clonus_context.d.ts","sourceRoot":"","sources":["../src/clonus_context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC7B;AAED,eAAO,MAAM,aAAa,6CAIxB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { ClonusClient, ClonusUser, ClonusOptions } from '@clonus/js-client';
|
|
4
|
+
type WithClient = {
|
|
5
|
+
client: ClonusClient;
|
|
6
|
+
};
|
|
7
|
+
type WithConfiguration = {
|
|
8
|
+
apikey: string;
|
|
9
|
+
user: ClonusUser;
|
|
10
|
+
options?: ClonusOptions;
|
|
11
|
+
};
|
|
12
|
+
type ProviderChildrenProps = {
|
|
13
|
+
children: ReactNode | ReactNode[];
|
|
14
|
+
loadingComponent?: ReactNode | ReactNode[];
|
|
15
|
+
};
|
|
16
|
+
export type ClonusProviderProps = ProviderChildrenProps & (WithClient | WithConfiguration);
|
|
17
|
+
export declare function ClonusProvider(props: ClonusProviderProps): React.ReactElement;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=clonus_provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clonus_provider.d.ts","sourceRoot":"","sources":["../src/clonus_provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAgC,MAAM,OAAO,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAI5E,KAAK,UAAU,GAAG;IAChB,MAAM,EAAE,YAAY,CAAC;CACtB,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,UAAU,CAAC;IACjB,OAAO,CAAC,EAAE,aAAa,CAAC;CACzB,CAAC;AAEF,KAAK,qBAAqB,GAAG;IAC3B,QAAQ,EAAE,SAAS,GAAG,SAAS,EAAE,CAAC;IAClC,gBAAgB,CAAC,EAAE,SAAS,GAAG,SAAS,EAAE,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,qBAAqB,GAAG,CAAC,UAAU,GAAG,iBAAiB,CAAC,CAAC;AAE3F,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,GAAG,KAAK,CAAC,YAAY,CAY7E"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { ClonusContext } from './clonus_context';
|
|
2
|
+
export type { ClonusContextValue } from './clonus_context';
|
|
3
|
+
export { ClonusProvider } from './clonus_provider';
|
|
4
|
+
export type { ClonusProviderProps } from './clonus_provider';
|
|
5
|
+
export { useClonusClient } from './use_clonus_client';
|
|
6
|
+
export { useClientAsyncInit } from './use_client_async_init';
|
|
7
|
+
export { NoopClonusClient, isNoopClient } from './noop_clonus_client';
|
|
8
|
+
export * from '@clonus/js-client';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,YAAY,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,YAAY,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEtE,cAAc,mBAAmB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react"),C=require("react/jsx-runtime"),y=require("@clonus/js-client"),s=()=>{},d=()=>Promise.resolve(),h={initializeAsync:d,info:s,warn:s,error:s,shutdown:d,getUser:()=>({getEmail:()=>"",getUserID:()=>{},getProperties:()=>({}),toJSON:()=>({email:""})}),getOptions:()=>({getApiUrl:()=>"",isPageCaptureEnabled:()=>!1,isClickCaptureEnabled:()=>!1,getFlushInterval:()=>0,getFlushThreshold:()=>0,getSessionDuration:()=>0,isSessionStorageEnabled:()=>!1}),getDevice:()=>({getDeviceID:()=>"",getDeviceInfo:()=>({})}),getSession:()=>({getSessionID:()=>"",getSessionInfo:()=>({})}),getEvent:()=>({enqueue:s,flush:d,destroy:s}),getNetwork:()=>({send:d}),getStorage:()=>({get:()=>null,set:s,remove:s}),getLogger:()=>({debug:s,info:s,warn:s,error:s,capture:(e,t,i)=>{try{return t()}catch{return i()}},swallow:(e,t)=>{try{t()}catch{}}}),getBrowser:()=>!1,isNoop:!0};function b(e){return"isNoop"in e&&e.isNoop===!0}const f=o.createContext({renderVersion:0,client:h,isLoading:!0});let g=null;function S(e){if(g)return g;const t=e.options??{};return t.$sdk={version:"0.0.1",library:"react-bindings"},g=new y.ClonusClient(e.apikey,e.user,t),g}function w(e,t,i){const n=o.useMemo(()=>S({apikey:e,user:t,options:i}),[]),[r,u]=o.useState(!0);return o.useMemo(()=>{n.initializeAsync().catch(l=>{console.error("Failed to initialize Clonus client:",l)}).finally(()=>u(!1))},[n]),{client:n,isLoading:r}}function P(e){return"client"in e?(("apikey"in e||"user"in e)&&console.warn("Both client and configuration props (apikey, user) were provided to ClonusProvider. The client prop will be used and the configuration props will be ignored."),C.jsx(x,{...e})):C.jsx(I,{...e})}function I(e){const[t,i]=o.useState(0),n=w(e.apikey,e.user,e.options).client,[r,u]=o.useState(!p(n));m(n,i,u);const l=o.useMemo(()=>({renderVersion:t,client:n,isLoading:r}),[t,n,r]);return C.jsx(f.Provider,{value:l,children:e.loadingComponent==null||!l.isLoading?e.children:e.loadingComponent})}function x(e){const[t,i]=o.useState(0),n=e.client,[r,u]=o.useState(!p(n));m(n,i,u);const l=o.useMemo(()=>({renderVersion:t,client:n,isLoading:r}),[t,n,r]);return C.jsx(f.Provider,{value:l,children:e.loadingComponent==null||!l.isLoading?e.children:e.loadingComponent})}function m(e,t,i){o.useEffect(()=>()=>{e.shutdown().catch(n=>console.error("An error occurred during shutdown",n))},[e,t,i])}function p(e){return"isNoop"in e}function L(){const{client:e,renderVersion:t,isLoading:i}=o.useContext(f),n=o.useMemo(()=>b(e)?(console.warn("Attempting to retrieve a ClonusClient but none was set."),h):e,[e,t]),r=[n,t],u=o.useCallback((a,c)=>n.info(a,c),r),l=o.useCallback((a,c)=>n.warn(a,c),r),v=o.useCallback((a,c)=>n.error(a,c),r);return o.useMemo(()=>({client:n,info:u,warn:l,error:v,isLoading:i}),[n,u,l,v,i])}exports.ClonusContext=f;exports.ClonusProvider=P;exports.NoopClonusClient=h;exports.isNoopClient=b;exports.useClientAsyncInit=w;exports.useClonusClient=L;Object.keys(y).forEach(e=>{e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:()=>y[e]})});
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/noop_clonus_client.ts","../src/clonus_context.ts","../src/use_client_async_init.ts","../src/clonus_provider.tsx","../src/use_clonus_client.ts"],"sourcesContent":["import { ClonusClient } from '@clonus/js-client';\n\nconst _noop = (): void => {\n // noop\n};\n\nconst _noopAsync = (): Promise<void> => Promise.resolve();\n\nexport const NoopClonusClient = {\n initializeAsync: _noopAsync,\n info: _noop,\n warn: _noop,\n error: _noop,\n shutdown: _noopAsync,\n getUser: () => ({\n getEmail: () => '',\n getUserID: () => undefined,\n getProperties: () => ({}),\n toJSON: () => ({ email: '' }),\n }),\n getOptions: () => ({\n getApiUrl: () => '',\n isPageCaptureEnabled: () => false,\n isClickCaptureEnabled: () => false,\n getFlushInterval: () => 0,\n getFlushThreshold: () => 0,\n getSessionDuration: () => 0,\n isSessionStorageEnabled: () => false,\n }),\n getDevice: () => ({\n getDeviceID: () => '',\n getDeviceInfo: () => ({}),\n }),\n getSession: () => ({\n getSessionID: () => '',\n getSessionInfo: () => ({}),\n }),\n getEvent: () => ({\n enqueue: _noop,\n flush: _noopAsync,\n destroy: _noop,\n }),\n getNetwork: () => ({\n send: _noopAsync,\n }),\n getStorage: () => ({\n get: () => null,\n set: _noop,\n remove: _noop,\n }),\n getLogger: () => ({\n debug: _noop,\n info: _noop,\n warn: _noop,\n error: _noop,\n capture: <T>(tag: string, task: () => T, recover: () => T) => {\n try {\n return task();\n } catch {\n return recover();\n }\n },\n swallow: <T>(tag: string, task: () => T) => {\n try {\n task();\n } catch {\n // swallow\n }\n },\n }),\n getBrowser: () => false,\n isNoop: true,\n} as unknown as ClonusClient & { isNoop: true };\n\nexport function isNoopClient(\n client: ClonusClient | typeof NoopClonusClient\n): client is typeof NoopClonusClient {\n return 'isNoop' in client && client.isNoop === true;\n}\n","import { createContext } from 'react';\nimport { ClonusClient } from '@clonus/js-client';\nimport { NoopClonusClient } from './noop_clonus_client';\n\nexport interface ClonusContextValue {\n readonly renderVersion: number;\n readonly client: ClonusClient;\n readonly isLoading: boolean;\n}\n\nexport const ClonusContext = createContext<ClonusContextValue>({\n renderVersion: 0,\n client: NoopClonusClient,\n isLoading: true,\n});\n","import { useMemo, useState } from 'react';\nimport { ClonusClient, ClonusUser, ClonusOptions } from '@clonus/js-client';\n\ntype FactoryArgs = {\n apikey: string;\n user: ClonusUser;\n options?: ClonusOptions;\n};\n\nlet globalClientInstance: ClonusClient | null = null;\n\nfunction getOrCreateClient(args: FactoryArgs): ClonusClient {\n if (globalClientInstance) {\n return globalClientInstance;\n }\n const options: ClonusOptions = args.options ?? {};\n options.$sdk = { version: '0.0.1', library: 'react-bindings' };\n globalClientInstance = new ClonusClient(args.apikey, args.user, options);\n return globalClientInstance;\n}\n\nexport function useClientAsyncInit(\n apikey: string,\n user: ClonusUser,\n options?: ClonusOptions\n): { isLoading: boolean; client: ClonusClient } {\n const client = useMemo(() => getOrCreateClient({ apikey, user, options }), []);\n\n const [isLoading, setIsLoading] = useState(true);\n\n useMemo(() => {\n client\n .initializeAsync()\n .catch((err: unknown) => {\n console.error('Failed to initialize Clonus client:', err);\n })\n .finally(() => setIsLoading(false));\n }, [client]);\n\n return { client, isLoading };\n}\n","import * as React from 'react';\nimport { ReactNode, useEffect, useMemo, useState } from 'react';\nimport { ClonusClient, ClonusUser, ClonusOptions } from '@clonus/js-client';\nimport { ClonusContext } from './clonus_context';\nimport { useClientAsyncInit } from './use_client_async_init';\n\ntype WithClient = {\n client: ClonusClient;\n};\n\ntype WithConfiguration = {\n apikey: string;\n user: ClonusUser;\n options?: ClonusOptions;\n};\n\ntype ProviderChildrenProps = {\n children: ReactNode | ReactNode[];\n loadingComponent?: ReactNode | ReactNode[];\n};\n\nexport type ClonusProviderProps = ProviderChildrenProps & (WithClient | WithConfiguration);\n\nexport function ClonusProvider(props: ClonusProviderProps): React.ReactElement {\n if (!('client' in props)) {\n return <ConfigBasedClonusProvider {...props} />;\n }\n\n if ('apikey' in props || 'user' in props) {\n console.warn(\n 'Both client and configuration props (apikey, user) were provided to ClonusProvider. The client prop will be used and the configuration props will be ignored.'\n );\n }\n\n return <ClientBasedClonusProvider {...props} />;\n}\n\nfunction ConfigBasedClonusProvider(\n props: WithConfiguration & ProviderChildrenProps\n): React.ReactElement {\n const [renderVersion, setRenderVersion] = useState(0);\n const client = useClientAsyncInit(props.apikey, props.user, props.options).client;\n const [isLoading, setIsLoading] = useState(!_isReady(client));\n\n useClonusClientSetup(client, setRenderVersion, setIsLoading);\n\n const contextValue = useMemo(\n () => ({\n renderVersion,\n client,\n isLoading,\n }),\n [renderVersion, client, isLoading]\n );\n\n return (\n <ClonusContext.Provider value={contextValue}>\n {props.loadingComponent == null || !contextValue.isLoading\n ? props.children\n : props.loadingComponent}\n </ClonusContext.Provider>\n );\n}\n\nfunction ClientBasedClonusProvider(props: WithClient & ProviderChildrenProps): React.ReactElement {\n const [renderVersion, setRenderVersion] = useState(0);\n const client = props.client;\n const [isLoading, setIsLoading] = useState(!_isReady(client));\n\n useClonusClientSetup(client, setRenderVersion, setIsLoading);\n\n const contextValue = useMemo(\n () => ({\n renderVersion,\n client,\n isLoading,\n }),\n [renderVersion, client, isLoading]\n );\n\n return (\n <ClonusContext.Provider value={contextValue}>\n {props.loadingComponent == null || !contextValue.isLoading\n ? props.children\n : props.loadingComponent}\n </ClonusContext.Provider>\n );\n}\n\nfunction useClonusClientSetup(\n client: ClonusClient,\n setRenderVersion: React.Dispatch<React.SetStateAction<number>>,\n setIsLoading: React.Dispatch<React.SetStateAction<boolean>>\n): void {\n useEffect(() => {\n return () => {\n client\n .shutdown()\n .catch((err: unknown) => console.error('An error occurred during shutdown', err));\n };\n }, [client, setRenderVersion, setIsLoading]);\n}\n\nfunction _isReady(client: ClonusClient | { isNoop: true }): boolean {\n if ('isNoop' in client) {\n return true;\n }\n\n return false;\n}\n","import { useCallback, useContext, useMemo } from 'react';\nimport { ClonusClient } from '@clonus/js-client';\nimport { ClonusContext } from './clonus_context';\nimport { NoopClonusClient, isNoopClient } from './noop_clonus_client';\n\ntype HostedFuncs = {\n info: (message: string, properties?: Record<string, unknown>) => void;\n warn: (message: string, properties?: Record<string, unknown>) => void;\n error: (message: string, properties?: Record<string, unknown>) => void;\n};\n\ntype Output = HostedFuncs & {\n client: ClonusClient;\n isLoading: boolean;\n};\n\nexport function useClonusClient(): Output {\n const { client: anyClient, renderVersion, isLoading } = useContext(ClonusContext);\n\n const client = useMemo(() => {\n if (isNoopClient(anyClient)) {\n console.warn('Attempting to retrieve a ClonusClient but none was set.');\n return NoopClonusClient;\n }\n\n return anyClient;\n }, [anyClient, renderVersion]);\n\n const deps = [client, renderVersion];\n\n const info: HostedFuncs['info'] = useCallback(\n (message: string, properties?: Record<string, unknown>) => {\n return client.info(message, properties);\n },\n deps\n );\n\n const warn: HostedFuncs['warn'] = useCallback(\n (message: string, properties?: Record<string, unknown>) => {\n return client.warn(message, properties);\n },\n deps\n );\n\n const error: HostedFuncs['error'] = useCallback(\n (message: string, properties?: Record<string, unknown>) => {\n return client.error(message, properties);\n },\n deps\n );\n\n return useMemo(() => {\n return {\n client,\n info,\n warn,\n error,\n isLoading,\n };\n }, [client, info, warn, error, isLoading]);\n}\n"],"names":["_noop","_noopAsync","NoopClonusClient","tag","task","recover","isNoopClient","client","ClonusContext","createContext","globalClientInstance","getOrCreateClient","args","options","ClonusClient","useClientAsyncInit","apikey","user","useMemo","isLoading","setIsLoading","useState","err","ClonusProvider","props","jsx","ClientBasedClonusProvider","ConfigBasedClonusProvider","renderVersion","setRenderVersion","_isReady","useClonusClientSetup","contextValue","useEffect","useClonusClient","anyClient","useContext","deps","info","useCallback","message","properties","warn","error"],"mappings":"uKAEMA,EAAQ,IAAY,CAE1B,EAEMC,EAAa,IAAqB,QAAQ,QAAA,EAEnCC,EAAmB,CAC9B,gBAAiBD,EACjB,KAAMD,EACN,KAAMA,EACN,MAAOA,EACP,SAAUC,EACV,QAAS,KAAO,CACd,SAAU,IAAM,GAChB,UAAW,IAAA,GACX,cAAe,KAAO,CAAA,GACtB,OAAQ,KAAO,CAAE,MAAO,EAAA,EAAG,GAE7B,WAAY,KAAO,CACjB,UAAW,IAAM,GACjB,qBAAsB,IAAM,GAC5B,sBAAuB,IAAM,GAC7B,iBAAkB,IAAM,EACxB,kBAAmB,IAAM,EACzB,mBAAoB,IAAM,EAC1B,wBAAyB,IAAM,EAAA,GAEjC,UAAW,KAAO,CAChB,YAAa,IAAM,GACnB,cAAe,KAAO,CAAA,EAAC,GAEzB,WAAY,KAAO,CACjB,aAAc,IAAM,GACpB,eAAgB,KAAO,CAAA,EAAC,GAE1B,SAAU,KAAO,CACf,QAASD,EACT,MAAOC,EACP,QAASD,CAAA,GAEX,WAAY,KAAO,CACjB,KAAMC,CAAA,GAER,WAAY,KAAO,CACjB,IAAK,IAAM,KACX,IAAKD,EACL,OAAQA,CAAA,GAEV,UAAW,KAAO,CAChB,MAAOA,EACP,KAAMA,EACN,KAAMA,EACN,MAAOA,EACP,QAAS,CAAIG,EAAaC,EAAeC,IAAqB,CAC5D,GAAI,CACF,OAAOD,EAAA,CACT,MAAQ,CACN,OAAOC,EAAA,CACT,CACF,EACA,QAAS,CAAIF,EAAaC,IAAkB,CAC1C,GAAI,CACFA,EAAA,CACF,MAAQ,CAER,CACF,CAAA,GAEF,WAAY,IAAM,GAClB,OAAQ,EACV,EAEO,SAASE,EACdC,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EAC/DjC,GAGFiC,EACN,CAACA,EAAWP,CAAa,CAAC,EAEvBS,EAAO,CAAC9B,EAAQqB,CAAa,EAE7BU,EAA4BC,EAAAA,YAChC,CAACC,EAAiBC,IACTlC,EAAO,KAAKiC,EAASC,CAAU,EAExCJ,CAAA,EAGIK,EAA4BH,EAAAA,YAChC,CAACC,EAAiBC,IACTlC,EAAO,KAAKiC,EAASC,CAAU,EAExCJ,CAAA,EAGIM,EAA8BJ,EAAAA,YAClC,CAACC,EAAiBC,IACTlC,EAAO,MAAMiC,EAASC,CAAU,EAEzCJ,CAAA,EAGF,OAAOnB,EAAAA,QAAQ,KACN,CACL,OAAAX,EACA,KAAA+B,EACA,KAAAI,EACA,MAAAC,EACA,UAAAxB,CAAA,GAED,CAACZ,EAAQ+B,EAAMI,EAAMC,EAAOxB,CAAS,CAAC,CAC3C"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { createContext as b, useMemo as u, useState as d, useEffect as I, useContext as L, useCallback as h } from "react";
|
|
2
|
+
import { jsx as C } from "react/jsx-runtime";
|
|
3
|
+
import { ClonusClient as S } from "@clonus/js-client";
|
|
4
|
+
export * from "@clonus/js-client";
|
|
5
|
+
const r = () => {
|
|
6
|
+
}, g = () => Promise.resolve(), m = {
|
|
7
|
+
initializeAsync: g,
|
|
8
|
+
info: r,
|
|
9
|
+
warn: r,
|
|
10
|
+
error: r,
|
|
11
|
+
shutdown: g,
|
|
12
|
+
getUser: () => ({
|
|
13
|
+
getEmail: () => "",
|
|
14
|
+
getUserID: () => {
|
|
15
|
+
},
|
|
16
|
+
getProperties: () => ({}),
|
|
17
|
+
toJSON: () => ({ email: "" })
|
|
18
|
+
}),
|
|
19
|
+
getOptions: () => ({
|
|
20
|
+
getApiUrl: () => "",
|
|
21
|
+
isPageCaptureEnabled: () => !1,
|
|
22
|
+
isClickCaptureEnabled: () => !1,
|
|
23
|
+
getFlushInterval: () => 0,
|
|
24
|
+
getFlushThreshold: () => 0,
|
|
25
|
+
getSessionDuration: () => 0,
|
|
26
|
+
isSessionStorageEnabled: () => !1
|
|
27
|
+
}),
|
|
28
|
+
getDevice: () => ({
|
|
29
|
+
getDeviceID: () => "",
|
|
30
|
+
getDeviceInfo: () => ({})
|
|
31
|
+
}),
|
|
32
|
+
getSession: () => ({
|
|
33
|
+
getSessionID: () => "",
|
|
34
|
+
getSessionInfo: () => ({})
|
|
35
|
+
}),
|
|
36
|
+
getEvent: () => ({
|
|
37
|
+
enqueue: r,
|
|
38
|
+
flush: g,
|
|
39
|
+
destroy: r
|
|
40
|
+
}),
|
|
41
|
+
getNetwork: () => ({
|
|
42
|
+
send: g
|
|
43
|
+
}),
|
|
44
|
+
getStorage: () => ({
|
|
45
|
+
get: () => null,
|
|
46
|
+
set: r,
|
|
47
|
+
remove: r
|
|
48
|
+
}),
|
|
49
|
+
getLogger: () => ({
|
|
50
|
+
debug: r,
|
|
51
|
+
info: r,
|
|
52
|
+
warn: r,
|
|
53
|
+
error: r,
|
|
54
|
+
capture: (e, t, o) => {
|
|
55
|
+
try {
|
|
56
|
+
return t();
|
|
57
|
+
} catch {
|
|
58
|
+
return o();
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
swallow: (e, t) => {
|
|
62
|
+
try {
|
|
63
|
+
t();
|
|
64
|
+
} catch {
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}),
|
|
68
|
+
getBrowser: () => !1,
|
|
69
|
+
isNoop: !0
|
|
70
|
+
};
|
|
71
|
+
function P(e) {
|
|
72
|
+
return "isNoop" in e && e.isNoop === !0;
|
|
73
|
+
}
|
|
74
|
+
const v = b({
|
|
75
|
+
renderVersion: 0,
|
|
76
|
+
client: m,
|
|
77
|
+
isLoading: !0
|
|
78
|
+
});
|
|
79
|
+
let f = null;
|
|
80
|
+
function k(e) {
|
|
81
|
+
if (f)
|
|
82
|
+
return f;
|
|
83
|
+
const t = e.options ?? {};
|
|
84
|
+
return t.$sdk = { version: "0.0.1", library: "react-bindings" }, f = new S(e.apikey, e.user, t), f;
|
|
85
|
+
}
|
|
86
|
+
function x(e, t, o) {
|
|
87
|
+
const n = u(() => k({ apikey: e, user: t, options: o }), []), [i, l] = d(!0);
|
|
88
|
+
return u(() => {
|
|
89
|
+
n.initializeAsync().catch((s) => {
|
|
90
|
+
console.error("Failed to initialize Clonus client:", s);
|
|
91
|
+
}).finally(() => l(!1));
|
|
92
|
+
}, [n]), { client: n, isLoading: i };
|
|
93
|
+
}
|
|
94
|
+
function B(e) {
|
|
95
|
+
return "client" in e ? (("apikey" in e || "user" in e) && console.warn(
|
|
96
|
+
"Both client and configuration props (apikey, user) were provided to ClonusProvider. The client prop will be used and the configuration props will be ignored."
|
|
97
|
+
), /* @__PURE__ */ C(V, { ...e })) : /* @__PURE__ */ C(N, { ...e });
|
|
98
|
+
}
|
|
99
|
+
function N(e) {
|
|
100
|
+
const [t, o] = d(0), n = x(e.apikey, e.user, e.options).client, [i, l] = d(!y(n));
|
|
101
|
+
p(n, o, l);
|
|
102
|
+
const s = u(
|
|
103
|
+
() => ({
|
|
104
|
+
renderVersion: t,
|
|
105
|
+
client: n,
|
|
106
|
+
isLoading: i
|
|
107
|
+
}),
|
|
108
|
+
[t, n, i]
|
|
109
|
+
);
|
|
110
|
+
return /* @__PURE__ */ C(v.Provider, { value: s, children: e.loadingComponent == null || !s.isLoading ? e.children : e.loadingComponent });
|
|
111
|
+
}
|
|
112
|
+
function V(e) {
|
|
113
|
+
const [t, o] = d(0), n = e.client, [i, l] = d(!y(n));
|
|
114
|
+
p(n, o, l);
|
|
115
|
+
const s = u(
|
|
116
|
+
() => ({
|
|
117
|
+
renderVersion: t,
|
|
118
|
+
client: n,
|
|
119
|
+
isLoading: i
|
|
120
|
+
}),
|
|
121
|
+
[t, n, i]
|
|
122
|
+
);
|
|
123
|
+
return /* @__PURE__ */ C(v.Provider, { value: s, children: e.loadingComponent == null || !s.isLoading ? e.children : e.loadingComponent });
|
|
124
|
+
}
|
|
125
|
+
function p(e, t, o) {
|
|
126
|
+
I(() => () => {
|
|
127
|
+
e.shutdown().catch((n) => console.error("An error occurred during shutdown", n));
|
|
128
|
+
}, [e, t, o]);
|
|
129
|
+
}
|
|
130
|
+
function y(e) {
|
|
131
|
+
return "isNoop" in e;
|
|
132
|
+
}
|
|
133
|
+
function z() {
|
|
134
|
+
const { client: e, renderVersion: t, isLoading: o } = L(v), n = u(() => P(e) ? (console.warn("Attempting to retrieve a ClonusClient but none was set."), m) : e, [e, t]), i = [n, t], l = h(
|
|
135
|
+
(a, c) => n.info(a, c),
|
|
136
|
+
i
|
|
137
|
+
), s = h(
|
|
138
|
+
(a, c) => n.warn(a, c),
|
|
139
|
+
i
|
|
140
|
+
), w = h(
|
|
141
|
+
(a, c) => n.error(a, c),
|
|
142
|
+
i
|
|
143
|
+
);
|
|
144
|
+
return u(() => ({
|
|
145
|
+
client: n,
|
|
146
|
+
info: l,
|
|
147
|
+
warn: s,
|
|
148
|
+
error: w,
|
|
149
|
+
isLoading: o
|
|
150
|
+
}), [n, l, s, w, o]);
|
|
151
|
+
}
|
|
152
|
+
export {
|
|
153
|
+
v as ClonusContext,
|
|
154
|
+
B as ClonusProvider,
|
|
155
|
+
m as NoopClonusClient,
|
|
156
|
+
P as isNoopClient,
|
|
157
|
+
x as useClientAsyncInit,
|
|
158
|
+
z as useClonusClient
|
|
159
|
+
};
|
|
160
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/noop_clonus_client.ts","../src/clonus_context.ts","../src/use_client_async_init.ts","../src/clonus_provider.tsx","../src/use_clonus_client.ts"],"sourcesContent":["import { ClonusClient } from '@clonus/js-client';\n\nconst _noop = (): void => {\n // noop\n};\n\nconst _noopAsync = (): Promise<void> => Promise.resolve();\n\nexport const NoopClonusClient = {\n initializeAsync: _noopAsync,\n info: _noop,\n warn: _noop,\n error: _noop,\n shutdown: _noopAsync,\n getUser: () => ({\n getEmail: () => '',\n getUserID: () => undefined,\n getProperties: () => ({}),\n toJSON: () => ({ email: '' }),\n }),\n getOptions: () => ({\n getApiUrl: () => '',\n isPageCaptureEnabled: () => false,\n isClickCaptureEnabled: () => false,\n getFlushInterval: () => 0,\n getFlushThreshold: () => 0,\n getSessionDuration: () => 0,\n isSessionStorageEnabled: () => false,\n }),\n getDevice: () => ({\n getDeviceID: () => '',\n getDeviceInfo: () => ({}),\n }),\n getSession: () => ({\n getSessionID: () => '',\n getSessionInfo: () => ({}),\n }),\n getEvent: () => ({\n enqueue: _noop,\n flush: _noopAsync,\n destroy: _noop,\n }),\n getNetwork: () => ({\n send: _noopAsync,\n }),\n getStorage: () => ({\n get: () => null,\n set: _noop,\n remove: _noop,\n }),\n getLogger: () => ({\n debug: _noop,\n info: _noop,\n warn: _noop,\n error: _noop,\n capture: <T>(tag: string, task: () => T, recover: () => T) => {\n try {\n return task();\n } catch {\n return recover();\n }\n },\n swallow: <T>(tag: string, task: () => T) => {\n try {\n task();\n } catch {\n // swallow\n }\n },\n }),\n getBrowser: () => false,\n isNoop: true,\n} as unknown as ClonusClient & { isNoop: true };\n\nexport function isNoopClient(\n client: ClonusClient | typeof NoopClonusClient\n): client is typeof NoopClonusClient {\n return 'isNoop' in client && client.isNoop === true;\n}\n","import { createContext } from 'react';\nimport { ClonusClient } from '@clonus/js-client';\nimport { NoopClonusClient } from './noop_clonus_client';\n\nexport interface ClonusContextValue {\n readonly renderVersion: number;\n readonly client: ClonusClient;\n readonly isLoading: boolean;\n}\n\nexport const ClonusContext = createContext<ClonusContextValue>({\n renderVersion: 0,\n client: NoopClonusClient,\n isLoading: true,\n});\n","import { useMemo, useState } from 'react';\nimport { ClonusClient, ClonusUser, ClonusOptions } from '@clonus/js-client';\n\ntype FactoryArgs = {\n apikey: string;\n user: ClonusUser;\n options?: ClonusOptions;\n};\n\nlet globalClientInstance: ClonusClient | null = null;\n\nfunction getOrCreateClient(args: FactoryArgs): ClonusClient {\n if (globalClientInstance) {\n return globalClientInstance;\n }\n const options: ClonusOptions = args.options ?? {};\n options.$sdk = { version: '0.0.1', library: 'react-bindings' };\n globalClientInstance = new ClonusClient(args.apikey, args.user, options);\n return globalClientInstance;\n}\n\nexport function useClientAsyncInit(\n apikey: string,\n user: ClonusUser,\n options?: ClonusOptions\n): { isLoading: boolean; client: ClonusClient } {\n const client = useMemo(() => getOrCreateClient({ apikey, user, options }), []);\n\n const [isLoading, setIsLoading] = useState(true);\n\n useMemo(() => {\n client\n .initializeAsync()\n .catch((err: unknown) => {\n console.error('Failed to initialize Clonus client:', err);\n })\n .finally(() => setIsLoading(false));\n }, [client]);\n\n return { client, isLoading };\n}\n","import * as React from 'react';\nimport { ReactNode, useEffect, useMemo, useState } from 'react';\nimport { ClonusClient, ClonusUser, ClonusOptions } from '@clonus/js-client';\nimport { ClonusContext } from './clonus_context';\nimport { useClientAsyncInit } from './use_client_async_init';\n\ntype WithClient = {\n client: ClonusClient;\n};\n\ntype WithConfiguration = {\n apikey: string;\n user: ClonusUser;\n options?: ClonusOptions;\n};\n\ntype ProviderChildrenProps = {\n children: ReactNode | ReactNode[];\n loadingComponent?: ReactNode | ReactNode[];\n};\n\nexport type ClonusProviderProps = ProviderChildrenProps & (WithClient | WithConfiguration);\n\nexport function ClonusProvider(props: ClonusProviderProps): React.ReactElement {\n if (!('client' in props)) {\n return <ConfigBasedClonusProvider {...props} />;\n }\n\n if ('apikey' in props || 'user' in props) {\n console.warn(\n 'Both client and configuration props (apikey, user) were provided to ClonusProvider. The client prop will be used and the configuration props will be ignored.'\n );\n }\n\n return <ClientBasedClonusProvider {...props} />;\n}\n\nfunction ConfigBasedClonusProvider(\n props: WithConfiguration & ProviderChildrenProps\n): React.ReactElement {\n const [renderVersion, setRenderVersion] = useState(0);\n const client = useClientAsyncInit(props.apikey, props.user, props.options).client;\n const [isLoading, setIsLoading] = useState(!_isReady(client));\n\n useClonusClientSetup(client, setRenderVersion, setIsLoading);\n\n const contextValue = useMemo(\n () => ({\n renderVersion,\n client,\n isLoading,\n }),\n [renderVersion, client, isLoading]\n );\n\n return (\n <ClonusContext.Provider value={contextValue}>\n {props.loadingComponent == null || !contextValue.isLoading\n ? props.children\n : props.loadingComponent}\n </ClonusContext.Provider>\n );\n}\n\nfunction ClientBasedClonusProvider(props: WithClient & ProviderChildrenProps): React.ReactElement {\n const [renderVersion, setRenderVersion] = useState(0);\n const client = props.client;\n const [isLoading, setIsLoading] = useState(!_isReady(client));\n\n useClonusClientSetup(client, setRenderVersion, setIsLoading);\n\n const contextValue = useMemo(\n () => ({\n renderVersion,\n client,\n isLoading,\n }),\n [renderVersion, client, isLoading]\n );\n\n return (\n <ClonusContext.Provider value={contextValue}>\n {props.loadingComponent == null || !contextValue.isLoading\n ? props.children\n : props.loadingComponent}\n </ClonusContext.Provider>\n );\n}\n\nfunction useClonusClientSetup(\n client: ClonusClient,\n setRenderVersion: React.Dispatch<React.SetStateAction<number>>,\n setIsLoading: React.Dispatch<React.SetStateAction<boolean>>\n): void {\n useEffect(() => {\n return () => {\n client\n .shutdown()\n .catch((err: unknown) => console.error('An error occurred during shutdown', err));\n };\n }, [client, setRenderVersion, setIsLoading]);\n}\n\nfunction _isReady(client: ClonusClient | { isNoop: true }): boolean {\n if ('isNoop' in client) {\n return true;\n }\n\n return false;\n}\n","import { useCallback, useContext, useMemo } from 'react';\nimport { ClonusClient } from '@clonus/js-client';\nimport { ClonusContext } from './clonus_context';\nimport { NoopClonusClient, isNoopClient } from './noop_clonus_client';\n\ntype HostedFuncs = {\n info: (message: string, properties?: Record<string, unknown>) => void;\n warn: (message: string, properties?: Record<string, unknown>) => void;\n error: (message: string, properties?: Record<string, unknown>) => void;\n};\n\ntype Output = HostedFuncs & {\n client: ClonusClient;\n isLoading: boolean;\n};\n\nexport function useClonusClient(): Output {\n const { client: anyClient, renderVersion, isLoading } = useContext(ClonusContext);\n\n const client = useMemo(() => {\n if (isNoopClient(anyClient)) {\n console.warn('Attempting to retrieve a ClonusClient but none was set.');\n return NoopClonusClient;\n }\n\n return anyClient;\n }, [anyClient, renderVersion]);\n\n const deps = [client, renderVersion];\n\n const info: HostedFuncs['info'] = useCallback(\n (message: string, properties?: Record<string, unknown>) => {\n return client.info(message, properties);\n },\n deps\n );\n\n const warn: HostedFuncs['warn'] = useCallback(\n (message: string, properties?: Record<string, unknown>) => {\n return client.warn(message, properties);\n },\n deps\n );\n\n const error: HostedFuncs['error'] = useCallback(\n (message: string, properties?: Record<string, unknown>) => {\n return client.error(message, properties);\n },\n deps\n );\n\n return useMemo(() => {\n return {\n client,\n info,\n warn,\n error,\n isLoading,\n };\n }, [client, info, warn, error, isLoading]);\n}\n"],"names":["_noop","_noopAsync","NoopClonusClient","tag","task","recover","isNoopClient","client","ClonusContext","createContext","globalClientInstance","getOrCreateClient","args","options","ClonusClient","useClientAsyncInit","apikey","user","useMemo","isLoading","setIsLoading","useState","err","ClonusProvider","props","jsx","ClientBasedClonusProvider","ConfigBasedClonusProvider","renderVersion","setRenderVersion","_isReady","useClonusClientSetup","contextValue","useEffect","useClonusClient","anyClient","useContext","deps","info","useCallback","message","properties","warn","error"],"mappings":";;;;AAEA,MAAMA,IAAQ,MAAY;AAE1B,GAEMC,IAAa,MAAqB,QAAQ,QAAA,GAEnCC,IAAmB;AAAA,EAC9B,iBAAiBD;AAAA,EACjB,MAAMD;AAAA,EACN,MAAMA;AAAA,EACN,OAAOA;AAAA,EACP,UAAUC;AAAA,EACV,SAAS,OAAO;AAAA,IACd,UAAU,MAAM;AAAA,IAChB,WAAW,MAAA;AAAA;AAAA,IACX,eAAe,OAAO,CAAA;AAAA,IACtB,QAAQ,OAAO,EAAE,OAAO,GAAA;AAAA,EAAG;AAAA,EAE7B,YAAY,OAAO;AAAA,IACjB,WAAW,MAAM;AAAA,IACjB,sBAAsB,MAAM;AAAA,IAC5B,uBAAuB,MAAM;AAAA,IAC7B,kBAAkB,MAAM;AAAA,IACxB,mBAAmB,MAAM;AAAA,IACzB,oBAAoB,MAAM;A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,CAAU;AAAA,IAExCJ;AAAA,EAAA,GAGIM,IAA8BJ;AAAA,IAClC,CAACC,GAAiBC,MACTlC,EAAO,MAAMiC,GAASC,CAAU;AAAA,IAEzCJ;AAAA,EAAA;AAGF,SAAOnB,EAAQ,OACN;AAAA,IACL,QAAAX;AAAA,IACA,MAAA+B;AAAA,IACA,MAAAI;AAAA,IACA,OAAAC;AAAA,IACA,WAAAxB;AAAA,EAAA,IAED,CAACZ,GAAQ+B,GAAMI,GAAMC,GAAOxB,CAAS,CAAC;AAC3C;"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ClonusClient } from '@clonus/js-client';
|
|
2
|
+
export declare const NoopClonusClient: ClonusClient & {
|
|
3
|
+
isNoop: true;
|
|
4
|
+
};
|
|
5
|
+
export declare function isNoopClient(client: ClonusClient | typeof NoopClonusClient): client is typeof NoopClonusClient;
|
|
6
|
+
//# sourceMappingURL=noop_clonus_client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noop_clonus_client.d.ts","sourceRoot":"","sources":["../src/noop_clonus_client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAQjD,eAAO,MAAM,gBAAgB,EAgEb,YAAY,GAAG;IAAE,MAAM,EAAE,IAAI,CAAA;CAAE,CAAC;AAEhD,wBAAgB,YAAY,CAC1B,MAAM,EAAE,YAAY,GAAG,OAAO,gBAAgB,GAC7C,MAAM,IAAI,OAAO,gBAAgB,CAEnC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ClonusClient, ClonusUser, ClonusOptions } from '@clonus/js-client';
|
|
2
|
+
export declare function useClientAsyncInit(apikey: string, user: ClonusUser, options?: ClonusOptions): {
|
|
3
|
+
isLoading: boolean;
|
|
4
|
+
client: ClonusClient;
|
|
5
|
+
};
|
|
6
|
+
//# sourceMappingURL=use_client_async_init.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use_client_async_init.d.ts","sourceRoot":"","sources":["../src/use_client_async_init.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAoB5E,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,UAAU,EAChB,OAAO,CAAC,EAAE,aAAa,GACtB;IAAE,SAAS,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,YAAY,CAAA;CAAE,CAe9C"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ClonusClient } from '@clonus/js-client';
|
|
2
|
+
type HostedFuncs = {
|
|
3
|
+
info: (message: string, properties?: Record<string, unknown>) => void;
|
|
4
|
+
warn: (message: string, properties?: Record<string, unknown>) => void;
|
|
5
|
+
error: (message: string, properties?: Record<string, unknown>) => void;
|
|
6
|
+
};
|
|
7
|
+
type Output = HostedFuncs & {
|
|
8
|
+
client: ClonusClient;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare function useClonusClient(): Output;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=use_clonus_client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use_clonus_client.d.ts","sourceRoot":"","sources":["../src/use_clonus_client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAIjD,KAAK,WAAW,GAAG;IACjB,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IACtE,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IACtE,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;CACxE,CAAC;AAEF,KAAK,MAAM,GAAG,WAAW,GAAG;IAC1B,MAAM,EAAE,YAAY,CAAC;IACrB,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,wBAAgB,eAAe,IAAI,MAAM,CA4CxC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@clonus/react-bindings",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"description": "React bindings for Clonus Analytics SDK",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"module": "./dist/index.mjs",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.mjs",
|
|
14
|
+
"require": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@clonus/js-client": "2.0.0"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@testing-library/react": "^14.1.0",
|
|
28
|
+
"@testing-library/jest-dom": "^6.1.5",
|
|
29
|
+
"@testing-library/user-event": "^14.5.1",
|
|
30
|
+
"@types/react": "^18.2.0",
|
|
31
|
+
"@types/react-dom": "^18.0.6",
|
|
32
|
+
"@vitejs/plugin-react": "^4.2.0",
|
|
33
|
+
"@vitest/coverage-v8": "^1.0.0",
|
|
34
|
+
"jsdom": "^23.0.0",
|
|
35
|
+
"react": "^18.2.0",
|
|
36
|
+
"react-dom": "^18.2.0",
|
|
37
|
+
"typescript": "^5.0.0",
|
|
38
|
+
"vite": "^5.0.0",
|
|
39
|
+
"vitest": "^1.0.0"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "vite build && tsc --emitDeclarationOnly --declaration --declarationMap",
|
|
43
|
+
"dev": "vite build --watch",
|
|
44
|
+
"test": "vitest run",
|
|
45
|
+
"test:watch": "vitest",
|
|
46
|
+
"test:coverage": "vitest run --coverage",
|
|
47
|
+
"lint": "eslint 'src/**/*.{ts,tsx}'",
|
|
48
|
+
"lint:fix": "eslint 'src/**/*.{ts,tsx}' --fix",
|
|
49
|
+
"type-check": "tsc --noEmit"
|
|
50
|
+
}
|
|
51
|
+
}
|