@mindline/sync 1.0.39 → 1.0.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,5 @@
2
2
  "ExpandedNodes": [
3
3
  ""
4
4
  ],
5
- "SelectedNode": "\\index.ts",
6
5
  "PreviewInSolutionExplorer": false
7
6
  }
package/.vs/slnx.sqlite CHANGED
Binary file
Binary file
package/hybridspa.ts CHANGED
@@ -51,7 +51,8 @@ export const graphConfig = {
51
51
  authorityCNRegex: /^(https:\/\/login\.partner\.microsoftonline\.cn\/)([\dA-Fa-f]{8}-[\dA-Fa-f]{4}-[\dA-Fa-f]{4}-[\dA-Fa-f]{4}-[\dA-Fa-f]{12})\/oauth2\/authorize$/,
52
52
  };
53
53
  // helper functions
54
- async function defineHeaders(
54
+ // TODO: this is where you want to trigger a re-authentication if token expires
55
+ export async function defineHeaders(
55
56
  instance: IPublicClientApplication,
56
57
  user: User
57
58
  ): Promise<Headers> {
@@ -758,16 +759,8 @@ export async function tenantPut(
758
759
  let tenantEndpoint: string = graphConfig.tenantEndpoint;
759
760
  // create tenant headers
760
761
  const headers = await defineHeaders(instance, authorizedUser);
761
- // be sure we send null and not "null" in body
762
- let readAccessToken: string = tenant.readServicePrincipal
763
- ? `"${tenant.readServicePrincipal}"`
764
- : "null";
765
- let writeAccessToken: string = tenant.writeServicePrincipal
766
- ? `"${tenant.writeServicePrincipal}"`
767
- : "null";
768
762
  // create tenant body
769
- let tenantBody: string = `
770
- {"tenantId": "${tenant.tid}", "readServicePrincipal": ${readAccessToken}, "writeServicePrincipal": ${writeAccessToken}}`;
763
+ let tenantBody: string = `{"tenantId": "${tenant.tid}"}`;
771
764
  let options = { method: "PUT", headers: headers, body: tenantBody };
772
765
  // make tenant endpoint call
773
766
  try {
package/index.d.ts CHANGED
@@ -50,8 +50,6 @@ declare module "@mindline/sync" {
50
50
  permissionType: TenantPermissionTypeStrings; // read/write/notassigned
51
51
  onboarded: string; // have we onboarded this tenant? "true" or "false"
52
52
  authority: string; // from AAD ID auth response
53
- readServicePrincipal: string; // from AAD consent
54
- writeServicePrincipal: string; // from AAD consent
55
53
  workspaceIDs: string;
56
54
  constructor();
57
55
  }
@@ -219,15 +217,14 @@ declare module "@mindline/sync" {
219
217
  //
220
218
  // Azure AD Graph API
221
219
  //
222
- export function groupGet(tenant: Tenant, groupid: string): Promise<{group: string, error: string}>;
223
- export function groupsGet(tenant: Tenant, groupSearchString: string): Promise<{groups: Group[], error: string}>;
220
+ export function groupsGet(instance: IPublicClientApplication, user: User | undefined, groupSearchString: string): Promise<{groups: Group[], error: string}>;
224
221
  export function signIn(user: User, tasks: TaskArray): void;
225
222
  export function signInIncrementally(user: User, scope: string): void;
226
223
  export function signOut(user: User): void;
227
224
  export function tenantRelationshipsGetByDomain(loggedInuser: User, tenant: Tenant, instance: IPublicClientApplication, debug: boolean): boolean;
228
225
  export function tenantRelationshipsGetById(user: User, ii: InitInfo, instance: IPublicClientApplication, tasks: TaskArray, debug: boolean): boolean;
229
226
  export function tenantUnauthenticatedLookup(tenant: Tenant, debug: boolean): Promise<boolean>;
230
- export function usersGet(tenant: Tenant): { users: string[], error: string };
227
+ export function usersGet(instance: IPublicClientApplication, user: User | undefined): { users: string[], error: string };
231
228
  //
232
229
  // Mindline Config API
233
230
  //
package/index.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  import * as signalR from "@microsoft/signalr"
3
3
  import { IPublicClientApplication, AuthenticationResult } from "@azure/msal-browser"
4
4
  import { deserializeArray, instanceToPlain, ClassTransformOptions } from 'class-transformer';
5
- import { adminDelete, adminPost, adminsGet, configDelete, configsGet, configPost, configPut, graphConfig, initPost, readerPost, tenantPut, tenantPost, tenantDelete, tenantsGet, workspacesGet } from './hybridspa';
5
+ import { defineHeaders, adminDelete, adminPost, adminsGet, configDelete, configsGet, configPost, configPut, graphConfig, initPost, readerPost, tenantPut, tenantPost, tenantDelete, tenantsGet, workspacesGet } from './hybridspa';
6
6
  import { version } from './package.json';
7
7
  import users from "./users.json";
8
8
  import tenants from "./tenants.json";
@@ -79,8 +79,6 @@ export class Tenant {
79
79
  permissionType: TenantPermissionTypeStrings;
80
80
  onboarded: string;
81
81
  authority: string;
82
- readServicePrincipal: string;
83
- writeServicePrincipal: string;
84
82
  workspaceIDs: string;
85
83
  constructor() {
86
84
  this.tid = "";
@@ -90,8 +88,6 @@ export class Tenant {
90
88
  this.permissionType = "notassigned";
91
89
  this.onboarded = "false";
92
90
  this.authority = "";
93
- this.readServicePrincipal = "";
94
- this.writeServicePrincipal = "";
95
91
  this.workspaceIDs = "";
96
92
  }
97
93
  }
@@ -1026,48 +1022,14 @@ export class APIResult {
1026
1022
  //
1027
1023
  // Azure AD Graph API
1028
1024
  //
1029
- //groupGet - GET /groups/{id}
1030
- export async function groupGet(tenant: Tenant, groupid: string): Promise<{ group: string, error: string }> {
1031
- // need a read or write access token to get graph users
1032
- let accessToken: string = "";
1033
- if (tenant.permissionType === TenantPermissionType[TenantPermissionType.read])
1034
- accessToken = tenant.readServicePrincipal;
1035
- if (tenant.permissionType === TenantPermissionType[TenantPermissionType.write])
1036
- accessToken = tenant.writeServicePrincipal;
1037
- if (accessToken === "") return { group: "", error: "no access token specified" };
1038
- // prepare Authorization headers as part of options
1039
- const headers = new Headers();
1040
- const bearer = `Bearer ${accessToken}`;
1041
- headers.append("Authorization", bearer);
1042
- let options = { method: "GET", headers: headers };
1043
- // make /groups endpoint call
1044
- try {
1045
- let groupsEndpoint = `${graphConfig.graphGroupsEndpoint}/${groupid}`;
1046
- let response = await fetch(groupsEndpoint, options);
1047
- let data = await response.json();
1048
- if (typeof data.error !== "undefined") {
1049
- return { group: "", error: `${data.error.code}: ${data.error.message}` };
1050
- }
1051
- return { group: data.value, error: `` };
1052
- }
1053
- catch (error: any) {
1054
- console.log(error);
1055
- return { group: "", error: `Exception: ${error}` };
1056
- }
1057
- }
1058
1025
  //groupsGet - GET /groups
1059
- export async function groupsGet(tenant: Tenant, groupSearchString: string): Promise<{ groups: Group[], error: string }> {
1060
- // need a read or write access token to get graph users
1061
- let accessToken: string = "";
1062
- if (tenant.permissionType === TenantPermissionType[TenantPermissionType.read])
1063
- accessToken = tenant.readServicePrincipal;
1064
- if (tenant.permissionType === TenantPermissionType[TenantPermissionType.write])
1065
- accessToken = tenant.writeServicePrincipal;
1066
- if (accessToken === "") return { groups: [], error: "no access token specified" };
1067
- // prepare Authorization headers as part of options
1068
- const headers = new Headers();
1069
- const bearer = `Bearer ${accessToken}`;
1070
- headers.append("Authorization", bearer);
1026
+ export async function groupsGet(instance: IPublicClientApplication, user: User | undefined, groupSearchString: string): Promise<{ groups: Group[], error: string }> {
1027
+ // need a logged in user to get graph users
1028
+ if (user == null || user.spacode == "") {
1029
+ return { groups: [], error: `500: invalid user passed to groupsGet` };
1030
+ }
1031
+ // create headers
1032
+ const headers = await defineHeaders(instance, user);
1071
1033
  let options = { method: "GET", headers: headers };
1072
1034
  // make /groups endpoint call
1073
1035
  try {
@@ -1081,7 +1043,7 @@ export async function groupsGet(tenant: Tenant, groupSearchString: string): Prom
1081
1043
  }
1082
1044
  catch (error: any) {
1083
1045
  console.log(error);
1084
- return { group: "", error: `Exception: ${error}` };
1046
+ return { groups: [], error: `Exception: ${error}` };
1085
1047
  }
1086
1048
  }
1087
1049
  export function signIn(user: User, tasks: TaskArray): void {
@@ -1295,18 +1257,13 @@ export async function tenantUnauthenticatedLookup(tenant: Tenant, debug: boolean
1295
1257
  return false; // failed, no need for UX to re-render
1296
1258
  }
1297
1259
  //usersGet - GET from AAD Users endpoint
1298
- export async function usersGet(tenant: Tenant): Promise<{ users: string[], error: string }> {
1299
- // need a read or write access token to get graph users
1300
- let accessToken: string = "";
1301
- if (tenant.permissionType === TenantPermissionType[TenantPermissionType.read])
1302
- accessToken = tenant.readServicePrincipal;
1303
- if (tenant.permissionType === TenantPermissionType[TenantPermissionType.write])
1304
- accessToken = tenant.writeServicePrincipal;
1305
- if (accessToken === "") return { users: [], error: "no access token specified" };
1306
- // prepare Authorization headers as part of options
1307
- const headers = new Headers();
1308
- const bearer = `Bearer ${accessToken}`;
1309
- headers.append("Authorization", bearer);
1260
+ export async function usersGet(instance: IPublicClientApplication, user: User | undefined): Promise<{ users: string[], error: string }> {
1261
+ // need a logged in user to get graph users
1262
+ if (user == null || user.spacode == "") {
1263
+ return { users: [], error: `500: invalid user passed to groupsGet` };
1264
+ }
1265
+ // create headers
1266
+ const headers = await defineHeaders(instance, user);
1310
1267
  let options = { method: "GET", headers: headers };
1311
1268
  // make /users endpoint call
1312
1269
  try {
@@ -1315,7 +1272,7 @@ export async function usersGet(tenant: Tenant): Promise<{ users: string[], error
1315
1272
  if (typeof data.error !== "undefined") {
1316
1273
  return { users: [], error: `${data.error.code}: ${data.error.message}` };
1317
1274
  }
1318
- let users = new Array<User>();
1275
+ let users = new Array<string>();
1319
1276
  for (let user of data.value) {
1320
1277
  users.push(user.mail);
1321
1278
  }
@@ -1496,8 +1453,6 @@ function processReturnedTenants(workspace: Workspace, ii: InitInfo, returnedTena
1496
1453
  const regexMatch = item.authority.match(regex);
1497
1454
  tenant.authority = regexMatch ? regexMatch[1] : item.authority;
1498
1455
 
1499
- tenant.readServicePrincipal = item.readServicePrincipal;
1500
- tenant.writeServicePrincipal = item.writeServicePrincipal;
1501
1456
  // ensure this workspace tracks this tenant
1502
1457
  let idx = workspace.associatedTenants.findIndex((t) => t === item.tenantId);
1503
1458
  if (idx == -1) workspace.associatedTenants.push(item.tenantId);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mindline/sync",
3
3
  "type": "module",
4
- "version": "1.0.39",
4
+ "version": "1.0.40",
5
5
  "types": "index.d.ts",
6
6
  "exports": "./index.ts",
7
7
  "description": "sync is a node.js package encapsulating javscript classes required for configuring Mindline sync service.",
package/tenants.json CHANGED
@@ -6,8 +6,6 @@
6
6
  "tenantType": "",
7
7
  "permissionType": "",
8
8
  "onboarded": false,
9
- "authority": "",
10
- "readServicePrincipal": "",
11
- "writeServicePrincipal": ""
9
+ "authority": ""
12
10
  }
13
11
  ]
package/tenants2.json CHANGED
@@ -4,53 +4,41 @@
4
4
  "name": "Mindline1",
5
5
  "domain": "mindline1.onmicrosoft.com",
6
6
  "tenantType": "aad",
7
- "authority": "https://login.microsoftonline.com/common/",
8
- "readServicePrincipal": "TODO",
9
- "writeServicePrincipal": "TODO"
7
+ "authority": "https://login.microsoftonline.com/common/"
10
8
  },
11
9
  {
12
10
  "tid": "df9c2e0a-f6fe-43bb-a155-d51f66dffe0e",
13
11
  "name": "Mindline2",
14
12
  "domain": "mindline2.onmicrosoft.com",
15
13
  "tenantType": "aad",
16
- "authority": "https://login.microsoftonline.com/common/",
17
- "readServicePrincipal": "TODO",
18
- "writeServicePrincipal": "TODO"
14
+ "authority": "https://login.microsoftonline.com/common/"
19
15
  },
20
16
  {
21
17
  "tid": "1",
22
18
  "name": "WhoIam",
23
19
  "domain": "whoiam.onmicrosoft.com",
24
20
  "tenantType": "aad",
25
- "authority": "https://login.microsoftonline.com/common/",
26
- "readServicePrincipal": "TODO",
27
- "writeServicePrincipal": "TODO"
21
+ "authority": "https://login.microsoftonline.com/common/"
28
22
  },
29
23
  {
30
24
  "tid": "2",
31
25
  "name": "Grit Software",
32
26
  "domain": "gritsoftware.onmicrosoft.com",
33
27
  "tenantType": "aad",
34
- "authority": "https://login.microsoftonline.com/common/",
35
- "readServicePrincipal": "TODO",
36
- "writeServicePrincipal": "TODO"
28
+ "authority": "https://login.microsoftonline.com/common/"
37
29
  },
38
30
  {
39
31
  "tid": "3",
40
32
  "name": "Google",
41
33
  "domain": "google.onmicrosoft.com",
42
34
  "tenantType": "aad",
43
- "authority": "https://login.microsoftonline.com/common/",
44
- "readServicePrincipal": "TODO",
45
- "writeServicePrincipal": "TODO"
35
+ "authority": "https://login.microsoftonline.com/common/"
46
36
  },
47
37
  {
48
38
  "tid": "4",
49
39
  "name": "Trackman Golf",
50
40
  "domain": "trackman.onmicrosoft.com",
51
41
  "tenantType": "aad",
52
- "authority": "https://login.microsoftonline.com/common/",
53
- "readServicePrincipal": "TODO",
54
- "writeServicePrincipal": "TODO"
42
+ "authority": "https://login.microsoftonline.com/common/"
55
43
  }
56
44
  ]