tempest-react-sdk 0.60.0 → 0.62.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.
Files changed (42) hide show
  1. package/README.md +9 -7
  2. package/dist/components/ImageCropper/ImageCropper.module.cjs.map +1 -1
  3. package/dist/components/ImageCropper/ImageCropper.module.js.map +1 -1
  4. package/dist/components/PasswordInput/PasswordInput.module.cjs.map +1 -1
  5. package/dist/components/PasswordInput/PasswordInput.module.js.map +1 -1
  6. package/dist/components/PinInput/PinInput.module.cjs.map +1 -1
  7. package/dist/components/PinInput/PinInput.module.js.map +1 -1
  8. package/dist/sse/create-event-stream.cjs +1 -1
  9. package/dist/sse/create-event-stream.cjs.map +1 -1
  10. package/dist/sse/create-event-stream.js +32 -27
  11. package/dist/sse/create-event-stream.js.map +1 -1
  12. package/dist/sse/use-event-stream.cjs.map +1 -1
  13. package/dist/sse/use-event-stream.js.map +1 -1
  14. package/dist/styles/ImageCropper.css +3 -3
  15. package/dist/styles/PasswordInput.css +1 -1
  16. package/dist/styles/PinInput.css +1 -1
  17. package/dist/styles/base.css +1 -1
  18. package/dist/styles/core.css +3 -3
  19. package/dist/styles/forms.css +5 -5
  20. package/dist/styles/scoped.css +1 -1
  21. package/dist/styles/tokens.css +2 -2
  22. package/dist/styles.css +1 -1
  23. package/dist/tempest-react-sdk.d.ts +180 -21
  24. package/dist/utils/dev-mode.cjs.map +1 -1
  25. package/dist/utils/dev-mode.js.map +1 -1
  26. package/dist/utils/json-frame.cjs +1 -1
  27. package/dist/utils/json-frame.cjs.map +1 -1
  28. package/dist/utils/json-frame.js +33 -14
  29. package/dist/utils/json-frame.js.map +1 -1
  30. package/dist/utils/schema-like.cjs +2 -0
  31. package/dist/utils/schema-like.cjs.map +1 -0
  32. package/dist/utils/schema-like.js +43 -0
  33. package/dist/utils/schema-like.js.map +1 -0
  34. package/dist/ws/create-web-socket.cjs +1 -1
  35. package/dist/ws/create-web-socket.cjs.map +1 -1
  36. package/dist/ws/create-web-socket.js +54 -38
  37. package/dist/ws/create-web-socket.js.map +1 -1
  38. package/dist/ws/use-web-socket.cjs +1 -1
  39. package/dist/ws/use-web-socket.cjs.map +1 -1
  40. package/dist/ws/use-web-socket.js +5 -3
  41. package/dist/ws/use-web-socket.js.map +1 -1
  42. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"use-web-socket.js","names":[],"sources":["../../src/ws/use-web-socket.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from \"react\";\nimport { useLatestRef } from \"@/hooks/use-latest-ref\";\nimport {\n createWebSocket,\n type CreateWebSocketOptions,\n type WebSocketController,\n type WebSocketMessage,\n type WebSocketStatus,\n} from \"./create-web-socket\";\n\nexport interface UseWebSocketOptions<T> extends Omit<CreateWebSocketOptions<T>, \"onStatusChange\"> {\n /** When false, the socket is not opened. Default: true. */\n enabled?: boolean;\n}\n\nexport interface UseWebSocketResult<T> {\n status: WebSocketStatus;\n /**\n * Last decoded frame received.\n *\n * A snapshot, not a stream: two frames arriving in the same tick collapse\n * into a single render and only the later one is ever visible. One server\n * action often emits several frames in a row, so anything that must see\n * every message has to use `onMessage`, which fires once per frame. Read\n * `lastMessage` for \"what is the current state\" rendering only.\n */\n lastMessage: WebSocketMessage<T> | null;\n /** Send a payload through the active connection. Returns false when not open. */\n send: (payload: string | Blob | BufferSource) => boolean;\n /** Force a reconnect, resetting the retry counter. */\n reconnect: () => void;\n /**\n * Change the silence watchdog at runtime, in ms. `0` disables it.\n *\n * For a server that announces its own heartbeat interval in the first frame,\n * so the tolerated silence is not hard-coded on both ends.\n */\n setSilenceTimeout: (ms: number) => void;\n}\n\n/**\n * React hook around {@link createWebSocket}. Manages the connection lifecycle\n * for the host component and tears it down on unmount.\n *\n * Every callback is read through a ref, so `onOpen` / `onMessage` / `onClose` /\n * `onError` / `onReconnecting` / `onReconnected` / `onLost` always run the\n * latest closure — an inline arrow function is fine and never reopens the\n * socket. Connection-shaping options (`protocols`, `maxRetries`,\n * `initialBackoff`, `maxBackoff`, `jitter`, `handshakeTimeout`,\n * `silenceTimeout`, `waitForOnline`, `pingInterval`, `queueWhileClosed`) are\n * baked into the connection, so changing one reopens it with the new value\n * rather than being silently ignored.\n *\n * @param url - Full ws:// or wss:// URL.\n * @param options - Connection configuration and callbacks.\n * @returns Status, last frame, and the `send` / `reconnect` controls.\n */\nexport function useWebSocket<T = unknown>(\n url: string,\n options: UseWebSocketOptions<T> = {},\n): UseWebSocketResult<T> {\n const {\n enabled = true,\n protocols,\n maxRetries,\n initialBackoff,\n maxBackoff,\n jitter,\n handshakeTimeout,\n silenceTimeout,\n waitForOnline,\n pingInterval,\n respondToPing,\n queueWhileClosed,\n maxQueuedMessages,\n } = options;\n const [status, setStatus] = useState<WebSocketStatus>(\"idle\");\n const [lastMessage, setLastMessage] = useState<WebSocketMessage<T> | null>(null);\n const controllerRef = useRef<WebSocketController | null>(null);\n\n const optionsRef = useLatestRef(options);\n\n const protocolsKey = Array.isArray(protocols) ? protocols.join(\",\") : (protocols ?? \"\");\n\n useEffect(() => {\n if (!enabled || !url) {\n setStatus(\"idle\");\n return;\n }\n\n /*\n * Presence is read once, when the socket opens, and decides whether the\n * forwarder is passed at all. A forwarder is always truthy, so wrapping\n * an absent `parser` — or an absent `onParseError` — would tell\n * `decodeFrame` the caller had supplied one and silently pick the wrong\n * branch.\n */\n const hasParser = optionsRef.current.parser !== undefined;\n const hasParseError = optionsRef.current.onParseError !== undefined;\n\n const controller = createWebSocket<T>(url, {\n protocols: optionsRef.current.protocols,\n maxRetries,\n initialBackoff,\n maxBackoff,\n jitter,\n handshakeTimeout,\n silenceTimeout,\n waitForOnline,\n pingInterval,\n pingPayload: optionsRef.current.pingPayload,\n respondToPing,\n pongPayload: optionsRef.current.pongPayload,\n queueWhileClosed,\n maxQueuedMessages,\n parser: hasParser ? (raw) => optionsRef.current.parser?.(raw) as T : undefined,\n onParseError: hasParseError\n ? (error, raw) => optionsRef.current.onParseError?.(error, raw)\n : undefined,\n onStatusChange: setStatus,\n onOpen: (event) => optionsRef.current.onOpen?.(event),\n onClose: (event) => optionsRef.current.onClose?.(event),\n onError: (event) => optionsRef.current.onError?.(event),\n onReconnecting: (attempt, total) => optionsRef.current.onReconnecting?.(attempt, total),\n onReconnected: () => optionsRef.current.onReconnected?.(),\n onLost: (reason) => optionsRef.current.onLost?.(reason),\n onMessage: (message) => {\n setLastMessage(message);\n optionsRef.current.onMessage?.(message);\n },\n });\n controllerRef.current = controller;\n\n return () => {\n controller.close();\n controllerRef.current = null;\n };\n }, [\n url,\n enabled,\n protocolsKey,\n maxRetries,\n initialBackoff,\n maxBackoff,\n jitter,\n handshakeTimeout,\n silenceTimeout,\n waitForOnline,\n pingInterval,\n respondToPing,\n queueWhileClosed,\n maxQueuedMessages,\n optionsRef,\n ]);\n\n const send = useCallback((payload: string | Blob | BufferSource): boolean => {\n return controllerRef.current?.send(payload) ?? false;\n }, []);\n\n const reconnect = useCallback((): void => {\n controllerRef.current?.reconnect();\n }, []);\n\n const setSilenceTimeout = useCallback((ms: number): void => {\n controllerRef.current?.setSilenceTimeout(ms);\n }, []);\n\n return { status, lastMessage, send, reconnect, setSilenceTimeout };\n}\n"],"mappings":";;;;AAyDA,SAAgB,EACZ,GACA,IAAkC,CAAC,GACd;CACrB,IAAM,EACF,aAAU,IACV,cACA,eACA,mBACA,eACA,WACA,qBACA,mBACA,kBACA,iBACA,kBACA,qBACA,yBACA,GACE,CAAC,GAAQ,KAAa,EAA0B,MAAM,GACtD,CAAC,GAAa,KAAkB,EAAqC,IAAI,GACzE,IAAgB,EAAmC,IAAI,GAEvD,IAAa,EAAa,CAAO,GAEjC,IAAe,MAAM,QAAQ,CAAS,IAAI,EAAU,KAAK,GAAG,IAAK,KAAa;CAqFpF,OAnFA,QAAgB;EACZ,IAAI,CAAC,KAAW,CAAC,GAAK;GAClB,EAAU,MAAM;GAChB;EACJ;EASA,IAAM,IAAY,EAAW,QAAQ,WAAW,KAAA,GAC1C,IAAgB,EAAW,QAAQ,iBAAiB,KAAA,GAEpD,IAAa,EAAmB,GAAK;GACvC,WAAW,EAAW,QAAQ;GAC9B;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA,aAAa,EAAW,QAAQ;GAChC;GACA,aAAa,EAAW,QAAQ;GAChC;GACA;GACA,QAAQ,KAAa,MAAQ,EAAW,QAAQ,SAAS,CAAG,IAAS,KAAA;GACrE,cAAc,KACP,GAAO,MAAQ,EAAW,QAAQ,eAAe,GAAO,CAAG,IAC5D,KAAA;GACN,gBAAgB;GAChB,SAAS,MAAU,EAAW,QAAQ,SAAS,CAAK;GACpD,UAAU,MAAU,EAAW,QAAQ,UAAU,CAAK;GACtD,UAAU,MAAU,EAAW,QAAQ,UAAU,CAAK;GACtD,iBAAiB,GAAS,MAAU,EAAW,QAAQ,iBAAiB,GAAS,CAAK;GACtF,qBAAqB,EAAW,QAAQ,gBAAgB;GACxD,SAAS,MAAW,EAAW,QAAQ,SAAS,CAAM;GACtD,YAAY,MAAY;IAEpB,AADA,EAAe,CAAO,GACtB,EAAW,QAAQ,YAAY,CAAO;GAC1C;EACJ,CAAC;EAGD,OAFA,EAAc,UAAU,SAEX;GAET,AADA,EAAW,MAAM,GACjB,EAAc,UAAU;EAC5B;CACJ,GAAG;EACC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACJ,CAAC,GAcM;EAAE;EAAQ;EAAa,MAZjB,GAAa,MACf,EAAc,SAAS,KAAK,CAAO,KAAK,IAChD,CAAC,CAU0B;EAAM,WARlB,QAAwB;GACtC,EAAc,SAAS,UAAU;EACrC,GAAG,CAAC,CAMgC;EAAW,mBAJrB,GAAa,MAAqB;GACxD,EAAc,SAAS,kBAAkB,CAAE;EAC/C,GAAG,CAAC,CAE2C;CAAkB;AACrE"}
