@suprsend/web-sdk 2.0.0 → 3.0.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/README.md +7 -0
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/es/index.js +861 -458
- package/dist/es/index.js.map +1 -1
- package/dist/types/api.d.ts +1 -2
- package/dist/types/feed.d.ts +54 -0
- package/dist/types/index.d.ts +2 -44
- package/dist/types/interface.d.ts +94 -3
- package/dist/types/main.d.ts +45 -0
- package/dist/types/preferences.d.ts +2 -2
- package/package.json +4 -2
package/dist/types/index.d.ts
CHANGED
|
@@ -1,45 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { default as User } from './user';
|
|
4
|
-
import { default as WebPush } from './webpush';
|
|
5
|
-
import { Emitter } from 'mitt';
|
|
6
|
-
|
|
7
|
-
export declare class SuprSend {
|
|
8
|
-
host: string;
|
|
9
|
-
publicApiKey: string;
|
|
10
|
-
distinctId: unknown;
|
|
11
|
-
userToken?: string;
|
|
12
|
-
vapidKey: string;
|
|
13
|
-
swFileName: string;
|
|
14
|
-
private apiClient;
|
|
15
|
-
private userTokenExpirationTimer;
|
|
16
|
-
authenticateOptions?: AuthenticateOptions;
|
|
17
|
-
readonly user: User;
|
|
18
|
-
readonly webpush: WebPush;
|
|
19
|
-
readonly emitter: Emitter<EmitterEvents>;
|
|
20
|
-
constructor(publicApiKey: string, options?: SuprSendOptions);
|
|
21
|
-
private handleRefreshUserToken;
|
|
22
|
-
client(): ApiClient;
|
|
23
|
-
eventApi(payload: Dictionary): Promise<import('./interface').ApiResponse>;
|
|
24
|
-
/**
|
|
25
|
-
* Used to authenticate user. Usually called just after successful login and on reload of loggedin route to re-authenticate loggedin user.
|
|
26
|
-
* In production env's userToken is mandatory for security purposes.
|
|
27
|
-
*/
|
|
28
|
-
identify(distinctId: unknown, userToken?: string, options?: AuthenticateOptions): Promise<import('./interface').ApiResponse>;
|
|
29
|
-
/**
|
|
30
|
-
* Check's if SuprSend instance is authenticated. To check if userToken is also present pass true.
|
|
31
|
-
*/
|
|
32
|
-
isIdentified(checkUserToken?: boolean): boolean;
|
|
33
|
-
/**
|
|
34
|
-
* Used to trigger events to suprsend.
|
|
35
|
-
*/
|
|
36
|
-
track(event: string, properties?: Dictionary): Promise<import('./interface').ApiResponse>;
|
|
37
|
-
/**
|
|
38
|
-
* Clears user related data attached to SuprSend instance. Usually called during logout.
|
|
39
|
-
*/
|
|
40
|
-
reset(options?: {
|
|
41
|
-
unsubscribePush?: boolean;
|
|
42
|
-
}): Promise<import('./interface').ApiResponse>;
|
|
43
|
-
}
|
|
44
|
-
export default SuprSend;
|
|
1
|
+
export { default as SuprSend } from './main';
|
|
2
|
+
export { Feed } from './feed';
|
|
45
3
|
export * from './interface';
|
|
@@ -6,7 +6,7 @@ export interface SuprSendOptions {
|
|
|
6
6
|
}
|
|
7
7
|
export type RefreshTokenCallback = (oldUserToken: string, tokenPayload: Dictionary) => Promise<string>;
|
|
8
8
|
export interface AuthenticateOptions {
|
|
9
|
-
refreshUserToken
|
|
9
|
+
refreshUserToken?: RefreshTokenCallback;
|
|
10
10
|
}
|
|
11
11
|
export interface ResponseOptions {
|
|
12
12
|
status: RESPONSE_STATUS.ERROR | RESPONSE_STATUS.SUCCESS;
|
|
@@ -66,9 +66,14 @@ export type EmitterEvents = {
|
|
|
66
66
|
preferences_updated: PreferenceApiResponse;
|
|
67
67
|
preferences_error: ApiResponse;
|
|
68
68
|
};
|
|
69
|
+
export type InboxEmitterEvents = {
|
|
70
|
+
'feed.new_notification': IRemoteNotification;
|
|
71
|
+
'feed.store_update': IFeedData;
|
|
72
|
+
'*': undefined;
|
|
73
|
+
};
|
|
69
74
|
export interface HandleRequest {
|
|
70
75
|
type: 'get' | 'post' | 'patch';
|
|
71
|
-
|
|
76
|
+
url: string;
|
|
72
77
|
payload?: Dictionary;
|
|
73
78
|
}
|
|
74
79
|
export interface ValidatedDataOptions {
|
|
@@ -80,10 +85,96 @@ export declare enum ERROR_TYPE {
|
|
|
80
85
|
NETWORK_ERROR = "NETWORK_ERROR",
|
|
81
86
|
UNKNOWN_ERROR = "UNKNOWN_ERROR",
|
|
82
87
|
PERMISSION_DENIED = "PERMISSION_DENIED",
|
|
83
|
-
UNSUPPORTED_ACTION = "UNSUPPORTED_ACTION"
|
|
88
|
+
UNSUPPORTED_ACTION = "UNSUPPORTED_ACTION",
|
|
89
|
+
NOT_FOUND = "NOT_FOUND"
|
|
84
90
|
}
|
|
85
91
|
export declare enum RESPONSE_STATUS {
|
|
86
92
|
SUCCESS = "success",
|
|
87
93
|
ERROR = "error"
|
|
88
94
|
}
|
|
95
|
+
export interface IStore {
|
|
96
|
+
storeId: string;
|
|
97
|
+
label: string;
|
|
98
|
+
query?: {
|
|
99
|
+
tags?: string | string[];
|
|
100
|
+
categories?: string | string[];
|
|
101
|
+
read?: boolean;
|
|
102
|
+
archived?: boolean;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
export declare enum ApiResponseStatus {
|
|
106
|
+
INITIAL = "INITIAL",// Before any request is made (or after a reset).
|
|
107
|
+
LOADING = "LOADING",// The initial API call is in progress
|
|
108
|
+
SUCCESS = "SUCCESS",// The API call was successful, and data has been received
|
|
109
|
+
ERROR = "ERROR",// The API call failed (network issue, server issue, etc.)
|
|
110
|
+
FETCHING_MORE = "FETCHING_MORE"
|
|
111
|
+
}
|
|
112
|
+
export interface IActionObject {
|
|
113
|
+
name: string;
|
|
114
|
+
url: string;
|
|
115
|
+
open_in_new_tab?: boolean;
|
|
116
|
+
}
|
|
117
|
+
export interface IAvatarObject {
|
|
118
|
+
action_url?: string;
|
|
119
|
+
avatar_url: string;
|
|
120
|
+
}
|
|
121
|
+
export interface ISubTextObject {
|
|
122
|
+
action_url?: string;
|
|
123
|
+
text: string;
|
|
124
|
+
}
|
|
125
|
+
export interface IRemoteNotificationMessage {
|
|
126
|
+
header?: string;
|
|
127
|
+
schema: string;
|
|
128
|
+
text: string;
|
|
129
|
+
url?: string;
|
|
130
|
+
open_in_new_tab?: boolean;
|
|
131
|
+
extra_data?: string;
|
|
132
|
+
actions?: IActionObject[];
|
|
133
|
+
avatar?: IAvatarObject;
|
|
134
|
+
subtext?: ISubTextObject;
|
|
135
|
+
}
|
|
136
|
+
export interface IRemoteNotification {
|
|
137
|
+
n_id: string;
|
|
138
|
+
n_category: string;
|
|
139
|
+
created_on: number;
|
|
140
|
+
seen_on?: number;
|
|
141
|
+
read_on?: number | null;
|
|
142
|
+
interacted_on?: number;
|
|
143
|
+
archived?: boolean;
|
|
144
|
+
tags?: string[];
|
|
145
|
+
expiry?: number;
|
|
146
|
+
is_expiry_visible: boolean;
|
|
147
|
+
is_pinned: boolean;
|
|
148
|
+
can_user_unpin?: boolean;
|
|
149
|
+
message: IRemoteNotificationMessage;
|
|
150
|
+
}
|
|
151
|
+
export interface IFeedOptions {
|
|
152
|
+
tenantId?: string;
|
|
153
|
+
pageSize?: number;
|
|
154
|
+
stores?: IStore[] | null;
|
|
155
|
+
host?: {
|
|
156
|
+
socketHost?: string;
|
|
157
|
+
apiHost?: string;
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
export interface INotificationStore {
|
|
161
|
+
notifications: IRemoteNotification[];
|
|
162
|
+
store: IStore;
|
|
163
|
+
pageInfo: {
|
|
164
|
+
total: number;
|
|
165
|
+
currentPage: number;
|
|
166
|
+
totalPages: number;
|
|
167
|
+
pageSize: number;
|
|
168
|
+
};
|
|
169
|
+
meta: Record<string, number>;
|
|
170
|
+
apiStatus: ApiResponseStatus;
|
|
171
|
+
_firstFetchedTimeStamp: number | null;
|
|
172
|
+
}
|
|
173
|
+
export interface IFeedData extends Omit<INotificationStore, '_firstFetchedTimeStamp'> {
|
|
174
|
+
}
|
|
175
|
+
export interface IInboxFetchOptions {
|
|
176
|
+
page?: number;
|
|
177
|
+
pageSize?: number;
|
|
178
|
+
storeId?: IStore;
|
|
179
|
+
}
|
|
89
180
|
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Emitter } from 'mitt';
|
|
2
|
+
import { SuprSendOptions, Dictionary, EmitterEvents, AuthenticateOptions } from './interface';
|
|
3
|
+
import { default as ApiClient } from './api';
|
|
4
|
+
import { default as User } from './user';
|
|
5
|
+
import { default as WebPush } from './webpush';
|
|
6
|
+
import { default as FeedsFactory } from './feed';
|
|
7
|
+
|
|
8
|
+
export default class SuprSend {
|
|
9
|
+
host: string;
|
|
10
|
+
publicApiKey: string;
|
|
11
|
+
distinctId: unknown;
|
|
12
|
+
userToken?: string;
|
|
13
|
+
vapidKey: string;
|
|
14
|
+
swFileName: string;
|
|
15
|
+
private apiClient;
|
|
16
|
+
private userTokenExpirationTimer;
|
|
17
|
+
authenticateOptions?: AuthenticateOptions;
|
|
18
|
+
readonly user: User;
|
|
19
|
+
readonly webpush: WebPush;
|
|
20
|
+
readonly feeds: FeedsFactory;
|
|
21
|
+
readonly emitter: Emitter<EmitterEvents>;
|
|
22
|
+
constructor(publicApiKey: string, options?: SuprSendOptions);
|
|
23
|
+
private handleRefreshUserToken;
|
|
24
|
+
client(): ApiClient;
|
|
25
|
+
eventApi(payload: Dictionary): Promise<import('./interface').ApiResponse>;
|
|
26
|
+
/**
|
|
27
|
+
* Used to authenticate user. Usually called just after successful login and on reload of loggedin route to re-authenticate loggedin user.
|
|
28
|
+
* In production env's userToken is mandatory for security purposes.
|
|
29
|
+
*/
|
|
30
|
+
identify(distinctId: unknown, userToken?: string, options?: AuthenticateOptions): Promise<import('./interface').ApiResponse>;
|
|
31
|
+
/**
|
|
32
|
+
* Check's if SuprSend instance is authenticated. To check if userToken is also present pass true.
|
|
33
|
+
*/
|
|
34
|
+
isIdentified(checkUserToken?: boolean): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Used to trigger events to suprsend.
|
|
37
|
+
*/
|
|
38
|
+
track(event: string, properties?: Dictionary): Promise<import('./interface').ApiResponse>;
|
|
39
|
+
/**
|
|
40
|
+
* Clears user related data attached to SuprSend instance. Usually called during logout.
|
|
41
|
+
*/
|
|
42
|
+
reset(options?: {
|
|
43
|
+
unsubscribePush?: boolean;
|
|
44
|
+
}): Promise<import('./interface').ApiResponse>;
|
|
45
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SuprSend } from './
|
|
1
|
+
import { default as SuprSend } from './main';
|
|
2
2
|
import { Dictionary, PreferenceData, PreferenceOptions, ChannelLevelPreferenceOptions } from './interface';
|
|
3
3
|
|
|
4
4
|
export default class Preferences {
|
|
@@ -12,7 +12,7 @@ export default class Preferences {
|
|
|
12
12
|
private validateQueryParams;
|
|
13
13
|
set data(value: PreferenceData);
|
|
14
14
|
get data(): PreferenceData;
|
|
15
|
-
|
|
15
|
+
getUrl(path: string, qp?: Dictionary): string;
|
|
16
16
|
/**
|
|
17
17
|
* Used to get user's whole preferences data.
|
|
18
18
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@suprsend/web-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "The client side javascript library for interacting with SuprSend",
|
|
5
5
|
"author": "SuprSend Developers",
|
|
6
6
|
"type": "module",
|
|
@@ -53,6 +53,8 @@
|
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"jwt-decode": "3.1.2",
|
|
56
|
-
"mitt": "^3.0.1"
|
|
56
|
+
"mitt": "^3.0.1",
|
|
57
|
+
"socket.io-client": "^4.8.1",
|
|
58
|
+
"zustand": "^5.0.1"
|
|
57
59
|
}
|
|
58
60
|
}
|