@sawport/react-sdk 1.2.5-beta.1 → 1.2.5-beta.2

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,60 +1,120 @@
1
1
  # Getting Started With Sawport Widget
2
2
 
3
- ## Web Usage
4
- ### Pull the Sawport Widget CSS from your HTML head into your web page.
3
+ ## Web Usage (CDN)
4
+
5
+ ### Step 1: Add Required Scripts and Styles to HTML Head
6
+ Add the React importmap and Sawport widget CSS to your HTML `<head>` tag:
7
+
5
8
  ```html
6
9
  <html>
7
10
  <head>
8
- <link href="https://unpkg.com/@sawport/react-sdk/dist/style.css" rel="stylesheet" />
9
- ...
11
+ <script type="importmap">
12
+ {
13
+ "imports": {
14
+ "react": "https://esm.sh/react@19.1.1",
15
+ "react-dom": "https://esm.sh/react-dom@19.1.1"
16
+ }
17
+ }
18
+ </script>
19
+ <link
20
+ href="https://esm.sh/@sawport/react-sdk/dist/react-sdk.css"
21
+ rel="stylesheet"
22
+ />
23
+ </head>
10
24
  ```
11
25
 
12
- ### Create a div with id of `sawport-widget` that will contain the widget.
13
- ```html
14
- ...
15
- <div id="sawport-widget"></div>
16
- </body>
17
- ```
26
+ ### Step 2: Create Widget Container and Mount Script
27
+ Add the widget container and mounting script after the `<body>` tag:
18
28
 
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.
22
29
  ```html
23
- ...
24
- <script type="module" src="https://unpkg.com/@sawport/react-sdk@latest/dist/index.js"></script>
25
- </body>
26
- ```
30
+ <body>
31
+ <div style="position: fixed; bottom: 20px; right: 20px; z-index: 200" id="sawport-widget"></div>
27
32
 
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
30
- ```html
31
- ...
32
- <script>function docReady(fn) {
33
+ <script type="module">
34
+ import {
35
+ mountWidget,
36
+ setSawportConfig,
37
+ } from "https://esm.sh/@sawport/react-sdk";
38
+
39
+ function docReady(fn) {
33
40
  ['complete', 'interactive'].includes(document.readyState)
34
41
  ? setTimeout(fn, 1)
35
42
  : document.addEventListener('DOMContentLoaded', fn);
36
43
  }
37
44
 
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'))
45
+ docReady(() => mountWidget(
46
+ {
47
+ baseURL: "https://{{BASE_URL}}",
48
+ apiURL: "https://{{BASE_URL}}/api/v1/",
49
+ projectId: "{{PROJECT_ID}}",
50
+ user: {email: 'example@email.com', mobile: '080XXXXXXXXX', name: 'Firstname Lastname'}, // optional
51
+ },
52
+ "sawport-widget"
53
+ ))
44
54
  </script>
45
55
  </body>
46
56
  ```
47
57
 
58
+ ### Complete Example
59
+ ```html
60
+ <!DOCTYPE html>
61
+ <html>
62
+ <head>
63
+ <script type="importmap">
64
+ {
65
+ "imports": {
66
+ "react": "https://esm.sh/react@19.1.1",
67
+ "react-dom": "https://esm.sh/react-dom@19.1.1"
68
+ }
69
+ }
70
+ </script>
71
+ <link
72
+ href="https://esm.sh/@sawport/react-sdk/dist/react-sdk.css"
73
+ rel="stylesheet"
74
+ />
75
+ </head>
76
+ <body>
77
+ <!-- Your page content -->
78
+
79
+ <div style="position: fixed; bottom: 20px; right: 20px; z-index: 200" id="sawport-widget"></div>
80
+
81
+ <script type="module">
82
+ import {
83
+ mountWidget,
84
+ setSawportConfig,
85
+ } from "https://esm.sh/@sawport/react-sdk";
86
+
87
+ function docReady(fn) {
88
+ ['complete', 'interactive'].includes(document.readyState)
89
+ ? setTimeout(fn, 1)
90
+ : document.addEventListener('DOMContentLoaded', fn);
91
+ }
92
+
93
+ docReady(() => mountWidget(
94
+ {
95
+ baseURL: "https://your-dashboard-domain.com",
96
+ apiURL: "https://your-dashboard-domain.com/api/v1/",
97
+ projectId: "your-project-id",
98
+ user: {email: 'example@email.com', mobile: '080XXXXXXXXX', name: 'Firstname Lastname'}, // optional
99
+ },
100
+ "sawport-widget"
101
+ ))
102
+ </script>
103
+ </body>
104
+ </html>
105
+ ```
106
+
48
107
  ### Setting up enterprise credentials
