@tiendanube/live-state 1.0.0-beta.1
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 +109 -0
- package/dist/clarity-BvtWdaMS.js +45 -0
- package/dist/clarity-BvtWdaMS.js.map +1 -0
- package/dist/clarity-Dc6nPh3X.cjs +2 -0
- package/dist/clarity-Dc6nPh3X.cjs.map +1 -0
- package/dist/index.cjs +12 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +8039 -0
- package/dist/index.js.map +1 -0
- package/dist/src/components/LiveStateAlert.d.ts +15 -0
- package/dist/src/components/LiveStateAlert.d.ts.map +1 -0
- package/dist/src/components/LiveStateInfo.d.ts +16 -0
- package/dist/src/components/LiveStateInfo.d.ts.map +1 -0
- package/dist/src/components/LiveStateRenderer.d.ts +11 -0
- package/dist/src/components/LiveStateRenderer.d.ts.map +1 -0
- package/dist/src/hooks/useLiveState.d.ts +22 -0
- package/dist/src/hooks/useLiveState.d.ts.map +1 -0
- package/dist/src/index.d.ts +9 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/providers/LiveStateProvider.d.ts +28 -0
- package/dist/src/providers/LiveStateProvider.d.ts.map +1 -0
- package/dist/src/types/index.d.ts +101 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/utils/analytics.d.ts +41 -0
- package/dist/src/utils/analytics.d.ts.map +1 -0
- package/dist/src/utils/cta.d.ts +8 -0
- package/dist/src/utils/cta.d.ts.map +1 -0
- package/package.json +102 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tiendanube/Nuvemshop
|
|
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,109 @@
|
|
|
1
|
+
# @tiendanube/live-state
|
|
2
|
+
|
|
3
|
+
> React library for rendering dynamic, context-aware notifications based on backend-computed state
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@tiendanube/live-state)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
A generic React library for rendering live state notifications (banners, alerts) driven entirely by backend-computed state. Built for the Tiendanube/Nuvemshop ecosystem using the Nimbus Design System.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- **Backend-controlled** — all content and logic comes from the API, zero hardcoding
|
|
15
|
+
- **Type-safe** — full TypeScript support with strict types
|
|
16
|
+
- **Analytics built-in** — automatic Amplitude + Clarity tracking for view, click, and close events
|
|
17
|
+
- **Graceful degradation** — fails silently, never breaks the host application
|
|
18
|
+
- **Nimbus Design System** — uses `@nimbus-ds/components`
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
yarn add @tiendanube/live-state
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Install peer dependencies if not already present:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
yarn add react react-dom @nimbus-ds/components @nimbus-ds/icons
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Quick start
|
|
37
|
+
|
|
38
|
+
### 1. Add the provider
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
import { LiveStateProvider } from '@tiendanube/live-state';
|
|
42
|
+
|
|
43
|
+
async function fetchLiveState() {
|
|
44
|
+
try {
|
|
45
|
+
const res = await fetch('/api/lending/live-state', {
|
|
46
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
47
|
+
});
|
|
48
|
+
return res.status === 204 ? null : res.json();
|
|
49
|
+
} catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function App() {
|
|
55
|
+
return (
|
|
56
|
+
<LiveStateProvider
|
|
57
|
+
fetcher={fetchLiveState}
|
|
58
|
+
analytics={{
|
|
59
|
+
amplitudeKey: process.env.REACT_APP_AMPLITUDE_KEY,
|
|
60
|
+
clarityProjectId: process.env.REACT_APP_CLARITY_PROJECT_ID,
|
|
61
|
+
}}
|
|
62
|
+
>
|
|
63
|
+
<YourApp />
|
|
64
|
+
</LiveStateProvider>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 2. Render notifications
|
|
70
|
+
|
|
71
|
+
```tsx
|
|
72
|
+
import { useLiveState, LiveStateRenderer } from '@tiendanube/live-state';
|
|
73
|
+
|
|
74
|
+
function LendingNotifications() {
|
|
75
|
+
const { liveState, isLoading } = useLiveState();
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<LiveStateRenderer
|
|
79
|
+
data={liveState}
|
|
80
|
+
loading={isLoading}
|
|
81
|
+
trackingConfig={{ prefix: 'lending_', page: 'dashboard' }}
|
|
82
|
+
/>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
That's it. The library handles rendering, tracking, and CTA behavior automatically.
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## Documentation
|
|
92
|
+
|
|
93
|
+
- [Implementation Guide](./docs/IMPLEMENTATION_GUIDE.md) — full integration guide with usage patterns, API reference, and troubleshooting
|
|
94
|
+
- [Architecture](./docs/ARCHITECTURE.md) — internal design decisions
|
|
95
|
+
- [Versioning & Release](./docs/VERSIONING_AND_RELEASE.md) — how to publish new versions
|
|
96
|
+
- [CircleCI Setup](./docs/CIRCLECI_SETUP.md) — CI/CD configuration
|
|
97
|
+
- [Contributing](./CONTRIBUTING.md) — developer contribution guide
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Contributing
|
|
102
|
+
|
|
103
|
+
This is an internal Tiendanube/Nuvemshop library. For questions or issues, contact the team.
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## License
|
|
108
|
+
|
|
109
|
+
MIT © Tiendanube/Nuvemshop
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//#region node_modules/@microsoft/clarity/src/utils.js
|
|
2
|
+
function e(e) {
|
|
3
|
+
try {
|
|
4
|
+
(function(e, t, n, r, i, a, o) {
|
|
5
|
+
t.getElementById("clarity-script") || (e[n] = e[n] || function() {
|
|
6
|
+
(e[n].q = e[n].q || []).push(arguments);
|
|
7
|
+
}, a = t.createElement(r), a.async = 1, a.src = "https://www.clarity.ms/tag/" + i + "?ref=npm", a.id = "clarity-script", o = t.getElementsByTagName(r)[0], o.parentNode.insertBefore(a, o));
|
|
8
|
+
})(window, document, "clarity", "script", e);
|
|
9
|
+
return;
|
|
10
|
+
} catch {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region node_modules/@microsoft/clarity/index.js
|
|
16
|
+
var t = {
|
|
17
|
+
init(t) {
|
|
18
|
+
e(t, "clarity-script");
|
|
19
|
+
},
|
|
20
|
+
setTag(e, t) {
|
|
21
|
+
window.clarity("set", e, t);
|
|
22
|
+
},
|
|
23
|
+
identify(e, t, n, r) {
|
|
24
|
+
window.clarity("identify", e, t, n, r);
|
|
25
|
+
},
|
|
26
|
+
consent(e = !0) {
|
|
27
|
+
window.clarity("consent", e);
|
|
28
|
+
},
|
|
29
|
+
consentV2(e = {
|
|
30
|
+
ad_Storage: "granted",
|
|
31
|
+
analytics_Storage: "granted"
|
|
32
|
+
}) {
|
|
33
|
+
window.clarity("consentv2", e);
|
|
34
|
+
},
|
|
35
|
+
upgrade(e) {
|
|
36
|
+
window.clarity("upgrade", e);
|
|
37
|
+
},
|
|
38
|
+
event(e) {
|
|
39
|
+
window.clarity("event", e);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
//#endregion
|
|
43
|
+
export { t as default };
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=clarity-BvtWdaMS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clarity-BvtWdaMS.js","names":[],"sources":["../node_modules/@microsoft/clarity/src/utils.js","../node_modules/@microsoft/clarity/index.js"],"sourcesContent":["export function injectScript(projectId) {\r\n try {\r\n (function (c, l, a, r, i, t, y) {\r\n if (l.getElementById(\"clarity-script\")) {\r\n return;\r\n }\r\n c[a] = c[a] ||\r\n function () {\r\n (c[a].q = c[a].q || []).push(arguments);\r\n };\r\n t = l.createElement(r);\r\n t.async = 1;\r\n t.src = \"https://www.clarity.ms/tag/\" + i + \"?ref=npm\";\r\n t.id = \"clarity-script\"\r\n y = l.getElementsByTagName(r)[0];\r\n y.parentNode.insertBefore(t, y);\r\n })(window, document, \"clarity\", \"script\", projectId);\r\n return;\r\n } catch (error) {\r\n return;\r\n }\r\n};\r\n","import { injectScript } from \"./src/utils.js\"\r\n\r\nconst Clarity = {\r\n init(projectId) {\r\n injectScript(projectId, 'clarity-script');\r\n },\r\n\r\n setTag(key, value) {\r\n window.clarity('set', key, value);\r\n },\r\n\r\n identify(customerId, customSessionId, customPageId, friendlyName) {\r\n window.clarity('identify', customerId, customSessionId, customPageId, friendlyName);\r\n },\r\n\r\n consent(consent = true) {\r\n window.clarity('consent', consent);\r\n },\r\n\r\n consentV2(consentOptions = { ad_Storage: 'granted', analytics_Storage: 'granted' }) {\r\n window.clarity('consentv2', consentOptions);\r\n },\r\n\r\n upgrade(reason) {\r\n window.clarity('upgrade', reason);\r\n },\r\n\r\n event(eventName) {\r\n window.clarity('event', eventName);\r\n },\r\n};\r\n\r\nexport default Clarity;\r\n"],"x_google_ignoreList":[0,1],"mappings":";AAAA,SAAgB,EAAa,GAAW;AACtC,KAAI;AACF,GAAC,SAAU,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG;AAC1B,KAAE,eAAe,iBAAiB,KAGtC,EAAE,KAAK,EAAE,MACP,WAAY;AACV,KAAC,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,EAAE,EAAE,KAAK,UAAU;MAE3C,IAAI,EAAE,cAAc,EAAE,EACtB,EAAE,QAAQ,GACV,EAAE,MAAM,gCAAgC,IAAI,YAC5C,EAAE,KAAK,kBACP,IAAI,EAAE,qBAAqB,EAAE,CAAC,IAC9B,EAAE,WAAW,aAAa,GAAG,EAAE;KAC9B,QAAQ,UAAU,WAAW,UAAU,EAAU;AACpD;SACc;AACd;;;;;ACjBJ,IAAM,IAAU;CACZ,KAAK,GAAW;AACZ,IAAa,GAAW,iBAAiB;;CAG7C,OAAO,GAAK,GAAO;AACf,SAAO,QAAQ,OAAO,GAAK,EAAM;;CAGrC,SAAS,GAAY,GAAiB,GAAc,GAAc;AAC9D,SAAO,QAAQ,YAAY,GAAY,GAAiB,GAAc,EAAa;;CAGvF,QAAQ,IAAU,IAAM;AACpB,SAAO,QAAQ,WAAW,EAAQ;;CAGtC,UAAU,IAAiB;EAAE,YAAY;EAAW,mBAAmB;EAAW,EAAE;AAChF,SAAO,QAAQ,aAAa,EAAe;;CAG/C,QAAQ,GAAQ;AACZ,SAAO,QAAQ,WAAW,EAAO;;CAGrC,MAAM,GAAW;AACb,SAAO,QAAQ,SAAS,EAAU;;CAEzC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function e(e){try{(function(e,t,n,r,i,a,o){t.getElementById(`clarity-script`)||(e[n]=e[n]||function(){(e[n].q=e[n].q||[]).push(arguments)},a=t.createElement(r),a.async=1,a.src=`https://www.clarity.ms/tag/`+i+`?ref=npm`,a.id=`clarity-script`,o=t.getElementsByTagName(r)[0],o.parentNode.insertBefore(a,o))})(window,document,`clarity`,`script`,e);return}catch{return}}var t={init(t){e(t,`clarity-script`)},setTag(e,t){window.clarity(`set`,e,t)},identify(e,t,n,r){window.clarity(`identify`,e,t,n,r)},consent(e=!0){window.clarity(`consent`,e)},consentV2(e={ad_Storage:`granted`,analytics_Storage:`granted`}){window.clarity(`consentv2`,e)},upgrade(e){window.clarity(`upgrade`,e)},event(e){window.clarity(`event`,e)}};exports.default=t;
|
|
2
|
+
//# sourceMappingURL=clarity-Dc6nPh3X.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clarity-Dc6nPh3X.cjs","names":[],"sources":["../node_modules/@microsoft/clarity/src/utils.js","../node_modules/@microsoft/clarity/index.js"],"sourcesContent":["export function injectScript(projectId) {\r\n try {\r\n (function (c, l, a, r, i, t, y) {\r\n if (l.getElementById(\"clarity-script\")) {\r\n return;\r\n }\r\n c[a] = c[a] ||\r\n function () {\r\n (c[a].q = c[a].q || []).push(arguments);\r\n };\r\n t = l.createElement(r);\r\n t.async = 1;\r\n t.src = \"https://www.clarity.ms/tag/\" + i + \"?ref=npm\";\r\n t.id = \"clarity-script\"\r\n y = l.getElementsByTagName(r)[0];\r\n y.parentNode.insertBefore(t, y);\r\n })(window, document, \"clarity\", \"script\", projectId);\r\n return;\r\n } catch (error) {\r\n return;\r\n }\r\n};\r\n","import { injectScript } from \"./src/utils.js\"\r\n\r\nconst Clarity = {\r\n init(projectId) {\r\n injectScript(projectId, 'clarity-script');\r\n },\r\n\r\n setTag(key, value) {\r\n window.clarity('set', key, value);\r\n },\r\n\r\n identify(customerId, customSessionId, customPageId, friendlyName) {\r\n window.clarity('identify', customerId, customSessionId, customPageId, friendlyName);\r\n },\r\n\r\n consent(consent = true) {\r\n window.clarity('consent', consent);\r\n },\r\n\r\n consentV2(consentOptions = { ad_Storage: 'granted', analytics_Storage: 'granted' }) {\r\n window.clarity('consentv2', consentOptions);\r\n },\r\n\r\n upgrade(reason) {\r\n window.clarity('upgrade', reason);\r\n },\r\n\r\n event(eventName) {\r\n window.clarity('event', eventName);\r\n },\r\n};\r\n\r\nexport default Clarity;\r\n"],"x_google_ignoreList":[0,1],"mappings":"AAAA,SAAgB,EAAa,EAAW,CACtC,GAAI,EACD,SAAU,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,CAC1B,EAAE,eAAe,iBAAiB,GAGtC,EAAE,GAAK,EAAE,IACP,UAAY,EACT,EAAE,GAAG,EAAI,EAAE,GAAG,GAAK,EAAE,EAAE,KAAK,UAAU,EAE3C,EAAI,EAAE,cAAc,EAAE,CACtB,EAAE,MAAQ,EACV,EAAE,IAAM,8BAAgC,EAAI,WAC5C,EAAE,GAAK,iBACP,EAAI,EAAE,qBAAqB,EAAE,CAAC,GAC9B,EAAE,WAAW,aAAa,EAAG,EAAE,IAC9B,OAAQ,SAAU,UAAW,SAAU,EAAU,CACpD,YACc,CACd,QCjBJ,IAAM,EAAU,CACZ,KAAK,EAAW,CACZ,EAAa,EAAW,iBAAiB,EAG7C,OAAO,EAAK,EAAO,CACf,OAAO,QAAQ,MAAO,EAAK,EAAM,EAGrC,SAAS,EAAY,EAAiB,EAAc,EAAc,CAC9D,OAAO,QAAQ,WAAY,EAAY,EAAiB,EAAc,EAAa,EAGvF,QAAQ,EAAU,GAAM,CACpB,OAAO,QAAQ,UAAW,EAAQ,EAGtC,UAAU,EAAiB,CAAE,WAAY,UAAW,kBAAmB,UAAW,CAAE,CAChF,OAAO,QAAQ,YAAa,EAAe,EAG/C,QAAQ,EAAQ,CACZ,OAAO,QAAQ,UAAW,EAAO,EAGrC,MAAM,EAAW,CACb,OAAO,QAAQ,QAAS,EAAU,EAEzC"}
|