@sawport/react-sdk 1.2.5-alpha.1 → 1.2.5-alpha.11

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 CHANGED
@@ -1,212 +1,263 @@
1
- # Getting Started With Sawport Widget
1
+ # Sawport Widget Integration Guide
2
+
3
+ ## Overview
4
+
5
+ The Sawport Widget enables secure customer interactions—video calls, chat, document upload, and e-signature—embedded directly into your website or web application.
6
+
7
+ Available integrations:
8
+ - Web (CDN Embedded)
9
+ - React SDK
10
+ - Vue.js ES Module Integration
11
+
12
+ This guide provides configuration steps and usage examples for all supported platforms.
13
+
14
+ ## Using Sawport Widget on the Web (CDN)
15
+
16
+ ### 2.1 Add Required Scripts and Styles
17
+ Place this inside your HTML `<head>` tag:
2
18
 
3
- ## Web Usage
4
- ### Pull the Sawport Widget CSS from your HTML head into your web page.
5
19
  ```html
6
- <html>
7
- <head>
8
- <link href="https://unpkg.com/@sawport/react-sdk/dist/style.css" rel="stylesheet" />
9
- ...
20
+ <link
21
+ href="https://cdn.jsdelivr.net/npm/@sawport/react-sdk/dist/react-sdk.css"
22
+ rel="stylesheet"
23
+ />
10
24
  ```
11
25
 
12
- ### Create a div with id of `sawport-widget` that will contain the widget.
26
+ ### 2.2 Create Widget Container & Mount the Widget
27
+ Place this immediately after the `<body>` tag:
28
+
13
29
  ```html
14
- ...
15
- <div id="sawport-widget"></div>
16
- </body>
30
+ <div style="position: fixed; bottom: 20px; right: 20px; z-index: 200" id="sawport-widget"></div>
31
+
32
+ <script src="https://cdn.jsdelivr.net/npm/@sawport/react-sdk/dist/index.standalone.js" type="text/javascript"></script>
33
+
34
+ <script type="text/javascript">
35
+ function docReady(fn) {
36
+ ['complete', 'interactive'].includes(document.readyState)
37
+ ? setTimeout(fn, 1)
38
+ : document.addEventListener('DOMContentLoaded', fn);
39
+ }
40
+
41
+ docReady(() => window.sawportReactSDK.mountWidget(
42
+ {
43
+ baseURL: "https://{{BASE_URL}}",
44
+ apiURL: "https://{{BASE_URL}}/api/v1/",
45
+ projectId: "{{PROJECT_ID}}",
46
+ user: { email: 'example@email.com', mobile: '080XXXXXXXXX', name: 'Firstname Lastname' }, // optional
47
+ },
48
+ "sawport-widget"
49
+ ));
50
+ }
51
+ </script>
17
52
  ```
18
53
 
19
- ### Pull in the sawport SDK into your website
20
- After pulling the sawport SDK
21
- Global variable `sawportSDK` will be exposed to your webpage which you can access its method and properties.
54
+ ### 2.3 Complete HTML Example
55
+
22
56
  ```html
23
- ...
24
- <script type="module" src="https://unpkg.com/@sawport/react-sdk@latest/dist/index.js"></script>
25
- </body>
57
+ <!DOCTYPE html>
58
+ <html>
59
+ <head>
60
+ <link
61
+ href="https://cdn.jsdelivr.net/npm/@sawport/react-sdk/dist/react-sdk.css"
62
+ rel="stylesheet"
63
+ />
64
+ </head>
65
+
66
+ <body>
67
+ <!-- Your website content -->
68
+
69
+ <div
70
+ style="position: fixed; bottom: 20px; right: 20px; z-index: 200"
71
+ id="sawport-widget"
72
+ ></div>
73
+
74
+ <script src="https://cdn.jsdelivr.net/npm/@sawport/react-sdk/dist/index.standalone.js" type="text/javascript"></script>
75
+
76
+ <script type="text/javascript">
77
+ function docReady(fn) {
78
+ ['complete', 'interactive'].includes(document.readyState)
79
+ ? setTimeout(fn, 1)
80
+ : document.addEventListener('DOMContentLoaded', fn);
81
+ }
82
+
83
+ docReady(() => window.sawportReactSDK.mountWidget(
84
+ {
85
+ baseURL: "https://{{BASE_URL}}",
86
+ apiURL: "https://{{BASE_URL}}/api/v1/",
87
+ projectId: "{{PROJECT_ID}}",
88
+ user: { email: 'example@email.com', mobile: '080XXXXXXXXX', name: 'Firstname Lastname' }, // optional
89
+ },
90
+ "sawport-widget"
91
+ ));
92
+ </script>
93
+ </body>
94
+ </html>
26
95
  ```
