@encorekit/web-sdk 2.0.2 → 2.0.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 +102 -4
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/umd/encore.min.js +1 -1
- package/dist/umd/encore.min.js.map +1 -1
- package/package.json +1 -1
- package/types/analytics/events.d.ts +20 -3
- package/types/analytics/events.d.ts.map +1 -1
- package/types/api/APIClient.d.ts.map +1 -1
- package/types/api/generated/types.d.ts +6 -1
- package/types/api/generated/types.d.ts.map +1 -1
- package/types/core/Encore.d.ts +4 -1
- package/types/core/Encore.d.ts.map +1 -1
- package/types/core/OfferManager.d.ts +1 -1
- package/types/core/OfferManager.d.ts.map +1 -1
- package/types/core/version.d.ts +1 -1
- package/types/index.d.ts +1 -0
- package/types/index.d.ts.map +1 -1
- package/types/types.d.ts +50 -1
- package/types/types.d.ts.map +1 -1
- package/types/ui/OfferCarousel.d.ts +8 -0
- package/types/ui/OfferCarousel.d.ts.map +1 -1
- package/types/ui/OfferModal.d.ts +25 -1
- package/types/ui/OfferModal.d.ts.map +1 -1
- package/types/ui/RewardActions.d.ts +15 -0
- package/types/ui/RewardActions.d.ts.map +1 -1
- package/types/ui/RewardLayout.d.ts +16 -0
- package/types/ui/RewardLayout.d.ts.map +1 -1
- package/types/ui/appearance.d.ts +154 -0
- package/types/ui/appearance.d.ts.map +1 -0
- package/types/ui/cssSafe.d.ts +34 -0
- package/types/ui/cssSafe.d.ts.map +1 -0
- package/types/ui/styles.d.ts +21 -1
- package/types/ui/styles.d.ts.map +1 -1
- package/types/utils/text.d.ts +14 -0
- package/types/utils/text.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ A JavaScript/TypeScript SDK that enables web applications to display targeted of
|
|
|
16
16
|
## Installation
|
|
17
17
|
|
|
18
18
|
```bash
|
|
19
|
-
npm install @encorekit/web-sdk
|
|
19
|
+
npm install @encorekit/web-sdk
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
Or via CDN:
|
|
@@ -25,9 +25,9 @@ Or via CDN:
|
|
|
25
25
|
<script src="https://encorekit.com/encore.min.js"></script>
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
## Upgrading to
|
|
28
|
+
## Upgrading to 2.0.2
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
2.0.2 removes the deferred redemption flow and the layout system. Claiming an
|
|
31
31
|
offer now always redirects to the advertiser immediately, and the composition is
|
|
32
32
|
derived from the placement's use case.
|
|
33
33
|
|
|
@@ -112,9 +112,107 @@ await Encore.show(
|
|
|
112
112
|
| `useCase` | `'reduceChurn' \| 'rewardUsers'` | Why the placement presents, and which composition it renders. Defaults to `'reduceChurn'`. |
|
|
113
113
|
| `headline` | `string` | Per-call override of the sheet's primary heading. |
|
|
114
114
|
| `subheadline` | `string` | Per-call override of the line under it. |
|
|
115
|
-
| `appearance` | `
|
|
115
|
+
| `appearance` | `AppearanceConfig` | Optional colour and per-element overrides. Advanced — see [Appearance](#appearance-advanced--optional). |
|
|
116
116
|
| `statusIcon` | `'success' \| 'none'` | Status icon above the headline. Defaults to `'none'` — nothing renders unless you ask for `'success'`, which draws a green-circle check. Only `'rewardUsers'` has a status block; `'reduceChurn'` ignores it. The default matches iOS and Android, whose reward variant renders no checkmark. |
|
|
117
117
|
|
|
118
|
+
### Appearance (advanced — optional)
|
|
119
|
+
|
|
120
|
+
**You can skip this.** Omitting `appearance` renders the SDK's default sheet, which is
|
|
121
|
+
the normal integration path. Everything below is opt-in.
|
|
122
|
+
|
|
123
|
+
Changing a colour is one line:
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
await Encore.show(undefined, { appearance: { accentColor: '#0A6' } });
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
| Option | Type | What it moves |
|
|
130
|
+
|:-------|:-----|:--------------|
|
|
131
|
+
| `accentColor` | colour | `--encore-primary-color`: focus rings, links, the churn CTA. |
|
|
132
|
+
| `backgroundColor` | colour | `--encore-bg-color`: the sheet canvas and every surface derived from it. |
|
|
133
|
+
| `textColor` | colour | `--encore-text-color`, from which muted and secondary ink are derived. |
|
|
134
|
+
| `modalBackgroundColor` | colour | The modal container only — narrower than `backgroundColor`. |
|
|
135
|
+
| `dotColor` / `dotActiveColor` | colour | The page indicator's inactive / active dots. |
|
|
136
|
+
| `headline` / `subheadline` | slot | The reward sheet's heading and the line under it. |
|
|
137
|
+
| `claimButton` / `declineButton` | slot | The "Claim gift" CTA and the "No thanks" button. |
|
|
138
|
+
|
|
139
|
+
Colours accept hex, `rgb()`/`hsl()`/`oklch()` and friends, named colours, and
|
|
140
|
+
`var(--your-token)`. Slot fields are read by the `'rewardUsers'` composition — the one
|
|
141
|
+
with a heading block, a CTA pair and page dots; `'reduceChurn'` renders the bare
|
|
142
|
+
carousel and uses the colours only.
|
|
143
|
+
|
|
144
|
+
#### Slots
|
|
145
|
+
|
|
146
|
+
A **slot** takes whichever of these three you need — nothing more:
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
appearance: {
|
|
150
|
+
// 1. Styled text. No DOM required.
|
|
151
|
+
headline: {
|
|
152
|
+
text: 'Nice work, Sam!',
|
|
153
|
+
color: '#FFD166',
|
|
154
|
+
fontFamily: '"Söhne", system-ui, sans-serif',
|
|
155
|
+
fontSize: '28px',
|
|
156
|
+
fontWeight: 700,
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
// 2. Your own element. Render something that is not text at all.
|
|
160
|
+
subheadline: myStreakBadgeElement,
|
|
161
|
+
|
|
162
|
+
// 3. A render function, called per presentation.
|
|
163
|
+
claimButton: ({ text, useCase, defaultElement }) => myCta(text),
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
A render function receives `text` (the copy the SDK resolved), `useCase`, and
|
|
168
|
+
`defaultElement` — the element the SDK would have rendered. Return `defaultElement` to
|
|
169
|
+
decorate rather than replace, which keeps every default style and accessibility
|
|
170
|
+
attribute:
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
declineButton: ({ defaultElement }) => {
|
|
174
|
+
defaultElement.classList.add('my-ghost-button');
|
|
175
|
+
return defaultElement;
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Text fields accept `text`, `color`, `fontFamily`, `fontSize`, `fontWeight`,
|
|
180
|
+
`letterSpacing` and `textAlign`; button slots add `backgroundColor`, `borderColor` and
|
|
181
|
+
`borderRadius`.
|
|
182
|
+
|
|
183
|
+
`fontFamily` accepts Latin family names, including accented ones (`"Söhne"`, `Größe`).
|
|
184
|
+
A family name in a non-Latin script (CJK, Cyrillic, Arabic) is not accepted on this
|
|
185
|
+
path — use the element or render-function form for those, which applies your own CSS
|
|
186
|
+
and bypasses the check entirely.
|
|
187
|
+
|
|
188
|
+
#### Precedence and fallbacks
|
|
189
|
+
|
|
190
|
+
Copy resolves per field, most specific first:
|
|
191
|
+
|
|
192
|
+
`appearance.headline.text` → `PlacementOptions.headline` → backend-resolved copy →
|
|
193
|
+
the SDK's built-in fallback.
|
|
194
|
+
|
|
195
|
+
A blank or whitespace-only value falls **through** to the next tier rather than blanking
|
|
196
|
+
the slot, so omit a field instead of passing `''`.
|
|
197
|
+
|
|
198
|
+
#### Two guarantees
|
|
199
|
+
|
|
200
|
+
**A bad override costs you the override, never the sheet.** Render functions run inside
|
|
201
|
+
a guard and colours/fonts/sizes go through an allow-list, so a throw, a non-element
|
|
202
|
+
return, a wrong type or a malformed colour falls back to the SDK's default element. The
|
|
203
|
+
modal cannot be taken down by anything you pass.
|
|
204
|
+
|
|
205
|
+
**The SDK keeps the action.** On `claimButton` and `declineButton` you supply appearance
|
|
206
|
+
only. Your element is mounted inside an SDK-owned control that carries the role, the tab
|
|
207
|
+
stop and the listener; the listener runs in the capture phase, so the SDK's
|
|
208
|
+
claim/decline runs first and a handler you attached to your own element does not run.
|
|
209
|
+
Read the outcome from `show()`'s resolved `ShowResult` — that is the supported way to
|
|
210
|
+
react to a claim or a dismissal.
|
|
211
|
+
|
|
212
|
+
> The element you pass is **adopted**: it is moved into the sheet and removed with it.
|
|
213
|
+
> Pass a fresh element (or use a render function) rather than one that is live in your
|
|
214
|
+
> page, and do not pass the same element to two slots.
|
|
215
|
+
|
|
118
216
|
### The result
|
|
119
217
|
|
|
120
218
|
`show()` **never rejects**. It resolves one of three statuses:
|