@saasquatch/squatch-js 2.6.0-0 → 2.6.0-10
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/static.yml +89 -0
- package/CHANGELOG.md +3 -0
- package/README.md +96 -68
- package/coverage/clover.xml +772 -775
- package/coverage/coverage-final.json +20 -22
- package/coverage/lcov.info +1364 -1369
- package/cucumber.js +3 -3
- package/dist/api/WidgetApi.d.ts +3 -2
- package/dist/async.d.ts +5 -0
- package/dist/globals.d.ts +4 -0
- package/dist/squatch.d.ts +28 -16
- package/dist/squatch.esm.js +561 -340
- package/dist/squatch.esm.js.map +1 -1
- package/dist/squatch.js +560 -340
- package/dist/squatch.js.map +1 -1
- package/dist/squatch.min.js +1 -1
- package/dist/types.d.ts +8 -6
- package/dist/utils/io.d.ts +1 -1
- package/dist/utils/validate.d.ts +2 -2
- package/dist/widgets/EmbedWidget.d.ts +14 -5
- package/dist/widgets/PopupWidget.d.ts +12 -7
- package/dist/widgets/Widget.d.ts +3 -2
- package/dist/widgets/Widgets.d.ts +22 -18
- package/dist/widgets/declarative/DeclarativeWidget.d.ts +75 -7
- package/dist/widgets/declarative/DeclarativeWidgets.d.ts +22 -0
- package/jest.config.ts +3 -5
- package/package.json +6 -6
- package/tsconfig.json +1 -0
- package/coverage/lcov-report/api/AnalyticsApi.ts.html +0 -304
- package/coverage/lcov-report/api/WidgetApi.ts.html +0 -628
- package/coverage/lcov-report/api/graphql.ts.html +0 -130
- package/coverage/lcov-report/utils/cookieUtils.ts.html +0 -415
- package/coverage/lcov-report/utils/decodeUserJwt.ts.html +0 -133
- package/coverage/lcov-report/utils/domready.ts.html +0 -160
- package/coverage/lcov-report/utils/io.ts.html +0 -385
- package/coverage/lcov-report/utils/utmUtils.ts.html +0 -277
- package/coverage/lcov-report/utils/validate.ts.html +0 -268
- package/coverage/lcov-report/validate.ts.html +0 -268
- package/coverage/lcov-report/widgets/EmbedWidget.ts.html +0 -436
- package/coverage/lcov-report/widgets/PopupWidget.ts.html +0 -625
- package/coverage/lcov-report/widgets/Widget.ts.html +0 -1108
- package/coverage/lcov-report/widgets/declarative/DeclarativeWidget.ts.html +0 -499
- package/dist/squatch.min.js.map +0 -1
- package/dist/squatch.modern.js +0 -2
- package/dist/squatch.modern.js.map +0 -1
- package/dist/stats.html +0 -208
- package/dist/utils/domUtils.d.ts +0 -1
- package/dist/utils/loadEvent.d.ts +0 -2
- package/dist/widgets/CtaWidget.d.ts +0 -24
- package/dist/widgets/IREmbedWidget.d.ts +0 -29
- package/dist/widgets/IRPopupWidget.d.ts +0 -32
- package/dist/widgets/declarative/DeclarativeEmbedWidget.d.ts +0 -12
- package/stats.json +0 -1
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Simple workflow for deploying static content to GitHub Pages
|
|
2
|
+
name: Deploy static content to Pages
|
|
3
|
+
|
|
4
|
+
on:
|
|
5
|
+
# Runs on pushes targeting the default branch
|
|
6
|
+
push:
|
|
7
|
+
branches: ["master"]
|
|
8
|
+
pull_request:
|
|
9
|
+
branches: ["master"]
|
|
10
|
+
|
|
11
|
+
# Allows you to run this workflow manually from the Actions tab
|
|
12
|
+
workflow_dispatch:
|
|
13
|
+
|
|
14
|
+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
|
|
15
|
+
permissions:
|
|
16
|
+
# Write permissions are needed to push the built site to the gh-pages branch
|
|
17
|
+
contents: write
|
|
18
|
+
id-token: write
|
|
19
|
+
pull-requests: write
|
|
20
|
+
|
|
21
|
+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
|
|
22
|
+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
|
|
23
|
+
concurrency:
|
|
24
|
+
group: "pages"
|
|
25
|
+
cancel-in-progress: false
|
|
26
|
+
|
|
27
|
+
jobs:
|
|
28
|
+
# Single deploy job since we're just deploying
|
|
29
|
+
deploy:
|
|
30
|
+
runs-on: ubuntu-latest
|
|
31
|
+
env:
|
|
32
|
+
PR_PATH: pull/${{github.event.number}}
|
|
33
|
+
|
|
34
|
+
steps:
|
|
35
|
+
- name: Checkout
|
|
36
|
+
id: checkout
|
|
37
|
+
uses: actions/checkout@v3
|
|
38
|
+
|
|
39
|
+
- name: Comment on PR
|
|
40
|
+
if: github.ref != 'refs/heads/master'
|
|
41
|
+
id: preview-comment
|
|
42
|
+
uses: hasura/comment-progress@v2
|
|
43
|
+
with:
|
|
44
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
45
|
+
repository: ${{ github.repository }}
|
|
46
|
+
number: ${{ github.event.number }}
|
|
47
|
+
id: deploy-preview
|
|
48
|
+
message: "Starting deployment of docs preview ⏳..."
|
|
49
|
+
|
|
50
|
+
- name: Setup NodeJS
|
|
51
|
+
id: setup-node
|
|
52
|
+
uses: actions/setup-node@v3
|
|
53
|
+
with:
|
|
54
|
+
node-version-file: package.json
|
|
55
|
+
cache: "npm"
|
|
56
|
+
|
|
57
|
+
- name: NPM Install
|
|
58
|
+
id: npm-ci
|
|
59
|
+
run: npm ci
|
|
60
|
+
|
|
61
|
+
- name: Build Docs
|
|
62
|
+
id: build-docs
|
|
63
|
+
run: npm run build:docs
|
|
64
|
+
|
|
65
|
+
- name: Deploy Master
|
|
66
|
+
if: github.ref == 'refs/heads/master'
|
|
67
|
+
uses: peaceiris/actions-gh-pages@v3
|
|
68
|
+
with:
|
|
69
|
+
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
70
|
+
publish_dir: ./docs
|
|
71
|
+
|
|
72
|
+
- name: Deploy Preview
|
|
73
|
+
if: github.ref != 'refs/heads/master'
|
|
74
|
+
uses: peaceiris/actions-gh-pages@v3
|
|
75
|
+
with:
|
|
76
|
+
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
77
|
+
publish_dir: ./docs
|
|
78
|
+
destination_dir: ${{ env.PR_PATH }}
|
|
79
|
+
|
|
80
|
+
- name: Update preview comment
|
|
81
|
+
if: github.ref != 'refs/heads/master'
|
|
82
|
+
id: update-preview-comment
|
|
83
|
+
uses: hasura/comment-progress@v2
|
|
84
|
+
with:
|
|
85
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
86
|
+
repository: ${{ github.repository }}
|
|
87
|
+
number: ${{ github.event.number }}
|
|
88
|
+
id: deploy-preview
|
|
89
|
+
message: "A preview of ${{ github.event.after }} is uploaded and can be seen here:\n\n ✨ https://saasquatch.github.io/squatch-js/${{ env.PR_PATH }} ✨"
|
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
- Added custom web-components `squatch-embed` and `squatch-popup` for easier widget rendering.
|
|
11
|
+
- Support for additional namespacing of squatchjs
|
|
12
|
+
|
|
10
13
|
## [2.5.0] - 2023-05-16
|
|
11
14
|
|
|
12
15
|
### Removed
|
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
|
-
|
|
27
|
-
|
|
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
|
-
|
|
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
|
|
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).
|
|
57
53
|
|
|
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
|
-
|
|
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
|
-
####
|
|
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
|
-
|
|
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,71 @@ 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" | locale="en_US" ]>
|
|
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
|
+
- Changing this attribute's value causes the widget to reload.
|
|
152
|
+
- `container`: A CSS selector for a container element to use as the parent of the widget's iframe.
|
|
153
|
+
- Default: `null`
|
|
154
|
+
- Note, if no container is specified, the widget iframe will attach to the shadow DOM of `squatch-embed`.
|
|
155
|
+
- `locale`: Locale that determines the widget translation displayed. Should be of the form "xx_XX".
|
|
156
|
+
- Default: Browser's current locale
|
|
157
|
+
- Changing this attribute's value causes the widget to reload.
|
|
158
|
+
|
|
159
|
+
### `squatch-popup`
|
|
160
|
+
```html
|
|
161
|
+
<squatch-embed widget="WIDGET_TYPE" [ open | container="#selector" | locale="en_US" ]>
|
|
162
|
+
<!-- Clicking a child of squatch-popup opens the popup -->
|
|
163
|
+
<button>Click me to open</button>
|
|
164
|
+
</squatch-embed>
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
- `widget: string`: Specifies the SaaSquatch `widgetType` identifier of the desired widget
|
|
168
|
+
- Required
|
|
169
|
+
- `open: boolean`: Whether to the popup is open when loaded into the page
|
|
170
|
+
- Default: `false`
|
|
171
|
+
- `container`: A CSS selector for a container element to use as the parent of the widget's iframe.
|
|
172
|
+
- Default: `null`
|
|
173
|
+
- Note, if no container is specified, the widget iframe will attach to the shadow DOM of `squatch-embed`.
|
|
174
|
+
- `locale`: Locale that determines the widget translation displayed. Should be of the form "xx_XX".
|
|
175
|
+
- Default: Browser's current locale
|
|
176
|
+
- Changing this attribute's value causes the widget to reload.
|
|
177
|
+
|
|
178
|
+
## Legacy
|
|
179
|
+
|
|
180
|
+
### Rendering a widget via Widgets API
|
|
181
|
+
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.
|
|
182
|
+
|
|
183
|
+
```html
|
|
184
|
+
<script type="text/javascript">
|
|
185
|
+
squatch.ready(function() {
|
|
186
|
+
|
|
187
|
+
squatch.widgets().upsertUser({
|
|
188
|
+
user: { // Object (required)
|
|
189
|
+
id: 'USER_ID', // String (required)
|
|
190
|
+
accountId: 'USER_ACCOUNT_ID', // String (required)
|
|
191
|
+
email: 'USER_EMAIL', // String (optional)
|
|
192
|
+
firstName: 'USER_FIRST_NAME', // String (optional)
|
|
193
|
+
lastName: 'USER_LAST_NAME', // String (optional)
|
|
194
|
+
|
|
195
|
+
...
|
|
196
|
+
},
|
|
197
|
+
engagementMedium: 'EMBED', // String (optional: POPUP, EMBED)
|
|
198
|
+
widgetType: 'p/PROGRAM-ID/w/referrerWidget', // Update PROGRAM-ID
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
</script>
|
|
202
|
+
```
|
|
203
|
+
|
|
176
204
|
## Contributing
|
|
177
205
|
This is an open source project! If you are interested in contributing please look at [contributing guidelines](CONTRIBUTING.md) first.
|
|
178
206
|
|