27
96
 
28
- ### Mount the sawport widget when document is fully loaded and with default configurations.
29
- Use the global `sawportSDK.mountWidget` to mount the widget anytime with the configuration it accepts
97
+ ### 2.4 Updating Enterprise Credentials Dynamically
98
+
30
99
  ```html
31
- ...
32
- <script>function docReady(fn) {
33
- ['complete', 'interactive'].includes(document.readyState)
34
- ? setTimeout(fn, 1)
35
- : document.addEventListener('DOMContentLoaded', fn);
100
+ <script type="text/javascript">
101
+ window.sawportReactSDK.setSawportConfig({
102
+ baseURL: 'https://{DASHBOARD_HOST_DOMAIN}',
103
+ apiURL: 'https://{DASHBOARD_HOST_DOMAIN}/api/v1/',
104
+ projectId: 'XXXXXXXXXXXXXX',
105
+ user: {
106
+ email: 'example@email.com',
107
+ mobile: '080XXXXXXXXX',
108
+ name: 'Firstname Lastname',
36
109
  }
37
-
38
- docReady(() => sawportSDK.mountWidget({
39
- baseURL: 'https://{DASHBOARD_HOST_DOMAIN}',
40
- apiURL: 'https://{DASHBOARD_HOST_DOMAIN}/api/v1/',
41
- projectId: XXXXXXXXXXXXXX,
42
- user: {email: 'example@emai.lcom', mobile: '080XXXXXXXXX', name: 'Firstname Lastname'}, // optional
43
- }, 'sawport-widget'))
44
- </script>
45
- </body>
110
+ });
111
+ </script>
46
112
  ```
47
113
 
48
- ### Setting up enterprise credentials
49
- Call the Sawport function `setSawportConfig` to set the enterprise credential.
50
- ```js
51
- docReady(() => sawportSDK.setSawportConfig({
52
- baseURL: 'https://{DASHBOARD_HOST_DOMAIN}',
53
- apiURL: 'https://{DASHBOARD_HOST_DOMAIN}/api/v1/',
54
- projectId: XXXXXXXXXXXXXX,
55
- user: {email: 'example@emai.lcom', mobile: '080XXXXXXXXX', name: 'Firstname Lastname'}
56
- })
57
- )
58
- ```
114
+ ## Using the Widget in ReactJS
115
+
116
+ ### 3.1 Install the SDK
59
117
 
60
- # Usage In REACTJS
61
- ## Install the SDK
62
118
  ```bash
63
119
  yarn add @sawport/react-sdk
64
120
  ```
65
121
 
66
- ## Configuring The Widget
67
- You may configure the widget by passing object of config to the `SawportContext.Provider`.
122
+ ### 3.2 Configure the SDK (Global Config)
123
+
124
+ Wrap your app with `SawportContext.Provider`:
125
+
68
126
  ```jsx
69
127
  import { SawportContext } from '@sawport/react-sdk';
70
128
 
71
129
  <SawportContext.Provider
72
- value={{
73
- config: {
74
- baseURL: 'https://{DASHBOARD_HOST_DOMAIN}', // required
75
- apiURL: 'https://{DASHBOARD_HOST_DOMAIN}/api/v1/', // required
76
- projectId: 'XXXXXXXXXXXXXX' // required
77
- }
78
- }}>
79
- <YourApp />
130
+ value={{
131
+ config: {
132
+ baseURL: 'https://{DASHBOARD_HOST_DOMAIN}',
133
+ apiURL: 'https://{DASHBOARD_HOST_DOMAIN}/api/v1/',
134
+ projectId: 'XXXXXXXXXXXXXX'
135
+ }
136
+ }}
137
+ >
138
+ <YourApp />
80
139
  </SawportContext.Provider>
81
140
  ```
