@mindline/sync 1.0.20 → 1.0.22

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/README.md CHANGED
@@ -10,6 +10,10 @@ https://nodejs.org/en/download
10
10
  npm install class-transformer --save
11
11
  npm install reflect-metadata --save
12
12
  ```
13
+ ## install @azure/msal-browser
14
+ ``` js
15
+ npm install @azure/msal-browser --save
16
+ ```
13
17
  # 2. Latest releases
14
18
  # 3. API references
15
19
  # 4. Unit Test
package/hybridspa.ts CHANGED
@@ -58,13 +58,13 @@ function callMSGraph(endpoint, token, callback) {
58
58
  }
59
59
 
60
60
  ///get Token
61
- function getTokenByCode(spaCode) {
61
+ function getTokenByCode(spaCode: string, instance: IPublicClientApplication) {
62
62
  var code = spaCode;
63
63
  const scopes = ["user.read"];
64
64
 
65
65
  console.log("MSAL: acquireTokenByCode hybrid parameters present");
66
66
 
67
- var authResult = msalInstance.acquireTokenByCode({
67
+ var authResult = instance.acquireTokenByCode({
68
68
  code,
69
69
  scopes,
70
70
  });
@@ -74,8 +74,8 @@ function getTokenByCode(spaCode) {
74
74
  }
75
75
 
76
76
  //See Profile
77
- function seeProfile(spaCode) {
78
- getTokenByCode(spaCode)
77
+ function seeProfile(spaCode: string, instance: IPublicClientApplication) {
78
+ getTokenByCode(spaCode, instance)
79
79
  .then((response) => {
80
80
  callMSGraph(graphConfig.graphMeEndpoint, response.accessToken, updateUI);
81
81
  })
@@ -95,7 +95,6 @@ export function getTenantInfo(user: User, instance: IPublicClientApplication) {
95
95
  .catch((e: any) => {
96
96
  console.log(e);
97
97
  });
98
-
99
98
  const headers = new Headers();
100
99
  const bearer = `Bearer ${authResult.accessToken}`;
101
100
  headers.append("Authorization", bearer);
@@ -114,13 +113,17 @@ export function getTenantInfo(user: User, instance: IPublicClientApplication) {
114
113
  "request made to Graph API tenant endpoint at: " + new Date().toString()
115
114
  );
116
115
 
116
+ let r = null;
117
117
  fetch(tenantEndpoint, options)
118
118
  .then((response) => response.json())
119
119
  .then((response) => {
120
+ r = response;
120
121
  console.log("Successfully Fetched Data from Graph API:", response);
121
122
  })
122
123
  .catch((error) => console.log(error));
123
124
 
124
- user.companyName = response.displayName;
125
- user.companyDomain = response.defaultDomainName;
125
+ if(r!==null) {
126
+ user.companyName = r.displayName;
127
+ user.companyDomain = r.defaultDomainName;
128
+ }
126
129
  }
@@ -1,4 +1,4 @@
1
- import { IPublicClientApplication } from "@azure/msal-browser";
1
+ import { IPublicClientApplication } from "@azure/msal-browser/dist";
2
2
 
3
3
  declare module "@mindline/sync" {
4
4
  export function sum(a: number, b: number): number;
package/index.test.ts CHANGED
@@ -1,11 +1,12 @@
1
- import {sum, User, InitInfo, InitGet } from "index";
1
+ import {sum, InitInfo, InitGet} from "./index";
2
2
  import {test, expect} from "vitest";
3
+ import {stubbedPublicClientApplication} from "@azure/msal-browser/dist";
3
4
 
4
5
  test("adds 1 + 2 to equal 3", () => {
5
6
  expect(sum(1, 2)).toBe(3);
6
7
  });
7
8
  test("loads config based on a user and expects function to return true", () => {
8
9
  let ii = new InitInfo();
9
- let bResult:boolean = InitGet(ii, null);
10
+ let bResult:boolean = InitGet(ii, stubbedPublicClientApplication);
10
11
  expect(bResult);
11
12
  });
package/index.ts CHANGED
@@ -1,16 +1,24 @@
1
1
  //index.js
2
2
 
3
+ import { deserializeArray } from 'class-transformer';
4
+ import { IPublicClientApplication } from '@azure/msal-browser';
5
+ import { getTenantInfo } from './hybridspa';
6
+ import users from "./users.json";
7
+ import targets from "./targets.json";
8
+ import configs from "./configs.json";
9
+ import workspaces from "./workspaces.json";
10
+
11
+ const FILTER_FIELD = "workspaceIDs";
12
+
3
13
  // called by unit tests
4
- export function sum(a, b) {
14
+ export function sum(a: number, b: number): number {
5
15
  return a + b;
6
16
  }
7
- export function helloNpm() {
17
+ export function helloNpm() : string {
8
18
  return "hello NPM";
9
19
  }
10
20
 
11
- const FILTER_FIELD = "workspaceIDs";
12
-
13
- export class User {
21
+ class User {
14
22
  oid: string;
15
23
  name: string;
16
24
  mail: string;
@@ -37,7 +45,7 @@ export class User {
37
45
  }
38
46
  }
39
47
 
40
- export class Target {
48
+ class Target {
41
49
  tid: string;
42
50
  name: string;
43
51
  domain: string;
@@ -58,13 +66,13 @@ export class Target {
58
66
  }
59
67
  }
60
68
 
61
- export class TargetConfigInfo {
69
+ class TargetConfigInfo {
62
70
  tid: string;
63
71
  sourceGroups: string[];
64
72
  targetGroup: string;
65
73
  }
66
74
 
67
- export class Config {
75
+ class Config {
68
76
  id: string;
69
77
  name: string;
70
78
  description: string;
@@ -81,7 +89,7 @@ export class Config {
81
89
  }
82
90
  }
83
91
 
84
- export class Workspace {
92
+ class Workspace {
85
93
  id: string;
86
94
  name: string;
87
95
  associatedUsers: string[];
@@ -158,16 +166,8 @@ export class InitInfo {
158
166
  }
159
167
  }
160
168
 
161
- import { deserializeArray } from 'class-transformer';
162
- import { IPublicClientApplication } from '@azure/msal-browser';
163
- import { getTenantInfo } from './hybridspa';
164
- import users from "./users.json";
165
- import targets from "./targets.json";
166
- import configs from "./configs.json";
167
- import workspaces from "./workspaces.json";
168
-
169
169
  // get hardcoded data from JSON
170
- function DummyInit(ii)
170
+ function DummyInit(ii: InitInfo)
171
171
  {
172
172
  var usersString = JSON.stringify(users);
173
173
  var targetsString = JSON.stringify(targets);
@@ -178,7 +178,7 @@ function DummyInit(ii)
178
178
  ii.ts = deserializeArray(Target, targetsString);
179
179
  ii.cs = deserializeArray(Config, configsString);
180
180
  ii.ws = deserializeArray(Workspace, workspacesString);
181
- if(!ii.initWorkspaceIDs()) return false;
181
+ if(!ii.tagWithWorkspaces()) return false;
182
182
  } catch (e) {
183
183
  debugger;
184
184
  return false;
@@ -204,9 +204,10 @@ function DummyInit(ii)
204
204
  // TODO: Mindline: retrieve associated admins, targets for each workspace
205
205
  // ii.us / ii.ts / ii.cs: query components of each associated workspaces
206
206
  // Returns: users, targets, configs for each workspace
207
- export function InitGet(ii: InitInfo, instance: IPublicClientApplication)
207
+ export function InitGet(ii: InitInfo, instance: IPublicClientApplication, debug: boolean): boolean
208
208
  {
209
- debugger;
209
+ if(debug)
210
+ debugger;
210
211
 
211
212
  // if empty user array, retrieve dummy data from JSON to populate UI
212
213
  let l = ii.us.length;
@@ -234,30 +235,30 @@ export function InitGet(ii: InitInfo, instance: IPublicClientApplication)
234
235
 
235
236
  // valid user, query AAD for associated company name and domain
236
237
  getTenantInfo(user, instance);
237
- return;
238
+ return true;
238
239
  }
239
240
 
240
- export function AddTarget()
241
+ function AddTarget(): boolean
241
242
  {
242
243
  return true;
243
244
  }
244
245
 
245
- export function CompleteTarget()
246
+ function CompleteTarget(): boolean
246
247
  {
247
248
  return true;
248
249
  }
249
250
 
250
- export function AddUser()
251
+ function AddUser(): boolean
251
252
  {
252
253
  return true;
253
254
  }
254
255
 
255
- export function CompleteUser()
256
+ function CompleteUser(): boolean
256
257
  {
257
258
  return true;
258
259
  }
259
260
 
260
- export function CreateConfig()
261
+ function CreateConfig(): boolean
261
262
  {
262
263
  return true;
263
264
  }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@mindline/sync",
3
3
  "type": "module",
4
- "version": "1.0.20",
5
- "description": "sync is a node.js package encapsulating javscript classes required for configuring Mindline sync service.",
4
+ "version": "1.0.22",
5
+ "types": "index.d.ts",
6
6
  "exports": "./index.ts",
7
- "main": "./index.ts",
7
+ "description": "sync is a node.js package encapsulating javscript classes required for configuring Mindline sync service.",
8
8
  "scripts": {
9
9
  "test": "vitest",
10
10
  "coverage": "vitest run --coverage"
@@ -19,6 +19,5 @@
19
19
  "@azure/msal-browser": "^2.37.0",
20
20
  "class-transformer": "^0.5.1",
21
21
  "reflect-metadata": "^0.1.13"
22
- },
23
- "typings": "sync.d.ts"
22
+ }
24
23
  }