react-native-usesense 1.0.0 → 2.1.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.
@@ -1,172 +1,235 @@
1
- import { NativeModules, NativeEventEmitter } from 'react-native';
2
- const {
3
- UseSenseModule
4
- } = NativeModules;
1
+ import { NativeModules, NativeEventEmitter, Platform } from 'react-native';
2
+ const LINKING_ERROR = `react-native-usesense: the native module could not be found.\n\n` + Platform.select({
3
+ ios: `iOS: run \`cd ios && pod install\` and rebuild the app.`,
4
+ android: `Android: rebuild the app after installing the package.`,
5
+ default: ''
6
+ }) + `\n\nIf you're using Expo, the plugin must be consumed through a development build; it does not support Expo Go because it wraps a native camera SDK.`;
7
+ const UseSenseModule = NativeModules.UseSenseModule;
5
8
  if (!UseSenseModule) {
6
- throw new Error('react-native-usesense: NativeModule not found. Make sure you have linked the library correctly.\n' + 'iOS: Run `cd ios && pod install`\n' + 'Android: Rebuild the app after installing the package.');
9
+ throw new Error(LINKING_ERROR);
7
10
  }
8
11
 
9
- // ─── Types ───────────────────────────────────────────────────────────
12
+ // ─── Types ───────────────────────────────────────────────────────────────
10
13
 
11
- /** Environment for the UseSense API. */
14
+ /**
15
+ * Target environment for the UseSense API. `auto` asks the native SDK
16
+ * to detect from the API key prefix (`sk_sandbox_*` → sandbox,
17
+ * `sk_prod_*` → production).
18
+ */
12
19
 
13
- /** Session type for verification. */
20
+ /** Type of verification session. */
14
21
 
15
- /** Challenge policy controlling verification difficulty. */
22
+ /**
23
+ * Decision returned by the native SDK.
24
+ *
25
+ * These values come straight from the server's verdict and are
26
+ * exposed to the integrator for UI feedback only. The definitive
27
+ * verdict arrives at your backend via an HMAC-signed webhook; never
28
+ * trust the client-side decision for access-control.
29
+ */
16
30
 
17
- /** Decision returned by the verification engine. */
31
+ /**
32
+ * Branding overrides applied to the native camera UI.
33
+ *
34
+ * - `logoUrl`, `primaryColor`, `buttonRadius`, `fontFamily` are
35
+ * honoured on both iOS and Android.
36
+ * - `displayName`, `redirectUrl` are Android-only fields. They're
37
+ * accepted on iOS for cross-platform API parity but ignored.
38
+ */
18
39
 
19
- /** Processing stage during server-side analysis. */
40
+ /**
41
+ * Configuration for `UseSense.initialize`. The minimum required
42
+ * field is the API key; every other field has a sensible default.
43
+ */
20
44
 
21
45
  /**
22
- * Configuration for initializing the UseSense plugin.
23
- *
24
- * @example
25
- * ```ts
26
- * await UseSense.initialize({
27
- * apiKey: 'your_api_key',
28
- * environment: 'sandbox',
29
- * });
30
- * ```
46
+ * Request to start a verification session.
31
47
  */
32
48
 
33
49
  /**
34
- * Result returned when a verification session completes.
50
+ * Redacted decision object returned when a session completes.
35
51
  *
36
- * **Important:** This result is for UI feedback only.
37
- * The definitive verdict arrives at your backend via HMAC-signed webhook.
52
+ * This is the ONLY shape the plugin exposes to React Native. Pillar
53
+ * scores (channel trust, liveness, matchsense risk) are intentionally
54
+ * not included — the native SDKs strip those fields before returning
55
+ * across the bridge to prevent reverse-engineering of the server-side
56
+ * scoring logic. If you need full scoring details, consume the signed
57
+ * webhook delivered to your backend.
38
58
  */
39
59
 
40
60
  /**
41
- * Error returned when a verification session fails.
61
+ * Error thrown when a verification session fails.
62
+ *
63
+ * Matches the native SDKs' error shape: machine-readable code,
64
+ * human-readable message, retry hint.
42
65
  */
