@resulticks/trustsignal-wa-hsm 0.5.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
@@ -11,49 +11,84 @@ The library ships its own compiled styles, so you only need to import the CSS on
11
11
  ## Installation
12
12
 
13
13
  ```bash
14
- npm i @resulticks/trustsignal react react-dom react-router-dom
14
+ npm i @resulticks/trustsignal react react-dom
15
15
  ```
16
16
 
17
- > react, react-dom and react-router-dom are peer dependencies and must be installed in the host app.
17
+ > react and react-dom are peer dependencies and must be installed in the host app.
18
18
 
19
- ## Quick Start (Routing Example)
19
+ ## Quick Start (State-Based Toggling - No Routing Required)
20
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.
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
22
 
23
23
  ```tsx
24
- import { BrowserRouter, Routes, Route, useNavigate, Navigate } from "react-router-dom";
24
+ import { useState } from "react";
25
25
  import { TrustSignalProvider, Dashboard, CreateTemplate } from "@resulticks/trustsignal";
26
26
  import "@resulticks/trustsignal/style.css";
27
27
 
28
- function AppRoutes() {
29
- const navigate = useNavigate();
30
- return (
31
- <Routes>
32
- <Route path="/" element={<Dashboard />} />
28
+ type View = 'dashboard' | 'create' | 'edit';
33
29
 
34
- <Route path="/create" element={<CreateTemplate onCancel={() => navigate("/")} />} />
30
+ export default function App() {
31
+ const [currentView, setCurrentView] = useState<View>('dashboard');
32
+ const [editId, setEditId] = useState<string | null>(null);
35
33
 
36
- <Route path="*" element={<Navigate to="/" replace />} />
37
- </Routes>
38
- );
39
- }
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
+ };
40
48
 
41
- export default function App() {
42
49
  return (
43
- <BrowserRouter>
44
- <TrustSignalProvider apiKey="YOUR_API_KEY">
45
- <AppRoutes />
46
- </TrustSignalProvider>
47
- </BrowserRouter>
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>
48
72
  );
49
73
  }
50
74
  ```
51
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
+
52
86
  ### Notes
53
87
  - Import the stylesheet once: `import "@resulticks/trustsignal/style.css";`
54
- - The provider writes the `apiKey` to `localStorage('account')` so all API calls work without additional wiring.
55
- - If your Dashboard navigates to a different path for creation, add a matching `<Route>` that renders `<CreateTemplate />` for that path.
56
- - You can supply a custom `onCancel` to control navigation from the builder.
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.
57
92
 
58
93
  ## Local Development / Building the Library (inside this repo)
59
94
 
@@ -80,4 +115,4 @@ CSS is automatically included via the package metadata, but you can also explici
80
115
  import "@resulticks/trustsignal/style.css";
81
116
  ```
82
117
 
83
- Thats it—drop in `Dashboard` and route to `CreateTemplate` when the user clicks create.
118
+ That's it—drop in `Dashboard` and toggle to `CreateTemplate` when the user clicks create. No routing library needed!
@@ -0,0 +1,17 @@
1
+ async function a(o, c) {
2
+ const n = `https://wpapi.trustsignal.io/v1/user-templates/${encodeURIComponent(c)}?api_key=${encodeURIComponent(o)}`, s = await fetch(n, {
3
+ method: "POST",
4
+ redirect: "follow"
5
+ }), t = await s.text();
6
+ if (!s.ok)
7
+ return { success: !1, message: `Delete failed (${s.status}): ${t}` };
8
+ try {
9
+ const e = JSON.parse(t);
10
+ return { success: !!((e == null ? void 0 : e.success) ?? !0), message: e == null ? void 0 : e.message };
11
+ } catch {
12
+ return { success: !0 };
13
+ }
14
+ }
15
+ export {
16
+ a as deleteTemplateById
17
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});async function r(o,c){const n=`https://wpapi.trustsignal.io/v1/user-templates/${encodeURIComponent(c)}?api_key=${encodeURIComponent(o)}`,t=await fetch(n,{method:"POST",redirect:"follow"}),s=await t.text();if(!t.ok)return{success:!1,message:`Delete failed (${t.status}): ${s}`};try{const e=JSON.parse(s);return{success:!!((e==null?void 0:e.success)??!0),message:e==null?void 0:e.message}}catch{return{success:!0}}}exports.deleteTemplateById=r;