@haloduck/core 2.1.0 → 2.1.1

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.
@@ -0,0 +1,963 @@
1
+ import { from, switchMap, of, distinctUntilChanged, map, catchError, withLatestFrom, tap, forkJoin } from 'rxjs';
2
+ import { fetchAuthSession } from 'aws-amplify/auth';
3
+ import * as i0 from '@angular/core';
4
+ import { inject, isDevMode, Pipe, Injectable, InjectionToken, Inject } from '@angular/core';
5
+ import { createFeatureSelector, createSelector, Store, createAction, props, createReducer, on } from '@ngrx/store';
6
+ import { HttpClient } from '@angular/common/http';
7
+ import { map as map$1, catchError as catchError$1, withLatestFrom as withLatestFrom$1, mergeMap, finalize } from 'rxjs/operators';
8
+ import { ComponentStore } from '@ngrx/component-store';
9
+ import { Actions, createEffect, ofType } from '@ngrx/effects';
10
+
11
+ const authGuard = (route, state) => {
12
+ return from(fetchAuthSession()).pipe(switchMap((session) => {
13
+ if (session.tokens?.idToken) {
14
+ return of(true);
15
+ }
16
+ window.location.href = '/authenticate';
17
+ return of(false);
18
+ }));
19
+ };
20
+
21
+ // deprecated
22
+ const dummyMemberIdInterceptor = (req, next) => {
23
+ const dummyMemberId = localStorage.getItem('dummyMemberId');
24
+ if (req.url.startsWith('http://localhost')) {
25
+ if (dummyMemberId) {
26
+ const clonedRequest = req.clone({
27
+ setHeaders: {
28
+ 'X-Dummy-Member-Id': dummyMemberId || '',
29
+ },
30
+ });
31
+ return next(clonedRequest);
32
+ }
33
+ }
34
+ return next(req);
35
+ };
36
+
37
+ var GlobalSelectors;
38
+ (function (GlobalSelectors) {
39
+ GlobalSelectors.selectGlobalState = createFeatureSelector('global');
40
+ GlobalSelectors.isInitiated = createSelector(GlobalSelectors.selectGlobalState, (state) => state.initiated);
41
+ GlobalSelectors.selectIsAuthenticated = createSelector(GlobalSelectors.selectGlobalState, (state) => state.isAuthenticated);
42
+ GlobalSelectors.selectProfile = createSelector(GlobalSelectors.selectGlobalState, (state) => state.profile);
43
+ GlobalSelectors.selectIsLoading = createSelector(GlobalSelectors.selectGlobalState, (state) => state.loadingReference > 0);
44
+ GlobalSelectors.selectAcl = createSelector(GlobalSelectors.selectGlobalState, (state) => state.acl);
45
+ GlobalSelectors.selectListMenuItem = createSelector(GlobalSelectors.selectGlobalState, (state) => state.listMenuItem);
46
+ GlobalSelectors.selectIsSideMenuOpen = createSelector(GlobalSelectors.selectGlobalState, (state) => state.isSideMenuOpen);
47
+ GlobalSelectors.selectLanguage = createSelector(GlobalSelectors.selectGlobalState, (state) => state.language);
48
+ GlobalSelectors.canActivate = (resource, action, shouldStripTag) => createSelector(GlobalSelectors.selectAcl, (acl) => {
49
+ const allowedActions = [];
50
+ switch (action) {
51
+ case 'delete':
52
+ allowedActions.push('delete');
53
+ break;
54
+ case 'create':
55
+ allowedActions.push('delete');
56
+ allowedActions.push('create');
57
+ break;
58
+ case 'update':
59
+ allowedActions.push('delete');
60
+ allowedActions.push('create');
61
+ allowedActions.push('update');
62
+ break;
63
+ case 'read':
64
+ allowedActions.push('delete');
65
+ allowedActions.push('create');
66
+ allowedActions.push('update');
67
+ allowedActions.push('read');
68
+ }
69
+ const result = Object.keys(acl).some((aclKey) => {
70
+ return ['delete', 'create', 'update', 'read'].some((_action) => {
71
+ if (undefined === acl[aclKey][_action]) {
72
+ return false;
73
+ }
74
+ let [_resource, _conditionsRaw] = resource.split(':');
75
+ const _conditions = _conditionsRaw ? _conditionsRaw.split('|') : [];
76
+ _resource =
77
+ shouldStripTag && _resource.includes('/') ? _resource.split('/')[0] : _resource;
78
+ const _resourceAclArray = acl[aclKey][_action];
79
+ return _resourceAclArray.some((_resourceAclRaw) => {
80
+ const [_resourceAcl, _conditionsAclRaw] = _resourceAclRaw.split(':');
81
+ const _conditionsAcl = _conditionsAclRaw ? _conditionsAclRaw.split('|') : [];
82
+ if (_resourceAcl === '*') {
83
+ return true;
84
+ }
85
+ if (_resource === _resourceAcl &&
86
+ allowedActions.includes(_action) &&
87
+ (_conditions.length === 0 ||
88
+ _conditionsAcl.some((_condition) => _conditions.includes(_condition)))) {
89
+ return true;
90
+ }
91
+ return false;
92
+ });
93
+ });
94
+ });
95
+ return result;
96
+ });
97
+ GlobalSelectors.selectCurrentGroupId = createSelector(GlobalSelectors.selectGlobalState, (state) => state.currentGroup?.id);
98
+ GlobalSelectors.selectCurrentGroup = createSelector(GlobalSelectors.selectGlobalState, (state) => state.currentGroup);
99
+ })(GlobalSelectors || (GlobalSelectors = {}));
100
+
101
+ // deprecated
102
+ const groupIdInterceptor = (req, next) => {
103
+ const store = inject((Store));
104
+ const groupId$ = store.select(GlobalSelectors.selectCurrentGroupId);
105
+ if (req.url.endsWith('/member/me'))
106
+ return next(req);
107
+ if (req.url.endsWith('/menu'))
108
+ return next(req);
109
+ if (req.url.endsWith('/acl'))
110
+ return next(req);
111
+ if (req.url.startsWith('https://api') || req.url.startsWith('http://localhost')) {
112
+ return groupId$.pipe(switchMap((groupId) => {
113
+ if (groupId) {
114
+ const clonedRequest = req.clone({
115
+ setHeaders: {
116
+ 'X-Group-Id': groupId || '',
117
+ },
118
+ });
119
+ return next(clonedRequest);
120
+ }
121
+ return next(req);
122
+ }));
123
+ }
124
+ return next(req);
125
+ };
126
+
127
+ const idTokenInterceptor = (req, next) => {
128
+ if (req.url.endsWith('/oauth2/token'))
129
+ return next(req);
130
+ if (req.url.startsWith('https://api')) {
131
+ return from(fetchAuthSession()).pipe(switchMap((session) => {
132
+ if (session.tokens?.idToken) {
133
+ const clonedRequest = req.clone({
134
+ setHeaders: {
135
+ Authorization: `Bearer ${session.tokens.idToken}`,
136
+ },
137
+ });
138
+ return next(clonedRequest);
139
+ }
140
+ return next(req);
141
+ }));
142
+ }
143
+ else if (req.url.startsWith('https://auth') || req.url.startsWith('https://eleven-auth')) {
144
+ return from(fetchAuthSession()).pipe(switchMap((session) => {
145
+ if (session.tokens?.accessToken) {
146
+ const clonedRequest = req.clone({
147
+ setHeaders: {
148
+ Authorization: `Bearer ${session.tokens.accessToken}`,
149
+ },
150
+ });
151
+ return next(clonedRequest);
152
+ }
153
+ return next(req);
154
+ }));
155
+ }
156
+ return next(req);
157
+ };
158
+
159
+ var SearchParams;
160
+ (function (SearchParams) {
161
+ SearchParams.SortDirectionAsc = 'asc';
162
+ SearchParams.SortDirectionDesc = 'desc';
163
+ // export interface OrderAndPage{
164
+ // size: number;
165
+ // sort: Order[];
166
+ // searchAfter?: any[];
167
+ // }
168
+ })(SearchParams || (SearchParams = {}));
169
+
170
+ function responseHandler(response) {
171
+ if (!response) {
172
+ errorHandler({
173
+ error: 'empty response',
174
+ message: 'empty response',
175
+ });
176
+ }
177
+ if (response.error != '00') {
178
+ errorHandler({
179
+ error: response.error,
180
+ message: response.message,
181
+ });
182
+ }
183
+ return response;
184
+ }
185
+ function errorHandler(err) {
186
+ isDevMode() && console.error('API Error: ', err);
187
+ throw err;
188
+ }
189
+
190
+ class DisplayNamePipe {
191
+ transform(member) {
192
+ if (!member)
193
+ return '';
194
+ return member.nickname?.trim() || member.fullName || '' || (member.email || '').split('@')[0];
195
+ }
196
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: DisplayNamePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
197
+ static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.1.4", ngImport: i0, type: DisplayNamePipe, isStandalone: true, name: "displayName" });
198
+ }
199
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: DisplayNamePipe, decorators: [{
200
+ type: Pipe,
201
+ args: [{
202
+ name: 'displayName',
203
+ }]
204
+ }] });
205
+
206
+ var GlobalActions;
207
+ (function (GlobalActions) {
208
+ GlobalActions.markInitiated = createAction('[Global] Mark Initiated', props());
209
+ GlobalActions.clearAuthentication = createAction('[Global] Clear Authentication');
210
+ GlobalActions.setAuthenticated = createAction('[Global] Set Authenticated', props());
211
+ GlobalActions.setProfile = createAction('[Global] Set Profile', props());
212
+ GlobalActions.increaseLoadingReference = createAction('[Global] Increase Loading Reference');
213
+ GlobalActions.decreaseLoadingReference = createAction('[Global] Decrease Loading Reference');
214
+ GlobalActions.setAcl = createAction('[Global] Set Acl', props());
215
+ GlobalActions.setListMenuItem = createAction('[Global] Set List Menu Item', props());
216
+ GlobalActions.toggleSideMenu = createAction('[Global] Toggle Side Menu');
217
+ GlobalActions.closeSideMenu = createAction('[Global] Close Side Menu');
218
+ GlobalActions.setLanguage = createAction('[Global] Set Language', props());
219
+ GlobalActions.setCurrentGroup = createAction('[Global] Set Current Group', props());
220
+ })(GlobalActions || (GlobalActions = {}));
221
+
222
+ class AuthService {
223
+ globalStore = inject((Store));
224
+ canActivate(resource, action, shouldStripTag) {
225
+ return this.globalStore
226
+ .select(GlobalSelectors.canActivate(resource, action, shouldStripTag))
227
+ .pipe(distinctUntilChanged());
228
+ }
229
+ getProfile() {
230
+ return this.globalStore.select(GlobalSelectors.selectProfile);
231
+ }
232
+ setProfile(profile) {
233
+ return this.globalStore.dispatch(GlobalActions.setProfile({ profile }));
234
+ }
235
+ isAuthenticated() {
236
+ return this.globalStore
237
+ .select(GlobalSelectors.selectIsAuthenticated)
238
+ .pipe(distinctUntilChanged());
239
+ }
240
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: AuthService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
241
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: AuthService, providedIn: 'root' });
242
+ }
243
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: AuthService, decorators: [{
244
+ type: Injectable,
245
+ args: [{
246
+ providedIn: 'root',
247
+ }]
248
+ }] });
249
+
250
+ const defaultLanguage = { id: 'en', value: 'English' };
251
+ const supportedLanguages = [defaultLanguage, { id: 'ko', value: '한국어' }];
252
+ const HALODUCK_CORE_CONFIG = new InjectionToken('HALODUCK_CORE_CONFIG', {
253
+ providedIn: 'root',
254
+ factory: () => ({
255
+ stage: 'local',
256
+ appName: 'please-register-app-name-via-provideHaloduckCoreConfig',
257
+ defaultLanguage: defaultLanguage.id,
258
+ dateFormat: {
259
+ long: 'yyyy-MM-dd',
260
+ short: 'yyMMdd',
261
+ },
262
+ apiUrl: 'https://please-register-via-provideHaloduckCoreConfig.com',
263
+ cdnUrl: 'https://please-register-via-provideHaloduckCoreConfig.com',
264
+ map: {
265
+ mapId: 'please-register-map-id-via-provideHaloduckCoreConfig',
266
+ googleApiKey: 'please-register-google-api-key-via-provideHaloduckCoreConfig',
267
+ defaultLngLat: {
268
+ lat: 37.575971,
269
+ lng: 126.9768,
270
+ },
271
+ },
272
+ }),
273
+ });
274
+ function provideHaloduckCoreConfig(config) {
275
+ return {
276
+ provide: HALODUCK_CORE_CONFIG,
277
+ useValue: config,
278
+ };
279
+ }
280
+ class CoreService {
281
+ config = inject(HALODUCK_CORE_CONFIG);
282
+ constructor() { }
283
+ getStage() {
284
+ return this.config.stage;
285
+ }
286
+ getAppName() {
287
+ return this.config.appName;
288
+ }
289
+ getDefaultLanguage() {
290
+ return this.config.defaultLanguage;
291
+ }
292
+ getApiUrl() {
293
+ return this.config.apiUrl;
294
+ }
295
+ getCdnUrl() {
296
+ return this.config.cdnUrl;
297
+ }
298
+ getDateFormatLong() {
299
+ return this.config.dateFormat.long;
300
+ }
301
+ getDateFormatShort() {
302
+ return this.config.dateFormat.short;
303
+ }
304
+ getGoogleApiKey() {
305
+ return this.config.map.googleApiKey;
306
+ }
307
+ getMapId() {
308
+ return this.config.map.mapId;
309
+ }
310
+ getDefaultLngLat() {
311
+ return this.config.map.defaultLngLat;
312
+ }
313
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: CoreService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
314
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: CoreService, providedIn: 'root' });
315
+ }
316
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: CoreService, decorators: [{
317
+ type: Injectable,
318
+ args: [{
319
+ providedIn: 'root',
320
+ }]
321
+ }], ctorParameters: () => [] });
322
+
323
+ class BaseEntityApiService {
324
+ coreService = inject(CoreService);
325
+ http = inject(HttpClient);
326
+ apiUrl = this.coreService.getApiUrl();
327
+ createEntity(entity, parent) {
328
+ const url = `${this.apiUrl}/${parent ? (parent.name ? parent.name + '/' : '') + (parent.id ? parent.id + '/' : '') : ''}${this.getEntityName()}`;
329
+ return this.http.put(url, entity).pipe(map((response) => responseHandler(response)), catchError((error) => errorHandler(error)));
330
+ }
331
+ getListEntity(searchParams, parent) {
332
+ const filter = JSON.stringify(searchParams.filter);
333
+ const sort = JSON.stringify(searchParams.sort);
334
+ const page = searchParams.page ? JSON.stringify(searchParams.page) : '';
335
+ const url = `${this.apiUrl}/${parent ? (parent.name ? parent.name + '/' : '') + (parent.id ? parent.id + '/' : '') : ''}${this.getEntityName()}`;
336
+ return this.http
337
+ .get(url, {
338
+ params: { filter, sort, page },
339
+ })
340
+ .pipe(map((response) => responseHandler(response)), catchError((error) => errorHandler(error)));
341
+ }
342
+ getEntityById(id, parent) {
343
+ const url = `${this.apiUrl}/${parent ? (parent.name ? parent.name + '/' : '') + (parent.id ? parent.id + '/' : '') : ''}${this.getEntityName()}/${id}`;
344
+ return this.http.get(url).pipe(map((response) => responseHandler(response)), catchError((error) => errorHandler(error)));
345
+ }
346
+ updateEntityById(id, entity, parent) {
347
+ const url = `${this.apiUrl}/${parent ? (parent.name ? parent.name + '/' : '') + (parent.id ? parent.id + '/' : '') : ''}${this.getEntityName()}/${id}`;
348
+ return this.http.patch(url, entity).pipe(map((response) => responseHandler(response)), catchError((error) => errorHandler(error)));
349
+ }
350
+ deleteEntityById(id, parent) {
351
+ const url = `${this.apiUrl}/${parent ? (parent.name ? parent.name + '/' : '') + (parent.id ? parent.id + '/' : '') : ''}${this.getEntityName()}/${id}`;
352
+ return this.http.delete(url).pipe(map((response) => responseHandler(response)), catchError((error) => errorHandler(error)));
353
+ }
354
+ getEntityName() {
355
+ throw new Error('Method not implemented.');
356
+ }
357
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: BaseEntityApiService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
358
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: BaseEntityApiService, providedIn: 'root' });
359
+ }
360
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: BaseEntityApiService, decorators: [{
361
+ type: Injectable,
362
+ args: [{
363
+ providedIn: 'root',
364
+ }]
365
+ }] });
366
+
367
+ class CdnApiService {
368
+ coreService = inject(CoreService);
369
+ http = inject(HttpClient);
370
+ apiUrl = this.coreService.getApiUrl();
371
+ upload(file, keyPrefix) {
372
+ return this.getPresignedPutUrl(`${keyPrefix}/${file.name}`).pipe(switchMap((response) => {
373
+ const presignedUrl = response.data.url;
374
+ const key = response.data.key;
375
+ return this.uploadFile(presignedUrl, file).pipe(map(() => {
376
+ return key;
377
+ }), catchError((error) => {
378
+ console.error('Upload error:', error);
379
+ return errorHandler(error);
380
+ }));
381
+ }), catchError((error) => {
382
+ console.error('Error getting presigned URL:', error);
383
+ return errorHandler(error);
384
+ }));
385
+ }
386
+ getPresignedPutUrl(key) {
387
+ return this.http
388
+ .get(`${this.apiUrl}/tool/presignedPutUrl`, {
389
+ params: { key },
390
+ })
391
+ .pipe(map((response) => responseHandler(response)), catchError((error) => errorHandler(error)));
392
+ }
393
+ uploadFile(presignedUrl, file) {
394
+ return this.http
395
+ .put(presignedUrl, file, {
396
+ headers: { 'x-amz-tagging': 'expire1D=true' },
397
+ })
398
+ .pipe(catchError((error) => errorHandler(error)));
399
+ }
400
+ getPresignedGetUrl(key) {
401
+ return this.http
402
+ .get(`${this.apiUrl}/tool/presignedGetUrl`, {
403
+ params: { key },
404
+ })
405
+ .pipe(map((response) => responseHandler(response)), catchError((error) => errorHandler(error)), map((response) => response.data.url));
406
+ }
407
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: CdnApiService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
408
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: CdnApiService, providedIn: 'root' });
409
+ }
410
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: CdnApiService, decorators: [{
411
+ type: Injectable,
412
+ args: [{
413
+ providedIn: 'root',
414
+ }]
415
+ }] });
416
+
417
+ class GlobalApiService {
418
+ coreService = inject(CoreService);
419
+ http = inject(HttpClient);
420
+ apiUrl = this.coreService.getApiUrl();
421
+ getAcl() {
422
+ return this.http.get(`${this.apiUrl}/acl`).pipe(map((response) => responseHandler(response)), catchError((error) => errorHandler(error)));
423
+ }
424
+ getListMenuItem() {
425
+ return this.http.get(`${this.apiUrl}/menu`).pipe(map((response) => responseHandler(response)), catchError((error) => errorHandler(error)));
426
+ }
427
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: GlobalApiService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
428
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: GlobalApiService, providedIn: 'root' });
429
+ }
430
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: GlobalApiService, decorators: [{
431
+ type: Injectable,
432
+ args: [{
433
+ providedIn: 'root',
434
+ }]
435
+ }] });
436
+
437
+ class GroupApiService extends BaseEntityApiService {
438
+ getEntityName() {
439
+ return 'group';
440
+ }
441
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: GroupApiService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
442
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: GroupApiService, providedIn: 'root' });
443
+ }
444
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: GroupApiService, decorators: [{
445
+ type: Injectable,
446
+ args: [{
447
+ providedIn: 'root',
448
+ }]
449
+ }] });
450
+
451
+ class MemberApiService extends BaseEntityApiService {
452
+ getEntityName() {
453
+ return 'member';
454
+ }
455
+ getProfile() {
456
+ return this.http.get(`${this.apiUrl}/${this.getEntityName()}/me`).pipe(map$1((response) => responseHandler(response)), catchError$1((error) => errorHandler(error)));
457
+ }
458
+ updateProfile(id, profile) {
459
+ return this.http
460
+ .patch(`${this.apiUrl}/${this.getEntityName()}/me/${id}`, profile)
461
+ .pipe(map$1((response) => responseHandler(response)), catchError$1((error) => errorHandler(error)));
462
+ }
463
+ checkMemberByEmail(email) {
464
+ return this.http
465
+ .get(`${this.apiUrl}/${this.getEntityName()}/check/email/${email}`)
466
+ .pipe(map$1((response) => responseHandler(response)), catchError$1((error) => errorHandler(error)));
467
+ }
468
+ checkMemberByNickname(nickname) {
469
+ return this.http
470
+ .get(`${this.apiUrl}/${this.getEntityName()}/check/nickname/${nickname}`)
471
+ .pipe(map$1((response) => responseHandler(response)), catchError$1((error) => errorHandler(error)));
472
+ }
473
+ registration(member) {
474
+ return this.http
475
+ .put(`${this.apiUrl}/${this.getEntityName()}/registration`, member)
476
+ .pipe(map$1((response) => responseHandler(response)), catchError$1((error) => errorHandler(error)));
477
+ }
478
+ resetPassword(memberId, subDomain, language) {
479
+ return this.http
480
+ .post(`${this.apiUrl}/${this.getEntityName()}/${memberId}/resetPassword`, {
481
+ subDomain,
482
+ language,
483
+ })
484
+ .pipe(map$1((response) => responseHandler(response)), catchError$1((error) => errorHandler(error)));
485
+ }
486
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: MemberApiService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
487
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: MemberApiService, providedIn: 'root' });
488
+ }
489
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: MemberApiService, decorators: [{
490
+ type: Injectable,
491
+ args: [{
492
+ providedIn: 'root',
493
+ }]
494
+ }] });
495
+
496
+ class DeviceApiService extends BaseEntityApiService {
497
+ getEntityName() {
498
+ return 'device';
499
+ }
500
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: DeviceApiService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
501
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: DeviceApiService, providedIn: 'root' });
502
+ }
503
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: DeviceApiService, decorators: [{
504
+ type: Injectable,
505
+ args: [{
506
+ providedIn: 'root',
507
+ }]
508
+ }] });
509
+
510
+ const ITableStateStatusCreating = 'creating';
511
+ const ITableStateStatusCreated = 'created';
512
+ const ITableStateStatusFailedToCreate = 'failedToCreate';
513
+ const ITableStateStatusUpdating = 'updating';
514
+ const ITableStateStatusUpdated = 'updated';
515
+ const ITableStateStatusFailedToUpdate = 'failedToUpdate';
516
+ const ITableStateStatusDeleting = 'deleting';
517
+ const ITableStateStatusDeleted = 'deleted';
518
+ const ITableStateStatusFailedToDelete = 'failedToDelete';
519
+ const ITableStateStatusLoading = 'loading';
520
+ const ITableStateStatusLoaded = 'loaded';
521
+ const ITableStateStatusFailedToLoad = 'failedToLoad';
522
+ class TableStore extends ComponentStore {
523
+ initialState;
524
+ apiService;
525
+ // selectors
526
+ status$ = this.select((state) => state.status);
527
+ parent$ = this.select((state) => state.parent);
528
+ filter$ = this.select((state) => state.filter);
529
+ sort$ = this.select((state) => state.sort);
530
+ page$ = this.select((state) => state.page);
531
+ listEntity$ = this.select((state) => state.listEntity);
532
+ totalCount$ = this.select((state) => state.totalCount);
533
+ currentCount$ = this.select((state) => state.currentCount);
534
+ isLoading$ = this.select((state) => state.isLoading);
535
+ lastEvaluatedKey$ = this.select((state) => state.lastEvaluatedKey);
536
+ // effects
537
+ loadListEntity = this.effect((trigger$) => trigger$.pipe(withLatestFrom(this.listEntity$, this.filter$, this.sort$, this.page$, this.parent$), switchMap(([, listEntity, filter, sort, page, parent]) => {
538
+ this.updateStatus(ITableStateStatusLoading);
539
+ return this.apiService.getListEntity({ filter, sort, page }, parent).pipe(tap((response) => {
540
+ const totalCount = (listEntity.length === 0 ? response.total : this.get()?.totalCount) || 0;
541
+ listEntity = [...listEntity, ...(response.data ? response.data : [])];
542
+ const lastEvaluatedKey = totalCount > listEntity.length ? response.lastEvaluatedKey : undefined;
543
+ this.patchState({
544
+ listEntity,
545
+ totalCount,
546
+ currentCount: listEntity.length,
547
+ lastEvaluatedKey,
548
+ });
549
+ this.updateStatus(ITableStateStatusLoaded);
550
+ }), catchError(() => {
551
+ this.updateStatus(ITableStateStatusFailedToLoad);
552
+ return [];
553
+ }));
554
+ })));
555
+ createEntity = this.effect((trigger$) => trigger$.pipe(withLatestFrom(this.listEntity$, this.parent$), switchMap(([data, listEntity, parent]) => {
556
+ this.updateStatus(ITableStateStatusCreating);
557
+ return this.apiService.createEntity(data, parent).pipe(tap((response) => {
558
+ this.patchState({
559
+ listEntity: (() => {
560
+ if (response.data?.parentId) {
561
+ const updatedListEntity = listEntity.map((entity) => {
562
+ if (entity.id === response.data.parentId) {
563
+ return {
564
+ ...entity,
565
+ children: [
566
+ ...(entity.children
567
+ ? [response.data, ...entity.children]
568
+ : [response.data]),
569
+ ],
570
+ };
571
+ }
572
+ return entity;
573
+ });
574
+ const parentExists = updatedListEntity.some((entity) => entity.id === response.data.parentId);
575
+ if (!parentExists) {
576
+ return updatedListEntity.map((entity) => ({
577
+ ...entity,
578
+ children: entity.children?.map((child) => child.id === response.data.parentId
579
+ ? {
580
+ ...child,
581
+ children: [
582
+ ...(child.children
583
+ ? [response.data, ...child.children]
584
+ : [response.data]),
585
+ ],
586
+ }
587
+ : child),
588
+ }));
589
+ }
590
+ return updatedListEntity;
591
+ }
592
+ return [...(response.data ? [response.data] : []), ...listEntity];
593
+ })(),
594
+ });
595
+ this.updateStatus(ITableStateStatusCreated);
596
+ }), catchError(() => {
597
+ this.updateStatus(ITableStateStatusFailedToCreate);
598
+ return [];
599
+ }));
600
+ })));
601
+ getEntityById = this.effect((trigger$) => trigger$.pipe(withLatestFrom(this.listEntity$, this.parent$), switchMap(([id, listEntity, parent]) => {
602
+ this.updateStatus(ITableStateStatusLoading);
603
+ return this.apiService.getEntityById(id, parent).pipe(tap((response) => {
604
+ this.patchState({
605
+ listEntity: (() => {
606
+ if (response.data?.parentId) {
607
+ const updatedListEntity = listEntity.map((entity) => {
608
+ if (entity.id === response.data.parentId) {
609
+ return {
610
+ ...entity,
611
+ children: [
612
+ ...(entity.children
613
+ ? [response.data, ...entity.children]
614
+ : [response.data]),
615
+ ],
616
+ };
617
+ }
618
+ return entity;
619
+ });
620
+ const parentExists = updatedListEntity.some((entity) => entity.id === response.data.parentId);
621
+ if (!parentExists) {
622
+ return updatedListEntity.map((entity) => ({
623
+ ...entity,
624
+ children: entity.children?.map((child) => child.id === response.data.parentId
625
+ ? {
626
+ ...child,
627
+ children: [
628
+ ...(child.children
629
+ ? [response.data, ...child.children]
630
+ : [response.data]),
631
+ ],
632
+ }
633
+ : child),
634
+ }));
635
+ }
636
+ return updatedListEntity;
637
+ }
638
+ return listEntity.map((e) => (e.id === response.data.id ? response.data : e));
639
+ })(),
640
+ });
641
+ this.updateStatus(ITableStateStatusLoaded);
642
+ }), catchError(() => {
643
+ this.updateStatus(ITableStateStatusFailedToLoad);
644
+ return [];
645
+ }));
646
+ })));
647
+ updateEntityById = this.effect((trigger$) => trigger$.pipe(withLatestFrom(this.listEntity$, this.parent$), switchMap(([data, listEntity, parent]) => {
648
+ this.updateStatus(ITableStateStatusUpdating);
649
+ return this.apiService.updateEntityById(data.id, data.entity, parent).pipe(tap((response) => {
650
+ this.patchState({
651
+ listEntity: (() => {
652
+ if (response.data?.parentId) {
653
+ const updatedListEntity = listEntity.map((entity) => {
654
+ if (entity.id === response.data.parentId) {
655
+ return {
656
+ ...entity,
657
+ children: entity.children?.map((child) => child.id === response.data.id ? response.data : child),
658
+ };
659
+ }
660
+ return entity;
661
+ });
662
+ const parentExists = updatedListEntity.some((entity) => entity.id === response.data.parentId);
663
+ if (!parentExists) {
664
+ return updatedListEntity.map((entity) => ({
665
+ ...entity,
666
+ children: entity.children?.map((child) => child.id === response.data.parentId
667
+ ? {
668
+ ...child,
669
+ children: child.children?.map((grandChild) => grandChild.id === response.data.id ? response.data : grandChild),
670
+ }
671
+ : child),
672
+ }));
673
+ }
674
+ return updatedListEntity;
675
+ }
676
+ return listEntity.map((e) => (e.id === response.data.id ? response.data : e));
677
+ })(),
678
+ });
679
+ this.updateStatus(ITableStateStatusUpdated);
680
+ }), catchError(() => {
681
+ this.updateStatus(ITableStateStatusFailedToUpdate);
682
+ return [];
683
+ }));
684
+ })));
685
+ deleteEntityById = this.effect((trigger$) => trigger$.pipe(withLatestFrom(this.listEntity$, this.parent$), switchMap(([id, listEntity, parent]) => {
686
+ this.updateStatus(ITableStateStatusDeleting);
687
+ return this.apiService.deleteEntityById(id, parent).pipe(tap(() => {
688
+ this.patchState({
689
+ listEntity: listEntity.filter((e) => e.id !== id),
690
+ });
691
+ this.updateStatus(ITableStateStatusDeleted);
692
+ }), catchError(() => {
693
+ this.updateStatus(ITableStateStatusFailedToDelete);
694
+ return [];
695
+ }));
696
+ })));
697
+ // actions
698
+ updateEntity = this.updater((state, data) => ({
699
+ ...state,
700
+ listEntity: state.listEntity.map((e) => {
701
+ return e.id === data.id ? data : e;
702
+ }),
703
+ }));
704
+ updateStatus = this.updater((state, status) => ({
705
+ ...state,
706
+ status,
707
+ }));
708
+ setParent = this.updater((state, parent) => ({
709
+ ...state,
710
+ parent,
711
+ }));
712
+ updateSortField = this.updater((state, sort) => ({
713
+ ...state,
714
+ sort: [sort],
715
+ }));
716
+ updateFilter = this.updater((state, filter) => ({
717
+ ...state,
718
+ filter,
719
+ }));
720
+ updatePage = this.updater((state, page) => ({
721
+ ...state,
722
+ page,
723
+ }));
724
+ setExpandMode = this.updater((state, { id, mode }) => ({
725
+ ...state,
726
+ listEntity: state.listEntity.map((e) => ({
727
+ ...e,
728
+ expandMode: e.id === id ? mode : e.expandMode,
729
+ })),
730
+ }));
731
+ toggleExpanded = this.updater((state, { id }) => ({
732
+ ...state,
733
+ listEntity: state.listEntity.map((e) => ({
734
+ ...e,
735
+ isExpanded: e.id === id ? !(e.isExpanded || false) : e.isExpanded,
736
+ })),
737
+ }));
738
+ showExpanded = this.updater((state, { id }) => ({
739
+ ...state,
740
+ listEntity: state.listEntity.map((e) => ({
741
+ ...e,
742
+ isExpanded: e.id === id ? true : e.isExpanded,
743
+ })),
744
+ }));
745
+ hideExpanded = this.updater((state, { id }) => ({
746
+ ...state,
747
+ listEntity: state.listEntity.map((e) => ({
748
+ ...e,
749
+ isExpanded: e.id === id ? false : e.isExpanded,
750
+ })),
751
+ }));
752
+ toggleSelected = this.updater((state, { id }) => ({
753
+ ...state,
754
+ listEntity: state.listEntity.map((e) => ({
755
+ ...e,
756
+ isSelected: e.id === id ? !(e.isSelected || false) : e.isSelected,
757
+ })),
758
+ }));
759
+ constructor(initialState, apiService) {
760
+ super(initialState);
761
+ this.initialState = initialState;
762
+ this.apiService = apiService;
763
+ // this.loadListEntity();
764
+ }
765
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: TableStore, deps: [{ token: 'initialState' }, { token: 'apiService' }], target: i0.ɵɵFactoryTarget.Injectable });
766
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: TableStore });
767
+ }
768
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: TableStore, decorators: [{
769
+ type: Injectable
770
+ }], ctorParameters: () => [{ type: undefined, decorators: [{
771
+ type: Inject,
772
+ args: ['initialState']
773
+ }] }, { type: undefined, decorators: [{
774
+ type: Inject,
775
+ args: ['apiService']
776
+ }] }] });
777
+
778
+ class GroupStore extends TableStore {
779
+ constructor() {
780
+ super({
781
+ isLoading: false,
782
+ filter: {
783
+ dateRange: undefined,
784
+ organizationId: [],
785
+ id: [],
786
+ type: [],
787
+ active: null,
788
+ approved: null,
789
+ keyword: '',
790
+ },
791
+ sort: [
792
+ {
793
+ field: 'created_timestamp',
794
+ direction: SearchParams.SortDirectionDesc,
795
+ },
796
+ ],
797
+ page: {
798
+ limit: 10,
799
+ },
800
+ listEntity: [],
801
+ }, inject(GroupApiService));
802
+ }
803
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: GroupStore, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
804
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: GroupStore });
805
+ }
806
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: GroupStore, decorators: [{
807
+ type: Injectable
808
+ }], ctorParameters: () => [] });
809
+
810
+ class MemberStore extends TableStore {
811
+ constructor() {
812
+ super({
813
+ isLoading: false,
814
+ filter: {
815
+ dateRange: undefined,
816
+ organizationId: [],
817
+ groupId: [],
818
+ type: [],
819
+ active: null,
820
+ keyword: '',
821
+ },
822
+ sort: [
823
+ {
824
+ field: 'created_timestamp',
825
+ direction: SearchParams.SortDirectionDesc,
826
+ },
827
+ ],
828
+ page: {
829
+ limit: 10,
830
+ },
831
+ listEntity: [],
832
+ }, inject(MemberApiService));
833
+ }
834
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: MemberStore, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
835
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: MemberStore });
836
+ }
837
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: MemberStore, decorators: [{
838
+ type: Injectable
839
+ }], ctorParameters: () => [] });
840
+
841
+ var Device;
842
+ (function (Device) {
843
+ class DeviceStore extends TableStore {
844
+ constructor() {
845
+ super({
846
+ isLoading: false,
847
+ filter: {
848
+ campaignId: undefined,
849
+ type: [],
850
+ keyword: undefined,
851
+ },
852
+ sort: [
853
+ {
854
+ field: 'created_timestamp',
855
+ direction: SearchParams.SortDirectionDesc,
856
+ },
857
+ ],
858
+ page: {
859
+ limit: 10,
860
+ },
861
+ listEntity: [],
862
+ }, inject(DeviceApiService));
863
+ }
864
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: DeviceStore, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
865
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: DeviceStore });
866
+ }
867
+ Device.DeviceStore = DeviceStore;
868
+ })(Device || (Device = {}));
869
+
870
+ class GlobalEffects {
871
+ actions$ = inject(Actions);
872
+ memberApiService = inject(MemberApiService);
873
+ globalApiService = inject(GlobalApiService);
874
+ groupApiService = inject(GroupApiService);
875
+ store = inject((Store));
876
+ setAuthenticated$ = createEffect(() => this.actions$.pipe(ofType(GlobalActions.setAuthenticated), withLatestFrom$1(this.store.select(GlobalSelectors.selectIsAuthenticated)), mergeMap(([action, isAuthenticated]) => {
877
+ if (isAuthenticated) {
878
+ this.store.dispatch(GlobalActions.increaseLoadingReference());
879
+ return forkJoin({
880
+ profile: this.memberApiService.getProfile(),
881
+ acl: this.globalApiService.getAcl(),
882
+ listMenuItem: this.globalApiService.getListMenuItem(),
883
+ }).pipe(mergeMap(({ profile, acl, listMenuItem }) => {
884
+ const groupId = profile.data.groupId;
885
+ return this.groupApiService.getEntityById(groupId).pipe(mergeMap((group) => [
886
+ GlobalActions.setProfile({ profile: profile.data }),
887
+ GlobalActions.setAcl({ acl: acl.data }),
888
+ GlobalActions.setListMenuItem({
889
+ listMenuItem: listMenuItem.data,
890
+ }),
891
+ GlobalActions.setCurrentGroup({ group: group.data }),
892
+ GlobalActions.markInitiated({ initiated: true }),
893
+ ]));
894
+ }), catchError$1(() => of(GlobalActions.clearAuthentication())), finalize(() => {
895
+ this.store.dispatch(GlobalActions.decreaseLoadingReference());
896
+ }));
897
+ }
898
+ return of(GlobalActions.clearAuthentication());
899
+ })));
900
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: GlobalEffects, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
901
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: GlobalEffects });
902
+ }
903
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: GlobalEffects, decorators: [{
904
+ type: Injectable
905
+ }] });
906
+
907
+ const initialState = {
908
+ initiated: false,
909
+ isAuthenticated: false,
910
+ loadingReference: 0,
911
+ acl: {},
912
+ listMenuItem: [],
913
+ isSideMenuOpen: false,
914
+ language: 'en', // TODO: Use a proper language management system
915
+ profile: undefined,
916
+ currentGroup: undefined,
917
+ };
918
+
919
+ const globalReducer = createReducer(initialState, on(GlobalActions.markInitiated, (state) => ({
920
+ ...state,
921
+ initiated: true,
922
+ })), on(GlobalActions.setAuthenticated, (state, { isAuthenticated }) => ({
923
+ ...state,
924
+ isAuthenticated,
925
+ })), on(GlobalActions.setProfile, (state, { profile }) => ({
926
+ ...state,
927
+ profile,
928
+ })), on(GlobalActions.increaseLoadingReference, (state) => ({
929
+ ...state,
930
+ loadingReference: state.loadingReference + 1,
931
+ })), on(GlobalActions.decreaseLoadingReference, (state) => ({
932
+ ...state,
933
+ loadingReference: Math.max(state.loadingReference - 1, 0),
934
+ })), on(GlobalActions.setAcl, (state, { acl }) => ({
935
+ ...state,
936
+ acl,
937
+ })), on(GlobalActions.setListMenuItem, (state, { listMenuItem }) => ({
938
+ ...state,
939
+ listMenuItem,
940
+ })), on(GlobalActions.toggleSideMenu, (state) => ({
941
+ ...state,
942
+ isSideMenuOpen: !state.isSideMenuOpen,
943
+ })), on(GlobalActions.closeSideMenu, (state) => ({
944
+ ...state,
945
+ isSideMenuOpen: false,
946
+ })), on(GlobalActions.setLanguage, (state, { language }) => ({
947
+ ...state,
948
+ language,
949
+ })), on(GlobalActions.setCurrentGroup, (state, { group }) => ({
950
+ ...state,
951
+ currentGroup: group,
952
+ })));
953
+
954
+ /*
955
+ * Public API Surface of core
956
+ */
957
+
958
+ /**
959
+ * Generated bundle index. Do not edit.
960
+ */
961
+
962
+ export { AuthService, BaseEntityApiService, CdnApiService, CoreService, Device, DeviceApiService, DisplayNamePipe, GlobalActions, GlobalApiService, GlobalEffects, GlobalSelectors, GroupApiService, GroupStore, HALODUCK_CORE_CONFIG, ITableStateStatusCreated, ITableStateStatusCreating, ITableStateStatusDeleted, ITableStateStatusDeleting, ITableStateStatusFailedToCreate, ITableStateStatusFailedToDelete, ITableStateStatusFailedToLoad, ITableStateStatusFailedToUpdate, ITableStateStatusLoaded, ITableStateStatusLoading, ITableStateStatusUpdated, ITableStateStatusUpdating, MemberApiService, MemberStore, SearchParams, TableStore, authGuard, defaultLanguage, dummyMemberIdInterceptor, errorHandler, globalReducer, groupIdInterceptor, idTokenInterceptor, initialState, provideHaloduckCoreConfig, responseHandler, supportedLanguages };
963
+ //# sourceMappingURL=haloduck-core.mjs.map