@simplr-ai/vue 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,385 @@
1
+ import { InjectionKey, App, ComputedRef, Ref, MaybeRefOrGetter, DefineComponent, Directive } from 'vue';
2
+ import { SimplrFraud, SimplrFlags, SimplrProfiles, SimplrRUM, SimplrAI, SimplrFraudConfig, SimplrFlagsConfig, SimplrProfilesConfig, SimplrRUMConfig, AIDelegationConfig, CollectedSignals, DeviceSignals, BehaviorSignals, FlagDefinition, EvalContext, IdentifyOptions, ProfileIdentifyResult, ProfileOrderInput, ProfileOrderFraudResult, ProfileRiskResult, RUMLogLevel, RUMActionType, 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, RUMActionType, RUMEvent, RUMEventType, RUMLogLevel, SimplrAI, SimplrFlags, SimplrFlagsConfig, SimplrFraud, SimplrFraudConfig, SimplrProfiles, SimplrProfilesConfig, SimplrRUM, SimplrRUMConfig, TouchMetrics, ValidationResult, clearDeviceId, createFingerprintHash, createSimplrAI, createSimplrProfiles, getDeviceId, murmurHash3, sha256, simplrFlags, simplrRUM } from '@simplr-ai/js';
4
+
5
+ /**
6
+ * The bundle of configured core SDK instances provided by the Simplr Vue plugin.
7
+ * Every instance is the real `@simplr-ai/js` object — this adapter never
8
+ * reimplements behaviour, it only wires the core surface into Vue primitives.
9
+ */
10
+ interface SimplrContext {
11
+ /** Core fraud client: device fingerprint + behavioral biometrics + collect(). */
12
+ fraud: SimplrFraud;
13
+ /** Feature flags client (local eval + murmurhash bucketing). May be undefined if not configured. */
14
+ flags?: SimplrFlags;
15
+ /** Anonymous profiles + order fraud scoring client. May be undefined if not configured. */
16
+ profiles?: SimplrProfiles;
17
+ /** Real User Monitoring client (singleton). May be undefined if not configured. */
18
+ rum?: SimplrRUM;
19
+ /** AI delegation (OAuth-like) client. May be undefined if not configured. */
20
+ ai?: SimplrAI;
21
+ }
22
+ /** Vue injection key for the full Simplr context bundle. */
23
+ declare const SimplrInjectionKey: InjectionKey<SimplrContext>;
24
+ declare module "@vue/runtime-core" {
25
+ interface ComponentCustomProperties {
26
+ $simplr: SimplrContext;
27
+ }
28
+ }
29
+
30
+ interface CreateSimplrConfig {
31
+ /**
32
+ * Public API key (`pk_*`). Used as the default key for every sub-client
33
+ * unless that sub-client supplies its own key in its config block.
34
+ */
35
+ apiKey?: string;
36
+ /** API base URL override (passed to flags + profiles). */
37
+ baseUrl?: string;
38
+ /** Core fraud / device-signal config (or `false` to skip — fraud is on by default). */
39
+ fraud?: SimplrFraudConfig;
40
+ /**
41
+ * Feature flags config. Pass `true` to enable with defaults, an object to
42
+ * customise, or omit to skip. `initialize()` is called automatically.
43
+ */
44
+ flags?: Partial<SimplrFlagsConfig> | boolean;
45
+ /** Profiles config. Pass `true` to enable with the shared key/baseUrl, or an object. */
46
+ profiles?: Partial<SimplrProfilesConfig> | boolean;
47
+ /** RUM config — requires at least `applicationId`. Omit to skip RUM. */
48
+ rum?: SimplrRUMConfig;
49
+ /** AI delegation config. Pass `true` to enable with the shared key, or an object. */
50
+ ai?: Partial<AIDelegationConfig> | boolean;
51
+ }
52
+ /**
53
+ * The Simplr Vue plugin. Returned by {@link createSimplr}; install with
54
+ * `app.use(simplr)`. It builds the configured core SDK instances and provides
55
+ * them through Vue's `provide`/`inject` so every composable can reach them.
56
+ */
57
+ interface SimplrPlugin {
58
+ /** Vue install hook — registered when you call `app.use(plugin)`. */
59
+ install: (app: App) => void;
60
+ /** The constructed context — handy for direct access / SSR / testing. */
61
+ context: SimplrContext;
62
+ }
63
+ /**
64
+ * Create an installable Simplr plugin that wires the full `@simplr-ai/js`
65
+ * surface (fraud, flags, profiles, RUM, AI delegation) into Vue.
66
+ *
67
+ * ```ts
68
+ * import { createSimplr } from "@simplr-ai/vue";
69
+ * app.use(createSimplr({
70
+ * apiKey: "pk_live_…",
71
+ * flags: true,
72
+ * profiles: true,
73
+ * rum: { apiKey: "pk_live_…", applicationId: "my-app" },
74
+ * ai: true,
75
+ * }));
76
+ * ```
77
+ */
78
+ declare function createSimplr(config?: CreateSimplrConfig): SimplrPlugin;
79
+
80
+ /**
81
+ * Low-level accessor for the full provided Simplr context bundle.
82
+ * Throws a helpful error if the plugin was never installed.
83
+ */
84
+ declare function useSimplrContext(): SimplrContext;
85
+
86
+ interface UseSimplrReturn {
87
+ /** The underlying core fraud client. */
88
+ simplr: SimplrFraud;
89
+ /** Whether the SDK has finished initialization and is ready to collect. */
90
+ isReady: ComputedRef<boolean>;
91
+ /** Collect all signals (device fingerprint + behavioral biometrics). */
92
+ collect: () => Promise<CollectedSignals>;
93
+ /** Collect device fingerprint signals only. */
94
+ collectDeviceSignals: () => Promise<DeviceSignals>;
95
+ /** Collect behavioral biometric signals only (sync). */
96
+ collectBehaviorSignals: () => BehaviorSignals;
97
+ /** Reset all collected behavioral data. */
98
+ reset: () => void;
99
+ /** Get input tracking handlers/attrs for a named field. */
100
+ trackInput: SimplrFraud["trackInput"];
101
+ /** Start biometric tracking. */
102
+ startTracking: () => void;
103
+ /** Stop biometric tracking. */
104
+ stopTracking: () => void;
105
+ }
106
+ /**
107
+ * Access the core Simplr fraud client and its `collect()` device/behavior
108
+ * signal API. Thin wrapper over `@simplr-ai/js`'s `SimplrFraud`.
109
+ *
110
+ * Covers: [device fingerprint] [behavioral biometrics] [input validation helpers].
111
+ */
112
+ declare function useSimplr(): UseSimplrReturn;
113
+
114
+ interface UseDeviceSignalsOptions {
115
+ /** Collect immediately on mount (default: true). */
116
+ immediate?: boolean;
117
+ }
118
+ interface UseDeviceSignalsReturn {
119
+ /** The collected device fingerprint signals (null until first collect). */
120
+ signals: Ref<DeviceSignals | null>;
121
+ /** Whether a collection is in flight. */
122
+ loading: Ref<boolean>;
123
+ /** Error from the last collection, if any. */
124
+ error: Ref<Error | null>;
125
+ /** Re-collect the device signals. */
126
+ refresh: () => Promise<void>;
127
+ }
128
+ /**
129
+ * Reactive device fingerprint collection. Mirrors the React
130
+ * `useDeviceFingerprint` hook.
131
+ *
132
+ * Covers: [device fingerprint].
133
+ */
134
+ declare function useDeviceSignals(options?: UseDeviceSignalsOptions): UseDeviceSignalsReturn;
135
+
136
+ interface UseFeatureFlagReturn {
137
+ /** Reactive boolean — re-evaluates as flags load/refresh and as ctx changes. */
138
+ enabled: ComputedRef<boolean>;
139
+ /** Whether the flags client has loaded at least once. */
140
+ isReady: Ref<boolean>;
141
+ }
142
+ /**
143
+ * Reactively evaluate a single feature flag. Re-evaluates when the flag set
144
+ * finishes loading / refreshes, and when the (optional) eval context changes.
145
+ *
146
+ * Covers: [feature flags local eval].
147
+ */
148
+ declare function useFeatureFlag(key: MaybeRefOrGetter<string>, ctx?: MaybeRefOrGetter<EvalContext | undefined>): UseFeatureFlagReturn;
149
+ interface UseFeatureFlagsReturn {
150
+ /** Reactive map of every flag key → enabled boolean. */
151
+ flags: ComputedRef<Record<string, boolean>>;
152
+ /** Raw flag definitions snapshot. */
153
+ definitions: ComputedRef<Record<string, FlagDefinition>>;
154
+ /** Imperative evaluation honoring the shared context. */
155
+ isEnabled: (key: string, ctx?: EvalContext) => boolean;
156
+ /** Whether the flags client has loaded at least once. */
157
+ isReady: Ref<boolean>;
158
+ /** Force a refresh from the API. */
159
+ refresh: () => Promise<void>;
160
+ /** Set the default user id used for bucketing/targeting. */
161
+ setUser: (userId: string) => void;
162
+ }
163
+ /**
164
+ * Reactively evaluate the full feature-flag set as a `{ key: boolean }` map.
165
+ *
166
+ * Covers: [feature flags local eval].
167
+ */
168
+ declare function useFeatureFlags(ctx?: MaybeRefOrGetter<EvalContext | undefined>): UseFeatureFlagsReturn;
169
+
170
+ interface UseProfilesReturn {
171
+ /** The underlying core profiles client. */
172
+ profiles: SimplrProfiles;
173
+ /** Loading state of the most recent operation. */
174
+ loading: Ref<boolean>;
175
+ /** Error from the most recent operation. */
176
+ error: Ref<Error | null>;
177
+ /** Identify a user — creates/updates an anonymous profile, links the device. */
178
+ identify: (externalId: string, options?: IdentifyOptions) => Promise<ProfileIdentifyResult>;
179
+ /** Submit an order for real-time fraud scoring. */
180
+ submitOrder: (order: ProfileOrderInput) => Promise<ProfileOrderFraudResult>;
181
+ /** Fetch the risk profile for a user. */
182
+ getProfileRisk: (externalId: string) => Promise<ProfileRiskResult>;
183
+ /** Report a profile as fraud or legitimate. */
184
+ reportOutcome: (externalId: string, outcome: "fraud" | "legitimate") => Promise<void>;
185
+ }
186
+ /**
187
+ * Anonymous user profiles + order fraud scoring. Thin wrapper over the core
188
+ * `SimplrProfiles`; device fingerprint auto-attach is already wired by the
189
+ * plugin via `setDeviceSignalCollector`.
190
+ *
191
+ * Covers: [profiles/identify] [order scoring /v1/orders].
192
+ */
193
+ declare function useProfiles(): UseProfilesReturn;
194
+
195
+ /**
196
+ * Access the RUM instance. Falls back to the core singleton (`simplrRUM`) when
197
+ * the plugin did not configure RUM, so RUM composables work standalone too.
198
+ */
199
+ declare function useRum(): SimplrRUM;
200
+ /**
201
+ * Track a page/screen view when the component mounts (and re-track if the name
202
+ * changes). Mirrors the React `useTrackView` hook.
203
+ *
204
+ * Covers: [RUM full].
205
+ */
206
+ declare function useTrackView(name: MaybeRefOrGetter<string>): void;
207
+ /**
208
+ * Returns an action-tracking function. Mirrors React `useTrackAction`.
209
+ *
210
+ * Covers: [RUM full].
211
+ */
212
+ declare function useTrackAction(): (name: string, type: RUMActionType, attributes?: Record<string, unknown>) => void;
213
+ /**
214
+ * Returns an error-tracking function. Mirrors React `useTrackError`.
215
+ *
216
+ * Covers: [RUM full].
217
+ */
218
+ declare function useTrackError(): (error: Error, context?: Record<string, unknown>) => void;
219
+ /**
220
+ * Leveled logging helpers backed by RUM. Mirrors React `useRUMLogger`.
221
+ *
222
+ * Covers: [RUM full].
223
+ */
224
+ declare function useRumLogger(): Record<RUMLogLevel, (message: string, context?: Record<string, unknown>) => void>;
225
+ /**
226
+ * Set / clear the RUM user. Mirrors React `useRUMUser`.
227
+ *
228
+ * Covers: [RUM full].
229
+ */
230
+ declare function useRumUser(): {
231
+ setUser: (userId: string, attributes?: Record<string, unknown>) => void;
232
+ clearUser: () => void;
233
+ };
234
+ /**
235
+ * Add / remove global RUM attributes. Mirrors React `useRUMAttributes`.
236
+ *
237
+ * Covers: [RUM full].
238
+ */
239
+ declare function useRumAttributes(): {
240
+ addAttribute: (key: string, value: unknown) => void;
241
+ removeAttribute: (key: string) => void;
242
+ };
243
+ /**
244
+ * Wrap an async operation so its duration is tracked as a RUM action and any
245
+ * thrown error is reported. Mirrors React `useTrackAsync`.
246
+ *
247
+ * Covers: [RUM full].
248
+ */
249
+ declare function useTrackAsync<T>(operationName: string): (asyncFn: () => Promise<T>) => Promise<T>;
250
+ /**
251
+ * Install a global Vue `errorHandler` that forwards uncaught component errors
252
+ * to RUM. Call from a plugin/app setup, e.g. `app.use(rumErrorHandler)` is not
253
+ * needed — instead `installRumErrorHandler(app)`.
254
+ */
255
+ declare function flushRumOnUnmount(): void;
256
+
257
+ type ConnectOptions = Parameters<SimplrAI["connect"]>[0];
258
+ type ConnectResult = Awaited<ReturnType<SimplrAI["connect"]>>;
259
+ type ValidateOptions = {
260
+ fingerprintHash?: string;
261
+ aiProvider?: string;
262
+ action?: string;
263
+ };
264
+ interface UseAIDelegationReturn {
265
+ /** The underlying core AI client. */
266
+ ai: SimplrAI;
267
+ /** Loading state of the most recent operation. */
268
+ loading: Ref<boolean>;
269
+ /** Error from the most recent operation. */
270
+ error: Ref<Error | null>;
271
+ /** Open the OAuth-like AI Connect gateway (popup/redirect). */
272
+ connect: (options: ConnectOptions) => Promise<ConnectResult>;
273
+ /** Create a new AI delegation token. */
274
+ createDelegation: (options: CreateDelegationOptions) => Promise<DelegationResult>;
275
+ /** Validate an AI delegation token. */
276
+ validate: (token: string, options?: ValidateOptions) => Promise<ValidationResult>;
277
+ /** Revoke a single delegation. */
278
+ revoke: (delegationId: string, reason?: string) => Promise<void>;
279
+ /** List delegations (optionally scoped to a user). */
280
+ list: (userId?: string) => Promise<DelegationInfo[]>;
281
+ /** Get a single delegation by id. */
282
+ get: (delegationId: string) => Promise<DelegationInfo>;
283
+ /** Get delegation statistics. */
284
+ stats: () => Promise<DelegationStats>;
285
+ /** Revoke all delegations for a user (e.g. on logout). */
286
+ revokeAllForUser: (userId: string, reason?: string) => Promise<number>;
287
+ }
288
+ /**
289
+ * AI delegation (OAuth-like AI authentication). Mirrors React `useAIDelegation`.
290
+ *
291
+ * Covers: [AI delegation].
292
+ */
293
+ declare function useAIDelegation(config?: AIDelegationConfig): UseAIDelegationReturn;
294
+ interface UseDelegationsReturn {
295
+ /** Reactive list of delegations for the user. */
296
+ delegations: Ref<DelegationInfo[]>;
297
+ loading: Ref<boolean>;
298
+ error: Ref<Error | null>;
299
+ /** Re-fetch the list. */
300
+ refresh: () => Promise<void>;
301
+ /** Revoke a delegation then refresh the list. */
302
+ revoke: (delegationId: string, reason?: string) => Promise<void>;
303
+ }
304
+ /**
305
+ * Manage a reactive list of a user's delegations. Mirrors React `useDelegations`.
306
+ *
307
+ * Covers: [AI delegation].
308
+ */
309
+ declare function useDelegations(config?: AIDelegationConfig, userId?: string): UseDelegationsReturn;
310
+
311
+ /**
312
+ * `<SimplrProtectedForm>` — collects device + behavioral signals on submit and
313
+ * emits them via `@submit` (signals, event) plus `@error` (error).
314
+ */
315
+ declare const SimplrProtectedForm: DefineComponent<
316
+ Record<string, never>,
317
+ Record<string, never>,
318
+ unknown
319
+ >;
320
+
321
+ /**
322
+ * `<SimplrProtectedInput>` — an input that auto-attaches keystroke tracking
323
+ * handlers and a `data-simplr-field` marker. Props: `field`, `modelValue`.
324
+ */
325
+ declare const SimplrProtectedInput: DefineComponent<{
326
+ field: string;
327
+ modelValue?: string;
328
+ }>;
329
+
330
+ /** `<RumView name="...">` — tracks a RUM view on mount. */
331
+ declare const RumView: DefineComponent<{ name: string }>;
332
+
333
+ /**
334
+ * `<RumErrorBoundary>` — catches descendant errors via onErrorCaptured, reports
335
+ * them to RUM, and renders the `#fallback` slot. Emits `@error` (error, info).
336
+ */
337
+ declare const RumErrorBoundary: DefineComponent<
338
+ Record<string, never>,
339
+ Record<string, never>,
340
+ unknown
341
+ >;
342
+
343
+ /**
344
+ * `v-simplr-protect="fieldName"` — attaches the core fraud client's keystroke
345
+ * tracking handlers to an input element and tags it with `data-simplr-field`.
346
+ *
347
+ * The bound value is the field name. The bound element MUST receive the active
348
+ * fraud client through the directive's `arg`/context — to keep the directive
349
+ * dependency-free of injection, it pulls handlers off the `data-simplr` payload
350
+ * placed by `<SimplrProtectedForm>` / `<SimplrProtectedInput>`, or, if a
351
+ * `trackInput` factory is provided via the binding value object, uses that.
352
+ *
353
+ * Usage forms:
354
+ * v-simplr-protect="'email'"
355
+ * v-simplr-protect="{ field: 'email', trackInput }"
356
+ *
357
+ * Covers: [behavioral biometrics] [input validation helpers].
358
+ */
359
+ declare const vSimplrProtect: Directive<HTMLElement, ProtectBinding>;
360
+ type TrackInputFactory = (field: string) => {
361
+ onKeyDown: (e: KeyboardEvent) => void;
362
+ onKeyUp: (e: KeyboardEvent) => void;
363
+ onPaste: () => void;
364
+ "data-simplr-field": string;
365
+ };
366
+ type ProtectBinding = string | {
367
+ field: string;
368
+ trackInput?: TrackInputFactory;
369
+ };
370
+
371
+ /**
372
+ * Install a global Vue `app.config.errorHandler` that forwards every uncaught
373
+ * component error to RUM via `trackError`. Chains to any previously-installed
374
+ * handler.
375
+ *
376
+ * ```ts
377
+ * import { installRumErrorHandler } from "@simplr-ai/vue";
378
+ * installRumErrorHandler(app);
379
+ * ```
380
+ *
381
+ * Covers: [RUM full].
382
+ */
383
+ declare function installRumErrorHandler(app: App, rum?: SimplrRUM): void;
384
+
385
+ export { type CreateSimplrConfig, type ProtectBinding, RumErrorBoundary, RumView, type SimplrContext, SimplrInjectionKey, type SimplrPlugin, SimplrProtectedForm, SimplrProtectedInput, type TrackInputFactory, type UseAIDelegationReturn, type UseDelegationsReturn, type UseDeviceSignalsOptions, type UseDeviceSignalsReturn, type UseFeatureFlagReturn, type UseFeatureFlagsReturn, type UseProfilesReturn, type UseSimplrReturn, createSimplr, flushRumOnUnmount, installRumErrorHandler, useAIDelegation, useDelegations, useDeviceSignals, useFeatureFlag, useFeatureFlags, useProfiles, useRum, useRumAttributes, useRumLogger, useRumUser, useSimplr, useSimplrContext, useTrackAction, useTrackAsync, useTrackError, useTrackView, vSimplrProtect };