@mindline/sync 1.0.19 → 1.0.20

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.
package/hybridspa.ts CHANGED
@@ -1,8 +1,5 @@
1
- // Select DOM elements to work with
2
- const welcomeDiv = document.getElementById("welcomeMessage");
3
- const cardDiv = document.getElementById("card-div");
4
- const profileButton = document.getElementById("seeProfile");
5
- const profileDiv = document.getElementById("profile-div");
1
+ import { IPublicClientApplication, AuthenticationResult } from '@azure/msal-browser';
2
+ import { User } from '@mindline/sync';
6
3
 
7
4
  // Add here the endpoints for MS Graph API services you would like to use.
8
5
  const graphConfig = {
@@ -16,55 +13,21 @@ function updateUI(data, endpoint) {
16
13
  console.log("Graph API responded at: " + new Date().toString());
17
14
 
18
15
  if (endpoint === graphConfig.graphMeEndpoint) {
19
- profileDiv.innerHTML = "";
20
- const title = document.createElement("p");
21
- title.innerHTML = "<strong>Title: </strong>" + data.jobTitle;
22
16
  console.log(data.jobTitle);
23
- const email = document.createElement("p");
24
- email.innerHTML = "<strong>Mail: </strong>" + data.mail;
25
17
  console.log(data.mail);
26
- const phone = document.createElement("p");
27
- phone.innerHTML = "<strong>Phone: </strong>" + data.businessPhones[0];
28
18
  console.log(data.businessPhones[0]);
29
- const address = document.createElement("p");
30
- address.innerHTML = "<strong>Location: </strong>" + data.officeLocation;
31
19
  console.log(data.officeLocation);
32
- profileDiv.appendChild(title);
33
- profileDiv.appendChild(email);
34
- profileDiv.appendChild(phone);
35
- profileDiv.appendChild(address);
36
20
  } else if (endpoint === graphConfig.graphMailEndpoint) {
37
21
  if (data.value.length < 1) {
38
22
  alert("Your mailbox is empty!");
39
23
  } else {
40
24
  console.log("Displaying Emails for the signed in user.");
41
- const tabList = document.getElementById("list-tab");
42
- tabList.innerHTML = ""; // clear tabList at each readMail call
43
- const tabContent = document.getElementById("nav-tabContent");
44
-
45
25
  data.value.map((d, i) => {
46
26
  // Keeping it simple
47
27
  if (i < 10) {
48
- const listItem = document.createElement("a");
49
- listItem.setAttribute(
50
- "class",
51
- "list-group-item list-group-item-action"
52
- );
53
- listItem.setAttribute("id", "list" + i + "list");
54
- listItem.setAttribute("data-toggle", "list");
55
- listItem.setAttribute("href", "#list" + i);
56
- listItem.setAttribute("role", "tab");
57
- listItem.setAttribute("aria-controls", i);
58
- listItem.innerHTML = d.subject;
59
- tabList.appendChild(listItem);
60
- const contentItem = document.createElement("div");
61
- contentItem.setAttribute("class", "tab-pane fade");
62
- contentItem.setAttribute("id", "list" + i);
63
- contentItem.setAttribute("role", "tabpanel");
64
- contentItem.setAttribute("aria-labelledby", "list" + i + "list");
65
- contentItem.innerHTML =
66
- "<strong> from: " + d.from.emailAddress.address + "</strong>";
67
- tabContent.appendChild(contentItem);
28
+ console.log(data.officeLocation);
29
+ console.log(d.subject);
30
+ console.log(d.from.emailAddress.address);
68
31
  }
69
32
  });
70
33
  }
@@ -122,9 +85,13 @@ function seeProfile(spaCode) {
122
85
  }
123
86
 
124
87
  //Get Tenant Info
125
- async function getTenantInfo(user: User, instance: IPublicClientApplication) {
126
- var authResult = await instance
88
+ export function getTenantInfo(user: User, instance: IPublicClientApplication) {
89
+ debugger;
90
+
91
+ let authResult: AuthenticationResult;
92
+ instance
127
93
  .acquireTokenByCode({ code: user.spacode })
94
+ .then((result) => (authResult = result))
128
95
  .catch((e: any) => {
129
96
  console.log(e);
130
97
  });
@@ -154,6 +121,6 @@ async function getTenantInfo(user: User, instance: IPublicClientApplication) {
154
121
  })
155
122
  .catch((error) => console.log(error));
156
123
 
157
- user.companyName = response.displayName;
158
- user.companyDomain = response.defaultDomainName;
124
+ user.companyName = response.displayName;
125
+ user.companyDomain = response.defaultDomainName;
159
126
  }
package/index.test.ts CHANGED
@@ -6,11 +6,6 @@ test("adds 1 + 2 to equal 3", () => {
6
6
  });
7
7
  test("loads config based on a user and expects function to return true", () => {
8
8
  let ii = new InitInfo();
9
- let bResult:boolean = false;
10
- InitGet(ii, null)
11
- .then((response) => bResult = response)
12
- .catch((e: any) => {
13
- console.log(e);
14
- });
9
+ let bResult:boolean = InitGet(ii, null);
15
10
  expect(bResult);
16
11
  });
package/index.ts CHANGED
@@ -11,7 +11,18 @@ export function helloNpm() {
11
11
  const FILTER_FIELD = "workspaceIDs";
12
12
 
13
13
  export class User {
14
- constructor(){
14
+ oid: string;
15
+ name: string;
16
+ mail: string;
17
+ authority: string;
18
+ tid: string;
19
+ companyName: string;
20
+ companyDomain: string;
21
+ associatedWorkspaces: string[];
22
+ workspaceIDs: string;
23
+ session: string;
24
+ spacode: string;
25
+ constructor() {
15
26
  this.oid = "";
16
27
  this.name = "";
17
28
  this.mail = "";
@@ -19,7 +30,7 @@ export class User {
19
30
  this.tid = "";
20
31
  this.companyName = "";
21
32
  this.companyDomain = "";
22
- this.associatedWorkspaces = {};
33
+ this.associatedWorkspaces = new Array();
23
34
  this.workspaceIDs = "";
24
35
  this.session = "";
25
36
  this.spacode = "";
@@ -27,6 +38,14 @@ export class User {
27
38
  }
28
39
 
29
40
  export class Target {
41
+ tid: string;
42
+ name: string;
43
+ domain: string;
44
+ type: string;
45
+ authority: string;
46
+ readServicePrincipal: string;
47
+ writeServicePrincipal: string;
48
+ workspaceIDs: string;
30
49
  constructor(){
31
50
  this.tid = "";
32
51
  this.name = "";
@@ -39,35 +58,56 @@ export class Target {
39
58
  }
40
59
  }
41
60
 
61
+ export class TargetConfigInfo {
62
+ tid: string;
63
+ sourceGroups: string[];
64
+ targetGroup: string;
65
+ }
66
+
42
67
  export class Config {
68
+ id: string;
69
+ name: string;
70
+ description: string;
71
+ targetConfigs: TargetConfigInfo[];
72
+ enabled: boolean;
73
+ workspaceIDs: string;
43
74
  constructor(){
44
75
  this.id = "";
45
76
  this.name = "";
46
77
  this.description = "";
47
- this.targetConfigs = {};
78
+ this.targetConfigs = new Array();
48
79
  this.enabled = false;
49
80
  this.workspaceIDs = "";
50
81
  }
51
82
  }
52
83
 
53
84
  export class Workspace {
85
+ id: string;
86
+ name: string;
87
+ associatedUsers: string[];
88
+ associatedTargets: string[];
89
+ associatedConfigs: string[];
54
90
  constructor(){
55
91
  this.id = "";
56
92
  this.name = "";
57
- this.associatedUsers = {};
58
- this.associatedTargets = {};
59
- this.associatedConfigs = {};
93
+ this.associatedUsers = new Array();
94
+ this.associatedTargets = new Array();
95
+ this.associatedConfigs = new Array();
60
96
  }
61
97
  }
62
98
 
63
99
  export class InitInfo {
64
- constructor() {
65
- this.us = {};
66
- this.ts = {};
67
- this.cs = {};
68
- this.ws = {};
100
+ us: User[];
101
+ ts: Target[];
102
+ cs: Config[];
103
+ ws: Workspace[];
104
+ constructor(){
105
+ this.us = new Array();
106
+ this.ts = new Array();
107
+ this.cs = new Array();
108
+ this.ws = new Array();
69
109
  }
70
- initWorkspaceIDs() {
110
+ tagWithWorkspaces(): boolean {
71
111
  // for each Workspace tag associated User, Target, Config with Workspace.id
72
112
  for (let workspace of this.ws) {
73
113
  // find matching Users to tag with this workspace
@@ -120,6 +160,7 @@ export class InitInfo {
120
160
 
121
161
  import { deserializeArray } from 'class-transformer';
122
162
  import { IPublicClientApplication } from '@azure/msal-browser';
163
+ import { getTenantInfo } from './hybridspa';
123
164
  import users from "./users.json";
124
165
  import targets from "./targets.json";
125
166
  import configs from "./configs.json";
@@ -163,8 +204,10 @@ function DummyInit(ii)
163
204
  // TODO: Mindline: retrieve associated admins, targets for each workspace
164
205
  // ii.us / ii.ts / ii.cs: query components of each associated workspaces
165
206
  // Returns: users, targets, configs for each workspace
166
- export async function InitGet(ii, instance)
207
+ export function InitGet(ii: InitInfo, instance: IPublicClientApplication)
167
208
  {
209
+ debugger;
210
+
168
211
  // if empty user array, retrieve dummy data from JSON to populate UI
169
212
  let l = ii.us.length;
170
213
  if(l === 0) return DummyInit(ii);
@@ -176,11 +219,11 @@ export async function InitGet(ii, instance)
176
219
  // have real user: remove dummy user, target, config, workspace if they exist
177
220
  let dummyIndex = ii.us.findIndex((u) => u.oid === "1");
178
221
  ii.us.splice(dummyIndex, 1);
179
- dummyIndex = ii.ts.findIndex((u) => u.oid === "1");
222
+ dummyIndex = ii.ts.findIndex((u) => u.tid === "1");
180
223
  ii.ts.splice(dummyIndex, 1);
181
- dummyIndex = ii.cs.findIndex((u) => u.oid === "1");
224
+ dummyIndex = ii.cs.findIndex((u) => u.id === "1");
182
225
  ii.cs.splice(dummyIndex, 1);
183
- dummyIndex = ii.ws.findIndex((u) => u.oid === "1");
226
+ dummyIndex = ii.ws.findIndex((u) => u.id === "1");
184
227
  ii.ws.splice(dummyIndex, 1);
185
228
 
186
229
  // why would instance be null here? investigate!
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@mindline/sync",
3
3
  "type": "module",
4
- "version": "1.0.19",
4
+ "version": "1.0.20",
5
5
  "description": "sync is a node.js package encapsulating javscript classes required for configuring Mindline sync service.",
6
- "exports": "./index.js",
6
+ "exports": "./index.ts",
7
+ "main": "./index.ts",
7
8
  "scripts": {
8
9
  "test": "vitest",
9
10
  "coverage": "vitest run --coverage"
package/sync.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { IPublicClientApplication } from "@azure/msal-browser";
2
+
1
3
  declare module "@mindline/sync" {
2
4
  export function sum(a: number, b: number): number;
3
5
  export function helloNpm(): string;
@@ -18,12 +20,11 @@ declare module "@mindline/sync" {
18
20
  }
19
21
 
20
22
  // target (Azure AD tenant, AD domain, Google workspace)
21
- enum TargetType { AAD = 1, AD, Google }
22
23
  export class Target {
23
24
  tid: string; // from AAD ID token
24
25
  name: string; // findTenantInformationByTenantId
25
26
  domain: string; // findTenantInformationByTenantId
26
- type: TargetType; // always AAD for now
27
+ type: string; // always AAD=1 for now
27
28
  authority: string; // from AAD ID auth response
28
29
  readServicePrincipal: string; // from AAD consent
29
30
  writeServicePrincipal: string; // from AAD consent
@@ -33,7 +34,7 @@ declare module "@mindline/sync" {
33
34
  // config
34
35
  export class TargetConfigInfo {
35
36
  tid: string; // target identifier
36
- sourceGroups: string[]; // source groups - we can confiure multiple source groups for reading (*may* slow things down, but less work for admin)
37
+ sourceGroups: string[]; // source groups - we can configure multiple source groups for reading (*may* slow things down, but less work for admin)
37
38
  targetGroup: string; // target group - we only write users to a single target group (complex to fiugure out which users get written to which groups)
38
39
  }
39
40
  export class Config {