@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.
@@ -0,0 +1,371 @@
1
+ import { InjectionToken, OnDestroy, EventEmitter, OnInit, ModuleWithProviders, EnvironmentProviders, ErrorHandler } from '@angular/core';
2
+ import { SimplrFraudConfig, SimplrFlagsConfig, SimplrProfilesConfig, SimplrRUMConfig, AIDelegationConfig, SimplrFraud, DeviceSignals, BehaviorSignals, CollectedSignals, SimplrRUM, RUMActionType, RUMActionTarget, RUMErrorData, RUMLogLevel, SimplrFlags, FlagDefinition, EvalContext, SimplrProfiles, IdentifyOptions, ProfileIdentifyResult, ProfileOrderInput, ProfileOrderFraudResult, ProfileRiskResult, SimplrAI, CreateDelegationOptions, DelegationResult, ValidationResult, DelegationInfo, DelegationStats } from '@simplr-ai/js';
3
+ export { AIDelegationConfig, BehaviorSignals, BindingMode, CollectedSignals, CreateDelegationOptions, DelegationInfo, DelegationResult, DelegationStats, DeviceSignals, EvalContext, FlagDefinition, FlagRule, IdentifyOptions, KeystrokeMetrics, MouseMetrics, ProfileIdentifyResult, ProfileOrderFraudResult, ProfileOrderInput, ProfileRiskResult, RUMActionTarget, RUMActionType, RUMErrorData, RUMEvent, RUMEventType, RUMLogLevel, SimplrAI, SimplrFlags, SimplrFlagsConfig, SimplrFraud, SimplrFraudConfig, SimplrProfiles, SimplrProfilesConfig, SimplrRUM, SimplrRUMConfig, TouchMetrics, ValidationResult, clearDeviceId, createSimplrAI, createSimplrProfiles, getDeviceId, murmurHash3, sha256 } from '@simplr-ai/js';
4
+ import { Observable, BehaviorSubject } from 'rxjs';
5
+
6
+ /**
7
+ * Unified configuration for the Simplr Angular adapter. A single config object
8
+ * configures every feature surface: fraud/biometrics, feature flags, profiles,
9
+ * RUM and AI delegation. All keys are optional except `apiKey` (your public
10
+ * `pk_*` key) which most features require.
11
+ */
12
+ interface SimplrConfig {
13
+ /** Public API key (`pk_live_…` / `pk_test_…`). Safe for the client. */
14
+ apiKey: string;
15
+ /** Override the API base URL (default `https://api.simplr.sh`). */
16
+ baseUrl?: string;
17
+ /** Options forwarded to the core `SimplrFraud` device/biometrics collector. */
18
+ fraud?: Omit<SimplrFraudConfig, "apiKey">;
19
+ /** Options forwarded to the core `SimplrFlags` feature-flag engine. */
20
+ flags?: Partial<Omit<SimplrFlagsConfig, "apiKey">>;
21
+ /**
22
+ * Options forwarded to the core `SimplrProfiles` SDK.
23
+ * Falls back to the top-level `apiKey`/`baseUrl`.
24
+ */
25
+ profiles?: Partial<Omit<SimplrProfilesConfig, "apiKey">>;
26
+ /**
27
+ * Options forwarded to the core `SimplrRUM` SDK. `applicationId` is required
28
+ * by the core when RUM is initialized.
29
+ */
30
+ rum?: Partial<SimplrRUMConfig>;
31
+ /** Options forwarded to the core `SimplrAI` delegation client. */
32
+ ai?: Partial<Omit<AIDelegationConfig, "apiKey">>;
33
+ }
34
+ /**
35
+ * DI token holding the resolved {@link SimplrConfig}. Provided by
36
+ * `provideSimplr()` or `SimplrModule.forRoot()`.
37
+ */
38
+ declare const SIMPLR_CONFIG: InjectionToken<SimplrConfig>;
39
+
40
+ /**
41
+ * Wraps the core `SimplrFraud` instance: device fingerprinting + behavioral
42
+ * biometrics + signal collection used for `/v1/check` fraud/identity checks.
43
+ *
44
+ * The constructor accepts the resolved {@link SimplrConfig} directly so it can be
45
+ * unit-tested without Angular's DI runtime: `new SimplrService(config)`.
46
+ */
47
+ declare class SimplrService implements OnDestroy {
48
+ /** The underlying core SDK instance. Exposed for advanced/escape-hatch use. */
49
+ readonly core: SimplrFraud;
50
+ private readonly config?;
51
+ constructor(config?: SimplrConfig);
52
+ /** Whether the SDK has been initialized and is ready to collect. */
53
+ get isReady(): boolean;
54
+ /** Initialize the SDK and start biometric tracking (no-op if auto-started). */
55
+ initialize(): void;
56
+ /** Start behavioral biometric tracking. */
57
+ startTracking(): void;
58
+ /** Stop behavioral biometric tracking. */
59
+ stopTracking(): void;
60
+ /** Reset all collected behavioral data. */
61
+ reset(): void;
62
+ /** Event handlers + `data-simplr-field` attr to wire up an input for keystroke biometrics. */
63
+ trackInput(fieldName: string): {
64
+ onKeyDown: (e: KeyboardEvent) => void;
65
+ onKeyUp: (e: KeyboardEvent) => void;
66
+ onPaste: () => void;
67
+ "data-simplr-field": string;
68
+ };
69
+ /** Collect the full device fingerprint only (Promise). */
70
+ getDeviceSignals(): Promise<DeviceSignals>;
71
+ /** Collect the full device fingerprint only (Observable). */
72
+ getDeviceSignals$(): Observable<DeviceSignals>;
73
+ /** Collect behavioral signals synchronously. */
74
+ getBehaviorSignals(): BehaviorSignals;
75
+ /** Collect device + behavior signals (Promise). */
76
+ collect(): Promise<CollectedSignals>;
77
+ /** Collect device + behavior signals (Observable). */
78
+ collect$(): Observable<CollectedSignals>;
79
+ /**
80
+ * Convenience: run a fraud/identity check against `/v1/check`. Collects fresh
81
+ * device + behavior signals and posts them with the configured public key.
82
+ * Returns the unwrapped `content` from the response envelope.
83
+ */
84
+ check(input?: Record<string, unknown>): Promise<unknown>;
85
+ /** Observable variant of {@link check}. */
86
+ check$(input?: Record<string, unknown>): Observable<unknown>;
87
+ ngOnDestroy(): void;
88
+ }
89
+
90
+ /**
91
+ * `[simplrProtect]` — attach Simplr device + behavioral signals to a form on
92
+ * submit. On the form's `submit` event it collects fresh signals and emits them
93
+ * via `(simplrSignals)`. By default it prevents the native submit so callers
94
+ * can finish their request with the signals attached; set
95
+ * `[simplrPreventDefault]="false"` to opt out.
96
+ *
97
+ * ```html
98
+ * <form simplrProtect (simplrSignals)="onSignals($event)"> … </form>
99
+ * ```
100
+ */
101
+ declare class SimplrProtectDirective {
102
+ private readonly simplr;
103
+ /** Prevent the native form submit while signals are collected (default true). */
104
+ simplrPreventDefault: boolean;
105
+ /** Emits the collected device + behavior signals on submit. */
106
+ simplrSignals: EventEmitter<CollectedSignals>;
107
+ /** Emits if signal collection fails. */
108
+ simplrError: EventEmitter<unknown>;
109
+ constructor(simplr: SimplrService);
110
+ onSubmit(event: Event): Promise<void>;
111
+ }
112
+
113
+ /**
114
+ * Wraps the core `SimplrRUM` Real User Monitoring SDK. Exposes the full method
115
+ * surface (setUser/clearUser/attributes/trackView/trackAction/trackError/log/
116
+ * flush/getSessionId/getViewId) plus an auto-view-tracking helper used by the
117
+ * `[simplrRumView]` directive.
118
+ *
119
+ * Unit-testable without Angular DI: `new SimplrRumService(config)`.
120
+ */
121
+ declare class SimplrRumService implements OnDestroy {
122
+ /** The underlying core RUM singleton. */
123
+ readonly core: SimplrRUM;
124
+ private readonly config?;
125
+ constructor(config?: SimplrConfig);
126
+ /**
127
+ * Initialize RUM. `applicationId` is required by the core. Pulls apiKey/baseUrl
128
+ * from the unified config when not supplied in overrides.
129
+ */
130
+ initialize(overrides?: Partial<SimplrRUMConfig>): void;
131
+ /** Whether RUM has been initialized. */
132
+ isInitialized(): boolean;
133
+ /** Associate the current session with a user. */
134
+ setUser(userId: string, attributes?: Record<string, unknown>): void;
135
+ /** Clear the current session's user. */
136
+ clearUser(): void;
137
+ /** Add a global attribute attached to every event. */
138
+ addAttribute(key: string, value: unknown): void;
139
+ /** Remove a previously added global attribute. */
140
+ removeAttribute(key: string): void;
141
+ /** Track a page/screen view. */
142
+ trackView(name: string, attributes?: Record<string, unknown>): void;
143
+ /** Track a user action. */
144
+ trackAction(name: string, type: RUMActionType, options?: {
145
+ target?: Partial<RUMActionTarget>;
146
+ attributes?: Record<string, unknown>;
147
+ }): void;
148
+ /** Track an error. */
149
+ trackError(error: Error | RUMErrorData, context?: Record<string, unknown>): void;
150
+ /** Emit a structured log message. */
151
+ log(level: RUMLogLevel, message: string, context?: Record<string, unknown>): void;
152
+ /** End the current RUM session and flush. */
153
+ stopSession(): void;
154
+ /** Force-flush the event batch. */
155
+ flush(): Promise<void>;
156
+ /** Current session id (or null). */
157
+ getSessionId(): string | null;
158
+ /** Current view id (or null). */
159
+ getViewId(): string | null;
160
+ ngOnDestroy(): void;
161
+ }
162
+
163
+ /**
164
+ * `[simplrRumView]` — declaratively track a RUM view when the host element
165
+ * initializes. The view name is the directive's bound value; an optional
166
+ * attributes object can be supplied.
167
+ *
168
+ * ```html
169
+ * <section [simplrRumView]="'Checkout'" [simplrRumViewAttributes]="{ step: 2 }"></section>
170
+ * ```
171
+ */
172
+ declare class SimplrRumViewDirective implements OnInit {
173
+ private readonly rum;
174
+ /** The view name to report. */
175
+ viewName: string;
176
+ /** Optional attributes attached to the view event. */
177
+ simplrRumViewAttributes?: Record<string, unknown>;
178
+ constructor(rum: SimplrRumService);
179
+ ngOnInit(): void;
180
+ }
181
+
182
+ /**
183
+ * `<simplr-protected-form>` — a standalone form wrapper that collects Simplr
184
+ * device + behavioral signals on submit and emits them via
185
+ * `(submitWithSignals)`. Project your form fields as content.
186
+ *
187
+ * ```html
188
+ * <simplr-protected-form (submitWithSignals)="submit($event)">
189
+ * <input name="email" /> <button type="submit">Pay</button>
190
+ * </simplr-protected-form>
191
+ * ```
192
+ */
193
+ declare class SimplrProtectedFormComponent {
194
+ private readonly simplr;
195
+ /** Prevent native submit while signals are collected (default true). */
196
+ preventDefault: boolean;
197
+ /** Emits the collected device + behavior signals together with the event. */
198
+ submitWithSignals: EventEmitter<{
199
+ signals: CollectedSignals;
200
+ event: Event;
201
+ }>;
202
+ /** Emits if signal collection fails. */
203
+ collectError: EventEmitter<unknown>;
204
+ constructor(simplr: SimplrService);
205
+ onSubmit(event: Event): Promise<void>;
206
+ }
207
+
208
+ /** Extra options for {@link provideSimplr} / {@link SimplrModule.forRoot}. */
209
+ interface ProvideSimplrOptions {
210
+ /**
211
+ * When true, registers {@link SimplrErrorHandler} as Angular's `ErrorHandler`
212
+ * so uncaught errors are piped into RUM. Default false.
213
+ */
214
+ errorHandler?: boolean;
215
+ }
216
+ /**
217
+ * Standalone provider for the Simplr Angular adapter. Use in `bootstrapApplication`:
218
+ *
219
+ * ```ts
220
+ * bootstrapApplication(AppComponent, {
221
+ * providers: [provideSimplr({ apiKey: "pk_live_…" })],
222
+ * });
223
+ * ```
224
+ */
225
+ declare function provideSimplr(config: SimplrConfig, options?: ProvideSimplrOptions): EnvironmentProviders;
226
+ /** Standalone declarables (directives + component) for ergonomic imports. */
227
+ declare const SIMPLR_DIRECTIVES: readonly [typeof SimplrProtectDirective, typeof SimplrRumViewDirective, typeof SimplrProtectedFormComponent];
228
+ /**
229
+ * NgModule for module-based Angular apps. Import `SimplrModule.forRoot(config)`
230
+ * once in your root module; the directives/component are re-exported for use in
231
+ * templates.
232
+ */
233
+ declare class SimplrModule {
234
+ static forRoot(config: SimplrConfig, options?: ProvideSimplrOptions): ModuleWithProviders<SimplrModule>;
235
+ }
236
+
237
+ /**
238
+ * Wraps the core `SimplrFlags` engine (feature flags with deterministic
239
+ * per-user rollout + targeting, evaluated locally). Adds an RxJS surface:
240
+ * `flags$` emits the full flag map whenever flags refresh, and
241
+ * `observeFlag(key, ctx?)` emits a boolean that re-evaluates on every refresh.
242
+ *
243
+ * Unit-testable without Angular DI: `new SimplrFlagsService(config)`.
244
+ */
245
+ declare class SimplrFlagsService implements OnDestroy {
246
+ /** The underlying core SDK instance. */
247
+ readonly core: SimplrFlags;
248
+ /** Emits the full `{ key -> FlagDefinition }` map on every refresh. */
249
+ readonly flags$: BehaviorSubject<Record<string, FlagDefinition>>;
250
+ private readonly config?;
251
+ private refreshTimer;
252
+ private autoInitDone;
253
+ constructor(config?: SimplrConfig);
254
+ /**
255
+ * Initialize the flag engine. Loads flags from `/v1/flags`, seeds `flags$`,
256
+ * and starts an internal refresh loop that re-emits `flags$` on each cycle.
257
+ */
258
+ initialize(overrides?: Partial<SimplrFlagsConfig>): Promise<void>;
259
+ /** Set the default user id used for flag evaluation/bucketing. */
260
+ setUser(userId: string): void;
261
+ /** Manually refresh flags from the server and re-emit `flags$`. */
262
+ refresh(): Promise<void>;
263
+ /** Manually refresh flags as an Observable. */
264
+ refresh$(): Observable<void>;
265
+ /** Evaluate a flag synchronously (local eval, murmurhash bucketing). */
266
+ isEnabled(key: string, ctx?: EvalContext): boolean;
267
+ /**
268
+ * Observe a single flag as a boolean stream. Re-evaluates and emits whenever
269
+ * `flags$` changes (i.e. on every refresh), deduping consecutive equal values.
270
+ */
271
+ observeFlag(key: string, ctx?: EvalContext): Observable<boolean>;
272
+ /** Whether the engine has loaded its initial flag set. */
273
+ isReady(): boolean;
274
+ /** Snapshot of all currently-known flag definitions. */
275
+ getAll(): Record<string, FlagDefinition>;
276
+ private emit;
277
+ ngOnDestroy(): void;
278
+ }
279
+
280
+ /**
281
+ * Wraps the core `SimplrProfiles` SDK: anonymous user profile management and
282
+ * order fraud scoring. Methods are exposed as Promises and `*$` Observable
283
+ * variants. Device fingerprints are auto-collected via a wired-in `SimplrFraud`
284
+ * collector, matching the browser core behavior.
285
+ *
286
+ * Unit-testable without Angular DI: `new SimplrProfilesService(config)`.
287
+ */
288
+ declare class SimplrProfilesService {
289
+ /** The underlying core SDK instance. */
290
+ readonly core: SimplrProfiles;
291
+ constructor(config?: SimplrConfig);
292
+ /** Identify a user — creates/updates an anonymous profile, links the device. */
293
+ identify(externalId: string, options?: IdentifyOptions): Promise<ProfileIdentifyResult>;
294
+ /** Observable variant of {@link identify}. */
295
+ identify$(externalId: string, options?: IdentifyOptions): Observable<ProfileIdentifyResult>;
296
+ /** Submit an order for real-time fraud scoring (`/v1/orders`). */
297
+ submitOrder(order: ProfileOrderInput): Promise<ProfileOrderFraudResult>;
298
+ /** Observable variant of {@link submitOrder}. */
299
+ submitOrder$(order: ProfileOrderInput): Observable<ProfileOrderFraudResult>;
300
+ /** Get the risk profile for a user (`GET /v1/profiles/{externalId}`). */
301
+ getProfileRisk(externalId: string): Promise<ProfileRiskResult>;
302
+ /** Observable variant of {@link getProfileRisk}. */
303
+ getProfileRisk$(externalId: string): Observable<ProfileRiskResult>;
304
+ /** Report a profile outcome as `fraud` or `legitimate`. */
305
+ reportOutcome(externalId: string, outcome: "fraud" | "legitimate"): Promise<void>;
306
+ /** Observable variant of {@link reportOutcome}. */
307
+ reportOutcome$(externalId: string, outcome: "fraud" | "legitimate"): Observable<void>;
308
+ }
309
+
310
+ type ConnectOptions = Parameters<SimplrAI["connect"]>[0];
311
+ type ConnectResult = Awaited<ReturnType<SimplrAI["connect"]>>;
312
+ type ValidateOptions = Parameters<SimplrAI["validate"]>[1];
313
+ /**
314
+ * Wraps the core `SimplrAI` delegation client (OAuth-like AI authentication).
315
+ * Full surface — connect/createDelegation/validate/revoke/list/get/stats/
316
+ * revokeAllForUser — exposed as Promises and `*$` Observable variants.
317
+ *
318
+ * Unit-testable without Angular DI: `new SimplrAIService(config)`.
319
+ */
320
+ declare class SimplrAIService {
321
+ /** The underlying core SDK instance. */
322
+ readonly core: SimplrAI;
323
+ constructor(config?: SimplrConfig);
324
+ /** Open the AI Connect gateway (popup/redirect) for users to connect their AI. */
325
+ connect(options: ConnectOptions): Promise<ConnectResult>;
326
+ /** Observable variant of {@link connect}. */
327
+ connect$(options: ConnectOptions): Observable<ConnectResult>;
328
+ /** Create a new AI delegation token for a user. */
329
+ createDelegation(options: CreateDelegationOptions): Promise<DelegationResult>;
330
+ /** Observable variant of {@link createDelegation}. */
331
+ createDelegation$(options: CreateDelegationOptions): Observable<DelegationResult>;
332
+ /** Validate a delegation token. */
333
+ validate(token: string, options?: ValidateOptions): Promise<ValidationResult>;
334
+ /** Observable variant of {@link validate}. */
335
+ validate$(token: string, options?: ValidateOptions): Observable<ValidationResult>;
336
+ /** Revoke a single delegation. */
337
+ revoke(delegationId: string, reason?: string): Promise<void>;
338
+ /** Observable variant of {@link revoke}. */
339
+ revoke$(delegationId: string, reason?: string): Observable<void>;
340
+ /** List delegations (optionally filtered by user). */
341
+ list(userId?: string): Promise<DelegationInfo[]>;
342
+ /** Observable variant of {@link list}. */
343
+ list$(userId?: string): Observable<DelegationInfo[]>;
344
+ /** Get a single delegation. */
345
+ get(delegationId: string): Promise<DelegationInfo>;
346
+ /** Observable variant of {@link get}. */
347
+ get$(delegationId: string): Observable<DelegationInfo>;
348
+ /** Get aggregate delegation statistics. */
349
+ stats(): Promise<DelegationStats>;
350
+ /** Observable variant of {@link stats}. */
351
+ stats$(): Observable<DelegationStats>;
352
+ /** Revoke all delegations for a user (useful on logout). Returns the count revoked. */
353
+ revokeAllForUser(userId: string, reason?: string): Promise<number>;
354
+ /** Observable variant of {@link revokeAllForUser}. */
355
+ revokeAllForUser$(userId: string, reason?: string): Observable<number>;
356
+ }
357
+
358
+ /**
359
+ * Optional Angular `ErrorHandler` that pipes uncaught application errors into
360
+ * Simplr RUM via {@link SimplrRumService.trackError} before re-logging them.
361
+ *
362
+ * Wire it up by adding `{ provide: ErrorHandler, useClass: SimplrErrorHandler }`
363
+ * to your providers (or pass `errorHandler: true` to `provideSimplr()`).
364
+ */
365
+ declare class SimplrErrorHandler implements ErrorHandler {
366
+ private readonly rum?;
367
+ constructor(rum?: SimplrRumService | undefined);
368
+ handleError(error: unknown): void;
369
+ }
370
+
371
+ export { type ProvideSimplrOptions, SIMPLR_CONFIG, SIMPLR_DIRECTIVES, SimplrAIService, type SimplrConfig, SimplrErrorHandler, SimplrFlagsService, SimplrModule, SimplrProfilesService, SimplrProtectDirective, SimplrProtectedFormComponent, SimplrRumService, SimplrRumViewDirective, SimplrService, provideSimplr };