43
66
 
44
67
  /**
45
- * Events emitted during the verification session lifecycle.
68
+ * Lifecycle event types emitted by the native SDK during a
69
+ * verification session.
46
70
  */
47
71
 
48
- /** Options for starting a verification session. */
72
+ /** Single event emitted during a session. */
49
73
 
50
- /** Status of a verification session. */
74
+ /** Handle returned by `UseSense.addListener`. */
51
75
 
52
- /** Subscription handle returned by {@link UseSense.addListener}. */
53
-
54
- // ─── Implementation ──────────────────────────────────────────────────
76
+ // ─── Implementation ──────────────────────────────────────────────────────
55
77
 
56
78
  const eventEmitter = new NativeEventEmitter(UseSenseModule);
57
79
 
58
80
  /**
59
81
  * UseSense React Native plugin.
60
82
  *
61
- * Provides human presence verification by wrapping the native UseSense
62
- * iOS and Android SDKs into a single cross-platform API.
83
+ * Human presence verification wrapping the native iOS and Android
84
+ * UseSense SDKs. Every session runs inside a full-screen native
85
+ * camera activity; the plugin is a thin bridge that forwards
86
+ * initialization, verification requests, and lifecycle events to
87
+ * the platform SDK and returns a redacted decision object.
63
88
  *
64
89
  * @example
65
90
  * ```ts
66
91
  * import { UseSense } from 'react-native-usesense';
67
92
  *
68
- * await UseSense.initialize({ apiKey: 'your_key', environment: 'sandbox' });
69
- * const result = await UseSense.startSession({ sessionType: 'enrollment' });
70
- * console.log(result.decision);
93
+ * await UseSense.initialize({
94
+ * apiKey: 'sk_sandbox_...',
95
+ * environment: 'sandbox',
96
+ * });
97
+ *
98
+ * const unsubscribe = UseSense.addListener((event) => {
99
+ * console.log(event.type, event.data);
100
+ * });
101
+ *
102
+ * try {
103
+ * const result = await UseSense.startVerification({
104
+ * sessionType: 'enrollment',
105
+ * });
106
+ * console.log(result.decision); // 'APPROVE' | 'REJECT' | 'MANUAL_REVIEW'
107
+ * } finally {
108
+ * unsubscribe.remove();
109
+ * }
71
110
  * ```
72
111
  */
