@saasquatch/squatch-js 2.5.1-9 → 2.6.0-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/.github/workflows/size-limit.yml +15 -0
- package/CHANGELOG.md +326 -334
- package/LICENSE +20 -20
- package/README.md +180 -145
- package/babel.config.js +8 -0
- package/coverage/clover.xml +888 -0
- package/coverage/coverage-final.json +23 -0
- package/coverage/lcov-report/api/AnalyticsApi.ts.html +304 -0
- package/coverage/lcov-report/api/WidgetApi.ts.html +628 -0
- package/coverage/lcov-report/api/graphql.ts.html +130 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov-report/utils/cookieUtils.ts.html +415 -0
- package/coverage/lcov-report/utils/decodeUserJwt.ts.html +133 -0
- package/coverage/lcov-report/utils/domready.ts.html +160 -0
- package/coverage/lcov-report/utils/io.ts.html +385 -0
- package/coverage/lcov-report/utils/utmUtils.ts.html +277 -0
- package/coverage/lcov-report/utils/validate.ts.html +268 -0
- package/coverage/lcov-report/validate.ts.html +268 -0
- package/coverage/lcov-report/widgets/EmbedWidget.ts.html +436 -0
- package/coverage/lcov-report/widgets/PopupWidget.ts.html +625 -0
- package/coverage/lcov-report/widgets/Widget.ts.html +1108 -0
- package/coverage/lcov-report/widgets/declarative/DeclarativeWidget.ts.html +499 -0
- package/coverage/lcov.info +1628 -0
- package/demo/sandbox.ts +124 -124
- package/demo/toolbar.tsx +526 -526
- package/dist/api/AnalyticsApi.d.ts +32 -32
- package/dist/api/EventsApi.d.ts +52 -52
- package/dist/api/WidgetApi.d.ts +63 -80
- package/dist/api/graphql.d.ts +1 -1
- package/dist/async.d.ts +15 -11
- package/dist/docs.d.ts +1 -1
- package/dist/squatch.d.ts +108 -108
- package/dist/squatch.esm.js +1105 -1417
- package/dist/squatch.esm.js.map +1 -1
- package/dist/squatch.js +1105 -1438
- package/dist/squatch.js.map +1 -1
- package/dist/squatch.min.js +2 -13
- package/dist/squatch.min.js.LICENSE.txt +6 -0
- package/dist/squatch.min.js.map +1 -1
- package/dist/squatch.modern.js +1 -1
- package/dist/squatch.modern.js.map +1 -1
- package/dist/stats.html +1 -1
- package/dist/types.d.ts +107 -106
- package/dist/utils/cookieUtils.d.ts +2 -2
- package/dist/utils/decodeUserJwt.d.ts +2 -0
- package/dist/utils/domUtils.d.ts +1 -0
- package/dist/utils/domready.d.ts +6 -6
- package/dist/utils/io.d.ts +5 -13
- package/dist/utils/loadEvent.d.ts +2 -0
- package/dist/utils/utmUtils.d.ts +14 -14
- package/dist/utils/validate.d.ts +12 -16
- package/dist/widgets/EmbedWidget.d.ts +16 -15
- package/dist/widgets/IREmbedWidget.d.ts +29 -0
- package/dist/widgets/IRPopupWidget.d.ts +32 -0
- package/dist/widgets/PopupWidget.d.ts +25 -23
- package/dist/widgets/Widget.d.ts +53 -33
- package/dist/widgets/Widgets.d.ts +108 -116
- package/dist/widgets/declarative/DeclarativeEmbedWidget.d.ts +12 -0
- package/dist/widgets/declarative/DeclarativeWidget.d.ts +32 -0
- package/dist/widgets/declarative/DeclarativeWidgets.d.ts +13 -0
- package/jest.config.ts +202 -0
- package/package.json +123 -105
- package/stats.json +1 -0
- package/tsconfig.json +2 -2
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,145 +1,180 @@
|
|
|
1
|
-
# Referral SaaSquatch Javascript SDK
|
|
2
|
-
|
|
3
|
-
## Install the library
|
|
4
|
-
|
|
5
|
-
To integrate any SaaSquatch program to your website or web app, copy/paste this snippet of JavaScript above the `</head>` tag of your page:
|
|
6
|
-
|
|
7
|
-
```html
|
|
8
|
-
<script type="text/javascript">
|
|
9
|
-
!function(a,b){a("squatch","https://fast.ssqt.io/squatch-js@2",b)}(function(a,b,c){var d,e,f;c["_"+a]={},c[a]={},c[a].ready=function(b){c["_" + a].ready = c["_" + a].ready || [];c["_" + a].ready.push(b);},e=document.createElement("script"),e.async=1,e.src=b,f=document.getElementsByTagName("script")[0],f.parentNode.insertBefore(e,f)},this);
|
|
10
|
-
</script>
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
Or load the library synchronously from our CDN:
|
|
14
|
-
|
|
15
|
-
```html
|
|
16
|
-
<script src="https://fast.ssqt.io/squatch-js@2" type="text/javascript"></script>
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
## 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
|
-
|
|
25
|
-
```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)
|
|
47
|
-
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
</script>
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
1
|
+
# Referral SaaSquatch Javascript SDK
|
|
2
|
+
|
|
3
|
+
## Install the library
|
|
4
|
+
|
|
5
|
+
To integrate any SaaSquatch program to your website or web app, copy/paste this snippet of JavaScript above the `</head>` tag of your page:
|
|
6
|
+
|
|
7
|
+
```html
|
|
8
|
+
<script type="text/javascript">
|
|
9
|
+
!function(a,b){a("squatch","https://fast.ssqt.io/squatch-js@2",b)}(function(a,b,c){var d,e,f;c["_"+a]={},c[a]={},c[a].ready=function(b){c["_" + a].ready = c["_" + a].ready || [];c["_" + a].ready.push(b);},e=document.createElement("script"),e.async=1,e.src=b,f=document.getElementsByTagName("script")[0],f.parentNode.insertBefore(e,f)},this);
|
|
10
|
+
</script>
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or load the library synchronously from our CDN:
|
|
14
|
+
|
|
15
|
+
```html
|
|
16
|
+
<script src="https://fast.ssqt.io/squatch-js@2" type="text/javascript"></script>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
## 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
|
+
|
|
25
|
+
```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)
|
|
47
|
+
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
</script>
|
|
51
|
+
```
|
|
52
|
+
|
|
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.
|
|
55
|
+
|
|
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
|
+
|
|
63
|
+
// Optional
|
|
64
|
+
window.squatchConfig = {
|
|
65
|
+
... // Custom configuration settings
|
|
66
|
+
}
|
|
67
|
+
</script>
|
|
68
|
+
|
|
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
|
+
|
|
73
|
+
#### `squatch-embed`
|
|
74
|
+
|
|
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`.
|
|
80
|
+
|
|
81
|
+
|
|
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.
|
|
90
|
+
|
|
91
|
+
```html
|
|
92
|
+
<script type="text/javascript">
|
|
93
|
+
squatch.ready(function() {
|
|
94
|
+
|
|
95
|
+
// Always call init
|
|
96
|
+
squatch.init({
|
|
97
|
+
tenantAlias: "YOUR_TENANT_ALIAS" // String (required)
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
var user;
|
|
101
|
+
|
|
102
|
+
squatch.api().upsertUser({
|
|
103
|
+
user: { // Object (required)
|
|
104
|
+
id: 'USER_ID', // String (required)
|
|
105
|
+
accountId: 'USER_ACCOUNT_ID', // String (required)
|
|
106
|
+
email: 'USER_EMAIL', // String (optional)
|
|
107
|
+
firstName: 'USER_FIRST_NAME', // String (optional)
|
|
108
|
+
lastName: 'USER_LAST_NAME', // String (optional)
|
|
109
|
+
...
|
|
110
|
+
},
|
|
111
|
+
engagementMedium: 'EMBED', // String (optional: POPUP, EMBED)
|
|
112
|
+
widgetType: 'p/PROGRAM-ID/w/referrerWidget', // Update PROGRAM-ID
|
|
113
|
+
jwt: 'TOKEN' // String (required)
|
|
114
|
+
}).then(function(response) {
|
|
115
|
+
user = response.user;
|
|
116
|
+
}).catch(function(err){
|
|
117
|
+
console.log(err);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// autofill
|
|
121
|
+
var element = document.getElementById('my_coupon');
|
|
122
|
+
element.value = user.referredBy.code;
|
|
123
|
+
|
|
124
|
+
});
|
|
125
|
+
</script>
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Get Referral Cookie Code
|
|
129
|
+
You can also use the `api()` function to call the WidgetApi methods directly.
|
|
130
|
+
|
|
131
|
+
```html
|
|
132
|
+
<script type="text/javascript">
|
|
133
|
+
squatch.ready(function(){
|
|
134
|
+
|
|
135
|
+
// Always call init
|
|
136
|
+
squatch.init({tenantAlias: 'YOUR_TENANT_ALIAS'});
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
var element = document.getElementById('my_coupon');
|
|
140
|
+
|
|
141
|
+
squatch.api().squatchReferralCookie().then(function(response) {
|
|
142
|
+
/* `response.codes` looks like `{"program_id":"NEWCO", "friend_program":"BOB"}` */
|
|
143
|
+
|
|
144
|
+
element.value = response.codes["program-id"];
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
});
|
|
148
|
+
</script>
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Want more control? Visit our [guide](https://github.com/saasquatch/squatch-js/blob/master/docs/docs.md).
|
|
152
|
+
|
|
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
|
+
## Contributing
|
|
177
|
+
This is an open source project! If you are interested in contributing please look at [contributing guidelines](CONTRIBUTING.md) first.
|
|
178
|
+
|
|
179
|
+
## Support
|
|
180
|
+
Shoot us an email at [support@saasqt.ch](mailto:support@saasqt.ch) if you need help!
|