49
- Call the Sawport function `setSawportConfig` to set the enterprise credential.
108
+ You can dynamically update the Sawport configuration using `setSawportConfig`:
50
109
  ```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
- )
110
+ import { setSawportConfig } from "https://esm.sh/@sawport/react-sdk";
111
+
112
+ setSawportConfig({
113
+ baseURL: 'https://{DASHBOARD_HOST_DOMAIN}',
114
+ apiURL: 'https://{DASHBOARD_HOST_DOMAIN}/api/v1/',
115
+ projectId: 'XXXXXXXXXXXXXX',
116
+ user: {email: 'example@email.com', mobile: '080XXXXXXXXX', name: 'Firstname Lastname'}
117
+ })
58
118
  ```
59
119
 
60
120
  # Usage In REACTJS
@@ -108,39 +168,45 @@ setSawportConfig({
108
168
  <link rel="icon" href="/favicon.ico">
109
169
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
110
170
  <title>Vite App</title>
111
- <!-- ADD SAWPORT SDK CSS -->
112
- <link href="https://unpkg.com/@sawport/react-sdk/dist/style.css" rel="stylesheet" />
171
+ <!-- ADD REACT IMPORTMAP -->
172
+ <script type="importmap">
173
+ {
174
+ "imports": {
175
+ "react": "https://esm.sh/react@19.1.1",
176
+ "react-dom": "https://esm.sh/react-dom@19.1.1"
177
+ }
178
+ }
179
+ </script>
180
+ <!-- ADD SAWPORT SDK CSS -->
181
+ <link href="https://esm.sh/@sawport/react-sdk/dist/react-sdk.css" rel="stylesheet" />
113
182
  </head>
114
183
  <body>
115
184
  <div id="app"></div>
116
- <!-- CREATE A DIV TO HOLD SAWPORT WIDGET -->
185
+ <!-- CREATE A DIV TO HOLD SAWPORT WIDGET -->
117
186
  <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
187
  <script type="module" src="/src/main.js"></script>
121
188
  </body>
122
189
  </html>
123
190
  ```
124
191
 
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.
192
+ ## Mounting Sawport SDK From Your Vue.js APP
193
+ You need to mount the widget from your Vue.js app. Import the SDK functions directly using ES modules.
128
194
  ```vue
129
195
  <script setup>
196
+ import { onMounted } from 'vue'
197
+ import { mountWidget } from 'https://esm.sh/@sawport/react-sdk'
130
198
  import HelloWorld from './components/HelloWorld.vue'
131
199
 
132
- console.log({sawportSDK});
133
-
134
- const dashboardUrl = 'https://{DASHBOARD_HOST_DOMAIN}/api/v1/'
200
+ const dashboardUrl = 'https://{DASHBOARD_HOST_DOMAIN}'
135
201
 
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')
202
+ onMounted(() => {
203
+ mountWidget({
204
+ baseURL: dashboardUrl,
205
+ apiURL: `${dashboardUrl}/api/v1/`,
206
+ projectId: 'XXXXXXXXXXXXXX',
207
+ user: {email: 'example@email.com', mobile: '2348123456789', name: 'Firstname Lastname'}, // optional
208
+ }, 'sawport-widget')
209
+ })
144
210
  </script>
145
211
 
146
212
  <template>