@knocklabs/client 0.8.14 → 0.8.16
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 +22 -13
- package/dist/cjs/api.js +33 -56
- package/dist/cjs/api.js.map +1 -1
- package/dist/cjs/clients/feed/feed.js +492 -624
- package/dist/cjs/clients/feed/feed.js.map +1 -1
- package/dist/cjs/clients/feed/index.js +1 -10
- package/dist/cjs/clients/feed/index.js.map +1 -1
- package/dist/cjs/clients/feed/interfaces.js.map +1 -1
- package/dist/cjs/clients/feed/store.js +4 -15
- package/dist/cjs/clients/feed/store.js.map +1 -1
- package/dist/cjs/clients/feed/types.js.map +1 -1
- package/dist/cjs/clients/feed/utils.js +0 -5
- package/dist/cjs/clients/feed/utils.js.map +1 -1
- package/dist/cjs/clients/preferences/index.js +216 -249
- package/dist/cjs/clients/preferences/index.js.map +1 -1
- package/dist/cjs/clients/preferences/interfaces.js.map +1 -1
- package/dist/cjs/clients/users/index.js +185 -0
- package/dist/cjs/clients/users/index.js.map +1 -0
- package/dist/cjs/clients/users/interfaces.js +6 -0
- package/dist/cjs/clients/users/interfaces.js.map +1 -0
- package/dist/cjs/index.js +15 -21
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/interfaces.js.map +1 -1
- package/dist/cjs/knock.js +11 -21
- package/dist/cjs/knock.js.map +1 -1
- package/dist/cjs/networkStatus.js +3 -6
- package/dist/cjs/networkStatus.js.map +1 -1
- package/dist/esm/api.js +9 -21
- package/dist/esm/api.js.map +1 -1
- package/dist/esm/clients/feed/feed.js +69 -149
- package/dist/esm/clients/feed/feed.js.map +1 -1
- package/dist/esm/clients/feed/index.js +0 -5
- package/dist/esm/clients/feed/index.js.map +1 -1
- package/dist/esm/clients/feed/interfaces.js.map +1 -1
- package/dist/esm/clients/feed/store.js +2 -8
- package/dist/esm/clients/feed/store.js.map +1 -1
- package/dist/esm/clients/feed/types.js.map +1 -1
- package/dist/esm/clients/feed/utils.js +0 -1
- package/dist/esm/clients/feed/utils.js.map +1 -1
- package/dist/esm/clients/preferences/index.js +35 -25
- package/dist/esm/clients/preferences/index.js.map +1 -1
- package/dist/esm/clients/preferences/interfaces.js.map +1 -1
- package/dist/esm/clients/users/index.js +84 -0
- package/dist/esm/clients/users/index.js.map +1 -0
- package/dist/esm/clients/users/interfaces.js +2 -0
- package/dist/esm/clients/users/interfaces.js.map +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/interfaces.js.map +1 -1
- package/dist/esm/knock.js +10 -22
- package/dist/esm/knock.js.map +1 -1
- package/dist/esm/networkStatus.js +3 -5
- package/dist/esm/networkStatus.js.map +1 -1
- package/dist/types/api.d.ts +1 -1
- package/dist/types/api.d.ts.map +1 -1
- package/dist/types/clients/feed/feed.d.ts +1 -1
- package/dist/types/clients/feed/feed.d.ts.map +1 -1
- package/dist/types/clients/feed/interfaces.d.ts +2 -1
- package/dist/types/clients/feed/interfaces.d.ts.map +1 -1
- package/dist/types/clients/feed/types.d.ts +10 -10
- package/dist/types/clients/feed/types.d.ts.map +1 -1
- package/dist/types/clients/preferences/index.d.ts +27 -0
- package/dist/types/clients/preferences/index.d.ts.map +1 -1
- package/dist/types/clients/preferences/interfaces.d.ts +7 -4
- package/dist/types/clients/preferences/interfaces.d.ts.map +1 -1
- package/dist/types/clients/users/index.d.ts +16 -0
- package/dist/types/clients/users/index.d.ts.map +1 -0
- package/dist/types/clients/users/interfaces.d.ts +8 -0
- package/dist/types/clients/users/interfaces.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/interfaces.d.ts +6 -2
- package/dist/types/interfaces.d.ts.map +1 -1
- package/dist/types/knock.d.ts +2 -0
- package/dist/types/knock.d.ts.map +1 -1
- package/package.json +15 -10
package/dist/esm/api.js
CHANGED
|
@@ -3,23 +3,18 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
3
3
|
import axios from "axios";
|
|
4
4
|
import axiosRetry from "axios-retry";
|
|
5
5
|
import { Socket } from "phoenix";
|
|
6
|
-
|
|
7
6
|
class ApiClient {
|
|
8
7
|
constructor(options) {
|
|
9
8
|
_defineProperty(this, "host", void 0);
|
|
10
|
-
|
|
11
9
|
_defineProperty(this, "apiKey", void 0);
|
|
12
|
-
|
|
13
10
|
_defineProperty(this, "userToken", void 0);
|
|
14
|
-
|
|
15
11
|
_defineProperty(this, "axiosClient", void 0);
|
|
16
|
-
|
|
17
12
|
_defineProperty(this, "socket", void 0);
|
|
18
|
-
|
|
19
13
|
this.host = options.host;
|
|
20
14
|
this.apiKey = options.apiKey;
|
|
21
|
-
this.userToken = options.userToken || null;
|
|
15
|
+
this.userToken = options.userToken || null;
|
|
22
16
|
|
|
17
|
+
// Create a retryable axios client
|
|
23
18
|
this.axiosClient = axios.create({
|
|
24
19
|
baseURL: this.host,
|
|
25
20
|
headers: {
|
|
@@ -29,7 +24,6 @@ class ApiClient {
|
|
|
29
24
|
"X-Knock-User-Token": this.userToken
|
|
30
25
|
}
|
|
31
26
|
});
|
|
32
|
-
|
|
33
27
|
if (typeof window !== "undefined") {
|
|
34
28
|
this.socket = new Socket("".concat(this.host.replace("http", "ws"), "/ws/v1"), {
|
|
35
29
|
params: {
|
|
@@ -38,17 +32,14 @@ class ApiClient {
|
|
|
38
32
|
}
|
|
39
33
|
});
|
|
40
34
|
}
|
|
41
|
-
|
|
42
35
|
axiosRetry(this.axiosClient, {
|
|
43
36
|
retries: 3,
|
|
44
37
|
retryCondition: this.canRetryRequest,
|
|
45
38
|
retryDelay: axiosRetry.exponentialDelay
|
|
46
39
|
});
|
|
47
40
|
}
|
|
48
|
-
|
|
49
41
|
makeRequest(req) {
|
|
50
42
|
var _this = this;
|
|
51
|
-
|
|
52
43
|
return _asyncToGenerator(function* () {
|
|
53
44
|
try {
|
|
54
45
|
var result = yield _this.axiosClient(req);
|
|
@@ -57,7 +48,9 @@ class ApiClient {
|
|
|
57
48
|
body: result.data,
|
|
58
49
|
error: undefined,
|
|
59
50
|
status: result.status
|
|
60
|
-
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// eslint:disable-next-line
|
|
61
54
|
} catch (e) {
|
|
62
55
|
console.error(e);
|
|
63
56
|
return {
|
|
@@ -69,32 +62,27 @@ class ApiClient {
|
|
|
69
62
|
}
|
|
70
63
|
})();
|
|
71
64
|
}
|
|
72
|
-
|
|
73
65
|
canRetryRequest(error) {
|
|
74
66
|
// Retry Network Errors.
|
|
75
67
|
if (axiosRetry.isNetworkError(error)) {
|
|
76
68
|
return true;
|
|
77
69
|
}
|
|
78
|
-
|
|
79
70
|
if (!error.response) {
|
|
80
71
|
// Cannot determine if the request can be retried
|
|
81
72
|
return false;
|
|
82
|
-
}
|
|
83
|
-
|
|
73
|
+
}
|
|
84
74
|
|
|
75
|
+
// Retry Server Errors (5xx).
|
|
85
76
|
if (error.response.status >= 500 && error.response.status <= 599) {
|
|
86
77
|
return true;
|
|
87
|
-
}
|
|
88
|
-
|
|
78
|
+
}
|
|
89
79
|
|
|
80
|
+
// Retry if rate limited.
|
|
90
81
|
if (error.response.status === 429) {
|
|
91
82
|
return true;
|
|
92
83
|
}
|
|
93
|
-
|
|
94
84
|
return false;
|
|
95
85
|
}
|
|
96
|
-
|
|
97
86
|
}
|
|
98
|
-
|
|
99
87
|
export default ApiClient;
|
|
100
88
|
//# sourceMappingURL=api.js.map
|
package/dist/esm/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"api.js","names":["axios","axiosRetry","Socket","ApiClient","constructor","options","_defineProperty","host","apiKey","userToken","axiosClient","create","baseURL","headers","Accept","Authorization","concat","window","socket","replace","params","user_token","api_key","retries","retryCondition","canRetryRequest","retryDelay","exponentialDelay","makeRequest","req","_this","_asyncToGenerator","result","statusCode","status","body","data","error","undefined","e","console","isNetworkError","response"],"sources":["../../src/api.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosRequestConfig } from \"axios\";\nimport axiosRetry from \"axios-retry\";\nimport { Socket } from \"phoenix\";\nimport { AxiosError } from \"axios\";\n\ntype ApiClientOptions = {\n host: string;\n apiKey: string;\n userToken: string | undefined;\n};\n\nexport interface ApiResponse {\n // eslint-disable-next-line\n error?: any;\n // eslint-disable-next-line\n body?: any;\n statusCode: \"ok\" | \"error\";\n status: number;\n}\n\nclass ApiClient {\n private host: string;\n private apiKey: string;\n private userToken: string | null;\n private axiosClient: AxiosInstance;\n\n public socket: Socket | undefined;\n\n constructor(options: ApiClientOptions) {\n this.host = options.host;\n this.apiKey = options.apiKey;\n this.userToken = options.userToken || null;\n\n // Create a retryable axios client\n this.axiosClient = axios.create({\n baseURL: this.host,\n headers: {\n Accept: \"application/json\",\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.apiKey}`,\n \"X-Knock-User-Token\": this.userToken,\n },\n });\n\n if (typeof window !== \"undefined\") {\n this.socket = new Socket(`${this.host.replace(\"http\", \"ws\")}/ws/v1`, {\n params: {\n user_token: this.userToken,\n api_key: this.apiKey,\n },\n });\n }\n\n axiosRetry(this.axiosClient, {\n retries: 3,\n retryCondition: this.canRetryRequest,\n retryDelay: axiosRetry.exponentialDelay,\n });\n }\n\n async makeRequest(req: AxiosRequestConfig): Promise<ApiResponse> {\n try {\n const result = await this.axiosClient(req);\n\n return {\n statusCode: result.status < 300 ? \"ok\" : \"error\",\n body: result.data,\n error: undefined,\n status: result.status,\n };\n\n // eslint:disable-next-line\n } catch (e: unknown) {\n console.error(e);\n\n return {\n statusCode: \"error\",\n status: 500,\n body: undefined,\n error: e,\n };\n }\n }\n\n private canRetryRequest(error: AxiosError) {\n // Retry Network Errors.\n if (axiosRetry.isNetworkError(error)) {\n return true;\n }\n\n if (!error.response) {\n // Cannot determine if the request can be retried\n return false;\n }\n\n // Retry Server Errors (5xx).\n if (error.response.status >= 500 && error.response.status <= 599) {\n return true;\n }\n\n // Retry if rate limited.\n if (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