@@ -8,8 +8,11 @@ import {
8
8
Logger ,
9
9
RuntimeContext ,
10
10
RuntimeEnvironment ,
11
+ EventCallback ,
11
12
} from '@gitbook/runtime' ;
12
13
14
+ // import type { GithubRuntimeContext } from '../../github/src/types';
15
+
13
16
const logger = Logger ( 'auth0.visitor-auth' ) ;
14
17
15
18
type Auth0RuntimeEnvironment = RuntimeEnvironment <
@@ -32,6 +35,7 @@ const handleFetchEvent: FetchEventCallback<Auth0RuntimeContext> = async (request
32
35
} ) ;
33
36
router . get ( '/visitor-auth' , async ( request ) => {
34
37
logger . debug ( 'Got a request' ) ;
38
+ return Response . json ( { req : 'Got in the fetch event' } ) ;
35
39
const location = request . query . location ;
36
40
const issuerBaseUrl = environment . spaceInstallation ?. configuration . issuer_base_url ;
37
41
const clientId = environment . spaceInstallation ?. configuration . client_id ;
@@ -127,6 +131,53 @@ const handleFetchEvent: FetchEventCallback<Auth0RuntimeContext> = async (request
127
131
}
128
132
} ;
129
133
134
+ // const handleFetchVisitorAuth: EventCallback<
135
+ // 'fetch_visitor_authentication',
136
+ // Auth0RuntimeContext
137
+ // > = async (event, context) => {
138
+ // const { data: revision } = await context.api.spaces.getRevisionById(
139
+ // event.spaceId,
140
+ // event.revisionId
141
+ // );
142
+ // if (revision.git?.oid) {
143
+ // const revisionStatus = revision.git.createdByGitBook ? 'exported' : 'imported';
144
+ // logger.info(
145
+ // `skipping Git Sync for space ${event.spaceId} revision ${revision.id} as it was already ${revisionStatus}`
146
+ // );
147
+ // return;
148
+ // }
149
+
150
+ // const spaceInstallation = context.environment.spaceInstallation;
151
+ // if (!spaceInstallation) {
152
+ // logger.debug(`missing space installation, skipping`);
153
+ // return;
154
+ // }
155
+
156
+ // // await triggerExport(context, spaceInstallation);
157
+ // };
158
+ // const handleGitSyncCompleted: EventCallback<
159
+ // 'space_gitsync_completed',
160
+ // GithubRuntimeContext
161
+ // > = async (event, context) => {
162
+ // logger.info(
163
+ // `Git Sync completed (${event.state}) for space ${event.spaceId} revision ${event.revisionId}, updating commit status`
164
+ // );
165
+
166
+ // const spaceInstallation = context.environment.spaceInstallation;
167
+ // if (!spaceInstallation) {
168
+ // logger.debug(`missing space installation, skipping`);
169
+ // return;
170
+ // }
171
+
172
+ // await updateCommitWithPreviewLinks(
173
+ // context,
174
+ // spaceInstallation,
175
+ // event.revisionId,
176
+ // event.commitId,
177
+ // event.state as GitSyncOperationState
178
+ // );
179
+ // };
180
+
130
181
export default createIntegration ( {
131
182
fetch : handleFetchEvent ,
132
183
events : {
@@ -144,5 +195,22 @@ export default createIntegration({
144
195
) ;
145
196
}
146
197
} ,
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
+ } ,
147
215
} ,
148
216
} ) ;
0 commit comments