@mindline/sync 1.0.24 → 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 (2) hide show
  1. package/hybridspa.ts +27 -33
  2. 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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mindline/sync",
3
3
  "type": "module",
4
- "version": "1.0.24",
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.",