@simplr-ai/web-components 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Simplr
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,202 @@
1
+ # @simplr-ai/web-components
2
+
3
+ Framework-agnostic **Web Components** for the [Simplr](https://docs.simplr.so/docs/sdks/) platform.
4
+
5
+ One universal package of standard **Custom Elements** + a small imperative
6
+ controller that work in **any framework — Vue, Angular, Svelte, Astro, plain
7
+ HTML — or none**. It is a **thin adapter** over the browser core
8
+ [`@simplr-ai/js`](https://www.npmjs.com/package/@simplr-ai/js): it does not
9
+ reimplement any feature, it wraps the core's full surface as custom elements.
10
+
11
+ Covers the complete client feature surface:
12
+ **device fingerprint · behavioral biometrics · fraud/identity check (`/v1/check`) ·
13
+ order scoring (`/v1/orders`) · feature flags (local eval) · RUM · profiles · AI delegation · input validation helpers.**
14
+
15
+ ---
16
+
17
+ ## Install
18
+
19
+ ### npm / bun (bundled apps + frameworks)
20
+
21
+ ```bash
22
+ npm install @simplr-ai/web-components @simplr-ai/js
23
+ ```
24
+
25
+ ```js
26
+ import { defineSimplrElements, SimplrElements } from "@simplr-ai/web-components";
27
+
28
+ defineSimplrElements(); // register the custom elements
29
+ SimplrElements.configure({ apiKey: "pk_live_…" }); // or use <simplr-provider>
30
+ ```
31
+
32
+ ### `<script>` tag / CDN (zero build step)
33
+
34
+ The global bundle is **self-contained** — the core SDK is bundled inline. Just
35
+ drop in one tag; all elements auto-register.
36
+
37
+ ```html
38
+ <script src="https://cdn.jsdelivr.net/npm/@simplr-ai/web-components/dist/simplr-web-components.global.js"></script>
39
+
40
+ <simplr-provider api-key="pk_live_…" app-id="my-app"></simplr-provider>
41
+
42
+ <simplr-protected-form auto-check>
43
+ <form>
44
+ <input type="email" name="email" required />
45
+ <button type="submit">Sign up</button>
46
+ </form>
47
+ </simplr-protected-form>
48
+
49
+ <script>
50
+ document.querySelector("simplr-protected-form")
51
+ .addEventListener("simplr-submit", (e) => {
52
+ console.log(e.detail.signals, e.detail.check);
53
+ });
54
+ </script>
55
+ ```
56
+
57
+ Everything is also exposed on `window.SimplrWebComponents`.
58
+
59
+ ---
60
+
61
+ ## Configuration
62
+
63
+ Configure the shared client once — every element + helper reads from it. Any of:
64
+
65
+ 1. **`<simplr-provider>` element** — `api-key` (or `public-key`) attribute.
66
+ 2. **`data-simplr-key`** attribute on the provider, `<html>` or `<body>`.
67
+ 3. **`window.SIMPLR_CONFIG = { apiKey, baseUrl?, appId? }`** global.
68
+ 4. **Imperative** — `SimplrElements.configure({ apiKey, baseUrl?, autoStart?, flags?, profiles?, rum?, ai? })`.
69
+
70
+ ```html
71
+ <simplr-provider
72
+ api-key="pk_live_…"
73
+ base-url="https://api.simplr.sh"
74
+ app-id="my-app" <!-- enables RUM -->
75
+ flags="true" profiles="true" ai="true">
76
+ </simplr-provider>
77
+ ```
78
+
79
+ ---
80
+
81
+ ## Custom elements
82
+
83
+ ### `<simplr-provider>`
84
+ Configures the shared Simplr client and provides context to all descendant
85
+ elements. Emits `simplr-ready`.
86
+
87
+ ### `<simplr-protected-form>`
88
+ Wraps a `<form>` (via slot). On submit it collects device + behavioral signals
89
+ (and runs `/v1/check` if `auto-check` is set), injects a hidden
90
+ `simplr_signals` field, and emits a `simplr-submit` CustomEvent with
91
+ `{ signals, check, event }`. Native submit is prevented unless `native-submit`
92
+ is present.
93
+
94
+ ```html
95
+ <simplr-protected-form auto-check>
96
+ <form action="/signup" method="post">
97
+ <simplr-protected-input field="email"><input name="email" type="email" /></simplr-protected-input>
98
+ <button type="submit">Go</button>
99
+ </form>
100
+ </simplr-protected-form>
101
+ ```
102
+
103
+ ### `<simplr-protected-input field="email">`
104
+ Attaches keystroke biometrics to a slotted `<input>`/`<textarea>`.
105
+
106
+ ### `<simplr-feature-flag key="…" user-id="…">`
107
+ Renders its slotted content only when the flag is enabled (local eval, reacts to
108
+ flag refresh). Emits `simplr-flag`. Also use the helper `isFeatureEnabled(key, ctx?)`.
109
+
110
+ ```html
111
+ <simplr-feature-flag key="new-checkout" user-id="user_123">
112
+ <div>✨ new checkout</div>
113
+ </simplr-feature-flag>
114
+ ```
115
+
116
+ ### `<simplr-rum-view name="Checkout">`
117
+ Fires `trackView(name)` on connect (and when `name` changes). Auto-RUM init is
118
+ done through the provider's `app-id`. Emits `simplr-view`.
119
+
120
+ ### `<simplr-ai-delegation user-id="…">`
121
+ Slotted trigger (default a `<button>`); on click calls
122
+ `ai.createDelegation(...)` (or `ai.connect(...)` with `mode="connect"`) and emits
123
+ `simplr-delegation`. For `list`/`get`/`revoke`/`stats`/`validate`/`revokeAllForUser`
124
+ use `SimplrElements.ai` directly.
125
+
126
+ ---
127
+
128
+ ## Imperative controller (`SimplrElements`)
129
+
130
+ For non-HTML consumers (or alongside the elements):
131
+
132
+ ```ts
133
+ import { SimplrElements, isFeatureEnabled } from "@simplr-ai/web-components";
134
+
135
+ SimplrElements.configure({ apiKey: "pk_live_…", rum: { apiKey: "pk_live_…", applicationId: "my-app" } });
136
+
137
+ // Sub-clients (the full core surface)
138
+ SimplrElements.fraud // SimplrFraud — device fingerprint + biometrics
139
+ SimplrElements.flags // SimplrFlags — feature flags (local eval)
140
+ SimplrElements.profiles // SimplrProfiles — identify / submitOrder / risk / reportOutcome
141
+ SimplrElements.rum // SimplrRUM — trackView / trackAction / trackError / log …
142
+ SimplrElements.ai // SimplrAI — connect / createDelegation / validate / revoke / list / get / stats / revokeAllForUser
143
+
144
+ // Convenience
145
+ await SimplrElements.collect(); // device + behavior signals
146
+ await SimplrElements.getDeviceSignals(); // device fingerprint only
147
+ SimplrElements.getBehaviorSignals(); // biometrics (sync)
148
+ await SimplrElements.check({ email }); // POST /v1/check
149
+ SimplrElements.trackInput("email"); // keystroke handlers
150
+ isFeatureEnabled("new-checkout", { userId: "u_1" });
151
+ ```
152
+
153
+ ---
154
+
155
+ ## One-liner per framework
156
+
157
+ The same elements work everywhere — register once, use as normal tags.
158
+
159
+ **Plain HTML** — load the `<script>` global bundle (auto-registers), then use the tags.
160
+
161
+ **Vue** (`vite.config` `compilerOptions.isCustomElement = (t) => t.startsWith("simplr-")`):
162
+ ```js
163
+ import { defineSimplrElements } from "@simplr-ai/web-components"; defineSimplrElements();
164
+ ```
165
+ ```html
166
+ <simplr-feature-flag key="beta"><BetaBanner /></simplr-feature-flag>
167
+ ```
168
+
169
+ **Angular** (add `CUSTOM_ELEMENTS_SCHEMA` to the module/component):
170
+ ```ts
171
+ import { defineSimplrElements } from "@simplr-ai/web-components"; defineSimplrElements();
172
+ ```
173
+ ```html
174
+ <simplr-protected-form auto-check (simplr-submit)="onSubmit($event)"><form>…</form></simplr-protected-form>
175
+ ```
176
+
177
+ **Svelte** (works natively):
178
+ ```js
179
+ import { defineSimplrElements } from "@simplr-ai/web-components"; defineSimplrElements();
180
+ ```
181
+ ```svelte
182
+ <simplr-rum-view name="Checkout" />
183
+ ```
184
+
185
+ **Astro** (in a `client:load` script):
186
+ ```astro
187
+ <script>import { defineSimplrElements } from "@simplr-ai/web-components"; defineSimplrElements();</script>
188
+ <simplr-provider api-key="pk_live_…" />
189
+ ```
190
+
191
+ ---
192
+
193
+ ## SSR safety
194
+
195
+ Importing the package never touches `window`/`customElements`. Elements only
196
+ register when you call `defineSimplrElements()` in a browser (or load the global
197
+ bundle). The controller's collectors guard for non-browser environments.
198
+
199
+ ## License
200
+
201
+ MIT — wraps the [`@simplr-ai/js`](https://www.npmjs.com/package/@simplr-ai/js)
202
+ core. Docs: <https://docs.simplr.so/docs/sdks/> (Web Components page).