@geexcode/geex-angular 0.0.38 → 0.0.41
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/README.md +108 -0
- package/dist/README.md +108 -0
- package/dist/esbuild/gql-redirect.plugin.js +399 -261
- package/dist/fesm2022/geexcode-geex-angular.mjs +3111 -0
- package/dist/fesm2022/geexcode-geex-angular.mjs.map +1 -0
- package/dist/index.d.ts +994 -127
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -444
- package/dist/index.mjs +1 -397
- package/dist/rison/rison.js +553 -0
- package/dist/src/esbuild/gql-redirect.plugin.js +399 -0
- package/dist/src/rison/rison.js +553 -0
- package/package.json +87 -17
- package/dist/chunk-63O7VUAZ.mjs +0 -65
- package/dist/chunk-EBO3CZXG.mjs +0 -15
- package/dist/esbuild/gql-redirect.plugin.d.mts +0 -37
- package/dist/esbuild/gql-redirect.plugin.d.ts +0 -37
- package/dist/esbuild/gql-redirect.plugin.mjs +0 -269
- package/dist/index.d.mts +0 -148
package/dist/index.mjs
CHANGED
|
@@ -1,397 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
// src/provide-geex.ts
|
|
4
|
-
import { Injector as Injector3 } from "@angular/core";
|
|
5
|
-
|
|
6
|
-
// src/geex.ts
|
|
7
|
-
import { InjectionToken, runInInjectionContext as runInInjectionContext2 } from "@angular/core";
|
|
8
|
-
|
|
9
|
-
// src/modules.ts
|
|
10
|
-
import { Apollo } from "apollo-angular";
|
|
11
|
-
import { runInInjectionContext, signal } from "@angular/core";
|
|
12
|
-
import { OAuthService } from "angular-oauth2-oidc";
|
|
13
|
-
import { CookieService, deepCopy } from "@delon/util";
|
|
14
|
-
import gql from "graphql-tag";
|
|
15
|
-
import { firstValueFrom, map, fromEvent } from "rxjs";
|
|
16
|
-
import { debounceTime, switchMap } from "rxjs/operators";
|
|
17
|
-
import { toSignal } from "@angular/core/rxjs-interop";
|
|
18
|
-
var LoginProviderEnum = {
|
|
19
|
-
Local: "Local"
|
|
20
|
-
};
|
|
21
|
-
var OrgTypeEnum = {
|
|
22
|
-
Default: "Default"
|
|
23
|
-
};
|
|
24
|
-
var ExtensionModule = {};
|
|
25
|
-
var GQL_CHECK_TENANT = gql`mutation checkTenant($code: String!) { checkTenant(code: $code) { id code name isEnabled createdOn } }`;
|
|
26
|
-
var GQL_FEDERATE_AUTH = gql`mutation federateAuthenticate(
|
|
27
|
-
$code: String!
|
|
28
|
-
$loginProvider: LoginProviderEnum!
|
|
29
|
-
) {
|
|
30
|
-
federateAuthenticate(
|
|
31
|
-
request: { code: $code, loginProvider: $loginProvider }
|
|
32
|
-
) {
|
|
33
|
-
token
|
|
34
|
-
loginProvider
|
|
35
|
-
userId
|
|
36
|
-
name
|
|
37
|
-
user {
|
|
38
|
-
id
|
|
39
|
-
username
|
|
40
|
-
nickname
|
|
41
|
-
phoneNumber
|
|
42
|
-
email
|
|
43
|
-
isEnable
|
|
44
|
-
openId
|
|
45
|
-
loginProvider
|
|
46
|
-
createdOn
|
|
47
|
-
... on IUser {
|
|
48
|
-
roleNames
|
|
49
|
-
roleIds
|
|
50
|
-
permissions
|
|
51
|
-
orgCodes
|
|
52
|
-
avatarFileId
|
|
53
|
-
orgs {
|
|
54
|
-
allParentOrgs {
|
|
55
|
-
code
|
|
56
|
-
name
|
|
57
|
-
}
|
|
58
|
-
name
|
|
59
|
-
code
|
|
60
|
-
}
|
|
61
|
-
claims {
|
|
62
|
-
claimType
|
|
63
|
-
claimValue
|
|
64
|
-
}
|
|
65
|
-
avatarFile {
|
|
66
|
-
id
|
|
67
|
-
createdOn
|
|
68
|
-
fileSize
|
|
69
|
-
mimeType
|
|
70
|
-
storageType
|
|
71
|
-
fileName
|
|
72
|
-
md5
|
|
73
|
-
url
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
`;
|
|
80
|
-
var GQL_ON_PUBLIC_NOTIFY = gql`subscription onPublicNotify { onPublicNotify { __typename ... on DataChangeClientNotify { dataChangeType } } }`;
|
|
81
|
-
var GQL_ORGS_CACHE = gql`query orgsCache { orgs(take: 999) { items { id orgType code name parentOrgCode } } }`;
|
|
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
|
-
}
|
|
102
|
-
function createTenantModule(injector) {
|
|
103
|
-
const _current = signal(null);
|
|
104
|
-
let _initialized = false;
|
|
105
|
-
let _initPromise = null;
|
|
106
|
-
const module = {
|
|
107
|
-
get init() {
|
|
108
|
-
if (!_initPromise) {
|
|
109
|
-
_initPromise = (async () => {
|
|
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);
|
|
115
|
-
}
|
|
116
|
-
_initialized = true;
|
|
117
|
-
} catch (err) {
|
|
118
|
-
console.error(err);
|
|
119
|
-
}
|
|
120
|
-
})();
|
|
121
|
-
}
|
|
122
|
-
return _initPromise;
|
|
123
|
-
},
|
|
124
|
-
current: guardedSignal(_current, () => _initialized),
|
|
125
|
-
async loadTenantData(code) {
|
|
126
|
-
const res = await firstValueFrom(
|
|
127
|
-
injector.get(Apollo).mutate({ mutation: GQL_CHECK_TENANT, variables: { code } })
|
|
128
|
-
);
|
|
129
|
-
return res.data.checkTenant;
|
|
130
|
-
},
|
|
131
|
-
switchTenant(targetTenantCode) {
|
|
132
|
-
const domainParts = location.hostname.split(".");
|
|
133
|
-
if (domainParts.length > 2) {
|
|
134
|
-
domainParts.shift();
|
|
135
|
-
}
|
|
136
|
-
const rootDomain = domainParts.join(".");
|
|
137
|
-
injector.get(CookieService).put("__tenant", targetTenantCode, {
|
|
138
|
-
secure: false,
|
|
139
|
-
SameSite: "lax",
|
|
140
|
-
HttpOnly: false,
|
|
141
|
-
domain: rootDomain
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
return module;
|
|
146
|
-
}
|
|
147
|
-
function createAuthModule(injector) {
|
|
148
|
-
const _user = signal(null);
|
|
149
|
-
let _initialized = false;
|
|
150
|
-
let _initPromise = null;
|
|
151
|
-
const module = {
|
|
152
|
-
get init() {
|
|
153
|
-
if (!_initPromise) {
|
|
154
|
-
_initPromise = (async () => {
|
|
155
|
-
try {
|
|
156
|
-
const userData = await module.loadUserData();
|
|
157
|
-
_user.set(userData ?? null);
|
|
158
|
-
_initialized = true;
|
|
159
|
-
} catch (err) {
|
|
160
|
-
console.error(err);
|
|
161
|
-
}
|
|
162
|
-
})();
|
|
163
|
-
}
|
|
164
|
-
return _initPromise;
|
|
165
|
-
},
|
|
166
|
-
user: guardedSignal(_user, () => _initialized),
|
|
167
|
-
async loadUserData() {
|
|
168
|
-
const oAuthService = injector.get(OAuthService);
|
|
169
|
-
try {
|
|
170
|
-
await oAuthService.loadDiscoveryDocument();
|
|
171
|
-
if (!oAuthService.hasValidAccessToken()) {
|
|
172
|
-
return void 0;
|
|
173
|
-
}
|
|
174
|
-
await oAuthService.loadUserProfile();
|
|
175
|
-
const profile = oAuthService.getIdentityClaims();
|
|
176
|
-
if (profile) {
|
|
177
|
-
const result = await firstValueFrom(injector.get(Apollo).mutate({
|
|
178
|
-
mutation: GQL_FEDERATE_AUTH,
|
|
179
|
-
variables: {
|
|
180
|
-
code: oAuthService.getAccessToken(),
|
|
181
|
-
loginProvider: profile.login_provider
|
|
182
|
-
}
|
|
183
|
-
}).pipe(map((res) => res?.data?.federateAuthenticate.user)));
|
|
184
|
-
return result;
|
|
185
|
-
}
|
|
186
|
-
} catch (err) {
|
|
187
|
-
console.error(err);
|
|
188
|
-
}
|
|
189
|
-
return void 0;
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
return module;
|
|
193
|
-
}
|
|
194
|
-
function createIdentityModule(injector) {
|
|
195
|
-
const _orgsSignal = signal([]);
|
|
196
|
-
const _userOwnedOrgsSignal = signal([]);
|
|
197
|
-
let _initialized = false;
|
|
198
|
-
let _initPromise = null;
|
|
199
|
-
const module = {
|
|
200
|
-
orgs: guardedSignal(_orgsSignal, () => _initialized),
|
|
201
|
-
userOwnedOrgs: guardedSignal(_userOwnedOrgsSignal, () => _initialized),
|
|
202
|
-
get init() {
|
|
203
|
-
if (!_initPromise) {
|
|
204
|
-
_initPromise = (async () => {
|
|
205
|
-
try {
|
|
206
|
-
await geex.tenant.init;
|
|
207
|
-
await geex.auth.init;
|
|
208
|
-
await new Promise((resolve, reject) => {
|
|
209
|
-
const orgs$ = injector.get(Apollo).watchQuery({ query: GQL_ORGS_CACHE }).valueChanges.pipe(map((res) => deepCopy(res.data.orgs.items)));
|
|
210
|
-
orgs$.subscribe({
|
|
211
|
-
next: (orgs) => {
|
|
212
|
-
runInInjectionContext(injector, () => {
|
|
213
|
-
_orgsSignal.set(orgs);
|
|
214
|
-
const userData = geex.auth.user();
|
|
215
|
-
let allOwned = [];
|
|
216
|
-
if (orgs?.length && userData) {
|
|
217
|
-
if (userData.id === "000000000000000000000001") {
|
|
218
|
-
allOwned = deepCopy(orgs);
|
|
219
|
-
} else {
|
|
220
|
-
const ownedCodes = userData.orgs.map((x) => x.code);
|
|
221
|
-
allOwned = orgs.filter((o) => ownedCodes.some((code) => o.code.startsWith(code)));
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
_userOwnedOrgsSignal.set(allOwned);
|
|
225
|
-
resolve();
|
|
226
|
-
});
|
|
227
|
-
},
|
|
228
|
-
error: (err) => {
|
|
229
|
-
console.error(err);
|
|
230
|
-
reject(err);
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
_initialized = true;
|
|
235
|
-
} catch (error) {
|
|
236
|
-
console.error(error);
|
|
237
|
-
}
|
|
238
|
-
})();
|
|
239
|
-
}
|
|
240
|
-
return _initPromise;
|
|
241
|
-
}
|
|
242
|
-
};
|
|
243
|
-
return module;
|
|
244
|
-
}
|
|
245
|
-
function createMessagingModule(injector) {
|
|
246
|
-
let _initialized = false;
|
|
247
|
-
let _initPromise = null;
|
|
248
|
-
const module = {
|
|
249
|
-
get init() {
|
|
250
|
-
if (!_initPromise) {
|
|
251
|
-
_initPromise = (async () => {
|
|
252
|
-
try {
|
|
253
|
-
await geex.auth.init;
|
|
254
|
-
if (injector.get(OAuthService).hasValidAccessToken()) {
|
|
255
|
-
const subClient = injector.get(Apollo).use("subscription");
|
|
256
|
-
subClient.subscribe({ query: GQL_ON_PUBLIC_NOTIFY }).pipe(map((res) => res?.data?.onPublicNotify)).subscribe((notify) => {
|
|
257
|
-
module.onPublicNotify(notify);
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
_initialized = true;
|
|
261
|
-
} catch (err) {
|
|
262
|
-
console.error(err);
|
|
263
|
-
}
|
|
264
|
-
})();
|
|
265
|
-
}
|
|
266
|
-
return _initPromise;
|
|
267
|
-
},
|
|
268
|
-
onPublicNotify(notify) {
|
|
269
|
-
console.log("Public notify", notify);
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
return module;
|
|
273
|
-
}
|
|
274
|
-
function createSettingsModule(injector) {
|
|
275
|
-
const _settingsSignal = signal([]);
|
|
276
|
-
let _initialized = false;
|
|
277
|
-
let _initPromise = null;
|
|
278
|
-
const module = {
|
|
279
|
-
settings: guardedSignal(_settingsSignal, () => _initialized),
|
|
280
|
-
get init() {
|
|
281
|
-
if (!_initPromise) {
|
|
282
|
-
_initPromise = (async () => {
|
|
283
|
-
try {
|
|
284
|
-
const res = await firstValueFrom(
|
|
285
|
-
injector.get(Apollo).query({ query: GQL_INIT_SETTINGS })
|
|
286
|
-
);
|
|
287
|
-
const settings = res.data.initSettings;
|
|
288
|
-
_settingsSignal.set(settings);
|
|
289
|
-
_initialized = true;
|
|
290
|
-
} catch (err) {
|
|
291
|
-
console.error(err);
|
|
292
|
-
}
|
|
293
|
-
})();
|
|
294
|
-
}
|
|
295
|
-
return _initPromise;
|
|
296
|
-
}
|
|
297
|
-
};
|
|
298
|
-
return module;
|
|
299
|
-
}
|
|
300
|
-
function createUiModule(injector) {
|
|
301
|
-
const _fullScreenSignal = signal(false);
|
|
302
|
-
const _isMobile = toSignal(fromEvent(window, "resize").pipe(
|
|
303
|
-
debounceTime(200),
|
|
304
|
-
switchMap(async () => window.innerHeight / window.innerWidth >= 1.5)
|
|
305
|
-
));
|
|
306
|
-
let _initialized = false;
|
|
307
|
-
let _initPromise = null;
|
|
308
|
-
const module = {
|
|
309
|
-
fullScreen: guardedSignal(_fullScreenSignal, () => _initialized),
|
|
310
|
-
isMobile: guardedSignal(_isMobile, () => _initialized),
|
|
311
|
-
activeRoutedComponent: void 0,
|
|
312
|
-
get init() {
|
|
313
|
-
if (!_initPromise) {
|
|
314
|
-
_initPromise = (async () => {
|
|
315
|
-
_initialized = true;
|
|
316
|
-
})();
|
|
317
|
-
}
|
|
318
|
-
return _initPromise;
|
|
319
|
-
}
|
|
320
|
-
};
|
|
321
|
-
return module;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
// src/geex.ts
|
|
325
|
-
var geex;
|
|
326
|
-
var Geex = new InjectionToken("Geex");
|
|
327
|
-
function configGeex(injector, overrides = {}) {
|
|
328
|
-
runInInjectionContext2(injector, () => {
|
|
329
|
-
const modules = {
|
|
330
|
-
...overrides
|
|
331
|
-
};
|
|
332
|
-
let _initPromise = null;
|
|
333
|
-
if (!modules.init) {
|
|
334
|
-
Object.defineProperty(modules, "init", {
|
|
335
|
-
get() {
|
|
336
|
-
if (!_initPromise) {
|
|
337
|
-
_initPromise = (async () => {
|
|
338
|
-
const entries = Object.entries(modules).filter(([key]) => key !== "init");
|
|
339
|
-
return Object.fromEntries(await Promise.all(
|
|
340
|
-
entries.map(async ([key, mod]) => {
|
|
341
|
-
const maybeInit = mod.init;
|
|
342
|
-
try {
|
|
343
|
-
return [key, await maybeInit];
|
|
344
|
-
} catch (err) {
|
|
345
|
-
console.error(err);
|
|
346
|
-
return [key, null];
|
|
347
|
-
}
|
|
348
|
-
})
|
|
349
|
-
));
|
|
350
|
-
})();
|
|
351
|
-
}
|
|
352
|
-
return _initPromise;
|
|
353
|
-
}
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
modules.tenant ?? (modules.tenant = createTenantModule(injector));
|
|
357
|
-
modules.auth ?? (modules.auth = createAuthModule(injector));
|
|
358
|
-
modules.identity ?? (modules.identity = createIdentityModule(injector));
|
|
359
|
-
modules.messaging ?? (modules.messaging = createMessagingModule(injector));
|
|
360
|
-
modules.settings ?? (modules.settings = createSettingsModule(injector));
|
|
361
|
-
modules.ui ?? (modules.ui = createUiModule(injector));
|
|
362
|
-
geex = modules;
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
// src/provide-geex.ts
|
|
367
|
-
function provideGeex(overrides = {}, extensions = {}) {
|
|
368
|
-
return [
|
|
369
|
-
{
|
|
370
|
-
provide: Geex,
|
|
371
|
-
useFactory: (injector) => {
|
|
372
|
-
const mergedModules = {
|
|
373
|
-
...extensions,
|
|
374
|
-
...overrides
|
|
375
|
-
};
|
|
376
|
-
configGeex(injector, mergedModules);
|
|
377
|
-
return geex;
|
|
378
|
-
},
|
|
379
|
-
deps: [Injector3]
|
|
380
|
-
}
|
|
381
|
-
];
|
|
382
|
-
}
|
|
383
|
-
export {
|
|
384
|
-
ExtensionModule,
|
|
385
|
-
Geex,
|
|
386
|
-
LoginProviderEnum,
|
|
387
|
-
OrgTypeEnum,
|
|
388
|
-
configGeex,
|
|
389
|
-
createAuthModule,
|
|
390
|
-
createIdentityModule,
|
|
391
|
-
createMessagingModule,
|
|
392
|
-
createSettingsModule,
|
|
393
|
-
createTenantModule,
|
|
394
|
-
createUiModule,
|
|
395
|
-
geex,
|
|
396
|
-
provideGeex
|
|
397
|
-
};
|
|
1
|
+
export * from "./fesm2022/geexcode-geex-angular.mjs";
|