obi-sdk 0.1.2 → 0.1.3

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
@@ -18,13 +18,12 @@ Currently, the recommended way to use Obi SDK is through the inline loader scrip
18
18
 
19
19
  The loader accepts the following configuration options:
20
20
 
21
- | Option | Type | Default | Description |
22
- | ------------ | ------- | ------------------------------ | ----------------------------------------------------------------------------------------------------------- |
23
- | `position` | string | `'bottom-right'` | Position of the widget on the page. Options: `'bottom-right'`, `'bottom-left'`, `'top-right'`, `'top-left'` |
24
- | `apiKey` | string | - | Your Obi API key (required for production) |
25
- | `sdkVersion` | string | `'latest'` | Version of the SDK to load |
26
- | `noCacheSDK` | boolean | `false` | Force fresh load of SDK without caching |
27
- | `apiBaseUrl` | string | `'https://www.iamobi.ai/api/'` | Base URL for API calls |
21
+ | Option | Type | Default | Description |
22
+ | ---------- | ------- | ---------------- | ----------------------------------------------------------------------------------------------------------- |
23
+ | `position` | string | `'bottom-right'` | Position of the widget on the page. Options: `'bottom-right'`, `'bottom-left'`, `'top-right'`, `'top-left'` |
24
+ | `apiKey` | string | - | Your Obi API key (required for production) |
25
+ | `autoInit` | boolean | `true` | Whether to initialize the widget automatically when loaded |
26
+ | `user` | object | - | User information with `id` (required), `email` (optional) and `metadata` (optional) |
28
27
 
29
28
  ## Quick Start
30
29
 
@@ -44,7 +43,10 @@ The simplest way to add Obi to your website is by using the inline loader script
44
43
  window.obiWidgetConfig = {
45
44
  position: "bottom-right",
46
45
  apiKey: "YOUR_API_KEY",
47
- apiBaseUrl: "https://www.iamobi.ai/api/",
46
+ user: {
47
+ id: "user-123",
48
+ email: "user@example.com",
49
+ },
48
50
  }
49
51
  </script>
50
52
  </head>
@@ -57,9 +59,7 @@ The simplest way to add Obi to your website is by using the inline loader script
57
59
  "use strict"
58
60
  var c = {
59
61
  position: "bottom-right",
60
- apiBaseUrl: "https://www.iamobi.ai/api/",
61
- sdkVersion: "latest",
62
- noCacheSDK: !1,
62
+ autoInit: true,
63
63
  }
64
64
  w.__obiSDKLoading = w.__obiSDKLoading || !1
65
65
  function i() {
@@ -73,20 +73,12 @@ The simplest way to add Obi to your website is by using the inline loader script
73
73
  })
74
74
  return
75
75
  }
76
- if (f.sdkVersion === "latest" && !f.noCacheSDK) {
77
- m(function (v) {
78
- v && (f.sdkVersion = v)
79
- j(f, function () {
80
- w.__obiSDKLoading = !1
81
- g(f)
82
- })
83
- })
84
- } else {
85
- j(f, function () {
76
+ m(function (v) {
77
+ j(v, function () {
86
78
  w.__obiSDKLoading = !1
87
79
  g(f)
88
80
  })
89
- }
81
+ })
90
82
  }
91
83
  }
92
84
  function e(f) {
@@ -99,7 +91,7 @@ The simplest way to add Obi to your website is by using the inline loader script
99
91
  }
