=> {
+ // get the definition of the export which should be downloaded
+ const exportDef = session.exports![id];
+ if (exportDef.type !== ResExportDefinitionType.DOWNLOAD)
+ return {
+ info: {
+ message: "Export is not of type DOWNLOAD.",
+ result: ISdStargateExportFileResultEnum.NOTHING,
+ },
+ };
+ // request the export
+ const {
+ data: {exports: exportResults},
+ } = await new ExportApi(config).computeExports(session.sessionId, {
+ parameters,
+ exports: [id],
+ });
+ const exportResult = exportResults![id] as ResExport;
+ if (
+ exportResult.status_collect !== ResComputationStatus.SUCCESS ||
+ exportResult.status_computation !== ResComputationStatus.SUCCESS
+ )
+ return {
+ info: {
+ message: "Export computation was not successful.",
+ result: ISdStargateExportFileResultEnum.NOTHING,
+ },
+ };
+ // fetch the exported file
+ const {href, size} = exportResult.content![index];
+ await fetchFileWithToken(
+ href,
+ exportResult.filename!,
+ config.accessToken as string,
+ );
+ return {
+ info: {
+ message: `File ${exportResult.filename} downloaded successfully (${size} bytes).`,
+ result: ISdStargateExportFileResultEnum.SUCCESS,
+ },
+ };
+ },
+ [],
+ );
+
+ return {getDataCommandHandler, exportFileCommandHandler, supportedData};
+}
diff --git a/src/pages/HomePage.tsx b/src/pages/HomePage.tsx
index 17b0ed0..fd88756 100644
--- a/src/pages/HomePage.tsx
+++ b/src/pages/HomePage.tsx
@@ -1,5 +1,52 @@
import React from "react";
+import useShapeDiverAuth from "~/hooks/useShapeDiverAuth";
+import useShapeDiverStargate from "~/hooks/useShapeDiverStargate";
+import useStargateHandlers from "~/hooks/useStargateHandlers";
export default function HomePage() {
- return <>>;
+ // call hook used to manage authentication with ShapeDiver via OAuth2 Authorization Code Flow with PKCE
+ const {
+ error,
+ errorDescription,
+ accessToken,
+ initiateShapeDiverAuth,
+ authUsingRefreshToken,
+ authState,
+ platformSdk,
+ } = useShapeDiverAuth({ autoLogin: true });
+
+ // example handlers for the ShapeDiver Stargate service
+ const handlers = useStargateHandlers();
+
+ // call hook used to register as a client for the ShapeDiver Stargate service, using the example handlers
+ const { stargateSdk, isActive } = useShapeDiverStargate({
+ accessToken,
+ platformSdk,
+ ...handlers,
+ });
+
+ return (
+ <>
+ {error && Error: {error}
}
+ {errorDescription && Error description: {errorDescription}
}
+ Authentication state: {authState}
+ {stargateSdk && (
+
+ Stargate SDK initialized {isActive ? "(active)" : undefined}
+
+ )}
+
+ {authState === "not_authenticated" ? (
+
+ ) : undefined}
+ {authState === "refresh_token_present" ? (
+
+ ) : undefined}
+
+ >
+ );
}