@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.
Files changed (70) hide show
  1. package/.github/workflows/size-limit.yml +15 -0
  2. package/CHANGELOG.md +326 -334
  3. package/LICENSE +20 -20
  4. package/README.md +180 -145
  5. package/babel.config.js +8 -0
  6. package/coverage/clover.xml +888 -0
  7. package/coverage/coverage-final.json +23 -0
  8. package/coverage/lcov-report/api/AnalyticsApi.ts.html +304 -0
  9. package/coverage/lcov-report/api/WidgetApi.ts.html +628 -0
  10. package/coverage/lcov-report/api/graphql.ts.html +130 -0
  11. package/coverage/lcov-report/base.css +224 -0
  12. package/coverage/lcov-report/block-navigation.js +87 -0
  13. package/coverage/lcov-report/favicon.png +0 -0
  14. package/coverage/lcov-report/prettify.css +1 -0
  15. package/coverage/lcov-report/prettify.js +2 -0
  16. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  17. package/coverage/lcov-report/sorter.js +196 -0
  18. package/coverage/lcov-report/utils/cookieUtils.ts.html +415 -0
  19. package/coverage/lcov-report/utils/decodeUserJwt.ts.html +133 -0
  20. package/coverage/lcov-report/utils/domready.ts.html +160 -0
  21. package/coverage/lcov-report/utils/io.ts.html +385 -0
  22. package/coverage/lcov-report/utils/utmUtils.ts.html +277 -0
  23. package/coverage/lcov-report/utils/validate.ts.html +268 -0
  24. package/coverage/lcov-report/validate.ts.html +268 -0
  25. package/coverage/lcov-report/widgets/EmbedWidget.ts.html +436 -0
  26. package/coverage/lcov-report/widgets/PopupWidget.ts.html +625 -0
  27. package/coverage/lcov-report/widgets/Widget.ts.html +1108 -0
  28. package/coverage/lcov-report/widgets/declarative/DeclarativeWidget.ts.html +499 -0
  29. package/coverage/lcov.info +1628 -0
  30. package/demo/sandbox.ts +124 -124
  31. package/demo/toolbar.tsx +526 -526
  32. package/dist/api/AnalyticsApi.d.ts +32 -32
  33. package/dist/api/EventsApi.d.ts +52 -52
  34. package/dist/api/WidgetApi.d.ts +63 -80
  35. package/dist/api/graphql.d.ts +1 -1
  36. package/dist/async.d.ts +15 -11
  37. package/dist/docs.d.ts +1 -1
  38. package/dist/squatch.d.ts +108 -108
  39. package/dist/squatch.esm.js +1105 -1417
  40. package/dist/squatch.esm.js.map +1 -1
  41. package/dist/squatch.js +1105 -1438
  42. package/dist/squatch.js.map +1 -1
  43. package/dist/squatch.min.js +2 -13
  44. package/dist/squatch.min.js.LICENSE.txt +6 -0
  45. package/dist/squatch.min.js.map +1 -1
  46. package/dist/squatch.modern.js +1 -1
  47. package/dist/squatch.modern.js.map +1 -1
  48. package/dist/stats.html +1 -1
  49. package/dist/types.d.ts +107 -106
  50. package/dist/utils/cookieUtils.d.ts +2 -2
  51. package/dist/utils/decodeUserJwt.d.ts +2 -0
  52. package/dist/utils/domUtils.d.ts +1 -0
  53. package/dist/utils/domready.d.ts +6 -6
  54. package/dist/utils/io.d.ts +5 -13
  55. package/dist/utils/loadEvent.d.ts +2 -0
  56. package/dist/utils/utmUtils.d.ts +14 -14
  57. package/dist/utils/validate.d.ts +12 -16
  58. package/dist/widgets/EmbedWidget.d.ts +16 -15
  59. package/dist/widgets/IREmbedWidget.d.ts +29 -0
  60. package/dist/widgets/IRPopupWidget.d.ts +32 -0
  61. package/dist/widgets/PopupWidget.d.ts +25 -23
  62. package/dist/widgets/Widget.d.ts +53 -33
  63. package/dist/widgets/Widgets.d.ts +108 -116
  64. package/dist/widgets/declarative/DeclarativeEmbedWidget.d.ts +12 -0
  65. package/dist/widgets/declarative/DeclarativeWidget.d.ts +32 -0
  66. package/dist/widgets/declarative/DeclarativeWidgets.d.ts +13 -0
  67. package/jest.config.ts +202 -0
  68. package/package.json +123 -105
  69. package/stats.json +1 -0
  70. 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
