Skip to content

Commit 86448fe

Browse files
committed
Disabling button not working
1 parent ec5cbc0 commit 86448fe

File tree

4 files changed

+125
-50
lines changed

4 files changed

+125
-50
lines changed

integrations/va-auth0/gitbook-manifest.yaml

+19-18
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ externalLinks:
55
- label: Documentation
66
url: https://www.gitbook.com/integrations/heap
77
visibility: public
8-
script: ./src/index.ts
8+
script: ./src/index.tsx
99
# The following scope(s) are available only to GitBook Staff
1010
# See https://developer.gitbook.com/integrations/configurations#scopes
1111
scopes:
@@ -19,21 +19,22 @@ categories:
1919
- analytics
2020
configurations:
2121
space:
22-
properties:
23-
client_id:
24-
type: string
25-
title: Client ID
26-
description: Client ID of your Auth0 app
27-
issuer_base_url:
28-
type: string
29-
title: Issuer Base URL
30-
description: Issuer Base URL of your Auth0 instance
31-
client_secret:
32-
type: string
33-
title: Client Secret
34-
description: The Client Secret of your Auth0 app
22+
componentId: hello
23+
# properties:
24+
# client_id:
25+
# type: string
26+
# title: Client ID
27+
# description: Client ID of your Auth0 app
28+
# issuer_base_url:
29+
# type: string
30+
# title: Issuer Base URL
31+
# description: Issuer Base URL of your Auth0 instance
32+
# client_secret:
33+
# type: string
34+
# title: Client Secret
35+
# description: The Client Secret of your Auth0 app
3536

36-
required:
37-
- client_id
38-
- issuer_base_url
39-
- client_secret
37+
# required:
38+
# - client_id
39+
# - issuer_base_url
40+
# - client_secret

integrations/va-auth0/src/index.ts integrations/va-auth0/src/index.tsx

+105-22
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import { sign } from '@tsndr/cloudflare-worker-jwt';
22
import { Router } from 'itty-router';
3-
// import * as jwt from 'jsonwebtoken';
43

4+
// import * as jwt from 'jsonwebtoken';
5+
import { IntegrationInstallationConfiguration } from '@gitbook/api';
56
import {
67
createIntegration,
78
FetchEventCallback,
89
Logger,
910
RuntimeContext,
1011
RuntimeEnvironment,
1112
EventCallback,
13+
createComponent,
1214
} from '@gitbook/runtime';
1315

1416
// import type { GithubRuntimeContext } from '../../github/src/types';
@@ -17,15 +19,94 @@ const logger = Logger('auth0.visitor-auth');
1719

