@mindline/sync 1.0.38 → 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.d.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
  }
@@ -160,12 +158,12 @@ declare module "@mindline/sync" {
160
158
  constructor(bClearLocalStorage: boolean);
161
159
  init(bClearLocalStorage: boolean): void;
162
160
  save(): void;
163
- start(setMilestones): void;
164
- unstart(setMilestones): void;
165
- post(setMilestones): void;
166
- read(setMilestones): void;
167
- write(setMilestones): void;
168
- #initFromObjects(milestones: Milestones): void;
161
+ start(setMilestones: (milestones: Milestone[]) => void): void;
162
+ unstart(setMilestones: (milestones: Milestone[]) => void): void;
163
+ post(setMilestones: (milestones: Milestone[]) => void): void;
164
+ read(setMilestones: (milestones: Milestone[]) => void): void;
165
+ write(setMilestones: (milestones: Milestone[]) => void): void;
166
+ #initFromObjects(milestones: Object[]): void;
169
167
  }
170
168
  export class BatchArray {
171
169
  tenantNodes: TenantNode[];
@@ -174,24 +172,24 @@ declare module "@mindline/sync" {
174
172
  pb_increment: number;
175
173
  pb_idle: number;
176
174
  pb_idleMax: number;
177
- pb_timer;
175
+ pb_timer: NodeJS.Timer;
178
176
  milestoneArray: MilestoneArray;
179
177
  constructor(config: Config|null, syncPortalGlobalState: InitInfo|null, bClearLocalStorage: boolean);
180
178
  // populate tenantNodes based on config tenants
181
179
  init(config: Config|null|undefined, syncPortalGlobalState: InitInfo|null, bClearLocalStorage: boolean): void;
182
- initializeProgressBar(setSyncProgress, setConfigSyncResult, setIdleText, setMilestones): void;
183
- uninitializeProgressBar(setSyncProgress, setConfigSyncResult, setIdleText, setMilestones): void;
180
+ initializeProgressBar(setSyncProgress: (progress: number) => void, setConfigSyncResult: (result: string) => void, setIdleText: (idleText: string) => void, setMilestones: (milestones: Milestone[]) => void): void;
181
+ uninitializeProgressBar(setSyncProgress: (progress: number) => void, setConfigSyncResult: (result: string) => void, setIdleText: (idleText: string) => void, setMilestones: (milestones: Milestone[]) => void): void;
184
182
  initializeSignalR(
185
183
  config: Config | null | undefined,
186
184
  syncPortalGlobalState: InitInfo | null,
187
185
  batchIdArray: Array<Object>,
188
- setRefreshDeltaTrigger,
189
- setReadersTotal,
190
- setReadersCurrent,
191
- setWritersTotal,
192
- setWritersCurrent,
193
- setMilestones,
194
- setConfigSyncResult,
186
+ setRefreshDeltaTrigger: (trigger: boolean) => void,
187
+ setReadersTotal: (readersTotal: number) => void,
188
+ setReadersCurrent: (readersCurrent: number) => void,
189
+ setWritersTotal: (writersTotal: number) => void,
190
+ setWritersCurrent: (writersCurrent: number) => void,
191
+ setMilestones: (milestones: Milestone[]) => void,
192
+ setConfigSyncResult: (result: string) => void,
195
193
  bClearLocalStorage: boolean): void;
196
194
  startSync(instance: IPublicClientApplication, authorizedUser: User | null | undefined, config: Config | null | undefined): APIResult;
197
195
  }
@@ -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
  }
@@ -518,7 +514,7 @@ export class MilestoneArray {
518
514
  }
519
515
  }
520
516
  // milestone tracking during a sync
