@geexcode/geex-angular 0.0.35 → 0.0.37
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/dist/index.js +103 -175
- package/dist/index.mjs +103 -175
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -61,37 +61,6 @@ var import_graphql_tag = __toESM(require("graphql-tag"));
|
|
|
61
61
|
var import_rxjs = require("rxjs");
|
|
62
62
|
var import_operators = require("rxjs/operators");
|
|
63
63
|
var import_rxjs_interop = require("@angular/core/rxjs-interop");
|
|
64
|
-
function wrapSignal(originalSignal, getInitPromise, timeout = 5e3) {
|
|
65
|
-
const checkInit = () => {
|
|
66
|
-
const initPromise = getInitPromise();
|
|
67
|
-
const timeoutPromise = new Promise(
|
|
68
|
-
(_, reject) => setTimeout(() => reject(new Error(`Module initialization timeout after ${timeout}ms`)), timeout)
|
|
69
|
-
);
|
|
70
|
-
return Promise.race([initPromise, timeoutPromise]);
|
|
71
|
-
};
|
|
72
|
-
let isWaiting = false;
|
|
73
|
-
let waitPromise = null;
|
|
74
|
-
const wrapped = (() => {
|
|
75
|
-
const promise = getInitPromise();
|
|
76
|
-
if (promise._completed) {
|
|
77
|
-
return originalSignal();
|
|
78
|
-
}
|
|
79
|
-
if (!isWaiting) {
|
|
80
|
-
isWaiting = true;
|
|
81
|
-
waitPromise = checkInit().finally(() => {
|
|
82
|
-
isWaiting = false;
|
|
83
|
-
waitPromise = null;
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
throw new Error(
|
|
87
|
-
"Signal accessed before module initialization completed. Please await module.init() or geex.init() before accessing signals."
|
|
88
|
-
);
|
|
89
|
-
});
|
|
90
|
-
wrapped.set = originalSignal.set.bind(originalSignal);
|
|
91
|
-
wrapped.update = originalSignal.update.bind(originalSignal);
|
|
92
|
-
wrapped.asReadonly = originalSignal.asReadonly.bind(originalSignal);
|
|
93
|
-
return wrapped;
|
|
94
|
-
}
|
|
95
64
|
var LoginProviderEnum = {
|
|
96
65
|
Local: "Local"
|
|
97
66
|
};
|
|
@@ -157,35 +126,45 @@ var GQL_FEDERATE_AUTH = import_graphql_tag.default`mutation federateAuthenticate
|
|
|
157
126
|
var GQL_ON_PUBLIC_NOTIFY = import_graphql_tag.default`subscription onPublicNotify { onPublicNotify { __typename ... on DataChangeClientNotify { dataChangeType } } }`;
|
|
158
127
|
var GQL_ORGS_CACHE = import_graphql_tag.default`query orgsCache { orgs(take: 999) { items { id orgType code name parentOrgCode } } }`;
|
|
159
128
|
var GQL_INIT_SETTINGS = import_graphql_tag.default`query initSettings { initSettings { id name value } }`;
|
|
129
|
+
function guardedSignal(innerSignal, isInitialized) {
|
|
130
|
+
const guard = (() => {
|
|
131
|
+
if (!isInitialized()) {
|
|
132
|
+
throw new Error(`GuardedSignal not initialized.
|
|
133
|
+
isInitialized: ${isInitialized.toString()}
|
|
134
|
+
innerSignal: ${innerSignal.toString()}
|
|
135
|
+
`);
|
|
136
|
+
}
|
|
137
|
+
return innerSignal();
|
|
138
|
+
});
|
|
139
|
+
if ("set" in innerSignal) {
|
|
140
|
+
guard.set = innerSignal.set.bind(innerSignal);
|
|
141
|
+
guard.update = innerSignal.update.bind(innerSignal);
|
|
142
|
+
}
|
|
143
|
+
if ("asReadonly" in innerSignal) {
|
|
144
|
+
guard.asReadonly = innerSignal.asReadonly.bind(innerSignal);
|
|
145
|
+
}
|
|
146
|
+
return guard;
|
|
147
|
+
}
|
|
160
148
|
function createTenantModule(injector) {
|
|
161
149
|
const _current = (0, import_core.signal)(null);
|
|
162
|
-
let
|
|
163
|
-
_initPromise._completed = false;
|
|
150
|
+
let _initialized = false;
|
|
164
151
|
const module2 = {
|
|
165
152
|
init: async (force = false) => {
|
|
166
|
-
if (
|
|
153
|
+
if (_initialized && !force) {
|
|
167
154
|
return;
|
|
168
155
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const tenantCode = injector.get(import_util.CookieService).get("__tenant");
|
|
175
|
-
if (tenantCode) {
|
|
176
|
-
const tenantData = await module2.loadTenantData(tenantCode);
|
|
177
|
-
_current.set(tenantData ?? null);
|
|
178
|
-
}
|
|
179
|
-
} catch (err) {
|
|
180
|
-
console.error(err);
|
|
181
|
-
throw err;
|
|
182
|
-
} finally {
|
|
183
|
-
_initPromise._completed = true;
|
|
156
|
+
try {
|
|
157
|
+
const tenantCode = injector.get(import_util.CookieService).get("__tenant");
|
|
158
|
+
if (tenantCode) {
|
|
159
|
+
const tenantData = await module2.loadTenantData(tenantCode);
|
|
160
|
+
_current.set(tenantData ?? null);
|
|
184
161
|
}
|
|
185
|
-
|
|
186
|
-
|
|
162
|
+
_initialized = true;
|
|
163
|
+
} catch (err) {
|
|
164
|
+
console.error(err);
|
|
165
|
+
}
|
|
187
166
|
},
|
|
188
|
-
current:
|
|
167
|
+
current: guardedSignal(_current, () => _initialized),
|
|
189
168
|
async loadTenantData(code) {
|
|
190
169
|
const res = await (0, import_rxjs.firstValueFrom)(
|
|
191
170
|
injector.get(import_apollo_angular.Apollo).mutate({ mutation: GQL_CHECK_TENANT, variables: { code } })
|
|
@@ -210,30 +189,21 @@ function createTenantModule(injector) {
|
|
|
210
189
|
}
|
|
211
190
|
function createAuthModule(injector) {
|
|
212
191
|
const _user = (0, import_core.signal)(null);
|
|
213
|
-
let
|
|
214
|
-
_initPromise._completed = false;
|
|
192
|
+
let _initialized = false;
|
|
215
193
|
const module2 = {
|
|
216
194
|
init: async (force = false) => {
|
|
217
|
-
if (
|
|
195
|
+
if (_initialized && !force) {
|
|
218
196
|
return;
|
|
219
197
|
}
|
|
220
|
-
|
|
221
|
-
|
|
198
|
+
try {
|
|
199
|
+
const userData = await module2.loadUserData();
|
|
200
|
+
_user.set(userData ?? null);
|
|
201
|
+
_initialized = true;
|
|
202
|
+
} catch (err) {
|
|
203
|
+
console.error(err);
|
|
222
204
|
}
|
|
223
|
-
_initPromise = (async () => {
|
|
224
|
-
try {
|
|
225
|
-
const userData = await module2.loadUserData();
|
|
226
|
-
_user.set(userData ?? null);
|
|
227
|
-
} catch (err) {
|
|
228
|
-
console.error(err);
|
|
229
|
-
throw err;
|
|
230
|
-
} finally {
|
|
231
|
-
_initPromise._completed = true;
|
|
232
|
-
}
|
|
233
|
-
})();
|
|
234
|
-
return _initPromise;
|
|
235
205
|
},
|
|
236
|
-
user:
|
|
206
|
+
user: guardedSignal(_user, () => _initialized),
|
|
237
207
|
async loadUserData() {
|
|
238
208
|
const oAuthService = injector.get(import_angular_oauth2_oidc.OAuthService);
|
|
239
209
|
try {
|
|
@@ -264,90 +234,70 @@ function createAuthModule(injector) {
|
|
|
264
234
|
function createIdentityModule(injector) {
|
|
265
235
|
const _orgsSignal = (0, import_core.signal)([]);
|
|
266
236
|
const _userOwnedOrgsSignal = (0, import_core.signal)([]);
|
|
267
|
-
let
|
|
268
|
-
_initPromise._completed = false;
|
|
237
|
+
let _initialized = false;
|
|
269
238
|
const module2 = {
|
|
270
|
-
orgs:
|
|
271
|
-
userOwnedOrgs:
|
|
239
|
+
orgs: guardedSignal(_orgsSignal, () => _initialized),
|
|
240
|
+
userOwnedOrgs: guardedSignal(_userOwnedOrgsSignal, () => _initialized),
|
|
272
241
|
async init(force = false) {
|
|
273
|
-
if (
|
|
242
|
+
if (_initialized && !force) {
|
|
274
243
|
return;
|
|
275
244
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
} else {
|
|
294
|
-
const ownedCodes = userData.orgs.map((x) => x.code);
|
|
295
|
-
allOwned = orgs.filter((o) => ownedCodes.some((code) => o.code.startsWith(code)));
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
_userOwnedOrgsSignal.set(allOwned);
|
|
299
|
-
if (isFirstEmit) {
|
|
300
|
-
isFirstEmit = false;
|
|
301
|
-
resolve();
|
|
245
|
+
try {
|
|
246
|
+
await geex.tenant.init();
|
|
247
|
+
await geex.auth.init();
|
|
248
|
+
await new Promise((resolve, reject) => {
|
|
249
|
+
const orgs$ = injector.get(import_apollo_angular.Apollo).watchQuery({ query: GQL_ORGS_CACHE }).valueChanges.pipe((0, import_rxjs.map)((res) => (0, import_util.deepCopy)(res.data.orgs.items)));
|
|
250
|
+
orgs$.subscribe({
|
|
251
|
+
next: (orgs) => {
|
|
252
|
+
(0, import_core.runInInjectionContext)(injector, () => {
|
|
253
|
+
_orgsSignal.set(orgs);
|
|
254
|
+
const userData = geex.auth.user();
|
|
255
|
+
let allOwned = [];
|
|
256
|
+
if (orgs?.length && userData) {
|
|
257
|
+
if (userData.id === "000000000000000000000001") {
|
|
258
|
+
allOwned = (0, import_util.deepCopy)(orgs);
|
|
259
|
+
} else {
|
|
260
|
+
const ownedCodes = userData.orgs.map((x) => x.code);
|
|
261
|
+
allOwned = orgs.filter((o) => ownedCodes.some((code) => o.code.startsWith(code)));
|
|
302
262
|
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
263
|
+
}
|
|
264
|
+
_userOwnedOrgsSignal.set(allOwned);
|
|
265
|
+
resolve();
|
|
266
|
+
});
|
|
267
|
+
},
|
|
268
|
+
error: (err) => {
|
|
269
|
+
console.error(err);
|
|
270
|
+
reject(err);
|
|
271
|
+
}
|
|
310
272
|
});
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
}
|
|
317
|
-
})();
|
|
318
|
-
return _initPromise;
|
|
273
|
+
});
|
|
274
|
+
_initialized = true;
|
|
275
|
+
} catch (error) {
|
|
276
|
+
console.error(error);
|
|
277
|
+
}
|
|
319
278
|
}
|
|
320
279
|
};
|
|
321
280
|
return module2;
|
|
322
281
|
}
|
|
323
282
|
function createMessagingModule(injector) {
|
|
324
|
-
let
|
|
325
|
-
_initPromise._completed = false;
|
|
283
|
+
let _initialized = false;
|
|
326
284
|
const module2 = {
|
|
327
285
|
async init(force = false) {
|
|
328
|
-
if (
|
|
286
|
+
if (_initialized && !force) {
|
|
329
287
|
return;
|
|
330
288
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
const subClient = injector.get(import_apollo_angular.Apollo).use("subscription");
|
|
339
|
-
subClient.subscribe({ query: GQL_ON_PUBLIC_NOTIFY }).pipe((0, import_rxjs.map)((res) => res?.data?.onPublicNotify)).subscribe((notify) => {
|
|
340
|
-
module2.onPublicNotify(notify);
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
} catch (err) {
|
|
344
|
-
console.error(err);
|
|
345
|
-
throw err;
|
|
346
|
-
} finally {
|
|
347
|
-
_initPromise._completed = true;
|
|
289
|
+
try {
|
|
290
|
+
await geex.auth.init();
|
|
291
|
+
if (injector.get(import_angular_oauth2_oidc.OAuthService).hasValidAccessToken()) {
|
|
292
|
+
const subClient = injector.get(import_apollo_angular.Apollo).use("subscription");
|
|
293
|
+
subClient.subscribe({ query: GQL_ON_PUBLIC_NOTIFY }).pipe((0, import_rxjs.map)((res) => res?.data?.onPublicNotify)).subscribe((notify) => {
|
|
294
|
+
module2.onPublicNotify(notify);
|
|
295
|
+
});
|
|
348
296
|
}
|
|
349
|
-
|
|
350
|
-
|
|
297
|
+
_initialized = true;
|
|
298
|
+
} catch (err) {
|
|
299
|
+
console.error(err);
|
|
300
|
+
}
|
|
351
301
|
},
|
|
352
302
|
onPublicNotify(notify) {
|
|
353
303
|
console.log("Public notify", notify);
|
|
@@ -357,32 +307,19 @@ function createMessagingModule(injector) {
|
|
|
357
307
|
}
|
|
358
308
|
function createSettingsModule(injector) {
|
|
359
309
|
const _settingsSignal = (0, import_core.signal)([]);
|
|
360
|
-
let
|
|
361
|
-
_initPromise._completed = false;
|
|
310
|
+
let _initialized = false;
|
|
362
311
|
const module2 = {
|
|
363
|
-
settings:
|
|
312
|
+
settings: guardedSignal(_settingsSignal, () => _initialized),
|
|
364
313
|
async init(force = false) {
|
|
365
|
-
if (
|
|
314
|
+
if (_initialized && !force) {
|
|
366
315
|
return;
|
|
367
316
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
injector.get(import_apollo_angular.Apollo).query({ query: GQL_INIT_SETTINGS })
|
|
375
|
-
);
|
|
376
|
-
const settings = res.data.initSettings;
|
|
377
|
-
_settingsSignal.set(settings);
|
|
378
|
-
} catch (err) {
|
|
379
|
-
console.error(err);
|
|
380
|
-
throw err;
|
|
381
|
-
} finally {
|
|
382
|
-
_initPromise._completed = true;
|
|
383
|
-
}
|
|
384
|
-
})();
|
|
385
|
-
return _initPromise;
|
|
317
|
+
const res = await (0, import_rxjs.firstValueFrom)(
|
|
318
|
+
injector.get(import_apollo_angular.Apollo).query({ query: GQL_INIT_SETTINGS })
|
|
319
|
+
);
|
|
320
|
+
const settings = res.data.initSettings;
|
|
321
|
+
_settingsSignal.set(settings);
|
|
322
|
+
_initialized = true;
|
|
386
323
|
}
|
|
387
324
|
};
|
|
388
325
|
return module2;
|
|
@@ -393,26 +330,17 @@ function createUiModule(injector) {
|
|
|
393
330
|
(0, import_operators.debounceTime)(200),
|
|
394
331
|
(0, import_operators.switchMap)(async () => window.innerHeight / window.innerWidth >= 1.5)
|
|
395
332
|
));
|
|
396
|
-
let
|
|
397
|
-
_initPromise._completed = false;
|
|
333
|
+
let _initialized = false;
|
|
398
334
|
const module2 = {
|
|
399
|
-
fullScreen:
|
|
400
|
-
isMobile: _isMobile,
|
|
335
|
+
fullScreen: guardedSignal(_fullScreenSignal, () => _initialized),
|
|
336
|
+
isMobile: guardedSignal(_isMobile, () => _initialized),
|
|
401
337
|
activeRoutedComponent: void 0,
|
|
402
338
|
async init(force = false) {
|
|
403
|
-
if (
|
|
339
|
+
if (_initialized && !force) {
|
|
404
340
|
return;
|
|
405
341
|
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
}
|
|
409
|
-
_initPromise = (async () => {
|
|
410
|
-
try {
|
|
411
|
-
} finally {
|
|
412
|
-
_initPromise._completed = true;
|
|
413
|
-
}
|
|
414
|
-
})();
|
|
415
|
-
return _initPromise;
|
|
342
|
+
_initialized = true;
|
|
343
|
+
return;
|
|
416
344
|
}
|
|
417
345
|
};
|
|
418
346
|
return module2;
|
package/dist/index.mjs
CHANGED
|
@@ -15,37 +15,6 @@ import gql from "graphql-tag";
|
|
|
15
15
|
import { firstValueFrom, map, fromEvent } from "rxjs";
|
|
16
16
|
import { debounceTime, switchMap } from "rxjs/operators";
|
|
17
17
|
import { toSignal } from "@angular/core/rxjs-interop";
|
|
18
|
-
function wrapSignal(originalSignal, getInitPromise, timeout = 5e3) {
|
|
19
|
-
const checkInit = () => {
|
|
20
|
-
const initPromise = getInitPromise();
|
|
21
|
-
const timeoutPromise = new Promise(
|
|
22
|
-
(_, reject) => setTimeout(() => reject(new Error(`Module initialization timeout after ${timeout}ms`)), timeout)
|
|
23
|
-
);
|
|
24
|
-
return Promise.race([initPromise, timeoutPromise]);
|
|
25
|
-
};
|
|
26
|
-
let isWaiting = false;
|
|
27
|
-
let waitPromise = null;
|
|
28
|
-
const wrapped = (() => {
|
|
29
|
-
const promise = getInitPromise();
|
|
30
|
-
if (promise._completed) {
|
|
31
|
-
return originalSignal();
|
|
32
|
-
}
|
|
33
|
-
if (!isWaiting) {
|
|
34
|
-
isWaiting = true;
|
|
35
|
-
waitPromise = checkInit().finally(() => {
|
|
36
|
-
isWaiting = false;
|
|
37
|
-
waitPromise = null;
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
throw new Error(
|
|
41
|
-
"Signal accessed before module initialization completed. Please await module.init() or geex.init() before accessing signals."
|
|
42
|
-
);
|
|
43
|
-
});
|
|
44
|
-
wrapped.set = originalSignal.set.bind(originalSignal);
|
|
45
|
-
wrapped.update = originalSignal.update.bind(originalSignal);
|
|
46
|
-
wrapped.asReadonly = originalSignal.asReadonly.bind(originalSignal);
|
|
47
|
-
return wrapped;
|
|
48
|
-
}
|
|
49
18
|
var LoginProviderEnum = {
|
|
50
19
|
Local: "Local"
|
|
51
20
|
};
|
|
@@ -111,35 +80,45 @@ var GQL_FEDERATE_AUTH = gql`mutation federateAuthenticate(
|
|
|
111
80
|
var GQL_ON_PUBLIC_NOTIFY = gql`subscription onPublicNotify { onPublicNotify { __typename ... on DataChangeClientNotify { dataChangeType } } }`;
|
|
112
81
|
var GQL_ORGS_CACHE = gql`query orgsCache { orgs(take: 999) { items { id orgType code name parentOrgCode } } }`;
|
|
113
82
|
var GQL_INIT_SETTINGS = gql`query initSettings { initSettings { id name value } }`;
|
|
83
|
+
function guardedSignal(innerSignal, isInitialized) {
|
|
84
|
+
const guard = (() => {
|
|
85
|
+
if (!isInitialized()) {
|
|
86
|
+
throw new Error(`GuardedSignal not initialized.
|
|
87
|
+
isInitialized: ${isInitialized.toString()}
|
|
88
|
+
innerSignal: ${innerSignal.toString()}
|
|
89
|
+
`);
|
|
90
|
+
}
|
|
91
|
+
return innerSignal();
|
|
92
|
+
});
|
|
93
|
+
if ("set" in innerSignal) {
|
|
94
|
+
guard.set = innerSignal.set.bind(innerSignal);
|
|
95
|
+
guard.update = innerSignal.update.bind(innerSignal);
|
|
96
|
+
}
|
|
97
|
+
if ("asReadonly" in innerSignal) {
|
|
98
|
+
guard.asReadonly = innerSignal.asReadonly.bind(innerSignal);
|
|
99
|
+
}
|
|
100
|
+
return guard;
|
|
101
|
+
}
|
|
114
102
|
function createTenantModule(injector) {
|
|
115
103
|
const _current = signal(null);
|
|
116
|
-
let
|
|
117
|
-
_initPromise._completed = false;
|
|
104
|
+
let _initialized = false;
|
|
118
105
|
const module = {
|
|
119
106
|
init: async (force = false) => {
|
|
120
|
-
if (
|
|
107
|
+
if (_initialized && !force) {
|
|
121
108
|
return;
|
|
122
109
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const tenantCode = injector.get(CookieService).get("__tenant");
|
|
129
|
-
if (tenantCode) {
|
|
130
|
-
const tenantData = await module.loadTenantData(tenantCode);
|
|
131
|
-
_current.set(tenantData ?? null);
|
|
132
|
-
}
|
|
133
|
-
} catch (err) {
|
|
134
|
-
console.error(err);
|
|
135
|
-
throw err;
|
|
136
|
-
} finally {
|
|
137
|
-
_initPromise._completed = true;
|
|
110
|
+
try {
|
|
111
|
+
const tenantCode = injector.get(CookieService).get("__tenant");
|
|
112
|
+
if (tenantCode) {
|
|
113
|
+
const tenantData = await module.loadTenantData(tenantCode);
|
|
114
|
+
_current.set(tenantData ?? null);
|
|
138
115
|
}
|
|
139
|
-
|
|
140
|
-
|
|
116
|
+
_initialized = true;
|
|
117
|
+
} catch (err) {
|
|
118
|
+
console.error(err);
|
|
119
|
+
}
|
|
141
120
|
},
|
|
142
|
-
current:
|
|
121
|
+
current: guardedSignal(_current, () => _initialized),
|
|
143
122
|
async loadTenantData(code) {
|
|
144
123
|
const res = await firstValueFrom(
|
|
145
124
|
injector.get(Apollo).mutate({ mutation: GQL_CHECK_TENANT, variables: { code } })
|
|
@@ -164,30 +143,21 @@ function createTenantModule(injector) {
|
|
|
164
143
|
}
|
|
165
144
|
function createAuthModule(injector) {
|
|
166
145
|
const _user = signal(null);
|
|
167
|
-
let
|
|
168
|
-
_initPromise._completed = false;
|
|
146
|
+
let _initialized = false;
|
|
169
147
|
const module = {
|
|
170
148
|
init: async (force = false) => {
|
|
171
|
-
if (
|
|
149
|
+
if (_initialized && !force) {
|
|
172
150
|
return;
|
|
173
151
|
}
|
|
174
|
-
|
|
175
|
-
|
|
152
|
+
try {
|
|
153
|
+
const userData = await module.loadUserData();
|
|
154
|
+
_user.set(userData ?? null);
|
|
155
|
+
_initialized = true;
|
|
156
|
+
} catch (err) {
|
|
157
|
+
console.error(err);
|
|
176
158
|
}
|
|
177
|
-
_initPromise = (async () => {
|
|
178
|
-
try {
|
|
179
|
-
const userData = await module.loadUserData();
|
|
180
|
-
_user.set(userData ?? null);
|
|
181
|
-
} catch (err) {
|
|
182
|
-
console.error(err);
|
|
183
|
-
throw err;
|
|
184
|
-
} finally {
|
|
185
|
-
_initPromise._completed = true;
|
|
186
|
-
}
|
|
187
|
-
})();
|
|
188
|
-
return _initPromise;
|
|
189
159
|
},
|
|
190
|
-
user:
|
|
160
|
+
user: guardedSignal(_user, () => _initialized),
|
|
191
161
|
async loadUserData() {
|
|
192
162
|
const oAuthService = injector.get(OAuthService);
|
|
193
163
|
try {
|
|
@@ -218,90 +188,70 @@ function createAuthModule(injector) {
|
|
|
218
188
|
function createIdentityModule(injector) {
|
|
219
189
|
const _orgsSignal = signal([]);
|
|
220
190
|
const _userOwnedOrgsSignal = signal([]);
|
|
221
|
-
let
|
|
222
|
-
_initPromise._completed = false;
|
|
191
|
+
let _initialized = false;
|
|
223
192
|
const module = {
|
|
224
|
-
orgs:
|
|
225
|
-
userOwnedOrgs:
|
|
193
|
+
orgs: guardedSignal(_orgsSignal, () => _initialized),
|
|
194
|
+
userOwnedOrgs: guardedSignal(_userOwnedOrgsSignal, () => _initialized),
|
|
226
195
|
async init(force = false) {
|
|
227
|
-
if (
|
|
196
|
+
if (_initialized && !force) {
|
|
228
197
|
return;
|
|
229
198
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
} else {
|
|
248
|
-
const ownedCodes = userData.orgs.map((x) => x.code);
|
|
249
|
-
allOwned = orgs.filter((o) => ownedCodes.some((code) => o.code.startsWith(code)));
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
_userOwnedOrgsSignal.set(allOwned);
|
|
253
|
-
if (isFirstEmit) {
|
|
254
|
-
isFirstEmit = false;
|
|
255
|
-
resolve();
|
|
199
|
+
try {
|
|
200
|
+
await geex.tenant.init();
|
|
201
|
+
await geex.auth.init();
|
|
202
|
+
await new Promise((resolve, reject) => {
|
|
203
|
+
const orgs$ = injector.get(Apollo).watchQuery({ query: GQL_ORGS_CACHE }).valueChanges.pipe(map((res) => deepCopy(res.data.orgs.items)));
|
|
204
|
+
orgs$.subscribe({
|
|
205
|
+
next: (orgs) => {
|
|
206
|
+
runInInjectionContext(injector, () => {
|
|
207
|
+
_orgsSignal.set(orgs);
|
|
208
|
+
const userData = geex.auth.user();
|
|
209
|
+
let allOwned = [];
|
|
210
|
+
if (orgs?.length && userData) {
|
|
211
|
+
if (userData.id === "000000000000000000000001") {
|
|
212
|
+
allOwned = deepCopy(orgs);
|
|
213
|
+
} else {
|
|
214
|
+
const ownedCodes = userData.orgs.map((x) => x.code);
|
|
215
|
+
allOwned = orgs.filter((o) => ownedCodes.some((code) => o.code.startsWith(code)));
|
|
256
216
|
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
217
|
+
}
|
|
218
|
+
_userOwnedOrgsSignal.set(allOwned);
|
|
219
|
+
resolve();
|
|
220
|
+
});
|
|
221
|
+
},
|
|
222
|
+
error: (err) => {
|
|
223
|
+
console.error(err);
|
|
224
|
+
reject(err);
|
|
225
|
+
}
|
|
264
226
|
});
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
})();
|
|
272
|
-
return _initPromise;
|
|
227
|
+
});
|
|
228
|
+
_initialized = true;
|
|
229
|
+
} catch (error) {
|
|
230
|
+
console.error(error);
|
|
231
|
+
}
|
|
273
232
|
}
|
|
274
233
|
};
|
|
275
234
|
return module;
|
|
276
235
|
}
|
|
277
236
|
function createMessagingModule(injector) {
|
|
278
|
-
let
|
|
279
|
-
_initPromise._completed = false;
|
|
237
|
+
let _initialized = false;
|
|
280
238
|
const module = {
|
|
281
239
|
async init(force = false) {
|
|
282
|
-
if (
|
|
240
|
+
if (_initialized && !force) {
|
|
283
241
|
return;
|
|
284
242
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
const subClient = injector.get(Apollo).use("subscription");
|
|
293
|
-
subClient.subscribe({ query: GQL_ON_PUBLIC_NOTIFY }).pipe(map((res) => res?.data?.onPublicNotify)).subscribe((notify) => {
|
|
294
|
-
module.onPublicNotify(notify);
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
} catch (err) {
|
|
298
|
-
console.error(err);
|
|
299
|
-
throw err;
|
|
300
|
-
} finally {
|
|
301
|
-
_initPromise._completed = true;
|
|
243
|
+
try {
|
|
244
|
+
await geex.auth.init();
|
|
245
|
+
if (injector.get(OAuthService).hasValidAccessToken()) {
|
|
246
|
+
const subClient = injector.get(Apollo).use("subscription");
|
|
247
|
+
subClient.subscribe({ query: GQL_ON_PUBLIC_NOTIFY }).pipe(map((res) => res?.data?.onPublicNotify)).subscribe((notify) => {
|
|
248
|
+
module.onPublicNotify(notify);
|
|
249
|
+
});
|
|
302
250
|
}
|
|
303
|
-
|
|
304
|
-
|
|
251
|
+
_initialized = true;
|
|
252
|
+
} catch (err) {
|
|
253
|
+
console.error(err);
|
|
254
|
+
}
|
|
305
255
|
},
|
|
306
256
|
onPublicNotify(notify) {
|
|
307
257
|
console.log("Public notify", notify);
|
|
@@ -311,32 +261,19 @@ function createMessagingModule(injector) {
|
|
|
311
261
|
}
|
|
312
262
|
function createSettingsModule(injector) {
|
|
313
263
|
const _settingsSignal = signal([]);
|
|
314
|
-
let
|
|
315
|
-
_initPromise._completed = false;
|
|
264
|
+
let _initialized = false;
|
|
316
265
|
const module = {
|
|
317
|
-
settings:
|
|
266
|
+
settings: guardedSignal(_settingsSignal, () => _initialized),
|
|
318
267
|
async init(force = false) {
|
|
319
|
-
if (
|
|
268
|
+
if (_initialized && !force) {
|
|
320
269
|
return;
|
|
321
270
|
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
injector.get(Apollo).query({ query: GQL_INIT_SETTINGS })
|
|
329
|
-
);
|
|
330
|
-
const settings = res.data.initSettings;
|
|
331
|
-
_settingsSignal.set(settings);
|
|
332
|
-
} catch (err) {
|
|
333
|
-
console.error(err);
|
|
334
|
-
throw err;
|
|
335
|
-
} finally {
|
|
336
|
-
_initPromise._completed = true;
|
|
337
|
-
}
|
|
338
|
-
})();
|
|
339
|
-
return _initPromise;
|
|
271
|
+
const res = await firstValueFrom(
|
|
272
|
+
injector.get(Apollo).query({ query: GQL_INIT_SETTINGS })
|
|
273
|
+
);
|
|
274
|
+
const settings = res.data.initSettings;
|
|
275
|
+
_settingsSignal.set(settings);
|
|
276
|
+
_initialized = true;
|
|
340
277
|
}
|
|
341
278
|
};
|
|
342
279
|
return module;
|
|
@@ -347,26 +284,17 @@ function createUiModule(injector) {
|
|
|
347
284
|
debounceTime(200),
|
|
348
285
|
switchMap(async () => window.innerHeight / window.innerWidth >= 1.5)
|
|
349
286
|
));
|
|
350
|
-
let
|
|
351
|
-
_initPromise._completed = false;
|
|
287
|
+
let _initialized = false;
|
|
352
288
|
const module = {
|
|
353
|
-
fullScreen:
|
|
354
|
-
isMobile: _isMobile,
|
|
289
|
+
fullScreen: guardedSignal(_fullScreenSignal, () => _initialized),
|
|
290
|
+
isMobile: guardedSignal(_isMobile, () => _initialized),
|
|
355
291
|
activeRoutedComponent: void 0,
|
|
356
292
|
async init(force = false) {
|
|
357
|
-
if (
|
|
293
|
+
if (_initialized && !force) {
|
|
358
294
|
return;
|
|
359
295
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
}
|
|
363
|
-
_initPromise = (async () => {
|
|
364
|
-
try {
|
|
365
|
-
} finally {
|
|
366
|
-
_initPromise._completed = true;
|
|
367
|
-
}
|
|
368
|
-
})();
|
|
369
|
-
return _initPromise;
|
|
296
|
+
_initialized = true;
|
|
297
|
+
return;
|
|
370
298
|
}
|
|
371
299
|
};
|
|
372
300
|
return module;
|