@trakit/react 0.0.1 → 0.0.2

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/README.md CHANGED
@@ -4,17 +4,25 @@ This library contains ReactJS controls, hooks, and contexts to assist in working
4
4
 
5
5
  ### Prerequisites
6
6
 
7
- The `@trakit/objects` and `@trakit/commands` packages are required since they contain the definitions for all the commands required to manipulate the objects.
7
+ The `@trakit/objects`, `@trakit/commands` and `@trakit/sync` packages are required since they contain the definitions for all the commands required to manipulate the objects.
8
8
 
9
- In order to build this project, you need to install the RollupJS, and plugins for TypeScript and Minifying.
9
+ In order to build this project, you need to install the ReactJS types, RollupJS, and plugins for TypeScript and Minifying.
10
10
  ```
11
- npm i rollup rollup-plugin-typescript2 @rollup/plugin-terser
11
+ npm i @types/react rollup rollup-plugin-typescript2 @rollup/plugin-terser
12
12
  ```
13
13
  After those have been installed, build the project normally.
14
14
  ```
15
15
  rollup --config rollup.config.js
16
16
  ```
17
17
 
18
+ ### `useConnection` hook
19
+
20
+ Used as the main hook for keeping a persistent connection.
21
+
22
+ ### `useSync` hook
23
+
24
+ Used to synchronize the specified type(s) of objects with the system. Internally, this hook uses `useConnection`.
25
+
18
26
  ## Questions and Feedback
19
27
 
20
28
  If you have any questions, please start for the project on GitHub
package/index.d.ts CHANGED
@@ -10,7 +10,7 @@ import useSync, { UseSyncResult } from "./hooks/useSync";
10
10
  /**
11
11
  * Version number for this release.
12
12
  */
