@knocklabs/react-core 0.3.0-rc.0 → 0.3.1
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 +41 -4
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/modules/core/context/KnockProvider.js +1 -1
- package/dist/cjs/modules/core/context/KnockProvider.js.map +1 -1
- package/dist/cjs/modules/core/hooks/useAuthenticatedKnockClient.js.map +1 -1
- package/dist/cjs/modules/core/utils.js +1 -1
- package/dist/cjs/modules/core/utils.js.map +1 -1
- package/dist/cjs/modules/feed/context/KnockFeedProvider.js +1 -1
- package/dist/cjs/modules/feed/context/KnockFeedProvider.js.map +1 -1
- package/dist/cjs/modules/i18n/languages/en.js +1 -1
- package/dist/cjs/modules/i18n/languages/en.js.map +1 -1
- package/dist/cjs/modules/i18n/languages/index.js.map +1 -1
- package/dist/cjs/modules/ms-teams/context/KnockMsTeamsProvider.js +2 -0
- package/dist/cjs/modules/ms-teams/context/KnockMsTeamsProvider.js.map +1 -0
- package/dist/cjs/modules/ms-teams/hooks/useMsTeamsAuth.js +2 -0
- package/dist/cjs/modules/ms-teams/hooks/useMsTeamsAuth.js.map +1 -0
- package/dist/cjs/modules/ms-teams/hooks/useMsTeamsConnectionStatus.js +2 -0
- package/dist/cjs/modules/ms-teams/hooks/useMsTeamsConnectionStatus.js.map +1 -0
- package/dist/cjs/modules/slack/hooks/useConnectedSlackChannels.js.map +1 -1
- package/dist/cjs/modules/slack/hooks/useSlackAuth.js +1 -1
- package/dist/cjs/modules/slack/hooks/useSlackAuth.js.map +1 -1
- package/dist/cjs/modules/slack/hooks/useSlackConnectionStatus.js.map +1 -1
- package/dist/esm/index.mjs +42 -40
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/modules/core/context/KnockProvider.mjs +14 -14
- package/dist/esm/modules/core/context/KnockProvider.mjs.map +1 -1
- package/dist/esm/modules/core/hooks/useAuthenticatedKnockClient.mjs.map +1 -1
- package/dist/esm/modules/core/utils.mjs +13 -4
- package/dist/esm/modules/core/utils.mjs.map +1 -1
- package/dist/esm/modules/feed/context/KnockFeedProvider.mjs +13 -19
- package/dist/esm/modules/feed/context/KnockFeedProvider.mjs.map +1 -1
- package/dist/esm/modules/i18n/languages/en.mjs +9 -0
- package/dist/esm/modules/i18n/languages/en.mjs.map +1 -1
- package/dist/esm/modules/i18n/languages/index.mjs.map +1 -1
- package/dist/esm/modules/ms-teams/context/KnockMsTeamsProvider.mjs +45 -0
- package/dist/esm/modules/ms-teams/context/KnockMsTeamsProvider.mjs.map +1 -0
- package/dist/esm/modules/ms-teams/hooks/useMsTeamsAuth.mjs +51 -0
- package/dist/esm/modules/ms-teams/hooks/useMsTeamsAuth.mjs.map +1 -0
- package/dist/esm/modules/ms-teams/hooks/useMsTeamsConnectionStatus.mjs +38 -0
- package/dist/esm/modules/ms-teams/hooks/useMsTeamsConnectionStatus.mjs.map +1 -0
- package/dist/esm/modules/slack/hooks/useConnectedSlackChannels.mjs +2 -2
- package/dist/esm/modules/slack/hooks/useConnectedSlackChannels.mjs.map +1 -1
- package/dist/esm/modules/slack/hooks/useSlackAuth.mjs.map +1 -1
- package/dist/esm/modules/slack/hooks/useSlackConnectionStatus.mjs.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modules/core/context/KnockProvider.d.ts +2 -3
- package/dist/types/modules/core/context/KnockProvider.d.ts.map +1 -1
- package/dist/types/modules/core/hooks/useAuthenticatedKnockClient.d.ts +1 -2
- package/dist/types/modules/core/hooks/useAuthenticatedKnockClient.d.ts.map +1 -1
- package/dist/types/modules/core/utils.d.ts +8 -3
- package/dist/types/modules/core/utils.d.ts.map +1 -1
- package/dist/types/modules/feed/context/KnockFeedProvider.d.ts +0 -1
- package/dist/types/modules/feed/context/KnockFeedProvider.d.ts.map +1 -1
- package/dist/types/modules/feed/hooks/useFeedSettings.d.ts +0 -1
- package/dist/types/modules/feed/hooks/useNotificationStore.d.ts +0 -1
- package/dist/types/modules/feed/hooks/useNotifications.d.ts +0 -1
- package/dist/types/modules/i18n/context/KnockI18nProvider.d.ts +0 -1
- package/dist/types/modules/i18n/languages/de.d.ts +0 -1
- package/dist/types/modules/i18n/languages/en.d.ts +0 -1
- package/dist/types/modules/i18n/languages/en.d.ts.map +1 -1
- package/dist/types/modules/i18n/languages/index.d.ts +9 -0
- package/dist/types/modules/i18n/languages/index.d.ts.map +1 -1
- package/dist/types/modules/ms-teams/context/KnockMsTeamsProvider.d.ts +20 -0
- package/dist/types/modules/ms-teams/context/KnockMsTeamsProvider.d.ts.map +1 -0
- package/dist/types/modules/ms-teams/context/index.d.ts +2 -0
- package/dist/types/modules/ms-teams/context/index.d.ts.map +1 -0
- package/dist/types/modules/ms-teams/hooks/index.d.ts +3 -0
- package/dist/types/modules/ms-teams/hooks/index.d.ts.map +1 -0
- package/dist/types/modules/ms-teams/hooks/useMsTeamsAuth.d.ts +7 -0
- package/dist/types/modules/ms-teams/hooks/useMsTeamsAuth.d.ts.map +1 -0
- package/dist/types/modules/ms-teams/hooks/useMsTeamsConnectionStatus.d.ts +13 -0
- package/dist/types/modules/ms-teams/hooks/useMsTeamsConnectionStatus.d.ts.map +1 -0
- package/dist/types/modules/ms-teams/index.d.ts.map +1 -0
- package/dist/types/modules/slack/hooks/useConnectedSlackChannels.d.ts +0 -1
- package/dist/types/modules/slack/hooks/useSlackChannels.d.ts +0 -1
- package/dist/types/modules/slack/hooks/useSlackConnectionStatus.d.ts +0 -1
- package/package.json +11 -12
- package/src/index.ts +1 -1
- package/src/modules/core/context/KnockProvider.tsx +10 -10
- package/src/modules/core/hooks/useAuthenticatedKnockClient.ts +4 -4
- package/src/modules/core/utils.ts +23 -3
- package/src/modules/feed/context/KnockFeedProvider.tsx +6 -11
- package/src/modules/i18n/languages/en.ts +10 -0
- package/src/modules/i18n/languages/index.ts +9 -0
- package/src/modules/ms-teams/context/KnockMsTeamsProvider.tsx +74 -0
- package/src/modules/ms-teams/context/index.ts +1 -0
- package/src/modules/ms-teams/hooks/index.ts +2 -0
- package/src/modules/ms-teams/hooks/useMsTeamsAuth.ts +84 -0
- package/src/modules/ms-teams/hooks/useMsTeamsConnectionStatus.ts +82 -0
- package/src/modules/ms-teams/index.ts +2 -0
- package/src/modules/slack/hooks/useConnectedSlackChannels.ts +1 -1
- package/src/modules/slack/hooks/useSlackAuth.ts +1 -1
- package/src/modules/slack/hooks/useSlackConnectionStatus.ts +1 -1
- package/dist/cjs/modules/in-app-messages/context/KnockInAppMessagesChannelProvider.js +0 -2
- package/dist/cjs/modules/in-app-messages/context/KnockInAppMessagesChannelProvider.js.map +0 -1
- package/dist/cjs/modules/in-app-messages/hooks/useInAppMessages.js +0 -2
- package/dist/cjs/modules/in-app-messages/hooks/useInAppMessages.js.map +0 -1
- package/dist/esm/modules/in-app-messages/context/KnockInAppMessagesChannelProvider.mjs +0 -33
- package/dist/esm/modules/in-app-messages/context/KnockInAppMessagesChannelProvider.mjs.map +0 -1
- package/dist/esm/modules/in-app-messages/hooks/useInAppMessages.mjs +0 -41
- package/dist/esm/modules/in-app-messages/hooks/useInAppMessages.mjs.map +0 -1
- package/dist/types/modules/in-app-messages/context/KnockInAppMessagesChannelProvider.d.ts +0 -16
- package/dist/types/modules/in-app-messages/context/KnockInAppMessagesChannelProvider.d.ts.map +0 -1
- package/dist/types/modules/in-app-messages/context/index.d.ts +0 -2
- package/dist/types/modules/in-app-messages/context/index.d.ts.map +0 -1
- package/dist/types/modules/in-app-messages/hooks/index.d.ts +0 -2
- package/dist/types/modules/in-app-messages/hooks/index.d.ts.map +0 -1
- package/dist/types/modules/in-app-messages/hooks/useInAppMessages.d.ts +0 -21
- package/dist/types/modules/in-app-messages/hooks/useInAppMessages.d.ts.map +0 -1
- package/dist/types/modules/in-app-messages/index.d.ts.map +0 -1
- package/src/modules/in-app-messages/context/KnockInAppMessagesChannelProvider.tsx +0 -68
- package/src/modules/in-app-messages/context/index.ts +0 -1
- package/src/modules/in-app-messages/hooks/index.ts +0 -1
- package/src/modules/in-app-messages/hooks/useInAppMessages.ts +0 -89
- package/src/modules/in-app-messages/index.ts +0 -3
- /package/dist/types/modules/{in-app-messages → ms-teams}/index.d.ts +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"en.d.ts","sourceRoot":"","sources":["../../../../../src/modules/i18n/languages/en.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,GAAG,CAAC;AAEhC,QAAA,MAAM,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"en.d.ts","sourceRoot":"","sources":["../../../../../src/modules/i18n/languages/en.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,GAAG,CAAC;AAEhC,QAAA,MAAM,EAAE,EAAE,WAgDT,CAAC;AAEF,eAAe,EAAE,CAAC"}
|
|
@@ -10,6 +10,15 @@ export interface Translations {
|
|
|
10
10
|
readonly unread: string;
|
|
11
11
|
readonly read: string;
|
|
12
12
|
readonly unseen: string;
|
|
13
|
+
readonly msTeamsConnect: string;
|
|
14
|
+
readonly msTeamsConnected: string;
|
|
15
|
+
readonly msTeamsConnecting: string;
|
|
16
|
+
readonly msTeamsConnectContainerDescription: string;
|
|
17
|
+
readonly msTeamsDisconnect: string;
|
|
18
|
+
readonly msTeamsDisconnecting: string;
|
|
19
|
+
readonly msTeamsError: string;
|
|
20
|
+
readonly msTeamsReconnect: string;
|
|
21
|
+
readonly msTeamsTenantIdNotSet: string;
|
|
13
22
|
readonly slackConnectChannel: string;
|
|
14
23
|
readonly slackChannelId: string;
|
|
15
24
|
readonly slackConnecting: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/modules/i18n/languages/index.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,cAAc,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@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
|
+
import { ConnectionStatus } from '../hooks/useMsTeamsConnectionStatus';
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
export interface KnockMsTeamsProviderState {
|
|
5
|
+
knockMsTeamsChannelId: string;
|
|
6
|
+
tenantId: string;
|
|
7
|
+
connectionStatus: ConnectionStatus;
|
|
8
|
+
setConnectionStatus: (connectionStatus: ConnectionStatus) => void;
|
|
9
|
+
errorLabel: string | null;
|
|
10
|
+
setErrorLabel: (label: string) => void;
|
|
11
|
+
actionLabel: string | null;
|
|
12
|
+
setActionLabel: (label: string | null) => void;
|
|
13
|
+
}
|
|
14
|
+
export interface KnockMsTeamsProviderProps {
|
|
15
|
+
knockMsTeamsChannelId: string;
|
|
16
|
+
tenantId: string;
|
|
17
|
+
}
|
|
18
|
+
export declare const KnockMsTeamsProvider: React.FC<PropsWithChildren<KnockMsTeamsProviderProps>>;
|
|
19
|
+
export declare const useKnockMsTeamsClient: () => KnockMsTeamsProviderState;
|
|
20
|
+
//# sourceMappingURL=KnockMsTeamsProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KnockMsTeamsProvider.d.ts","sourceRoot":"","sources":["../../../../../src/modules/ms-teams/context/KnockMsTeamsProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAK1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAEvE,MAAM,WAAW,yBAAyB;IACxC,qBAAqB,EAAE,MAAM,CAAC;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,mBAAmB,EAAE,CAAC,gBAAgB,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAClE,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,cAAc,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;CAChD;AAKD,MAAM,WAAW,yBAAyB;IACxC,qBAAqB,EAAE,MAAM,CAAC;IAC9B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CACzC,iBAAiB,CAAC,yBAAyB,CAAC,CAmC7C,CAAC;AAEF,eAAO,MAAM,qBAAqB,QAAO,yBAQxC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/modules/ms-teams/context/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/modules/ms-teams/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AACrF,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
interface UseMsTeamsAuthOutput {
|
|
2
|
+
buildMsTeamsAuthUrl: () => string;
|
|
3
|
+
disconnectFromMsTeams: () => void;
|
|
4
|
+
}
|
|
5
|
+
declare function useMsTeamsAuth(msTeamsBotId: string, redirectUrl?: string): UseMsTeamsAuthOutput;
|
|
6
|
+
export default useMsTeamsAuth;
|
|
7
|
+
//# sourceMappingURL=useMsTeamsAuth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMsTeamsAuth.d.ts","sourceRoot":"","sources":["../../../../../src/modules/ms-teams/hooks/useMsTeamsAuth.ts"],"names":[],"mappings":"AAWA,UAAU,oBAAoB;IAC5B,mBAAmB,EAAE,MAAM,MAAM,CAAC;IAClC,qBAAqB,EAAE,MAAM,IAAI,CAAC;CACnC;AAED,iBAAS,cAAc,CACrB,YAAY,EAAE,MAAM,EACpB,WAAW,CAAC,EAAE,MAAM,GACnB,oBAAoB,CA8DtB;AAED,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { default as Knock } from '@knocklabs/client';
|
|
2
|
+
export type ConnectionStatus = "connecting" | "connected" | "disconnected" | "error" | "disconnecting";
|
|
3
|
+
type UseMsTeamsConnectionStatusOutput = {
|
|
4
|
+
connectionStatus: ConnectionStatus;
|
|
5
|
+
setConnectionStatus: (status: ConnectionStatus) => void;
|
|
6
|
+
errorLabel: string | null;
|
|
7
|
+
setErrorLabel: (errorLabel: string) => void;
|
|
8
|
+
actionLabel: string | null;
|
|
9
|
+
setActionLabel: (actionLabel: string | null) => void;
|
|
10
|
+
};
|
|
11
|
+
declare function useMsTeamsConnectionStatus(knock: Knock, knockMsTeamsChannelId: string, tenantId: string): UseMsTeamsConnectionStatusOutput;
|
|
12
|
+
export default useMsTeamsConnectionStatus;
|
|
13
|
+
//# sourceMappingURL=useMsTeamsConnectionStatus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMsTeamsConnectionStatus.d.ts","sourceRoot":"","sources":["../../../../../src/modules/ms-teams/hooks/useMsTeamsConnectionStatus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,mBAAmB,CAAC;AAKtC,MAAM,MAAM,gBAAgB,GACxB,YAAY,GACZ,WAAW,GACX,cAAc,GACd,OAAO,GACP,eAAe,CAAC;AAEpB,KAAK,gCAAgC,GAAG;IACtC,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,mBAAmB,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,CAAC;IACxD,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,aAAa,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5C,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,cAAc,EAAE,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;CACtD,CAAC;AAEF,iBAAS,0BAA0B,CACjC,KAAK,EAAE,KAAK,EACZ,qBAAqB,EAAE,MAAM,EAC7B,QAAQ,EAAE,MAAM,GACf,gCAAgC,CAsDlC;AAED,eAAe,0BAA0B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/modules/ms-teams/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@knocklabs/react-core",
|
|
3
3
|
"description": "A set of React components to build notification experiences powered by Knock",
|
|
4
4
|
"author": "@knocklabs",
|
|
5
|
-
"version": "0.3.
|
|
5
|
+
"version": "0.3.1",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "dist/cjs/index.js",
|
|
8
8
|
"module": "dist/esm/index.mjs",
|
|
@@ -49,8 +49,7 @@
|
|
|
49
49
|
"react": "^16.11.0 || ^17.0.0 || ^18.0.0"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@knocklabs/client": "^0.11.
|
|
53
|
-
"@tanstack/react-store": "^0.5.5",
|
|
52
|
+
"@knocklabs/client": "^0.11.1",
|
|
54
53
|
"date-fns": "^4.0.0",
|
|
55
54
|
"swr": "^2.2.5",
|
|
56
55
|
"zustand": "^3.7.2"
|
|
@@ -58,21 +57,21 @@
|
|
|
58
57
|
"devDependencies": {
|
|
59
58
|
"@testing-library/react": "^14.2.0",
|
|
60
59
|
"@types/react": "^18.3.6",
|
|
61
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
62
|
-
"@typescript-eslint/parser": "^8.
|
|
63
|
-
"@vitejs/plugin-react": "^4.3.
|
|
60
|
+
"@typescript-eslint/eslint-plugin": "^8.19.1",
|
|
61
|
+
"@typescript-eslint/parser": "^8.16.0",
|
|
62
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
64
63
|
"babel-plugin-react-require": "^4.0.3",
|
|
65
64
|
"eslint": "^8.56.0",
|
|
66
|
-
"eslint-plugin-react-hooks": "^
|
|
67
|
-
"eslint-plugin-react-refresh": "^0.4.
|
|
68
|
-
"jsdom": "^
|
|
65
|
+
"eslint-plugin-react-hooks": "^5.0.0",
|
|
66
|
+
"eslint-plugin-react-refresh": "^0.4.14",
|
|
67
|
+
"jsdom": "^25.0.1",
|
|
69
68
|
"react": "^18.2.0",
|
|
70
69
|
"rimraf": "^6.0.1",
|
|
71
70
|
"rollup-plugin-execute": "^1.1.1",
|
|
72
|
-
"typescript": "^5.
|
|
71
|
+
"typescript": "^5.7.3",
|
|
73
72
|
"vite": "^5.0.0",
|
|
74
|
-
"vite-plugin-dts": "^3.
|
|
73
|
+
"vite-plugin-dts": "^4.3.0",
|
|
75
74
|
"vite-plugin-no-bundle": "^4.0.0",
|
|
76
|
-
"vitest": "^2.
|
|
75
|
+
"vitest": "^2.1.8"
|
|
77
76
|
}
|
|
78
77
|
}
|
package/src/index.ts
CHANGED
|
@@ -9,21 +9,21 @@ export interface KnockProviderState {
|
|
|
9
9
|
knock: Knock;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const ProviderStateContext = React.createContext<KnockProviderState | null>(
|
|
13
|
+
null,
|
|
14
|
+
);
|
|
13
15
|
|
|
14
16
|
export interface KnockProviderProps {
|
|
15
17
|
// Knock client props
|
|
16
18
|
apiKey: string;
|
|
17
19
|
host?: string;
|
|
18
20
|
// Authentication props
|
|
19
|
-
userId:
|
|
20
|
-
userToken?:
|
|
21
|
+
userId: Knock["userId"];
|
|
22
|
+
userToken?: Knock["userToken"];
|
|
21
23
|
onUserTokenExpiring?: AuthenticateOptions["onUserTokenExpiring"];
|
|
22
24
|
timeBeforeExpirationInMs?: AuthenticateOptions["timeBeforeExpirationInMs"];
|
|
23
|
-
|
|
24
25
|
// i18n translations
|
|
25
26
|
i18n?: I18nContent;
|
|
26
|
-
|
|
27
27
|
logLevel?: LogLevel;
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -57,20 +57,20 @@ export const KnockProvider: React.FC<PropsWithChildren<KnockProviderProps>> = ({
|
|
|
57
57
|
);
|
|
58
58
|
|
|
59
59
|
return (
|
|
60
|
-
<
|
|
60
|
+
<ProviderStateContext.Provider
|
|
61
61
|
value={{
|
|
62
62
|
knock,
|
|
63
63
|
}}
|
|
64
64
|
>
|
|
65
65
|
<KnockI18nProvider i18n={i18n}>{children}</KnockI18nProvider>
|
|
66
|
-
</
|
|
66
|
+
</ProviderStateContext.Provider>
|
|
67
67
|
);
|
|
68
68
|
};
|
|
69
69
|
|
|
70
70
|
export const useKnockClient = (): Knock => {
|
|
71
|
-
const context = React.useContext(
|
|
72
|
-
if (
|
|
73
|
-
throw new Error("
|
|
71
|
+
const context = React.useContext(ProviderStateContext) as KnockProviderState;
|
|
72
|
+
if (context === undefined) {
|
|
73
|
+
throw new Error("useKnock must be used within a KnockProvider");
|
|
74
74
|
}
|
|
75
75
|
return context.knock;
|
|
76
76
|
};
|
|
@@ -5,8 +5,8 @@ import { useStableOptions } from "../../core";
|
|
|
5
5
|
|
|
6
6
|
function authenticateWithOptions(
|
|
7
7
|
knock: Knock,
|
|
8
|
-
userId:
|
|
9
|
-
userToken?:
|
|
8
|
+
userId: Knock["userId"],
|
|
9
|
+
userToken?: Knock["userToken"],
|
|
10
10
|
options: AuthenticateOptions = {},
|
|
11
11
|
) {
|
|
12
12
|
knock.authenticate(userId, userToken, {
|
|
@@ -20,8 +20,8 @@ export type AuthenticatedKnockClientOptions = KnockOptions &
|
|
|
20
20
|
|
|
21
21
|
function useAuthenticatedKnockClient(
|
|
22
22
|
apiKey: string,
|
|
23
|
-
userId:
|
|
24
|
-
userToken?:
|
|
23
|
+
userId: Knock["userId"],
|
|
24
|
+
userToken?: Knock["userToken"],
|
|
25
25
|
options: AuthenticatedKnockClientOptions = {},
|
|
26
26
|
) {
|
|
27
27
|
const knockRef = React.useRef<Knock | undefined>();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FeedClientOptions } from "@knocklabs/client";
|
|
1
|
+
import Knock, { FeedClientOptions } from "@knocklabs/client";
|
|
2
2
|
import { intlFormatDistance, parseISO } from "date-fns";
|
|
3
3
|
import { ReactNode } from "react";
|
|
4
4
|
|
|
@@ -21,7 +21,7 @@ export function formatTimestamp(
|
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
return formatted;
|
|
24
|
-
} catch (
|
|
24
|
+
} catch (_e) {
|
|
25
25
|
return ts;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -39,7 +39,7 @@ export function renderNodeOrFallback(node: ReactNode, fallback: ReactNode) {
|
|
|
39
39
|
to trigger a re-render of the context when a key property changes.
|
|
40
40
|
*/
|
|
41
41
|
export function feedProviderKey(
|
|
42
|
-
userId:
|
|
42
|
+
userId: Knock["userId"],
|
|
43
43
|
feedId: string,
|
|
44
44
|
options: FeedClientOptions = {},
|
|
45
45
|
) {
|
|
@@ -74,3 +74,23 @@ export function slackProviderKey({
|
|
|
74
74
|
.filter((f) => f !== null && f !== undefined)
|
|
75
75
|
.join("-");
|
|
76
76
|
}
|
|
77
|
+
|
|
78
|
+
/*
|
|
79
|
+
Used to build a consistent key for the KnockMsTeamsProvider so that React knows when
|
|
80
|
+
to trigger a re-render of the context when a key property changes.
|
|
81
|
+
*/
|
|
82
|
+
export function msTeamsProviderKey({
|
|
83
|
+
knockMsTeamsChannelId,
|
|
84
|
+
tenantId,
|
|
85
|
+
connectionStatus,
|
|
86
|
+
errorLabel,
|
|
87
|
+
}: {
|
|
88
|
+
knockMsTeamsChannelId: string;
|
|
89
|
+
tenantId: string;
|
|
90
|
+
connectionStatus: string;
|
|
91
|
+
errorLabel: string | null;
|
|
92
|
+
}) {
|
|
93
|
+
return [knockMsTeamsChannelId, tenantId, connectionStatus, errorLabel]
|
|
94
|
+
.filter((f) => f !== null && f !== undefined)
|
|
95
|
+
.join("-");
|
|
96
|
+
}
|
|
@@ -20,7 +20,7 @@ export interface KnockFeedProviderState {
|
|
|
20
20
|
colorMode: ColorMode;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
const
|
|
23
|
+
const FeedStateContext = React.createContext<
|
|
24
24
|
KnockFeedProviderState | undefined
|
|
25
25
|
>(undefined);
|
|
26
26
|
|
|
@@ -38,18 +38,12 @@ export interface KnockFeedProviderProps {
|
|
|
38
38
|
export const KnockFeedProvider: React.FC<
|
|
39
39
|
PropsWithChildren<KnockFeedProviderProps>
|
|
40
40
|
> = ({ feedId, children, defaultFeedOptions = {}, colorMode = "light" }) => {
|
|
41
|
-
|
|
42
|
-
try {
|
|
43
|
-
knock = useKnockClient();
|
|
44
|
-
} catch (error) {
|
|
45
|
-
throw new Error("KnockFeedProvider must be used within a KnockProvider.");
|
|
46
|
-
}
|
|
47
|
-
|
|
41
|
+
const knock = useKnockClient();
|
|
48
42
|
const feedClient = useNotifications(knock, feedId, defaultFeedOptions);
|
|
49
43
|
const useFeedStore = useCreateNotificationStore(feedClient);
|
|
50
44
|
|
|
51
45
|
return (
|
|
52
|
-
<
|
|
46
|
+
<FeedStateContext.Provider
|
|
53
47
|
key={feedProviderKey(knock.userId, feedId, defaultFeedOptions)}
|
|
54
48
|
value={{
|
|
55
49
|
knock,
|
|
@@ -59,12 +53,13 @@ export const KnockFeedProvider: React.FC<
|
|
|
59
53
|
}}
|
|
60
54
|
>
|
|
61
55
|
{children}
|
|
62
|
-
</
|
|
56
|
+
</FeedStateContext.Provider>
|
|
63
57
|
);
|
|
64
58
|
};
|
|
65
59
|
|
|
66
60
|
export const useKnockFeed = (): KnockFeedProviderState => {
|
|
67
|
-
const context = React.useContext(
|
|
61
|
+
const context = React.useContext(FeedStateContext);
|
|
62
|
+
|
|
68
63
|
if (!context) {
|
|
69
64
|
throw new Error("useKnockFeed must be used within a KnockFeedProvider");
|
|
70
65
|
}
|
|
@@ -12,6 +12,16 @@ const en: I18nContent = {
|
|
|
12
12
|
unread: "Unread",
|
|
13
13
|
read: "Read",
|
|
14
14
|
unseen: "Unseen",
|
|
15
|
+
msTeamsConnect: "Connect to Microsoft Teams",
|
|
16
|
+
msTeamsConnected: "Connected",
|
|
17
|
+
msTeamsConnecting: "Connecting to Microsoft Teams…",
|
|
18
|
+
msTeamsConnectContainerDescription:
|
|
19
|
+
"Connect to get notifications in Microsoft Teams",
|
|
20
|
+
msTeamsDisconnect: "Disconnect",
|
|
21
|
+
msTeamsDisconnecting: "Disconnecting from Microsoft Teams…",
|
|
22
|
+
msTeamsError: "Error",
|
|
23
|
+
msTeamsReconnect: "Reconnect",
|
|
24
|
+
msTeamsTenantIdNotSet: "Microsoft Teams tenant ID not set.",
|
|
15
25
|
slackConnectChannel: "Connect channel",
|
|
16
26
|
slackChannelId: "Slack channel ID",
|
|
17
27
|
slackConnecting: "Connecting to Slack...",
|
|
@@ -13,6 +13,15 @@ export interface Translations {
|
|
|
13
13
|
readonly unread: string;
|
|
14
14
|
readonly read: string;
|
|
15
15
|
readonly unseen: string;
|
|
16
|
+
readonly msTeamsConnect: string;
|
|
17
|
+
readonly msTeamsConnected: string;
|
|
18
|
+
readonly msTeamsConnecting: string;
|
|
19
|
+
readonly msTeamsConnectContainerDescription: string;
|
|
20
|
+
readonly msTeamsDisconnect: string;
|
|
21
|
+
readonly msTeamsDisconnecting: string;
|
|
22
|
+
readonly msTeamsError: string;
|
|
23
|
+
readonly msTeamsReconnect: string;
|
|
24
|
+
readonly msTeamsTenantIdNotSet: string;
|
|
16
25
|
readonly slackConnectChannel: string;
|
|
17
26
|
readonly slackChannelId: string;
|
|
18
27
|
readonly slackConnecting: string;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { PropsWithChildren } from "react";
|
|
3
|
+
|
|
4
|
+
import { useKnockClient } from "../../core";
|
|
5
|
+
import { msTeamsProviderKey } from "../../core/utils";
|
|
6
|
+
import { useMsTeamsConnectionStatus } from "../hooks";
|
|
7
|
+
import { ConnectionStatus } from "../hooks/useMsTeamsConnectionStatus";
|
|
8
|
+
|
|
9
|
+
export interface KnockMsTeamsProviderState {
|
|
10
|
+
knockMsTeamsChannelId: string;
|
|
11
|
+
tenantId: string;
|
|
12
|
+
connectionStatus: ConnectionStatus;
|
|
13
|
+
setConnectionStatus: (connectionStatus: ConnectionStatus) => void;
|
|
14
|
+
errorLabel: string | null;
|
|
15
|
+
setErrorLabel: (label: string) => void;
|
|
16
|
+
actionLabel: string | null;
|
|
17
|
+
setActionLabel: (label: string | null) => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const MsTeamsProviderStateContext =
|
|
21
|
+
React.createContext<KnockMsTeamsProviderState | null>(null);
|
|
22
|
+
|
|
23
|
+
export interface KnockMsTeamsProviderProps {
|
|
24
|
+
knockMsTeamsChannelId: string;
|
|
25
|
+
tenantId: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const KnockMsTeamsProvider: React.FC<
|
|
29
|
+
PropsWithChildren<KnockMsTeamsProviderProps>
|
|
30
|
+
> = ({ knockMsTeamsChannelId, tenantId, children }) => {
|
|
31
|
+
const knock = useKnockClient();
|
|
32
|
+
|
|
33
|
+
const {
|
|
34
|
+
connectionStatus,
|
|
35
|
+
setConnectionStatus,
|
|
36
|
+
errorLabel,
|
|
37
|
+
setErrorLabel,
|
|
38
|
+
actionLabel,
|
|
39
|
+
setActionLabel,
|
|
40
|
+
} = useMsTeamsConnectionStatus(knock, knockMsTeamsChannelId, tenantId);
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<MsTeamsProviderStateContext.Provider
|
|
44
|
+
key={msTeamsProviderKey({
|
|
45
|
+
knockMsTeamsChannelId,
|
|
46
|
+
tenantId,
|
|
47
|
+
connectionStatus,
|
|
48
|
+
errorLabel,
|
|
49
|
+
})}
|
|
50
|
+
value={{
|
|
51
|
+
connectionStatus,
|
|
52
|
+
setConnectionStatus,
|
|
53
|
+
errorLabel,
|
|
54
|
+
setErrorLabel,
|
|
55
|
+
actionLabel,
|
|
56
|
+
setActionLabel,
|
|
57
|
+
knockMsTeamsChannelId,
|
|
58
|
+
tenantId,
|
|
59
|
+
}}
|
|
60
|
+
>
|
|
61
|
+
{children}
|
|
62
|
+
</MsTeamsProviderStateContext.Provider>
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const useKnockMsTeamsClient = (): KnockMsTeamsProviderState => {
|
|
67
|
+
const context = React.useContext(MsTeamsProviderStateContext);
|
|
68
|
+
if (!context) {
|
|
69
|
+
throw new Error(
|
|
70
|
+
"useKnockMsTeamsClient must be used within a KnockMsTeamsProvider",
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
return context;
|
|
74
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./KnockMsTeamsProvider";
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { useKnockMsTeamsClient } from "..";
|
|
2
|
+
import { TENANT_OBJECT_COLLECTION } from "@knocklabs/client";
|
|
3
|
+
import { useCallback, useMemo } from "react";
|
|
4
|
+
|
|
5
|
+
import { useKnockClient } from "../../core";
|
|
6
|
+
|
|
7
|
+
const MS_TEAMS_ADMINCONSENT_URL =
|
|
8
|
+
"https://login.microsoftonline.com/organizations/adminconsent";
|
|
9
|
+
|
|
10
|
+
const AUTH_REDIRECT_PATH = "/providers/ms-teams/authenticate";
|
|
11
|
+
|
|
12
|
+
interface UseMsTeamsAuthOutput {
|
|
13
|
+
buildMsTeamsAuthUrl: () => string;
|
|
14
|
+
disconnectFromMsTeams: () => void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function useMsTeamsAuth(
|
|
18
|
+
msTeamsBotId: string,
|
|
19
|
+
redirectUrl?: string,
|
|
20
|
+
): UseMsTeamsAuthOutput {
|
|
21
|
+
const knock = useKnockClient();
|
|
22
|
+
const {
|
|
23
|
+
setConnectionStatus,
|
|
24
|
+
knockMsTeamsChannelId,
|
|
25
|
+
tenantId,
|
|
26
|
+
setActionLabel,
|
|
27
|
+
} = useKnockMsTeamsClient();
|
|
28
|
+
|
|
29
|
+
const authRedirectUri = useMemo(
|
|
30
|
+
() => knock.host + AUTH_REDIRECT_PATH,
|
|
31
|
+
[knock.host],
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const buildMsTeamsAuthUrl = useCallback(() => {
|
|
35
|
+
const rawParams = {
|
|
36
|
+
state: JSON.stringify({
|
|
37
|
+
redirect_url: redirectUrl,
|
|
38
|
+
ms_teams_tenant_object: {
|
|
39
|
+
object_id: tenantId,
|
|
40
|
+
collection: TENANT_OBJECT_COLLECTION,
|
|
41
|
+
},
|
|
42
|
+
channel_id: knockMsTeamsChannelId,
|
|
43
|
+
public_key: knock.apiKey,
|
|
44
|
+
user_token: knock.userToken,
|
|
45
|
+
}),
|
|
46
|
+
client_id: msTeamsBotId,
|
|
47
|
+
redirect_uri: authRedirectUri,
|
|
48
|
+
};
|
|
49
|
+
return `${MS_TEAMS_ADMINCONSENT_URL}?${new URLSearchParams(rawParams)}`;
|
|
50
|
+
}, [
|
|
51
|
+
redirectUrl,
|
|
52
|
+
tenantId,
|
|
53
|
+
knockMsTeamsChannelId,
|
|
54
|
+
knock.apiKey,
|
|
55
|
+
knock.userToken,
|
|
56
|
+
msTeamsBotId,
|
|
57
|
+
authRedirectUri,
|
|
58
|
+
]);
|
|
59
|
+
|
|
60
|
+
const disconnectFromMsTeams = useCallback(async () => {
|
|
61
|
+
setActionLabel(null);
|
|
62
|
+
setConnectionStatus("disconnecting");
|
|
63
|
+
try {
|
|
64
|
+
const revokeResult = await knock.msTeams.revokeAccessToken({
|
|
65
|
+
tenant: tenantId,
|
|
66
|
+
knockChannelId: knockMsTeamsChannelId,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
setConnectionStatus(revokeResult === "ok" ? "disconnected" : "error");
|
|
70
|
+
} catch (_error) {
|
|
71
|
+
setConnectionStatus("error");
|
|
72
|
+
}
|
|
73
|
+
}, [
|
|
74
|
+
setConnectionStatus,
|
|
75
|
+
knock.msTeams,
|
|
76
|
+
tenantId,
|
|
77
|
+
knockMsTeamsChannelId,
|
|
78
|
+
setActionLabel,
|
|
79
|
+
]);
|
|
80
|
+
|
|
81
|
+
return { buildMsTeamsAuthUrl, disconnectFromMsTeams };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export default useMsTeamsAuth;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import Knock from "@knocklabs/client";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
|
|
4
|
+
import { useTranslations } from "../../i18n";
|
|
5
|
+
|
|
6
|
+
export type ConnectionStatus =
|
|
7
|
+
| "connecting"
|
|
8
|
+
| "connected"
|
|
9
|
+
| "disconnected"
|
|
10
|
+
| "error"
|
|
11
|
+
| "disconnecting";
|
|
12
|
+
|
|
13
|
+
type UseMsTeamsConnectionStatusOutput = {
|
|
14
|
+
connectionStatus: ConnectionStatus;
|
|
15
|
+
setConnectionStatus: (status: ConnectionStatus) => void;
|
|
16
|
+
errorLabel: string | null;
|
|
17
|
+
setErrorLabel: (errorLabel: string) => void;
|
|
18
|
+
actionLabel: string | null;
|
|
19
|
+
setActionLabel: (actionLabel: string | null) => void;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function useMsTeamsConnectionStatus(
|
|
23
|
+
knock: Knock,
|
|
24
|
+
knockMsTeamsChannelId: string,
|
|
25
|
+
tenantId: string,
|
|
26
|
+
): UseMsTeamsConnectionStatusOutput {
|
|
27
|
+
const { t } = useTranslations();
|
|
28
|
+
|
|
29
|
+
const [connectionStatus, setConnectionStatus] =
|
|
30
|
+
useState<ConnectionStatus>("connecting");
|
|
31
|
+
const [errorLabel, setErrorLabel] = useState<string | null>(null);
|
|
32
|
+
const [actionLabel, setActionLabel] = useState<string | null>(null);
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const checkAuthStatus = async () => {
|
|
36
|
+
if (connectionStatus !== "connecting") return;
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
const authRes = await knock.msTeams.authCheck({
|
|
40
|
+
tenant: tenantId,
|
|
41
|
+
knockChannelId: knockMsTeamsChannelId,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
if (authRes.connection?.ok === true) {
|
|
45
|
+
return setConnectionStatus("connected");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (authRes.connection?.ok === false) {
|
|
49
|
+
return setConnectionStatus("disconnected");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// This is a normal response for a tenant that doesn't have
|
|
53
|
+
// ms_teams_tenant_id set on it, meaning it's not connected to MS Teams,
|
|
54
|
+
// so we give it a "disconnected" status instead of an error status.
|
|
55
|
+
if (
|
|
56
|
+
authRes.code === "ERR_BAD_REQUEST" &&
|
|
57
|
+
authRes.response?.data?.message === t("msTeamsTenantIdNotSet")
|
|
58
|
+
) {
|
|
59
|
+
return setConnectionStatus("disconnected");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// This is for any Knock errors that would require a reconnect.
|
|
63
|
+
setConnectionStatus("error");
|
|
64
|
+
} catch (_error) {
|
|
65
|
+
setConnectionStatus("error");
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
checkAuthStatus();
|
|
70
|
+
}, [connectionStatus, tenantId, knockMsTeamsChannelId, knock.msTeams, t]);
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
connectionStatus,
|
|
74
|
+
setConnectionStatus,
|
|
75
|
+
errorLabel,
|
|
76
|
+
setErrorLabel,
|
|
77
|
+
actionLabel,
|
|
78
|
+
setActionLabel,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export default useMsTeamsConnectionStatus;
|