Skip to content

Commit 0cf996a

Browse files
committed
Merge branch 'refs/heads/main' into chore/rtk-identity-traits
# Conflicts: # frontend/common/types/requests.ts # frontend/common/types/responses.ts
2 parents 4e4bb52 + 31bbf45 commit 0cf996a

File tree

9 files changed

+500
-438
lines changed

9 files changed

+500
-438
lines changed

frontend/common/providers/withAuditWebhooks.js

Lines changed: 0 additions & 78 deletions
This file was deleted.
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
import { Res } from 'common/types/responses'
2+
import { Req } from 'common/types/requests'
3+
import { service } from 'common/service'
4+
5+
export const organisationWebhookService = service
6+
.enhanceEndpoints({ addTagTypes: ['AuditLogWebhook'] })
7+
.injectEndpoints({
8+
endpoints: (builder) => ({
9+
createAuditLogWebhooks: builder.mutation<
10+
Res['organisationWebhooks'],
11+
Req['createAuditLogWebhooks']
12+
>({
13+
invalidatesTags: (res, _, req) => [
14+
{ id: req?.organisationId, type: 'AuditLogWebhook' },
15+
],
16+
query: (query: Req['createAuditLogWebhooks']) => ({
17+
body: query.data,
18+
method: 'POST',
19+
url: `organisations/${query.organisationId}/webhooks/`,
20+
}),
21+
}),
22+
deleteAuditLogWebhook: builder.mutation<
23+
Res['organisationWebhooks'],
24+
Req['deleteAuditLogWebhook']
25+
>({
26+
invalidatesTags: (res, _, req) => [
27+
{ id: req?.organisationId, type: 'AuditLogWebhook' },
28+
],
29+
query: (query: Req['deleteAuditLogWebhook']) => ({
30+
body: query,
31+
method: 'DELETE',
32+
url: `organisations/${query.organisationId}/webhooks/${query.id}/`,
33+
}),
34+
}),
35+
getAuditLogWebhooks: builder.query<
36+
Res['organisationWebhooks'],
37+
Req['getAuditLogWebhooks']
38+
>({
39+
providesTags: (res, _, req) => [
40+
{ id: req?.organisationId, type: 'AuditLogWebhook' },
41+
],
42+
query: (query: Req['getAuditLogWebhooks']) => ({
43+
url: `organisations/${query.organisationId}/webhooks/`,
44+
}),
45+
}),
46+
updateAuditLogWebhooks: builder.mutation<
47+
Res['organisationWebhooks'],
48+
Req['updateAuditLogWebhooks']
49+
>({
50+
invalidatesTags: (res, _, req) => [
51+
{ id: req?.organisationId, type: 'AuditLogWebhook' },
52+
],
53+
query: (query: Req['updateAuditLogWebhooks']) => ({
54+
body: query.data,
55+
method: 'PUT',
56+
url: `organisations/${query.organisationId}/webhooks/${query.data.id}/`,
57+
}),
58+
}),
59+
// END OF ENDPOINTS
60+
}),
61+
})
62+
63+
export async function createAuditLogWebhooks(
64+
store: any,
65+
data: Req['createAuditLogWebhooks'],
66+
options?: Parameters<
67+
typeof organisationWebhookService.endpoints.createAuditLogWebhooks.initiate
68+
>[1],
69+
) {
70+
return store.dispatch(
71+
organisationWebhookService.endpoints.createAuditLogWebhooks.initiate(
72+
data,
73+
options,
74+
),
75+
)
76+
}
77+
export async function deleteAuditLogWebhook(
78+
store: any,
79+
data: Req['deleteAuditLogWebhook'],
80+
options?: Parameters<
81+
typeof organisationWebhookService.endpoints.deleteAuditLogWebhook.initiate
82+
>[1],
83+
) {
84+
return store.dispatch(
85+
organisationWebhookService.endpoints.deleteAuditLogWebhook.initiate(
86+
data,
87+
options,
88+
),
89+
)
90+
}
91+
export async function getAuditLogWebhooks(
92+
store: any,
93+
data: Req['getAuditLogWebhooks'],
94+
options?: Parameters<
95+
typeof organisationWebhookService.endpoints.getAuditLogWebhooks.initiate
96+
>[1],
97+
) {
98+
return store.dispatch(
99+
organisationWebhookService.endpoints.getAuditLogWebhooks.initiate(
100+
data,
101+
options,
102+
),
103+
)
104+
}
105+
export async function updateAuditLogWebhooks(
106+
store: any,
107+
data: Req['updateAuditLogWebhooks'],
108+
options?: Parameters<
109+
typeof organisationWebhookService.endpoints.updateAuditLogWebhooks.initiate
110+
>[1],
111+
) {
112+
return store.dispatch(
113+
organisationWebhookService.endpoints.updateAuditLogWebhooks.initiate(
114+
data,
115+
options,
116+
),
117+
)
118+
}
119+
// END OF FUNCTION_EXPORTS
120+
121+
export const {
122+
useCreateAuditLogWebhooksMutation,
123+
useDeleteAuditLogWebhookMutation,
124+
useGetAuditLogWebhooksQuery,
125+
useUpdateAuditLogWebhooksMutation,
126+
// END OF EXPORTS
127+
} = organisationWebhookService
128+
129+
/* Usage examples:
130+
const { data, isLoading } = useGetAuditLogWebhooksQuery({ id: 2 }, {}) //get hook
131+
const [createAuditLogWebhooks, { isLoading, data, isSuccess }] = useCreateAuditLogWebhooksMutation() //create hook
132+
organisationWebhookService.endpoints.getAuditLogWebhooks.select({id: 2})(store.getState()) //access data from any function
133+
*/

