@mindline/sync 1.0.23 → 1.0.25

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.
Files changed (3) hide show
  1. package/hybridspa.ts +27 -33
  2. package/index.ts +6 -8
  3. package/package.json +1 -1
package/hybridspa.ts CHANGED
@@ -88,42 +88,36 @@ function seeProfile(spaCode: string, instance: IPublicClientApplication) {
88
88
  export function getTenantInfo(user: User, instance: IPublicClientApplication) {
89
89
  debugger;
90
90
 
91
- let authResult: AuthenticationResult;
92
91
  instance
93
92
  .acquireTokenByCode({ code: user.spacode })
94
- .then((result) => (authResult = result))
93
+ .then((result) => {
94
+ // prepare access token in Authorization headers as part of options
95
+ const headers = new Headers();
96
+ const bearer = `Bearer ${result.accessToken}`;
97
+ headers.append("Authorization", bearer);
98
+ const options = {
99
+ method: "GET",
100
+ headers: headers,
101
+ };
102
+ // prepare tenant info endpoint
103
+ var tenantEndpoint = graphConfig.graphTenantEndpoint;
104
+ tenantEndpoint += "(tenantId='";
105
+ tenantEndpoint += user.tid;
106
+ tenantEndpoint += "')";
107
+ console.log(
108
+ "request made to Graph API tenant endpoint at: " + new Date().toString()
109
+ );
110
+ // make tenant endpoint call
111
+ fetch(tenantEndpoint, options)
112
+ .then((response) => response.json())
113
+ .then((body) => {
114
+ console.log("Successfully Fetched Data from Graph API:", body);
115
+ user.companyName = body.displayName;
116
+ user.companyDomain = body.defaultDomainName;
117
+ })
118
+ .catch((error) => console.log(error));
119
+ })
95
120
  .catch((e: any) => {
96
121
  console.log(e);
97
122
  });
98
- const headers = new Headers();
99
- const bearer = `Bearer ${authResult.accessToken}`;
100
- headers.append("Authorization", bearer);
101
-
102
- const options = {
103
- method: "GET",
104
- headers: headers,
105
- };
106
-
107
- var tenantEndpoint = graphConfig.graphTenantEndpoint;
108
- tenantEndpoint += "(tenantId='";
109
- tenantEndpoint += user.tid;
110
- tenantEndpoint += "')";
111
-
112
- console.log(
113
- "request made to Graph API tenant endpoint at: " + new Date().toString()
114
- );
115
-
116
- let r = null;
117
- fetch(tenantEndpoint, options)
118
- .then((response) => response.json())
119
- .then((response) => {
120
- r = response;
121
- console.log("Successfully Fetched Data from Graph API:", response);
122
- })
123
- .catch((error) => console.log(error));
124
-
125
- if(r!==null) {
126
- user.companyName = r.displayName;
127
- user.companyDomain = r.defaultDomainName;
128
- }
129
123
  }
package/index.ts CHANGED
@@ -206,9 +206,6 @@ function DummyInit(ii: InitInfo)
206
206
  // Returns: users, targets, configs for each workspace
207
207
  export function InitGet(ii: InitInfo, instance: IPublicClientApplication, debug: boolean): boolean
208
208
  {
209
- if(debug)
210
- debugger;
211
-
212
209
  // if empty user array, retrieve dummy data from JSON to populate UI
213
210
  let l = ii.us.length;
214
211
  if(l === 0) return DummyInit(ii);
@@ -217,15 +214,15 @@ export function InitGet(ii: InitInfo, instance: IPublicClientApplication, debug:
217
214
  let user:User = ii.us[l-1];
218
215
  if(user.oid === "1") return true;
219
216
 
220
- // have real user: remove dummy user, target, config, workspace if they exist
217
+ // have real user: remove any dummy user, target, config, workspace if they exist
221
218
  let dummyIndex = ii.us.findIndex((u) => u.oid === "1");
222
- ii.us.splice(dummyIndex, 1);
219
+ if(dummyIndex!==-1) ii.us.splice(dummyIndex, 1);
223
220
  dummyIndex = ii.ts.findIndex((u) => u.tid === "1");
224
- ii.ts.splice(dummyIndex, 1);
221
+ if(dummyIndex!==-1) ii.ts.splice(dummyIndex, 1);
225
222
  dummyIndex = ii.cs.findIndex((u) => u.id === "1");
226
- ii.cs.splice(dummyIndex, 1);
223
+ if(dummyIndex!==-1) ii.cs.splice(dummyIndex, 1);
227
224
  dummyIndex = ii.ws.findIndex((u) => u.id === "1");
228
- ii.ws.splice(dummyIndex, 1);
225
+ if(dummyIndex!==-1) ii.ws.splice(dummyIndex, 1);
229
226
 
230
227
  // why would instance be null here? investigate!
231
228
  if(instance===null) {
@@ -234,6 +231,7 @@ export function InitGet(ii: InitInfo, instance: IPublicClientApplication, debug:
234
231
  }
235
232
 
236
233
  // valid user, query AAD for associated company name and domain
234
+ if(debug) debugger;
237
235
  getTenantInfo(user, instance);
238
236
  return true;
239
237
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mindline/sync",
3
3
  "type": "module",
4
- "version": "1.0.23",
4
+ "version": "1.0.25",
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.",