@trakit/react 0.0.10 → 0.0.11

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.
@@ -0,0 +1,22 @@
1
+ import { RepSelfGet } from '@trakit/commands';
2
+ import { guid, Machine, nothing, url } from '@trakit/objects';
3
+ import { TrakitAuditCommander } from '@trakit/sync';
4
+ /**
5
+ *
6
+ * @param account The account information used for authentication.
7
+ * @param baseAddress The base address of the audit service.
8
+ * @returns An object containing the auditor instance and its readiness state.
9
+ */
10
+ export declare function useAudit(account?: RepSelfGet | {
11
+ machine: {
12
+ key: string;
13
+ };
14
+ } | Machine | {
15
+ key: string;
16
+ } | {
17
+ ghostId: guid;
18
+ } | guid | nothing, baseAddress?: URL | url | nothing): {
19
+ auditor: TrakitAuditCommander;
20
+ ready: boolean;
21
+ };
22
+ //# sourceMappingURL=useAudit.d.ts.map
package/index.d.ts CHANGED
@@ -5,18 +5,19 @@
5
5
  * @copyright Trak-iT Wireless Inc. 2026
6
6
  */
7
7
  import { ConnectionProvider, useConnection, type ConnectionContextType } from "./context/connectionContext";
8
+ import { useAudit } from "./hooks/useAudit";
8
9
  import useIsOnline from "./hooks/useIsOnline";
9
10
  import { useSingle, useSync, UseSyncMultiple, UseSyncResult, UseSyncSingle } from "./hooks/useSync";
10
11
  /**
11
12
  * Version number for this release.
12
13
  */
13
- export declare const version = "0.0.10";
14
+ export declare const version = "0.0.11";
14
15
  /**
15
16
  * Hooks
16
17
  */
17
- export { useConnection, useIsOnline, useSingle, useSync, type UseSyncMultiple, type UseSyncResult, type UseSyncSingle, };
18
+ export { useAudit, useConnection, useIsOnline, useSingle, useSync, type UseSyncMultiple, type UseSyncResult, type UseSyncSingle };
18
19
  /**
19
20
  * Context provider for connection state and synchronizer instance.
20
21
  */
21
- export { ConnectionProvider, type ConnectionContextType, };
22
+ export { ConnectionProvider, type ConnectionContextType };
22
23
  //# 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.10",
4
+ "version": "0.0.11",
5
5
  "main": "./trakit-react.min.js",
6
6
  "types": "./index.d.ts",
