@sidebandai/sideband-web 1.4.5-rc.1 → 1.4.5-rc.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
@@ -33,6 +33,141 @@ Replace `1.0.0` with your application's version, not the SDK version.
33
33
  Sideband presents available Pulses automatically. Styles are included; no
34
34
  stylesheet import is required.
35
35
 
36
+ ## Content Security Policy
37
+
38
+ If your site sends a Content Security Policy, allow the Sideband API origin in
39
+ `connect-src`. Without it, the browser blocks every send: no events arrive and
40
+ no pulses show.
41
+
42
+ | Endpoint | `connect-src` | `img-src` (pulse images) |
43
+ | --- | --- | --- |
44
+ | Production (default) | `https://api.sideband.ai` | `https://images.sideband.ai` |
45
+ | Development (`syncEndpoint: 'dev'`) | `https://api.dev-sideband.ai` | `https://images-dev.sideband.ai` |
46
+ | A custom `baseUrl` | That URL's origin, and the final origin if it redirects | That environment's image host |
47
+
48
+ The SDK also needs these, if your policy restricts them:
49
+
50
+ - `style-src` must allow inline styles (`'unsafe-inline'`). The SDK adds its
51
+ styles in a `<style>` element inside its shadow root, and it does not accept a
52
+ nonce. Without it, pulses show unstyled. If your policy has `style-src-elem`,
53
+ that directive applies instead, so it needs `'unsafe-inline'` too.
54
+ - If that directive already has a nonce (`'nonce-…'`) or a hash (`'sha256-…'`),
55
+ the browser ignores `'unsafe-inline'` in it. The SDK's styles are then
56
+ blocked, and pulses show unstyled; answering still works. The SDK cannot use
57
+ your nonce today. Do not remove the nonce or hash from your policy for
58
+ Sideband; contact Sideband instead.
59
+ - `img-src` must allow `data:` and the image host above. The close button's
60
+ icon is a `data:` image. Without the image host, a pulse shows without its
61
+ image; it still works.
62
+
63
+ For production, a policy with only these Sideband parts looks like this:
64
+
65
+ ```text
66
+ script-src 'self';
67
+ connect-src 'self' https://api.sideband.ai;
68
+ img-src 'self' data: https://images.sideband.ai;
69
+ style-src 'self' 'unsafe-inline'
70
+ ```
71
+
72
+ The SDK does not support Trusted Types (`require-trusted-types-for 'script'`).
73
+ It sets its icons with `innerHTML`, so the pulse sheet cannot open and `onError`
74
+ receives a `TrustedHTML` error. A site-wide `default` Trusted Types policy that
75
+ accepts any HTML makes it work, but removes that protection for your whole page.
76
+
77
+ A blocked send appears in the browser console as a Content Security Policy
78
+ error, and `onError` receives a network error. These rules, including the nonce,
79
+ hash and Trusted Types cases, were checked in Chrome against the built package
80
+ with `npm run test:csp` in the SDK repository.
81
+
82
+ ## Consent
83
+
84
+ Your app decides when Sideband runs. If Sideband needs consent on your site,
85
+ call `Sideband.configure` only after the user gives it, and call
86
+ `Sideband.destroy()` when the user withdraws it. Which consent category applies
87
+ is your decision; this README does not give legal advice.
88
+
89
+ A user who declines sends no events and sees no pulses. Before `configure`, and
90
+ after `destroy`, calls such as `Sideband.track` throw, so route them through one
91
+ wrapper that checks consent first:
92
+
93
+ ```ts
94
+ import { Sideband } from '@sidebandai/sideband-web'
95
+
96
+ let started = false
97
+
98
+ export function startSideband() {
99
+ if (started) return
100
+ started = true
101
+ Sideband.configure({ apiKey: 'YOUR_API_KEY', appVersion: '1.0.0' })
102
+ }
103
+
104
+ export function stopSideband() {
105
+ if (!started) return
106
+ started = false
107
+ Sideband.destroy() // events not yet sent are discarded
108
+ }
109
+
110
+ export function track(eventName: string, metadata?: Record<string, string>) {
111
+ if (started) Sideband.track(eventName, metadata)
112
+ }
113
+ ```
114
+
115
+ The SDK has no consent setting of its own.
116
+
117
+ ## Server-rendered apps and React 18
118
+
119
+ Start Sideband in the browser only, once per page load. With React 18 and server
120
+ rendering, use this package (the React package needs React 19). Load it from an
121
+ effect, so the server never imports it, and guard the start at module level, so
122
+ StrictMode's second effect run does not start it again:
123
+
124
+ ```tsx
125
+ import { useEffect } from 'react'
126
+
127
+ let starting: Promise<void> | null = null
128
+
129
+ function startSidebandOnce() {
130
+ starting ??= import('@sidebandai/sideband-web').then(({ Sideband }) => {
131
+ Sideband.configure({ apiKey: 'YOUR_API_KEY', appVersion: '1.0.0' })
132
+ })
133
+ return starting
134
+ }
135
+
136
+ export function SidebandStarter() {
137
+ useEffect(() => {
138
+ void startSidebandOnce()
139
+ }, [])
140
+ return null
141
+ }
142
+ ```
143
+
144
+ Render `<SidebandStarter />` once, near the root. Do not call `Sideband.destroy()`
145
+ in the effect cleanup: StrictMode runs the cleanup once in development, and a
146
+ second `configure` would send a second `system_app_launch`. If you gate on
147
+ consent, call the starter only after consent is given.
148
+
149
+ ## Language
150
+
151
+ The SDK reports the browser's language (for example `de` from `de-AT`). The
152
+ server shows a pulse only when that language matches the pulse's base language
153
+ or one of its published translations. If nothing matches, the pulse is not
154
+ shown, even without a language rule in its targeting. There is no fallback
155
+ language today.
156
+
157
+ If your site has one UI language, you can report that language instead, so
158
+ pulses match the page rather than the browser:
159
+
160
+ ```ts
161
+ Sideband.configure({
162
+ apiKey: 'YOUR_API_KEY',
163
+ appVersion: '1.0.0',
164
+ context: { language: 'en' },
165
+ })
166
+ ```
167
+
168
+ If your site is translated, pass the page's current language the same way. Test
169
+ with a browser set to a language that differs from your site's language.
170
+
36
171
  ## Identify users