521
- start(setMilestones): void {
517
+ start(setMilestones: (milestones: Milestone[]) => void): void {
522
518
  // we should always have a milestone array and a first milestone
523
519
  if (this.milestones == null || this.milestones.length < 1) { debugger; return; }
524
520
  let currentRun: number = Number(this.milestones[0].Run);
@@ -543,7 +539,7 @@ export class MilestoneArray {
543
539
  setMilestones(this.milestones);
544
540
  console.log(`Start milestone: ${this.milestones[0].Run}:${this.milestones[0].Start}`);
545
541
  }
546
- unstart(setMilestones): void {
542
+ unstart(setMilestones: (milestones: Milestone[]) => void): void {
547
543
  // we should always have a milestone array and a first milestone
548
544
  if (this.milestones == null || this.milestones.length < 1) { debugger; return; }
549
545
  let currentRun: number = Number(this.milestones[0].Run);
@@ -567,20 +563,20 @@ export class MilestoneArray {
567
563
  setMilestones(this.milestones);
568
564
  console.log(`Unstart removed first milestone: ${removedMilestone.Run}:${removedMilestone.Start}`);
569
565
  }
570
- post(setMilestones): void {
566
+ post(setMilestones: (milestones: Milestone[]) => void): void {
571
567
  // update the post value of the first milestone
572
568
  if (this.milestones == null || this.milestones.length < 1) { debugger; return; }
573
569
  this.milestones[0].post("");
574
570
  setMilestones(this.milestones);
575
571
  console.log(`POST milestone: ${this.milestones[0].Run}:${this.milestones[0].POST}`);
576
572
  }
577
- read(setMilestones): void {
573
+ read(setMilestones: (milestones: Milestone[]) => void): void {
578
574
  if (this.milestones == null || this.milestones.length < 1) { debugger; return; }
579
575
  this.milestones[0].read("");
580
576
  setMilestones(this.milestones);
581
577
  console.log(`Read milestone: ${this.milestones[0].Run}:${this.milestones[0].Read}`);
582
578
  }
583
- write(setMilestones): void {
579
+ write(setMilestones: (milestones: Milestone[]) => void): void {
584
580
  if (this.milestones == null || this.milestones.length < 1) { debugger; return; }
585
581
  this.milestones[0].write("");
586
582
  // while we have >10 complete milestones, remove the last
@@ -630,7 +626,7 @@ export class BatchArray {
630
626
  pb_increment: number;
631
627
  pb_idle: number;
632
628
  pb_idleMax: number;
633
- pb_timer;
629
+ pb_timer: NodeJS.Timer;
634
630
  milestoneArray: MilestoneArray;
635
631
  constructor(
636
632
  config: Config | null,
@@ -642,7 +638,7 @@ export class BatchArray {
642
638
  this.pb_startTS = 0;
643
639
  this.pb_progress = 0;
644
640
  this.pb_increment = 0;
645
- this.pb_timer = 0;
641
+ this.pb_timer = null;
646
642
  this.pb_idle = 0;
647
643
  this.pb_idleMax = 0;
648
644
  this.milestoneArray = new MilestoneArray(false);
@@ -728,7 +724,7 @@ export class BatchArray {
728
724
  });
729
725
  }
730
726
  }
731
- initializeProgressBar(setSyncProgress, setConfigSyncResult, setIdleText, setMilestones): void {
727
+ initializeProgressBar(setSyncProgress: (progress: number) => void, setConfigSyncResult: (result: string) => void, setIdleText: (idleText: string) => void, setMilestones: (milestones: Milestone[]) => void): void {
732
728
  this.pb_startTS = Date.now();
733
729
  this.pb_progress = 0;
734
730
  this.pb_increment = 1;
@@ -742,6 +738,7 @@ export class BatchArray {
742
738
  setIdleText(`No updates seen for ${this.pb_idle} seconds. [max idle: ${this.pb_idleMax}]`);
743
739
  if (this.pb_idle >= 20) {
744
740
  clearInterval(this.pb_timer);
741
+ this.pb_timer = null;
745
742
  if (this.milestoneArray.milestones[0].Write == null) {
746
743
  this.milestoneArray.write(setMilestones);
747
744
  }
@@ -755,14 +752,14 @@ export class BatchArray {
755
752
  }, 1000);
756
753
  this.milestoneArray.start(setMilestones);
757
754
  }
758
- uninitializeProgressBar(setSyncProgress, setConfigSyncResult, setIdleText, setMilestones): void {
755
+ uninitializeProgressBar(setSyncProgress: (progress: number) => void, setConfigSyncResult: (result: string) => void, setIdleText: (idleText: string) => void, setMilestones: (milestones: Milestone[]) => void): void {
759
756
  this.pb_startTS = 0;
760
757
  this.pb_progress = 0;
761
758
  setSyncProgress(this.pb_progress);
762
759
  setConfigSyncResult("sync failed to execute");
763
760
  this.pb_increment = 0;
764
761
  clearInterval(this.pb_timer);
765
- this.pb_timer = 0;
762
+ this.pb_timer = null;
766
763
  this.pb_idle = 0;
767
764
  this.pb_idleMax = 0;
768
765
  setIdleText(`No updates seen for ${this.pb_idle} seconds. [max idle: ${this.pb_idleMax}]`);
@@ -772,13 +769,13 @@ export class BatchArray {
772
769
  config: Config | null | undefined,
773
770
  syncPortalGlobalState: InitInfo | null,
774
771
  batchIdArray: Array<Object>,
775
- setRefreshDeltaTrigger,
776
- setReadersTotal,
777
- setReadersCurrent,
778
- setWritersTotal,
779
- setWritersCurrent,
780
- setMilestones,
781
- setConfigSyncResult,
772
+ setRefreshDeltaTrigger: (trigger: boolean) => void,
773
+ setReadersTotal: (readersTotal: number) => void,
774
+ setReadersCurrent: (readersCurrent: number) => void,
775
+ setWritersTotal: (writersTotal: number) => void,
776
+ setWritersCurrent: (writersCurrent: number) => void ,
777
+ setMilestones: (milestones: Milestone[]) => void,
778
+ setConfigSyncResult: (result: string) => void,
782
779
  bClearLocalStorage: boolean
783
780
  ): void {
784
781
  // we have just completed a successful POST to startSync
@@ -1025,48 +1022,14 @@ export class APIResult {
1025
1022
  //
1026
1023
  // Azure AD Graph API
1027
1024
  //
1028
- //groupGet - GET /groups/{id}
1029
- export async function groupGet(tenant: Tenant, groupid: string): Promise<{ group: string, error: string }> {
1030
- // need a read or write access token to get graph users
1031
- let accessToken: string = "";
1032
- if (tenant.permissionType === TenantPermissionType[TenantPermissionType.read])
1033
- accessToken = tenant.readServicePrincipal;
1034
- if (tenant.permissionType === TenantPermissionType[TenantPermissionType.write])
1035
- accessToken = tenant.writeServicePrincipal;
1036
- if (accessToken === "") return { group: "", error: "no access token specified" };
1037
- // prepare Authorization headers as part of options
1038
- const headers = new Headers();
1039
- const bearer = `Bearer ${accessToken}`;
1040
- headers.append("Authorization", bearer);
1041
- let options = { method: "GET", headers: headers };
1042
- // make /groups endpoint call
1043
- try {
1044
- let groupsEndpoint = `${graphConfig.graphGroupsEndpoint}/${groupid}`;
1045
- let response = await fetch(groupsEndpoint, options);
1046
- let data = await response.json();
1047
- if (typeof data.error !== "undefined") {
1048
- return { group: "", error: `${data.error.code}: ${data.error.message}` };
1049
- }
1050
- return { group: data.value, error: `` };
1051
- }
1052
- catch (error: any) {
1053
- console.log(error);
1054
- return { group: "", error: `Exception: ${error}` };
1055
- }
1056
- }
1057
1025
  //groupsGet - GET /groups
1058
- export async function groupsGet(tenant: Tenant, groupSearchString: string): Promise<{ groups: Group[], error: string }> {
1059
- // need a read or write access token to get graph users
1060
- let accessToken: string = "";
1061
- if (tenant.permissionType === TenantPermissionType[TenantPermissionType.read])
1062
- accessToken = tenant.readServicePrincipal;
1063
- if (tenant.permissionType === TenantPermissionType[TenantPermissionType.write])
1064
- accessToken = tenant.writeServicePrincipal;
1065
- if (accessToken === "") return { groups: [], error: "no access token specified" };
1066
- // prepare Authorization headers as part of options
1067
- const headers = new Headers();
1068
- const bearer = `Bearer ${accessToken}`;
1069
- 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);
1070
1033
  let options = { method: "GET", headers: headers };
1071
1034
  // make /groups endpoint call
1072
1035
  try {
@@ -1080,7 +1043,7 @@ export async function groupsGet(tenant: Tenant, groupSearchString: string): Prom
1080
1043
  }
1081
1044
  catch (error: any) {
1082
1045
  console.log(error);
1083
- return { group: "", error: `Exception: ${error}` };
1046
+ return { groups: [], error: `Exception: ${error}` };
1084
1047
  }
1085
1048
  }
1086
1049
  export function signIn(user: User, tasks: TaskArray): void {
@@ -1294,18 +1257,13 @@ export async function tenantUnauthenticatedLookup(tenant: Tenant, debug: boolean
1294
1257
  return false; // failed, no need for UX to re-render
1295
1258
  }
1296
1259
  //usersGet - GET from AAD Users endpoint
1297
- export async function usersGet(tenant: Tenant): Promise<{ users: string[], error: string }> {
1298
- // need a read or write access token to get graph users
1299
- let accessToken: string = "";
1300
- if (tenant.permissionType === TenantPermissionType[TenantPermissionType.read])
1301
- accessToken = tenant.readServicePrincipal;
1302
- if (tenant.permissionType === TenantPermissionType[TenantPermissionType.write])
1303
- accessToken = tenant.writeServicePrincipal;
1304
- if (accessToken === "") return { users: [], error: "no access token specified" };
1305
- // prepare Authorization headers as part of options
1306
- const headers = new Headers();
1307
- const bearer = `Bearer ${accessToken}`;
1308
- 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);
1309
1267
  let options = { method: "GET", headers: headers };
1310
1268
  // make /users endpoint call
1311
1269
  try {
@@ -1314,7 +1272,7 @@ export async function usersGet(tenant: Tenant): Promise<{ users: string[], error
1314
1272
  if (typeof data.error !== "undefined") {
1315
1273
  return { users: [], error: `${data.error.code}: ${data.error.message}` };
1316
1274
  }
1317
- let users = new Array<User>();
1275
+ let users = new Array<string>();
1318
1276
  for (let user of data.value) {
1319
1277
  users.push(user.mail);
1320
1278
  }
@@ -1495,8 +1453,6 @@ function processReturnedTenants(workspace: Workspace, ii: InitInfo, returnedTena
1495
1453
  const regexMatch = item.authority.match(regex);
1496
1454
  tenant.authority = regexMatch ? regexMatch[1] : item.authority;
1497
1455
 
1498
- tenant.readServicePrincipal = item.readServicePrincipal;
1499
- tenant.writeServicePrincipal = item.writeServicePrincipal;
1500
1456
  // ensure this workspace tracks this tenant
1501
1457
  let idx = workspace.associatedTenants.findIndex((t) => t === item.tenantId);
1502
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.38",
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
  ]