@worthai/onboarding-sdk 2.0.17 โ†’ 3.0.0-beta.2.12.7

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.
Files changed (47) hide show
  1. package/README.md +109 -220
  2. package/dist-sdk/sdk3/createWorthOnboarding.d.ts +2 -0
  3. package/dist-sdk/sdk3/errors.d.ts +24 -0
  4. package/dist-sdk/sdk3/index-Cf08HIBl.js +3341 -0
  5. package/dist-sdk/sdk3/index.d.ts +3 -0
  6. package/dist-sdk/sdk3/index.js +6 -0
  7. package/dist-sdk/sdk3/runtimeAdapter-COcjQ078.js +36532 -0
  8. package/dist-sdk/sdk3/runtimeAdapter.d.ts +7 -0
  9. package/dist-sdk/sdk3/runtimeAdapterHydration.d.ts +8 -0
  10. package/dist-sdk/sdk3/styleManager.d.ts +1 -0
  11. package/dist-sdk/sdk3/worthOnboarding.d.ts +27 -0
  12. package/dist-sdk/sdk3/worthOnboarding.types.d.ts +315 -0
  13. package/dist-sdk/sdk3/worthai-onboarding-sdk.global.js +6101 -0
  14. package/package.json +81 -38
  15. package/dist/index.d.ts +0 -2
  16. package/dist/index.js +0 -279
  17. package/dist/index.js.map +0 -1
  18. package/dist/interfaces/AnyMessage.d.ts +0 -4
  19. package/dist/interfaces/ChildSite.d.ts +0 -2
  20. package/dist/interfaces/ChildSiteMessage.d.ts +0 -8
  21. package/dist/interfaces/ChildSiteSubscription.d.ts +0 -2
  22. package/dist/interfaces/DetachedEvent.d.ts +0 -73
  23. package/dist/interfaces/IframeMode.d.ts +0 -1
  24. package/dist/interfaces/IframeQueryParams.d.ts +0 -1
  25. package/dist/interfaces/OnboardingApp.d.ts +0 -2
  26. package/dist/interfaces/OnboardingAppAppSubscription.d.ts +0 -2
  27. package/dist/interfaces/OnboardingAppMessage.d.ts +0 -41
  28. package/dist/interfaces/OnboardingAppMode.d.ts +0 -2
  29. package/dist/interfaces/OnboardingAppSubscription.d.ts +0 -2
  30. package/dist/interfaces/OnboardingConsumerApp.d.ts +0 -2
  31. package/dist/interfaces/OnboardingConsumerAppMessage.d.ts +0 -17
  32. package/dist/interfaces/ParentSite.d.ts +0 -2
  33. package/dist/interfaces/ParentSiteMessage.d.ts +0 -26
  34. package/dist/interfaces/ParentSiteSubscription.d.ts +0 -2
  35. package/dist/interfaces/QueryParams.d.ts +0 -1
  36. package/dist/interfaces/StageNavigation.d.ts +0 -21
  37. package/dist/interfaces/index.d.ts +0 -19
  38. package/dist/mockServiceWorker.js +0 -349
  39. package/dist/mocks/browser.d.ts +0 -1
  40. package/dist/mocks/handlers/authHandler.d.ts +0 -1
  41. package/dist/mocks/handlers/index.d.ts +0 -1
  42. package/dist/utils/createChildSite/index.d.ts +0 -23
  43. package/dist/utils/createOnboardingApp/index.d.ts +0 -20
  44. package/dist/utils/createOnboardingConsumerApp/index.d.ts +0 -9
  45. package/dist/utils/createParentSite/index.d.ts +0 -10
  46. package/dist/utils/getURLQueryParams/index.d.ts +0 -2
  47. package/dist/utils/index.d.ts +0 -4
package/README.md CHANGED
@@ -1,276 +1,165 @@
1
- # @worthai/onboarding-sdk
1
+ # Worth Onboarding SDK
2
2
 
