@saasquatch/component-boilerplate 1.5.0-8 → 1.5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saasquatch/component-boilerplate",
3
- "version": "1.5.0-8",
3
+ "version": "1.5.0",
4
4
  "private": false,
5
5
  "description": "Boilerplate for writing web components for the SaaSquatch widget environments",
6
6
  "source": "src/index.ts",
@@ -41,7 +41,7 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "@formatjs/intl": "^1.8.2",
44
- "@saasquatch/component-environment": "^1.0.0-5",
44
+ "@saasquatch/component-environment": "^1.0.0",
45
45
  "@saasquatch/dom-context-hooks": "^1.0.0",
46
46
  "@saasquatch/universal-hooks": "^1.0.0",
47
47
  "@wry/equality": "^0.5.2",
@@ -1,9 +0,0 @@
1
- import { Subject } from "rxjs";
2
- import { RequestDocument } from "graphql-request/dist/types";
3
- import { GraphQLClient } from "graphql-request";
4
- export declare class BatchedGraphQLClient extends GraphQLClient {
5
- subject: Subject<unknown>;
6
- constructor(url: string, opts?: any);
7
- superRequest<T>(query: RequestDocument, variables?: any): Promise<T>;
8
- request<T>(query: any, variables: any): Promise<T>;
9
- }
@@ -1 +0,0 @@
1
- export declare function addQuery(queryObj: any): void;
@@ -1,15 +0,0 @@
1
- import { ContextProvider } from "dom-context";
2
- import { WidgetIdent } from "./environment";
3
- declare global {
4
- interface Window {
5
- widgetIdent: WidgetIdent;
6
- squatchLocale: ContextProvider<string>;
7
- }
8
- }
9
- export declare function useLocale(): string | undefined;
10
- /**
11
- * Overide the globally defined Locale context
12
- *
13
- * @param locale the new locale used by the user
14
- */
15
- export declare function setLocale(locale: string): void;
@@ -1,15 +0,0 @@
1
- import { ContextProvider } from "dom-context";
2
- import { WidgetIdent } from "./environment";
3
- declare global {
4
- interface Window {
5
- widgetIdent: WidgetIdent;
6
- squatchProgramId: ContextProvider<string>;
7
- }
8
- }
9
- export declare function useProgramId(): string | undefined;
10
- /**
11
- * Overide the globally defined Program ID context
12
- *
13
- * @param programId the new programID used by the user, or undefined if logged out
14
- */
15
- export declare function setProgramId(programId: string): void;
@@ -1,26 +0,0 @@
1
- import { WidgetIdent } from "./environment";
2
- /**
3
- * Environment provided by components hosted in a web component (`sqh-widget`)
4
- */
5
- export declare type SquatchPortal = typeof SquatchPortalInstance;
6
- declare global {
7
- interface Window {
8
- SquatchPortal?: PortalEnv;
9
- }
10
- }
11
- /**
12
- * Portal env doesn't include User Id
13
- */
14
- export declare type PortalEnv = Pick<WidgetIdent, "tenantAlias" | "appDomain" | "programId"> & { portalAuthUrl: string };
15
- export declare const SquatchPortalInstance: {
16
- readonly localeContext: {
17
- useContext: (host: HTMLElement, options?: Pick<import("dom-context").ListenerOptions<unknown>, "onStatus" | "pollingMs" | "attempts">) => string;
18
- useContextState: (host: HTMLElement, initialState?: string) => readonly [string, (value: string | ((previousState?: string) => string)) => void, import("dom-context").ContextProvider<string>];
19
- Listener: new (o: Pick<import("dom-context").ListenerOptions<string>, "element" | "onChange" | "onStatus" | "pollingMs" | "attempts">) => import("dom-context").ContextListener<string>;
20
- listen(o: Pick<import("dom-context").ListenerOptions<string>, "element" | "onChange" | "onStatus" | "pollingMs" | "attempts">): import("dom-context").ContextListener<string>;
21
- Provider: new (o: Pick<import("dom-context").ProviderOptions<string>, "element" | "initialState">) => import("dom-context").ContextProvider<string>;
22
- provide(o: Pick<import("dom-context").ProviderOptions<string>, "element" | "initialState">): import("dom-context").ContextProvider<string>;
23
- provideGlobally(next: string): void;
24
- name: string;
25
- };
26
- };
@@ -1,51 +0,0 @@
1
- import { ContextProvider } from "dom-context";
2
- import debugFn from "debug";
3
- export declare const debug: debugFn.Debugger;
4
- export declare type UserIdentity = {
5
- id: string;
6
- accountId: string;
7
- jwt?: string;
8
- managedIdentity?: {
9
- email: string;
10
- emailVerified: boolean;
11
- sessionData?: {
12
- [key: string]: any;
13
- };
14
- };
15
- };
16
- export interface DecodedSquatchJWT {
17
- exp?: number;
18
- user?: {
19
- accountId: string;
20
- id: string;
21
- };
22
- }
23
- export interface DecodedWidgetAPIJWT {
24
- exp?: number;
25
- sub?: string;
26
- }
27
- declare global {
28
- interface Window {
29
- squatchUserIdentity: ContextProvider<UserIdentity>;
30
- }
31
- }
32
- /**
33
- * Overide the globally defined user context, and persists the user identity in local storage
34
- *
35
- * @param identity the new identity of the user, or undefined if logged out
36
- */
37
- export declare function setUserIdentity(identity?: UserIdentity): void;
38
- /**
39
- * Gets the SessionData of the current user, or undefined if logged out
40
- */
41
- export declare function useSessionData(): {
42
- [key: string]: any;
43
- } | undefined;
44
- /**
45
- * Gets the JWT of the current user, or undefined if logged out
46
- */
47
- export declare function useToken(): string | undefined;
48
- /**
49
- * Get the IDs and JWT of the current user, or undefined if logged out
50
- */
51
- export declare function useUserIdentity(): UserIdentity | undefined;
@@ -1,134 +0,0 @@
1
- /**
2
- * Environment provided by components hosted in a web component (`sqh-widget`)
3
- */
4
- declare global {
5
- interface Window {
6
- SquatchPortal?: PortalEnv;
7
- }
8
- }
9
- /**
10
- * Portal env doesn't include User Id
11
- */
12
- export declare type PortalEnv = Pick<WidgetIdent, "tenantAlias" | "appDomain" | "programId">;
13
- /**
14
- * Program ID context helpers
15
- */
16
- export { useProgramId, setProgramId } from "./ProgramContext";
17
- /**
18
- * Locale context helpers
19
- */
20
- export { useLocale } from "./LocaleContext";
21
- /**
22
- * Provided by the SaaSquatch GraphQL backend when a widget is rendered.
23
- *
24
- * Source: https://github.com/saasquatch/saasquatch/blob/805e51284f818f8656b6458bcee6181f378819d3/packages/saasquatch-core/app/saasquatch/controllers/api/widget/WidgetApi.java
25
- *
26
- */
27
- export interface WidgetIdent {
28
- tenantAlias: string;
29
- appDomain: string;
30
- token: string;
31
- userId: string;
32
- accountId: string;
33
- locale?: string;
34
- engagementMedium?: "POPUP" | "EMBED";
35
- programId?: string;
36
- env?: string;
37
- }
38
- /**
39
- * An interface for interacting with the SaaSquatch Admin Portal.
40
- *
41
- * Used for rendering widgets in a preview/demo mode.
42
- */
43
- export interface SquatchAdmin {
44
- /**
45
- * Provides a way of providing user feedback when a widget is rendered in the SaaSquatch admin portal
46
- *
47
- * @param text
48
- */
49
- showMessage(text: string): void;
50
- }
51
- /**
52
- * Type for the Javascript environment added by https://github.com/saasquatch/squatch-android
53
- *
54
- * Should exist as `window.SquatchAndroid`
55
- */
56
- export interface SquatchAndroid {
57
- /**
58
- *
59
- * @param shareLink
60
- * @param messageLink fallback URL to redirect to if the app is not installed
61
- */
62
- shareOnFacebook(shareLink: string, messageLink: string): void;
63
- /**
64
- * Shows a native Android toast
65
- *
66
- * @param text
67
- */
68
- showToast(text: string): void;
69
- }
70
- /**
71
- * An interface provided by Squatch.js V2 for widgets.
72
- *
73
- * See: https://github.com/saasquatch/squatch-js/blob/8f2b218c9d55567e0cc12d27d635a5fb545e6842/src/widgets/Widget.ts#L47
74
- *
75
- */
76
- export interface SquatchJS2 {
77
- /**
78
- * Opens the current popup widget (if loaded as a popup)
79
- */
80
- open?: () => void;
81
- /**
82
- * Closes the current popup widget (if loaded as a popup)
83
- */
84
- close?: () => void;
85
- /**
86
- * DEPRECATED used to update user details from inside the widget.
87
- *
88
- * Should no longer be used. Replace with natively using the GraphQL API and re-rendering locally. Will be removed in a future version of Squatch.js
89
- *
90
- * @deprecated
91
- */
92
- reload(userDetails: {
93
- email: string;
94
- firstName: string;
95
- lastName: string;
96
- }, jwt: string): void;
97
- }
98
- export declare type Environment = EnvironmentSDK["type"];
99
- export declare type EnvironmentSDK = {
100
- type: "SquatchJS2";
101
- api: SquatchJS2;
102
- widgetIdent: WidgetIdent;
103
- } | {
104
- type: "SquatchAndroid";
105
- android: SquatchAndroid;
106
- widgetIdent: WidgetIdent;
107
- } | {
108
- type: "SquatchPortal";
109
- env: PortalEnv;
110
- } | {
111
- type: "SquatchAdmin";
112
- adminSDK: SquatchAdmin;
113
- } | {
114
- type: "None";
115
- };
116
- /**
117
- * Get the type of environment that this widget is being rendered in
118
- *
119
- * Should never return null.
120
- */
121
- export declare function getEnvironment(): Environment;
122
- /**
123
- * Get the SDK for interacting with the host environment
124
- */
125
- export declare function getEnvironmentSDK(): EnvironmentSDK;
126
- export declare function isDemo(): boolean;
127
- export declare function useTenantAlias(): string;
128
- export declare function useAppDomain(): string;
129
- export declare type UserId = {
130
- id: string;
131
- accountId: string;
132
- };
133
- declare type EngagementMedium = "EMBED" | "POPUP";
134
- export declare function useEngagementMedium(): EngagementMedium;
@@ -1,5 +0,0 @@
1
- export * from "./environment";
2
- /**
3
- * User identity context helpers
4
- */
5
- export { useUserIdentity, useToken, setUserIdentity, useSessionData, } from "./UserIdentityContext";
@@ -1,45 +0,0 @@
1
- import { RequestDocument } from "graphql-request/dist/types";
2
- export declare type GqlType = RequestDocument;
3
- export interface BaseQueryData<T = unknown> {
4
- loading: boolean;
5
- data?: T;
6
- errors?: GraphQlRequestError<T>;
7
- }
8
- export declare type QueryData<T> = BaseQueryData<T> & {
9
- refetch: (variables?: unknown) => unknown;
10
- };
11
- /**
12
- * Note: reverse-engineered from a returned error. May not capture all error types.
13
- */
14
- export declare type GraphQlRequestError<T> = {
15
- response: {
16
- errors: [
17
- {
18
- message: string;
19
- locations: [{
20
- line: number;
21
- column: number;
22
- }];
23
- path: string[];
24
- extensions: {
25
- apiError: {
26
- message: string;
27
- statusCode: number;
28
- apiErrorCode: string;
29
- rsCode: string;
30
- };
31
- classification: string;
32
- };
33
- }
34
- ];
35
- data: Partial<T>;
36
- status: number;
37
- };
38
- request: {
39
- query: string;
40
- variables: {
41
- [key: string]: unknown;
42
- };
43
- };
44
- };
45
- export declare function useBatchedQuery<T = any>(query: GqlType, initialState: BaseQueryData<T>): [BaseQueryData<T>, (variables: unknown) => unknown];
@@ -1,30 +0,0 @@
1
- import { RequestDocument } from "graphql-request/dist/types";
2
- declare type GqlType = RequestDocument;
3
- interface CustomQueryData<T = unknown, E = any> {
4
- loading: boolean;
5
- data?: T;
6
- errors?: CustomGraphQlRequestError<T, E>;
7
- }
8
- declare type QueryData<T> = CustomQueryData<T> & {
9
- refetch: (variables?: unknown) => unknown;
10
- };
11
- declare type CustomGraphQlRequestError<T, E> = {
12
- response: {
13
- errors: E[];
14
- data: Partial<T>;
15
- status: number;
16
- };
17
- request: {
18
- query: string;
19
- variables: {
20
- [key: string]: unknown;
21
- };
22
- };
23
- };
24
- export declare function useCustomQuery<T = any, E = any>(query: GqlType, initialState: CustomQueryData<T>, url: string): [CustomQueryData<T>, (variables: unknown) => unknown];
25
- export declare const customQueryHooksFactory: <E>(url: string) => {
26
- useQuery: <T = any>(query: GqlType, variables: unknown, skip?: boolean) => QueryData<T>;
27
- useLazyQuery: <T_1 = any>(query: GqlType) => [(e: unknown) => unknown, QueryData<T_1>];
28
- useMutation: <T_2 = any>(query: GqlType) => [(e: unknown) => unknown, CustomQueryData<T_2, any>];
29
- };
30
- export {};
@@ -1,13 +0,0 @@
1
- import { QueryData } from "../graphql/useBaseQuery";
2
- interface ManagedIdentityResult {
3
- managedIdentity: {
4
- email: string;
5
- emailVerified: boolean;
6
- sessionData: Record<string, any>;
7
- };
8
- }
9
- export declare function useManagedIdentityQuery(): [
10
- () => unknown,
11
- QueryData<ManagedIdentityResult>
12
- ];
13
- export {};