82
- ## Using The Widget
141
+
142
+ ### 3.3 Using the Widget
143
+
83
144
  ```jsx
84
145
  import { Widget } from '@sawport/react-sdk';
85
146
 
86
- <Widget user={{email: 'example@emai.lcom', mobile: '080XXXXXXXXX', name: 'Firstname Lastname'}} />
147
+ <Widget
148
+ user={{
149
+ email: 'example@email.com',
150
+ mobile: '080XXXXXXXXX',
151
+ name: 'Firstname Lastname'
152
+ }}
153
+ />
87
154
  ```
88
155
 
89
- ## Updating SDK Configuration
156
+ ### 3.4 Updating Config at Runtime
157
+
90
158
  ```js
91
159
  import { setSawportConfig } from '@sawport/react-sdk';
92
160
 
93
161
  setSawportConfig({
94
- user: {email: 'example@emai.lcom', mobile: '080XXXXXXXXX', name: 'Firstname Lastname'},
95
- baseURL: 'https://{DASHBOARD_HOST_DOMAIN}', // required
96
- apiURL: 'https://{DASHBOARD_HOST_DOMAIN}/api/v1/', // required
97
- projectId: 'XXXXXXXXXXXXXX' // required
98
- })
162
+ user: {
163
+ email: 'example@email.com',
164
+ mobile: '080XXXXXXXXX',
165
+ name: 'Firstname Lastname'
166
+ },
167
+ baseURL: 'https://{DASHBOARD_HOST_DOMAIN}',
168
+ apiURL: 'https://{DASHBOARD_HOST_DOMAIN}/api/v1/',
169
+ projectId: 'XXXXXXXXXXXXXX'
170
+ });
171
+ ```
172
+
173
+ ## Using the Widget in Vue.js
174
+
175
+ ### 4.1 Install the SDK
176
+
177
+ ```bash
178
+ yarn add @sawport/react-sdk
99
179
  ```
100
180
 
101
- # Usage In VUEJS
102
- ## Pull in Sawport SDK from the project's index.html
181
+ ### 4.2 Create Widget Mounting Point
182
+
103
183
  ```html
104
- <!DOCTYPE html>
105
- <html lang="en">
106
- <head>
107
- <meta charset="UTF-8">
108
- <link rel="icon" href="/favicon.ico">
109
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
110
- <title>Vite App</title>
111
- <!-- ADD SAWPORT SDK CSS -->
112
- <link href="https://unpkg.com/@sawport/react-sdk/dist/style.css" rel="stylesheet" />
113
- </head>
114
- <body>
115
- <div id="app"></div>
116
- <!-- CREATE A DIV TO HOLD SAWPORT WIDGET -->
117
- <div id="sawport-widget"></div>
118
- <!-- ADD SAWPORT SDK JS -->
119
- <script type="module" src="https://unpkg.com/@sawport/react-sdk@latest/dist/index.js"></script>
120
- <script type="module" src="/src/main.js"></script>
121
- </body>
122
- </html>
184
+ <div id="sawport-widget"></div>
123
185
  ```
124
186
 
125
- ## Mounting Sawport SDK From Your Vuejs APP
126
- You need to mount the widget from your vuejs app any time and any where.
127
- By pulling the Sawport SDK, `sawportSDK` variable would be exposed to your vuejs app globally.
187
+ ### 4.3 Mount Widget From Vue App
188
+
128
189
  ```vue
129
190
  <script setup>
191
+ import { onMounted } from 'vue'
192
+ import { mountWidget } from '@sawport/react-sdk'
130
193
  import HelloWorld from './components/HelloWorld.vue'
194
+ // import the SDK css styling
195
+ import '@sawport/react-sdk/dist/react-sdk.css'
131
196
 
132
- console.log({sawportSDK});
197
+ const dashboardUrl = 'https://{DASHBOARD_HOST_DOMAIN}'
133
198
 
134
- const dashboardUrl = 'https://{DASHBOARD_HOST_DOMAIN}/api/v1/'
135
-
136
- // sawportSDK is globally accessible
137
- // Call Once
138
- sawportSDK.mountWidget({
139
- baseURL: dashboardUrl,
140
- apiURL: `${dashboardUrl}/api/v1/`,
141
- projectId: 'XXXXXXXXXXXXXX',
142
- user: {email: 'example@email.com', mobile: '2348123456789', name: 'Firstname Lastname'}, // optional
143
- }, 'sawport-widget')
199
+ onMounted(() => {
200
+ mountWidget({
201
+ baseURL: dashboardUrl,
202
+ apiURL: `${dashboardUrl}/api/v1/`,
203
+ projectId: 'XXXXXXXXXXXXXX',
204
+ user: {
205
+ email: 'example@email.com',
206
+ mobile: '2348123456789',
207
+ name: 'Firstname Lastname'
208
+ },
209
+ }, 'sawport-widget')
210
+ })
144
211
  </script>
145
212
 
146
213
  <template>
147
- <div class="wrapper">
148
- <!-- YOU MAY ADD DIV WITH ID ANYWHERE TO HOLD THE SAWPORT WIDGET -->
149
- <!-- <div id="sawport-widget"></div> -->
150
- <HelloWorld msg="You did it!" />
151
- </div>
214
+ <div class="wrapper">
215
+ <HelloWorld msg="You did it!" />
216
+ </div>
152
217
  </template>
153
218
  ```
