@geexcode/geex-angular 0.0.35 → 0.0.36
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 +105 -175
- package/dist/index.mjs +105 -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,72 @@ 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
|
-
allOwned = (0, import_util.deepCopy)(orgs);
|
|
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 new Promise((resolve, reject) => {
|
|
247
|
+
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)));
|
|
248
|
+
let isFirstEmit = true;
|
|
249
|
+
orgs$.subscribe({
|
|
250
|
+
next: (orgs) => {
|
|
251
|
+
(0, import_core.runInInjectionContext)(injector, () => {
|
|
252
|
+
_orgsSignal.set(orgs);
|
|
253
|
+
const userData = geex.auth.user();
|
|
254
|
+
let allOwned = [];
|
|
255
|
+
if (orgs?.length && userData) {
|
|
256
|
+
if (userData.id === "000000000000000000000001") {
|
|
257
|
+
allOwned = (0, import_util.deepCopy)(orgs);
|
|
258
|
+
} else {
|
|
259
|
+
const ownedCodes = userData.orgs.map((x) => x.code);
|
|
260
|
+
allOwned = orgs.filter((o) => ownedCodes.some((code) => o.code.startsWith(code)));
|
|
302
261
|
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
262
|
+
}
|
|
263
|
+
_userOwnedOrgsSignal.set(allOwned);
|
|
264
|
+
if (isFirstEmit) {
|
|
265
|
+
isFirstEmit = false;
|
|
266
|
+
resolve();
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
},
|
|
270
|
+
error: (err) => {
|
|
271
|
+
console.error(err);
|
|
272
|
+
reject(err);
|
|
273
|
+
}
|
|
310
274
|
});
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
}
|
|
317
|
-
})();
|
|
318
|
-
return _initPromise;
|
|
275
|
+
});
|
|
276
|
+
_initialized = true;
|
|
277
|
+
} catch (error) {
|
|
278
|
+
console.error(error);
|
|
279
|
+
}
|
|
319
280
|
}
|
|
320
281
|
};
|
|
321
282
|
return module2;
|
|
322
283
|
}
|
|
323
284
|
function createMessagingModule(injector) {
|
|
324
|
-
let
|
|
325
|
-
_initPromise._completed = false;
|
|
285
|
+
let _initialized = false;
|
|
326
286
|
const module2 = {
|
|
327
287
|
async init(force = false) {
|
|
328
|
-
if (
|
|
288
|
+
if (_initialized && !force) {
|
|
329
289
|
return;
|
|
330
290
|
}
|
|
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;
|
|
291
|
+
try {
|
|
292
|
+
await geex.auth.init();
|
|
293
|
+
if (injector.get(import_angular_oauth2_oidc.OAuthService).hasValidAccessToken()) {
|
|
294
|
+
const subClient = injector.get(import_apollo_angular.Apollo).use("subscription");
|
|
295
|
+
subClient.subscribe({ query: GQL_ON_PUBLIC_NOTIFY }).pipe((0, import_rxjs.map)((res) => res?.data?.onPublicNotify)).subscribe((notify) => {
|
|
296
|
+
module2.onPublicNotify(notify);
|
|
297
|
+
});
|
|
348
298
|
}
|
|
349
|
-
|
|
350
|
-
|
|
299
|
+
_initialized = true;
|
|
300
|
+
} catch (err) {
|
|
301
|
+
console.error(err);
|
|
302
|
+
}
|
|
351
303
|
},
|
|
352
304
|
onPublicNotify(notify) {
|
|
353
305
|
console.log("Public notify", notify);
|
|
@@ -357,32 +309,19 @@ function createMessagingModule(injector) {
|
|
|
357
309
|
}
|
|
358
310
|
function createSettingsModule(injector) {
|
|
359
311
|
const _settingsSignal = (0, import_core.signal)([]);
|
|
360
|
-
let
|
|
361
|
-
_initPromise._completed = false;
|
|
312
|
+
let _initialized = false;
|
|
362
313
|
const module2 = {
|
|
363
|
-
settings:
|
|
314
|
+
settings: guardedSignal(_settingsSignal, () => _initialized),
|
|
364
315
|
async init(force = false) {
|
|
365
|
-
if (
|
|
316
|
+
if (_initialized && !force) {
|
|
366
317
|
return;
|
|
367
318
|
}
|
|
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;
|
|
319
|
+
const res = await (0, import_rxjs.firstValueFrom)(
|
|
320
|
+
injector.get(import_apollo_angular.Apollo).query({ query: GQL_INIT_SETTINGS })
|
|
321
|
+
);
|
|
322
|
+
const settings = res.data.initSettings;
|
|
323
|
+
_settingsSignal.set(settings);
|
|
324
|
+
_initialized = true;
|
|
386
325
|
}
|
|
387
326
|
};
|
|
388
327
|
return module2;
|
|
@@ -393,26 +332,17 @@ function createUiModule(injector) {
|
|
|
393
332
|
(0, import_operators.debounceTime)(200),
|
|
394
333
|
(0, import_operators.switchMap)(async () => window.innerHeight / window.innerWidth >= 1.5)
|
|
395
334
|
));
|
|
396
|
-
let
|
|
397
|
-
_initPromise._completed = false;
|
|
335
|
+
let _initialized = false;
|
|
398
336
|
const module2 = {
|
|
399
|
-
fullScreen:
|
|
400
|
-
isMobile: _isMobile,
|
|
337
|
+
fullScreen: guardedSignal(_fullScreenSignal, () => _initialized),
|
|
338
|
+
isMobile: guardedSignal(_isMobile, () => _initialized),
|
|
401
339
|
activeRoutedComponent: void 0,
|
|
402
340
|
async init(force = false) {
|
|
403
|
-
if (
|
|
341
|
+
if (_initialized && !force) {
|
|
404
342
|
return;
|
|
405
343
|
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
}
|
|
409
|
-
_initPromise = (async () => {
|
|
410
|
-
try {
|
|
411
|
-
} finally {
|
|
412
|
-
_initPromise._completed = true;
|
|
413
|
-
}
|
|
414
|
-
})();
|
|
415
|
-
return _initPromise;
|
|
344
|
+
_initialized = true;
|
|
345
|
+
return;
|
|
416
346
|
}
|
|
417
347
|
};
|
|
418
348
|
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,72 @@ 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
|
-
allOwned = deepCopy(orgs);
|
|
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 new Promise((resolve, reject) => {
|
|
201
|
+
const orgs$ = injector.get(Apollo).watchQuery({ query: GQL_ORGS_CACHE }).valueChanges.pipe(map((res) => deepCopy(res.data.orgs.items)));
|
|
202
|
+
let isFirstEmit = true;
|
|
203
|
+
orgs$.subscribe({
|
|
204
|
+
next: (orgs) => {
|
|
205
|
+
runInInjectionContext(injector, () => {
|
|
206
|
+
_orgsSignal.set(orgs);
|
|
207
|
+
const userData = geex.auth.user();
|
|
208
|
+
let allOwned = [];
|
|
209
|
+
if (orgs?.length && userData) {
|
|
210
|
+
if (userData.id === "000000000000000000000001") {
|
|
211
|
+
allOwned = deepCopy(orgs);
|
|
212
|
+
} else {
|
|
213
|
+
const ownedCodes = userData.orgs.map((x) => x.code);
|
|
214
|
+
allOwned = orgs.filter((o) => ownedCodes.some((code) => o.code.startsWith(code)));
|
|
256
215
|
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
216
|
+
}
|
|
217
|
+
_userOwnedOrgsSignal.set(allOwned);
|
|
218
|
+
if (isFirstEmit) {
|
|
219
|
+
isFirstEmit = false;
|
|
220
|
+
resolve();
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
},
|
|
224
|
+
error: (err) => {
|
|
225
|
+
console.error(err);
|
|
226
|
+
reject(err);
|
|
227
|
+
}
|
|
264
228
|
});
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
})();
|
|
272
|
-
return _initPromise;
|
|
229
|
+
});
|
|
230
|
+
_initialized = true;
|
|
231
|
+
} catch (error) {
|
|
232
|
+
console.error(error);
|
|
233
|
+
}
|
|
273
234
|
}
|
|
274
235
|
};
|
|
275
236
|
return module;
|
|
276
237
|
}
|
|
277
238
|
function createMessagingModule(injector) {
|
|
278
|
-
let
|
|
279
|
-
_initPromise._completed = false;
|
|
239
|
+
let _initialized = false;
|
|
280
240
|
const module = {
|
|
281
241
|
async init(force = false) {
|
|
282
|
-
if (
|
|
242
|
+
if (_initialized && !force) {
|
|
283
243
|
return;
|
|
284
244
|
}
|
|
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;
|
|
245
|
+
try {
|
|
246
|
+
await geex.auth.init();
|
|
247
|
+
if (injector.get(OAuthService).hasValidAccessToken()) {
|
|
248
|
+
const subClient = injector.get(Apollo).use("subscription");
|
|
249
|
+
subClient.subscribe({ query: GQL_ON_PUBLIC_NOTIFY }).pipe(map((res) => res?.data?.onPublicNotify)).subscribe((notify) => {
|
|
250
|
+
module.onPublicNotify(notify);
|
|
251
|
+
});
|
|
302
252
|
}
|
|
303
|
-
|
|
304
|
-
|
|
253
|
+
_initialized = true;
|
|
254
|
+
} catch (err) {
|
|
255
|
+
console.error(err);
|
|
256
|
+
}
|
|
305
257
|
},
|
|
306
258
|
onPublicNotify(notify) {
|
|
307
259
|
console.log("Public notify", notify);
|
|
@@ -311,32 +263,19 @@ function createMessagingModule(injector) {
|
|
|
311
263
|
}
|
|
312
264
|
function createSettingsModule(injector) {
|
|
313
265
|
const _settingsSignal = signal([]);
|
|
314
|
-
let
|
|
315
|
-
_initPromise._completed = false;
|
|
266
|
+
let _initialized = false;
|
|
316
267
|
const module = {
|
|
317
|
-
settings:
|
|
268
|
+
settings: guardedSignal(_settingsSignal, () => _initialized),
|
|
318
269
|
async init(force = false) {
|
|
319
|
-
if (
|
|
270
|
+
if (_initialized && !force) {
|
|
320
271
|
return;
|
|
321
272
|
}
|
|
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;
|
|
273
|
+
const res = await firstValueFrom(
|
|
274
|
+
injector.get(Apollo).query({ query: GQL_INIT_SETTINGS })
|
|
275
|
+
);
|
|
276
|
+
const settings = res.data.initSettings;
|
|
277
|
+
_settingsSignal.set(settings);
|
|
278
|
+
_initialized = true;
|
|
340
279
|
}
|
|
341
280
|
};
|
|
342
281
|
return module;
|
|
@@ -347,26 +286,17 @@ function createUiModule(injector) {
|
|
|
347
286
|
debounceTime(200),
|
|
348
287
|
switchMap(async () => window.innerHeight / window.innerWidth >= 1.5)
|
|
349
288
|
));
|
|
350
|
-
let
|
|
351
|
-
_initPromise._completed = false;
|
|
289
|
+
let _initialized = false;
|
|
352
290
|
const module = {
|
|
353
|
-
fullScreen:
|
|
354
|
-
isMobile: _isMobile,
|
|
291
|
+
fullScreen: guardedSignal(_fullScreenSignal, () => _initialized),
|
|
292
|
+
isMobile: guardedSignal(_isMobile, () => _initialized),
|
|
355
293
|
activeRoutedComponent: void 0,
|
|
356
294
|
async init(force = false) {
|
|
357
|
-
if (
|
|
295
|
+
if (_initialized && !force) {
|
|
358
296
|
return;
|
|
359
297
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
}
|
|
363
|
-
_initPromise = (async () => {
|
|
364
|
-
try {
|
|
365
|
-
} finally {
|
|
366
|
-
_initPromise._completed = true;
|
|
367
|
-
}
|
|
368
|
-
})();
|
|
369
|
-
return _initPromise;
|
|
298
|
+
_initialized = true;
|
|
299
|
+
return;
|
|
370
300
|
}
|
|
371
301
|
};
|
|
372
302
|
return module;
|