100
92
  function m(cb) {
101
93
  try {
102
- var x = new (w.XMLHttpRequest || w.ActiveXObject)("Microsoft.XMLHTTP")
94
+ var x = new XMLHttpRequest()
103
95
  x.open("GET", "https://registry.npmjs.org/obi-sdk/latest")
104
96
  x.onload = function () {
105
97
  if (x.status === 200) {
@@ -121,23 +113,23 @@ The simplest way to add Obi to your website is by using the inline loader script
121
113
  cb(null)
122
114
  }
123
115
  }
124
- function j(f, cb) {
116
+ function j(v, cb) {
125
117
  w.__obiSDKLoading = !0
126
118
  var s = d.createElement("script")
127
119
  s.type = "text/javascript"
128
120
  s.async = !0
129
121
  var b = "https://unpkg.com/obi-sdk"
130
- s.src = f.noCacheSDK
131
- ? b + "@" + f.sdkVersion + "/dist/obi-sdk.standalone.iife.js?t=" + Date.now()
132
- : b + "@" + f.sdkVersion + "/dist/obi-sdk.standalone.iife.js"
122
+ var u = v || "latest"
123
+ s.src = b + "@" + u + "/dist/obi-sdk.standalone.iife.js"
133
124
  s.onload = cb
134
125
  s.onerror = function () {
135
- w.__obiSDKLoading = !1
136
- w.console && w.console.error && w.console.error("Failed to load Obi SDK")
137
- if (f.sdkVersion !== "latest" && !f.noCacheSDK) {
138
- w.console && w.console.warn && w.console.warn("Falling back to latest version")
139
- f.sdkVersion = "latest"
140
- j(f, cb)
126
+ if (u !== "latest") {
127
+ console.warn("Failed to load specific version, falling back to latest")
128
+ s.src = b + "@latest/dist/obi-sdk.standalone.iife.js"
129
+ s.onload = cb
130
+ } else {
131
+ w.__obiSDKLoading = !1
132
+ console.error("Failed to load Obi SDK")
141
133
  }
142
134
  }
143
135
  var fs = d.getElementsByTagName("script")[0]
@@ -159,36 +151,22 @@ The simplest way to add Obi to your website is by using the inline loader script
159
151
  var t = d.createElement("obi-widget")
160
152
  f.theme && t.setAttribute("theme", f.theme)
161
153
  f.apiKey && t.setAttribute("api-key", f.apiKey)
162
- f.endpoint && t.setAttribute("endpoint", f.endpoint)
163
- f.apiBaseUrl && t.setAttribute("api-base-url", f.apiBaseUrl)
164
- t.style.position = "fixed"
165
- t.style.zIndex = "9999"
166
- switch (f.position) {
167
- case "bottom-right":
168
- t.style.bottom = "20px"
169
- t.style.right = "20px"
170
- break
171
- case "bottom-left":
172
- t.style.bottom = "20px"
173
- t.style.left = "20px"
174
- break
175
- case "top-right":
176
- t.style.top = "20px"
177
- t.style.right = "20px"
178
- break
179
- case "top-left":
180
- t.style.top = "20px"
181
- t.style.left = "20px"
182
- break
183
- }
154
+ t.setAttribute("api-base-url", "https://www.iamobi.ai/api/")
155
+ f.position && t.setAttribute("position", f.position)
156
+ f.user && t.setAttribute("user", JSON.stringify(f.user))
184
157
  d.body.appendChild(t)
185
158
  w.console && w.console.log && w.console.log("Obi Widget added to page")
186
159
  }
187
- d.readyState === "complete"
188
- ? i()
189
- : w.attachEvent
190
- ? w.attachEvent("onload", i)
191
- : w.addEventListener("load", i, !1)
160
+ if (w.obiWidgetConfig && w.obiWidgetConfig.autoInit === false) {
161
+ // Skip auto-initialization
162
+ console.log("Obi Widget auto-initialization disabled")
163
+ } else {
164
+ d.readyState === "complete"
165
+ ? i()
166
+ : w.attachEvent
167
+ ? w.attachEvent("onload", i)
168
+ : w.addEventListener("load", i, !1)
169
+ }
192
170
  })(window, document)
193
171
  </script>
194
172
  </body>
@@ -202,10 +180,29 @@ The widget will automatically appear in the specified position on your page.
202
180
  The loader script:
203
181
 
204
182
  1. Dynamically checks for the latest version using the npm registry API
205
- 2. Loads the Obi SDK from unpkg.com with the appropriate version
183
+ 2. Loads the specific versioned SDK from unpkg.com for better browser caching
206
184
  3. Creates and positions the `<obi-widget>` custom element on your page
207
185
  4. Initializes the widget with your API key and configuration
208
186
 
187
+ ## Advanced Loader Usage
188
+
189
+ The inline loader script shown above is already minified for production use. If you need to customize it or understand how it works, you can find the full, commented version in the source code (`src/loader-inline.js`).
190
+
191
+ The loader script is also available as a separate file that can be loaded directly:
192
+
193
+ ```html
194
+ <!-- Configure the widget (optional) -->
195
+ <script>
196
+ window.obiWidgetConfig = {
197
+ position: "bottom-right",
198
+ apiKey: "YOUR_API_KEY",
199
+ }
200
+ </script>
201
+
202
+ <!-- Load the widget using the separate loader script -->
203
+ <script src="https://unpkg.com/obi-sdk@latest/dist/obi-loader.iife.js"></script>
204
+ ```
205
+
209
206
  ## Installation for npm Projects
210
207
 
211
208
  You can also install the SDK via npm:
@@ -222,7 +219,6 @@ import ObiSDK from "obi-sdk"
222
219
  // Initialize the SDK
223
220
  const sdk = new ObiSDK({
224
221
  apiKey: "YOUR_API_KEY",
225
- apiBaseUrl: "https://www.iamobi.ai/api/",
226
222
  })
227
223
  ```
228
224
 
@@ -284,7 +280,6 @@ The widget can be positioned in one of four corners of the page:
284
280
  window.obiWidgetConfig = {
285
281
  position: "bottom-right", // Options: "bottom-right", "bottom-left", "top-right", "top-left"
286
282
  apiKey: "YOUR_API_KEY",
287
- apiBaseUrl: "https://www.iamobi.ai/api/",
288
283
  }
289
284
  ```
290
285
 
@@ -296,7 +291,6 @@ The widget supports light and dark themes:
296
291
  window.obiWidgetConfig = {
297
292
  theme: "light", // Options: "light", "dark"
298
293
  apiKey: "YOUR_API_KEY",
299
- apiBaseUrl: "https://www.iamobi.ai/api/",
300
294
  }
301
295
  ```
302
296
 
@@ -309,7 +303,6 @@ window.obiWidgetConfig = {
309
303
  sdkVersion: "latest", // Use "latest" or a specific version number
310
304
  noCacheSDK: false, // Set to true to bypass cache
311
305
  apiKey: "YOUR_API_KEY",
312
- apiBaseUrl: "https://www.iamobi.ai/api/",
313
306
  }
314
307
  ```
315
308