154
219
 
155
- # API References `sawportSDK`
156
-
157
- ## Widget
158
- Sawport React SDK widget component
159
- ### Type
160
- - React Component
161
- ### Props
162
- - [user](#user)
163
- - [projectId](#projectid)
164
-
165
- ## SawportContext
166
- Sawport Context for global configuration of the widget
167
- ### Type
168
- - React Context Component
169
- ### Props
170
- #### value
171
- - [config](#sawportconfig)
172
- - [setConfig](#setsawportconfig)
173
-
174
- ## setSawportConfig
175
- ### Type
176
- - Function(config)
177
- ### Props
178
- - [config](#sawportconfig)
179
-
180
- ## sawportConfig
181
- The Sawport configuration object
182
- ### Type
183
- - Object
184
- ### user
185
- - name: `customer name to populate in the widget`
186
- - mobile: `customer phone number to populate in the widget`
187
- - email: `customer email to populate in the widget`
188
- ### projectId
189
- `The Enterprise's ID from the Dashboard`
190
-
191
- ## useSawportConfig
192
- The React hook to get access to the Sawport configuration object
193
- ### Type
194
- - React Hook - Function()
195
- ### Return
196
- - [config](#sawportconfig)
197
-
198
- ## useSawportContext
199
- React hook for Sawport Context for global configuration of the widget
200
- ### Type
201
- - React Context Hook - Function()
202
- ### Return
203
- - Sawport Context
204
- - - [config](#sawportconfig)
205
- - - [setConfig](#setsawportconfig)
206
-
207
- ## mountWidget
208
- Method to mount the Sawport SDK widget in HTML element with id of `sawport-widget`
209
- ### Type
210
- - Function(config)
211
- ### Props
212
- - [config](#sawportconfig)
220
+ ## API Reference: Sawport SDK
221
+
222
+ ### 5.1 Widget Component
223
+ - React component for embedding the widget.
224
+ - Props:
225
+ - **user**: Customer information
226
+ - **projectId**: Enterprise ID
227
+
228
+ ### 5.2 SawportContext
229
+ - Global configuration provider.
230
+ - Properties:
231
+ - **config**: Sawport configuration object
232
+ - **setConfig**: Update configuration
233
+
234
+ ### 5.3 setSawportConfig
235
+ - Function for updating SDK config globally.
236
+
237
+ ### 5.4 sawportConfig Object
238
+ - Fields:
239
+ - **user.name**: Customer name
240
+ - **user.mobile**: Customer phone number
241
+ - **user.email**: Customer email address
242
+ - **projectId**: Enterprise project ID
243
+ - **baseURL**: Dashboard domain
244
+ - **apiURL**: Dashboard API base
245
+
246
+ ### 5.5 useSawportConfig
247
+ - React hook to access the config object.
248
+
249
+ ### 5.6 useSawportContext
250
+ - Hook to retrieve both config and setConfig.
251
+
252
+ ### 5.7 mountWidget
253
+ - Mounts SDK widget into a DOM element.
254
+ - Usage: `mountWidget(config, "sawport-widget")`
255
+
256
+ ## Summary
257
+
258
+ This page provides a complete guide for integrating the Sawport Widget across:
259
+ - CDN-based web apps
260
+ - React apps
261
+ - Vue.js apps
262
+
263
+ It includes configuration references, usage patterns, and API documentation for all widget-related tools.