- ## Data Only Operations
54
- You can create/upsert users without loading a widget.
55
-
56
- ```html
57
- <script type="text/javascript">
58
- squatch.ready(function() {
59
-
60
- // Always call init
61
- squatch.init({
62
- tenantAlias: "YOUR_TENANT_ALIAS" // String (required)
63
- });
64
-
65
- var user;
66
-
67
- squatch.api().upsertUser({
68
- user: { // Object (required)
69
- id: 'USER_ID', // String (required)
70
- accountId: 'USER_ACCOUNT_ID', // String (required)
71
- email: 'USER_EMAIL', // String (optional)
72
- firstName: 'USER_FIRST_NAME', // String (optional)
73
- lastName: 'USER_LAST_NAME', // String (optional)
74
- ...
75
- },
76
- engagementMedium: 'EMBED', // String (optional: POPUP, EMBED)
77
- widgetType: 'p/PROGRAM-ID/w/referrerWidget', // Update PROGRAM-ID
78
- jwt: 'TOKEN' // String (required)
79
- }).then(function(response) {
80
- user = response.user;
81
- }).catch(function(err){
82
- console.log(err);
83
- });
84
-
85
- // autofill
86
- var element = document.getElementById('my_coupon');
87
- element.value = user.referredBy.code;
88
-
89
- });
90
- </script>
91
- ```
92
-
93
- ## Get Referral Cookie Code
94
- You can also use the `api()` function to call the WidgetApi methods directly.
95
-
96
- ```html
97
- <script type="text/javascript">
98
- squatch.ready(function(){
99
-
100
- // Always call init
101
- squatch.init({tenantAlias: 'YOUR_TENANT_ALIAS'});
102
-
103
-
104
- var element = document.getElementById('my_coupon');
105
-
106
- squatch.api().squatchReferralCookie().then(function(response) {
107
- /* `response.codes` looks like `{"program_id":"NEWCO", "friend_program":"BOB"}` */
108
-
109
- element.value = response.codes["program-id"];
110
- });
111
-
112
- });
113
- </script>
114
- ```
115
-
116
- Want more control? Visit our [guide](https://github.com/saasquatch/squatch-js/blob/master/docs/docs.md).
117
-
118
-
119
- ## Install via NPM and Webpack (advanced)
120
-
121
- Squatch.js can also be installed via NPM and bundled into your application with Webpack.
122
-
123
- ```ssh
124
- # via npm
125
- $ npm install @saasquatch/squatch-js
126
- ```
127
-
128
- ```js
129
- import * as squatch from "@saasquatch/squatch-js";
130
-
131
- // Always call init
132
- squatch.init({
133
- tenantAlias: "YOUR_TENANT_ALIAS" // String (required)
134
- });
135
-
136
- // Don't need to wait for .ready when importing via NPM/Webpack
137
- squatch.api().upsertUser({...});
138
-
139
- ```
140
-
141
- ## Contributing
142
- This is an open source project! If you are interested in contributing please look at [contributing guidelines](CONTRIBUTING.md) first.
143
-
144
- ## Support
145
- Shoot us an email at [support@saasqt.ch](mailto:support@saasqt.ch) if you need help!
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!
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ presets: [
3
+ [
4
+ "@babel/preset-env",
5
+ { targets: { esmodules: true }}
6
+ ]
7
+ ]
8
+ }