13
- export declare const version = "0.0.1";
13
+ export declare const version = "0.0.2";
14
14
  /**
15
15
  * Hooks
16
16
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@trakit/react",
3
3
  "type": "module",
4
- "version": "0.0.1",
4
+ "version": "0.0.2",
5
5
  "main": "./trakit-react.min.js",
6
6
  "types": "./index.d.ts",
7
7
  "scripts": {
@@ -26,7 +26,7 @@
26
26
  "url": "https://github.com/trakitwireless/trakit-ts-react/issues"
27
27
  },
28
28
  "homepage": "https://github.com/trakitwireless/trakit-ts-react#readme",
29
- "description": "Trak-iT uses these object definitions to interact with all our APIs.",
29
+ "description": "ReactJS controls, hooks, and contexts to assist in working with Trak-iT's APIs.",
30
30
  "devDependencies": {
31
31
  "@rollup/plugin-terser": "^1.0.0",
32
32
  "rollup": "^4.35.0",
@@ -37,7 +37,8 @@
37
37
  "dependencies": {
38
38
  "@trakit/commands": "^0.1.2",
39
39
  "@trakit/objects": "^0.1.2",
40
- "@trakit/sync": "^0.1.1",
41
- "@types/react": "^19.2.17"
40
+ "@trakit/sync": "^0.1.2",
41
+ "@types/react": "^19.2.17",
42
+ "react-cookie": "^8.1.2"
42
43
  }
43
44
  }
@@ -1,7 +1,7 @@
1
- function n(n,o){function e(n){d(n.online)}function t(n){const{account:o}=n;p(o.user?.login&&o.expiry>new Date?o.ghostId:""),y(o.user||null),g(o.machine||null)}const r=s(new c(null,n||u.URI_PROD,o||l.URI_PROD)),[i,d]=f(r.current.socketOnline),[m,p]=f(r.current.account.ghostId||""),[w,y]=f(r.current.account.user||null),[h,g]=f(r.current.account.machine||null),b=i===!(!m&&!h);return a(()=>(r.current.on("open",e),r.current.on("error",e),r.current.on("close",e),r.current.on("account",t),()=>{r.current.off("open",e),r.current.off("error",e),r.current.off("close",e),r.current.off("account",t),r.current.dispose()}),[]),{synchronizer:r.current,ready:b,ghostId:m,online:i,user:w,machine:h}}function o(n){return window.addEventListener("online",n),window.addEventListener("offline",n),()=>{window.removeEventListener("online",n),window.removeEventListener("offline",n)}}function e(){return navigator.onLine}function t(){return!0}function r(){return d(o,e,t)}function i(o,e){const t=s(null),r=s(0),[i,c]=f(null),[u,d]=f(null),{synchronizer:p,ready:w,online:y,user:h,machine:g}=n();return a(()=>{function n(n,t){0!==r.current&&e===t&&o===n&&d([...m[n].values().filter(n=>n.companyId===e)])}function u(o){const{kind:e,companyId:t}=o;n(e,t)}function s(o){const{name:e,body:t}=o;n(l.msgNameToSyncName(e),t.company)}function f(){if(0===r.current){const n=i?.map(n=>n.syncName).filter(n=>!!n);n?.length&&p.desync(e,n),p.off("list",u),p.off("update",u),p.off("delete",u),p.off("message",s)}t.current=null}function a(t){c(t),n(o,e)}if(w&&o&&!isNaN(e))return r.current++,p.on("list",u),p.on("update",u),p.on("delete",u),p.on("message",s),t.current=p.sync(e,[o]),t.current.then(a,a),t.current.finally(f),()=>{r.current--,t.current||f()}},[w,y,e=e??h?.companyId??g?.companyId,o]),{ready:w&&y&&!!u&&!t.current,replies:i??[],objects:u??[]}}
1
+ function n(n,e){function t(n){I(n.online)}function o(n){const{account:e}=n;e.user?.login&&e.expiry>new Date?(u(y,e.ghostId,{...k,expires:e.expiry}),D(e.ghostId||"")):m(y,k),z(e.user||null),e.machine?.key&&e.expiry>new Date?(u(h,e.machine.key,{...k,expires:e.expiry}),u(g,e.machine.secret,{...k,expires:e.expiry})):(m(h,k),m(g,k)),S(e.machine||null)}const i=f(new s(null,n||l.URI_PROD,e||a.URI_PROD)),[r,u,m]=w([y,h,g]),[x,I]=d(i.current.socketOnline),[b,D]=d(r[y]||""),[j,z]=d(i.current.account.user||null),[N,S]=d(i.current.account.machine||r[h]&&new c({key:r[h],secret:r[g]})||null),v=x===!(!b&&!N);return p(()=>(i.current.on("open",t),i.current.on("error",t),i.current.on("close",t),i.current.on("account",o),(b||N)&&i.current.setAuth({ghostId:b,machine:N?.toJSON()}),()=>i.current.dispose()),[]),{synchronizer:i.current,ready:v,ghostId:b,online:x,user:j,machine:N}}function e(n){return window.addEventListener("online",n),window.addEventListener("offline",n),()=>{window.removeEventListener("online",n),window.removeEventListener("offline",n)}}function t(){return navigator.onLine}function o(){return!0}function i(){return m(e,t,o)}function r(e,t){const o=f(null),i=f(0),[r,c]=d(null),[s,l]=d(null),{synchronizer:m,ready:w,online:y,user:h,machine:g}=n();return p(()=>{function n(n,o){0!==i.current&&t===o&&e===n&&l([...u[n].values().filter(n=>n.companyId===t)])}function s(e){const{kind:t,companyId:o}=e;n(t,o)}function f(e){const{name:t,body:o}=e;n(a.msgNameToSyncName(t),o.company)}function d(){if(0===i.current){const n=r?.map(n=>n.syncName).filter(n=>!!n);n?.length&&m.desync(t,n),m.off("list",s),m.off("update",s),m.off("delete",s),m.off("message",f)}o.current=null}function p(o){c(o),n(e,t)}if(w&&e&&!isNaN(t))return i.current++,m.on("list",s),m.on("update",s),m.on("delete",s),m.on("message",f),o.current=m.sync(t,[e]),o.current.then(p,p),o.current.finally(d),()=>{i.current--,o.current||d()}},[w,y,t=t??h?.companyId??g?.companyId,e]),{ready:w&&y&&!!s&&!o.current,replies:r??[],objects:s??[]}}
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{TrakitSyncCommander as c,TrakitRestfulCommander as u,TrakitSocketCommander as l}from"@trakit/sync";import{useRef as s,useState as f,useEffect as a,useSyncExternalStore as d}from"react";import{storage as m}from"@trakit/objects";const p="0.0.1";export{n as useConnection,r as useIsOnline,i as useSync,p as version};
7
+ */import{Machine as c,storage as u}from"@trakit/objects";import{TrakitSyncCommander as s,TrakitRestfulCommander as l,TrakitSocketCommander as a}from"@trakit/sync";import{useRef as f,useState as d,useEffect as p,useSyncExternalStore as m}from"react";import{useCookies as w}from"react-cookie";const y="ghostId",h="apiKey",g="apiSec",k={path:"/",secure:!0,sameSite:"strict",expires:new Date(0)},x="0.0.2";export{n as useConnection,i as useIsOnline,r as useSync,x as version};