@mindline/sync 1.0.44 → 1.0.46

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,5 +2,6 @@
2
2
  "ExpandedNodes": [
3
3
  ""
4
4
  ],
5
+ "SelectedNode": "\\index.ts",
5
6
  "PreviewInSolutionExplorer": false
6
7
  }
package/.vs/slnx.sqlite CHANGED
Binary file
Binary file
package/configs.json CHANGED
@@ -5,6 +5,7 @@
5
5
  "name": "",
6
6
  "description": "",
7
7
  "tenants": [],
8
- "isEnabled": true
8
+ "isEnabled": true,
9
+ "sel": true
9
10
  }
10
11
  ]
package/hybridspa.ts CHANGED
@@ -759,8 +759,25 @@ export async function tenantPut(
759
759
  let tenantEndpoint: string = graphConfig.tenantEndpoint;
760
760
  // create tenant headers
761
761
  const headers = await defineHeaders(instance, authorizedUser);
762
+ // establish read and write service principals ("notassigned" is default")
763
+ let readServicePrincipal: string = "null";
764
+ let writeServicePrincipal: string = "null";
765
+ if (tenant.permissionType == "write") {
766
+ writeServicePrincipal = `"1"`;
767
+ }
768
+ else if (tenant.permissionType == "read") {
769
+ readServicePrincipal = `"1"`;
770
+ }
762
771
  // create tenant body
763
- let tenantBody: string = `{"tenantId": "${tenant.tid}"}`;
772
+ let tenantBody: string = `{"tenantId": "${tenant.tid}",
773
+ "name": "${tenant.name}",
774
+ "domain": "${tenant.domain}",
775
+ "type": "${tenant.tenantType}",
776
+ "permissionType": "${tenant.permissionType}",
777
+ "isOnboarded": ${tenant.onboarded == "true"},
778
+ "authority": "${tenant.authority}",
779
+ "readServicePrincipal": ${readServicePrincipal},
780
+ "writeServicePrincipal": ${writeServicePrincipal}}`;
764
781
  let options = { method: "PUT", headers: headers, body: tenantBody };
765
782
  // make tenant endpoint call
766
783
  try {
package/index.d.ts CHANGED
@@ -33,6 +33,7 @@ declare module "@mindline/sync" {
33
33
  loginHint: string;
34
34
  scopes: string[];
35
35
  authTS: Date;
36
+ sel: boolean; // selection state
36
37
  constructor();
37
38
  }
38
39
  // tenant (Azure AD tenant, AD domain, Google workspace)
@@ -58,6 +59,7 @@ declare module "@mindline/sync" {
58
59
  onboarded: string; // have we onboarded this tenant? "true" or "false"
59
60
  authority: string; // from AAD ID auth response
60
61
  workspaceIDs: string;
62
+ sel: boolean; // selection state
61
63
  constructor();
62
64
  }
63
65
  // config
@@ -87,6 +89,7 @@ declare module "@mindline/sync" {
87
89
  tenants: TenantConfigInfo[];
88
90
  isEnabled: boolean;
89
91
  workspaceIDs: string;
92
+ sel: boolean; // selection state
90
93
  constructor();
91
94
  }
92
95
  // class to group Users, Tenants, and Configs
@@ -96,9 +99,11 @@ declare module "@mindline/sync" {
96
99
  associatedUsers: string[];
97
100
  associatedTenants: string[];
98
101
  associatedConfigs: string[];
102
+ sel: boolean; // selection state
99
103
  constructor();
100
104
  }
101
105
  export class InitInfo {
106
+ tab: number;
102
107
  us: User[];
103
108
  ts: Tenant[];
104
109
  cs: Config[];
package/index.ts CHANGED
@@ -52,6 +52,7 @@ export class User {
52
52
  loginHint: string; // to help sign out without prompt
53
53
  scopes: string[]; // to detect if incremental consent has happened
54
54
  authTS: Date; // timestamp user was authenticated
55
+ sel: boolean; // selection state
55
56
  constructor() {
56
57
  this.oid = "";
57
58
  this.name = "";
@@ -68,6 +69,7 @@ export class User {
68
69
  this.loginHint = "";
69
70
  this.scopes = new Array();
70
71
  this.authTS = new Date(0);
72
+ this.sel = false;
71
73
  }
72
74
  }
73
75
  export enum TenantType {
@@ -92,6 +94,7 @@ export class Tenant {
92
94
  onboarded: string;
93
95
  authority: string;
94
96
  workspaceIDs: string;
97
+ sel: boolean; // selection state
95
98
  constructor() {
96
99
  this.tid = "";
97
100
  this.name = "";
@@ -101,6 +104,7 @@ export class Tenant {
101
104
  this.onboarded = "false";
102
105
  this.authority = "";
103
106
  this.workspaceIDs = "";
107
+ this.sel = false;
104
108
  }
105
109
  }
106
110
  function getGraphEndpoint(authority: string): string {
@@ -149,6 +153,7 @@ export class Config {
149
153
  tenants: TenantConfigInfo[];
150
154
  isEnabled: boolean;
151
155
  workspaceIDs: string;
156
+ sel: boolean; // selection state
152
157
  constructor() {
153
158
  this.id = "";
154
159
  this.name = "";
@@ -156,6 +161,7 @@ export class Config {
156
161
  this.tenants = new Array();
157
162
  this.isEnabled = false;
158
163
  this.workspaceIDs = "";
164
+ this.sel = false;
159
165
  }
160
166
  }
161
167
  export class Workspace {
@@ -164,12 +170,14 @@ export class Workspace {
164
170
  associatedUsers: string[];
165
171
  associatedTenants: string[];
166
172
  associatedConfigs: string[];
173
+ sel: boolean; // selection state
167
174
  constructor() {
168
175
  this.id = "";
169
176
  this.name = "";
170
177
  this.associatedUsers = new Array();
171
178
  this.associatedTenants = new Array();
172
179
  this.associatedConfigs = new Array();
180
+ this.sel = false;
173
181
  }
174
182
  }
175
183
  // check for localStorage availability
@@ -200,6 +208,7 @@ function storageAvailable(type) {
200
208
  }
201
209
  }
202
210
  export class InitInfo {
211
+ tab: number;
203
212
  us: User[];
204
213
  ts: Tenant[];
205
214
  cs: Config[];
@@ -217,7 +226,9 @@ export class InitInfo {
217
226
  let initInfoString: string = result;
218
227
  let iiReadFromLocalStorage: InitInfo = JSON.parse(initInfoString);
219
228
  if (iiReadFromLocalStorage.us.length !== 0) {
220
- if (bClearLocalStorage) { localStorage.removeItem("InitInfo"); }
229
+ if (bClearLocalStorage) {
230
+ localStorage.removeItem("InitInfo");
231
+ }
221
232
  else {
222
233
  this.#initFromObjects(iiReadFromLocalStorage);
223
234
  return;
@@ -225,12 +236,13 @@ export class InitInfo {
225
236
  }
226
237
  }
227
238
  }
228
- // if storage unavailable or we were just asked to clear, read from default files to enable usable UI
239
+ // if storage unavailable or we were just asked to clear, read defaults to enable usable UI
229
240
  var usersString = JSON.stringify(users);
230
241
  var tenantsString = JSON.stringify(tenants);
231
242
  var configsString = JSON.stringify(configs);
232
243
  var workspacesString = JSON.stringify(workspaces);
233
244
  try {
245
+ this.tab = 0;
234
246
  this.us = deserializeArray(User, usersString);
235
247
  this.ts = deserializeArray(Tenant, tenantsString);
236
248
  this.cs = deserializeArray(Config, configsString);
@@ -298,15 +310,82 @@ export class InitInfo {
298
310
  return true;
299
311
  }
300
312
  #initFromObjects(ii: InitInfo): void {
301
- // user array is the only one that has a Date that must be re-created on every read
302
- if (typeof ii.us === "undefined") this.us = new Array();
303
- else this.us = ii.us.map((user: User) => { user.authTS = new Date(user.authTS); return user });
304
- if (typeof ii.ts === "undefined") this.ts = new Array();
305
- else this.ts = ii.ts;
306
- if (typeof ii.cs === "undefined") this.cs = new Array();
307
- else this.cs = ii.cs;
308
- if (typeof ii.ws === "undefined") this.ws = new Array();
309
- else this.ws = ii.ws;
313
+ this.tab = ii.tab;
314
+ if (typeof ii.us === "undefined") {
315
+ this.us = new Array<User>();
316
+ }
317
+ else {
318
+ this.us = ii.us.map((user: User) => {
319
+ let newuser: User = new User();
320
+ newuser.oid = user.oid;
321
+ newuser.name = user.name;
322
+ newuser.mail = user.mail;
323
+ newuser.authority = user.authority;
324
+ newuser.tid = user.tid;
325
+ newuser.companyName = user.companyName;
326
+ newuser.companyDomain = user.companyDomain;
327
+ newuser.associatedWorkspaces = user.associatedWorkspaces;
328
+ newuser.workspaceIDs = user.workspaceIDs;
329
+ newuser.session = user.session;
330
+ newuser.spacode = user.spacode;
331
+ newuser.accessToken = user.accessToken;
332
+ newuser.loginHint = user.loginHint;
333
+ newuser.scopes = user.scopes;
334
+ newuser.authTS = new Date(user.authTS);
335
+ newuser.sel = user.sel;
336
+ return newuser
337
+ });
338
+ }
339
+ if (typeof ii.ts === "undefined") {
340
+ this.ts = new Array<Tenant>();
341
+ }
342
+ else {
343
+ this.ts = ii.ts.map((tenant: Tenant) => {
344
+ let newtenant: Tenant = new Tenant();
345
+ newtenant.tid = tenant.tid;
346
+ newtenant.name = tenant.name;
347
+ newtenant.domain = tenant.domain;
348
+ newtenant.tenantType = tenant.tenantType;
349
+ newtenant.permissionType = tenant.permissionType;
350
+ newtenant.onboarded = tenant.onboarded;
351
+ newtenant.authority = tenant.authority;
352
+ newtenant.workspaceIDs = tenant.workspaceIDs;
353
+ newtenant.sel = tenant.sel;
354
+ return newtenant;
355
+ });
356
+ }
357
+ if (typeof ii.cs === "undefined") {
358
+ this.cs = new Array<Config>();
359
+ }
360
+ else {
361
+ this.cs = ii.cs.map((config: Config) => {
362
+ let newconfig: Config = new Config();
363
+ newconfig.id = config.id;
364
+ newconfig.workspaceId = config.workspaceId;
365
+ newconfig.name = config.name;
366
+ newconfig.description = config.description;
367
+ newconfig.tenants = config.tenants;
368
+ newconfig.isEnabled = config.isEnabled;
369
+ newconfig.workspaceIDs = config.workspaceIDs;
370
+ newconfig.sel = config.sel;
371
+ return newconfig;
372
+ });
373
+ }
374
+ if (typeof ii.ws === "undefined") {
375
+ this.ws = new Array<Workspace>();
376
+ }
377
+ else {
378
+ this.ws = ii.ws.map((workspace: Workspace) => {
379
+ let newworkspace: Workspace = new Workspace();
380
+ newworkspace.id = workspace.id;
381
+ newworkspace.name = workspace.name;
382
+ newworkspace.associatedUsers = workspace.associatedUsers;
383
+ newworkspace.associatedTenants = workspace.associatedTenants;
384
+ newworkspace.associatedConfigs = workspace.associatedConfigs;
385
+ newworkspace.sel = workspace.sel;
386
+ return newworkspace;
387
+ });
388
+ }
310
389
  }
311
390
  }
312
391
  export type TaskType = "initialization" |
@@ -1388,7 +1467,7 @@ export async function initGet(instance: IPublicClientApplication, authorizedUser
1388
1467
  tenant.domain = user.tid;
1389
1468
  let bResult: boolean = await tenantUnauthenticatedLookup(tenant, debug);
1390
1469
  if (bResult) {
1391
- // success, we now know instance of this tenant
1470
+ // success, we now know cloud instance where this tenant is provisioned
1392
1471
  user.authority = tenant.authority;
1393
1472
  // do we have a logged in user from the same authority as this newly proposed tenant?
1394
1473
  let loggedInUser: User | undefined = ii.us.find((u: User) => (u.session === "Sign Out" && u.authority === user.authority));
@@ -1407,12 +1486,18 @@ export async function initGet(instance: IPublicClientApplication, authorizedUser
1407
1486
  result = await workspaceInfoGet(instance, authorizedUser, user, ii, debug);
1408
1487
  tasks.setTaskEnd("GET workspaces", new Date(), result.result ? "complete" : "failed");
1409
1488
  }
1410
- if (result.result) result.error = version;
1411
- else console.log("@mindline/sync package version: " + version);
1489
+ // if successful, return true result and the version in the result.error field
1490
+ if (result.result) {
1491
+ result.error = version;
1492
+ }
1493
+ // if failed, output version information to the log
1494
+ else {
1495
+ console.log("@mindline/sync package version: " + version);
1496
+ }
1412
1497
  return result;
1413
1498
  }
1414
1499
  else {
1415
- result.error = `${user.mail} with insufficient privileges to lookup under authority: ${user.authority}.`;
1500
+ result.error = `${user.mail} has insufficient privileges to lookup under authority: ${user.authority}.`;
1416
1501
  result.result = false;
1417
1502
  return result;
1418
1503
  }
@@ -1452,7 +1537,14 @@ function processReturnedAdmins(workspace: Workspace, ii: InitInfo, returnedAdmin
1452
1537
  if (dummyIndex !== -1) {
1453
1538
  // clear and overwrite dummy
1454
1539
  user = ii.us.at(dummyIndex);
1455
- user.associatedWorkspaces.length = 0;
1540
+ // replace dummy User oid "1" with real oid in associatedTenants of all workspaces
1541
+ ii.ws.map((w: Workspace) => {
1542
+ let idx: number = w.associatedUsers.findIndex((oid: string) => oid == "1");
1543
+ if (idx !== -1) {
1544
+ w.associatedUsers.splice(idx, 1);
1545
+ w.associatedUsers.push(item.userId);
1546
+ }
1547
+ });
1456
1548
  }
1457
1549
  else {
1458
1550
  // create and track new user
@@ -1484,6 +1576,14 @@ function processReturnedTenants(workspace: Workspace, ii: InitInfo, returnedTena
1484
1576
  if (dummyIndex !== -1) {
1485
1577
  // clear and overwrite dummy
1486
1578
  tenant = ii.ts.at(dummyIndex);
1579
+ // replace dummy Tenant id "1" with real id in associatedTenants of all workspaces
1580
+ ii.ws.map((w: Workspace) => {
1581
+ let idx: number = w.associatedTenants.findIndex((tid: string) => tid == "1");
1582
+ if (idx !== -1) {
1583
+ w.associatedTenants.splice(idx, 1);
1584
+ w.associatedTenants.push(item.tenantId);
1585
+ }
1586
+ });
1487
1587
  } else {
1488
1588
  // create and track new tenant
1489
1589
  tenant = new Tenant();
@@ -1522,6 +1622,14 @@ function processReturnedConfigs(workspace: Workspace, ii: InitInfo, returnedConf
1522
1622
  if (dummyIndex !== -1) {
1523
1623
  // clear and overwrite dummy
1524
1624
  config = ii.cs.at(dummyIndex);
1625
+ // replace dummy Config id "1" with real id in associatedConfigs of all workspaces
1626
+ ii.ws.map((w: Workspace) => {
1627
+ let idx: number = w.associatedConfigs.findIndex((id: string) => id == "1");
1628
+ if (idx !== -1) {
1629
+ w.associatedConfigs.splice(idx, 1);
1630
+ w.associatedConfigs.push(item.id);
1631
+ }
1632
+ });
1525
1633
  } else {
1526
1634
  // create and track new workspace
1527
1635
  config = new Config();
@@ -1582,9 +1690,11 @@ async function workspaceInfoGet(instance: IPublicClientApplication, authorizedUs
1582
1690
  workspace = ii.ws.at(wsIndex);
1583
1691
  }
1584
1692
  // clear associations as we are about to reset
1585
- workspace.associatedUsers.length = 0;
1586
- workspace.associatedTenants.length = 0;
1587
- workspace.associatedConfigs.length = 0;
1693
+ // IN PROGRESS: do not clear so we can retain selection state
1694
+ //workspace.associatedUsers.length = 0;
1695
+ //workspace.associatedTenants.length = 0;
1696
+ //workspace.associatedConfigs.length = 0;
1697
+ // set id and name based on returned data
1588
1698
  workspace.id = o.id;
1589
1699
  workspace.name = o.name;
1590
1700
  // parallel GET admins, tenants, configs associated with this workspace
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mindline/sync",
3
3
  "type": "module",
4
- "version": "1.0.44",
4
+ "version": "1.0.46",
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,6 +6,7 @@
6
6
  "tenantType": "",
7
7
  "permissionType": "",
8
8
  "onboarded": false,
9
- "authority": ""
9
+ "authority": "",
10
+ "sel": true
10
11
  }
11
12
  ]
package/users.json CHANGED
@@ -8,6 +8,7 @@
8
8
  "companyName": "",
9
9
  "companyDomain": "",
10
10
  "associatedWorkspaces": [ "1" ],
11
- "session": "Sign In"
11
+ "session": "Sign In",
12
+ "sel": true
12
13
  }
13
14
  ]
package/workspaces.json CHANGED
@@ -4,6 +4,7 @@
4
4
  "name": "",
5
5
  "associatedUsers": [ "1" ],
6
6
  "associatedTenants": [ "1" ],
7
- "associatedConfigs": [ "1" ]
7
+ "associatedConfigs": [ "1" ],
8
+ "sel": true
8
9
  }
9
10
  ]