7
7
  "scripts": {
@@ -1,7 +1,7 @@
1
- function n({children:n,restAddress:t,socketAddress:r}){return l(A,{children:l(e,{restAddress:t,socketAddress:r,children:n})})}function e({children:n,restAddress:e,socketAddress:t}){function r(n){h(n.online)}function o(n){const{account:e}=n;e.user?.login&&e.expiry>new Date?(c(I,e.ghostId,{...D,expires:e.expiry}),x(e.ghostId||"")):u(I,D),C(e.user||null),e.machine?.key&&e.expiry>new Date?(c(j,e.machine.key,{...D,expires:e.expiry}),c(v,e.machine.secret,{...D,expires:e.expiry})):(u(j,D),u(v,D)),S(e.machine||null)}const i=w(new f(null,e||m.URI_PROD,t||p.URI_PROD)),[s,c,u]=b([I,j,v]),[a,h]=g(i.current.socketOnline),[y,x]=g(s[I]||""),[A,C]=g(i.current.account.user||null),[N,S]=g(i.current.account.machine||s[j]&&new d({key:s[j],secret:s[v]})||null),E=!(!y&&!N)==!(!i.current.account.user&&!i.current.account.machine);return k(()=>{i.current.on("open",r),i.current.on("error",r),i.current.on("close",r),i.current.on("account",o),(y||N)&&i.current.setAuth({ghostId:y,machine:N?.toJSON()})},[]),l(z,{value:{synchronizer:i.current,ready:E,ghostId:y,online:a,user:A,machine:N},children:n})}function t(){const n=y(z);if(!n)throw new Error("useConnection must be used within ConnectionProvider");return n}function r(n){return window.addEventListener("online",n),window.addEventListener("offline",n),()=>{window.removeEventListener("online",n),window.removeEventListener("offline",n)}}function o(){return navigator.onLine}function i(){return!0}function s(){return x(r,o,i)}function c(n,e){const r=w(null),o=w(0),[i,s]=g(null),[c,u]=g({}),{synchronizer:l,ready:d,online:f,user:m,machine:h}=t();return k(()=>{function t(t,r){0!==o.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===o.current){const n=i?.map(n=>n.syncName).filter(n=>!!n);n?.length&&l.desync(e,n),l.off("list",c),l.off("update",c),l.off("delete",c),l.off("message",f)}r.current=null}function h(r){s(r),n.forEach(n=>t(n,e))}if(d&&n?.length&&!isNaN(e))return o.current++,l.on("list",c),l.on("update",c),l.on("delete",c),l.on("message",f),r.current=r.current||l.sync(e,n),r.current.then(h,h),r.current.finally(m),()=>{o.current--,r.current||m()}},[e=e??m?.companyId??h?.companyId,n.sort().join(",")]),{loading:!(d&&f&&i&&!r.current),replies:i??[],...c}}function u(n,e){const{loading:t,replies:r,[n]:o}=c([n],e);return{loading:t,replies:r,objects:o??[]}}
1
+ function n({children:n,restAddress:t,socketAddress:r}){return d(I,{children:d(e,{restAddress:t,socketAddress:r,children:n})})}function e({children:n,restAddress:e,socketAddress:t}){function r(n){f(n.online)}function o(n){const{account:e}=n;e.user?.login&&e.expiry>new Date?(c(v,e.ghostId,{...C,expires:e.expiry}),g(e.ghostId||"")):u(v,C),b(e.user||null),e.machine?.key&&e.expiry>new Date?(c(D,e.machine.key,{...C,expires:e.expiry}),c(z,e.machine.secret,{...C,expires:e.expiry})):(u(D,C),u(z,C)),S(e.machine||null)}const i=y(new m(null,e||p.URI_PROD,t||w.URI_PROD)),[s,c,u]=j([v,D,z]),[l,f]=k(i.current.socketOnline),[h,g]=k(s[v]||""),[A,b]=k(i.current.account.user||null),[I,S]=k(i.current.account.machine||s[D]&&new a({key:s[D],secret:s[z]})||null),E=!(!h&&!I)==!(!i.current.account.user&&!i.current.account.machine);return x(()=>{i.current.on("open",r),i.current.on("error",r),i.current.on("close",r),i.current.on("account",o),(h||I)&&i.current.setAuth({ghostId:h,machine:I?.toJSON()})},[]),d(N,{value:{synchronizer:i.current,ready:E,ghostId:h,online:l,user:A,machine:I},children:n})}function t(){const n=A(N);if(!n)throw new Error("useConnection must be used within ConnectionProvider");return n}function r(n,e){const t=y(new h(null,e||h.URI_PROD)),r=!(!t.current.account.user&&!t.current.account.machine);return x(()=>t.current.setAuth(n),[n?.machine?.key||n?.user?.login||n?.key||n?.ghostId||n||null]),{auditor:t.current,ready:r}}function o(n){return window.addEventListener("online",n),window.addEventListener("offline",n),()=>{window.removeEventListener("online",n),window.removeEventListener("offline",n)}}function i(){return navigator.onLine}function s(){return!0}function c(){return b(o,i,s)}function u(n,e){const r=y(null),o=y(0),[i,s]=k(null),[c,u]=k({}),{synchronizer:l,ready:d,online:a,user:m,machine:p}=t();return x(()=>{function t(t,r){0!==o.current&&e===r&&n.includes(t)&&u(n=>({...n,[t]:[...f[t].values().filter(n=>n.companyId===e)]}))}function c(n){const{kind:e,companyId:r}=n;t(e,r)}function a(n){const{name:e,body:r}=n;t(w.msgNameToSyncName(e),r.company)}function m(){if(0===o.current){const n=i?.map(n=>n.syncName).filter(n=>!!n);n?.length&&l.desync(e,n),l.off("list",c),l.off("update",c),l.off("delete",c),l.off("message",a)}r.current=null}function p(r){s(r),n.forEach(n=>t(n,e))}if(d&&n?.length&&!isNaN(e))return o.current++,l.on("list",c),l.on("update",c),l.on("delete",c),l.on("message",a),r.current=r.current||l.sync(e,n),r.current.then(p,p),r.current.finally(m),()=>{o.current--,r.current||m()}},[e=e??m?.companyId??p?.companyId,n.sort().join(",")]),{loading:!(d&&a&&i&&!r.current),replies:i??[],...c}}function l(n,e){const{loading:t,replies:r,[n]:o}=u([n],e);return{loading:t,replies:r,objects:o??[]}}
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 l}from"react/jsx-runtime";import{Machine as d,storage as a}from"@trakit/objects";import{TrakitSyncCommander as f,TrakitRestfulCommander as m,TrakitSocketCommander as p}from"@trakit/sync";import{createContext as h,useRef as w,useState as g,useEffect as k,useContext as y,useSyncExternalStore as x}from"react";import{CookiesProvider as A,useCookies as b}from"react-cookie";const I="ghostId",j="aK",v="aS",D={path:"/",secure:!0,sameSite:"strict",expires:new Date(0)},z=h(null),C="0.0.10";export{n as ConnectionProvider,t as useConnection,s as useIsOnline,u as useSingle,c as useSync,C as version};
7
+ */import{jsx as d}from"react/jsx-runtime";import{Machine as a,storage as f}from"@trakit/objects";import{TrakitSyncCommander as m,TrakitRestfulCommander as p,TrakitSocketCommander as w,TrakitAuditCommander as h}from"@trakit/sync";import{createContext as g,useRef as y,useState as k,useEffect as x,useContext as A,useSyncExternalStore as b}from"react";import{CookiesProvider as I,useCookies as j}from"react-cookie";const v="ghostId",D="aK",z="aS",C={path:"/",secure:!0,sameSite:"strict",expires:new Date(0)},N=g(null),S="0.0.11";export{n as ConnectionProvider,r as useAudit,t as useConnection,c as useIsOnline,l as useSingle,u as useSync,S as version};