3
- A TypeScript SDK for seamless cross-origin communication between parent and child sites using iframe postMessage API. This SDK provides type-safe utilities for building onboarding flows with secure message passing between applications.
3
+ The Worth Onboarding SDK embeds onboarding experiences directly into your website's DOM.
4
+ Rather than managing an iframe separately, you provide a mount point and lifecycle callbacks,
5
+ and the SDK handles rendering, execution, and teardown.
4
6
 
5
- ## ๐Ÿ“ฆ Installation
7
+ SDK 3 delivers improved performance, greater configurability, and seamless host application
8
+ integration compared to its predecessor (SDK 2).
6
9
 
7
- ### Within the monorepo
10
+ > "Instead of managing an iframe, you give the SDK a mount point and a set of lifecycle callbacks."
8
11
 
9
- ```bash
10
- # Add as workspace dependency
11
- pnpm add @worthai/onboarding-sdk@workspace:*
12
- ```
13
-
14
- ### External projects
15
-
16
- ```bash
17
- # Using npm
18
- npm install @worthai/onboarding-sdk
19
-
20
- # Using pnpm
21
- pnpm install @worthai/onboarding-sdk
22
- ```
12
+ ## Key Benefits
23
13
 
24
- ## ๐Ÿ› ๏ธ API Reference
25
-
26
- ### Onboarding-Specific Utilities
27
-
28
- #### `createOnboardingApp(args)`
29
-
30
- Creates an onboarding app instance for parent-to-child communication with type-safe onboarding messages.
31
-
32
- > **Note**: The following example is illustrative code for vanilla TypeScript. Adapt to your framework's patterns when using React or other JavaScript frameworks.
33
-
34
- ```typescript
35
- import { createOnboardingApp } from '@worthai/onboarding-sdk';
36
-
37
- // Create an onboarding app instance and communicate with it
38
- const onboardingApp = createOnboardingApp({
39
- origin: 'https://onboarding-app.com',
40
- inviteToken: 'YOUR_INVITE_TOKEN',
41
- mode: 'embedded',
42
- });
14
+ - **Faster integration**: Minimize custom development and deploy Worth's onboarding quickly
15
+ - **Branded experience**: Preserve your brand while leveraging Worth's core capabilities
16
+ - **Flexible embedding**: Mount the flow into any DOM element you control
17
+ - **Type-safe communication**: Built-in TypeScript support with type-safe messaging
43
18
 
44
- // Listen for onboarding messages
45
- const subscription = onboardingApp.subscribe((event) => {
46
- if (event.data.type === 'ROUTE_URL') {
47
- console.log('Current route:', event.data.payload.url);
48
- }
49
- });
19
+ ## Scope
50
20
 
51
- // โš ๏ธ Important: Remember to unsubscribe when component unmounts or cleanup is needed
52
- // subscription.unsubscribe();
21
+ **In scope**: Applicant onboarding embedded in host DOM, JavaScript/TypeScript web SDK,
22
+ modern browser support (last 2 versions of Chrome, Firefox, Safari, Edge), client-side
23
+ rendering.
53
24
 
54
- // Append the onboarding app iframe
55
- document
56
- .getElementById('onboarding-container')
57
- .appendChild(onboardingApp.iframe);
25
+ **Out of scope**: Non-onboarding products, mobile native SDKs, server-side rendering,
26
+ offline functionality, legacy browser support.
58
27
 
59
- // Adding event listeners to Prev and Next buttons (for vanilla JS)
28
+ ## Installation
60
29
 
61
- const prevButton = document.getElementById('onboarding-prev');
62
- const nextButton = document.getElementById('onboarding-next');
30
+ ```bash
31
+ npm install @worthai/onboarding-sdk
32
+ ```
63
33
 
64
- // Next stage navigation command
65
- prevButton && prevButton.addEventListener('click', () => onboardingApp.prev());
34
+ ## Quick Start
66
35
 
67
- // Prev stage navigation command
68
- nextButton && nextButton.addEventListener('click', () => onboardingApp.next());
36
+ ### 1. Add a mount target to your page
69
37
 
70
- // In your HTML:
71
- // <div id="onboarding-container"></div>
72
- // <button id="onboarding-prev">Back</button>
73
- // <button id="onboarding-next">Next</button>
38
+ ```html
39
+ <div id="worth-onboarding"></div>
74
40
  ```
75
41
 
76
- #### `createOnboardingConsumerApp(args)`
42
+ ### 2. Create an instance
77
43
 
78
- Creates an onboarding consumer app instance for child-to-parent communication with type-safe onboarding messages.
44
+ Initialize with your invite token and lifecycle callbacks:
79
45
 
80
- > **Note**: The following example is illustrative code for vanilla TypeScript. Adapt to your framework's patterns when using React or other JavaScript frameworks.
46
+ - `onStepSubmit` โ€” fires when applicants submit each step
47
+ - `onComplete` โ€” fires upon finishing the flow
48
+ - `onError` โ€” handles SDK or runtime errors
81
49
 
82
50
  ```typescript
