@returningai/widget-sdk 1.3.0 → 1.4.0

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
@@ -52,11 +52,12 @@ const { data } = await response.json()
52
52
  data-widget-type="store"
53
53
  data-theme="dark"
54
54
  data-embed-token="eyJ..."
55
- api-url="YOUR_API_URL"
56
55
  widget-url="YOUR_WIDGET_URL"
57
56
  ></script>
58
57
  ```
59
58
 
59
+ `api-url` is optional. The SDK resolves the widget server from `domain-key` when provided and uses production by default; pass `api-url` only if you need to override the widget auth server.
60
+
60
61
  The server validates the token and extracts identity from its signed claims. If the token is expired, invalid, or its identifiers don't satisfy the widget's configured User Identifier Fields, the widget shows an error screen. Tokens expire after 15 minutes — regenerate on each page render.
61
62
 
62
63
  ---
@@ -102,7 +103,6 @@ All examples below use **Access Key Embed** (recommended) — identity is signed
102
103
  data-widget-type="store"
103
104
  data-theme="dark"
104
105
  data-embed-token="eyJ..."
105
- api-url="YOUR_API_URL"
106
106
  widget-url="YOUR_WIDGET_URL"
107
107
  ></script>
108
108
  ```
@@ -116,7 +116,6 @@ All examples below use **Access Key Embed** (recommended) — identity is signed
116
116
  data-widget-type="channel"
117
117
  data-theme="dark"
118
118
  data-embed-token="eyJ..."
119
- api-url="YOUR_API_URL"
120
119
  widget-url="YOUR_WIDGET_URL"
121
120
  ></script>
122
121
  ```
@@ -132,7 +131,6 @@ All examples below use **Access Key Embed** (recommended) — identity is signed
132
131
  data-widget-type="social"
133
132
  data-theme="dark"
134
133
  data-embed-token="eyJ..."
135
- api-url="YOUR_API_URL"
136
134
  widget-url="YOUR_WIDGET_URL"
137
135
  ></script>
138
136
  ```
@@ -146,7 +144,6 @@ All examples below use **Access Key Embed** (recommended) — identity is signed
146
144
  data-widget-type="milestone"
147
145
  data-theme="dark"
148
146
  data-embed-token="eyJ..."
149
- api-url="YOUR_API_URL"
150
147
  widget-url="YOUR_WIDGET_URL"
151
148
  ></script>
152
149
  ```
@@ -160,7 +157,6 @@ All examples below use **Access Key Embed** (recommended) — identity is signed
160
157
  data-widget-type="custom"
161
158
  data-theme="dark"
162
159
  data-embed-token="eyJ..."
163
- api-url="YOUR_API_URL"
164
160
  widget-url="YOUR_WIDGET_URL"
165
161
  ></script>
166
162
  ```
@@ -184,10 +180,10 @@ All attributes can be provided with or without the `data-` prefix — both work.
184
180
  |-----------|----------|---------|-------------|
185
181
  | `data-widget-id` | **Yes** | — | Your widget ID (from dashboard) |
186
182
  | `data-widget-type` | **Yes** | `store` | Widget type (see table above) |
187
- | `api-url` | **Yes**\* | — | Auth API base URL (from dashboard) |
183
+ | `api-url` | No | Production widget server | Optional widget auth server override. Defaults from `domain-key` when provided |
188
184
  | `widget-url` | **Yes**\* | — | Widget URL (from dashboard). \*Not required when using `data-bundle-url` |
