@knocklabs/react-core
Advanced tools
Comparing version 0.2.24 to 0.2.25
# Changelog | ||
## 0.2.25 | ||
### Patch Changes | ||
- 47a88da: feature: allow passing additional OAuth scope to SlackAuthButton | ||
## 0.2.24 | ||
@@ -4,0 +10,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";const k=require("../context/KnockSlackProvider.js"),i=require("react");require("../../i18n/context/KnockI18nProvider.js");require("swr/infinite");const l=require("../../core/context/KnockProvider.js"),d=require("@knocklabs/client");require("zustand/shallow");require("date-fns");const h="https://slack.com/oauth/v2/authorize",S=["chat:write","chat:write.public","channels:read","groups:read"];function _(o,s){const e=l.useKnockClient(),{setConnectionStatus:c,knockSlackChannelId:n,tenant:r,setActionLabel:a}=k.useKnockSlackClient(),u=i.useCallback(async()=>{a(null),c("disconnecting");try{const t=await e.slack.revokeAccessToken({tenant:r,knockChannelId:n});c(t==="ok"?"disconnected":"error")}catch{c("error")}},[c,e.slack,r,n,a]);return{buildSlackAuthUrl:i.useCallback(()=>{const t={state:JSON.stringify({redirect_url:s,access_token_object:{object_id:r,collection:d.TENANT_OBJECT_COLLECTION},channel_id:n,public_key:e.apiKey,user_token:e.userToken}),client_id:o,scope:S.join(",")};return`${h}?${new URLSearchParams(t)}`},[s,r,n,e.apiKey,e.userToken,o]),disconnectFromSlack:u}}module.exports=_; | ||
"use strict";const S=require("../context/KnockSlackProvider.js"),k=require("react");require("../../i18n/context/KnockI18nProvider.js");require("swr/infinite");const _=require("../../core/context/KnockProvider.js"),C=require("@knocklabs/client");require("zustand/shallow");require("date-fns");const d="https://slack.com/oauth/v2/authorize",l=["chat:write","chat:write.public","channels:read","groups:read"];function A(s,a,o){const e=_.useKnockClient(),{setConnectionStatus:c,knockSlackChannelId:n,tenant:r,setActionLabel:i}=S.useKnockSlackClient(),u=o&&o.length>0?Array.from(new Set(l.concat(o))):l,h=k.useCallback(async()=>{i(null),c("disconnecting");try{const t=await e.slack.revokeAccessToken({tenant:r,knockChannelId:n});c(t==="ok"?"disconnected":"error")}catch{c("error")}},[c,e.slack,r,n,i]);return{buildSlackAuthUrl:k.useCallback(()=>{const t={state:JSON.stringify({redirect_url:a,access_token_object:{object_id:r,collection:C.TENANT_OBJECT_COLLECTION},channel_id:n,public_key:e.apiKey,user_token:e.userToken}),client_id:s,scope:u.join(",")};return`${d}?${new URLSearchParams(t)}`},[a,r,n,e.apiKey,e.userToken,s,u]),disconnectFromSlack:h}}module.exports=A; | ||
//# sourceMappingURL=useSlackAuth.js.map |
@@ -5,4 +5,4 @@ type UseSlackAuthOutput = { | ||
}; | ||
declare function useSlackAuth(slackClientId: string, redirectUrl?: string): UseSlackAuthOutput; | ||
declare function useSlackAuth(slackClientId: string, redirectUrl?: string, additionalScopes?: string[]): UseSlackAuthOutput; | ||
export default useSlackAuth; | ||
//# sourceMappingURL=useSlackAuth.d.ts.map |
@@ -5,3 +5,3 @@ { | ||
"author": "@knocklabs", | ||
"version": "0.2.24", | ||
"version": "0.2.25", | ||
"license": "MIT", | ||
@@ -54,3 +54,3 @@ "main": "dist/cjs/index.js", | ||
"@knocklabs/client": "^0.10.13", | ||
"date-fns": "^3.3.1", | ||
"date-fns": "^4.0.0", | ||
"swr": "^2.2.5", | ||
@@ -61,6 +61,6 @@ "zustand": "^3.7.2" | ||
"@testing-library/react": "^14.2.0", | ||
"@types/react": "^18.2.37", | ||
"@types/react": "^18.3.6", | ||
"@typescript-eslint/eslint-plugin": "^6.20.0", | ||
"@typescript-eslint/parser": "^6.20.0", | ||
"@vitejs/plugin-react": "^4.2.0", | ||
"@typescript-eslint/parser": "^8.8.0", | ||
"@vitejs/plugin-react": "^4.3.2", | ||
"babel-plugin-react-require": "^4.0.3", | ||
@@ -74,3 +74,3 @@ "eslint": "^8.56.0", | ||
"rollup-plugin-execute": "^1.1.1", | ||
"typescript": "^5.5.4", | ||
"typescript": "^5.6.2", | ||
"vite": "^5.0.0", | ||
@@ -77,0 +77,0 @@ "vite-plugin-dts": "^3.6.3", |
@@ -23,2 +23,3 @@ import { useKnockSlackClient } from ".."; | ||
redirectUrl?: string, | ||
additionalScopes?: string[], | ||
): UseSlackAuthOutput { | ||
@@ -29,2 +30,7 @@ const knock = useKnockClient(); | ||
const combinedScopes = | ||
additionalScopes && additionalScopes.length > 0 | ||
? Array.from(new Set(DEFAULT_SLACK_SCOPES.concat(additionalScopes))) | ||
: DEFAULT_SLACK_SCOPES; | ||
const disconnectFromSlack = useCallback(async () => { | ||
@@ -68,3 +74,3 @@ setActionLabel(null); | ||
client_id: slackClientId, | ||
scope: DEFAULT_SLACK_SCOPES.join(","), | ||
scope: combinedScopes.join(","), | ||
}; | ||
@@ -79,2 +85,3 @@ return `${SLACK_AUTHORIZE_URL}?${new URLSearchParams(rawParams)}`; | ||
slackClientId, | ||
combinedScopes, | ||
]); | ||
@@ -81,0 +88,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
209055
1970
+ Addeddate-fns@4.1.0(transitive)
- Removeddate-fns@3.6.0(transitive)
Updateddate-fns@^4.0.0