1820
type Auth0RuntimeEnvironment = RuntimeEnvironment<
1921
{},
20-
{
21-
client_id?: string;
22-
issuer_base_url?: string;
22+
Auth0SpaceInstallationConfiguration & {
2323
private_key?: string;
24-
client_secret?: string;
2524
}
2625
>;
2726

2827
type Auth0RuntimeContext = RuntimeContext<Auth0RuntimeEnvironment>;
28+
29+
type Auth0SpaceInstallationConfiguration = {
30+
client_id?: string;
31+
issuer_base_url?: string;
32+
client_secret?: string;
33+
};
34+
35+
type Auth0State = Auth0SpaceInstallationConfiguration;
36+
37+
type Auth0Props = {
38+
installation: {
39+
configuration?: IntegrationInstallationConfiguration;
40+
};
41+
spaceInstallation: {
42+
configuration?: Auth0SpaceInstallationConfiguration;
43+
};
44+
};
45+
46+
export type Auth0Action = { action: 'save.config' };
47+
48+
const helloWorldBlock = createComponent<Auth0Props, Auth0State, Auth0Action, Auth0RuntimeContext>({
49+
componentId: 'hello',
50+
initialState: (props) => {
51+
return {
52+
client_id: props.spaceInstallation.configuration?.client_id?.toString() || '',
53+
issuer_base_url:
54+
props.spaceInstallation.configuration?.issuer_base_url?.toString() || '',
55+
client_secret: props.spaceInstallation.configuration?.client_secret?.toString() || '',
56+
};
57+
},
58+
action: async (element, action, context) => {
59+
switch (action.action) {
60+
case 'save.config':
61+
// await saveConfig();
62+
return element;
63+
}
64+
},
65+
render: async (element, context) => {
66+
// eslint-disable-next-line no-console
67+
console.log(
68+
'disabled?',
69+
element.dynamicState('client_id'),
70+
!element.state.client_id ||
71+
!element.state.issuer_base_url ||
72+
!element.state.client_secret
73+
);
74+
const showButton =
75+
element.state.client_id && element.state.issuer_base_url && element.state.client_secret;
76+
return (
77+
<block>
78+
<textinput state="client_id" placeholder="Enter Client Id" />
79+
<textinput state="issuer_base_url" placeholder="Enter Issuer Base URL" />
80+
<textinput state="client_secret" placeholder="Enter Client Secret" />
81+
{true ? (
82+
<input
83+
label=""
84+
hint=""
85+
element={
86+
<button
87+
style="primary"
88+
disabled={
89+
!element.state.client_id ||
90+
!element.state.client_secret ||
91+
!element.state.issuer_base_url
92+
}
93+
label="Configure"
94+
tooltip="Save configuration"
95+
onPress={{
96+
action: 'save.config',
97+
client_id: element.dynamicState('client_id'),
98+
client_secret: element.dynamicState('client_secret'),
99+
issuer_base_url: element.dynamicState('issuer_base_url'),
100+
}}
101+
/>
102+
}
103+
/>
104+
) : null}
105+
</block>
106+
);
107+
},
108+
});
109+
29110
const handleFetchEvent: FetchEventCallback<Auth0RuntimeContext> = async (request, context) => {
30111
const { environment } = context;
31112
const installationURL = environment.spaceInstallation?.urls?.publicEndpoint;
@@ -180,8 +261,27 @@ const handleFetchEvent: FetchEventCallback<Auth0RuntimeContext> = async (request
180261

181262
export default createIntegration({
182263
fetch: handleFetchEvent,
264+
components: [helloWorldBlock],
265+
fetch_visitor_authentication: async (event, context) => {
266+
const { environment } = context;
267+
const installationURL = environment.spaceInstallation?.urls?.publicEndpoint;
268+
const issuerBaseUrl = environment.spaceInstallation?.configuration.issuer_base_url;
269+
const clientId = environment.spaceInstallation?.configuration.client_id;
270+
const location = '';
271+
272+
try {
273+
return Response.redirect(
274+
`${issuerBaseUrl}/authorize?response_type=code&client_id=${clientId}&redirect_uri=${installationURL}/visitor-auth/response&state=${location}`
275+
);
276+
} catch (e) {
277+
return Response.json({ error: e.stack });
278+
}
279+
280+
// await triggerExport(context, spaceInstallation);
281+
},
183282
events: {
184283
space_installation_setup: async (event, context) => {
284+
// check event status to be active
185285
if (!context.environment.spaceInstallation?.configuration.private_key) {
186286
const res = await context.api.integrations.updateIntegrationSpaceInstallation(
187287
context.environment.integration.name,
@@ -195,22 +295,5 @@ export default createIntegration({
195295
);
196296
}
197297
},
198-
fetch_visitor_authentication: async (event, context) => {
199-
const { environment } = context;
200-
const installationURL = environment.spaceInstallation?.urls?.publicEndpoint;
201-
const issuerBaseUrl = environment.spaceInstallation?.configuration.issuer_base_url;
202-
const clientId = environment.spaceInstallation?.configuration.client_id;
203-
const location = event.location || '';
204-
205-
try {
206-
return Response.redirect(
207-
`${issuerBaseUrl}/authorize?response_type=code&client_id=${clientId}&redirect_uri=${installationURL}/visitor-auth/response&state=${location}`
208-
);
209-
} catch (e) {
210-
return Response.json({ error: e.stack });
211-
}
212-
213-
// await triggerExport(context, spaceInstallation);
214-
},
215298
},
216299
});

integrations/va-auth0/tsconfig.json

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
11
{
2-
"extends": "@gitbook/tsconfig/integration.json",
3-
"compilerOptions": {
4-
"strict": true,
5-
"lib": ["ESNext", "DOM"],
6-
"downlevelIteration": true
7-
}
2+
"extends": "@gitbook/tsconfig/integration.json"
83
}

integrations/va-auth0/wrangler.toml

-4
This file was deleted.

0 commit comments

Comments
 (0)