@knocklabs/react-core 0.11.2 → 0.11.4
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 +70 -0
- 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 +1 -1
- package/dist/cjs/modules/core/hooks/useAuthenticatedKnockClient.js.map +1 -1
- package/dist/cjs/modules/ms-teams/hooks/useMsTeamsAuth.js +1 -1
- package/dist/cjs/modules/ms-teams/hooks/useMsTeamsAuth.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/esm/modules/core/context/KnockProvider.mjs +18 -16
- package/dist/esm/modules/core/context/KnockProvider.mjs.map +1 -1
- package/dist/esm/modules/core/hooks/useAuthenticatedKnockClient.mjs +11 -10
- package/dist/esm/modules/core/hooks/useAuthenticatedKnockClient.mjs.map +1 -1
- package/dist/esm/modules/ms-teams/hooks/useMsTeamsAuth.mjs +16 -15
- package/dist/esm/modules/ms-teams/hooks/useMsTeamsAuth.mjs.map +1 -1
- package/dist/esm/modules/slack/hooks/useSlackAuth.mjs +24 -23
- package/dist/esm/modules/slack/hooks/useSlackAuth.mjs.map +1 -1
- package/dist/types/modules/core/context/KnockProvider.d.ts +1 -0
- package/dist/types/modules/core/context/KnockProvider.d.ts.map +1 -1
- package/dist/types/modules/core/hooks/useAuthenticatedKnockClient.d.ts.map +1 -1
- package/dist/types/modules/ms-teams/hooks/useMsTeamsAuth.d.ts.map +1 -1
- package/dist/types/modules/slack/hooks/useSlackAuth.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/modules/core/context/KnockProvider.tsx +4 -0
- package/src/modules/core/hooks/useAuthenticatedKnockClient.ts +1 -0
- package/src/modules/ms-teams/hooks/useMsTeamsAuth.ts +2 -0
- package/src/modules/slack/hooks/useSlackAuth.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,75 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.11.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [a56bf70]
|
|
8
|
+
- @knocklabs/client@0.19.4
|
|
9
|
+
|
|
10
|
+
## 0.11.3
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 571abb1: Add `branch` option to `useAuthenticatedKnockClient` hook
|
|
15
|
+
|
|
16
|
+
The `useAuthenticatedKnockClient` hook now accepts a `branch` option. To use
|
|
17
|
+
`useAuthenticatedKnockClient` with a branch, set the `apiKey` param to your
|
|
18
|
+
development environment's API key and set the `branch` option to the slug of an
|
|
19
|
+
existing branch.
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { useAuthenticatedKnockClient } from "@knocklabs/react-core";
|
|
23
|
+
|
|
24
|
+
const knock = useAuthenticatedKnockClient(
|
|
25
|
+
process.env.KNOCK_PUBLIC_API_KEY,
|
|
26
|
+
{ id: user.id },
|
|
27
|
+
undefined, // userToken when needed
|
|
28
|
+
{ branch: "my-branch-slug" },
|
|
29
|
+
);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
- f4529cc: Enable use of SlackKit with branches
|
|
33
|
+
|
|
34
|
+
The `useSlackAuth` hook exported by `@knocklabs/react-core` has been updated so
|
|
35
|
+
that it works with branches. You can now use either this hook or the
|
|
36
|
+
`<SlackAuthButton>` component exported by `@knocklabs/react` to test connecting
|
|
37
|
+
Slack workspaces to Knock tenants while working on a branch.
|
|
38
|
+
|
|
39
|
+
- f278892: Enable use of TeamsKit with branches
|
|
40
|
+
|
|
41
|
+
The `useMsTeamsAuth` hook exported by `@knocklabs/react-core` has been updated
|
|
42
|
+
so that it works with branches. You can now use either this hook or the
|
|
43
|
+
`<MsTeamsAuthButton>` component exported by `@knocklabs/react` to test
|
|
44
|
+
connecting Microsoft Teams organizations to Knock tenants while working on a
|
|
45
|
+
branch.
|
|
46
|
+
|
|
47
|
+
- 571abb1: Add `branch` prop to `<KnockProvider>`
|
|
48
|
+
|
|
49
|
+
The `<KnockProvider>` context provider now accepts an optional `branch` prop.
|
|
50
|
+
To use `<KnockProvider>` with a branch, set the `apiKey` prop to your
|
|
51
|
+
development environment's API key and set `branch` to the slug of an existing
|
|
52
|
+
branch.
|
|
53
|
+
|
|
54
|
+
```tsx
|
|
55
|
+
import { KnockProvider } from "@knocklabs/react";
|
|
56
|
+
|
|
57
|
+
const YourAppLayout = () => {
|
|
58
|
+
return (
|
|
59
|
+
<KnockProvider
|
|
60
|
+
apiKey={process.env.KNOCK_PUBLIC_API_KEY}
|
|
61
|
+
user={{ id: user.id }}
|
|
62
|
+
branch="my-branch-slug"
|
|
63
|
+
>
|
|
64
|
+
{/** the rest of your app */}
|
|
65
|
+
</KnockProvider>
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
- Updated dependencies [571abb1]
|
|
71
|
+
- @knocklabs/client@0.19.3
|
|
72
|
+
|
|
3
73
|
## 0.11.2
|
|
4
74
|
|
|
5
75
|
### Patch Changes
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("react"),m=require("../../i18n/context/KnockI18nProvider.js"),v=require("../hooks/useAuthenticatedKnockClient.js");require("fast-deep-equal");function C(e){if(e&&typeof e=="object"&&"default"in e)return e;const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:()=>e[t]})}}return n.default=e,Object.freeze(n)}const r=C(b),l=r.createContext(null),O=({apiKey:e,host:n,logLevel:t,userToken:o,onUserTokenExpiring:u,timeBeforeExpirationInMs:i,children:d,i18n:k,identificationStrategy:s,branch:a,...c})=>{const f=(c==null?void 0:c.user)||(c==null?void 0:c.userId),K=r.useMemo(()=>({host:n,onUserTokenExpiring:u,timeBeforeExpirationInMs:i,logLevel:t,identificationStrategy:s,branch:a}),[n,u,i,t,s,a]),P=v(e??"",f,o,K);return r.createElement(l.Provider,{value:{knock:P}},r.createElement(m.KnockI18nProvider,{i18n:k},d))},j=()=>{const e=r.useContext(l);if(!e)throw new Error("useKnockClient must be used within a KnockProvider");return e.knock};exports.KnockProvider=O;exports.useKnockClient=j;
|
|
2
2
|
//# sourceMappingURL=KnockProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KnockProvider.js","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"sourcesContent":["import Knock, {\n AuthenticateOptions,\n LogLevel,\n UserWithProperties,\n} from \"@knocklabs/client\";\nimport * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\n\nimport { I18nContent, KnockI18nProvider } from \"../../i18n\";\nimport { useAuthenticatedKnockClient } from \"../hooks\";\n\nexport interface KnockProviderState {\n knock: Knock;\n}\n\nconst KnockContext = React.createContext<KnockProviderState | null>(null);\n\nexport type KnockProviderProps = {\n // Knock client props\n apiKey: string | undefined;\n host?: string;\n userToken?: Knock[\"userToken\"];\n onUserTokenExpiring?: AuthenticateOptions[\"onUserTokenExpiring\"];\n timeBeforeExpirationInMs?: AuthenticateOptions[\"timeBeforeExpirationInMs\"];\n // i18n translations\n i18n?: I18nContent;\n logLevel?: LogLevel;\n} & (\n | {\n /**\n * @deprecated The `userId` prop is deprecated and will be removed in a future version.\n * Please pass the `user` prop instead containing an `id` value.\n * example:\n * ```ts\n * <KnockProvider user={{ id: \"user_123\" }}></KnockProvider>\n * ```\n */\n userId: Knock[\"userId\"];\n user?: never;\n identificationStrategy?: never;\n }\n | {\n user: UserWithProperties;\n identificationStrategy?: AuthenticateOptions[\"identificationStrategy\"];\n /**\n * @deprecated The `userId` prop is deprecated and will be removed in a future version.\n * Please pass the `user` prop instead containing an `id` value.\n * example:\n * ```ts\n * <KnockProvider user={{ id: \"user_123\" }}></KnockProvider>\n * ```\n */\n userId?: never;\n }\n);\n\nexport const KnockProvider: React.FC<PropsWithChildren<KnockProviderProps>> = ({\n apiKey,\n host,\n logLevel,\n userToken,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n children,\n i18n,\n identificationStrategy,\n ...props\n}) => {\n const userIdOrUserWithProperties = props?.user || props?.userId;\n\n // We memoize the options here so that we don't create a new object on every re-render\n const authenticateOptions = React.useMemo(\n () => ({\n host,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n logLevel,\n identificationStrategy,\n }),\n [\n host,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n logLevel,\n identificationStrategy,\n ],\n );\n\n const knock = useAuthenticatedKnockClient(\n apiKey ?? \"\",\n userIdOrUserWithProperties,\n userToken,\n authenticateOptions,\n );\n\n return (\n <KnockContext.Provider value={{ knock }}>\n <KnockI18nProvider i18n={i18n}>{children}</KnockI18nProvider>\n </KnockContext.Provider>\n );\n};\n\nexport const useKnockClient = (): Knock => {\n const context = React.useContext(KnockContext);\n if (!context) {\n throw new Error(\"useKnockClient must be used within a KnockProvider\");\n }\n return context.knock;\n};\n"],"names":["KnockContext","React","createContext","KnockProvider","apiKey","host","logLevel","userToken","onUserTokenExpiring","timeBeforeExpirationInMs","children","i18n","identificationStrategy","props","userIdOrUserWithProperties","user","userId","authenticateOptions","useMemo","knock","useAuthenticatedKnockClient","KnockI18nProvider","useKnockClient","context","useContext","Error"],"mappings":"yjBAeMA,EAAeC,EAAMC,cAAyC,IAAI,
|
|
1
|
+
{"version":3,"file":"KnockProvider.js","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"sourcesContent":["import Knock, {\n AuthenticateOptions,\n LogLevel,\n UserWithProperties,\n} from \"@knocklabs/client\";\nimport * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\n\nimport { I18nContent, KnockI18nProvider } from \"../../i18n\";\nimport { useAuthenticatedKnockClient } from \"../hooks\";\n\nexport interface KnockProviderState {\n knock: Knock;\n}\n\nconst KnockContext = React.createContext<KnockProviderState | null>(null);\n\nexport type KnockProviderProps = {\n // Knock client props\n apiKey: string | undefined;\n host?: string;\n userToken?: Knock[\"userToken\"];\n onUserTokenExpiring?: AuthenticateOptions[\"onUserTokenExpiring\"];\n timeBeforeExpirationInMs?: AuthenticateOptions[\"timeBeforeExpirationInMs\"];\n // i18n translations\n i18n?: I18nContent;\n logLevel?: LogLevel;\n branch?: string;\n} & (\n | {\n /**\n * @deprecated The `userId` prop is deprecated and will be removed in a future version.\n * Please pass the `user` prop instead containing an `id` value.\n * example:\n * ```ts\n * <KnockProvider user={{ id: \"user_123\" }}></KnockProvider>\n * ```\n */\n userId: Knock[\"userId\"];\n user?: never;\n identificationStrategy?: never;\n }\n | {\n user: UserWithProperties;\n identificationStrategy?: AuthenticateOptions[\"identificationStrategy\"];\n /**\n * @deprecated The `userId` prop is deprecated and will be removed in a future version.\n * Please pass the `user` prop instead containing an `id` value.\n * example:\n * ```ts\n * <KnockProvider user={{ id: \"user_123\" }}></KnockProvider>\n * ```\n */\n userId?: never;\n }\n);\n\nexport const KnockProvider: React.FC<PropsWithChildren<KnockProviderProps>> = ({\n apiKey,\n host,\n logLevel,\n userToken,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n children,\n i18n,\n identificationStrategy,\n branch,\n ...props\n}) => {\n const userIdOrUserWithProperties = props?.user || props?.userId;\n\n // We memoize the options here so that we don't create a new object on every re-render\n const authenticateOptions = React.useMemo(\n () => ({\n host,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n logLevel,\n identificationStrategy,\n branch,\n }),\n [\n host,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n logLevel,\n identificationStrategy,\n branch,\n ],\n );\n\n const knock = useAuthenticatedKnockClient(\n apiKey ?? \"\",\n userIdOrUserWithProperties,\n userToken,\n authenticateOptions,\n );\n\n return (\n <KnockContext.Provider value={{ knock }}>\n <KnockI18nProvider i18n={i18n}>{children}</KnockI18nProvider>\n </KnockContext.Provider>\n );\n};\n\nexport const useKnockClient = (): Knock => {\n const context = React.useContext(KnockContext);\n if (!context) {\n throw new Error(\"useKnockClient must be used within a KnockProvider\");\n }\n return context.knock;\n};\n"],"names":["KnockContext","React","createContext","KnockProvider","apiKey","host","logLevel","userToken","onUserTokenExpiring","timeBeforeExpirationInMs","children","i18n","identificationStrategy","branch","props","userIdOrUserWithProperties","user","userId","authenticateOptions","useMemo","knock","useAuthenticatedKnockClient","KnockI18nProvider","useKnockClient","context","useContext","Error"],"mappings":"yjBAeMA,EAAeC,EAAMC,cAAyC,IAAI,EA0C3DC,EAAiEA,CAAC,CAC7EC,OAAAA,EACAC,KAAAA,EACAC,SAAAA,EACAC,UAAAA,EACAC,oBAAAA,EACAC,yBAAAA,EACAC,SAAAA,EACAC,KAAAA,EACAC,uBAAAA,EACAC,OAAAA,EACA,GAAGC,CACL,IAAM,CACEC,MAAAA,GAA6BD,GAAAA,YAAAA,EAAOE,QAAQF,GAAAA,YAAAA,EAAOG,QAGnDC,EAAsBjB,EAAMkB,QAChC,KAAO,CACLd,KAAAA,EACAG,oBAAAA,EACAC,yBAAAA,EACAH,SAAAA,EACAM,uBAAAA,EACAC,OAAAA,CAAAA,GAEF,CACER,EACAG,EACAC,EACAH,EACAM,EACAC,CAAM,CAEV,EAEMO,EAAQC,EACZjB,GAAU,GACVW,EACAR,EACAW,CACF,EAEA,OACGjB,EAAA,cAAAD,EAAa,SAAb,CAAsB,MAAO,CAAEoB,MAAAA,CAAAA,CAC9B,EAAAnB,EAAA,cAACqB,EAAAA,kBAAkB,CAAA,KAAAX,CAAA,EAAaD,CAAS,CAC3C,CAEJ,EAEaa,EAAiBA,IAAa,CACnCC,MAAAA,EAAUvB,EAAMwB,WAAWzB,CAAY,EAC7C,GAAI,CAACwB,EACG,MAAA,IAAIE,MAAM,oDAAoD,EAEtE,OAAOF,EAAQJ,KACjB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const k=require("@knocklabs/client"),g=require("react");require("../context/KnockProvider.js");const o=require("./useStableOptions.js");require("date-fns");const l=t=>t&&typeof t=="object"&&"default"in t?t:{default:t},q=l(k),d=l(g);function s(t,i,c,e={}){t.authenticate(i,c,{onUserTokenExpiring:e==null?void 0:e.onUserTokenExpiring,timeBeforeExpirationInMs:e==null?void 0:e.timeBeforeExpirationInMs,identificationStrategy:e==null?void 0:e.identificationStrategy})}function x(t,i,c,e={}){const f=d.default.useRef(void 0),u=o(e),n=o(i);return d.default.useMemo(()=>{const h=typeof n=="string"?n:n==null?void 0:n.id,r=f.current;if(r&&r.isAuthenticated()&&(r.userId!==h||r.userToken!==c))return s(r,n,c,u),r;r&&r.teardown();const a=new q.default(t,{host:u.host,logLevel:u.logLevel,branch:u.branch});return s(a,n,c,u),f.current=a,a},[t,n,c,u])}module.exports=x;
|
|
2
2
|
//# sourceMappingURL=useAuthenticatedKnockClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAuthenticatedKnockClient.js","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"sourcesContent":["import Knock, {\n AuthenticateOptions,\n KnockOptions,\n UserId,\n UserIdOrUserWithProperties,\n} from \"@knocklabs/client\";\nimport React from \"react\";\n\nimport { useStableOptions } from \"../../core\";\n\nfunction authenticateWithOptions(\n knock: Knock,\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options: AuthenticateOptions = {},\n) {\n knock.authenticate(userIdOrUserWithProperties, userToken, {\n onUserTokenExpiring: options?.onUserTokenExpiring,\n timeBeforeExpirationInMs: options?.timeBeforeExpirationInMs,\n identificationStrategy: options?.identificationStrategy,\n });\n}\n\nexport type AuthenticatedKnockClientOptions = KnockOptions &\n AuthenticateOptions;\n\n/**\n * @deprecated Passing `userId` as a `string` is deprecated and will be removed in a future version.\n * Please pass a `user` object instead containing an `id` value.\n * example:\n * ```ts\n * useAuthenticatedKnockClient(\"pk_test_12345\", { id: \"user_123\" });\n * ```\n */\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userIdOrUserWithProperties: UserId,\n userToken?: Knock[\"userToken\"],\n options?: AuthenticatedKnockClientOptions,\n): Knock;\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options?: AuthenticatedKnockClientOptions,\n): Knock;\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options: AuthenticatedKnockClientOptions = {},\n) {\n const knockRef = React.useRef<Knock | undefined>(undefined);\n\n const stableOptions = useStableOptions(options);\n const stableUserIdOrObject = useStableOptions(userIdOrUserWithProperties);\n\n return React.useMemo(() => {\n const userId =\n typeof stableUserIdOrObject === \"string\"\n ? stableUserIdOrObject\n : stableUserIdOrObject?.id;\n\n const currentKnock = knockRef.current;\n\n // If the userId and the userToken changes then just reauth\n if (\n currentKnock &&\n currentKnock.isAuthenticated() &&\n (currentKnock.userId !== userId || currentKnock.userToken !== userToken)\n ) {\n authenticateWithOptions(\n currentKnock,\n stableUserIdOrObject,\n userToken,\n stableOptions,\n );\n return currentKnock;\n }\n\n if (currentKnock) {\n currentKnock.teardown();\n }\n\n // Otherwise instantiate a new Knock client\n const knock = new Knock(apiKey, {\n host: stableOptions.host,\n logLevel: stableOptions.logLevel,\n });\n\n authenticateWithOptions(\n knock,\n stableUserIdOrObject,\n userToken,\n stableOptions,\n );\n knockRef.current = knock;\n\n return knock;\n }, [apiKey, stableUserIdOrObject, userToken, stableOptions]);\n}\n\nexport default useAuthenticatedKnockClient;\n"],"names":["authenticateWithOptions","knock","userIdOrUserWithProperties","userToken","options","authenticate","onUserTokenExpiring","timeBeforeExpirationInMs","identificationStrategy","useAuthenticatedKnockClient","apiKey","knockRef","React","useRef","undefined","stableOptions","useStableOptions","stableUserIdOrObject","useMemo","userId","id","currentKnock","current","isAuthenticated","teardown","Knock","host","logLevel"],"mappings":"qPAUA,SAASA,EACPC,EACAC,EACAC,EACAC,EAA+B,CAAA,EAC/B,CACMC,EAAAA,aAAaH,EAA4BC,EAAW,CACxDG,oBAAqBF,GAAAA,YAAAA,EAASE,oBAC9BC,yBAA0BH,GAAAA,YAAAA,EAASG,yBACnCC,uBAAwBJ,GAAAA,YAAAA,EAASI,sBAAAA,CAClC,CACH,CAyBA,SAASC,EACPC,EACAR,EACAC,EACAC,EAA2C,CAAA,EAC3C,CACMO,MAAAA,EAAWC,EAAAA,QAAMC,OAA0BC,MAAS,EAEpDC,EAAgBC,EAAiBZ,CAAO,EACxCa,EAAuBD,EAAiBd,CAA0B,EAEjEU,OAAAA,EAAAA,QAAMM,QAAQ,IAAM,CACzB,MAAMC,EACJ,OAAOF,GAAyB,SAC5BA,EACAA,GAAAA,YAAAA,EAAsBG,GAEtBC,EAAeV,EAASW,QAI5BD,GAAAA,GACAA,EAAaE,gBAAgB,IAC5BF,EAAaF,SAAWA,GAAUE,EAAalB,YAAcA,GAG5DkB,OAAAA,EAAAA,EACAJ,EACAd,EACAY,CACF,EACOM,EAGLA,GACFA,EAAaG,SAAS,EAIlBvB,MAAAA,EAAQ,IAAIwB,EAAAA,QAAMf,EAAQ,CAC9BgB,KAAMX,EAAcW,KACpBC,SAAUZ,EAAcY,
|
|
1
|
+
{"version":3,"file":"useAuthenticatedKnockClient.js","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"sourcesContent":["import Knock, {\n AuthenticateOptions,\n KnockOptions,\n UserId,\n UserIdOrUserWithProperties,\n} from \"@knocklabs/client\";\nimport React from \"react\";\n\nimport { useStableOptions } from \"../../core\";\n\nfunction authenticateWithOptions(\n knock: Knock,\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options: AuthenticateOptions = {},\n) {\n knock.authenticate(userIdOrUserWithProperties, userToken, {\n onUserTokenExpiring: options?.onUserTokenExpiring,\n timeBeforeExpirationInMs: options?.timeBeforeExpirationInMs,\n identificationStrategy: options?.identificationStrategy,\n });\n}\n\nexport type AuthenticatedKnockClientOptions = KnockOptions &\n AuthenticateOptions;\n\n/**\n * @deprecated Passing `userId` as a `string` is deprecated and will be removed in a future version.\n * Please pass a `user` object instead containing an `id` value.\n * example:\n * ```ts\n * useAuthenticatedKnockClient(\"pk_test_12345\", { id: \"user_123\" });\n * ```\n */\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userIdOrUserWithProperties: UserId,\n userToken?: Knock[\"userToken\"],\n options?: AuthenticatedKnockClientOptions,\n): Knock;\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options?: AuthenticatedKnockClientOptions,\n): Knock;\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options: AuthenticatedKnockClientOptions = {},\n) {\n const knockRef = React.useRef<Knock | undefined>(undefined);\n\n const stableOptions = useStableOptions(options);\n const stableUserIdOrObject = useStableOptions(userIdOrUserWithProperties);\n\n return React.useMemo(() => {\n const userId =\n typeof stableUserIdOrObject === \"string\"\n ? stableUserIdOrObject\n : stableUserIdOrObject?.id;\n\n const currentKnock = knockRef.current;\n\n // If the userId and the userToken changes then just reauth\n if (\n currentKnock &&\n currentKnock.isAuthenticated() &&\n (currentKnock.userId !== userId || currentKnock.userToken !== userToken)\n ) {\n authenticateWithOptions(\n currentKnock,\n stableUserIdOrObject,\n userToken,\n stableOptions,\n );\n return currentKnock;\n }\n\n if (currentKnock) {\n currentKnock.teardown();\n }\n\n // Otherwise instantiate a new Knock client\n const knock = new Knock(apiKey, {\n host: stableOptions.host,\n logLevel: stableOptions.logLevel,\n branch: stableOptions.branch,\n });\n\n authenticateWithOptions(\n knock,\n stableUserIdOrObject,\n userToken,\n stableOptions,\n );\n knockRef.current = knock;\n\n return knock;\n }, [apiKey, stableUserIdOrObject, userToken, stableOptions]);\n}\n\nexport default useAuthenticatedKnockClient;\n"],"names":["authenticateWithOptions","knock","userIdOrUserWithProperties","userToken","options","authenticate","onUserTokenExpiring","timeBeforeExpirationInMs","identificationStrategy","useAuthenticatedKnockClient","apiKey","knockRef","React","useRef","undefined","stableOptions","useStableOptions","stableUserIdOrObject","useMemo","userId","id","currentKnock","current","isAuthenticated","teardown","Knock","host","logLevel","branch"],"mappings":"qPAUA,SAASA,EACPC,EACAC,EACAC,EACAC,EAA+B,CAAA,EAC/B,CACMC,EAAAA,aAAaH,EAA4BC,EAAW,CACxDG,oBAAqBF,GAAAA,YAAAA,EAASE,oBAC9BC,yBAA0BH,GAAAA,YAAAA,EAASG,yBACnCC,uBAAwBJ,GAAAA,YAAAA,EAASI,sBAAAA,CAClC,CACH,CAyBA,SAASC,EACPC,EACAR,EACAC,EACAC,EAA2C,CAAA,EAC3C,CACMO,MAAAA,EAAWC,EAAAA,QAAMC,OAA0BC,MAAS,EAEpDC,EAAgBC,EAAiBZ,CAAO,EACxCa,EAAuBD,EAAiBd,CAA0B,EAEjEU,OAAAA,EAAAA,QAAMM,QAAQ,IAAM,CACzB,MAAMC,EACJ,OAAOF,GAAyB,SAC5BA,EACAA,GAAAA,YAAAA,EAAsBG,GAEtBC,EAAeV,EAASW,QAI5BD,GAAAA,GACAA,EAAaE,gBAAgB,IAC5BF,EAAaF,SAAWA,GAAUE,EAAalB,YAAcA,GAG5DkB,OAAAA,EAAAA,EACAJ,EACAd,EACAY,CACF,EACOM,EAGLA,GACFA,EAAaG,SAAS,EAIlBvB,MAAAA,EAAQ,IAAIwB,EAAAA,QAAMf,EAAQ,CAC9BgB,KAAMX,EAAcW,KACpBC,SAAUZ,EAAcY,SACxBC,OAAQb,EAAca,MAAAA,CACvB,EAGC3B,OAAAA,EAAAA,EACAgB,EACAd,EACAY,CACF,EACAJ,EAASW,QAAUrB,EAEZA,GACN,CAACS,EAAQO,EAAsBd,EAAWY,CAAa,CAAC,CAC7D"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const m=require("../context/KnockMsTeamsProvider.js"),o=require("react");require("../../i18n/context/KnockI18nProvider.js");const T=require("@knocklabs/client"),_=require("../../core/context/KnockProvider.js");require("fast-deep-equal");require("date-fns");require("swr/infinite");require("swr");const d="https://login.microsoftonline.com/organizations/adminconsent",h="/providers/ms-teams/authenticate";function C(c,a){const e=_.useKnockClient(),{setConnectionStatus:n,knockMsTeamsChannelId:s,tenantId:t,setActionLabel:i}=m.useKnockMsTeamsClient(),u=o.useMemo(()=>e.host+h,[e.host]),k=o.useCallback(()=>{const r={state:JSON.stringify({redirect_url:a,ms_teams_tenant_object:{object_id:t,collection:T.TENANT_OBJECT_COLLECTION},channel_id:s,public_key:e.apiKey,user_token:e.userToken,branch_slug:e.branch}),client_id:c,redirect_uri:u};return`${d}?${new URLSearchParams(r)}`},[a,t,s,e.apiKey,e.userToken,e.branch,c,u]),l=o.useCallback(async()=>{i(null),n("disconnecting");try{const r=await e.msTeams.revokeAccessToken({tenant:t,knockChannelId:s});n(r==="ok"?"disconnected":"error")}catch{n("error")}},[n,e.msTeams,t,s,i]);return{buildMsTeamsAuthUrl:k,disconnectFromMsTeams:l}}module.exports=C;
|
|
2
2
|
//# sourceMappingURL=useMsTeamsAuth.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMsTeamsAuth.js","sources":["../../../../../src/modules/ms-teams/hooks/useMsTeamsAuth.ts"],"sourcesContent":["import { useKnockMsTeamsClient } from \"..\";\nimport { TENANT_OBJECT_COLLECTION } from \"@knocklabs/client\";\nimport { useCallback, useMemo } from \"react\";\n\nimport { useKnockClient } from \"../../core\";\n\nconst MS_TEAMS_ADMINCONSENT_URL =\n \"https://login.microsoftonline.com/organizations/adminconsent\";\n\nconst AUTH_REDIRECT_PATH = \"/providers/ms-teams/authenticate\";\n\ninterface UseMsTeamsAuthOutput {\n buildMsTeamsAuthUrl: () => string;\n disconnectFromMsTeams: () => void;\n}\n\nfunction useMsTeamsAuth(\n graphApiClientId: string,\n redirectUrl?: string,\n): UseMsTeamsAuthOutput {\n const knock = useKnockClient();\n const {\n setConnectionStatus,\n knockMsTeamsChannelId,\n tenantId,\n setActionLabel,\n } = useKnockMsTeamsClient();\n\n const authRedirectUri = useMemo(\n () => knock.host + AUTH_REDIRECT_PATH,\n [knock.host],\n );\n\n const buildMsTeamsAuthUrl = useCallback(() => {\n const rawParams = {\n state: JSON.stringify({\n redirect_url: redirectUrl,\n ms_teams_tenant_object: {\n object_id: tenantId,\n collection: TENANT_OBJECT_COLLECTION,\n },\n channel_id: knockMsTeamsChannelId,\n public_key: knock.apiKey,\n user_token: knock.userToken,\n }),\n client_id: graphApiClientId,\n redirect_uri: authRedirectUri,\n };\n return `${MS_TEAMS_ADMINCONSENT_URL}?${new URLSearchParams(rawParams)}`;\n }, [\n redirectUrl,\n tenantId,\n knockMsTeamsChannelId,\n knock.apiKey,\n knock.userToken,\n graphApiClientId,\n authRedirectUri,\n ]);\n\n const disconnectFromMsTeams = useCallback(async () => {\n setActionLabel(null);\n setConnectionStatus(\"disconnecting\");\n try {\n const revokeResult = await knock.msTeams.revokeAccessToken({\n tenant: tenantId,\n knockChannelId: knockMsTeamsChannelId,\n });\n\n setConnectionStatus(revokeResult === \"ok\" ? \"disconnected\" : \"error\");\n } catch (_error) {\n setConnectionStatus(\"error\");\n }\n }, [\n setConnectionStatus,\n knock.msTeams,\n tenantId,\n knockMsTeamsChannelId,\n setActionLabel,\n ]);\n\n return { buildMsTeamsAuthUrl, disconnectFromMsTeams };\n}\n\nexport default useMsTeamsAuth;\n"],"names":["MS_TEAMS_ADMINCONSENT_URL","AUTH_REDIRECT_PATH","useMsTeamsAuth","graphApiClientId","redirectUrl","knock","useKnockClient","setConnectionStatus","knockMsTeamsChannelId","tenantId","setActionLabel","useKnockMsTeamsClient","authRedirectUri","useMemo","host","buildMsTeamsAuthUrl","useCallback","rawParams","state","JSON","stringify","redirect_url","ms_teams_tenant_object","object_id","collection","TENANT_OBJECT_COLLECTION","channel_id","public_key","apiKey","user_token","userToken","client_id","redirect_uri","URLSearchParams","disconnectFromMsTeams","revokeResult","msTeams","revokeAccessToken","tenant","knockChannelId"],"mappings":"qTAMA,MAAMA,EACJ,+DAEIC,EAAqB,mCAO3B,SAASC,EACPC,EACAC,EACsB,CACtB,MAAMC,EAAQC,EAAAA,eAAe,EACvB,CACJC,oBAAAA,EACAC,sBAAAA,EACAC,SAAAA,EACAC,eAAAA,GACEC,wBAAsB,EAEpBC,EAAkBC,UACtB,IAAMR,EAAMS,KAAOb,EACnB,CAACI,EAAMS,IAAI,CACb,EAEMC,EAAsBC,EAAAA,YAAY,IAAM,CAC5C,MAAMC,EAAY,CAChBC,MAAOC,KAAKC,UAAU,CACpBC,aAAcjB,EACdkB,uBAAwB,CACtBC,UAAWd,EACXe,WAAYC,EAAAA,wBACd,EACAC,WAAYlB,EACZmB,WAAYtB,EAAMuB,OAClBC,WAAYxB,EAAMyB,
|
|
1
|
+
{"version":3,"file":"useMsTeamsAuth.js","sources":["../../../../../src/modules/ms-teams/hooks/useMsTeamsAuth.ts"],"sourcesContent":["import { useKnockMsTeamsClient } from \"..\";\nimport { TENANT_OBJECT_COLLECTION } from \"@knocklabs/client\";\nimport { useCallback, useMemo } from \"react\";\n\nimport { useKnockClient } from \"../../core\";\n\nconst MS_TEAMS_ADMINCONSENT_URL =\n \"https://login.microsoftonline.com/organizations/adminconsent\";\n\nconst AUTH_REDIRECT_PATH = \"/providers/ms-teams/authenticate\";\n\ninterface UseMsTeamsAuthOutput {\n buildMsTeamsAuthUrl: () => string;\n disconnectFromMsTeams: () => void;\n}\n\nfunction useMsTeamsAuth(\n graphApiClientId: string,\n redirectUrl?: string,\n): UseMsTeamsAuthOutput {\n const knock = useKnockClient();\n const {\n setConnectionStatus,\n knockMsTeamsChannelId,\n tenantId,\n setActionLabel,\n } = useKnockMsTeamsClient();\n\n const authRedirectUri = useMemo(\n () => knock.host + AUTH_REDIRECT_PATH,\n [knock.host],\n );\n\n const buildMsTeamsAuthUrl = useCallback(() => {\n const rawParams = {\n state: JSON.stringify({\n redirect_url: redirectUrl,\n ms_teams_tenant_object: {\n object_id: tenantId,\n collection: TENANT_OBJECT_COLLECTION,\n },\n channel_id: knockMsTeamsChannelId,\n public_key: knock.apiKey,\n user_token: knock.userToken,\n branch_slug: knock.branch,\n }),\n client_id: graphApiClientId,\n redirect_uri: authRedirectUri,\n };\n return `${MS_TEAMS_ADMINCONSENT_URL}?${new URLSearchParams(rawParams)}`;\n }, [\n redirectUrl,\n tenantId,\n knockMsTeamsChannelId,\n knock.apiKey,\n knock.userToken,\n knock.branch,\n graphApiClientId,\n authRedirectUri,\n ]);\n\n const disconnectFromMsTeams = useCallback(async () => {\n setActionLabel(null);\n setConnectionStatus(\"disconnecting\");\n try {\n const revokeResult = await knock.msTeams.revokeAccessToken({\n tenant: tenantId,\n knockChannelId: knockMsTeamsChannelId,\n });\n\n setConnectionStatus(revokeResult === \"ok\" ? \"disconnected\" : \"error\");\n } catch (_error) {\n setConnectionStatus(\"error\");\n }\n }, [\n setConnectionStatus,\n knock.msTeams,\n tenantId,\n knockMsTeamsChannelId,\n setActionLabel,\n ]);\n\n return { buildMsTeamsAuthUrl, disconnectFromMsTeams };\n}\n\nexport default useMsTeamsAuth;\n"],"names":["MS_TEAMS_ADMINCONSENT_URL","AUTH_REDIRECT_PATH","useMsTeamsAuth","graphApiClientId","redirectUrl","knock","useKnockClient","setConnectionStatus","knockMsTeamsChannelId","tenantId","setActionLabel","useKnockMsTeamsClient","authRedirectUri","useMemo","host","buildMsTeamsAuthUrl","useCallback","rawParams","state","JSON","stringify","redirect_url","ms_teams_tenant_object","object_id","collection","TENANT_OBJECT_COLLECTION","channel_id","public_key","apiKey","user_token","userToken","branch_slug","branch","client_id","redirect_uri","URLSearchParams","disconnectFromMsTeams","revokeResult","msTeams","revokeAccessToken","tenant","knockChannelId"],"mappings":"qTAMA,MAAMA,EACJ,+DAEIC,EAAqB,mCAO3B,SAASC,EACPC,EACAC,EACsB,CACtB,MAAMC,EAAQC,EAAAA,eAAe,EACvB,CACJC,oBAAAA,EACAC,sBAAAA,EACAC,SAAAA,EACAC,eAAAA,GACEC,wBAAsB,EAEpBC,EAAkBC,UACtB,IAAMR,EAAMS,KAAOb,EACnB,CAACI,EAAMS,IAAI,CACb,EAEMC,EAAsBC,EAAAA,YAAY,IAAM,CAC5C,MAAMC,EAAY,CAChBC,MAAOC,KAAKC,UAAU,CACpBC,aAAcjB,EACdkB,uBAAwB,CACtBC,UAAWd,EACXe,WAAYC,EAAAA,wBACd,EACAC,WAAYlB,EACZmB,WAAYtB,EAAMuB,OAClBC,WAAYxB,EAAMyB,UAClBC,YAAa1B,EAAM2B,MAAAA,CACpB,EACDC,UAAW9B,EACX+B,aAActB,CAChB,EACA,MAAO,GAAGZ,CAAyB,IAAI,IAAImC,gBAAgBlB,CAAS,CAAC,EACpE,EAAA,CACDb,EACAK,EACAD,EACAH,EAAMuB,OACNvB,EAAMyB,UACNzB,EAAM2B,OACN7B,EACAS,CAAe,CAChB,EAEKwB,EAAwBpB,EAAAA,YAAY,SAAY,CACpDN,EAAe,IAAI,EACnBH,EAAoB,eAAe,EAC/B,GAAA,CACF,MAAM8B,EAAe,MAAMhC,EAAMiC,QAAQC,kBAAkB,CACzDC,OAAQ/B,EACRgC,eAAgBjC,CAAAA,CACjB,EAEmB6B,EAAAA,IAAiB,KAAO,eAAiB,OAAO,OACrD,CACf9B,EAAoB,OAAO,CAAA,CAC7B,EACC,CACDA,EACAF,EAAMiC,QACN7B,EACAD,EACAE,CAAc,CACf,EAEM,MAAA,CAAEK,oBAAAA,EAAqBqB,sBAAAA,CAAsB,CACtD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const p=require("../context/KnockSlackProvider.js"),l=require("react");require("../../i18n/context/KnockI18nProvider.js");require("swr/infinite");const _=require("../../core/context/KnockProvider.js"),b=require("@knocklabs/client");require("fast-deep-equal");require("date-fns");require("swr");const A="https://slack.com/oauth/v2/authorize",s=["chat:write","chat:write.public","channels:read","groups:read"];function C(e){return e?Array.isArray(e)?{scopes:s,additionalScopes:e}:{scopes:e.scopes??s,additionalScopes:e.additionalScopes??[]}:{scopes:s,additionalScopes:[]}}function q(e,a,k){const c=_.useKnockClient(),{setConnectionStatus:n,knockSlackChannelId:r,tenantId:o,setActionLabel:i}=p.useKnockSlackClient(),{scopes:d,additionalScopes:S}=C(k),u=Array.from(new Set(d.concat(S))),h=l.useCallback(async()=>{i(null),n("disconnecting");try{const t=await c.slack.revokeAccessToken({tenant:o,knockChannelId:r});n(t==="ok"?"disconnected":"error")}catch{n("error")}},[n,c.slack,o,r,i]);return{buildSlackAuthUrl:l.useCallback(()=>{const t={state:JSON.stringify({redirect_url:a,access_token_object:{object_id:o,collection:b.TENANT_OBJECT_COLLECTION},channel_id:r,public_key:c.apiKey,user_token:c.userToken,branch_slug:c.branch}),client_id:e,scope:u.join(",")};return`${A}?${new URLSearchParams(t)}`},[a,o,r,c.apiKey,c.userToken,c.branch,e,u]),disconnectFromSlack:h}}module.exports=q;
|
|
2
2
|
//# sourceMappingURL=useSlackAuth.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSlackAuth.js","sources":["../../../../../src/modules/slack/hooks/useSlackAuth.ts"],"sourcesContent":["import { useKnockSlackClient } from \"..\";\nimport { TENANT_OBJECT_COLLECTION } from \"@knocklabs/client\";\nimport { useCallback } from \"react\";\n\nimport { useKnockClient } from \"../../core\";\n\nconst SLACK_AUTHORIZE_URL = \"https://slack.com/oauth/v2/authorize\";\nconst DEFAULT_SLACK_SCOPES = [\n \"chat:write\",\n \"chat:write.public\",\n \"channels:read\",\n \"groups:read\",\n];\n\ntype UseSlackAuthOutput = {\n buildSlackAuthUrl: () => string;\n disconnectFromSlack: () => void;\n};\n\ntype UseSlackAuthOptions = {\n // When provided, the default scopes will be overridden with the provided scopes\n scopes?: string[];\n // Additional scopes to add to the default scopes\n additionalScopes?: string[];\n};\n\n// Here we normalize the options to be a single object with scopes and additionalScopes\n// The \"options\" parameter can be an array of scopes, an object with scopes and additionalScopes, or undefined\n// We handle the array case because it was the previous way to pass options so we're being backward compatible\nfunction normalizeOptions(options?: UseSlackAuthOptions | string[]): {\n scopes: string[];\n additionalScopes: string[];\n} {\n if (!options) {\n return { scopes: DEFAULT_SLACK_SCOPES, additionalScopes: [] };\n }\n\n if (Array.isArray(options)) {\n return { scopes: DEFAULT_SLACK_SCOPES, additionalScopes: options };\n }\n\n return {\n scopes: options.scopes ?? DEFAULT_SLACK_SCOPES,\n additionalScopes: options.additionalScopes ?? [],\n };\n}\n\nfunction useSlackAuth(\n slackClientId: string,\n redirectUrl?: string,\n options?: UseSlackAuthOptions | string[],\n): UseSlackAuthOutput {\n const knock = useKnockClient();\n const { setConnectionStatus, knockSlackChannelId, tenantId, setActionLabel } =\n useKnockSlackClient();\n\n const { scopes, additionalScopes } = normalizeOptions(options);\n const combinedScopes = Array.from(new Set(scopes.concat(additionalScopes)));\n\n const disconnectFromSlack = useCallback(async () => {\n setActionLabel(null);\n setConnectionStatus(\"disconnecting\");\n try {\n const revoke = await knock.slack.revokeAccessToken({\n tenant: tenantId,\n knockChannelId: knockSlackChannelId,\n });\n\n if (revoke === \"ok\") {\n setConnectionStatus(\"disconnected\");\n } else {\n setConnectionStatus(\"error\");\n }\n } catch (_error) {\n setConnectionStatus(\"error\");\n }\n }, [\n setConnectionStatus,\n knock.slack,\n tenantId,\n knockSlackChannelId,\n setActionLabel,\n ]);\n\n const buildSlackAuthUrl = useCallback(() => {\n const rawParams = {\n state: JSON.stringify({\n redirect_url: redirectUrl,\n access_token_object: {\n object_id: tenantId,\n collection: TENANT_OBJECT_COLLECTION,\n },\n channel_id: knockSlackChannelId,\n public_key: knock.apiKey,\n user_token: knock.userToken,\n }),\n client_id: slackClientId,\n scope: combinedScopes.join(\",\"),\n };\n return `${SLACK_AUTHORIZE_URL}?${new URLSearchParams(rawParams)}`;\n }, [\n redirectUrl,\n tenantId,\n knockSlackChannelId,\n knock.apiKey,\n knock.userToken,\n slackClientId,\n combinedScopes,\n ]);\n\n return {\n buildSlackAuthUrl,\n disconnectFromSlack,\n };\n}\n\nexport default useSlackAuth;\n"],"names":["SLACK_AUTHORIZE_URL","DEFAULT_SLACK_SCOPES","normalizeOptions","options","Array","isArray","scopes","additionalScopes","useSlackAuth","slackClientId","redirectUrl","knock","useKnockClient","setConnectionStatus","knockSlackChannelId","tenantId","setActionLabel","useKnockSlackClient","combinedScopes","from","Set","concat","disconnectFromSlack","useCallback","revoke","slack","revokeAccessToken","tenant","knockChannelId","buildSlackAuthUrl","rawParams","state","JSON","stringify","redirect_url","access_token_object","object_id","collection","TENANT_OBJECT_COLLECTION","channel_id","public_key","apiKey","user_token","userToken","client_id","scope","join","URLSearchParams"],"mappings":"mTAMA,MAAMA,EAAsB,uCACtBC,EAAuB,CAC3B,aACA,oBACA,gBACA,aAAa,EAkBf,SAASC,EAAiBC,EAGxB,CACA,OAAKA,EAIDC,MAAMC,QAAQF,CAAO,EAChB,CAAEG,OAAQL,EAAsBM,iBAAkBJ,CAAQ,EAG5D,CACLG,OAAQH,EAAQG,QAAUL,EAC1BM,iBAAkBJ,EAAQI,kBAAoB,CAAA,CAChD,EAVS,CAAED,OAAQL,EAAsBM,iBAAkB,CAAA,CAAG,CAWhE,CAEA,SAASC,EACPC,EACAC,EACAP,EACoB,CACpB,MAAMQ,EAAQC,EAAAA,eAAe,EACvB,CAAEC,oBAAAA,EAAqBC,oBAAAA,EAAqBC,SAAAA,EAAUC,eAAAA,GAC1DC,sBAAoB,EAEhB,CAAEX,OAAAA,EAAQC,iBAAAA,CAAAA,EAAqBL,EAAiBC,CAAO,EACvDe,EAAiBd,MAAMe,KAAK,IAAIC,IAAId,EAAOe,OAAOd,CAAgB,CAAC,CAAC,EAEpEe,EAAsBC,EAAAA,YAAY,SAAY,CAClDP,EAAe,IAAI,EACnBH,EAAoB,eAAe,EAC/B,GAAA,CACF,MAAMW,EAAS,MAAMb,EAAMc,MAAMC,kBAAkB,CACjDC,OAAQZ,EACRa,eAAgBd,CAAAA,CACjB,EAGCD,EADEW,IAAW,KACO,eAEA,OAFc,OAIrB,CACfX,EAAoB,OAAO,CAAA,CAC7B,EACC,CACDA,EACAF,EAAMc,MACNV,EACAD,EACAE,CAAc,CACf,
|
|
1
|
+
{"version":3,"file":"useSlackAuth.js","sources":["../../../../../src/modules/slack/hooks/useSlackAuth.ts"],"sourcesContent":["import { useKnockSlackClient } from \"..\";\nimport { TENANT_OBJECT_COLLECTION } from \"@knocklabs/client\";\nimport { useCallback } from \"react\";\n\nimport { useKnockClient } from \"../../core\";\n\nconst SLACK_AUTHORIZE_URL = \"https://slack.com/oauth/v2/authorize\";\nconst DEFAULT_SLACK_SCOPES = [\n \"chat:write\",\n \"chat:write.public\",\n \"channels:read\",\n \"groups:read\",\n];\n\ntype UseSlackAuthOutput = {\n buildSlackAuthUrl: () => string;\n disconnectFromSlack: () => void;\n};\n\ntype UseSlackAuthOptions = {\n // When provided, the default scopes will be overridden with the provided scopes\n scopes?: string[];\n // Additional scopes to add to the default scopes\n additionalScopes?: string[];\n};\n\n// Here we normalize the options to be a single object with scopes and additionalScopes\n// The \"options\" parameter can be an array of scopes, an object with scopes and additionalScopes, or undefined\n// We handle the array case because it was the previous way to pass options so we're being backward compatible\nfunction normalizeOptions(options?: UseSlackAuthOptions | string[]): {\n scopes: string[];\n additionalScopes: string[];\n} {\n if (!options) {\n return { scopes: DEFAULT_SLACK_SCOPES, additionalScopes: [] };\n }\n\n if (Array.isArray(options)) {\n return { scopes: DEFAULT_SLACK_SCOPES, additionalScopes: options };\n }\n\n return {\n scopes: options.scopes ?? DEFAULT_SLACK_SCOPES,\n additionalScopes: options.additionalScopes ?? [],\n };\n}\n\nfunction useSlackAuth(\n slackClientId: string,\n redirectUrl?: string,\n options?: UseSlackAuthOptions | string[],\n): UseSlackAuthOutput {\n const knock = useKnockClient();\n const { setConnectionStatus, knockSlackChannelId, tenantId, setActionLabel } =\n useKnockSlackClient();\n\n const { scopes, additionalScopes } = normalizeOptions(options);\n const combinedScopes = Array.from(new Set(scopes.concat(additionalScopes)));\n\n const disconnectFromSlack = useCallback(async () => {\n setActionLabel(null);\n setConnectionStatus(\"disconnecting\");\n try {\n const revoke = await knock.slack.revokeAccessToken({\n tenant: tenantId,\n knockChannelId: knockSlackChannelId,\n });\n\n if (revoke === \"ok\") {\n setConnectionStatus(\"disconnected\");\n } else {\n setConnectionStatus(\"error\");\n }\n } catch (_error) {\n setConnectionStatus(\"error\");\n }\n }, [\n setConnectionStatus,\n knock.slack,\n tenantId,\n knockSlackChannelId,\n setActionLabel,\n ]);\n\n const buildSlackAuthUrl = useCallback(() => {\n const rawParams = {\n state: JSON.stringify({\n redirect_url: redirectUrl,\n access_token_object: {\n object_id: tenantId,\n collection: TENANT_OBJECT_COLLECTION,\n },\n channel_id: knockSlackChannelId,\n public_key: knock.apiKey,\n user_token: knock.userToken,\n branch_slug: knock.branch,\n }),\n client_id: slackClientId,\n scope: combinedScopes.join(\",\"),\n };\n return `${SLACK_AUTHORIZE_URL}?${new URLSearchParams(rawParams)}`;\n }, [\n redirectUrl,\n tenantId,\n knockSlackChannelId,\n knock.apiKey,\n knock.userToken,\n knock.branch,\n slackClientId,\n combinedScopes,\n ]);\n\n return {\n buildSlackAuthUrl,\n disconnectFromSlack,\n };\n}\n\nexport default useSlackAuth;\n"],"names":["SLACK_AUTHORIZE_URL","DEFAULT_SLACK_SCOPES","normalizeOptions","options","Array","isArray","scopes","additionalScopes","useSlackAuth","slackClientId","redirectUrl","knock","useKnockClient","setConnectionStatus","knockSlackChannelId","tenantId","setActionLabel","useKnockSlackClient","combinedScopes","from","Set","concat","disconnectFromSlack","useCallback","revoke","slack","revokeAccessToken","tenant","knockChannelId","buildSlackAuthUrl","rawParams","state","JSON","stringify","redirect_url","access_token_object","object_id","collection","TENANT_OBJECT_COLLECTION","channel_id","public_key","apiKey","user_token","userToken","branch_slug","branch","client_id","scope","join","URLSearchParams"],"mappings":"mTAMA,MAAMA,EAAsB,uCACtBC,EAAuB,CAC3B,aACA,oBACA,gBACA,aAAa,EAkBf,SAASC,EAAiBC,EAGxB,CACA,OAAKA,EAIDC,MAAMC,QAAQF,CAAO,EAChB,CAAEG,OAAQL,EAAsBM,iBAAkBJ,CAAQ,EAG5D,CACLG,OAAQH,EAAQG,QAAUL,EAC1BM,iBAAkBJ,EAAQI,kBAAoB,CAAA,CAChD,EAVS,CAAED,OAAQL,EAAsBM,iBAAkB,CAAA,CAAG,CAWhE,CAEA,SAASC,EACPC,EACAC,EACAP,EACoB,CACpB,MAAMQ,EAAQC,EAAAA,eAAe,EACvB,CAAEC,oBAAAA,EAAqBC,oBAAAA,EAAqBC,SAAAA,EAAUC,eAAAA,GAC1DC,sBAAoB,EAEhB,CAAEX,OAAAA,EAAQC,iBAAAA,CAAAA,EAAqBL,EAAiBC,CAAO,EACvDe,EAAiBd,MAAMe,KAAK,IAAIC,IAAId,EAAOe,OAAOd,CAAgB,CAAC,CAAC,EAEpEe,EAAsBC,EAAAA,YAAY,SAAY,CAClDP,EAAe,IAAI,EACnBH,EAAoB,eAAe,EAC/B,GAAA,CACF,MAAMW,EAAS,MAAMb,EAAMc,MAAMC,kBAAkB,CACjDC,OAAQZ,EACRa,eAAgBd,CAAAA,CACjB,EAGCD,EADEW,IAAW,KACO,eAEA,OAFc,OAIrB,CACfX,EAAoB,OAAO,CAAA,CAC7B,EACC,CACDA,EACAF,EAAMc,MACNV,EACAD,EACAE,CAAc,CACf,EA8BM,MAAA,CACLa,kBA7BwBN,EAAAA,YAAY,IAAM,CAC1C,MAAMO,EAAY,CAChBC,MAAOC,KAAKC,UAAU,CACpBC,aAAcxB,EACdyB,oBAAqB,CACnBC,UAAWrB,EACXsB,WAAYC,EAAAA,wBACd,EACAC,WAAYzB,EACZ0B,WAAY7B,EAAM8B,OAClBC,WAAY/B,EAAMgC,UAClBC,YAAajC,EAAMkC,MAAAA,CACpB,EACDC,UAAWrC,EACXsC,MAAO7B,EAAe8B,KAAK,GAAG,CAChC,EACA,MAAO,GAAGhD,CAAmB,IAAI,IAAIiD,gBAAgBnB,CAAS,CAAC,EAC9D,EAAA,CACDpB,EACAK,EACAD,EACAH,EAAM8B,OACN9B,EAAMgC,UACNhC,EAAMkC,OACNpC,EACAS,CAAc,CACf,EAICI,oBAAAA,CACF,CACF"}
|
|
@@ -1,37 +1,39 @@
|
|
|
1
1
|
import * as t from "react";
|
|
2
|
-
import { KnockI18nProvider as
|
|
3
|
-
import
|
|
2
|
+
import { KnockI18nProvider as P } from "../../i18n/context/KnockI18nProvider.mjs";
|
|
3
|
+
import v from "../hooks/useAuthenticatedKnockClient.mjs";
|
|
4
4
|
import "fast-deep-equal";
|
|
5
|
-
const
|
|
5
|
+
const m = t.createContext(null), f = ({
|
|
6
6
|
apiKey: n,
|
|
7
7
|
host: c,
|
|
8
8
|
logLevel: o,
|
|
9
|
-
userToken:
|
|
9
|
+
userToken: s,
|
|
10
10
|
onUserTokenExpiring: r,
|
|
11
11
|
timeBeforeExpirationInMs: u,
|
|
12
|
-
children:
|
|
13
|
-
i18n:
|
|
12
|
+
children: d,
|
|
13
|
+
i18n: K,
|
|
14
14
|
identificationStrategy: i,
|
|
15
|
+
branch: k,
|
|
15
16
|
...e
|
|
16
17
|
}) => {
|
|
17
|
-
const
|
|
18
|
+
const a = (e == null ? void 0 : e.user) || (e == null ? void 0 : e.userId), l = t.useMemo(() => ({
|
|
18
19
|
host: c,
|
|
19
20
|
onUserTokenExpiring: r,
|
|
20
21
|
timeBeforeExpirationInMs: u,
|
|
21
22
|
logLevel: o,
|
|
22
|
-
identificationStrategy: i
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
},
|
|
28
|
-
|
|
23
|
+
identificationStrategy: i,
|
|
24
|
+
branch: k
|
|
25
|
+
}), [c, r, u, o, i, k]), C = v(n ?? "", a, s, l);
|
|
26
|
+
return /* @__PURE__ */ t.createElement(m.Provider, { value: {
|
|
27
|
+
knock: C
|
|
28
|
+
} }, /* @__PURE__ */ t.createElement(P, { i18n: K }, d));
|
|
29
|
+
}, I = () => {
|
|
30
|
+
const n = t.useContext(m);
|
|
29
31
|
if (!n)
|
|
30
32
|
throw new Error("useKnockClient must be used within a KnockProvider");
|
|
31
33
|
return n.knock;
|
|
32
34
|
};
|
|
33
35
|
export {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
f as KnockProvider,
|
|
37
|
+
I as useKnockClient
|
|
36
38
|
};
|
|
37
39
|
//# sourceMappingURL=KnockProvider.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KnockProvider.mjs","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"sourcesContent":["import Knock, {\n AuthenticateOptions,\n LogLevel,\n UserWithProperties,\n} from \"@knocklabs/client\";\nimport * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\n\nimport { I18nContent, KnockI18nProvider } from \"../../i18n\";\nimport { useAuthenticatedKnockClient } from \"../hooks\";\n\nexport interface KnockProviderState {\n knock: Knock;\n}\n\nconst KnockContext = React.createContext<KnockProviderState | null>(null);\n\nexport type KnockProviderProps = {\n // Knock client props\n apiKey: string | undefined;\n host?: string;\n userToken?: Knock[\"userToken\"];\n onUserTokenExpiring?: AuthenticateOptions[\"onUserTokenExpiring\"];\n timeBeforeExpirationInMs?: AuthenticateOptions[\"timeBeforeExpirationInMs\"];\n // i18n translations\n i18n?: I18nContent;\n logLevel?: LogLevel;\n} & (\n | {\n /**\n * @deprecated The `userId` prop is deprecated and will be removed in a future version.\n * Please pass the `user` prop instead containing an `id` value.\n * example:\n * ```ts\n * <KnockProvider user={{ id: \"user_123\" }}></KnockProvider>\n * ```\n */\n userId: Knock[\"userId\"];\n user?: never;\n identificationStrategy?: never;\n }\n | {\n user: UserWithProperties;\n identificationStrategy?: AuthenticateOptions[\"identificationStrategy\"];\n /**\n * @deprecated The `userId` prop is deprecated and will be removed in a future version.\n * Please pass the `user` prop instead containing an `id` value.\n * example:\n * ```ts\n * <KnockProvider user={{ id: \"user_123\" }}></KnockProvider>\n * ```\n */\n userId?: never;\n }\n);\n\nexport const KnockProvider: React.FC<PropsWithChildren<KnockProviderProps>> = ({\n apiKey,\n host,\n logLevel,\n userToken,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n children,\n i18n,\n identificationStrategy,\n ...props\n}) => {\n const userIdOrUserWithProperties = props?.user || props?.userId;\n\n // We memoize the options here so that we don't create a new object on every re-render\n const authenticateOptions = React.useMemo(\n () => ({\n host,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n logLevel,\n identificationStrategy,\n }),\n [\n host,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n logLevel,\n identificationStrategy,\n ],\n );\n\n const knock = useAuthenticatedKnockClient(\n apiKey ?? \"\",\n userIdOrUserWithProperties,\n userToken,\n authenticateOptions,\n );\n\n return (\n <KnockContext.Provider value={{ knock }}>\n <KnockI18nProvider i18n={i18n}>{children}</KnockI18nProvider>\n </KnockContext.Provider>\n );\n};\n\nexport const useKnockClient = (): Knock => {\n const context = React.useContext(KnockContext);\n if (!context) {\n throw new Error(\"useKnockClient must be used within a KnockProvider\");\n }\n return context.knock;\n};\n"],"names":["KnockContext","React","createContext","KnockProvider","apiKey","host","logLevel","userToken","onUserTokenExpiring","timeBeforeExpirationInMs","children","i18n","identificationStrategy","props","userIdOrUserWithProperties","user","userId","authenticateOptions","useMemo","knock","useAuthenticatedKnockClient","KnockI18nProvider","useKnockClient","context","useContext","Error"],"mappings":";;;;AAeA,MAAMA,IAAeC,EAAMC,cAAyC,IAAI,
|
|
1
|
+
{"version":3,"file":"KnockProvider.mjs","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"sourcesContent":["import Knock, {\n AuthenticateOptions,\n LogLevel,\n UserWithProperties,\n} from \"@knocklabs/client\";\nimport * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\n\nimport { I18nContent, KnockI18nProvider } from \"../../i18n\";\nimport { useAuthenticatedKnockClient } from \"../hooks\";\n\nexport interface KnockProviderState {\n knock: Knock;\n}\n\nconst KnockContext = React.createContext<KnockProviderState | null>(null);\n\nexport type KnockProviderProps = {\n // Knock client props\n apiKey: string | undefined;\n host?: string;\n userToken?: Knock[\"userToken\"];\n onUserTokenExpiring?: AuthenticateOptions[\"onUserTokenExpiring\"];\n timeBeforeExpirationInMs?: AuthenticateOptions[\"timeBeforeExpirationInMs\"];\n // i18n translations\n i18n?: I18nContent;\n logLevel?: LogLevel;\n branch?: string;\n} & (\n | {\n /**\n * @deprecated The `userId` prop is deprecated and will be removed in a future version.\n * Please pass the `user` prop instead containing an `id` value.\n * example:\n * ```ts\n * <KnockProvider user={{ id: \"user_123\" }}></KnockProvider>\n * ```\n */\n userId: Knock[\"userId\"];\n user?: never;\n identificationStrategy?: never;\n }\n | {\n user: UserWithProperties;\n identificationStrategy?: AuthenticateOptions[\"identificationStrategy\"];\n /**\n * @deprecated The `userId` prop is deprecated and will be removed in a future version.\n * Please pass the `user` prop instead containing an `id` value.\n * example:\n * ```ts\n * <KnockProvider user={{ id: \"user_123\" }}></KnockProvider>\n * ```\n */\n userId?: never;\n }\n);\n\nexport const KnockProvider: React.FC<PropsWithChildren<KnockProviderProps>> = ({\n apiKey,\n host,\n logLevel,\n userToken,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n children,\n i18n,\n identificationStrategy,\n branch,\n ...props\n}) => {\n const userIdOrUserWithProperties = props?.user || props?.userId;\n\n // We memoize the options here so that we don't create a new object on every re-render\n const authenticateOptions = React.useMemo(\n () => ({\n host,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n logLevel,\n identificationStrategy,\n branch,\n }),\n [\n host,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n logLevel,\n identificationStrategy,\n branch,\n ],\n );\n\n const knock = useAuthenticatedKnockClient(\n apiKey ?? \"\",\n userIdOrUserWithProperties,\n userToken,\n authenticateOptions,\n );\n\n return (\n <KnockContext.Provider value={{ knock }}>\n <KnockI18nProvider i18n={i18n}>{children}</KnockI18nProvider>\n </KnockContext.Provider>\n );\n};\n\nexport const useKnockClient = (): Knock => {\n const context = React.useContext(KnockContext);\n if (!context) {\n throw new Error(\"useKnockClient must be used within a KnockProvider\");\n }\n return context.knock;\n};\n"],"names":["KnockContext","React","createContext","KnockProvider","apiKey","host","logLevel","userToken","onUserTokenExpiring","timeBeforeExpirationInMs","children","i18n","identificationStrategy","branch","props","userIdOrUserWithProperties","user","userId","authenticateOptions","useMemo","knock","useAuthenticatedKnockClient","KnockI18nProvider","useKnockClient","context","useContext","Error"],"mappings":";;;;AAeA,MAAMA,IAAeC,EAAMC,cAAyC,IAAI,GA0C3DC,IAAiEA,CAAC;AAAA,EAC7EC,QAAAA;AAAAA,EACAC,MAAAA;AAAAA,EACAC,UAAAA;AAAAA,EACAC,WAAAA;AAAAA,EACAC,qBAAAA;AAAAA,EACAC,0BAAAA;AAAAA,EACAC,UAAAA;AAAAA,EACAC,MAAAA;AAAAA,EACAC,wBAAAA;AAAAA,EACAC,QAAAA;AAAAA,EACA,GAAGC;AACL,MAAM;AACEC,QAAAA,KAA6BD,KAAAA,gBAAAA,EAAOE,UAAQF,KAAAA,gBAAAA,EAAOG,SAGnDC,IAAsBjB,EAAMkB,QAChC,OAAO;AAAA,IACLd,MAAAA;AAAAA,IACAG,qBAAAA;AAAAA,IACAC,0BAAAA;AAAAA,IACAH,UAAAA;AAAAA,IACAM,wBAAAA;AAAAA,IACAC,QAAAA;AAAAA,EAAAA,IAEF,CACER,GACAG,GACAC,GACAH,GACAM,GACAC,CAAM,CAEV,GAEMO,IAAQC,EACZjB,KAAU,IACVW,GACAR,GACAW,CACF;AAEA,SACG,gBAAAjB,EAAA,cAAAD,EAAa,UAAb,EAAsB,OAAO;AAAA,IAAEoB,OAAAA;AAAAA,EAAAA,EAC9B,GAAA,gBAAAnB,EAAA,cAACqB,GAAkB,EAAA,MAAAX,EAAA,GAAaD,CAAS,CAC3C;AAEJ,GAEaa,IAAiBA,MAAa;AACnCC,QAAAA,IAAUvB,EAAMwB,WAAWzB,CAAY;AAC7C,MAAI,CAACwB;AACG,UAAA,IAAIE,MAAM,oDAAoD;AAEtE,SAAOF,EAAQJ;AACjB;"}
|
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
import
|
|
1
|
+
import l from "@knocklabs/client";
|
|
2
2
|
import o from "react";
|
|
3
3
|
import "../context/KnockProvider.mjs";
|
|
4
4
|
import m from "./useStableOptions.mjs";
|
|
5
5
|
import "date-fns";
|
|
6
|
-
function d(c,
|
|
7
|
-
c.authenticate(
|
|
6
|
+
function d(c, a, n, e = {}) {
|
|
7
|
+
c.authenticate(a, n, {
|
|
8
8
|
onUserTokenExpiring: e == null ? void 0 : e.onUserTokenExpiring,
|
|
9
9
|
timeBeforeExpirationInMs: e == null ? void 0 : e.timeBeforeExpirationInMs,
|
|
10
10
|
identificationStrategy: e == null ? void 0 : e.identificationStrategy
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
|
-
function v(c,
|
|
14
|
-
const f = o.useRef(void 0), i = m(e), t = m(
|
|
13
|
+
function v(c, a, n, e = {}) {
|
|
14
|
+
const f = o.useRef(void 0), i = m(e), t = m(a);
|
|
15
15
|
return o.useMemo(() => {
|
|
16
|
-
const
|
|
17
|
-
if (r && r.isAuthenticated() && (r.userId !==
|
|
16
|
+
const h = typeof t == "string" ? t : t == null ? void 0 : t.id, r = f.current;
|
|
17
|
+
if (r && r.isAuthenticated() && (r.userId !== h || r.userToken !== n))
|
|
18
18
|
return d(r, t, n, i), r;
|
|
19
19
|
r && r.teardown();
|
|
20
|
-
const
|
|
20
|
+
const u = new l(c, {
|
|
21
21
|
host: i.host,
|
|
22
|
-
logLevel: i.logLevel
|
|
22
|
+
logLevel: i.logLevel,
|
|
23
|
+
branch: i.branch
|
|
23
24
|
});
|
|
24
|
-
return d(
|
|
25
|
+
return d(u, t, n, i), f.current = u, u;
|
|
25
26
|
}, [c, t, n, i]);
|
|
26
27
|
}
|
|
27
28
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAuthenticatedKnockClient.mjs","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"sourcesContent":["import Knock, {\n AuthenticateOptions,\n KnockOptions,\n UserId,\n UserIdOrUserWithProperties,\n} from \"@knocklabs/client\";\nimport React from \"react\";\n\nimport { useStableOptions } from \"../../core\";\n\nfunction authenticateWithOptions(\n knock: Knock,\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options: AuthenticateOptions = {},\n) {\n knock.authenticate(userIdOrUserWithProperties, userToken, {\n onUserTokenExpiring: options?.onUserTokenExpiring,\n timeBeforeExpirationInMs: options?.timeBeforeExpirationInMs,\n identificationStrategy: options?.identificationStrategy,\n });\n}\n\nexport type AuthenticatedKnockClientOptions = KnockOptions &\n AuthenticateOptions;\n\n/**\n * @deprecated Passing `userId` as a `string` is deprecated and will be removed in a future version.\n * Please pass a `user` object instead containing an `id` value.\n * example:\n * ```ts\n * useAuthenticatedKnockClient(\"pk_test_12345\", { id: \"user_123\" });\n * ```\n */\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userIdOrUserWithProperties: UserId,\n userToken?: Knock[\"userToken\"],\n options?: AuthenticatedKnockClientOptions,\n): Knock;\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options?: AuthenticatedKnockClientOptions,\n): Knock;\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options: AuthenticatedKnockClientOptions = {},\n) {\n const knockRef = React.useRef<Knock | undefined>(undefined);\n\n const stableOptions = useStableOptions(options);\n const stableUserIdOrObject = useStableOptions(userIdOrUserWithProperties);\n\n return React.useMemo(() => {\n const userId =\n typeof stableUserIdOrObject === \"string\"\n ? stableUserIdOrObject\n : stableUserIdOrObject?.id;\n\n const currentKnock = knockRef.current;\n\n // If the userId and the userToken changes then just reauth\n if (\n currentKnock &&\n currentKnock.isAuthenticated() &&\n (currentKnock.userId !== userId || currentKnock.userToken !== userToken)\n ) {\n authenticateWithOptions(\n currentKnock,\n stableUserIdOrObject,\n userToken,\n stableOptions,\n );\n return currentKnock;\n }\n\n if (currentKnock) {\n currentKnock.teardown();\n }\n\n // Otherwise instantiate a new Knock client\n const knock = new Knock(apiKey, {\n host: stableOptions.host,\n logLevel: stableOptions.logLevel,\n });\n\n authenticateWithOptions(\n knock,\n stableUserIdOrObject,\n userToken,\n stableOptions,\n );\n knockRef.current = knock;\n\n return knock;\n }, [apiKey, stableUserIdOrObject, userToken, stableOptions]);\n}\n\nexport default useAuthenticatedKnockClient;\n"],"names":["authenticateWithOptions","knock","userIdOrUserWithProperties","userToken","options","authenticate","onUserTokenExpiring","timeBeforeExpirationInMs","identificationStrategy","useAuthenticatedKnockClient","apiKey","knockRef","React","useRef","undefined","stableOptions","useStableOptions","stableUserIdOrObject","useMemo","userId","id","currentKnock","current","isAuthenticated","teardown","Knock","host","logLevel"],"mappings":";;;;;AAUA,SAASA,EACPC,GACAC,GACAC,GACAC,IAA+B,CAAA,GAC/B;AACMC,EAAAA,EAAAA,aAAaH,GAA4BC,GAAW;AAAA,IACxDG,qBAAqBF,KAAAA,gBAAAA,EAASE;AAAAA,IAC9BC,0BAA0BH,KAAAA,gBAAAA,EAASG;AAAAA,IACnCC,wBAAwBJ,KAAAA,gBAAAA,EAASI;AAAAA,EAAAA,CAClC;AACH;AAyBA,SAASC,EACPC,GACAR,GACAC,GACAC,IAA2C,CAAA,GAC3C;AACMO,QAAAA,IAAWC,EAAMC,OAA0BC,MAAS,GAEpDC,IAAgBC,EAAiBZ,CAAO,GACxCa,IAAuBD,EAAiBd,CAA0B;AAEjEU,SAAAA,EAAMM,QAAQ,MAAM;AACzB,UAAMC,IACJ,OAAOF,KAAyB,WAC5BA,IACAA,KAAAA,gBAAAA,EAAsBG,IAEtBC,IAAeV,EAASW;AAI5BD,QAAAA,KACAA,EAAaE,gBAAgB,MAC5BF,EAAaF,WAAWA,KAAUE,EAAalB,cAAcA;AAG5DkB,aAAAA,EAAAA,GACAJ,GACAd,GACAY,CACF,GACOM;AAGT,IAAIA,KACFA,EAAaG,SAAS;AAIlBvB,UAAAA,IAAQ,IAAIwB,EAAMf,GAAQ;AAAA,MAC9BgB,MAAMX,EAAcW;AAAAA,MACpBC,UAAUZ,EAAcY;AAAAA,IAAAA,
|
|
1
|
+
{"version":3,"file":"useAuthenticatedKnockClient.mjs","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"sourcesContent":["import Knock, {\n AuthenticateOptions,\n KnockOptions,\n UserId,\n UserIdOrUserWithProperties,\n} from \"@knocklabs/client\";\nimport React from \"react\";\n\nimport { useStableOptions } from \"../../core\";\n\nfunction authenticateWithOptions(\n knock: Knock,\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options: AuthenticateOptions = {},\n) {\n knock.authenticate(userIdOrUserWithProperties, userToken, {\n onUserTokenExpiring: options?.onUserTokenExpiring,\n timeBeforeExpirationInMs: options?.timeBeforeExpirationInMs,\n identificationStrategy: options?.identificationStrategy,\n });\n}\n\nexport type AuthenticatedKnockClientOptions = KnockOptions &\n AuthenticateOptions;\n\n/**\n * @deprecated Passing `userId` as a `string` is deprecated and will be removed in a future version.\n * Please pass a `user` object instead containing an `id` value.\n * example:\n * ```ts\n * useAuthenticatedKnockClient(\"pk_test_12345\", { id: \"user_123\" });\n * ```\n */\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userIdOrUserWithProperties: UserId,\n userToken?: Knock[\"userToken\"],\n options?: AuthenticatedKnockClientOptions,\n): Knock;\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options?: AuthenticatedKnockClientOptions,\n): Knock;\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options: AuthenticatedKnockClientOptions = {},\n) {\n const knockRef = React.useRef<Knock | undefined>(undefined);\n\n const stableOptions = useStableOptions(options);\n const stableUserIdOrObject = useStableOptions(userIdOrUserWithProperties);\n\n return React.useMemo(() => {\n const userId =\n typeof stableUserIdOrObject === \"string\"\n ? stableUserIdOrObject\n : stableUserIdOrObject?.id;\n\n const currentKnock = knockRef.current;\n\n // If the userId and the userToken changes then just reauth\n if (\n currentKnock &&\n currentKnock.isAuthenticated() &&\n (currentKnock.userId !== userId || currentKnock.userToken !== userToken)\n ) {\n authenticateWithOptions(\n currentKnock,\n stableUserIdOrObject,\n userToken,\n stableOptions,\n );\n return currentKnock;\n }\n\n if (currentKnock) {\n currentKnock.teardown();\n }\n\n // Otherwise instantiate a new Knock client\n const knock = new Knock(apiKey, {\n host: stableOptions.host,\n logLevel: stableOptions.logLevel,\n branch: stableOptions.branch,\n });\n\n authenticateWithOptions(\n knock,\n stableUserIdOrObject,\n userToken,\n stableOptions,\n );\n knockRef.current = knock;\n\n return knock;\n }, [apiKey, stableUserIdOrObject, userToken, stableOptions]);\n}\n\nexport default useAuthenticatedKnockClient;\n"],"names":["authenticateWithOptions","knock","userIdOrUserWithProperties","userToken","options","authenticate","onUserTokenExpiring","timeBeforeExpirationInMs","identificationStrategy","useAuthenticatedKnockClient","apiKey","knockRef","React","useRef","undefined","stableOptions","useStableOptions","stableUserIdOrObject","useMemo","userId","id","currentKnock","current","isAuthenticated","teardown","Knock","host","logLevel","branch"],"mappings":";;;;;AAUA,SAASA,EACPC,GACAC,GACAC,GACAC,IAA+B,CAAA,GAC/B;AACMC,EAAAA,EAAAA,aAAaH,GAA4BC,GAAW;AAAA,IACxDG,qBAAqBF,KAAAA,gBAAAA,EAASE;AAAAA,IAC9BC,0BAA0BH,KAAAA,gBAAAA,EAASG;AAAAA,IACnCC,wBAAwBJ,KAAAA,gBAAAA,EAASI;AAAAA,EAAAA,CAClC;AACH;AAyBA,SAASC,EACPC,GACAR,GACAC,GACAC,IAA2C,CAAA,GAC3C;AACMO,QAAAA,IAAWC,EAAMC,OAA0BC,MAAS,GAEpDC,IAAgBC,EAAiBZ,CAAO,GACxCa,IAAuBD,EAAiBd,CAA0B;AAEjEU,SAAAA,EAAMM,QAAQ,MAAM;AACzB,UAAMC,IACJ,OAAOF,KAAyB,WAC5BA,IACAA,KAAAA,gBAAAA,EAAsBG,IAEtBC,IAAeV,EAASW;AAI5BD,QAAAA,KACAA,EAAaE,gBAAgB,MAC5BF,EAAaF,WAAWA,KAAUE,EAAalB,cAAcA;AAG5DkB,aAAAA,EAAAA,GACAJ,GACAd,GACAY,CACF,GACOM;AAGT,IAAIA,KACFA,EAAaG,SAAS;AAIlBvB,UAAAA,IAAQ,IAAIwB,EAAMf,GAAQ;AAAA,MAC9BgB,MAAMX,EAAcW;AAAAA,MACpBC,UAAUZ,EAAcY;AAAAA,MACxBC,QAAQb,EAAca;AAAAA,IAAAA,CACvB;AAGC3B,WAAAA,EAAAA,GACAgB,GACAd,GACAY,CACF,GACAJ,EAASW,UAAUrB,GAEZA;AAAAA,KACN,CAACS,GAAQO,GAAsBd,GAAWY,CAAa,CAAC;AAC7D;"}
|
|
@@ -7,41 +7,42 @@ import "fast-deep-equal";
|
|
|
7
7
|
import "date-fns";
|
|
8
8
|
import "swr/infinite";
|
|
9
9
|
import "swr";
|
|
10
|
-
const
|
|
10
|
+
const h = "https://login.microsoftonline.com/organizations/adminconsent", p = "/providers/ms-teams/authenticate";
|
|
11
11
|
function S(r, c) {
|
|
12
12
|
const e = d(), {
|
|
13
13
|
setConnectionStatus: t,
|
|
14
|
-
knockMsTeamsChannelId:
|
|
15
|
-
tenantId:
|
|
16
|
-
setActionLabel:
|
|
17
|
-
} = T(),
|
|
14
|
+
knockMsTeamsChannelId: n,
|
|
15
|
+
tenantId: o,
|
|
16
|
+
setActionLabel: a
|
|
17
|
+
} = T(), i = _(() => e.host + p, [e.host]), u = m(() => {
|
|
18
18
|
const s = {
|
|
19
19
|
state: JSON.stringify({
|
|
20
20
|
redirect_url: c,
|
|
21
21
|
ms_teams_tenant_object: {
|
|
22
|
-
object_id:
|
|
22
|
+
object_id: o,
|
|
23
23
|
collection: k
|
|
24
24
|
},
|
|
25
|
-
channel_id:
|
|
25
|
+
channel_id: n,
|
|
26
26
|
public_key: e.apiKey,
|
|
27
|
-
user_token: e.userToken
|
|
27
|
+
user_token: e.userToken,
|
|
28
|
+
branch_slug: e.branch
|
|
28
29
|
}),
|
|
29
30
|
client_id: r,
|
|
30
|
-
redirect_uri:
|
|
31
|
+
redirect_uri: i
|
|
31
32
|
};
|
|
32
|
-
return `${
|
|
33
|
-
}, [c,
|
|
34
|
-
|
|
33
|
+
return `${h}?${new URLSearchParams(s)}`;
|
|
34
|
+
}, [c, o, n, e.apiKey, e.userToken, e.branch, r, i]), l = m(async () => {
|
|
35
|
+
a(null), t("disconnecting");
|
|
35
36
|
try {
|
|
36
37
|
const s = await e.msTeams.revokeAccessToken({
|
|
37
|
-
tenant:
|
|
38
|
-
knockChannelId:
|
|
38
|
+
tenant: o,
|
|
39
|
+
knockChannelId: n
|
|
39
40
|
});
|
|
40
41
|
t(s === "ok" ? "disconnected" : "error");
|
|
41
42
|
} catch {
|
|
42
43
|
t("error");
|
|
43
44
|
}
|
|
44
|
-
}, [t, e.msTeams,
|
|
45
|
+
}, [t, e.msTeams, o, n, a]);
|
|
45
46
|
return {
|
|
46
47
|
buildMsTeamsAuthUrl: u,
|
|
47
48
|
disconnectFromMsTeams: l
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMsTeamsAuth.mjs","sources":["../../../../../src/modules/ms-teams/hooks/useMsTeamsAuth.ts"],"sourcesContent":["import { useKnockMsTeamsClient } from \"..\";\nimport { TENANT_OBJECT_COLLECTION } from \"@knocklabs/client\";\nimport { useCallback, useMemo } from \"react\";\n\nimport { useKnockClient } from \"../../core\";\n\nconst MS_TEAMS_ADMINCONSENT_URL =\n \"https://login.microsoftonline.com/organizations/adminconsent\";\n\nconst AUTH_REDIRECT_PATH = \"/providers/ms-teams/authenticate\";\n\ninterface UseMsTeamsAuthOutput {\n buildMsTeamsAuthUrl: () => string;\n disconnectFromMsTeams: () => void;\n}\n\nfunction useMsTeamsAuth(\n graphApiClientId: string,\n redirectUrl?: string,\n): UseMsTeamsAuthOutput {\n const knock = useKnockClient();\n const {\n setConnectionStatus,\n knockMsTeamsChannelId,\n tenantId,\n setActionLabel,\n } = useKnockMsTeamsClient();\n\n const authRedirectUri = useMemo(\n () => knock.host + AUTH_REDIRECT_PATH,\n [knock.host],\n );\n\n const buildMsTeamsAuthUrl = useCallback(() => {\n const rawParams = {\n state: JSON.stringify({\n redirect_url: redirectUrl,\n ms_teams_tenant_object: {\n object_id: tenantId,\n collection: TENANT_OBJECT_COLLECTION,\n },\n channel_id: knockMsTeamsChannelId,\n public_key: knock.apiKey,\n user_token: knock.userToken,\n }),\n client_id: graphApiClientId,\n redirect_uri: authRedirectUri,\n };\n return `${MS_TEAMS_ADMINCONSENT_URL}?${new URLSearchParams(rawParams)}`;\n }, [\n redirectUrl,\n tenantId,\n knockMsTeamsChannelId,\n knock.apiKey,\n knock.userToken,\n graphApiClientId,\n authRedirectUri,\n ]);\n\n const disconnectFromMsTeams = useCallback(async () => {\n setActionLabel(null);\n setConnectionStatus(\"disconnecting\");\n try {\n const revokeResult = await knock.msTeams.revokeAccessToken({\n tenant: tenantId,\n knockChannelId: knockMsTeamsChannelId,\n });\n\n setConnectionStatus(revokeResult === \"ok\" ? \"disconnected\" : \"error\");\n } catch (_error) {\n setConnectionStatus(\"error\");\n }\n }, [\n setConnectionStatus,\n knock.msTeams,\n tenantId,\n knockMsTeamsChannelId,\n setActionLabel,\n ]);\n\n return { buildMsTeamsAuthUrl, disconnectFromMsTeams };\n}\n\nexport default useMsTeamsAuth;\n"],"names":["MS_TEAMS_ADMINCONSENT_URL","AUTH_REDIRECT_PATH","useMsTeamsAuth","graphApiClientId","redirectUrl","knock","useKnockClient","setConnectionStatus","knockMsTeamsChannelId","tenantId","setActionLabel","useKnockMsTeamsClient","authRedirectUri","useMemo","host","buildMsTeamsAuthUrl","useCallback","rawParams","state","JSON","stringify","redirect_url","ms_teams_tenant_object","object_id","collection","TENANT_OBJECT_COLLECTION","channel_id","public_key","apiKey","user_token","userToken","client_id","redirect_uri","URLSearchParams","disconnectFromMsTeams","revokeResult","msTeams","revokeAccessToken","tenant","knockChannelId"],"mappings":";;;;;;;;;AAMA,MAAMA,IACJ,gEAEIC,IAAqB;AAO3B,SAASC,EACPC,GACAC,GACsB;AACtB,QAAMC,IAAQC,EAAe,GACvB;AAAA,IACJC,qBAAAA;AAAAA,IACAC,uBAAAA;AAAAA,IACAC,UAAAA;AAAAA,IACAC,gBAAAA;AAAAA,MACEC,EAAsB,GAEpBC,IAAkBC,EACtB,MAAMR,EAAMS,OAAOb,GACnB,CAACI,EAAMS,IAAI,CACb,GAEMC,IAAsBC,EAAY,MAAM;AAC5C,UAAMC,IAAY;AAAA,MAChBC,OAAOC,KAAKC,UAAU;AAAA,QACpBC,cAAcjB;AAAAA,QACdkB,wBAAwB;AAAA,UACtBC,WAAWd;AAAAA,UACXe,YAAYC;AAAAA,QACd;AAAA,QACAC,YAAYlB;AAAAA,QACZmB,YAAYtB,EAAMuB;AAAAA,QAClBC,YAAYxB,EAAMyB;AAAAA,MAAAA,
|
|
1
|
+
{"version":3,"file":"useMsTeamsAuth.mjs","sources":["../../../../../src/modules/ms-teams/hooks/useMsTeamsAuth.ts"],"sourcesContent":["import { useKnockMsTeamsClient } from \"..\";\nimport { TENANT_OBJECT_COLLECTION } from \"@knocklabs/client\";\nimport { useCallback, useMemo } from \"react\";\n\nimport { useKnockClient } from \"../../core\";\n\nconst MS_TEAMS_ADMINCONSENT_URL =\n \"https://login.microsoftonline.com/organizations/adminconsent\";\n\nconst AUTH_REDIRECT_PATH = \"/providers/ms-teams/authenticate\";\n\ninterface UseMsTeamsAuthOutput {\n buildMsTeamsAuthUrl: () => string;\n disconnectFromMsTeams: () => void;\n}\n\nfunction useMsTeamsAuth(\n graphApiClientId: string,\n redirectUrl?: string,\n): UseMsTeamsAuthOutput {\n const knock = useKnockClient();\n const {\n setConnectionStatus,\n knockMsTeamsChannelId,\n tenantId,\n setActionLabel,\n } = useKnockMsTeamsClient();\n\n const authRedirectUri = useMemo(\n () => knock.host + AUTH_REDIRECT_PATH,\n [knock.host],\n );\n\n const buildMsTeamsAuthUrl = useCallback(() => {\n const rawParams = {\n state: JSON.stringify({\n redirect_url: redirectUrl,\n ms_teams_tenant_object: {\n object_id: tenantId,\n collection: TENANT_OBJECT_COLLECTION,\n },\n channel_id: knockMsTeamsChannelId,\n public_key: knock.apiKey,\n user_token: knock.userToken,\n branch_slug: knock.branch,\n }),\n client_id: graphApiClientId,\n redirect_uri: authRedirectUri,\n };\n return `${MS_TEAMS_ADMINCONSENT_URL}?${new URLSearchParams(rawParams)}`;\n }, [\n redirectUrl,\n tenantId,\n knockMsTeamsChannelId,\n knock.apiKey,\n knock.userToken,\n knock.branch,\n graphApiClientId,\n authRedirectUri,\n ]);\n\n const disconnectFromMsTeams = useCallback(async () => {\n setActionLabel(null);\n setConnectionStatus(\"disconnecting\");\n try {\n const revokeResult = await knock.msTeams.revokeAccessToken({\n tenant: tenantId,\n knockChannelId: knockMsTeamsChannelId,\n });\n\n setConnectionStatus(revokeResult === \"ok\" ? \"disconnected\" : \"error\");\n } catch (_error) {\n setConnectionStatus(\"error\");\n }\n }, [\n setConnectionStatus,\n knock.msTeams,\n tenantId,\n knockMsTeamsChannelId,\n setActionLabel,\n ]);\n\n return { buildMsTeamsAuthUrl, disconnectFromMsTeams };\n}\n\nexport default useMsTeamsAuth;\n"],"names":["MS_TEAMS_ADMINCONSENT_URL","AUTH_REDIRECT_PATH","useMsTeamsAuth","graphApiClientId","redirectUrl","knock","useKnockClient","setConnectionStatus","knockMsTeamsChannelId","tenantId","setActionLabel","useKnockMsTeamsClient","authRedirectUri","useMemo","host","buildMsTeamsAuthUrl","useCallback","rawParams","state","JSON","stringify","redirect_url","ms_teams_tenant_object","object_id","collection","TENANT_OBJECT_COLLECTION","channel_id","public_key","apiKey","user_token","userToken","branch_slug","branch","client_id","redirect_uri","URLSearchParams","disconnectFromMsTeams","revokeResult","msTeams","revokeAccessToken","tenant","knockChannelId"],"mappings":";;;;;;;;;AAMA,MAAMA,IACJ,gEAEIC,IAAqB;AAO3B,SAASC,EACPC,GACAC,GACsB;AACtB,QAAMC,IAAQC,EAAe,GACvB;AAAA,IACJC,qBAAAA;AAAAA,IACAC,uBAAAA;AAAAA,IACAC,UAAAA;AAAAA,IACAC,gBAAAA;AAAAA,MACEC,EAAsB,GAEpBC,IAAkBC,EACtB,MAAMR,EAAMS,OAAOb,GACnB,CAACI,EAAMS,IAAI,CACb,GAEMC,IAAsBC,EAAY,MAAM;AAC5C,UAAMC,IAAY;AAAA,MAChBC,OAAOC,KAAKC,UAAU;AAAA,QACpBC,cAAcjB;AAAAA,QACdkB,wBAAwB;AAAA,UACtBC,WAAWd;AAAAA,UACXe,YAAYC;AAAAA,QACd;AAAA,QACAC,YAAYlB;AAAAA,QACZmB,YAAYtB,EAAMuB;AAAAA,QAClBC,YAAYxB,EAAMyB;AAAAA,QAClBC,aAAa1B,EAAM2B;AAAAA,MAAAA,CACpB;AAAA,MACDC,WAAW9B;AAAAA,MACX+B,cAActB;AAAAA,IAChB;AACA,WAAO,GAAGZ,CAAyB,IAAI,IAAImC,gBAAgBlB,CAAS,CAAC;AAAA,EACpE,GAAA,CACDb,GACAK,GACAD,GACAH,EAAMuB,QACNvB,EAAMyB,WACNzB,EAAM2B,QACN7B,GACAS,CAAe,CAChB,GAEKwB,IAAwBpB,EAAY,YAAY;AACpDN,IAAAA,EAAe,IAAI,GACnBH,EAAoB,eAAe;AAC/B,QAAA;AACF,YAAM8B,IAAe,MAAMhC,EAAMiC,QAAQC,kBAAkB;AAAA,QACzDC,QAAQ/B;AAAAA,QACRgC,gBAAgBjC;AAAAA,MAAAA,CACjB;AAEmB6B,MAAAA,EAAAA,MAAiB,OAAO,iBAAiB,OAAO;AAAA,YACrD;AACf9B,MAAAA,EAAoB,OAAO;AAAA,IAAA;AAAA,EAC7B,GACC,CACDA,GACAF,EAAMiC,SACN7B,GACAD,GACAE,CAAc,CACf;AAEM,SAAA;AAAA,IAAEK,qBAAAA;AAAAA,IAAqBqB,uBAAAA;AAAAA,EAAsB;AACtD;"}
|
|
@@ -2,13 +2,13 @@ import { useKnockSlackClient as S } from "../context/KnockSlackProvider.mjs";
|
|
|
2
2
|
import { useCallback as u } from "react";
|
|
3
3
|
import "../../i18n/context/KnockI18nProvider.mjs";
|
|
4
4
|
import "swr/infinite";
|
|
5
|
-
import { useKnockClient as
|
|
6
|
-
import { TENANT_OBJECT_COLLECTION as
|
|
5
|
+
import { useKnockClient as h } from "../../core/context/KnockProvider.mjs";
|
|
6
|
+
import { TENANT_OBJECT_COLLECTION as _ } from "@knocklabs/client";
|
|
7
7
|
import "fast-deep-equal";
|
|
8
8
|
import "date-fns";
|
|
9
9
|
import "swr";
|
|
10
10
|
const A = "https://slack.com/oauth/v2/authorize", a = ["chat:write", "chat:write.public", "channels:read", "groups:read"];
|
|
11
|
-
function
|
|
11
|
+
function b(e) {
|
|
12
12
|
return e ? Array.isArray(e) ? {
|
|
13
13
|
scopes: a,
|
|
14
14
|
additionalScopes: e
|
|
@@ -20,49 +20,50 @@ function f(e) {
|
|
|
20
20
|
additionalScopes: []
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
-
function
|
|
24
|
-
const
|
|
25
|
-
setConnectionStatus:
|
|
26
|
-
knockSlackChannelId:
|
|
27
|
-
tenantId:
|
|
23
|
+
function g(e, s, k) {
|
|
24
|
+
const c = h(), {
|
|
25
|
+
setConnectionStatus: o,
|
|
26
|
+
knockSlackChannelId: n,
|
|
27
|
+
tenantId: t,
|
|
28
28
|
setActionLabel: i
|
|
29
29
|
} = S(), {
|
|
30
30
|
scopes: d,
|
|
31
31
|
additionalScopes: p
|
|
32
|
-
} =
|
|
33
|
-
i(null),
|
|
32
|
+
} = b(k), l = Array.from(new Set(d.concat(p))), m = u(async () => {
|
|
33
|
+
i(null), o("disconnecting");
|
|
34
34
|
try {
|
|
35
|
-
const r = await
|
|
36
|
-
tenant:
|
|
37
|
-
knockChannelId:
|
|
35
|
+
const r = await c.slack.revokeAccessToken({
|
|
36
|
+
tenant: t,
|
|
37
|
+
knockChannelId: n
|
|
38
38
|
});
|
|
39
|
-
|
|
39
|
+
o(r === "ok" ? "disconnected" : "error");
|
|
40
40
|
} catch {
|
|
41
|
-
|
|
41
|
+
o("error");
|
|
42
42
|
}
|
|
43
|
-
}, [
|
|
43
|
+
}, [o, c.slack, t, n, i]);
|
|
44
44
|
return {
|
|
45
45
|
buildSlackAuthUrl: u(() => {
|
|
46
46
|
const r = {
|
|
47
47
|
state: JSON.stringify({
|
|
48
48
|
redirect_url: s,
|
|
49
49
|
access_token_object: {
|
|
50
|
-
object_id:
|
|
51
|
-
collection:
|
|
50
|
+
object_id: t,
|
|
51
|
+
collection: _
|
|
52
52
|
},
|
|
53
|
-
channel_id:
|
|
54
|
-
public_key:
|
|
55
|
-
user_token:
|
|
53
|
+
channel_id: n,
|
|
54
|
+
public_key: c.apiKey,
|
|
55
|
+
user_token: c.userToken,
|
|
56
|
+
branch_slug: c.branch
|
|
56
57
|
}),
|
|
57
58
|
client_id: e,
|
|
58
59
|
scope: l.join(",")
|
|
59
60
|
};
|
|
60
61
|
return `${A}?${new URLSearchParams(r)}`;
|
|
61
|
-
}, [s,
|
|
62
|
+
}, [s, t, n, c.apiKey, c.userToken, c.branch, e, l]),
|
|
62
63
|
disconnectFromSlack: m
|
|
63
64
|
};
|
|
64
65
|
}
|
|
65
66
|
export {
|
|
66
|
-
|
|
67
|
+
g as default
|
|
67
68
|
};
|
|
68
69
|
//# sourceMappingURL=useSlackAuth.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSlackAuth.mjs","sources":["../../../../../src/modules/slack/hooks/useSlackAuth.ts"],"sourcesContent":["import { useKnockSlackClient } from \"..\";\nimport { TENANT_OBJECT_COLLECTION } from \"@knocklabs/client\";\nimport { useCallback } from \"react\";\n\nimport { useKnockClient } from \"../../core\";\n\nconst SLACK_AUTHORIZE_URL = \"https://slack.com/oauth/v2/authorize\";\nconst DEFAULT_SLACK_SCOPES = [\n \"chat:write\",\n \"chat:write.public\",\n \"channels:read\",\n \"groups:read\",\n];\n\ntype UseSlackAuthOutput = {\n buildSlackAuthUrl: () => string;\n disconnectFromSlack: () => void;\n};\n\ntype UseSlackAuthOptions = {\n // When provided, the default scopes will be overridden with the provided scopes\n scopes?: string[];\n // Additional scopes to add to the default scopes\n additionalScopes?: string[];\n};\n\n// Here we normalize the options to be a single object with scopes and additionalScopes\n// The \"options\" parameter can be an array of scopes, an object with scopes and additionalScopes, or undefined\n// We handle the array case because it was the previous way to pass options so we're being backward compatible\nfunction normalizeOptions(options?: UseSlackAuthOptions | string[]): {\n scopes: string[];\n additionalScopes: string[];\n} {\n if (!options) {\n return { scopes: DEFAULT_SLACK_SCOPES, additionalScopes: [] };\n }\n\n if (Array.isArray(options)) {\n return { scopes: DEFAULT_SLACK_SCOPES, additionalScopes: options };\n }\n\n return {\n scopes: options.scopes ?? DEFAULT_SLACK_SCOPES,\n additionalScopes: options.additionalScopes ?? [],\n };\n}\n\nfunction useSlackAuth(\n slackClientId: string,\n redirectUrl?: string,\n options?: UseSlackAuthOptions | string[],\n): UseSlackAuthOutput {\n const knock = useKnockClient();\n const { setConnectionStatus, knockSlackChannelId, tenantId, setActionLabel } =\n useKnockSlackClient();\n\n const { scopes, additionalScopes } = normalizeOptions(options);\n const combinedScopes = Array.from(new Set(scopes.concat(additionalScopes)));\n\n const disconnectFromSlack = useCallback(async () => {\n setActionLabel(null);\n setConnectionStatus(\"disconnecting\");\n try {\n const revoke = await knock.slack.revokeAccessToken({\n tenant: tenantId,\n knockChannelId: knockSlackChannelId,\n });\n\n if (revoke === \"ok\") {\n setConnectionStatus(\"disconnected\");\n } else {\n setConnectionStatus(\"error\");\n }\n } catch (_error) {\n setConnectionStatus(\"error\");\n }\n }, [\n setConnectionStatus,\n knock.slack,\n tenantId,\n knockSlackChannelId,\n setActionLabel,\n ]);\n\n const buildSlackAuthUrl = useCallback(() => {\n const rawParams = {\n state: JSON.stringify({\n redirect_url: redirectUrl,\n access_token_object: {\n object_id: tenantId,\n collection: TENANT_OBJECT_COLLECTION,\n },\n channel_id: knockSlackChannelId,\n public_key: knock.apiKey,\n user_token: knock.userToken,\n }),\n client_id: slackClientId,\n scope: combinedScopes.join(\",\"),\n };\n return `${SLACK_AUTHORIZE_URL}?${new URLSearchParams(rawParams)}`;\n }, [\n redirectUrl,\n tenantId,\n knockSlackChannelId,\n knock.apiKey,\n knock.userToken,\n slackClientId,\n combinedScopes,\n ]);\n\n return {\n buildSlackAuthUrl,\n disconnectFromSlack,\n };\n}\n\nexport default useSlackAuth;\n"],"names":["SLACK_AUTHORIZE_URL","DEFAULT_SLACK_SCOPES","normalizeOptions","options","Array","isArray","scopes","additionalScopes","useSlackAuth","slackClientId","redirectUrl","knock","useKnockClient","setConnectionStatus","knockSlackChannelId","tenantId","setActionLabel","useKnockSlackClient","combinedScopes","from","Set","concat","disconnectFromSlack","useCallback","revoke","slack","revokeAccessToken","tenant","knockChannelId","buildSlackAuthUrl","rawParams","state","JSON","stringify","redirect_url","access_token_object","object_id","collection","TENANT_OBJECT_COLLECTION","channel_id","public_key","apiKey","user_token","userToken","client_id","scope","join","URLSearchParams"],"mappings":";;;;;;;;;AAMA,MAAMA,IAAsB,wCACtBC,IAAuB,CAC3B,cACA,qBACA,iBACA,aAAa;AAkBf,SAASC,EAAiBC,GAGxB;AACA,SAAKA,IAIDC,MAAMC,QAAQF,CAAO,IAChB;AAAA,IAAEG,QAAQL;AAAAA,IAAsBM,kBAAkBJ;AAAAA,EAAQ,IAG5D;AAAA,IACLG,QAAQH,EAAQG,UAAUL;AAAAA,IAC1BM,kBAAkBJ,EAAQI,oBAAoB,CAAA;AAAA,EAChD,IAVS;AAAA,IAAED,QAAQL;AAAAA,IAAsBM,kBAAkB,CAAA;AAAA,EAAG;AAWhE;AAEA,SAASC,EACPC,GACAC,GACAP,GACoB;AACpB,QAAMQ,IAAQC,EAAe,GACvB;AAAA,IAAEC,qBAAAA;AAAAA,IAAqBC,qBAAAA;AAAAA,IAAqBC,UAAAA;AAAAA,IAAUC,gBAAAA;AAAAA,MAC1DC,EAAoB,GAEhB;AAAA,IAAEX,QAAAA;AAAAA,IAAQC,kBAAAA;AAAAA,EAAAA,IAAqBL,EAAiBC,CAAO,GACvDe,IAAiBd,MAAMe,KAAK,IAAIC,IAAId,EAAOe,OAAOd,CAAgB,CAAC,CAAC,GAEpEe,IAAsBC,EAAY,YAAY;AAClDP,IAAAA,EAAe,IAAI,GACnBH,EAAoB,eAAe;AAC/B,QAAA;AACF,YAAMW,IAAS,MAAMb,EAAMc,MAAMC,kBAAkB;AAAA,QACjDC,QAAQZ;AAAAA,QACRa,gBAAgBd;AAAAA,MAAAA,CACjB;AAED,MACED,EADEW,MAAW,OACO,iBAEA,OAFc;AAAA,YAIrB;AACfX,MAAAA,EAAoB,OAAO;AAAA,IAAA;AAAA,EAC7B,GACC,CACDA,GACAF,EAAMc,OACNV,GACAD,GACAE,CAAc,CACf;
|
|
1
|
+
{"version":3,"file":"useSlackAuth.mjs","sources":["../../../../../src/modules/slack/hooks/useSlackAuth.ts"],"sourcesContent":["import { useKnockSlackClient } from \"..\";\nimport { TENANT_OBJECT_COLLECTION } from \"@knocklabs/client\";\nimport { useCallback } from \"react\";\n\nimport { useKnockClient } from \"../../core\";\n\nconst SLACK_AUTHORIZE_URL = \"https://slack.com/oauth/v2/authorize\";\nconst DEFAULT_SLACK_SCOPES = [\n \"chat:write\",\n \"chat:write.public\",\n \"channels:read\",\n \"groups:read\",\n];\n\ntype UseSlackAuthOutput = {\n buildSlackAuthUrl: () => string;\n disconnectFromSlack: () => void;\n};\n\ntype UseSlackAuthOptions = {\n // When provided, the default scopes will be overridden with the provided scopes\n scopes?: string[];\n // Additional scopes to add to the default scopes\n additionalScopes?: string[];\n};\n\n// Here we normalize the options to be a single object with scopes and additionalScopes\n// The \"options\" parameter can be an array of scopes, an object with scopes and additionalScopes, or undefined\n// We handle the array case because it was the previous way to pass options so we're being backward compatible\nfunction normalizeOptions(options?: UseSlackAuthOptions | string[]): {\n scopes: string[];\n additionalScopes: string[];\n} {\n if (!options) {\n return { scopes: DEFAULT_SLACK_SCOPES, additionalScopes: [] };\n }\n\n if (Array.isArray(options)) {\n return { scopes: DEFAULT_SLACK_SCOPES, additionalScopes: options };\n }\n\n return {\n scopes: options.scopes ?? DEFAULT_SLACK_SCOPES,\n additionalScopes: options.additionalScopes ?? [],\n };\n}\n\nfunction useSlackAuth(\n slackClientId: string,\n redirectUrl?: string,\n options?: UseSlackAuthOptions | string[],\n): UseSlackAuthOutput {\n const knock = useKnockClient();\n const { setConnectionStatus, knockSlackChannelId, tenantId, setActionLabel } =\n useKnockSlackClient();\n\n const { scopes, additionalScopes } = normalizeOptions(options);\n const combinedScopes = Array.from(new Set(scopes.concat(additionalScopes)));\n\n const disconnectFromSlack = useCallback(async () => {\n setActionLabel(null);\n setConnectionStatus(\"disconnecting\");\n try {\n const revoke = await knock.slack.revokeAccessToken({\n tenant: tenantId,\n knockChannelId: knockSlackChannelId,\n });\n\n if (revoke === \"ok\") {\n setConnectionStatus(\"disconnected\");\n } else {\n setConnectionStatus(\"error\");\n }\n } catch (_error) {\n setConnectionStatus(\"error\");\n }\n }, [\n setConnectionStatus,\n knock.slack,\n tenantId,\n knockSlackChannelId,\n setActionLabel,\n ]);\n\n const buildSlackAuthUrl = useCallback(() => {\n const rawParams = {\n state: JSON.stringify({\n redirect_url: redirectUrl,\n access_token_object: {\n object_id: tenantId,\n collection: TENANT_OBJECT_COLLECTION,\n },\n channel_id: knockSlackChannelId,\n public_key: knock.apiKey,\n user_token: knock.userToken,\n branch_slug: knock.branch,\n }),\n client_id: slackClientId,\n scope: combinedScopes.join(\",\"),\n };\n return `${SLACK_AUTHORIZE_URL}?${new URLSearchParams(rawParams)}`;\n }, [\n redirectUrl,\n tenantId,\n knockSlackChannelId,\n knock.apiKey,\n knock.userToken,\n knock.branch,\n slackClientId,\n combinedScopes,\n ]);\n\n return {\n buildSlackAuthUrl,\n disconnectFromSlack,\n };\n}\n\nexport default useSlackAuth;\n"],"names":["SLACK_AUTHORIZE_URL","DEFAULT_SLACK_SCOPES","normalizeOptions","options","Array","isArray","scopes","additionalScopes","useSlackAuth","slackClientId","redirectUrl","knock","useKnockClient","setConnectionStatus","knockSlackChannelId","tenantId","setActionLabel","useKnockSlackClient","combinedScopes","from","Set","concat","disconnectFromSlack","useCallback","revoke","slack","revokeAccessToken","tenant","knockChannelId","buildSlackAuthUrl","rawParams","state","JSON","stringify","redirect_url","access_token_object","object_id","collection","TENANT_OBJECT_COLLECTION","channel_id","public_key","apiKey","user_token","userToken","branch_slug","branch","client_id","scope","join","URLSearchParams"],"mappings":";;;;;;;;;AAMA,MAAMA,IAAsB,wCACtBC,IAAuB,CAC3B,cACA,qBACA,iBACA,aAAa;AAkBf,SAASC,EAAiBC,GAGxB;AACA,SAAKA,IAIDC,MAAMC,QAAQF,CAAO,IAChB;AAAA,IAAEG,QAAQL;AAAAA,IAAsBM,kBAAkBJ;AAAAA,EAAQ,IAG5D;AAAA,IACLG,QAAQH,EAAQG,UAAUL;AAAAA,IAC1BM,kBAAkBJ,EAAQI,oBAAoB,CAAA;AAAA,EAChD,IAVS;AAAA,IAAED,QAAQL;AAAAA,IAAsBM,kBAAkB,CAAA;AAAA,EAAG;AAWhE;AAEA,SAASC,EACPC,GACAC,GACAP,GACoB;AACpB,QAAMQ,IAAQC,EAAe,GACvB;AAAA,IAAEC,qBAAAA;AAAAA,IAAqBC,qBAAAA;AAAAA,IAAqBC,UAAAA;AAAAA,IAAUC,gBAAAA;AAAAA,MAC1DC,EAAoB,GAEhB;AAAA,IAAEX,QAAAA;AAAAA,IAAQC,kBAAAA;AAAAA,EAAAA,IAAqBL,EAAiBC,CAAO,GACvDe,IAAiBd,MAAMe,KAAK,IAAIC,IAAId,EAAOe,OAAOd,CAAgB,CAAC,CAAC,GAEpEe,IAAsBC,EAAY,YAAY;AAClDP,IAAAA,EAAe,IAAI,GACnBH,EAAoB,eAAe;AAC/B,QAAA;AACF,YAAMW,IAAS,MAAMb,EAAMc,MAAMC,kBAAkB;AAAA,QACjDC,QAAQZ;AAAAA,QACRa,gBAAgBd;AAAAA,MAAAA,CACjB;AAED,MACED,EADEW,MAAW,OACO,iBAEA,OAFc;AAAA,YAIrB;AACfX,MAAAA,EAAoB,OAAO;AAAA,IAAA;AAAA,EAC7B,GACC,CACDA,GACAF,EAAMc,OACNV,GACAD,GACAE,CAAc,CACf;AA8BM,SAAA;AAAA,IACLa,mBA7BwBN,EAAY,MAAM;AAC1C,YAAMO,IAAY;AAAA,QAChBC,OAAOC,KAAKC,UAAU;AAAA,UACpBC,cAAcxB;AAAAA,UACdyB,qBAAqB;AAAA,YACnBC,WAAWrB;AAAAA,YACXsB,YAAYC;AAAAA,UACd;AAAA,UACAC,YAAYzB;AAAAA,UACZ0B,YAAY7B,EAAM8B;AAAAA,UAClBC,YAAY/B,EAAMgC;AAAAA,UAClBC,aAAajC,EAAMkC;AAAAA,QAAAA,CACpB;AAAA,QACDC,WAAWrC;AAAAA,QACXsC,OAAO7B,EAAe8B,KAAK,GAAG;AAAA,MAChC;AACA,aAAO,GAAGhD,CAAmB,IAAI,IAAIiD,gBAAgBnB,CAAS,CAAC;AAAA,IAC9D,GAAA,CACDpB,GACAK,GACAD,GACAH,EAAM8B,QACN9B,EAAMgC,WACNhC,EAAMkC,QACNpC,GACAS,CAAc,CACf;AAAA,IAICI,qBAAAA;AAAAA,EACF;AACF;"}
|
|
@@ -13,6 +13,7 @@ export type KnockProviderProps = {
|
|
|
13
13
|
timeBeforeExpirationInMs?: AuthenticateOptions["timeBeforeExpirationInMs"];
|
|
14
14
|
i18n?: I18nContent;
|
|
15
15
|
logLevel?: LogLevel;
|
|
16
|
+
branch?: string;
|
|
16
17
|
} & ({
|
|
17
18
|
/**
|
|
18
19
|
* @deprecated The `userId` prop is deprecated and will be removed in a future version.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KnockProvider.d.ts","sourceRoot":"","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,mBAAmB,EACnB,QAAQ,EACR,kBAAkB,EACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAqB,MAAM,YAAY,CAAC;AAG5D,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,KAAK,CAAC;CACd;AAID,MAAM,MAAM,kBAAkB,GAAG;IAE/B,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IAC/B,mBAAmB,CAAC,EAAE,mBAAmB,CAAC,qBAAqB,CAAC,CAAC;IACjE,wBAAwB,CAAC,EAAE,mBAAmB,CAAC,0BAA0B,CAAC,CAAC;IAE3E,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,QAAQ,CAAC,EAAE,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"KnockProvider.d.ts","sourceRoot":"","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,mBAAmB,EACnB,QAAQ,EACR,kBAAkB,EACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAqB,MAAM,YAAY,CAAC;AAG5D,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,KAAK,CAAC;CACd;AAID,MAAM,MAAM,kBAAkB,GAAG;IAE/B,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IAC/B,mBAAmB,CAAC,EAAE,mBAAmB,CAAC,qBAAqB,CAAC,CAAC;IACjE,wBAAwB,CAAC,EAAE,mBAAmB,CAAC,0BAA0B,CAAC,CAAC;IAE3E,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,CACA;IACE;;;;;;;OAOG;IACH,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;IACxB,IAAI,CAAC,EAAE,KAAK,CAAC;IACb,sBAAsB,CAAC,EAAE,KAAK,CAAC;CAChC,GACD;IACE,IAAI,EAAE,kBAAkB,CAAC;IACzB,sBAAsB,CAAC,EAAE,mBAAmB,CAAC,wBAAwB,CAAC,CAAC;IACvE;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,KAAK,CAAC;CAChB,CACJ,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,CA+CzE,CAAC;AAEF,eAAO,MAAM,cAAc,QAAO,KAMjC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAuthenticatedKnockClient.d.ts","sourceRoot":"","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,mBAAmB,EACnB,YAAY,EACZ,MAAM,EACN,0BAA0B,EAC3B,MAAM,mBAAmB,CAAC;AAkB3B,MAAM,MAAM,+BAA+B,GAAG,YAAY,GACxD,mBAAmB,CAAC;AAEtB;;;;;;;GAOG;AACH,iBAAS,2BAA2B,CAClC,MAAM,EAAE,MAAM,EACd,0BAA0B,EAAE,MAAM,EAClC,SAAS,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,EAC9B,OAAO,CAAC,EAAE,+BAA+B,GACxC,KAAK,CAAC;AACT,iBAAS,2BAA2B,CAClC,MAAM,EAAE,MAAM,EACd,0BAA0B,EAAE,0BAA0B,EACtD,SAAS,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,EAC9B,OAAO,CAAC,EAAE,+BAA+B,GACxC,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"useAuthenticatedKnockClient.d.ts","sourceRoot":"","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,mBAAmB,EACnB,YAAY,EACZ,MAAM,EACN,0BAA0B,EAC3B,MAAM,mBAAmB,CAAC;AAkB3B,MAAM,MAAM,+BAA+B,GAAG,YAAY,GACxD,mBAAmB,CAAC;AAEtB;;;;;;;GAOG;AACH,iBAAS,2BAA2B,CAClC,MAAM,EAAE,MAAM,EACd,0BAA0B,EAAE,MAAM,EAClC,SAAS,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,EAC9B,OAAO,CAAC,EAAE,+BAA+B,GACxC,KAAK,CAAC;AACT,iBAAS,2BAA2B,CAClC,MAAM,EAAE,MAAM,EACd,0BAA0B,EAAE,0BAA0B,EACtD,SAAS,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,EAC9B,OAAO,CAAC,EAAE,+BAA+B,GACxC,KAAK,CAAC;AA0DT,eAAe,2BAA2B,CAAC"}
|
|
@@ -1 +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,gBAAgB,EAAE,MAAM,EACxB,WAAW,CAAC,EAAE,MAAM,GACnB,oBAAoB,
|
|
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,gBAAgB,EAAE,MAAM,EACxB,WAAW,CAAC,EAAE,MAAM,GACnB,oBAAoB,CAgEtB;AAED,eAAe,cAAc,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSlackAuth.d.ts","sourceRoot":"","sources":["../../../../../src/modules/slack/hooks/useSlackAuth.ts"],"names":[],"mappings":"AAcA,KAAK,kBAAkB,GAAG;IACxB,iBAAiB,EAAE,MAAM,MAAM,CAAC;IAChC,mBAAmB,EAAE,MAAM,IAAI,CAAC;CACjC,CAAC;AAEF,KAAK,mBAAmB,GAAG;IAEzB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAElB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B,CAAC;AAuBF,iBAAS,YAAY,CACnB,aAAa,EAAE,MAAM,EACrB,WAAW,CAAC,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE,mBAAmB,GAAG,MAAM,EAAE,GACvC,kBAAkB,
|
|
1
|
+
{"version":3,"file":"useSlackAuth.d.ts","sourceRoot":"","sources":["../../../../../src/modules/slack/hooks/useSlackAuth.ts"],"names":[],"mappings":"AAcA,KAAK,kBAAkB,GAAG;IACxB,iBAAiB,EAAE,MAAM,MAAM,CAAC;IAChC,mBAAmB,EAAE,MAAM,IAAI,CAAC;CACjC,CAAC;AAEF,KAAK,mBAAmB,GAAG;IAEzB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAElB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B,CAAC;AAuBF,iBAAS,YAAY,CACnB,aAAa,EAAE,MAAM,EACrB,WAAW,CAAC,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE,mBAAmB,GAAG,MAAM,EAAE,GACvC,kBAAkB,CAiEpB;AAED,eAAe,YAAY,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.11.
|
|
5
|
+
"version": "0.11.4",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "dist/cjs/index.js",
|
|
8
8
|
"module": "dist/esm/index.mjs",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"react": "^16.11.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@knocklabs/client": "^0.19.
|
|
50
|
+
"@knocklabs/client": "^0.19.4",
|
|
51
51
|
"@tanstack/react-store": "^0.7.3",
|
|
52
52
|
"date-fns": "^4.0.0",
|
|
53
53
|
"fast-deep-equal": "^3.1.3",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@codecov/vite-plugin": "^1.9.1",
|
|
58
|
-
"@testing-library/dom": "^10.4.
|
|
58
|
+
"@testing-library/dom": "^10.4.1",
|
|
59
59
|
"@testing-library/react": "^16.3.0",
|
|
60
60
|
"@types/react": "^19.1.8",
|
|
61
61
|
"@types/react-dom": "^19.1.6",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"eslint": "^8.56.0",
|
|
67
67
|
"eslint-plugin-react-hooks": "^5.2.0",
|
|
68
68
|
"eslint-plugin-react-refresh": "^0.4.14",
|
|
69
|
-
"jsdom": "^27.
|
|
69
|
+
"jsdom": "^27.1.0",
|
|
70
70
|
"react": "^19.0.0",
|
|
71
71
|
"react-dom": "^19.0.0",
|
|
72
72
|
"rimraf": "^6.0.1",
|
|
@@ -25,6 +25,7 @@ export type KnockProviderProps = {
|
|
|
25
25
|
// i18n translations
|
|
26
26
|
i18n?: I18nContent;
|
|
27
27
|
logLevel?: LogLevel;
|
|
28
|
+
branch?: string;
|
|
28
29
|
} & (
|
|
29
30
|
| {
|
|
30
31
|
/**
|
|
@@ -64,6 +65,7 @@ export const KnockProvider: React.FC<PropsWithChildren<KnockProviderProps>> = ({
|
|
|
64
65
|
children,
|
|
65
66
|
i18n,
|
|
66
67
|
identificationStrategy,
|
|
68
|
+
branch,
|
|
67
69
|
...props
|
|
68
70
|
}) => {
|
|
69
71
|
const userIdOrUserWithProperties = props?.user || props?.userId;
|
|
@@ -76,6 +78,7 @@ export const KnockProvider: React.FC<PropsWithChildren<KnockProviderProps>> = ({
|
|
|
76
78
|
timeBeforeExpirationInMs,
|
|
77
79
|
logLevel,
|
|
78
80
|
identificationStrategy,
|
|
81
|
+
branch,
|
|
79
82
|
}),
|
|
80
83
|
[
|
|
81
84
|
host,
|
|
@@ -83,6 +86,7 @@ export const KnockProvider: React.FC<PropsWithChildren<KnockProviderProps>> = ({
|
|
|
83
86
|
timeBeforeExpirationInMs,
|
|
84
87
|
logLevel,
|
|
85
88
|
identificationStrategy,
|
|
89
|
+
branch,
|
|
86
90
|
],
|
|
87
91
|
);
|
|
88
92
|
|
|
@@ -42,6 +42,7 @@ function useMsTeamsAuth(
|
|
|
42
42
|
channel_id: knockMsTeamsChannelId,
|
|
43
43
|
public_key: knock.apiKey,
|
|
44
44
|
user_token: knock.userToken,
|
|
45
|
+
branch_slug: knock.branch,
|
|
45
46
|
}),
|
|
46
47
|
client_id: graphApiClientId,
|
|
47
48
|
redirect_uri: authRedirectUri,
|
|
@@ -53,6 +54,7 @@ function useMsTeamsAuth(
|
|
|
53
54
|
knockMsTeamsChannelId,
|
|
54
55
|
knock.apiKey,
|
|
55
56
|
knock.userToken,
|
|
57
|
+
knock.branch,
|
|
56
58
|
graphApiClientId,
|
|
57
59
|
authRedirectUri,
|
|
58
60
|
]);
|
|
@@ -93,6 +93,7 @@ function useSlackAuth(
|
|
|
93
93
|
channel_id: knockSlackChannelId,
|
|
94
94
|
public_key: knock.apiKey,
|
|
95
95
|
user_token: knock.userToken,
|
|
96
|
+
branch_slug: knock.branch,
|
|
96
97
|
}),
|
|
97
98
|
client_id: slackClientId,
|
|
98
99
|
scope: combinedScopes.join(","),
|
|
@@ -104,6 +105,7 @@ function useSlackAuth(
|
|
|
104
105
|
knockSlackChannelId,
|
|
105
106
|
knock.apiKey,
|
|
106
107
|
knock.userToken,
|
|
108
|
+
knock.branch,
|
|
107
109
|
slackClientId,
|
|
108
110
|
combinedScopes,
|
|
109
111
|
]);
|