@mindline/sync 1.0.88 → 1.0.90
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/.vs/VSWorkspaceState.json +0 -1
- package/.vs/slnx.sqlite +0 -0
- package/.vs/sync/CopilotIndices/17.14.260.54502/CodeChunks.db +0 -0
- package/.vs/sync/CopilotIndices/17.14.260.54502/SemanticSymbols.db +0 -0
- package/.vs/sync/FileContentIndex/0f447c8e-f707-40c3-aa4c-30bfeab10f57.vsidx +0 -0
- package/.vs/sync/FileContentIndex/14855cf9-9dc6-406b-8690-3a6fd40f6dea.vsidx +0 -0
- package/.vs/sync/v17/.wsuo +0 -0
- package/.vs/sync/v17/DocumentLayout.backup.json +35 -3
- package/.vs/sync/v17/DocumentLayout.json +13 -15
- package/index.ts +1008 -0
- package/package.json +1 -1
- package/.vs/sync/FileContentIndex/942626e0-d13f-45dd-ad1c-d850883e48b9.vsidx +0 -0
- package/hybridspa.ts +0 -1023
package/hybridspa.ts
DELETED
|
@@ -1,1023 +0,0 @@
|
|
|
1
|
-
//hybridspa.ts - calls to Mindline Config API
|
|
2
|
-
import {
|
|
3
|
-
APIResult,
|
|
4
|
-
Config,
|
|
5
|
-
mindlineConfig,
|
|
6
|
-
Tenant,
|
|
7
|
-
TenantConfigInfo,
|
|
8
|
-
User
|
|
9
|
-
} from "./index";
|
|
10
|
-
import {
|
|
11
|
-
AccountInfo
|
|
12
|
-
} from "@azure/msal-common";
|
|
13
|
-
import {
|
|
14
|
-
IPublicClientApplication,
|
|
15
|
-
AuthenticationResult,
|
|
16
|
-
} from "@azure/msal-browser";
|
|
17
|
-
import { deserializeArray } from "class-transformer";
|
|
18
|
-
|
|
19
|
-
// helper functions
|
|
20
|
-
function getAPIScope(user: User): string {
|
|
21
|
-
let apiAppID: string = "8d95d21c-c378-4bb0-9f52-88c30d271e7a";
|
|
22
|
-
let authority: string = user.authority.toLowerCase();
|
|
23
|
-
if (authority.startsWith("https://login.microsoftonline.com/"))
|
|
24
|
-
apiAppID = "8d95d21c-c378-4bb0-9f52-88c30d271e7a";
|
|
25
|
-
else if (authority.startsWith("https://login.microsoftonline.us/"))
|
|
26
|
-
apiAppID = "48da942e-ea3d-49e4-a054-81649012f8f2";
|
|
27
|
-
else if (authority.startsWith("https://login.partner.microsoftonline.cn/"))
|
|
28
|
-
apiAppID = "c91d32e4-dcc5-4d77-826a-16e93ffce666";
|
|
29
|
-
let apiScope: string = `api://${apiAppID}/Config.Write`;
|
|
30
|
-
return apiScope;
|
|
31
|
-
}
|
|
32
|
-
// TODO: this is where you want to trigger a re-authentication if token expires
|
|
33
|
-
async function mindlineDefineHeaders(
|
|
34
|
-
instance: IPublicClientApplication,
|
|
35
|
-
user: User
|
|
36
|
-
): Promise<Headers> {
|
|
37
|
-
const headers = new Headers();
|
|
38
|
-
headers.append("Content-Type", "application/json");
|
|
39
|
-
headers.append("accept", "*/*");
|
|
40
|
-
// always call acquireTokenSilent, handling expired tokens on exception
|
|
41
|
-
const apiScope: string = getAPIScope(user);
|
|
42
|
-
try {
|
|
43
|
-
let accounts: AccountInfo[] = instance.getAllAccounts();
|
|
44
|
-
let homeAccountId = user.oid + "." + user.tid;
|
|
45
|
-
let account: AccountInfo = null;
|
|
46
|
-
for (let i: number = 0; i < accounts.length; i++) {
|
|
47
|
-
if (accounts[i].homeAccountId == homeAccountId) {
|
|
48
|
-
account = accounts[i];
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
let response: AuthenticationResult = await instance.acquireTokenSilent({
|
|
52
|
-
scopes: [apiScope],
|
|
53
|
-
account: account
|
|
54
|
-
});
|
|
55
|
-
user.mindlineAccessToken = response.accessToken; // cache access token
|
|
56
|
-
console.log("Front end mindline token acquired silently: " + user.mindlineAccessToken.slice(0, 20));
|
|
57
|
-
}
|
|
58
|
-
catch (error: any) {
|
|
59
|
-
try {
|
|
60
|
-
console.log("Front end mindline token silent acquisition failure, triggering redirect: " + error);
|
|
61
|
-
// fallback to redirect if silent acquisition fails
|
|
62
|
-
let accounts: AccountInfo[] = instance.getAllAccounts();
|
|
63
|
-
let homeAccountId = user.oid + "." + user.tid;
|
|
64
|
-
let account: AccountInfo = null;
|
|
65
|
-
for (let i: number = 0; i < accounts.length; i++) {
|
|
66
|
-
if (accounts[i].homeAccountId == homeAccountId) {
|
|
67
|
-
account = accounts[i];
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
// assumption: this redirect will trigger login flow callbacks in program.cs
|
|
71
|
-
instance.acquireTokenRedirect({
|
|
72
|
-
scopes: [apiScope],
|
|
73
|
-
account: account
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
catch (error: any) {
|
|
77
|
-
console.log("Front end mindline token redirect acquisition failure: " + error);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
headers.append("Authorization", `Bearer ${user.mindlineAccessToken}`);
|
|
81
|
-
return headers;
|
|
82
|
-
}
|
|
83
|
-
export async function processErrors(response: Response): Promise<string> {
|
|
84
|
-
let errorString: string = "";
|
|
85
|
-
if (response.status === 401) {
|
|
86
|
-
errorString = response.statusText;
|
|
87
|
-
if (errorString != "") return errorString;
|
|
88
|
-
}
|
|
89
|
-
let data = await response.json();
|
|
90
|
-
// process errors from Mindline Config API
|
|
91
|
-
if (data.error !== undefined) {
|
|
92
|
-
errorString = `Error: ${data.error} Message: ${data.message}`;
|
|
93
|
-
} else if (data.errors !== undefined) {
|
|
94
|
-
let errorArray = Object.keys(data.errors);
|
|
95
|
-
let errorlist: string = "";
|
|
96
|
-
errorString = errorArray.reduce(
|
|
97
|
-
(acc, curr) => acc + curr + ": " + data.errors[curr] + " ",
|
|
98
|
-
errorlist
|
|
99
|
-
);
|
|
100
|
-
} else if (data.title !== undefined) {
|
|
101
|
-
errorString = data.title;
|
|
102
|
-
} else {
|
|
103
|
-
debugger;
|
|
104
|
-
}
|
|
105
|
-
return errorString;
|
|
106
|
-
}
|
|
107
|
-
//adminDelete
|
|
108
|
-
export async function adminDelete(
|
|
109
|
-
instance: IPublicClientApplication,
|
|
110
|
-
authorizedUser: User,
|
|
111
|
-
user: User,
|
|
112
|
-
workspaceId: string
|
|
113
|
-
): Promise<APIResult> {
|
|
114
|
-
let result: APIResult = new APIResult();
|
|
115
|
-
// we need either oid or mail for the user and valid workspace id
|
|
116
|
-
if ((user.oid == "" && user.mail == "") || workspaceId == "") {
|
|
117
|
-
result.result = false;
|
|
118
|
-
result.error = "adminDelete: invalid parameters";
|
|
119
|
-
result.status = 500;
|
|
120
|
-
return result;
|
|
121
|
-
}
|
|
122
|
-
// define admin endpoint and add workspaceId parameter
|
|
123
|
-
let url: URL | null = null;
|
|
124
|
-
url = new URL(mindlineConfig.adminEndpoint());
|
|
125
|
-
url.searchParams.append("workspaceId", workspaceId);
|
|
126
|
-
url.searchParams.append("email", user.mail);
|
|
127
|
-
// create headers
|
|
128
|
-
const headers = await mindlineDefineHeaders(instance, authorizedUser);
|
|
129
|
-
// make endpoint call
|
|
130
|
-
let options = { method: "DELETE", headers: headers };
|
|
131
|
-
try {
|
|
132
|
-
console.log("Attempting DELETE from /admin: " + url!.href);
|
|
133
|
-
let response = await fetch(url!.href, options);
|
|
134
|
-
if (response.status === 200 && response.statusText === "OK") {
|
|
135
|
-
console.log(`Successful DELETE from /admin: ${url!.href}`);
|
|
136
|
-
return result;
|
|
137
|
-
} else {
|
|
138
|
-
result.error = await processErrors(response);
|
|
139
|
-
console.log(`Failed DELETE from /admin: ${url.href}`);
|
|
140
|
-
console.log(result.error);
|
|
141
|
-
result.status = 500;
|
|
142
|
-
result.result = false;
|
|
143
|
-
return result;
|
|
144
|
-
}
|
|
145
|
-
} catch (error: any) {
|
|
146
|
-
result.error = error.message;
|
|
147
|
-
result.status = 500;
|
|
148
|
-
result.result = false;
|
|
149
|
-
console.log(error.message);
|
|
150
|
-
}
|
|
151
|
-
return result;
|
|
152
|
-
}
|
|
153
|
-
//adminsGet
|
|
154
|
-
export async function adminsGet(
|
|
155
|
-
instance: IPublicClientApplication,
|
|
156
|
-
user: User,
|
|
157
|
-
workspaceID: string,
|
|
158
|
-
debug: boolean
|
|
159
|
-
): Promise<APIResult> {
|
|
160
|
-
let result: APIResult = new APIResult();
|
|
161
|
-
// we need a workspace id
|
|
162
|
-
if (workspaceID === "") {
|
|
163
|
-
result.result = false;
|
|
164
|
-
result.status = 500;
|
|
165
|
-
result.error = "adminsGet: no workspace provided";
|
|
166
|
-
return result;
|
|
167
|
-
}
|
|
168
|
-
// create endpoint
|
|
169
|
-
let endpoint: string = mindlineConfig.adminsEndpoint();
|
|
170
|
-
// add parameter to endpoint
|
|
171
|
-
let url: URL = new URL(endpoint);
|
|
172
|
-
url.searchParams.append("workspaceId", workspaceID);
|
|
173
|
-
// create headers
|
|
174
|
-
const headers = await mindlineDefineHeaders(instance, user);
|
|
175
|
-
// make endpoint call
|
|
176
|
-
let options = { method: "GET", headers: headers };
|
|
177
|
-
try {
|
|
178
|
-
if (debug) debugger;
|
|
179
|
-
console.log("Attempting GET from /admins: " + url.href);
|
|
180
|
-
let response = await fetch(url.href, options);
|
|
181
|
-
if (response.status === 200 && response.statusText === "OK") {
|
|
182
|
-
let returnedArray: Array<Object> = await response.json();
|
|
183
|
-
if (returnedArray != null) {
|
|
184
|
-
result.array = returnedArray;
|
|
185
|
-
let initialValue: string = "";
|
|
186
|
-
console.log(`Successful GET from /admins: ${result.array.reduce((acc, curr) => acc + curr.email + " ", initialValue)}`);
|
|
187
|
-
return result;
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
result.error = `Failed GET from /admins: failed to JSON-parse response`;
|
|
191
|
-
console.log(result.error);
|
|
192
|
-
result.status = 500;
|
|
193
|
-
result.result = false;
|
|
194
|
-
return result;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
console.log(`Failed GET from /admins: ${url.href}`);
|
|
199
|
-
result.error = await processErrors(response);
|
|
200
|
-
result.status = 500;
|
|
201
|
-
result.result = false;
|
|
202
|
-
console.log(result.error);
|
|
203
|
-
return result;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
catch (error: any) {
|
|
207
|
-
result.error = error.message;
|
|
208
|
-
result.status = 500;
|
|
209
|
-
result.result = false;
|
|
210
|
-
console.log(error.message);
|
|
211
|
-
}
|
|
212
|
-
return result;
|
|
213
|
-
}
|
|
214
|
-
//adminPost: write validated admin to back end
|
|
215
|
-
export async function adminPost(
|
|
216
|
-
instance: IPublicClientApplication,
|
|
217
|
-
authorizedUser: User,
|
|
218
|
-
user: User,
|
|
219
|
-
workspaceId: string
|
|
220
|
-
): Promise<APIResult> {
|
|
221
|
-
let result: APIResult = new APIResult();
|
|
222
|
-
if (user.mail == "" || user.authority == "" || user.tid === "") {
|
|
223
|
-
result.result = false;
|
|
224
|
-
result.error = "adminPost: invalid argument";
|
|
225
|
-
result.status = 500;
|
|
226
|
-
return result;
|
|
227
|
-
}
|
|
228
|
-
// create admin endpoint
|
|
229
|
-
let endpoint: string = mindlineConfig.adminEndpoint();
|
|
230
|
-
// create headers
|
|
231
|
-
const headers = await mindlineDefineHeaders(instance, authorizedUser);
|
|
232
|
-
// create admin body
|
|
233
|
-
let adminBody: string = `
|
|
234
|
-
{"email": "${user.mail}",
|
|
235
|
-
"tenantId": "${user.tid}",
|
|
236
|
-
"workspaceId": "${workspaceId}"
|
|
237
|
-
}`;
|
|
238
|
-
let options = { method: "POST", headers: headers, body: adminBody };
|
|
239
|
-
// make admin endpoint call
|
|
240
|
-
try {
|
|
241
|
-
console.log("Attempting POST to /admin: " + endpoint);
|
|
242
|
-
let response = await fetch(endpoint, options);
|
|
243
|
-
if (response.status === 200 && response.statusText === "OK") {
|
|
244
|
-
console.log(`Successful POST to /admin: ${adminBody}`);
|
|
245
|
-
return result;
|
|
246
|
-
} else {
|
|
247
|
-
result.error = await processErrors(response);
|
|
248
|
-
console.log(`Failed POST to /admin: ${adminBody}`);
|
|
249
|
-
console.log(result.error);
|
|
250
|
-
result.status = 500;
|
|
251
|
-
result.result = false;
|
|
252
|
-
return result;
|
|
253
|
-
}
|
|
254
|
-
} catch (error: any) {
|
|
255
|
-
result.error = error.message;
|
|
256
|
-
result.status = 500;
|
|
257
|
-
result.result = false;
|
|
258
|
-
console.log(error.message);
|
|
259
|
-
}
|
|
260
|
-
return result;
|
|
261
|
-
}
|
|
262
|
-
//configConsentReadPut
|
|
263
|
-
export async function configConsentReadPut(instance: IPublicClientApplication, authorizedUser: User, configId: string, tid: string, consent: boolean): Promise<APIResult> {
|
|
264
|
-
let result: APIResult = new APIResult();
|
|
265
|
-
// create parameterized config consent endpoint
|
|
266
|
-
let endpoint: string = mindlineConfig.configConsentEndpoint();
|
|
267
|
-
let url: URL = new URL(endpoint);
|
|
268
|
-
url.searchParams.append("configurationId", configId);
|
|
269
|
-
// create headers
|
|
270
|
-
const headers = await mindlineDefineHeaders(instance, authorizedUser);
|
|
271
|
-
// create body
|
|
272
|
-
let configConsentReadBody: string = `
|
|
273
|
-
{
|
|
274
|
-
"tenantId": "${tid}",
|
|
275
|
-
"isReadPermissionConsented": ${consent ? "true" : "false"}
|
|
276
|
-
}`;
|
|
277
|
-
// make endpoint call
|
|
278
|
-
let options = { method: "PUT", headers: headers, body: configConsentReadBody };
|
|
279
|
-
try {
|
|
280
|
-
console.log("Attempting PUT read consent to /configuration/consent: " + url.href);
|
|
281
|
-
let response = await fetch(url.href, options);
|
|
282
|
-
if (response.status === 200 && response.statusText === "OK") {
|
|
283
|
-
console.log(`Successful PUT to ${url.href}`);
|
|
284
|
-
return result;
|
|
285
|
-
}
|
|
286
|
-
else {
|
|
287
|
-
result.error = await processErrors(response);
|
|
288
|
-
console.log(`Failed PUT to ${url.href}`);
|
|
289
|
-
console.log(result.error);
|
|
290
|
-
result.status = 500;
|
|
291
|
-
result.result = false;
|
|
292
|
-
return result;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
catch (error: any) {
|
|
296
|
-
result.error = error.message;
|
|
297
|
-
result.status = 500;
|
|
298
|
-
result.result = false;
|
|
299
|
-
console.log(error.message);
|
|
300
|
-
}
|
|
301
|
-
return result;
|
|
302
|
-
}
|
|
303
|
-
//configConsentWritePut
|
|
304
|
-
export async function configConsentWritePut(instance: IPublicClientApplication, authorizedUser: User, configId: string, tid: string, consent: boolean): Promise<APIResult> {
|
|
305
|
-
let result: APIResult = new APIResult();
|
|
306
|
-
// create parameterized config consent endpoint
|
|
307
|
-
let endpoint: string = mindlineConfig.configConsentEndpoint();
|
|
308
|
-
let url: URL = new URL(endpoint);
|
|
309
|
-
url.searchParams.append("configurationId", configId);
|
|
310
|
-
// create headers
|
|
311
|
-
const headers = await mindlineDefineHeaders(instance, authorizedUser);
|
|
312
|
-
// create body
|
|
313
|
-
let configConsentWriteBody: string = `
|
|
314
|
-
{
|
|
315
|
-
"tenantId": "${tid}",
|
|
316
|
-
"isWritePermissionConsented": ${consent ? "true" : "false"}
|
|
317
|
-
}`;
|
|
318
|
-
// make endpoint call
|
|
319
|
-
let options = { method: "PUT", headers: headers, body: configConsentWriteBody };
|
|
320
|
-
try {
|
|
321
|
-
console.log("Attempting PUT read consent to /configuration/consent: " + url.href);
|
|
322
|
-
let response = await fetch(url.href, options);
|
|
323
|
-
if (response.status === 200 && response.statusText === "OK") {
|
|
324
|
-
console.log(`Successful PUT to ${url.href}`);
|
|
325
|
-
return result;
|
|
326
|
-
}
|
|
327
|
-
else {
|
|
328
|
-
result.error = await processErrors(response);
|
|
329
|
-
console.log(`Failed PUT to ${url.href}`);
|
|
330
|
-
console.log(result.error);
|
|
331
|
-
result.status = 500;
|
|
332
|
-
result.result = false;
|
|
333
|
-
return result;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
catch (error: any) {
|
|
337
|
-
result.error = error.message;
|
|
338
|
-
result.status = 500;
|
|
339
|
-
result.result = false;
|
|
340
|
-
console.log(error.message);
|
|
341
|
-
}
|
|
342
|
-
return result;
|
|
343
|
-
}
|
|
344
|
-
//configDelete
|
|
345
|
-
export async function configDelete(
|
|
346
|
-
instance: IPublicClientApplication,
|
|
347
|
-
authorizedUser: User,
|
|
348
|
-
config: Config,
|
|
349
|
-
workspaceId: string,
|
|
350
|
-
debug: boolean
|
|
351
|
-
): Promise<APIResult> {
|
|
352
|
-
let result: APIResult = new APIResult();
|
|
353
|
-
if (config.id === "" || workspaceId == "") {
|
|
354
|
-
result.result = false;
|
|
355
|
-
result.error = "configPost: invalid config ID";
|
|
356
|
-
result.status = 500;
|
|
357
|
-
return result;
|
|
358
|
-
}
|
|
359
|
-
let url: URL | null = null;
|
|
360
|
-
url = new URL(mindlineConfig.configEndpoint());
|
|
361
|
-
url.searchParams.append("configurationId", config.id);
|
|
362
|
-
// create headers
|
|
363
|
-
const headers = await mindlineDefineHeaders(instance, authorizedUser);
|
|
364
|
-
// make endpoint call
|
|
365
|
-
let options = { method: "DELETE", headers: headers };
|
|
366
|
-
try {
|
|
367
|
-
console.log("Attempting DELETE from /config: " + url.href);
|
|
368
|
-
let response = await fetch(url.href, options);
|
|
369
|
-
if (response.status === 200 && response.statusText === "OK") {
|
|
370
|
-
console.log(`Successful DELETE from /config`);
|
|
371
|
-
return result;
|
|
372
|
-
}
|
|
373
|
-
else {
|
|
374
|
-
result.error = await processErrors(response);
|
|
375
|
-
console.log(`Failed DELETE from ${url.href}`);
|
|
376
|
-
console.log(result.error);
|
|
377
|
-
result.status = 500;
|
|
378
|
-
result.result = false;
|
|
379
|
-
return result;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
catch (error: any) {
|
|
383
|
-
result.error = error.message;
|
|
384
|
-
result.status = 500;
|
|
385
|
-
result.result = false;
|
|
386
|
-
console.log(error.message);
|
|
387
|
-
}
|
|
388
|
-
return result;
|
|
389
|
-
}
|
|
390
|
-
//configPatch
|
|
391
|
-
export async function configPatch(
|
|
392
|
-
instance: IPublicClientApplication,
|
|
393
|
-
authorizedUser: User,
|
|
394
|
-
configurationId: string,
|
|
395
|
-
enabled: boolean,
|
|
396
|
-
debug: boolean
|
|
397
|
-
): Promise<APIResult> {
|
|
398
|
-
let result: APIResult = new APIResult();
|
|
399
|
-
if (configurationId === "") {
|
|
400
|
-
result.result = false;
|
|
401
|
-
result.error = "configPatch: invalid config ID";
|
|
402
|
-
result.status = 500;
|
|
403
|
-
return result;
|
|
404
|
-
}
|
|
405
|
-
// create parametrized config endpoint
|
|
406
|
-
let endpoint: string = mindlineConfig.configEnabledEndpoint();
|
|
407
|
-
let url: URL = new URL(endpoint);
|
|
408
|
-
url.searchParams.append("configurationId", configurationId);
|
|
409
|
-
url.searchParams.append("isEnabled", enabled.toString());
|
|
410
|
-
// create config headers
|
|
411
|
-
const headers = await mindlineDefineHeaders(instance, authorizedUser);
|
|
412
|
-
let options = { method: "PATCH", headers: headers };
|
|
413
|
-
// make config endpoint call
|
|
414
|
-
try {
|
|
415
|
-
if (debug) debugger;
|
|
416
|
-
console.log("Attempting PATCH to /config: " + url.href);
|
|
417
|
-
let response = await fetch(url.href, options);
|
|
418
|
-
if (response.status === 200 && response.statusText === "OK") {
|
|
419
|
-
console.log(`Successful PATCH to ${url.href}: ${enabled.toString()}`);
|
|
420
|
-
return result;
|
|
421
|
-
}
|
|
422
|
-
else {
|
|
423
|
-
result.error = await processErrors(response);
|
|
424
|
-
console.log(`Failed PATCH to ${url.href}: ${enabled.toString()}`);
|
|
425
|
-
console.log(result.error);
|
|
426
|
-
result.status = 500;
|
|
427
|
-
result.result = false;
|
|
428
|
-
return result;
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
catch (error: any) {
|
|
432
|
-
result.error = error.message;
|
|
433
|
-
result.status = 500;
|
|
434
|
-
result.result = false;
|
|
435
|
-
console.log(error.message);
|
|
436
|
-
}
|
|
437
|
-
return result;
|
|
438
|
-
}
|
|
439
|
-
//configPost
|
|
440
|
-
export async function configPost(
|
|
441
|
-
instance: IPublicClientApplication,
|
|
442
|
-
authorizedUser: User,
|
|
443
|
-
config: Config,
|
|
444
|
-
workspaceId: string,
|
|
445
|
-
debug: boolean
|
|
446
|
-
): Promise<APIResult> {
|
|
447
|
-
let result: APIResult = new APIResult();
|
|
448
|
-
if (config.id === "") {
|
|
449
|
-
result.result = false;
|
|
450
|
-
result.error = "configPost: invalid config ID";
|
|
451
|
-
result.status = 500;
|
|
452
|
-
return result;
|
|
453
|
-
}
|
|
454
|
-
// create no parameter config endpoint
|
|
455
|
-
let endpoint: string = mindlineConfig.configEndpoint();
|
|
456
|
-
// create config headers
|
|
457
|
-
const headers = await mindlineDefineHeaders(instance, authorizedUser);
|
|
458
|
-
// create config body
|
|
459
|
-
let configBody: string = `
|
|
460
|
-
{
|
|
461
|
-
"workspaceId": "${workspaceId}",
|
|
462
|
-
"name": "${config.name}",
|
|
463
|
-
"description": "${config.description}",
|
|
464
|
-
"isEnabled": ${config.isEnabled},
|
|
465
|
-
"tenants": [`;
|
|
466
|
-
config.tenants.map((tci) => {
|
|
467
|
-
// be sure we send null and not "null" in body
|
|
468
|
-
let sourceGroupId: string = tci.sourceGroupId != "" ? `"${tci.sourceGroupId}"` : "null";
|
|
469
|
-
let sourceGroupName: string = tci.sourceGroupName != "" ? `"${tci.sourceGroupName}"` : "null";
|
|
470
|
-
let targetGroupId: string = tci.targetGroupId != "" ? `"${tci.targetGroupId}"` : "null";
|
|
471
|
-
let targetGroupName: string = tci.targetGroupName != "" ? `"${tci.targetGroupName}"` : "null";
|
|
472
|
-
// if last character is } we need a comma first
|
|
473
|
-
let needComma: boolean = configBody.slice(-1) === "}";
|
|
474
|
-
if (needComma) configBody += ",";
|
|
475
|
-
configBody += `{
|
|
476
|
-
"tenantId": "${tci.tid}",
|
|
477
|
-
"sourceGroupId": ${sourceGroupId},
|
|
478
|
-
"sourceGroupName": ${sourceGroupName},
|
|
479
|
-
"targetGroupId": ${targetGroupId},
|
|
480
|
-
"targetGroupName": ${targetGroupName},
|
|
481
|
-
"configurationTenantType": "${tci.configurationTenantType}"
|
|
482
|
-
}`;
|
|
483
|
-
});
|
|
484
|
-
configBody += `]}`;
|
|
485
|
-
let options = { method: "POST", headers: headers, body: configBody };
|
|
486
|
-
// make config endpoint call
|
|
487
|
-
try {
|
|
488
|
-
if (debug) debugger;
|
|
489
|
-
console.log("Attempting POST to /config: " + endpoint);
|
|
490
|
-
let response = await fetch(endpoint, options);
|
|
491
|
-
if (response.status === 200 && response.statusText === "OK") {
|
|
492
|
-
let data = await response.json();
|
|
493
|
-
config.id = data;
|
|
494
|
-
console.log(
|
|
495
|
-
`Successful ConfigID: ${data} from POST to /config: ${configBody}`
|
|
496
|
-
);
|
|
497
|
-
return result;
|
|
498
|
-
}
|
|
499
|
-
else {
|
|
500
|
-
result.error = await processErrors(response);
|
|
501
|
-
console.log(`Failed PUT to /config: ${configBody}`);
|
|
502
|
-
console.log(result.error);
|
|
503
|
-
result.status = 500;
|
|
504
|
-
result.result = false;
|
|
505
|
-
return result;
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
catch (error: any) {
|
|
509
|
-
result.status = 500;
|
|
510
|
-
result.result = false;
|
|
511
|
-
result.error = error.message;
|
|
512
|
-
console.log(result.error);
|
|
513
|
-
return result;
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
//configPut
|
|
517
|
-
export async function configPut(
|
|
518
|
-
instance: IPublicClientApplication,
|
|
519
|
-
authorizedUser: User,
|
|
520
|
-
config: Config,
|
|
521
|
-
debug: boolean
|
|
522
|
-
): Promise<APIResult> {
|
|
523
|
-
let result: APIResult = new APIResult();
|
|
524
|
-
if (config.id === "") {
|
|
525
|
-
result.result = false;
|
|
526
|
-
result.error = "configPost: invalid config ID";
|
|
527
|
-
result.status = 500;
|
|
528
|
-
return result;
|
|
529
|
-
}
|
|
530
|
-
// create parametrized config endpoint
|
|
531
|
-
let endpoint: string = mindlineConfig.configEndpoint();
|
|
532
|
-
let url: URL = new URL(endpoint);
|
|
533
|
-
url.searchParams.append("configurationId", config.id);
|
|
534
|
-
// create config headers
|
|
535
|
-
const headers = await mindlineDefineHeaders(instance, authorizedUser);
|
|
536
|
-
// create config body
|
|
537
|
-
let configBody: string = `
|
|
538
|
-
{
|
|
539
|
-
"name": "${config.name}",
|
|
540
|
-
"description": "${config.description}",
|
|
541
|
-
"tenants": [`;
|
|
542
|
-
config.tenants.map((tci: TenantConfigInfo) => {
|
|
543
|
-
// if last character is } we need a comma first
|
|
544
|
-
let needComma: boolean = configBody.slice(-1) === "}";
|
|
545
|
-
if (needComma) configBody += ",";
|
|
546
|
-
// be sure we send null and not "null" in body
|
|
547
|
-
let sourceGroupId: string = tci.sourceGroupId != "" ? `"${tci.sourceGroupId}"` : "null";
|
|
548
|
-
let sourceGroupName: string = tci.sourceGroupName != "" ? `"${tci.sourceGroupName}"` : "null";
|
|
549
|
-
let targetGroupId: string = tci.targetGroupId != "" ? `"${tci.targetGroupId}"` : "null";
|
|
550
|
-
let targetGroupName: string = tci.targetGroupName != "" ? `"${tci.targetGroupName}"` : "null";
|
|
551
|
-
configBody += `{
|
|
552
|
-
"tenantId": "${tci.tid}",
|
|
553
|
-
"sourceGroupId": ${sourceGroupId},
|
|
554
|
-
"sourceGroupName": ${sourceGroupName},
|
|
555
|
-
"targetGroupId": ${targetGroupId},
|
|
556
|
-
"targetGroupName": ${targetGroupName},
|
|
557
|
-
"configurationTenantType": "${tci.configurationTenantType}",
|
|
558
|
-
"deltaToken": "${tci.deltaToken}"
|
|
559
|
-
}`;
|
|
560
|
-
});
|
|
561
|
-
configBody += `]}`;
|
|
562
|
-
let options = { method: "PUT", headers: headers, body: configBody };
|
|
563
|
-
// make config endpoint call
|
|
564
|
-
try {
|
|
565
|
-
if (debug) debugger;
|
|
566
|
-
console.log("Attempting PUT to /config: " + url.href);
|
|
567
|
-
let response = await fetch(url.href, options);
|
|
568
|
-
if (response.status === 200 && response.statusText === "OK") {
|
|
569
|
-
console.log(`Successful PUT to ${url.href}: ${configBody}`);
|
|
570
|
-
return result;
|
|
571
|
-
}
|
|
572
|
-
else {
|
|
573
|
-
result.error = await processErrors(response);
|
|
574
|
-
console.log(`Failed PUT to ${url.href}: ${configBody}`);
|
|
575
|
-
console.log(result.error);
|
|
576
|
-
result.status = 500;
|
|
577
|
-
result.result = false;
|
|
578
|
-
return result;
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
catch (error: any) {
|
|
582
|
-
result.error = error.message;
|
|
583
|
-
result.status = 500;
|
|
584
|
-
result.result = false;
|
|
585
|
-
console.log(error.message);
|
|
586
|
-
}
|
|
587
|
-
return result;
|
|
588
|
-
}
|
|
589
|
-
//configsGet
|
|
590
|
-
export async function configsGet(
|
|
591
|
-
instance: IPublicClientApplication,
|
|
592
|
-
user: User,
|
|
593
|
-
workspaceID: string,
|
|
594
|
-
debug: boolean
|
|
595
|
-
): Promise<APIResult> {
|
|
596
|
-
let result: APIResult = new APIResult();
|
|
597
|
-
// we need a workspace id
|
|
598
|
-
if (workspaceID === "") {
|
|
599
|
-
result.result = false;
|
|
600
|
-
result.status = 500;
|
|
601
|
-
result.error = "configsGet: no workspace provided";
|
|
602
|
-
return result;
|
|
603
|
-
}
|
|
604
|
-
// create endpoint
|
|
605
|
-
let endpoint: string = mindlineConfig.configsEndpoint();
|
|
606
|
-
// add parameter to endpoint
|
|
607
|
-
let url: URL = new URL(endpoint);
|
|
608
|
-
url.searchParams.append("workspaceId", workspaceID);
|
|
609
|
-
// create headers
|
|
610
|
-
const headers = await mindlineDefineHeaders(instance, user);
|
|
611
|
-
// make endpoint call
|
|
612
|
-
let options = { method: "GET", headers: headers };
|
|
613
|
-
try {
|
|
614
|
-
if (debug) debugger;
|
|
615
|
-
console.log("Attempting GET from /configurations: " + url.href);
|
|
616
|
-
let response = await fetch(url.href, options);
|
|
617
|
-
if (response.status === 200 && response.statusText === "OK") {
|
|
618
|
-
let returnedArray: Array<Object> = await response.json();
|
|
619
|
-
if (returnedArray != null) {
|
|
620
|
-
result.array = returnedArray;
|
|
621
|
-
let initialValue: string = "";
|
|
622
|
-
console.log(`Successful GET from /configurations: ${result.array.reduce((acc, curr) => acc + curr.name + " ", initialValue)}`);
|
|
623
|
-
return result;
|
|
624
|
-
}
|
|
625
|
-
else {
|
|
626
|
-
result.error = `Failed GET from /configurations: failed to JSON-parse response`;
|
|
627
|
-
console.log(result.error);
|
|
628
|
-
result.status = 500;
|
|
629
|
-
result.result = false;
|
|
630
|
-
return result;
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
else {
|
|
634
|
-
console.log(`Failed GET from /configurations: ${url.href}`);
|
|
635
|
-
result.error = await processErrors(response);
|
|
636
|
-
result.status = 500;
|
|
637
|
-
result.result = false;
|
|
638
|
-
console.log(result.error);
|
|
639
|
-
return result;
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
catch (error: any) {
|
|
643
|
-
result.error = error.message;
|
|
644
|
-
result.status = 500;
|
|
645
|
-
result.result = false;
|
|
646
|
-
console.log(error.message);
|
|
647
|
-
}
|
|
648
|
-
return result;
|
|
649
|
-
}
|
|
650
|
-
//initPost
|
|
651
|
-
export async function initPost(
|
|
652
|
-
instance: IPublicClientApplication,
|
|
653
|
-
user: User,
|
|
654
|
-
debug: boolean
|
|
655
|
-
): Promise<APIResult> {
|
|
656
|
-
let result: APIResult = new APIResult();
|
|
657
|
-
// we expect valid company name and domain by this point
|
|
658
|
-
if (user.companyName === "" || user.companyDomain === "") {
|
|
659
|
-
result.result = false;
|
|
660
|
-
result.error = "initPost: invalid company name or domain"
|
|
661
|
-
result.status = 500;
|
|
662
|
-
return result;
|
|
663
|
-
}
|
|
664
|
-
// create init endpoint
|
|
665
|
-
let endpoint: string = mindlineConfig.initEndpoint();
|
|
666
|
-
// create init headers
|
|
667
|
-
const headers = await mindlineDefineHeaders(instance, user);
|
|
668
|
-
// create init body
|
|
669
|
-
let initBody: string = `
|
|
670
|
-
{
|
|
671
|
-
"tenantCreateModel": {
|
|
672
|
-
"tenantId": "${user.tid}",
|
|
673
|
-
"name": "${user.companyName}",
|
|
674
|
-
"domain": "${user.companyDomain}",
|
|
675
|
-
"type": "aad",
|
|
676
|
-
"authority": "${user.authority}"
|
|
677
|
-
}
|
|
678
|
-
}`;
|
|
679
|
-
let options = { method: "POST", headers: headers, body: initBody };
|
|
680
|
-
// make init endpoint call
|
|
681
|
-
try {
|
|
682
|
-
if (debug) debugger;
|
|
683
|
-
console.log("Attempting POST to /configuration/init: " + endpoint);
|
|
684
|
-
let response = await fetch(endpoint, options);
|
|
685
|
-
if (response.status === 200 && response.statusText === "OK") {
|
|
686
|
-
console.log(`Successful POST to /configuration/init: ${initBody}`);
|
|
687
|
-
return result;
|
|
688
|
-
}
|
|
689
|
-
else {
|
|
690
|
-
result.error = await processErrors(response);
|
|
691
|
-
result.status = 500;
|
|
692
|
-
result.result = false;
|
|
693
|
-
console.log(`Failed POST to /configuration/init: ${initBody}`);
|
|
694
|
-
console.log(result.error);
|
|
695
|
-
return result;
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
catch (error: any) {
|
|
699
|
-
result.error = error.message;
|
|
700
|
-
console.log(result.error);
|
|
701
|
-
}
|
|
702
|
-
result.status = 500;
|
|
703
|
-
result.result = false;
|
|
704
|
-
return result;
|
|
705
|
-
}
|
|
706
|
-
//tenantDelete
|
|
707
|
-
export async function tenantDelete(
|
|
708
|
-
instance: IPublicClientApplication,
|
|
709
|
-
authorizedUser: User,
|
|
710
|
-
tenant: Tenant,
|
|
711
|
-
workspaceId: string,
|
|
712
|
-
debug: boolean
|
|
713
|
-
): Promise<APIResult> {
|
|
714
|
-
let result: APIResult = new APIResult();
|
|
715
|
-
// we expect valid tid amd workspaceId
|
|
716
|
-
if (tenant.tid === "" || workspaceId === "") {
|
|
717
|
-
result.result = false;
|
|
718
|
-
result.error = "tenantDelete: invalid tid, workspaceId";
|
|
719
|
-
result.status = 500;
|
|
720
|
-
return result;
|
|
721
|
-
}
|
|
722
|
-
// create parametrized tenant endpoint
|
|
723
|
-
let url: URL = new URL(mindlineConfig.tenantEndpoint());
|
|
724
|
-
url.searchParams.append("tenantId", tenant.tid);
|
|
725
|
-
url.searchParams.append("workspaceId", workspaceId);
|
|
726
|
-
// create headers
|
|
727
|
-
const headers = await mindlineDefineHeaders(instance, authorizedUser);
|
|
728
|
-
// make tenant endpoint call
|
|
729
|
-
let options = { method: "DELETE", headers: headers };
|
|
730
|
-
try {
|
|
731
|
-
console.log("Attempting DELETE from /tenant: " + url.href);
|
|
732
|
-
let response = await fetch(url.href, options);
|
|
733
|
-
if (response.status === 200 && response.statusText === "OK") {
|
|
734
|
-
console.log(`Successful DELETE from /tenant: ${url.href}`);
|
|
735
|
-
return result;
|
|
736
|
-
}
|
|
737
|
-
else {
|
|
738
|
-
console.log(`Failed DELETE from /tenant: ${url.href}`);
|
|
739
|
-
result.error = await processErrors(response);
|
|
740
|
-
console.log(result.error);
|
|
741
|
-
result.status = 500;
|
|
742
|
-
result.result = false;
|
|
743
|
-
return result;
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
catch (error: any) {
|
|
747
|
-
result.error = error.message;
|
|
748
|
-
result.status = 500;
|
|
749
|
-
result.result = false;
|
|
750
|
-
console.log(result.error);
|
|
751
|
-
}
|
|
752
|
-
return result;
|
|
753
|
-
}
|
|
754
|
-
//tenantsGet
|
|
755
|
-
export async function tenantsGet(
|
|
756
|
-
instance: IPublicClientApplication,
|
|
757
|
-
user: User,
|
|
758
|
-
workspaceID: string,
|
|
759
|
-
debug: boolean
|
|
760
|
-
): Promise<APIResult> {
|
|
761
|
-
let result: APIResult = new APIResult();
|
|
762
|
-
// we need a workspace id
|
|
763
|
-
if (workspaceID === "") {
|
|
764
|
-
result.result = false;
|
|
765
|
-
result.status = 500;
|
|
766
|
-
result.error = "tenantsGet: no workspace provided";
|
|
767
|
-
return result;
|
|
768
|
-
}
|
|
769
|
-
// create endpoint
|
|
770
|
-
let endpoint: string = mindlineConfig.tenantsEndpoint();
|
|
771
|
-
// add parameter to endpoint
|
|
772
|
-
let url: URL = new URL(endpoint);
|
|
773
|
-
url.searchParams.append("workspaceId", workspaceID);
|
|
774
|
-
// create headers
|
|
775
|
-
const headers = await mindlineDefineHeaders(instance, user);
|
|
776
|
-
// make endpoint call
|
|
777
|
-
let options = { method: "GET", headers: headers };
|
|
778
|
-
try {
|
|
779
|
-
if (debug) debugger;
|
|
780
|
-
console.log(`Attempting GET from /tenants: ${url.href}`);
|
|
781
|
-
let response = await fetch(url.href, options);
|
|
782
|
-
if (response.status === 200 && response.statusText === "OK") {
|
|
783
|
-
let returnedArray: Array<Object> = await response.json();
|
|
784
|
-
if (returnedArray != null) {
|
|
785
|
-
result.array = returnedArray;
|
|
786
|
-
let initialValue: string = "";
|
|
787
|
-
console.log(`Successful GET from /tenants: ${result.array.reduce((acc, curr) => acc + curr.domain + " ", initialValue)}`);
|
|
788
|
-
return result;
|
|
789
|
-
}
|
|
790
|
-
else {
|
|
791
|
-
result.error = `Failed GET from /tenants: failed to JSON-parse response`;
|
|
792
|
-
console.log(result.error);
|
|
793
|
-
result.status = 500;
|
|
794
|
-
result.result = false;
|
|
795
|
-
return result;
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
else {
|
|
799
|
-
console.log(`Failed GET from /tenants: ${url.href}`);
|
|
800
|
-
result.error = await processErrors(response);
|
|
801
|
-
result.status = 500;
|
|
802
|
-
result.result = false;
|
|
803
|
-
console.log(result.error);
|
|
804
|
-
return result;
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
catch (error: any) {
|
|
808
|
-
result.error = error.message;
|
|
809
|
-
result.status = 500;
|
|
810
|
-
result.result = false;
|
|
811
|
-
console.log(error.message);
|
|
812
|
-
}
|
|
813
|
-
return result;
|
|
814
|
-
}
|
|
815
|
-
//tenantPost: write validated tenant to back end
|
|
816
|
-
export async function tenantPost(
|
|
817
|
-
instance: IPublicClientApplication,
|
|
818
|
-
addingUser: User,
|
|
819
|
-
tenant: Tenant,
|
|
820
|
-
workspaceId: string
|
|
821
|
-
): Promise<APIResult> {
|
|
822
|
-
let result: APIResult = new APIResult();
|
|
823
|
-
// we expect valid tid, name, validated domain
|
|
824
|
-
if (tenant.tid === "" || tenant.name === "" || tenant.domain === "") {
|
|
825
|
-
result.result = false;
|
|
826
|
-
result.error = "tenantPost: invalid tid, name, domain";
|
|
827
|
-
result.status = 500;
|
|
828
|
-
return result;
|
|
829
|
-
}
|
|
830
|
-
// create parametrized tenant endpoint
|
|
831
|
-
let endpoint: string = mindlineConfig.tenantEndpoint();
|
|
832
|
-
let url: URL = new URL(endpoint);
|
|
833
|
-
url.searchParams.append("workspaceId", workspaceId);
|
|
834
|
-
// create tenant headers
|
|
835
|
-
const headers = await mindlineDefineHeaders(instance, addingUser);
|
|
836
|
-
// create tenant body
|
|
837
|
-
let tenantBody: string = `
|
|
838
|
-
{"tenantId": "${tenant.tid}",
|
|
839
|
-
"name": "${tenant.name}",
|
|
840
|
-
"domain": "${tenant.domain}",
|
|
841
|
-
"type": 1,
|
|
842
|
-
"authority": "${tenant.authority}"
|
|
843
|
-
}`;
|
|
844
|
-
let options = { method: "POST", headers: headers, body: tenantBody };
|
|
845
|
-
// make tenant endpoint call
|
|
846
|
-
try {
|
|
847
|
-
console.log(`Attempting POST to ${url.href}: ${tenantBody}`);
|
|
848
|
-
let response = await fetch(url.href, options);
|
|
849
|
-
if (response.status === 200 && response.statusText === "OK") {
|
|
850
|
-
console.log(`Successful POST to ${url.href}: ${tenantBody}`);
|
|
851
|
-
return result;
|
|
852
|
-
}
|
|
853
|
-
else {
|
|
854
|
-
console.log(`Failed POST to ${url.href}: ${tenantBody}`);
|
|
855
|
-
result.error = await processErrors(response);
|
|
856
|
-
console.log(result.error);
|
|
857
|
-
result.status = 500;
|
|
858
|
-
result.result = false;
|
|
859
|
-
return result;
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
catch (error: any) {
|
|
863
|
-
result.error = error.message;
|
|
864
|
-
result.status = 500;
|
|
865
|
-
result.result = false;
|
|
866
|
-
console.log(result.error);
|
|
867
|
-
}
|
|
868
|
-
return result;
|
|
869
|
-
}
|
|
870
|
-
//workspacePut
|
|
871
|
-
export async function workspacePut(instance: IPublicClientApplication, authorizedUser: User, workspaceId: string, workspaceName: string): Promise<APIResult> {
|
|
872
|
-
let result: APIResult = new APIResult();
|
|
873
|
-
if (workspaceId == "" || workspaceName == "") {
|
|
874
|
-
result.result = false;
|
|
875
|
-
result.error = "workspacePut: invalid workspace ID or name";
|
|
876
|
-
result.status = 500;
|
|
877
|
-
return result;
|
|
878
|
-
}
|
|
879
|
-
// create parameterized workspace endpoint
|
|
880
|
-
let endpoint: string = mindlineConfig.workspaceEndpoint();
|
|
881
|
-
let url: URL = new URL(endpoint);
|
|
882
|
-
url.searchParams.append("workspaceId", workspaceId);
|
|
883
|
-
url.searchParams.append("workspaceName", workspaceName);
|
|
884
|
-
// create workspace headers
|
|
885
|
-
const headers = await mindlineDefineHeaders(instance, authorizedUser);
|
|
886
|
-
let options = { method: "PUT", headers: headers };
|
|
887
|
-
// make config endpoint call
|
|
888
|
-
try {
|
|
889
|
-
console.log("Attempting PUT to /workspace: " + url.href);
|
|
890
|
-
let response = await fetch(url.href, options);
|
|
891
|
-
if (response.status === 200 && response.statusText === "OK") {
|
|
892
|
-
console.log(`Successful PUT to ${url.href}`);
|
|
893
|
-
return result;
|
|
894
|
-
}
|
|
895
|
-
else {
|
|
896
|
-
result.error = await processErrors(response);
|
|
897
|
-
console.log(`Failed PUT to ${url.href}`);
|
|
898
|
-
console.log(result.error);
|
|
899
|
-
result.status = 500;
|
|
900
|
-
result.result = false;
|
|
901
|
-
return result;
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
|
-
catch (error: any) {
|
|
905
|
-
result.error = error.message;
|
|
906
|
-
result.status = 500;
|
|
907
|
-
result.result = false;
|
|
908
|
-
console.log(error.message);
|
|
909
|
-
}
|
|
910
|
-
return result;
|
|
911
|
-
}
|
|
912
|
-
//workspacesGet
|
|
913
|
-
export async function workspacesGet(
|
|
914
|
-
instance: IPublicClientApplication,
|
|
915
|
-
user: User,
|
|
916
|
-
debug: boolean
|
|
917
|
-
): Promise<APIResult> {
|
|
918
|
-
let result: APIResult = new APIResult();
|
|
919
|
-
// we need a valid email address
|
|
920
|
-
if (user.mail == undefined || user.mail == "") {
|
|
921
|
-
result.result = false;
|
|
922
|
-
result.status = 500;
|
|
923
|
-
result.error = "adminsGet: no workspace provided";
|
|
924
|
-
return result;
|
|
925
|
-
}
|
|
926
|
-
// create workspaces endpoint
|
|
927
|
-
let endpoint: string = mindlineConfig.workspacesEndpoint();
|
|
928
|
-
// create workspace endpoint
|
|
929
|
-
let url: URL = new URL(endpoint);
|
|
930
|
-
// create workspace headers
|
|
931
|
-
const headers = await mindlineDefineHeaders(instance, user);
|
|
932
|
-
// make workspace endpoint call
|
|
933
|
-
let options = { method: "GET", headers: headers };
|
|
934
|
-
try {
|
|
935
|
-
if (debug) debugger;
|
|
936
|
-
console.log("Attempting GET from /workspaces endpoint: " + url.href);
|
|
937
|
-
let response = await fetch(url.href, options);
|
|
938
|
-
if (response.status === 200 && response.statusText === "OK") {
|
|
939
|
-
let returnedArray: Array<Object> = await response.json();
|
|
940
|
-
if (returnedArray != null) {
|
|
941
|
-
result.array = returnedArray;
|
|
942
|
-
let initialValue: string = "";
|
|
943
|
-
console.log(`Successful GET from /workspaces: ${result.array.reduce((acc, curr) => acc + curr.name + " ", initialValue)}`);
|
|
944
|
-
return result;
|
|
945
|
-
}
|
|
946
|
-
else {
|
|
947
|
-
result.error = `Failed GET from /workspaces: failed to JSON-parse response`;
|
|
948
|
-
console.log(result.error);
|
|
949
|
-
result.status = 500;
|
|
950
|
-
result.result = false;
|
|
951
|
-
return result;
|
|
952
|
-
}
|
|
953
|
-
}
|
|
954
|
-
else {
|
|
955
|
-
console.log(`Failed GET from /workspaces: ${url.href}`);
|
|
956
|
-
result.error = await processErrors(response);
|
|
957
|
-
result.status = 500;
|
|
958
|
-
result.result = false;
|
|
959
|
-
console.log(result.error);
|
|
960
|
-
return result;
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
catch (error: any) {
|
|
964
|
-
result.error = error.message;
|
|
965
|
-
result.status = 500;
|
|
966
|
-
result.result = false;
|
|
967
|
-
console.log(error.message);
|
|
968
|
-
}
|
|
969
|
-
return result;
|
|
970
|
-
}
|
|
971
|
-
//readerPost
|
|
972
|
-
export async function readerPost(
|
|
973
|
-
instance: IPublicClientApplication,
|
|
974
|
-
authorizedUser: User,
|
|
975
|
-
config: Config
|
|
976
|
-
): Promise<APIResult> {
|
|
977
|
-
let result: APIResult = new APIResult();
|
|
978
|
-
if (instance == null || authorizedUser == null)
|
|
979
|
-
{
|
|
980
|
-
result.result = false;
|
|
981
|
-
result.error = "readerPost: invalid parameters";
|
|
982
|
-
result.status = 500;
|
|
983
|
-
return result;
|
|
984
|
-
}
|
|
985
|
-
// create reader endpoint
|
|
986
|
-
let readerEndpoint: string = mindlineConfig.readerStartSyncEndpoint();
|
|
987
|
-
let url: URL = new URL(readerEndpoint);
|
|
988
|
-
url.searchParams.append("configurationId", config.id);
|
|
989
|
-
// create headers
|
|
990
|
-
const headers = await mindlineDefineHeaders(instance, authorizedUser);
|
|
991
|
-
// make reader endpoint call
|
|
992
|
-
let options = { method: "POST", headers: headers };
|
|
993
|
-
try {
|
|
994
|
-
console.log("Attempting POST to /startSync: " + url.href);
|
|
995
|
-
let response = await fetch(url.href, options);
|
|
996
|
-
if (response.status === 200 && response.statusText === "OK") {
|
|
997
|
-
console.log(`Successful POST to /startSync: ${readerEndpoint}`);
|
|
998
|
-
let jsonResponse = await response.json();
|
|
999
|
-
if (jsonResponse.PayloadStr != "") {
|
|
1000
|
-
result.array = JSON.parse(jsonResponse.PayloadStr);
|
|
1001
|
-
}
|
|
1002
|
-
else {
|
|
1003
|
-
result.result = false;
|
|
1004
|
-
result.error = "readerPost: blank payload returned, sync may be disabled on back end";
|
|
1005
|
-
result.status = 500;
|
|
1006
|
-
}
|
|
1007
|
-
return result;
|
|
1008
|
-
} else {
|
|
1009
|
-
result.error = await processErrors(response);
|
|
1010
|
-
console.log(`Failed POST to /startSync: ${readerEndpoint}`);
|
|
1011
|
-
console.log(result.error);
|
|
1012
|
-
result.status = 500;
|
|
1013
|
-
result.result = false;
|
|
1014
|
-
return result;
|
|
1015
|
-
}
|
|
1016
|
-
} catch (error: any) {
|
|
1017
|
-
result.error = error.message;
|
|
1018
|
-
result.status = 500;
|
|
1019
|
-
result.result = false;
|
|
1020
|
-
console.log(error.message);
|
|
1021
|
-
}
|
|
1022
|
-
return result;
|
|
1023
|
-
}
|