@saasquatch/squatch-js 2.6.0-0 → 2.6.0-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
@@ -1,5 +1,21 @@
1
1
  # Referral SaaSquatch Javascript SDK
2
2
 
3
+ - [Referral SaaSquatch Javascript SDK](#referral-saasquatch-javascript-sdk)
4
+ - [Install the library](#install-the-library)
5
+ - [Getting Started](#getting-started)
6
+ - [Data Only Operations](#data-only-operations)
7
+ - [Create/upsert users without loading a widget.](#createupsert-users-without-loading-a-widget)
8
+ - [Get Referral Cookie Code](#get-referral-cookie-code)
9
+ - [Install via NPM and Webpack (advanced)](#install-via-npm-and-webpack-advanced)
10
+ - [Component API:](#component-api)
11
+ - [`squatch-embed`](#squatch-embed)
12
+ - [`squatch-popup`](#squatch-popup)
13
+ - [Legacy](#legacy)
14
+ - [Rendering a widget via Widgets API](#rendering-a-widget-via-widgets-api)
15
+ - [Contributing](#contributing)
16
+ - [Support](#support)
17
+
18
+
3
19
  ## Install the library
4
20
 
5
21
  To integrate any SaaSquatch program to your website or web app, copy/paste this snippet of JavaScript above the `</head>` tag of your page:
@@ -18,85 +34,37 @@ Or load the library synchronously from our CDN:
18
34
 
19
35
 
20
36
  ## Getting Started
21
- The `init` function lets you configure your global squatch instance.
22
-
23
- Note: `engagementMedium` is required in the `squatch.widgets()` functions if you want to load the widget. Otherwise, Squatch.js will look for your portal settings and render the widget that's mapped to the URL where this snippet is included.
24
37
 
38
+ Include either of the squatchjs generated web-components in your page's HTML to render your desired widget:
25
39
  ```html
26
- <script type="text/javascript">
27
- squatch.ready(function() {
28
-
29
- // Always call init
30
- squatch.init({
31
- tenantAlias: "YOUR_TENANT_ALIAS", // String (required)
32
- });
33
-
34
- squatch.widgets().upsertUser({
35
- user: { // Object (required)
36
- id: 'USER_ID', // String (required)
37
- accountId: 'USER_ACCOUNT_ID', // String (required)
38
- email: 'USER_EMAIL', // String (optional)
39
- firstName: 'USER_FIRST_NAME', // String (optional)
40
- lastName: 'USER_LAST_NAME', // String (optional)
41
-
42
- ...
43
- },
44
- engagementMedium: 'EMBED', // String (optional: POPUP, EMBED)
45
- widgetType: 'p/PROGRAM-ID/w/referrerWidget', // Update PROGRAM-ID
46
- jwt: 'TOKEN' // String (required by default, or disable Security in the portal)
40
+ <!-- EMBED WIDGET -->
41
+ <squatch-embed widget="WIDGET_TYPE"><!-- Widget is rendered here --></squatch-embed>
47
42
 
48
- });
49
- });
50
- </script>
43
+ <!-- POPUP WIDGET -->
44
+ <squatch-popup widget="WIDGET_TYPE"><!-- Widget is rendered here --></squatch-popup>
51
45
  ```
46
+ For rendering widgets and API calls, Squatchjs respects configurations set on the following:
47
+ - `window.squatchToken`: Signed JWT for calls to the SaaSquatch API -- [How to generate valid JWT Tokens](https://docs.saasquatch.com/topics/json-web-tokens#example-building-the-jwt)
48
+ - `window.squatchTenant`: SaaSquatch tenant alias
49
+ - `window.squatchConfig`: Additional configuration overrides (Optional)
50
+ - `debug`: Turn on console debugging (Default: `false`)
52
51
 
53
- ### Declarative method for rendering widgets
54
- As opposed to the above method which requires some manual javascript, squatchjs includes the custom Web Components: `squatch-embed` and `squatch-popup` that can render embedded and popup widgets respectively.
52
+ **Note**: If `window.squatchToken` is undefined, widgets will be rendered as [Instant Access widgets](https://docs.saasquatch.com/topics/widget-types#instant-access-widgets).
55
53
 
56
- TODO: `display: inline` until squatchjs loads
57
-
58
- ```html
59
- <script type="text/javascript">
60
- window.squatchToken = "TOKEN"
61
- window.squatchTenant = "TENANT_ALIAS"
62
54
 
63
- // Optional
64
- window.squatchConfig = {
65
- ... // Custom configuration settings
66
- }
67
- </script>
68
55
 
69
- <squatch-embed widget="WIDGET_TYPE"><!-- Widget is rendered here --></squatch-embed>
70
- <squatch-popup widget="WIDGET_TYPE"><!-- Widget is rendered here --></squatch-popup>
71
- ```
72
56
 
73
- #### `squatch-embed`
74
57
 
75
- - `widget`: Specifies the SaaSquatch `widgetType` identifier of the desired widget
76
- - Required
77
- - `container`: A CSS selector for a container element to use as the parent of the widget's iframe.
78
- - Default: `null`
79
- - Note, if no container is specified, the widget iframe will attach to the shadow DOM of `squatch-embed`.
58
+ ## Data Only Operations
80
59
 
81
60
 
82
- #### `squatch-popup`
83
-
84
- - `widget: string`: Specifies the SaaSquatch `widgetType` identifier of the desired widget
85
- - Required
86
- - `show: boolean`: Whether to show the popup dialog on page load or not.
87
- - Default: `false`
88
- ## Data Only Operations
89
- You can create/upsert users without loading a widget.
61
+ #### Create/upsert users without loading a widget.
90
62
 
91
63
  ```html
92
64
  <script type="text/javascript">
93
- squatch.ready(function() {
94
-
95
- // Always call init
96
- squatch.init({
97
- tenantAlias: "YOUR_TENANT_ALIAS" // String (required)
98
- });
65
+ // Assuming window.squatchTenant, and window.squatchToken are set
99
66
 
67
+ squatch.ready(function() {
100
68
  var user;
101
69
 
102
70
  squatch.api().upsertUser({
@@ -110,7 +78,6 @@ You can create/upsert users without loading a widget.
110
78
  },
111
79
  engagementMedium: 'EMBED', // String (optional: POPUP, EMBED)
112
80
  widgetType: 'p/PROGRAM-ID/w/referrerWidget', // Update PROGRAM-ID
113
- jwt: 'TOKEN' // String (required)
114
81
  }).then(function(response) {
115
82
  user = response.user;
116
83
  }).catch(function(err){
@@ -132,10 +99,6 @@ You can also use the `api()` function to call the WidgetApi methods directly.
132
99
  <script type="text/javascript">
133
100
  squatch.ready(function(){
134
101
 
135
- // Always call init
136
- squatch.init({tenantAlias: 'YOUR_TENANT_ALIAS'});
137
-
138
-
139
102
  var element = document.getElementById('my_coupon');
140
103
 
141
104
  squatch.api().squatchReferralCookie().then(function(response) {
@@ -173,6 +136,62 @@ squatch.api().upsertUser({...});
173
136
 
174
137
  ```
175
138
 
139
+ ## Component API:
140
+
141
+ ### `squatch-embed`
142
+ ```html
143
+ <squatch-embed widget="WIDGET_TYPE" [ container="#selector" ]>
144
+ <!-- Children of squatch-embed act as a loading state -->
145
+ Loading...
146
+ </squatch-embed>
147
+ ```
148
+
149
+ - `widget`: Specifies the SaaSquatch `widgetType` identifier of the desired widget
150
+ - Required
151
+ - `container`: A CSS selector for a container element to use as the parent of the widget's iframe.
152
+ - Default: `null`
153
+ - Note, if no container is specified, the widget iframe will attach to the shadow DOM of `squatch-embed`.
154
+
155
+
156
+ ### `squatch-popup`
157
+ ```html
158
+ <squatch-embed widget="WIDGET_TYPE" [ open ]>
159
+ <!-- Clicking a child of squatch-popup opens the popup -->
160
+ <button>Click me to open</button>
161
+ </squatch-embed>
162
+ ```
163
+
164
+ - `widget: string`: Specifies the SaaSquatch `widgetType` identifier of the desired widget
165
+ - Required
166
+ - `open: boolean`: Whether to the popup is open when loaded into the page
167
+ - Default: `false`
168
+
169
+ ## Legacy
170
+
171
+ ### Rendering a widget via Widgets API
172
+ Note: `engagementMedium` is required in the `squatch.widgets()` functions if you want to load the widget. Otherwise, Squatch.js will look for your portal settings and render the widget that's mapped to the URL where this snippet is included.
173
+
174
+ ```html
175
+ <script type="text/javascript">
176
+ squatch.ready(function() {
177
+
178
+ squatch.widgets().upsertUser({
179
+ user: { // Object (required)
180
+ id: 'USER_ID', // String (required)
181
+ accountId: 'USER_ACCOUNT_ID', // String (required)
182
+ email: 'USER_EMAIL', // String (optional)
183
+ firstName: 'USER_FIRST_NAME', // String (optional)
184
+ lastName: 'USER_LAST_NAME', // String (optional)
185
+
186
+ ...
187
+ },
188
+ engagementMedium: 'EMBED', // String (optional: POPUP, EMBED)
189
+ widgetType: 'p/PROGRAM-ID/w/referrerWidget', // Update PROGRAM-ID
190
+ });
191
+ });
192
+ </script>
193
+ ```
194
+
176
195
  ## Contributing
177
196
  This is an open source project! If you are interested in contributing please look at [contributing guidelines](CONTRIBUTING.md) first.
178
197