@saasquatch/squatch-js 2.5.0-0 → 2.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/dist/types.d.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  import Widget from "./widgets/Widget";
2
+ export declare type WithRequired<T, K extends keyof T> = T & {
3
+ [P in K]-?: T[P];
4
+ };
2
5
  /**
3
6
  * When you load Squatch.js you need to provide these configuration options.
4
7
  *
@@ -23,12 +26,14 @@ export interface ConfigOptions {
23
26
  * @param jwt the JSON Web Token (JWT) that is used
24
27
  */
25
28
  export interface WidgetConfig {
26
- user: User;
29
+ user?: User;
27
30
  widgetType?: WidgetType;
28
31
  engagementMedium?: EngagementMedium;
29
32
  container?: HTMLElement | string;
30
33
  trigger?: string;
31
34
  jwt?: JWT;
35
+ locale?: string;
36
+ displayOnLoad?: boolean;
32
37
  }
33
38
  /**
34
39
  * @param user The user details
@@ -72,18 +77,19 @@ export declare type EngagementMedium =
72
77
  /** Displays the widget embedded in the page. Create an {@link EmbedWidget} */
73
78
  | "EMBED";
74
79
  export declare type WidgetContext = {
75
- type: "cookie" | "error";
80
+ type: "cookie" | "error" | "passwordless";
76
81
  engagementMedium?: EngagementMedium;
77
82
  container?: HTMLElement | string;
78
83
  trigger?: string;
84
+ displayOnLoad?: boolean;
79
85
  } | {
80
86
  type: "upsert";
81
- user: User;
87
+ user?: User | null;
82
88
  engagementMedium?: EngagementMedium;
83
89
  container?: HTMLElement | string;
84
90
  trigger?: string;
85
91
  };
86
- export declare type WidgetContextType = "upsert" | "cookie" | "error";
92
+ export declare type WidgetContextType = "upsert" | "cookie" | "error" | "passwordless";
87
93
  /**
88
94
  * WidgetType is an enum for types of ways a Widget can be displayed.
89
95
  */
@@ -94,3 +100,7 @@ export declare type WidgetType =
94
100
  | "CONVERSION_WIDGET" | string;
95
101
  export declare type ShareMedium = string;
96
102
  export declare type JWT = string;
103
+ export declare type ReferralCookie = {
104
+ codes: string[];
105
+ encodedCookie: string;
106
+ };
@@ -1 +1,2 @@
1
+ export declare function b64decode(input: any): string;
1
2
  export declare function _pushCookie(): void;
@@ -1,5 +1,6 @@
1
1
  import { JWT } from "../types";
2
- export declare function doGet(url: any, jwt?: string): Promise<any>;
2
+ export declare function doQuery(url: string, query: string, variables: any, token: string | undefined): Promise<any>;
3
+ export declare function doGet<T>(url: any, jwt?: string): Promise<T>;
3
4
  /**
4
5
  * @hidden
5
6
  *
@@ -0,0 +1,14 @@
1
+ import { ConfigOptions, WidgetConfig } from "../types";
2
+ export declare function _getAutoConfig(configIn: ConfigOptions): {
3
+ widgetConfig: WidgetConfig;
4
+ squatchConfig: ConfigOptions;
5
+ } | undefined;
6
+ /**
7
+ * Deconstructs _saasquatchExtra into domain, tenantAlias, and widgetConfig
8
+ * @param obj {Record<string, any>} Expected to be of the form `{ [appDomain]: { [tenantAlias]: { autoPopupWidgetType: [widgetType], [rest]?: ... } } }`
9
+ */
10
+ export declare function convertExtraToConfig(obj: Record<string, any>): {
11
+ domain: string | undefined;
12
+ tenantAlias: string;
13
+ widgetConfig: any;
14
+ };
@@ -10,5 +10,7 @@ declare type Required<T> = T extends object ? {
10
10
  [P in keyof T]-?: NonNullable<T[P]>;
11
11
  } : T;