73
112
  export class UseSense {
74
113
  /**
75
- * Initialize the UseSense plugin. Must be called once before any other method.
114
+ * Initialize the UseSense plugin. Must be called before any other
115
+ * method. Calling again with a different API key or environment
116
+ * replaces the previous configuration.
76
117
  *
77
- * @param config - Plugin configuration including API key and environment.
78
- * @throws {UseSenseError} If the API key is invalid or configuration is malformed.
118
+ * @throws {UseSenseError} If the API key is empty or initialization
119
+ * fails on the native side.
79
120
  */
80
121
  static async initialize(config) {
81
122
  if (!config.apiKey) {
82
- throw {
123
+ const err = {
83
124
  code: 'invalid_config',
84
- message: 'apiKey is required'
125
+ message: 'apiKey is required',
126
+ isRetryable: false
85
127
  };
128
+ throw err;
86
129
  }
87
130
  return UseSenseModule.initialize({
88
131
  apiKey: config.apiKey,
89
- environment: config.environment ?? 'sandbox',
90
- organizationId: config.organizationId,
91
- sessionType: config.sessionType ?? 'enrollment',
92
- identityId: config.identityId,
93
- challengePolicy: config.challengePolicy ?? 'standard',
94
- enableAudio: config.enableAudio ?? false,
95
- timeout: config.timeout ?? 60000,
96
- metadata: config.metadata
132
+ environment: config.environment ?? 'auto',
133
+ apiEndpoint: config.apiEndpoint,
134
+ branding: config.branding,
135
+ antispoofOnDeviceEnabled: config.antispoofOnDeviceEnabled ?? false,
136
+ liveSenseV4Enabled: config.liveSenseV4Enabled ?? false
97
137
  });
98
138
  }
99
139
 
100
140
  /**
101
- * Start a verification session. Presents a full-screen native camera UI.
102
- *
103
- * The returned promise resolves when the session completes and the modal
104
- * dismisses, or rejects if an error occurs.
105
- *
106
- * @param options - Optional overrides for session type and identity ID.
107
- * @returns The verification result (for UI feedback only).
108
- * @throws {UseSenseError} On failure or cancellation.
141
+ * Start a verification session. Presents a full-screen native
142
+ * camera activity. The returned promise resolves when the session
143
+ * completes or rejects with a `UseSenseError` (including the
144
+ * `USER_CANCELLED` / `session_cancelled` cases when the user
145
+ * dismisses the camera screen).
109
146
  */
110
- static async startSession(options) {
111
- return UseSenseModule.startSession(options ?? {});
147
+ static async startVerification(request) {
148
+ return UseSenseModule.startVerification({
149
+ sessionType: request.sessionType,
150
+ externalUserId: request.externalUserId,
151
+ identityId: request.identityId,
152
+ metadata: request.metadata
153
+ });
112
154
  }
113
155
 
114
156
  /**
115
- * Cancel an in-progress verification session.
157
+ * Subscribe to real-time lifecycle events emitted by the native
158
+ * SDK during a verification session. Call this **before**
159
+ * `startVerification` so the subscription captures the earliest
160
+ * events (`SESSION_CREATED`, `PERMISSIONS_REQUESTED`).
116
161
  *
117
- * The camera UI is dismissed and the `startSession` promise rejects
118
- * with a `session_cancelled` error.
162
+ * Returns a subscription handle; call `.remove()` to stop
163
+ * receiving events.
119
164
  */
120
- static async cancelSession() {
121
- return UseSenseModule.cancelSession();
165
+ static addListener(callback) {
166
+ const subscription = eventEmitter.addListener('UseSenseEvent', raw => {
167
+ callback(raw);
168
+ });
169
+ return {
170
+ remove: () => subscription.remove()
171
+ };
122
172
  }
123
173
 
124
174
  /**
125
- * Get the status of a verification session by ID.
126
- *
127
- * @param sessionId - The session ID to query.
128
- * @returns The current status and optional result.
175
+ * Clear all event listeners and release native resources. Does not
176
+ * need to be called explicitly during normal usage; the plugin
177
+ * cleans up on process teardown. Useful when you want to re-
178
+ * initialize against a different API key or during test teardown.
129
179
  */
130
- static async getSessionStatus(sessionId) {
131
- return UseSenseModule.getSessionStatus(sessionId);
180
+ static async reset() {
181
+ return UseSenseModule.reset();
132
182
  }
133
183
 
134
184
  /**
135
- * Subscribe to real-time events during the verification lifecycle.
136
- *
137
- * Call this before `startSession()` to receive all events.
138
- *
139
- * @param callback - Function invoked for each event.
140
- * @returns A subscription handle with a `remove()` method.
141
- *
142
- * @example
143
- * ```ts
144
- * const listener = UseSense.addListener((event) => {
145
- * console.log(event.type);
146
- * });
147
- * // Later:
148
- * listener.remove();
149
- * ```
185
+ * Whether the native plugin has an active `UseSense` client. Set
186
+ * to `true` after a successful `initialize` and `false` after
187
+ * `reset`. Useful for feature-flagging UI that should only show
188
+ * when the SDK is ready.
150
189
  */
151
- static addListener(callback) {
152
- UseSenseModule.subscribeToEvents();
153
- const subscription = eventEmitter.addListener('UseSenseEvent', callback);
154
- return {
155
- remove: () => {
156
- subscription.remove();
157
- UseSenseModule.unsubscribeFromEvents();
158
- }
159
- };
190
+ static async isInitialized() {
191
+ return UseSenseModule.isInitialized();
160
192
  }
161
193
 
194
+ // ─── LiveSense v4 ─────────────────────────────────────────────────────
195
+ // Phase 1 ticket R-1.
196
+ //
197
+ // v4 runs the perspective-distortion zoom-motion capture. Passthrough
198
+ // to the native SDK's startV4Session (iOS) / startV4Verification
199
+ // (Android). The returned promise resolves with the opaque verdict;
200
+ // sub-scores and pillar verdicts are never exposed.
201
+
162
202
  /**
163
- * Get the native SDK version string.
203
+ * Start a LiveSense v4 session.
164
204
  *
165
- * @returns Version string in semver format (e.g. `"1.0.0"`).
205
+ * The session must already have been created on your backend and the
206
+ * session_token + nonce forwarded to the client. The native SDK drives
207
+ * the camera, signs the frame hash chain with the platform-attested
208
+ * key, uploads, and returns the opaque verdict.
166
209
  */
167
- static getSdkVersion() {
168
- return UseSenseModule.getSdkVersion();
210
+ static async startV4Verification(request) {
211
+ return UseSenseModule.startV4Verification({
212
+ sessionId: request.sessionId,
213
+ sessionToken: request.sessionToken,
214
+ nonce: request.nonce,
215
+ apiBaseUrl: request.apiBaseUrl,
216
+ environment: request.environment ?? 'production',
217
+ displayName: request.displayName,
218
+ brandPrimaryColor: request.brandPrimaryColor
219
+ });
169
220
  }
170
221
  }
222
+
223
+ // ─── LiveSense v4 types (R-1) ─────────────────────────────────────────────
224
+
225
+ /**
226
+ * Opaque verdict from POST /v1/sessions/:id/result. Matches the server
227
+ * contract exactly; no sub-scores leak through.
228
+ */
229
+
171
230
  export default UseSense;
231
+
232
+ // Slice 5d: Flows. A parallel surface to Sessions — host apps choose one
233
+ // per call. See guides/flows/sessions-vs-flows in the API docs.
234
+ export { UseSenseFlows, FlowError } from './flows';
172
235
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["NativeModules","NativeEventEmitter","UseSenseModule","Error","eventEmitter","UseSense","initialize","config","apiKey","code","message","environment","organizationId","sessionType","identityId","challengePolicy","enableAudio","timeout","metadata","startSession","options","cancelSession","getSessionStatus","sessionId","addListener","callback","subscribeToEvents","subscription","remove","unsubscribeFromEvents","getSdkVersion"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA,SAASA,aAAa,EAAEC,kBAAkB,QAAQ,cAAc;AAEhE,MAAM;EAAEC;AAAe,CAAC,GAAGF,aAAa;AAExC,IAAI,CAACE,cAAc,EAAE;EACnB,MAAM,IAAIC,KAAK,CACb,mGAAmG,GACjG,oCAAoC,GACpC,wDACJ,CAAC;AACH;;AAEA;;AAEA;;AAGA;;AAGA;;AAGA;;AAGA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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;EACE,aAAaC,gBAAgBA,CAACC,SAAiB,EAA0B;IACvE,OAAOrB,cAAc,CAACoB,gBAAgB,CAACC,SAAS,CAAC;EACnD;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACE,OAAOC,WAAWA,CAACC,QAAwC,EAAwB;IACjFvB,cAAc,CAACwB,iBAAiB,CAAC,CAAC;IAClC,MAAMC,YAAY,GAAGvB,YAAY,CAACoB,WAAW,CAAC,eAAe,EAAEC,QAAQ,CAAC;IACxE,OAAO;MACLG,MAAM,EAAEA,CAAA,KAAM;QACZD,YAAY,CAACC,MAAM,CAAC,CAAC;QACrB1B,cAAc,CAAC2B,qBAAqB,CAAC,CAAC;MACxC;IACF,CAAC;EACH;;EAEA;AACF;AACA;AACA;AACA;EACE,OAAOC,aAAaA,CAAA,EAAW;IAC7B,OAAO5B,cAAc,CAAC4B,aAAa,CAAC,CAAC;EACvC;AACF;AAEA,eAAezB,QAAQ","ignoreList":[]}
1
+ {"version":3,"names":["NativeModules","NativeEventEmitter","Platform","LINKING_ERROR","select","ios","android","default","UseSenseModule","Error","eventEmitter","UseSense","initialize","config","apiKey","err","code","message","isRetryable","environment","apiEndpoint","branding","antispoofOnDeviceEnabled","liveSenseV4Enabled","startVerification","request","sessionType","externalUserId","identityId","metadata","addListener","callback","subscription","raw","remove","reset","isInitialized","startV4Verification","sessionId","sessionToken","nonce","apiBaseUrl","displayName","brandPrimaryColor","UseSenseFlows","FlowError"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA,SAASA,aAAa,EAAEC,kBAAkB,EAAEC,QAAQ,QAAQ,cAAc;AAE1E,MAAMC,aAAa,GACjB,kEAAkE,GAClED,QAAQ,CAACE,MAAM,CAAC;EACdC,GAAG,EAAE,yDAAyD;EAC9DC,OAAO,EAAE,wDAAwD;EACjEC,OAAO,EAAE;AACX,CAAC,CAAC,GACF,sJAAsJ;AAExJ,MAAMC,cAAc,GAAGR,aAAa,CAACQ,cAAc;AAEnD,IAAI,CAACA,cAAc,EAAE;EACnB,MAAM,IAAIC,KAAK,CAACN,aAAa,CAAC;AAChC;;AAEA;;AAEA;AACA;AACA;AACA;AACA;;AAGA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAUA;AACA;AACA;AACA;;AAsCA;AACA;AACA;;AAcA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAeA;AACA;AACA;AACA;AACA;AACA;;AAwBA;AACA;AACA;AACA;;AAsBA;;AASA;;AAKA;;AAEA,MAAMO,YAAY,GAAG,IAAIT,kBAAkB,CAACO,cAAc,CAAC;;AAE3D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMG,QAAQ,CAAC;EACpB;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACE,aAAaC,UAAUA,CAACC,MAAsB,EAAiB;IAC7D,IAAI,CAACA,MAAM,CAACC,MAAM,EAAE;MAClB,MAAMC,GAAkB,GAAG;QACzBC,IAAI,EAAE,gBAAgB;QACtBC,OAAO,EAAE,oBAAoB;QAC7BC,WAAW,EAAE;MACf,CAAC;MACD,MAAMH,GAAG;IACX;IACA,OAAOP,cAAc,CAACI,UAAU,CAAC;MAC/BE,MAAM,EAAED,MAAM,CAACC,MAAM;MACrBK,WAAW,EAAEN,MAAM,CAACM,WAAW,IAAI,MAAM;MACzCC,WAAW,EAAEP,MAAM,CAACO,WAAW;MAC/BC,QAAQ,EAAER,MAAM,CAACQ,QAAQ;MACzBC,wBAAwB,EAAET,MAAM,CAACS,wBAAwB,IAAI,KAAK;MAClEC,kBAAkB,EAAEV,MAAM,CAACU,kBAAkB,IAAI;IACnD,CAAC,CAAC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OAAO,CAACiB,WAAW;MAChCC,iBAAiB,EAAElB,OAAO,CAACkB;IAC7B,CAAC,CAAC;EACJ;AACF;;AAEA;;AAiBA;AACA;AACA;AACA;;AAWA,eAAehC,QAAQ;;AAEvB;AACA;AACA,SACEiC,aAAa,EACbC,SAAS,QAMJ,SAAS","ignoreList":[]}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * React Native wrapper for the UseSense Flows runner.
3
+ *
4
+ * Coexists with the existing Sessions API (`UseSense.startSession`, etc.);
5
+ * this is a parallel surface, not a replacement. See `guides/flows/sessions-vs-flows`
6
+ * in the API docs for when to use which.
7
+ *
8
+ * Usage:
9
+ *
10
+ * import { UseSenseFlows, FlowError } from 'react-native-usesense';
11
+ *
12
+ * try {
13
+ * const result = await UseSenseFlows.runFlow({ flowRunId, sdkToken });
14
+ * console.log(result.outcome); // 'APPROVE' | 'REJECT' | 'MANUAL_REVIEW' | null
15
+ * } catch (e) {
16
+ * if (e instanceof FlowError) {
17
+ * // e.code: 'token_expired' | 'token_invalid' | ...
18
+ * }
19
+ * }
20
+ */
21
+ /**
22
+ * Server-driven flow run state. Host apps see only the terminal ones via
23
+ * `FlowRunResult`; intermediate states drive the runner internally.
24
+ */
25
+ export type FlowRunState = 'pending' | 'in_progress' | 'stalled' | 'awaiting_review' | 'completed' | 'errored' | 'abandoned' | 'cancelled';
26
+ /** Terminal outcome of a flow run. */
27
+ export type FlowOutcome = 'APPROVE' | 'REJECT' | 'MANUAL_REVIEW';
28
+ /**
29
+ * Uniform error taxonomy across every SDK. See `guides/flows/errors` in the
30
+ * API docs for per-code recovery patterns.
31
+ */
32
+ export type FlowErrorCode = 'token_expired' | 'token_invalid' | 'network_unavailable' | 'permission_denied' | 'provider_unavailable' | 'cancelled' | 'unsupported_action'
33
+ /** Server form validation failed. The native runner handles this inline
34
+ * (per-field highlights) and never reports terminal — but if a host app
35
+ * drives advance() outside the runner, the 422 surfaces with this code. */
36
+ | 'invalid_input' | 'unknown';
37
+ /** Result returned to the host app's `runFlow` promise on terminal state. */
38
+ export interface FlowRunResult {
39
+ flowRunId: string;
40
+ state: FlowRunState;
41
+ outcome: FlowOutcome | null;
42
+ }
43
+ /**
44
+ * Typed error thrown by `runFlow` when the native runner reports a failure.
45
+ * Mirrors the web / iOS / Android / Flutter SDKs so host apps catch one
46
+ * taxonomy regardless of platform.
47
+ */
48
+ export declare class FlowError extends Error {
49
+ readonly code: FlowErrorCode;
50
+ constructor(code: FlowErrorCode, message: string);
51
+ }
52
+ /** Options for `UseSenseFlows.runFlow`. */
53
+ export interface RunFlowOptions {
54
+ flowRunId: string;
55
+ sdkToken: string;
56
+ /** Defaults to `https://api.usesense.ai`. */
57
+ apiBaseUrl?: string;
58
+ }
59
+ /**
60
+ * Public entry point for the Flows runner. Sessions APIs are untouched;
61
+ * this is a parallel namespace.
62
+ */
63
+ export declare const UseSenseFlows: {
64
+ /**
65
+ * Run an operator-authored Flow inside the host app. Resolves with a
66
+ * [FlowRunResult] when the run reaches a terminal state (completed,
67
+ * cancelled, errored, abandoned). Rejects with a [FlowError] on transport
68
+ * / token / unsupported-action faults.
69
+ */
70
+ runFlow(options: RunFlowOptions): Promise<FlowRunResult>;
71
+ };
72
+ //# sourceMappingURL=flows.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flows.d.ts","sourceRoot":"","sources":["../../../src/flows.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAoBH;;;GAGG;AACH,MAAM,MAAM,YAAY,GACpB,SAAS,GACT,aAAa,GACb,SAAS,GACT,iBAAiB,GACjB,WAAW,GACX,SAAS,GACT,WAAW,GACX,WAAW,CAAC;AAEhB,sCAAsC;AACtC,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,QAAQ,GAAG,eAAe,CAAC;AAEjE;;;GAGG;AACH,MAAM,MAAM,aAAa,GACrB,eAAe,GACf,eAAe,GACf,qBAAqB,GACrB,mBAAmB,GACnB,sBAAsB,GACtB,WAAW,GACX,oBAAoB;AACtB;;4EAE4E;GAC1E,eAAe,GACf,SAAS,CAAC;AAoBd,6EAA6E;AAC7E,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,YAAY,CAAC;IACpB,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;CAC7B;AAQD;;;;GAIG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAClC,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;gBACjB,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM;CAKjD;AAED,2CAA2C;AAC3C,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,6CAA6C;IAC7C,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa;IACxB;;;;;OAKG;qBACoB,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;CAoB/D,CAAC"}