@saasquatch/squatch-js 2.5.0 → 2.5.1-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/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,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
- ## 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
+ ## 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!
package/demo/sandbox.ts CHANGED
@@ -1,124 +1,124 @@
1
- import { getQueryStringParams } from "./util";
2
-
3
- export const tenantAlias = "test_aojsrf4r06zi0";
4
- export const domain = "https://staging.referralsaasquatch.com";
5
- export const script = "https://fast.ssqt.io/squatch-js@2";
6
-
7
- export const user = {
8
- id: "5b980d34e4b0cabee07f2cb0",
9
- accountId: "AZJZSVG0LS1LB19R",
10
- email: "chesterscott.uexwltgh@mailosaur.io",
11
- };
12
- export const badJwtUser = {
13
- ...user,
14
- firstName: "Bad JWT",
15
- };
16
- export const noIds = {
17
- firstName: "No IDs",
18
- };
19
- export const noUserId = {
20
- accountId: "abc_123",
21
- firstName: "No UserID",
22
- };
23
- export const noAccountId = {
24
- id: "abc_123",
25
- firstName: "No AccountID",
26
- };
27
-
28
- export const users = [user, badJwtUser, noIds, noUserId, noAccountId, {}];
29
-
30
- export const popup: Sandbox = {
31
- script,
32
- domain,
33
- tenantAlias,
34
- debug: true,
35
- initObj: {
36
- widgetType: "REFERRER_WIDGET",
37
- engagementMedium: "POPUP",
38
- user: user,
39
- jwt: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjoiNWI5ODBkMzRlNGIwY2FiZWUwN2YyY2IwIiwiYWNjb3VudElkIjoiQVpKWlNWRzBMUzFMQjE5UiIsImVtYWlsIjoiY2hlc3RlcnNjb3R0LnVleHdsdGdoQG1haWxvc2F1ci5pbyJ9fQ.MkrO7-980M7NRJcOUcdqCO1JftqmynLMK8bTEB3WObo",
40
- },
41
- };
42
-
43
- export const embed: Sandbox = {
44
- script,
45
- domain,
46
- tenantAlias,
47
- initObj: {
48
- widgetType: "REFERRER_WIDGET",
49
- engagementMedium: "EMBED",
50
- user: {
51
- id: "5b980d34e4b0cabee07f2cb0",
52
- accountId: "AZJZSVG0LS1LB19R",
53
- email: "chesterscott.uexwltgh@mailosaur.io",
54
- },
55
- jwt: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjoiNWI5ODBkMzRlNGIwY2FiZWUwN2YyY2IwIiwiYWNjb3VudElkIjoiQVpKWlNWRzBMUzFMQjE5UiIsImVtYWlsIjoiY2hlc3RlcnNjb3R0LnVleHdsdGdoQG1haWxvc2F1ci5pbyJ9fQ.MkrO7-980M7NRJcOUcdqCO1JftqmynLMK8bTEB3WObo",
56
- },
57
- };
58
-
59
- export const embedNew: Sandbox = {
60
- ...embed,
61
- initObj: {
62
- ...embed.initObj,
63
- widgetType: "p/tuesday-text/w/referrerWidget",
64
- },
65
- };
66
-
67
- export const embedReferred: Sandbox = {
68
- ...embed,
69
- initObj: {
70
- ...embed.initObj,
71
- widgetType: "CONVERSION_WIDGET",
72
- },
73
- };
74
-
75
- export const popupReferred: Sandbox = {
76
- ...popup,
77
- initObj: {
78
- ...popup.initObj,
79
- widgetType: "CONVERSION_WIDGET",
80
- },
81
- };
82
-
83
- export const popupNew: Sandbox = {
84
- ...popup,
85
- initObj: {
86
- ...popup.initObj,
87
- widgetType: "p/tuesday-test/w/referrerWidget",
88
- },
89
- };
90
-
91
- export function fromURL() {
92
- let urlSandbox;
93
- try {
94
- urlSandbox = JSON.parse(
95
- window.atob(getQueryStringParams(window.location.search).sandbox)
96
- );
97
- } catch (e) {
98
- urlSandbox = {};
99
- }
100
-
101
- const sandbox = {
102
- ...popup,
103
- ...urlSandbox,
104
- };
105
- return sandbox;
106
- }
107
-
108
- export function toURL(sandbox: Sandbox) {
109
- window.location.href = href(sandbox);
110
- }
111
-
112
- export function href(sandbox: Sandbox) {
113
- const urlParams = new URLSearchParams(window.location.search);
114
- const param = window.btoa(JSON.stringify(sandbox));
115
- var url = window.location.href;
116
- if (url.indexOf("?") > 0) {
117
- url = url.substring(0, url.indexOf("?"));
118
- }
119
-
120
- urlParams.delete("sandbox");
121
-
122
- url += `?sandbox=${encodeURIComponent(param)}&${urlParams.toString()}`;
123
- return url;
124
- }
1
+ import { getQueryStringParams } from "./util";
2
+
3
+ export const tenantAlias = "test_aojsrf4r06zi0";
4
+ export const domain = "https://staging.referralsaasquatch.com";
5
+ export const script = "https://fast.ssqt.io/squatch-js@2";
6
+
7
+ export const user = {
8
+ id: "5b980d34e4b0cabee07f2cb0",
9
+ accountId: "AZJZSVG0LS1LB19R",
10
+ email: "chesterscott.uexwltgh@mailosaur.io",
11
+ };
12
+ export const badJwtUser = {
13
+ ...user,
14
+ firstName: "Bad JWT",
15
+ };
16
+ export const noIds = {
17
+ firstName: "No IDs",
18
+ };
19
+ export const noUserId = {
20
+ accountId: "abc_123",
21
+ firstName: "No UserID",
22
+ };
23
+ export const noAccountId = {
24
+ id: "abc_123",
25
+ firstName: "No AccountID",
26
+ };
27
+
28
+ export const users = [user, badJwtUser, noIds, noUserId, noAccountId, {}];
29
+
30
+ export const popup: Sandbox = {
31
+ script,
32
+ domain,
33
+ tenantAlias,
34
+ debug: true,
35
+ initObj: {
36
+ widgetType: "REFERRER_WIDGET",
37
+ engagementMedium: "POPUP",
38
+ user: user,
39
+ jwt: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjoiNWI5ODBkMzRlNGIwY2FiZWUwN2YyY2IwIiwiYWNjb3VudElkIjoiQVpKWlNWRzBMUzFMQjE5UiIsImVtYWlsIjoiY2hlc3RlcnNjb3R0LnVleHdsdGdoQG1haWxvc2F1ci5pbyJ9fQ.MkrO7-980M7NRJcOUcdqCO1JftqmynLMK8bTEB3WObo",
40
+ },
41
+ };
42
+
43
+ export const embed: Sandbox = {
44
+ script,
45
+ domain,
46
+ tenantAlias,
47
+ initObj: {
48
+ widgetType: "REFERRER_WIDGET",
49
+ engagementMedium: "EMBED",
50
+ user: {
51
+ id: "5b980d34e4b0cabee07f2cb0",
52
+ accountId: "AZJZSVG0LS1LB19R",
53
+ email: "chesterscott.uexwltgh@mailosaur.io",
54
+ },
55
+ jwt: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjoiNWI5ODBkMzRlNGIwY2FiZWUwN2YyY2IwIiwiYWNjb3VudElkIjoiQVpKWlNWRzBMUzFMQjE5UiIsImVtYWlsIjoiY2hlc3RlcnNjb3R0LnVleHdsdGdoQG1haWxvc2F1ci5pbyJ9fQ.MkrO7-980M7NRJcOUcdqCO1JftqmynLMK8bTEB3WObo",
56
+ },
57
+ };
58
+
59
+ export const embedNew: Sandbox = {
60
+ ...embed,
61
+ initObj: {
62
+ ...embed.initObj,
63
+ widgetType: "p/tuesday-text/w/referrerWidget",
64
+ },
65
+ };
66
+
67
+ export const embedReferred: Sandbox = {
68
+ ...embed,
69
+ initObj: {
70
+ ...embed.initObj,
71
+ widgetType: "CONVERSION_WIDGET",
72
+ },
73
+ };
74
+
75
+ export const popupReferred: Sandbox = {
76
+ ...popup,
77
+ initObj: {
78
+ ...popup.initObj,
79
+ widgetType: "CONVERSION_WIDGET",
80
+ },
81
+ };
82
+
83
+ export const popupNew: Sandbox = {
84
+ ...popup,
85
+ initObj: {
86
+ ...popup.initObj,
87
+ widgetType: "p/tuesday-test/w/referrerWidget",
88
+ },
89
+ };
90
+
91
+ export function fromURL() {
92
+ let urlSandbox;
93
+ try {
94
+ urlSandbox = JSON.parse(
95
+ window.atob(getQueryStringParams(window.location.search).sandbox)
96
+ );
97
+ } catch (e) {
98
+ urlSandbox = {};
99
+ }
100
+
101
+ const sandbox = {
102
+ ...popup,
103
+ ...urlSandbox,
104
+ };
105
+ return sandbox;
106
+ }
107
+
108
+ export function toURL(sandbox: Sandbox) {
109
+ window.location.href = href(sandbox);
110
+ }
111
+
112
+ export function href(sandbox: Sandbox) {
113
+ const urlParams = new URLSearchParams(window.location.search);
114
+ const param = window.btoa(JSON.stringify(sandbox));
115
+ var url = window.location.href;
116
+ if (url.indexOf("?") > 0) {
117
+ url = url.substring(0, url.indexOf("?"));
118
+ }
119
+
120
+ urlParams.delete("sandbox");
121
+
122
+ url += `?sandbox=${encodeURIComponent(param)}&${urlParams.toString()}`;
123
+ return url;
124
+ }