1
+ {"version":3,"file":"use-web-socket.js","names":[],"sources":["../../src/ws/use-web-socket.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from \"react\";\nimport { useLatestRef } from \"@/hooks/use-latest-ref\";\nimport {\n createWebSocket,\n type CreateWebSocketOptions,\n type WebSocketController,\n type WebSocketMessage,\n type WebSocketStatus,\n} from \"./create-web-socket\";\n\nexport interface UseWebSocketOptions<T> extends Omit<CreateWebSocketOptions<T>, \"onStatusChange\"> {\n /** When false, the socket is not opened. Default: true. */\n enabled?: boolean;\n}\n\nexport interface UseWebSocketResult<T> {\n status: WebSocketStatus;\n /**\n * Last decoded frame received.\n *\n * A snapshot, not a stream: two frames arriving in the same tick collapse\n * into a single render and only the later one is ever visible. One server\n * action often emits several frames in a row, so anything that must see\n * every message has to use `onMessage`, which fires once per frame. Read\n * `lastMessage` for \"what is the current state\" rendering only.\n */\n lastMessage: WebSocketMessage<T> | null;\n /** Send a payload through the active connection. Returns false when not open. */\n send: (payload: string | Blob | BufferSource) => boolean;\n /** Force a reconnect, resetting the retry counter. */\n reconnect: () => void;\n /**\n * Change the silence watchdog at runtime, in ms. `0` disables it.\n *\n * For a server that announces its own heartbeat interval in the first frame,\n * so the tolerated silence is not hard-coded on both ends.\n */\n setSilenceTimeout: (ms: number) => void;\n}\n\n/**\n * React hook around {@link createWebSocket}. Manages the connection lifecycle\n * for the host component and tears it down on unmount.\n *\n * Every callback is read through a ref, so `onOpen` / `onMessage` / `onClose` /\n * `onError` / `onReconnecting` / `onReconnected` / `onLost` always run the\n * latest closure — an inline arrow function is fine and never reopens the\n * socket. Connection-shaping options (`protocols`, `maxRetries`,\n * `initialBackoff`, `maxBackoff`, `jitter`, `handshakeTimeout`,\n * `silenceTimeout`, `waitForOnline`, `pingInterval`, `queueWhileClosed`) are\n * baked into the connection, so changing one reopens it with the new value\n * rather than being silently ignored.\n *\n * `schema` is read when the socket opens, so declare it outside the component\n * (or memoize it): a schema built inline is a new object on every render, and\n * the one in force is whichever existed at the last open.\n *\n * @param url - Full ws:// or wss:// URL.\n * @param options - Connection configuration and callbacks.\n * @returns Status, last frame, and the `send` / `reconnect` controls.\n */\nexport function useWebSocket<T = unknown>(\n url: string,\n options: UseWebSocketOptions<T> = {},\n): UseWebSocketResult<T> {\n const {\n enabled = true,\n protocols,\n maxRetries,\n initialBackoff,\n maxBackoff,\n jitter,\n handshakeTimeout,\n silenceTimeout,\n waitForOnline,\n pingInterval,\n respondToPing,\n queueWhileClosed,\n maxQueuedMessages,\n } = options;\n const [status, setStatus] = useState<WebSocketStatus>(\"idle\");\n const [lastMessage, setLastMessage] = useState<WebSocketMessage<T> | null>(null);\n const controllerRef = useRef<WebSocketController | null>(null);\n\n const optionsRef = useLatestRef(options);\n\n const protocolsKey = Array.isArray(protocols) ? protocols.join(\",\") : (protocols ?? \"\");\n\n useEffect(() => {\n if (!enabled || !url) {\n setStatus(\"idle\");\n return;\n }\n\n /*\n * Presence is read once, when the socket opens, and decides whether the\n * forwarder is passed at all. A forwarder is always truthy, so wrapping\n * an absent `parser` — or an absent `onParseError` — would tell\n * `decodeFrame` the caller had supplied one and silently pick the wrong\n * branch.\n */\n const hasParser = optionsRef.current.parser !== undefined;\n const hasParseError = optionsRef.current.onParseError !== undefined;\n const hasValidationError = optionsRef.current.onValidationError !== undefined;\n\n const controller = createWebSocket<T>(url, {\n protocols: optionsRef.current.protocols,\n maxRetries,\n initialBackoff,\n maxBackoff,\n jitter,\n handshakeTimeout,\n silenceTimeout,\n waitForOnline,\n pingInterval,\n pingPayload: optionsRef.current.pingPayload,\n respondToPing,\n pongPayload: optionsRef.current.pongPayload,\n queueWhileClosed,\n maxQueuedMessages,\n parser: hasParser ? (raw) => optionsRef.current.parser?.(raw) as T : undefined,\n onParseError: hasParseError\n ? (error, raw) => optionsRef.current.onParseError?.(error, raw)\n : undefined,\n schema: optionsRef.current.schema,\n onValidationError: hasValidationError\n ? (issues, raw) => optionsRef.current.onValidationError?.(issues, raw)\n : undefined,\n onStatusChange: setStatus,\n onOpen: (event) => optionsRef.current.onOpen?.(event),\n onClose: (event) => optionsRef.current.onClose?.(event),\n onError: (event) => optionsRef.current.onError?.(event),\n onReconnecting: (attempt, total) => optionsRef.current.onReconnecting?.(attempt, total),\n onReconnected: () => optionsRef.current.onReconnected?.(),\n onLost: (reason) => optionsRef.current.onLost?.(reason),\n onMessage: (message) => {\n setLastMessage(message);\n optionsRef.current.onMessage?.(message);\n },\n });\n controllerRef.current = controller;\n\n return () => {\n controller.close();\n controllerRef.current = null;\n };\n }, [\n url,\n enabled,\n protocolsKey,\n maxRetries,\n initialBackoff,\n maxBackoff,\n jitter,\n handshakeTimeout,\n silenceTimeout,\n waitForOnline,\n pingInterval,\n respondToPing,\n queueWhileClosed,\n maxQueuedMessages,\n optionsRef,\n ]);\n\n const send = useCallback((payload: string | Blob | BufferSource): boolean => {\n return controllerRef.current?.send(payload) ?? false;\n }, []);\n\n const reconnect = useCallback((): void => {\n controllerRef.current?.reconnect();\n }, []);\n\n const setSilenceTimeout = useCallback((ms: number): void => {\n controllerRef.current?.setSilenceTimeout(ms);\n }, []);\n\n return { status, lastMessage, send, reconnect, setSilenceTimeout };\n}\n"],"mappings":";;;;AA6DA,SAAgB,EACZ,GACA,IAAkC,CAAC,GACd;CACrB,IAAM,EACF,aAAU,IACV,cACA,eACA,mBACA,eACA,WACA,qBACA,mBACA,kBACA,iBACA,kBACA,qBACA,yBACA,GACE,CAAC,GAAQ,KAAa,EAA0B,MAAM,GACtD,CAAC,GAAa,KAAkB,EAAqC,IAAI,GACzE,IAAgB,EAAmC,IAAI,GAEvD,IAAa,EAAa,CAAO,GAEjC,IAAe,MAAM,QAAQ,CAAS,IAAI,EAAU,KAAK,GAAG,IAAK,KAAa;CA0FpF,OAxFA,QAAgB;EACZ,IAAI,CAAC,KAAW,CAAC,GAAK;GAClB,EAAU,MAAM;GAChB;EACJ;EASA,IAAM,IAAY,EAAW,QAAQ,WAAW,KAAA,GAC1C,IAAgB,EAAW,QAAQ,iBAAiB,KAAA,GACpD,IAAqB,EAAW,QAAQ,sBAAsB,KAAA,GAE9D,IAAa,EAAmB,GAAK;GACvC,WAAW,E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react-sdk",
3
- "version": "0.60.0",
3
+ "version": "0.62.0",
4
4
  "description": "SDK público da Tempest com componentes, hooks e integrações para projetos React.",
5
5
  "type": "module",
6
6
  "license": "MIT",