37
172
 
38
173
  Tag the signed-in user wherever your app knows who they are: after sign-up and
@@ -91,6 +226,28 @@ When the page is hidden or unloads, the SDK tries to send queued events with
91
226
  `keepalive`. This is best effort: a send already in progress can delay it. For an
92
227
  event tracked just before your code navigates away, await `Sideband.flush()` first.
93
228
 
229
+ A pulse answer is sent when the user presses the final button (for example
230
+ Done), or closes the pulse, which sends the answers given so far. As in the iOS
231
+ and Android SDKs, nothing is sent while the thank-you screen is showing, so
232
+ answers are kept across a page load only after Done or a close; leaving the page
233
+ on the thank-you screen loses them. If the user leaves the page before the
234
+ server accepts the answer, the SDK tries again after the next page load in the
235
+ same tab. This is best effort.
236
+ The SDK keeps pending answers in the tab's `sessionStorage`, separately for each
237
+ API key and endpoint, and sends each answer only while the same user is tagged
238
+ (or the same `context.user_id` is configured). An answer is still lost when:
239
+
240
+ - storage is unavailable or full (`onError` receives a
241
+ `PendingInteractionStorageError` with `reason` `storage_unavailable` or
242
+ `storage_write_failed`);
243
+ - more than 10 answers are pending: the oldest are not kept (`reason`
244
+ `queue_full`);
245
+ - it is still unsent 24 hours after it was given;
246
+ - the server rejects it permanently, with a 4xx response other than 408, 425 or
247
+ 429 (`onError` receives the error);
248
+ - the user closes the tab, or does not return to that tab with the same user
249
+ and configuration.
250
+
94
251
  ## Events the SDK sends itself
