@fasttrack-solutions/rewards 0.0.0 → 1.44.0-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 CHANGED
@@ -1,3 +1,64 @@
1
1
  # @fasttrack-solutions/rewards
2
2
 
3
- Reserved. The first real version is published from CI.
3
+ The Fast Track Rewards SDK and its `ft-*` web components, for sites that bundle their
4
+ JavaScript instead of loading the SDK from the Fast Track CDN. It is the same production
5
+ build as `https://crm-lib.fasttrack-solutions.com/wc/rewards-main.js`, and it loads no code
6
+ from the CDN: the mini-game engine (wheel and sounds) ships inside the package as its own
7
+ chunk, which your bundler splits out and serves with the rest of your site.
8
+
9
+ ## Use
10
+
11
+ Keep your configuration exactly as it is today, in a module of its own that you import
12
+ before the package (ES imports run before the code around them, and the SDK reads some
13
+ settings, such as `rewards.callbacks`, as it loads), and import the package where you used
14
+ to add the loader script:
15
+
16
+ ```js
17
+ // fasttrack-config.js
18
+ window.fasttrackbrand = 'your-brand';
19
+ window.sid = '<JWT for the logged-in player>';
20
+ window.fasttrack = {
21
+ baseUrl: 'https://your-brand.ft-crm.com',
22
+ enableJWT: true,
23
+ integrationVersion: 2.0,
24
+ autoInit: true,
25
+ rewards: { enable: true },
26
+ };
27
+ ```
28
+
29
+ ```js
30
+ import './fasttrack-config.js';
31
+ import '@fasttrack-solutions/rewards';
32
+ ```
33
+
34
+ A `<script>` that sets the same globals before your bundle works too.
35
+
36
+ Everything else works as documented in the
37
+ [front-end integration guide](https://www.fasttrack.ai/en/resources/integration/rewards/front-end-integration):
38
+ `<ft-my-rewards-toggle>` and the other components, `window.initFtRewards()`,
39
+ `window.logoutFtRewards()`, `window.updateFtJwtToken(token)`, `window.ftRewardsVersion`
40
+ and the `ft-config-error` event.
41
+
42
+ - Import the package once per page. A second copy of the SDK, including the CDN build
43
+ (`wc/rewards-main.js`), does nothing.
44
+ - Remove the CDN loader script when you switch. The loader is not a copy of the SDK: with
45
+ both on the page it starts Rewards a second time, which reloads its data, reconnects and
46
+ drops the player id from the first start.
47
+ - Set `window.sid` before the page's `DOMContentLoaded`, which is when the package starts
48
+ Rewards. When the player logs in later, set `window.sid` and then call
49
+ `window.initFtRewards()`.
50
+ - On a server (Next.js, Nuxt, Vite SSR) the import resolves to an empty module through
51
+ the `node` export condition; the SDK starts in the browser.
52
+ - The standalone games (`<ft-game-launcher>`) still load from the CDN unless you serve
53
+ [`@fasttrack-solutions/rewards-games`](https://www.npmjs.com/package/@fasttrack-solutions/rewards-games)
54
+ yourself and set `window.fasttrack.rewards.gamesBaseUrl`.
55
+
56
+ ## What still leaves your site
57
+
58
+ API calls to your Fast Track instance and the Rewards backend, and images that operators
59
+ configure in the CRM (plus a few default images on the Fast Track CDN). No script.
60
+
61
+ ## Versions
62
+
63
+ Each version is a Fast Track Rewards release: the same tag as the CDN build, published
64
+ from CI by npm trusted publishing. `npm audit signatures` verifies the registry signature.