@saasquatch/squatch-js 2.6.0-1 → 2.6.0-11
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 +14 -14
- package/.github/workflows/static.yml +89 -0
- package/CHANGELOG.md +329 -326
- package/LICENSE +20 -20
- package/README.md +208 -199
- package/babel.config.js +7 -7
- package/coverage/clover.xml +2 -2
- package/cucumber.js +45 -45
- package/demo/sandbox.ts +124 -124
- package/demo/toolbar.tsx +526 -526
- 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 +464 -249
- package/dist/squatch.esm.js.map +1 -1
- package/dist/squatch.js +463 -249
- package/dist/squatch.js.map +1 -1
- package/dist/squatch.min.js +1 -1
- package/dist/squatch.min.js.br +0 -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 +8 -6
- package/dist/utils/decodeJwt.d.ts +1 -0
- package/dist/utils/validate.d.ts +2 -2
- package/dist/widgets/EmbedWidget.d.ts +9 -0
- package/dist/widgets/PopupWidget.d.ts +8 -3
- package/dist/widgets/Widgets.d.ts +21 -8
- package/dist/widgets/declarative/DeclarativeWidget.d.ts +72 -2
- package/dist/widgets/declarative/DeclarativeWidgets.d.ts +22 -0
- package/jest.config.ts +200 -202
- package/package.json +123 -123
- package/tsconfig.json +23 -23
- package/coverage/lcov-report/WidgetApi.ts.html +0 -631
- package/coverage/lcov-report/api/AnalyticsApi.ts.html +0 -304
- package/coverage/lcov-report/api/WidgetApi.ts.html +0 -631
- 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 -400
- 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 -433
- package/coverage/lcov-report/widgets/PopupWidget.ts.html +0 -670
- package/coverage/lcov-report/widgets/Widget.ts.html +0 -1165
- package/coverage/lcov-report/widgets/Widgets.ts.html +0 -1060
- package/coverage/lcov-report/widgets/declarative/DeclarativeWidget.ts.html +0 -499
- package/stats.json +0 -1
package/dist/types.d.ts
CHANGED
|
@@ -77,19 +77,21 @@ export type EngagementMedium =
|
|
|
77
77
|
"POPUP"
|
|
78
78
|
/** Displays the widget embedded in the page. Create an {@link EmbedWidget} */
|
|
79
79
|
| "EMBED";
|
|
80
|
-
export type
|
|
81
|
-
type: "
|
|
80
|
+
export type UpsertWidgetContext = {
|
|
81
|
+
type: "upsert";
|
|
82
|
+
user?: User | null;
|
|
82
83
|
engagementMedium?: EngagementMedium;
|
|
83
84
|
container?: HTMLElement | string;
|
|
84
85
|
trigger?: string;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
type: "
|
|
88
|
-
user?: User | null;
|
|
86
|
+
};
|
|
87
|
+
export type BaseWidgetContext = {
|
|
88
|
+
type: "cookie" | "error" | "passwordless";
|
|
89
89
|
engagementMedium?: EngagementMedium;
|
|
90
90
|
container?: HTMLElement | string;
|
|
91
91
|
trigger?: string;
|
|
92
|
+
displayOnLoad?: boolean;
|
|
92
93
|
};
|
|
94
|
+
export type WidgetContext = UpsertWidgetContext | BaseWidgetContext;
|
|
93
95
|
export type WidgetContextType = "upsert" | "cookie" | "error" | "passwordless";
|
|
94
96
|
/**
|
|
95
97
|
* WidgetType is an enum for types of ways a Widget can be displayed.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function decodeUserJwt(tokenStr: string): any;
|
package/dist/utils/validate.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { ConfigOptions, WidgetConfig } from "../types";
|
|
2
|
-
export declare const DEFAULT_DOMAIN = "https://app.referralsaasquatch.com";
|
|
3
|
-
export declare const DEFAULT_NPM_CDN = "https://fast.ssqt.io/npm";
|
|
4
2
|
type Required<T> = T extends object ? {
|
|
5
3
|
[P in keyof T]-?: NonNullable<T[P]>;
|
|
6
4
|
} : T;
|
|
@@ -9,4 +7,6 @@ export declare function isObject(obj: unknown): obj is object;
|
|
|
9
7
|
export declare function validateLocale(locale?: string): string | undefined;
|
|
10
8
|
export declare function validateWidgetConfig(raw: unknown | undefined): WidgetConfig;
|
|
11
9
|
export declare function validatePasswordlessConfig(raw: unknown | undefined): WidgetConfig;
|
|
10
|
+
export declare function getToken(): string;
|
|
11
|
+
export declare function getConfig(): Omit<ConfigOptions, "tenantAlias">;
|
|
12
12
|
export {};
|
|
@@ -4,13 +4,22 @@ import Widget, { Params } from "./Widget";
|
|
|
4
4
|
*
|
|
5
5
|
* To create an EmbedWidget use {@link Widgets}
|
|
6
6
|
*
|
|
7
|
+
* @example
|
|
8
|
+
* const widget = new EmbedWidget({ ... })
|
|
9
|
+
* widget.load() // Loads widget into the DOM
|
|
10
|
+
* widget.open() // Makes the iframe container visible
|
|
11
|
+
* widget.close() // Hides the iframe container
|
|
7
12
|
*/
|
|
8
13
|
export default class EmbedWidget extends Widget {
|
|
9
14
|
constructor(params: Params, container?: HTMLElement | string);
|
|
10
15
|
load(): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Un-hide if element is available and refresh data
|
|
18
|
+
*/
|
|
11
19
|
open(): void;
|
|
12
20
|
close(): void;
|
|
13
21
|
protected _error(rs: any, mode?: string, style?: string): string;
|
|
22
|
+
private _shouldFireLoadEvent;
|
|
14
23
|
show: () => void;
|
|
15
24
|
hide: () => void;
|
|
16
25
|
}
|
|
@@ -5,15 +5,20 @@ import Widget, { Params } from "./Widget";
|
|
|
5
5
|
*
|
|
6
6
|
* To create a PopupWidget use {@link Widgets}
|
|
7
7
|
*
|
|
8
|
+
* @example
|
|
9
|
+
* const widget = new PopupWidget({ ... })
|
|
10
|
+
* widget.load() // Loads the widget into a dialog element
|
|
11
|
+
* widget.open() // Opens the dialog element
|
|
12
|
+
* widget.close() // Hides the dialog element
|
|
8
13
|
*/
|
|
9
14
|
export default class PopupWidget extends Widget {
|
|
10
15
|
trigger: string | null;
|
|
11
16
|
id: string;
|
|
12
17
|
constructor(params: Params, trigger?: string | null);
|
|
13
|
-
_initialiseCTA(
|
|
18
|
+
_initialiseCTA(): void;
|
|
14
19
|
_createPopupDialog(): HTMLDialogElement;
|
|
15
|
-
load(): void
|
|
16
|
-
protected _setupResizeHandler(frame: HTMLIFrameElement): void
|
|
20
|
+
load(): Promise<void>;
|
|
21
|
+
protected _setupResizeHandler(frame: HTMLIFrameElement): Promise<void>;
|
|
17
22
|
open(): void;
|
|
18
23
|
close(): void;
|
|
19
24
|
protected _clickedOutside({ target }: {
|
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
import WidgetApi from "../api/WidgetApi";
|
|
2
2
|
import { ConfigOptions, WidgetConfig, WidgetResult, WithRequired } from "../types";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
4
|
* `Widgets` is a factory for creating widgets. It's possible to build your own widgets using the
|
|
6
5
|
* {@link WidgetApi} but most people will prefer to use these easy methods.
|
|
7
|
-
*
|
|
6
|
+
* @class
|
|
8
7
|
*/
|
|
9
8
|
export default class Widgets {
|
|
9
|
+
/**
|
|
10
|
+
* Instance of {@link WidgetApi}
|
|
11
|
+
*/
|
|
10
12
|
api: WidgetApi;
|
|
13
|
+
/**
|
|
14
|
+
* Tenant alias of SaaSquatch tenant
|
|
15
|
+
*/
|
|
11
16
|
tenantAlias: string;
|
|
17
|
+
/**
|
|
18
|
+
* SaaSquatch domain for API requests
|
|
19
|
+
* @default "https://app.referralsaasquatch.com"
|
|
20
|
+
*/
|
|
12
21
|
domain: string;
|
|
22
|
+
/**
|
|
23
|
+
* Hosted CDN for npm packages
|
|
24
|
+
* @default "https://fast.ssqt.io/npm"
|
|
25
|
+
*/
|
|
13
26
|
npmCdn: string;
|
|
14
27
|
/**
|
|
15
28
|
* Initialize a new {@link Widgets} instance.
|
|
@@ -36,13 +49,13 @@ export default class Widgets {
|
|
|
36
49
|
* @param {Object} config.user The user details
|
|
37
50
|
* @param {string} config.user.id The user id
|
|
38
51
|
* @param {string} config.user.accountId The user account id
|
|
39
|
-
* @param {WidgetType} config.widgetType The content of the widget
|
|
40
|
-
* @param {EngagementMedium} config.engagementMedium How to display the widget
|
|
52
|
+
* @param {WidgetType} config.widgetType The content of the widget
|
|
53
|
+
* @param {EngagementMedium} config.engagementMedium How to display the widget
|
|
41
54
|
* @param {string} config.jwt the JSON Web Token (JWT) that is used to validate the data (can be disabled)
|
|
42
55
|
* @param {HTMLElement | string | undefined} config.container Element to load the widget into
|
|
43
56
|
* @param {string | undefined} config.trigger Trigger element for opening the popup widget
|
|
44
57
|
*
|
|
45
|
-
* @return {Promise<WidgetResult>} json object if true, with a Widget and user details
|
|
58
|
+
* @return {Promise<WidgetResult>} json object if true, with a Widget and user details
|
|
46
59
|
*/
|
|
47
60
|
upsertUser(config: WithRequired<WidgetConfig, "user">): Promise<{
|
|
48
61
|
widget: any;
|
|
@@ -56,12 +69,12 @@ export default class Widgets {
|
|
|
56
69
|
* @param {Object} config.user The user details
|
|
57
70
|
* @param {string} config.user.id The user id
|
|
58
71
|
* @param {string} config.user.accountId The user account id
|
|
59
|
-
* @param {WidgetType} config.widgetType The content of the widget
|
|
60
|
-
* @param {EngagementMedium} config.engagementMedium How to display the widget
|
|
72
|
+
* @param {WidgetType} config.widgetType The content of the widget
|
|
73
|
+
* @param {EngagementMedium} config.engagementMedium How to display the widget
|
|
61
74
|
* @param {string} config.jwt the JSON Web Token (JWT) that is used
|
|
62
75
|
* to validate the data (can be disabled)
|
|
63
76
|
*
|
|
64
|
-
* @return {Promise<WidgetResult>} json object if true, with a Widget and user details
|
|
77
|
+
* @return {Promise<WidgetResult>} json object if true, with a Widget and user details
|
|
65
78
|
*/
|
|
66
79
|
render(config: WidgetConfig): Promise<WidgetResult | undefined>;
|
|
67
80
|
/**
|
|
@@ -3,28 +3,98 @@ import WidgetApi from "../../api/WidgetApi";
|
|
|
3
3
|
import { DeclarativeConfigOptions } from "../../types";
|
|
4
4
|
import EmbedWidget from "../EmbedWidget";
|
|
5
5
|
import 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
|
+
*/
|
|
6
16
|
export default abstract class DeclarativeWidget extends HTMLElement {
|
|
17
|
+
/**
|
|
18
|
+
* Configuration overrides
|
|
19
|
+
* @default window.squatchConfig
|
|
20
|
+
*/
|
|
7
21
|
config: DeclarativeConfigOptions | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Signed JWT containing user information
|
|
24
|
+
* @default window.squatchToken
|
|
25
|
+
*/
|
|
8
26
|
token: string | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Tenant alias of SaaSquatch tenant
|
|
29
|
+
* @default window.squatchTenant
|
|
30
|
+
*/
|
|
9
31
|
tenant: string | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* widgetType of widget to load
|
|
34
|
+
*/
|
|
10
35
|
widgetType: string | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Locale to render the widget in
|
|
38
|
+
*/
|
|
39
|
+
locale: string | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Instance of {@link WidgetApi}
|
|
42
|
+
*/
|
|
11
43
|
widgetApi: WidgetApi;
|
|
44
|
+
/**
|
|
45
|
+
* Instance of {@link AnalyticsApi}
|
|
46
|
+
*/
|
|
12
47
|
analyticsApi: AnalyticsApi;
|
|
13
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Instance of {@link EmbedWidget} or {@link PopupWidget}
|
|
50
|
+
*/
|
|
14
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
|
+
*/
|
|
15
60
|
container: string | HTMLElement | undefined | null;
|
|
16
61
|
element: HTMLElement | undefined;
|
|
17
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Flag for if the component has been loaded or not
|
|
64
|
+
* @hidden
|
|
65
|
+
*/
|
|
66
|
+
loaded: boolean;
|
|
18
67
|
constructor();
|
|
19
68
|
private _setupApis;
|
|
20
69
|
private renderPasswordlessVariant;
|
|
21
70
|
private renderUserUpsertVariant;
|
|
22
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
|
+
*/
|
|
23
77
|
getWidgetInstance(): Promise<EmbedWidget | PopupWidget>;
|
|
78
|
+
/**
|
|
79
|
+
* Calls {@link getWidgetInstance} to build the Widget instance and loads the widget iframe into the DOM
|
|
80
|
+
*/
|
|
24
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
|
+
*/
|
|
25
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
|
+
*/
|
|
26
91
|
open(): void;
|
|
92
|
+
/**
|
|
93
|
+
* Calls `close` method of `widgetInstance`
|
|
94
|
+
* @throws Throws an Error if called before the widget has loaded
|
|
95
|
+
*/
|
|
27
96
|
close(): void;
|
|
97
|
+
reload: () => Promise<void>;
|
|
28
98
|
show: () => void;
|
|
29
99
|
hide: () => void;
|
|
30
100
|
}
|
|
@@ -1,10 +1,32 @@
|
|
|
1
1
|
import 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
|
+
*/
|
|
2
13
|
export declare class DeclarativeEmbedWidget extends DeclarativeWidget {
|
|
3
14
|
constructor();
|
|
4
15
|
static get observedAttributes(): string[];
|
|
5
16
|
attributeChangedCallback(attr: string, oldVal: string, newVal: string): void;
|
|
6
17
|
connectedCallback(): Promise<void>;
|
|
7
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
|
+
*/
|
|
8
30
|
export declare class DeclarativePopupWidget extends DeclarativeWidget {
|
|
9
31
|
constructor();
|
|
10
32
|
static get observedAttributes(): string[];
|