Line data Source code
1 : import * as connection from '@ankoh/dashql-jsonschema/connection.js';
2 :
3 : import { ConnectionState } from './connection_state.js';
4 : import { isSalesforceDetails } from './connection_state_details.js';
5 :
6 1 : export enum ConnectionSetupCheck {
7 1 : UNKNOWN,
8 1 : CONNECTION_NULL,
9 1 : CONNECTION_TYPE_MISMATCH,
10 1 : AUTHENTICATED,
11 1 : AUTHENTICATION_FAILED,
12 1 : AUTHENTICATION_IN_PROGRESS,
13 1 : AUTHENTICATION_NOT_STARTED,
14 1 : CLIENT_ID_MISMATCH,
15 1 : }
16 :
17 1 : export function checkSalesforceConnectionSetup(
18 1 : state: ConnectionState | null,
19 1 : params: connection.SalesforceConnectionParams,
20 1 : ): ConnectionSetupCheck {
21 1 : if (!state) {
22 0 : return ConnectionSetupCheck.CONNECTION_NULL;
23 : }
24 1 : if (!isSalesforceDetails(state.details)) {
25 0 : return ConnectionSetupCheck.CONNECTION_TYPE_MISMATCH;
26 : }
27 1 : const details = state.details.value;
28 1 : if (!details.proto.setupParams) {
29 0 : return ConnectionSetupCheck.AUTHENTICATION_NOT_STARTED;
30 : }
31 1 : if (details.proto.setupParams.appConsumerKey != params.appConsumerKey) {
32 0 : return ConnectionSetupCheck.CLIENT_ID_MISMATCH;
33 : }
34 1 : if (details.proto.setupError) {
35 1 : return ConnectionSetupCheck.AUTHENTICATION_FAILED;
36 : }
37 1 : const coreToken = details.proto.oauthState?.coreAccessToken;
38 1 : const token = details.proto.oauthState?.dataCloudAccessToken;
39 1 : if (coreToken?.accessToken && token?.jwt?.raw) {
40 1 : return ConnectionSetupCheck.AUTHENTICATED;
41 : }
42 1 : if (details.proto.setupTimings?.authStartedAt) {
43 1 : return ConnectionSetupCheck.AUTHENTICATION_IN_PROGRESS;
44 : }
45 0 : return ConnectionSetupCheck.UNKNOWN;
46 1 : }
47 :
48 : export function checkHyperConnectionSetup(
49 : state: ConnectionState | null,
50 : params: connection.HyperConnectionParams,
51 : ): ConnectionSetupCheck {
52 : return ConnectionSetupCheck.UNKNOWN;
53 : }
|