12
12
  export declare function validateConfig(raw: unknown): Required<ConfigOptions>;
13
+ export declare function validateLocale(locale?: string): string | undefined;
13
14
  export declare function validateWidgetConfig(raw: unknown): WidgetConfig;
15
+ export declare function validatePasswordlessConfig(raw: unknown): WidgetConfig;
14
16
  export {};
@@ -1,5 +1,5 @@
1
1
  import WidgetApi from "../api/WidgetApi";
2
- import { WidgetResult } from "../types";
2
+ import { WidgetResult, WithRequired } from "../types";
3
3
  import { ConfigOptions, WidgetConfig } from "../types";
4
4
  /**
5
5
  *
@@ -46,7 +46,7 @@ export default class Widgets {
46
46
  *
47
47
  * @return {Promise<WidgetResult>} json object if true, with a Widget and user details.
48
48
  */
49
- upsertUser(config: WidgetConfig): Promise<{
49
+ upsertUser(config: WithRequired<WidgetConfig, "user">): Promise<{
50
50
  widget: any;
51
51
  user: any;
52
52
  }>;
@@ -65,7 +65,7 @@ export default class Widgets {
65
65
  *
66
66
  * @return {Promise<WidgetResult>} json object if true, with a Widget and user details.
67
67
  */
68
- render(config: WidgetConfig): Promise<WidgetResult>;
68
+ render(config: WidgetConfig): Promise<WidgetResult | undefined>;
69
69
  /**
70
70
  * Autofills a referral code into an element when someone has been referred.
71
71
  * Uses {@link WidgetApi.squatchReferralCookie} behind the scenes.
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@saasquatch/squatch-js",
3
- "version": "2.5.0-0",
3
+ "version": "2.5.0",
4
4
  "description": "The official Referral SaaSquatch Javascript Web/Browser SDK https://docs.referralsaasquatch.com/developer/squatchjs/",
5
5
  "license": "MIT",
6
+ "author": "ReferralSaaSquatch.com, Inc.",
6
7
  "types": "dist/squatch.d.ts",
7
8
  "source": "src/squatch.ts",
8
9
  "main": "dist/squatch.js",
@@ -28,7 +29,7 @@
28
29
  "build:es": "microbundle --target node --format cjs,es",
29
30
  "build:umd": "webpack",
30
31
  "build": "run-s build:es build:umd",
31
- "watch": "microbundle watch",
32
+ "watch": "webpack --watch",
32
33
  "declaration": "tsc --emitDeclarationOnly",
33
34
  "test:browser": "cucumber-js",
34
35
  "test:webkit": "cross-env BROWSER=webkit cucumber-js",
@@ -41,7 +42,7 @@
41
42
  "preversion": "run-s build",
42
43
  "demo": "msw init demo/dist/ --save && run-p static parcel",
43
44
  "demo:deploy": "run-s parcel:build parcel:deploy",
44
- "static": "serve dist",
45
+ "static": "serve -l 3333 -s dist",
45
46
  "parcel": "cd demo && parcel index.html",
46
47
  "parcel:build": "cd demo && parcel build index.html",
47
48
  "parcel:deploy": "surge demo/dist -d squathjs-demo.surge.sh"
@@ -75,7 +76,7 @@
75
76
  "npm-run-all": "^4.1.5",
76
77
  "parcel": "^1.12.3",
77
78
  "parcel-bundler": "^1.12.4",
78
- "playwright": "^1.28.1",
79
+ "playwright": "^1.33.0-alpha-mar-29-2023",
79
80
  "react": "^16.13.1",
80
81
  "react-bootstrap": "^1.0.1",
81
82
  "react-dom": "^16.13.1",
@@ -99,6 +100,6 @@
99
100
  },
100
101
  "browserslist": "> 0.25%, not dead",
101
102
  "msw": {
102
- "workerDirectory": "demo\\dist"
103
+ "workerDirectory": "demo/dist"
103
104
  }
104
- }
105
+ }