@knocklabs/client 0.9.1 → 0.9.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/CHANGELOG.md +12 -0
- package/dist/types/clients/feed/interfaces.d.ts +21 -3
- package/dist/types/clients/feed/interfaces.d.ts.map +1 -1
- package/package.json +4 -1
- package/src/api.ts +110 -0
- package/src/clients/feed/feed.ts +774 -0
- package/src/clients/feed/index.ts +39 -0
- package/src/clients/feed/interfaces.ts +105 -0
- package/src/clients/feed/store.ts +93 -0
- package/src/clients/feed/types.ts +64 -0
- package/src/clients/feed/utils.ts +23 -0
- package/src/clients/objects/constants.ts +1 -0
- package/src/clients/objects/index.ts +61 -0
- package/src/clients/preferences/index.ts +196 -0
- package/src/clients/preferences/interfaces.ts +34 -0
- package/src/clients/slack/index.ts +89 -0
- package/src/clients/slack/interfaces.ts +36 -0
- package/src/clients/users/index.ts +90 -0
- package/src/clients/users/interfaces.ts +8 -0
- package/src/index.ts +16 -0
- package/src/interfaces.ts +52 -0
- package/src/knock.ts +182 -0
- package/src/networkStatus.ts +19 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.9.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- bc69618: Add react-native to package.json files to fix a bug in our React Native SDK
|
|
8
|
+
|
|
9
|
+
## 0.9.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- fed0f8c: add support for actions in notification feed cells
|
|
14
|
+
|
|
3
15
|
## 0.9.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -20,16 +20,34 @@ export type FetchFeedOptions = {
|
|
|
20
20
|
__loadingType?: NetworkStatus.loading | NetworkStatus.fetchMore;
|
|
21
21
|
__fetchSource?: "socket" | "http";
|
|
22
22
|
} & Omit<FeedClientOptions, "__experimentalCrossBrowserUpdates">;
|
|
23
|
-
export interface
|
|
23
|
+
export interface ContentBlockBase {
|
|
24
|
+
name: string;
|
|
25
|
+
type: "markdown" | "text" | "button_set";
|
|
26
|
+
}
|
|
27
|
+
export interface ActionButton {
|
|
28
|
+
name: string;
|
|
29
|
+
label: string;
|
|
30
|
+
action: string;
|
|
31
|
+
}
|
|
32
|
+
export interface ButtonSetContentBlock extends ContentBlockBase {
|
|
33
|
+
type: "button_set";
|
|
34
|
+
buttons: ActionButton[];
|
|
35
|
+
}
|
|
36
|
+
export interface TextContentBlock extends ContentBlockBase {
|
|
37
|
+
type: "text";
|
|
38
|
+
rendered: string;
|
|
24
39
|
content: string;
|
|
40
|
+
}
|
|
41
|
+
export interface MarkdownContentBlock extends ContentBlockBase {
|
|
42
|
+
type: "markdown";
|
|
25
43
|
rendered: string;
|
|
26
|
-
|
|
27
|
-
name: string;
|
|
44
|
+
content: string;
|
|
28
45
|
}
|
|
29
46
|
export interface NotificationSource {
|
|
30
47
|
key: string;
|
|
31
48
|
version_id: string;
|
|
32
49
|
}
|
|
50
|
+
export type ContentBlock = MarkdownContentBlock | TextContentBlock | ButtonSetContentBlock;
|
|
33
51
|
export interface FeedItem<T = GenericData> {
|
|
34
52
|
__cursor: string;
|
|
35
53
|
id: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../../src/clients/feed/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../../src/clients/feed/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEzD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,qB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AAQ,CAAC;CACrB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knocklabs/client",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"description": "The clientside library for interacting with Knock",
|
|
5
5
|
"homepage": "https://github.com/knocklabs/javascript/tree/main/packages/client",
|
|
6
6
|
"author": "@knocklabs",
|
|
@@ -9,16 +9,19 @@
|
|
|
9
9
|
"module": "dist/esm/index.mjs",
|
|
10
10
|
"types": "dist/types/index.d.ts",
|
|
11
11
|
"typings": "dist/types/index.d.ts",
|
|
12
|
+
"react-native": "./src/index.ts",
|
|
12
13
|
"exports": {
|
|
13
14
|
".": {
|
|
14
15
|
"require": "./dist/cjs/index.js",
|
|
15
16
|
"import": "./dist/esm/index.mjs",
|
|
16
17
|
"types": "./dist/types/index.d.ts",
|
|
18
|
+
"react-native": "./src/index.ts",
|
|
17
19
|
"default": "./dist/esm/index.mjs"
|
|
18
20
|
}
|
|
19
21
|
},
|
|
20
22
|
"files": [
|
|
21
23
|
"dist",
|
|
24
|
+
"src",
|
|
22
25
|
"README.md"
|
|
23
26
|
],
|
|
24
27
|
"repository": {
|
package/src/api.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import axios, { AxiosError, AxiosInstance, AxiosRequestConfig } from "axios";
|
|
2
|
+
import axiosRetry from "axios-retry";
|
|
3
|
+
import { Socket } from "phoenix";
|
|
4
|
+
|
|
5
|
+
type ApiClientOptions = {
|
|
6
|
+
host: string;
|
|
7
|
+
apiKey: string;
|
|
8
|
+
userToken: string | undefined;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export interface ApiResponse {
|
|
12
|
+
// eslint-disable-next-line
|
|
13
|
+
error?: any;
|
|
14
|
+
// eslint-disable-next-line
|
|
15
|
+
body?: any;
|
|
16
|
+
statusCode: "ok" | "error";
|
|
17
|
+
status: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
class ApiClient {
|
|
21
|
+
private host: string;
|
|
22
|
+
private apiKey: string;
|
|
23
|
+
private userToken: string | null;
|
|
24
|
+
private axiosClient: AxiosInstance;
|
|
25
|
+
|
|
26
|
+
public socket: Socket | undefined;
|
|
27
|
+
|
|
28
|
+
constructor(options: ApiClientOptions) {
|
|
29
|
+
this.host = options.host;
|
|
30
|
+
this.apiKey = options.apiKey;
|
|
31
|
+
this.userToken = options.userToken || null;
|
|
32
|
+
|
|
33
|
+
// Create a retryable axios client
|
|
34
|
+
this.axiosClient = axios.create({
|
|
35
|
+
baseURL: this.host,
|
|
36
|
+
headers: {
|
|
37
|
+
Accept: "application/json",
|
|
38
|
+
"Content-Type": "application/json",
|
|
39
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
40
|
+
"X-Knock-User-Token": this.userToken,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
if (typeof window !== "undefined") {
|
|
45
|
+
this.socket = new Socket(`${this.host.replace("http", "ws")}/ws/v1`, {
|
|
46
|
+
params: {
|
|
47
|
+
user_token: this.userToken,
|
|
48
|
+
api_key: this.apiKey,
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// @ts-ignore
|
|
54
|
+
axiosRetry(this.axiosClient, {
|
|
55
|
+
retries: 3,
|
|
56
|
+
retryCondition: this.canRetryRequest,
|
|
57
|
+
retryDelay: axiosRetry.exponentialDelay,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async makeRequest(req: AxiosRequestConfig): Promise<ApiResponse> {
|
|
62
|
+
try {
|
|
63
|
+
const result = await this.axiosClient(req);
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
statusCode: result.status < 300 ? "ok" : "error",
|
|
67
|
+
body: result.data,
|
|
68
|
+
error: undefined,
|
|
69
|
+
status: result.status,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// eslint:disable-next-line
|
|
73
|
+
} catch (e: unknown) {
|
|
74
|
+
console.error(e);
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
statusCode: "error",
|
|
78
|
+
status: 500,
|
|
79
|
+
body: undefined,
|
|
80
|
+
error: e,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
private canRetryRequest(error: AxiosError) {
|
|
86
|
+
// Retry Network Errors.
|
|
87
|
+
if (axiosRetry.isNetworkError(error)) {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (!error.response) {
|
|
92
|
+
// Cannot determine if the request can be retried
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Retry Server Errors (5xx).
|
|
97
|
+
if (error.response.status >= 500 && error.response.status <= 599) {
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Retry if rate limited.
|
|
102
|
+
if (error.response.status === 429) {
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export default ApiClient;
|