@tesouro/embedded-components-loader 0.0.0 → 0.11.200
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 +201 -0
- package/NOTICE +7 -0
- package/README.md +314 -5
- package/dist/caretRange.d.ts +13 -0
- package/dist/caretRange.d.ts.map +1 -0
- package/dist/entries.generated.d.ts +34 -0
- package/dist/entries.generated.d.ts.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +208 -0
- package/dist/loader.d.ts +66 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/react/experimental/BalanceHistoryWidget.d.ts +1382 -0
- package/dist/react/experimental/QuickViewWidget.d.ts +888 -0
- package/dist/react/experimental/RemoteCheckCapture.d.ts +714 -0
- package/dist/react/experimental/index.d.ts +1776 -0
- package/dist/react/index.d.ts +7429 -0
- package/dist/react/lib/AcceptDisclosuresWidget.d.ts +1457 -0
- package/dist/react/lib/BalancesWidget.d.ts +647 -0
- package/dist/react/lib/BankAccountOnboardingWidget.d.ts +2053 -0
- package/dist/react/lib/BankAccountsWidget.d.ts +773 -0
- package/dist/react/lib/BankingComplianceBannerWidget.d.ts +647 -0
- package/dist/react/lib/BillPayWidget.d.ts +651 -0
- package/dist/react/lib/CardDetailsWidget.d.ts +1647 -0
- package/dist/react/lib/CounterpartsWidget.d.ts +1698 -0
- package/dist/react/lib/CounterpartsWidgetPublic.d.ts +1697 -0
- package/dist/react/lib/CreditCardsWidget.d.ts +2153 -0
- package/dist/react/lib/DebitCardsWidget.d.ts +2149 -0
- package/dist/react/lib/ExpenseManagementWidget.d.ts +835 -0
- package/dist/react/lib/InsightsWidget.d.ts +696 -0
- package/dist/react/lib/LinkedAccountsWidget.d.ts +726 -0
- package/dist/react/lib/OfferWidget.d.ts +1421 -0
- package/dist/react/lib/ReceivablesWidget.d.ts +2556 -0
- package/dist/react/lib/RecentActivityWidget.d.ts +655 -0
- package/dist/react/lib/SettingsWidget.d.ts +775 -0
- package/dist/react/lib/TransfersWidget.d.ts +794 -0
- package/dist/react/lib/WidgetProvider.d.ts +1305 -0
- package/dist/react/lib/WidgetProviderPublic.d.ts +619 -0
- package/dist/react/lib/WidgetSuite.d.ts +5664 -0
- package/dist/stylesheet.d.ts +3 -0
- package/dist/stylesheet.d.ts.map +1 -0
- package/package.json +93 -4
|
@@ -0,0 +1,1305 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ComponentType, AnchorHTMLAttributes, ReactNode, PropsWithChildren, ErrorInfo } from 'react';
|
|
3
|
+
|
|
4
|
+
declare type FallbackProps = {
|
|
5
|
+
error: unknown;
|
|
6
|
+
resetErrorBoundary: (...args: unknown[]) => void;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
type AuthToken = string | undefined;
|
|
10
|
+
interface Auth {
|
|
11
|
+
/**
|
|
12
|
+
* Which part of the request do we use to send the auth?
|
|
13
|
+
*
|
|
14
|
+
* @default 'header'
|
|
15
|
+
*/
|
|
16
|
+
in?: 'header' | 'query' | 'cookie';
|
|
17
|
+
/**
|
|
18
|
+
* A unique identifier for the security scheme.
|
|
19
|
+
*
|
|
20
|
+
* Defined only when there are multiple security schemes whose `Auth`
|
|
21
|
+
* shape would otherwise be identical.
|
|
22
|
+
*/
|
|
23
|
+
key?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Header or query parameter name.
|
|
26
|
+
*
|
|
27
|
+
* @default 'Authorization'
|
|
28
|
+
*/
|
|
29
|
+
name?: string;
|
|
30
|
+
scheme?: 'basic' | 'bearer';
|
|
31
|
+
type: 'apiKey' | 'http';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface SerializerOptions<T> {
|
|
35
|
+
/**
|
|
36
|
+
* @default true
|
|
37
|
+
*/
|
|
38
|
+
explode: boolean;
|
|
39
|
+
style: T;
|
|
40
|
+
}
|
|
41
|
+
type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited';
|
|
42
|
+
type ObjectStyle = 'form' | 'deepObject';
|
|
43
|
+
|
|
44
|
+
type QuerySerializer = (query: Record<string, unknown>) => string;
|
|
45
|
+
type BodySerializer = (body: unknown) => unknown;
|
|
46
|
+
type QuerySerializerOptionsObject = {
|
|
47
|
+
allowReserved?: boolean;
|
|
48
|
+
array?: Partial<SerializerOptions<ArrayStyle>>;
|
|
49
|
+
object?: Partial<SerializerOptions<ObjectStyle>>;
|
|
50
|
+
};
|
|
51
|
+
type QuerySerializerOptions = QuerySerializerOptionsObject & {
|
|
52
|
+
/**
|
|
53
|
+
* Per-parameter serialization overrides. When provided, these settings
|
|
54
|
+
* override the global array/object settings for specific parameter names.
|
|
55
|
+
*/
|
|
56
|
+
parameters?: Record<string, QuerySerializerOptionsObject>;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
type HttpMethod = 'connect' | 'delete' | 'get' | 'head' | 'options' | 'patch' | 'post' | 'put' | 'trace';
|
|
60
|
+
type Client$1<RequestFn = never, Config = unknown, MethodFn = never, BuildUrlFn = never, SseFn = never> = {
|
|
61
|
+
/**
|
|
62
|
+
* Returns the final request URL.
|
|
63
|
+
*/
|
|
64
|
+
buildUrl: BuildUrlFn;
|
|
65
|
+
getConfig: () => Config;
|
|
66
|
+
request: RequestFn;
|
|
67
|
+
setConfig: (config: Config) => Config;
|
|
68
|
+
} & {
|
|
69
|
+
[K in HttpMethod]: MethodFn;
|
|
70
|
+
} & ([SseFn] extends [never] ? {
|
|
71
|
+
sse?: never;
|
|
72
|
+
} : {
|
|
73
|
+
sse: {
|
|
74
|
+
[K in HttpMethod]: SseFn;
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
interface Config$1 {
|
|
78
|
+
/**
|
|
79
|
+
* Auth token or a function returning auth token. The resolved value will be
|
|
80
|
+
* added to the request payload as defined by its `security` array.
|
|
81
|
+
*/
|
|
82
|
+
auth?: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken;
|
|
83
|
+
/**
|
|
84
|
+
* A function for serializing request body parameter. By default,
|
|
85
|
+
* {@link JSON.stringify()} will be used.
|
|
86
|
+
*/
|
|
87
|
+
bodySerializer?: BodySerializer | null;
|
|
88
|
+
/**
|
|
89
|
+
* An object containing any HTTP headers that you want to pre-populate your
|
|
90
|
+
* `Headers` object with.
|
|
91
|
+
*
|
|
92
|
+
* {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
|
|
93
|
+
*/
|
|
94
|
+
headers?: RequestInit['headers'] | Record<string, string | number | boolean | (string | number | boolean)[] | null | undefined | unknown>;
|
|
95
|
+
/**
|
|
96
|
+
* The request method.
|
|
97
|
+
*
|
|
98
|
+
* {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
|
|
99
|
+
*/
|
|
100
|
+
method?: Uppercase<HttpMethod>;
|
|
101
|
+
/**
|
|
102
|
+
* A function for serializing request query parameters. By default, arrays
|
|
103
|
+
* will be exploded in form style, objects will be exploded in deepObject
|
|
104
|
+
* style, and reserved characters are percent-encoded.
|
|
105
|
+
*
|
|
106
|
+
* This method will have no effect if the native `paramsSerializer()` Axios
|
|
107
|
+
* API function is used.
|
|
108
|
+
*
|
|
109
|
+
* {@link https://swagger.io/docs/specification/serialization/#query View examples}
|
|
110
|
+
*/
|
|
111
|
+
querySerializer?: QuerySerializer | QuerySerializerOptions;
|
|
112
|
+
/**
|
|
113
|
+
* A function validating request data. This is useful if you want to ensure
|
|
114
|
+
* the request conforms to the desired shape, so it can be safely sent to
|
|
115
|
+
* the server.
|
|
116
|
+
*/
|
|
117
|
+
requestValidator?: (data: unknown) => Promise<unknown>;
|
|
118
|
+
/**
|
|
119
|
+
* A function transforming response data before it's returned. This is useful
|
|
120
|
+
* for post-processing data, e.g., converting ISO strings into Date objects.
|
|
121
|
+
*/
|
|
122
|
+
responseTransformer?: (data: unknown) => Promise<unknown>;
|
|
123
|
+
/**
|
|
124
|
+
* A function validating response data. This is useful if you want to ensure
|
|
125
|
+
* the response conforms to the desired shape, so it can be safely passed to
|
|
126
|
+
* the transformers and returned to the user.
|
|
127
|
+
*/
|
|
128
|
+
responseValidator?: (data: unknown) => Promise<unknown>;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
type ServerSentEventsOptions<TData = unknown> = Omit<RequestInit, 'method'> & Pick<Config$1, 'method' | 'responseTransformer' | 'responseValidator'> & {
|
|
132
|
+
/**
|
|
133
|
+
* Fetch API implementation. You can use this option to provide a custom
|
|
134
|
+
* fetch instance.
|
|
135
|
+
*
|
|
136
|
+
* @default globalThis.fetch
|
|
137
|
+
*/
|
|
138
|
+
fetch?: typeof fetch;
|
|
139
|
+
/**
|
|
140
|
+
* Implementing clients can call request interceptors inside this hook.
|
|
141
|
+
*/
|
|
142
|
+
onRequest?: (url: string, init: RequestInit) => Promise<Request>;
|
|
143
|
+
/**
|
|
144
|
+
* Callback invoked when a network or parsing error occurs during streaming.
|
|
145
|
+
*
|
|
146
|
+
* This option applies only if the endpoint returns a stream of events.
|
|
147
|
+
*
|
|
148
|
+
* @param error The error that occurred.
|
|
149
|
+
*/
|
|
150
|
+
onSseError?: (error: unknown) => void;
|
|
151
|
+
/**
|
|
152
|
+
* Callback invoked when an event is streamed from the server.
|
|
153
|
+
*
|
|
154
|
+
* This option applies only if the endpoint returns a stream of events.
|
|
155
|
+
*
|
|
156
|
+
* @param event Event streamed from the server.
|
|
157
|
+
* @returns Nothing (void).
|
|
158
|
+
*/
|
|
159
|
+
onSseEvent?: (event: StreamEvent<TData>) => void;
|
|
160
|
+
serializedBody?: RequestInit['body'];
|
|
161
|
+
/**
|
|
162
|
+
* Default retry delay in milliseconds.
|
|
163
|
+
*
|
|
164
|
+
* This option applies only if the endpoint returns a stream of events.
|
|
165
|
+
*
|
|
166
|
+
* @default 3000
|
|
167
|
+
*/
|
|
168
|
+
sseDefaultRetryDelay?: number;
|
|
169
|
+
/**
|
|
170
|
+
* Maximum number of retry attempts before giving up.
|
|
171
|
+
*/
|
|
172
|
+
sseMaxRetryAttempts?: number;
|
|
173
|
+
/**
|
|
174
|
+
* Maximum retry delay in milliseconds.
|
|
175
|
+
*
|
|
176
|
+
* Applies only when exponential backoff is used.
|
|
177
|
+
*
|
|
178
|
+
* This option applies only if the endpoint returns a stream of events.
|
|
179
|
+
*
|
|
180
|
+
* @default 30000
|
|
181
|
+
*/
|
|
182
|
+
sseMaxRetryDelay?: number;
|
|
183
|
+
/**
|
|
184
|
+
* Optional sleep function for retry backoff.
|
|
185
|
+
*
|
|
186
|
+
* Defaults to using `setTimeout`.
|
|
187
|
+
*/
|
|
188
|
+
sseSleepFn?: (ms: number) => Promise<void>;
|
|
189
|
+
url: string;
|
|
190
|
+
};
|
|
191
|
+
interface StreamEvent<TData = unknown> {
|
|
192
|
+
data: TData;
|
|
193
|
+
event?: string;
|
|
194
|
+
id?: string;
|
|
195
|
+
retry?: number;
|
|
196
|
+
}
|
|
197
|
+
type ServerSentEventsResult<TData = unknown, TReturn = void, TNext = unknown> = {
|
|
198
|
+
stream: AsyncGenerator<TData extends Record<string, unknown> ? TData[keyof TData] : TData, TReturn, TNext>;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
type ErrInterceptor<Err, Res, Req, Options> = (error: Err,
|
|
202
|
+
/** response may be undefined due to a network error where no response object is produced */
|
|
203
|
+
response: Res | undefined,
|
|
204
|
+
/** request may be undefined, because error may be from building the request object itself */
|
|
205
|
+
request: Req | undefined, options: Options) => Err | Promise<Err>;
|
|
206
|
+
type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>;
|
|
207
|
+
type ResInterceptor<Res, Req, Options> = (response: Res, request: Req, options: Options) => Res | Promise<Res>;
|
|
208
|
+
declare class Interceptors<Interceptor> {
|
|
209
|
+
fns: Array<Interceptor | null>;
|
|
210
|
+
clear(): void;
|
|
211
|
+
eject(id: number | Interceptor): void;
|
|
212
|
+
exists(id: number | Interceptor): boolean;
|
|
213
|
+
getInterceptorIndex(id: number | Interceptor): number;
|
|
214
|
+
update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false;
|
|
215
|
+
use(fn: Interceptor): number;
|
|
216
|
+
}
|
|
217
|
+
interface Middleware<Req, Res, Err, Options> {
|
|
218
|
+
error: Interceptors<ErrInterceptor<Err, Res, Req, Options>>;
|
|
219
|
+
request: Interceptors<ReqInterceptor<Req, Options>>;
|
|
220
|
+
response: Interceptors<ResInterceptor<Res, Req, Options>>;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
type ResponseStyle = 'data' | 'fields';
|
|
224
|
+
interface Config<T extends ClientOptions$1 = ClientOptions$1> extends Omit<RequestInit, 'body' | 'headers' | 'method'>, Config$1 {
|
|
225
|
+
/**
|
|
226
|
+
* Base URL for all requests made by this client.
|
|
227
|
+
*/
|
|
228
|
+
baseUrl?: T['baseUrl'];
|
|
229
|
+
/**
|
|
230
|
+
* Fetch API implementation. You can use this option to provide a custom
|
|
231
|
+
* fetch instance.
|
|
232
|
+
*
|
|
233
|
+
* @default globalThis.fetch
|
|
234
|
+
*/
|
|
235
|
+
fetch?: typeof fetch;
|
|
236
|
+
/**
|
|
237
|
+
* Please don't use the Fetch client for Next.js applications. The `next`
|
|
238
|
+
* options won't have any effect.
|
|
239
|
+
*
|
|
240
|
+
* Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead.
|
|
241
|
+
*/
|
|
242
|
+
next?: never;
|
|
243
|
+
/**
|
|
244
|
+
* Return the response data parsed in a specified format. By default, `auto`
|
|
245
|
+
* will infer the appropriate method from the `Content-Type` response header.
|
|
246
|
+
* You can override this behavior with any of the {@link Body} methods.
|
|
247
|
+
* Select `stream` if you don't want to parse response data at all.
|
|
248
|
+
*
|
|
249
|
+
* @default 'auto'
|
|
250
|
+
*/
|
|
251
|
+
parseAs?: 'arrayBuffer' | 'auto' | 'blob' | 'formData' | 'json' | 'stream' | 'text';
|
|
252
|
+
/**
|
|
253
|
+
* Should we return only data or multiple fields (data, error, response, etc.)?
|
|
254
|
+
*
|
|
255
|
+
* @default 'fields'
|
|
256
|
+
*/
|
|
257
|
+
responseStyle?: ResponseStyle;
|
|
258
|
+
/**
|
|
259
|
+
* Throw an error instead of returning it in the response?
|
|
260
|
+
*
|
|
261
|
+
* @default false
|
|
262
|
+
*/
|
|
263
|
+
throwOnError?: T['throwOnError'];
|
|
264
|
+
}
|
|
265
|
+
interface RequestOptions<TData = unknown, TResponseStyle extends ResponseStyle = 'fields', ThrowOnError extends boolean = boolean, Url extends string = string> extends Config<{
|
|
266
|
+
responseStyle: TResponseStyle;
|
|
267
|
+
throwOnError: ThrowOnError;
|
|
268
|
+
}>, Pick<ServerSentEventsOptions<TData>, 'onRequest' | 'onSseError' | 'onSseEvent' | 'sseDefaultRetryDelay' | 'sseMaxRetryAttempts' | 'sseMaxRetryDelay'> {
|
|
269
|
+
/**
|
|
270
|
+
* Any body that you want to add to your request.
|
|
271
|
+
*
|
|
272
|
+
* {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
|
|
273
|
+
*/
|
|
274
|
+
body?: unknown;
|
|
275
|
+
path?: Record<string, unknown>;
|
|
276
|
+
query?: Record<string, unknown>;
|
|
277
|
+
/**
|
|
278
|
+
* Security mechanism(s) to use for the request.
|
|
279
|
+
*/
|
|
280
|
+
security?: ReadonlyArray<Auth>;
|
|
281
|
+
url: Url;
|
|
282
|
+
}
|
|
283
|
+
interface ResolvedRequestOptions<TResponseStyle extends ResponseStyle = 'fields', ThrowOnError extends boolean = boolean, Url extends string = string> extends RequestOptions<unknown, TResponseStyle, ThrowOnError, Url> {
|
|
284
|
+
headers: Headers;
|
|
285
|
+
serializedBody?: string;
|
|
286
|
+
}
|
|
287
|
+
type RequestResult<TData = unknown, TError = unknown, ThrowOnError extends boolean = boolean, TResponseStyle extends ResponseStyle = 'fields'> = ThrowOnError extends true ? Promise<TResponseStyle extends 'data' ? TData extends Record<string, unknown> ? TData[keyof TData] : TData : {
|
|
288
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
289
|
+
request: Request;
|
|
290
|
+
response: Response;
|
|
291
|
+
}> : Promise<TResponseStyle extends 'data' ? (TData extends Record<string, unknown> ? TData[keyof TData] : TData) | undefined : ({
|
|
292
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
293
|
+
error: undefined;
|
|
294
|
+
} | {
|
|
295
|
+
data: undefined;
|
|
296
|
+
error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
|
|
297
|
+
}) & {
|
|
298
|
+
/** request may be undefined, because error may be from building the request object itself */
|
|
299
|
+
request?: Request;
|
|
300
|
+
/** response may be undefined, because error may be from building the request object itself or from a network error */
|
|
301
|
+
response?: Response;
|
|
302
|
+
}>;
|
|
303
|
+
interface ClientOptions$1 {
|
|
304
|
+
baseUrl?: string;
|
|
305
|
+
responseStyle?: ResponseStyle;
|
|
306
|
+
throwOnError?: boolean;
|
|
307
|
+
}
|
|
308
|
+
type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
309
|
+
type SseFn = <TData = unknown, _TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<never, TResponseStyle, ThrowOnError>, 'method'>) => Promise<ServerSentEventsResult<TData>>;
|
|
310
|
+
type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'> & Pick<Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>, 'method'>) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
311
|
+
type BuildUrlFn = <TData extends {
|
|
312
|
+
body?: unknown;
|
|
313
|
+
path?: Record<string, unknown>;
|
|
314
|
+
query?: Record<string, unknown>;
|
|
315
|
+
url: string;
|
|
316
|
+
}>(options: TData & Options<TData>) => string;
|
|
317
|
+
type Client = Client$1<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
|
|
318
|
+
interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions>;
|
|
319
|
+
};
|
|
320
|
+
interface TDataShape {
|
|
321
|
+
body?: unknown;
|
|
322
|
+
headers?: unknown;
|
|
323
|
+
path?: unknown;
|
|
324
|
+
query?: unknown;
|
|
325
|
+
url: string;
|
|
326
|
+
}
|
|
327
|
+
type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
|
|
328
|
+
type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown, TResponseStyle extends ResponseStyle = 'fields'> = OmitKeys<RequestOptions<TResponse, TResponseStyle, ThrowOnError>, 'body' | 'path' | 'query' | 'url'> & ([TData] extends [never] ? unknown : Omit<TData, 'url'>);
|
|
329
|
+
|
|
330
|
+
type ClientOptions = {
|
|
331
|
+
baseUrl: 'https://api.stage.tesouro.com' | 'https://api.sandbox.stage.tesouro.com' | 'https://api.stage.business-banking.app' | 'https://api.tesouro.com' | 'https://api.sandbox.tesouro.com' | 'https://api.business-banking.app' | (string & {});
|
|
332
|
+
};
|
|
333
|
+
type DisclosureRequirement = 'NOT_REQUIRED' | 'REQUIRED';
|
|
334
|
+
type OrganizationType = 'BANK' | 'EMBEDDED' | 'PLATFORM' | 'TRANSACTOR' | 'VERTICAL_SOFTWARE_PROVIDER';
|
|
335
|
+
type WidgetInitResponse = {
|
|
336
|
+
bankName?: null | string;
|
|
337
|
+
/**
|
|
338
|
+
* Whether the user has accepted the version currently in force. False for a user who accepted an
|
|
339
|
+
* earlier version, which is what makes publishing a new one prompt them again, and false when
|
|
340
|
+
* there is no user yet. Prompt on this rather than on `status`, which cannot answer it: an
|
|
341
|
+
* already-active user can owe a re-acceptance while never being invited again.
|
|
342
|
+
*/
|
|
343
|
+
disclosuresAccepted?: boolean;
|
|
344
|
+
/**
|
|
345
|
+
* Whether embedded banking requires this widget session's user to accept disclosures.
|
|
346
|
+
* Resolved through the organization hierarchy, nearest owner first: the organization asked about,
|
|
347
|
+
* then its VSP, then its parent platform, then the bank, defaulting to NOT_REQUIRED.
|
|
348
|
+
* Resolved for the user when there is one, which is the rung the acceptance writes against.
|
|
349
|
+
* It falls back to the organization owning the widget application in the two cases where the user
|
|
350
|
+
* cannot answer: before the user exists, which is what an onboarding widget needs, and when their
|
|
351
|
+
* organization's settings chain resolves nothing at all. In that second case the acceptance
|
|
352
|
+
* refuses rather than reporting the user clear, so a prompt shown here is never one the widget
|
|
353
|
+
* can silently fail to record.
|
|
354
|
+
*/
|
|
355
|
+
disclosuresRequired?: DisclosureRequirement;
|
|
356
|
+
organizationId?: null | string;
|
|
357
|
+
organizationTypes?: null | Array<OrganizationType>;
|
|
358
|
+
scopes: Array<string>;
|
|
359
|
+
status?: WidgetUserStatus;
|
|
360
|
+
userId?: null | string;
|
|
361
|
+
vspName?: null | string;
|
|
362
|
+
};
|
|
363
|
+
type WidgetUserStatus = 'ACTIVE' | 'INACTIVE' | 'INVITED' | 'NOT_FOUND';
|
|
364
|
+
|
|
365
|
+
type EmbeddedClient = Client;
|
|
366
|
+
type ExtractLiterals<T> = T extends string ? string extends T ? never : T : never;
|
|
367
|
+
type BaseUrl = ExtractLiterals<ClientOptions['baseUrl']>;
|
|
368
|
+
/**
|
|
369
|
+
* Returns a new {@link EmbeddedClient} that is a shallow clone of `source`:
|
|
370
|
+
* same config, and all existing interceptors copied in their original order.
|
|
371
|
+
*
|
|
372
|
+
* Use this inside a `configClient` callback when you want to add interceptors
|
|
373
|
+
* without mutating the client instance that was passed in.
|
|
374
|
+
*
|
|
375
|
+
* @example
|
|
376
|
+
* ```ts
|
|
377
|
+
* const addLogging = useCallback((client: EmbeddedClient) => {
|
|
378
|
+
* const cloned = cloneEmbeddedClient(client);
|
|
379
|
+
* cloned.interceptors.request.use((req) => {
|
|
380
|
+
* console.log('[widget]', req.method, req.url);
|
|
381
|
+
* return req;
|
|
382
|
+
* });
|
|
383
|
+
* return cloned;
|
|
384
|
+
* }, []);
|
|
385
|
+
* ```
|
|
386
|
+
*/
|
|
387
|
+
declare function cloneEmbeddedClient(source: EmbeddedClient): EmbeddedClient;
|
|
388
|
+
|
|
389
|
+
type LinkComponentProps = AnchorHTMLAttributes<HTMLAnchorElement> & {
|
|
390
|
+
children?: ReactNode;
|
|
391
|
+
};
|
|
392
|
+
type LinkComponent = ComponentType<LinkComponentProps>;
|
|
393
|
+
/**
|
|
394
|
+
* The UI frameworks a widget's UI layer can render with.
|
|
395
|
+
*
|
|
396
|
+
* - `shadcn` — the shadcn/Tailwind implementation. This is the default and the
|
|
397
|
+
* implicit fallback, so existing consumers that select nothing keep rendering
|
|
398
|
+
* shadcn.
|
|
399
|
+
* - `tecton` — the Tecton implementation.
|
|
400
|
+
*
|
|
401
|
+
* Declared as an `as const` object (not a TypeScript `enum`) per repo
|
|
402
|
+
* convention.
|
|
403
|
+
*/
|
|
404
|
+
declare const UIFramework: {
|
|
405
|
+
readonly Shadcn: "shadcn";
|
|
406
|
+
readonly Tecton: "tecton";
|
|
407
|
+
};
|
|
408
|
+
type UIFramework = (typeof UIFramework)[keyof typeof UIFramework];
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* A renderer is just a component that accepts the widget's public props. The
|
|
412
|
+
* registry is keyed by a stable widget id (e.g. `'help-widget'`), so a single
|
|
413
|
+
* extension can register implementations for many widgets at once.
|
|
414
|
+
*/
|
|
415
|
+
type AnyRenderer = ComponentType<any>;
|
|
416
|
+
type RendererMap = Record<string, AnyRenderer>;
|
|
417
|
+
/** A framework's design-system bootstrap (idempotent, SSR-safe). */
|
|
418
|
+
type DesignSystemEnsurer = () => Promise<void>;
|
|
419
|
+
/**
|
|
420
|
+
* Registers UI renderers for a framework. Called by an extension package (never
|
|
421
|
+
* by core) to make its implementations resolvable by the widget switches.
|
|
422
|
+
*
|
|
423
|
+
* Idempotent and additive: later calls merge into any existing map for the
|
|
424
|
+
* framework, so multiple extensions (or repeated calls) compose rather than
|
|
425
|
+
* clobber. Notifies mounted switches via `useSyncExternalStore`.
|
|
426
|
+
*
|
|
427
|
+
* @param framework - The framework these renderers implement (e.g. `'tecton'`).
|
|
428
|
+
* @param map - Widget-id → component for that framework's surface.
|
|
429
|
+
*/
|
|
430
|
+
declare function registerUIRenderers(framework: UIFramework, map: RendererMap): void;
|
|
431
|
+
/**
|
|
432
|
+
* Registers a framework's design-system bootstrap (e.g. Tecton's
|
|
433
|
+
* `ensureTectonDesignSystem`). Called by an extension; core invokes the
|
|
434
|
+
* registered ensurer from its provider cascade when the resolved framework
|
|
435
|
+
* matches. No-op resolution (undefined) means the extension is absent — core
|
|
436
|
+
* simply does not bootstrap any non-shadcn design system.
|
|
437
|
+
*
|
|
438
|
+
* @param framework - The framework this ensurer bootstraps.
|
|
439
|
+
* @param ensurer - Idempotent, SSR-safe bootstrap returning a `Promise`.
|
|
440
|
+
*/
|
|
441
|
+
declare function registerDesignSystemEnsurer(framework: UIFramework, ensurer: DesignSystemEnsurer): void;
|
|
442
|
+
|
|
443
|
+
declare const ERROR_STATE_ID = "error-state";
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* The settable fields of the widget config cascade.
|
|
447
|
+
*
|
|
448
|
+
* This is the type accepted by {@link setGlobalWidgetConfig} and all provider props.
|
|
449
|
+
* It intentionally excludes `initResponse`, which is populated automatically by the
|
|
450
|
+
* provider after a successful fetch and must never be set manually.
|
|
451
|
+
*
|
|
452
|
+
* The `null` vs `undefined` distinction on `widgetToken` and `organizationId` is intentional:
|
|
453
|
+
* - `undefined` — not set at this level; inherit from the nearest ancestor or global store.
|
|
454
|
+
* - `null` — explicitly cleared; downstream sees "no value" even if an ancestor had one
|
|
455
|
+
* (e.g. after logout or deliberate de-scoping).
|
|
456
|
+
*
|
|
457
|
+
* @see {@link WidgetConfig} for the resolved output type (includes `initResponse`)
|
|
458
|
+
* @see {@link RootWidgetProvider}
|
|
459
|
+
* @see {@link WidgetProvider}
|
|
460
|
+
* @see {@link setGlobalWidgetConfig}
|
|
461
|
+
*/
|
|
462
|
+
interface WidgetConfigInput {
|
|
463
|
+
/**
|
|
464
|
+
* Base URL of the Tesouro embedded API (e.g. `"https://api.tesouro.com"`).
|
|
465
|
+
*
|
|
466
|
+
* When omitted the nearest ancestor's `baseUrl` or the global store value is used.
|
|
467
|
+
* Changing this recreates the underlying HTTP client so all subsequent requests
|
|
468
|
+
* go to the new host.
|
|
469
|
+
*/
|
|
470
|
+
baseUrl?: BaseUrl;
|
|
471
|
+
/**
|
|
472
|
+
* Bearer token used to authenticate widget requests.
|
|
473
|
+
*
|
|
474
|
+
* Injected as `Authorization: Bearer <token>` on every outgoing request via an
|
|
475
|
+
* interceptor on the scoped HTTP client. Token updates are picked up immediately
|
|
476
|
+
* without recreating the client.
|
|
477
|
+
*
|
|
478
|
+
* - `string` — send this token on all requests from this level downward.
|
|
479
|
+
* - `null` — explicitly cleared; no auth header is sent and fetching is suppressed.
|
|
480
|
+
* - `undefined` — not set at this level; inherit from the nearest ancestor or global store.
|
|
481
|
+
*/
|
|
482
|
+
widgetToken?: string | null;
|
|
483
|
+
/**
|
|
484
|
+
* Organization ID forwarded as the `x-organization-id` request header.
|
|
485
|
+
*
|
|
486
|
+
* Passed through {@link EmbedApiProvider} context rather than the auth interceptor,
|
|
487
|
+
* so individual data-access hooks can opt in per-request.
|
|
488
|
+
*
|
|
489
|
+
* - `string` — use this organization for downstream data requests.
|
|
490
|
+
* - `null` — explicitly cleared; queries that require an org ID will be disabled.
|
|
491
|
+
* - `undefined` — not set at this level; inherit from the nearest ancestor or global store.
|
|
492
|
+
*
|
|
493
|
+
* When `undefined` across the **whole** cascade (no prop, no ancestor, no global
|
|
494
|
+
* value), the resolved org defaults to the loaded `initResponse.organizationId`
|
|
495
|
+
* (see {@link WidgetConfig.initResponse}) once the widget-init fetch settles. This
|
|
496
|
+
* is the lowest-priority fallback — any explicit `string` or `null` at any cascade
|
|
497
|
+
* level wins, and an explicit `null` is preserved and never falls back.
|
|
498
|
+
*
|
|
499
|
+
* Only an **explicit** ancestor org is inherited. An ancestor's *init-derived*
|
|
500
|
+
* default does not propagate into a descendant that owns its own fetch (its own
|
|
501
|
+
* `baseUrl`/`widgetToken`); such a descendant defaults to its own
|
|
502
|
+
* `initResponse.organizationId` instead, so it never sends an ancestor's org with
|
|
503
|
+
* its own token.
|
|
504
|
+
*/
|
|
505
|
+
organizationId?: string | null;
|
|
506
|
+
/**
|
|
507
|
+
* Optional post-creation hook for the scoped HTTP client.
|
|
508
|
+
*
|
|
509
|
+
* Called once after the provider creates its scoped {@link EmbeddedClient} and
|
|
510
|
+
* applies the built-in `Authorization: Bearer` interceptor. Receives the
|
|
511
|
+
* fully-configured client and must return the client to be used for the lifetime of
|
|
512
|
+
* this provider level — either the same instance (with additional interceptors
|
|
513
|
+
* attached) or a new client entirely.
|
|
514
|
+
*
|
|
515
|
+
* **Order:** The built-in auth interceptor is always applied first. `configClient`
|
|
516
|
+
* is called on top of it, so any interceptors you add here run after auth is set.
|
|
517
|
+
*
|
|
518
|
+
* **Any prop triggers a scoped client.** A {@link WidgetProvider} creates its own
|
|
519
|
+
* scoped client whenever any prop is set — including `configClient` alone, without
|
|
520
|
+
* `baseUrl` or `widgetToken`. Only a fully props-free pass-through provider skips
|
|
521
|
+
* client creation and never calls this function.
|
|
522
|
+
*
|
|
523
|
+
* **Stability:** The function reference is included in the client creation memo's
|
|
524
|
+
* dependency array. Passing an unstable (inline) function recreates the client on
|
|
525
|
+
* every render. Stabilize with `useCallback` or define the function outside the
|
|
526
|
+
* component.
|
|
527
|
+
*
|
|
528
|
+
* **Cascade:** Inherits from the nearest ancestor when `undefined`. A child
|
|
529
|
+
* {@link WidgetProvider} that creates its own scoped client will use the resolved
|
|
530
|
+
* `configClient` from the cascade unless it provides its own override.
|
|
531
|
+
*
|
|
532
|
+
* @example
|
|
533
|
+
* ```tsx
|
|
534
|
+
* const addLogging = useCallback(
|
|
535
|
+
* (client: EmbeddedClient) => {
|
|
536
|
+
* client.interceptors.request.use((req) => {
|
|
537
|
+
* console.log('[widget]', req.method, req.url);
|
|
538
|
+
* return req;
|
|
539
|
+
* });
|
|
540
|
+
* return client;
|
|
541
|
+
* },
|
|
542
|
+
* [],
|
|
543
|
+
* );
|
|
544
|
+
*
|
|
545
|
+
* <RootWidgetProvider
|
|
546
|
+
* baseUrl="https://api.tesouro.com"
|
|
547
|
+
* widgetToken={token}
|
|
548
|
+
* configClient={addLogging}
|
|
549
|
+
* >
|
|
550
|
+
* <App />
|
|
551
|
+
* </RootWidgetProvider>
|
|
552
|
+
* ```
|
|
553
|
+
*/
|
|
554
|
+
configClient?: (client: EmbeddedClient) => EmbeddedClient;
|
|
555
|
+
/**
|
|
556
|
+
* Overrides the widget-gateway routing decision for the scoped HTTP client.
|
|
557
|
+
*
|
|
558
|
+
* Any caller reaching the Tesouro API with a widget token must route data
|
|
559
|
+
* requests through the widget gateway: prefix the path with
|
|
560
|
+
* `/api/widget-gateway/proxy` and carry the token as `X-Widget-Token`. The
|
|
561
|
+
* provider applies both automatically per request when the request origin is
|
|
562
|
+
* a known Tesouro API host (`WIDGET_GATEWAY_HOSTS`, derived from the
|
|
563
|
+
* generated `ClientOptions['baseUrl']`); `/api/widget-gateway/*` paths (the
|
|
564
|
+
* init round-trip) always pass through untouched.
|
|
565
|
+
*
|
|
566
|
+
* - `undefined` — decide from the request origin, as above. Inherits from
|
|
567
|
+
* the nearest ancestor or global store like every other config field.
|
|
568
|
+
* - `true` — always apply the rewrite, even for an unlisted base URL (e.g. a
|
|
569
|
+
* custom domain in front of the gateway).
|
|
570
|
+
* - `false` — never apply it. For hosts that route widget requests their own
|
|
571
|
+
* way, such as a same-origin BFF whose `configClient` retargets every
|
|
572
|
+
* request.
|
|
573
|
+
*
|
|
574
|
+
* Independent of {@link configClient}: a host that only adds a header keeps
|
|
575
|
+
* the built-in routing, and the built-in interceptor runs before any
|
|
576
|
+
* `configClient` interceptor.
|
|
577
|
+
*/
|
|
578
|
+
gatewayRouting?: boolean;
|
|
579
|
+
/**
|
|
580
|
+
* Component the embedded widgets should render in place of plain `<a>` tags.
|
|
581
|
+
*
|
|
582
|
+
* Pass e.g. Next.js's `Link` to make in-app navigation use the host router.
|
|
583
|
+
* Cascades like other config: provider prop > nearest ancestor > global store.
|
|
584
|
+
* When no value is set anywhere, widgets fall back to a plain `<a>` element.
|
|
585
|
+
*/
|
|
586
|
+
linkComponent?: LinkComponent;
|
|
587
|
+
/**
|
|
588
|
+
* Which UI framework the widget UI layer should render with.
|
|
589
|
+
*
|
|
590
|
+
* Lets a consuming context bind widgets to either the shadcn/Tailwind or the
|
|
591
|
+
* Tecton implementation behind the same outward-facing API. The selection is
|
|
592
|
+
* a presentation concern only — it cascades through the provider tree exactly
|
|
593
|
+
* like {@link linkComponent} and is read by UI libraries via `useUIFramework`;
|
|
594
|
+
* it never appears in any widget's feature-library or component props.
|
|
595
|
+
*
|
|
596
|
+
* - `'shadcn'` — the shadcn/Tailwind implementation.
|
|
597
|
+
* - `'tecton'` — the Tecton implementation.
|
|
598
|
+
* - `null` / `undefined` — not set at this level; inherit from the nearest
|
|
599
|
+
* ancestor or global store, falling back to `shadcn` when unset everywhere.
|
|
600
|
+
* `shadcn` is the implicit default, so existing consumers need no changes.
|
|
601
|
+
*/
|
|
602
|
+
uiFramework?: UIFramework | null;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Props shared by every analytics-owner-capable widget provider.
|
|
606
|
+
*
|
|
607
|
+
* Combines the full settable cascade ({@link WidgetConfigInput}) with the
|
|
608
|
+
* analytics opt-out honored by analytics owners. Both {@link RootWidgetProvider}
|
|
609
|
+
* and {@link WidgetProvider} build their public props on top of this; the latter
|
|
610
|
+
* adds error-boundary props of its own.
|
|
611
|
+
*
|
|
612
|
+
* @see {@link WidgetConfigInput} for per-field cascade and `null` vs omitted semantics
|
|
613
|
+
*/
|
|
614
|
+
interface WidgetProviderBaseProps extends WidgetConfigInput {
|
|
615
|
+
/**
|
|
616
|
+
* Opt out of all analytics capture and prevent PostHog from loading. Default `true`.
|
|
617
|
+
*
|
|
618
|
+
* Honored only by an analytics **owner** — a {@link RootWidgetProvider} or a
|
|
619
|
+
* standalone {@link WidgetProvider} with no parent provider. When `false`,
|
|
620
|
+
* owner-bound `track` calls in this subtree become no-ops and the PostHog
|
|
621
|
+
* installer is never dynamically imported for this owner's environment.
|
|
622
|
+
* Setting it on a nested {@link WidgetProvider} is ignored in v1 (a one-time
|
|
623
|
+
* `console.warn` is emitted to make the no-op discoverable).
|
|
624
|
+
*/
|
|
625
|
+
analytics?: boolean;
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* The fully-resolved widget config at a given provider level.
|
|
629
|
+
*
|
|
630
|
+
* Extends {@link WidgetConfigInput} with `initResponse`, which is populated automatically
|
|
631
|
+
* after a successful `GET /api/widget-gateway/init` fetch. This type is returned by
|
|
632
|
+
* {@link useWidgetConfig} and represents the cascade result — it is never an input type.
|
|
633
|
+
*
|
|
634
|
+
* `initResponse` cascades as a **whole object** — it is either present (a fetch succeeded
|
|
635
|
+
* at some level in the tree) or absent (`undefined`). Fields are never merged across levels.
|
|
636
|
+
* It is cleared immediately when `widgetToken` or `baseUrl` changes to prevent stale tenant
|
|
637
|
+
* data from persisting across auth boundaries.
|
|
638
|
+
*
|
|
639
|
+
* @see {@link WidgetConfigInput} for the input type accepted by providers and setGlobalWidgetConfig
|
|
640
|
+
* @see {@link useWidgetConfig}
|
|
641
|
+
*/
|
|
642
|
+
interface WidgetConfig extends WidgetConfigInput {
|
|
643
|
+
/**
|
|
644
|
+
* The response from `GET /api/widget-gateway/init` for this level of the tree.
|
|
645
|
+
*
|
|
646
|
+
* Read-only — populated automatically by the provider. Use {@link useWidgetConfig}
|
|
647
|
+
* to access it; do not attempt to set this field via {@link setGlobalWidgetConfig}
|
|
648
|
+
* or provider props (those accept {@link WidgetConfigInput}, which excludes this field).
|
|
649
|
+
*
|
|
650
|
+
* Its `organizationId` also seeds the resolved {@link WidgetConfigInput.organizationId}
|
|
651
|
+
* when the org is unset across the whole cascade.
|
|
652
|
+
*/
|
|
653
|
+
initResponse?: WidgetInitResponse;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
/**
|
|
657
|
+
* Copy for the states `WidgetProvider` renders *itself*, in place of the widget:
|
|
658
|
+
* the error-boundary fallback and the disclosures gate. A host overrides any
|
|
659
|
+
* subset through the `providerLabels` prop, which cascades like
|
|
660
|
+
* `disclosuresAcceptance`.
|
|
661
|
+
*
|
|
662
|
+
* Not named `Labels` on the public surface: a widget's own `labels` prop is a
|
|
663
|
+
* different thing, and these two travel together on every widget's props type.
|
|
664
|
+
*/
|
|
665
|
+
interface WidgetProviderLabels {
|
|
666
|
+
/** Default copy for the built-in error boundary fallback. */
|
|
667
|
+
errorBoundaryFallback: string;
|
|
668
|
+
/** Heading when init reports disclosures are required and not yet accepted. */
|
|
669
|
+
disclosuresRequiredTitle: string;
|
|
670
|
+
/** Heading while a token-only refresh leaves init stale for the live token. */
|
|
671
|
+
disclosuresRefreshingTitle: string;
|
|
672
|
+
/** Supporting copy while the accept action is withheld for a stale init. */
|
|
673
|
+
disclosuresRefreshingDescription: string;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
/**
|
|
677
|
+
* Replaces the global widget config and notifies all reactive subscribers.
|
|
678
|
+
*
|
|
679
|
+
* Designed for non-React entry points — web component hosts, imperative SDKs, or any
|
|
680
|
+
* code outside the React tree — that need to push configuration into mounted widgets
|
|
681
|
+
* before or after they render. Any mounted {@link RootWidgetProvider} or component
|
|
682
|
+
* calling {@link useWidgetConfig} outside a provider re-renders automatically via
|
|
683
|
+
* `useSyncExternalStore`.
|
|
684
|
+
*
|
|
685
|
+
* **Priority**: The global store is the lowest-priority fallback. Any prop passed
|
|
686
|
+
* directly to a {@link RootWidgetProvider} or {@link WidgetProvider} overrides it.
|
|
687
|
+
*
|
|
688
|
+
* @param config - The new global config. **Replaces** the previous value entirely;
|
|
689
|
+
* fields absent from `config` revert to `undefined` on the next read.
|
|
690
|
+
*
|
|
691
|
+
* @example
|
|
692
|
+
* ```ts
|
|
693
|
+
* // Web component attribute-change handler — outside the React tree
|
|
694
|
+
* setGlobalWidgetConfig({
|
|
695
|
+
* baseUrl: 'https://api.tesouro.com',
|
|
696
|
+
* widgetToken: tokenFromHost,
|
|
697
|
+
* });
|
|
698
|
+
* ```
|
|
699
|
+
*
|
|
700
|
+
* @see {@link getGlobalWidgetConfig} for a synchronous non-reactive read
|
|
701
|
+
* @see {@link RootWidgetProvider} for the React provider that subscribes to this store
|
|
702
|
+
*/
|
|
703
|
+
declare function setGlobalWidgetConfig(config: WidgetConfigInput): void;
|
|
704
|
+
/**
|
|
705
|
+
* Merges a partial widget config into the global store and notifies subscribers.
|
|
706
|
+
*
|
|
707
|
+
* Unlike {@link setGlobalWidgetConfig}, this does **not** wipe untouched fields:
|
|
708
|
+
* keys absent from `patch` are preserved. Keys explicitly present in `patch` —
|
|
709
|
+
* including those set to `undefined` or `null` — overwrite. Use this when you
|
|
710
|
+
* have a single field to update (most commonly a freshly fetched
|
|
711
|
+
* `widgetToken`) without disturbing the rest of the global config.
|
|
712
|
+
*
|
|
713
|
+
* @param patch - The fields to merge into the existing global config. Omitted
|
|
714
|
+
* keys are preserved; explicitly present keys replace their counterparts.
|
|
715
|
+
*
|
|
716
|
+
* @example
|
|
717
|
+
* ```ts
|
|
718
|
+
* setGlobalWidgetConfig({ baseUrl: 'https://api.tesouro.com', widgetToken: 'a' });
|
|
719
|
+
* updateGlobalWidgetConfig({ widgetToken: 'b' });
|
|
720
|
+
* // baseUrl is still 'https://api.tesouro.com'
|
|
721
|
+
* ```
|
|
722
|
+
*
|
|
723
|
+
* @see {@link setGlobalWidgetConfig} for the replace-all variant
|
|
724
|
+
*/
|
|
725
|
+
declare function updateGlobalWidgetConfig(patch: WidgetConfigInput): void;
|
|
726
|
+
/**
|
|
727
|
+
* Returns the current global widget config synchronously without subscribing to changes.
|
|
728
|
+
*
|
|
729
|
+
* Use this in non-React contexts such as event handlers or imperative callbacks where
|
|
730
|
+
* you need a one-off read. For reactive reads inside React components use
|
|
731
|
+
* {@link useWidgetConfig} instead.
|
|
732
|
+
*
|
|
733
|
+
* @returns The current {@link WidgetConfig} from the global store. The object is
|
|
734
|
+
* replaced (not mutated) on each {@link setGlobalWidgetConfig} call — do not
|
|
735
|
+
* cache the return value across renders or async boundaries.
|
|
736
|
+
*
|
|
737
|
+
* @see {@link setGlobalWidgetConfig} to write to the global store
|
|
738
|
+
* @see {@link useWidgetConfig} for a reactive React hook alternative
|
|
739
|
+
*/
|
|
740
|
+
declare function getGlobalWidgetConfig(): WidgetConfigInput;
|
|
741
|
+
|
|
742
|
+
/**
|
|
743
|
+
* The widget-init state a non-React host observes.
|
|
744
|
+
*
|
|
745
|
+
* A discriminated union, so `status` narrows the payload: the `ready` branch
|
|
746
|
+
* guarantees an `initResponse` and the `error` branch guarantees an `error`.
|
|
747
|
+
*
|
|
748
|
+
* - `idle` — no init in flight and none landed. The owner has no usable
|
|
749
|
+
* `widgetToken` yet, or it was cleared (logout, de-scoping). Also the state
|
|
750
|
+
* before any provider mounts and after the last one unmounts. A host that
|
|
751
|
+
* supplies the token asynchronously — minting it before calling
|
|
752
|
+
* `setGlobalWidgetConfig`, or mounting `RefreshingRootWidgetProvider`, which
|
|
753
|
+
* passes `widgetToken={null}` while its fetcher runs — therefore sees `idle`
|
|
754
|
+
* *before* `loading`, so loading chrome should cover both. The channel says
|
|
755
|
+
* nothing about the mint itself: if it fails, the state stays `idle`, and
|
|
756
|
+
* surfacing that is the host's job.
|
|
757
|
+
* - `loading` — **no usable init response yet**, and a
|
|
758
|
+
* `GET /api/widget-gateway/init` is in flight or about to be. This is the
|
|
759
|
+
* first-load and token-rotation signal, *not* "a request is in flight": a
|
|
760
|
+
* background refetch that still has a valid response for the active token
|
|
761
|
+
* stays `ready`, so a host rendering from this channel never blanks
|
|
762
|
+
* mid-session. (A host that needs to show a refresh indicator wants a
|
|
763
|
+
* separate in-flight flag, which this channel does not carry.)
|
|
764
|
+
* - `ready` — an init response fetched under the currently-resolved token.
|
|
765
|
+
* - `error` — the last init fetch settled as a failure. `initResponse` rides
|
|
766
|
+
* along when a previously-successful response is still valid for the active
|
|
767
|
+
* token and only a later refetch failed, which is the same split
|
|
768
|
+
* `useWidgetError()` + `useWidgetConfig()` expose together in the tree; a host
|
|
769
|
+
* can render through a background failure instead of blanking.
|
|
770
|
+
*
|
|
771
|
+
* A response is never carried across a token change: while a rotation's
|
|
772
|
+
* replacement fetch is in flight the status is `loading`, even though the React
|
|
773
|
+
* tree deliberately keeps the previous response visible for UI continuity.
|
|
774
|
+
*/
|
|
775
|
+
type WidgetInitState = {
|
|
776
|
+
status: 'idle';
|
|
777
|
+
} | {
|
|
778
|
+
status: 'loading';
|
|
779
|
+
} | {
|
|
780
|
+
status: 'ready';
|
|
781
|
+
initResponse: WidgetInitResponse;
|
|
782
|
+
} | {
|
|
783
|
+
status: 'error';
|
|
784
|
+
error: Error;
|
|
785
|
+
initResponse?: WidgetInitResponse;
|
|
786
|
+
};
|
|
787
|
+
/**
|
|
788
|
+
* Returns the current widget-init state synchronously, without subscribing.
|
|
789
|
+
*
|
|
790
|
+
* The non-React equivalent of reading `useWidgetConfig().initResponse` +
|
|
791
|
+
* `useWidgetLoading()` + `useWidgetError()` together. Use it for a one-off read
|
|
792
|
+
* from an event handler or imperative SDK call, and pair it with
|
|
793
|
+
* {@link subscribeToGlobalWidgetInitState} when you need to react to changes —
|
|
794
|
+
* reading first closes the window where init settles before your subscription
|
|
795
|
+
* lands.
|
|
796
|
+
*
|
|
797
|
+
* @returns The elected owner's {@link WidgetInitState}, or an `idle` state when
|
|
798
|
+
* no provider is mounted. The object is replaced (never mutated) on change.
|
|
799
|
+
*
|
|
800
|
+
* @example
|
|
801
|
+
* ```ts
|
|
802
|
+
* const state = getGlobalWidgetInitState();
|
|
803
|
+
* if (state.status === 'ready' && state.initResponse.status === 'INVITED') {
|
|
804
|
+
* showDisclosureGate();
|
|
805
|
+
* }
|
|
806
|
+
* ```
|
|
807
|
+
*
|
|
808
|
+
* @see {@link subscribeToGlobalWidgetInitState} for change notifications
|
|
809
|
+
* @see {@link getGlobalWidgetConfig} for the matching read of the config store
|
|
810
|
+
* @see {@link useWidgetConfig} for the React equivalent
|
|
811
|
+
*/
|
|
812
|
+
declare function getGlobalWidgetInitState(): WidgetInitState;
|
|
813
|
+
/**
|
|
814
|
+
* Subscribes to widget-init changes from outside the React tree.
|
|
815
|
+
*
|
|
816
|
+
* Designed for web-component and drop-in hosts, which have no hooks available
|
|
817
|
+
* to them: it is the only way for such a host to branch on the user's init
|
|
818
|
+
* status (`status`, `scopes`, `disclosuresRequired`, …) or to show its own
|
|
819
|
+
* loading and error chrome around the widget tree.
|
|
820
|
+
*
|
|
821
|
+
* The listener fires only on change — not immediately on subscribe. Call
|
|
822
|
+
* {@link getGlobalWidgetInitState} once alongside subscribing to pick up an
|
|
823
|
+
* init that has already settled.
|
|
824
|
+
*
|
|
825
|
+
* @param listener - Called with the new state on every change. Repeat states
|
|
826
|
+
* are collapsed, so a provider re-render that changes nothing does not fire.
|
|
827
|
+
* @returns An unsubscribe function. Call it to stop receiving updates; the
|
|
828
|
+
* channel holds no reference to the listener afterwards.
|
|
829
|
+
*
|
|
830
|
+
* @example
|
|
831
|
+
* ```ts
|
|
832
|
+
* const unsubscribe = subscribeToGlobalWidgetInitState((state) => {
|
|
833
|
+
* // `idle` too, not just `loading`: a host that mints its own token sits at
|
|
834
|
+
* // `idle` until the token lands. See {@link WidgetInitState}.
|
|
835
|
+
* host.toggleSpinner(state.status === 'idle' || state.status === 'loading');
|
|
836
|
+
* if (state.status === 'ready') {
|
|
837
|
+
* host.setDisclosureGate(
|
|
838
|
+
* state.initResponse.disclosuresRequired === 'REQUIRED',
|
|
839
|
+
* );
|
|
840
|
+
* }
|
|
841
|
+
* });
|
|
842
|
+
*
|
|
843
|
+
* // Cover an init that settled before this subscription:
|
|
844
|
+
* const current = getGlobalWidgetInitState();
|
|
845
|
+
*
|
|
846
|
+
* // Later, when the host tears down:
|
|
847
|
+
* unsubscribe();
|
|
848
|
+
* ```
|
|
849
|
+
*
|
|
850
|
+
* @see {@link getGlobalWidgetInitState} for a synchronous non-reactive read
|
|
851
|
+
* @see {@link setGlobalWidgetConfig} for the matching non-React config channel
|
|
852
|
+
*/
|
|
853
|
+
declare function subscribeToGlobalWidgetInitState(listener: (state: WidgetInitState) => void): () => void;
|
|
854
|
+
|
|
855
|
+
/**
|
|
856
|
+
* Props for {@link RootWidgetProvider}.
|
|
857
|
+
*
|
|
858
|
+
* All fields are optional and come from {@link WidgetProviderBaseProps}. When a
|
|
859
|
+
* field is omitted the global store value (set via {@link setGlobalWidgetConfig})
|
|
860
|
+
* is used as a reactive fallback. See {@link WidgetConfigInput} for per-field
|
|
861
|
+
* cascade and `null` vs omitted semantics.
|
|
862
|
+
*/
|
|
863
|
+
interface RootWidgetProviderProps extends WidgetProviderBaseProps {
|
|
864
|
+
/**
|
|
865
|
+
* Host-supplied replacement for the `GET /api/widget-gateway/init` response.
|
|
866
|
+
*
|
|
867
|
+
* For first-party hosts whose users authenticate directly against the
|
|
868
|
+
* Tesouro issuer: the host already holds a user access token whose claims
|
|
869
|
+
* carry everything init would return, so the widget-gateway round-trip is
|
|
870
|
+
* redundant. When this prop is set the provider skips the init fetch
|
|
871
|
+
* entirely — no `/api/widget-gateway/init` request is made — and the given
|
|
872
|
+
* object is exposed as `initResponse` to the whole subtree (scope gating,
|
|
873
|
+
* org default, `useWidgetConfig()`), exactly as a fetched response would be.
|
|
874
|
+
*
|
|
875
|
+
* The `widgetToken` (typically the user's bearer access token in this mode)
|
|
876
|
+
* is still required and still rides every data request as
|
|
877
|
+
* `Authorization: Bearer <token>`; only the init round-trip is bypassed.
|
|
878
|
+
*
|
|
879
|
+
* Embed integrations that mint widget JWEs must leave this unset — the
|
|
880
|
+
* gateway init response is the source of truth for their scopes and status.
|
|
881
|
+
*/
|
|
882
|
+
unstable_initResponseOverride?: WidgetInitResponse;
|
|
883
|
+
/**
|
|
884
|
+
* Accept surface shown when the caller owes disclosures — INVITED or
|
|
885
|
+
* an ACTIVE user who owes a new version. Pass `<AcceptDisclosuresWidget />`
|
|
886
|
+
* so gated widgets have somewhere to accept. Cascades to nested
|
|
887
|
+
* WidgetProviders.
|
|
888
|
+
*/
|
|
889
|
+
disclosuresAcceptance?: ReactNode;
|
|
890
|
+
/**
|
|
891
|
+
* Overrides for the copy a descendant `WidgetProvider` renders in place of
|
|
892
|
+
* its widget: the built-in error-boundary fallback and the disclosures gate.
|
|
893
|
+
* Any subset; unlisted keys keep their defaults. Cascades to the whole tree.
|
|
894
|
+
*/
|
|
895
|
+
providerLabels?: Partial<WidgetProviderLabels>;
|
|
896
|
+
}
|
|
897
|
+
/**
|
|
898
|
+
* Top-level provider for the widget config cascade.
|
|
899
|
+
*
|
|
900
|
+
* Place this **once** near the root of your React tree. It:
|
|
901
|
+
* - Resolves `baseUrl`, `widgetToken`, and `organizationId` from its own props,
|
|
902
|
+
* falling back to the global store (see {@link setGlobalWidgetConfig}) for any
|
|
903
|
+
* prop that is `undefined`.
|
|
904
|
+
* - Calls `GET /api/widget-gateway/init` whenever both `baseUrl` and `widgetToken`
|
|
905
|
+
* resolve to a non-null value. The response is stored as `initResponse` and made
|
|
906
|
+
* available to every descendant via {@link useWidgetConfig}.
|
|
907
|
+
* - Creates a stable `QueryClient` once on mount and provides it via
|
|
908
|
+
* `QueryClientProvider` for the entire subtree.
|
|
909
|
+
* - Creates a scoped `@hey-api` HTTP client configured for `baseUrl`. The
|
|
910
|
+
* `Authorization: Bearer` header is kept current via a ref-based interceptor so
|
|
911
|
+
* token rotation never recreates the client.
|
|
912
|
+
* - Provides `QueryClientProvider`, {@link EmbedApiProvider}, and `WidgetContext`
|
|
913
|
+
* for the entire subtree.
|
|
914
|
+
*
|
|
915
|
+
* Reacts to {@link setGlobalWidgetConfig} calls after mount — any global change
|
|
916
|
+
* that resolves a previously missing `baseUrl` or `widgetToken` triggers a fetch.
|
|
917
|
+
*
|
|
918
|
+
* @param props.baseUrl - API base URL. Falls back to `global.baseUrl` when omitted.
|
|
919
|
+
* @param props.widgetToken - Auth token. Falls back to `global.widgetToken` when omitted.
|
|
920
|
+
* @param props.organizationId - Org ID for data requests. Falls back to `global.organizationId`,
|
|
921
|
+
* then to the init response's `organizationId` when unset everywhere.
|
|
922
|
+
* @param props.children - The React subtree that will consume the widget context.
|
|
923
|
+
*
|
|
924
|
+
* @example
|
|
925
|
+
* ```tsx
|
|
926
|
+
* // Standard usage — one fetch for the whole tree
|
|
927
|
+
* <RootWidgetProvider
|
|
928
|
+
* baseUrl="https://api.tesouro.com"
|
|
929
|
+
* widgetToken={userToken}
|
|
930
|
+
* >
|
|
931
|
+
* <App />
|
|
932
|
+
* </RootWidgetProvider>
|
|
933
|
+
* ```
|
|
934
|
+
*
|
|
935
|
+
* @example
|
|
936
|
+
* ```tsx
|
|
937
|
+
* // Host sets the URL globally; React tree only needs the token
|
|
938
|
+
* setGlobalWidgetConfig({ baseUrl: 'https://api.tesouro.com' });
|
|
939
|
+
*
|
|
940
|
+
* <RootWidgetProvider widgetToken={token}>
|
|
941
|
+
* <App />
|
|
942
|
+
* </RootWidgetProvider>
|
|
943
|
+
* ```
|
|
944
|
+
*
|
|
945
|
+
* @see {@link WidgetProvider} for mid-tree token or URL overrides
|
|
946
|
+
* @see {@link useWidgetConfig} to read the resolved config in descendants
|
|
947
|
+
* @see {@link setGlobalWidgetConfig} to push config imperatively from outside React
|
|
948
|
+
*/
|
|
949
|
+
declare function RootWidgetProvider({ children, baseUrl, widgetToken, organizationId, configClient, gatewayRouting, linkComponent, uiFramework, analytics, unstable_initResponseOverride, disclosuresAcceptance, providerLabels, }: PropsWithChildren<RootWidgetProviderProps>): React.JSX.Element;
|
|
950
|
+
|
|
951
|
+
/**
|
|
952
|
+
* Props for {@link WidgetProvider}.
|
|
953
|
+
*
|
|
954
|
+
* All fields are optional. When **all** are omitted the provider is a transparent
|
|
955
|
+
* pass-through: no fetch is issued and all resolved values cascade unchanged from
|
|
956
|
+
* the nearest ancestor.
|
|
957
|
+
*/
|
|
958
|
+
interface WidgetProviderProps extends WidgetProviderBaseProps {
|
|
959
|
+
/**
|
|
960
|
+
* Fallback rendered when a render-time exception is caught inside this
|
|
961
|
+
* provider's subtree. Pass either a `ReactNode` (rendered directly) or a
|
|
962
|
+
* render-prop receiving `{ error, resetErrorBoundary }` from
|
|
963
|
+
* `react-error-boundary`. Default is a plain `role="alert"` div whose copy
|
|
964
|
+
* comes from `providerLabels.errorBoundaryFallback`.
|
|
965
|
+
*/
|
|
966
|
+
errorFallback?: ReactNode | ((props: FallbackProps) => ReactNode);
|
|
967
|
+
/**
|
|
968
|
+
* Called once when the boundary catches an error, before the fallback
|
|
969
|
+
* renders. Use for telemetry / error tracking / partner logging. Exceptions
|
|
970
|
+
* thrown from `onError` propagate per `react-error-boundary` semantics.
|
|
971
|
+
*/
|
|
972
|
+
onError?: (error: unknown, info: ErrorInfo) => void;
|
|
973
|
+
/**
|
|
974
|
+
* Accept surface shown when the caller owes disclosures — an INVITED
|
|
975
|
+
* teammate (including `NOT_REQUIRED` orgs, who still need Accept to
|
|
976
|
+
* activate) or an ACTIVE user who owes a new version. Pass
|
|
977
|
+
* `<AcceptDisclosuresWidget />`. Cascades like `linkComponent`.
|
|
978
|
+
* WidgetProvider cannot import the widget itself (cycle).
|
|
979
|
+
*/
|
|
980
|
+
disclosuresAcceptance?: ReactNode;
|
|
981
|
+
/**
|
|
982
|
+
* Overrides for the copy this provider renders in place of the widget: the
|
|
983
|
+
* built-in error-boundary fallback and the disclosures gate. Any subset;
|
|
984
|
+
* unlisted keys keep their defaults. Cascades like `linkComponent`.
|
|
985
|
+
*
|
|
986
|
+
* Named `providerLabels` rather than `labels` because a widget's own
|
|
987
|
+
* `labels` prop sits alongside this one on the same props type.
|
|
988
|
+
*/
|
|
989
|
+
providerLabels?: Partial<WidgetProviderLabels>;
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
type WidgetTokenFetcher = () => Promise<{
|
|
993
|
+
widgetToken: string;
|
|
994
|
+
exp?: number;
|
|
995
|
+
}>;
|
|
996
|
+
type WidgetTokenState = {
|
|
997
|
+
status: 'loading';
|
|
998
|
+
} | {
|
|
999
|
+
status: 'ready';
|
|
1000
|
+
widgetToken: string;
|
|
1001
|
+
exp?: number;
|
|
1002
|
+
isRefreshing: boolean;
|
|
1003
|
+
lastError?: unknown;
|
|
1004
|
+
} | {
|
|
1005
|
+
status: 'error';
|
|
1006
|
+
error: unknown;
|
|
1007
|
+
};
|
|
1008
|
+
interface WidgetTokenManager {
|
|
1009
|
+
start(): void;
|
|
1010
|
+
stop(): void;
|
|
1011
|
+
refresh(): Promise<void>;
|
|
1012
|
+
/**
|
|
1013
|
+
* Reports that the API rejected `widgetToken` with a 401. Refreshes once per
|
|
1014
|
+
* rejected token, and backs off when a token this produced is rejected too.
|
|
1015
|
+
* Ignored for a token other than the current one, while a refresh is in
|
|
1016
|
+
* flight, and while stopped.
|
|
1017
|
+
*/
|
|
1018
|
+
reportRejectedToken(widgetToken: string): Promise<void>;
|
|
1019
|
+
getState(): WidgetTokenState;
|
|
1020
|
+
subscribe(listener: () => void): () => void;
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
interface CspConfig {
|
|
1024
|
+
/**
|
|
1025
|
+
* Nonce for the one `<style>` tag the widgets add at runtime (the dialog
|
|
1026
|
+
* scroll lock). Found on the page when not set. `null` clears an override.
|
|
1027
|
+
*/
|
|
1028
|
+
nonce?: string | null;
|
|
1029
|
+
/**
|
|
1030
|
+
* URL of a self-hosted pdf.js worker. Defaults to the Tesouro CDN. `null`
|
|
1031
|
+
* restores the default.
|
|
1032
|
+
*/
|
|
1033
|
+
pdfWorkerSrc?: string | null;
|
|
1034
|
+
}
|
|
1035
|
+
/**
|
|
1036
|
+
* Page-wide overrides for hosts with a strict Content Security Policy. Fields
|
|
1037
|
+
* left out keep their current value. Global rather than a provider prop
|
|
1038
|
+
* because pdf.js and the scroll lock each keep one setting per page.
|
|
1039
|
+
*/
|
|
1040
|
+
declare function configureCsp(options: CspConfig): void;
|
|
1041
|
+
|
|
1042
|
+
interface WidgetTokenRefreshProviderProps {
|
|
1043
|
+
fetcher: WidgetTokenFetcher;
|
|
1044
|
+
leadSeconds?: number;
|
|
1045
|
+
onToken?: (widgetToken: string) => void;
|
|
1046
|
+
}
|
|
1047
|
+
declare function WidgetTokenRefreshProvider({ fetcher, leadSeconds, onToken, children, }: PropsWithChildren<WidgetTokenRefreshProviderProps>): React.JSX.Element;
|
|
1048
|
+
|
|
1049
|
+
type RefreshingRootWidgetProviderProps = Omit<RootWidgetProviderProps, 'widgetToken'> & WidgetTokenRefreshProviderProps;
|
|
1050
|
+
/**
|
|
1051
|
+
* One-stop provider that bundles {@link WidgetTokenRefreshProvider} and
|
|
1052
|
+
* {@link RootWidgetProvider} so callers don't have to wire `useWidgetToken()`
|
|
1053
|
+
* into the `widgetToken` prop themselves. Takes every `RootWidgetProvider`
|
|
1054
|
+
* prop *except* `widgetToken` (which is managed by the internal token
|
|
1055
|
+
* refresh manager) plus the refresh provider's `fetcher` / `leadSeconds` /
|
|
1056
|
+
* `onToken`.
|
|
1057
|
+
*
|
|
1058
|
+
* While the manager is `loading` or `error`, this passes `widgetToken={null}`
|
|
1059
|
+
* to `RootWidgetProvider`, deferring the init fetch until a valid token is
|
|
1060
|
+
* available. Once `ready`, it passes the live `state.widgetToken` through.
|
|
1061
|
+
*
|
|
1062
|
+
* Children render inside both providers' contexts, so `useWidgetToken()` and
|
|
1063
|
+
* `useWidgetConfig()` both work in descendants — useful for status badges,
|
|
1064
|
+
* retry buttons, etc.
|
|
1065
|
+
*
|
|
1066
|
+
* @example
|
|
1067
|
+
* ```tsx
|
|
1068
|
+
* <RefreshingRootWidgetProvider
|
|
1069
|
+
* baseUrl="https://api.tesouro.com"
|
|
1070
|
+
* fetcher={async () => {
|
|
1071
|
+
* const res = await fetch('/api/widget-token').then((r) => r.json());
|
|
1072
|
+
* return { widgetToken: res.token, exp: res.exp };
|
|
1073
|
+
* }}
|
|
1074
|
+
* >
|
|
1075
|
+
* <App />
|
|
1076
|
+
* </RefreshingRootWidgetProvider>
|
|
1077
|
+
* ```
|
|
1078
|
+
*/
|
|
1079
|
+
declare function RefreshingRootWidgetProvider({ fetcher, leadSeconds, onToken, children, ...rootProps }: PropsWithChildren<RefreshingRootWidgetProviderProps>): React.JSX.Element;
|
|
1080
|
+
|
|
1081
|
+
/**
|
|
1082
|
+
* Returns the fully-resolved {@link WidgetConfig} for the nearest provider level.
|
|
1083
|
+
*
|
|
1084
|
+
* Reads from the nearest `WidgetContext` ancestor (set by {@link RootWidgetProvider}
|
|
1085
|
+
* or {@link WidgetProvider}) and falls back to the global store when called outside
|
|
1086
|
+
* any provider. Subscribes to {@link setGlobalWidgetConfig} calls reactively via
|
|
1087
|
+
* `useSyncExternalStore`.
|
|
1088
|
+
*
|
|
1089
|
+
* **Cascade priority** (highest to lowest):
|
|
1090
|
+
* 1. Nearest `WidgetProvider` / `RootWidgetProvider` own prop
|
|
1091
|
+
* 2. Global store (`setGlobalWidgetConfig`)
|
|
1092
|
+
*
|
|
1093
|
+
* @returns The resolved {@link WidgetConfig} at the nearest provider level. All fields
|
|
1094
|
+
* may be `undefined` if no values have been provided at any level. `initResponse` is
|
|
1095
|
+
* `undefined` until the first successful fetch completes.
|
|
1096
|
+
*
|
|
1097
|
+
* @example
|
|
1098
|
+
* ```tsx
|
|
1099
|
+
* function BankNameBadge() {
|
|
1100
|
+
* const { initResponse } = useWidgetConfig();
|
|
1101
|
+
* if (!initResponse) return <Skeleton />;
|
|
1102
|
+
* return <span>{initResponse.bankName}</span>;
|
|
1103
|
+
* }
|
|
1104
|
+
* ```
|
|
1105
|
+
*
|
|
1106
|
+
* @see {@link useWidgetLoading} to check whether a fetch is currently in progress
|
|
1107
|
+
* @see {@link useWidgetError} to check whether the last fetch failed
|
|
1108
|
+
* @see {@link useOwnWidgetConfig} to read only what the *current* level contributed
|
|
1109
|
+
*/
|
|
1110
|
+
declare function useWidgetConfig(): WidgetConfig;
|
|
1111
|
+
/**
|
|
1112
|
+
* Returns only the {@link WidgetConfig} fields explicitly set at the **current**
|
|
1113
|
+
* provider level, without inheriting from ancestors.
|
|
1114
|
+
*
|
|
1115
|
+
* Useful for debugging or conditional logic that needs to distinguish "set here"
|
|
1116
|
+
* from "inherited from parent". Fields not explicitly set at this level are
|
|
1117
|
+
* `undefined` even if a parent has a value.
|
|
1118
|
+
*
|
|
1119
|
+
* Does **not** subscribe to the global store — use {@link useWidgetConfig} if you
|
|
1120
|
+
* need the fully-resolved (cascaded) config.
|
|
1121
|
+
*
|
|
1122
|
+
* @returns The partial {@link WidgetConfig} owned by the nearest provider, or `null`
|
|
1123
|
+
* when called outside any provider context.
|
|
1124
|
+
*
|
|
1125
|
+
* @example
|
|
1126
|
+
* ```tsx
|
|
1127
|
+
* function DebugLayer() {
|
|
1128
|
+
* const own = useOwnWidgetConfig();
|
|
1129
|
+
* // e.g. { baseUrl: undefined, widgetToken: 'tok_partner', organizationId: undefined }
|
|
1130
|
+
* // — only widgetToken was set at this provider level
|
|
1131
|
+
* console.log('own config at this level:', own);
|
|
1132
|
+
* return null;
|
|
1133
|
+
* }
|
|
1134
|
+
* ```
|
|
1135
|
+
*
|
|
1136
|
+
* @see {@link useWidgetConfig} to read the fully-resolved cascaded config instead
|
|
1137
|
+
*/
|
|
1138
|
+
declare function useOwnWidgetConfig(): WidgetConfigInput | null;
|
|
1139
|
+
/**
|
|
1140
|
+
* Host-supplied AcceptDisclosuresWidget (or equivalent) for callers who
|
|
1141
|
+
* owe disclosures. `undefined` outside a provider or when the host has
|
|
1142
|
+
* not passed `disclosuresAcceptance`.
|
|
1143
|
+
*/
|
|
1144
|
+
declare function useDisclosuresAcceptanceSurface(): ReactNode | undefined;
|
|
1145
|
+
/**
|
|
1146
|
+
* Is the still-visible `initResponse` one produced under a *different* widget
|
|
1147
|
+
* token than the active one — i.e. is a token-only refresh in flight?
|
|
1148
|
+
*
|
|
1149
|
+
* While this is true the init-derived `organizationId` default is deliberately
|
|
1150
|
+
* withheld (a stale init org must never scope a request carrying the new
|
|
1151
|
+
* token), so `useWidgetConfig().organizationId` reads `undefined` for a host
|
|
1152
|
+
* that supplies no explicit org. That is a *timing* gap, not the org changing.
|
|
1153
|
+
*
|
|
1154
|
+
* Read this before treating a missing org as "no org": it lets a consumer
|
|
1155
|
+
* distinguish the refresh window from a genuinely unscoped widget, and hold its
|
|
1156
|
+
* last known org rather than tearing its subtree down every time the host
|
|
1157
|
+
* rotates a token (EMBD-4823). Callers that simply disable a query while the org
|
|
1158
|
+
* is missing need not consult it — the suppression is already doing its job.
|
|
1159
|
+
*
|
|
1160
|
+
* @returns `true` while a replacement init is in flight for a rotated token;
|
|
1161
|
+
* `false` outside a provider, and once the new init settles.
|
|
1162
|
+
*
|
|
1163
|
+
* @see {@link useWidgetConfig} for the resolved config whose org this suppresses
|
|
1164
|
+
*/
|
|
1165
|
+
declare function useWidgetInitStaleForToken(): boolean;
|
|
1166
|
+
/**
|
|
1167
|
+
* Returns a stable callback that re-triggers the widget-init fetch at the
|
|
1168
|
+
* **nearest provider level that owns a fetch**.
|
|
1169
|
+
*
|
|
1170
|
+
* Pass-through {@link WidgetProvider} instances (no own `baseUrl`/`widgetToken`)
|
|
1171
|
+
* automatically bubble this up the tree, so the returned function always targets
|
|
1172
|
+
* the correct fetch-owning ancestor regardless of nesting depth.
|
|
1173
|
+
*
|
|
1174
|
+
* Re-fetching keeps the current `initResponse` visible while the request is in
|
|
1175
|
+
* flight — the previous data is not cleared until the new response arrives. This
|
|
1176
|
+
* prevents a blank/loading flash during background refreshes.
|
|
1177
|
+
*
|
|
1178
|
+
* **A failed re-fetch keeps it visible too**, and only sets
|
|
1179
|
+
* {@link useWidgetError}. `useWidgetFetch` clears the retained response for a
|
|
1180
|
+
* *client* change, which is an auth boundary; a re-fetch is not one, so the
|
|
1181
|
+
* previous response is still valid for the active token. This line previously
|
|
1182
|
+
* said the opposite, which matters: a consumer branching on `!initResponse`
|
|
1183
|
+
* would conclude a failed refresh drops it back to its pre-init state, when in
|
|
1184
|
+
* fact it keeps rendering the response it already had. Verified against the
|
|
1185
|
+
* running provider (EMBD-4911) — a suite gating on a field of the init response
|
|
1186
|
+
* holds that gate closed after a failed refresh rather than falling open.
|
|
1187
|
+
*
|
|
1188
|
+
* @returns A stable `() => void` function. Calling it increments an internal counter
|
|
1189
|
+
* that re-triggers the fetch effect. Returns a no-op when called outside any provider.
|
|
1190
|
+
*
|
|
1191
|
+
* @example
|
|
1192
|
+
* ```tsx
|
|
1193
|
+
* function RefreshButton() {
|
|
1194
|
+
* const refetch = useRefetchWidget();
|
|
1195
|
+
* return <button onClick={refetch}>Refresh</button>;
|
|
1196
|
+
* }
|
|
1197
|
+
* ```
|
|
1198
|
+
*
|
|
1199
|
+
* @see {@link useWidgetLoading} to show a loading indicator during the re-fetch
|
|
1200
|
+
* @see {@link useWidgetError} to handle fetch failures after a re-fetch
|
|
1201
|
+
*/
|
|
1202
|
+
declare function useRefetchWidget(): () => void;
|
|
1203
|
+
/**
|
|
1204
|
+
* Returns `true` while the nearest fetch-owning provider has a widget-init
|
|
1205
|
+
* request in flight, `false` otherwise.
|
|
1206
|
+
*
|
|
1207
|
+
* Pass-through {@link WidgetProvider} instances (no own `baseUrl`/`widgetToken`)
|
|
1208
|
+
* bubble this up automatically, so the value always reflects the owning ancestor
|
|
1209
|
+
* regardless of nesting depth.
|
|
1210
|
+
*
|
|
1211
|
+
* `loading` transitions to `true` immediately when a fetch starts (including
|
|
1212
|
+
* manual refetches) and back to `false` when the fetch settles — whether it
|
|
1213
|
+
* succeeds or fails.
|
|
1214
|
+
*
|
|
1215
|
+
* @returns `true` during an active fetch, `false` at all other times.
|
|
1216
|
+
* Returns `false` when called outside any provider.
|
|
1217
|
+
*
|
|
1218
|
+
* @example
|
|
1219
|
+
* ```tsx
|
|
1220
|
+
* function WidgetShell() {
|
|
1221
|
+
* const loading = useWidgetLoading();
|
|
1222
|
+
* const { initResponse } = useWidgetConfig();
|
|
1223
|
+
*
|
|
1224
|
+
* if (loading && !initResponse) return <Skeleton />;
|
|
1225
|
+
* if (!initResponse) return null;
|
|
1226
|
+
* return <Dashboard data={initResponse} />;
|
|
1227
|
+
* }
|
|
1228
|
+
* ```
|
|
1229
|
+
*
|
|
1230
|
+
* @see {@link useWidgetError} for fetch failure state
|
|
1231
|
+
* @see {@link useRefetchWidget} to manually trigger a re-fetch
|
|
1232
|
+
*/
|
|
1233
|
+
declare function useWidgetLoading(): boolean;
|
|
1234
|
+
/**
|
|
1235
|
+
* Returns the most recent fetch error from the nearest fetch-owning provider,
|
|
1236
|
+
* or `null` when the last fetch succeeded (or no fetch has run yet).
|
|
1237
|
+
*
|
|
1238
|
+
* Pass-through {@link WidgetProvider} instances (no own `baseUrl`/`widgetToken`)
|
|
1239
|
+
* bubble this up automatically, so the value always reflects the owning ancestor
|
|
1240
|
+
* regardless of nesting depth.
|
|
1241
|
+
*
|
|
1242
|
+
* The error is cleared automatically when:
|
|
1243
|
+
* - `widgetToken` or `baseUrl` changes (a new fetch is about to start).
|
|
1244
|
+
* - A subsequent fetch succeeds.
|
|
1245
|
+
*
|
|
1246
|
+
* A first-load failure leaves `initResponse` from {@link useWidgetConfig}
|
|
1247
|
+
* undefined. A failed same-token refetch can keep the previous response visible
|
|
1248
|
+
* because it is still valid for the active token; token/client changes never
|
|
1249
|
+
* carry the old response across the auth boundary.
|
|
1250
|
+
*
|
|
1251
|
+
* API errors thrown by the HTTP client (4xx/5xx responses) are wrapped in a plain
|
|
1252
|
+
* `Error` with `error.cause` set to the raw response body for inspection.
|
|
1253
|
+
*
|
|
1254
|
+
* @returns The `Error` from the last failed fetch, or `null`. Returns `null` when
|
|
1255
|
+
* called outside any provider.
|
|
1256
|
+
*
|
|
1257
|
+
* @example
|
|
1258
|
+
* ```tsx
|
|
1259
|
+
* function WidgetShell() {
|
|
1260
|
+
* const error = useWidgetError();
|
|
1261
|
+
* const { initResponse } = useWidgetConfig();
|
|
1262
|
+
* const refetch = useRefetchWidget();
|
|
1263
|
+
*
|
|
1264
|
+
* if (error) return <ErrorBanner message={error.message} onRetry={refetch} />;
|
|
1265
|
+
* if (!initResponse) return <Skeleton />;
|
|
1266
|
+
* return <Dashboard data={initResponse} />;
|
|
1267
|
+
* }
|
|
1268
|
+
* ```
|
|
1269
|
+
*
|
|
1270
|
+
* @see {@link useWidgetLoading} for in-flight request status
|
|
1271
|
+
* @see {@link useRefetchWidget} to retry after an error
|
|
1272
|
+
*/
|
|
1273
|
+
declare function useWidgetError(): Error | null;
|
|
1274
|
+
|
|
1275
|
+
interface UseWidgetTokenResult {
|
|
1276
|
+
state: WidgetTokenState;
|
|
1277
|
+
refresh: () => Promise<void>;
|
|
1278
|
+
/**
|
|
1279
|
+
* Synchronously read the manager's current state without subscribing the
|
|
1280
|
+
* caller to re-renders. Useful for non-React callbacks that need the
|
|
1281
|
+
* post-`await refresh()` token without the React render lag of `state`.
|
|
1282
|
+
*/
|
|
1283
|
+
getState: () => WidgetTokenState;
|
|
1284
|
+
}
|
|
1285
|
+
declare function useWidgetToken(): UseWidgetTokenResult;
|
|
1286
|
+
|
|
1287
|
+
/**
|
|
1288
|
+
* Public {@link WidgetProvider} — the integrator-facing provider.
|
|
1289
|
+
*
|
|
1290
|
+
* The workspace-internal provider additionally accepts a `widgetName` prop that
|
|
1291
|
+
* stamps analytics identity (`widget_name` + a per-mount `widget_instance_id`)
|
|
1292
|
+
* on everything emitted beneath it (EMBD-4190). That identity is set **only** by
|
|
1293
|
+
* widget feature libs, never by integrators: a spoofed `widget_name` or a forced
|
|
1294
|
+
* fresh `widget_instance_id` would corrupt correlation.
|
|
1295
|
+
*
|
|
1296
|
+
* `WidgetProviderProps` deliberately omits `widgetName`, so typed (TS) consumers
|
|
1297
|
+
* cannot pass it. This wrapper additionally strips any stray `widgetName` a
|
|
1298
|
+
* non-typed (JS) host might pass at runtime before delegating, so the internal
|
|
1299
|
+
* identity prop is unreachable from the published surface in every case — the
|
|
1300
|
+
* provider's declaration in the emitted types carries no `widgetName`.
|
|
1301
|
+
*/
|
|
1302
|
+
declare function WidgetProvider(props: PropsWithChildren<WidgetProviderProps>): ReactNode;
|
|
1303
|
+
|
|
1304
|
+
export { ERROR_STATE_ID, RefreshingRootWidgetProvider, RootWidgetProvider, UIFramework, WidgetProvider, WidgetTokenRefreshProvider, cloneEmbeddedClient, configureCsp, getGlobalWidgetConfig, getGlobalWidgetInitState, registerDesignSystemEnsurer, registerUIRenderers, setGlobalWidgetConfig, subscribeToGlobalWidgetInitState, updateGlobalWidgetConfig, useDisclosuresAcceptanceSurface, useOwnWidgetConfig, useRefetchWidget, useWidgetConfig, useWidgetError, useWidgetInitStaleForToken, useWidgetLoading, useWidgetToken };
|
|
1305
|
+
export type { CspConfig, EmbeddedClient, LinkComponent, LinkComponentProps, RefreshingRootWidgetProviderProps, RootWidgetProviderProps, WidgetConfig, WidgetConfigInput, WidgetInitResponse, WidgetInitState, WidgetProviderLabels, WidgetProviderProps, WidgetTokenFetcher, WidgetTokenManager, WidgetTokenRefreshProviderProps, WidgetTokenState };
|