95
252
 
96
253
  Do not track these yourself:
@@ -117,6 +274,14 @@ pulses. After each send, the server sets a minimum wait before the next
117
274
  regular send, and the SDK honors it. A pulse therefore usually shows a few
118
275
  seconds after its trigger event, not exactly one second after it.
119
276
 
277
+ Ordinary event batches wait for that interval, so a trigger tracked soon after
278
+ a send waits for the rest of it, including after a client-side route change.
279
+ Some sends do not wait, and queued events go with them: a new pulse answer, a pulse
280
+ impression, the page being hidden, and an explicit `flush()`. On a quiet page, a
281
+ new page load sends `system_app_launch` about one second after the SDK starts,
282
+ with the default `flushIntervalSeconds`. Tagging the user right after start
283
+ sends it sooner.
284
+
120
285
  `SidebandWebConfig` in the package's type definitions lists the optional
121
286
  settings, such as `shouldPresentPulse` to hold a Pulse back for a better
122
287
  moment and `onError` for background errors. `Sideband.flush()` sends queued
@@ -125,22 +290,29 @@ events now and returns a promise.
125
290
  ## Automated test builds
126
291
 
127
292
  Builds that use your Development channel's key also receive the pulses you
128
- publish there. In unattended UI tests, a pulse can cover the page and break the
129
- next step. To keep sending events but hold pulses back in those builds, return
130
- `'notNow'` from `shouldPresentPulse`:
293
+ publish there. Treat two kinds of automated run differently.
294
+
295
+ **Event-only automation.** In unattended UI tests, a pulse can cover the page
296
+ and break the next step. To keep sending events but hold pulses back in those
297
+ builds, return `'notNow'` from `shouldPresentPulse`:
131
298
 
132
299
  ```ts
133
300
  Sideband.configure({
134
301
  apiKey: 'YOUR_API_KEY',
135
302
  appVersion: '1.0.0',
136
- shouldPresentPulse: () => (isAutomatedTest ? 'notNow' : 'showNow'),
303
+ shouldPresentPulse: () => (holdPulses ? 'notNow' : 'showNow'),
137
304
  })
138
305
  ```
139
306
 
140
- `isAutomatedTest` stands for however your test runs mark themselves, such as a
307
+ `holdPulses` stands for an explicit setting your test runs turn on, such as a
141
308
  build-time variable. The SDK reports each pulse held back this way as a "not
142
309
  now" dismissal.
143
310
 
311
+ **A deliberate pulse test.** When a test is meant to show and answer a pulse,
312
+ turn that setting off for that run only. Use the same explicit setting; do not
313
+ detect automation from the browser (for example `navigator.webdriver`) and then
314
+ hide that signal to let a pulse through.
315
+
144
316
  ## Install Without a Bundler
145
317
 
