@trakit/react 0.0.12 → 0.0.13
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/context/apiContext.d.ts +7 -7
- package/index.d.ts +4 -4
- package/package.json +2 -2
- package/trakit-react.min.js +2 -2
package/context/apiContext.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { ReactNode } from 'react';
|
|
|
4
4
|
/**
|
|
5
5
|
* The result of the `useConnection` hook, providing the synchronizer instance and connection state.
|
|
6
6
|
*/
|
|
7
|
-
export type
|
|
7
|
+
export type TrakitContextType = {
|
|
8
8
|
/**
|
|
9
9
|
* The synchronizer instance used for commands.
|
|
10
10
|
*/
|
|
@@ -39,22 +39,22 @@ export type ApiContextType = {
|
|
|
39
39
|
};
|
|
40
40
|
/**
|
|
41
41
|
* Provider component that wraps the application with CookiesProvider.
|
|
42
|
-
* Required for the `
|
|
42
|
+
* Required for the `useTrakit` hook to work properly.
|
|
43
43
|
*
|
|
44
44
|
* @example
|
|
45
45
|
* ```tsx
|
|
46
|
-
* import {
|
|
46
|
+
* import { TrakitProvider, useTrakit } from '@trakit/react';
|
|
47
47
|
*
|
|
48
48
|
* function App() {
|
|
49
49
|
* return (
|
|
50
|
-
* <
|
|
50
|
+
* <TrakitProvider>
|
|
51
51
|
* <YourComponent />
|
|
52
|
-
* </
|
|
52
|
+
* </TrakitProvider>
|
|
53
53
|
* );
|
|
54
54
|
* }
|
|
55
55
|
* ```
|
|
56
56
|
*/
|
|
57
|
-
export declare function
|
|
57
|
+
export declare function TrakitProvider({ children, restAddress, socketAddress, auditAddress, }: {
|
|
58
58
|
children: ReactNode;
|
|
59
59
|
restAddress?: URL | url | nothing;
|
|
60
60
|
socketAddress?: URL | url | nothing;
|
|
@@ -65,5 +65,5 @@ export declare function ApiProvider({ children, restAddress, socketAddress, audi
|
|
|
65
65
|
* It initializes the synchronizer, listens for connection and account events,
|
|
66
66
|
* and provides the current connection state, API instances, and user/machine information.
|
|
67
67
|
*/
|
|
68
|
-
export declare function
|
|
68
|
+
export declare function useTrakit(): TrakitContextType;
|
|
69
69
|
//# sourceMappingURL=apiContext.d.ts.map
|
package/index.d.ts
CHANGED
|
@@ -4,19 +4,19 @@
|
|
|
4
4
|
* Last updated on Thu June 11 2026 15:43:01
|
|
5
5
|
* @copyright Trak-iT Wireless Inc. 2026
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
7
|
+
import { TrakitProvider, useTrakit, type TrakitContextType } from "./context/apiContext";
|
|
8
8
|
import useIsOnline from "./hooks/useIsOnline";
|
|
9
9
|
import { useSingle, useSync, UseSyncMultiple, UseSyncResult, UseSyncSingle } from "./hooks/useSync";
|
|
10
10
|
/**
|
|
11
11
|
* Version number for this release.
|
|
12
12
|
*/
|
|
13
|
-
export declare const version = "0.0.
|
|
13
|
+
export declare const version = "0.0.13";
|
|
14
14
|
/**
|
|
15
15
|
* Hooks
|
|
16
16
|
*/
|
|
17
|
-
export {
|
|
17
|
+
export { useIsOnline, useSingle, useSync, useTrakit, type UseSyncMultiple, type UseSyncResult, type UseSyncSingle, };
|
|
18
18
|
/**
|
|
19
19
|
* Context provider for connection state and API instances.
|
|
20
20
|
*/
|
|
21
|
-
export {
|
|
21
|
+
export { TrakitProvider, type TrakitContextType, };
|
|
22
22
|
//# sourceMappingURL=index.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trakit/react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.13",
|
|
5
5
|
"main": "./trakit-react.min.js",
|
|
6
6
|
"types": "./index.d.ts",
|
|
7
7
|
"scripts": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@trakit/commands": "^0.1.8",
|
|
39
39
|
"@trakit/objects": "^0.1.5",
|
|
40
|
-
"@trakit/sync": "^0.1.
|
|
40
|
+
"@trakit/sync": "^0.1.11",
|
|
41
41
|
"@types/react": "^19.2.17"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
package/trakit-react.min.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
function n({children:n,restAddress:t,socketAddress:r,auditAddress:i}){return d(b,{children:d(e,{restAddress:t,socketAddress:r,auditAddress:i,children:n})})}function e({children:n,restAddress:e,socketAddress:t,auditAddress:r}){function i(n){x(n.online)}function o(n){const{account:e}=n;e.user?.login&&e.expiry>new Date?(a(j,e.ghostId,{...z,expires:e.expiry}),S(e.ghostId||"")):h(j,z),
|
|
1
|
+
function n({children:n,restAddress:t,socketAddress:r,auditAddress:i}){return d(b,{children:d(e,{restAddress:t,socketAddress:r,auditAddress:i,children:n})})}function e({children:n,restAddress:e,socketAddress:t,auditAddress:r}){function i(n){x(n.online)}function o(n){const{account:e}=n;e.user?.login&&e.expiry>new Date?(a(j,e.ghostId,{...z,expires:e.expiry}),S(e.ghostId||"")):h(j,z),E(e.user||null),e.machine?.key&&e.expiry>new Date?(a(v,e.machine.key,{...z,expires:e.expiry}),a(D,e.machine.secret,{...z,expires:e.expiry})):(h(v,z),h(D,z)),P(e.machine||null),c.current.setAuth(e)}const s=k(new f(null,e||m.URI_PROD,t||p.URI_PROD)),c=k(new w(null,r||w.URI_PROD)),[u,a,h]=I([j,v,D]),[y,x]=g(s.current.socketOnline),[b,S]=g(u[j]||""),[T,E]=g(s.current.account.user||null),[K,P]=g(s.current.account.machine||u[v]&&new l({key:u[v],secret:u[D]})||null),q=!(!b&&!K)==!(!s.current.account.user&&!s.current.account.machine);return A(()=>{s.current.on("open",i),s.current.on("error",i),s.current.on("close",i),s.current.on("account",o),(b||K)&&s.current.setAuth({ghostId:b,machine:K?.toJSON()})},[]),d(N,{value:{synchronizer:s.current,auditor:c.current,ready:q,ghostId:b,online:y,user:T,machine:K},children:n})}function t(){const n=y(N);if(!n)throw new Error("useTrakit must be used within TrakitProvider");return n}function r(n){return window.addEventListener("online",n),window.addEventListener("offline",n),()=>{window.removeEventListener("online",n),window.removeEventListener("offline",n)}}function i(){return navigator.onLine}function o(){return!0}function s(){return x(r,i,o)}function c(n,e){const r=k(null),i=k(0),[o,s]=g(null),[c,u]=g({}),{synchronizer:d,ready:l,online:f,user:m,machine:w}=t();return A(()=>{function t(t,r){0!==i.current&&e===r&&n.includes(t)&&u(n=>({...n,[t]:[...a[t].values().filter(n=>n.companyId===e)]}))}function c(n){const{kind:e,companyId:r}=n;t(e,r)}function f(n){const{name:e,body:r}=n;t(p.msgNameToSyncName(e),r.company)}function m(){if(0===i.current){const n=o?.map(n=>n.syncName).filter(n=>!!n);n?.length&&d.desync(e,n),d.off("list",c),d.off("update",c),d.off("delete",c),d.off("message",f)}r.current=null}function w(r){s(r),n.forEach(n=>t(n,e))}if(l&&n?.length&&!isNaN(e))return i.current++,d.on("list",c),d.on("update",c),d.on("delete",c),d.on("message",f),r.current=r.current||d.sync(e,n),r.current.then(w,w),r.current.finally(m),()=>{i.current--,r.current||m()}},[e=e??m?.companyId??w?.companyId,n.sort().join(",")]),{loading:!(l&&f&&o&&!r.current),replies:o??[],...c}}function u(n,e){const{loading:t,replies:r,[n]:i}=c([n],e);return{loading:t,replies:r,objects:i??[]}}
|
|
2
2
|
/**
|
|
3
3
|
* ReactJS library.
|
|
4
4
|
* {@link https://github.com/trakitwireless/trakit-ts-react|ReactJS controls.}
|
|
5
5
|
* Last updated on Thu June 11 2026 15:43:01
|
|
6
6
|
* @copyright Trak-iT Wireless Inc. 2026
|
|
7
|
-
*/import{jsx as d}from"react/jsx-runtime";import{Machine as l,storage as a}from"@trakit/objects";import{TrakitSyncCommander as f,TrakitRestfulCommander as m,TrakitSocketCommander as p,TrakitAuditCommander as w}from"@trakit/sync";import{createContext as h,useRef as
|
|
7
|
+
*/import{jsx as d}from"react/jsx-runtime";import{Machine as l,storage as a}from"@trakit/objects";import{TrakitSyncCommander as f,TrakitRestfulCommander as m,TrakitSocketCommander as p,TrakitAuditCommander as w}from"@trakit/sync";import{createContext as h,useRef as k,useState as g,useEffect as A,useContext as y,useSyncExternalStore as x}from"react";import{CookiesProvider as b,useCookies as I}from"react-cookie";const j="ghostId",v="aK",D="aS",z={path:"/",secure:!0,sameSite:"strict",expires:new Date(0)},N=h(null),S="0.0.13";export{n as TrakitProvider,s as useIsOnline,u as useSingle,c as useSync,t as useTrakit,S as version};
|