@mindline/sync 1.0.20 → 1.0.21
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 +4 -0
- package/hybridspa.ts +10 -7
- package/{sync.d.ts → index.d.ts} +1 -1
- package/index.test.ts +3 -2
- package/index.ts +27 -26
- package/package.json +4 -5
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 =
|
|
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
|
-
|
|
125
|
-
|
|
125
|
+
if(r!==null) {
|
|
126
|
+
user.companyName = r.displayName;
|
|
127
|
+
user.companyDomain = r.defaultDomainName;
|
|
128
|
+
}
|
|
126
129
|
}
|
package/{sync.d.ts → index.d.ts}
RENAMED
package/index.test.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {sum,
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
69
|
+
class TargetConfigInfo {
|
|
62
70
|
tid: string;
|
|
63
71
|
sourceGroups: string[];
|
|
64
72
|
targetGroup: string;
|
|
65
73
|
}
|
|
66
74
|
|
|
67
|
-
|
|
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
|
-
|
|
92
|
+
class Workspace {
|
|
85
93
|
id: string;
|
|
86
94
|
name: string;
|
|
87
95
|
associatedUsers: string[];
|
|
@@ -102,6 +110,7 @@ export class InitInfo {
|
|
|
102
110
|
cs: Config[];
|
|
103
111
|
ws: Workspace[];
|
|
104
112
|
constructor(){
|
|
113
|
+
debugger;
|
|
105
114
|
this.us = new Array();
|
|
106
115
|
this.ts = new Array();
|
|
107
116
|
this.cs = new Array();
|
|
@@ -158,16 +167,8 @@ export class InitInfo {
|
|
|
158
167
|
}
|
|
159
168
|
}
|
|
160
169
|
|
|
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
170
|
// get hardcoded data from JSON
|
|
170
|
-
function DummyInit(ii)
|
|
171
|
+
function DummyInit(ii: InitInfo)
|
|
171
172
|
{
|
|
172
173
|
var usersString = JSON.stringify(users);
|
|
173
174
|
var targetsString = JSON.stringify(targets);
|
|
@@ -178,7 +179,7 @@ function DummyInit(ii)
|
|
|
178
179
|
ii.ts = deserializeArray(Target, targetsString);
|
|
179
180
|
ii.cs = deserializeArray(Config, configsString);
|
|
180
181
|
ii.ws = deserializeArray(Workspace, workspacesString);
|
|
181
|
-
if(!ii.
|
|
182
|
+
if(!ii.tagWithWorkspaces()) return false;
|
|
182
183
|
} catch (e) {
|
|
183
184
|
debugger;
|
|
184
185
|
return false;
|
|
@@ -204,7 +205,7 @@ function DummyInit(ii)
|
|
|
204
205
|
// TODO: Mindline: retrieve associated admins, targets for each workspace
|
|
205
206
|
// ii.us / ii.ts / ii.cs: query components of each associated workspaces
|
|
206
207
|
// Returns: users, targets, configs for each workspace
|
|
207
|
-
export function InitGet(ii: InitInfo, instance: IPublicClientApplication)
|
|
208
|
+
export function InitGet(ii: InitInfo, instance: IPublicClientApplication): boolean
|
|
208
209
|
{
|
|
209
210
|
debugger;
|
|
210
211
|
|
|
@@ -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
|
-
|
|
241
|
+
function AddTarget(): boolean
|
|
241
242
|
{
|
|
242
243
|
return true;
|
|
243
244
|
}
|
|
244
245
|
|
|
245
|
-
|
|
246
|
+
function CompleteTarget(): boolean
|
|
246
247
|
{
|
|
247
248
|
return true;
|
|
248
249
|
}
|
|
249
250
|
|
|
250
|
-
|
|
251
|
+
function AddUser(): boolean
|
|
251
252
|
{
|
|
252
253
|
return true;
|
|
253
254
|
}
|
|
254
255
|
|
|
255
|
-
|
|
256
|
+
function CompleteUser(): boolean
|
|
256
257
|
{
|
|
257
258
|
return true;
|
|
258
259
|
}
|
|
259
260
|
|
|
260
|
-
|
|
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.
|
|
5
|
-
"
|
|
4
|
+
"version": "1.0.21",
|
|
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.",
|
|
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
|
}
|