@saasquatch/squatch-js 2.7.0-2 → 2.7.0-3
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/dist/api/AnalyticsApi.d.ts +32 -0
- package/dist/api/EventsApi.d.ts +52 -0
- package/dist/api/WidgetApi.d.ts +64 -0
- package/dist/api/graphql.d.ts +1 -0
- package/dist/async.d.ts +20 -0
- package/dist/docs.d.ts +1 -0
- package/dist/globals.d.ts +4 -0
- package/dist/squatch.cjs.js +1 -0
- package/dist/squatch.cjs.js.map +1 -0
- package/dist/squatch.d.ts +122 -0
- package/dist/squatch.es.js +1 -0
- package/dist/squatch.es.js.map +1 -0
- package/dist/squatch.js +1 -0
- package/dist/squatch.js.map +1 -0
- package/dist/types.d.ts +109 -0
- package/dist/utils/cookieUtils.d.ts +3 -0
- package/dist/utils/decodeUserJwt.d.ts +2 -0
- package/dist/utils/domready.d.ts +6 -0
- package/dist/utils/io.d.ts +5 -0
- package/dist/utils/utmUtils.d.ts +14 -0
- package/dist/utils/validate.d.ts +12 -0
- package/dist/widgets/EmbedWidget.d.ts +25 -0
- package/dist/widgets/PopupWidget.d.ts +30 -0
- package/dist/widgets/Widget.d.ts +57 -0
- package/dist/widgets/Widgets.d.ts +112 -0
- package/dist/widgets/declarative/DeclarativeWidget.d.ts +100 -0
- package/dist/widgets/declarative/DeclarativeWidgets.d.ts +35 -0
- package/package.json +2 -1
- package/vite.config.ts +9 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { default as AnalyticsApi } from '../api/AnalyticsApi';
|
|
2
|
+
import { default as WidgetApi } from '../api/WidgetApi';
|
|
3
|
+
import { EngagementMedium, WidgetContext, WidgetType } from '../types';
|
|
4
|
+
export interface Params {
|
|
5
|
+
type: WidgetType;
|
|
6
|
+
domain: string;
|
|
7
|
+
npmCdn: string;
|
|
8
|
+
content: string;
|
|
9
|
+
api: WidgetApi;
|
|
10
|
+
rsCode?: string;
|
|
11
|
+
context: WidgetContext;
|
|
12
|
+
container?: string | HTMLElement | null | undefined;
|
|
13
|
+
}
|
|
14
|
+
export type ProgramLoadEvent = {
|
|
15
|
+
programId: string;
|
|
16
|
+
tenantAlias?: string;
|
|
17
|
+
accountId?: string;
|
|
18
|
+
userId?: string;
|
|
19
|
+
engagementMedium?: EngagementMedium;
|
|
20
|
+
};
|
|
21
|
+
export type GenericLoadEvent = {
|
|
22
|
+
mode: any;
|
|
23
|
+
analytics: any;
|
|
24
|
+
};
|
|
25
|
+
export default abstract class Widget {
|
|
26
|
+
type: WidgetType;
|
|
27
|
+
content: string;
|
|
28
|
+
analyticsApi: AnalyticsApi;
|
|
29
|
+
widgetApi: WidgetApi;
|
|
30
|
+
context: WidgetContext;
|
|
31
|
+
npmCdn: string;
|
|
32
|
+
container: string | HTMLElement | undefined | null;
|
|
33
|
+
loadEventListener: EventListener | null;
|
|
34
|
+
protected constructor(params: Params);
|
|
35
|
+
_findElement(): HTMLElement;
|
|
36
|
+
_createFrame(): HTMLIFrameElement;
|
|
37
|
+
_findFrame(): HTMLIFrameElement | null;
|
|
38
|
+
abstract load(): void;
|
|
39
|
+
protected _detachLoadEventListener(frameDoc: Document): void;
|
|
40
|
+
protected _attachLoadEventListener(frameDoc: Document, sqh: ProgramLoadEvent | GenericLoadEvent): void;
|
|
41
|
+
protected _loadEvent(sqh: ProgramLoadEvent | GenericLoadEvent): void;
|
|
42
|
+
protected _shareEvent(sqh: any, medium: any): void;
|
|
43
|
+
protected _error(rs: any, mode?: string, style?: string): string;
|
|
44
|
+
protected _findInnerContainer(frame: HTMLIFrameElement): Promise<Element>;
|
|
45
|
+
/**
|
|
46
|
+
* Reloads the current widget, makes updated request to API and renders result.
|
|
47
|
+
* Primarily for Classic widgets with registration
|
|
48
|
+
* @param param0 Form field values
|
|
49
|
+
* @param jwt JWT for API authentication
|
|
50
|
+
*/
|
|
51
|
+
reload({ email, firstName, lastName }: {
|
|
52
|
+
email: any;
|
|
53
|
+
firstName: any;
|
|
54
|
+
lastName: any;
|
|
55
|
+
}, jwt: any): void;
|
|
56
|
+
private __deprecated__register;
|
|
57
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { default as WidgetApi } from '../api/WidgetApi';
|
|
2
|
+
import { ConfigOptions, WidgetConfig, WidgetResult, WithRequired } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* `Widgets` is a factory for creating widgets. It's possible to build your own widgets using the
|
|
5
|
+
* {@link WidgetApi} but most people will prefer to use these easy methods.
|
|
6
|
+
* @class
|
|
7
|
+
*/
|
|
8
|
+
export default class Widgets {
|
|
9
|
+
/**
|
|
10
|
+
* Instance of {@link WidgetApi}
|
|
11
|
+
*/
|
|
12
|
+
api: WidgetApi;
|
|
13
|
+
/**
|
|
14
|
+
* Tenant alias of SaaSquatch tenant
|
|
15
|
+
*/
|
|
16
|
+
tenantAlias: string;
|
|
17
|
+
/**
|
|
18
|
+
* SaaSquatch domain for API requests
|
|
19
|
+
* @default "https://app.referralsaasquatch.com"
|
|
20
|
+
*/
|
|
21
|
+
domain: string;
|
|
22
|
+
/**
|
|
23
|
+
* Hosted CDN for npm packages
|
|
24
|
+
* @default "https://fast.ssqt.io/npm"
|
|
25
|
+
*/
|
|
26
|
+
npmCdn: string;
|
|
27
|
+
/**
|
|
28
|
+
* Initialize a new {@link Widgets} instance.
|
|
29
|
+
*
|
|
30
|
+
* @param {ConfigOptions} config Config details
|
|
31
|
+
*
|
|
32
|
+
* @example <caption>Browser example</caption>
|
|
33
|
+
* var widgets = new squatch.Widgets({tenantAlias:'test_12b5bo1b25125'});
|
|
34
|
+
*
|
|
35
|
+
* @example <caption>Browserify/Webpack example</caption>
|
|
36
|
+
* var Widgets = require('@saasquatch/squatch-js').Widgets;
|
|
37
|
+
* var widgets = new Widgets({tenantAlias:'test_12b5bo1b25125'});
|
|
38
|
+
*
|
|
39
|
+
* @example <caption>Babel+Browserify/Webpack example</caption>
|
|
40
|
+
* import {Widgets} from '@saasquatch/squatch-js';
|
|
41
|
+
* let widgets = new Widgets({tenantAlias:'test_12b5bo1b25125'});
|
|
42
|
+
*/
|
|
43
|
+
constructor(configin: ConfigOptions);
|
|
44
|
+
/**
|
|
45
|
+
* This function calls the {@link WidgetApi.upsertUser} method, and it renders
|
|
46
|
+
* the widget if it is successful. Otherwise it shows the "error" widget.
|
|
47
|
+
*
|
|
48
|
+
* @param {Object} config Config details
|
|
49
|
+
* @param {Object} config.user The user details
|
|
50
|
+
* @param {string} config.user.id The user id
|
|
51
|
+
* @param {string} config.user.accountId The user account id
|
|
52
|
+
* @param {WidgetType} config.widgetType The content of the widget
|
|
53
|
+
* @param {EngagementMedium} config.engagementMedium How to display the widget
|
|
54
|
+
* @param {string} config.jwt the JSON Web Token (JWT) that is used to validate the data (can be disabled)
|
|
55
|
+
* @param {HTMLElement | string | undefined} config.container Element to load the widget into
|
|
56
|
+
* @param {string | undefined} config.trigger Trigger element for opening the popup widget
|
|
57
|
+
*
|
|
58
|
+
* @return {Promise<WidgetResult>} json object if true, with a Widget and user details
|
|
59
|
+
*/
|
|
60
|
+
upsertUser(config: WithRequired<WidgetConfig, "user">): Promise<{
|
|
61
|
+
widget: any;
|
|
62
|
+
user: any;
|
|
63
|
+
}>;
|
|
64
|
+
/**
|
|
65
|
+
* This function calls the {@link WidgetApi.render} method, and it renders
|
|
66
|
+
* the widget if it is successful. Otherwise it shows the "error" widget.
|
|
67
|
+
*
|
|
68
|
+
* @param {Object} config Config details
|
|
69
|
+
* @param {Object} config.user The user details
|
|
70
|
+
* @param {string} config.user.id The user id
|
|
71
|
+
* @param {string} config.user.accountId The user account id
|
|
72
|
+
* @param {WidgetType} config.widgetType The content of the widget
|
|
73
|
+
* @param {EngagementMedium} config.engagementMedium How to display the widget
|
|
74
|
+
* @param {string} config.jwt the JSON Web Token (JWT) that is used
|
|
75
|
+
* to validate the data (can be disabled)
|
|
76
|
+
*
|
|
77
|
+
* @return {Promise<WidgetResult>} json object if true, with a Widget and user details
|
|
78
|
+
*/
|
|
79
|
+
render(config: WidgetConfig): Promise<WidgetResult | undefined>;
|
|
80
|
+
/**
|
|
81
|
+
* Autofills a referral code into an element when someone has been referred.
|
|
82
|
+
* Uses {@link WidgetApi.squatchReferralCookie} behind the scenes.
|
|
83
|
+
*
|
|
84
|
+
* @param selector Element class/id selector, or a callback function
|
|
85
|
+
* @returns
|
|
86
|
+
*/
|
|
87
|
+
autofill(selector: string | Function): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* @hidden
|
|
90
|
+
* @param {Object} response The json object return from the WidgetApi
|
|
91
|
+
* @param {Object} config Config details
|
|
92
|
+
* @param {string} config.widgetType The widget type (REFERRER_WIDGET, CONVERSION_WIDGET)
|
|
93
|
+
* @param {string} config.engagementMedium (POPUP, EMBED)
|
|
94
|
+
* @returns {Widget} widget (PopupWidget or EmbedWidget)
|
|
95
|
+
*/
|
|
96
|
+
private _renderWidget;
|
|
97
|
+
private _renderPopupWidget;
|
|
98
|
+
private _renderEmbedWidget;
|
|
99
|
+
/**
|
|
100
|
+
* @hidden
|
|
101
|
+
* @param {Object} error The json object containing the error details
|
|
102
|
+
* @param {string} em The engagementMedium
|
|
103
|
+
* @returns {void}
|
|
104
|
+
*/
|
|
105
|
+
private _renderErrorWidget;
|
|
106
|
+
/**
|
|
107
|
+
* @hidden
|
|
108
|
+
* @param {string} rule A regular expression
|
|
109
|
+
* @returns {boolean} true if rule matches Url, false otherwise
|
|
110
|
+
*/
|
|
111
|
+
private static _matchesUrl;
|
|
112
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { default as AnalyticsApi } from '../../api/AnalyticsApi';
|
|
2
|
+
import { default as WidgetApi } from '../../api/WidgetApi';
|
|
3
|
+
import { DeclarativeConfigOptions } from '../../types';
|
|
4
|
+
import { default as EmbedWidget } from '../EmbedWidget';
|
|
5
|
+
import { default as PopupWidget } from '../PopupWidget';
|
|
6
|
+
/**
|
|
7
|
+
* Abstract class for building web-components that render SaaSquatch widgets to the DOM
|
|
8
|
+
* @abstract
|
|
9
|
+
* @example
|
|
10
|
+
* class TestWidgetElement extends DeclarativeWidget {}
|
|
11
|
+
* const testWidget = new TestWidgetElement()
|
|
12
|
+
* testWidget.widgetType = 'w/widget-type'
|
|
13
|
+
* testWidget.type = 'EMBED'
|
|
14
|
+
* testWidget.renderWidget()
|
|
15
|
+
*/
|
|
16
|
+
export default abstract class DeclarativeWidget extends HTMLElement {
|
|
17
|
+
/**
|
|
18
|
+
* Configuration overrides
|
|
19
|
+
* @default window.squatchConfig
|
|
20
|
+
*/
|
|
21
|
+
config: DeclarativeConfigOptions | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Signed JWT containing user information
|
|
24
|
+
* @default window.squatchToken
|
|
25
|
+
*/
|
|
26
|
+
token: string | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Tenant alias of SaaSquatch tenant
|
|
29
|
+
* @default window.squatchTenant
|
|
30
|
+
*/
|
|
31
|
+
tenant: string | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* widgetType of widget to load
|
|
34
|
+
*/
|
|
35
|
+
widgetType: string | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Locale to render the widget in
|
|
38
|
+
*/
|
|
39
|
+
locale: string | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Instance of {@link WidgetApi}
|
|
42
|
+
*/
|
|
43
|
+
widgetApi: WidgetApi;
|
|
44
|
+
/**
|
|
45
|
+
* Instance of {@link AnalyticsApi}
|
|
46
|
+
*/
|
|
47
|
+
analyticsApi: AnalyticsApi;
|
|
48
|
+
/**
|
|
49
|
+
* Instance of {@link EmbedWidget} or {@link PopupWidget}
|
|
50
|
+
*/
|
|
51
|
+
widgetInstance: EmbedWidget | PopupWidget;
|
|
52
|
+
/**
|
|
53
|
+
* Determines whether to render the widget as an embedding widget or popup widget
|
|
54
|
+
*/
|
|
55
|
+
type: "EMBED" | "POPUP";
|
|
56
|
+
/**
|
|
57
|
+
* Container element to contain the widget iframe
|
|
58
|
+
* @default this
|
|
59
|
+
*/
|
|
60
|
+
container: string | HTMLElement | undefined | null;
|
|
61
|
+
element: HTMLElement | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Flag for if the component has been loaded or not
|
|
64
|
+
* @hidden
|
|
65
|
+
*/
|
|
66
|
+
loaded: boolean;
|
|
67
|
+
constructor();
|
|
68
|
+
private _setupApis;
|
|
69
|
+
private renderPasswordlessVariant;
|
|
70
|
+
private renderUserUpsertVariant;
|
|
71
|
+
private _setWidget;
|
|
72
|
+
/**
|
|
73
|
+
* Fetches widget content from SaaSquatch and builds a Widget instance to support rendering the widget in the DOM
|
|
74
|
+
* @returns Instance of either {@link EmbedWidget} or {@link PopupWidget} depending on `this.type`
|
|
75
|
+
* @throws Throws an Error if `widgetType` is undefined
|
|
76
|
+
*/
|
|
77
|
+
getWidgetInstance(): Promise<EmbedWidget | PopupWidget>;
|
|
78
|
+
/**
|
|
79
|
+
* Calls {@link getWidgetInstance} to build the Widget instance and loads the widget iframe into the DOM
|
|
80
|
+
*/
|
|
81
|
+
renderWidget(): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Builds a Widget instance for the default error widget
|
|
84
|
+
* @returns Instance of either {@link EmbedWidget} or {@link PopupWidget} depending on `this.type`
|
|
85
|
+
*/
|
|
86
|
+
setErrorWidget: (e: Error) => EmbedWidget | PopupWidget;
|
|
87
|
+
/**
|
|
88
|
+
* Calls `open` method of `widgetInstance`
|
|
89
|
+
* @throws Throws an Error if called before the widget has loaded
|
|
90
|
+
*/
|
|
91
|
+
open(): void;
|
|
92
|
+
/**
|
|
93
|
+
* Calls `close` method of `widgetInstance`
|
|
94
|
+
* @throws Throws an Error if called before the widget has loaded
|
|
95
|
+
*/
|
|
96
|
+
close(): void;
|
|
97
|
+
reload: () => Promise<void>;
|
|
98
|
+
show: () => void;
|
|
99
|
+
hide: () => void;
|
|
100
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { default as DeclarativeWidget } from './DeclarativeWidget';
|
|
2
|
+
/**
|
|
3
|
+
* Base class for `squatch-embed` web-component
|
|
4
|
+
* @extends {DeclarativeWidget}
|
|
5
|
+
* @class
|
|
6
|
+
* @example
|
|
7
|
+
* window.createCustomElement('squatch-embed', DeclarativeEmbedWidget)
|
|
8
|
+
* const widget = document.querySelector('squatch-embed') as DeclarativeEmbedWidget
|
|
9
|
+
* widget.open()
|
|
10
|
+
* widget.close()
|
|
11
|
+
* widget.reload()
|
|
12
|
+
*/
|
|
13
|
+
export declare class DeclarativeEmbedWidget extends DeclarativeWidget {
|
|
14
|
+
constructor();
|
|
15
|
+
static get observedAttributes(): string[];
|
|
16
|
+
attributeChangedCallback(attr: string, oldVal: string, newVal: string): void;
|
|
17
|
+
connectedCallback(): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Base class for `squatch-popup` web-component
|
|
21
|
+
* @extends {DeclarativeWidget}
|
|
22
|
+
* @class
|
|
23
|
+
* @example
|
|
24
|
+
* window.createCustomElement('squatch-popup', DeclarativePopupWidget)
|
|
25
|
+
* const widget = document.querySelector('squatch-popup') as DeclarativePopupWidget
|
|
26
|
+
* widget.open()
|
|
27
|
+
* widget.close()
|
|
28
|
+
* widget.reload()
|
|
29
|
+
*/
|
|
30
|
+
export declare class DeclarativePopupWidget extends DeclarativeWidget {
|
|
31
|
+
constructor();
|
|
32
|
+
static get observedAttributes(): string[];
|
|
33
|
+
attributeChangedCallback(attr: string, oldVal: string, newVal: string): void;
|
|
34
|
+
connectedCallback(): Promise<void>;
|
|
35
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saasquatch/squatch-js",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.7.0-
|
|
4
|
+
"version": "2.7.0-3",
|
|
5
5
|
"description": "The official Referral SaaSquatch Javascript Web/Browser SDK https://docs.referralsaasquatch.com/developer/squatchjs/",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "ReferralSaaSquatch.com, Inc.",
|
|
@@ -101,6 +101,7 @@
|
|
|
101
101
|
"tsd": "^0.13.1",
|
|
102
102
|
"typedoc": "^0.24.8",
|
|
103
103
|
"typescript": "^5.1.6",
|
|
104
|
+
"vite-plugin-dts": "^4.5.3",
|
|
104
105
|
"webpack-bundle-analyzer": "^4.9.0",
|
|
105
106
|
"webpack-cli": "^6.0.1",
|
|
106
107
|
"webpack-visualizer-plugin": "^0.1.11"
|
package/vite.config.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { resolve } from "path";
|
|
2
2
|
import { defineConfig } from "vite";
|
|
3
3
|
import tsconfigPaths from "vite-tsconfig-paths";
|
|
4
|
+
import dts from "vite-plugin-dts";
|
|
4
5
|
|
|
5
6
|
export default defineConfig({
|
|
6
|
-
plugins: [
|
|
7
|
+
plugins: [
|
|
8
|
+
tsconfigPaths(),
|
|
9
|
+
dts({
|
|
10
|
+
outDir: "dist",
|
|
11
|
+
tsconfigPath: "./tsconfig.json",
|
|
12
|
+
}),
|
|
13
|
+
],
|
|
7
14
|
server: {
|
|
8
15
|
port: 3000,
|
|
9
16
|
},
|
|
@@ -23,5 +30,6 @@ export default defineConfig({
|
|
|
23
30
|
format: "umd",
|
|
24
31
|
},
|
|
25
32
|
},
|
|
33
|
+
sourcemap: true,
|
|
26
34
|
},
|
|
27
35
|
});
|