189
185
  | `data-bundle-url` | No | — | URL to the widget IIFE bundle — triggers [bundle mode](#bundle-mode) (non-iframe) |
190
- | `data-domain-key` | Bundle mode | — | Environment key: `SGTR`, `STG`, or `PROD`. Required for bundle mode on external sites |
186
+ | `data-domain-key` | No | `PROD` | Environment key: `SGTR`, `STG`, or `PROD`. Used to resolve default environment URLs when overrides are omitted |
191
187
  | `data-theme` | No | `light` | `light` or `dark` |
192
188
  | `data-email` | Public Embed only | — | User's email for identification. **Access Key Embed:** omit — identity is signed into `data-embed-token` |
193
189
  | `data-embed-token` | Access Key Embed only | — | Short-lived JWT from your server. Carries signed user identifiers — no `data-*` identifier attributes needed |
@@ -197,7 +193,7 @@ All attributes can be provided with or without the `data-` prefix — both work.
197
193
  | `data-debug` | No | `false` | Verbose console logging |
198
194
  | `data-custom-data` | No | — | JSON object forwarded to the widget |
199
195
  | `data-retry-label` | No | `Retry` | Label text for the retry button on the error screen |
200
- | `data-v2-api-url` | Reserved | — | Reserved for future deployments where V2 API endpoints live on a different host than `api-url`. Currently unused — safe to omit |
196
+ | `data-v2-api-url` | No | Domain-key default | Optional V2 API override for bundle mode. Safe to omit for standard environments |
201
197
 
202
198
  ### Custom element attributes
203
199
 
@@ -205,10 +201,10 @@ All attributes can be provided with or without the `data-` prefix — both work.
205
201
  |-----------|----------|---------|-------------|
206
202
  | `community-id` | **Yes**\* | — | Your community ID (raw ObjectId from dashboard). \*Custom widgets use `widget-id` instead |
207
203
  | `channel-id` | **Channel only** | — | Channel ID (raw ObjectId) — required for `<rai-channel-widget>` |
208
- | `api-url` | **Yes** | — | Auth API base URL (from dashboard) |
204
+ | `api-url` | No | Production widget server | Optional widget auth server override. Defaults from `domain-key` when provided |
209
205
  | `widget-url` | **Yes**\* | — | Widget URL (from dashboard). \*Not required when using `bundle-url` |
210
206
  | `bundle-url` | No | — | URL to the widget IIFE bundle — triggers [bundle mode](#bundle-mode) (non-iframe) |
211
- | `domain-key` | Bundle mode | — | Environment key: `SGTR`, `STG`, or `PROD`. Required for bundle mode on external sites |
207
+ | `domain-key` | No | `PROD` | Environment key: `SGTR`, `STG`, or `PROD`. Used to resolve default environment URLs when overrides are omitted |
212
208
  | `theme` | No | `light` | `light` or `dark` |
213
209
  | `data-email` | Public Embed only | — | User's email for identification. **Access Key Embed:** omit — identity is signed into `embed-token` |
214
210
  | `embed-token` | Access Key Embed only | — | Short-lived JWT from your server. Carries signed user identifiers — no `data-*` identifier attributes needed |
@@ -220,7 +216,7 @@ All attributes can be provided with or without the `data-` prefix — both work.
220
216
  | `debug` | No | `false` | Verbose console logging |
221
217
  | `custom-data` | No | — | JSON object forwarded to the widget |
222
218
  | `retry-label` | No | `Retry` | Label text for the retry button on the error screen |
223
- | `v2-api-url` | Reserved | — | Reserved for future deployments where V2 API endpoints live on a different host than `api-url`. Currently unused — safe to omit |
219
+ | `v2-api-url` | No | Domain-key default | Optional V2 API override for bundle mode. Safe to omit for standard environments |
224
220
 
225
221
  > **`widget-id` vs `community-id`:** The script-tag method uses `data-widget-id` which is a pre-encoded identifier (base64). The custom element method uses raw ObjectIds — `community-id` for most widget types, plus `channel-id` for channel widgets. The SDK handles the encoding internally.
226
222
 
@@ -248,7 +244,6 @@ Custom elements don't need a container div — they size themselves using `width
248
244
  data-email="user@example.com"
249
245
  data-user-id="12345"
250
246
  data-account-id="abc"
251
- api-url="YOUR_API_URL"
252
247
  widget-url="YOUR_WIDGET_URL"
253
248
  ></script>
254
249
  ```
@@ -262,10 +257,11 @@ In Public Embed mode, any `data-*` attribute not reserved by the SDK is forwarde
262
257
  When you set the `bundle-url` attribute, the widget renders directly in the page DOM instead of inside an iframe. This gives full CSS cascade — `html[data-theme]` and Tailwind classes apply to the widget content naturally.
263
258
 
264
259
  - `widget-url` is **not** needed in bundle mode (the widget is loaded directly from `bundle-url`).
265
- - `api-url` **is still required** — it's where the SDK sends the auth request (`/auth/serverless`).
266
- - `domain-key` is required so the widget IIFE resolves the correct environment URLs.
260
+ - `api-url` is optional. The SDK resolves the widget auth server from `domain-key` when provided, or defaults to production.
261
+ - `domain-key` is optional. When omitted, the SDK defaults to production (`PROD`).
262
+ - Environment URL variables such as `window.api_url` are optional overrides. Standard `SGTR`, `STG`, and `PROD` environments resolve from `domain-key`.
267
263
 
268
- Both examples below use Access Key Embed:
264
+ Both examples below use Access Key Embed and target staging. Omit `domain-key` for production.
269
265
 
270
266
  ```html
271
267
  <!-- Script-tag approach -->
@@ -276,17 +272,15 @@ Both examples below use Access Key Embed:
276
272
  data-theme="dark"
277
273
  data-embed-token="eyJ..."
278
274
  data-bundle-url="YOUR_BUNDLE_URL"
279
- data-domain-key="YOUR_DOMAIN_KEY"
280
- api-url="YOUR_API_URL"
275
+ data-domain-key="STG"
281
276
  data-eager
282
277
  ></script>
283
278
 
284
279
  <!-- Custom element approach -->
285
280
  <rai-store-widget
286
281
  community-id="YOUR_COMMUNITY_ID"
287
- api-url="YOUR_API_URL"
288
282
  bundle-url="YOUR_BUNDLE_URL"
289
- domain-key="YOUR_DOMAIN_KEY"
283
+ domain-key="STG"
290
284
  embed-token="eyJ..."
291
285
  theme="dark"
292
286
  width="100%"
@@ -327,7 +321,6 @@ All examples below use **Access Key Embed** — pass the short-lived token your
327
321
  community-id="YOUR_COMMUNITY_ID"
328
322
  theme="dark"
329
323
  embed-token="eyJ..."
330
- api-url="YOUR_API_URL"
331
324
  widget-url="YOUR_WIDGET_URL"
332
325
  ></rai-store-widget>
333
326
 
@@ -337,7 +330,6 @@ All examples below use **Access Key Embed** — pass the short-lived token your
337
330
  channel-id="YOUR_CHANNEL_ID"
338
331
  theme="dark"
339
332
  embed-token="eyJ..."
340
- api-url="YOUR_API_URL"
341
333
  widget-url="YOUR_WIDGET_URL"
342
334
  ></rai-channel-widget>
343
335
  ```
@@ -355,7 +347,6 @@ export function StoreEmbed({ embedToken }: { embedToken: string }) {
355
347
  community-id="YOUR_COMMUNITY_ID"
356
348
  theme="dark"
357
349
  embed-token={embedToken}
358
- api-url="YOUR_API_URL"
359
350
  widget-url="YOUR_WIDGET_URL"
360
351
  />
361
352
  )
@@ -368,7 +359,6 @@ export function ChannelEmbed({ embedToken }: { embedToken: string }) {
368
359
  channel-id="YOUR_CHANNEL_ID"
369
360
  theme="dark"
370
361
  embed-token={embedToken}
371
- api-url="YOUR_API_URL"
372
362
  widget-url="YOUR_WIDGET_URL"
373
363
  />
374
364
  )
@@ -389,7 +379,6 @@ defineProps({ embedToken: String })
389
379
  community-id="YOUR_COMMUNITY_ID"
390
380
  theme="dark"
391
381
  :embed-token="embedToken"
392
- api-url="YOUR_API_URL"
393
382
  widget-url="YOUR_WIDGET_URL"
394
383
  />
395
384
 
@@ -399,7 +388,6 @@ defineProps({ embedToken: String })
399
388
  channel-id="YOUR_CHANNEL_ID"
400
389
  theme="dark"
401
390
  :embed-token="embedToken"
402
- api-url="YOUR_API_URL"
403
391
  widget-url="YOUR_WIDGET_URL"
404
392
  />
405
393
  </template>
@@ -421,7 +409,6 @@ import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'
421
409
  community-id="YOUR_COMMUNITY_ID"
422
410
  theme="dark"
423
411
  [attr.embed-token]="embedToken"
424
- api-url="YOUR_API_URL"
425
412
  widget-url="YOUR_WIDGET_URL"
426
413
  ></rai-store-widget>
427
414
 
@@ -431,7 +418,6 @@ import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'
431
418
  channel-id="YOUR_CHANNEL_ID"
432
419
  theme="dark"
433
420
  [attr.embed-token]="embedToken"
434
- api-url="YOUR_API_URL"
435
421
  widget-url="YOUR_WIDGET_URL"
436
422
  ></rai-channel-widget>
437
423
  ```