@bridgewise/embed-sdk-web 0.0.0-stage → 0.1.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +218 -2
- package/dist/index.cjs +508 -0
- package/dist/index.d.cts +326 -0
- package/dist/index.d.ts +326 -0
- package/dist/index.js +474 -0
- package/package.json +51 -4
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
type EmbedErrorReason = "auth_callback_error" | "token_exchange_failed" | "token_refresh_failed";
|
|
2
|
+
declare class EmbedError extends Error {
|
|
3
|
+
readonly reason: EmbedErrorReason;
|
|
4
|
+
readonly cause?: unknown | undefined;
|
|
5
|
+
constructor(reason: EmbedErrorReason, message: string, cause?: unknown | undefined);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
type FrameMessageHandler = (data: unknown, source: Window) => void;
|
|
9
|
+
/**
|
|
10
|
+
* The postMessage link between the host page and its embed iframes. It only
|
|
11
|
+
* accepts messages from child frames on the embed origin, and only ever
|
|
12
|
+
* posts to that origin.
|
|
13
|
+
*/
|
|
14
|
+
declare class FrameChannel {
|
|
15
|
+
readonly origin: string;
|
|
16
|
+
private readonly handlers;
|
|
17
|
+
constructor(origin: string);
|
|
18
|
+
/** Receives every message from an embed. Returns an unsubscribe function. */
|
|
19
|
+
subscribe(handler: FrameMessageHandler): () => void;
|
|
20
|
+
/**
|
|
21
|
+
* Posts a message to every frame on the page. `postMessage`'s
|
|
22
|
+
* `targetOrigin` is enforced by the browser at delivery time, so frames
|
|
23
|
+
* whose actual origin isn't the embed origin simply never receive it —
|
|
24
|
+
* no need to inspect the page to find which frames are embeds.
|
|
25
|
+
*/
|
|
26
|
+
broadcast(message: object): void;
|
|
27
|
+
send(frame: Window, message: object): void;
|
|
28
|
+
destroy(): void;
|
|
29
|
+
private readonly handleMessage;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface TokenResult {
|
|
33
|
+
accessToken: string;
|
|
34
|
+
refreshToken?: string;
|
|
35
|
+
userId?: string;
|
|
36
|
+
tenantId?: string;
|
|
37
|
+
expiresAtEpochSeconds: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface SsoAuthOptions {
|
|
41
|
+
clientId: string;
|
|
42
|
+
apiBaseUrl: string;
|
|
43
|
+
redirectPath?: string;
|
|
44
|
+
autoLogin: boolean;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* SSO module of the embed SDK, reached through `EmbedClient.auth`. Signs the
|
|
48
|
+
* user in through the hosted login page, keeps the access token fresh, and
|
|
49
|
+
* hands it to the embed iframes. Tokens are held in memory only and never
|
|
50
|
+
* persisted to storage.
|
|
51
|
+
*/
|
|
52
|
+
declare class SsoAuth {
|
|
53
|
+
private readonly options;
|
|
54
|
+
private readonly channel;
|
|
55
|
+
private readonly api;
|
|
56
|
+
private tokens;
|
|
57
|
+
private refreshTimer;
|
|
58
|
+
private refreshInFlight;
|
|
59
|
+
private readonly successListeners;
|
|
60
|
+
private readonly refreshListeners;
|
|
61
|
+
private readonly errorListeners;
|
|
62
|
+
/** @internal Created by `EmbedClient`. */
|
|
63
|
+
constructor(options: SsoAuthOptions, channel: FrameChannel);
|
|
64
|
+
/** Fires after `init()` completes a sign-in. Returns an unsubscribe function. */
|
|
65
|
+
onSuccess(listener: (tokens: TokenResult) => void): () => void;
|
|
66
|
+
/** Fires after each successful token refresh. Returns an unsubscribe function. */
|
|
67
|
+
onTokenRefresh(listener: (tokens: TokenResult) => void): () => void;
|
|
68
|
+
/** Fires when sign-in or refresh fails. Returns an unsubscribe function. */
|
|
69
|
+
onError(listener: (error: EmbedError) => void): () => void;
|
|
70
|
+
/**
|
|
71
|
+
* Call once when the app loads. If the URL carries `code`/`state` from the
|
|
72
|
+
* hosted login page, exchanges them for tokens and removes them from the
|
|
73
|
+
* URL. Otherwise, when `autoLogin` is true, redirects to the hosted login
|
|
74
|
+
* page immediately; when false, resolves to null and leaves starting a
|
|
75
|
+
* sign-in up to an explicit `login()` call.
|
|
76
|
+
*/
|
|
77
|
+
init(): Promise<TokenResult | null>;
|
|
78
|
+
/**
|
|
79
|
+
* Redirects the browser to the hosted login page. After sign-in the user
|
|
80
|
+
* returns to `path`, else `redirectPath`, else the current page.
|
|
81
|
+
*/
|
|
82
|
+
login(path?: string): void;
|
|
83
|
+
/** Drops the in-memory session and tells embedded iframes to drop theirs. */
|
|
84
|
+
logout(): void;
|
|
85
|
+
/** Returns a valid access token, refreshing first if expired. Null if there is no session. */
|
|
86
|
+
getAccessToken(): Promise<string | null>;
|
|
87
|
+
/** Whether the SDK currently holds tokens (they don't survive a reload). */
|
|
88
|
+
hasSession(): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Re-sends the current access token to embedded iframes. Embeds normally
|
|
91
|
+
* ask for it themselves when they load, so this is only needed for an
|
|
92
|
+
* embed that doesn't.
|
|
93
|
+
*/
|
|
94
|
+
broadcastToken(): void;
|
|
95
|
+
/** @internal Stops token refresh. Called by `EmbedClient.destroy()`. */
|
|
96
|
+
destroy(): void;
|
|
97
|
+
private setTokens;
|
|
98
|
+
private sendTokenTo;
|
|
99
|
+
/** Concurrent callers share a single in-flight refresh. */
|
|
100
|
+
private refresh;
|
|
101
|
+
private performRefresh;
|
|
102
|
+
/** Refreshes at the moment the access token expires. */
|
|
103
|
+
private scheduleRefresh;
|
|
104
|
+
private clearRefreshTimer;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* SSO messages exchanged with embed iframes. They are plain objects (unlike
|
|
109
|
+
* widget events, which are JSON strings).
|
|
110
|
+
*/
|
|
111
|
+
/** Host → embed: the current access token. */
|
|
112
|
+
declare const SSO_TOKEN_MESSAGE_TYPE: "bridgewise:sso:token";
|
|
113
|
+
/** Embed → host: sent once its listener is attached, asking for the current token. */
|
|
114
|
+
declare const SSO_READY_MESSAGE_TYPE: "bridgewise:sso:ready";
|
|
115
|
+
/** Host → embed: the session ended, drop the token. */
|
|
116
|
+
declare const SSO_LOGOUT_MESSAGE_TYPE: "bridgewise:sso:logout";
|
|
117
|
+
interface SsoTokenMessage {
|
|
118
|
+
type: typeof SSO_TOKEN_MESSAGE_TYPE;
|
|
119
|
+
accessToken: string;
|
|
120
|
+
/** From the `/token` response; absent if it didn't include one. */
|
|
121
|
+
userId?: string;
|
|
122
|
+
/** From the `/token` response; absent if it didn't include one. */
|
|
123
|
+
tenantId?: string;
|
|
124
|
+
expiresAtEpochSeconds: number;
|
|
125
|
+
}
|
|
126
|
+
interface SsoLogoutMessage {
|
|
127
|
+
type: typeof SSO_LOGOUT_MESSAGE_TYPE;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
type EmbedEnvironment = "dev" | "stage" | "prod";
|
|
131
|
+
interface EmbedConfig {
|
|
132
|
+
clientId: string;
|
|
133
|
+
environment: EmbedEnvironment;
|
|
134
|
+
/**
|
|
135
|
+
* App-relative path the hosted login page sends the user back to. Defaults
|
|
136
|
+
* to the page `auth.login()` is called from.
|
|
137
|
+
*/
|
|
138
|
+
redirectPath?: string;
|
|
139
|
+
/**
|
|
140
|
+
* When true, `auth.init()` redirects to the hosted login page immediately
|
|
141
|
+
* if the URL carries no auth callback. When false (the default), `init()`
|
|
142
|
+
* only processes an in-progress callback (or resolves to null otherwise) —
|
|
143
|
+
* the app must call `auth.login()` itself to start a sign-in.
|
|
144
|
+
*/
|
|
145
|
+
autoLogin?: boolean;
|
|
146
|
+
/**
|
|
147
|
+
* When true (the default), the SDK sets each embed iframe's height from
|
|
148
|
+
* the `height` in its `load`, `resize` and `success` events.
|
|
149
|
+
*/
|
|
150
|
+
autoResize?: boolean;
|
|
151
|
+
/**
|
|
152
|
+
* Origin of the embedded widgets, overriding the environment's default
|
|
153
|
+
* (e.g. "http://localhost:3001" when running the widgets locally). Tokens
|
|
154
|
+
* are only ever posted to this origin.
|
|
155
|
+
*/
|
|
156
|
+
embeddedOrigin?: string;
|
|
157
|
+
}
|
|
158
|
+
/** Base URL of the Bridgewise REST API for an environment. */
|
|
159
|
+
declare function getApiBaseUrl(environment: EmbedEnvironment): string;
|
|
160
|
+
/** Default origin the embedded widgets are served from for an environment. */
|
|
161
|
+
declare function getEmbeddedOrigin(environment: EmbedEnvironment): string;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Events posted by embedded Bridgewise widgets to the host page. Widgets send
|
|
165
|
+
* them as JSON strings (unlike the SSO messages, which are plain objects).
|
|
166
|
+
*/
|
|
167
|
+
type AssetType = "fund" | "stock" | "alt" | "bond";
|
|
168
|
+
interface IdentifiersDataType {
|
|
169
|
+
exchange?: string;
|
|
170
|
+
ticker?: string;
|
|
171
|
+
tase?: string;
|
|
172
|
+
isin?: string;
|
|
173
|
+
type: AssetType;
|
|
174
|
+
tradingItemId?: number;
|
|
175
|
+
}
|
|
176
|
+
interface BridgetTeaserPayload {
|
|
177
|
+
companyId: number | null;
|
|
178
|
+
message: string;
|
|
179
|
+
query: string;
|
|
180
|
+
primaryTickerSymbol: string | null;
|
|
181
|
+
}
|
|
182
|
+
interface RestrictedPayload {
|
|
183
|
+
type: AssetType;
|
|
184
|
+
assetName?: string;
|
|
185
|
+
ticker?: string;
|
|
186
|
+
exchange?: string;
|
|
187
|
+
isin?: string;
|
|
188
|
+
tase?: string;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Payload of `click` / `hover` / `trigger` events: the widget's own data with
|
|
192
|
+
* `id` naming the action (e.g. "instrument", "trade_now", "info_action").
|
|
193
|
+
* Some widgets (Reasoning, StatisticalInsights, MarketSignals, altwise) use
|
|
194
|
+
* the widget name as `id` and nest their fields under `data`.
|
|
195
|
+
*/
|
|
196
|
+
type WidgetActionPayload = {
|
|
197
|
+
id: string;
|
|
198
|
+
} & Record<string, unknown>;
|
|
199
|
+
/** `click` from portfolio-positions when the user hits "Trade now" on an optimization suggestion. */
|
|
200
|
+
interface TradeNowPayload {
|
|
201
|
+
id: "trade_now";
|
|
202
|
+
currentAsset: {
|
|
203
|
+
identifier: string;
|
|
204
|
+
tid: number;
|
|
205
|
+
quantity: number;
|
|
206
|
+
assetType: AssetType;
|
|
207
|
+
};
|
|
208
|
+
targetAsset: {
|
|
209
|
+
identifier: string;
|
|
210
|
+
assetType: AssetType;
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
declare function isPositionsTradeNow(data: WidgetActionPayload, widget: string): data is WidgetActionPayload & TradeNowPayload;
|
|
214
|
+
interface WidgetEventPayloads {
|
|
215
|
+
load: {
|
|
216
|
+
height: number;
|
|
217
|
+
width: number;
|
|
218
|
+
};
|
|
219
|
+
resize: {
|
|
220
|
+
height: number | undefined;
|
|
221
|
+
};
|
|
222
|
+
success: {
|
|
223
|
+
height: number | undefined;
|
|
224
|
+
};
|
|
225
|
+
error: {
|
|
226
|
+
message: string;
|
|
227
|
+
status: number;
|
|
228
|
+
height: number;
|
|
229
|
+
};
|
|
230
|
+
"security-select": {
|
|
231
|
+
id: string;
|
|
232
|
+
} & Partial<IdentifiersDataType>;
|
|
233
|
+
"bridget-teaser-trigger": BridgetTeaserPayload;
|
|
234
|
+
navigate: {
|
|
235
|
+
href: string;
|
|
236
|
+
meta?: {
|
|
237
|
+
source: "security";
|
|
238
|
+
identifier: unknown;
|
|
239
|
+
} | {
|
|
240
|
+
source: "bridget-answer";
|
|
241
|
+
};
|
|
242
|
+
};
|
|
243
|
+
"trading-item-id-change": {
|
|
244
|
+
tradingItemId?: number;
|
|
245
|
+
};
|
|
246
|
+
"restricted-trigger": RestrictedPayload;
|
|
247
|
+
click: WidgetActionPayload;
|
|
248
|
+
hover: WidgetActionPayload;
|
|
249
|
+
trigger: WidgetActionPayload;
|
|
250
|
+
}
|
|
251
|
+
type WidgetEventType = keyof WidgetEventPayloads;
|
|
252
|
+
interface BridgewiseMessage<T extends WidgetEventType = WidgetEventType> {
|
|
253
|
+
/** Legacy name: `on-<type>-<widgetName>`. */
|
|
254
|
+
event: string;
|
|
255
|
+
type: T;
|
|
256
|
+
/** widgetName from the iframe URL. */
|
|
257
|
+
widget: string;
|
|
258
|
+
data: WidgetEventPayloads[T];
|
|
259
|
+
}
|
|
260
|
+
interface WidgetEventContext {
|
|
261
|
+
widget: string;
|
|
262
|
+
event: string;
|
|
263
|
+
/** The iframe window that sent the event. */
|
|
264
|
+
source: Window;
|
|
265
|
+
}
|
|
266
|
+
/** Maps each event type to the name of its callback in `WidgetCallbacks`. */
|
|
267
|
+
declare const WIDGET_CALLBACK_NAMES: {
|
|
268
|
+
readonly load: "onLoad";
|
|
269
|
+
readonly resize: "onResize";
|
|
270
|
+
readonly success: "onSuccess";
|
|
271
|
+
readonly error: "onError";
|
|
272
|
+
readonly "security-select": "onSecuritySelect";
|
|
273
|
+
readonly "bridget-teaser-trigger": "onBridgetTeaserTrigger";
|
|
274
|
+
readonly navigate: "onNavigate";
|
|
275
|
+
readonly "trading-item-id-change": "onTradingItemIdChange";
|
|
276
|
+
readonly "restricted-trigger": "onRestrictedTrigger";
|
|
277
|
+
readonly click: "onClick";
|
|
278
|
+
readonly hover: "onHover";
|
|
279
|
+
readonly trigger: "onTrigger";
|
|
280
|
+
};
|
|
281
|
+
type WidgetCallback<T extends WidgetEventType> = (data: WidgetEventPayloads[T], context: WidgetEventContext) => void;
|
|
282
|
+
/** One optional callback per event type: `onLoad`, `onResize`, `onClick`, ... */
|
|
283
|
+
type WidgetCallbacks = {
|
|
284
|
+
[T in WidgetEventType as (typeof WIDGET_CALLBACK_NAMES)[T]]?: WidgetCallback<T>;
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
interface WidgetEventsOptions {
|
|
288
|
+
autoResize: boolean;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Widget events module of the embed SDK, reached through
|
|
292
|
+
* `EmbedClient.widgets`. Delivers the events embedded widgets post to the
|
|
293
|
+
* host page, and keeps each iframe as tall as its content.
|
|
294
|
+
*/
|
|
295
|
+
declare class WidgetEvents {
|
|
296
|
+
private readonly options;
|
|
297
|
+
private readonly subscriptions;
|
|
298
|
+
/** @internal Created by `EmbedClient`. */
|
|
299
|
+
constructor(options: WidgetEventsOptions, channel: FrameChannel);
|
|
300
|
+
/**
|
|
301
|
+
* Registers callbacks for events posted by embedded widgets (onLoad,
|
|
302
|
+
* onResize, onClick, ...). Returns an unsubscribe function.
|
|
303
|
+
*/
|
|
304
|
+
on(callbacks: WidgetCallbacks): () => void;
|
|
305
|
+
private handle;
|
|
306
|
+
private emit;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Public entry point for the embed SDK: everything a host page needs to run
|
|
311
|
+
* Bridgewise embeds. Each feature lives on its own module.
|
|
312
|
+
*/
|
|
313
|
+
declare class EmbedClient {
|
|
314
|
+
/** SSO sign-in, token refresh, and handing the token to embeds. */
|
|
315
|
+
readonly auth: SsoAuth;
|
|
316
|
+
/** Events posted by embedded widgets, and iframe auto-resize. */
|
|
317
|
+
readonly widgets: WidgetEvents;
|
|
318
|
+
/** The origin embeds are served from — use it to build iframe URLs. */
|
|
319
|
+
readonly embeddedOrigin: string;
|
|
320
|
+
private readonly channel;
|
|
321
|
+
constructor(config: EmbedConfig);
|
|
322
|
+
/** Stops listening to embeds and stops token refresh. */
|
|
323
|
+
destroy(): void;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export { type AssetType, type BridgetTeaserPayload, type BridgewiseMessage, EmbedClient, type EmbedConfig, type EmbedEnvironment, EmbedError, type EmbedErrorReason, type IdentifiersDataType, type RestrictedPayload, SSO_LOGOUT_MESSAGE_TYPE, SSO_READY_MESSAGE_TYPE, SSO_TOKEN_MESSAGE_TYPE, SsoAuth, type SsoLogoutMessage, type SsoTokenMessage, type TokenResult, type TradeNowPayload, type WidgetActionPayload, type WidgetCallback, type WidgetCallbacks, type WidgetEventContext, type WidgetEventPayloads, type WidgetEventType, WidgetEvents, getApiBaseUrl, getEmbeddedOrigin, isPositionsTradeNow };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
type EmbedErrorReason = "auth_callback_error" | "token_exchange_failed" | "token_refresh_failed";
|
|
2
|
+
declare class EmbedError extends Error {
|
|
3
|
+
readonly reason: EmbedErrorReason;
|
|
4
|
+
readonly cause?: unknown | undefined;
|
|
5
|
+
constructor(reason: EmbedErrorReason, message: string, cause?: unknown | undefined);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
type FrameMessageHandler = (data: unknown, source: Window) => void;
|
|
9
|
+
/**
|
|
10
|
+
* The postMessage link between the host page and its embed iframes. It only
|
|
11
|
+
* accepts messages from child frames on the embed origin, and only ever
|
|
12
|
+
* posts to that origin.
|
|
13
|
+
*/
|
|
14
|
+
declare class FrameChannel {
|
|
15
|
+
readonly origin: string;
|
|
16
|
+
private readonly handlers;
|
|
17
|
+
constructor(origin: string);
|
|
18
|
+
/** Receives every message from an embed. Returns an unsubscribe function. */
|
|
19
|
+
subscribe(handler: FrameMessageHandler): () => void;
|
|
20
|
+
/**
|
|
21
|
+
* Posts a message to every frame on the page. `postMessage`'s
|
|
22
|
+
* `targetOrigin` is enforced by the browser at delivery time, so frames
|
|
23
|
+
* whose actual origin isn't the embed origin simply never receive it —
|
|
24
|
+
* no need to inspect the page to find which frames are embeds.
|
|
25
|
+
*/
|
|
26
|
+
broadcast(message: object): void;
|
|
27
|
+
send(frame: Window, message: object): void;
|
|
28
|
+
destroy(): void;
|
|
29
|
+
private readonly handleMessage;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface TokenResult {
|
|
33
|
+
accessToken: string;
|
|
34
|
+
refreshToken?: string;
|
|
35
|
+
userId?: string;
|
|
36
|
+
tenantId?: string;
|
|
37
|
+
expiresAtEpochSeconds: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface SsoAuthOptions {
|
|
41
|
+
clientId: string;
|
|
42
|
+
apiBaseUrl: string;
|
|
43
|
+
redirectPath?: string;
|
|
44
|
+
autoLogin: boolean;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* SSO module of the embed SDK, reached through `EmbedClient.auth`. Signs the
|
|
48
|
+
* user in through the hosted login page, keeps the access token fresh, and
|
|
49
|
+
* hands it to the embed iframes. Tokens are held in memory only and never
|
|
50
|
+
* persisted to storage.
|
|
51
|
+
*/
|
|
52
|
+
declare class SsoAuth {
|
|
53
|
+
private readonly options;
|
|
54
|
+
private readonly channel;
|
|
55
|
+
private readonly api;
|
|
56
|
+
private tokens;
|
|
57
|
+
private refreshTimer;
|
|
58
|
+
private refreshInFlight;
|
|
59
|
+
private readonly successListeners;
|
|
60
|
+
private readonly refreshListeners;
|
|
61
|
+
private readonly errorListeners;
|
|
62
|
+
/** @internal Created by `EmbedClient`. */
|
|
63
|
+
constructor(options: SsoAuthOptions, channel: FrameChannel);
|
|
64
|
+
/** Fires after `init()` completes a sign-in. Returns an unsubscribe function. */
|
|
65
|
+
onSuccess(listener: (tokens: TokenResult) => void): () => void;
|
|
66
|
+
/** Fires after each successful token refresh. Returns an unsubscribe function. */
|
|
67
|
+
onTokenRefresh(listener: (tokens: TokenResult) => void): () => void;
|
|
68
|
+
/** Fires when sign-in or refresh fails. Returns an unsubscribe function. */
|
|
69
|
+
onError(listener: (error: EmbedError) => void): () => void;
|
|
70
|
+
/**
|
|
71
|
+
* Call once when the app loads. If the URL carries `code`/`state` from the
|
|
72
|
+
* hosted login page, exchanges them for tokens and removes them from the
|
|
73
|
+
* URL. Otherwise, when `autoLogin` is true, redirects to the hosted login
|
|
74
|
+
* page immediately; when false, resolves to null and leaves starting a
|
|
75
|
+
* sign-in up to an explicit `login()` call.
|
|
76
|
+
*/
|
|
77
|
+
init(): Promise<TokenResult | null>;
|
|
78
|
+
/**
|
|
79
|
+
* Redirects the browser to the hosted login page. After sign-in the user
|
|
80
|
+
* returns to `path`, else `redirectPath`, else the current page.
|
|
81
|
+
*/
|
|
82
|
+
login(path?: string): void;
|
|
83
|
+
/** Drops the in-memory session and tells embedded iframes to drop theirs. */
|
|
84
|
+
logout(): void;
|
|
85
|
+
/** Returns a valid access token, refreshing first if expired. Null if there is no session. */
|
|
86
|
+
getAccessToken(): Promise<string | null>;
|
|
87
|
+
/** Whether the SDK currently holds tokens (they don't survive a reload). */
|
|
88
|
+
hasSession(): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Re-sends the current access token to embedded iframes. Embeds normally
|
|
91
|
+
* ask for it themselves when they load, so this is only needed for an
|
|
92
|
+
* embed that doesn't.
|
|
93
|
+
*/
|
|
94
|
+
broadcastToken(): void;
|
|
95
|
+
/** @internal Stops token refresh. Called by `EmbedClient.destroy()`. */
|
|
96
|
+
destroy(): void;
|
|
97
|
+
private setTokens;
|
|
98
|
+
private sendTokenTo;
|
|
99
|
+
/** Concurrent callers share a single in-flight refresh. */
|
|
100
|
+
private refresh;
|
|
101
|
+
private performRefresh;
|
|
102
|
+
/** Refreshes at the moment the access token expires. */
|
|
103
|
+
private scheduleRefresh;
|
|
104
|
+
private clearRefreshTimer;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* SSO messages exchanged with embed iframes. They are plain objects (unlike
|
|
109
|
+
* widget events, which are JSON strings).
|
|
110
|
+
*/
|
|
111
|
+
/** Host → embed: the current access token. */
|
|
112
|
+
declare const SSO_TOKEN_MESSAGE_TYPE: "bridgewise:sso:token";
|
|
113
|
+
/** Embed → host: sent once its listener is attached, asking for the current token. */
|
|
114
|
+
declare const SSO_READY_MESSAGE_TYPE: "bridgewise:sso:ready";
|
|
115
|
+
/** Host → embed: the session ended, drop the token. */
|
|
116
|
+
declare const SSO_LOGOUT_MESSAGE_TYPE: "bridgewise:sso:logout";
|
|
117
|
+
interface SsoTokenMessage {
|
|
118
|
+
type: typeof SSO_TOKEN_MESSAGE_TYPE;
|
|
119
|
+
accessToken: string;
|
|
120
|
+
/** From the `/token` response; absent if it didn't include one. */
|
|
121
|
+
userId?: string;
|
|
122
|
+
/** From the `/token` response; absent if it didn't include one. */
|
|
123
|
+
tenantId?: string;
|
|
124
|
+
expiresAtEpochSeconds: number;
|
|
125
|
+
}
|
|
126
|
+
interface SsoLogoutMessage {
|
|
127
|
+
type: typeof SSO_LOGOUT_MESSAGE_TYPE;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
type EmbedEnvironment = "dev" | "stage" | "prod";
|
|
131
|
+
interface EmbedConfig {
|
|
132
|
+
clientId: string;
|
|
133
|
+
environment: EmbedEnvironment;
|
|
134
|
+
/**
|
|
135
|
+
* App-relative path the hosted login page sends the user back to. Defaults
|
|
136
|
+
* to the page `auth.login()` is called from.
|
|
137
|
+
*/
|
|
138
|
+
redirectPath?: string;
|
|
139
|
+
/**
|
|
140
|
+
* When true, `auth.init()` redirects to the hosted login page immediately
|
|
141
|
+
* if the URL carries no auth callback. When false (the default), `init()`
|
|
142
|
+
* only processes an in-progress callback (or resolves to null otherwise) —
|
|
143
|
+
* the app must call `auth.login()` itself to start a sign-in.
|
|
144
|
+
*/
|
|
145
|
+
autoLogin?: boolean;
|
|
146
|
+
/**
|
|
147
|
+
* When true (the default), the SDK sets each embed iframe's height from
|
|
148
|
+
* the `height` in its `load`, `resize` and `success` events.
|
|
149
|
+
*/
|
|
150
|
+
autoResize?: boolean;
|
|
151
|
+
/**
|
|
152
|
+
* Origin of the embedded widgets, overriding the environment's default
|
|
153
|
+
* (e.g. "http://localhost:3001" when running the widgets locally). Tokens
|
|
154
|
+
* are only ever posted to this origin.
|
|
155
|
+
*/
|
|
156
|
+
embeddedOrigin?: string;
|
|
157
|
+
}
|
|
158
|
+
/** Base URL of the Bridgewise REST API for an environment. */
|
|
159
|
+
declare function getApiBaseUrl(environment: EmbedEnvironment): string;
|
|
160
|
+
/** Default origin the embedded widgets are served from for an environment. */
|
|
161
|
+
declare function getEmbeddedOrigin(environment: EmbedEnvironment): string;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Events posted by embedded Bridgewise widgets to the host page. Widgets send
|
|
165
|
+
* them as JSON strings (unlike the SSO messages, which are plain objects).
|
|
166
|
+
*/
|
|
167
|
+
type AssetType = "fund" | "stock" | "alt" | "bond";
|
|
168
|
+
interface IdentifiersDataType {
|
|
169
|
+
exchange?: string;
|
|
170
|
+
ticker?: string;
|
|
171
|
+
tase?: string;
|
|
172
|
+
isin?: string;
|
|
173
|
+
type: AssetType;
|
|
174
|
+
tradingItemId?: number;
|
|
175
|
+
}
|
|
176
|
+
interface BridgetTeaserPayload {
|
|
177
|
+
companyId: number | null;
|
|
178
|
+
message: string;
|
|
179
|
+
query: string;
|
|
180
|
+
primaryTickerSymbol: string | null;
|
|
181
|
+
}
|
|
182
|
+
interface RestrictedPayload {
|
|
183
|
+
type: AssetType;
|
|
184
|
+
assetName?: string;
|
|
185
|
+
ticker?: string;
|
|
186
|
+
exchange?: string;
|
|
187
|
+
isin?: string;
|
|
188
|
+
tase?: string;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Payload of `click` / `hover` / `trigger` events: the widget's own data with
|
|
192
|
+
* `id` naming the action (e.g. "instrument", "trade_now", "info_action").
|
|
193
|
+
* Some widgets (Reasoning, StatisticalInsights, MarketSignals, altwise) use
|
|
194
|
+
* the widget name as `id` and nest their fields under `data`.
|
|
195
|
+
*/
|
|
196
|
+
type WidgetActionPayload = {
|
|
197
|
+
id: string;
|
|
198
|
+
} & Record<string, unknown>;
|
|
199
|
+
/** `click` from portfolio-positions when the user hits "Trade now" on an optimization suggestion. */
|
|
200
|
+
interface TradeNowPayload {
|
|
201
|
+
id: "trade_now";
|
|
202
|
+
currentAsset: {
|
|
203
|
+
identifier: string;
|
|
204
|
+
tid: number;
|
|
205
|
+
quantity: number;
|
|
206
|
+
assetType: AssetType;
|
|
207
|
+
};
|
|
208
|
+
targetAsset: {
|
|
209
|
+
identifier: string;
|
|
210
|
+
assetType: AssetType;
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
declare function isPositionsTradeNow(data: WidgetActionPayload, widget: string): data is WidgetActionPayload & TradeNowPayload;
|
|
214
|
+
interface WidgetEventPayloads {
|
|
215
|
+
load: {
|
|
216
|
+
height: number;
|
|
217
|
+
width: number;
|
|
218
|
+
};
|
|
219
|
+
resize: {
|
|
220
|
+
height: number | undefined;
|
|
221
|
+
};
|
|
222
|
+
success: {
|
|
223
|
+
height: number | undefined;
|
|
224
|
+
};
|
|
225
|
+
error: {
|
|
226
|
+
message: string;
|
|
227
|
+
status: number;
|
|
228
|
+
height: number;
|
|
229
|
+
};
|
|
230
|
+
"security-select": {
|
|
231
|
+
id: string;
|
|
232
|
+
} & Partial<IdentifiersDataType>;
|
|
233
|
+
"bridget-teaser-trigger": BridgetTeaserPayload;
|
|
234
|
+
navigate: {
|
|
235
|
+
href: string;
|
|
236
|
+
meta?: {
|
|
237
|
+
source: "security";
|
|
238
|
+
identifier: unknown;
|
|
239
|
+
} | {
|
|
240
|
+
source: "bridget-answer";
|
|
241
|
+
};
|
|
242
|
+
};
|
|
243
|
+
"trading-item-id-change": {
|
|
244
|
+
tradingItemId?: number;
|
|
245
|
+
};
|
|
246
|
+
"restricted-trigger": RestrictedPayload;
|
|
247
|
+
click: WidgetActionPayload;
|
|
248
|
+
hover: WidgetActionPayload;
|
|
249
|
+
trigger: WidgetActionPayload;
|
|
250
|
+
}
|
|
251
|
+
type WidgetEventType = keyof WidgetEventPayloads;
|
|
252
|
+
interface BridgewiseMessage<T extends WidgetEventType = WidgetEventType> {
|
|
253
|
+
/** Legacy name: `on-<type>-<widgetName>`. */
|
|
254
|
+
event: string;
|
|
255
|
+
type: T;
|
|
256
|
+
/** widgetName from the iframe URL. */
|
|
257
|
+
widget: string;
|
|
258
|
+
data: WidgetEventPayloads[T];
|
|
259
|
+
}
|
|
260
|
+
interface WidgetEventContext {
|
|
261
|
+
widget: string;
|
|
262
|
+
event: string;
|
|
263
|
+
/** The iframe window that sent the event. */
|
|
264
|
+
source: Window;
|
|
265
|
+
}
|
|
266
|
+
/** Maps each event type to the name of its callback in `WidgetCallbacks`. */
|
|
267
|
+
declare const WIDGET_CALLBACK_NAMES: {
|
|
268
|
+
readonly load: "onLoad";
|
|
269
|
+
readonly resize: "onResize";
|
|
270
|
+
readonly success: "onSuccess";
|
|
271
|
+
readonly error: "onError";
|
|
272
|
+
readonly "security-select": "onSecuritySelect";
|
|
273
|
+
readonly "bridget-teaser-trigger": "onBridgetTeaserTrigger";
|
|
274
|
+
readonly navigate: "onNavigate";
|
|
275
|
+
readonly "trading-item-id-change": "onTradingItemIdChange";
|
|
276
|
+
readonly "restricted-trigger": "onRestrictedTrigger";
|
|
277
|
+
readonly click: "onClick";
|
|
278
|
+
readonly hover: "onHover";
|
|
279
|
+
readonly trigger: "onTrigger";
|
|
280
|
+
};
|
|
281
|
+
type WidgetCallback<T extends WidgetEventType> = (data: WidgetEventPayloads[T], context: WidgetEventContext) => void;
|
|
282
|
+
/** One optional callback per event type: `onLoad`, `onResize`, `onClick`, ... */
|
|
283
|
+
type WidgetCallbacks = {
|
|
284
|
+
[T in WidgetEventType as (typeof WIDGET_CALLBACK_NAMES)[T]]?: WidgetCallback<T>;
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
interface WidgetEventsOptions {
|
|
288
|
+
autoResize: boolean;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Widget events module of the embed SDK, reached through
|
|
292
|
+
* `EmbedClient.widgets`. Delivers the events embedded widgets post to the
|
|
293
|
+
* host page, and keeps each iframe as tall as its content.
|
|
294
|
+
*/
|
|
295
|
+
declare class WidgetEvents {
|
|
296
|
+
private readonly options;
|
|
297
|
+
private readonly subscriptions;
|
|
298
|
+
/** @internal Created by `EmbedClient`. */
|
|
299
|
+
constructor(options: WidgetEventsOptions, channel: FrameChannel);
|
|
300
|
+
/**
|
|
301
|
+
* Registers callbacks for events posted by embedded widgets (onLoad,
|
|
302
|
+
* onResize, onClick, ...). Returns an unsubscribe function.
|
|
303
|
+
*/
|
|
304
|
+
on(callbacks: WidgetCallbacks): () => void;
|
|
305
|
+
private handle;
|
|
306
|
+
private emit;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Public entry point for the embed SDK: everything a host page needs to run
|
|
311
|
+
* Bridgewise embeds. Each feature lives on its own module.
|
|
312
|
+
*/
|
|
313
|
+
declare class EmbedClient {
|
|
314
|
+
/** SSO sign-in, token refresh, and handing the token to embeds. */
|
|
315
|
+
readonly auth: SsoAuth;
|
|
316
|
+
/** Events posted by embedded widgets, and iframe auto-resize. */
|
|
317
|
+
readonly widgets: WidgetEvents;
|
|
318
|
+
/** The origin embeds are served from — use it to build iframe URLs. */
|
|
319
|
+
readonly embeddedOrigin: string;
|
|
320
|
+
private readonly channel;
|
|
321
|
+
constructor(config: EmbedConfig);
|
|
322
|
+
/** Stops listening to embeds and stops token refresh. */
|
|
323
|
+
destroy(): void;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export { type AssetType, type BridgetTeaserPayload, type BridgewiseMessage, EmbedClient, type EmbedConfig, type EmbedEnvironment, EmbedError, type EmbedErrorReason, type IdentifiersDataType, type RestrictedPayload, SSO_LOGOUT_MESSAGE_TYPE, SSO_READY_MESSAGE_TYPE, SSO_TOKEN_MESSAGE_TYPE, SsoAuth, type SsoLogoutMessage, type SsoTokenMessage, type TokenResult, type TradeNowPayload, type WidgetActionPayload, type WidgetCallback, type WidgetCallbacks, type WidgetEventContext, type WidgetEventPayloads, type WidgetEventType, WidgetEvents, getApiBaseUrl, getEmbeddedOrigin, isPositionsTradeNow };
|