frontend/common/types/requests.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
Identity,
1717
Role,
1818
RolePermission,
19+
Webhook,
1920
IdentityTrait,
2021
} from './responses'
2122

@@ -561,6 +562,13 @@ export type Req = {
561562
environmentId: string
562563
data: Identity
563564
}
565+
createAuditLogWebhooks: {
566+
organisationId: string
567+
data: Omit<Webhook, 'id' | 'created_at' | 'updated_at'>
568+
}
569+
getAuditLogWebhooks: { organisationId: string }
570+
updateAuditLogWebhooks: { organisationId: string; data: Webhook }
571+
deleteAuditLogWebhook: { organisationId: string; id: number }
564572
createIdentityTrait: {
565573
use_edge_identities: boolean
566574
environmentId: string

frontend/common/types/responses.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export type PagedResponse<T> = {
1717
previous?: string
1818
results: T[]
1919
}
20+
2021
export interface GitHubPagedResponse<T> extends PagedResponse<T> {
2122
incomplete_results: boolean
2223
}
@@ -801,6 +802,7 @@ export type Res = {
801802
metadata_xml: string
802803
}
803804
samlAttributeMapping: PagedResponse<SAMLAttributeMapping>
805+
organisationWebhooks: PagedResponse<Webhook>
804806
identityTrait: { id: string }
805807
identityTraits: IdentityTrait[]
806808
// END OF TYPES

frontend/web/components/TestWebhook.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import data from 'common/data/base/_data'
66
import Button from './base/forms/Button'
77

88
type TestWebhookType = {
9-
webhook: string
9+
webhook: string | undefined
1010
json: string
11-
secret: string
11+
secret: string | undefined
1212
}
1313

1414
// from https://stackoverflow.com/questions/24834812/space-in-between-json-stringify-output
@@ -61,7 +61,7 @@ const TestWebhook: FC<TestWebhookType> = ({ json, secret, webhook }) => {
6161
setError(null)
6262
setLoading(true)
6363
setSuccess(false)
64-
signPayload(json, secret).then((sign) => {
64+
signPayload(json, secret || '').then((sign) => {
6565
const headers = {
6666
'X-Flagsmith-Signature': sign,
6767
}
@@ -71,7 +71,7 @@ const TestWebhook: FC<TestWebhookType> = ({ json, secret, webhook }) => {
7171
setLoading(false)
7272
setSuccess(true)
7373
})
74-
.catch((e) => {
74+
.catch((e: any) => {
7575
if (e.text) {
7676
e.text().then((error: string) => {
7777
setError(`The server returned an error: ${error}`)

0 commit comments

Comments
 (0)