146
318
  Copy `node_modules/@sidebandai/sideband-web/dist/sideband.iife.js` to your
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { EventMetadata, SidebandCoreConfig, SidebandRuntime, SimulatedPulseDefinition, TrackOptions } from '@sidebandai/sideband-core';
2
- export { createSidebandClient, getDeviceId, getSessionId, SidebandApiError, SurveySessionStore, buildFabTitle, getChoiceValue, SyncEngine, } from '@sidebandai/sideband-core';
3
- export type { AnsweredInteraction, ApiErrorDetail, ClientContext, CompletionActionStyle, CompletionActionType, CompletionIconType, CompletionType, DismissedInteraction, EventMetadata, EventRecord, Fab, FabOffset, FabPlacement, FabPoint, FabState, Interaction, Platform, PendingPulse, SyncEndpoint, Pulse, PulseAnswer, PulseCompletion, PulseCompletionAction, PulseQuestion, QuestionType, SentimentPresentation, SentimentPresentationOptions, BarPosition, BarBehavior, SimulatedPulseDefinition, SidebandClient, SidebandClientConfig, SidebandCoreConfig, SurveyAnswerDraft, SurveyAnswerMap, SurveyAnswerValue, SurveySessionState, SurveyStoreSnapshot, SurveyStoreUpdateReason, SyncEngineDeps, SyncEngineOptions, SyncErrorResponse, ServiceUnavailableError, SyncOptions, SyncRequest, SyncResponse, TrackedEvent, TrackOptions, Theme, ThemeColor, TimerStyle, SurveyPresentationDecision, SurveyPresentationKind, } from '@sidebandai/sideband-core';
2
+ export { createSidebandClient, getDeviceId, getSessionId, PendingInteractionStorageError, SidebandApiError, SurveySessionStore, buildFabTitle, getChoiceValue, SyncEngine, } from '@sidebandai/sideband-core';
3
+ export type { AnsweredInteraction, ApiErrorDetail, ClientContext, CompletionActionStyle, CompletionActionType, CompletionIconType, CompletionType, DismissedInteraction, EventMetadata, EventRecord, Fab, FabOffset, FabPlacement, FabPoint, FabState, Interaction, Platform, PendingInteractionStorageReason, PendingPulse, SyncEndpoint, Pulse, PulseAnswer, PulseCompletion, PulseCompletionAction, PulseQuestion, QuestionType, SentimentPresentation, SentimentPresentationOptions, BarPosition, BarBehavior, SimulatedPulseDefinition, SidebandClient, SidebandClientConfig, SidebandCoreConfig, SurveyAnswerDraft, SurveyAnswerMap, SurveyAnswerValue, SurveySessionState, SurveyStoreSnapshot, SurveyStoreUpdateReason, SyncEngineDeps, SyncEngineOptions, SyncErrorResponse, ServiceUnavailableError, SyncOptions, SyncRequest, SyncResponse, TrackedEvent, TrackOptions, Theme, ThemeColor, TimerStyle, SurveyPresentationDecision, SurveyPresentationKind, } from '@sidebandai/sideband-core';
4
4
  export type SidebandWebConfig = SidebandCoreConfig & {
5
5
  ui?: boolean;
6
6
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,wBAAwB,EACxB,YAAY,EACb,MAAM,2BAA2B,CAAA;AAIlC,OAAO,EACL,oBAAoB,EACpB,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,UAAU,GACX,MAAM,2BAA2B,CAAA;AAClC,YAAY,EACV,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EAClB,cAAc,EACd,oBAAoB,EACpB,aAAa,EACb,WAAW,EACX,GAAG,EACH,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,QAAQ,EAC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AKrE;AAED,wBAAgB,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,YAAY,QAExF;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,QAAkC;AACxE,wBAAgB,SAAS,SAA+B;AACxD,wBAAgB,KAAK,kBAAkC;AACvD,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,wBAAwB,WAA2D;AACrI,wBAAgB,OAAO,SAGtB;AAED,eAAO,MAAM,QAAQ;;;;;;;;CAAkF,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,wBAAwB,EACxB,YAAY,EACb,MAAM,2BAA2B,CAAA;AAIlC,OAAO,EACL,oBAAoB,EACpB,WAAW,EACX,YAAY,EACZ,8BAA8B,EAC9B,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,UAAU,GACX,MAAM,2BAA2B,CAAA;AAClC,YAAY,EACV,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EAClB,cAAc,EACd,oBAAoB,EACpB,aAAa,EACb,WAAW,EACX,GAAG,EACH,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,+BAA+B,EAC/B,YAAY,EACZ,YAAY,EACZ,KAAK,EACL,WAAW,EACX,eAAe,EACf,qBAAqB,EACrB,aAAa,EACb,YAAY,EACZ,qBAAqB,EACrB,4BAA4B,EAC5B,WAAW,EACX,WAAW,EACX,wBAAwB,EACxB,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,uBAAuB,EACvB,cAAc,EACd,iBAAiB,EACjB,iBAAi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