@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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Simplr
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,257 @@
1
+ # @simplr-ai/angular
2
+
3
+ Idiomatic **Angular adapter** for the [Simplr](https://simplr.so) platform.
4
+
5
+ This package is a **thin wrapper** over the browser core SDK
6
+ [`@simplr-ai/js`](../simplr-js-sdk). It does **not** reimplement any
7
+ feature — it exposes the core's full surface through Angular primitives:
8
+ **injectable DI services**, **RxJS observables**, and **directives + a component**.
9
+
10
+ Everything the core can do — device fingerprinting, behavioral biometrics,
11
+ fraud/identity checks, order scoring, feature flags (local eval), Real User
12
+ Monitoring (RUM), anonymous profiles, and AI delegation — has an idiomatic
13
+ Angular binding here.
14
+
15
+ > Docs: https://docs.simplr.so/docs/sdks/angular
16
+
17
+ ## Install
18
+
19
+ ```bash
20
+ npm i @simplr-ai/angular @simplr-ai/js @angular/core rxjs
21
+ ```
22
+
23
+ `@angular/core` (`^17 || ^18`), `@angular/common`, `rxjs` (`^7`) and
24
+ `@simplr-ai/js` are **peer dependencies**.
25
+
26
+ ## Setup
27
+
28
+ ### Standalone (recommended) — `provideSimplr()`
29
+
30
+ ```ts
31
+ import { bootstrapApplication } from "@angular/platform-browser";
32
+ import { provideSimplr } from "@simplr-ai/angular";
33
+ import { AppComponent } from "./app/app.component";
34
+
35
+ bootstrapApplication(AppComponent, {
36
+ providers: [
37
+ provideSimplr({
38
+ apiKey: "pk_live_…", // your public key
39
+ flags: { environment: "live", refreshIntervalMs: 60_000 },
40
+ rum: { applicationId: "my-app", environment: "production" },
41
+ }),
42
+ ],
43
+ });
44
+ ```
45
+
46
+ Pipe uncaught errors into RUM by enabling the optional error handler:
47
+
48
+ ```ts
49
+ provideSimplr({ apiKey: "pk_live_…" }, { errorHandler: true });
50
+ ```
51
+
52
+ ### NgModule — `SimplrModule.forRoot()`
53
+
54
+ ```ts
55
+ import { NgModule } from "@angular/core";
56
+ import { SimplrModule } from "@simplr-ai/angular";
57
+
58
+ @NgModule({
59
+ imports: [SimplrModule.forRoot({ apiKey: "pk_live_…" })],
60
+ })
61
+ export class AppModule {}
62
+ ```
63
+
64
+ The directives and component (`simplrProtect`, `simplrRumView`,
65
+ `simplr-protected-form`) are standalone and re-exported by `SimplrModule`. In
66
+ standalone components import them directly (or use the `SIMPLR_DIRECTIVES`
67
+ array).
68
+
69
+ ---
70
+
71
+ ## Features
72
+
73
+ Each feature is bound through an injectable service. All async methods are
74
+ available as a Promise and an `*$` Observable variant (via RxJS `from`).
75
+
76
+ ### Device fingerprint + behavioral biometrics + fraud check — `SimplrService`
77
+
78
+ ```ts
79
+ import { Component, inject } from "@angular/core";
80
+ import { SimplrService } from "@simplr-ai/angular";
81
+
82
+ @Component({ /* … */ })
83
+ export class CheckoutComponent {
84
+ private simplr = inject(SimplrService);
85
+
86
+ async pay() {
87
+ const signals = await this.simplr.collect(); // device + behavior
88
+ const device = await this.simplr.getDeviceSignals(); // fingerprint only
89
+ const result = await this.simplr.check({ email: "a@b.com" }); // POST /v1/check
90
+ }
91
+
92
+ // Observable variants
93
+ signals$ = this.simplr.collect$();
94
+ }
95
+ ```
96
+
97
+ #### `[simplrProtect]` directive — protect a form on submit
98
+
99
+ Collects fresh device + behavior signals on submit and emits them. Prevents the
100
+ native submit by default (set `[simplrPreventDefault]="false"` to opt out).
101
+
102
+ ```html
103
+ <form simplrProtect (simplrSignals)="onSignals($event)" (simplrError)="onErr($event)">
104
+ <input name="email" />
105
+ <button type="submit">Pay</button>
106
+ </form>
107
+ ```
108
+
109
+ #### `<simplr-protected-form>` component
110
+
111
+ ```html
112
+ <simplr-protected-form (submitWithSignals)="submit($event.signals)">
113
+ <input name="email" />
114
+ <button type="submit">Pay</button>
115
+ </simplr-protected-form>
116
+ ```
117
+
118
+ ### Feature flags (local eval) — `SimplrFlagsService`
119
+
120
+ Deterministic per-user rollout + targeting, evaluated locally. `flags$` emits
121
+ the full flag map on every refresh; `observeFlag` emits a boolean stream.
122
+
123
+ ```ts
124
+ import { Component, inject, OnInit } from "@angular/core";
125
+ import { SimplrFlagsService } from "@simplr-ai/angular";
126
+
127
+ @Component({ /* … */ })
128
+ export class FeatureComponent implements OnInit {
129
+ private flags = inject(SimplrFlagsService);
130
+
131
+ newCheckout$ = this.flags.observeFlag("new-checkout"); // Observable<boolean>
132
+
133
+ async ngOnInit() {
134
+ await this.flags.initialize(); // loads flags + starts refresh loop
135
+ this.flags.setUser("user_123");
136
+ if (this.flags.isEnabled("beta")) { /* … */ }
137
+ }
138
+ }
139
+ ```
140
+
141
+ ```html
142
+ <app-new-checkout *ngIf="newCheckout$ | async"></app-new-checkout>
143
+ ```
144
+
145
+ ### Profiles / identify + order scoring — `SimplrProfilesService`
146
+
147
+ Anonymous profile management and real-time order fraud scoring. Device
148
+ fingerprints are auto-collected.
149
+
150
+ ```ts
151
+ const profiles = inject(SimplrProfilesService);
152
+
153
+ await profiles.identify("user_123"); // POST /v1/profiles
154
+ const order = await profiles.submitOrder({ // POST /v1/orders
155
+ external_order_id: "ord_1",
156
+ amount_cents: 4999,
157
+ currency: "USD",
158
+ });
159
+ const risk = await profiles.getProfileRisk("user_123"); // GET /v1/profiles/{id}
160
+ await profiles.reportOutcome("user_123", "fraud");
161
+
162
+ // Observable variants: identify$, submitOrder$, getProfileRisk$, reportOutcome$
163
+ ```
164
+
165
+ ### Real User Monitoring (RUM) — `SimplrRumService`
166
+
167
+ Full RUM surface. Auto-collects sessions, views, clicks, network, errors and
168
+ performance; batches + flushes.
169
+
170
+ ```ts
171
+ const rum = inject(SimplrRumService);
172
+
173
+ rum.initialize({ applicationId: "my-app" });
174
+ rum.setUser("user_123", { plan: "pro" });
175
+ rum.addAttribute("tenant", "acme");
176
+ rum.trackView("Checkout", { step: 2 });
177
+ rum.trackAction("Add to cart", "click");
178
+ rum.trackError(new Error("boom"));
179
+ rum.log("info", "checkout started");
180
+ await rum.flush();
181
+ const sessionId = rum.getSessionId();
182
+ ```
183
+
184
+ #### `[simplrRumView]` directive — declarative view tracking
185
+
186
+ ```html
187
+ <section [simplrRumView]="'Checkout'" [simplrRumViewAttributes]="{ step: 2 }"></section>
188
+ ```
189
+
190
+ #### `SimplrErrorHandler` — pipe uncaught errors into RUM
191
+
192
+ Enable via `provideSimplr(config, { errorHandler: true })`, or register
193
+ manually:
194
+
195
+ ```ts
196
+ import { ErrorHandler } from "@angular/core";
197
+ import { SimplrErrorHandler } from "@simplr-ai/angular";
198
+
199
+ providers: [{ provide: ErrorHandler, useClass: SimplrErrorHandler }];
200
+ ```
201
+
202
+ ### AI delegation — `SimplrAIService`
203
+
204
+ OAuth-like AI authentication. Full surface
205
+ (connect/createDelegation/validate/revoke/list/get/stats/revokeAllForUser).
206
+
207
+ ```ts
208
+ const ai = inject(SimplrAIService);
209
+
210
+ const conn = await ai.connect({ userId: "user_123" }); // popup/redirect
211
+ const del = await ai.createDelegation({ userId: "user_123" });
212
+ const check = await ai.validate(token);
213
+ const list = await ai.list("user_123");
214
+ const stats = await ai.stats();
215
+ await ai.revoke(del.delegationId, "logout");
216
+ await ai.revokeAllForUser("user_123");
217
+
218
+ // Every method also has an Observable `*$` variant.
219
+ ```
220
+
221
+ ---
222
+
223
+ ## Feature checklist coverage
224
+
225
+ | Contract feature | Angular binding |
226
+ | ----------------------------- | ----------------------------------------------------------- |
227
+ | Device fingerprint | `SimplrService.getDeviceSignals()/$` |
228
+ | Behavioral biometrics | `SimplrService` (`collect`, `trackInput`, `[simplrProtect]`) |
229
+ | Fraud / identity `/v1/check` | `SimplrService.check()/$` |
230
+ | Order scoring `/v1/orders` | `SimplrProfilesService.submitOrder()/$` |
231
+ | Feature flags (local eval) | `SimplrFlagsService` (`flags$`, `observeFlag`, `isEnabled`) |
232
+ | RUM (full) | `SimplrRumService`, `[simplrRumView]`, `SimplrErrorHandler` |
233
+ | Profiles / identify | `SimplrProfilesService` (`identify`, `getProfileRisk`, …) |
234
+ | AI delegation | `SimplrAIService` (full surface) |
235
+ | Input validation helpers | re-exported from `@simplr-ai/js` core |
236
+
237
+ ## Re-exported core types & helpers
238
+
239
+ For convenience the package re-exports the core SDK's classes
240
+ (`SimplrFraud`, `SimplrFlags`, `SimplrProfiles`, `SimplrRUM`, `SimplrAI`),
241
+ helpers (`getDeviceId`, `murmurHash3`, `sha256`, …) and all public types — so
242
+ you can import everything from `@simplr-ai/angular` without reaching into the
243
+ core package.
244
+
245
+ ## Build note (tsup vs ng-packagr)
246
+
247
+ This library is built with **tsup** (esm + cjs + `.d.ts`), not ng-packagr. It
248
+ ships as plain TypeScript with emitted decorator metadata (`@swc/core`), and is
249
+ **Ivy-partial-free** — i.e. no `*.partial.js` Ivy compilation artifacts. This
250
+ keeps the build fast and fully verifiable headlessly without the Angular CLI
251
+ toolchain. Angular consumers can use it directly: the standalone directives and
252
+ component are decorated and the services use explicit `@Inject` tokens, so JIT
253
+ and AOT apps both resolve them correctly.
254
+
255
+ ## License
256
+
257
+ MIT