1
1
import { sign } from '@tsndr/cloudflare-worker-jwt' ;
2
2
import { Router } from 'itty-router' ;
3
3
4
- // import * as jwt from 'jsonwebtoken';
5
4
import { IntegrationInstallationConfiguration } from '@gitbook/api' ;
6
5
import {
7
6
createIntegration ,
8
7
FetchEventCallback ,
9
8
Logger ,
10
9
RuntimeContext ,
11
10
RuntimeEnvironment ,
12
- EventCallback ,
13
11
createComponent ,
14
12
} from '@gitbook/runtime' ;
15
13
16
- // import type { GithubRuntimeContext } from '../../github/src/types';
17
-
18
14
const logger = Logger ( 'auth0.visitor-auth' ) ;
19
15
20
16
type Auth0RuntimeEnvironment = RuntimeEnvironment <
@@ -58,8 +54,6 @@ const helloWorldBlock = createComponent<Auth0Props, Auth0State, Auth0Action, Aut
58
54
action : async ( element , action , context ) => {
59
55
switch ( action . action ) {
60
56
case 'save.config' :
61
- // eslint-disable-next-line no-console
62
- console . log ( 'action save.config element.state.client_id' , element . state . client_id ) ;
63
57
const { api, environment } = context ;
64
58
const spaceInstallation = environment . spaceInstallation ;
65
59
@@ -69,7 +63,8 @@ const helloWorldBlock = createComponent<Auth0Props, Auth0State, Auth0Action, Aut
69
63
client_secret : element . state . client_secret ,
70
64
issuer_base_url : element . state . issuer_base_url ,
71
65
} ;
72
-
66
+ // eslint-disable-next-line no-console
67
+ console . log ( 'env.auth_token' , environment . authToken ) ;
73
68
const res = await api . integrations . updateIntegrationSpaceInstallation (
74
69
spaceInstallation . integration ,
75
70
spaceInstallation . installation ,
@@ -80,8 +75,6 @@ const helloWorldBlock = createComponent<Auth0Props, Auth0State, Auth0Action, Aut
80
75
} ,
81
76
}
82
77
) ;
83
- // eslint-disable-next-line no-console
84
- console . log ( 'res' , res ) ;
85
78
return element ;
86
79
}
87
80
} ,
@@ -99,13 +92,10 @@ const helloWorldBlock = createComponent<Auth0Props, Auth0State, Auth0Action, Aut
99
92
< button
100
93
style = "primary"
101
94
disabled = { false }
102
- label = "Vibby "
103
- tooltip = "Save configuration Vib "
95
+ label = "Vib "
96
+ tooltip = "Save configuration"
104
97
onPress = { {
105
98
action : 'save.config' ,
106
- // client_id: element.dynamicState('client_id'),
107
- // client_secret: element.dynamicState('client_secret'),
108
- // issuer_base_url: element.dynamicState('issuer_base_url'),
109
99
} }
110
100
/>
111
101
}
@@ -154,12 +144,16 @@ const handleFetchEvent: FetchEventCallback<Auth0RuntimeContext> = async (request
154
144
context . environment . spaceInstallation ?. space
155
145
) ;
156
146
const obj = space . data ;
147
+ // eslint-disable-next-line no-console
148
+ console . log ( 'obj' , obj ) ;
157
149
const privateKey = context . environment . spaceInstallation . configuration . private_key ;
150
+ const envPK = context . environment . signingSecret ;
151
+ console . log ( 'privateKey envPK' , envPK ) ;
158
152
let token ;
159
153
try {
160
154
token = await sign (
161
155
{ exp : Math . floor ( Date . now ( ) / 1000 ) + 2 * ( 60 * 60 ) } ,
162
- privateKey ? privateKey : ''
156
+ envPK ? envPK : ''
163
157
) ;
164
158
} catch ( e ) {
165
159
return Response . json ( { error : e . stack } ) ;
@@ -230,53 +224,6 @@ const handleFetchEvent: FetchEventCallback<Auth0RuntimeContext> = async (request
230
224
}
231
225
} ;
232
226
233
- // const handleFetchVisitorAuth: EventCallback<
234
- // 'fetch_visitor_authentication',
235
- // Auth0RuntimeContext
236
- // > = async (event, context) => {
237
- // const { data: revision } = await context.api.spaces.getRevisionById(
238
- // event.spaceId,
239
- // event.revisionId
240
- // );
241
- // if (revision.git?.oid) {
242
- // const revisionStatus = revision.git.createdByGitBook ? 'exported' : 'imported';
243
- // logger.info(
244
- // `skipping Git Sync for space ${event.spaceId} revision ${revision.id} as it was already ${revisionStatus}`
245
- // );
246
- // return;
247
- // }
248
-
249
- // const spaceInstallation = context.environment.spaceInstallation;
250
- // if (!spaceInstallation) {
251
- // logger.debug(`missing space installation, skipping`);
252
- // return;
253
- // }
254
-
255
- // // await triggerExport(context, spaceInstallation);
256
- // };
257
- // const handleGitSyncCompleted: EventCallback<
258
- // 'space_gitsync_completed',
259
- // GithubRuntimeContext
260
- // > = async (event, context) => {
261
- // logger.info(
262
- // `Git Sync completed (${event.state}) for space ${event.spaceId} revision ${event.revisionId}, updating commit status`
263
- // );
264
-
265
- // const spaceInstallation = context.environment.spaceInstallation;
266
- // if (!spaceInstallation) {
267
- // logger.debug(`missing space installation, skipping`);
268
- // return;
269
- // }
270
-
271
- // await updateCommitWithPreviewLinks(
272
- // context,
273
- // spaceInstallation,
274
- // event.revisionId,
275
- // event.commitId,
276
- // event.state as GitSyncOperationState
277
- // );
278
- // };
279
-
280
227
export default createIntegration ( {
281
228
fetch : handleFetchEvent ,
282
229
components : [ helloWorldBlock ] ,
@@ -294,12 +241,9 @@ export default createIntegration({
294
241
} catch ( e ) {
295
242
return Response . json ( { error : e . stack } ) ;
296
243
}
297
-
298
- // await triggerExport(context, spaceInstallation);
299
244
} ,
300
245
events : {
301
246
space_installation_setup : async ( event , context ) => {
302
- // check event status to be active
303
247
if ( ! context . environment . spaceInstallation ?. configuration . private_key ) {
304
248
const res = await context . api . integrations . updateIntegrationSpaceInstallation (
305
249
context . environment . integration . name ,
0 commit comments