Skip to content

Commit 6f8bf5f

Browse files
committed
wip
1 parent f4600be commit 6f8bf5f

File tree

4 files changed

+73
-1
lines changed

4 files changed

+73
-1
lines changed

integrations/va-auth0/src/index.ts

+68
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ import {
88
Logger,
99
RuntimeContext,
1010
RuntimeEnvironment,
11+
EventCallback,
1112
} from '@gitbook/runtime';
1213

14+
// import type { GithubRuntimeContext } from '../../github/src/types';
15+
1316
const logger = Logger('auth0.visitor-auth');
1417

1518
type Auth0RuntimeEnvironment = RuntimeEnvironment<
@@ -32,6 +35,7 @@ const handleFetchEvent: FetchEventCallback<Auth0RuntimeContext> = async (request
3235
});
3336
router.get('/visitor-auth', async (request) => {
3437
logger.debug('Got a request');
38+
return Response.json({ req: 'Got in the fetch event' });
3539
const location = request.query.location;
3640
const issuerBaseUrl = environment.spaceInstallation?.configuration.issuer_base_url;
3741
const clientId = environment.spaceInstallation?.configuration.client_id;
@@ -127,6 +131,53 @@ const handleFetchEvent: FetchEventCallback<Auth0RuntimeContext> = async (request
127131
}
128132
};
129133

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+
130181
export default createIntegration({
131182
fetch: handleFetchEvent,
132183
events: {
@@ -144,5 +195,22 @@ export default createIntegration({
144195
);
145196
}
146197
},
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+
},
147215
},
148216
});

integrations/va-azure/.eslintrc.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": ["@gitbook/eslint-config/integration"]
3+
}

package-lock.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/runtime/src/integrations.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export function createIntegration<Context extends RuntimeContext = RuntimeContex
126126
if (Array.isArray(cb)) {
127127
await Promise.all(cb.map((c) => c(event, context)));
128128
} else {
129-
await cb(event, context);
129+
return await cb(event, context);
130130
}
131131

132132
// TODO: maybe the callback wants to return something

0 commit comments

Comments
 (0)