@parafin/core 3.0.0 → 3.1.1
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/index.ts +37 -4
- package/out/index.d.ts +5 -2
- package/out/index.js +21 -2
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -169,13 +169,29 @@ export const defaultWidgetStyles = {
|
|
|
169
169
|
boxSizing: 'border-box' as const,
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
export type WidgetEvent =
|
|
172
|
+
export type WidgetEvent =
|
|
173
|
+
| 'opted_in'
|
|
174
|
+
| 'opted_out'
|
|
175
|
+
| 'dashboard_opened'
|
|
176
|
+
| 'widget_loaded'
|
|
177
|
+
| 'widget_error'
|
|
178
|
+
|
|
179
|
+
export type WidgetEventMetadata = {
|
|
180
|
+
timeToLoadInMs: number | null
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const emptyMetadata: WidgetEventMetadata = {
|
|
184
|
+
timeToLoadInMs: null,
|
|
185
|
+
}
|
|
173
186
|
|
|
174
187
|
export type WidgetProps = {
|
|
175
188
|
token: string
|
|
176
189
|
product: 'capital' | 'spend_card' | 'cash_account'
|
|
177
190
|
externalBusinessId?: string
|
|
178
|
-
onEvent?: (
|
|
191
|
+
onEvent?: (
|
|
192
|
+
eventType: WidgetEvent,
|
|
193
|
+
metadata: WidgetEventMetadata
|
|
194
|
+
) => Promise<void> | void
|
|
179
195
|
onExit?: () => void
|
|
180
196
|
openInNewTab?: boolean
|
|
181
197
|
onLinkOpened?: (url: string, metadata: LinkOpenedMetadata) => void
|
|
@@ -186,6 +202,8 @@ export const initializeParafinWidget = (
|
|
|
186
202
|
iframe: HTMLIFrameElement,
|
|
187
203
|
props: WidgetProps
|
|
188
204
|
) => {
|
|
205
|
+
let initStartTime = Date.now()
|
|
206
|
+
|
|
189
207
|
// @ts-ignore
|
|
190
208
|
const url = new URL(props.widgetUrlOverride ?? 'https://widget.parafin.com')
|
|
191
209
|
const query = {
|
|
@@ -216,10 +234,14 @@ export const initializeParafinWidget = (
|
|
|
216
234
|
}
|
|
217
235
|
break
|
|
218
236
|
case 'open-dashboard':
|
|
237
|
+
if (props.onEvent) {
|
|
238
|
+
props.onEvent('dashboard_opened', emptyMetadata)
|
|
239
|
+
}
|
|
219
240
|
openParafinDashboard({
|
|
220
241
|
...props,
|
|
221
242
|
route: data?.route,
|
|
222
243
|
onExit: () => {
|
|
244
|
+
initStartTime = Date.now()
|
|
223
245
|
iframe.src = iframeSrc
|
|
224
246
|
props.onExit?.()
|
|
225
247
|
},
|
|
@@ -228,7 +250,7 @@ export const initializeParafinWidget = (
|
|
|
228
250
|
case 'person-opt-in':
|
|
229
251
|
if (props.onEvent) {
|
|
230
252
|
try {
|
|
231
|
-
await props.onEvent('opted_in')
|
|
253
|
+
await props.onEvent('opted_in', emptyMetadata)
|
|
232
254
|
sendMessage({ message: 'person-opt-in', state: 'success' })
|
|
233
255
|
} catch {
|
|
234
256
|
sendMessage({ message: 'person-opt-in', state: 'error' })
|
|
@@ -240,7 +262,7 @@ export const initializeParafinWidget = (
|
|
|
240
262
|
case 'person-opt-out':
|
|
241
263
|
if (props.onEvent) {
|
|
242
264
|
try {
|
|
243
|
-
await props.onEvent('opted_out')
|
|
265
|
+
await props.onEvent('opted_out', emptyMetadata)
|
|
244
266
|
sendMessage({ message: 'person-opt-out', state: 'success' })
|
|
245
267
|
} catch {
|
|
246
268
|
sendMessage({ message: 'person-opt-out', state: 'error' })
|
|
@@ -254,6 +276,17 @@ export const initializeParafinWidget = (
|
|
|
254
276
|
iframe.style.height = data.height
|
|
255
277
|
}
|
|
256
278
|
break
|
|
279
|
+
case 'widget-error':
|
|
280
|
+
if (props.onEvent) {
|
|
281
|
+
props.onEvent('widget_error', emptyMetadata)
|
|
282
|
+
}
|
|
283
|
+
break
|
|
284
|
+
case 'widget-load-complete':
|
|
285
|
+
if (props.onEvent) {
|
|
286
|
+
const timeToLoadInMs = Date.now() - initStartTime
|
|
287
|
+
props.onEvent('widget_loaded', { timeToLoadInMs })
|
|
288
|
+
}
|
|
289
|
+
break
|
|
257
290
|
}
|
|
258
291
|
}
|
|
259
292
|
}
|
package/out/index.d.ts
CHANGED
|
@@ -34,12 +34,15 @@ export declare const defaultWidgetStyles: {
|
|
|
34
34
|
transition: string;
|
|
35
35
|
boxSizing: "border-box";
|
|
36
36
|
};
|
|
37
|
-
export type WidgetEvent = 'opted_in' | 'opted_out';
|
|
37
|
+
export type WidgetEvent = 'opted_in' | 'opted_out' | 'dashboard_opened' | 'widget_loaded' | 'widget_error';
|
|
38
|
+
export type WidgetEventMetadata = {
|
|
39
|
+
timeToLoadInMs: number | null;
|
|
40
|
+
};
|
|
38
41
|
export type WidgetProps = {
|
|
39
42
|
token: string;
|
|
40
43
|
product: 'capital' | 'spend_card' | 'cash_account';
|
|
41
44
|
externalBusinessId?: string;
|
|
42
|
-
onEvent?: (eventType: WidgetEvent) => Promise<void> | void;
|
|
45
|
+
onEvent?: (eventType: WidgetEvent, metadata: WidgetEventMetadata) => Promise<void> | void;
|
|
43
46
|
onExit?: () => void;
|
|
44
47
|
openInNewTab?: boolean;
|
|
45
48
|
onLinkOpened?: (url: string, metadata: LinkOpenedMetadata) => void;
|
package/out/index.js
CHANGED
|
@@ -127,7 +127,11 @@ export const defaultWidgetStyles = {
|
|
|
127
127
|
transition: 'border 0.2s, border-radius 0.2s',
|
|
128
128
|
boxSizing: 'border-box',
|
|
129
129
|
};
|
|
130
|
+
const emptyMetadata = {
|
|
131
|
+
timeToLoadInMs: null,
|
|
132
|
+
};
|
|
130
133
|
export const initializeParafinWidget = (iframe, props) => {
|
|
134
|
+
let initStartTime = Date.now();
|
|
131
135
|
// @ts-ignore
|
|
132
136
|
const url = new URL(props.widgetUrlOverride ?? 'https://widget.parafin.com');
|
|
133
137
|
const query = {
|
|
@@ -155,10 +159,14 @@ export const initializeParafinWidget = (iframe, props) => {
|
|
|
155
159
|
}
|
|
156
160
|
break;
|
|
157
161
|
case 'open-dashboard':
|
|
162
|
+
if (props.onEvent) {
|
|
163
|
+
props.onEvent('dashboard_opened', emptyMetadata);
|
|
164
|
+
}
|
|
158
165
|
openParafinDashboard({
|
|
159
166
|
...props,
|
|
160
167
|
route: data?.route,
|
|
161
168
|
onExit: () => {
|
|
169
|
+
initStartTime = Date.now();
|
|
162
170
|
iframe.src = iframeSrc;
|
|
163
171
|
props.onExit?.();
|
|
164
172
|
},
|
|
@@ -167,7 +175,7 @@ export const initializeParafinWidget = (iframe, props) => {
|
|
|
167
175
|
case 'person-opt-in':
|
|
168
176
|
if (props.onEvent) {
|
|
169
177
|
try {
|
|
170
|
-
await props.onEvent('opted_in');
|
|
178
|
+
await props.onEvent('opted_in', emptyMetadata);
|
|
171
179
|
sendMessage({ message: 'person-opt-in', state: 'success' });
|
|
172
180
|
}
|
|
173
181
|
catch {
|
|
@@ -181,7 +189,7 @@ export const initializeParafinWidget = (iframe, props) => {
|
|
|
181
189
|
case 'person-opt-out':
|
|
182
190
|
if (props.onEvent) {
|
|
183
191
|
try {
|
|
184
|
-
await props.onEvent('opted_out');
|
|
192
|
+
await props.onEvent('opted_out', emptyMetadata);
|
|
185
193
|
sendMessage({ message: 'person-opt-out', state: 'success' });
|
|
186
194
|
}
|
|
187
195
|
catch {
|
|
@@ -197,6 +205,17 @@ export const initializeParafinWidget = (iframe, props) => {
|
|
|
197
205
|
iframe.style.height = data.height;
|
|
198
206
|
}
|
|
199
207
|
break;
|
|
208
|
+
case 'widget-error':
|
|
209
|
+
if (props.onEvent) {
|
|
210
|
+
props.onEvent('widget_error', emptyMetadata);
|
|
211
|
+
}
|
|
212
|
+
break;
|
|
213
|
+
case 'widget-load-complete':
|
|
214
|
+
if (props.onEvent) {
|
|
215
|
+
const timeToLoadInMs = Date.now() - initStartTime;
|
|
216
|
+
props.onEvent('widget_loaded', { timeToLoadInMs });
|
|
217
|
+
}
|
|
218
|
+
break;
|
|
200
219
|
}
|
|
201
220
|
}
|
|
202
221
|
};
|