@saasquatch/squatch-js 2.6.0 → 2.6.1

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 CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2023 ReferralSaaSquatch.com, Inc.
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
13
- all 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
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 ReferralSaaSquatch.com, Inc.
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
13
+ all 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
21
21
  THE SOFTWARE.
package/README.md CHANGED
@@ -1,259 +1,259 @@
1
- # Referral SaaSquatch Javascript SDK
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
- ## Install the library
19
-
20
- To integrate any SaaSquatch program to your website or web app, copy/paste this snippet of JavaScript above the `</head>` tag of your page:
21
-
22
- ```html
23
- <script type="text/javascript">
24
- !(function (a, b) {
25
- a("squatch", "https://fast.ssqt.io/squatch-js@2", b);
26
- })(function (a, b, c) {
27
- var d, e, f;
28
- (c["_" + a] = {}),
29
- (c[a] = {}),
30
- (c[a].ready = function (b) {
31
- c["_" + a].ready = c["_" + a].ready || [];
32
- c["_" + a].ready.push(b);
33
- }),
34
- (e = document.createElement("script")),
35
- (e.async = 1),
36
- (e.src = b),
37
- (f = document.getElementsByTagName("script")[0]),
38
- f.parentNode.insertBefore(e, f);
39
- }, this);
40
- </script>
41
- ```
42
-
43
- Or load the library synchronously from our CDN:
44
-
45
- ```html
46
- <script src="https://fast.ssqt.io/squatch-js@2" type="text/javascript"></script>
47
- ```
48
-
49
- ## Getting Started
50
-
51
- Include either of the squatchjs generated web-components in your page's HTML to render your desired widget:
52
-
53
- ```html
54
- <!-- EMBED WIDGET -->
55
- <squatch-embed widget="WIDGET_TYPE"
56
- ><!-- Widget is rendered here --></squatch-embed
57
- >
58
-
59
- <!-- POPUP WIDGET -->
60
- <squatch-popup widget="WIDGET_TYPE"
61
- ><!-- Widget is rendered here --></squatch-popup
62
- >
63
- ```
64
-
65
- For rendering widgets and API calls, squatchjs respects configurations set on the following:
66
-
67
- - `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)
68
- - `window.squatchTenant`: SaaSquatch tenant alias
69
- - `window.squatchConfig`: Additional configuration overrides (Optional)
70
- - `debug`: Turn on console debugging (Default: `false`)
71
- - `window.squatchOnReady`: Declarative on ready function to be run when the squatch-js module has finished loading
72
-
73
- ```html
74
- <script type="text/javascript">
75
- window.squatchOnReady = () => {
76
- squatch.widgets().upsertUser({
77
- user: { // Object (required)
78
- id: 'USER_ID', // String (required)
79
- accountId: 'USER_ACCOUNT_ID', // String (required)
80
- email: 'USER_EMAIL', // String (optional)
81
- firstName: 'USER_FIRST_NAME', // String (optional)
82
- lastName: 'USER_LAST_NAME', // String (optional)
83
-
84
- ...
85
- },
86
- engagementMedium: 'EMBED', // String (optional: POPUP, EMBED)
87
- widgetType: 'p/PROGRAM-ID/w/referrerWidget', // Update PROGRAM-ID
88
- });
89
- }
90
- </script>
91
- ```
92
-
93
- **Note**: If `window.squatchToken` is undefined, widgets will be rendered as [Instant Access widgets](https://docs.saasquatch.com/topics/widget-types#instant-access-widgets).
94
-
95
- ## Data Only Operations
96
-
97
- #### Create/upsert users without loading a widget.
98
-
99
- ```html
100
- <script type="text/javascript">
101
- // Assuming window.squatchTenant, and window.squatchToken are set
102
-
103
- squatch.ready(function() {
104
- var user;
105
-
106
- squatch.api().upsertUser({
107
- user: { // Object (required)
108
- id: 'USER_ID', // String (required)
109
- accountId: 'USER_ACCOUNT_ID', // String (required)
110
- email: 'USER_EMAIL', // String (optional)
111
- firstName: 'USER_FIRST_NAME', // String (optional)
112
- lastName: 'USER_LAST_NAME', // String (optional)
113
- ...
114
- },
115
- engagementMedium: 'EMBED', // String (optional: POPUP, EMBED)
116
- widgetType: 'p/PROGRAM-ID/w/referrerWidget', // Update PROGRAM-ID
117
- }).then(function(response) {
118
- user = response.user;
119
- }).catch(function(err){
120
- console.log(err);
121
- });
122
-
123
- // autofill
124
- var element = document.getElementById('my_coupon');
125
- element.value = user.referredBy.code;
126
-
127
- });
128
- </script>
129
- ```
130
-
131
- ## Get Referral Cookie Code
132
-
133
- You can also use the `api()` function to call the WidgetApi methods directly.
134
-
135
- ```html
136
- <script type="text/javascript">
137
- squatch.ready(function () {
138
- var element = document.getElementById("my_coupon");
139
-
140
- squatch
141
- .api()
142
- .squatchReferralCookie()
143
- .then(function (response) {
144
- /* `response.codes` looks like `{"program_id":"NEWCO", "friend_program":"BOB"}` */
145
-
146
- element.value = response.codes["program-id"];
147
- });
148
- });
149
- </script>
150
- ```
151
-
152
- Want more control? Visit our [guide](https://github.com/saasquatch/squatch-js/blob/master/docs/docs.md).
153
-
154
- ## Install via NPM and Webpack (advanced)
155
-
156
- Squatch.js can also be installed via NPM and bundled into your application with Webpack.
157
-
158
- ```ssh
159
- # via npm
160
- $ npm install @saasquatch/squatch-js
161
- ```
162
-
163
- ```js
164
- import * as squatch from "@saasquatch/squatch-js";
165
-
166
- // Always call init
167
- squatch.init({
168
- tenantAlias: "YOUR_TENANT_ALIAS" // String (required)
169
- });
170
-
171
- // Don't need to wait for .ready when importing via NPM/Webpack
172
- squatch.api().upsertUser({...});
173
-
174
- ```
175
-
176
- ## Component API:
177
-
178
- ### `squatch-embed`
179
-
180
- ```html
181
- <squatch-embed widget="WIDGET_TYPE" [ container="#selector" | locale="en_US" ]>
182
- <!-- Children of squatch-embed act as a loading state -->
183
- Loading...
184
- </squatch-embed>
185
- ```
186
-
187
- - `widget`: Specifies the SaaSquatch `widgetType` identifier of the desired widget
188
- - Required
189
- - Changing this attribute's value causes the widget to reload.
190
- - `container`: A CSS selector for a container element to use as the parent of the widget's iframe.
191
- - Default: `null`
192
- - Note, if no container is specified, the widget iframe will attach to the shadow DOM of `squatch-embed`.
193
- - `locale`: Locale that determines the widget translation displayed. Should be of the form "xx_XX".
194
- - Default: Browser's current locale
195
- - Changing this attribute's value causes the widget to reload.
196
-
197
- ### `squatch-popup`
198
-
199
- ```html
200
- <squatch-embed
201
- widget="WIDGET_TYPE"
202
- [
203
- open
204
- |
205
- container="#selector"
206
- |
207
- locale="en_US"
208
- ]
209
- >
210
- <!-- Clicking a child of squatch-popup opens the popup -->
211
- <button>Click me to open</button>
212
- </squatch-embed>
213
- ```
214
-
215
- - `widget: string`: Specifies the SaaSquatch `widgetType` identifier of the desired widget
216
- - Required
217
- - `open: boolean`: Whether to the popup is open when loaded into the page
218
- - Default: `false`
219
- - `container`: A CSS selector for a container element to use as the parent of the widget's iframe.
220
- - Default: `null`
221
- - Note, if no container is specified, the widget iframe will attach to the shadow DOM of `squatch-embed`.
222
- - `locale`: Locale that determines the widget translation displayed. Should be of the form "xx_XX".
223
- - Default: Browser's current locale
224
- - Changing this attribute's value causes the widget to reload.
225
-
226
- ## Legacy
227
-
228
- ### Rendering a widget via Widgets API
229
-
230
- 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.
231
-
232
- ```html
233
- <script type="text/javascript">
234
- squatch.ready(function() {
235
-
236
- squatch.widgets().upsertUser({
237
- user: { // Object (required)
238
- id: 'USER_ID', // String (required)
239
- accountId: 'USER_ACCOUNT_ID', // String (required)
240
- email: 'USER_EMAIL', // String (optional)
241
- firstName: 'USER_FIRST_NAME', // String (optional)
242
- lastName: 'USER_LAST_NAME', // String (optional)
243
-
244
- ...
245
- },
246
- engagementMedium: 'EMBED', // String (optional: POPUP, EMBED)
247
- widgetType: 'p/PROGRAM-ID/w/referrerWidget', // Update PROGRAM-ID
248
- });
249
- });
250
- </script>
251
- ```
252
-
253
- ## Contributing
254
-
255
- This is an open source project! If you are interested in contributing please look at [contributing guidelines](CONTRIBUTING.md) first.
256
-
257
- ## Support
258
-
259
- Shoot us an email at [support@saasqt.ch](mailto:support@saasqt.ch) if you need help!
1
+ # Referral SaaSquatch Javascript SDK
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
+ ## Install the library
19
+
20
+ To integrate any SaaSquatch program to your website or web app, copy/paste this snippet of JavaScript above the `</head>` tag of your page:
21
+
22
+ ```html
23
+ <script type="text/javascript">
24
+ !(function (a, b) {
25
+ a("squatch", "https://fast.ssqt.io/squatch-js@2", b);
26
+ })(function (a, b, c) {
27
+ var d, e, f;
28
+ (c["_" + a] = {}),
29
+ (c[a] = {}),
30
+ (c[a].ready = function (b) {
31
+ c["_" + a].ready = c["_" + a].ready || [];
32
+ c["_" + a].ready.push(b);
33
+ }),
34
+ (e = document.createElement("script")),
35
+ (e.async = 1),
36
+ (e.src = b),
37
+ (f = document.getElementsByTagName("script")[0]),
38
+ f.parentNode.insertBefore(e, f);
39
+ }, this);
40
+ </script>
41
+ ```
42
+
43
+ Or load the library synchronously from our CDN:
44
+
45
+ ```html
46
+ <script src="https://fast.ssqt.io/squatch-js@2" type="text/javascript"></script>
47
+ ```
48
+
49
+ ## Getting Started
50
+
51
+ Include either of the squatchjs generated web-components in your page's HTML to render your desired widget:
52
+
53
+ ```html
54
+ <!-- EMBED WIDGET -->
55
+ <squatch-embed widget="WIDGET_TYPE"
56
+ ><!-- Widget is rendered here --></squatch-embed
57
+ >
58
+
59
+ <!-- POPUP WIDGET -->
60
+ <squatch-popup widget="WIDGET_TYPE"
61
+ ><!-- Widget is rendered here --></squatch-popup
62
+ >
63
+ ```
64
+
65
+ For rendering widgets and API calls, squatchjs respects configurations set on the following:
66
+
67
+ - `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)
68
+ - `window.squatchTenant`: SaaSquatch tenant alias
69
+ - `window.squatchConfig`: Additional configuration overrides (Optional)
70
+ - `debug`: Turn on console debugging (Default: `false`)
71
+ - `window.squatchOnReady`: Declarative on ready function to be run when the squatch-js module has finished loading
72
+
73
+ ```html
74
+ <script type="text/javascript">
75
+ window.squatchOnReady = () => {
76
+ squatch.widgets().upsertUser({
77
+ user: { // Object (required)
78
+ id: 'USER_ID', // String (required)
79
+ accountId: 'USER_ACCOUNT_ID', // String (required)
80
+ email: 'USER_EMAIL', // String (optional)
81
+ firstName: 'USER_FIRST_NAME', // String (optional)
82
+ lastName: 'USER_LAST_NAME', // String (optional)
83
+
84
+ ...
85
+ },
86
+ engagementMedium: 'EMBED', // String (optional: POPUP, EMBED)
87
+ widgetType: 'p/PROGRAM-ID/w/referrerWidget', // Update PROGRAM-ID
88
+ });
89
+ }
90
+ </script>
91
+ ```
92
+
93
+ **Note**: If `window.squatchToken` is undefined, widgets will be rendered as [Instant Access widgets](https://docs.saasquatch.com/topics/widget-types#instant-access-widgets).
94
+
95
+ ## Data Only Operations
96
+
97
+ #### Create/upsert users without loading a widget.
98
+
99
+ ```html
100
+ <script type="text/javascript">
101
+ // Assuming window.squatchTenant, and window.squatchToken are set
102
+
103
+ squatch.ready(function() {
104
+ var user;
105
+
106
+ squatch.api().upsertUser({
107
+ user: { // Object (required)
108
+ id: 'USER_ID', // String (required)
109
+ accountId: 'USER_ACCOUNT_ID', // String (required)
110
+ email: 'USER_EMAIL', // String (optional)
111
+ firstName: 'USER_FIRST_NAME', // String (optional)
112
+ lastName: 'USER_LAST_NAME', // String (optional)
113
+ ...
114
+ },
115
+ engagementMedium: 'EMBED', // String (optional: POPUP, EMBED)
116
+ widgetType: 'p/PROGRAM-ID/w/referrerWidget', // Update PROGRAM-ID
117
+ }).then(function(response) {
118
+ user = response.user;
119
+ }).catch(function(err){
120
+ console.log(err);
121
+ });
122
+
123
+ // autofill
124
+ var element = document.getElementById('my_coupon');
125
+ element.value = user.referredBy.code;
126
+
127
+ });
128
+ </script>
129
+ ```
130
+
131
+ ## Get Referral Cookie Code
132
+
133
+ You can also use the `api()` function to call the WidgetApi methods directly.
134
+
135
+ ```html
136
+ <script type="text/javascript">
137
+ squatch.ready(function () {
138
+ var element = document.getElementById("my_coupon");
139
+
140
+ squatch
141
+ .api()
142
+ .squatchReferralCookie()
143
+ .then(function (response) {
144
+ /* `response.codes` looks like `{"program_id":"NEWCO", "friend_program":"BOB"}` */
145
+
146
+ element.value = response.codes["program-id"];
147
+ });
148
+ });
149
+ </script>
150
+ ```
151
+
152
+ Want more control? Visit our [guide](https://github.com/saasquatch/squatch-js/blob/master/docs/docs.md).
153
+
154
+ ## Install via NPM and Webpack (advanced)
155
+
156
+ Squatch.js can also be installed via NPM and bundled into your application with Webpack.
157
+
158
+ ```ssh
159
+ # via npm
160
+ $ npm install @saasquatch/squatch-js
161
+ ```
162
+
163
+ ```js
164
+ import * as squatch from "@saasquatch/squatch-js";
165
+
166
+ // Always call init
167
+ squatch.init({
168
+ tenantAlias: "YOUR_TENANT_ALIAS" // String (required)
169
+ });
170
+
171
+ // Don't need to wait for .ready when importing via NPM/Webpack
172
+ squatch.api().upsertUser({...});
173
+
174
+ ```
175
+
176
+ ## Component API:
177
+
178
+ ### `squatch-embed`
179
+
180
+ ```html
181
+ <squatch-embed widget="WIDGET_TYPE" [ container="#selector" | locale="en_US" ]>
182
+ <!-- Children of squatch-embed act as a loading state -->
183
+ Loading...
184
+ </squatch-embed>
185
+ ```
186
+
187
+ - `widget`: Specifies the SaaSquatch `widgetType` identifier of the desired widget
188
+ - Required
189
+ - Changing this attribute's value causes the widget to reload.
190
+ - `container`: A CSS selector for a container element to use as the parent of the widget's iframe.
191
+ - Default: `null`
192
+ - Note, if no container is specified, the widget iframe will attach to the shadow DOM of `squatch-embed`.
193
+ - `locale`: Locale that determines the widget translation displayed. Should be of the form "xx_XX".
194
+ - Default: Browser's current locale
195
+ - Changing this attribute's value causes the widget to reload.
196
+
197
+ ### `squatch-popup`
198
+
199
+ ```html
200
+ <squatch-embed
201
+ widget="WIDGET_TYPE"
202
+ [
203
+ open
204
+ |
205
+ container="#selector"
206
+ |
207
+ locale="en_US"
208
+ ]
209
+ >
210
+ <!-- Clicking a child of squatch-popup opens the popup -->
211
+ <button>Click me to open</button>
212
+ </squatch-embed>
213
+ ```
214
+
215
+ - `widget: string`: Specifies the SaaSquatch `widgetType` identifier of the desired widget
216
+ - Required
217
+ - `open: boolean`: Whether to the popup is open when loaded into the page
218
+ - Default: `false`
219
+ - `container`: A CSS selector for a container element to use as the parent of the widget's iframe.
220
+ - Default: `null`
221
+ - Note, if no container is specified, the widget iframe will attach to the shadow DOM of `squatch-embed`.
222
+ - `locale`: Locale that determines the widget translation displayed. Should be of the form "xx_XX".
223
+ - Default: Browser's current locale
224
+ - Changing this attribute's value causes the widget to reload.
225
+
226
+ ## Legacy
227
+
228
+ ### Rendering a widget via Widgets API
229
+
230
+ 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.
231
+
232
+ ```html
233
+ <script type="text/javascript">
234
+ squatch.ready(function() {
235
+
236
+ squatch.widgets().upsertUser({
237
+ user: { // Object (required)
238
+ id: 'USER_ID', // String (required)
239
+ accountId: 'USER_ACCOUNT_ID', // String (required)
240
+ email: 'USER_EMAIL', // String (optional)
241
+ firstName: 'USER_FIRST_NAME', // String (optional)
242
+ lastName: 'USER_LAST_NAME', // String (optional)
243
+
244
+ ...
245
+ },
246
+ engagementMedium: 'EMBED', // String (optional: POPUP, EMBED)
247
+ widgetType: 'p/PROGRAM-ID/w/referrerWidget', // Update PROGRAM-ID
248
+ });
249
+ });
250
+ </script>
251
+ ```
252
+
253
+ ## Contributing
254
+
255
+ This is an open source project! If you are interested in contributing please look at [contributing guidelines](CONTRIBUTING.md) first.
256
+
257
+ ## Support
258
+
259
+ Shoot us an email at [support@saasqt.ch](mailto:support@saasqt.ch) if you need help!
package/babel.config.js CHANGED
@@ -1,8 +1,8 @@
1
- module.exports = {
2
- presets: [
3
- [
4
- "@babel/preset-env",
5
- { targets: { esmodules: true }}
6
- ]
7
- ]
1
+ module.exports = {
2
+ presets: [
3
+ [
4
+ "@babel/preset-env",
5
+ { targets: { esmodules: true }}
6
+ ]
7
+ ]
8
8
  }