@resulticks/trustsignal-wa-hsm 0.6.0 → 0.7.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.
package/README.md CHANGED
@@ -1,94 +1,118 @@
1
- # TrustSignal WebSDK (Library)
2
-
3
- This package exposes two React components that you can drop into your app:
4
-
5
- - `Dashboard`: list and entry point
6
- - `CreateTemplate`: the template builder screen
7
- - `TrustSignalProvider`: wraps your app and provides the API key/config
8
-
9
- The library ships its own compiled styles, so you only need to import the CSS once.
10
-
11
- ## Installation
12
-
13
- ```bash
14
- npm i @resulticks/trustsignal react react-dom react-router-dom
15
- ```
16
-
17
- > react, react-dom and react-router-dom are peer dependencies and must be installed in the host app.
18
-
19
- ## Quick Start (Routing Example)
20
-
21
- Add these routes so only one screen renders at a time. The Dashboard should navigate to `/create` when the "Create Template" button is clicked.
22
-
23
- ```tsx
24
- import { BrowserRouter, Routes, Route, useNavigate, Navigate } from "react-router-dom";
25
- import { TrustSignalProvider, Dashboard, CreateTemplate } from "@resulticks/trustsignal";
26
- import "@resulticks/trustsignal/style.css";
27
-
28
- function AppRoutes() {
29
- const navigate = useNavigate();
30
- return (
31
- <Routes>
32
- <Route path="/" element={<Dashboard />} />
33
-
34
- <Route path="/create" element={<CreateTemplate onCancel={() => navigate("/")} />} />
35
-
36
- <Route path="*" element={<Navigate to="/" replace />} />
37
- </Routes>
38
- );
39
- }
40
-
41
- export default function App() {
42
- return (
43
- <BrowserRouter>
44
- <TrustSignalProvider
45
- apiKey="YOUR_API_KEY"
46
- pConfig={{
47
- baseUrl: process.env.RESUL_BASE_URL,
48
- departmentId: Number(process.env.RESUL_DEPARTMENT_ID),
49
- clientId: Number(process.env.RESUL_CLIENT_ID),
50
- createdBy: Number(process.env.RESUL_CREATED_BY),
51
- userId: Number(process.env.RESUL_USER_ID),
52
- }}
53
- >
54
- <AppRoutes />
55
- </TrustSignalProvider>
56
- </BrowserRouter>
57
- );
58
- }
59
- ```
60
-
61
- ### Notes
62
- - Import the stylesheet once: `import "@resulticks/trustsignal/style.css";`
63
- - The provider writes the `apiKey` (and optional `pConfig` metadata) to `localStorage('account')` so all API calls work without additional wiring.
64
- - Pass `pConfig` if you need to override meta identifiers (`departmentId`, `clientId`, `createdBy`, `userId`) and/or `baseUrl` for the Resul API submission; updates propagate automatically.
65
- - Consider sourcing `pConfig` values from env variables (as in the example) to simplify environment-specific deployments.
66
- - If your Dashboard navigates to a different path for creation, add a matching `<Route>` that renders `<CreateTemplate />` for that path.
67
- - You can supply a custom `onCancel` to control navigation from the builder.
68
-
69
- ## Local Development / Building the Library (inside this repo)
70
-
71
- ```bash
72
- # Build the library bundles to dist/
73
- npm run build:lib
74
-
75
- # (optional) link into another project while developing
76
- # in this repo
77
- npm pack # or use a local link strategy
78
- # then in your host project
79
- npm i ../path/to/@resulticks/trustsignal-*.tgz
80
- ```
81
-
82
- The library exports:
83
-
84
- ```ts
85
- import { TrustSignalProvider, Dashboard, CreateTemplate } from "@resulticks/trustsignal";
86
- ```
87
-
88
- CSS is automatically included via the package metadata, but you can also explicitly import it early in your app entry to ensure styles load before first paint:
89
-
90
- ```ts
91
- import "@resulticks/trustsignal/style.css";
92
- ```
93
-
94
- That’s it—drop in `Dashboard` and route to `CreateTemplate` when the user clicks create.
1
+ # TrustSignal WebSDK (Library)
2
+
3
+ This package exposes two React components that you can drop into your app:
4
+
5
+ - `Dashboard`: list and entry point
6
+ - `CreateTemplate`: the template builder screen
7
+ - `TrustSignalProvider`: wraps your app and provides the API key/config
8
+
9
+ The library ships its own compiled styles, so you only need to import the CSS once.
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ npm i @resulticks/trustsignal react react-dom
15
+ ```
16
+
17
+ > react and react-dom are peer dependencies and must be installed in the host app.
18
+
19
+ ## Quick Start (State-Based Toggling - No Routing Required)
20
+
21
+ The components can be toggled using React state without requiring any routing library. Simply manage the view state and pass callbacks to handle navigation between components.
22
+
23
+ ```tsx
24
+ import { useState } from "react";
25
+ import { TrustSignalProvider, Dashboard, CreateTemplate } from "@resulticks/trustsignal";
26
+ import "@resulticks/trustsignal/style.css";
27
+
28
+ type View = 'dashboard' | 'create' | 'edit';
29
+
30
+ export default function App() {
31
+ const [currentView, setCurrentView] = useState<View>('dashboard');
32
+ const [editId, setEditId] = useState<string | null>(null);
33
+
34
+ const handleCreateTemplate = () => {
35
+ setEditId(null);
36
+ setCurrentView('create');
37
+ };
38
+
39
+ const handleEditTemplate = (id: string) => {
40
+ setEditId(id);
41
+ setCurrentView('edit');
42
+ };
43
+
44
+ const handleBackToDashboard = () => {
45
+ setCurrentView('dashboard');
46
+ setEditId(null);
47
+ };
48
+
49
+ return (
50
+ <TrustSignalProvider
51
+ apiKey="YOUR_API_KEY"
52
+ pConfig={{
53
+ baseUrl: process.env.RESUL_BASE_URL,
54
+ departmentId: Number(process.env.RESUL_DEPARTMENT_ID),
55
+ clientId: Number(process.env.RESUL_CLIENT_ID),
56
+ createdBy: Number(process.env.RESUL_CREATED_BY),
57
+ userId: Number(process.env.RESUL_USER_ID),
58
+ }}
59
+ >
60
+ {currentView === 'dashboard' ? (
61
+ <Dashboard
62
+ onCreateTemplate={handleCreateTemplate}
63
+ onEditTemplate={handleEditTemplate}
64
+ />
65
+ ) : (
66
+ <CreateTemplate
67
+ editId={editId || undefined}
68
+ onCancel={handleBackToDashboard}
69
+ />
70
+ )}
71
+ </TrustSignalProvider>
72
+ );
73
+ }
74
+ ```
75
+
76
+ ### Component Props
77
+
78
+ #### Dashboard
79
+ - `onCreateTemplate?: () => void` - Callback when user clicks to create a new template
80
+ - `onEditTemplate?: (id: string) => void` - Callback when user clicks to edit a template (receives template ID)
81
+
82
+ #### CreateTemplate
83
+ - `editId?: string` - Optional template ID to edit. If provided, the component will load and edit that template.
84
+ - `onCancel?: () => void` - Callback when user clicks the Back button to return to dashboard
85
+
86
+ ### Notes
87
+ - Import the stylesheet once: `import "@resulticks/trustsignal/style.css";`
88
+ - The provider writes the `apiKey` (and optional `pConfig` metadata) to `localStorage('account')` so all API calls work without additional wiring.
89
+ - Pass `pConfig` if you need to override meta identifiers (`departmentId`, `clientId`, `createdBy`, `userId`) and/or `baseUrl` for the Resul API submission; updates propagate automatically.
90
+ - Consider sourcing `pConfig` values from env variables (as in the example) to simplify environment-specific deployments.
91
+ - **No routing required**: The components work with simple state toggling, making integration easier without needing react-router-dom.
92
+
93
+ ## Local Development / Building the Library (inside this repo)
94
+
95
+ ```bash
96
+ # Build the library bundles to dist/
97
+ npm run build:lib
98
+
99
+ # (optional) link into another project while developing
100
+ # in this repo
101
+ npm pack # or use a local link strategy
102
+ # then in your host project
103
+ npm i ../path/to/@resulticks/trustsignal-*.tgz
104
+ ```
105
+
106
+ The library exports:
107
+
108
+ ```ts
109
+ import { TrustSignalProvider, Dashboard, CreateTemplate } from "@resulticks/trustsignal";
110
+ ```
111
+
112
+ CSS is automatically included via the package metadata, but you can also explicitly import it early in your app entry to ensure styles load before first paint:
113
+
114
+ ```ts
115
+ import "@resulticks/trustsignal/style.css";
116
+ ```
117
+
118
+ That's it—drop in `Dashboard` and toggle to `CreateTemplate` when the user clicks create. No routing library needed!