83
- import { createOnboardingConsumerApp } from '@worthai/onboarding-sdk';
51
+ import { createWorthOnboarding } from '@worthai/onboarding-sdk';
84
52
 
85
- // Create an onboarding consumer app instance for child-to-parent communication
86
- const consumerApp = createOnboardingConsumerApp();
87
-
88
- // Send onboarding messages to parent
89
- consumerApp.postMessage({
90
- type: "ROUTE_URL";
91
- payload: {
92
- url: '/getting-started';
93
- };
94
- });
95
-
96
- // Listen for messages from parent
97
- const subscription = consumerApp.subscribe((event) => {
98
- if (event.data.type === 'NEXT_STAGE') {
99
- // Navigate to next stage
100
- }
53
+ const onboarding = createWorthOnboarding({
54
+ inviteToken: '{{YOUR_INVITE_TOKEN}}',
55
+ onStepSubmit: ({ stepId, values }) => {
56
+ console.log('Step submitted:', stepId, values);
57
+ },
58
+ onComplete: ({ values }) => {
59
+ console.log('Onboarding completed:', values);
60
+ },
61
+ onError: (error) => {
62
+ console.error('Onboarding error:', error);
63
+ },
101
64
  });
102
-
103
- // โš ๏ธ Important: Remember to unsubscribe when component unmounts or cleanup is needed
104
- // subscription.unsubscribe();
105
65
  ```
106
66
 
107
- ## ๐Ÿ“‹ Message Types
108
-
109
- ### OnboardingAppMessage Events (Child โ†’ Parent)
110
-
111
- | Event Type | Description |
112
- | -------------------- | ---------------------------------------------------------------------- |
113
- | `ROUTE_URL` | Notifies parent site of current route changes in onboarding app |
114
- | `IFRAME_RESIZE` | Notifies parent site when the iframe needs to resize (includes height) |
115
- | `IFRAME_INITIALIZED` | Notifies parent site when the iframe has finished initializing |
116
-
117
- ### OnboardingConsumerAppMessage Events (Parent โ†’ Child)
118
-
119
- | Event Type | Description |
120
- | -------------------------------- | ------------------------------------------------------------------------------ |
121
- | `NEXT_STAGE` | Navigates the onboarding app to the next stage |
122
- | `PREV_STAGE` | Navigates the onboarding app to the previous stage |
123
- | `SKIP_STAGE` | Skips the current stage in the onboarding app |
124
- | `INVITE_TOKEN_SENT` | Notifies child site that an invite token has been sent (includes token) |
125
- | `IFRAME_RENDERED_ON_PARENT_SITE` | Notifies child site that the iframe has been rendered on the parent site |
126
- | `REFRESH_SIZE` | Requests the child site to refresh its size |
127
- | `IFRAME_INITIALIZED` | Notifies child site that the iframe has been initialized (includes mode) |
128
- | `SET_CUSTOM_CSS` | Sets custom CSS styles for the iframe (includes CSS string) |
129
- | `SET_IFRAME_MODE` | Sets the iframe mode (includes mode: 'embedded', 'non-embedded', or undefined) |
130
-
131
- ## ๐Ÿ”ง Usage Examples
67
+ Optional: use `apiBaseUrl` to target non-production environments.
132
68
 
133
- > **Note**: The following examples are illustrative code for vanilla TypeScript. If you're using React or other JavaScript frameworks, the code should be adapted to the corresponding framework patterns (hooks, lifecycle methods, etc.).
134
-
135
- ### Parent Site Implementation
69
+ ### 3. Mount asynchronously
136
70
 
137
71
  ```typescript
138
- import { createOnboardingApp } from '@worthai/onboarding-sdk';
139
-
140
- // Initialize the onboarding app
141
- const onboardingApp = createOnboardingApp({
142
- origin: 'https://onboarding.example.com',
143
- });
144
-
145
- // Mount the iframe
146
- document
147
- .getElementById('onboarding-container')
148
- ?.appendChild(onboardingApp.iframe);
149
-
150
- // Listen for route changes
151
- const subscription = onboardingApp.subscribe((event) => {
152
- if (event.data.type === 'ROUTE_URL') {
153
- //Some logic here...
154
- }
155
- });
156
-
157
- // โš ๏ธ Important: Remember to unsubscribe when component unmounts or cleanup is needed
158
- // subscription.unsubscribe();
159
-
160
- // Next stage navigation command
161
- onboardingApp.next();
162
-
163
- // Prev stage navigation command
164
- onboardingApp.prev();
72
+ await onboarding.mount('#worth-onboarding');
165
73
  ```
166
74
 
167
- ### Child Site Implementation
168
-
169
- ```typescript
170
- import { createOnboardingConsumerApp } from '@worthai/onboarding-sdk';
171
-
172
- // Initialize the consumer app
173
- const consumerApp = createOnboardingConsumerApp();
75
+ Wrap the mount call in try/catch to handle mount failures separately from runtime errors.
174
76
 
175
- // Listen for parent commands
176
- const subscription = consumerApp.subscribe((event) => {
177
- if (event.data.type === 'NEXT_STAGE') {
178
- // Add some logic here...
179
- }
180
- });
77
+ ### 4. Clean up
181
78
 
182
- // โš ๏ธ Important: Remember to unsubscribe when component unmounts or cleanup is needed
183
- // subscription.unsubscribe();
79
+ Call `unmount()` when routes change or components unload. SDK 3 allows only one mounted instance at a time.
184
80
 
185
- // Send form data to parent
186
- onboardingConsumerApp.postMessage({
187
- type: 'ROUTE_URL',
188
- payload: { url: '/some-route-here' },
189
- });
81
+ ```typescript
82
+ onboarding.unmount();
190
83
  ```
191
84
 
192
- ### Custom Raw CSS
85
+ ### Framework Integration
193
86
 
194
- The SDK allows parent sites to inject custom CSS styles into the child iframe. This is useful for customizing the appearance of the onboarding flow to match your brand or design requirements.
87
+ In React or similar frameworks, create the instance once, mount during component
88
+ initialization, and unmount in the cleanup function of your effect/lifecycle hook.
195
89
 
196
- #### Parent Site: Sending Custom CSS
90
+ ### Content Security Policy
197
91
 
198
- ```typescript
199
- import { createOnboardingApp } from '@worthai/onboarding-sdk';
92
+ If your page enforces a strict `style-src` CSP, pass your nonce so injected styles aren't blocked:
200
93
 
201
- const onboardingApp = createOnboardingApp({
202
- origin: 'https://onboarding.example.com',
203
- });
204
-
205
- // Send custom CSS to the child iframe
206
- onboardingApp.postMessage({
207
- type: 'SET_CUSTOM_CSS',
208
- payload: {
209
- css: `
210
- body {
211
- background: #f0f0f0;
212
- font-family: 'Custom Font', sans-serif;
213
- }
214
- .onboarding-container {
215
- padding: 20px;
216
- border-radius: 8px;
217
- }
218
- `,
219
- },
94
+ ```typescript
95
+ createWorthOnboarding({
96
+ // ...
97
+ styleNonce: window.__CSP_NONCE__,
220
98
  });
221
99
  ```
222
100
 
223
- #### Child Site: Receiving and Applying Custom CSS
101
+ ### Error Handling
224
102
 
225
- ```typescript
226
- import { createOnboardingConsumerApp } from '@worthai/onboarding-sdk';
227
-
228
- const consumerApp = createOnboardingConsumerApp();
103
+ Use `isWorthOnboardingError()` to identify Worth-specific errors and branch on their `code` property.
229
104
 
230
- // Listen for custom CSS messages
231
- const subscription = consumerApp.subscribe((event) => {
232
- if (event.data.type === 'SET_CUSTOM_CSS') {
233
- // Create or update a style element
234
- let styleElement = document.getElementById('custom-css-injection');
105
+ ## Migrating from SDK 2
235
106
 
236
- if (!styleElement) {
237
- styleElement = document.createElement('style');
238
- styleElement.id = 'custom-css-injection';
239
- document.head.appendChild(styleElement);
240
- }
107
+ The migration shifts iframe ownership from your application to the SDK itself. Instead of
108
+ creating and managing an iframe with `postMessage` subscriptions, you now mount an embedded
109
+ runtime into a DOM element.
241
110
 
242
- // Apply the custom CSS
243
- styleElement.innerHTML = event.data.payload.css;
244
- }
245
- });
111
+ **Key architectural shift:** With SDK 2, your host page creates and manages a Worth iframe
112
+ directly. With SDK 3, you give the SDK a DOM element and it mounts, renders, and tears down
113
+ the onboarding runtime for you โ€” no iframe and no `postMessage` subscription required.
246
114
 
247
- // โš ๏ธ Important: Remember to unsubscribe when component unmounts or cleanup is needed
248
- // subscription.unsubscribe();
249
- ```
115
+ ### Feature Comparison
250
116
 
251
- > **Note**: The child site should handle CSS injection securely and validate that the CSS doesn't contain malicious content. Consider sanitizing the CSS string before applying it in production environments.
117
+ | Aspect | SDK 2 | SDK 3 |
118
+ | ---------- | -------------------------------------- | ---------------------------------------------------------- |
119
+ | Rendering | Host-managed iframe | SDK-managed DOM mount |
120
+ | Setup | `createOnboardingApp()` | `createWorthOnboarding()` |
121
+ | Mounting | `appendChild(iframe)` | `await onboarding.mount(target)` |
122
+ | Events | `subscribe()` + postMessage | Typed callbacks (`onStepSubmit`, `onComplete`, `onError`) |
123
+ | Navigation | Manual (`next()`, `prev()`, `skip()`) | SDK-owned (not exposed) |
124
+ | Styling | `setCustomCss()` | Auto-injected on mount |
125
+ | Cleanup | `unsubscribe()` + `cleanup()` | `unmount()` |
252
126
 
253
- ## ๐Ÿ”’ Security
127
+ ### SDK 3 Basic Setup
254
128
 
255
- The SDK includes built-in security measures:
129
+ ```typescript
130
+ const onboarding = createWorthOnboarding({
131
+ inviteToken: 'INVITE_TOKEN',
132
+ onComplete: ({ values }) => {},
133
+ onError: (error) => {},
134
+ });
256
135
 
257
- - **Origin validation**: All messages are validated against the specified origin
258
- - **Type safety**: TypeScript ensures message structure integrity
136
+ await onboarding.mount('#worth-onboarding');
259
137
 
260
- ## ๐Ÿงช Development
138
+ onboarding.unmount(); // cleanup
139
+ ```
261
140
 
262
- ### Building the SDK
141
+ ### Migration Steps
263
142
 
264
- ```bash
265
- pnpm build
266
- ```
143
+ 1. Update package version
144
+ 2. Add mount target element
145
+ 3. Remove old stylesheet imports
146
+ 4. Replace `createOnboardingApp` with `createWorthOnboarding`
147
+ 5. Move event handlers to callbacks (`onComplete`, `onError`)
148
+ 6. Add `onStepSubmit` if analytics/auditing needed
149
+ 7. Handle CSP nonce if applicable
150
+ 8. Remove iframe navigation methods
151
+ 9. Replace cleanup with `unmount()`
152
+ 10. Test full flow end-to-end
267
153
 
268
- ### Running Storybook
154
+ ## Documentation Links
269
155
 
270
- ```bash
271
- pnpm storybook
272
- ```
156
+ - [Overview](https://docs.worthai.com/onboarding-sdk-3/overview)
157
+ - [Quick Start Guide](https://docs.worthai.com/onboarding-sdk-3/quickstart)
158
+ - [Migration Guide (SDK 2 โ†’ SDK 3)](https://docs.worthai.com/onboarding-sdk-3/migrate)
159
+ - [API Reference](https://docs.worthai.com/onboarding-sdk-3/api-reference)
160
+ - [Full Documentation](https://docs.worthai.com/introduction)
161
+ - [Sample SDK initialization](https://docs.worthai.com/onboarding-sdk-3/sample-scenario)
273
162
 
274
- ## ๐Ÿ“ License
163
+ ## Support
275
164
 
276
- Private package - All rights reserved.
165
+ Questions or issues: [support@joinworth.com](mailto:support@joinworth.com)
@@ -0,0 +1,2 @@
1
+ import { WorthOnboarding, WorthOnboardingOptions } from './worthOnboarding.types';
2
+ export declare function createWorthOnboarding(options: WorthOnboardingOptions): WorthOnboarding;
@@ -0,0 +1,24 @@
1
+ export declare const WorthOnboardingErrorCode: {
2
+ readonly ALREADY_MOUNTED: "ALREADY_MOUNTED";
3
+ readonly CALLBACK_FAILED: "CALLBACK_FAILED";
4
+ readonly INVALID_MOUNT_TARGET: "INVALID_MOUNT_TARGET";
5
+ readonly INVALID_OPTIONS: "INVALID_OPTIONS";
6
+ readonly MISSING_INVITE_TOKEN: "MISSING_INVITE_TOKEN";
7
+ readonly MOUNT_CANCELLED: "MOUNT_CANCELLED";
8
+ readonly MOUNT_IN_PROGRESS: "MOUNT_IN_PROGRESS";
9
+ readonly MOUNT_TARGET_NOT_FOUND: "MOUNT_TARGET_NOT_FOUND";
10
+ readonly RUNTIME_ERROR: "RUNTIME_ERROR";
11
+ readonly RUNTIME_RENDER_FAILED: "RUNTIME_RENDER_FAILED";
12
+ readonly UNMOUNT_FAILED: "UNMOUNT_FAILED";
13
+ };
14
+ export type WorthOnboardingErrorCode = (typeof WorthOnboardingErrorCode)[keyof typeof WorthOnboardingErrorCode];
15
+ export interface WorthOnboardingErrorOptions {
16
+ readonly cause?: unknown;
17
+ readonly details?: Readonly<Record<string, unknown>>;
18
+ }
19
+ export declare class WorthOnboardingError extends Error {
20
+ readonly code: WorthOnboardingErrorCode;
21
+ readonly details?: Readonly<Record<string, unknown>>;
22
+ constructor(code: WorthOnboardingErrorCode, message: string, options?: WorthOnboardingErrorOptions);
23
+ }
24
+ export declare function isWorthOnboardingError(error: unknown): error is WorthOnboardingError;