@simplr-ai/angular 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 +257 -0
- package/dist/index.cjs +867 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +371 -0
- package/dist/index.d.ts +371 -0
- package/dist/index.js +820 -0
- package/dist/index.js.map +1 -0
- package/package.json +60 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,820 @@
|
|
|
1
|
+
import { InjectionToken, Injectable, Optional, Inject, EventEmitter, Input, Output, HostListener, Directive, Component, NgModule, ErrorHandler, makeEnvironmentProviders } from '@angular/core';
|
|
2
|
+
import { from, BehaviorSubject } from 'rxjs';
|
|
3
|
+
import { SimplrFraud, SimplrFlags, SimplrProfiles, SimplrRUM, SimplrAI } from '@simplr-ai/js';
|
|
4
|
+
export { SimplrAI, SimplrFlags, SimplrFraud, SimplrProfiles, SimplrRUM, clearDeviceId, createSimplrAI, createSimplrProfiles, getDeviceId, murmurHash3, sha256 } from '@simplr-ai/js';
|
|
5
|
+
import { map, distinctUntilChanged } from 'rxjs/operators';
|
|
6
|
+
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var SIMPLR_CONFIG = new InjectionToken("SIMPLR_CONFIG");
|
|
10
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
11
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
12
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
13
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
14
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
15
|
+
}
|
|
16
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
17
|
+
function _ts_metadata(k, v) {
|
|
18
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
19
|
+
}
|
|
20
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
21
|
+
function _ts_param(paramIndex, decorator) {
|
|
22
|
+
return function(target, key) {
|
|
23
|
+
decorator(target, key, paramIndex);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
__name(_ts_param, "_ts_param");
|
|
27
|
+
var SimplrService = class {
|
|
28
|
+
static {
|
|
29
|
+
__name(this, "SimplrService");
|
|
30
|
+
}
|
|
31
|
+
/** The underlying core SDK instance. Exposed for advanced/escape-hatch use. */
|
|
32
|
+
core;
|
|
33
|
+
config;
|
|
34
|
+
constructor(config) {
|
|
35
|
+
this.config = config;
|
|
36
|
+
this.core = new SimplrFraud({
|
|
37
|
+
apiKey: config?.apiKey,
|
|
38
|
+
...config?.fraud
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/** Whether the SDK has been initialized and is ready to collect. */
|
|
42
|
+
get isReady() {
|
|
43
|
+
return this.core.isReady;
|
|
44
|
+
}
|
|
45
|
+
/** Initialize the SDK and start biometric tracking (no-op if auto-started). */
|
|
46
|
+
initialize() {
|
|
47
|
+
this.core.initialize();
|
|
48
|
+
}
|
|
49
|
+
/** Start behavioral biometric tracking. */
|
|
50
|
+
startTracking() {
|
|
51
|
+
this.core.startTracking();
|
|
52
|
+
}
|
|
53
|
+
/** Stop behavioral biometric tracking. */
|
|
54
|
+
stopTracking() {
|
|
55
|
+
this.core.stopTracking();
|
|
56
|
+
}
|
|
57
|
+
/** Reset all collected behavioral data. */
|
|
58
|
+
reset() {
|
|
59
|
+
this.core.reset();
|
|
60
|
+
}
|
|
61
|
+
/** Event handlers + `data-simplr-field` attr to wire up an input for keystroke biometrics. */
|
|
62
|
+
trackInput(fieldName) {
|
|
63
|
+
return this.core.trackInput(fieldName);
|
|
64
|
+
}
|
|
65
|
+
/** Collect the full device fingerprint only (Promise). */
|
|
66
|
+
getDeviceSignals() {
|
|
67
|
+
return this.core.collectDeviceSignals();
|
|
68
|
+
}
|
|
69
|
+
/** Collect the full device fingerprint only (Observable). */
|
|
70
|
+
getDeviceSignals$() {
|
|
71
|
+
return from(this.core.collectDeviceSignals());
|
|
72
|
+
}
|
|
73
|
+
/** Collect behavioral signals synchronously. */
|
|
74
|
+
getBehaviorSignals() {
|
|
75
|
+
return this.core.collectBehaviorSignals();
|
|
76
|
+
}
|
|
77
|
+
/** Collect device + behavior signals (Promise). */
|
|
78
|
+
collect() {
|
|
79
|
+
return this.core.collect();
|
|
80
|
+
}
|
|
81
|
+
/** Collect device + behavior signals (Observable). */
|
|
82
|
+
collect$() {
|
|
83
|
+
return from(this.core.collect());
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Convenience: run a fraud/identity check against `/v1/check`. Collects fresh
|
|
87
|
+
* device + behavior signals and posts them with the configured public key.
|
|
88
|
+
* Returns the unwrapped `content` from the response envelope.
|
|
89
|
+
*/
|
|
90
|
+
async check(input = {}) {
|
|
91
|
+
const config = this.config;
|
|
92
|
+
const signals = await this.core.collect();
|
|
93
|
+
const baseUrl = (config?.baseUrl || "https://api.simplr.sh").replace(/\/+$/, "");
|
|
94
|
+
const res = await fetch(`${baseUrl}/v1/check`, {
|
|
95
|
+
method: "POST",
|
|
96
|
+
headers: {
|
|
97
|
+
"Content-Type": "application/json",
|
|
98
|
+
"X-API-Key": config?.apiKey ?? ""
|
|
99
|
+
},
|
|
100
|
+
body: JSON.stringify({
|
|
101
|
+
...input,
|
|
102
|
+
device: signals.device,
|
|
103
|
+
behavior: signals.behavior
|
|
104
|
+
})
|
|
105
|
+
});
|
|
106
|
+
const body = await res.json().catch(() => null);
|
|
107
|
+
if (!res.ok) {
|
|
108
|
+
throw new Error(body?.message || body?.error || `Simplr API error ${res.status}`);
|
|
109
|
+
}
|
|
110
|
+
return body && "content" in body ? body.content : body;
|
|
111
|
+
}
|
|
112
|
+
/** Observable variant of {@link check}. */
|
|
113
|
+
check$(input = {}) {
|
|
114
|
+
return from(this.check(input));
|
|
115
|
+
}
|
|
116
|
+
ngOnDestroy() {
|
|
117
|
+
this.core.stopTracking();
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
SimplrService = _ts_decorate([
|
|
121
|
+
Injectable({
|
|
122
|
+
providedIn: "root"
|
|
123
|
+
}),
|
|
124
|
+
_ts_param(0, Optional()),
|
|
125
|
+
_ts_param(0, Inject(SIMPLR_CONFIG)),
|
|
126
|
+
_ts_metadata("design:type", Function),
|
|
127
|
+
_ts_metadata("design:paramtypes", [
|
|
128
|
+
typeof SimplrConfig === "undefined" ? Object : SimplrConfig
|
|
129
|
+
])
|
|
130
|
+
], SimplrService);
|
|
131
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
132
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
133
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
134
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
135
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
136
|
+
}
|
|
137
|
+
__name(_ts_decorate2, "_ts_decorate");
|
|
138
|
+
function _ts_metadata2(k, v) {
|
|
139
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
140
|
+
}
|
|
141
|
+
__name(_ts_metadata2, "_ts_metadata");
|
|
142
|
+
function _ts_param2(paramIndex, decorator) {
|
|
143
|
+
return function(target, key) {
|
|
144
|
+
decorator(target, key, paramIndex);
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
__name(_ts_param2, "_ts_param");
|
|
148
|
+
var SimplrFlagsService = class {
|
|
149
|
+
static {
|
|
150
|
+
__name(this, "SimplrFlagsService");
|
|
151
|
+
}
|
|
152
|
+
/** The underlying core SDK instance. */
|
|
153
|
+
core = new SimplrFlags();
|
|
154
|
+
/** Emits the full `{ key -> FlagDefinition }` map on every refresh. */
|
|
155
|
+
flags$ = new BehaviorSubject({});
|
|
156
|
+
config;
|
|
157
|
+
refreshTimer = null;
|
|
158
|
+
autoInitDone = false;
|
|
159
|
+
constructor(config) {
|
|
160
|
+
this.config = config;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Initialize the flag engine. Loads flags from `/v1/flags`, seeds `flags$`,
|
|
164
|
+
* and starts an internal refresh loop that re-emits `flags$` on each cycle.
|
|
165
|
+
*/
|
|
166
|
+
async initialize(overrides) {
|
|
167
|
+
const refreshIntervalMs = overrides?.refreshIntervalMs ?? this.config?.flags?.refreshIntervalMs ?? 6e4;
|
|
168
|
+
const cfg = {
|
|
169
|
+
apiKey: this.config?.apiKey ?? "",
|
|
170
|
+
baseUrl: this.config?.baseUrl,
|
|
171
|
+
...this.config?.flags,
|
|
172
|
+
...overrides,
|
|
173
|
+
// We drive refresh emissions ourselves so flags$ stays in sync; disable
|
|
174
|
+
// the core's internal timer to avoid a second uncontrolled loop.
|
|
175
|
+
refreshIntervalMs: 0
|
|
176
|
+
};
|
|
177
|
+
await this.core.initialize(cfg);
|
|
178
|
+
this.emit();
|
|
179
|
+
if (refreshIntervalMs > 0 && typeof setInterval !== "undefined") {
|
|
180
|
+
this.refreshTimer = setInterval(() => this.refresh(), refreshIntervalMs);
|
|
181
|
+
}
|
|
182
|
+
this.autoInitDone = true;
|
|
183
|
+
}
|
|
184
|
+
/** Set the default user id used for flag evaluation/bucketing. */
|
|
185
|
+
setUser(userId) {
|
|
186
|
+
this.core.setUser(userId);
|
|
187
|
+
}
|
|
188
|
+
/** Manually refresh flags from the server and re-emit `flags$`. */
|
|
189
|
+
async refresh() {
|
|
190
|
+
await this.core.refresh();
|
|
191
|
+
this.emit();
|
|
192
|
+
}
|
|
193
|
+
/** Manually refresh flags as an Observable. */
|
|
194
|
+
refresh$() {
|
|
195
|
+
return from(this.refresh());
|
|
196
|
+
}
|
|
197
|
+
/** Evaluate a flag synchronously (local eval, murmurhash bucketing). */
|
|
198
|
+
isEnabled(key, ctx) {
|
|
199
|
+
return this.core.isEnabled(key, ctx);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Observe a single flag as a boolean stream. Re-evaluates and emits whenever
|
|
203
|
+
* `flags$` changes (i.e. on every refresh), deduping consecutive equal values.
|
|
204
|
+
*/
|
|
205
|
+
observeFlag(key, ctx) {
|
|
206
|
+
return this.flags$.pipe(map(() => this.core.isEnabled(key, ctx)), distinctUntilChanged());
|
|
207
|
+
}
|
|
208
|
+
/** Whether the engine has loaded its initial flag set. */
|
|
209
|
+
isReady() {
|
|
210
|
+
return this.core.isReady();
|
|
211
|
+
}
|
|
212
|
+
/** Snapshot of all currently-known flag definitions. */
|
|
213
|
+
getAll() {
|
|
214
|
+
return this.core.getAll();
|
|
215
|
+
}
|
|
216
|
+
emit() {
|
|
217
|
+
this.flags$.next(this.core.getAll());
|
|
218
|
+
}
|
|
219
|
+
ngOnDestroy() {
|
|
220
|
+
if (this.refreshTimer) clearInterval(this.refreshTimer);
|
|
221
|
+
this.refreshTimer = null;
|
|
222
|
+
this.core.dispose();
|
|
223
|
+
this.flags$.complete();
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
SimplrFlagsService = _ts_decorate2([
|
|
227
|
+
Injectable({
|
|
228
|
+
providedIn: "root"
|
|
229
|
+
}),
|
|
230
|
+
_ts_param2(0, Optional()),
|
|
231
|
+
_ts_param2(0, Inject(SIMPLR_CONFIG)),
|
|
232
|
+
_ts_metadata2("design:type", Function),
|
|
233
|
+
_ts_metadata2("design:paramtypes", [
|
|
234
|
+
typeof SimplrConfig === "undefined" ? Object : SimplrConfig
|
|
235
|
+
])
|
|
236
|
+
], SimplrFlagsService);
|
|
237
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
238
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
239
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
240
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
241
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
242
|
+
}
|
|
243
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
244
|
+
function _ts_metadata3(k, v) {
|
|
245
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
246
|
+
}
|
|
247
|
+
__name(_ts_metadata3, "_ts_metadata");
|
|
248
|
+
function _ts_param3(paramIndex, decorator) {
|
|
249
|
+
return function(target, key) {
|
|
250
|
+
decorator(target, key, paramIndex);
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
__name(_ts_param3, "_ts_param");
|
|
254
|
+
var SimplrProfilesService = class {
|
|
255
|
+
static {
|
|
256
|
+
__name(this, "SimplrProfilesService");
|
|
257
|
+
}
|
|
258
|
+
/** The underlying core SDK instance. */
|
|
259
|
+
core;
|
|
260
|
+
constructor(config) {
|
|
261
|
+
this.core = new SimplrProfiles({
|
|
262
|
+
apiKey: config?.apiKey ?? "",
|
|
263
|
+
baseUrl: config?.baseUrl,
|
|
264
|
+
...config?.profiles
|
|
265
|
+
});
|
|
266
|
+
const fraud = new SimplrFraud({
|
|
267
|
+
apiKey: config?.apiKey,
|
|
268
|
+
collectBiometrics: false,
|
|
269
|
+
autoStart: false
|
|
270
|
+
});
|
|
271
|
+
this.core.setDeviceSignalCollector(() => fraud.collectDeviceSignals());
|
|
272
|
+
}
|
|
273
|
+
/** Identify a user — creates/updates an anonymous profile, links the device. */
|
|
274
|
+
identify(externalId, options) {
|
|
275
|
+
return this.core.identify(externalId, options);
|
|
276
|
+
}
|
|
277
|
+
/** Observable variant of {@link identify}. */
|
|
278
|
+
identify$(externalId, options) {
|
|
279
|
+
return from(this.core.identify(externalId, options));
|
|
280
|
+
}
|
|
281
|
+
/** Submit an order for real-time fraud scoring (`/v1/orders`). */
|
|
282
|
+
submitOrder(order) {
|
|
283
|
+
return this.core.submitOrder(order);
|
|
284
|
+
}
|
|
285
|
+
/** Observable variant of {@link submitOrder}. */
|
|
286
|
+
submitOrder$(order) {
|
|
287
|
+
return from(this.core.submitOrder(order));
|
|
288
|
+
}
|
|
289
|
+
/** Get the risk profile for a user (`GET /v1/profiles/{externalId}`). */
|
|
290
|
+
getProfileRisk(externalId) {
|
|
291
|
+
return this.core.getProfileRisk(externalId);
|
|
292
|
+
}
|
|
293
|
+
/** Observable variant of {@link getProfileRisk}. */
|
|
294
|
+
getProfileRisk$(externalId) {
|
|
295
|
+
return from(this.core.getProfileRisk(externalId));
|
|
296
|
+
}
|
|
297
|
+
/** Report a profile outcome as `fraud` or `legitimate`. */
|
|
298
|
+
reportOutcome(externalId, outcome) {
|
|
299
|
+
return this.core.reportOutcome(externalId, outcome);
|
|
300
|
+
}
|
|
301
|
+
/** Observable variant of {@link reportOutcome}. */
|
|
302
|
+
reportOutcome$(externalId, outcome) {
|
|
303
|
+
return from(this.core.reportOutcome(externalId, outcome));
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
SimplrProfilesService = _ts_decorate3([
|
|
307
|
+
Injectable({
|
|
308
|
+
providedIn: "root"
|
|
309
|
+
}),
|
|
310
|
+
_ts_param3(0, Optional()),
|
|
311
|
+
_ts_param3(0, Inject(SIMPLR_CONFIG)),
|
|
312
|
+
_ts_metadata3("design:type", Function),
|
|
313
|
+
_ts_metadata3("design:paramtypes", [
|
|
314
|
+
typeof SimplrConfig === "undefined" ? Object : SimplrConfig
|
|
315
|
+
])
|
|
316
|
+
], SimplrProfilesService);
|
|
317
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
318
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
319
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
320
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
321
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
322
|
+
}
|
|
323
|
+
__name(_ts_decorate4, "_ts_decorate");
|
|
324
|
+
function _ts_metadata4(k, v) {
|
|
325
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
326
|
+
}
|
|
327
|
+
__name(_ts_metadata4, "_ts_metadata");
|
|
328
|
+
function _ts_param4(paramIndex, decorator) {
|
|
329
|
+
return function(target, key) {
|
|
330
|
+
decorator(target, key, paramIndex);
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
__name(_ts_param4, "_ts_param");
|
|
334
|
+
var SimplrRumService = class {
|
|
335
|
+
static {
|
|
336
|
+
__name(this, "SimplrRumService");
|
|
337
|
+
}
|
|
338
|
+
/** The underlying core RUM singleton. */
|
|
339
|
+
core = SimplrRUM.getInstance();
|
|
340
|
+
config;
|
|
341
|
+
constructor(config) {
|
|
342
|
+
this.config = config;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Initialize RUM. `applicationId` is required by the core. Pulls apiKey/baseUrl
|
|
346
|
+
* from the unified config when not supplied in overrides.
|
|
347
|
+
*/
|
|
348
|
+
initialize(overrides) {
|
|
349
|
+
const merged = {
|
|
350
|
+
apiKey: this.config?.apiKey,
|
|
351
|
+
...this.config?.rum,
|
|
352
|
+
...overrides
|
|
353
|
+
};
|
|
354
|
+
this.core.initialize(merged);
|
|
355
|
+
}
|
|
356
|
+
/** Whether RUM has been initialized. */
|
|
357
|
+
isInitialized() {
|
|
358
|
+
return this.core.isInitialized();
|
|
359
|
+
}
|
|
360
|
+
/** Associate the current session with a user. */
|
|
361
|
+
setUser(userId, attributes) {
|
|
362
|
+
this.core.setUser(userId, attributes);
|
|
363
|
+
}
|
|
364
|
+
/** Clear the current session's user. */
|
|
365
|
+
clearUser() {
|
|
366
|
+
this.core.clearUser();
|
|
367
|
+
}
|
|
368
|
+
/** Add a global attribute attached to every event. */
|
|
369
|
+
addAttribute(key, value) {
|
|
370
|
+
this.core.addAttribute(key, value);
|
|
371
|
+
}
|
|
372
|
+
/** Remove a previously added global attribute. */
|
|
373
|
+
removeAttribute(key) {
|
|
374
|
+
this.core.removeAttribute(key);
|
|
375
|
+
}
|
|
376
|
+
/** Track a page/screen view. */
|
|
377
|
+
trackView(name, attributes) {
|
|
378
|
+
this.core.trackView(name, attributes);
|
|
379
|
+
}
|
|
380
|
+
/** Track a user action. */
|
|
381
|
+
trackAction(name, type, options) {
|
|
382
|
+
this.core.trackAction(name, type, options);
|
|
383
|
+
}
|
|
384
|
+
/** Track an error. */
|
|
385
|
+
trackError(error, context) {
|
|
386
|
+
this.core.trackError(error, context);
|
|
387
|
+
}
|
|
388
|
+
/** Emit a structured log message. */
|
|
389
|
+
log(level, message, context) {
|
|
390
|
+
this.core.log(level, message, context);
|
|
391
|
+
}
|
|
392
|
+
/** End the current RUM session and flush. */
|
|
393
|
+
stopSession() {
|
|
394
|
+
this.core.stopSession();
|
|
395
|
+
}
|
|
396
|
+
/** Force-flush the event batch. */
|
|
397
|
+
flush() {
|
|
398
|
+
return this.core.flush();
|
|
399
|
+
}
|
|
400
|
+
/** Current session id (or null). */
|
|
401
|
+
getSessionId() {
|
|
402
|
+
return this.core.getSessionId();
|
|
403
|
+
}
|
|
404
|
+
/** Current view id (or null). */
|
|
405
|
+
getViewId() {
|
|
406
|
+
return this.core.getViewId();
|
|
407
|
+
}
|
|
408
|
+
ngOnDestroy() {
|
|
409
|
+
if (this.core.isInitialized()) {
|
|
410
|
+
this.core.flush();
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
SimplrRumService = _ts_decorate4([
|
|
415
|
+
Injectable({
|
|
416
|
+
providedIn: "root"
|
|
417
|
+
}),
|
|
418
|
+
_ts_param4(0, Optional()),
|
|
419
|
+
_ts_param4(0, Inject(SIMPLR_CONFIG)),
|
|
420
|
+
_ts_metadata4("design:type", Function),
|
|
421
|
+
_ts_metadata4("design:paramtypes", [
|
|
422
|
+
typeof SimplrConfig === "undefined" ? Object : SimplrConfig
|
|
423
|
+
])
|
|
424
|
+
], SimplrRumService);
|
|
425
|
+
function _ts_decorate5(decorators, target, key, desc) {
|
|
426
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
427
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
428
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
429
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
430
|
+
}
|
|
431
|
+
__name(_ts_decorate5, "_ts_decorate");
|
|
432
|
+
function _ts_metadata5(k, v) {
|
|
433
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
434
|
+
}
|
|
435
|
+
__name(_ts_metadata5, "_ts_metadata");
|
|
436
|
+
function _ts_param5(paramIndex, decorator) {
|
|
437
|
+
return function(target, key) {
|
|
438
|
+
decorator(target, key, paramIndex);
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
__name(_ts_param5, "_ts_param");
|
|
442
|
+
var SimplrAIService = class {
|
|
443
|
+
static {
|
|
444
|
+
__name(this, "SimplrAIService");
|
|
445
|
+
}
|
|
446
|
+
/** The underlying core SDK instance. */
|
|
447
|
+
core;
|
|
448
|
+
constructor(config) {
|
|
449
|
+
this.core = new SimplrAI({
|
|
450
|
+
apiKey: config?.apiKey ?? "",
|
|
451
|
+
endpoint: config?.baseUrl,
|
|
452
|
+
...config?.ai
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
/** Open the AI Connect gateway (popup/redirect) for users to connect their AI. */
|
|
456
|
+
connect(options) {
|
|
457
|
+
return this.core.connect(options);
|
|
458
|
+
}
|
|
459
|
+
/** Observable variant of {@link connect}. */
|
|
460
|
+
connect$(options) {
|
|
461
|
+
return from(this.core.connect(options));
|
|
462
|
+
}
|
|
463
|
+
/** Create a new AI delegation token for a user. */
|
|
464
|
+
createDelegation(options) {
|
|
465
|
+
return this.core.createDelegation(options);
|
|
466
|
+
}
|
|
467
|
+
/** Observable variant of {@link createDelegation}. */
|
|
468
|
+
createDelegation$(options) {
|
|
469
|
+
return from(this.core.createDelegation(options));
|
|
470
|
+
}
|
|
471
|
+
/** Validate a delegation token. */
|
|
472
|
+
validate(token, options) {
|
|
473
|
+
return this.core.validate(token, options);
|
|
474
|
+
}
|
|
475
|
+
/** Observable variant of {@link validate}. */
|
|
476
|
+
validate$(token, options) {
|
|
477
|
+
return from(this.core.validate(token, options));
|
|
478
|
+
}
|
|
479
|
+
/** Revoke a single delegation. */
|
|
480
|
+
revoke(delegationId, reason) {
|
|
481
|
+
return this.core.revoke(delegationId, reason);
|
|
482
|
+
}
|
|
483
|
+
/** Observable variant of {@link revoke}. */
|
|
484
|
+
revoke$(delegationId, reason) {
|
|
485
|
+
return from(this.core.revoke(delegationId, reason));
|
|
486
|
+
}
|
|
487
|
+
/** List delegations (optionally filtered by user). */
|
|
488
|
+
list(userId) {
|
|
489
|
+
return this.core.list(userId);
|
|
490
|
+
}
|
|
491
|
+
/** Observable variant of {@link list}. */
|
|
492
|
+
list$(userId) {
|
|
493
|
+
return from(this.core.list(userId));
|
|
494
|
+
}
|
|
495
|
+
/** Get a single delegation. */
|
|
496
|
+
get(delegationId) {
|
|
497
|
+
return this.core.get(delegationId);
|
|
498
|
+
}
|
|
499
|
+
/** Observable variant of {@link get}. */
|
|
500
|
+
get$(delegationId) {
|
|
501
|
+
return from(this.core.get(delegationId));
|
|
502
|
+
}
|
|
503
|
+
/** Get aggregate delegation statistics. */
|
|
504
|
+
stats() {
|
|
505
|
+
return this.core.stats();
|
|
506
|
+
}
|
|
507
|
+
/** Observable variant of {@link stats}. */
|
|
508
|
+
stats$() {
|
|
509
|
+
return from(this.core.stats());
|
|
510
|
+
}
|
|
511
|
+
/** Revoke all delegations for a user (useful on logout). Returns the count revoked. */
|
|
512
|
+
revokeAllForUser(userId, reason) {
|
|
513
|
+
return this.core.revokeAllForUser(userId, reason);
|
|
514
|
+
}
|
|
515
|
+
/** Observable variant of {@link revokeAllForUser}. */
|
|
516
|
+
revokeAllForUser$(userId, reason) {
|
|
517
|
+
return from(this.core.revokeAllForUser(userId, reason));
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
SimplrAIService = _ts_decorate5([
|
|
521
|
+
Injectable({
|
|
522
|
+
providedIn: "root"
|
|
523
|
+
}),
|
|
524
|
+
_ts_param5(0, Optional()),
|
|
525
|
+
_ts_param5(0, Inject(SIMPLR_CONFIG)),
|
|
526
|
+
_ts_metadata5("design:type", Function),
|
|
527
|
+
_ts_metadata5("design:paramtypes", [
|
|
528
|
+
typeof SimplrConfig === "undefined" ? Object : SimplrConfig
|
|
529
|
+
])
|
|
530
|
+
], SimplrAIService);
|
|
531
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
532
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
533
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
534
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
535
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
536
|
+
}
|
|
537
|
+
__name(_ts_decorate6, "_ts_decorate");
|
|
538
|
+
function _ts_metadata6(k, v) {
|
|
539
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
540
|
+
}
|
|
541
|
+
__name(_ts_metadata6, "_ts_metadata");
|
|
542
|
+
function _ts_param6(paramIndex, decorator) {
|
|
543
|
+
return function(target, key) {
|
|
544
|
+
decorator(target, key, paramIndex);
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
__name(_ts_param6, "_ts_param");
|
|
548
|
+
var SimplrErrorHandler = class {
|
|
549
|
+
static {
|
|
550
|
+
__name(this, "SimplrErrorHandler");
|
|
551
|
+
}
|
|
552
|
+
rum;
|
|
553
|
+
constructor(rum) {
|
|
554
|
+
this.rum = rum;
|
|
555
|
+
}
|
|
556
|
+
handleError(error) {
|
|
557
|
+
try {
|
|
558
|
+
if (this.rum?.isInitialized()) {
|
|
559
|
+
const err = error instanceof Error ? error : new Error(typeof error === "string" ? error : JSON.stringify(error));
|
|
560
|
+
this.rum.trackError(err, {
|
|
561
|
+
source: "angular_error_handler"
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
} catch {
|
|
565
|
+
}
|
|
566
|
+
console.error(error);
|
|
567
|
+
}
|
|
568
|
+
};
|
|
569
|
+
SimplrErrorHandler = _ts_decorate6([
|
|
570
|
+
Injectable(),
|
|
571
|
+
_ts_param6(0, Optional()),
|
|
572
|
+
_ts_metadata6("design:type", Function),
|
|
573
|
+
_ts_metadata6("design:paramtypes", [
|
|
574
|
+
typeof SimplrRumService === "undefined" ? Object : SimplrRumService
|
|
575
|
+
])
|
|
576
|
+
], SimplrErrorHandler);
|
|
577
|
+
function _ts_decorate7(decorators, target, key, desc) {
|
|
578
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
579
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
580
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
581
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
582
|
+
}
|
|
583
|
+
__name(_ts_decorate7, "_ts_decorate");
|
|
584
|
+
function _ts_metadata7(k, v) {
|
|
585
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
586
|
+
}
|
|
587
|
+
__name(_ts_metadata7, "_ts_metadata");
|
|
588
|
+
var SimplrProtectDirective = class {
|
|
589
|
+
static {
|
|
590
|
+
__name(this, "SimplrProtectDirective");
|
|
591
|
+
}
|
|
592
|
+
simplr;
|
|
593
|
+
/** Prevent the native form submit while signals are collected (default true). */
|
|
594
|
+
simplrPreventDefault = true;
|
|
595
|
+
/** Emits the collected device + behavior signals on submit. */
|
|
596
|
+
simplrSignals = new EventEmitter();
|
|
597
|
+
/** Emits if signal collection fails. */
|
|
598
|
+
simplrError = new EventEmitter();
|
|
599
|
+
constructor(simplr) {
|
|
600
|
+
this.simplr = simplr;
|
|
601
|
+
}
|
|
602
|
+
async onSubmit(event) {
|
|
603
|
+
if (this.simplrPreventDefault) {
|
|
604
|
+
event.preventDefault();
|
|
605
|
+
}
|
|
606
|
+
try {
|
|
607
|
+
const signals = await this.simplr.collect();
|
|
608
|
+
this.simplrSignals.emit(signals);
|
|
609
|
+
} catch (err) {
|
|
610
|
+
this.simplrError.emit(err);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
_ts_decorate7([
|
|
615
|
+
Input()
|
|
616
|
+
], SimplrProtectDirective.prototype, "simplrPreventDefault", void 0);
|
|
617
|
+
_ts_decorate7([
|
|
618
|
+
Output()
|
|
619
|
+
], SimplrProtectDirective.prototype, "simplrSignals", void 0);
|
|
620
|
+
_ts_decorate7([
|
|
621
|
+
Output()
|
|
622
|
+
], SimplrProtectDirective.prototype, "simplrError", void 0);
|
|
623
|
+
_ts_decorate7([
|
|
624
|
+
HostListener("submit", [
|
|
625
|
+
"$event"
|
|
626
|
+
]),
|
|
627
|
+
_ts_metadata7("design:type", Function),
|
|
628
|
+
_ts_metadata7("design:paramtypes", [
|
|
629
|
+
typeof Event === "undefined" ? Object : Event
|
|
630
|
+
]),
|
|
631
|
+
_ts_metadata7("design:returntype", Promise)
|
|
632
|
+
], SimplrProtectDirective.prototype, "onSubmit", null);
|
|
633
|
+
SimplrProtectDirective = _ts_decorate7([
|
|
634
|
+
Directive({
|
|
635
|
+
selector: "[simplrProtect]",
|
|
636
|
+
standalone: true
|
|
637
|
+
}),
|
|
638
|
+
_ts_metadata7("design:type", Function),
|
|
639
|
+
_ts_metadata7("design:paramtypes", [
|
|
640
|
+
typeof SimplrService === "undefined" ? Object : SimplrService
|
|
641
|
+
])
|
|
642
|
+
], SimplrProtectDirective);
|
|
643
|
+
function _ts_decorate8(decorators, target, key, desc) {
|
|
644
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
645
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
646
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
647
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
648
|
+
}
|
|
649
|
+
__name(_ts_decorate8, "_ts_decorate");
|
|
650
|
+
function _ts_metadata8(k, v) {
|
|
651
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
652
|
+
}
|
|
653
|
+
__name(_ts_metadata8, "_ts_metadata");
|
|
654
|
+
var SimplrRumViewDirective = class {
|
|
655
|
+
static {
|
|
656
|
+
__name(this, "SimplrRumViewDirective");
|
|
657
|
+
}
|
|
658
|
+
rum;
|
|
659
|
+
/** The view name to report. */
|
|
660
|
+
viewName = "";
|
|
661
|
+
/** Optional attributes attached to the view event. */
|
|
662
|
+
simplrRumViewAttributes;
|
|
663
|
+
constructor(rum) {
|
|
664
|
+
this.rum = rum;
|
|
665
|
+
}
|
|
666
|
+
ngOnInit() {
|
|
667
|
+
if (this.viewName) {
|
|
668
|
+
this.rum.trackView(this.viewName, this.simplrRumViewAttributes);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
_ts_decorate8([
|
|
673
|
+
Input("simplrRumView")
|
|
674
|
+
], SimplrRumViewDirective.prototype, "viewName", void 0);
|
|
675
|
+
_ts_decorate8([
|
|
676
|
+
Input(),
|
|
677
|
+
_ts_metadata8("design:type", typeof Record === "undefined" ? Object : Record)
|
|
678
|
+
], SimplrRumViewDirective.prototype, "simplrRumViewAttributes", void 0);
|
|
679
|
+
SimplrRumViewDirective = _ts_decorate8([
|
|
680
|
+
Directive({
|
|
681
|
+
selector: "[simplrRumView]",
|
|
682
|
+
standalone: true
|
|
683
|
+
}),
|
|
684
|
+
_ts_metadata8("design:type", Function),
|
|
685
|
+
_ts_metadata8("design:paramtypes", [
|
|
686
|
+
typeof SimplrRumService === "undefined" ? Object : SimplrRumService
|
|
687
|
+
])
|
|
688
|
+
], SimplrRumViewDirective);
|
|
689
|
+
function _ts_decorate9(decorators, target, key, desc) {
|
|
690
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
691
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
692
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
693
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
694
|
+
}
|
|
695
|
+
__name(_ts_decorate9, "_ts_decorate");
|
|
696
|
+
function _ts_metadata9(k, v) {
|
|
697
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
698
|
+
}
|
|
699
|
+
__name(_ts_metadata9, "_ts_metadata");
|
|
700
|
+
var SimplrProtectedFormComponent = class {
|
|
701
|
+
static {
|
|
702
|
+
__name(this, "SimplrProtectedFormComponent");
|
|
703
|
+
}
|
|
704
|
+
simplr;
|
|
705
|
+
/** Prevent native submit while signals are collected (default true). */
|
|
706
|
+
preventDefault = true;
|
|
707
|
+
/** Emits the collected device + behavior signals together with the event. */
|
|
708
|
+
submitWithSignals = new EventEmitter();
|
|
709
|
+
/** Emits if signal collection fails. */
|
|
710
|
+
collectError = new EventEmitter();
|
|
711
|
+
constructor(simplr) {
|
|
712
|
+
this.simplr = simplr;
|
|
713
|
+
}
|
|
714
|
+
async onSubmit(event) {
|
|
715
|
+
if (this.preventDefault) {
|
|
716
|
+
event.preventDefault();
|
|
717
|
+
}
|
|
718
|
+
try {
|
|
719
|
+
const signals = await this.simplr.collect();
|
|
720
|
+
this.submitWithSignals.emit({
|
|
721
|
+
signals,
|
|
722
|
+
event
|
|
723
|
+
});
|
|
724
|
+
} catch (err) {
|
|
725
|
+
this.collectError.emit(err);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
};
|
|
729
|
+
_ts_decorate9([
|
|
730
|
+
Input()
|
|
731
|
+
], SimplrProtectedFormComponent.prototype, "preventDefault", void 0);
|
|
732
|
+
_ts_decorate9([
|
|
733
|
+
Output()
|
|
734
|
+
], SimplrProtectedFormComponent.prototype, "submitWithSignals", void 0);
|
|
735
|
+
_ts_decorate9([
|
|
736
|
+
Output()
|
|
737
|
+
], SimplrProtectedFormComponent.prototype, "collectError", void 0);
|
|
738
|
+
SimplrProtectedFormComponent = _ts_decorate9([
|
|
739
|
+
Component({
|
|
740
|
+
selector: "simplr-protected-form",
|
|
741
|
+
standalone: true,
|
|
742
|
+
template: `
|
|
743
|
+
<form (submit)="onSubmit($event)">
|
|
744
|
+
<ng-content></ng-content>
|
|
745
|
+
</form>
|
|
746
|
+
`
|
|
747
|
+
}),
|
|
748
|
+
_ts_metadata9("design:type", Function),
|
|
749
|
+
_ts_metadata9("design:paramtypes", [
|
|
750
|
+
typeof SimplrService === "undefined" ? Object : SimplrService
|
|
751
|
+
])
|
|
752
|
+
], SimplrProtectedFormComponent);
|
|
753
|
+
|
|
754
|
+
// src/provider.ts
|
|
755
|
+
function _ts_decorate10(decorators, target, key, desc) {
|
|
756
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
757
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
758
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
759
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
760
|
+
}
|
|
761
|
+
__name(_ts_decorate10, "_ts_decorate");
|
|
762
|
+
function buildProviders(config, options) {
|
|
763
|
+
const providers = [
|
|
764
|
+
{
|
|
765
|
+
provide: SIMPLR_CONFIG,
|
|
766
|
+
useValue: config
|
|
767
|
+
},
|
|
768
|
+
SimplrService,
|
|
769
|
+
SimplrFlagsService,
|
|
770
|
+
SimplrProfilesService,
|
|
771
|
+
SimplrRumService,
|
|
772
|
+
SimplrAIService
|
|
773
|
+
];
|
|
774
|
+
if (options?.errorHandler) {
|
|
775
|
+
providers.push({
|
|
776
|
+
provide: ErrorHandler,
|
|
777
|
+
useClass: SimplrErrorHandler
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
return providers;
|
|
781
|
+
}
|
|
782
|
+
__name(buildProviders, "buildProviders");
|
|
783
|
+
function provideSimplr(config, options) {
|
|
784
|
+
return makeEnvironmentProviders(buildProviders(config, options));
|
|
785
|
+
}
|
|
786
|
+
__name(provideSimplr, "provideSimplr");
|
|
787
|
+
var SIMPLR_DIRECTIVES = [
|
|
788
|
+
SimplrProtectDirective,
|
|
789
|
+
SimplrRumViewDirective,
|
|
790
|
+
SimplrProtectedFormComponent
|
|
791
|
+
];
|
|
792
|
+
var SimplrModule = class _SimplrModule {
|
|
793
|
+
static {
|
|
794
|
+
__name(this, "SimplrModule");
|
|
795
|
+
}
|
|
796
|
+
static forRoot(config, options) {
|
|
797
|
+
return {
|
|
798
|
+
ngModule: _SimplrModule,
|
|
799
|
+
providers: buildProviders(config, options)
|
|
800
|
+
};
|
|
801
|
+
}
|
|
802
|
+
};
|
|
803
|
+
SimplrModule = _ts_decorate10([
|
|
804
|
+
NgModule({
|
|
805
|
+
imports: [
|
|
806
|
+
SimplrProtectDirective,
|
|
807
|
+
SimplrRumViewDirective,
|
|
808
|
+
SimplrProtectedFormComponent
|
|
809
|
+
],
|
|
810
|
+
exports: [
|
|
811
|
+
SimplrProtectDirective,
|
|
812
|
+
SimplrRumViewDirective,
|
|
813
|
+
SimplrProtectedFormComponent
|
|
814
|
+
]
|
|
815
|
+
})
|
|
816
|
+
], SimplrModule);
|
|
817
|
+
|
|
818
|
+
export { SIMPLR_CONFIG, SIMPLR_DIRECTIVES, SimplrAIService, SimplrErrorHandler, SimplrFlagsService, SimplrModule, SimplrProfilesService, SimplrProtectDirective, SimplrProtectedFormComponent, SimplrRumService, SimplrRumViewDirective, SimplrService, provideSimplr };
|
|
819
|
+
//# sourceMappingURL=index.js.map
|
|
820
|
+
//# sourceMappingURL=index.js.map
|