Skip to content

Commit 40a6771

Browse files
committed
add org domain support + list orgs
1 parent 46d9a2a commit 40a6771

File tree

7 files changed

+116
-22
lines changed

7 files changed

+116
-22
lines changed

src/getCurrentConnectionFromPortal.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ export const getCurrentConnectionFromPortal =
2222
return null;
2323
}
2424

25-
const connection = await sdk.getConnectionByIndex(urlInfo.connectionIndex);
25+
const connection = await sdk.getConnectionByIndex(
26+
urlInfo.connectionIndex,
27+
urlInfo.organizationDomain
28+
);
2629
if (!connection) {
2730
return null;
2831
}

src/getCurrentConnectionInfo.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import { DEMO_CONNECTION_INDEX } from './cookies';
33
/**
44
* Information parsed out of the current url.
55
*
6+
* `/o/<organizationDomain>/<connectionIndex>/[product]/[productPath...]`
67
* `/u/<connectionIndex>/[product]/[productPath...]`
78
*/
89
export type ConnectionInfo = {
910
connectionIndex: number;
11+
organizationDomain?: string;
1012

1113
/** an optional string like "designer" | "explorer" | "studio" */
1214
product?: string;
@@ -17,19 +19,30 @@ export type ConnectionInfo = {
1719
productPath?: string;
1820
};
1921

22+
// ORGANIZATION_SEARCH = re.compile(r"/o/([^/]+)/([0-9]+)/.*")
23+
// CONNECTION_SEARCH = re.compile(r"/u/([0-9]+)/.*")
24+
2025
/** returns info on the current Portal/Cloud connection */
2126
export const getCurrentConnectionInfo = (
2227
window: Window
2328
): ConnectionInfo | null => {
24-
const connectionIndexMatch = window.location.pathname.match(
29+
const publicOrgMatch = window.location.pathname.match(
30+
/^\/o\/([^/]+)\/([0-9]+|demo)(?:\/(.*))?$/
31+
);
32+
const personalOrgMatch = window.location.pathname.match(
2533
/^\/u\/([0-9]+|demo)(?:\/(.*))?$/
2634
);
35+
36+
const connectionIndexMatch = publicOrgMatch?.[2] || personalOrgMatch?.[1];
37+
2738
if (!connectionIndexMatch) {
2839
return null;
2940
}
3041

42+
const organizationDomain = publicOrgMatch?.[1] || undefined;
43+
3144
const connectionIndex = Number.parseInt(
32-
connectionIndexMatch[1].replace('demo', DEMO_CONNECTION_INDEX.toString())
45+
connectionIndexMatch.replace('demo', DEMO_CONNECTION_INDEX.toString())
3346
);
3447
const connectionIndexExtra = connectionIndexMatch[2];
3548

@@ -39,6 +52,7 @@ export const getCurrentConnectionInfo = (
3952

4053
return {
4154
connectionIndex,
55+
organizationDomain,
4256
product,
4357
productPath,
4458
};

src/getPortalSdk.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ export const getPortalSdk = () => {
5858
const result = await sdk.addShare({ input });
5959
return result.addShare || null;
6060
},
61-
getConnectionByIndex: async (index: number) => {
62-
const result = await sdk.getConnectionByIndex({ index });
61+
getConnectionByIndex: async (index: number, org: string | undefined) => {
62+
const result = await sdk.getConnectionByIndex({ index, org });
6363
return result.connection || null;
6464
},
6565
createDesignerProject: async (
@@ -134,8 +134,8 @@ export const getPortalSdk = () => {
134134
) || [],
135135
};
136136
},
137-
listConnections: async () => {
138-
const result = await sdk.listConnections();
137+
listConnections: async (org: string | undefined) => {
138+
const result = await sdk.listConnections({ org });
139139
if (!result.listConnections) {
140140
return null;
141141
}
@@ -146,6 +146,18 @@ export const getPortalSdk = () => {
146146
connection !== null
147147
);
148148
},
149+
listOrganizations: async () => {
150+
const result = await sdk.listOrganizations();
151+
if (!result.listOrganizations) {
152+
return null;
153+
}
154+
return result.listOrganizations.filter(
155+
(
156+
organization
157+
): organization is NonNullable<(typeof result.listOrganizations)[0]> =>
158+
organization !== null
159+
);
160+
},
149161
listVoiceboxConversations: async () => {
150162
const result = await sdk.listVoiceboxConversations();
151163
if (!result.listVoiceboxConversations) {

src/sdk/documents/getConnectionByIndexQuery.graphql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
query getConnectionByIndex($index: Int!) {
2-
connection: getConnectionByIndex(index: $index) {
1+
query getConnectionByIndex($index: Int!, $org: String) {
2+
connection: getConnectionByIndex(index: $index, org: $org) {
33
# getCurrentConnectionFromPortal
44
token
55
username

src/sdk/documents/listConnectionsQuery.graphql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
query listConnections {
2-
listConnections {
1+
query listConnections($org: String) {
2+
listConnections(org: $org) {
33
# same fields as getConnectionByIndex
44
dashboard
55
endpoint
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
query listOrganizations {
2+
listOrganizations {
3+
id
4+
name
5+
domain
6+
}
7+
}

src/sdk/index.ts

Lines changed: 69 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export type Connection = {
149149
isStardogFree?: Maybe<Scalars['Boolean']>;
150150
isWaitingForPayment?: Maybe<Scalars['Boolean']>;
151151
name: Scalars['String'];
152+
org_domain?: Maybe<Scalars['String']>;
152153
shouldShowDesigner?: Maybe<Scalars['Boolean']>;
153154
stripeSubscription?: Maybe<PurchaseSession>;
154155
stripeSubscriptionOrder?: Maybe<ProvisionedOrder>;
@@ -158,7 +159,6 @@ export type Connection = {
158159
useBrowserAuth?: Maybe<Scalars['Boolean']>;
159160
useConnectionSSO?: Maybe<Scalars['Boolean']>;
160161
useSSO?: Maybe<Scalars['Boolean']>;
161-
user?: Maybe<User>;
162162
username?: Maybe<Scalars['String']>;
163163
};
164164

@@ -402,6 +402,7 @@ export type MutationAcceptInvitationArgs = {
402402
/** Root Mutation Type */
403403
export type MutationAddConnectionArgs = {
404404
input: AddConnectionInput;
405+
org?: InputMaybe<Scalars['String']>;
405406
};
406407

407408
/** Root Mutation Type */
@@ -470,7 +471,8 @@ export type MutationDeleteCloudArgs = {
470471

471472
/** Root Mutation Type */
472473
export type MutationDeleteConnectionArgs = {
473-
name: Scalars['String'];
474+
id: Scalars['String'];
475+
org?: InputMaybe<Scalars['String']>;
474476
};
475477

476478
/** Root Mutation Type */
@@ -491,6 +493,7 @@ export type MutationEditApiTokenArgs = {
491493
/** Root Mutation Type */
492494
export type MutationEditConnectionArgs = {
493495
input: EditConnectionInput;
496+
org?: InputMaybe<Scalars['String']>;
494497
};
495498

496499
/** Root Mutation Type */
@@ -614,6 +617,13 @@ export type OktaProvider = {
614617
customerName: Scalars['String'];
615618
};
616619

620+
export type Organization = {
621+
__typename?: 'Organization';
622+
domain?: Maybe<Scalars['String']>;
623+
id: Scalars['ID'];
624+
name: Scalars['String'];
625+
};
626+
617627
/** To page through response. */
618628
export type PagingInput = {
619629
limit?: InputMaybe<Scalars['Int']>;
@@ -681,7 +691,7 @@ export type Query = {
681691
customerSsoSettings?: Maybe<CustomerSsoSettings>;
682692
generateToken?: Maybe<OAuthToken>;
683693
getCloudReport?: Maybe<CloudReportData>;
684-
getConnection?: Maybe<Connection>;
694+
getConnectionById?: Maybe<Connection>;
685695
getConnectionByIndex?: Maybe<Connection>;
686696
/** Retrieve a single Designer project. */
687697
getDesignerProject: DesignerProject;
@@ -712,6 +722,7 @@ export type Query = {
712722
listConnections?: Maybe<Array<Maybe<Connection>>>;
713723
listConnectionsByEndpoint?: Maybe<Array<Maybe<Connection>>>;
714724
listInactiveClouds?: Maybe<Array<Maybe<StardogCloud>>>;
725+
listOrganizations?: Maybe<Array<Maybe<Organization>>>;
715726
listStardogCloud?: Maybe<Array<Maybe<StardogCloud>>>;
716727
/** Retrieve Voicebox Applications owned by the authenticated user. */
717728
listVoiceboxApps?: Maybe<Array<Maybe<VoiceboxApp>>>;
@@ -741,7 +752,7 @@ export type QueryApiTokenCountArgs = {
741752

742753
/** Root Query Type */
743754
export type QueryGenerateTokenArgs = {
744-
endpoint: Scalars['String'];
755+
connection_id: Scalars['String'];
745756
};
746757

747758
/** Root Query Type */
@@ -750,13 +761,15 @@ export type QueryGetCloudReportArgs = {
750761
};
751762

752763
/** Root Query Type */
753-
export type QueryGetConnectionArgs = {
754-
name: Scalars['String'];
764+
export type QueryGetConnectionByIdArgs = {
765+
id: Scalars['String'];
766+
org?: InputMaybe<Scalars['String']>;
755767
};
756768

757769
/** Root Query Type */
758770
export type QueryGetConnectionByIndexArgs = {
759771
index: Scalars['Int'];
772+
org?: InputMaybe<Scalars['String']>;
760773
};
761774

762775
/** Root Query Type */
@@ -826,9 +839,15 @@ export type QueryListApiTokensArgs = {
826839
paging?: InputMaybe<PagingInput>;
827840
};
828841

842+
/** Root Query Type */
843+
export type QueryListConnectionsArgs = {
844+
org?: InputMaybe<Scalars['String']>;
845+
};
846+
829847
/** Root Query Type */
830848
export type QueryListConnectionsByEndpointArgs = {
831849
endpoint: Scalars['String'];
850+
org?: InputMaybe<Scalars['String']>;
832851
};
833852

834853
/** Root Query Type */
@@ -1195,6 +1214,7 @@ export type CreateDesignerProjectMutation = {
11951214

11961215
export type GetConnectionByIndexQueryVariables = Exact<{
11971216
index: Scalars['Int'];
1217+
org?: InputMaybe<Scalars['String']>;
11981218
}>;
11991219

12001220
export type GetConnectionByIndexQuery = {
@@ -1296,7 +1316,9 @@ export type GetVoiceboxConversationQuery = {
12961316
} | null;
12971317
};
12981318

1299-
export type ListConnectionsQueryVariables = Exact<{ [key: string]: never }>;
1319+
export type ListConnectionsQueryVariables = Exact<{
1320+
org?: InputMaybe<Scalars['String']>;
1321+
}>;
13001322

13011323
export type ListConnectionsQuery = {
13021324
__typename?: 'Query';
@@ -1312,6 +1334,18 @@ export type ListConnectionsQuery = {
13121334
} | null> | null;
13131335
};
13141336

1337+
export type ListOrganizationsQueryVariables = Exact<{ [key: string]: never }>;
1338+
1339+
export type ListOrganizationsQuery = {
1340+
__typename?: 'Query';
1341+
listOrganizations?: Array<{
1342+
__typename?: 'Organization';
1343+
id: string;
1344+
name: string;
1345+
domain?: string | null;
1346+
} | null> | null;
1347+
};
1348+
13151349
export type ListVoiceboxConversationsQueryVariables = Exact<{
13161350
paging?: InputMaybe<PagingInput>;
13171351
}>;
@@ -1435,8 +1469,8 @@ export const CreateDesignerProjectDocument = `
14351469
}
14361470
`;
14371471
export const GetConnectionByIndexDocument = `
1438-
query getConnectionByIndex($index: Int!) {
1439-
connection: getConnectionByIndex(index: $index) {
1472+
query getConnectionByIndex($index: Int!, $org: String) {
1473+
connection: getConnectionByIndex(index: $index, org: $org) {
14401474
token
14411475
username
14421476
endpoint
@@ -1526,8 +1560,8 @@ export const GetVoiceboxConversationDocument = `
15261560
}
15271561
`;
15281562
export const ListConnectionsDocument = `
1529-
query listConnections {
1530-
listConnections {
1563+
query listConnections($org: String) {
1564+
listConnections(org: $org) {
15311565
dashboard
15321566
endpoint
15331567
id
@@ -1538,6 +1572,15 @@ export const ListConnectionsDocument = `
15381572
}
15391573
}
15401574
`;
1575+
export const ListOrganizationsDocument = `
1576+
query listOrganizations {
1577+
listOrganizations {
1578+
id
1579+
name
1580+
domain
1581+
}
1582+
}
1583+
`;
15411584
export const ListVoiceboxConversationsDocument = `
15421585
query listVoiceboxConversations($paging: PagingInput) {
15431586
listVoiceboxConversations(paging: $paging) {
@@ -1749,6 +1792,21 @@ export function getSdk(
17491792
'query'
17501793
);
17511794
},
1795+
listOrganizations(
1796+
variables?: ListOrganizationsQueryVariables,
1797+
requestHeaders?: Dom.RequestInit['headers']
1798+
): Promise<ListOrganizationsQuery> {
1799+
return withWrapper(
1800+
(wrappedRequestHeaders) =>
1801+
client.request<ListOrganizationsQuery>(
1802+
ListOrganizationsDocument,
1803+
variables,
1804+
{ ...requestHeaders, ...wrappedRequestHeaders }
1805+
),
1806+
'listOrganizations',
1807+
'query'
1808+
);
1809+
},
17521810
listVoiceboxConversations(
17531811
variables?: ListVoiceboxConversationsQueryVariables,
17541812
requestHeaders?: Dom.RequestInit['headers']

0 commit comments

Comments
 (0)