@sidebandai/sideband-web 0.0.0-stage → 1.4.1-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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 SidebandAI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,139 @@
1
- # Temporary Holding Version
1
+ # @sidebandai/sideband-web
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Sideband event tracking and Pulse presentation for websites, with no framework
4
+ dependency. Styles are isolated from your application using Shadow DOM.
5
+
6
+ ## Install
7
+
8
+ ```bash
9
+ npm install @sidebandai/sideband-web@rc
10
+ ```
11
+
12
+ The `rc` tag selects the latest release candidate. Installation uses the public
13
+ npm registry and requires no registry credentials. Core is installed automatically.
14
+
15
+ ## Quick start
16
+
17
+ ```ts
18
+ import { Sideband } from '@sidebandai/sideband-web'
19
+
20
+ Sideband.configure({ apiKey: 'YOUR_API_KEY' })
21
+ Sideband.tagUser('user-123')
22
+ Sideband.track('checkout_completed', { plan: 'pro' })
23
+ Sideband.untagUser()
24
+ await Sideband.flush()
25
+ ```
26
+
27
+ For script-tag use, self-host `dist/sideband.iife.js`. Its `Sideband` global
28
+ exposes the same `configure`, `track`, `tagUser`, `untagUser`, and `flush` methods.
29
+ Styles are bundled inside Shadow DOM; no stylesheet import is required.
30
+
31
+ ## Configuration
32
+
33
+ `apiKey` identifies your Sideband application. Requests use the production
34
+ endpoint by default. An explicit `baseUrl` overrides the endpoint for custom
35
+ deployments and tests.
36
+
37
+ `appVersion` is optional and has no default.
38
+
39
+ ```ts
40
+ Sideband.configure({
41
+ apiKey: 'YOUR_API_KEY',
42
+ shouldPresentPulse: async (pulse) => {
43
+ // pulseId, version, title, and optional fab; no transport envelope.
44
+ return pulse.title.includes('Survey') ? 'notNow' : 'showNow'
45
+ },
46
+ })
47
+ ```
48
+
49
+ The presentation callback returns `showNow`, `notNow`, or `never`. Declines are
50
+ reported to the server. `onError` receives background errors; `onRateApp` handles
51
+ rating completion actions in the host website.
52
+
53
+ Browser integrations may also supply `context`, `headers`, `fetch`, or `ui: false`
54
+ for headless transport. Without `ui: false`, configuration during SSR is inert.
55
+
56
+ ## API
57
+
58
+ - `configure(config)` replaces the shared client and returns its instance.
59
+ - `track(eventName, metadata?)` queues an event. Metadata is a string-to-string
60
+ map; invalid values and empty event names are rejected.
61
+ - `tagUser(userId)` persists the opaque identity exactly.
62
+ - `untagUser()` clears runtime and persisted identity. An explicitly configured
63
+ `context.user_id` is restored after the runtime override is cleared.
64
+ - `flush()` forces queued delivery and returns a promise.
65
+ - `presentSimulatedPulse({ pulse, sentimentPresentation? })` presents a canonical
66
+ `Pulse` locally and returns whether it was accepted. It is also available on
67
+ the configured instance and script-tag global.
68
+ - `destroy()` tears down the shared client.
69
+
70
+ The returned instance also exposes `sync`, `openSurvey`, `closeSurvey`,
71
+ `getDeviceId`, and `destroy` for advanced browser integrations. Raw `sync` is a
72
+ one-shot request; background queued delivery owns batching and retries.
73
+
74
+ Device identity is persisted in localStorage; session identity is per-tab.
75
+ Event queues are in memory. Background/pagehide delivery uses fetch keepalive.
76
+ See `SidebandWebConfig` for delivery tuning options.
77
+
78
+ ## Event metadata and Pulse targeting
79
+
80
+ Pass metadata to `track` as string key-value pairs. Use metadata to describe an
81
+ event without creating a separate event name for each source, item type, or mode.
82
+ Only these six keys support Pulse trigger filters and event-history conditions:
83
+
84
+ | Key | Value format | Example |
85
+ | --- | --- | --- |
86
+ | `source` | String | `'home'` |
87
+ | `item_type` | String | `'article'` |
88
+ | `mode` | String | `'manual'` |
89
+ | `variant` | String | `'control'` |
90
+ | `count` | Integer sent as a string | `'3'` |
91
+ | `duration` | Seconds sent as a string; fractions allowed | `'12.5'` |
92
+
93
+ Use the exact lowercase key names. The server trims and lowercases values for
94
+ `source`, `item_type`, `mode`, and `variant`. These keys support equals and
95
+ not-equals comparisons. It compares `count` and `duration` numerically, with
96
+ equals, not-equals, greater-than, greater-than-or-equal, less-than, and
97
+ less-than-or-equal comparisons. Send `duration` in seconds, not milliseconds.
98
+
99
+ ```ts
100
+ Sideband.track('content_created', {
101
+ source: 'editor',
102
+ item_type: 'article',
103
+ count: '3',
104
+ duration: '12.5',
105
+ content_id: 'article-123',
106
+ })
107
+ ```
108
+
109
+ Custom keys such as `content_id`, `screen`, or `plan` are stored unchanged, but
110
+ cannot be used in Pulse targeting filters. A missing key does not match any
111
+ filter, including not-equals.
112
+
113
+ The server stores at most 20 metadata properties per event. It keeps valid
114
+ targeting keys first, then fills the remaining slots with custom keys in sorted
115
+ key order. It drops empty keys and invalid targeting values without rejecting
116
+ the event. For example, `count: '3.5'` and `count: '3.0'` are invalid; use
117
+ `count: '3'`. Normalization and numeric comparison happen on the server, not in
118
+ the SDK. Script-tag integrations use the same metadata rules.
119
+
120
+ ## Snackbar simulations
121
+
122
+ ```ts
123
+ Sideband.presentSimulatedPulse({
124
+ pulse, // A canonical Pulse value, including its FAB configuration.
125
+ sentimentPresentation: 'snackbar',
126
+ })
127
+ ```
128
+
129
+ The local preference defaults to `'sheet'`, matching the native SDKs. Snackbar
130
+ requires a FAB and a root `yes_no` question with exactly two answers and no
131
+ `system_other` option; other pulses use their normal presentation. Server-delivered
132
+ pulses use FAB/sheet presentation. This option only applies to local simulations.
133
+
134
+ Simulations do not report impressions or responses, or invoke `onRateApp`.
135
+ The configured runtime's normal event delivery continues independently.
136
+ The snackbar uses the root question prompt, sheet-derived colors, and the FAB's
137
+ artwork, placement, timeout, and `none`/`bar`/`fill` timer. Selecting an answer
138
+ freezes the timer and retains the answer through the card acknowledgement and
139
+ branch transition. Use `closeSurvey()` or the close control to dismiss it.
@@ -0,0 +1,35 @@
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, 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
+ export type SidebandWebConfig = SidebandCoreConfig & {
5
+ ui?: boolean;
6
+ };
7
+ export type SidebandInstance = {
8
+ track: (eventName: string, metadata?: EventMetadata, options?: TrackOptions) => void;
9
+ tagUser: (userId: string) => void;
10
+ untagUser: () => void;
11
+ sync: SidebandRuntime['sync'];
12
+ flush: () => Promise<void>;
13
+ openSurvey: () => void;
14
+ presentSimulatedPulse: (definition: SimulatedPulseDefinition) => boolean;
15
+ closeSurvey: () => Promise<void>;
16
+ getDeviceId: () => string;
17
+ destroy: () => void;
18
+ };
19
+ export declare function configure(config: SidebandWebConfig): SidebandInstance;
20
+ export declare function track(eventName: string, metadata?: EventMetadata, options?: TrackOptions): void;
21
+ export declare function tagUser(userId: string): void;
22
+ export declare function untagUser(): void;
23
+ export declare function flush(): Promise<void>;
24
+ export declare function presentSimulatedPulse(definition: SimulatedPulseDefinition): boolean;
25
+ export declare function destroy(): void;
26
+ export declare const Sideband: {
27
+ configure: typeof configure;
28
+ track: typeof track;
29
+ tagUser: typeof tagUser;
30
+ untagUser: typeof untagUser;
31
+ flush: typeof flush;
32
+ presentSimulatedPulse: typeof presentSimulatedPulse;
33
+ destroy: typeof destroy;
34
+ };
35
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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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