@knocklabs/react-core 0.6.8 → 0.6.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/cjs/modules/slack/hooks/useSlackAuth.js +1 -1
- package/dist/cjs/modules/slack/hooks/useSlackAuth.js.map +1 -1
- package/dist/esm/modules/slack/hooks/useSlackAuth.mjs +41 -26
- package/dist/esm/modules/slack/hooks/useSlackAuth.mjs.map +1 -1
- package/dist/types/modules/slack/hooks/useSlackAuth.d.ts +5 -1
- package/dist/types/modules/slack/hooks/useSlackAuth.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/modules/slack/hooks/useSlackAuth.ts +31 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.6.10
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 337bade: feat: introduce ability to override slack scopes
|
|
8
|
+
|
|
9
|
+
## 0.6.9
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 329ee05: downgrade tanstack store deps to 0.6.x to work in older TS version
|
|
14
|
+
- Updated dependencies [329ee05]
|
|
15
|
+
- @knocklabs/client@0.14.8
|
|
16
|
+
|
|
3
17
|
## 0.6.8
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const _=require("../context/KnockSlackProvider.js"),
|
|
1
|
+
"use strict";const _=require("../context/KnockSlackProvider.js"),l=require("react");require("../../i18n/context/KnockI18nProvider.js");require("swr/infinite");const h=require("../../core/context/KnockProvider.js"),A=require("@knocklabs/client");require("fast-deep-equal");require("date-fns");require("swr");const C="https://slack.com/oauth/v2/authorize",s=["chat:write","chat:write.public","channels:read","groups:read"];function b(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=h.useKnockClient(),{setConnectionStatus:n,knockSlackChannelId:r,tenantId:o,setActionLabel:i}=_.useKnockSlackClient(),{scopes:d,additionalScopes:S}=b(k),u=Array.from(new Set(d.concat(S))),p=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:A.TENANT_OBJECT_COLLECTION},channel_id:r,public_key:c.apiKey,user_token:c.userToken}),client_id:e,scope:u.join(",")};return`${C}?${new URLSearchParams(t)}`},[a,o,r,c.apiKey,c.userToken,e,u]),disconnectFromSlack:p}}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\nfunction useSlackAuth(\n slackClientId: string,\n redirectUrl?: string,\n
|
|
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,EA4BM,MAAA,CACLa,kBA3BwBN,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,SAAAA,CACnB,EACDC,UAAWnC,EACXoC,MAAO3B,EAAe4B,KAAK,GAAG,CAChC,EACA,MAAO,GAAG9C,CAAmB,IAAI,IAAI+C,gBAAgBjB,CAAS,CAAC,EACjE,EAAG,CACDpB,EACAK,EACAD,EACAH,EAAM8B,OACN9B,EAAMgC,UACNlC,EACAS,CAAc,CACf,EAICI,oBAAAA,CACF,CACF"}
|
|
@@ -1,53 +1,68 @@
|
|
|
1
|
-
import { useKnockSlackClient as
|
|
2
|
-
import { useCallback as
|
|
1
|
+
import { useKnockSlackClient as S } from "../context/KnockSlackProvider.mjs";
|
|
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 _ } from "../../core/context/KnockProvider.mjs";
|
|
6
|
+
import { TENANT_OBJECT_COLLECTION as h } from "@knocklabs/client";
|
|
7
7
|
import "fast-deep-equal";
|
|
8
8
|
import "date-fns";
|
|
9
9
|
import "swr";
|
|
10
|
-
const
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
const A = "https://slack.com/oauth/v2/authorize", a = ["chat:write", "chat:write.public", "channels:read", "groups:read"];
|
|
11
|
+
function f(e) {
|
|
12
|
+
return e ? Array.isArray(e) ? {
|
|
13
|
+
scopes: a,
|
|
14
|
+
additionalScopes: e
|
|
15
|
+
} : {
|
|
16
|
+
scopes: e.scopes ?? a,
|
|
17
|
+
additionalScopes: e.additionalScopes ?? []
|
|
18
|
+
} : {
|
|
19
|
+
scopes: a,
|
|
20
|
+
additionalScopes: []
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function I(e, s, k) {
|
|
24
|
+
const o = _(), {
|
|
25
|
+
setConnectionStatus: c,
|
|
26
|
+
knockSlackChannelId: t,
|
|
15
27
|
tenantId: n,
|
|
16
28
|
setActionLabel: i
|
|
17
|
-
} =
|
|
18
|
-
|
|
29
|
+
} = S(), {
|
|
30
|
+
scopes: d,
|
|
31
|
+
additionalScopes: p
|
|
32
|
+
} = f(k), l = Array.from(new Set(d.concat(p))), m = u(async () => {
|
|
33
|
+
i(null), c("disconnecting");
|
|
19
34
|
try {
|
|
20
|
-
const
|
|
35
|
+
const r = await o.slack.revokeAccessToken({
|
|
21
36
|
tenant: n,
|
|
22
|
-
knockChannelId:
|
|
37
|
+
knockChannelId: t
|
|
23
38
|
});
|
|
24
|
-
|
|
39
|
+
c(r === "ok" ? "disconnected" : "error");
|
|
25
40
|
} catch {
|
|
26
|
-
|
|
41
|
+
c("error");
|
|
27
42
|
}
|
|
28
|
-
}, [
|
|
43
|
+
}, [c, o.slack, n, t, i]);
|
|
29
44
|
return {
|
|
30
|
-
buildSlackAuthUrl:
|
|
31
|
-
const
|
|
45
|
+
buildSlackAuthUrl: u(() => {
|
|
46
|
+
const r = {
|
|
32
47
|
state: JSON.stringify({
|
|
33
48
|
redirect_url: s,
|
|
34
49
|
access_token_object: {
|
|
35
50
|
object_id: n,
|
|
36
|
-
collection:
|
|
51
|
+
collection: h
|
|
37
52
|
},
|
|
38
|
-
channel_id:
|
|
39
|
-
public_key:
|
|
40
|
-
user_token:
|
|
53
|
+
channel_id: t,
|
|
54
|
+
public_key: o.apiKey,
|
|
55
|
+
user_token: o.userToken
|
|
41
56
|
}),
|
|
42
|
-
client_id:
|
|
57
|
+
client_id: e,
|
|
43
58
|
scope: l.join(",")
|
|
44
59
|
};
|
|
45
|
-
return `${
|
|
46
|
-
}, [s, n,
|
|
60
|
+
return `${A}?${new URLSearchParams(r)}`;
|
|
61
|
+
}, [s, n, t, o.apiKey, o.userToken, e, l]),
|
|
47
62
|
disconnectFromSlack: m
|
|
48
63
|
};
|
|
49
64
|
}
|
|
50
65
|
export {
|
|
51
|
-
|
|
66
|
+
I as default
|
|
52
67
|
};
|
|
53
68
|
//# 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\nfunction useSlackAuth(\n slackClientId: string,\n redirectUrl?: string,\n
|
|
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;AA4BM,SAAA;AAAA,IACLa,mBA3BwBN,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,QAAAA,CACnB;AAAA,QACDC,WAAWnC;AAAAA,QACXoC,OAAO3B,EAAe4B,KAAK,GAAG;AAAA,MAChC;AACA,aAAO,GAAG9C,CAAmB,IAAI,IAAI+C,gBAAgBjB,CAAS,CAAC;AAAA,IACjE,GAAG,CACDpB,GACAK,GACAD,GACAH,EAAM8B,QACN9B,EAAMgC,WACNlC,GACAS,CAAc,CACf;AAAA,IAICI,qBAAAA;AAAAA,EACF;AACF;"}
|
|
@@ -2,6 +2,10 @@ type UseSlackAuthOutput = {
|
|
|
2
2
|
buildSlackAuthUrl: () => string;
|
|
3
3
|
disconnectFromSlack: () => void;
|
|
4
4
|
};
|
|
5
|
-
|
|
5
|
+
type UseSlackAuthOptions = {
|
|
6
|
+
scopes?: string[];
|
|
7
|
+
additionalScopes?: string[];
|
|
8
|
+
};
|
|
9
|
+
declare function useSlackAuth(slackClientId: string, redirectUrl?: string, options?: UseSlackAuthOptions | string[]): UseSlackAuthOutput;
|
|
6
10
|
export default useSlackAuth;
|
|
7
11
|
//# sourceMappingURL=useSlackAuth.d.ts.map
|
|
@@ -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,iBAAS,YAAY,CACnB,aAAa,EAAE,MAAM,EACrB,WAAW,CAAC,EAAE,MAAM,EACpB,
|
|
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,CA+DpB;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.6.
|
|
5
|
+
"version": "0.6.10",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "dist/cjs/index.js",
|
|
8
8
|
"module": "dist/esm/index.mjs",
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"react": "^16.11.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@knocklabs/client": "^0.14.
|
|
53
|
-
"@tanstack/react-store": "
|
|
52
|
+
"@knocklabs/client": "^0.14.8",
|
|
53
|
+
"@tanstack/react-store": "0.6.1",
|
|
54
54
|
"date-fns": "^4.0.0",
|
|
55
55
|
"fast-deep-equal": "^3.1.3",
|
|
56
56
|
"swr": "^2.3.3",
|
|
@@ -58,9 +58,9 @@
|
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@testing-library/dom": "^10.4.0",
|
|
61
|
-
"@testing-library/react": "^16.
|
|
61
|
+
"@testing-library/react": "^16.3.0",
|
|
62
62
|
"@types/react": "^18.3.6",
|
|
63
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
63
|
+
"@typescript-eslint/eslint-plugin": "^8.32.0",
|
|
64
64
|
"@typescript-eslint/parser": "^8.27.0",
|
|
65
65
|
"@vitejs/plugin-react": "^4.4.1",
|
|
66
66
|
"babel-plugin-react-require": "^4.0.3",
|
|
@@ -17,19 +17,45 @@ type UseSlackAuthOutput = {
|
|
|
17
17
|
disconnectFromSlack: () => void;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
+
type UseSlackAuthOptions = {
|
|
21
|
+
// When provided, the default scopes will be overridden with the provided scopes
|
|
22
|
+
scopes?: string[];
|
|
23
|
+
// Additional scopes to add to the default scopes
|
|
24
|
+
additionalScopes?: string[];
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// Here we normalize the options to be a single object with scopes and additionalScopes
|
|
28
|
+
// The "options" parameter can be an array of scopes, an object with scopes and additionalScopes, or undefined
|
|
29
|
+
// We handle the array case because it was the previous way to pass options so we're being backward compatible
|
|
30
|
+
function normalizeOptions(options?: UseSlackAuthOptions | string[]): {
|
|
31
|
+
scopes: string[];
|
|
32
|
+
additionalScopes: string[];
|
|
33
|
+
} {
|
|
34
|
+
if (!options) {
|
|
35
|
+
return { scopes: DEFAULT_SLACK_SCOPES, additionalScopes: [] };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (Array.isArray(options)) {
|
|
39
|
+
return { scopes: DEFAULT_SLACK_SCOPES, additionalScopes: options };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
scopes: options.scopes ?? DEFAULT_SLACK_SCOPES,
|
|
44
|
+
additionalScopes: options.additionalScopes ?? [],
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
20
48
|
function useSlackAuth(
|
|
21
49
|
slackClientId: string,
|
|
22
50
|
redirectUrl?: string,
|
|
23
|
-
|
|
51
|
+
options?: UseSlackAuthOptions | string[],
|
|
24
52
|
): UseSlackAuthOutput {
|
|
25
53
|
const knock = useKnockClient();
|
|
26
54
|
const { setConnectionStatus, knockSlackChannelId, tenantId, setActionLabel } =
|
|
27
55
|
useKnockSlackClient();
|
|
28
56
|
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
? Array.from(new Set(DEFAULT_SLACK_SCOPES.concat(additionalScopes)))
|
|
32
|
-
: DEFAULT_SLACK_SCOPES;
|
|
57
|
+
const { scopes, additionalScopes } = normalizeOptions(options);
|
|
58
|
+
const combinedScopes = Array.from(new Set(scopes.concat(additionalScopes)));
|
|
33
59
|
|
|
34
60
|
const disconnectFromSlack = useCallback(async () => {
|
|
35
61
|
setActionLabel(null);
|