@knocklabs/client 0.10.8 → 0.10.10
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 +14 -0
- package/dist/cjs/api.js.map +1 -1
- package/dist/cjs/clients/feed/feed.js +1 -1
- package/dist/cjs/clients/feed/feed.js.map +1 -1
- package/dist/cjs/clients/feed/store.js.map +1 -1
- package/dist/cjs/clients/messages/index.js.map +1 -1
- package/dist/cjs/clients/objects/index.js.map +1 -1
- package/dist/cjs/clients/preferences/index.js.map +1 -1
- package/dist/cjs/clients/users/index.js.map +1 -1
- package/dist/esm/api.mjs.map +1 -1
- package/dist/esm/clients/feed/feed.mjs +1 -1
- package/dist/esm/clients/feed/feed.mjs.map +1 -1
- package/dist/esm/clients/feed/store.mjs.map +1 -1
- package/dist/esm/clients/messages/index.mjs.map +1 -1
- package/dist/esm/clients/objects/index.mjs.map +1 -1
- package/dist/esm/clients/preferences/index.mjs.map +1 -1
- package/dist/esm/clients/users/index.mjs.map +1 -1
- package/dist/types/api.d.ts.map +1 -1
- package/dist/types/clients/feed/feed.d.ts +8 -7
- package/dist/types/clients/feed/feed.d.ts.map +1 -1
- package/dist/types/clients/feed/interfaces.d.ts +1 -1
- package/dist/types/clients/feed/interfaces.d.ts.map +1 -1
- package/dist/types/clients/feed/store.d.ts.map +1 -1
- package/dist/types/clients/feed/types.d.ts +2 -2
- package/dist/types/clients/feed/types.d.ts.map +1 -1
- package/dist/types/clients/messages/interfaces.d.ts +2 -1
- package/dist/types/clients/messages/interfaces.d.ts.map +1 -1
- package/dist/types/clients/objects/index.d.ts +3 -2
- package/dist/types/clients/objects/index.d.ts.map +1 -1
- package/dist/types/clients/preferences/index.d.ts +1 -1
- package/dist/types/clients/preferences/index.d.ts.map +1 -1
- package/dist/types/clients/users/index.d.ts +4 -3
- package/dist/types/clients/users/index.d.ts.map +1 -1
- package/dist/types/clients/users/interfaces.d.ts +2 -1
- package/dist/types/clients/users/interfaces.d.ts.map +1 -1
- package/dist/types/interfaces.d.ts +3 -2
- package/dist/types/interfaces.d.ts.map +1 -1
- package/package.json +8 -9
- package/src/api.ts +0 -1
- package/src/clients/feed/feed.ts +4 -4
- package/src/clients/feed/interfaces.ts +1 -1
- package/src/clients/feed/store.ts +2 -1
- package/src/clients/feed/types.ts +2 -2
- package/src/clients/messages/index.ts +1 -1
- package/src/clients/messages/interfaces.ts +3 -1
- package/src/clients/objects/index.ts +4 -2
- package/src/clients/preferences/index.ts +3 -1
- package/src/clients/users/index.ts +5 -3
- package/src/clients/users/interfaces.ts +3 -1
- package/src/interfaces.ts +3 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knocklabs/client",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.10",
|
|
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",
|
|
@@ -33,15 +33,14 @@
|
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
35
|
"dev": "tsc && vite build --watch --emptyOutDir false",
|
|
36
|
-
"lint": "eslint
|
|
36
|
+
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
|
37
37
|
"format": "prettier \"src/**/*.{js,ts,tsx}\" --write",
|
|
38
38
|
"format:check": "prettier \"src/**/*.{js,ts,tsx}\" --check",
|
|
39
39
|
"test": "vitest run",
|
|
40
40
|
"test:watch": "vitest",
|
|
41
|
+
"type:check": "tsc --noEmit",
|
|
41
42
|
"coverage": "vitest run --coverage",
|
|
42
43
|
"clean": "rimraf dist",
|
|
43
|
-
"type-check": "tsc --noEmit",
|
|
44
|
-
"type-check:watch": "npm run type-check -- --watch",
|
|
45
44
|
"build": "yarn clean && yarn build:cjs && yarn build:esm",
|
|
46
45
|
"build:esm": "BUILD_TARGET=esm; vite build",
|
|
47
46
|
"build:cjs": "BUILD_TARGET=cjs; vite build",
|
|
@@ -56,22 +55,22 @@
|
|
|
56
55
|
"@babel/preset-env": "^7.16.7",
|
|
57
56
|
"@babel/preset-typescript": "^7.16.7",
|
|
58
57
|
"@types/jsonwebtoken": "^9.0.5",
|
|
59
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
60
|
-
"@typescript-eslint/parser": "^6.
|
|
58
|
+
"@typescript-eslint/eslint-plugin": "^6.20.0",
|
|
59
|
+
"@typescript-eslint/parser": "^6.20.0",
|
|
61
60
|
"cross-env": "^7.0.3",
|
|
62
61
|
"crypto": "^1.0.1",
|
|
63
|
-
"eslint": "^8.
|
|
62
|
+
"eslint": "^8.56.0",
|
|
64
63
|
"jsonwebtoken": "^9.0.2",
|
|
65
64
|
"prettier": "^3.1.0",
|
|
66
65
|
"rimraf": "^5.0.5",
|
|
67
66
|
"rollup": "^2.46.0",
|
|
68
|
-
"typescript": "^5.
|
|
67
|
+
"typescript": "^5.3.3",
|
|
69
68
|
"vite": "^5.0.0",
|
|
70
69
|
"vitest": "^1.2.2"
|
|
71
70
|
},
|
|
72
71
|
"dependencies": {
|
|
73
72
|
"@babel/runtime": "^7.23.9",
|
|
74
|
-
"@knocklabs/types": "^0.1.
|
|
73
|
+
"@knocklabs/types": "^0.1.4",
|
|
75
74
|
"@types/phoenix": "^1.5.4",
|
|
76
75
|
"axios": "^1.6.0",
|
|
77
76
|
"axios-retry": "^3.1.9",
|
package/src/api.ts
CHANGED
package/src/clients/feed/feed.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { GenericData } from "@knocklabs/types";
|
|
1
2
|
import EventEmitter from "eventemitter2";
|
|
2
3
|
import { Channel } from "phoenix";
|
|
3
4
|
import { StoreApi } from "zustand";
|
|
@@ -42,9 +43,9 @@ class Feed {
|
|
|
42
43
|
private defaultOptions: FeedClientOptions;
|
|
43
44
|
private broadcastChannel!: BroadcastChannel | null;
|
|
44
45
|
private disconnectTimer: ReturnType<typeof setTimeout> | null = null;
|
|
45
|
-
private hasSubscribedToRealTimeUpdates:
|
|
46
|
+
private hasSubscribedToRealTimeUpdates: boolean = false;
|
|
46
47
|
private visibilityChangeHandler: () => void = () => {};
|
|
47
|
-
private visibilityChangeListenerConnected:
|
|
48
|
+
private visibilityChangeListenerConnected: boolean = false;
|
|
48
49
|
|
|
49
50
|
// The raw store instance, used for binding in React and other environments
|
|
50
51
|
public store: StoreApi<FeedStoreState>;
|
|
@@ -112,7 +113,6 @@ class Feed {
|
|
|
112
113
|
this.teardown();
|
|
113
114
|
this.broadcaster.removeAllListeners();
|
|
114
115
|
this.knock.feeds.removeInstance(this);
|
|
115
|
-
this.store.destroy();
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
/*
|
|
@@ -660,7 +660,7 @@ class Feed {
|
|
|
660
660
|
}
|
|
661
661
|
}
|
|
662
662
|
|
|
663
|
-
private broadcastOverChannel(type: string, payload:
|
|
663
|
+
private broadcastOverChannel(type: string, payload: GenericData) {
|
|
664
664
|
// The broadcastChannel may not be available in non-browser environments
|
|
665
665
|
if (!this.broadcastChannel) {
|
|
666
666
|
return;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { GenericData } from "@knocklabs/types";
|
|
1
2
|
import create from "zustand/vanilla";
|
|
2
3
|
|
|
3
4
|
import { NetworkStatus } from "../../networkStatus";
|
|
@@ -53,7 +54,7 @@ export default function createStore() {
|
|
|
53
54
|
set((state) => {
|
|
54
55
|
// We resort the list on set, so concating everything is fine (if a bit suboptimal)
|
|
55
56
|
const items = options.shouldAppend
|
|
56
|
-
? processItems(state.items.concat(entries))
|
|
57
|
+
? processItems(state.items.concat(entries as FeedItem<GenericData>[]))
|
|
57
58
|
: entries;
|
|
58
59
|
|
|
59
60
|
return {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PageInfo } from "@knocklabs/types";
|
|
1
|
+
import { GenericData, PageInfo } from "@knocklabs/types";
|
|
2
2
|
|
|
3
3
|
import { NetworkStatus } from "../../networkStatus";
|
|
4
4
|
|
|
@@ -51,7 +51,7 @@ export type FeedEvent =
|
|
|
51
51
|
// Because we can bind to wild card feed events, this is here to accomodate whatever can be bound to
|
|
52
52
|
export type BindableFeedEvent = FeedEvent | "items.received.*" | "items.*";
|
|
53
53
|
|
|
54
|
-
export interface FeedEventPayload<T =
|
|
54
|
+
export interface FeedEventPayload<T = GenericData> {
|
|
55
55
|
event: Omit<FeedEvent, "messages.new">;
|
|
56
56
|
items: FeedItem<T>[];
|
|
57
57
|
metadata: FeedMetadata;
|
|
@@ -75,7 +75,7 @@ class MessageClient {
|
|
|
75
75
|
return this.handleResponse<BulkOperation>(result);
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
private handleResponse<T =
|
|
78
|
+
private handleResponse<T = unknown>(response: ApiResponse) {
|
|
79
79
|
if (response.statusCode === "error") {
|
|
80
80
|
if (response.error?.response?.status < 500) {
|
|
81
81
|
return response.error || response.body;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { GenericData } from "@knocklabs/types";
|
|
2
|
+
|
|
1
3
|
import { RecipientRef } from "../..";
|
|
2
4
|
|
|
3
5
|
export type MessageDeliveryStatus =
|
|
@@ -20,7 +22,7 @@ export type MessageEngagementStatus =
|
|
|
20
22
|
| "interacted"
|
|
21
23
|
| "archived";
|
|
22
24
|
|
|
23
|
-
export interface Message<T =
|
|
25
|
+
export interface Message<T = GenericData> {
|
|
24
26
|
id: string;
|
|
25
27
|
channel_id: string;
|
|
26
28
|
recipient: RecipientRef;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { GenericData } from "@knocklabs/types";
|
|
2
|
+
|
|
1
3
|
import { ApiResponse } from "../../api";
|
|
2
4
|
import { ChannelData } from "../../interfaces";
|
|
3
5
|
import Knock from "../../knock";
|
|
@@ -12,7 +14,7 @@ type SetChannelDataInput = {
|
|
|
12
14
|
objectId: string;
|
|
13
15
|
collection: string;
|
|
14
16
|
channelId: string;
|
|
15
|
-
data:
|
|
17
|
+
data: GenericData;
|
|
16
18
|
};
|
|
17
19
|
|
|
18
20
|
class ObjectClient {
|
|
@@ -21,7 +23,7 @@ class ObjectClient {
|
|
|
21
23
|
constructor(instance: Knock) {
|
|
22
24
|
this.instance = instance;
|
|
23
25
|
}
|
|
24
|
-
async getChannelData<T =
|
|
26
|
+
async getChannelData<T = GenericData>({
|
|
25
27
|
collection,
|
|
26
28
|
objectId,
|
|
27
29
|
channelId,
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { ChannelType } from "@knocklabs/types";
|
|
2
|
+
|
|
2
3
|
import { ApiResponse } from "../../api";
|
|
3
4
|
import Knock from "../../knock";
|
|
5
|
+
|
|
4
6
|
import {
|
|
5
7
|
ChannelTypePreferences,
|
|
6
8
|
PreferenceOptions,
|
|
9
|
+
PreferenceSet,
|
|
7
10
|
SetPreferencesProperties,
|
|
8
11
|
WorkflowPreferenceSetting,
|
|
9
12
|
WorkflowPreferences,
|
|
10
|
-
PreferenceSet,
|
|
11
13
|
} from "./interfaces";
|
|
12
14
|
|
|
13
15
|
const DEFAULT_PREFERENCE_SET_ID = "default";
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { GenericData } from "@knocklabs/types";
|
|
2
|
+
|
|
1
3
|
import { ApiResponse } from "../../api";
|
|
2
4
|
import { ChannelData, User } from "../../interfaces";
|
|
3
5
|
import Knock from "../../knock";
|
|
@@ -28,7 +30,7 @@ class UserClient {
|
|
|
28
30
|
return this.handleResponse<User>(result);
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
async identify(props:
|
|
33
|
+
async identify(props: GenericData = {}) {
|
|
32
34
|
const result = await this.instance.client().makeRequest({
|
|
33
35
|
method: "PUT",
|
|
34
36
|
url: `/v1/users/${this.instance.userId}`,
|
|
@@ -76,7 +78,7 @@ class UserClient {
|
|
|
76
78
|
return this.handleResponse<PreferenceSet>(result);
|
|
77
79
|
}
|
|
78
80
|
|
|
79
|
-
async getChannelData<T =
|
|
81
|
+
async getChannelData<T = GenericData>(params: GetChannelDataInput) {
|
|
80
82
|
const result = await this.instance.client().makeRequest({
|
|
81
83
|
method: "GET",
|
|
82
84
|
url: `/v1/users/${this.instance.userId}/channel_data/${params.channelId}`,
|
|
@@ -85,7 +87,7 @@ class UserClient {
|
|
|
85
87
|
return this.handleResponse<ChannelData<T>>(result);
|
|
86
88
|
}
|
|
87
89
|
|
|
88
|
-
async setChannelData<T =
|
|
90
|
+
async setChannelData<T = GenericData>({
|
|
89
91
|
channelId,
|
|
90
92
|
channelData,
|
|
91
93
|
}: SetChannelDataInput) {
|
package/src/interfaces.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GenericData } from "@knocklabs/types";
|
|
2
|
+
import { JwtPayload } from "jwt-decode";
|
|
2
3
|
|
|
3
4
|
export type LogLevel = "debug";
|
|
4
5
|
|
|
@@ -38,14 +39,14 @@ export interface Activity<T = GenericData> {
|
|
|
38
39
|
data: T | null;
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
export interface ChannelData<T =
|
|
42
|
+
export interface ChannelData<T = GenericData> {
|
|
42
43
|
channel_id: string;
|
|
43
44
|
data: T;
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
export type UserTokenExpiringCallback = (
|
|
47
48
|
currentToken: string,
|
|
48
|
-
decodedToken:
|
|
49
|
+
decodedToken: JwtPayload,
|
|
49
50
|
) => Promise<string | void>;
|
|
50
51
|
|
|
51
52
|
export interface AuthenticateOptions {
|