@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 +21 -0
- package/README.md +202 -0
- package/dist/index.cjs +573 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +211 -0
- package/dist/index.d.ts +211 -0
- package/dist/index.js +506 -0
- package/dist/index.js.map +1 -0
- package/dist/simplr-web-components.global.js +6 -0
- package/dist/simplr-web-components.global.js.map +1 -0
- package/package.json +62 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
import { SimplrFraud, SimplrFlags, SimplrProfiles, simplrRUM, SimplrAI } from '@simplr-ai/js';
|
|
2
|
+
export { SimplrAI, SimplrFlags, SimplrFraud, SimplrProfiles, SimplrRUM, clearDeviceId, createFingerprintHash, createSimplrAI, createSimplrProfiles, getDeviceId, murmurHash3, sha256, simplrFlags, simplrRUM } from '@simplr-ai/js';
|
|
3
|
+
|
|
4
|
+
// src/controller.ts
|
|
5
|
+
var DEFAULT_BASE_URL = "https://api.simplr.sh";
|
|
6
|
+
function resolveBlock(block, fallback) {
|
|
7
|
+
if (block === false || block === void 0) return void 0;
|
|
8
|
+
if (block === true) return fallback;
|
|
9
|
+
return { ...fallback, ...block };
|
|
10
|
+
}
|
|
11
|
+
var SimplrController = class {
|
|
12
|
+
constructor() {
|
|
13
|
+
this._config = null;
|
|
14
|
+
this._baseUrl = DEFAULT_BASE_URL;
|
|
15
|
+
/** Core device-fingerprint + behavioral-biometrics client. */
|
|
16
|
+
this.fraud = null;
|
|
17
|
+
/** Feature flags (local eval + murmurhash bucketing). */
|
|
18
|
+
this.flags = null;
|
|
19
|
+
/** Anonymous profiles + order fraud monitoring. */
|
|
20
|
+
this.profiles = null;
|
|
21
|
+
/** Real User Monitoring (shared core singleton). */
|
|
22
|
+
this.rum = null;
|
|
23
|
+
/** AI delegation (OAuth-like). */
|
|
24
|
+
this.ai = null;
|
|
25
|
+
this.readyResolvers = [];
|
|
26
|
+
this._ready = false;
|
|
27
|
+
}
|
|
28
|
+
/** True once {@link configure} has built the core clients. */
|
|
29
|
+
get isConfigured() {
|
|
30
|
+
return this._config !== null;
|
|
31
|
+
}
|
|
32
|
+
/** The resolved public API key, or undefined if not configured. */
|
|
33
|
+
get apiKey() {
|
|
34
|
+
return this._config?.apiKey;
|
|
35
|
+
}
|
|
36
|
+
/** The resolved API base URL. */
|
|
37
|
+
get baseUrl() {
|
|
38
|
+
return this._baseUrl;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Configure the shared client. Idempotent: if already configured with the
|
|
42
|
+
* same key it is a no-op, so multiple `<simplr-provider>` mounts are safe.
|
|
43
|
+
*/
|
|
44
|
+
configure(config) {
|
|
45
|
+
if (this._config && this._config.apiKey === config.apiKey) {
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
this._config = {
|
|
49
|
+
autoStart: true,
|
|
50
|
+
collectBiometrics: true,
|
|
51
|
+
...config
|
|
52
|
+
};
|
|
53
|
+
this._baseUrl = (config.baseUrl || DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
54
|
+
const apiKey = config.apiKey;
|
|
55
|
+
this.fraud = new SimplrFraud({
|
|
56
|
+
apiKey,
|
|
57
|
+
autoStart: this._config.autoStart,
|
|
58
|
+
collectBiometrics: this._config.collectBiometrics,
|
|
59
|
+
...config.fraud
|
|
60
|
+
});
|
|
61
|
+
const flagsConfig = resolveBlock(
|
|
62
|
+
config.flags === void 0 ? true : config.flags,
|
|
63
|
+
{ apiKey, baseUrl: this._baseUrl }
|
|
64
|
+
);
|
|
65
|
+
if (flagsConfig) {
|
|
66
|
+
this.flags = new SimplrFlags();
|
|
67
|
+
void this.flags.initialize(flagsConfig);
|
|
68
|
+
}
|
|
69
|
+
const profilesConfig = resolveBlock(
|
|
70
|
+
config.profiles === void 0 ? true : config.profiles,
|
|
71
|
+
{ apiKey, baseUrl: this._baseUrl }
|
|
72
|
+
);
|
|
73
|
+
if (profilesConfig) {
|
|
74
|
+
this.profiles = new SimplrProfiles(profilesConfig);
|
|
75
|
+
this.profiles.setDeviceSignalCollector(() => this.fraud.collectDeviceSignals());
|
|
76
|
+
}
|
|
77
|
+
if (config.rum) {
|
|
78
|
+
if (!simplrRUM.isInitialized()) {
|
|
79
|
+
simplrRUM.initialize(config.rum);
|
|
80
|
+
}
|
|
81
|
+
this.rum = simplrRUM;
|
|
82
|
+
}
|
|
83
|
+
const aiConfig = resolveBlock(
|
|
84
|
+
config.ai === void 0 ? true : config.ai,
|
|
85
|
+
{ apiKey }
|
|
86
|
+
);
|
|
87
|
+
if (aiConfig && aiConfig.apiKey) {
|
|
88
|
+
this.ai = new SimplrAI(aiConfig);
|
|
89
|
+
}
|
|
90
|
+
this._ready = true;
|
|
91
|
+
this.readyResolvers.splice(0).forEach((r) => r());
|
|
92
|
+
if (typeof window !== "undefined") {
|
|
93
|
+
window.dispatchEvent(new CustomEvent("simplr:configured", { detail: { controller: this } }));
|
|
94
|
+
}
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
/** Resolves once the controller has been configured. */
|
|
98
|
+
ready() {
|
|
99
|
+
if (this._ready) return Promise.resolve();
|
|
100
|
+
return new Promise((resolve) => this.readyResolvers.push(resolve));
|
|
101
|
+
}
|
|
102
|
+
requireFraud() {
|
|
103
|
+
if (!this.fraud) {
|
|
104
|
+
throw new Error(
|
|
105
|
+
'Simplr is not configured. Call SimplrElements.configure({ apiKey }) or add a <simplr-provider api-key="pk_..."> element first.'
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
return this.fraud;
|
|
109
|
+
}
|
|
110
|
+
// --- Signal collection (delegates to the core fraud client) --------------
|
|
111
|
+
/** Collect device fingerprint + behavioral biometrics together. */
|
|
112
|
+
collect() {
|
|
113
|
+
return this.requireFraud().collect();
|
|
114
|
+
}
|
|
115
|
+
/** Collect device fingerprint signals only. */
|
|
116
|
+
getDeviceSignals() {
|
|
117
|
+
return this.requireFraud().collectDeviceSignals();
|
|
118
|
+
}
|
|
119
|
+
/** Collect behavioral biometric signals only (sync). */
|
|
120
|
+
getBehaviorSignals() {
|
|
121
|
+
return this.requireFraud().collectBehaviorSignals();
|
|
122
|
+
}
|
|
123
|
+
/** Input tracking handlers/attrs for a named field (keystroke biometrics). */
|
|
124
|
+
trackInput(fieldName) {
|
|
125
|
+
return this.requireFraud().trackInput(fieldName);
|
|
126
|
+
}
|
|
127
|
+
/** Reset collected behavioral data. */
|
|
128
|
+
reset() {
|
|
129
|
+
this.requireFraud().reset();
|
|
130
|
+
}
|
|
131
|
+
// --- API calls (public-key ingestion, per the contract) ------------------
|
|
132
|
+
/**
|
|
133
|
+
* Run a fraud/identity check (POST `/v1/check`). Device + behavior signals
|
|
134
|
+
* are auto-collected and merged into the request unless already on `input`.
|
|
135
|
+
*/
|
|
136
|
+
async check(input = {}) {
|
|
137
|
+
const collected = await this.collect();
|
|
138
|
+
const body = {
|
|
139
|
+
...input,
|
|
140
|
+
device: input.device ?? collected.device,
|
|
141
|
+
behavior: input.behavior ?? collected.behavior
|
|
142
|
+
};
|
|
143
|
+
return this.request("/v1/check", body);
|
|
144
|
+
}
|
|
145
|
+
async request(path, body) {
|
|
146
|
+
const apiKey = this.apiKey;
|
|
147
|
+
if (!apiKey) throw new Error("Simplr is not configured (missing apiKey).");
|
|
148
|
+
const res = await fetch(`${this._baseUrl}${path}`, {
|
|
149
|
+
method: "POST",
|
|
150
|
+
headers: { "Content-Type": "application/json", "X-API-Key": apiKey },
|
|
151
|
+
body: JSON.stringify(body)
|
|
152
|
+
});
|
|
153
|
+
const json = await res.json().catch(() => null);
|
|
154
|
+
if (!res.ok) {
|
|
155
|
+
const message = json && (json.message || json.error) || `Simplr API error ${res.status}`;
|
|
156
|
+
throw new Error(message);
|
|
157
|
+
}
|
|
158
|
+
return json && "content" in json ? json.content : json;
|
|
159
|
+
}
|
|
160
|
+
// --- Feature flags helper ------------------------------------------------
|
|
161
|
+
/** Evaluate a feature flag locally. Returns false if flags aren't enabled. */
|
|
162
|
+
isFeatureEnabled(key, ctx) {
|
|
163
|
+
return this.flags ? this.flags.isEnabled(key, ctx) : false;
|
|
164
|
+
}
|
|
165
|
+
/** Tear down timers / trackers (useful for tests + SPA teardown). */
|
|
166
|
+
dispose() {
|
|
167
|
+
this.fraud?.stopTracking();
|
|
168
|
+
this.flags?.dispose();
|
|
169
|
+
this.rum?.stopSession();
|
|
170
|
+
this._config = null;
|
|
171
|
+
this._ready = false;
|
|
172
|
+
this.fraud = this.flags = this.profiles = this.ai = this.rum = null;
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
var SimplrElements = new SimplrController();
|
|
176
|
+
function isFeatureEnabled(key, ctx) {
|
|
177
|
+
return SimplrElements.isFeatureEnabled(key, ctx);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// src/elements/provider.ts
|
|
181
|
+
function readKey(el) {
|
|
182
|
+
return el.getAttribute("api-key") || el.getAttribute("public-key") || el.getAttribute("publicKey") || el.getAttribute("data-simplr-key") || (typeof document !== "undefined" ? document.documentElement.getAttribute("data-simplr-key") || document.body?.getAttribute("data-simplr-key") || void 0 : void 0) || (typeof window !== "undefined" ? window.SIMPLR_CONFIG?.apiKey || window.SIMPLR_CONFIG?.publicKey : void 0) || void 0;
|
|
183
|
+
}
|
|
184
|
+
function flagFor(el, name, fallback) {
|
|
185
|
+
if (!el.hasAttribute(name)) return fallback;
|
|
186
|
+
const v = el.getAttribute(name);
|
|
187
|
+
return v !== "false" && v !== "off" && v !== "0";
|
|
188
|
+
}
|
|
189
|
+
var SimplrProviderElement = class extends HTMLElement {
|
|
190
|
+
static get observedAttributes() {
|
|
191
|
+
return ["api-key", "public-key", "base-url"];
|
|
192
|
+
}
|
|
193
|
+
connectedCallback() {
|
|
194
|
+
this.tryConfigure();
|
|
195
|
+
}
|
|
196
|
+
attributeChangedCallback() {
|
|
197
|
+
if (this.isConnected) this.tryConfigure();
|
|
198
|
+
}
|
|
199
|
+
tryConfigure() {
|
|
200
|
+
const apiKey = readKey(this);
|
|
201
|
+
if (!apiKey) return;
|
|
202
|
+
const appId = this.getAttribute("app-id") || (typeof window !== "undefined" ? window.SIMPLR_CONFIG?.appId : void 0);
|
|
203
|
+
SimplrElements.configure({
|
|
204
|
+
apiKey,
|
|
205
|
+
baseUrl: this.getAttribute("base-url") || (typeof window !== "undefined" ? window.SIMPLR_CONFIG?.baseUrl : void 0) || void 0,
|
|
206
|
+
autoStart: !this.hasAttribute("no-autostart"),
|
|
207
|
+
flags: flagFor(this, "flags", true),
|
|
208
|
+
profiles: flagFor(this, "profiles", true),
|
|
209
|
+
ai: flagFor(this, "ai", true),
|
|
210
|
+
rum: appId ? { apiKey, applicationId: appId } : void 0
|
|
211
|
+
});
|
|
212
|
+
this.dispatchEvent(
|
|
213
|
+
new CustomEvent("simplr-ready", {
|
|
214
|
+
bubbles: true,
|
|
215
|
+
composed: true,
|
|
216
|
+
detail: { controller: SimplrElements }
|
|
217
|
+
})
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
// src/elements/protected-form.ts
|
|
223
|
+
var SimplrProtectedFormElement = class extends HTMLElement {
|
|
224
|
+
constructor() {
|
|
225
|
+
super(...arguments);
|
|
226
|
+
this.form = null;
|
|
227
|
+
this.onSubmit = (e) => this.handleSubmit(e);
|
|
228
|
+
}
|
|
229
|
+
connectedCallback() {
|
|
230
|
+
this.form = this.querySelector("form");
|
|
231
|
+
const target = this.form ?? this;
|
|
232
|
+
target.addEventListener("submit", this.onSubmit);
|
|
233
|
+
}
|
|
234
|
+
disconnectedCallback() {
|
|
235
|
+
const target = this.form ?? this;
|
|
236
|
+
target.removeEventListener("submit", this.onSubmit);
|
|
237
|
+
}
|
|
238
|
+
/** Field name used for the hidden signals input. */
|
|
239
|
+
get fieldName() {
|
|
240
|
+
return this.getAttribute("field-name") || "simplr_signals";
|
|
241
|
+
}
|
|
242
|
+
async handleSubmit(event) {
|
|
243
|
+
const allowNative = this.hasAttribute("native-submit");
|
|
244
|
+
if (!allowNative) event.preventDefault();
|
|
245
|
+
this.setAttribute("submitting", "");
|
|
246
|
+
try {
|
|
247
|
+
const signals = await SimplrElements.collect();
|
|
248
|
+
let check;
|
|
249
|
+
if (this.hasAttribute("auto-check")) {
|
|
250
|
+
const form = this.form ?? event.target;
|
|
251
|
+
const input = {};
|
|
252
|
+
const email = form?.querySelector?.('[type="email"], [name="email"]');
|
|
253
|
+
if (email?.value) input.email = email.value;
|
|
254
|
+
check = await SimplrElements.check(input);
|
|
255
|
+
}
|
|
256
|
+
if (this.form) {
|
|
257
|
+
let hidden = this.form.querySelector(
|
|
258
|
+
`input[name="${this.fieldName}"]`
|
|
259
|
+
);
|
|
260
|
+
if (!hidden) {
|
|
261
|
+
hidden = document.createElement("input");
|
|
262
|
+
hidden.type = "hidden";
|
|
263
|
+
hidden.name = this.fieldName;
|
|
264
|
+
this.form.appendChild(hidden);
|
|
265
|
+
}
|
|
266
|
+
hidden.value = JSON.stringify({ signals, check });
|
|
267
|
+
}
|
|
268
|
+
this.dispatchEvent(
|
|
269
|
+
new CustomEvent("simplr-submit", {
|
|
270
|
+
bubbles: true,
|
|
271
|
+
composed: true,
|
|
272
|
+
detail: { signals, check, event }
|
|
273
|
+
})
|
|
274
|
+
);
|
|
275
|
+
} catch (e) {
|
|
276
|
+
this.dispatchEvent(
|
|
277
|
+
new CustomEvent("simplr-error", {
|
|
278
|
+
bubbles: true,
|
|
279
|
+
composed: true,
|
|
280
|
+
detail: { error: e instanceof Error ? e : new Error(String(e)) }
|
|
281
|
+
})
|
|
282
|
+
);
|
|
283
|
+
} finally {
|
|
284
|
+
this.removeAttribute("submitting");
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
// src/elements/protected-input.ts
|
|
290
|
+
var SimplrProtectedInputElement = class extends HTMLElement {
|
|
291
|
+
constructor() {
|
|
292
|
+
super(...arguments);
|
|
293
|
+
this.input = null;
|
|
294
|
+
this.handlers = null;
|
|
295
|
+
this.bound = {};
|
|
296
|
+
}
|
|
297
|
+
static get observedAttributes() {
|
|
298
|
+
return ["field"];
|
|
299
|
+
}
|
|
300
|
+
get field() {
|
|
301
|
+
return this.getAttribute("field") || "input";
|
|
302
|
+
}
|
|
303
|
+
connectedCallback() {
|
|
304
|
+
queueMicrotask(() => this.attach());
|
|
305
|
+
}
|
|
306
|
+
disconnectedCallback() {
|
|
307
|
+
this.detach();
|
|
308
|
+
}
|
|
309
|
+
attributeChangedCallback() {
|
|
310
|
+
if (this.isConnected) {
|
|
311
|
+
this.detach();
|
|
312
|
+
this.attach();
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
attach() {
|
|
316
|
+
if (!SimplrElements.fraud) return;
|
|
317
|
+
this.input = this.querySelector("input") || this.querySelector("textarea") || null;
|
|
318
|
+
if (!this.input) return;
|
|
319
|
+
this.handlers = SimplrElements.trackInput(this.field);
|
|
320
|
+
this.input.setAttribute("data-simplr-field", this.field);
|
|
321
|
+
this.bound.down = (e) => this.handlers.onKeyDown(e);
|
|
322
|
+
this.bound.up = (e) => this.handlers.onKeyUp(e);
|
|
323
|
+
this.bound.paste = () => this.handlers.onPaste();
|
|
324
|
+
this.input.addEventListener("keydown", this.bound.down);
|
|
325
|
+
this.input.addEventListener("keyup", this.bound.up);
|
|
326
|
+
this.input.addEventListener("paste", this.bound.paste);
|
|
327
|
+
}
|
|
328
|
+
detach() {
|
|
329
|
+
if (!this.input) return;
|
|
330
|
+
if (this.bound.down) this.input.removeEventListener("keydown", this.bound.down);
|
|
331
|
+
if (this.bound.up) this.input.removeEventListener("keyup", this.bound.up);
|
|
332
|
+
if (this.bound.paste) this.input.removeEventListener("paste", this.bound.paste);
|
|
333
|
+
this.bound = {};
|
|
334
|
+
this.input = null;
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
// src/elements/feature-flag.ts
|
|
339
|
+
var SimplrFeatureFlagElement = class extends HTMLElement {
|
|
340
|
+
constructor() {
|
|
341
|
+
super(...arguments);
|
|
342
|
+
this.onConfigured = () => this.evaluate();
|
|
343
|
+
this.poll = null;
|
|
344
|
+
}
|
|
345
|
+
static get observedAttributes() {
|
|
346
|
+
return ["key", "user-id"];
|
|
347
|
+
}
|
|
348
|
+
connectedCallback() {
|
|
349
|
+
if (typeof window !== "undefined") {
|
|
350
|
+
window.addEventListener("simplr:configured", this.onConfigured);
|
|
351
|
+
}
|
|
352
|
+
this.evaluate();
|
|
353
|
+
this.poll = setInterval(() => this.evaluate(), 2e3);
|
|
354
|
+
}
|
|
355
|
+
disconnectedCallback() {
|
|
356
|
+
if (typeof window !== "undefined") {
|
|
357
|
+
window.removeEventListener("simplr:configured", this.onConfigured);
|
|
358
|
+
}
|
|
359
|
+
if (this.poll) clearInterval(this.poll);
|
|
360
|
+
this.poll = null;
|
|
361
|
+
}
|
|
362
|
+
attributeChangedCallback() {
|
|
363
|
+
if (this.isConnected) this.evaluate();
|
|
364
|
+
}
|
|
365
|
+
/** The flag key. */
|
|
366
|
+
get key() {
|
|
367
|
+
return this.getAttribute("key") || "";
|
|
368
|
+
}
|
|
369
|
+
/** Whether this flag currently evaluates to enabled. */
|
|
370
|
+
get enabled() {
|
|
371
|
+
if (!this.key) return false;
|
|
372
|
+
const ctx = {};
|
|
373
|
+
const userId = this.getAttribute("user-id");
|
|
374
|
+
if (userId) ctx.userId = userId;
|
|
375
|
+
return SimplrElements.isFeatureEnabled(this.key, ctx);
|
|
376
|
+
}
|
|
377
|
+
evaluate() {
|
|
378
|
+
const on = this.enabled;
|
|
379
|
+
if (on) {
|
|
380
|
+
this.removeAttribute("hidden");
|
|
381
|
+
this.setAttribute("enabled", "");
|
|
382
|
+
} else {
|
|
383
|
+
this.setAttribute("hidden", "");
|
|
384
|
+
this.removeAttribute("enabled");
|
|
385
|
+
}
|
|
386
|
+
this.dispatchEvent(
|
|
387
|
+
new CustomEvent("simplr-flag", {
|
|
388
|
+
bubbles: true,
|
|
389
|
+
composed: true,
|
|
390
|
+
detail: { key: this.key, enabled: on }
|
|
391
|
+
})
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
// src/elements/rum-view.ts
|
|
397
|
+
var SimplrRumViewElement = class extends HTMLElement {
|
|
398
|
+
static get observedAttributes() {
|
|
399
|
+
return ["name"];
|
|
400
|
+
}
|
|
401
|
+
get viewName() {
|
|
402
|
+
return this.getAttribute("name") || (typeof location !== "undefined" ? location.pathname : "/");
|
|
403
|
+
}
|
|
404
|
+
connectedCallback() {
|
|
405
|
+
this.track();
|
|
406
|
+
}
|
|
407
|
+
attributeChangedCallback(_n, oldV, newV) {
|
|
408
|
+
if (this.isConnected && oldV !== newV) this.track();
|
|
409
|
+
}
|
|
410
|
+
track() {
|
|
411
|
+
const rum = SimplrElements.rum;
|
|
412
|
+
if (rum && rum.isInitialized()) {
|
|
413
|
+
rum.trackView(this.viewName);
|
|
414
|
+
this.dispatchEvent(
|
|
415
|
+
new CustomEvent("simplr-view", {
|
|
416
|
+
bubbles: true,
|
|
417
|
+
composed: true,
|
|
418
|
+
detail: { name: this.viewName, viewId: rum.getViewId() }
|
|
419
|
+
})
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
// src/elements/ai-delegation.ts
|
|
426
|
+
var SimplrAiDelegationElement = class extends HTMLElement {
|
|
427
|
+
constructor() {
|
|
428
|
+
super(...arguments);
|
|
429
|
+
this.trigger = null;
|
|
430
|
+
this.onClick = () => this.run();
|
|
431
|
+
}
|
|
432
|
+
connectedCallback() {
|
|
433
|
+
queueMicrotask(() => {
|
|
434
|
+
this.trigger = this.querySelector("[slot=trigger]") || this.querySelector("button") || this;
|
|
435
|
+
this.trigger.addEventListener("click", this.onClick);
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
disconnectedCallback() {
|
|
439
|
+
this.trigger?.removeEventListener("click", this.onClick);
|
|
440
|
+
}
|
|
441
|
+
get userId() {
|
|
442
|
+
return this.getAttribute("user-id") || "";
|
|
443
|
+
}
|
|
444
|
+
async run() {
|
|
445
|
+
const ai = SimplrElements.ai;
|
|
446
|
+
if (!ai) {
|
|
447
|
+
this.dispatchEvent(
|
|
448
|
+
new CustomEvent("simplr-error", {
|
|
449
|
+
bubbles: true,
|
|
450
|
+
composed: true,
|
|
451
|
+
detail: { error: new Error("AI delegation is not configured.") }
|
|
452
|
+
})
|
|
453
|
+
);
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
const binding = this.getAttribute("binding") || void 0;
|
|
457
|
+
const email = this.getAttribute("email") || void 0;
|
|
458
|
+
let fingerprintHash;
|
|
459
|
+
try {
|
|
460
|
+
if (SimplrElements.fraud) {
|
|
461
|
+
fingerprintHash = (await SimplrElements.getDeviceSignals()).fingerprint;
|
|
462
|
+
}
|
|
463
|
+
} catch {
|
|
464
|
+
}
|
|
465
|
+
try {
|
|
466
|
+
const result = this.getAttribute("mode") === "connect" ? await ai.connect({ userId: this.userId, email, binding, fingerprintHash }) : await ai.createDelegation({ userId: this.userId, email, binding, fingerprintHash });
|
|
467
|
+
this.dispatchEvent(
|
|
468
|
+
new CustomEvent("simplr-delegation", {
|
|
469
|
+
bubbles: true,
|
|
470
|
+
composed: true,
|
|
471
|
+
detail: { result }
|
|
472
|
+
})
|
|
473
|
+
);
|
|
474
|
+
} catch (e) {
|
|
475
|
+
this.dispatchEvent(
|
|
476
|
+
new CustomEvent("simplr-error", {
|
|
477
|
+
bubbles: true,
|
|
478
|
+
composed: true,
|
|
479
|
+
detail: { error: e instanceof Error ? e : new Error(String(e)) }
|
|
480
|
+
})
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
// src/define.ts
|
|
487
|
+
var SIMPLR_ELEMENTS = {
|
|
488
|
+
"simplr-provider": SimplrProviderElement,
|
|
489
|
+
"simplr-protected-form": SimplrProtectedFormElement,
|
|
490
|
+
"simplr-protected-input": SimplrProtectedInputElement,
|
|
491
|
+
"simplr-feature-flag": SimplrFeatureFlagElement,
|
|
492
|
+
"simplr-rum-view": SimplrRumViewElement,
|
|
493
|
+
"simplr-ai-delegation": SimplrAiDelegationElement
|
|
494
|
+
};
|
|
495
|
+
function defineSimplrElements() {
|
|
496
|
+
if (typeof customElements === "undefined") return;
|
|
497
|
+
for (const [tag, ctor] of Object.entries(SIMPLR_ELEMENTS)) {
|
|
498
|
+
if (!customElements.get(tag)) {
|
|
499
|
+
customElements.define(tag, ctor);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
export { SIMPLR_ELEMENTS, SimplrAiDelegationElement, SimplrController, SimplrElements, SimplrFeatureFlagElement, SimplrProtectedFormElement, SimplrProtectedInputElement, SimplrProviderElement, SimplrRumViewElement, defineSimplrElements, isFeatureEnabled };
|
|
505
|
+
//# sourceMappingURL=index.js.map
|
|
506
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/controller.ts","../src/elements/provider.ts","../src/elements/protected-form.ts","../src/elements/protected-input.ts","../src/elements/feature-flag.ts","../src/elements/rum-view.ts","../src/elements/ai-delegation.ts","../src/define.ts"],"names":[],"mappings":";;;;AA6BA,IAAM,gBAAA,GAAmB,uBAAA;AAoDzB,SAAS,YAAA,CACP,OACA,QAAA,EACe;AACf,EAAA,IAAI,KAAA,KAAU,KAAA,IAAS,KAAA,KAAU,MAAA,EAAW,OAAO,MAAA;AACnD,EAAA,IAAI,KAAA,KAAU,MAAM,OAAO,QAAA;AAC3B,EAAA,OAAO,EAAE,GAAG,QAAA,EAAU,GAAG,KAAA,EAAM;AACjC;AAMO,IAAM,mBAAN,MAAuB;AAAA,EAAvB,WAAA,GAAA;AACL,IAAA,IAAA,CAAQ,OAAA,GAA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,EACvB,iBAAA,EAAmB,oBAAA;AAAA,EACnB,sBAAA,EAAwB;AAC1B;AAOO,SAAS,oBAAA,GAA6B;AAC3C,EAAA,IAAI,OAAO,mBAAmB,WAAA,EAAa;AAC3C,EAAA,KAAA,MAAW,CAAC,GAAA,EAAK,IAAI,KAAK,MAAA,CAAO,OAAA,CAAQ,eAAe,CAAA,EAAG;AACzD,IAAA,IAAI,CAAC,cAAA,CAAe,GAAA,CAAI,GAAG,CAAA,EAAG;AAC5B,MAAA,cAAA,CAAe,MAAA,CAAO,KAAK,IAAI,CAAA;AAAA,IACjC;AAAA,EACF;AACF","file":"index.js","sourcesContent":["/**\n * SimplrElements — the shared imperative controller / singleton.\n *\n * Builds and holds the configured `@simplr-ai/js` core instances\n * (SimplrFraud + SimplrFlags + SimplrProfiles + SimplrRUM + SimplrAI) so that\n * every custom element AND non-HTML consumers share ONE configured client.\n *\n * This is a THIN adapter — it never reimplements features. `check()` and\n * `submitOrder()` POST to the documented public-key endpoints (`/v1/check`,\n * `/v1/orders`) exactly as specified in the Simplr API contract, attaching the\n * device + behavior signals collected by the core fraud client.\n */\nimport {\n SimplrFraud,\n SimplrFlags,\n SimplrProfiles,\n SimplrAI,\n simplrRUM,\n type SimplrFraudConfig,\n type SimplrFlagsConfig,\n type SimplrProfilesConfig,\n type SimplrRUMConfig,\n type AIDelegationConfig,\n type CollectedSignals,\n type DeviceSignals,\n type BehaviorSignals,\n type EvalContext,\n} from \"@simplr-ai/js\";\n\nconst DEFAULT_BASE_URL = \"https://api.simplr.sh\";\n\n/** POST /v1/check input (public-key client ingestion). */\nexport interface CheckInput {\n email?: string;\n phone?: string;\n device?: Record<string, unknown>;\n behavior?: Record<string, unknown>;\n event_type?: string;\n event_id?: string;\n metadata?: Record<string, unknown>;\n [key: string]: unknown;\n}\n\nexport type RiskLevel = \"low\" | \"medium\" | \"high\" | \"critical\";\n\n/** POST /v1/check result. */\nexport interface CheckResult {\n type?: string;\n risk_score: number;\n risk_level: RiskLevel;\n signals?: Record<string, unknown>;\n email?: string;\n phone_number?: string;\n fingerprint_hash?: string;\n checked_at?: string;\n is_sandbox?: boolean;\n [key: string]: unknown;\n}\n\n/** Configuration accepted by {@link SimplrController.configure}. */\nexport interface SimplrConfig {\n /** Public API key (`pk_*`) — safe for the client. */\n apiKey: string;\n /** API base URL override (default `https://api.simplr.sh`). */\n baseUrl?: string;\n /** Whether to auto-start biometric tracking on configure (default true). */\n autoStart?: boolean;\n /** Whether to collect behavioral biometrics (default true). */\n collectBiometrics?: boolean;\n /** Core fraud / device-signal config overrides. */\n fraud?: SimplrFraudConfig;\n /** Feature-flags config. `true` = enable with defaults, object = customise, omit/false = skip. */\n flags?: Partial<SimplrFlagsConfig> | boolean;\n /** Profiles config. `true` = enable with the shared key/baseUrl, object = customise. */\n profiles?: Partial<SimplrProfilesConfig> | boolean;\n /** RUM config — requires at least `applicationId`. Omit to skip RUM. */\n rum?: SimplrRUMConfig;\n /** AI delegation config. `true` = enable with the shared key, object = customise. */\n ai?: Partial<AIDelegationConfig> | boolean;\n}\n\nfunction resolveBlock<T extends object>(\n block: Partial<T> | boolean | undefined,\n fallback: T,\n): T | undefined {\n if (block === false || block === undefined) return undefined;\n if (block === true) return fallback;\n return { ...fallback, ...block } as T;\n}\n\n/**\n * The Simplr controller. A single shared instance ({@link SimplrElements}) is\n * exported; call `.configure()` once and every element + helper reads from it.\n */\nexport class SimplrController {\n private _config: SimplrConfig | null = null;\n private _baseUrl = DEFAULT_BASE_URL;\n\n /** Core device-fingerprint + behavioral-biometrics client. */\n fraud: SimplrFraud | null = null;\n /** Feature flags (local eval + murmurhash bucketing). */\n flags: SimplrFlags | null = null;\n /** Anonymous profiles + order fraud monitoring. */\n profiles: SimplrProfiles | null = null;\n /** Real User Monitoring (shared core singleton). */\n rum: typeof simplrRUM | null = null;\n /** AI delegation (OAuth-like). */\n ai: SimplrAI | null = null;\n\n private readyResolvers: Array<() => void> = [];\n private _ready = false;\n\n /** True once {@link configure} has built the core clients. */\n get isConfigured(): boolean {\n return this._config !== null;\n }\n\n /** The resolved public API key, or undefined if not configured. */\n get apiKey(): string | undefined {\n return this._config?.apiKey;\n }\n\n /** The resolved API base URL. */\n get baseUrl(): string {\n return this._baseUrl;\n }\n\n /**\n * Configure the shared client. Idempotent: if already configured with the\n * same key it is a no-op, so multiple `<simplr-provider>` mounts are safe.\n */\n configure(config: SimplrConfig): SimplrController {\n if (this._config && this._config.apiKey === config.apiKey) {\n return this; // already configured with this key\n }\n\n this._config = {\n autoStart: true,\n collectBiometrics: true,\n ...config,\n };\n this._baseUrl = (config.baseUrl || DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n const apiKey = config.apiKey;\n\n // Core fraud client (device fingerprint + behavioral biometrics).\n this.fraud = new SimplrFraud({\n apiKey,\n autoStart: this._config.autoStart,\n collectBiometrics: this._config.collectBiometrics,\n ...config.fraud,\n });\n\n // Feature flags.\n const flagsConfig = resolveBlock<SimplrFlagsConfig>(\n config.flags === undefined ? true : config.flags,\n { apiKey, baseUrl: this._baseUrl },\n );\n if (flagsConfig) {\n this.flags = new SimplrFlags();\n void this.flags.initialize(flagsConfig);\n }\n\n // Profiles.\n const profilesConfig = resolveBlock<SimplrProfilesConfig>(\n config.profiles === undefined ? true : config.profiles,\n { apiKey, baseUrl: this._baseUrl },\n );\n if (profilesConfig) {\n this.profiles = new SimplrProfiles(profilesConfig);\n this.profiles.setDeviceSignalCollector(() => this.fraud!.collectDeviceSignals());\n }\n\n // RUM (core singleton).\n if (config.rum) {\n if (!simplrRUM.isInitialized()) {\n simplrRUM.initialize(config.rum);\n }\n this.rum = simplrRUM;\n }\n\n // AI delegation.\n const aiConfig = resolveBlock<AIDelegationConfig>(\n config.ai === undefined ? true : config.ai,\n { apiKey },\n );\n if (aiConfig && aiConfig.apiKey) {\n this.ai = new SimplrAI(aiConfig);\n }\n\n this._ready = true;\n this.readyResolvers.splice(0).forEach((r) => r());\n if (typeof window !== \"undefined\") {\n window.dispatchEvent(new CustomEvent(\"simplr:configured\", { detail: { controller: this } }));\n }\n return this;\n }\n\n /** Resolves once the controller has been configured. */\n ready(): Promise<void> {\n if (this._ready) return Promise.resolve();\n return new Promise((resolve) => this.readyResolvers.push(resolve));\n }\n\n private requireFraud(): SimplrFraud {\n if (!this.fraud) {\n throw new Error(\n \"Simplr is not configured. Call SimplrElements.configure({ apiKey }) \" +\n \"or add a <simplr-provider api-key=\\\"pk_...\\\"> element first.\",\n );\n }\n return this.fraud;\n }\n\n // --- Signal collection (delegates to the core fraud client) --------------\n\n /** Collect device fingerprint + behavioral biometrics together. */\n collect(): Promise<CollectedSignals> {\n return this.requireFraud().collect();\n }\n\n /** Collect device fingerprint signals only. */\n getDeviceSignals(): Promise<DeviceSignals> {\n return this.requireFraud().collectDeviceSignals();\n }\n\n /** Collect behavioral biometric signals only (sync). */\n getBehaviorSignals(): BehaviorSignals {\n return this.requireFraud().collectBehaviorSignals();\n }\n\n /** Input tracking handlers/attrs for a named field (keystroke biometrics). */\n trackInput(fieldName: string) {\n return this.requireFraud().trackInput(fieldName);\n }\n\n /** Reset collected behavioral data. */\n reset(): void {\n this.requireFraud().reset();\n }\n\n // --- API calls (public-key ingestion, per the contract) ------------------\n\n /**\n * Run a fraud/identity check (POST `/v1/check`). Device + behavior signals\n * are auto-collected and merged into the request unless already on `input`.\n */\n async check(input: CheckInput = {}): Promise<CheckResult> {\n const collected = await this.collect();\n const body: CheckInput = {\n ...input,\n device: input.device ?? (collected.device as unknown as Record<string, unknown>),\n behavior: input.behavior ?? (collected.behavior as unknown as Record<string, unknown>),\n };\n return this.request<CheckResult>(\"/v1/check\", body);\n }\n\n private async request<T>(path: string, body: unknown): Promise<T> {\n const apiKey = this.apiKey;\n if (!apiKey) throw new Error(\"Simplr is not configured (missing apiKey).\");\n const res = await fetch(`${this._baseUrl}${path}`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\", \"X-API-Key\": apiKey },\n body: JSON.stringify(body),\n });\n const json = await res.json().catch(() => null);\n if (!res.ok) {\n const message =\n (json && (json.message || json.error)) || `Simplr API error ${res.status}`;\n throw new Error(message);\n }\n // Unwrap the standard { success, message, content } envelope when present.\n return (json && \"content\" in json ? json.content : json) as T;\n }\n\n // --- Feature flags helper ------------------------------------------------\n\n /** Evaluate a feature flag locally. Returns false if flags aren't enabled. */\n isFeatureEnabled(key: string, ctx?: EvalContext): boolean {\n return this.flags ? this.flags.isEnabled(key, ctx) : false;\n }\n\n /** Tear down timers / trackers (useful for tests + SPA teardown). */\n dispose(): void {\n this.fraud?.stopTracking();\n this.flags?.dispose();\n this.rum?.stopSession();\n this._config = null;\n this._ready = false;\n this.fraud = this.flags = this.profiles = this.ai = this.rum = null;\n }\n}\n\n/** The shared controller singleton every element + helper reads from. */\nexport const SimplrElements = new SimplrController();\n\n/**\n * Imperative feature-flag helper mirroring the core local-eval contract.\n * Reads from the shared controller.\n */\nexport function isFeatureEnabled(key: string, ctx?: EvalContext): boolean {\n return SimplrElements.isFeatureEnabled(key, ctx);\n}\n","/**\n * `<simplr-provider>` — configures the shared Simplr client.\n *\n * Configuration sources (first match wins):\n * 1. the `api-key` / `public-key` attribute on this element\n * 2. a `data-simplr-key` attribute on this element or <html>/<body>\n * 3. `window.SIMPLR_CONFIG = { apiKey, baseUrl?, autoStart? }`\n *\n * Optional attributes: `base-url`, `no-autostart`, `flags`, `profiles`, `ai`\n * (presence enables; `flags=\"false\"` disables), `app-id` (enables RUM).\n *\n * Covers: client configuration / context for all descendant elements.\n */\nimport { SimplrElements } from \"../controller\";\n\ndeclare global {\n interface Window {\n SIMPLR_CONFIG?: {\n apiKey?: string;\n publicKey?: string;\n baseUrl?: string;\n autoStart?: boolean;\n appId?: string;\n };\n }\n}\n\nfunction readKey(el: HTMLElement): string | undefined {\n return (\n el.getAttribute(\"api-key\") ||\n el.getAttribute(\"public-key\") ||\n el.getAttribute(\"publicKey\") ||\n el.getAttribute(\"data-simplr-key\") ||\n (typeof document !== \"undefined\"\n ? document.documentElement.getAttribute(\"data-simplr-key\") ||\n document.body?.getAttribute(\"data-simplr-key\") ||\n undefined\n : undefined) ||\n (typeof window !== \"undefined\"\n ? window.SIMPLR_CONFIG?.apiKey || window.SIMPLR_CONFIG?.publicKey\n : undefined) ||\n undefined\n );\n}\n\nfunction flagFor(el: HTMLElement, name: string, fallback: boolean): boolean {\n if (!el.hasAttribute(name)) return fallback;\n const v = el.getAttribute(name);\n return v !== \"false\" && v !== \"off\" && v !== \"0\";\n}\n\nexport class SimplrProviderElement extends HTMLElement {\n static get observedAttributes(): string[] {\n return [\"api-key\", \"public-key\", \"base-url\"];\n }\n\n connectedCallback(): void {\n this.tryConfigure();\n }\n\n attributeChangedCallback(): void {\n if (this.isConnected) this.tryConfigure();\n }\n\n private tryConfigure(): void {\n const apiKey = readKey(this);\n if (!apiKey) return; // wait for a key to appear\n\n const appId =\n this.getAttribute(\"app-id\") ||\n (typeof window !== \"undefined\" ? window.SIMPLR_CONFIG?.appId : undefined);\n\n SimplrElements.configure({\n apiKey,\n baseUrl:\n this.getAttribute(\"base-url\") ||\n (typeof window !== \"undefined\" ? window.SIMPLR_CONFIG?.baseUrl : undefined) ||\n undefined,\n autoStart: !this.hasAttribute(\"no-autostart\"),\n flags: flagFor(this, \"flags\", true),\n profiles: flagFor(this, \"profiles\", true),\n ai: flagFor(this, \"ai\", true),\n rum: appId ? { apiKey, applicationId: appId } : undefined,\n });\n\n this.dispatchEvent(\n new CustomEvent(\"simplr-ready\", {\n bubbles: true,\n composed: true,\n detail: { controller: SimplrElements },\n }),\n );\n }\n}\n","/**\n * `<simplr-protected-form>` — wraps a `<form>` (via slot). On submit it collects\n * device + behavioral signals from the shared core fraud client and, if\n * `auto-check` is set, runs a `/v1/check`. It attaches the result two ways:\n * - a hidden `<input name=\"simplr_signals\">` injected into the form (JSON), and\n * - a `simplr-submit` CustomEvent carrying `{ signals, check, event }`.\n *\n * By default the native submit is prevented so you can finish it after the\n * async collect resolves; add `native-submit` to let it proceed.\n *\n * Covers: [device fingerprint] [behavioral biometrics] [fraud/identity check].\n */\nimport { SimplrElements, type CheckResult, type CheckInput } from \"../controller\";\nimport type { CollectedSignals } from \"@simplr-ai/js\";\n\nexport class SimplrProtectedFormElement extends HTMLElement {\n private form: HTMLFormElement | null = null;\n private onSubmit = (e: Event) => this.handleSubmit(e);\n\n connectedCallback(): void {\n // Locate a form: either a slotted child form or this element acting as one.\n this.form = this.querySelector(\"form\");\n const target: HTMLElement = this.form ?? this;\n target.addEventListener(\"submit\", this.onSubmit);\n }\n\n disconnectedCallback(): void {\n const target: HTMLElement = this.form ?? this;\n target.removeEventListener(\"submit\", this.onSubmit);\n }\n\n /** Field name used for the hidden signals input. */\n get fieldName(): string {\n return this.getAttribute(\"field-name\") || \"simplr_signals\";\n }\n\n private async handleSubmit(event: Event): Promise<void> {\n const allowNative = this.hasAttribute(\"native-submit\");\n if (!allowNative) event.preventDefault();\n\n this.setAttribute(\"submitting\", \"\");\n try {\n const signals: CollectedSignals = await SimplrElements.collect();\n\n let check: CheckResult | undefined;\n if (this.hasAttribute(\"auto-check\")) {\n const form = this.form ?? (event.target as HTMLFormElement);\n const input: CheckInput = {};\n const email = form?.querySelector?.<HTMLInputElement>('[type=\"email\"], [name=\"email\"]');\n if (email?.value) input.email = email.value;\n check = await SimplrElements.check(input);\n }\n\n // Inject a hidden field with the collected signals for plain HTML forms.\n if (this.form) {\n let hidden = this.form.querySelector<HTMLInputElement>(\n `input[name=\"${this.fieldName}\"]`,\n );\n if (!hidden) {\n hidden = document.createElement(\"input\");\n hidden.type = \"hidden\";\n hidden.name = this.fieldName;\n this.form.appendChild(hidden);\n }\n hidden.value = JSON.stringify({ signals, check });\n }\n\n this.dispatchEvent(\n new CustomEvent(\"simplr-submit\", {\n bubbles: true,\n composed: true,\n detail: { signals, check, event },\n }),\n );\n } catch (e) {\n this.dispatchEvent(\n new CustomEvent(\"simplr-error\", {\n bubbles: true,\n composed: true,\n detail: { error: e instanceof Error ? e : new Error(String(e)) },\n }),\n );\n } finally {\n this.removeAttribute(\"submitting\");\n }\n }\n}\n","/**\n * `<simplr-protected-input field=\"email\">` — attaches keystroke biometrics to a\n * slotted `<input>`/`<textarea>`. Works by wrapping the input: it wires the\n * core keystroke tracker's keydown/keyup/paste handlers to the inner control.\n *\n * Covers: [behavioral biometrics] (keystroke dynamics) [input validation helpers].\n */\nimport { SimplrElements } from \"../controller\";\n\nexport class SimplrProtectedInputElement extends HTMLElement {\n static get observedAttributes(): string[] {\n return [\"field\"];\n }\n\n private input: HTMLInputElement | HTMLTextAreaElement | null = null;\n private handlers: ReturnType<typeof SimplrElements.trackInput> | null = null;\n private bound: { down?: EventListener; up?: EventListener; paste?: EventListener } = {};\n\n get field(): string {\n return this.getAttribute(\"field\") || \"input\";\n }\n\n connectedCallback(): void {\n // Defer one microtask so slotted children are present.\n queueMicrotask(() => this.attach());\n }\n\n disconnectedCallback(): void {\n this.detach();\n }\n\n attributeChangedCallback(): void {\n if (this.isConnected) {\n this.detach();\n this.attach();\n }\n }\n\n private attach(): void {\n if (!SimplrElements.fraud) return;\n this.input =\n this.querySelector(\"input\") || this.querySelector(\"textarea\") || null;\n if (!this.input) return;\n\n this.handlers = SimplrElements.trackInput(this.field);\n this.input.setAttribute(\"data-simplr-field\", this.field);\n\n this.bound.down = (e) => this.handlers!.onKeyDown(e as KeyboardEvent);\n this.bound.up = (e) => this.handlers!.onKeyUp(e as KeyboardEvent);\n this.bound.paste = () => this.handlers!.onPaste();\n\n this.input.addEventListener(\"keydown\", this.bound.down);\n this.input.addEventListener(\"keyup\", this.bound.up);\n this.input.addEventListener(\"paste\", this.bound.paste);\n }\n\n private detach(): void {\n if (!this.input) return;\n if (this.bound.down) this.input.removeEventListener(\"keydown\", this.bound.down);\n if (this.bound.up) this.input.removeEventListener(\"keyup\", this.bound.up);\n if (this.bound.paste) this.input.removeEventListener(\"paste\", this.bound.paste);\n this.bound = {};\n this.input = null;\n }\n}\n","/**\n * `<simplr-feature-flag key=\"new-checkout\" user-id=\"u_1\">` — renders its slotted\n * content only when the flag is enabled (local eval via the core SimplrFlags).\n * Listens for `simplr:configured` and polls flag readiness so it reacts to flag\n * refreshes. Use a `<template slot=\"fallback\">` child for the disabled branch.\n *\n * Covers: [feature flags local eval].\n */\nimport { SimplrElements } from \"../controller\";\nimport type { EvalContext } from \"@simplr-ai/js\";\n\nexport class SimplrFeatureFlagElement extends HTMLElement {\n static get observedAttributes(): string[] {\n return [\"key\", \"user-id\"];\n }\n\n private onConfigured = () => this.evaluate();\n private poll: ReturnType<typeof setInterval> | null = null;\n\n connectedCallback(): void {\n if (typeof window !== \"undefined\") {\n window.addEventListener(\"simplr:configured\", this.onConfigured);\n }\n this.evaluate();\n // Re-evaluate periodically so async flag refreshes are reflected.\n this.poll = setInterval(() => this.evaluate(), 2000);\n }\n\n disconnectedCallback(): void {\n if (typeof window !== \"undefined\") {\n window.removeEventListener(\"simplr:configured\", this.onConfigured);\n }\n if (this.poll) clearInterval(this.poll);\n this.poll = null;\n }\n\n attributeChangedCallback(): void {\n if (this.isConnected) this.evaluate();\n }\n\n /** The flag key. */\n get key(): string {\n return this.getAttribute(\"key\") || \"\";\n }\n\n /** Whether this flag currently evaluates to enabled. */\n get enabled(): boolean {\n if (!this.key) return false;\n const ctx: EvalContext = {};\n const userId = this.getAttribute(\"user-id\");\n if (userId) ctx.userId = userId;\n return SimplrElements.isFeatureEnabled(this.key, ctx);\n }\n\n private evaluate(): void {\n const on = this.enabled;\n // Reflect state for styling; default-hide via the [hidden] attribute.\n if (on) {\n this.removeAttribute(\"hidden\");\n this.setAttribute(\"enabled\", \"\");\n } else {\n this.setAttribute(\"hidden\", \"\");\n this.removeAttribute(\"enabled\");\n }\n this.dispatchEvent(\n new CustomEvent(\"simplr-flag\", {\n bubbles: true,\n composed: true,\n detail: { key: this.key, enabled: on },\n }),\n );\n }\n}\n","/**\n * `<simplr-rum-view name=\"Checkout\">` — fires `rum.trackView(name)` when it\n * connects (and again if `name` changes). RUM itself is initialized through the\n * provider (`app-id` attribute) or `configure({ rum })`.\n *\n * Covers: [RUM full] (view tracking entrypoint).\n */\nimport { SimplrElements } from \"../controller\";\n\nexport class SimplrRumViewElement extends HTMLElement {\n static get observedAttributes(): string[] {\n return [\"name\"];\n }\n\n get viewName(): string {\n return this.getAttribute(\"name\") || (typeof location !== \"undefined\" ? location.pathname : \"/\");\n }\n\n connectedCallback(): void {\n this.track();\n }\n\n attributeChangedCallback(_n: string, oldV: string | null, newV: string | null): void {\n if (this.isConnected && oldV !== newV) this.track();\n }\n\n private track(): void {\n const rum = SimplrElements.rum;\n if (rum && rum.isInitialized()) {\n rum.trackView(this.viewName);\n this.dispatchEvent(\n new CustomEvent(\"simplr-view\", {\n bubbles: true,\n composed: true,\n detail: { name: this.viewName, viewId: rum.getViewId() },\n }),\n );\n }\n }\n}\n","/**\n * `<simplr-ai-delegation user-id=\"u_1\">` — a thin element around the AI\n * delegation flow. Renders a slotted trigger (default a button); on click it\n * calls `ai.createDelegation(...)` (or `ai.connect(...)` with `mode=\"connect\"`)\n * and emits the result via `simplr-delegation`.\n *\n * For full programmatic access (list/get/revoke/stats/validate/revokeAllForUser)\n * use `SimplrElements.ai` directly.\n *\n * Covers: [AI delegation].\n */\nimport { SimplrElements } from \"../controller\";\nimport type { BindingMode } from \"@simplr-ai/js\";\n\nexport class SimplrAiDelegationElement extends HTMLElement {\n private trigger: HTMLElement | null = null;\n private onClick = () => this.run();\n\n connectedCallback(): void {\n queueMicrotask(() => {\n this.trigger =\n this.querySelector(\"[slot=trigger]\") ||\n this.querySelector(\"button\") ||\n this;\n this.trigger.addEventListener(\"click\", this.onClick);\n });\n }\n\n disconnectedCallback(): void {\n this.trigger?.removeEventListener(\"click\", this.onClick);\n }\n\n get userId(): string {\n return this.getAttribute(\"user-id\") || \"\";\n }\n\n private async run(): Promise<void> {\n const ai = SimplrElements.ai;\n if (!ai) {\n this.dispatchEvent(\n new CustomEvent(\"simplr-error\", {\n bubbles: true,\n composed: true,\n detail: { error: new Error(\"AI delegation is not configured.\") },\n }),\n );\n return;\n }\n\n const binding = (this.getAttribute(\"binding\") as BindingMode) || undefined;\n const email = this.getAttribute(\"email\") || undefined;\n let fingerprintHash: string | undefined;\n try {\n if (SimplrElements.fraud) {\n fingerprintHash = (await SimplrElements.getDeviceSignals()).fingerprint;\n }\n } catch {\n // proceed without a fingerprint\n }\n\n try {\n const result =\n this.getAttribute(\"mode\") === \"connect\"\n ? await ai.connect({ userId: this.userId, email, binding, fingerprintHash })\n : await ai.createDelegation({ userId: this.userId, email, binding, fingerprintHash });\n this.dispatchEvent(\n new CustomEvent(\"simplr-delegation\", {\n bubbles: true,\n composed: true,\n detail: { result },\n }),\n );\n } catch (e) {\n this.dispatchEvent(\n new CustomEvent(\"simplr-error\", {\n bubbles: true,\n composed: true,\n detail: { error: e instanceof Error ? e : new Error(String(e)) },\n }),\n );\n }\n }\n}\n","/**\n * Element registration. SSR-safe: importing this module never touches\n * `customElements`. Call {@link defineSimplrElements} in a browser to register,\n * or import the global `<script>` bundle which auto-registers.\n */\nimport { SimplrProviderElement } from \"./elements/provider\";\nimport { SimplrProtectedFormElement } from \"./elements/protected-form\";\nimport { SimplrProtectedInputElement } from \"./elements/protected-input\";\nimport { SimplrFeatureFlagElement } from \"./elements/feature-flag\";\nimport { SimplrRumViewElement } from \"./elements/rum-view\";\nimport { SimplrAiDelegationElement } from \"./elements/ai-delegation\";\n\n/** Map of tag name → element constructor for every Simplr custom element. */\nexport const SIMPLR_ELEMENTS: Record<string, CustomElementConstructor> = {\n \"simplr-provider\": SimplrProviderElement,\n \"simplr-protected-form\": SimplrProtectedFormElement,\n \"simplr-protected-input\": SimplrProtectedInputElement,\n \"simplr-feature-flag\": SimplrFeatureFlagElement,\n \"simplr-rum-view\": SimplrRumViewElement,\n \"simplr-ai-delegation\": SimplrAiDelegationElement,\n};\n\n/**\n * Register all Simplr custom elements with the browser's CustomElementRegistry.\n * No-op (and safe) when there is no `customElements` (e.g. SSR / Node). Already\n * registered tags are skipped, so calling this twice is harmless.\n */\nexport function defineSimplrElements(): void {\n if (typeof customElements === \"undefined\") return;\n for (const [tag, ctor] of Object.entries(SIMPLR_ELEMENTS)) {\n if (!customElements.get(tag)) {\n customElements.define(tag, ctor);\n }\n }\n}\n"]}
|