@fasttrack-solutions/rewards 0.0.0 → 1.44.2-beta.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 +203 -1
- package/dist/chunks/mini-game-engine-CYsCHBn8.js +3034 -0
- package/dist/chunks/sdkCallback-D3f8wFOW.js +11090 -0
- package/dist/rewards.js +14982 -0
- package/index.d.ts +6 -0
- package/package.json +41 -5
- package/ssr.js +4 -0
package/README.md
CHANGED
|
@@ -1,3 +1,205 @@
|
|
|
1
1
|
# @fasttrack-solutions/rewards
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Fast Track Rewards SDK and its `ft-*` web components (rewards modal, wheel, tournaments,
|
|
4
|
+
jackpots, mini games), for sites that bundle their JavaScript. It is the same production build
|
|
5
|
+
as the Rewards script on the Fast Track CDN, and it loads no code from the CDN: the mini-game
|
|
6
|
+
engine (wheel and sounds) ships inside the package as its own chunk, which your bundler splits
|
|
7
|
+
out and serves with the rest of your site.
|
|
8
|
+
|
|
9
|
+
## Which packages you need
|
|
10
|
+
|
|
11
|
+
| You want | Install | `integrationVersion` |
|
|
12
|
+
| --- | --- | --- |
|
|
13
|
+
| Rewards only | `@fasttrack-solutions/rewards` | `2.0` |
|
|
14
|
+
| Rewards with on-site notifications and the inbox | `@fasttrack-solutions/rewards` and [`@fasttrack-solutions/onsite`](https://www.npmjs.com/package/@fasttrack-solutions/onsite) | `1.1` |
|
|
15
|
+
| The standalone mini games served from your own site | add [`@fasttrack-solutions/rewards-games`](https://www.npmjs.com/package/@fasttrack-solutions/rewards-games) | either |
|
|
16
|
+
|
|
17
|
+
Your Fast Track integration manager gives you your brand name and your Fast Track API URL
|
|
18
|
+
(`https://<your-brand>.ft-crm.com` or similar).
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
npm install @fasttrack-solutions/rewards
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Pre-releases are published under the `beta` tag (`npm install @fasttrack-solutions/rewards@beta`).
|
|
27
|
+
|
|
28
|
+
## Quick start (Rewards only, integration 2.0)
|
|
29
|
+
|
|
30
|
+
1. Put the configuration in a module of its own. It must run before the package, because the
|
|
31
|
+
SDK reads some settings (such as `rewards.callbacks`) as it loads, and ES imports run before
|
|
32
|
+
the code around them:
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
// fasttrack-config.js
|
|
36
|
+
window.fasttrackbrand = 'your-brand';
|
|
37
|
+
window.sid = playerJwt; // the logged-in player's JWT; leave unset for a logged-out visitor
|
|
38
|
+
window.fasttrack = {
|
|
39
|
+
baseUrl: 'https://your-brand.ft-crm.com',
|
|
40
|
+
enableJWT: true,
|
|
41
|
+
integrationVersion: 2.0,
|
|
42
|
+
autoInit: true,
|
|
43
|
+
rewards: { enable: true },
|
|
44
|
+
};
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
2. Import it, then the package, once, in your entry point:
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
import './fasttrack-config.js';
|
|
51
|
+
import '@fasttrack-solutions/rewards';
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
3. Place the components in your markup:
|
|
55
|
+
|
|
56
|
+
```html
|
|
57
|
+
<ft-my-rewards-toggle></ft-my-rewards-toggle>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
When `window.sid` is set by the page's `DOMContentLoaded`, the package logs the player in and
|
|
61
|
+
starts Rewards. A `<script>` that sets the same globals before your bundle works too.
|
|
62
|
+
|
|
63
|
+
## With the on-site widget (integration 1.1)
|
|
64
|
+
|
|
65
|
+
Use `integrationVersion: 1.1`, follow the
|
|
66
|
+
[`@fasttrack-solutions/onsite`](https://www.npmjs.com/package/@fasttrack-solutions/onsite)
|
|
67
|
+
quick start, and import this package as well:
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
import './fasttrack-config.js';
|
|
71
|
+
import '@fasttrack-solutions/rewards';
|
|
72
|
+
import { FastTrackLoader } from '@fasttrack-solutions/onsite';
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The on-site widget logs the player in. Rewards starts when it does (the `fasttrack-crm-authed`
|
|
76
|
+
event) and logs out with it (`window.FasttrackCrm.logout()`), so you call none of the functions
|
|
77
|
+
below yourself.
|
|
78
|
+
|
|
79
|
+
## Logging players in and out (integration 2.0)
|
|
80
|
+
|
|
81
|
+
For a player who logs in after the page has loaded, such as in a single-page app:
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
function onLogin(jwt) {
|
|
85
|
+
window.sid = jwt;
|
|
86
|
+
window.ftcrm = { ...window.ftcrm, auth: { jwtToken: jwt } };
|
|
87
|
+
window.initFtRewards();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function onLogout() {
|
|
91
|
+
window.logoutFtRewards();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Your session refreshed the player's JWT: the SDK reconnects with the new one.
|
|
95
|
+
function onTokenRefresh(jwt) {
|
|
96
|
+
window.sid = jwt;
|
|
97
|
+
window.updateFtJwtToken(jwt);
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Calling `window.initFtRewards()` again reloads Rewards, which is also how a new login refreshes
|
|
102
|
+
its data.
|
|
103
|
+
|
|
104
|
+
## Components
|
|
105
|
+
|
|
106
|
+
| Element | What it shows |
|
|
107
|
+
| --- | --- |
|
|
108
|
+
| `<ft-my-rewards-toggle>` | A button that opens the rewards modal, with a badge for unclaimed rewards |
|
|
109
|
+
| `<ft-my-rewards>` | The rewards modal |
|
|
110
|
+
| `<ft-wheel-component>` | A spin wheel on its own |
|
|
111
|
+
| `<ft-tournament-page>` | Tournament leaderboards and details |
|
|
112
|
+
| `<ft-jackpot-card>` | A progressive jackpot |
|
|
113
|
+
| `<ft-notifications-center>` | Toast notifications for rewards events |
|
|
114
|
+
| `<ft-game-launcher game="ancient-temple" label="Play">` | A play button that opens a mini game full screen |
|
|
115
|
+
|
|
116
|
+
## Configuration
|
|
117
|
+
|
|
118
|
+
Everything goes under `window.fasttrack`:
|
|
119
|
+
|
|
120
|
+
| Key | Description |
|
|
121
|
+
| --- | --- |
|
|
122
|
+
| `baseUrl` | Your Fast Track API URL. Integration 1.1 takes it from the on-site widget instead. |
|
|
123
|
+
| `integrationVersion` | `2.0` for Rewards only, `1.1` with the on-site widget. |
|
|
124
|
+
| `enableJWT` | `true`: `window.sid` is a JWT. |
|
|
125
|
+
| `rewards.enable` | `true` to turn Rewards on. |
|
|
126
|
+
| `rewards.callbacks.successfulBonusClaim` | `(data) => {}`, called when the player claims a bonus (refresh your balance, for example). |
|
|
127
|
+
| `rewards.events.onJackpotWon` | `(data) => {}`, called when the player wins a jackpot. |
|
|
128
|
+
| `rewards.events.onWheelOpened` | `() => {}`, called when a wheel opens. |
|
|
129
|
+
| `rewards.gamesBaseUrl` | Where you serve `@fasttrack-solutions/rewards-games`. Unset: the mini games load from the Fast Track CDN. |
|
|
130
|
+
| `rewards.errorReporting` | `false` stops the SDK from reporting its own errors to Fast Track. On by default; it never reports your page's errors. |
|
|
131
|
+
|
|
132
|
+
## Functions and events
|
|
133
|
+
|
|
134
|
+
| On `window` | Description |
|
|
135
|
+
| --- | --- |
|
|
136
|
+
| `initFtRewards()` | Start, or reload, Rewards for the player in `window.ftcrm.auth`. |
|
|
137
|
+
| `logoutFtRewards()` | Log the player out; the components render nothing until the next login. |
|
|
138
|
+
| `updateFtJwtToken(jwt)` | Hand the SDK a refreshed JWT. |
|
|
139
|
+
| `pauseFtRewardsModals(pause)` | `true` holds back Rewards pop-ups (during a game round, for example); `false` lets them show. |
|
|
140
|
+
| `ftRewardsVersion` | The SDK version running on the page. |
|
|
141
|
+
| `ftRewardsError` | `null`, or `{ message, reason }` when the last start stopped. |
|
|
142
|
+
|
|
143
|
+
| Event on `window` | When |
|
|
144
|
+
| --- | --- |
|
|
145
|
+
| `ft-rewards-ready` | Rewards started and is on for this player. |
|
|
146
|
+
| `ft-config-error` | The start stopped. `event.detail.reason` is `'disabled'` (Rewards is off for this player), `'unauthenticated'` (the backend refused the token), or `'failed'`. Only `'failed'` is an error. |
|
|
147
|
+
| `ft-rewards-signed-out` | The player logged out. |
|
|
148
|
+
| `show-my-rewards` / `close-my-rewards` | The rewards modal opened or closed. |
|
|
149
|
+
|
|
150
|
+
The [front-end integration guide](https://www.fasttrack.ai/en/resources/integration/rewards/front-end-integration)
|
|
151
|
+
describes the components, their attributes and styling in full.
|
|
152
|
+
|
|
153
|
+
## Frameworks
|
|
154
|
+
|
|
155
|
+
The package starts Rewards when it is imported in a browser. Import it once, in code that
|
|
156
|
+
runs only in the browser, after the configuration:
|
|
157
|
+
|
|
158
|
+
- **Vite, webpack, plain bundles:** the two imports in your entry point, as in the quick start.
|
|
159
|
+
- **React, Next.js:** set the configuration and import the package in an effect of your root
|
|
160
|
+
component, so it only ever runs in the browser:
|
|
161
|
+
|
|
162
|
+
```jsx
|
|
163
|
+
useEffect(() => {
|
|
164
|
+
if (window.ftRewardsVersion) return;
|
|
165
|
+
window.fasttrackbrand = 'your-brand';
|
|
166
|
+
window.sid = playerJwt;
|
|
167
|
+
window.fasttrack = { /* as in the quick start */ };
|
|
168
|
+
import('@fasttrack-solutions/rewards');
|
|
169
|
+
}, []);
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Changes of player after that go through `onLogin` and `onLogout` above.
|
|
173
|
+
- **Nuxt:** a client-only plugin (`plugins/fasttrack.client.js`) with the two imports.
|
|
174
|
+
|
|
175
|
+
On a server (Node, Deno, edge runtimes, React Server Components) the import resolves to an
|
|
176
|
+
empty module, so server-rendered pages import it safely.
|
|
177
|
+
|
|
178
|
+
## Switching from the CDN script
|
|
179
|
+
|
|
180
|
+
Keep your `window.fasttrackbrand`, `window.sid` and `window.fasttrack` configuration, move it
|
|
181
|
+
into a module imported before the package (or keep it in a `<script>` before your bundle),
|
|
182
|
+
remove the Fast Track loader `<script>`, and import the package. The globals, the `ft-*`
|
|
183
|
+
elements and the events stay the same.
|
|
184
|
+
|
|
185
|
+
- Remove the loader when you switch. With both on the page, the loader starts Rewards a second
|
|
186
|
+
time, which reloads its data, reconnects and drops the player id from the first start.
|
|
187
|
+
- Import the package once per page. A second copy of the SDK, including the CDN build, does
|
|
188
|
+
nothing.
|
|
189
|
+
|
|
190
|
+
## Content-Security-Policy
|
|
191
|
+
|
|
192
|
+
The SDK adds its styles as `<style>` elements, so it needs `style-src 'unsafe-inline'`.
|
|
193
|
+
`connect-src` must allow your Fast Track API URL and its WebSocket, `img-src` the hosts your
|
|
194
|
+
operators put reward images on (and `https://crm-lib.fasttrack-solutions.com` for a few default
|
|
195
|
+
images), and `frame-src` the host of the mini games.
|
|
196
|
+
|
|
197
|
+
## What still leaves your site
|
|
198
|
+
|
|
199
|
+
API calls to your Fast Track instance and the Rewards backend, and images that operators
|
|
200
|
+
configure in the CRM (plus a few default images on the Fast Track CDN). No script.
|
|
201
|
+
|
|
202
|
+
## Versions
|
|
203
|
+
|
|
204
|
+
Each version is a Fast Track Rewards release, the same tag as the CDN build. `npm audit
|
|
205
|
+
signatures` verifies the registry signature.
|